@1agh/maude 2.0.6 → 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 (177) hide show
  1. package/apps/studio/access/closure.ts +156 -16
  2. package/apps/studio/access/filters.ts +27 -0
  3. package/apps/studio/actions/agents.ts +54 -0
  4. package/apps/studio/actions/ctx.ts +3 -0
  5. package/apps/studio/actions/defs/sync.ts +13 -0
  6. package/apps/studio/actions/defs/view.ts +59 -3
  7. package/apps/studio/actions/keymap.gen.ts +35 -0
  8. package/apps/studio/actions/menu.ts +2 -0
  9. package/apps/studio/actions/types.ts +3 -1
  10. package/apps/studio/actions.manifest.json +136 -1
  11. package/apps/studio/actions.parity.json +25 -1
  12. package/apps/studio/annotations/ui/ai-seen.tsx +4 -3
  13. package/apps/studio/annotations/ui/ride.ts +2 -1
  14. package/apps/studio/annotations-context-toolbar.tsx +5 -4
  15. package/apps/studio/annotations-layer.tsx +4 -3
  16. package/apps/studio/api.ts +383 -128
  17. package/apps/studio/artboard-activity-overlay.tsx +4 -4
  18. package/apps/studio/artboard-ai-copies.tsx +4 -4
  19. package/apps/studio/artboard-freeze.ts +108 -0
  20. package/apps/studio/artboard-live-gate.tsx +414 -45
  21. package/apps/studio/artboard-live.ts +526 -31
  22. package/apps/studio/artboard-placeholder.ts +197 -0
  23. package/apps/studio/artboard-still-raster.ts +485 -0
  24. package/apps/studio/artboard-still-warmup.ts +221 -0
  25. package/apps/studio/artboard-still.ts +1188 -0
  26. package/apps/studio/artboard-webgl.ts +2 -1
  27. package/apps/studio/asset-placeholder.tsx +237 -132
  28. package/apps/studio/asset-upload-bars.tsx +4 -4
  29. package/apps/studio/bin/_perf-probe-open.mjs +364 -0
  30. package/apps/studio/bin/_perf-shared.mjs +12 -7
  31. package/apps/studio/bin/_pw-launch.mjs +26 -1
  32. package/apps/studio/bin/perf.sh +19 -0
  33. package/apps/studio/bridge/dgn-protocol.ts +35 -0
  34. package/apps/studio/canvas-build-sandbox.ts +69 -13
  35. package/apps/studio/canvas-camera.ts +90 -0
  36. package/apps/studio/canvas-comment-mount.tsx +9 -9
  37. package/apps/studio/canvas-lib.tsx +160 -34
  38. package/apps/studio/canvas-pages-view.tsx +465 -0
  39. package/apps/studio/canvas-pages.ts +305 -0
  40. package/apps/studio/canvas-rows.ts +62 -0
  41. package/apps/studio/canvas-shell.tsx +62 -16
  42. package/apps/studio/canvas-theme-icons.tsx +41 -0
  43. package/apps/studio/canvas-theme-pill.tsx +15 -6
  44. package/apps/studio/canvas-theme.ts +12 -11
  45. package/apps/studio/client/app.jsx +7 -0
  46. package/apps/studio/client/canvas-url.js +23 -1
  47. package/apps/studio/client/hooks/canvas-origin-probe.js +34 -0
  48. package/apps/studio/client/hooks/use-action-keys.jsx +3 -1
  49. package/apps/studio/client/hooks/use-canvas-bridge.jsx +1 -1
  50. package/apps/studio/client/hooks/use-palette-and-panels.jsx +23 -6
  51. package/apps/studio/client/hooks/use-photo-and-timeline.jsx +16 -8
  52. package/apps/studio/client/hooks/use-project-data.jsx +11 -2
  53. package/apps/studio/client/hooks/use-shell-core.jsx +19 -9
  54. package/apps/studio/client/index-loader.ts +41 -21
  55. package/apps/studio/client/inspector/inspector-panel.jsx +35 -14
  56. package/apps/studio/client/shell/viewport.jsx +32 -16
  57. package/apps/studio/client/tree/tree.jsx +17 -0
  58. package/apps/studio/client/v2/canvases/canvases-panel.jsx +24 -0
  59. package/apps/studio/client/v2/canvases/use-canvas-index.js +24 -1
  60. package/apps/studio/client/v2/code/canvas-error-card.jsx +14 -2
  61. package/apps/studio/client/v2/code/canvas-imports-card.jsx +7 -3
  62. package/apps/studio/client/v2/code/canvas-imports-words.js +16 -0
  63. package/apps/studio/client/v2/code/canvas-waiting-card.jsx +59 -5
  64. package/apps/studio/client/v2/code/canvas-waiting.js +18 -1
  65. package/apps/studio/client/v2/code/code-consent-sheet.jsx +87 -0
  66. package/apps/studio/client/v2/code/code-consent.js +67 -0
  67. package/apps/studio/client/v2/diagnostics/sync-details/sync-details-model.js +62 -10
  68. package/apps/studio/client/v2/diagnostics/sync-details/sync-details.jsx +314 -5
  69. package/apps/studio/client/v2/layers/artboard-layers.jsx +24 -5
  70. package/apps/studio/client/v2/layers/layers-request.js +49 -0
  71. package/apps/studio/client/v2/left-panel/canvases-pinned.jsx +93 -3
  72. package/apps/studio/client/v2/left-panel/ds-boards.js +39 -0
  73. package/apps/studio/client/v2/left-panel/left-panel-model.js +13 -0
  74. package/apps/studio/client/v2/left-panel/left-panel.css +24 -0
  75. package/apps/studio/client/v2/shell/canvas-crash-guard.js +40 -5
  76. package/apps/studio/client/v2/shell/canvas-mode.js +17 -1
  77. package/apps/studio/client/v2/shell/floating-panels.css +37 -1
  78. package/apps/studio/client/v2/shell/mode-switch.jsx +14 -3
  79. package/apps/studio/client/v2/shell/opening-skeleton.js +118 -0
  80. package/apps/studio/client/v2/shell/opening-skeleton.jsx +103 -0
  81. package/apps/studio/client/v2/shell/pages-pick.js +49 -0
  82. package/apps/studio/client/v2/shell/project-menu-model.js +3 -0
  83. package/apps/studio/client/v2/shell/share-cluster-host.jsx +3 -1
  84. package/apps/studio/client/v2/shell/shell-parity.json +8 -0
  85. package/apps/studio/client/v2/shell/use-canvas-mode-lane.js +30 -0
  86. package/apps/studio/comments-overlay.tsx +12 -11
  87. package/apps/studio/config-reload-wire.ts +4 -1
  88. package/apps/studio/config.schema.json +6 -0
  89. package/apps/studio/context.ts +37 -1
  90. package/apps/studio/dist/client.bundle.js +720 -720
  91. package/apps/studio/dist/comment-mount.js +2 -2
  92. package/apps/studio/dist/styles.css +1 -1
  93. package/apps/studio/ds/board/board.css +6 -0
  94. package/apps/studio/ds/board/ds-bar.tsx +21 -3
  95. package/apps/studio/ds/board/specimen.tsx +6 -3
  96. package/apps/studio/ds/board/template.ts +39 -19
  97. package/apps/studio/ds/cli.ts +7 -1
  98. package/apps/studio/ds/component-list.ts +2 -1
  99. package/apps/studio/ds/default.ts +6 -1
  100. package/apps/studio/ds/ds-resolver.ts +58 -8
  101. package/apps/studio/ds/engine.ts +3 -1
  102. package/apps/studio/ds/folder-systems.ts +199 -0
  103. package/apps/studio/ds/pairing-css.ts +2 -1
  104. package/apps/studio/ds/rename.ts +10 -3
  105. package/apps/studio/ds/shell-fallbacks.ts +2 -1
  106. package/apps/studio/ds/upgrade-stage.ts +6 -2
  107. package/apps/studio/editing/ai-point-ring.tsx +4 -4
  108. package/apps/studio/editing/ai-scope-outline.tsx +4 -4
  109. package/apps/studio/editing/align-bar.tsx +4 -4
  110. package/apps/studio/editing/anchor-report.ts +3 -2
  111. package/apps/studio/editing/artboard-handles.tsx +4 -4
  112. package/apps/studio/editing/corner-dots.tsx +4 -4
  113. package/apps/studio/editing/crop-mode.tsx +4 -4
  114. package/apps/studio/editing/drop-chip.tsx +4 -4
  115. package/apps/studio/editing/empty-report.ts +3 -2
  116. package/apps/studio/editing/focus-model.tsx +4 -4
  117. package/apps/studio/editing/gap-bands.tsx +3 -3
  118. package/apps/studio/editing/hold-rings.tsx +4 -4
  119. package/apps/studio/editing/lock-badge.tsx +3 -3
  120. package/apps/studio/editing/long-page.ts +23 -1
  121. package/apps/studio/editing/nudge.tsx +2 -2
  122. package/apps/studio/editing/page-activity.ts +4 -3
  123. package/apps/studio/editing/paste-bar.tsx +4 -4
  124. package/apps/studio/editing/pen/overlay.tsx +4 -3
  125. package/apps/studio/editing/place-freely.tsx +3 -3
  126. package/apps/studio/editing/reorder-slot.tsx +3 -3
  127. package/apps/studio/editing/selection.tsx +4 -4
  128. package/apps/studio/editing/size-ghost.tsx +4 -4
  129. package/apps/studio/editing/tab-order.tsx +4 -4
  130. package/apps/studio/editing/text-in-place.tsx +4 -4
  131. package/apps/studio/editing/undo-preview.tsx +3 -3
  132. package/apps/studio/equal-spacing-handles.tsx +3 -3
  133. package/apps/studio/frame-clock.ts +89 -0
  134. package/apps/studio/http.ts +66 -32
  135. package/apps/studio/index/ds-usage.ts +4 -1
  136. package/apps/studio/index-cache.ts +272 -0
  137. package/apps/studio/inspect-overlay.tsx +4 -3
  138. package/apps/studio/inspect.ts +7 -2
  139. package/apps/studio/link-chip-overlay.tsx +4 -3
  140. package/apps/studio/measure-overlay.tsx +4 -3
  141. package/apps/studio/present/pointer-dot.tsx +3 -2
  142. package/apps/studio/present/present-media.ts +6 -2
  143. package/apps/studio/present/present-stage.tsx +3 -2
  144. package/apps/studio/preview/preview-camera.tsx +3 -2
  145. package/apps/studio/routes/sync.ts +176 -0
  146. package/apps/studio/safe-zones-overlay.tsx +3 -2
  147. package/apps/studio/skip-dirs.ts +103 -47
  148. package/apps/studio/studio-page-host.ts +70 -0
  149. package/apps/studio/sync/code-module-consent.ts +86 -0
  150. package/apps/studio/sync/file-ledger.ts +24 -0
  151. package/apps/studio/sync/file-plane.ts +458 -53
  152. package/apps/studio/sync/held-deletes.ts +230 -0
  153. package/apps/studio/sync/hubs-config.ts +59 -2
  154. package/apps/studio/sync/index.ts +99 -15
  155. package/apps/studio/sync/seed-progress.ts +92 -2
  156. package/apps/studio/sync/settings.ts +36 -1
  157. package/apps/studio/sync/status.ts +15 -1
  158. package/apps/studio/sync/writer-registry.ts +5 -0
  159. package/apps/studio/text-caret.ts +5 -3
  160. package/apps/studio/toolbars/toolbar-rect.ts +3 -2
  161. package/apps/studio/use-annotation-resize.tsx +4 -3
  162. package/apps/studio/use-artboard-drag.tsx +3 -2
  163. package/apps/studio/use-element-resize.tsx +7 -6
  164. package/apps/studio/use-grid-track-handles.tsx +5 -4
  165. package/apps/studio/use-selection-set.tsx +64 -4
  166. package/apps/studio/use-spacing-handles.tsx +7 -6
  167. package/apps/studio/video-comp.tsx +55 -42
  168. package/apps/studio/video-play-overlay.tsx +4 -3
  169. package/apps/studio/whats-new.json +27 -0
  170. package/cli/commands/design.mjs +5 -2
  171. package/cli/commands/hub.mjs +10 -1
  172. package/cli/lib/bash-guard.mjs +14 -0
  173. package/cli/lib/design-help.gen.mjs +1 -1
  174. package/cli/lib/design-link.mjs +42 -17
  175. package/cli/lib/hub-purge.mjs +183 -0
  176. package/package.json +8 -8
  177. package/plugins/design/templates/_shell.html +164 -1
