@reqvire-org/ads 0.3.46 → 0.3.47

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 (110) hide show
  1. package/README.md +21 -11
  2. package/dist/a11y.mjs +4 -2
  3. package/dist/assets.mjs +20 -15
  4. package/dist/atomic-composition.mjs +3 -2
  5. package/dist/brand-assets.mjs +48 -11
  6. package/dist/brands.mjs +82 -0
  7. package/dist/browser-audit/worker.mjs +45 -0
  8. package/dist/browser-audit.mjs +117 -0
  9. package/dist/capture/worker.mjs +1 -0
  10. package/dist/capture-store.mjs +2 -0
  11. package/dist/capture.mjs +7 -4
  12. package/dist/check.mjs +38 -8
  13. package/dist/cli.mjs +45 -10
  14. package/dist/color-values.mjs +325 -0
  15. package/dist/config.mjs +16 -2
  16. package/dist/control-padding.mjs +93 -0
  17. package/dist/design-values.mjs +3 -2
  18. package/dist/finding-rules.mjs +61 -0
  19. package/dist/foundation.mjs +17 -4
  20. package/dist/icons.mjs +107 -0
  21. package/dist/init.mjs +3 -0
  22. package/dist/mcp/apps.mjs +9 -6
  23. package/dist/mcp/drafts.mjs +3 -0
  24. package/dist/mcp/mutations.mjs +17 -1
  25. package/dist/mcp/preview-widget.bundle.js +36 -36
  26. package/dist/mcp/project-widget.bundle.js +12 -12
  27. package/dist/mcp/server.mjs +21 -9
  28. package/dist/mcp/widget.bundle.js +17 -17
  29. package/dist/palette-generated.mjs +180 -0
  30. package/dist/preview-resources.mjs +12 -3
  31. package/dist/render-color-probe.mjs +148 -0
  32. package/dist/runtime-contracts.mjs +14 -4
  33. package/dist/scenarios.mjs +1 -1
  34. package/dist/showcase/client.bundle.js +28 -28
  35. package/dist/showcase/icons.js +146 -0
  36. package/dist/showcase/index.html +2 -1
  37. package/dist/showcase/style.css +19 -2
  38. package/dist/skills/README.md +2 -1
  39. package/dist/skills/ads-break-ui/SKILL.md +6 -5
  40. package/dist/skills/ads-break-ui/references/atomic-styles.md +12 -12
  41. package/dist/skills/ads-break-ui/references/contracts.md +13 -10
  42. package/dist/skills/ads-break-ui/references/design-data.md +137 -29
  43. package/dist/skills/ads-break-ui/references/validation.md +8 -4
  44. package/dist/skills/ads-designer/SKILL.md +23 -16
  45. package/dist/skills/ads-designer/references/accessibility.md +39 -5
  46. package/dist/skills/ads-designer/references/atomic-styles.md +12 -12
  47. package/dist/skills/ads-designer/references/branding.md +37 -10
  48. package/dist/skills/ads-designer/references/cli.md +8 -2
  49. package/dist/skills/ads-designer/references/contracts.md +13 -10
  50. package/dist/skills/ads-designer/references/design-data.md +137 -29
  51. package/dist/skills/ads-designer/references/validation.md +8 -4
  52. package/dist/skills/ads-import/SKILL.md +9 -8
  53. package/dist/skills/ads-import/references/atomic-styles.md +12 -12
  54. package/dist/skills/ads-import/references/cli.md +8 -2
  55. package/dist/skills/ads-import/references/contracts.md +13 -10
  56. package/dist/skills/ads-import/references/design-data.md +137 -29
  57. package/dist/skills/ads-import/references/tokens.md +7 -3
  58. package/dist/skills/ads-import/references/validation.md +8 -4
  59. package/dist/skills/ads-motion/SKILL.md +6 -5
  60. package/dist/skills/ads-motion/references/atomic-styles.md +12 -12
  61. package/dist/skills/ads-motion/references/contracts.md +13 -10
  62. package/dist/skills/ads-motion/references/design-data.md +137 -29
  63. package/dist/skills/ads-motion/references/validation.md +8 -4
  64. package/dist/skills/ads-port/SKILL.md +6 -5
  65. package/dist/skills/ads-port/references/atomic-styles.md +12 -12
  66. package/dist/skills/ads-port/references/cli.md +8 -2
  67. package/dist/skills/ads-port/references/contracts.md +13 -10
  68. package/dist/skills/ads-port/references/design-data.md +137 -29
  69. package/dist/skills/ads-port/references/validation.md +8 -4
  70. package/dist/starters/preact/design-system/review/token-preview/TokenPreview.tsx +11 -2
  71. package/dist/starters/react/ADS.md +43 -10
  72. package/dist/starters/react/README.md +14 -9
  73. package/dist/starters/react/design-system/assets/brand/README.md +8 -3
  74. package/dist/starters/react/design-system/assets/glyphs/README.md +4 -1
  75. package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.fixture.ts +6 -1
  76. package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.scenario.tsx +3 -2
  77. package/dist/starters/react/design-system/components/Content/Icon/README.md +2 -1
  78. package/dist/starters/react/design-system/components/Content/Logo/Logo.tsx +3 -9
  79. package/dist/starters/react/design-system/components/Content/Logo/README.md +4 -2
  80. package/dist/starters/react/design-system/controllers/Palette/Palette.ts +164 -0
  81. package/dist/starters/react/design-system/index.ts +3 -0
  82. package/dist/starters/react/design-system/review/brand-preview/BrandPreview.tsx +2 -5
  83. package/dist/starters/react/design-system/review/token-preview/TokenPreview.tsx +11 -2
  84. package/dist/starters/react/design-system/styles.css +1 -0
  85. package/dist/starters/react/design-system/tokens/base.css +8 -5
  86. package/dist/starters/react/design-system/tokens/colors.css +167 -175
  87. package/dist/starters/react/design-system/tokens/elevation.css +14 -21
  88. package/dist/starters/react/design-system/tokens/themes.generated.css +142 -0
  89. package/dist/starters/react/design-system/tokens/themes.generated.ts +402 -0
  90. package/dist/style-boundaries.mjs +2 -1
  91. package/dist/themes-generated.mjs +150 -0
  92. package/dist/themes-watch.mjs +42 -0
  93. package/dist/themes.mjs +214 -63
  94. package/dist/token-export.mjs +22 -11
  95. package/dist/token-policy.mjs +2 -1
  96. package/dist/token-quality.mjs +28 -25
  97. package/dist/tokens.mjs +27 -32
  98. package/dist/validation.mjs +18 -1
  99. package/dist/verification/browser.mjs +14 -3
  100. package/docs/ADS.md +41 -27
  101. package/docs/ARCHITECTURE.md +49 -22
  102. package/docs/CACHING.md +2 -3
  103. package/docs/CHANGELOG.md +97 -13
  104. package/docs/CONTRACTS.md +13 -10
  105. package/docs/GUIDE.md +89 -21
  106. package/docs/MCP.md +35 -25
  107. package/docs/benchmarks/bun-previews.md +5 -5
  108. package/docs/benchmarks/{gidi-preview-memory.md → preview-memory.md} +14 -12
  109. package/docs/benchmarks/turbo-poc.md +24 -6
  110. package/package.json +2 -1
