@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,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 = "css";
82
+ const calc = computed(() => {
83
+ return useUniqueMemo_default(() => {
84
+ const unitlessCssVar = /* @__PURE__ */ new Set();
85
+ 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, unitlessCssVar);
90
+ }, [
91
+ type,
92
+ component,
93
+ cssVar?.value?.prefix
94
+ ]);
95
+ });
96
+ const { max, min } = maxmin_default(type);
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 (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,
144
+ min
145
+ }, defaultComponentToken);
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,86 @@
1
+ import { collectStyleText } from "../ssr/styleCollector.js";
2
+ import { ATTR_MARK, ATTR_TOKEN, CSS_IN_JS_INSTANCE, useStyleContext } from "../StyleContext.js";
3
+ import { transformToken } from "../util/css-variables.js";
4
+ import { isClientSide, toStyleStr } from "../util/index.js";
5
+ import { useGlobalCache } from "./useGlobalCache.js";
6
+ import { uniqueHash } from "./useStyleRegister.js";
7
+ import canUseDom from "@v-c/util/dist/Dom/canUseDom";
8
+ import { removeCSS, updateCSS } from "@v-c/util/dist/Dom/dynamicCSS";
9
+ import { computed } from "vue";
10
+
11
+ //#region src/hooks/useCSSVarRegister.ts
12
+ const CSS_VAR_PREFIX = "cssVar";
13
+ const extract = (cache, _effectStyles, options) => {
14
+ const [, styleStr, styleId, cssVarKey] = cache;
15
+ const { plain } = options || {};
16
+ if (!styleStr) return null;
17
+ const order = -999;
18
+ return [
19
+ order,
20
+ styleId,
21
+ toStyleStr(styleStr, cssVarKey, styleId, {
22
+ "data-rc-order": "prependQueue",
23
+ "data-rc-priority": `${order}`
24
+ }, plain)
25
+ ];
26
+ };
27
+ function useCSSVarRegister(config, fn) {
28
+ const styleContext = useStyleContext();
29
+ const stylePath = computed(() => {
30
+ const { key, scope = "", token } = config.value;
31
+ const tokenKey = token?._tokenKey;
32
+ return [
33
+ ...config.value.path,
34
+ key,
35
+ scope,
36
+ tokenKey
37
+ ];
38
+ });
39
+ return useGlobalCache(computed(() => CSS_VAR_PREFIX), stylePath, () => {
40
+ const originToken = fn();
41
+ const { key, prefix, unitless, ignore, hashId, scope = "" } = config.value;
42
+ const hashPriority = styleContext.value.hashPriority;
43
+ const [mergedToken, cssVarsStr] = transformToken(originToken, key, {
44
+ prefix,
45
+ unitless,
46
+ ignore,
47
+ scope,
48
+ hashPriority,
49
+ hashCls: hashId
50
+ });
51
+ return [
52
+ mergedToken,
53
+ cssVarsStr,
54
+ uniqueHash(stylePath.value, cssVarsStr),
55
+ key
56
+ ];
57
+ }, ([, , styleId]) => {
58
+ if (isClientSide) removeCSS(styleId, {
59
+ mark: ATTR_MARK,
60
+ attachTo: styleContext.value.container
61
+ });
62
+ }, (cacheValue) => {
63
+ const [, cssVarsStr, styleId] = cacheValue;
64
+ if (!canUseDom()) {
65
+ const extracted = extract(cacheValue, {}, { plain: false });
66
+ if (extracted) {
67
+ const [, , styleText] = extracted;
68
+ collectStyleText(styleText);
69
+ }
70
+ return;
71
+ }
72
+ if (!cssVarsStr) return;
73
+ const context = styleContext.value;
74
+ const style = updateCSS(cssVarsStr, styleId, {
75
+ mark: ATTR_MARK,
76
+ prepend: "queue",
77
+ attachTo: context.container,
78
+ priority: -999
79
+ });
80
+ style[CSS_IN_JS_INSTANCE] = context.cache.instanceId;
81
+ style.setAttribute(ATTR_TOKEN, config.value.key);
82
+ });
83
+ }
84
+
85
+ //#endregion
86
+ export { CSS_VAR_PREFIX, useCSSVarRegister as default, extract };