@@ -19,6 +19,24 @@
19
19
  * Captures render EVERYTHING: the mode is `off` for every headless/export render (top-level
20
20
  * page, `?hide-chrome=1`, `?thumb-only=`), and the in-frame export (`export-capture`) wakes
21
21
  * every artboard for the length of the capture (`forceAll`).
22
+ *
23
+ * 2.0.7 — the mount RING (Michal: "what is in the viewport is right, what is far away is released").
24
+ * In `sleep` an artboard's children mount when it comes into the prefetch ring (`NEAR_MARGIN`) and
25
+ * are RELEASED again once it has been outside the larger keep ring (`KEEP_MARGIN` — the hysteresis)
26
+ * for `RELEASE_AFTER_MS`, so a long canvas never holds every artboard's DOM at once (a 45k-node
27
+ * canvas froze WebKit for seconds per frame even with three artboards on screen). Mounting is
28
+ * bounded by a DOM budget (`MOUNT_NODE_BUDGET`, measured per artboard): on-screen artboards first,
29
+ * nearest the centre first, then the prefetch ring; one that does not fit stays a same-size
30
+ * placeholder. Mounting goes on DURING a gesture (on-screen artboards only, one per frame; the React
31
+ * side renders it as an interruptible transition), so a pan never waits for the canvas to load.
32
+ * Live wakes (WebGL, video) still wait for the settle.
33
+ *
34
+ * 2.0.7 — a LIGHT canvas has no ring (decision `v2-207-light-canvas-mounts-all`): when the whole canvas's
35
+ * estimated element count fits the budget (`isLight`), every artboard mounts — far ones too, through the
36
+ * same queue, never mid-gesture — and none is released, as in 1.x: no churn and no stand-in blocks. The
37
+ * estimate follows the weights as artboards mount, so a canvas that grows past the budget falls back to
38
+ * the ring (its far artboards are released after their grace, at a settle). Live wakes and a video
39
+ * artboard's media still follow the ring, as on any canvas.
22
40
  */
