@erclx/canon 5.15.0 → 5.17.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 (55) hide show
  1. package/claude/.claude-plugin/plugin.json +1 -1
  2. package/claude/skills/draft-figure/REQUIREMENT.md +8 -2
  3. package/claude/skills/draft-figure/SKILL.md +19 -4
  4. package/claude/skills/draft-wiki/SKILL.md +1 -1
  5. package/claude/skills/draft-wireframes/SKILL.md +1 -1
  6. package/claude/skills/plan-groundwork/SKILL.md +1 -1
  7. package/claude/skills/search-craft/REQUIREMENT.md +57 -0
  8. package/claude/skills/search-craft/SKILL.md +83 -0
  9. package/claude/skills/teach-workspace/SKILL.md +1 -1
  10. package/claude/skills/teach-workspace/references/lesson-craft.md +1 -1
  11. package/docs/agents/canvas.md +36 -0
  12. package/docs/agents/commands.md +3 -3
  13. package/docs/agents/demo.md +3 -1
  14. package/docs/agents/index.md +1 -0
  15. package/docs/agents/teach.md +2 -2
  16. package/docs/workflow/skill-map.md +1 -0
  17. package/docs/workflow/visual-design-workflow.md +8 -15
  18. package/governance/rules/claude/566-output.md +3 -5
  19. package/governance/rules/claude/575-hooks.md +1 -1
  20. package/package.json +1 -1
  21. package/scripts/lib/sandbox-git.sh +2 -2
  22. package/src/canvas/address.ts +184 -0
  23. package/src/canvas/capture.ts +172 -0
  24. package/src/canvas/client/app.tsx +2 -0
  25. package/src/canvas/client/inspector.tsx +121 -0
  26. package/src/canvas/client/layers.tsx +118 -0
  27. package/src/canvas/client/pages-panel.tsx +47 -13
  28. package/src/canvas/client/shell.css +131 -1
  29. package/src/canvas/client/state.ts +186 -0
  30. package/src/canvas/client/surface.tsx +272 -20
  31. package/src/canvas/content.ts +307 -16
  32. package/src/canvas/server.ts +182 -13
  33. package/src/claude/cases/misc.ts +5 -0
  34. package/src/commands/canvas.ts +200 -3
  35. package/src/commands/demo.ts +2 -0
  36. package/src/commands/migrate.ts +1 -1
  37. package/src/commands/teach.ts +3 -1
  38. package/src/demo/drive.ts +36 -7
  39. package/src/demo/timeline.ts +64 -0
  40. package/src/migrate/rename.ts +5 -4
  41. package/src/teach/browser/compile.ts +44 -0
  42. package/src/teach/browser/dismiss.ts +76 -0
  43. package/src/teach/browser/focus-line.ts +19 -0
  44. package/src/teach/browser/glossary-filter.ts +44 -0
  45. package/src/teach/browser/head.ts +30 -0
  46. package/src/teach/browser/quiz.ts +19 -0
  47. package/src/teach/browser/sidebar.ts +233 -0
  48. package/src/teach/browser/theme.ts +18 -0
  49. package/src/teach/nav.ts +19 -374
  50. package/src/teach/workspace.ts +61 -6
  51. package/standards/figures.md +1 -0
  52. package/tooling/claude/reference.md +1 -1
  53. package/tooling/claude/seeds/.claude/hooks/path-form.sh +2 -4
  54. package/tooling/claude/seeds/.claude/hooks/search-reminder.sh +35 -0
  55. package/tooling/claude/seeds/.claude/settings.json +9 -0
@@ -119,7 +119,8 @@ code {
119
119
  background: var(--color-border);
120
120
  }
121
121
 
