@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.
Files changed (212) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -141
  3. package/dist/Cache.d.ts +22 -0
  4. package/dist/Cache.js +45 -0
  5. package/dist/Keyframes.d.ts +12 -0
  6. package/dist/Keyframes.js +17 -0
  7. package/dist/StyleContext.d.ts +119 -0
  8. package/dist/StyleContext.js +67 -0
  9. package/dist/cssinjs-utils/_util/hooks/useUniqueMemo.js +62 -0
  10. package/dist/cssinjs-utils/hooks/useCSP.d.ts +8 -0
  11. package/dist/cssinjs-utils/hooks/useCSP.js +8 -0
  12. package/dist/cssinjs-utils/hooks/usePrefix.d.ts +9 -0
  13. package/dist/cssinjs-utils/hooks/useToken.d.ts +25 -0
  14. package/dist/cssinjs-utils/index.d.ts +4 -0
  15. package/dist/cssinjs-utils/index.js +4 -0
  16. package/dist/cssinjs-utils/interface/components.d.ts +12 -0
  17. package/dist/cssinjs-utils/util/genStyleUtils.d.ts +127 -0
  18. package/dist/cssinjs-utils/util/genStyleUtils.js +188 -0
  19. package/dist/cssinjs-utils/util/getCompVarPrefix.js +8 -0
  20. package/dist/cssinjs-utils/util/getComponentToken.js +22 -0
  21. package/dist/cssinjs-utils/util/getDefaultComponentToken.js +11 -0
  22. package/dist/cssinjs-utils/util/maxmin.js +17 -0
  23. package/dist/cssinjs-utils/util/statistic.d.ts +15 -0
  24. package/dist/cssinjs-utils/util/statistic.js +52 -0
  25. package/dist/extractStyle.d.ts +18 -0
  26. package/dist/extractStyle.js +54 -0
  27. package/dist/hooks/useCSSVarRegister.d.ts +19 -0
  28. package/dist/hooks/useCSSVarRegister.js +86 -0
  29. package/dist/hooks/useCacheToken.d.ts +60 -0
  30. package/dist/hooks/useCacheToken.js +133 -0
  31. package/dist/hooks/useGlobalCache.d.ts +9 -0
  32. package/dist/hooks/useGlobalCache.js +68 -0
  33. package/dist/hooks/useStyleRegister.d.ts +47 -0
  34. package/dist/hooks/useStyleRegister.js +237 -0
  35. package/dist/index.d.ts +35 -0
  36. package/dist/index.js +30 -0
  37. package/dist/linters/NaNLinter.d.ts +6 -0
  38. package/dist/linters/NaNLinter.js +10 -0
  39. package/dist/linters/contentQuotesLinter.js +18 -0
  40. package/dist/linters/hashedAnimationLinter.js +12 -0
  41. package/dist/linters/index.d.ts +5 -0
  42. package/dist/linters/index.js +8 -0
  43. package/dist/linters/interface.d.ts +11 -0
  44. package/dist/linters/legacyNotSelectorLinter.d.ts +6 -0
  45. package/dist/linters/legacyNotSelectorLinter.js +20 -0
  46. package/dist/linters/logicalPropertiesLinter.d.ts +6 -0
  47. package/dist/linters/logicalPropertiesLinter.js +57 -0
  48. package/dist/linters/parentSelectorLinter.d.ts +7 -0
  49. package/dist/linters/parentSelectorLinter.js +12 -0
  50. package/dist/linters/utils.js +10 -0
  51. package/dist/ssr/styleCollector.d.ts +8 -0
  52. package/dist/ssr/styleCollector.js +11 -0
  53. package/dist/theme/Theme.d.ts +16 -0
  54. package/dist/theme/Theme.js +24 -0
  55. package/dist/theme/ThemeCache.js +79 -0
  56. package/dist/theme/calc/CSSCalculator.d.ts +19 -0
  57. package/dist/theme/calc/CSSCalculator.js +63 -0
  58. package/dist/theme/calc/NumCalculator.d.ts +14 -0
  59. package/dist/theme/calc/NumCalculator.js +37 -0
  60. package/dist/theme/calc/calculator.d.ts +32 -0
  61. package/dist/theme/calc/calculator.js +6 -0
  62. package/dist/theme/calc/index.d.ts +8 -0
  63. package/dist/theme/calc/index.js +12 -0
  64. package/dist/theme/createTheme.d.ts +11 -0
  65. package/dist/theme/createTheme.js +16 -0
  66. package/dist/theme/index.js +6 -0
  67. package/dist/theme/interface.d.ts +5 -0
  68. package/dist/transformers/autoPrefix.d.ts +6 -0
  69. package/dist/transformers/autoPrefix.js +7 -0
  70. package/dist/transformers/interface.d.ts +9 -0
  71. package/{es → dist}/transformers/legacyLogicalProperties.d.ts +6 -2
  72. package/dist/transformers/legacyLogicalProperties.js +123 -0
  73. package/dist/transformers/px2rem.d.ts +23 -0
  74. package/dist/transformers/px2rem.js +37 -0
  75. package/dist/util/cacheMapUtil.js +60 -0
  76. package/dist/util/css-variables.d.ts +7 -0
  77. package/dist/util/css-variables.js +35 -0
  78. package/dist/util/index.d.ts +8 -0
  79. package/dist/util/index.js +108 -0
  80. package/package.json +33 -64
  81. package/dist/cssinjs.umd.js +0 -3
  82. package/es/Cache.d.ts +0 -20
  83. package/es/Cache.js +0 -33
  84. package/es/Keyframes.d.ts +0 -9
  85. package/es/Keyframes.js +0 -14
  86. package/es/StyleContext.d.ts +0 -40
  87. package/es/StyleContext.js +0 -100
  88. package/es/extractStyle.d.ts +0 -12
  89. package/es/extractStyle.js +0 -43
  90. package/es/hooks/useCSSVarRegister.d.ts +0 -21
  91. package/es/hooks/useCSSVarRegister.js +0 -59
  92. package/es/hooks/useCacheToken.d.ts +0 -69
  93. package/es/hooks/useCacheToken.js +0 -106
  94. package/es/hooks/useEffectCleanupRegister.d.ts +0 -2
  95. package/es/hooks/useEffectCleanupRegister.js +0 -8
  96. package/es/hooks/useGlobalCache.d.ts +0 -7
  97. package/es/hooks/useGlobalCache.js +0 -41
  98. package/es/hooks/useHMR.d.ts +0 -3
  99. package/es/hooks/useHMR.js +0 -20
  100. package/es/hooks/useStyleRegister.d.ts +0 -81
  101. package/es/hooks/useStyleRegister.js +0 -216
  102. package/es/index.d.ts +0 -18
  103. package/es/index.js +0 -44
  104. package/es/interface.d.ts +0 -2
  105. package/es/linters/NaNLinter.d.ts +0 -3
  106. package/es/linters/NaNLinter.js +0 -7
  107. package/es/linters/contentQuotesLinter.d.ts +0 -3
  108. package/es/linters/contentQuotesLinter.js +0 -13
  109. package/es/linters/hashedAnimationLinter.d.ts +0 -3
  110. package/es/linters/hashedAnimationLinter.js +0 -10
  111. package/es/linters/index.d.ts +0 -7
  112. package/es/linters/interface.d.ts +0 -8
  113. package/es/linters/legacyNotSelectorLinter.d.ts +0 -3
  114. package/es/linters/legacyNotSelectorLinter.js +0 -14
  115. package/es/linters/logicalPropertiesLinter.d.ts +0 -3
  116. package/es/linters/logicalPropertiesLinter.js +0 -61
  117. package/es/linters/parentSelectorLinter.d.ts +0 -3
  118. package/es/linters/parentSelectorLinter.js +0 -7
  119. package/es/linters/utils.d.ts +0 -2
  120. package/es/linters/utils.js +0 -11
  121. package/es/theme/Theme.d.ts +0 -11
  122. package/es/theme/Theme.js +0 -21
  123. package/es/theme/ThemeCache.d.ts +0 -20
  124. package/es/theme/ThemeCache.js +0 -74
  125. package/es/theme/calc/CSSCalculator.d.ts +0 -15
  126. package/es/theme/calc/CSSCalculator.js +0 -40
  127. package/es/theme/calc/NumCalculator.d.ts +0 -10
  128. package/es/theme/calc/NumCalculator.js +0 -25
  129. package/es/theme/calc/calculator.d.ts +0 -30
  130. package/es/theme/calc/calculator.js +0 -5
  131. package/es/theme/calc/index.d.ts +0 -5
  132. package/es/theme/calc/index.js +0 -9
  133. package/es/theme/createTheme.d.ts +0 -6
  134. package/es/theme/createTheme.js +0 -10
  135. package/es/theme/index.d.ts +0 -6
  136. package/es/theme/interface.d.ts +0 -2
  137. package/es/transformers/interface.d.ts +0 -4
  138. package/es/transformers/legacyLogicalProperties.js +0 -108
  139. package/es/transformers/px2rem.d.ts +0 -20
  140. package/es/transformers/px2rem.js +0 -32
  141. package/es/util/cacheMapUtil.d.ts +0 -14
  142. package/es/util/cacheMapUtil.js +0 -48
  143. package/es/util/css-variables.d.ts +0 -20
  144. package/es/util/css-variables.js +0 -22
  145. package/es/util/index.d.ts +0 -15
  146. package/es/util/index.js +0 -85
  147. package/lib/Cache.d.ts +0 -20
  148. package/lib/Cache.js +0 -1
  149. package/lib/Keyframes.d.ts +0 -9
  150. package/lib/Keyframes.js +0 -1
  151. package/lib/StyleContext.d.ts +0 -40
  152. package/lib/StyleContext.js +0 -1
  153. package/lib/extractStyle.d.ts +0 -12
  154. package/lib/extractStyle.js +0 -1
  155. package/lib/hooks/useCSSVarRegister.d.ts +0 -21
  156. package/lib/hooks/useCSSVarRegister.js +0 -1
  157. package/lib/hooks/useCacheToken.d.ts +0 -69
  158. package/lib/hooks/useCacheToken.js +0 -1
  159. package/lib/hooks/useEffectCleanupRegister.d.ts +0 -2
  160. package/lib/hooks/useEffectCleanupRegister.js +0 -1
  161. package/lib/hooks/useGlobalCache.d.ts +0 -7
  162. package/lib/hooks/useGlobalCache.js +0 -1
  163. package/lib/hooks/useHMR.d.ts +0 -3
  164. package/lib/hooks/useHMR.js +0 -1
  165. package/lib/hooks/useStyleRegister.d.ts +0 -81
  166. package/lib/hooks/useStyleRegister.js +0 -3
  167. package/lib/index.d.ts +0 -18
  168. package/lib/index.js +0 -1
  169. package/lib/interface.d.ts +0 -2
  170. package/lib/linters/NaNLinter.d.ts +0 -3
  171. package/lib/linters/NaNLinter.js +0 -1
  172. package/lib/linters/contentQuotesLinter.d.ts +0 -3
  173. package/lib/linters/contentQuotesLinter.js +0 -1
  174. package/lib/linters/hashedAnimationLinter.d.ts +0 -3
  175. package/lib/linters/hashedAnimationLinter.js +0 -1
  176. package/lib/linters/index.d.ts +0 -7
  177. package/lib/linters/interface.d.ts +0 -8
  178. package/lib/linters/legacyNotSelectorLinter.d.ts +0 -3
  179. package/lib/linters/legacyNotSelectorLinter.js +0 -1
  180. package/lib/linters/logicalPropertiesLinter.d.ts +0 -3
  181. package/lib/linters/logicalPropertiesLinter.js +0 -1
  182. package/lib/linters/parentSelectorLinter.d.ts +0 -3
  183. package/lib/linters/parentSelectorLinter.js +0 -1
  184. package/lib/linters/utils.d.ts +0 -2
  185. package/lib/linters/utils.js +0 -1
  186. package/lib/theme/Theme.d.ts +0 -11
  187. package/lib/theme/Theme.js +0 -1
  188. package/lib/theme/ThemeCache.d.ts +0 -20
  189. package/lib/theme/ThemeCache.js +0 -1
  190. package/lib/theme/calc/CSSCalculator.d.ts +0 -15
  191. package/lib/theme/calc/CSSCalculator.js +0 -1
  192. package/lib/theme/calc/NumCalculator.d.ts +0 -10
  193. package/lib/theme/calc/NumCalculator.js +0 -1
  194. package/lib/theme/calc/calculator.d.ts +0 -30
  195. package/lib/theme/calc/calculator.js +0 -1
  196. package/lib/theme/calc/index.d.ts +0 -5
  197. package/lib/theme/calc/index.js +0 -1
  198. package/lib/theme/createTheme.d.ts +0 -6
  199. package/lib/theme/createTheme.js +0 -1
  200. package/lib/theme/index.d.ts +0 -6
  201. package/lib/theme/interface.d.ts +0 -2
  202. package/lib/transformers/interface.d.ts +0 -4
  203. package/lib/transformers/legacyLogicalProperties.d.ts +0 -12
  204. package/lib/transformers/legacyLogicalProperties.js +0 -1
  205. package/lib/transformers/px2rem.d.ts +0 -20
  206. package/lib/transformers/px2rem.js +0 -1
  207. package/lib/util/cacheMapUtil.d.ts +0 -14
  208. package/lib/util/cacheMapUtil.js +0 -1
  209. package/lib/util/css-variables.d.ts +0 -20
  210. package/lib/util/css-variables.js +0 -1
  211. package/lib/util/index.d.ts +0 -15
  212. 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,11 @@
