@1agh/maude 2.0.4 → 2.0.8

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 (272) hide show
  1. package/apps/hub/src/project-transactions/kernel.mjs +10 -1
  2. package/apps/studio/access/closure.ts +156 -16
  3. package/apps/studio/access/filters.ts +39 -5
  4. package/apps/studio/access/known-canvases.ts +24 -1
  5. package/apps/studio/access/refused-inputs.ts +89 -0
  6. package/apps/studio/actions/agents.ts +59 -0
  7. package/apps/studio/actions/ctx.ts +3 -0
  8. package/apps/studio/actions/defs/app.ts +12 -0
  9. package/apps/studio/actions/defs/sync.ts +13 -0
  10. package/apps/studio/actions/defs/view.ts +59 -3
  11. package/apps/studio/actions/keymap.gen.ts +35 -0
  12. package/apps/studio/actions/menu.ts +2 -0
  13. package/apps/studio/actions/types.ts +3 -1
  14. package/apps/studio/actions.manifest.json +148 -1
  15. package/apps/studio/actions.parity.json +31 -1
  16. package/apps/studio/annotations/ui/ai-seen.tsx +4 -3
  17. package/apps/studio/annotations/ui/element-node.tsx +139 -54
  18. package/apps/studio/annotations/ui/lod.tsx +1 -1
  19. package/apps/studio/annotations/ui/ride.ts +2 -1
  20. package/apps/studio/annotations/ui/text-style.ts +1 -1
  21. package/apps/studio/annotations-context-toolbar.tsx +5 -4
  22. package/apps/studio/annotations-layer.tsx +4 -15
  23. package/apps/studio/api.ts +425 -128
  24. package/apps/studio/artboard-activity-overlay.tsx +4 -4
  25. package/apps/studio/artboard-ai-copies.tsx +4 -4
  26. package/apps/studio/artboard-freeze.ts +108 -0
  27. package/apps/studio/artboard-live-gate.tsx +636 -0
  28. package/apps/studio/artboard-live.ts +831 -0
  29. package/apps/studio/artboard-placeholder.ts +197 -0
  30. package/apps/studio/artboard-still-raster.ts +485 -0
  31. package/apps/studio/artboard-still-warmup.ts +221 -0
  32. package/apps/studio/artboard-still.ts +1188 -0
  33. package/apps/studio/artboard-webgl.ts +669 -0
  34. package/apps/studio/asset-placeholder.tsx +237 -132
  35. package/apps/studio/asset-upload-bars.tsx +4 -4
  36. package/apps/studio/bin/_agent-browser-bin.mjs +8 -0
  37. package/apps/studio/bin/_agent-browser-safe.mjs +2 -1
  38. package/apps/studio/bin/_canvas-reasons.mjs +34 -0
  39. package/apps/studio/bin/_ds-check-live.mjs +37 -0
  40. package/apps/studio/bin/_ds-check.mjs +4 -1
  41. package/apps/studio/bin/_ds-prove-judge.mjs +167 -0
  42. package/apps/studio/bin/_ds-prove-playwright.mjs +183 -105
  43. package/apps/studio/bin/_import-asset.mjs +2 -1
  44. package/apps/studio/bin/_perf-probe-open.mjs +364 -0
  45. package/apps/studio/bin/_perf-probe.mjs +2 -1
  46. package/apps/studio/bin/_perf-shared.mjs +12 -7
  47. package/apps/studio/bin/_pw-launch.mjs +26 -1
  48. package/apps/studio/bin/_studio-verb.mjs +24 -3
  49. package/apps/studio/bin/_thumb-blank.mjs +70 -0
  50. package/apps/studio/bin/_thumb-cover.mjs +35 -0
  51. package/apps/studio/bin/_thumbs-playwright.mjs +89 -12
  52. package/apps/studio/bin/ds-check.sh +5 -1
  53. package/apps/studio/bin/perf.sh +30 -1
  54. package/apps/studio/bin/server-up.sh +7 -2
  55. package/apps/studio/bin/smoke.sh +19 -0
  56. package/apps/studio/bridge/dgn-protocol.ts +35 -0
  57. package/apps/studio/canvas-build-sandbox.ts +69 -13
  58. package/apps/studio/canvas-camera.ts +90 -0
  59. package/apps/studio/canvas-comment-mount.tsx +9 -9
  60. package/apps/studio/canvas-lib.tsx +289 -44
  61. package/apps/studio/canvas-pages-view.tsx +465 -0
  62. package/apps/studio/canvas-pages.ts +305 -0
  63. package/apps/studio/canvas-rows.ts +62 -0
  64. package/apps/studio/canvas-shell.tsx +62 -16
  65. package/apps/studio/canvas-theme-icons.tsx +41 -0
  66. package/apps/studio/canvas-theme-pill.tsx +15 -6
  67. package/apps/studio/canvas-theme.ts +12 -11
  68. package/apps/studio/client/app.jsx +7 -0
  69. package/apps/studio/client/canvas-url.js +36 -1
  70. package/apps/studio/client/home/HomeAccounts.jsx +262 -0
  71. package/apps/studio/client/home/Shelves.jsx +4 -3
  72. package/apps/studio/client/home/home-accounts-model.js +121 -0
  73. package/apps/studio/client/home/home-api.js +6 -0
  74. package/apps/studio/client/home/home-app.jsx +141 -40
  75. package/apps/studio/client/home/home-model.js +172 -6
  76. package/apps/studio/client/home/home.css +169 -5
  77. package/apps/studio/client/home/shell-mode.js +8 -1
  78. package/apps/studio/client/hooks/canvas-origin-probe.js +34 -0
  79. package/apps/studio/client/hooks/use-action-keys.jsx +3 -1
  80. package/apps/studio/client/hooks/use-canvas-bridge.jsx +1 -1
  81. package/apps/studio/client/hooks/use-palette-and-panels.jsx +23 -6
  82. package/apps/studio/client/hooks/use-photo-and-timeline.jsx +16 -8
  83. package/apps/studio/client/hooks/use-project-data.jsx +13 -2
  84. package/apps/studio/client/hooks/use-shell-core.jsx +19 -9
  85. package/apps/studio/client/index-loader.ts +41 -21
  86. package/apps/studio/client/inspector/inspector-panel.jsx +35 -14
  87. package/apps/studio/client/panels/ChatPanel.jsx +27 -20
  88. package/apps/studio/client/panels/CreateProject.jsx +19 -5
  89. package/apps/studio/client/panels/caps-cache.js +46 -0
  90. package/apps/studio/client/shell/viewport.jsx +66 -22
  91. package/apps/studio/client/tree/tree.jsx +17 -0
  92. package/apps/studio/client/v2/access/access-client.js +2 -0
  93. package/apps/studio/client/v2/access/access-host.jsx +12 -1
  94. package/apps/studio/client/v2/access/trashed-banner.jsx +6 -3
  95. package/apps/studio/client/v2/ai/Advanced.jsx +12 -0
  96. package/apps/studio/client/v2/ai/Composer.jsx +27 -10
  97. package/apps/studio/client/v2/canvases/canvases-panel.jsx +24 -0
  98. package/apps/studio/client/v2/canvases/use-canvas-index.js +24 -1
  99. package/apps/studio/client/v2/code/canvas-error-card.jsx +14 -2
  100. package/apps/studio/client/v2/code/canvas-imports-card.jsx +19 -14
  101. package/apps/studio/client/v2/code/canvas-imports-words.js +60 -0
  102. package/apps/studio/client/v2/code/canvas-waiting-card.jsx +59 -5
  103. package/apps/studio/client/v2/code/canvas-waiting.js +18 -1
  104. package/apps/studio/client/v2/code/code-bus.js +5 -0
  105. package/apps/studio/client/v2/code/code-consent-sheet.jsx +87 -0
  106. package/apps/studio/client/v2/code/code-consent.js +67 -0
  107. package/apps/studio/client/v2/diagnostics/sync-details/sync-details-model.js +62 -10
  108. package/apps/studio/client/v2/diagnostics/sync-details/sync-details.jsx +314 -5
  109. package/apps/studio/client/v2/ds/advanced-host.jsx +11 -26
  110. package/apps/studio/client/v2/ds/ds-refresh.js +161 -0
  111. package/apps/studio/client/v2/ds/library-host.jsx +45 -45
  112. package/apps/studio/client/v2/ds/make-host.jsx +13 -15
  113. package/apps/studio/client/v2/ds/off-system-host.jsx +18 -19
  114. package/apps/studio/client/v2/ds/review-host.jsx +7 -1
  115. package/apps/studio/client/v2/ds/truth-host.jsx +15 -17
  116. package/apps/studio/client/v2/ds/upgrade-host.jsx +26 -10
  117. package/apps/studio/client/v2/history/branch-actions.js +13 -9
  118. package/apps/studio/client/v2/history/git-advanced.jsx +8 -1
  119. package/apps/studio/client/v2/history/git-model.js +3 -1
  120. package/apps/studio/client/v2/history/git-parts.jsx +16 -1
  121. package/apps/studio/client/v2/layers/artboard-layers.jsx +24 -5
  122. package/apps/studio/client/v2/layers/layers-request.js +49 -0
  123. package/apps/studio/client/v2/left-panel/canvases-pinned.jsx +93 -3
  124. package/apps/studio/client/v2/left-panel/ds-boards.js +39 -0
  125. package/apps/studio/client/v2/left-panel/left-panel-model.js +13 -0
  126. package/apps/studio/client/v2/left-panel/left-panel.css +24 -0
  127. package/apps/studio/client/v2/presence/faces.jsx +42 -14
  128. package/apps/studio/client/v2/shell/account-card.jsx +10 -4
  129. package/apps/studio/client/v2/shell/canvas-crash-guard.js +172 -0
  130. package/apps/studio/client/v2/shell/canvas-mode.js +17 -1
  131. package/apps/studio/client/v2/shell/floating-panels.css +37 -1
  132. package/apps/studio/client/v2/shell/github-signin-host.jsx +42 -0
  133. package/apps/studio/client/v2/shell/menu-runner.js +11 -0
  134. package/apps/studio/client/v2/shell/mode-switch.jsx +14 -3
  135. package/apps/studio/client/v2/shell/opening-skeleton.js +118 -0
  136. package/apps/studio/client/v2/shell/opening-skeleton.jsx +103 -0
  137. package/apps/studio/client/v2/shell/pages-pick.js +49 -0
  138. package/apps/studio/client/v2/shell/project-account-card.jsx +203 -0
  139. package/apps/studio/client/v2/shell/project-account-model.js +182 -0
  140. package/apps/studio/client/v2/shell/project-menu-model.js +3 -0
  141. package/apps/studio/client/v2/shell/share-cluster-host.jsx +140 -11
  142. package/apps/studio/client/v2/shell/share-cluster.css +58 -0
  143. package/apps/studio/client/v2/shell/share-cluster.jsx +26 -7
  144. package/apps/studio/client/v2/shell/shell-parity.json +8 -0
  145. package/apps/studio/client/v2/shell/team-switch.js +94 -0
  146. package/apps/studio/client/v2/shell/too-heavy-card.jsx +38 -0
  147. package/apps/studio/client/v2/shell/use-account.js +8 -1
  148. package/apps/studio/client/v2/shell/use-canvas-mode-lane.js +30 -0
  149. package/apps/studio/collab/persistence.ts +9 -1
  150. package/apps/studio/collab/registry.ts +32 -0
  151. package/apps/studio/collab/room.ts +8 -0
  152. package/apps/studio/comments-overlay.tsx +12 -11
  153. package/apps/studio/config-reload-wire.ts +56 -0
  154. package/apps/studio/config.schema.json +6 -0
  155. package/apps/studio/context.ts +37 -1
  156. package/apps/studio/dist/client.bundle.js +1198 -1198
  157. package/apps/studio/dist/comment-mount.js +2 -2
  158. package/apps/studio/dist/styles.css +1 -1
  159. package/apps/studio/ds/board/board.css +6 -0
  160. package/apps/studio/ds/board/ds-bar.tsx +21 -3
  161. package/apps/studio/ds/board/specimen.tsx +16 -2
  162. package/apps/studio/ds/board/template.ts +39 -19
  163. package/apps/studio/ds/canvas-cli.ts +58 -2
  164. package/apps/studio/ds/check.ts +26 -1
  165. package/apps/studio/ds/cli.ts +14 -4
  166. package/apps/studio/ds/component-list.ts +2 -1
  167. package/apps/studio/ds/convert.ts +34 -6
  168. package/apps/studio/ds/default.ts +6 -1
  169. package/apps/studio/ds/ds-resolver.ts +58 -8
  170. package/apps/studio/ds/ds-verb.ts +13 -0
  171. package/apps/studio/ds/engine.ts +3 -1
  172. package/apps/studio/ds/folder-systems.ts +199 -0
  173. package/apps/studio/ds/pairing-css.ts +2 -1
  174. package/apps/studio/ds/post-build.ts +38 -0
  175. package/apps/studio/ds/rename.ts +10 -3
  176. package/apps/studio/ds/shell-fallbacks.ts +2 -1
  177. package/apps/studio/ds/upgrade-apply.ts +27 -5
  178. package/apps/studio/ds/upgrade-cli.ts +22 -2
  179. package/apps/studio/ds/upgrade-prove.ts +198 -15
  180. package/apps/studio/ds/upgrade-stage.ts +10 -3
  181. package/apps/studio/editing/ai-point-ring.tsx +4 -4
  182. package/apps/studio/editing/ai-scope-outline.tsx +4 -4
  183. package/apps/studio/editing/align-bar.tsx +4 -4
  184. package/apps/studio/editing/anchor-report.ts +3 -2
  185. package/apps/studio/editing/artboard-handles.tsx +4 -4
  186. package/apps/studio/editing/corner-dots.tsx +4 -4
  187. package/apps/studio/editing/crop-mode.tsx +4 -4
  188. package/apps/studio/editing/drop-chip.tsx +4 -4
  189. package/apps/studio/editing/empty-report.ts +3 -2
  190. package/apps/studio/editing/focus-model.tsx +4 -4
  191. package/apps/studio/editing/gap-bands.tsx +3 -3
  192. package/apps/studio/editing/hold-rings.tsx +4 -4
  193. package/apps/studio/editing/lock-badge.tsx +3 -3
  194. package/apps/studio/editing/long-page.ts +23 -1
  195. package/apps/studio/editing/nudge.tsx +2 -2
  196. package/apps/studio/editing/page-activity.ts +4 -3
  197. package/apps/studio/editing/paste-bar.tsx +4 -4
  198. package/apps/studio/editing/pen/overlay.tsx +4 -3
  199. package/apps/studio/editing/place-freely.tsx +3 -3
  200. package/apps/studio/editing/reorder-slot.tsx +3 -3
  201. package/apps/studio/editing/selection.tsx +4 -4
  202. package/apps/studio/editing/size-ghost.tsx +4 -4
  203. package/apps/studio/editing/tab-order.tsx +4 -4
  204. package/apps/studio/editing/text-in-place.tsx +4 -4
  205. package/apps/studio/editing/undo-preview.tsx +3 -3
  206. package/apps/studio/equal-spacing-handles.tsx +3 -3
  207. package/apps/studio/frame-clock.ts +89 -0
  208. package/apps/studio/history/trash.ts +6 -0
  209. package/apps/studio/home/accounts.ts +87 -0
  210. package/apps/studio/home/index-reader.ts +24 -2
  211. package/apps/studio/home/routes.ts +19 -0
  212. package/apps/studio/http.ts +80 -34
  213. package/apps/studio/index/ds-usage.ts +4 -1
  214. package/apps/studio/index-cache.ts +272 -0
  215. package/apps/studio/inspect-overlay.tsx +4 -3
  216. package/apps/studio/inspect.ts +7 -2
  217. package/apps/studio/link-chip-overlay.tsx +4 -3
  218. package/apps/studio/measure-overlay.tsx +4 -3
  219. package/apps/studio/present/pointer-dot.tsx +3 -2
  220. package/apps/studio/present/present-media.ts +6 -2
  221. package/apps/studio/present/present-stage.tsx +3 -2
  222. package/apps/studio/preview/preview-camera.tsx +3 -2
  223. package/apps/studio/routes/ds-convert.ts +18 -0
  224. package/apps/studio/routes/sync.ts +176 -0
  225. package/apps/studio/routes/trash.ts +16 -1
  226. package/apps/studio/safe-zones-overlay.tsx +3 -2
  227. package/apps/studio/server.ts +8 -10
  228. package/apps/studio/skip-dirs.ts +103 -47
  229. package/apps/studio/studio-page-host.ts +70 -0
  230. package/apps/studio/sync/accepted-cold-start.ts +28 -13
  231. package/apps/studio/sync/asset-push.ts +146 -23
  232. package/apps/studio/sync/asset-state.ts +3 -2
  233. package/apps/studio/sync/code-module-consent.ts +86 -0
  234. package/apps/studio/sync/file-ledger.ts +24 -0
  235. package/apps/studio/sync/file-membership.ts +28 -3
  236. package/apps/studio/sync/file-plane.ts +497 -61
  237. package/apps/studio/sync/file-pull.ts +304 -33
  238. package/apps/studio/sync/held-deletes.ts +230 -0
  239. package/apps/studio/sync/hub-link.ts +1 -2
  240. package/apps/studio/sync/hubs-config.ts +59 -2
  241. package/apps/studio/sync/index.ts +405 -163
  242. package/apps/studio/sync/journal-client.ts +94 -5
  243. package/apps/studio/sync/pending-deletes.ts +100 -0
  244. package/apps/studio/sync/projection.ts +77 -12
  245. package/apps/studio/sync/seed-progress.ts +104 -3
  246. package/apps/studio/sync/settings.ts +36 -1
  247. package/apps/studio/sync/status.ts +17 -1
  248. package/apps/studio/sync/writer-registry.ts +5 -0
  249. package/apps/studio/text-caret.ts +5 -3
  250. package/apps/studio/thumbs/service.ts +12 -2
  251. package/apps/studio/thumbs/validate.ts +7 -0
  252. package/apps/studio/toolbars/toolbar-rect.ts +3 -2
  253. package/apps/studio/ui-prefs-migrate.ts +4 -0
  254. package/apps/studio/use-annotation-resize.tsx +4 -3
  255. package/apps/studio/use-artboard-drag.tsx +3 -2
  256. package/apps/studio/use-element-resize.tsx +7 -6
  257. package/apps/studio/use-grid-track-handles.tsx +5 -4
  258. package/apps/studio/use-selection-set.tsx +64 -4
  259. package/apps/studio/use-spacing-handles.tsx +7 -6
  260. package/apps/studio/video-comp.tsx +75 -39
  261. package/apps/studio/video-play-overlay.tsx +4 -3
  262. package/apps/studio/whats-new.json +99 -0
  263. package/cli/commands/design.mjs +5 -2
  264. package/cli/commands/hub.mjs +10 -1
  265. package/cli/lib/bash-guard.mjs +27 -1
  266. package/cli/lib/design-help.gen.mjs +1 -1
  267. package/cli/lib/design-hook.mjs +20 -0
  268. package/cli/lib/design-link.mjs +42 -17
  269. package/cli/lib/hub-purge.mjs +183 -0
  270. package/cli/lib/studio-locate.mjs +35 -10
  271. package/package.json +8 -8
  272. package/plugins/design/templates/_shell.html +164 -1