122
- .row[aria-current='page'] {
122
+ .row[aria-current='page'],
123
+ .row[aria-current='true'] {
123
124
  background: var(--color-surface);
124
125
  color: var(--color-text);
125
126
  box-shadow: inset 2px 0 0 var(--color-accent);
@@ -275,6 +276,73 @@ code {
275
276
  border-radius: 2px;
276
277
  }
277
278
 
279
+ /* The frame's handle, since a press inside the frame picks an element. */
280
+ .frame-label {
281
+ cursor: move;
282
+ touch-action: none;
283
+ }
284
+
285
+ .frame[data-dragging='true'] .frame-label {
286
+ cursor: grabbing;
287
+ }
288
+
289
+ .frame-body {
290
+ position: relative;
291
+ }
292
+
293
+ /* Inset by the iframe border, so a box lines up with the element it marks. */
294
+ .element-outline {
295
+ position: absolute;
296
+ translate: 1px 1px;
297
+ pointer-events: none;
298
+ }
299
+
300
+ .element-outline[data-outline='hover'] {
301
+ outline: calc(1px * var(--outline-scale, 1)) dashed var(--color-accent);
302
+ }
303
+
304
+ .element-outline[data-outline='selected'] {
305
+ outline: calc(2px * var(--outline-scale, 1)) solid var(--color-accent);
306
+ }
307
+
308
+ /* Above its neighbors, so a frame dragged over another stays whole. */
309
+ .frame[data-selected='true'] {
310
+ z-index: 1;
311
+ }
312
+
313
+ .frame[data-selected='true'] iframe {
314
+ outline: 2px solid var(--color-accent);
315
+ outline-offset: 2px;
316
+ }
317
+
318
+ .frame:focus-visible {
319
+ outline: 2px solid var(--color-accent);
320
+ outline-offset: 6px;
321
+ }
322
+
323
+ .box {
324
+ display: grid;
325
+ grid-template-columns: 1fr 1fr;
326
+ gap: var(--space-xs) var(--space-md);
327
+ margin: var(--space-xs) 0 0;
328
+ }
329
+
330
+ .box-row {
331
+ display: flex;
332
+ justify-content: space-between;
333
+ gap: var(--space-sm);
334
+ }
335
+
336
+ .box dt {
337
+ color: var(--color-muted);
338
+ }
339
+
340
+ .box dd {
341
+ margin: 0;
342
+ color: var(--color-text);
343
+ font-variant-numeric: tabular-nums;
344
+ }
345
+
278
346
  .toolbar {
279
347
  position: absolute;
280
348
  right: var(--space-md);
@@ -317,3 +385,65 @@ code {
317
385
  border-bottom: 1px solid var(--color-border);
318
386
  }
319
387
  }
388
+
389
+ .frame-row {
390
+ display: flex;
391
+ align-items: center;
392
+ }
393
+
394
+ .frame-row .row {
395
+ flex: 1;
396
+ min-width: 0;
397
+ }
398
+
399
+ .disclosure {
400
+ flex: none;
401
+ width: 24px;
402
+ height: 24px;
403
+ padding: 0;
404
+ border: 0;
405
+ border-radius: var(--radius-action);
406
+ background: none;
407
+ color: var(--color-muted);
408
+ font: inherit;
409
+ cursor: pointer;
410
+ }
411
+
412
+ .disclosure:hover {
413
+ background: var(--color-surface);
414
+ color: var(--color-text);
415
+ }
416
+
417
+ .layers {
418
+ margin: 0;
419
+ padding: 0 0 0 var(--space-sm);
420
+ list-style: none;
421
+ }
422
+
423
+ .layers-root {
424
+ padding-left: var(--space-lg);
425
+ }
426
+
427
+ .layer {
428
+ min-height: 24px;
429
+ }
430
+
431
+ .row-meta.layer-text {
432
+ flex-shrink: 1;
433
+ min-width: 0;
434
+ overflow: hidden;
435
+ text-overflow: ellipsis;
436
+ white-space: nowrap;
437
+ }
438
+
439
+ /* One property a row, since a computed color or font stack outgrows a half. */
440
+ .styles {
441
+ grid-template-columns: 1fr;
442
+ }
443
+
444
+ .styles dd {
445
+ min-width: 0;
446
+ overflow: hidden;
447
+ text-overflow: ellipsis;
448
+ white-space: nowrap;
449
+ }
@@ -1,9 +1,12 @@
1
1
  import { computed, signal } from '@preact/signals'
2
+ import type { ElementAddress } from '@/canvas/address'
2
3
  import type { Frame, Page } from '@/canvas/content'
3
4
 
4
5
  /**
5
6
  * Everything the panels read. Type imports only from outside `client/`, since
6
7
  * this runs in the browser and a Node or Bun module would not bundle there.
8
+ * `@/canvas/address` is the one exception the client imports for values, since
9
+ * it imports nothing itself.
7
10
  */
8
11
 
9
12
  export type Theme = 'light' | 'dark'
@@ -14,9 +17,27 @@ export interface TokenSource {
14
17
  readonly notice?: string
15
18
  }
16
19
 
20
+ export interface FrameRef {
21
+ readonly page: string
22
+ readonly frame: string
23
+ }
24
+
25
+ export interface ElementRef {
26
+ readonly index: number
27
+ readonly tag: string
28
+ /** Set by the server once the frame file changed since the pick. */
29
+ readonly stale?: boolean
30
+ }
31
+
32
+ export interface SelectionRef extends FrameRef {
33
+ readonly element?: ElementRef
34
+ }
35
+
17
36
  export interface PagesRecord {
18
37
  readonly pages: readonly Page[]
19
38
  readonly tokens: TokenSource
39
+ /** Absent when nothing is selected or the selected frame is gone. */
40
+ readonly selection?: SelectionRef | null
20
41
  }
21
42
 
22
43
  export interface ChangeEvent {
@@ -54,11 +75,51 @@ export const frameVersions = signal<ReadonlyMap<string, number>>(new Map())
54
75
 
55
76
  export const view = signal<View>({ x: 0, y: 0, zoom: 0.5 })
56
77
 
78
+ /**
79
+ * The one frame, or element in it, the operator pointed at, which Claude reads
80
+ * as "this one".
81
+ */
82
+ export const selection = signal<SelectionRef | undefined>(undefined)
83
+
84
+ /** Each loaded frame's document by frame key, replaced on every reload. */
85
+ export const frameDocuments = signal<ReadonlyMap<string, Document>>(new Map())
86
+
87
+ /** The element under the pointer, in a frame or in the layers tree. */
88
+ export const hoveredElement = signal<
89
+ { readonly key: string; readonly index: number } | undefined
90
+ >(undefined)
91
+
92
+ /** Frame keys whose layers are open in the pages panel. */
93
+ export const expandedFrames = signal<ReadonlySet<string>>(new Set())
94
+
95
+ /** Set while a frame follows the pointer, so the surface can style it. */
96
+ export const draggingFrame = signal<string | undefined>(undefined)
97
+
98
+ /** Why the last write to the canvas failed, until the next one succeeds. */
99
+ export const writeError = signal<string | undefined>(undefined)
100
+
57
101
  export const currentPage = computed<Page | undefined>(() => {
58
102
  const all = pages.value
59
103
  return all.find((page) => page.name === selectedPage.value) ?? all[0]
60
104
  })
61
105
 
106
+ /** The selected frame when it is on the page being shown. */
107
+ export const selectedFrame = computed<Frame | undefined>(() => {
108
+ const page = currentPage.value
109
+ const chosen = selection.value
110
+ if (!page || chosen?.page !== page.name) return undefined
111
+ return page.frames.find((frame) => frame.name === chosen.frame)
112
+ })
113
+
114
+ /** The selected element when its frame is on the page being shown. */
115
+ export const selectedElement = computed<
116
+ { readonly frame: Frame; readonly element: ElementRef } | undefined
117
+ >(() => {
118
+ const frame = selectedFrame.value
119
+ const element = selection.value?.element
120
+ return frame && element ? { frame, element } : undefined
121
+ })
122
+
62
123
  export function frameKey(page: string, frame: Pick<Frame, 'file'>): string {
63
124
  return `${page}/${frame.file}`
64
125
  }
@@ -77,9 +138,22 @@ export function toggleFrameTheme(key: string): void {
77
138
  frameThemes.value = next
78
139
  }
79
140
 
141
+ export function registerFrameDocument(key: string, doc: Document): void {
142
+ const next = new Map(frameDocuments.value)
143
+ next.set(key, doc)
144
+ frameDocuments.value = next
145
+ }
146
+
147
+ export function toggleLayers(key: string): void {
148
+ const next = new Set(expandedFrames.value)
149
+ if (!next.delete(key)) next.add(key)
150
+ expandedFrames.value = next
151
+ }
152
+
80
153
  export function applyRecord(record: PagesRecord): void {
81
154
  pages.value = record.pages
82
155
  tokens.value = record.tokens
156
+ selection.value = record.selection ?? undefined
83
157
  loadError.value = undefined
84
158
  isLoaded.value = true
85
159
  }
@@ -115,6 +189,112 @@ export async function applyChange(
115
189
  await loadPages(fetchImpl)
116
190
  }
117
191
 
192
+ /** What a refused element pick tells the operator, by the server's reason. */
193
+ const PICK_NOTICES: Readonly<Record<string, string | undefined>> = {
194
+ 'address-mismatch':
195
+ 'Could not select that element, since the browser and the file count the elements of this frame differently, as when the browser builds an element the file does not state.',
196
+ 'stale-address':
197
+ 'Could not select that element, since the frame changed before the pick arrived. Pick it again once the frame reloads.',
198
+ }
199
+
200
+ async function refusalReason(response: Response): Promise<string | undefined> {
201
+ try {
202
+ const body: unknown = await response.json()
203
+ return typeof body === 'object' && body !== null && 'reason' in body
204
+ ? String(body.reason)
205
+ : undefined
206
+ } catch {
207
+ return undefined
208
+ }
209
+ }
210
+
211
+ /**
212
+ * Posts one write and reports a refusal in the panel rather than failing
213
+ * silently. A refusal also rereads the page list, so a position the server
214
+ * would not take does not stay on the surface.
215
+ */
216
+ async function write(
217
+ path: string,
218
+ body: unknown,
219
+ fetchImpl: typeof fetch,
220
+ ): Promise<void> {
221
+ try {
222
+ const response = await fetchImpl(path, {
223
+ method: 'POST',
224
+ headers: { 'content-type': 'application/json' },
225
+ body: JSON.stringify(body),
226
+ })
227
+ if (!response.ok) {
228
+ const reason = await refusalReason(response)
229
+ writeError.value =
230
+ (reason && PICK_NOTICES[reason]) ??
231
+ `Could not save (status ${response.status}). Check canon canvas serve is still running.`
232
+ await loadPages(fetchImpl)
233
+ return
234
+ }
235
+ writeError.value = undefined
236
+ } catch (error) {
237
+ writeError.value = `Could not save (${error instanceof Error ? error.message : 'unknown'}). Check canon canvas serve is still running.`
238
+ await loadPages(fetchImpl)
239
+ }
240
+ }
241
+
242
+ /** Selects a frame here at once and records it where Claude reads it. */
243
+ export async function selectFrame(
244
+ ref: FrameRef | undefined,
245
+ fetchImpl: typeof fetch = fetch,
246
+ ): Promise<void> {
247
+ selection.value = ref
248
+ await write('/api/selection', ref ?? {}, fetchImpl)
249
+ }
250
+
251
+ /**
252
+ * Selects one element of a frame, opens that frame's layers so the tree shows
253
+ * the pick, and records it where Claude reads it. The server checks the
254
+ * address against the file and refuses one it cannot match.
255
+ */
256
+ export async function selectElement(
257
+ ref: FrameRef,
258
+ key: string,
259
+ address: ElementAddress,
260
+ fetchImpl: typeof fetch = fetch,
261
+ ): Promise<void> {
262
+ selection.value = {
263
+ ...ref,
264
+ element: { index: address.index, tag: address.tag },
265
+ }
266
+ if (!expandedFrames.value.has(key)) toggleLayers(key)
267
+ await write('/api/selection', { ...ref, element: address }, fetchImpl)
268
+ }
269
+
270
+ /**
271
+ * Moves a frame on the surface without writing, which a drag calls on every
272
+ * pointer move. The next reread replaces it with what the layout holds.
273
+ */
274
+ export function previewMove(ref: FrameRef, x: number, y: number): void {
275
+ pages.value = pages.value.map((candidate) =>
276
+ candidate.name === ref.page
277
+ ? {
278
+ ...candidate,
279
+ frames: candidate.frames.map((frame) =>
280
+ frame.name === ref.frame ? { ...frame, x, y, placed: true } : frame,
281
+ ),
282
+ }
283
+ : candidate,
284
+ )
285
+ }
286
+
287
+ /** Shows the move and writes it through the server's shared layout writer. */
288
+ export async function moveFrameTo(
289
+ ref: FrameRef,
290
+ x: number,
291
+ y: number,
292
+ fetchImpl: typeof fetch = fetch,
293
+ ): Promise<void> {
294
+ previewMove(ref, x, y)
295
+ await write('/api/frames/move', { ...ref, x, y }, fetchImpl)
296
+ }
297
+
118
298
  export function clampZoom(zoom: number): number {
119
299
  return Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, zoom))
120
300
  }
@@ -183,4 +363,10 @@ export function resetState(): void {
183
363
  frameThemes.value = new Map()
184
364
  frameVersions.value = new Map()
185
365
  view.value = { x: 0, y: 0, zoom: 0.5 }
366
+ selection.value = undefined
367
+ frameDocuments.value = new Map()
368
+ hoveredElement.value = undefined
369
+ expandedFrames.value = new Set()
370
+ draggingFrame.value = undefined
371
+ writeError.value = undefined
186
372
  }