@omnific/atelier 0.1.0 → 0.3.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 (58) hide show
  1. package/README.md +10 -1
  2. package/dist/box/Box.d.ts +7 -0
  3. package/dist/box/Box.js +23 -0
  4. package/dist/box/constants.js +8 -0
  5. package/dist/box/index.d.ts +3 -0
  6. package/dist/box/index.js +2 -0
  7. package/dist/box/types.d.ts +24 -0
  8. package/dist/button/Button.js +1 -1
  9. package/dist/button/LoadingIcon.js +1 -1
  10. package/dist/main.d.ts +4 -1
  11. package/dist/main.js +2 -1
  12. package/dist/props/display.props.d.ts +10 -0
  13. package/dist/props/display.props.js +15 -0
  14. package/dist/props/flex.props.d.ts +58 -0
  15. package/dist/props/flex.props.js +72 -0
  16. package/dist/props/gap.props.d.ts +10 -0
  17. package/dist/props/gap.props.js +18 -0
  18. package/dist/props/height.props.d.ts +10 -0
  19. package/dist/props/height.props.js +27 -0
  20. package/dist/props/index.d.ts +95 -0
  21. package/dist/props/index.js +158 -0
  22. package/dist/props/justify.props.d.ts +34 -0
  23. package/dist/props/justify.props.js +43 -0
  24. package/dist/props/margin.props.d.ts +10 -0
  25. package/dist/props/margin.props.js +27 -0
  26. package/dist/props/overflow.props.d.ts +10 -0
  27. package/dist/props/overflow.props.js +13 -0
  28. package/dist/props/padding.props.d.ts +10 -0
  29. package/dist/props/padding.props.js +18 -0
  30. package/dist/props/position.props.d.ts +18 -0
  31. package/dist/props/position.props.js +38 -0
  32. package/dist/props/radius.props.d.ts +10 -0
  33. package/dist/props/radius.props.js +19 -0
  34. package/dist/props/scaling.props.d.ts +10 -0
  35. package/dist/props/shadow.props.d.ts +10 -0
  36. package/dist/props/shadow.props.js +16 -0
  37. package/dist/props/width.props.d.ts +10 -0
  38. package/dist/props/width.props.js +26 -0
  39. package/dist/styles.css +2432 -76
  40. package/dist/system/create-system.d.ts +14 -0
  41. package/dist/system/create-system.js +22 -0
  42. package/dist/system/css-vars.d.ts +17 -0
  43. package/dist/system/css-vars.js +56 -0
  44. package/dist/system/default-system.d.ts +11 -0
  45. package/dist/system/default-system.js +9 -0
  46. package/dist/system/defaults/colors.d.ts +254 -0
  47. package/dist/system/defaults/colors.js +94 -0
  48. package/dist/system/define-colors.d.ts +7 -0
  49. package/dist/system/define-colors.js +7 -0
  50. package/dist/system/index.d.ts +9 -0
  51. package/dist/system/index.js +8 -0
  52. package/dist/system/merge-colors.d.ts +10 -0
  53. package/dist/system/merge-colors.js +21 -0
  54. package/dist/system/types.d.ts +37 -0
  55. package/dist/system/use-theme.d.ts +11 -0
  56. package/dist/system/use-theme.js +20 -0
  57. package/dist/utils/extractProps.js +34 -0
  58. package/package.json +16 -7
