UNPKG

@zenkit/styles

Version:

ZenKit components for impliments styles

69 lines (52 loc) 2.25 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _hash = _interopRequireDefault(require("@emotion/hash")); var escapeRegex = /([[\].#*$><+~=|^:(),"'`\s])/g; function safePrefix(classNamePrefix) { var prefix = String(classNamePrefix); return prefix.replace(escapeRegex, '-'); } var themeHashCache = {}; function createGenerateClassName() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var _options$dangerouslyU = options.dangerouslyUseGlobalCSS, dangerouslyUseGlobalCSS = _options$dangerouslyU === void 0 ? false : _options$dangerouslyU, _options$productionPr = options.productionPrefix, productionPrefix = _options$productionPr === void 0 ? 'Z' : _options$productionPr, _options$seed = options.seed, seed = _options$seed === void 0 ? '' : _options$seed; var ruleCounter = 0; return function (rule, styleSheet) { var isStatic = !styleSheet.options.link; if (dangerouslyUseGlobalCSS && styleSheet && styleSheet.options.name && isStatic) { return "".concat(safePrefix(styleSheet.options.name), "-").concat(rule.key); } var suffix; if (isStatic) { var themeHash = themeHashCache[styleSheet.options.theme]; if (!themeHash) { themeHash = (0, _hash.default)(JSON.stringify(styleSheet.options.theme)); themeHashCache[styleSheet.options.theme] = themeHash; } var raw = styleSheet.rules.raw[rule.key]; suffix = (0, _hash.default)("".concat(themeHash).concat(rule.key).concat(JSON.stringify(raw))); } if (!suffix) { ruleCounter += 1; suffix = ruleCounter; } if (process.env.NODE_ENV !== 'production') { if (styleSheet && styleSheet.options.classNamePrefix) { return "".concat(safePrefix(styleSheet.options.classNamePrefix), "-").concat(rule.key, "-").concat(seed).concat(suffix); } return "".concat(rule.key, "-").concat(seed).concat(suffix); } return "".concat(productionPrefix).concat(seed).concat(suffix); }; } var _default = createGenerateClassName; exports.default = _default;