@omnific/atelier 0.2.0 → 0.4.0

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 (79) hide show
  1. package/README.md +9 -5
  2. package/dist/box/Box.d.ts +1 -1
  3. package/dist/box/Box.js +8 -13
  4. package/dist/box/index.js +1 -2
  5. package/dist/box/types.d.ts +6 -30
  6. package/dist/button/Button.js +3 -2
  7. package/dist/button/index.d.ts +2 -2
  8. package/dist/button/index.js +1 -2
  9. package/dist/button/types.d.ts +15 -5
  10. package/dist/props/display.props.d.ts +10 -0
  11. package/dist/props/display.props.js +15 -0
  12. package/dist/props/flex.props.d.ts +58 -0
  13. package/dist/props/flex.props.js +72 -0
  14. package/dist/props/gap.props.d.ts +10 -0
  15. package/dist/props/gap.props.js +18 -0
  16. package/dist/props/height.props.d.ts +10 -0
  17. package/dist/props/height.props.js +27 -0
  18. package/dist/props/index.d.ts +95 -0
  19. package/dist/props/index.js +158 -0
  20. package/dist/props/justify.props.d.ts +34 -0
  21. package/dist/props/justify.props.js +43 -0
  22. package/dist/props/margin.props.d.ts +10 -0
  23. package/dist/props/margin.props.js +27 -0
  24. package/dist/props/overflow.props.d.ts +10 -0
  25. package/dist/props/overflow.props.js +13 -0
  26. package/dist/props/padding.props.d.ts +10 -0
  27. package/dist/props/padding.props.js +18 -0
  28. package/dist/props/position.props.d.ts +18 -0
  29. package/dist/props/position.props.js +38 -0
  30. package/dist/props/radius.props.d.ts +10 -0
  31. package/dist/props/radius.props.js +19 -0
  32. package/dist/props/scaling.props.d.ts +10 -0
  33. package/dist/props/shadow.props.d.ts +10 -0
  34. package/dist/props/shadow.props.js +16 -0
  35. package/dist/props/width.props.d.ts +10 -0
  36. package/dist/props/width.props.js +26 -0
  37. package/dist/styles.css +2479 -69
  38. package/dist/system/create-system.d.ts +9 -4
  39. package/dist/system/create-system.js +9 -8
  40. package/dist/system/css-vars.d.ts +5 -40
  41. package/dist/system/css-vars.js +5 -61
  42. package/dist/system/default-system.d.ts +7 -3
  43. package/dist/system/default-system.js +3 -3
  44. package/dist/system/defaults/color-keys.gen.d.ts +3 -0
  45. package/dist/system/defaults/colors.d.ts +92 -169
  46. package/dist/system/defaults/colors.js +101 -63
  47. package/dist/system/define-colors.d.ts +7 -0
  48. package/dist/system/define-colors.js +7 -0
  49. package/dist/system/flatten-colors.d.ts +11 -0
  50. package/dist/system/flatten-colors.js +26 -0
  51. package/dist/system/index.d.ts +8 -14
  52. package/dist/system/index.js +6 -13
  53. package/dist/system/merge-colors.d.ts +12 -0
  54. package/dist/system/merge-colors.js +30 -0
  55. package/dist/system/types.d.ts +15 -53
  56. package/dist/system/use-theme.d.ts +3 -23
  57. package/dist/system/use-theme.js +2 -21
  58. package/dist/utils/extractProps.js +34 -0
  59. package/package.json +16 -20
  60. package/dist/system/defaults/control-heights.d.ts +0 -16
  61. package/dist/system/defaults/control-heights.js +0 -11
  62. package/dist/system/defaults/focus-rings.d.ts +0 -10
  63. package/dist/system/defaults/focus-rings.js +0 -7
  64. package/dist/system/defaults/font-sizes.d.ts +0 -13
  65. package/dist/system/defaults/font-sizes.js +0 -10
  66. package/dist/system/defaults/fonts.d.ts +0 -10
  67. package/dist/system/defaults/fonts.js +0 -7
  68. package/dist/system/defaults/index.d.ts +0 -422
  69. package/dist/system/defaults/index.js +0 -28
  70. package/dist/system/defaults/radii.d.ts +0 -40
  71. package/dist/system/defaults/radii.js +0 -19
  72. package/dist/system/defaults/shadows.d.ts +0 -31
  73. package/dist/system/defaults/shadows.js +0 -16
  74. package/dist/system/defaults/spacing.d.ts +0 -112
  75. package/dist/system/defaults/spacing.js +0 -43
  76. package/dist/system/define-tokens.d.ts +0 -7
  77. package/dist/system/define-tokens.js +0 -7
  78. package/dist/system/merge-tokens.d.ts +0 -20
  79. package/dist/system/merge-tokens.js +0 -27
