@enhance-eng/enhance 0.1.7 → 0.1.14
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-BSUBcRJm.mjs → cli-output-identity.lib-bX6NwZjd.mjs} +602 -85
- package/dist/main.mjs +265 -354
- package/dist/mcp-invocation.adapter-BdZ-LpPW.mjs +119 -0
- package/dist/mcp-main.mjs +36 -20
- package/dist/{mcp-server.adapter-lxpsuDlU.mjs → mcp-server.adapter-DBlOw4BM.mjs} +23 -12
- package/dist/mcp.mjs +2 -2
- package/dist/{mutation-key.adapter-EvvklGSw.mjs → mutation-key.adapter-p1odGHfg.mjs} +20 -7
- package/dist/remote-mcp-main.mjs +5 -5
- package/package.json +1 -1
- package/dist/mcp-invocation.adapter-Bn41hcLB.mjs +0 -64
package/dist/main.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { A as startRecordingOutputSchema, C as CliError, D as createScreenOutputSchema, E as completeScreenOutputSchema, G as
|
|
3
|
-
import { a as createOauthLoopbackAdapter, c as createWriteHtmlCanvasComposite, d as createRenderCanvasComposite, f as createAuthUseCase, l as createApplyCanvasComposite, n as createHttpRemoteAdapter, o as createCapabilityInvocationAdapter, r as CLI_CONFIG, s as createRenderFileAdapter, t as createMutationKeyAdapter, u as createCanvasActivityComposite } from "./mutation-key.adapter-
|
|
2
|
+
import { $ as canvasLayoutWithoutCssProperties, A as startRecordingOutputSchema, C as CliError, D as createScreenOutputSchema, E as completeScreenOutputSchema, G as emptyFixtureDocument, J as canvasAgentActivityPhaseSchema, K as withFixtureScreen, O as appendRecordingChunkOutputSchema, Q as canvasNodeStylePatchSchema, S as PartialBatchError, T as appErrorSchema, W as createOrganisationOutputSchema, Y as MAX_CANVAS_OPERATIONS, Z as canvasOperationSchema, _t as canvasSchema, at as canvasWorldBoundsSchema, c as ProcessExitError, d as createCapabilityPolicyAdapter, dt as canvasAdditionalStyleSchema, et as getCanvasDocumentOutputSchema, ft as canvasAuthoredLayoutValueOf, gt as canvasLayoutPriorityDeclarations, ht as canvasLayoutMainAxisOf, i as toFailurePayload, it as RENDER_MIN_SCALE, k as completeRecordingOutputSchema, l as createCapabilityCatalogAdapter, m as PROCEDURE_DESCRIPTIONS, mt as canvasAxisStyleProperties, n as withCommandName, o as toSharedCapabilities, p as OPTION_DESCRIPTIONS, pt as canvasAuthoredStyleDeclarations, q as beginCanvasActivityOutputSchema, r as toExitCode, s as createMcpCapabilityDiscoveryAdapter, t as withCommandInFailure, tt as saveCanvasDocumentOutputSchema, u as createRouterShapeAdapter, ut as canvasReadableSceneDocumentSchema } from "./cli-output-identity.lib-bX6NwZjd.mjs";
|
|
3
|
+
import { a as createOauthLoopbackAdapter, c as createWriteHtmlCanvasComposite, d as createRenderCanvasComposite, f as createAuthUseCase, l as createApplyCanvasComposite, n as createHttpRemoteAdapter, o as createCapabilityInvocationAdapter, r as CLI_CONFIG, s as createRenderFileAdapter, t as createMutationKeyAdapter, u as createCanvasActivityComposite } from "./mutation-key.adapter-p1odGHfg.mjs";
|
|
4
4
|
import { t as toCapabilityInventory } from "./capability-inventory.mapper-DyYXyVBJ.mjs";
|
|
5
5
|
import { t as createFileCredentialAdapter } from "./file-credential.adapter-rI5HpMEo.mjs";
|
|
6
6
|
import { Command } from "commander";
|
|
@@ -15,69 +15,6 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
15
15
|
import { readFile } from "node:fs/promises";
|
|
16
16
|
import { proxify } from "trpc-cli/dist/proxify.js";
|
|
17
17
|
|
|
18
|
-
//#region ../../packages/contract/src/canvas/canvas-presentation-defaults.lib.ts
|
|
19
|
-
const emptyCanvasNodeLayout = () => ({
|
|
20
|
-
rotation: 0,
|
|
21
|
-
flipHorizontal: false,
|
|
22
|
-
flipVertical: false,
|
|
23
|
-
horizontal: {
|
|
24
|
-
mode: "fixed",
|
|
25
|
-
value: 0
|
|
26
|
-
},
|
|
27
|
-
vertical: {
|
|
28
|
-
mode: "fixed",
|
|
29
|
-
value: 0
|
|
30
|
-
},
|
|
31
|
-
position: "absolute",
|
|
32
|
-
clipContent: false
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region ../../packages/contract/src/fixture/canvas-fixture.lib.ts
|
|
37
|
-
const ROOT_FIXTURE_NODE_ID = "root";
|
|
38
|
-
const SORT_KEY_DIGITS = 4;
|
|
39
|
-
const sortKeyAt = (seat) => `a${String(seat).padStart(SORT_KEY_DIGITS, "0")}`;
|
|
40
|
-
const emptyFixtureDocument = () => ({
|
|
41
|
-
version: 2,
|
|
42
|
-
nodes: { [ROOT_FIXTURE_NODE_ID]: {
|
|
43
|
-
id: ROOT_FIXTURE_NODE_ID,
|
|
44
|
-
label: "Canvas",
|
|
45
|
-
component: "root",
|
|
46
|
-
styles: {}
|
|
47
|
-
} },
|
|
48
|
-
relationships: {}
|
|
49
|
-
});
|
|
50
|
-
const withFixtureNode = (document, node) => ({
|
|
51
|
-
...document,
|
|
52
|
-
nodes: {
|
|
53
|
-
...document.nodes,
|
|
54
|
-
[node.id]: node
|
|
55
|
-
},
|
|
56
|
-
relationships: {
|
|
57
|
-
...document.relationships,
|
|
58
|
-
[node.id]: {
|
|
59
|
-
parentId: ROOT_FIXTURE_NODE_ID,
|
|
60
|
-
sortKey: sortKeyAt(Object.keys(document.relationships).length)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
const withFixtureScreen = (document, input) => withFixtureNode(document, {
|
|
65
|
-
id: input.id,
|
|
66
|
-
label: input.label,
|
|
67
|
-
component: "screen",
|
|
68
|
-
props: { capture: {
|
|
69
|
-
viewport: input.viewport,
|
|
70
|
-
atMs: 0,
|
|
71
|
-
screenId: input.screenId
|
|
72
|
-
} },
|
|
73
|
-
styles: {},
|
|
74
|
-
box: {
|
|
75
|
-
...input.at,
|
|
76
|
-
...input.viewport
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
//#endregion
|
|
81
18
|
//#region ../../packages/contract/src/recording/event-stream.lib.ts
|
|
82
19
|
/**
|
|
83
20
|
* @justified docs/comments.md#intent
|
|
@@ -474,6 +411,13 @@ const assertNodesInScope = (scope, nodeIds) => {
|
|
|
474
411
|
const outside = nodeIds.filter((id) => !scope.has(id));
|
|
475
412
|
if (outside.length > 0) throw new CliError("BAD_REQUEST", `These nodes are outside the link selection: ${outside.join(", ")}.`, "Limit the edit to the selected nodes and their descendants. Request a wider selection only when the person wants a wider change.");
|
|
476
413
|
};
|
|
414
|
+
const conversionScope = (operation) => {
|
|
415
|
+
if (operation.destination.kind === "adjacent") throw new CliError("BAD_REQUEST", "Adjacent conversion would insert outside the link selection.", "Use insert-children or replace with a selected target.");
|
|
416
|
+
return {
|
|
417
|
+
required: [operation.destination.targetNodeId],
|
|
418
|
+
inserted: Object.keys(operation.nodes)
|
|
419
|
+
};
|
|
420
|
+
};
|
|
477
421
|
const operationScope = (operation, document) => {
|
|
478
422
|
switch (operation.op) {
|
|
479
423
|
case "insertNode": return {
|
|
@@ -485,12 +429,7 @@ const operationScope = (operation, document) => {
|
|
|
485
429
|
required: [operation.parentId, ...operation.afterId === void 0 ? [] : [operation.afterId]],
|
|
486
430
|
inserted: [operation.nodeId]
|
|
487
431
|
};
|
|
488
|
-
case "insertConvertedSubtree":
|
|
489
|
-
if (operation.destination.kind === "adjacent") throw new CliError("BAD_REQUEST", "Adjacent conversion would insert outside the link selection.", "Use insert-children or replace with a selected target.");
|
|
490
|
-
return {
|
|
491
|
-
required: [operation.destination.targetNodeId],
|
|
492
|
-
inserted: Object.keys(operation.nodes)
|
|
493
|
-
};
|
|
432
|
+
case "insertConvertedSubtree": return conversionScope(operation);
|
|
494
433
|
case "move":
|
|
495
434
|
case "setParentage": {
|
|
496
435
|
const parentId = operation.op === "move" ? operation.parentId : operation.parentage.parentId;
|
|
@@ -503,6 +442,7 @@ const operationScope = (operation, document) => {
|
|
|
503
442
|
case "setText":
|
|
504
443
|
case "setBox":
|
|
505
444
|
case "setLabel":
|
|
445
|
+
case "setContainerKind":
|
|
506
446
|
case "setVisibility":
|
|
507
447
|
case "setLocked":
|
|
508
448
|
case "setConstraints":
|
|
@@ -547,7 +487,7 @@ const sceneAtVersion = async (input, canvasId, expectedVersion) => {
|
|
|
547
487
|
const held = getCanvasDocumentOutputSchema.safeParse(await input.remote.query("canvas.document.get", { canvasId }));
|
|
548
488
|
if (!held.success) throw new CliError("INTERNAL", "The API returned an invalid canvas document.", "Run `enhance doctor` and report incompatible API and CLI versions.");
|
|
549
489
|
if (held.data.version !== expectedVersion) throw new CliError("CONFLICT", `Canvas version ${String(held.data.version)} no longer matches --base-version ${String(expectedVersion)}.`, `Run 'enhance canvas tree --canvas ${canvasId}' and recompute against version ${String(held.data.version)}.`);
|
|
550
|
-
const scene =
|
|
490
|
+
const scene = canvasReadableSceneDocumentSchema.safeParse(held.data.document);
|
|
551
491
|
if (scene.success) return scene.data;
|
|
552
492
|
throw new CliError("INTERNAL", "The stored canvas is not an editable scene.", "Open the canvas in the editor and repair or recreate the invalid document.");
|
|
553
493
|
};
|
|
@@ -707,233 +647,104 @@ const configureCanvasAuthoringActivity = (canvas, input) => {
|
|
|
707
647
|
configureFinish(canvas, input);
|
|
708
648
|
};
|
|
709
649
|
|
|
710
|
-
//#endregion
|
|
711
|
-
//#region src/application/canvas-style-layout.use-case.ts
|
|
712
|
-
const LAYOUT_PROPERTY$1 = /^(?:align|bottom|column-gap|display|flex|gap|height|justify|left|order|overflow|padding|position|right|row-gap|top|transform|width)/u;
|
|
713
|
-
const canvasStyleNumeric = (value) => {
|
|
714
|
-
if (typeof value === "number") return Number.isFinite(value) ? value : null;
|
|
715
|
-
if (typeof value !== "string") return null;
|
|
716
|
-
const match = /^(-?\d+(?:\.\d+)?)(?:px)?$/u.exec(value.trim());
|
|
717
|
-
return match === null ? null : Number(match[1]);
|
|
718
|
-
};
|
|
719
|
-
const sizeIntent = (value, fallback) => {
|
|
720
|
-
const number = canvasStyleNumeric(value);
|
|
721
|
-
if (number !== null) return {
|
|
722
|
-
mode: "fixed",
|
|
723
|
-
value: Math.max(0, number)
|
|
724
|
-
};
|
|
725
|
-
if (["100%", "fill"].includes(String(value))) return { mode: "fill" };
|
|
726
|
-
if ([
|
|
727
|
-
"fit-content",
|
|
728
|
-
"auto",
|
|
729
|
-
"hug"
|
|
730
|
-
].includes(String(value))) return { mode: "hug" };
|
|
731
|
-
return fallback;
|
|
732
|
-
};
|
|
733
|
-
const fourSides = (styles, property, current) => {
|
|
734
|
-
const shorthand = styles[property];
|
|
735
|
-
const [top = current.top, right = top, bottom = top, left = right] = typeof shorthand === "string" ? shorthand.split(/\s+/u).map((value) => canvasStyleNumeric(value) ?? 0) : typeof shorthand === "number" ? [shorthand] : [];
|
|
736
|
-
return {
|
|
737
|
-
top: Math.max(0, canvasStyleNumeric(styles[`${property}-top`]) ?? top),
|
|
738
|
-
right: Math.max(0, canvasStyleNumeric(styles[`${property}-right`]) ?? right),
|
|
739
|
-
bottom: Math.max(0, canvasStyleNumeric(styles[`${property}-bottom`]) ?? bottom),
|
|
740
|
-
left: Math.max(0, canvasStyleNumeric(styles[`${property}-left`]) ?? left)
|
|
741
|
-
};
|
|
742
|
-
};
|
|
743
|
-
const alignment = (value, fallback) => {
|
|
744
|
-
switch (value) {
|
|
745
|
-
case "center":
|
|
746
|
-
case "start":
|
|
747
|
-
case "stretch": return value;
|
|
748
|
-
case "end":
|
|
749
|
-
case "flex-end": return "end";
|
|
750
|
-
case "flex-start": return "start";
|
|
751
|
-
default: return fallback;
|
|
752
|
-
}
|
|
753
|
-
};
|
|
754
|
-
const distribution = (value, fallback) => {
|
|
755
|
-
switch (value) {
|
|
756
|
-
case "center":
|
|
757
|
-
case "space-around":
|
|
758
|
-
case "space-between":
|
|
759
|
-
case "space-evenly":
|
|
760
|
-
case "start": return value;
|
|
761
|
-
case "end":
|
|
762
|
-
case "flex-end": return "end";
|
|
763
|
-
case "flex-start": return "start";
|
|
764
|
-
default: return fallback;
|
|
765
|
-
}
|
|
766
|
-
};
|
|
767
|
-
const baseContainer = () => ({
|
|
768
|
-
direction: "column",
|
|
769
|
-
alignItems: "start",
|
|
770
|
-
alignContent: "start",
|
|
771
|
-
justifyContent: "start",
|
|
772
|
-
gap: 0,
|
|
773
|
-
rowGap: 0,
|
|
774
|
-
columnGap: 0,
|
|
775
|
-
wrap: "nowrap",
|
|
776
|
-
padding: {
|
|
777
|
-
top: 0,
|
|
778
|
-
right: 0,
|
|
779
|
-
bottom: 0,
|
|
780
|
-
left: 0
|
|
781
|
-
}
|
|
782
|
-
});
|
|
783
|
-
const nextContainer = (current, styles) => {
|
|
784
|
-
const display = styles["display"];
|
|
785
|
-
if (["block", "none"].includes(String(display))) return void 0;
|
|
786
|
-
const hasFlexDisplay = ["flex", "inline-flex"].includes(String(display));
|
|
787
|
-
if (current === void 0 && !hasFlexDisplay) return void 0;
|
|
788
|
-
const container = { ...current ?? baseContainer() };
|
|
789
|
-
const direction = styles["flex-direction"];
|
|
790
|
-
container.direction = direction === void 0 ? container.direction : String(direction).startsWith("row") ? "row" : "column";
|
|
791
|
-
container.alignItems = alignment(styles["align-items"], container.alignItems);
|
|
792
|
-
container.justifyContent = distribution(styles["justify-content"], container.justifyContent);
|
|
793
|
-
container.alignContent = distribution(styles["align-content"], container.alignContent === "stretch" ? "start" : container.alignContent ?? "start");
|
|
794
|
-
container.gap = Math.max(0, canvasStyleNumeric(styles["gap"]) ?? container.gap);
|
|
795
|
-
container.rowGap = Math.max(0, canvasStyleNumeric(styles["row-gap"]) ?? container.rowGap ?? container.gap);
|
|
796
|
-
container.columnGap = Math.max(0, canvasStyleNumeric(styles["column-gap"]) ?? container.columnGap ?? container.gap);
|
|
797
|
-
container.wrap = styles["flex-wrap"] === "wrap" ? "wrap" : container.wrap ?? "nowrap";
|
|
798
|
-
container.padding = fourSides(styles, "padding", container.padding);
|
|
799
|
-
return container;
|
|
800
|
-
};
|
|
801
|
-
const itemPatch = (base, styles) => {
|
|
802
|
-
const grow = canvasStyleNumeric(styles["flex-grow"]);
|
|
803
|
-
const shrink = canvasStyleNumeric(styles["flex-shrink"]);
|
|
804
|
-
const order = canvasStyleNumeric(styles["order"]);
|
|
805
|
-
return {
|
|
806
|
-
horizontal: sizeIntent(styles["width"], base.horizontal),
|
|
807
|
-
vertical: sizeIntent(styles["height"], base.vertical),
|
|
808
|
-
...styles["align-self"] !== void 0 && { alignSelf: alignment(styles["align-self"], "start") },
|
|
809
|
-
...grow !== null && { flexGrow: Math.max(0, grow) },
|
|
810
|
-
...shrink !== null && { flexShrink: Math.max(0, shrink) },
|
|
811
|
-
...styles["flex-basis"] !== void 0 && { flexBasis: canvasStyleNumeric(styles["flex-basis"]) ?? "auto" },
|
|
812
|
-
...order !== null && { order: Math.round(order) }
|
|
813
|
-
};
|
|
814
|
-
};
|
|
815
|
-
const nextCanvasLayout = (node, styles) => {
|
|
816
|
-
if (Object.keys(styles).every((property) => !LAYOUT_PROPERTY$1.test(property))) return null;
|
|
817
|
-
const box = node.box ?? {
|
|
818
|
-
x: 0,
|
|
819
|
-
y: 0,
|
|
820
|
-
width: 1,
|
|
821
|
-
height: 1
|
|
822
|
-
};
|
|
823
|
-
const base = node.layout ?? {
|
|
824
|
-
...emptyCanvasNodeLayout(),
|
|
825
|
-
horizontal: {
|
|
826
|
-
mode: "fixed",
|
|
827
|
-
value: box.width
|
|
828
|
-
},
|
|
829
|
-
vertical: {
|
|
830
|
-
mode: "fixed",
|
|
831
|
-
value: box.height
|
|
832
|
-
}
|
|
833
|
-
};
|
|
834
|
-
const rotation = /rotate\(\s*(-?\d+(?:\.\d+)?)deg\s*\)/u.exec(String(styles["transform"] ?? ""))?.[1];
|
|
835
|
-
const overflow = `${String(styles["overflow"] ?? "")} ${String(styles["overflow-x"] ?? "")} ${String(styles["overflow-y"] ?? "")}`;
|
|
836
|
-
const container = nextContainer(base.container, styles);
|
|
837
|
-
const position = styles["position"];
|
|
838
|
-
return {
|
|
839
|
-
...base,
|
|
840
|
-
...itemPatch(base, styles),
|
|
841
|
-
rotation: rotation === void 0 ? base.rotation : Number(rotation),
|
|
842
|
-
position: position === "absolute" ? "absolute" : ["relative", "flow"].includes(String(position)) ? "flow" : base.position,
|
|
843
|
-
clipContent: /\b(?:clip|hidden)\b/u.test(overflow) || base.clipContent,
|
|
844
|
-
...container === void 0 ? { container: void 0 } : { container }
|
|
845
|
-
};
|
|
846
|
-
};
|
|
847
|
-
const canvasBoxOperation = (node, styles) => {
|
|
848
|
-
if (node.box === void 0) return null;
|
|
849
|
-
const x = canvasStyleNumeric(styles["left"]);
|
|
850
|
-
const y = canvasStyleNumeric(styles["top"]);
|
|
851
|
-
const width = canvasStyleNumeric(styles["width"]);
|
|
852
|
-
const height = canvasStyleNumeric(styles["height"]);
|
|
853
|
-
if (x === null && y === null && width === null && height === null) return null;
|
|
854
|
-
return {
|
|
855
|
-
op: "setBox",
|
|
856
|
-
nodeId: node.id,
|
|
857
|
-
box: {
|
|
858
|
-
x: x ?? node.box.x,
|
|
859
|
-
y: y ?? node.box.y,
|
|
860
|
-
width: Math.max(1, width ?? node.box.width),
|
|
861
|
-
height: Math.max(1, height ?? node.box.height)
|
|
862
|
-
}
|
|
863
|
-
};
|
|
864
|
-
};
|
|
865
|
-
|
|
866
650
|
//#endregion
|
|
867
651
|
//#region src/application/canvas-style-operations.use-case.ts
|
|
868
652
|
const ADDITIONAL_STYLE_ID_LENGTH = 200;
|
|
869
|
-
const
|
|
870
|
-
const camelToKebab = (property) => property.replace(/^Webkit/u, "-webkit-").replace(/^Moz/u, "-moz-").replaceAll(/([a-z\d])([A-Z])/gu, "$1-$2").toLowerCase();
|
|
871
|
-
const isSafeAdditionalValue = (value) => !/javascript|vbscript|data\s*:\s*text\/html|expression\s*\(|@import/iu.test(value);
|
|
653
|
+
const camelToKebab = (property) => property.startsWith("--") ? property : property.replace(/^Webkit/u, "-webkit-").replace(/^Moz/u, "-moz-").replaceAll(/([a-z\d])([A-Z])/gu, "$1-$2").toLowerCase();
|
|
872
654
|
const additionalOperation = (node, styles) => {
|
|
873
655
|
const held = new Map((node.additionalStyles?.declarations ?? []).map((declaration) => [declaration.property, declaration]));
|
|
874
|
-
let isTouched = false;
|
|
875
656
|
for (const [property, value] of Object.entries(styles)) {
|
|
876
|
-
if (canvasNodeStylePatchSchema.safeParse({ [property]: value }).success)
|
|
877
|
-
if (LAYOUT_PROPERTY.test(property)) continue;
|
|
878
|
-
isTouched = true;
|
|
879
|
-
if (value === null) {
|
|
657
|
+
if (value === null || canvasNodeStylePatchSchema.safeParse({ [property]: value }).success) {
|
|
880
658
|
held.delete(property);
|
|
881
659
|
continue;
|
|
882
660
|
}
|
|
883
|
-
const
|
|
884
|
-
if (!isSafeAdditionalValue(normalized)) throw new CliError("BAD_REQUEST", `Style ${property} contains executable CSS.`, "Remove imports, expressions, and executable URL schemes.");
|
|
885
|
-
held.set(property, {
|
|
661
|
+
const result = canvasAdditionalStyleSchema.safeParse({
|
|
886
662
|
id: held.get(property)?.id ?? `css-${property}`.slice(0, ADDITIONAL_STYLE_ID_LENGTH),
|
|
887
663
|
property,
|
|
888
|
-
value:
|
|
664
|
+
value: String(value),
|
|
889
665
|
enabled: true
|
|
890
666
|
});
|
|
667
|
+
if (!result.success) throw new CliError("BAD_REQUEST", `Style ${property} is not safe CSS.`, "Use a valid CSS property without imports, expressions, or executable URLs.");
|
|
668
|
+
held.set(property, result.data);
|
|
891
669
|
}
|
|
892
670
|
const declarations = [];
|
|
893
671
|
for (const declaration of held.values()) {
|
|
894
|
-
if (declarations.length
|
|
672
|
+
if (declarations.length === 128) throw new CliError("BAD_REQUEST", "Too many additional CSS declarations.", "Remove unused declarations before adding more; no styles were changed.");
|
|
895
673
|
declarations.push(declaration);
|
|
896
674
|
}
|
|
897
|
-
return
|
|
675
|
+
return JSON.stringify(declarations) === JSON.stringify(node.additionalStyles?.declarations ?? []) ? null : {
|
|
898
676
|
op: "setAdditionalStyles",
|
|
899
677
|
nodeId: node.id,
|
|
900
678
|
additionalStyles: { declarations }
|
|
901
|
-
}
|
|
902
|
-
};
|
|
903
|
-
const
|
|
904
|
-
const
|
|
905
|
-
const
|
|
906
|
-
const
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
const stylePatch = Object.fromEntries(Object.entries(styles).filter(([property, value]) => canvasNodeStylePatchSchema.safeParse({ [property]: value }).success));
|
|
910
|
-
if (Object.keys(stylePatch).length > 0) operations.push({
|
|
911
|
-
op: "setStyles",
|
|
912
|
-
nodeId: node.id,
|
|
913
|
-
styles: canvasNodeStylePatchSchema.parse(stylePatch)
|
|
679
|
+
};
|
|
680
|
+
};
|
|
681
|
+
const layoutOperation = (document, node, next, styles) => {
|
|
682
|
+
const changed = new Set(Object.keys(styles));
|
|
683
|
+
const properties = (axis) => [...canvasAxisStyleProperties(node, axis, document), ...canvasAxisStyleProperties(next, axis, document)];
|
|
684
|
+
const layout = canvasLayoutWithoutCssProperties(node.layout ?? {}, changed, {
|
|
685
|
+
horizontal: properties("horizontal"),
|
|
686
|
+
vertical: properties("vertical")
|
|
914
687
|
});
|
|
915
|
-
const
|
|
916
|
-
|
|
688
|
+
for (const [property, axis] of [["width", "horizontal"], ["height", "vertical"]]) {
|
|
689
|
+
const value = styles[property];
|
|
690
|
+
if (value === "fill" || value === "hug") layout[axis] = { mode: value };
|
|
691
|
+
}
|
|
692
|
+
return JSON.stringify(layout) === JSON.stringify(node.layout ?? {}) ? null : {
|
|
917
693
|
op: "setLayout",
|
|
918
694
|
nodeId: node.id,
|
|
919
|
-
layout
|
|
920
|
-
}
|
|
695
|
+
layout: Object.keys(layout).length === 0 ? "default" : layout
|
|
696
|
+
};
|
|
697
|
+
};
|
|
698
|
+
const cssValues = (document, node, styles) => {
|
|
699
|
+
const result = { ...styles };
|
|
700
|
+
for (const [property, axis] of [["width", "horizontal"], ["height", "vertical"]]) {
|
|
701
|
+
if (styles[property] !== "fill" && styles[property] !== "hug") continue;
|
|
702
|
+
result[property] = null;
|
|
703
|
+
for (const related of canvasAxisStyleProperties(node, axis, document)) if (node.styles[related] !== void 0 || node.additionalStyles?.declarations.some((declaration) => declaration.property === related) === true) result[related] = null;
|
|
704
|
+
}
|
|
705
|
+
return result;
|
|
706
|
+
};
|
|
707
|
+
const operationsForNode = (document, node, source) => {
|
|
708
|
+
const styles = cssValues(document, node, source);
|
|
921
709
|
const additional = additionalOperation(node, styles);
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
}
|
|
928
|
-
|
|
710
|
+
const stylePatch = Object.fromEntries(Object.entries(styles).filter(([property, value]) => canvasNodeStylePatchSchema.safeParse({ [property]: value }).success));
|
|
711
|
+
const next = {
|
|
712
|
+
...node,
|
|
713
|
+
styles: { ...node.styles },
|
|
714
|
+
...additional !== null && additional.additionalStyles !== "default" && { additionalStyles: additional.additionalStyles }
|
|
715
|
+
};
|
|
716
|
+
for (const [property, value] of Object.entries(stylePatch)) if (value === null) Reflect.deleteProperty(next.styles, property);
|
|
717
|
+
else next.styles[property] = value;
|
|
718
|
+
const layout = layoutOperation(document, node, next, source);
|
|
719
|
+
return [
|
|
720
|
+
...Object.keys(stylePatch).length > 0 ? [{
|
|
721
|
+
op: "setStyles",
|
|
722
|
+
nodeId: node.id,
|
|
723
|
+
styles: canvasNodeStylePatchSchema.parse(stylePatch)
|
|
724
|
+
}] : [],
|
|
725
|
+
...layout === null ? [] : [layout],
|
|
726
|
+
...additional === null ? [] : [additional]
|
|
727
|
+
];
|
|
929
728
|
};
|
|
930
|
-
const
|
|
931
|
-
const
|
|
932
|
-
|
|
933
|
-
|
|
729
|
+
const mergedUpdates = (updates) => {
|
|
730
|
+
const merged = /* @__PURE__ */ new Map();
|
|
731
|
+
for (const update of updates) for (const nodeId of update.nodeIds) {
|
|
732
|
+
const styles = merged.get(nodeId) ?? {};
|
|
733
|
+
for (const [property, value] of Object.entries(update.styles)) {
|
|
734
|
+
const normalized = camelToKebab(property);
|
|
735
|
+
Reflect.deleteProperty(styles, normalized);
|
|
736
|
+
styles[normalized] = value;
|
|
737
|
+
}
|
|
738
|
+
merged.set(nodeId, styles);
|
|
739
|
+
}
|
|
740
|
+
return merged;
|
|
934
741
|
};
|
|
935
|
-
const canvasStyleOperations = (
|
|
936
|
-
const operations = updates
|
|
742
|
+
const canvasStyleOperations = (document, updates) => {
|
|
743
|
+
const operations = [...mergedUpdates(updates)].flatMap(([nodeId, styles]) => {
|
|
744
|
+
const node = document.nodes[nodeId];
|
|
745
|
+
if (node === void 0) throw new CliError("NOT_FOUND", `Canvas node ${nodeId} does not exist.`, "Run canvas tree and use current stable node ids.");
|
|
746
|
+
return operationsForNode(document, node, styles);
|
|
747
|
+
});
|
|
937
748
|
if (operations.length === 0) throw new CliError("BAD_REQUEST", "No style changes were provided.", "Pass at least one changed CSS property.");
|
|
938
749
|
return operations;
|
|
939
750
|
};
|
|
@@ -1009,7 +820,7 @@ const configureStyles = (canvas, input) => {
|
|
|
1009
820
|
const canvasId = parseCanvasReference(options.canvas).canvasId;
|
|
1010
821
|
const scene = await sceneAtVersion(input, canvasId, authoringBaseVersion(options.baseVersion));
|
|
1011
822
|
const updates = createCanvasJsonInputAdapter(options.updates, styleUpdatesSchema, "--updates");
|
|
1012
|
-
input.output.result(await applyAuthoringOperations(input, options, "update-styles", canvasStyleOperations(scene
|
|
823
|
+
input.output.result(await applyAuthoringOperations(input, options, "update-styles", canvasStyleOperations(scene, updates)));
|
|
1013
824
|
});
|
|
1014
825
|
};
|
|
1015
826
|
const configureCanvasAuthoringEdits = (canvas, input) => {
|
|
@@ -1019,6 +830,168 @@ const configureCanvasAuthoringEdits = (canvas, input) => {
|
|
|
1019
830
|
configureStyles(canvas, input);
|
|
1020
831
|
};
|
|
1021
832
|
|
|
833
|
+
//#endregion
|
|
834
|
+
//#region src/application/canvas-style-layout.use-case.ts
|
|
835
|
+
const PERCENT$1 = 100;
|
|
836
|
+
const UNITLESS = /* @__PURE__ */ new Set([
|
|
837
|
+
"flex-grow",
|
|
838
|
+
"flex-shrink",
|
|
839
|
+
"order",
|
|
840
|
+
"aspect-ratio"
|
|
841
|
+
]);
|
|
842
|
+
const aligned = (value) => value === "start" || value === "end" ? `flex-${value}` : value;
|
|
843
|
+
const parentBound = (value) => {
|
|
844
|
+
const percentage = `${String(value.ratio * PERCENT$1)}%`;
|
|
845
|
+
const offset = value.offset ?? 0;
|
|
846
|
+
return offset === 0 ? percentage : `calc(${percentage} ${offset < 0 ? "-" : "+"} ${String(Math.abs(offset))}px)`;
|
|
847
|
+
};
|
|
848
|
+
const boundCss = (intent, kind) => {
|
|
849
|
+
const absolute = intent[kind];
|
|
850
|
+
const parent = intent[kind === "min" ? "minParent" : "maxParent"];
|
|
851
|
+
if (parent === void 0) return absolute;
|
|
852
|
+
const relative = parentBound(parent);
|
|
853
|
+
return absolute === void 0 ? relative : `${kind === "min" ? "max" : "min"}(${String(absolute)}px, ${relative})`;
|
|
854
|
+
};
|
|
855
|
+
const sizeCss = (property, intent, isImplicitFill) => {
|
|
856
|
+
if (intent === void 0) return {};
|
|
857
|
+
if (intent.mode === "fixed") return { [property]: intent.value };
|
|
858
|
+
const bounds = {};
|
|
859
|
+
for (const kind of ["min", "max"]) {
|
|
860
|
+
const value = boundCss(intent, kind);
|
|
861
|
+
if (value !== void 0) bounds[`${kind}-${property}`] = value;
|
|
862
|
+
}
|
|
863
|
+
if (intent.mode === "hug") return {
|
|
864
|
+
[property]: "max-content",
|
|
865
|
+
...bounds
|
|
866
|
+
};
|
|
867
|
+
const offset = intent.offset ?? 0;
|
|
868
|
+
const fill = offset === 0 ? "100%" : `calc(100% + ${String(offset)}px)`;
|
|
869
|
+
return {
|
|
870
|
+
[property]: isImplicitFill && offset === 0 ? "auto" : fill,
|
|
871
|
+
...bounds
|
|
872
|
+
};
|
|
873
|
+
};
|
|
874
|
+
const boxCss = (node, document) => {
|
|
875
|
+
const box = node.box;
|
|
876
|
+
if (box === void 0) return {};
|
|
877
|
+
const authored = canvasAuthoredStyleDeclarations(node);
|
|
878
|
+
const position = node.layout?.position ?? canvasAuthoredLayoutValueOf(node, "position");
|
|
879
|
+
const isPositioned = position === void 0 || ["absolute", "fixed"].includes(position);
|
|
880
|
+
const hasInset = (axis) => (axis === "horizontal" ? [
|
|
881
|
+
"left",
|
|
882
|
+
"right",
|
|
883
|
+
"inset",
|
|
884
|
+
"inset-inline",
|
|
885
|
+
"inset-inline-start",
|
|
886
|
+
"inset-inline-end"
|
|
887
|
+
] : [
|
|
888
|
+
"top",
|
|
889
|
+
"bottom",
|
|
890
|
+
"inset",
|
|
891
|
+
"inset-block",
|
|
892
|
+
"inset-block-start",
|
|
893
|
+
"inset-block-end"
|
|
894
|
+
]).some((property) => authored[property] !== void 0);
|
|
895
|
+
const hasSize = (axis) => canvasAxisStyleProperties(node, axis, document).some((property) => authored[property] !== void 0 || node.additionalStyles?.declarations.some((declaration) => declaration.property.toLowerCase() === property) === true);
|
|
896
|
+
return {
|
|
897
|
+
...authored["box-sizing"] === void 0 && { "box-sizing": "border-box" },
|
|
898
|
+
...isPositioned && authored["position"] === void 0 && { position: "absolute" },
|
|
899
|
+
...isPositioned && !hasInset("horizontal") && { left: box.x },
|
|
900
|
+
...isPositioned && !hasInset("vertical") && { top: box.y },
|
|
901
|
+
...isPositioned && node.layout?.horizontal === void 0 && !hasSize("horizontal") && { width: box.width },
|
|
902
|
+
...isPositioned && node.layout?.vertical === void 0 && !hasSize("vertical") && { height: box.height }
|
|
903
|
+
};
|
|
904
|
+
};
|
|
905
|
+
const gridColumnsCss = (container) => {
|
|
906
|
+
if (container.gridColumns !== void 0) return `repeat(${String(container.gridColumns)}, minmax(0, 1fr))`;
|
|
907
|
+
if (container.gridAutoRepeat === void 0) return void 0;
|
|
908
|
+
return `repeat(${container.gridAutoRepeat.mode}, minmax(${String(container.gridAutoRepeat.minimum)}px, 1fr))`;
|
|
909
|
+
};
|
|
910
|
+
const containerCss = (node) => {
|
|
911
|
+
const layout = node.layout;
|
|
912
|
+
const container = layout?.container;
|
|
913
|
+
const css = layout?.clipContent === void 0 ? {} : { overflow: layout.clipContent ? "hidden" : "visible" };
|
|
914
|
+
if (container === void 0) return css;
|
|
915
|
+
const columns = gridColumnsCss(container);
|
|
916
|
+
const rowGap = container.rowGap ?? container.gap;
|
|
917
|
+
const columnGap = container.columnGap ?? container.gap;
|
|
918
|
+
return {
|
|
919
|
+
...css,
|
|
920
|
+
...canvasAuthoredLayoutValueOf(node, "display") === void 0 && { display: columns === void 0 ? "flex" : "grid" },
|
|
921
|
+
...columns !== void 0 && { "grid-template-columns": columns },
|
|
922
|
+
...container.direction !== void 0 && { "flex-direction": container.direction },
|
|
923
|
+
...container.wrap !== void 0 && { "flex-wrap": container.wrap },
|
|
924
|
+
...container.alignItems !== void 0 && { "align-items": aligned(container.alignItems) },
|
|
925
|
+
...container.alignContent !== void 0 && { "align-content": aligned(container.alignContent) },
|
|
926
|
+
...container.justifyContent !== void 0 && { "justify-content": aligned(container.justifyContent) },
|
|
927
|
+
...rowGap !== void 0 && { "row-gap": rowGap },
|
|
928
|
+
...columnGap !== void 0 && { "column-gap": columnGap },
|
|
929
|
+
...Object.fromEntries(Object.entries(container.padding ?? {}).map(([side, value]) => [`padding-${side}`, value]))
|
|
930
|
+
};
|
|
931
|
+
};
|
|
932
|
+
const flowCss = (node, primary) => {
|
|
933
|
+
const layout = node.layout ?? {};
|
|
934
|
+
const hasOwnership = (property) => primary !== void 0 && canvasAuthoredLayoutValueOf(node, property) === void 0;
|
|
935
|
+
const basis = layout.flexBasis ?? (primary?.mode === "fill" ? 0 : "auto");
|
|
936
|
+
return {
|
|
937
|
+
...(hasOwnership("flex-basis") || layout.flexBasis !== void 0) && { "flex-basis": typeof basis === "object" ? parentBound(basis) : basis },
|
|
938
|
+
...(hasOwnership("flex-grow") || layout.flexGrow !== void 0) && { "flex-grow": layout.flexGrow ?? (primary?.mode === "fill" ? 1 : 0) },
|
|
939
|
+
...(hasOwnership("flex-shrink") || layout.flexShrink !== void 0) && { "flex-shrink": layout.flexShrink ?? (primary?.mode === "fill" ? 1 : 0) },
|
|
940
|
+
...layout.flowOffset !== void 0 && {
|
|
941
|
+
left: layout.flowOffset.x,
|
|
942
|
+
top: layout.flowOffset.y
|
|
943
|
+
},
|
|
944
|
+
...layout.order !== void 0 && { order: layout.order },
|
|
945
|
+
...Object.fromEntries(Object.entries(layout.margin ?? {}).map(([side, value]) => [`margin-${side}`, value]))
|
|
946
|
+
};
|
|
947
|
+
};
|
|
948
|
+
const transformCss = (layout) => {
|
|
949
|
+
const transforms = [
|
|
950
|
+
...layout.rotation === void 0 || layout.rotation === 0 ? [] : [`rotate(${String(layout.rotation)}deg)`],
|
|
951
|
+
...layout.flipHorizontal === true ? ["scaleX(-1)"] : [],
|
|
952
|
+
...layout.flipVertical === true ? ["scaleY(-1)"] : []
|
|
953
|
+
];
|
|
954
|
+
return transforms.length === 0 ? {} : { transform: transforms.join(" ") };
|
|
955
|
+
};
|
|
956
|
+
const childAlignment = (layout, cross) => layout.alignSelf === void 0 || layout.alignSelf === "auto" ? cross?.mode === "fill" ? "stretch" : void 0 : aligned(layout.alignSelf);
|
|
957
|
+
const fillMinimumCss = (node, main) => {
|
|
958
|
+
if (main === void 0) return {};
|
|
959
|
+
const primary = node.layout?.[main];
|
|
960
|
+
const property = main === "horizontal" ? "min-width" : "min-height";
|
|
961
|
+
if (primary?.mode !== "fill" || primary.min !== void 0 || primary.minParent !== void 0 || canvasAuthoredStyleDeclarations(node)[property] !== void 0) return {};
|
|
962
|
+
return { [property]: 0 };
|
|
963
|
+
};
|
|
964
|
+
const placementCss = (node, document) => {
|
|
965
|
+
const layout = node.layout;
|
|
966
|
+
if (layout === void 0) return {};
|
|
967
|
+
const parentId = document?.relationships[node.id]?.parentId;
|
|
968
|
+
const main = canvasLayoutMainAxisOf(parentId === void 0 ? void 0 : document?.nodes[parentId], document);
|
|
969
|
+
const position = layout.position ?? canvasAuthoredLayoutValueOf(node, "position");
|
|
970
|
+
const isFlow = position === "flow" || position !== "absolute" && position !== "fixed" && (position !== void 0 || node.box === void 0);
|
|
971
|
+
const primary = main === "horizontal" ? layout.horizontal : layout.vertical;
|
|
972
|
+
const cross = main === "horizontal" ? layout.vertical : layout.horizontal;
|
|
973
|
+
const alignment = childAlignment(layout, cross);
|
|
974
|
+
return {
|
|
975
|
+
...layout.position !== void 0 && { position: isFlow ? "relative" : "absolute" },
|
|
976
|
+
...sizeCss("width", layout.horizontal, isFlow && (main === "horizontal" || alignment === "stretch")),
|
|
977
|
+
...sizeCss("height", layout.vertical, isFlow && (main === "vertical" || alignment === "stretch")),
|
|
978
|
+
...isFlow && main !== void 0 && flowCss(node, primary),
|
|
979
|
+
...isFlow && alignment !== void 0 && { "align-self": alignment },
|
|
980
|
+
...isFlow && fillMinimumCss(node, main),
|
|
981
|
+
...alignment === "stretch" && cross?.mode === "hug" && main !== void 0 && { [main === "horizontal" ? "height" : "width"]: "auto" },
|
|
982
|
+
...layout.aspectRatio !== void 0 && { "aspect-ratio": layout.aspectRatio },
|
|
983
|
+
...transformCss(layout)
|
|
984
|
+
};
|
|
985
|
+
};
|
|
986
|
+
/** A structural CSS reading, never a measurement of the browser's used geometry. */
|
|
987
|
+
const canvasStyleLayoutCss = (node, document) => Object.fromEntries(Object.entries({
|
|
988
|
+
...boxCss(node, document),
|
|
989
|
+
...canvasLayoutPriorityDeclarations(node, {
|
|
990
|
+
...placementCss(node, document),
|
|
991
|
+
...containerCss(node)
|
|
992
|
+
})
|
|
993
|
+
}).map(([property, value]) => [property, typeof value === "number" && !UNITLESS.has(property) ? `${String(value)}px` : value]));
|
|
994
|
+
|
|
1022
995
|
//#endregion
|
|
1023
996
|
//#region src/application/canvas-css-projection.use-case.ts
|
|
1024
997
|
const RGB_CHANNEL_MAX = 255;
|
|
@@ -1112,80 +1085,17 @@ const typographyCss = (typography) => typography === void 0 ? {} : {
|
|
|
1112
1085
|
"text-decoration-style": typography.decoration.style,
|
|
1113
1086
|
"white-space": typography.wrapping
|
|
1114
1087
|
};
|
|
1115
|
-
const
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
...
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
},
|
|
1126
|
-
width: sizeCss(layout.horizontal, box.width),
|
|
1127
|
-
height: sizeCss(layout.vertical, box.height),
|
|
1128
|
-
...layout.clipContent === true && { overflow: "hidden" }
|
|
1088
|
+
const computedCanvasNodeCss = (node, document) => ({
|
|
1089
|
+
...Object.fromEntries(Object.entries(canvasAuthoredStyleDeclarations(node)).filter(([property]) => node.layout?.clipContent === void 0 || ![
|
|
1090
|
+
"overflow",
|
|
1091
|
+
"overflow-x",
|
|
1092
|
+
"overflow-y"
|
|
1093
|
+
].includes(property))),
|
|
1094
|
+
...typographyCss(node.typography),
|
|
1095
|
+
...appearanceCss(node.appearance),
|
|
1096
|
+
...canvasStyleLayoutCss(node, document),
|
|
1097
|
+
...node.visible === false && { display: "none" }
|
|
1129
1098
|
});
|
|
1130
|
-
const transformCss = (layout) => {
|
|
1131
|
-
const transforms = [
|
|
1132
|
-
...layout.rotation === 0 ? [] : [`rotate(${String(layout.rotation)}deg)`],
|
|
1133
|
-
...layout.flipHorizontal === true ? ["scaleX(-1)"] : [],
|
|
1134
|
-
...layout.flipVertical === true ? ["scaleY(-1)"] : []
|
|
1135
|
-
];
|
|
1136
|
-
return transforms.length === 0 ? {} : { transform: transforms.join(" ") };
|
|
1137
|
-
};
|
|
1138
|
-
const flexBasisCss = (basis) => {
|
|
1139
|
-
if (typeof basis !== "object") return basis === "auto" ? basis : `${String(basis)}px`;
|
|
1140
|
-
const percentage = `${String(basis.ratio * PERCENT)}%`;
|
|
1141
|
-
const offset = basis.offset ?? 0;
|
|
1142
|
-
return offset === 0 ? percentage : `calc(${percentage} ${offset < 0 ? "-" : "+"} ${String(Math.abs(offset))}px)`;
|
|
1143
|
-
};
|
|
1144
|
-
const flexItemCss = (layout) => ({
|
|
1145
|
-
...layout.alignSelf !== void 0 && { "align-self": aligned(layout.alignSelf === "auto" ? "start" : layout.alignSelf) },
|
|
1146
|
-
...layout.flexGrow !== void 0 && { "flex-grow": layout.flexGrow },
|
|
1147
|
-
...layout.flexShrink !== void 0 && { "flex-shrink": layout.flexShrink },
|
|
1148
|
-
...layout.flexBasis !== void 0 && { "flex-basis": flexBasisCss(layout.flexBasis) },
|
|
1149
|
-
...layout.order !== void 0 && { order: layout.order }
|
|
1150
|
-
});
|
|
1151
|
-
const flexContainerCss = (layout) => {
|
|
1152
|
-
const container = layout.container;
|
|
1153
|
-
if (container === void 0) return {};
|
|
1154
|
-
return {
|
|
1155
|
-
display: "flex",
|
|
1156
|
-
"flex-direction": container.direction,
|
|
1157
|
-
"align-items": aligned(container.alignItems),
|
|
1158
|
-
"align-content": aligned(container.alignContent ?? "start"),
|
|
1159
|
-
"justify-content": aligned(container.justifyContent),
|
|
1160
|
-
gap: `${String(container.gap)}px`,
|
|
1161
|
-
"row-gap": `${String(container.rowGap ?? container.gap)}px`,
|
|
1162
|
-
"column-gap": `${String(container.columnGap ?? container.gap)}px`,
|
|
1163
|
-
"flex-wrap": container.wrap ?? "nowrap",
|
|
1164
|
-
padding: [
|
|
1165
|
-
container.padding.top,
|
|
1166
|
-
container.padding.right,
|
|
1167
|
-
container.padding.bottom,
|
|
1168
|
-
container.padding.left
|
|
1169
|
-
].map((value) => `${String(value)}px`).join(" ")
|
|
1170
|
-
};
|
|
1171
|
-
};
|
|
1172
|
-
const computedCanvasNodeCss = (node) => {
|
|
1173
|
-
const additional = Object.fromEntries((node.additionalStyles?.declarations ?? []).filter((declaration) => declaration.enabled).map((declaration) => [declaration.property, declaration.value]));
|
|
1174
|
-
const layout = node.layout === void 0 || node.box === void 0 ? {} : {
|
|
1175
|
-
...placementCss(node.layout, node.box),
|
|
1176
|
-
...transformCss(node.layout),
|
|
1177
|
-
...flexItemCss(node.layout),
|
|
1178
|
-
...flexContainerCss(node.layout)
|
|
1179
|
-
};
|
|
1180
|
-
return {
|
|
1181
|
-
...node.styles,
|
|
1182
|
-
...additional,
|
|
1183
|
-
...typographyCss(node.typography),
|
|
1184
|
-
...appearanceCss(node.appearance),
|
|
1185
|
-
...layout,
|
|
1186
|
-
...node.visible === false && { display: "none" }
|
|
1187
|
-
};
|
|
1188
|
-
};
|
|
1189
1099
|
|
|
1190
1100
|
//#endregion
|
|
1191
1101
|
//#region src/application/canvas-source-projection.use-case.ts
|
|
@@ -1206,7 +1116,7 @@ const jsxFor = (document, nodeId, depth, maximumDepth) => {
|
|
|
1206
1116
|
const properties = [
|
|
1207
1117
|
`data-node-id=${JSON.stringify(node.id)}`,
|
|
1208
1118
|
`data-name=${JSON.stringify(node.label)}`,
|
|
1209
|
-
`style={${JSON.stringify(computedCanvasNodeCss(node))}}`
|
|
1119
|
+
`style={${JSON.stringify(computedCanvasNodeCss(node, document))}}`
|
|
1210
1120
|
];
|
|
1211
1121
|
if (node.locked === true) properties.push("data-locked=\"true\"");
|
|
1212
1122
|
if (node.component === "image") return `${indent}<img ${properties.join(" ")} alt=${JSON.stringify(stringProperty(node, "alt"))} src=${JSON.stringify(stringProperty(node, "src"))} />`;
|
|
@@ -1230,7 +1140,7 @@ const canvasComputedStyleRecords = (document, nodeIds) => nodeIds.map((nodeId) =
|
|
|
1230
1140
|
name: node.label,
|
|
1231
1141
|
component: node.component,
|
|
1232
1142
|
box: node.box,
|
|
1233
|
-
css: computedCanvasNodeCss(node),
|
|
1143
|
+
css: computedCanvasNodeCss(node, document),
|
|
1234
1144
|
layout: node.layout,
|
|
1235
1145
|
appearance: node.appearance,
|
|
1236
1146
|
typography: node.typography
|
|
@@ -1272,7 +1182,7 @@ const canvasScene = async (input, canvasId) => {
|
|
|
1272
1182
|
const held = getCanvasDocumentOutputSchema.parse(await input.remote.query("canvas.document.get", { canvasId }));
|
|
1273
1183
|
return {
|
|
1274
1184
|
held,
|
|
1275
|
-
document:
|
|
1185
|
+
document: canvasReadableSceneDocumentSchema.parse(held.document)
|
|
1276
1186
|
};
|
|
1277
1187
|
};
|
|
1278
1188
|
const configureCanvasAuthoringSource = (canvas, input) => {
|
|
@@ -1301,7 +1211,8 @@ const configureCanvasAuthoringSource = (canvas, input) => {
|
|
|
1301
1211
|
input.output.result({
|
|
1302
1212
|
canvasId,
|
|
1303
1213
|
version: held.version,
|
|
1304
|
-
nodes: canvasComputedStyleRecords(document, nodeIds)
|
|
1214
|
+
nodes: canvasComputedStyleRecords(document, nodeIds),
|
|
1215
|
+
warning: "These are authored CSS instructions, not measured browser dimensions. Use canvas render as the pixel authority."
|
|
1305
1216
|
});
|
|
1306
1217
|
});
|
|
1307
1218
|
};
|
|
@@ -1677,7 +1588,7 @@ const nodeIdFor = (command, reference) => {
|
|
|
1677
1588
|
};
|
|
1678
1589
|
const readLinkedSelection = async (command, input, reference, url) => {
|
|
1679
1590
|
const held = getCanvasDocumentOutputSchema.parse(await input.remote.query("canvas.document.get", { canvasId: reference.canvasId }));
|
|
1680
|
-
const document =
|
|
1591
|
+
const document = canvasReadableSceneDocumentSchema.parse(held.document);
|
|
1681
1592
|
const scope = canvasReferenceNodeIds(reference, document);
|
|
1682
1593
|
const nodes = Object.values(document.nodes).filter((node) => scope.has(node.id)).map((node) => ({
|
|
1683
1594
|
...node,
|
|
@@ -1775,7 +1686,7 @@ const selectedRenderNode = async (options, input) => {
|
|
|
1775
1686
|
const nodeId = options.nodeId ?? (reference.nodeIds.length === 1 ? reference.nodeIds[0] : void 0);
|
|
1776
1687
|
if (nodeId === void 0 || options.bounds !== void 0) throw new CliError("BAD_REQUEST", "A selection link requires one selected node to render.", "Pass --node-id for one node in the selection; bounds and whole-canvas renders would include unrelated content.");
|
|
1777
1688
|
const held = getCanvasDocumentOutputSchema.parse(await input.remote.query("canvas.document.get", { canvasId: reference.canvasId }));
|
|
1778
|
-
assertCanvasReferenceNodes(reference,
|
|
1689
|
+
assertCanvasReferenceNodes(reference, canvasReadableSceneDocumentSchema.parse(held.document), [nodeId]);
|
|
1779
1690
|
return nodeId;
|
|
1780
1691
|
};
|
|
1781
1692
|
const executeRender = async (options, input) => {
|
|
@@ -1840,7 +1751,7 @@ const COMMAND_SUMMARIES = {
|
|
|
1840
1751
|
"canvas.duplicate": "Copy a canvas into a shelf.",
|
|
1841
1752
|
"canvas.deletePermanently": "Permanently delete a binned canvas.",
|
|
1842
1753
|
"canvas.restore": "Restore a binned canvas.",
|
|
1843
|
-
"canvas.inspect": "
|
|
1754
|
+
"canvas.inspect": "Read the canvas browser URL, structure summary, and inspection commands.",
|
|
1844
1755
|
"canvas.tree": "List canvas node ids, hierarchy, kinds, and boxes.",
|
|
1845
1756
|
"canvas.node": "Read one canvas node and its children.",
|
|
1846
1757
|
"canvas.selection": "Read the person’s current live browser selection.",
|
|
@@ -2616,7 +2527,7 @@ const main = async () => {
|
|
|
2616
2527
|
const credentials = createFileCredentialAdapter(CLI_CONFIG.configDirectory);
|
|
2617
2528
|
const mutationKey = createMutationKeyAdapter();
|
|
2618
2529
|
const cli = createCliProgram({
|
|
2619
|
-
version: "0.1.
|
|
2530
|
+
version: "0.1.14",
|
|
2620
2531
|
credentials,
|
|
2621
2532
|
remote: createHttpRemoteAdapter(CLI_CONFIG.apiUrl, credentials, mutationKey),
|
|
2622
2533
|
mutationKey,
|