23
41
 
24
42
  import { LOD_ZOOM } from './annotations/ui/lod.tsx';
@@ -33,6 +51,41 @@ export const WEBGL_LIVE_CAP = 8;
33
51
  export const NEAR_MARGIN = '50%';
34
52
  /** How many artboards wake (or first mount) per animation frame. */
35
53
  export const WAKE_PER_FRAME = 3;
54
+ /** The keep ring: a mounted artboard stays mounted while it is this near (hysteresis over `NEAR_MARGIN`). */
55
+ export const KEEP_MARGIN = '150%';
56
+ /** How long an artboard must have been outside the keep ring before its children are released (ms). */
57
+ export const RELEASE_AFTER_MS = 2500;
58
+ /**
59
+ * How long a slot nobody subscribes to any more is kept (ms): an edit's soft reload remounts every gate, and the
60
+ * new one must find its artboard still mounted (2.0.7 — a placeholder in between lost the shell's selection).
61
+ */
62
+ export const RETIRE_AFTER_MS = 250;
63
+ /** The DOM budget of one canvas document: mounted artboards' element count stays about this (2.0.7). */
64
+ export const MOUNT_NODE_BUDGET = 12000;
65
+ /**
66
+ * On-screen artboards mount past `MOUNT_NODE_BUDGET` up to this many elements (2.0.7): the budget bounds what is
67
+ * off screen; this only stops a fit-all of a huge canvas, whose tiny artboards keep their still pictures.
68
+ */
69
+ export const ON_SCREEN_NODE_CEILING = 30000;
70
+ /** The weight (elements) of an artboard nobody has measured yet, until one of the canvas has been. */
71
+ export const DEFAULT_WEIGHT = 400;
72
+ /** After a frame longer than this (ms) the next frame mounts one artboard, not `WAKE_PER_FRAME`. */
73
+ export const SLOW_FRAME_MS = 34;
74
+ /** Mid-gesture, at most one first mount per this many ms (a WebKit mount lays out and paints at once). */
75
+ export const GESTURE_MOUNT_GAP_MS = 350;
76
+ /**
77
+ * More artboards than this on screen and WebKit drops their per-artboard compositing layers: it rasterizes each
78
+ * layer at full size whatever the world's scale (40 on screen at 8 % = seconds per frame). An 18-board
79
+ * moodboard keeps them (they are why its fit-all zoom is smooth — RCA issue-canvas-pan-zoom-jank-large-moodboard).
80
+ */
81
+ export const LAYER_MAX_VISIBLE = 24;
82
+ /**
83
+ * A light canvas mounts every artboard and keeps it (2.0.7, decision `v2-207-light-canvas-mounts-all`): when the
84
+ * canvas's estimated element count — the measured artboards plus their average for each one not measured yet — fits
85
+ * `MOUNT_NODE_BUDGET`. The estimate is trusted once this many artboards are measured (or all of a smaller canvas);
86
+ * before that the ring decides, and `DEFAULT_WEIGHT` is never an estimate.
87
+ */
88
+ export const LIGHT_MIN_MEASURED = 4;
36
89
 
37
90
  /**
38
91
  * `off` — every artboard live, every child mounted (captures, exports, headless, tests): the pre-2.0.5 behaviour.
@@ -78,21 +131,49 @@ export interface ArtboardLiveState {
78
131
  live: boolean;
79
132
  /** Its children may be mounted (always true in `sleep`/`off` once seen; follows `live` in `light`). */
80
133
  seen: boolean;
