@fower/core
Advanced tools
Comparing version 1.41.0 to 1.42.0
@@ -1264,3 +1264,3 @@ 'use strict'; | ||
var find = atoms.find(function (atom) { | ||
return [atom.propKey, atom.key, 'css'].includes(key); | ||
return [atom.propKey, atom.key, atom.id, 'css'].includes(key); | ||
}); | ||
@@ -1267,0 +1267,0 @@ if (!find) result[key] = value; |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("deepmerge")),r=require("@fower/utils"),i=e(require("string-hash")),n=require("@fower/color-helper"),o=require("@fower/css-object-processor");function s(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function a(e,t,r){return t&&s(e.prototype,t),r&&s(e,r),e}function u(){return(u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e}).apply(this,arguments)}function l(e,t){if(null==e)return{};var r,i,n={},o=Object.keys(e);for(i=0;i<o.length;i++)t.indexOf(r=o[i])>=0||(n[r]=e[r]);return n}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,i=new Array(t);r<t;r++)i[r]=e[r];return i}function d(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return c(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?c(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var i=0;return function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}require("@fower/atomic-props");var f=function(){function e(){var e=this;this.config={unit:"px",inline:!1,important:!1,mode:{currentMode:"light",autoDarkMode:{enabled:!1,mappings:{white:"black",black:"white",50:"900",100:"800",200:"700",300:"600",400:"500",500:"400",600:"300",700:"200",800:"100",900:"50"}},modeList:["light","dark"],classPrefix:""},prefix:"",pseudos:["active","checked","disabled","enabled","default","empty","focus","focus-within","invalid","hover","link","visited","first-child","last-child","after","before","placeholder","selection"],theme:{breakpoints:{}},plugins:[]},this.atomCache=new Map,this.getAtomIds=function(){return Array.from(e.atomCache.keys())},this.compositions=new Map,this.getConfig=function(){return e.config},this.setConfig=function(r,i){void 0===i&&(i="deepmerge"),e.config="replace"===i?r:"merge"===i?u({},e.config,r):t(e.config,r)},this.getTheme=function(){return e.config.theme},this.setTheme=function(r){e.config.theme=t(e.config.theme||{},r)},this.getMode=function(){var t;return(null==(t=e.config.mode)?void 0:t.currentMode)||""},this.setMode=function(t){if(r.isBrowser){var i=e.config.mode.currentMode;i&&document.documentElement.classList.remove(i),t&&document.documentElement.classList.add(t),localStorage.setItem("fower-mode",t),e.setConfig({mode:{currentMode:t}})}},this.use=function(){var t;(t=e.config.plugins).push.apply(t,arguments)},this.addAtom=function(t,r){var i={isMatch:function(e){return"string"==typeof t?e===t:t instanceof RegExp&&t.test(e)},handleAtom:"function"==typeof r?r:function(e){return e.style=r,e}};return e.use(i),i},this.composeAtom=function(t,r){e.compositions.set(t,r)}}return a(e,[{key:"theme",get:function(){return this.config.theme}}]),e}(),p=new f,h=["excludedProps"],m=/^(m[xytrbl]?-?|p[xytrbl]?|space[xy]?|top-?|right-?|bottom-?|left-?|[wh]|square|circle|min[hw]|max[hw]|opacity|delay|duration|translate[xyz]|scale[xy]?|rotate[xy]?|skew[xy]?|text|zIndex-?|leading|stroke|fontWeight|outlineOffset|order|flex(Grow|Shrink|Basis)?|(row|column)?Gap|gridTemplateColumns|border[trbl]?|rounded(Top(Left|Right)?|Right|Bottom(Left|Right)?|Left)?)(-?\d+[a-z]*?|-auto)$/i,y=function(){function e(e){var t=this;this.options=e,this.value="",this.id="",this.type="",this.setId=function(){var e,r=t.meta,n=t.key,o=t.value,s=r.important,a=l(r,["pseudoPrefix","childSelector","important"]),u=Object.values(a).sort();return s&&u.push("i"),r.global?(e=i(JSON.stringify(o)).toString(),t.id=e,e):(e="boolean"==typeof o&&!0===o?n:Array.isArray(o)?n+"-"+o.join("-"):n+"-"+String(o),u.length&&(e=e+"--"+u.join("--")),e=e.replace(/[#().]/g,"").replace(/\%/g,"p").replace(/\s+/g,"-"),e=/^[a-zA-Z0-9-]+$/.test(e)?e:"css-"+i(e),t.isFalsePropValue&&(e+="--false"),t.id=e,e)},this.propKey=e.propKey,this.propValue=e.propValue,this.key=e.key||this.propKey,this.value=e.value||this.propValue,this.style=e.style,this.handled=this.getInitialHandled(),this.isValid=this.getIsValid(),this.inserted=!1,this.meta=u({},e.meta)||{},this.preprocessAtom()}var t=e.prototype;return t.preprocessAtom=function(){var e=this.postfixPreprocessor();return this.setId(),e},t.postfixPreprocessor=function(){var e=p.config,t=e.pseudos,r=void 0===t?[]:t,i=e.mode.modeList,n=this.propKey,o=this.propValue,s=Object.keys(e.theme.breakpoints),a=i||[],u=r,l="--("+s.join("|")+")",c="--("+a.join("|")+")",d="--("+u.join("|")+")",f=new RegExp(c),h=new RegExp(d),m=new RegExp(l),y=/--[told](\d{1,2}|100)($|--)/i;if(y.test(o)){var g=o.split("--"),v=g[1];this.value=g[0],this.meta.colorPostfix=v}var b=f.test(n),k=h.test(n),S=m.test(n),x=/--i/i.test(n),A=y.test(n),w=/--\$\w+/i.test(n);if(!(b||k||S||x||A))return this.digitPreprocessor();var j,C=n.split("--");if(this.key=C[0],b&&(this.meta.mode=C.find((function(e){return a.includes(e)}))),k){var O=C.find((function(e){return u.includes(e)}));this.meta.pseudoPrefix=["after","before","placeholder","selection"].includes(O)?"::":":",this.meta.pseudo=O}if(S){var P=C.find((function(e){return s.includes(e)}));this.meta.breakpoint=P}return x&&(this.meta.important=!!C.find((function(e){return"i"===e}))),A&&(this.meta.colorPostfix=C.find((function(e){return y.test("--"+e)}))),w&&(this.meta.parentClass=null==(j=C.find((function(e){return e.startsWith("$")})))?void 0:j.replace(/^\$/,"")),this.digitPreprocessor(),this},t.digitPreprocessor=function(){if(!m.test(this.key))return this;var e=p.config.theme.spacings,t=/^([a-z]+)(\d+)$/i.test(this.key),r=this.key.toString(),i=r.match(/^([a-z]+)(\d+)$/i)||r.match(/^([a-z]*)-(-?\d+[a-z]*?)$/i)||r.match(/^([a-z]+)-(auto)$/i);if(!i)return this;var n=i[2];return this.key=i[1],this.value=t?e[""+n.toLowerCase()]:n,this},t.getInitialHandled=function(){return this.options.handled?this.options.handled:!!this.isFalsePropValue||!!h.includes(this.propKey)},t.getIsValid=function(){return!this.isFalsePropValue&&!h.includes(this.propKey)},a(e,[{key:"isValueProp",get:function(){return"string"==typeof this.propValue||"number"==typeof this.propValue}},{key:"styleKeys",get:function(){return Object.keys(this.style||{}).join("-")}},{key:"styleKeysHash",get:function(){var e=l(this.meta,["colorPostfix"]);return Object.keys(this.style||{}).join("-")+JSON.stringify(e)}},{key:"isFalsePropValue",get:function(){return"boolean"==typeof this.propValue&&!this.propValue}},{key:"isTruePropValue",get:function(){return"boolean"==typeof this.propValue&&this.propValue}}]),e}(),g=new(function(){function e(){var e;this.$style=null,this.cssString="",this.ssrAtomIds=null,r.isBrowser&&(this.$style=null==(e=globalThis.document)||null==e.querySelector?void 0:e.querySelector("[data-fower]"))}var t=e.prototype;return t.createStyleElement=function(){var e=document.createElement("style");return e.dataset.fower="",document.head.append(e),e},t.getSsrAtomIds=function(){var e,t;return this.$style?this.ssrAtomIds?this.ssrAtomIds:(null==(e=this.$style)||null==(t=e.dataset.fower)?void 0:t.split(","))||[]:[]},t.insertStyleToHtml=function(e){if(r.isBrowser){this.$style||(this.$style=this.createStyleElement());for(var t,i=d(e);!(t=i()).done;){var n=t.value;try{this.$style.sheet.insertRule(n)}catch(e){console.warn(e)}}}},t.insertStyles=function(e){if(void 0===e&&(e=[]),e.length)return r.isBrowser?this.insertStyleToHtml(e):void(this.cssString=this.cssString+" "+e.join(" "))},t.getStyle=function(){return this.cssString},e}()),v=/(-columns|(^|[^e]-)padding|[^t]-spacing|l-align|rows|(^|(^border|[dkmnptx]|le|ne)-)width|^border|tom|[ek]-start|(o|[^e]-du)ration|us|(^|[^tv]-)left|(^|-)top|tance|rgin|e-offset|(er|g|n|t)-block|(^|[^tv]-)right|basis|[gnt]-inline|gap|(^|[^e]-)height|ness|(^|[^p]-)inset|[ek]-end|elay|tline|ve|dent|-rotate|n-rule|(c|ck|d|ne|t)-size)$/,b=["color","backgroundColor","borderColor"],k=["children","onClick","onChange","onBlur","className","placeholder"],S=function(){function e(e){var t,r;void 0===e&&(e={}),this.props=e,this.atoms=[],this.getClassNameById=function(e){return p.config.prefix+e},this.traverseProps(e),null!=(t=p.config.mode)&&null!=(r=t.autoDarkMode)&&r.enabled&&this.autoDarkMode()}var t=e.prototype;return t.traverseProps=function(e){if(!r.isEmptyObj(e)){for(var t,i=this.config,n=i.pseudos,o=void 0===n?[]:n,s=i.mode.modeList,a=i.theme.breakpoints||{},l=Object.keys(a),c=s||[],f=o,h=e.excludedProps,m=void 0===h?[]:h,g=Object.entries(e),v=d(this.plugins);!(t=v()).done;){var b=t.value;b.init&&b.init(e)}if(null!=e&&e.className)for(var S,x=d(e.className.split(/\s+/));!(S=x()).done;)g.push([S.value,!0]);for(var A=0,w=g;A<w.length;A++){var j=w[A],C=j[0],O=j[1];if(!m.includes(C)&&!k.includes(C)&&this.isValidProp(C,O))if("css"!==C){if(C.startsWith("_")){var P=C.replace(/^_/,""),V=Array.isArray(O)?O.reduce((function(e,t){var r;return u({},e,((r={})[t]=!0,r))}),{}):O;if(c.includes(P)){this.parseCSSObject(V,{mode:P});continue}if(l.includes(P)){this.parseCSSObject(V,{breakpoint:a[P]});continue}if(f.includes(P)){this.parseCSSObject(V,{pseudoPrefix:":",pseudo:P});continue}}var K=p.compositions.get(C);if(K){this.parseCSSObject(K,{});var M=new y({propKey:C,propValue:O});M.handled=!0,M.style={},this.addAtom(M)}else{var I=new y({propKey:C,propValue:O});try{this.mutateAtom(I),I.handled&&this.addAtom(I)}catch(e){continue}}}else this.parseCSSObject(O,{})}for(var N,T=d(this.plugins);!(N=T()).done;){var $=N.value;$.afterAtomStyleCreate&&$.afterAtomStyleCreate(this)}}},t.getAutoDarkModeAtom=function(e){var t;if(e.meta.mode)return null;if(!e.style)return null;var i=Object.entries(e.style);if(null==i||!i.length)return null;var n,o={},s=p.config,a=s.mode.autoDarkMode.mappings,l=s.theme.colors,c=i[0],d=c[0],f=c[1];if(!b.includes(d))return null;if(!l[f])return null;var h=(f.match(/^([a-z]+)(\d+)$/i)||[])[2];if(!1===a[f])return null;var m="color"===d,g="backgroundColor"===d,v="borderColor"===d;return l[n=a[f]?a[f]:f.replace(h,a[h])]?(m?o.propKey=n:g?o.propKey="bg"+r.upFirst(n):v&&(o.propKey="border"+r.upFirst(n)),o.propValue=!0):m?(o.propKey="color",o.propValue=n):g?(o.propKey="bg",o.propValue=n):v&&(o.propKey="borderColor",o.propValue=n),o.style=((t={})[d]=n,t),new y(u({},o,{meta:u({},e.meta,{mode:"dark"})}))},t.autoDarkMode=function(){for(var e,t=d(this.atoms);!(e=t()).done;){var r=e.value;if(!this.atoms.find((function(e){return b.includes(e.type)&&"dark"===e.meta.mode}))){var i=this.getAutoDarkModeAtom(r);if(i){var n=p.atomCache.get(i.id);this.addAtom(n||i)}}}},t.formatCssValue=function(e,t){if(!v.test(e))return t;var i;if(r.isPercentNumber(String(t)))return String(t).replace("p","%");if(!r.isNumber(t))return t;if((i=Number(t))<1&&i>0)return 100*i+"%";var n=p.config;return"none"!==n.unit?n.transformUnit?n.transformUnit(i):t+p.config.unit:i},t.styleToString=function(e,t){var i=this,o=t.important,s=t.colorPostfix;return Object.entries(e).reduce((function(e,t){var a=t[1],u=r.jsKeyToCssKey(t[0]),l=o?" !important":"",c=p.theme.colors;try{return e+(u+": ")+(a=s?n.formatColor((null==c?void 0:c[a])||a,s):i.formatCssValue(u,(null==c?void 0:c[a])||a))+l+";"}catch(e){return""}}),"")},t.addAtom=function(e){var t;p.atomCache.get(e.id)||p.atomCache.set(e.id,e);for(var r=g.getSsrAtomIds(),i=((null==(t=this.config.theme)?void 0:t.colors)||{}).modes,n=0,o=Object.entries(void 0===i?{}:i);n<o.length;n++){var s=o[n],a=s[0],l=s[1];if(e.style){var c=Object.entries(e.style);if(c.length){var d=c[0],f=d[0],h=l[d[1]];if(h){var m="--"+a,y=JSON.parse(JSON.stringify(e));y.key=e.key+m,y.id=e.id+m,y.meta=u({mode:a},e.meta),y.style[f]=h,r.includes(y.id)&&(y.inserted=!0),this.atoms.push(y)}}}}r.includes(e.id)&&(e.inserted=!0),this.atoms.push(e)},t.isValidProp=function(e,t){return"css"===e||!!e.startsWith("_")||!!Array.isArray(t)||!!["string","boolean","number","undefined"].includes(typeof t)},t.mutateAtom=function(e){var t=p.atomCache.get(e.id);if(t)throw this.addAtom(t),new Error("atom is cached, add to this.atoms derectly, no need to mutate");if(e.handled)throw this.addAtom(e),new Error("atom is handled, add to this.atoms derectly ,no need to mutate");for(var r,i=d(this.plugins);!(r=i()).done;){var n=r.value;if(null!=n.isMatch&&n.isMatch(e.key,this)){n.beforeHandleAtom&&(e=n.beforeHandleAtom(e,this)),n.handleAtom&&(e=null==n.handleAtom?void 0:n.handleAtom(e,this)),e.handled=!0;break}}},t.parseCSSObject=function(e,t){void 0===t&&(t={});for(var r,i=d(o.parse(e));!(r=i()).done;){var n=r.value,s=n.selector,a=n.selectorType,l=n.style,c=Object.entries(l);if(c.length){var f=c[0],h={propKey:f[0],propValue:f[1],meta:u({},t)};if("pseudo"===a&&h.meta){var m=s.match(/(:+)(.+)/)||[],g=m[2];h.meta.pseudoPrefix=m[1],h.meta.pseudo=g}"child"===a&&h.meta&&(h.meta.childSelector=s),"sibling"===a&&h.meta&&(h.meta.siblingSelector=s);var v=new y(h);try{this.mutateAtom(v)}catch(e){continue}v.style||(v.style=l,v.handled=!0);var b=p.atomCache.get(v.id);this.addAtom(b||v)}}},t.makeResponsiveStyle=function(e,t){return"@media (min-width: "+this.config.theme.breakpoints[e]+") {"+t+"}"},t.getClassNames=function(){var e=this,t=[];this.atoms.reduce((function(r,i){if(!i.style||!Object.keys(i.style).length)return r;var n=r.findIndex((function(e){return e.styleKeysHash===i.styleKeysHash}));if(!i.isValid)return r;var o=e.getClassNameById(i.id);return-1===n?(t.push(o),r=[].concat(r,[i])):(r.splice(n,1,i),t.splice(n,1,o)),r}),[]);var r=this.props.className,i=(void 0===r?"":r).split(/\s+/).filter((function(e){return!t.includes(e)&&!!e}));return t=t.concat(i),this.hasResponsive&&t.unshift(this.uniqueClassName),t},t.toStyle=function(){var e=this;return this.atoms.reduce((function(t,i){if(!i.isValid)return t;var n=p.theme.colors,o=Object.entries(i.style).reduce((function(t,i){var o,s=i[0],a=i[1],l=e.formatCssValue(r.jsKeyToCssKey(s),n[a]||a);return u({},t,((o={})[s]=l,o))}),{});return u({},t,o)}),{})},t.toRules=function(e){var t=this;void 0===e&&(e=!1);var i=this.config.mode.classPrefix,n=void 0===i?"":i,o=[],s=this.config.theme.breakpoints;this.atoms=this.atoms.sort((function(e,t){return parseInt(s[t.meta.breakpoint]||"0")-parseInt(s[e.meta.breakpoint]||"0")}));for(var a,u=function(){var i=a.value,s="",u=i.id,l=i.style,c=void 0===l?{}:l,d=i.meta;if(!i.isValid)return"continue";if(r.isEmptyObj(c))return"continue";var f=d.pseudo,p=d.pseudoPrefix,h=d.mode,m=d.breakpoint,y=void 0===m?"":m,g=d.childSelector,v=d.siblingSelector,b=d.parentClass,k=!!t.atoms.find((function(e){return e.styleKeys===i.styleKeys&&(y||e.meta.breakpoint)})),S=k||y?"."+t.uniqueClassName:"";if(!e&&!k&&i.inserted)return"continue";i.inserted=!0;var x=t.getClassNameById(u),A=d.global?d.global:S+"."+x;if(h&&(A="."+n+h+" "+A),g&&(A=A+" "+g),v&&(A=""+A+v),f){var w=p+f;b?A="."+b+w+" "+A:A+=w}s=A+" { "+t.styleToString(c,i.meta)+" }",y&&(s=t.makeResponsiveStyle(y,s)),o.push(s)},l=d(this.atoms);!(a=l()).done;)u();return o},t.getParsedProps=function(){var e=this.props,t=this.atoms;return r.isEmptyObj(e)?{}:Object.entries(e).reduce((function(e,r){var i=r[0],n=r[1];return/.*--(\d+)?[a-z]+$/i.test(i)||t.find((function(e){return[e.propKey,e.key,"css"].includes(i)}))||(e[i]=n),e}),{})},t.insertRules=function(){var e=this.toRules();g.insertStyles(e)},a(e,[{key:"uniqueClassName",get:function(){return r.objectToClassName(Object.keys(this.props))}},{key:"hasResponsive",get:function(){return this.atoms.some((function(e){return!!e.meta.breakpoint}))}},{key:"store",get:function(){return p}},{key:"config",get:function(){return p.config}},{key:"plugins",get:function(){return p.config.plugins}}]),e}();function x(e){for(var t=Object.entries(e),r=new S({}),i=0,n=t;i<n.length;i++){var o=n[i],s=o[0],a=o[1],u=new y({propKey:s,propValue:a,value:a,meta:{global:s},style:a});r.addAtom(u)}r.insertRules()}x({"*, ::before, ::after":{borderWidth:0,borderStyle:"solid",borderColor:"#d4d4d4",boxSizing:"border-box"}});var A=p.setConfig,w=p.getConfig,j=p.setTheme,C=p.getTheme,O=p.setMode,P=p.getMode,V=p.addAtom,K=p.composeAtom;exports.Atom=y,exports.Parser=S,exports.Store=f,exports.addAtom=V,exports.composeAtom=K,exports.createStyle=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var i=t.reduce((function(e,t){var r;return u({},e,"string"==typeof t?((r={})[t]=!0,r):{css:t})}),{}),n=new S(i),o=n.toStyle();return o},exports.css=function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];if(!t.length)return"";var n=new S(r.argsToProps(t));return n.insertRules(),n.getClassNames().join(" ")},exports.digitReg=m,exports.getConfig=w,exports.getMode=P,exports.getTheme=C,exports.injectGlobalStyle=x,exports.keyframes=function(e,t){var i=Object.entries(e).reduce((function(e,t){var i=t[0],n=Object.entries(t[1]).reduce((function(e,t){return e+(t[0]+": ")+t[1]+";"}),"");return e+(r.jsKeyToCssKey(i)+" {")+n+"}"}),""),n=t||"keyframes-"+r.hash(JSON.stringify(e));return g.insertStyles(["\n @keyframes "+n+" {\n "+i+"\n }\n "]),n},exports.setConfig=A,exports.setMode=O,exports.setTheme=j,exports.store=p,exports.styleSheet=g; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("deepmerge")),r=require("@fower/utils"),i=e(require("string-hash")),n=require("@fower/color-helper"),o=require("@fower/css-object-processor");function s(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function a(e,t,r){return t&&s(e.prototype,t),r&&s(e,r),e}function u(){return(u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e}).apply(this,arguments)}function l(e,t){if(null==e)return{};var r,i,n={},o=Object.keys(e);for(i=0;i<o.length;i++)t.indexOf(r=o[i])>=0||(n[r]=e[r]);return n}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,i=new Array(t);r<t;r++)i[r]=e[r];return i}function d(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return c(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?c(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var i=0;return function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}require("@fower/atomic-props");var f=function(){function e(){var e=this;this.config={unit:"px",inline:!1,important:!1,mode:{currentMode:"light",autoDarkMode:{enabled:!1,mappings:{white:"black",black:"white",50:"900",100:"800",200:"700",300:"600",400:"500",500:"400",600:"300",700:"200",800:"100",900:"50"}},modeList:["light","dark"],classPrefix:""},prefix:"",pseudos:["active","checked","disabled","enabled","default","empty","focus","focus-within","invalid","hover","link","visited","first-child","last-child","after","before","placeholder","selection"],theme:{breakpoints:{}},plugins:[]},this.atomCache=new Map,this.getAtomIds=function(){return Array.from(e.atomCache.keys())},this.compositions=new Map,this.getConfig=function(){return e.config},this.setConfig=function(r,i){void 0===i&&(i="deepmerge"),e.config="replace"===i?r:"merge"===i?u({},e.config,r):t(e.config,r)},this.getTheme=function(){return e.config.theme},this.setTheme=function(r){e.config.theme=t(e.config.theme||{},r)},this.getMode=function(){var t;return(null==(t=e.config.mode)?void 0:t.currentMode)||""},this.setMode=function(t){if(r.isBrowser){var i=e.config.mode.currentMode;i&&document.documentElement.classList.remove(i),t&&document.documentElement.classList.add(t),localStorage.setItem("fower-mode",t),e.setConfig({mode:{currentMode:t}})}},this.use=function(){var t;(t=e.config.plugins).push.apply(t,arguments)},this.addAtom=function(t,r){var i={isMatch:function(e){return"string"==typeof t?e===t:t instanceof RegExp&&t.test(e)},handleAtom:"function"==typeof r?r:function(e){return e.style=r,e}};return e.use(i),i},this.composeAtom=function(t,r){e.compositions.set(t,r)}}return a(e,[{key:"theme",get:function(){return this.config.theme}}]),e}(),p=new f,h=["excludedProps"],m=/^(m[xytrbl]?-?|p[xytrbl]?|space[xy]?|top-?|right-?|bottom-?|left-?|[wh]|square|circle|min[hw]|max[hw]|opacity|delay|duration|translate[xyz]|scale[xy]?|rotate[xy]?|skew[xy]?|text|zIndex-?|leading|stroke|fontWeight|outlineOffset|order|flex(Grow|Shrink|Basis)?|(row|column)?Gap|gridTemplateColumns|border[trbl]?|rounded(Top(Left|Right)?|Right|Bottom(Left|Right)?|Left)?)(-?\d+[a-z]*?|-auto)$/i,y=function(){function e(e){var t=this;this.options=e,this.value="",this.id="",this.type="",this.setId=function(){var e,r=t.meta,n=t.key,o=t.value,s=r.important,a=l(r,["pseudoPrefix","childSelector","important"]),u=Object.values(a).sort();return s&&u.push("i"),r.global?(e=i(JSON.stringify(o)).toString(),t.id=e,e):(e="boolean"==typeof o&&!0===o?n:Array.isArray(o)?n+"-"+o.join("-"):n+"-"+String(o),u.length&&(e=e+"--"+u.join("--")),e=e.replace(/[#().]/g,"").replace(/\%/g,"p").replace(/\s+/g,"-"),e=/^[a-zA-Z0-9-]+$/.test(e)?e:"css-"+i(e),t.isFalsePropValue&&(e+="--false"),t.id=e,e)},this.propKey=e.propKey,this.propValue=e.propValue,this.key=e.key||this.propKey,this.value=e.value||this.propValue,this.style=e.style,this.handled=this.getInitialHandled(),this.isValid=this.getIsValid(),this.inserted=!1,this.meta=u({},e.meta)||{},this.preprocessAtom()}var t=e.prototype;return t.preprocessAtom=function(){var e=this.postfixPreprocessor();return this.setId(),e},t.postfixPreprocessor=function(){var e=p.config,t=e.pseudos,r=void 0===t?[]:t,i=e.mode.modeList,n=this.propKey,o=this.propValue,s=Object.keys(e.theme.breakpoints),a=i||[],u=r,l="--("+s.join("|")+")",c="--("+a.join("|")+")",d="--("+u.join("|")+")",f=new RegExp(c),h=new RegExp(d),m=new RegExp(l),y=/--[told](\d{1,2}|100)($|--)/i;if(y.test(o)){var g=o.split("--"),v=g[1];this.value=g[0],this.meta.colorPostfix=v}var b=f.test(n),k=h.test(n),S=m.test(n),x=/--i/i.test(n),A=y.test(n),w=/--\$\w+/i.test(n);if(!(b||k||S||x||A))return this.digitPreprocessor();var j,C=n.split("--");if(this.key=C[0],b&&(this.meta.mode=C.find((function(e){return a.includes(e)}))),k){var O=C.find((function(e){return u.includes(e)}));this.meta.pseudoPrefix=["after","before","placeholder","selection"].includes(O)?"::":":",this.meta.pseudo=O}if(S){var P=C.find((function(e){return s.includes(e)}));this.meta.breakpoint=P}return x&&(this.meta.important=!!C.find((function(e){return"i"===e}))),A&&(this.meta.colorPostfix=C.find((function(e){return y.test("--"+e)}))),w&&(this.meta.parentClass=null==(j=C.find((function(e){return e.startsWith("$")})))?void 0:j.replace(/^\$/,"")),this.digitPreprocessor(),this},t.digitPreprocessor=function(){if(!m.test(this.key))return this;var e=p.config.theme.spacings,t=/^([a-z]+)(\d+)$/i.test(this.key),r=this.key.toString(),i=r.match(/^([a-z]+)(\d+)$/i)||r.match(/^([a-z]*)-(-?\d+[a-z]*?)$/i)||r.match(/^([a-z]+)-(auto)$/i);if(!i)return this;var n=i[2];return this.key=i[1],this.value=t?e[""+n.toLowerCase()]:n,this},t.getInitialHandled=function(){return this.options.handled?this.options.handled:!!this.isFalsePropValue||!!h.includes(this.propKey)},t.getIsValid=function(){return!this.isFalsePropValue&&!h.includes(this.propKey)},a(e,[{key:"isValueProp",get:function(){return"string"==typeof this.propValue||"number"==typeof this.propValue}},{key:"styleKeys",get:function(){return Object.keys(this.style||{}).join("-")}},{key:"styleKeysHash",get:function(){var e=l(this.meta,["colorPostfix"]);return Object.keys(this.style||{}).join("-")+JSON.stringify(e)}},{key:"isFalsePropValue",get:function(){return"boolean"==typeof this.propValue&&!this.propValue}},{key:"isTruePropValue",get:function(){return"boolean"==typeof this.propValue&&this.propValue}}]),e}(),g=new(function(){function e(){var e;this.$style=null,this.cssString="",this.ssrAtomIds=null,r.isBrowser&&(this.$style=null==(e=globalThis.document)||null==e.querySelector?void 0:e.querySelector("[data-fower]"))}var t=e.prototype;return t.createStyleElement=function(){var e=document.createElement("style");return e.dataset.fower="",document.head.append(e),e},t.getSsrAtomIds=function(){var e,t;return this.$style?this.ssrAtomIds?this.ssrAtomIds:(null==(e=this.$style)||null==(t=e.dataset.fower)?void 0:t.split(","))||[]:[]},t.insertStyleToHtml=function(e){if(r.isBrowser){this.$style||(this.$style=this.createStyleElement());for(var t,i=d(e);!(t=i()).done;){var n=t.value;try{this.$style.sheet.insertRule(n)}catch(e){console.warn(e)}}}},t.insertStyles=function(e){if(void 0===e&&(e=[]),e.length)return r.isBrowser?this.insertStyleToHtml(e):void(this.cssString=this.cssString+" "+e.join(" "))},t.getStyle=function(){return this.cssString},e}()),v=/(-columns|(^|[^e]-)padding|[^t]-spacing|l-align|rows|(^|(^border|[dkmnptx]|le|ne)-)width|^border|tom|[ek]-start|(o|[^e]-du)ration|us|(^|[^tv]-)left|(^|-)top|tance|rgin|e-offset|(er|g|n|t)-block|(^|[^tv]-)right|basis|[gnt]-inline|gap|(^|[^e]-)height|ness|(^|[^p]-)inset|[ek]-end|elay|tline|ve|dent|-rotate|n-rule|(c|ck|d|ne|t)-size)$/,b=["color","backgroundColor","borderColor"],k=["children","onClick","onChange","onBlur","className","placeholder"],S=function(){function e(e){var t,r;void 0===e&&(e={}),this.props=e,this.atoms=[],this.getClassNameById=function(e){return p.config.prefix+e},this.traverseProps(e),null!=(t=p.config.mode)&&null!=(r=t.autoDarkMode)&&r.enabled&&this.autoDarkMode()}var t=e.prototype;return t.traverseProps=function(e){if(!r.isEmptyObj(e)){for(var t,i=this.config,n=i.pseudos,o=void 0===n?[]:n,s=i.mode.modeList,a=i.theme.breakpoints||{},l=Object.keys(a),c=s||[],f=o,h=e.excludedProps,m=void 0===h?[]:h,g=Object.entries(e),v=d(this.plugins);!(t=v()).done;){var b=t.value;b.init&&b.init(e)}if(null!=e&&e.className)for(var S,x=d(e.className.split(/\s+/));!(S=x()).done;)g.push([S.value,!0]);for(var A=0,w=g;A<w.length;A++){var j=w[A],C=j[0],O=j[1];if(!m.includes(C)&&!k.includes(C)&&this.isValidProp(C,O))if("css"!==C){if(C.startsWith("_")){var P=C.replace(/^_/,""),V=Array.isArray(O)?O.reduce((function(e,t){var r;return u({},e,((r={})[t]=!0,r))}),{}):O;if(c.includes(P)){this.parseCSSObject(V,{mode:P});continue}if(l.includes(P)){this.parseCSSObject(V,{breakpoint:a[P]});continue}if(f.includes(P)){this.parseCSSObject(V,{pseudoPrefix:":",pseudo:P});continue}}var K=p.compositions.get(C);if(K){this.parseCSSObject(K,{});var M=new y({propKey:C,propValue:O});M.handled=!0,M.style={},this.addAtom(M)}else{var I=new y({propKey:C,propValue:O});try{this.mutateAtom(I),I.handled&&this.addAtom(I)}catch(e){continue}}}else this.parseCSSObject(O,{})}for(var N,T=d(this.plugins);!(N=T()).done;){var $=N.value;$.afterAtomStyleCreate&&$.afterAtomStyleCreate(this)}}},t.getAutoDarkModeAtom=function(e){var t;if(e.meta.mode)return null;if(!e.style)return null;var i=Object.entries(e.style);if(null==i||!i.length)return null;var n,o={},s=p.config,a=s.mode.autoDarkMode.mappings,l=s.theme.colors,c=i[0],d=c[0],f=c[1];if(!b.includes(d))return null;if(!l[f])return null;var h=(f.match(/^([a-z]+)(\d+)$/i)||[])[2];if(!1===a[f])return null;var m="color"===d,g="backgroundColor"===d,v="borderColor"===d;return l[n=a[f]?a[f]:f.replace(h,a[h])]?(m?o.propKey=n:g?o.propKey="bg"+r.upFirst(n):v&&(o.propKey="border"+r.upFirst(n)),o.propValue=!0):m?(o.propKey="color",o.propValue=n):g?(o.propKey="bg",o.propValue=n):v&&(o.propKey="borderColor",o.propValue=n),o.style=((t={})[d]=n,t),new y(u({},o,{meta:u({},e.meta,{mode:"dark"})}))},t.autoDarkMode=function(){for(var e,t=d(this.atoms);!(e=t()).done;){var r=e.value;if(!this.atoms.find((function(e){return b.includes(e.type)&&"dark"===e.meta.mode}))){var i=this.getAutoDarkModeAtom(r);if(i){var n=p.atomCache.get(i.id);this.addAtom(n||i)}}}},t.formatCssValue=function(e,t){if(!v.test(e))return t;var i;if(r.isPercentNumber(String(t)))return String(t).replace("p","%");if(!r.isNumber(t))return t;if((i=Number(t))<1&&i>0)return 100*i+"%";var n=p.config;return"none"!==n.unit?n.transformUnit?n.transformUnit(i):t+p.config.unit:i},t.styleToString=function(e,t){var i=this,o=t.important,s=t.colorPostfix;return Object.entries(e).reduce((function(e,t){var a=t[1],u=r.jsKeyToCssKey(t[0]),l=o?" !important":"",c=p.theme.colors;try{return e+(u+": ")+(a=s?n.formatColor((null==c?void 0:c[a])||a,s):i.formatCssValue(u,(null==c?void 0:c[a])||a))+l+";"}catch(e){return""}}),"")},t.addAtom=function(e){var t;p.atomCache.get(e.id)||p.atomCache.set(e.id,e);for(var r=g.getSsrAtomIds(),i=((null==(t=this.config.theme)?void 0:t.colors)||{}).modes,n=0,o=Object.entries(void 0===i?{}:i);n<o.length;n++){var s=o[n],a=s[0],l=s[1];if(e.style){var c=Object.entries(e.style);if(c.length){var d=c[0],f=d[0],h=l[d[1]];if(h){var m="--"+a,y=JSON.parse(JSON.stringify(e));y.key=e.key+m,y.id=e.id+m,y.meta=u({mode:a},e.meta),y.style[f]=h,r.includes(y.id)&&(y.inserted=!0),this.atoms.push(y)}}}}r.includes(e.id)&&(e.inserted=!0),this.atoms.push(e)},t.isValidProp=function(e,t){return"css"===e||!!e.startsWith("_")||!!Array.isArray(t)||!!["string","boolean","number","undefined"].includes(typeof t)},t.mutateAtom=function(e){var t=p.atomCache.get(e.id);if(t)throw this.addAtom(t),new Error("atom is cached, add to this.atoms derectly, no need to mutate");if(e.handled)throw this.addAtom(e),new Error("atom is handled, add to this.atoms derectly ,no need to mutate");for(var r,i=d(this.plugins);!(r=i()).done;){var n=r.value;if(null!=n.isMatch&&n.isMatch(e.key,this)){n.beforeHandleAtom&&(e=n.beforeHandleAtom(e,this)),n.handleAtom&&(e=null==n.handleAtom?void 0:n.handleAtom(e,this)),e.handled=!0;break}}},t.parseCSSObject=function(e,t){void 0===t&&(t={});for(var r,i=d(o.parse(e));!(r=i()).done;){var n=r.value,s=n.selector,a=n.selectorType,l=n.style,c=Object.entries(l);if(c.length){var f=c[0],h={propKey:f[0],propValue:f[1],meta:u({},t)};if("pseudo"===a&&h.meta){var m=s.match(/(:+)(.+)/)||[],g=m[2];h.meta.pseudoPrefix=m[1],h.meta.pseudo=g}"child"===a&&h.meta&&(h.meta.childSelector=s),"sibling"===a&&h.meta&&(h.meta.siblingSelector=s);var v=new y(h);try{this.mutateAtom(v)}catch(e){continue}v.style||(v.style=l,v.handled=!0);var b=p.atomCache.get(v.id);this.addAtom(b||v)}}},t.makeResponsiveStyle=function(e,t){return"@media (min-width: "+this.config.theme.breakpoints[e]+") {"+t+"}"},t.getClassNames=function(){var e=this,t=[];this.atoms.reduce((function(r,i){if(!i.style||!Object.keys(i.style).length)return r;var n=r.findIndex((function(e){return e.styleKeysHash===i.styleKeysHash}));if(!i.isValid)return r;var o=e.getClassNameById(i.id);return-1===n?(t.push(o),r=[].concat(r,[i])):(r.splice(n,1,i),t.splice(n,1,o)),r}),[]);var r=this.props.className,i=(void 0===r?"":r).split(/\s+/).filter((function(e){return!t.includes(e)&&!!e}));return t=t.concat(i),this.hasResponsive&&t.unshift(this.uniqueClassName),t},t.toStyle=function(){var e=this;return this.atoms.reduce((function(t,i){if(!i.isValid)return t;var n=p.theme.colors,o=Object.entries(i.style).reduce((function(t,i){var o,s=i[0],a=i[1],l=e.formatCssValue(r.jsKeyToCssKey(s),n[a]||a);return u({},t,((o={})[s]=l,o))}),{});return u({},t,o)}),{})},t.toRules=function(e){var t=this;void 0===e&&(e=!1);var i=this.config.mode.classPrefix,n=void 0===i?"":i,o=[],s=this.config.theme.breakpoints;this.atoms=this.atoms.sort((function(e,t){return parseInt(s[t.meta.breakpoint]||"0")-parseInt(s[e.meta.breakpoint]||"0")}));for(var a,u=function(){var i=a.value,s="",u=i.id,l=i.style,c=void 0===l?{}:l,d=i.meta;if(!i.isValid)return"continue";if(r.isEmptyObj(c))return"continue";var f=d.pseudo,p=d.pseudoPrefix,h=d.mode,m=d.breakpoint,y=void 0===m?"":m,g=d.childSelector,v=d.siblingSelector,b=d.parentClass,k=!!t.atoms.find((function(e){return e.styleKeys===i.styleKeys&&(y||e.meta.breakpoint)})),S=k||y?"."+t.uniqueClassName:"";if(!e&&!k&&i.inserted)return"continue";i.inserted=!0;var x=t.getClassNameById(u),A=d.global?d.global:S+"."+x;if(h&&(A="."+n+h+" "+A),g&&(A=A+" "+g),v&&(A=""+A+v),f){var w=p+f;b?A="."+b+w+" "+A:A+=w}s=A+" { "+t.styleToString(c,i.meta)+" }",y&&(s=t.makeResponsiveStyle(y,s)),o.push(s)},l=d(this.atoms);!(a=l()).done;)u();return o},t.getParsedProps=function(){var e=this.props,t=this.atoms;return r.isEmptyObj(e)?{}:Object.entries(e).reduce((function(e,r){var i=r[0],n=r[1];return/.*--(\d+)?[a-z]+$/i.test(i)||t.find((function(e){return[e.propKey,e.key,e.id,"css"].includes(i)}))||(e[i]=n),e}),{})},t.insertRules=function(){var e=this.toRules();g.insertStyles(e)},a(e,[{key:"uniqueClassName",get:function(){return r.objectToClassName(Object.keys(this.props))}},{key:"hasResponsive",get:function(){return this.atoms.some((function(e){return!!e.meta.breakpoint}))}},{key:"store",get:function(){return p}},{key:"config",get:function(){return p.config}},{key:"plugins",get:function(){return p.config.plugins}}]),e}();function x(e){for(var t=Object.entries(e),r=new S({}),i=0,n=t;i<n.length;i++){var o=n[i],s=o[0],a=o[1],u=new y({propKey:s,propValue:a,value:a,meta:{global:s},style:a});r.addAtom(u)}r.insertRules()}x({"*, ::before, ::after":{borderWidth:0,borderStyle:"solid",borderColor:"#d4d4d4",boxSizing:"border-box"}});var A=p.setConfig,w=p.getConfig,j=p.setTheme,C=p.getTheme,O=p.setMode,P=p.getMode,V=p.addAtom,K=p.composeAtom;exports.Atom=y,exports.Parser=S,exports.Store=f,exports.addAtom=V,exports.composeAtom=K,exports.createStyle=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var i=t.reduce((function(e,t){var r;return u({},e,"string"==typeof t?((r={})[t]=!0,r):{css:t})}),{}),n=new S(i),o=n.toStyle();return o},exports.css=function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];if(!t.length)return"";var n=new S(r.argsToProps(t));return n.insertRules(),n.getClassNames().join(" ")},exports.digitReg=m,exports.getConfig=w,exports.getMode=P,exports.getTheme=C,exports.injectGlobalStyle=x,exports.keyframes=function(e,t){var i=Object.entries(e).reduce((function(e,t){var i=t[0],n=Object.entries(t[1]).reduce((function(e,t){return e+(t[0]+": ")+t[1]+";"}),"");return e+(r.jsKeyToCssKey(i)+" {")+n+"}"}),""),n=t||"keyframes-"+r.hash(JSON.stringify(e));return g.insertStyles(["\n @keyframes "+n+" {\n "+i+"\n }\n "]),n},exports.setConfig=A,exports.setMode=O,exports.setTheme=j,exports.store=p,exports.styleSheet=g; | ||
//# sourceMappingURL=core.cjs.production.min.js.map |
@@ -1258,3 +1258,3 @@ import deepmerge from 'deepmerge'; | ||
var find = atoms.find(function (atom) { | ||
return [atom.propKey, atom.key, 'css'].includes(key); | ||
return [atom.propKey, atom.key, atom.id, 'css'].includes(key); | ||
}); | ||
@@ -1261,0 +1261,0 @@ if (!find) result[key] = value; |
{ | ||
"name": "@fower/core", | ||
"version": "1.41.0", | ||
"version": "1.42.0", | ||
"license": "MIT", | ||
@@ -25,9 +25,9 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@fower/atomic-props": "^1.41.0", | ||
"@fower/css-object-processor": "^1.41.0", | ||
"@fower/utils": "^1.41.0", | ||
"@fower/atomic-props": "^1.42.0", | ||
"@fower/css-object-processor": "^1.42.0", | ||
"@fower/utils": "^1.42.0", | ||
"deepmerge": "^4.2.2", | ||
"string-hash": "^1.1.3" | ||
}, | ||
"gitHead": "b86d6b0ca00b9edb3056236ac035faec55279752" | ||
"gitHead": "ccd3c129198ce8d1cad92af5400bd66671385e65" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
315892
Updated@fower/atomic-props@^1.42.0
Updated@fower/utils@^1.42.0