@@ -0,0 +1,14 @@
1
+ import { ColorSet } from "./types.js";
2
+ //#region system/create-system.d.ts
3
+ /**
4
+ * 合并扁平颜色表并返回 system 实例。
5
+ *
6
+ * 第一个参数可以是主题名称,也可以直接传入扁平颜色表;
7
+ * 省略主题名称时使用 `default`。
8
+ */
9
+ export declare function createSystem(nameOrColors: string | ColorSet, ...colorSets: ColorSet[]): {
10
+ name: string;
11
+ colors: ColorSet;
12
+ cssVars: Readonly<Record<string, string>>;
13
+ };
14
+ //#endregion
@@ -0,0 +1,22 @@
1
+ import { mergeColors } from "./merge-colors.js";
2
+ import { isString } from "@omnific/utils";
3
+ //#region system/create-system.ts
4
+ const DEFAULT_SYSTEM_NAME = "default";
5
+ /**
6
+ * 合并扁平颜色表并返回 system 实例。
7
+ *
8
+ * 第一个参数可以是主题名称,也可以直接传入扁平颜色表;
9
+ * 省略主题名称时使用 `default`。
10
+ */
11
+ function createSystem(nameOrColors, ...colorSets) {
12
+ const name = isString(nameOrColors) ? nameOrColors : DEFAULT_SYSTEM_NAME;
13
+ const mergedColorSets = isString(nameOrColors) ? colorSets : [nameOrColors, ...colorSets];
14
+ const { colors, cssVars } = mergeColors(...mergedColorSets);
15
+ return {
16
+ name,
17
+ colors,
18
+ cssVars
19
+ };
20
+ }
21
+ //#endregion
22
+ export { createSystem };
@@ -0,0 +1,17 @@
1
+ import { SystemContext } from "./types.js";
2
+ //#region system/css-vars.d.ts
3
+ /**
4
+ * 将扁平语义颜色键转为 CSS 变量名。
5
+ *
6
+ * @example
7
+ * toColorVarName('accent-solid') // '--color-accent-solid'
8
+ */
9
+ export declare const toColorVarName: (key: string) => string;
10
+ /**
11
+ * 将 `system.cssVars` 写入文档级 `<style>`(挂在 `document.head` 下)。
12
+ *
13
+ * 以 `system.name` 为 key 复用节点。返回卸载函数。
14
+ * 目标节点设置 `data-atelier-theme={system.name}`。
15
+ */
16
+ export declare const applyCssVars: (system: SystemContext, target: HTMLElement) => () => void;
17
+ //#endregion
@@ -0,0 +1,56 @@
1
+ import { hasValue, isNil } from "@omnific/utils";
2
+ //#region system/css-vars.ts
3
+ /**
4
+ * 主题作用域属性;值为 `system.name`(含挂在 `documentElement` 上时)。
5
+ */
6
+ const THEME_ATTR = "data-atelier-theme";
7
+ const stylesByName = /* @__PURE__ */ new Map();
8
+ /**
9
+ * 将扁平语义颜色键转为 CSS 变量名。
10
+ *
11
+ * @example
12
+ * toColorVarName('accent-solid') // '--color-accent-solid'
13
+ */
14
+ const toColorVarName = (key) => {
15
+ return `--color-${key.replaceAll(".", "-")}`;
16
+ };
17
+ const toCssText = (system) => {
18
+ const lines = [];
19
+ for (const [name, value] of Object.entries(system.cssVars)) lines.push(` ${name}: ${value};`);
20
+ return `${`[${THEME_ATTR}="${CSS.escape(system.name)}"]`} {\n${lines.join("\n")}\n}`;
21
+ };
22
+ /**
23
+ * 将 `system.cssVars` 写入文档级 `<style>`(挂在 `document.head` 下)。
24
+ *
25
+ * 以 `system.name` 为 key 复用节点。返回卸载函数。
26
+ * 目标节点设置 `data-atelier-theme={system.name}`。
27
+ */
28
+ const applyCssVars = (system, target) => {
29
+ const { document: doc } = globalThis;
30
+ if (isNil(doc) || isNil(doc.head)) return () => {};
31
+ const { name } = system;
32
+ target.setAttribute(THEME_ATTR, name);
33
+ let entry = stylesByName.get(name);
34
+ if (hasValue(entry) && entry.style.isConnected) entry.count += 1;
35
+ else {
36
+ const style = doc.createElement("style");
37
+ style.dataset.atelierCssVars = "";
38
+ style.dataset.atelierSystem = name;
39
+ style.textContent = toCssText(system);
40
+ doc.head.append(style);
41
+ entry = {
42
+ style,
43
+ count: 1
44
+ };
45
+ stylesByName.set(name, entry);
46
+ }
47
+ return () => {
48
+ target.removeAttribute(THEME_ATTR);
49
+ entry.count -= 1;
50
+ if (entry.count > 0) return;
51
+ entry.style.remove();
52
+ stylesByName.delete(name);
53
+ };
54
+ };
55
+ //#endregion
56
+ export { applyCssVars, toColorVarName };
@@ -0,0 +1,11 @@
1
+ import { ColorSet } from "./types.js";
2
+ //#region system/default-system.d.ts
3
+ /**
4
+ * 基于 `defaultColors` 的共享默认 system(单例,可直接 `useTheme` / `applyCssVars`)。
5
+ */
6
+ export declare const defaultSystem: {
7
+ name: string;
8
+ colors: ColorSet;
9
+ cssVars: Readonly<Record<string, string>>;
10
+ };
11
+ //#endregion
@@ -0,0 +1,9 @@
1
+ import { createSystem } from "./create-system.js";
2
+ import { defaultColors } from "./defaults/colors.js";
3
+ //#region system/default-system.ts
4
+ /**
5
+ * 基于 `defaultColors` 的共享默认 system(单例,可直接 `useTheme` / `applyCssVars`)。
6
+ */
7
+ const defaultSystem = createSystem(defaultColors);
8
+ //#endregion
9
+ export { defaultSystem };
@@ -0,0 +1,254 @@
1
+ //#region system/defaults/colors.d.ts
2
+ /**
3
+ * 默认语义颜色。
4
+ *
5
+ * 颜色键使用扁平 kebab-case 语义名,运行时统一映射为 `--color-*`。
6
+ */
7
+ export declare const defaultColors: {
8
+ readonly bg: {
9
+ readonly value: "#ffffff";
10
+ };
11
+ readonly 'bg-subtle': {
12
+ readonly value: "#fafafa";
13
+ };
14
+ readonly 'bg-muted': {
15
+ readonly value: "#f4f4f5";
16
+ };
17
+ readonly 'bg-emphasized': {
18
+ readonly value: "#e4e4e7";
19
+ };
20
+ readonly 'bg-inverted': {
21
+ readonly value: "#09090b";
22
+ };
23
+ readonly 'bg-panel': {
24
+ readonly value: "#ffffff";
25
+ };
26
+ readonly 'bg-disabled': {
27
+ readonly value: "rgb(239 239 239)";
28
+ };
29
+ readonly 'bg-danger': {
30
+ readonly value: "#fef2f2";
31
+ };
32
+ readonly 'bg-warning': {
33
+ readonly value: "#fff7ed";
34
+ };
35
+ readonly 'bg-success': {
36
+ readonly value: "#f0fdf4";
37
+ };
38
+ readonly 'bg-info': {
39
+ readonly value: "#e6f4ff";
40
+ };
41
+ readonly fg: {
42
+ readonly value: "rgb(0 0 0 / 88%)";
43
+ };
44
+ readonly 'fg-muted': {
45
+ readonly value: "rgb(0 0 0 / 45%)";
46
+ };
47
+ readonly 'fg-subtle': {
48
+ readonly value: "rgb(0 0 0 / 25%)";
49
+ };
50
+ readonly 'fg-inverted': {
51
+ readonly value: "#ffffff";
52
+ };
53
+ readonly 'fg-disabled': {
54
+ readonly value: "rgb(0 0 0 / 25%)";
55
+ };
56
+ readonly 'fg-danger': {
57
+ readonly value: "#ff4d4f";
58
+ };
59
+ readonly 'fg-warning': {
60
+ readonly value: "#faad14";
61
+ };
62
+ readonly 'fg-success': {
63
+ readonly value: "#52c41a";
64
+ };
65
+ readonly 'fg-info': {
66
+ readonly value: "#1677ff";
67
+ };
68
+ readonly border: {
69
+ readonly value: "#d9d9d9";
70
+ };
71
+ readonly 'border-muted': {
72
+ readonly value: "#f0f0f0";
73
+ };
74
+ readonly 'border-subtle': {
75
+ readonly value: "#fafafa";
76
+ };
77
+ readonly 'border-emphasized': {
78
+ readonly value: "#d9d9d9";
79
+ };
80
+ readonly 'border-inverted': {
81
+ readonly value: "#434343";
82
+ };
83
+ readonly 'border-danger': {
84
+ readonly value: "#ff4d4f";
85
+ };
86
+ readonly 'border-warning': {
87
+ readonly value: "#faad14";
88
+ };
89
+ readonly 'border-success': {
90
+ readonly value: "#52c41a";
91
+ };
92
+ readonly 'border-info': {
93
+ readonly value: "#1677ff";
94
+ };
95
+ readonly 'accent-contrast': {
96
+ readonly value: "#ffffff";
97
+ };
98
+ readonly 'accent-fg': {
99
+ readonly value: "#1677ff";
100
+ };
101
+ readonly 'accent-subtle': {
102
+ readonly value: "#e6f4ff";
103
+ };
104
+ readonly 'accent-muted': {
105
+ readonly value: "#bae0ff";
106
+ };
107
+ readonly 'accent-emphasized': {
108
+ readonly value: "#69b1ff";
109
+ };
110
+ readonly 'accent-solid': {
111
+ readonly value: "#1677ff";
112
+ };
113
+ readonly 'accent-hover': {
114
+ readonly value: "#4096ff";
115
+ };
116
+ readonly 'accent-active': {
117
+ readonly value: "#0958d9";
118
+ };
119
+ readonly 'accent-focus-ring': {
120
+ readonly value: "rgb(21 112 239 / 25%)";
121
+ };
122
+ readonly 'accent-border': {
123
+ readonly value: "#1677ff";
124
+ };
125
+ readonly 'danger-contrast': {
126
+ readonly value: "#ffffff";
127
+ };
128
+ readonly 'danger-fg': {
129
+ readonly value: "#ff4d4f";
130
+ };
131
+ readonly 'danger-subtle': {
132
+ readonly value: "#fff1f0";
133
+ };
134
+ readonly 'danger-muted': {
135
+ readonly value: "#ffccc7";
136
+ };
137
+ readonly 'danger-emphasized': {
138
+ readonly value: "#ffa39e";
139
+ };
140
+ readonly 'danger-solid': {
141
+ readonly value: "#ff4d4f";
142
+ };
143
+ readonly 'danger-hover': {
144
+ readonly value: "#ff7875";
145
+ };
146
+ readonly 'danger-active': {
147
+ readonly value: "#d9363e";
148
+ };
149
+ readonly 'danger-focus-ring': {
150
+ readonly value: "rgb(255 77 79 / 25%)";
151
+ };
152
+ readonly 'danger-border': {
153
+ readonly value: "#ff4d4f";
154
+ };
155
+ readonly 'warning-contrast': {
156
+ readonly value: "#ffffff";
157
+ };
158
+ readonly 'warning-fg': {
159
+ readonly value: "#faad14";
160
+ };
161
+ readonly 'warning-subtle': {
162
+ readonly value: "#fff7ed";
163
+ };
164
+ readonly 'warning-muted': {
165
+ readonly value: "#ffe7ba";
166
+ };
167
+ readonly 'warning-emphasized': {
168
+ readonly value: "#ffd666";
169
+ };
170
+ readonly 'warning-solid': {
171
+ readonly value: "#faad14";
172
+ };
173
+ readonly 'warning-hover': {
174
+ readonly value: "#ffc53d";
175
+ };
176
+ readonly 'warning-active': {
177
+ readonly value: "#d48806";
178
+ };
179
+ readonly 'warning-focus-ring': {
180
+ readonly value: "rgb(250 173 20 / 25%)";
181
+ };
182
+ readonly 'warning-border': {
183
+ readonly value: "#faad14";
184
+ };
185
+ readonly 'success-contrast': {
186
+ readonly value: "#ffffff";
187
+ };
188
+ readonly 'success-fg': {
189
+ readonly value: "#52c41a";
190
+ };
191
+ readonly 'success-subtle': {
192
+ readonly value: "#f0fdf4";
193
+ };
194
+ readonly 'success-muted': {
195
+ readonly value: "#b7eb8f";
196
+ };
197
+ readonly 'success-emphasized': {
198
+ readonly value: "#95de64";
199
+ };
200
+ readonly 'success-solid': {
201
+ readonly value: "#52c41a";
202
+ };
203
+ readonly 'success-hover': {
204
+ readonly value: "#73d13d";
205
+ };
206
+ readonly 'success-active': {
207
+ readonly value: "#389e0d";
208
+ };
209
+ readonly 'success-focus-ring': {
210
+ readonly value: "rgb(82 196 26 / 25%)";
211
+ };
212
+ readonly 'success-border': {
213
+ readonly value: "#52c41a";
214
+ };
215
+ readonly 'info-contrast': {
216
+ readonly value: "#ffffff";
217
+ };
218
+ readonly 'info-fg': {
219
+ readonly value: "#1677ff";
220
+ };
221
+ readonly 'info-subtle': {
222
+ readonly value: "#e6f4ff";
223
+ };
224
+ readonly 'info-muted': {
225
+ readonly value: "#bae0ff";
226
+ };
227
+ readonly 'info-emphasized': {
228
+ readonly value: "#69b1ff";
229
+ };
230
+ readonly 'info-solid': {
231
+ readonly value: "#1677ff";
232
+ };
233
+ readonly 'info-hover': {
234
+ readonly value: "#4096ff";
235
+ };
236
+ readonly 'info-active': {
237
+ readonly value: "#0958d9";
238
+ };
239
+ readonly 'info-focus-ring': {
240
+ readonly value: "rgb(21 112 239 / 25%)";
241
+ };
242
+ readonly 'info-border': {
243
+ readonly value: "#1677ff";
244
+ };
245
+ };
246
+ /**
247
+ * 默认颜色键列表。
248
+ */
249
+ export declare const defaultColorKeys: Array<keyof typeof defaultColors>;
250
+ /**
251
+ * 默认颜色键类型。
252
+ */
253
+ export type DefaultColorKey = (typeof defaultColorKeys)[number];
254
+ //#endregion
@@ -0,0 +1,94 @@
1
+ import { defineColors } from "../define-colors.js";
2
+ //#region system/defaults/colors.ts
3
+ /**
4
+ * 默认语义颜色。
5
+ *
6
+ * 颜色键使用扁平 kebab-case 语义名,运行时统一映射为 `--color-*`。
7
+ */
8
+ const defaultColors = defineColors({
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-danger": { 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-danger": { 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-danger": { value: "#ff4d4f" },
35
+ "border-warning": { value: "#faad14" },
36
+ "border-success": { value: "#52c41a" },
37
+ "border-info": { value: "#1677ff" },
38
+ "accent-contrast": { value: "#ffffff" },
39
+ "accent-fg": { value: "#1677ff" },
40
+ "accent-subtle": { value: "#e6f4ff" },
41
+ "accent-muted": { value: "#bae0ff" },
42
+ "accent-emphasized": { value: "#69b1ff" },
43
+ "accent-solid": { value: "#1677ff" },
44
+ "accent-hover": { value: "#4096ff" },
45
+ "accent-active": { value: "#0958d9" },
46
+ "accent-focus-ring": { value: "rgb(21 112 239 / 25%)" },
47
+ "accent-border": { value: "#1677ff" },
48
+ "danger-contrast": { value: "#ffffff" },
49
+ "danger-fg": { value: "#ff4d4f" },
50
+ "danger-subtle": { value: "#fff1f0" },
51
+ "danger-muted": { value: "#ffccc7" },
52
+ "danger-emphasized": { value: "#ffa39e" },
53
+ "danger-solid": { value: "#ff4d4f" },
54
+ "danger-hover": { value: "#ff7875" },
55
+ "danger-active": { value: "#d9363e" },
56
+ "danger-focus-ring": { value: "rgb(255 77 79 / 25%)" },
57
+ "danger-border": { value: "#ff4d4f" },
58
+ "warning-contrast": { value: "#ffffff" },
59
+ "warning-fg": { value: "#faad14" },
60
+ "warning-subtle": { value: "#fff7ed" },
61
+ "warning-muted": { value: "#ffe7ba" },
62
+ "warning-emphasized": { value: "#ffd666" },
63
+ "warning-solid": { value: "#faad14" },
64
+ "warning-hover": { value: "#ffc53d" },
65
+ "warning-active": { value: "#d48806" },
66
+ "warning-focus-ring": { value: "rgb(250 173 20 / 25%)" },
67
+ "warning-border": { value: "#faad14" },
68
+ "success-contrast": { value: "#ffffff" },
69
+ "success-fg": { value: "#52c41a" },
70
+ "success-subtle": { value: "#f0fdf4" },
71
+ "success-muted": { value: "#b7eb8f" },
72
+ "success-emphasized": { value: "#95de64" },
73
+ "success-solid": { value: "#52c41a" },
74
+ "success-hover": { value: "#73d13d" },
75
+ "success-active": { value: "#389e0d" },
76
+ "success-focus-ring": { value: "rgb(82 196 26 / 25%)" },
77
+ "success-border": { value: "#52c41a" },
78
+ "info-contrast": { value: "#ffffff" },
79
+ "info-fg": { value: "#1677ff" },
80
+ "info-subtle": { value: "#e6f4ff" },
81
+ "info-muted": { value: "#bae0ff" },
82
+ "info-emphasized": { value: "#69b1ff" },
83
+ "info-solid": { value: "#1677ff" },
84
+ "info-hover": { value: "#4096ff" },
85
+ "info-active": { value: "#0958d9" },
86
+ "info-focus-ring": { value: "rgb(21 112 239 / 25%)" },
87
+ "info-border": { value: "#1677ff" }
88
+ });
89
+ /**
90
+ * 默认颜色键列表。
91
+ */
92
+ const defaultColorKeys = Object.keys(defaultColors);
93
+ //#endregion
94
+ export { defaultColorKeys, 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,9 @@
1
+ import { DefaultColorKey, defaultColorKeys, defaultColors } from "./defaults/colors.js";
2
+ import { ColorSet, ColorValue, SystemContext } from "./types.js";
3
+ import { applyCssVars, toColorVarName } from "./css-vars.js";
4
+ import { createSystem } from "./create-system.js";
5
+ import { defaultSystem } from "./default-system.js";
6
+ import { defineColors } from "./define-colors.js";
7
+ import { mergeColors } from "./merge-colors.js";
8
+ import { useTheme } from "./use-theme.js";
9
+ export { type ColorSet, type ColorValue, type DefaultColorKey, type SystemContext, applyCssVars, createSystem, defaultColorKeys, defaultColors, defaultSystem, defineColors, mergeColors, toColorVarName, useTheme };
@@ -0,0 +1,8 @@
1
+ import { applyCssVars, toColorVarName } from "./css-vars.js";
2
+ import { mergeColors } from "./merge-colors.js";
3
+ import { createSystem } from "./create-system.js";
4
+ import { defineColors } from "./define-colors.js";
5
+ import { defaultColorKeys, defaultColors } from "./defaults/colors.js";
6
+ import { defaultSystem } from "./default-system.js";
7
+ import { useTheme } from "./use-theme.js";
8
+ export { applyCssVars, createSystem, defaultColorKeys, defaultColors, defaultSystem, defineColors, mergeColors, toColorVarName, useTheme };
@@ -0,0 +1,10 @@
1
+ import { ColorSet } from "./types.js";
2
+ //#region system/merge-colors.d.ts
3
+ /**
4
+ * 按传入顺序浅合并扁平颜色表,后写入覆盖同名键,并生成颜色 CSS 变量。
5
+ */
6
+ export declare const mergeColors: (...colorSets: ColorSet[]) => {
7
+ colors: ColorSet;
8
+ cssVars: Readonly<Record<string, string>>;
9
+ };
10
+ //#endregion
@@ -0,0 +1,21 @@
1
+ import { toColorVarName } from "./css-vars.js";
2
+ import { isNil } from "@omnific/utils";
3
+ //#region system/merge-colors.ts
4
+ /**
5
+ * 按传入顺序浅合并扁平颜色表,后写入覆盖同名键,并生成颜色 CSS 变量。
6
+ */
7
+ const mergeColors = (...colorSets) => {
8
+ const colors = {};
9
+ const cssVars = {};
10
+ for (const next of colorSets) for (const [key, node] of Object.entries(next)) {
11
+ if (isNil(node)) continue;
12
+ colors[key] = node;
13
+ cssVars[toColorVarName(key)] = node.value;
14
+ }
15
+ return {
16
+ colors,
17
+ cssVars: Object.freeze(cssVars)
18
+ };
19
+ };
20
+ //#endregion
21
+ export { mergeColors };
@@ -0,0 +1,37 @@
1
+ //#region system/types.d.ts
2
+ /**
3
+ * 单个颜色值节点。
4
+ */
5
+ export type ColorValue = {
6
+ /**
7
+ * CSS 颜色值。
8
+ */
9
+ value: string;
10
+ };
11
+ /**
12
+ * 扁平语义颜色表。
13
+ *
14
+ * 只约束值的结构,不枚举颜色键。
15
+ * 具体颜色键由 `defineColors` 或 `defaultColors` 自动推导。
16
+ */
17
+ export type ColorSet = Record<string, ColorValue>;
18
+ /**
19
+ * applyCssVars / useTheme 的参数契约。
20
+ *
21
+ * 不是 createSystem 的返回值类型来源;返回值仍由 createSystem 自动推导。
22
+ */
23
+ export type SystemContext = {
24
+ /**
25
+ * 主题名称;同名 system 在注入时复用同一张 `<style>`。
26
+ */
27
+ name: string;
28
+ /**
29
+ * 合并后的扁平颜色表。
30
+ */
31
+ colors: ColorSet;
32
+ /**
33
+ * 已缓存的颜色 CSS 变量表。
34
+ */
35
+ cssVars: Readonly<Record<string, string>>;
36
+ };
37
+ //#endregion
@@ -0,0 +1,11 @@
1
+ import { SystemContext } from "./types.js";
2
+ //#region system/use-theme.d.ts
3
+ /**
4
+ * 将 system 的颜色 CSS 变量运行时注入到 DOM。
5
+ *
6
+ * 返回对象 ref:
7
+ * - 挂到元素上时,给该节点打上 `data-atelier-theme={system.name}`;
8
+ * - 未挂载时,变量写在 `document.documentElement`。
9
+ */
10
+ export declare const useTheme: <TElement extends HTMLElement = HTMLElement>(system: SystemContext) => import("react").RefObject<TElement | null>;
11
+ //#endregion
@@ -0,0 +1,20 @@
1
+ import { applyCssVars } from "./css-vars.js";
2
+ import { useLayoutEffect, useRef } from "react";
3
+ //#region system/use-theme.ts
4
+ /**
5
+ * 将 system 的颜色 CSS 变量运行时注入到 DOM。
6
+ *
7
+ * 返回对象 ref:
8
+ * - 挂到元素上时,给该节点打上 `data-atelier-theme={system.name}`;
9
+ * - 未挂载时,变量写在 `document.documentElement`。
10
+ */
11
+ const useTheme = (system) => {
12
+ const ref = useRef(null);
13
+ useLayoutEffect(() => {
14
+ const target = ref.current ?? document.documentElement;
15
+ return applyCssVars(system, target);
16
+ }, [system]);
17
+ return ref;
18
+ };
19
+ //#endregion
20
+ export { useTheme };
@@ -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 };