@ant-design/cssinjs
Advanced tools
Comparing version 1.5.0 to 1.5.1
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
// [times, realValue] | ||
@@ -8,4 +9,6 @@ var Entity = /*#__PURE__*/function () { | ||
_classCallCheck(this, Entity); | ||
_defineProperty(this, "cache", new Map()); | ||
} | ||
_createClass(Entity, [{ | ||
@@ -22,2 +25,3 @@ key: "get", | ||
var nextValue = valueFn(prevValue); | ||
if (nextValue === null) { | ||
@@ -30,4 +34,6 @@ this.cache.delete(path); | ||
}]); | ||
return Entity; | ||
}(); | ||
export default Entity; |
@@ -8,11 +8,12 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; | ||
import { flattenToken, token2key } from "../util"; | ||
var EMPTY_OVERRIDE = {}; | ||
var EMPTY_OVERRIDE = {}; // Generate different prefix to make user selector break in production env. | ||
// This helps developer not to do style override directly on the hash id. | ||
// Generate different prefix to make user selector break in production env. | ||
// This helps developer not to do style override directly on the hash id. | ||
var hashPrefix = process.env.NODE_ENV !== 'production' ? 'css-dev-only-do-not-override' : 'css'; | ||
var tokenKeys = new Map(); | ||
function recordCleanToken(tokenKey) { | ||
tokenKeys.set(tokenKey, (tokenKeys.get(tokenKey) || 0) + 1); | ||
} | ||
function removeStyleTags(key) { | ||
@@ -24,2 +25,3 @@ if (typeof document !== 'undefined') { | ||
var _style$parentNode; | ||
(_style$parentNode = style.parentNode) === null || _style$parentNode === void 0 ? void 0 : _style$parentNode.removeChild(style); | ||
@@ -29,5 +31,5 @@ } | ||
} | ||
} | ||
} // Remove will check current keys first | ||
// Remove will check current keys first | ||
function cleanTokenStyle(tokenKey) { | ||
@@ -40,2 +42,3 @@ tokenKeys.set(tokenKey, (tokenKeys.get(tokenKey) || 0) - 1); | ||
}); | ||
if (cleanableKeyList.length < tokenKeyList.length) { | ||
@@ -48,3 +51,2 @@ cleanableKeyList.forEach(function (key) { | ||
} | ||
/** | ||
@@ -57,11 +59,12 @@ * Cache theme derivative token as global shared one | ||
*/ | ||
export default function useCacheToken(theme, tokens) { | ||
var option = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var _option$salt = option.salt, | ||
salt = _option$salt === void 0 ? '' : _option$salt, | ||
_option$override = option.override, | ||
override = _option$override === void 0 ? EMPTY_OVERRIDE : _option$override, | ||
formatToken = option.formatToken; | ||
salt = _option$salt === void 0 ? '' : _option$salt, | ||
_option$override = option.override, | ||
override = _option$override === void 0 ? EMPTY_OVERRIDE : _option$override, | ||
formatToken = option.formatToken; // Basic - We do basic cache here | ||
// Basic - We do basic cache here | ||
var mergedToken = React.useMemo(function () { | ||
@@ -77,13 +80,12 @@ return Object.assign.apply(Object, [{}].concat(_toConsumableArray(tokens))); | ||
var cachedToken = useGlobalCache('token', [salt, theme.id, tokenStr, overrideTokenStr], function () { | ||
var derivativeToken = theme.getDerivativeToken(mergedToken); | ||
var derivativeToken = theme.getDerivativeToken(mergedToken); // Merge with override | ||
// Merge with override | ||
var mergedDerivativeToken = _objectSpread(_objectSpread({}, derivativeToken), override); | ||
var mergedDerivativeToken = _objectSpread(_objectSpread({}, derivativeToken), override); // Format if needed | ||
// Format if needed | ||
if (formatToken) { | ||
mergedDerivativeToken = formatToken(mergedDerivativeToken); | ||
} | ||
} // Optimize for `useStyleRegister` performance | ||
// Optimize for `useStyleRegister` performance | ||
var tokenKey = token2key(mergedDerivativeToken, salt); | ||
@@ -90,0 +92,0 @@ mergedDerivativeToken._tokenKey = tokenKey; |
@@ -8,17 +8,18 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
var _React$useContext = React.useContext(StyleContext), | ||
globalCache = _React$useContext.cache; | ||
globalCache = _React$useContext.cache; | ||
var fullPath = [prefix].concat(_toConsumableArray(keyPath)); | ||
var HMRUpdate = useHMR(); | ||
var HMRUpdate = useHMR(); // Create cache | ||
// Create cache | ||
React.useMemo(function () { | ||
globalCache.update(fullPath, function (prevCache) { | ||
var _ref = prevCache || [], | ||
_ref2 = _slicedToArray(_ref, 2), | ||
_ref2$ = _ref2[0], | ||
times = _ref2$ === void 0 ? 0 : _ref2$, | ||
cache = _ref2[1]; | ||
_ref2 = _slicedToArray(_ref, 2), | ||
_ref2$ = _ref2[0], | ||
times = _ref2$ === void 0 ? 0 : _ref2$, | ||
cache = _ref2[1]; // HMR should always ignore cache since developer may change it | ||
// HMR should always ignore cache since developer may change it | ||
var tmpCache = cache; | ||
if (process.env.NODE_ENV !== 'production' && cache && HMRUpdate) { | ||
@@ -28,10 +29,12 @@ onCacheRemove === null || onCacheRemove === void 0 ? void 0 : onCacheRemove(tmpCache, HMRUpdate); | ||
} | ||
var mergedCache = tmpCache || cacheFn(); | ||
return [times + 1, mergedCache]; | ||
}); | ||
}, /* eslint-disable react-hooks/exhaustive-deps */ | ||
}, | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
[fullPath.join('_')] | ||
/* eslint-enable */); | ||
/* eslint-enable */ | ||
); // Remove if no need anymore | ||
// Remove if no need anymore | ||
React.useEffect(function () { | ||
@@ -41,7 +44,9 @@ return function () { | ||
var _ref3 = prevCache || [], | ||
_ref4 = _slicedToArray(_ref3, 2), | ||
_ref4$ = _ref4[0], | ||
times = _ref4$ === void 0 ? 0 : _ref4$, | ||
cache = _ref4[1]; | ||
_ref4 = _slicedToArray(_ref3, 2), | ||
_ref4$ = _ref4[0], | ||
times = _ref4$ === void 0 ? 0 : _ref4$, | ||
cache = _ref4[1]; | ||
var nextCount = times - 1; | ||
if (nextCount === 0) { | ||
@@ -51,2 +56,3 @@ onCacheRemove === null || onCacheRemove === void 0 ? void 0 : onCacheRemove(cache, false); | ||
} | ||
return [times - 1, cache]; | ||
@@ -53,0 +59,0 @@ }); |
function useProdHMR() { | ||
return false; | ||
} | ||
var webpackHMR = false; | ||
function useDevHMR() { | ||
return webpackHMR; | ||
} | ||
export default process.env.NODE_ENV === 'production' ? useProdHMR : useDevHMR; | ||
// Webpack `module.hot.accept` do not support any deps update trigger | ||
export default process.env.NODE_ENV === 'production' ? useProdHMR : useDevHMR; // Webpack `module.hot.accept` do not support any deps update trigger | ||
// We have to hack handler to force mark as HRM | ||
if (process.env.NODE_ENV !== 'production' && typeof module !== 'undefined' && module && module.hot) { | ||
var win = window; | ||
if (typeof win.webpackHotUpdate === 'function') { | ||
var originWebpackHotUpdate = win.webpackHotUpdate; | ||
win.webpackHotUpdate = function () { | ||
@@ -17,0 +21,0 @@ webpackHMR = true; |
@@ -10,4 +10,4 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import { removeCSS, updateCSS } from "rc-util/es/Dom/dynamicCSS"; | ||
import * as React from 'react'; | ||
// @ts-ignore | ||
import * as React from 'react'; // @ts-ignore | ||
import unitless from '@emotion/unitless'; | ||
@@ -29,7 +29,8 @@ import { compile, serialize, stringify } from 'stylis'; | ||
} | ||
function isCompoundCSSProperty(value) { | ||
return _typeof(value) === 'object' && value && SKIP_CHECK in value; | ||
} | ||
} // 注入 hash 值 | ||
// 注入 hash 值 | ||
function injectSelectorHash(key, hashId, hashPriority) { | ||
@@ -39,11 +40,11 @@ if (!hashId) { | ||
} | ||
var hashClassName = ".".concat(hashId); | ||
var hashSelector = hashPriority === 'low' ? ":where(".concat(hashClassName, ")") : hashClassName; | ||
var hashSelector = hashPriority === 'low' ? ":where(".concat(hashClassName, ")") : hashClassName; // 注入 hashId | ||
// 注入 hashId | ||
var keys = key.split(',').map(function (k) { | ||
var _firstPath$match; | ||
var fullPath = k.trim().split(/\s+/); | ||
// 如果 Selector 第一个是 HTML Element,那我们就插到它的后面。反之,就插到最前面。 | ||
var fullPath = k.trim().split(/\s+/); // 如果 Selector 第一个是 HTML Element,那我们就插到它的后面。反之,就插到最前面。 | ||
var firstPath = fullPath[0] || ''; | ||
@@ -56,45 +57,51 @@ var htmlElement = ((_firstPath$match = firstPath.match(/^\w+/)) === null || _firstPath$match === void 0 ? void 0 : _firstPath$match[0]) || ''; | ||
} | ||
// Global effect style will mount once and not removed | ||
// The effect will not save in SSR cache (e.g. keyframes) | ||
var globalEffectStyleKeys = new Set(); | ||
/** | ||
* @private Test only. Clear the global effect style keys. | ||
*/ | ||
export var _cf = process.env.NODE_ENV !== 'production' ? function () { | ||
return globalEffectStyleKeys.clear(); | ||
} : undefined; | ||
} : undefined; // Parse CSSObject to style content | ||
// Parse CSSObject to style content | ||
export var parseStyle = function parseStyle(interpolation) { | ||
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { | ||
root: true, | ||
parentSelectors: [] | ||
}, | ||
root = _ref.root, | ||
injectHash = _ref.injectHash, | ||
parentSelectors = _ref.parentSelectors; | ||
root: true, | ||
parentSelectors: [] | ||
}, | ||
root = _ref.root, | ||
injectHash = _ref.injectHash, | ||
parentSelectors = _ref.parentSelectors; | ||
var hashId = config.hashId, | ||
layer = config.layer, | ||
path = config.path, | ||
hashPriority = config.hashPriority, | ||
_config$transformers = config.transformers, | ||
transformers = _config$transformers === void 0 ? [] : _config$transformers, | ||
_config$linters = config.linters, | ||
linters = _config$linters === void 0 ? [] : _config$linters; | ||
layer = config.layer, | ||
path = config.path, | ||
hashPriority = config.hashPriority, | ||
_config$transformers = config.transformers, | ||
transformers = _config$transformers === void 0 ? [] : _config$transformers, | ||
_config$linters = config.linters, | ||
linters = _config$linters === void 0 ? [] : _config$linters; | ||
var styleStr = ''; | ||
var effectStyle = {}; | ||
function parseKeyframes(keyframes) { | ||
var animationName = keyframes.getName(hashId); | ||
if (!effectStyle[animationName]) { | ||
var _parseStyle = parseStyle(keyframes.style, config, { | ||
root: false, | ||
parentSelectors: parentSelectors | ||
}), | ||
_parseStyle2 = _slicedToArray(_parseStyle, 1), | ||
_parsedStr = _parseStyle2[0]; | ||
root: false, | ||
parentSelectors: parentSelectors | ||
}), | ||
_parseStyle2 = _slicedToArray(_parseStyle, 1), | ||
_parsedStr = _parseStyle2[0]; | ||
effectStyle[animationName] = "@keyframes ".concat(keyframes.getName(hashId)).concat(_parsedStr); | ||
} | ||
} | ||
function flattenList(list) { | ||
@@ -111,2 +118,3 @@ var fullList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
} | ||
var flattenStyleList = flattenList(Array.isArray(interpolation) ? interpolation : [interpolation]); | ||
@@ -116,2 +124,3 @@ flattenStyleList.forEach(function (originStyle) { | ||
var style = typeof originStyle === 'string' && !root ? {} : originStyle; | ||
if (typeof style === 'string') { | ||
@@ -125,17 +134,16 @@ styleStr += "".concat(style, "\n"); | ||
var _trans$visit; | ||
return (trans === null || trans === void 0 ? void 0 : (_trans$visit = trans.visit) === null || _trans$visit === void 0 ? void 0 : _trans$visit.call(trans, prev)) || prev; | ||
}, style); | ||
}, style); // Normal CSSObject | ||
// Normal CSSObject | ||
Object.keys(mergedStyle).forEach(function (key) { | ||
var value = mergedStyle[key]; | ||
if (_typeof(value) === 'object' && value && (key !== 'animationName' || !value._keyframe) && !isCompoundCSSProperty(value)) { | ||
var subInjectHash = false; | ||
var subInjectHash = false; // 当成嵌套对象来处理 | ||
// 当成嵌套对象来处理 | ||
var mergedKey = key.trim(); | ||
// Whether treat child as root. In most case it is false. | ||
var nextRoot = false; | ||
var mergedKey = key.trim(); // Whether treat child as root. In most case it is false. | ||
// 拆分多个选择器 | ||
var nextRoot = false; // 拆分多个选择器 | ||
if ((root || injectHash) && hashId) { | ||
@@ -158,10 +166,12 @@ if (mergedKey.startsWith('@')) { | ||
} | ||
var _parseStyle3 = parseStyle(value, config, { | ||
root: nextRoot, | ||
injectHash: subInjectHash, | ||
parentSelectors: [].concat(_toConsumableArray(parentSelectors), [mergedKey]) | ||
}), | ||
_parseStyle4 = _slicedToArray(_parseStyle3, 2), | ||
_parsedStr2 = _parseStyle4[0], | ||
childEffectStyle = _parseStyle4[1]; | ||
root: nextRoot, | ||
injectHash: subInjectHash, | ||
parentSelectors: [].concat(_toConsumableArray(parentSelectors), [mergedKey]) | ||
}), | ||
_parseStyle4 = _slicedToArray(_parseStyle3, 2), | ||
_parsedStr2 = _parseStyle4[0], | ||
childEffectStyle = _parseStyle4[1]; | ||
effectStyle = _objectSpread(_objectSpread({}, effectStyle), childEffectStyle); | ||
@@ -171,3 +181,5 @@ styleStr += "".concat(mergedKey).concat(_parsedStr2); | ||
var _value; | ||
var actualValue = (_value = value === null || value === void 0 ? void 0 : value.value) !== null && _value !== void 0 ? _value : value; | ||
if (process.env.NODE_ENV !== 'production' && (_typeof(value) !== 'object' || !(value !== null && value !== void 0 && value[SKIP_CHECK]))) { | ||
@@ -181,16 +193,16 @@ [contentQuotesLinter, hashedAnimationLinter].concat(_toConsumableArray(linters)).forEach(function (linter) { | ||
}); | ||
} | ||
} // 如果是样式则直接插入 | ||
// 如果是样式则直接插入 | ||
var styleName = key.replace(/[A-Z]/g, function (match) { | ||
return "-".concat(match.toLowerCase()); | ||
}); | ||
}); // Auto suffix with px | ||
// Auto suffix with px | ||
var formatValue = actualValue; | ||
if (!unitless[key] && typeof formatValue === 'number' && formatValue !== 0) { | ||
formatValue = "".concat(formatValue, "px"); | ||
} | ||
} // handle animationName & Keyframe value | ||
// handle animationName & Keyframe value | ||
if (key === 'animationName' && value !== null && value !== void 0 && value._keyframe) { | ||
@@ -200,2 +212,3 @@ parseKeyframes(value); | ||
} | ||
styleStr += "".concat(styleName, ":").concat(formatValue, ";"); | ||
@@ -206,2 +219,3 @@ } | ||
}); | ||
if (!root) { | ||
@@ -212,5 +226,4 @@ styleStr = "{".concat(styleStr, "}"); | ||
var layerName = layerCells[layerCells.length - 1].trim(); | ||
styleStr = "@layer ".concat(layerName, " {").concat(styleStr, "}"); | ||
styleStr = "@layer ".concat(layerName, " {").concat(styleStr, "}"); // Order of layer if needed | ||
// Order of layer if needed | ||
if (layerCells.length > 1) { | ||
@@ -221,105 +234,112 @@ // zombieJ: stylis do not support layer order, so we need to handle it manually. | ||
} | ||
return [styleStr, effectStyle]; | ||
}; | ||
// ============================================================================ | ||
}; // ============================================================================ | ||
// == Register == | ||
// ============================================================================ | ||
function uniqueHash(path, styleStr) { | ||
return hash("".concat(path.join('%')).concat(styleStr)); | ||
} | ||
function Empty() { | ||
return null; | ||
} | ||
/** | ||
* Register a style to the global style sheet. | ||
*/ | ||
export default function useStyleRegister(info, styleFn) { | ||
var token = info.token, | ||
path = info.path, | ||
hashId = info.hashId, | ||
layer = info.layer; | ||
path = info.path, | ||
hashId = info.hashId, | ||
layer = info.layer; | ||
var _React$useContext = React.useContext(StyleContext), | ||
autoClear = _React$useContext.autoClear, | ||
mock = _React$useContext.mock, | ||
defaultCache = _React$useContext.defaultCache, | ||
hashPriority = _React$useContext.hashPriority, | ||
container = _React$useContext.container, | ||
ssrInline = _React$useContext.ssrInline, | ||
transformers = _React$useContext.transformers, | ||
linters = _React$useContext.linters; | ||
autoClear = _React$useContext.autoClear, | ||
mock = _React$useContext.mock, | ||
defaultCache = _React$useContext.defaultCache, | ||
hashPriority = _React$useContext.hashPriority, | ||
container = _React$useContext.container, | ||
ssrInline = _React$useContext.ssrInline, | ||
transformers = _React$useContext.transformers, | ||
linters = _React$useContext.linters; | ||
var tokenKey = token._tokenKey; | ||
var fullPath = [tokenKey].concat(_toConsumableArray(path)); | ||
var fullPath = [tokenKey].concat(_toConsumableArray(path)); // Check if need insert style | ||
// Check if need insert style | ||
var isMergedClientSide = isClientSide; | ||
if (process.env.NODE_ENV !== 'production' && mock !== undefined) { | ||
isMergedClientSide = mock === 'client'; | ||
} | ||
var _useGlobalCache = useGlobalCache('style', fullPath, | ||
// Create cache if needed | ||
function () { | ||
var styleObj = styleFn(); | ||
var _parseStyle5 = parseStyle(styleObj, { | ||
hashId: hashId, | ||
hashPriority: hashPriority, | ||
layer: layer, | ||
path: path.join('-'), | ||
transformers: transformers, | ||
linters: linters | ||
}), | ||
var _useGlobalCache = useGlobalCache('style', fullPath, // Create cache if needed | ||
function () { | ||
var styleObj = styleFn(); | ||
var _parseStyle5 = parseStyle(styleObj, { | ||
hashId: hashId, | ||
hashPriority: hashPriority, | ||
layer: layer, | ||
path: path.join('-'), | ||
transformers: transformers, | ||
linters: linters | ||
}), | ||
_parseStyle6 = _slicedToArray(_parseStyle5, 2), | ||
parsedStyle = _parseStyle6[0], | ||
effectStyle = _parseStyle6[1]; | ||
var styleStr = normalizeStyle(parsedStyle); | ||
var styleId = uniqueHash(fullPath, styleStr); | ||
if (isMergedClientSide) { | ||
var style = updateCSS(styleStr, styleId, { | ||
mark: ATTR_MARK, | ||
prepend: 'queue', | ||
attachTo: container | ||
}); | ||
style[CSS_IN_JS_INSTANCE] = CSS_IN_JS_INSTANCE_ID; | ||
// Used for `useCacheToken` to remove on batch when token removed | ||
style.setAttribute(ATTR_TOKEN, tokenKey); | ||
var styleStr = normalizeStyle(parsedStyle); | ||
var styleId = uniqueHash(fullPath, styleStr); | ||
// Dev usage to find which cache path made this easily | ||
if (process.env.NODE_ENV !== 'production') { | ||
style.setAttribute(ATTR_DEV_CACHE_PATH, fullPath.join('|')); | ||
if (isMergedClientSide) { | ||
var style = updateCSS(styleStr, styleId, { | ||
mark: ATTR_MARK, | ||
prepend: 'queue', | ||
attachTo: container | ||
}); | ||
style[CSS_IN_JS_INSTANCE] = CSS_IN_JS_INSTANCE_ID; // Used for `useCacheToken` to remove on batch when token removed | ||
style.setAttribute(ATTR_TOKEN, tokenKey); // Dev usage to find which cache path made this easily | ||
if (process.env.NODE_ENV !== 'production') { | ||
style.setAttribute(ATTR_DEV_CACHE_PATH, fullPath.join('|')); | ||
} // Inject client side effect style | ||
Object.keys(effectStyle).forEach(function (effectKey) { | ||
if (!globalEffectStyleKeys.has(effectKey)) { | ||
globalEffectStyleKeys.add(effectKey); // Inject | ||
updateCSS(normalizeStyle(effectStyle[effectKey]), "_effect-".concat(effectKey), { | ||
mark: ATTR_MARK, | ||
prepend: 'queue', | ||
attachTo: container | ||
}); | ||
} | ||
}); | ||
} | ||
// Inject client side effect style | ||
Object.keys(effectStyle).forEach(function (effectKey) { | ||
if (!globalEffectStyleKeys.has(effectKey)) { | ||
globalEffectStyleKeys.add(effectKey); | ||
return [styleStr, tokenKey, styleId]; | ||
}, // Remove cache if no need | ||
function (_ref2, fromHMR) { | ||
var _ref3 = _slicedToArray(_ref2, 3), | ||
styleId = _ref3[2]; | ||
// Inject | ||
updateCSS(normalizeStyle(effectStyle[effectKey]), "_effect-".concat(effectKey), { | ||
mark: ATTR_MARK, | ||
prepend: 'queue', | ||
attachTo: container | ||
}); | ||
} | ||
}); | ||
} | ||
return [styleStr, tokenKey, styleId]; | ||
}, | ||
// Remove cache if no need | ||
function (_ref2, fromHMR) { | ||
var _ref3 = _slicedToArray(_ref2, 3), | ||
styleId = _ref3[2]; | ||
if ((fromHMR || autoClear) && isClientSide) { | ||
removeCSS(styleId, { | ||
mark: ATTR_MARK | ||
}); | ||
} | ||
}), | ||
_useGlobalCache2 = _slicedToArray(_useGlobalCache, 3), | ||
cachedStyleStr = _useGlobalCache2[0], | ||
cachedTokenKey = _useGlobalCache2[1], | ||
cachedStyleId = _useGlobalCache2[2]; | ||
if ((fromHMR || autoClear) && isClientSide) { | ||
removeCSS(styleId, { | ||
mark: ATTR_MARK | ||
}); | ||
} | ||
}), | ||
_useGlobalCache2 = _slicedToArray(_useGlobalCache, 3), | ||
cachedStyleStr = _useGlobalCache2[0], | ||
cachedTokenKey = _useGlobalCache2[1], | ||
cachedStyleId = _useGlobalCache2[2]; | ||
return function (node) { | ||
var styleNode; | ||
if (!ssrInline || isMergedClientSide || !defaultCache) { | ||
@@ -329,2 +349,3 @@ styleNode = /*#__PURE__*/React.createElement(Empty, null); | ||
var _ref4; | ||
styleNode = /*#__PURE__*/React.createElement("style", _extends({}, (_ref4 = {}, _defineProperty(_ref4, ATTR_TOKEN, cachedTokenKey), _defineProperty(_ref4, ATTR_MARK, cachedStyleId), _ref4), { | ||
@@ -336,9 +357,9 @@ dangerouslySetInnerHTML: { | ||
} | ||
return /*#__PURE__*/React.createElement(React.Fragment, null, styleNode, node); | ||
}; | ||
} | ||
// ============================================================================ | ||
} // ============================================================================ | ||
// == SSR == | ||
// ============================================================================ | ||
export function extractStyle(cache) { | ||
@@ -348,12 +369,11 @@ // prefix with `style` is used for `useStyleRegister` to cache style context | ||
return key.startsWith('style%'); | ||
}); | ||
}); // const tokenStyles: Record<string, string[]> = {}; | ||
// const tokenStyles: Record<string, string[]> = {}; | ||
var styleText = ''; | ||
styleKeys.forEach(function (key) { | ||
var _ = _slicedToArray(cache.cache.get(key)[1], 3), | ||
styleStr = _[0], | ||
tokenKey = _[1], | ||
styleId = _[2]; | ||
styleStr = _[0], | ||
tokenKey = _[1], | ||
styleId = _[2]; | ||
styleText += "<style ".concat(ATTR_TOKEN, "=\"").concat(tokenKey, "\" ").concat(ATTR_MARK, "=\"").concat(styleId, "\">").concat(styleStr, "</style>"); | ||
@@ -360,0 +380,0 @@ }); |
@@ -8,6 +8,4 @@ import useCacheToken from "./hooks/useCacheToken"; | ||
import legacyLogicalPropertiesTransformer from "./transformers/legacyLogicalProperties"; | ||
export { Theme, createTheme, useStyleRegister, useCacheToken, createCache, StyleProvider, Keyframes, extractStyle, | ||
// Transformer | ||
legacyLogicalPropertiesTransformer, | ||
// Linters | ||
export { Theme, createTheme, useStyleRegister, useCacheToken, createCache, StyleProvider, Keyframes, extractStyle, // Transformer | ||
legacyLogicalPropertiesTransformer, // Linters | ||
logicalPropertiesLinter, legacyNotSelectorLinter }; |
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
var Keyframe = /*#__PURE__*/function () { | ||
function Keyframe(name, style) { | ||
_classCallCheck(this, Keyframe); | ||
_defineProperty(this, "name", void 0); | ||
_defineProperty(this, "style", void 0); | ||
_defineProperty(this, "_keyframe", true); | ||
this.name = name; | ||
this.style = style; | ||
} | ||
_createClass(Keyframe, [{ | ||
@@ -20,4 +26,6 @@ key: "getName", | ||
}]); | ||
return Keyframe; | ||
}(); | ||
export default Keyframe; |
import { lintWarning } from "./utils"; | ||
var linter = function linter(key, value, info) { | ||
@@ -7,2 +8,3 @@ if (key === 'content') { | ||
var contentValues = ['normal', 'none', 'initial', 'inherit', 'unset']; | ||
if (typeof value !== 'string' || contentValues.indexOf(value) === -1 && !contentValuePattern.test(value) && (value.charAt(0) !== value.charAt(value.length - 1) || value.charAt(0) !== '"' && value.charAt(0) !== "'")) { | ||
@@ -13,2 +15,3 @@ lintWarning("You seem to be using a value for 'content' without quotes, try replacing it with `content: '\"".concat(value, "\"'`."), info); | ||
}; | ||
export default linter; |
import { lintWarning } from "./utils"; | ||
var linter = function linter(key, value, info) { | ||
@@ -9,2 +10,3 @@ if (key === 'animation') { | ||
}; | ||
export default linter; |
import { lintWarning } from "./utils"; | ||
function isConcatSelector(selector) { | ||
var _selector$match; | ||
var notContent = ((_selector$match = selector.match(/:not\(([^)]*)\)/)) === null || _selector$match === void 0 ? void 0 : _selector$match[1]) || ''; | ||
// split selector. e.g. | ||
var notContent = ((_selector$match = selector.match(/:not\(([^)]*)\)/)) === null || _selector$match === void 0 ? void 0 : _selector$match[1]) || ''; // split selector. e.g. | ||
// `h1#a.b` => ['h1', #a', '.b'] | ||
var splitCells = notContent.split(/(?=[.#])/); | ||
var splitCells = notContent.split(/(\[[^[]*])|(?=[.#])/).filter(function (str) { | ||
return str; | ||
}); | ||
return splitCells.length > 1; | ||
} | ||
function parsePath(info) { | ||
@@ -16,8 +20,11 @@ return info.parentSelectors.reduce(function (prev, cur) { | ||
} | ||
return cur.includes('&') ? cur.replace(/\&/g, prev) : "".concat(prev, " ").concat(cur); | ||
return cur.includes('&') ? cur.replace(/&/g, prev) : "".concat(prev, " ").concat(cur); | ||
}, ''); | ||
} | ||
var linter = function linter(key, value, info) { | ||
var parentSelectorPath = parsePath(info); | ||
var notList = parentSelectorPath.match(/:not\([^)]*\)/g) || []; | ||
if (notList.length > 0 && notList.some(isConcatSelector)) { | ||
@@ -27,2 +34,3 @@ lintWarning("Concat ':not' selector not support in legacy browsers.", info); | ||
}; | ||
export default linter; |
import { lintWarning } from "./utils"; | ||
var linter = function linter(key, value, info) { | ||
@@ -24,2 +25,3 @@ switch (key) { | ||
return; | ||
case 'margin': | ||
@@ -34,2 +36,3 @@ case 'padding': | ||
}); | ||
if (valueArr.length === 4 && valueArr[1] !== valueArr[3]) { | ||
@@ -39,3 +42,5 @@ lintWarning("You seem to be using '".concat(key, "' property with different left ").concat(key, " and right ").concat(key, ", which is not compatible with RTL mode. Please use logical properties and values instead. For more information: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties."), info); | ||
} | ||
return; | ||
case 'clear': | ||
@@ -46,3 +51,5 @@ case 'textAlign': | ||
} | ||
return; | ||
case 'borderRadius': | ||
@@ -57,19 +64,24 @@ if (typeof value === 'string') { | ||
} | ||
var radiusArr = group.split(' ').map(function (item) { | ||
return item.trim(); | ||
}); | ||
// borderRadius: '2px 4px' | ||
}); // borderRadius: '2px 4px' | ||
if (radiusArr.length >= 2 && radiusArr[0] !== radiusArr[1]) { | ||
return true; | ||
} | ||
// borderRadius: '4px 4px 2px' | ||
} // borderRadius: '4px 4px 2px' | ||
if (radiusArr.length === 3 && radiusArr[1] !== radiusArr[2]) { | ||
return true; | ||
} | ||
// borderRadius: '4px 4px 2px 4px' | ||
} // borderRadius: '4px 4px 2px 4px' | ||
if (radiusArr.length === 4 && radiusArr[2] !== radiusArr[3]) { | ||
return true; | ||
} | ||
return result; | ||
}, false); | ||
if (invalid) { | ||
@@ -79,6 +91,9 @@ lintWarning("You seem to be using non-logical value '".concat(value, "' of ").concat(key, ", which is not compatible with RTL mode. Please use logical properties and values instead. For more information: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties."), info); | ||
} | ||
return; | ||
default: | ||
} | ||
}; | ||
export default linter; |
import devWarning from "rc-util/es/warning"; | ||
export function lintWarning(message, info) { | ||
var path = info.path, | ||
parentSelectors = info.parentSelectors; | ||
devWarning(false, "[Ant Design CSS-in-JS] ".concat(path ? "Error in '".concat(path, "': ") : '').concat(message).concat(parentSelectors.length ? " Selector info: ".concat(parentSelectors.join(' -> '), ")") : '')); | ||
parentSelectors = info.parentSelectors; | ||
devWarning(false, "[Ant Design CSS-in-JS] ".concat(path ? "Error in '".concat(path, "': ") : '').concat(message).concat(parentSelectors.length ? " Selector info: ".concat(parentSelectors.join(' -> ')) : '')); | ||
} |
@@ -10,5 +10,4 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; | ||
export var ATTR_MARK = 'data-css-hash'; | ||
export var ATTR_DEV_CACHE_PATH = 'data-dev-cache-path'; | ||
export var ATTR_DEV_CACHE_PATH = 'data-dev-cache-path'; // Mark css-in-js instance in style element | ||
// Mark css-in-js instance in style element | ||
export var CSS_IN_JS_INSTANCE = '__cssinjs_instance__'; | ||
@@ -21,15 +20,15 @@ export var CSS_IN_JS_INSTANCE_ID = Math.random().toString(12).slice(2); | ||
Array.from(styles).forEach(function (style) { | ||
style[CSS_IN_JS_INSTANCE] = style[CSS_IN_JS_INSTANCE] || CSS_IN_JS_INSTANCE_ID; | ||
style[CSS_IN_JS_INSTANCE] = style[CSS_IN_JS_INSTANCE] || CSS_IN_JS_INSTANCE_ID; // Not force move if no head | ||
// Not force move if no head | ||
document.head.insertBefore(style, firstChild); | ||
}); | ||
}); // Deduplicate of moved styles | ||
// Deduplicate of moved styles | ||
var styleHash = {}; | ||
Array.from(document.querySelectorAll("style[".concat(ATTR_MARK, "]"))).forEach(function (style) { | ||
var hash = style.getAttribute(ATTR_MARK); | ||
if (styleHash[hash]) { | ||
if (style[CSS_IN_JS_INSTANCE] === CSS_IN_JS_INSTANCE_ID) { | ||
var _style$parentNode; | ||
(_style$parentNode = style.parentNode) === null || _style$parentNode === void 0 ? void 0 : _style$parentNode.removeChild(style); | ||
@@ -42,2 +41,3 @@ } | ||
} | ||
return new CacheEntity(); | ||
@@ -52,8 +52,11 @@ } | ||
var children = props.children, | ||
restProps = _objectWithoutProperties(props, _excluded); | ||
restProps = _objectWithoutProperties(props, _excluded); | ||
var parentContext = React.useContext(StyleContext); | ||
var context = useMemo(function () { | ||
var mergedContext = _objectSpread({}, parentContext); | ||
Object.keys(restProps).forEach(function (key) { | ||
var value = restProps[key]; | ||
if (restProps[key] !== undefined) { | ||
@@ -60,0 +63,0 @@ mergedContext[key] = value; |
import ThemeCache from "./ThemeCache"; | ||
import Theme from "./Theme"; | ||
var cacheThemes = new ThemeCache(); | ||
/** | ||
* Same as new Theme, but will always return same one if `derivative` not changed. | ||
*/ | ||
export default function createTheme(derivatives) { | ||
var derivativeArr = Array.isArray(derivatives) ? derivatives : [derivatives]; | ||
// Create new theme if not exist | ||
var derivativeArr = Array.isArray(derivatives) ? derivatives : [derivatives]; // Create new theme if not exist | ||
if (!cacheThemes.has(derivativeArr)) { | ||
cacheThemes.set(derivativeArr, new Theme(derivativeArr)); | ||
} | ||
} // Get theme from cache and return | ||
// Get theme from cache and return | ||
return cacheThemes.get(derivativeArr); | ||
} |
@@ -6,3 +6,2 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
var uuid = 0; | ||
/** | ||
@@ -12,14 +11,21 @@ * Theme with algorithms to derive tokens from design tokens. | ||
*/ | ||
var Theme = /*#__PURE__*/function () { | ||
function Theme(derivatives) { | ||
_classCallCheck(this, Theme); | ||
_defineProperty(this, "derivatives", void 0); | ||
_defineProperty(this, "id", void 0); | ||
this.derivatives = Array.isArray(derivatives) ? derivatives : [derivatives]; | ||
this.id = uuid; | ||
if (derivatives.length === 0) { | ||
warning(derivatives.length > 0, '[Ant Design CSS-in-JS] Theme should have at least one derivative function.'); | ||
} | ||
uuid += 1; | ||
} | ||
_createClass(Theme, [{ | ||
@@ -33,4 +39,6 @@ key: "getDerivativeToken", | ||
}]); | ||
return Theme; | ||
}(); | ||
export { Theme as default }; |
@@ -6,3 +6,2 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
// ================================== Cache ================================== | ||
export function sameDerivativeOption(left, right) { | ||
@@ -12,2 +11,3 @@ if (left.length !== right.length) { | ||
} | ||
for (var i = 0; i < left.length; i++) { | ||
@@ -18,10 +18,16 @@ if (left[i] !== right[i]) { | ||
} | ||
return true; | ||
} | ||
var ThemeCache = /*#__PURE__*/function () { | ||
function ThemeCache() { | ||
_classCallCheck(this, ThemeCache); | ||
_defineProperty(this, "cache", void 0); | ||
_defineProperty(this, "keys", void 0); | ||
_defineProperty(this, "cacheCallTimes", void 0); | ||
this.cache = new Map(); | ||
@@ -31,2 +37,3 @@ this.keys = []; | ||
} | ||
_createClass(ThemeCache, [{ | ||
@@ -41,2 +48,3 @@ key: "size", | ||
var _cache2, _cache3; | ||
var updateCallTimes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
@@ -51,8 +59,11 @@ var cache = { | ||
var _cache, _cache$map; | ||
cache = (_cache = cache) === null || _cache === void 0 ? void 0 : (_cache$map = _cache.map) === null || _cache$map === void 0 ? void 0 : _cache$map.get(derivative); | ||
} | ||
}); | ||
if ((_cache2 = cache) !== null && _cache2 !== void 0 && _cache2.value && updateCallTimes) { | ||
cache.value[1] = this.cacheCallTimes++; | ||
} | ||
return (_cache3 = cache) === null || _cache3 === void 0 ? void 0 : _cache3.value; | ||
@@ -64,2 +75,3 @@ } | ||
var _this$internalGet; | ||
return (_this$internalGet = this.internalGet(derivativeOption, true)) === null || _this$internalGet === void 0 ? void 0 : _this$internalGet[0]; | ||
@@ -76,2 +88,3 @@ } | ||
var _this = this; | ||
// New cache | ||
@@ -81,15 +94,20 @@ if (!this.has(derivativeOption)) { | ||
var _this$keys$reduce = this.keys.reduce(function (result, key) { | ||
var _result = _slicedToArray(result, 2), | ||
var _result = _slicedToArray(result, 2), | ||
callTimes = _result[1]; | ||
if (_this.internalGet(key)[1] < callTimes) { | ||
return [key, _this.internalGet(key)[1]]; | ||
} | ||
return result; | ||
}, [this.keys[0], this.cacheCallTimes]), | ||
_this$keys$reduce2 = _slicedToArray(_this$keys$reduce, 1), | ||
targetKey = _this$keys$reduce2[0]; | ||
if (_this.internalGet(key)[1] < callTimes) { | ||
return [key, _this.internalGet(key)[1]]; | ||
} | ||
return result; | ||
}, [this.keys[0], this.cacheCallTimes]), | ||
_this$keys$reduce2 = _slicedToArray(_this$keys$reduce, 1), | ||
targetKey = _this$keys$reduce2[0]; | ||
this.delete(targetKey); | ||
} | ||
this.keys.push(derivativeOption); | ||
} | ||
var cache = this.cache; | ||
@@ -103,2 +121,3 @@ derivativeOption.forEach(function (derivative, index) { | ||
var cacheValue = cache.get(derivative); | ||
if (!cacheValue) { | ||
@@ -111,2 +130,3 @@ cache.set(derivative, { | ||
} | ||
cache = cache.get(derivative).map; | ||
@@ -120,4 +140,6 @@ } | ||
var cache = currentCache.get(derivatives[0]); | ||
if (derivatives.length === 1) { | ||
var _cache$value; | ||
if (!cache.map) { | ||
@@ -130,8 +152,12 @@ currentCache.delete(derivatives[0]); | ||
} | ||
return (_cache$value = cache.value) === null || _cache$value === void 0 ? void 0 : _cache$value[0]; | ||
} | ||
var result = this.deleteByPath(cache.map, derivatives.slice(1)); | ||
if ((!cache.map || cache.map.size === 0) && !cache.value) { | ||
currentCache.delete(derivatives[0]); | ||
} | ||
return result; | ||
@@ -149,9 +175,14 @@ } | ||
} | ||
return undefined; | ||
} | ||
}]); | ||
return ThemeCache; | ||
}(); | ||
_defineProperty(ThemeCache, "MAX_CACHE_SIZE", 20); | ||
_defineProperty(ThemeCache, "MAX_CACHE_OFFSET", 5); | ||
export { ThemeCache as default }; |
@@ -5,5 +5,5 @@ function splitValues(value) { | ||
} | ||
var splitStyle = String(value).split(/\s+/); | ||
// Combine styles split in brackets, like `calc(1px + 2px)` | ||
var splitStyle = String(value).split(/\s+/); // Combine styles split in brackets, like `calc(1px + 2px)` | ||
var temp = ''; | ||
@@ -18,2 +18,3 @@ var brackets = 0; | ||
brackets -= item.split(')').length - 1; | ||
if (brackets === 0) { | ||
@@ -28,5 +29,7 @@ list.push(temp); | ||
} | ||
return list; | ||
}, []); | ||
} | ||
function noSplit(list) { | ||
@@ -36,2 +39,3 @@ list.notSplit = true; | ||
} | ||
var keyMap = { | ||
@@ -94,2 +98,3 @@ // Inset | ||
}; | ||
function skipCheck(value) { | ||
@@ -101,3 +106,2 @@ return { | ||
} | ||
/** | ||
@@ -112,2 +116,4 @@ * Convert css logical properties to legacy properties. | ||
*/ | ||
var transform = { | ||
@@ -119,4 +125,6 @@ visit: function visit(cssObj) { | ||
var matchValue = keyMap[key]; | ||
if (matchValue && (typeof value === 'number' || typeof value === 'string')) { | ||
var values = splitValues(value); | ||
if (matchValue.length && matchValue.notSplit) { | ||
@@ -134,2 +142,3 @@ // not split means always give same value like border | ||
var _values$index; | ||
clone[matchKey] = skipCheck((_values$index = values[index]) !== null && _values$index !== void 0 ? _values$index : values[0]); | ||
@@ -141,2 +150,3 @@ }); | ||
var _ref, _values$index2; | ||
clone[matchKey] = skipCheck((_ref = (_values$index2 = values[index]) !== null && _values$index2 !== void 0 ? _values$index2 : values[index - 2]) !== null && _ref !== void 0 ? _ref : values[0]); | ||
@@ -143,0 +153,0 @@ }); |
@@ -10,2 +10,3 @@ import _typeof from "@babel/runtime/helpers/esm/typeof"; | ||
str += key; | ||
if (value && _typeof(value) === 'object') { | ||
@@ -19,6 +20,6 @@ str += flattenToken(value); | ||
} | ||
/** | ||
* Convert derivative token to key string | ||
*/ | ||
export function token2key(token, salt) { | ||
@@ -29,7 +30,11 @@ return hash("".concat(salt, "_").concat(flattenToken(token))); | ||
var layerWidth = '903px'; | ||
function supportSelector(styleStr, handleElement) { | ||
if (canUseDom()) { | ||
var _ele$parentNode; | ||
updateCSS(styleStr, layerKey); | ||
var _ele = document.createElement('div'); | ||
_ele.style.position = 'fixed'; | ||
@@ -40,2 +45,3 @@ _ele.style.left = '0'; | ||
document.body.appendChild(_ele); | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -45,2 +51,3 @@ _ele.innerHTML = 'Test'; | ||
} | ||
var support = getComputedStyle(_ele).width === layerWidth; | ||
@@ -51,4 +58,6 @@ (_ele$parentNode = _ele.parentNode) === null || _ele$parentNode === void 0 ? void 0 : _ele$parentNode.removeChild(_ele); | ||
} | ||
return false; | ||
} | ||
var canLayer = undefined; | ||
@@ -61,3 +70,4 @@ export function supportLayer() { | ||
} | ||
return canLayer; | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,5 +9,9 @@ value: true | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
// [times, realValue] | ||
@@ -18,2 +23,3 @@ var Entity = /*#__PURE__*/function () { | ||
} | ||
(0, _createClass2.default)(Entity, [{ | ||
@@ -30,2 +36,3 @@ key: "get", | ||
var nextValue = valueFn(prevValue); | ||
if (nextValue === null) { | ||
@@ -40,3 +47,4 @@ this.cache.delete(path); | ||
}(); | ||
var _default = Entity; | ||
exports.default = _default; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,20 +11,31 @@ value: true | ||
exports.default = useCacheToken; | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2")); | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _hash = _interopRequireDefault(require("@emotion/hash")); | ||
var _StyleContext = require("../StyleContext"); | ||
var _useGlobalCache = _interopRequireDefault(require("./useGlobalCache")); | ||
var _util = require("../util"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
var EMPTY_OVERRIDE = {}; | ||
// Generate different prefix to make user selector break in production env. | ||
var EMPTY_OVERRIDE = {}; // Generate different prefix to make user selector break in production env. | ||
// This helps developer not to do style override directly on the hash id. | ||
var hashPrefix = process.env.NODE_ENV !== 'production' ? 'css-dev-only-do-not-override' : 'css'; | ||
var tokenKeys = new Map(); | ||
function recordCleanToken(tokenKey) { | ||
tokenKeys.set(tokenKey, (tokenKeys.get(tokenKey) || 0) + 1); | ||
} | ||
function removeStyleTags(key) { | ||
@@ -34,2 +47,3 @@ if (typeof document !== 'undefined') { | ||
var _style$parentNode; | ||
(_style$parentNode = style.parentNode) === null || _style$parentNode === void 0 ? void 0 : _style$parentNode.removeChild(style); | ||
@@ -39,5 +53,5 @@ } | ||
} | ||
} | ||
} // Remove will check current keys first | ||
// Remove will check current keys first | ||
function cleanTokenStyle(tokenKey) { | ||
@@ -50,2 +64,3 @@ tokenKeys.set(tokenKey, (tokenKeys.get(tokenKey) || 0) - 1); | ||
}); | ||
if (cleanableKeyList.length < tokenKeyList.length) { | ||
@@ -58,3 +73,2 @@ cleanableKeyList.forEach(function (key) { | ||
} | ||
/** | ||
@@ -67,11 +81,12 @@ * Cache theme derivative token as global shared one | ||
*/ | ||
function useCacheToken(theme, tokens) { | ||
var option = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var _option$salt = option.salt, | ||
salt = _option$salt === void 0 ? '' : _option$salt, | ||
_option$override = option.override, | ||
override = _option$override === void 0 ? EMPTY_OVERRIDE : _option$override, | ||
formatToken = option.formatToken; | ||
salt = _option$salt === void 0 ? '' : _option$salt, | ||
_option$override = option.override, | ||
override = _option$override === void 0 ? EMPTY_OVERRIDE : _option$override, | ||
formatToken = option.formatToken; // Basic - We do basic cache here | ||
// Basic - We do basic cache here | ||
var mergedToken = React.useMemo(function () { | ||
@@ -87,13 +102,11 @@ return Object.assign.apply(Object, [{}].concat((0, _toConsumableArray2.default)(tokens))); | ||
var cachedToken = (0, _useGlobalCache.default)('token', [salt, theme.id, tokenStr, overrideTokenStr], function () { | ||
var derivativeToken = theme.getDerivativeToken(mergedToken); | ||
var derivativeToken = theme.getDerivativeToken(mergedToken); // Merge with override | ||
// Merge with override | ||
var mergedDerivativeToken = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, derivativeToken), override); | ||
var mergedDerivativeToken = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, derivativeToken), override); // Format if needed | ||
// Format if needed | ||
if (formatToken) { | ||
mergedDerivativeToken = formatToken(mergedDerivativeToken); | ||
} | ||
} // Optimize for `useStyleRegister` performance | ||
// Optimize for `useStyleRegister` performance | ||
var tokenKey = (0, _util.token2key)(mergedDerivativeToken, salt); | ||
@@ -100,0 +113,0 @@ mergedDerivativeToken._tokenKey = tokenKey; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,26 +11,35 @@ value: true | ||
exports.default = useClientCache; | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _StyleContext = _interopRequireDefault(require("../StyleContext")); | ||
var _useHMR = _interopRequireDefault(require("./useHMR")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function useClientCache(prefix, keyPath, cacheFn, onCacheRemove) { | ||
var _React$useContext = React.useContext(_StyleContext.default), | ||
globalCache = _React$useContext.cache; | ||
globalCache = _React$useContext.cache; | ||
var fullPath = [prefix].concat((0, _toConsumableArray2.default)(keyPath)); | ||
var HMRUpdate = (0, _useHMR.default)(); | ||
var HMRUpdate = (0, _useHMR.default)(); // Create cache | ||
// Create cache | ||
React.useMemo(function () { | ||
globalCache.update(fullPath, function (prevCache) { | ||
var _ref = prevCache || [], | ||
_ref2 = (0, _slicedToArray2.default)(_ref, 2), | ||
_ref2$ = _ref2[0], | ||
times = _ref2$ === void 0 ? 0 : _ref2$, | ||
cache = _ref2[1]; | ||
_ref2 = (0, _slicedToArray2.default)(_ref, 2), | ||
_ref2$ = _ref2[0], | ||
times = _ref2$ === void 0 ? 0 : _ref2$, | ||
cache = _ref2[1]; // HMR should always ignore cache since developer may change it | ||
// HMR should always ignore cache since developer may change it | ||
var tmpCache = cache; | ||
if (process.env.NODE_ENV !== 'production' && cache && HMRUpdate) { | ||
@@ -38,10 +49,12 @@ onCacheRemove === null || onCacheRemove === void 0 ? void 0 : onCacheRemove(tmpCache, HMRUpdate); | ||
} | ||
var mergedCache = tmpCache || cacheFn(); | ||
return [times + 1, mergedCache]; | ||
}); | ||
}, /* eslint-disable react-hooks/exhaustive-deps */ | ||
}, | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
[fullPath.join('_')] | ||
/* eslint-enable */); | ||
/* eslint-enable */ | ||
); // Remove if no need anymore | ||
// Remove if no need anymore | ||
React.useEffect(function () { | ||
@@ -51,7 +64,9 @@ return function () { | ||
var _ref3 = prevCache || [], | ||
_ref4 = (0, _slicedToArray2.default)(_ref3, 2), | ||
_ref4$ = _ref4[0], | ||
times = _ref4$ === void 0 ? 0 : _ref4$, | ||
cache = _ref4[1]; | ||
_ref4 = (0, _slicedToArray2.default)(_ref3, 2), | ||
_ref4$ = _ref4[0], | ||
times = _ref4$ === void 0 ? 0 : _ref4$, | ||
cache = _ref4[1]; | ||
var nextCount = times - 1; | ||
if (nextCount === 0) { | ||
@@ -61,2 +76,3 @@ onCacheRemove === null || onCacheRemove === void 0 ? void 0 : onCacheRemove(cache, false); | ||
} | ||
return [times - 1, cache]; | ||
@@ -63,0 +79,0 @@ }); |
@@ -7,16 +7,25 @@ "use strict"; | ||
exports.default = void 0; | ||
function useProdHMR() { | ||
return false; | ||
} | ||
var webpackHMR = false; | ||
function useDevHMR() { | ||
return webpackHMR; | ||
} | ||
var _default = process.env.NODE_ENV === 'production' ? useProdHMR : useDevHMR; // Webpack `module.hot.accept` do not support any deps update trigger | ||
// We have to hack handler to force mark as HRM | ||
exports.default = _default; | ||
if (process.env.NODE_ENV !== 'production' && typeof module !== 'undefined' && module && module.hot) { | ||
var win = window; | ||
if (typeof win.webpackHotUpdate === 'function') { | ||
var originWebpackHotUpdate = win.webpackHotUpdate; | ||
win.webpackHotUpdate = function () { | ||
@@ -23,0 +32,0 @@ webpackHMR = true; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof3 = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -13,24 +15,43 @@ value: true | ||
exports.parseStyle = void 0; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2")); | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _hash = _interopRequireDefault(require("@emotion/hash")); | ||
var _canUseDom = _interopRequireDefault(require("rc-util/lib/Dom/canUseDom")); | ||
var _dynamicCSS = require("rc-util/lib/Dom/dynamicCSS"); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _unitless = _interopRequireDefault(require("@emotion/unitless")); | ||
var _stylis = require("stylis"); | ||
var _linters = require("../linters"); | ||
var _StyleContext = _interopRequireWildcard(require("../StyleContext")); | ||
var _util = require("../util"); | ||
var _useGlobalCache3 = _interopRequireDefault(require("./useGlobalCache")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
// @ts-ignore | ||
var isClientSide = (0, _canUseDom.default)(); | ||
var SKIP_CHECK = '_skip_check_'; | ||
// ============================================================================ | ||
@@ -44,7 +65,8 @@ // == Parser == | ||
} | ||
function isCompoundCSSProperty(value) { | ||
return (0, _typeof2.default)(value) === 'object' && value && SKIP_CHECK in value; | ||
} | ||
} // 注入 hash 值 | ||
// 注入 hash 值 | ||
function injectSelectorHash(key, hashId, hashPriority) { | ||
@@ -54,11 +76,11 @@ if (!hashId) { | ||
} | ||
var hashClassName = ".".concat(hashId); | ||
var hashSelector = hashPriority === 'low' ? ":where(".concat(hashClassName, ")") : hashClassName; | ||
var hashSelector = hashPriority === 'low' ? ":where(".concat(hashClassName, ")") : hashClassName; // 注入 hashId | ||
// 注入 hashId | ||
var keys = key.split(',').map(function (k) { | ||
var _firstPath$match; | ||
var fullPath = k.trim().split(/\s+/); | ||
// 如果 Selector 第一个是 HTML Element,那我们就插到它的后面。反之,就插到最前面。 | ||
var fullPath = k.trim().split(/\s+/); // 如果 Selector 第一个是 HTML Element,那我们就插到它的后面。反之,就插到最前面。 | ||
var firstPath = fullPath[0] || ''; | ||
@@ -71,46 +93,54 @@ var htmlElement = ((_firstPath$match = firstPath.match(/^\w+/)) === null || _firstPath$match === void 0 ? void 0 : _firstPath$match[0]) || ''; | ||
} | ||
// Global effect style will mount once and not removed | ||
// The effect will not save in SSR cache (e.g. keyframes) | ||
var globalEffectStyleKeys = new Set(); | ||
/** | ||
* @private Test only. Clear the global effect style keys. | ||
*/ | ||
var _cf = process.env.NODE_ENV !== 'production' ? function () { | ||
return globalEffectStyleKeys.clear(); | ||
} : undefined; | ||
} : undefined; // Parse CSSObject to style content | ||
// Parse CSSObject to style content | ||
exports._cf = _cf; | ||
var parseStyle = function parseStyle(interpolation) { | ||
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { | ||
root: true, | ||
parentSelectors: [] | ||
}, | ||
root = _ref.root, | ||
injectHash = _ref.injectHash, | ||
parentSelectors = _ref.parentSelectors; | ||
root: true, | ||
parentSelectors: [] | ||
}, | ||
root = _ref.root, | ||
injectHash = _ref.injectHash, | ||
parentSelectors = _ref.parentSelectors; | ||
var hashId = config.hashId, | ||
layer = config.layer, | ||
path = config.path, | ||
hashPriority = config.hashPriority, | ||
_config$transformers = config.transformers, | ||
transformers = _config$transformers === void 0 ? [] : _config$transformers, | ||
_config$linters = config.linters, | ||
linters = _config$linters === void 0 ? [] : _config$linters; | ||
layer = config.layer, | ||
path = config.path, | ||
hashPriority = config.hashPriority, | ||
_config$transformers = config.transformers, | ||
transformers = _config$transformers === void 0 ? [] : _config$transformers, | ||
_config$linters = config.linters, | ||
linters = _config$linters === void 0 ? [] : _config$linters; | ||
var styleStr = ''; | ||
var effectStyle = {}; | ||
function parseKeyframes(keyframes) { | ||
var animationName = keyframes.getName(hashId); | ||
if (!effectStyle[animationName]) { | ||
var _parseStyle = parseStyle(keyframes.style, config, { | ||
root: false, | ||
parentSelectors: parentSelectors | ||
}), | ||
_parseStyle2 = (0, _slicedToArray2.default)(_parseStyle, 1), | ||
_parsedStr = _parseStyle2[0]; | ||
root: false, | ||
parentSelectors: parentSelectors | ||
}), | ||
_parseStyle2 = (0, _slicedToArray2.default)(_parseStyle, 1), | ||
_parsedStr = _parseStyle2[0]; | ||
effectStyle[animationName] = "@keyframes ".concat(keyframes.getName(hashId)).concat(_parsedStr); | ||
} | ||
} | ||
function flattenList(list) { | ||
@@ -127,2 +157,3 @@ var fullList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
} | ||
var flattenStyleList = flattenList(Array.isArray(interpolation) ? interpolation : [interpolation]); | ||
@@ -132,2 +163,3 @@ flattenStyleList.forEach(function (originStyle) { | ||
var style = typeof originStyle === 'string' && !root ? {} : originStyle; | ||
if (typeof style === 'string') { | ||
@@ -141,17 +173,16 @@ styleStr += "".concat(style, "\n"); | ||
var _trans$visit; | ||
return (trans === null || trans === void 0 ? void 0 : (_trans$visit = trans.visit) === null || _trans$visit === void 0 ? void 0 : _trans$visit.call(trans, prev)) || prev; | ||
}, style); | ||
}, style); // Normal CSSObject | ||
// Normal CSSObject | ||
Object.keys(mergedStyle).forEach(function (key) { | ||
var value = mergedStyle[key]; | ||
if ((0, _typeof2.default)(value) === 'object' && value && (key !== 'animationName' || !value._keyframe) && !isCompoundCSSProperty(value)) { | ||
var subInjectHash = false; | ||
var subInjectHash = false; // 当成嵌套对象来处理 | ||
// 当成嵌套对象来处理 | ||
var mergedKey = key.trim(); | ||
// Whether treat child as root. In most case it is false. | ||
var nextRoot = false; | ||
var mergedKey = key.trim(); // Whether treat child as root. In most case it is false. | ||
// 拆分多个选择器 | ||
var nextRoot = false; // 拆分多个选择器 | ||
if ((root || injectHash) && hashId) { | ||
@@ -174,10 +205,12 @@ if (mergedKey.startsWith('@')) { | ||
} | ||
var _parseStyle3 = parseStyle(value, config, { | ||
root: nextRoot, | ||
injectHash: subInjectHash, | ||
parentSelectors: [].concat((0, _toConsumableArray2.default)(parentSelectors), [mergedKey]) | ||
}), | ||
_parseStyle4 = (0, _slicedToArray2.default)(_parseStyle3, 2), | ||
_parsedStr2 = _parseStyle4[0], | ||
childEffectStyle = _parseStyle4[1]; | ||
root: nextRoot, | ||
injectHash: subInjectHash, | ||
parentSelectors: [].concat((0, _toConsumableArray2.default)(parentSelectors), [mergedKey]) | ||
}), | ||
_parseStyle4 = (0, _slicedToArray2.default)(_parseStyle3, 2), | ||
_parsedStr2 = _parseStyle4[0], | ||
childEffectStyle = _parseStyle4[1]; | ||
effectStyle = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, effectStyle), childEffectStyle); | ||
@@ -187,3 +220,5 @@ styleStr += "".concat(mergedKey).concat(_parsedStr2); | ||
var _value; | ||
var actualValue = (_value = value === null || value === void 0 ? void 0 : value.value) !== null && _value !== void 0 ? _value : value; | ||
if (process.env.NODE_ENV !== 'production' && ((0, _typeof2.default)(value) !== 'object' || !(value !== null && value !== void 0 && value[SKIP_CHECK]))) { | ||
@@ -197,16 +232,16 @@ [_linters.contentQuotesLinter, _linters.hashedAnimationLinter].concat((0, _toConsumableArray2.default)(linters)).forEach(function (linter) { | ||
}); | ||
} | ||
} // 如果是样式则直接插入 | ||
// 如果是样式则直接插入 | ||
var styleName = key.replace(/[A-Z]/g, function (match) { | ||
return "-".concat(match.toLowerCase()); | ||
}); | ||
}); // Auto suffix with px | ||
// Auto suffix with px | ||
var formatValue = actualValue; | ||
if (!_unitless.default[key] && typeof formatValue === 'number' && formatValue !== 0) { | ||
formatValue = "".concat(formatValue, "px"); | ||
} | ||
} // handle animationName & Keyframe value | ||
// handle animationName & Keyframe value | ||
if (key === 'animationName' && value !== null && value !== void 0 && value._keyframe) { | ||
@@ -216,2 +251,3 @@ parseKeyframes(value); | ||
} | ||
styleStr += "".concat(styleName, ":").concat(formatValue, ";"); | ||
@@ -222,2 +258,3 @@ } | ||
}); | ||
if (!root) { | ||
@@ -228,5 +265,4 @@ styleStr = "{".concat(styleStr, "}"); | ||
var layerName = layerCells[layerCells.length - 1].trim(); | ||
styleStr = "@layer ".concat(layerName, " {").concat(styleStr, "}"); | ||
styleStr = "@layer ".concat(layerName, " {").concat(styleStr, "}"); // Order of layer if needed | ||
// Order of layer if needed | ||
if (layerCells.length > 1) { | ||
@@ -237,106 +273,115 @@ // zombieJ: stylis do not support layer order, so we need to handle it manually. | ||
} | ||
return [styleStr, effectStyle]; | ||
}; | ||
// ============================================================================ | ||
}; // ============================================================================ | ||
// == Register == | ||
// ============================================================================ | ||
exports.parseStyle = parseStyle; | ||
function uniqueHash(path, styleStr) { | ||
return (0, _hash.default)("".concat(path.join('%')).concat(styleStr)); | ||
} | ||
function Empty() { | ||
return null; | ||
} | ||
/** | ||
* Register a style to the global style sheet. | ||
*/ | ||
function useStyleRegister(info, styleFn) { | ||
var token = info.token, | ||
path = info.path, | ||
hashId = info.hashId, | ||
layer = info.layer; | ||
path = info.path, | ||
hashId = info.hashId, | ||
layer = info.layer; | ||
var _React$useContext = React.useContext(_StyleContext.default), | ||
autoClear = _React$useContext.autoClear, | ||
mock = _React$useContext.mock, | ||
defaultCache = _React$useContext.defaultCache, | ||
hashPriority = _React$useContext.hashPriority, | ||
container = _React$useContext.container, | ||
ssrInline = _React$useContext.ssrInline, | ||
transformers = _React$useContext.transformers, | ||
linters = _React$useContext.linters; | ||
autoClear = _React$useContext.autoClear, | ||
mock = _React$useContext.mock, | ||
defaultCache = _React$useContext.defaultCache, | ||
hashPriority = _React$useContext.hashPriority, | ||
container = _React$useContext.container, | ||
ssrInline = _React$useContext.ssrInline, | ||
transformers = _React$useContext.transformers, | ||
linters = _React$useContext.linters; | ||
var tokenKey = token._tokenKey; | ||
var fullPath = [tokenKey].concat((0, _toConsumableArray2.default)(path)); | ||
var fullPath = [tokenKey].concat((0, _toConsumableArray2.default)(path)); // Check if need insert style | ||
// Check if need insert style | ||
var isMergedClientSide = isClientSide; | ||
if (process.env.NODE_ENV !== 'production' && mock !== undefined) { | ||
isMergedClientSide = mock === 'client'; | ||
} | ||
var _useGlobalCache = (0, _useGlobalCache3.default)('style', fullPath, | ||
// Create cache if needed | ||
function () { | ||
var styleObj = styleFn(); | ||
var _parseStyle5 = parseStyle(styleObj, { | ||
hashId: hashId, | ||
hashPriority: hashPriority, | ||
layer: layer, | ||
path: path.join('-'), | ||
transformers: transformers, | ||
linters: linters | ||
}), | ||
var _useGlobalCache = (0, _useGlobalCache3.default)('style', fullPath, // Create cache if needed | ||
function () { | ||
var styleObj = styleFn(); | ||
var _parseStyle5 = parseStyle(styleObj, { | ||
hashId: hashId, | ||
hashPriority: hashPriority, | ||
layer: layer, | ||
path: path.join('-'), | ||
transformers: transformers, | ||
linters: linters | ||
}), | ||
_parseStyle6 = (0, _slicedToArray2.default)(_parseStyle5, 2), | ||
parsedStyle = _parseStyle6[0], | ||
effectStyle = _parseStyle6[1]; | ||
var styleStr = normalizeStyle(parsedStyle); | ||
var styleId = uniqueHash(fullPath, styleStr); | ||
if (isMergedClientSide) { | ||
var style = (0, _dynamicCSS.updateCSS)(styleStr, styleId, { | ||
mark: _StyleContext.ATTR_MARK, | ||
prepend: 'queue', | ||
attachTo: container | ||
}); | ||
style[_StyleContext.CSS_IN_JS_INSTANCE] = _StyleContext.CSS_IN_JS_INSTANCE_ID; | ||
// Used for `useCacheToken` to remove on batch when token removed | ||
style.setAttribute(_StyleContext.ATTR_TOKEN, tokenKey); | ||
var styleStr = normalizeStyle(parsedStyle); | ||
var styleId = uniqueHash(fullPath, styleStr); | ||
// Dev usage to find which cache path made this easily | ||
if (process.env.NODE_ENV !== 'production') { | ||
style.setAttribute(_StyleContext.ATTR_DEV_CACHE_PATH, fullPath.join('|')); | ||
if (isMergedClientSide) { | ||
var style = (0, _dynamicCSS.updateCSS)(styleStr, styleId, { | ||
mark: _StyleContext.ATTR_MARK, | ||
prepend: 'queue', | ||
attachTo: container | ||
}); | ||
style[_StyleContext.CSS_IN_JS_INSTANCE] = _StyleContext.CSS_IN_JS_INSTANCE_ID; // Used for `useCacheToken` to remove on batch when token removed | ||
style.setAttribute(_StyleContext.ATTR_TOKEN, tokenKey); // Dev usage to find which cache path made this easily | ||
if (process.env.NODE_ENV !== 'production') { | ||
style.setAttribute(_StyleContext.ATTR_DEV_CACHE_PATH, fullPath.join('|')); | ||
} // Inject client side effect style | ||
Object.keys(effectStyle).forEach(function (effectKey) { | ||
if (!globalEffectStyleKeys.has(effectKey)) { | ||
globalEffectStyleKeys.add(effectKey); // Inject | ||
(0, _dynamicCSS.updateCSS)(normalizeStyle(effectStyle[effectKey]), "_effect-".concat(effectKey), { | ||
mark: _StyleContext.ATTR_MARK, | ||
prepend: 'queue', | ||
attachTo: container | ||
}); | ||
} | ||
}); | ||
} | ||
// Inject client side effect style | ||
Object.keys(effectStyle).forEach(function (effectKey) { | ||
if (!globalEffectStyleKeys.has(effectKey)) { | ||
globalEffectStyleKeys.add(effectKey); | ||
return [styleStr, tokenKey, styleId]; | ||
}, // Remove cache if no need | ||
function (_ref2, fromHMR) { | ||
var _ref3 = (0, _slicedToArray2.default)(_ref2, 3), | ||
styleId = _ref3[2]; | ||
// Inject | ||
(0, _dynamicCSS.updateCSS)(normalizeStyle(effectStyle[effectKey]), "_effect-".concat(effectKey), { | ||
mark: _StyleContext.ATTR_MARK, | ||
prepend: 'queue', | ||
attachTo: container | ||
}); | ||
} | ||
}); | ||
} | ||
return [styleStr, tokenKey, styleId]; | ||
}, | ||
// Remove cache if no need | ||
function (_ref2, fromHMR) { | ||
var _ref3 = (0, _slicedToArray2.default)(_ref2, 3), | ||
styleId = _ref3[2]; | ||
if ((fromHMR || autoClear) && isClientSide) { | ||
(0, _dynamicCSS.removeCSS)(styleId, { | ||
mark: _StyleContext.ATTR_MARK | ||
}); | ||
} | ||
}), | ||
_useGlobalCache2 = (0, _slicedToArray2.default)(_useGlobalCache, 3), | ||
cachedStyleStr = _useGlobalCache2[0], | ||
cachedTokenKey = _useGlobalCache2[1], | ||
cachedStyleId = _useGlobalCache2[2]; | ||
if ((fromHMR || autoClear) && isClientSide) { | ||
(0, _dynamicCSS.removeCSS)(styleId, { | ||
mark: _StyleContext.ATTR_MARK | ||
}); | ||
} | ||
}), | ||
_useGlobalCache2 = (0, _slicedToArray2.default)(_useGlobalCache, 3), | ||
cachedStyleStr = _useGlobalCache2[0], | ||
cachedTokenKey = _useGlobalCache2[1], | ||
cachedStyleId = _useGlobalCache2[2]; | ||
return function (node) { | ||
var styleNode; | ||
if (!ssrInline || isMergedClientSide || !defaultCache) { | ||
@@ -346,2 +391,3 @@ styleNode = /*#__PURE__*/React.createElement(Empty, null); | ||
var _ref4; | ||
styleNode = /*#__PURE__*/React.createElement("style", (0, _extends2.default)({}, (_ref4 = {}, (0, _defineProperty2.default)(_ref4, _StyleContext.ATTR_TOKEN, cachedTokenKey), (0, _defineProperty2.default)(_ref4, _StyleContext.ATTR_MARK, cachedStyleId), _ref4), { | ||
@@ -353,9 +399,10 @@ dangerouslySetInnerHTML: { | ||
} | ||
return /*#__PURE__*/React.createElement(React.Fragment, null, styleNode, node); | ||
}; | ||
} | ||
// ============================================================================ | ||
} // ============================================================================ | ||
// == SSR == | ||
// ============================================================================ | ||
function extractStyle(cache) { | ||
@@ -365,12 +412,11 @@ // prefix with `style` is used for `useStyleRegister` to cache style context | ||
return key.startsWith('style%'); | ||
}); | ||
}); // const tokenStyles: Record<string, string[]> = {}; | ||
// const tokenStyles: Record<string, string[]> = {}; | ||
var styleText = ''; | ||
styleKeys.forEach(function (key) { | ||
var _ = (0, _slicedToArray2.default)(cache.cache.get(key)[1], 3), | ||
styleStr = _[0], | ||
tokenKey = _[1], | ||
styleId = _[2]; | ||
styleStr = _[0], | ||
tokenKey = _[1], | ||
styleId = _[2]; | ||
styleText += "<style ".concat(_StyleContext.ATTR_TOKEN, "=\"").concat(tokenKey, "\" ").concat(_StyleContext.ATTR_MARK, "=\"").concat(styleId, "\">").concat(styleStr, "</style>"); | ||
@@ -377,0 +423,0 @@ }); |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -74,10 +76,19 @@ value: true | ||
}); | ||
var _useCacheToken = _interopRequireDefault(require("./hooks/useCacheToken")); | ||
var _useStyleRegister = _interopRequireWildcard(require("./hooks/useStyleRegister")); | ||
var _Keyframes = _interopRequireDefault(require("./Keyframes")); | ||
var _linters = require("./linters"); | ||
var _StyleContext = require("./StyleContext"); | ||
var _theme = require("./theme"); | ||
var _legacyLogicalProperties = _interopRequireDefault(require("./transformers/legacyLogicalProperties")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,5 +9,9 @@ value: true | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var Keyframe = /*#__PURE__*/function () { | ||
@@ -21,2 +26,3 @@ function Keyframe(name, style) { | ||
} | ||
(0, _createClass2.default)(Keyframe, [{ | ||
@@ -31,3 +37,4 @@ key: "getName", | ||
}(); | ||
var _default = Keyframe; | ||
exports.default = _default; |
@@ -7,3 +7,5 @@ "use strict"; | ||
exports.default = void 0; | ||
var _utils = require("./utils"); | ||
var linter = function linter(key, value, info) { | ||
@@ -14,2 +16,3 @@ if (key === 'content') { | ||
var contentValues = ['normal', 'none', 'initial', 'inherit', 'unset']; | ||
if (typeof value !== 'string' || contentValues.indexOf(value) === -1 && !contentValuePattern.test(value) && (value.charAt(0) !== value.charAt(value.length - 1) || value.charAt(0) !== '"' && value.charAt(0) !== "'")) { | ||
@@ -20,3 +23,4 @@ (0, _utils.lintWarning)("You seem to be using a value for 'content' without quotes, try replacing it with `content: '\"".concat(value, "\"'`."), info); | ||
}; | ||
var _default = linter; | ||
exports.default = _default; |
@@ -7,3 +7,5 @@ "use strict"; | ||
exports.default = void 0; | ||
var _utils = require("./utils"); | ||
var linter = function linter(key, value, info) { | ||
@@ -16,3 +18,4 @@ if (key === 'animation') { | ||
}; | ||
var _default = linter; | ||
exports.default = _default; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -31,5 +32,9 @@ value: true | ||
}); | ||
var _contentQuotesLinter = _interopRequireDefault(require("./contentQuotesLinter")); | ||
var _hashedAnimationLinter = _interopRequireDefault(require("./hashedAnimationLinter")); | ||
var _legacyNotSelectorLinter = _interopRequireDefault(require("./legacyNotSelectorLinter")); | ||
var _logicalPropertiesLinter = _interopRequireDefault(require("./logicalPropertiesLinter")); |
@@ -7,12 +7,17 @@ "use strict"; | ||
exports.default = void 0; | ||
var _utils = require("./utils"); | ||
function isConcatSelector(selector) { | ||
var _selector$match; | ||
var notContent = ((_selector$match = selector.match(/:not\(([^)]*)\)/)) === null || _selector$match === void 0 ? void 0 : _selector$match[1]) || ''; | ||
// split selector. e.g. | ||
var notContent = ((_selector$match = selector.match(/:not\(([^)]*)\)/)) === null || _selector$match === void 0 ? void 0 : _selector$match[1]) || ''; // split selector. e.g. | ||
// `h1#a.b` => ['h1', #a', '.b'] | ||
var splitCells = notContent.split(/(?=[.#])/); | ||
var splitCells = notContent.split(/(\[[^[]*])|(?=[.#])/).filter(function (str) { | ||
return str; | ||
}); | ||
return splitCells.length > 1; | ||
} | ||
function parsePath(info) { | ||
@@ -23,8 +28,11 @@ return info.parentSelectors.reduce(function (prev, cur) { | ||
} | ||
return cur.includes('&') ? cur.replace(/\&/g, prev) : "".concat(prev, " ").concat(cur); | ||
return cur.includes('&') ? cur.replace(/&/g, prev) : "".concat(prev, " ").concat(cur); | ||
}, ''); | ||
} | ||
var linter = function linter(key, value, info) { | ||
var parentSelectorPath = parsePath(info); | ||
var notList = parentSelectorPath.match(/:not\([^)]*\)/g) || []; | ||
if (notList.length > 0 && notList.some(isConcatSelector)) { | ||
@@ -34,3 +42,4 @@ (0, _utils.lintWarning)("Concat ':not' selector not support in legacy browsers.", info); | ||
}; | ||
var _default = linter; | ||
exports.default = _default; |
@@ -7,3 +7,5 @@ "use strict"; | ||
exports.default = void 0; | ||
var _utils = require("./utils"); | ||
var linter = function linter(key, value, info) { | ||
@@ -31,2 +33,3 @@ switch (key) { | ||
return; | ||
case 'margin': | ||
@@ -41,2 +44,3 @@ case 'padding': | ||
}); | ||
if (valueArr.length === 4 && valueArr[1] !== valueArr[3]) { | ||
@@ -46,3 +50,5 @@ (0, _utils.lintWarning)("You seem to be using '".concat(key, "' property with different left ").concat(key, " and right ").concat(key, ", which is not compatible with RTL mode. Please use logical properties and values instead. For more information: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties."), info); | ||
} | ||
return; | ||
case 'clear': | ||
@@ -53,3 +59,5 @@ case 'textAlign': | ||
} | ||
return; | ||
case 'borderRadius': | ||
@@ -64,19 +72,24 @@ if (typeof value === 'string') { | ||
} | ||
var radiusArr = group.split(' ').map(function (item) { | ||
return item.trim(); | ||
}); | ||
// borderRadius: '2px 4px' | ||
}); // borderRadius: '2px 4px' | ||
if (radiusArr.length >= 2 && radiusArr[0] !== radiusArr[1]) { | ||
return true; | ||
} | ||
// borderRadius: '4px 4px 2px' | ||
} // borderRadius: '4px 4px 2px' | ||
if (radiusArr.length === 3 && radiusArr[1] !== radiusArr[2]) { | ||
return true; | ||
} | ||
// borderRadius: '4px 4px 2px 4px' | ||
} // borderRadius: '4px 4px 2px 4px' | ||
if (radiusArr.length === 4 && radiusArr[2] !== radiusArr[3]) { | ||
return true; | ||
} | ||
return result; | ||
}, false); | ||
if (invalid) { | ||
@@ -86,7 +99,10 @@ (0, _utils.lintWarning)("You seem to be using non-logical value '".concat(value, "' of ").concat(key, ", which is not compatible with RTL mode. Please use logical properties and values instead. For more information: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties."), info); | ||
} | ||
return; | ||
default: | ||
} | ||
}; | ||
var _default = linter; | ||
exports.default = _default; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,7 +9,9 @@ value: true | ||
exports.lintWarning = lintWarning; | ||
var _warning = _interopRequireDefault(require("rc-util/lib/warning")); | ||
function lintWarning(message, info) { | ||
var path = info.path, | ||
parentSelectors = info.parentSelectors; | ||
(0, _warning.default)(false, "[Ant Design CSS-in-JS] ".concat(path ? "Error in '".concat(path, "': ") : '').concat(message).concat(parentSelectors.length ? " Selector info: ".concat(parentSelectors.join(' -> '), ")") : '')); | ||
parentSelectors = info.parentSelectors; | ||
(0, _warning.default)(false, "[Ant Design CSS-in-JS] ".concat(path ? "Error in '".concat(path, "': ") : '').concat(message).concat(parentSelectors.length ? " Selector info: ".concat(parentSelectors.join(' -> ')) : '')); | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,11 +13,21 @@ value: true | ||
exports.default = void 0; | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2")); | ||
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); | ||
var _useMemo = _interopRequireDefault(require("rc-util/lib/hooks/useMemo")); | ||
var _isEqual = _interopRequireDefault(require("rc-util/lib/isEqual")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _Cache = _interopRequireDefault(require("./Cache")); | ||
var _excluded = ["children"]; | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
var ATTR_TOKEN = 'data-token-hash'; | ||
@@ -25,5 +37,4 @@ exports.ATTR_TOKEN = ATTR_TOKEN; | ||
exports.ATTR_MARK = ATTR_MARK; | ||
var ATTR_DEV_CACHE_PATH = 'data-dev-cache-path'; | ||
var ATTR_DEV_CACHE_PATH = 'data-dev-cache-path'; // Mark css-in-js instance in style element | ||
// Mark css-in-js instance in style element | ||
exports.ATTR_DEV_CACHE_PATH = ATTR_DEV_CACHE_PATH; | ||
@@ -34,2 +45,3 @@ var CSS_IN_JS_INSTANCE = '__cssinjs_instance__'; | ||
exports.CSS_IN_JS_INSTANCE_ID = CSS_IN_JS_INSTANCE_ID; | ||
function createCache() { | ||
@@ -40,15 +52,15 @@ if (typeof document !== 'undefined' && document.head && document.body) { | ||
Array.from(styles).forEach(function (style) { | ||
style[CSS_IN_JS_INSTANCE] = style[CSS_IN_JS_INSTANCE] || CSS_IN_JS_INSTANCE_ID; | ||
style[CSS_IN_JS_INSTANCE] = style[CSS_IN_JS_INSTANCE] || CSS_IN_JS_INSTANCE_ID; // Not force move if no head | ||
// Not force move if no head | ||
document.head.insertBefore(style, firstChild); | ||
}); | ||
}); // Deduplicate of moved styles | ||
// Deduplicate of moved styles | ||
var styleHash = {}; | ||
Array.from(document.querySelectorAll("style[".concat(ATTR_MARK, "]"))).forEach(function (style) { | ||
var hash = style.getAttribute(ATTR_MARK); | ||
if (styleHash[hash]) { | ||
if (style[CSS_IN_JS_INSTANCE] === CSS_IN_JS_INSTANCE_ID) { | ||
var _style$parentNode; | ||
(_style$parentNode = style.parentNode) === null || _style$parentNode === void 0 ? void 0 : _style$parentNode.removeChild(style); | ||
@@ -61,4 +73,6 @@ } | ||
} | ||
return new _Cache.default(); | ||
} | ||
var StyleContext = /*#__PURE__*/React.createContext({ | ||
@@ -69,5 +83,6 @@ hashPriority: 'low', | ||
}); | ||
var StyleProvider = function StyleProvider(props) { | ||
var children = props.children, | ||
restProps = (0, _objectWithoutProperties2.default)(props, _excluded); | ||
restProps = (0, _objectWithoutProperties2.default)(props, _excluded); | ||
var parentContext = React.useContext(StyleContext); | ||
@@ -78,2 +93,3 @@ var context = (0, _useMemo.default)(function () { | ||
var value = restProps[key]; | ||
if (restProps[key] !== undefined) { | ||
@@ -94,4 +110,5 @@ mergedContext[key] = value; | ||
}; | ||
exports.StyleProvider = StyleProvider; | ||
var _default = StyleContext; | ||
exports.default = _default; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,18 +9,21 @@ value: true | ||
exports.default = createTheme; | ||
var _ThemeCache = _interopRequireDefault(require("./ThemeCache")); | ||
var _Theme = _interopRequireDefault(require("./Theme")); | ||
var cacheThemes = new _ThemeCache.default(); | ||
/** | ||
* Same as new Theme, but will always return same one if `derivative` not changed. | ||
*/ | ||
function createTheme(derivatives) { | ||
var derivativeArr = Array.isArray(derivatives) ? derivatives : [derivatives]; | ||
// Create new theme if not exist | ||
var derivativeArr = Array.isArray(derivatives) ? derivatives : [derivatives]; // Create new theme if not exist | ||
if (!cacheThemes.has(derivativeArr)) { | ||
cacheThemes.set(derivativeArr, new _Theme.default(derivativeArr)); | ||
} | ||
} // Get theme from cache and return | ||
// Get theme from cache and return | ||
return cacheThemes.get(derivativeArr); | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -25,4 +26,7 @@ value: true | ||
}); | ||
var _createTheme = _interopRequireDefault(require("./createTheme")); | ||
var _Theme = _interopRequireDefault(require("./Theme")); | ||
var _ThemeCache = _interopRequireDefault(require("./ThemeCache")); |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,8 +9,12 @@ value: true | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _warning = require("rc-util/lib/warning"); | ||
var uuid = 0; | ||
/** | ||
@@ -19,2 +24,3 @@ * Theme with algorithms to derive tokens from design tokens. | ||
*/ | ||
var Theme = /*#__PURE__*/function () { | ||
@@ -27,7 +33,10 @@ function Theme(derivatives) { | ||
this.id = uuid; | ||
if (derivatives.length === 0) { | ||
(0, _warning.warning)(derivatives.length > 0, '[Ant Design CSS-in-JS] Theme should have at least one derivative function.'); | ||
} | ||
uuid += 1; | ||
} | ||
(0, _createClass2.default)(Theme, [{ | ||
@@ -43,2 +52,3 @@ key: "getDerivativeToken", | ||
}(); | ||
exports.default = Theme; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,8 +10,12 @@ value: true | ||
exports.sameDerivativeOption = sameDerivativeOption; | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
// ================================== Cache ================================== | ||
function sameDerivativeOption(left, right) { | ||
@@ -20,2 +25,3 @@ if (left.length !== right.length) { | ||
} | ||
for (var i = 0; i < left.length; i++) { | ||
@@ -26,4 +32,6 @@ if (left[i] !== right[i]) { | ||
} | ||
return true; | ||
} | ||
var ThemeCache = /*#__PURE__*/function () { | ||
@@ -39,2 +47,3 @@ function ThemeCache() { | ||
} | ||
(0, _createClass2.default)(ThemeCache, [{ | ||
@@ -49,2 +58,3 @@ key: "size", | ||
var _cache2, _cache3; | ||
var updateCallTimes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
@@ -59,8 +69,11 @@ var cache = { | ||
var _cache, _cache$map; | ||
cache = (_cache = cache) === null || _cache === void 0 ? void 0 : (_cache$map = _cache.map) === null || _cache$map === void 0 ? void 0 : _cache$map.get(derivative); | ||
} | ||
}); | ||
if ((_cache2 = cache) !== null && _cache2 !== void 0 && _cache2.value && updateCallTimes) { | ||
cache.value[1] = this.cacheCallTimes++; | ||
} | ||
return (_cache3 = cache) === null || _cache3 === void 0 ? void 0 : _cache3.value; | ||
@@ -72,2 +85,3 @@ } | ||
var _this$internalGet; | ||
return (_this$internalGet = this.internalGet(derivativeOption, true)) === null || _this$internalGet === void 0 ? void 0 : _this$internalGet[0]; | ||
@@ -84,2 +98,3 @@ } | ||
var _this = this; | ||
// New cache | ||
@@ -89,15 +104,20 @@ if (!this.has(derivativeOption)) { | ||
var _this$keys$reduce = this.keys.reduce(function (result, key) { | ||
var _result = (0, _slicedToArray2.default)(result, 2), | ||
var _result = (0, _slicedToArray2.default)(result, 2), | ||
callTimes = _result[1]; | ||
if (_this.internalGet(key)[1] < callTimes) { | ||
return [key, _this.internalGet(key)[1]]; | ||
} | ||
return result; | ||
}, [this.keys[0], this.cacheCallTimes]), | ||
_this$keys$reduce2 = (0, _slicedToArray2.default)(_this$keys$reduce, 1), | ||
targetKey = _this$keys$reduce2[0]; | ||
if (_this.internalGet(key)[1] < callTimes) { | ||
return [key, _this.internalGet(key)[1]]; | ||
} | ||
return result; | ||
}, [this.keys[0], this.cacheCallTimes]), | ||
_this$keys$reduce2 = (0, _slicedToArray2.default)(_this$keys$reduce, 1), | ||
targetKey = _this$keys$reduce2[0]; | ||
this.delete(targetKey); | ||
} | ||
this.keys.push(derivativeOption); | ||
} | ||
var cache = this.cache; | ||
@@ -111,2 +131,3 @@ derivativeOption.forEach(function (derivative, index) { | ||
var cacheValue = cache.get(derivative); | ||
if (!cacheValue) { | ||
@@ -119,2 +140,3 @@ cache.set(derivative, { | ||
} | ||
cache = cache.get(derivative).map; | ||
@@ -128,4 +150,6 @@ } | ||
var cache = currentCache.get(derivatives[0]); | ||
if (derivatives.length === 1) { | ||
var _cache$value; | ||
if (!cache.map) { | ||
@@ -138,8 +162,12 @@ currentCache.delete(derivatives[0]); | ||
} | ||
return (_cache$value = cache.value) === null || _cache$value === void 0 ? void 0 : _cache$value[0]; | ||
} | ||
var result = this.deleteByPath(cache.map, derivatives.slice(1)); | ||
if ((!cache.map || cache.map.size === 0) && !cache.value) { | ||
currentCache.delete(derivatives[0]); | ||
} | ||
return result; | ||
@@ -157,2 +185,3 @@ } | ||
} | ||
return undefined; | ||
@@ -163,4 +192,5 @@ } | ||
}(); | ||
exports.default = ThemeCache; | ||
(0, _defineProperty2.default)(ThemeCache, "MAX_CACHE_SIZE", 20); | ||
(0, _defineProperty2.default)(ThemeCache, "MAX_CACHE_OFFSET", 5); |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.default = void 0; | ||
function splitValues(value) { | ||
@@ -12,5 +13,5 @@ if (typeof value === 'number') { | ||
} | ||
var splitStyle = String(value).split(/\s+/); | ||
// Combine styles split in brackets, like `calc(1px + 2px)` | ||
var splitStyle = String(value).split(/\s+/); // Combine styles split in brackets, like `calc(1px + 2px)` | ||
var temp = ''; | ||
@@ -25,2 +26,3 @@ var brackets = 0; | ||
brackets -= item.split(')').length - 1; | ||
if (brackets === 0) { | ||
@@ -35,5 +37,7 @@ list.push(temp); | ||
} | ||
return list; | ||
}, []); | ||
} | ||
function noSplit(list) { | ||
@@ -43,2 +47,3 @@ list.notSplit = true; | ||
} | ||
var keyMap = { | ||
@@ -101,2 +106,3 @@ // Inset | ||
}; | ||
function skipCheck(value) { | ||
@@ -108,3 +114,2 @@ return { | ||
} | ||
/** | ||
@@ -119,2 +124,4 @@ * Convert css logical properties to legacy properties. | ||
*/ | ||
var transform = { | ||
@@ -126,4 +133,6 @@ visit: function visit(cssObj) { | ||
var matchValue = keyMap[key]; | ||
if (matchValue && (typeof value === 'number' || typeof value === 'string')) { | ||
var values = splitValues(value); | ||
if (matchValue.length && matchValue.notSplit) { | ||
@@ -141,2 +150,3 @@ // not split means always give same value like border | ||
var _values$index; | ||
clone[matchKey] = skipCheck((_values$index = values[index]) !== null && _values$index !== void 0 ? _values$index : values[0]); | ||
@@ -148,2 +158,3 @@ }); | ||
var _ref, _values$index2; | ||
clone[matchKey] = skipCheck((_ref = (_values$index2 = values[index]) !== null && _values$index2 !== void 0 ? _values$index2 : values[index - 2]) !== null && _ref !== void 0 ? _ref : values[0]); | ||
@@ -150,0 +161,0 @@ }); |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -10,6 +11,11 @@ value: true | ||
exports.token2key = token2key; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _hash = _interopRequireDefault(require("@emotion/hash")); | ||
var _canUseDom = _interopRequireDefault(require("rc-util/lib/Dom/canUseDom")); | ||
var _dynamicCSS = require("rc-util/lib/Dom/dynamicCSS"); | ||
function flattenToken(token) { | ||
@@ -20,2 +26,3 @@ var str = ''; | ||
str += key; | ||
if (value && (0, _typeof2.default)(value) === 'object') { | ||
@@ -29,16 +36,22 @@ str += flattenToken(value); | ||
} | ||
/** | ||
* Convert derivative token to key string | ||
*/ | ||
function token2key(token, salt) { | ||
return (0, _hash.default)("".concat(salt, "_").concat(flattenToken(token))); | ||
} | ||
var layerKey = "layer-".concat(Date.now(), "-").concat(Math.random()).replace(/\./g, ''); | ||
var layerWidth = '903px'; | ||
function supportSelector(styleStr, handleElement) { | ||
if ((0, _canUseDom.default)()) { | ||
var _ele$parentNode; | ||
(0, _dynamicCSS.updateCSS)(styleStr, layerKey); | ||
var _ele = document.createElement('div'); | ||
_ele.style.position = 'fixed'; | ||
@@ -49,2 +62,3 @@ _ele.style.left = '0'; | ||
document.body.appendChild(_ele); | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -54,2 +68,3 @@ _ele.innerHTML = 'Test'; | ||
} | ||
var support = getComputedStyle(_ele).width === layerWidth; | ||
@@ -60,5 +75,8 @@ (_ele$parentNode = _ele.parentNode) === null || _ele$parentNode === void 0 ? void 0 : _ele$parentNode.removeChild(_ele); | ||
} | ||
return false; | ||
} | ||
var canLayer = undefined; | ||
function supportLayer() { | ||
@@ -70,3 +88,4 @@ if (canLayer === undefined) { | ||
} | ||
return canLayer; | ||
} |
{ | ||
"name": "@ant-design/cssinjs", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "Component level cssinjs resolution for antd", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
135608
2950