@ant-design/cssinjs
Advanced tools
Comparing version 1.4.0 to 1.5.0
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] | ||
@@ -9,6 +8,4 @@ var Entity = /*#__PURE__*/function () { | ||
_classCallCheck(this, Entity); | ||
_defineProperty(this, "cache", new Map()); | ||
} | ||
_createClass(Entity, [{ | ||
@@ -25,3 +22,2 @@ key: "get", | ||
var nextValue = valueFn(prevValue); | ||
if (nextValue === null) { | ||
@@ -34,6 +30,4 @@ this.cache.delete(path); | ||
}]); | ||
return Entity; | ||
}(); | ||
export default Entity; |
@@ -8,12 +8,11 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; | ||
import { flattenToken, token2key } from "../util"; | ||
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) { | ||
@@ -25,3 +24,2 @@ if (typeof document !== 'undefined') { | ||
var _style$parentNode; | ||
(_style$parentNode = style.parentNode) === null || _style$parentNode === void 0 ? void 0 : _style$parentNode.removeChild(style); | ||
@@ -31,5 +29,5 @@ } | ||
} | ||
} // Remove will check current keys first | ||
} | ||
// Remove will check current keys first | ||
function cleanTokenStyle(tokenKey) { | ||
@@ -42,3 +40,2 @@ tokenKeys.set(tokenKey, (tokenKeys.get(tokenKey) || 0) - 1); | ||
}); | ||
if (cleanableKeyList.length < tokenKeyList.length) { | ||
@@ -51,2 +48,3 @@ cleanableKeyList.forEach(function (key) { | ||
} | ||
/** | ||
@@ -59,12 +57,11 @@ * 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; // Basic - We do basic cache here | ||
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 | ||
var mergedToken = React.useMemo(function () { | ||
@@ -80,12 +77,13 @@ return Object.assign.apply(Object, [{}].concat(_toConsumableArray(tokens))); | ||
var cachedToken = useGlobalCache('token', [salt, theme.id, tokenStr, overrideTokenStr], function () { | ||
var derivativeToken = theme.getDerivativeToken(mergedToken); // Merge with override | ||
var derivativeToken = theme.getDerivativeToken(mergedToken); | ||
var mergedDerivativeToken = _objectSpread(_objectSpread({}, derivativeToken), override); // Format if needed | ||
// Merge with override | ||
var mergedDerivativeToken = _objectSpread(_objectSpread({}, derivativeToken), override); | ||
// Format if needed | ||
if (formatToken) { | ||
mergedDerivativeToken = formatToken(mergedDerivativeToken); | ||
} // Optimize for `useStyleRegister` performance | ||
} | ||
// Optimize for `useStyleRegister` performance | ||
var tokenKey = token2key(mergedDerivativeToken, salt); | ||
@@ -92,0 +90,0 @@ mergedDerivativeToken._tokenKey = tokenKey; |
@@ -8,18 +8,17 @@ 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(); // Create cache | ||
var HMRUpdate = useHMR(); | ||
// 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]; // HMR should always ignore cache since developer may change it | ||
_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 | ||
var tmpCache = cache; | ||
if (process.env.NODE_ENV !== 'production' && cache && HMRUpdate) { | ||
@@ -29,12 +28,10 @@ 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 */ | ||
); // Remove if no need anymore | ||
/* eslint-enable */); | ||
// Remove if no need anymore | ||
React.useEffect(function () { | ||
@@ -44,9 +41,7 @@ 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) { | ||
@@ -56,3 +51,2 @@ onCacheRemove === null || onCacheRemove === void 0 ? void 0 : onCacheRemove(cache, false); | ||
} | ||
return [times - 1, cache]; | ||
@@ -59,0 +53,0 @@ }); |
function useProdHMR() { | ||
return false; | ||
} | ||
var webpackHMR = false; | ||
function useDevHMR() { | ||
return webpackHMR; | ||
} | ||
export default process.env.NODE_ENV === 'production' ? useProdHMR : useDevHMR; | ||
export default process.env.NODE_ENV === 'production' ? useProdHMR : useDevHMR; // Webpack `module.hot.accept` do not support any deps update trigger | ||
// 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 () { | ||
@@ -21,0 +17,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,8 +29,7 @@ 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) { | ||
@@ -40,11 +39,11 @@ if (!hashId) { | ||
} | ||
var hashClassName = ".".concat(hashId); | ||
var hashSelector = hashPriority === 'low' ? ":where(".concat(hashClassName, ")") : hashClassName; // 注入 hashId | ||
var hashSelector = hashPriority === 'low' ? ":where(".concat(hashClassName, ")") : hashClassName; | ||
// 注入 hashId | ||
var keys = key.split(',').map(function (k) { | ||
var _firstPath$match; | ||
var fullPath = k.trim().split(/\s+/); | ||
var fullPath = k.trim().split(/\s+/); // 如果 Selector 第一个是 HTML Element,那我们就插到它的后面。反之,就插到最前面。 | ||
// 如果 Selector 第一个是 HTML Element,那我们就插到它的后面。反之,就插到最前面。 | ||
var firstPath = fullPath[0] || ''; | ||
@@ -57,51 +56,45 @@ 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; // Parse CSSObject to style content | ||
} : undefined; | ||
// 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) { | ||
@@ -118,3 +111,2 @@ var fullList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
} | ||
var flattenStyleList = flattenList(Array.isArray(interpolation) ? interpolation : [interpolation]); | ||
@@ -124,3 +116,2 @@ flattenStyleList.forEach(function (originStyle) { | ||
var style = typeof originStyle === 'string' && !root ? {} : originStyle; | ||
if (typeof style === 'string') { | ||
@@ -134,16 +125,17 @@ 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); // Normal CSSObject | ||
}, style); | ||
// 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 mergedKey = key.trim(); | ||
// Whether treat child as root. In most case it is false. | ||
var nextRoot = false; | ||
var nextRoot = false; // 拆分多个选择器 | ||
// 拆分多个选择器 | ||
if ((root || injectHash) && hashId) { | ||
@@ -166,12 +158,10 @@ 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); | ||
@@ -181,5 +171,3 @@ 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]))) { | ||
@@ -193,16 +181,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) { | ||
@@ -212,3 +200,2 @@ parseKeyframes(value); | ||
} | ||
styleStr += "".concat(styleName, ":").concat(formatValue, ";"); | ||
@@ -219,3 +206,2 @@ } | ||
}); | ||
if (!root) { | ||
@@ -226,4 +212,5 @@ styleStr = "{".concat(styleStr, "}"); | ||
var layerName = layerCells[layerCells.length - 1].trim(); | ||
styleStr = "@layer ".concat(layerName, " {").concat(styleStr, "}"); // Order of layer if needed | ||
styleStr = "@layer ".concat(layerName, " {").concat(styleStr, "}"); | ||
// Order of layer if needed | ||
if (layerCells.length > 1) { | ||
@@ -234,112 +221,105 @@ // zombieJ: stylis do not support layer order, so we need to handle it manually. | ||
} | ||
return [styleStr, effectStyle]; | ||
}; | ||
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)); // Check if need insert style | ||
var fullPath = [tokenKey].concat(_toConsumableArray(path)); | ||
// 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; | ||
var styleStr = normalizeStyle(parsedStyle); | ||
var styleId = uniqueHash(fullPath, styleStr); | ||
// Used for `useCacheToken` to remove on batch when token removed | ||
style.setAttribute(ATTR_TOKEN, tokenKey); | ||
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 | ||
// Dev usage to find which cache path made this easily | ||
if (process.env.NODE_ENV !== 'production') { | ||
style.setAttribute(ATTR_DEV_CACHE_PATH, fullPath.join('|')); | ||
} | ||
style.setAttribute(ATTR_TOKEN, tokenKey); // Dev usage to find which cache path made this easily | ||
// Inject client side effect style | ||
Object.keys(effectStyle).forEach(function (effectKey) { | ||
if (!globalEffectStyleKeys.has(effectKey)) { | ||
globalEffectStyleKeys.add(effectKey); | ||
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 | ||
}); | ||
} | ||
}); | ||
} | ||
return [styleStr, tokenKey, styleId]; | ||
}, // Remove cache if no need | ||
function (_ref2, fromHMR) { | ||
var _ref3 = _slicedToArray(_ref2, 3), | ||
// 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) { | ||
@@ -349,3 +329,2 @@ 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), { | ||
@@ -357,9 +336,9 @@ dangerouslySetInnerHTML: { | ||
} | ||
return /*#__PURE__*/React.createElement(React.Fragment, null, styleNode, node); | ||
}; | ||
} // ============================================================================ | ||
} | ||
// ============================================================================ | ||
// == SSR == | ||
// ============================================================================ | ||
export function extractStyle(cache) { | ||
@@ -369,11 +348,12 @@ // 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>"); | ||
@@ -380,0 +360,0 @@ }); |
@@ -6,3 +6,3 @@ import useCacheToken from './hooks/useCacheToken'; | ||
import type { Linter } from './linters'; | ||
import { logicalPropertiesLinter } from './linters'; | ||
import { legacyNotSelectorLinter, logicalPropertiesLinter } from './linters'; | ||
import { createCache, StyleProvider } from './StyleContext'; | ||
@@ -13,3 +13,3 @@ import type { DerivativeFunc, TokenType } from './theme'; | ||
import legacyLogicalPropertiesTransformer from './transformers/legacyLogicalProperties'; | ||
export { Theme, createTheme, useStyleRegister, useCacheToken, createCache, StyleProvider, Keyframes, extractStyle, legacyLogicalPropertiesTransformer, logicalPropertiesLinter, }; | ||
export { Theme, createTheme, useStyleRegister, useCacheToken, createCache, StyleProvider, Keyframes, extractStyle, legacyLogicalPropertiesTransformer, logicalPropertiesLinter, legacyNotSelectorLinter, }; | ||
export type { TokenType, CSSObject, CSSInterpolation, DerivativeFunc, Transformer, Linter, }; |
import useCacheToken from "./hooks/useCacheToken"; | ||
import useStyleRegister, { extractStyle } from "./hooks/useStyleRegister"; | ||
import Keyframes from "./Keyframes"; | ||
import { logicalPropertiesLinter } from "./linters"; | ||
import { legacyNotSelectorLinter, logicalPropertiesLinter } from "./linters"; | ||
import { createCache, StyleProvider } from "./StyleContext"; | ||
import { createTheme, Theme } from "./theme"; | ||
import legacyLogicalPropertiesTransformer from "./transformers/legacyLogicalProperties"; | ||
export { Theme, createTheme, useStyleRegister, useCacheToken, createCache, StyleProvider, Keyframes, extractStyle, // Transformer | ||
legacyLogicalPropertiesTransformer, // Linters | ||
logicalPropertiesLinter }; | ||
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, [{ | ||
@@ -26,6 +20,4 @@ key: "getName", | ||
}]); | ||
return Keyframe; | ||
}(); | ||
export default Keyframe; |
import { lintWarning } from "./utils"; | ||
var linter = function linter(key, value, info) { | ||
@@ -8,3 +7,2 @@ 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) !== "'")) { | ||
@@ -15,3 +13,2 @@ 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) { | ||
@@ -10,3 +9,2 @@ if (key === 'animation') { | ||
}; | ||
export default linter; |
export { default as contentQuotesLinter } from './contentQuotesLinter'; | ||
export { default as hashedAnimationLinter } from './hashedAnimationLinter'; | ||
export type { Linter } from './interface'; | ||
export { default as legacyNotSelectorLinter } from './legacyNotSelectorLinter'; | ||
export { default as logicalPropertiesLinter } from './logicalPropertiesLinter'; |
export { default as contentQuotesLinter } from "./contentQuotesLinter"; | ||
export { default as hashedAnimationLinter } from "./hashedAnimationLinter"; | ||
export { default as legacyNotSelectorLinter } from "./legacyNotSelectorLinter"; | ||
export { default as logicalPropertiesLinter } from "./logicalPropertiesLinter"; |
import { lintWarning } from "./utils"; | ||
var linter = function linter(key, value, info) { | ||
@@ -25,3 +24,2 @@ switch (key) { | ||
return; | ||
case 'margin': | ||
@@ -36,3 +34,2 @@ case 'padding': | ||
}); | ||
if (valueArr.length === 4 && valueArr[1] !== valueArr[3]) { | ||
@@ -42,5 +39,3 @@ 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': | ||
@@ -51,5 +46,3 @@ case 'textAlign': | ||
} | ||
return; | ||
case 'borderRadius': | ||
@@ -64,24 +57,19 @@ 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) { | ||
@@ -91,9 +79,6 @@ 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; |
@@ -1,2 +0,2 @@ | ||
import { LinterInfo } from './interface'; | ||
import type { LinterInfo } from './interface'; | ||
export declare function lintWarning(message: string, info: LinterInfo): void; |
import devWarning from "rc-util/es/warning"; | ||
export function lintWarning(message, info) { | ||
var path = info.path, | ||
parentSelectors = info.parentSelectors; | ||
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,4 +10,5 @@ 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'; // Mark css-in-js instance in style element | ||
export var ATTR_DEV_CACHE_PATH = 'data-dev-cache-path'; | ||
// Mark css-in-js instance in style element | ||
export var CSS_IN_JS_INSTANCE = '__cssinjs_instance__'; | ||
@@ -20,15 +21,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; // Not force move if no head | ||
style[CSS_IN_JS_INSTANCE] = style[CSS_IN_JS_INSTANCE] || CSS_IN_JS_INSTANCE_ID; | ||
// 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); | ||
@@ -41,3 +42,2 @@ } | ||
} | ||
return new CacheEntity(); | ||
@@ -52,11 +52,8 @@ } | ||
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) { | ||
@@ -63,0 +60,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,2 +6,3 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
var uuid = 0; | ||
/** | ||
@@ -11,21 +12,14 @@ * 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, [{ | ||
@@ -39,6 +33,4 @@ key: "getDerivativeToken", | ||
}]); | ||
return Theme; | ||
}(); | ||
export { Theme as default }; |
@@ -6,2 +6,3 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
// ================================== Cache ================================== | ||
export function sameDerivativeOption(left, right) { | ||
@@ -11,3 +12,2 @@ if (left.length !== right.length) { | ||
} | ||
for (var i = 0; i < left.length; i++) { | ||
@@ -18,16 +18,10 @@ 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(); | ||
@@ -37,3 +31,2 @@ this.keys = []; | ||
} | ||
_createClass(ThemeCache, [{ | ||
@@ -48,3 +41,2 @@ key: "size", | ||
var _cache2, _cache3; | ||
var updateCallTimes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
@@ -59,11 +51,8 @@ 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; | ||
@@ -75,3 +64,2 @@ } | ||
var _this$internalGet; | ||
return (_this$internalGet = this.internalGet(derivativeOption, true)) === null || _this$internalGet === void 0 ? void 0 : _this$internalGet[0]; | ||
@@ -88,3 +76,2 @@ } | ||
var _this = this; | ||
// New cache | ||
@@ -94,20 +81,15 @@ 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; | ||
@@ -121,3 +103,2 @@ derivativeOption.forEach(function (derivative, index) { | ||
var cacheValue = cache.get(derivative); | ||
if (!cacheValue) { | ||
@@ -130,3 +111,2 @@ cache.set(derivative, { | ||
} | ||
cache = cache.get(derivative).map; | ||
@@ -140,6 +120,4 @@ } | ||
var cache = currentCache.get(derivatives[0]); | ||
if (derivatives.length === 1) { | ||
var _cache$value; | ||
if (!cache.map) { | ||
@@ -152,12 +130,8 @@ 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; | ||
@@ -175,14 +149,9 @@ } | ||
} | ||
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+/); | ||
var splitStyle = String(value).split(/\s+/); // Combine styles split in brackets, like `calc(1px + 2px)` | ||
// Combine styles split in brackets, like `calc(1px + 2px)` | ||
var temp = ''; | ||
@@ -18,3 +18,2 @@ var brackets = 0; | ||
brackets -= item.split(')').length - 1; | ||
if (brackets === 0) { | ||
@@ -29,7 +28,5 @@ list.push(temp); | ||
} | ||
return list; | ||
}, []); | ||
} | ||
function noSplit(list) { | ||
@@ -39,3 +36,2 @@ list.notSplit = true; | ||
} | ||
var keyMap = { | ||
@@ -98,3 +94,2 @@ // Inset | ||
}; | ||
function skipCheck(value) { | ||
@@ -106,2 +101,3 @@ return { | ||
} | ||
/** | ||
@@ -116,4 +112,2 @@ * Convert css logical properties to legacy properties. | ||
*/ | ||
var transform = { | ||
@@ -125,6 +119,4 @@ 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) { | ||
@@ -142,3 +134,2 @@ // 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]); | ||
@@ -150,3 +141,2 @@ }); | ||
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]); | ||
@@ -153,0 +143,0 @@ }); |
@@ -10,3 +10,2 @@ import _typeof from "@babel/runtime/helpers/esm/typeof"; | ||
str += key; | ||
if (value && _typeof(value) === 'object') { | ||
@@ -20,6 +19,6 @@ str += flattenToken(value); | ||
} | ||
/** | ||
* Convert derivative token to key string | ||
*/ | ||
export function token2key(token, salt) { | ||
@@ -30,11 +29,7 @@ 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'; | ||
@@ -45,3 +40,2 @@ _ele.style.left = '0'; | ||
document.body.appendChild(_ele); | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -51,3 +45,2 @@ _ele.innerHTML = 'Test'; | ||
} | ||
var support = getComputedStyle(_ele).width === layerWidth; | ||
@@ -58,6 +51,4 @@ (_ele$parentNode = _ele.parentNode) === null || _ele$parentNode === void 0 ? void 0 : _ele$parentNode.removeChild(_ele); | ||
} | ||
return false; | ||
} | ||
var canLayer = undefined; | ||
@@ -70,4 +61,3 @@ export function supportLayer() { | ||
} | ||
return canLayer; | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,9 +8,5 @@ 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] | ||
@@ -23,3 +18,2 @@ var Entity = /*#__PURE__*/function () { | ||
} | ||
(0, _createClass2.default)(Entity, [{ | ||
@@ -36,3 +30,2 @@ key: "get", | ||
var nextValue = valueFn(prevValue); | ||
if (nextValue === null) { | ||
@@ -47,4 +40,3 @@ 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", { | ||
@@ -11,31 +9,20 @@ 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 = {}; | ||
var EMPTY_OVERRIDE = {}; // Generate different prefix to make user selector break in production env. | ||
// 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) { | ||
@@ -47,3 +34,2 @@ if (typeof document !== 'undefined') { | ||
var _style$parentNode; | ||
(_style$parentNode = style.parentNode) === null || _style$parentNode === void 0 ? void 0 : _style$parentNode.removeChild(style); | ||
@@ -53,5 +39,5 @@ } | ||
} | ||
} // Remove will check current keys first | ||
} | ||
// Remove will check current keys first | ||
function cleanTokenStyle(tokenKey) { | ||
@@ -64,3 +50,2 @@ tokenKeys.set(tokenKey, (tokenKeys.get(tokenKey) || 0) - 1); | ||
}); | ||
if (cleanableKeyList.length < tokenKeyList.length) { | ||
@@ -73,2 +58,3 @@ cleanableKeyList.forEach(function (key) { | ||
} | ||
/** | ||
@@ -81,12 +67,11 @@ * 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; // Basic - We do basic cache here | ||
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 | ||
var mergedToken = React.useMemo(function () { | ||
@@ -102,11 +87,13 @@ 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); // Merge with override | ||
var derivativeToken = theme.getDerivativeToken(mergedToken); | ||
var mergedDerivativeToken = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, derivativeToken), override); // Format if needed | ||
// Merge with override | ||
var mergedDerivativeToken = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, derivativeToken), override); | ||
// Format if needed | ||
if (formatToken) { | ||
mergedDerivativeToken = formatToken(mergedDerivativeToken); | ||
} // Optimize for `useStyleRegister` performance | ||
} | ||
// Optimize for `useStyleRegister` performance | ||
var tokenKey = (0, _util.token2key)(mergedDerivativeToken, salt); | ||
@@ -113,0 +100,0 @@ mergedDerivativeToken._tokenKey = tokenKey; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,35 +9,26 @@ 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)(); // Create cache | ||
var HMRUpdate = (0, _useHMR.default)(); | ||
// 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]; // HMR should always ignore cache since developer may change it | ||
_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 | ||
var tmpCache = cache; | ||
if (process.env.NODE_ENV !== 'production' && cache && HMRUpdate) { | ||
@@ -49,12 +38,10 @@ 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 */ | ||
); // Remove if no need anymore | ||
/* eslint-enable */); | ||
// Remove if no need anymore | ||
React.useEffect(function () { | ||
@@ -64,9 +51,7 @@ 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) { | ||
@@ -76,3 +61,2 @@ onCacheRemove === null || onCacheRemove === void 0 ? void 0 : onCacheRemove(cache, false); | ||
} | ||
return [times - 1, cache]; | ||
@@ -79,0 +63,0 @@ }); |
@@ -7,25 +7,16 @@ "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 () { | ||
@@ -32,0 +23,0 @@ webpackHMR = true; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof3 = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -15,43 +13,24 @@ 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 | ||
// @ts-ignore | ||
var isClientSide = (0, _canUseDom.default)(); | ||
var SKIP_CHECK = '_skip_check_'; | ||
// ============================================================================ | ||
@@ -65,8 +44,7 @@ // == Parser == | ||
} | ||
function isCompoundCSSProperty(value) { | ||
return (0, _typeof2.default)(value) === 'object' && value && SKIP_CHECK in value; | ||
} // 注入 hash 值 | ||
} | ||
// 注入 hash 值 | ||
function injectSelectorHash(key, hashId, hashPriority) { | ||
@@ -76,11 +54,11 @@ if (!hashId) { | ||
} | ||
var hashClassName = ".".concat(hashId); | ||
var hashSelector = hashPriority === 'low' ? ":where(".concat(hashClassName, ")") : hashClassName; // 注入 hashId | ||
var hashSelector = hashPriority === 'low' ? ":where(".concat(hashClassName, ")") : hashClassName; | ||
// 注入 hashId | ||
var keys = key.split(',').map(function (k) { | ||
var _firstPath$match; | ||
var fullPath = k.trim().split(/\s+/); | ||
var fullPath = k.trim().split(/\s+/); // 如果 Selector 第一个是 HTML Element,那我们就插到它的后面。反之,就插到最前面。 | ||
// 如果 Selector 第一个是 HTML Element,那我们就插到它的后面。反之,就插到最前面。 | ||
var firstPath = fullPath[0] || ''; | ||
@@ -93,54 +71,46 @@ 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; // Parse CSSObject to style content | ||
} : undefined; | ||
// 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) { | ||
@@ -157,3 +127,2 @@ var fullList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
} | ||
var flattenStyleList = flattenList(Array.isArray(interpolation) ? interpolation : [interpolation]); | ||
@@ -163,3 +132,2 @@ flattenStyleList.forEach(function (originStyle) { | ||
var style = typeof originStyle === 'string' && !root ? {} : originStyle; | ||
if (typeof style === 'string') { | ||
@@ -173,16 +141,17 @@ 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); // Normal CSSObject | ||
}, style); | ||
// 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 mergedKey = key.trim(); | ||
// Whether treat child as root. In most case it is false. | ||
var nextRoot = false; | ||
var nextRoot = false; // 拆分多个选择器 | ||
// 拆分多个选择器 | ||
if ((root || injectHash) && hashId) { | ||
@@ -205,12 +174,10 @@ 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); | ||
@@ -220,5 +187,3 @@ 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]))) { | ||
@@ -232,16 +197,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) { | ||
@@ -251,3 +216,2 @@ parseKeyframes(value); | ||
} | ||
styleStr += "".concat(styleName, ":").concat(formatValue, ";"); | ||
@@ -258,3 +222,2 @@ } | ||
}); | ||
if (!root) { | ||
@@ -265,4 +228,5 @@ styleStr = "{".concat(styleStr, "}"); | ||
var layerName = layerCells[layerCells.length - 1].trim(); | ||
styleStr = "@layer ".concat(layerName, " {").concat(styleStr, "}"); // Order of layer if needed | ||
styleStr = "@layer ".concat(layerName, " {").concat(styleStr, "}"); | ||
// Order of layer if needed | ||
if (layerCells.length > 1) { | ||
@@ -273,115 +237,106 @@ // zombieJ: stylis do not support layer order, so we need to handle it manually. | ||
} | ||
return [styleStr, effectStyle]; | ||
}; | ||
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)); // Check if need insert style | ||
var fullPath = [tokenKey].concat((0, _toConsumableArray2.default)(path)); | ||
// 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; | ||
var styleStr = normalizeStyle(parsedStyle); | ||
var styleId = uniqueHash(fullPath, styleStr); | ||
// Used for `useCacheToken` to remove on batch when token removed | ||
style.setAttribute(_StyleContext.ATTR_TOKEN, tokenKey); | ||
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 | ||
// 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('|')); | ||
} | ||
style.setAttribute(_StyleContext.ATTR_TOKEN, tokenKey); // Dev usage to find which cache path made this easily | ||
// Inject client side effect style | ||
Object.keys(effectStyle).forEach(function (effectKey) { | ||
if (!globalEffectStyleKeys.has(effectKey)) { | ||
globalEffectStyleKeys.add(effectKey); | ||
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 | ||
}); | ||
} | ||
}); | ||
} | ||
return [styleStr, tokenKey, styleId]; | ||
}, // Remove cache if no need | ||
function (_ref2, fromHMR) { | ||
var _ref3 = (0, _slicedToArray2.default)(_ref2, 3), | ||
// 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) { | ||
@@ -391,3 +346,2 @@ 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), { | ||
@@ -399,10 +353,9 @@ dangerouslySetInnerHTML: { | ||
} | ||
return /*#__PURE__*/React.createElement(React.Fragment, null, styleNode, node); | ||
}; | ||
} // ============================================================================ | ||
} | ||
// ============================================================================ | ||
// == SSR == | ||
// ============================================================================ | ||
function extractStyle(cache) { | ||
@@ -412,11 +365,12 @@ // 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>"); | ||
@@ -423,0 +377,0 @@ }); |
@@ -6,3 +6,3 @@ import useCacheToken from './hooks/useCacheToken'; | ||
import type { Linter } from './linters'; | ||
import { logicalPropertiesLinter } from './linters'; | ||
import { legacyNotSelectorLinter, logicalPropertiesLinter } from './linters'; | ||
import { createCache, StyleProvider } from './StyleContext'; | ||
@@ -13,3 +13,3 @@ import type { DerivativeFunc, TokenType } from './theme'; | ||
import legacyLogicalPropertiesTransformer from './transformers/legacyLogicalProperties'; | ||
export { Theme, createTheme, useStyleRegister, useCacheToken, createCache, StyleProvider, Keyframes, extractStyle, legacyLogicalPropertiesTransformer, logicalPropertiesLinter, }; | ||
export { Theme, createTheme, useStyleRegister, useCacheToken, createCache, StyleProvider, Keyframes, extractStyle, legacyLogicalPropertiesTransformer, logicalPropertiesLinter, legacyNotSelectorLinter, }; | ||
export type { TokenType, CSSObject, CSSInterpolation, DerivativeFunc, Transformer, Linter, }; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -52,2 +50,8 @@ value: true | ||
}); | ||
Object.defineProperty(exports, "legacyNotSelectorLinter", { | ||
enumerable: true, | ||
get: function get() { | ||
return _linters.legacyNotSelectorLinter; | ||
} | ||
}); | ||
Object.defineProperty(exports, "logicalPropertiesLinter", { | ||
@@ -71,19 +75,10 @@ enumerable: 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", { | ||
@@ -9,9 +8,5 @@ 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 () { | ||
@@ -26,3 +21,2 @@ function Keyframe(name, style) { | ||
} | ||
(0, _createClass2.default)(Keyframe, [{ | ||
@@ -37,4 +31,3 @@ key: "getName", | ||
}(); | ||
var _default = Keyframe; | ||
exports.default = _default; |
@@ -7,5 +7,3 @@ "use strict"; | ||
exports.default = void 0; | ||
var _utils = require("./utils"); | ||
var linter = function linter(key, value, info) { | ||
@@ -16,3 +14,2 @@ 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) !== "'")) { | ||
@@ -23,4 +20,3 @@ (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,5 +7,3 @@ "use strict"; | ||
exports.default = void 0; | ||
var _utils = require("./utils"); | ||
var linter = function linter(key, value, info) { | ||
@@ -18,4 +16,3 @@ if (key === 'animation') { | ||
}; | ||
var _default = linter; | ||
exports.default = _default; |
export { default as contentQuotesLinter } from './contentQuotesLinter'; | ||
export { default as hashedAnimationLinter } from './hashedAnimationLinter'; | ||
export type { Linter } from './interface'; | ||
export { default as legacyNotSelectorLinter } from './legacyNotSelectorLinter'; | ||
export { default as logicalPropertiesLinter } from './logicalPropertiesLinter'; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -20,2 +19,8 @@ value: true | ||
}); | ||
Object.defineProperty(exports, "legacyNotSelectorLinter", { | ||
enumerable: true, | ||
get: function get() { | ||
return _legacyNotSelectorLinter.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "logicalPropertiesLinter", { | ||
@@ -27,7 +32,5 @@ enumerable: true, | ||
}); | ||
var _contentQuotesLinter = _interopRequireDefault(require("./contentQuotesLinter")); | ||
var _hashedAnimationLinter = _interopRequireDefault(require("./hashedAnimationLinter")); | ||
var _legacyNotSelectorLinter = _interopRequireDefault(require("./legacyNotSelectorLinter")); | ||
var _logicalPropertiesLinter = _interopRequireDefault(require("./logicalPropertiesLinter")); |
@@ -7,5 +7,3 @@ "use strict"; | ||
exports.default = void 0; | ||
var _utils = require("./utils"); | ||
var linter = function linter(key, value, info) { | ||
@@ -33,3 +31,2 @@ switch (key) { | ||
return; | ||
case 'margin': | ||
@@ -44,3 +41,2 @@ case 'padding': | ||
}); | ||
if (valueArr.length === 4 && valueArr[1] !== valueArr[3]) { | ||
@@ -50,5 +46,3 @@ (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': | ||
@@ -59,5 +53,3 @@ case 'textAlign': | ||
} | ||
return; | ||
case 'borderRadius': | ||
@@ -72,24 +64,19 @@ 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) { | ||
@@ -99,10 +86,7 @@ (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; |
@@ -1,2 +0,2 @@ | ||
import { LinterInfo } from './interface'; | ||
import type { LinterInfo } from './interface'; | ||
export declare function lintWarning(message: string, info: LinterInfo): void; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,9 +8,7 @@ value: true | ||
exports.lintWarning = lintWarning; | ||
var _warning = _interopRequireDefault(require("rc-util/lib/warning")); | ||
function lintWarning(message, info) { | ||
var path = info.path, | ||
parentSelectors = info.parentSelectors; | ||
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", { | ||
@@ -13,21 +11,11 @@ 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'; | ||
@@ -37,4 +25,5 @@ exports.ATTR_TOKEN = ATTR_TOKEN; | ||
exports.ATTR_MARK = ATTR_MARK; | ||
var ATTR_DEV_CACHE_PATH = 'data-dev-cache-path'; // Mark css-in-js instance in style element | ||
var ATTR_DEV_CACHE_PATH = 'data-dev-cache-path'; | ||
// Mark css-in-js instance in style element | ||
exports.ATTR_DEV_CACHE_PATH = ATTR_DEV_CACHE_PATH; | ||
@@ -45,3 +34,2 @@ var CSS_IN_JS_INSTANCE = '__cssinjs_instance__'; | ||
exports.CSS_IN_JS_INSTANCE_ID = CSS_IN_JS_INSTANCE_ID; | ||
function createCache() { | ||
@@ -52,15 +40,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; // Not force move if no head | ||
style[CSS_IN_JS_INSTANCE] = style[CSS_IN_JS_INSTANCE] || CSS_IN_JS_INSTANCE_ID; | ||
// 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); | ||
@@ -73,6 +61,4 @@ } | ||
} | ||
return new _Cache.default(); | ||
} | ||
var StyleContext = /*#__PURE__*/React.createContext({ | ||
@@ -83,6 +69,5 @@ 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); | ||
@@ -93,3 +78,2 @@ var context = (0, _useMemo.default)(function () { | ||
var value = restProps[key]; | ||
if (restProps[key] !== undefined) { | ||
@@ -110,5 +94,4 @@ 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", { | ||
@@ -9,21 +8,18 @@ value: true | ||
exports.default = createTheme; | ||
var _ThemeCache = _interopRequireDefault(require("./ThemeCache")); | ||
var _Theme = _interopRequireDefault(require("./Theme")); | ||
var cacheThemes = new _ThemeCache.default(); | ||
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", { | ||
@@ -26,7 +25,4 @@ 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", { | ||
@@ -9,12 +8,8 @@ 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; | ||
var uuid = 0; | ||
/** | ||
@@ -24,3 +19,2 @@ * Theme with algorithms to derive tokens from design tokens. | ||
*/ | ||
var Theme = /*#__PURE__*/function () { | ||
@@ -33,10 +27,7 @@ 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, [{ | ||
@@ -52,3 +43,2 @@ key: "getDerivativeToken", | ||
}(); | ||
exports.default = Theme; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -10,12 +9,8 @@ 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 ================================== | ||
// ================================== Cache ================================== | ||
function sameDerivativeOption(left, right) { | ||
@@ -25,3 +20,2 @@ if (left.length !== right.length) { | ||
} | ||
for (var i = 0; i < left.length; i++) { | ||
@@ -32,6 +26,4 @@ if (left[i] !== right[i]) { | ||
} | ||
return true; | ||
} | ||
var ThemeCache = /*#__PURE__*/function () { | ||
@@ -47,3 +39,2 @@ function ThemeCache() { | ||
} | ||
(0, _createClass2.default)(ThemeCache, [{ | ||
@@ -58,3 +49,2 @@ key: "size", | ||
var _cache2, _cache3; | ||
var updateCallTimes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
@@ -69,11 +59,8 @@ 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; | ||
@@ -85,3 +72,2 @@ } | ||
var _this$internalGet; | ||
return (_this$internalGet = this.internalGet(derivativeOption, true)) === null || _this$internalGet === void 0 ? void 0 : _this$internalGet[0]; | ||
@@ -98,3 +84,2 @@ } | ||
var _this = this; | ||
// New cache | ||
@@ -104,20 +89,15 @@ 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; | ||
@@ -131,3 +111,2 @@ derivativeOption.forEach(function (derivative, index) { | ||
var cacheValue = cache.get(derivative); | ||
if (!cacheValue) { | ||
@@ -140,3 +119,2 @@ cache.set(derivative, { | ||
} | ||
cache = cache.get(derivative).map; | ||
@@ -150,6 +128,4 @@ } | ||
var cache = currentCache.get(derivatives[0]); | ||
if (derivatives.length === 1) { | ||
var _cache$value; | ||
if (!cache.map) { | ||
@@ -162,12 +138,8 @@ 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; | ||
@@ -185,3 +157,2 @@ } | ||
} | ||
return undefined; | ||
@@ -192,5 +163,4 @@ } | ||
}(); | ||
exports.default = ThemeCache; | ||
(0, _defineProperty2.default)(ThemeCache, "MAX_CACHE_SIZE", 20); | ||
(0, _defineProperty2.default)(ThemeCache, "MAX_CACHE_OFFSET", 5); |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.default = void 0; | ||
function splitValues(value) { | ||
@@ -13,5 +12,5 @@ if (typeof value === 'number') { | ||
} | ||
var splitStyle = String(value).split(/\s+/); | ||
var splitStyle = String(value).split(/\s+/); // Combine styles split in brackets, like `calc(1px + 2px)` | ||
// Combine styles split in brackets, like `calc(1px + 2px)` | ||
var temp = ''; | ||
@@ -26,3 +25,2 @@ var brackets = 0; | ||
brackets -= item.split(')').length - 1; | ||
if (brackets === 0) { | ||
@@ -37,7 +35,5 @@ list.push(temp); | ||
} | ||
return list; | ||
}, []); | ||
} | ||
function noSplit(list) { | ||
@@ -47,3 +43,2 @@ list.notSplit = true; | ||
} | ||
var keyMap = { | ||
@@ -106,3 +101,2 @@ // Inset | ||
}; | ||
function skipCheck(value) { | ||
@@ -114,2 +108,3 @@ return { | ||
} | ||
/** | ||
@@ -124,4 +119,2 @@ * Convert css logical properties to legacy properties. | ||
*/ | ||
var transform = { | ||
@@ -133,6 +126,4 @@ 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) { | ||
@@ -150,3 +141,2 @@ // 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]); | ||
@@ -158,3 +148,2 @@ }); | ||
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]); | ||
@@ -161,0 +150,0 @@ }); |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,11 +10,6 @@ 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) { | ||
@@ -26,3 +20,2 @@ var str = ''; | ||
str += key; | ||
if (value && (0, _typeof2.default)(value) === 'object') { | ||
@@ -36,22 +29,16 @@ 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'; | ||
@@ -62,3 +49,2 @@ _ele.style.left = '0'; | ||
document.body.appendChild(_ele); | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -68,3 +54,2 @@ _ele.innerHTML = 'Test'; | ||
} | ||
var support = getComputedStyle(_ele).width === layerWidth; | ||
@@ -75,8 +60,5 @@ (_ele$parentNode = _ele.parentNode) === null || _ele$parentNode === void 0 ? void 0 : _ele$parentNode.removeChild(_ele); | ||
} | ||
return false; | ||
} | ||
var canLayer = undefined; | ||
function supportLayer() { | ||
@@ -88,4 +70,3 @@ if (canLayer === undefined) { | ||
} | ||
return canLayer; | ||
} |
{ | ||
"name": "@ant-design/cssinjs", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Component level cssinjs resolution for antd", | ||
@@ -15,4 +15,3 @@ "keywords": [ | ||
"es", | ||
"lib", | ||
"dist" | ||
"lib" | ||
], | ||
@@ -33,3 +32,3 @@ "homepage": "https://github.com/ant-design/cssinjs", | ||
"compile": "father build", | ||
"gh-pages": "npm run docs:build && father doc deploy", | ||
"gh-pages": "npm run docs:build && npm run docs:deploy", | ||
"prepublishOnly": "npm run compile && np --yolo --no-publish", | ||
@@ -36,0 +35,0 @@ "postpublish": "npm run gh-pages", |
135501
95
3028