@@ -0,0 +1,402 @@
1
+ /* Generated by ADS from the token sheets' per-theme halves and ds.config.json themes and brands.
2
+ The showcase and MCP server rewrite it when they change; do not edit it. */
3
+
4
+ /** A palette context: a theme of the default brand, or <brand>/<theme> for another brand. */
5
+ export type PaletteContext =
6
+ | "light"
7
+ | "dark";
8
+ /** A shared token whose value is a color in every context. */
9
+ export type ColorToken =
10
+ | "--accent"
11
+ | "--accent-fg"
12
+ | "--accent-hover"
13
+ | "--accent-subtle"
14
+ | "--accent-text"
15
+ | "--bg-active"
16
+ | "--bg-canvas"
17
+ | "--bg-disabled"
18
+ | "--bg-field"
19
+ | "--bg-hover"
20
+ | "--bg-overlay"
21
+ | "--bg-raised"
22
+ | "--bg-selected"
23
+ | "--bg-skeleton"
24
+ | "--bg-surface"
25
+ | "--border-default"
26
+ | "--border-disabled"
27
+ | "--border-focus"
28
+ | "--border-strong"
29
+ | "--border-subtle"
30
+ | "--color-accent-1"
31
+ | "--color-accent-2"
32
+ | "--color-accent-3"
33
+ | "--color-accent-4"
34
+ | "--color-accent-5"
35
+ | "--color-accent-6"
36
+ | "--color-accent-7"
37
+ | "--color-accent-8"
38
+ | "--color-accent-9"
39
+ | "--color-accent-10"
40
+ | "--color-accent-11"
41
+ | "--color-accent-12"
42
+ | "--color-amber-1"
43
+ | "--color-amber-2"
44
+ | "--color-amber-3"
45
+ | "--color-amber-4"
46
+ | "--color-amber-5"
47
+ | "--color-amber-6"
48
+ | "--color-amber-7"
49
+ | "--color-amber-8"
50
+ | "--color-amber-9"
51
+ | "--color-amber-10"
52
+ | "--color-amber-11"
53
+ | "--color-amber-12"
54
+ | "--color-blue-1"
55
+ | "--color-blue-2"
56
+ | "--color-blue-3"
57
+ | "--color-blue-4"
58
+ | "--color-blue-5"
59
+ | "--color-blue-6"
60
+ | "--color-blue-7"
61
+ | "--color-blue-8"
62
+ | "--color-blue-9"
63
+ | "--color-blue-10"
64
+ | "--color-blue-11"
65
+ | "--color-blue-12"
66
+ | "--color-green-1"
67
+ | "--color-green-2"
68
+ | "--color-green-3"
69
+ | "--color-green-4"
70
+ | "--color-green-5"
71
+ | "--color-green-6"
72
+ | "--color-green-7"
73
+ | "--color-green-8"
74
+ | "--color-green-9"
75
+ | "--color-green-10"
76
+ | "--color-green-11"
77
+ | "--color-green-12"
78
+ | "--color-red-1"
79
+ | "--color-red-2"
80
+ | "--color-red-3"
81
+ | "--color-red-4"
82
+ | "--color-red-5"
83
+ | "--color-red-6"
84
+ | "--color-red-7"
85
+ | "--color-red-8"
86
+ | "--color-red-9"
87
+ | "--color-red-10"
88
+ | "--color-red-11"
89
+ | "--color-red-12"
90
+ | "--danger"
91
+ | "--danger-bg"
92
+ | "--danger-border"
93
+ | "--danger-fg"
94
+ | "--danger-text"
95
+ | "--info"
96
+ | "--info-bg"
97
+ | "--info-border"
98
+ | "--info-fg"
99
+ | "--info-text"
100
+ | "--slate-1"
101
+ | "--slate-2"
102
+ | "--slate-3"
103
+ | "--slate-4"
104
+ | "--slate-5"
105
+ | "--slate-6"
106
+ | "--slate-7"
107
+ | "--slate-8"
108
+ | "--slate-9"
109
+ | "--slate-10"
110
+ | "--slate-11"
111
+ | "--slate-12"
112
+ | "--success"
113
+ | "--success-bg"
114
+ | "--success-border"
115
+ | "--success-fg"
116
+ | "--success-text"
117
+ | "--text-body"
118
+ | "--text-disabled"
119
+ | "--text-inverse"
120
+ | "--text-link"
121
+ | "--text-muted"
122
+ | "--text-strong"
123
+ | "--warning"
124
+ | "--warning-bg"
125
+ | "--warning-border"
126
+ | "--warning-fg"
127
+ | "--warning-text";
128
+ /** A resolved color: its canonical CSS string and sRGB channels 0–255 with alpha 0–1. */
129
+ export interface PaletteColor { readonly css: string; readonly rgba: readonly [r: number, g: number, b: number, a: number] }
130
+ /** Every color token of one context. */
131
+ export type Palette = { readonly [token in ColorToken]: PaletteColor };
132
+
133
+ export const themes = ["light", "dark"] as const;
134
+ export const brands = [] as const;
135
+ export const contexts = ["light", "dark"] as const satisfies readonly PaletteContext[];
136
+ export const defaultContext: PaletteContext = "light";
137
+ /** The theme each OS color scheme selects on a root without data-theme (followSystemTheme), or null. */
138
+ export const systemThemes: { readonly light: (typeof themes)[number]; readonly dark: (typeof themes)[number] } | null = null;
139
+
140
+ /** A declared theme. */
141
+ export type Theme = (typeof themes)[number];
142
+ /** Each declared theme's color scheme. */
143
+ export const themeSchemes = { light: "light", dark: "dark" } as const satisfies { readonly [theme in Theme]: "light" | "dark" };
144
+
145
+ /** A runtime value per declared theme (complete CSS values, such as colors from data) as one
146
+ * expression that follows the nearest data-theme, like a token's halves. Use it for inline
147
+ * styles and inline custom properties; never light-dark(). */
148
+ export function themed(values: { readonly [theme in Theme]: string }): string {
149
+ return `var(--ads-if-light, ${values.light})var(--ads-if-dark, ${values.dark})`;
150
+ }
151
+
152
+ /** themed() from a light and a dark value: each declared theme takes the value of its color scheme. */
153
+ export function themedByScheme(values: { readonly light: string; readonly dark: string }): string {
154
+ return `var(--ads-if-light, ${values.light})var(--ads-if-dark, ${values.dark})`;
155
+ }
156
+
157
+ export const palette = {
158
+ "light": {
159
+ "--accent": { css: "#c90a44", rgba: [201, 10, 68, 1] },
160
+ "--accent-fg": { css: "#fdfdfe", rgba: [253, 253, 254, 1] },
161
+ "--accent-hover": { css: "#b7013c", rgba: [183, 1, 60, 1] },
162
+ "--accent-subtle": { css: "#feeced", rgba: [254, 236, 237, 1] },
163
+ "--accent-text": { css: "#a31d3b", rgba: [163, 29, 59, 1] },
164
+ "--bg-active": { css: "#e6eaf1", rgba: [230, 234, 241, 1] },
165
+ "--bg-canvas": { css: "#f7f9fd", rgba: [247, 249, 253, 1] },
166
+ "--bg-disabled": { css: "#eef1f7", rgba: [238, 241, 247, 1] },
167
+ "--bg-field": { css: "#fdfdfe", rgba: [253, 253, 254, 1] },
168
+ "--bg-hover": { css: "#eef1f7", rgba: [238, 241, 247, 1] },
169
+ "--bg-overlay": { css: "rgba(16, 24, 40, 0.45)", rgba: [16, 24, 40, 0.45] },
170
+ "--bg-raised": { css: "#fdfdfe", rgba: [253, 253, 254, 1] },
171
+ "--bg-selected": { css: "#feeced", rgba: [254, 236, 237, 1] },
172
+ "--bg-skeleton": { css: "#e6eaf1", rgba: [230, 234, 241, 1] },
173
+ "--bg-surface": { css: "#fdfdfe", rgba: [253, 253, 254, 1] },
174
+ "--border-default": { css: "#d4d9e2", rgba: [212, 217, 226, 1] },
175
+ "--border-disabled": { css: "#dde2ea", rgba: [221, 226, 234, 1] },
176
+ "--border-focus": { css: "#c90a44", rgba: [201, 10, 68, 1] },
177
+ "--border-strong": { css: "#868d97", rgba: [134, 141, 151, 1] },
178
+ "--border-subtle": { css: "#dde2ea", rgba: [221, 226, 234, 1] },
179
+ "--color-accent-1": { css: "#fefdfd", rgba: [254, 253, 253, 1] },
180
+ "--color-accent-2": { css: "#fef7f7", rgba: [254, 247, 247, 1] },
181
+ "--color-accent-3": { css: "#feeced", rgba: [254, 236, 237, 1] },
182
+ "--color-accent-4": { css: "#ffe2e3", rgba: [255, 226, 227, 1] },
183
+ "--color-accent-5": { css: "#ffd6d8", rgba: [255, 214, 216, 1] },
184
+ "--color-accent-6": { css: "#fec9cc", rgba: [254, 201, 204, 1] },
185
+ "--color-accent-7": { css: "#ffb6ba", rgba: [255, 182, 186, 1] },
186
+ "--color-accent-8": { css: "#fe949d", rgba: [254, 148, 157, 1] },
187
+ "--color-accent-9": { css: "#c90a44", rgba: [201, 10, 68, 1] },
188
+ "--color-accent-10": { css: "#b7013c", rgba: [183, 1, 60, 1] },
189
+ "--color-accent-11": { css: "#a31d3b", rgba: [163, 29, 59, 1] },
190
+ "--color-accent-12": { css: "#440312", rgba: [68, 3, 18, 1] },
191
+ "--color-amber-1": { css: "#fefdfc", rgba: [254, 253, 252, 1] },
192
+ "--color-amber-2": { css: "#fef8f0", rgba: [254, 248, 240, 1] },
193
+ "--color-amber-3": { css: "#feefdb", rgba: [254, 239, 219, 1] },
194
+ "--color-amber-4": { css: "#fbe6cb", rgba: [251, 230, 203, 1] },
195
+ "--color-amber-5": { css: "#f8debb", rgba: [248, 222, 187, 1] },
196
+ "--color-amber-6": { css: "#f4d3a7", rgba: [244, 211, 167, 1] },
197
+ "--color-amber-7": { css: "#edc58d", rgba: [237, 197, 141, 1] },
198
+ "--color-amber-8": { css: "#e7b369", rgba: [231, 179, 105, 1] },
199
+ "--color-amber-9": { css: "#fcab05", rgba: [252, 171, 5, 1] },
200
+ "--color-amber-10": { css: "#eba005", rgba: [235, 160, 5, 1] },
201
+ "--color-amber-11": { css: "#865900", rgba: [134, 89, 0, 1] },
202
+ "--color-amber-12": { css: "#402800", rgba: [64, 40, 0, 1] },
203
+ "--color-blue-1": { css: "#fdfdfe", rgba: [253, 253, 254, 1] },
204
+ "--color-blue-2": { css: "#f6f9ff", rgba: [246, 249, 255, 1] },
205
+ "--color-blue-3": { css: "#e9f2fe", rgba: [233, 242, 254, 1] },
206
+ "--color-blue-4": { css: "#dcebff", rgba: [220, 235, 255, 1] },
207
+ "--color-blue-5": { css: "#d0e4fe", rgba: [208, 228, 254, 1] },
208
+ "--color-blue-6": { css: "#c1dbfe", rgba: [193, 219, 254, 1] },
209
+ "--color-blue-7": { css: "#aacfff", rgba: [170, 207, 255, 1] },
210
+ "--color-blue-8": { css: "#85baff", rgba: [133, 186, 255, 1] },
211
+ "--color-blue-9": { css: "#006bd0", rgba: [0, 107, 208, 1] },
212
+ "--color-blue-10": { css: "#0060bb", rgba: [0, 96, 187, 1] },
213
+ "--color-blue-11": { css: "#115aa9", rgba: [17, 90, 169, 1] },
214
+ "--color-blue-12": { css: "#012147", rgba: [1, 33, 71, 1] },
215
+ "--color-green-1": { css: "#fbfffb", rgba: [251, 255, 251, 1] },
216
+ "--color-green-2": { css: "#f2fdf3", rgba: [242, 253, 243, 1] },
217
+ "--color-green-3": { css: "#e3f7e7", rgba: [227, 247, 231, 1] },
218
+ "--color-green-4": { css: "#d7f2db", rgba: [215, 242, 219, 1] },
219
+ "--color-green-5": { css: "#c9edcf", rgba: [201, 237, 207, 1] },
220
+ "--color-green-6": { css: "#bae6c1", rgba: [186, 230, 193, 1] },
221
+ "--color-green-7": { css: "#a5dcaf", rgba: [165, 220, 175, 1] },
222
+ "--color-green-8": { css: "#82cb92", rgba: [130, 203, 146, 1] },
223
+ "--color-green-9": { css: "#04833b", rgba: [4, 131, 59, 1] },
224
+ "--color-green-10": { css: "#027634", rgba: [2, 118, 52, 1] },
225
+ "--color-green-11": { css: "#006e30", rgba: [0, 110, 48, 1] },
226
+ "--color-green-12": { css: "#002a0d", rgba: [0, 42, 13, 1] },
227
+ "--color-red-1": { css: "#fefdfd", rgba: [254, 253, 253, 1] },
228
+ "--color-red-2": { css: "#fef7f7", rgba: [254, 247, 247, 1] },
229
+ "--color-red-3": { css: "#feecea", rgba: [254, 236, 234, 1] },
230
+ "--color-red-4": { css: "#fee3e0", rgba: [254, 227, 224, 1] },
231
+ "--color-red-5": { css: "#ffd7d3", rgba: [255, 215, 211, 1] },
232
+ "--color-red-6": { css: "#fecac5", rgba: [254, 202, 197, 1] },
233
+ "--color-red-7": { css: "#feb8b1", rgba: [254, 184, 177, 1] },
234
+ "--color-red-8": { css: "#fe968e", rgba: [254, 150, 142, 1] },
235
+ "--color-red-9": { css: "#cb1125", rgba: [203, 17, 37, 1] },
236
+ "--color-red-10": { css: "#b9031d", rgba: [185, 3, 29, 1] },
237
+ "--color-red-11": { css: "#a42025", rgba: [164, 32, 37, 1] },
238
+ "--color-red-12": { css: "#450407", rgba: [69, 4, 7, 1] },
239
+ "--danger": { css: "#cb1125", rgba: [203, 17, 37, 1] },
240
+ "--danger-bg": { css: "#feecea", rgba: [254, 236, 234, 1] },
241
+ "--danger-border": { css: "#feb8b1", rgba: [254, 184, 177, 1] },
242
+ "--danger-fg": { css: "#fdfdfe", rgba: [253, 253, 254, 1] },
243
+ "--danger-text": { css: "#a42025", rgba: [164, 32, 37, 1] },
244
+ "--info": { css: "#006bd0", rgba: [0, 107, 208, 1] },
245
+ "--info-bg": { css: "#e9f2fe", rgba: [233, 242, 254, 1] },
246
+ "--info-border": { css: "#aacfff", rgba: [170, 207, 255, 1] },
247
+ "--info-fg": { css: "#fdfdfe", rgba: [253, 253, 254, 1] },
248
+ "--info-text": { css: "#115aa9", rgba: [17, 90, 169, 1] },
249
+ "--slate-1": { css: "#fdfdfe", rgba: [253, 253, 254, 1] },
250
+ "--slate-2": { css: "#f7f9fd", rgba: [247, 249, 253, 1] },
251
+ "--slate-3": { css: "#eef1f7", rgba: [238, 241, 247, 1] },
252
+ "--slate-4": { css: "#e6eaf1", rgba: [230, 234, 241, 1] },
253
+ "--slate-5": { css: "#dde2ea", rgba: [221, 226, 234, 1] },
254
+ "--slate-6": { css: "#d4d9e2", rgba: [212, 217, 226, 1] },
255
+ "--slate-7": { css: "#c6ccd6", rgba: [198, 204, 214, 1] },
256
+ "--slate-8": { css: "#b1b8c2", rgba: [177, 184, 194, 1] },
257
+ "--slate-9": { css: "#868d97", rgba: [134, 141, 151, 1] },
258
+ "--slate-10": { css: "#747b85", rgba: [116, 123, 133, 1] },
259
+ "--slate-11": { css: "#555b64", rgba: [85, 91, 100, 1] },
260
+ "--slate-12": { css: "#1d2229", rgba: [29, 34, 41, 1] },
261
+ "--success": { css: "#04833b", rgba: [4, 131, 59, 1] },
262
+ "--success-bg": { css: "#e3f7e7", rgba: [227, 247, 231, 1] },
263
+ "--success-border": { css: "#a5dcaf", rgba: [165, 220, 175, 1] },
264
+ "--success-fg": { css: "#fdfdfe", rgba: [253, 253, 254, 1] },
265
+ "--success-text": { css: "#006e30", rgba: [0, 110, 48, 1] },
266
+ "--text-body": { css: "#1d2229", rgba: [29, 34, 41, 1] },
267
+ "--text-disabled": { css: "#b1b8c2", rgba: [177, 184, 194, 1] },
268
+ "--text-inverse": { css: "#fdfdfe", rgba: [253, 253, 254, 1] },
269
+ "--text-link": { css: "#a31d3b", rgba: [163, 29, 59, 1] },
270
+ "--text-muted": { css: "#555b64", rgba: [85, 91, 100, 1] },
271
+ "--text-strong": { css: "#1d2229", rgba: [29, 34, 41, 1] },
272
+ "--warning": { css: "#fcab05", rgba: [252, 171, 5, 1] },
273
+ "--warning-bg": { css: "#feefdb", rgba: [254, 239, 219, 1] },
274
+ "--warning-border": { css: "#edc58d", rgba: [237, 197, 141, 1] },
275
+ "--warning-fg": { css: "#1d2229", rgba: [29, 34, 41, 1] },
276
+ "--warning-text": { css: "#865900", rgba: [134, 89, 0, 1] },
277
+ },
278
+ "dark": {
279
+ "--accent": { css: "#f74867", rgba: [247, 72, 103, 1] },
280
+ "--accent-fg": { css: "#0f1112", rgba: [15, 17, 18, 1] },
281
+ "--accent-hover": { css: "#fe687c", rgba: [254, 104, 124, 1] },
282
+ "--accent-subtle": { css: "#30191b", rgba: [48, 25, 27, 1] },
283
+ "--accent-text": { css: "#fe9fa6", rgba: [254, 159, 166, 1] },
284
+ "--bg-active": { css: "#25282d", rgba: [37, 40, 45, 1] },
285
+ "--bg-canvas": { css: "#0f1112", rgba: [15, 17, 18, 1] },
286
+ "--bg-disabled": { css: "#1e2125", rgba: [30, 33, 37, 1] },
287
+ "--bg-field": { css: "#1e2125", rgba: [30, 33, 37, 1] },
288
+ "--bg-hover": { css: "#1e2125", rgba: [30, 33, 37, 1] },
289
+ "--bg-overlay": { css: "rgba(0, 0, 0, 0.6)", rgba: [0, 0, 0, 0.6] },
290
+ "--bg-raised": { css: "#1e2125", rgba: [30, 33, 37, 1] },
291
+ "--bg-selected": { css: "#30191b", rgba: [48, 25, 27, 1] },
292
+ "--bg-skeleton": { css: "#25282d", rgba: [37, 40, 45, 1] },
293
+ "--bg-surface": { css: "#16171a", rgba: [22, 23, 26, 1] },
294
+ "--border-default": { css: "#353940", rgba: [53, 57, 64, 1] },
295
+ "--border-disabled": { css: "#2c2f35", rgba: [44, 47, 53, 1] },
296
+ "--border-focus": { css: "#f74867", rgba: [247, 72, 103, 1] },
297
+ "--border-strong": { css: "#6e757f", rgba: [110, 117, 127, 1] },
298
+ "--border-subtle": { css: "#2c2f35", rgba: [44, 47, 53, 1] },
299
+ "--color-accent-1": { css: "#160e0f", rgba: [22, 14, 15, 1] },
300
+ "--color-accent-2": { css: "#201314", rgba: [32, 19, 20, 1] },
301
+ "--color-accent-3": { css: "#30191b", rgba: [48, 25, 27, 1] },
302
+ "--color-accent-4": { css: "#3e1c1f", rgba: [62, 28, 31, 1] },
303
+ "--color-accent-5": { css: "#4b1f24", rgba: [75, 31, 36, 1] },
304
+ "--color-accent-6": { css: "#5d242b", rgba: [93, 36, 43, 1] },
305
+ "--color-accent-7": { css: "#762b35", rgba: [118, 43, 53, 1] },
306
+ "--color-accent-8": { css: "#9b3544", rgba: [155, 53, 68, 1] },
307
+ "--color-accent-9": { css: "#f74867", rgba: [247, 72, 103, 1] },
308
+ "--color-accent-10": { css: "#fe687c", rgba: [254, 104, 124, 1] },
309
+ "--color-accent-11": { css: "#fe9fa6", rgba: [254, 159, 166, 1] },
310
+ "--color-accent-12": { css: "#ffeaeb", rgba: [255, 234, 235, 1] },
311
+ "--color-amber-1": { css: "#13100c", rgba: [19, 16, 12, 1] },
312
+ "--color-amber-2": { css: "#1c160e", rgba: [28, 22, 14, 1] },
313
+ "--color-amber-3": { css: "#291e0f", rgba: [41, 30, 15, 1] },
314
+ "--color-amber-4": { css: "#34240e", rgba: [52, 36, 14, 1] },
315
+ "--color-amber-5": { css: "#3f2b0b", rgba: [63, 43, 11, 1] },
316
+ "--color-amber-6": { css: "#4e3306", rgba: [78, 51, 6, 1] },
317
+ "--color-amber-7": { css: "#624000", rgba: [98, 64, 0, 1] },
318
+ "--color-amber-8": { css: "#7e5402", rgba: [126, 84, 2, 1] },
319
+ "--color-amber-9": { css: "#c38406", rgba: [195, 132, 6, 1] },
320
+ "--color-amber-10": { css: "#d79202", rgba: [215, 146, 2, 1] },
321
+ "--color-amber-11": { css: "#f0b04d", rgba: [240, 176, 77, 1] },
322
+ "--color-amber-12": { css: "#feedd7", rgba: [254, 237, 215, 1] },
323
+ "--color-blue-1": { css: "#0d1115", rgba: [13, 17, 21, 1] },
324
+ "--color-blue-2": { css: "#12181f", rgba: [18, 24, 31, 1] },
325
+ "--color-blue-3": { css: "#162130", rgba: [22, 33, 48, 1] },
326
+ "--color-blue-4": { css: "#18283d", rgba: [24, 40, 61, 1] },
327
+ "--color-blue-5": { css: "#1a304b", rgba: [26, 48, 75, 1] },
328
+ "--color-blue-6": { css: "#1d3a5e", rgba: [29, 58, 94, 1] },
329
+ "--color-blue-7": { css: "#234877", rgba: [35, 72, 119, 1] },
330
+ "--color-blue-8": { css: "#2a5e9e", rgba: [42, 94, 158, 1] },
331
+ "--color-blue-9": { css: "#3792fd", rgba: [55, 146, 253, 1] },
332
+ "--color-blue-10": { css: "#5aa3fe", rgba: [90, 163, 254, 1] },
333
+ "--color-blue-11": { css: "#91c1ff", rgba: [145, 193, 255, 1] },
334
+ "--color-blue-12": { css: "#e7f1ff", rgba: [231, 241, 255, 1] },
335
+ "--color-green-1": { css: "#0d120e", rgba: [13, 18, 14, 1] },
336
+ "--color-green-2": { css: "#121913", rgba: [18, 25, 19, 1] },
337
+ "--color-green-3": { css: "#162519", rgba: [22, 37, 25, 1] },
338
+ "--color-green-4": { css: "#172e1c", rgba: [23, 46, 28, 1] },
339
+ "--color-green-5": { css: "#193720", rgba: [25, 55, 32, 1] },
340
+ "--color-green-6": { css: "#1b4326", rgba: [27, 67, 38, 1] },
341
+ "--color-green-7": { css: "#1f542e", rgba: [31, 84, 46, 1] },
342
+ "--color-green-8": { css: "#236e3a", rgba: [35, 110, 58, 1] },
343
+ "--color-green-9": { css: "#24ae56", rgba: [36, 174, 86, 1] },
344
+ "--color-green-10": { css: "#45bd69", rgba: [69, 189, 105, 1] },
345
+ "--color-green-11": { css: "#78d68e", rgba: [120, 214, 142, 1] },
346
+ "--color-green-12": { css: "#cdffd6", rgba: [205, 255, 214, 1] },
347
+ "--color-red-1": { css: "#160e0e", rgba: [22, 14, 14, 1] },
348
+ "--color-red-2": { css: "#201312", rgba: [32, 19, 18, 1] },
349
+ "--color-red-3": { css: "#301917", rgba: [48, 25, 23, 1] },
350
+ "--color-red-4": { css: "#3e1c1a", rgba: [62, 28, 26, 1] },
351
+ "--color-red-5": { css: "#4c201d", rgba: [76, 32, 29, 1] },
352
+ "--color-red-6": { css: "#5d2522", rgba: [93, 37, 34, 1] },
353
+ "--color-red-7": { css: "#762c29", rgba: [118, 44, 41, 1] },
354
+ "--color-red-8": { css: "#9c3634", rgba: [156, 54, 52, 1] },
355
+ "--color-red-9": { css: "#f84b4b", rgba: [248, 75, 75, 1] },
356
+ "--color-red-10": { css: "#ff6b65", rgba: [255, 107, 101, 1] },
357
+ "--color-red-11": { css: "#ffa098", rgba: [255, 160, 152, 1] },
358
+ "--color-red-12": { css: "#feebe9", rgba: [254, 235, 233, 1] },
359
+ "--danger": { css: "#f84b4b", rgba: [248, 75, 75, 1] },
360
+ "--danger-bg": { css: "#301917", rgba: [48, 25, 23, 1] },
361
+ "--danger-border": { css: "#762c29", rgba: [118, 44, 41, 1] },
362
+ "--danger-fg": { css: "#0f1112", rgba: [15, 17, 18, 1] },
363
+ "--danger-text": { css: "#ffa098", rgba: [255, 160, 152, 1] },
364
+ "--info": { css: "#3792fd", rgba: [55, 146, 253, 1] },
365
+ "--info-bg": { css: "#162130", rgba: [22, 33, 48, 1] },
366
+ "--info-border": { css: "#234877", rgba: [35, 72, 119, 1] },
367
+ "--info-fg": { css: "#0f1112", rgba: [15, 17, 18, 1] },
368
+ "--info-text": { css: "#91c1ff", rgba: [145, 193, 255, 1] },
369
+ "--slate-1": { css: "#0f1112", rgba: [15, 17, 18, 1] },
370
+ "--slate-2": { css: "#16171a", rgba: [22, 23, 26, 1] },
371
+ "--slate-3": { css: "#1e2125", rgba: [30, 33, 37, 1] },
372
+ "--slate-4": { css: "#25282d", rgba: [37, 40, 45, 1] },
373
+ "--slate-5": { css: "#2c2f35", rgba: [44, 47, 53, 1] },
374
+ "--slate-6": { css: "#353940", rgba: [53, 57, 64, 1] },
375
+ "--slate-7": { css: "#434850", rgba: [67, 72, 80, 1] },
376
+ "--slate-8": { css: "#585e67", rgba: [88, 94, 103, 1] },
377
+ "--slate-9": { css: "#6e757f", rgba: [110, 117, 127, 1] },
378
+ "--slate-10": { css: "#808791", rgba: [128, 135, 145, 1] },
379
+ "--slate-11": { css: "#b8bec9", rgba: [184, 190, 201, 1] },
380
+ "--slate-12": { css: "#eaf1fb", rgba: [234, 241, 251, 1] },
381
+ "--success": { css: "#24ae56", rgba: [36, 174, 86, 1] },
382
+ "--success-bg": { css: "#162519", rgba: [22, 37, 25, 1] },
383
+ "--success-border": { css: "#1f542e", rgba: [31, 84, 46, 1] },
384
+ "--success-fg": { css: "#0f1112", rgba: [15, 17, 18, 1] },
385
+ "--success-text": { css: "#78d68e", rgba: [120, 214, 142, 1] },
386
+ "--text-body": { css: "#eaf1fb", rgba: [234, 241, 251, 1] },
387
+ "--text-disabled": { css: "#585e67", rgba: [88, 94, 103, 1] },
388
+ "--text-inverse": { css: "#0f1112", rgba: [15, 17, 18, 1] },
389
+ "--text-link": { css: "#fe9fa6", rgba: [254, 159, 166, 1] },
390
+ "--text-muted": { css: "#b8bec9", rgba: [184, 190, 201, 1] },
391
+ "--text-strong": { css: "#eaf1fb", rgba: [234, 241, 251, 1] },
392
+ "--warning": { css: "#c38406", rgba: [195, 132, 6, 1] },
393
+ "--warning-bg": { css: "#291e0f", rgba: [41, 30, 15, 1] },
394
+ "--warning-border": { css: "#624000", rgba: [98, 64, 0, 1] },
395
+ "--warning-fg": { css: "#0f1112", rgba: [15, 17, 18, 1] },
396
+ "--warning-text": { css: "#f0b04d", rgba: [240, 176, 77, 1] },
397
+ },
398
+ } as const satisfies { readonly [context in PaletteContext]: Palette };
399
+
400
+ /** Color tokens ADS cannot resolve statically in some context; they are not in the palette. */
401
+ export const unresolved: readonly { readonly context: PaletteContext; readonly token: string; readonly value: string; readonly reason: string }[] = [
402
+ ];
@@ -2,6 +2,7 @@ import path from "node:path";
2
2
  import ts from "typescript";
