@1agh/maude 1.7.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/apps/studio/acp/bridge.ts +15 -2
  2. package/apps/studio/acp/login-state.ts +1 -0
  3. package/apps/studio/acp/probe.ts +52 -1
  4. package/apps/studio/api.ts +431 -39
  5. package/apps/studio/asset-upload.ts +174 -0
  6. package/apps/studio/assets-s3.ts +37 -2
  7. package/apps/studio/bin/_curl-local.mjs +7 -0
  8. package/apps/studio/bin/_pdf-playwright.mjs +22 -1
  9. package/apps/studio/bin/_png-playwright.mjs +20 -1
  10. package/apps/studio/bin/_region.mjs +92 -0
  11. package/apps/studio/bin/annotate.mjs +16 -7
  12. package/apps/studio/bin/read-annotations.mjs +62 -4
  13. package/apps/studio/canvas-build.ts +59 -4
  14. package/apps/studio/canvas-lib.tsx +48 -1
  15. package/apps/studio/canvas-shell.tsx +28 -4
  16. package/apps/studio/client/app.jsx +441 -15903
  17. package/apps/studio/client/canvas-url.js +9 -0
  18. package/apps/studio/client/dialogs/asset-picker.jsx +331 -0
  19. package/apps/studio/client/dialogs/command-palette.jsx +112 -0
  20. package/apps/studio/client/dialogs/export-dialog.jsx +782 -0
  21. package/apps/studio/client/dialogs/help-modal.jsx +324 -0
  22. package/apps/studio/client/dialogs/shortcuts-overlay.jsx +144 -0
  23. package/apps/studio/client/embed-view.jsx +284 -0
  24. package/apps/studio/client/embed.js +101 -0
  25. package/apps/studio/client/export-center.jsx +2 -0
  26. package/apps/studio/client/github.js +36 -3
  27. package/apps/studio/client/hooks/use-canvas-bridge.jsx +2150 -0
  28. package/apps/studio/client/hooks/use-git-actions.jsx +236 -0
  29. package/apps/studio/client/hooks/use-keyboard-shortcuts.jsx +297 -0
  30. package/apps/studio/client/hooks/use-palette-and-panels.jsx +474 -0
  31. package/apps/studio/client/hooks/use-photo-and-timeline.jsx +901 -0
  32. package/apps/studio/client/hooks/use-project-data.jsx +90 -0
  33. package/apps/studio/client/hooks/use-shell-core.jsx +1212 -0
  34. package/apps/studio/client/hooks/use-tabs.jsx +723 -0
  35. package/apps/studio/client/hooks/use-web-socket.jsx +13 -0
  36. package/apps/studio/client/inspector/artboard-knobs.jsx +456 -0
  37. package/apps/studio/client/inspector/color-picker.jsx +196 -0
  38. package/apps/studio/client/inspector/color.js +92 -0
  39. package/apps/studio/client/inspector/css-knobs.jsx +1720 -0
  40. package/apps/studio/client/inspector/css-vocab.jsx +131 -0
  41. package/apps/studio/client/inspector/ds-tokens.js +90 -0
  42. package/apps/studio/client/inspector/grid-tracks-editor.jsx +97 -0
  43. package/apps/studio/client/inspector/inspect-computed.jsx +68 -0
  44. package/apps/studio/client/inspector/inspector-panel.jsx +769 -0
  45. package/apps/studio/client/inspector/layers.jsx +322 -0
  46. package/apps/studio/client/inspector/selection.js +65 -0
  47. package/apps/studio/client/inspector/token-popover.jsx +301 -0
  48. package/apps/studio/client/menus/menubar.jsx +856 -0
  49. package/apps/studio/client/report-bug.jsx +8 -2
  50. package/apps/studio/client/selection-scope.js +40 -0
  51. package/apps/studio/client/shell/banners.jsx +272 -0
  52. package/apps/studio/client/shell/collapsed-rail.jsx +23 -0
  53. package/apps/studio/client/shell/comments-panel.jsx +177 -0
  54. package/apps/studio/client/shell/constants.js +60 -0
  55. package/apps/studio/client/shell/dock.jsx +131 -0
  56. package/apps/studio/client/shell/icons.jsx +370 -0
  57. package/apps/studio/client/shell/status-bar.jsx +215 -0
  58. package/apps/studio/client/shell/util.js +332 -0
  59. package/apps/studio/client/shell/viewport.jsx +254 -0
  60. package/apps/studio/client/system/system-view.jsx +255 -0
  61. package/apps/studio/client/tree/tree.jsx +1243 -0
  62. package/apps/studio/comments-overlay.tsx +6 -4
  63. package/apps/studio/config.schema.json +5 -0
  64. package/apps/studio/context.ts +20 -0
  65. package/apps/studio/dist/client.bundle.js +2728 -2728
  66. package/apps/studio/dist/comment-mount.js +2 -2
  67. package/apps/studio/embed-origins.ts +52 -0
  68. package/apps/studio/export-dialog.tsx +55 -3
  69. package/apps/studio/exporters/_browser-bundles.ts +21 -2
  70. package/apps/studio/exporters/format-scopes.ts +11 -3
  71. package/apps/studio/exporters/index.ts +17 -2
  72. package/apps/studio/exporters/jobs.ts +91 -23
  73. package/apps/studio/exporters/pdf.ts +10 -2
  74. package/apps/studio/exporters/png.ts +10 -2
  75. package/apps/studio/exporters/scope.ts +89 -15
  76. package/apps/studio/format.ts +296 -0
  77. package/apps/studio/generation/runtime-probe.ts +1 -1
  78. package/apps/studio/git/service.ts +1 -0
  79. package/apps/studio/http.ts +399 -36
  80. package/apps/studio/input-router.tsx +7 -1
  81. package/apps/studio/path-containment.ts +72 -0
  82. package/apps/studio/paths.ts +14 -1
  83. package/apps/studio/read-only-mode.ts +53 -0
  84. package/apps/studio/server.ts +123 -25
  85. package/apps/studio/sync/accepted-link.ts +6 -0
  86. package/apps/studio/sync/agent.ts +9 -1
  87. package/apps/studio/sync/cold-start-apply.ts +29 -4
  88. package/apps/studio/sync/cold-start.ts +78 -0
  89. package/apps/studio/sync/file-plane.ts +61 -1
  90. package/apps/studio/sync/format-sync.ts +160 -0
  91. package/apps/studio/sync/index.ts +208 -23
  92. package/apps/studio/sync/journal-client.ts +25 -5
  93. package/apps/studio/sync/migrate-seed.ts +8 -1
  94. package/apps/studio/sync/park.ts +39 -0
  95. package/apps/studio/sync/presentation.ts +9 -3
  96. package/apps/studio/sync/status.ts +2 -0
  97. package/apps/studio/sync/transaction-client.ts +130 -13
  98. package/apps/studio/sync/writer-registry.ts +5 -0
  99. package/apps/studio/ui-prefs.ts +95 -10
  100. package/apps/studio/use-canvas-media-drop.tsx +8 -28
  101. package/apps/studio/whats-new.json +36 -0
  102. package/apps/studio/ws.ts +19 -4
  103. package/cli/bin/claude-design-server.mjs +0 -0
  104. package/cli/commands/design.mjs +9 -2
  105. package/cli/commands/hub-workspace.mjs +25 -0
  106. package/cli/lib/workspace-plan.mjs +51 -0
  107. package/package.json +11 -9
  108. package/plugins/design/templates/_shell.html +58 -0