134
+ /**
135
+ * Its media may load (a `<video>`'s src, a Player). Equal to `seen`, except on an eager artboard: that one is
136
+ * mounted wherever it is so its comp registers, but its media follows the ring as a lazy artboard's children
137
+ * would — near or on screen, kept inside the keep ring, released after the grace (2.0.7).
138
+ */
139
+ media: boolean;
81
140
  }
82
141
 
83
142
  interface Slot {
84
143
  near: boolean;
85
144
  visible: boolean;
145
+ /** Inside the keep ring (starts true: an artboard nobody has reported on is not far). */
146
+ keep: boolean;
147
+ /** When it left the keep ring (ms), or 0. */
148
+ farSince: number;
149
+ /** Distance of its centre to the viewport centre (px, the near observer's last word). */
150
+ dist: number;
151
+ /** Measured element count of its mounted children, or 0. */
152
+ weight: number;
153
+ /** Never released (the active artboard — a selection or an edit lives in its DOM). */
154
+ pinned: boolean;
155
+ /**
156
+ * Always mounted in `sleep`, wherever it is (a video artboard: its comp registers itself only while mounted, and
157
+ * the link glyph, the Timeline's shared count and Present's format switch read those registrations).
158
+ */
159
+ eager: boolean;
160
+ /**
161
+ * Mounted for the stills' warm-up (2.0.7, artboard-still-warmup.ts): far away, asleep, within the DOM budget, until
162
+ * its still is drawn. Never a prefetch past the budget, never mid-gesture (the drain's own rules).
163
+ */
164
+ warm: boolean;
86
165
  admitted: boolean;
87
166
  live: boolean;
167
+ /** Its media may load: `admitted`, except on an eager artboard, where it is the ring's own answer. */
168
+ media: boolean;
88
169
  /** The last state handed out — one object per change, so React's external store sees a stable snapshot. */
89
170
  view: ArtboardLiveState;
90
171
  subs: Set<(s: ArtboardLiveState) => void>;
91
172
  }
92
173
 
93
- const ASLEEP: ArtboardLiveState = Object.freeze({ live: false, seen: false });
174
+ const ASLEEP: ArtboardLiveState = Object.freeze({ live: false, seen: false, media: false });
94
175
 
95
- const ALL_LIVE: ArtboardLiveState = Object.freeze({ live: true, seen: true });
176
+ const ALL_LIVE: ArtboardLiveState = Object.freeze({ live: true, seen: true, media: true });
96
177
 
97
178
  /**
98
179
  * One per canvas document. Fed by two IntersectionObservers (near / visible), the published zoom and the
@@ -109,10 +190,52 @@ export class LiveRegistry {
109
190
  private scheduled = false;
110
191
  private readonly schedule: (fn: () => void) => void;
111
192
  private listeners = new Set<() => void>();
112
-
113
- constructor(mode: LiveMode, schedule: (fn: () => void) => void) {
193
+ private readonly now: () => number;
194
+ private readonly later: (fn: () => void, ms: number) => void;
195
+ private sweepAt = 0;
196
+ private lastDrainAt = 0;
197
+ private lastGestureMountAt = Number.NEGATIVE_INFINITY;
198
+ private lastAnyMountAt = Number.NEGATIVE_INFINITY;
199
+ /** First mounts made during the current gesture (2.0.7: the settle frees what they took past the budget). */
200
+ private gestureMounts = 0;
201
+ /** The canvas fits the budget whole (`isLight`): every artboard mounted and kept. Kept current by `recompute`. */
202
+ private light = false;
203
+ readonly budget: number;
204
+ readonly ceiling: number;
205
+
206
+ constructor(
207
+ mode: LiveMode,
208
+ schedule: (fn: () => void) => void,
209
+ opts: {
210
+ now?: () => number;
211
+ later?: (fn: () => void, ms: number) => void;
212
+ budget?: number;
213
+ ceiling?: number;
214
+ } = {}
215
+ ) {
114
216
  this.mode = mode;
115
217
  this.schedule = schedule;
218
+ this.now =
219
+ opts.now ?? (() => (typeof performance !== 'undefined' ? performance.now() : Date.now()));
220
+ this.later = opts.later ?? ((fn, ms) => void setTimeout(fn, ms));
221
+ this.budget = opts.budget ?? MOUNT_NODE_BUDGET;
222
+ this.ceiling = opts.ceiling ?? ON_SCREEN_NODE_CEILING;
223
+ }
224
+
225
+ private mayWait: (id: string) => boolean = () => false;
226
+
227
+ /**
228
+ * 2.0.7 — which on-screen artboards may wait for the settle to mount (the gate: under the overview cut, where
229
+ * the placeholder shows its colour or its kept still and a mount would show nothing more mid-gesture). The
230
+ * rest mount mid-gesture as before: a placeholder over the cut is a block the user sees.
231
+ */
232
+ setMayWait(fn: (id: string) => boolean): void {
233
+ this.mayWait = fn;
234
+ }
235
+
236
+ /** The active artboard and a video one never wait (neither is ever a still). */
237
+ private waits(id: string, s: Slot): boolean {
238
+ return !s.pinned && !s.eager && this.mayWait(id);
116
239
  }
117
240
 
