@motion-proto/live-tokens 0.13.0 → 0.13.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@motion-proto/live-tokens",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "type": "module",
5
5
  "description": "Design token editor with live CSS variable editing. Svelte 5 + Vite 6/7.",
6
6
  "keywords": [
@@ -1,7 +1,15 @@
1
1
  import type { FontFamily, FontSource, FontStack, Theme } from '../themes/themeTypes';
2
- import frauncesRomanLatin from '../../../system/styles/fonts/Fraunces/Fraunces-roman-latin.woff2?url';
3
- import frauncesItalicLatin from '../../../system/styles/fonts/Fraunces/Fraunces-italic-latin.woff2?url';
4
- import manropeLatin from '../../../system/styles/fonts/Manrope/Manrope-latin.woff2?url';
2
+
3
+ // Stable relative paths. fonts.css and fonts/ ship colocated under
4
+ // src/system/styles/ in this package, so `./fonts/...` resolves correctly
5
+ // whether the css is served from the repo's own dev server, from inside
6
+ // node_modules in a consumer, or from a hashed asset in a production build.
7
+ // (Previously these were Vite `?url` imports — those resolved to absolute
8
+ // paths like `/src/system/styles/fonts/...` that worked inside live-tokens
9
+ // but 404'd for any consumer importing the bundled fonts.css.)
10
+ const FRAUNCES_ROMAN_LATIN = './fonts/Fraunces/Fraunces-roman-latin.woff2';
11
+ const FRAUNCES_ITALIC_LATIN = './fonts/Fraunces/Fraunces-italic-latin.woff2';
12
+ const MANROPE_LATIN = './fonts/Manrope/Manrope-latin.woff2';
5
13
 
6
14
  function makeId(prefix: string): string {
7
15
  return `${prefix}_${Math.random().toString(36).slice(2, 10)}`;
@@ -43,7 +51,7 @@ export function defaultFontSources(): FontSource[] {
43
51
  {
44
52
  id: frauncesId,
45
53
  kind: 'font-face',
46
- cssText: `@font-face {\n font-family: "Fraunces";\n src: url('${frauncesRomanLatin}') format('woff2');\n font-weight: 100 900;\n font-style: normal;\n font-display: swap;\n}\n@font-face {\n font-family: "Fraunces";\n src: url('${frauncesItalicLatin}') format('woff2');\n font-weight: 100 900;\n font-style: italic;\n font-display: swap;\n}`,
54
+ cssText: `@font-face {\n font-family: "Fraunces";\n src: url('${FRAUNCES_ROMAN_LATIN}') format('woff2');\n font-weight: 100 900;\n font-style: normal;\n font-display: swap;\n}\n@font-face {\n font-family: "Fraunces";\n src: url('${FRAUNCES_ITALIC_LATIN}') format('woff2');\n font-weight: 100 900;\n font-style: italic;\n font-display: swap;\n}`,
47
55
  label: 'Local',
48
56
  families: [
49
57
  fam(frauncesId, 'Fraunces', '"Fraunces"', [100, 200, 300, 400, 500, 600, 700, 800, 900]),
@@ -52,7 +60,7 @@ export function defaultFontSources(): FontSource[] {
52
60
  {
53
61
  id: manropeId,
54
62
  kind: 'font-face',
55
- cssText: `@font-face {\n font-family: "Manrope";\n src: url('${manropeLatin}') format('woff2');\n font-weight: 200 800;\n font-style: normal;\n font-display: swap;\n}`,
63
+ cssText: `@font-face {\n font-family: "Manrope";\n src: url('${MANROPE_LATIN}') format('woff2');\n font-weight: 200 800;\n font-style: normal;\n font-display: swap;\n}`,
56
64
  label: 'Local',
57
65
  families: [
58
66
  fam(manropeId, 'Manrope', '"Manrope"', [200, 300, 400, 500, 600, 700, 800]),
@@ -116,11 +124,28 @@ export function defaultFontStacks(sources: FontSource[]): FontStack[] {
116
124
  * only when missing; safe to call on already-migrated themes. Also strips any
117
125
  * stale --font-* entries from cssVariables since those are now derived.
118
126
  */
127
+ // Older themes (built before relative font paths) baked absolute Vite-resolved
128
+ // URLs into fontSources[].cssText, e.g. `/src/system/styles/fonts/...` or
129
+ // `/src/live-tokens/system/styles/fonts/...`. Those paths only resolve inside
130
+ // the live-tokens repo or a consumer that vendored the source; in any package
131
+ // consumer they 404. Normalise to the package-relative `./fonts/...` form on
132
+ // theme load.
133
+ const ABSOLUTE_FONT_PATH_PATTERN = /'\/src\/(?:live-tokens\/)?system\/styles\/fonts\//g;
134
+
119
135
  export function migrateThemeFonts(theme: Theme): { migrated: boolean } {
120
136
  let migrated = false;
121
137
  if (!theme.fontSources || theme.fontSources.length === 0) {
122
138
  theme.fontSources = defaultFontSources();
123
139
  migrated = true;
140
+ } else {
141
+ for (const src of theme.fontSources) {
142
+ if (!src.cssText) continue;
143
+ const rewritten = src.cssText.replace(ABSOLUTE_FONT_PATH_PATTERN, "'./fonts/");
144
+ if (rewritten !== src.cssText) {
145
+ src.cssText = rewritten;
146
+ migrated = true;
147
+ }
148
+ }
124
149
  }
125
150
  if (!theme.fontStacks || theme.fontStacks.length === 0) {
126
151
  theme.fontStacks = defaultFontStacks(theme.fontSources);
@@ -63,11 +63,20 @@
63
63
  });
64
64
 
65
65
  // The /components route renders the same component-editor surface as the
66
- // overlay's components view. Pair them: when the page is /components, flip
67
- // the overlay to tokens so the two surfaces don't stack.
66
+ // overlay's components view. Pair them: on entering /components, flip the
67
+ // overlay to tokens so the two surfaces don't stack. Fires only on route
68
+ // change, not on every editorView change — otherwise cross-window storage
69
+ // sync re-triggers the rule, which writes editorView, which fires another
70
+ // storage event, which fires the rule again. The result is heavy re-render
71
+ // cascades (the storage handler regularly took >1s in practice) and a
72
+ // visible flicker as the view bounces.
73
+ let prevRoute: string | undefined;
68
74
  run(() => {
69
- if ($route === '/components' && $editorView === 'components') {
70
- editorView.set('tokens');
75
+ const r = $route;
76
+ if (r === prevRoute) return;
77
+ prevRoute = r;
78
+ if (r === '/components') {
79
+ editorView.update((v) => (v === 'components' ? 'tokens' : v));
71
80
  }
72
81
  });
73
82
 
@@ -13,7 +13,7 @@
13
13
  /* Local — Manrope */
14
14
  @font-face {
15
15
  font-family: "Manrope";
16
- src: url('/src/system/styles/fonts/Manrope/Manrope-latin.woff2') format('woff2');
16
+ src: url('./fonts/Manrope/Manrope-latin.woff2') format('woff2');
17
17
  font-weight: 200 800;
18
18
  font-style: normal;
19
19
  font-display: swap;