@1agh/maude 2.0.6 → 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/studio/access/closure.ts +156 -16
- package/apps/studio/access/filters.ts +27 -0
- package/apps/studio/actions/agents.ts +54 -0
- package/apps/studio/actions/ctx.ts +3 -0
- package/apps/studio/actions/defs/sync.ts +13 -0
- package/apps/studio/actions/defs/view.ts +59 -3
- package/apps/studio/actions/keymap.gen.ts +35 -0
- package/apps/studio/actions/menu.ts +2 -0
- package/apps/studio/actions/types.ts +3 -1
- package/apps/studio/actions.manifest.json +136 -1
- package/apps/studio/actions.parity.json +25 -1
- package/apps/studio/annotations/ui/ai-seen.tsx +4 -3
- package/apps/studio/annotations/ui/ride.ts +2 -1
- package/apps/studio/annotations-context-toolbar.tsx +5 -4
- package/apps/studio/annotations-layer.tsx +4 -3
- package/apps/studio/api.ts +383 -128
- package/apps/studio/artboard-activity-overlay.tsx +4 -4
- package/apps/studio/artboard-ai-copies.tsx +4 -4
- package/apps/studio/artboard-freeze.ts +108 -0
- package/apps/studio/artboard-live-gate.tsx +414 -45
- package/apps/studio/artboard-live.ts +526 -31
- package/apps/studio/artboard-placeholder.ts +197 -0
- package/apps/studio/artboard-still-raster.ts +485 -0
- package/apps/studio/artboard-still-warmup.ts +221 -0
- package/apps/studio/artboard-still.ts +1188 -0
- package/apps/studio/artboard-webgl.ts +2 -1
- package/apps/studio/asset-placeholder.tsx +237 -132
- package/apps/studio/asset-upload-bars.tsx +4 -4
- package/apps/studio/bin/_perf-probe-open.mjs +364 -0
- package/apps/studio/bin/_perf-shared.mjs +12 -7
- package/apps/studio/bin/_pw-launch.mjs +26 -1
- package/apps/studio/bin/perf.sh +19 -0
- package/apps/studio/bridge/dgn-protocol.ts +35 -0
- package/apps/studio/canvas-build-sandbox.ts +69 -13
- package/apps/studio/canvas-camera.ts +90 -0
- package/apps/studio/canvas-comment-mount.tsx +9 -9
- package/apps/studio/canvas-lib.tsx +160 -34
- package/apps/studio/canvas-pages-view.tsx +465 -0
- package/apps/studio/canvas-pages.ts +305 -0
- package/apps/studio/canvas-rows.ts +62 -0
- package/apps/studio/canvas-shell.tsx +62 -16
- package/apps/studio/canvas-theme-icons.tsx +41 -0
- package/apps/studio/canvas-theme-pill.tsx +15 -6
- package/apps/studio/canvas-theme.ts +12 -11
- package/apps/studio/client/app.jsx +7 -0
- package/apps/studio/client/canvas-url.js +23 -1
- package/apps/studio/client/hooks/canvas-origin-probe.js +34 -0
- package/apps/studio/client/hooks/use-action-keys.jsx +3 -1
- package/apps/studio/client/hooks/use-canvas-bridge.jsx +1 -1
- package/apps/studio/client/hooks/use-palette-and-panels.jsx +23 -6
- package/apps/studio/client/hooks/use-photo-and-timeline.jsx +16 -8
- package/apps/studio/client/hooks/use-project-data.jsx +11 -2
- package/apps/studio/client/hooks/use-shell-core.jsx +19 -9
- package/apps/studio/client/index-loader.ts +41 -21
- package/apps/studio/client/inspector/inspector-panel.jsx +35 -14
- package/apps/studio/client/shell/viewport.jsx +32 -16
- package/apps/studio/client/tree/tree.jsx +17 -0
- package/apps/studio/client/v2/canvases/canvases-panel.jsx +24 -0
- package/apps/studio/client/v2/canvases/use-canvas-index.js +24 -1
- package/apps/studio/client/v2/code/canvas-error-card.jsx +14 -2
- package/apps/studio/client/v2/code/canvas-imports-card.jsx +7 -3
- package/apps/studio/client/v2/code/canvas-imports-words.js +16 -0
- package/apps/studio/client/v2/code/canvas-waiting-card.jsx +59 -5
- package/apps/studio/client/v2/code/canvas-waiting.js +18 -1
- package/apps/studio/client/v2/code/code-consent-sheet.jsx +87 -0
- package/apps/studio/client/v2/code/code-consent.js +67 -0
- package/apps/studio/client/v2/diagnostics/sync-details/sync-details-model.js +62 -10
- package/apps/studio/client/v2/diagnostics/sync-details/sync-details.jsx +314 -5
- package/apps/studio/client/v2/layers/artboard-layers.jsx +24 -5
- package/apps/studio/client/v2/layers/layers-request.js +49 -0
- package/apps/studio/client/v2/left-panel/canvases-pinned.jsx +93 -3
- package/apps/studio/client/v2/left-panel/ds-boards.js +39 -0
- package/apps/studio/client/v2/left-panel/left-panel-model.js +13 -0
- package/apps/studio/client/v2/left-panel/left-panel.css +24 -0
- package/apps/studio/client/v2/shell/canvas-crash-guard.js +40 -5
- package/apps/studio/client/v2/shell/canvas-mode.js +17 -1
- package/apps/studio/client/v2/shell/floating-panels.css +37 -1
- package/apps/studio/client/v2/shell/mode-switch.jsx +14 -3
- package/apps/studio/client/v2/shell/opening-skeleton.js +118 -0
- package/apps/studio/client/v2/shell/opening-skeleton.jsx +103 -0
- package/apps/studio/client/v2/shell/pages-pick.js +49 -0
- package/apps/studio/client/v2/shell/project-menu-model.js +3 -0
- package/apps/studio/client/v2/shell/share-cluster-host.jsx +3 -1
- package/apps/studio/client/v2/shell/shell-parity.json +8 -0
- package/apps/studio/client/v2/shell/use-canvas-mode-lane.js +30 -0
- package/apps/studio/comments-overlay.tsx +12 -11
- package/apps/studio/config-reload-wire.ts +4 -1
- package/apps/studio/config.schema.json +6 -0
- package/apps/studio/context.ts +37 -1
- package/apps/studio/dist/client.bundle.js +720 -720
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/ds/board/board.css +6 -0
- package/apps/studio/ds/board/ds-bar.tsx +21 -3
- package/apps/studio/ds/board/specimen.tsx +6 -3
- package/apps/studio/ds/board/template.ts +39 -19
- package/apps/studio/ds/cli.ts +7 -1
- package/apps/studio/ds/component-list.ts +2 -1
- package/apps/studio/ds/default.ts +6 -1
- package/apps/studio/ds/ds-resolver.ts +58 -8
- package/apps/studio/ds/engine.ts +3 -1
- package/apps/studio/ds/folder-systems.ts +199 -0
- package/apps/studio/ds/pairing-css.ts +2 -1
- package/apps/studio/ds/rename.ts +10 -3
- package/apps/studio/ds/shell-fallbacks.ts +2 -1
- package/apps/studio/ds/upgrade-stage.ts +6 -2
- package/apps/studio/editing/ai-point-ring.tsx +4 -4
- package/apps/studio/editing/ai-scope-outline.tsx +4 -4
- package/apps/studio/editing/align-bar.tsx +4 -4
- package/apps/studio/editing/anchor-report.ts +3 -2
- package/apps/studio/editing/artboard-handles.tsx +4 -4
- package/apps/studio/editing/corner-dots.tsx +4 -4
- package/apps/studio/editing/crop-mode.tsx +4 -4
- package/apps/studio/editing/drop-chip.tsx +4 -4
- package/apps/studio/editing/empty-report.ts +3 -2
- package/apps/studio/editing/focus-model.tsx +4 -4
- package/apps/studio/editing/gap-bands.tsx +3 -3
- package/apps/studio/editing/hold-rings.tsx +4 -4
- package/apps/studio/editing/lock-badge.tsx +3 -3
- package/apps/studio/editing/long-page.ts +23 -1
- package/apps/studio/editing/nudge.tsx +2 -2
- package/apps/studio/editing/page-activity.ts +4 -3
- package/apps/studio/editing/paste-bar.tsx +4 -4
- package/apps/studio/editing/pen/overlay.tsx +4 -3
- package/apps/studio/editing/place-freely.tsx +3 -3
- package/apps/studio/editing/reorder-slot.tsx +3 -3
- package/apps/studio/editing/selection.tsx +4 -4
- package/apps/studio/editing/size-ghost.tsx +4 -4
- package/apps/studio/editing/tab-order.tsx +4 -4
- package/apps/studio/editing/text-in-place.tsx +4 -4
- package/apps/studio/editing/undo-preview.tsx +3 -3
- package/apps/studio/equal-spacing-handles.tsx +3 -3
- package/apps/studio/frame-clock.ts +89 -0
- package/apps/studio/http.ts +66 -32
- package/apps/studio/index/ds-usage.ts +4 -1
- package/apps/studio/index-cache.ts +272 -0
- package/apps/studio/inspect-overlay.tsx +4 -3
- package/apps/studio/inspect.ts +7 -2
- package/apps/studio/link-chip-overlay.tsx +4 -3
- package/apps/studio/measure-overlay.tsx +4 -3
- package/apps/studio/present/pointer-dot.tsx +3 -2
- package/apps/studio/present/present-media.ts +6 -2
- package/apps/studio/present/present-stage.tsx +3 -2
- package/apps/studio/preview/preview-camera.tsx +3 -2
- package/apps/studio/routes/sync.ts +176 -0
- package/apps/studio/safe-zones-overlay.tsx +3 -2
- package/apps/studio/skip-dirs.ts +103 -47
- package/apps/studio/studio-page-host.ts +70 -0
- package/apps/studio/sync/code-module-consent.ts +86 -0
- package/apps/studio/sync/file-ledger.ts +24 -0
- package/apps/studio/sync/file-plane.ts +458 -53
- package/apps/studio/sync/held-deletes.ts +230 -0
- package/apps/studio/sync/hubs-config.ts +59 -2
- package/apps/studio/sync/index.ts +99 -15
- package/apps/studio/sync/seed-progress.ts +92 -2
- package/apps/studio/sync/settings.ts +36 -1
- package/apps/studio/sync/status.ts +15 -1
- package/apps/studio/sync/writer-registry.ts +5 -0
- package/apps/studio/text-caret.ts +5 -3
- package/apps/studio/toolbars/toolbar-rect.ts +3 -2
- package/apps/studio/use-annotation-resize.tsx +4 -3
- package/apps/studio/use-artboard-drag.tsx +3 -2
- package/apps/studio/use-element-resize.tsx +7 -6
- package/apps/studio/use-grid-track-handles.tsx +5 -4
- package/apps/studio/use-selection-set.tsx +64 -4
- package/apps/studio/use-spacing-handles.tsx +7 -6
- package/apps/studio/video-comp.tsx +55 -42
- package/apps/studio/video-play-overlay.tsx +4 -3
- package/apps/studio/whats-new.json +27 -0
- package/cli/commands/design.mjs +5 -2
- package/cli/commands/hub.mjs +10 -1
- package/cli/lib/bash-guard.mjs +14 -0
- package/cli/lib/design-help.gen.mjs +1 -1
- package/cli/lib/design-link.mjs +42 -17
- package/cli/lib/hub-purge.mjs +183 -0
- package/package.json +8 -8
- package/plugins/design/templates/_shell.html +164 -1
package/apps/studio/inspect.ts
CHANGED
|
@@ -621,6 +621,11 @@ const INSPECTOR_SCRIPT = `
|
|
|
621
621
|
|
|
622
622
|
var pinNodes = [];
|
|
623
623
|
var rafToken = null;
|
|
624
|
+
// the pins follow the camera: never deferred by the gesture freeze (frame-clock.ts)
|
|
625
|
+
var pinRaf = function (fn) {
|
|
626
|
+
var ff = window.__maudeFrameFreeze;
|
|
627
|
+
return ff ? ff.raf(fn) : requestAnimationFrame(fn);
|
|
628
|
+
};
|
|
624
629
|
|
|
625
630
|
function buildPinNodes() {
|
|
626
631
|
pinLayer.innerHTML = '';
|
|
@@ -682,10 +687,10 @@ const INSPECTOR_SCRIPT = `
|
|
|
682
687
|
function tick() {
|
|
683
688
|
rafToken = null;
|
|
684
689
|
placePins();
|
|
685
|
-
if (pinNodes.length) rafToken =
|
|
690
|
+
if (pinNodes.length) rafToken = pinRaf(tick);
|
|
686
691
|
}
|
|
687
692
|
function startTick() {
|
|
688
|
-
if (rafToken == null && pinNodes.length) rafToken =
|
|
693
|
+
if (rafToken == null && pinNodes.length) rafToken = pinRaf(tick);
|
|
689
694
|
}
|
|
690
695
|
|
|
691
696
|
function schedulePins() { buildPinNodes(); startTick(); }
|
|
@@ -12,6 +12,7 @@ import { linkLabel, parseLinkTarget } from './bridge/link-target.ts';
|
|
|
12
12
|
import { modeShows } from './bridge/mode-shows.ts';
|
|
13
13
|
import { DsIcon } from './canvas-ds-icons.tsx';
|
|
14
14
|
import { resolveSelectionEl } from './dom-selection.ts';
|
|
15
|
+
import { frameCaf, frameRaf } from './frame-clock.ts';
|
|
15
16
|
import { type Selection, useSelectionSet } from './use-selection-set.tsx';
|
|
16
17
|
|
|
17
18
|
const LINK_ATTR = 'data-cd-link';
|
|
@@ -139,11 +140,11 @@ export function LinkChipOverlay() {
|
|
|
139
140
|
: { words, left, top, from }
|
|
140
141
|
);
|
|
141
142
|
}
|
|
142
|
-
raf.current =
|
|
143
|
+
raf.current = frameRaf(tick);
|
|
143
144
|
};
|
|
144
|
-
raf.current =
|
|
145
|
+
raf.current = frameRaf(tick);
|
|
145
146
|
return () => {
|
|
146
|
-
if (raf.current != null)
|
|
147
|
+
if (raf.current != null) frameCaf(raf.current);
|
|
147
148
|
raf.current = null;
|
|
148
149
|
};
|
|
149
150
|
}, [editing, selected]);
|
|
@@ -29,6 +29,7 @@ import { modeShows } from './bridge/mode-shows.ts';
|
|
|
29
29
|
import { useArtboardsContext } from './canvas-lib.tsx';
|
|
30
30
|
import { resolveSelectionEl } from './dom-selection.ts';
|
|
31
31
|
import { computePairGap } from './equal-spacing-detector.ts';
|
|
32
|
+
import { frameCaf, frameRaf } from './frame-clock.ts';
|
|
32
33
|
import { resolveHoverTarget } from './input-router.tsx';
|
|
33
34
|
import { type ModifierState, reduceModifiers } from './use-cursor-modifiers.tsx';
|
|
34
35
|
import { useGovernedMode } from './use-governed-mode.ts';
|
|
@@ -234,12 +235,12 @@ export function MeasureOverlay() {
|
|
|
234
235
|
} else {
|
|
235
236
|
hideBoth();
|
|
236
237
|
}
|
|
237
|
-
rafId =
|
|
238
|
+
rafId = frameRaf(tick);
|
|
238
239
|
};
|
|
239
|
-
rafId =
|
|
240
|
+
rafId = frameRaf(tick);
|
|
240
241
|
return () => {
|
|
241
242
|
alive = false;
|
|
242
|
-
if (rafId != null)
|
|
243
|
+
if (rafId != null) frameCaf(rafId);
|
|
243
244
|
};
|
|
244
245
|
}, [active, one, hoverEl, zoom]);
|
|
245
246
|
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
import { type JSX, useEffect, useRef } from 'react';
|
|
15
15
|
import { canvasModeStore } from '../bridge/canvas-mode-store.ts';
|
|
16
|
+
import { frameCafOn, frameRafOn } from '../frame-clock.ts';
|
|
16
17
|
import { useCollab, useForeignAwareness } from '../use-collab.tsx';
|
|
17
18
|
import { sanitizePointer, type WorldPoint } from './pointer-point.ts';
|
|
18
19
|
|
|
@@ -310,8 +311,8 @@ export function usePointerDot(opts: UsePointerDotOptions): void {
|
|
|
310
311
|
},
|
|
311
312
|
color: () => collabRef.current?.myColor || 'oklch(0.74 0.16 40)',
|
|
312
313
|
now: () => (typeof performance !== 'undefined' ? performance.now() : Date.now()),
|
|
313
|
-
raf: (cb) => win
|
|
314
|
-
caf: (id) => win
|
|
314
|
+
raf: (cb) => frameRafOn(win, cb),
|
|
315
|
+
caf: (id) => frameCafOn(win, id),
|
|
315
316
|
reducedMotion: () => {
|
|
316
317
|
try {
|
|
317
318
|
return !!win.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
|
|
@@ -114,8 +114,12 @@ export interface PresentMedia extends StageMedia {
|
|
|
114
114
|
hasClip(artboardId: string): boolean;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
/**
|
|
118
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Retries for a Player that is not mounted yet, and the wait between them. A video artboard far from where the
|
|
119
|
+
* canvas was mounts its Player only once Present brings it on screen (2.0.7 — far media loads nothing), a frame
|
|
120
|
+
* or a few after `arrive`: ~1.2 s of patience.
|
|
121
|
+
*/
|
|
122
|
+
const MOUNT_TRIES = 20;
|
|
119
123
|
const MOUNT_WAIT_MS = 60;
|
|
120
124
|
/** After this long a clip that was told to play with sound but is not playing is retried muted. */
|
|
121
125
|
const SOUND_CHECK_MS = 400;
|
|
@@ -23,6 +23,7 @@ import { type RefObject, useEffect, useLayoutEffect, useRef, useSyncExternalStor
|
|
|
23
23
|
import { canvasModeStore, reportPresentPosition } from '../bridge/canvas-mode-store.ts';
|
|
24
24
|
import type { ArtboardRect } from '../canvas-lib.tsx';
|
|
25
25
|
import { togglePlayback } from '../editing/video-play.ts';
|
|
26
|
+
import { frameCafOn, frameRafOn } from '../frame-clock.ts';
|
|
26
27
|
import { resolveBleedMm, resolveMmPx } from '../print/units.ts';
|
|
27
28
|
import {
|
|
28
29
|
type AwarenessChanges,
|
|
@@ -734,8 +735,8 @@ export function usePresentStage(opts: UsePresentStageOptions): void {
|
|
|
734
735
|
readMeta: () =>
|
|
735
736
|
(win as unknown as { __canvas_meta__?: { present?: PresentMeta } }).__canvas_meta__
|
|
736
737
|
?.present,
|
|
737
|
-
raf: (cb) => win
|
|
738
|
-
caf: (id) => win
|
|
738
|
+
raf: (cb) => frameRafOn(win, cb),
|
|
739
|
+
caf: (id) => frameCafOn(win, id),
|
|
739
740
|
now: () => (typeof performance !== 'undefined' ? performance.now() : Date.now()),
|
|
740
741
|
reducedMotion: () => reducedMotion(win),
|
|
741
742
|
liftMs: () => cssMs(win),
|
|
@@ -19,6 +19,7 @@ import { type RefObject, useEffect, useRef, useSyncExternalStore } from 'react';
|
|
|
19
19
|
import { canvasModeStore } from '../bridge/canvas-mode-store.ts';
|
|
20
20
|
import type { CanvasModeV2 } from '../bridge/canvas-modes.ts';
|
|
21
21
|
import { type Insets, visibleRect, ZERO_INSETS } from '../bridge/occlusion.ts';
|
|
22
|
+
import { frameCafOn, frameRafOn } from '../frame-clock.ts';
|
|
22
23
|
|
|
23
24
|
export interface Camera {
|
|
24
25
|
x: number;
|
|
@@ -385,8 +386,8 @@ export function usePreviewCamera<T extends BoardRect>(opts: UsePreviewCameraOpti
|
|
|
385
386
|
fit: (rect) => optsRef.current.fit(rect as T),
|
|
386
387
|
holdOverview: () =>
|
|
387
388
|
optsRef.current.artboards.length > 1 && !win.document.querySelector('[data-cd-link]'),
|
|
388
|
-
raf: (cb) => win
|
|
389
|
-
caf: (id) => win
|
|
389
|
+
raf: (cb) => frameRafOn(win, cb),
|
|
390
|
+
caf: (id) => frameCafOn(win, id),
|
|
390
391
|
now: () => (typeof performance !== 'undefined' ? performance.now() : Date.now()),
|
|
391
392
|
reducedMotion: () => reducedMotion(win),
|
|
392
393
|
durationMs: () => cssTokenMs(win),
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
//
|
|
3
3
|
// POST /_api/sync/resync → { ok, sync, resync? } · 409 busy · 200 { ok:false, reason } when there
|
|
4
4
|
// is nothing to restart · 403 { ok:false, reason, detail } at the gates
|
|
5
|
+
// GET /_api/sync/code-consent → { consent: CodeConsentView | null } (fix/207)
|
|
6
|
+
// POST /_api/sync/code-consent/set { allow } → { ok, consent } · 403 window-only / read-only ·
|
|
7
|
+
// 409 not-linked / not-signed-in / cell
|
|
8
|
+
// POST /_api/sync/held-deletes { answer: delete|keep, folder? } → { ok, how, count } · 403
|
|
9
|
+
// window-only / read-only / not-owner · 409 not-linked / nothing-held / busy
|
|
5
10
|
//
|
|
6
11
|
// MAIN ORIGIN ONLY (never `origin: 'canvas'`): resync re-handshakes every document against the
|
|
7
12
|
// person's own hub and re-runs a whole-project comparison — an amplification primitive a canvas must
|
|
@@ -21,6 +26,8 @@
|
|
|
21
26
|
|
|
22
27
|
import { currentAccess, notInScopeResponse } from '../access/request.ts';
|
|
23
28
|
import type { Access } from '../access/scope.ts';
|
|
29
|
+
import type { CodeConsentControl } from '../sync/code-module-consent.ts';
|
|
30
|
+
import type { HeldDeletesControl } from '../sync/held-deletes.ts';
|
|
24
31
|
import type { LinkGate } from '../sync/link-consent.ts';
|
|
25
32
|
import type { ResyncTrace } from '../sync/resync-trace.ts';
|
|
26
33
|
import type { RouteSpec } from './table.ts';
|
|
@@ -29,8 +36,21 @@ import type { RouteSpec } from './table.ts';
|
|
|
29
36
|
export interface SyncControlLike {
|
|
30
37
|
busy?(): boolean;
|
|
31
38
|
restart(): Promise<{ syncing: boolean; canvases?: number; reason?: string; detail?: string }>;
|
|
39
|
+
/** fix/207 — the running runtime: its shared-code consent and its "pass now". */
|
|
40
|
+
current?(): unknown;
|
|
32
41
|
}
|
|
33
42
|
|
|
43
|
+
/** fix/207 — the slice of the running runtime the consent routes use (sync/index.ts SyncRuntime). */
|
|
44
|
+
interface ConsentRuntime {
|
|
45
|
+
codeConsent?(): CodeConsentControl | null;
|
|
46
|
+
heldDeletes?(): HeldDeletesControl | null;
|
|
47
|
+
pullRemoteNow?(): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
const consentRuntime = (c: SyncControlLike | null | undefined): ConsentRuntime | null => {
|
|
50
|
+
const r = c?.current?.();
|
|
51
|
+
return r && typeof r === 'object' ? (r as ConsentRuntime) : null;
|
|
52
|
+
};
|
|
53
|
+
|
|
34
54
|
export interface SyncRouteDeps {
|
|
35
55
|
/** `ctx.syncControl` — a LIVE view: server.ts attaches it after the table is built. */
|
|
36
56
|
control: () => SyncControlLike | null | undefined;
|
|
@@ -138,6 +158,162 @@ export function createSyncRoutes(deps: SyncRouteDeps): RouteSpec[] {
|
|
|
138
158
|
return json(r.ok ? 200 : r.reason === 'nothing-pending' ? 409 : 500, r);
|
|
139
159
|
},
|
|
140
160
|
},
|
|
161
|
+
// fix/207 — may the linked hub deliver SHARED CODE (`.ts`/`.js` modules) to this Mac? The answer
|
|
162
|
+
// the consent sheet shows (Sync details' held row, the canvas-waiting card). MAIN ORIGIN ONLY: a
|
|
163
|
+
// canvas never learns whether code would reach this Mac. Names the host and the answer, nothing
|
|
164
|
+
// else (no token, no account).
|
|
165
|
+
{
|
|
166
|
+
method: 'GET',
|
|
167
|
+
path: '/_api/sync/code-consent',
|
|
168
|
+
origin: 'main',
|
|
169
|
+
readOnly: 'allowed',
|
|
170
|
+
handle: async () => {
|
|
171
|
+
if (!access().can('read', null)) return notInScopeResponse();
|
|
172
|
+
const consent = consentRuntime(deps.control())?.codeConsent?.() ?? null;
|
|
173
|
+
return json(200, { consent: consent ? consent.view() : null });
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
// fix/207 — the person's answer: "Allow shared code from <host>" / "Stop allowing shared code".
|
|
177
|
+
// Code modules land OUTSIDE the sandboxed canvas origin — the agent and every `maude design *`
|
|
178
|
+
// helper read them (DDR-054) — so this is the same class of act as Connect: the person's, in the
|
|
179
|
+
// Maude window. Gates, in order: the table's CSRF + DNS-rebind (`guardTableRoute`), then
|
|
180
|
+
// `Sec-Fetch-Site: same-origin` (window-only, routes/cloud-move.ts), then Can edit (a signed-in
|
|
181
|
+
// member of that hub; the role is this Mac's stored one), then a signed-in record for the hub
|
|
182
|
+
// the RUNTIME dials (never a body field). Never canvas-safe; refused in a cell (studio-manifest);
|
|
183
|
+
// the agent never reaches it (human 'consent'; cli/lib/bash-guard.mjs human-only).
|
|
184
|
+
{
|
|
185
|
+
method: 'POST',
|
|
186
|
+
path: '/_api/sync/code-consent/set',
|
|
187
|
+
origin: 'main',
|
|
188
|
+
readOnly: 'refused',
|
|
189
|
+
refuse: (reason) => {
|
|
190
|
+
(deps.warn ?? ((m: string) => console.warn(m)))(
|
|
191
|
+
`[sync] ${reason} request to the shared-code consent route — refused.`
|
|
192
|
+
);
|
|
193
|
+
return json(403, {
|
|
194
|
+
ok: false,
|
|
195
|
+
reason,
|
|
196
|
+
detail:
|
|
197
|
+
reason === 'cross-origin'
|
|
198
|
+
? 'Answer this from Maude itself, not from inside a canvas.'
|
|
199
|
+
: "Answer this from the Maude app or this machine's own browser tab.",
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
async handle(req) {
|
|
203
|
+
if (req.headers.get('sec-fetch-site') !== 'same-origin') {
|
|
204
|
+
return json(403, {
|
|
205
|
+
ok: false,
|
|
206
|
+
reason: 'window-only',
|
|
207
|
+
detail: 'Answer this in Sync details in the Maude window.',
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (!access().can('edit', null)) {
|
|
211
|
+
return json(403, {
|
|
212
|
+
error: 'read-only',
|
|
213
|
+
reason: 'not-allowed',
|
|
214
|
+
message: 'Ask the owner to change this.',
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
let body: unknown = null;
|
|
218
|
+
try {
|
|
219
|
+
body = await req.json();
|
|
220
|
+
} catch {
|
|
221
|
+
body = null;
|
|
222
|
+
}
|
|
223
|
+
const allow = (body as { allow?: unknown } | null)?.allow;
|
|
224
|
+
if (typeof allow !== 'boolean') {
|
|
225
|
+
return json(400, { ok: false, reason: 'bad-request', detail: 'Say yes or no.' });
|
|
226
|
+
}
|
|
227
|
+
const runtime = consentRuntime(deps.control());
|
|
228
|
+
const consent = runtime?.codeConsent?.() ?? null;
|
|
229
|
+
if (!consent) {
|
|
230
|
+
return json(409, {
|
|
231
|
+
ok: false,
|
|
232
|
+
reason: 'not-linked',
|
|
233
|
+
detail: 'This project isn’t syncing with a hub right now.',
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
const r = consent.set(allow);
|
|
237
|
+
if (!r.ok) {
|
|
238
|
+
return json(409, {
|
|
239
|
+
ok: false,
|
|
240
|
+
reason: r.reason,
|
|
241
|
+
detail:
|
|
242
|
+
r.reason === 'cell'
|
|
243
|
+
? 'Shared code is always allowed on the project’s own server.'
|
|
244
|
+
: 'Sign in to this project’s hub first.',
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
// Held rows are admitted on the very next pass — start it now rather than in 20 s.
|
|
248
|
+
if (r.changed && allow) void runtime?.pullRemoteNow?.().catch(() => {});
|
|
249
|
+
return json(200, { ok: true, consent: r.view });
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
// Issue #207 (7b) — the answer to "Deleted on this Mac, held": `{ answer: 'delete' | 'keep',
|
|
253
|
+
// folder? }`. Delete sends the held deletes as one confirmed batch (the hub's door, or the owner's
|
|
254
|
+
// confirmed purge past its budget — sync/held-deletes.ts); Keep leaves them on the hub. The same
|
|
255
|
+
// class of act as the shared-code answer: the person's, in the Maude window (window-only, Can edit;
|
|
256
|
+
// never canvas-safe; refused in a cell; human 'hub-link').
|
|
257
|
+
{
|
|
258
|
+
method: 'POST',
|
|
259
|
+
path: '/_api/sync/held-deletes',
|
|
260
|
+
origin: 'main',
|
|
261
|
+
readOnly: 'refused',
|
|
262
|
+
refuse: (reason) => {
|
|
263
|
+
(deps.warn ?? ((m: string) => console.warn(m)))(
|
|
264
|
+
`[sync] ${reason} request to the held-deletes route — refused.`
|
|
265
|
+
);
|
|
266
|
+
return json(403, {
|
|
267
|
+
ok: false,
|
|
268
|
+
reason,
|
|
269
|
+
detail:
|
|
270
|
+
reason === 'cross-origin'
|
|
271
|
+
? 'Answer this from Maude itself, not from inside a canvas.'
|
|
272
|
+
: "Answer this from the Maude app or this machine's own browser tab.",
|
|
273
|
+
});
|
|
274
|
+
},
|
|
275
|
+
async handle(req) {
|
|
276
|
+
if (req.headers.get('sec-fetch-site') !== 'same-origin') {
|
|
277
|
+
return json(403, {
|
|
278
|
+
ok: false,
|
|
279
|
+
reason: 'window-only',
|
|
280
|
+
detail: 'Answer this in Sync details in the Maude window.',
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
if (!access().can('edit', null)) {
|
|
284
|
+
return json(403, {
|
|
285
|
+
error: 'read-only',
|
|
286
|
+
reason: 'not-allowed',
|
|
287
|
+
message: 'Ask the owner to change this.',
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
let body: unknown = null;
|
|
291
|
+
try {
|
|
292
|
+
body = await req.json();
|
|
293
|
+
} catch {
|
|
294
|
+
body = null;
|
|
295
|
+
}
|
|
296
|
+
const answer = (body as { answer?: unknown } | null)?.answer;
|
|
297
|
+
const folder = (body as { folder?: unknown } | null)?.folder ?? null;
|
|
298
|
+
if (
|
|
299
|
+
(answer !== 'delete' && answer !== 'keep') ||
|
|
300
|
+
(folder !== null && (typeof folder !== 'string' || folder.length > 1024))
|
|
301
|
+
) {
|
|
302
|
+
return json(400, { ok: false, reason: 'bad-request', detail: 'Say delete or keep.' });
|
|
303
|
+
}
|
|
304
|
+
const control = consentRuntime(deps.control())?.heldDeletes?.() ?? null;
|
|
305
|
+
if (!control) {
|
|
306
|
+
return json(409, {
|
|
307
|
+
ok: false,
|
|
308
|
+
reason: 'not-linked',
|
|
309
|
+
detail: 'This project isn’t syncing with a hub right now.',
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
const r = await control.answer(answer, folder as string | null);
|
|
313
|
+
if (r.ok) return json(200, r);
|
|
314
|
+
return json(r.reason === 'not-owner' ? 403 : 409, r);
|
|
315
|
+
},
|
|
316
|
+
},
|
|
141
317
|
{
|
|
142
318
|
method: 'POST',
|
|
143
319
|
path: '/_api/sync/resync',
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
import { type ReactNode, useEffect, useMemo, useState } from 'react';
|
|
22
|
+
import { frameCaf, frameRaf } from './frame-clock.ts';
|
|
22
23
|
|
|
23
24
|
import {
|
|
24
25
|
type BandRect,
|
|
@@ -156,7 +157,7 @@ function useUnderFlags(artboardId: string | undefined, bands: BandRect[], w: num
|
|
|
156
157
|
);
|
|
157
158
|
};
|
|
158
159
|
const schedule = () => {
|
|
159
|
-
if (!frame) frame =
|
|
160
|
+
if (!frame) frame = frameRaf(run);
|
|
160
161
|
};
|
|
161
162
|
schedule();
|
|
162
163
|
const body = document.querySelector(`[data-dc-screen="${escapeId(artboardId)}"]`);
|
|
@@ -166,7 +167,7 @@ function useUnderFlags(artboardId: string | undefined, bands: BandRect[], w: num
|
|
|
166
167
|
mo.observe(body, { subtree: true, childList: true, characterData: true, attributes: true });
|
|
167
168
|
}
|
|
168
169
|
return () => {
|
|
169
|
-
if (frame)
|
|
170
|
+
if (frame) frameCaf(frame);
|
|
170
171
|
mo?.disconnect();
|
|
171
172
|
};
|
|
172
173
|
}, [artboardId, bands, w]);
|
package/apps/studio/skip-dirs.ts
CHANGED
|
@@ -79,44 +79,92 @@ export function isCanvasRelInGroups(
|
|
|
79
79
|
return isInCanvasGroup(groups, rel) && !isComponentRel(rel, componentDir);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
// 2.0.7 (#207) — the scan writes into a UTF-16 buffer and every look-back reads that buffer, so a
|
|
83
|
+
// scan is linear in the source. It used to grow a string with `+=` and test the whole string at
|
|
84
|
+
// every literal (a `$`-anchored regex, `out[k]` on a rope): quadratic, ~3 s for one 1 MB canvas, and
|
|
85
|
+
// `/_index-data` ran it for every file every canvas reaches. Same output, character for character
|
|
86
|
+
// (pinned against the old implementation in test/import-scan-linear.test.ts).
|
|
87
|
+
const WS_RE = /\s/;
|
|
88
|
+
/** `/\s/` on one UTF-16 code unit (`undefined` = before the start). */
|
|
89
|
+
function isWs(c: number | undefined): boolean {
|
|
90
|
+
if (c === undefined) return false;
|
|
91
|
+
if (c < 128) return c === 32 || (c >= 9 && c <= 13);
|
|
92
|
+
return WS_RE.test(String.fromCharCode(c));
|
|
93
|
+
}
|
|
94
|
+
/** `/[\w$]/` on one UTF-16 code unit. */
|
|
95
|
+
function isIdent(c: number | undefined): boolean {
|
|
96
|
+
if (c === undefined) return false;
|
|
97
|
+
return (
|
|
98
|
+
(c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c === 95 || c === 36
|
|
99
|
+
);
|
|
100
|
+
}
|
|
84
101
|
|
|
85
|
-
/** `
|
|
86
|
-
function wordEndsAt(
|
|
87
|
-
if (k < w.length
|
|
88
|
-
|
|
102
|
+
/** `buf[..k)` ends in the whole word `w`; `ci` compares ASCII letters case-insensitively. */
|
|
103
|
+
function wordEndsAt(buf: Uint16Array, k: number, w: string, ci = false): boolean {
|
|
104
|
+
if (k < w.length) return false;
|
|
105
|
+
const at = k - w.length;
|
|
106
|
+
for (let t = 0; t < w.length; t++) {
|
|
107
|
+
let c = buf[at + t] as number;
|
|
108
|
+
if (ci && c >= 65 && c <= 90) c += 32;
|
|
109
|
+
if (c !== w.charCodeAt(t)) return false;
|
|
110
|
+
}
|
|
111
|
+
return !isIdent(at > 0 ? buf[at - 1] : undefined);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Skip whitespace backwards from `k` (exclusive) in `buf`. */
|
|
115
|
+
function skipWsBack(buf: Uint16Array, k: number): number {
|
|
116
|
+
while (k > 0 && isWs(buf[k - 1])) k--;
|
|
117
|
+
return k;
|
|
89
118
|
}
|
|
90
119
|
|
|
91
120
|
/**
|
|
92
|
-
* gate-b-c4l — does the text written so far end in a module-specifier lead: `from`,
|
|
93
|
-
* `import(` or `require(`, with ANY whitespace between (a comment is already blanked to
|
|
94
|
-
* there, whatever its length)? c4e looked back a fixed 32 characters, and a longer comment
|
|
95
|
-
* `from` and the string hid the import.
|
|
121
|
+
* gate-b-c4l — does the text written so far (`buf[..len)`) end in a module-specifier lead: `from`,
|
|
122
|
+
* `import`, `import(` or `require(`, with ANY whitespace between (a comment is already blanked to
|
|
123
|
+
* spaces there, whatever its length)? c4e looked back a fixed 32 characters, and a longer comment
|
|
124
|
+
* between `from` and the string hid the import.
|
|
96
125
|
*/
|
|
97
|
-
function endsInSpecifierLead(
|
|
98
|
-
let k =
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
k
|
|
102
|
-
while (k > 0 && isWs(out[k - 1])) k--;
|
|
103
|
-
return wordEndsAt(out, k, 'import') || wordEndsAt(out, k, 'require');
|
|
126
|
+
function endsInSpecifierLead(buf: Uint16Array, len: number): boolean {
|
|
127
|
+
let k = skipWsBack(buf, len);
|
|
128
|
+
if (k > 0 && buf[k - 1] === 40 /* ( */) {
|
|
129
|
+
k = skipWsBack(buf, k - 1);
|
|
130
|
+
return wordEndsAt(buf, k, 'import') || wordEndsAt(buf, k, 'require');
|
|
104
131
|
}
|
|
105
|
-
return wordEndsAt(
|
|
132
|
+
return wordEndsAt(buf, k, 'from') || wordEndsAt(buf, k, 'import');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Does `buf[..len)` end in `import(` / `require(` (whitespace allowed)? */
|
|
136
|
+
function endsInCallLead(buf: Uint16Array, len: number): boolean {
|
|
137
|
+
let k = skipWsBack(buf, len);
|
|
138
|
+
if (k === 0 || buf[k - 1] !== 40 /* ( */) return false;
|
|
139
|
+
k = skipWsBack(buf, k - 1);
|
|
140
|
+
return wordEndsAt(buf, k, 'import') || wordEndsAt(buf, k, 'require');
|
|
106
141
|
}
|
|
107
142
|
|
|
108
|
-
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
143
|
+
/**
|
|
144
|
+
* CSS: does `buf[..len)` end in the lead of `@import url("./x.css")` — `/@import\s+url\(\s*$/i`
|
|
145
|
+
* (ASCII case-insensitive: without the `u` flag a non-ASCII letter never folds to an ASCII one)?
|
|
146
|
+
*/
|
|
147
|
+
function endsInCssImportUrlLead(buf: Uint16Array, len: number): boolean {
|
|
148
|
+
let k = skipWsBack(buf, len);
|
|
149
|
+
if (k === 0 || buf[k - 1] !== 40 /* ( */) return false;
|
|
113
150
|
k--;
|
|
114
|
-
|
|
115
|
-
|
|
151
|
+
// `url` right before `(`; the `\s+` before it keeps the word check below honest
|
|
152
|
+
if (!wordEndsAt(buf, k, 'url', true)) return false;
|
|
153
|
+
k -= 3;
|
|
154
|
+
const before = k;
|
|
155
|
+
k = skipWsBack(buf, k);
|
|
156
|
+
if (k === before) return false; // `\s+`
|
|
157
|
+
return wordEndsAt(buf, k, 'import', true) && k >= 7 && buf[k - 7] === 64; /* @ */
|
|
116
158
|
}
|
|
117
159
|
|
|
118
|
-
/**
|
|
119
|
-
|
|
160
|
+
/** `buf[..len)` as a string, in chunks (`fromCharCode.apply` caps its argument count). */
|
|
161
|
+
function bufText(buf: Uint16Array, len: number): string {
|
|
162
|
+
const CHUNK = 8192;
|
|
163
|
+
const parts: string[] = [];
|
|
164
|
+
for (let a = 0; a < len; a += CHUNK)
|
|
165
|
+
parts.push(String.fromCharCode.apply(null, buf.subarray(a, Math.min(len, a + CHUNK)) as never));
|
|
166
|
+
return parts.join('');
|
|
167
|
+
}
|
|
120
168
|
|
|
121
169
|
/**
|
|
122
170
|
* gate-b-c4e — `source` as the import scanner may read it: comments blanked and every string
|
|
@@ -130,54 +178,62 @@ const CSS_IMPORT_URL_LEAD_RE = /@import\s+url\(\s*$/i;
|
|
|
130
178
|
* spaces, newlines kept), so an offset in the result is an offset in `source`.
|
|
131
179
|
*/
|
|
132
180
|
export function importScanText(source: string, css = false): string {
|
|
133
|
-
let out = '';
|
|
134
|
-
let i = 0;
|
|
135
181
|
const n = source.length;
|
|
182
|
+
const buf = new Uint16Array(n);
|
|
183
|
+
let len = 0;
|
|
184
|
+
/** blank `source[a..b)` into the buffer: every code unit but `\n` becomes a space */
|
|
185
|
+
const blank = (a: number, b: number) => {
|
|
186
|
+
for (let k = a; k < b; k++) buf[len++] = source.charCodeAt(k) === 10 ? 10 : 32;
|
|
187
|
+
};
|
|
188
|
+
let i = 0;
|
|
136
189
|
while (i < n) {
|
|
137
|
-
const c = source
|
|
138
|
-
const next = source
|
|
139
|
-
if (c ===
|
|
190
|
+
const c = source.charCodeAt(i);
|
|
191
|
+
const next = i + 1 < n ? source.charCodeAt(i + 1) : -1;
|
|
192
|
+
if (c === 47 /* / */ && next === 42 /* * */) {
|
|
140
193
|
const end = source.indexOf('*/', i + 2);
|
|
141
194
|
const stop = end === -1 ? n : end + 2;
|
|
142
|
-
|
|
195
|
+
blank(i, stop);
|
|
143
196
|
i = stop;
|
|
144
197
|
continue;
|
|
145
198
|
}
|
|
146
|
-
if (!css && c ===
|
|
199
|
+
if (!css && c === 47 && next === 47) {
|
|
147
200
|
const end = source.indexOf('\n', i);
|
|
148
201
|
const stop = end === -1 ? n : end;
|
|
149
|
-
|
|
202
|
+
for (let k = i; k < stop; k++) buf[len++] = 32;
|
|
150
203
|
i = stop;
|
|
151
204
|
continue;
|
|
152
205
|
}
|
|
153
|
-
if (c ===
|
|
206
|
+
if (c === 34 /* " */ || c === 39 /* ' */ || (!css && c === 96) /* ` */) {
|
|
154
207
|
let j = i + 1;
|
|
155
208
|
while (j < n) {
|
|
156
|
-
const d = source
|
|
157
|
-
if (d ===
|
|
209
|
+
const d = source.charCodeAt(j);
|
|
210
|
+
if (d === 92 /* \ */) {
|
|
158
211
|
j += 2;
|
|
159
212
|
continue;
|
|
160
213
|
}
|
|
161
214
|
if (d === c) break;
|
|
162
|
-
if (d ===
|
|
215
|
+
if (d === 10 && c !== 96) break; // an unterminated string ends with its line
|
|
163
216
|
j++;
|
|
164
217
|
}
|
|
165
218
|
const stop = Math.min(j, n);
|
|
166
|
-
const
|
|
219
|
+
const closed = j < n && source.charCodeAt(j) === c;
|
|
167
220
|
// gate-b-c4m (defender L-B) — a template with no substitution after `import(` / `require(`
|
|
168
221
|
// is a module specifier Bun resolves at build time; in CSS, the string of `@import url("…")`.
|
|
169
222
|
const keep =
|
|
170
|
-
c ===
|
|
171
|
-
? !
|
|
172
|
-
: endsInSpecifierLead(
|
|
173
|
-
|
|
174
|
-
|
|
223
|
+
c === 96
|
|
224
|
+
? !source.slice(i + 1, stop).includes('${') && endsInCallLead(buf, len)
|
|
225
|
+
: endsInSpecifierLead(buf, len) || (css && endsInCssImportUrlLead(buf, len));
|
|
226
|
+
buf[len++] = c;
|
|
227
|
+
if (keep) for (let k = i + 1; k < stop; k++) buf[len++] = source.charCodeAt(k);
|
|
228
|
+
else blank(i + 1, stop);
|
|
229
|
+
if (closed) buf[len++] = c;
|
|
230
|
+
i = closed ? j + 1 : stop;
|
|
175
231
|
continue;
|
|
176
232
|
}
|
|
177
|
-
|
|
233
|
+
buf[len++] = c;
|
|
178
234
|
i++;
|
|
179
235
|
}
|
|
180
|
-
return
|
|
236
|
+
return bufText(buf, len);
|
|
181
237
|
}
|
|
182
238
|
|
|
183
239
|
/**
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// 2.0.7 — the studio page and its canvas frames must be on ONE site.
|
|
2
|
+
//
|
|
3
|
+
// Each canvas frame proves which canvas it was opened for with its `fc` capability (gate-b-c4,
|
|
4
|
+
// access/frame.ts). The shell puts `fc` on the frame's own URL; everything the canvas loads by
|
|
5
|
+
// itself (an `<img>`, a CSS `url()`, a font) carries it only in the Referer. WebKit — Safari and
|
|
6
|
+
// Playwright's WebKit — cuts the Referer of EVERY request a frame makes down to the bare origin when
|
|
7
|
+
// that frame is on another site than the top page, whatever Referrer-Policy the page sets. So with
|
|
8
|
+
// the studio on `127.0.0.1:<port>` and the canvas origin on `localhost:<port>` (two sites), every
|
|
9
|
+
// picture lost its capability and got the frame-less answer (403): "Picture not found".
|
|
10
|
+
//
|
|
11
|
+
// The desktop app, `maude design browse` and every printed address use `localhost`, the same site
|
|
12
|
+
// as the canvas origin, so they never hit this; a cell and a self-hosted workspace must already put
|
|
13
|
+
// the canvas domain on the studio's site (its session cookie needs it). What is left is a person
|
|
14
|
+
// (or a harness) typing `127.0.0.1` or `[::1]`. Their browser's own top-level navigation to the
|
|
15
|
+
// studio page is sent to the same port on `localhost`, where the frames are same-site again.
|
|
16
|
+
//
|
|
17
|
+
// Rejected: a Referrer-Policy (WebKit ignores it here, measured); a cookie (blocked in a
|
|
18
|
+
// third-party frame); `fc` in a path prefix (absolute asset paths drop it); answering frame-less
|
|
19
|
+
// media (widens C4). The capability check itself is unchanged.
|
|
20
|
+
|
|
21
|
+
/** A browser's own top-level navigation: Fetch Metadata says `navigate` + `document`. */
|
|
22
|
+
function isTopLevelNavigation(req: Request): boolean {
|
|
23
|
+
return (
|
|
24
|
+
req.method === 'GET' &&
|
|
25
|
+
req.headers.get('sec-fetch-mode') === 'navigate' &&
|
|
26
|
+
req.headers.get('sec-fetch-dest') === 'document'
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface StudioPageHostOpts {
|
|
31
|
+
/** `ctx.canvasOrigin` — the interactive canvas origin, when the split is on. */
|
|
32
|
+
canvasOrigin?: string;
|
|
33
|
+
/** `ctx.mainOrigin` — the space-separated origins this studio page is served on. */
|
|
34
|
+
mainOrigin?: string;
|
|
35
|
+
/** A cell / workspace: public names come from configuration, never rewritten here. */
|
|
36
|
+
workspace: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A 307 to the same port on `localhost` for a browser's top-level navigation to the studio page
|
|
41
|
+
* on a loopback IP literal, when the canvas frames live on `localhost`; otherwise null (serve the
|
|
42
|
+
* page). The port must be the one this studio is bound on (`mainOrigin`), so the redirect never
|
|
43
|
+
* names a listener that is not ours, and the target host is fixed — nothing from the request but
|
|
44
|
+
* the port (checked), the path and the query is carried over.
|
|
45
|
+
*/
|
|
46
|
+
export function studioPageHostRedirect(req: Request, opts: StudioPageHostOpts): Response | null {
|
|
47
|
+
if (opts.workspace || !opts.canvasOrigin || !opts.mainOrigin) return null;
|
|
48
|
+
if (!isTopLevelNavigation(req)) return null;
|
|
49
|
+
let canvasHost: string;
|
|
50
|
+
let url: URL;
|
|
51
|
+
try {
|
|
52
|
+
canvasHost = new URL(opts.canvasOrigin).hostname;
|
|
53
|
+
url = new URL(req.url);
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
if (canvasHost !== 'localhost') return null;
|
|
58
|
+
if (url.protocol !== 'http:') return null;
|
|
59
|
+
if (url.hostname !== '127.0.0.1' && url.hostname !== '[::1]') return null;
|
|
60
|
+
// The port this studio is bound on: `mainOrigin` lists it on BOTH loopback names (server.ts);
|
|
61
|
+
// an extra shell origin naming only `localhost:<other>` never qualifies.
|
|
62
|
+
const target = `http://localhost:${url.port}`;
|
|
63
|
+
const ours = opts.mainOrigin.split(/\s+/);
|
|
64
|
+
if (!url.port || !ours.includes(target) || !ours.includes(`http://127.0.0.1:${url.port}`))
|
|
65
|
+
return null;
|
|
66
|
+
return new Response(null, {
|
|
67
|
+
status: 307,
|
|
68
|
+
headers: { Location: `${target}${url.pathname}${url.search}`, 'Cache-Control': 'no-store' },
|
|
69
|
+
});
|
|
70
|
+
}
|