@@ -0,0 +1,197 @@
1
+ /**
2
+ * @file artboard-placeholder.ts — 2.0.7: what an artboard shows while its children are not mounted
3
+ * @scope apps/studio/artboard-placeholder.ts (React-free; drawn by artboard-live-gate.tsx)
4
+ * @purpose An artboard that is not mounted yet, or was released because it is far away, used to show the
5
+ * bare frame — `var(--bg-0)`, which on a dark design system is a black box (Michal, 2.0.7). It now
6
+ * shows a placeholder of the same size in the artboard's OWN colours:
7
+ *
8
+ * - `picture` — it has rendered before (this session): its background and a few of its biggest
9
+ * blocks (their rectangles and colours, pictures as a muted tone), a cheap still of what was there;
10
+ * - `skeleton` — it has never rendered: its `background` prop, else the background the canvas's other
11
+ * artboards turned out to have, else the frame's own.
12
+ *
13
+ * The picture lives only in this canvas document's memory: never on disk and never in the canvas
14
+ * origin's storage, which every canvas on that origin can read (C4's named gap) — a canvas must not
15
+ * learn another canvas's layout from it.
16
+ */
17
+
18
+ export interface PictureBlock {
19
+ /** left, top, width, height — fractions of the artboard body */
20
+ x: number;
21
+ y: number;
22
+ w: number;
23
+ h: number;
24
+ /** a CSS colour; '' = a picture / media, drawn in a muted tone */
25
+ c: string;
26
+ }
27
+
28
+ export interface ArtboardPicture {
29
+ bg: string;
30
+ blocks: PictureBlock[];
31
+ /** the body's height when it was taken (px) — the placeholder holds it */
32
+ h: number;
33
+ }
34
+
35
+ export type PlaceholderKind = 'picture' | 'skeleton';
36
+
37
+ /** At most this many blocks per picture, and this many elements walked to find them. */
38
+ export const PICTURE_MAX_BLOCKS = 24;
39
+ export const PICTURE_MAX_WALK = 400;
40
+ /** A block smaller than this share of the body is detail, not structure. */
41
+ export const PICTURE_MIN_AREA = 0.004;
42
+
43
+ const pictures = new Map<string, ArtboardPicture>();
44
+ const backgrounds = new Map<string, string>();
45
+ let canvasBg = '';
46
+ const canvasBgSubs = new Set<() => void>();
47
+
48
+ /** The background this canvas's artboards turned out to have ('' until one has mounted). */
49
+ export function canvasBackground(): string {
50
+ return canvasBg;
51
+ }
52
+
53
+ /**
54
+ * Told once, when the canvas colour first becomes known: the skeletons drawn before any artboard rendered took the
55
+ * mid tone and repaint in it. Later colours do not repaint every placeholder again (new ones take the latest).
56
+ */
57
+ export function subscribeCanvasBackground(fn: () => void): () => void {
58
+ canvasBgSubs.add(fn);
59
+ return () => {
60
+ canvasBgSubs.delete(fn);
61
+ };
62
+ }
63
+
64
+ function setCanvasBg(bg: string): void {
65
+ if (!bg) return;
66
+ const first = !canvasBg;
67
+ canvasBg = bg;
68
+ if (first) for (const fn of [...canvasBgSubs]) fn();
69
+ }
70
+
71
+ /**
72
+ * Nothing known yet (the first frames of an open): a soft mid tone over the frame's own colour — on a dark
73
+ * design system the bare `var(--bg-0)` is the black box this replaces.
74
+ */
75
+ export const UNKNOWN_BG = 'color-mix(in oklab, var(--bg-0, #ffffff) 55%, #9a9a9a)';
76
+
77
+ /** Test hook. */
78
+ export function resetPictures(): void {
79
+ pictures.clear();
80
+ backgrounds.clear();
81
+ canvasBg = '';
82
+ }
83
+
84
+ export function pictureOf(id: string): ArtboardPicture | undefined {
85
+ return pictures.get(id);
86
+ }
87
+
88
+ export function rememberPicture(id: string, pic: ArtboardPicture): void {
89
+ pictures.set(id, pic);
90
+ setCanvasBg(pic.bg);
91
+ }
92
+
93
+ /** Transparent, or a colour the frame would show through. */
94
+ export function isClear(c: string | null | undefined): boolean {
95
+ if (!c) return true;
96
+ const v = c.replace(/\s+/g, '').toLowerCase();
97
+ return (
98
+ v === 'transparent' ||
99
+ v === 'none' ||
100
+ v === 'rgba(0,0,0,0)' ||
101
+ /^rgba\([^)]*,0(\.0+)?\)$/.test(v) ||
102
+ /\/0(\.0+)?\)$/.test(v)
103
+ );
104
+ }
105
+
106
+ /**
107
+ * Which placeholder, in which colour. `background` is the artboard's own prop (a token or a colour); a
108
+ * remembered picture wins over it because it is what the artboard actually looked like.
109
+ */
110
+ export function choosePlaceholder(
111
+ id: string,
112
+ background?: string
113
+ ): { kind: PlaceholderKind; bg: string; picture?: ArtboardPicture } {
114
+ const pic = pictures.get(id);
115
+ const own = backgrounds.get(id);
116
+ if (pic)
117
+ return {
118
+ kind: 'picture',
119
+ bg: pic.bg || own || background || canvasBg || UNKNOWN_BG,
120
+ picture: pic,
121
+ };
122
+ return { kind: 'skeleton', bg: own || background || canvasBg || UNKNOWN_BG };
123
+ }
124
+
125
+ const MEDIA = new Set(['IMG', 'PICTURE', 'VIDEO', 'CANVAS', 'svg', 'SVG', 'IFRAME']);
126
+
127
+ /**
128
+ * The colour an artboard body shows: its own background, else that of the first element covering most of it
129
+ * (a transparent body usually wraps a full-size `.root`). '' when it has none. Cheap — at most four elements.
130
+ */
131
+ export function backgroundOf(
132
+ body: HTMLElement,
133
+ br: DOMRect = body.getBoundingClientRect()
134
+ ): string {
135
+ const area = br.width * br.height;
136
+ let bg = getComputedStyle(body).backgroundColor;
137
+ let probe: Element | null = body;
138
+ for (let depth = 0; isClear(bg) && probe && depth < 4; depth++) {
139
+ probe = probe.firstElementChild;
140
+ if (!probe) break;
141
+ const r = probe.getBoundingClientRect();
142
+ if (area > 0 && r.width * r.height < area * 0.6) break;
143
+ bg = getComputedStyle(probe).backgroundColor;
144
+ }
145
+ return isClear(bg) ? '' : bg;
146
+ }
147
+
148
+ /**
149
+ * The own colour this artboard is known to have ('' when nothing is known yet): its measured background, else its
150
+ * `background` prop, else the canvas's. The frame takes it (`--dc-own-bg`), so an unpainted body or an unpainted
151
+ * WebKit tile shows the artboard's colour, never `var(--bg-0)` (a black square on a dark design system).
152
+ */
153
+ export function knownBackground(id: string, background?: string): string {
154
+ return backgrounds.get(id) || background || canvasBg || '';
155
+ }
156
+
157
+ /** An artboard's colour as soon as it mounts (its picture comes later): its own skeleton and the canvas guess. */
158
+ export function rememberBackground(id: string, bg: string): void {
159
+ if (!bg) return;
160
+ backgrounds.set(id, bg);
161
+ setCanvasBg(bg);
162
+ }
163
+
164
+ /**
165
+ * Take the picture of a mounted artboard body: its background (the body's, else the first element covering
166
+ * most of it) and its biggest coloured / media blocks. Bounded (`PICTURE_MAX_WALK` elements), read-only.
167
+ */
168
+ export function takePicture(body: HTMLElement): ArtboardPicture | null {
169
+ const br = body.getBoundingClientRect();
170
+ if (br.width < 2 || br.height < 2) return null;
171
+ const area = br.width * br.height;
172
+ const cs = (el: Element) => getComputedStyle(el);
173
+ const bg = backgroundOf(body, br) || '';
174
+ const blocks: PictureBlock[] = [];
175
+ const queue: Element[] = [...body.children];
176
+ let walked = 0;
177
+ while (queue.length && walked < PICTURE_MAX_WALK && blocks.length < PICTURE_MAX_BLOCKS) {
178
+ const el = queue.shift() as Element;
179
+ walked += 1;
180
+ const r = el.getBoundingClientRect();
181
+ const share = (r.width * r.height) / area;
182
+ if (share < PICTURE_MIN_AREA) continue;
183
+ const media = MEDIA.has(el.tagName);
184
+ const c = media ? '' : cs(el).backgroundColor;
185
+ if (media || (!isClear(c) && c !== bg && share < 0.9)) {
186
+ blocks.push({
187
+ x: (r.left - br.left) / br.width,
188
+ y: (r.top - br.top) / br.height,
189
+ w: r.width / br.width,
190
+ h: r.height / br.height,
191
+ c: media ? '' : c,
192
+ });
193
+ }
194
+ if (!media) for (const ch of el.children) queue.push(ch);
195
+ }
196
+ return { bg, blocks, h: body.offsetHeight };
197
+ }
@@ -0,0 +1,485 @@
1
+ /**
2
+ * @file artboard-still-raster.ts — 2.0.7: draw a still picture of a mounted artboard body into a `<canvas>`
3
+ * @scope apps/studio/artboard-still-raster.ts (DOM + canvas 2D; used by artboard-still.ts via the live gate)
4
+ * @purpose WebKit has no way to turn DOM into a bitmap (no `element()`, and an SVG `<foreignObject>` image of a
5
+ * real artboard drew blank into a canvas in Safari, measured 2026-11-06). This draws the body from its
6
+ * own geometry, in document order: boxes (background, border, radius), pictures and canvases (drawn
7
+ * as they are), each inline `<svg>` (serialized on its own with the rules its classes use and the
8
+ * defs it references — an SVG image draws reliably) and text as lines in its colour. At the size it
9
+ * stands in (under ~200 screen px) that reads as the artboard.
10
+ *
11
+ * In slices (`startStill`): the walk a few nodes at a time, then the pictures decode off the main
12
+ * thread, then the paint a few operations at a time — so a drawing fits in a pan's frames.
13
+ *
14
+ * Read-only and bounded (`RASTER_MAX_NODES`). Same-origin pictures only (the canvas origin's assets):
15
+ * a picture that would taint the canvas is skipped, never fetched.
16
+ */
17
+
18
+ import { STILL_MAX_SCREEN_PX } from './artboard-still.ts';
19
+
20
+ /** Walk at most this many nodes of one body. */
21
+ export const RASTER_MAX_NODES = 4000;
22
+ /** The still's width in device px: 1.5 × the threshold at the device pixel ratio (≤ 2) — sharp up to that zoom-in. */
23
+ export function stillWidthPx(dpr: number): number {
24
+ return Math.ceil(STILL_MAX_SCREEN_PX * Math.min(2, Math.max(1, dpr || 1)) * 1.5);
25
+ }
26
+ /** And never taller than this (a long page artboard). */
27
+ export const RASTER_MAX_HEIGHT_PX = 1600;
28
+
29
+ const clear = (c: string | null | undefined): boolean =>
30
+ !c || c === 'transparent' || /rgba\([^)]*,\s*0\)$/.test(c) || /\/\s*0\)$/.test(c);
31
+
32
+ type Op =
33
+ | {
34
+ k: 'box';
35
+ x: number;
36
+ y: number;
37
+ w: number;
38
+ h: number;
39
+ r: number;
40
+ bg: string;
41
+ bw: number;
42
+ bc: string;
43
+ a: number;
44
+ }
45
+ | { k: 'draw'; el: CanvasImageSource; x: number; y: number; w: number; h: number; a: number }
46
+ | {
47
+ k: 'svg';
48
+ src: string;
49
+ x: number;
50
+ y: number;
51
+ w: number;
52
+ h: number;
53
+ a: number;
54
+ img?: HTMLImageElement | null;
55
+ }
56
+ | { k: 'text'; rects: Array<[number, number, number, number]>; color: string; a: number };
57
+
58
+ let rulesCache: { at: number; rules: CSSStyleRule[] } | null = null;
59
+
60
+ function styleRules(doc: Document): CSSStyleRule[] {
61
+ // the stylesheets of a canvas document change rarely; re-read them at most every few seconds
62
+ const now = Date.now();
63
+ if (rulesCache && now - rulesCache.at < 5000) return rulesCache.rules;
64
+ const rules: CSSStyleRule[] = [];
65
+ for (const sh of Array.from(doc.styleSheets)) {
66
+ let list: CSSRuleList | null = null;
67
+ try {
68
+ list = sh.cssRules;
69
+ } catch {
70
+ list = null; // a cross-origin sheet (web fonts)
71
+ }
72
+ if (!list) continue;
73
+ for (const r of Array.from(list))
74
+ if ((r as CSSStyleRule).selectorText) rules.push(r as CSSStyleRule);
75
+ }
76
+ rulesCache = { at: now, rules };
77
+ return rules;
78
+ }
79
+
80
+ /** The rules an SVG's classes use (its own `<style>` children serialize with it). */
81
+ function cssFor(svg: Element): string {
82
+ const cls = new Set<string>();
83
+ for (const e of [svg, ...Array.from(svg.querySelectorAll('[class]'))])
84
+ for (const c of (e.getAttribute('class') || '').split(/\s+/)) if (c) cls.add(c);
85
+ if (!cls.size) return '';
86
+ let out = '';
87
+ for (const r of styleRules(svg.ownerDocument)) {
88
+ const s = r.selectorText;
89
+ for (const c of cls)
90
+ if (s.includes(`.${c}`)) {
91
+ out += `${r.cssText}\n`;
92
+ break;
93
+ }
94
+ }
95
+ return out;
96
+ }
97
+
98
+ const URL_REF = /url\(["']?#([^)"']+)["']?\)/g;
99
+
100
+ /** Gradients, patterns, filters, symbols an SVG references from outside itself. */
101
+ function defsFor(svg: Element): string {
102
+ const ids = new Set<string>();
103
+ for (const e of [svg, ...Array.from(svg.querySelectorAll('*'))]) {
104
+ for (const at of ['fill', 'stroke', 'filter', 'mask', 'clip-path', 'style']) {
105
+ const v = e.getAttribute(at);
106
+ if (v) for (const m of v.matchAll(URL_REF)) ids.add(m[1] as string);
107
+ }
108
+ const h = e.getAttribute('href') || e.getAttribute('xlink:href');
109
+ if (h && h[0] === '#') ids.add(h.slice(1));
110
+ }
111
+ const ser = new XMLSerializer();
112
+ let out = '';
113
+ for (const id of ids) {
114
+ const d = svg.ownerDocument.getElementById(id);
115
+ if (d && !svg.contains(d)) out += ser.serializeToString(d);
116
+ }
117
+ return out;
118
+ }
119
+
120
+ function escCss(s: string): string {
121
+ return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
122
+ }
123
+
124
+ function svgSource(svg: SVGSVGElement, w: number, h: number): string {
125
+ const cl = svg.cloneNode(true) as SVGSVGElement;
126
+ cl.setAttribute('width', String(w));
127
+ cl.setAttribute('height', String(h));
128
+ cl.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
129
+ const color = getComputedStyle(svg).color;
130
+ const extra = `<style>svg{color:${color}}${escCss(cssFor(svg))}</style><defs>${defsFor(svg)}</defs>`;
131
+ return new XMLSerializer().serializeToString(cl).replace(/^<svg([^>]*)>/, (m) => m + extra);
132
+ }
133
+
134
+ function loadSvg(src: string): Promise<HTMLImageElement | null> {
135
+ return new Promise((resolve) => {
136
+ const url = URL.createObjectURL(new Blob([src], { type: 'image/svg+xml' }));
137
+ const im = new Image();
138
+ im.onload = () => {
139
+ URL.revokeObjectURL(url);
140
+ resolve(im);
141
+ };
142
+ im.onerror = () => {
143
+ URL.revokeObjectURL(url);
144
+ resolve(null);
145
+ };
146
+ im.src = url;
147
+ });
148
+ }
149
+
150
+ /**
151
+ * Collects a body's paint in document order, a few nodes at a time (`run(deadline)`), so one drawing never holds a
152
+ * frame (2.0.7 follow-up: drawings happen during a pan too). Coordinates are in the body's own CSS px — the body's
153
+ * rect and its screen scale are read again at every slice, so a pan or a zoom between two slices moves nothing.
154
+ * The children must stay in the render tree from the first slice to the last (the caller's walk state).
155
+ */
156
+ export class Collector {
157
+ readonly ops: Op[] = [];
158
+ walked = 0;
159
+ /** the body's size in its own CSS px (read at every slice) */
160
+ w = 0;
161
+ h = 0;
162
+ private stack: Node[] = [];
163
+ private started = false;
164
+ constructor(
165
+ private readonly body: HTMLElement,
166
+ /** the still's px per body px (svg pictures are serialized at the size they are drawn) */
167
+ private readonly pxPerLocal: (w: number) => number,
168
+ private readonly now: () => number = () => performance.now()
169
+ ) {}
170
+
171
+ get done(): boolean {
172
+ return this.started && (!this.stack.length || this.walked >= RASTER_MAX_NODES);
173
+ }
174
+
175
+ /** Walk until `deadline` (a `now()` value) or the end. Returns false when the body has no size. */
176
+ run(deadline = Number.POSITIVE_INFINITY): boolean {
177
+ const body = this.body;
178
+ const br = body.getBoundingClientRect();
179
+ if (br.width < 1 || br.height < 1) return false;
180
+ const k = br.width / (body.offsetWidth || br.width);
181
+ this.w = br.width / k;
182
+ this.h = br.height / k;
183
+ const s = this.pxPerLocal(this.w);
184
+ if (!this.started) {
185
+ this.started = true;
186
+ for (let i = body.childNodes.length - 1; i >= 0; i--)
187
+ this.stack.push(body.childNodes[i] as Node);
188
+ }
189
+ const stack = this.stack;
190
+ const ops = this.ops;
191
+ let n = 0;
192
+ while (stack.length && this.walked < RASTER_MAX_NODES) {
193
+ if ((++n & 7) === 0 && this.now() >= deadline) break;
194
+ const node = stack.pop() as Node;
195
+ this.walked += 1;
196
+ if (node.nodeType === 3) {
197
+ const t = node.textContent;
198
+ const el = node.parentElement;
199
+ if (!t?.trim() || !el) continue;
200
+ const cs = getComputedStyle(el);
201
+ if (cs.visibility === 'hidden' || clear(cs.color)) continue;
202
+ const rg = document.createRange();
203
+ rg.selectNodeContents(node);
204
+ const fs = Number.parseFloat(cs.fontSize) || 12;
205
+ const rects: Array<[number, number, number, number]> = [];
206
+ for (const r of Array.from(rg.getClientRects())) {
207
+ if (r.width < 0.2 * k) continue;
208
+ const rh = r.height / k;
209
+ const h = Math.max(0.6, Math.min(rh * 0.5, fs * 0.55));
210
+ rects.push([(r.left - br.left) / k, (r.top - br.top) / k + (rh - h) / 2, r.width / k, h]);
211
+ }
212
+ if (rects.length) ops.push({ k: 'text', rects, color: cs.color, a: 0.6 });
213
+ continue;
214
+ }
215
+ if (node.nodeType !== 1) continue;
216
+ const el = node as Element;
217
+ const r = el.getBoundingClientRect();
218
+ if (r.width < 0.3 * k || r.height < 0.3 * k) continue;
219
+ const cs = getComputedStyle(el);
220
+ if (cs.display === 'none' || cs.visibility === 'hidden' || cs.opacity === '0') continue;
221
+ const x = (r.left - br.left) / k;
222
+ const y = (r.top - br.top) / k;
223
+ const w = r.width / k;
224
+ const h = r.height / k;
225
+ const a = Math.max(0, Math.min(1, Number(cs.opacity) || 1));
226
+ if (el instanceof SVGElement) {
227
+ if (el.tagName.toLowerCase() === 'svg') {
228
+ const pw = Math.max(1, Math.round(w * s));
229
+ const ph = Math.max(1, Math.round(h * s));
230
+ ops.push({ k: 'svg', src: svgSource(el as SVGSVGElement, pw, ph), x, y, w, h, a });
231
+ }
232
+ continue; // an svg's children are drawn by its serialization
233
+ }
234
+ const bg = cs.backgroundColor;
235
+ const bw = Number.parseFloat(cs.borderTopWidth) || 0;
236
+ const bc = cs.borderTopColor;
237
+ if (!clear(bg) || (bw > 0 && !clear(bc))) {
238
+ const rad = Number.parseFloat(cs.borderTopLeftRadius) || 0;
239
+ ops.push({
240
+ k: 'box',
241
+ x,
242
+ y,
243
+ w,
244
+ h,
245
+ r: rad,
246
+ bg: clear(bg) ? '' : bg,
247
+ bw: clear(bc) ? 0 : bw,
248
+ bc,
249
+ a,
250
+ });
251
+ }
252
+ const tag = el.tagName;
253
+ if (tag === 'IMG') {
254
+ const im = el as HTMLImageElement;
255
+ // a picture still loading is drawn once it has (the drawing waits for it, bounded)
256
+ if (!(im.complete && im.naturalWidth === 0)) ops.push({ k: 'draw', el: im, x, y, w, h, a });
257
+ continue;
258
+ }
259
+ if (tag === 'CANVAS') {
260
+ ops.push({ k: 'draw', el: el as HTMLCanvasElement, x, y, w, h, a });
261
+ continue;
262
+ }
263
+ if (tag === 'VIDEO') {
264
+ const v = el as HTMLVideoElement;
265
+ if (v.readyState >= 2) ops.push({ k: 'draw', el: v, x, y, w, h, a });
266
+ continue;
267
+ }
268
+ if (tag === 'IFRAME' || tag === 'SCRIPT' || tag === 'STYLE') continue;
269
+ for (let i = el.childNodes.length - 1; i >= 0; i--) stack.push(el.childNodes[i] as Node);
270
+ }
271
+ return true;
272
+ }
273
+ }
274
+
275
+ /** Collect the body's paint at once (in the body's own CSS px). Exported for tests. */
276
+ export function collectOps(body: HTMLElement): { ops: Op[]; walked: number } {
277
+ const c = new Collector(body, (w) => stillWidthPx(dpr()) / (w || 1));
278
+ c.run();
279
+ return { ops: c.ops, walked: c.walked };
280
+ }
281
+
282
+ function roundRect(
283
+ g: CanvasRenderingContext2D,
284
+ x: number,
285
+ y: number,
286
+ w: number,
287
+ h: number,
288
+ r: number
289
+ ) {
290
+ const rr = Math.max(0, Math.min(r, w / 2, h / 2));
291
+ g.beginPath();
292
+ if (typeof g.roundRect === 'function') g.roundRect(x, y, w, h, rr);
293
+ else g.rect(x, y, w, h);
294
+ }
295
+
296
+ const dpr = () => (typeof devicePixelRatio === 'number' ? devicePixelRatio : 1);
297
+
298
+ /** The longest synchronous slice of each phase so far (ms) — diagnostics (`__maudeStillStats`). */
299
+ export const rasterTimings = { collectMax: 0, paintMax: 0, decodeWaitMax: 0 };
300
+
301
+ /**
302
+ * How long a drawing waits for its pictures to load and decode (ms). Decoding happens off the main thread
303
+ * (`HTMLImageElement.decode()`); a picture drawn cold decodes ON it — 6 ms median, 36 ms worst per picture on the
304
+ * mascot canvas in Safari, against 1–2 ms once decoded (measured 2026-11-07). A picture not in by then is left out.
305
+ */
306
+ export const RASTER_DECODE_WAIT_MS = 1500;
307
+
308
+ /** The body's children enter / leave the render tree for the walk (the controller's walk state). */
309
+ export interface WalkHooks {
310
+ enter(): void;
311
+ leave(): void;
312
+ }
313
+
314
+ /**
315
+ * One still being drawn, in slices: `step(deadline)` works until `deadline` and returns `more` (call again next
316
+ * frame), `wait` (pictures are decoding — call again once `ready` settles) or `done` (`result` holds the still, or
317
+ * null). The walk state is on from the first collect slice to the last, never across the decode wait or the paint.
318
+ */
319
+ export interface StillJob {
320
+ step(deadline: number): 'more' | 'wait' | 'done';
321
+ readonly ready: Promise<unknown> | null;
322
+ readonly result: HTMLElement | null;
323
+ /** which phase it is in (diagnostics, tests) */
324
+ readonly phase: 'collect' | 'decode' | 'paint' | 'done';
325
+ abort(): void;
326
+ }
327
+
328
+ function bounded(p: Promise<unknown>, ms: number): Promise<unknown> {
329
+ return Promise.race([p.catch(() => {}), new Promise((r) => setTimeout(r, ms))]);
330
+ }
331
+
332
+ /** Start drawing a still of a mounted artboard body. */
333
+ export function startStill(
334
+ body: HTMLElement,
335
+ walk: WalkHooks,
336
+ now: () => number = () => performance.now()
337
+ ): StillJob {
338
+ const wPx = stillWidthPx(dpr());
339
+ const collector = new Collector(body, (w) => wPx / (w || 1), now);
340
+ let phase: StillJob['phase'] = 'collect';
341
+ let ready: Promise<unknown> | null = null;
342
+ let decoded = false;
343
+ let result: HTMLCanvasElement | null = null;
344
+ let cv: HTMLCanvasElement | null = null;
345
+ let g: CanvasRenderingContext2D | null = null;
346
+ let i = 0;
347
+ let entered = false;
348
+ let base = '';
349
+ const leave = () => {
350
+ if (entered) walk.leave();
351
+ entered = false;
352
+ };
353
+ const finish = (r: HTMLCanvasElement | null) => {
354
+ leave();
355
+ result = r;
356
+ phase = 'done';
357
+ return 'done' as const;
358
+ };
359
+ const job: StillJob = {
360
+ get ready() {
361
+ return ready;
362
+ },
363
+ get result() {
364
+ return result;
365
+ },
366
+ get phase() {
367
+ return phase;
368
+ },
369
+ abort() {
370
+ leave();
371
+ phase = 'done';
372
+ },
373
+ step(deadline) {
374
+ if (phase === 'collect') {
375
+ if (!entered) {
376
+ walk.enter();
377
+ entered = true;
378
+ }
379
+ const t0 = now();
380
+ const ok = collector.run(deadline);
381
+ rasterTimings.collectMax = Math.max(rasterTimings.collectMax, now() - t0);
382
+ if (!ok) return finish(null);
383
+ if (!collector.done) return 'more';
384
+ // the body's colour, else the frame's (the article's own background): never a transparent hole
385
+ base = getComputedStyle(body).backgroundColor;
386
+ if (clear(base) && body.parentElement)
387
+ base = getComputedStyle(body.parentElement).backgroundColor;
388
+ leave();
389
+ phase = 'decode';
390
+ const waits: Promise<unknown>[] = [];
391
+ for (const op of collector.ops) {
392
+ if (op.k === 'svg') {
393
+ waits.push(
394
+ loadSvg(op.src).then(async (im) => {
395
+ op.img = im;
396
+ if (im) await im.decode().catch(() => {});
397
+ })
398
+ );
399
+ } else if (op.k === 'draw' && op.el instanceof HTMLImageElement) {
400
+ waits.push(op.el.decode().catch(() => {}));
401
+ }
402
+ }
403
+ const t1 = now();
404
+ ready = bounded(Promise.all(waits), RASTER_DECODE_WAIT_MS).then(() => {
405
+ decoded = true;
406
+ rasterTimings.decodeWaitMax = Math.max(rasterTimings.decodeWaitMax, now() - t1);
407
+ });
408
+ if (waits.length) return 'wait';
409
+ decoded = true;
410
+ return job.step(deadline);
411
+ }
412
+ if (phase === 'decode') {
413
+ if (!decoded) return 'wait';
414
+ phase = 'paint';
415
+ cv = document.createElement('canvas');
416
+ cv.width = wPx;
417
+ const lw = collector.w || 1;
418
+ const lh = collector.h || 1;
419
+ const s = wPx / lw;
420
+ cv.height = Math.max(1, Math.min(RASTER_MAX_HEIGHT_PX, Math.round(lh * s)));
421
+ g = cv.getContext('2d');
422
+ if (!g) return finish(null);
423
+ g.scale(s, cv.height / lh);
424
+ if (!clear(base)) {
425
+ g.fillStyle = base;
426
+ g.fillRect(0, 0, lw, lh);
427
+ }
428
+ }
429
+ if (phase === 'paint' && g && cv) {
430
+ const t0 = now();
431
+ const ops = collector.ops;
432
+ while (i < ops.length) {
433
+ if (i > 0 && (i & 3) === 0 && now() >= deadline) break;
434
+ const op = ops[i++] as Op;
435
+ g.globalAlpha = op.a;
436
+ try {
437
+ if (op.k === 'box') {
438
+ roundRect(g, op.x, op.y, op.w, op.h, op.r);
439
+ if (op.bg) {
440
+ g.fillStyle = op.bg;
441
+ g.fill();
442
+ }
443
+ if (op.bw > 0) {
444
+ g.strokeStyle = op.bc;
445
+ g.lineWidth = op.bw;
446
+ g.stroke();
447
+ }
448
+ } else if (op.k === 'draw') {
449
+ const im = op.el as HTMLImageElement;
450
+ if (!(im instanceof HTMLImageElement) || (im.complete && im.naturalWidth > 0))
451
+ g.drawImage(op.el, op.x, op.y, op.w, op.h);
452
+ } else if (op.k === 'svg') {
453
+ if (op.img) g.drawImage(op.img, op.x, op.y, op.w, op.h);
454
+ } else {
455
+ g.fillStyle = op.color;
456
+ for (const [x, y, w, h] of op.rects) g.fillRect(x, y, w, h);
457
+ }
458
+ } catch {
459
+ // a picture that cannot be drawn is left out
460
+ }
461
+ }
462
+ rasterTimings.paintMax = Math.max(rasterTimings.paintMax, now() - t0);
463
+ if (i < ops.length) return 'more';
464
+ g.globalAlpha = 1;
465
+ return finish(cv);
466
+ }
467
+ return phase === 'done' ? 'done' : 'more';
468
+ },
469
+ };
470
+ return job;
471
+ }
472
+
473
+ /**
474
+ * Draw a still of a mounted artboard body at once (no slicing; the body must be in the render tree). Resolves to a
475
+ * `<canvas>` (not yet in the document), or null when the body has no size.
476
+ */
477
+ export async function drawStill(body: HTMLElement): Promise<HTMLCanvasElement | null> {
478
+ const job = startStill(body, { enter() {}, leave() {} });
479
+ for (let n = 0; n < 1000; n++) {
480
+ const r = job.step(Number.POSITIVE_INFINITY);
481
+ if (r === 'done') return job.result as HTMLCanvasElement | null;
482
+ if (r === 'wait') await job.ready;
483
+ }
484
+ return null;
485
+ }