@@ -0,0 +1,284 @@
1
+ // DDR-247 — the chromeless, read-only `?embed=1&open=<rel>[&artboard=<id>]`
2
+ // view another app frames (orbit showing a design next to a task).
3
+ //
4
+ // A SEPARATE ROOT, not a mode of <App>. The studio shell persists view prefs,
5
+ // rewrites the address bar, mounts panels, chat and export — every one of which
6
+ // an embed must not do. Rendering this instead of <App> means none of it runs,
7
+ // rather than each of it remembering to check a flag. What IS shared is the
8
+ // canvas: the same `canvasUrl()` and the same in-canvas Presentation Mode
9
+ // (`view-chrome` `present`), with `ro=1` + `comments=0` + `embed=1` on the URL.
10
+ //
11
+ // It speaks the one-way contract in `embed.js` to the parent and accepts
12
+ // nothing from it.
13
+ import { useEffect, useRef, useState } from 'react';
14
+
15
+ import { canvasTokenRefreshDelay, canvasUrl, setLiveCanvasToken } from './canvas-url.js';
16
+ import { postToEmbedder, readEmbedParams } from './embed.js';
17
+ import { normalizeOpenPath } from './share-link.js';
18
+
19
+ const CANVAS_EXT_RE = /\.(tsx|html?)$/i;
20
+ // DDR-247 — every config read this view makes says it is the embed, so a hub
21
+ // mints it a read-only canvas capability (the canvas door then refuses writes).
22
+ const EMBED_CONFIG_URL = '/_config?embed=1';
23
+ // Same order of magnitude as the studio's own compile cap (issue #115): past
24
+ // this the canvas is not coming, and the embedder deserves an answer.
25
+ const LOAD_TIMEOUT_MS = 20_000;
26
+ // `dgn:'loaded'` fires from the inline inspector script BEFORE the React canvas
27
+ // shell mounts its listener (app.jsx says the same), so the view is seeded on a
28
+ // short ladder rather than once. Every message on it is idempotent.
29
+ const SEED_LADDER_MS = [0, 150, 500, 1200, 2500];
30
+
31
+ const ROOT_STYLE = { position: 'fixed', inset: 0, overflow: 'hidden', background: 'var(--u-bg-0)' };
32
+ const FRAME_STYLE = { width: '100%', height: '100%', border: 0, display: 'block' };
33
+ const NOTE_STYLE = {
34
+ position: 'absolute',
35
+ inset: 0,
36
+ display: 'grid',
37
+ placeItems: 'center',
38
+ padding: 24,
39
+ textAlign: 'center',
40
+ color: 'var(--u-fg-2)',
41
+ };
42
+
43
+ function originOf(value) {
44
+ try {
45
+ return new URL(value, location.href).origin;
46
+ } catch {
47
+ return null;
48
+ }
49
+ }
50
+
51
+ async function readJson(url) {
52
+ const r = await fetch(url, { cache: 'no-store', credentials: 'same-origin' });
53
+ if (!r.ok) throw Object.assign(new Error(`${url} → ${r.status}`), { status: r.status });
54
+ return r.json();
55
+ }
56
+
57
+ export default function EmbedView() {
58
+ // loading | canvas | missing | signed-out
59
+ const [view, setView] = useState({ phase: 'loading' });
60
+ const frameRef = useRef(null);
61
+ // The allowlist and the echo travel in refs: posting must never wait on a render.
62
+ const allowRef = useRef([]);
63
+ const openRef = useRef('');
64
+ const post = (type, title) => postToEmbedder(window, allowRef.current, type, openRef.current, title);
65
+
66
+ // Follow the OS theme for the little chrome there is. Never persisted.
67
+ useEffect(() => {
68
+ const mq = window.matchMedia?.('(prefers-color-scheme: light)');
69
+ document.documentElement.dataset.theme = mq?.matches ? 'light' : 'dark';
70
+ }, []);
71
+
72
+ // Escape pressed on this page itself (focus outside the canvas frame) goes
73
+ // to the embedder too, when nothing here consumed it. This view never moves
74
+ // focus on its own — keys only arrive here after the person clicked in.
75
+ useEffect(() => {
76
+ const onKey = (e) => {
77
+ if (e.key !== 'Escape' || e.isComposing) return;
78
+ setTimeout(() => {
79
+ if (!e.defaultPrevented) post('escape');
80
+ }, 0);
81
+ };
82
+ window.addEventListener('keydown', onKey);
83
+ return () => window.removeEventListener('keydown', onKey);
84
+ }, []);
85
+
86
+ // Boot: config → resolve the identity against the project index → frame it.
87
+ useEffect(() => {
88
+ let cancelled = false;
89
+ const miss = () => {
90
+ if (cancelled) return;
91
+ setView({ phase: 'missing' });
92
+ post('not-found');
93
+ };
94
+ (async () => {
95
+ let data;
96
+ try {
97
+ // `embed=1` asks the hub for a READ-ONLY canvas capability (DDR-247).
98
+ data = await readJson(EMBED_CONFIG_URL);
99
+ } catch (err) {
100
+ if (cancelled) return;
101
+ // The session ended between the hub letting the page through and this
102
+ // fetch — the hub answers an API call 401 rather than redirecting it.
103
+ if (err?.status === 401) {
104
+ setView({ phase: 'signed-out' });
105
+ post('auth-required');
106
+ } else miss();
107
+ return;
108
+ }
109
+ const designRel = (data.designRoot || '.design').replace(/^\/+|\/+$/g, '');
110
+ allowRef.current = Array.isArray(data.embedOrigins) ? data.embedOrigins : [];
111
+ const params = readEmbedParams(location, designRel);
112
+ openRef.current = params.open ?? params.requested;
113
+ if (!params.open) return miss();
114
+ let index;
115
+ try {
116
+ index = await readJson('/_index-data');
117
+ } catch {
118
+ return miss();
119
+ }
120
+ const path = (index.groups ?? [])
121
+ .flatMap((g) => g.paths || [])
122
+ .find((p) => normalizeOpenPath(p, designRel) === params.open);
123
+ if (!path || !CANVAS_EXT_RE.test(path)) return miss();
124
+ let title = null;
125
+ try {
126
+ const meta = await readJson(`/_api/canvas-meta?file=${encodeURIComponent(path)}`);
127
+ if (typeof meta?.title === 'string' && meta.title.trim()) title = meta.title.trim().slice(0, 200);
128
+ } catch {
129
+ /* a canvas without a sidecar still renders — it just has no title */
130
+ }
131
+ if (cancelled) return;
132
+ const cfg = {
133
+ designRel,
134
+ tokensCssRel: data.tokensCssRel,
135
+ designSystems: data.designSystems,
136
+ canvasOrigin: data.canvasOrigin,
137
+ canvasToken: data.canvasToken,
138
+ canvasDesignSystems: index.canvasDesignSystems ?? {},
139
+ };
140
+ setView({
141
+ phase: 'canvas',
142
+ path,
143
+ title,
144
+ artboard: params.artboard,
145
+ cfg,
146
+ src: canvasUrl(path, cfg, { embed: true }),
147
+ });
148
+ })();
149
+ return () => {
150
+ cancelled = true;
151
+ };
152
+ }, []);
153
+
154
+ // While the canvas is up: announce `ready` once, seed the view on every
155
+ // (re)load, and give up with `not-found` if it never loads. Keyed on the
156
+ // canvas identity; `post` reads refs only.
157
+ useEffect(() => {
158
+ if (view.phase !== 'canvas') return undefined;
159
+ const canvasOrigin = view.cfg.canvasOrigin ? originOf(view.cfg.canvasOrigin) : location.origin;
160
+ const timers = [];
161
+ let ready = false;
162
+ let giveUp = null;
163
+ const seed = () => {
164
+ const win = frameRef.current?.contentWindow;
165
+ if (!win || !canvasOrigin) return;
166
+ const theme = document.documentElement.dataset.theme === 'light' ? 'light' : 'dark';
167
+ const messages = [
168
+ { dgn: 'comments-set', comments: [] },
169
+ { dgn: 'theme', theme },
170
+ { dgn: 'view-chrome', minimap: false, zoom: false, present: true },
171
+ view.artboard ? { dgn: 'zoom', op: 'artboard', id: view.artboard } : { dgn: 'zoom', op: 'fit' },
172
+ ];
173
+ for (const m of messages) {
174
+ try {
175
+ win.postMessage(m, canvasOrigin);
176
+ } catch {
177
+ /* frame navigated away — the next load re-seeds */
178
+ }
179
+ }
180
+ };
181
+ const loaded = () => {
182
+ if (!ready) {
183
+ ready = true;
184
+ clearTimeout(giveUp);
185
+ post('ready', view.title ?? undefined);
186
+ }
187
+ for (const ms of SEED_LADDER_MS) timers.push(setTimeout(seed, ms));
188
+ };
189
+ giveUp = setTimeout(() => {
190
+ if (ready) return;
191
+ setView({ phase: 'missing' });
192
+ post('not-found');
193
+ }, LOAD_TIMEOUT_MS);
194
+ function onMessage(e) {
195
+ // Only the frame we built, from the origin we built it on.
196
+ if (e.origin !== canvasOrigin || e.source !== frameRef.current?.contentWindow) return;
197
+ if (!e.data || typeof e.data !== 'object') return;
198
+ if (e.data.dgn === 'loaded') loaded();
199
+ // An Escape the canvas did not consume (read-only-mode.ts) belongs to
200
+ // the app around the embed — its dialog must still close.
201
+ else if (e.data.dgn === 'embed-escape') post('escape');
202
+ }
203
+ window.addEventListener('message', onMessage);
204
+ // A legacy `.html` canvas never posts `loaded`; its frame load is the signal.
205
+ const frame = frameRef.current;
206
+ const onFrameLoad = () => {
207
+ if (!view.path.endsWith('.tsx')) loaded();
208
+ };
209
+ frame?.addEventListener('load', onFrameLoad);
210
+ return () => {
211
+ window.removeEventListener('message', onMessage);
212
+ frame?.removeEventListener('load', onFrameLoad);
213
+ clearTimeout(giveUp);
214
+ for (const t of timers) clearTimeout(t);
215
+ };
216
+ }, [view.phase, view.path]);
217
+
218
+ // THE CANVAS CAPABILITY EXPIRES (render-token.mjs). Same re-mint the studio
219
+ // shell runs (app.jsx), for the one frame this view holds: an embed left open
220
+ // on a task must keep loading after a teammate's edit re-imports the module.
221
+ useEffect(() => {
222
+ if (view.phase !== 'canvas' || !view.cfg.canvasToken) return undefined;
223
+ const target = originOf(view.cfg.canvasOrigin);
224
+ let stopped = false;
225
+ let timer = null;
226
+ const schedule = (token) => {
227
+ timer = setTimeout(refresh, canvasTokenRefreshDelay(token));
228
+ };
229
+ async function refresh() {
230
+ let token = null;
231
+ try {
232
+ // Re-mint the SAME read-only capability — never a full one.
233
+ token = (await readJson(EMBED_CONFIG_URL))?.canvasToken;
234
+ } catch {
235
+ /* retried below; the current capability may still be valid */
236
+ }
237
+ if (stopped) return;
238
+ if (typeof token !== 'string' || !token) {
239
+ timer = setTimeout(refresh, 30_000);
240
+ return;
241
+ }
242
+ setLiveCanvasToken(token);
243
+ if (target) {
244
+ try {
245
+ frameRef.current?.contentWindow?.postMessage({ dgn: 'canvas-cap', t: token }, target);
246
+ } catch {}
247
+ }
248
+ schedule(token);
249
+ }
250
+ schedule(view.cfg.canvasToken);
251
+ return () => {
252
+ stopped = true;
253
+ clearTimeout(timer);
254
+ };
255
+ }, [view.phase, view.cfg?.canvasToken, view.cfg?.canvasOrigin]);
256
+
257
+ return (
258
+ <div style={ROOT_STYLE} data-testid="embed-view">
259
+ {view.phase === 'canvas' && (
260
+ <iframe
261
+ ref={frameRef}
262
+ src={view.src}
263
+ title={view.title ? `Canvas: ${view.title}` : `Canvas: ${view.path}`}
264
+ style={FRAME_STYLE}
265
+ data-testid="embed-canvas-frame"
266
+ // Same containment the studio shell gives a cross-origin canvas.
267
+ {...(view.cfg.canvasOrigin
268
+ ? { sandbox: 'allow-scripts allow-same-origin', allow: 'clipboard-write' }
269
+ : {})}
270
+ />
271
+ )}
272
+ {view.phase === 'missing' && (
273
+ <div style={NOTE_STYLE} role="status">
274
+ This design is not in the project, or it could not be loaded.
275
+ </div>
276
+ )}
277
+ {view.phase === 'signed-out' && (
278
+ <div style={NOTE_STYLE} role="status">
279
+ Sign in to the design hub to see this design.
280
+ </div>
281
+ )}
282
+ </div>
283
+ );
284
+ }
@@ -0,0 +1,101 @@
1
+ // DDR-247 — the chromeless `?embed=1` view another app frames, and the ONE-WAY
2
+ // message contract it speaks to that app. Pure (URLSearchParams + URL only) so
3
+ // `test/embed.test.ts` exercises it without React or a DOM.
4
+ //
5
+ // THE CONTRACT (v1) — embedders build against this shape, so it only grows:
6
+ //
7
+ // { source: 'maude-hub', v: 1,
8
+ // type: 'ready' | 'auth-required' | 'not-found' | 'escape',
9
+ // open: string, title?: string }
10
+ //
11
+ // `auth-required` is posted by the hub's signed-out embed page
12
+ // (apps/hub/src/embed-page.mjs), the others by `embed-view.jsx`. `escape`
13
+ // (added to v1, additive) means Escape was pressed inside the embed and
14
+ // nothing there consumed it — keys in a frame never reach the embedding page,
15
+ // so without it an embed inside a dialog would trap a keyboard user. The embed
16
+ // never takes focus on its own; only a click moves focus into it. Nothing is
17
+ // ever posted to '*': the target is the parent's exact origin, and only when
18
+ // that origin is on the server's embed allowlist. Nothing is accepted FROM the
19
+ // parent in v1.
20
+ import { readOpenParam } from './share-link.js';
21
+
22
+ export const EMBED_SOURCE = 'maude-hub';
23
+ export const EMBED_VERSION = 1;
24
+
25
+ /** Is this page load the embed view? Exactly `embed=1`, nothing looser. */
26
+ export function isEmbedLocation(location) {
27
+ try {
28
+ return new URLSearchParams(location?.search ?? '').get('embed') === '1';
29
+ } catch {
30
+ return false;
31
+ }
32
+ }
33
+
34
+ /** An artboard id the embed may ask the canvas to frame. Only ever compared for
35
+ * equality against `data-dc-screen`, so the bound is length + no controls. */
36
+ export function validArtboardId(raw) {
37
+ return (
38
+ typeof raw === 'string' &&
39
+ raw.length > 0 &&
40
+ raw.length <= 120 &&
41
+ ![...raw].some((c) => c.charCodeAt(0) < 32 || c.charCodeAt(0) === 127)
42
+ );
43
+ }
44
+
45
+ /**
46
+ * What the embed was asked to show. `open` is the validated design-root
47
+ * relative identity (share-link.js rules) or null; `requested` is what the
48
+ * embedder sent, echoed back in `not-found` so it can tell its own requests
49
+ * apart.
50
+ */
51
+ export function readEmbedParams(location, designRel = '.design') {
52
+ const params = new URLSearchParams(location?.search ?? '');
53
+ const values = params.getAll('open');
54
+ const artboard = params.get('artboard');
55
+ return {
56
+ open: readOpenParam(location, designRel),
57
+ requested: values.length === 1 ? values[0].slice(0, 512) : '',
58
+ artboard: validArtboardId(artboard) ? artboard : null,
59
+ };
60
+ }
61
+
62
+ /**
63
+ * The embedding page's origin. `ancestorOrigins` where the engine has it
64
+ * (Chromium, WebKit) — it cannot be influenced by the parent's referrer
65
+ * policy — else the referrer's origin (Firefox). Null when not framed at all.
66
+ */
67
+ export function parentOrigin(win) {
68
+ try {
69
+ if (!win || win.parent === win) return null;
70
+ const ancestors = win.location?.ancestorOrigins;
71
+ if (ancestors && ancestors.length > 0) return ancestors[0];
72
+ const referrer = win.document?.referrer;
73
+ return referrer ? new URL(referrer).origin : null;
74
+ } catch {
75
+ return null;
76
+ }
77
+ }
78
+
79
+ /** The exact origin to post to, or null — never '*', never an unlisted parent. */
80
+ export function embedTarget(origin, allowlist) {
81
+ if (typeof origin !== 'string' || !origin || origin === 'null') return null;
82
+ return Array.isArray(allowlist) && allowlist.includes(origin) ? origin : null;
83
+ }
84
+
85
+ export function embedMessage(type, open, title) {
86
+ const msg = { source: EMBED_SOURCE, v: EMBED_VERSION, type, open: String(open ?? '') };
87
+ if (typeof title === 'string' && title) msg.title = title;
88
+ return msg;
89
+ }
90
+
91
+ /** Post one contract message to the parent, if the parent may hear it. */
92
+ export function postToEmbedder(win, allowlist, type, open, title) {
93
+ const target = embedTarget(parentOrigin(win), allowlist);
94
+ if (!target) return false;
95
+ try {
96
+ win.parent.postMessage(embedMessage(type, open, title), target);
97
+ return true;
98
+ } catch {
99
+ return false;
100
+ }
101
+ }
@@ -31,6 +31,8 @@ const SCOPE_LABELS = {
31
31
  selection: 'Selection',
32
32
  artboard: 'Artboard',
33
33
  'canvas-as-separate': 'Canvas → separate',
34
+ 'canvas-whole': 'Whole canvas',
35
+ 'selection-bounds': 'Selection area',
34
36
  'project-raw': 'Project (raw)',
35
37
  };