3
3
  import { isUiCssProperties, styleAccessProperty } from "./boundaries.mjs";
4
4
  import { uiOperation } from "./ui-framework.mjs";
5
+ import { findingSeverity } from "./finding-rules.mjs";
5
6
 
6
7
  const nameOf = node => node && (ts.isIdentifier(node) || ts.isStringLiteralLike(node)) ? node.text : null;
7
8
 
@@ -54,6 +55,6 @@ export function pointerCaptureAdvisories(source) {
54
55
  visit(source);
55
56
  return cleanup.length ? [] : captures.map(node => {
56
57
  const position = source.getLineAndCharacterOfPosition(node.getStart(source));
57
- return { rule: "pointer-capture-review", line: position.line + 1, column: position.character + 1, message: "Pointer capture has no locally visible lostpointercapture cleanup handler. Verify cancellation and capture-loss cleanup, including any delegated hook/helper. This advisory does not prove cleanup is missing or correct." };
58
+ return { rule: "pointer-capture-review", severity: findingSeverity("pointer-capture-review"), line: position.line + 1, column: position.character + 1, message: "Pointer capture has no locally visible lostpointercapture cleanup handler. Verify cancellation and capture-loss cleanup, including any delegated hook/helper. This review item does not prove cleanup is missing or correct." };
58
59
  });
59
60
  }