@@ -1,68 +1,106 @@
1
+ import { defineColors } from "../define-colors.js";
1
2
  //#region system/defaults/colors.ts
2
3
  /**
3
- * 默认语义色。
4
+ * 默认语义颜色。
4
5
  *
5
- * 控件品牌色与灰阶对齐 Atelier 既有 Button 主题(Ant Design 色值);
6
- * `bg` / `fg` / `border` 角色名保留,便于组件与业务扩展。
6
+ * 分组内使用 base 表示当前分组自己的颜色。
7
7
  */
8
- const colors = {
9
- bg: { value: "#ffffff" },
10
- "bg.subtle": { value: "#fafafa" },
11
- "bg.muted": { value: "#f4f4f5" },
12
- "bg.emphasized": { value: "#e4e4e7" },
13
- "bg.inverted": { value: "#09090b" },
14
- "bg.panel": { value: "#ffffff" },
15
- "bg.disabled": { value: "rgb(239 239 239)" },
16
- "bg.error": { value: "#fef2f2" },
17
- "bg.warning": { value: "#fff7ed" },
18
- "bg.success": { value: "#f0fdf4" },
19
- "bg.info": { value: "#e6f4ff" },
20
- fg: { value: "rgb(0 0 0 / 88%)" },
21
- "fg.muted": { value: "rgb(0 0 0 / 45%)" },
22
- "fg.subtle": { value: "rgb(0 0 0 / 25%)" },
23
- "fg.inverted": { value: "#ffffff" },
24
- "fg.disabled": { value: "rgb(0 0 0 / 25%)" },
25
- "fg.error": { value: "#ff4d4f" },
26
- "fg.warning": { value: "#faad14" },
27
- "fg.success": { value: "#52c41a" },
28
- "fg.info": { value: "#1677ff" },
29
- border: { value: "#d9d9d9" },
30
- "border.muted": { value: "#f0f0f0" },
31
- "border.subtle": { value: "#fafafa" },
32
- "border.emphasized": { value: "#d9d9d9" },
33
- "border.inverted": { value: "#434343" },
34
- "border.error": { value: "#ff4d4f" },
35
- "border.warning": { value: "#faad14" },
36
- "border.success": { value: "#52c41a" },
37
- "border.info": { value: "#1677ff" },
38
- "gray.contrast": { value: "#ffffff" },
39
- "gray.fg": { value: "rgb(0 0 0 / 88%)" },
40
- "gray.subtle": { value: "#fafafa" },
41
- "gray.muted": { value: "#f5f5f5" },
42
- "gray.emphasized": { value: "#d9d9d9" },
43
- "gray.solid": { value: "#1f1f1f" },
44
- "gray.focus-ring": { value: "rgb(0 0 0 / 15%)" },
45
- "gray.border": { value: "#d9d9d9" },
46
- "blue.contrast": { value: "#ffffff" },
47
- "blue.fg": { value: "#1677ff" },
48
- "blue.subtle": { value: "#e6f4ff" },
49
- "blue.muted": { value: "#bae0ff" },
50
- "blue.emphasized": { value: "#69b1ff" },
51
- "blue.solid": { value: "#1677ff" },
52
- "blue.hover": { value: "#4096ff" },
53
- "blue.active": { value: "#0958d9" },
54
- "blue.focus-ring": { value: "rgb(21 112 239 / 25%)" },
55
- "blue.border": { value: "#1677ff" },
56
- "red.contrast": { value: "#ffffff" },
57
- "red.fg": { value: "#ff4d4f" },
58
- "red.subtle": { value: "#fff1f0" },
59
- "red.muted": { value: "#ffccc7" },
60
- "red.emphasized": { value: "#ffa39e" },
61
- "red.solid": { value: "#ff4d4f" },
62
- "red.hover": { value: "#ff7875" },
63
- "red.active": { value: "#d9363e" },
64
- "red.focus-ring": { value: "rgb(255 77 79 / 25%)" },
65
- "red.border": { value: "#ff4d4f" }
66
- };
8
+ const defaultColors = defineColors({
9
+ bg: {
10
+ base: "#ffffff",
11
+ subtle: "#fafafa",
12
+ muted: "#f4f4f5",
13
+ emphasized: "#e4e4e7",
14
+ inverted: "#09090b",
15
+ panel: "#ffffff",
16
+ disabled: "rgb(239 239 239)",
17
+ danger: "#fef2f2",
18
+ warning: "#fff7ed",
19
+ success: "#f0fdf4",
20
+ info: "#e6f4ff"
21
+ },
22
+ fg: {
23
+ base: "rgb(0 0 0 / 88%)",
24
+ muted: "rgb(0 0 0 / 45%)",
25
+ subtle: "rgb(0 0 0 / 25%)",
26
+ inverted: "#ffffff",
27
+ disabled: "rgb(0 0 0 / 25%)",
28
+ danger: "#ff4d4f",
29
+ warning: "#faad14",
30
+ success: "#52c41a",
31
+ info: "#1677ff"
32
+ },
33
+ border: {
34
+ base: "#d9d9d9",
35
+ muted: "#f0f0f0",
36
+ subtle: "#fafafa",
37
+ emphasized: "#d9d9d9",
38
+ inverted: "#434343",
39
+ danger: "#ff4d4f",
40
+ warning: "#faad14",
41
+ success: "#52c41a",
42
+ info: "#1677ff"
43
+ },
44
+ accent: {
45
+ contrast: "#ffffff",
46
+ fg: "#1677ff",
47
+ subtle: "#e6f4ff",
48
+ muted: "#bae0ff",
49
+ emphasized: "#69b1ff",
50
+ solid: "#1677ff",
51
+ hover: "#4096ff",
52
+ active: "#0958d9",
53
+ "focus-ring": "rgb(21 112 239 / 25%)",
54
+ border: "#1677ff"
55
+ },
56
+ danger: {
57
+ contrast: "#ffffff",
58
+ fg: "#ff4d4f",
59
+ subtle: "#fff1f0",
60
+ muted: "#ffccc7",
61
+ emphasized: "#ffa39e",
62
+ solid: "#ff4d4f",
63
+ hover: "#ff7875",
64
+ active: "#d9363e",
65
+ "focus-ring": "rgb(255 77 79 / 25%)",
66
+ border: "#ff4d4f"
67
+ },
68
+ warning: {
69
+ contrast: "#ffffff",
70
+ fg: "#faad14",
71
+ subtle: "#fff7ed",
72
+ muted: "#ffe7ba",
73
+ emphasized: "#ffd666",
74
+ solid: "#faad14",
75
+ hover: "#ffc53d",
76
+ active: "#d48806",
77
+ "focus-ring": "rgb(250 173 20 / 25%)",
78
+ border: "#faad14"
79
+ },
80
+ success: {
81
+ contrast: "#ffffff",
82
+ fg: "#52c41a",
83
+ subtle: "#f0fdf4",
84
+ muted: "#b7eb8f",
85
+ emphasized: "#95de64",
86
+ solid: "#52c41a",
87
+ hover: "#73d13d",
88
+ active: "#389e0d",
89
+ "focus-ring": "rgb(82 196 26 / 25%)",
90
+ border: "#52c41a"
91
+ },
92
+ info: {
93
+ contrast: "#ffffff",
94
+ fg: "#1677ff",
95
+ subtle: "#e6f4ff",
96
+ muted: "#bae0ff",
97
+ emphasized: "#69b1ff",
98
+ solid: "#1677ff",
99
+ hover: "#4096ff",
100
+ active: "#0958d9",
101
+ "focus-ring": "rgb(21 112 239 / 25%)",
102
+ border: "#1677ff"
103
+ }
104
+ });
67
105
  //#endregion
