decklight 0.9.0 → 0.11.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 (133) hide show
  1. package/NOTICE +2 -0
  2. package/PLATFORM.md +61 -3
  3. package/README.md +58 -28
  4. package/SPEC.md +1326 -85
  5. package/cli/agent-review.mjs +5 -4
  6. package/cli/agents.mjs +148 -18
  7. package/cli/bundle-audio.mjs +10 -3
  8. package/cli/bundle-module.mjs +95 -0
  9. package/cli/bundle.mjs +125 -7
  10. package/cli/cast.mjs +86 -19
  11. package/cli/check-fixes.mjs +194 -0
  12. package/cli/check-watch.mjs +151 -0
  13. package/cli/check.mjs +491 -75
  14. package/cli/code-editor.mjs +287 -0
  15. package/cli/commands.mjs +13 -2
  16. package/cli/commit-flow.mjs +7 -3
  17. package/cli/commit-message.mjs +35 -8
  18. package/cli/commit-split.mjs +125 -25
  19. package/cli/deck-refs.mjs +8 -3
  20. package/cli/decklight.mjs +11 -1
  21. package/cli/design-system-edit.mjs +37 -1
  22. package/cli/design-system-refs.mjs +263 -6
  23. package/cli/design-system.mjs +82 -14
  24. package/cli/edit-address.mjs +184 -0
  25. package/cli/edit-git.mjs +23 -6
  26. package/cli/edit-handover.mjs +257 -40
  27. package/cli/edit-look.mjs +293 -6
  28. package/cli/edit-open.mjs +143 -0
  29. package/cli/edit-slides.mjs +1043 -67
  30. package/cli/edit-translate.mjs +243 -0
  31. package/cli/edit.mjs +3680 -319
  32. package/cli/editor-support.mjs +286 -0
  33. package/cli/enhance.mjs +157 -27
  34. package/cli/find-replace.mjs +142 -0
  35. package/cli/fix-review.mjs +368 -0
  36. package/cli/git.mjs +13 -0
  37. package/cli/init.mjs +101 -22
  38. package/cli/keep-awake.mjs +68 -0
  39. package/cli/marketplace-autocheck.mjs +200 -0
  40. package/cli/marketplace.mjs +250 -13
  41. package/cli/migrate-writing.mjs +214 -0
  42. package/cli/narrate.mjs +121 -5
  43. package/cli/open.mjs +53 -15
  44. package/cli/outside-edit.mjs +257 -0
  45. package/cli/paste.mjs +92 -0
  46. package/cli/pdf.mjs +88 -10
  47. package/cli/pptx-export.mjs +10 -5
  48. package/cli/publish.mjs +24 -3
  49. package/cli/record.mjs +86 -15
  50. package/cli/remote.mjs +32 -6
  51. package/cli/rewrite.mjs +265 -0
  52. package/cli/runtime-link.mjs +218 -17
  53. package/cli/serve.mjs +9 -6
  54. package/cli/setup.mjs +2 -2
  55. package/cli/skill-content.mjs +251 -10
  56. package/cli/skills/slide-writing.md +333 -0
  57. package/cli/skills/voiceover.md +423 -0
  58. package/cli/skills.mjs +282 -15
  59. package/cli/starter-full.mjs +353 -0
  60. package/cli/supervise.mjs +14 -0
  61. package/cli/theme-refs.mjs +14 -2
  62. package/cli/theme.mjs +3 -2
  63. package/cli/translate-core.mjs +466 -0
  64. package/cli/translate-files.mjs +149 -0
  65. package/cli/translate.mjs +458 -0
  66. package/cli/units.mjs +75 -7
  67. package/cli/util.mjs +25 -0
  68. package/cli/vocabulary-docs.mjs +138 -0
  69. package/dist/decklight.css +2506 -113
  70. package/dist/decklight.js +385 -175
  71. package/dist/decklight.js.map +4 -4
  72. package/docs/GLOSSARY.md +9 -2
  73. package/docs/WRITING_RESEARCH.md +327 -0
  74. package/package.json +5 -3
  75. package/themes/coastal.css +3 -0
  76. package/themes/metropolis.css +2 -0
  77. package/themes/reveal-blood.css +3 -0
  78. package/themes/reveal-league.css +2 -0
  79. package/themes/reveal-moon.css +2 -0
  80. package/themes/reveal-serif.css +1 -0
  81. package/themes/reveal-sky.css +1 -0
  82. package/themes/reveal-solarized.css +4 -0
  83. package/tools/brand-palette.mjs +6 -1
  84. package/tools/build-groups.mjs +28 -8
  85. package/tools/cdp.mjs +176 -0
  86. package/tools/chart-spec.mjs +242 -0
  87. package/tools/click-match.mjs +70 -0
  88. package/tools/code-options.mjs +174 -0
  89. package/tools/conversation.mjs +49 -0
  90. package/tools/deck-family.mjs +101 -0
  91. package/tools/deck-html.mjs +212 -15
  92. package/tools/design-system-format.mjs +40 -1
  93. package/tools/design-system-migrations.mjs +207 -0
  94. package/tools/diagram-shapes.mjs +221 -0
  95. package/tools/elevenlabs-tts.mjs +62 -53
  96. package/tools/exec.mjs +10 -2
  97. package/tools/face-clip.mjs +96 -0
  98. package/tools/face-layout.mjs +94 -0
  99. package/tools/gemini-tts.mjs +1 -1
  100. package/tools/invisible-in-print.mjs +27 -0
  101. package/tools/lipsync-auto.mjs +197 -0
  102. package/tools/lipsync-config.mjs +16 -0
  103. package/tools/lipsync-engines.mjs +22 -4
  104. package/tools/lipsync-server.mjs +8 -5
  105. package/tools/lipsync.mjs +122 -30
  106. package/tools/local-voice.mjs +1 -1
  107. package/tools/mouth-file.mjs +26 -0
  108. package/tools/mouth.mjs +320 -0
  109. package/tools/narration-manifest.mjs +100 -6
  110. package/tools/narration-synth.mjs +96 -76
  111. package/tools/recording-impact.mjs +16 -1
  112. package/tools/sentences.mjs +7 -1
  113. package/tools/site-clip.mjs +114 -0
  114. package/tools/starters.mjs +402 -0
  115. package/tools/steps.mjs +118 -0
  116. package/tools/take-check.mjs +146 -0
  117. package/tools/template-theme.mjs +3 -1
  118. package/tools/test-impact.mjs +36 -12
  119. package/tools/theme-check.mjs +196 -1
  120. package/tools/tone-cue.mjs +108 -0
  121. package/tools/tts-cache.mjs +9 -3
  122. package/tools/tts-engines.mjs +100 -11
  123. package/tools/video-cache.mjs +93 -0
  124. package/tools/video-live.mjs +349 -0
  125. package/tools/video-options.mjs +11 -0
  126. package/tools/video.mjs +825 -117
  127. package/tools/viseme-fit.mjs +27 -0
  128. package/tools/viseme-match.mjs +77 -0
  129. package/tools/vocabulary.mjs +397 -0
  130. package/tools/voice-renumber.mjs +605 -0
  131. package/tools/voiceover-server.mjs +42 -11
  132. package/tools/voiceover.mjs +48 -20
  133. package/dist/build-info.json +0 -1
