@erclx/canon 5.53.0 → 5.54.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 (94) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +10 -9
  3. package/claude/.claude-plugin/plugin.json +1 -1
  4. package/claude/skills/canon-cli/SKILL.md +5 -5
  5. package/claude/skills/design-identity/REQUIREMENT.md +2 -2
  6. package/claude/skills/design-identity/SKILL.md +6 -6
  7. package/claude/skills/design-record/REQUIREMENT.md +2 -2
  8. package/claude/skills/design-record/SKILL.md +4 -4
  9. package/claude/skills/design-record/references/folder.md +1 -1
  10. package/claude/skills/design-taste/REQUIREMENT.md +1 -1
  11. package/claude/skills/draw-figure/REQUIREMENT.md +1 -1
  12. package/claude/skills/draw-figure/SKILL.md +1 -1
  13. package/claude/skills/pick-by-eye/REQUIREMENT.md +4 -4
  14. package/claude/skills/pick-by-eye/SKILL.md +34 -41
  15. package/claude/skills/pick-by-eye/references/board.md +42 -0
  16. package/claude/skills/pick-by-eye/references/live-arms.md +3 -3
  17. package/claude/skills/plan-groundwork/SKILL.md +1 -1
  18. package/claude/skills/teach-craft/REQUIREMENT.md +1 -1
  19. package/claude/skills/teach-craft/SKILL.md +32 -1
  20. package/claude/skills/teach-craft/references/adopted.md +113 -0
  21. package/claude/skills/teach-craft/references/lesson-craft.md +10 -2
  22. package/claude/skills/teach-craft/references/pedagogy.md +29 -2
  23. package/docs/agents/install-and-sync.md +0 -8
  24. package/docs/target/migrations.md +8 -3
  25. package/docs/target/projects.md +1 -1
  26. package/docs/workflow/skill-map.md +0 -1
  27. package/docs/workflow/visual-design-workflow.md +1 -4
  28. package/governance/detect.toml +1 -6
  29. package/governance/renames.toml +0 -1
  30. package/package.json +2 -5
  31. package/src/claude/cases/misc.ts +0 -5
  32. package/src/claude/skills-audit.ts +1 -0
  33. package/src/cli/help.ts +0 -3
  34. package/src/cli.ts +0 -2
  35. package/src/commands/design.ts +16 -315
  36. package/src/commands/sync.ts +4 -5
  37. package/src/design/regen.ts +5 -32
  38. package/src/design/render.ts +1 -1
  39. package/src/design/tokens.ts +3 -2
  40. package/src/gate/stages.ts +4 -10
  41. package/src/gov/audit.ts +1 -6
  42. package/src/markdown/scope.ts +2 -4
  43. package/src/shipped/references.ts +1 -2
  44. package/src/sync/check.ts +4 -29
  45. package/src/sync/stamp.ts +6 -6
  46. package/src/sync/target.ts +1 -4
  47. package/tooling/claude/reference.md +1 -1
  48. package/tooling/claude/seeds/canon/DESIGN.md +1 -1
  49. package/claude/skills/canvas-board/REQUIREMENT.md +0 -35
  50. package/claude/skills/canvas-board/SKILL.md +0 -143
  51. package/claude/skills/canvas-board/references/canvas.md +0 -170
  52. package/governance/rules/ui/canvas.md +0 -13
  53. package/src/canvas/address.ts +0 -227
  54. package/src/canvas/arrange.ts +0 -66
  55. package/src/canvas/capture.ts +0 -391
  56. package/src/canvas/client/app.tsx +0 -188
  57. package/src/canvas/client/inspector/align-grid.tsx +0 -162
  58. package/src/canvas/client/inspector/color-field.tsx +0 -398
  59. package/src/canvas/client/inspector/color-inputs.tsx +0 -139
  60. package/src/canvas/client/inspector/color-picker.tsx +0 -668
  61. package/src/canvas/client/inspector/color-space.ts +0 -240
  62. package/src/canvas/client/inspector/field.tsx +0 -263
  63. package/src/canvas/client/inspector/fields.css +0 -763
  64. package/src/canvas/client/inspector/section.tsx +0 -27
  65. package/src/canvas/client/inspector/size-field.tsx +0 -69
  66. package/src/canvas/client/inspector/token-select.tsx +0 -109
  67. package/src/canvas/client/inspector/values.ts +0 -297
  68. package/src/canvas/client/inspector.tsx +0 -692
  69. package/src/canvas/client/keys.ts +0 -71
  70. package/src/canvas/client/layers.tsx +0 -118
  71. package/src/canvas/client/main.tsx +0 -71
  72. package/src/canvas/client/pages-panel.tsx +0 -212
  73. package/src/canvas/client/panel-handle.tsx +0 -90
  74. package/src/canvas/client/selection.tsx +0 -199
  75. package/src/canvas/client/shell.css +0 -762
  76. package/src/canvas/client/state.ts +0 -792
  77. package/src/canvas/client/surface.tsx +0 -803
  78. package/src/canvas/client/theme-panel.tsx +0 -55
  79. package/src/canvas/client/tools.tsx +0 -153
  80. package/src/canvas/content.ts +0 -781
  81. package/src/canvas/edit.ts +0 -575
  82. package/src/canvas/editing.ts +0 -203
  83. package/src/canvas/fit.ts +0 -238
  84. package/src/canvas/global.d.ts +0 -15
  85. package/src/canvas/history.ts +0 -116
  86. package/src/canvas/index.html +0 -20
  87. package/src/canvas/server.ts +0 -766
  88. package/src/canvas/tokens.ts +0 -221
  89. package/src/commands/canvas.ts +0 -1097
  90. package/src/design/adapter.ts +0 -59
  91. package/src/design/base.css +0 -203
  92. package/src/design/brand-favicon.ts +0 -18
  93. package/src/design/neutral.ts +0 -127
  94. package/src/design/project-fonts.ts +0 -392