36
38
 
@@ -155,17 +155,50 @@ export const saveExport = (filename, jobId) => invoke('save_export', { filename,
155
155
  /**
156
156
  * Native "open file" for media upload — the read counterpart to saveExport.
157
157
  * WKWebView won't present the file panel for an HTML <input type=file>, so the
158
- * AssetPicker uses this in the desktop app. Returns { name, bytes:[...] } or null
159
- * (cancelled). Browser build uses the <input type=file> path instead.
158
+ * AssetPicker uses this in the desktop app. Returns `{ token, name, size }` or
159
+ * null (cancelled) — never the bytes: read them with {@link pickedMediaSource}.
160
+ * Browser build uses the <input type=file> path instead.
160
161
  */
161
162
  export const pickMediaFile = () => invoke('pick_media_file');
162
163
 
163
164
  /**
164
165
  * feature-bulk-media-insert — multi-select counterpart to pickMediaFile.
165
- * Resolves to `[{name, bytes:[...]}, ...]` (empty array if cancelled).
166
+ * Resolves to `[{ token, name, size }, ...]` (empty array if cancelled).
166
167
  */
167
168
  export const pickMediaFiles = () => invoke('pick_media_files');
168
169
 
170
+ /**
171
+ * A picked file as an upload source (`asset-upload.ts` ChunkSource): bytes are
172
+ * read one slice at a time as a raw ArrayBuffer over IPC, so a 500 MB clip is
173
+ * never held whole in the page. Call `release()` when the upload is done.
174
+ */
175
+ export function pickedMediaSource(ref, type) {
176
+ return {
177
+ size: ref.size,
178
+ type: type || '',
179
+ name: ref.name,
180
+ async read(start, end) {
181
+ const buf = await invoke('read_picked_media', {
182
+ token: ref.token,
183
+ offset: start,
184
+ len: end - start,
185
+ });
186
+ return new Uint8Array(buf);
187
+ },
188
+ release: () => invoke('release_picked_media', { token: ref.token }).catch(() => {}),
189
+ };
190
+ }
191
+
192
+ /** A small picked file read whole (screenshots). Releases the pick. */
193
+ export async function readPickedMediaBlob(ref, type) {
194
+ const src = pickedMediaSource(ref, type);
195
+ try {
196
+ return new Blob([await src.read(0, ref.size)], type ? { type } : undefined);
197
+ } finally {
198
+ src.release();
199
+ }
200
+ }
201
+
169
202
  // ── Tauri shell: auto-update (Phase 32 / Task 1) ────────────────────────────────
170
203
  // The shell downloads + stages a newer build in the background and emits
171
204
  // `update-ready` with { version, notes }. The client shows a banner; clicking