68
- export { colors };
106
+ export { defaultColors };
@@ -0,0 +1,7 @@
1
+ import { ColorSet } from "./types.js";
2
+ //#region system/define-colors.d.ts
3
+ /**
4
+ * 标注并返回嵌套颜色配置,保留字面量结构。
5
+ */
6
+ export declare const defineColors: <const T extends ColorSet>(colors: T) => T;
7
+ //#endregion
@@ -0,0 +1,7 @@
1
+ //#region system/define-colors.ts
2
+ /**
3
+ * 标注并返回嵌套颜色配置,保留字面量结构。
4
+ */
5
+ const defineColors = (colors) => colors;
6
+ //#endregion
7
+ export { defineColors };
@@ -0,0 +1,11 @@
1
+ import { ColorSet } from "./types.js";
2
+ //#region system/flatten-colors.d.ts
3
+ /**
4
+ * 将嵌套颜色配置展开为扁平 key。
5
+ *
6
+ * bg.base -> bg
7
+ * bg.muted -> bg-muted
8
+ * accent.solid -> accent-solid
9
+ */
10
+ export declare const flattenColors: (colors: ColorSet, prefix?: string, result?: Record<string, string>) => Record<string, string>;
11
+ //#endregion
@@ -0,0 +1,26 @@
1
+ import { isNil, isString } from "@omnific/utils";
2
+ //#region system/flatten-colors.ts
3
+ /**
4
+ * 将嵌套颜色配置展开为扁平 key。
5
+ *
6
+ * bg.base -> bg
7
+ * bg.muted -> bg-muted
8
+ * accent.solid -> accent-solid
9
+ */
10
+ const flattenColors = (colors, prefix = "", result = {}) => {
11
+ const keys = Object.keys(colors);
12
+ for (const key of keys) {
13
+ if (isNil(key)) continue;
14
+ const value = colors[key];
15
+ const path = key === "base" ? prefix : prefix ? `${prefix}-${key}` : key;
16
+ if (isString(value)) {
17
+ result[path] = value;
18
+ continue;
19
+ }
20
+ if (isNil(value)) continue;
21
+ flattenColors(value, path, result);
22
+ }
23
+ return result;
24
+ };
25
+ //#endregion
26
+ export { flattenColors };
@@ -1,17 +1,11 @@
1
- import { SystemContext, ThemeTokens, TokenCategory, TokenCategoryKeys, TokenNode } from "./types.js";
1
+ import { defaultColors } from "./defaults/colors.js";
2
+ import { DefaultColorKey } from "./defaults/color-keys.gen.js";
3
+ import { ColorSet, ColorValue, FlatColorSet, SystemContext } from "./types.js";
4
+ import { applyCssVars, toColorVarName } from "./css-vars.js";
2
5
  import { createSystem } from "./create-system.js";