@@ -1,392 +0,0 @@
1
- import {
2
- appendFileSync,
3
- copyFileSync,
4
- existsSync,
5
- mkdirSync,
6
- readdirSync,
7
- readFileSync,
8
- realpathSync,
9
- statSync,
10
- } from 'node:fs'
11
- import {
12
- basename,
13
- dirname,
14
- extname,
15
- isAbsolute,
16
- join,
17
- relative,
18
- resolve,
19
- } from 'node:path'
20
- import { primaryFontFamily } from '@/capture/sources'
21
- import { DESIGN_INSTALL_DIR, DESIGN_PROJECT_SUBDIR } from '@/design/adapter'
22
-
23
- /**
24
- * A project's own faces, declared as plain `@font-face` rules in its override
25
- * sheets and stored beside them under `project/`, which sync treats as
26
- * project-authored by location and never writes. CSS is the declaration
27
- * format because every consumer already reads it, and reading descriptors
28
- * out of the font's own tables cannot open WOFF2 without a Brotli parser.
29
- *
30
- * A rule's `url()` is read from inside `project/` only, after `realpath`, so
31
- * an override cannot carry a file from elsewhere on the machine into a frame.
32
- * A hand-edited sheet reaches this module as often as `addProjectFace` does,
33
- * so the check sits on the read rather than on the write.
34
- */
35
-
36
- export const PROJECT_FONTS_DIR = 'fonts'
37
- export const PROJECT_FONTS_SHEET = 'fonts.css'
38
-
39
- export type FaceProblem = 'missing' | 'outside-folder'
40
-
41
- export interface ProjectFace {
42
- readonly family: string
43
- /** The `font-weight` descriptor verbatim, `400` where the rule omits it. */
44
- readonly weight: string
45
- readonly style: string
46
- /** Relative to the root. */
47
- readonly sheet: string
48
- /** The first local `url()` as the rule writes it. */
49
- readonly file: string
50
- readonly present: boolean
51
- readonly problem?: FaceProblem
52
- }
53
-
54
- export interface DroppedFace {
55
- readonly sheet: string
56
- readonly file: string
57
- readonly reason: FaceProblem
58
- }
59
-
60
- export interface InlinedSheet {
61
- readonly css: string
62
- readonly dropped: readonly DroppedFace[]
63
- /** The families of the rules that survived, in sheet order. */
64
- readonly declared: readonly string[]
65
- }
66
-
67
- const FORMATS = {
68
- '.woff2': { mime: 'font/woff2', format: 'woff2', magic: ['wOF2'] },
69
- '.woff': { mime: 'font/woff', format: 'woff', magic: ['wOFF'] },
70
- '.ttf': {
71
- mime: 'font/ttf',
72
- format: 'truetype',
73
- magic: ['\u0000\u0001\u0000\u0000', 'true'],
74
- },
75
- '.otf': { mime: 'font/otf', format: 'opentype', magic: ['OTTO'] },
76
- } as const
77
-
78
- type FontExtension = keyof typeof FORMATS
79
-
80
- function isFontExtension(ext: string): ext is FontExtension {
81
- return Object.hasOwn(FORMATS, ext)
82
- }
83
-
84
- const FACE_RULE = /@font-face\s*\{[^}]*\}/g
85
- const URL = /url\(\s*(['"]?)([^'")]+)\1\s*\)/g
86
- const SCHEME = /^[a-z][a-z0-9+.-]*:/i
87
- const DECLARATION = /([A-Za-z-]+)\s*:\s*([^;}]*)/g
88
-
89
- /** Comments blanked to equal length, so an index into the result fits the source. */
90
- function masked(css: string): string {
91
- return css.replace(/\/\*[\s\S]*?\*\//g, (comment) =>
92
- ' '.repeat(comment.length),
93
- )
94
- }
95
-
96
- function descriptor(rule: string, name: string): string | undefined {
97
- const match = rule.match(new RegExp(`(?:^|[;{\\s])${name}\\s*:\\s*([^;}]*)`))
98
- return match?.[1]?.trim()
99
- }
100
-
101
- function familyOf(rule: string): string {
102
- return primaryFontFamily(descriptor(rule, 'font-family') ?? '')
103
- }
104
-
105
- /**
106
- * Every family a declaration value lists, quoted or not, across the sheet
107
- * outside its `@font-face` rules, which declare a face rather than use one.
108
- * Reads every property rather than only `font-family`, since a token such as
109
- * `--figure-hand` names its stack under a name that ends in neither.
110
- */
111
- export function namedFamilies(css: string): Set<string> {
112
- const uses = masked(css).replace(FACE_RULE, '')
113
- const named = new Set<string>()
114
- for (const [, , value] of uses.matchAll(DECLARATION)) {
115
- for (const item of (value ?? '').split(',')) {
116
- const family = primaryFontFamily(item)
117
- if (family) named.add(family)
118
- }
119
- }
120
- return named
121
- }
122
-
123
- function projectDir(root: string): string {
124
- return join(root, DESIGN_INSTALL_DIR, DESIGN_PROJECT_SUBDIR)
125
- }
126
-
127
- function isWithin(folder: string, path: string): boolean {
128
- const inside = relative(folder, path)
129
- return inside !== '' && !inside.startsWith('..') && !isAbsolute(inside)
130
- }
131
-
132
- type Located =
133
- | { readonly ok: true; readonly path: string }
134
- | { readonly ok: false; readonly reason: FaceProblem }
135
-
136
- /** A URL path as the name on disk, or undefined for a malformed escape. */
137
- function decoded(url: string): string | undefined {
138
- try {
139
- return decodeURIComponent(url.replace(/[?#].*$/, ''))
140
- } catch {
141
- return undefined
142
- }
143
- }
144
-
145
- /**
146
- * Confined lexically before any read, then again after resolving links. The
147
- * check runs on the decoded path, so an escaped `..` cannot pass it.
148
- */
149
- function locate(root: string, sheet: string, url: string): Located {
150
- const folder = projectDir(root)
151
- const clean = decoded(url)
152
- if (clean === undefined) return { ok: false, reason: 'missing' }
153
- if (isAbsolute(clean)) return { ok: false, reason: 'outside-folder' }
154
- const path = resolve(join(root, dirname(sheet)), clean)
155
- if (!isWithin(folder, path)) return { ok: false, reason: 'outside-folder' }
156
- if (!existsSync(path) || !statSync(path).isFile()) {
157
- return { ok: false, reason: 'missing' }
158
- }
159
- if (!isWithin(realpathSync(folder), realpathSync(path))) {
160
- return { ok: false, reason: 'outside-folder' }
161
- }
162
- return { ok: true, path }
163
- }
164
-
165
- function localUrls(rule: string): string[] {
166
- return [...rule.matchAll(URL)]
167
- .map((match) => match[2]?.trim() ?? '')
168
- .filter((url) => url !== '' && !SCHEME.test(url))
169
- }
170
-
171
- function mimeOf(path: string): string {
172
- const ext = extname(path).toLowerCase()
173
- return isFontExtension(ext) ? FORMATS[ext].mime : 'application/octet-stream'
174
- }
175
-
176
- /**
177
- * Rewrites each local `url()` in a sheet's `@font-face` rules to a `data:`
178
- * URI, so a frame carries the face rather than a path the frame's origin
179
- * cannot serve. A rule naming a file that is missing or leads out of
180
- * `project/` is dropped whole and reported, and the sheet otherwise renders.
181
- * A `data:` or remote URL is left as written.
182
- */
183
- export function inlineProjectFaces(
184
- root: string,
185
- sheet: string,
186
- css: string,
187
- ): InlinedSheet {
188
- const dropped: DroppedFace[] = []
189
- const declared: string[] = []
190
- let out = ''
191
- let cursor = 0
192
- for (const match of masked(css).matchAll(FACE_RULE)) {
193
- const start = match.index
194
- const end = start + match[0].length
195
- const rule = css.slice(start, end)
196
- out += css.slice(cursor, start)
197
- cursor = end
198
-
199
- const urls = localUrls(match[0])
200
- const located = urls.map((url) => ({ url, at: locate(root, sheet, url) }))
201
- const failed = located.find(({ at }) => !at.ok)
202
- if (failed && !failed.at.ok) {
203
- dropped.push({ sheet, file: failed.url, reason: failed.at.reason })
204
- continue
205
- }
206
- let inlined = rule
207
- for (const { url, at } of located) {
208
- if (!at.ok) continue
209
- const data = `data:${mimeOf(at.path)};base64,${readFileSync(at.path).toString('base64')}`
210
- inlined = inlined.replace(url, data)
211
- }
212
- out += inlined
213
- declared.push(familyOf(match[0]))
214
- }
215
- return { css: out + css.slice(cursor), dropped, declared }
216
- }
217
-
218
- /** The project's override sheets, root-relative, in the order a frame cascades them. */
219
- export function projectSheets(root: string): string[] {
220
- const folder = projectDir(root)
221
- if (!existsSync(folder)) return []
222
- return readdirSync(folder)
223
- .filter((name) => name.endsWith('.css'))
224
- .sort((a, b) => a.localeCompare(b))
225
- .map((name) => join(DESIGN_INSTALL_DIR, DESIGN_PROJECT_SUBDIR, name))
226
- }
227
-
228
- /** Every face the override sheets declare, without reading a font file. */
229
- export function listProjectFaces(root: string): ProjectFace[] {
230
- return projectSheets(root).flatMap((sheet) => {
231
- const css = masked(readFileSync(join(root, sheet), 'utf8'))
232
- return [...css.matchAll(FACE_RULE)].map((match): ProjectFace => {
233
- const rule = match[0]
234
- const local = localUrls(rule)[0]
235
- const external = [...rule.matchAll(URL)][0]?.[2]?.trim() ?? ''
236
- /*
237
- * A rule carrying its face inline or remotely has no file to read, and
238
- * the frame keeps it as written, so it lists as present. A `data:` URI
239
- * is shortened to its scheme rather than echoing the whole face.
240
- */
241
- const file = local ?? (external.startsWith('data:') ? 'data:' : external)
242
- const at: Located = local
243
- ? locate(root, sheet, local)
244
- : external
245
- ? { ok: true, path: external }
246
- : { ok: false, reason: 'missing' }
247
- return {
248
- family: familyOf(rule),
249
- weight: descriptor(rule, 'font-weight') ?? '400',
250
- style: descriptor(rule, 'font-style') ?? 'normal',
251
- sheet,
252
- file,
253
- present: at.ok,
254
- ...(!at.ok && { problem: at.reason }),
255
- }
256
- })
257
- })
258
- }
259
-
260
- export interface FaceSpec {
261
- readonly family: string
262
- readonly weight?: string
263
- readonly style?: string
264
- }
265
-
266
- export type AddOutcome =
267
- | {
268
- readonly ok: true
269
- readonly family: string
270
- readonly weight: string
271
- readonly style: string
272
- /** Relative to the sheet's folder, as the rule writes it. */
273
- readonly file: string
274
- readonly sheet: string
275
- }
276
- | {
277
- readonly ok: false
278
- readonly reason: 'invalid-font' | 'invalid-face' | 'exists'
279
- readonly detail: string
280
- }
281
-
282
- /** A name CSS takes inside single quotes with no escaping. */
283
- const SAFE_FAMILY = /^[A-Za-z0-9][A-Za-z0-9 _-]*$/
284
- /** A file name a single-quoted `url()` takes with no escaping. */
285
- const SAFE_FILE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/
286
- const WEIGHT = /^\d{1,4}( \d{1,4})?$/
287
-
288
- function weightInRange(weight: string): boolean {
289
- return weight.split(' ').every((n) => Number(n) >= 1 && Number(n) <= 1000)
290
- }
291
-
292
- /**
293
- * Copies a face into `project/fonts/` and appends one rule for it to
294
- * `project/fonts.css`. Refuses before writing anything when the extension is
295
- * not a font, the bytes disagree with it, a descriptor would need escaping,
296
- * or the folder already holds a file of that name.
297
- */
298
- export function addProjectFace(
299
- root: string,
300
- source: string,
301
- spec: FaceSpec,
302
- ): AddOutcome {
303
- const name = basename(source)
304
- const ext = extname(name).toLowerCase()
305
- if (!isFontExtension(ext)) {
306
- return {
307
- ok: false,
308
- reason: 'invalid-font',
309
- detail: `${name} is not a font. Use woff2, woff, ttf, or otf`,
310
- }
311
- }
312
- if (!SAFE_FILE.test(name)) {
313
- return {
314
- ok: false,
315
- reason: 'invalid-font',
316
- detail: `${name} must be letters, digits, dots, dashes, or underscores to sit in a url(). Rename it`,
317
- }
318
- }
319
- if (!existsSync(source) || !statSync(source).isFile()) {
320
- return { ok: false, reason: 'invalid-font', detail: `${source} not found` }
321
- }
322
- const head = readFileSync(source).subarray(0, 4).toString('binary')
323
- if (!FORMATS[ext].magic.some((magic) => head === magic)) {
324
- return {
325
- ok: false,
326
- reason: 'invalid-font',
327
- detail: `${name} does not read as ${ext.slice(1)} from its first bytes`,
328
- }
329
- }
330
-
331
- const weight = spec.weight ?? '400'
332
- const style = spec.style ?? 'normal'
333
- if (!SAFE_FAMILY.test(spec.family)) {
334
- return {
335
- ok: false,
336
- reason: 'invalid-face',
337
- detail: `family ${spec.family} must be letters, digits, spaces, dashes, or underscores`,
338
- }
339
- }
340
- if (!WEIGHT.test(weight) || !weightInRange(weight)) {
341
- return {
342
- ok: false,
343
- reason: 'invalid-face',
344
- detail: `weight ${weight} must be one number or a range of two, from 1 to 1000`,
345
- }
346
- }
347
- if (style !== 'normal' && style !== 'italic') {
348
- return {
349
- ok: false,
350
- reason: 'invalid-face',
351
- detail: `style ${style} must be normal or italic`,
352
- }
353
- }
354
-
355
- const folder = join(projectDir(root), PROJECT_FONTS_DIR)
356
- const dest = join(folder, name)
357
- const file = `${PROJECT_FONTS_DIR}/${name}`
358
- if (existsSync(dest)) {
359
- return {
360
- ok: false,
361
- reason: 'exists',
362
- detail: `${relative(root, dest)} already exists. Remove it or rename the source`,
363
- }
364
- }
365
-
366
- mkdirSync(folder, { recursive: true })
367
- copyFileSync(source, dest)
368
- const sheetPath = join(projectDir(root), PROJECT_FONTS_SHEET)
369
- const lead =
370
- existsSync(sheetPath) && readFileSync(sheetPath, 'utf8').trim() !== ''
371
- ? '\n'
372
- : ''
373
- appendFileSync(
374
- sheetPath,
375
- `${lead}@font-face {
376
- font-family: '${spec.family}';
377
- font-weight: ${weight};
378
- font-style: ${style};
379
- font-display: swap;
380
- src: url('${file}') format('${FORMATS[ext].format}');
381
- }
382
- `,
383
- )
384
- return {
385
- ok: true,
386
- family: spec.family,
387
- weight,
388
- style,
389
- file,
390
- sheet: relative(root, sheetPath),
391
- }
392
- }