@erclx/canon 5.52.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 (201) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +11 -13
  3. package/claude/.claude-plugin/plugin.json +1 -1
  4. package/claude/skills/canon-cli/SKILL.md +5 -8
  5. package/claude/skills/context-fold/REQUIREMENT.md +0 -1
  6. package/claude/skills/design-identity/REQUIREMENT.md +2 -2
  7. package/claude/skills/design-identity/SKILL.md +6 -6
  8. package/claude/skills/design-record/REQUIREMENT.md +2 -2
  9. package/claude/skills/design-record/SKILL.md +4 -4
  10. package/claude/skills/design-record/references/folder.md +1 -1
  11. package/claude/skills/design-taste/REQUIREMENT.md +1 -1
  12. package/claude/skills/design-taste/references/kinds.md +0 -1
  13. package/claude/skills/draw-figure/REQUIREMENT.md +3 -4
  14. package/claude/skills/draw-figure/SKILL.md +5 -6
  15. package/claude/skills/draw-figure/references/figures.md +0 -1
  16. package/claude/skills/draw-figure/references/hand-drawn.md +1 -1
  17. package/claude/skills/pick-by-eye/REQUIREMENT.md +4 -5
  18. package/claude/skills/pick-by-eye/SKILL.md +34 -41
  19. package/claude/skills/pick-by-eye/references/board.md +42 -0
  20. package/claude/skills/pick-by-eye/references/live-arms.md +3 -3
  21. package/claude/skills/plan-groundwork/SKILL.md +1 -1
  22. package/claude/skills/teach-craft/REQUIREMENT.md +30 -0
  23. package/claude/skills/teach-craft/SKILL.md +70 -0
  24. package/claude/skills/teach-craft/references/adopted.md +113 -0
  25. package/claude/skills/teach-craft/references/lesson-craft.md +60 -0
  26. package/claude/skills/{teach-workspace → teach-craft}/references/pedagogy.md +41 -6
  27. package/docs/agents/audits.md +0 -1
  28. package/docs/agents/install-and-sync.md +0 -8
  29. package/docs/target/migrations.md +16 -2
  30. package/docs/target/projects.md +1 -1
  31. package/docs/workflow/parallel-features.md +1 -1
  32. package/docs/workflow/skill-map-on-request.md +10 -22
  33. package/docs/workflow/skill-map.md +11 -14
  34. package/docs/workflow/visual-design-workflow.md +1 -4
  35. package/governance/detect.toml +1 -6
  36. package/governance/renames.toml +0 -1
  37. package/package.json +2 -8
  38. package/scripts/core/regen-web-previews.ts +2 -67
  39. package/src/audits/catalog.ts +0 -1
  40. package/src/browser/engine.ts +3 -6
  41. package/src/capture/render.ts +1 -1
  42. package/src/claude/cases/authoring.ts +0 -12
  43. package/src/claude/cases/misc.ts +0 -22
  44. package/src/claude/cases/workflow.ts +2 -38
  45. package/src/claude/skills-audit.ts +1 -1
  46. package/src/cli/help.ts +0 -10
  47. package/src/cli.ts +0 -8
  48. package/src/commands/design.ts +16 -315
  49. package/src/commands/records.ts +0 -1
  50. package/src/commands/serve.ts +2 -2
  51. package/src/commands/sync.ts +4 -5
  52. package/src/design/components.ts +8 -1514
  53. package/src/design/css.ts +5 -6
  54. package/src/design/fonts.ts +3 -5
  55. package/src/design/regen.ts +5 -32
  56. package/src/design/render.ts +1 -1
  57. package/src/design/tokens.ts +3 -2
  58. package/src/driver/drive.ts +3 -4
  59. package/src/driver/steps.ts +2 -5
  60. package/src/gate/stages.ts +4 -10
  61. package/src/gov/audit.ts +1 -6
  62. package/src/inventory/walk.ts +1 -1
  63. package/src/markdown/scope.ts +6 -35
  64. package/src/records/validate.ts +4 -176
  65. package/src/sandbox/equivalence.ts +0 -5
  66. package/src/shipped/references.ts +1 -2
  67. package/src/sync/check.ts +4 -29
  68. package/src/sync/stamp.ts +6 -6
  69. package/src/sync/target.ts +1 -4
  70. package/tooling/claude/reference.md +1 -1
  71. package/tooling/claude/seeds/canon/DESIGN.md +1 -1
  72. package/claude/skills/canvas-board/REQUIREMENT.md +0 -35
  73. package/claude/skills/canvas-board/SKILL.md +0 -143
  74. package/claude/skills/canvas-board/references/canvas.md +0 -170
  75. package/claude/skills/draft-and-pick/REQUIREMENT.md +0 -26
  76. package/claude/skills/draft-and-pick/SKILL.md +0 -11
  77. package/claude/skills/draft-doc/REQUIREMENT.md +0 -26
  78. package/claude/skills/draft-doc/SKILL.md +0 -11
  79. package/claude/skills/draft-figure/REQUIREMENT.md +0 -26
  80. package/claude/skills/draft-figure/SKILL.md +0 -11
  81. package/claude/skills/draft-identity/REQUIREMENT.md +0 -26
  82. package/claude/skills/draft-identity/SKILL.md +0 -11
  83. package/claude/skills/draft-ready/REQUIREMENT.md +0 -26
  84. package/claude/skills/draft-ready/SKILL.md +0 -11
  85. package/claude/skills/draft-screencast/REQUIREMENT.md +0 -26
  86. package/claude/skills/draft-screencast/SKILL.md +0 -11
  87. package/claude/skills/draft-slides/REQUIREMENT.md +0 -26
  88. package/claude/skills/draft-slides/SKILL.md +0 -11
  89. package/claude/skills/make-deck/REQUIREMENT.md +0 -36
  90. package/claude/skills/make-deck/SKILL.md +0 -80
  91. package/claude/skills/make-deck/references/deck.md +0 -183
  92. package/claude/skills/read-frames/REQUIREMENT.md +0 -30
  93. package/claude/skills/read-frames/SKILL.md +0 -55
  94. package/claude/skills/record-screencast/REQUIREMENT.md +0 -35
  95. package/claude/skills/record-screencast/SKILL.md +0 -99
  96. package/claude/skills/script-screencast/REQUIREMENT.md +0 -34
  97. package/claude/skills/script-screencast/SKILL.md +0 -70
  98. package/claude/skills/script-screencast/references/beats-template.md +0 -119
  99. package/claude/skills/teach-workspace/REQUIREMENT.md +0 -34
  100. package/claude/skills/teach-workspace/SKILL.md +0 -196
  101. package/claude/skills/teach-workspace/references/glossary.md +0 -90
  102. package/claude/skills/teach-workspace/references/lesson-build.md +0 -106
  103. package/claude/skills/teach-workspace/references/lesson-craft.md +0 -135
  104. package/claude/skills/teach-workspace/references/promotion-fold.md +0 -35
  105. package/claude/skills/teach-workspace/references/promotion.md +0 -116
  106. package/claude/skills/teach-workspace/references/revisit.md +0 -28
  107. package/claude/skills/teach-workspace/references/teach.md +0 -211
  108. package/claude/skills/video-craft/REQUIREMENT.md +0 -35
  109. package/claude/skills/video-craft/SKILL.md +0 -96
  110. package/claude/skills/video-craft/references/adopted.md +0 -110
  111. package/governance/rules/ui/canvas.md +0 -13
  112. package/src/canvas/address.ts +0 -227
  113. package/src/canvas/arrange.ts +0 -66
  114. package/src/canvas/capture.ts +0 -391
  115. package/src/canvas/client/app.tsx +0 -188
  116. package/src/canvas/client/inspector/align-grid.tsx +0 -162
  117. package/src/canvas/client/inspector/color-field.tsx +0 -398
  118. package/src/canvas/client/inspector/color-inputs.tsx +0 -139
  119. package/src/canvas/client/inspector/color-picker.tsx +0 -668
  120. package/src/canvas/client/inspector/color-space.ts +0 -240
  121. package/src/canvas/client/inspector/field.tsx +0 -263
  122. package/src/canvas/client/inspector/fields.css +0 -763
  123. package/src/canvas/client/inspector/section.tsx +0 -27
  124. package/src/canvas/client/inspector/size-field.tsx +0 -69
  125. package/src/canvas/client/inspector/token-select.tsx +0 -109
  126. package/src/canvas/client/inspector/values.ts +0 -297
  127. package/src/canvas/client/inspector.tsx +0 -692
  128. package/src/canvas/client/keys.ts +0 -71
  129. package/src/canvas/client/layers.tsx +0 -118
  130. package/src/canvas/client/main.tsx +0 -71
  131. package/src/canvas/client/pages-panel.tsx +0 -212
  132. package/src/canvas/client/panel-handle.tsx +0 -90
  133. package/src/canvas/client/selection.tsx +0 -199
  134. package/src/canvas/client/shell.css +0 -762
  135. package/src/canvas/client/state.ts +0 -792
  136. package/src/canvas/client/surface.tsx +0 -803
  137. package/src/canvas/client/theme-panel.tsx +0 -55
  138. package/src/canvas/client/tools.tsx +0 -153
  139. package/src/canvas/content.ts +0 -781
  140. package/src/canvas/edit.ts +0 -575
  141. package/src/canvas/editing.ts +0 -203
  142. package/src/canvas/fit.ts +0 -238
  143. package/src/canvas/global.d.ts +0 -15
  144. package/src/canvas/history.ts +0 -116
  145. package/src/canvas/index.html +0 -20
  146. package/src/canvas/server.ts +0 -766
  147. package/src/canvas/tokens.ts +0 -221
  148. package/src/commands/canvas.ts +0 -1097
  149. package/src/commands/demo.ts +0 -542
  150. package/src/commands/slides.ts +0 -184
  151. package/src/commands/teach.ts +0 -1401
  152. package/src/demo/beats.ts +0 -135
  153. package/src/demo/compile.ts +0 -350
  154. package/src/demo/container.ts +0 -219
  155. package/src/demo/cursors.ts +0 -55
  156. package/src/demo/drive.ts +0 -442
  157. package/src/demo/pointer.ts +0 -178
  158. package/src/demo/theme.ts +0 -112
  159. package/src/demo/timeline.ts +0 -64
  160. package/src/design/adapter.ts +0 -59
  161. package/src/design/base.css +0 -203
  162. package/src/design/brand-favicon.ts +0 -18
  163. package/src/design/neutral.ts +0 -127
  164. package/src/design/project-fonts.ts +0 -392
  165. package/src/slides/convert/chart.ts +0 -165
  166. package/src/slides/convert/deck.ts +0 -244
  167. package/src/slides/convert/export.ts +0 -567
  168. package/src/slides/convert/master.ts +0 -198
  169. package/src/slides/convert/shapes.ts +0 -804
  170. package/src/slides/convert/svg.ts +0 -38
  171. package/src/slides/convert/walk.ts +0 -671
  172. package/src/slides/decks.ts +0 -110
  173. package/src/slides/open.ts +0 -18
  174. package/src/slides/package/fonts.ts +0 -301
  175. package/src/slides/package/motion.ts +0 -316
  176. package/src/slides/package/test-face.ts +0 -113
  177. package/src/teach/browser/compile.ts +0 -44
  178. package/src/teach/browser/dismiss.ts +0 -76
  179. package/src/teach/browser/focus-line.ts +0 -19
  180. package/src/teach/browser/glossary-filter.ts +0 -44
  181. package/src/teach/browser/head.ts +0 -30
  182. package/src/teach/browser/quiz.ts +0 -19
  183. package/src/teach/browser/reload.ts +0 -9
  184. package/src/teach/browser/sidebar.ts +0 -233
  185. package/src/teach/browser/theme.ts +0 -18
  186. package/src/teach/components/code.tsx +0 -24
  187. package/src/teach/components/heading.tsx +0 -11
  188. package/src/teach/components/list.tsx +0 -17
  189. package/src/teach/components/paragraph.tsx +0 -29
  190. package/src/teach/components/refs.tsx +0 -28
  191. package/src/teach/cross-references.ts +0 -78
  192. package/src/teach/fonts.ts +0 -16
  193. package/src/teach/highlight.ts +0 -71
  194. package/src/teach/html/jsx-dev-runtime.ts +0 -13
  195. package/src/teach/html/jsx-runtime.ts +0 -113
  196. package/src/teach/html/raw.ts +0 -28
  197. package/src/teach/lesson.ts +0 -178
  198. package/src/teach/nav.ts +0 -1337
  199. package/src/teach/render.ts +0 -240
  200. package/src/teach/workspace.ts +0 -1164
  201. package/src/teach/write-if-changed.ts +0 -17
