@enhance-eng/enhance 0.1.17 → 0.1.20
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/dist/{cli-output-identity.lib-LnsyU8mi.mjs → cli-output-identity.lib-Du4_Ahcj.mjs} +2016 -1077
- package/dist/main.mjs +46 -19
- package/dist/{mcp-invocation.adapter-CdKeCw-i.mjs → mcp-invocation.adapter-CcSWERtl.mjs} +2 -2
- package/dist/mcp-main.mjs +7 -7
- package/dist/{mcp-server.adapter-Bk2r-Iiz.mjs → mcp-server.adapter-DrbFMc01.mjs} +1 -1
- package/dist/mcp.mjs +2 -2
- package/dist/{mutation-key.adapter-CRbBW6xF.mjs → mutation-key.adapter-B6dNFpWt.mjs} +88 -73
- package/dist/remote-mcp-main.mjs +5 -5
- package/package.json +1 -1
|
@@ -211,296 +211,10 @@ const restoreCanvasInputSchema = z.object({ canvasId: z.uuid() });
|
|
|
211
211
|
const restoreCanvasOutputSchema = z.object({ canvasId: z.uuid() });
|
|
212
212
|
|
|
213
213
|
//#endregion
|
|
214
|
-
//#region ../../packages/contract/src/canvas/canvas-
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
"line-clamp",
|
|
219
|
-
"flex-grow",
|
|
220
|
-
"flex-shrink",
|
|
221
|
-
"font-weight",
|
|
222
|
-
"opacity",
|
|
223
|
-
"order",
|
|
224
|
-
"z-index",
|
|
225
|
-
"grid-area",
|
|
226
|
-
"grid-row",
|
|
227
|
-
"grid-column",
|
|
228
|
-
"grid-row-start",
|
|
229
|
-
"grid-row-end",
|
|
230
|
-
"grid-column-start",
|
|
231
|
-
"grid-column-end"
|
|
232
|
-
]);
|
|
233
|
-
const canvasCssValue = (property, value) => typeof value === "number" && !UNITLESS_PROPERTIES.has(property.toLowerCase()) ? `${String(value)}px` : String(value);
|
|
234
|
-
const SIDES$1 = [
|
|
235
|
-
"top",
|
|
236
|
-
"right",
|
|
237
|
-
"bottom",
|
|
238
|
-
"left"
|
|
239
|
-
];
|
|
240
|
-
const LEFT_SIDE_INDEX = 3;
|
|
241
|
-
const GRID_TEMPLATE_PROPERTIES = [
|
|
242
|
-
"grid-template-rows",
|
|
243
|
-
"grid-template-columns",
|
|
244
|
-
"grid-template-areas"
|
|
245
|
-
];
|
|
246
|
-
const SHORTHANDS = {
|
|
247
|
-
gap: ["row-gap", "column-gap"],
|
|
248
|
-
padding: SIDES$1.map((side) => `padding-${side}`),
|
|
249
|
-
margin: SIDES$1.map((side) => `margin-${side}`),
|
|
250
|
-
flex: [
|
|
251
|
-
"flex-grow",
|
|
252
|
-
"flex-shrink",
|
|
253
|
-
"flex-basis"
|
|
254
|
-
],
|
|
255
|
-
"flex-flow": ["flex-direction", "flex-wrap"],
|
|
256
|
-
"place-content": ["align-content", "justify-content"],
|
|
257
|
-
"place-items": ["align-items", "justify-items"],
|
|
258
|
-
"place-self": ["align-self", "justify-self"],
|
|
259
|
-
"grid-template": GRID_TEMPLATE_PROPERTIES,
|
|
260
|
-
grid: [
|
|
261
|
-
...GRID_TEMPLATE_PROPERTIES,
|
|
262
|
-
"grid-auto-rows",
|
|
263
|
-
"grid-auto-columns",
|
|
264
|
-
"grid-auto-flow"
|
|
265
|
-
],
|
|
266
|
-
"grid-row": ["grid-row-start", "grid-row-end"],
|
|
267
|
-
"grid-column": ["grid-column-start", "grid-column-end"],
|
|
268
|
-
"grid-area": [
|
|
269
|
-
"grid-row-start",
|
|
270
|
-
"grid-column-start",
|
|
271
|
-
"grid-row-end",
|
|
272
|
-
"grid-column-end"
|
|
273
|
-
]
|
|
274
|
-
};
|
|
275
|
-
/** Related declarations stay authored; a longhand edit must not discard the rest of a shorthand. */
|
|
276
|
-
const canvasCssPropertyScope = (property) => SHORTHANDS[property.toLowerCase()] ?? [property.toLowerCase()];
|
|
277
|
-
const componentStateAfter = (state, character) => {
|
|
278
|
-
if (state.isEscaped) return {
|
|
279
|
-
...state,
|
|
280
|
-
isEscaped: false
|
|
281
|
-
};
|
|
282
|
-
if (character === "\\") return {
|
|
283
|
-
...state,
|
|
284
|
-
isEscaped: true
|
|
285
|
-
};
|
|
286
|
-
if (state.quote !== "") return {
|
|
287
|
-
...state,
|
|
288
|
-
quote: state.quote === character ? "" : state.quote
|
|
289
|
-
};
|
|
290
|
-
if (["\"", "'"].includes(character)) return {
|
|
291
|
-
...state,
|
|
292
|
-
quote: character
|
|
293
|
-
};
|
|
294
|
-
const delta = [
|
|
295
|
-
"(",
|
|
296
|
-
"[",
|
|
297
|
-
"{"
|
|
298
|
-
].includes(character) ? 1 : [
|
|
299
|
-
")",
|
|
300
|
-
"]",
|
|
301
|
-
"}"
|
|
302
|
-
].includes(character) ? -1 : 0;
|
|
303
|
-
return {
|
|
304
|
-
...state,
|
|
305
|
-
depth: state.depth + delta
|
|
306
|
-
};
|
|
307
|
-
};
|
|
308
|
-
/** Split only at CSS component boundaries, keeping functions, line names and strings intact. */
|
|
309
|
-
const canvasCssTokens = (value, separator = "space") => {
|
|
310
|
-
const tokens = [];
|
|
311
|
-
let token = "";
|
|
312
|
-
let state = {
|
|
313
|
-
depth: 0,
|
|
314
|
-
quote: "",
|
|
315
|
-
isEscaped: false
|
|
316
|
-
};
|
|
317
|
-
for (const character of value) {
|
|
318
|
-
const canSplit = state.depth === 0 && state.quote === "" && !state.isEscaped;
|
|
319
|
-
state = componentStateAfter(state, character);
|
|
320
|
-
if (canSplit && (separator === "space" ? /\s/u.test(character) : character === separator)) {
|
|
321
|
-
if (separator !== "space" || token !== "") tokens.push(token.trim());
|
|
322
|
-
token = "";
|
|
323
|
-
} else token += character;
|
|
324
|
-
}
|
|
325
|
-
if (separator !== "space" || token !== "") tokens.push(token.trim());
|
|
326
|
-
return tokens;
|
|
327
|
-
};
|
|
328
|
-
const omittedGridLine = (value) => /^(?:--|-?[_a-z\u{80}-\u{FFFF}])[-\w\u{80}-\u{FFFF}]*$/iu.test(value) && !/^(?:auto|span|initial|unset)$/iu.test(value) ? value : "auto";
|
|
329
|
-
const gridPlacementValue = (property, value, index) => {
|
|
330
|
-
const parts = canvasCssTokens(value, "/");
|
|
331
|
-
const first = parts[0] ?? value;
|
|
332
|
-
if (property !== "grid-area") return parts[index] ?? omittedGridLine(first);
|
|
333
|
-
const column = parts[1] ?? omittedGridLine(first);
|
|
334
|
-
return [
|
|
335
|
-
first,
|
|
336
|
-
column,
|
|
337
|
-
parts[2] ?? omittedGridLine(first),
|
|
338
|
-
parts[3] ?? omittedGridLine(column)
|
|
339
|
-
][index] ?? value;
|
|
340
|
-
};
|
|
341
|
-
const implicitGridValues = (row, column, hasAutoRows) => {
|
|
342
|
-
const tokens = canvasCssTokens(hasAutoRows ? row : column);
|
|
343
|
-
const size = tokens.filter((token) => !/^(?:auto-flow|dense)$/iu.test(token)).join(" ");
|
|
344
|
-
const flow = `${hasAutoRows ? "row" : "column"}${tokens.some((token) => /^dense$/iu.test(token)) ? " dense" : ""}`;
|
|
345
|
-
return [
|
|
346
|
-
hasAutoRows ? "none" : row,
|
|
347
|
-
hasAutoRows ? column : "none",
|
|
348
|
-
"none",
|
|
349
|
-
hasAutoRows && size !== "" ? size : "auto",
|
|
350
|
-
!hasAutoRows && size !== "" ? size : "auto",
|
|
351
|
-
flow
|
|
352
|
-
];
|
|
353
|
-
};
|
|
354
|
-
const gridTemplateValue = (property, value, index) => {
|
|
355
|
-
if (/^(?:none|initial|unset)$/iu.test(value)) return [
|
|
356
|
-
"none",
|
|
357
|
-
"none",
|
|
358
|
-
"none",
|
|
359
|
-
"auto",
|
|
360
|
-
"auto",
|
|
361
|
-
"row"
|
|
362
|
-
][index] ?? value;
|
|
363
|
-
const parts = canvasCssTokens(value, "/");
|
|
364
|
-
const row = parts[0] ?? value;
|
|
365
|
-
const column = parts[1];
|
|
366
|
-
if (row === "" || column === "" || parts.length > 2) return value;
|
|
367
|
-
const hasAutoRows = canvasCssTokens(row).some((token) => token.toLowerCase() === "auto-flow");
|
|
368
|
-
const hasAutoColumns = column !== void 0 && canvasCssTokens(column).some((token) => token.toLowerCase() === "auto-flow");
|
|
369
|
-
if (property === "grid" && column !== void 0 && hasAutoRows !== hasAutoColumns) return implicitGridValues(row, column, hasAutoRows)[index] ?? value;
|
|
370
|
-
if (hasAutoRows || hasAutoColumns) return value;
|
|
371
|
-
const hasAreas = /["']/u.test(row);
|
|
372
|
-
if (column === void 0 && !hasAreas) return value;
|
|
373
|
-
return [
|
|
374
|
-
hasAreas ? value : row,
|
|
375
|
-
column ?? "none",
|
|
376
|
-
hasAreas ? row : "none",
|
|
377
|
-
"auto",
|
|
378
|
-
"auto",
|
|
379
|
-
"row"
|
|
380
|
-
][index] ?? value;
|
|
381
|
-
};
|
|
382
|
-
const flexValues = (tokens) => {
|
|
383
|
-
const numbers = [];
|
|
384
|
-
let basis = "0%";
|
|
385
|
-
for (const token of tokens) if (/^(?:\d+(?:\.\d*)?|\.\d+)$/u.test(token) && numbers.length < 2) numbers.push(token);
|
|
386
|
-
else basis = token;
|
|
387
|
-
return [
|
|
388
|
-
numbers[0] ?? "1",
|
|
389
|
-
numbers[1] ?? "1",
|
|
390
|
-
basis
|
|
391
|
-
];
|
|
392
|
-
};
|
|
393
|
-
const canvasCssShorthandValue = (property, value, index) => {
|
|
394
|
-
if (/(?:var|env)\(|^(?:inherit|revert(?:-layer)?)$/iu.test(value)) return value;
|
|
395
|
-
if (/^grid-(?:area|row|column)$/u.test(property)) return gridPlacementValue(property, value, index);
|
|
396
|
-
if (property === "grid-template" || property === "grid") return gridTemplateValue(property, value, index);
|
|
397
|
-
const tokens = canvasCssTokens(value);
|
|
398
|
-
if (property === "flex-flow") return index === 0 ? tokens.find((token) => /^(?:row|column)(?:-reverse)?$/u.test(token)) ?? "row" : tokens.find((token) => /^(?:nowrap|wrap|wrap-reverse)$/u.test(token)) ?? "nowrap";
|
|
399
|
-
if (property === "flex") {
|
|
400
|
-
if (value === "none") return [
|
|
401
|
-
"0",
|
|
402
|
-
"0",
|
|
403
|
-
"auto"
|
|
404
|
-
][index] ?? value;
|
|
405
|
-
if (value === "initial") return [
|
|
406
|
-
"0",
|
|
407
|
-
"1",
|
|
408
|
-
"auto"
|
|
409
|
-
][index] ?? value;
|
|
410
|
-
return flexValues(tokens)[index] ?? value;
|
|
411
|
-
}
|
|
412
|
-
return tokens[index] ?? (index === LEFT_SIDE_INDEX ? tokens[1] : void 0) ?? tokens[0] ?? value;
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
//#endregion
|
|
416
|
-
//#region ../../packages/contract/src/canvas/canvas-authored-css.lib.ts
|
|
417
|
-
const canvasAdditionalStyleDeclarations = (node) => {
|
|
418
|
-
if (node.additionalStyles === void 0) return {};
|
|
419
|
-
return Object.fromEntries(node.additionalStyles.declarations.filter((declaration) => declaration.enabled).map((declaration) => [declaration.property, declaration.value]));
|
|
420
|
-
};
|
|
421
|
-
/** Additional-style controls exclusively own every property they expose, including when off. */
|
|
422
|
-
const canvasAuthoredStyleDeclarations = (node) => {
|
|
423
|
-
const controlledProperties = new Set(node.additionalStyles?.declarations.map((declaration) => declaration.property.toLowerCase()));
|
|
424
|
-
return {
|
|
425
|
-
...Object.fromEntries(Object.entries(node.styles).filter(([property]) => !controlledProperties.has(property.toLowerCase()))),
|
|
426
|
-
...canvasAdditionalStyleDeclarations(node)
|
|
427
|
-
};
|
|
428
|
-
};
|
|
429
|
-
const hasCanvasCssPriority = (value) => /!important\s*$/iu.test(String(value));
|
|
430
|
-
const cssValue = (value, shouldPreserveCase) => {
|
|
431
|
-
const source = String(value).replace(/\s*!important\s*$/iu, "").trim();
|
|
432
|
-
return shouldPreserveCase || source.includes("(") ? source : source.toLowerCase();
|
|
433
|
-
};
|
|
434
|
-
/** Read supported authored longhands without measuring or rewriting unresolved CSS expressions. */
|
|
435
|
-
const canvasAuthoredLayoutValueOf = (node, property) => {
|
|
436
|
-
let result = null;
|
|
437
|
-
let isImportant = false;
|
|
438
|
-
const declarations = Object.entries(canvasAuthoredStyleDeclarations(node));
|
|
439
|
-
for (const [key, raw] of declarations) {
|
|
440
|
-
const scope = canvasCssPropertyScope(key);
|
|
441
|
-
const index = scope.indexOf(property);
|
|
442
|
-
if (index === -1) continue;
|
|
443
|
-
const isPriority = hasCanvasCssPriority(raw);
|
|
444
|
-
if (isImportant && !isPriority) continue;
|
|
445
|
-
const value = cssValue(raw, /^grid(?:-|$)/iu.test(key));
|
|
446
|
-
result = scope.length === 1 ? value : canvasCssShorthandValue(key.toLowerCase(), value, index);
|
|
447
|
-
isImportant = isPriority;
|
|
448
|
-
}
|
|
449
|
-
return result ?? void 0;
|
|
450
|
-
};
|
|
451
|
-
/** Named controls override only their own longhand, even beside an important shorthand. */
|
|
452
|
-
const canvasLayoutPriorityDeclarations = (node, declarations) => {
|
|
453
|
-
const important = new Set(Object.entries(canvasAuthoredStyleDeclarations(node)).filter(([, value]) => hasCanvasCssPriority(value)).flatMap(([property]) => canvasCssPropertyScope(property)));
|
|
454
|
-
return Object.fromEntries(Object.entries(declarations).map(([property, value]) => [property, canvasCssPropertyScope(property).some((owned) => important.has(owned)) && !hasCanvasCssPriority(value) ? `${canvasCssValue(property, value)} !important` : value]));
|
|
455
|
-
};
|
|
456
|
-
const canvasWritingModeOf = (node, document) => {
|
|
457
|
-
const visited = /* @__PURE__ */ new Set();
|
|
458
|
-
let current = node;
|
|
459
|
-
while (current !== void 0 && !visited.has(current.id)) {
|
|
460
|
-
visited.add(current.id);
|
|
461
|
-
const value = canvasAuthoredLayoutValueOf(current, "writing-mode");
|
|
462
|
-
if (value !== void 0 && value !== "inherit" && value !== "unset") return value;
|
|
463
|
-
if (document === void 0) break;
|
|
464
|
-
const parentId = document.relationships[current.id]?.parentId;
|
|
465
|
-
if (parentId === void 0) break;
|
|
466
|
-
current = document.nodes[parentId];
|
|
467
|
-
}
|
|
468
|
-
return "horizontal-tb";
|
|
469
|
-
};
|
|
470
|
-
const canvasAxisStyleProperties = (node, axis, document) => {
|
|
471
|
-
const isVerticalWriting = /^(?:vertical|sideways)-/u.test(canvasWritingModeOf(node, document));
|
|
472
|
-
return [axis === "horizontal" ? "width" : "height", axis === "vertical" === isVerticalWriting ? "inline-size" : "block-size"];
|
|
473
|
-
};
|
|
474
|
-
/** Authored display wins over legacy presets; Grid has no Flex main axis. */
|
|
475
|
-
const canvasLayoutFlowOf = (node) => {
|
|
476
|
-
if (node === void 0) return "freeform";
|
|
477
|
-
const display = canvasAuthoredLayoutValueOf(node, "display");
|
|
478
|
-
if (display !== void 0) {
|
|
479
|
-
if (/^(?:(?:inline|block)\s+|inline-)?grid$/u.test(display)) return "grid";
|
|
480
|
-
if (/^(?:(?:inline|block)\s+|inline-)?flex$/u.test(display)) return "flex";
|
|
481
|
-
return "freeform";
|
|
482
|
-
}
|
|
483
|
-
const container = node.layout?.container;
|
|
484
|
-
if (container === void 0) return "freeform";
|
|
485
|
-
return container.gridColumns !== void 0 || container.gridAutoRepeat !== void 0 ? "grid" : "flex";
|
|
486
|
-
};
|
|
487
|
-
/** Read a Flex main axis in its inherited writing mode without persisting a preset. */
|
|
488
|
-
const canvasLayoutMainAxisOf = (node, document) => {
|
|
489
|
-
if (node === void 0) return void 0;
|
|
490
|
-
if (canvasLayoutFlowOf(node) !== "flex") return void 0;
|
|
491
|
-
const container = node.layout?.container;
|
|
492
|
-
const css = (property) => canvasAuthoredLayoutValueOf(node, property);
|
|
493
|
-
const direction = container?.direction ?? css("flex-direction") ?? "row";
|
|
494
|
-
if (!/^(?:row|column)(?:-reverse)?$/u.test(direction)) return void 0;
|
|
495
|
-
const isVerticalWriting = /^(?:vertical|sideways)-/u.test(canvasWritingModeOf(node, document));
|
|
496
|
-
return direction.startsWith("column") === isVerticalWriting ? "horizontal" : "vertical";
|
|
497
|
-
};
|
|
498
|
-
|
|
499
|
-
//#endregion
|
|
500
|
-
//#region ../../packages/contract/src/canvas/canvas-limits.schema.ts
|
|
501
|
-
const MAX_CANVAS_VALUE = 1e5;
|
|
502
|
-
const boundedCanvasNumberSchema = z.number().min(-1e5).max(MAX_CANVAS_VALUE);
|
|
503
|
-
const nonNegativeCanvasNumberSchema = z.number().nonnegative().max(MAX_CANVAS_VALUE);
|
|
214
|
+
//#region ../../packages/contract/src/canvas/canvas-limits.schema.ts
|
|
215
|
+
const MAX_CANVAS_VALUE = 1e5;
|
|
216
|
+
const boundedCanvasNumberSchema = z.number().min(-1e5).max(MAX_CANVAS_VALUE);
|
|
217
|
+
const nonNegativeCanvasNumberSchema = z.number().nonnegative().max(MAX_CANVAS_VALUE);
|
|
504
218
|
|
|
505
219
|
//#endregion
|
|
506
220
|
//#region ../../packages/contract/src/canvas/canvas-layout.schema.ts
|
|
@@ -612,6 +326,9 @@ const canvasNodeLayoutSchema = z.object({
|
|
|
612
326
|
//#endregion
|
|
613
327
|
//#region ../../packages/contract/src/canvas/canvas-presentation.schema.ts
|
|
614
328
|
const MAX_ITEM_ID_LENGTH$1 = 200;
|
|
329
|
+
const QUARTER_TURN = 90;
|
|
330
|
+
const HALF_TURN = 180;
|
|
331
|
+
const THREE_QUARTER_TURN = 270;
|
|
615
332
|
const boundedNumber$1 = boundedCanvasNumberSchema;
|
|
616
333
|
const nonNegativeNumber$1 = nonNegativeCanvasNumberSchema;
|
|
617
334
|
const ratio = z.number().min(0).max(1);
|
|
@@ -632,6 +349,25 @@ const canvasPointSchema = z.object({
|
|
|
632
349
|
x: ratio,
|
|
633
350
|
y: ratio
|
|
634
351
|
});
|
|
352
|
+
const adjustment = z.number().min(-1).max(1);
|
|
353
|
+
const canvasImageAdjustmentsSchema = z.object({
|
|
354
|
+
exposure: adjustment.optional(),
|
|
355
|
+
contrast: adjustment.optional(),
|
|
356
|
+
saturation: adjustment.optional(),
|
|
357
|
+
temperature: adjustment.optional(),
|
|
358
|
+
tint: adjustment.optional(),
|
|
359
|
+
highlights: adjustment.optional(),
|
|
360
|
+
shadows: adjustment.optional()
|
|
361
|
+
});
|
|
362
|
+
/** Maps normalized source (u,v) into body (a*u+c*v+e,b*u+d*v+f), before node rotation. */
|
|
363
|
+
const canvasImageTransformSchema = z.tuple([
|
|
364
|
+
boundedNumber$1,
|
|
365
|
+
boundedNumber$1,
|
|
366
|
+
boundedNumber$1,
|
|
367
|
+
boundedNumber$1,
|
|
368
|
+
boundedNumber$1,
|
|
369
|
+
boundedNumber$1
|
|
370
|
+
]).refine(([a, b, c, d]) => a * d !== b * c, "image transform must be invertible");
|
|
635
371
|
const canvasPaintBaseSchema = z.object({
|
|
636
372
|
id: itemId,
|
|
637
373
|
visible: z.boolean(),
|
|
@@ -658,16 +394,30 @@ const canvasPaintSchema = z.discriminatedUnion("kind", [
|
|
|
658
394
|
assetId: z.string().min(1).max(500),
|
|
659
395
|
fit: z.enum([
|
|
660
396
|
"fill",
|
|
397
|
+
"cover",
|
|
661
398
|
"fit",
|
|
662
399
|
"crop",
|
|
663
400
|
"tile"
|
|
664
401
|
]),
|
|
402
|
+
tileScale: boundedNumber$1.positive().optional(),
|
|
403
|
+
tileOrigin: z.enum(["center", "top-left"]).optional(),
|
|
404
|
+
rotation: z.union([
|
|
405
|
+
z.literal(0),
|
|
406
|
+
z.literal(QUARTER_TURN),
|
|
407
|
+
z.literal(HALF_TURN),
|
|
408
|
+
z.literal(THREE_QUARTER_TURN)
|
|
409
|
+
]).optional(),
|
|
665
410
|
crop: z.object({
|
|
666
411
|
x: ratio,
|
|
667
412
|
y: ratio,
|
|
668
413
|
width: ratio,
|
|
669
414
|
height: ratio
|
|
670
|
-
}).optional()
|
|
415
|
+
}).optional(),
|
|
416
|
+
transform: canvasImageTransformSchema.optional(),
|
|
417
|
+
adjustments: canvasImageAdjustmentsSchema.optional()
|
|
418
|
+
}).refine((paint) => paint.crop === void 0 || paint.transform === void 0, {
|
|
419
|
+
message: "image paint cannot have both a crop rectangle and an affine transform",
|
|
420
|
+
path: ["transform"]
|
|
671
421
|
})
|
|
672
422
|
]);
|
|
673
423
|
const canvasCornerRadiusSchema = z.object({
|
|
@@ -690,12 +440,7 @@ const canvasBorderSchema = z.object({
|
|
|
690
440
|
"dashed",
|
|
691
441
|
"dotted"
|
|
692
442
|
]),
|
|
693
|
-
paint: canvasPaintSchema
|
|
694
|
-
alignment: z.enum([
|
|
695
|
-
"inside",
|
|
696
|
-
"center",
|
|
697
|
-
"outside"
|
|
698
|
-
])
|
|
443
|
+
paint: canvasPaintSchema
|
|
699
444
|
});
|
|
700
445
|
const canvasOutlineSchema = z.object({
|
|
701
446
|
visible: z.boolean(),
|
|
@@ -827,38 +572,70 @@ const canvasAppearancePatchSchema = z.object({
|
|
|
827
572
|
//#region ../../packages/contract/src/canvas/canvas-content-styles.schema.ts
|
|
828
573
|
const MAX_CANVAS_FONT_FAMILIES = 20;
|
|
829
574
|
const MAX_CANVAS_FONT_WEIGHT = 1e3;
|
|
575
|
+
const MAX_FONT_AXES = 64;
|
|
576
|
+
const MAX_CANVAS_LIST_LEVEL = 16;
|
|
577
|
+
const MAX_FONT_FEATURES = 128;
|
|
578
|
+
const MAX_FONT_FEATURE_VALUE = 65535;
|
|
830
579
|
const MAX_ITEM_ID_LENGTH = 200;
|
|
831
580
|
const MAX_CANVAS_FONT_FAMILY_LENGTH = 500;
|
|
832
581
|
const MAX_CANVAS_ADDITIONAL_STYLE_VALUE_LENGTH = 1e4;
|
|
833
582
|
const MAX_CANVAS_ADDITIONAL_STYLES = 128;
|
|
834
583
|
const boundedNumber = z.number().min(-MAX_CANVAS_VALUE).max(MAX_CANVAS_VALUE);
|
|
835
584
|
const nonNegativeNumber = z.number().nonnegative().max(MAX_CANVAS_VALUE);
|
|
585
|
+
const fontFeatureTag = z.string().regex(/^[\u{20}-\u{7E}]{4}$/u);
|
|
586
|
+
const fontAxisTag = fontFeatureTag.refine((tag) => !["wght", "opsz"].includes(tag));
|
|
836
587
|
const canvasTypographySchema = z.object({
|
|
837
588
|
family: z.string().min(1).max(500),
|
|
838
589
|
fallbackFamilies: z.array(z.string().min(1).max(500)).max(20),
|
|
839
590
|
size: nonNegativeNumber,
|
|
840
|
-
weight: z.number().
|
|
591
|
+
weight: z.number().min(1).max(MAX_CANVAS_FONT_WEIGHT),
|
|
592
|
+
variations: z.record(fontAxisTag, boundedNumber).refine((axes) => Object.keys(axes).length <= MAX_FONT_AXES).optional(),
|
|
593
|
+
features: z.record(fontFeatureTag, z.number().int().nonnegative().max(MAX_FONT_FEATURE_VALUE)).refine((features) => Object.keys(features).length <= MAX_FONT_FEATURES).optional(),
|
|
594
|
+
opticalSize: z.discriminatedUnion("mode", [
|
|
595
|
+
z.object({ mode: z.literal("auto") }),
|
|
596
|
+
z.object({ mode: z.literal("font-default") }),
|
|
597
|
+
z.object({
|
|
598
|
+
mode: z.literal("fixed"),
|
|
599
|
+
value: boundedNumber
|
|
600
|
+
})
|
|
601
|
+
]).optional(),
|
|
841
602
|
style: z.enum([
|
|
842
603
|
"normal",
|
|
843
604
|
"italic",
|
|
844
605
|
"oblique"
|
|
845
606
|
]),
|
|
846
|
-
lineHeight: z.discriminatedUnion("mode", [
|
|
847
|
-
mode: z.literal("
|
|
848
|
-
|
|
607
|
+
lineHeight: z.discriminatedUnion("mode", [
|
|
608
|
+
z.object({ mode: z.literal("normal") }),
|
|
609
|
+
z.object({
|
|
610
|
+
mode: z.literal("fixed"),
|
|
611
|
+
value: nonNegativeNumber
|
|
612
|
+
}),
|
|
613
|
+
z.object({
|
|
614
|
+
mode: z.literal("percent"),
|
|
615
|
+
value: nonNegativeNumber
|
|
616
|
+
})
|
|
617
|
+
]),
|
|
618
|
+
letterSpacing: z.union([boundedNumber, z.object({
|
|
619
|
+
mode: z.literal("percent"),
|
|
620
|
+
value: boundedNumber
|
|
849
621
|
})]),
|
|
850
|
-
letterSpacing: boundedNumber,
|
|
851
622
|
align: z.enum([
|
|
852
623
|
"left",
|
|
853
624
|
"center",
|
|
854
625
|
"right",
|
|
855
626
|
"justify"
|
|
856
627
|
]),
|
|
628
|
+
direction: z.enum([
|
|
629
|
+
"auto",
|
|
630
|
+
"ltr",
|
|
631
|
+
"rtl"
|
|
632
|
+
]).optional(),
|
|
857
633
|
verticalAlign: z.enum([
|
|
858
634
|
"top",
|
|
859
635
|
"middle",
|
|
860
636
|
"bottom"
|
|
861
637
|
]),
|
|
638
|
+
verticalTrim: z.enum(["none", "cap-height"]).optional(),
|
|
862
639
|
transform: z.enum([
|
|
863
640
|
"none",
|
|
864
641
|
"uppercase",
|
|
@@ -879,11 +656,32 @@ const canvasTypographySchema = z.object({
|
|
|
879
656
|
"wavy"
|
|
880
657
|
]),
|
|
881
658
|
color: canvasColorSchema.optional(),
|
|
882
|
-
thickness:
|
|
659
|
+
thickness: z.union([
|
|
660
|
+
nonNegativeNumber,
|
|
661
|
+
z.object({
|
|
662
|
+
mode: z.literal("percent"),
|
|
663
|
+
value: nonNegativeNumber
|
|
664
|
+
}),
|
|
665
|
+
z.object({ mode: z.literal("font-default") })
|
|
666
|
+
]).optional(),
|
|
667
|
+
offset: z.union([boundedNumber, z.object({
|
|
668
|
+
mode: z.literal("percent"),
|
|
669
|
+
value: boundedNumber
|
|
670
|
+
})]).optional(),
|
|
671
|
+
skipInk: z.enum([
|
|
672
|
+
"auto",
|
|
673
|
+
"none",
|
|
674
|
+
"all"
|
|
675
|
+
]).optional()
|
|
883
676
|
}),
|
|
884
677
|
stroke: z.object({
|
|
885
678
|
width: nonNegativeNumber,
|
|
886
|
-
paint: canvasPaintSchema
|
|
679
|
+
paint: canvasPaintSchema,
|
|
680
|
+
alignment: z.enum([
|
|
681
|
+
"inside",
|
|
682
|
+
"center",
|
|
683
|
+
"outside"
|
|
684
|
+
]).optional()
|
|
887
685
|
}).optional(),
|
|
888
686
|
wrapping: z.enum([
|
|
889
687
|
"wrap",
|
|
@@ -893,6 +691,21 @@ const canvasTypographySchema = z.object({
|
|
|
893
691
|
"pre-wrap",
|
|
894
692
|
"break-spaces"
|
|
895
693
|
]),
|
|
694
|
+
wrapStyle: z.enum([
|
|
695
|
+
"auto",
|
|
696
|
+
"pretty",
|
|
697
|
+
"balance"
|
|
698
|
+
]).optional(),
|
|
699
|
+
paragraphSpacing: nonNegativeNumber.optional(),
|
|
700
|
+
paragraphIndent: nonNegativeNumber.optional(),
|
|
701
|
+
listStyle: z.enum([
|
|
702
|
+
"none",
|
|
703
|
+
"bulleted",
|
|
704
|
+
"numbered"
|
|
705
|
+
]).optional(),
|
|
706
|
+
listSpacing: nonNegativeNumber.optional(),
|
|
707
|
+
hangingList: z.boolean().optional(),
|
|
708
|
+
hangingPunctuation: z.boolean().optional(),
|
|
896
709
|
truncation: z.object({
|
|
897
710
|
mode: z.enum(["none", "ellipsis"]),
|
|
898
711
|
maxLines: z.number().int().min(1).max(MAX_CANVAS_VALUE).nullable()
|
|
@@ -904,6 +717,76 @@ const canvasTypographySchema = z.object({
|
|
|
904
717
|
left: boundedNumber
|
|
905
718
|
}).optional()
|
|
906
719
|
});
|
|
720
|
+
const canvasTextParagraphSchema = canvasTypographySchema.pick({
|
|
721
|
+
align: true,
|
|
722
|
+
direction: true,
|
|
723
|
+
wrapStyle: true,
|
|
724
|
+
paragraphSpacing: true,
|
|
725
|
+
paragraphIndent: true,
|
|
726
|
+
listStyle: true,
|
|
727
|
+
listSpacing: true,
|
|
728
|
+
hangingList: true
|
|
729
|
+
}).partial().extend({
|
|
730
|
+
listLevel: z.number().int().min(1).max(16).optional(),
|
|
731
|
+
listStart: z.number().int().min(1).max(MAX_CANVAS_VALUE).optional()
|
|
732
|
+
}).strict();
|
|
733
|
+
const canvasAuthoredTypographySchema = canvasTypographySchema.partial().strict();
|
|
734
|
+
const CANVAS_TYPOGRAPHY_PROPERTIES = canvasTypographySchema.keyof().options;
|
|
735
|
+
const canvasTypographyPatchSchema = canvasAuthoredTypographySchema.extend({
|
|
736
|
+
featureChanges: z.object({
|
|
737
|
+
set: canvasTypographySchema.shape.features,
|
|
738
|
+
clear: z.array(fontFeatureTag).max(MAX_FONT_FEATURES).optional(),
|
|
739
|
+
removeIfEmpty: z.boolean().optional()
|
|
740
|
+
}).strict().optional(),
|
|
741
|
+
variationChanges: z.object({
|
|
742
|
+
set: canvasTypographySchema.shape.variations,
|
|
743
|
+
clear: z.array(fontAxisTag).max(MAX_FONT_AXES).optional(),
|
|
744
|
+
removeIfEmpty: z.boolean().optional()
|
|
745
|
+
}).strict().optional(),
|
|
746
|
+
clear: z.array(canvasTypographySchema.keyof()).max(CANVAS_TYPOGRAPHY_PROPERTIES.length).optional()
|
|
747
|
+
}).refine((patch) => patch.clear?.every((property) => patch[property] === void 0) ?? true, "a typography property cannot be set and cleared in the same patch").refine((patch) => ["features", "variations"].every((property) => {
|
|
748
|
+
const change = patch[property === "features" ? "featureChanges" : "variationChanges"];
|
|
749
|
+
return change === void 0 || patch[property] === void 0 && patch.clear?.includes(property) !== true && (change.clear?.every((tag) => change.set?.[tag] === void 0) ?? true);
|
|
750
|
+
}), "font settings cannot be replaced and patched, or set and cleared, together");
|
|
751
|
+
const CANVAS_TYPOGRAPHY_CSS_OWNERS = {
|
|
752
|
+
"font-family": ["family", "fallbackFamilies"],
|
|
753
|
+
"font-size": ["size"],
|
|
754
|
+
"font-weight": ["weight"],
|
|
755
|
+
"font-variation-settings": [
|
|
756
|
+
"weight",
|
|
757
|
+
"variations",
|
|
758
|
+
"opticalSize"
|
|
759
|
+
],
|
|
760
|
+
"font-optical-sizing": ["opticalSize"],
|
|
761
|
+
"font-feature-settings": ["features"],
|
|
762
|
+
"font-style": ["style"],
|
|
763
|
+
"line-height": ["lineHeight"],
|
|
764
|
+
"letter-spacing": ["letterSpacing"],
|
|
765
|
+
"text-align": ["align"],
|
|
766
|
+
direction: ["direction"],
|
|
767
|
+
"unicode-bidi": ["direction"],
|
|
768
|
+
"text-indent": ["paragraphIndent"],
|
|
769
|
+
"hanging-punctuation": ["hangingPunctuation"],
|
|
770
|
+
"align-content": ["verticalAlign"],
|
|
771
|
+
"text-box": ["verticalTrim"],
|
|
772
|
+
"text-box-trim": ["verticalTrim"],
|
|
773
|
+
"text-box-edge": ["verticalTrim"],
|
|
774
|
+
"text-transform": ["transform"],
|
|
775
|
+
"text-decoration": ["decoration"],
|
|
776
|
+
"text-decoration-line": ["decoration"],
|
|
777
|
+
"text-decoration-style": ["decoration"],
|
|
778
|
+
"text-decoration-color": ["decoration"],
|
|
779
|
+
"text-decoration-thickness": ["decoration"],
|
|
780
|
+
"text-underline-offset": ["decoration"],
|
|
781
|
+
"text-decoration-skip-ink": ["decoration"],
|
|
782
|
+
"-webkit-text-stroke": ["stroke"],
|
|
783
|
+
"-webkit-text-stroke-width": ["stroke"],
|
|
784
|
+
"-webkit-text-stroke-color": ["stroke"],
|
|
785
|
+
"--canvas-text-stroke-alignment": ["stroke"],
|
|
786
|
+
"white-space": ["wrapping"],
|
|
787
|
+
"text-wrap-style": ["wrapStyle"],
|
|
788
|
+
"text-wrap": ["wrapStyle"]
|
|
789
|
+
};
|
|
907
790
|
const unsafeStyleValue = /javascript|vbscript|data\s*:\s*text\/html|expression\s*\(|@import/iu;
|
|
908
791
|
const blockedStyleProperty = /^(?:behavior|-moz-binding)$/iu;
|
|
909
792
|
const canvasAdditionalStylePropertySchema = z.string().min(1).max(MAX_ITEM_ID_LENGTH).regex(/^(?:--[\w-]+|-(?:webkit|moz|ms|o)-[a-z][a-z\d-]*|[a-z][a-z\d-]*)$/iu).refine((property) => !blockedStyleProperty.test(property), "unsafe CSS property");
|
|
@@ -917,165 +800,571 @@ const canvasAdditionalStyleSchema = z.object({
|
|
|
917
800
|
const canvasAdditionalStylesSchema = z.object({ declarations: z.array(canvasAdditionalStyleSchema).max(128) }).refine(({ declarations }) => new Set(declarations.map((declaration) => declaration.id)).size === declarations.length, "additional style ids must be unique");
|
|
918
801
|
|
|
919
802
|
//#endregion
|
|
920
|
-
//#region ../../packages/contract/src/canvas/canvas-
|
|
921
|
-
const
|
|
922
|
-
const
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
"
|
|
935
|
-
"
|
|
936
|
-
"
|
|
937
|
-
"
|
|
938
|
-
"
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
"
|
|
946
|
-
"
|
|
947
|
-
"
|
|
803
|
+
//#region ../../packages/contract/src/canvas/canvas-additional-style-patch.schema.ts
|
|
804
|
+
const identifiers = z.array(canvasAdditionalStyleSchema.shape.id).max(128).refine((ids) => new Set(ids).size === ids.length, "declaration ids must be unique");
|
|
805
|
+
const canvasAdditionalStylePatchSchema = z.object({
|
|
806
|
+
set: z.array(canvasAdditionalStyleSchema).max(128).refine((items) => new Set(items.map((item) => item.id)).size === items.length, "declaration ids must be unique").optional(),
|
|
807
|
+
clear: identifiers.optional(),
|
|
808
|
+
order: identifiers.optional(),
|
|
809
|
+
empty: z.enum(["keep", "remove"]).optional()
|
|
810
|
+
}).strict().refine((patch) => patch.set?.every((item) => patch.clear?.includes(item.id) !== true) ?? true, "a declaration cannot be set and cleared in the same patch");
|
|
811
|
+
|
|
812
|
+
//#endregion
|
|
813
|
+
//#region ../../packages/contract/src/canvas/canvas-css-values.lib.ts
|
|
814
|
+
const UNITLESS_PROPERTIES = /* @__PURE__ */ new Set([
|
|
815
|
+
"aspect-ratio",
|
|
816
|
+
"-webkit-line-clamp",
|
|
817
|
+
"line-clamp",
|
|
818
|
+
"flex-grow",
|
|
819
|
+
"flex-shrink",
|
|
820
|
+
"font-weight",
|
|
821
|
+
"opacity",
|
|
822
|
+
"order",
|
|
823
|
+
"z-index",
|
|
824
|
+
"grid-area",
|
|
825
|
+
"grid-row",
|
|
826
|
+
"grid-column",
|
|
827
|
+
"grid-row-start",
|
|
828
|
+
"grid-row-end",
|
|
829
|
+
"grid-column-start",
|
|
830
|
+
"grid-column-end"
|
|
948
831
|
]);
|
|
949
|
-
const
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
})
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
832
|
+
const canvasCssValue = (property, value) => typeof value === "number" && !UNITLESS_PROPERTIES.has(property.toLowerCase()) ? `${String(value)}px` : String(value);
|
|
833
|
+
const SIDES$1 = [
|
|
834
|
+
"top",
|
|
835
|
+
"right",
|
|
836
|
+
"bottom",
|
|
837
|
+
"left"
|
|
838
|
+
];
|
|
839
|
+
const LEFT_SIDE_INDEX = 3;
|
|
840
|
+
const GRID_TEMPLATE_PROPERTIES = [
|
|
841
|
+
"grid-template-rows",
|
|
842
|
+
"grid-template-columns",
|
|
843
|
+
"grid-template-areas"
|
|
844
|
+
];
|
|
845
|
+
const SHORTHANDS = {
|
|
846
|
+
gap: ["row-gap", "column-gap"],
|
|
847
|
+
"text-wrap": ["text-wrap-mode", "text-wrap-style"],
|
|
848
|
+
padding: SIDES$1.map((side) => `padding-${side}`),
|
|
849
|
+
margin: SIDES$1.map((side) => `margin-${side}`),
|
|
850
|
+
flex: [
|
|
851
|
+
"flex-grow",
|
|
852
|
+
"flex-shrink",
|
|
853
|
+
"flex-basis"
|
|
854
|
+
],
|
|
855
|
+
"flex-flow": ["flex-direction", "flex-wrap"],
|
|
856
|
+
"place-content": ["align-content", "justify-content"],
|
|
857
|
+
"place-items": ["align-items", "justify-items"],
|
|
858
|
+
"place-self": ["align-self", "justify-self"],
|
|
859
|
+
"grid-template": GRID_TEMPLATE_PROPERTIES,
|
|
860
|
+
grid: [
|
|
861
|
+
...GRID_TEMPLATE_PROPERTIES,
|
|
862
|
+
"grid-auto-rows",
|
|
863
|
+
"grid-auto-columns",
|
|
864
|
+
"grid-auto-flow"
|
|
865
|
+
],
|
|
866
|
+
"grid-row": ["grid-row-start", "grid-row-end"],
|
|
867
|
+
"grid-column": ["grid-column-start", "grid-column-end"],
|
|
868
|
+
"grid-area": [
|
|
869
|
+
"grid-row-start",
|
|
870
|
+
"grid-column-start",
|
|
871
|
+
"grid-row-end",
|
|
872
|
+
"grid-column-end"
|
|
873
|
+
]
|
|
874
|
+
};
|
|
875
|
+
/** Related declarations stay authored; a longhand edit must not discard the rest of a shorthand. */
|
|
876
|
+
const canvasCssPropertyScope = (property) => SHORTHANDS[property.toLowerCase()] ?? [property.toLowerCase()];
|
|
877
|
+
const componentStateAfter = (state, character) => {
|
|
878
|
+
if (state.isEscaped) return {
|
|
879
|
+
...state,
|
|
880
|
+
isEscaped: false
|
|
881
|
+
};
|
|
882
|
+
if (character === "\\") return {
|
|
883
|
+
...state,
|
|
884
|
+
isEscaped: true
|
|
885
|
+
};
|
|
886
|
+
if (state.quote !== "") return {
|
|
887
|
+
...state,
|
|
888
|
+
quote: state.quote === character ? "" : state.quote
|
|
889
|
+
};
|
|
890
|
+
if (["\"", "'"].includes(character)) return {
|
|
891
|
+
...state,
|
|
892
|
+
quote: character
|
|
893
|
+
};
|
|
894
|
+
const delta = [
|
|
895
|
+
"(",
|
|
896
|
+
"[",
|
|
897
|
+
"{"
|
|
898
|
+
].includes(character) ? 1 : [
|
|
899
|
+
")",
|
|
900
|
+
"]",
|
|
901
|
+
"}"
|
|
902
|
+
].includes(character) ? -1 : 0;
|
|
986
903
|
return {
|
|
987
|
-
...
|
|
988
|
-
|
|
904
|
+
...state,
|
|
905
|
+
depth: state.depth + delta
|
|
989
906
|
};
|
|
990
907
|
};
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
const
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
908
|
+
/** Split only at CSS component boundaries, keeping functions, line names and strings intact. */
|
|
909
|
+
const canvasCssTokens = (value, separator = "space") => {
|
|
910
|
+
const tokens = [];
|
|
911
|
+
let token = "";
|
|
912
|
+
let state = {
|
|
913
|
+
depth: 0,
|
|
914
|
+
quote: "",
|
|
915
|
+
isEscaped: false
|
|
999
916
|
};
|
|
917
|
+
for (const character of value) {
|
|
918
|
+
const canSplit = state.depth === 0 && state.quote === "" && !state.isEscaped;
|
|
919
|
+
state = componentStateAfter(state, character);
|
|
920
|
+
if (canSplit && (separator === "space" ? /\s/u.test(character) : character === separator)) {
|
|
921
|
+
if (separator !== "space" || token !== "") tokens.push(token.trim());
|
|
922
|
+
token = "";
|
|
923
|
+
} else token += character;
|
|
924
|
+
}
|
|
925
|
+
if (separator !== "space" || token !== "") tokens.push(token.trim());
|
|
926
|
+
return tokens;
|
|
927
|
+
};
|
|
928
|
+
const omittedGridLine = (value) => /^(?:--|-?[_a-z\u{80}-\u{FFFF}])[-\w\u{80}-\u{FFFF}]*$/iu.test(value) && !/^(?:auto|span|initial|unset)$/iu.test(value) ? value : "auto";
|
|
929
|
+
const gridPlacementValue = (property, value, index) => {
|
|
930
|
+
const parts = canvasCssTokens(value, "/");
|
|
931
|
+
const first = parts[0] ?? value;
|
|
932
|
+
if (property !== "grid-area") return parts[index] ?? omittedGridLine(first);
|
|
933
|
+
const column = parts[1] ?? omittedGridLine(first);
|
|
934
|
+
return [
|
|
935
|
+
first,
|
|
936
|
+
column,
|
|
937
|
+
parts[2] ?? omittedGridLine(first),
|
|
938
|
+
parts[3] ?? omittedGridLine(column)
|
|
939
|
+
][index] ?? value;
|
|
940
|
+
};
|
|
941
|
+
const implicitGridValues = (row, column, hasAutoRows) => {
|
|
942
|
+
const tokens = canvasCssTokens(hasAutoRows ? row : column);
|
|
943
|
+
const size = tokens.filter((token) => !/^(?:auto-flow|dense)$/iu.test(token)).join(" ");
|
|
944
|
+
const flow = `${hasAutoRows ? "row" : "column"}${tokens.some((token) => /^dense$/iu.test(token)) ? " dense" : ""}`;
|
|
945
|
+
return [
|
|
946
|
+
hasAutoRows ? "none" : row,
|
|
947
|
+
hasAutoRows ? column : "none",
|
|
948
|
+
"none",
|
|
949
|
+
hasAutoRows && size !== "" ? size : "auto",
|
|
950
|
+
!hasAutoRows && size !== "" ? size : "auto",
|
|
951
|
+
flow
|
|
952
|
+
];
|
|
953
|
+
};
|
|
954
|
+
const gridTemplateValue = (property, value, index) => {
|
|
955
|
+
if (/^(?:none|initial|unset)$/iu.test(value)) return [
|
|
956
|
+
"none",
|
|
957
|
+
"none",
|
|
958
|
+
"none",
|
|
959
|
+
"auto",
|
|
960
|
+
"auto",
|
|
961
|
+
"row"
|
|
962
|
+
][index] ?? value;
|
|
963
|
+
const parts = canvasCssTokens(value, "/");
|
|
964
|
+
const row = parts[0] ?? value;
|
|
965
|
+
const column = parts[1];
|
|
966
|
+
if (row === "" || column === "" || parts.length > 2) return value;
|
|
967
|
+
const hasAutoRows = canvasCssTokens(row).some((token) => token.toLowerCase() === "auto-flow");
|
|
968
|
+
const hasAutoColumns = column !== void 0 && canvasCssTokens(column).some((token) => token.toLowerCase() === "auto-flow");
|
|
969
|
+
if (property === "grid" && column !== void 0 && hasAutoRows !== hasAutoColumns) return implicitGridValues(row, column, hasAutoRows)[index] ?? value;
|
|
970
|
+
if (hasAutoRows || hasAutoColumns) return value;
|
|
971
|
+
const hasAreas = /["']/u.test(row);
|
|
972
|
+
if (column === void 0 && !hasAreas) return value;
|
|
973
|
+
return [
|
|
974
|
+
hasAreas ? value : row,
|
|
975
|
+
column ?? "none",
|
|
976
|
+
hasAreas ? row : "none",
|
|
977
|
+
"auto",
|
|
978
|
+
"auto",
|
|
979
|
+
"row"
|
|
980
|
+
][index] ?? value;
|
|
981
|
+
};
|
|
982
|
+
const flexValues = (tokens) => {
|
|
983
|
+
const numbers = [];
|
|
984
|
+
let basis = "0%";
|
|
985
|
+
for (const token of tokens) if (/^(?:\d+(?:\.\d*)?|\.\d+)$/u.test(token) && numbers.length < 2) numbers.push(token);
|
|
986
|
+
else basis = token;
|
|
987
|
+
return [
|
|
988
|
+
numbers[0] ?? "1",
|
|
989
|
+
numbers[1] ?? "1",
|
|
990
|
+
basis
|
|
991
|
+
];
|
|
992
|
+
};
|
|
993
|
+
const canvasCssShorthandValue = (property, value, index) => {
|
|
994
|
+
if (/(?:var|env)\(|^(?:inherit|revert(?:-layer)?)$/iu.test(value)) return value;
|
|
995
|
+
if (/^grid-(?:area|row|column)$/u.test(property)) return gridPlacementValue(property, value, index);
|
|
996
|
+
if (property === "grid-template" || property === "grid") return gridTemplateValue(property, value, index);
|
|
997
|
+
const tokens = canvasCssTokens(value);
|
|
998
|
+
if (property === "text-wrap") return index === 0 ? tokens.find((token) => /^(?:wrap|nowrap)$/u.test(token)) ?? "wrap" : tokens.find((token) => /^(?:auto|balance|pretty|stable)$/u.test(token)) ?? "auto";
|
|
999
|
+
if (property === "flex-flow") return index === 0 ? tokens.find((token) => /^(?:row|column)(?:-reverse)?$/u.test(token)) ?? "row" : tokens.find((token) => /^(?:nowrap|wrap|wrap-reverse)$/u.test(token)) ?? "nowrap";
|
|
1000
|
+
if (property === "flex") {
|
|
1001
|
+
if (value === "none") return [
|
|
1002
|
+
"0",
|
|
1003
|
+
"0",
|
|
1004
|
+
"auto"
|
|
1005
|
+
][index] ?? value;
|
|
1006
|
+
if (value === "initial") return [
|
|
1007
|
+
"0",
|
|
1008
|
+
"1",
|
|
1009
|
+
"auto"
|
|
1010
|
+
][index] ?? value;
|
|
1011
|
+
return flexValues(tokens)[index] ?? value;
|
|
1012
|
+
}
|
|
1013
|
+
return tokens[index] ?? (index === LEFT_SIDE_INDEX ? tokens[1] : void 0) ?? tokens[0] ?? value;
|
|
1000
1014
|
};
|
|
1001
|
-
/** Known old scenes are adapted in memory; only an explicit mutation persists the new format. */
|
|
1002
|
-
const canvasReadableSceneDocumentSchema = z.preprocess((value) => {
|
|
1003
|
-
const blob = legacyRecordSchema.safeParse(value).data;
|
|
1004
|
-
if (blob === void 0) return value;
|
|
1005
|
-
const version = blob["version"];
|
|
1006
|
-
return (/* @__PURE__ */ new Set([
|
|
1007
|
-
void 0,
|
|
1008
|
-
1,
|
|
1009
|
-
2
|
|
1010
|
-
])).has(version) ? legacyDocument(blob) : blob;
|
|
1011
|
-
}, canvasSceneDocumentSchema);
|
|
1012
|
-
const emptyCanvasSceneDocument = () => ({
|
|
1013
|
-
version: 3,
|
|
1014
|
-
nodes: { root: {
|
|
1015
|
-
id: "root",
|
|
1016
|
-
label: "Canvas",
|
|
1017
|
-
component: "root",
|
|
1018
|
-
labelOrigin: "generated",
|
|
1019
|
-
visible: true,
|
|
1020
|
-
locked: false,
|
|
1021
|
-
styles: {}
|
|
1022
|
-
} },
|
|
1023
|
-
relationships: {},
|
|
1024
|
-
tombstones: {}
|
|
1025
|
-
});
|
|
1026
1015
|
|
|
1027
1016
|
//#endregion
|
|
1028
|
-
//#region ../../packages/contract/src/canvas/canvas-
|
|
1029
|
-
const
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
const
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1017
|
+
//#region ../../packages/contract/src/canvas/canvas-authored-css.lib.ts
|
|
1018
|
+
const canvasAdditionalStyleDeclarations = (node) => {
|
|
1019
|
+
if (node.additionalStyles === void 0) return {};
|
|
1020
|
+
return Object.fromEntries(node.additionalStyles.declarations.filter((declaration) => declaration.enabled).map((declaration) => [declaration.property, declaration.value]));
|
|
1021
|
+
};
|
|
1022
|
+
/** Additional-style controls exclusively own every property they expose, including when off. */
|
|
1023
|
+
const canvasAuthoredStyleDeclarations = (node) => {
|
|
1024
|
+
const controlledProperties = new Set(node.additionalStyles?.declarations.map((declaration) => declaration.property.toLowerCase()));
|
|
1025
|
+
return {
|
|
1026
|
+
...Object.fromEntries(Object.entries(node.styles).filter(([property]) => !controlledProperties.has(property.toLowerCase()))),
|
|
1027
|
+
...canvasAdditionalStyleDeclarations(node)
|
|
1028
|
+
};
|
|
1029
|
+
};
|
|
1030
|
+
const hasCanvasCssPriority = (value) => /!important\s*$/iu.test(String(value));
|
|
1031
|
+
const cssValue = (value, shouldPreserveCase) => {
|
|
1032
|
+
const source = String(value).replace(/\s*!important\s*$/iu, "").trim();
|
|
1033
|
+
return shouldPreserveCase || source.includes("(") ? source : source.toLowerCase();
|
|
1034
|
+
};
|
|
1035
|
+
/** Read supported authored longhands without measuring or rewriting unresolved CSS expressions. */
|
|
1036
|
+
const canvasAuthoredLayoutValueOf = (node, property) => {
|
|
1037
|
+
let result = null;
|
|
1038
|
+
let isImportant = false;
|
|
1039
|
+
const declarations = Object.entries(canvasAuthoredStyleDeclarations(node));
|
|
1040
|
+
for (const [key, raw] of declarations) {
|
|
1041
|
+
const scope = canvasCssPropertyScope(key);
|
|
1042
|
+
const index = scope.indexOf(property);
|
|
1043
|
+
if (index === -1) continue;
|
|
1044
|
+
const isPriority = hasCanvasCssPriority(raw);
|
|
1045
|
+
if (isImportant && !isPriority) continue;
|
|
1046
|
+
const value = cssValue(raw, /^grid(?:-|$)/iu.test(key));
|
|
1047
|
+
result = scope.length === 1 ? value : canvasCssShorthandValue(key.toLowerCase(), value, index);
|
|
1048
|
+
isImportant = isPriority;
|
|
1049
|
+
}
|
|
1050
|
+
return result ?? void 0;
|
|
1051
|
+
};
|
|
1052
|
+
/** Named controls override only their own longhand, even beside an important shorthand. */
|
|
1053
|
+
const canvasLayoutPriorityDeclarations = (node, declarations) => {
|
|
1054
|
+
const important = new Set(Object.entries(canvasAuthoredStyleDeclarations(node)).filter(([, value]) => hasCanvasCssPriority(value)).flatMap(([property]) => canvasCssPropertyScope(property)));
|
|
1055
|
+
return Object.fromEntries(Object.entries(declarations).map(([property, value]) => [property, canvasCssPropertyScope(property).some((owned) => important.has(owned)) && !hasCanvasCssPriority(value) ? `${canvasCssValue(property, value)} !important` : value]));
|
|
1056
|
+
};
|
|
1057
|
+
const canvasWritingModeOf = (node, document) => {
|
|
1058
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1059
|
+
let current = node;
|
|
1060
|
+
while (current !== void 0 && !visited.has(current.id)) {
|
|
1061
|
+
visited.add(current.id);
|
|
1062
|
+
const value = canvasAuthoredLayoutValueOf(current, "writing-mode");
|
|
1063
|
+
if (value !== void 0 && value !== "inherit" && value !== "unset") return value;
|
|
1064
|
+
if (document === void 0) break;
|
|
1065
|
+
const parentId = document.relationships[current.id]?.parentId;
|
|
1066
|
+
if (parentId === void 0) break;
|
|
1067
|
+
current = document.nodes[parentId];
|
|
1068
|
+
}
|
|
1069
|
+
return "horizontal-tb";
|
|
1070
|
+
};
|
|
1071
|
+
const canvasAxisStyleProperties = (node, axis, document) => {
|
|
1072
|
+
const isVerticalWriting = /^(?:vertical|sideways)-/u.test(canvasWritingModeOf(node, document));
|
|
1073
|
+
return [axis === "horizontal" ? "width" : "height", axis === "vertical" === isVerticalWriting ? "inline-size" : "block-size"];
|
|
1074
|
+
};
|
|
1075
|
+
/** Authored display wins over legacy presets; Grid has no Flex main axis. */
|
|
1076
|
+
const canvasLayoutFlowOf = (node) => {
|
|
1077
|
+
if (node === void 0) return "freeform";
|
|
1078
|
+
const display = canvasAuthoredLayoutValueOf(node, "display");
|
|
1079
|
+
if (display !== void 0) {
|
|
1080
|
+
if (/^(?:(?:inline|block)\s+|inline-)?grid$/u.test(display)) return "grid";
|
|
1081
|
+
if (/^(?:(?:inline|block)\s+|inline-)?flex$/u.test(display)) return "flex";
|
|
1082
|
+
return "freeform";
|
|
1083
|
+
}
|
|
1084
|
+
const container = node.layout?.container;
|
|
1085
|
+
if (container === void 0) return "freeform";
|
|
1086
|
+
return container.gridColumns !== void 0 || container.gridAutoRepeat !== void 0 ? "grid" : "flex";
|
|
1087
|
+
};
|
|
1088
|
+
/** Read a Flex main axis in its inherited writing mode without persisting a preset. */
|
|
1089
|
+
const canvasLayoutMainAxisOf = (node, document) => {
|
|
1090
|
+
if (node === void 0) return void 0;
|
|
1091
|
+
if (canvasLayoutFlowOf(node) !== "flex") return void 0;
|
|
1092
|
+
const container = node.layout?.container;
|
|
1093
|
+
const css = (property) => canvasAuthoredLayoutValueOf(node, property);
|
|
1094
|
+
const direction = container?.direction ?? css("flex-direction") ?? "row";
|
|
1095
|
+
if (!/^(?:row|column)(?:-reverse)?$/u.test(direction)) return void 0;
|
|
1096
|
+
const isVerticalWriting = /^(?:vertical|sideways)-/u.test(canvasWritingModeOf(node, document));
|
|
1097
|
+
return direction.startsWith("column") === isVerticalWriting ? "horizontal" : "vertical";
|
|
1098
|
+
};
|
|
1099
|
+
|
|
1100
|
+
//#endregion
|
|
1101
|
+
//#region ../../packages/contract/src/canvas/canvas-text-style.schema.ts
|
|
1102
|
+
const MAX_STYLE_ID = 200;
|
|
1103
|
+
const MAX_DESCRIPTION$1 = 2e3;
|
|
1104
|
+
const MAX_OVERRIDE_VALUE = 1e3;
|
|
1105
|
+
const canvasTextStyleTypographySchema = canvasTypographySchema.pick({
|
|
1106
|
+
family: true,
|
|
1107
|
+
fallbackFamilies: true,
|
|
1108
|
+
size: true,
|
|
1109
|
+
weight: true,
|
|
1110
|
+
style: true,
|
|
1111
|
+
variations: true,
|
|
1112
|
+
opticalSize: true,
|
|
1113
|
+
features: true,
|
|
1114
|
+
lineHeight: true,
|
|
1115
|
+
letterSpacing: true,
|
|
1116
|
+
transform: true,
|
|
1117
|
+
decoration: true,
|
|
1118
|
+
paragraphSpacing: true,
|
|
1119
|
+
paragraphIndent: true,
|
|
1120
|
+
listSpacing: true,
|
|
1121
|
+
hangingList: true,
|
|
1122
|
+
hangingPunctuation: true,
|
|
1123
|
+
verticalTrim: true,
|
|
1124
|
+
wrapStyle: true
|
|
1125
|
+
}).strict();
|
|
1126
|
+
const CANVAS_TEXT_STYLE_PROPERTIES = canvasTextStyleTypographySchema.keyof().options;
|
|
1127
|
+
const canvasTextStyleSchema = z.object({
|
|
1128
|
+
id: z.string().min(1).max(MAX_STYLE_ID),
|
|
1129
|
+
name: z.string().trim().min(1).max(MAX_STYLE_ID),
|
|
1130
|
+
description: z.string().max(MAX_DESCRIPTION$1),
|
|
1131
|
+
sortKey: z.string().min(1).max(MAX_STYLE_ID).optional(),
|
|
1132
|
+
sourceStyleId: z.string().min(1).max(MAX_STYLE_ID).optional(),
|
|
1133
|
+
sourceCanvasId: z.uuid().optional(),
|
|
1134
|
+
sourceRevision: z.number().int().positive().optional(),
|
|
1135
|
+
typography: canvasTextStyleTypographySchema.extend({ listStyle: canvasTypographySchema.shape.listStyle }).transform((typography) => {
|
|
1136
|
+
Reflect.deleteProperty(typography, "listStyle");
|
|
1137
|
+
return typography;
|
|
1138
|
+
})
|
|
1139
|
+
}).strict().refine((style) => style.sourceCanvasId === void 0 || style.sourceStyleId !== void 0, {
|
|
1140
|
+
message: "A source canvas belongs to a reference snapshot.",
|
|
1141
|
+
path: ["sourceCanvasId"]
|
|
1142
|
+
}).refine((style) => style.sourceRevision === void 0 || style.sourceCanvasId !== void 0 && style.sourceStyleId !== void 0, {
|
|
1143
|
+
message: "A published revision belongs to a source style and canvas.",
|
|
1144
|
+
path: ["sourceRevision"]
|
|
1145
|
+
});
|
|
1146
|
+
const canvasTextStyleBindingSchema = z.object({
|
|
1147
|
+
id: canvasTextStyleSchema.shape.id,
|
|
1148
|
+
position: z.enum([
|
|
1149
|
+
"normal",
|
|
1150
|
+
"subscript",
|
|
1151
|
+
"superscript"
|
|
1152
|
+
]).optional(),
|
|
1153
|
+
overrides: z.partialRecord(z.enum([
|
|
1154
|
+
"fontWeight",
|
|
1155
|
+
"fontStyle",
|
|
1156
|
+
"fontVariationSettings",
|
|
1157
|
+
"fontOpticalSizing",
|
|
1158
|
+
"textDecorationLine",
|
|
1159
|
+
"textDecorationStyle",
|
|
1160
|
+
"textDecorationColor",
|
|
1161
|
+
"textDecorationThickness",
|
|
1162
|
+
"textUnderlineOffset",
|
|
1163
|
+
"textDecorationSkipInk"
|
|
1164
|
+
]), z.union([z.string().max(MAX_OVERRIDE_VALUE), z.number()])).optional()
|
|
1165
|
+
}).strict();
|
|
1166
|
+
|
|
1167
|
+
//#endregion
|
|
1168
|
+
//#region ../../packages/contract/src/canvas/canvas-rich-text.lib.ts
|
|
1169
|
+
const fillsSchema = canvasPaintSchema.array().max(32).optional();
|
|
1170
|
+
const characterFormattingSchema = canvasTextParagraphSchema.pick({
|
|
1171
|
+
paragraphSpacing: true,
|
|
1172
|
+
paragraphIndent: true,
|
|
1173
|
+
listSpacing: true,
|
|
1174
|
+
wrapStyle: true
|
|
1175
|
+
}).extend({
|
|
1176
|
+
hangingPunctuation: canvasTypographySchema.shape.hangingPunctuation,
|
|
1177
|
+
verticalTrim: canvasTypographySchema.shape.verticalTrim
|
|
1178
|
+
}).strip();
|
|
1179
|
+
|
|
1180
|
+
//#endregion
|
|
1181
|
+
//#region ../../packages/contract/src/canvas/canvas-scene.schema.ts
|
|
1182
|
+
const COMPLETE_TYPOGRAPHY_FORMAT = 3;
|
|
1183
|
+
const LEGACY_CANVAS_FORMAT_4 = 4;
|
|
1184
|
+
const MAX_SCENE_NODE_ID_LENGTH = 200;
|
|
1185
|
+
const MAX_SCENE_LABEL_LENGTH = 500;
|
|
1186
|
+
const MAX_SCENE_COMPONENT_LENGTH = 100;
|
|
1187
|
+
const MAX_SCENE_SORT_KEY_LENGTH = 500;
|
|
1188
|
+
const CANVAS_SCENE_VERSION = 5;
|
|
1189
|
+
const canvasDocumentFormatSchema = z.literal(5, { error: "This editor uses an unsupported document format. Update the editor before changing this canvas." });
|
|
1190
|
+
const MAX_PRESERVED_FONT_APPEARANCE_BYTES = 2e6;
|
|
1191
|
+
const MAX_PRESERVED_FONT_FAMILY_LENGTH = 256;
|
|
1192
|
+
const MAX_PRESERVED_FONT_FAMILIES = 256;
|
|
1193
|
+
const canvasPreservedFontAppearanceSchema = z.object({
|
|
1194
|
+
signature: z.string().regex(/^[a-f0-9]{16}$/u),
|
|
1195
|
+
image: z.string().startsWith("data:image/jpeg;base64,").max(MAX_PRESERVED_FONT_APPEARANCE_BYTES),
|
|
1196
|
+
families: z.array(z.string().min(1).max(MAX_PRESERVED_FONT_FAMILY_LENGTH)).min(1).max(MAX_PRESERVED_FONT_FAMILIES)
|
|
1047
1197
|
});
|
|
1048
|
-
const
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
collapsedNeutralWrapperNodeCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_SOURCE_NODES).optional(),
|
|
1054
|
-
collapsedTransferredWrapperNodeCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_SOURCE_NODES).optional(),
|
|
1055
|
-
layoutContainerCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_NODES).optional(),
|
|
1056
|
-
removedLeafNodeCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_SOURCE_NODES).optional(),
|
|
1057
|
-
retainedSemanticOwnerNodeCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_SOURCE_NODES).optional(),
|
|
1058
|
-
truncatedNodeCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_SOURCE_NODES * 2).optional(),
|
|
1059
|
-
addedLayoutNodeCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_SOURCE_NODES).optional(),
|
|
1060
|
-
issues: z.array(canvasConversionIssueSchema).max(MAX_CANVAS_CONVERSION_SOURCE_NODES)
|
|
1061
|
-
}).refine(({ collapsedNeutralWrapperNodeCount, collapsedTransferredWrapperNodeCount, collapsedWrapperNodeCount }) => collapsedWrapperNodeCount === void 0 || collapsedNeutralWrapperNodeCount === void 0 || collapsedTransferredWrapperNodeCount === void 0 || collapsedNeutralWrapperNodeCount + collapsedTransferredWrapperNodeCount === collapsedWrapperNodeCount, "wrapper collapse proof classes must explain the collapsed wrapper count").refine(({ collapsedNodeCount, collapsedWrapperNodeCount, removedLeafNodeCount }) => collapsedNodeCount === void 0 || collapsedWrapperNodeCount === void 0 || removedLeafNodeCount === void 0 || collapsedWrapperNodeCount + removedLeafNodeCount === collapsedNodeCount, "collapsed node kinds must explain the total collapsed node count").refine(({ addedLayoutNodeCount, collapsedNodeCount, nodeCount, sourceNodeCount, truncatedNodeCount }) => sourceNodeCount === void 0 || collapsedNodeCount === void 0 || sourceNodeCount + (addedLayoutNodeCount ?? 0) - nodeCount === collapsedNodeCount + (truncatedNodeCount ?? 0), "added, collapsed and truncated node counts must explain the source to editable difference").refine(({ layoutContainerCount, nodeCount }) => layoutContainerCount === void 0 || layoutContainerCount <= nodeCount, "layout container count cannot exceed editable node count");
|
|
1062
|
-
const canvasSubtreeDraftNodeSchema = canvasSceneNodeSchema.omit({ id: true }).extend({ temporaryId: temporaryIdSchema });
|
|
1063
|
-
const canvasSubtreeDraftRelationshipSchema = z.object({
|
|
1064
|
-
temporaryId: temporaryIdSchema,
|
|
1065
|
-
parentTemporaryId: temporaryIdSchema,
|
|
1066
|
-
sortKey: z.string().min(1).max(500)
|
|
1198
|
+
const canvasSceneBoxSchema = z.object({
|
|
1199
|
+
x: z.number(),
|
|
1200
|
+
y: z.number(),
|
|
1201
|
+
width: z.number().nonnegative(),
|
|
1202
|
+
height: z.number().nonnegative()
|
|
1067
1203
|
});
|
|
1068
|
-
const
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1204
|
+
const canvasConstraintSchema = z.enum([
|
|
1205
|
+
"start",
|
|
1206
|
+
"center",
|
|
1207
|
+
"end",
|
|
1208
|
+
"stretch",
|
|
1209
|
+
"scale"
|
|
1210
|
+
]);
|
|
1211
|
+
const canvasNodeConstraintsSchema = z.object({
|
|
1212
|
+
x: canvasConstraintSchema,
|
|
1213
|
+
y: canvasConstraintSchema
|
|
1074
1214
|
});
|
|
1075
|
-
const
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1215
|
+
const canvasNodeLabelOriginSchema = z.enum([
|
|
1216
|
+
"source",
|
|
1217
|
+
"generated",
|
|
1218
|
+
"user"
|
|
1219
|
+
]);
|
|
1220
|
+
const canvasSceneNodeSchema = z.looseObject({
|
|
1221
|
+
id: z.string().min(1).max(MAX_SCENE_NODE_ID_LENGTH),
|
|
1222
|
+
label: z.string().max(MAX_SCENE_LABEL_LENGTH),
|
|
1223
|
+
component: z.string().min(1).max(MAX_SCENE_COMPONENT_LENGTH),
|
|
1224
|
+
labelOrigin: canvasNodeLabelOriginSchema.optional(),
|
|
1225
|
+
visible: z.boolean().optional(),
|
|
1226
|
+
locked: z.boolean().optional(),
|
|
1227
|
+
constraints: canvasNodeConstraintsSchema.optional(),
|
|
1228
|
+
styles: z.record(z.string(), z.union([z.string(), z.number()])),
|
|
1229
|
+
layout: canvasNodeLayoutSchema.optional(),
|
|
1230
|
+
responsive: z.never().optional(),
|
|
1231
|
+
appearance: canvasAppearanceValuesSchema.optional(),
|
|
1232
|
+
typography: canvasAuthoredTypographySchema.optional(),
|
|
1233
|
+
additionalStyles: canvasAdditionalStylesSchema.optional(),
|
|
1234
|
+
props: z.record(z.string(), z.unknown()).optional(),
|
|
1235
|
+
box: canvasSceneBoxSchema.optional()
|
|
1236
|
+
});
|
|
1237
|
+
const canvasSceneDocumentSchema = z.object({
|
|
1238
|
+
version: z.literal(5),
|
|
1239
|
+
nodes: z.record(z.string(), canvasSceneNodeSchema),
|
|
1240
|
+
relationships: z.record(z.string(), z.object({
|
|
1241
|
+
parentId: z.string().min(1).max(MAX_SCENE_NODE_ID_LENGTH),
|
|
1242
|
+
sortKey: z.string().min(1).max(MAX_SCENE_SORT_KEY_LENGTH)
|
|
1243
|
+
})),
|
|
1244
|
+
tombstones: z.record(z.string(), z.literal(true)).default({})
|
|
1245
|
+
});
|
|
1246
|
+
const legacyRecordSchema = z.record(z.string(), z.unknown());
|
|
1247
|
+
const legacyNode = (node) => {
|
|
1248
|
+
const layout = legacyRecordSchema.safeParse(node["layout"]).data;
|
|
1249
|
+
if (layout === void 0) return node;
|
|
1250
|
+
const next = Object.fromEntries(Object.entries(layout).filter(([key]) => key !== "gridTrack"));
|
|
1251
|
+
const container = legacyRecordSchema.safeParse(next["container"]).data;
|
|
1252
|
+
if (container !== void 0) next["container"] = Object.fromEntries(Object.entries(container).filter(([key]) => key !== "materialized"));
|
|
1253
|
+
for (const axis of ["horizontal", "vertical"]) {
|
|
1254
|
+
const intent = legacyRecordSchema.safeParse(next[axis]).data;
|
|
1255
|
+
if (intent?.["mode"] === "hug") next[axis] = Object.fromEntries(Object.entries(intent).filter(([key]) => key !== "basis"));
|
|
1256
|
+
}
|
|
1257
|
+
return {
|
|
1258
|
+
...node,
|
|
1259
|
+
layout: next
|
|
1260
|
+
};
|
|
1261
|
+
};
|
|
1262
|
+
const legacyDocument = (blob) => {
|
|
1263
|
+
if (Object.keys(blob).length === 0) return emptyCanvasSceneDocument();
|
|
1264
|
+
if (blob["version"] === COMPLETE_TYPOGRAPHY_FORMAT || blob["version"] === LEGACY_CANVAS_FORMAT_4) return {
|
|
1265
|
+
...blob,
|
|
1266
|
+
version: 5
|
|
1267
|
+
};
|
|
1268
|
+
const nodes = z.record(z.string(), legacyRecordSchema).safeParse(blob["nodes"]).data;
|
|
1269
|
+
if (nodes === void 0) return blob;
|
|
1270
|
+
return {
|
|
1271
|
+
...blob,
|
|
1272
|
+
version: 5,
|
|
1273
|
+
nodes: Object.fromEntries(Object.entries(nodes).map(([id, node]) => [id, legacyNode(node)]))
|
|
1274
|
+
};
|
|
1275
|
+
};
|
|
1276
|
+
/** Known old scenes are adapted in memory; only an explicit mutation persists the new format. */
|
|
1277
|
+
const canvasReadableSceneDocumentSchema = z.preprocess((value) => {
|
|
1278
|
+
const blob = legacyRecordSchema.safeParse(value).data;
|
|
1279
|
+
if (blob === void 0) return value;
|
|
1280
|
+
const version = blob["version"];
|
|
1281
|
+
return (/* @__PURE__ */ new Set([
|
|
1282
|
+
void 0,
|
|
1283
|
+
1,
|
|
1284
|
+
2,
|
|
1285
|
+
COMPLETE_TYPOGRAPHY_FORMAT,
|
|
1286
|
+
LEGACY_CANVAS_FORMAT_4
|
|
1287
|
+
])).has(version) ? legacyDocument(blob) : blob;
|
|
1288
|
+
}, canvasSceneDocumentSchema);
|
|
1289
|
+
const emptyCanvasSceneDocument = () => ({
|
|
1290
|
+
version: 5,
|
|
1291
|
+
nodes: { root: {
|
|
1292
|
+
id: "root",
|
|
1293
|
+
label: "Canvas",
|
|
1294
|
+
component: "root",
|
|
1295
|
+
labelOrigin: "generated",
|
|
1296
|
+
visible: true,
|
|
1297
|
+
locked: false,
|
|
1298
|
+
styles: {}
|
|
1299
|
+
} },
|
|
1300
|
+
relationships: {},
|
|
1301
|
+
tombstones: {}
|
|
1302
|
+
});
|
|
1303
|
+
|
|
1304
|
+
//#endregion
|
|
1305
|
+
//#region ../../packages/contract/src/canvas/canvas-text-content.lib.ts
|
|
1306
|
+
const textLinkSchema = z.object({
|
|
1307
|
+
start: z.number().int().nonnegative(),
|
|
1308
|
+
end: z.number().int().positive(),
|
|
1309
|
+
href: z.url().refine((href) => ["http:", "https:"].includes(new URL(href).protocol))
|
|
1310
|
+
});
|
|
1311
|
+
const textSchema = z.object({
|
|
1312
|
+
text: z.string(),
|
|
1313
|
+
links: z.array(textLinkSchema).optional()
|
|
1314
|
+
});
|
|
1315
|
+
|
|
1316
|
+
//#endregion
|
|
1317
|
+
//#region ../../packages/contract/src/canvas/canvas-conversion-draft.schema.ts
|
|
1318
|
+
const MAX_CANVAS_CONVERSION_NODES = 3e4;
|
|
1319
|
+
const MAX_CANVAS_CONVERSION_SOURCE_NODES = 5e4;
|
|
1320
|
+
const MAX_CANVAS_CONVERSION_ID_LENGTH = 200;
|
|
1321
|
+
const MAX_CANVAS_CONVERSION_TEXT_LENGTH = 500;
|
|
1322
|
+
const MAX_CANVAS_HTML_SOURCE_LENGTH = 262144;
|
|
1323
|
+
const temporaryIdSchema = z.string().min(1).max(200);
|
|
1324
|
+
const canvasConversionIssueSchema = z.object({
|
|
1325
|
+
code: z.enum([
|
|
1326
|
+
"asset-unavailable",
|
|
1327
|
+
"content-omitted",
|
|
1328
|
+
"cross-origin-frame",
|
|
1329
|
+
"nodes-truncated",
|
|
1330
|
+
"responsive-behavior-not-editable",
|
|
1331
|
+
"style-degraded",
|
|
1332
|
+
"unsupported-surface"
|
|
1333
|
+
]),
|
|
1334
|
+
message: z.string().min(1).max(500),
|
|
1335
|
+
temporaryId: temporaryIdSchema.optional()
|
|
1336
|
+
});
|
|
1337
|
+
const canvasConversionReportSchema = z.object({
|
|
1338
|
+
nodeCount: z.number().int().positive().max(MAX_CANVAS_CONVERSION_NODES),
|
|
1339
|
+
sourceNodeCount: z.number().int().positive().max(MAX_CANVAS_CONVERSION_SOURCE_NODES).optional(),
|
|
1340
|
+
collapsedNodeCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_SOURCE_NODES).optional(),
|
|
1341
|
+
collapsedWrapperNodeCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_SOURCE_NODES).optional(),
|
|
1342
|
+
collapsedNeutralWrapperNodeCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_SOURCE_NODES).optional(),
|
|
1343
|
+
collapsedTransferredWrapperNodeCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_SOURCE_NODES).optional(),
|
|
1344
|
+
layoutContainerCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_NODES).optional(),
|
|
1345
|
+
removedLeafNodeCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_SOURCE_NODES).optional(),
|
|
1346
|
+
retainedSemanticOwnerNodeCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_SOURCE_NODES).optional(),
|
|
1347
|
+
truncatedNodeCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_SOURCE_NODES * 2).optional(),
|
|
1348
|
+
addedLayoutNodeCount: z.number().int().nonnegative().max(MAX_CANVAS_CONVERSION_SOURCE_NODES).optional(),
|
|
1349
|
+
issues: z.array(canvasConversionIssueSchema).max(MAX_CANVAS_CONVERSION_SOURCE_NODES)
|
|
1350
|
+
}).refine(({ collapsedNeutralWrapperNodeCount, collapsedTransferredWrapperNodeCount, collapsedWrapperNodeCount }) => collapsedWrapperNodeCount === void 0 || collapsedNeutralWrapperNodeCount === void 0 || collapsedTransferredWrapperNodeCount === void 0 || collapsedNeutralWrapperNodeCount + collapsedTransferredWrapperNodeCount === collapsedWrapperNodeCount, "wrapper collapse proof classes must explain the collapsed wrapper count").refine(({ collapsedNodeCount, collapsedWrapperNodeCount, removedLeafNodeCount }) => collapsedNodeCount === void 0 || collapsedWrapperNodeCount === void 0 || removedLeafNodeCount === void 0 || collapsedWrapperNodeCount + removedLeafNodeCount === collapsedNodeCount, "collapsed node kinds must explain the total collapsed node count").refine(({ addedLayoutNodeCount, collapsedNodeCount, nodeCount, sourceNodeCount, truncatedNodeCount }) => sourceNodeCount === void 0 || collapsedNodeCount === void 0 || sourceNodeCount + (addedLayoutNodeCount ?? 0) - nodeCount === collapsedNodeCount + (truncatedNodeCount ?? 0), "added, collapsed and truncated node counts must explain the source to editable difference").refine(({ layoutContainerCount, nodeCount }) => layoutContainerCount === void 0 || layoutContainerCount <= nodeCount, "layout container count cannot exceed editable node count");
|
|
1351
|
+
const canvasSubtreeDraftNodeSchema = canvasSceneNodeSchema.omit({ id: true }).extend({ temporaryId: temporaryIdSchema });
|
|
1352
|
+
const canvasSubtreeDraftRelationshipSchema = z.object({
|
|
1353
|
+
temporaryId: temporaryIdSchema,
|
|
1354
|
+
parentTemporaryId: temporaryIdSchema,
|
|
1355
|
+
sortKey: z.string().min(1).max(500)
|
|
1356
|
+
});
|
|
1357
|
+
const canvasSubtreeDraftSchema = z.object({
|
|
1358
|
+
version: z.literal(1),
|
|
1359
|
+
rootTemporaryId: temporaryIdSchema,
|
|
1360
|
+
nodes: z.array(canvasSubtreeDraftNodeSchema).min(1).max(MAX_CANVAS_CONVERSION_NODES),
|
|
1361
|
+
relationships: z.array(canvasSubtreeDraftRelationshipSchema).max(MAX_CANVAS_CONVERSION_NODES - 1),
|
|
1362
|
+
report: canvasConversionReportSchema
|
|
1363
|
+
});
|
|
1364
|
+
const createEditableFrameInputSchema = z.object({
|
|
1365
|
+
canvasId: z.uuid(),
|
|
1366
|
+
documentFormatVersion: canvasDocumentFormatSchema,
|
|
1367
|
+
mutationId: z.uuid(),
|
|
1079
1368
|
baseVersion: z.number().int().positive(),
|
|
1080
1369
|
screenNodeId: z.string().min(1).max(200),
|
|
1081
1370
|
draft: canvasSubtreeDraftSchema
|
|
@@ -1169,7 +1458,7 @@ const RENDER_MAX_OUTPUT_BYTES = RENDER_MAX_OUTPUT_MIB * BYTES_PER_MIB$2;
|
|
|
1169
1458
|
const RENDER_MAX_SNAPSHOT_BYTES = RENDER_MAX_SNAPSHOT_MIB * BYTES_PER_MIB$2;
|
|
1170
1459
|
const RENDER_MAX_WORLD_EDGE = 1e5;
|
|
1171
1460
|
const RENDER_MIN_SCALE = .1;
|
|
1172
|
-
const MAX_NODE_ID_LENGTH$
|
|
1461
|
+
const MAX_NODE_ID_LENGTH$7 = 200;
|
|
1173
1462
|
const MAX_RENDER_MESSAGE_LENGTH$1 = 500;
|
|
1174
1463
|
const canvasWorldBoundsSchema = z.object({
|
|
1175
1464
|
x: z.number(),
|
|
@@ -1181,7 +1470,7 @@ const canvasRenderTargetSchema = z.discriminatedUnion("kind", [
|
|
|
1181
1470
|
z.object({ kind: z.literal("content") }),
|
|
1182
1471
|
z.object({
|
|
1183
1472
|
kind: z.literal("node"),
|
|
1184
|
-
nodeId: z.string().min(1).max(MAX_NODE_ID_LENGTH$
|
|
1473
|
+
nodeId: z.string().min(1).max(MAX_NODE_ID_LENGTH$7)
|
|
1185
1474
|
}),
|
|
1186
1475
|
z.object({
|
|
1187
1476
|
kind: z.literal("bounds"),
|
|
@@ -1203,7 +1492,7 @@ const canvasRenderSnapshotResultSchema = z.object({
|
|
|
1203
1492
|
recordingId: z.uuid(),
|
|
1204
1493
|
atMs: z.number().int().nonnegative(),
|
|
1205
1494
|
screenId: z.uuid(),
|
|
1206
|
-
screenNodeId: z.string().min(1).max(MAX_NODE_ID_LENGTH$
|
|
1495
|
+
screenNodeId: z.string().min(1).max(MAX_NODE_ID_LENGTH$7),
|
|
1207
1496
|
viewport: z.object({
|
|
1208
1497
|
width: z.number().int().positive(),
|
|
1209
1498
|
height: z.number().int().positive()
|
|
@@ -1230,14 +1519,14 @@ const canvasRenderWarningCodeSchema = z.enum(RENDER_WARNING_CODES);
|
|
|
1230
1519
|
const canvasRenderWarningSchema = z.object({
|
|
1231
1520
|
code: canvasRenderWarningCodeSchema,
|
|
1232
1521
|
message: z.string().min(1).max(MAX_RENDER_MESSAGE_LENGTH$1),
|
|
1233
|
-
sourceId: z.string().min(1).max(MAX_NODE_ID_LENGTH$
|
|
1522
|
+
sourceId: z.string().min(1).max(MAX_NODE_ID_LENGTH$7).nullable()
|
|
1234
1523
|
});
|
|
1235
1524
|
const canvasRenderFailureSchema = z.object({
|
|
1236
1525
|
reason: canvasRenderFailureReasonSchema,
|
|
1237
1526
|
phase: canvasRenderPhaseSchema,
|
|
1238
1527
|
message: z.string().min(1).max(MAX_RENDER_MESSAGE_LENGTH$1),
|
|
1239
1528
|
retryable: z.boolean(),
|
|
1240
|
-
sourceId: z.string().min(1).max(MAX_NODE_ID_LENGTH$
|
|
1529
|
+
sourceId: z.string().min(1).max(MAX_NODE_ID_LENGTH$7).nullable()
|
|
1241
1530
|
});
|
|
1242
1531
|
const canvasRenderTimingSchema = z.object({
|
|
1243
1532
|
phase: canvasRenderPhaseSchema,
|
|
@@ -1408,556 +1697,129 @@ const canvasConversionJobSchema = z.discriminatedUnion("state", [
|
|
|
1408
1697
|
state: z.literal("succeeded"),
|
|
1409
1698
|
phase: z.literal("complete"),
|
|
1410
1699
|
result: createEditableFrameResultSchema.extend({ report: canvasConversionReportSchema }),
|
|
1411
|
-
failure: z.null()
|
|
1412
|
-
}),
|
|
1413
|
-
canvasConversionJobBaseSchema.extend({
|
|
1414
|
-
state: z.literal("failed"),
|
|
1415
|
-
result: z.null(),
|
|
1416
|
-
failure: canvasRenderFailureSchema
|
|
1417
|
-
}),
|
|
1418
|
-
canvasConversionJobBaseSchema.extend({
|
|
1419
|
-
state: z.literal("cancelled"),
|
|
1420
|
-
result: z.null(),
|
|
1421
|
-
failure: canvasRenderFailureSchema.extend({ reason: z.literal("CANCELLED") })
|
|
1422
|
-
}),
|
|
1423
|
-
canvasConversionJobBaseSchema.extend({
|
|
1424
|
-
state: z.literal("expired"),
|
|
1425
|
-
result: z.null(),
|
|
1426
|
-
failure: canvasRenderFailureSchema.extend({ reason: z.literal("EXPIRED") })
|
|
1427
|
-
})
|
|
1428
|
-
]);
|
|
1429
|
-
const createCanvasConversionInputSchema = canvasConversionRequestSchema.and(z.object({
|
|
1430
|
-
canvasId: z.uuid(),
|
|
1431
|
-
expectedVersion: z.number().int().positive().optional()
|
|
1432
|
-
}));
|
|
1433
|
-
const createCanvasConversionOutputSchema = z.object({
|
|
1434
|
-
job: canvasConversionJobSchema,
|
|
1435
|
-
alreadyExists: z.boolean()
|
|
1436
|
-
});
|
|
1437
|
-
const getCanvasConversionInputSchema = z.object({ jobId: z.uuid() });
|
|
1438
|
-
const getCanvasConversionOutputSchema = z.object({ job: canvasConversionJobSchema });
|
|
1439
|
-
const cancelCanvasConversionInputSchema = z.object({ jobId: z.uuid() });
|
|
1440
|
-
const cancelCanvasConversionOutputSchema = z.object({ job: canvasConversionJobSchema });
|
|
1441
|
-
const conversionRouteStateSchema = z.discriminatedUnion("state", [
|
|
1442
|
-
z.object({
|
|
1443
|
-
state: z.literal("loading"),
|
|
1444
|
-
jobId: z.uuid()
|
|
1445
|
-
}),
|
|
1446
|
-
z.object({
|
|
1447
|
-
state: z.literal("ready"),
|
|
1448
|
-
jobId: z.uuid(),
|
|
1449
|
-
loadedVersion: z.number().int().positive(),
|
|
1450
|
-
draft: canvasSubtreeDraftSchema
|
|
1451
|
-
}),
|
|
1452
|
-
z.object({
|
|
1453
|
-
state: z.literal("failed"),
|
|
1454
|
-
jobId: z.uuid(),
|
|
1455
|
-
message: z.string().min(1).max(500)
|
|
1456
|
-
})
|
|
1457
|
-
]);
|
|
1458
|
-
|
|
1459
|
-
//#endregion
|
|
1460
|
-
//#region ../../packages/contract/src/canvas/canvas-
|
|
1461
|
-
|
|
1462
|
-
const
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
"
|
|
1522
|
-
"
|
|
1523
|
-
"
|
|
1524
|
-
"
|
|
1525
|
-
"
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
bytes: z.number().int().positive().max(MAX_CANVAS_IMAGE_BYTES)
|
|
1535
|
-
});
|
|
1536
|
-
const reserveCanvasImageOutputSchema = z.object({
|
|
1537
|
-
assetId: z.uuid(),
|
|
1538
|
-
path: z.string().startsWith("/v1/canvas-assets/"),
|
|
1539
|
-
upload: signedUploadSchema
|
|
1540
|
-
});
|
|
1541
|
-
const canvasImageAssetPath = (canvasId, assetId) => `/v1/canvas-assets/${encodeURIComponent(canvasId)}/${encodeURIComponent(assetId)}`;
|
|
1542
|
-
|
|
1543
|
-
//#endregion
|
|
1544
|
-
//#region ../../packages/contract/src/canvas/canvas-property-section.schema.ts
|
|
1545
|
-
const CANVAS_PROPERTY_SECTIONS = [
|
|
1546
|
-
"position",
|
|
1547
|
-
"layout",
|
|
1548
|
-
"clip",
|
|
1549
|
-
"cornerRadius",
|
|
1550
|
-
"blending",
|
|
1551
|
-
"typography",
|
|
1552
|
-
"nativeControl",
|
|
1553
|
-
"textDecoration",
|
|
1554
|
-
"fill",
|
|
1555
|
-
"outline",
|
|
1556
|
-
"textStroke",
|
|
1557
|
-
"border",
|
|
1558
|
-
"outerShadow",
|
|
1559
|
-
"innerShadow",
|
|
1560
|
-
"filters",
|
|
1561
|
-
"additionalStyles",
|
|
1562
|
-
"vector",
|
|
1563
|
-
"export",
|
|
1564
|
-
"source"
|
|
1565
|
-
];
|
|
1566
|
-
const canvasPropertySectionSchema = z.enum(CANVAS_PROPERTY_SECTIONS);
|
|
1567
|
-
|
|
1568
|
-
//#endregion
|
|
1569
|
-
//#region ../../packages/contract/src/canvas/canvas-inspection.schema.ts
|
|
1570
|
-
const MAX_NODE_ID_LENGTH$5 = 200;
|
|
1571
|
-
const MAX_RENDER_MESSAGE_LENGTH = 500;
|
|
1572
|
-
const MAX_RENDER_KIND_LENGTH = 100;
|
|
1573
|
-
const canvasInspectNodeSummarySchema = z.object({
|
|
1574
|
-
id: z.string().min(1).max(MAX_NODE_ID_LENGTH$5),
|
|
1575
|
-
label: z.string().max(MAX_RENDER_MESSAGE_LENGTH),
|
|
1576
|
-
kind: z.string().min(1).max(MAX_RENDER_KIND_LENGTH),
|
|
1577
|
-
parentId: z.string().min(1).max(MAX_NODE_ID_LENGTH$5).nullable(),
|
|
1578
|
-
childCount: z.number().int().min(0),
|
|
1579
|
-
box: canvasWorldBoundsSchema.nullable(),
|
|
1580
|
-
propertySections: z.array(canvasPropertySectionSchema)
|
|
1581
|
-
});
|
|
1582
|
-
const inspectCanvasInputSchema = z.object({ canvasId: z.uuid() });
|
|
1583
|
-
const inspectCanvasOutputSchema = z.object({
|
|
1584
|
-
canvasId: z.uuid(),
|
|
1585
|
-
openUrl: z.url(),
|
|
1586
|
-
title: z.string().min(1),
|
|
1587
|
-
version: z.number().int().positive(),
|
|
1588
|
-
nodeCount: z.number().int().min(0),
|
|
1589
|
-
rootChildCount: z.number().int().min(0),
|
|
1590
|
-
bounds: canvasWorldBoundsSchema.nullable(),
|
|
1591
|
-
kinds: z.record(z.string(), z.number().int().min(0)),
|
|
1592
|
-
next: z.array(z.string().min(1))
|
|
1593
|
-
});
|
|
1594
|
-
const inspectCanvasTreeInputSchema = z.object({ canvasId: z.uuid() });
|
|
1595
|
-
const inspectCanvasTreeOutputSchema = z.object({
|
|
1596
|
-
canvasId: z.uuid(),
|
|
1597
|
-
version: z.number().int().positive(),
|
|
1598
|
-
nodes: z.array(canvasInspectNodeSummarySchema)
|
|
1599
|
-
});
|
|
1600
|
-
const inspectCanvasNodeInputSchema = z.object({
|
|
1601
|
-
canvasId: z.uuid(),
|
|
1602
|
-
nodeId: z.string().min(1).max(MAX_NODE_ID_LENGTH$5)
|
|
1603
|
-
});
|
|
1604
|
-
const inspectCanvasNodeOutputSchema = z.object({
|
|
1605
|
-
canvasId: z.uuid(),
|
|
1606
|
-
version: z.number().int().positive(),
|
|
1607
|
-
node: canvasInspectNodeSummarySchema.extend({
|
|
1608
|
-
styles: z.record(z.string(), z.union([z.string(), z.number()])),
|
|
1609
|
-
layout: canvasNodeLayoutSchema.optional(),
|
|
1610
|
-
appearance: canvasAppearanceValuesSchema.optional(),
|
|
1611
|
-
typography: canvasTypographySchema.optional(),
|
|
1612
|
-
additionalStyles: canvasAdditionalStylesSchema.optional(),
|
|
1613
|
-
props: z.record(z.string(), z.unknown()),
|
|
1614
|
-
children: z.array(z.string().min(1).max(MAX_NODE_ID_LENGTH$5))
|
|
1615
|
-
}),
|
|
1616
|
-
next: z.array(z.string().min(1))
|
|
1617
|
-
});
|
|
1618
|
-
|
|
1619
|
-
//#endregion
|
|
1620
|
-
//#region ../../packages/contract/src/canvas/canvas-layout-ownership.lib.ts
|
|
1621
|
-
const CANVAS_LAYOUT_CSS_FIELDS = [
|
|
1622
|
-
["alignSelf", "align-self"],
|
|
1623
|
-
["order", "order"],
|
|
1624
|
-
["flexGrow", "flex-grow"],
|
|
1625
|
-
["flexShrink", "flex-shrink"],
|
|
1626
|
-
["flexBasis", "flex-basis"],
|
|
1627
|
-
["aspectRatio", "aspect-ratio"]
|
|
1628
|
-
];
|
|
1629
|
-
const CANVAS_CONTAINER_CSS_FIELDS = [
|
|
1630
|
-
["direction", "flex-direction"],
|
|
1631
|
-
["wrap", "flex-wrap"],
|
|
1632
|
-
["alignItems", "align-items"],
|
|
1633
|
-
["alignContent", "align-content"],
|
|
1634
|
-
["justifyContent", "justify-content"],
|
|
1635
|
-
["rowGap", "row-gap"],
|
|
1636
|
-
["columnGap", "column-gap"]
|
|
1637
|
-
];
|
|
1638
|
-
const SIDES = [
|
|
1639
|
-
"top",
|
|
1640
|
-
"right",
|
|
1641
|
-
"bottom",
|
|
1642
|
-
"left"
|
|
1643
|
-
];
|
|
1644
|
-
const releasedSpacing = (held, prefix, properties) => {
|
|
1645
|
-
const next = { ...held };
|
|
1646
|
-
for (const side of SIDES) if (properties.has(`${prefix}-${side}`)) Reflect.deleteProperty(next, side);
|
|
1647
|
-
return next;
|
|
1648
|
-
};
|
|
1649
|
-
/** A shorthand can release several named controls; a longhand releases only itself. */
|
|
1650
|
-
const releasedFields = (held, changed) => {
|
|
1651
|
-
const properties = new Set([...changed].flatMap((property) => canvasCssPropertyScope(property)));
|
|
1652
|
-
const layout = { ...held };
|
|
1653
|
-
for (const [key, property] of CANVAS_LAYOUT_CSS_FIELDS) if (properties.has(property)) Reflect.deleteProperty(layout, key);
|
|
1654
|
-
if (layout.margin !== void 0) layout.margin = releasedSpacing(layout.margin, "margin", properties);
|
|
1655
|
-
if (layout.container === void 0) return layout;
|
|
1656
|
-
const container = { ...layout.container };
|
|
1657
|
-
if ((properties.has("row-gap") || properties.has("column-gap")) && container.gap !== void 0) {
|
|
1658
|
-
container.rowGap ??= container.gap;
|
|
1659
|
-
container.columnGap ??= container.gap;
|
|
1660
|
-
Reflect.deleteProperty(container, "gap");
|
|
1661
|
-
}
|
|
1662
|
-
for (const [key, property] of CANVAS_CONTAINER_CSS_FIELDS) if (properties.has(property)) Reflect.deleteProperty(container, key);
|
|
1663
|
-
if (container.padding !== void 0) container.padding = releasedSpacing(container.padding, "padding", properties);
|
|
1664
|
-
if (properties.has("grid-template-columns")) {
|
|
1665
|
-
Reflect.deleteProperty(container, "gridColumns");
|
|
1666
|
-
Reflect.deleteProperty(container, "gridAutoRepeat");
|
|
1667
|
-
}
|
|
1668
|
-
layout.container = container;
|
|
1669
|
-
return layout;
|
|
1670
|
-
};
|
|
1671
|
-
const axisWithoutCssBounds = (intent, properties, changed) => {
|
|
1672
|
-
if (intent === void 0 || intent.mode === "fixed") return intent;
|
|
1673
|
-
const released = { ...intent };
|
|
1674
|
-
for (const bound of ["min", "max"]) {
|
|
1675
|
-
if (properties.every((property) => !changed.has(`${bound}-${property}`))) continue;
|
|
1676
|
-
Reflect.deleteProperty(released, bound);
|
|
1677
|
-
Reflect.deleteProperty(released, `${bound}Parent`);
|
|
1678
|
-
}
|
|
1679
|
-
return released;
|
|
1680
|
-
};
|
|
1681
|
-
/** Editors hand CSS control back property by property; absent presets stay absent. */
|
|
1682
|
-
const canvasLayoutWithoutCssProperties = (held, changed, axes) => {
|
|
1683
|
-
const properties = new Set([...changed].flatMap((property) => canvasCssPropertyScope(property)));
|
|
1684
|
-
const layout = releasedFields(held, properties);
|
|
1685
|
-
if ([
|
|
1686
|
-
"overflow",
|
|
1687
|
-
"overflow-x",
|
|
1688
|
-
"overflow-y"
|
|
1689
|
-
].some((property) => properties.has(property))) Reflect.deleteProperty(layout, "clipContent");
|
|
1690
|
-
if (properties.has("position")) Reflect.deleteProperty(layout, "position");
|
|
1691
|
-
if (properties.has("transform")) for (const key of [
|
|
1692
|
-
"rotation",
|
|
1693
|
-
"flipHorizontal",
|
|
1694
|
-
"flipVertical"
|
|
1695
|
-
]) Reflect.deleteProperty(layout, key);
|
|
1696
|
-
if ([
|
|
1697
|
-
"inset",
|
|
1698
|
-
"left",
|
|
1699
|
-
"right",
|
|
1700
|
-
"top",
|
|
1701
|
-
"bottom"
|
|
1702
|
-
].some((property) => properties.has(property))) Reflect.deleteProperty(layout, "flowOffset");
|
|
1703
|
-
for (const axis of ["horizontal", "vertical"]) {
|
|
1704
|
-
const intent = axes[axis].some((property) => properties.has(property)) ? void 0 : axisWithoutCssBounds(layout[axis], axes[axis], properties);
|
|
1705
|
-
if (intent === void 0) Reflect.deleteProperty(layout, axis);
|
|
1706
|
-
else layout[axis] = intent;
|
|
1707
|
-
}
|
|
1708
|
-
return layout;
|
|
1709
|
-
};
|
|
1710
|
-
|
|
1711
|
-
//#endregion
|
|
1712
|
-
//#region ../../packages/contract/src/canvas/canvas-object-kind.lib.ts
|
|
1713
|
-
const ROOT_KIND = "root";
|
|
1714
|
-
const PAGE_KIND = "page";
|
|
1715
|
-
const SCREEN_KIND = "screen";
|
|
1716
|
-
const FRAME_KIND = "frame";
|
|
1717
|
-
const GROUP_KIND = "group";
|
|
1718
|
-
const RECTANGLE_KIND = "rectangle";
|
|
1719
|
-
const IMAGE_KIND = "image";
|
|
1720
|
-
const SVG_KIND = "svg";
|
|
1721
|
-
const RECORDING_KIND = "recording";
|
|
1722
|
-
const PROTOTYPE_KIND = "prototype";
|
|
1723
|
-
const TEXT_KIND = "text";
|
|
1724
|
-
const SHAPE_PROPERTY_SECTIONS = [
|
|
1725
|
-
"position",
|
|
1726
|
-
"layout",
|
|
1727
|
-
"cornerRadius",
|
|
1728
|
-
"blending",
|
|
1729
|
-
"fill",
|
|
1730
|
-
"outline",
|
|
1731
|
-
"border",
|
|
1732
|
-
"outerShadow",
|
|
1733
|
-
"innerShadow",
|
|
1734
|
-
"filters",
|
|
1735
|
-
"additionalStyles",
|
|
1736
|
-
"export"
|
|
1737
|
-
];
|
|
1738
|
-
const FRAME_PROPERTY_SECTIONS = [
|
|
1739
|
-
"position",
|
|
1740
|
-
"layout",
|
|
1741
|
-
"clip",
|
|
1742
|
-
...SHAPE_PROPERTY_SECTIONS.filter((section) => section !== "position" && section !== "layout")
|
|
1743
|
-
];
|
|
1744
|
-
const SVG_PROPERTY_SECTIONS = [...SHAPE_PROPERTY_SECTIONS, "vector"];
|
|
1745
|
-
const DESCRIPTOR_BY_KIND = Object.fromEntries([
|
|
1746
|
-
{
|
|
1747
|
-
objectKind: PROTOTYPE_KIND,
|
|
1748
|
-
label: "Prototype",
|
|
1749
|
-
category: "import",
|
|
1750
|
-
capabilities: {
|
|
1751
|
-
canSelect: true,
|
|
1752
|
-
canContainChildren: false,
|
|
1753
|
-
canEditProperties: false,
|
|
1754
|
-
commentAnchor: "node"
|
|
1755
|
-
},
|
|
1756
|
-
capture: { preservesHtmlCssAssets: true },
|
|
1757
|
-
selectionBehavior: { hitTarget: "frame" },
|
|
1758
|
-
resizeBehavior: {
|
|
1759
|
-
mode: "reflow",
|
|
1760
|
-
preservesAspect: false,
|
|
1761
|
-
canLockAspectRatio: true
|
|
1762
|
-
},
|
|
1763
|
-
propertySections: ["position", "layout"]
|
|
1764
|
-
},
|
|
1765
|
-
{
|
|
1766
|
-
objectKind: ROOT_KIND,
|
|
1767
|
-
label: "Canvas",
|
|
1768
|
-
category: "container",
|
|
1769
|
-
capabilities: {
|
|
1770
|
-
canSelect: false,
|
|
1771
|
-
canContainChildren: true,
|
|
1772
|
-
canEditProperties: false
|
|
1773
|
-
},
|
|
1774
|
-
selectionBehavior: { hitTarget: "children" },
|
|
1775
|
-
propertySections: []
|
|
1776
|
-
},
|
|
1777
|
-
{
|
|
1778
|
-
objectKind: PAGE_KIND,
|
|
1779
|
-
label: "Page",
|
|
1780
|
-
category: "container",
|
|
1781
|
-
capabilities: {
|
|
1782
|
-
canSelect: false,
|
|
1783
|
-
canContainChildren: false,
|
|
1784
|
-
canEditProperties: false
|
|
1785
|
-
},
|
|
1786
|
-
selectionBehavior: { hitTarget: "children" },
|
|
1787
|
-
propertySections: []
|
|
1788
|
-
},
|
|
1789
|
-
{
|
|
1790
|
-
objectKind: SCREEN_KIND,
|
|
1791
|
-
label: "Screen",
|
|
1792
|
-
category: "import",
|
|
1793
|
-
capabilities: {
|
|
1794
|
-
canSelect: true,
|
|
1795
|
-
canContainChildren: false,
|
|
1796
|
-
canEditProperties: false,
|
|
1797
|
-
commentAnchor: "screen"
|
|
1798
|
-
},
|
|
1799
|
-
capture: { preservesHtmlCssAssets: true },
|
|
1800
|
-
selectionBehavior: { hitTarget: "frame" },
|
|
1801
|
-
resizeBehavior: {
|
|
1802
|
-
mode: "reflow",
|
|
1803
|
-
preservesAspect: false,
|
|
1804
|
-
canLockAspectRatio: true
|
|
1805
|
-
},
|
|
1806
|
-
propertySections: [
|
|
1807
|
-
"position",
|
|
1808
|
-
"layout",
|
|
1809
|
-
"source"
|
|
1810
|
-
]
|
|
1811
|
-
},
|
|
1812
|
-
{
|
|
1813
|
-
objectKind: FRAME_KIND,
|
|
1814
|
-
label: "Frame",
|
|
1815
|
-
category: "container",
|
|
1816
|
-
capabilities: {
|
|
1817
|
-
canSelect: true,
|
|
1818
|
-
canContainChildren: true,
|
|
1819
|
-
canEditProperties: true,
|
|
1820
|
-
commentAnchor: "node"
|
|
1821
|
-
},
|
|
1822
|
-
selectionBehavior: { hitTarget: "frame" },
|
|
1823
|
-
resizeBehavior: {
|
|
1824
|
-
mode: "reflow",
|
|
1825
|
-
preservesAspect: false,
|
|
1826
|
-
canLockAspectRatio: true
|
|
1827
|
-
},
|
|
1828
|
-
propertySections: FRAME_PROPERTY_SECTIONS
|
|
1829
|
-
},
|
|
1830
|
-
{
|
|
1831
|
-
objectKind: GROUP_KIND,
|
|
1832
|
-
label: "Group",
|
|
1833
|
-
category: "container",
|
|
1834
|
-
capabilities: {
|
|
1835
|
-
canSelect: true,
|
|
1836
|
-
canContainChildren: true,
|
|
1837
|
-
canEditProperties: true,
|
|
1838
|
-
commentAnchor: "node"
|
|
1839
|
-
},
|
|
1840
|
-
selectionBehavior: { hitTarget: "frame" },
|
|
1841
|
-
resizeBehavior: {
|
|
1842
|
-
mode: "reflow",
|
|
1843
|
-
preservesAspect: false,
|
|
1844
|
-
canLockAspectRatio: true
|
|
1845
|
-
},
|
|
1846
|
-
propertySections: [
|
|
1847
|
-
"position",
|
|
1848
|
-
"layout",
|
|
1849
|
-
"blending",
|
|
1850
|
-
"additionalStyles",
|
|
1851
|
-
"export"
|
|
1852
|
-
]
|
|
1853
|
-
},
|
|
1854
|
-
{
|
|
1855
|
-
objectKind: RECTANGLE_KIND,
|
|
1856
|
-
label: "Rectangle",
|
|
1857
|
-
category: "primitive",
|
|
1858
|
-
capabilities: {
|
|
1859
|
-
canSelect: true,
|
|
1860
|
-
canContainChildren: false,
|
|
1861
|
-
canEditProperties: true,
|
|
1862
|
-
commentAnchor: "node"
|
|
1863
|
-
},
|
|
1864
|
-
selectionBehavior: { hitTarget: "frame" },
|
|
1865
|
-
resizeBehavior: {
|
|
1866
|
-
mode: "reflow",
|
|
1867
|
-
preservesAspect: false,
|
|
1868
|
-
canLockAspectRatio: true
|
|
1869
|
-
},
|
|
1870
|
-
propertySections: SHAPE_PROPERTY_SECTIONS
|
|
1871
|
-
},
|
|
1872
|
-
{
|
|
1873
|
-
objectKind: IMAGE_KIND,
|
|
1874
|
-
label: "Image",
|
|
1875
|
-
category: "media",
|
|
1876
|
-
capabilities: {
|
|
1877
|
-
canSelect: true,
|
|
1878
|
-
canContainChildren: false,
|
|
1879
|
-
canEditProperties: true,
|
|
1880
|
-
commentAnchor: "node"
|
|
1881
|
-
},
|
|
1882
|
-
selectionBehavior: { hitTarget: "frame" },
|
|
1883
|
-
resizeBehavior: {
|
|
1884
|
-
mode: "scale",
|
|
1885
|
-
preservesAspect: true,
|
|
1886
|
-
canLockAspectRatio: true
|
|
1887
|
-
},
|
|
1888
|
-
propertySections: SHAPE_PROPERTY_SECTIONS
|
|
1889
|
-
},
|
|
1890
|
-
{
|
|
1891
|
-
objectKind: "svg",
|
|
1892
|
-
label: "SVG",
|
|
1893
|
-
category: "primitive",
|
|
1894
|
-
capabilities: {
|
|
1895
|
-
canSelect: true,
|
|
1896
|
-
canContainChildren: false,
|
|
1897
|
-
canEditProperties: true,
|
|
1898
|
-
commentAnchor: "node"
|
|
1899
|
-
},
|
|
1900
|
-
capture: { preservesVectorData: true },
|
|
1901
|
-
selectionBehavior: { hitTarget: "frame" },
|
|
1902
|
-
resizeBehavior: {
|
|
1903
|
-
mode: "scale",
|
|
1904
|
-
preservesAspect: true,
|
|
1905
|
-
canLockAspectRatio: true
|
|
1906
|
-
},
|
|
1907
|
-
propertySections: SVG_PROPERTY_SECTIONS
|
|
1908
|
-
},
|
|
1909
|
-
{
|
|
1910
|
-
objectKind: RECORDING_KIND,
|
|
1911
|
-
label: "Recording",
|
|
1912
|
-
category: "media",
|
|
1913
|
-
capabilities: {
|
|
1914
|
-
canSelect: true,
|
|
1915
|
-
canContainChildren: false,
|
|
1916
|
-
canEditProperties: false
|
|
1917
|
-
},
|
|
1918
|
-
capture: { preservesAssets: true },
|
|
1919
|
-
selectionBehavior: { hitTarget: "frame" },
|
|
1920
|
-
resizeBehavior: {
|
|
1921
|
-
mode: "scale",
|
|
1922
|
-
preservesAspect: true,
|
|
1923
|
-
canLockAspectRatio: true
|
|
1924
|
-
},
|
|
1925
|
-
propertySections: []
|
|
1926
|
-
},
|
|
1927
|
-
{
|
|
1928
|
-
objectKind: TEXT_KIND,
|
|
1929
|
-
label: "Text",
|
|
1930
|
-
category: "primitive",
|
|
1931
|
-
capabilities: {
|
|
1932
|
-
canSelect: true,
|
|
1933
|
-
canContainChildren: false,
|
|
1934
|
-
canEditProperties: true,
|
|
1935
|
-
commentAnchor: "node"
|
|
1936
|
-
},
|
|
1937
|
-
selectionBehavior: { hitTarget: "text" },
|
|
1938
|
-
resizeBehavior: {
|
|
1939
|
-
mode: "reflow",
|
|
1940
|
-
preservesAspect: false,
|
|
1941
|
-
canLockAspectRatio: false
|
|
1942
|
-
},
|
|
1943
|
-
propertySections: [
|
|
1944
|
-
"position",
|
|
1945
|
-
"layout",
|
|
1946
|
-
"typography",
|
|
1947
|
-
"nativeControl",
|
|
1948
|
-
"textDecoration",
|
|
1949
|
-
"textStroke",
|
|
1950
|
-
"blending",
|
|
1951
|
-
"fill",
|
|
1952
|
-
"outerShadow",
|
|
1953
|
-
"filters",
|
|
1954
|
-
"additionalStyles",
|
|
1955
|
-
"export"
|
|
1956
|
-
]
|
|
1957
|
-
}
|
|
1958
|
-
].map((descriptor) => [descriptor.objectKind, descriptor]));
|
|
1959
|
-
const canvasObjectKindDescriptor = (objectKind) => DESCRIPTOR_BY_KIND[objectKind] ?? null;
|
|
1960
|
-
const canvasPropertySectionsForKind = (objectKind) => canvasObjectKindDescriptor(objectKind)?.propertySections ?? [];
|
|
1700
|
+
failure: z.null()
|
|
1701
|
+
}),
|
|
1702
|
+
canvasConversionJobBaseSchema.extend({
|
|
1703
|
+
state: z.literal("failed"),
|
|
1704
|
+
result: z.null(),
|
|
1705
|
+
failure: canvasRenderFailureSchema
|
|
1706
|
+
}),
|
|
1707
|
+
canvasConversionJobBaseSchema.extend({
|
|
1708
|
+
state: z.literal("cancelled"),
|
|
1709
|
+
result: z.null(),
|
|
1710
|
+
failure: canvasRenderFailureSchema.extend({ reason: z.literal("CANCELLED") })
|
|
1711
|
+
}),
|
|
1712
|
+
canvasConversionJobBaseSchema.extend({
|
|
1713
|
+
state: z.literal("expired"),
|
|
1714
|
+
result: z.null(),
|
|
1715
|
+
failure: canvasRenderFailureSchema.extend({ reason: z.literal("EXPIRED") })
|
|
1716
|
+
})
|
|
1717
|
+
]);
|
|
1718
|
+
const createCanvasConversionInputSchema = canvasConversionRequestSchema.and(z.object({
|
|
1719
|
+
canvasId: z.uuid(),
|
|
1720
|
+
expectedVersion: z.number().int().positive().optional()
|
|
1721
|
+
}));
|
|
1722
|
+
const createCanvasConversionOutputSchema = z.object({
|
|
1723
|
+
job: canvasConversionJobSchema,
|
|
1724
|
+
alreadyExists: z.boolean()
|
|
1725
|
+
});
|
|
1726
|
+
const getCanvasConversionInputSchema = z.object({ jobId: z.uuid() });
|
|
1727
|
+
const getCanvasConversionOutputSchema = z.object({ job: canvasConversionJobSchema });
|
|
1728
|
+
const cancelCanvasConversionInputSchema = z.object({ jobId: z.uuid() });
|
|
1729
|
+
const cancelCanvasConversionOutputSchema = z.object({ job: canvasConversionJobSchema });
|
|
1730
|
+
const conversionRouteStateSchema = z.discriminatedUnion("state", [
|
|
1731
|
+
z.object({
|
|
1732
|
+
state: z.literal("loading"),
|
|
1733
|
+
jobId: z.uuid()
|
|
1734
|
+
}),
|
|
1735
|
+
z.object({
|
|
1736
|
+
state: z.literal("ready"),
|
|
1737
|
+
jobId: z.uuid(),
|
|
1738
|
+
loadedVersion: z.number().int().positive(),
|
|
1739
|
+
draft: canvasSubtreeDraftSchema
|
|
1740
|
+
}),
|
|
1741
|
+
z.object({
|
|
1742
|
+
state: z.literal("failed"),
|
|
1743
|
+
jobId: z.uuid(),
|
|
1744
|
+
message: z.string().min(1).max(500)
|
|
1745
|
+
})
|
|
1746
|
+
]);
|
|
1747
|
+
|
|
1748
|
+
//#endregion
|
|
1749
|
+
//#region ../../packages/contract/src/canvas/canvas-font-library.schema.ts
|
|
1750
|
+
const MAX_CANVAS_FONT_IMPORT_FILES = 100;
|
|
1751
|
+
const MAX_RESOURCE_ID_LENGTH = 300;
|
|
1752
|
+
const canvasFontLibraryPatchSchema = z.object({
|
|
1753
|
+
add: z.array(z.object({ resourceId: z.string().min(1).max(MAX_RESOURCE_ID_LENGTH) }).catchall(z.unknown())).max(100),
|
|
1754
|
+
remove: z.array(z.string().min(1).max(MAX_RESOURCE_ID_LENGTH)).max(100)
|
|
1755
|
+
});
|
|
1756
|
+
|
|
1757
|
+
//#endregion
|
|
1758
|
+
//#region ../../packages/contract/src/canvas/canvas-decoration-style-patch.schema.ts
|
|
1759
|
+
const dimensionalStyleValue$1 = z.union([z.string(), boundedCanvasNumberSchema]);
|
|
1760
|
+
const layoutStylePatchValue$1 = z.union([canvasAdditionalStyleSchema.shape.value, boundedCanvasNumberSchema]).nullable().optional();
|
|
1761
|
+
const canvasDecorationStylePatchSchema = z.strictObject({
|
|
1762
|
+
border: layoutStylePatchValue$1,
|
|
1763
|
+
"border-block": layoutStylePatchValue$1,
|
|
1764
|
+
"border-block-color": layoutStylePatchValue$1,
|
|
1765
|
+
"border-block-style": layoutStylePatchValue$1,
|
|
1766
|
+
"border-block-width": layoutStylePatchValue$1,
|
|
1767
|
+
"border-block-end": layoutStylePatchValue$1,
|
|
1768
|
+
"border-block-end-color": layoutStylePatchValue$1,
|
|
1769
|
+
"border-block-end-style": layoutStylePatchValue$1,
|
|
1770
|
+
"border-block-end-width": layoutStylePatchValue$1,
|
|
1771
|
+
"border-block-start": layoutStylePatchValue$1,
|
|
1772
|
+
"border-block-start-color": layoutStylePatchValue$1,
|
|
1773
|
+
"border-block-start-style": layoutStylePatchValue$1,
|
|
1774
|
+
"border-block-start-width": layoutStylePatchValue$1,
|
|
1775
|
+
"border-bottom": layoutStylePatchValue$1,
|
|
1776
|
+
"border-bottom-color": layoutStylePatchValue$1,
|
|
1777
|
+
"border-bottom-style": layoutStylePatchValue$1,
|
|
1778
|
+
"border-bottom-left-radius": dimensionalStyleValue$1.optional(),
|
|
1779
|
+
"border-bottom-right-radius": dimensionalStyleValue$1.optional(),
|
|
1780
|
+
"border-bottom-width": dimensionalStyleValue$1.optional(),
|
|
1781
|
+
"border-color": z.string().nullable().optional(),
|
|
1782
|
+
"border-image": layoutStylePatchValue$1,
|
|
1783
|
+
"border-image-source": layoutStylePatchValue$1,
|
|
1784
|
+
"border-image-slice": layoutStylePatchValue$1,
|
|
1785
|
+
"border-image-width": layoutStylePatchValue$1,
|
|
1786
|
+
"border-image-outset": layoutStylePatchValue$1,
|
|
1787
|
+
"border-image-repeat": layoutStylePatchValue$1,
|
|
1788
|
+
"border-inline": layoutStylePatchValue$1,
|
|
1789
|
+
"border-inline-color": layoutStylePatchValue$1,
|
|
1790
|
+
"border-inline-style": layoutStylePatchValue$1,
|
|
1791
|
+
"border-inline-width": layoutStylePatchValue$1,
|
|
1792
|
+
"border-inline-end": layoutStylePatchValue$1,
|
|
1793
|
+
"border-inline-end-color": layoutStylePatchValue$1,
|
|
1794
|
+
"border-inline-end-style": layoutStylePatchValue$1,
|
|
1795
|
+
"border-inline-end-width": layoutStylePatchValue$1,
|
|
1796
|
+
"border-inline-start": layoutStylePatchValue$1,
|
|
1797
|
+
"border-inline-start-color": layoutStylePatchValue$1,
|
|
1798
|
+
"border-inline-start-style": layoutStylePatchValue$1,
|
|
1799
|
+
"border-inline-start-width": layoutStylePatchValue$1,
|
|
1800
|
+
"border-left": layoutStylePatchValue$1,
|
|
1801
|
+
"border-left-color": layoutStylePatchValue$1,
|
|
1802
|
+
"border-left-style": layoutStylePatchValue$1,
|
|
1803
|
+
"border-left-width": dimensionalStyleValue$1.optional(),
|
|
1804
|
+
"border-radius": dimensionalStyleValue$1.nullable().optional(),
|
|
1805
|
+
"border-right": layoutStylePatchValue$1,
|
|
1806
|
+
"border-right-color": layoutStylePatchValue$1,
|
|
1807
|
+
"border-right-style": layoutStylePatchValue$1,
|
|
1808
|
+
"border-right-width": dimensionalStyleValue$1.optional(),
|
|
1809
|
+
"border-style": layoutStylePatchValue$1,
|
|
1810
|
+
"border-top": layoutStylePatchValue$1,
|
|
1811
|
+
"border-top-color": layoutStylePatchValue$1,
|
|
1812
|
+
"border-top-style": layoutStylePatchValue$1,
|
|
1813
|
+
"border-top-left-radius": dimensionalStyleValue$1.optional(),
|
|
1814
|
+
"border-top-right-radius": dimensionalStyleValue$1.optional(),
|
|
1815
|
+
"border-top-width": dimensionalStyleValue$1.optional(),
|
|
1816
|
+
"border-width": dimensionalStyleValue$1.nullable().optional(),
|
|
1817
|
+
outline: layoutStylePatchValue$1,
|
|
1818
|
+
"outline-color": layoutStylePatchValue$1,
|
|
1819
|
+
"outline-style": layoutStylePatchValue$1,
|
|
1820
|
+
"outline-offset": dimensionalStyleValue$1.optional(),
|
|
1821
|
+
"outline-width": dimensionalStyleValue$1.optional()
|
|
1822
|
+
});
|
|
1961
1823
|
|
|
1962
1824
|
//#endregion
|
|
1963
1825
|
//#region ../../packages/contract/src/canvas/canvas-operation-styles.schema.ts
|
|
@@ -2025,11 +1887,37 @@ const canvasTextStylesSchema = z.strictObject({
|
|
|
2025
1887
|
"text-align": textStyleValues["text-align"].optional(),
|
|
2026
1888
|
"white-space": textStyleValues["white-space"].optional()
|
|
2027
1889
|
});
|
|
1890
|
+
const restorableTextStyleValue = z.union([canvasAdditionalStyleSchema.shape.value, boundedCanvasNumberSchema]).nullable().optional();
|
|
2028
1891
|
const canvasTextStylePatchSchema = z.strictObject({
|
|
1892
|
+
"text-decoration": restorableTextStyleValue,
|
|
1893
|
+
"text-decoration-line": restorableTextStyleValue,
|
|
1894
|
+
"text-decoration-style": restorableTextStyleValue,
|
|
1895
|
+
"text-decoration-color": restorableTextStyleValue,
|
|
1896
|
+
"text-decoration-thickness": restorableTextStyleValue,
|
|
1897
|
+
"text-underline-offset": restorableTextStyleValue,
|
|
1898
|
+
"text-decoration-skip-ink": restorableTextStyleValue,
|
|
2029
1899
|
color: textStyleValues.color.nullable().optional(),
|
|
2030
|
-
"font-family":
|
|
1900
|
+
"font-family": canvasAdditionalStyleSchema.shape.value.nullable().optional(),
|
|
2031
1901
|
"font-size": z.union([nonNegativeCanvasNumberSchema, nonNegativePixelLengthSchema]).nullable().optional(),
|
|
2032
|
-
"font-weight": z.
|
|
1902
|
+
"font-weight": z.union([
|
|
1903
|
+
canvasTypographySchema.shape.weight,
|
|
1904
|
+
z.enum([
|
|
1905
|
+
"normal",
|
|
1906
|
+
"bold",
|
|
1907
|
+
"bolder",
|
|
1908
|
+
"lighter"
|
|
1909
|
+
]),
|
|
1910
|
+
z.string().regex(/^\d+(?:\.\d+)?$/u).refine((value) => canvasTypographySchema.shape.weight.safeParse(Number(value)).success)
|
|
1911
|
+
]).nullable().optional(),
|
|
1912
|
+
"font-optical-sizing": z.enum(["auto", "none"]).nullable().optional(),
|
|
1913
|
+
"font-variation-settings": canvasAdditionalStyleSchema.shape.value.nullable().optional(),
|
|
1914
|
+
"font-feature-settings": canvasAdditionalStyleSchema.shape.value.nullable().optional(),
|
|
1915
|
+
"text-wrap": canvasAdditionalStyleSchema.shape.value.nullable().optional(),
|
|
1916
|
+
"text-wrap-mode": canvasAdditionalStyleSchema.shape.value.nullable().optional(),
|
|
1917
|
+
"text-wrap-style": canvasAdditionalStyleSchema.shape.value.nullable().optional(),
|
|
1918
|
+
"text-box": canvasAdditionalStyleSchema.shape.value.nullable().optional(),
|
|
1919
|
+
"text-box-trim": canvasAdditionalStyleSchema.shape.value.nullable().optional(),
|
|
1920
|
+
"text-box-edge": canvasAdditionalStyleSchema.shape.value.nullable().optional(),
|
|
2033
1921
|
"font-style": textStyleValues["font-style"].nullable().optional(),
|
|
2034
1922
|
"font-stretch": z.union([z.enum([
|
|
2035
1923
|
"normal",
|
|
@@ -2060,7 +1948,7 @@ const canvasTextStylePatchSchema = z.strictObject({
|
|
|
2060
1948
|
const overflowStyleValue = canvasAdditionalStyleSchema.shape.value;
|
|
2061
1949
|
const dimensionalStyleValue = z.union([z.string(), boundedCanvasNumberSchema]);
|
|
2062
1950
|
const layoutStylePatchValue = z.union([canvasAdditionalStyleSchema.shape.value, boundedCanvasNumberSchema]).nullable().optional();
|
|
2063
|
-
const
|
|
1951
|
+
const canvasKnownNodeStylePatchSchema = canvasTextStylePatchSchema.extend(canvasDecorationStylePatchSchema.shape).extend({
|
|
2064
1952
|
"align-content": layoutStylePatchValue,
|
|
2065
1953
|
"align-items": layoutStylePatchValue,
|
|
2066
1954
|
"align-self": layoutStylePatchValue,
|
|
@@ -2115,23 +2003,6 @@ const canvasNodeStylePatchSchema = canvasTextStylePatchSchema.extend({
|
|
|
2115
2003
|
width: layoutStylePatchValue,
|
|
2116
2004
|
background: z.string().nullable().optional(),
|
|
2117
2005
|
"background-color": z.string().nullable().optional(),
|
|
2118
|
-
"border-bottom-left-radius": dimensionalStyleValue.optional(),
|
|
2119
|
-
"border-bottom-right-radius": dimensionalStyleValue.optional(),
|
|
2120
|
-
"border-bottom-width": dimensionalStyleValue.optional(),
|
|
2121
|
-
"border-color": z.string().nullable().optional(),
|
|
2122
|
-
"border-left-width": dimensionalStyleValue.optional(),
|
|
2123
|
-
"border-radius": dimensionalStyleValue.nullable().optional(),
|
|
2124
|
-
"border-right-width": dimensionalStyleValue.optional(),
|
|
2125
|
-
"border-style": z.enum([
|
|
2126
|
-
"none",
|
|
2127
|
-
"solid",
|
|
2128
|
-
"dashed",
|
|
2129
|
-
"dotted"
|
|
2130
|
-
]).nullable().optional(),
|
|
2131
|
-
"border-top-left-radius": dimensionalStyleValue.optional(),
|
|
2132
|
-
"border-top-right-radius": dimensionalStyleValue.optional(),
|
|
2133
|
-
"border-top-width": dimensionalStyleValue.optional(),
|
|
2134
|
-
"border-width": dimensionalStyleValue.nullable().optional(),
|
|
2135
2006
|
"box-shadow": z.string().nullable().optional(),
|
|
2136
2007
|
"column-gap": dimensionalStyleValue.optional(),
|
|
2137
2008
|
gap: dimensionalStyleValue.optional(),
|
|
@@ -2140,8 +2011,6 @@ const canvasNodeStylePatchSchema = canvasTextStylePatchSchema.extend({
|
|
|
2140
2011
|
"margin-right": dimensionalStyleValue.optional(),
|
|
2141
2012
|
"margin-top": dimensionalStyleValue.optional(),
|
|
2142
2013
|
opacity: z.union([z.string(), z.number()]).nullable().optional(),
|
|
2143
|
-
"outline-offset": dimensionalStyleValue.optional(),
|
|
2144
|
-
"outline-width": dimensionalStyleValue.optional(),
|
|
2145
2014
|
overflow: overflowStyleValue.nullable().optional(),
|
|
2146
2015
|
"overflow-x": overflowStyleValue.nullable().optional(),
|
|
2147
2016
|
"overflow-y": overflowStyleValue.nullable().optional(),
|
|
@@ -2152,6 +2021,142 @@ const canvasNodeStylePatchSchema = canvasTextStylePatchSchema.extend({
|
|
|
2152
2021
|
"row-gap": dimensionalStyleValue.optional(),
|
|
2153
2022
|
"stroke-width": dimensionalStyleValue.optional()
|
|
2154
2023
|
});
|
|
2024
|
+
const canvasRestorableStylePropertySchema = z.union([canvasKnownNodeStylePatchSchema.keyof(), canvasAdditionalStyleSchema.shape.property.refine((property) => property.startsWith("--"))]);
|
|
2025
|
+
const canvasNodeStylePatchSchema = canvasKnownNodeStylePatchSchema.catchall(layoutStylePatchValue).refine((styles) => Object.keys(styles).every((property) => canvasRestorableStylePropertySchema.safeParse(property).success));
|
|
2026
|
+
|
|
2027
|
+
//#endregion
|
|
2028
|
+
//#region ../../packages/contract/src/canvas/canvas-text-change.schema.ts
|
|
2029
|
+
const MAX_CANVAS_TEXT_LENGTH = 1e5;
|
|
2030
|
+
const MAX_CANVAS_TEXT_ACTION_ID_LENGTH = 200;
|
|
2031
|
+
const MAX_TEXT_ATTRIBUTES = 128;
|
|
2032
|
+
const attributesSchema = z.record(z.string().max(200), z.unknown()).refine((attributes) => Object.keys(attributes).length <= MAX_TEXT_ATTRIBUTES);
|
|
2033
|
+
const countSchema$1 = z.number().int().positive().max(MAX_CANVAS_TEXT_LENGTH);
|
|
2034
|
+
const canvasTextStepSchema = z.discriminatedUnion("kind", [
|
|
2035
|
+
z.object({
|
|
2036
|
+
kind: z.literal("retain"),
|
|
2037
|
+
count: countSchema$1,
|
|
2038
|
+
attributes: attributesSchema.optional()
|
|
2039
|
+
}),
|
|
2040
|
+
z.object({
|
|
2041
|
+
kind: z.literal("delete"),
|
|
2042
|
+
count: countSchema$1
|
|
2043
|
+
}),
|
|
2044
|
+
z.object({
|
|
2045
|
+
kind: z.literal("insert"),
|
|
2046
|
+
text: z.string().min(1).max(MAX_CANVAS_TEXT_LENGTH).refine((text) => text.isWellFormed()),
|
|
2047
|
+
attributes: attributesSchema.optional()
|
|
2048
|
+
})
|
|
2049
|
+
]);
|
|
2050
|
+
const canvasTextChangeSchema = z.object({
|
|
2051
|
+
baseLength: z.number().int().nonnegative().max(MAX_CANVAS_TEXT_LENGTH),
|
|
2052
|
+
representation: z.enum([
|
|
2053
|
+
"plain",
|
|
2054
|
+
"rich",
|
|
2055
|
+
"links"
|
|
2056
|
+
]).optional(),
|
|
2057
|
+
steps: z.array(canvasTextStepSchema).max(MAX_CANVAS_TEXT_LENGTH),
|
|
2058
|
+
endAttributes: attributesSchema.optional(),
|
|
2059
|
+
properties: attributesSchema.refine((properties) => [
|
|
2060
|
+
"text",
|
|
2061
|
+
"richText",
|
|
2062
|
+
"links"
|
|
2063
|
+
].every((key) => !Object.hasOwn(properties, key))).optional()
|
|
2064
|
+
}).superRefine((change, context) => {
|
|
2065
|
+
let consumed = 0;
|
|
2066
|
+
let produced = 0;
|
|
2067
|
+
for (const step of change.steps) {
|
|
2068
|
+
if (step.kind !== "insert") consumed += step.count;
|
|
2069
|
+
if (step.kind !== "delete") produced += step.kind === "insert" ? step.text.length : step.count;
|
|
2070
|
+
}
|
|
2071
|
+
if (consumed !== change.baseLength || produced > 1e5) context.addIssue({
|
|
2072
|
+
code: "custom",
|
|
2073
|
+
message: "text change must consume its exact base and fit the text limit"
|
|
2074
|
+
});
|
|
2075
|
+
});
|
|
2076
|
+
const canvasTextHistoryTargetSchema = z.object({
|
|
2077
|
+
actionId: z.string().min(1).max(200),
|
|
2078
|
+
baseVersion: z.number().int().nonnegative(),
|
|
2079
|
+
isActive: z.boolean()
|
|
2080
|
+
});
|
|
2081
|
+
const MAX_TEXT_SOURCE_ACTIONS = 4e3;
|
|
2082
|
+
const canvasTextSourceSchema = z.object({
|
|
2083
|
+
baseVersion: z.number().int().nonnegative(),
|
|
2084
|
+
after: z.array(z.string().min(1).max(200)).max(MAX_TEXT_SOURCE_ACTIONS),
|
|
2085
|
+
change: canvasTextChangeSchema
|
|
2086
|
+
});
|
|
2087
|
+
const canvasTextRevisionSchema = z.object({
|
|
2088
|
+
actionId: z.string().min(1).max(200),
|
|
2089
|
+
baseVersion: z.number().int().nonnegative(),
|
|
2090
|
+
originalChange: canvasTextChangeSchema,
|
|
2091
|
+
inverse: canvasTextChangeSchema,
|
|
2092
|
+
history: canvasTextHistoryTargetSchema.optional(),
|
|
2093
|
+
source: canvasTextSourceSchema.optional()
|
|
2094
|
+
});
|
|
2095
|
+
const canvasEditTextOperationSchema = z.object({
|
|
2096
|
+
op: z.literal("editText"),
|
|
2097
|
+
nodeId: z.string().min(1).max(200),
|
|
2098
|
+
change: canvasTextChangeSchema,
|
|
2099
|
+
actionId: z.string().min(1).max(200).optional(),
|
|
2100
|
+
revision: canvasTextRevisionSchema.optional(),
|
|
2101
|
+
history: canvasTextHistoryTargetSchema.optional(),
|
|
2102
|
+
source: canvasTextSourceSchema.optional()
|
|
2103
|
+
});
|
|
2104
|
+
|
|
2105
|
+
//#endregion
|
|
2106
|
+
//#region ../../packages/contract/src/canvas/text-style-library.schema.ts
|
|
2107
|
+
const MAX_STYLES = 1e3;
|
|
2108
|
+
const MAX_DESCRIPTION = 2e3;
|
|
2109
|
+
const MAX_TITLE = 200;
|
|
2110
|
+
const MAX_PAGE = 50;
|
|
2111
|
+
const DEFAULT_PAGE = 20;
|
|
2112
|
+
const enabledTextStyleLibrarySchema = z.object({ title: z.string().trim().min(1).max(MAX_TITLE) }).strict();
|
|
2113
|
+
const styleIds = z.array(canvasTextStyleSchema.shape.id).max(MAX_STYLES);
|
|
2114
|
+
const textStyleLibraryIdentitySchema = z.object({ canvasId: z.uuid() });
|
|
2115
|
+
const publishedTextStyleSchema = z.object({
|
|
2116
|
+
definition: canvasTextStyleSchema.refine((style) => style.sourceStyleId === void 0),
|
|
2117
|
+
revision: z.number().int().positive(),
|
|
2118
|
+
fontFaces: z.array(z.record(z.string(), z.unknown()))
|
|
2119
|
+
});
|
|
2120
|
+
const textStyleLibraryPayloadSchema = z.object({ styles: z.array(publishedTextStyleSchema).max(MAX_STYLES).refine((styles) => new Set(styles.map((style) => style.definition.id)).size === styles.length) });
|
|
2121
|
+
const textStyleLibrarySchema = textStyleLibraryIdentitySchema.extend({
|
|
2122
|
+
revision: z.number().int().positive(),
|
|
2123
|
+
documentVersion: z.number().int().positive(),
|
|
2124
|
+
description: z.string().max(MAX_DESCRIPTION),
|
|
2125
|
+
publishedAt: z.iso.datetime(),
|
|
2126
|
+
...textStyleLibraryPayloadSchema.shape
|
|
2127
|
+
});
|
|
2128
|
+
const publishTextStyleLibraryInputSchema = textStyleLibraryIdentitySchema.extend({
|
|
2129
|
+
mutationId: z.uuid(),
|
|
2130
|
+
expectedRevision: z.number().int().nonnegative(),
|
|
2131
|
+
documentVersion: z.number().int().positive(),
|
|
2132
|
+
publish: styleIds,
|
|
2133
|
+
remove: styleIds,
|
|
2134
|
+
description: z.string().trim().max(MAX_DESCRIPTION)
|
|
2135
|
+
}).strict().refine((input) => {
|
|
2136
|
+
const ids = [...input.publish, ...input.remove];
|
|
2137
|
+
return ids.length > 0 && ids.length <= MAX_STYLES && new Set(ids).size === ids.length;
|
|
2138
|
+
}, { message: "Select each changed style once." });
|
|
2139
|
+
const libraryCursorSchema = z.object({
|
|
2140
|
+
canvasId: z.uuid(),
|
|
2141
|
+
title: z.string().max(MAX_TITLE)
|
|
2142
|
+
});
|
|
2143
|
+
const listTextStyleLibrariesInputSchema = z.object({
|
|
2144
|
+
search: z.string().trim().max(MAX_TITLE).default(""),
|
|
2145
|
+
cursor: libraryCursorSchema.nullable().default(null),
|
|
2146
|
+
limit: z.number().int().min(1).max(MAX_PAGE).default(DEFAULT_PAGE)
|
|
2147
|
+
});
|
|
2148
|
+
const textStyleLibrarySummarySchema = z.object({
|
|
2149
|
+
canvasId: z.uuid(),
|
|
2150
|
+
title: z.string(),
|
|
2151
|
+
organisationId: z.uuid().nullable(),
|
|
2152
|
+
revision: z.number().int().positive(),
|
|
2153
|
+
styleCount: z.number().int().positive(),
|
|
2154
|
+
publishedAt: z.iso.datetime()
|
|
2155
|
+
});
|
|
2156
|
+
const listTextStyleLibrariesOutputSchema = z.object({
|
|
2157
|
+
items: z.array(textStyleLibrarySummarySchema).max(MAX_PAGE),
|
|
2158
|
+
nextCursor: libraryCursorSchema.nullable()
|
|
2159
|
+
});
|
|
2155
2160
|
|
|
2156
2161
|
//#endregion
|
|
2157
2162
|
//#region ../../packages/contract/src/canvas/canvas-operation.schema.ts
|
|
@@ -2167,11 +2172,11 @@ const insertConvertedSubtreeOperationSchema = z.object({
|
|
|
2167
2172
|
nodes: z.record(z.string().min(1).max(200), canvasSceneNodeSchema).refine((nodes) => Object.keys(nodes).length <= MAX_CANVAS_CONVERSION_NODES),
|
|
2168
2173
|
relationships: z.record(z.string().min(1).max(200), convertedSubtreeRelationshipSchema).refine((relationships) => Object.keys(relationships).length < MAX_CANVAS_CONVERSION_NODES)
|
|
2169
2174
|
});
|
|
2170
|
-
const MAX_NODE_ID_LENGTH$
|
|
2175
|
+
const MAX_NODE_ID_LENGTH$6 = 200;
|
|
2171
2176
|
const MAX_LABEL_LENGTH$1 = 500;
|
|
2172
2177
|
const MAX_TEXT_LENGTH$1 = 1e5;
|
|
2173
2178
|
const MAX_CANVAS_OPERATIONS = 1e3;
|
|
2174
|
-
const nodeIdSchema$1 = z.string().min(1).max(MAX_NODE_ID_LENGTH$
|
|
2179
|
+
const nodeIdSchema$1 = z.string().min(1).max(MAX_NODE_ID_LENGTH$6);
|
|
2175
2180
|
const sortKeySchema = z.string().min(1).max(MAX_LABEL_LENGTH$1);
|
|
2176
2181
|
const writableBoxSchema = canvasSceneBoxSchema.extend({
|
|
2177
2182
|
width: z.number().positive(),
|
|
@@ -2189,7 +2194,7 @@ const canvasSetStylesOperationSchema = z.object({
|
|
|
2189
2194
|
op: z.literal("setStyles"),
|
|
2190
2195
|
nodeId: nodeIdSchema$1,
|
|
2191
2196
|
styles: canvasNodeStylePatchSchema,
|
|
2192
|
-
clear: z.array(
|
|
2197
|
+
clear: z.array(canvasRestorableStylePropertySchema).min(1).max(Object.keys(canvasNodeStylePatchSchema.shape).length).refine((properties) => new Set(properties).size === properties.length).optional()
|
|
2193
2198
|
}).refine((operation) => (operation.clear ?? []).every((property) => !Object.hasOwn(operation.styles, property)));
|
|
2194
2199
|
const canvasOperationSchema = z.discriminatedUnion("op", [
|
|
2195
2200
|
insertConvertedSubtreeOperationSchema,
|
|
@@ -2221,6 +2226,7 @@ const canvasOperationSchema = z.discriminatedUnion("op", [
|
|
|
2221
2226
|
prototypeId: z.uuid(),
|
|
2222
2227
|
deploymentId: z.uuid()
|
|
2223
2228
|
}),
|
|
2229
|
+
canvasEditTextOperationSchema,
|
|
2224
2230
|
z.object({
|
|
2225
2231
|
op: z.literal("setText"),
|
|
2226
2232
|
nodeId: nodeIdSchema$1,
|
|
@@ -2268,16 +2274,43 @@ const canvasOperationSchema = z.discriminatedUnion("op", [
|
|
|
2268
2274
|
nodeId: nodeIdSchema$1,
|
|
2269
2275
|
layout: z.union([canvasNodeLayoutSchema, z.literal("default")])
|
|
2270
2276
|
}),
|
|
2277
|
+
z.object({
|
|
2278
|
+
op: z.literal("patchTypography"),
|
|
2279
|
+
nodeId: nodeIdSchema$1,
|
|
2280
|
+
typography: canvasTypographyPatchSchema
|
|
2281
|
+
}),
|
|
2271
2282
|
z.object({
|
|
2272
2283
|
op: z.literal("setTypography"),
|
|
2273
2284
|
nodeId: nodeIdSchema$1,
|
|
2274
|
-
typography: z.union([
|
|
2285
|
+
typography: z.union([canvasAuthoredTypographySchema, z.literal("default")])
|
|
2286
|
+
}),
|
|
2287
|
+
z.object({
|
|
2288
|
+
op: z.literal("patchAdditionalStyles"),
|
|
2289
|
+
nodeId: nodeIdSchema$1,
|
|
2290
|
+
additionalStyles: canvasAdditionalStylePatchSchema
|
|
2275
2291
|
}),
|
|
2276
2292
|
z.object({
|
|
2277
2293
|
op: z.literal("setAdditionalStyles"),
|
|
2278
2294
|
nodeId: nodeIdSchema$1,
|
|
2279
2295
|
additionalStyles: z.union([canvasAdditionalStylesSchema, z.literal("default")])
|
|
2280
2296
|
}),
|
|
2297
|
+
z.object({
|
|
2298
|
+
op: z.literal("setTextStyleLibrary"),
|
|
2299
|
+
nodeId: z.literal("root"),
|
|
2300
|
+
sourceCanvasId: z.uuid(),
|
|
2301
|
+
library: enabledTextStyleLibrarySchema.nullable()
|
|
2302
|
+
}),
|
|
2303
|
+
z.object({
|
|
2304
|
+
op: z.literal("patchFontLibrary"),
|
|
2305
|
+
nodeId: z.literal("root"),
|
|
2306
|
+
fonts: canvasFontLibraryPatchSchema
|
|
2307
|
+
}),
|
|
2308
|
+
z.object({
|
|
2309
|
+
op: z.literal("setTextStyle"),
|
|
2310
|
+
nodeId: z.literal("root"),
|
|
2311
|
+
styleId: canvasTextStyleSchema.shape.id,
|
|
2312
|
+
textStyle: canvasTextStyleSchema.nullable()
|
|
2313
|
+
}).refine((operation) => operation.textStyle === null || operation.textStyle.id === operation.styleId, "text style identity must match"),
|
|
2281
2314
|
z.object({
|
|
2282
2315
|
op: z.literal("setProps"),
|
|
2283
2316
|
nodeId: nodeIdSchema$1,
|
|
@@ -2294,7 +2327,8 @@ const canvasOperationSchema = z.discriminatedUnion("op", [
|
|
|
2294
2327
|
}),
|
|
2295
2328
|
z.object({
|
|
2296
2329
|
op: z.literal("remove"),
|
|
2297
|
-
nodeId: nodeIdSchema$1
|
|
2330
|
+
nodeId: nodeIdSchema$1,
|
|
2331
|
+
removedText: z.record(nodeIdSchema$1, canvasSceneNodeSchema.pick({ props: true })).optional()
|
|
2298
2332
|
})
|
|
2299
2333
|
]);
|
|
2300
2334
|
const applyCanvasOperationsInputSchema = z.object({
|
|
@@ -2309,6 +2343,7 @@ const applyCanvasOperationsOutputSchema = z.object({
|
|
|
2309
2343
|
mutationId: z.uuid(),
|
|
2310
2344
|
previousVersion: z.number().int().positive(),
|
|
2311
2345
|
version: z.number().int().positive(),
|
|
2346
|
+
operations: z.array(canvasOperationSchema),
|
|
2312
2347
|
insertedNodeIds: z.array(nodeIdSchema$1),
|
|
2313
2348
|
changedNodeIds: z.array(nodeIdSchema$1),
|
|
2314
2349
|
removedNodeIds: z.array(nodeIdSchema$1),
|
|
@@ -2316,18 +2351,566 @@ const applyCanvasOperationsOutputSchema = z.object({
|
|
|
2316
2351
|
affectedBounds: writableBoxSchema.nullable(),
|
|
2317
2352
|
next: z.array(z.string().min(1))
|
|
2318
2353
|
});
|
|
2319
|
-
const createEditableFrameOutputSchema = createEditableFrameResultSchema.extend({
|
|
2320
|
-
operation: insertConvertedSubtreeOperationSchema,
|
|
2354
|
+
const createEditableFrameOutputSchema = createEditableFrameResultSchema.extend({
|
|
2355
|
+
operation: insertConvertedSubtreeOperationSchema,
|
|
2356
|
+
next: z.array(z.string().min(1))
|
|
2357
|
+
});
|
|
2358
|
+
|
|
2359
|
+
//#endregion
|
|
2360
|
+
//#region ../../packages/contract/src/canvas/canvas-document.schema.ts
|
|
2361
|
+
/** More screens than one canvas has ever held, and a bound on one save's work. */
|
|
2362
|
+
const MAX_SCREENS_PER_DOCUMENT = 2e3;
|
|
2363
|
+
/** Reads retain unsupported documents; the write boundary validates the current scene format. */
|
|
2364
|
+
const canvasDocumentBlobSchema = z.record(z.string(), z.unknown());
|
|
2365
|
+
const getCanvasDocumentInputSchema = z.object({
|
|
2366
|
+
canvasId: z.uuid(),
|
|
2367
|
+
afterVersion: z.number().int().positive().optional()
|
|
2368
|
+
});
|
|
2369
|
+
const documentScreenSchema = z.object({
|
|
2370
|
+
screenId: z.uuid(),
|
|
2371
|
+
/** Null for a link visitor. Always present on the agent surface. */
|
|
2372
|
+
route: z.string().max(MAX_URL_LENGTH).nullable(),
|
|
2373
|
+
title: z.string().max(200).nullable(),
|
|
2374
|
+
viewport: z.object({
|
|
2375
|
+
width: z.number().int().positive(),
|
|
2376
|
+
height: z.number().int().positive()
|
|
2377
|
+
}),
|
|
2378
|
+
atMs: z.number().int().min(0).nullable(),
|
|
2379
|
+
sourceRecordingId: z.uuid().nullable(),
|
|
2380
|
+
/** Durable rendering dependency, deliberately independent of recording provenance. */
|
|
2381
|
+
assetBundle: z.object({
|
|
2382
|
+
assetBundleId: z.uuid(),
|
|
2383
|
+
sourceUrl: z.string().max(MAX_URL_LENGTH),
|
|
2384
|
+
assets: z.array(z.object({
|
|
2385
|
+
url: z.string().max(MAX_URL_LENGTH),
|
|
2386
|
+
contentType: z.string().max(200),
|
|
2387
|
+
path: z.string().startsWith("/v1/recording-assets/")
|
|
2388
|
+
})),
|
|
2389
|
+
missingAssetCount: z.number().int().min(0)
|
|
2390
|
+
}).nullable(),
|
|
2391
|
+
/** Null while the blob has not landed. The client draws an empty frame with its label. */
|
|
2392
|
+
download: signedDownloadSchema.nullable()
|
|
2393
|
+
});
|
|
2394
|
+
const canvasMutationRevisionSchema = z.object({
|
|
2395
|
+
mutationId: z.uuid(),
|
|
2396
|
+
previousVersion: z.number().int().positive(),
|
|
2397
|
+
version: z.number().int().positive(),
|
|
2398
|
+
operations: z.array(canvasOperationSchema)
|
|
2399
|
+
});
|
|
2400
|
+
const getCanvasDocumentOutputSchema = z.object({
|
|
2401
|
+
mutations: z.array(canvasMutationRevisionSchema).optional(),
|
|
2402
|
+
version: z.number().int().min(1),
|
|
2403
|
+
document: canvasDocumentBlobSchema,
|
|
2404
|
+
/** The manifest, resolved and signed. This is what makes a cold open one round trip. */
|
|
2405
|
+
screens: z.array(documentScreenSchema)
|
|
2406
|
+
});
|
|
2407
|
+
const saveCanvasDocumentInputSchema = z.object({
|
|
2408
|
+
canvasId: z.uuid(),
|
|
2409
|
+
baseVersion: z.number().int().min(1),
|
|
2410
|
+
document: canvasDocumentBlobSchema.refine((document) => canvasSceneDocumentSchema.safeParse(document).success, "A save requires a valid current-format canvas document."),
|
|
2411
|
+
/** Every screen the document names. Replaces the manifest wholesale. */
|
|
2412
|
+
screenIds: z.array(z.uuid()).max(MAX_SCREENS_PER_DOCUMENT)
|
|
2413
|
+
});
|
|
2414
|
+
/**
|
|
2415
|
+
* A conflict is an outcome, not an error. `AppError` is `{ code, message, fields? }` and a
|
|
2416
|
+
* whole document does not fit in it — and a path that is expected to fire should not go
|
|
2417
|
+
* through the error log line and the tRPC error protocol on its way to a merge dialog.
|
|
2418
|
+
*/
|
|
2419
|
+
const saveCanvasDocumentOutputSchema = z.discriminatedUnion("outcome", [z.object({
|
|
2420
|
+
outcome: z.literal("saved"),
|
|
2421
|
+
version: z.number().int().min(1)
|
|
2422
|
+
}), z.object({
|
|
2423
|
+
outcome: z.literal("conflict"),
|
|
2424
|
+
version: z.number().int().min(1),
|
|
2425
|
+
document: canvasDocumentBlobSchema
|
|
2426
|
+
})]);
|
|
2427
|
+
|
|
2428
|
+
//#endregion
|
|
2429
|
+
//#region ../../packages/contract/src/canvas/canvas-image-asset.schema.ts
|
|
2430
|
+
const CANVAS_ASSET_PATH_PREFIX = "/v1/canvas-assets/";
|
|
2431
|
+
const CANVAS_IMAGE_CONTENT_TYPES = [
|
|
2432
|
+
"image/avif",
|
|
2433
|
+
"image/gif",
|
|
2434
|
+
"image/jpeg",
|
|
2435
|
+
"image/png",
|
|
2436
|
+
"image/webp"
|
|
2437
|
+
];
|
|
2438
|
+
const BYTES_PER_KIBIBYTE$1 = 1024;
|
|
2439
|
+
const KIBIBYTES_PER_MEBIBYTE$1 = 1024;
|
|
2440
|
+
const MAX_CANVAS_IMAGE_MEBIBYTES = 20;
|
|
2441
|
+
const MAX_CANVAS_IMAGE_BYTES = MAX_CANVAS_IMAGE_MEBIBYTES * BYTES_PER_KIBIBYTE$1 * KIBIBYTES_PER_MEBIBYTE$1;
|
|
2442
|
+
const reserveCanvasImageInputSchema = z.object({
|
|
2443
|
+
canvasId: z.uuid(),
|
|
2444
|
+
contentType: z.enum(CANVAS_IMAGE_CONTENT_TYPES),
|
|
2445
|
+
bytes: z.number().int().positive().max(MAX_CANVAS_IMAGE_BYTES)
|
|
2446
|
+
});
|
|
2447
|
+
const reserveCanvasImageOutputSchema = z.object({
|
|
2448
|
+
assetId: z.uuid(),
|
|
2449
|
+
path: z.string().startsWith("/v1/canvas-assets/"),
|
|
2450
|
+
upload: signedUploadSchema
|
|
2451
|
+
});
|
|
2452
|
+
const canvasImageAssetPath = (canvasId, assetId) => `${CANVAS_ASSET_PATH_PREFIX}${encodeURIComponent(canvasId)}/${encodeURIComponent(assetId)}`;
|
|
2453
|
+
|
|
2454
|
+
//#endregion
|
|
2455
|
+
//#region ../../packages/contract/src/canvas/canvas-font-asset.schema.ts
|
|
2456
|
+
const BYTES_PER_KIBIBYTE = 1024;
|
|
2457
|
+
const KIBIBYTES_PER_MEBIBYTE = 1024;
|
|
2458
|
+
const MAX_FONT_MEBIBYTES = 20;
|
|
2459
|
+
const MAX_CANVAS_FONT_BYTES = MAX_FONT_MEBIBYTES * BYTES_PER_KIBIBYTE * KIBIBYTES_PER_MEBIBYTE;
|
|
2460
|
+
const CANVAS_FONT_CONTENT_TYPES = [
|
|
2461
|
+
"font/ttf",
|
|
2462
|
+
"font/otf",
|
|
2463
|
+
"font/woff",
|
|
2464
|
+
"font/woff2"
|
|
2465
|
+
];
|
|
2466
|
+
const canvasFontAssetIdentitySchema = z.object({
|
|
2467
|
+
canvasId: z.uuid(),
|
|
2468
|
+
sha256: z.string().regex(/^[a-f0-9]{64}$/u)
|
|
2469
|
+
});
|
|
2470
|
+
const completeCanvasFontInputSchema = canvasFontAssetIdentitySchema.extend({ bytes: z.number().int().positive().max(MAX_CANVAS_FONT_BYTES) });
|
|
2471
|
+
const reserveCanvasFontInputSchema = completeCanvasFontInputSchema.extend({ contentType: z.enum(CANVAS_FONT_CONTENT_TYPES) });
|
|
2472
|
+
const completeCanvasFontOutputSchema = z.object({ path: z.string().startsWith("/v1/canvas-assets/") });
|
|
2473
|
+
const reserveCanvasFontOutputSchema = completeCanvasFontOutputSchema.extend({ upload: signedUploadSchema });
|
|
2474
|
+
const canvasFontAssetPath = (canvasId, sha256) => `${CANVAS_ASSET_PATH_PREFIX}${encodeURIComponent(canvasId)}/fonts/${encodeURIComponent(sha256)}`;
|
|
2475
|
+
const copyCanvasFontsInputSchema = z.object({
|
|
2476
|
+
canvasId: z.uuid(),
|
|
2477
|
+
sources: z.array(canvasFontAssetIdentitySchema).min(1).max(100)
|
|
2478
|
+
});
|
|
2479
|
+
const copyCanvasFontsOutputSchema = z.object({ resources: z.array(z.object({
|
|
2480
|
+
source: canvasFontAssetIdentitySchema,
|
|
2481
|
+
path: z.string()
|
|
2482
|
+
})) });
|
|
2483
|
+
|
|
2484
|
+
//#endregion
|
|
2485
|
+
//#region ../../packages/contract/src/canvas/canvas-property-section.schema.ts
|
|
2486
|
+
const CANVAS_PROPERTY_SECTIONS = [
|
|
2487
|
+
"position",
|
|
2488
|
+
"layout",
|
|
2489
|
+
"clip",
|
|
2490
|
+
"cornerRadius",
|
|
2491
|
+
"blending",
|
|
2492
|
+
"typography",
|
|
2493
|
+
"nativeControl",
|
|
2494
|
+
"textDecoration",
|
|
2495
|
+
"fill",
|
|
2496
|
+
"outline",
|
|
2497
|
+
"textStroke",
|
|
2498
|
+
"border",
|
|
2499
|
+
"outerShadow",
|
|
2500
|
+
"innerShadow",
|
|
2501
|
+
"filters",
|
|
2502
|
+
"additionalStyles",
|
|
2503
|
+
"vector",
|
|
2504
|
+
"export",
|
|
2505
|
+
"source"
|
|
2506
|
+
];
|
|
2507
|
+
const canvasPropertySectionSchema = z.enum(CANVAS_PROPERTY_SECTIONS);
|
|
2508
|
+
|
|
2509
|
+
//#endregion
|
|
2510
|
+
//#region ../../packages/contract/src/canvas/canvas-inspection.schema.ts
|
|
2511
|
+
const MAX_NODE_ID_LENGTH$5 = 200;
|
|
2512
|
+
const MAX_RENDER_MESSAGE_LENGTH = 500;
|
|
2513
|
+
const MAX_RENDER_KIND_LENGTH = 100;
|
|
2514
|
+
const canvasInspectNodeSummarySchema = z.object({
|
|
2515
|
+
id: z.string().min(1).max(MAX_NODE_ID_LENGTH$5),
|
|
2516
|
+
label: z.string().max(MAX_RENDER_MESSAGE_LENGTH),
|
|
2517
|
+
kind: z.string().min(1).max(MAX_RENDER_KIND_LENGTH),
|
|
2518
|
+
parentId: z.string().min(1).max(MAX_NODE_ID_LENGTH$5).nullable(),
|
|
2519
|
+
childCount: z.number().int().min(0),
|
|
2520
|
+
box: canvasWorldBoundsSchema.nullable(),
|
|
2521
|
+
propertySections: z.array(canvasPropertySectionSchema)
|
|
2522
|
+
});
|
|
2523
|
+
const inspectCanvasInputSchema = z.object({ canvasId: z.uuid() });
|
|
2524
|
+
const inspectCanvasOutputSchema = z.object({
|
|
2525
|
+
canvasId: z.uuid(),
|
|
2526
|
+
openUrl: z.url(),
|
|
2527
|
+
title: z.string().min(1),
|
|
2528
|
+
version: z.number().int().positive(),
|
|
2529
|
+
nodeCount: z.number().int().min(0),
|
|
2530
|
+
rootChildCount: z.number().int().min(0),
|
|
2531
|
+
bounds: canvasWorldBoundsSchema.nullable(),
|
|
2532
|
+
kinds: z.record(z.string(), z.number().int().min(0)),
|
|
2533
|
+
next: z.array(z.string().min(1))
|
|
2534
|
+
});
|
|
2535
|
+
const inspectCanvasTreeInputSchema = z.object({ canvasId: z.uuid() });
|
|
2536
|
+
const inspectCanvasTreeOutputSchema = z.object({
|
|
2537
|
+
canvasId: z.uuid(),
|
|
2538
|
+
version: z.number().int().positive(),
|
|
2539
|
+
nodes: z.array(canvasInspectNodeSummarySchema)
|
|
2540
|
+
});
|
|
2541
|
+
const inspectCanvasNodeInputSchema = z.object({
|
|
2542
|
+
canvasId: z.uuid(),
|
|
2543
|
+
nodeId: z.string().min(1).max(MAX_NODE_ID_LENGTH$5)
|
|
2544
|
+
});
|
|
2545
|
+
const inspectCanvasNodeOutputSchema = z.object({
|
|
2546
|
+
canvasId: z.uuid(),
|
|
2547
|
+
version: z.number().int().positive(),
|
|
2548
|
+
node: canvasInspectNodeSummarySchema.extend({
|
|
2549
|
+
styles: z.record(z.string(), z.union([z.string(), z.number()])),
|
|
2550
|
+
layout: canvasNodeLayoutSchema.optional(),
|
|
2551
|
+
appearance: canvasAppearanceValuesSchema.optional(),
|
|
2552
|
+
typography: canvasAuthoredTypographySchema.optional(),
|
|
2553
|
+
additionalStyles: canvasAdditionalStylesSchema.optional(),
|
|
2554
|
+
props: z.record(z.string(), z.unknown()),
|
|
2555
|
+
children: z.array(z.string().min(1).max(MAX_NODE_ID_LENGTH$5))
|
|
2556
|
+
}),
|
|
2321
2557
|
next: z.array(z.string().min(1))
|
|
2322
2558
|
});
|
|
2323
2559
|
|
|
2560
|
+
//#endregion
|
|
2561
|
+
//#region ../../packages/contract/src/canvas/canvas-layout-ownership.lib.ts
|
|
2562
|
+
const CANVAS_LAYOUT_CSS_FIELDS = [
|
|
2563
|
+
["alignSelf", "align-self"],
|
|
2564
|
+
["order", "order"],
|
|
2565
|
+
["flexGrow", "flex-grow"],
|
|
2566
|
+
["flexShrink", "flex-shrink"],
|
|
2567
|
+
["flexBasis", "flex-basis"],
|
|
2568
|
+
["aspectRatio", "aspect-ratio"]
|
|
2569
|
+
];
|
|
2570
|
+
const CANVAS_CONTAINER_CSS_FIELDS = [
|
|
2571
|
+
["direction", "flex-direction"],
|
|
2572
|
+
["wrap", "flex-wrap"],
|
|
2573
|
+
["alignItems", "align-items"],
|
|
2574
|
+
["alignContent", "align-content"],
|
|
2575
|
+
["justifyContent", "justify-content"],
|
|
2576
|
+
["rowGap", "row-gap"],
|
|
2577
|
+
["columnGap", "column-gap"]
|
|
2578
|
+
];
|
|
2579
|
+
const SIDES = [
|
|
2580
|
+
"top",
|
|
2581
|
+
"right",
|
|
2582
|
+
"bottom",
|
|
2583
|
+
"left"
|
|
2584
|
+
];
|
|
2585
|
+
const releasedSpacing = (held, prefix, properties) => {
|
|
2586
|
+
const next = { ...held };
|
|
2587
|
+
for (const side of SIDES) if (properties.has(`${prefix}-${side}`)) Reflect.deleteProperty(next, side);
|
|
2588
|
+
return next;
|
|
2589
|
+
};
|
|
2590
|
+
/** A shorthand can release several named controls; a longhand releases only itself. */
|
|
2591
|
+
const releasedFields = (held, changed) => {
|
|
2592
|
+
const properties = new Set([...changed].flatMap((property) => canvasCssPropertyScope(property)));
|
|
2593
|
+
const layout = { ...held };
|
|
2594
|
+
for (const [key, property] of CANVAS_LAYOUT_CSS_FIELDS) if (properties.has(property)) Reflect.deleteProperty(layout, key);
|
|
2595
|
+
if (layout.margin !== void 0) layout.margin = releasedSpacing(layout.margin, "margin", properties);
|
|
2596
|
+
if (layout.container === void 0) return layout;
|
|
2597
|
+
const container = { ...layout.container };
|
|
2598
|
+
if ((properties.has("row-gap") || properties.has("column-gap")) && container.gap !== void 0) {
|
|
2599
|
+
container.rowGap ??= container.gap;
|
|
2600
|
+
container.columnGap ??= container.gap;
|
|
2601
|
+
Reflect.deleteProperty(container, "gap");
|
|
2602
|
+
}
|
|
2603
|
+
for (const [key, property] of CANVAS_CONTAINER_CSS_FIELDS) if (properties.has(property)) Reflect.deleteProperty(container, key);
|
|
2604
|
+
if (container.padding !== void 0) container.padding = releasedSpacing(container.padding, "padding", properties);
|
|
2605
|
+
if (properties.has("grid-template-columns")) {
|
|
2606
|
+
Reflect.deleteProperty(container, "gridColumns");
|
|
2607
|
+
Reflect.deleteProperty(container, "gridAutoRepeat");
|
|
2608
|
+
}
|
|
2609
|
+
layout.container = container;
|
|
2610
|
+
return layout;
|
|
2611
|
+
};
|
|
2612
|
+
const axisWithoutCssBounds = (intent, properties, changed) => {
|
|
2613
|
+
if (intent === void 0 || intent.mode === "fixed") return intent;
|
|
2614
|
+
const released = { ...intent };
|
|
2615
|
+
for (const bound of ["min", "max"]) {
|
|
2616
|
+
if (properties.every((property) => !changed.has(`${bound}-${property}`))) continue;
|
|
2617
|
+
Reflect.deleteProperty(released, bound);
|
|
2618
|
+
Reflect.deleteProperty(released, `${bound}Parent`);
|
|
2619
|
+
}
|
|
2620
|
+
return released;
|
|
2621
|
+
};
|
|
2622
|
+
/** Editors hand CSS control back property by property; absent presets stay absent. */
|
|
2623
|
+
const canvasLayoutWithoutCssProperties = (held, changed, axes) => {
|
|
2624
|
+
const properties = new Set([...changed].flatMap((property) => canvasCssPropertyScope(property)));
|
|
2625
|
+
const layout = releasedFields(held, properties);
|
|
2626
|
+
if ([
|
|
2627
|
+
"overflow",
|
|
2628
|
+
"overflow-x",
|
|
2629
|
+
"overflow-y"
|
|
2630
|
+
].some((property) => properties.has(property))) Reflect.deleteProperty(layout, "clipContent");
|
|
2631
|
+
if (properties.has("position")) Reflect.deleteProperty(layout, "position");
|
|
2632
|
+
if (properties.has("transform")) for (const key of [
|
|
2633
|
+
"rotation",
|
|
2634
|
+
"flipHorizontal",
|
|
2635
|
+
"flipVertical"
|
|
2636
|
+
]) Reflect.deleteProperty(layout, key);
|
|
2637
|
+
if ([
|
|
2638
|
+
"inset",
|
|
2639
|
+
"left",
|
|
2640
|
+
"right",
|
|
2641
|
+
"top",
|
|
2642
|
+
"bottom"
|
|
2643
|
+
].some((property) => properties.has(property))) Reflect.deleteProperty(layout, "flowOffset");
|
|
2644
|
+
for (const axis of ["horizontal", "vertical"]) {
|
|
2645
|
+
const intent = axes[axis].some((property) => properties.has(property)) ? void 0 : axisWithoutCssBounds(layout[axis], axes[axis], properties);
|
|
2646
|
+
if (intent === void 0) Reflect.deleteProperty(layout, axis);
|
|
2647
|
+
else layout[axis] = intent;
|
|
2648
|
+
}
|
|
2649
|
+
return layout;
|
|
2650
|
+
};
|
|
2651
|
+
|
|
2652
|
+
//#endregion
|
|
2653
|
+
//#region ../../packages/contract/src/canvas/canvas-object-kind.lib.ts
|
|
2654
|
+
const ROOT_KIND = "root";
|
|
2655
|
+
const PAGE_KIND = "page";
|
|
2656
|
+
const SCREEN_KIND = "screen";
|
|
2657
|
+
const FRAME_KIND = "frame";
|
|
2658
|
+
const GROUP_KIND = "group";
|
|
2659
|
+
const RECTANGLE_KIND = "rectangle";
|
|
2660
|
+
const IMAGE_KIND = "image";
|
|
2661
|
+
const SVG_KIND = "svg";
|
|
2662
|
+
const RECORDING_KIND = "recording";
|
|
2663
|
+
const PROTOTYPE_KIND = "prototype";
|
|
2664
|
+
const TEXT_KIND = "text";
|
|
2665
|
+
const SHAPE_PROPERTY_SECTIONS = [
|
|
2666
|
+
"position",
|
|
2667
|
+
"layout",
|
|
2668
|
+
"cornerRadius",
|
|
2669
|
+
"blending",
|
|
2670
|
+
"fill",
|
|
2671
|
+
"outline",
|
|
2672
|
+
"border",
|
|
2673
|
+
"outerShadow",
|
|
2674
|
+
"innerShadow",
|
|
2675
|
+
"filters",
|
|
2676
|
+
"additionalStyles",
|
|
2677
|
+
"export"
|
|
2678
|
+
];
|
|
2679
|
+
const FRAME_PROPERTY_SECTIONS = [
|
|
2680
|
+
"position",
|
|
2681
|
+
"layout",
|
|
2682
|
+
"clip",
|
|
2683
|
+
...SHAPE_PROPERTY_SECTIONS.filter((section) => section !== "position" && section !== "layout")
|
|
2684
|
+
];
|
|
2685
|
+
const SVG_PROPERTY_SECTIONS = [...SHAPE_PROPERTY_SECTIONS, "vector"];
|
|
2686
|
+
const DESCRIPTOR_BY_KIND = Object.fromEntries([
|
|
2687
|
+
{
|
|
2688
|
+
objectKind: PROTOTYPE_KIND,
|
|
2689
|
+
label: "Prototype",
|
|
2690
|
+
category: "import",
|
|
2691
|
+
capabilities: {
|
|
2692
|
+
canSelect: true,
|
|
2693
|
+
canContainChildren: false,
|
|
2694
|
+
canEditProperties: false,
|
|
2695
|
+
commentAnchor: "node"
|
|
2696
|
+
},
|
|
2697
|
+
capture: { preservesHtmlCssAssets: true },
|
|
2698
|
+
selectionBehavior: { hitTarget: "frame" },
|
|
2699
|
+
resizeBehavior: {
|
|
2700
|
+
mode: "reflow",
|
|
2701
|
+
preservesAspect: false,
|
|
2702
|
+
canLockAspectRatio: true
|
|
2703
|
+
},
|
|
2704
|
+
propertySections: ["position", "layout"]
|
|
2705
|
+
},
|
|
2706
|
+
{
|
|
2707
|
+
objectKind: ROOT_KIND,
|
|
2708
|
+
label: "Canvas",
|
|
2709
|
+
category: "container",
|
|
2710
|
+
capabilities: {
|
|
2711
|
+
canSelect: false,
|
|
2712
|
+
canContainChildren: true,
|
|
2713
|
+
canEditProperties: false
|
|
2714
|
+
},
|
|
2715
|
+
selectionBehavior: { hitTarget: "children" },
|
|
2716
|
+
propertySections: []
|
|
2717
|
+
},
|
|
2718
|
+
{
|
|
2719
|
+
objectKind: PAGE_KIND,
|
|
2720
|
+
label: "Page",
|
|
2721
|
+
category: "container",
|
|
2722
|
+
capabilities: {
|
|
2723
|
+
canSelect: false,
|
|
2724
|
+
canContainChildren: false,
|
|
2725
|
+
canEditProperties: false
|
|
2726
|
+
},
|
|
2727
|
+
selectionBehavior: { hitTarget: "children" },
|
|
2728
|
+
propertySections: []
|
|
2729
|
+
},
|
|
2730
|
+
{
|
|
2731
|
+
objectKind: SCREEN_KIND,
|
|
2732
|
+
label: "Screen",
|
|
2733
|
+
category: "import",
|
|
2734
|
+
capabilities: {
|
|
2735
|
+
canSelect: true,
|
|
2736
|
+
canContainChildren: false,
|
|
2737
|
+
canEditProperties: false,
|
|
2738
|
+
commentAnchor: "screen"
|
|
2739
|
+
},
|
|
2740
|
+
capture: { preservesHtmlCssAssets: true },
|
|
2741
|
+
selectionBehavior: { hitTarget: "frame" },
|
|
2742
|
+
resizeBehavior: {
|
|
2743
|
+
mode: "reflow",
|
|
2744
|
+
preservesAspect: false,
|
|
2745
|
+
canLockAspectRatio: true
|
|
2746
|
+
},
|
|
2747
|
+
propertySections: [
|
|
2748
|
+
"position",
|
|
2749
|
+
"layout",
|
|
2750
|
+
"source"
|
|
2751
|
+
]
|
|
2752
|
+
},
|
|
2753
|
+
{
|
|
2754
|
+
objectKind: FRAME_KIND,
|
|
2755
|
+
label: "Frame",
|
|
2756
|
+
category: "container",
|
|
2757
|
+
capabilities: {
|
|
2758
|
+
canSelect: true,
|
|
2759
|
+
canContainChildren: true,
|
|
2760
|
+
canEditProperties: true,
|
|
2761
|
+
commentAnchor: "node"
|
|
2762
|
+
},
|
|
2763
|
+
selectionBehavior: { hitTarget: "frame" },
|
|
2764
|
+
resizeBehavior: {
|
|
2765
|
+
mode: "reflow",
|
|
2766
|
+
preservesAspect: false,
|
|
2767
|
+
canLockAspectRatio: true
|
|
2768
|
+
},
|
|
2769
|
+
propertySections: FRAME_PROPERTY_SECTIONS
|
|
2770
|
+
},
|
|
2771
|
+
{
|
|
2772
|
+
objectKind: GROUP_KIND,
|
|
2773
|
+
label: "Group",
|
|
2774
|
+
category: "container",
|
|
2775
|
+
capabilities: {
|
|
2776
|
+
canSelect: true,
|
|
2777
|
+
canContainChildren: true,
|
|
2778
|
+
canEditProperties: true,
|
|
2779
|
+
commentAnchor: "node"
|
|
2780
|
+
},
|
|
2781
|
+
selectionBehavior: { hitTarget: "frame" },
|
|
2782
|
+
resizeBehavior: {
|
|
2783
|
+
mode: "reflow",
|
|
2784
|
+
preservesAspect: false,
|
|
2785
|
+
canLockAspectRatio: true
|
|
2786
|
+
},
|
|
2787
|
+
propertySections: [
|
|
2788
|
+
"position",
|
|
2789
|
+
"layout",
|
|
2790
|
+
"blending",
|
|
2791
|
+
"additionalStyles",
|
|
2792
|
+
"export"
|
|
2793
|
+
]
|
|
2794
|
+
},
|
|
2795
|
+
{
|
|
2796
|
+
objectKind: RECTANGLE_KIND,
|
|
2797
|
+
label: "Rectangle",
|
|
2798
|
+
category: "primitive",
|
|
2799
|
+
capabilities: {
|
|
2800
|
+
canSelect: true,
|
|
2801
|
+
canContainChildren: false,
|
|
2802
|
+
canEditProperties: true,
|
|
2803
|
+
commentAnchor: "node"
|
|
2804
|
+
},
|
|
2805
|
+
selectionBehavior: { hitTarget: "frame" },
|
|
2806
|
+
resizeBehavior: {
|
|
2807
|
+
mode: "reflow",
|
|
2808
|
+
preservesAspect: false,
|
|
2809
|
+
canLockAspectRatio: true
|
|
2810
|
+
},
|
|
2811
|
+
propertySections: SHAPE_PROPERTY_SECTIONS
|
|
2812
|
+
},
|
|
2813
|
+
{
|
|
2814
|
+
objectKind: IMAGE_KIND,
|
|
2815
|
+
label: "Image",
|
|
2816
|
+
category: "media",
|
|
2817
|
+
capabilities: {
|
|
2818
|
+
canSelect: true,
|
|
2819
|
+
canContainChildren: false,
|
|
2820
|
+
canEditProperties: true,
|
|
2821
|
+
commentAnchor: "node"
|
|
2822
|
+
},
|
|
2823
|
+
selectionBehavior: { hitTarget: "frame" },
|
|
2824
|
+
resizeBehavior: {
|
|
2825
|
+
mode: "scale",
|
|
2826
|
+
preservesAspect: true,
|
|
2827
|
+
canLockAspectRatio: true
|
|
2828
|
+
},
|
|
2829
|
+
propertySections: SHAPE_PROPERTY_SECTIONS
|
|
2830
|
+
},
|
|
2831
|
+
{
|
|
2832
|
+
objectKind: "svg",
|
|
2833
|
+
label: "SVG",
|
|
2834
|
+
category: "primitive",
|
|
2835
|
+
capabilities: {
|
|
2836
|
+
canSelect: true,
|
|
2837
|
+
canContainChildren: false,
|
|
2838
|
+
canEditProperties: true,
|
|
2839
|
+
commentAnchor: "node"
|
|
2840
|
+
},
|
|
2841
|
+
capture: { preservesVectorData: true },
|
|
2842
|
+
selectionBehavior: { hitTarget: "frame" },
|
|
2843
|
+
resizeBehavior: {
|
|
2844
|
+
mode: "scale",
|
|
2845
|
+
preservesAspect: true,
|
|
2846
|
+
canLockAspectRatio: true
|
|
2847
|
+
},
|
|
2848
|
+
propertySections: SVG_PROPERTY_SECTIONS
|
|
2849
|
+
},
|
|
2850
|
+
{
|
|
2851
|
+
objectKind: RECORDING_KIND,
|
|
2852
|
+
label: "Recording",
|
|
2853
|
+
category: "media",
|
|
2854
|
+
capabilities: {
|
|
2855
|
+
canSelect: true,
|
|
2856
|
+
canContainChildren: false,
|
|
2857
|
+
canEditProperties: false
|
|
2858
|
+
},
|
|
2859
|
+
capture: { preservesAssets: true },
|
|
2860
|
+
selectionBehavior: { hitTarget: "frame" },
|
|
2861
|
+
resizeBehavior: {
|
|
2862
|
+
mode: "scale",
|
|
2863
|
+
preservesAspect: true,
|
|
2864
|
+
canLockAspectRatio: true
|
|
2865
|
+
},
|
|
2866
|
+
propertySections: []
|
|
2867
|
+
},
|
|
2868
|
+
{
|
|
2869
|
+
objectKind: TEXT_KIND,
|
|
2870
|
+
label: "Text",
|
|
2871
|
+
category: "primitive",
|
|
2872
|
+
capabilities: {
|
|
2873
|
+
canSelect: true,
|
|
2874
|
+
canContainChildren: false,
|
|
2875
|
+
canEditProperties: true,
|
|
2876
|
+
commentAnchor: "node"
|
|
2877
|
+
},
|
|
2878
|
+
selectionBehavior: { hitTarget: "text" },
|
|
2879
|
+
resizeBehavior: {
|
|
2880
|
+
mode: "reflow",
|
|
2881
|
+
preservesAspect: false,
|
|
2882
|
+
canLockAspectRatio: false
|
|
2883
|
+
},
|
|
2884
|
+
propertySections: [
|
|
2885
|
+
"position",
|
|
2886
|
+
"layout",
|
|
2887
|
+
"typography",
|
|
2888
|
+
"nativeControl",
|
|
2889
|
+
"textDecoration",
|
|
2890
|
+
"textStroke",
|
|
2891
|
+
"blending",
|
|
2892
|
+
"fill",
|
|
2893
|
+
"outerShadow",
|
|
2894
|
+
"filters",
|
|
2895
|
+
"additionalStyles",
|
|
2896
|
+
"export"
|
|
2897
|
+
]
|
|
2898
|
+
}
|
|
2899
|
+
].map((descriptor) => [descriptor.objectKind, descriptor]));
|
|
2900
|
+
const canvasObjectKindDescriptor = (objectKind) => DESCRIPTOR_BY_KIND[objectKind] ?? null;
|
|
2901
|
+
const canvasPropertySectionsForKind = (objectKind) => canvasObjectKindDescriptor(objectKind)?.propertySections ?? [];
|
|
2902
|
+
|
|
2324
2903
|
//#endregion
|
|
2325
2904
|
//#region ../../packages/contract/src/canvas/canvas-realtime.schema.ts
|
|
2326
2905
|
const CANVAS_REALTIME_PROTOCOL = "enhance3.canvas.v1";
|
|
2327
2906
|
const MAX_DISPLAY_NAME_LENGTH = 100;
|
|
2328
2907
|
const MAX_INITIALS_LENGTH = 8;
|
|
2329
|
-
const MAX_NODE_ID_LENGTH$
|
|
2330
|
-
const
|
|
2908
|
+
const MAX_NODE_ID_LENGTH$4 = 200;
|
|
2909
|
+
const MAX_CANVAS_PRESENCE_IDS = 100;
|
|
2910
|
+
const MAX_CANVAS_PRESENCE_DETAIL_BYTES = 16384;
|
|
2911
|
+
const MAX_CANVAS_SELECTION_IDS = 3e4;
|
|
2912
|
+
const MAX_CANVAS_SELECTION_CHUNK_IDS = 1e3;
|
|
2913
|
+
const MAX_CANVAS_SELECTION_CHUNK_BYTES = 49152;
|
|
2331
2914
|
const MAX_ACTIVITY_TARGETS = 100;
|
|
2332
2915
|
const MAX_REALTIME_TICKET_LENGTH = 4096;
|
|
2333
2916
|
const MAX_ERROR_MESSAGE_LENGTH = 200;
|
|
@@ -2375,10 +2958,15 @@ const visibleWorldBoxSchema = canvasSceneBoxSchema.extend({
|
|
|
2375
2958
|
width: z.number().positive(),
|
|
2376
2959
|
height: z.number().positive()
|
|
2377
2960
|
});
|
|
2961
|
+
const selectionSummarySchema = z.object({
|
|
2962
|
+
count: z.number().int().positive(),
|
|
2963
|
+
bounds: visibleWorldBoxSchema.nullable()
|
|
2964
|
+
});
|
|
2378
2965
|
const gesturePreviewSchema = z.object({
|
|
2379
2966
|
kind: z.enum(["drag", "resize"]),
|
|
2380
2967
|
baseVersion: z.number().int().positive(),
|
|
2381
|
-
boxes: z.record(z.string().min(1).max(MAX_NODE_ID_LENGTH$
|
|
2968
|
+
boxes: z.record(z.string().min(1).max(MAX_NODE_ID_LENGTH$4), visibleWorldBoxSchema).refine((boxes) => Object.keys(boxes).length <= 100 && new TextEncoder().encode(JSON.stringify(boxes)).byteLength <= 16384),
|
|
2969
|
+
summary: selectionSummarySchema.optional()
|
|
2382
2970
|
});
|
|
2383
2971
|
const canvasPresencePatchSchema = z.object({
|
|
2384
2972
|
cursor: cursorSchema.nullable().optional(),
|
|
@@ -2388,7 +2976,8 @@ const canvasPresencePatchSchema = z.object({
|
|
|
2388
2976
|
"keyboard"
|
|
2389
2977
|
]).optional(),
|
|
2390
2978
|
focused: z.boolean().optional(),
|
|
2391
|
-
selectedNodeIds: z.array(z.string().min(1).max(MAX_NODE_ID_LENGTH$
|
|
2979
|
+
selectedNodeIds: z.array(z.string().min(1).max(MAX_NODE_ID_LENGTH$4)).max(100).refine((ids) => new TextEncoder().encode(JSON.stringify(ids)).byteLength <= MAX_CANVAS_PRESENCE_DETAIL_BYTES).optional(),
|
|
2980
|
+
selectionSummary: selectionSummarySchema.nullable().optional(),
|
|
2392
2981
|
visibleWorldBox: visibleWorldBoxSchema.optional(),
|
|
2393
2982
|
gesture: gesturePreviewSchema.nullable().optional(),
|
|
2394
2983
|
cursorChat: z.string().max(140).nullable().optional()
|
|
@@ -2403,7 +2992,8 @@ const canvasPresenceSchema = z.object({
|
|
|
2403
2992
|
"keyboard"
|
|
2404
2993
|
]),
|
|
2405
2994
|
focused: z.boolean(),
|
|
2406
|
-
selectedNodeIds: z.array(z.string().min(1).max(MAX_NODE_ID_LENGTH$
|
|
2995
|
+
selectedNodeIds: z.array(z.string().min(1).max(MAX_NODE_ID_LENGTH$4)).max(100).refine((ids) => new TextEncoder().encode(JSON.stringify(ids)).byteLength <= MAX_CANVAS_PRESENCE_DETAIL_BYTES),
|
|
2996
|
+
selectionSummary: selectionSummarySchema.nullable().optional(),
|
|
2407
2997
|
visibleWorldBox: visibleWorldBoxSchema.nullable(),
|
|
2408
2998
|
gesture: gesturePreviewSchema.nullable(),
|
|
2409
2999
|
cursorChat: z.string().max(140).nullable().default(null),
|
|
@@ -2421,7 +3011,7 @@ const canvasAgentActivitySchema = z.object({
|
|
|
2421
3011
|
canvasId: z.uuid(),
|
|
2422
3012
|
actor: agentMutationActorSchema,
|
|
2423
3013
|
phase: canvasAgentActivityPhaseSchema,
|
|
2424
|
-
nodeIds: z.array(z.string().min(1).max(MAX_NODE_ID_LENGTH$
|
|
3014
|
+
nodeIds: z.array(z.string().min(1).max(MAX_NODE_ID_LENGTH$4)).max(MAX_ACTIVITY_TARGETS),
|
|
2425
3015
|
bounds: visibleWorldBoxSchema.nullable(),
|
|
2426
3016
|
expiresAt: z.iso.datetime()
|
|
2427
3017
|
});
|
|
@@ -2438,7 +3028,7 @@ const canvasRealtimeTicketOutputSchema = z.object({
|
|
|
2438
3028
|
const beginCanvasActivityInputSchema = z.object({
|
|
2439
3029
|
canvasId: z.uuid(),
|
|
2440
3030
|
phase: canvasAgentActivityPhaseSchema,
|
|
2441
|
-
nodeIds: z.array(z.string().min(1).max(MAX_NODE_ID_LENGTH$
|
|
3031
|
+
nodeIds: z.array(z.string().min(1).max(MAX_NODE_ID_LENGTH$4)).max(MAX_ACTIVITY_TARGETS).default([]),
|
|
2442
3032
|
bounds: visibleWorldBoxSchema.nullable().default(null)
|
|
2443
3033
|
});
|
|
2444
3034
|
const beginCanvasActivityOutputSchema = z.object({
|
|
@@ -2452,17 +3042,6 @@ const endCanvasActivityInputSchema = z.object({
|
|
|
2452
3042
|
activityId: z.uuid()
|
|
2453
3043
|
});
|
|
2454
3044
|
const endCanvasActivityOutputSchema = z.object({ ended: z.literal(true) });
|
|
2455
|
-
const canvasRealtimeClientEnvelopeSchema = z.discriminatedUnion("type", [z.object({
|
|
2456
|
-
v: z.literal(1),
|
|
2457
|
-
type: z.literal("presence.patch"),
|
|
2458
|
-
seq: z.number().int().nonnegative(),
|
|
2459
|
-
payload: canvasPresencePatchSchema
|
|
2460
|
-
}), z.object({
|
|
2461
|
-
v: z.literal(1),
|
|
2462
|
-
type: z.literal("room.pong"),
|
|
2463
|
-
seq: z.number().int().nonnegative(),
|
|
2464
|
-
payload: z.object({ pingId: z.uuid() })
|
|
2465
|
-
})]);
|
|
2466
3045
|
const serverEnvelopeBase = {
|
|
2467
3046
|
v: z.literal(1),
|
|
2468
3047
|
seq: z.number().int().nonnegative()
|
|
@@ -2545,6 +3124,41 @@ const canvasRealtimeServerEnvelopeSchema = z.discriminatedUnion("type", [
|
|
|
2545
3124
|
})
|
|
2546
3125
|
]);
|
|
2547
3126
|
|
|
3127
|
+
//#endregion
|
|
3128
|
+
//#region ../../packages/contract/src/canvas/canvas-realtime-client.schema.ts
|
|
3129
|
+
const MAX_NODE_ID_LENGTH$3 = 200;
|
|
3130
|
+
const canvasRealtimeClientEnvelopeSchema = z.discriminatedUnion("type", [
|
|
3131
|
+
z.object({
|
|
3132
|
+
v: z.literal(1),
|
|
3133
|
+
type: z.literal("presence.patch"),
|
|
3134
|
+
seq: z.number().int().nonnegative(),
|
|
3135
|
+
payload: canvasPresencePatchSchema
|
|
3136
|
+
}),
|
|
3137
|
+
z.object({
|
|
3138
|
+
v: z.literal(1),
|
|
3139
|
+
type: z.literal("selection.chunk"),
|
|
3140
|
+
seq: z.number().int().nonnegative(),
|
|
3141
|
+
payload: z.object({
|
|
3142
|
+
transferId: z.uuid(),
|
|
3143
|
+
offset: z.number().int().nonnegative().max(MAX_CANVAS_SELECTION_IDS - 1),
|
|
3144
|
+
total: z.number().int().positive().max(MAX_CANVAS_SELECTION_IDS),
|
|
3145
|
+
nodeIds: z.array(z.string().min(1).max(MAX_NODE_ID_LENGTH$3)).min(1).max(MAX_CANVAS_SELECTION_CHUNK_IDS)
|
|
3146
|
+
})
|
|
3147
|
+
}),
|
|
3148
|
+
z.object({
|
|
3149
|
+
v: z.literal(1),
|
|
3150
|
+
type: z.literal("selection.unavailable"),
|
|
3151
|
+
seq: z.number().int().nonnegative(),
|
|
3152
|
+
payload: z.object({ count: z.number().int().min(MAX_CANVAS_SELECTION_IDS + 1) })
|
|
3153
|
+
}),
|
|
3154
|
+
z.object({
|
|
3155
|
+
v: z.literal(1),
|
|
3156
|
+
type: z.literal("room.pong"),
|
|
3157
|
+
seq: z.number().int().nonnegative(),
|
|
3158
|
+
payload: z.object({ pingId: z.uuid() })
|
|
3159
|
+
})
|
|
3160
|
+
]).refine((envelope) => envelope.type !== "selection.chunk" || new TextEncoder().encode(JSON.stringify(envelope)).byteLength <= 49152);
|
|
3161
|
+
|
|
2548
3162
|
//#endregion
|
|
2549
3163
|
//#region ../../packages/contract/src/canvas/canvas-render-exposure.schema.ts
|
|
2550
3164
|
const MAX_NODE_ID_LENGTH$2 = 200;
|
|
@@ -2744,7 +3358,9 @@ const readCanvasSelectionOutputSchema = z.object({
|
|
|
2744
3358
|
"selected",
|
|
2745
3359
|
"none",
|
|
2746
3360
|
"offline",
|
|
2747
|
-
"stale"
|
|
3361
|
+
"stale",
|
|
3362
|
+
"updating",
|
|
3363
|
+
"unsupported"
|
|
2748
3364
|
]),
|
|
2749
3365
|
documentVersion: z.number().int().positive(),
|
|
2750
3366
|
selectionRevision: z.number().int().positive().nullable(),
|
|
@@ -2757,6 +3373,43 @@ const readCanvasSelectionOutputSchema = z.object({
|
|
|
2757
3373
|
next: z.array(z.string().min(1)).max(MAX_SELECTION_COMMANDS)
|
|
2758
3374
|
});
|
|
2759
3375
|
|
|
3376
|
+
//#endregion
|
|
3377
|
+
//#region ../../packages/contract/src/canvas/canvas-text-run-format.lib.ts
|
|
3378
|
+
const STYLE_PROPERTIES = new Set(CANVAS_TEXT_STYLE_PROPERTIES);
|
|
3379
|
+
const STYLE_CSS = new Set(Object.entries(CANVAS_TYPOGRAPHY_CSS_OWNERS).flatMap(([css, owners]) => owners.some((owner) => STYLE_PROPERTIES.has(owner)) ? [css.replaceAll(/-([a-z])/gu, (_, letter) => letter.toUpperCase())] : []));
|
|
3380
|
+
|
|
3381
|
+
//#endregion
|
|
3382
|
+
//#region ../../packages/contract/src/canvas/canvas-text-style-consumers.lib.ts
|
|
3383
|
+
const ownedProperties = new Set(CANVAS_TEXT_STYLE_PROPERTIES);
|
|
3384
|
+
const ownedCss = new Set(Object.entries(CANVAS_TYPOGRAPHY_CSS_OWNERS).flatMap(([css, owners]) => owners.some((property) => ownedProperties.has(property)) ? [css] : []));
|
|
3385
|
+
|
|
3386
|
+
//#endregion
|
|
3387
|
+
//#region ../../packages/contract/src/canvas/canvas-typography-ownership.lib.ts
|
|
3388
|
+
const FONT_SETTINGS = [["features", "featureChanges"], ["variations", "variationChanges"]];
|
|
3389
|
+
const applyCanvasTypographyPatch = (before, patch) => {
|
|
3390
|
+
const next = { ...before };
|
|
3391
|
+
for (const property of CANVAS_TYPOGRAPHY_PROPERTIES) {
|
|
3392
|
+
const value = patch[property];
|
|
3393
|
+
if (value !== void 0) Reflect.set(next, property, value);
|
|
3394
|
+
}
|
|
3395
|
+
for (const [property, key] of FONT_SETTINGS) {
|
|
3396
|
+
const change = patch[key];
|
|
3397
|
+
if (change === void 0) continue;
|
|
3398
|
+
const settings = {
|
|
3399
|
+
...before?.[property],
|
|
3400
|
+
...change.set
|
|
3401
|
+
};
|
|
3402
|
+
const cleared = change.clear ?? [];
|
|
3403
|
+
for (const tag of cleared) Reflect.deleteProperty(settings, tag);
|
|
3404
|
+
if (change.removeIfEmpty === true && Object.keys(settings).length === 0) Reflect.deleteProperty(next, property);
|
|
3405
|
+
else next[property] = settings;
|
|
3406
|
+
}
|
|
3407
|
+
const cleared = patch.clear ?? [];
|
|
3408
|
+
for (const property of cleared) Reflect.deleteProperty(next, property);
|
|
3409
|
+
return Object.keys(next).length === 0 ? null : next;
|
|
3410
|
+
};
|
|
3411
|
+
const canvasCssTypographyOwners = (changed) => [...new Set(Object.entries(CANVAS_TYPOGRAPHY_CSS_OWNERS).flatMap(([css, properties]) => changed.has(css) ? properties : []))];
|
|
3412
|
+
|
|
2760
3413
|
//#endregion
|
|
2761
3414
|
//#region ../../packages/contract/src/canvas/canvas-version.schema.ts
|
|
2762
3415
|
const CANVAS_VERSION_DESCRIPTION_MAX_LENGTH = 1e3;
|
|
@@ -2890,6 +3543,82 @@ const duplicateCanvasVersionOutputSchema = z.object({
|
|
|
2890
3543
|
version: z.literal(1)
|
|
2891
3544
|
});
|
|
2892
3545
|
|
|
3546
|
+
//#endregion
|
|
3547
|
+
//#region ../../packages/contract/src/canvas/font-catalog.schema.ts
|
|
3548
|
+
const MAX_FONT_NAME_LENGTH = 200;
|
|
3549
|
+
const MAX_WEIGHT = 1e3;
|
|
3550
|
+
const MAX_STRETCH_PERCENT = 1e3;
|
|
3551
|
+
const isNumericRange = (value, maximum) => {
|
|
3552
|
+
const values = value.split(" ").map((part) => Number(part.replace("%", "")));
|
|
3553
|
+
return values.every((part) => part > 0 && part <= maximum) && (values.length === 1 || (values[0] ?? 0) <= (values[1] ?? 0));
|
|
3554
|
+
};
|
|
3555
|
+
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
|
3556
|
+
const fontNameSchema = z.string().trim().min(1).max(MAX_FONT_NAME_LENGTH);
|
|
3557
|
+
const fontCatalogScopeSchema = z.object({ organisationId: z.uuid().nullable() });
|
|
3558
|
+
const fontCatalogMetadataSchema = z.object({
|
|
3559
|
+
family: z.string().regex(/^uploaded-font-[a-f0-9]{64}(?:-[a-f0-9]{12})?$/u),
|
|
3560
|
+
familyName: fontNameSchema,
|
|
3561
|
+
subfamilyName: fontNameSchema,
|
|
3562
|
+
version: fontNameSchema,
|
|
3563
|
+
weight: z.string().regex(/^\d+(?:\.\d+)?(?: \d+(?:\.\d+)?)?$/u).refine((value) => isNumericRange(value, MAX_WEIGHT)),
|
|
3564
|
+
style: z.enum([
|
|
3565
|
+
"normal",
|
|
3566
|
+
"italic",
|
|
3567
|
+
"oblique"
|
|
3568
|
+
]),
|
|
3569
|
+
stretch: z.union([z.enum([
|
|
3570
|
+
"normal",
|
|
3571
|
+
"ultra-condensed",
|
|
3572
|
+
"extra-condensed",
|
|
3573
|
+
"condensed",
|
|
3574
|
+
"semi-condensed",
|
|
3575
|
+
"semi-expanded",
|
|
3576
|
+
"expanded",
|
|
3577
|
+
"extra-expanded",
|
|
3578
|
+
"ultra-expanded"
|
|
3579
|
+
]), z.string().regex(/^\d+(?:\.\d+)?%(?: \d+(?:\.\d+)?%)?$/u).refine((value) => isNumericRange(value, MAX_STRETCH_PERCENT))]),
|
|
3580
|
+
format: z.enum([
|
|
3581
|
+
"truetype",
|
|
3582
|
+
"opentype",
|
|
3583
|
+
"woff",
|
|
3584
|
+
"woff2"
|
|
3585
|
+
])
|
|
3586
|
+
});
|
|
3587
|
+
const fontCatalogIdentitySchema = z.object({
|
|
3588
|
+
kind: z.enum(["personal", "team"]),
|
|
3589
|
+
ownerId: z.uuid(),
|
|
3590
|
+
sha256: digestSchema
|
|
3591
|
+
});
|
|
3592
|
+
const reserveFontCatalogInputSchema = fontCatalogScopeSchema.extend({
|
|
3593
|
+
sha256: digestSchema,
|
|
3594
|
+
bytes: z.number().int().positive().max(MAX_CANVAS_FONT_BYTES),
|
|
3595
|
+
contentType: z.enum(CANVAS_FONT_CONTENT_TYPES)
|
|
3596
|
+
});
|
|
3597
|
+
const reserveFontCatalogOutputSchema = z.object({ upload: signedUploadSchema });
|
|
3598
|
+
const completeFontCatalogInputSchema = reserveFontCatalogInputSchema.extend({
|
|
3599
|
+
metadata: fontCatalogMetadataSchema,
|
|
3600
|
+
hasSharingRights: z.literal(true)
|
|
3601
|
+
});
|
|
3602
|
+
const fontCatalogEntrySchema = fontCatalogIdentitySchema.extend({
|
|
3603
|
+
bytes: z.number().int().positive().max(MAX_CANVAS_FONT_BYTES),
|
|
3604
|
+
metadata: fontCatalogMetadataSchema,
|
|
3605
|
+
createdAt: z.iso.datetime(),
|
|
3606
|
+
path: z.string().startsWith("/v1/font-catalog/")
|
|
3607
|
+
});
|
|
3608
|
+
const listFontCatalogOutputSchema = z.object({
|
|
3609
|
+
entries: z.array(fontCatalogEntrySchema),
|
|
3610
|
+
canManage: z.boolean()
|
|
3611
|
+
});
|
|
3612
|
+
const removeFontCatalogInputSchema = fontCatalogScopeSchema.extend({ sha256: digestSchema });
|
|
3613
|
+
const importFontCatalogInputSchema = fontCatalogScopeSchema.extend({
|
|
3614
|
+
canvasId: z.uuid(),
|
|
3615
|
+
sha256: z.array(digestSchema).min(1).max(100)
|
|
3616
|
+
});
|
|
3617
|
+
const importFontCatalogOutputSchema = z.object({ resources: z.array(z.object({
|
|
3618
|
+
entry: fontCatalogEntrySchema,
|
|
3619
|
+
path: z.string().startsWith("/v1/canvas-assets/")
|
|
3620
|
+
})) });
|
|
3621
|
+
|
|
2893
3622
|
//#endregion
|
|
2894
3623
|
//#region ../../packages/contract/src/canvas/invite.schema.ts
|
|
2895
3624
|
const inviteSchema = z.object({
|
|
@@ -3226,7 +3955,7 @@ const ROOT_FIXTURE_NODE_ID = "root";
|
|
|
3226
3955
|
const SORT_KEY_DIGITS = 4;
|
|
3227
3956
|
const sortKeyAt = (seat) => `a${String(seat).padStart(SORT_KEY_DIGITS, "0")}`;
|
|
3228
3957
|
const emptyFixtureDocument = () => ({
|
|
3229
|
-
version:
|
|
3958
|
+
version: 5,
|
|
3230
3959
|
nodes: { [ROOT_FIXTURE_NODE_ID]: {
|
|
3231
3960
|
id: ROOT_FIXTURE_NODE_ID,
|
|
3232
3961
|
label: "Canvas",
|
|
@@ -3775,7 +4504,25 @@ const PROTOTYPE_VIEWPORT_SELECTOR = `[${PROTOTYPE_VIEWPORT_ATTRIBUTE}]`;
|
|
|
3775
4504
|
const prototypeBridgeCaptureRequestSchema = z.object({
|
|
3776
4505
|
protocol: z.literal(1),
|
|
3777
4506
|
type: z.literal("enhance.prototype.capture"),
|
|
3778
|
-
requestId: z.uuid()
|
|
4507
|
+
requestId: z.uuid(),
|
|
4508
|
+
connectionId: z.uuid().optional(),
|
|
4509
|
+
documentId: z.uuid().optional()
|
|
4510
|
+
});
|
|
4511
|
+
const prototypeBridgeConnectRequestSchema = z.object({
|
|
4512
|
+
protocol: z.literal(1),
|
|
4513
|
+
type: z.literal("enhance.prototype.connect"),
|
|
4514
|
+
connectionId: z.uuid()
|
|
4515
|
+
});
|
|
4516
|
+
const prototypeBridgeConnectedSchema = prototypeBridgeConnectRequestSchema.extend({
|
|
4517
|
+
type: z.literal("enhance.prototype.connected"),
|
|
4518
|
+
documentId: z.uuid(),
|
|
4519
|
+
capabilities: z.array(z.string()),
|
|
4520
|
+
release: z.string().min(1)
|
|
4521
|
+
});
|
|
4522
|
+
const prototypeBridgeUnloadingSchema = z.object({
|
|
4523
|
+
protocol: z.literal(1),
|
|
4524
|
+
type: z.literal("enhance.prototype.unloading"),
|
|
4525
|
+
documentId: z.uuid()
|
|
3779
4526
|
});
|
|
3780
4527
|
const prototypeBridgeReadySchema = z.object({
|
|
3781
4528
|
protocol: z.literal(1),
|
|
@@ -3820,14 +4567,17 @@ const capturedPrototypeScreenSchema = z.object({
|
|
|
3820
4567
|
const prototypeBridgeCaptureResponseBaseSchema = z.object({
|
|
3821
4568
|
protocol: z.literal(1),
|
|
3822
4569
|
type: z.literal("enhance.prototype.captured"),
|
|
3823
|
-
requestId: z.uuid()
|
|
4570
|
+
requestId: z.uuid(),
|
|
4571
|
+
connectionId: z.uuid().optional(),
|
|
4572
|
+
documentId: z.uuid().optional()
|
|
3824
4573
|
});
|
|
3825
4574
|
const prototypeBridgeCaptureResponseSchema = z.discriminatedUnion("outcome", [prototypeBridgeCaptureResponseBaseSchema.extend({
|
|
3826
4575
|
outcome: z.literal("captured"),
|
|
3827
4576
|
screen: capturedPrototypeScreenSchema
|
|
3828
4577
|
}), prototypeBridgeCaptureResponseBaseSchema.extend({
|
|
3829
4578
|
outcome: z.literal("failed"),
|
|
3830
|
-
error: z.string().min(1)
|
|
4579
|
+
error: z.string().min(1),
|
|
4580
|
+
code: z.enum(["capture-failed", "capture-busy"]).optional()
|
|
3831
4581
|
})]);
|
|
3832
4582
|
|
|
3833
4583
|
//#endregion
|
|
@@ -4730,6 +5480,7 @@ const operationScope = (operation, document) => {
|
|
|
4730
5480
|
}
|
|
4731
5481
|
case "setPrototypeDeployment":
|
|
4732
5482
|
case "setText":
|
|
5483
|
+
case "editText":
|
|
4733
5484
|
case "setBox":
|
|
4734
5485
|
case "setLabel":
|
|
4735
5486
|
case "setContainerKind":
|
|
@@ -4739,7 +5490,12 @@ const operationScope = (operation, document) => {
|
|
|
4739
5490
|
case "setStyles":
|
|
4740
5491
|
case "setAppearance":
|
|
4741
5492
|
case "setLayout":
|
|
5493
|
+
case "patchTypography":
|
|
4742
5494
|
case "setTypography":
|
|
5495
|
+
case "patchFontLibrary":
|
|
5496
|
+
case "setTextStyleLibrary":
|
|
5497
|
+
case "setTextStyle":
|
|
5498
|
+
case "patchAdditionalStyles":
|
|
4743
5499
|
case "setAdditionalStyles":
|
|
4744
5500
|
case "setProps":
|
|
4745
5501
|
case "remove": return {
|
|
@@ -4917,6 +5673,11 @@ const CANVAS_CAPABILITY_SPECS = [
|
|
|
4917
5673
|
mutationId: CAPABILITY_UUID_EXAMPLE,
|
|
4918
5674
|
previousVersion: 1,
|
|
4919
5675
|
version: 2,
|
|
5676
|
+
operations: [{
|
|
5677
|
+
op: "setText",
|
|
5678
|
+
nodeId: "text_title",
|
|
5679
|
+
text: "Today"
|
|
5680
|
+
}],
|
|
4920
5681
|
insertedNodeIds: [],
|
|
4921
5682
|
changedNodeIds: ["text_title"],
|
|
4922
5683
|
removedNodeIds: [],
|
|
@@ -4954,6 +5715,11 @@ const CANVAS_CAPABILITY_SPECS = [
|
|
|
4954
5715
|
mutationId: CAPABILITY_UUID_EXAMPLE,
|
|
4955
5716
|
previousVersion: 1,
|
|
4956
5717
|
version: 2,
|
|
5718
|
+
operations: [{
|
|
5719
|
+
op: "setText",
|
|
5720
|
+
nodeId: "text_title",
|
|
5721
|
+
text: "Ready"
|
|
5722
|
+
}],
|
|
4957
5723
|
insertedNodeIds: [],
|
|
4958
5724
|
changedNodeIds: ["text_title"],
|
|
4959
5725
|
removedNodeIds: [],
|
|
@@ -5252,6 +6018,9 @@ const PROCEDURE_DESCRIPTIONS = {
|
|
|
5252
6018
|
"screen.complete": "Confirm a captured page after its bytes have been uploaded.",
|
|
5253
6019
|
"screen.delete": "Delete an unattached captured page owned by this person."
|
|
5254
6020
|
};
|
|
6021
|
+
|
|
6022
|
+
//#endregion
|
|
6023
|
+
//#region src/infrastructure/procedure-options.consts.ts
|
|
5255
6024
|
const OPTION_DESCRIPTIONS = {
|
|
5256
6025
|
...CANVAS_VERSION_OPTION_DESCRIPTIONS,
|
|
5257
6026
|
"--canvas-id": "Canvas id, from `enhance canvas list`.",
|
|
@@ -5335,7 +6104,14 @@ const OPTION_DESCRIPTIONS = {
|
|
|
5335
6104
|
"canvas.move --organisation-id": "Destination team UUID from `enhance organisation list`, or the literal `personal`.",
|
|
5336
6105
|
"canvas.duplicate --organisation-id": "Destination team UUID from `enhance organisation list`, or the literal `personal`.",
|
|
5337
6106
|
"canvas.deletePermanently --confirmation": "Exact canvas title returned by `enhance canvas list --deleted true`.",
|
|
6107
|
+
"canvas.textStyleLibrary.list --search": "Match published library titles in your teams and files shared with you.",
|
|
6108
|
+
"canvas.textStyleLibrary.publish --expected-revision": "Current published library revision; use 0 for its first publication.",
|
|
6109
|
+
"canvas.textStyleLibrary.publish --document-version": "Saved source document version containing the selected style definitions.",
|
|
6110
|
+
"canvas.textStyleLibrary.publish --publish": "Local text style ids to add or update in this publication, as a JSON array.",
|
|
6111
|
+
"canvas.textStyleLibrary.publish --remove": "Published text style ids to remove from the library, as a JSON array.",
|
|
6112
|
+
"canvas.textStyleLibrary.publish --description": "Release notes describing these library changes for consuming files.",
|
|
5338
6113
|
"canvas.document.save --base-version": "Current version from `canvas document get`; a stale value exits 5 with CONFLICT.",
|
|
6114
|
+
"canvas.document.get --after-version": "Saved revision to request subsequent retained mutations from, excluding that revision. Verify a contiguous chain before rebasing; missing history or a restore requires the current document.",
|
|
5339
6115
|
"canvas.document.save --document": "Complete opaque JSON object; preserve fields you did not intend to change.",
|
|
5340
6116
|
"canvas.document.save --screen-ids": "Complete replacement manifest of screen UUIDs; omit to detach every screen.",
|
|
5341
6117
|
"canvas.participants.setAccess --person-id": "Participant person id from `enhance canvas participants list`.",
|
|
@@ -5510,6 +6286,16 @@ const toCapabilityDefinition = (input) => {
|
|
|
5510
6286
|
|
|
5511
6287
|
//#endregion
|
|
5512
6288
|
//#region src/infrastructure/capability-policy.consts.ts
|
|
6289
|
+
const FONT_ASSET_POLICY = {
|
|
6290
|
+
exposure: "internal",
|
|
6291
|
+
reason: "Font upload and transfer lifecycle belongs to document authoring transactions.",
|
|
6292
|
+
owner: "product"
|
|
6293
|
+
};
|
|
6294
|
+
const RENDER_LIFECYCLE_POLICY = {
|
|
6295
|
+
exposure: "internal",
|
|
6296
|
+
reason: "Render creation, polling and cancellation belong to higher-level render capabilities.",
|
|
6297
|
+
owner: "product"
|
|
6298
|
+
};
|
|
5513
6299
|
const SHARED_CAPABILITY_POLICY = {
|
|
5514
6300
|
exposure: "shared",
|
|
5515
6301
|
reason: "Authenticated product operation supported equally by CLI and MCP.",
|
|
@@ -5531,16 +6317,16 @@ const PROCEDURE_CAPABILITY_POLICIES = {
|
|
|
5531
6317
|
reason: "Signed image upload reservation is wrapped by file-safe authoring.",
|
|
5532
6318
|
owner: "product"
|
|
5533
6319
|
},
|
|
5534
|
-
"canvas.
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
"canvas.
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
6320
|
+
"canvas.copyFonts": FONT_ASSET_POLICY,
|
|
6321
|
+
"canvas.reserveFont": FONT_ASSET_POLICY,
|
|
6322
|
+
"canvas.completeFont": FONT_ASSET_POLICY,
|
|
6323
|
+
"canvas.fontCatalog.list": FONT_ASSET_POLICY,
|
|
6324
|
+
"canvas.fontCatalog.reserve": FONT_ASSET_POLICY,
|
|
6325
|
+
"canvas.fontCatalog.complete": FONT_ASSET_POLICY,
|
|
6326
|
+
"canvas.fontCatalog.remove": FONT_ASSET_POLICY,
|
|
6327
|
+
"canvas.fontCatalog.import": FONT_ASSET_POLICY,
|
|
6328
|
+
"canvas.render.cancel": RENDER_LIFECYCLE_POLICY,
|
|
6329
|
+
"canvas.render.create": RENDER_LIFECYCLE_POLICY,
|
|
5544
6330
|
"canvas.render.download": {
|
|
5545
6331
|
exposure: "internal",
|
|
5546
6332
|
reason: "Signed downloads must be written through a protected artifact adapter.",
|
|
@@ -5551,11 +6337,7 @@ const PROCEDURE_CAPABILITY_POLICIES = {
|
|
|
5551
6337
|
reason: "Signed render exposure is a transport implementation detail.",
|
|
5552
6338
|
owner: "product"
|
|
5553
6339
|
},
|
|
5554
|
-
"canvas.render.get":
|
|
5555
|
-
exposure: "internal",
|
|
5556
|
-
reason: "Render polling is owned by higher-level render capabilities.",
|
|
5557
|
-
owner: "product"
|
|
5558
|
-
},
|
|
6340
|
+
"canvas.render.get": RENDER_LIFECYCLE_POLICY,
|
|
5559
6341
|
"canvas.render.snapshot": {
|
|
5560
6342
|
exposure: "internal",
|
|
5561
6343
|
reason: "Render snapshot creation is owned by higher-level render capabilities.",
|
|
@@ -5786,6 +6568,9 @@ const SHARED_CAPABILITY_PROCEDURES = /* @__PURE__ */ new Set([
|
|
|
5786
6568
|
"canvas.selection",
|
|
5787
6569
|
"canvas.setAccess",
|
|
5788
6570
|
"canvas.setReviewState",
|
|
6571
|
+
"canvas.textStyleLibrary.get",
|
|
6572
|
+
"canvas.textStyleLibrary.list",
|
|
6573
|
+
"canvas.textStyleLibrary.publish",
|
|
5789
6574
|
"canvas.tree",
|
|
5790
6575
|
"canvas.version.get",
|
|
5791
6576
|
"canvas.version.list",
|
|
@@ -6496,6 +7281,7 @@ const applyOperations = (handlers) => canvasCommenterProcedure.input(applyCanvas
|
|
|
6496
7281
|
const renderNext = applied.affectedBounds === null ? [] : [`enhance canvas render --canvas ${applied.canvasId} --bounds '${JSON.stringify(applied.affectedBounds)}' --expected-version ${String(applied.version)}`];
|
|
6497
7282
|
return {
|
|
6498
7283
|
...applied,
|
|
7284
|
+
operations: applied.operations.map((operation) => canvasOperationSchema.parse(operation)),
|
|
6499
7285
|
insertedNodeIds: [...applied.insertedNodeIds],
|
|
6500
7286
|
changedNodeIds: [...applied.changedNodeIds],
|
|
6501
7287
|
removedNodeIds: [...applied.removedNodeIds],
|
|
@@ -6629,9 +7415,16 @@ const createCanvasRouter = (handlers) => trpcRouter({
|
|
|
6629
7415
|
const getDocument = (handlers) => canvasReaderProcedure.input(getCanvasDocumentInputSchema).output(getCanvasDocumentOutputSchema).query(async ({ input, ctx }) => {
|
|
6630
7416
|
const result = orThrow(await handlers.getDocument.execute({
|
|
6631
7417
|
canvasId: input.canvasId,
|
|
7418
|
+
afterVersion: input.afterVersion,
|
|
6632
7419
|
withRoutes: ctx.canvasAccess.canSeeRoutes
|
|
6633
7420
|
}));
|
|
6634
7421
|
return {
|
|
7422
|
+
...result.mutations !== void 0 && { mutations: result.mutations.map((commit) => ({
|
|
7423
|
+
mutationId: commit.mutationId,
|
|
7424
|
+
previousVersion: commit.previousVersion,
|
|
7425
|
+
version: commit.version,
|
|
7426
|
+
operations: commit.operations.map((operation) => canvasOperationSchema.parse(operation))
|
|
7427
|
+
})) },
|
|
6635
7428
|
version: result.document.version,
|
|
6636
7429
|
document: result.document.document,
|
|
6637
7430
|
screens: result.screens.map((screen) => ({
|
|
@@ -6684,6 +7477,35 @@ const createCanvasDocumentRouter = (handlers) => trpcRouter({
|
|
|
6684
7477
|
save: saveDocument(handlers)
|
|
6685
7478
|
});
|
|
6686
7479
|
|
|
7480
|
+
//#endregion
|
|
7481
|
+
//#region ../api/src/canvas/infrastructure/canvas-font.router.ts
|
|
7482
|
+
const createCanvasFontRouter = (handlers) => trpcRouter({
|
|
7483
|
+
copyFonts: canvasCommenterProcedure.meta({ description: "Copy readable file fonts into this canvas before publishing pasted content." }).input(copyCanvasFontsInputSchema).output(copyCanvasFontsOutputSchema).mutation(async ({ input, ctx }) => {
|
|
7484
|
+
orThrow(await handlers.fonts.copy({
|
|
7485
|
+
...input,
|
|
7486
|
+
viewer: ctx.viewer
|
|
7487
|
+
}));
|
|
7488
|
+
return { resources: input.sources.map((source) => ({
|
|
7489
|
+
source,
|
|
7490
|
+
path: canvasFontAssetPath(input.canvasId, source.sha256)
|
|
7491
|
+
})) };
|
|
7492
|
+
}),
|
|
7493
|
+
reserveFont: canvasCommenterProcedure.meta({ description: "Reserve a file-scoped font upload pinned to its SHA-256 digest." }).input(reserveCanvasFontInputSchema).output(reserveCanvasFontOutputSchema).mutation(async ({ input }) => {
|
|
7494
|
+
const upload = orThrow(await handlers.fonts.reserve(input));
|
|
7495
|
+
return {
|
|
7496
|
+
path: canvasFontAssetPath(input.canvasId, input.sha256),
|
|
7497
|
+
upload: {
|
|
7498
|
+
...upload,
|
|
7499
|
+
expiresAt: upload.expiresAt.toISOString()
|
|
7500
|
+
}
|
|
7501
|
+
};
|
|
7502
|
+
}),
|
|
7503
|
+
completeFont: canvasCommenterProcedure.meta({ description: "Verify that the exact font bytes have arrived before using the resource." }).input(completeCanvasFontInputSchema).output(completeCanvasFontOutputSchema).mutation(async ({ input }) => {
|
|
7504
|
+
orThrow(await handlers.fonts.complete(input));
|
|
7505
|
+
return { path: canvasFontAssetPath(input.canvasId, input.sha256) };
|
|
7506
|
+
})
|
|
7507
|
+
});
|
|
7508
|
+
|
|
6687
7509
|
//#endregion
|
|
6688
7510
|
//#region ../api/src/canvas/infrastructure/canvas-image.router.ts
|
|
6689
7511
|
const createCanvasImageRouter = (handlers) => trpcRouter({ reserveImage: canvasCommenterProcedure.meta({ description: "Reserve storage and upload instructions for one canvas image." }).input(reserveCanvasImageInputSchema).output(reserveCanvasImageOutputSchema).mutation(async ({ input }) => {
|
|
@@ -7641,7 +8463,8 @@ const nextCommands = (canvasId, version, nodeIds) => [
|
|
|
7641
8463
|
].slice(0, MAX_NEXT_COMMANDS);
|
|
7642
8464
|
const toCanvasSelection = (canvasId, source, selection) => toCanvasInspection(source.document).map((projected) => {
|
|
7643
8465
|
const summaries = new Map(projected.nodes.map((node) => [node.id, node]));
|
|
7644
|
-
const
|
|
8466
|
+
const pendingStatus = selection?.status === "updating" || selection?.status === "unsupported" ? selection.status : null;
|
|
8467
|
+
const selectedNodeIds = pendingStatus === null ? selection?.selectedNodeIds ?? [] : [];
|
|
7645
8468
|
const nodes = selectedNodeIds.flatMap((nodeId) => {
|
|
7646
8469
|
const node = summaries.get(nodeId);
|
|
7647
8470
|
return node === void 0 ? [] : [node];
|
|
@@ -7650,7 +8473,7 @@ const toCanvasSelection = (canvasId, source, selection) => toCanvasInspection(so
|
|
|
7650
8473
|
const missingNodeIds = selectedNodeIds.filter((nodeId) => !found.has(nodeId));
|
|
7651
8474
|
return {
|
|
7652
8475
|
canvasId,
|
|
7653
|
-
status: selection === null ? "offline" : selectedNodeIds.length === 0 ? "none" : nodes.length === 0 ? "stale" : "selected",
|
|
8476
|
+
status: pendingStatus ?? (selection === null ? "offline" : selectedNodeIds.length === 0 ? "none" : nodes.length === 0 ? "stale" : "selected"),
|
|
7654
8477
|
documentVersion: source.version,
|
|
7655
8478
|
selectionRevision: selection?.selectionRevision ?? null,
|
|
7656
8479
|
selectionChangedAt: selection?.selectionChangedAt?.toISOString() ?? null,
|
|
@@ -7866,6 +8689,56 @@ const createCanvasVersionRouter = (handlers) => trpcRouter({
|
|
|
7866
8689
|
duplicate: duplicate(handlers)
|
|
7867
8690
|
});
|
|
7868
8691
|
|
|
8692
|
+
//#endregion
|
|
8693
|
+
//#region ../api/src/canvas/infrastructure/font-catalog.router.ts
|
|
8694
|
+
const entryView = (entry) => ({
|
|
8695
|
+
...entry,
|
|
8696
|
+
createdAt: entry.createdAt.toISOString(),
|
|
8697
|
+
path: `/v1/font-catalog/${entry.kind}/${entry.ownerId}/${entry.sha256}`
|
|
8698
|
+
});
|
|
8699
|
+
const createFontCatalogRouter = ({ fontCatalog }) => trpcRouter({
|
|
8700
|
+
list: personProcedure.meta({ description: "List fonts uploaded by you or shared with your team." }).input(fontCatalogScopeSchema).output(listFontCatalogOutputSchema).query(async ({ input, ctx }) => {
|
|
8701
|
+
const result = orThrow(await fontCatalog.list({
|
|
8702
|
+
...input,
|
|
8703
|
+
personId: ctx.viewer.personId
|
|
8704
|
+
}));
|
|
8705
|
+
return {
|
|
8706
|
+
...result,
|
|
8707
|
+
entries: result.entries.map((entry) => entryView(entry))
|
|
8708
|
+
};
|
|
8709
|
+
}),
|
|
8710
|
+
reserve: personProcedure.meta({ description: "Reserve an immutable personal or team font upload." }).input(reserveFontCatalogInputSchema).output(reserveFontCatalogOutputSchema).mutation(async ({ input, ctx }) => {
|
|
8711
|
+
const upload = orThrow(await fontCatalog.reserve({
|
|
8712
|
+
...input,
|
|
8713
|
+
personId: ctx.viewer.personId
|
|
8714
|
+
}));
|
|
8715
|
+
return { upload: {
|
|
8716
|
+
...upload,
|
|
8717
|
+
expiresAt: upload.expiresAt.toISOString()
|
|
8718
|
+
} };
|
|
8719
|
+
}),
|
|
8720
|
+
complete: personProcedure.meta({ description: "Publish a verified font version with acknowledged sharing rights." }).input(completeFontCatalogInputSchema).output(fontCatalogEntrySchema).mutation(async ({ input, ctx }) => entryView(orThrow(await fontCatalog.complete({
|
|
8721
|
+
...input,
|
|
8722
|
+
personId: ctx.viewer.personId
|
|
8723
|
+
})))),
|
|
8724
|
+
remove: personProcedure.meta({ description: "Remove a library entry while retaining existing file font copies." }).input(removeFontCatalogInputSchema).output(z.object({ removed: z.literal(true) })).mutation(async ({ input, ctx }) => {
|
|
8725
|
+
orThrow(await fontCatalog.remove({
|
|
8726
|
+
...input,
|
|
8727
|
+
personId: ctx.viewer.personId
|
|
8728
|
+
}));
|
|
8729
|
+
return { removed: true };
|
|
8730
|
+
}),
|
|
8731
|
+
import: personProcedure.meta({ description: "Copy selected library font versions into an editable file." }).input(importFontCatalogInputSchema).output(importFontCatalogOutputSchema).mutation(async ({ input, ctx }) => {
|
|
8732
|
+
return { resources: orThrow(await fontCatalog.import({
|
|
8733
|
+
...input,
|
|
8734
|
+
personId: ctx.viewer.personId
|
|
8735
|
+
})).map((entry) => ({
|
|
8736
|
+
entry: entryView(entry),
|
|
8737
|
+
path: canvasFontAssetPath(input.canvasId, entry.sha256)
|
|
8738
|
+
})) };
|
|
8739
|
+
})
|
|
8740
|
+
});
|
|
8741
|
+
|
|
7869
8742
|
//#endregion
|
|
7870
8743
|
//#region ../api/src/canvas/domain/render-result.value-object.ts
|
|
7871
8744
|
const isRenderConversionResult = (result) => "rootNodeId" in result;
|
|
@@ -8204,6 +9077,39 @@ const createRenderExposureRouter = (handlers) => trpcRouter({ exposure: renderPr
|
|
|
8204
9077
|
};
|
|
8205
9078
|
}) });
|
|
8206
9079
|
|
|
9080
|
+
//#endregion
|
|
9081
|
+
//#region ../api/src/canvas/infrastructure/text-style-library.router.ts
|
|
9082
|
+
const view = (publication) => textStyleLibrarySchema.parse({
|
|
9083
|
+
...publication,
|
|
9084
|
+
publishedAt: publication.publishedAt.toISOString()
|
|
9085
|
+
});
|
|
9086
|
+
const createTextStyleLibraryRouter = ({ textStyleLibrary }) => trpcRouter({
|
|
9087
|
+
list: personProcedure.meta({ description: "Find published text style libraries in your teams and files shared with you." }).input(listTextStyleLibrariesInputSchema).output(listTextStyleLibrariesOutputSchema).query(async ({ input, ctx }) => {
|
|
9088
|
+
const page = orThrow(await textStyleLibrary.list({
|
|
9089
|
+
...input,
|
|
9090
|
+
personId: ctx.viewer.personId
|
|
9091
|
+
}));
|
|
9092
|
+
return {
|
|
9093
|
+
...page,
|
|
9094
|
+
items: page.items.map((item) => ({
|
|
9095
|
+
...item,
|
|
9096
|
+
publishedAt: item.publishedAt.toISOString()
|
|
9097
|
+
}))
|
|
9098
|
+
};
|
|
9099
|
+
}),
|
|
9100
|
+
get: personProcedure.meta({ description: "Read the last published text styles from an accessible source file." }).input(textStyleLibraryIdentitySchema).output(textStyleLibrarySchema.nullable()).query(async ({ input, ctx }) => {
|
|
9101
|
+
const publication = orThrow(await textStyleLibrary.get({
|
|
9102
|
+
...input,
|
|
9103
|
+
personId: ctx.viewer.personId
|
|
9104
|
+
}));
|
|
9105
|
+
return publication === null ? null : view(publication);
|
|
9106
|
+
}),
|
|
9107
|
+
publish: personProcedure.meta({ description: "Publish selected text style changes without exposing unfinished edits or updating consumer files." }).input(publishTextStyleLibraryInputSchema).output(textStyleLibrarySchema).mutation(async ({ input, ctx }) => view(orThrow(await textStyleLibrary.publish({
|
|
9108
|
+
...input,
|
|
9109
|
+
personId: ctx.viewer.personId
|
|
9110
|
+
}))))
|
|
9111
|
+
});
|
|
9112
|
+
|
|
8207
9113
|
//#endregion
|
|
8208
9114
|
//#region ../api/src/shared/lib/units.consts.ts
|
|
8209
9115
|
/**
|
|
@@ -9354,6 +10260,9 @@ const createAppRouter = (handlers, options = DEFAULT_ROUTER_OPTIONS) => trpcRout
|
|
|
9354
10260
|
canvas: trpcRouter({
|
|
9355
10261
|
...createCanvasRouter(handlers.canvas)._def.record,
|
|
9356
10262
|
...createCanvasImageRouter(handlers.canvas)._def.record,
|
|
10263
|
+
...createCanvasFontRouter(handlers.canvas)._def.record,
|
|
10264
|
+
fontCatalog: createFontCatalogRouter(handlers.canvas),
|
|
10265
|
+
textStyleLibrary: createTextStyleLibraryRouter(handlers.canvas),
|
|
9357
10266
|
...createCanvasLifecycleRouter(handlers.canvas)._def.record,
|
|
9358
10267
|
...createCanvasInspectionRouter(handlers.render, options.webOrigin),
|
|
9359
10268
|
selection: createCanvasSelectionRoute(handlers.canvas.selection, handlers.render.readCanvas),
|
|
@@ -9438,6 +10347,26 @@ const handlers = {
|
|
|
9438
10347
|
getDocument: unavailable,
|
|
9439
10348
|
saveDocument: unavailable,
|
|
9440
10349
|
reserveImage: unavailable,
|
|
10350
|
+
fonts: {
|
|
10351
|
+
copy: unavailable.execute,
|
|
10352
|
+
importResource: unavailable.execute,
|
|
10353
|
+
reserve: unavailable.execute,
|
|
10354
|
+
complete: unavailable.execute,
|
|
10355
|
+
deliver: unavailable.execute
|
|
10356
|
+
},
|
|
10357
|
+
fontCatalog: {
|
|
10358
|
+
list: unavailable.execute,
|
|
10359
|
+
reserve: unavailable.execute,
|
|
10360
|
+
complete: unavailable.execute,
|
|
10361
|
+
remove: unavailable.execute,
|
|
10362
|
+
import: unavailable.execute,
|
|
10363
|
+
deliver: unavailable.execute
|
|
10364
|
+
},
|
|
10365
|
+
textStyleLibrary: {
|
|
10366
|
+
get: unavailable.execute,
|
|
10367
|
+
list: unavailable.execute,
|
|
10368
|
+
publish: unavailable.execute
|
|
10369
|
+
},
|
|
9441
10370
|
listParticipants: unavailable,
|
|
9442
10371
|
setParticipantAccess: unavailable,
|
|
9443
10372
|
revokeParticipant: unavailable,
|
|
@@ -9554,6 +10483,15 @@ const IMPORT_SOURCE_EXAMPLE = {
|
|
|
9554
10483
|
targetNodeId: "root"
|
|
9555
10484
|
}
|
|
9556
10485
|
};
|
|
10486
|
+
const LIBRARY_PUBLISH_EXAMPLE = {
|
|
10487
|
+
canvasId: CAPABILITY_UUID_EXAMPLE,
|
|
10488
|
+
mutationId: CAPABILITY_UUID_EXAMPLE,
|
|
10489
|
+
expectedRevision: 0,
|
|
10490
|
+
documentVersion: 1,
|
|
10491
|
+
publish: ["body"],
|
|
10492
|
+
remove: [],
|
|
10493
|
+
description: "Publish the Body text style."
|
|
10494
|
+
};
|
|
9557
10495
|
const recordFrom$1 = (value, label) => {
|
|
9558
10496
|
const parsed = jsonRecordSchema.safeParse(value);
|
|
9559
10497
|
if (!parsed.success) throw new TypeError(`${label} is not an object`);
|
|
@@ -9608,6 +10546,7 @@ const createCapabilityCatalogAdapter = () => {
|
|
|
9608
10546
|
policy: procedurePolicy,
|
|
9609
10547
|
cliPath: procedurePolicy.exposure === "shared" ? id.replaceAll(".", " ") : null,
|
|
9610
10548
|
...id === "canvas.render.importSource" && { inputExample: IMPORT_SOURCE_EXAMPLE },
|
|
10549
|
+
...id === "canvas.textStyleLibrary.publish" && { inputExample: LIBRARY_PUBLISH_EXAMPLE },
|
|
9611
10550
|
...id === "canvas.document.save" && { inputExample: {
|
|
9612
10551
|
canvasId: "00000000-0000-4000-8000-000000000010",
|
|
9613
10552
|
baseVersion: 1,
|
|
@@ -9990,4 +10929,4 @@ const withCommandInFailure = (value, commandName) => ({
|
|
|
9990
10929
|
});
|
|
9991
10930
|
|
|
9992
10931
|
//#endregion
|
|
9993
|
-
export { createOrganisationOutputSchema as $, parseCanvasReference as A,
|
|
10932
|
+
export { createOrganisationOutputSchema as $, parseCanvasReference as A, canvasAdditionalStyleSchema as At, PROTOTYPE_ARTIFACT_MANIFEST_PATH as B, transcriptReadCapabilityInputSchema as C, getCanvasRenderOutputSchema as Ct, assertCanvasReferenceOperations as D, canvasAxisStyleProperties as Dt, assertCanvasReferenceNodes as E, canvasAuthoredStyleDeclarations as Et, completeScreenOutputSchema as F, getPrototypePublishStatusOutputSchema as G, createPrototypeArtifactOutputSchema as H, createScreenOutputSchema as I, submitPrototypeArtifactOutputSchema as J, prototypeArtifactManifestSchema as K, appendRecordingChunkOutputSchema as L, CliError as M, transcriptOutputSchema as N, canvasReferenceNodeIds as O, canvasLayoutMainAxisOf as Ot, appErrorSchema as P, createAgentTokenOutputSchema as Q, completeRecordingOutputSchema as R, recordingSnapshotCapabilityInputSchema as S, downloadCanvasRenderOutputSchema as St, canvasEditsSchema as T, canvasAuthoredLayoutValueOf as Tt, foldPrototypeArtifactPath as U, attachPrototypeArtifactOutputSchema as V, getPrototypeArtifactCapabilitiesOutputSchema as W, MCP_AUTH_SCOPE as X, getMeOutputSchema as Y, cliAuthConfigurationSchema as Z, canvasApplyCapabilityInputSchema as _, canvasRenderSourceStateSchema as _t, toExitCode as a, canvasAgentActivityPhaseSchema as at, commentAttentionCapabilityInputSchema as b, createCanvasRenderOutputSchema as bt, toSharedCapabilities as c, saveCanvasDocumentOutputSchema as ct, createCapabilityCatalogAdapter as d, applyCanvasOperationsOutputSchema as dt, emptyFixtureDocument as et, createRouterShapeAdapter as f, canvasOperationSchema as ft, PROCEDURE_DESCRIPTIONS as g, RENDER_MIN_SCALE as gt, OPTION_DESCRIPTIONS as h, getCanvasConversionOutputSchema as ht, toCanvasAuthoringResult as i, beginCanvasActivityOutputSchema as it, PartialBatchError as j, canvasSchema as jt, fromCanvasReference as k, canvasLayoutPriorityDeclarations as kt, createMcpCapabilityDiscoveryAdapter as l, MAX_CANVAS_OPERATIONS as lt, toCapabilityDefinition as m, createCanvasConversionOutputSchema as mt, withCommandName as n, applyCanvasTypographyPatch as nt, toFailurePayload as o, canvasLayoutWithoutCssProperties as ot, createCapabilityPolicyAdapter as p, canvasNodeStylePatchSchema as pt, prototypeArtifactPathSchema as q, canvasRenderResultSchema as r, canvasCssTypographyOwners as rt, toPresentedCapabilities as s, getCanvasDocumentOutputSchema as st, withCommandInFailure as t, withFixtureScreen as tt, ProcessExitError as u, applyCanvasOperationsInputSchema as ut, canvasRenderCapabilityInputSchema as v, canvasRenderTargetSchema as vt, canvasEditCapabilityInputSchema as w, canvasReadableSceneDocumentSchema as wt, prototypePublishCapabilityInputSchema as x, createRecordingSnapshotOutputSchema as xt, canvasWriteHtmlCapabilityInputSchema as y, canvasWorldBoundsSchema as yt, startRecordingOutputSchema as z };
|