@motion-proto/live-tokens 0.7.1 → 0.9.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 (96) hide show
  1. package/.claude/skills/live-tokens-add-component/SKILL.md +488 -0
  2. package/README.md +34 -0
  3. package/dist-plugin/index.cjs +707 -90
  4. package/dist-plugin/index.d.cts +1 -0
  5. package/dist-plugin/index.d.ts +1 -0
  6. package/dist-plugin/index.js +707 -90
  7. package/package.json +6 -2
  8. package/src/app/site.css +1 -1
  9. package/src/editor/component-editor/CollapsibleSectionEditor.svelte +34 -27
  10. package/src/editor/component-editor/DialogEditor.svelte +4 -4
  11. package/src/editor/component-editor/NotificationEditor.svelte +3 -1
  12. package/src/editor/component-editor/SectionDividerEditor.svelte +439 -112
  13. package/src/editor/component-editor/StandardButtonsEditor.svelte +13 -1
  14. package/src/editor/component-editor/editors.d.ts +10 -0
  15. package/src/editor/component-editor/index.ts +16 -1
  16. package/src/editor/component-editor/registry.ts +103 -26
  17. package/src/editor/component-editor/scaffolding/AngleDial.svelte +52 -13
  18. package/src/editor/component-editor/scaffolding/ComponentFileManager.svelte +10 -11
  19. package/src/editor/component-editor/scaffolding/ComponentsTab.svelte +2 -2
  20. package/src/editor/component-editor/scaffolding/LinkedBlock.svelte +0 -1
  21. package/src/editor/component-editor/scaffolding/RadialShapePad.svelte +483 -0
  22. package/src/editor/component-editor/scaffolding/ShadowBackdrop.svelte +15 -2
  23. package/src/editor/component-editor/scaffolding/StateBlock.svelte +103 -15
  24. package/src/editor/component-editor/scaffolding/TokenLayout.svelte +9 -6
  25. package/src/editor/component-editor/scaffolding/TypeEditor.svelte +13 -1
  26. package/src/editor/component-editor/scaffolding/VariantGroup.svelte +239 -25
  27. package/src/editor/component-editor/scaffolding/buildTypeGroupTokens.ts +1 -0
  28. package/src/editor/component-editor/scaffolding/componentSources.ts +3 -3
  29. package/src/editor/component-editor/scaffolding/defaultSections.ts +15 -10
  30. package/src/editor/component-editor/scaffolding/types.ts +11 -0
  31. package/src/editor/core/components/componentConfigKeys.ts +22 -3
  32. package/src/editor/core/components/componentConfigService.ts +2 -2
  33. package/src/editor/core/components/componentPersist.ts +7 -5
  34. package/src/editor/core/manifests/manifestService.ts +58 -3
  35. package/src/editor/core/palettes/familySwap.ts +99 -0
  36. package/src/editor/core/palettes/paletteDerivation.ts +69 -0
  37. package/src/editor/core/palettes/tokenRegistry.ts +4 -1
  38. package/src/editor/core/store/editorStore.ts +206 -12
  39. package/src/editor/core/store/editorTypes.ts +55 -12
  40. package/src/editor/core/store/gradientSource.ts +192 -0
  41. package/src/editor/core/themes/migrations/2026-05-19-collapsiblesection-drop-frame-surface.ts +28 -0
  42. package/src/editor/core/themes/migrations/2026-05-19-sectiondivider-rich-gradient.ts +35 -0
  43. package/src/editor/core/themes/migrations/2026-05-20-sectiondivider-slim-variants.ts +82 -0
  44. package/src/editor/core/themes/migrations/2026-05-21-sectiondivider-spacing-to-padding.ts +24 -0
  45. package/src/editor/core/themes/migrations/2026-05-22-sectiondivider-intrinsics-to-css.ts +81 -0
  46. package/src/editor/core/themes/migrations/index.ts +10 -0
  47. package/src/editor/core/themes/slices/components.ts +27 -4
  48. package/src/editor/core/themes/slices/gradients.ts +88 -13
  49. package/src/editor/core/themes/themeInit.ts +2 -2
  50. package/src/editor/core/themes/themeTypes.ts +56 -1
  51. package/src/editor/index.ts +10 -1
  52. package/src/editor/overlay/ColumnsOverlay.svelte +0 -1
  53. package/src/editor/overlay/LiveEditorOverlay.svelte +1 -4
  54. package/src/editor/pages/ComponentEditorPage.svelte +53 -3
  55. package/src/editor/pages/EditorShell.svelte +53 -3
  56. package/src/editor/styles/ui-editor.css +1 -0
  57. package/src/editor/styles/ui-form-controls.css +19 -20
  58. package/src/editor/ui/BezierCurveEditor.svelte +114 -63
  59. package/src/editor/ui/EditorViewSwitcher.svelte +0 -1
  60. package/src/editor/ui/FileLoadList.svelte +22 -5
  61. package/src/editor/ui/FontStackEditor.svelte +214 -76
  62. package/src/editor/ui/GradientEditor.svelte +435 -215
  63. package/src/editor/ui/GradientStopPicker.svelte +11 -3
  64. package/src/editor/ui/ManifestFileManager.svelte +71 -4
  65. package/src/editor/ui/PaletteEditor.svelte +52 -79
  66. package/src/editor/ui/ProjectFontsSection.svelte +328 -293
  67. package/src/editor/ui/ThemeFileManager.svelte +0 -4
  68. package/src/editor/ui/UIFontFamilySelector.svelte +0 -1
  69. package/src/editor/ui/UIFontSizeSelector.svelte +3 -0
  70. package/src/editor/ui/UIInfoPopover.svelte +0 -1
  71. package/src/editor/ui/UILetterSpacingSelector.svelte +65 -0
  72. package/src/editor/ui/UIPaletteSelector.svelte +31 -4
  73. package/src/editor/ui/UIPillButton.svelte +33 -3
  74. package/src/editor/ui/UISegmentedControl.svelte +114 -0
  75. package/src/editor/ui/UITokenSelector.svelte +4 -1
  76. package/src/editor/ui/VariablesTab.svelte +41 -35
  77. package/src/editor/ui/palette/OverridesPanel.svelte +14 -37
  78. package/src/editor/ui/palette/PaletteBase.svelte +3 -3
  79. package/src/editor/ui/sections/ColumnsSection.svelte +1 -2
  80. package/src/editor/ui/sections/GradientsSection.svelte +1 -1
  81. package/src/editor/ui/sections/OverlaysSection.svelte +1 -1
  82. package/src/editor/ui/sections/ShadowsSection.svelte +1 -1
  83. package/src/system/components/Button.svelte +2 -2
  84. package/src/system/components/Card.svelte +29 -1
  85. package/src/system/components/CollapsibleSection.svelte +25 -2
  86. package/src/system/components/Dialog.svelte +24 -4
  87. package/src/system/components/FloatingTokenTags.css +43 -24
  88. package/src/system/components/FloatingTokenTags.svelte +88 -137
  89. package/src/system/components/Notification.svelte +8 -1
  90. package/src/system/components/SectionDivider.svelte +532 -381
  91. package/src/system/styles/CONVENTIONS.md +1 -1
  92. package/src/system/styles/fonts.css +3 -16
  93. package/src/system/styles/tokens.css +356 -1199
  94. package/src/system/styles/tokens.generated.css +544 -0
  95. package/src/editor/component-editor/scaffolding/DividerEditor.svelte +0 -94
  96. package/src/editor/component-editor/scaffolding/GradientCard.svelte +0 -296
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Family-aware token rewrites.
3
+ *
4
+ * Color tokens encode their palette family as a hyphen segment in the slug
5
+ * (e.g. `--border-canvas-strong` → `canvas`, `--surface-accent-low` →
6
+ * `accent`). Text tokens are special-cased: `--text-primary` carries no
7
+ * family, `--text-{family}` and `--text-{family}-{step}` do, and `--text-{step}`
8
+ * resolves to the neutral text scale.
9
+ *
10
+ * These helpers let editor flows (variant family swap, per-stop monochrome
11
+ * snap) rewrite a token slug without re-implementing the parser each time.
12
+ */
13
+
14
+ export const KNOWN_FAMILIES = [
15
+ 'neutral', 'alternate', 'canvas', 'brand',
16
+ 'accent', 'special', 'success', 'warning', 'info', 'danger',
17
+ ] as const;
18
+
19
+ export type FamilyName = (typeof KNOWN_FAMILIES)[number];
20
+
21
+ export const TEXT_STEPS = ['primary', 'secondary', 'tertiary', 'muted', 'disabled'] as const;
22
+
23
+ export type TextStep = (typeof TEXT_STEPS)[number];
24
+
25
+ /** Parse a text-scale token name into family + step. Returns null for any
26
+ * non-`--text-*` slug or one whose parts don't resolve to a known step. */
27
+ export function parseTextToken(colorRef: string): { family: FamilyName; step: TextStep } | null {
28
+ if (!colorRef.startsWith('--text-')) return null;
29
+ const rest = colorRef.slice('--text-'.length);
30
+ const parts = rest.split('-');
31
+ if (parts.length === 1) {
32
+ const p = parts[0];
33
+ if ((TEXT_STEPS as readonly string[]).includes(p)) return { family: 'neutral', step: p as TextStep };
34
+ if ((KNOWN_FAMILIES as readonly string[]).includes(p)) return { family: p as FamilyName, step: 'primary' };
35
+ return null;
36
+ }
37
+ if (parts.length === 2) {
38
+ const [fam, step] = parts;
39
+ if (
40
+ (KNOWN_FAMILIES as readonly string[]).includes(fam)
41
+ && (TEXT_STEPS as readonly string[]).includes(step)
42
+ ) {
43
+ return { family: fam as FamilyName, step: step as TextStep };
44
+ }
45
+ }
46
+ return null;
47
+ }
48
+
49
+ /** Inverse of parseTextToken — assemble a `--text-*` slug from family + step.
50
+ * `neutral` family flattens to `--text-{step}`; `primary` step on a named
51
+ * family flattens to `--text-{family}` (matches authoring conventions). */
52
+ export function buildTextToken(family: FamilyName | string, step: TextStep | string): string {
53
+ if (family === 'neutral') return `--text-${step}`;
54
+ return step === 'primary' ? `--text-${family}` : `--text-${family}-${step}`;
55
+ }
56
+
57
+ /** Pull the family marker out of a token slug, or null if none of the
58
+ * hyphen-delimited parts is a known family. */
59
+ export function detectFamily(colorRef: string): FamilyName | null {
60
+ if (!colorRef.startsWith('--')) return null;
61
+ const parts = colorRef.slice(2).split('-');
62
+ for (const p of parts) {
63
+ if ((KNOWN_FAMILIES as readonly string[]).includes(p)) return p as FamilyName;
64
+ }
65
+ return null;
66
+ }
67
+
68
+ /** Rewrite the family marker in a slug from `oldFamily` to `newFamily`.
69
+ * Returns the input unchanged when the slug doesn't reference `oldFamily`
70
+ * (so unrelated tokens, literals, and out-of-family stops fall through). */
71
+ export function swapTokenFamily(name: string, oldFamily: string, newFamily: string): string {
72
+ if (!name.startsWith('--')) return name;
73
+ const text = parseTextToken(name);
74
+ if (text) {
75
+ if (text.family !== oldFamily) return name;
76
+ return buildTextToken(newFamily, text.step);
77
+ }
78
+ const parts = name.slice(2).split('-');
79
+ const idx = parts.indexOf(oldFamily);
80
+ if (idx < 0) return name;
81
+ parts[idx] = newFamily;
82
+ return '--' + parts.join('-');
83
+ }
84
+
85
+ /** Coerce a slug to the given target family. Unlike swapTokenFamily this
86
+ * doesn't need to know the source family — it autodetects, then rewrites.
87
+ * Returns the input unchanged if no family is present (e.g. literal colors,
88
+ * `transparent`, or a `--text-primary` neutral). */
89
+ export function snapTokenToFamily(name: string, targetFamily: string): string {
90
+ if (!name.startsWith('--')) return name;
91
+ const text = parseTextToken(name);
92
+ if (text) {
93
+ if (text.family === targetFamily) return name;
94
+ return buildTextToken(targetFamily, text.step);
95
+ }
96
+ const fromFamily = detectFamily(name);
97
+ if (!fromFamily || fromFamily === targetFamily) return name;
98
+ return swapTokenFamily(name, fromFamily, targetFamily);
99
+ }
@@ -298,3 +298,72 @@ export function palettesToVars(palettes: Record<string, PaletteConfig>): Record<
298
298
  }