3
- import { TokenStyleEntry, applyCssVars, styleFromTokens, toCssVarName } from "./css-vars.js";
4
6
  import { defaultSystem } from "./default-system.js";
5
- import { colors } from "./defaults/colors.js";
6
- import { controlHeights } from "./defaults/control-heights.js";
7
- import { focusRings } from "./defaults/focus-rings.js";
8
- import { fontSizes } from "./defaults/font-sizes.js";
9
- import { fonts } from "./defaults/fonts.js";
10
- import { radii } from "./defaults/radii.js";
11
- import { shadows } from "./defaults/shadows.js";
12
- import { spacing } from "./defaults/spacing.js";
13
- import { ColorToken, ControlHeightToken, FocusRingToken, FontSizeToken, FontToken, RadiiToken, ShadowToken, SpacingToken, defaultConfig } from "./defaults/index.js";
14
- import { defineTokens } from "./define-tokens.js";
15
- import { MergeTokensResult, mergeTokens } from "./merge-tokens.js";
7
+ import { defineColors } from "./define-colors.js";
8
+ import { flattenColors } from "./flatten-colors.js";
9
+ import { mergeColors } from "./merge-colors.js";
16
10
  import { useTheme } from "./use-theme.js";
17
- export { type ColorToken, type ControlHeightToken, type FocusRingToken, type FontSizeToken, type FontToken, type MergeTokensResult, type RadiiToken, type ShadowToken, type SpacingToken, type SystemContext, type ThemeTokens, type TokenCategory, type TokenCategoryKeys, type TokenNode, type TokenStyleEntry, applyCssVars, colors, controlHeights, createSystem, defaultConfig, defaultSystem, defineTokens, focusRings, fontSizes, fonts, mergeTokens, radii, shadows, spacing, styleFromTokens, toCssVarName, useTheme };
11
+ export { type ColorSet, type ColorValue, type DefaultColorKey, type FlatColorSet, type SystemContext, applyCssVars, createSystem, defaultColors, defaultSystem, defineColors, flattenColors, mergeColors, toColorVarName, useTheme };
@@ -1,16 +1,9 @@
1
- import { applyCssVars, styleFromTokens, toCssVarName } from "./css-vars.js";
2
- import { mergeTokens } from "./merge-tokens.js";
1
+ import { applyCssVars, toColorVarName } from "./css-vars.js";
2
+ import { flattenColors } from "./flatten-colors.js";
3
+ import { mergeColors } from "./merge-colors.js";
3
4
  import { createSystem } from "./create-system.js";
