@motion-proto/live-tokens 0.73.0 → 0.74.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-build-page/SKILL.md +2 -2
- package/.claude/skills/live-tokens-check-compliance/SKILL.md +2 -2
- package/.claude/skills/live-tokens-create-component/SKILL.md +4 -4
- package/.claude/skills/live-tokens-create-theme/SKILL.md +80 -0
- package/.claude/skills/live-tokens-create-theme/references/design-directions.md +94 -0
- package/.claude/skills/live-tokens-set-colors/SKILL.md +140 -0
- package/.claude/skills/live-tokens-set-colors/references/color-anchors.md +80 -0
- package/.claude/skills/{live-tokens-adjust-geometry → live-tokens-set-geometry}/SKILL.md +12 -7
- package/.claude/skills/live-tokens-set-geometry/references/geometry-anchors.md +61 -0
- package/.claude/skills/{live-tokens-pair-fonts → live-tokens-set-type}/SKILL.md +18 -15
- package/.claude/skills/live-tokens-set-type/references/type-anchors.md +60 -0
- package/CHANGELOG.md +91 -0
- package/README.md +24 -15
- package/bin/check-page.mjs +3 -3
- package/bin/cli.mjs +92 -55
- package/bin/lib/liveState.mjs +110 -0
- package/bin/save-theme.mjs +177 -0
- package/bin/set-colors.mjs +191 -0
- package/bin/{adjust.mjs → set-geometry.mjs} +18 -50
- package/bin/{set-fonts.mjs → set-type.mjs} +21 -55
- package/dist-plugin/{chunk-RIXO2E55.js → chunk-7VRTBGJT.js} +1 -1
- package/dist-plugin/{chunk-YLCOIGQC.js → chunk-V3YF6CGT.js} +56 -2
- package/dist-plugin/index.cjs +58 -3
- package/dist-plugin/index.js +11 -11
- package/dist-plugin/migrateData/index.cjs +56 -1
- package/dist-plugin/migrateData/index.js +2 -2
- package/dist-plugin/{generateColorsAndType → setColors}/index.cjs +1109 -1071
- package/dist-plugin/{generateColorsAndType → setColors}/index.d.cts +33 -24
- package/dist-plugin/{generateColorsAndType → setColors}/index.d.ts +33 -24
- package/dist-plugin/{generateColorsAndType → setColors}/index.js +45 -63
- package/dist-plugin/{adjust → setGeometry}/index.cjs +60 -5
- package/dist-plugin/{adjust → setGeometry}/index.d.cts +1 -1
- package/dist-plugin/{adjust → setGeometry}/index.d.ts +1 -1
- package/dist-plugin/{adjust → setGeometry}/index.js +1 -1
- package/dist-plugin/{fontPairing → setType}/index.cjs +4 -4
- package/dist-plugin/{fontPairing → setType}/index.d.cts +1 -1
- package/dist-plugin/{fontPairing → setType}/index.d.ts +1 -1
- package/dist-plugin/{themeTypes-DSV3Zisf.d.cts → themeTypes-BxRtuN5V.d.cts} +1 -1
- package/dist-plugin/{themeTypes-DSV3Zisf.d.ts → themeTypes-BxRtuN5V.d.ts} +1 -1
- package/package.json +2 -1
- package/src/editor/core/themes/{generateColorsAndType.ts → buildColors.ts} +82 -96
- package/src/editor/core/themes/migrations/2026-09-03-drop-legacy-component-keys.ts +62 -0
- package/src/editor/core/themes/migrations/index.ts +2 -0
- package/src/editor/docs/content/themes-workflow.md +2 -2
- package/src/editor/docs/content.generated.ts +1 -1
- package/src/editor/overlay/LiveEditorOverlay.svelte +519 -28
- package/src/editor/skill-atlas/SkillAtlas.svelte +2 -2
- package/src/editor/skill-atlas/skillSources.generated.ts +19 -15
- package/src/editor/skill-atlas/skillTrees.ts +785 -632
- package/src/live-tokens/data/colors-and-type/autumn.json +1 -37
- package/src/live-tokens/data/colors-and-type/default.json +1 -37
- package/src/live-tokens/data/colors-and-type/halloween.json +1 -37
- package/src/live-tokens/data/colors-and-type/midnight-study.json +1 -37
- package/src/live-tokens/data/colors-and-type/ocean.json +1 -37
- package/src/live-tokens/data/colors-and-type/royal-velvet.json +1 -37
- package/src/live-tokens/data/colors-and-type/sketchy.json +1 -37
- package/src/live-tokens/data/colors-and-type/spring-meadow.json +1 -37
- package/src/live-tokens/data/colors-and-type/sunset.json +1 -37
- package/src/live-tokens/data/themes/autumn.json +1 -37
- package/src/live-tokens/data/themes/halloween.json +1 -37
- package/src/live-tokens/data/themes/midnight-study.json +1 -37
- package/src/live-tokens/data/themes/ocean.json +1 -37
- package/src/live-tokens/data/themes/royal-velvet.json +1 -37
- package/src/live-tokens/data/themes/sketchy.json +1 -37
- package/src/live-tokens/data/themes/spring-meadow.json +1 -37
- package/src/live-tokens/data/themes/sunset.json +1 -37
- package/src/live-tokens/data/tokens.generated.css +0 -36
- package/.claude/skills/live-tokens-generate-theme/SKILL.md +0 -156
- package/.claude/skills/live-tokens-generate-theme/references/mood-vocabulary.md +0 -43
- package/.claude/skills/live-tokens-generate-theme/references/named-themes.md +0 -18
- package/.claude/skills/live-tokens-generate-theme/references/style-vocabulary.md +0 -35
- package/bin/generate-theme.mjs +0 -260
- /package/dist-plugin/{fontPairing → setType}/index.js +0 -0
package/bin/generate-theme.mjs
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
// `live-tokens generate-theme` worker.
|
|
2
|
-
//
|
|
3
|
-
// Reads a seed brief (JSON), builds a full validated colors-and-type layer via
|
|
4
|
-
// the compiled engine (dist-plugin/generateColorsAndType — the CLI never imports
|
|
5
|
-
// TS sources), enforces the AA contrast gate, and saves the result as a theme:
|
|
6
|
-
// <themesDir>/<slug>.json, the document that carries the whole theme by value.
|
|
7
|
-
// Unless --no-activate it then opens that theme the way the dev server's apply
|
|
8
|
-
// door does — existing `_working` buffers are cleared and
|
|
9
|
-
// `themes/_active.json` names it. Nothing else moves, so generating a theme
|
|
10
|
-
// cannot change what the site ships.
|
|
11
|
-
//
|
|
12
|
-
// Non-color content (shadows, component aliases, fonts) carries forward from
|
|
13
|
-
// the live state so generation only replaces the color identity. Swatch
|
|
14
|
-
// gradients ride along too when user-tuned; stock ones are rebuilt from the new
|
|
15
|
-
// theme's families by the engine.
|
|
16
|
-
|
|
17
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
18
|
-
import { dirname, join, relative, resolve } from 'node:path';
|
|
19
|
-
import { fileURLToPath } from 'node:url';
|
|
20
|
-
|
|
21
|
-
const pkgRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
22
|
-
const ENGINE = resolve(pkgRoot, 'dist-plugin/generateColorsAndType/index.js');
|
|
23
|
-
const packageDataDir = join(pkgRoot, 'src/live-tokens/data');
|
|
24
|
-
// Source of truth: src/editor/core/themes/themeTypes.ts, which
|
|
25
|
-
// normalizeTheme.ts re-exports. This copy cannot import TS, so
|
|
26
|
-
// `check:preset-themes` and generate-theme.test.ts are what catch a drift.
|
|
27
|
-
const THEME_SCHEMA_VERSION = 5;
|
|
28
|
-
|
|
29
|
-
async function loadEngine() {
|
|
30
|
-
if (!existsSync(ENGINE)) {
|
|
31
|
-
throw new Error(
|
|
32
|
-
`theme engine not found at ${relative(process.cwd(), ENGINE)}. ` +
|
|
33
|
-
`Build the plugin first (npm run build:plugin).`,
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
return import(ENGINE);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function readJson(path) {
|
|
40
|
-
return JSON.parse(readFileSync(path, 'utf8'));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function readJsonIfExists(path) {
|
|
44
|
-
try {
|
|
45
|
-
return existsSync(path) ? readJson(path) : null;
|
|
46
|
-
} catch {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Local dir first, then the installed package's shipped copy — the same
|
|
52
|
-
* fallback order the dev server's reads use. */
|
|
53
|
-
function readData(localDir, packageSubdir, fileName) {
|
|
54
|
-
return (
|
|
55
|
-
readJsonIfExists(join(localDir, `${fileName}.json`)) ??
|
|
56
|
-
readJsonIfExists(join(packageDataDir, packageSubdir, `${fileName}.json`))
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function componentNames(componentConfigsDir) {
|
|
61
|
-
if (!existsSync(componentConfigsDir)) return [];
|
|
62
|
-
return readdirSync(componentConfigsDir, { withFileTypes: true })
|
|
63
|
-
.filter((e) => e.isDirectory())
|
|
64
|
-
.map((e) => e.name)
|
|
65
|
-
.sort();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** `_fileName` and `_source` are read-door markers, never part of a document. */
|
|
69
|
-
function stripMarkers(value) {
|
|
70
|
-
if (!value || typeof value !== 'object') return value;
|
|
71
|
-
const { _fileName, _source, ...rest } = value;
|
|
72
|
-
return rest;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** A component's derived default, local tree first, then the installed
|
|
76
|
-
* package's shipped copy — same fallback order every other read here uses. */
|
|
77
|
-
function defaultComponentConfig(componentConfigsDir, comp) {
|
|
78
|
-
return readData(join(componentConfigsDir, comp), `component-configs/${comp}`, 'default');
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* The look the new theme carries forward. Without --carry-from that is the LIVE
|
|
83
|
-
* state — buffer first, then the open theme, then the shipped default — because
|
|
84
|
-
* what the user sees is what they expect to keep. With it, the named theme,
|
|
85
|
-
* then the shipped default for anything that theme omits, so an incomplete
|
|
86
|
-
* source never produces an incomplete result.
|
|
87
|
-
*/
|
|
88
|
-
function resolveCarrySource({ carryFrom, colorsAndTypeDir, componentConfigsDir, themesDir }) {
|
|
89
|
-
const comps = componentNames(componentConfigsDir);
|
|
90
|
-
|
|
91
|
-
if (carryFrom) {
|
|
92
|
-
const theme = readData(themesDir, 'themes', carryFrom);
|
|
93
|
-
if (!theme) throw new Error(`--carry-from theme "${carryFrom}" not found`);
|
|
94
|
-
const componentConfigs = {};
|
|
95
|
-
for (const comp of comps) {
|
|
96
|
-
const cfg = theme.componentConfigs?.[comp] ?? defaultComponentConfig(componentConfigsDir, comp);
|
|
97
|
-
if (cfg) componentConfigs[comp] = stripMarkers(cfg);
|
|
98
|
-
}
|
|
99
|
-
return { colorsAndType: stripMarkers(theme.colorsAndType), componentConfigs };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const activeSlug = readJsonIfExists(join(themesDir, '_active.json'))?.activeFile ?? 'default';
|
|
103
|
-
const activeTheme = readData(themesDir, 'themes', activeSlug);
|
|
104
|
-
const colorsAndType = stripMarkers(
|
|
105
|
-
readJsonIfExists(join(colorsAndTypeDir, '_working.json')) ??
|
|
106
|
-
activeTheme?.colorsAndType ??
|
|
107
|
-
readData(colorsAndTypeDir, 'colors-and-type', 'default'),
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
// A working buffer is an unsaved delta from the active theme; absent theme
|
|
111
|
-
// component entries fall through to the component defaults. Mirrors
|
|
112
|
-
// `bin/adjust.mjs`'s `readLiveConfigs` and the dev server's
|
|
113
|
-
// `resolveLiveComponentConfig` — all three layers, in the same order.
|
|
114
|
-
const componentConfigs = {};
|
|
115
|
-
for (const comp of comps) {
|
|
116
|
-
const live =
|
|
117
|
-
readJsonIfExists(join(componentConfigsDir, comp, '_working.json')) ??
|
|
118
|
-
activeTheme?.componentConfigs?.[comp] ??
|
|
119
|
-
defaultComponentConfig(componentConfigsDir, comp);
|
|
120
|
-
if (live) componentConfigs[comp] = stripMarkers(live);
|
|
121
|
-
}
|
|
122
|
-
return { colorsAndType, componentConfigs };
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** `engine` is a test seam; the CLI always runs the compiled bundle. */
|
|
126
|
-
export async function runGenerateTheme({
|
|
127
|
-
briefPath,
|
|
128
|
-
activate = true,
|
|
129
|
-
dryRun = false,
|
|
130
|
-
carryFrom,
|
|
131
|
-
root = process.cwd(),
|
|
132
|
-
colorsAndTypeDir,
|
|
133
|
-
componentConfigsDir,
|
|
134
|
-
themesDir,
|
|
135
|
-
engine,
|
|
136
|
-
} = {}) {
|
|
137
|
-
const { buildColorsAndTypeFromSeeds, resolveDataDirs, CURRENT_COMPONENT_SCHEMA_VERSION } =
|
|
138
|
-
engine ?? (await loadEngine());
|
|
139
|
-
|
|
140
|
-
const briefFull = resolve(root, briefPath);
|
|
141
|
-
if (!existsSync(briefFull)) {
|
|
142
|
-
throw new Error(`brief not found at ${relative(root, briefFull)}`);
|
|
143
|
-
}
|
|
144
|
-
let brief;
|
|
145
|
-
try {
|
|
146
|
-
brief = readJson(briefFull);
|
|
147
|
-
} catch (err) {
|
|
148
|
-
throw new Error(`brief is not valid JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const dirs =
|
|
152
|
-
colorsAndTypeDir && componentConfigsDir && themesDir
|
|
153
|
-
? { colorsAndTypeDir, componentConfigsDir, themesDir }
|
|
154
|
-
: resolveDataDirs();
|
|
155
|
-
|
|
156
|
-
const previousActive = readJsonIfExists(join(dirs.themesDir, '_active.json'))?.activeFile ?? 'default';
|
|
157
|
-
const carry = resolveCarrySource({ carryFrom, ...dirs });
|
|
158
|
-
|
|
159
|
-
const { colorsAndType, slug, report } = buildColorsAndTypeFromSeeds(
|
|
160
|
-
brief,
|
|
161
|
-
{
|
|
162
|
-
cssVariables: carry.colorsAndType?.cssVariables,
|
|
163
|
-
fontSources: carry.colorsAndType?.fontSources,
|
|
164
|
-
fontStacks: carry.colorsAndType?.fontStacks,
|
|
165
|
-
gradients: carry.colorsAndType?.gradients,
|
|
166
|
-
},
|
|
167
|
-
new Date().toISOString(),
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
const themePath = join(dirs.themesDir, `${slug}.json`);
|
|
171
|
-
const existing = readJsonIfExists(themePath);
|
|
172
|
-
const theme = {
|
|
173
|
-
name: colorsAndType.name,
|
|
174
|
-
createdAt: existing?.createdAt ?? colorsAndType.createdAt,
|
|
175
|
-
updatedAt: colorsAndType.updatedAt,
|
|
176
|
-
schemaVersion: THEME_SCHEMA_VERSION,
|
|
177
|
-
colorsAndType,
|
|
178
|
-
componentConfigs: carry.componentConfigs,
|
|
179
|
-
componentSchemaVersion: CURRENT_COMPONENT_SCHEMA_VERSION,
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
if (!dryRun) {
|
|
183
|
-
mkdirSync(dirs.themesDir, { recursive: true });
|
|
184
|
-
writeFileSync(themePath, JSON.stringify(theme, null, 2) + '\n');
|
|
185
|
-
if (activate) applyTheme(slug, dirs);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return {
|
|
189
|
-
name: theme.name,
|
|
190
|
-
slug,
|
|
191
|
-
themePath,
|
|
192
|
-
existed: existing !== null,
|
|
193
|
-
activated: activate && !dryRun,
|
|
194
|
-
previousActive,
|
|
195
|
-
carriedFrom: carryFrom ?? null,
|
|
196
|
-
componentsCarried: Object.keys(carry.componentConfigs).length,
|
|
197
|
-
dryRun,
|
|
198
|
-
report,
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/** The apply door's write set, reproduced: clear every working delta and point
|
|
203
|
-
* `themes/_active.json` at the open document. Production is untouched. */
|
|
204
|
-
function applyTheme(slug, dirs) {
|
|
205
|
-
const colorsWorking = join(dirs.colorsAndTypeDir, '_working.json');
|
|
206
|
-
if (existsSync(colorsWorking)) rmSync(colorsWorking);
|
|
207
|
-
|
|
208
|
-
for (const comp of componentNames(dirs.componentConfigsDir)) {
|
|
209
|
-
const workingPath = join(dirs.componentConfigsDir, comp, '_working.json');
|
|
210
|
-
if (existsSync(workingPath)) rmSync(workingPath);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
writeFileSync(join(dirs.themesDir, '_active.json'), JSON.stringify({ activeFile: slug }));
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export function formatGenerateThemeResult(result) {
|
|
217
|
-
const root = process.cwd();
|
|
218
|
-
const lines = [];
|
|
219
|
-
const wrote = result.dryRun ? 'Would write' : result.existed ? 'Updated' : 'Created';
|
|
220
|
-
lines.push(`${wrote} theme "${result.name}" → ${relative(root, result.themePath)}`);
|
|
221
|
-
lines.push(
|
|
222
|
-
`Carried forward from ${result.carriedFrom ? `theme "${result.carriedFrom}"` : 'the live state'}: ` +
|
|
223
|
-
`fonts, gradients and ${result.componentsCarried} component config(s).`,
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
lines.push(`\nContrast report (${result.report.scheme} scheme):`);
|
|
227
|
-
const width = Math.max(...result.report.checks.map((c) => c.textVar.length));
|
|
228
|
-
for (const c of result.report.checks) {
|
|
229
|
-
const mark = c.pass ? '✓' : '✗';
|
|
230
|
-
const fixed = c.corrected ? ' (auto-corrected)' : '';
|
|
231
|
-
lines.push(
|
|
232
|
-
` ${mark} ${c.textVar.padEnd(width)} ${c.ratio.toFixed(2).padStart(6)}:1 vs ${c.against} floor ${c.floor}:1${fixed}`,
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
if (result.report.failures.length > 0) {
|
|
236
|
-
lines.push(`\nUnmet floors — adjust the brief's seeds and re-run:`);
|
|
237
|
-
for (const f of result.report.failures) lines.push(` ! ${f}`);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
lines.push(
|
|
241
|
-
result.report.gradients === 'carried'
|
|
242
|
-
? '\nGradients: kept your tuned swatch gradients.'
|
|
243
|
-
: '\nGradients: swatch tokens rebuilt from the theme families.',
|
|
244
|
-
);
|
|
245
|
-
lines.push(`Shadows: ${result.report.shadows}; carried geometry kept.`);
|
|
246
|
-
if (result.report.canvasGradient) {
|
|
247
|
-
lines.push(`Canvas sky: ${result.report.canvasGradient}.`);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (result.activated) {
|
|
251
|
-
lines.push(
|
|
252
|
-
`\nOpened "${result.slug}" (previously open: "${result.previousActive}"). ` +
|
|
253
|
-
`Reload the app to see it; switch back any time from Load in the editor's Theme panel. ` +
|
|
254
|
-
`Adopt it there to publish it to tokens.generated.css.`,
|
|
255
|
-
);
|
|
256
|
-
} else if (!result.dryRun) {
|
|
257
|
-
lines.push(`\nNot opened (--no-activate). Load "${result.slug}" from the editor's Theme panel to see it.`);
|
|
258
|
-
}
|
|
259
|
-
return lines.join('\n');
|
|
260
|
-
}
|
|
File without changes
|