@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
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
// Output: `diff.json` (every measurement) and `review.json` (the four SCHEMA_FIX lines) beside the
|
|
17
17
|
// stage record.
|
|
18
18
|
|
|
19
|
-
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
19
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
20
20
|
import { tmpdir } from 'node:os';
|
|
21
21
|
import { basename, dirname, join } from 'node:path';
|
|
22
22
|
import type { Subprocess } from 'bun';
|
|
23
23
|
import { exportShimPath, spawnShim } from '../exporters/_runtime.ts';
|
|
24
|
-
import { DEV_SERVER_ROOT } from '../paths.ts';
|
|
24
|
+
import { DEV_SERVER_ROOT, IS_COMPILED_BINARY } from '../paths.ts';
|
|
25
25
|
import { checkCanvas } from './canvas-check.ts';
|
|
26
26
|
import { canvasContext, listCanvases } from './canvas-cli.ts';
|
|
27
27
|
import { systemConfigsFrom } from './system.ts';
|
|
@@ -46,11 +46,15 @@ export const DIFF_FORMAT = 'maude.ds-upgrade-diff';
|
|
|
46
46
|
export const REVIEW_FORMAT = 'maude.ds-upgrade-review';
|
|
47
47
|
export const DELTA_E = 2;
|
|
48
48
|
export const FAIL_RATIO = 0.005;
|
|
49
|
+
/** one canvas's hard deadline in the visual gate */
|
|
50
|
+
export const CANVAS_TIMEOUT = 180_000;
|
|
49
51
|
|
|
50
52
|
export interface RenderCanvas {
|
|
51
53
|
path: string;
|
|
52
54
|
tokens: string | null;
|
|
53
55
|
components: string | null;
|
|
56
|
+
/** the system's themes: an artboard that carries none of its own is measured in each */
|
|
57
|
+
themes?: string[];
|
|
54
58
|
}
|
|
55
59
|
export interface RenderJob {
|
|
56
60
|
before: string;
|
|
@@ -59,6 +63,8 @@ export interface RenderJob {
|
|
|
59
63
|
deltaE: number;
|
|
60
64
|
ratio: number;
|
|
61
65
|
timeout: number;
|
|
66
|
+
/** the hard deadline of one canvas (ms): past it the canvas is `timeout` and the run goes on */
|
|
67
|
+
canvasTimeout?: number;
|
|
62
68
|
}
|
|
63
69
|
export interface ArtboardDiff {
|
|
64
70
|
id: string;
|
|
@@ -69,9 +75,23 @@ export interface ArtboardDiff {
|
|
|
69
75
|
area?: number;
|
|
70
76
|
fail: boolean;
|
|
71
77
|
reason?: string;
|
|
78
|
+
/** failed before x after, but before x before failed alike: the gate's own noise, not a change */
|
|
79
|
+
noise?: boolean;
|
|
80
|
+
/** nothing rendered on either side */
|
|
81
|
+
empty?: boolean;
|
|
82
|
+
/** before x before (the noise control), when it ran */
|
|
83
|
+
control?: { changed: number; area: number; sized: boolean };
|
|
72
84
|
}
|
|
73
85
|
export interface RenderResult {
|
|
74
|
-
canvases: {
|
|
86
|
+
canvases: {
|
|
87
|
+
path: string;
|
|
88
|
+
/** before / after: that side showed an error; render: the gate threw; timeout: no answer */
|
|
89
|
+
error?: string;
|
|
90
|
+
detail?: string;
|
|
91
|
+
/** no artboard: the canvas's whole mount was measured */
|
|
92
|
+
specimen?: boolean;
|
|
93
|
+
artboards: ArtboardDiff[];
|
|
94
|
+
}[];
|
|
75
95
|
}
|
|
76
96
|
|
|
77
97
|
export interface Studio {
|
|
@@ -114,18 +134,117 @@ export interface Review {
|
|
|
114
134
|
keepsOwn: { native: string; as: string }[];
|
|
115
135
|
updatesCanvases: { path: string; edits: number; diff: 'pass' | 'fail' }[];
|
|
116
136
|
refused: { path: string; reason: string }[];
|
|
137
|
+
/** canvases the gate could not measure (a timeout, a broken before): they block nothing, and a
|
|
138
|
+
* codemod on one is not applied (it is in `refused` too) */
|
|
139
|
+
unmeasured?: { path: string; reason: string }[];
|
|
117
140
|
needsPick: string[];
|
|
118
141
|
}
|
|
119
142
|
|
|
120
143
|
/* ------------------------------------------------------------- studios */
|
|
121
144
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (!
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
145
|
+
/** A compiled studio by its shape: the desktop sidecar `maude-server`, or npm's `maude-<slug>/maude`. */
|
|
146
|
+
export function isCompiledStudioBinary(p: string | undefined | null): boolean {
|
|
147
|
+
if (!p) return false;
|
|
148
|
+
const b = basename(p);
|
|
149
|
+
if (b === 'maude-server' || b === 'maude-server.exe') return true;
|
|
150
|
+
return (b === 'maude' || b === 'maude.exe') && /^maude-[a-z0-9-]+$/.test(basename(dirname(p)));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface ServerResolveInput {
|
|
154
|
+
env: Record<string, string | undefined>;
|
|
155
|
+
/** this process's executable (the compiled studio, a compiled binary run as bun, or bun) */
|
|
156
|
+
execPath: string;
|
|
157
|
+
/** apps/studio as paths.ts resolved it */
|
|
158
|
+
devServerRoot: string;
|
|
159
|
+
/** true inside the compiled studio itself (paths.ts IS_COMPILED_BINARY) */
|
|
160
|
+
compiled: boolean;
|
|
161
|
+
exists: (p: string) => boolean;
|
|
162
|
+
readText?: (p: string) => string | null;
|
|
163
|
+
/** npm platform-package slugs to look for (`darwin-arm64`, `linux-x64`, `linux-x64-musl`…) */
|
|
164
|
+
platformSlugs?: string[];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface ServerCommand {
|
|
168
|
+
cmd: string[];
|
|
169
|
+
/** env the compiled studio needs to find its served tree (the desktop sidecar sets the same) */
|
|
170
|
+
env: Record<string, string>;
|
|
171
|
+
kind: 'compiled' | 'source';
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* How a staged studio is started — the same resolution the desktop sidecar and `maude design serve`
|
|
176
|
+
* use (DDR-084, DDR-177): the COMPILED studio whenever one exists, because it embeds every dependency
|
|
177
|
+
* the source server imports (the hub's transaction core, jszip, yjs…), none of which a packaged app or
|
|
178
|
+
* an npm install has on disk. Source (`bun run server.ts`) only in a dev tree, or when nothing
|
|
179
|
+
* compiled is there.
|
|
180
|
+
*
|
|
181
|
+
* 1. this process IS the compiled studio (a prove started from the studio's own route)
|
|
182
|
+
* 2. MAUDE_DEV_SERVER_BIN (the desktop sidecar hands it to every child; `maude design` to boot verbs)
|
|
183
|
+
* 3. not a dev tree: this process's executable when it is a compiled studio run as bun (the
|
|
184
|
+
* desktop's bun shim), the .app's Contents/MacOS/maude-server, npm's maude-<slug>/maude
|
|
185
|
+
* 4. server.ts from source
|
|
186
|
+
*/
|
|
187
|
+
export function resolveStudioServer(o: ServerResolveInput): ServerCommand {
|
|
188
|
+
const pkgRoot = join(o.devServerRoot, '..', '..');
|
|
189
|
+
const compiledEnv = (): Record<string, string> => ({
|
|
190
|
+
MAUDE_DEV_SERVER_ROOT: o.devServerRoot,
|
|
191
|
+
...(o.exists(join(pkgRoot, 'cli', 'commands', 'design.mjs'))
|
|
192
|
+
? { MAUDE_PKG_ROOT: pkgRoot }
|
|
193
|
+
: {}),
|
|
194
|
+
});
|
|
195
|
+
const compiled = (bin: string): ServerCommand => ({
|
|
196
|
+
cmd: [bin],
|
|
197
|
+
env: compiledEnv(),
|
|
198
|
+
kind: 'compiled',
|
|
199
|
+
});
|
|
200
|
+
if (o.compiled && !o.env.BUN_BE_BUN) return compiled(o.execPath);
|
|
201
|
+
const fromEnv = o.env.MAUDE_DEV_SERVER_BIN;
|
|
202
|
+
if (fromEnv && isCompiledStudioBinary(fromEnv) && o.exists(fromEnv)) return compiled(fromEnv);
|
|
203
|
+
const serverTs = join(o.devServerRoot, 'server.ts');
|
|
204
|
+
const devTree =
|
|
205
|
+
o.env.MAUDE_FORCE_SOURCE === '1' ||
|
|
206
|
+
o.exists(join(pkgRoot, 'packages', 'maude-darwin-arm64', 'package.json'));
|
|
207
|
+
if (!devTree) {
|
|
208
|
+
const exe = process.platform === 'win32' ? 'maude-server.exe' : 'maude-server';
|
|
209
|
+
const candidates = [
|
|
210
|
+
o.execPath,
|
|
211
|
+
join(o.devServerRoot, '..', '..', '..', 'MacOS', exe),
|
|
212
|
+
...(o.platformSlugs ?? []).map((slug) =>
|
|
213
|
+
join(pkgRoot, '..', `maude-${slug}`, process.platform === 'win32' ? 'maude.exe' : 'maude')
|
|
214
|
+
),
|
|
215
|
+
];
|
|
216
|
+
const side = o.readText?.(join(pkgRoot, 'cli', '.platform-binary-path'))?.trim();
|
|
217
|
+
if (side) candidates.push(side);
|
|
218
|
+
for (const c of candidates) if (isCompiledStudioBinary(c) && o.exists(c)) return compiled(c);
|
|
219
|
+
}
|
|
220
|
+
if (!o.exists(serverTs)) return compiled(o.execPath); // nothing else to run
|
|
221
|
+
const bun = basename(o.execPath).startsWith('bun')
|
|
222
|
+
? o.execPath
|
|
223
|
+
: (Bun.which('bun') ?? o.execPath);
|
|
224
|
+
return { cmd: [bun, 'run', serverTs], env: {}, kind: 'source' };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function platformSlugs(): string[] {
|
|
228
|
+
const base = `${process.platform}-${process.platform === 'win32' ? 'x64' : process.arch}`;
|
|
229
|
+
return process.platform === 'linux' ? [base, `${base}-musl`] : [base];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function serverCommand(): ServerCommand {
|
|
233
|
+
return resolveStudioServer({
|
|
234
|
+
env: process.env,
|
|
235
|
+
execPath: process.execPath,
|
|
236
|
+
devServerRoot: DEV_SERVER_ROOT,
|
|
237
|
+
compiled: IS_COMPILED_BINARY,
|
|
238
|
+
exists: existsSync,
|
|
239
|
+
readText: (p) => {
|
|
240
|
+
try {
|
|
241
|
+
return readFileSync(p, 'utf8');
|
|
242
|
+
} catch {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
platformSlugs: platformSlugs(),
|
|
247
|
+
});
|
|
129
248
|
}
|
|
130
249
|
|
|
131
250
|
/**
|
|
@@ -139,15 +258,33 @@ const STAGED_DROP =
|
|
|
139
258
|
export function studioEnv(
|
|
140
259
|
projectRoot: string,
|
|
141
260
|
machineFile: string,
|
|
142
|
-
from: Record<string, string | undefined> = process.env
|
|
261
|
+
from: Record<string, string | undefined> = process.env,
|
|
262
|
+
/** a throwaway home: the staged studio writes prefs (fold state…) under HOME/XDG_CONFIG_HOME,
|
|
263
|
+
* and a staged copy must never write the person's real ~/.config/maude */
|
|
264
|
+
home?: string
|
|
143
265
|
): Record<string, string> {
|
|
144
266
|
// the staged studio picks its own port, and runs as the studio (never as a bare bun)
|
|
145
267
|
const drop = new Set(['BUN_BE_BUN', 'PORT', 'MDCC_DEV_PORT']);
|
|
268
|
+
// with a throwaway home, nothing may point back at the person's own config stores
|
|
269
|
+
const homeDrop = new Set([
|
|
270
|
+
'XDG_CONFIG_HOME',
|
|
271
|
+
'HUBS_CONFIG_PATH',
|
|
272
|
+
'MAUDE_CLOUD_CONFIG',
|
|
273
|
+
'MAUDE_INDEX_DIR',
|
|
274
|
+
]);
|
|
146
275
|
const env: Record<string, string> = {};
|
|
147
276
|
for (const [k, v] of Object.entries(from))
|
|
148
|
-
if (v !== undefined && !drop.has(k) && !STAGED_DROP.test(k)
|
|
277
|
+
if (v !== undefined && !drop.has(k) && !STAGED_DROP.test(k) && !(home && homeDrop.has(k)))
|
|
278
|
+
env[k] = v;
|
|
149
279
|
return {
|
|
150
280
|
...env,
|
|
281
|
+
...(home
|
|
282
|
+
? {
|
|
283
|
+
HOME: home,
|
|
284
|
+
XDG_CONFIG_HOME: join(home, '.config'),
|
|
285
|
+
MAUDE_INDEX_DIR: join(home, 'index'),
|
|
286
|
+
}
|
|
287
|
+
: {}),
|
|
151
288
|
NO_OPEN: '1',
|
|
152
289
|
MAUDE_NO_AUTOBUILD: '1',
|
|
153
290
|
MAUDE_MACHINE_FILE: machineFile,
|
|
@@ -159,12 +296,35 @@ export function studioEnv(
|
|
|
159
296
|
export async function bootHeadlessStudio(projectRoot: string): Promise<Studio> {
|
|
160
297
|
const designRoot = join(projectRoot, '.design');
|
|
161
298
|
const scratch = mkdtempSync(join(tmpdir(), 'maude-ds-prove-machine-'));
|
|
162
|
-
|
|
299
|
+
mkdirSync(join(scratch, 'home', '.config'), { recursive: true });
|
|
300
|
+
const server = serverCommand();
|
|
301
|
+
const proc: Subprocess = Bun.spawn([...server.cmd, '--root', projectRoot, '--port', '0'], {
|
|
163
302
|
cwd: DEV_SERVER_ROOT,
|
|
164
|
-
env:
|
|
303
|
+
env: {
|
|
304
|
+
...studioEnv(projectRoot, join(scratch, 'machine.json'), process.env, join(scratch, 'home')),
|
|
305
|
+
...server.env,
|
|
306
|
+
},
|
|
165
307
|
stdout: 'ignore',
|
|
166
308
|
stderr: 'pipe',
|
|
167
309
|
});
|
|
310
|
+
// drain stderr (an unread pipe can stall a chatty child) and keep its tail for the error
|
|
311
|
+
let errTail = '';
|
|
312
|
+
void (async () => {
|
|
313
|
+
try {
|
|
314
|
+
const dec = new TextDecoder();
|
|
315
|
+
for await (const chunk of proc.stderr as ReadableStream<Uint8Array>)
|
|
316
|
+
errTail = (errTail + dec.decode(chunk)).slice(-2000);
|
|
317
|
+
} catch {
|
|
318
|
+
/* gone */
|
|
319
|
+
}
|
|
320
|
+
})();
|
|
321
|
+
const lastLine = () =>
|
|
322
|
+
errTail
|
|
323
|
+
.trim()
|
|
324
|
+
.split('\n')
|
|
325
|
+
.filter((l) => l.trim())
|
|
326
|
+
.at(-1)
|
|
327
|
+
?.slice(0, 240) ?? '';
|
|
168
328
|
const stop = async () => {
|
|
169
329
|
const exited = proc.exited.then(
|
|
170
330
|
() => true,
|
|
@@ -189,7 +349,13 @@ export async function bootHeadlessStudio(projectRoot: string): Promise<Studio> {
|
|
|
189
349
|
try {
|
|
190
350
|
const started = Date.now();
|
|
191
351
|
while (Date.now() - started < 60000) {
|
|
192
|
-
if (proc.exitCode !== null)
|
|
352
|
+
if (proc.exitCode !== null) {
|
|
353
|
+
await Bun.sleep(50); // the last stderr chunk
|
|
354
|
+
const why = lastLine();
|
|
355
|
+
throw new Error(
|
|
356
|
+
`the staged ${server.kind} studio exited ${proc.exitCode}${why ? `: ${why}` : ''}`
|
|
357
|
+
);
|
|
358
|
+
}
|
|
193
359
|
try {
|
|
194
360
|
const s = JSON.parse(readFileSync(join(designRoot, '_server.json'), 'utf8')) as {
|
|
195
361
|
pid?: number;
|
|
@@ -252,6 +418,7 @@ function affectedCanvases(stageDir: string, ds: string): RenderCanvas[] {
|
|
|
252
418
|
out.push({
|
|
253
419
|
path: rel,
|
|
254
420
|
tokens: sys?.tokensCssRel ?? null,
|
|
421
|
+
themes: sys?.themes ?? [],
|
|
255
422
|
components: sys ? `${sys.path}/preview/_components.css` : null,
|
|
256
423
|
});
|
|
257
424
|
}
|
|
@@ -271,7 +438,21 @@ function reviewOf(
|
|
|
271
438
|
path: r.path,
|
|
272
439
|
reason: r.invariant,
|
|
273
440
|
}));
|
|
441
|
+
const unmeasured: { path: string; reason: string }[] = [];
|
|
274
442
|
for (const c of result.canvases) {
|
|
443
|
+
// A canvas that could not be measured (no answer in time, an error before the upgrade touched
|
|
444
|
+
// anything, the gate itself threw) proves nothing either way: it never blocks the system files,
|
|
445
|
+
// and its own codemod is not applied unproved. `after` alone is a finding: the upgrade broke it.
|
|
446
|
+
// Noise the control explained away is not a failure (`noise`, the shim's judge).
|
|
447
|
+
if (c.error && c.error !== 'after') {
|
|
448
|
+
const reason = c.error === 'timeout' ? 'timeout' : 'unmeasured';
|
|
449
|
+
unmeasured.push({ path: c.path, reason });
|
|
450
|
+
if (codemodded.has(c.path)) {
|
|
451
|
+
failedCanvases.add(c.path);
|
|
452
|
+
refused.push({ path: c.path, reason });
|
|
453
|
+
}
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
275
456
|
const failed = c.error === 'after' || c.artboards.some((a) => a.fail);
|
|
276
457
|
if (!failed) continue;
|
|
277
458
|
if (codemodded.has(c.path)) {
|
|
@@ -317,6 +498,7 @@ function reviewOf(
|
|
|
317
498
|
diff: failedCanvases.has(c.path) ? 'fail' : 'pass',
|
|
318
499
|
})),
|
|
319
500
|
refused,
|
|
501
|
+
...(unmeasured.length ? { unmeasured } : {}),
|
|
320
502
|
needsPick: items.filter((i) => i.status === 'needs-pick' && i.picked == null).map((i) => i.id),
|
|
321
503
|
};
|
|
322
504
|
return { review, failedCanvases };
|
|
@@ -390,6 +572,7 @@ export async function proveStage(
|
|
|
390
572
|
deltaE: DELTA_E,
|
|
391
573
|
ratio: FAIL_RATIO,
|
|
392
574
|
timeout: 20000,
|
|
575
|
+
canvasTimeout: CANVAS_TIMEOUT,
|
|
393
576
|
},
|
|
394
577
|
{
|
|
395
578
|
signal: ctl.signal,
|
|
@@ -189,7 +189,10 @@ export function systemOf(designRoot: string, ds: string): SystemConfig {
|
|
|
189
189
|
/** `<designRoot>/_state/ds-upgrade/<ds>/<stamp>` — the stamp is digits only (never a path). */
|
|
190
190
|
export function stateDirOf(designRoot: string, ds: string, stamp: string): string {
|
|
191
191
|
if (!/^[0-9]{1,20}(?:-[0-9]{1,4})?$/.test(stamp))
|
|
192
|
-
throw new DsUpgradeError(
|
|
192
|
+
throw new DsUpgradeError(
|
|
193
|
+
'ds-upgrade-usage',
|
|
194
|
+
'a stage is named by its stamp: the digits `ds-upgrade <ds> --stage` printed as "stamp" (`ds-upgrade <ds> --status` lists them; the record is _state/ds-upgrade/<ds>/<stamp>/)'
|
|
195
|
+
);
|
|
193
196
|
return join(designRoot, STATE_REL, ds, stamp);
|
|
194
197
|
}
|
|
195
198
|
|
|
@@ -11,6 +11,7 @@ import { type ReactNode, useEffect, useState } from 'react';
|
|
|
11
11
|
import { getLiveViewport, useViewportControllerContext } from '../canvas-lib.tsx';
|
|
12
12
|
import { jumpTarget, type PageSection, sectionAt, visibleSentence } from './artboard-resize.ts';
|
|
13
13
|
import { type LongPage, measureLongPages, pageInView, pageSections } from './long-page.ts';
|
|
14
|
+
import { activeInterval } from './page-activity.ts';
|
|
14
15
|
|
|
15
16
|
export interface MiniModel {
|
|
16
17
|
id: string;
|
|
@@ -91,9 +92,8 @@ export function MinimapContext({ pollMs = 200 }: { pollMs?: number }): ReactNode
|
|
|
91
92
|
: next
|
|
92
93
|
);
|
|
93
94
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return () => clearInterval(t);
|
|
95
|
+
// only while the page is in use: an idle or hidden canvas is not polled (page-activity.ts, 2.0.4)
|
|
96
|
+
return activeInterval(run, pollMs);
|
|
97
97
|
}, [pollMs]);
|
|
98
98
|
|
|
99
99
|
if (!model) return null;
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
// editing/page-activity.ts — Maude 2.0.4 (task O): one "is anyone using this canvas right now" clock for the
|
|
2
|
+
// canvas runtime's per-frame and polling loops.
|
|
3
|
+
//
|
|
4
|
+
// Measured on 2.0.3 (headless WebKit, an idle canvas with nothing selected): the rotate handle's rAF loop ran 72×/s
|
|
5
|
+
// and the sticky-name / minimap polls measured every long page 15×/s, forever — the idle CPU of every open project
|
|
6
|
+
// tab. A loop built on this clock runs only while the page is ACTIVE and stops outright (no timer, no frame) when it
|
|
7
|
+
// goes idle or hidden; the next sign of use starts it again and runs it at once, so nothing lags the person.
|
|
8
|
+
//
|
|
9
|
+
// Active = visible AND something happened in the last IDLE_AFTER_MS: input (pointer, wheel, keys), a message from
|
|
10
|
+
// the shell (camera moves, selections and file pushes all arrive as `message`), a resize or scroll, a focus, or a
|
|
11
|
+
// change to the page's nodes (an AI write, a hot swap). Attribute changes are deliberately NOT activity: the loops
|
|
12
|
+
// themselves write styles every frame and would keep the page awake forever.
|
|
13
|
+
//
|
|
14
|
+
// Pure core (`createPageActivity`) over an injected environment, so the clock is tested without a DOM;
|
|
15
|
+
// `pageActivity()` is the one per-window instance the canvas uses.
|
|
16
|
+
|
|
17
|
+
/** How long after the last sign of use the page counts as idle. Long enough to cover a camera glide (≤ 1 s). */
|
|
18
|
+
export const IDLE_AFTER_MS = 3000;
|
|
19
|
+
|
|
20
|
+
/** Window events that count as use. */
|
|
21
|
+
export const WAKE_EVENTS = [
|
|
22
|
+
'pointermove',
|
|
23
|
+
'pointerdown',
|
|
24
|
+
'pointerup',
|
|
25
|
+
'wheel',
|
|
26
|
+
'keydown',
|
|
27
|
+
'keyup',
|
|
28
|
+
'message',
|
|
29
|
+
'resize',
|
|
30
|
+
'scroll',
|
|
31
|
+
'focus',
|
|
32
|
+
] as const;
|
|
33
|
+
|
|
34
|
+
export interface ActivityEnv {
|
|
35
|
+
now(): number;
|
|
36
|
+
hidden(): boolean;
|
|
37
|
+
/** Subscribe to every wake source (events, visibility, node changes); returns the unsubscribe. */
|
|
38
|
+
listen(onWake: () => void, onVisibility: () => void): () => void;
|
|
39
|
+
setTimer(fn: () => void, ms: number): unknown;
|
|
40
|
+
clearTimer(t: unknown): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface PageActivity {
|
|
44
|
+
active(): boolean;
|
|
45
|
+
/** The page is hidden (a background tab, a minimized window). */
|
|
46
|
+
hidden(): boolean;
|
|
47
|
+
/** Called with the new state on every change. Returns the unsubscribe. */
|
|
48
|
+
subscribe(fn: (active: boolean) => void): () => void;
|
|
49
|
+
/** Count as use now (a caller that knows the page changed). */
|
|
50
|
+
poke(): void;
|
|
51
|
+
dispose(): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function createPageActivity(env: ActivityEnv, idleAfter = IDLE_AFTER_MS): PageActivity {
|
|
55
|
+
let last = env.now();
|
|
56
|
+
let state = !env.hidden();
|
|
57
|
+
let timer: unknown = null;
|
|
58
|
+
const subs = new Set<(active: boolean) => void>();
|
|
59
|
+
const set = (next: boolean) => {
|
|
60
|
+
if (next === state) return;
|
|
61
|
+
state = next;
|
|
62
|
+
for (const fn of [...subs]) fn(next);
|
|
63
|
+
};
|
|
64
|
+
// One timer while active, re-armed only when it fires (not on every pointermove): it checks how long ago the last
|
|
65
|
+
// use was and either sleeps the rest or turns the page idle. Idle = no timer at all.
|
|
66
|
+
const arm = (ms: number) => {
|
|
67
|
+
timer = env.setTimer(() => {
|
|
68
|
+
timer = null;
|
|
69
|
+
const since = env.now() - last;
|
|
70
|
+
if (env.hidden()) set(false);
|
|
71
|
+
else if (since >= idleAfter) set(false);
|
|
72
|
+
else arm(idleAfter - since);
|
|
73
|
+
}, ms);
|
|
74
|
+
};
|
|
75
|
+
const poke = () => {
|
|
76
|
+
last = env.now();
|
|
77
|
+
if (env.hidden()) return;
|
|
78
|
+
set(true);
|
|
79
|
+
if (timer === null) arm(idleAfter);
|
|
80
|
+
};
|
|
81
|
+
const onVisibility = () => {
|
|
82
|
+
if (env.hidden()) {
|
|
83
|
+
if (timer !== null) env.clearTimer(timer);
|
|
84
|
+
timer = null;
|
|
85
|
+
set(false);
|
|
86
|
+
} else poke();
|
|
87
|
+
};
|
|
88
|
+
const off = env.listen(poke, onVisibility);
|
|
89
|
+
if (state) arm(idleAfter);
|
|
90
|
+
return {
|
|
91
|
+
active: () => state,
|
|
92
|
+
hidden: () => env.hidden(),
|
|
93
|
+
subscribe(fn) {
|
|
94
|
+
subs.add(fn);
|
|
95
|
+
return () => void subs.delete(fn);
|
|
96
|
+
},
|
|
97
|
+
poke,
|
|
98
|
+
dispose() {
|
|
99
|
+
off();
|
|
100
|
+
if (timer !== null) env.clearTimer(timer);
|
|
101
|
+
timer = null;
|
|
102
|
+
subs.clear();
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The real environment: window events, `visibilitychange`, and node (not attribute) changes. */
|
|
108
|
+
export function domActivityEnv(
|
|
109
|
+
win: Window,
|
|
110
|
+
{ nodes = true }: { nodes?: boolean } = {}
|
|
111
|
+
): ActivityEnv {
|
|
112
|
+
const doc = win.document;
|
|
113
|
+
return {
|
|
114
|
+
now: () => win.performance?.now?.() ?? Date.now(),
|
|
115
|
+
hidden: () => doc.hidden === true,
|
|
116
|
+
listen(onWake, onVisibility) {
|
|
117
|
+
const opts = { passive: true, capture: true } as const;
|
|
118
|
+
for (const t of WAKE_EVENTS) win.addEventListener(t, onWake, opts);
|
|
119
|
+
doc.addEventListener('visibilitychange', onVisibility);
|
|
120
|
+
const MO = (win as Window & { MutationObserver?: typeof MutationObserver }).MutationObserver;
|
|
121
|
+
const mo = nodes && typeof MO === 'function' && doc.documentElement ? new MO(onWake) : null;
|
|
122
|
+
mo?.observe(doc.documentElement, { childList: true, subtree: true, characterData: true });
|
|
123
|
+
return () => {
|
|
124
|
+
for (const t of WAKE_EVENTS) win.removeEventListener(t, onWake, opts);
|
|
125
|
+
doc.removeEventListener('visibilitychange', onVisibility);
|
|
126
|
+
mo?.disconnect();
|
|
127
|
+
};
|
|
128
|
+
},
|
|
129
|
+
setTimer: (fn, ms) => win.setTimeout(fn, ms),
|
|
130
|
+
clearTimer: (t) => win.clearTimeout(t as number),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const KEY = Symbol.for('maude.pageActivity');
|
|
135
|
+
|
|
136
|
+
/** The window's one activity clock (made on first use). */
|
|
137
|
+
export function pageActivity(win: Window = window): PageActivity {
|
|
138
|
+
const w = win as unknown as Record<symbol, PageActivity | undefined>;
|
|
139
|
+
let a = w[KEY];
|
|
140
|
+
if (!a) {
|
|
141
|
+
a = createPageActivity(domActivityEnv(win));
|
|
142
|
+
w[KEY] = a;
|
|
143
|
+
}
|
|
144
|
+
return a;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* `setInterval(fn, ms)` that runs only while the page is active: `fn` runs at once, every `ms` while active, once
|
|
149
|
+
* more as the page goes idle (so what it draws settles on the final state), and again at once when use resumes.
|
|
150
|
+
*/
|
|
151
|
+
export function activeInterval(
|
|
152
|
+
fn: () => void,
|
|
153
|
+
ms: number,
|
|
154
|
+
activity: PageActivity = pageActivity()
|
|
155
|
+
): () => void {
|
|
156
|
+
let t: ReturnType<typeof setInterval> | null = null;
|
|
157
|
+
const start = () => {
|
|
158
|
+
if (t === null) t = setInterval(fn, ms);
|
|
159
|
+
};
|
|
160
|
+
const stop = () => {
|
|
161
|
+
if (t !== null) clearInterval(t);
|
|
162
|
+
t = null;
|
|
163
|
+
};
|
|
164
|
+
fn();
|
|
165
|
+
if (activity.active()) start();
|
|
166
|
+
const off = activity.subscribe((on) => {
|
|
167
|
+
fn();
|
|
168
|
+
if (on) start();
|
|
169
|
+
else stop();
|
|
170
|
+
});
|
|
171
|
+
return () => {
|
|
172
|
+
off();
|
|
173
|
+
stop();
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* A `requestAnimationFrame` loop that runs only while the page is active. `tick` runs every frame while active and
|
|
179
|
+
* once more as the page goes idle; the loop restarts on the next use. Returns the stop.
|
|
180
|
+
*/
|
|
181
|
+
export function activeFrameLoop(
|
|
182
|
+
tick: () => void,
|
|
183
|
+
activity: PageActivity = pageActivity()
|
|
184
|
+
): () => void {
|
|
185
|
+
let raf = 0;
|
|
186
|
+
let running = false;
|
|
187
|
+
const frame = () => {
|
|
188
|
+
if (!running) return;
|
|
189
|
+
raf = requestAnimationFrame(frame);
|
|
190
|
+
tick();
|
|
191
|
+
};
|
|
192
|
+
const start = () => {
|
|
193
|
+
if (running) return;
|
|
194
|
+
running = true;
|
|
195
|
+
raf = requestAnimationFrame(frame);
|
|
196
|
+
};
|
|
197
|
+
const stop = () => {
|
|
198
|
+
running = false;
|
|
199
|
+
cancelAnimationFrame(raf);
|
|
200
|
+
};
|
|
201
|
+
if (activity.active()) start();
|
|
202
|
+
else tick();
|
|
203
|
+
const off = activity.subscribe((on) => {
|
|
204
|
+
if (on) start();
|
|
205
|
+
else {
|
|
206
|
+
stop();
|
|
207
|
+
tick();
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
return () => {
|
|
211
|
+
off();
|
|
212
|
+
stop();
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* A poll that keeps its pace while the page is in use, slows to `idleMs` while it is visible but unused, and holds
|
|
218
|
+
* no timer at all while it is hidden. Coming back (visible again, or used again) runs `fn` at once and restores the
|
|
219
|
+
* pace. For the shell's server polls (2.0.4), where "unused" still means someone may be looking.
|
|
220
|
+
*/
|
|
221
|
+
export function pacedInterval(
|
|
222
|
+
fn: () => void,
|
|
223
|
+
ms: number,
|
|
224
|
+
activity: PageActivity | null,
|
|
225
|
+
idleMs: number = Math.max(ms * 4, 30_000)
|
|
226
|
+
): () => void {
|
|
227
|
+
if (!activity) {
|
|
228
|
+
const t = setInterval(fn, ms);
|
|
229
|
+
return () => clearInterval(t);
|
|
230
|
+
}
|
|
231
|
+
let t: ReturnType<typeof setInterval> | null = null;
|
|
232
|
+
let every = 0;
|
|
233
|
+
const pace = () => (activity.hidden() ? 0 : activity.active() ? ms : idleMs);
|
|
234
|
+
const apply = () => {
|
|
235
|
+
const next = pace();
|
|
236
|
+
if (next === every) return;
|
|
237
|
+
if (t !== null) clearInterval(t);
|
|
238
|
+
t = next ? setInterval(fn, next) : null;
|
|
239
|
+
every = next;
|
|
240
|
+
};
|
|
241
|
+
apply();
|
|
242
|
+
const off = activity.subscribe((on) => {
|
|
243
|
+
if (on) fn();
|
|
244
|
+
apply();
|
|
245
|
+
});
|
|
246
|
+
return () => {
|
|
247
|
+
off();
|
|
248
|
+
if (t !== null) clearInterval(t);
|
|
249
|
+
t = null;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
@@ -21,6 +21,7 @@ import { useSelectionSet } from '../use-selection-set.tsx';
|
|
|
21
21
|
import { useToolModeOptional } from '../use-tool-mode.tsx';
|
|
22
22
|
import { useUndoStackOptional } from '../use-undo-stack.tsx';
|
|
23
23
|
import { type ObjectTarget, objectTargets, runArranged } from './arrange.ts';
|
|
24
|
+
import { activeFrameLoop } from './page-activity.ts';
|
|
24
25
|
|
|
25
26
|
export const SNAP_DEGREES = 15;
|
|
26
27
|
|
|
@@ -143,14 +144,18 @@ export function RotateHandle({ readOnly = false }: { readOnly?: boolean }) {
|
|
|
143
144
|
};
|
|
144
145
|
}, []);
|
|
145
146
|
|
|
146
|
-
// keep the handle at the selection's bottom-right corner, every frame (pan / zoom / write)
|
|
147
|
+
// keep the handle at the selection's bottom-right corner, every frame (pan / zoom / write) — but only while there is
|
|
148
|
+
// a selection to turn and the page is in use (2.0.4: this loop ran 72×/s on every idle canvas, selection or not)
|
|
147
149
|
useEffect(() => {
|
|
148
150
|
const h = handle.current;
|
|
149
151
|
const tip = hint.current;
|
|
150
152
|
if (!h || !tip) return;
|
|
151
|
-
|
|
153
|
+
if (!canRotate) {
|
|
154
|
+
h.style.display = 'none';
|
|
155
|
+
tip.style.display = 'none';
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
152
158
|
const tick = () => {
|
|
153
|
-
raf = requestAnimationFrame(tick);
|
|
154
159
|
const els = live.current.targets.map((t) => t.el);
|
|
155
160
|
const locked = els.some((e) => e.hasAttribute('data-cd-locked'));
|
|
156
161
|
const mode = canvasModeStore(window).get().mode;
|
|
@@ -178,8 +183,7 @@ export function RotateHandle({ readOnly = false }: { readOnly?: boolean }) {
|
|
|
178
183
|
tip.style.left = `${Math.round(box.r + 36)}px`;
|
|
179
184
|
tip.style.top = `${Math.round(box.b + 10)}px`;
|
|
180
185
|
};
|
|
181
|
-
|
|
182
|
-
return () => cancelAnimationFrame(raf);
|
|
186
|
+
return activeFrameLoop(tick);
|
|
183
187
|
}, [canRotate]);
|
|
184
188
|
|
|
185
189
|
const restore = (t: Turning) => {
|
|
@@ -8,6 +8,7 @@ import { type ReactNode, useEffect, useState } from 'react';
|
|
|
8
8
|
|
|
9
9
|
import { sizeText, stickyNameTop } from './artboard-resize.ts';
|
|
10
10
|
import { type LongPage, measureLongPages, pageInView } from './long-page.ts';
|
|
11
|
+
import { activeInterval } from './page-activity.ts';
|
|
11
12
|
|
|
12
13
|
export interface StickyChip {
|
|
13
14
|
id: string;
|
|
@@ -77,7 +78,8 @@ const same = (a: StickyChip[], b: StickyChip[]) =>
|
|
|
77
78
|
);
|
|
78
79
|
});
|
|
79
80
|
|
|
80
|
-
/** Polls the canvas ~10×/s (a scroll is a pan — the DOM does not tell us) and draws the chip when
|
|
81
|
+
/** Polls the canvas ~10×/s while it is in use (a scroll is a pan — the DOM does not tell us) and draws the chip when
|
|
82
|
+
* there is one. An idle or hidden page is not polled at all (page-activity.ts, 2.0.4). */
|
|
81
83
|
export function StickyName({ pollMs = 100 }: { pollMs?: number }): ReactNode {
|
|
82
84
|
const [chips, setChips] = useState<StickyChip[]>([]);
|
|
83
85
|
useEffect(() => {
|
|
@@ -87,9 +89,7 @@ export function StickyName({ pollMs = 100 }: { pollMs?: number }): ReactNode {
|
|
|
87
89
|
const next = planStickyChips(measureLongPages(document));
|
|
88
90
|
setChips((prev) => (same(prev, next) ? prev : next));
|
|
89
91
|
};
|
|
90
|
-
run
|
|
91
|
-
const t = setInterval(run, pollMs);
|
|
92
|
-
return () => clearInterval(t);
|
|
92
|
+
return activeInterval(run, pollMs);
|
|
93
93
|
}, [pollMs]);
|
|
94
94
|
if (!chips.length) return null;
|
|
95
95
|
return (
|