@1agh/maude 1.6.13 → 1.8.1
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/acp/bridge.ts +1 -0
- package/apps/studio/acp/login-state.ts +1 -0
- package/apps/studio/acp/probe.ts +1 -0
- package/apps/studio/annotations/ai-read.ts +3 -0
- package/apps/studio/annotations/ai-write.ts +15 -1
- package/apps/studio/annotations/lock.ts +174 -0
- package/apps/studio/annotations/migrate-v1.ts +1 -0
- package/apps/studio/annotations/registry.ts +3 -0
- package/apps/studio/annotations/v1-adapter.ts +1 -0
- package/apps/studio/annotations-context-toolbar.tsx +39 -0
- package/apps/studio/annotations-layer.tsx +167 -17
- package/apps/studio/annotations-model.ts +9 -0
- package/apps/studio/api.ts +412 -35
- package/apps/studio/asset-upload.ts +174 -0
- package/apps/studio/assets-s3.ts +37 -2
- package/apps/studio/bin/_pdf-playwright.mjs +22 -1
- package/apps/studio/bin/_png-playwright.mjs +20 -1
- package/apps/studio/bin/_region.mjs +92 -0
- package/apps/studio/canvas-build.ts +59 -4
- package/apps/studio/canvas-icons.tsx +18 -0
- package/apps/studio/canvas-lib.tsx +48 -1
- package/apps/studio/canvas-shell.tsx +28 -4
- package/apps/studio/client/app.jsx +109 -22
- package/apps/studio/client/canvas-url.js +9 -0
- package/apps/studio/client/embed-view.jsx +284 -0
- package/apps/studio/client/embed.js +101 -0
- package/apps/studio/client/export-center.jsx +2 -0
- package/apps/studio/client/github.js +36 -3
- package/apps/studio/client/report-bug.jsx +8 -2
- package/apps/studio/context.ts +7 -0
- package/apps/studio/dist/client.bundle.js +2682 -2682
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/embed-origins.ts +52 -0
- package/apps/studio/export-dialog.tsx +55 -3
- package/apps/studio/exporters/format-scopes.ts +11 -3
- package/apps/studio/exporters/index.ts +17 -2
- package/apps/studio/exporters/jobs.ts +16 -8
- package/apps/studio/exporters/pdf.ts +10 -2
- package/apps/studio/exporters/png.ts +10 -2
- package/apps/studio/exporters/scope.ts +74 -3
- package/apps/studio/generation/runtime-probe.ts +1 -1
- package/apps/studio/git/service.ts +1 -0
- package/apps/studio/http.ts +186 -13
- package/apps/studio/input-router.tsx +7 -1
- package/apps/studio/path-containment.ts +72 -0
- package/apps/studio/paths.ts +14 -1
- package/apps/studio/read-only-mode.ts +53 -0
- package/apps/studio/server.ts +9 -0
- package/apps/studio/sync/index.ts +74 -13
- package/apps/studio/sync/park.ts +39 -0
- package/apps/studio/sync/presentation.ts +9 -3
- package/apps/studio/sync/writer-registry.ts +5 -0
- package/apps/studio/use-annotation-resize.tsx +4 -1
- package/apps/studio/use-canvas-media-drop.tsx +8 -28
- package/apps/studio/whats-new.json +36 -0
- package/cli/commands/design.mjs +9 -2
- package/cli/commands/hub-workspace.mjs +25 -0
- package/cli/lib/workspace-plan.mjs +51 -0
- package/package.json +9 -9
- package/plugins/design/templates/_shell.html +58 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file asset-upload.ts — the one client for `POST /_api/asset*`
|
|
3
|
+
* @scope apps/studio/asset-upload.ts
|
|
4
|
+
* @purpose Uploads a media file the way every surface should: in one request
|
|
5
|
+
* when it is small, or as a chunked session (issue #126) when it is
|
|
6
|
+
* a video/audio clip past {@link CHUNK_THRESHOLD}. Shared by the
|
|
7
|
+
* canvas drop/paste hook (inside the canvas iframe) and the shell's
|
|
8
|
+
* AssetPicker, including the desktop native "Open file" picker — so
|
|
9
|
+
* no surface is left capped at the one-shot limit.
|
|
10
|
+
*
|
|
11
|
+
* DOM- and React-free. The server decides type, caps and budget;
|
|
12
|
+
* nothing here is trusted by it.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export type UploadResult = { path: string } | { error: string };
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Bytes to upload. A `Blob`/`File` slices lazily, so a 500 MB drop is never
|
|
19
|
+
* read whole; a {@link ChunkSource} serves sources that live outside the page
|
|
20
|
+
* (the desktop picker reads them through IPC, one slice at a time).
|
|
21
|
+
*/
|
|
22
|
+
export interface ChunkSource {
|
|
23
|
+
readonly size: number;
|
|
24
|
+
readonly type: string;
|
|
25
|
+
read(start: number, end: number): Promise<Uint8Array>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type UploadInput = Blob | ChunkSource;
|
|
29
|
+
|
|
30
|
+
export interface UploadOptions {
|
|
31
|
+
/** 0..1 as chunks land. Called only on the chunked path. */
|
|
32
|
+
onProgress?: (fraction: number) => void;
|
|
33
|
+
fetchImpl?: typeof fetch;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Above this, video/audio goes through chunk sessions. A client constant on
|
|
38
|
+
* purpose — the server's one-shot cap is env-configurable and unknown here; the
|
|
39
|
+
* chunk SIZE comes from the server's chunk-start answer.
|
|
40
|
+
*/
|
|
41
|
+
export const CHUNK_THRESHOLD = 32 * 1024 * 1024;
|
|
42
|
+
|
|
43
|
+
const CHUNK_RETRIES = 3;
|
|
44
|
+
|
|
45
|
+
function isBlob(input: UploadInput): input is Blob {
|
|
46
|
+
return typeof Blob !== 'undefined' && input instanceof Blob;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Whether an upload takes the chunked path. Images never do (the server refuses
|
|
51
|
+
* them there); an UNTYPED large source is assumed to be media — the server
|
|
52
|
+
* sniffs the bytes either way.
|
|
53
|
+
*/
|
|
54
|
+
export function shouldChunk(size: number, type: string): boolean {
|
|
55
|
+
return size > CHUNK_THRESHOLD && !type.startsWith('image/');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** `[start, end)` byte ranges for `size` bytes in `chunkBytes` pieces. */
|
|
59
|
+
export function chunkRanges(size: number, chunkBytes: number): Array<[number, number]> {
|
|
60
|
+
const out: Array<[number, number]> = [];
|
|
61
|
+
for (let start = 0; start < size; start += chunkBytes) {
|
|
62
|
+
out.push([start, Math.min(size, start + chunkBytes)]);
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function errorOf(res: Response): Promise<string> {
|
|
68
|
+
try {
|
|
69
|
+
const j = (await res.json()) as { error?: string };
|
|
70
|
+
if (j?.error) return j.error;
|
|
71
|
+
} catch {
|
|
72
|
+
/* non-JSON error body */
|
|
73
|
+
}
|
|
74
|
+
return `upload failed (${res.status})`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function bodyOf(input: UploadInput, start: number, end: number): Promise<BodyInit> {
|
|
78
|
+
if (isBlob(input)) return input.slice(start, end);
|
|
79
|
+
return (await input.read(start, end)) as Uint8Array<ArrayBuffer>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function uploadOneShot(input: UploadInput, doFetch: typeof fetch): Promise<UploadResult> {
|
|
83
|
+
const res = await doFetch('/_api/asset', {
|
|
84
|
+
method: 'POST',
|
|
85
|
+
headers: { 'Content-Type': input.type || 'application/octet-stream' },
|
|
86
|
+
body: await bodyOf(input, 0, input.size),
|
|
87
|
+
});
|
|
88
|
+
if (!res.ok) return { error: await errorOf(res) };
|
|
89
|
+
const j = (await res.json()) as { path?: unknown };
|
|
90
|
+
return typeof j?.path === 'string' ? { path: j.path } : { error: 'malformed upload response' };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 4xx other than 409/429 won't change on a retry. */
|
|
94
|
+
function retryable(status: number): boolean {
|
|
95
|
+
return status >= 500 || status === 409 || status === 429;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function uploadChunked(
|
|
99
|
+
input: UploadInput,
|
|
100
|
+
doFetch: typeof fetch,
|
|
101
|
+
onProgress?: (fraction: number) => void
|
|
102
|
+
): Promise<UploadResult> {
|
|
103
|
+
const startRes = await doFetch('/_api/asset/chunk-start', {
|
|
104
|
+
method: 'POST',
|
|
105
|
+
headers: { 'Content-Type': 'application/json' },
|
|
106
|
+
body: JSON.stringify({ totalSize: input.size }),
|
|
107
|
+
});
|
|
108
|
+
if (!startRes.ok) return { error: await errorOf(startRes) };
|
|
109
|
+
const { session, chunkBytes } = (await startRes.json()) as {
|
|
110
|
+
session?: unknown;
|
|
111
|
+
chunkBytes?: unknown;
|
|
112
|
+
};
|
|
113
|
+
if (typeof session !== 'string' || typeof chunkBytes !== 'number' || chunkBytes <= 0) {
|
|
114
|
+
return { error: 'malformed upload response' };
|
|
115
|
+
}
|
|
116
|
+
const q = `session=${encodeURIComponent(session)}`;
|
|
117
|
+
const abort = () =>
|
|
118
|
+
doFetch(`/_api/asset/chunk?${q}`, { method: 'DELETE' }).catch(() => undefined);
|
|
119
|
+
|
|
120
|
+
const ranges = chunkRanges(input.size, chunkBytes);
|
|
121
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
122
|
+
const [start, end] = ranges[i];
|
|
123
|
+
let lastError = 'upload failed';
|
|
124
|
+
let sent = false;
|
|
125
|
+
for (let attempt = 0; attempt < CHUNK_RETRIES && !sent; attempt++) {
|
|
126
|
+
if (attempt > 0) await new Promise((r) => setTimeout(r, 300 * attempt));
|
|
127
|
+
try {
|
|
128
|
+
const res = await doFetch(`/_api/asset/chunk?${q}&index=${i}`, {
|
|
129
|
+
method: 'POST',
|
|
130
|
+
headers: { 'Content-Type': 'application/octet-stream' },
|
|
131
|
+
body: await bodyOf(input, start, end),
|
|
132
|
+
});
|
|
133
|
+
if (res.ok) {
|
|
134
|
+
sent = true;
|
|
135
|
+
} else {
|
|
136
|
+
lastError = await errorOf(res);
|
|
137
|
+
if (!retryable(res.status)) break;
|
|
138
|
+
}
|
|
139
|
+
} catch (e) {
|
|
140
|
+
lastError = e instanceof Error ? e.message : 'network error';
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (!sent) {
|
|
144
|
+
await abort();
|
|
145
|
+
return { error: lastError };
|
|
146
|
+
}
|
|
147
|
+
onProgress?.((i + 1) / ranges.length);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const res = await doFetch(`/_api/asset/chunk-finish?${q}`, { method: 'POST' });
|
|
151
|
+
if (!res.ok) return { error: await errorOf(res) };
|
|
152
|
+
const j = (await res.json()) as { path?: unknown };
|
|
153
|
+
return typeof j?.path === 'string' ? { path: j.path } : { error: 'malformed upload response' };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Chunked uploads run one at a time: the server caps open sessions, so a
|
|
157
|
+
// six-file native pick fired concurrently would 429 on the fifth. One-shot
|
|
158
|
+
// uploads stay concurrent.
|
|
159
|
+
let chunkQueue: Promise<unknown> = Promise.resolve();
|
|
160
|
+
|
|
161
|
+
export async function uploadAsset(
|
|
162
|
+
input: UploadInput,
|
|
163
|
+
opts: UploadOptions = {}
|
|
164
|
+
): Promise<UploadResult> {
|
|
165
|
+
const doFetch = opts.fetchImpl ?? fetch;
|
|
166
|
+
try {
|
|
167
|
+
if (!shouldChunk(input.size, input.type)) return await uploadOneShot(input, doFetch);
|
|
168
|
+
const run = chunkQueue.then(() => uploadChunked(input, doFetch, opts.onProgress));
|
|
169
|
+
chunkQueue = run.catch(() => undefined);
|
|
170
|
+
return await run;
|
|
171
|
+
} catch (e) {
|
|
172
|
+
return { error: e instanceof Error ? e.message : 'network error' };
|
|
173
|
+
}
|
|
174
|
+
}
|
package/apps/studio/assets-s3.ts
CHANGED
|
@@ -99,8 +99,16 @@ export function signRequest(
|
|
|
99
99
|
method,
|
|
100
100
|
key,
|
|
101
101
|
body = null,
|
|
102
|
+
bodySha256,
|
|
102
103
|
now = new Date(),
|
|
103
|
-
}: {
|
|
104
|
+
}: {
|
|
105
|
+
method: string;
|
|
106
|
+
key: string;
|
|
107
|
+
body?: Uint8Array | null;
|
|
108
|
+
/** Hex SHA-256 of a body the caller streams instead of passing as `body`. */
|
|
109
|
+
bodySha256?: string;
|
|
110
|
+
now?: Date;
|
|
111
|
+
}
|
|
104
112
|
): SignedRequest {
|
|
105
113
|
const url = new URL(`${cfg.endpoint}/${cfg.bucket}${key ? `/${encodeKey(key)}` : ''}`);
|
|
106
114
|
const iso = now
|
|
@@ -108,7 +116,7 @@ export function signRequest(
|
|
|
108
116
|
.replace(/[-:]/g, '')
|
|
109
117
|
.replace(/\.\d{3}/, '');
|
|
110
118
|
const dateStamp = iso.slice(0, 8);
|
|
111
|
-
const payloadHash = body === null ? sha256Hex('') : sha256Hex(body);
|
|
119
|
+
const payloadHash = bodySha256 ?? (body === null ? sha256Hex('') : sha256Hex(body));
|
|
112
120
|
|
|
113
121
|
const headers: Record<string, string> = {
|
|
114
122
|
host: url.host,
|
|
@@ -202,6 +210,11 @@ export interface AssetMirror {
|
|
|
202
210
|
* bucket is the redundant copy, not the authority).
|
|
203
211
|
*/
|
|
204
212
|
push(rel: string, bytes: Uint8Array): Promise<boolean>;
|
|
213
|
+
/**
|
|
214
|
+
* {@link push} for a file already on disk, streamed so a 512 MB clip is never
|
|
215
|
+
* held in RAM. `sha256Hex` is the hash of the file's bytes (the writer has it).
|
|
216
|
+
*/
|
|
217
|
+
pushFile(rel: string, absPath: string, sha256Hex: string): Promise<boolean>;
|
|
205
218
|
/** Download one asset, or null when absent. Verifies the content address. */
|
|
206
219
|
pull(rel: string): Promise<Uint8Array | null>;
|
|
207
220
|
/** True when the object exists. Used by the dangling-pointer check. */
|
|
@@ -214,6 +227,9 @@ const NOOP_MIRROR: AssetMirror = {
|
|
|
214
227
|
async push() {
|
|
215
228
|
return false;
|
|
216
229
|
},
|
|
230
|
+
async pushFile() {
|
|
231
|
+
return false;
|
|
232
|
+
},
|
|
217
233
|
async pull() {
|
|
218
234
|
return null;
|
|
219
235
|
},
|
|
@@ -258,6 +274,25 @@ export function createAssetMirror(
|
|
|
258
274
|
}
|
|
259
275
|
},
|
|
260
276
|
|
|
277
|
+
async pushFile(rel, absPath, sha256Hex) {
|
|
278
|
+
try {
|
|
279
|
+
const { url, headers } = signRequest(cfg, {
|
|
280
|
+
method: 'PUT',
|
|
281
|
+
key: rel,
|
|
282
|
+
bodySha256: sha256Hex,
|
|
283
|
+
});
|
|
284
|
+
const res = await fetch(url, { method: 'PUT', headers, body: Bun.file(absPath) });
|
|
285
|
+
if (!res.ok) {
|
|
286
|
+
log.warn(`[assets] mirror PUT ${rel} failed: ${res.status}`);
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
return true;
|
|
290
|
+
} catch (err) {
|
|
291
|
+
log.warn(`[assets] mirror PUT ${rel} failed: ${(err as Error).message}`);
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
|
|
261
296
|
async pull(rel) {
|
|
262
297
|
try {
|
|
263
298
|
const res = await send('GET', rel);
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
26
26
|
import { dirname, join } from 'node:path';
|
|
27
27
|
import { assertRenderOutputSizeOk, launchChromium, safeArtboardFilename } from './_pw-launch.mjs';
|
|
28
|
+
import { layoutRegion, parseRegionArg } from './_region.mjs';
|
|
28
29
|
|
|
29
30
|
const args = Object.fromEntries(
|
|
30
31
|
process.argv.slice(2).reduce((acc, cur, i, all) => {
|
|
@@ -40,6 +41,7 @@ const {
|
|
|
40
41
|
'out-dir': outDir,
|
|
41
42
|
'widen-to-artboard': widenFlag,
|
|
42
43
|
multi: multiFlag,
|
|
44
|
+
region: regionArg,
|
|
43
45
|
timeout = '12',
|
|
44
46
|
scale = '1',
|
|
45
47
|
} = args;
|
|
@@ -51,6 +53,7 @@ if (!url) {
|
|
|
51
53
|
|
|
52
54
|
const widen = widenFlag !== undefined;
|
|
53
55
|
const multi = multiFlag !== undefined;
|
|
56
|
+
const region = parseRegionArg(regionArg);
|
|
54
57
|
const timeoutMs = Number(timeout) * 1000;
|
|
55
58
|
// Same ceiling as _png-playwright.mjs's raised T4 ceiling (600dpi = 6.25×).
|
|
56
59
|
// The PDF *page* stays vector-sized regardless of this factor (only raster
|
|
@@ -104,7 +107,25 @@ try {
|
|
|
104
107
|
}
|
|
105
108
|
});
|
|
106
109
|
|
|
107
|
-
|
|
110
|
+
if (region) {
|
|
111
|
+
// Issue #125 — one page covering a whole region of the world plane (the
|
|
112
|
+
// whole canvas, or the selection's bounding box), layout + annotations
|
|
113
|
+
// intact. Page size = region size, same crop trick as the loop below.
|
|
114
|
+
const box = await layoutRegion(page, region);
|
|
115
|
+
assertRenderOutputSizeOk(box.width, box.height, deviceScaleFactor, '_pdf-playwright');
|
|
116
|
+
await page.setViewportSize({ width: Math.max(1, box.width), height: Math.max(1, box.height) });
|
|
117
|
+
const pdf = await page.pdf({
|
|
118
|
+
width: `${box.width}px`,
|
|
119
|
+
height: `${box.height}px`,
|
|
120
|
+
printBackground: true,
|
|
121
|
+
preferCSSPageSize: false,
|
|
122
|
+
margin: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
123
|
+
});
|
|
124
|
+
writeFileSync(out, pdf);
|
|
125
|
+
written.push(out);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
for (let i = 0; i < (region ? 0 : screens.length); i += 1) {
|
|
108
129
|
// Widen a descendant selector to its enclosing artboard when requested
|
|
109
130
|
// (artboard-via-descendant fallback); selection / artboard-by-id targets
|
|
110
131
|
// pass through unchanged.
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { mkdirSync } from 'node:fs';
|
|
9
9
|
import { dirname, join } from 'node:path';
|
|
10
10
|
import { launchChromium, safeArtboardFilename } from './_pw-launch.mjs';
|
|
11
|
+
import { layoutRegion, parseRegionArg } from './_region.mjs';
|
|
11
12
|
|
|
12
13
|
const args = Object.fromEntries(
|
|
13
14
|
process.argv.slice(2).reduce((acc, cur, i, all) => {
|
|
@@ -23,6 +24,7 @@ const {
|
|
|
23
24
|
'out-dir': outDir,
|
|
24
25
|
'widen-to-artboard': widenFlag,
|
|
25
26
|
multi: multiFlag,
|
|
27
|
+
region: regionArg,
|
|
26
28
|
timeout = '12',
|
|
27
29
|
scale = '1',
|
|
28
30
|
} = args;
|
|
@@ -33,6 +35,7 @@ if (!url) {
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
const widen = widenFlag !== undefined;
|
|
38
|
+
const region = parseRegionArg(regionArg);
|
|
36
39
|
const multi = multiFlag !== undefined;
|
|
37
40
|
const timeoutMs = Number(timeout) * 1000;
|
|
38
41
|
// feature-2-print-artboards T4 — ceiling raised 4→8 so a 300dpi export
|
|
@@ -202,7 +205,23 @@ try {
|
|
|
202
205
|
}, savedPos);
|
|
203
206
|
};
|
|
204
207
|
|
|
205
|
-
if (
|
|
208
|
+
if (region) {
|
|
209
|
+
// Issue #125 — one image of a whole region of the world plane (the whole
|
|
210
|
+
// canvas, or the selection's bounding box), layout + annotations intact.
|
|
211
|
+
if (!out) {
|
|
212
|
+
console.error('_png-playwright: --out required with --region');
|
|
213
|
+
process.exit(2);
|
|
214
|
+
}
|
|
215
|
+
mkdirSync(dirname(out), { recursive: true });
|
|
216
|
+
const box = await layoutRegion(page, region);
|
|
217
|
+
assertOutputSizeOk(box.width, box.height);
|
|
218
|
+
await page.setViewportSize({ width: Math.max(1, box.width), height: Math.max(1, box.height) });
|
|
219
|
+
await page.screenshot({
|
|
220
|
+
path: out,
|
|
221
|
+
clip: { x: 0, y: 0, width: box.width, height: box.height },
|
|
222
|
+
});
|
|
223
|
+
written.push(out);
|
|
224
|
+
} else if (multi) {
|
|
206
225
|
if (!outDir) {
|
|
207
226
|
console.error('_png-playwright: --multi requires --out-dir');
|
|
208
227
|
process.exit(2);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// _region.mjs — region capture for the PNG / PDF playwright shims (issue #125).
|
|
2
|
+
//
|
|
3
|
+
// The per-artboard path pins ONE artboard to (0,0) and crops to it. A region
|
|
4
|
+
// capture instead keeps the world-plane layout intact and crops to the union
|
|
5
|
+
// bounding box of several things: every artboard + annotation element
|
|
6
|
+
// (`--region canvas`, the `canvas-whole` scope) or a list of selected elements
|
|
7
|
+
// (`--region '{"selectors":[…]}'`, the `selection-bounds` scope). Annotations
|
|
8
|
+
// that fall inside the box come along for free — they live in `.dc-world`
|
|
9
|
+
// too (annotations/ui/scene.tsx), visible when the shell was loaded with
|
|
10
|
+
// `annotations=1`.
|
|
11
|
+
|
|
12
|
+
/** Gap between the content and the image edge, in CSS px. */
|
|
13
|
+
export const REGION_PADDING = 32;
|
|
14
|
+
|
|
15
|
+
/** Parse the shim's `--region` value: `canvas` or `{"selectors":[...]}`. */
|
|
16
|
+
export function parseRegionArg(raw) {
|
|
17
|
+
if (raw === undefined) return null;
|
|
18
|
+
if (raw === 'canvas') return { kind: 'canvas' };
|
|
19
|
+
try {
|
|
20
|
+
const v = JSON.parse(raw);
|
|
21
|
+
if (v && Array.isArray(v.selectors) && v.selectors.every((s) => typeof s === 'string')) {
|
|
22
|
+
return { kind: 'selectors', selectors: v.selectors };
|
|
23
|
+
}
|
|
24
|
+
} catch {
|
|
25
|
+
/* fall through */
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`invalid --region value (expected "canvas" or {"selectors":[…]})`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Lay the region out at the viewport origin and return its size in CSS px.
|
|
32
|
+
*
|
|
33
|
+
* Resets the world plane's pan/zoom (CSS `zoom` shrinks layout, so rects lie
|
|
34
|
+
* under it), measures the union box, then translates `.dc-world` so the box's
|
|
35
|
+
* top-left — minus the padding — sits at (0,0). The caller sizes the viewport
|
|
36
|
+
* to the returned box and captures from the origin.
|
|
37
|
+
*/
|
|
38
|
+
export async function layoutRegion(page, region, padding = REGION_PADDING) {
|
|
39
|
+
const box = await page.evaluate(
|
|
40
|
+
({ region, padding }) => {
|
|
41
|
+
const world = document.querySelector('.dc-world');
|
|
42
|
+
if (world) {
|
|
43
|
+
world.style.zoom = '1';
|
|
44
|
+
world.style.transform = 'none';
|
|
45
|
+
}
|
|
46
|
+
// The active-artboard ring (`aria-current` → accent box-shadow) paints
|
|
47
|
+
// OUTSIDE the artboard box: a per-artboard crop cut it off, a region
|
|
48
|
+
// keeps it. Editor state, not design — drop it (throwaway shim page).
|
|
49
|
+
for (const ab of document.querySelectorAll('[data-dc-screen][aria-current]')) {
|
|
50
|
+
ab.removeAttribute('aria-current');
|
|
51
|
+
}
|
|
52
|
+
const els = [];
|
|
53
|
+
if (region.kind === 'canvas') {
|
|
54
|
+
els.push(...document.querySelectorAll('[data-dc-screen]'));
|
|
55
|
+
// Annotation elements count only when they are actually painted —
|
|
56
|
+
// without `annotations=1` the scene is display:none and measures 0×0.
|
|
57
|
+
for (const scene of document.querySelectorAll('[data-mdcc-annotations]')) {
|
|
58
|
+
els.push(...scene.children);
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
for (const sel of region.selectors) {
|
|
62
|
+
try {
|
|
63
|
+
els.push(...document.querySelectorAll(sel));
|
|
64
|
+
} catch {
|
|
65
|
+
/* an unparsable selector contributes nothing */
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
let minX = Infinity;
|
|
70
|
+
let minY = Infinity;
|
|
71
|
+
let maxX = -Infinity;
|
|
72
|
+
let maxY = -Infinity;
|
|
73
|
+
for (const el of els) {
|
|
74
|
+
const r = el.getBoundingClientRect();
|
|
75
|
+
if (r.width === 0 && r.height === 0) continue;
|
|
76
|
+
minX = Math.min(minX, r.left);
|
|
77
|
+
minY = Math.min(minY, r.top);
|
|
78
|
+
maxX = Math.max(maxX, r.right);
|
|
79
|
+
maxY = Math.max(maxY, r.bottom);
|
|
80
|
+
}
|
|
81
|
+
if (!Number.isFinite(minX)) return null;
|
|
82
|
+
if (world) {
|
|
83
|
+
world.style.transform = `translate(${padding - minX}px, ${padding - minY}px)`;
|
|
84
|
+
}
|
|
85
|
+
window.scrollTo(0, 0);
|
|
86
|
+
return { width: maxX - minX + padding * 2, height: maxY - minY + padding * 2 };
|
|
87
|
+
},
|
|
88
|
+
{ region, padding }
|
|
89
|
+
);
|
|
90
|
+
if (!box) throw new Error('region capture: nothing to export — no visible element matched');
|
|
91
|
+
return { width: Math.ceil(box.width), height: Math.ceil(box.height) };
|
|
92
|
+
}
|
|
@@ -28,6 +28,8 @@ import path from 'node:path';
|
|
|
28
28
|
import { canvasLibPath, canvasLibResolver } from './canvas-lib-resolver.ts';
|
|
29
29
|
import { transpileCanvasSource } from './canvas-pipeline.ts';
|
|
30
30
|
import type { LocatorMap } from './locator.ts';
|
|
31
|
+
import { isUnderOrEqual } from './path-containment.ts';
|
|
32
|
+
import { DEV_SERVER_ROOT } from './paths.ts';
|
|
31
33
|
import { RUNTIME_PACKAGES } from './runtime-bundle.ts';
|
|
32
34
|
|
|
33
35
|
// Sanity-check the dev-server-bundled canvas-lib once per process boot. If the
|
|
@@ -379,7 +381,47 @@ function importAllowlist(
|
|
|
379
381
|
// value was not assignable at the one place it is used.
|
|
380
382
|
): import('bun').BunPlugin {
|
|
381
383
|
const root = path.resolve(designRoot);
|
|
382
|
-
|
|
384
|
+
// Both spellings of every root: the bundler reports importers (and so every
|
|
385
|
+
// relative target) by REAL path, while callers pass the logical one. Comparing
|
|
386
|
+
// only the logical root made every canvas file behind a symlink — macOS
|
|
387
|
+
// `/var`, a symlinked `~/git`, a Windows `subst` drive or junction — look like
|
|
388
|
+
// one of OUR modules, exempt from the allowlist, so it could import any file
|
|
389
|
+
// on disk (security review of #145, attacker F1).
|
|
390
|
+
const bothForms = (p: string) => {
|
|
391
|
+
const abs = path.resolve(p);
|
|
392
|
+
try {
|
|
393
|
+
const real = realpathSync(abs);
|
|
394
|
+
return real === abs ? [abs] : [abs, real];
|
|
395
|
+
} catch {
|
|
396
|
+
return [abs];
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
const roots = bothForms(root);
|
|
400
|
+
// OUR code: canvas-lib and its siblings, plus the dependencies they import
|
|
401
|
+
// (`apps/studio/node_modules`, or hoisted one level up in the npm layout).
|
|
402
|
+
// Named explicitly — an importer that is neither ours nor the tenant's is
|
|
403
|
+
// refused, never presumed safe.
|
|
404
|
+
const ours = [
|
|
405
|
+
...bothForms(DEV_SERVER_ROOT),
|
|
406
|
+
...bothForms(path.join(DEV_SERVER_ROOT, '..', '..', 'node_modules')),
|
|
407
|
+
];
|
|
408
|
+
const inRoot = (p: string) => roots.some((r) => isUnderOrEqual(p, r));
|
|
409
|
+
const realTarget = (p: string): string => {
|
|
410
|
+
let dir = p;
|
|
411
|
+
let rest = '';
|
|
412
|
+
for (;;) {
|
|
413
|
+
try {
|
|
414
|
+
const real = realpathSync(dir);
|
|
415
|
+
return rest ? path.join(real, rest) : real;
|
|
416
|
+
} catch {
|
|
417
|
+
const parent = path.dirname(dir);
|
|
418
|
+
if (parent === dir) return p;
|
|
419
|
+
rest = rest ? path.join(path.basename(dir), rest) : path.basename(dir);
|
|
420
|
+
dir = parent;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
const isOurs = (p: string) => ours.some((r) => isUnderOrEqual(p, r));
|
|
383
425
|
const deny = (specifier: string, reason: string): never => {
|
|
384
426
|
denials.push({ specifier, reason });
|
|
385
427
|
throw new Error(reason);
|
|
@@ -399,8 +441,17 @@ function importAllowlist(
|
|
|
399
441
|
// schemes that go to the NETWORK; these never do.
|
|
400
442
|
if (/^(data|blob):/i.test(args.path)) return { path: args.path, external: true };
|
|
401
443
|
const importer = args.importer ? path.resolve(args.importer) : '';
|
|
402
|
-
// Our own modules (canvas-lib and its graph) resolve normally.
|
|
403
|
-
|
|
444
|
+
// Our own modules (canvas-lib and its graph) resolve normally. The
|
|
445
|
+
// design root is checked FIRST: it may itself sit inside our tree (this
|
|
446
|
+
// repo's own `.design/`), and then the tenant's rules must still apply.
|
|
447
|
+
if (importer && !inRoot(importer)) {
|
|
448
|
+
if (isOurs(importer)) return null;
|
|
449
|
+
deny(
|
|
450
|
+
args.path,
|
|
451
|
+
`"${args.path}" is imported from ${importer}, which is outside the project. ` +
|
|
452
|
+
`A canvas may only import files inside its own design.`
|
|
453
|
+
);
|
|
454
|
+
}
|
|
404
455
|
if (!args.path.startsWith('.') && !path.isAbsolute(args.path)) {
|
|
405
456
|
deny(
|
|
406
457
|
args.path,
|
|
@@ -411,7 +462,11 @@ function importAllowlist(
|
|
|
411
462
|
);
|
|
412
463
|
}
|
|
413
464
|
const resolved = path.resolve(path.dirname(importer || root), args.path);
|
|
414
|
-
|
|
465
|
+
// Where the bytes really are: a symlink INSIDE the design root (file or
|
|
466
|
+
// directory) still points wherever it points. The nearest existing
|
|
467
|
+
// ancestor is resolved, so `./dirlink/secret` and an extensionless
|
|
468
|
+
// specifier through a linked folder are both judged by their real home.
|
|
469
|
+
if (!inRoot(resolved) || !inRoot(realTarget(resolved))) {
|
|
415
470
|
deny(
|
|
416
471
|
args.path,
|
|
417
472
|
`This canvas imports "${args.path}", which is outside the project (${path.relative(root, resolved)}). ` +
|
|
@@ -614,6 +614,24 @@ export function IconGroup(props: IconProps) {
|
|
|
614
614
|
</Svg>
|
|
615
615
|
);
|
|
616
616
|
}
|
|
617
|
+
/** Lucide `lock` — #137 annotation lock. */
|
|
618
|
+
export function IconLock(props: IconProps) {
|
|
619
|
+
return (
|
|
620
|
+
<Svg {...props}>
|
|
621
|
+
<rect x="3" y="11" width="18" height="11" rx="2" />
|
|
622
|
+
<path d="M7 11V7a5 5 0 0110 0v4" />
|
|
623
|
+
</Svg>
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
/** Lucide `lock-open` — #137 annotation unlock. */
|
|
627
|
+
export function IconLockOpen(props: IconProps) {
|
|
628
|
+
return (
|
|
629
|
+
<Svg {...props}>
|
|
630
|
+
<rect x="3" y="11" width="18" height="11" rx="2" />
|
|
631
|
+
<path d="M7 11V7a5 5 0 019.9-1" />
|
|
632
|
+
</Svg>
|
|
633
|
+
);
|
|
634
|
+
}
|
|
617
635
|
export function IconUngroup(props: IconProps) {
|
|
618
636
|
return (
|
|
619
637
|
<Svg {...props}>
|
|
@@ -139,7 +139,7 @@ import {
|
|
|
139
139
|
// (photo/pipeline.ts, which imports pixi.js) is loaded via a DYNAMIC import
|
|
140
140
|
// inside <PhotoLayer> only when an edited photo actually mounts — see there.
|
|
141
141
|
import { isDefaultEdit, type PhotoEdit } from './photo/schema.ts';
|
|
142
|
-
import { isReadOnlyCanvas } from './read-only-mode.ts';
|
|
142
|
+
import { isEmbedCanvas, isReadOnlyCanvas } from './read-only-mode.ts';
|
|
143
143
|
import { AgentPresenceProvider, useAgentPresence } from './use-agent-presence.tsx';
|
|
144
144
|
import { type DragState, useArtboardDrag } from './use-artboard-drag.tsx';
|
|
145
145
|
import {
|
|
@@ -828,6 +828,10 @@ function patchCanvasMeta(patch: {
|
|
|
828
828
|
layout?: { artboards: ArtboardRect[] };
|
|
829
829
|
}): void {
|
|
830
830
|
if (typeof window === 'undefined' || typeof fetch === 'undefined') return;
|
|
831
|
+
// DDR-247 — an embedded view persists nothing, camera included: its fit is
|
|
832
|
+
// not the designer's view, and the next time they open the canvas in the
|
|
833
|
+
// studio it must be where they left it.
|
|
834
|
+
if (isEmbedCanvas()) return;
|
|
831
835
|
// Cloud Phase 25 C2 — a read-only session persists its CAMERA (per-user
|
|
832
836
|
// `_canvas-state/` view, DDR-115) but never the LAYOUT lane (versioned
|
|
833
837
|
// `.meta.json`). The dev-server refuses the layout lane too (http.ts);
|
|
@@ -1429,6 +1433,10 @@ export function useViewportController(opts: ViewportControllerOptions): Viewport
|
|
|
1429
1433
|
// iframe's contentWindow so the window-scoped keydown listener below
|
|
1430
1434
|
// receives events natively.
|
|
1431
1435
|
const onPointerEnter = () => {
|
|
1436
|
+
// DDR-247 — an embed never takes focus on its own: a pointer merely
|
|
1437
|
+
// passing over it inside another app's dialog would pull keyboard focus
|
|
1438
|
+
// out of that app and strand its Escape. A click still focuses it.
|
|
1439
|
+
if (isEmbedCanvas()) return;
|
|
1432
1440
|
try {
|
|
1433
1441
|
const active = document.activeElement as HTMLElement | null;
|
|
1434
1442
|
// Never steal focus from something being TYPED into. An editor that
|
|
@@ -1945,9 +1953,48 @@ function useExportCaptureBridge() {
|
|
|
1945
1953
|
}, []);
|
|
1946
1954
|
}
|
|
1947
1955
|
|
|
1956
|
+
// Issue #125 — the shell's "Selection area" export needs EVERYTHING selected:
|
|
1957
|
+
// canvas elements (the selection set — the shell only tracks one) AND
|
|
1958
|
+
// annotation elements (a separate selection, never reported to the shell).
|
|
1959
|
+
// The shell asks right before submitting; we answer with one selector per item.
|
|
1960
|
+
function useExportSelectionBridge() {
|
|
1961
|
+
const selSet = useSelectionSetOptional();
|
|
1962
|
+
const selRef = useRef(selSet);
|
|
1963
|
+
selRef.current = selSet;
|
|
1964
|
+
useEffect(() => {
|
|
1965
|
+
if (typeof window === 'undefined' || window.parent === window) return;
|
|
1966
|
+
const onMsg = (e: MessageEvent) => {
|
|
1967
|
+
if (e.source !== window.parent) return;
|
|
1968
|
+
const m = e.data as { dgn?: string; id?: unknown } | null;
|
|
1969
|
+
if (m?.dgn !== 'export-selection-query' || typeof m.id !== 'string') return;
|
|
1970
|
+
const selectors: string[] = [];
|
|
1971
|
+
for (const it of selRef.current?.selected ?? []) {
|
|
1972
|
+
if (it?.selector) selectors.push(it.selector);
|
|
1973
|
+
}
|
|
1974
|
+
const annotIds = (
|
|
1975
|
+
document.querySelector('.dc-annot-svg')?.getAttribute('data-selection') ?? ''
|
|
1976
|
+
)
|
|
1977
|
+
.split(/\s+/)
|
|
1978
|
+
.filter(Boolean);
|
|
1979
|
+
for (const id of annotIds) {
|
|
1980
|
+
selectors.push(`[data-mdcc-annotations] [data-id="${id.replace(/["\\]/g, '\\$&')}"]`);
|
|
1981
|
+
}
|
|
1982
|
+
const replyOrigin = e.origin && e.origin !== 'null' ? e.origin : '*';
|
|
1983
|
+
try {
|
|
1984
|
+
window.parent.postMessage({ dgn: 'export-selection', id: m.id, selectors }, replyOrigin);
|
|
1985
|
+
} catch {
|
|
1986
|
+
/* parent gone */
|
|
1987
|
+
}
|
|
1988
|
+
};
|
|
1989
|
+
window.addEventListener('message', onMsg);
|
|
1990
|
+
return () => window.removeEventListener('message', onMsg);
|
|
1991
|
+
}, []);
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1948
1994
|
function DesignCanvasInner({ children, controls }: DesignCanvasProps) {
|
|
1949
1995
|
ensureEngineStyles();
|
|
1950
1996
|
useExportCaptureBridge();
|
|
1997
|
+
useExportSelectionBridge();
|
|
1951
1998
|
|
|
1952
1999
|
const hostRef = useRef<HTMLDivElement | null>(null);
|
|
1953
2000
|
const worldRef = useRef<HTMLDivElement | null>(null);
|