118
241
  get(id: string): ArtboardLiveState {
@@ -130,26 +253,219 @@ export class LiveRegistry {
130
253
  return () => this.listeners.delete(fn);
131
254
  }
132
255
 
256
+ private settleListeners = new Set<() => void>();
257
+
258
+ /** A gesture settled. */
259
+ onSettle(fn: () => void): () => void {
260
+ this.settleListeners.add(fn);
261
+ return () => this.settleListeners.delete(fn);
262
+ }
263
+
133
264
  subscribe(id: string, fn: (s: ArtboardLiveState) => void): () => void {
134
265
  const s = this.slot(id);
135
266
  s.subs.add(fn);
136
267
  return () => {
137
268
  s.subs.delete(fn);
138
- if (s.subs.size === 0) {
269
+ if (s.subs.size > 0) return;
270
+ // Not dropped at once: an edit soft-reloads the canvas and remounts every gate in ONE commit (old cleanup,
271
+ // then the new subscribe). The new gate must find the slot mounted, or its artboard falls back to a
272
+ // placeholder just as the shell reselects — the 2.0.7 video regression. Nobody back within the grace: gone.
273
+ this.later(() => {
274
+ if (s.subs.size > 0 || this.slots.get(id) !== s) return;
139
275
  this.slots.delete(id);
140
276
  this.pending.delete(id);
141
277
  this.recompute();
142
- }
278
+ }, RETIRE_AFTER_MS);
143
279
  };
144
280
  }
145
281
 
146
- setNear(id: string, near: boolean): void {
282
+ /**
283
+ * The gate stopped observing its article (an unmount, or the old gate of a remount). Clears what the observers
284
+ * said — unless another gate holds the id now (the remount: its own observers report on its new article).
285
+ * Never creates a slot.
286
+ */
287
+ unobserve(id: string): void {
288
+ const s = this.slots.get(id);
289
+ if (!s || s.subs.size > 0) return;
290
+ if (!s.near && !s.visible) return;
291
+ s.near = false;
292
+ s.visible = false;
293
+ this.recompute();
294
+ }
295
+
296
+ setNear(id: string, near: boolean, dist?: number): void {
147
297
  const s = this.slot(id);
298
+ if (dist !== undefined && Number.isFinite(dist)) s.dist = dist;
148
299
  if (s.near === near) return;
149
300
  s.near = near;
301
+ // near is inside the keep ring by definition (the two observers can report in either order)
302
+ if (near) this.setKeepState(s, true);
150
303
  this.recompute();
151
304
  }
152
305
 
306
+ /** The keep ring (`KEEP_MARGIN`): outside it for `RELEASE_AFTER_MS`, a mounted artboard is released. */
307
+ setKeep(id: string, keep: boolean): void {
308
+ const s = this.slot(id);
309
+ const k = keep || s.near;
310
+ if (s.keep === k) return;
311
+ this.setKeepState(s, k);
312
+ this.recompute();
313
+ }
314
+
315
+ /** The active artboard is never released nor pushed out of the budget (its selection lives in its DOM). */
316
+ setPinned(id: string, pinned: boolean): void {
317
+ const s = this.slot(id);
318
+ if (s.pinned === pinned) return;
319
+ s.pinned = pinned;
320
+ this.recompute();
321
+ }
322
+
323
+ /** A video artboard: mounted wherever it is, past the budget, never released nor pushed out (`sleep` only). */
324
+ setEager(id: string, eager: boolean): void {
325
+ const s = this.slot(id);
326
+ if (s.eager === eager) return;
327
+ s.eager = eager;
328
+ this.recompute();
329
+ }
330
+
331
+ /**
332
+ * The stills' warm-up mounts a far artboard (`on`) and releases it once its still is drawn. The release is at once
333
+ * (not the keep ring's grace) unless the artboard came near, on screen, or is pinned / eager meanwhile.
334
+ */
335
+ setWarm(id: string, on: boolean): void {
336
+ const s = this.slots.get(id);
337
+ if (!s || s.warm === on) return;
338
+ s.warm = on;
339
+ if (on) {
340
+ this.recompute();
341
+ return;
342
+ }
343
+ const stays = s.near || s.visible || s.pinned || s.eager || this.forceAll > 0;
344
+ if (s.admitted && !stays) {
345
+ s.admitted = false;
346
+ s.live = false;
347
+ s.media = false;
348
+ this.pending.delete(id);
349
+ this.notify(id, s);
350
+ this.emit();
351
+ } else if (!s.admitted) this.pending.delete(id);
352
+ this.kick();
353
+ }
354
+
355
+ /** Is this artboard's warm mount done (its children mounted)? */
356
+ isMounted(id: string): boolean {
357
+ return !!this.slots.get(id)?.admitted;
358
+ }
359
+
360
+ /**
361
+ * Artboards the warm-up may mount: a gate holds them, not mounted, not on screen nor near, not pinned nor eager (a
362
+ * video keeps its own media rule), and their first mount fits the DOM budget now. Nearest the viewport first.
363
+ */
364
+ warmCandidates(): Array<{ id: string; dist: number; fits: boolean }> {
365
+ if (this.mode !== 'sleep' || this.forceAll > 0) return [];
366
+ const mounted = this.mountedWeight();
367
+ const out: Array<{ id: string; dist: number; fits: boolean }> = [];
368
+ for (const [id, s] of this.slots) {
369
+ if (s.admitted || s.warm || s.visible || s.near || s.pinned || s.eager || s.subs.size === 0)
370
+ continue;
371
+ out.push({ id, dist: s.dist, fits: mounted + this.weightOf(s) <= this.budget });
372
+ }
373
+ return out;
374
+ }
375
+
376
+ /** When the queue last mounted or woke an artboard (ms) — the warm-up waits for the ring's own mounts. */
377
+ lastMountAt(): number {
378
+ return this.lastAnyMountAt;
379
+ }
380
+
381
+ /** The element count an artboard's children came to once mounted (the DOM budget's unit). */
382
+ setWeight(id: string, nodes: number): void {
383
+ const s = this.slots.get(id);
384
+ if (!s || !Number.isFinite(nodes) || nodes < 0) return;
385
+ s.weight = Math.max(1, Math.round(nodes));
386
+ if (this.computeLight() !== this.light) this.recompute();
387
+ }
388
+
389
+ /** The whole canvas fits the DOM budget: every artboard is mounted and kept (2.0.7, `LIGHT_MIN_MEASURED`). */
390
+ isLight(): boolean {
391
+ return this.light;
392
+ }
393
+
394
+ /** The estimated element count of the whole canvas (every artboard a gate holds), or -1 before it is known. */
395
+ estimatedWeight(): number {
396
+ let held = 0;
397
+ let measured = 0;
398
+ let sum = 0;
399
+ for (const s of this.slots.values()) {
400
+ if (s.subs.size === 0) continue;
401
+ held += 1;
402
+ if (s.weight) {
403
+ measured += 1;
404
+ sum += s.weight;
405
+ }
406
+ }
407
+ if (held === 0 || measured < Math.min(LIGHT_MIN_MEASURED, held)) return -1;
408
+ return sum + ((held - measured) * sum) / measured;
409
+ }
410
+
411
+ private computeLight(): boolean {
412
+ if (this.mode !== 'sleep') return false;
413
+ const est = this.estimatedWeight();
414
+ return est >= 0 && est <= this.budget;
415
+ }
416
+
417
+ /** Elements mounted now (measured, or estimated for one not measured yet). */
418
+ mountedWeight(): number {
419
+ let n = 0;
420
+ for (const s of this.slots.values()) if (s.admitted) n += this.weightOf(s);
421
+ return n;
422
+ }
423
+
424
+ /** How many artboards have their children mounted now. */
425
+ mountedCount(): number {
426
+ let n = 0;
427
+ for (const s of this.slots.values()) if (s.admitted) n += 1;
428
+ return n;
429
+ }
430
+
431
+ private weightOf(s: Slot): number {
432
+ if (s.weight) return s.weight;
433
+ let sum = 0;
434
+ let k = 0;
435
+ for (const o of this.slots.values())
436
+ if (o.weight) {
437
+ sum += o.weight;
438
+ k += 1;
439
+ }
440
+ return k ? sum / k : DEFAULT_WEIGHT;
441
+ }
442
+
443
+ private setKeepState(s: Slot, keep: boolean): void {
444
+ if (s.keep === keep) return;
445
+ s.keep = keep;
446
+ s.farSince = keep ? 0 : this.now();
447
+ if (!keep) this.sweepLater(RELEASE_AFTER_MS);
448
+ }
449
+
450
+ private sweepLater(ms: number): void {
451
+ const at = this.now() + ms;
452
+ if (this.sweepAt && this.sweepAt <= at) return;
453
+ this.sweepAt = at;
454
+ this.later(() => {
455
+ this.sweepAt = 0;
456
+ this.recompute();
457
+ // the ones whose grace has not run out yet (they left later) get their own sweep
458
+ let next = Number.POSITIVE_INFINITY;
459
+ // (one whose grace ran out and is still held waits for what holds it — a settle, an unpin, a light canvas
460
+ // growing — and each of those recomputes: rescheduling it here was a sweep every 16 ms meanwhile)
461
+ const now = this.now();
462
+ for (const s of this.slots.values())
463
+ if ((s.admitted || s.media) && !s.keep && s.farSince && s.farSince + RELEASE_AFTER_MS > now)
464
+ next = Math.min(next, s.farSince + RELEASE_AFTER_MS);
465
+ if (Number.isFinite(next)) this.sweepLater(Math.max(16, next - this.now()));
466
+ }, ms);
467
+ }
468
+
153
469
  setVisible(id: string, visible: boolean): void {
154
470
  const s = this.slot(id);
155
471
  if (s.visible === visible) return;
@@ -166,7 +482,18 @@ export class LiveRegistry {
166
482
  setInteracting(on: boolean): void {
167
483
  if (on === this.interacting) return;
168
484
  this.interacting = on;
169
- if (!on) this.kick();
485
+ // the settle wakes what waited, and lets the releases that waited for it happen
486
+ if (!on) {
487
+ this.recompute();
488
+ // 2.0.7 — a mount mid-gesture pushed nothing out (no unmount while the camera moves): what it took past
489
+ // the budget is freed now, from what is off screen, the farthest first
490
+ if (this.gestureMounts > 0 && this.mode === 'sleep' && this.forceAll === 0) {
491
+ const over = this.mountedWeight() - this.budget;
492
+ if (over > 0 && this.evictFor(over) > 0) this.emit();
493
+ }
494
+ this.gestureMounts = 0;
495
+ for (const fn of this.settleListeners) fn();
496
+ } else this.kick(); // on-screen artboards keep mounting during the gesture
170
497
  }
171
498
 
172
499
  /** A capture is running: everything live, NOW (no queue). Returns the release. */
@@ -182,6 +509,31 @@ export class LiveRegistry {
182
509
  };
183
510
  }
184
511
 
512
+ /** The canvas is in its overview right now (zoomed out, or too many artboards on screen). */
513
+ overview(): boolean {
514
+ return this.mode !== 'off' && inOverview(this.zoom, this.visibleCount());
515
+ }
516
+
517
+ /**
518
+ * So many artboards on screen that a compositing layer each costs more than it saves (WebKit, 2.0.7). Never on a
519
+ * light canvas (`isLight`): its layers are cheap, and they are what keeps its fit-all zoom smooth.
520
+ */
521
+ crowded(): boolean {
522
+ return this.mode !== 'off' && !this.light && this.visibleCount() > LAYER_MAX_VISIBLE;
523
+ }
524
+
525
+ /** A gesture is in flight (the gate defers its picture-taking past it). */
526
+ isInteracting(): boolean {
527
+ return this.interacting;
528
+ }
529
+
530
+ /** On screen, and the elements its children came to (measured, or the estimate) — the stills' heavy signal. */
531
+ slotInfo(id: string): { visible: boolean; weight: number } | null {
532
+ const s = this.slots.get(id);
533
+ if (!s) return null;
534
+ return { visible: s.visible, weight: s.admitted ? this.weightOf(s) : 0 };
535
+ }
536
+
185
537
  visibleCount(): number {
186
538
  let n = 0;
187
539
  for (const s of this.slots.values()) if (s.visible) n += 1;
@@ -194,8 +546,16 @@ export class LiveRegistry {
194
546
  s = {
195
547
  near: false,
196
548
  visible: false,
549
+ keep: true,
550
+ farSince: 0,
551
+ dist: Number.POSITIVE_INFINITY,
552
+ weight: 0,
553
+ pinned: false,
554
+ eager: false,
555
+ warm: false,
197
556
  admitted: false,
198
557
  live: false,
558
+ media: false,
199
559
  view: ASLEEP,
200
560
  subs: new Set(),
201
561
  };
@@ -204,7 +564,7 @@ export class LiveRegistry {
204
564
  return s;
205
565
  }
206
566
 
207
- private target(s: Slot): { live: boolean; admitted: boolean } {
567
+ private target(s: Slot): { live: boolean; admitted: boolean; media: boolean } {
208
568
  const force = this.forceAll > 0;
209
569
  const live = decideLive({
210
570
  near: s.near,
@@ -214,22 +574,59 @@ export class LiveRegistry {
214
574
  });
215
575
  // `sleep` mounts what came near and keeps it. `light` (after a crash) mounts only what is LIVE — near and
216
576
  // not in the overview — so a zoomed-out view of 60 scenes mounts none of them, and unmounts what leaves.
217
- const admitted =
218
- this.mode === 'light' ? live : force || s.near || (this.mode === 'sleep' && s.admitted);
219
- return { live, admitted };
577
+ // `sleep` (2.0.7): wanted while in the prefetch ring or on screen, KEPT while inside the keep ring, and
578
+ // released only after `RELEASE_AFTER_MS` outside it (the sweep). Whether a first mount fits the DOM budget
579
+ // is the queue's call (drain).
580
+ // The ring's answer is the same for an eager artboard (a video), but there it decides its MEDIA only: the
581
+ // artboard itself is mounted wherever it is (its comp registers), its Player and <video> load in the ring.
582
+ // On a light canvas (2.0.7) every artboard a gate holds is mounted and kept, like an eager one: the ring then
583
+ // decides its media only (a non-video artboard has none — its children are mounted, asleep).
584
+ const kept = this.mode === 'sleep' && (s.eager || (this.light && s.subs.size > 0));
585
+ const held = kept ? s.media : s.admitted;
586
+ const ring =
587
+ this.mode === 'light'
588
+ ? live
589
+ : force ||
590
+ s.near ||
591
+ s.visible ||
592
+ (this.mode === 'sleep' && s.warm) ||
593
+ (this.mode === 'sleep' && held && !this.releasable(s, held));
594
+ const admitted = ring || kept;
595
+ return { live, admitted, media: ring };
596
+ }
597
+
598
+ /** Mounted (`held`), outside the keep ring for long enough, not on screen, and no gesture in flight. */
599
+ private releasable(s: Slot, held: boolean): boolean {
600
+ return (
601
+ held &&
602
+ !s.pinned &&
603
+ !s.keep &&
604
+ !s.visible &&
605
+ !s.near &&
606
+ s.farSince > 0 &&
607
+ this.now() - s.farSince >= RELEASE_AFTER_MS &&
608
+ !this.interacting
609
+ );
220
610
  }
221
611
 
222
612
  private recompute(): void {
223
613
  if (this.mode === 'off') return;
224
614
  const force = this.forceAll > 0;
615
+ // 2.0.7 — nothing goes down mid-gesture (no sleep, no media release, no unmount): the frame freeze already
616
+ // stops the artboards' own work while the camera moves, and each change is a render. The settle applies them.
617
+ const hold = this.interacting && !force;
618
+ this.light = this.computeLight();
225
619
  let changed = false;
226
620
  for (const [id, s] of this.slots) {
227
621
  const t = this.target(s);
228
- const goesDown = (s.live && !t.live) || (s.admitted && !t.admitted);
229
- const goesUp = (!s.live && t.live) || (!s.admitted && t.admitted);
230
- if (goesDown && !goesUp) {
622
+ const goesDown = (s.live && !t.live) || (s.admitted && !t.admitted) || (s.media && !t.media);
623
+ const goesUp = (!s.live && t.live) || (!s.admitted && t.admitted) || (!s.media && t.media);
624
+ if (hold && goesDown) {
625
+ if (goesUp) this.pending.add(id);
626
+ } else if (goesDown && !goesUp) {
231
627
  s.live = t.live;
232
628
  s.admitted = t.admitted;
629
+ s.media = t.media;
233
630
  this.pending.delete(id);
234
631
  this.notify(id, s);
235
632
  changed = true;
@@ -237,13 +634,15 @@ export class LiveRegistry {
237
634
  if (force) {
238
635
  s.live = t.live;
239
636
  s.admitted = t.admitted;
637
+ s.media = t.media;
240
638
  this.pending.delete(id);
241
639
  this.notify(id, s);
242
640
  changed = true;
243
641
  } else {
244
642
  // The part that goes down applies now; the part that goes up waits for the queue.
245
- if (s.live && !t.live) {
246
- s.live = false;
643
+ if ((s.live && !t.live) || (s.media && !t.media)) {
644
+ if (!t.live) s.live = false;
645
+ if (!t.media) s.media = false;
247
646
  this.notify(id, s);
248
647
  changed = true;
249
648
  }
@@ -258,7 +657,8 @@ export class LiveRegistry {
258
657
  }
259
658
 
260
659
  private kick(): void {
261
- if (this.scheduled || this.pending.size === 0 || this.interacting) return;
660
+ if (this.scheduled || this.pending.size === 0) return;
661
+ if (this.interacting && !this.hasVisibleMount()) return;
262
662
  this.scheduled = true;
263
663
  this.schedule(() => {
264
664
  this.scheduled = false;
@@ -266,21 +666,82 @@ export class LiveRegistry {
266
666
  });
267
667
  }
268
668
 
269
- /** One frame's worth of wakes. Exposed for tests (the browser drains on rAF). */
669
+ private hasVisibleMount(): boolean {
670
+ for (const id of this.pending) {
671
+ const s = this.slots.get(id);
672
+ if (!s?.visible || this.waits(id, s)) continue;
673
+ const t = this.target(s);
674
+ if ((!s.admitted && t.admitted) || (!s.media && t.media)) return true;
675
+ }
676
+ return false;
677
+ }
678
+
679
+ /**
680
+ * One frame's worth of wakes and first mounts. Exposed for tests (the browser drains on rAF).
681
+ *
682
+ * Order: on screen before the prefetch ring, nearest the viewport centre first. A first mount must fit the
683
+ * DOM budget; an on-screen one may push out mounted artboards that are not on screen (outside the prefetch
684
+ * ring first, the farthest first); a prefetch never pushes anything out. During a gesture only on-screen
685
+ * artboards mount (asleep), one per frame, and nothing wakes. After a slow frame, one per frame.
686
+ */
270
687
  drain(): void {
271
- if (this.interacting) return;
688
+ const t = this.now();
689
+ const slow = this.lastDrainAt > 0 && t - this.lastDrainAt > SLOW_FRAME_MS;
690
+ this.lastDrainAt = t;
691
+ // mid-gesture: one first mount, after a fast frame, and not sooner than GESTURE_MOUNT_GAP_MS after the last
692
+ const gestureHold =
693
+ this.interacting && (slow || t - this.lastGestureMountAt < GESTURE_MOUNT_GAP_MS);
694
+ const cap = gestureHold ? 0 : this.interacting || slow ? 1 : WAKE_PER_FRAME;
695
+ const order: Array<{ id: string; s: Slot }> = [];
696
+ for (const id of this.pending) {
697
+ const s = this.slots.get(id);
698
+ if (s) order.push({ id, s });
699
+ else this.pending.delete(id);
700
+ }
701
+ order.sort((a, b) => Number(b.s.visible) - Number(a.s.visible) || a.s.dist - b.s.dist);
272
702
  let n = 0;
273
703
  let changed = false;
274
- for (const id of [...this.pending]) {
275
- if (n >= WAKE_PER_FRAME) break;
276
- this.pending.delete(id);
277
- const s = this.slots.get(id);
278
- if (!s) continue;
279
- const t = this.target(s);
280
- if (t.live === s.live && t.admitted === s.admitted) continue;
281
- s.live = t.live;
282
- s.admitted = t.admitted;
704
+ let mounted = this.mountedWeight();
705
+ for (const { id, s } of order) {
706
+ if (n >= cap) break;
707
+ const tg = this.target(s);
708
+ if (tg.live === s.live && tg.admitted === s.admitted && tg.media === s.media) {
709
+ this.pending.delete(id);
710
+ continue;
711
+ }
712
+ // an eager artboard's media coming up is a mount too (its Player): paced the same, outside the budget
713
+ const mounts = (tg.admitted && !s.admitted) || (tg.media && !s.media);
714
+ // mid-gesture only what is on screen and would show a block mounts (2.0.7: under the cut it waits)
715
+ if (this.interacting && !(mounts && s.visible && !this.waits(id, s))) continue; // waits for the settle
716
+ if (mounts && this.forceAll === 0 && this.mode === 'sleep' && !s.eager) {
717
+ const w = this.weightOf(s);
718
+ if (mounted > 0 && mounted + w > this.budget) {
719
+ if (s.visible && !this.interacting) {
720
+ const freed = this.evictFor(mounted + w - this.budget);
721
+ if (freed) changed = true;
722
+ mounted -= freed;
723
+ }
724
+ // What is ON SCREEN mounts past the budget (up to the ceiling) once nothing off screen is left to push
725
+ // out: the budget bounds what you do not see. At a settled view of the mascot canvas 41 on-screen
726
+ // artboards weighed 17k and three of them stayed placeholders for good.
727
+ const limit = s.visible ? Math.max(this.budget, this.ceiling) : this.budget;
728
+ if (mounted > 0 && mounted + w > limit) continue; // a placeholder until there is room
729
+ }
730
+ mounted += w;
731
+ }
732
+ // mid-gesture a mount only raises (nothing goes down until the settle)
733
+ s.admitted = this.interacting ? s.admitted || tg.admitted : tg.admitted;
734
+ s.media = this.interacting ? s.media || tg.media : tg.media;
735
+ if (this.interacting) {
736
+ // a first mount mid-gesture comes up asleep (`live` stays what it was); its wake waits for the settle
737
+ this.lastGestureMountAt = t;
738
+ this.gestureMounts += 1;
739
+ } else {
740
+ s.live = tg.live;
741
+ this.pending.delete(id);
742
+ }
283
743
  this.notify(id, s);
744
+ this.lastAnyMountAt = t;
284
745
  changed = true;
285
746
  n += 1;
286
747
  }
@@ -288,12 +749,46 @@ export class LiveRegistry {
288
749
  this.kick();
289
750
  }
290
751
 
752
+ /** Release mounted artboards that are not on screen to free `need` elements; returns what it freed. */
753
+ private evictFor(need: number): number {
754
+ const victims = [...this.slots.values()]
755
+ .filter((v) => v.admitted && !v.visible && !v.pinned && !v.eager)
756
+ .sort((a, b) => Number(a.near) - Number(b.near) || b.dist - a.dist);
757
+ let freed = 0;
758
+ for (const v of victims) {
759
+ if (freed >= need) break;
760
+ freed += this.weightOf(v);
761
+ v.admitted = false;
762
+ v.live = false;
763
+ v.media = false;
764
+ this.notify('', v);
765
+ }
766
+ return freed;
767
+ }
768
+
291
769
  private notify(_id: string, s: Slot): void {
292
- if (s.view.live === s.live && s.view.seen === s.admitted) return;
293
- s.view = Object.freeze({ live: s.live, seen: s.admitted });
770
+ if (s.view.live === s.live && s.view.seen === s.admitted && s.view.media === s.media) return;
771
+ const c = this.churn;
772
+ if (s.admitted !== s.view.seen) {
773
+ if (s.admitted) c.mounts += 1;
774
+ else c.releases += 1;
775
+ }
776
+ if (this.interacting) {
777
+ if (s.admitted && !s.view.seen) c.gestureMounts += 1;
778
+ if ((!s.live && s.view.live) || (!s.admitted && s.view.seen) || (!s.media && s.view.media))
779
+ c.gestureDowns += 1;
780
+ }
781
+ s.view = Object.freeze({ live: s.live, seen: s.admitted, media: s.media });
294
782
  for (const fn of s.subs) fn(s.view);
295
783
  }
296
784
 
785
+ private churn = { mounts: 0, releases: 0, gestureMounts: 0, gestureDowns: 0 };
786
+
787
+ /** Ring churn since the open: mounts, releases, and what changed mid-gesture (2.0.7 — the measurement). */
788
+ churnStats(): { mounts: number; releases: number; gestureMounts: number; gestureDowns: number } {
789
+ return { ...this.churn };
790
+ }
791
+
297
792
  private emit(): void {
298
793
  for (const fn of this.listeners) fn();
299
794
  }