@@ -26,6 +26,7 @@
26
26
  // references, and the CSS reaches nothing outside its own package.
27
27
 
28
28
  import { SEMVER_RE } from './semver.mjs';
29
+ import { migrationShapeProblems, migrationNameProblems, migrationsOf, RENAME_KINDS } from './design-system-migrations.mjs';
29
30
  import { readScales, expandThemes, paletteEntries, offPaletteTokens, offRoleColours, nearestRole, roleToken, COLOUR_TOKENS, WEIGHTS } from './brand-palette.mjs';
30
31
 
31
32
  /**
@@ -77,6 +78,20 @@ export const THEME_CONTRACT = [
77
78
  'ansi-bright-blue', 'ansi-bright-magenta', 'ansi-bright-cyan', 'ansi-bright-white',
78
79
  ].map((t) => `--${t}`);
79
80
  const CONTRACT = new Set(THEME_CONTRACT);
81
+ /**
82
+ * Tokens a theme MAY set and a design system may set too, per template, with
83
+ * no prefix and no exception: knobs the runtime reads rather than colours or
84
+ * type a theme answers for. `--code-max-size` is how large `data-fit="fill"`
85
+ * grows code (CODE_AND_MATH), which a template with a big code slot raises;
86
+ * `--code-callout-width` the gutter a line walk's callouts take beside it;
87
+ * `--figure-size` the size a figure's value is set at (DECK_ANATOMY), which a
88
+ * template built round one large number raises; `--steps-top`,
89
+ * `--steps-bottom`, `--steps-inset`, `--steps-align` and `--steps-size`
90
+ * where a run's strip sits and how large it is (DECK_ANATOMY), which a design
91
+ * system places.
92
+ */
93
+ export const OPEN_TOKENS = ['--code-max-size', '--code-callout-width', '--figure-size', '--steps-top', '--steps-bottom', '--steps-inset', '--steps-align', '--steps-size'];
94
+ const OPEN = new Set(OPEN_TOKENS);
80
95
 
81
96
  const lineAt = (text, index) => text.slice(0, index).split('\n').length;
82
97
  const ext = (path) => (/\.([A-Za-z0-9]+)$/.exec(path)?.[1] ?? '').toLowerCase();
@@ -199,6 +214,8 @@ export function readManifest(raw) {
199
214
  if (m.recommendedFonts !== undefined && (!Array.isArray(m.recommendedFonts) || !m.recommendedFonts.every((t) => typeof t === 'string'))) {
200
215
  at('manifest-field', 'recommendedFonts', 'recommendedFonts must be an array of font names — a font package (name or name@marketplace) or a font-picker stack');
201
216
  }
217
+ // what a major version renamed (SPEC DESIGN_SYSTEM_MIGRATIONS): its shape here, its names in checkPackage
218
+ for (const p of migrationShapeProblems(m)) at('migration', 'migrations', p.msg);
202
219
  return { manifest: m, problems };
203
220
  }
204
221
 
@@ -209,6 +226,8 @@ function parseThemeTokens(css) {
209
226
  return out;
210
227
  }
