Created
October 20, 2021 07:06
-
-
Save thecodedrift/f84b450d9bc3e4e834098c4ad2caf6cf to your computer and use it in GitHub Desktop.
Revisions
-
thecodedrift created this gist
Oct 20, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ // just the changed bits // and definitely not elegant yet // withCommon: extract the top level CSS properties and magically push them down // this is probably something you'd want to cache function withCommon(v, list) { const common = list.filter(([k, v]) => !(typeof v == 'object' && v.constructor == Object)) return { ...common.reduce((merged, [k, vPrime]) => { merged[k] = vPrime return merged }, {}), ...v, } } function configToCss(config = {}, { target, className, prefix }) { return Object.fromEntries( Object.entries( merge( {}, ...Object.keys(config) .filter((key) => computed[key]) .map((key) => computed[key](config[key])), ...castArray(config.css || {}) ) ) .map(([k, v], idx, list) => { if (target === 'legacy') { return [k, v] } if (typeof v == 'object' && v.constructor == Object) { return [inWhere(k, { className, prefix }), withCommon(v, list)] } else { return null // drop all "common" props with our filter } }) .filter((v) => !!v) ) }