1
+ //#region src/linters/interface.d.ts
2
+ interface LinterInfo {
3
+ path?: string;
4
+ hashId?: string;
5
+ parentSelectors: string[];
6
+ }
7
+ interface Linter {
8
+ (key: string, value: string | number, info: LinterInfo): void;
9
+ }
10
+ //#endregion
11
+ export { Linter };
@@ -0,0 +1,6 @@
1
+ import { Linter } from "./interface.js";
2
+
3
+ //#region src/linters/legacyNotSelectorLinter.d.ts
4
+ declare const linter: Linter;
5
+ //#endregion
6
+ export { linter };
@@ -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,6 @@
1
+ import { Linter } from "./interface.js";
2
+
3
+ //#region src/linters/logicalPropertiesLinter.d.ts
4
+ declare const linter: Linter;
5
+ //#endregion
6
+ export { linter };
@@ -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,7 @@
1
+ import { Linter } from "./interface.js";
2
+ import "../index.js";
3
+
4
+ //#region src/linters/parentSelectorLinter.d.ts
5
+ declare const linter: Linter;
6
+ //#endregion
7
+ export { linter };
@@ -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,6 @@
1
+ //#region src/theme/calc/calculator.ts
2
+ var AbstractCalculator = class {};
3
+ var calculator_default = AbstractCalculator;
4
+
5
+ //#endregion
6
+ export { calculator_default as default };
@@ -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,6 @@
1
+ import calc_default from "./calc/index.js";
2
+ import Theme from "./Theme.js";
3
+ import ThemeCache from "./ThemeCache.js";
4
+ import createTheme from "./createTheme.js";
5
+
6
+ export { };
@@ -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 };
@@ -0,0 +1,6 @@
1
+ import { Transformer } from "./interface.js";
2
+
3
+ //#region src/transformers/autoPrefix.d.ts
4
+ declare const transform: Transformer;
5
+ //#endregion
6
+ export { transform };
@@ -0,0 +1,7 @@
1
+ //#region src/transformers/autoPrefix.ts
2
+ const AUTO_PREFIX = {};
3
+ const transform = AUTO_PREFIX;
4
+ var autoPrefix_default = transform;
5
+
6
+ //#endregion
7
+ export { autoPrefix_default as default };
@@ -0,0 +1,9 @@
1
+ import { CSSObject } from "../hooks/useStyleRegister.js";
2
+ import "../index.js";
3
+
4
+ //#region src/transformers/interface.d.ts
5
+ interface Transformer {
6
+ visit?: (cssObj: CSSObject) => CSSObject;
7
+ }
8
+ //#endregion
9
+ export { Transformer };
@@ -1,4 +1,7 @@
1
- import { Transformer } from './interface';
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
- export default transform;
15
+ //#endregion
16
+ export { transform };