@fower/parser
Advanced tools
Comparing version 1.11.0 to 1.11.1
@@ -116,2 +116,3 @@ 'use strict'; | ||
this.traverseProps(props); | ||
this.autoDarkMode(); | ||
} | ||
@@ -235,2 +236,69 @@ | ||
} | ||
}; | ||
_proto.autoDarkMode = function autoDarkMode() { | ||
var colorMap = { | ||
white: 'black', | ||
black: 'white', | ||
'50': '900', | ||
'100': '800', | ||
'200': '700', | ||
'300': '600', | ||
'400': '500', | ||
'500': '400', | ||
'600': '300', | ||
'700': '200', | ||
'800': '100', | ||
'900': '50' | ||
}; | ||
var colorKeys = ['color', 'backgroundColor', 'borderColor']; | ||
var darkAtoms = []; | ||
/** TODO: hack for auto dark mode, need to refactor */ | ||
for (var _iterator3 = _createForOfIteratorHelperLoose(this.atoms), _step3; !(_step3 = _iterator3()).done;) { | ||
var atom$1 = _step3.value; | ||
if (colorKeys.includes(atom$1.type) && !atom$1.meta.mode) { | ||
var find = this.atoms.find(function (i) { | ||
return colorKeys.includes(i.type) && i.meta.mode === 'dark'; | ||
}); | ||
if (find) continue; | ||
var entries = Object.entries(atom$1.style); | ||
if (!(entries != null && entries.length)) continue; | ||
var _entries$ = entries[0], | ||
colorValue = _entries$[1]; | ||
var _ref2 = colorValue.match(/^([a-z]+)(\d+)$/i) || [], | ||
mapKey = _ref2[2]; | ||
if (['white', 'black'].includes(colorValue)) mapKey = colorValue; | ||
var str = JSON.stringify(atom$1).replaceAll(mapKey, colorMap[mapKey]); | ||
if (mapKey === 'white') str = str.replaceAll('White', 'Black'); | ||
if (mapKey === 'black') str = str.replaceAll('Black', 'White'); | ||
var cloned = JSON.parse(str); | ||
var _darkAtom = new atom.Atom(_extends({}, cloned, { | ||
className: '', | ||
propKey: cloned.propKey + '--dark', | ||
meta: _extends({}, cloned.meta, { | ||
mode: 'dark' | ||
}) | ||
})); | ||
_darkAtom.createClassName(this.config.prefix); | ||
var cachedAtom = atomCache.get(_darkAtom.id); | ||
if (cachedAtom) { | ||
darkAtoms.push(cachedAtom); | ||
} else { | ||
darkAtoms.push(_darkAtom); | ||
} | ||
} | ||
} | ||
for (var _i2 = 0, _darkAtoms = darkAtoms; _i2 < _darkAtoms.length; _i2++) { | ||
var darkAtom = _darkAtoms[_i2]; | ||
this.addAtom(darkAtom); | ||
} | ||
} | ||
@@ -289,5 +357,5 @@ /** | ||
colorPostfix = meta.colorPostfix; | ||
return Object.entries(style).reduce(function (r, _ref2) { | ||
var key = _ref2[0], | ||
value = _ref2[1]; | ||
return Object.entries(style).reduce(function (r, _ref3) { | ||
var key = _ref3[0], | ||
value = _ref3[1]; | ||
var cssKey = utils.jsKeyToCssKey(key); | ||
@@ -318,4 +386,4 @@ var posfix = important ? ' !important' : ''; | ||
for (var _i2 = 0, _entries2 = entries; _i2 < _entries2.length; _i2++) { | ||
var _entries2$_i = _entries2[_i2], | ||
for (var _i3 = 0, _entries2 = entries; _i3 < _entries2.length; _i3++) { | ||
var _entries2$_i = _entries2[_i3], | ||
mode = _entries2$_i[0], | ||
@@ -374,4 +442,4 @@ colors = _entries2$_i[1]; | ||
_proto.mutateAtom = function mutateAtom(atom) { | ||
for (var _iterator3 = _createForOfIteratorHelperLoose(this.plugins), _step3; !(_step3 = _iterator3()).done;) { | ||
var plugin = _step3.value; | ||
for (var _iterator4 = _createForOfIteratorHelperLoose(this.plugins), _step4; !(_step4 = _iterator4()).done;) { | ||
var plugin = _step4.value; | ||
if (!(plugin.isMatch != null && plugin.isMatch(atom.key))) continue; | ||
@@ -398,4 +466,4 @@ | ||
for (var _iterator4 = _createForOfIteratorHelperLoose(this.plugins), _step4; !(_step4 = _iterator4()).done;) { | ||
var _plugin = _step4.value; | ||
for (var _iterator5 = _createForOfIteratorHelperLoose(this.plugins), _step5; !(_step5 = _iterator5()).done;) { | ||
var _plugin = _step5.value; | ||
if (!(_plugin.isMatch != null && _plugin.isMatch(atom.key))) continue; | ||
@@ -425,12 +493,12 @@ | ||
for (var _iterator5 = _createForOfIteratorHelperLoose(parsed), _step5; !(_step5 = _iterator5()).done;) { | ||
var _step5$value = _step5.value, | ||
selector = _step5$value.selector, | ||
selectorType = _step5$value.selectorType, | ||
style = _step5$value.style; | ||
for (var _iterator6 = _createForOfIteratorHelperLoose(parsed), _step6; !(_step6 = _iterator6()).done;) { | ||
var _step6$value = _step6.value, | ||
selector = _step6$value.selector, | ||
selectorType = _step6$value.selectorType, | ||
style = _step6$value.style; | ||
var entries = Object.entries(style); | ||
if (!entries.length) continue; | ||
var _entries$ = entries[0], | ||
propKey = _entries$[0], | ||
_propValue = _entries$[1]; | ||
var _entries$2 = entries[0], | ||
propKey = _entries$2[0], | ||
_propValue = _entries$2[1]; | ||
var option = { | ||
@@ -527,7 +595,7 @@ propKey: propKey, | ||
var colors = store.store.theme.colors; | ||
var style = Object.entries(atom.style).reduce(function (c, _ref3) { | ||
var style = Object.entries(atom.style).reduce(function (c, _ref4) { | ||
var _extends3; | ||
var key = _ref3[0], | ||
value = _ref3[1]; | ||
var key = _ref4[0], | ||
value = _ref4[1]; | ||
@@ -561,63 +629,4 @@ var cssValue = _this2.formatCssValue(utils.jsKeyToCssKey(key), colors[value] || value); | ||
return parseInt(b.meta.breakpoint || '0') - parseInt(a.meta.breakpoint || '0'); | ||
}); | ||
var colorMap = { | ||
white: 'black', | ||
black: 'white', | ||
'50': '900', | ||
'100': '800', | ||
'200': '700', | ||
'300': '600', | ||
'400': '500', | ||
'500': '400', | ||
'600': '300', | ||
'700': '200', | ||
'800': '100', | ||
'900': '50' | ||
}; | ||
var colorKeys = ['color', 'backgroundColor', 'borderColor']; | ||
var darkAtoms = []; | ||
/** TODO: hack for auto dark mode, need to refactor */ | ||
}); // console.log('this.atoms-----:', this.atoms) | ||
for (var _iterator6 = _createForOfIteratorHelperLoose(this.atoms), _step6; !(_step6 = _iterator6()).done;) { | ||
var atom$1 = _step6.value; | ||
if (colorKeys.includes(atom$1.type) && !atom$1.meta.mode) { | ||
var find = this.atoms.find(function (i) { | ||
return colorKeys.includes(i.type) && i.meta.mode === 'dark'; | ||
}); | ||
if (find) continue; | ||
var entries = Object.entries(atom$1.style); | ||
if (!(entries != null && entries.length)) continue; | ||
var _entries$2 = entries[0], | ||
colorValue = _entries$2[1]; | ||
var _ref4 = colorValue.match(/^([a-z]+)(\d+)$/i) || [], | ||
mapKey = _ref4[2]; | ||
if (['white', 'black'].includes(colorValue)) mapKey = colorValue; | ||
var str = JSON.stringify(atom$1).replaceAll(mapKey, colorMap[mapKey]); | ||
if (mapKey === 'white') str = str.replaceAll('White', 'Black'); | ||
if (mapKey === 'black') str = str.replaceAll('Black', 'White'); | ||
var cloned = JSON.parse(str); | ||
var _darkAtom = new atom.Atom(_extends({}, cloned, { | ||
className: '', | ||
propKey: cloned.propKey + '--dark', | ||
meta: _extends({}, cloned.meta, { | ||
mode: 'dark' | ||
}) | ||
})); | ||
_darkAtom.createClassName(this.config.prefix); | ||
darkAtoms.push(_darkAtom); | ||
} | ||
} | ||
for (var _i3 = 0, _darkAtoms = darkAtoms; _i3 < _darkAtoms.length; _i3++) { | ||
var darkAtom = _darkAtoms[_i3]; | ||
this.addAtom(darkAtom); | ||
} // console.log('this.atoms-----:', this.atoms) | ||
var _loop = function _loop() { | ||
@@ -624,0 +633,0 @@ var atom = _step7.value; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@fower/atom"),t=require("@fower/store"),r=require("@fower/color-helper"),n=require("@fower/sheet"),o=require("@fower/css-object-processor"),s=require("@fower/utils");function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function l(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 a(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)?a(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var c=new Map,u=/(-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)$/,d=["children","onClick","onChange","onBlur","className","placeholder"];exports.Parser=function(){function a(e){void 0===e&&(e={}),this.props=e,this.atoms=[],this.traverseProps(e)}var f,m=a.prototype;return m.traverseProps=function(r){if(!s.isEmptyObj(r)){var n=this.config,o=n.pseudos,a=void 0===o?[]:o,c=n.theme||{},u=c.breakpoints,f=c.modes,m=Object.keys(u),p=f||[],h=a,v=r.excludedProps,y=void 0===v?[]:v,b=Object.entries(r);if(null!=r&&r.className)for(var g,k=l(r.className.split(/\s+/));!(g=k()).done;)b.push([g.value,!0]);for(var A=0,S=b;A<S.length;A++){var j=S[A],C=j[0],O=j[1];if(!y.includes(C)&&!d.includes(C)&&this.isValidProp(C,O))if("css"!==C){if(C.startsWith("_")){var N=C.replace(/^_/,""),w=Array.isArray(O)?O.reduce((function(e,t){var r;return i({},e,((r={})[t]=!0,r))}),{}):O;if(p.includes(N)){this.parseCSSObject(w,{mode:N});continue}if(m.includes(N)){this.parseCSSObject(w,{breakpoint:u[N]});continue}if(h.includes(N)){this.parseCSSObject(w,{pseudo:":"+N});continue}}var K=t.store.compositions.get(C);if(K){this.parseCSSObject(K,{});var P=new e.Atom({propKey:C,propValue:O});P.handled=!0,P.style={},P.createClassName(t.store.config.prefix),this.addAtom(P)}else{var x=new e.Atom({propKey:C,propValue:O});try{this.mutateAtom(x),x.handled&&this.addAtom(x)}catch(e){continue}}}else this.parseCSSObject(O)}for(var V,T=l(this.plugins);!(V=T()).done;){var q=V.value;q.afterAtomStyleCreate&&q.afterAtomStyleCreate(this)}}},m.formatCssValue=function(e,r){if(!u.test(e))return r;var n;if(s.isPercentNumber(String(r)))return String(r).replace("p","%");if(!s.isNumber(r))return r;if((n=Number(r))<1&&n>0)return 100*n+"%";var o=t.store.config;return"none"!==o.unit?o.transformUnit?o.transformUnit(n):r+t.store.config.unit:n},m.styleToString=function(e,n){var o=this,i=n.important,a=n.colorPostfix;return Object.entries(e).reduce((function(e,n){var l=n[1],c=s.jsKeyToCssKey(n[0]),u=i?" !important":"",d=t.store.theme.colors;return e+(c+": ")+(l=a?r.formatColor(d[l]||l,a):o.formatCssValue(c,d[l]||l))+u+";"}),"")},m.addAtom=function(e){c.get(e.id)||c.set(e.id,e);for(var t=this.config.theme.colors.modes,r=0,n=Object.entries(void 0===t?{}:t);r<n.length;r++){var o=n[r],s=o[0],a=o[1];if(e.style){var l=Object.entries(e.style);if(l.length){var u=l[0],d=u[0],f=a[u[1]];if(f){var m="--"+s,p=JSON.parse(JSON.stringify(e));p.className=e.className+m,p.key=e.key+m,p.id=e.id+m,p.meta=i({mode:s},e.meta),p.style[d]=f,this.atoms.push(p)}}}}this.atoms.push(e)},m.isValidProp=function(e,t){return"css"===e||!!e.startsWith("_")||!!["string","boolean","number","undefined"].includes(typeof t)},m.mutateAtom=function(e){for(var r,n=l(this.plugins);!(r=n()).done;){var o=r.value;null!=o.isMatch&&o.isMatch(e.key)&&o.beforeHandleAtom&&(e=o.beforeHandleAtom(e,this))}var s=c.get(e.id);if(s)throw this.addAtom(s),new Error("atom is cached, add to this.atoms derectly, no need to mutate");if((e=e.preprocessAtom(t.store.config)).handled)throw this.addAtom(e),new Error("atom is handled, add to this.atoms derectly ,no need to mutate");for(var i,a=l(this.plugins);!(i=a()).done;){var u=i.value;if(null!=u.isMatch&&u.isMatch(e.key)){u.beforeHandleAtom&&(e=u.beforeHandleAtom(e,this)),u.handleAtom&&(e=null==u.handleAtom?void 0:u.handleAtom(e,this)),e.createClassName(t.store.config.prefix),e.handled=!0;break}}},m.parseCSSObject=function(t,r){void 0===r&&(r={});for(var n,i=o.parse(t),a=s.objectToClassName(t),c=l(i);!(n=c()).done;){var u=n.value,d=u.selector,f=u.selectorType,m=u.style,p=Object.entries(m);if(p.length){var h=p[0],v={propKey:h[0],propValue:h[1],meta:r};"pseudo"===f&&v.meta&&(v.meta.pseudo=d),"child"===f&&v.meta&&(v.meta.childSelector=d);var y=new e.Atom(v),b="void"===f;try{this.mutateAtom(y)}catch(e){continue}y.style||(y.style=m,y.id=s.objectToClassName({style:m}),y.className=b?s.objectToClassName(m):a,y.handled=!0),this.addAtom(y)}}},m.makeResponsiveStyle=function(e,t){return"@media (min-width: "+e+") {"+t+"}"},m.getClassNames=function(){var e=[];this.atoms.reduce((function(t,r){var n=t.findIndex((function(e){return e.styleKeysHash===r.styleKeysHash}));return r.isValid?(-1===n?(e.push(r.className),t=[].concat(t,[r])):(t.splice(n,1,r),e.splice(n,1,r.className)),t):t}),[]);var t=this.props.className,r=(void 0===t?"":t).split(/\s+/).filter((function(t){return!e.includes(t)&&!!t}));return e=e.concat(r),this.hasResponsive&&e.unshift(this.uniqueClassName),e},m.toStyle=function(){var e=this;return this.atoms.reduce((function(r,n){if(!n.isValid)return r;var o=t.store.theme.colors,a=Object.entries(n.style).reduce((function(t,r){var n,a=r[0],l=r[1],c=e.formatCssValue(s.jsKeyToCssKey(a),o[l]||l);return i({},t,((n={})[a]=c,n))}),{});return i({},r,a)}),{})},m.toRules=function(t){var r=this;void 0===t&&(t=!1);var n=this.config.theme.modePrefix,o=void 0===n?"":n,a=[];this.atoms=this.atoms.sort((function(e,t){return parseInt(t.meta.breakpoint||"0")-parseInt(e.meta.breakpoint||"0")}));for(var c,u={white:"black",black:"white",50:"900",100:"800",200:"700",300:"600",400:"500",500:"400",600:"300",700:"200",800:"100",900:"50"},d=["color","backgroundColor","borderColor"],f=[],m=l(this.atoms);!(c=m()).done;){var p=c.value;if(d.includes(p.type)&&!p.meta.mode){if(this.atoms.find((function(e){return d.includes(e.type)&&"dark"===e.meta.mode})))continue;var h=Object.entries(p.style);if(null==h||!h.length)continue;var v=h[0][1],y=(v.match(/^([a-z]+)(\d+)$/i)||[])[2];["white","black"].includes(v)&&(y=v);var b=JSON.stringify(p).replaceAll(y,u[y]);"white"===y&&(b=b.replaceAll("White","Black")),"black"===y&&(b=b.replaceAll("Black","White"));var g=JSON.parse(b),k=new e.Atom(i({},g,{className:"",propKey:g.propKey+"--dark",meta:i({},g.meta,{mode:"dark"})}));k.createClassName(this.config.prefix),f.push(k)}}for(var A=0,S=f;A<S.length;A++)this.addAtom(S[A]);for(var j,C=function(){var e=j.value,n="",i=e.className,l=e.style,c=void 0===l?{}:l;if(!e.isValid)return"continue";if(s.isEmptyObj(c))return"continue";if(!t&&e.inserted)return"continue";e.inserted=!0;var u=e.meta,d=u.pseudo,f=u.mode,m=u.breakpoint,p=void 0===m?"":m,h=u.childSelector,v=(r.atoms.find((function(t){return t.styleKeys===e.styleKeys&&(e.meta.breakpoint||t.meta.breakpoint)}))||e.meta.breakpoint?"."+r.uniqueClassName:"")+"."+i;d&&(v+=d),f&&(v="."+o+f+" "+v),h&&(v=v+" "+h),n=v+" { "+r.styleToString(c,e.meta)+" }",p&&(n=r.makeResponsiveStyle(p,n)),a.push(n)},O=l(this.atoms);!(j=O()).done;)C();return a},m.getParsedProps=function(){var e=this.props,t=this.atoms;return s.isEmptyObj(e)?{}:Object.entries(e).reduce((function(e,r){var n=r[0],o=r[1];return t.find((function(e){return[e.propKey,e.key,e.id,"css"].includes(n)}))||(e[n]=o),e}),{})},m.insertRule=function(){var e=this.toRules();n.styleSheet.insertStyles(e)},(f=[{key:"uniqueClassName",get:function(){return s.objectToClassName(Object.keys(this.props))}},{key:"hasResponsive",get:function(){return!!this.atoms.find((function(e){return!!e.meta.breakpoint}))}},{key:"config",get:function(){return t.store.config}},{key:"plugins",get:function(){return t.store.config.plugins}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(a.prototype,f),a}(),exports.atomCache=c; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@fower/atom"),t=require("@fower/store"),r=require("@fower/color-helper"),n=require("@fower/sheet"),o=require("@fower/css-object-processor"),s=require("@fower/utils");function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function l(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 a(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)?a(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u=new Map,c=/(-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)$/,d=["children","onClick","onChange","onBlur","className","placeholder"];exports.Parser=function(){function a(e){void 0===e&&(e={}),this.props=e,this.atoms=[],this.traverseProps(e),this.autoDarkMode()}var f,m=a.prototype;return m.traverseProps=function(r){if(!s.isEmptyObj(r)){var n=this.config,o=n.pseudos,a=void 0===o?[]:o,u=n.theme||{},c=u.breakpoints,f=u.modes,m=Object.keys(c),p=f||[],h=a,v=r.excludedProps,y=void 0===v?[]:v,b=Object.entries(r);if(null!=r&&r.className)for(var g,k=l(r.className.split(/\s+/));!(g=k()).done;)b.push([g.value,!0]);for(var A=0,S=b;A<S.length;A++){var j=S[A],C=j[0],O=j[1];if(!y.includes(C)&&!d.includes(C)&&this.isValidProp(C,O))if("css"!==C){if(C.startsWith("_")){var N=C.replace(/^_/,""),w=Array.isArray(O)?O.reduce((function(e,t){var r;return i({},e,((r={})[t]=!0,r))}),{}):O;if(p.includes(N)){this.parseCSSObject(w,{mode:N});continue}if(m.includes(N)){this.parseCSSObject(w,{breakpoint:c[N]});continue}if(h.includes(N)){this.parseCSSObject(w,{pseudo:":"+N});continue}}var K=t.store.compositions.get(C);if(K){this.parseCSSObject(K,{});var P=new e.Atom({propKey:C,propValue:O});P.handled=!0,P.style={},P.createClassName(t.store.config.prefix),this.addAtom(P)}else{var x=new e.Atom({propKey:C,propValue:O});try{this.mutateAtom(x),x.handled&&this.addAtom(x)}catch(e){continue}}}else this.parseCSSObject(O)}for(var V,T=l(this.plugins);!(V=T()).done;){var q=V.value;q.afterAtomStyleCreate&&q.afterAtomStyleCreate(this)}}},m.autoDarkMode=function(){for(var t,r={white:"black",black:"white",50:"900",100:"800",200:"700",300:"600",400:"500",500:"400",600:"300",700:"200",800:"100",900:"50"},n=["color","backgroundColor","borderColor"],o=[],s=l(this.atoms);!(t=s()).done;){var a=t.value;if(n.includes(a.type)&&!a.meta.mode){if(this.atoms.find((function(e){return n.includes(e.type)&&"dark"===e.meta.mode})))continue;var c=Object.entries(a.style);if(null==c||!c.length)continue;var d=c[0][1],f=(d.match(/^([a-z]+)(\d+)$/i)||[])[2];["white","black"].includes(d)&&(f=d);var m=JSON.stringify(a).replaceAll(f,r[f]);"white"===f&&(m=m.replaceAll("White","Black")),"black"===f&&(m=m.replaceAll("Black","White"));var p=JSON.parse(m),h=new e.Atom(i({},p,{className:"",propKey:p.propKey+"--dark",meta:i({},p.meta,{mode:"dark"})}));h.createClassName(this.config.prefix);var v=u.get(h.id);o.push(v||h)}}for(var y=0,b=o;y<b.length;y++)this.addAtom(b[y])},m.formatCssValue=function(e,r){if(!c.test(e))return r;var n;if(s.isPercentNumber(String(r)))return String(r).replace("p","%");if(!s.isNumber(r))return r;if((n=Number(r))<1&&n>0)return 100*n+"%";var o=t.store.config;return"none"!==o.unit?o.transformUnit?o.transformUnit(n):r+t.store.config.unit:n},m.styleToString=function(e,n){var o=this,i=n.important,a=n.colorPostfix;return Object.entries(e).reduce((function(e,n){var l=n[1],u=s.jsKeyToCssKey(n[0]),c=i?" !important":"",d=t.store.theme.colors;return e+(u+": ")+(l=a?r.formatColor(d[l]||l,a):o.formatCssValue(u,d[l]||l))+c+";"}),"")},m.addAtom=function(e){u.get(e.id)||u.set(e.id,e);for(var t=this.config.theme.colors.modes,r=0,n=Object.entries(void 0===t?{}:t);r<n.length;r++){var o=n[r],s=o[0],a=o[1];if(e.style){var l=Object.entries(e.style);if(l.length){var c=l[0],d=c[0],f=a[c[1]];if(f){var m="--"+s,p=JSON.parse(JSON.stringify(e));p.className=e.className+m,p.key=e.key+m,p.id=e.id+m,p.meta=i({mode:s},e.meta),p.style[d]=f,this.atoms.push(p)}}}}this.atoms.push(e)},m.isValidProp=function(e,t){return"css"===e||!!e.startsWith("_")||!!["string","boolean","number","undefined"].includes(typeof t)},m.mutateAtom=function(e){for(var r,n=l(this.plugins);!(r=n()).done;){var o=r.value;null!=o.isMatch&&o.isMatch(e.key)&&o.beforeHandleAtom&&(e=o.beforeHandleAtom(e,this))}var s=u.get(e.id);if(s)throw this.addAtom(s),new Error("atom is cached, add to this.atoms derectly, no need to mutate");if((e=e.preprocessAtom(t.store.config)).handled)throw this.addAtom(e),new Error("atom is handled, add to this.atoms derectly ,no need to mutate");for(var i,a=l(this.plugins);!(i=a()).done;){var c=i.value;if(null!=c.isMatch&&c.isMatch(e.key)){c.beforeHandleAtom&&(e=c.beforeHandleAtom(e,this)),c.handleAtom&&(e=null==c.handleAtom?void 0:c.handleAtom(e,this)),e.createClassName(t.store.config.prefix),e.handled=!0;break}}},m.parseCSSObject=function(t,r){void 0===r&&(r={});for(var n,i=o.parse(t),a=s.objectToClassName(t),u=l(i);!(n=u()).done;){var c=n.value,d=c.selector,f=c.selectorType,m=c.style,p=Object.entries(m);if(p.length){var h=p[0],v={propKey:h[0],propValue:h[1],meta:r};"pseudo"===f&&v.meta&&(v.meta.pseudo=d),"child"===f&&v.meta&&(v.meta.childSelector=d);var y=new e.Atom(v),b="void"===f;try{this.mutateAtom(y)}catch(e){continue}y.style||(y.style=m,y.id=s.objectToClassName({style:m}),y.className=b?s.objectToClassName(m):a,y.handled=!0),this.addAtom(y)}}},m.makeResponsiveStyle=function(e,t){return"@media (min-width: "+e+") {"+t+"}"},m.getClassNames=function(){var e=[];this.atoms.reduce((function(t,r){var n=t.findIndex((function(e){return e.styleKeysHash===r.styleKeysHash}));return r.isValid?(-1===n?(e.push(r.className),t=[].concat(t,[r])):(t.splice(n,1,r),e.splice(n,1,r.className)),t):t}),[]);var t=this.props.className,r=(void 0===t?"":t).split(/\s+/).filter((function(t){return!e.includes(t)&&!!t}));return e=e.concat(r),this.hasResponsive&&e.unshift(this.uniqueClassName),e},m.toStyle=function(){var e=this;return this.atoms.reduce((function(r,n){if(!n.isValid)return r;var o=t.store.theme.colors,a=Object.entries(n.style).reduce((function(t,r){var n,a=r[0],l=r[1],u=e.formatCssValue(s.jsKeyToCssKey(a),o[l]||l);return i({},t,((n={})[a]=u,n))}),{});return i({},r,a)}),{})},m.toRules=function(e){var t=this;void 0===e&&(e=!1);var r=this.config.theme.modePrefix,n=void 0===r?"":r,o=[];this.atoms=this.atoms.sort((function(e,t){return parseInt(t.meta.breakpoint||"0")-parseInt(e.meta.breakpoint||"0")}));for(var i,a=function(){var r=i.value,a="",l=r.className,u=r.style,c=void 0===u?{}:u;if(!r.isValid)return"continue";if(s.isEmptyObj(c))return"continue";if(!e&&r.inserted)return"continue";r.inserted=!0;var d=r.meta,f=d.pseudo,m=d.mode,p=d.breakpoint,h=void 0===p?"":p,v=d.childSelector,y=(t.atoms.find((function(e){return e.styleKeys===r.styleKeys&&(r.meta.breakpoint||e.meta.breakpoint)}))||r.meta.breakpoint?"."+t.uniqueClassName:"")+"."+l;f&&(y+=f),m&&(y="."+n+m+" "+y),v&&(y=y+" "+v),a=y+" { "+t.styleToString(c,r.meta)+" }",h&&(a=t.makeResponsiveStyle(h,a)),o.push(a)},u=l(this.atoms);!(i=u()).done;)a();return o},m.getParsedProps=function(){var e=this.props,t=this.atoms;return s.isEmptyObj(e)?{}:Object.entries(e).reduce((function(e,r){var n=r[0],o=r[1];return t.find((function(e){return[e.propKey,e.key,e.id,"css"].includes(n)}))||(e[n]=o),e}),{})},m.insertRule=function(){var e=this.toRules();n.styleSheet.insertStyles(e)},(f=[{key:"uniqueClassName",get:function(){return s.objectToClassName(Object.keys(this.props))}},{key:"hasResponsive",get:function(){return!!this.atoms.find((function(e){return!!e.meta.breakpoint}))}},{key:"config",get:function(){return t.store.config}},{key:"plugins",get:function(){return t.store.config.plugins}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(a.prototype,f),a}(),exports.atomCache=u; | ||
//# sourceMappingURL=parser.cjs.production.min.js.map |
@@ -25,2 +25,3 @@ import { Atom } from '@fower/atom'; | ||
traverseProps(props: Props): void; | ||
autoDarkMode(): void; | ||
/** | ||
@@ -27,0 +28,0 @@ * Get final css value |
@@ -112,2 +112,3 @@ import { Atom } from '@fower/atom'; | ||
this.traverseProps(props); | ||
this.autoDarkMode(); | ||
} | ||
@@ -231,2 +232,69 @@ | ||
} | ||
}; | ||
_proto.autoDarkMode = function autoDarkMode() { | ||
var colorMap = { | ||
white: 'black', | ||
black: 'white', | ||
'50': '900', | ||
'100': '800', | ||
'200': '700', | ||
'300': '600', | ||
'400': '500', | ||
'500': '400', | ||
'600': '300', | ||
'700': '200', | ||
'800': '100', | ||
'900': '50' | ||
}; | ||
var colorKeys = ['color', 'backgroundColor', 'borderColor']; | ||
var darkAtoms = []; | ||
/** TODO: hack for auto dark mode, need to refactor */ | ||
for (var _iterator3 = _createForOfIteratorHelperLoose(this.atoms), _step3; !(_step3 = _iterator3()).done;) { | ||
var atom = _step3.value; | ||
if (colorKeys.includes(atom.type) && !atom.meta.mode) { | ||
var find = this.atoms.find(function (i) { | ||
return colorKeys.includes(i.type) && i.meta.mode === 'dark'; | ||
}); | ||
if (find) continue; | ||
var entries = Object.entries(atom.style); | ||
if (!(entries != null && entries.length)) continue; | ||
var _entries$ = entries[0], | ||
colorValue = _entries$[1]; | ||
var _ref2 = colorValue.match(/^([a-z]+)(\d+)$/i) || [], | ||
mapKey = _ref2[2]; | ||
if (['white', 'black'].includes(colorValue)) mapKey = colorValue; | ||
var str = JSON.stringify(atom).replaceAll(mapKey, colorMap[mapKey]); | ||
if (mapKey === 'white') str = str.replaceAll('White', 'Black'); | ||
if (mapKey === 'black') str = str.replaceAll('Black', 'White'); | ||
var cloned = JSON.parse(str); | ||
var _darkAtom = new Atom(_extends({}, cloned, { | ||
className: '', | ||
propKey: cloned.propKey + '--dark', | ||
meta: _extends({}, cloned.meta, { | ||
mode: 'dark' | ||
}) | ||
})); | ||
_darkAtom.createClassName(this.config.prefix); | ||
var cachedAtom = atomCache.get(_darkAtom.id); | ||
if (cachedAtom) { | ||
darkAtoms.push(cachedAtom); | ||
} else { | ||
darkAtoms.push(_darkAtom); | ||
} | ||
} | ||
} | ||
for (var _i2 = 0, _darkAtoms = darkAtoms; _i2 < _darkAtoms.length; _i2++) { | ||
var darkAtom = _darkAtoms[_i2]; | ||
this.addAtom(darkAtom); | ||
} | ||
} | ||
@@ -285,5 +353,5 @@ /** | ||
colorPostfix = meta.colorPostfix; | ||
return Object.entries(style).reduce(function (r, _ref2) { | ||
var key = _ref2[0], | ||
value = _ref2[1]; | ||
return Object.entries(style).reduce(function (r, _ref3) { | ||
var key = _ref3[0], | ||
value = _ref3[1]; | ||
var cssKey = jsKeyToCssKey(key); | ||
@@ -314,4 +382,4 @@ var posfix = important ? ' !important' : ''; | ||
for (var _i2 = 0, _entries2 = entries; _i2 < _entries2.length; _i2++) { | ||
var _entries2$_i = _entries2[_i2], | ||
for (var _i3 = 0, _entries2 = entries; _i3 < _entries2.length; _i3++) { | ||
var _entries2$_i = _entries2[_i3], | ||
mode = _entries2$_i[0], | ||
@@ -370,4 +438,4 @@ colors = _entries2$_i[1]; | ||
_proto.mutateAtom = function mutateAtom(atom) { | ||
for (var _iterator3 = _createForOfIteratorHelperLoose(this.plugins), _step3; !(_step3 = _iterator3()).done;) { | ||
var plugin = _step3.value; | ||
for (var _iterator4 = _createForOfIteratorHelperLoose(this.plugins), _step4; !(_step4 = _iterator4()).done;) { | ||
var plugin = _step4.value; | ||
if (!(plugin.isMatch != null && plugin.isMatch(atom.key))) continue; | ||
@@ -394,4 +462,4 @@ | ||
for (var _iterator4 = _createForOfIteratorHelperLoose(this.plugins), _step4; !(_step4 = _iterator4()).done;) { | ||
var _plugin = _step4.value; | ||
for (var _iterator5 = _createForOfIteratorHelperLoose(this.plugins), _step5; !(_step5 = _iterator5()).done;) { | ||
var _plugin = _step5.value; | ||
if (!(_plugin.isMatch != null && _plugin.isMatch(atom.key))) continue; | ||
@@ -421,12 +489,12 @@ | ||
for (var _iterator5 = _createForOfIteratorHelperLoose(parsed), _step5; !(_step5 = _iterator5()).done;) { | ||
var _step5$value = _step5.value, | ||
selector = _step5$value.selector, | ||
selectorType = _step5$value.selectorType, | ||
style = _step5$value.style; | ||
for (var _iterator6 = _createForOfIteratorHelperLoose(parsed), _step6; !(_step6 = _iterator6()).done;) { | ||
var _step6$value = _step6.value, | ||
selector = _step6$value.selector, | ||
selectorType = _step6$value.selectorType, | ||
style = _step6$value.style; | ||
var entries = Object.entries(style); | ||
if (!entries.length) continue; | ||
var _entries$ = entries[0], | ||
propKey = _entries$[0], | ||
_propValue = _entries$[1]; | ||
var _entries$2 = entries[0], | ||
propKey = _entries$2[0], | ||
_propValue = _entries$2[1]; | ||
var option = { | ||
@@ -523,7 +591,7 @@ propKey: propKey, | ||
var colors = store.theme.colors; | ||
var style = Object.entries(atom.style).reduce(function (c, _ref3) { | ||
var style = Object.entries(atom.style).reduce(function (c, _ref4) { | ||
var _extends3; | ||
var key = _ref3[0], | ||
value = _ref3[1]; | ||
var key = _ref4[0], | ||
value = _ref4[1]; | ||
@@ -557,63 +625,4 @@ var cssValue = _this2.formatCssValue(jsKeyToCssKey(key), colors[value] || value); | ||
return parseInt(b.meta.breakpoint || '0') - parseInt(a.meta.breakpoint || '0'); | ||
}); | ||
var colorMap = { | ||
white: 'black', | ||
black: 'white', | ||
'50': '900', | ||
'100': '800', | ||
'200': '700', | ||
'300': '600', | ||
'400': '500', | ||
'500': '400', | ||
'600': '300', | ||
'700': '200', | ||
'800': '100', | ||
'900': '50' | ||
}; | ||
var colorKeys = ['color', 'backgroundColor', 'borderColor']; | ||
var darkAtoms = []; | ||
/** TODO: hack for auto dark mode, need to refactor */ | ||
}); // console.log('this.atoms-----:', this.atoms) | ||
for (var _iterator6 = _createForOfIteratorHelperLoose(this.atoms), _step6; !(_step6 = _iterator6()).done;) { | ||
var atom = _step6.value; | ||
if (colorKeys.includes(atom.type) && !atom.meta.mode) { | ||
var find = this.atoms.find(function (i) { | ||
return colorKeys.includes(i.type) && i.meta.mode === 'dark'; | ||
}); | ||
if (find) continue; | ||
var entries = Object.entries(atom.style); | ||
if (!(entries != null && entries.length)) continue; | ||
var _entries$2 = entries[0], | ||
colorValue = _entries$2[1]; | ||
var _ref4 = colorValue.match(/^([a-z]+)(\d+)$/i) || [], | ||
mapKey = _ref4[2]; | ||
if (['white', 'black'].includes(colorValue)) mapKey = colorValue; | ||
var str = JSON.stringify(atom).replaceAll(mapKey, colorMap[mapKey]); | ||
if (mapKey === 'white') str = str.replaceAll('White', 'Black'); | ||
if (mapKey === 'black') str = str.replaceAll('Black', 'White'); | ||
var cloned = JSON.parse(str); | ||
var _darkAtom = new Atom(_extends({}, cloned, { | ||
className: '', | ||
propKey: cloned.propKey + '--dark', | ||
meta: _extends({}, cloned.meta, { | ||
mode: 'dark' | ||
}) | ||
})); | ||
_darkAtom.createClassName(this.config.prefix); | ||
darkAtoms.push(_darkAtom); | ||
} | ||
} | ||
for (var _i3 = 0, _darkAtoms = darkAtoms; _i3 < _darkAtoms.length; _i3++) { | ||
var darkAtom = _darkAtoms[_i3]; | ||
this.addAtom(darkAtom); | ||
} // console.log('this.atoms-----:', this.atoms) | ||
var _loop = function _loop() { | ||
@@ -620,0 +629,0 @@ var atom = _step7.value; |
{ | ||
"name": "@fower/parser", | ||
"version": "1.11.0", | ||
"version": "1.11.1", | ||
"license": "MIT", | ||
@@ -24,9 +24,9 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@fower/atom": "^1.11.0", | ||
"@fower/css-object-processor": "^1.11.0", | ||
"@fower/sheet": "^1.11.0", | ||
"@fower/store": "^1.11.0", | ||
"@fower/utils": "^1.11.0" | ||
"@fower/atom": "^1.11.1", | ||
"@fower/css-object-processor": "^1.11.1", | ||
"@fower/sheet": "^1.11.1", | ||
"@fower/store": "^1.11.1", | ||
"@fower/utils": "^1.11.1" | ||
}, | ||
"gitHead": "e4ad8d9cf0c7fc3972c42ab85d034030857d99e4" | ||
"gitHead": "5d21b31f330a83dd6af0ebc9b6b3392cc2984201" | ||
} |
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
146073
1315
Updated@fower/atom@^1.11.1
Updated@fower/sheet@^1.11.1
Updated@fower/store@^1.11.1
Updated@fower/utils@^1.11.1