@motion-proto/live-tokens 0.7.1 → 0.8.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.
- package/dist-plugin/index.cjs +707 -90
- package/dist-plugin/index.d.cts +1 -0
- package/dist-plugin/index.d.ts +1 -0
- package/dist-plugin/index.js +707 -90
- package/package.json +2 -1
- package/src/app/site.css +1 -1
- package/src/editor/component-editor/CollapsibleSectionEditor.svelte +34 -27
- package/src/editor/component-editor/DialogEditor.svelte +4 -4
- package/src/editor/component-editor/NotificationEditor.svelte +3 -1
- package/src/editor/component-editor/SectionDividerEditor.svelte +439 -112
- package/src/editor/component-editor/StandardButtonsEditor.svelte +13 -1
- package/src/editor/component-editor/editors.d.ts +10 -0
- package/src/editor/component-editor/scaffolding/AngleDial.svelte +52 -13
- package/src/editor/component-editor/scaffolding/ComponentFileManager.svelte +10 -11
- package/src/editor/component-editor/scaffolding/LinkedBlock.svelte +0 -1
- package/src/editor/component-editor/scaffolding/RadialShapePad.svelte +483 -0
- package/src/editor/component-editor/scaffolding/ShadowBackdrop.svelte +15 -2
- package/src/editor/component-editor/scaffolding/StateBlock.svelte +103 -15
- package/src/editor/component-editor/scaffolding/TokenLayout.svelte +9 -6
- package/src/editor/component-editor/scaffolding/TypeEditor.svelte +13 -1
- package/src/editor/component-editor/scaffolding/VariantGroup.svelte +239 -25
- package/src/editor/component-editor/scaffolding/buildTypeGroupTokens.ts +1 -0
- package/src/editor/component-editor/scaffolding/types.ts +11 -0
- package/src/editor/core/components/componentConfigKeys.ts +8 -0
- package/src/editor/core/components/componentConfigService.ts +2 -2
- package/src/editor/core/components/componentPersist.ts +7 -5
- package/src/editor/core/manifests/manifestService.ts +58 -3
- package/src/editor/core/palettes/familySwap.ts +99 -0
- package/src/editor/core/palettes/paletteDerivation.ts +69 -0
- package/src/editor/core/palettes/tokenRegistry.ts +4 -1
- package/src/editor/core/store/editorStore.ts +206 -12
- package/src/editor/core/store/editorTypes.ts +55 -12
- package/src/editor/core/store/gradientSource.ts +192 -0
- package/src/editor/core/themes/migrations/2026-05-19-collapsiblesection-drop-frame-surface.ts +28 -0
- package/src/editor/core/themes/migrations/2026-05-19-sectiondivider-rich-gradient.ts +35 -0
- package/src/editor/core/themes/migrations/2026-05-20-sectiondivider-slim-variants.ts +82 -0
- package/src/editor/core/themes/migrations/2026-05-21-sectiondivider-spacing-to-padding.ts +24 -0
- package/src/editor/core/themes/migrations/2026-05-22-sectiondivider-intrinsics-to-css.ts +81 -0
- package/src/editor/core/themes/migrations/index.ts +10 -0
- package/src/editor/core/themes/slices/components.ts +18 -4
- package/src/editor/core/themes/slices/gradients.ts +88 -13
- package/src/editor/core/themes/themeInit.ts +2 -2
- package/src/editor/core/themes/themeTypes.ts +56 -1
- package/src/editor/overlay/ColumnsOverlay.svelte +0 -1
- package/src/editor/overlay/LiveEditorOverlay.svelte +1 -4
- package/src/editor/styles/ui-editor.css +1 -0
- package/src/editor/styles/ui-form-controls.css +19 -20
- package/src/editor/ui/BezierCurveEditor.svelte +114 -63
- package/src/editor/ui/EditorViewSwitcher.svelte +0 -1
- package/src/editor/ui/FileLoadList.svelte +22 -5
- package/src/editor/ui/FontStackEditor.svelte +214 -76
- package/src/editor/ui/GradientEditor.svelte +435 -215
- package/src/editor/ui/GradientStopPicker.svelte +11 -3
- package/src/editor/ui/ManifestFileManager.svelte +71 -4
- package/src/editor/ui/PaletteEditor.svelte +52 -79
- package/src/editor/ui/ProjectFontsSection.svelte +328 -293
- package/src/editor/ui/ThemeFileManager.svelte +0 -4
- package/src/editor/ui/UIFontFamilySelector.svelte +0 -1
- package/src/editor/ui/UIFontSizeSelector.svelte +3 -0
- package/src/editor/ui/UIInfoPopover.svelte +0 -1
- package/src/editor/ui/UILetterSpacingSelector.svelte +65 -0
- package/src/editor/ui/UIPaletteSelector.svelte +31 -4
- package/src/editor/ui/UIPillButton.svelte +33 -3
- package/src/editor/ui/UISegmentedControl.svelte +114 -0
- package/src/editor/ui/UITokenSelector.svelte +4 -1
- package/src/editor/ui/VariablesTab.svelte +41 -35
- package/src/editor/ui/palette/OverridesPanel.svelte +14 -37
- package/src/editor/ui/palette/PaletteBase.svelte +3 -3
- package/src/editor/ui/sections/ColumnsSection.svelte +1 -2
- package/src/editor/ui/sections/GradientsSection.svelte +1 -1
- package/src/editor/ui/sections/OverlaysSection.svelte +1 -1
- package/src/editor/ui/sections/ShadowsSection.svelte +1 -1
- package/src/system/components/Button.svelte +2 -2
- package/src/system/components/Card.svelte +29 -1
- package/src/system/components/CollapsibleSection.svelte +25 -2
- package/src/system/components/FloatingTokenTags.css +43 -24
- package/src/system/components/FloatingTokenTags.svelte +88 -137
- package/src/system/components/Notification.svelte +8 -1
- package/src/system/components/SectionDivider.svelte +456 -379
- package/src/system/styles/CONVENTIONS.md +1 -1
- package/src/system/styles/fonts.css +3 -16
- package/src/system/styles/tokens.css +356 -1199
- package/src/system/styles/tokens.generated.css +544 -0
- package/src/editor/component-editor/scaffolding/DividerEditor.svelte +0 -94
- package/src/editor/component-editor/scaffolding/GradientCard.svelte +0 -296
|
@@ -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
|
-
|
|
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
|
-
|
|
224
|
+
aliasesIn: Record<string, AliasDiskValue>,
|
|
225
|
+
rawConfig: Record<string, unknown> | undefined,
|
|
211
226
|
fileVersion: number,
|
|
212
|
-
): Record<string, string> {
|
|
213
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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.
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source adapter for the visual gradient editor.
|
|
3
|
+
*
|
|
4
|
+
* `GradientEditor.svelte` was originally hard-wired to the theme-level
|
|
5
|
+
* gradient library (`state.gradients.tokens`). Components that own their
|
|
6
|
+
* own structured gradients (e.g. SectionDivider's per-variant slot) live
|
|
7
|
+
* in `state.components[...].aliases[...]` as a `kind: 'gradient'` ref.
|
|
8
|
+
*
|
|
9
|
+
* Wrapping both behind one source interface lets the editor read + write
|
|
10
|
+
* either backing store without leaking knowledge of which it's editing.
|
|
11
|
+
* The store-derived `current` field reactively exposes the current value;
|
|
12
|
+
* the mutator methods funnel each change through `mutate`, so undo /
|
|
13
|
+
* persistence still cover the edit identically to direct API calls.
|
|
14
|
+
*/
|
|
15
|
+
import { derived, get, type Readable } from 'svelte/store';
|
|
16
|
+
import { editorState } from './editorStore';
|
|
17
|
+
import type { GradientType, GradientTokenStop, GradientAliasValue, CssVarRef } from './editorTypes';
|
|
18
|
+
import {
|
|
19
|
+
setGradient,
|
|
20
|
+
setGradientType,
|
|
21
|
+
setGradientAngle,
|
|
22
|
+
setGradientCenterX,
|
|
23
|
+
setGradientAspect,
|
|
24
|
+
setGradientStop,
|
|
25
|
+
addGradientStop,
|
|
26
|
+
removeGradientStop,
|
|
27
|
+
} from '../themes/slices/gradients';
|
|
28
|
+
import { setComponentAlias } from '../themes/slices/components';
|
|
29
|
+
import { mutate } from './editorCore';
|
|
30
|
+
|
|
31
|
+
export interface GradientSourceSnapshot {
|
|
32
|
+
type: GradientType;
|
|
33
|
+
angle: number;
|
|
34
|
+
/** Horizontal center for radial gradients, 0–100. */
|
|
35
|
+
centerX?: number;
|
|
36
|
+
/** Per-axis stretch factors for the radial ellipse (1 = unscaled). */
|
|
37
|
+
aspectX?: number;
|
|
38
|
+
aspectY?: number;
|
|
39
|
+
stops: GradientTokenStop[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface GradientSource {
|
|
43
|
+
/** Reactive readable of the current gradient value (or undefined if missing). */
|
|
44
|
+
current: Readable<GradientSourceSnapshot | undefined>;
|
|
45
|
+
setAll(next: GradientSourceSnapshot): void;
|
|
46
|
+
setType(type: GradientType): void;
|
|
47
|
+
setAngle(angle: number): void;
|
|
48
|
+
setCenterX(centerX: number): void;
|
|
49
|
+
setAspect(aspect: { x: number; y: number }): void;
|
|
50
|
+
setStop(index: number, partial: Partial<GradientTokenStop>): void;
|
|
51
|
+
addStop(stop: GradientTokenStop): void;
|
|
52
|
+
removeStop(index: number): void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Adapter for `--gradient-N` library tokens in `state.gradients.tokens`. */
|
|
56
|
+
export function themeGradientSource(variable: string): GradientSource {
|
|
57
|
+
const current = derived(editorState, ($s) => {
|
|
58
|
+
const t = $s.gradients.tokens.find((g) => g.variable === variable);
|
|
59
|
+
if (!t) return undefined;
|
|
60
|
+
return {
|
|
61
|
+
type: t.type,
|
|
62
|
+
angle: t.angle,
|
|
63
|
+
centerX: t.centerX,
|
|
64
|
+
aspectX: t.aspectX,
|
|
65
|
+
aspectY: t.aspectY,
|
|
66
|
+
stops: t.stops.map((s) => ({ ...s })),
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
current,
|
|
71
|
+
setAll: (next) => setGradient(variable, next),
|
|
72
|
+
setType: (t) => setGradientType(variable, t),
|
|
73
|
+
setAngle: (a) => setGradientAngle(variable, a),
|
|
74
|
+
setCenterX: (x) => setGradientCenterX(variable, x),
|
|
75
|
+
setAspect: (a) => setGradientAspect(variable, a),
|
|
76
|
+
setStop: (i, p) => setGradientStop(variable, i, p),
|
|
77
|
+
addStop: (s) => addGradientStop(variable, s),
|
|
78
|
+
removeStop: (i) => removeGradientStop(variable, i),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function readComponentGradient(component: string, varName: string): GradientAliasValue | undefined {
|
|
83
|
+
const ref = get(editorState).components[component]?.aliases[varName];
|
|
84
|
+
return ref?.kind === 'gradient' ? ref.value : undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function writeComponentGradient(component: string, varName: string, value: GradientAliasValue): void {
|
|
88
|
+
const ref: CssVarRef = { kind: 'gradient', value };
|
|
89
|
+
setComponentAlias(component, varName, ref);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Adapter for component-owned gradients stored inline on a component alias. */
|
|
93
|
+
export function componentGradientSource(component: string, varName: string): GradientSource {
|
|
94
|
+
const current = derived(editorState, ($s) => {
|
|
95
|
+
const ref = $s.components[component]?.aliases[varName];
|
|
96
|
+
if (ref?.kind !== 'gradient') return undefined;
|
|
97
|
+
return {
|
|
98
|
+
type: ref.value.type,
|
|
99
|
+
angle: ref.value.angle,
|
|
100
|
+
centerX: ref.value.centerX,
|
|
101
|
+
aspectX: ref.value.aspectX,
|
|
102
|
+
aspectY: ref.value.aspectY,
|
|
103
|
+
stops: ref.value.stops.map((s) => ({ ...s })),
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
/** Read-modify-write through `mutate` so each edit is one history entry
|
|
107
|
+
* and the renderer + persistence cycle pick it up uniformly with the
|
|
108
|
+
* theme-gradient path. */
|
|
109
|
+
const update = (label: string, mutator: (g: GradientAliasValue) => void): void => {
|
|
110
|
+
mutate(label, (s) => {
|
|
111
|
+
const slice = s.components[component] ?? (s.components[component] = { activeFile: 'default', aliases: {}, config: {} });
|
|
112
|
+
const ref = slice.aliases[varName];
|
|
113
|
+
const base: GradientAliasValue =
|
|
114
|
+
ref?.kind === 'gradient'
|
|
115
|
+
? {
|
|
116
|
+
type: ref.value.type,
|
|
117
|
+
angle: ref.value.angle,
|
|
118
|
+
...(ref.value.centerX !== undefined ? { centerX: ref.value.centerX } : {}),
|
|
119
|
+
...(ref.value.aspectX !== undefined ? { aspectX: ref.value.aspectX } : {}),
|
|
120
|
+
...(ref.value.aspectY !== undefined ? { aspectY: ref.value.aspectY } : {}),
|
|
121
|
+
stops: ref.value.stops.map((st) => ({ ...st })),
|
|
122
|
+
}
|
|
123
|
+
: { type: 'linear', angle: 135, stops: [] };
|
|
124
|
+
mutator(base);
|
|
125
|
+
slice.aliases[varName] = { kind: 'gradient', value: base };
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
current,
|
|
130
|
+
setAll: (next) => writeComponentGradient(component, varName, {
|
|
131
|
+
type: next.type,
|
|
132
|
+
angle: next.angle,
|
|
133
|
+
...(next.centerX !== undefined ? { centerX: next.centerX } : {}),
|
|
134
|
+
...(next.aspectX !== undefined ? { aspectX: next.aspectX } : {}),
|
|
135
|
+
...(next.aspectY !== undefined ? { aspectY: next.aspectY } : {}),
|
|
136
|
+
stops: next.stops.map((s) => ({ ...s })),
|
|
137
|
+
}),
|
|
138
|
+
setType: (t) => update(`set gradient type ${varName}`, (g) => { g.type = t; }),
|
|
139
|
+
setAngle: (a) => update(`set gradient angle ${varName}`, (g) => { g.angle = a; }),
|
|
140
|
+
setCenterX: (x) => update(`set gradient center ${varName}`, (g) => { g.centerX = x; }),
|
|
141
|
+
setAspect: (a) => update(`set gradient aspect ${varName}`, (g) => {
|
|
142
|
+
// Drop axes that equal 1 so persisted JSON stays minimal and pre-aspect
|
|
143
|
+
// data round-trips unchanged.
|
|
144
|
+
if (a.x === 1) delete g.aspectX;
|
|
145
|
+
else g.aspectX = a.x;
|
|
146
|
+
if (a.y === 1) delete g.aspectY;
|
|
147
|
+
else g.aspectY = a.y;
|
|
148
|
+
}),
|
|
149
|
+
setStop: (i, p) => update(`set gradient stop ${varName}[${i}]`, (g) => {
|
|
150
|
+
const stop = g.stops[i];
|
|
151
|
+
if (!stop) return;
|
|
152
|
+
if (p.position !== undefined) stop.position = p.position;
|
|
153
|
+
if (p.color !== undefined) stop.color = p.color;
|
|
154
|
+
if (p.opacity !== undefined) stop.opacity = p.opacity;
|
|
155
|
+
// `monochrome: true` is the implicit default — drop the field on write
|
|
156
|
+
// so the persisted shape stays minimal. Only the explicit override
|
|
157
|
+
// (`false`) needs to live on the stop.
|
|
158
|
+
if (p.monochrome !== undefined) {
|
|
159
|
+
if (p.monochrome === false) stop.monochrome = false;
|
|
160
|
+
else delete stop.monochrome;
|
|
161
|
+
}
|
|
162
|
+
}),
|
|
163
|
+
addStop: (s) => update(`add gradient stop ${varName}`, (g) => {
|
|
164
|
+
g.stops.push({ ...s });
|
|
165
|
+
g.stops.sort((a, b) => a.position - b.position);
|
|
166
|
+
}),
|
|
167
|
+
removeStop: (i) => update(`remove gradient stop ${varName}[${i}]`, (g) => {
|
|
168
|
+
if (g.stops.length <= 2) return;
|
|
169
|
+
g.stops.splice(i, 1);
|
|
170
|
+
}),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Snapshot helper for save/cancel flows. */
|
|
175
|
+
export function snapshotGradient(source: GradientSource): GradientSourceSnapshot | null {
|
|
176
|
+
const cur = get(source.current);
|
|
177
|
+
if (!cur) return null;
|
|
178
|
+
return {
|
|
179
|
+
type: cur.type,
|
|
180
|
+
angle: cur.angle,
|
|
181
|
+
...(cur.centerX !== undefined ? { centerX: cur.centerX } : {}),
|
|
182
|
+
...(cur.aspectX !== undefined ? { aspectX: cur.aspectX } : {}),
|
|
183
|
+
...(cur.aspectY !== undefined ? { aspectY: cur.aspectY } : {}),
|
|
184
|
+
stops: cur.stops.map((s) => ({ ...s })),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Read the component-side current gradient value used to seed UI defaults
|
|
189
|
+
* outside the GradientSource flow (e.g. the Monochrome checkbox derivation). */
|
|
190
|
+
export function readComponentGradientSync(component: string, varName: string): GradientAliasValue | undefined {
|
|
191
|
+
return readComponentGradient(component, varName);
|
|
192
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Migration } from './index';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 2026-05-19: drop `--collapsiblesection-container-frame-surface`.
|
|
5
|
+
*
|
|
6
|
+
* The frame-surface token only ever painted the outer `.es-root` background.
|
|
7
|
+
* Since `.section-header` covers that area with its own per-state surface, the
|
|
8
|
+
* frame-surface was only visible where the (typically transparent) frame
|
|
9
|
+
* border zone exposed it — a ring around the header. That made the token
|
|
10
|
+
* read as a "border" while being labeled "surface color" in the editor.
|
|
11
|
+
*
|
|
12
|
+
* Frame is now pure chrome: border color, border width, corner radius. The
|
|
13
|
+
* per-state header surface tokens already cover all the legitimate surface
|
|
14
|
+
* needs of the Container variant.
|
|
15
|
+
*/
|
|
16
|
+
function dropFrameSurface(rawVars: Record<string, string>, meta: { component?: string }): Record<string, string> {
|
|
17
|
+
if (meta.component !== 'collapsiblesection') return rawVars;
|
|
18
|
+
const { '--collapsiblesection-container-frame-surface': _drop, ...rest } = rawVars;
|
|
19
|
+
return rest;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const componentMigration_2026_05_19_collapsiblesectionDropFrameSurface: Migration = {
|
|
23
|
+
id: '2026-05-19-collapsiblesection-drop-frame-surface',
|
|
24
|
+
fromVersion: 6,
|
|
25
|
+
toVersion: 7,
|
|
26
|
+
appliesTo: 'component-config',
|
|
27
|
+
apply: dropFrameSurface,
|
|
28
|
+
};
|