4
- import { colors } from "./defaults/colors.js";
5
- import { controlHeights } from "./defaults/control-heights.js";
6
- import { focusRings } from "./defaults/focus-rings.js";
7
- import { fontSizes } from "./defaults/font-sizes.js";
8
- import { fonts } from "./defaults/fonts.js";
9
- import { radii } from "./defaults/radii.js";
10
- import { shadows } from "./defaults/shadows.js";
11
- import { spacing } from "./defaults/spacing.js";
12
- import { defineTokens } from "./define-tokens.js";
13
- import { defaultConfig } from "./defaults/index.js";
5
+ import { defineColors } from "./define-colors.js";
6
+ import { defaultColors } from "./defaults/colors.js";
14
7
  import { defaultSystem } from "./default-system.js";
15
8
  import { useTheme } from "./use-theme.js";
16
- export { applyCssVars, colors, controlHeights, createSystem, defaultConfig, defaultSystem, defineTokens, focusRings, fontSizes, fonts, mergeTokens, radii, shadows, spacing, styleFromTokens, toCssVarName, useTheme };
9
+ export { applyCssVars, createSystem, defaultColors, defaultSystem, defineColors, flattenColors, mergeColors, toColorVarName, useTheme };
@@ -0,0 +1,12 @@
1
+ import { ColorSet, FlatColorSet } from "./types.js";
2
+ //#region system/merge-colors.d.ts
3
+ /**
4
+ * 展开并合并嵌套颜色表,输出扁平颜色和 CSS 变量。
5
+ *
6
+ * 后传入的颜色覆盖前面同名 key。
7
+ */
8
+ export declare const mergeColors: (...colorSets: ColorSet[]) => {
9
+ colors: FlatColorSet;
10
+ cssVars: Readonly<Record<string, string>>;
11
+ };
12
+ //#endregion
@@ -0,0 +1,30 @@
1
+ import { toColorVarName } from "./css-vars.js";
2
+ import { flattenColors } from "./flatten-colors.js";
3
+ import { isNil } from "@omnific/utils";
4
+ //#region system/merge-colors.ts
5
+ /**
6
+ * 展开并合并嵌套颜色表,输出扁平颜色和 CSS 变量。
7
+ *
8
+ * 后传入的颜色覆盖前面同名 key。
9
+ */
10
+ const mergeColors = (...colorSets) => {
11
+ const colors = {};
12
+ for (const colorSet of colorSets) {
13
+ if (isNil(colorSet)) continue;
14
+ Object.assign(colors, flattenColors(colorSet));
15
+ }
16
+ const colorKeys = Object.keys(colors);
17
+ const cssVars = {};
18
+ for (const key of colorKeys) {
19
+ if (isNil(key)) continue;
20
+ const value = colors[key];
21
+ if (isNil(value)) continue;
22
+ cssVars[toColorVarName(key)] = value;
23
+ }
24
+ return {
25
+ colors,
26
+ cssVars: Object.freeze(cssVars)
27
+ };
28
+ };
29
+ //#endregion
30
+ export { mergeColors };
@@ -1,72 +1,34 @@
1
1
  //#region system/types.d.ts