211
228
 
229
+ const isObjLike = (v) => v && typeof v === 'object' && !Array.isArray(v);
230
+
212
231
  /** The token prefix a manifest holds its CSS to. */
213
232
  export const tokenPrefixOf = (manifest) => manifest?.tokenPrefix ?? `--${manifest?.name ?? ''}-`;
214
233
 
@@ -258,7 +277,7 @@ function styleProblems(css, { file, prefix, files }) {
258
277
  if (!excepted.has(t.name)) {
259
278
  push(t.line, 'contract-token', `${t.name} is a theme-contract token — a design system sits beside any theme; set it only with a /* ds-exception: ${t.name} <reason> */ comment`);
260
279
  }
261
- } else if (prefix && !t.name.startsWith(prefix)) {
280
+ } else if (prefix && !t.name.startsWith(prefix) && !OPEN.has(t.name)) {
262
281
  push(t.line, 'unprefixed-token', `${t.name} does not start with this package's tokenPrefix ${prefix}`);
263
282
  }
264
283
  }
@@ -749,5 +768,25 @@ export function checkPackage(pkg) {
749
768
  : summary.brand ? `${summary.brand.scales.length} colours, ${summary.brand.palette.length} swatches${summary.brand.palette.some((e) => e.derived) ? ` (${summary.brand.palette.filter((e) => e.derived).length} derived)` : ''}` : 0;
750
769
  summary.recommendedThemes = manifest.recommendedThemes ?? [];
751
770
  summary.recommendedFonts = manifest.recommendedFonts ?? [];
771
+
772
+ // every name a migration renamed is gone from this version, every successor
773
+ // here (SPEC DESIGN_SYSTEM_MIGRATIONS) — held only once the files they are
774
+ // read from were readable, and the shape itself passed
775
+ if (manifest.migrations !== undefined && stylesRead && !mp.some((p) => p.rule === 'migration')) {
776
+ const css = files.get(stylesPath)?.text ?? '';
777
+ const templatesText = (templatesPath && files.get(templatesPath)?.text) || '';
778
+ const classes = new Set();
779
+ for (const c of css.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\{[^{}]*\}/g, '{}').matchAll(/\.(-?[A-Za-z_][A-Za-z0-9_-]*)/g)) classes.add(c[1]);
780
+ for (const a of templatesText.matchAll(/\bclass\s*=\s*(?:"([^"]*)"|'([^']*)')/gi)) for (const c of (a[1] ?? a[2]).split(/\s+/)) if (c) classes.add(c);
781
+ const roleIds = isObjLike(manifest.roles) ? Object.keys(manifest.roles) : [];
782
+ const has = {
783
+ roles: new Set(roleIds),
784
+ tokens: new Set([...summary.tokens, ...(summary.brand?.palette ?? []).map((e) => e.token), ...roleIds.map((id) => roleToken(prefix ?? '', id))]),
785
+ classes,
786
+ themes: new Set([...(summary.brand?.themes ?? []).map((t) => t.name), ...(Array.isArray(manifest.recommendedThemes) ? manifest.recommendedThemes.map((t) => String(t).split('@')[0]) : [])]),
787
+ };
788
+ for (const p of migrationNameProblems(manifest, has)) problems.push({ file: 'design-system.json', line: keyLine(pkg.manifest, 'migrations'), rule: 'migration', msg: p.msg });
789
+ }
790
+ summary.migrations = migrationsOf(manifest).map((m) => ({ version: m.version, skill: m.skill, renames: RENAME_KINDS.reduce((n, k) => n + Object.keys(m[k]).length, 0) }));
752
791
  return { ok: problems.length === 0, problems, warnings, summary };
753
792
  }
