@antdv-next/cssinjs 0.0.3 → 1.0.0-alpha.1

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 (210) 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 +118 -0
  8. package/dist/StyleContext.js +64 -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 +74 -0
  29. package/dist/hooks/useCacheToken.d.ts +60 -0
  30. package/dist/hooks/useCacheToken.js +120 -0
  31. package/dist/hooks/useGlobalCache.d.ts +9 -0
  32. package/dist/hooks/useGlobalCache.js +70 -0
  33. package/dist/hooks/useStyleRegister.d.ts +47 -0
  34. package/dist/hooks/useStyleRegister.js +237 -0
  35. package/dist/index.d.ts +34 -0
  36. package/dist/index.js +29 -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/theme/Theme.d.ts +16 -0
  52. package/dist/theme/Theme.js +24 -0
  53. package/dist/theme/ThemeCache.js +79 -0
  54. package/dist/theme/calc/CSSCalculator.d.ts +19 -0
  55. package/dist/theme/calc/CSSCalculator.js +63 -0
  56. package/dist/theme/calc/NumCalculator.d.ts +14 -0
  57. package/dist/theme/calc/NumCalculator.js +37 -0
  58. package/dist/theme/calc/calculator.d.ts +32 -0
  59. package/dist/theme/calc/calculator.js +6 -0
  60. package/dist/theme/calc/index.d.ts +8 -0
  61. package/dist/theme/calc/index.js +12 -0
  62. package/dist/theme/createTheme.d.ts +11 -0
  63. package/dist/theme/createTheme.js +16 -0
  64. package/dist/theme/index.js +6 -0
  65. package/dist/theme/interface.d.ts +5 -0
  66. package/dist/transformers/autoPrefix.d.ts +6 -0
  67. package/dist/transformers/autoPrefix.js +7 -0
  68. package/dist/transformers/interface.d.ts +9 -0
  69. package/{es → dist}/transformers/legacyLogicalProperties.d.ts +6 -2
  70. package/dist/transformers/legacyLogicalProperties.js +123 -0
  71. package/dist/transformers/px2rem.d.ts +23 -0
  72. package/dist/transformers/px2rem.js +37 -0
  73. package/dist/util/cacheMapUtil.js +60 -0
  74. package/dist/util/css-variables.d.ts +7 -0
  75. package/dist/util/css-variables.js +35 -0
  76. package/dist/util/index.d.ts +8 -0
  77. package/dist/util/index.js +108 -0
  78. package/package.json +33 -64
  79. package/dist/cssinjs.umd.js +0 -3
  80. package/es/Cache.d.ts +0 -20
  81. package/es/Cache.js +0 -33
  82. package/es/Keyframes.d.ts +0 -9
  83. package/es/Keyframes.js +0 -14
  84. package/es/StyleContext.d.ts +0 -40
  85. package/es/StyleContext.js +0 -100
  86. package/es/extractStyle.d.ts +0 -12
  87. package/es/extractStyle.js +0 -43
  88. package/es/hooks/useCSSVarRegister.d.ts +0 -21
  89. package/es/hooks/useCSSVarRegister.js +0 -59
  90. package/es/hooks/useCacheToken.d.ts +0 -69
  91. package/es/hooks/useCacheToken.js +0 -106
  92. package/es/hooks/useEffectCleanupRegister.d.ts +0 -2
  93. package/es/hooks/useEffectCleanupRegister.js +0 -8
  94. package/es/hooks/useGlobalCache.d.ts +0 -7
  95. package/es/hooks/useGlobalCache.js +0 -41
  96. package/es/hooks/useHMR.d.ts +0 -3
  97. package/es/hooks/useHMR.js +0 -20
  98. package/es/hooks/useStyleRegister.d.ts +0 -81
  99. package/es/hooks/useStyleRegister.js +0 -216
  100. package/es/index.d.ts +0 -18
  101. package/es/index.js +0 -44
  102. package/es/interface.d.ts +0 -2
  103. package/es/linters/NaNLinter.d.ts +0 -3
  104. package/es/linters/NaNLinter.js +0 -7
  105. package/es/linters/contentQuotesLinter.d.ts +0 -3
  106. package/es/linters/contentQuotesLinter.js +0 -13
  107. package/es/linters/hashedAnimationLinter.d.ts +0 -3
  108. package/es/linters/hashedAnimationLinter.js +0 -10
  109. package/es/linters/index.d.ts +0 -7
  110. package/es/linters/interface.d.ts +0 -8
  111. package/es/linters/legacyNotSelectorLinter.d.ts +0 -3
  112. package/es/linters/legacyNotSelectorLinter.js +0 -14
  113. package/es/linters/logicalPropertiesLinter.d.ts +0 -3
  114. package/es/linters/logicalPropertiesLinter.js +0 -61
  115. package/es/linters/parentSelectorLinter.d.ts +0 -3
  116. package/es/linters/parentSelectorLinter.js +0 -7
  117. package/es/linters/utils.d.ts +0 -2
  118. package/es/linters/utils.js +0 -11
  119. package/es/theme/Theme.d.ts +0 -11
  120. package/es/theme/Theme.js +0 -21
  121. package/es/theme/ThemeCache.d.ts +0 -20
  122. package/es/theme/ThemeCache.js +0 -74
  123. package/es/theme/calc/CSSCalculator.d.ts +0 -15
  124. package/es/theme/calc/CSSCalculator.js +0 -40
  125. package/es/theme/calc/NumCalculator.d.ts +0 -10
  126. package/es/theme/calc/NumCalculator.js +0 -25
  127. package/es/theme/calc/calculator.d.ts +0 -30
  128. package/es/theme/calc/calculator.js +0 -5
  129. package/es/theme/calc/index.d.ts +0 -5
  130. package/es/theme/calc/index.js +0 -9
  131. package/es/theme/createTheme.d.ts +0 -6
  132. package/es/theme/createTheme.js +0 -10
  133. package/es/theme/index.d.ts +0 -6
  134. package/es/theme/interface.d.ts +0 -2
  135. package/es/transformers/interface.d.ts +0 -4
  136. package/es/transformers/legacyLogicalProperties.js +0 -108
  137. package/es/transformers/px2rem.d.ts +0 -20
  138. package/es/transformers/px2rem.js +0 -32
  139. package/es/util/cacheMapUtil.d.ts +0 -14
  140. package/es/util/cacheMapUtil.js +0 -48
  141. package/es/util/css-variables.d.ts +0 -20
  142. package/es/util/css-variables.js +0 -22
  143. package/es/util/index.d.ts +0 -15
  144. package/es/util/index.js +0 -85
  145. package/lib/Cache.d.ts +0 -20
  146. package/lib/Cache.js +0 -1
  147. package/lib/Keyframes.d.ts +0 -9
  148. package/lib/Keyframes.js +0 -1
  149. package/lib/StyleContext.d.ts +0 -40
  150. package/lib/StyleContext.js +0 -1
  151. package/lib/extractStyle.d.ts +0 -12
  152. package/lib/extractStyle.js +0 -1
  153. package/lib/hooks/useCSSVarRegister.d.ts +0 -21
  154. package/lib/hooks/useCSSVarRegister.js +0 -1
  155. package/lib/hooks/useCacheToken.d.ts +0 -69
  156. package/lib/hooks/useCacheToken.js +0 -1
  157. package/lib/hooks/useEffectCleanupRegister.d.ts +0 -2
  158. package/lib/hooks/useEffectCleanupRegister.js +0 -1
  159. package/lib/hooks/useGlobalCache.d.ts +0 -7
  160. package/lib/hooks/useGlobalCache.js +0 -1
  161. package/lib/hooks/useHMR.d.ts +0 -3
  162. package/lib/hooks/useHMR.js +0 -1
  163. package/lib/hooks/useStyleRegister.d.ts +0 -81
  164. package/lib/hooks/useStyleRegister.js +0 -3
  165. package/lib/index.d.ts +0 -18
  166. package/lib/index.js +0 -1
  167. package/lib/interface.d.ts +0 -2
  168. package/lib/linters/NaNLinter.d.ts +0 -3
  169. package/lib/linters/NaNLinter.js +0 -1
  170. package/lib/linters/contentQuotesLinter.d.ts +0 -3
  171. package/lib/linters/contentQuotesLinter.js +0 -1
  172. package/lib/linters/hashedAnimationLinter.d.ts +0 -3
  173. package/lib/linters/hashedAnimationLinter.js +0 -1
  174. package/lib/linters/index.d.ts +0 -7
  175. package/lib/linters/interface.d.ts +0 -8
  176. package/lib/linters/legacyNotSelectorLinter.d.ts +0 -3
  177. package/lib/linters/legacyNotSelectorLinter.js +0 -1
  178. package/lib/linters/logicalPropertiesLinter.d.ts +0 -3
  179. package/lib/linters/logicalPropertiesLinter.js +0 -1
  180. package/lib/linters/parentSelectorLinter.d.ts +0 -3
  181. package/lib/linters/parentSelectorLinter.js +0 -1
  182. package/lib/linters/utils.d.ts +0 -2
  183. package/lib/linters/utils.js +0 -1
  184. package/lib/theme/Theme.d.ts +0 -11
  185. package/lib/theme/Theme.js +0 -1
  186. package/lib/theme/ThemeCache.d.ts +0 -20
  187. package/lib/theme/ThemeCache.js +0 -1
  188. package/lib/theme/calc/CSSCalculator.d.ts +0 -15
  189. package/lib/theme/calc/CSSCalculator.js +0 -1
  190. package/lib/theme/calc/NumCalculator.d.ts +0 -10
  191. package/lib/theme/calc/NumCalculator.js +0 -1
  192. package/lib/theme/calc/calculator.d.ts +0 -30
  193. package/lib/theme/calc/calculator.js +0 -1
  194. package/lib/theme/calc/index.d.ts +0 -5
  195. package/lib/theme/calc/index.js +0 -1
  196. package/lib/theme/createTheme.d.ts +0 -6
  197. package/lib/theme/createTheme.js +0 -1
  198. package/lib/theme/index.d.ts +0 -6
  199. package/lib/theme/interface.d.ts +0 -2
  200. package/lib/transformers/interface.d.ts +0 -4
  201. package/lib/transformers/legacyLogicalProperties.d.ts +0 -12
  202. package/lib/transformers/legacyLogicalProperties.js +0 -1
  203. package/lib/transformers/px2rem.d.ts +0 -20
  204. package/lib/transformers/px2rem.js +0 -1
  205. package/lib/util/cacheMapUtil.d.ts +0 -14
  206. package/lib/util/cacheMapUtil.js +0 -1
  207. package/lib/util/css-variables.d.ts +0 -20
  208. package/lib/util/css-variables.js +0 -1
  209. package/lib/util/index.d.ts +0 -15
  210. package/lib/util/index.js +0 -1
