@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,305 @@
1
+ // The canvas's Canvas | Pages view (2.0.7 B2, decision `v2-207-pages-view`).
2
+ //
3
+ // Canvas is the infinite canvas. Pages shows ONE artboard at a time, filling the view, and pages through them in the
4
+ // canvas's order: the Present order when "Order and notes…" set one, else the layout order (rows, left to right —
5
+ // present/order.ts). Skipped artboards stay in: Pages is the designer's own view, not a presentation.
6
+ //
7
+ // the switch next to Light | Dark on the pill at the top of the canvas (canvas-theme-pill.tsx)
8
+ // the pick remembered per canvas, per Mac: `_canvas-state/<slug>.view.json` `canvasView` (DDR-115), never the
9
+ // versioned `.meta.json`. It reaches the iframe as `window.__canvas_meta__.canvasView` on load, like
10
+ // `canvasTheme` (canvas-theme.ts).
11
+ // the page which artboard is showing is this session's only (no write per step).
12
+ // the shell is told `pages-view` (bridge/dgn-protocol.ts) so Preview and Present are off while Pages is on;
13
+ // the shell drives the frame only through `run-action` (`view.pages`, `pages.next`, `pages.prev`).
14
+ //
15
+ // Pages applies only to the designer's own view in the studio window: Edit or Viewing, framed by the studio, not an
16
+ // embed, a Present follower or a past version. A headless capture (exports, `maude design screenshot`) loads the
17
+ // canvas as the top document, so it always renders the whole canvas.
18
+ //
19
+ // The store lives on `globalThis` for the reason canvas-theme.ts gives: a soft HMR re-evaluation must agree.
20
+
21
+ import { useSyncExternalStore } from 'react';
22
+ import type { Insets } from './bridge/occlusion.ts';
23
+ import { type OrderRect, type PresentMeta, presentRun } from './present/order.ts';
24
+ import { isEmbedCanvas, isFollowCanvas, isHistoricalCanvas } from './read-only-mode.ts';
25
+
26
+ export type CanvasView = 'canvas' | 'pages';
27
+
28
+ interface Store {
29
+ /** the pick made in this session; null = none (the saved one, else Canvas) */
30
+ chosen: CanvasView | null;
31
+ /** the artboard Pages shows, this session; null = the first */
32
+ at: string | null;
33
+ /** the artboards in page order, as the canvas last laid them out */
34
+ order: string[];
35
+ subs: Set<() => void>;
36
+ }
37
+
38
+ const KEY = '__maudeCanvasPages';
39
+
40
+ function store(): Store {
41
+ const g = globalThis as unknown as Record<string, Store | undefined>;
42
+ let s = g[KEY];
43
+ if (!s) {
44
+ s = { chosen: null, at: null, order: [], subs: new Set() };
45
+ g[KEY] = s;
46
+ }
47
+ return s;
48
+ }
49
+
50
+ const emit = (): void => {
51
+ for (const f of [...store().subs]) f();
52
+ };
53
+
54
+ interface MetaWindow {
55
+ __canvas_meta__?: { canvasView?: unknown; present?: PresentMeta };
56
+ __canvas_meta_file__?: string;
57
+ __maude_last_meta_self_write_at?: number;
58
+ }
59
+
60
+ const isView = (v: unknown): v is CanvasView => v === 'canvas' || v === 'pages';
61
+
62
+ function savedView(): CanvasView | null {
63
+ if (typeof window === 'undefined') return null;
64
+ const v = (window as unknown as MetaWindow).__canvas_meta__?.canvasView;
65
+ return isView(v) ? v : null;
66
+ }
67
+
68
+ /** The view this canvas is set to: this session's pick, else the saved one, else Canvas. */
69
+ export function getCanvasView(): CanvasView {
70
+ return store().chosen ?? savedView() ?? 'canvas';
71
+ }
72
+
73
+ /**
74
+ * Remember the pick for this canvas on this Mac. The canvas writes nothing itself (its origin may PATCH only `layout`
75
+ * and `viewport`): it tells the studio `pages-pick`, and the shell writes `canvasView` into the view file for the
76
+ * canvas it has open (client/v2/shell/pages-pick.js). Outside the studio window nothing is remembered.
77
+ */
78
+ function persist(view: CanvasView): void {
79
+ if (typeof window === 'undefined' || !persistsView() || !framedByStudio()) return;
80
+ const w = window as unknown as MetaWindow;
81
+ // keep the page-load snapshot current, so a soft remount reads the pick back (DDR-138)
82
+ if (w.__canvas_meta__ && typeof w.__canvas_meta__ === 'object')
83
+ w.__canvas_meta__.canvasView = view;
84
+ try {
85
+ window.parent.postMessage({ dgn: 'pages-pick', v: 1, view }, '*');
86
+ } catch {
87
+ /* detached */
88
+ }
89
+ }
90
+
91
+ /** An embed, a Present follower and a past version are not the designer's own view (read-only-mode.ts). */
92
+ function persistsView(): boolean {
93
+ return !isEmbedCanvas() && !isFollowCanvas() && !isHistoricalCanvas();
94
+ }
95
+
96
+ /** Switch the canvas to `view`. `persist: false` shows it without remembering it. */
97
+ export function setCanvasView(view: CanvasView, opts: { persist?: boolean } = {}): void {
98
+ if (!isView(view)) return;
99
+ const s = store();
100
+ const changed = getCanvasView() !== view;
101
+ s.chosen = view;
102
+ if (opts.persist !== false && changed) persist(view);
103
+ if (changed) emit();
104
+ }
105
+
106
+ export function subscribeCanvasView(f: () => void): () => void {
107
+ const subs = store().subs;
108
+ subs.add(f);
109
+ return () => {
110
+ subs.delete(f);
111
+ };
112
+ }
113
+
114
+ export const useCanvasView = (): CanvasView =>
115
+ useSyncExternalStore(subscribeCanvasView, getCanvasView, getCanvasView);
116
+
117
+ // ── the page order ─────────────────────────────────────────────────────────────────────────────
118
+
119
+ /** Every artboard in page order: the Present order (when set) over the layout order. Skipped ones stay in. */
120
+ export function pagesOrder(
121
+ rects: readonly OrderRect[],
122
+ present: PresentMeta | null | undefined
123
+ ): string[] {
124
+ const order =
125
+ present && typeof present === 'object' && !Array.isArray(present) ? present.order : undefined;
126
+ return presentRun(rects, { order }).run;
127
+ }
128
+
129
+ /** Where `at` sits in `order` (an id the canvas no longer has is the first page). */
130
+ export function pageIndex(order: readonly string[], at: string | null | undefined): number {
131
+ if (!at) return 0;
132
+ const i = order.indexOf(at);
133
+ return i < 0 ? 0 : i;
134
+ }
135
+
136
+ /** The page after / before `at`, held at the ends (no wrap: the counter says where you are). */
137
+ export function pageStep(
138
+ order: readonly string[],
139
+ at: string | null | undefined,
140
+ dir: 'next' | 'prev'
141
+ ): string | null {
142
+ if (order.length === 0) return null;
143
+ const i = pageIndex(order, at);
144
+ const j = dir === 'next' ? Math.min(order.length - 1, i + 1) : Math.max(0, i - 1);
145
+ return order[j];
146
+ }
147
+
148
+ /** What the counter says: `{ index, total, id }` (index 0-based), or null with no artboard. */
149
+ export function pagePosition(
150
+ order: readonly string[],
151
+ at: string | null | undefined
152
+ ): { index: number; total: number; id: string } | null {
153
+ if (order.length === 0) return null;
154
+ const index = pageIndex(order, at);
155
+ return { index, total: order.length, id: order[index] };
156
+ }
157
+
158
+ /** The live order and the page showing, as the canvas laid them out last (the pill and the keys read it). */
159
+ export function getPagesState(): { order: readonly string[]; at: string | null } {
160
+ const s = store();
161
+ return { order: s.order, at: s.order.length ? s.order[pageIndex(s.order, s.at)] : null };
162
+ }
163
+
164
+ /** The artboard this session asked Pages to show (null = none yet; may name one the canvas no longer has). */
165
+ export const getPageChosen = (): string | null => store().at;
166
+
167
+ /** The canvas reports its order (called by usePagesView on every layout change). */
168
+ export function setPagesOrder(order: readonly string[]): void {
169
+ const s = store();
170
+ if (s.order.length === order.length && s.order.every((id, i) => id === order[i])) return;
171
+ s.order = [...order];
172
+ emit();
173
+ }
174
+
175
+ /** Show artboard `id` (when Pages has it). */
176
+ export function setPageAt(id: string | null): void {
177
+ const s = store();
178
+ if (s.at === id) return;
179
+ s.at = id;
180
+ emit();
181
+ }
182
+
183
+ /** Next / Previous page. Returns true when Pages is on and there was somewhere to go. */
184
+ export function stepPage(dir: 'next' | 'prev'): boolean {
185
+ if (getCanvasView() !== 'pages') return false;
186
+ const { order, at } = getPagesState();
187
+ const to = pageStep(order, at, dir);
188
+ if (!to || to === at) return false;
189
+ setPageAt(to);
190
+ return true;
191
+ }
192
+
193
+ /** The pill's counter and buttons re-read on any change. */
194
+ let snapCache: { key: string; value: { index: number; total: number } | null } = {
195
+ key: '',
196
+ value: null,
197
+ };
198
+ function pageSnapshot(): { index: number; total: number } | null {
199
+ const { order, at } = getPagesState();
200
+ const p = pagePosition(order, at);
201
+ const key = p ? `${p.index}/${p.total}` : '';
202
+ if (snapCache.key !== key)
203
+ snapCache = { key, value: p ? { index: p.index, total: p.total } : null };
204
+ return snapCache.value;
205
+ }
206
+
207
+ export const usePagePosition = (): { index: number; total: number } | null =>
208
+ useSyncExternalStore(subscribeCanvasView, pageSnapshot, pageSnapshot);
209
+
210
+ // ── where Pages applies ────────────────────────────────────────────────────────────────────────
211
+
212
+ /** Is this the studio window's own view of the canvas? A capture loads the canvas as the top document. */
213
+ export function framedByStudio(): boolean {
214
+ if (typeof window === 'undefined') return false;
215
+ try {
216
+ return window.parent !== window;
217
+ } catch {
218
+ return false;
219
+ }
220
+ }
221
+
222
+ /**
223
+ * Does Pages show here? Only in Edit or Viewing (a free canvas has no shell mode: null), framed by the studio, and
224
+ * not an embed, a Present follower or a past version.
225
+ */
226
+ export function pagesApply(mode: string | null | undefined): boolean {
227
+ if (mode && mode !== 'edit' && mode !== 'viewing') return false;
228
+ return framedByStudio() && persistsView();
229
+ }
230
+
231
+ // ── the camera and the rule that leaves one artboard ───────────────────────────────────────────
232
+
233
+ /** The room the Light | Dark pill takes at the top of the canvas (16 px from the top, 44 px tall), plus a gap. */
234
+ export const PAGES_TOP_ROOM = 72;
235
+ /** The margin around the page on the other sides. */
236
+ export const PAGES_PAD = 32;
237
+ const ZOOM_MIN = 0.02;
238
+ const ZOOM_MAX = 4;
239
+
240
+ /**
241
+ * The camera that shows `rect` whole, as large as fits, centred in the visible part of a `w × h` host (the shell's
242
+ * floating panels occlude `insets`; the pill takes `top`). Pure.
243
+ */
244
+ export function pageCamera(
245
+ rect: { x: number; y: number; w: number; h: number },
246
+ host: { w: number; h: number },
247
+ insets: Readonly<Insets>,
248
+ opts: { pad?: number; top?: number } = {}
249
+ ): { x: number; y: number; zoom: number } {
250
+ const pad = opts.pad ?? PAGES_PAD;
251
+ const top = Math.max(insets.top, opts.top ?? PAGES_TOP_ROOM);
252
+ if (!(rect.w > 0) || !(rect.h > 0) || !(host.w > 0) || !(host.h > 0))
253
+ return { x: 0, y: 0, zoom: 1 };
254
+ let left = insets.left + pad;
255
+ let right = host.w - insets.right - pad;
256
+ let up = top;
257
+ let down = host.h - insets.bottom - pad;
258
+ // the panels leave too little room: fill the host instead of a sliver
259
+ if (right - left < 120) {
260
+ left = pad;
261
+ right = host.w - pad;
262
+ }
263
+ if (down - up < 120) {
264
+ up = pad;
265
+ down = host.h - pad;
266
+ }
267
+ const vw = Math.max(1, right - left);
268
+ const vh = Math.max(1, down - up);
269
+ const zoom = Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, Math.min(vw / rect.w, vh / rect.h)));
270
+ return {
271
+ x: left + (vw - rect.w * zoom) / 2 - rect.x * zoom,
272
+ y: up + (vh - rect.h * zoom) / 2 - rect.y * zoom,
273
+ zoom,
274
+ };
275
+ }
276
+
277
+ /** The attribute the rule keys on while Pages shows. */
278
+ export const PAGES_ATTR = 'data-maude-pages';
279
+ /** The style element that holds the rule. */
280
+ export const PAGES_STYLE_ID = 'dc-pages-css';
281
+
282
+ /** A CSS string literal for an artboard id (the id is the canvas's own, but never trusted as CSS). */
283
+ const cssString = (s: string): string =>
284
+ `"${s.replace(/[\\"]/g, (c) => `\\${c}`).replace(/[\n\r\f]/g, ' ')}"`;
285
+
286
+ /**
287
+ * Every artboard but `id` steps out of sight and out of reach. Off during a capture (`#maude-capture-chrome`,
288
+ * exporters/capture-chrome.ts), so an in-window export still sees every artboard.
289
+ */
290
+ export function pagesHideCss(id: string): string {
291
+ return `html[${PAGES_ATTR}]:not(:has(#maude-capture-chrome)) .dc-canvas .dc-artboard:not([data-dc-screen=${cssString(id)}]){visibility:hidden !important;pointer-events:none !important}`;
292
+ }
293
+
294
+ /** The pill's "2 / 6". */
295
+ export const pageCounter = (index: number, total: number): string => `${index + 1} / ${total}`;
296
+
297
+ /** test seam */
298
+ export function __resetCanvasPages(): void {
299
+ const s = store();
300
+ s.chosen = null;
301
+ s.at = null;
302
+ s.order = [];
303
+ snapCache = { key: '', value: null };
304
+ emit();
305
+ }
@@ -27,6 +27,18 @@ export interface RowRect {
27
27
  */
28
28
  export const ROW_GAP = 80;
29
29
 
30
+ /**
31
+ * The most artboards one generated row holds (2.0.7 fix #6). A converted system put every page of a
32
+ * section in ONE row — StudyFi's 29 component pages made a row 43 000 px wide, and the canvas fitted
33
+ * at 2 %. Six 1 440 px pages (8 880 px) keep a row about as wide as a few rows are tall, so the
34
+ * canvas reads as a grid. The generator wraps at this count (`ds/board/template.ts`), and the open
35
+ * canvas wraps an older generated grid the same way at run time (`wrapRows`).
36
+ */
37
+ export const MAX_ROW_COLUMNS = 6;
38
+
39
+ /** The column gap of a generated row when it has only one artboard to measure it from (`OWN_ARTBOARD.gap`). */
40
+ const DEFAULT_COLUMN_GAP = 48;
41
+
30
42
  /** A column gap wider than this is not a packed row — somebody placed the artboard there. */
31
43
  const MAX_COLUMN_GAP = 96;
32
44
 
@@ -93,6 +105,56 @@ export function isUntouchedRowGrid(rects: readonly RowRect[], declared?: Declare
93
105
  return true;
94
106
  }
95
107
 
108
+ /**
109
+ * Wrap every row of an untouched row grid that holds more than `maxCols` artboards onto rows below
110
+ * it, packed from the left edge at the row's own column gap, in the order they stood. Everything
111
+ * under a wrapped row moves down by the room the new rows take (`gap` between rows, each row as tall
112
+ * as its tallest artboard); rows above the first wrapped one keep their place. The row flow
113
+ * (`flowRows`) re-pitches the result from the measured heights as before. Run time only, like the
114
+ * flow: an older converted canvas reads as a grid without its versioned meta being rewritten on
115
+ * open. Returns the SAME array when no row is too long or the layout is not an untouched grid (a
116
+ * person's arrangement is never wrapped), so a caller can compare by identity.
117
+ */
118
+ export function wrapRows<T extends RowRect>(
119
+ rects: T[],
120
+ opts: { gap?: number; maxCols?: number; declared?: DeclaredSizes } = {}
121
+ ): T[] {
122
+ const gap = opts.gap ?? ROW_GAP;
123
+ const maxCols = Math.max(1, opts.maxCols ?? MAX_ROW_COLUMNS);
124
+ if (!isUntouchedRowGrid(rects, opts.declared)) return rects;
125
+ const rows = rowsOf(rects);
126
+ if (rows.every((row) => row.length <= maxCols)) return rects;
127
+ const left = Math.min(...rects.map((r) => r.x));
128
+ const tallest = (row: readonly T[]) => Math.max(...row.map((r) => r.h));
129
+ const next = new Map<string, { x: number; y: number }>();
130
+ let shift = 0;
131
+ for (const row of rows) {
132
+ const y = (row[0] as T).y + shift;
133
+ if (row.length <= maxCols) {
134
+ for (const r of row) next.set(r.id, { x: r.x, y });
135
+ continue;
136
+ }
137
+ const colGap =
138
+ row.length > 1 ? (row[1] as T).x - ((row[0] as T).x + (row[0] as T).w) : DEFAULT_COLUMN_GAP;
139
+ let cy = y;
140
+ for (let i = 0; i < row.length; i += maxCols) {
141
+ const chunk = row.slice(i, i + maxCols);
142
+ let cx = left;
143
+ for (const r of chunk) {
144
+ next.set(r.id, { x: cx, y: cy });
145
+ cx += r.w + colGap;
146
+ }
147
+ if (i + maxCols < row.length) cy += tallest(chunk) + gap;
148
+ }
149
+ const last = row.slice(Math.floor((row.length - 1) / maxCols) * maxCols);
150
+ shift += cy - y + tallest(last) - tallest(row);
151
+ }
152
+ return rects.map((r) => {
153
+ const p = next.get(r.id) as { x: number; y: number };
154
+ return p.x === r.x && p.y === r.y ? r : { ...r, x: p.x, y: p.y };
155
+ });
156
+ }
157
+
96
158
  /**
97
159
  * Re-pitch the rows of an untouched row grid from the artboards' heights: the first row keeps its
98
160
  * `y`, every row below starts `gap` under the TALLEST artboard of the row above. Columns (`x`) are
@@ -58,6 +58,14 @@ import {
58
58
  useViewportControllerContext,
59
59
  type ViewportControllerHandle,
60
60
  } from './canvas-lib.tsx';
61
+ import {
62
+ CanvasPagesSwitch,
63
+ PAGES_PILL_CSS,
64
+ pickTurnsPage,
65
+ runPagesAction,
66
+ turnToPage,
67
+ usePagesView,
68
+ } from './canvas-pages-view.tsx';
61
69
  import { replayActionKey, replayToolKey } from './canvas-replay-keys.ts';
62
70
  import { getCanvasTheme, subscribeCanvasTheme } from './canvas-theme.ts';
63
71
  import { CanvasThemePill } from './canvas-theme-pill.tsx';
@@ -111,6 +119,7 @@ import { isLockedDom, lockedClickSelection, stepOut } from './editing/selection.
111
119
  import { commitTextInPlace, lockedTextLine, textOpDeps } from './editing/text-actions.ts';
112
120
  import { worldMenuSections } from './editing/world-menu.ts';
113
121
  import { EqualSpacingHandles } from './equal-spacing-handles.tsx';
122
+ import { frameCaf, frameRaf } from './frame-clock.ts';
114
123
  import {
115
124
  crossedDragThreshold,
116
125
  dropPageRoot,
@@ -734,7 +743,7 @@ function postLayersTree(artboardId: string | null | undefined): void {
734
743
  const LAYERS_CHROME_SEL =
735
744
  '.dc-cv-halo, .dc-cv-group-bbox, .dgn-pin, .dc-cv-reorder-divider, .dc-cv-reorder-into, .dc-activity-rim, .dc-activity-scan, .dc-cv-reorder-lift';
736
745
 
737
- function LayersLiveSync() {
746
+ export function LayersLiveSync() {
738
747
  useEffect(() => {
739
748
  if (typeof MutationObserver === 'undefined' || typeof document === 'undefined') return;
740
749
  const isChrome = (n: Node): boolean =>
@@ -750,10 +759,12 @@ function LayersLiveSync() {
750
759
  structural = true;
751
760
  break;
752
761
  }
753
- const art = getLastLayersArtboardId();
754
- if (!structural || !art) return;
762
+ if (!structural || !getLastLayersArtboardId()) return;
755
763
  if (timer) clearTimeout(timer);
756
- timer = setTimeout(() => postLayersTree(art), 90);
764
+ // 2.0.7 fix (decision `v2-207-layers-current`) — read the tracked artboard when the timer FIRES: a
765
+ // request-layers for another artboard inside the debounce made that one current, and re-posting the one
766
+ // read at mutation time put the previous artboard's tree back in the shell, after the right one
767
+ timer = setTimeout(() => postLayersTree(getLastLayersArtboardId()), 90);
757
768
  });
758
769
  obs.observe(document.body, { childList: true, subtree: true });
759
770
  return () => {
@@ -835,11 +846,21 @@ function CanvasThemePillMount() {
835
846
  <CanvasThemePill
836
847
  bothThemes={() => detectDsThemeSupport().supported}
837
848
  onProbeStale={subscribeDsThemeProbe}
849
+ extra={
850
+ // 2.0.7 B2 — Canvas | Pages beside Light | Dark (canvas-pages-view.tsx)
851
+ <>
852
+ <style data-dc-pages-css="">{PAGES_PILL_CSS}</style>
853
+ <CanvasPagesSwitch />
854
+ </>
855
+ }
838
856
  />,
839
857
  document.body
840
858
  );
841
859
  }
842
860
 
861
+ /** 2.0.7 B2 — a canvas with no artboard context yet pages through nothing (a stable empty list). */
862
+ const NO_ARTBOARDS: ArtboardRect[] = [];
863
+
843
864
  // ─────────────────────────────────────────────────────────────────────────────
844
865
  // CanvasCore — sits inside SelectionSetProvider, builds the menu registry
845
866
  // against the live viewport controller + selection set, then mounts
@@ -880,6 +901,20 @@ function CanvasCore({
880
901
  const artboardsCtx = useArtboardsContext();
881
902
  const dragBus = useDragStateContext();
882
903
 
904
+ // 2.0.7 B2 — Canvas | Pages: one artboard at a time, in the Present order (canvas-pages-view.tsx). Not on an embed
905
+ // or a Present follower, where the pill steps aside too. The Design system canvas has it on its own bar (2.0.7
906
+ // polish, ds/board/ds-bar.tsx).
907
+ usePagesView({
908
+ controller,
909
+ artboards: artboardsCtx?.artboards ?? NO_ARTBOARDS,
910
+ selectedArtboard: () => selSet.selected[0]?.artboardId ?? null,
911
+ hostRef,
912
+ here: !isEmbedCanvas() && !isFollowCanvas(),
913
+ selectionNone: () => selSet.selected.length === 0,
914
+ // 2.0.7 (decision `v2-207-pages-stale-selection`) — a page turn drops what is selected on another artboard
915
+ dropOffPage: (page) => selSet.drop((s) => !s.artboardId || s.artboardId === page),
916
+ });
917
+
883
918
  // T33 — programmatic-zoom easing via double-click on empty world only.
884
919
  // Per post-Wave-3 user feedback, dblclick-on-artboard auto-zoom was
885
920
  // surprising (interfered with native dblclick text-select inside chrome
@@ -2870,6 +2905,9 @@ function CanvasRouter({
2870
2905
  } else if (replayActionKey(id)) {
2871
2906
  // V2-4.2 — Select all / Copy properties / Paste properties from the project menu: the
2872
2907
  // canvas replays the action's own chord, so the key handler is the one implementation.
2908
+ } else if (runPagesAction(id, params)) {
2909
+ // 2.0.7 B2 — Menu › View › Pages / ⌘K: Canvas | Pages and its paging (canvas-pages-view.tsx); in Pages a
2910
+ // left-panel jump's `view.zoom-to-artboard` turns to that page instead of framing a hidden artboard
2873
2911
  } else if (zoomController) {
2874
2912
  // Shell View-menu zoom items — route to the live viewport controller
2875
2913
  // (the same methods the in-canvas zoom pill calls).
@@ -3031,6 +3069,11 @@ function CanvasRouter({
3031
3069
  ? selSet.addFromShell(picked)
3032
3070
  : selSet.replaceFromShell(picked);
3033
3071
  if (!applied) return;
3072
+ // 2.0.7 (decision `v2-207-pages-stale-selection`) — in Pages every pick turns to its artboard's page, also
3073
+ // when that artboard was already selected (the old rule waited for the selected artboard to CHANGE, so
3074
+ // re-picking it after a page step stayed on the other page and the reveal below moved the camera to where
3075
+ // the hidden artboard sits). The page brings its own camera, so the reveal is skipped.
3076
+ if (pickTurnsPage(picked.artboardId ?? mm.artboardId)) return;
3034
3077
  // Task A1 — reveal THROUGH the camera, not host scroll. The old
3035
3078
  // `scrollIntoView` scrolled the overflow:hidden `.dc-canvas` /
3036
3079
  // `.dc-artboard-body` clip layers, desyncing the `.dc-world`
@@ -3097,7 +3140,10 @@ function CanvasRouter({
3097
3140
  if (!board) return;
3098
3141
  const rect = window.__maudeCanvasRects?.().artboards.find((a) => a.id === aid);
3099
3142
  const host = hostRef.current;
3100
- if (rect && zoomController) {
3143
+ // 2.0.7 polish — in Pages the reveal turns to that artboard's page (its camera), never to a hidden one
3144
+ if (turnToPage(aid)) {
3145
+ /* the page's own camera */
3146
+ } else if (rect && zoomController) {
3101
3147
  if (mm.glide === true || !host) zoomController.jumpTo(rect);
3102
3148
  else zoomController.animateTo(fitRectIntoHost(rect, host), 0);
3103
3149
  }
@@ -3595,7 +3641,7 @@ function CanvasRouter({
3595
3641
  useEffect(
3596
3642
  () => () => {
3597
3643
  if (hoverRafRef.current != null && typeof cancelAnimationFrame !== 'undefined') {
3598
- cancelAnimationFrame(hoverRafRef.current);
3644
+ frameCaf(hoverRafRef.current);
3599
3645
  }
3600
3646
  },
3601
3647
  []
@@ -3608,7 +3654,7 @@ function CanvasRouter({
3608
3654
  onHover: ({ deep, clientX, clientY }) => {
3609
3655
  pendingHoverRef.current = { deep, x: clientX, y: clientY };
3610
3656
  if (hoverRafRef.current == null && typeof requestAnimationFrame !== 'undefined') {
3611
- hoverRafRef.current = requestAnimationFrame(applyHover);
3657
+ hoverRafRef.current = frameRaf(applyHover);
3612
3658
  }
3613
3659
  },
3614
3660
  onSelect: ({ mode, deep, clientX, clientY }) => {
@@ -3845,11 +3891,11 @@ function HoverHalo({ el }: { el: Element | null }) {
3845
3891
  div.style.width = `${Math.round(r.width)}px`;
3846
3892
  div.style.height = `${Math.round(r.height)}px`;
3847
3893
  }
3848
- rafRef.current = requestAnimationFrame(tick);
3894
+ rafRef.current = frameRaf(tick);
3849
3895
  };
3850
- rafRef.current = requestAnimationFrame(tick);
3896
+ rafRef.current = frameRaf(tick);
3851
3897
  return () => {
3852
- if (rafRef.current != null) cancelAnimationFrame(rafRef.current);
3898
+ if (rafRef.current != null) frameCaf(rafRef.current);
3853
3899
  };
3854
3900
  }, [el]);
3855
3901
 
@@ -3953,11 +3999,11 @@ function SelectionHalos() {
3953
3999
  child.style.height = `${Math.round(r.height) + gap * 2}px`;
3954
4000
  }
3955
4001
  }
3956
- rafRef.current = requestAnimationFrame(tick);
4002
+ rafRef.current = frameRaf(tick);
3957
4003
  };
3958
- rafRef.current = requestAnimationFrame(tick);
4004
+ rafRef.current = frameRaf(tick);
3959
4005
  return () => {
3960
- if (rafRef.current != null) cancelAnimationFrame(rafRef.current);
4006
+ if (rafRef.current != null) frameCaf(rafRef.current);
3961
4007
  };
3962
4008
  }, [selected]);
3963
4009
 
@@ -4687,11 +4733,11 @@ function GroupBbox() {
4687
4733
  div.style.top = `${Math.round(yMin - pad)}px`;
4688
4734
  div.style.width = `${Math.round(xMax - xMin + pad * 2)}px`;
4689
4735
  div.style.height = `${Math.round(yMax - yMin + pad * 2)}px`;
4690
- rafRef.current = requestAnimationFrame(tick);
4736
+ rafRef.current = frameRaf(tick);
4691
4737
  };
4692
- rafRef.current = requestAnimationFrame(tick);
4738
+ rafRef.current = frameRaf(tick);
4693
4739
  return () => {
4694
- if (rafRef.current != null) cancelAnimationFrame(rafRef.current);
4740
+ if (rafRef.current != null) frameCaf(rafRef.current);
4695
4741
  };
4696
4742
  }, [selected]);
4697
4743
 
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @file canvas-theme-icons.tsx — the sun and moon on the Light | Dark switch (2.0.7, Michal: icons only,
3
+ * a more compact pill). Drawn in the maude-v2 icon grammar (16 grid, live area 2–14, 1.5 round
4
+ * stroke, `currentColor`) like canvas-ds-icons.tsx, kept apart from DS_GLYPHS because the kit has no
5
+ * theme glyphs yet (test/canvas-ds-icons.test.tsx pins DS_GLYPHS path for path to the kit).
6
+ * React-only, no studio imports — the canvas pill and the Design system bar both draw them.
7
+ */
8
+
9
+ import type { JSX } from 'react';
10
+
11
+ export type ThemeMode = 'light' | 'dark';
12
+
13
+ /** The icon for one theme; `aria-hidden` — the button carries the name. */
14
+ export function ThemeIcon({ mode, size = 14 }: { mode: ThemeMode; size?: number }): JSX.Element {
15
+ return (
16
+ <svg
17
+ width={size}
18
+ height={size}
19
+ viewBox="0 0 16 16"
20
+ fill="none"
21
+ stroke="currentColor"
22
+ strokeWidth={1.5}
23
+ strokeLinecap="round"
24
+ strokeLinejoin="round"
25
+ aria-hidden="true"
26
+ focusable="false"
27
+ >
28
+ {mode === 'light' ? (
29
+ <>
30
+ <circle cx="8" cy="8" r="2.75" />
31
+ <path d="M8 2v1.25M8 12.75V14M2 8h1.25M12.75 8H14M3.75 3.75l.9.9M11.35 11.35l.9.9M3.75 12.25l.9-.9M11.35 4.65l.9-.9" />
32
+ </>
33
+ ) : (
34
+ <path d="M13.25 9.75A5.5 5.5 0 1 1 6.25 2.75a4.25 4.25 0 0 0 7 7z" />
35
+ )}
36
+ </svg>
37
+ );
38
+ }
39
+
40
+ /** The words a person reads for a theme: the button's name and its tooltip. */
41
+ export const THEME_WORD: Readonly<Record<ThemeMode, string>> = { light: 'Light', dark: 'Dark' };
@@ -11,9 +11,10 @@
11
11
  // ("Following …" / "Everyone here is following you … Stop", presence/canvas-presence.tsx): the pill sat on top of it and
12
12
  // took the Stop click.
13
13
 
14
- import { useEffect, useState } from 'react';
14
+ import { type ReactNode, useEffect, useState } from 'react';
15
15
  import { DsIcon } from './canvas-ds-icons.tsx';
16
16
  import { getCanvasThemeSystemName, setCanvasTheme, useCanvasTheme } from './canvas-theme.ts';
17
+ import { THEME_WORD, ThemeIcon } from './canvas-theme-icons.tsx';
17
18
 
18
19
  /** The pill's chrome. Kept in step with the `.ds-bar` block of ds/board/board.css (same pill, other canvases). */
19
20
  const PILL_CSS = `
@@ -25,7 +26,8 @@ const PILL_CSS = `
25
26
  .dc-theme-pill-b{appearance:none;border:0;border-radius:calc(var(--maude-hud-radius-md,10px) - 2px);padding:4px 12px;background:transparent;color:var(--maude-chrome-fg-1);font:inherit;font-size:var(--maude-hud-type-xs,11px);cursor:pointer}
26
27
  .dc-theme-pill-b[aria-pressed="true"]{background:var(--maude-chrome-bg-2);color:var(--maude-chrome-fg-0);box-shadow:var(--maude-hud-shadow-md),inset 0 0 0 1px var(--maude-hud-accent)}
27
28
  .dc-theme-pill-b:disabled{opacity:.4;cursor:default}
28
- .dc-theme-pill-note{color:var(--maude-chrome-fg-1);font-size:var(--maude-hud-type-xs,11px)}
29
+ .dc-theme-pill-b--ic{display:grid;place-items:center;padding:4px 7px}
30
+ .dc-theme-pill-sr{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}
29
31
  .dc-theme-pill-path{appearance:none;border:0;border-radius:var(--maude-hud-radius-xs,4px);padding:4px 6px;margin:0;background:transparent;color:var(--maude-chrome-fg-1);font:inherit;font-size:var(--maude-hud-type-xs,11px);font-family:var(--maude-chrome-font-mono,ui-monospace,monospace);cursor:pointer;max-width:260px;overflow:hidden;text-overflow:ellipsis}
30
32
  .dc-theme-pill-path:hover{background:var(--maude-chrome-bg-3);color:var(--maude-chrome-fg-0)}
31
33
  .dc-theme-pill-path:focus-visible{outline:2px solid var(--maude-hud-focus-ring);outline-offset:1px}
@@ -65,10 +67,13 @@ function canvasFilePath(): string | null {
65
67
  export function CanvasThemePill({
66
68
  bothThemes,
67
69
  onProbeStale,
70
+ extra,
68
71
  }: {
69
72
  bothThemes: () => boolean;
70
73
  /** subscribe to "the answer may have changed" (a stylesheet or the first artboard wrapper arrived) */
71
74
  onProbeStale?: (f: () => void) => () => void;
75
+ /** 2.0.7 B2 — drawn after Light | Dark: the canvas's Canvas | Pages (canvas-pages-view.tsx) */
76
+ extra?: ReactNode;
72
77
  }) {
73
78
  const mode = useCanvasTheme();
74
79
  const [, tick] = useState(0);
@@ -142,22 +147,26 @@ export function CanvasThemePill({
142
147
  <button
143
148
  key={m}
144
149
  type="button"
145
- className="dc-theme-pill-b"
150
+ className="dc-theme-pill-b dc-theme-pill-b--ic"
146
151
  data-testid={`canvas-theme-mode-${m}`}
147
152
  aria-pressed={mode === m}
153
+ aria-label={THEME_WORD[m]}
148
154
  disabled={!both && mode !== m}
149
- title={!both && mode !== m ? 'This design system defines only one theme.' : undefined}
155
+ // 2.0.7 — icons only (Michal): the name is the tooltip; a theme the canvas lacks says so there
156
+ title={!both && mode !== m ? `This canvas has no ${THEME_WORD[m]}` : THEME_WORD[m]}
150
157
  onClick={() => setCanvasTheme(m)}
151
158
  >
152
- {m === 'light' ? 'Light' : 'Dark'}
159
+ <ThemeIcon mode={m} />
153
160
  </button>
154
161
  ))}
155
162
  </fieldset>
156
163
  {!both ? (
157
- <span className="dc-theme-pill-note" data-testid="canvas-theme-note">
164
+ // read by a screen reader only; the greyed button's tooltip says the same to everyone else
165
+ <span className="dc-theme-pill-sr" data-testid="canvas-theme-note">
158
166
  {`This canvas has no ${mode === 'light' ? 'Dark' : 'Light'}`}
159
167
  </span>
160
168
  ) : null}
169
+ {extra}
161
170
  </div>
162
171
  </>
163
172
  );