@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,782 @@
1
+ // dialogs/export-dialog.jsx — moved verbatim out of client/app.jsx (Maude v2 plan V2-0.2, move-only split).
2
+
3
+ import { useCallback, useEffect, useState } from 'react';
4
+ import { BROWSER_CAPTURE_FORMATS, BROWSER_SERVABLE_FORMATS, browserCaptureEligible, captureDeckViaBrowser, captureScale, recordBrowserExport, sanitizeCapturedItems } from '../export-lane.js';
5
+ import { defaultScopeForFormat, isScopeValidForFormat, validScopesForFormat } from '../../exporters/format-scopes.ts';
6
+ import { activeComp, resolveCompTarget } from '../panels/timeline-comp-target.js';
7
+ import { SYSTEM_TAB } from '../shell/constants.js';
8
+ import { basename, displayName } from '../shell/util.js';
9
+ import { StIcon } from '../shell/icons.jsx';
10
+
11
+ // T5 (Plan C) — shell-level Export & Handoff dialog (maude `.st-dialog`), per
12
+ // `.design/ui/Studio.tsx` HandoffBoard. Wired to the privileged main-origin
13
+ // `POST /_api/export` (7 real formats × scopes). The shadcn card is HANDOFF —
14
+ // a privileged disk-write kept off HTTP routes (DDR-054), so it surfaces the
15
+ // `/design:handoff` command instead. PPTX/Canva kept reachable (no silent cap).
16
+ export const EXPORT_CARDS = [
17
+ { id: 'png', label: 'PNG', sub: 'raster · 2×', icon: 'image', format: 'png', options: { scale: 2 } },
18
+ { id: 'pdf', label: 'PDF', sub: 'vector · print', icon: 'file', format: 'pdf' },
19
+ { id: 'svg', label: 'SVG', sub: 'per artboard', icon: 'vector', format: 'svg' },
20
+ { id: 'html', label: 'HTML', sub: 'self-contained', icon: 'code', format: 'html' },
21
+ { id: 'pptx', label: 'PPTX', sub: 'slides', icon: 'presentation', format: 'pptx' },
22
+ // DDR-148 — temporal formats. Shown only when the active canvas has a
23
+ // video-comp (`temporal: true` + the hasComps gate in ExportDialog); the
24
+ // capture engine renders the artboard frame-by-frame.
25
+ { id: 'mp4', label: 'MP4', sub: 'video · H.264', icon: 'presentation', format: 'mp4', temporal: true },
26
+ { id: 'gif', label: 'GIF', sub: 'animated', icon: 'image', format: 'gif', temporal: true },
27
+ { id: 'canva', label: 'Canva', sub: 'handoff bundle', icon: 'external', format: 'canva' },
28
+ { id: 'zip', label: 'ZIP', sub: 'project bundle', icon: 'archive', format: 'zip' },
29
+ { id: 'shadcn', label: 'AI handoff', sub: 'production drop', icon: 'sparkle', handoff: true },
30
+ ];
31
+
32
+ // Mirrors export-dialog.tsx (the in-canvas dialog) so both entry points offer
33
+ // the same settings. Scope validity + PNG scale presets are ported verbatim.
34
+ export const EXPORT_SCOPE_LABELS = {
35
+ selection: 'Current selection',
36
+ artboard: 'Active artboard',
37
+ 'canvas-as-separate': 'Canvas · artboards separate',
38
+ 'canvas-whole': 'Whole canvas · one image',
39
+ 'selection-bounds': 'Selection area · one image',
40
+ 'project-raw': 'Whole project (raw)',
41
+ };
42
+
43
+ // Issue #125 — scopes that capture a world-plane region as one unit; the only
44
+ // ones that can carry the annotation layer.
45
+ export const EXPORT_REGION_SCOPES = new Set(['canvas-whole', 'selection-bounds']);
46
+
47
+ export const PNG_SCALES = [
48
+ { value: 1, label: '1× (native)' },
49
+ { value: 2, label: '2× (retina)' },
50
+ { value: 3, label: '3× (max)' },
51
+ ];
52
+
53
+ // feature-2-print-artboards T6 — the PNG card's resolution picker folds the
54
+ // legacy 1×/2×/3× multiplier and the new physical-DPI ladder (T4) into ONE
55
+ // select: `kind:'scale'` entries send `options.scale`, `kind:'dpi'` entries
56
+ // send `options.dpi` (exporters/png.ts resolveDeviceScale — dpi wins over
57
+ // scale when both could apply). Default stays 2× (unchanged UX for anyone
58
+ // not exporting for print).
59
+ export const PNG_RESOLUTIONS = [
60
+ { id: '1x', label: '1× (native)', kind: 'scale', value: 1 },
61
+ { id: '2x', label: '2× (retina)', kind: 'scale', value: 2 },
62
+ { id: '3x', label: '3× (max)', kind: 'scale', value: 3 },
63
+ { id: 'dpi150', label: '150 dpi', kind: 'dpi', value: 150 },
64
+ { id: 'dpi300', label: '300 dpi (print)', kind: 'dpi', value: 300 },
65
+ { id: 'dpi600', label: '600 dpi (high-res print)', kind: 'dpi', value: 600 },
66
+ ];
67
+
68
+ export const PNG_RESOLUTION_DEFAULT = '2x';
69
+
70
+ // feature-2-print-artboards T5/T6 (dogfood follow-up) — the PDF page itself
71
+ // is always vector (text/shapes never rasterize), but any RASTER content ON
72
+ // the artboard — a dropped photo, a large-format piece authored at a
73
+ // fraction of its real physical size (e.g. a billboard at 1:10 scale) —
74
+ // still embeds as a bitmap whose density this controls. Default "Auto (1×)"
75
+ // is today's unchanged behavior; PDF has no legacy scale concept, so unlike
76
+ // PNG_RESOLUTIONS this is DPI-only.
77
+ export const PDF_DPI_OPTIONS = [
78
+ { id: 'auto', label: 'Auto (1×)', value: undefined },
79
+ { id: 'dpi150', label: '150 dpi', value: 150 },
80
+ { id: 'dpi300', label: '300 dpi (print)', value: 300 },
81
+ { id: 'dpi600', label: '600 dpi (high-res print)', value: 600 },
82
+ ];
83
+
84
+ export const PDF_DPI_DEFAULT = 'auto';
85
+
86
+ // issue #116 — how the export treats text. Mirrors export-dialog.tsx's
87
+ // PDF_TEXT_OPTIONS (same mirror obligation as PDF_DPI_OPTIONS above).
88
+ //
89
+ // The list is FIXED regardless of whether Ghostscript is present on this
90
+ // machine. Hiding "Convert to outlines" when gs is missing would need a new
91
+ // capability route, and would answer the user's question ("can I send this to
92
+ // a printer?") by making the answer invisible; a refusal that names the
93
+ // one-line install is more honest and reaches them at the moment they care.
94
+ export const PDF_TEXT_OPTIONS = [
95
+ {
96
+ id: 'keep',
97
+ label: 'Keep selectable (default)',
98
+ description:
99
+ 'Text stays selectable and searchable. You are warned if a font came out unprintable.',
100
+ },
101
+ {
102
+ id: 'embed',
103
+ label: 'Verify fonts embedded',
104
+ description:
105
+ 'Same file, but the export fails instead of shipping a font a print shop would reject.',
106
+ },
107
+ {
108
+ id: 'outline',
109
+ label: 'Convert to outlines (print-safe)',
110
+ description:
111
+ 'Every glyph becomes a vector path — no fonts left to break. Text is no longer selectable ' +
112
+ 'and the file can grow a lot. Needs Ghostscript installed locally; cloud workspaces have it.',
113
+ },
114
+ ];
115
+
116
+ export const PDF_TEXT_DEFAULT = 'keep';
117
+
118
+ // Direct download for a browser-lane capture. export-center's autoDownloadBlob
119
+ // fetches a JOB's bytes — a browser capture has no job, just the Blob.
120
+ export function downloadCapturedBlob(name, blob) {
121
+ const url = URL.createObjectURL(blob);
122
+ const a = document.createElement('a');
123
+ a.href = url;
124
+ a.download = name || 'export';
125
+ document.body.appendChild(a);
126
+ a.click();
127
+ a.remove();
128
+ // Revoke on a delay — an immediate revoke can race the download start in
129
+ // some engines (the click only queues the fetch of the object URL).
130
+ setTimeout(() => URL.revokeObjectURL(url), 10_000);
131
+ }
132
+
133
+ export function ExportDialog({
134
+ mode,
135
+ initialScope,
136
+ activePath,
137
+ hasComps = false,
138
+ comps = [],
139
+ activeArtboardId = null,
140
+ selection = null,
141
+ exportLane = 'local',
142
+ onBrowserCapture = null,
143
+ onQuerySelection = null,
144
+ onClose,
145
+ }) {
146
+ // feature-cloud-export-render-workers — on a cell with no render service
147
+ // (`lane === 'none'`), formats that render through a browser are offered
148
+ // disabled-with-a-reason instead of firing a request the proxy 404s. ZIP
149
+ // (JSZip over project files) and the AI-handoff card (clipboard copy) need
150
+ // no browser — and DDR-231's browser lane keeps png/svg live in every
151
+ // workspace lane too (captured by the member's own browser, no service).
152
+ const laneBlocked = useCallback(
153
+ (c) =>
154
+ (exportLane === 'none' &&
155
+ !c.handoff &&
156
+ c.format !== 'zip' &&
157
+ !BROWSER_SERVABLE_FORMATS.has(c.format)) ||
158
+ // Canva bundles project files the render service can't reach — desktop only
159
+ // in every workspace lane (exporters/remote.ts REMOTE_UNSUPPORTED_FORMATS).
160
+ (exportLane !== 'local' && c.format === 'canva'),
161
+ [exportLane]
162
+ );
163
+ const [sel, setSel] = useState(mode === 'handoff' ? 'shadcn' : 'png');
164
+ // DDR-231 Phase 2 T4 — seed from the shared table, and only honour an
165
+ // incoming hint the CHOSEN FORMAT can actually render. A hint the format
166
+ // can't take (a context menu's `project-raw`, a re-run of a zip history
167
+ // entry) used to survive into the request and reach the render service as
168
+ // an unrenderable file-tree target: "invalid render job".
169
+ // The dialog opens on the PNG card; the format-change effect below re-seeds
170
+ // the scope whenever the member picks another one.
171
+ const [scope, setScope] = useState(() =>
172
+ initialScope && isScopeValidForFormat('png', initialScope)
173
+ ? initialScope
174
+ : defaultScopeForFormat('png')
175
+ );
176
+ const [scale, setScale] = useState(2);
177
+ // feature-2-print-artboards T4/T6 — PNG resolution (folds scale + dpi, see
178
+ // PNG_RESOLUTIONS above).
179
+ const [pngResId, setPngResId] = useState(PNG_RESOLUTION_DEFAULT);
180
+ // feature-2-print-artboards T5/T6 — PDF print options. Sent unconditionally
181
+ // on every PDF export; the server no-ops them for a non-print artboard (no
182
+ // `print` JSX prop → applyPrintBoxesAndMarks never runs), so there's no
183
+ // need to detect the artboard's kind client-side before showing these.
184
+ const [pdfIncludeBleed, setPdfIncludeBleed] = useState(true);
185
+ const [pdfMarksOpen, setPdfMarksOpen] = useState(false);
186
+ const [pdfMarksCrop, setPdfMarksCrop] = useState(false);
187
+ const [pdfMarksRegistration, setPdfMarksRegistration] = useState(false);
188
+ const [pdfDpiId, setPdfDpiId] = useState(PDF_DPI_DEFAULT);
189
+ const [pdfTextId, setPdfTextId] = useState(PDF_TEXT_DEFAULT);
190
+ // Issue #125 — opt-in, region scopes only. Comment pins never export.
191
+ const [includeAnnotations, setIncludeAnnotations] = useState(false);
192
+ // DDR-148 addendum — mp4/webm of a registered video-comp render through
193
+ // renderMediaOnWeb, which produces real audio (Remotion owns the
194
+ // TransitionSeries/volume-closure timeline). gif has no audio track at all
195
+ // (format limitation, not a toggle), so this only applies to mp4/webm.
196
+ const [audio, setAudio] = useState(true);
197
+ const [busy, setBusy] = useState(false);
198
+ const [status, setStatus] = useState(null); // { ok, msg }
199
+ const [recent, setRecent] = useState([]);
200
+ const card = EXPORT_CARDS.find((c) => c.id === sel) || EXPORT_CARDS[0];
201
+ const validScopes = card.handoff ? [] : validScopesForFormat(card.format);
202
+ // Long-comp tiers (feature-enhanced-video-editing Task 1). 900 frames is the
203
+ // safe tier (the frame-step fallback runs ~2.5 s/frame and 1080p captures
204
+ // have died from memory pressure above it); 3600 is the server's default cap
205
+ // (exporters/video.ts DEFAULT_MAX_FRAMES). Above the cap the dialog raises it
206
+ // EXPLICITLY for this export, with the notice below as the informed consent —
207
+ // never a silent truncation, never a surprise refusal.
208
+ const EXPORT_SAFE_FRAMES = 900;
209
+ const EXPORT_DEFAULT_CAP = 3600;
210
+ // The comp being exported — resolved to the artboard this dialog targets, not
211
+ // to whichever comp mounted first (#75). It drives the long-comp consent
212
+ // notice AND `options.maxFrames`, so a wrong pick both misstates the frame
213
+ // count to the user and raises the server-side cap on behalf of a comp that
214
+ // isn't the one leaving the machine.
215
+ const exportComp = activeComp(comps, resolveCompTarget(comps, { artboardId: activeArtboardId }));
216
+ const exportCompFrames = exportComp?.durationInFrames || 0;
217
+ const exportCompFps = exportComp?.fps || 30;
218
+ const exportIsHeavy = card.temporal && exportCompFrames > EXPORT_SAFE_FRAMES;
219
+ const exportOverCap = card.temporal && exportCompFrames > EXPORT_DEFAULT_CAP;
220
+
221
+ // Keep the scope valid for the chosen format (pptx/zip etc. only allow a
222
+ // subset). Both dialogs and the server now read one table
223
+ // (exporters/format-scopes.ts) — see DDR-231 Phase 2 T4.
224
+ useEffect(() => {
225
+ if (validScopes.length && !validScopes.includes(scope)) {
226
+ setScope(defaultScopeForFormat(card.format));
227
+ }
228
+ }, [validScopes, scope, card.format]);
229
+
230
+ // DDR-231 T7 — wake the render service the moment the dialog opens on a
231
+ // remote-lane workspace: the multi-GB Chromium container starts booting
232
+ // while the member is still picking format/scope, so a video/PDF job lands
233
+ // on a warm (or at least warming) service instead of a cold one.
234
+ useEffect(() => {
235
+ if (exportLane !== 'remote') return;
236
+ fetch('/_api/export-warmup').catch(() => {});
237
+ }, [exportLane]);
238
+
239
+ const loadRecent = useCallback(() => {
240
+ fetch('/_api/export-history')
241
+ .then((r) => r.json())
242
+ .then((d) => setRecent(Array.isArray(d?.history) ? d.history.slice(0, 6) : []))
243
+ .catch(() => {});
244
+ }, []);
245
+ useEffect(() => {
246
+ loadRecent();
247
+ }, [loadRecent]);
248
+
249
+ useEffect(() => {
250
+ function onKey(e) {
251
+ if (e.key === 'Escape') {
252
+ e.preventDefault();
253
+ onClose();
254
+ }
255
+ }
256
+ window.addEventListener('keydown', onKey);
257
+ return () => window.removeEventListener('keydown', onKey);
258
+ }, [onClose]);
259
+
260
+ async function doExport() {
261
+ if (card.handoff) {
262
+ const p = activePath && activePath !== SYSTEM_TAB ? activePath : '<canvas>.tsx';
263
+ const cmd = `/design:handoff ${p}`;
264
+ try {
265
+ await navigator.clipboard?.writeText(cmd);
266
+ } catch {}
267
+ setStatus({ ok: true, msg: `Copied: ${cmd} — run it in Claude Code.` });
268
+ return;
269
+ }
270
+ if (laneBlocked(card)) {
271
+ // Belt to the disabled-card braces — a stale selection can't submit a
272
+ // format this workspace cannot render.
273
+ setStatus({ ok: false, msg: 'This format needs the render service, which this workspace doesn’t have configured.' });
274
+ return;
275
+ }
276
+ setBusy(true);
277
+ setStatus(null);
278
+ // `scale` drives video resolution (deviceScaleFactor → encoder dims);
279
+ // temporal formats were previously fixed at the tiny native size. PNG's
280
+ // resolution now comes from pngResId (T4/T6 — scale OR dpi).
281
+ const options = card.temporal ? { scale } : {};
282
+ if (card.format === 'png') {
283
+ const res = PNG_RESOLUTIONS.find((r) => r.id === pngResId) || PNG_RESOLUTIONS[1];
284
+ if (res.kind === 'dpi') options.dpi = res.value;
285
+ else options.scale = res.value;
286
+ }
287
+ // Export-with-audio (DDR-148 addendum) — mp4/webm only; gif is silent by
288
+ // format, so the checkbox never renders for it (see hasAudioToggle below).
289
+ if (card.format === 'mp4' || card.format === 'webm') options.audio = audio;
290
+ // Long-comp cap raise — the visible notice above the button is the consent.
291
+ if (exportOverCap) options.maxFrames = exportCompFrames;
292
+ // feature-2-print-artboards T5/T6 — always sent on a PDF export; the
293
+ // adapter no-ops includeBleed/marks for a non-print artboard (T5).
294
+ if (card.format === 'pdf') {
295
+ options.pdfPrint = {
296
+ includeBleed: pdfIncludeBleed,
297
+ marks: { crop: pdfMarksCrop, registration: pdfMarksRegistration },
298
+ };
299
+ // Dogfood follow-up — raster CONTENT on the artboard (a dropped photo,
300
+ // large-format art) still needs a real capture density; the page
301
+ // itself stays vector regardless of this.
302
+ const pdfDpi = PDF_DPI_OPTIONS.find((d) => d.id === pdfDpiId)?.value;
303
+ if (pdfDpi !== undefined) options.dpi = pdfDpi;
304
+ // issue #116 — omitted for `keep` rather than sent explicitly: the
305
+ // adapter's default IS keep, so an untouched dialog produces the exact
306
+ // request body it did before this feature existed.
307
+ if (pdfTextId !== 'keep') options.text = pdfTextId;
308
+ }
309
+ // Scope targeting hints (resolveScope reads these): `artboardId` makes
310
+ // "Active artboard" export the right screen instead of `:first-of-type`;
311
+ // `selection` makes "Current selection" export the selected element. Mirrors
312
+ // the in-canvas dialog's captureScopeHints.
313
+ if (activeArtboardId) options.artboardId = activeArtboardId;
314
+ if (selection?.selector) options.selection = selection;
315
+ if (EXPORT_REGION_SCOPES.has(scope) && includeAnnotations) options.includeAnnotations = true;
316
+ if (scope === 'selection-bounds' && typeof onQuerySelection === 'function') {
317
+ const all = await onQuerySelection();
318
+ if (all?.length) options.selectionAll = all;
319
+ }
320
+ // Which canvas FILE this dialog is exporting — the server's `_active.json`
321
+ // lags a tab switch, and a job resolved against the stale file renders the
322
+ // wrong canvas (with this dialog's artboardId, which then never matches).
323
+ if (activePath && activePath !== SYSTEM_TAB) options.canvasFile = activePath;
324
+ // DDR-231 — the browser lane: in a workspace, png/svg of the active
325
+ // artboard is captured by the member's OWN browser (the canvas already
326
+ // renders here) — instant, no fleet wake. Everything else continues to
327
+ // the jobs lane below.
328
+ // NOTE the format gate. `browserCaptureEligible` answers for the whole
329
+ // browser lane, pptx included — but this branch is the SINGLE-ARTBOARD
330
+ // capture that downloads what the bridge returns verbatim. Without the
331
+ // gate, a pptx export fell in here, asked the bridge for a "pptx" (which it
332
+ // renders as PNG), and died in `sanitizeCapturedItems` on "not a valid
333
+ // pptx" — silently degrading to the worker lane, which is why the deck
334
+ // arrived minutes later with none of the browser lane's fixes in it. The
335
+ // dedicated deck branch below was unreachable. Found by the T7 export E2E.
336
+ const browserEligible =
337
+ BROWSER_CAPTURE_FORMATS.has(card.format) &&
338
+ browserCaptureEligible({
339
+ exportLane,
340
+ format: card.format,
341
+ scope,
342
+ artboardId: options.artboardId,
343
+ }) &&
344
+ typeof onBrowserCapture === 'function';
345
+ if (browserEligible) {
346
+ try {
347
+ const capScale = captureScale(options);
348
+ setStatus({ ok: true, msg: 'Capturing…' });
349
+ const items = await onBrowserCapture({
350
+ format: card.format,
351
+ artboardIds: [options.artboardId],
352
+ scale: capScale,
353
+ onProgress: (current, total) =>
354
+ setStatus({ ok: true, msg: `Capturing ${current}/${total}…` }),
355
+ });
356
+ // Validate before writing to disk — the capture bridge shares a window
357
+ // with tenant TSX, which can forge a reply (DDR-231 security pass, F1):
358
+ // caps count/bytes, sniffs magic, forces name+MIME.
359
+ const safeItems = await sanitizeCapturedItems(items, card.format);
360
+ for (const it of safeItems) downloadCapturedBlob(it.name, it.blob);
361
+ // DDR-231 Phase 2 T6 — the export is DONE and the member should see
362
+ // that, in the dialog and in the ledger. Phase 1 closed the modal the
363
+ // instant the download was handed off, so a browser-lane export left
364
+ // no trace anywhere ("v exports dialog nic nevidim").
365
+ for (const it of safeItems) {
366
+ await recordBrowserExport({ format: card.format, scope, filename: it.name });
367
+ }
368
+ setBusy(false);
369
+ setStatus({
370
+ ok: true,
371
+ msg: `Saved ${safeItems.map((it) => it.name).join(', ')} to your downloads.`,
372
+ });
373
+ return;
374
+ } catch (err) {
375
+ if (exportLane !== 'remote') {
376
+ setStatus({ ok: false, msg: `Capture failed: ${(err && err.message) || err}` });
377
+ setBusy(false);
378
+ return;
379
+ }
380
+ // A render service exists — degrade to the slower jobs lane instead of
381
+ // a dead end (and the fallback keeps the worker path exercised).
382
+ }
383
+ }
384
+ // DDR-231 — the pptx deck: capture every artboard as PNG in THIS browser,
385
+ // compose in-cell (/_api/export-assemble — the zip containment class).
386
+ if (
387
+ browserCaptureEligible({ exportLane, format: card.format, scope }) &&
388
+ card.format === 'pptx' &&
389
+ typeof onBrowserCapture === 'function'
390
+ ) {
391
+ try {
392
+ setStatus({ ok: true, msg: 'Capturing artboards…' });
393
+ const deckName =
394
+ activePath && activePath !== SYSTEM_TAB
395
+ ? basename(activePath).replace(/\.[^.]+$/, '')
396
+ : 'export';
397
+ const { filename, blob } = await captureDeckViaBrowser({
398
+ capture: onBrowserCapture,
399
+ name: deckName,
400
+ onProgress: (current, total) =>
401
+ setStatus({ ok: true, msg: `Capturing ${current}/${total}…` }),
402
+ // Composition happens in-cell AFTER the last capture, and it is not
403
+ // instant for a 10-slide deck. Without this the status sat on
404
+ // "Capturing 10/10…" through the whole assemble step and the deck
405
+ // then appeared out of nowhere — the reported "modal closes, nothing
406
+ // happens, and after a while it downloads by itself".
407
+ onAssemble: () => setStatus({ ok: true, msg: 'Assembling deck…' }),
408
+ });
409
+ downloadCapturedBlob(filename, blob);
410
+ await recordBrowserExport({ format: card.format, scope, filename });
411
+ setBusy(false);
412
+ setStatus({ ok: true, msg: `Saved ${filename} to your downloads.` });
413
+ return;
414
+ } catch (err) {
415
+ if (exportLane !== 'remote') {
416
+ setStatus({ ok: false, msg: `Deck export failed: ${(err && err.message) || err}` });
417
+ setBusy(false);
418
+ return;
419
+ }
420
+ // Render service available — degrade to the jobs lane below.
421
+ }
422
+ }
423
+ if (exportLane === 'none' && BROWSER_CAPTURE_FORMATS.has(card.format)) {
424
+ // Without a render service the browser can only capture what it renders:
425
+ // the active artboard. Other scopes have nowhere to run.
426
+ setStatus({
427
+ ok: false,
428
+ msg: 'Without the render service this workspace exports PNG/SVG of the active artboard only — switch Scope to “Active artboard”, or ask your admin to add maude-render.',
429
+ });
430
+ setBusy(false);
431
+ return;
432
+ }
433
+ try {
434
+ // feature-background-export-notification-center — enqueue and close
435
+ // immediately; the menubar notification center owns status, progress,
436
+ // and completion (download / native Save…) from here on.
437
+ const r = await fetch('/_api/export-jobs', {
438
+ method: 'POST',
439
+ headers: { 'content-type': 'application/json' },
440
+ body: JSON.stringify({ format: card.format, scope, options }),
441
+ });
442
+ if (!r.ok) {
443
+ setStatus({ ok: false, msg: (await r.text()) || `Export failed (${r.status})` });
444
+ setBusy(false);
445
+ return;
446
+ }
447
+ onClose();
448
+ } catch (err) {
449
+ setStatus({ ok: false, msg: err && err.message ? err.message : String(err) });
450
+ setBusy(false);
451
+ }
452
+ }
453
+
454
+ return (
455
+ <div
456
+ className="st-scrim"
457
+ role="presentation"
458
+ onMouseDown={(e) => {
459
+ if (e.target === e.currentTarget) onClose();
460
+ }}
461
+ >
462
+ <div className="st-dialog" role="dialog" aria-modal="true" aria-label="Export and handoff">
463
+ <div className="st-dialog-hd">
464
+ <span className="st-dialog-title">Export &amp; handoff</span>
465
+ <button type="button" className="st-iconbtn" aria-label="Close" onClick={onClose}>
466
+ <StIcon name="x" size={15} />
467
+ </button>
468
+ </div>
469
+ <div className="st-dialog-bd">
470
+ <div className="st-rp-hd">
471
+ {activePath && activePath !== SYSTEM_TAB
472
+ ? `Format · ${displayName(basename(activePath))}`
473
+ : 'Format'}
474
+ </div>
475
+ <div className="st-fmt-grid">
476
+ {EXPORT_CARDS.filter((c) => !c.temporal || hasComps).map((c) => (
477
+ <button
478
+ type="button"
479
+ key={c.id}
480
+ // Stable hooks for the export E2E harnesses (agent-browser web
481
+ // + desktop-e2e native) — data-testid convention, DDR-231
482
+ // Phase 2 T7/T8.
483
+ data-testid={`export-format-${c.id}`}
484
+ className={'st-fmt' + (c.id === sel ? ' is-on' : '')}
485
+ disabled={laneBlocked(c)}
486
+ title={
487
+ laneBlocked(c)
488
+ ? 'Needs the render service — not configured on this workspace'
489
+ : undefined
490
+ }
491
+ onClick={() => {
492
+ setSel(c.id);
493
+ setStatus(null);
494
+ }}
495
+ >
496
+ <StIcon name={c.icon} size={16} />
497
+ <span className="st-fmt-name">{c.label}</span>
498
+ <span className="st-fmt-sub">{c.sub}</span>
499
+ </button>
500
+ ))}
501
+ </div>
502
+ {exportLane === 'none' && (
503
+ <div className="st-dialog-note" data-testid="export-lane-note">
504
+ PNG and SVG of the active artboard — and the PPTX deck — export right
505
+ here in your browser; ZIP and AI handoff work too. PDF, video and other
506
+ multi-artboard exports need the render service, which this workspace
507
+ doesn&apos;t have configured — use the desktop app, or ask your admin to
508
+ add the <code> maude-render</code> service (see the self-hosting docs).
509
+ </div>
510
+ )}
511
+ {!card.handoff && (
512
+ <div className="st-dialog-row">
513
+ <label className="st-dialog-lbl" htmlFor="st-export-scope">
514
+ Scope
515
+ </label>
516
+ <select
517
+ id="st-export-scope"
518
+ data-testid="export-scope"
519
+ className="st-select"
520
+ value={scope}
521
+ onChange={(e) => setScope(e.target.value)}
522
+ >
523
+ {validScopes.map((s) => (
524
+ <option key={s} value={s}>
525
+ {EXPORT_SCOPE_LABELS[s]}
526
+ </option>
527
+ ))}
528
+ </select>
529
+ </div>
530
+ )}
531
+ {!card.handoff && EXPORT_REGION_SCOPES.has(scope) && (
532
+ <div className="st-dialog-row">
533
+ <label className="st-dialog-lbl" htmlFor="st-export-annotations">
534
+ Annotations
535
+ </label>
536
+ <label style={{ display: 'flex', alignItems: 'center', gap: 8, cursor: 'pointer' }}>
537
+ <input
538
+ id="st-export-annotations"
539
+ type="checkbox"
540
+ data-testid="export-include-annotations"
541
+ checked={includeAnnotations}
542
+ onChange={(e) => setIncludeAnnotations(e.target.checked)}
543
+ />
544
+ Include annotations
545
+ </label>
546
+ </div>
547
+ )}
548
+ {!card.handoff && card.format === 'png' && (
549
+ <div className="st-dialog-row">
550
+ <label className="st-dialog-lbl" htmlFor="st-export-size">
551
+ Resolution
552
+ </label>
553
+ <select
554
+ id="st-export-size"
555
+ className="st-select"
556
+ value={pngResId}
557
+ onChange={(e) => setPngResId(e.target.value)}
558
+ >
559
+ {PNG_RESOLUTIONS.map((r) => (
560
+ <option key={r.id} value={r.id}>
561
+ {r.label}
562
+ </option>
563
+ ))}
564
+ </select>
565
+ </div>
566
+ )}
567
+ {!card.handoff && card.format === 'png' && (
568
+ <div className="st-mono" style={{ fontSize: 11, color: 'var(--fg-3)' }}>
569
+ {(() => {
570
+ const res = PNG_RESOLUTIONS.find((r) => r.id === pngResId) || PNG_RESOLUTIONS[1];
571
+ const factor = res.kind === 'dpi' ? res.value / 96 : res.value;
572
+ return `${res.label} ≈ ${Math.round(1440 * factor)}×${Math.round(900 * factor)} for a 1440×900 artboard.`;
573
+ })()}
574
+ </div>
575
+ )}
576
+ {!card.handoff && card.temporal && (
577
+ <div className="st-dialog-row">
578
+ <label className="st-dialog-lbl" htmlFor="st-export-temporal-size">
579
+ Resolution
580
+ </label>
581
+ <select
582
+ id="st-export-temporal-size"
583
+ className="st-select"
584
+ value={scale}
585
+ onChange={(e) => setScale(Number(e.target.value))}
586
+ >
587
+ {PNG_SCALES.map((s) => (
588
+ <option key={s.value} value={s.value}>
589
+ {s.label}
590
+ </option>
591
+ ))}
592
+ </select>
593
+ </div>
594
+ )}
595
+ {!card.handoff && card.temporal && (
596
+ <div className="st-mono" style={{ fontSize: 11, color: 'var(--fg-3)' }}>
597
+ {scale}× the artboard's native resolution (e.g. 960×540 → {960 * scale}×{540 * scale}).
598
+ </div>
599
+ )}
600
+ {exportIsHeavy && (
601
+ <div
602
+ className="st-mono st-export-long-notice"
603
+ data-testid="export-long-comp-notice"
604
+ style={{ fontSize: 11, color: 'var(--accent)', lineHeight: 1.5 }}
605
+ >
606
+ ⚠ Long comp: {exportCompFrames} frames (≈
607
+ {Math.round(exportCompFrames / exportCompFps)}s).
608
+ {exportOverCap
609
+ ? ` Exceeds the default ${EXPORT_DEFAULT_CAP}-frame export cap — exporting raises the cap to the full length for this run.`
610
+ : ''}{' '}
611
+ If the fast renderer falls back to frame-by-frame capture this can take several
612
+ minutes; 2× resolution (≈720–1080p) is recommended for memory headroom.
613
+ </div>
614
+ )}
615
+ {!card.handoff && card.format === 'pdf' && (
616
+ <>
617
+ <div className="st-dialog-row">
618
+ <label className="st-dialog-lbl" htmlFor="st-export-pdf-dpi">
619
+ Image quality
620
+ </label>
621
+ <select
622
+ id="st-export-pdf-dpi"
623
+ className="st-select"
624
+ value={pdfDpiId}
625
+ onChange={(e) => setPdfDpiId(e.target.value)}
626
+ >
627
+ {PDF_DPI_OPTIONS.map((d) => (
628
+ <option key={d.id} value={d.id}>
629
+ {d.label}
630
+ </option>
631
+ ))}
632
+ </select>
633
+ </div>
634
+ <div className="st-mono" style={{ fontSize: 11, color: 'var(--fg-3)' }}>
635
+ The page stays vector; this only sets the capture density for raster content on it
636
+ (dropped photos, large-format art).
637
+ </div>
638
+ <div className="st-dialog-row">
639
+ <label className="st-dialog-lbl" htmlFor="st-export-pdf-text">
640
+ Text
641
+ </label>
642
+ <select
643
+ id="st-export-pdf-text"
644
+ className="st-select"
645
+ data-testid="export-pdf-text"
646
+ value={pdfTextId}
647
+ onChange={(e) => setPdfTextId(e.target.value)}
648
+ >
649
+ {PDF_TEXT_OPTIONS.map((t) => (
650
+ <option key={t.id} value={t.id}>
651
+ {t.label}
652
+ </option>
653
+ ))}
654
+ </select>
655
+ </div>
656
+ <div className="st-mono" style={{ fontSize: 11, color: 'var(--fg-3)' }}>
657
+ {PDF_TEXT_OPTIONS.find((t) => t.id === pdfTextId)?.description}
658
+ </div>
659
+ <div className="st-dialog-row">
660
+ <label
661
+ className="st-dialog-lbl"
662
+ htmlFor="st-export-pdf-bleed"
663
+ style={{ display: 'flex', alignItems: 'center', gap: 8, cursor: 'pointer' }}
664
+ >
665
+ <input
666
+ id="st-export-pdf-bleed"
667
+ type="checkbox"
668
+ checked={pdfIncludeBleed}
669
+ onChange={(e) => setPdfIncludeBleed(e.target.checked)}
670
+ />
671
+ Include bleed
672
+ </label>
673
+ </div>
674
+ <div className="st-dialog-row">
675
+ <button
676
+ type="button"
677
+ className="st-dialog-lbl"
678
+ style={{ background: 'none', border: 0, padding: 0, cursor: 'pointer' }}
679
+ onClick={() => setPdfMarksOpen((v) => !v)}
680
+ aria-expanded={pdfMarksOpen}
681
+ >
682
+ {pdfMarksOpen ? '▾' : '▸'} Marks
683
+ </button>
684
+ </div>
685
+ {pdfMarksOpen && (
686
+ <div style={{ padding: '0 12px 4px', display: 'flex', flexDirection: 'column', gap: 6 }}>
687
+ <label style={{ display: 'flex', alignItems: 'center', gap: 8, cursor: 'pointer', fontSize: 12 }}>
688
+ <input
689
+ type="checkbox"
690
+ checked={pdfMarksCrop}
691
+ onChange={(e) => setPdfMarksCrop(e.target.checked)}
692
+ />
693
+ Crop marks
694
+ </label>
695
+ <label style={{ display: 'flex', alignItems: 'center', gap: 8, cursor: 'pointer', fontSize: 12 }}>
696
+ <input
697
+ type="checkbox"
698
+ checked={pdfMarksRegistration}
699
+ onChange={(e) => setPdfMarksRegistration(e.target.checked)}
700
+ />
701
+ Registration marks
702
+ </label>
703
+ </div>
704
+ )}
705
+ <div className="st-mono" style={{ fontSize: 11, color: 'var(--fg-3)' }}>
706
+ Bleed and marks apply to print (<code>kind="print"</code>) artboards only.
707
+ {scope === 'canvas-as-separate' ? ' One PDF page per artboard.' : ''}
708
+ </div>
709
+ </>
710
+ )}
711
+ {!card.handoff && (card.format === 'mp4' || card.format === 'webm') && (
712
+ <div className="st-dialog-row">
713
+ <label
714
+ className="st-dialog-lbl"
715
+ htmlFor="st-export-audio"
716
+ style={{ display: 'flex', alignItems: 'center', gap: 8, cursor: 'pointer' }}
717
+ >
718
+ <input
719
+ id="st-export-audio"
720
+ type="checkbox"
721
+ checked={audio}
722
+ onChange={(e) => setAudio(e.target.checked)}
723
+ />
724
+ Export with audio
725
+ </label>
726
+ </div>
727
+ )}
728
+ {card.handoff && (
729
+ <div className="callout callout--info" style={{ fontSize: 12 }}>
730
+ Hands the active canvas off to production. Copies{' '}
731
+ <span className="st-mono">/design:handoff &lt;path&gt;</span> — run it in Claude Code to
732
+ emit a ready-to-drop production component next to the canvas.
733
+ </div>
734
+ )}
735
+ {status && (
736
+ <div
737
+ className={'callout ' + (status.ok ? 'callout--success' : 'callout--error')}
738
+ style={{ fontSize: 12 }}
739
+ data-testid="export-status"
740
+ data-ok={status.ok ? '1' : '0'}
741
+ >
742
+ {status.msg}
743
+ </div>
744
+ )}
745
+ {recent.length > 0 && (
746
+ <div className="st-export-recent" data-testid="export-recent">
747
+ <div className="st-rp-hd">Recent</div>
748
+ {recent.map((h, i) => (
749
+ <div className="st-export-recent-row" key={i}>
750
+ <span>
751
+ {String(h.format || '').toUpperCase()} ·{' '}
752
+ {EXPORT_SCOPE_LABELS[h.scope] || h.scope}
753
+ </span>
754
+ <span className="st-mono">{h.filename}</span>
755
+ </div>
756
+ ))}
757
+ </div>
758
+ )}
759
+ </div>
760
+ <div className="st-dialog-ft">
761
+ <button type="button" className="btn btn--ghost" onClick={onClose}>
762
+ Cancel
763
+ </button>
764
+ <button
765
+ type="button"
766
+ className="btn btn--primary"
767
+ data-testid="export-submit"
768
+ disabled={busy}
769
+ onClick={doExport}
770
+ >
771
+ <StIcon name="download" size={14} />
772
+ {card.handoff
773
+ ? 'Copy handoff command'
774
+ : busy
775
+ ? 'Exporting…'
776
+ : `Export ${card.label}`}
777
+ </button>
778
+ </div>
779
+ </div>
780
+ </div>
781
+ );
782
+ }