@@ -0,0 +1,127 @@
1
+ import { AbstractCalculator } from "../../theme/calc/calculator.js";
2
+ import { TokenType } from "../../theme/interface.js";
3
+ import { ComponentTokenKey, GlobalTokenWithComponent, TokenMap, TokenMapKey } from "../interface/components.js";
4
+ import { CSSInterpolation, CSSObject, useStyleRegister } from "../../hooks/useStyleRegister.js";
5
+ import "../../index.js";
6
+ import { UseCSP } from "../hooks/useCSP.js";
7
+ import { UsePrefix } from "../hooks/usePrefix.js";
8
+ import { UseToken } from "../hooks/useToken.js";
9
+ import * as vue0 from "vue";
10
+ import { Ref, UnwrapRef } from "vue";
11
+
12
+ //#region src/cssinjs-utils/util/genStyleUtils.d.ts
13
+ type LayerConfig = UnwrapRef<Parameters<typeof useStyleRegister>[0]>['layer'];
14
+ interface StyleInfo {
15
+ hashId: string;
16
+ prefixCls: string;
17
+ rootPrefixCls: string;
18
+ iconPrefixCls: string;
19
+ }
20
+ interface CSSUtil {
21
+ calc: (number: any) => AbstractCalculator;
22
+ max: (...values: (number | string)[]) => number | string;
23
+ min: (...values: (number | string)[]) => number | string;
24
+ }
25
+ type TokenWithCommonCls<T> = T & {
26
+ /** Wrap component class with `.` prefix */
27
+ componentCls: string;
28
+ /** Origin prefix which do not have `.` prefix */
29
+ prefixCls: string;
30
+ /** Wrap icon class with `.` prefix */
31
+ iconCls: string;
32
+ /** Wrap ant prefixCls class with `.` prefix */
33
+ antCls: string;
34
+ } & CSSUtil;
35
+ type FullToken<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = TokenWithCommonCls<GlobalTokenWithComponent<CompTokenMap, AliasToken, C>>;
36
+ type GenStyleFn<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = (token: FullToken<CompTokenMap, AliasToken, C>, info: StyleInfo) => CSSInterpolation;
37
+ type GetDefaultTokenFn<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = (token: AliasToken & Partial<CompTokenMap[C]>) => CompTokenMap[C];
38
+ type GetDefaultToken<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = null | CompTokenMap[C] | GetDefaultTokenFn<CompTokenMap, AliasToken, C>;
39
+ interface SubStyleComponentProps {
40
+ prefixCls: string;
41
+ rootCls?: string;
42
+ }
43
+ interface CSSVarRegisterProps {
44
+ rootCls: string;
45
+ component: string;
46
+ cssVar: {
47
+ prefix?: string;
48
+ key?: string;
49
+ };
50
+ }
51
+ interface GetResetStylesConfig {
52
+ prefix: ReturnType<UsePrefix>;
53
+ csp: ReturnType<UseCSP>;
54
+ }
55
+ type GetResetStyles<AliasToken extends TokenType> = (token: AliasToken, config?: GetResetStylesConfig) => CSSInterpolation;
56
+ type GetCompUnitless<CompTokenMap extends TokenMap, AliasToken extends TokenType> = <C extends TokenMapKey<CompTokenMap>>(component: C | [C, string]) => Partial<Record<ComponentTokenKey<CompTokenMap, AliasToken, C>, boolean>>;
57
+ declare function genStyleUtils<CompTokenMap extends TokenMap, AliasToken extends TokenType, DesignToken extends TokenType>(config: {
58
+ usePrefix: UsePrefix;
59
+ useToken: UseToken<CompTokenMap, AliasToken, DesignToken>;
60
+ useCSP?: UseCSP;
61
+ getResetStyles?: GetResetStyles<AliasToken>;
62
+ getCommonStyle?: (token: AliasToken, componentPrefixCls: string, rootCls?: string, resetFont?: boolean) => CSSObject;
63
+ getCompUnitless?: GetCompUnitless<CompTokenMap, AliasToken>;
64
+ layer?: LayerConfig;
65
+ }): {
66
+ genStyleHooks: <C extends TokenMapKey<CompTokenMap>>(component: C | [C, string], styleFn: GenStyleFn<CompTokenMap, AliasToken, C>, getDefaultToken?: GetDefaultToken<CompTokenMap, AliasToken, C>, options?: {
67
+ resetStyle?: boolean;
68
+ resetFont?: boolean;
69
+ deprecatedTokens?: [ComponentTokenKey<CompTokenMap, AliasToken, C>, ComponentTokenKey<CompTokenMap, AliasToken, C>][];
70
+ /**
71
+ * Component tokens that do not need unit.
72
+ */
73
+ unitless?: Partial<Record<ComponentTokenKey<CompTokenMap, AliasToken, C>, boolean>>;
74
+ /**
75
+ * Only use component style in client side. Ignore in SSR.
76
+ */
77
+ clientOnly?: boolean;
78
+ /**
79
+ * Set order of component style.
80
+ * @default -999
81
+ */
82
+ order?: number;
83
+ /**
84
+ * Whether generate styles
85
+ * @default true
86
+ */
87
+ injectStyle?: boolean;
88
+ }) => (prefixCls: Ref<string>, rootCls?: Ref<string | undefined>) => readonly [Ref<string, string>, vue0.ComputedRef<string | undefined>];
89
+ genSubStyleComponent: <C extends TokenMapKey<CompTokenMap>>(componentName: C | [C, string], styleFn: GenStyleFn<CompTokenMap, AliasToken, C>, getDefaultToken?: GetDefaultToken<CompTokenMap, AliasToken, C>, options?: {
90
+ resetStyle?: boolean;
91
+ resetFont?: boolean;
92
+ deprecatedTokens?: [ComponentTokenKey<CompTokenMap, AliasToken, C>, ComponentTokenKey<CompTokenMap, AliasToken, C>][];
93
+ /**
94
+ * Only use component style in client side. Ignore in SSR.
95
+ */
96
+ clientOnly?: boolean;
97
+ /**
98
+ * Set order of component style. Default is -999.
99
+ */
100
+ order?: number;
101
+ injectStyle?: boolean;
102
+ unitless?: Partial<Record<ComponentTokenKey<CompTokenMap, AliasToken, C>, boolean>>;
103
+ }) => vue0.DefineComponent<vue0.ExtractPropTypes<{
104
+ prefixCls: StringConstructor;
105
+ rootCls: StringConstructor;
106
+ }>, () => null, {}, {}, {}, vue0.ComponentOptionsMixin, vue0.ComponentOptionsMixin, {}, string, vue0.PublicProps, Readonly<vue0.ExtractPropTypes<{
107
+ prefixCls: StringConstructor;
108
+ rootCls: StringConstructor;
109
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, vue0.ComponentProvideOptions, true, {}, any>;
110
+ genComponentStyleHook: <C extends TokenMapKey<CompTokenMap>>(componentName: C | [C, string], styleFn: GenStyleFn<CompTokenMap, AliasToken, C>, getDefaultToken?: GetDefaultToken<CompTokenMap, AliasToken, C>, options?: {
111
+ resetStyle?: boolean;
112
+ resetFont?: boolean;
113
+ deprecatedTokens?: [ComponentTokenKey<CompTokenMap, AliasToken, C>, ComponentTokenKey<CompTokenMap, AliasToken, C>][];
114
+ /**
115
+ * Only use component style in client side. Ignore in SSR.
116
+ */
117
+ clientOnly?: boolean;
118
+ /**
119
+ * Set order of component style. Default is -999.
120
+ */
121
+ order?: number;
122
+ injectStyle?: boolean;
123
+ unitless?: Partial<Record<ComponentTokenKey<CompTokenMap, AliasToken, C>, boolean>>;
124
+ }) => (prefixCls: Ref<string>, rootCls?: Ref<string | undefined>) => Ref<string, string>;
125
+ };
126
+ //#endregion
127
+ export { CSSUtil, CSSVarRegisterProps, FullToken, GenStyleFn, GetCompUnitless, GetDefaultToken, GetDefaultTokenFn, GetResetStyles, StyleInfo, SubStyleComponentProps, TokenWithCommonCls, genStyleUtils };
@@ -0,0 +1,188 @@
1
+ import calc_default from "../../theme/calc/index.js";
2
+ import { token2CSSVar } from "../../util/css-variables.js";
3
+ import useStyleRegister from "../../hooks/useStyleRegister.js";
4
+ import useCSSVarRegister from "../../hooks/useCSSVarRegister.js";
5
+ import useUniqueMemo_default from "../_util/hooks/useUniqueMemo.js";
6
+ import useCSP_default from "../hooks/useCSP.js";
7
+ import getComponentToken_default from "./getComponentToken.js";
8
+ import getCompVarPrefix_default from "./getCompVarPrefix.js";
9
+ import statistic_default, { merge } from "./statistic.js";
10
+ import getDefaultComponentToken_default from "./getDefaultComponentToken.js";
11
+ import maxmin_default from "./maxmin.js";
12
+ import "../../index.js";
13
+ import { computed, defineComponent } from "vue";
14
+
15
+ //#region src/cssinjs-utils/util/genStyleUtils.ts
16
+ function genStyleUtils(config) {
17
+ const { useCSP = useCSP_default, useToken, usePrefix, getResetStyles, getCommonStyle, getCompUnitless } = config;
18
+ function genStyleHooks(component, styleFn, getDefaultToken, options) {
19
+ const componentName = Array.isArray(component) ? component[0] : component;
20
+ function prefixToken(key) {
21
+ return `${String(componentName)}${key.slice(0, 1).toUpperCase()}${key.slice(1)}`;
22
+ }
23
+ const originUnitless = options?.unitless || {};
24
+ const compUnitless = {
25
+ ...typeof getCompUnitless === "function" ? getCompUnitless(component) : {},
26
+ [prefixToken("zIndexPopup")]: true
27
+ };
28
+ Object.keys(originUnitless).forEach((key) => {
29
+ compUnitless[prefixToken(key)] = originUnitless[key];
30
+ });
31
+ const mergedOptions = {
32
+ ...options,
33
+ unitless: compUnitless,
34
+ prefixToken
35
+ };
36
+ const useStyle = genComponentStyleHook(component, styleFn, getDefaultToken, mergedOptions);
37
+ const useCSSVar = genCSSVarRegister(componentName, getDefaultToken, mergedOptions);
38
+ return (prefixCls, rootCls = prefixCls) => {
39
+ return [useStyle(prefixCls, rootCls), useCSSVar(rootCls)];
40
+ };
41
+ }
42
+ function genCSSVarRegister(component, getDefaultToken, options) {
43
+ const { unitless: compUnitless, prefixToken, ignore } = options;
44
+ return (rootCls) => {
45
+ const { cssVar, realToken } = useToken();
46
+ useCSSVarRegister(computed(() => {
47
+ const _cssVar = cssVar.value;
48
+ return {
49
+ path: [component],
50
+ prefix: _cssVar?.prefix,
51
+ key: _cssVar.key,
52
+ unitless: compUnitless,
53
+ ignore,
54
+ token: realToken?.value,
55
+ scope: rootCls.value
56
+ };
57
+ }), () => {
58
+ const defaultToken = getDefaultComponentToken_default(component, realToken.value, getDefaultToken);
59
+ const componentToken = getComponentToken_default(component, realToken.value, defaultToken, { deprecatedTokens: options?.deprecatedTokens });
60
+ if (defaultToken) Object.keys(defaultToken).forEach((key) => {
61
+ componentToken[prefixToken(key)] = componentToken[key];
62
+ delete componentToken[key];
63
+ });
64
+ return componentToken;
65
+ });
66
+ return computed(() => cssVar?.value?.key);
67
+ };
68
+ }
69
+ function genComponentStyleHook(componentName, styleFn, getDefaultToken, options = {}) {
70
+ const cells = Array.isArray(componentName) ? componentName : [componentName, componentName];
71
+ const [component] = cells;
72
+ const concatComponent = cells.join("-");
73
+ const mergedLayer = config.layer || { name: "antd" };
74
+ return (prefixCls, rootCls) => {
75
+ const { theme, realToken, hashId, token, cssVar, zeroRuntime } = useToken();
76
+ if (computed(() => {
77
+ return zeroRuntime?.value;
78
+ }).value) return hashId;
79
+ const prefix = usePrefix();
80
+ const csp = useCSP();
81
+ const type = computed(() => cssVar?.value ? "css" : "js");
82
+ const calc = computed(() => {
83
+ return useUniqueMemo_default(() => {
84
+ const unitlessCssVar = /* @__PURE__ */ new Set();
85
+ if (cssVar) Object.keys(options.unitless || {}).forEach((key) => {
86
+ unitlessCssVar.add(token2CSSVar(key, cssVar.value.prefix));
87
+ unitlessCssVar.add(token2CSSVar(key, getCompVarPrefix_default(component, cssVar.value.prefix)));
88
+ });
89
+ return calc_default(type.value, unitlessCssVar);
90
+ }, [
91
+ type,
92
+ component,
93
+ cssVar?.value?.prefix
94
+ ]);
95
+ });
96
+ const maxMinFunc = computed(() => maxmin_default(type.value));
97
+ const sharedConfig = computed(() => {
98
+ return {
99
+ theme: theme?.value,
100
+ token: token.value,
101
+ hashId: hashId?.value,
102
+ nonce: () => csp.value.nonce,
103
+ clientOnly: options.clientOnly,
104
+ layer: mergedLayer,
105
+ order: options.order || -999
106
+ };
107
+ });
108
+ if (typeof getResetStyles === "function") useStyleRegister(computed(() => ({
109
+ ...sharedConfig.value,
110
+ clientOnly: false,
111
+ path: ["Shared", prefix.value?.rootPrefixCls]
112
+ })), () => getResetStyles(token.value, {
113
+ prefix: computed(() => ({
114
+ rootPrefixCls: prefix.value.rootPrefixCls,
115
+ iconPrefixCls: prefix.value.iconPrefixCls
116
+ })),
117
+ csp
118
+ }));
119
+ useStyleRegister(computed(() => {
120
+ return {
121
+ ...sharedConfig.value,
122
+ path: [
123
+ concatComponent,
124
+ prefixCls.value,
125
+ prefix.value.iconPrefixCls
126
+ ]
127
+ };
128
+ }), () => {
129
+ if (options.injectStyle === false) return [];
130
+ const { token: proxyToken, flush } = statistic_default(token);
131
+ const defaultComponentToken = getDefaultComponentToken_default(component, realToken.value, getDefaultToken);
132
+ const componentCls = `.${prefixCls.value}`;
133
+ const componentToken = getComponentToken_default(component, realToken.value, defaultComponentToken, { deprecatedTokens: options.deprecatedTokens });
134
+ if (cssVar && defaultComponentToken && typeof defaultComponentToken === "object") Object.keys(defaultComponentToken).forEach((key) => {
135
+ defaultComponentToken[key] = `var(${token2CSSVar(key, getCompVarPrefix_default(component, cssVar.value.prefix))})`;
136
+ });
137
+ const mergedToken = merge(proxyToken.value, {
138
+ componentCls,
139
+ prefixCls: prefixCls.value,
140
+ iconCls: `.${prefix.value.iconPrefixCls}`,
141
+ antCls: `.${prefix.value.rootPrefixCls}`,
142
+ calc: calc.value,
143
+ max: maxMinFunc.value.max,
144
+ min: maxMinFunc.value.min
145
+ }, cssVar?.value ? defaultComponentToken : componentToken);
146
+ const styleInterpolation = styleFn(mergedToken, {
147
+ hashId: hashId.value,
148
+ prefixCls: prefixCls.value,
149
+ rootPrefixCls: prefix.value.rootPrefixCls,
150
+ iconPrefixCls: prefix.value.iconPrefixCls
151
+ });
152
+ flush(component, componentToken);
153
+ const commonStyle = typeof getCommonStyle === "function" ? getCommonStyle(mergedToken, prefixCls.value, rootCls?.value, options.resetFont) : null;
154
+ return [options.resetStyle === false ? null : commonStyle, styleInterpolation];
155
+ });
156
+ return hashId;
157
+ };
158
+ }
159
+ function genSubStyleComponent(componentName, styleFn, getDefaultToken, options = {}) {
160
+ const useStyle = genComponentStyleHook(componentName, styleFn, getDefaultToken, {
161
+ resetStyle: false,
162
+ order: -998,
163
+ ...options
164
+ });
165
+ return defineComponent({
166
+ props: {
167
+ prefixCls: String,
168
+ rootCls: String
169
+ },
170
+ setup(props) {
171
+ useStyle(computed(() => props.prefixCls), computed(() => props.rootCls ?? props.prefixCls));
172
+ return () => {
173
+ return null;
174
+ };
175
+ },
176
+ name: `SubStyle_${String(Array.isArray(componentName) ? componentName.join(".") : componentName)}`
177
+ });
178
+ }
179
+ return {
180
+ genStyleHooks,
181
+ genSubStyleComponent,
182
+ genComponentStyleHook
183
+ };
184
+ }
185
+ var genStyleUtils_default = genStyleUtils;
186
+
187
+ //#endregion
188
+ export { genStyleUtils_default as default };
@@ -0,0 +1,8 @@
1
+ //#region src/cssinjs-utils/util/getCompVarPrefix.ts
2
+ function getCompVarPrefix(component, prefix) {
3
+ return [prefix, component.replace(/([A-Z]+)([A-Z][a-z]+)/g, "$1-$2").replace(/([a-z])([A-Z])/g, "$1-$2")].filter(Boolean).join("-");
4
+ }
5
+ var getCompVarPrefix_default = getCompVarPrefix;
6
+
7
+ //#endregion
8
+ export { getCompVarPrefix_default as default };
@@ -0,0 +1,22 @@
1
+ import { warning } from "@v-c/util/dist/warning";
2
+
3
+ //#region src/cssinjs-utils/util/getComponentToken.ts
4
+ function getComponentToken(component, token, defaultToken, options) {
5
+ const customToken = { ...token[component] };
6
+ if (options?.deprecatedTokens) options.deprecatedTokens.forEach(([oldKey, newKey]) => {
7
+ if (process.env.NODE_ENV !== "production") warning(!customToken?.[oldKey], `Component Token \`${String(oldKey)}\` of ${String(component)} is deprecated. Please use \`${String(newKey)}\` instead.`);
8
+ if (customToken?.[oldKey] || customToken?.[newKey]) customToken[newKey] ??= customToken?.[oldKey];
9
+ });
10
+ const mergedToken = {
11
+ ...defaultToken,
12
+ ...customToken
13
+ };
14
+ Object.keys(mergedToken).forEach((key) => {
15
+ if (mergedToken[key] === token[key]) delete mergedToken[key];
16
+ });
17
+ return mergedToken;
18
+ }
19
+ var getComponentToken_default = getComponentToken;
20
+
21
+ //#endregion
22
+ export { getComponentToken_default as default };
@@ -0,0 +1,11 @@
1
+ import { merge } from "./statistic.js";
2
+
3
+ //#region src/cssinjs-utils/util/getDefaultComponentToken.ts
4
+ function getDefaultComponentToken(component, token, getDefaultToken) {
5
+ if (typeof getDefaultToken === "function") return getDefaultToken(merge(token, token[component] ?? {}));
6
+ return getDefaultToken ?? {};
7
+ }
8
+ var getDefaultComponentToken_default = getDefaultComponentToken;
9
+
10
+ //#endregion
11
+ export { getDefaultComponentToken_default as default };
@@ -0,0 +1,17 @@
1
+ import { unit } from "../../util/index.js";
2
+
3
+ //#region src/cssinjs-utils/util/maxmin.ts
4
+ function genMaxMin(type) {
5
+ if (type === "js") return {
6
+ max: Math.max,
7
+ min: Math.min
8
+ };
9
+ return {
10
+ max: (...args) => `max(${args.map((value) => unit(value)).join(",")})`,
11
+ min: (...args) => `min(${args.map((value) => unit(value)).join(",")})`
12
+ };
13
+ }
14
+ var maxmin_default = genMaxMin;
15
+
16
+ //#endregion
17
+ export { maxmin_default as default };
@@ -0,0 +1,15 @@
1
+ import { TokenMap } from "../interface/components.js";
2
+
3
+ //#region src/cssinjs-utils/util/statistic.d.ts
4
+ declare function merge<CompTokenMap extends TokenMap>(...objs: Partial<CompTokenMap>[]): CompTokenMap;
5
+ declare const statistic: Record<string, {
6
+ global: string[];
7
+ component: Record<string, string | number>;
8
+ }>;
9
+ declare function statisticToken<CompTokenMap extends TokenMap>(token: CompTokenMap): {
10
+ token: CompTokenMap;
11
+ keys: Set<string> | undefined;
12
+ flush: (component: string, componentToken: Record<string, string | number>) => void;
13
+ };
14
+ //#endregion
15
+ export { merge, statistic, statisticToken };
@@ -0,0 +1,52 @@
1
+ //#region src/cssinjs-utils/util/statistic.ts
2
+ const enableStatistic = process.env.NODE_ENV !== "production" || typeof CSSINJS_STATISTIC !== "undefined";
3
+ let recording = true;
4
+ function merge(...objs) {
5
+ if (!enableStatistic) return Object.assign({}, ...objs);
6
+ recording = false;
7
+ const ret = {};
8
+ objs.forEach((obj) => {
9
+ if (!obj || typeof obj !== "object") return;
10
+ Object.keys(obj).forEach((key) => {
11
+ Object.defineProperty(ret, key, {
12
+ configurable: true,
13
+ enumerable: true,
14
+ get: () => obj[key]
15
+ });
16
+ });
17
+ });
18
+ recording = true;
19
+ return ret;
20
+ }
21
+ const statistic = {};
22
+ function noop() {}
23
+ function statisticToken(token) {
24
+ let tokenKeys;
25
+ let proxy = token;
26
+ let flush = noop;
27
+ if (enableStatistic && typeof Proxy !== "undefined") {
28
+ tokenKeys = /* @__PURE__ */ new Set();
29
+ proxy = new Proxy(token, { get(obj, prop) {
30
+ if (recording) tokenKeys?.add(String(prop));
31
+ return obj[prop];
32
+ } });
33
+ flush = (componentName, componentToken) => {
34
+ statistic[componentName] = {
35
+ global: Array.from(tokenKeys),
36
+ component: {
37
+ ...statistic[componentName]?.component,
38
+ ...componentToken
39
+ }
40
+ };
41
+ };
42
+ }
43
+ return {
44
+ token: proxy,
45
+ keys: tokenKeys,
46
+ flush
47
+ };
48
+ }
49
+ var statistic_default = statisticToken;
50
+
51
+ //#endregion
52
+ export { statistic_default as default, merge, statistic };
@@ -0,0 +1,18 @@
1
+ import { Entity } from "./Cache.js";
2
+ import { ExtractStyle } from "./hooks/useGlobalCache.js";
3
+ import { CSSVarCacheValue } from "./hooks/useCSSVarRegister.js";
4
+
5
+ //#region src/extractStyle.d.ts
6
+ declare const ExtractStyleFns: {
7
+ style: ExtractStyle<[styleStr: string, styleId: string, effectStyle: Record<string, string>, clientOnly: boolean | undefined, order: number]>;
8
+ token: ExtractStyle<[token: any, hashId: string, realToken: any, cssVarStr: string, cssVarKey: string]>;
9
+ cssVar: ExtractStyle<CSSVarCacheValue<any, Record<string, any>>>;
10
+ };
11
+ type ExtractStyleType = keyof typeof ExtractStyleFns;
12
+ declare function extractStyle(cache: Entity, options?: boolean | {
13
+ plain?: boolean;
14
+ types?: ExtractStyleType | ExtractStyleType[];
15
+ once?: boolean;
16
+ }): string;
17
+ //#endregion
18
+ export { extractStyle };
@@ -0,0 +1,54 @@
1
+ import { toStyleStr } from "./util/index.js";
2
+ import { TOKEN_PREFIX, extract } from "./hooks/useCacheToken.js";
3
+ import { ATTR_CACHE_MAP, serialize } from "./util/cacheMapUtil.js";
4
+ import { STYLE_PREFIX, extract as extract$2 } from "./hooks/useStyleRegister.js";
5
+ import { CSS_VAR_PREFIX, extract as extract$1 } from "./hooks/useCSSVarRegister.js";
6
+
7
+ //#region src/extractStyle.ts
8
+ const ExtractStyleFns = {
9
+ [STYLE_PREFIX]: extract$2,
10
+ [TOKEN_PREFIX]: extract,
11
+ [CSS_VAR_PREFIX]: extract$1
12
+ };
13
+ function isNotNull(value) {
14
+ return value !== null;
15
+ }
16
+ function extractStyle(cache, options) {
17
+ const { plain = false, types = [
18
+ "style",
19
+ "token",
20
+ "cssVar"
21
+ ], once = false } = typeof options === "boolean" ? { plain: options } : options || {};
22
+ const matchPrefixRegexp = /* @__PURE__ */ new RegExp(`^(${(typeof types === "string" ? [types] : types).join("|")})%`);
23
+ const styleKeys = Array.from(cache.cache.keys()).filter((key) => matchPrefixRegexp.test(key));
24
+ const effectStyles = {};
25
+ const cachePathMap = {};
26
+ let styleText = "";
27
+ styleKeys.map((key) => {
28
+ if (once && cache.extracted.has(key)) return null;
29
+ const cachePath = key.replace(matchPrefixRegexp, "").replace(/%/g, "|");
30
+ const [prefix] = key.split("%");
31
+ const extractFn = ExtractStyleFns[prefix];
32
+ const extractedStyle = extractFn(cache.cache.get(key)[1], effectStyles, { plain });
33
+ if (!extractedStyle) return null;
34
+ const updateTime = cache.updateTimes.get(key) || 0;
35
+ const [order, styleId, styleStr] = extractedStyle;
36
+ if (key.startsWith("style")) cachePathMap[cachePath] = styleId;
37
+ cache.extracted.add(key);
38
+ return [
39
+ order,
40
+ styleStr,
41
+ updateTime
42
+ ];
43
+ }).filter(isNotNull).sort(([o1, , u1], [o2, , u2]) => {
44
+ if (o1 !== o2) return o1 - o2;
45
+ return u1 - u2;
46
+ }).forEach(([, style]) => {
47
+ styleText += style;
48
+ });
49
+ styleText += toStyleStr(`.${ATTR_CACHE_MAP}{content:"${serialize(cachePathMap)}";}`, void 0, void 0, { [ATTR_CACHE_MAP]: ATTR_CACHE_MAP }, plain);
50
+ return styleText;
51
+ }
52
+
53
+ //#endregion
54
+ export { extractStyle as default };
@@ -0,0 +1,19 @@
1
+ import "./useGlobalCache.js";
2
+ import { TokenWithCSSVar } from "../util/css-variables.js";
3
+ import { Ref } from "vue";
4
+
5
+ //#region src/hooks/useCSSVarRegister.d.ts
6
+ type CSSVarCacheValue<V, T extends Record<string, V> = Record<string, V>> = [cssVarToken: TokenWithCSSVar<V, T>, cssVarStr: string, styleId: string, cssVarKey: string];
7
+ interface CSSVarRegisterConfig {
8
+ path: string[];
9
+ key: string;
10
+ prefix?: string;
11
+ unitless?: Record<string, boolean>;
12
+ ignore?: Record<string, boolean>;
13
+ scope?: string;
14
+ token: any;
15
+ hashId?: string;
16
+ }
17
+ declare function useCSSVarRegister<V, T extends Record<string, V>>(config: Ref<CSSVarRegisterConfig>, fn: () => T): Ref<CSSVarCacheValue<V, T>, CSSVarCacheValue<V, T>>;
18
+ //#endregion
19
+ export { CSSVarCacheValue, useCSSVarRegister };
@@ -0,0 +1,74 @@
1
+ import { ATTR_MARK, ATTR_TOKEN, CSS_IN_JS_INSTANCE, useStyleContext } from "../StyleContext.js";
2
+ import { transformToken } from "../util/css-variables.js";
3
+ import { isClientSide, toStyleStr } from "../util/index.js";
4
+ import { useGlobalCache } from "./useGlobalCache.js";
5
+ import { uniqueHash } from "./useStyleRegister.js";
6
+ import { removeCSS, updateCSS } from "@v-c/util/dist/Dom/dynamicCSS";
7
+ import { computed } from "vue";
8
+
9
+ //#region src/hooks/useCSSVarRegister.ts
10
+ const CSS_VAR_PREFIX = "cssVar";
11
+ function useCSSVarRegister(config, fn) {
12
+ const styleContext = useStyleContext();
13
+ const stylePath = computed(() => {
14
+ const { key, prefix, scope = "" } = config.value;
15
+ return [
16
+ ...config.value.path,
17
+ key,
18
+ prefix,
19
+ scope
20
+ ];
21
+ });
22
+ return useGlobalCache(computed(() => CSS_VAR_PREFIX), stylePath, () => {
23
+ const originToken = fn();
24
+ const { key, prefix, unitless, ignore, hashId, scope = "" } = config.value;
25
+ const hashPriority = styleContext.value.hashPriority;
26
+ const [mergedToken, cssVarsStr] = transformToken(originToken, key, {
27
+ prefix,
28
+ unitless,
29
+ ignore,
30
+ scope,
31
+ hashPriority,
32
+ hashCls: hashId
33
+ });
34
+ return [
35
+ mergedToken,
36
+ cssVarsStr,
37
+ uniqueHash(stylePath.value, cssVarsStr),
38
+ key
39
+ ];
40
+ }, ([, , styleId]) => {
41
+ if (isClientSide) removeCSS(styleId, {
42
+ mark: ATTR_MARK,
43
+ attachTo: styleContext.value.container
44
+ });
45
+ }, ([, cssVarsStr, styleId]) => {
46
+ if (!cssVarsStr) return;
47
+ const context = styleContext.value;
48
+ const style = updateCSS(cssVarsStr, styleId, {
49
+ mark: ATTR_MARK,
50
+ prepend: "queue",
51
+ attachTo: context.container,
52
+ priority: -999
53
+ });
54
+ style[CSS_IN_JS_INSTANCE] = context.cache.instanceId;
55
+ style.setAttribute(ATTR_TOKEN, config.value.key);
56
+ });
57
+ }
58
+ const extract = (cache, _effectStyles, options) => {
59
+ const [, styleStr, styleId, cssVarKey] = cache;
60
+ const { plain } = options || {};
61
+ if (!styleStr) return null;
62
+ const order = -999;
63
+ return [
64
+ order,
65
+ styleId,
66
+ toStyleStr(styleStr, cssVarKey, styleId, {
67
+ "data-rc-order": "prependQueue",
68
+ "data-rc-priority": `${order}`
69
+ }, plain)
70
+ ];
71
+ };
72
+
73
+ //#endregion
74
+ export { CSS_VAR_PREFIX, useCSSVarRegister as default, extract };
@@ -0,0 +1,60 @@
1
+ import { Theme } from "../theme/Theme.js";
2
+ import "./useGlobalCache.js";
3
+ import { Ref } from "vue";
4
+
5
+ //#region src/hooks/useCacheToken.d.ts
6
+ interface Option<DerivativeToken, DesignToken> {
7
+ /**
8
+ * Generate token with salt.
9
+ * This is used to generate different hashId even same derivative token for different version.
10
+ */
11
+ salt?: string;
12
+ override?: object;
13
+ /**
14
+ * Format token as you need. Such as:
15
+ *
16
+ * - rename token
17
+ * - merge token
18
+ * - delete token
19
+ *
20
+ * This should always be the same since it's one time process.
21
+ * It's ok to useMemo outside but this has better cache strategy.
22
+ */
23
+ formatToken?: (mergedToken: any) => DerivativeToken;
24
+ /**
25
+ * Get final token with origin token, override token and theme.
26
+ * The parameters do not contain formatToken since it's passed by user.
27
+ * @param origin The original token.
28
+ * @param override Extra tokens to override.
29
+ * @param theme Theme instance. Could get derivative token by `theme.getDerivativeToken`
30
+ */
31
+ getComputedToken?: (origin: DesignToken, override: object, theme: Theme<any, any>) => DerivativeToken;
32
+ /**
33
+ * Transform token to css variables.
34
+ */
35
+ cssVar: {
36
+ hashed?: boolean;
37
+ /** Prefix for css variables */
38
+ prefix?: string;
39
+ /** Tokens that should not be appended with unit */
40
+ unitless?: Record<string, boolean>;
41
+ /** Tokens that should not be transformed to css variables */
42
+ ignore?: Record<string, boolean>;
43
+ /** Tokens that preserves origin value */
44
+ preserve?: Record<string, boolean>;
45
+ /** Key for current theme. Useful for customizing and should be unique */
46
+ key: string;
47
+ };
48
+ }
49
+ declare function getComputedToken<DerivativeToken = object, DesignToken = DerivativeToken>(originToken: DesignToken, overrideToken: object, theme: Theme<any, any>, format?: (token: DesignToken) => DerivativeToken): any;
50
+ type TokenCacheValue<DerivativeToken> = [token: DerivativeToken, hashId: string, realToken: DerivativeToken, cssVarStr: string, cssVarKey: string];
51
+ /**
52
+ * Cache theme derivative token as global shared one
53
+ * @param theme Theme entity
54
+ * @param tokens List of tokens, used for cache. Please do not dynamic generate object directly
55
+ * @param option Additional config
56
+ * @returns Call Theme.getDerivativeToken(tokenObject) to get token
57
+ */
58
+ declare function useCacheToken<DerivativeToken = Record<string, any>, DesignToken = DerivativeToken>(theme: Ref<Theme<any, any>>, tokens: Ref<(Partial<DesignToken> | (() => Partial<DesignToken>))[]>, option: Ref<Option<DerivativeToken, DesignToken>>): Ref<TokenCacheValue<DerivativeToken>, TokenCacheValue<DerivativeToken>>;
59
+ //#endregion
60
+ export { getComputedToken, useCacheToken };