@antdv-next/cssinjs 0.0.3 → 1.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +0 -141
- package/dist/Cache.d.ts +22 -0
- package/dist/Cache.js +45 -0
- package/dist/Keyframes.d.ts +12 -0
- package/dist/Keyframes.js +17 -0
- package/dist/StyleContext.d.ts +119 -0
- package/dist/StyleContext.js +67 -0
- package/dist/cssinjs-utils/_util/hooks/useUniqueMemo.js +62 -0
- package/dist/cssinjs-utils/hooks/useCSP.d.ts +8 -0
- package/dist/cssinjs-utils/hooks/useCSP.js +8 -0
- package/dist/cssinjs-utils/hooks/usePrefix.d.ts +9 -0
- package/dist/cssinjs-utils/hooks/useToken.d.ts +25 -0
- package/dist/cssinjs-utils/index.d.ts +4 -0
- package/dist/cssinjs-utils/index.js +4 -0
- package/dist/cssinjs-utils/interface/components.d.ts +12 -0
- package/dist/cssinjs-utils/util/genStyleUtils.d.ts +127 -0
- package/dist/cssinjs-utils/util/genStyleUtils.js +188 -0
- package/dist/cssinjs-utils/util/getCompVarPrefix.js +8 -0
- package/dist/cssinjs-utils/util/getComponentToken.js +22 -0
- package/dist/cssinjs-utils/util/getDefaultComponentToken.js +11 -0
- package/dist/cssinjs-utils/util/maxmin.js +17 -0
- package/dist/cssinjs-utils/util/statistic.d.ts +15 -0
- package/dist/cssinjs-utils/util/statistic.js +52 -0
- package/dist/extractStyle.d.ts +18 -0
- package/dist/extractStyle.js +54 -0
- package/dist/hooks/useCSSVarRegister.d.ts +19 -0
- package/dist/hooks/useCSSVarRegister.js +86 -0
- package/dist/hooks/useCacheToken.d.ts +60 -0
- package/dist/hooks/useCacheToken.js +133 -0
- package/dist/hooks/useGlobalCache.d.ts +9 -0
- package/dist/hooks/useGlobalCache.js +68 -0
- package/dist/hooks/useStyleRegister.d.ts +47 -0
- package/dist/hooks/useStyleRegister.js +237 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +30 -0
- package/dist/linters/NaNLinter.d.ts +6 -0
- package/dist/linters/NaNLinter.js +10 -0
- package/dist/linters/contentQuotesLinter.js +18 -0
- package/dist/linters/hashedAnimationLinter.js +12 -0
- package/dist/linters/index.d.ts +5 -0
- package/dist/linters/index.js +8 -0
- package/dist/linters/interface.d.ts +11 -0
- package/dist/linters/legacyNotSelectorLinter.d.ts +6 -0
- package/dist/linters/legacyNotSelectorLinter.js +20 -0
- package/dist/linters/logicalPropertiesLinter.d.ts +6 -0
- package/dist/linters/logicalPropertiesLinter.js +57 -0
- package/dist/linters/parentSelectorLinter.d.ts +7 -0
- package/dist/linters/parentSelectorLinter.js +12 -0
- package/dist/linters/utils.js +10 -0
- package/dist/ssr/styleCollector.d.ts +8 -0
- package/dist/ssr/styleCollector.js +11 -0
- package/dist/theme/Theme.d.ts +16 -0
- package/dist/theme/Theme.js +24 -0
- package/dist/theme/ThemeCache.js +79 -0
- package/dist/theme/calc/CSSCalculator.d.ts +19 -0
- package/dist/theme/calc/CSSCalculator.js +63 -0
- package/dist/theme/calc/NumCalculator.d.ts +14 -0
- package/dist/theme/calc/NumCalculator.js +37 -0
- package/dist/theme/calc/calculator.d.ts +32 -0
- package/dist/theme/calc/calculator.js +6 -0
- package/dist/theme/calc/index.d.ts +8 -0
- package/dist/theme/calc/index.js +12 -0
- package/dist/theme/createTheme.d.ts +11 -0
- package/dist/theme/createTheme.js +16 -0
- package/dist/theme/index.js +6 -0
- package/dist/theme/interface.d.ts +5 -0
- package/dist/transformers/autoPrefix.d.ts +6 -0
- package/dist/transformers/autoPrefix.js +7 -0
- package/dist/transformers/interface.d.ts +9 -0
- package/{es → dist}/transformers/legacyLogicalProperties.d.ts +6 -2
- package/dist/transformers/legacyLogicalProperties.js +123 -0
- package/dist/transformers/px2rem.d.ts +23 -0
- package/dist/transformers/px2rem.js +37 -0
- package/dist/util/cacheMapUtil.js +60 -0
- package/dist/util/css-variables.d.ts +7 -0
- package/dist/util/css-variables.js +35 -0
- package/dist/util/index.d.ts +8 -0
- package/dist/util/index.js +108 -0
- package/package.json +33 -64
- package/dist/cssinjs.umd.js +0 -3
- package/es/Cache.d.ts +0 -20
- package/es/Cache.js +0 -33
- package/es/Keyframes.d.ts +0 -9
- package/es/Keyframes.js +0 -14
- package/es/StyleContext.d.ts +0 -40
- package/es/StyleContext.js +0 -100
- package/es/extractStyle.d.ts +0 -12
- package/es/extractStyle.js +0 -43
- package/es/hooks/useCSSVarRegister.d.ts +0 -21
- package/es/hooks/useCSSVarRegister.js +0 -59
- package/es/hooks/useCacheToken.d.ts +0 -69
- package/es/hooks/useCacheToken.js +0 -106
- package/es/hooks/useEffectCleanupRegister.d.ts +0 -2
- package/es/hooks/useEffectCleanupRegister.js +0 -8
- package/es/hooks/useGlobalCache.d.ts +0 -7
- package/es/hooks/useGlobalCache.js +0 -41
- package/es/hooks/useHMR.d.ts +0 -3
- package/es/hooks/useHMR.js +0 -20
- package/es/hooks/useStyleRegister.d.ts +0 -81
- package/es/hooks/useStyleRegister.js +0 -216
- package/es/index.d.ts +0 -18
- package/es/index.js +0 -44
- package/es/interface.d.ts +0 -2
- package/es/linters/NaNLinter.d.ts +0 -3
- package/es/linters/NaNLinter.js +0 -7
- package/es/linters/contentQuotesLinter.d.ts +0 -3
- package/es/linters/contentQuotesLinter.js +0 -13
- package/es/linters/hashedAnimationLinter.d.ts +0 -3
- package/es/linters/hashedAnimationLinter.js +0 -10
- package/es/linters/index.d.ts +0 -7
- package/es/linters/interface.d.ts +0 -8
- package/es/linters/legacyNotSelectorLinter.d.ts +0 -3
- package/es/linters/legacyNotSelectorLinter.js +0 -14
- package/es/linters/logicalPropertiesLinter.d.ts +0 -3
- package/es/linters/logicalPropertiesLinter.js +0 -61
- package/es/linters/parentSelectorLinter.d.ts +0 -3
- package/es/linters/parentSelectorLinter.js +0 -7
- package/es/linters/utils.d.ts +0 -2
- package/es/linters/utils.js +0 -11
- package/es/theme/Theme.d.ts +0 -11
- package/es/theme/Theme.js +0 -21
- package/es/theme/ThemeCache.d.ts +0 -20
- package/es/theme/ThemeCache.js +0 -74
- package/es/theme/calc/CSSCalculator.d.ts +0 -15
- package/es/theme/calc/CSSCalculator.js +0 -40
- package/es/theme/calc/NumCalculator.d.ts +0 -10
- package/es/theme/calc/NumCalculator.js +0 -25
- package/es/theme/calc/calculator.d.ts +0 -30
- package/es/theme/calc/calculator.js +0 -5
- package/es/theme/calc/index.d.ts +0 -5
- package/es/theme/calc/index.js +0 -9
- package/es/theme/createTheme.d.ts +0 -6
- package/es/theme/createTheme.js +0 -10
- package/es/theme/index.d.ts +0 -6
- package/es/theme/interface.d.ts +0 -2
- package/es/transformers/interface.d.ts +0 -4
- package/es/transformers/legacyLogicalProperties.js +0 -108
- package/es/transformers/px2rem.d.ts +0 -20
- package/es/transformers/px2rem.js +0 -32
- package/es/util/cacheMapUtil.d.ts +0 -14
- package/es/util/cacheMapUtil.js +0 -48
- package/es/util/css-variables.d.ts +0 -20
- package/es/util/css-variables.js +0 -22
- package/es/util/index.d.ts +0 -15
- package/es/util/index.js +0 -85
- package/lib/Cache.d.ts +0 -20
- package/lib/Cache.js +0 -1
- package/lib/Keyframes.d.ts +0 -9
- package/lib/Keyframes.js +0 -1
- package/lib/StyleContext.d.ts +0 -40
- package/lib/StyleContext.js +0 -1
- package/lib/extractStyle.d.ts +0 -12
- package/lib/extractStyle.js +0 -1
- package/lib/hooks/useCSSVarRegister.d.ts +0 -21
- package/lib/hooks/useCSSVarRegister.js +0 -1
- package/lib/hooks/useCacheToken.d.ts +0 -69
- package/lib/hooks/useCacheToken.js +0 -1
- package/lib/hooks/useEffectCleanupRegister.d.ts +0 -2
- package/lib/hooks/useEffectCleanupRegister.js +0 -1
- package/lib/hooks/useGlobalCache.d.ts +0 -7
- package/lib/hooks/useGlobalCache.js +0 -1
- package/lib/hooks/useHMR.d.ts +0 -3
- package/lib/hooks/useHMR.js +0 -1
- package/lib/hooks/useStyleRegister.d.ts +0 -81
- package/lib/hooks/useStyleRegister.js +0 -3
- package/lib/index.d.ts +0 -18
- package/lib/index.js +0 -1
- package/lib/interface.d.ts +0 -2
- package/lib/linters/NaNLinter.d.ts +0 -3
- package/lib/linters/NaNLinter.js +0 -1
- package/lib/linters/contentQuotesLinter.d.ts +0 -3
- package/lib/linters/contentQuotesLinter.js +0 -1
- package/lib/linters/hashedAnimationLinter.d.ts +0 -3
- package/lib/linters/hashedAnimationLinter.js +0 -1
- package/lib/linters/index.d.ts +0 -7
- package/lib/linters/interface.d.ts +0 -8
- package/lib/linters/legacyNotSelectorLinter.d.ts +0 -3
- package/lib/linters/legacyNotSelectorLinter.js +0 -1
- package/lib/linters/logicalPropertiesLinter.d.ts +0 -3
- package/lib/linters/logicalPropertiesLinter.js +0 -1
- package/lib/linters/parentSelectorLinter.d.ts +0 -3
- package/lib/linters/parentSelectorLinter.js +0 -1
- package/lib/linters/utils.d.ts +0 -2
- package/lib/linters/utils.js +0 -1
- package/lib/theme/Theme.d.ts +0 -11
- package/lib/theme/Theme.js +0 -1
- package/lib/theme/ThemeCache.d.ts +0 -20
- package/lib/theme/ThemeCache.js +0 -1
- package/lib/theme/calc/CSSCalculator.d.ts +0 -15
- package/lib/theme/calc/CSSCalculator.js +0 -1
- package/lib/theme/calc/NumCalculator.d.ts +0 -10
- package/lib/theme/calc/NumCalculator.js +0 -1
- package/lib/theme/calc/calculator.d.ts +0 -30
- package/lib/theme/calc/calculator.js +0 -1
- package/lib/theme/calc/index.d.ts +0 -5
- package/lib/theme/calc/index.js +0 -1
- package/lib/theme/createTheme.d.ts +0 -6
- package/lib/theme/createTheme.js +0 -1
- package/lib/theme/index.d.ts +0 -6
- package/lib/theme/interface.d.ts +0 -2
- package/lib/transformers/interface.d.ts +0 -4
- package/lib/transformers/legacyLogicalProperties.d.ts +0 -12
- package/lib/transformers/legacyLogicalProperties.js +0 -1
- package/lib/transformers/px2rem.d.ts +0 -20
- package/lib/transformers/px2rem.js +0 -1
- package/lib/util/cacheMapUtil.d.ts +0 -14
- package/lib/util/cacheMapUtil.js +0 -1
- package/lib/util/css-variables.d.ts +0 -20
- package/lib/util/css-variables.js +0 -1
- package/lib/util/index.d.ts +0 -15
- package/lib/util/index.js +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { lintWarning } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/linters/hashedAnimationLinter.ts
|
|
4
|
+
const linter = (key, value, info) => {
|
|
5
|
+
if (key === "animation") {
|
|
6
|
+
if (info.hashId && value !== "none") lintWarning(`You seem to be using hashed animation '${value}', in which case 'animationName' with Keyframe as value is recommended.`, info);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
var hashedAnimationLinter_default = linter;
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { hashedAnimationLinter_default as default };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Linter } from "./interface.js";
|
|
2
|
+
import { linter } from "./legacyNotSelectorLinter.js";
|
|
3
|
+
import { linter as linter$1 } from "./logicalPropertiesLinter.js";
|
|
4
|
+
import { linter as linter$2 } from "./NaNLinter.js";
|
|
5
|
+
import { linter as linter$3 } from "./parentSelectorLinter.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import contentQuotesLinter_default from "./contentQuotesLinter.js";
|
|
2
|
+
import hashedAnimationLinter_default from "./hashedAnimationLinter.js";
|
|
3
|
+
import legacyNotSelectorLinter_default from "./legacyNotSelectorLinter.js";
|
|
4
|
+
import logicalPropertiesLinter_default from "./logicalPropertiesLinter.js";
|
|
5
|
+
import NaNLinter_default from "./NaNLinter.js";
|
|
6
|
+
import parentSelectorLinter_default from "./parentSelectorLinter.js";
|
|
7
|
+
|
|
8
|
+
export { };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { lintWarning } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/linters/legacyNotSelectorLinter.ts
|
|
4
|
+
function isConcatSelector(selector) {
|
|
5
|
+
return (selector.match(/:not\(([^)]*)\)/)?.[1] || "").split(/(\[[^[]*\])|(?=[.#])/).filter((str) => str).length > 1;
|
|
6
|
+
}
|
|
7
|
+
function parsePath(info) {
|
|
8
|
+
return info.parentSelectors.reduce((prev, cur) => {
|
|
9
|
+
if (!prev) return cur;
|
|
10
|
+
return cur.includes("&") ? cur.replace(/&/g, prev) : `${prev} ${cur}`;
|
|
11
|
+
}, "");
|
|
12
|
+
}
|
|
13
|
+
const linter = (_key, _value, info) => {
|
|
14
|
+
const notList = parsePath(info).match(/:not\([^)]*\)/g) || [];
|
|
15
|
+
if (notList.length > 0 && notList.some(isConcatSelector)) lintWarning(`Concat ':not' selector not support in legacy browsers.`, info);
|
|
16
|
+
};
|
|
17
|
+
var legacyNotSelectorLinter_default = linter;
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { legacyNotSelectorLinter_default as default };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { lintWarning } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/linters/logicalPropertiesLinter.ts
|
|
4
|
+
const linter = (key, value, info) => {
|
|
5
|
+
switch (key) {
|
|
6
|
+
case "marginLeft":
|
|
7
|
+
case "marginRight":
|
|
8
|
+
case "paddingLeft":
|
|
9
|
+
case "paddingRight":
|
|
10
|
+
case "left":
|
|
11
|
+
case "right":
|
|
12
|
+
case "borderLeft":
|
|
13
|
+
case "borderLeftWidth":
|
|
14
|
+
case "borderLeftStyle":
|
|
15
|
+
case "borderLeftColor":
|
|
16
|
+
case "borderRight":
|
|
17
|
+
case "borderRightWidth":
|
|
18
|
+
case "borderRightStyle":
|
|
19
|
+
case "borderRightColor":
|
|
20
|
+
case "borderTopLeftRadius":
|
|
21
|
+
case "borderTopRightRadius":
|
|
22
|
+
case "borderBottomLeftRadius":
|
|
23
|
+
case "borderBottomRightRadius":
|
|
24
|
+
lintWarning(`You seem to be using non-logical property '${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);
|
|
25
|
+
return;
|
|
26
|
+
case "margin":
|
|
27
|
+
case "padding":
|
|
28
|
+
case "borderWidth":
|
|
29
|
+
case "borderStyle":
|
|
30
|
+
if (typeof value === "string") {
|
|
31
|
+
const valueArr = value.split(" ").map((item) => item.trim());
|
|
32
|
+
if (valueArr.length === 4 && valueArr[1] !== valueArr[3]) lintWarning(`You seem to be using '${key}' property with different left ${key} and right ${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);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
case "clear":
|
|
36
|
+
case "textAlign":
|
|
37
|
+
if (value === "left" || value === "right") lintWarning(`You seem to be using non-logical value '${value}' of ${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);
|
|
38
|
+
return;
|
|
39
|
+
case "borderRadius":
|
|
40
|
+
if (typeof value === "string") {
|
|
41
|
+
if (value.split("/").map((item) => item.trim()).reduce((result, group) => {
|
|
42
|
+
if (result) return result;
|
|
43
|
+
const radiusArr = group.split(" ").map((item) => item.trim());
|
|
44
|
+
if (radiusArr.length >= 2 && radiusArr[0] !== radiusArr[1]) return true;
|
|
45
|
+
if (radiusArr.length === 3 && radiusArr[1] !== radiusArr[2]) return true;
|
|
46
|
+
if (radiusArr.length === 4 && radiusArr[2] !== radiusArr[3]) return true;
|
|
47
|
+
return result;
|
|
48
|
+
}, false)) lintWarning(`You seem to be using non-logical value '${value}' of ${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);
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
default:
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var logicalPropertiesLinter_default = linter;
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { logicalPropertiesLinter_default as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { lintWarning } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/linters/parentSelectorLinter.ts
|
|
4
|
+
const linter = (_key, _value, info) => {
|
|
5
|
+
if (info.parentSelectors.some((selector) => {
|
|
6
|
+
return selector.split(",").some((item) => item.split("&").length > 2);
|
|
7
|
+
})) lintWarning("Should not use more than one `&` in a selector.", info);
|
|
8
|
+
};
|
|
9
|
+
var parentSelectorLinter_default = linter;
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { parentSelectorLinter_default as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import devWarning from "@v-c/util/dist/warning";
|
|
2
|
+
|
|
3
|
+
//#region src/linters/utils.ts
|
|
4
|
+
function lintWarning(message, info) {
|
|
5
|
+
const { path, parentSelectors } = info;
|
|
6
|
+
devWarning(false, `[Ant Design CSS-in-JS] ${path ? `Error in ${path}: ` : ""}${message}${parentSelectors.length ? ` Selector: ${parentSelectors.join(" | ")}` : ""}`);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { lintWarning };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/ssr/styleCollector.d.ts
|
|
2
|
+
type StyleCollector = {
|
|
3
|
+
push: (styleText: string) => void;
|
|
4
|
+
} | null;
|
|
5
|
+
declare function setStyleCollector(next: StyleCollector): void;
|
|
6
|
+
declare function collectStyleText(styleText: string): void;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { collectStyleText, setStyleCollector };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/ssr/styleCollector.ts
|
|
2
|
+
let collector = null;
|
|
3
|
+
function setStyleCollector(next) {
|
|
4
|
+
collector = next;
|
|
5
|
+
}
|
|
6
|
+
function collectStyleText(styleText) {
|
|
7
|
+
collector?.push(styleText);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { collectStyleText, setStyleCollector };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DerivativeFunc, TokenType } from "./interface.js";
|
|
2
|
+
|
|
3
|
+
//#region src/theme/Theme.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Theme with algorithms to derive tokens from design tokens.
|
|
7
|
+
* Use `createTheme` first which will help to manage the theme instance cache.
|
|
8
|
+
*/
|
|
9
|
+
declare class Theme<DesignToken extends TokenType, DerivativeToken extends TokenType> {
|
|
10
|
+
private derivatives;
|
|
11
|
+
readonly id: number;
|
|
12
|
+
constructor(derivatives: DerivativeFunc<DesignToken, DerivativeToken> | DerivativeFunc<DesignToken, DerivativeToken>[]);
|
|
13
|
+
getDerivativeToken(token: DesignToken): DerivativeToken;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { Theme };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { warning } from "@v-c/util/dist/warning";
|
|
2
|
+
|
|
3
|
+
//#region src/theme/Theme.ts
|
|
4
|
+
let uuid = 0;
|
|
5
|
+
/**
|
|
6
|
+
* Theme with algorithms to derive tokens from design tokens.
|
|
7
|
+
* Use `createTheme` first which will help to manage the theme instance cache.
|
|
8
|
+
*/
|
|
9
|
+
var Theme = class {
|
|
10
|
+
derivatives;
|
|
11
|
+
id;
|
|
12
|
+
constructor(derivatives) {
|
|
13
|
+
this.derivatives = Array.isArray(derivatives) ? derivatives : [derivatives];
|
|
14
|
+
this.id = uuid;
|
|
15
|
+
if (derivatives.length === 0) warning(derivatives.length > 0, "[Ant Design CSS-in-JS] Theme should have at least one derivative function.");
|
|
16
|
+
uuid += 1;
|
|
17
|
+
}
|
|
18
|
+
getDerivativeToken(token) {
|
|
19
|
+
return this.derivatives.reduce((result, derivative) => derivative(token, result), void 0);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { Theme as default };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//#region src/theme/ThemeCache.ts
|
|
2
|
+
function sameDerivativeOption(left, right) {
|
|
3
|
+
if (left.length !== right.length) return false;
|
|
4
|
+
for (let i = 0; i < left.length; i++) if (left[i] !== right[i]) return false;
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
var ThemeCache = class ThemeCache {
|
|
8
|
+
static MAX_CACHE_SIZE = 20;
|
|
9
|
+
static MAX_CACHE_OFFSET = 5;
|
|
10
|
+
cache;
|
|
11
|
+
keys;
|
|
12
|
+
cacheCallTimes;
|
|
13
|
+
constructor() {
|
|
14
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
15
|
+
this.keys = [];
|
|
16
|
+
this.cacheCallTimes = 0;
|
|
17
|
+
}
|
|
18
|
+
size() {
|
|
19
|
+
return this.keys.length;
|
|
20
|
+
}
|
|
21
|
+
internalGet(derivativeOption, updateCallTimes = false) {
|
|
22
|
+
let cache = { map: this.cache };
|
|
23
|
+
derivativeOption.forEach((derivative) => {
|
|
24
|
+
if (!cache) cache = void 0;
|
|
25
|
+
else cache = cache?.map?.get(derivative);
|
|
26
|
+
});
|
|
27
|
+
if (cache?.value && updateCallTimes) cache.value[1] = this.cacheCallTimes++;
|
|
28
|
+
return cache?.value;
|
|
29
|
+
}
|
|
30
|
+
get(derivativeOption) {
|
|
31
|
+
return this.internalGet(derivativeOption, true)?.[0];
|
|
32
|
+
}
|
|
33
|
+
has(derivativeOption) {
|
|
34
|
+
return !!this.internalGet(derivativeOption);
|
|
35
|
+
}
|
|
36
|
+
set(derivativeOption, value) {
|
|
37
|
+
if (!this.has(derivativeOption)) {
|
|
38
|
+
if (this.size() + 1 > ThemeCache.MAX_CACHE_SIZE + ThemeCache.MAX_CACHE_OFFSET) {
|
|
39
|
+
const [targetKey] = this.keys.reduce((result, key) => {
|
|
40
|
+
const [, callTimes] = result;
|
|
41
|
+
if (this.internalGet(key)[1] < callTimes) return [key, this.internalGet(key)[1]];
|
|
42
|
+
return result;
|
|
43
|
+
}, [this.keys[0], this.cacheCallTimes]);
|
|
44
|
+
this.delete(targetKey);
|
|
45
|
+
}
|
|
46
|
+
this.keys.push(derivativeOption);
|
|
47
|
+
}
|
|
48
|
+
let cache = this.cache;
|
|
49
|
+
derivativeOption.forEach((derivative, index) => {
|
|
50
|
+
if (index === derivativeOption.length - 1) cache.set(derivative, { value: [value, this.cacheCallTimes++] });
|
|
51
|
+
else {
|
|
52
|
+
const cacheValue = cache.get(derivative);
|
|
53
|
+
if (!cacheValue) cache.set(derivative, { map: /* @__PURE__ */ new Map() });
|
|
54
|
+
else if (!cacheValue.map) cacheValue.map = /* @__PURE__ */ new Map();
|
|
55
|
+
cache = cache.get(derivative).map;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
deleteByPath(currentCache, derivatives) {
|
|
60
|
+
const cache = currentCache.get(derivatives[0]);
|
|
61
|
+
if (derivatives.length === 1) {
|
|
62
|
+
if (!cache.map) currentCache.delete(derivatives[0]);
|
|
63
|
+
else currentCache.set(derivatives[0], { map: cache.map });
|
|
64
|
+
return cache.value?.[0];
|
|
65
|
+
}
|
|
66
|
+
const result = this.deleteByPath(cache.map, derivatives.slice(1));
|
|
67
|
+
if ((!cache.map || cache.map.size === 0) && !cache.value) currentCache.delete(derivatives[0]);
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
delete(derivativeOption) {
|
|
71
|
+
if (this.has(derivativeOption)) {
|
|
72
|
+
this.keys = this.keys.filter((item) => !sameDerivativeOption(item, derivativeOption));
|
|
73
|
+
return this.deleteByPath(this.cache, derivativeOption);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { ThemeCache as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AbstractCalculator } from "./calculator.js";
|
|
2
|
+
|
|
3
|
+
//#region src/theme/calc/CSSCalculator.d.ts
|
|
4
|
+
declare class CSSCalculator extends AbstractCalculator {
|
|
5
|
+
result: string;
|
|
6
|
+
unitlessCssVar: Set<string>;
|
|
7
|
+
lowPriority?: boolean;
|
|
8
|
+
constructor(num: number | string | AbstractCalculator, unitlessCssVar: Set<string>);
|
|
9
|
+
add(num: number | string | AbstractCalculator): this;
|
|
10
|
+
sub(num: number | string | AbstractCalculator): this;
|
|
11
|
+
mul(num: number | string | AbstractCalculator): this;
|
|
12
|
+
div(num: number | string | AbstractCalculator): this;
|
|
13
|
+
getResult(force?: boolean): string;
|
|
14
|
+
equal(options?: {
|
|
15
|
+
unit?: boolean;
|
|
16
|
+
}): string;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { CSSCalculator };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import calculator_default from "./calculator.js";
|
|
2
|
+
|
|
3
|
+
//#region src/theme/calc/CSSCalculator.ts
|
|
4
|
+
const CALC_UNIT = "CALC_UNIT";
|
|
5
|
+
const regexp = new RegExp(CALC_UNIT, "g");
|
|
6
|
+
function unit(value) {
|
|
7
|
+
if (typeof value === "number") return `${value}${CALC_UNIT}`;
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
var CSSCalculator = class CSSCalculator extends calculator_default {
|
|
11
|
+
result = "";
|
|
12
|
+
unitlessCssVar;
|
|
13
|
+
lowPriority;
|
|
14
|
+
constructor(num, unitlessCssVar) {
|
|
15
|
+
super();
|
|
16
|
+
const numType = typeof num;
|
|
17
|
+
this.unitlessCssVar = unitlessCssVar;
|
|
18
|
+
if (num instanceof CSSCalculator) this.result = `(${num.result})`;
|
|
19
|
+
else if (numType === "number") this.result = unit(num);
|
|
20
|
+
else if (numType === "string") this.result = num;
|
|
21
|
+
}
|
|
22
|
+
add(num) {
|
|
23
|
+
if (num instanceof CSSCalculator) this.result = `${this.result} + ${num.getResult()}`;
|
|
24
|
+
else if (typeof num === "number" || typeof num === "string") this.result = `${this.result} + ${unit(num)}`;
|
|
25
|
+
this.lowPriority = true;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
sub(num) {
|
|
29
|
+
if (num instanceof CSSCalculator) this.result = `${this.result} - ${num.getResult()}`;
|
|
30
|
+
else if (typeof num === "number" || typeof num === "string") this.result = `${this.result} - ${unit(num)}`;
|
|
31
|
+
this.lowPriority = true;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
mul(num) {
|
|
35
|
+
if (this.lowPriority) this.result = `(${this.result})`;
|
|
36
|
+
if (num instanceof CSSCalculator) this.result = `${this.result} * ${num.getResult(true)}`;
|
|
37
|
+
else if (typeof num === "number" || typeof num === "string") this.result = `${this.result} * ${num}`;
|
|
38
|
+
this.lowPriority = false;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
div(num) {
|
|
42
|
+
if (this.lowPriority) this.result = `(${this.result})`;
|
|
43
|
+
if (num instanceof CSSCalculator) this.result = `${this.result} / ${num.getResult(true)}`;
|
|
44
|
+
else if (typeof num === "number" || typeof num === "string") this.result = `${this.result} / ${num}`;
|
|
45
|
+
this.lowPriority = false;
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
getResult(force) {
|
|
49
|
+
return this.lowPriority || force ? `(${this.result})` : this.result;
|
|
50
|
+
}
|
|
51
|
+
equal(options) {
|
|
52
|
+
const { unit: cssUnit } = options || {};
|
|
53
|
+
let mergedUnit = true;
|
|
54
|
+
if (typeof cssUnit === "boolean") mergedUnit = cssUnit;
|
|
55
|
+
else if (Array.from(this.unitlessCssVar).some((cssVar) => this.result.includes(cssVar))) mergedUnit = false;
|
|
56
|
+
this.result = this.result.replace(regexp, mergedUnit ? "px" : "");
|
|
57
|
+
if (typeof this.lowPriority !== "undefined") return `calc(${this.result})`;
|
|
58
|
+
return this.result;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { CSSCalculator as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AbstractCalculator } from "./calculator.js";
|
|
2
|
+
|
|
3
|
+
//#region src/theme/calc/NumCalculator.d.ts
|
|
4
|
+
declare class NumCalculator extends AbstractCalculator {
|
|
5
|
+
result: number;
|
|
6
|
+
constructor(num: number | string | AbstractCalculator);
|
|
7
|
+
add(num: number | string | AbstractCalculator): this;
|
|
8
|
+
sub(num: number | string | AbstractCalculator): this;
|
|
9
|
+
mul(num: number | string | AbstractCalculator): this;
|
|
10
|
+
div(num: number | string | AbstractCalculator): this;
|
|
11
|
+
equal(): number;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { NumCalculator };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import calculator_default from "./calculator.js";
|
|
2
|
+
|
|
3
|
+
//#region src/theme/calc/NumCalculator.ts
|
|
4
|
+
var NumCalculator = class NumCalculator extends calculator_default {
|
|
5
|
+
result = 0;
|
|
6
|
+
constructor(num) {
|
|
7
|
+
super();
|
|
8
|
+
if (num instanceof NumCalculator) this.result = num.result;
|
|
9
|
+
else if (typeof num === "number") this.result = num;
|
|
10
|
+
}
|
|
11
|
+
add(num) {
|
|
12
|
+
if (num instanceof NumCalculator) this.result += num.result;
|
|
13
|
+
else if (typeof num === "number") this.result += num;
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
sub(num) {
|
|
17
|
+
if (num instanceof NumCalculator) this.result -= num.result;
|
|
18
|
+
else if (typeof num === "number") this.result -= num;
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
mul(num) {
|
|
22
|
+
if (num instanceof NumCalculator) this.result *= num.result;
|
|
23
|
+
else if (typeof num === "number") this.result *= num;
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
div(num) {
|
|
27
|
+
if (num instanceof NumCalculator) this.result /= num.result;
|
|
28
|
+
else if (typeof num === "number") this.result /= num;
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
equal() {
|
|
32
|
+
return this.result;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { NumCalculator as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/theme/calc/calculator.d.ts
|
|
2
|
+
declare abstract class AbstractCalculator {
|
|
3
|
+
/**
|
|
4
|
+
* @descCN 计算两数的和,例如:1 + 2
|
|
5
|
+
* @descEN Calculate the sum of two numbers, e.g. 1 + 2
|
|
6
|
+
*/
|
|
7
|
+
abstract add(num: number | string | AbstractCalculator): this;
|
|
8
|
+
/**
|
|
9
|
+
* @descCN 计算两数的差,例如:1 - 2
|
|
10
|
+
* @descEN Calculate the difference between two numbers, e.g. 1 - 2
|
|
11
|
+
*/
|
|
12
|
+
abstract sub(num: number | string | AbstractCalculator): this;
|
|
13
|
+
/**
|
|
14
|
+
* @descCN 计算两数的积,例如:1 * 2
|
|
15
|
+
* @descEN Calculate the product of two numbers, e.g. 1 * 2
|
|
16
|
+
*/
|
|
17
|
+
abstract mul(num: number | string | AbstractCalculator): this;
|
|
18
|
+
/**
|
|
19
|
+
* @descCN 计算两数的商,例如:1 / 2
|
|
20
|
+
* @descEN Calculate the quotient of two numbers, e.g. 1 / 2
|
|
21
|
+
*/
|
|
22
|
+
abstract div(num: number | string | AbstractCalculator): this;
|
|
23
|
+
/**
|
|
24
|
+
* @descCN 获取计算结果
|
|
25
|
+
* @descEN Get the calculation result
|
|
26
|
+
*/
|
|
27
|
+
abstract equal(options?: {
|
|
28
|
+
unit?: boolean;
|
|
29
|
+
}): string | number;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { AbstractCalculator };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AbstractCalculator } from "./calculator.js";
|
|
2
|
+
import { CSSCalculator } from "./CSSCalculator.js";
|
|
3
|
+
import { NumCalculator } from "./NumCalculator.js";
|
|
4
|
+
|
|
5
|
+
//#region src/theme/calc/index.d.ts
|
|
6
|
+
declare function genCalc(type: 'css' | 'js', unitlessCssVar: Set<string>): (num: number | string | AbstractCalculator) => CSSCalculator | NumCalculator;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { genCalc };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import CSSCalculator from "./CSSCalculator.js";
|
|
2
|
+
import NumCalculator from "./NumCalculator.js";
|
|
3
|
+
|
|
4
|
+
//#region src/theme/calc/index.ts
|
|
5
|
+
function genCalc(type, unitlessCssVar) {
|
|
6
|
+
const Calculator = type === "css" ? CSSCalculator : NumCalculator;
|
|
7
|
+
return (num) => new Calculator(num, unitlessCssVar);
|
|
8
|
+
}
|
|
9
|
+
var calc_default = genCalc;
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { calc_default as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DerivativeFunc, TokenType } from "./interface.js";
|
|
2
|
+
import { Theme } from "./Theme.js";
|
|
3
|
+
|
|
4
|
+
//#region src/theme/createTheme.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Same as new Theme, but will always return same one if `derivative` not changed.
|
|
8
|
+
*/
|
|
9
|
+
declare function createTheme<DesignToken extends TokenType, DerivativeToken extends TokenType>(derivatives: DerivativeFunc<DesignToken, DerivativeToken>[] | DerivativeFunc<DesignToken, DerivativeToken>): Theme<any, any>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { createTheme };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Theme from "./Theme.js";
|
|
2
|
+
import ThemeCache from "./ThemeCache.js";
|
|
3
|
+
|
|
4
|
+
//#region src/theme/createTheme.ts
|
|
5
|
+
const cacheThemes = new ThemeCache();
|
|
6
|
+
/**
|
|
7
|
+
* Same as new Theme, but will always return same one if `derivative` not changed.
|
|
8
|
+
*/
|
|
9
|
+
function createTheme(derivatives) {
|
|
10
|
+
const derivativeArr = Array.isArray(derivatives) ? derivatives : [derivatives];
|
|
11
|
+
if (!cacheThemes.has(derivativeArr)) cacheThemes.set(derivativeArr, new Theme(derivativeArr));
|
|
12
|
+
return cacheThemes.get(derivativeArr);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { createTheme as default };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
//#region src/theme/interface.d.ts
|
|
2
|
+
type TokenType = object;
|
|
3
|
+
type DerivativeFunc<DesignToken extends TokenType, DerivativeToken extends TokenType> = (designToken: DesignToken, derivativeToken?: DerivativeToken) => DerivativeToken;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { DerivativeFunc, TokenType };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { Transformer } from
|
|
1
|
+
import { Transformer } from "./interface.js";
|
|
2
|
+
|
|
3
|
+
//#region src/transformers/legacyLogicalProperties.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Convert css logical properties to legacy properties.
|
|
4
7
|
* Such as: `margin-block-start` to `margin-top`.
|
|
@@ -9,4 +12,5 @@ import { Transformer } from './interface';
|
|
|
9
12
|
* - border
|
|
10
13
|
*/
|
|
11
14
|
declare const transform: Transformer;
|
|
12
|
-
|
|
15
|
+
//#endregion
|
|
16
|
+
export { transform };
|