@@ -1,398 +0,0 @@
1
- /** @jsxImportSource preact */
2
- import type { JSX } from 'preact'
3
- import { useLayoutEffect, useRef, useState } from 'preact/hooks'
4
- import type { ScrubSession } from '@/canvas/client/inspector/field'
5
- import {
6
- ColorInputs,
7
- currentOpacity,
8
- } from '@/canvas/client/inspector/color-inputs'
9
- import {
10
- ColorPicker,
11
- isPickerHeld,
12
- releasePicker,
13
- } from '@/canvas/client/inspector/color-picker'
14
- import {
15
- composeColor,
16
- type ParsedColor,
17
- readHex,
18
- } from '@/canvas/client/inspector/values'
19
-
20
- interface ColorFieldProps {
21
- /** The full word, which names the hex input for assistive technology. */
22
- readonly label: string
23
- /** What the element holds, or undefined for a form the picker cannot read. */
24
- readonly color: ParsedColor | undefined
25
- /** The value as written, shown when `color` is undefined. */
26
- readonly text: string
27
- /** The element's own inline value, empty where none stands. */
28
- readonly inline: string
29
- /** The color the browser paints, which fills the swatch. */
30
- readonly painted: string
31
- /** The color tokens in the order the token sheet sorts them. */
32
- readonly tokens: readonly string[]
33
- /** The color a token paints in the frame, read when the list opens. */
34
- readonly paint: (name: string) => string
35
- /** The frame, element, and property, so a reload reopens the right picker. */
36
- readonly owner: string
37
- readonly isRaw: boolean
38
- readonly isBusy: boolean
39
- /** Opens a session previewing into the frame, where the element takes one. */
40
- readonly preview?: () => ScrubSession
41
- readonly onCommit: (value: string) => void
42
- }
43
-
44
- /**
45
- * The accessible name of the row control that last wrote a value, so it takes
46
- * focus back each time the frame reloads. A saved edit remounts the inspector,
47
- * once for the edit and again when the file watcher reports the write, and each
48
- * remount replaces the control that held focus and drops it to the page. It
49
- * holds until focus lands anywhere else.
50
- */
51
- let refocus: string | undefined
52
-
53
- function swatchLabel(label: string): string {
54
- return `${label} picker`
55
- }
56
-
57
- function tokensLabel(label: string): string {
58
- return `${label} tokens`
59
- }
60
-
61
- function eyedropperLabel(label: string): string {
62
- return `${label} eyedropper`
63
- }
64
-
65
- if (typeof document !== 'undefined') {
66
- document.addEventListener('focusin', (event) => {
67
- if (refocus === undefined) return
68
- const target = event.target
69
- const name =
70
- target instanceof Element ? target.getAttribute('aria-label') : null
71
- if (name !== refocus) refocus = undefined
72
- })
73
- }
74
-
75
- /** The screen sampler, where the browser ships one. */
76
- function eyeDropper(): (new () => EyeDropperSampler) | undefined {
77
- return typeof window === 'undefined' ? undefined : window.EyeDropper
78
- }
79
-
80
- type Open = 'picker' | 'tokens' | undefined
81
-
82
- const GAP = 8
83
-
84
- /**
85
- * The left edge of the scrolling panel holding the row, so a popover clears
86
- * the panel's padding rather than overlapping it. The row's own edge stands in
87
- * where no ancestor scrolls.
88
- */
89
- function panelLeft(row: HTMLElement): number {
90
- for (let node = row.parentElement; node; node = node.parentElement) {
91
- const overflow = getComputedStyle(node).overflowY
92
- if (overflow === 'auto' || overflow === 'scroll') {
93
- return node.getBoundingClientRect().left
94
- }
95
- }
96
- return row.getBoundingClientRect().left
97
- }
98
-
99
- /**
100
- * Places a popover beside the row, to the left of the panel, and holds it
101
- * inside the window. The panel scrolls and clips, so the popover sits in the
102
- * top layer where the browser has one and at fixed coordinates either way.
103
- */
104
- function place(popover: HTMLElement, row: HTMLElement): void {
105
- if (
106
- typeof popover.showPopover === 'function' &&
107
- !popover.matches(':popover-open')
108
- ) {
109
- popover.showPopover()
110
- }
111
- const box = popover.getBoundingClientRect()
112
- const anchor = row.getBoundingClientRect()
113
- const width = document.documentElement.clientWidth || window.innerWidth
114
- const height = document.documentElement.clientHeight || window.innerHeight
115
- const before = panelLeft(row) - GAP - box.width
116
- const left =
117
- before >= GAP
118
- ? before
119
- : Math.max(GAP, Math.min(anchor.right + GAP, width - box.width - GAP))
120
- const top = Math.max(GAP, Math.min(anchor.top, height - box.height - GAP))
121
- popover.style.left = `${left}px`
122
- popover.style.top = `${top}px`
123
- }
124
-
125
- /**
126
- * One color property: a swatch opening the picker, the hex, the opacity, a
127
- * tokens icon opening the project's color tokens, and an eyedropper where the
128
- * browser has one. A token keeps following the theme and a literal does not,
129
- * so the tokens sit one press from the row.
130
- */
131
- export function ColorField({
132
- label,
133
- color,
134
- text,
135
- inline,
136
- painted,
137
- tokens,
138
- paint,
139
- owner,
140
- isRaw,
141
- isBusy,
142
- preview,
143
- onCommit,
144
- }: ColorFieldProps): JSX.Element {
145
- const [open, setOpen] = useState<Open>(() =>
146
- isPickerHeld(owner) ? 'picker' : undefined,
147
- )
148
- const root = useRef<HTMLDivElement>(null)
149
- const row = useRef<HTMLDivElement>(null)
150
- const swatch = useRef<HTMLButtonElement>(null)
151
- const tokenButton = useRef<HTMLButtonElement>(null)
152
- const list = useRef<HTMLUListElement>(null)
153
- const dialog = useRef<HTMLDivElement>(null)
154
- const picked = color?.kind === 'token' ? tokens.indexOf(color.name) : -1
155
- const [active, setActive] = useState(Math.max(0, picked))
156
- const isNone = color?.kind === 'none'
157
-
158
- /*
159
- * Focus moves in the commit rather than after paint, so a key typed straight
160
- * after the one that opened the list reaches it, not the button.
161
- */
162
- useLayoutEffect(() => {
163
- if (!open || !dialog.current || !row.current) return
164
- place(dialog.current, row.current)
165
- if (open === 'tokens') (list.current ?? dialog.current).focus()
166
- }, [open])
167
-
168
- useLayoutEffect(() => {
169
- if (refocus === undefined) return
170
- root.current
171
- ?.querySelector<HTMLElement>(`[aria-label="${refocus}"]`)
172
- ?.focus()
173
- }, [label])
174
-
175
- const close = () => {
176
- const trigger = open === 'tokens' ? tokenButton : swatch
177
- releasePicker()
178
- setOpen(undefined)
179
- trigger.current?.focus()
180
- }
181
-
182
- const toggle = (next: Exclude<Open, undefined>) => {
183
- releasePicker()
184
- setActive(Math.max(0, picked))
185
- setOpen(open === next ? undefined : next)
186
- }
187
-
188
- const pick = (name: string) => {
189
- if (color?.kind === 'token' && color.name === name) {
190
- close()
191
- return
192
- }
193
- close()
194
- refocus = tokensLabel(label)
195
- onCommit(
196
- composeColor({ kind: 'token', name, opacity: currentOpacity(color) }),
197
- )
198
- }
199
-
200
- const Sampler = eyeDropper()
201
- const sample = async (sampler: new () => EyeDropperSampler) => {
202
- let picked: string
203
- try {
204
- picked = (await new sampler().open()).sRGBHex
205
- } catch {
206
- /* The operator dismissed the sampler, which writes nothing. */
207
- return
208
- }
209
- const hex = readHex(picked)
210
- if (!hex) return
211
- refocus = eyedropperLabel(label)
212
- onCommit(
213
- composeColor({
214
- kind: 'hex',
215
- hex: hex.hex,
216
- opacity: currentOpacity(color),
217
- }),
218
- )
219
- }
220
-
221
- const id = `color-${label.replace(/\W+/g, '-')}`
222
-
223
- return (
224
- <div
225
- ref={root}
226
- class="color-field is-wide"
227
- onFocusOut={(event) => {
228
- const field = event.currentTarget
229
- /*
230
- * Read once focus has settled. A reload removes the field while it
231
- * holds focus, and a picker held across that reload must stay open.
232
- */
233
- setTimeout(() => {
234
- if (!field.isConnected) return
235
- if (field.contains(document.activeElement)) return
236
- releasePicker()
237
- setOpen(undefined)
238
- }, 0)
239
- }}
240
- >
241
- <div ref={row} class="fill-row">
242
- <div class="glyph-field">
243
- <button
244
- ref={swatch}
245
- class={isNone ? 'swatch is-none' : 'swatch'}
246
- type="button"
247
- aria-label={swatchLabel(label)}
248
- aria-haspopup="dialog"
249
- aria-expanded={open === 'picker'}
250
- title={label}
251
- disabled={isBusy}
252
- onClick={() => toggle('picker')}
253
- >
254
- <span
255
- class="swatch-paint"
256
- style={isNone ? undefined : { '--paint': painted }}
257
- />
258
- </button>
259
- <ColorInputs
260
- hexLabel={label}
261
- opacityLabel={`${label} opacity`}
262
- color={color}
263
- text={text}
264
- isBusy={isBusy}
265
- onCommit={onCommit}
266
- />
267
- </div>
268
- <button
269
- ref={tokenButton}
270
- class="color-icon"
271
- type="button"
272
- aria-label={tokensLabel(label)}
273
- aria-haspopup="dialog"
274
- aria-expanded={open === 'tokens'}
275
- title="Pick a color token"
276
- disabled={isBusy}
277
- onClick={() => toggle('tokens')}
278
- >
279
- <svg viewBox="0 0 16 16" aria-hidden="true">
280
- <circle cx="5" cy="5" r="2.25" />
281
- <circle cx="11" cy="5" r="2.25" />
282
- <circle cx="5" cy="11" r="2.25" />
283
- <circle cx="11" cy="11" r="2.25" />
284
- </svg>
285
- </button>
286
- {Sampler ? (
287
- <button
288
- class="color-icon"
289
- type="button"
290
- aria-label={eyedropperLabel(label)}
291
- title="Pick a color from the screen"
292
- disabled={isBusy}
293
- onClick={() => void sample(Sampler)}
294
- >
295
- <svg viewBox="0 0 16 16" aria-hidden="true">
296
- <path d="M10.5 2.5a1.4 1.4 0 0 1 2 0l1 1a1.4 1.4 0 0 1 0 2L12 7l.5.5-1 1-4-4 1-1L9 4zM7.5 5.5l3 3-5 5H2.5v-3z" />
297
- </svg>
298
- </button>
299
- ) : null}
300
- {isRaw ? (
301
- <span
302
- class="raw"
303
- title="Set as a raw value, so it will not follow the theme. Pick a token to fix it"
304
- >
305
- raw
306
- </span>
307
- ) : null}
308
- </div>
309
- {open ? (
310
- <div
311
- ref={dialog}
312
- class={
313
- open === 'picker' ? 'color-popover' : 'color-popover is-tokens'
314
- }
315
- popover="manual"
316
- role="dialog"
317
- aria-label={
318
- open === 'picker' ? `${label} color` : `${label} token list`
319
- }
320
- tabIndex={-1}
321
- onKeyDown={(event) => {
322
- if (event.key !== 'Escape') return
323
- event.preventDefault()
324
- /* A blur would commit what was typed, so put it back first. */
325
- if (event.target instanceof HTMLInputElement) {
326
- event.target.value = event.target.defaultValue
327
- }
328
- close()
329
- }}
330
- >
331
- {open === 'picker' ? (
332
- <ColorPicker
333
- owner={owner}
334
- color={color}
335
- text={text}
336
- inline={inline}
337
- painted={painted}
338
- begin={preview}
339
- isBusy={isBusy}
340
- onCommit={onCommit}
341
- />
342
- ) : tokens.length > 0 ? (
343
- <ul
344
- ref={list}
345
- class="token-list"
346
- role="listbox"
347
- aria-label="Tokens"
348
- tabIndex={0}
349
- aria-activedescendant={`${id}-${active}`}
350
- onKeyDown={(event) => {
351
- const last = tokens.length - 1
352
- const moves: Record<string, number> = {
353
- ArrowDown: Math.min(last, active + 1),
354
- ArrowUp: Math.max(0, active - 1),
355
- Home: 0,
356
- End: last,
357
- }
358
- if (event.key in moves) {
359
- event.preventDefault()
360
- setActive(moves[event.key] ?? active)
361
- } else if (event.key === 'Enter' || event.key === ' ') {
362
- event.preventDefault()
363
- const name = tokens[active]
364
- if (name) pick(name)
365
- }
366
- }}
367
- >
368
- {tokens.map((name, index) => (
369
- <li
370
- key={name}
371
- id={`${id}-${index}`}
372
- class={
373
- index === active ? 'token-option is-active' : 'token-option'
374
- }
375
- role="option"
376
- aria-selected={index === picked}
377
- title={name}
378
- onClick={() => pick(name)}
379
- >
380
- <span
381
- class="swatch-paint"
382
- aria-hidden="true"
383
- style={{ '--paint': paint(name) }}
384
- />
385
- <span class="token-name">{name}</span>
386
- </li>
387
- ))}
388
- </ul>
389
- ) : (
390
- <p class="empty">
391
- No color tokens resolve. Add them to the token sheet
392
- </p>
393
- )}
394
- </div>
395
- ) : null}
396
- </div>
397
- )
398
- }
@@ -1,139 +0,0 @@
1
- /** @jsxImportSource preact */
2
- import type { JSX } from 'preact'
3
- import {
4
- composeColor,
5
- type ParsedColor,
6
- readHex,
7
- readOpacity,
8
- } from '@/canvas/client/inspector/values'
9
-
10
- function shownHex(color: ParsedColor | undefined, text: string): string {
11
- if (!color) return text
12
- if (color.kind === 'none') return ''
13
- return color.kind === 'token' ? color.name : color.hex
14
- }
15
-
16
- function shownOpacity(color: ParsedColor | undefined): string {
17
- return color && color.kind !== 'none' ? String(color.opacity) : ''
18
- }
19
-
20
- export function currentOpacity(color: ParsedColor | undefined): number {
21
- return color && color.kind !== 'none' ? color.opacity : 100
22
- }
23
-
24
- /**
25
- * What a typed hex writes. A token name typed whole picks the token, and any
26
- * other text goes through as written, which the panel then marks raw.
27
- */
28
- function fromTyped(typed: string, opacity: number): string {
29
- const hex = readHex(typed)
30
- if (hex) {
31
- return composeColor({
32
- kind: 'hex',
33
- hex: hex.hex,
34
- opacity: hex.opacity ?? opacity,
35
- })
36
- }
37
- if (/^--[\w-]+$/.test(typed)) {
38
- return composeColor({ kind: 'token', name: typed, opacity })
39
- }
40
- return typed
41
- }
42
-
43
- export interface ColorInputsProps {
44
- readonly hexLabel: string
45
- readonly opacityLabel: string
46
- readonly color: ParsedColor | undefined
47
- readonly text: string
48
- readonly isBusy: boolean
49
- /**
50
- * Holds the inputs read-only rather than disabled while busy, for a
51
- * popover that closes once focus leaves it and a disabled input drops focus.
52
- */
53
- readonly keepsFocus?: boolean
54
- readonly onCommit: (value: string) => void
55
- }
56
-
57
- /**
58
- * The hex and the opacity. Each commits on change and posts nothing when the
59
- * value is what it started at, or an opacity outside 0 to 100.
60
- */
61
- export function ColorInputs({
62
- hexLabel,
63
- opacityLabel,
64
- color,
65
- text,
66
- isBusy,
67
- keepsFocus = false,
68
- onCommit,
69
- }: ColorInputsProps): JSX.Element {
70
- const hex = shownHex(color, text)
71
- const opacity = shownOpacity(color)
72
- const isDisabled = isBusy && !keepsFocus
73
- const isReadOnly = isBusy && keepsFocus
74
- return (
75
- <>
76
- <input
77
- class={
78
- color === undefined
79
- ? 'glyph-field-input is-text'
80
- : color.kind === 'token'
81
- ? 'glyph-field-input is-token'
82
- : 'glyph-field-input'
83
- }
84
- type="text"
85
- aria-label={hexLabel}
86
- title={hex}
87
- defaultValue={hex}
88
- placeholder="None"
89
- disabled={isDisabled}
90
- readOnly={isReadOnly}
91
- spellcheck={false}
92
- onChange={(event) => {
93
- const typed = event.currentTarget.value.trim()
94
- if (isBusy) {
95
- event.currentTarget.value = hex
96
- return
97
- }
98
- if (typed === '' || typed === hex) return
99
- onCommit(fromTyped(typed, currentOpacity(color)))
100
- }}
101
- onKeyDown={(event) => {
102
- if (event.key === 'Escape') event.currentTarget.value = hex
103
- }}
104
- />
105
- <input
106
- class="color-opacity"
107
- type="text"
108
- inputMode="numeric"
109
- aria-label={opacityLabel}
110
- defaultValue={opacity}
111
- disabled={isDisabled || !color || color.kind === 'none'}
112
- readOnly={isReadOnly}
113
- spellcheck={false}
114
- onChange={(event) => {
115
- const percent = readOpacity(event.currentTarget.value)
116
- if (
117
- isBusy ||
118
- percent === undefined ||
119
- !color ||
120
- color.kind === 'none' ||
121
- percent === color.opacity
122
- ) {
123
- event.currentTarget.value = opacity
124
- return
125
- }
126
- onCommit(composeColor({ ...color, opacity: percent }))
127
- }}
128
- onKeyDown={(event) => {
129
- if (event.key === 'Escape') event.currentTarget.value = opacity
130
- }}
131
- />
132
- {opacity ? (
133
- <span class="color-percent" aria-hidden="true">
134
- %
135
- </span>
136
- ) : null}
137
- </>
138
- )
139
- }