@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.
Files changed (91) hide show
  1. package/.claude/skills/live-tokens-adjust-shape-space/SKILL.md +7 -1
  2. package/CHANGELOG.md +108 -0
  3. package/bin/adjust.mjs +16 -39
  4. package/bin/generate-theme.mjs +20 -6
  5. package/dist-plugin/adjust/index.cjs +781 -21
  6. package/dist-plugin/adjust/index.d.cts +2 -1
  7. package/dist-plugin/adjust/index.d.ts +2 -1
  8. package/dist-plugin/adjust/index.js +43 -21
  9. package/dist-plugin/{chunk-6OZFXIQI.js → chunk-232GZGQU.js} +207 -12
  10. package/dist-plugin/chunk-NE6N66EE.js +753 -0
  11. package/dist-plugin/{chunk-76TFDTJO.js → chunk-PB2JTK2H.js} +179 -128
  12. package/dist-plugin/{chunk-44RSTAII.js → chunk-TKZBVIW5.js} +33 -5
  13. package/dist-plugin/chunk-YR6GPXW2.js +129 -0
  14. package/dist-plugin/generateColorsAndType/index.cjs +135 -63
  15. package/dist-plugin/generateColorsAndType/index.d.cts +2 -1
  16. package/dist-plugin/generateColorsAndType/index.d.ts +2 -1
  17. package/dist-plugin/generateColorsAndType/index.js +28 -784
  18. package/dist-plugin/{themeTypes-DSwKq-bj.d.ts → index-DpTIRZ2H.d.cts} +67 -26
  19. package/dist-plugin/{themeTypes-DSwKq-bj.d.cts → index-DpTIRZ2H.d.ts} +67 -26
  20. package/dist-plugin/index.cjs +1254 -140
  21. package/dist-plugin/index.js +106 -82
  22. package/dist-plugin/migrateData/index.cjs +956 -14
  23. package/dist-plugin/migrateData/index.js +10 -3
  24. package/dist-plugin/tokensCssMigrations/index.cjs +71 -5
  25. package/dist-plugin/tokensCssMigrations/index.d.cts +20 -9
  26. package/dist-plugin/tokensCssMigrations/index.d.ts +20 -9
  27. package/dist-plugin/tokensCssMigrations/index.js +4 -1
  28. package/package.json +8 -4
  29. package/src/editor/component-editor/NotificationEditor.svelte +6 -0
  30. package/src/editor/component-editor/scaffolding/ComponentFileManager.svelte +9 -23
  31. package/src/editor/component-editor/scaffolding/LinkedBlock.svelte +8 -8
  32. package/src/editor/core/components/adjustAliases.ts +49 -22
  33. package/src/editor/core/components/aliasKinds.ts +7 -2
  34. package/src/editor/core/components/componentConfigService.ts +1 -1
  35. package/src/editor/core/palettes/oklch.ts +3 -137
  36. package/src/editor/core/palettes/paletteDerivation.ts +79 -37
  37. package/src/editor/core/store/editorStore.ts +7 -197
  38. package/src/editor/core/store/editorTypes.ts +9 -30
  39. package/src/editor/core/themes/generateColorsAndType.ts +18 -8
  40. package/src/editor/core/themes/lookSummary.ts +3 -25
  41. package/src/editor/core/themes/migrateComponentConfig.ts +205 -0
  42. package/src/editor/core/themes/migrations/2026-05-19-sectiondivider-rich-gradient.ts +1 -1
  43. package/src/editor/core/themes/migrations/2026-05-20-sectiondivider-slim-variants.ts +1 -1
  44. package/src/editor/core/themes/migrations/2026-05-22-sectiondivider-intrinsics-to-css.ts +1 -1
  45. package/src/editor/core/themes/parsers/gradient.ts +211 -0
  46. package/src/editor/core/themes/slices/gradients.ts +5 -58
  47. package/src/editor/core/themes/themeService.ts +22 -9
  48. package/src/editor/core/themes/themeTypes.ts +89 -27
  49. package/src/editor/docs/content/editing-tokens.md +6 -2
  50. package/src/editor/docs/content/themes-workflow.md +9 -11
  51. package/src/editor/docs/content/where-themes-live.md +2 -2
  52. package/src/editor/docs/content.generated.ts +3 -3
  53. package/src/editor/index.ts +1 -0
  54. package/src/editor/styles/ui-editor.css +5 -2
  55. package/src/editor/ui/BezierCurveEditor.svelte +90 -67
  56. package/src/editor/ui/PaletteEditor.svelte +180 -59
  57. package/src/editor/ui/ThemePanel.svelte +24 -15
  58. package/src/editor/ui/Toggle.svelte +36 -24
  59. package/src/editor/ui/UIPillButton.svelte +1 -1
  60. package/src/editor/ui/UIReveal.svelte +47 -0
  61. package/src/editor/ui/UISquareButton.svelte +1 -1
  62. package/src/editor/ui/colors/ColorStory.svelte +12 -8
  63. package/src/editor/ui/colors/ColorsTab.svelte +4 -5
  64. package/src/editor/ui/curveEngine.ts +101 -21
  65. package/src/editor/ui/palette/OverridesPanel.svelte +23 -8
  66. package/src/editor/ui/palette/PaletteBase.svelte +17 -78
  67. package/src/editor/ui/palette/PaletteJumpButton.svelte +3 -3
  68. package/src/editor/ui/palette/ScaleCurveEditor.svelte +110 -20
  69. package/src/editor/ui/palette/curveSummary.ts +20 -0
  70. package/src/editor/ui/palette/dockMagnify.ts +5 -13
  71. package/src/editor/ui/palette/paletteMath.ts +7 -4
  72. package/src/live-tokens/data/colors-and-type/autumn.json +528 -528
  73. package/src/live-tokens/data/colors-and-type/default.json +247 -247
  74. package/src/live-tokens/data/colors-and-type/halloween.json +532 -532
  75. package/src/live-tokens/data/colors-and-type/midnight-study.json +538 -538
  76. package/src/live-tokens/data/colors-and-type/ocean.json +521 -521
  77. package/src/live-tokens/data/colors-and-type/royal-velvet.json +532 -532
  78. package/src/live-tokens/data/colors-and-type/spring-meadow.json +504 -504
  79. package/src/live-tokens/data/colors-and-type/sunset.json +531 -531
  80. package/src/live-tokens/data/themes/autumn.json +604 -568
  81. package/src/live-tokens/data/themes/halloween.json +584 -583
  82. package/src/live-tokens/data/themes/midnight-study.json +673 -605
  83. package/src/live-tokens/data/themes/ocean.json +597 -561
  84. package/src/live-tokens/data/themes/royal-velvet.json +574 -573
  85. package/src/live-tokens/data/themes/spring-meadow.json +590 -556
  86. package/src/live-tokens/data/themes/sunset.json +632 -571
  87. package/src/live-tokens/data/tokens.generated.css +282 -282
  88. package/src/system/components/FloatingTokenTags.css +0 -1
  89. package/src/system/internal/backgroundContrast.ts +7 -0
  90. package/src/system/internal/oklch.ts +189 -0
  91. package/src/system/styles/tokens.css +283 -283