299
299
  return out;
300
300
  }
301
+
302
+ const HEX_RE = /^#[0-9a-f]{6}$/i;
303
+
304
+ /**
305
+ * Reconcile palette typed state against the catch-all `cssVariables` bag and
306
+ * report the set of variable names the typed slice now owns. Two operations:
307
+ *
308
+ * - **Snap** (gated by `_imported`): for any palette whose `_imported` flag
309
+ * is true, the imported `--color-{ns}-500` value is treated as the
310
+ * authoritative anchor. Chromatic palettes get `baseColor` snapped to it;
311
+ * gray palettes (Neutral/Alternate) get `tintHue` + `tintChroma` derived
312
+ * from it via OKLCH. The flag is then cleared. Editor-authored palettes
313
+ * (no `_imported`) are left untouched — see `temp/manifest-robustness-plan.md`
314
+ * §9 for why "snap on any divergence" was wrong: it would have flipped
315
+ * `themes/default.json`'s accent from teal to olive on first read.
316
+ *
317
+ * - **Consume** (always): every variable the palette's derivation produces
318
+ * is reported in `consumed` so the caller can strip it from
319
+ * `cssVariables`. The renderer (`editorRenderer.ts:42`) overlays
320
+ * `palettesToVars(palettes)` on top of `cssVariables` regardless, so
321
+ * stripped keys were dead data anyway. Stripping makes the file
322
+ * invariant explicit: catch-all carries only tokens no typed slice owns.
323
+ *
324
+ * Returns the updated palette map plus the two sets. Pure: no DOM, no I/O,
325
+ * no module state. Idempotent on second call with the same input (no anchor
326
+ * to snap to after first call's strip).
327
+ */
328
+ export function reconcilePalettesFromCssVars(
329
+ palettes: Record<string, PaletteConfig>,
330
+ cssVars: Record<string, string>,
331
+ ): {
332
+ palettes: Record<string, PaletteConfig>;
333
+ consumed: ReadonlySet<string>;
334
+ snapped: ReadonlySet<string>;
335
+ } {
336
+ const next: Record<string, PaletteConfig> = structuredClone(palettes);
337
+ const consumed = new Set<string>();
338
+ const snapped = new Set<string>();
339
+
340
+ for (const spec of PALETTE_SPECS) {
341
+ const current = next[spec.label];
342
+ if (current === undefined) continue;
343
+
344
+ if (current._imported === true) {
345
+ const anchorHex = cssVars[`--color-${spec.cssNamespace}-500`];
346
+ if (anchorHex && HEX_RE.test(anchorHex.trim())) {
347
+ const hex = anchorHex.trim();
348
+ if (spec.mode === 'gray') {
349
+ const { c, h } = hexToOklch(hex);
350
+ next[spec.label] = { ...current, tintHue: h, tintChroma: c, _imported: false };
351
+ } else {
352
+ next[spec.label] = { ...current, baseColor: hex, _imported: false };
353
+ }
354
+ snapped.add(spec.label);
355
+ } else {
356
+ // No anchor in cssVariables to snap to — flag has nothing to do; clear
357
+ // it so subsequent calls don't keep checking. Safe because the renderer
358
+ // is going to overlay palettesToVars anyway.
359
+ next[spec.label] = { ...current, _imported: false };
360
+ }
361
+ }
362
+
363
+ for (const k of Object.keys(derivePaletteVars(spec, next[spec.label]))) {
364
+ consumed.add(k);
365
+ }
366
+ }
367
+
368
+ return { palettes: next, consumed, snapped };
369
+ }
@@ -23,6 +23,7 @@ import tokensCss from '../../../system/styles/tokens.css?raw';
23
23
  import { editorState } from '../store/editorStore';
