@marver-design/marver 0.27.0 → 0.27.2
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/CHANGELOG.md +94 -0
- package/README.md +5 -2
- package/dist/{anchor-check-ChdDqL5z.mjs → anchor-check-gkxkPAIv.mjs} +1 -1
- package/dist/{board-tree-DRioF94d.mjs → board-tree-BXR8dw4b.mjs} +3 -1
- package/dist/{boards-CGg6piKF.mjs → boards-BHKP5yhI.mjs} +1 -1
- package/dist/{boards-DlTcpF47.mjs → boards-BqUqKNW8.mjs} +4 -4
- package/dist/{build-DZnFysGU.mjs → build-VgNg4rr8.mjs} +7 -22
- package/dist/cli.mjs +32 -18
- package/dist/{collab-Dxg2trOK.mjs → collab-BEAcXrBb.mjs} +1 -1
- package/dist/{comments-DxOkCSNE.mjs → comments-YEU1Zhv9.mjs} +4 -4
- package/dist/{context-HQ4Giw58.mjs → context-Ccjrhr1J.mjs} +3 -3
- package/dist/{daemon-BSA0lV8d.mjs → daemon-Dc9AH0M3.mjs} +4 -4
- package/dist/{dev-eQJhWsqg.mjs → dev-ri6nAlRp.mjs} +11 -11
- package/dist/{init-COD0x48i.mjs → init-W0nxR1OY.mjs} +3 -3
- package/dist/{link-DDXZVGtv.mjs → link-CdTgn94Y.mjs} +4 -4
- package/dist/{ls-D7O1G505.mjs → ls-BZ5TAtd5.mjs} +1 -1
- package/dist/{manifest-Nl3KSVOk.mjs → manifest-aFyDmL8C.mjs} +2 -2
- package/dist/{marks-CWM3WJjc.mjs → marks-BF9pNEgH.mjs} +2 -2
- package/dist/{marks-CKgzucHZ.mjs → marks-CnCCfAbD.mjs} +3 -3
- package/dist/{marver-id-gate-BjF6v4bT.mjs → marver-id-gate-D-R0hSt_.mjs} +1 -1
- package/dist/perf-DkAUFT6W.mjs +1319 -0
- package/dist/perf-jam-BaH3Lg0m.mjs +635 -0
- package/dist/{plugin-C-E7omsh.mjs → plugin-B8UghYuF.mjs} +2592 -112
- package/dist/{poster-Bx83ZYVK.mjs → poster-BNgafWMK.mjs} +1 -1
- package/dist/{profile-Bh5Y5zpW.mjs → profile-jIS6BcAs.mjs} +1 -1
- package/dist/{publish-bakes-aljgm45S.mjs → publish-bakes-38Nja78p.mjs} +3 -3
- package/dist/{recover-t9Pno3u9.mjs → recover-B8AiI29B.mjs} +2 -2
- package/dist/{serve-C8rVheYk.mjs → serve-Dp3nHstu.mjs} +3 -3
- package/dist/{share-W5H3BNvP.mjs → share-Ce4tP7ji.mjs} +1 -1
- package/dist/{shot-DoHLl6ig.mjs → shot-CMQgMVZm.mjs} +1 -1
- package/dist/{shot-LFhC-WYD.mjs → shot-Ch24tiMO.mjs} +30 -5
- package/dist/{slots-DCDo3N0x.mjs → slots-CFNnegCc.mjs} +8 -1
- package/dist/{sync-BQVlHZpx.mjs → sync-CQdGARJ9.mjs} +1 -1
- package/dist/{work-BroFwnup.mjs → work-Bxz-ObF3.mjs} +3 -3
- package/dist/{work-Bp1p39kq.mjs → work-CNhFF9pU.mjs} +1 -1
- package/docs/jam-session.md +2 -1
- package/docs/performance.md +197 -35
- package/package.json +1 -1
- package/src/client/content/video.tsx +10 -2
- package/src/client/shell/App.tsx +10 -3
- package/src/client/shell/Comments.tsx +5 -3
- package/src/client/shell/ContextMenu.tsx +5 -3
- package/src/client/shell/LockedApp.tsx +3 -0
- package/src/client/shell/Play.tsx +4 -2
- package/src/client/shell/Tip.tsx +3 -1
- package/src/client/shell/api.ts +47 -20
- package/src/client/shell/app-bridge.ts +254 -0
- package/src/client/shell/app-perf.ts +92 -0
- package/src/client/shell/canvas/Canvas.tsx +115 -22
- package/src/client/shell/canvas/FrameNode.tsx +10 -6
- package/src/client/shell/canvas/admission.ts +23 -8
- package/src/client/shell/canvas/ctl.ts +6 -0
- package/src/client/shell/canvas/sleep.ts +57 -17
- package/src/client/shell/canvas/updates.ts +2 -1
- package/src/client/shell/inset.ts +44 -0
- package/src/client/shell/jam-capture.ts +19 -14
- package/src/client/shell/jam-keys.ts +8 -3
- package/src/client/shell/jam-panel.tsx +6 -3
- package/src/client/shell/jam-voice.ts +48 -10
- package/src/client/shell/main.tsx +14 -1
- package/src/client/shell/marks-ui.tsx +5 -3
- package/src/client/shell/marver-app.ts +21 -0
- package/src/client/shell/perf-run-probe.ts +34 -0
- package/src/client/shell/perf-run.ts +70 -0
- package/src/client/shell/perf.ts +11 -0
- package/src/client/shell/recorder.ts +45 -3
- package/src/client/shell/store.ts +52 -24
- package/src/client/shell/styles.css +47 -15
- package/src/client/shell/unsaved.ts +81 -0
- package/src/client/shell/whiteout-probes.ts +141 -0
- package/src/shared/app-api.ts +205 -0
- package/src/shared/app-perf.ts +308 -0
- package/src/shared/logo-sniff.ts +86 -0
- package/src/shared/machine.ts +132 -0
- package/src/shared/perf-run.ts +177 -0
- package/templates/AGENTS-embedded.md +3 -0
- package/templates/AGENTS-studio.md +3 -0
- package/templates/instructions/boards.md +3 -1
- package/dist/bake-DM_uWgAA.mjs +0 -786
- package/dist/perf-BWzQwZqj.mjs +0 -369
- package/dist/perf-BoDSkbEb.mjs +0 -429
- package/dist/perf-jam-D55U3FZK.mjs +0 -242
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shell's side of `mv:perf` (spec 28 A3.8 #9, #10, #16): what a 0.27.2 shell tells the Mac app's recorder -
|
|
3
|
+
* its gestures (perf.ts's begin and end, the white-out detector's window), its probe answers (whiteout-probes.ts,
|
|
4
|
+
* given by the canvas: `answerProbesWith`)
|
|
5
|
+
* and its board's frame count at each commit. Inert unless `window.marverApp.perf` exists (app 0.2): in Chrome, on
|
|
6
|
+
* a published canvas and inside app 0.1 nothing here sends, listens or runs a timer. The preload sends `mem` and
|
|
7
|
+
* `shown` by itself; the shell never sees a `doc`.
|
|
8
|
+
*
|
|
9
|
+
* FROZEN signatures (A3.8 #53); the recorder stream fills them (the probes' geometry is the flash stream's
|
|
10
|
+
* whiteout-probes.ts). Every message goes through `APP.perf` in a try: the app going away never breaks the page.
|
|
11
|
+
*
|
|
12
|
+
* As built: a gesture's `on` and `off` carry one `seq` (a new start while one is open ends it first, so main never
|
|
13
|
+
* holds two); `board` is sent when the frame count or the sleeping count changed, read at each change of the board's
|
|
14
|
+
* nodes and again at each gesture's end (frames fall asleep without the store moving), never more.
|
|
15
|
+
*/
|
|
16
|
+
import type { PerfMsg } from '../../shared/app-api.ts'
|
|
17
|
+
import { APP } from './marver-app.ts'
|
|
18
|
+
import { useStore } from './store.ts'
|
|
19
|
+
import { sleepingCount } from './canvas/sleep.ts'
|
|
20
|
+
|
|
21
|
+
/** Whether this page talks to the recorder at all. */
|
|
22
|
+
export const PERF_ON = typeof APP?.perf === 'function'
|
|
23
|
+
|
|
24
|
+
/** The white-out probes (whiteout-probes.ts' pick and verify), given by the canvas (Canvas.tsx): canvas code, never
|
|
25
|
+
* in an all-boards-locked bundle, whose shell has no canvas - an ask there goes unanswered, which main reads as an
|
|
26
|
+
* inconclusive sample, as it reads any probe answer that never came. */
|
|
27
|
+
export interface Probes { pick(tick: number): PerfMsg; verify(tick: number): PerfMsg }
|
|
28
|
+
let probes: Probes | null = null
|
|
29
|
+
/** Canvas.tsx, at import: the probes this page answers with. */
|
|
30
|
+
export function answerProbesWith(p: Probes): void { probes = p }
|
|
31
|
+
|
|
32
|
+
let started = false
|
|
33
|
+
let seq = 0
|
|
34
|
+
let open: number | null = null
|
|
35
|
+
let lastBoard = ''
|
|
36
|
+
|
|
37
|
+
/** The board now: its frames and how many sleep, sent when either changed. */
|
|
38
|
+
function boardNow(): void {
|
|
39
|
+
try { boardChanged(useStore.getState().nodes.length, sleepingCount()) } catch { /* the page goes on */ }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** main.tsx, after startAppBridge(): the probes' ask listener and the board subscription. Nothing without `APP.perf`. */
|
|
43
|
+
export function startAppPerf(): void {
|
|
44
|
+
if (!PERF_ON || started) return
|
|
45
|
+
started = true
|
|
46
|
+
try {
|
|
47
|
+
APP!.onPerfAsk?.((a) => {
|
|
48
|
+
if (a.kind !== 'probes' || !probes) return
|
|
49
|
+
try { sendPerf(a.at === 'before' ? probes.pick(a.tick) : probes.verify(a.tick)) } catch { /* no answer: main reads the sample as inconclusive */ }
|
|
50
|
+
})
|
|
51
|
+
} catch { /* the app's own */ }
|
|
52
|
+
useStore.subscribe((s, prev) => { if (s.nodes !== prev.nodes) boardNow() })
|
|
53
|
+
boardNow()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** perf.ts's begin(): a gesture starts. */
|
|
57
|
+
export function gestureOn(type?: 'pan' | 'zoom' | 'layout'): void {
|
|
58
|
+
if (!PERF_ON) return
|
|
59
|
+
if (open !== null) gestureOff()
|
|
60
|
+
seq = seq >= 2 ** 31 - 2 ? 1 : seq + 1
|
|
61
|
+
open = seq
|
|
62
|
+
sendPerf({ kind: 'gesture', on: true, seq, ...(type ? { type } : {}) })
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** perf.ts's end(): the gesture that started last ends. */
|
|
66
|
+
export function gestureOff(): void {
|
|
67
|
+
if (!PERF_ON || open === null) return
|
|
68
|
+
const s = open
|
|
69
|
+
open = null
|
|
70
|
+
sendPerf({ kind: 'gesture', on: false, seq: s })
|
|
71
|
+
boardNow()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The board committed: its frame count and how many sleep. */
|
|
75
|
+
export function boardChanged(frames: number, asleep: number): void {
|
|
76
|
+
if (!PERF_ON) return
|
|
77
|
+
const k = `${frames}/${asleep}`
|
|
78
|
+
if (k === lastBoard) return
|
|
79
|
+
lastBoard = k
|
|
80
|
+
sendPerf({ kind: 'board', frames, asleep })
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The display's refresh rate main last said (`display` ask), for gesture records' `hz`; null until it says. */
|
|
84
|
+
export function displayHz(): number | null {
|
|
85
|
+
try { return APP?.perfInfo?.().hz ?? null } catch { return null }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** One message to the app, never throwing. */
|
|
89
|
+
export function sendPerf(p: PerfMsg): void {
|
|
90
|
+
if (!PERF_ON) return
|
|
91
|
+
try { APP!.perf!(p) } catch { /* the page goes on */ }
|
|
92
|
+
}
|
|
@@ -10,7 +10,15 @@ import { NOTE_GAP } from '../notes.ts'
|
|
|
10
10
|
import { onMotion, startCameraBroadcast, setCameraScale } from './camera-broadcast.ts'
|
|
11
11
|
import { attachCanvas, recorder } from '../recorder.ts'
|
|
12
12
|
import { sleepingCount } from './sleep.ts'
|
|
13
|
-
import {
|
|
13
|
+
import { aimed } from './admission.ts'
|
|
14
|
+
import { keepOverResume, resumed, WS } from '../api.ts'
|
|
15
|
+
import { APP_REOPEN } from '../marver-app.ts'
|
|
16
|
+
import { TOP } from '../inset.ts'
|
|
17
|
+
import { answerProbesWith } from '../app-perf.ts'
|
|
18
|
+
import { pick, verify } from '../whiteout-probes.ts'
|
|
19
|
+
|
|
20
|
+
// the white-out probes the Mac app's recorder asks for (app-perf.ts): the canvas's own, so a locked bundle has none
|
|
21
|
+
answerProbesWith({ pick, verify })
|
|
14
22
|
|
|
15
23
|
/**
|
|
16
24
|
* The world. rzpp owns pan/zoom; nodes are absolutely positioned children of #sh-world.
|
|
@@ -34,6 +42,62 @@ import { keepOverResume, resumed } from '../api.ts'
|
|
|
34
42
|
*/
|
|
35
43
|
const GAP = 32
|
|
36
44
|
const BAR = 56
|
|
45
|
+
|
|
46
|
+
/** The camera survives a reload (spec 28 A2.9): kept per canvas and board, `mv-camera:<workspace>:<board>`, a second
|
|
47
|
+
* after it settles, and the next load of that board opens there - when its link names no selection, or when the Mac
|
|
48
|
+
* app reloaded the tab after a crash (`marverApp.reopen`). A1's camera carried over a resume wins. Dev canvases only:
|
|
49
|
+
* a published one has no workspace, and opens on the whole board as before. */
|
|
50
|
+
type Camera = { x: number; y: number; scale: number }
|
|
51
|
+
const cameraKey = (board: string) => `mv-camera:${WS}:${board}`
|
|
52
|
+
function savedCamera(board: string): Camera | null {
|
|
53
|
+
if (!WS) return null
|
|
54
|
+
try {
|
|
55
|
+
const c = JSON.parse(localStorage.getItem(cameraKey(board)) ?? 'null')
|
|
56
|
+
return c && [c.x, c.y, c.scale].every((v) => typeof v === 'number' && Number.isFinite(v)) && c.scale >= 0.05 && c.scale <= 5 ? { x: c.x, y: c.y, scale: c.scale } : null
|
|
57
|
+
} catch { return null }
|
|
58
|
+
}
|
|
59
|
+
let keepTimer: ReturnType<typeof setTimeout> | undefined
|
|
60
|
+
/** the camera write waiting for its second of quiet, if any */
|
|
61
|
+
let keepPending: (() => void) | undefined
|
|
62
|
+
/** Where the camera's flight lands (a fit, a zoom), for canvasCtl.landing: read only while rzpp animates. */
|
|
63
|
+
let flight: Camera | null = null
|
|
64
|
+
function keepCamera(x: number, y: number, scale: number) {
|
|
65
|
+
if (!WS) return
|
|
66
|
+
const board = useStore.getState().board
|
|
67
|
+
clearTimeout(keepTimer)
|
|
68
|
+
const write = () => {
|
|
69
|
+
keepPending = undefined
|
|
70
|
+
if (useStore.getState().board !== board) return // switched meanwhile: this camera was the other board's
|
|
71
|
+
try { localStorage.setItem(cameraKey(board), JSON.stringify({ x: Math.round(x * 100) / 100, y: Math.round(y * 100) / 100, scale })) } catch { /* storage off: the next load fits */ }
|
|
72
|
+
}
|
|
73
|
+
keepPending = write
|
|
74
|
+
keepTimer = setTimeout(write, 1000)
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The pending camera, written now (spec 28 A3.8 #43): the page is hidden or leaving, and the Mac app may unload a
|
|
78
|
+
* hidden tab, which ends its page with the second of quiet not yet over. A hide mid-flight writes where the flight
|
|
79
|
+
* was going: a hidden page's animation frames stop, so it would not land before the page went. Nothing pending,
|
|
80
|
+
* nothing written. In Chrome too - a tab switch, a closed tab.
|
|
81
|
+
*/
|
|
82
|
+
export function flushCamera(): void {
|
|
83
|
+
if (flight && canvasCtl.cameraBusy()) keepCamera(flight.x, flight.y, flight.scale)
|
|
84
|
+
if (!keepPending) return
|
|
85
|
+
clearTimeout(keepTimer)
|
|
86
|
+
keepPending()
|
|
87
|
+
}
|
|
88
|
+
let leaveWatched = false
|
|
89
|
+
/**
|
|
90
|
+
* The hide and the leave write the pending camera: listened for from the canvas's first mount, so after the page
|
|
91
|
+
* recorder's own listeners (startRecorder runs before the first render) - its cut of a load still waiting comes first,
|
|
92
|
+
* as `hidden`. Registered at import, ahead of the recorder's, the camera's pagehide write let a navigation away cut
|
|
93
|
+
* that load as `error` instead (page-recorder-browser's "the page goes").
|
|
94
|
+
*/
|
|
95
|
+
function watchLeave(): void {
|
|
96
|
+
if (leaveWatched || typeof document === 'undefined') return
|
|
97
|
+
leaveWatched = true
|
|
98
|
+
document.addEventListener('visibilitychange', () => { if (document.visibilityState === 'hidden') flushCamera() })
|
|
99
|
+
addEventListener('pagehide', flushCamera)
|
|
100
|
+
}
|
|
37
101
|
function insets(el: HTMLElement) {
|
|
38
102
|
const c = el.getBoundingClientRect()
|
|
39
103
|
const rect = (q: string) => document.querySelector(q)?.getBoundingClientRect()
|
|
@@ -47,7 +111,8 @@ function insets(el: HTMLElement) {
|
|
|
47
111
|
return {
|
|
48
112
|
left: (leftEdge ? Math.max(0, leftEdge - c.left) : 0) + GAP,
|
|
49
113
|
right: GAP + 16,
|
|
50
|
-
|
|
114
|
+
// the toolbar's foot, or the Mac app's strip when the toolbar is hidden (Hide UI) - the strip is always there
|
|
115
|
+
top: Math.max(pill ? pill.bottom - c.top : 0, TOP) + 12 + BAR,
|
|
51
116
|
bottom: (lane ? Math.max(0, c.bottom - lane.top) : 0) + GAP + 16,
|
|
52
117
|
}
|
|
53
118
|
}
|
|
@@ -61,23 +126,22 @@ function insets(el: HTMLElement) {
|
|
|
61
126
|
*/
|
|
62
127
|
const GRID = 20
|
|
63
128
|
function paintGrid(positionX: number, positionY: number, scale: number) {
|
|
64
|
-
|
|
65
|
-
|
|
129
|
+
// on .sh-app, which the canvas's ::before and the scroll edge (A3.8 #31) both inherit them from - the same element the
|
|
130
|
+
// camera's own variables go on every frame, so the style work per frame does not grow
|
|
131
|
+
const app = document.querySelector('.sh-app') as HTMLElement | null
|
|
132
|
+
if (!app) return
|
|
66
133
|
let step = GRID * scale
|
|
67
134
|
while (step < 14) step *= 2
|
|
68
135
|
while (step >= 28) step /= 2
|
|
69
136
|
const t = (step - 14) / 14
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
137
|
+
app.style.setProperty('--grid-size', `${step}px ${step}px`)
|
|
138
|
+
app.style.setProperty('--grid-pos', `${positionX % step}px ${positionY % step}px`)
|
|
139
|
+
app.style.setProperty('--grid-alpha', (0.35 + 0.65 * Math.min(1, t)).toFixed(3))
|
|
73
140
|
// screen-space overlays (selection bar) position themselves from these - no re-render per frame
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
app.style.setProperty('--sh-tx', `${positionX}px`)
|
|
79
|
-
app.style.setProperty('--sh-ty', `${positionY}px`)
|
|
80
|
-
}
|
|
141
|
+
app.style.setProperty('--sh-s', String(scale))
|
|
142
|
+
app.style.setProperty('--sh-inv', String(1 / scale)) // world-units-per-screen-px, for zoom-invariant strokes
|
|
143
|
+
app.style.setProperty('--sh-tx', `${positionX}px`)
|
|
144
|
+
app.style.setProperty('--sh-ty', `${positionY}px`)
|
|
81
145
|
}
|
|
82
146
|
|
|
83
147
|
/**
|
|
@@ -145,10 +209,19 @@ export function Canvas() {
|
|
|
145
209
|
const gesture = useStore((s) => s.gesture)
|
|
146
210
|
const setScale = useStore((s) => s.setScale)
|
|
147
211
|
const ref = useRef<ReactZoomPanPinchContentRef>(null)
|
|
212
|
+
// every camera move the canvas aims (a fit, a zoom, a camera restored): where it lands, while rzpp flies there, and the
|
|
213
|
+
// boot queue told - the first frame of a board starts now, ranked on that view, not once the flight is over
|
|
214
|
+
const fly = (x: number, y: number, scale: number, ms: number) => {
|
|
215
|
+
flight = ms ? { x, y, scale } : null
|
|
216
|
+
ref.current?.setTransform(x, y, scale, ms, 'easeOut')
|
|
217
|
+
aimed()
|
|
218
|
+
}
|
|
148
219
|
const scaleTimer = useRef(0)
|
|
149
220
|
|
|
150
221
|
// B0.4: frame-time sampler + image-LOD camera signal; the recorder hears when the camera stops and what sleeps (spec 28 A1.7)
|
|
151
222
|
useEffect(() => { startPerf(); startCameraBroadcast(); return attachCanvas({ onMotion, sleeping: sleepingCount }) }, [])
|
|
223
|
+
// the pending camera written as the page hides or leaves (A3.8 #43), after the recorder's own listeners
|
|
224
|
+
useEffect(() => { watchLeave() }, [])
|
|
152
225
|
|
|
153
226
|
useEffect(() => {
|
|
154
227
|
const wrap = () => document.querySelector('.sh-canvas') as HTMLElement | null
|
|
@@ -167,14 +240,15 @@ export function Canvas() {
|
|
|
167
240
|
let px = p.left + (aw - w * scale) / 2
|
|
168
241
|
let py = p.top + (ah - h * scale) / 2
|
|
169
242
|
if (focus) {
|
|
170
|
-
// clamp order matters: left/top win when the band is tighter than the content
|
|
243
|
+
// clamp order matters: left/top win when the band is tighter than the content. The centre is the usable
|
|
244
|
+
// rectangle's: below the Mac app's strip when the shell took the inset (TOP 44)
|
|
171
245
|
px = Math.max(Math.min((vw - w * scale) / 2, vw - p.right - w * scale), p.left)
|
|
172
|
-
py = Math.max(Math.min((vh - h * scale) / 2, vh - p.bottom - h * scale), p.top)
|
|
246
|
+
py = Math.max(Math.min(TOP + (vh - TOP - h * scale) / 2, vh - p.bottom - h * scale), p.top)
|
|
173
247
|
}
|
|
174
248
|
const tx = px - x * scale, ty = py - y * scale
|
|
175
249
|
// where this fit lands, in world px: the first one after a board's commit shows its visible cohort (spec 28 A1.7)
|
|
176
250
|
recorder.placed({ x: -tx / scale, y: -ty / scale, w: vw / scale, h: vh / scale })
|
|
177
|
-
|
|
251
|
+
fly(tx, ty, scale, 320)
|
|
178
252
|
}
|
|
179
253
|
const fitKeys = (keys: string[], focus: boolean) => {
|
|
180
254
|
const st = useStore.getState()
|
|
@@ -212,11 +286,24 @@ export function Canvas() {
|
|
|
212
286
|
const el = wrap(), inst = ref.current
|
|
213
287
|
if (!el || !inst) return
|
|
214
288
|
const { positionX, positionY, scale } = inst.instance.transformState
|
|
215
|
-
const cx = el.clientWidth / 2, cy = el.clientHeight / 2
|
|
216
|
-
const k = target / scale // zoom about the
|
|
217
|
-
|
|
289
|
+
const cx = el.clientWidth / 2, cy = TOP + (el.clientHeight - TOP) / 2
|
|
290
|
+
const k = target / scale // zoom about the usable rectangle's centre (below the Mac app's strip with the inset)
|
|
291
|
+
fly(cx - (cx - positionX) * k, cy - (cy - positionY) * k, target, 250)
|
|
218
292
|
}
|
|
219
293
|
canvasCtl.cameraBusy = () => !!ref.current?.instance.animation
|
|
294
|
+
// the camera as the world is drawn now, mid-flight included: the white-out probes' bracket (spec 28 A3.8 #16)
|
|
295
|
+
canvasCtl.transform = () => {
|
|
296
|
+
const t = ref.current?.instance.transformState
|
|
297
|
+
return t ? { x: t.positionX, y: t.positionY, s: t.scale } : null
|
|
298
|
+
}
|
|
299
|
+
// a rect on screen now, where it will be when the flight lands: the same world point under the landing transform
|
|
300
|
+
canvasCtl.landing = (r: DOMRect) => {
|
|
301
|
+
const el = wrap(), inst = ref.current
|
|
302
|
+
if (!flight || !el || !inst?.instance.animation) return r
|
|
303
|
+
const { positionX, positionY, scale } = inst.instance.transformState
|
|
304
|
+
const c = el.getBoundingClientRect(), k = flight.scale / scale
|
|
305
|
+
return new DOMRect(c.left + flight.x + (r.left - c.left - positionX) * k, c.top + flight.y + (r.top - c.top - positionY) * k, r.width * k, r.height * k)
|
|
306
|
+
}
|
|
220
307
|
// a page that reloads itself when its canvas comes back (spec 28 A1.11) opens where the person was looking
|
|
221
308
|
const unkeep = keepOverResume(() => {
|
|
222
309
|
const t = ref.current?.instance.transformState
|
|
@@ -253,7 +340,12 @@ export function Canvas() {
|
|
|
253
340
|
let revealed = false
|
|
254
341
|
booted.current = true
|
|
255
342
|
// the page before this one reloaded itself when its canvas came back: its camera, on the board it showed
|
|
256
|
-
const
|
|
343
|
+
const board = useStore.getState().board
|
|
344
|
+
const carried = resumed?.camera && resumed.board === board ? resumed.camera : null
|
|
345
|
+
// else the camera this board was left at (A2.9) - a link naming a selection fits it instead, unless the app
|
|
346
|
+
// reloaded this tab after a crash
|
|
347
|
+
const named = !!(bootHash.n?.length || bootHash.f?.length || bootHash.s?.length)
|
|
348
|
+
const cam = carried ?? (!named || APP_REOPEN ? savedCamera(board) : null)
|
|
257
349
|
const fit = () => {
|
|
258
350
|
const keys = linkTargets(bootHash, useStore.getState().nodes)
|
|
259
351
|
if (keys.length) {
|
|
@@ -264,7 +356,7 @@ export function Canvas() {
|
|
|
264
356
|
const el = document.querySelector('.sh-canvas') as HTMLElement | null
|
|
265
357
|
if (cam && el && ref.current) {
|
|
266
358
|
recorder.placed({ x: -cam.x / cam.scale, y: -cam.y / cam.scale, w: el.clientWidth / cam.scale, h: el.clientHeight / cam.scale })
|
|
267
|
-
|
|
359
|
+
fly(cam.x, cam.y, cam.scale, 0)
|
|
268
360
|
} else if (keys.length) {
|
|
269
361
|
canvasCtl.fitNodes(keys)
|
|
270
362
|
} else {
|
|
@@ -429,6 +521,7 @@ export function Canvas() {
|
|
|
429
521
|
onTransformed={(r) => {
|
|
430
522
|
paintGrid(r.state.positionX, r.state.positionY, r.state.scale)
|
|
431
523
|
setCameraScale(r.state.scale) // keep the LOD's settle-scale current (cheap number write, no React)
|
|
524
|
+
if (booted.current) keepCamera(r.state.positionX, r.state.positionY, r.state.scale) // over a reload (A2.9)
|
|
432
525
|
clearTimeout(scaleTimer.current)
|
|
433
526
|
scaleTimer.current = window.setTimeout(() => setScale(r.state.scale), 120)
|
|
434
527
|
}}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { memo, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
|
|
2
2
|
import { cap, frameUrl, shownRev, useStore, CONFIG, type Node } from '../store.ts'
|
|
3
3
|
import { admit, release } from './admission.ts'
|
|
4
|
+
import { canvasCtl } from './ctl.ts'
|
|
4
5
|
import { CopyIcon, IntentGlyph, ParallelogramFillIcon, ReloadIcon, SlideFrameIcon, XIcon } from '../icons.tsx'
|
|
5
6
|
import { CommentLayer } from '../Comments.tsx'
|
|
6
7
|
import { useComments } from '../comments-store.ts'
|
|
@@ -8,7 +9,7 @@ import { threadHostKey } from '../keys.ts'
|
|
|
8
9
|
import { registerFrame, unregisterFrame } from './frame-registry.ts'
|
|
9
10
|
import { canvasClick, canvasPointer, frameGone, frameLoaded, pressNow, useJamCapture } from '../jam-capture.ts'
|
|
10
11
|
import { primeCameraFor } from './camera-broadcast.ts'
|
|
11
|
-
import { sleep, wake } from './sleep.ts'
|
|
12
|
+
import { scheduleSleep, sleep, wake } from './sleep.ts'
|
|
12
13
|
import { canAutoReload, shouldArmReadyWatch } from './ready-watch.ts'
|
|
13
14
|
import { Stickies, type NoteSpec } from './Sticky.tsx'
|
|
14
15
|
import { recorder } from '../recorder.ts'
|
|
@@ -108,9 +109,12 @@ export const FrameNode = memo(function FrameNode({ node }: { node: Node }) {
|
|
|
108
109
|
useEffect(() => {
|
|
109
110
|
if (!frame || node.missing) { admittedRef.current = false; setSrc(undefined); return } // gone: the card replaces the iframe; a return is a new document, admitted anew
|
|
110
111
|
if (admittedRef.current) return // the document exists (the frame's id changed under it): no slot
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
// visible first, then by distance to the centre of the canvas (the panel offsets the window's) - where the frame
|
|
113
|
+
// will be once the camera lands from a fit or zoom on its way (a board's first pick comes as the fit sets off)
|
|
114
|
+
const rank = () => {
|
|
115
|
+
const now = iframeRef.current?.getBoundingClientRect(), c = document.querySelector('.sh-canvas')?.getBoundingClientRect()
|
|
116
|
+
if (!now || !c) return Infinity
|
|
117
|
+
const r = canvasCtl.landing(now)
|
|
114
118
|
const visible = r.right > c.left && r.left < c.right && r.bottom > c.top && r.top < c.bottom
|
|
115
119
|
return (visible ? 0 : 1e7) + Math.hypot(r.x + r.width / 2 - c.x - c.width / 2, r.y + r.height / 2 - c.y - c.height / 2)
|
|
116
120
|
}
|
|
@@ -215,8 +219,8 @@ export const FrameNode = memo(function FrameNode({ node }: { node: Node }) {
|
|
|
215
219
|
// one being installed
|
|
216
220
|
if (interact || dirty.current || resizing.current || node.status !== 'ready' || node.stale || behind) return
|
|
217
221
|
if (node.themeOn !== undefined && node.themeOn !== node.theme) return // the frame has not painted the new theme yet
|
|
218
|
-
|
|
219
|
-
return () =>
|
|
222
|
+
// counted while it waits (sleep.ts bakeWork): a headless perf run measures only once no sleep is still to come
|
|
223
|
+
return scheduleSleep(() => { void sleep(node.key, iframe, { frame: frame.id, theme: node.theme, w, h, doc: node.shown }) }, 250)
|
|
220
224
|
}, [interact, node.status, node.theme, node.themeOn, node.rev, node.nav, node.stale, behind, w, h, node.missing, frame?.id, node.key, resizeTick])
|
|
221
225
|
useEffect(() => () => wake(node.key, iframeRef.current), [node.key])
|
|
222
226
|
|
|
@@ -10,9 +10,11 @@
|
|
|
10
10
|
*
|
|
11
11
|
* A new batch admits ONE frame first (the quickest first content: one boot alone is ~550 ms, four
|
|
12
12
|
* together ~1.8 s), then up to SLOTS at a time. Pure, apart from its timing: a board that mounts
|
|
13
|
-
* registers every node, the shell
|
|
14
|
-
*
|
|
15
|
-
* the
|
|
13
|
+
* registers every node, the shell aims the camera (its fit: a frame after mount at boot, 60 ms after
|
|
14
|
+
* on a switch; Canvas.tsx says so through aimed()), then the first pump ranks them (visible first,
|
|
15
|
+
* nearest the centre of the canvas first) on where each frame will be once the camera lands
|
|
16
|
+
* (canvasCtl.landing) - it need not wait out the fit's ~320 ms flight. With no aim it waits SETTLE, as
|
|
17
|
+
* long as that flight. A freed slot pumps on the next microtask, ranking again by the view of that moment.
|
|
16
18
|
*/
|
|
17
19
|
export const SLOTS = 4
|
|
18
20
|
/** A new batch's head start: one frame alone until it is done, or until this long - one stalled
|
|
@@ -21,6 +23,7 @@ export const HEAD_MS = 2000
|
|
|
21
23
|
let primed = false // the batch may use every slot
|
|
22
24
|
let gen = 0 // the batch: a pump scheduled for an earlier one is void
|
|
23
25
|
let timer: ReturnType<typeof setTimeout> | undefined
|
|
26
|
+
let settling: ReturnType<typeof setTimeout> | undefined // a pump waiting for the view to settle (SETTLE): aimed() runs it now
|
|
24
27
|
|
|
25
28
|
export interface Admission { key: string; rank: () => number; start: () => void }
|
|
26
29
|
|
|
@@ -28,17 +31,29 @@ const waiting = new Map<string, Admission>()
|
|
|
28
31
|
const active = new Set<string>()
|
|
29
32
|
let scheduled = false
|
|
30
33
|
|
|
31
|
-
/** Ask for a slot. Starts once the view has settled
|
|
34
|
+
/** Ask for a slot. Starts once the view has settled - the camera aimed where it will rest (aimed()), else SETTLE ms -
|
|
35
|
+
* when one is free; else queued by rank. */
|
|
32
36
|
export function admit(a: Admission): void {
|
|
33
37
|
if (active.has(a.key)) return
|
|
34
38
|
if (!waiting.size && !active.size) { // a new batch
|
|
35
|
-
primed = false; gen++; scheduled = false; clearTimeout(timer)
|
|
39
|
+
primed = false; gen++; scheduled = false; clearTimeout(timer); clearTimeout(settling); settling = undefined
|
|
36
40
|
timer = setTimeout(() => { primed = true; schedule(0) }, HEAD_MS)
|
|
37
41
|
}
|
|
38
42
|
waiting.set(a.key, a)
|
|
39
43
|
schedule(SETTLE)
|
|
40
44
|
}
|
|
41
|
-
|
|
45
|
+
/** The board fit animates ~320 ms from 60 ms after mount: with no aim said, the first pick waits for it to land and
|
|
46
|
+
* ranks on the settled view. */
|
|
47
|
+
const SETTLE = 350
|
|
48
|
+
|
|
49
|
+
/** The camera was just sent where it will rest - a fit (a board's first, ⇧1, a link's selection), a zoom, a camera
|
|
50
|
+
* restored (Canvas.tsx). A pump waiting for the view to settle runs now: its ranks read where each frame will be once
|
|
51
|
+
* the camera lands (canvasCtl.landing), so the first pick is the one SETTLE would have made, a flight earlier. */
|
|
52
|
+
export function aimed(): void {
|
|
53
|
+
if (settling === undefined) return
|
|
54
|
+
clearTimeout(settling); settling = undefined; scheduled = false
|
|
55
|
+
schedule(0)
|
|
56
|
+
}
|
|
42
57
|
|
|
43
58
|
/** The frame is done booting (ready, error, gone, or its watchdog took over): free the slot, or
|
|
44
59
|
* leave the queue if it never started. */
|
|
@@ -58,7 +73,7 @@ function schedule(ms: number): void {
|
|
|
58
73
|
if (scheduled) return
|
|
59
74
|
scheduled = true
|
|
60
75
|
const g = gen, run = () => { if (g === gen) pump() }
|
|
61
|
-
if (ms) setTimeout(run, ms); else queueMicrotask(run)
|
|
76
|
+
if (ms) settling = setTimeout(() => { settling = undefined; run() }, ms); else queueMicrotask(run)
|
|
62
77
|
}
|
|
63
78
|
|
|
64
79
|
function pump(): void {
|
|
@@ -74,4 +89,4 @@ function pump(): void {
|
|
|
74
89
|
}
|
|
75
90
|
|
|
76
91
|
/** For tests: nothing queued, nothing active. */
|
|
77
|
-
export function resetAdmission(): void { waiting.clear(); active.clear(); primed = false; scheduled = false; gen++; clearTimeout(timer) }
|
|
92
|
+
export function resetAdmission(): void { waiting.clear(); active.clear(); primed = false; scheduled = false; gen++; clearTimeout(timer); clearTimeout(settling); settling = undefined }
|
|
@@ -31,4 +31,10 @@ export const canvasCtl = {
|
|
|
31
31
|
cameraBusy(): boolean { return false },
|
|
32
32
|
/** What the camera shows now, in world px (null with no canvas) - a load's visible cohort when no fit landed. */
|
|
33
33
|
view(): { x: number; y: number; w: number; h: number } | null { return null },
|
|
34
|
+
/** Where a rect on screen now will be once the camera lands from the flight it is on (a fit, a zoom) - itself while
|
|
35
|
+
* the camera rests: the boot queue ranks a board's first frame on the view the person will see (admission.ts). */
|
|
36
|
+
landing(r: DOMRect): DOMRect { return r },
|
|
37
|
+
/** The camera now, `{ x, y, s }` as the world is drawn (null with no canvas): the white-out probes' bracket (spec 28
|
|
38
|
+
* A3.8 #16) and a hide mid-flight (A3.8 #43). Assigned by Canvas.tsx from its camera. */
|
|
39
|
+
transform(): { x: number; y: number; s: number } | null { return null },
|
|
34
40
|
}
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
import { ROUTE } from '../../const.ts'
|
|
29
29
|
import { BAKES, PUBLISHED } from '../store.ts'
|
|
30
30
|
import { api } from '../api.ts'
|
|
31
|
+
import { PERF_RUN } from '../perf-run.ts'
|
|
31
32
|
import { readOwn, sleepRule } from '../../../shared/sleep-rule.ts'
|
|
33
|
+
import type { BakeWork } from '../../../shared/perf-run.ts'
|
|
32
34
|
|
|
33
35
|
/** `doc`: the revision the document shows (spec 26) - the compiler refuses a document behind its frame */
|
|
34
36
|
export interface SleepKey { frame: string; theme: string; w: number; h: number; doc?: string }
|
|
@@ -51,10 +53,32 @@ const keyOf = (k: SleepKey) => `${k.frame}|${k.theme}|${Math.round(k.w)}|${Math.
|
|
|
51
53
|
const asleep = new Map<string, { key: string; doc: Document }>()
|
|
52
54
|
/** How many frames are asleep now (the recorder's weight of a settled load, spec 28 A1.7). */
|
|
53
55
|
export const sleepingCount = (): number => asleep.size
|
|
56
|
+
/**
|
|
57
|
+
* The page's own bake work (spec 28 A3.8 #18): four counts of their own - `pending` below is the current request
|
|
58
|
+
* per node and survives a successful sleep, so it says nothing about idleness. `scheduled`: FrameNode's 250 ms
|
|
59
|
+
* timer and both retry timers, every one through `scheduleSleep()`; `running`: a sleep from its entry to its
|
|
60
|
+
* `finally` (fonts, the ask, the decode, the texture installed); `queued`: asks batched and not sent yet;
|
|
61
|
+
* `inflight`: the bake POST on its way. A headless perf run measures only once all four are zero and the server's
|
|
62
|
+
* own jobs for the run are too (bake.ts `jobsOf`).
|
|
63
|
+
*/
|
|
64
|
+
let scheduled = 0, running = 0, inflight = 0
|
|
65
|
+
export const bakeWork = (): BakeWork => ({ scheduled, running, queued: queue.length, inflight })
|
|
66
|
+
/** All four at zero. Not the run's bake-idle: the driver adds the server's `jobsOf(run)`. */
|
|
67
|
+
export const bakeIdle = (): boolean => { const w = bakeWork(); return !w.scheduled && !w.running && !w.queued && !w.inflight }
|
|
68
|
+
/** A sleep to try in `ms` (FrameNode's settle, a compile still running, one retry of a failed compile), counted while
|
|
69
|
+
* it waits; the cancel stops it and its count. */
|
|
70
|
+
export function scheduleSleep(fn: () => void, ms: number): () => void {
|
|
71
|
+
scheduled++
|
|
72
|
+
let done = false
|
|
73
|
+
const t = setTimeout(() => { if (done) return; done = true; scheduled--; fn() }, ms)
|
|
74
|
+
return () => { if (done) return; done = true; scheduled--; clearTimeout(t) }
|
|
75
|
+
}
|
|
54
76
|
/** The node's current request, so a stale answer (a newer sleep, a wake in between) is dropped. */
|
|
55
77
|
const pending = new Map<string, number>()
|
|
56
78
|
let seq = 0
|
|
57
|
-
/** Nodes with
|
|
79
|
+
/** Nodes with a retry of a failed compile in flight - or, in a headless perf run, spent: a run's frame retries once
|
|
80
|
+
* until it wakes, so the run can reach bake-idle; every other canvas retries every 4 s for as long as the frame
|
|
81
|
+
* rests, as before 0.27.2, so a frame recovers when the server does. */
|
|
58
82
|
const retried = new Set<string>()
|
|
59
83
|
const RETRY_MS = 4000
|
|
60
84
|
/** The server's answer for a compile still running (src/server/bake.ts COMPILING), and how many times a
|
|
@@ -95,27 +119,39 @@ function ask(key: SleepKey): Promise<Answer> {
|
|
|
95
119
|
for (const q of batch) { const kk = keyOf(q.key); const e = byKey.get(kk); if (e) e.waiters.push(q.resolve); else byKey.set(kk, { key: q.key, waiters: [q.resolve] }) }
|
|
96
120
|
const asks = [...byKey.values()].map((e) => ({ frame: e.key.frame, theme: e.key.theme, w: Math.round(e.key.w), h: Math.round(e.key.h), ...(e.key.doc ? { doc: e.key.doc } : {}) }))
|
|
97
121
|
let data: { answers?: (Answer & SleepKey)[] } | null = null
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
122
|
+
inflight++
|
|
123
|
+
try {
|
|
124
|
+
const index = PUBLISHED ? await staticAnswers() : null
|
|
125
|
+
if (!index) {
|
|
126
|
+
try {
|
|
127
|
+
const r = await api('bakes', { method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() }, body: JSON.stringify({ asks }) })
|
|
128
|
+
data = r.ok ? await r.json() : null
|
|
129
|
+
} catch { data = null }
|
|
130
|
+
}
|
|
131
|
+
answerAll(byKey, index, data)
|
|
132
|
+
} finally { inflight-- }
|
|
110
133
|
}, 40)
|
|
111
134
|
})
|
|
112
135
|
}
|
|
136
|
+
/** Every waiter of a batch, its key's answer - before the POST stops counting, so the page is never idle between. */
|
|
137
|
+
function answerAll(byKey: Map<string, { key: SleepKey; waiters: ((a: Answer) => void)[] }>, index: Record<string, Answer> | null, data: { answers?: (Answer & SleepKey)[] } | null): void {
|
|
138
|
+
for (const e of byKey.values()) {
|
|
139
|
+
const a = index ? index[keyOf(e.key)] : data?.answers?.find((x) => keyOf(x) === keyOf(e.key))
|
|
140
|
+
const answer: Answer = a ? (a.ok ? { ok: true, targets: a.targets } : { ok: false, error: a.error }) : { ok: false, error: 'no answer' }
|
|
141
|
+
for (const w of e.waiters) w(answer)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
113
144
|
|
|
114
145
|
/** Put a node's live document to sleep under `key`. Resolves once the override is installed (or
|
|
115
146
|
* the document was found to have no effects, or the compile failed and the frame stays live).
|
|
116
147
|
* A wake or a newer sleep in the meantime supersedes it. */
|
|
117
148
|
export async function sleep(nodeKey: string, iframe: HTMLIFrameElement, key: SleepKey): Promise<'asleep' | 'live'> {
|
|
118
149
|
if (AWAKE) return 'live'
|
|
150
|
+
running++
|
|
151
|
+
try { return await sleepNow(nodeKey, iframe, key) } finally { running-- }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function sleepNow(nodeKey: string, iframe: HTMLIFrameElement, key: SleepKey): Promise<'asleep' | 'live'> {
|
|
119
155
|
const k = keyOf(key)
|
|
120
156
|
const doc = iframe.contentDocument
|
|
121
157
|
if (!doc?.body) return 'live'
|
|
@@ -142,7 +178,7 @@ export async function sleep(nodeKey: string, iframe: HTMLIFrameElement, key: Sle
|
|
|
142
178
|
const was = compiling.get(nodeKey)
|
|
143
179
|
const n = (was && was.key === k ? was.n : 0) + 1
|
|
144
180
|
compiling.set(nodeKey, { key: k, n })
|
|
145
|
-
if (n <= COMPILING_TRIES) {
|
|
181
|
+
if (n <= COMPILING_TRIES) { scheduleSleep(() => { if (current()) void sleep(nodeKey, iframe, key) }, RETRY_MS); return 'live' }
|
|
146
182
|
}
|
|
147
183
|
// no compiler (a published canvas, a compile that failed): the pause alone, the glass live -
|
|
148
184
|
// never an effect layer without its texture
|
|
@@ -156,10 +192,13 @@ export async function sleep(nodeKey: string, iframe: HTMLIFrameElement, key: Sle
|
|
|
156
192
|
if (PUBLISHED && targets.length && doc.querySelector('meta[name="mv-bakes"]')?.getAttribute('content') !== String(BAKES)) targets = []
|
|
157
193
|
if (!install(doc, targets)) return 'live'
|
|
158
194
|
// a certified sleep is remembered; the pause-only fallback is not, so the next lifecycle event
|
|
159
|
-
// asks again (a compile the source outran, a server hiccup), and
|
|
160
|
-
|
|
195
|
+
// asks again (a compile the source outran, a server hiccup), and a retry is scheduled now. A canvas retries
|
|
196
|
+
// every 4 s while the frame rests: the retry clears its own mark, so a failure after a failure asks again and
|
|
197
|
+
// the glass sleeps once the server recovers. A headless perf run's retry keeps its mark until the node wakes -
|
|
198
|
+
// one retry, then nothing more, or a frame the compiler refuses would keep the run from ever being bake-idle
|
|
199
|
+
if (targets.length) { asleep.set(nodeKey, { key: k, doc }); compiling.delete(nodeKey); retried.delete(nodeKey) }
|
|
161
200
|
else if (answer.ok === false && answer.error === COMPILING) { /* out of looks: the pause alone, final */ }
|
|
162
|
-
else if (!PUBLISHED && !retried.has(nodeKey)) { retried.add(nodeKey);
|
|
201
|
+
else if (!PUBLISHED && !retried.has(nodeKey)) { retried.add(nodeKey); scheduleSleep(() => { if (!PERF_RUN) retried.delete(nodeKey); if (current()) void sleep(nodeKey, iframe, key) }, RETRY_MS) } // a static miss is final
|
|
163
202
|
return 'asleep'
|
|
164
203
|
}
|
|
165
204
|
|
|
@@ -168,6 +207,7 @@ export function wake(nodeKey: string, iframe: HTMLIFrameElement | null): void {
|
|
|
168
207
|
pending.delete(nodeKey)
|
|
169
208
|
asleep.delete(nodeKey)
|
|
170
209
|
compiling.delete(nodeKey)
|
|
210
|
+
retried.delete(nodeKey)
|
|
171
211
|
const doc = iframe?.contentDocument
|
|
172
212
|
const st = doc?.getElementById(STYLE_ID)
|
|
173
213
|
if (!doc || !st) return
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* when its turn comes.
|
|
8
8
|
*/
|
|
9
9
|
import { admit, release } from './admission.ts'
|
|
10
|
+
import { canvasCtl } from './ctl.ts'
|
|
10
11
|
import { frameIsLeased, useStore, type Node } from '../store.ts'
|
|
11
12
|
|
|
12
13
|
const rect = (key: string) => document.querySelector(`[data-node="${CSS.escape(key)}"]`)?.getBoundingClientRect()
|
|
@@ -21,7 +22,7 @@ function onScreen(key: string): boolean {
|
|
|
21
22
|
return r.right > c.left - mx && r.left < c.right + mx && r.bottom > c.top - my && r.top < c.bottom + my
|
|
22
23
|
}
|
|
23
24
|
const rank = (key: string) => () => {
|
|
24
|
-
const
|
|
25
|
+
const now = rect(key), c = view(), r = now && canvasCtl.landing(now) // where it will be once a camera flight lands
|
|
25
26
|
return r && c ? Math.hypot(r.x + r.width / 2 - c.x - c.width / 2, r.y + r.height / 2 - c.y - c.height / 2) : Infinity
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one usable-rectangle helper (spec 28 A2.9 v1.8 #6, A3.8 #31): where the shell may place what a person must
|
|
3
|
+
* see, under the Mac app's transparent strip. Owner: the one-ground stream (marver 0.27.2).
|
|
4
|
+
*
|
|
5
|
+
* `TOP` is 44 only when the app says this document must apply it (`topInset`, from `mv:doc`'s answer) **and** the
|
|
6
|
+
* presentation contract is whole (`onPresent` and `presented`): a shell never trusts half a contract, so in Chrome,
|
|
7
|
+
* on a published canvas, under `marver shot` and inside app 0.1 it is 0 and nothing moves. `--mv-top` goes on
|
|
8
|
+
* `:root` (some portals mount outside `.sh-app`), and every rule reads `var(--mv-top, 0px)`.
|
|
9
|
+
*
|
|
10
|
+
* FROZEN before the A3 streams split (A3.8 #53): `TOP`, `VISIBLE_TOP`, `usable()`, `onScreen()` and `applyInset()`.
|
|
11
|
+
* Consumers: the top-anchored layers, the selection bar, tips and menus (`TOP + 8`), insets(), focus, play sizes
|
|
12
|
+
* and Jam's fill use `usable()`; seen marks, visibleNodes(), A3.3's probes and A4.3's full-view test use `onScreen()`.
|
|
13
|
+
*/
|
|
14
|
+
import { EDGE_FADE, TOP_INSET, type Inset } from '../../shared/app-api.ts'
|
|
15
|
+
import { APP } from './marver-app.ts'
|
|
16
|
+
|
|
17
|
+
/** 44 in app 0.2+ for a document main placed full height, with the presentation channel to match; else 0. */
|
|
18
|
+
export const TOP: Inset = APP?.topInset === TOP_INSET && typeof APP.onPresent === 'function' && typeof APP.presented === 'function' ? TOP_INSET : 0
|
|
19
|
+
/** Below the scroll edge: what counts as seen. 0 with no inset (Chrome is unchanged). */
|
|
20
|
+
export const VISIBLE_TOP = TOP ? TOP + EDGE_FADE : 0
|
|
21
|
+
|
|
22
|
+
/** main.tsx, before the first render: the variable every placement reads, on :root. Nothing without the inset. */
|
|
23
|
+
export function applyInset(): void {
|
|
24
|
+
if (!TOP) return
|
|
25
|
+
document.documentElement.style.setProperty('--mv-top', `${TOP}px`)
|
|
26
|
+
document.documentElement.classList.add('mv-inset')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The view below the strip, in client px. */
|
|
30
|
+
export function usable(): { top: number; left: number; width: number; height: number } {
|
|
31
|
+
return { top: TOP, left: 0, width: innerWidth, height: Math.max(0, innerHeight - TOP) }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The part of a client rect on screen below the scroll edge, or null when none is. */
|
|
35
|
+
export function onScreen(r: DOMRectReadOnly): DOMRect | null {
|
|
36
|
+
const top = Math.max(r.top, VISIBLE_TOP)
|
|
37
|
+
const bottom = Math.min(r.bottom, innerHeight)
|
|
38
|
+
const left = Math.max(r.left, 0)
|
|
39
|
+
const right = Math.min(r.right, innerWidth)
|
|
40
|
+
return bottom > top && right > left ? new DOMRect(left, top, right - left, bottom - top) : null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// dev-only inspection hook for tests (never installed in published builds)
|
|
44
|
+
if (typeof window !== 'undefined' && (import.meta as { env?: { DEV?: boolean } }).env?.DEV) (window as unknown as { __mvInset: unknown }).__mvInset = { TOP, VISIBLE_TOP, usable, onScreen }
|