2
2
  /**
3
- * 单个 token 节点。
3
+ * 颜色叶子值。
4
4
  */
5
- export type TokenNode = {
6
- /**
7
- * CSS 值。
8
- */
9
- value: string;
10
- };
5
+ export type ColorValue = string;
11
6
  /**
12
- * 一类 token;键可用 `bg.muted` 这类带点路径段。
7
+ * 嵌套颜色配置。
8
+ *
9
+ * base 是保留键,表示当前分组自己的颜色。
13
10
  */
14
- export type TokenCategory = Record<string, TokenNode>;
15
- /**
16
- * 从具体 token 分类对象推导可用键的联合类型。
17
- */
18
- export type TokenCategoryKeys<T> = keyof T & (string | number);
11
+ export type ColorSet = {
12
+ [key: string]: ColorValue | ColorSet;
13
+ };
19
14
  /**
20
- * 主题 tokens。
15
+ * 展开后的扁平颜色表。
21
16
  */
22
- export type ThemeTokens = {
23
- /**
24
- * 颜色 token。
25
- */
26
- colors?: TokenCategory;
27
- /**
28
- * 间距 token。
29
- */
30
- spacing?: TokenCategory;
31
- /**
32
- * 圆角 token。
33
- */
34
- radii?: TokenCategory;
35
- /**
36
- * 阴影 token。
37
- */
38
- shadows?: TokenCategory;
39
- /**
40
- * 字体族 token。
41
- */
42
- fonts?: TokenCategory;
43
- /**
44
- * 字号 token。
45
- */
46
- fontSizes?: TokenCategory;
47
- /**
48
- * 控件高度 token。
49
- */
50
- controlHeights?: TokenCategory;
51
- /**
52
- * 焦点环 token。
53
- */
54
- focusRings?: TokenCategory;
55
- };
17
+ export type FlatColorSet = Record<string, string>;
56
18
  /**
57
- * 精简版 SystemContext;实例只描述运行时主题能力,不携带具体 tokens 泛型。
19
+ * applyCssVars / useTheme 的参数契约。
58
20
  */
59
21
  export type SystemContext = {
60
22
  /**
61
- * 主题名称;同名 system 在注入时复用同一张 `<style>`。
23
+ * 主题名称。
62
24
  */
63
25
  name: string;
64
26
  /**
65
- * 合并后的 tokens。
27
+ * 展开后的扁平颜色表。
66
28
  */
67
- _config: ThemeTokens;
29
+ colors: FlatColorSet;
68
30
  /**
69
- * 已缓存的扁平 CSS 变量表(变量名 → 值)。
31
+ * 扁平颜色 CSS 变量表。
70
32
  */
71
33
  cssVars: Readonly<Record<string, string>>;
72
34
  };
@@ -1,31 +1,11 @@
1
1
  import { SystemContext } from "./types.js";
2
- import { RefObject } from "react";
3
2
  //#region system/use-theme.d.ts