@@ -7,7 +7,10 @@ import {
7
7
  normalizeTheme,
8
8
  planLegacyRenames,
9
9
  versionedFileResourceServer
10
- } from "../chunk-6OZFXIQI.js";
10
+ } from "../chunk-232GZGQU.js";
11
+ import {
12
+ CURRENT_COMPONENT_SCHEMA_VERSION
13
+ } from "../chunk-NE6N66EE.js";
11
14
  import {
12
15
  readLiveTokensConfig,
13
16
  resolveDataDirs
@@ -151,6 +154,7 @@ function migrateData(opts) {
151
154
  const resolvers = {
152
155
  readColorsAndType: (name) => colorsRes.readJson(name),
153
156
  readComponentConfig: (comp, name) => compRes(comp).readJson(name),
157
+ listComponentNames: () => comps,
154
158
  normalizeColorsAndType: (colorsAndType) => colorsAndType
155
159
  };
156
160
  const upgradedThemes = [];
@@ -230,7 +234,6 @@ function migrateData(opts) {
230
234
  for (const comp of comps) {
231
235
  const pointed = prodConfigs.get(comp);
232
236
  if (!isObject(pointed)) continue;
233
- if (sameContent(pointed, defaultConfig(comp))) continue;
234
237
  componentConfigs[comp] = stripMarkers(pointed);
235
238
  }
236
239
  recoveredTheme = {
@@ -239,7 +242,11 @@ function migrateData(opts) {
239
242
  updatedAt: now,
240
243
  schemaVersion: THEME_SCHEMA_VERSION,
241
244
  colorsAndType: isObject(prodColors) ? stripMarkers(prodColors) : null,
242
- componentConfigs
245
+ componentConfigs,
246
+ // The configs above are what boot just wrote (`prodConfigs`, read off
247
+ // the pointed files), at the current component schema — not 0, which
248
+ // would misdescribe them as unmigrated.
249
+ componentSchemaVersion: CURRENT_COMPONENT_SCHEMA_VERSION
243
250
  };
244
251
  const slug = nextAvailableName((n) => themesRes.existingPath(n) !== null, RECOVERED_SLUG);
245
252
  recoveredThemePath = themesRes.filePath(slug);
@@ -33,6 +33,7 @@ __export(tokensCssMigrations_exports, {
33
33
  TOKENS_CSS_MIGRATIONS: () => TOKENS_CSS_MIGRATIONS,
34
34
  collectDefinedTokens: () => collectDefinedTokens,
35
35
  collectReferencedTokens: () => collectReferencedTokens,
36
+ collectTokenValues: () => collectTokenValues,
36
37
  enforceBreakingRequiresMajor: () => enforceBreakingRequiresMajor,
37
38
  ensureScale: () => ensureScale,
38
39
  findContractViolations: () => findContractViolations,
@@ -61,11 +62,17 @@ function extractGlobalRootBody(source) {
61
62
  // vite-plugin/tokensCssMigrations/cssTokenOps.ts
62
63
  var DECL_RE = /(^|[\s;{])(--[a-z0-9-]+)\s*:/gi;
63
64
  var REF_RE = /var\(\s*(--[a-z0-9-]+)/gi;
65
+ var DECL_VALUE_RE = /(^|[\s;{])(--[a-z0-9-]+)\s*:([^;}]*)/gi;
64
66
  function collectDefinedTokens(css) {
65
67
  const out = /* @__PURE__ */ new Set();
66
68
  for (const m of css.matchAll(DECL_RE)) out.add(m[2]);
67
69
  return out;
68
70
  }
71
+ function collectTokenValues(css) {
72
+ const out = /* @__PURE__ */ new Map();
73
+ for (const m of css.matchAll(DECL_VALUE_RE)) out.set(m[2], m[3].trim());
74
+ return out;
75
+ }
69
76
  function collectReferencedTokens(css) {
70
77
  const out = /* @__PURE__ */ new Set();
71
78
  for (const m of css.matchAll(REF_RE)) out.add(m[1]);
@@ -399,6 +406,62 @@ var tokensCssMigration_2026_07_20_semanticTextStyles = {
399
406
  }
400
407
  };
401
408
 
409
+ // src/system/internal/oklch.ts
410
+ function srgbToLinear(c) {
411
+ return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
412
+ }
413
+ function hexToLinearRgb(hex) {
414
+ const r = parseInt(hex.slice(1, 3), 16) / 255;
415
+ const g = parseInt(hex.slice(3, 5), 16) / 255;
416
+ const b = parseInt(hex.slice(5, 7), 16) / 255;
417
+ return [srgbToLinear(r), srgbToLinear(g), srgbToLinear(b)];
418
+ }
419
+ function linearRgbToOklab(r, g, b) {
420
+ const l_ = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b;
421
+ const m_ = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b;
422
+ const s_ = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b;
423
+ const l = Math.cbrt(l_);
424
+ const m = Math.cbrt(m_);
425
+ const s = Math.cbrt(s_);
426
+ return [
427
+ 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
428
+ 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
429
+ 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s
430
+ ];
431
+ }
432
+ function oklabToOklch(L, a, b) {
433
+ const c = Math.sqrt(a * a + b * b);
434
+ let h = Math.atan2(b, a) * 180 / Math.PI;
435
+ if (h < 0) h += 360;
436
+ return { l: L, c, h };
437
+ }
438
+ function hexToOklch(hex) {
439
+ const [r, g, b] = hexToLinearRgb(hex);
440
+ const [L, a, bVal] = linearRgbToOklab(r, g, b);
441
+ return oklabToOklch(L, a, bVal);
442
+ }
443
+ function trim(value, decimals) {
444
+ return Number(value.toFixed(decimals)).toString();
445
+ }
446
+ function oklchToCss(l, c, h) {
447
+ const cs = trim(c, 4);
448
+ return `oklch(${trim(l, 4)} ${cs} ${cs === "0" ? "0" : trim(h, 2)})`;
449
+ }
450
+
451
+ // vite-plugin/tokensCssMigrations/migrations/2026-08-19-oklch-color-values.ts
452
+ var HEX_DECLARATION_RE = /(--[a-z0-9-]+:\s*)#([0-9a-f]{6})(?=\s*[;}])/gi;
453
+ var tokensCssMigration_2026_08_19_oklchColorValues = {
454
+ id: "2026-08-19-oklch-color-values",
455
+ kind: "breaking",
456
+ description: "Rewrite hex token values as oklch()",
457
+ apply(css) {
458
+ return css.replace(HEX_DECLARATION_RE, (_match, prefix, hex) => {
459
+ const { l, c, h } = hexToOklch(`#${hex}`);
460
+ return `${prefix}${oklchToCss(l, c, h)}`;
461
+ });
462
+ }
463
+ };
464
+
402
465
  // vite-plugin/files/dataPaths.ts
403
466
  var import_fs = __toESM(require("fs"), 1);
404
467
  var import_path = __toESM(require("path"), 1);
@@ -441,7 +504,8 @@ var TOKENS_CSS_MIGRATIONS = [
441
504
  tokensCssMigration_2026_06_04_removeDeadSizeIconScale,
442
505
  tokensCssMigration_2026_06_04_easingColorAndTypescaleAdditions,
443
506
  tokensCssMigration_2026_07_20_lineHeightRename,
444
- tokensCssMigration_2026_07_20_semanticTextStyles
507
+ tokensCssMigration_2026_07_20_semanticTextStyles,
508
+ tokensCssMigration_2026_08_19_oklchColorValues
445
509
  ];
446
510
  function runTokensCssMigrations(css) {
447
511
  return foldMigrations(css, () => true);
@@ -466,10 +530,11 @@ function findContractViolations(canonicalCss) {
466
530
  const violations = [];
467
531
  for (const m of TOKENS_CSS_MIGRATIONS) {
468
532
  if (m.kind !== "additive") continue;
469
- const before = collectDefinedTokens(canonicalCss);
470
- const after = collectDefinedTokens(m.apply(canonicalCss));
471
- const removed = [...before].filter((t) => !after.has(t)).sort();
472
- if (removed.length) violations.push({ id: m.id, removed });
533
+ const before = collectTokenValues(canonicalCss);
534
+ const after = collectTokenValues(m.apply(canonicalCss));
535
+ const removed = [...before.keys()].filter((t) => !after.has(t)).sort();
536
+ const changed = [...before.entries()].filter(([t, v]) => after.has(t) && after.get(t) !== v).map(([t]) => t).sort();
537
+ if (removed.length || changed.length) violations.push({ id: m.id, removed, changed });
473
538
  }
474
539
  return violations;
475
540
  }
@@ -530,6 +595,7 @@ function validateTokensCss(input) {
530
595
  TOKENS_CSS_MIGRATIONS,
531
596
  collectDefinedTokens,
532
597
  collectReferencedTokens,
598
+ collectTokenValues,
533
599
  enforceBreakingRequiresMajor,
534
600
  ensureScale,
535
601
  findContractViolations,
@@ -52,6 +52,8 @@ interface TokensCssMigration {
52
52
  */
53
53
  /** Names declared as custom properties (`--x: …;`) anywhere in the source. */
54
54
  declare function collectDefinedTokens(css: string): Set<string>;
55
+ /** Declared name → value, last declaration winning (as the cascade would). */
56
+ declare function collectTokenValues(css: string): Map<string, string>;
55
57
  /** Names referenced via `var(--x)` anywhere in the source. */
56
58
  declare function collectReferencedTokens(css: string): Set<string>;
57
59
  interface ScaleEntry {
@@ -123,16 +125,25 @@ interface ContractViolation {
123
125
  id: string;
124
126
  /** Token names the migration removed or renamed away despite declaring `additive`. */
125
127
  removed: string[];
128
+ /** Token names whose value the migration rewrote despite declaring `additive`. */
129
+ changed: string[];
126
130
  }
127
131
  /**
128
- * Guardrail for the token-as-API contract: an `additive` migration must never
129
- * remove or rename a token. We verify behaviorally rather than trusting the
130
- * label — apply each additive migration to the package's own canonical
131
- * `tokens.css` (which defines the full current vocabulary) and flag any token
132
- * that disappears. A rename surfaces as the removal of its old name, so it is
133
- * caught too. This catches the dangerous direction: a breaking change shipped as
134
- * a backward-compatible one. (Over-labeling a no-op as `breaking` is harmless
135
- * and not checked.)
132
+ * Guardrail for the token-as-API contract: an `additive` migration must only
133
+ * ever insert new names — it must never remove or rename a token, and never
134
+ * rewrite the value of one a consumer already references. We verify
135
+ * behaviorally rather than trusting the label: apply each additive migration to
136
+ * the package's own canonical `tokens.css` (which defines the full current
137
+ * vocabulary) and flag any token that disappears or changes value. A rename
138
+ * surfaces as the removal of its old name, so it is caught too.
139
+ *
140
+ * The value half is what makes a value-rewriting migration (hex → `oklch()`)
141
+ * impossible to mislabel: it renames nothing, so a name-only guard would wave
142
+ * it through as additive and the dev plugin would auto-apply a breaking change
143
+ * to a consumer's vendored file.
144
+ *
145
+ * This catches the dangerous direction only. (Over-labeling a no-op as
146
+ * `breaking` is harmless and not checked.)
136
147
  */
137
148
  declare function findContractViolations(canonicalCss: string): ContractViolation[];
138
149
  type SemverBump = 'major' | 'minor' | 'patch' | 'none';
@@ -183,4 +194,4 @@ interface ValidateInput {
183
194
  */
184
195
  declare function validateTokensCss(input: ValidateInput): MissingToken[];
185
196
 
186
- export { type BreakingGateResult, type ComponentSource, type ContractViolation, type MissingToken, type RunResult, type SemverBump, TOKENS_CSS_MIGRATIONS, type TokensCssMigration, type ValidateInput, collectDefinedTokens, collectReferencedTokens, enforceBreakingRequiresMajor, ensureScale, findContractViolations, removeToken, removeTokensMatching, renameToken, runAdditiveTokensCssMigrations, runTokensCssMigrations, semverBumpType, validateTokensCss };
197
+ export { type BreakingGateResult, type ComponentSource, type ContractViolation, type MissingToken, type RunResult, type SemverBump, TOKENS_CSS_MIGRATIONS, type TokensCssMigration, type ValidateInput, collectDefinedTokens, collectReferencedTokens, collectTokenValues, enforceBreakingRequiresMajor, ensureScale, findContractViolations, removeToken, removeTokensMatching, renameToken, runAdditiveTokensCssMigrations, runTokensCssMigrations, semverBumpType, validateTokensCss };
@@ -52,6 +52,8 @@ interface TokensCssMigration {
52
52
  */
53
53
  /** Names declared as custom properties (`--x: …;`) anywhere in the source. */
54
54
  declare function collectDefinedTokens(css: string): Set<string>;
55
+ /** Declared name → value, last declaration winning (as the cascade would). */
56
+ declare function collectTokenValues(css: string): Map<string, string>;
55
57
  /** Names referenced via `var(--x)` anywhere in the source. */
56
58
  declare function collectReferencedTokens(css: string): Set<string>;
57
59
  interface ScaleEntry {
@@ -123,16 +125,25 @@ interface ContractViolation {
123
125
  id: string;
124
126
  /** Token names the migration removed or renamed away despite declaring `additive`. */
125
127
  removed: string[];
128
+ /** Token names whose value the migration rewrote despite declaring `additive`. */
129
+ changed: string[];
126
130
  }
127
131
  /**
128
- * Guardrail for the token-as-API contract: an `additive` migration must never
129
- * remove or rename a token. We verify behaviorally rather than trusting the
130
- * label — apply each additive migration to the package's own canonical
131
- * `tokens.css` (which defines the full current vocabulary) and flag any token
132
- * that disappears. A rename surfaces as the removal of its old name, so it is
133
- * caught too. This catches the dangerous direction: a breaking change shipped as
134
- * a backward-compatible one. (Over-labeling a no-op as `breaking` is harmless
135
- * and not checked.)
132
+ * Guardrail for the token-as-API contract: an `additive` migration must only
133
+ * ever insert new names — it must never remove or rename a token, and never
134
+ * rewrite the value of one a consumer already references. We verify
135
+ * behaviorally rather than trusting the label: apply each additive migration to
136
+ * the package's own canonical `tokens.css` (which defines the full current
137
+ * vocabulary) and flag any token that disappears or changes value. A rename
138
+ * surfaces as the removal of its old name, so it is caught too.
139
+ *
140
+ * The value half is what makes a value-rewriting migration (hex → `oklch()`)
141
+ * impossible to mislabel: it renames nothing, so a name-only guard would wave
142
+ * it through as additive and the dev plugin would auto-apply a breaking change
143
+ * to a consumer's vendored file.
144
+ *
145
+ * This catches the dangerous direction only. (Over-labeling a no-op as
146
+ * `breaking` is harmless and not checked.)
136
147
  */
137
148
  declare function findContractViolations(canonicalCss: string): ContractViolation[];
138
149
  type SemverBump = 'major' | 'minor' | 'patch' | 'none';
@@ -183,4 +194,4 @@ interface ValidateInput {
183
194
  */
184
195
  declare function validateTokensCss(input: ValidateInput): MissingToken[];
185
196
 
186
- export { type BreakingGateResult, type ComponentSource, type ContractViolation, type MissingToken, type RunResult, type SemverBump, TOKENS_CSS_MIGRATIONS, type TokensCssMigration, type ValidateInput, collectDefinedTokens, collectReferencedTokens, enforceBreakingRequiresMajor, ensureScale, findContractViolations, removeToken, removeTokensMatching, renameToken, runAdditiveTokensCssMigrations, runTokensCssMigrations, semverBumpType, validateTokensCss };
197
+ export { type BreakingGateResult, type ComponentSource, type ContractViolation, type MissingToken, type RunResult, type SemverBump, TOKENS_CSS_MIGRATIONS, type TokensCssMigration, type ValidateInput, collectDefinedTokens, collectReferencedTokens, collectTokenValues, enforceBreakingRequiresMajor, ensureScale, findContractViolations, removeToken, removeTokensMatching, renameToken, runAdditiveTokensCssMigrations, runTokensCssMigrations, semverBumpType, validateTokensCss };
@@ -2,6 +2,7 @@ import {
2
2
  TOKENS_CSS_MIGRATIONS,
3
3
  collectDefinedTokens,
4
4
  collectReferencedTokens,
5
+ collectTokenValues,
5
6
  enforceBreakingRequiresMajor,
6
7
  ensureScale,
7
8
  findContractViolations,
@@ -12,7 +13,8 @@ import {
12
13
  runTokensCssMigrations,
13
14
  semverBumpType,
14
15
  validateTokensCss
15
- } from "../chunk-44RSTAII.js";
16
+ } from "../chunk-TKZBVIW5.js";
17
+ import "../chunk-YR6GPXW2.js";
16
18
  import {
17
19
  readLiveTokensConfig
18
20
  } from "../chunk-D3ZVKOR4.js";
@@ -20,6 +22,7 @@ export {
20
22
  TOKENS_CSS_MIGRATIONS,
21
23
  collectDefinedTokens,
22
24
  collectReferencedTokens,
25
+ collectTokenValues,
23
26
  enforceBreakingRequiresMajor,
24
27
  ensureScale,
25
28
  findContractViolations,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@motion-proto/live-tokens",
3
- "version": "0.50.0",
3
+ "version": "0.53.0",
4
4
  "type": "module",
5
5
  "description": "Design token editor with live CSS variable editing. Svelte 5 + Vite 8.",
6
6
  "keywords": [
@@ -110,7 +110,9 @@
110
110
  "check": "svelte-check --tsconfig ./tsconfig.json",
111
111
  "test": "vitest run",
112
112
  "test:watch": "vitest",
113
- "test:e2e": "playwright test",
113
+ "test:e2e": "npm run test:e2e:contract && npm run test:e2e:stateful",
114
+ "test:e2e:contract": "playwright test tests/e2e/component-render-contract.spec.ts tests/e2e/component-alias-contract.spec.ts --workers=${PLAYWRIGHT_WORKERS:-4}",
115
+ "test:e2e:stateful": "playwright test tests/e2e/live-editing.spec.ts tests/e2e/theme-workflow.spec.ts --workers=1",
114
116
  "test:e2e:components": "playwright test tests/e2e/component-render-contract.spec.ts",
115
117
  "test:e2e:ui": "playwright test --ui",
116
118
  "prepare:e2e": "node scripts/prepare-playwright-data.mjs",
@@ -118,6 +120,7 @@
118
120
  "build:lib": "npm run build:plugin",
119
121
  "deploy:local": "bash scripts/deploy-local.sh",
120
122
  "check:no-style-imports": "node scripts/check-no-style-imports.mjs",
123
+ "check:no-tooling-imports": "node scripts/check-no-tooling-imports.mjs",
121
124
  "check:slot-prose": "node scripts/check-slot-prose.mjs",
122
125
  "check:overlay-portal": "node scripts/check-overlay-portal.mjs",
123
126
  "check:editor-font-isolation": "node scripts/check-editor-font-isolation.mjs",
@@ -125,13 +128,14 @@
125
128
  "check:production-is-default": "node scripts/check-production-is-default.mjs",
126
129
  "check:docs-content": "node scripts/sync-docs.mjs --check",
127
130
  "check:token-contract": "node scripts/check-token-contract.mjs",
131
+ "check:preset-themes": "node scripts/check-preset-themes.mjs",
128
132
  "sync:component-defaults": "node scripts/sync-component-defaults.mjs --write",
129
133
  "sync:docs": "node scripts/sync-docs.mjs --write",
130
- "generate:preset-themes": "node scripts/generate-preset-themes.mjs",
134
+ "seed:preset-theme": "node scripts/seed-preset-theme.mjs",
131
135
  "collapse:theme": "node scripts/collapse-theme-to-default.mjs",
132
136
  "check:smoke-install": "bash scripts/smoke-install.sh",
133
137
  "check:smoke-create": "bash scripts/smoke-create.sh",
134
- "prepublishOnly": "npm run check:no-style-imports && npm run check:slot-prose && npm run check:overlay-portal && npm run check:editor-font-isolation && npm run check:component-defaults && npm run check:production-is-default && npm run check:docs-content && npm run build:lib && npm run check:token-contract && npm run check:smoke-install && npm run check:smoke-create"
138
+ "prepublishOnly": "npm run check:no-style-imports && npm run check:no-tooling-imports && npm run check:slot-prose && npm run check:overlay-portal && npm run check:editor-font-isolation && npm run check:component-defaults && npm run check:production-is-default && npm run check:docs-content && npm run build:lib && npm run check:token-contract && npm run check:preset-themes && npm run check:smoke-install && npm run check:smoke-create"
135
139
  },
136
140
  "peerDependencies": {
137
141
  "@sveltejs/vite-plugin-svelte": "^7.0",
@@ -87,12 +87,14 @@
87
87
  let dismissible = $state(false);
88
88
  let rightOption: ButtonVariantOption = $state('none');
89
89
  let leftOption: ButtonVariantOption = $state('none');
90
+ let headerAction = $state(false);
90
91
  let actions = $derived(((): NotificationActions => {
91
92
  const a: NotificationActions = {};
92
93
  const right = toVariant(rightOption);
93
94
  const left = toVariant(leftOption);
94
95
  if (right) a.right = { label: 'Confirm', variant: right, onClick: () => {} };
95
96
  if (left) a.left = { label: 'Cancel', variant: left, onClick: () => {} };
97
+ if (headerAction) a.header = { label: 'Action', onClick: () => {} };
96
98
  return a;
97
99
  })());
98
100
  </script>
@@ -112,6 +114,10 @@
112
114
  <input type="checkbox" bind:checked={dismissible} />
113
115
  <span>Dismissible</span>
114
116
  </label>
117
+ <label class="toolbar-check">
118
+ <input type="checkbox" bind:checked={headerAction} />
119
+ <span>Header button</span>
120
+ </label>
115
121
  <label class="toolbar-field">
116
122
  <span>Right button</span>
117
123
  <select class="canvas-toolbar-select" bind:value={rightOption}>
@@ -5,10 +5,7 @@
5
5
  <script lang="ts">
6
6
  import { onMount, onDestroy } from 'svelte';
7
7
  import UIInfoPopover from '../../ui/UIInfoPopover.svelte';
8
- import type {
9
- ComponentConfigMeta,
10
- LiveSource,
11
- } from '../../core/themes/themeTypes';
8
+ import type { ComponentConfigMeta } from '../../core/themes/themeTypes';
12
9
  import { componentSourceFile } from './componentSources';
13
10
  import {
14
11
  getActiveComponentConfig,
@@ -73,7 +70,6 @@
73
70
  // Saved presets. Nothing live points at one: the component runs its working
74
71
  // buffer, and the theme it belongs to carries the copy that ships.
75
72
  let files: ComponentConfigMeta[] = $state([]);
76
- let liveSource: LiveSource = $state('default');
77
73
  let openTheme: { fileName: string; name: string } = $state({
78
74
  fileName: 'default',
79
75
  name: 'Motion Proto',
@@ -94,18 +90,13 @@
94
90
  let compDirty = $derived($componentDirty[component] ?? false);
95
91
  let openIsProtected = $derived(openTheme.fileName === 'default');
96
92
  // Both rows name a document, because that is what a config belongs to now:
97
- // the component runs the open theme's config (or the shipped default), and
98
- // production ships the published theme's.
99
- let editorDoc = $derived(liveSource === 'default' ? 'default' : openTheme.fileName);
100
- let productionDoc = $derived(
101
- $productionTheme
102
- ? ($productionTheme.componentConfigs[component] ? $productionTheme._fileName ?? 'default' : 'default')
103
- : null,
104
- );
105
- let editorName = $derived(liveSource === 'default' ? 'Default' : openTheme.name);
106
- let productionName = $derived(
107
- productionDoc === null ? '—' : productionDoc === 'default' ? 'Default' : $productionTheme?.name ?? '—',
108
- );
93
+ // every theme carries every component by value, so the component always
94
+ // runs the open theme's config, and production always runs the published
95
+ // theme's.
96
+ let editorDoc = $derived(openTheme.fileName);
97
+ let productionDoc = $derived($productionTheme?._fileName ?? null);
98
+ let editorName = $derived(openTheme.name);
99
+ let productionName = $derived(productionDoc === null ? '—' : $productionTheme?.name ?? '—');
109
100
  // Saving writes the buffer, which the bake has not seen: the document is
110
101
  // still the published one, so only the shared signal can say the config on
111
102
  // screen is not what production runs.
@@ -123,11 +114,8 @@
123
114
  if (data) files = data.files;
124
115
  }
125
116
 
126
- /** Which layer the component's live config comes from, and the theme it
127
- * belongs to. Both ride on the live read door's markers. */
117
+ /** The theme the component belongs to, by the open document's own markers. */
128
118
  async function refreshLive() {
129
- const cfg = await getActiveComponentConfig(component);
130
- if (cfg) liveSource = cfg._source ?? 'default';
131
119
  try {
132
120
  const theme = await getActiveTheme();
133
121
  if (theme) openTheme = { fileName: theme._fileName ?? 'default', name: theme.name };
@@ -186,7 +174,6 @@
186
174
  component,
187
175
  componentConfigFromState($editorState, component, openTheme.name),
188
176
  );
189
- liveSource = 'working';
190
177
  markComponentSaved(component);
191
178
  bumpComponentActiveRevision();
192
179
  }
@@ -233,7 +220,6 @@
233
220
  const { _fileName, _source, ...cfg } = await loadComponentConfig(component, file.fileName);
234
221
  await writeWorkingComponentConfig(component, { ...cfg, component });
235
222
  loadComponentActive(component, cfg.aliases, cfg.config, cfg.schemaVersion ?? 0);
236
- liveSource = 'working';
237
223
  bumpComponentActiveRevision();
238
224
  } catch {
239
225
  // intentional: see comment above
@@ -1,6 +1,7 @@
1
1
  <script lang="ts">
2
- import { fade, slide } from 'svelte/transition';
2
+ import { fade } from 'svelte/transition';
3
3
  import TokenLayout from './TokenLayout.svelte';
4
+ import UIReveal from '../../ui/UIReveal.svelte';
4
5
  import LinkageChart from './LinkageChart.svelte';
5
6
  import { getEditorContext } from './editorContext';
6
7
  import type { LinkedBlockResult, LinkedGroup } from './linkedBlock';
@@ -11,7 +12,6 @@
11
12
  const reduceMotion = typeof window !== 'undefined'
12
13
  && window.matchMedia?.('(prefers-reduced-motion: reduce)').matches === true;
13
14
  const fadeDur = reduceMotion ? 0 : 140;
14
- const slideDur = reduceMotion ? 0 : 200;
15
15
 
16
16
  interface Props {
17
17
  component: string;
@@ -139,8 +139,8 @@
139
139
  {/if}
140
140
  </span>
141
141
  </button>
142
- {#if sectionExpanded}
143
- <div class="linked-grid" transition:slide|local={{ duration: slideDur }}>
142
+ <UIReveal open={sectionExpanded}>
143
+ <div class="linked-grid">
144
144
  {#each cards as card (card.row.variable)}
145
145
  {@const cardExpanded = expandedCards[card.row.variable] === true}
146
146
  {@const cardHovered = hoveredVar === card.row.variable}
@@ -176,8 +176,8 @@
176
176
  >({card.unlinkedText})</span>
177
177
  {/if}
178
178
  </button>
179
- {#if cardExpanded}
180
- <div class="chart-wrap" transition:slide|local={{ duration: slideDur }}>
179
+ <UIReveal open={cardExpanded}>
180
+ <div class="chart-wrap">
181
181
  <LinkageChart
182
182
  contexts={card.contexts}
183
183
  broken={card.brokenContexts}
@@ -187,11 +187,11 @@
187
187
  onselect={handleChartSelect}
188
188
  />
189
189
  </div>
190
- {/if}
190
+ </UIReveal>
191
191
  </article>
192
192
  {/each}
193
193
  </div>
194
- {/if}
194
+ </UIReveal>
195
195
  </section>
196
196
  {/if}
197
197
 
@@ -1,4 +1,4 @@
1
- import { matchesKind } from './aliasKinds';
1
+ import { matchesKind, stripSide } from './aliasKinds';
2
2
  import type { AliasDiskValue, ComponentConfig } from '../themes/themeTypes';
3
3
 
4
4
  export type AdjustKind = 'radius' | 'padding' | 'gap' | 'border-width';
@@ -52,12 +52,21 @@ const RADIUS_RUNGS = [
52
52
  /** The editor picker's 12-step subset (`UIPaddingSelector`), not the full
53
53
  `--space-*` scale: every value this engine writes must stay re-editable
54
54
  by hand in the picker. */
55
- const SPACE_RUNGS = [
55
+ const SPACE_SETTABLE = [
56
56
  '--space-0', '--space-2', '--space-4', '--space-6', '--space-8', '--space-10',
57
57
  '--space-12', '--space-16', '--space-20', '--space-24', '--space-32', '--space-48',
58
58
  ];
59
59
 
60
- const SPACE_FAMILY = [...SPACE_RUNGS, '--space-40', '--space-64', '--space-96', '--space-128'];
60
+ const SPACE_RUNGS = SPACE_SETTABLE;
61
+
62
+ /** Content insets stop at `--space-4`. Below it the text sits against its own
63
+ edge, which is a deliberate choice rather than somewhere a relative
64
+ "tighter" should deposit you. Outer space is exempt: a 2px gap between an
65
+ icon and its label, or a 2px margin under a bar, is ordinary design. Both
66
+ rungs stay pickable by hand and settable by name. */
67
+ const INSET_RUNGS = SPACE_SETTABLE.slice(SPACE_SETTABLE.indexOf('--space-4'));
68
+
69
+ const SPACE_FAMILY = [...SPACE_SETTABLE, '--space-40', '--space-64', '--space-96', '--space-128'];
61
70
 
62
71
  const BORDER_WIDTH_RUNGS = [
63
72
  '--border-width-0', '--border-width-1', '--border-width-2', '--border-width-3',
@@ -66,48 +75,66 @@ const BORDER_WIDTH_RUNGS = [
66
75
  '--border-width-24',
67
76
  ];
68
77
 
69
- const LADDERS: Record<AdjustKind, { rungs: string[]; family: string[] }> = {
70
- radius: { rungs: RADIUS_RUNGS, family: [...RADIUS_RUNGS, RADIUS_FULL] },
71
- padding: { rungs: SPACE_RUNGS, family: SPACE_FAMILY },
72
- gap: { rungs: SPACE_RUNGS, family: SPACE_FAMILY },
73
- 'border-width': { rungs: BORDER_WIDTH_RUNGS, family: BORDER_WIDTH_RUNGS },
78
+ const LADDERS: Record<AdjustKind, { rungs: string[]; settable: string[]; family: string[] }> = {
79
+ radius: {
80
+ rungs: RADIUS_RUNGS,
81
+ settable: [...RADIUS_RUNGS, RADIUS_FULL],
82
+ family: [...RADIUS_RUNGS, RADIUS_FULL],
83
+ },
84
+ padding: { rungs: SPACE_RUNGS, settable: SPACE_SETTABLE, family: SPACE_FAMILY },
85
+ gap: { rungs: SPACE_RUNGS, settable: SPACE_SETTABLE, family: SPACE_FAMILY },
86
+ 'border-width': {
87
+ rungs: BORDER_WIDTH_RUNGS,
88
+ settable: BORDER_WIDTH_RUNGS,
89
+ family: BORDER_WIDTH_RUNGS,
90
+ },
74
91
  };
75
92
 
76
93
  const TOKEN_NAME = /^--[a-z0-9-]+$/;
77
94
 
78
95
  type Outcome = { from: string; to: string } | { skip: SkipReason };
79
96
 
80
- function rungsFor(op: AdjustOp): string[] {
81
- return op.kind === 'radius' && op.full ? [...RADIUS_RUNGS, RADIUS_FULL] : LADDERS[op.kind].rungs;
97
+ /** `-margin` shares the padding kind, so the inset floor keys off the variable
98
+ rather than the kind. */
99
+ function rungsFor(op: AdjustOp, variable: string): string[] {
100
+ if (op.kind === 'radius') return op.full ? [...RADIUS_RUNGS, RADIUS_FULL] : RADIUS_RUNGS;
101
+ if (op.kind === 'padding' && stripSide(variable).endsWith('-padding')) return INSET_RUNGS;
102
+ return LADDERS[op.kind].rungs;
82
103
  }
83
104
 
84
105
  function spaceStep(token: string): number {
85
106
  return Number(token.slice('--space-'.length));
86
107
  }
87
108
 
88
- /** `<=` sends an exact tie (`--space-40`, midway between 32 and 48) upward. */
89
- function nearestSpaceRung(token: string, rungs: string[]): number {
109
+ /** An off-rung value has no step to count from, so landing on the first rung
110
+ the shift points at is itself that shift's opening step. Snapping to the
111
+ nearest rung instead would spend two visible steps on a one-step request.
112
+ Returns -1 when the ladder holds nothing in that direction. */
113
+ function snapRung(token: string, rungs: string[], direction: number): number {
90
114
  const step = spaceStep(token);
91
- let best = 0;
92
- for (let i = 1; i < rungs.length; i++) {
93
- if (Math.abs(spaceStep(rungs[i]) - step) <= Math.abs(spaceStep(rungs[best]) - step)) best = i;
115
+ if (direction > 0) return rungs.findIndex((rung) => spaceStep(rung) > step);
116
+ for (let index = rungs.length - 1; index >= 0; index--) {
117
+ if (spaceStep(rungs[index]) < step) return index;
94
118
  }
95
- return best;
119
+ return -1;
96
120
  }
97
121
 
98
- function resolve(op: AdjustOp, value: AliasDiskValue): Outcome {
122
+ function resolve(op: AdjustOp, variable: string, value: AliasDiskValue): Outcome {
99
123
  if (typeof value !== 'string' || !TOKEN_NAME.test(value)) return { skip: 'raw-value' };
100
124
  if (!LADDERS[op.kind].family.includes(value)) return { skip: 'off-ladder' };
101
125
  if (op.set !== undefined) return { from: value, to: op.set };
102
126
 
103
- const rungs = rungsFor(op);
127
+ const rungs = rungsFor(op, variable);
104
128
  let index = rungs.indexOf(value);
129
+ let shift = op.shift!;
105
130
  if (index < 0) {
106
131
  if (value === RADIUS_FULL) return { skip: 'pill-preserved' };
107
- index = nearestSpaceRung(value, rungs);
132
+ index = snapRung(value, rungs, shift);
133
+ if (index < 0) return { skip: 'clamped' };
134
+ shift -= Math.sign(shift);
108
135
  }
109
136
 
110
- const wanted = index + op.shift!;
137
+ const wanted = index + shift;
111
138
  const landed = Math.min(Math.max(wanted, 0), rungs.length - 1);
112
139
  if (landed !== wanted && rungs[landed] === value) return { skip: 'clamped' };
113
140
  return { from: value, to: rungs[landed] };
@@ -123,7 +150,7 @@ function validateOp(op: AdjustOp, configs: Record<string, ComponentConfig>): voi
123
150
  const hasSet = op.set !== undefined;
124
151
  const hasShift = op.shift !== undefined;
125
152
  if (hasSet === hasShift) throw new Error(`A ${op.kind} op needs exactly one of "set" or "shift"`);
126
- const settable = op.kind === 'radius' ? ladder.family : ladder.rungs;
153
+ const settable = ladder.settable;
127
154
  if (hasSet && !settable.includes(op.set!)) {
128
155
  throw new Error(`"${op.set}" is not on the ${op.kind} ladder`);
129
156
  }
@@ -161,7 +188,7 @@ export function adjustAliases(
161
188
 
162
189
  for (const [variable, value] of Object.entries(config.aliases)) {
163
190
  if (!matchesKind(variable, op.kind)) continue;
164
- const outcome = resolve(op, value);
191
+ const outcome = resolve(op, variable, value);
165
192
  if ('skip' in outcome) {
166
193
  reportFor(component).skips.push({ variable, value, reason: outcome.skip });
167
194
  continue;
@@ -64,10 +64,15 @@ const MATCHER_BY_KIND = Object.fromEntries(
64
64
 
65
65
  const SIDE_SUFFIXES = ['-top', '-right', '-bottom', '-left'];
66
66
 
67
+ /** Drops a per-side suffix so callers can test the parent name. */
68
+ export function stripSide(variable: string): string {
69
+ const side = SIDE_SUFFIXES.find((s) => variable.endsWith(s));
70
+ return side ? variable.slice(0, -side.length) : variable;
71
+ }
72
+
67
73
  /** Side-aware kind test. Per-side paddings (`--card-default-body-padding-top`)
68
74
  are written by UIPaddingSelector and never declared as editor tokens, so
69
75
  `rawKind` never meets one; the CLI does, and they belong with their parent. */
70
76
  export function matchesKind(variable: string, kind: TokenKind): boolean {
71
- const side = SIDE_SUFFIXES.find((s) => variable.endsWith(s));
72
- return MATCHER_BY_KIND[kind](side ? variable.slice(0, -side.length) : variable);
77
+ return MATCHER_BY_KIND[kind](stripSide(variable));
73
78
  }
@@ -58,7 +58,7 @@ export const deleteComponentConfig = (component: string, fileName: string): Prom
58
58
  resourceFor(component).remove(fileName);
59
59
 
60
60
  /** The config the component is running: the buffer, else the open theme's
61
- * copy, else the component default. `_source` says which. */
61
+ * copy (every theme carries every component by value). `_source` says which. */
62
62
  export const getActiveComponentConfig = (component: string): Promise<ComponentConfig | null> =>
63
63
  resourceFor(component).getActive();
64
64