@cognitap/radiant 0.0.3 → 0.0.4

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 (56) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +19 -15
  3. package/dist/library/color/colorFamilies.d.ts +3 -0
  4. package/dist/library/color/colorFamilies.d.ts.map +1 -0
  5. package/dist/library/color/colorFamilies.js +20 -0
  6. package/dist/library/color/colorFamilies.js.map +1 -0
  7. package/dist/library/color/generateColorWall.d.ts +54 -0
  8. package/dist/library/color/generateColorWall.d.ts.map +1 -0
  9. package/dist/library/color/generateColorWall.js +231 -0
  10. package/dist/library/color/generateColorWall.js.map +1 -0
  11. package/dist/library/color/index.d.ts +5 -0
  12. package/dist/library/color/index.d.ts.map +1 -0
  13. package/dist/library/color/index.js +3 -0
  14. package/dist/library/color/index.js.map +1 -0
  15. package/dist/library/color/oklch.d.ts +17 -0
  16. package/dist/library/color/oklch.d.ts.map +1 -0
  17. package/dist/library/color/oklch.js +79 -0
  18. package/dist/library/color/oklch.js.map +1 -0
  19. package/dist/library/color/recommendColorPalette.d.ts +65 -0
  20. package/dist/library/color/recommendColorPalette.d.ts.map +1 -0
  21. package/dist/library/color/recommendColorPalette.js +263 -0
  22. package/dist/library/color/recommendColorPalette.js.map +1 -0
  23. package/dist/library/index.d.ts +8 -2
  24. package/dist/library/index.d.ts.map +1 -1
  25. package/dist/library/index.js +4 -1
  26. package/dist/library/index.js.map +1 -1
  27. package/dist/library/styles.css +1 -1
  28. package/dist/library/themes/index.d.ts +4 -0
  29. package/dist/library/themes/index.d.ts.map +1 -1
  30. package/dist/library/themes/index.js +2 -0
  31. package/dist/library/themes/index.js.map +1 -1
  32. package/dist/library/themes/themeDocument.d.ts +16 -0
  33. package/dist/library/themes/themeDocument.d.ts.map +1 -0
  34. package/dist/library/themes/themeDocument.js +307 -0
  35. package/dist/library/themes/themeDocument.js.map +1 -0
  36. package/dist/library/themes/themeDocumentTypes.d.ts +69 -0
  37. package/dist/library/themes/themeDocumentTypes.d.ts.map +1 -0
  38. package/dist/library/themes/themeDocumentTypes.js +2 -0
  39. package/dist/library/themes/themeDocumentTypes.js.map +1 -0
  40. package/dist/library/themes/updateThemeAppearance.d.ts +29 -0
  41. package/dist/library/themes/updateThemeAppearance.d.ts.map +1 -0
  42. package/dist/library/themes/updateThemeAppearance.js +138 -0
  43. package/dist/library/themes/updateThemeAppearance.js.map +1 -0
  44. package/docs/system.md +13 -0
  45. package/docs/theming.md +412 -0
  46. package/package.json +11 -4
  47. package/src/color/colorFamilies.ts +19 -0
  48. package/src/color/generateColorWall.ts +358 -0
  49. package/src/color/index.ts +11 -0
  50. package/src/color/oklch.ts +95 -0
  51. package/src/color/recommendColorPalette.ts +375 -0
  52. package/src/index.ts +37 -0
  53. package/src/themes/index.ts +24 -0
  54. package/src/themes/themeDocument.ts +340 -0
  55. package/src/themes/themeDocumentTypes.ts +76 -0
  56. package/src/themes/updateThemeAppearance.ts +172 -0