24
24
  import type { EditorState } from '../store/editorTypes';
25
25
  import { extractGlobalRootBody } from '../themes/parsers/globalRootBlock';
26
+ import { formatGradientValue } from '../themes/slices/gradients';
26
27
 
27
28
  // Re-exported for tests and downstream consumers that previously imported it
28
29
  // from this module. The canonical implementation lives in `./parsers/globalRootBlock`
@@ -111,7 +112,9 @@ function buildOverlayRegistry(
111
112
  const overrides = new Map<string, string>();
112
113
  for (const slice of Object.values(components)) {
113
114
  for (const [varName, ref] of Object.entries(slice.aliases)) {
114
- overrides.set(varName, ref.kind === 'token' ? `var(${ref.name})` : ref.value);
115
+ if (ref.kind === 'token') overrides.set(varName, `var(${ref.name})`);
116
+ else if (ref.kind === 'literal') overrides.set(varName, ref.value);
117
+ else overrides.set(varName, formatGradientValue(ref.value));
115
118
  }
116
119
  }
117
120
  const getDeclared = (v: string): string | null =>
@@ -18,8 +18,8 @@
18
18
  * orchestrate across slices and stay here.
19
19
  */
20
20
 
21
- import type { CssVarRef, EditorState } from './editorTypes';
22
- import type { Theme } from '../themes/themeTypes';
21
+ import type { CssVarRef, EditorState, GradientAliasValue } from './editorTypes';
22
+ import type { AliasDiskValue, Theme } from '../themes/themeTypes';
23
23
  import { KNOWN_COMPONENT_CONFIG_KEYS } from '../components/componentConfigKeys';
24
24
  import {
25
25
  CURRENT_THEME_SCHEMA_VERSION,
@@ -205,12 +205,200 @@ export {
205
205
  // literal-valued knobs (per `KNOWN_COMPONENT_CONFIG_KEYS`) into the config
206
206
  // bucket and wraps the remainder as `CssVarRef` discriminated unions.
207
207
 
208
+ /**
209
+ * Migrate a disk-shape alias bag through the registered migration runner.
210
+ *
211
+ * The runner is string-typed by contract (most migrations only do
212
+ * key/value string rewrites). Object-valued entries — currently just
213
+ * inline `{ kind: 'gradient', value: ... }` payloads — pass through
214
+ * untouched: we split the bag into string/object subsets, run the runner
215
+ * on the string subset, then merge.
216
+ *
217
+ * For sectiondivider's legacy 7-flat-token gradients we run a synthesis
218
+ * step BEFORE the migration runner that would strip those tokens. The
219
+ * synthesized gradient object lands in the object subset and survives
220
+ * the stripping pass.
221
+ */
208
222
  function migrateComponentAliases(
209
223
  component: string,
210
- aliases: Record<string, string>,
224
+ aliasesIn: Record<string, AliasDiskValue>,
225
+ rawConfig: Record<string, unknown> | undefined,
211
226
  fileVersion: number,
212
- ): Record<string, string> {
213
- return runMigrations('component-config', fileVersion, aliases, { component });
227
+ ): { aliases: Record<string, AliasDiskValue>; config: Record<string, unknown> } {
228
+ const stringPart: Record<string, string> = {};
229
+ const objectPart: Record<string, AliasDiskValue> = {};
230
+ for (const [k, v] of Object.entries(aliasesIn)) {
231
+ if (typeof v === 'string') stringPart[k] = v;
232
+ else objectPart[k] = v;
233
+ }
234
+ // String-valued config entries join the migration input so a migration can
235
+ // rename or relocate them. After migration the bag flows through
236
+ // `splitAliasesAndConfig` which routes KNOWN keys back to config and the
237
+ // rest to aliases — this is what lets a migration *move* a key from the
238
+ // config bucket to the aliases bucket by also removing it from KNOWN.
239
+ // Config wins over an aliases-bucket collision on the same key: the legacy
240
+ // single-bucket → split-bucket move preserved "explicit config field beats
241
+ // legacy alias-bucketed value", and that contract still holds.
242
+ // Non-string config values (rare; reserved for future structured payloads)
243
+ // pass through untouched.
244
+ const configOut: Record<string, unknown> = {};
245
+ for (const [k, v] of Object.entries(rawConfig ?? {})) {
246
+ if (typeof v === 'string') stringPart[k] = v;
247
+ else configOut[k] = v;
248
+ }
249
+ if (component === 'sectiondivider') {
250
+ synthesizeSectionDividerGradients(stringPart, objectPart);
251
+ }
252
+ const migratedString = runMigrations('component-config', fileVersion, stringPart, { component });
253
+ const migratedObject = component === 'sectiondivider'
254
+ ? renameSectionDividerObjectSlots(objectPart)
255
+ : objectPart;
256
+ return {
257
+ aliases: { ...migratedString, ...migratedObject },
258
+ config: configOut,
259
+ };
260
+ }
261
+
262
+ /**
263
+ * v8→v9 companion to `componentMigration_2026_05_20_sectiondividerSlimVariants`:
264
+ * the structured background payload is reshaped from six color families →
265
+ * three size variants (lg/md/sm). Canvas's gradient is taken as the canonical
266
+ * seed and fanned across all three new variants; other families' gradients
267
+ * are dropped. Idempotent — keys already at the final shape pass through.
268
+ *
269
+ * Sources accepted (in priority order, first-found wins for canvas's slot):
270
+ * --sectiondivider-canvas-background (current/in-progress shape)
271
+ * --sectiondivider-canvas-gradient (v7-era shape)
272
+ * --sectiondivider-color-canvas-background (intermediate shape that landed
273
+ * briefly during the color-prop pivot)
274
+ *
275
+ * The migration runner only sees string keys, so this object-shape rename
276
+ * has to live alongside the runner call.
277
+ */
278
+ const FAMILIES = ['canvas', 'neutral', 'alternate', 'primary', 'accent', 'special'] as const;
279
+ const SIZE_VARIANTS = ['lg', 'md', 'sm'] as const;
280
+ function renameSectionDividerObjectSlots(
281
+ objectPart: Record<string, AliasDiskValue>,
282
+ ): Record<string, AliasDiskValue> {
283
+ // Find canvas's gradient under any historical key shape.
284
+ const canvasSourceKeys = [
285
+ '--sectiondivider-canvas-background',
286
+ '--sectiondivider-canvas-gradient',
287
+ '--sectiondivider-color-canvas-background',
288
+ ];
289
+ let canvasGradient: AliasDiskValue | undefined;
290
+ for (const key of canvasSourceKeys) {
291
+ if (objectPart[key] !== undefined) {
292
+ canvasGradient = objectPart[key];
293
+ break;
294
+ }
295
+ }
296
+
297
+ // If we found a canvas gradient (any era), fan it into the three new
298
+ // per-variant background slots and drop every other family's gradient.
299
+ // If no canvas gradient is found, pass through non-family keys verbatim
300
+ // so non-migration data (theme tokens, other components) isn't touched.
301
+ const out: Record<string, AliasDiskValue> = {};
302
+ for (const [key, value] of Object.entries(objectPart)) {
303
+ // Skip any sectiondivider per-family gradient; the canvas fan-out emits
304
+ // the canonical set below.
305
+ let isFamilyGradient = false;
306
+ for (const f of FAMILIES) {
307
+ if (
308
+ key === `--sectiondivider-${f}-background`
309
+ || key === `--sectiondivider-${f}-gradient`
310
+ || key === `--sectiondivider-color-${f}-background`
311
+ ) {
312
+ isFamilyGradient = true;
313
+ break;
314
+ }
315
+ }
316
+ // Pass through anything that's already at the final lg/md/sm shape so
317
+ // re-running the migration is idempotent.
318
+ if (isFamilyGradient) continue;
319
+ out[key] = value;
320
+ }
321
+ if (canvasGradient !== undefined) {
322
+ for (const v of SIZE_VARIANTS) {
323
+ out[`--sectiondivider-${v}-background`] = canvasGradient;
324
+ }
325
+ }
326
+ return out;
327
+ }
328
+
329
+ /** SectionDivider variants that ship gradient aliases. */
330
+ const SECTIONDIVIDER_VARIANTS = ['canvas', 'neutral', 'alternate', 'primary', 'accent', 'special'] as const;
331
+
332
+ /**
333
+ * Collapse legacy 7-flat-token gradients (`{angle, stop-{1,2,3}-{color,position}}`)
334
+ * for each sectiondivider variant into one structured gradient alias at
335
+ * `--sectiondivider-{v}-gradient`. The flat tokens stay in `stringPart`
336
+ * for the migration runner to strip; the structured payload joins
337
+ * `objectPart` so the merge produces the new shape.
338
+ *
339
+ * Skips variants that already declare a gradient alias (object form) so
340
+ * round-tripping doesn't overwrite user edits.
341
+ */
342
+ function synthesizeSectionDividerGradients(
343
+ stringPart: Record<string, string>,
344
+ objectPart: Record<string, AliasDiskValue>,
345
+ ): void {
346
+ const GRADIENT_ANGLE_TOKENS: Record<string, number> = {
347
+ '--gradient-angle-horizontal': 90,
348
+ '--gradient-angle-vertical': 180,
349
+ '--gradient-angle-diagonal': 135,
350
+ '--gradient-angle-counter-diagonal': 45,
351
+ };
352
+ const GRADIENT_STOP_POSITIONS: Record<string, number> = {
353
+ '--gradient-stop-start': 0,
354
+ '--gradient-stop-mid': 50,
355
+ '--gradient-stop-end': 100,
356
+ };
357
+ const parseAngle = (raw: string | undefined): number => {
358
+ if (!raw) return 135;
359
+ if (raw.startsWith('--')) return GRADIENT_ANGLE_TOKENS[raw] ?? 135;
360
+ const m = raw.match(/^(-?\d+(?:\.\d+)?)\s*deg$/i);
361
+ return m ? parseFloat(m[1]) : 135;
362
+ };
363
+ const parsePosition = (raw: string | undefined, fallback: number): number => {
364
+ if (!raw) return fallback;
365
+ if (raw.startsWith('--')) return GRADIENT_STOP_POSITIONS[raw] ?? fallback;
366
+ const m = raw.match(/^(-?\d+(?:\.\d+)?)\s*%$/);
367
+ return m ? parseFloat(m[1]) : fallback;
368
+ };
369
+ const parseStopColor = (raw: string | undefined): { color: string; opacity?: number } | null => {
370
+ if (!raw) return null;
371
+ if (raw.startsWith('--')) return { color: raw };
372
+ const mix = raw.match(/^color-mix\(\s*in\s+srgb\s*,\s*var\((--[a-z0-9-]+)\)\s+([\d.]+)%\s*,\s*transparent\s*\)$/i);
373
+ if (mix) return { color: mix[1], opacity: parseFloat(mix[2]) };
374
+ return null;
375
+ };
376
+ for (const v of SECTIONDIVIDER_VARIANTS) {
377
+ const slot = `--sectiondivider-${v}-gradient`;
378
+ if (slot in objectPart) continue;
379
+ const angleKey = `${slot}-angle`;
380
+ const has1 = stringPart[`${slot}-stop-1-color`] !== undefined;
381
+ const has2 = stringPart[`${slot}-stop-2-color`] !== undefined;
382
+ const has3 = stringPart[`${slot}-stop-3-color`] !== undefined;
383
+ if (!has1 && !has2 && !has3) continue;
384
+ const stops: { position: number; color: string; opacity?: number }[] = [];
385
+ const positionDefaults = [0, 50, 100];
386
+ for (let i = 1; i <= 3; i++) {
387
+ const c = parseStopColor(stringPart[`${slot}-stop-${i}-color`]);
388
+ if (!c) continue;
389
+ const pos = parsePosition(stringPart[`${slot}-stop-${i}-position`], positionDefaults[i - 1]);
390
+ stops.push({ position: pos, color: c.color, ...(c.opacity !== undefined ? { opacity: c.opacity } : {}) });
391
+ }
392
+ if (stops.length < 2) continue;
393
+ objectPart[slot] = {
394
+ kind: 'gradient',
395
+ value: {
396
+ type: 'linear',
397
+ angle: parseAngle(stringPart[angleKey]),
398
+ stops,
399
+ },
400
+ };
401
+ }
214
402
  }
215
403
 
216
404
  /**
@@ -219,12 +407,18 @@ function migrateComponentAliases(
219
407
  * config bucket, and wraps the remainder as `CssVarRef` discriminated unions.
220
408
  */
221
409
  function splitAliasesAndConfig(
222
- rawAliases: Record<string, string>,
410
+ rawAliases: Record<string, AliasDiskValue>,
223
411
  rawConfig: Record<string, unknown> | undefined,
224
412
  ): { aliases: Record<string, CssVarRef>; config: Record<string, unknown> } {
225
413
  const aliases: Record<string, CssVarRef> = {};
226
414
  const config: Record<string, unknown> = { ...(rawConfig ?? {}) };
227
415
  for (const [key, value] of Object.entries(rawAliases)) {
416
+ if (typeof value !== 'string') {
417
+ if (value.kind === 'gradient') {
418
+ aliases[key] = { kind: 'gradient', value: value.value as GradientAliasValue };
419
+ }
420
+ continue;
421
+ }
228
422
  if (KNOWN_COMPONENT_CONFIG_KEYS.has(key)) {
229
423
  if (config[key] === undefined) config[key] = value;
230
424
  continue;
@@ -249,12 +443,12 @@ function splitAliasesAndConfig(
249
443
  export function loadComponentActive(
250
444
  component: string,
251
445
  activeFile: string,
252
- aliases: Record<string, string>,
446
+ aliases: Record<string, AliasDiskValue>,
253
447
  config?: Record<string, unknown>,
254
448
  schemaVersion: number = 0,
255
449
  ): void {
256
- const migrated = migrateComponentAliases(component, aliases, schemaVersion);
257
- const split = splitAliasesAndConfig(migrated, config);
450
+ const migrated = migrateComponentAliases(component, aliases, config, schemaVersion);
451
+ const split = splitAliasesAndConfig(migrated.aliases, migrated.config);
258
452
  mutate(`load ${component}/${activeFile}`, (s) => {
259
453
  s.components[component] = { activeFile, aliases: { ...split.aliases }, config: { ...split.config } };
260
454
  });
@@ -264,7 +458,7 @@ export function loadComponentActive(
264
458
 
265
459
  export interface ComponentSeed {
266
460
  activeFile: string;
267
- aliases: Record<string, string>;
461
+ aliases: Record<string, AliasDiskValue>;
268
462
  config?: Record<string, unknown>;
269
463
  schemaVersion?: number;
270
464
  }
@@ -282,8 +476,8 @@ export function seedComponentsFromApi(
282
476
  store.update((s) => {
283
477
  s.components = {};
284
478
  for (const [comp, cfg] of Object.entries(configs)) {
285
- const migrated = migrateComponentAliases(comp, cfg.aliases, cfg.schemaVersion ?? 0);
286
- const split = splitAliasesAndConfig(migrated, cfg.config);
479
+ const migrated = migrateComponentAliases(comp, cfg.aliases, cfg.config, cfg.schemaVersion ?? 0);
480
+ const split = splitAliasesAndConfig(migrated.aliases, migrated.config);
287
481
  s.components[comp] = { activeFile: cfg.activeFile, aliases: { ...split.aliases }, config: { ...split.config } };
288
482
  setSavedComponentBaseline(comp, componentBaseline(split));
289
483
  }
@@ -43,24 +43,25 @@ export interface ColumnsState {
43
43
  margin: number;
44
44
  }
45
45
 
46
- export type CssVarRef =
47
- | { kind: 'token'; name: string }
48
- | { kind: 'literal'; value: string };
49
-
50
- export interface ComponentSlice {
51
- activeFile: string;
52
- aliases: Record<string, CssVarRef>;
53
- config: Record<string, unknown>;
54
- unlinked?: string[];
55
- }
56
-
57
- export type GradientType = 'linear' | 'radial';
46
+ /** Gradient render mode.
47
+ * - `linear` / `radial`: real gradients with N stops + angle (linear) or radius (radial).
48
+ * - `solid`: collapses to the first stop's color. Angle/radius/extra stops carried in
49
+ * the payload but ignored by the renderer; toggling back restores the prior shape.
50
+ * - `none`: transparent. Same carry-forward semantics — payload retained for
51
+ * round-trip when the user toggles back to a real gradient. */
52
+ export type GradientType = 'linear' | 'radial' | 'solid' | 'none';
58
53
 
59
54
  export interface GradientTokenStop {
60
55
  /** 0–100 percentage along the gradient axis. */
61
56
  position: number;
62
57
  /** CSS variable name the stop resolves through (e.g. '--color-brand-500'). */
63
58
  color: string;
59
+ /** When `false`, this stop is an explicit off-palette override: the stop
60
+ * picker opens to any color (not family-filtered), and the stop is skipped
61
+ * by family-swap rewrites so its color survives a variant family change.
62
+ * Defaults to true (follow family) on read; absence is the same as `true`.
63
+ * Only meaningful for gradients rendered inside a family-aware context. */
64
+ monochrome?: boolean;
64
65
  /** 0–100 alpha applied to the stop's color. Defaults to 100 (fully opaque). */
65
66
  opacity?: number;
66
67
  }
@@ -71,9 +72,51 @@ export interface GradientToken {
71
72
  type: GradientType;
72
73
  /** Degrees, applies to linear only. */
73
74
  angle: number;
75
+ /** Pixel radius for radial gradients. When absent or zero, the renderer
76
+ * emits CSS's default ellipse/farthest-corner shape. */
77
+ radius?: number;
78
+ /** Horizontal center position for radial gradients, 0–100. Defaults to 50. */
79
+ centerX?: number;
80
+ /** Horizontal stretch factor for the radial ellipse (1–8). Defaults to 1.
81
+ * With aspectY, the rendered semi-axes are `radius * aspect*`, so both
82
+ * shape (ratio) and size are encoded together. Both = 1 keeps the legacy
83
+ * `circle` render path verbatim. */
84
+ aspectX?: number;
85
+ /** Vertical stretch factor for the radial ellipse (1–8). Defaults to 1. */
86
+ aspectY?: number;
74
87
  stops: GradientTokenStop[];
75
88
  }
76
89
 
90
+ /** Structured gradient payload carried inline on a component alias.
91
+ * Mirrors GradientToken minus `variable` (the alias key itself is the
92
+ * binding). Used when a component owns a per-instance gradient that
93
+ * doesn't share the theme-level `--gradient-N` library. */
94
+ export interface GradientAliasValue {
95
+ type: GradientType;
96
+ angle: number;
97
+ /** See GradientToken.radius. */
98
+ radius?: number;
99
+ /** See GradientToken.centerX. */
100
+ centerX?: number;
101
+ /** See GradientToken.aspectX. */
102
+ aspectX?: number;
103
+ /** See GradientToken.aspectY. */
104
+ aspectY?: number;
105
+ stops: GradientTokenStop[];
106
+ }
107
+
108
+ export type CssVarRef =
109
+ | { kind: 'token'; name: string }
110
+ | { kind: 'literal'; value: string }
111
+ | { kind: 'gradient'; value: GradientAliasValue };
112
+
113
+ export interface ComponentSlice {
114
+ activeFile: string;
115
+ aliases: Record<string, CssVarRef>;
116
+ config: Record<string, unknown>;
117
+ unlinked?: string[];
118
+ }
119
+
77
120
  /**
78
121
  * Single source of truth for everything a saved token file depends on, plus
79
122
  * the domain state currently scattered across VariablesTab local `let` fields.