4
3
  /**
5
- * 将 `system.cssVars` 运行时注入到 DOM。
4
+ * 将 system 的颜色 CSS 变量运行时注入到 DOM。
6
5
  *
7
6
  * 返回对象 ref:
8
7
  * - 挂到元素上时,给该节点打上 `data-atelier-theme={system.name}`;
9
- * - 未挂载(`ref.current === null`)时,变量写在 `document.documentElement`(同样打上该属性)。
10
- *
11
- * 样式节点统一挂在 `document.head` 下;同一 `system.name` 复用一张 `<style>`,以引用次数管理生命周期。
12
- * 不使用 inline style / React Context。
13
- *
14
- * @example
15
- * ```tsx
16
- * const system = createSystem('app', defaultConfig);
17
- *
18
- * function App() {
19
- * const themeRef = useTheme<HTMLDivElement>(system);
20
- * return <div ref={themeRef}>...</div>;
21
- * }
22
- *
23
- * // 或不挂 ref,自动注册到 documentElement
24
- * function App() {
25
- * useTheme(system);
26
- * return <div>...</div>;
27
- * }
28
- * ```
8
+ * - 未挂载时,变量写在 `document.documentElement`。
29
9
  */
30
- export declare const useTheme: <TElement extends HTMLElement = HTMLElement>(system: SystemContext) => RefObject<TElement | null>;
10
+ export declare const useTheme: <TElement extends HTMLElement = HTMLElement>(system: SystemContext) => import("react").RefObject<TElement | null>;
31
11
  //#endregion
@@ -2,30 +2,11 @@ import { applyCssVars } from "./css-vars.js";
2
2
  import { useLayoutEffect, useRef } from "react";
3
3
  //#region system/use-theme.ts
4
4
  /**
5
- * 将 `system.cssVars` 运行时注入到 DOM。
5
+ * 将 system 的颜色 CSS 变量运行时注入到 DOM。
6
6
  *
7
7
  * 返回对象 ref:
8
8
  * - 挂到元素上时,给该节点打上 `data-atelier-theme={system.name}`;
9
- * - 未挂载(`ref.current === null`)时,变量写在 `document.documentElement`(同样打上该属性)。
10
- *
11
- * 样式节点统一挂在 `document.head` 下;同一 `system.name` 复用一张 `<style>`,以引用次数管理生命周期。
12
- * 不使用 inline style / React Context。
13
- *
14
- * @example
15
- * ```tsx
16
- * const system = createSystem('app', defaultConfig);
17
- *
18
- * function App() {
19
- * const themeRef = useTheme<HTMLDivElement>(system);
20
- * return <div ref={themeRef}>...</div>;
21
- * }
22
- *
23
- * // 或不挂 ref,自动注册到 documentElement
24
- * function App() {
25
- * useTheme(system);
26
- * return <div>...</div>;
27
- * }
28
- * ```
9
+ * - 未挂载时,变量写在 `document.documentElement`。
29
10
  */
30
11
  const useTheme = (system) => {
31
12
  const ref = useRef(null);
@@ -0,0 +1,34 @@
1
+ import { atelierStyleMaps, getAtelierClassName } from "../props/index.js";
2
+ import { clsx } from "clsx";
3
+ import { hasValue, isNil } from "@omnific/utils";
4
+ //#region utils/extractProps.ts
5
+ /**
6
+ * 提取全局 props,生成静态 class 与 inline style,并透传剩余原生 props。
7
+ */
8
+ const extractProps = (props) => {
9
+ const sourceProps = props;
10
+ const restProps = {};
11
+ const classNames = [];
12
+ const style = {};
13
+ for (const propName in sourceProps) {
14
+ const value = sourceProps[propName];
15
+ if (isNil(value)) continue;
16
+ const stringValue = String(value);
17
+ const className = getAtelierClassName(propName, stringValue);
18
+ if (hasValue(className)) {
19
+ classNames.push(className);
20
+ continue;
21
+ }
22
+ const styleResolver = atelierStyleMaps[propName];
23
+ if (hasValue(styleResolver)) {
24
+ Object.assign(style, styleResolver(stringValue));
25
+ continue;
26
+ }
27
+ restProps[propName] = value;
28
+ }
29
+ restProps.className = clsx(classNames, sourceProps.className);
30
+ restProps.style = Object.assign(style, sourceProps.style);
31
+ return restProps;
32
+ };
33
+ //#endregion
34
+ export { extractProps };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnific/atelier",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "A refined React component library for Omnific",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -58,32 +58,28 @@
58
58
  "dist",
59
59
  "README.md"
60
60
  ],
