@chakra-v2/styled-system
Version:
Style function for css-in-js building component libraries
35 lines (31 loc) • 909 B
JavaScript
;
var utils = require('@chakra-v2/utils');
var pseudos = require('../pseudos.cjs');
var themeTokens = require('./theme-tokens.cjs');
function flattenTokens(theme) {
const tokens = themeTokens.extractTokens(theme);
const semanticTokens = themeTokens.extractSemanticTokens(theme);
const isSemanticCondition = (key) => (
// @ts-ignore
pseudos.pseudoPropNames.includes(key) || "default" === key
);
const result = {};
utils.walkObject(tokens, (value, path) => {
if (value == null)
return;
result[path.join(".")] = { isSemantic: false, value };
});
utils.walkObject(
semanticTokens,
(value, path) => {
if (value == null)
return;
result[path.join(".")] = { isSemantic: true, value };
},
{
stop: (value) => Object.keys(value).every(isSemanticCondition)
}
);
return result;
}
exports.flattenTokens = flattenTokens;