@1agh/maude 2.0.3 → 2.0.6
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.
- package/README.md +6 -5
- package/apps/hub/src/project-transactions/kernel.mjs +10 -1
- package/apps/studio/access/filters.ts +12 -5
- package/apps/studio/access/known-canvases.ts +24 -1
- package/apps/studio/access/refused-inputs.ts +89 -0
- package/apps/studio/access/request.ts +0 -1
- package/apps/studio/acp/adapter-stderr.ts +43 -13
- package/apps/studio/acp/background-tasks.ts +155 -0
- package/apps/studio/acp/bridge.ts +44 -5
- package/apps/studio/acp/connected-fact.ts +15 -4
- package/apps/studio/acp/index.ts +14 -5
- package/apps/studio/actions/agents.ts +10 -0
- package/apps/studio/actions/defs/app.ts +12 -0
- package/apps/studio/actions/defs/view.ts +12 -0
- package/apps/studio/actions.manifest.json +25 -1
- package/apps/studio/actions.parity.json +13 -1
- package/apps/studio/annotations/ui/element-node.tsx +139 -54
- package/apps/studio/annotations/ui/lod.tsx +1 -1
- package/apps/studio/annotations/ui/text-style.ts +1 -1
- package/apps/studio/annotations-layer.tsx +0 -12
- package/apps/studio/api.ts +73 -24
- package/apps/studio/artboard-live-gate.tsx +267 -0
- package/apps/studio/artboard-live.ts +336 -0
- package/apps/studio/artboard-webgl.ts +668 -0
- package/apps/studio/bin/_agent-browser-bin.mjs +8 -0
- package/apps/studio/bin/_agent-browser-safe.mjs +2 -1
- package/apps/studio/bin/_canvas-reasons.mjs +34 -0
- package/apps/studio/bin/_ds-check-live.mjs +37 -0
- package/apps/studio/bin/_ds-check.mjs +4 -1
- package/apps/studio/bin/_ds-prove-judge.mjs +167 -0
- package/apps/studio/bin/_ds-prove-playwright.mjs +183 -105
- package/apps/studio/bin/_import-asset.mjs +2 -1
- package/apps/studio/bin/_perf-probe.mjs +2 -1
- package/apps/studio/bin/_png-playwright.mjs +10 -1
- package/apps/studio/bin/_pw-launch.mjs +14 -0
- package/apps/studio/bin/_studio-verb.mjs +24 -3
- package/apps/studio/bin/_thumb-blank.mjs +70 -0
- package/apps/studio/bin/_thumb-cover.mjs +35 -0
- package/apps/studio/bin/_thumbs-playwright.mjs +93 -13
- package/apps/studio/bin/ds-check.sh +5 -1
- package/apps/studio/bin/perf.sh +11 -1
- package/apps/studio/bin/server-up.sh +7 -2
- package/apps/studio/bin/smoke.sh +19 -0
- package/apps/studio/boot-progress.ts +31 -0
- package/apps/studio/canvas-build-sandbox.ts +275 -42
- package/apps/studio/canvas-build-worker.ts +10 -0
- package/apps/studio/canvas-create.ts +24 -0
- package/apps/studio/canvas-lib.tsx +131 -12
- package/apps/studio/canvas-module-cache.ts +93 -0
- package/apps/studio/canvas-source/errors.ts +39 -0
- package/apps/studio/canvas-source/waiting.ts +290 -0
- package/apps/studio/client/actions/shell-key-handlers.js +5 -0
- package/apps/studio/client/app.jsx +19 -9
- package/apps/studio/client/canvas-url.js +13 -0
- package/apps/studio/client/github.js +23 -3
- package/apps/studio/client/home/HomeAccounts.jsx +262 -0
- package/apps/studio/client/home/Shelves.jsx +4 -3
- package/apps/studio/client/home/home-accounts-model.js +121 -0
- package/apps/studio/client/home/home-api.js +36 -19
- package/apps/studio/client/home/home-app.jsx +141 -40
- package/apps/studio/client/home/home-model.js +172 -6
- package/apps/studio/client/home/home.css +169 -5
- package/apps/studio/client/home/shell-mode.js +8 -1
- package/apps/studio/client/hooks/use-git-actions.jsx +2 -1
- package/apps/studio/client/hooks/use-project-data.jsx +2 -0
- package/apps/studio/client/hooks/use-shell-core.jsx +3 -0
- package/apps/studio/client/hooks/use-tabs.jsx +64 -35
- package/apps/studio/client/index-loader.ts +23 -3
- package/apps/studio/client/panels/ChatPanel.jsx +49 -57
- package/apps/studio/client/panels/CreateProject.jsx +19 -5
- package/apps/studio/client/panels/DiffView.jsx +314 -248
- package/apps/studio/client/panels/TeamProjects.jsx +119 -69
- package/apps/studio/client/panels/acp-runtime.js +25 -0
- package/apps/studio/client/panels/caps-cache.js +46 -0
- package/apps/studio/client/panels/chat-finish.js +66 -0
- package/apps/studio/client/shell/frame-cap.js +53 -0
- package/apps/studio/client/shell/viewport.jsx +45 -8
- package/apps/studio/client/styles/_index.css +2 -0
- package/apps/studio/client/tree/tree.jsx +48 -21
- package/apps/studio/client/v2/access/access-client.js +2 -0
- package/apps/studio/client/v2/access/access-host.jsx +12 -1
- package/apps/studio/client/v2/access/trashed-banner.jsx +6 -3
- package/apps/studio/client/v2/ai/Advanced.jsx +12 -0
- package/apps/studio/client/v2/ai/BackgroundStrip.jsx +120 -0
- package/apps/studio/client/v2/ai/Composer.jsx +27 -10
- package/apps/studio/client/v2/ai/StoppedDivider.jsx +2 -1
- package/apps/studio/client/v2/ai/ai-run.css +87 -3
- package/apps/studio/client/v2/ai/background-model.js +113 -0
- package/apps/studio/client/v2/ai/needs-you-store.js +2 -1
- package/apps/studio/client/v2/ai/run-api.js +7 -3
- package/apps/studio/client/v2/ai/runs-store.js +2 -1
- package/apps/studio/client/v2/annotations/vote-store.js +11 -5
- package/apps/studio/client/v2/assets/asset-state-lane.js +6 -3
- package/apps/studio/client/v2/assets/assets-bus.js +10 -8
- package/apps/studio/client/v2/assets/browse-view.jsx +2 -0
- package/apps/studio/client/v2/assets/ds-library-view.jsx +47 -0
- package/apps/studio/client/v2/assets/spotlight-model.js +75 -0
- package/apps/studio/client/v2/assets/spotlight.css +153 -0
- package/apps/studio/client/v2/assets/spotlight.jsx +199 -0
- package/apps/studio/client/v2/assets/tile-menu.jsx +3 -1
- package/apps/studio/client/v2/assets/tile.jsx +3 -0
- package/apps/studio/client/v2/assets/use-assets.js +2 -1
- package/apps/studio/client/v2/canvases/canvases-panel.jsx +13 -2
- package/apps/studio/client/v2/canvases/covers.js +11 -5
- package/apps/studio/client/v2/canvases/folder-ask.js +139 -0
- package/apps/studio/client/v2/canvases/folder-dialogs.jsx +150 -0
- package/apps/studio/client/v2/canvases/trash-canvas.js +10 -2
- package/apps/studio/client/v2/canvases/trash-queue.js +152 -0
- package/apps/studio/client/v2/canvases/use-canvas-index.js +42 -18
- package/apps/studio/client/v2/canvases/use-pins.js +2 -1
- package/apps/studio/client/v2/code/canvas-error-card.jsx +70 -5
- package/apps/studio/client/v2/code/canvas-imports-card.jsx +15 -14
- package/apps/studio/client/v2/code/canvas-imports-words.js +44 -0
- package/apps/studio/client/v2/code/canvas-waiting-card.jsx +128 -0
- package/apps/studio/client/v2/code/canvas-waiting.js +164 -0
- package/apps/studio/client/v2/code/code-bus.js +5 -0
- package/apps/studio/client/v2/code/code.css +67 -0
- package/apps/studio/client/v2/code/use-canvas-source.js +19 -4
- package/apps/studio/client/v2/create/NameDialog.jsx +4 -2
- package/apps/studio/client/v2/create/name-dialog.css +10 -0
- package/apps/studio/client/v2/ds/advanced-host.jsx +11 -23
- package/apps/studio/client/v2/ds/ds-refresh.js +161 -0
- package/apps/studio/client/v2/ds/library-host.jsx +45 -45
- package/apps/studio/client/v2/ds/make-host.jsx +13 -12
- package/apps/studio/client/v2/ds/off-system-host.jsx +18 -16
- package/apps/studio/client/v2/ds/review-host.jsx +7 -1
- package/apps/studio/client/v2/ds/truth-host.jsx +15 -14
- package/apps/studio/client/v2/ds/upgrade-host.jsx +26 -10
- package/apps/studio/client/v2/empty/arriving.jsx +29 -12
- package/apps/studio/client/v2/empty/empty-host.jsx +8 -2
- package/apps/studio/client/v2/empty/not-local.jsx +31 -1
- package/apps/studio/client/v2/empty/use-empty-canvas.js +10 -1
- package/apps/studio/client/v2/export/last-finished.js +2 -1
- package/apps/studio/client/v2/history/branch-actions.js +13 -9
- package/apps/studio/client/v2/history/git-advanced.jsx +8 -1
- package/apps/studio/client/v2/history/git-model.js +21 -5
- package/apps/studio/client/v2/history/git-parts.jsx +76 -43
- package/apps/studio/client/v2/history/history.css +6 -0
- package/apps/studio/client/v2/left-panel/assets-panel.jsx +87 -10
- package/apps/studio/client/v2/left-panel/use-trash.js +2 -1
- package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +100 -33
- package/apps/studio/client/v2/onboarding/HubSheet.jsx +51 -83
- package/apps/studio/client/v2/onboarding/onboarding-model.js +10 -6
- package/apps/studio/client/v2/presence/faces.jsx +42 -14
- package/apps/studio/client/v2/present/order-notes-artboards.js +2 -1
- package/apps/studio/client/v2/search/search-recent.js +3 -1
- package/apps/studio/client/v2/search/search-remote.js +6 -4
- package/apps/studio/client/v2/settings/connections-model.js +1 -1
- package/apps/studio/client/v2/shell/account-card.jsx +10 -4
- package/apps/studio/client/v2/shell/canvas-crash-guard.js +137 -0
- package/apps/studio/client/v2/shell/github-signin-host.jsx +42 -0
- package/apps/studio/client/v2/shell/menu-runner.js +12 -0
- package/apps/studio/client/v2/shell/occlusion-insets.js +14 -2
- package/apps/studio/client/v2/shell/project-account-card.jsx +203 -0
- package/apps/studio/client/v2/shell/project-account-model.js +182 -0
- package/apps/studio/client/v2/shell/recovery-store.js +2 -1
- package/apps/studio/client/v2/shell/served-routes.js +120 -0
- package/apps/studio/client/v2/shell/share-cluster-host.jsx +139 -11
- package/apps/studio/client/v2/shell/share-cluster.css +58 -0
- package/apps/studio/client/v2/shell/share-cluster.jsx +26 -7
- package/apps/studio/client/v2/shell/shell-activity.js +19 -0
- package/apps/studio/client/v2/shell/team-switch.js +94 -0
- package/apps/studio/client/v2/shell/too-heavy-card.jsx +38 -0
- package/apps/studio/client/v2/shell/use-account.js +8 -1
- package/apps/studio/client/v2/shell/use-occluded-insets.js +3 -0
- package/apps/studio/client/v2/sync-states/conflict-card.jsx +7 -2
- package/apps/studio/client/v2/undo/use-undo-projection.jsx +3 -1
- package/apps/studio/cloud/endpoints.ts +23 -1
- package/apps/studio/collab/persistence.ts +9 -1
- package/apps/studio/collab/registry.ts +32 -0
- package/apps/studio/collab/room.ts +8 -0
- package/apps/studio/config-reload-wire.ts +53 -0
- package/apps/studio/dist/client.bundle.js +1098 -1102
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/ds/board/specimen.tsx +12 -1
- package/apps/studio/ds/canvas-cli.ts +58 -2
- package/apps/studio/ds/check.ts +26 -1
- package/apps/studio/ds/cli.ts +7 -3
- package/apps/studio/ds/convert.ts +34 -6
- package/apps/studio/ds/ds-verb.ts +13 -0
- package/apps/studio/ds/post-build.ts +38 -0
- package/apps/studio/ds/upgrade-apply.ts +27 -5
- package/apps/studio/ds/upgrade-cli.ts +22 -2
- package/apps/studio/ds/upgrade-prove.ts +198 -15
- package/apps/studio/ds/upgrade-stage.ts +4 -1
- package/apps/studio/editing/minimap-context.tsx +3 -3
- package/apps/studio/editing/page-activity.ts +251 -0
- package/apps/studio/editing/rotate-handle.tsx +9 -5
- package/apps/studio/editing/sticky-name.tsx +4 -4
- package/apps/studio/history/restore-artboard-action.ts +40 -0
- package/apps/studio/history/trash.ts +6 -0
- package/apps/studio/home/accounts.ts +87 -0
- package/apps/studio/home/hub.ts +77 -175
- package/apps/studio/home/index-reader.ts +24 -2
- package/apps/studio/home/routes.ts +66 -8
- package/apps/studio/http.ts +131 -68
- package/apps/studio/index-flight.ts +40 -0
- package/apps/studio/managed-projects.ts +52 -24
- package/apps/studio/migrate/hub.ts +7 -1
- package/apps/studio/routes/canvas-source.ts +44 -2
- package/apps/studio/routes/ds-convert.ts +18 -0
- package/apps/studio/routes/history.ts +28 -5
- package/apps/studio/routes/hub-signin.ts +115 -0
- package/apps/studio/routes/index.ts +4 -0
- package/apps/studio/routes/table.ts +7 -0
- package/apps/studio/routes/trash.ts +19 -1
- package/apps/studio/server.ts +19 -10
- package/apps/studio/sync/accepted-cold-start.ts +54 -16
- package/apps/studio/sync/accepted-link.ts +9 -4
- package/apps/studio/sync/asset-push.ts +146 -23
- package/apps/studio/sync/asset-state.ts +3 -2
- package/apps/studio/sync/code-module-consent.ts +74 -0
- package/apps/studio/sync/file-ledger.ts +35 -0
- package/apps/studio/sync/file-membership.ts +28 -3
- package/apps/studio/sync/file-plane.ts +483 -86
- package/apps/studio/sync/file-pull.ts +304 -33
- package/apps/studio/sync/hub-browser-signin.ts +377 -0
- package/apps/studio/sync/hub-link.ts +1 -2
- package/apps/studio/sync/hub-text-undo.ts +30 -10
- package/apps/studio/sync/index.ts +381 -161
- package/apps/studio/sync/journal-client.ts +94 -5
- package/apps/studio/sync/pending-deletes.ts +100 -0
- package/apps/studio/sync/projection.ts +121 -14
- package/apps/studio/sync/pull-pacer.ts +160 -0
- package/apps/studio/sync/pull-priority.ts +119 -0
- package/apps/studio/sync/seed-progress.ts +58 -3
- package/apps/studio/sync/status.ts +3 -1
- package/apps/studio/sync/transaction-client.ts +71 -6
- package/apps/studio/sync/workspace-signin.ts +6 -256
- package/apps/studio/sync/writer-registry.ts +5 -1
- package/apps/studio/thumbs/service.ts +12 -2
- package/apps/studio/thumbs/validate.ts +7 -0
- package/apps/studio/ui-prefs-migrate.ts +4 -0
- package/apps/studio/video-comp.tsx +23 -0
- package/apps/studio/video-links-overlay.tsx +3 -2
- package/apps/studio/whats-new.json +126 -0
- package/cli/lib/bash-guard.mjs +13 -1
- package/cli/lib/design-help.gen.mjs +1 -1
- package/cli/lib/design-hook.mjs +20 -0
- package/cli/lib/studio-locate.mjs +35 -10
- package/cli/lib/workspace-plan.mjs +14 -0
- package/package.json +8 -8
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file artboard-live.ts — 2.0.5: heavy canvases must not crash the tab
|
|
3
|
+
* @scope apps/studio/artboard-live.ts (React-free core; the React half is artboard-live-gate.tsx)
|
|
4
|
+
* @purpose Decides which artboards of an open canvas run LIVE. A canvas with 88 three.js scenes or 30
|
|
5
|
+
* artboards of decoding video ran every one of them at once, and WebKit killed the page.
|
|
6
|
+
*
|
|
7
|
+
* An artboard is LIVE when it is near the viewport AND the canvas is not in its overview
|
|
8
|
+
* (zoomed out below `LIVE_MIN_ZOOM`, the annotation mosaic's own cut-over, or more than
|
|
9
|
+
* `LIVE_MAX_VISIBLE` artboards on screen at once). A sleeping artboard keeps its DOM and its
|
|
10
|
+
* size; what stops is its heavy content: WebGL contexts (lost, with a snapshot of the last
|
|
11
|
+
* frame), `<video>` (paused), CSS animations (paused), `VideoComp` players (paused) and anything
|
|
12
|
+
* a canvas gates on `useArtboardActive()`.
|
|
13
|
+
*
|
|
14
|
+
* Artboards come back a few per frame (`WAKE_PER_FRAME`) and only once a gesture settles, so a
|
|
15
|
+
* pan never pays for re-starting a dozen scenes at once. The first mount of an artboard's
|
|
16
|
+
* children waits for the same queue in `light` mode (and for `useArtboardSeen()` consumers —
|
|
17
|
+
* the design-system board's specimens), so a canvas never builds what nobody looked at.
|
|
18
|
+
*
|
|
19
|
+
* Captures render EVERYTHING: the mode is `off` for every headless/export render (top-level
|
|
20
|
+
* page, `?hide-chrome=1`, `?thumb-only=`), and the in-frame export (`export-capture`) wakes
|
|
21
|
+
* every artboard for the length of the capture (`forceAll`).
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { LOD_ZOOM } from './annotations/ui/lod.tsx';
|
|
25
|
+
|
|
26
|
+
/** Below this (published) zoom the canvas is in its overview: nothing runs live. Same cut-over as the annotation mosaic. */
|
|
27
|
+
export const LIVE_MIN_ZOOM = LOD_ZOOM;
|
|
28
|
+
/** More artboards than this on screen at once is an overview too, whatever the zoom. */
|
|
29
|
+
export const LIVE_MAX_VISIBLE = 16;
|
|
30
|
+
/** At most this many WebGL contexts per canvas stay live — well under the browsers' hard limit (~16). */
|
|
31
|
+
export const WEBGL_LIVE_CAP = 8;
|
|
32
|
+
/** How far past the viewport an artboard still counts as near (IntersectionObserver rootMargin). */
|
|
33
|
+
export const NEAR_MARGIN = '50%';
|
|
34
|
+
/** How many artboards wake (or first mount) per animation frame. */
|
|
35
|
+
export const WAKE_PER_FRAME = 3;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* `off` — every artboard live, every child mounted (captures, exports, headless, tests): the pre-2.0.5 behaviour.
|
|
39
|
+
* `sleep` — the studio default: offscreen / overview artboards sleep, their DOM stays mounted.
|
|
40
|
+
* `light` — "Show visible artboards only" after a crash: an artboard's children mount only while it is live
|
|
41
|
+
* (near the viewport and the canvas not in its overview).
|
|
42
|
+
*/
|
|
43
|
+
export type LiveMode = 'off' | 'sleep' | 'light';
|
|
44
|
+
|
|
45
|
+
/** The frame parameter that picks a mode explicitly (`?artboard-live=off|sleep|light`). */
|
|
46
|
+
export const LIVE_PARAM = 'artboard-live';
|
|
47
|
+
|
|
48
|
+
export function resolveLiveMode(env: { search: string; embedded: boolean }): LiveMode {
|
|
49
|
+
const p = new URLSearchParams(env.search);
|
|
50
|
+
// A capture — whoever asks for it — renders every artboard live. This wins over an explicit mode.
|
|
51
|
+
if (p.get('hide-chrome') === '1' || p.has('thumb-only')) return 'off';
|
|
52
|
+
const explicit = p.get(LIVE_PARAM);
|
|
53
|
+
if (explicit === 'off' || explicit === 'sleep' || explicit === 'light') return explicit;
|
|
54
|
+
// Only the studio frames a canvas. A top-level canvas page is a headless render (screenshot,
|
|
55
|
+
// smoke, canvas-rects, perf without --studio) or someone opening the shell URL by hand: all live.
|
|
56
|
+
return env.embedded ? 'sleep' : 'off';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The overview: zoomed out past the mosaic cut-over, or too many artboards on screen at once. */
|
|
60
|
+
export function inOverview(zoom: number, visibleCount: number): boolean {
|
|
61
|
+
return (zoom > 0 && zoom < LIVE_MIN_ZOOM) || visibleCount > LIVE_MAX_VISIBLE;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Whether one artboard should be live. `forceAll` (a capture in progress) always wins. */
|
|
65
|
+
export function decideLive(s: {
|
|
66
|
+
near: boolean;
|
|
67
|
+
zoom: number;
|
|
68
|
+
visibleCount: number;
|
|
69
|
+
forceAll: boolean;
|
|
70
|
+
}): boolean {
|
|
71
|
+
if (s.forceAll) return true;
|
|
72
|
+
if (!s.near) return false;
|
|
73
|
+
return !inOverview(s.zoom, s.visibleCount);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface ArtboardLiveState {
|
|
77
|
+
/** Runs its heavy content. */
|
|
78
|
+
live: boolean;
|
|
79
|
+
/** Its children may be mounted (always true in `sleep`/`off` once seen; follows `live` in `light`). */
|
|
80
|
+
seen: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface Slot {
|
|
84
|
+
near: boolean;
|
|
85
|
+
visible: boolean;
|
|
86
|
+
admitted: boolean;
|
|
87
|
+
live: boolean;
|
|
88
|
+
/** The last state handed out — one object per change, so React's external store sees a stable snapshot. */
|
|
89
|
+
view: ArtboardLiveState;
|
|
90
|
+
subs: Set<(s: ArtboardLiveState) => void>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const ASLEEP: ArtboardLiveState = Object.freeze({ live: false, seen: false });
|
|
94
|
+
|
|
95
|
+
const ALL_LIVE: ArtboardLiveState = Object.freeze({ live: true, seen: true });
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* One per canvas document. Fed by two IntersectionObservers (near / visible), the published zoom and the
|
|
99
|
+
* gesture flag; artboards subscribe by id. Sleeping is immediate; waking goes through a queue drained
|
|
100
|
+
* `WAKE_PER_FRAME` at a time on `schedule` (rAF in the browser), and holds while a gesture is in flight.
|
|
101
|
+
*/
|
|
102
|
+
export class LiveRegistry {
|
|
103
|
+
readonly mode: LiveMode;
|
|
104
|
+
private slots = new Map<string, Slot>();
|
|
105
|
+
private zoom = 1;
|
|
106
|
+
private interacting = false;
|
|
107
|
+
private forceAll = 0;
|
|
108
|
+
private pending = new Set<string>();
|
|
109
|
+
private scheduled = false;
|
|
110
|
+
private readonly schedule: (fn: () => void) => void;
|
|
111
|
+
private listeners = new Set<() => void>();
|
|
112
|
+
|
|
113
|
+
constructor(mode: LiveMode, schedule: (fn: () => void) => void) {
|
|
114
|
+
this.mode = mode;
|
|
115
|
+
this.schedule = schedule;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
get(id: string): ArtboardLiveState {
|
|
119
|
+
if (this.mode === 'off') return ALL_LIVE;
|
|
120
|
+
return this.slots.get(id)?.view ?? ASLEEP;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
isLive(id: string): boolean {
|
|
124
|
+
return this.get(id).live;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Any change at all (the WebGL budget re-plans on it). */
|
|
128
|
+
onChange(fn: () => void): () => void {
|
|
129
|
+
this.listeners.add(fn);
|
|
130
|
+
return () => this.listeners.delete(fn);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
subscribe(id: string, fn: (s: ArtboardLiveState) => void): () => void {
|
|
134
|
+
const s = this.slot(id);
|
|
135
|
+
s.subs.add(fn);
|
|
136
|
+
return () => {
|
|
137
|
+
s.subs.delete(fn);
|
|
138
|
+
if (s.subs.size === 0) {
|
|
139
|
+
this.slots.delete(id);
|
|
140
|
+
this.pending.delete(id);
|
|
141
|
+
this.recompute();
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
setNear(id: string, near: boolean): void {
|
|
147
|
+
const s = this.slot(id);
|
|
148
|
+
if (s.near === near) return;
|
|
149
|
+
s.near = near;
|
|
150
|
+
this.recompute();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
setVisible(id: string, visible: boolean): void {
|
|
154
|
+
const s = this.slot(id);
|
|
155
|
+
if (s.visible === visible) return;
|
|
156
|
+
s.visible = visible;
|
|
157
|
+
this.recompute();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
setZoom(zoom: number): void {
|
|
161
|
+
if (!Number.isFinite(zoom) || zoom === this.zoom) return;
|
|
162
|
+
this.zoom = zoom;
|
|
163
|
+
this.recompute();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
setInteracting(on: boolean): void {
|
|
167
|
+
if (on === this.interacting) return;
|
|
168
|
+
this.interacting = on;
|
|
169
|
+
if (!on) this.kick();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** A capture is running: everything live, NOW (no queue). Returns the release. */
|
|
173
|
+
holdAllLive(): () => void {
|
|
174
|
+
this.forceAll += 1;
|
|
175
|
+
this.recompute();
|
|
176
|
+
let released = false;
|
|
177
|
+
return () => {
|
|
178
|
+
if (released) return;
|
|
179
|
+
released = true;
|
|
180
|
+
this.forceAll -= 1;
|
|
181
|
+
this.recompute();
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
visibleCount(): number {
|
|
186
|
+
let n = 0;
|
|
187
|
+
for (const s of this.slots.values()) if (s.visible) n += 1;
|
|
188
|
+
return n;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private slot(id: string): Slot {
|
|
192
|
+
let s = this.slots.get(id);
|
|
193
|
+
if (!s) {
|
|
194
|
+
s = {
|
|
195
|
+
near: false,
|
|
196
|
+
visible: false,
|
|
197
|
+
admitted: false,
|
|
198
|
+
live: false,
|
|
199
|
+
view: ASLEEP,
|
|
200
|
+
subs: new Set(),
|
|
201
|
+
};
|
|
202
|
+
this.slots.set(id, s);
|
|
203
|
+
}
|
|
204
|
+
return s;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private target(s: Slot): { live: boolean; admitted: boolean } {
|
|
208
|
+
const force = this.forceAll > 0;
|
|
209
|
+
const live = decideLive({
|
|
210
|
+
near: s.near,
|
|
211
|
+
zoom: this.zoom,
|
|
212
|
+
visibleCount: this.visibleCount(),
|
|
213
|
+
forceAll: force,
|
|
214
|
+
});
|
|
215
|
+
// `sleep` mounts what came near and keeps it. `light` (after a crash) mounts only what is LIVE — near and
|
|
216
|
+
// 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 };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private recompute(): void {
|
|
223
|
+
if (this.mode === 'off') return;
|
|
224
|
+
const force = this.forceAll > 0;
|
|
225
|
+
let changed = false;
|
|
226
|
+
for (const [id, s] of this.slots) {
|
|
227
|
+
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) {
|
|
231
|
+
s.live = t.live;
|
|
232
|
+
s.admitted = t.admitted;
|
|
233
|
+
this.pending.delete(id);
|
|
234
|
+
this.notify(id, s);
|
|
235
|
+
changed = true;
|
|
236
|
+
} else if (goesUp) {
|
|
237
|
+
if (force) {
|
|
238
|
+
s.live = t.live;
|
|
239
|
+
s.admitted = t.admitted;
|
|
240
|
+
this.pending.delete(id);
|
|
241
|
+
this.notify(id, s);
|
|
242
|
+
changed = true;
|
|
243
|
+
} else {
|
|
244
|
+
// 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;
|
|
247
|
+
this.notify(id, s);
|
|
248
|
+
changed = true;
|
|
249
|
+
}
|
|
250
|
+
this.pending.add(id);
|
|
251
|
+
}
|
|
252
|
+
} else {
|
|
253
|
+
this.pending.delete(id);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (changed) this.emit();
|
|
257
|
+
this.kick();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
private kick(): void {
|
|
261
|
+
if (this.scheduled || this.pending.size === 0 || this.interacting) return;
|
|
262
|
+
this.scheduled = true;
|
|
263
|
+
this.schedule(() => {
|
|
264
|
+
this.scheduled = false;
|
|
265
|
+
this.drain();
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** One frame's worth of wakes. Exposed for tests (the browser drains on rAF). */
|
|
270
|
+
drain(): void {
|
|
271
|
+
if (this.interacting) return;
|
|
272
|
+
let n = 0;
|
|
273
|
+
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;
|
|
283
|
+
this.notify(id, s);
|
|
284
|
+
changed = true;
|
|
285
|
+
n += 1;
|
|
286
|
+
}
|
|
287
|
+
if (changed) this.emit();
|
|
288
|
+
this.kick();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
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 });
|
|
294
|
+
for (const fn of s.subs) fn(s.view);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
private emit(): void {
|
|
298
|
+
for (const fn of this.listeners) fn();
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ── WebGL budget ───────────────────────────────────────────────────────────────────────────────────
|
|
303
|
+
|
|
304
|
+
export interface GlCandidate {
|
|
305
|
+
key: number;
|
|
306
|
+
/** Its artboard is live (a canvas outside any artboard counts as live). */
|
|
307
|
+
live: boolean;
|
|
308
|
+
/** Distance of its centre to the viewport centre, in screen px. */
|
|
309
|
+
distance: number;
|
|
310
|
+
/** Last time it was kept live (ms) — the LRU tie-break. */
|
|
311
|
+
lastLive: number;
|
|
312
|
+
/** Currently lost by us. */
|
|
313
|
+
lost: boolean;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Which contexts to lose and which to restore: of the live artboards' canvases, the `cap` nearest the
|
|
318
|
+
* viewport centre (ties: most recently live) stay; every other context is released.
|
|
319
|
+
*/
|
|
320
|
+
export function planWebgl(
|
|
321
|
+
entries: readonly GlCandidate[],
|
|
322
|
+
cap: number = WEBGL_LIVE_CAP
|
|
323
|
+
): { lose: number[]; restore: number[] } {
|
|
324
|
+
const ranked = entries
|
|
325
|
+
.filter((e) => e.live)
|
|
326
|
+
.sort((a, b) => a.distance - b.distance || b.lastLive - a.lastLive);
|
|
327
|
+
const keep = new Set(ranked.slice(0, Math.max(0, cap)).map((e) => e.key));
|
|
328
|
+
const lose: number[] = [];
|
|
329
|
+
const restore: number[] = [];
|
|
330
|
+
for (const e of entries) {
|
|
331
|
+
if (keep.has(e.key)) {
|
|
332
|
+
if (e.lost) restore.push(e.key);
|
|
333
|
+
} else if (!e.lost) lose.push(e.key);
|
|
334
|
+
}
|
|
335
|
+
return { lose, restore };
|
|
336
|
+
}
|