@@ -0,0 +1,150 @@
1
+ import { existsSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { classifyScope, referencedTokens, themeDependents } from "./themes.mjs";
4
+ import { generatedPaletteFile, paletteTs } from "./palette-generated.mjs";
5
+
6
+ // themes.generated.css: the theme switches and per-element resolvers ADS writes from the token
7
+ // sheets' per-theme halves and ds.config.json themes/brands. The showcase and MCP server write
8
+ // it at startup and whenever a token sheet or the config changes, `ads assets` writes it on
9
+ // demand (for CI and agents without a running showcase); `ads check` only verifies it.
10
+ //
11
+ // Each theme has a switch, --ads-if-<theme>, inherited from the nearest [data-theme]: the
12
+ // active theme's is `initial` (the guaranteed-invalid value, so var() takes its fallback) and
13
+ // every other theme's is empty (var() substitutes nothing). A themed token concatenates one
14
+ // var(--ads-if-<theme>, var(--token-<theme>)) per theme, so exactly the active half survives.
15
+ // Display switches (--display-<theme>, --display-brand-<brand>) are `initial` where their theme
16
+ // or brand applies and `none` elsewhere, so display: var(--display-dark, block) shows artwork
17
+ // only in the nearest dark section. With followSystemTheme, an @media (prefers-color-scheme)
18
+ // block applies the matching theme's switches to a root without an explicit data-theme.
19
+ // Resolvers sit on :root, [data-theme] and [data-brand], so every themed or branded element
20
+ // re-resolves against its own switches and halves. A re-resolved token's conditional values
21
+ // (an @media or @supports block on :root in a token sheet) are repeated after the resolvers
22
+ // under the same conditions, so the unconditional resolver copy does not override them.
23
+ // Beside it, themes.generated.ts holds the resolved renderer palette (palette-generated.mjs);
24
+ // both files are written and checked together.
25
+
26
+ export const generatedThemesFile = "themes.generated.css";
27
+ export const themesCssPath = ({ dsRoot, config }) => path.join(dsRoot, config.tokenDir, generatedThemesFile);
28
+ export { generatedPaletteFile };
29
+ /** Both generated files, written and checked together: the theme sheet and the renderer palette. */
30
+ export const generatedThemeFiles = [generatedThemesFile, generatedPaletteFile];
31
+ export const paletteTsPath = ({ dsRoot, config }) => path.join(dsRoot, config.tokenDir, generatedPaletteFile);
32
+ const generatedTexts = (options, tokens) => [{ file: themesCssPath(options), text: themesCss(tokens, options.config) }, { file: paletteTsPath(options), text: paletteTs(tokens, options.config) }];
33
+ const header = "/* Generated by ADS from the token sheets' per-theme halves and ds.config.json themes and brands.\n The showcase and MCP server rewrite it when they change; do not edit it. */\n";
34
+
35
+ const declaration = definition => ({ property: definition.property ?? definition.name, value: (definition.authored ?? definition.value).trim() });
36
+ const block = (selector, lines) => lines.length ? [`${selector} {`, ...lines.map(line => ` ${line}`), "}"] : [];
37
+
38
+ /** The at-rule conditions of a default-brand :root definition ("@media … > :root"), or null. */
39
+ function rootConditions(definition, defaultBrand) {
40
+ if (!definition.conditional || definition.old || definition.brand !== null) return null;
41
+ const parts = definition.scope.split(" > "), selector = parts.pop();
42
+ if (!parts.length || parts.some(part => !part.startsWith("@")) || classifyScope(selector, defaultBrand).kind !== "root") return null;
43
+ return parts;
44
+ }
45
+
46
+ /** The display switches the generated sheet defines: --display-<theme> per declared theme and,
47
+ * with brands declared, --display-brand-<brand> per brand. Components read them with a
48
+ * fallback (display: var(--display-dark, block)), so they need no token-sheet definition. */
49
+ export function displaySwitches({ themes, brands = [] }) {
50
+ return [...themes.map(theme => `--display-${theme.name}`), ...brands.map(brand => `--display-brand-${brand.name}`)];
51
+ }
52
+
53
+ // A theme's switch block: its color scheme, --ads-if-<theme> per theme (initial for its own,
54
+ // empty otherwise) and --display-<theme> per theme (initial for its own, none otherwise).
55
+ const themeSwitches = (theme, themes) => [`color-scheme: ${theme.scheme};`,
56
+ ...themes.map(other => `--ads-if-${other.name}: ${other === theme ? "initial" : ""};`),
57
+ ...themes.map(other => `--display-${other.name}: ${other === theme ? "initial" : "none"};`)];
58
+ const brandSwitches = (brand, brands) => brands.map(other => `--display-brand-${other.name}: ${other === brand ? "initial" : "none"};`);
59
+
60
+ /** The theme that follows each OS color scheme when followSystemTheme is set: the first declared
61
+ * theme with that scheme, unless it is the default theme :root already applies. */
62
+ export function systemThemes(themes) {
63
+ return ["light", "dark"].map(scheme => [scheme, themes.find(theme => theme.scheme === scheme)]).filter(([, theme]) => theme && theme !== themes[0]);
64
+ }
65
+
66
+ /** The generated stylesheet for a token inventory's tokens and the declared themes and brands. */
67
+ export function themesCss(tokens, { themes, brands = [], followSystemTheme = false }) {
68
+ const out = [];
69
+ for (const [index, theme] of themes.entries()) {
70
+ out.push(...block(index ? `[data-theme="${theme.name}"]` : `:root, [data-theme="${theme.name}"]`, themeSwitches(theme, themes)));
71
+ }
72
+ // Without an explicit data-theme on the root, the OS color scheme picks the theme.
73
+ if (followSystemTheme) for (const [scheme, theme] of systemThemes(themes)) {
74
+ out.push(...block(`@media (prefers-color-scheme: ${scheme})`, block(":root:not([data-theme])", themeSwitches(theme, themes))));
75
+ }
76
+ const dependent = themeDependents(tokens);
77
+ const plain = definition => !definition.conditional;
78
+ const defaults = [], branded = new Map(brands.slice(1).map(brand => [brand.name, []]));
79
+ for (const token of tokens) for (const definition of token.definitions.filter(plain)) {
80
+ const entry = { ...declaration({ ...definition, name: token.name }), token: token.name, themed: definition.theme !== null };
81
+ if (definition.brand === null) defaults.push(entry);
82
+ else branded.get(definition.brand)?.push(entry);
83
+ }
84
+ // Brand-sensitive declarations re-apply on every [data-brand]: what a brand re-values, and
85
+ // every default value that refers to one of those, so a section inside another brand starts
86
+ // from the defaults and a brand's values resolve against its own halves.
87
+ const sensitive = new Set([...branded.values()].flat().map(entry => entry.property));
88
+ const sensitiveToken = name => sensitive.has(name) || tokens.some(token => token.themed && token.name === name && [...sensitive].some(property => property.startsWith(`${name}-`)));
89
+ for (let changed = true; changed;) {
90
+ changed = false;
91
+ for (const entry of defaults) if (!sensitive.has(entry.property) && referencedTokens(entry.value).some(sensitiveToken)) { sensitive.add(entry.property); changed = true; }
92
+ }
93
+ const sorted = entries => [...new Map(entries.map(entry => [entry.property, entry])).values()].sort((a, b) => a.property.localeCompare(b.property, "en", { numeric: true }));
94
+ const reresolved = entry => !entry.themed && dependent.has(entry.token);
95
+ if (brands.length) {
96
+ // The default brand's display switches hold on :root and reset on every [data-brand], so a
97
+ // default-brand section inside another brand shows its own artwork.
98
+ out.push(...block(":root, [data-brand]", brandSwitches(brands[0], brands)));
99
+ out.push(...block("[data-brand]", sorted(defaults.filter(entry => sensitive.has(entry.property) && !reresolved(entry))).map(entry => `${entry.property}: ${entry.value};`)));
100
+ for (const [name, entries] of branded) out.push(...block(`[data-brand="${name}"]`, [...brandSwitches(brands.find(brand => brand.name === name), brands), ...sorted(entries.filter(entry => !reresolved(entry))).map(entry => `${entry.property}: ${entry.value};`)]));
101
+ }
102
+ const resolvers = [
103
+ ...tokens.filter(token => token.themed).sort((a, b) => a.name.localeCompare(b.name, "en", { numeric: true })).map(token => `${token.name}: ${themes.map(theme => `var(--ads-if-${theme.name}, var(${token.name}-${theme.name}))`).join("")};`),
104
+ ...sorted(defaults.filter(reresolved)).map(entry => `${entry.property}: ${entry.value};`),
105
+ ];
106
+ const resolverSelector = brands.length ? ":root, [data-theme], [data-brand]" : ":root, [data-theme]";
107
+ out.push(...block(resolverSelector, resolvers));
108
+ // Conditional values of re-resolved tokens, in source order per condition, after the resolvers.
109
+ const conditioned = new Map();
110
+ for (const token of tokens) {
111
+ if (token.themed || !dependent.has(token.name)) continue;
112
+ for (const definition of token.definitions) {
113
+ const conditions = rootConditions(definition, brands[0]?.name);
114
+ if (!conditions) continue;
115
+ const key = JSON.stringify(conditions);
116
+ if (!conditioned.has(key)) conditioned.set(key, { conditions, lines: [] });
117
+ const { property, value } = declaration({ ...definition, name: token.name });
118
+ conditioned.get(key).lines.push(`${property}: ${value};`);
119
+ }
120
+ }
121
+ for (const { conditions, lines } of conditioned.values()) out.push(...conditions.reduceRight((inner, condition) => block(condition, inner), block(resolverSelector, lines)));
122
+ return `${header}${out.join("\n")}\n`;
123
+ }
124
+
125
+ /** Errors for a missing or stale generated file; none while the token sheets use the old form. */
126
+ export function themesCssDiagnostics(options, inventory) {
127
+ if (inventory.tokens.some(token => token.definitions.some(definition => definition.old))) return [];
128
+ const diagnostics = [];
129
+ for (const { file, text } of generatedTexts(options, inventory.tokens)) {
130
+ const relative = path.relative(options.root, file).replaceAll("\\", "/");
131
+ const at = { rule: "themes-generated", file: relative, line: 1, column: 1 };
132
+ if (!existsSync(file)) diagnostics.push({ ...at, message: `${relative} is missing. ADS writes it from the token sheets; run \`ads assets\` or start the showcase or MCP server.` });
133
+ else if (readFileSync(file, "utf8") !== text) diagnostics.push({ ...at, message: `${relative} is out of date with the token sheets or ds.config.json themes and brands; run \`ads assets\` or start the showcase or MCP server.` });
134
+ }
135
+ return diagnostics;
136
+ }
137
+
138
+ /** Writes both generated files when their content changed. Skipped while the old theme form
139
+ * remains. The result describes the theme sheet (file, written, text) and lists both in files. */
140
+ export function writeThemesCss(options, inventory) {
141
+ const file = themesCssPath(options);
142
+ if (inventory.tokens.some(token => token.definitions.some(definition => definition.old))) return { file, written: false, skipped: "old theme form", files: [] };
143
+ const files = generatedTexts(options, inventory.tokens).map(({ file, text }) => {
144
+ if (existsSync(file) && readFileSync(file, "utf8") === text) return { file, written: false, text };
145
+ const staged = `${file}.${process.pid}.tmp`;
146
+ try { writeFileSync(staged, text); renameSync(staged, file); } finally { rmSync(staged, { force: true }); }
147
+ return { file, written: true, text };
148
+ });
149
+ return { ...files[0], written: files.some(item => item.written), files };
150
+ }
@@ -0,0 +1,42 @@
1
+ import { watch } from "node:fs";
2
+ import path from "node:path";
3
+ import { loadConfig } from "./config.mjs";
4
+ import { inspectTokens } from "./tokens.mjs";
5
+ import { generatedThemeFiles, generatedThemesFile, writeThemesCss } from "./themes-generated.mjs";
6
+
7
+ /** Rewrites the project's themes.generated.css and themes.generated.ts from its token sheets and config when stale. */
8
+ export function refreshThemesCss(directory) {
9
+ const options = loadConfig(directory);
10
+ return { ...writeThemesCss(options, inspectTokens(directory, options)), root: options.root };
11
+ }
12
+
13
+ /** Keeps themes.generated.css and .ts current: once now, then on every token sheet or config change. */
14
+ export function watchThemesCss(directory, { log = () => {} } = {}) {
15
+ const watchers = [];
16
+ let timer;
17
+ const refresh = () => {
18
+ try {
19
+ const result = refreshThemesCss(directory);
20
+ for (const item of result.files ?? []) if (item.written) log(`ADS wrote ${path.relative(result.root, item.file).replaceAll("\\", "/")}`);
21
+ } catch (error) { log(`ADS could not write ${generatedThemesFile}: ${error.message}`); }
22
+ };
23
+ const changed = file => {
24
+ const name = path.basename(String(file ?? ""));
25
+ if (generatedThemeFiles.some(generated => name === generated || name.startsWith(`${generated}.`))) return;
26
+ clearTimeout(timer);
27
+ timer = setTimeout(refresh, 50);
28
+ timer.unref?.();
29
+ };
30
+ refresh();
31
+ try {
32
+ const { root, dsRoot, config } = loadConfig(directory);
33
+ for (const [folder, filter] of [[path.join(dsRoot, config.tokenDir), file => String(file).endsWith(".css")], [root, file => String(file) === "ds.config.json"]]) {
34
+ try {
35
+ const watcher = watch(folder, { recursive: folder !== root }, (_event, file) => { if (filter(file)) changed(file); });
36
+ watcher.unref(); watcher.on("error", () => watcher.close());
37
+ watchers.push(watcher);
38
+ } catch { /* A missing token folder has nothing to generate from. */ }
39
+ }
40
+ } catch { /* An invalid configuration is reported by the server itself. */ }
41
+ return { refresh, close() { clearTimeout(timer); for (const watcher of watchers) watcher.close(); } };
42
+ }