@motion-proto/live-tokens 0.50.0 → 0.53.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/.claude/skills/live-tokens-adjust-shape-space/SKILL.md +7 -1
- package/CHANGELOG.md +108 -0
- package/bin/adjust.mjs +16 -39
- package/bin/generate-theme.mjs +20 -6
- package/dist-plugin/adjust/index.cjs +781 -21
- package/dist-plugin/adjust/index.d.cts +2 -1
- package/dist-plugin/adjust/index.d.ts +2 -1
- package/dist-plugin/adjust/index.js +43 -21
- package/dist-plugin/{chunk-6OZFXIQI.js → chunk-232GZGQU.js} +207 -12
- package/dist-plugin/chunk-NE6N66EE.js +753 -0
- package/dist-plugin/{chunk-76TFDTJO.js → chunk-PB2JTK2H.js} +179 -128
- package/dist-plugin/{chunk-44RSTAII.js → chunk-TKZBVIW5.js} +33 -5
- package/dist-plugin/chunk-YR6GPXW2.js +129 -0
- package/dist-plugin/generateColorsAndType/index.cjs +135 -63
- package/dist-plugin/generateColorsAndType/index.d.cts +2 -1
- package/dist-plugin/generateColorsAndType/index.d.ts +2 -1
- package/dist-plugin/generateColorsAndType/index.js +28 -784
- package/dist-plugin/{themeTypes-DSwKq-bj.d.ts → index-DpTIRZ2H.d.cts} +67 -26
- package/dist-plugin/{themeTypes-DSwKq-bj.d.cts → index-DpTIRZ2H.d.ts} +67 -26
- package/dist-plugin/index.cjs +1254 -140
- package/dist-plugin/index.js +106 -82
- package/dist-plugin/migrateData/index.cjs +956 -14
- package/dist-plugin/migrateData/index.js +10 -3
- package/dist-plugin/tokensCssMigrations/index.cjs +71 -5
- package/dist-plugin/tokensCssMigrations/index.d.cts +20 -9
- package/dist-plugin/tokensCssMigrations/index.d.ts +20 -9
- package/dist-plugin/tokensCssMigrations/index.js +4 -1
- package/package.json +8 -4
- package/src/editor/component-editor/NotificationEditor.svelte +6 -0
- package/src/editor/component-editor/scaffolding/ComponentFileManager.svelte +9 -23
- package/src/editor/component-editor/scaffolding/LinkedBlock.svelte +8 -8
- package/src/editor/core/components/adjustAliases.ts +49 -22
- package/src/editor/core/components/aliasKinds.ts +7 -2
- package/src/editor/core/components/componentConfigService.ts +1 -1
- package/src/editor/core/palettes/oklch.ts +3 -137
- package/src/editor/core/palettes/paletteDerivation.ts +79 -37
- package/src/editor/core/store/editorStore.ts +7 -197
- package/src/editor/core/store/editorTypes.ts +9 -30
- package/src/editor/core/themes/generateColorsAndType.ts +18 -8
- package/src/editor/core/themes/lookSummary.ts +3 -25
- package/src/editor/core/themes/migrateComponentConfig.ts +205 -0
- package/src/editor/core/themes/migrations/2026-05-19-sectiondivider-rich-gradient.ts +1 -1
- package/src/editor/core/themes/migrations/2026-05-20-sectiondivider-slim-variants.ts +1 -1
- package/src/editor/core/themes/migrations/2026-05-22-sectiondivider-intrinsics-to-css.ts +1 -1
- package/src/editor/core/themes/parsers/gradient.ts +211 -0
- package/src/editor/core/themes/slices/gradients.ts +5 -58
- package/src/editor/core/themes/themeService.ts +22 -9
- package/src/editor/core/themes/themeTypes.ts +89 -27
- package/src/editor/docs/content/editing-tokens.md +6 -2
- package/src/editor/docs/content/themes-workflow.md +9 -11
- package/src/editor/docs/content/where-themes-live.md +2 -2
- package/src/editor/docs/content.generated.ts +3 -3
- package/src/editor/index.ts +1 -0
- package/src/editor/styles/ui-editor.css +5 -2
- package/src/editor/ui/BezierCurveEditor.svelte +90 -67
- package/src/editor/ui/PaletteEditor.svelte +180 -59
- package/src/editor/ui/ThemePanel.svelte +24 -15
- package/src/editor/ui/Toggle.svelte +36 -24
- package/src/editor/ui/UIPillButton.svelte +1 -1
- package/src/editor/ui/UIReveal.svelte +47 -0
- package/src/editor/ui/UISquareButton.svelte +1 -1
- package/src/editor/ui/colors/ColorStory.svelte +12 -8
- package/src/editor/ui/colors/ColorsTab.svelte +4 -5
- package/src/editor/ui/curveEngine.ts +101 -21
- package/src/editor/ui/palette/OverridesPanel.svelte +23 -8
- package/src/editor/ui/palette/PaletteBase.svelte +17 -78
- package/src/editor/ui/palette/PaletteJumpButton.svelte +3 -3
- package/src/editor/ui/palette/ScaleCurveEditor.svelte +110 -20
- package/src/editor/ui/palette/curveSummary.ts +20 -0
- package/src/editor/ui/palette/dockMagnify.ts +5 -13
- package/src/editor/ui/palette/paletteMath.ts +7 -4
- package/src/live-tokens/data/colors-and-type/autumn.json +528 -528
- package/src/live-tokens/data/colors-and-type/default.json +247 -247
- package/src/live-tokens/data/colors-and-type/halloween.json +532 -532
- package/src/live-tokens/data/colors-and-type/midnight-study.json +538 -538
- package/src/live-tokens/data/colors-and-type/ocean.json +521 -521
- package/src/live-tokens/data/colors-and-type/royal-velvet.json +532 -532
- package/src/live-tokens/data/colors-and-type/spring-meadow.json +504 -504
- package/src/live-tokens/data/colors-and-type/sunset.json +531 -531
- package/src/live-tokens/data/themes/autumn.json +604 -568
- package/src/live-tokens/data/themes/halloween.json +584 -583
- package/src/live-tokens/data/themes/midnight-study.json +673 -605
- package/src/live-tokens/data/themes/ocean.json +597 -561
- package/src/live-tokens/data/themes/royal-velvet.json +574 -573
- package/src/live-tokens/data/themes/spring-meadow.json +590 -556
- package/src/live-tokens/data/themes/sunset.json +632 -571
- package/src/live-tokens/data/tokens.generated.css +282 -282
- package/src/system/components/FloatingTokenTags.css +0 -1
- package/src/system/internal/backgroundContrast.ts +7 -0
- package/src/system/internal/oklch.ts +189 -0
- package/src/system/styles/tokens.css +283 -283
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PaletteConfig, FontSource, FontStack } from '../themes/themeTypes';
|
|
2
|
+
import type { GradientStop, GradientValue } from '../themes/parsers/gradient';
|
|
2
3
|
import type { HarmonyAxis } from '../palettes/colorHarmony';
|
|
3
4
|
|
|
4
5
|
export interface ShadowGlobals {
|
|
@@ -46,20 +47,9 @@ export interface ColumnsState {
|
|
|
46
47
|
* round-trip when the user toggles back to a real gradient. */
|
|
47
48
|
export type GradientType = 'linear' | 'radial' | 'solid' | 'none';
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
/** CSS variable name the stop resolves through (e.g. '--color-brand-500'). */
|
|
53
|
-
color: string;
|
|
54
|
-
/** When `false`, this stop is an explicit off-palette override: the stop
|
|
55
|
-
* picker opens to any color (not family-filtered), and the stop is skipped
|
|
56
|
-
* by family-swap rewrites so its color survives a variant family change.
|
|
57
|
-
* Defaults to true (follow family) on read; absence is the same as `true`.
|
|
58
|
-
* Only meaningful for gradients rendered inside a family-aware context. */
|
|
59
|
-
monochrome?: boolean;
|
|
60
|
-
/** 0–100 alpha applied to the stop's color. Defaults to 100 (fully opaque). */
|
|
61
|
-
opacity?: number;
|
|
62
|
-
}
|
|
50
|
+
/** One stop of a gradient. Defined by `themes/parsers/gradient`, which owns
|
|
51
|
+
* the shape so the CSS form and the persisted form cannot drift apart. */
|
|
52
|
+
export type GradientTokenStop = GradientStop;
|
|
63
53
|
|
|
64
54
|
export interface GradientToken {
|
|
65
55
|
/** Output CSS variable, e.g. '--gradient-1'. */
|
|
@@ -83,22 +73,11 @@ export interface GradientToken {
|
|
|
83
73
|
}
|
|
84
74
|
|
|
85
75
|
/** Structured gradient payload carried inline on a component alias.
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
angle: number;
|
|
92
|
-
/** See GradientToken.radius. */
|
|
93
|
-
radius?: number;
|
|
94
|
-
/** See GradientToken.centerX. */
|
|
95
|
-
centerX?: number;
|
|
96
|
-
/** See GradientToken.aspectX. */
|
|
97
|
-
aspectX?: number;
|
|
98
|
-
/** See GradientToken.aspectY. */
|
|
99
|
-
aspectY?: number;
|
|
100
|
-
stops: GradientTokenStop[];
|
|
101
|
-
}
|
|
76
|
+
* `GradientToken` minus `variable` (the alias key itself is the binding).
|
|
77
|
+
* Used when a component owns a per-instance gradient that doesn't share the
|
|
78
|
+
* theme-level `--gradient-N` library. Defined by `themes/parsers/gradient`,
|
|
79
|
+
* the module that serializes and parses this shape. */
|
|
80
|
+
export type GradientAliasValue = GradientValue;
|
|
102
81
|
|
|
103
82
|
export type CssVarRef =
|
|
104
83
|
/** An alias to a design token. `opacity` is an optional integer percent set
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* `dist-plugin/generateColorsAndType`, so keep this module Node-safe (no DOM).
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { hexToOklch, type Oklch } from '../palettes/oklch';
|
|
8
|
+
import { hexToOklch, cssColorToOklch, oklchToHexClamped, type Oklch } from '../palettes/oklch';
|
|
9
9
|
import {
|
|
10
10
|
PALETTE_SPECS,
|
|
11
11
|
PALETTE_STEPS,
|
|
@@ -201,6 +201,15 @@ function surfaceVars(): string[] {
|
|
|
201
201
|
];
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
+
/** Derived vars serialize as `oklch()` while the WCAG contrast API is
|
|
205
|
+
* sRGB-terminated (decision 7), so project back to hex at this boundary.
|
|
206
|
+
* Gradient `--page-bg` parses to null and is skipped, as it was when these
|
|
207
|
+
* call sites read hex directly. */
|
|
208
|
+
function varToHex(value: string | undefined): string | null {
|
|
209
|
+
const parsed = value ? cssColorToOklch(value) : null;
|
|
210
|
+
return parsed ? oklchToHexClamped(parsed.l, parsed.c, parsed.h) : null;
|
|
211
|
+
}
|
|
212
|
+
|
|
204
213
|
function worstSurface(
|
|
205
214
|
textHex: string,
|
|
206
215
|
vars: Record<string, string>,
|
|
@@ -208,8 +217,8 @@ function worstSurface(
|
|
|
208
217
|
let against = '';
|
|
209
218
|
let ratio = Infinity;
|
|
210
219
|
for (const surfVar of surfaceVars()) {
|
|
211
|
-
const surfHex = vars[surfVar];
|
|
212
|
-
if (!surfHex
|
|
220
|
+
const surfHex = varToHex(vars[surfVar]);
|
|
221
|
+
if (!surfHex) continue;
|
|
213
222
|
const r = contrastRatio(textHex, surfHex);
|
|
214
223
|
if (r < ratio) {
|
|
215
224
|
ratio = r;
|
|
@@ -248,17 +257,18 @@ function runContrastGate(
|
|
|
248
257
|
const vars = palettesToVars(configs);
|
|
249
258
|
let anyFixed = false;
|
|
250
259
|
for (const def of defs) {
|
|
251
|
-
const
|
|
252
|
-
if (!
|
|
260
|
+
const text = cssColorToOklch(vars[def.textVar] ?? '');
|
|
261
|
+
if (!text) continue;
|
|
262
|
+
const textHex = oklchToHexClamped(text.l, text.c, text.h);
|
|
253
263
|
const worst = worstSurface(textHex, vars);
|
|
254
264
|
if (worst.ratio >= def.floor) continue;
|
|
255
265
|
const cfg = configs[def.paletteLabel];
|
|
256
266
|
const seed = cfg.baseColor;
|
|
257
267
|
const solved = findLForContrast({
|
|
258
|
-
against: vars[worst.against],
|
|
268
|
+
against: varToHex(vars[worst.against]) ?? '#000000',
|
|
259
269
|
ratio: def.target,
|
|
260
270
|
direction,
|
|
261
|
-
c:
|
|
271
|
+
c: text.c,
|
|
262
272
|
h: seed.h,
|
|
263
273
|
lMax: Math.min(1, 2 * seed.l),
|
|
264
274
|
});
|
|
@@ -271,7 +281,7 @@ function runContrastGate(
|
|
|
271
281
|
|
|
272
282
|
const finalVars = palettesToVars(configs);
|
|
273
283
|
const checks: ContrastCheck[] = defs.map((def) => {
|
|
274
|
-
const worst = worstSurface(finalVars[def.textVar] ?? '#000000', finalVars);
|
|
284
|
+
const worst = worstSurface(varToHex(finalVars[def.textVar]) ?? '#000000', finalVars);
|
|
275
285
|
return {
|
|
276
286
|
textVar: def.textVar,
|
|
277
287
|
floor: def.floor,
|
|
@@ -47,29 +47,7 @@ export function lookProductionState({
|
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* Two facts are free on the client: whether the theme embeds a config for a
|
|
54
|
-
* component, and which layer the component's live config resolves from. A
|
|
55
|
-
* component the theme carries but which runs the shipped default is off it, and
|
|
56
|
-
* so is a component running a buffer the theme carries nothing for. A buffer
|
|
57
|
-
* over a config the theme does carry says nothing either way — that is the
|
|
58
|
-
* state an apply leaves — so it stays uncounted.
|
|
59
|
-
*
|
|
60
|
-
* The Default theme breaks that rule: it is the one theme that embeds every
|
|
61
|
-
* component's DEFAULT config by value (full set, not delta), so carrying an
|
|
62
|
-
* entry says nothing. For it, off-theme is simply "buffered".
|
|
63
|
-
*/
|
|
64
|
-
export function countComponentsOffLook(
|
|
65
|
-
components: ComponentSummary[],
|
|
66
|
-
lookConfigs: Record<string, unknown> | null | undefined,
|
|
67
|
-
lookIsDefault = false,
|
|
68
|
-
): number {
|
|
69
|
-
const carried = lookConfigs ?? {};
|
|
70
|
-
return components.filter((c) => {
|
|
71
|
-
if (lookIsDefault) return c.source === 'working';
|
|
72
|
-
const inLook = Object.prototype.hasOwnProperty.call(carried, c.name);
|
|
73
|
-
return inLook ? c.source === 'default' : c.source === 'working';
|
|
74
|
-
}).length;
|
|
50
|
+
/** How many components run an unsaved buffer, diverging from what the open theme carries. */
|
|
51
|
+
export function countComponentsOffLook(components: ComponentSummary[]): number {
|
|
52
|
+
return components.filter((c) => c.source === 'working').length;
|
|
75
53
|
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component-config migration, disk-shape in and disk-shape out. Extracted
|
|
3
|
+
* from `editorStore.ts` (Wave 1 of `docs/plans/theme-completeness.md`) so the
|
|
4
|
+
* server (`normalizeTheme`) can run the same migration an embedded theme
|
|
5
|
+
* config gets on the client, instead of reading it raw.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { AliasDiskValue } from './themeTypes';
|
|
9
|
+
import { runMigrations } from './migrations';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Migrate a disk-shape alias bag through the registered migration runner.
|
|
13
|
+
*
|
|
14
|
+
* The runner is string-typed by contract (most migrations only do
|
|
15
|
+
* key/value string rewrites). Object-valued entries — currently just
|
|
16
|
+
* inline `{ kind: 'gradient', value: ... }` payloads — pass through
|
|
17
|
+
* untouched: we split the bag into string/object subsets, run the runner
|
|
18
|
+
* on the string subset, then merge.
|
|
19
|
+
*
|
|
20
|
+
* For sectiondivider's legacy 7-flat-token gradients we run a synthesis
|
|
21
|
+
* step BEFORE the migration runner that would strip those tokens. The
|
|
22
|
+
* synthesized gradient object lands in the object subset and survives
|
|
23
|
+
* the stripping pass.
|
|
24
|
+
*/
|
|
25
|
+
export function migrateComponentConfig(
|
|
26
|
+
component: string,
|
|
27
|
+
aliasesIn: Record<string, AliasDiskValue>,
|
|
28
|
+
rawConfig: Record<string, unknown> | undefined,
|
|
29
|
+
fileVersion: number,
|
|
30
|
+
): { aliases: Record<string, AliasDiskValue>; config: Record<string, unknown> } {
|
|
31
|
+
const stringPart: Record<string, string> = {};
|
|
32
|
+
const objectPart: Record<string, AliasDiskValue> = {};
|
|
33
|
+
for (const [k, v] of Object.entries(aliasesIn)) {
|
|
34
|
+
if (typeof v === 'string') stringPart[k] = v;
|
|
35
|
+
else objectPart[k] = v;
|
|
36
|
+
}
|
|
37
|
+
// String-valued config entries join the migration input so a migration can
|
|
38
|
+
// rename or relocate them. After migration the bag flows through
|
|
39
|
+
// `splitAliasesAndConfig` which routes KNOWN keys back to config and the
|
|
40
|
+
// rest to aliases — this is what lets a migration *move* a key from the
|
|
41
|
+
// config bucket to the aliases bucket by also removing it from KNOWN.
|
|
42
|
+
// Config wins over an aliases-bucket collision on the same key: the legacy
|
|
43
|
+
// single-bucket → split-bucket move preserved "explicit config field beats
|
|
44
|
+
// legacy alias-bucketed value", and that contract still holds.
|
|
45
|
+
// Non-string config values (rare; reserved for future structured payloads)
|
|
46
|
+
// pass through untouched.
|
|
47
|
+
const configOut: Record<string, unknown> = {};
|
|
48
|
+
for (const [k, v] of Object.entries(rawConfig ?? {})) {
|
|
49
|
+
if (typeof v === 'string') stringPart[k] = v;
|
|
50
|
+
else configOut[k] = v;
|
|
51
|
+
}
|
|
52
|
+
if (component === 'sectiondivider') {
|
|
53
|
+
synthesizeSectionDividerGradients(stringPart, objectPart);
|
|
54
|
+
}
|
|
55
|
+
const migratedString = runMigrations('component-config', fileVersion, stringPart, { component });
|
|
56
|
+
const migratedObject = component === 'sectiondivider'
|
|
57
|
+
? renameSectionDividerObjectSlots(objectPart)
|
|
58
|
+
: objectPart;
|
|
59
|
+
return {
|
|
60
|
+
aliases: { ...migratedString, ...migratedObject },
|
|
61
|
+
config: configOut,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* v8→v9 companion to `componentMigration_2026_05_20_sectiondividerSlimVariants`:
|
|
67
|
+
* the structured background payload is reshaped from six color families →
|
|
68
|
+
* three size variants (lg/md/sm). Canvas's gradient is taken as the canonical
|
|
69
|
+
* seed and fanned across all three new variants; other families' gradients
|
|
70
|
+
* are dropped. Idempotent — keys already at the final shape pass through.
|
|
71
|
+
*
|
|
72
|
+
* Sources accepted (in priority order, first-found wins for canvas's slot):
|
|
73
|
+
* --sectiondivider-canvas-background (current/in-progress shape)
|
|
74
|
+
* --sectiondivider-canvas-gradient (v7-era shape)
|
|
75
|
+
* --sectiondivider-color-canvas-background (intermediate shape that landed
|
|
76
|
+
* briefly during the color-prop pivot)
|
|
77
|
+
*
|
|
78
|
+
* The migration runner only sees string keys, so this object-shape rename
|
|
79
|
+
* has to live alongside the runner call.
|
|
80
|
+
*/
|
|
81
|
+
const FAMILIES = ['canvas', 'neutral', 'alternate', 'primary', 'accent', 'special'] as const;
|
|
82
|
+
const SIZE_VARIANTS = ['lg', 'md', 'sm'] as const;
|
|
83
|
+
function renameSectionDividerObjectSlots(
|
|
84
|
+
objectPart: Record<string, AliasDiskValue>,
|
|
85
|
+
): Record<string, AliasDiskValue> {
|
|
86
|
+
// Find canvas's gradient under any historical key shape.
|
|
87
|
+
const canvasSourceKeys = [
|
|
88
|
+
'--sectiondivider-canvas-background',
|
|
89
|
+
'--sectiondivider-canvas-gradient',
|
|
90
|
+
'--sectiondivider-color-canvas-background',
|
|
91
|
+
];
|
|
92
|
+
let canvasGradient: AliasDiskValue | undefined;
|
|
93
|
+
for (const key of canvasSourceKeys) {
|
|
94
|
+
if (objectPart[key] !== undefined) {
|
|
95
|
+
canvasGradient = objectPart[key];
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// If we found a canvas gradient (any era), fan it into the three new
|
|
101
|
+
// per-variant background slots and drop every other family's gradient.
|
|
102
|
+
// If no canvas gradient is found, pass through non-family keys verbatim
|
|
103
|
+
// so non-migration data (theme tokens, other components) isn't touched.
|
|
104
|
+
const out: Record<string, AliasDiskValue> = {};
|
|
105
|
+
for (const [key, value] of Object.entries(objectPart)) {
|
|
106
|
+
// Skip any sectiondivider per-family gradient; the canvas fan-out emits
|
|
107
|
+
// the canonical set below.
|
|
108
|
+
let isFamilyGradient = false;
|
|
109
|
+
for (const f of FAMILIES) {
|
|
110
|
+
if (
|
|
111
|
+
key === `--sectiondivider-${f}-background`
|
|
112
|
+
|| key === `--sectiondivider-${f}-gradient`
|
|
113
|
+
|| key === `--sectiondivider-color-${f}-background`
|
|
114
|
+
) {
|
|
115
|
+
isFamilyGradient = true;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Pass through anything that's already at the final lg/md/sm shape so
|
|
120
|
+
// re-running the migration is idempotent.
|
|
121
|
+
if (isFamilyGradient) continue;
|
|
122
|
+
out[key] = value;
|
|
123
|
+
}
|
|
124
|
+
if (canvasGradient !== undefined) {
|
|
125
|
+
for (const v of SIZE_VARIANTS) {
|
|
126
|
+
out[`--sectiondivider-${v}-background`] = canvasGradient;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** SectionDivider variants that ship gradient aliases. */
|
|
133
|
+
const SECTIONDIVIDER_VARIANTS = ['canvas', 'neutral', 'alternate', 'primary', 'accent', 'special'] as const;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Collapse legacy 7-flat-token gradients (`{angle, stop-{1,2,3}-{color,position}}`)
|
|
137
|
+
* for each sectiondivider variant into one structured gradient alias at
|
|
138
|
+
* `--sectiondivider-{v}-gradient`. The flat tokens stay in `stringPart`
|
|
139
|
+
* for the migration runner to strip; the structured payload joins
|
|
140
|
+
* `objectPart` so the merge produces the new shape.
|
|
141
|
+
*
|
|
142
|
+
* Skips variants that already declare a gradient alias (object form) so
|
|
143
|
+
* round-tripping doesn't overwrite user edits.
|
|
144
|
+
*/
|
|
145
|
+
function synthesizeSectionDividerGradients(
|
|
146
|
+
stringPart: Record<string, string>,
|
|
147
|
+
objectPart: Record<string, AliasDiskValue>,
|
|
148
|
+
): void {
|
|
149
|
+
const GRADIENT_ANGLE_TOKENS: Record<string, number> = {
|
|
150
|
+
'--gradient-angle-horizontal': 90,
|
|
151
|
+
'--gradient-angle-vertical': 180,
|
|
152
|
+
'--gradient-angle-diagonal': 135,
|
|
153
|
+
'--gradient-angle-counter-diagonal': 45,
|
|
154
|
+
};
|
|
155
|
+
const GRADIENT_STOP_POSITIONS: Record<string, number> = {
|
|
156
|
+
'--gradient-stop-start': 0,
|
|
157
|
+
'--gradient-stop-mid': 50,
|
|
158
|
+
'--gradient-stop-end': 100,
|
|
159
|
+
};
|
|
160
|
+
const parseAngle = (raw: string | undefined): number => {
|
|
161
|
+
if (!raw) return 135;
|
|
162
|
+
if (raw.startsWith('--')) return GRADIENT_ANGLE_TOKENS[raw] ?? 135;
|
|
163
|
+
const m = raw.match(/^(-?\d+(?:\.\d+)?)\s*deg$/i);
|
|
164
|
+
return m ? parseFloat(m[1]) : 135;
|
|
165
|
+
};
|
|
166
|
+
const parsePosition = (raw: string | undefined, fallback: number): number => {
|
|
167
|
+
if (!raw) return fallback;
|
|
168
|
+
if (raw.startsWith('--')) return GRADIENT_STOP_POSITIONS[raw] ?? fallback;
|
|
169
|
+
const m = raw.match(/^(-?\d+(?:\.\d+)?)\s*%$/);
|
|
170
|
+
return m ? parseFloat(m[1]) : fallback;
|
|
171
|
+
};
|
|
172
|
+
const parseStopColor = (raw: string | undefined): { color: string; opacity?: number } | null => {
|
|
173
|
+
if (!raw) return null;
|
|
174
|
+
if (raw.startsWith('--')) return { color: raw };
|
|
175
|
+
const mix = raw.match(/^color-mix\(\s*in\s+srgb\s*,\s*var\((--[a-z0-9-]+)\)\s+([\d.]+)%\s*,\s*transparent\s*\)$/i);
|
|
176
|
+
if (mix) return { color: mix[1], opacity: parseFloat(mix[2]) };
|
|
177
|
+
return null;
|
|
178
|
+
};
|
|
179
|
+
for (const v of SECTIONDIVIDER_VARIANTS) {
|
|
180
|
+
const slot = `--sectiondivider-${v}-gradient`;
|
|
181
|
+
if (slot in objectPart) continue;
|
|
182
|
+
const angleKey = `${slot}-angle`;
|
|
183
|
+
const has1 = stringPart[`${slot}-stop-1-color`] !== undefined;
|
|
184
|
+
const has2 = stringPart[`${slot}-stop-2-color`] !== undefined;
|
|
185
|
+
const has3 = stringPart[`${slot}-stop-3-color`] !== undefined;
|
|
186
|
+
if (!has1 && !has2 && !has3) continue;
|
|
187
|
+
const stops: { position: number; color: string; opacity?: number }[] = [];
|
|
188
|
+
const positionDefaults = [0, 50, 100];
|
|
189
|
+
for (let i = 1; i <= 3; i++) {
|
|
190
|
+
const c = parseStopColor(stringPart[`${slot}-stop-${i}-color`]);
|
|
191
|
+
if (!c) continue;
|
|
192
|
+
const pos = parsePosition(stringPart[`${slot}-stop-${i}-position`], positionDefaults[i - 1]);
|
|
193
|
+
stops.push({ position: pos, color: c.color, ...(c.opacity !== undefined ? { opacity: c.opacity } : {}) });
|
|
194
|
+
}
|
|
195
|
+
if (stops.length < 2) continue;
|
|
196
|
+
objectPart[slot] = {
|
|
197
|
+
kind: 'gradient',
|
|
198
|
+
value: {
|
|
199
|
+
type: 'linear',
|
|
200
|
+
angle: parseAngle(stringPart[angleKey]),
|
|
201
|
+
stops,
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -7,7 +7,7 @@ import type { Migration } from './index';
|
|
|
7
7
|
* carrying `{type, angle, stops[]}` inline on the component slice.
|
|
8
8
|
*
|
|
9
9
|
* The structured value is synthesized *before* this migration runs — see
|
|
10
|
-
* `synthesizeSectionDividerGradients` in `
|
|
10
|
+
* `synthesizeSectionDividerGradients` in `migrateComponentConfig.ts`. The synthesizer
|
|
11
11
|
* walks the legacy 7-token shape and emits a `kind: 'gradient'` alias into
|
|
12
12
|
* the load path's object subset, where it survives this stripping pass and
|
|
13
13
|
* lands in the in-memory slice.
|
|
@@ -18,7 +18,7 @@ import type { Migration } from './index';
|
|
|
18
18
|
* `*-padding` → `*-spacing`
|
|
19
19
|
*
|
|
20
20
|
* The structured background payload moves through a companion rename in
|
|
21
|
-
* `
|
|
21
|
+
* `migrateComponentConfig` (migrateComponentConfig.ts), since the runner only sees
|
|
22
22
|
* string keys.
|
|
23
23
|
*/
|
|
24
24
|
const FAMILIES = ['canvas', 'neutral', 'alternate', 'primary', 'accent', 'special'] as const;
|
|
@@ -24,7 +24,7 @@ import type { Migration } from './index';
|
|
|
24
24
|
* - both undefined → emit nothing (default 'none' applies via CSS)
|
|
25
25
|
* - `show-hairline` unset but a real position exists → preserve the position
|
|
26
26
|
*
|
|
27
|
-
* The migration touches the unified bag produced by `
|
|
27
|
+
* The migration touches the unified bag produced by `migrateComponentConfig`
|
|
28
28
|
* (which now pre-merges string-valued config entries). The post-migration
|
|
29
29
|
* `splitAliasesAndConfig` step routes the new keys to `aliases` (since
|
|
30
30
|
* `KNOWN_COMPONENT_CONFIG_KEYS` no longer contains them) while keeping
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single source of truth for the CSS form of a structured gradient value.
|
|
3
|
+
* A component alias that owns a gradient serializes to one of two shapes:
|
|
4
|
+
*
|
|
5
|
+
* linear-gradient(<angle>deg, <stop>, <stop>, …)
|
|
6
|
+
* radial-gradient(<shape> at <cx>% 50%, <stop>, <stop>, …)
|
|
7
|
+
*
|
|
8
|
+
* `solid` and `none` are NOT represented here. `solid` renders as its first
|
|
9
|
+
* stop's colour and `none` as `transparent`, both indistinguishable in CSS
|
|
10
|
+
* from an ordinary colour alias, so `parseGradientValue` never claims them —
|
|
11
|
+
* see the round-trip contract below. Everything that writes or reads this form
|
|
12
|
+
* must go through `formatGradientValue` / `parseGradientValue` so the shape
|
|
13
|
+
* lives in exactly one place.
|
|
14
|
+
*
|
|
15
|
+
* ## Round-trip contract
|
|
16
|
+
*
|
|
17
|
+
* `formatGradientValue(parseGradientValue(css)) === css` for every string
|
|
18
|
+
* `formatGradientValue` can emit. The reverse holds only up to CSS
|
|
19
|
+
* equivalence: the format drops decompositions that have no rendered meaning,
|
|
20
|
+
* so parsing returns the canonical member of the equivalence class.
|
|
21
|
+
*
|
|
22
|
+
* - A radial's `angle` is never emitted (it exists so toggling the type back
|
|
23
|
+
* to linear restores the user's angle), so it parses back as 0.
|
|
24
|
+
* - `centerX: 50` and an absent `centerX` both emit `at 50% 50%`; parsing
|
|
25
|
+
* returns the absent form.
|
|
26
|
+
* - An ellipse emits `radius * aspectX` and `radius * aspectY`, three
|
|
27
|
+
* unknowns in two numbers. `radius` is vestigial (no setter writes it and
|
|
28
|
+
* `GradientSourceSnapshot` has no field for it), so parsing folds it into
|
|
29
|
+
* the aspects against `RADIAL_BASE_PX`. The two emitted numbers are
|
|
30
|
+
* unchanged, which is all CSS sees.
|
|
31
|
+
*
|
|
32
|
+
* This module depends only on its sibling `colorOpacity` parser, so the
|
|
33
|
+
* dev-server vite plugin (a separate build) can import it the same way it
|
|
34
|
+
* imports `globalRootBlock`.
|
|
35
|
+
*/
|
|
36
|
+
import { parseColorOpacity, formatColorOpacity } from './colorOpacity';
|
|
37
|
+
|
|
38
|
+
export interface GradientStop {
|
|
39
|
+
/** 0–100 percentage along the gradient axis. */
|
|
40
|
+
position: number;
|
|
41
|
+
/** A design-token name (`--surface-neutral-low`) or a raw CSS colour. */
|
|
42
|
+
color: string;
|
|
43
|
+
/** 0–100 alpha. Absent means 100. */
|
|
44
|
+
opacity?: number;
|
|
45
|
+
/** `false` marks the stop an explicit off-palette override: the stop picker
|
|
46
|
+
* opens to any colour rather than the current family, and a family-swap
|
|
47
|
+
* rewrite skips the stop so its colour survives. Absent means `true`.
|
|
48
|
+
* It has no CSS form, so `parseGradientValue` never produces it and
|
|
49
|
+
* `formatGradientValue` ignores it. It lives on the shared stop because
|
|
50
|
+
* the persisted stop carries it. */
|
|
51
|
+
monochrome?: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface GradientValue {
|
|
55
|
+
type: 'linear' | 'radial' | 'solid' | 'none';
|
|
56
|
+
angle: number;
|
|
57
|
+
radius?: number;
|
|
58
|
+
centerX?: number;
|
|
59
|
+
aspectX?: number;
|
|
60
|
+
aspectY?: number;
|
|
61
|
+
stops: GradientStop[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Base radius (px) an ellipse's aspect factors scale, when the gradient has
|
|
65
|
+
* no explicit `radius` but needs concrete dimensions to express its shape.
|
|
66
|
+
* A pleasant mid-size that reads as a soft glow inside typical component
|
|
67
|
+
* containers. */
|
|
68
|
+
export const RADIAL_BASE_PX = 100;
|
|
69
|
+
|
|
70
|
+
/** Resolve a stop's colour + opacity into a CSS colour value without the
|
|
71
|
+
* trailing `${position}%`. Shared by the stop formatter (which appends the
|
|
72
|
+
* position) and the solid path (which doesn't). */
|
|
73
|
+
function formatStopColor(s: GradientStop): string {
|
|
74
|
+
const opacity = s.opacity ?? 100;
|
|
75
|
+
if (s.color.startsWith('--')) {
|
|
76
|
+
return opacity >= 100 ? `var(${s.color})` : formatColorOpacity(s.color, opacity);
|
|
77
|
+
}
|
|
78
|
+
// A raw colour is not a design token, so colorOpacity, which owns the token
|
|
79
|
+
// form, cannot express it.
|
|
80
|
+
return opacity >= 100 ? s.color : `color-mix(in srgb, ${s.color} ${opacity}%, transparent)`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Stops portion only, for callers that supply their own gradient function
|
|
84
|
+
* wrapper (the palette selector overrides the angle per slot while keeping
|
|
85
|
+
* the token's stop list and its `var(--color-…)` refs). */
|
|
86
|
+
export function formatGradientStops(stops: readonly GradientStop[]): string {
|
|
87
|
+
return stops.map((s) => `${formatStopColor(s)} ${s.position}%`).join(', ');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function formatRadialShape(v: GradientValue): string {
|
|
91
|
+
const ax = v.aspectX ?? 1;
|
|
92
|
+
const ay = v.aspectY ?? 1;
|
|
93
|
+
if (ax === 1 && ay === 1) {
|
|
94
|
+
return v.radius && v.radius > 0 ? `circle ${v.radius}px` : 'circle';
|
|
95
|
+
}
|
|
96
|
+
const base = v.radius && v.radius > 0 ? v.radius : RADIAL_BASE_PX;
|
|
97
|
+
return `ellipse ${(base * ax).toFixed(2)}px ${(base * ay).toFixed(2)}px`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Serialize a structured gradient value (theme token or component-owned)
|
|
101
|
+
* into a CSS background declaration.
|
|
102
|
+
* - `none` → `transparent` (no background paint).
|
|
103
|
+
* - `solid` → the first stop's colour (no gradient function).
|
|
104
|
+
* - `linear` → `linear-gradient(<angle>deg, <stops>)`.
|
|
105
|
+
* - `radial` → `radial-gradient(<shape> at <centerX>% 50%, <stops>)`, where
|
|
106
|
+
* shape is `circle [radius]` at aspect 1 and `ellipse rx ry` otherwise.
|
|
107
|
+
* Aspects are independent stretch factors, not an area-preserving ratio:
|
|
108
|
+
* both at 8 is a circle eight times the size of both at 1. */
|
|
109
|
+
export function formatGradientValue(v: GradientValue): string {
|
|
110
|
+
if (v.type === 'none') return 'transparent';
|
|
111
|
+
if (v.type === 'solid') {
|
|
112
|
+
const first = v.stops[0];
|
|
113
|
+
return first ? formatStopColor(first) : 'transparent';
|
|
114
|
+
}
|
|
115
|
+
const stops = formatGradientStops(v.stops);
|
|
116
|
+
if (v.type === 'linear') return `linear-gradient(${v.angle}deg, ${stops})`;
|
|
117
|
+
return `radial-gradient(${formatRadialShape(v)} at ${v.centerX ?? 50}% 50%, ${stops})`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const NUM = String.raw`-?\d+(?:\.\d+)?`;
|
|
121
|
+
const LINEAR_RE = new RegExp(String.raw`^linear-gradient\(\s*(${NUM})deg\s*,\s*(.+)\)$`, 'i');
|
|
122
|
+
const RADIAL_RE = new RegExp(
|
|
123
|
+
String.raw`^radial-gradient\(\s*(circle|circle\s+${NUM}px|ellipse\s+${NUM}px\s+${NUM}px)\s+at\s+(${NUM})%\s+50%\s*,\s*(.+)\)$`,
|
|
124
|
+
'i',
|
|
125
|
+
);
|
|
126
|
+
const STOP_RE = new RegExp(String.raw`^(.*?)\s+(${NUM})%$`);
|
|
127
|
+
const CIRCLE_RADIUS_RE = new RegExp(String.raw`^circle\s+(${NUM})px$`, 'i');
|
|
128
|
+
const ELLIPSE_RE = new RegExp(String.raw`^ellipse\s+(${NUM})px\s+(${NUM})px$`, 'i');
|
|
129
|
+
const VAR_RE = /^var\((--[a-z0-9-]+)\)$/i;
|
|
130
|
+
|
|
131
|
+
/** Split on top-level separators only. Stop colours nest commas inside
|
|
132
|
+
* `color-mix(…)`, so a plain `split(',')` shreds them. */
|
|
133
|
+
function splitTopLevel(s: string): string[] {
|
|
134
|
+
const parts: string[] = [];
|
|
135
|
+
let depth = 0;
|
|
136
|
+
let start = 0;
|
|
137
|
+
for (let i = 0; i < s.length; i++) {
|
|
138
|
+
const c = s[i];
|
|
139
|
+
if (c === '(') depth++;
|
|
140
|
+
else if (c === ')') depth--;
|
|
141
|
+
else if (c === ',' && depth === 0) {
|
|
142
|
+
parts.push(s.slice(start, i));
|
|
143
|
+
start = i + 1;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
parts.push(s.slice(start));
|
|
147
|
+
return parts;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function parseStop(raw: string): GradientStop | null {
|
|
151
|
+
const m = raw.trim().match(STOP_RE);
|
|
152
|
+
if (!m) return null;
|
|
153
|
+
const position = parseFloat(m[2]);
|
|
154
|
+
const color = m[1].trim();
|
|
155
|
+
const opacity = parseColorOpacity(color);
|
|
156
|
+
if (opacity) return { position, color: opacity.name, opacity: opacity.opacity };
|
|
157
|
+
const token = color.match(VAR_RE);
|
|
158
|
+
return { position, color: token ? token[1] : color };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function parseStops(raw: string): GradientStop[] | null {
|
|
162
|
+
const stops: GradientStop[] = [];
|
|
163
|
+
for (const part of splitTopLevel(raw)) {
|
|
164
|
+
const stop = parseStop(part);
|
|
165
|
+
if (!stop) return null;
|
|
166
|
+
stops.push(stop);
|
|
167
|
+
}
|
|
168
|
+
return stops.length > 0 ? stops : null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function parseRadialShape(raw: string): Pick<GradientValue, 'radius' | 'aspectX' | 'aspectY'> | null {
|
|
172
|
+
const shape = raw.trim();
|
|
173
|
+
if (/^circle$/i.test(shape)) return {};
|
|
174
|
+
const circle = shape.match(CIRCLE_RADIUS_RE);
|
|
175
|
+
if (circle) return { radius: parseFloat(circle[1]) };
|
|
176
|
+
const ellipse = shape.match(ELLIPSE_RE);
|
|
177
|
+
if (!ellipse) return null;
|
|
178
|
+
// Aspects of exactly 1 are dropped, matching `setGradientAspect`, so the
|
|
179
|
+
// parsed value stays the canonical minimal shape.
|
|
180
|
+
const ax = parseFloat(ellipse[1]) / RADIAL_BASE_PX;
|
|
181
|
+
const ay = parseFloat(ellipse[2]) / RADIAL_BASE_PX;
|
|
182
|
+
return { ...(ax === 1 ? {} : { aspectX: ax }), ...(ay === 1 ? {} : { aspectY: ay }) };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Recover a structured gradient from the CSS `formatGradientValue` emits.
|
|
187
|
+
* Returns null for anything else, including the plain colour a `solid` or
|
|
188
|
+
* `none` gradient renders as: claiming those would turn every ordinary colour
|
|
189
|
+
* alias into a gradient object.
|
|
190
|
+
*/
|
|
191
|
+
export function parseGradientValue(value: string): GradientValue | null {
|
|
192
|
+
const css = value.trim();
|
|
193
|
+
const linear = css.match(LINEAR_RE);
|
|
194
|
+
if (linear) {
|
|
195
|
+
const stops = parseStops(linear[2]);
|
|
196
|
+
return stops && { type: 'linear', angle: parseFloat(linear[1]), stops };
|
|
197
|
+
}
|
|
198
|
+
const radial = css.match(RADIAL_RE);
|
|
199
|
+
if (!radial) return null;
|
|
200
|
+
const shape = parseRadialShape(radial[1]);
|
|
201
|
+
const stops = parseStops(radial[3]);
|
|
202
|
+
if (!shape || !stops) return null;
|
|
203
|
+
const centerX = parseFloat(radial[2]);
|
|
204
|
+
return {
|
|
205
|
+
type: 'radial',
|
|
206
|
+
angle: 0,
|
|
207
|
+
...shape,
|
|
208
|
+
...(centerX === 50 ? {} : { centerX }),
|
|
209
|
+
stops,
|
|
210
|
+
};
|
|
211
|
+
}
|