61
+ "scripts": {
62
+ "build": "tsx ../../scripts/build/atelier.ts",
63
+ "test": "vitest run",
64
+ "typecheck": "tsc -p tsconfig.json --noEmit"
65
+ },
61
66
  "dependencies": {
62
- "@omnific/hooks": "0.2.1",
63
- "@omnific/icons": "0.1.0",
64
- "@omnific/types": "0.0.8",
65
- "@omnific/utils": "0.3.1",
66
- "clsx": "^2.1.1"
67
+ "@omnific/hooks": "workspace:*",
68
+ "@omnific/icons": "workspace:*",
69
+ "@omnific/types": "workspace:*",
70
+ "@omnific/utils": "workspace:*",
71
+ "clsx": "^2.1.1",
72
+ "motion": "^14.4.0"
67
73
  },
68
74
  "peerDependencies": {
69
- "motion": "^13.1.0",
70
75
  "react": "^19.2.8",
71
76
  "react-dom": "^19.2.8"
72
77
  },
73
78
  "devDependencies": {
74
- "@omnific/tsconfig": "0.2.0",
79
+ "@omnific/tsconfig": "workspace:*",
75
80
  "@types/react": "^19.3.0",
76
81
  "@types/react-dom": "^19.3.0",
77
- "motion": "^13.4.4",
78
- "react": "^19.3.0",
79
- "react-dom": "^19.3.0",
80
- "sass-embedded": "1.105.0"
81
- },
82
- "scripts": {
83
- "dev": "pnpm --dir ../.. storybook",
84
- "build": "tsdown -c tsdown.config.mjs && pnpm build:styles",
85
- "build:styles": "sass --style=expanded --no-source-map styles/index.scss dist/styles.css",
86
- "test": "vitest run",
87
- "typecheck": "tsc -p tsconfig.json --noEmit"
82
+ "react": "^19.3.1",
83
+ "react-dom": "^19.3.1"
88
84
  }
89
- }
85
+ }
@@ -1,16 +0,0 @@
1
- //#region system/defaults/control-heights.d.ts
2
- /**
3
- * 默认控件高度。
4
- */
5
- export declare const controlHeights: {
6
- readonly sm: {
7
- readonly value: "24px";
8
- };
9
- readonly md: {
10
- readonly value: "32px";
11
- };
12
- readonly lg: {
13
- readonly value: "40px";
14
- };
15
- };
16
- //#endregion
@@ -1,11 +0,0 @@
1
- //#region system/defaults/control-heights.ts
2
- /**
3
- * 默认控件高度。
4
- */
5
- const controlHeights = {
6
- sm: { value: "24px" },
7
- md: { value: "32px" },
8
- lg: { value: "40px" }
9
- };
10
- //#endregion
11
- export { controlHeights };
@@ -1,10 +0,0 @@
1
- //#region system/defaults/focus-rings.d.ts
2
- /**
3
- * 默认焦点环(对齐 Atelier 既有 Button 焦点色)。
4
- */
5
- export declare const focusRings: {
6
- readonly default: {
7
- readonly value: "rgb(21 112 239 / 25%)";
8
- };
9
- };
10
- //#endregion
@@ -1,7 +0,0 @@
1
- //#region system/defaults/focus-rings.ts
2
- /**
3
- * 默认焦点环(对齐 Atelier 既有 Button 焦点色)。
4
- */
5
- const focusRings = { default: { value: "rgb(21 112 239 / 25%)" } };
6
- //#endregion
7
- export { focusRings };
@@ -1,13 +0,0 @@
1
- //#region system/defaults/font-sizes.d.ts
2
- /**
3
- * 默认字号。
4
- */
5
- export declare const fontSizes: {
6
- readonly md: {
7
- readonly value: "14px";
8
- };
9
- readonly lg: {
10
- readonly value: "16px";
11
- };
12
- };
13
- //#endregion
@@ -1,10 +0,0 @@
1
- //#region system/defaults/font-sizes.ts
2
- /**
3
- * 默认字号。
4
- */
5
- const fontSizes = {
6
- md: { value: "14px" },
7
- lg: { value: "16px" }
8
- };
9
- //#endregion
10
- export { fontSizes };