@@ -0,0 +1,307 @@
1
+ import { defineTheme } from './defineTheme.js';
2
+ import { freezeTree, tokenDefaults } from './tokens.js';
3
+ const sectionNames = [
4
+ ...Object.keys(tokenDefaults.light),
5
+ 'components'
6
+ ];
7
+ const stops = new Set([50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950]);
8
+ function record(value, path) {
9
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
10
+ throw new TypeError(`${path} must be an object.`);
11
+ }
12
+ }
13
+ function keys(value, allowed, path) {
14
+ for (const key of Object.keys(value)) {
15
+ if (!allowed.includes(key))
16
+ throw new TypeError(`Unknown key: ${path}.${key}.`);
17
+ }
18
+ }
19
+ function textValue(value, path) {
20
+ if (typeof value !== 'string' || !value.trim()) {
21
+ throw new TypeError(`${path} must be a nonempty string.`);
22
+ }
23
+ }
24
+ function choice(value, allowed, path) {
25
+ if (!allowed.includes(value)) {
26
+ throw new TypeError(`${path} must be one of: ${allowed.join(', ')}.`);
27
+ }
28
+ }
29
+ function list(value, path) {
30
+ if (!Array.isArray(value))
31
+ throw new TypeError(`${path} must be an array.`);
32
+ }
33
+ function unique(value, seen, path) {
34
+ if (seen.has(value))
35
+ throw new TypeError(`Duplicate value at ${path}: ${String(value)}.`);
36
+ seen.add(value);
37
+ }
38
+ /** Copy data without running getters/toJSON or silently losing functions and binaries. */
39
+ function jsonCopy(value, path, ancestors = new Set()) {
40
+ if (value === null || typeof value === 'string' || typeof value === 'boolean')
41
+ return value;
42
+ if (typeof value === 'number' && Number.isFinite(value))
43
+ return value === 0 ? 0 : value;
44
+ if (!value || typeof value !== 'object')
45
+ throw new TypeError(`${path} must contain JSON data only.`);
46
+ if (ancestors.has(value))
47
+ throw new TypeError(`Circular reference at ${path}.`);
48
+ const array = Array.isArray(value);
49
+ const prototype = Object.getPrototypeOf(value);
50
+ if (array ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) {
51
+ throw new TypeError(`${path} must contain plain JSON objects, not class instances or binaries.`);
52
+ }
53
+ ancestors.add(value);
54
+ const result = array ? [] : {};
55
+ if (Object.getOwnPropertySymbols(value).length)
56
+ throw new TypeError(`${path} cannot contain symbol keys.`);
57
+ const descriptors = Object.getOwnPropertyDescriptors(value);
58
+ for (const key of Object.keys(descriptors).sort()) {
59
+ if (array && key === 'length')
60
+ continue;
61
+ if (['__proto__', 'constructor', 'prototype'].includes(key))
62
+ throw new TypeError(`Forbidden key: ${path}.${key}.`);
63
+ const descriptor = descriptors[key];
64
+ if (!('value' in descriptor) || !descriptor.enumerable) {
65
+ throw new TypeError(`${path}.${key} must be an enumerable data property.`);
66
+ }
67
+ if (array && (!/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= value.length)) {
68
+ throw new TypeError(`${path}.${key} is not an array index.`);
69
+ }
70
+ // Optional object properties follow JSON omission rules; array holes/undefined are invalid.
71
+ if (descriptor.value === undefined && !array)
72
+ continue;
73
+ const copy = jsonCopy(descriptor.value, `${path}.${key}`, ancestors);
74
+ Object.defineProperty(result, key, {
75
+ value: copy,
76
+ enumerable: true,
77
+ writable: true,
78
+ configurable: true
79
+ });
80
+ }
81
+ if (array && Object.keys(result).length !== value.length)
82
+ throw new TypeError(`${path} cannot contain array holes.`);
83
+ ancestors.delete(value);
84
+ return result;
85
+ }
86
+ function validateColor(value, path) {
87
+ if (value.brand !== undefined) {
88
+ record(value.brand, `${path}.brand`);
89
+ keys(value.brand, ['value', 'gamut', 'srgbFallback'], `${path}.brand`);
90
+ textValue(value.brand.value, `${path}.brand.value`);
91
+ choice(value.brand.gamut, ['srgb', 'display-p3'], `${path}.brand.gamut`);
92
+ if (value.brand.srgbFallback !== undefined)
93
+ textValue(value.brand.srgbFallback, `${path}.brand.srgbFallback`);
94
+ if (value.fidelity === undefined)
95
+ value.fidelity = 'anchored';
96
+ }
97
+ if (value.fidelity !== undefined)
98
+ choice(value.fidelity, ['anchored', 'unanchored'], `${path}.fidelity`);
99
+ if (value.palettes !== undefined) {
100
+ list(value.palettes, `${path}.palettes`);
101
+ const ids = new Set();
102
+ for (const [i, palette] of value.palettes.entries()) {
103
+ const p = `${path}.palettes.${i}`;
104
+ record(palette, p);
105
+ keys(palette, ['id', 'name', 'swatches'], p);
106
+ textValue(palette.id, `${p}.id`);
107
+ textValue(palette.name, `${p}.name`);
108
+ unique(palette.id, ids, `${p}.id`);
109
+ list(palette.swatches, `${p}.swatches`);
110
+ if (!palette.swatches.length)
111
+ throw new TypeError(`${p}.swatches must not be empty.`);
112
+ const seen = new Set();
113
+ for (const [j, swatch] of palette.swatches.entries()) {
114
+ const s = `${p}.swatches.${j}`;
115
+ record(swatch, s);
116
+ keys(swatch, ['stop', 'value', 'srgbFallback'], s);
117
+ if (!stops.has(swatch.stop))
118
+ throw new TypeError(`${s}.stop must be a numbered color stop (50–950).`);
119
+ unique(swatch.stop, seen, `${s}.stop`);
120
+ textValue(swatch.value, `${s}.value`);
121
+ if (swatch.srgbFallback !== undefined)
122
+ textValue(swatch.srgbFallback, `${s}.srgbFallback`);
123
+ }
124
+ }
125
+ }
126
+ if (value.anchor !== undefined) {
127
+ record(value.anchor, `${path}.anchor`);
128
+ keys(value.anchor, ['paletteId', 'stop'], `${path}.anchor`);
129
+ textValue(value.anchor.paletteId, `${path}.anchor.paletteId`);
130
+ if (!stops.has(value.anchor.stop))
131
+ throw new TypeError(`${path}.anchor.stop must be a numbered color stop (50–950).`);
132
+ const color = value;
133
+ const swatch = color.palettes
134
+ ?.find(p => p.id === color.anchor.paletteId)
135
+ ?.swatches.find(s => s.stop === color.anchor.stop);
136
+ if (!color.brand || color.fidelity !== 'anchored' || swatch?.value !== color.brand.value) {
137
+ throw new TypeError(`${path}.anchor must reference a swatch containing the exact brand.value with anchored fidelity. Regenerate or replace the color section.`);
138
+ }
139
+ }
140
+ }
141
+ function validateFonts(value, path) {
142
+ list(value, path);
143
+ const ids = new Set();
144
+ for (const [i, font] of value.entries()) {
145
+ const p = `${path}.${i}`;
146
+ record(font, p);
147
+ keys(font, ['id', 'family', 'source', 'weights', 'styles'], p);
148
+ textValue(font.id, `${p}.id`);
149
+ textValue(font.family, `${p}.family`);
150
+ unique(font.id, ids, `${p}.id`);
151
+ choice(font.source, ['system', 'catalog', 'local'], `${p}.source`);
152
+ for (const key of ['weights', 'styles']) {
153
+ if (font[key] === undefined)
154
+ continue;
155
+ list(font[key], `${p}.${key}`);
156
+ const seen = new Set();
157
+ for (const [j, item] of font[key].entries()) {
158
+ const at = `${p}.${key}.${j}`;
159
+ if (key === 'styles')
160
+ choice(item, ['normal', 'italic'], at);
161
+ else if (typeof item !== 'number' || item < 1 || item > 1000)
162
+ throw new TypeError(`${at} must be a weight from 1 to 1000.`);
163
+ unique(item, seen, at);
164
+ }
165
+ }
166
+ }
167
+ }
168
+ function toDefinition(sections, id, name) {
169
+ const common = { tokens: {} };
170
+ const modes = { light: { tokens: {} }, dark: { tokens: {} } };
171
+ for (const sectionName of sectionNames) {
172
+ const section = sections[sectionName];
173
+ if (!section)
174
+ continue;
175
+ for (const mode of ['common', 'light', 'dark']) {
176
+ const values = mode === 'common' ? section.values : section.modes?.[mode];
177
+ if (values === undefined)
178
+ continue;
179
+ const layer = mode === 'common' ? common : modes[mode];
180
+ if (sectionName === 'components')
181
+ layer.components = values;
182
+ else
183
+ layer.tokens[sectionName] = values;
184
+ }
185
+ }
186
+ return { id, name, ...common, modes };
187
+ }
188
+ /** Read JSON.parse output (or data objects); unknown versions/keys fail with a path. */
189
+ export function parseThemeDocument(input) {
190
+ const value = jsonCopy(input, 'document');
191
+ record(value, 'document');
192
+ choice(value.kind, ['radiant-theme', 'radiant-theme-sections'], 'document.kind');
193
+ if (value.version !== 1)
194
+ throw new TypeError(`Unsupported document.version: ${String(value.version)}. Expected 1; migrate the configuration before importing.`);
195
+ const full = value.kind === 'radiant-theme';
196
+ keys(value, full ? ['kind', 'version', 'id', 'name', 'sections'] : ['kind', 'version', 'sections'], 'document');
197
+ record(value.sections, 'document.sections');
198
+ keys(value.sections, sectionNames, 'document.sections');
199
+ for (const [name, section] of Object.entries(value.sections)) {
200
+ const path = `document.sections.${name}`;
201
+ record(section, path);
202
+ keys(section, [
203
+ 'values',
204
+ 'modes',
205
+ ...(name === 'color'
206
+ ? ['brand', 'fidelity', 'palettes', 'anchor']
207
+ : name === 'typography'
208
+ ? ['fonts']
209
+ : [])
210
+ ], path);
211
+ if (section.modes !== undefined) {
212
+ record(section.modes, `${path}.modes`);
213
+ keys(section.modes, ['light', 'dark'], `${path}.modes`);
214
+ }
215
+ if (name === 'color')
216
+ validateColor(section, path);
217
+ if (name === 'typography' && section.fonts !== undefined)
218
+ validateFonts(section.fonts, `${path}.fonts`);
219
+ }
220
+ // Reuse the canonical token/component validation and resolution; no second token schema.
221
+ defineTheme(toDefinition(value.sections, full ? value.id : 'section-export', full ? value.name : 'Section export'));
222
+ return freezeTree(jsonCopy(value, 'document'));
223
+ }
224
+ /** Validate and detach an immutable, portable authoring snapshot. */
225
+ export function defineThemeDocument(document) {
226
+ const result = parseThemeDocument(document);
227
+ if (result.kind !== 'radiant-theme')
228
+ throw new TypeError('Expected a radiant-theme document with id and name.');
229
+ return result;
230
+ }
231
+ /** Compile only authored semantic values through the existing application theme runtime. */
232
+ export function compileThemeDocument(document) {
233
+ const validated = defineThemeDocument(document);
234
+ return defineTheme(toDefinition(validated.sections, validated.id, validated.name));
235
+ }
236
+ function merge(base, patch) {
237
+ if (!base ||
238
+ !patch ||
239
+ typeof base !== 'object' ||
240
+ typeof patch !== 'object' ||
241
+ Array.isArray(base) ||
242
+ Array.isArray(patch))
243
+ return patch;
244
+ const result = { ...base };
245
+ for (const [key, value] of Object.entries(patch))
246
+ result[key] = merge(result[key], value);
247
+ return result;
248
+ }
249
+ /** Merge leaves/replace arrays, or replace only supplied sections. Empty replacement resets. */
250
+ export function updateThemeDocument(document, sections, mode = 'merge') {
251
+ const base = defineThemeDocument(document);
252
+ choice(mode, ['merge', 'replace'], 'update mode');
253
+ // Check the patch's JSON boundary before merging, including keys a spread would discard.
254
+ const patch = jsonCopy(sections, 'sections');
255
+ record(patch, 'sections');
256
+ keys(patch, sectionNames, 'sections');
257
+ const next = { ...base.sections };
258
+ for (const [name, section] of Object.entries(patch))
259
+ next[name] = mode === 'replace' ? section : merge(next[name], section);
260
+ return defineThemeDocument({ ...base, sections: next });
261
+ }
262
+ /** Export exactly these sections, with no document identity or implicit component exceptions. */
263
+ export function exportThemeSections(document, names) {
264
+ const base = defineThemeDocument(document);
265
+ list(names, 'section names');
266
+ const sections = {};
267
+ for (const name of names) {
268
+ choice(name, sectionNames, 'section name');
269
+ if (base.sections[name] !== undefined)
270
+ sections[name] = base.sections[name];
271
+ }
272
+ return parseThemeDocument({
273
+ kind: 'radiant-theme-sections',
274
+ version: 1,
275
+ sections
276
+ });
277
+ }
278
+ /** Bring existing authored themes into the workshop without materialising defaults as overrides. */
279
+ export function themeDocumentFromDefinition(definition) {
280
+ const copy = jsonCopy(definition, 'theme');
281
+ defineTheme(copy);
282
+ const sections = {};
283
+ for (const name of sectionNames) {
284
+ const section = {};
285
+ const values = name === 'components' ? copy.components : copy.tokens?.[name];
286
+ if (values !== undefined)
287
+ section.values = values;
288
+ const modes = {};
289
+ for (const mode of ['light', 'dark']) {
290
+ const values = name === 'components' ? copy.modes?.[mode]?.components : copy.modes?.[mode]?.tokens?.[name];
291
+ if (values !== undefined)
292
+ modes[mode] = values;
293
+ }
294
+ if (Object.keys(modes).length)
295
+ section.modes = modes;
296
+ if (Object.keys(section).length)
297
+ sections[name] = section;
298
+ }
299
+ return defineThemeDocument({
300
+ kind: 'radiant-theme',
301
+ version: 1,
302
+ id: copy.id,
303
+ name: copy.name,
304
+ sections
305
+ });
306
+ }
307
+ //# sourceMappingURL=themeDocument.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"themeDocument.js","sourceRoot":"","sources":["../../../src/themes/themeDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqD,MAAM,kBAAkB,CAAA;AACjG,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAWvD,MAAM,YAAY,GAAgC;IAChD,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;IACnC,YAAY;CACS,CAAA;AACvB,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;AAG7E,SAAS,MAAM,CAAC,KAAc,EAAE,IAAY;IAC1C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChE,MAAM,IAAI,SAAS,CAAC,GAAG,IAAI,qBAAqB,CAAC,CAAA;IACnD,CAAC;AACH,CAAC;AAED,SAAS,IAAI,CAAC,KAAkB,EAAE,OAA0B,E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CAAC","sourcesContent":["import { defineTheme, type Theme, type ThemeDefinition, type ThemeLayer } from './defineTheme.js'\nimport { freezeTree, tokenDefaults } from './tokens.js'\nimport type {\n ThemeColorSection,\n ThemeDocument,\n ThemeSectionExport,\n ThemeSectionName,\n ThemeSections\n} from './themeDocumentTypes.js'\n\nexport type * from './themeDocumentTypes.js'\n\nconst sectionNames: readonly ThemeSectionName[] = [\n ...Object.keys(tokenDefaults.light),\n 'components'\n] as ThemeSectionName[]\nconst stops = new Set([50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950])\ntype RecordValue = Record<string, unknown>\n\nfunction record(value: unknown, path: string): asserts value is RecordValue {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n throw new TypeError(`${path} must be an object.`)\n }\n}\n\nfunction keys(value: RecordValue, allowed: readonly string[], path: string) {\n for (const key of Object.keys(value)) {\n if (!allowed.includes(key)) throw new TypeError(`Unknown key: ${path}.${key}.`)\n }\n}\n\nfunction textValue(value: unknown, path: string) {\n if (typeof value !== 'string' || !value.trim()) {\n throw new TypeError(`${path} must be a nonempty string.`)\n }\n}\n\nfunction choice(value: unknown, allowed: readonly unknown[], path: string) {\n if (!allowed.includes(value)) {\n throw new TypeError(`${path} must be one of: ${allowed.join(', ')}.`)\n }\n}\n\nfunction list(value: unknown, path: string): asserts value is unknown[] {\n if (!Array.isArray(value)) throw new TypeError(`${path} must be an array.`)\n}\n\nfunction unique(value: unknown, seen: Set<unknown>, path: string) {\n if (seen.has(value)) throw new TypeError(`Duplicate value at ${path}: ${String(value)}.`)\n seen.add(value)\n}\n\n/** Copy data without running getters/toJSON or silently losing functions and binaries. */\nfunction jsonCopy(value: unknown, path: string, ancestors = new Set<object>()): unknown {\n if (value === null || typeof value === 'string' || typeof value === 'boolean') return value\n if (typeof value === 'number' && Number.isFinite(value)) return value === 0 ? 0 : value\n if (!value || typeof value !== 'object')\n throw new TypeError(`${path} must contain JSON data only.`)\n if (ancestors.has(value)) throw new TypeError(`Circular reference at ${path}.`)\n const array = Array.isArray(value)\n const prototype = Object.getPrototypeOf(value)\n if (\n array ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null\n ) {\n throw new TypeError(`${path} must contain plain JSON objects, not class instances or binaries.`)\n }\n ancestors.add(value)\n const result: RecordValue | unknown[] = array ? [] : {}\n if (Object.getOwnPropertySymbols(value).length)\n throw new TypeError(`${path} cannot contain symbol keys.`)\n const descriptors = Object.getOwnPropertyDescriptors(value)\n for (const key of Object.keys(descriptors).sort()) {\n if (array && key === 'length') continue\n if (['__proto__', 'constructor', 'prototype'].includes(key))\n throw new TypeError(`Forbidden key: ${path}.${key}.`)\n const descriptor = descriptors[key]\n if (!('value' in descriptor) || !descriptor.enumerable) {\n throw new TypeError(`${path}.${key} must be an enumerable data property.`)\n }\n if (array && (!/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= value.length)) {\n throw new TypeError(`${path}.${key} is not an array index.`)\n }\n // Optional object properties follow JSON omission rules; array holes/undefined are invalid.\n if (descriptor.value === undefined && !array) continue\n const copy = jsonCopy(descriptor.value, `${path}.${key}`, ancestors)\n Object.defineProperty(result, key, {\n value: copy,\n enumerable: true,\n writable: true,\n configurable: true\n })\n }\n if (array && Object.keys(result).length !== value.length)\n throw new TypeError(`${path} cannot contain array holes.`)\n ancestors.delete(value)\n return result\n}\n\nfunction validateColor(value: RecordValue, path: string) {\n if (value.brand !== undefined) {\n record(value.brand, `${path}.brand`)\n keys(value.brand, ['value', 'gamut', 'srgbFallback'], `${path}.brand`)\n textValue(value.brand.value, `${path}.brand.value`)\n choice(value.brand.gamut, ['srgb', 'display-p3'], `${path}.brand.gamut`)\n if (value.brand.srgbFallback !== undefined)\n textValue(value.brand.srgbFallback, `${path}.brand.srgbFallback`)\n if (value.fidelity === undefined) value.fidelity = 'anchored'\n }\n if (value.fidelity !== undefined)\n choice(value.fidelity, ['anchored', 'unanchored'], `${path}.fidelity`)\n if (value.palettes !== undefined) {\n list(value.palettes, `${path}.palettes`)\n const ids = new Set<unknown>()\n for (const [i, palette] of value.palettes.entries()) {\n const p = `${path}.palettes.${i}`\n record(palette, p)\n keys(palette, ['id', 'name', 'swatches'], p)\n textValue(palette.id, `${p}.id`)\n textValue(palette.name, `${p}.name`)\n unique(palette.id, ids, `${p}.id`)\n list(palette.swatches, `${p}.swatches`)\n if (!palette.swatches.length) throw new TypeError(`${p}.swatches must not be empty.`)\n const seen = new Set<unknown>()\n for (const [j, swatch] of palette.swatches.entries()) {\n const s = `${p}.swatches.${j}`\n record(swatch, s)\n keys(swatch, ['stop', 'value', 'srgbFallback'], s)\n if (!stops.has(swatch.stop as number))\n throw new TypeError(`${s}.stop must be a numbered color stop (50–950).`)\n unique(swatch.stop, seen, `${s}.stop`)\n textValue(swatch.value, `${s}.value`)\n if (swatch.srgbFallback !== undefined) textValue(swatch.srgbFallback, `${s}.srgbFallback`)\n }\n }\n }\n if (value.anchor !== undefined) {\n record(value.anchor, `${path}.anchor`)\n keys(value.anchor, ['paletteId', 'stop'], `${path}.anchor`)\n textValue(value.anchor.paletteId, `${path}.anchor.paletteId`)\n if (!stops.has(value.anchor.stop as number))\n throw new TypeError(`${path}.anchor.stop must be a numbered color stop (50–950).`)\n const color = value as ThemeColorSection\n const swatch = color.palettes\n ?.find(p => p.id === color.anchor!.paletteId)\n ?.swatches.find(s => s.stop === color.anchor!.stop)\n if (!color.brand || color.fidelity !== 'anchored' || swatch?.value !== color.brand.value) {\n throw new TypeError(\n `${path}.anchor must reference a swatch containing the exact brand.value with anchored fidelity. Regenerate or replace the color section.`\n )\n }\n }\n}\n\nfunction validateFonts(value: unknown, path: string) {\n list(value, path)\n const ids = new Set<unknown>()\n for (const [i, font] of value.entries()) {\n const p = `${path}.${i}`\n record(font, p)\n keys(font, ['id', 'family', 'source', 'weights', 'styles'], p)\n textValue(font.id, `${p}.id`)\n textValue(font.family, `${p}.family`)\n unique(font.id, ids, `${p}.id`)\n choice(font.source, ['system', 'catalog', 'local'], `${p}.source`)\n for (const key of ['weights', 'styles']) {\n if (font[key] === undefined) continue\n list(font[key], `${p}.${key}`)\n const seen = new Set<unknown>()\n for (const [j, item] of font[key].entries()) {\n const at = `${p}.${key}.${j}`\n if (key === 'styles') choice(item, ['normal', 'italic'], at)\n else if (typeof item !== 'number' || item < 1 || item > 1000)\n throw new TypeError(`${at} must be a weight from 1 to 1000.`)\n unique(item, seen, at)\n }\n }\n }\n}\n\nfunction toDefinition(sections: ThemeSections, id: string, name: string): ThemeDefinition {\n const common: { tokens: RecordValue; components?: ThemeLayer['components'] } = { tokens: {} }\n const modes = { light: { tokens: {} } as typeof common, dark: { tokens: {} } as typeof common }\n for (const sectionName of sectionNames) {\n const section = sections[sectionName]\n if (!section) continue\n for (const mode of ['common', 'light', 'dark'] as const) {\n const values = mode === 'common' ? section.values : section.modes?.[mode]\n if (values === undefined) continue\n const layer = mode === 'common' ? common : modes[mode]\n if (sectionName === 'components') layer.components = values as ThemeLayer['components']\n else layer.tokens[sectionName] = values\n }\n }\n return { id, name, ...common, modes }\n}\n\n/** Read JSON.parse output (or data objects); unknown versions/keys fail with a path. */\nexport function parseThemeDocument(input: unknown): ThemeDocument | ThemeSectionExport {\n const value = jsonCopy(input, 'document')\n record(value, 'document')\n choice(value.kind, ['radiant-theme', 'radiant-theme-sections'], 'document.kind')\n if (value.version !== 1)\n throw new TypeError(\n `Unsupported document.version: ${String(value.version)}. Expected 1; migrate the configuration before importing.`\n )\n const full = value.kind === 'radiant-theme'\n keys(\n value,\n full ? ['kind', 'version', 'id', 'name', 'sections'] : ['kind', 'version', 'sections'],\n 'document'\n )\n record(value.sections, 'document.sections')\n keys(value.sections, sectionNames, 'document.sections')\n for (const [name, section] of Object.entries(value.sections)) {\n const path = `document.sections.${name}`\n record(section, path)\n keys(\n section,\n [\n 'values',\n 'modes',\n ...(name === 'color'\n ? ['brand', 'fidelity', 'palettes', 'anchor']\n : name === 'typography'\n ? ['fonts']\n : [])\n ],\n path\n )\n if (section.modes !== undefined) {\n record(section.modes, `${path}.modes`)\n keys(section.modes, ['light', 'dark'], `${path}.modes`)\n }\n if (name === 'color') validateColor(section, path)\n if (name === 'typography' && section.fonts !== undefined)\n validateFonts(section.fonts, `${path}.fonts`)\n }\n // Reuse the canonical token/component validation and resolution; no second token schema.\n defineTheme(\n toDefinition(\n value.sections as ThemeSections,\n full ? (value.id as string) : 'section-export',\n full ? (value.name as string) : 'Section export'\n )\n )\n return freezeTree(jsonCopy(value, 'document') as object) as ThemeDocument | ThemeSectionExport\n}\n\n/** Validate and detach an immutable, portable authoring snapshot. */\nexport function defineThemeDocument(document: ThemeDocument): ThemeDocument {\n const result = parseThemeDocument(document)\n if (result.kind !== 'radiant-theme')\n throw new TypeError('Expected a radiant-theme document with id and name.')\n return result\n}\n\n/** Compile only authored semantic values through the existing application theme runtime. */\nexport function compileThemeDocument(document: ThemeDocument): Theme {\n const validated = defineThemeDocument(document)\n return defineTheme(toDefinition(validated.sections, validated.id, validated.name))\n}\n\nfunction merge(base: unknown, patch: unknown): unknown {\n if (\n !base ||\n !patch ||\n typeof base !== 'object' ||\n typeof patch !== 'object' ||\n Array.isArray(base) ||\n Array.isArray(patch)\n )\n return patch\n const result: RecordValue = { ...base }\n for (const [key, value] of Object.entries(patch)) result[key] = merge(result[key], value)\n return result\n}\n\n/** Merge leaves/replace arrays, or replace only supplied sections. Empty replacement resets. */\nexport function updateThemeDocument(\n document: ThemeDocument,\n sections: ThemeSections,\n mode: 'merge' | 'replace' = 'merge'\n): ThemeDocument {\n const base = defineThemeDocument(document)\n choice(mode, ['merge', 'replace'], 'update mode')\n // Check the patch's JSON boundary before merging, including keys a spread would discard.\n const patch = jsonCopy(sections, 'sections')\n record(patch, 'sections')\n keys(patch, sectionNames, 'sections')\n const next = { ...base.sections } as RecordValue\n for (const [name, section] of Object.entries(patch))\n next[name] = mode === 'replace' ? section : merge(next[name], section)\n return defineThemeDocument({ ...base, sections: next })\n}\n\n/** Export exactly these sections, with no document identity or implicit component exceptions. */\nexport function exportThemeSections(\n document: ThemeDocument,\n names: readonly ThemeSectionName[]\n): ThemeSectionExport {\n const base = defineThemeDocument(document)\n list(names, 'section names')\n const sections: RecordValue = {}\n for (const name of names) {\n choice(name, sectionNames, 'section name')\n if (base.sections[name] !== undefined) sections[name] = base.sections[name]\n }\n return parseThemeDocument({\n kind: 'radiant-theme-sections',\n version: 1,\n sections\n }) as ThemeSectionExport\n}\n\n/** Bring existing authored themes into the workshop without materialising defaults as overrides. */\nexport function themeDocumentFromDefinition(definition: ThemeDefinition): ThemeDocument {\n const copy = jsonCopy(definition, 'theme') as ThemeDefinition\n defineTheme(copy)\n const sections: RecordValue = {}\n for (const name of sectionNames) {\n const section: RecordValue = {}\n const values = name === 'components' ? copy.components : copy.tokens?.[name]\n if (values !== undefined) section.values = values\n const modes: RecordValue = {}\n for (const mode of ['light', 'dark'] as const) {\n const values =\n name === 'components' ? copy.modes?.[mode]?.components : copy.modes?.[mode]?.tokens?.[name]\n if (values !== undefined) modes[mode] = values\n }\n if (Object.keys(modes).length) section.modes = modes\n if (Object.keys(section).length) sections[name] = section\n }\n return defineThemeDocument({\n kind: 'radiant-theme',\n version: 1,\n id: copy.id,\n name: copy.name,\n sections\n })\n}\n"]}
@@ -0,0 +1,69 @@
1
+ import type { ThemeComponentOverrides } from './components.js';
2
+ import type { ThemeTokens } from './tokens.js';
3
+ /** One existing token group, with independently authored mode layers. */
4
+ export interface ThemeSection<T> {
5
+ readonly values?: T;
6
+ readonly modes?: {
7
+ readonly light?: T;
8
+ readonly dark?: T;
9
+ };
10
+ }
11
+ export type ThemeColorStop = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950;
12
+ export interface ThemeBrandSource {
13
+ /** Unmodified source text. A mapped fallback never replaces this value. */
14
+ readonly value: string;
15
+ readonly gamut: 'srgb' | 'display-p3';
16
+ readonly srgbFallback?: string;
17
+ }
18
+ export interface ThemePalette {
19
+ readonly id: string;
20
+ readonly name: string;
21
+ readonly swatches: readonly {
22
+ readonly stop: ThemeColorStop;
23
+ readonly value: string;
24
+ readonly srgbFallback?: string;
25
+ }[];
26
+ }
27
+ export interface ThemeColorSection extends ThemeSection<ThemeTokens['color']> {
28
+ readonly brand?: ThemeBrandSource;
29
+ /** Defaults to anchored when a brand is present. Generation belongs to the color engine. */
30
+ readonly fidelity?: 'anchored' | 'unanchored';
31
+ readonly palettes?: readonly ThemePalette[];
32
+ /** Optional until generation; references the exact original, never its fallback. */
33
+ readonly anchor?: {
34
+ readonly paletteId: string;
35
+ readonly stop: ThemeColorStop;
36
+ };
37
+ }
38
+ /** Portable descriptors only. The consuming application owns loading and local availability. */
39
+ export interface ThemeFontMetadata {
40
+ readonly id: string;
41
+ readonly family: string;
42
+ readonly source: 'system' | 'catalog' | 'local';
43
+ readonly weights?: readonly number[];
44
+ readonly styles?: readonly ('normal' | 'italic')[];
45
+ }
46
+ export interface ThemeTypographySection extends ThemeSection<ThemeTokens['typography']> {
47
+ readonly fonts?: readonly ThemeFontMetadata[];
48
+ }
49
+ /** Token groups are the extension seams for richer typesetting and spring authoring. */
50
+ export type ThemeSections = {
51
+ readonly [K in keyof ThemeTokens]?: K extends 'color' ? ThemeColorSection : K extends 'typography' ? ThemeTypographySection : ThemeSection<ThemeTokens[K]>;
52
+ } & {
53
+ readonly components?: ThemeSection<ThemeComponentOverrides>;
54
+ };
55
+ export type ThemeSectionName = keyof ThemeSections;
56
+ export interface ThemeDocument {
57
+ readonly kind: 'radiant-theme';
58
+ readonly version: 1;
59
+ readonly id: string;
60
+ readonly name: string;
61
+ readonly sections: ThemeSections;
62
+ }
63
+ /** A selective export has no identity and cannot accidentally replace an entire document. */
64
+ export interface ThemeSectionExport {
65
+ readonly kind: 'radiant-theme-sections';
66
+ readonly version: 1;
67
+ readonly sections: ThemeSections;
68
+ }
69
+ //# sourceMappingURL=themeDocumentTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"themeDocumentTypes.d.ts","sourceRoot":"","sources":["../../../src/themes/themeDocumentTypes.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AA;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAA;CACjC;AAED,6FAA6F;AAC7F,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAA;IACvC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;IACnB,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAA;CACjC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=themeDocumentTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"themeDocumentTypes.js","sourceRoot":"","sources":["../../../src/themes/themeDocumentTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type { ThemeComponentOverrides } from './components.js'\nimport type { ThemeTokens } from './tokens.js'\n\n/** One existing token group, with independently authored mode layers. */\nexport interface ThemeSection<T> {\n readonly values?: T\n readonly modes?: { readonly light?: T; readonly dark?: T }\n}\n\nexport type ThemeColorStop = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950\n\nexport interface ThemeBrandSource {\n /** Unmodified source text. A mapped fallback never replaces this value. */\n readonly value: string\n readonly gamut: 'srgb' | 'display-p3'\n readonly srgbFallback?: string\n}\n\nexport interface ThemePalette {\n readonly id: string\n readonly name: string\n readonly swatches: readonly {\n readonly stop: ThemeColorStop\n readonly value: string\n readonly srgbFallback?: string\n }[]\n}\n\nexport interface ThemeColorSection extends ThemeSection<ThemeTokens['color']> {\n readonly brand?: ThemeBrandSource\n /** Defaults to anchored when a brand is present. Generation belongs to the color engine. */\n readonly fidelity?: 'anchored' | 'unanchored'\n readonly palettes?: readonly ThemePalette[]\n /** Optional until generation; references the exact original, never its fallback. */\n readonly anchor?: { readonly paletteId: string; readonly stop: ThemeColorStop }\n}\n\n/** Portable descriptors only. The consuming application owns loading and local availability. */\nexport interface ThemeFontMetadata {\n readonly id: string\n readonly family: string\n readonly source: 'system' | 'catalog' | 'local'\n readonly weights?: readonly number[]\n readonly styles?: readonly ('normal' | 'italic')[]\n}\n\nexport interface ThemeTypographySection extends ThemeSection<ThemeTokens['typography']> {\n readonly fonts?: readonly ThemeFontMetadata[]\n}\n\n/** Token groups are the extension seams for richer typesetting and spring authoring. */\nexport type ThemeSections = {\n readonly [K in keyof ThemeTokens]?: K extends 'color'\n ? ThemeColorSection\n : K extends 'typography'\n ? ThemeTypographySection\n : ThemeSection<ThemeTokens[K]>\n} & {\n readonly components?: ThemeSection<ThemeComponentOverrides>\n}\nexport type ThemeSectionName = keyof ThemeSections\n\nexport interface ThemeDocument {\n readonly kind: 'radiant-theme'\n readonly version: 1\n readonly id: string\n readonly name: string\n readonly sections: ThemeSections\n}\n\n/** A selective export has no identity and cannot accidentally replace an entire document. */\nexport interface ThemeSectionExport {\n readonly kind: 'radiant-theme-sections'\n readonly version: 1\n readonly sections: ThemeSections\n}\n"]}
@@ -0,0 +1,29 @@
1
+ import type { ColorPalette } from '../color/recommendColorPalette.js';
2
+ import type { ThemeDocument, ThemeSection } from './themeDocumentTypes.js';
3
+ /** Bounded workshop controls; dimensions are derived from the neutral baseline, not compounded. */
4
+ export interface ThemeGeometrySettings {
5
+ /** 0.5–2; scales shared gaps and panel padding, retaining rem units. */
6
+ readonly spacing?: number;
7
+ /** 0.75–1.5; scales all three control heights, inline padding and indicators, not fonts. */
8
+ readonly density?: number;
9
+ /** Pixels, 0–32. Checkbox still caps its inherited radius; Radio stays circular. */
10
+ readonly controlRadius?: number;
11
+ /** Pixels, 0–48. */
12
+ readonly surfaceRadius?: number;
13
+ /** Pixels, 0–4. */
14
+ readonly controlBorderWidth?: number;
15
+ readonly surfaceBorderWidth?: number;
16
+ readonly borderStyle?: 'solid' | 'dashed' | 'dotted';
17
+ /** 0 = none, 1 = baseline, 2 = raised, 3 = floating. Passive and overlay shadows only. */
18
+ readonly elevation?: 0 | 1 | 2 | 3;
19
+ /** 0–0.9; black modal backdrop. Panel filtering remains a component exception. */
20
+ readonly backdropOpacity?: number;
21
+ }
22
+ export interface ThemeAppearanceSettings {
23
+ readonly version?: 1;
24
+ readonly palette?: Pick<ColorPalette, 'version' | 'color' | 'surface'>;
25
+ readonly geometry?: ThemeSection<ThemeGeometrySettings>;
26
+ }
27
+ /** Apply generated color/canvas atomically and geometry leaves without erasing authored exceptions. */
28
+ export declare function updateThemeAppearance(document: ThemeDocument, settings: ThemeAppearanceSettings): ThemeDocument;
29
+ //# sourceMappingURL=updateThemeAppearance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateThemeAppearance.d.ts","sourceRoot":"","sources":["../../../src/themes/updateThemeAppearance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAGrE,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAE1E,mGAAmG;AACnG,MAAM,WAAW,qBAAqB;IACpC,wEAAwE;IACxE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,4FAA4F;IAC5F,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,oFAAoF;IACpF,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;IAC/B,oBAAoB;IACpB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;IAC/B,mBAAmB;IACnB,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IACpC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IACpC,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAA;IACpD,0FAA0F;IAC1F,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAClC,kFAAkF;IAClF,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAClC;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IACpB,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC,CAAA;IACtE,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC,qBAAqB,CAAC,CAAA;CACxD;AAoGD,uGAAuG;AACvG,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,aAAa,EACvB,QAAQ,EAAE,uBAAuB,GAChC,aAAa,CAsCf"}
@@ -0,0 +1,138 @@
1
+ import { tokenDefaults } from './tokens.js';
2
+ import { defineThemeDocument, updateThemeDocument } from './themeDocument.js';
3
+ const bounds = {
4
+ spacing: [0.5, 2],
5
+ density: [0.75, 1.5],
6
+ controlRadius: [0, 32],
7
+ surfaceRadius: [0, 48],
8
+ controlBorderWidth: [0, 4],
9
+ surfaceBorderWidth: [0, 4],
10
+ elevation: [0, 3],
11
+ backdropOpacity: [0, 0.9]
12
+ };
13
+ function record(value, path) {
14
+ if (!value || typeof value !== 'object' || Array.isArray(value))
15
+ throw new TypeError(`${path} must be an object.`);
16
+ }
17
+ function keys(value, allowed, path) {
18
+ for (const key of Object.keys(value))
19
+ if (!allowed.includes(key))
20
+ throw new TypeError(`Unknown ${path}.${key}.`);
21
+ }
22
+ function validate(value, path) {
23
+ record(value, path);
24
+ keys(value, [...Object.keys(bounds), 'borderStyle'], path);
25
+ for (const [key, item] of Object.entries(value)) {
26
+ if (item === undefined)
27
+ continue;
28
+ if (key === 'borderStyle') {
29
+ if (typeof item === 'string' && ['solid', 'dashed', 'dotted'].includes(item))
30
+ continue;
31
+ }
32
+ else {
33
+ const [min, max] = bounds[key];
34
+ if (typeof item === 'number' &&
35
+ Number.isFinite(item) &&
36
+ item >= min &&
37
+ item <= max &&
38
+ (key !== 'elevation' || Number.isInteger(item)))
39
+ continue;
40
+ throw new TypeError(`${path}.${key} must be a finite number from ${min} to ${max}${key === 'elevation' ? ' (integer)' : ''}.`);
41
+ }
42
+ throw new TypeError(`${path}.borderStyle must be solid, dashed or dotted.`);
43
+ }
44
+ }
45
+ const scaled = (rem, factor) => `${Number((parseFloat(rem) * factor).toFixed(6))}rem`;
46
+ function geometryTokens(settings, mode) {
47
+ const base = tokenDefaults[mode];
48
+ const spacing = {};
49
+ const control = {};
50
+ const surface = {};
51
+ if (settings.spacing !== undefined) {
52
+ for (const [key, value] of Object.entries(base.spacing))
53
+ spacing[key] = scaled(value, settings.spacing);
54
+ for (const key of ['padding', 'gap'])
55
+ surface[key] = scaled(base.surface[key], settings.spacing);
56
+ }
57
+ if (settings.density !== undefined)
58
+ for (const size of ['small', 'medium', 'large']) {
59
+ const metrics = {};
60
+ for (const key of ['height', 'paddingInline', 'indicatorSize'])
61
+ metrics[key] = scaled(base.control[size][key], settings.density);
62
+ control[size] = metrics;
63
+ }
64
+ for (const [key, target] of [
65
+ ['Radius', 'radius'],
66
+ ['BorderWidth', 'borderWidth']
67
+ ]) {
68
+ const a = settings[`control${key}`], b = settings[`surface${key}`];
69
+ if (a !== undefined)
70
+ control[target] = `${a}px`;
71
+ if (b !== undefined)
72
+ surface[target] = `${b}px`;
73
+ }
74
+ if (settings.borderStyle !== undefined)
75
+ control.borderStyle = surface.borderStyle = settings.borderStyle;
76
+ if (settings.elevation !== undefined) {
77
+ const level = settings.elevation;
78
+ surface.shadow =
79
+ level === 0
80
+ ? 'none'
81
+ : level === 1
82
+ ? base.surface.shadow
83
+ : `0 ${level * 2}px ${level * 6}px -2px rgb(0 0 0 / ${mode === 'light' ? 0.12 : 0.4})`;
84
+ surface.overlayShadow =
85
+ level === 0
86
+ ? 'none'
87
+ : level === 1
88
+ ? base.surface.overlayShadow
89
+ : `0 ${level * 12}px ${level * 32}px -16px rgb(0 0 0 / ${mode === 'light' ? 0.3 : 0.6})`;
90
+ }
91
+ if (settings.backdropOpacity !== undefined)
92
+ surface.backdrop = `rgb(0 0 0 / ${settings.backdropOpacity})`;
93
+ return {
94
+ ...(Object.keys(spacing).length ? { spacing } : {}),
95
+ ...(Object.keys(control).length ? { control } : {}),
96
+ ...(Object.keys(surface).length ? { surface } : {})
97
+ };
98
+ }
99
+ /** Apply generated color/canvas atomically and geometry leaves without erasing authored exceptions. */
100
+ export function updateThemeAppearance(document, settings) {
101
+ record(settings, 'appearance');
102
+ keys(settings, ['version', 'palette', 'geometry'], 'appearance');
103
+ if (settings.version !== undefined && settings.version !== 1)
104
+ throw new TypeError('Unsupported appearance.version; expected 1.');
105
+ let next = defineThemeDocument(document);
106
+ if (settings.palette !== undefined) {
107
+ record(settings.palette, 'appearance.palette');
108
+ if (settings.palette.version !== 1)
109
+ throw new TypeError('appearance.palette.version must be 1.');
110
+ record(settings.palette.color, 'appearance.palette.color');
111
+ record(settings.palette.surface, 'appearance.palette.surface');
112
+ next = updateThemeDocument(next, { color: settings.palette.color }, 'replace');
113
+ next = updateThemeDocument(next, { surface: settings.palette.surface });
114
+ }
115
+ const geometry = settings.geometry;
116
+ if (geometry === undefined)
117
+ return next;
118
+ record(geometry, 'appearance.geometry');
119
+ keys(geometry, ['values', 'modes'], 'appearance.geometry');
120
+ if (geometry.values !== undefined)
121
+ validate(geometry.values, 'appearance.geometry.values');
122
+ if (geometry.modes !== undefined) {
123
+ record(geometry.modes, 'appearance.geometry.modes');
124
+ keys(geometry.modes, ['light', 'dark'], 'appearance.geometry.modes');
125
+ }
126
+ for (const mode of ['light', 'dark']) {
127
+ if (geometry.modes?.[mode] !== undefined)
128
+ validate(geometry.modes[mode], `appearance.geometry.modes.${mode}`);
129
+ const values = { ...geometry.values };
130
+ for (const [key, value] of Object.entries(geometry.modes?.[mode] ?? {}))
131
+ if (value !== undefined)
132
+ Object.assign(values, { [key]: value });
133
+ const tokens = geometryTokens(values, mode);
134
+ next = updateThemeDocument(next, Object.fromEntries(Object.entries(tokens).map(([group, value]) => [group, { modes: { [mode]: value } }])));
135
+ }
136
+ return next;
137
+ }
138
+ //# sourceMappingURL=updateThemeAppearance.js.map