@@ -0,0 +1,207 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * A design system's declared migrations (SPEC DESIGN_SYSTEM_MIGRATIONS): what
6
+ * a major version renamed, so decklight knows a deck is behind without
7
+ * guessing, says it once, and can apply the renames itself.
8
+ *
9
+ * "migrations": {
10
+ * "6.0.0": {
11
+ * "skill": "acme-migrate",
12
+ * "roles": { "text-diagram-blue": "text-diagram-default" },
13
+ * "tokens": { "--acme-font-size-body-lg": "--acme-font-size-body-xl" },
14
+ * "classes": { "acme-tile--zest": "acme-tile--secondary-3" },
15
+ * "themes": { "acme-devrel": "acme-dark" }
16
+ * }
17
+ * }
18
+ *
19
+ * A key is the version that made the change. Every rename is a WHOLE name:
20
+ * a role id (the slide writes its token, `--<prefix>color-<role>`), a custom
21
+ * property, a class, a theme. Pure — no file is read here; the gate, `check`,
22
+ * the servers and `design-system migrate` hand in the text.
23
+ */
24
+
25
+ import { SEMVER_RE, semverCompare } from './semver.mjs';
26
+
27
+ /** The four kinds of name a migration renames, in the order they are said. */
28
+ export const RENAME_KINDS = ['roles', 'tokens', 'classes', 'themes'];
29
+ const ONE = { roles: 'role', tokens: 'token', classes: 'class', themes: 'theme' };
30
+
31
+ const ID_RE = /^[a-z][a-z0-9-]*$/;
32
+ const SHAPES = {
33
+ roles: [ID_RE, 'a role id (a lowercase word, e.g. "text-heading-main")'],
34
+ tokens: [/^--[A-Za-z0-9_-]+$/, 'a custom property, "--…"'],
35
+ classes: [/^-?[A-Za-z_][A-Za-z0-9_-]*$/, 'a class name, without the dot'],
36
+ themes: [ID_RE, 'a theme name'],
37
+ };
38
+
39
+ const isObj = (v) => v && typeof v === 'object' && !Array.isArray(v);
40
+ const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
41
+ /** A name as a whole word of CSS or HTML: not inside a longer identifier. */
42
+ const whole = (name) => new RegExp(`(?<![\\w-])${escapeRe(name)}(?![\\w-])`, 'g');
43
+
44
+ /** The major of a semver version, or null. */
45
+ export const majorOf = (v) => (SEMVER_RE.test(String(v ?? '')) ? Number(String(v).split('.')[0]) : null);
46
+
47
+ /**
48
+ * What is wrong with a manifest's `migrations`, as `[{ msg }]` — its shape
49
+ * only: every key a semver version no later than the package's own, every
50
+ * value `{ skill?, roles?, tokens?, classes?, themes? }` of whole names.
51
+ */
52
+ export function migrationShapeProblems(m) {
53
+ const out = [];
54
+ if (m.migrations === undefined) return out;
55
+ if (!isObj(m.migrations)) return [{ msg: 'migrations must be { "<version>": { "roles": { "<old>": "<new>" }, … } }, one entry per version that renamed something' }];
56
+ for (const [version, mig] of Object.entries(m.migrations)) {
57
+ if (!SEMVER_RE.test(version)) { out.push({ msg: `migrations: "${version}" is not a semver version — key each migration by the version that made it` }); continue; }
58
+ if (SEMVER_RE.test(String(m.version ?? '')) && semverCompare(version, m.version) > 0) {
59
+ out.push({ msg: `migrations: ${version} is later than this package's version ${m.version}` });
60
+ }
61
+ if (!isObj(mig)) { out.push({ msg: `migrations: ${version} must be { "skill"?, "roles"?, "tokens"?, "classes"?, "themes"? }` }); continue; }
62
+ for (const key of Object.keys(mig)) {
63
+ if (key !== 'skill' && !RENAME_KINDS.includes(key)) out.push({ msg: `migrations: ${version} has "${key}" — a migration renames roles, tokens, classes and themes, and may name a skill` });
64
+ }
65
+ if (mig.skill !== undefined && (typeof mig.skill !== 'string' || !ID_RE.test(mig.skill))) {
66
+ out.push({ msg: `migrations: ${version}.skill ${JSON.stringify(mig.skill)} — the name of a marketplace skill (decklight library add skill <name>)` });
67
+ }
68
+ for (const kind of RENAME_KINDS) {
69
+ if (mig[kind] === undefined) continue;
70
+ if (!isObj(mig[kind])) { out.push({ msg: `migrations: ${version}.${kind} must be { "<old>": "<new>" }` }); continue; }
71
+ const [re, what] = SHAPES[kind];
72
+ for (const [from, to] of Object.entries(mig[kind])) {
73
+ if (!re.test(from) || typeof to !== 'string' || !re.test(to)) out.push({ msg: `migrations: ${version}.${kind} "${from}" → ${JSON.stringify(to)} — each side is ${what}` });
74
+ else if (from === to) out.push({ msg: `migrations: ${version}.${kind} renames "${from}" to itself` });
75
+ }
76
+ }
77
+ }
78
+ return out;
79
+ }
80
+
81
+ /** The migrations in version order, each `{ version, skill, roles, tokens, classes, themes }` — only well-formed ones. */
82
+ export function migrationsOf(manifest) {
83
+ const all = isObj(manifest?.migrations) ? manifest.migrations : {};
84
+ return Object.entries(all)
85
+ .filter(([v, mig]) => SEMVER_RE.test(v) && isObj(mig))
86
+ .map(([version, mig]) => ({
87
+ version,
88
+ skill: typeof mig.skill === 'string' ? mig.skill : null,
89
+ ...Object.fromEntries(RENAME_KINDS.map((k) => [k, isObj(mig[k]) ? Object.fromEntries(Object.entries(mig[k]).filter(([, to]) => typeof to === 'string')) : {}])),
90
+ }))
91
+ .sort((a, b) => semverCompare(a.version, b.version));
92
+ }
93
+
94
+ /**
95
+ * The migrations a deck written for `from` has still to take, up to the
96
+ * package's own version: every one after `from`, or every one when the deck
97
+ * records no version.
98
+ */
99
+ export function pendingMigrations(manifest, from = null) {
100
+ return migrationsOf(manifest).filter((m) => (!from || !SEMVER_RE.test(from) || semverCompare(m.version, from) > 0)
101
+ && (!SEMVER_RE.test(String(manifest?.version ?? '')) || semverCompare(m.version, manifest.version) <= 0));
102
+ }
103
+
104
+ /**
105
+ * The renames of several migrations as one map per kind, chains followed: a
106
+ * name renamed in 5.0.0 and its successor again in 6.0.0 goes straight to the
107
+ * last one, so a deck two majors behind is moved in one pass. Each value is
108
+ * `{ to, version }` — the version of the LAST rename on the way.
109
+ */
110
+ export function composeRenames(migrations) {
111
+ const out = Object.fromEntries(RENAME_KINDS.map((k) => [k, {}]));
112
+ for (const m of migrations) {
113
+ for (const kind of RENAME_KINDS) {
114
+ const map = out[kind];
115
+ for (const [from, to] of Object.entries(m[kind])) {
116
+ for (const r of Object.values(map)) if (r.to === from) { r.to = to; r.version = m.version; }
117
+ if (!map[from]) map[from] = { to, version: m.version };
118
+ }
119
+ }
120
+ }
121
+ return out;
122
+ }
123
+
124
+ /** A role id's token, as a slide writes it — the shape `roleToken` gives (SPEC DESIGN_SYSTEM_ROLES). */
125
+ const roleTokenOf = (prefix, id) => `${prefix}color-${id}`;
126
+
127
+ /**
128
+ * Every renamed name the texts still use: `[{ kind, from, to, version, as }]`,
129
+ * `as` the spelling found (a role is found as its token). Classes are looked
130
+ * for in `class` attributes and in CSS selectors, themes as the configured
131
+ * `"theme"`; roles and tokens anywhere, as whole names.
132
+ */
133
+ export function findRenamed(texts, renames, prefix) {
134
+ const found = [];
135
+ const body = [].concat(texts).join('\n');
136
+ const classAttrs = [...body.matchAll(/\bclass\s*=\s*(?:"([^"]*)"|'([^']*)')/gi)].map((m) => ` ${m[1] ?? m[2]} `).join(' ');
137
+ for (const [from, r] of Object.entries(renames.roles ?? {})) {
138
+ const as = roleTokenOf(prefix, from);
139
+ if (whole(as).test(body)) found.push({ kind: 'roles', from, to: r.to, version: r.version, as });
140
+ }
141
+ for (const [from, r] of Object.entries(renames.tokens ?? {})) {
142
+ if (whole(from).test(body)) found.push({ kind: 'tokens', from, to: r.to, version: r.version, as: from });
143
+ }
144
+ for (const [from, r] of Object.entries(renames.classes ?? {})) {
145
+ if (whole(from).test(classAttrs) || new RegExp(`\\.${escapeRe(from)}(?![\\w-])`).test(body)) found.push({ kind: 'classes', from, to: r.to, version: r.version, as: from });
146
+ }
147
+ for (const [from, r] of Object.entries(renames.themes ?? {})) {
148
+ if (new RegExp(`"theme"\\s*:\\s*"${escapeRe(from)}"`).test(body)) found.push({ kind: 'themes', from, to: r.to, version: r.version, as: from });
149
+ }
150
+ return found;
151
+ }
152
+
153
+ /**
154
+ * The renames applied to one text: roles (as tokens) and tokens wherever they
155
+ * stand as whole names, classes in `class` attributes and in selectors, and
156
+ * — when `config` is true, for the deck — the configured `"theme"`. Nothing
157
+ * else changes, byte for byte. Returns `{ text, count }`.
158
+ */
159
+ export function applyRenames(text, renames, prefix, { config = false } = {}) {
160
+ let count = 0;
161
+ let out = String(text);
162
+ const swap = (re, to) => { out = out.replace(re, () => { count++; return to; }); };
163
+ for (const [from, r] of Object.entries(renames.roles ?? {})) swap(whole(roleTokenOf(prefix, from)), roleTokenOf(prefix, r.to));
164
+ for (const [from, r] of Object.entries(renames.tokens ?? {})) swap(whole(from), r.to);
165
+ const classes = Object.entries(renames.classes ?? {});
166
+ if (classes.length) {
167
+ out = out.replace(/(\bclass\s*=\s*)(?:"([^"]*)"|'([^']*)')/gi, (all, lead, dq, sq) => {
168
+ const q = dq !== undefined ? '"' : "'";
169
+ let v = dq ?? sq;
170
+ for (const [from, r] of classes) v = v.replace(whole(from), () => { count++; return r.to; });
171
+ return `${lead}${q}${v}${q}`;
172
+ });
173
+ for (const [from, r] of classes) swap(new RegExp(`\\.${escapeRe(from)}(?![\\w-])`, 'g'), `.${r.to}`);
174
+ }
175
+ if (config) {
176
+ for (const [from, r] of Object.entries(renames.themes ?? {})) {
177
+ out = out.replace(new RegExp(`("theme"\\s*:\\s*")${escapeRe(from)}"`, 'g'), (all, lead) => { count++; return `${lead}${r.to}"`; });
178
+ }
179
+ }
180
+ return { text: out, count };
181
+ }
182
+
183
+ /**
184
+ * The gate's half (DESIGN_SYSTEM_MIGRATIONS): a migration's names, against
185
+ * the package as it now is. Every old name must be gone — a rename that
186
+ * leaves it is not one — and every new name present, unless a later
187
+ * migration renamed it again. `has` is `{ roles, tokens, classes, themes }`,
188
+ * each a Set of what the package defines. Returns `[{ msg }]`.
189
+ */
190
+ export function migrationNameProblems(manifest, has) {
191
+ const out = [];
192
+ const migrations = migrationsOf(manifest);
193
+ migrations.forEach((m, i) => {
194
+ const later = migrations.slice(i + 1);
195
+ for (const kind of RENAME_KINDS) {
196
+ const set = has[kind];
197
+ if (!set) continue;
198
+ for (const [from, to] of Object.entries(m[kind])) {
199
+ if (set.has(from)) out.push({ msg: `migrations: ${m.version} renames ${ONE[kind]} "${from}", which this version still defines — a renamed name is gone from the new version` });
200
+ if (!set.has(to) && !later.some((n) => Object.hasOwn(n[kind], to))) {
201
+ out.push({ msg: `migrations: ${m.version} renames ${ONE[kind]} "${from}" to "${to}", which this version does not define` });
202
+ }
203
+ }
204
+ }
205
+ });
206
+ return out;
207
+ }
@@ -0,0 +1,221 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * The shapes and line styles the diagram editor writes (SPEC SVG_DIAGRAMS),
6
+ * pure, and here so the page (src/core/shapes.js) and the server
7
+ * (cli/edit.mjs) agree on every value: cli/ never imports src/, and src/ may
8
+ * import a tool.
9
+ */
10
+
11
+ /**
12
+ * Line ▸ (solid, dashed, dotted): the `stroke-dasharray` each one writes,
13
+ * inline on the stroke. A dot is a round cap on a dash of nothing, so dotted
14
+ * also writes `stroke-linecap: round`. Solid writes no dashes at all.
15
+ */
16
+ export const LINE_DASHES = Object.freeze({ dashed: '6 4', dotted: '0 4' });
17
+ export const LINES = Object.freeze(['solid', 'dashed', 'dotted']);
18
+
19
+ /** What a `stroke-dasharray` draws as: 'dotted' when its dashes are dots, 'dashed', or 'solid'. */
20
+ export function lineOf(dashes) {
21
+ const nums = String(dashes ?? '').match(/-?\d*\.?\d+/g)?.map(Number) ?? [];
22
+ if (!nums.some((n) => n > 0)) return 'solid';
23
+ return nums[0] < 1 ? 'dotted' : 'dashed';
24
+ }
25
+
26
+ /** Corners ▸ on a box: square (no `rx`), rounded, or a pill (`rx` half its short side, kept so on a resize). */
27
+ export const CORNERS = Object.freeze(['square', 'rounded', 'pill']);
28
+
29
+ /** The corners a box's attributes `{ width, height, rx, ry }` give it. */
30
+ export function cornersOf(b) {
31
+ const r = b.rx ?? b.ry ?? 0;
32
+ if (!(r > 0)) return 'square';
33
+ const short = Math.min(b.width ?? Infinity, b.height ?? Infinity);
34
+ return Number.isFinite(short) && 2 * r >= short - 0.5 ? 'pill' : 'rounded';
35
+ }
36
+
37
+ /** The `rx` (and `ry`) a box of `w` × `h` gets for `corners`: none, a modest curve, or half its short side. */
38
+ export function cornerRadius(corners, w, h) {
39
+ const short = Math.min(w, h);
40
+ if (corners === 'pill') { const r = Math.round(short * 5) / 10; return Object.is(r, -0) ? 0 : r; }
41
+ if (corners === 'rounded') return Math.max(2, Math.min(12, Math.round(short / 6)));
42
+ return null;
43
+ }
44
+
45
+ // ── more shapes than a box and an ellipse ──────────────────────────────────
46
+
47
+ /**
48
+ * The shapes Add a shape offers besides a box, an ellipse, a label and a line
49
+ * (SVG_DIAGRAMS). Each is ONE element marked `data-shape` with its kind, so a
50
+ * resize writes its geometry again for the new box and a wire stops at its
51
+ * outline: a `<polygon>` (diamond, hexagon) or a `<path>` in absolute
52
+ * M, L, C and Z (cylinder, document, note, cloud; the server's path data
53
+ * takes no arcs). Every number of the geometry lies inside its box and some
54
+ * number reaches each edge, so the box is read back from the numbers alone.
55
+ */
56
+ export const SHAPES = Object.freeze({
57
+ diamond: 'polygon', hexagon: 'polygon',
58
+ cylinder: 'path', document: 'path', note: 'path', cloud: 'path',
59
+ });
60
+ /** What a new one says until it is typed into. */
61
+ export const SHAPE_LABELS = Object.freeze({
62
+ diamond: 'Decision', hexagon: 'Step', cylinder: 'Store', document: 'Document', note: 'Note', cloud: 'Cloud',
63
+ });
64
+
65
+ /** A number as the file gets it: one decimal at most, never -0 (the server's formatCoord). */
66
+ const fmt = (n) => { const r = Math.round(n * 10) / 10; return String(Object.is(r, -0) ? 0 : r); };
67
+ /** A quarter ellipse's control-point factor. */
68
+ const K = 0.5523;
69
+
70
+ /**
71
+ * The geometry of a shape of `kind` filling box `{ x, y, w, h }`:
72
+ * `{ tag, attr, value }`, `points` on a polygon and `d` on a path, in the
73
+ * spelling the server writes back (`x,y x,y`; `M 1 2 L 3 4`), so the file
74
+ * and the page agree byte for byte. Null for a kind it does not know.
75
+ */
76
+ export function shapeGeometry(kind, box) {
77
+ const tag = SHAPES[kind];
78
+ if (!tag) return null;
79
+ const x = Number(fmt(box.x)); const y = Number(fmt(box.y));
80
+ const w = Math.max(0, Number(fmt(box.w))); const h = Math.max(0, Number(fmt(box.h)));
81
+ const r = x + w; const b = y + h; const cx = x + w / 2; const cy = y + h / 2;
82
+ const P = (pts) => pts.map(([px, py]) => `${fmt(px)},${fmt(py)}`).join(' ');
83
+ const D = (cmds) => cmds.map(([c, ...n]) => [c, ...n.map(fmt)].join(' ')).join(' ');
84
+ switch (kind) {
85
+ case 'diamond': return { tag, attr: 'points', value: P([[cx, y], [r, cy], [cx, b], [x, cy]]) };
86
+ case 'hexagon': {
87
+ const i = Math.min(w * 0.25, h * 0.5);
88
+ return { tag, attr: 'points', value: P([[x + i, y], [r - i, y], [r, cy], [r - i, b], [x + i, b], [x, cy]]) };
89
+ }
90
+ case 'cylinder': {
91
+ // the body and the back of the top rim, then the front of the rim on its own
92
+ const e = Math.min(h * 0.15, w * 0.25); const hx = w / 2;
93
+ const top = (yy) => [['C', x, yy - e * K, cx - hx * K, yy - e, cx, yy - e], ['C', cx + hx * K, yy - e, r, yy - e * K, r, yy]];
94
+ return { tag, attr: 'd', value: D([
95
+ ['M', x, y + e], ...top(y + e), ['L', r, b - e],
96
+ ['C', r, b - e + e * K, cx + hx * K, b, cx, b], ['C', cx - hx * K, b, x, b - e + e * K, x, b - e], ['Z'],
97
+ ['M', x, y + e], ['C', x, y + e + e * K, cx - hx * K, y + 2 * e, cx, y + 2 * e], ['C', cx + hx * K, y + 2 * e, r, y + e + e * K, r, y + e],
98
+ ]) };
99
+ }
100
+ case 'document': {
101
+ // a page whose foot is a wave
102
+ const d = h * 0.12;
103
+ return { tag, attr: 'd', value: D([['M', x, y], ['L', r, y], ['L', r, b - d], ['C', x + w * 0.7, b - 3 * d, x + w * 0.3, b, x, b - d], ['Z']]) };
104
+ }
105
+ case 'note': {
106
+ // a sheet with its top right corner folded down, and the fold
107
+ const f = Math.min(w, h) * 0.22;
108
+ return { tag, attr: 'd', value: D([['M', x, y], ['L', r - f, y], ['L', r, y + f], ['L', r, b], ['L', x, b], ['Z'], ['M', r - f, y], ['L', r - f, y + f], ['L', r, y + f]]) };
109
+ }
110
+ case 'cloud': {
111
+ // eight bumps between points on an inner ellipse, each bulging out to the box
112
+ const n = 8; const ix = w * 0.36; const iy = h * 0.34;
113
+ const at = (k) => { const a = (k / n) * 2 * Math.PI - Math.PI / 2; return [cx + ix * Math.cos(a), cy + iy * Math.sin(a)]; };
114
+ const clampX = (v) => Math.min(r, Math.max(x, v)); const clampY = (v) => Math.min(b, Math.max(y, v));
115
+ const out = (p, a) => [clampX(cx + (p[0] - cx) * a), clampY(cy + (p[1] - cy) * a)];
116
+ const cmds = [['M', ...at(0)]];
117
+ for (let k = 0; k < n; k++) {
118
+ const p = at(k); const q = at(k + 1);
119
+ cmds.push(['C', ...out(p, 1.9), ...out(q, 1.9), ...q]);
120
+ }
121
+ cmds.push(['Z']);
122
+ return { tag, attr: 'd', value: D(cmds) };
123
+ }
124
+ default: return null;
125
+ }
126
+ }
127
+
128
+ /** The numbers of a polygon's `points` or a path's `d`, as `[x, y]` pairs (absolute commands only: H and V read with the pen). */
129
+ function pairsOf(attr, value) {
130
+ const src = String(value ?? '');
131
+ if (attr === 'points') {
132
+ const n = src.trim().split(/[\s,]+/).filter(Boolean).map(Number);
133
+ const out = [];
134
+ for (let i = 0; i + 1 < n.length; i += 2) out.push([n[i], n[i + 1]]);
135
+ return out;
136
+ }
137
+ return flatten(src, { curves: false }).flat();
138
+ }
139
+
140
+ /**
141
+ * The box a shape's geometry fills, `{ x, y, w, h }`, read from its numbers
142
+ * (shapeGeometry keeps every one inside and reaches each edge): what a resize
143
+ * starts from. Null when there are none.
144
+ */
145
+ export function shapeBox(attr, value) {
146
+ const pts = pairsOf(attr, value).filter(([a, c]) => Number.isFinite(a) && Number.isFinite(c));
147
+ if (!pts.length) return null;
148
+ const xs = pts.map((p) => p[0]); const ys = pts.map((p) => p[1]);
149
+ const x = Math.min(...xs); const y = Math.min(...ys);
150
+ return { x, y, w: Math.max(...xs) - x, h: Math.max(...ys) - y };
151
+ }
152
+
153
+ /**
154
+ * Path data in absolute M, L, H, V, C, Q and Z as its subpaths, each a list
155
+ * of `[x, y]`: a curve sampled into `steps` points when `curves`, else its
156
+ * control points and its end as they are (the numbers, for shapeBox).
157
+ */
158
+ export function flatten(d, { curves = true, steps = 10 } = {}) {
159
+ const tokens = String(d ?? '').match(/[MLHVCQZ]|-?\d*\.?\d+(?:e[-+]?\d+)?/gi) ?? [];
160
+ const subs = []; let cur = null; let pen = [0, 0]; let start = [0, 0]; let cmd = null; let args = [];
161
+ const need = { M: 2, L: 2, H: 1, V: 1, C: 6, Q: 4, Z: 0 };
162
+ const run = () => {
163
+ const c = cmd?.toUpperCase();
164
+ if (!c) return;
165
+ if (c === 'Z') { if (cur) cur.push([...start]); pen = [...start]; return; }
166
+ for (let i = 0; i + need[c] <= args.length && need[c]; i += need[c]) {
167
+ const a = args.slice(i, i + need[c]);
168
+ if (c === 'M' && i === 0) { cur = [[a[0], a[1]]]; subs.push(cur); pen = [a[0], a[1]]; start = [...pen]; continue; }
169
+ cur ??= (subs.push([[...pen]]), subs.at(-1));
170
+ if (c === 'M' || c === 'L') pen = [a[0], a[1]];
171
+ else if (c === 'H') pen = [a[0], pen[1]];
172
+ else if (c === 'V') pen = [pen[0], a[0]];
173
+ if (c === 'M' || c === 'L' || c === 'H' || c === 'V') { cur.push([...pen]); continue; }
174
+ const p0 = pen;
175
+ const ctl = c === 'C' ? [[a[0], a[1]], [a[2], a[3]]] : [[a[0], a[1]]];
176
+ const end = c === 'C' ? [a[4], a[5]] : [a[2], a[3]];
177
+ if (!curves) cur.push(...ctl, end);
178
+ else {
179
+ for (let s = 1; s <= steps; s++) {
180
+ const t = s / steps; const u = 1 - t;
181
+ cur.push(c === 'C'
182
+ ? [u ** 3 * p0[0] + 3 * u * u * t * ctl[0][0] + 3 * u * t * t * ctl[1][0] + t ** 3 * end[0], u ** 3 * p0[1] + 3 * u * u * t * ctl[0][1] + 3 * u * t * t * ctl[1][1] + t ** 3 * end[1]]
183
+ : [u * u * p0[0] + 2 * u * t * ctl[0][0] + t * t * end[0], u * u * p0[1] + 2 * u * t * ctl[0][1] + t * t * end[1]]);
184
+ }
185
+ }
186
+ pen = end;
187
+ }
188
+ };
189
+ for (const tk of tokens) {
190
+ if (/^[MLHVCQZ]$/i.test(tk)) { run(); cmd = tk; args = []; } else args.push(Number(tk));
191
+ }
192
+ run();
193
+ return subs;
194
+ }
195
+
196
+ /** A shape's outline as one closed list of points: its polygon, or the first subpath of its path, curves sampled. */
197
+ export function outlineOf(attr, value) {
198
+ if (attr === 'points') return pairsOf('points', value);
199
+ return flatten(value)[0] ?? [];
200
+ }
201
+
202
+ /**
203
+ * Where a ray from `c` toward `p` first leaves `outline` (points, closed):
204
+ * what a wire stops at on a shape that is not a box. Null when the ray
205
+ * meets no edge (c outside it, or an outline of no size).
206
+ */
207
+ export function outlineToward(outline, c, p) {
208
+ const dx = p.x - c.x; const dy = p.y - c.y;
209
+ if ((!dx && !dy) || outline.length < 2) return null;
210
+ let best = Infinity;
211
+ for (let i = 0; i < outline.length; i++) {
212
+ const [ax, ay] = outline[i]; const [bx, by] = outline[(i + 1) % outline.length];
213
+ const ex = bx - ax; const ey = by - ay;
214
+ const den = dx * ey - dy * ex;
215
+ if (Math.abs(den) < 1e-12) continue;
216
+ const t = ((ax - c.x) * ey - (ay - c.y) * ex) / den;
217
+ const s = ((ax - c.x) * dy - (ay - c.y) * dx) / den;
218
+ if (t > 1e-9 && s >= -1e-9 && s <= 1 + 1e-9 && t < best) best = t;
219
+ }
220
+ return Number.isFinite(best) ? { x: c.x + dx * best, y: c.y + dy * best } : null;
221
+ }