diagram-contracts 0.1.3 → 0.1.5
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.mjs +2368 -2257
- package/dist/diagram-contracts.browser.mjs +379 -214
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +2360 -2249
- package/package.json +2 -2
package/dist/cli.mjs
CHANGED
|
@@ -740,1034 +740,560 @@ var ELEMENT_CATALOG = {
|
|
|
740
740
|
|
|
741
741
|
// src/ir/index.ts
|
|
742
742
|
import { z } from "zod";
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
);
|
|
751
|
-
function buildValidPropsSet(kind) {
|
|
752
|
-
const element = ELEMENT_CATALOG[kind];
|
|
753
|
-
if (!element) return /* @__PURE__ */ new Set();
|
|
754
|
-
const props = new Set(element.properties);
|
|
755
|
-
if (element.children.kind === "text") {
|
|
756
|
-
props.add("text");
|
|
757
|
-
}
|
|
758
|
-
return props;
|
|
759
|
-
}
|
|
760
|
-
function validateNode(node, path) {
|
|
761
|
-
if (!(node.kind in ELEMENT_CATALOG)) {
|
|
762
|
-
throw new Error(`Invalid element kind '${node.kind}' at ${path}`);
|
|
763
|
-
}
|
|
764
|
-
const validProps = buildValidPropsSet(node.kind);
|
|
765
|
-
const unknownProps = Object.keys(node.props).filter((k) => !validProps.has(k));
|
|
766
|
-
if (unknownProps.length > 0) {
|
|
767
|
-
throw new Error(
|
|
768
|
-
`Unknown properties for '${node.kind}' at ${path}: ${unknownProps.join(", ")}`
|
|
769
|
-
);
|
|
770
|
-
}
|
|
771
|
-
if (node.children) {
|
|
772
|
-
for (let i = 0; i < node.children.length; i++) {
|
|
773
|
-
validateNode(node.children[i], `${path}.children[${i}]`);
|
|
774
|
-
}
|
|
775
|
-
}
|
|
743
|
+
|
|
744
|
+
// src/graph/rule-engine.ts
|
|
745
|
+
import { load } from "js-yaml";
|
|
746
|
+
|
|
747
|
+
// src/graph/graph-helpers.ts
|
|
748
|
+
function num(v) {
|
|
749
|
+
return v ?? 0;
|
|
776
750
|
}
|
|
777
|
-
function
|
|
778
|
-
|
|
779
|
-
validateNode(parsed, "root");
|
|
780
|
-
return parsed;
|
|
751
|
+
function childrenOf(node) {
|
|
752
|
+
return node.children ?? [];
|
|
781
753
|
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
var SHAPE_PATTERNS = [
|
|
785
|
-
{ shape: "capsule", open: "([", close: "])" },
|
|
786
|
-
{ shape: "cylinder", open: "[(", close: ")]" },
|
|
787
|
-
{ shape: "circle", open: "((", close: "))" },
|
|
788
|
-
{ shape: "hexagon", open: "[[", close: "]]" },
|
|
789
|
-
{ shape: "roundedRect", open: "[", close: "]" },
|
|
790
|
-
{ shape: "diamond", open: "{", close: "}" },
|
|
791
|
-
{ shape: "rect", open: "(", close: ")" }
|
|
792
|
-
];
|
|
793
|
-
var SHAPE_ALIASES = {
|
|
794
|
-
stadium: "capsule",
|
|
795
|
-
pill: "capsule",
|
|
796
|
-
rounded: "roundedRect",
|
|
797
|
-
db: "cylinder",
|
|
798
|
-
database: "cylinder",
|
|
799
|
-
cyl: "cylinder",
|
|
800
|
-
decision: "diamond",
|
|
801
|
-
hex: "hexagon",
|
|
802
|
-
tri: "triangle"
|
|
803
|
-
};
|
|
804
|
-
function parseNodeShape(rest) {
|
|
805
|
-
let shapeOverride;
|
|
806
|
-
let cursor = 0;
|
|
807
|
-
if (rest.startsWith("@")) {
|
|
808
|
-
const atMatch = rest.match(/^@(\w+)/);
|
|
809
|
-
if (!atMatch) return null;
|
|
810
|
-
shapeOverride = SHAPE_ALIASES[atMatch[1]] ?? atMatch[1];
|
|
811
|
-
cursor = atMatch[0].length;
|
|
812
|
-
}
|
|
813
|
-
const remaining = rest.slice(cursor);
|
|
814
|
-
for (const { shape, open, close } of SHAPE_PATTERNS) {
|
|
815
|
-
if (!remaining.startsWith(open)) continue;
|
|
816
|
-
const contentStart = open.length;
|
|
817
|
-
const closeIdx = remaining.indexOf(close, contentStart);
|
|
818
|
-
if (closeIdx === -1) continue;
|
|
819
|
-
const afterClose = remaining.slice(closeIdx + close.length);
|
|
820
|
-
if (afterClose.length > 0 && /^[a-zA-Z0-9_-]/.test(afterClose)) continue;
|
|
821
|
-
let label = remaining.slice(contentStart, closeIdx);
|
|
822
|
-
if (label.startsWith('"') && label.endsWith('"')) {
|
|
823
|
-
label = label.slice(1, -1);
|
|
824
|
-
}
|
|
825
|
-
return {
|
|
826
|
-
label,
|
|
827
|
-
shape: shapeOverride ?? shape,
|
|
828
|
-
shapeOverride,
|
|
829
|
-
consumed: cursor + closeIdx + close.length
|
|
830
|
-
};
|
|
831
|
-
}
|
|
832
|
-
return null;
|
|
754
|
+
function slotId(nodeId, kind) {
|
|
755
|
+
return `${nodeId}.${kind}`;
|
|
833
756
|
}
|
|
834
|
-
function
|
|
835
|
-
const
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
if (pipeEnd !== -1) {
|
|
843
|
-
label = after.slice(1, pipeEnd).trim();
|
|
844
|
-
after = after.slice(pipeEnd + 1);
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
return { op, label, rest: after };
|
|
757
|
+
function ensureSlot(graph, nodeId, kind, value) {
|
|
758
|
+
const id = slotId(nodeId, kind);
|
|
759
|
+
let slot = graph.slots.get(id);
|
|
760
|
+
if (!slot) {
|
|
761
|
+
slot = { id, value, nodeId, slotKind: kind };
|
|
762
|
+
graph.slots.set(id, slot);
|
|
763
|
+
} else if (value !== void 0 && slot.value === void 0) {
|
|
764
|
+
slot.value = value;
|
|
848
765
|
}
|
|
849
|
-
return
|
|
766
|
+
return slot;
|
|
850
767
|
}
|
|
851
|
-
function
|
|
852
|
-
const
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
let def;
|
|
859
|
-
if (shapeParsed) {
|
|
860
|
-
after = after.slice(shapeParsed.consumed);
|
|
861
|
-
def = { label: shapeParsed.label, shape: shapeParsed.shape, shapeOverride: shapeParsed.shapeOverride };
|
|
768
|
+
function addCandidate(graph, targetSlotId, value, source, priority, operationId) {
|
|
769
|
+
const candidate = { targetSlotId, value, source, priority, operationId };
|
|
770
|
+
graph.candidates.push(candidate);
|
|
771
|
+
let bySlot = graph.candidatesBySlot.get(targetSlotId);
|
|
772
|
+
if (!bySlot) {
|
|
773
|
+
bySlot = [];
|
|
774
|
+
graph.candidatesBySlot.set(targetSlotId, bySlot);
|
|
862
775
|
}
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
def = { label: nodeId, shape: "roundedRect", variant: classMatch[1] };
|
|
870
|
-
}
|
|
871
|
-
after = after.slice(3 + classMatch[0].length);
|
|
776
|
+
bySlot.push(candidate);
|
|
777
|
+
if (operationId) {
|
|
778
|
+
let byOp = graph.candidatesByOperation.get(operationId);
|
|
779
|
+
if (!byOp) {
|
|
780
|
+
byOp = [];
|
|
781
|
+
graph.candidatesByOperation.set(operationId, byOp);
|
|
872
782
|
}
|
|
783
|
+
byOp.push(candidate);
|
|
873
784
|
}
|
|
874
|
-
return
|
|
785
|
+
return candidate;
|
|
875
786
|
}
|
|
876
|
-
function
|
|
877
|
-
const
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
}
|
|
882
|
-
const dirMatch = trimmed.match(/^(?:flowchart|graph)\s+(TD|TB|LR)$/i);
|
|
883
|
-
if (dirMatch) {
|
|
884
|
-
const dirRaw = dirMatch[1].toUpperCase();
|
|
885
|
-
const dir = dirRaw === "TB" ? "TD" : dirRaw;
|
|
886
|
-
if (dir !== "TD" && dir !== "LR") {
|
|
887
|
-
return null;
|
|
888
|
-
}
|
|
889
|
-
return { type: "direction", raw: line, line: lineNum, dir };
|
|
787
|
+
function addOperation(graph, id, op, inputs, outputs, compute) {
|
|
788
|
+
const operation = { id, op, inputs, outputs, compute };
|
|
789
|
+
graph.operations.set(id, operation);
|
|
790
|
+
for (const inputSlotId of inputs) {
|
|
791
|
+
graph.dependencies.push({ fromSlotId: inputSlotId, toOperationId: id });
|
|
890
792
|
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
line: lineNum,
|
|
897
|
-
subgraphId: subMatch[1],
|
|
898
|
-
label: subMatch[2] ?? void 0
|
|
899
|
-
};
|
|
793
|
+
return operation;
|
|
794
|
+
}
|
|
795
|
+
function addResolver(graph, targetSlotId, policy) {
|
|
796
|
+
if (!graph.resolvers.has(targetSlotId)) {
|
|
797
|
+
graph.resolvers.set(targetSlotId, { slotId: targetSlotId, policy });
|
|
900
798
|
}
|
|
901
|
-
|
|
902
|
-
|
|
799
|
+
}
|
|
800
|
+
function getNumericProp(node, prop, fallback) {
|
|
801
|
+
const val = node.props[prop];
|
|
802
|
+
if (typeof val === "number") return val;
|
|
803
|
+
if (typeof val === "string") {
|
|
804
|
+
const n = parseFloat(val);
|
|
805
|
+
if (!isNaN(n)) return n;
|
|
903
806
|
}
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
807
|
+
return fallback;
|
|
808
|
+
}
|
|
809
|
+
function getStringProp(node, prop, defaultValue) {
|
|
810
|
+
const val = node.props[prop];
|
|
811
|
+
return typeof val === "string" ? val : defaultValue;
|
|
812
|
+
}
|
|
813
|
+
function getSizeProp(node, prop) {
|
|
814
|
+
const val = node.props[prop];
|
|
815
|
+
if (typeof val === "number") return val;
|
|
816
|
+
if (val === "wrap") return "wrap";
|
|
817
|
+
if (val === "fill") return "fill";
|
|
818
|
+
if (typeof val === "string") {
|
|
819
|
+
const n = parseFloat(val);
|
|
820
|
+
if (!isNaN(n)) return n;
|
|
909
821
|
}
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
822
|
+
return "wrap";
|
|
823
|
+
}
|
|
824
|
+
function isConstraintKind(kind) {
|
|
825
|
+
return kind === "alignConstraint" || kind === "equalizeWidth" || kind === "equalizeHeight" || kind === "minGap" || kind === "keepInsideConstraint" || kind === "orderConstraint";
|
|
826
|
+
}
|
|
827
|
+
function registerSizeSlots(node, graph, parentId) {
|
|
828
|
+
const id = node.id;
|
|
829
|
+
const widthIntent = getSizeProp(node, "width");
|
|
830
|
+
const heightIntent = getSizeProp(node, "height");
|
|
831
|
+
ensureSlot(graph, id, "resolvedWidth");
|
|
832
|
+
ensureSlot(graph, id, "resolvedHeight");
|
|
833
|
+
ensureSlot(graph, id, "localX");
|
|
834
|
+
ensureSlot(graph, id, "localY");
|
|
835
|
+
if (typeof widthIntent === "number") {
|
|
836
|
+
ensureSlot(graph, id, "contentWidth", widthIntent);
|
|
837
|
+
addCandidate(graph, slotId(id, "contentWidth"), widthIntent, `${node.kind}(${id}).explicit`, "required");
|
|
838
|
+
addCandidate(graph, slotId(id, "resolvedWidth"), widthIntent, `${node.kind}(${id}).explicit`, "normal");
|
|
839
|
+
} else if (widthIntent === "fill" && parentId) {
|
|
840
|
+
ensureSlot(graph, parentId, "availableWidth");
|
|
919
841
|
}
|
|
920
|
-
if (
|
|
921
|
-
|
|
842
|
+
if (typeof heightIntent === "number") {
|
|
843
|
+
ensureSlot(graph, id, "contentHeight", heightIntent);
|
|
844
|
+
addCandidate(graph, slotId(id, "contentHeight"), heightIntent, `${node.kind}(${id}).explicit`, "required");
|
|
845
|
+
addCandidate(graph, slotId(id, "resolvedHeight"), heightIntent, `${node.kind}(${id}).explicit`, "normal");
|
|
846
|
+
} else if (heightIntent === "fill" && parentId) {
|
|
847
|
+
ensureSlot(graph, parentId, "availableHeight");
|
|
922
848
|
}
|
|
923
|
-
return parseEdgeOrNodeLine(trimmed, line, lineNum);
|
|
924
849
|
}
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
850
|
+
|
|
851
|
+
// src/graph/east-asian-width.ts
|
|
852
|
+
var WIDE_RANGES = [
|
|
853
|
+
[4352, 4447],
|
|
854
|
+
// Hangul Jamo (leading consonants)
|
|
855
|
+
[8986, 8987],
|
|
856
|
+
// ⌚ ⌛ watch, hourglass
|
|
857
|
+
[9001, 9002],
|
|
858
|
+
// 〈 〉 angle brackets (EAW Wide)
|
|
859
|
+
[9193, 9196],
|
|
860
|
+
// ⏩–⏬ media controls
|
|
861
|
+
[9200, 9200],
|
|
862
|
+
// ⏰ alarm clock
|
|
863
|
+
[9203, 9203],
|
|
864
|
+
// ⏳ hourglass with sand
|
|
865
|
+
[9725, 9726],
|
|
866
|
+
// ◽ ◾ medium small squares
|
|
867
|
+
[9748, 9749],
|
|
868
|
+
// ☔ ☕ umbrella, hot beverage
|
|
869
|
+
[9800, 9811],
|
|
870
|
+
// ♈–♓ zodiac signs
|
|
871
|
+
[9855, 9855],
|
|
872
|
+
// ♿ wheelchair symbol
|
|
873
|
+
[9875, 9875],
|
|
874
|
+
// ⚓ anchor
|
|
875
|
+
[9889, 9889],
|
|
876
|
+
// ⚡ high voltage
|
|
877
|
+
[9898, 9899],
|
|
878
|
+
// ⚪ ⚫ circles
|
|
879
|
+
[9917, 9918],
|
|
880
|
+
// ⚽ ⚾ soccer, baseball
|
|
881
|
+
[9924, 9925],
|
|
882
|
+
// ⛄ ⛅ snowman, sun behind cloud
|
|
883
|
+
[9934, 9934],
|
|
884
|
+
// ⛎ Ophiuchus
|
|
885
|
+
[9940, 9940],
|
|
886
|
+
// ⛔ no entry
|
|
887
|
+
[9962, 9962],
|
|
888
|
+
// ⛪ church
|
|
889
|
+
[9970, 9971],
|
|
890
|
+
// ⛲ ⛳ fountain, flag in hole
|
|
891
|
+
[9973, 9973],
|
|
892
|
+
// ⛵ sailboat
|
|
893
|
+
[9978, 9978],
|
|
894
|
+
// ⛺ tent
|
|
895
|
+
[9981, 9981],
|
|
896
|
+
// ⛽ fuel pump
|
|
897
|
+
[9989, 9989],
|
|
898
|
+
// ✅ check mark button
|
|
899
|
+
[9994, 9995],
|
|
900
|
+
// ✊ ✋ fists
|
|
901
|
+
[10024, 10024],
|
|
902
|
+
// ✨ sparkles
|
|
903
|
+
[10060, 10060],
|
|
904
|
+
// ❌ cross mark
|
|
905
|
+
[10062, 10062],
|
|
906
|
+
// ❎ cross mark button
|
|
907
|
+
[10067, 10069],
|
|
908
|
+
// ❓❔❕ question/exclamation marks
|
|
909
|
+
[10071, 10071],
|
|
910
|
+
// ❗ exclamation mark
|
|
911
|
+
[10133, 10135],
|
|
912
|
+
// ➕➖➗ math signs
|
|
913
|
+
[10160, 10160],
|
|
914
|
+
// ➰ curly loop
|
|
915
|
+
[10175, 10175],
|
|
916
|
+
// ➿ double curly loop
|
|
917
|
+
[11035, 11036],
|
|
918
|
+
// ⬛ ⬜ large squares
|
|
919
|
+
[11088, 11088],
|
|
920
|
+
// ⭐ star
|
|
921
|
+
[11093, 11093],
|
|
922
|
+
// ⭕ heavy large circle
|
|
923
|
+
[11904, 12350],
|
|
924
|
+
// CJK Radicals, Kangxi Radicals, CJK Symbols & Punctuation (incl. U+3000 ideographic space)
|
|
925
|
+
[12353, 13311],
|
|
926
|
+
// Hiragana, Katakana, Bopomofo, Hangul Compat Jamo, Kanbun, CJK Compatibility
|
|
927
|
+
[13312, 19903],
|
|
928
|
+
// CJK Unified Ideographs Extension A
|
|
929
|
+
[19968, 40959],
|
|
930
|
+
// CJK Unified Ideographs
|
|
931
|
+
[40960, 42191],
|
|
932
|
+
// Yi Syllables, Yi Radicals
|
|
933
|
+
[43360, 43391],
|
|
934
|
+
// Hangul Jamo Extended-A
|
|
935
|
+
[44032, 55203],
|
|
936
|
+
// Hangul Syllables
|
|
937
|
+
[63744, 64255],
|
|
938
|
+
// CJK Compatibility Ideographs
|
|
939
|
+
[65040, 65049],
|
|
940
|
+
// Vertical Forms
|
|
941
|
+
[65072, 65106],
|
|
942
|
+
// CJK Compatibility Forms
|
|
943
|
+
[65108, 65126],
|
|
944
|
+
// Small Form Variants
|
|
945
|
+
[65128, 65131],
|
|
946
|
+
// Small Form Variants (fullwidth-ish signs)
|
|
947
|
+
[65281, 65376],
|
|
948
|
+
// Fullwidth Forms (! … ⦆)
|
|
949
|
+
[65504, 65510],
|
|
950
|
+
// Fullwidth signs (¢ £ ¬  ̄ ¦ ¥ ₩)
|
|
951
|
+
[94176, 101759],
|
|
952
|
+
// Tangut, Khitan Small Script, Tangut Supplement (EAW Wide)
|
|
953
|
+
[110576, 111355],
|
|
954
|
+
// Kana Extended-B, Kana Supplement, Kana Extended-A, Small Kana Extension, Nushu
|
|
955
|
+
[126980, 126980],
|
|
956
|
+
// 🀄 mahjong red dragon
|
|
957
|
+
[127183, 127183],
|
|
958
|
+
// 🃏 playing card joker
|
|
959
|
+
[127374, 127374],
|
|
960
|
+
// 🆎 AB blood type button
|
|
961
|
+
[127377, 127386],
|
|
962
|
+
// 🆑–🆚 squared Latin abbreviations
|
|
963
|
+
[127488, 127589],
|
|
964
|
+
// Enclosed Ideographic Supplement (🈁 🈯 squared kana/CJK)
|
|
965
|
+
[127744, 128591],
|
|
966
|
+
// Misc Symbols & Pictographs, Emoticons (emoji, EAW Wide)
|
|
967
|
+
[128640, 128767],
|
|
968
|
+
// Transport and Map Symbols (🚀 …)
|
|
969
|
+
[128992, 129008],
|
|
970
|
+
// Geometric Shapes Extended (colored circles/squares)
|
|
971
|
+
[129280, 129535],
|
|
972
|
+
// Supplemental Symbols & Pictographs (emoji, EAW Wide)
|
|
973
|
+
[129648, 129791],
|
|
974
|
+
// Symbols & Pictographs Extended-A (🩰 🪐 …)
|
|
975
|
+
[131072, 196605],
|
|
976
|
+
// CJK Unified Ideographs Extensions B–F
|
|
977
|
+
[196608, 262141]
|
|
978
|
+
// CJK Unified Ideographs Extension G+
|
|
979
|
+
];
|
|
980
|
+
function isEastAsianWide(codePoint) {
|
|
981
|
+
let lo = 0;
|
|
982
|
+
let hi = WIDE_RANGES.length - 1;
|
|
983
|
+
while (lo <= hi) {
|
|
984
|
+
const mid = lo + hi >> 1;
|
|
985
|
+
const [start, end] = WIDE_RANGES[mid];
|
|
986
|
+
if (codePoint < start) {
|
|
987
|
+
hi = mid - 1;
|
|
988
|
+
} else if (codePoint > end) {
|
|
989
|
+
lo = mid + 1;
|
|
990
|
+
} else {
|
|
991
|
+
return true;
|
|
992
|
+
}
|
|
965
993
|
}
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
};
|
|
994
|
+
return false;
|
|
995
|
+
}
|
|
996
|
+
function approxCharEm(codePoint) {
|
|
997
|
+
return isEastAsianWide(codePoint) ? 1 : 0.6;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
// src/graph/ops.ts
|
|
1001
|
+
function approxTextWidth(text, fontSize) {
|
|
1002
|
+
let width = 0;
|
|
1003
|
+
for (const ch of text) {
|
|
1004
|
+
width += approxCharEm(ch.codePointAt(0)) * fontSize;
|
|
978
1005
|
}
|
|
979
|
-
return
|
|
1006
|
+
return width;
|
|
980
1007
|
}
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1008
|
+
var SIMPLE_FONT_METRICS = {
|
|
1009
|
+
CAP_HEIGHT: 0.7,
|
|
1010
|
+
ASCENT: 0.9,
|
|
1011
|
+
DESCENT: 0.25,
|
|
1012
|
+
LINE_HEIGHT: 1.4
|
|
1013
|
+
};
|
|
1014
|
+
var SimpleTextMeasurer = class {
|
|
1015
|
+
measure(text, fontSize, maxWidth) {
|
|
1016
|
+
const lineHeight = SIMPLE_FONT_METRICS.LINE_HEIGHT * fontSize;
|
|
1017
|
+
if (!text) {
|
|
1018
|
+
return { width: 0, height: lineHeight, lines: [""] };
|
|
990
1019
|
}
|
|
1020
|
+
const measureFn = (t) => approxTextWidth(t, fontSize);
|
|
1021
|
+
const lines = wrapLines(text, maxWidth, measureFn);
|
|
1022
|
+
const width = Math.max(...lines.map(measureFn));
|
|
1023
|
+
const height = lines.length * lineHeight;
|
|
1024
|
+
return { width, height, lines };
|
|
1025
|
+
}
|
|
1026
|
+
metrics(fontSize) {
|
|
991
1027
|
return {
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
label: firstRef.def.label,
|
|
997
|
-
shape: firstRef.def.shape,
|
|
998
|
-
variant: firstRef.def.variant,
|
|
999
|
-
shapeOverride: firstRef.def.shapeOverride
|
|
1028
|
+
ascent: SIMPLE_FONT_METRICS.ASCENT * fontSize,
|
|
1029
|
+
descent: SIMPLE_FONT_METRICS.DESCENT * fontSize,
|
|
1030
|
+
capHeight: SIMPLE_FONT_METRICS.CAP_HEIGHT * fontSize,
|
|
1031
|
+
lineHeight: SIMPLE_FONT_METRICS.LINE_HEIGHT * fontSize
|
|
1000
1032
|
};
|
|
1001
1033
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1034
|
+
};
|
|
1035
|
+
var BROWSER_COMPENSATION = 1.1;
|
|
1036
|
+
function measureGlyphWidth(font, text, fontSize) {
|
|
1037
|
+
const scale = fontSize / font.unitsPerEm;
|
|
1038
|
+
let width = 0;
|
|
1039
|
+
for (const ch of text) {
|
|
1040
|
+
const glyph = font.charToGlyph(ch);
|
|
1041
|
+
const missing = glyph.index === 0 || glyph.advanceWidth == null;
|
|
1042
|
+
if (missing) {
|
|
1043
|
+
width += approxCharEm(ch.codePointAt(0)) * fontSize;
|
|
1044
|
+
} else {
|
|
1045
|
+
width += glyph.advanceWidth * scale;
|
|
1046
|
+
}
|
|
1004
1047
|
}
|
|
1005
|
-
return
|
|
1048
|
+
return width * BROWSER_COMPENSATION;
|
|
1006
1049
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
remaining = edgeMatch.rest;
|
|
1015
|
-
const nextRef = parseNodeRef(remaining);
|
|
1016
|
-
if (!nextRef) break;
|
|
1017
|
-
segments.push({ fromId: currentId, toId: nextRef.nodeId });
|
|
1018
|
-
currentId = nextRef.nodeId;
|
|
1019
|
-
remaining = nextRef.rest;
|
|
1050
|
+
var OpenTypeTextMeasurer = class _OpenTypeTextMeasurer {
|
|
1051
|
+
fonts = /* @__PURE__ */ new Map();
|
|
1052
|
+
// Line-box factor shared with the SimpleTextMeasurer SSoT so a single-line
|
|
1053
|
+
// text box's measured height matches the line box regardless of measurer.
|
|
1054
|
+
lineHeightFactor = SIMPLE_FONT_METRICS.LINE_HEIGHT;
|
|
1055
|
+
addFont(key, font) {
|
|
1056
|
+
this.fonts.set(key, font);
|
|
1020
1057
|
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
colonLabel = colonMatch[1].trim();
|
|
1039
|
-
remaining = "";
|
|
1058
|
+
/** Canonical CSS font-weight key for "normal" — the default when none given. */
|
|
1059
|
+
static DEFAULT_WEIGHT = "400";
|
|
1060
|
+
static WEIGHT_ALIASES = {
|
|
1061
|
+
normal: "400",
|
|
1062
|
+
bold: "700",
|
|
1063
|
+
lighter: "300",
|
|
1064
|
+
bolder: "700"
|
|
1065
|
+
};
|
|
1066
|
+
getFont(fontWeight) {
|
|
1067
|
+
const raw = fontWeight != null ? String(fontWeight) : _OpenTypeTextMeasurer.DEFAULT_WEIGHT;
|
|
1068
|
+
const w = _OpenTypeTextMeasurer.WEIGHT_ALIASES[raw] ?? raw;
|
|
1069
|
+
return this.fonts.get(w) ?? this.fonts.get(_OpenTypeTextMeasurer.DEFAULT_WEIGHT) ?? this.fonts.values().next().value;
|
|
1070
|
+
}
|
|
1071
|
+
measure(text, fontSize, maxWidth, fontWeight) {
|
|
1072
|
+
const lineHeight = this.lineHeightFactor * fontSize;
|
|
1073
|
+
if (!text) {
|
|
1074
|
+
return { width: 0, height: lineHeight, lines: [""] };
|
|
1040
1075
|
}
|
|
1041
|
-
const
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
edgeType: edgeMatch.op,
|
|
1045
|
-
edgeLabel: edgeMatch.label ?? colonLabel
|
|
1046
|
-
};
|
|
1047
|
-
if (currentDef) {
|
|
1048
|
-
seg.fromDef = currentDef;
|
|
1076
|
+
const font = this.getFont(fontWeight);
|
|
1077
|
+
if (!font) {
|
|
1078
|
+
return new SimpleTextMeasurer().measure(text, fontSize, maxWidth);
|
|
1049
1079
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1080
|
+
const measureFn = (t) => measureGlyphWidth(font, t, fontSize);
|
|
1081
|
+
const lines = wrapLines(text, maxWidth, measureFn);
|
|
1082
|
+
const width = Math.max(...lines.map(measureFn));
|
|
1083
|
+
const height = lines.length * lineHeight;
|
|
1084
|
+
return { width, height, lines };
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Real vertical metrics for the weight's font, in px at `fontSize`.
|
|
1088
|
+
*
|
|
1089
|
+
* capHeight comes from the OS/2 `sCapHeight` field when present; otherwise it
|
|
1090
|
+
* is measured from the "H" glyph's bounding box (top-of-cap in font units).
|
|
1091
|
+
* If neither is available the loaded font is degenerate, so we defer to the
|
|
1092
|
+
* documented {@link SIMPLE_FONT_METRICS} ratio rather than inventing a value.
|
|
1093
|
+
* ascent/descent use the OS/2 typographic values, falling back to the
|
|
1094
|
+
* hhea ascender/descender, then to the Simple ratios.
|
|
1095
|
+
*/
|
|
1096
|
+
metrics(fontSize, fontWeight) {
|
|
1097
|
+
const font = this.getFont(fontWeight);
|
|
1098
|
+
if (!font) {
|
|
1099
|
+
return new SimpleTextMeasurer().metrics(fontSize);
|
|
1052
1100
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1101
|
+
const scale = fontSize / font.unitsPerEm;
|
|
1102
|
+
const simple = new SimpleTextMeasurer().metrics(fontSize);
|
|
1103
|
+
const capUnits = capHeightFontUnits(font);
|
|
1104
|
+
const ascentUnits = ascentFontUnits(font);
|
|
1105
|
+
const descentUnits = descentFontUnits(font);
|
|
1106
|
+
return {
|
|
1107
|
+
capHeight: capUnits !== void 0 ? capUnits * scale : simple.capHeight,
|
|
1108
|
+
ascent: ascentUnits !== void 0 ? ascentUnits * scale : simple.ascent,
|
|
1109
|
+
descent: descentUnits !== void 0 ? descentUnits * scale : simple.descent,
|
|
1110
|
+
lineHeight: this.lineHeightFactor * fontSize
|
|
1111
|
+
};
|
|
1056
1112
|
}
|
|
1057
|
-
|
|
1113
|
+
};
|
|
1114
|
+
function capHeightFontUnits(font) {
|
|
1115
|
+
const os2Cap = font.tables?.os2?.sCapHeight;
|
|
1116
|
+
if (os2Cap != null && os2Cap > 0) return os2Cap;
|
|
1117
|
+
const h = font.charToGlyph("H");
|
|
1118
|
+
const bbox = h.getBoundingBox?.();
|
|
1119
|
+
if (bbox && Number.isFinite(bbox.y2) && bbox.y2 > 0) return bbox.y2;
|
|
1120
|
+
if (h.yMax != null && h.yMax > 0) return h.yMax;
|
|
1121
|
+
return void 0;
|
|
1058
1122
|
}
|
|
1059
|
-
function
|
|
1060
|
-
const
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1123
|
+
function ascentFontUnits(font) {
|
|
1124
|
+
const typo = font.tables?.os2?.sTypoAscender;
|
|
1125
|
+
if (typo != null && typo > 0) return typo;
|
|
1126
|
+
if (font.ascender != null && font.ascender > 0) return font.ascender;
|
|
1127
|
+
return void 0;
|
|
1128
|
+
}
|
|
1129
|
+
function descentFontUnits(font) {
|
|
1130
|
+
const typo = font.tables?.os2?.sTypoDescender;
|
|
1131
|
+
if (typo != null) return Math.abs(typo);
|
|
1132
|
+
if (font.descender != null) return Math.abs(font.descender);
|
|
1133
|
+
return void 0;
|
|
1134
|
+
}
|
|
1135
|
+
function wrapLines(text, maxWidth, measureFn) {
|
|
1136
|
+
const words = text.split(/\s+/);
|
|
1137
|
+
const lines = [];
|
|
1138
|
+
if (maxWidth !== void 0 && maxWidth > 0) {
|
|
1139
|
+
let currentLine = "";
|
|
1140
|
+
for (const word of words) {
|
|
1141
|
+
const candidate = currentLine ? `${currentLine} ${word}` : word;
|
|
1142
|
+
if (measureFn(candidate) > maxWidth && currentLine) {
|
|
1143
|
+
lines.push(currentLine);
|
|
1144
|
+
currentLine = word;
|
|
1145
|
+
} else {
|
|
1146
|
+
currentLine = candidate;
|
|
1147
|
+
}
|
|
1066
1148
|
}
|
|
1149
|
+
if (currentLine) lines.push(currentLine);
|
|
1150
|
+
} else {
|
|
1151
|
+
lines.push(text);
|
|
1067
1152
|
}
|
|
1068
|
-
return
|
|
1153
|
+
return lines;
|
|
1069
1154
|
}
|
|
1070
1155
|
|
|
1071
|
-
// src/
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
if (
|
|
1104
|
-
const top = scopeStack[scopeStack.length - 1];
|
|
1105
|
-
if (!top.nodeIds.includes(id)) top.nodeIds.push(id);
|
|
1106
|
-
} else {
|
|
1107
|
-
if (!rootNodeIds.includes(id)) rootNodeIds.push(id);
|
|
1108
|
-
}
|
|
1156
|
+
// src/renderer/defaults.ts
|
|
1157
|
+
var RENDER_DEFAULTS = {
|
|
1158
|
+
image: { fit: "contain" },
|
|
1159
|
+
icon: { foreground: "#666" },
|
|
1160
|
+
table: { borderRadius: 6, stroke: "#d1d5db", strokeWidth: 1, background: "white" },
|
|
1161
|
+
divider: { stroke: "#ccc", strokeWidth: 1 },
|
|
1162
|
+
cell: { fill: "none", stroke: "#e5e7eb", strokeWidth: 0.5 },
|
|
1163
|
+
text: {
|
|
1164
|
+
anchor: "middle",
|
|
1165
|
+
fontSize: 14,
|
|
1166
|
+
lineHeightFactor: SIMPLE_FONT_METRICS.LINE_HEIGHT,
|
|
1167
|
+
capHeightFactor: SIMPLE_FONT_METRICS.CAP_HEIGHT
|
|
1168
|
+
},
|
|
1169
|
+
box: { shape: "rect" },
|
|
1170
|
+
connectorLabel: { background: "#ffffff" },
|
|
1171
|
+
connector: { stroke: "#6b7280", strokeWidth: 1.5, arrowSize: 1, startArrow: "none", endArrow: "arrow" },
|
|
1172
|
+
roundedRect: { radius: 8 }
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1175
|
+
// src/renderer/shapes.ts
|
|
1176
|
+
var STROKE_DASHARRAY = {
|
|
1177
|
+
dashed: "6 4",
|
|
1178
|
+
dotted: "2 3"
|
|
1179
|
+
};
|
|
1180
|
+
function styleAttrs(styles) {
|
|
1181
|
+
const parts = [];
|
|
1182
|
+
if (styles.fill != null) parts.push(`fill="${esc(styles.fill)}"`);
|
|
1183
|
+
else parts.push('fill="none"');
|
|
1184
|
+
if (styles.stroke != null) parts.push(`stroke="${esc(styles.stroke)}"`);
|
|
1185
|
+
if (styles.strokeWidth != null) parts.push(`stroke-width="${styles.strokeWidth}"`);
|
|
1186
|
+
if (styles.strokeStyle != null && styles.strokeStyle !== "solid") {
|
|
1187
|
+
const da = STROKE_DASHARRAY[String(styles.strokeStyle)];
|
|
1188
|
+
if (da) parts.push(`stroke-dasharray="${da}"`);
|
|
1109
1189
|
}
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
case "comment":
|
|
1113
|
-
break;
|
|
1114
|
-
case "direction":
|
|
1115
|
-
rootDirection = token.dir;
|
|
1116
|
-
break;
|
|
1117
|
-
case "nodeDef": {
|
|
1118
|
-
const t = token;
|
|
1119
|
-
registerNode(t.nodeId, t.label, t.shape, t.variant);
|
|
1120
|
-
break;
|
|
1121
|
-
}
|
|
1122
|
-
case "edge": {
|
|
1123
|
-
const t = token;
|
|
1124
|
-
for (const seg of t.segments) {
|
|
1125
|
-
processEdgeSegment(seg);
|
|
1126
|
-
}
|
|
1127
|
-
break;
|
|
1128
|
-
}
|
|
1129
|
-
case "invisibleEdge": {
|
|
1130
|
-
const t = token;
|
|
1131
|
-
for (const seg of t.segments) {
|
|
1132
|
-
ensureNode(seg.fromId);
|
|
1133
|
-
ensureNode(seg.toId);
|
|
1134
|
-
}
|
|
1135
|
-
const dir = currentDirection();
|
|
1136
|
-
const allIds = /* @__PURE__ */ new Set();
|
|
1137
|
-
for (const seg of t.segments) {
|
|
1138
|
-
allIds.add(seg.fromId);
|
|
1139
|
-
allIds.add(seg.toId);
|
|
1140
|
-
}
|
|
1141
|
-
constraints.push(buildAlignConstraint([...allIds], dir));
|
|
1142
|
-
break;
|
|
1143
|
-
}
|
|
1144
|
-
case "subgraphStart": {
|
|
1145
|
-
const t = token;
|
|
1146
|
-
scopeStack.push({
|
|
1147
|
-
id: t.subgraphId,
|
|
1148
|
-
label: t.label,
|
|
1149
|
-
nodeIds: []
|
|
1150
|
-
});
|
|
1151
|
-
break;
|
|
1152
|
-
}
|
|
1153
|
-
case "subgraphEnd": {
|
|
1154
|
-
if (scopeStack.length === 0) {
|
|
1155
|
-
diagnostics.push({
|
|
1156
|
-
level: "warning",
|
|
1157
|
-
message: "Unexpected 'end' without matching subgraph",
|
|
1158
|
-
path: `line:${token.line}`
|
|
1159
|
-
});
|
|
1160
|
-
break;
|
|
1161
|
-
}
|
|
1162
|
-
const frame = scopeStack.pop();
|
|
1163
|
-
groups.push({ frame, children: [...frame.nodeIds] });
|
|
1164
|
-
if (scopeStack.length > 0) {
|
|
1165
|
-
const parent = scopeStack[scopeStack.length - 1];
|
|
1166
|
-
if (!parent.nodeIds.includes(frame.id)) parent.nodeIds.push(frame.id);
|
|
1167
|
-
} else {
|
|
1168
|
-
if (!rootNodeIds.includes(frame.id)) rootNodeIds.push(frame.id);
|
|
1169
|
-
}
|
|
1170
|
-
break;
|
|
1171
|
-
}
|
|
1172
|
-
case "localDirection": {
|
|
1173
|
-
const t = token;
|
|
1174
|
-
if (scopeStack.length > 0) {
|
|
1175
|
-
scopeStack[scopeStack.length - 1].direction = t.dir;
|
|
1176
|
-
} else {
|
|
1177
|
-
rootDirection = t.dir;
|
|
1178
|
-
}
|
|
1179
|
-
break;
|
|
1180
|
-
}
|
|
1181
|
-
case "classDef": {
|
|
1182
|
-
const t = token;
|
|
1183
|
-
classDefMap.set(t.className, t.styles);
|
|
1184
|
-
break;
|
|
1185
|
-
}
|
|
1186
|
-
case "directive": {
|
|
1187
|
-
const t = token;
|
|
1188
|
-
processDirective(t);
|
|
1189
|
-
break;
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
function processEdgeSegment(seg) {
|
|
1194
|
-
if (seg.fromDef) {
|
|
1195
|
-
registerNode(seg.fromId, seg.fromDef.label, seg.fromDef.shape, seg.fromDef.variant);
|
|
1196
|
-
} else {
|
|
1197
|
-
ensureNode(seg.fromId);
|
|
1198
|
-
}
|
|
1199
|
-
if (seg.toDef) {
|
|
1200
|
-
registerNode(seg.toId, seg.toDef.label, seg.toDef.shape, seg.toDef.variant);
|
|
1201
|
-
} else {
|
|
1202
|
-
ensureNode(seg.toId);
|
|
1203
|
-
}
|
|
1204
|
-
const connectorProps = {
|
|
1205
|
-
from: seg.fromId,
|
|
1206
|
-
to: seg.toId
|
|
1207
|
-
};
|
|
1208
|
-
switch (seg.edgeType) {
|
|
1209
|
-
case "-->":
|
|
1210
|
-
connectorProps.endArrow = "arrow";
|
|
1211
|
-
break;
|
|
1212
|
-
case "---":
|
|
1213
|
-
connectorProps.startArrow = "none";
|
|
1214
|
-
connectorProps.endArrow = "none";
|
|
1215
|
-
break;
|
|
1216
|
-
case "-.->":
|
|
1217
|
-
connectorProps.strokeStyle = "dashed";
|
|
1218
|
-
connectorProps.endArrow = "arrow";
|
|
1219
|
-
break;
|
|
1220
|
-
case "==>":
|
|
1221
|
-
connectorProps.strokeWidth = 3;
|
|
1222
|
-
connectorProps.endArrow = "arrow";
|
|
1223
|
-
break;
|
|
1224
|
-
}
|
|
1225
|
-
const children = [];
|
|
1226
|
-
if (seg.edgeLabel) {
|
|
1227
|
-
children.push({
|
|
1228
|
-
kind: "label",
|
|
1229
|
-
props: { text: seg.edgeLabel }
|
|
1230
|
-
});
|
|
1231
|
-
}
|
|
1232
|
-
const connector = {
|
|
1233
|
-
kind: "connector",
|
|
1234
|
-
props: connectorProps
|
|
1235
|
-
};
|
|
1236
|
-
if (children.length > 0) {
|
|
1237
|
-
connector.children = children;
|
|
1238
|
-
}
|
|
1239
|
-
connectors.push(connector);
|
|
1240
|
-
}
|
|
1241
|
-
function processDirective(t) {
|
|
1242
|
-
switch (t.directiveType) {
|
|
1243
|
-
case "same-width": {
|
|
1244
|
-
const props = { targets: t.targets };
|
|
1245
|
-
if (t.strategy) props.strategy = t.strategy;
|
|
1246
|
-
constraints.push({ kind: "equalizeWidth", props });
|
|
1247
|
-
break;
|
|
1248
|
-
}
|
|
1249
|
-
case "same-height": {
|
|
1250
|
-
const props = { targets: t.targets };
|
|
1251
|
-
if (t.strategy) props.strategy = t.strategy;
|
|
1252
|
-
constraints.push({ kind: "equalizeHeight", props });
|
|
1253
|
-
break;
|
|
1254
|
-
}
|
|
1255
|
-
case "gap": {
|
|
1256
|
-
const props = {
|
|
1257
|
-
targets: t.targets,
|
|
1258
|
-
gap: t.min
|
|
1259
|
-
};
|
|
1260
|
-
constraints.push({ kind: "minGap", props });
|
|
1261
|
-
break;
|
|
1262
|
-
}
|
|
1263
|
-
case "mover": {
|
|
1264
|
-
const props = {
|
|
1265
|
-
targets: t.targets,
|
|
1266
|
-
mover: t.moverId
|
|
1267
|
-
};
|
|
1268
|
-
constraints.push({ kind: "alignConstraint", props });
|
|
1269
|
-
break;
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
const stackKind = rootDirection === "LR" ? "hstack" : "vstack";
|
|
1274
|
-
const groupNodes = /* @__PURE__ */ new Map();
|
|
1275
|
-
for (const g of groups) {
|
|
1276
|
-
const dir = g.frame.direction ?? rootDirection;
|
|
1277
|
-
const innerKind = dir === "LR" ? "hstack" : "vstack";
|
|
1278
|
-
const groupChildren = [];
|
|
1279
|
-
const innerStack = {
|
|
1280
|
-
kind: innerKind,
|
|
1281
|
-
props: { gap: 60, align: "center" },
|
|
1282
|
-
children: []
|
|
1283
|
-
};
|
|
1284
|
-
for (const childId of g.children) {
|
|
1285
|
-
const childGroup = groupNodes.get(childId);
|
|
1286
|
-
if (childGroup) {
|
|
1287
|
-
innerStack.children.push(childGroup);
|
|
1288
|
-
} else {
|
|
1289
|
-
const node = nodeMap.get(childId);
|
|
1290
|
-
if (node) {
|
|
1291
|
-
innerStack.children.push(buildBox(node));
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
groupChildren.push(innerStack);
|
|
1296
|
-
const groupNode = {
|
|
1297
|
-
kind: "group",
|
|
1298
|
-
id: g.frame.id,
|
|
1299
|
-
props: {},
|
|
1300
|
-
children: groupChildren
|
|
1301
|
-
};
|
|
1302
|
-
if (g.frame.label) {
|
|
1303
|
-
groupNode.props.label = g.frame.label;
|
|
1304
|
-
}
|
|
1305
|
-
groupNodes.set(g.frame.id, groupNode);
|
|
1306
|
-
}
|
|
1307
|
-
const rootChildren = [];
|
|
1308
|
-
for (const id of rootNodeIds) {
|
|
1309
|
-
const groupNode = groupNodes.get(id);
|
|
1310
|
-
if (groupNode) {
|
|
1311
|
-
rootChildren.push(groupNode);
|
|
1312
|
-
} else {
|
|
1313
|
-
const node = nodeMap.get(id);
|
|
1314
|
-
if (node) {
|
|
1315
|
-
rootChildren.push(buildBox(node));
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
const rootStack = {
|
|
1320
|
-
kind: stackKind,
|
|
1321
|
-
props: { gap: 60, align: "center" },
|
|
1322
|
-
children: rootChildren
|
|
1323
|
-
};
|
|
1324
|
-
const documentChildren = [rootStack, ...connectors, ...constraints];
|
|
1325
|
-
const document = {
|
|
1326
|
-
kind: "document",
|
|
1327
|
-
props: { padding: 20 },
|
|
1328
|
-
children: documentChildren
|
|
1329
|
-
};
|
|
1330
|
-
return { ir: document, diagnostics };
|
|
1190
|
+
if (styles.opacity != null) parts.push(`opacity="${styles.opacity}"`);
|
|
1191
|
+
return parts.join(" ");
|
|
1331
1192
|
}
|
|
1332
|
-
function
|
|
1333
|
-
|
|
1334
|
-
if (node.variant) {
|
|
1335
|
-
props.variant = node.variant;
|
|
1336
|
-
}
|
|
1337
|
-
return {
|
|
1338
|
-
kind: "box",
|
|
1339
|
-
id: node.id,
|
|
1340
|
-
props,
|
|
1341
|
-
children: [
|
|
1342
|
-
{ kind: "text", props: { text: node.label } }
|
|
1343
|
-
]
|
|
1344
|
-
};
|
|
1193
|
+
function esc(v) {
|
|
1194
|
+
return String(v).replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
1345
1195
|
}
|
|
1346
|
-
function
|
|
1347
|
-
|
|
1348
|
-
return {
|
|
1349
|
-
kind: "alignConstraint",
|
|
1350
|
-
props: {
|
|
1351
|
-
targets,
|
|
1352
|
-
axis,
|
|
1353
|
-
align: "center"
|
|
1354
|
-
}
|
|
1355
|
-
};
|
|
1196
|
+
function pts(coords) {
|
|
1197
|
+
return coords.map(([px, py]) => `${px},${py}`).join(" ");
|
|
1356
1198
|
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
import ts from "typescript";
|
|
1360
|
-
|
|
1361
|
-
// src/graph/rule-engine.ts
|
|
1362
|
-
import { load } from "js-yaml";
|
|
1363
|
-
|
|
1364
|
-
// src/graph/graph-helpers.ts
|
|
1365
|
-
function num(v) {
|
|
1366
|
-
return v ?? 0;
|
|
1199
|
+
function renderRect(r, sa) {
|
|
1200
|
+
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" ${sa}/>`;
|
|
1367
1201
|
}
|
|
1368
|
-
function
|
|
1369
|
-
|
|
1202
|
+
function renderRoundedRect(r, styles, sa) {
|
|
1203
|
+
const rx = styles.radius != null ? Number(styles.radius) : RENDER_DEFAULTS.roundedRect.radius;
|
|
1204
|
+
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
1370
1205
|
}
|
|
1371
|
-
function
|
|
1372
|
-
|
|
1206
|
+
function renderCircle(r, sa) {
|
|
1207
|
+
const radius = r.width / 2;
|
|
1208
|
+
return `<circle cx="${r.x + radius}" cy="${r.y + radius}" r="${radius}" ${sa}/>`;
|
|
1373
1209
|
}
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
graph.slots.set(id, slot);
|
|
1380
|
-
} else if (value !== void 0 && slot.value === void 0) {
|
|
1381
|
-
slot.value = value;
|
|
1382
|
-
}
|
|
1383
|
-
return slot;
|
|
1210
|
+
var ASPECT_LOCKED_SHAPES = /* @__PURE__ */ new Set(["circle"]);
|
|
1211
|
+
function renderEllipse(r, sa) {
|
|
1212
|
+
const rx = r.width / 2;
|
|
1213
|
+
const ry = r.height / 2;
|
|
1214
|
+
return `<ellipse cx="${r.x + rx}" cy="${r.y + ry}" rx="${rx}" ry="${ry}" ${sa}/>`;
|
|
1384
1215
|
}
|
|
1385
|
-
function
|
|
1386
|
-
const
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
let byOp = graph.candidatesByOperation.get(operationId);
|
|
1396
|
-
if (!byOp) {
|
|
1397
|
-
byOp = [];
|
|
1398
|
-
graph.candidatesByOperation.set(operationId, byOp);
|
|
1399
|
-
}
|
|
1400
|
-
byOp.push(candidate);
|
|
1401
|
-
}
|
|
1402
|
-
return candidate;
|
|
1216
|
+
function renderDiamond(r, sa) {
|
|
1217
|
+
const cx = r.x + r.width / 2;
|
|
1218
|
+
const cy = r.y + r.height / 2;
|
|
1219
|
+
const points = [
|
|
1220
|
+
[cx, r.y],
|
|
1221
|
+
[r.x + r.width, cy],
|
|
1222
|
+
[cx, r.y + r.height],
|
|
1223
|
+
[r.x, cy]
|
|
1224
|
+
];
|
|
1225
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
1403
1226
|
}
|
|
1404
|
-
function
|
|
1405
|
-
const
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1227
|
+
function renderParallelogram(r, sa) {
|
|
1228
|
+
const skew = r.width * 0.2;
|
|
1229
|
+
const points = [
|
|
1230
|
+
[r.x + skew, r.y],
|
|
1231
|
+
[r.x + r.width, r.y],
|
|
1232
|
+
[r.x + r.width - skew, r.y + r.height],
|
|
1233
|
+
[r.x, r.y + r.height]
|
|
1234
|
+
];
|
|
1235
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
1411
1236
|
}
|
|
1412
|
-
function
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
}
|
|
1237
|
+
function renderCapsule(r, sa) {
|
|
1238
|
+
const rx = Math.min(r.width, r.height) / 2;
|
|
1239
|
+
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
1416
1240
|
}
|
|
1417
|
-
function
|
|
1418
|
-
const
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1241
|
+
function renderCylinder(r, sa) {
|
|
1242
|
+
const ellipseH = Math.min(r.height * 0.2, 20);
|
|
1243
|
+
const ry = ellipseH / 2;
|
|
1244
|
+
const x = r.x;
|
|
1245
|
+
const y = r.y;
|
|
1246
|
+
const w = r.width;
|
|
1247
|
+
const h = r.height;
|
|
1248
|
+
const rx = w / 2;
|
|
1249
|
+
const topArc = `M ${x},${y + ry} A ${rx},${ry} 0 0,1 ${x + w},${y + ry}`;
|
|
1250
|
+
const rightSide = `L ${x + w},${y + h - ry}`;
|
|
1251
|
+
const bottomArc = `A ${rx},${ry} 0 0,1 ${x},${y + h - ry}`;
|
|
1252
|
+
const leftSide = `L ${x},${y + ry}`;
|
|
1253
|
+
const topEllipseBack = `M ${x},${y + ry} A ${rx},${ry} 0 0,0 ${x + w},${y + ry}`;
|
|
1254
|
+
return `<path d="${topArc} ${rightSide} ${bottomArc} ${leftSide}" ${sa}/><path d="${topEllipseBack}" ${styles_stroke_only(sa)}/>`;
|
|
1425
1255
|
}
|
|
1426
|
-
function
|
|
1427
|
-
|
|
1428
|
-
return typeof val === "string" ? val : defaultValue;
|
|
1256
|
+
function styles_stroke_only(sa) {
|
|
1257
|
+
return sa.replace(/fill="[^"]*"/, 'fill="none"');
|
|
1429
1258
|
}
|
|
1430
|
-
function
|
|
1431
|
-
const
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1259
|
+
function renderHexagon(r, sa) {
|
|
1260
|
+
const cx = r.x + r.width / 2;
|
|
1261
|
+
const cy = r.y + r.height / 2;
|
|
1262
|
+
const inset = r.width * 0.25;
|
|
1263
|
+
const points = [
|
|
1264
|
+
[r.x + inset, r.y],
|
|
1265
|
+
[r.x + r.width - inset, r.y],
|
|
1266
|
+
[r.x + r.width, cy],
|
|
1267
|
+
[r.x + r.width - inset, r.y + r.height],
|
|
1268
|
+
[r.x + inset, r.y + r.height],
|
|
1269
|
+
[r.x, cy]
|
|
1270
|
+
];
|
|
1271
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
1440
1272
|
}
|
|
1441
|
-
function
|
|
1442
|
-
|
|
1273
|
+
function renderTriangle(r, sa) {
|
|
1274
|
+
const points = [
|
|
1275
|
+
[r.x + r.width / 2, r.y],
|
|
1276
|
+
[r.x + r.width, r.y + r.height],
|
|
1277
|
+
[r.x, r.y + r.height]
|
|
1278
|
+
];
|
|
1279
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
1443
1280
|
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
ensureSlot(graph, id, "contentHeight", heightIntent);
|
|
1461
|
-
addCandidate(graph, slotId(id, "contentHeight"), heightIntent, `${node.kind}(${id}).explicit`, "required");
|
|
1462
|
-
addCandidate(graph, slotId(id, "resolvedHeight"), heightIntent, `${node.kind}(${id}).explicit`, "normal");
|
|
1463
|
-
} else if (heightIntent === "fill" && parentId) {
|
|
1464
|
-
ensureSlot(graph, parentId, "availableHeight");
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
// src/graph/east-asian-width.ts
|
|
1469
|
-
var WIDE_RANGES = [
|
|
1470
|
-
[4352, 4447],
|
|
1471
|
-
// Hangul Jamo (leading consonants)
|
|
1472
|
-
[8986, 8987],
|
|
1473
|
-
// ⌚ ⌛ watch, hourglass
|
|
1474
|
-
[9001, 9002],
|
|
1475
|
-
// 〈 〉 angle brackets (EAW Wide)
|
|
1476
|
-
[9193, 9196],
|
|
1477
|
-
// ⏩–⏬ media controls
|
|
1478
|
-
[9200, 9200],
|
|
1479
|
-
// ⏰ alarm clock
|
|
1480
|
-
[9203, 9203],
|
|
1481
|
-
// ⏳ hourglass with sand
|
|
1482
|
-
[9725, 9726],
|
|
1483
|
-
// ◽ ◾ medium small squares
|
|
1484
|
-
[9748, 9749],
|
|
1485
|
-
// ☔ ☕ umbrella, hot beverage
|
|
1486
|
-
[9800, 9811],
|
|
1487
|
-
// ♈–♓ zodiac signs
|
|
1488
|
-
[9855, 9855],
|
|
1489
|
-
// ♿ wheelchair symbol
|
|
1490
|
-
[9875, 9875],
|
|
1491
|
-
// ⚓ anchor
|
|
1492
|
-
[9889, 9889],
|
|
1493
|
-
// ⚡ high voltage
|
|
1494
|
-
[9898, 9899],
|
|
1495
|
-
// ⚪ ⚫ circles
|
|
1496
|
-
[9917, 9918],
|
|
1497
|
-
// ⚽ ⚾ soccer, baseball
|
|
1498
|
-
[9924, 9925],
|
|
1499
|
-
// ⛄ ⛅ snowman, sun behind cloud
|
|
1500
|
-
[9934, 9934],
|
|
1501
|
-
// ⛎ Ophiuchus
|
|
1502
|
-
[9940, 9940],
|
|
1503
|
-
// ⛔ no entry
|
|
1504
|
-
[9962, 9962],
|
|
1505
|
-
// ⛪ church
|
|
1506
|
-
[9970, 9971],
|
|
1507
|
-
// ⛲ ⛳ fountain, flag in hole
|
|
1508
|
-
[9973, 9973],
|
|
1509
|
-
// ⛵ sailboat
|
|
1510
|
-
[9978, 9978],
|
|
1511
|
-
// ⛺ tent
|
|
1512
|
-
[9981, 9981],
|
|
1513
|
-
// ⛽ fuel pump
|
|
1514
|
-
[9989, 9989],
|
|
1515
|
-
// ✅ check mark button
|
|
1516
|
-
[9994, 9995],
|
|
1517
|
-
// ✊ ✋ fists
|
|
1518
|
-
[10024, 10024],
|
|
1519
|
-
// ✨ sparkles
|
|
1520
|
-
[10060, 10060],
|
|
1521
|
-
// ❌ cross mark
|
|
1522
|
-
[10062, 10062],
|
|
1523
|
-
// ❎ cross mark button
|
|
1524
|
-
[10067, 10069],
|
|
1525
|
-
// ❓❔❕ question/exclamation marks
|
|
1526
|
-
[10071, 10071],
|
|
1527
|
-
// ❗ exclamation mark
|
|
1528
|
-
[10133, 10135],
|
|
1529
|
-
// ➕➖➗ math signs
|
|
1530
|
-
[10160, 10160],
|
|
1531
|
-
// ➰ curly loop
|
|
1532
|
-
[10175, 10175],
|
|
1533
|
-
// ➿ double curly loop
|
|
1534
|
-
[11035, 11036],
|
|
1535
|
-
// ⬛ ⬜ large squares
|
|
1536
|
-
[11088, 11088],
|
|
1537
|
-
// ⭐ star
|
|
1538
|
-
[11093, 11093],
|
|
1539
|
-
// ⭕ heavy large circle
|
|
1540
|
-
[11904, 12350],
|
|
1541
|
-
// CJK Radicals, Kangxi Radicals, CJK Symbols & Punctuation (incl. U+3000 ideographic space)
|
|
1542
|
-
[12353, 13311],
|
|
1543
|
-
// Hiragana, Katakana, Bopomofo, Hangul Compat Jamo, Kanbun, CJK Compatibility
|
|
1544
|
-
[13312, 19903],
|
|
1545
|
-
// CJK Unified Ideographs Extension A
|
|
1546
|
-
[19968, 40959],
|
|
1547
|
-
// CJK Unified Ideographs
|
|
1548
|
-
[40960, 42191],
|
|
1549
|
-
// Yi Syllables, Yi Radicals
|
|
1550
|
-
[43360, 43391],
|
|
1551
|
-
// Hangul Jamo Extended-A
|
|
1552
|
-
[44032, 55203],
|
|
1553
|
-
// Hangul Syllables
|
|
1554
|
-
[63744, 64255],
|
|
1555
|
-
// CJK Compatibility Ideographs
|
|
1556
|
-
[65040, 65049],
|
|
1557
|
-
// Vertical Forms
|
|
1558
|
-
[65072, 65106],
|
|
1559
|
-
// CJK Compatibility Forms
|
|
1560
|
-
[65108, 65126],
|
|
1561
|
-
// Small Form Variants
|
|
1562
|
-
[65128, 65131],
|
|
1563
|
-
// Small Form Variants (fullwidth-ish signs)
|
|
1564
|
-
[65281, 65376],
|
|
1565
|
-
// Fullwidth Forms (! … ⦆)
|
|
1566
|
-
[65504, 65510],
|
|
1567
|
-
// Fullwidth signs (¢ £ ¬  ̄ ¦ ¥ ₩)
|
|
1568
|
-
[94176, 101759],
|
|
1569
|
-
// Tangut, Khitan Small Script, Tangut Supplement (EAW Wide)
|
|
1570
|
-
[110576, 111355],
|
|
1571
|
-
// Kana Extended-B, Kana Supplement, Kana Extended-A, Small Kana Extension, Nushu
|
|
1572
|
-
[126980, 126980],
|
|
1573
|
-
// 🀄 mahjong red dragon
|
|
1574
|
-
[127183, 127183],
|
|
1575
|
-
// 🃏 playing card joker
|
|
1576
|
-
[127374, 127374],
|
|
1577
|
-
// 🆎 AB blood type button
|
|
1578
|
-
[127377, 127386],
|
|
1579
|
-
// 🆑–🆚 squared Latin abbreviations
|
|
1580
|
-
[127488, 127589],
|
|
1581
|
-
// Enclosed Ideographic Supplement (🈁 🈯 squared kana/CJK)
|
|
1582
|
-
[127744, 128591],
|
|
1583
|
-
// Misc Symbols & Pictographs, Emoticons (emoji, EAW Wide)
|
|
1584
|
-
[128640, 128767],
|
|
1585
|
-
// Transport and Map Symbols (🚀 …)
|
|
1586
|
-
[128992, 129008],
|
|
1587
|
-
// Geometric Shapes Extended (colored circles/squares)
|
|
1588
|
-
[129280, 129535],
|
|
1589
|
-
// Supplemental Symbols & Pictographs (emoji, EAW Wide)
|
|
1590
|
-
[129648, 129791],
|
|
1591
|
-
// Symbols & Pictographs Extended-A (🩰 🪐 …)
|
|
1592
|
-
[131072, 196605],
|
|
1593
|
-
// CJK Unified Ideographs Extensions B–F
|
|
1594
|
-
[196608, 262141]
|
|
1595
|
-
// CJK Unified Ideographs Extension G+
|
|
1596
|
-
];
|
|
1597
|
-
function isEastAsianWide(codePoint) {
|
|
1598
|
-
let lo = 0;
|
|
1599
|
-
let hi = WIDE_RANGES.length - 1;
|
|
1600
|
-
while (lo <= hi) {
|
|
1601
|
-
const mid = lo + hi >> 1;
|
|
1602
|
-
const [start, end] = WIDE_RANGES[mid];
|
|
1603
|
-
if (codePoint < start) {
|
|
1604
|
-
hi = mid - 1;
|
|
1605
|
-
} else if (codePoint > end) {
|
|
1606
|
-
lo = mid + 1;
|
|
1607
|
-
} else {
|
|
1608
|
-
return true;
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
return false;
|
|
1612
|
-
}
|
|
1613
|
-
function approxCharEm(codePoint) {
|
|
1614
|
-
return isEastAsianWide(codePoint) ? 1 : 0.6;
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
// src/graph/ops.ts
|
|
1618
|
-
function approxTextWidth(text, fontSize) {
|
|
1619
|
-
let width = 0;
|
|
1620
|
-
for (const ch of text) {
|
|
1621
|
-
width += approxCharEm(ch.codePointAt(0)) * fontSize;
|
|
1622
|
-
}
|
|
1623
|
-
return width;
|
|
1624
|
-
}
|
|
1625
|
-
var SIMPLE_FONT_METRICS = {
|
|
1626
|
-
CAP_HEIGHT: 0.7,
|
|
1627
|
-
ASCENT: 0.9,
|
|
1628
|
-
DESCENT: 0.25,
|
|
1629
|
-
LINE_HEIGHT: 1.4
|
|
1630
|
-
};
|
|
1631
|
-
var SimpleTextMeasurer = class {
|
|
1632
|
-
measure(text, fontSize, maxWidth) {
|
|
1633
|
-
const lineHeight = SIMPLE_FONT_METRICS.LINE_HEIGHT * fontSize;
|
|
1634
|
-
if (!text) {
|
|
1635
|
-
return { width: 0, height: lineHeight, lines: [""] };
|
|
1636
|
-
}
|
|
1637
|
-
const measureFn = (t) => approxTextWidth(t, fontSize);
|
|
1638
|
-
const lines = wrapLines(text, maxWidth, measureFn);
|
|
1639
|
-
const width = Math.max(...lines.map(measureFn));
|
|
1640
|
-
const height = lines.length * lineHeight;
|
|
1641
|
-
return { width, height, lines };
|
|
1642
|
-
}
|
|
1643
|
-
metrics(fontSize) {
|
|
1644
|
-
return {
|
|
1645
|
-
ascent: SIMPLE_FONT_METRICS.ASCENT * fontSize,
|
|
1646
|
-
descent: SIMPLE_FONT_METRICS.DESCENT * fontSize,
|
|
1647
|
-
capHeight: SIMPLE_FONT_METRICS.CAP_HEIGHT * fontSize,
|
|
1648
|
-
lineHeight: SIMPLE_FONT_METRICS.LINE_HEIGHT * fontSize
|
|
1649
|
-
};
|
|
1650
|
-
}
|
|
1651
|
-
};
|
|
1652
|
-
var BROWSER_COMPENSATION = 1.1;
|
|
1653
|
-
function measureGlyphWidth(font, text, fontSize) {
|
|
1654
|
-
const scale = fontSize / font.unitsPerEm;
|
|
1655
|
-
let width = 0;
|
|
1656
|
-
for (const ch of text) {
|
|
1657
|
-
const glyph = font.charToGlyph(ch);
|
|
1658
|
-
const missing = glyph.index === 0 || glyph.advanceWidth == null;
|
|
1659
|
-
if (missing) {
|
|
1660
|
-
width += approxCharEm(ch.codePointAt(0)) * fontSize;
|
|
1661
|
-
} else {
|
|
1662
|
-
width += glyph.advanceWidth * scale;
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
return width * BROWSER_COMPENSATION;
|
|
1666
|
-
}
|
|
1667
|
-
var OpenTypeTextMeasurer = class _OpenTypeTextMeasurer {
|
|
1668
|
-
fonts = /* @__PURE__ */ new Map();
|
|
1669
|
-
// Line-box factor shared with the SimpleTextMeasurer SSoT so a single-line
|
|
1670
|
-
// text box's measured height matches the line box regardless of measurer.
|
|
1671
|
-
lineHeightFactor = SIMPLE_FONT_METRICS.LINE_HEIGHT;
|
|
1672
|
-
addFont(key, font) {
|
|
1673
|
-
this.fonts.set(key, font);
|
|
1674
|
-
}
|
|
1675
|
-
/** Canonical CSS font-weight key for "normal" — the default when none given. */
|
|
1676
|
-
static DEFAULT_WEIGHT = "400";
|
|
1677
|
-
static WEIGHT_ALIASES = {
|
|
1678
|
-
normal: "400",
|
|
1679
|
-
bold: "700",
|
|
1680
|
-
lighter: "300",
|
|
1681
|
-
bolder: "700"
|
|
1682
|
-
};
|
|
1683
|
-
getFont(fontWeight) {
|
|
1684
|
-
const raw = fontWeight != null ? String(fontWeight) : _OpenTypeTextMeasurer.DEFAULT_WEIGHT;
|
|
1685
|
-
const w = _OpenTypeTextMeasurer.WEIGHT_ALIASES[raw] ?? raw;
|
|
1686
|
-
return this.fonts.get(w) ?? this.fonts.get(_OpenTypeTextMeasurer.DEFAULT_WEIGHT) ?? this.fonts.values().next().value;
|
|
1687
|
-
}
|
|
1688
|
-
measure(text, fontSize, maxWidth, fontWeight) {
|
|
1689
|
-
const lineHeight = this.lineHeightFactor * fontSize;
|
|
1690
|
-
if (!text) {
|
|
1691
|
-
return { width: 0, height: lineHeight, lines: [""] };
|
|
1692
|
-
}
|
|
1693
|
-
const font = this.getFont(fontWeight);
|
|
1694
|
-
if (!font) {
|
|
1695
|
-
return new SimpleTextMeasurer().measure(text, fontSize, maxWidth);
|
|
1696
|
-
}
|
|
1697
|
-
const measureFn = (t) => measureGlyphWidth(font, t, fontSize);
|
|
1698
|
-
const lines = wrapLines(text, maxWidth, measureFn);
|
|
1699
|
-
const width = Math.max(...lines.map(measureFn));
|
|
1700
|
-
const height = lines.length * lineHeight;
|
|
1701
|
-
return { width, height, lines };
|
|
1702
|
-
}
|
|
1703
|
-
/**
|
|
1704
|
-
* Real vertical metrics for the weight's font, in px at `fontSize`.
|
|
1705
|
-
*
|
|
1706
|
-
* capHeight comes from the OS/2 `sCapHeight` field when present; otherwise it
|
|
1707
|
-
* is measured from the "H" glyph's bounding box (top-of-cap in font units).
|
|
1708
|
-
* If neither is available the loaded font is degenerate, so we defer to the
|
|
1709
|
-
* documented {@link SIMPLE_FONT_METRICS} ratio rather than inventing a value.
|
|
1710
|
-
* ascent/descent use the OS/2 typographic values, falling back to the
|
|
1711
|
-
* hhea ascender/descender, then to the Simple ratios.
|
|
1712
|
-
*/
|
|
1713
|
-
metrics(fontSize, fontWeight) {
|
|
1714
|
-
const font = this.getFont(fontWeight);
|
|
1715
|
-
if (!font) {
|
|
1716
|
-
return new SimpleTextMeasurer().metrics(fontSize);
|
|
1717
|
-
}
|
|
1718
|
-
const scale = fontSize / font.unitsPerEm;
|
|
1719
|
-
const simple = new SimpleTextMeasurer().metrics(fontSize);
|
|
1720
|
-
const capUnits = capHeightFontUnits(font);
|
|
1721
|
-
const ascentUnits = ascentFontUnits(font);
|
|
1722
|
-
const descentUnits = descentFontUnits(font);
|
|
1723
|
-
return {
|
|
1724
|
-
capHeight: capUnits !== void 0 ? capUnits * scale : simple.capHeight,
|
|
1725
|
-
ascent: ascentUnits !== void 0 ? ascentUnits * scale : simple.ascent,
|
|
1726
|
-
descent: descentUnits !== void 0 ? descentUnits * scale : simple.descent,
|
|
1727
|
-
lineHeight: this.lineHeightFactor * fontSize
|
|
1728
|
-
};
|
|
1729
|
-
}
|
|
1730
|
-
};
|
|
1731
|
-
function capHeightFontUnits(font) {
|
|
1732
|
-
const os2Cap = font.tables?.os2?.sCapHeight;
|
|
1733
|
-
if (os2Cap != null && os2Cap > 0) return os2Cap;
|
|
1734
|
-
const h = font.charToGlyph("H");
|
|
1735
|
-
const bbox = h.getBoundingBox?.();
|
|
1736
|
-
if (bbox && Number.isFinite(bbox.y2) && bbox.y2 > 0) return bbox.y2;
|
|
1737
|
-
if (h.yMax != null && h.yMax > 0) return h.yMax;
|
|
1738
|
-
return void 0;
|
|
1739
|
-
}
|
|
1740
|
-
function ascentFontUnits(font) {
|
|
1741
|
-
const typo = font.tables?.os2?.sTypoAscender;
|
|
1742
|
-
if (typo != null && typo > 0) return typo;
|
|
1743
|
-
if (font.ascender != null && font.ascender > 0) return font.ascender;
|
|
1744
|
-
return void 0;
|
|
1745
|
-
}
|
|
1746
|
-
function descentFontUnits(font) {
|
|
1747
|
-
const typo = font.tables?.os2?.sTypoDescender;
|
|
1748
|
-
if (typo != null) return Math.abs(typo);
|
|
1749
|
-
if (font.descender != null) return Math.abs(font.descender);
|
|
1750
|
-
return void 0;
|
|
1751
|
-
}
|
|
1752
|
-
function wrapLines(text, maxWidth, measureFn) {
|
|
1753
|
-
const words = text.split(/\s+/);
|
|
1754
|
-
const lines = [];
|
|
1755
|
-
if (maxWidth !== void 0 && maxWidth > 0) {
|
|
1756
|
-
let currentLine = "";
|
|
1757
|
-
for (const word of words) {
|
|
1758
|
-
const candidate = currentLine ? `${currentLine} ${word}` : word;
|
|
1759
|
-
if (measureFn(candidate) > maxWidth && currentLine) {
|
|
1760
|
-
lines.push(currentLine);
|
|
1761
|
-
currentLine = word;
|
|
1762
|
-
} else {
|
|
1763
|
-
currentLine = candidate;
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
if (currentLine) lines.push(currentLine);
|
|
1767
|
-
} else {
|
|
1768
|
-
lines.push(text);
|
|
1769
|
-
}
|
|
1770
|
-
return lines;
|
|
1281
|
+
var SHAPE_RENDERERS = {
|
|
1282
|
+
rect: (r, _s, sa) => renderRect(r, sa),
|
|
1283
|
+
roundedRect: (r, s, sa) => renderRoundedRect(r, s, sa),
|
|
1284
|
+
circle: (r, _s, sa) => renderCircle(r, sa),
|
|
1285
|
+
ellipse: (r, _s, sa) => renderEllipse(r, sa),
|
|
1286
|
+
diamond: (r, _s, sa) => renderDiamond(r, sa),
|
|
1287
|
+
parallelogram: (r, _s, sa) => renderParallelogram(r, sa),
|
|
1288
|
+
capsule: (r, _s, sa) => renderCapsule(r, sa),
|
|
1289
|
+
cylinder: (r, _s, sa) => renderCylinder(r, sa),
|
|
1290
|
+
hexagon: (r, _s, sa) => renderHexagon(r, sa),
|
|
1291
|
+
triangle: (r, _s, sa) => renderTriangle(r, sa)
|
|
1292
|
+
};
|
|
1293
|
+
function renderShape(shape, rect, styles) {
|
|
1294
|
+
const sa = styleAttrs(styles);
|
|
1295
|
+
const renderer = SHAPE_RENDERERS[shape] ?? SHAPE_RENDERERS.rect;
|
|
1296
|
+
return renderer(rect, styles, sa);
|
|
1771
1297
|
}
|
|
1772
1298
|
|
|
1773
1299
|
// src/graph/rule-engine.ts
|
|
@@ -2224,1251 +1750,1974 @@ function deriveAllowedPropsMap(layoutRulesInput, constraintRulesInput) {
|
|
|
2224
1750
|
if (moverPropName && /^[A-Za-z_][A-Za-z0-9_]*$/.test(moverPropName)) {
|
|
2225
1751
|
props.add(moverPropName);
|
|
2226
1752
|
}
|
|
2227
|
-
if (rule.operation === "world_align") props.add("align");
|
|
2228
|
-
map.set(constraintKind, props);
|
|
1753
|
+
if (rule.operation === "world_align") props.add("align");
|
|
1754
|
+
map.set(constraintKind, props);
|
|
1755
|
+
}
|
|
1756
|
+
return map;
|
|
1757
|
+
}
|
|
1758
|
+
function buildAllowedPropsMap() {
|
|
1759
|
+
return deriveAllowedPropsMap(layoutRules, constraintRules);
|
|
1760
|
+
}
|
|
1761
|
+
var _allowedPropsMap;
|
|
1762
|
+
function getAllowedProps(kind) {
|
|
1763
|
+
if (!_allowedPropsMap) _allowedPropsMap = buildAllowedPropsMap();
|
|
1764
|
+
return _allowedPropsMap.get(kind);
|
|
1765
|
+
}
|
|
1766
|
+
function buildCatalogKindSet() {
|
|
1767
|
+
const kinds = /* @__PURE__ */ new Set();
|
|
1768
|
+
for (const [ruleKey, rule] of Object.entries(layoutRules)) {
|
|
1769
|
+
if (ruleKey === "style_props") continue;
|
|
1770
|
+
if (rule.applies_to) {
|
|
1771
|
+
for (const subKind of Object.keys(rule.applies_to)) kinds.add(subKind);
|
|
1772
|
+
continue;
|
|
1773
|
+
}
|
|
1774
|
+
kinds.add(ruleKey);
|
|
1775
|
+
if (rule.grid) {
|
|
1776
|
+
kinds.add(rule.grid.row_kind);
|
|
1777
|
+
kinds.add(rule.grid.cell_kind);
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
for (const constraintKind of Object.keys(constraintRules)) {
|
|
1781
|
+
kinds.add(constraintKind);
|
|
1782
|
+
}
|
|
1783
|
+
return kinds;
|
|
1784
|
+
}
|
|
1785
|
+
var _catalogKinds;
|
|
1786
|
+
function hasCatalogRule(kind) {
|
|
1787
|
+
if (!_catalogKinds) _catalogKinds = buildCatalogKindSet();
|
|
1788
|
+
return _catalogKinds.has(kind);
|
|
1789
|
+
}
|
|
1790
|
+
function unsupportedKindMessage(kind) {
|
|
1791
|
+
return `Element kind '${kind}' has no layout rules in the Rule Catalog and is not yet supported`;
|
|
1792
|
+
}
|
|
1793
|
+
var MAIN_AXIS_KINDS = {
|
|
1794
|
+
vstack: "localY",
|
|
1795
|
+
hstack: "localX",
|
|
1796
|
+
row: "localX"
|
|
1797
|
+
};
|
|
1798
|
+
function baseMainSlot(mainSlot) {
|
|
1799
|
+
return mainSlot === "localY" ? "baseLocalY" : "baseLocalX";
|
|
1800
|
+
}
|
|
1801
|
+
function getEffectiveSizeIntent(node, prop) {
|
|
1802
|
+
if (node.props[prop] === void 0) {
|
|
1803
|
+
const rule = layoutRules[node.kind];
|
|
1804
|
+
if (rule?.size_from_axis) {
|
|
1805
|
+
const axis = getStringProp(node, "axis", stringParamDefault(rule, "axis"));
|
|
1806
|
+
const spec = rule.size_from_axis[axis]?.[prop];
|
|
1807
|
+
if (spec === "fill") return "fill";
|
|
1808
|
+
if (typeof spec === "number") return spec;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
return getSizeProp(node, prop);
|
|
1812
|
+
}
|
|
1813
|
+
function sizeResolvableIndependently(nodeId, axis, graph) {
|
|
1814
|
+
const node = graph.irNodeMap.get(nodeId);
|
|
1815
|
+
if (!node) return false;
|
|
1816
|
+
const prop = axis === "horizontal" ? "width" : "height";
|
|
1817
|
+
const intent = getEffectiveSizeIntent(node, prop);
|
|
1818
|
+
if (typeof intent === "number") return true;
|
|
1819
|
+
if (intent === "fill") {
|
|
1820
|
+
const parentId = graph.parentMap.get(nodeId);
|
|
1821
|
+
if (!parentId) return false;
|
|
1822
|
+
return parentAvailableConcrete(parentId, axis, graph);
|
|
1823
|
+
}
|
|
1824
|
+
return false;
|
|
1825
|
+
}
|
|
1826
|
+
function parentAvailableConcrete(parentId, axis, graph) {
|
|
1827
|
+
const parentKind = graph.nodeKindMap.get(parentId);
|
|
1828
|
+
if (!parentKind) return false;
|
|
1829
|
+
if (parentKind === "document") return true;
|
|
1830
|
+
const isContainer = parentKind === "box" || parentKind === "group" || parentKind === "overlay" || parentKind === "cell";
|
|
1831
|
+
const isStack = parentKind in MAIN_AXIS_KINDS;
|
|
1832
|
+
if (isContainer || isStack) {
|
|
1833
|
+
return sizeResolvableIndependently(parentId, axis, graph);
|
|
1834
|
+
}
|
|
1835
|
+
return false;
|
|
1836
|
+
}
|
|
1837
|
+
function classifyMainAxisFill(graph, dim, parentId) {
|
|
1838
|
+
const parentKind = graph.nodeKindMap.get(parentId);
|
|
1839
|
+
const parentAxisConfig = parentKind ? STACK_RULE.applies_to?.[parentKind] : void 0;
|
|
1840
|
+
if (!parentAxisConfig || parentAxisConfig.main_size !== dim) return "cross";
|
|
1841
|
+
const axis = dim === "resolvedWidth" ? "horizontal" : "vertical";
|
|
1842
|
+
return sizeResolvableIndependently(parentId, axis, graph) ? "distributed" : "circular";
|
|
1843
|
+
}
|
|
1844
|
+
function suffixShiftSlotId(stackId, index) {
|
|
1845
|
+
return slotId(stackId, `suffixShift.${index}`);
|
|
1846
|
+
}
|
|
1847
|
+
function stackMainAxisContext(targetId, localSlot, graph) {
|
|
1848
|
+
const parentId = graph.parentMap.get(targetId);
|
|
1849
|
+
if (!parentId) return null;
|
|
1850
|
+
const parentKind = graph.nodeKindMap.get(parentId);
|
|
1851
|
+
if (!parentKind) return null;
|
|
1852
|
+
const mainAxis = MAIN_AXIS_KINDS[parentKind];
|
|
1853
|
+
if (!mainAxis || mainAxis !== localSlot) return null;
|
|
1854
|
+
const order = graph.childrenOrderMap.get(parentId);
|
|
1855
|
+
if (!order) return null;
|
|
1856
|
+
const index = order.indexOf(targetId);
|
|
1857
|
+
if (index < 0) return null;
|
|
1858
|
+
return { stackId: parentId, index };
|
|
1859
|
+
}
|
|
1860
|
+
function pickReferenceTarget(targets, localSlot, graph, anchorProp, moverProp) {
|
|
1861
|
+
if (anchorProp) {
|
|
1862
|
+
return {
|
|
1863
|
+
reference: anchorProp,
|
|
1864
|
+
movers: targets.filter((t) => t !== anchorProp)
|
|
1865
|
+
};
|
|
1866
|
+
}
|
|
1867
|
+
if (moverProp) {
|
|
1868
|
+
const reference2 = targets.find((t) => t !== moverProp) ?? targets[0];
|
|
1869
|
+
return { reference: reference2, movers: [moverProp] };
|
|
1870
|
+
}
|
|
1871
|
+
const scored = targets.map((t) => ({ id: t, score: computeFreedomScore(t, localSlot, graph) }));
|
|
1872
|
+
const allMainAxis = scored.every((s) => s.score === 0);
|
|
1873
|
+
if (allMainAxis) {
|
|
1874
|
+
const stackParents = new Set(
|
|
1875
|
+
targets.map((t) => graph.parentMap.get(t)).filter((p) => p !== void 0)
|
|
1876
|
+
);
|
|
1877
|
+
if (stackParents.size === 1) {
|
|
1878
|
+
const stackId = [...stackParents][0];
|
|
1879
|
+
const order = graph.childrenOrderMap.get(stackId);
|
|
1880
|
+
if (order) {
|
|
1881
|
+
let maxIdx = -1;
|
|
1882
|
+
let reference2 = targets[0];
|
|
1883
|
+
for (const t of targets) {
|
|
1884
|
+
const idx = order.indexOf(t);
|
|
1885
|
+
if (idx > maxIdx) {
|
|
1886
|
+
maxIdx = idx;
|
|
1887
|
+
reference2 = t;
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
return { reference: reference2, movers: targets.filter((t) => t !== reference2) };
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
scored.sort((a, b) => a.score - b.score);
|
|
1895
|
+
const reference = scored[0].id;
|
|
1896
|
+
return { reference, movers: scored.slice(1).map((s) => s.id) };
|
|
1897
|
+
}
|
|
1898
|
+
function computeFreedomScore(targetId, localSlot, graph) {
|
|
1899
|
+
const parentId = graph.parentMap.get(targetId);
|
|
1900
|
+
if (!parentId) return 4;
|
|
1901
|
+
const parentKind = graph.nodeKindMap.get(parentId);
|
|
1902
|
+
if (!parentKind) return 4;
|
|
1903
|
+
if (parentKind === "document") return 4;
|
|
1904
|
+
if (parentKind === "absolute") return 3;
|
|
1905
|
+
const mainAxis = MAIN_AXIS_KINDS[parentKind];
|
|
1906
|
+
if (mainAxis) {
|
|
1907
|
+
return mainAxis === localSlot ? 0 : 2;
|
|
1908
|
+
}
|
|
1909
|
+
if (parentKind === "table" || parentKind === "cell" || parentKind === "grid") return 0;
|
|
1910
|
+
if (parentKind === "overlay") return 1;
|
|
1911
|
+
return 2;
|
|
1912
|
+
}
|
|
1913
|
+
function describeFreedomContext(targetId, localSlot, graph) {
|
|
1914
|
+
const parentId = graph.parentMap.get(targetId);
|
|
1915
|
+
if (!parentId) return "root child";
|
|
1916
|
+
const parentKind = graph.nodeKindMap.get(parentId) ?? "unknown";
|
|
1917
|
+
const mainAxis = MAIN_AXIS_KINDS[parentKind];
|
|
1918
|
+
if (mainAxis && mainAxis === localSlot) {
|
|
1919
|
+
return `main-axis child of ${parentKind}(${parentId})`;
|
|
1920
|
+
}
|
|
1921
|
+
if (mainAxis && mainAxis !== localSlot) {
|
|
1922
|
+
return `cross-axis child of ${parentKind}(${parentId})`;
|
|
1923
|
+
}
|
|
1924
|
+
return `child of ${parentKind}(${parentId})`;
|
|
1925
|
+
}
|
|
1926
|
+
function collectPathLocalSlots(fromId, toAncestorId, localSlotKind, graph) {
|
|
1927
|
+
const slots = [];
|
|
1928
|
+
let current = fromId;
|
|
1929
|
+
while (current !== toAncestorId) {
|
|
1930
|
+
ensureSlot(graph, current, localSlotKind);
|
|
1931
|
+
slots.push(slotId(current, localSlotKind));
|
|
1932
|
+
const parent = graph.parentMap.get(current);
|
|
1933
|
+
if (!parent) break;
|
|
1934
|
+
current = parent;
|
|
1935
|
+
}
|
|
1936
|
+
return slots;
|
|
1937
|
+
}
|
|
1938
|
+
function applyWorldAlign(rule, node, graph) {
|
|
1939
|
+
const targets = node.props.targets;
|
|
1940
|
+
if (!targets || targets.length < 2) return;
|
|
1941
|
+
const axis = getStringProp(node, "axis", CONSTRAINT_DEFAULTS.alignAxis);
|
|
1942
|
+
const alignMode = getStringProp(node, "align", CONSTRAINT_DEFAULTS.alignMode);
|
|
1943
|
+
const strength = node.props.strength ?? rule.default_priority;
|
|
1944
|
+
const mapping = rule.axis_mapping;
|
|
1945
|
+
if (!mapping) return;
|
|
1946
|
+
const axisMap = mapping[axis];
|
|
1947
|
+
if (!axisMap) return;
|
|
1948
|
+
const { world_slot: worldSlot, local_slot: localSlot, size_slot: sizeSlot } = axisMap;
|
|
1949
|
+
let reference;
|
|
1950
|
+
let movers;
|
|
1951
|
+
const anchorProp = node.props.anchor;
|
|
1952
|
+
const moverProp = node.props.mover;
|
|
1953
|
+
if (anchorProp) {
|
|
1954
|
+
if (!targets.includes(anchorProp)) {
|
|
1955
|
+
graph.diagnostics.push({
|
|
1956
|
+
level: "error",
|
|
1957
|
+
message: `AlignConstraint(${node.id}): anchor="${anchorProp}" is not in targets [${targets.join(", ")}].`,
|
|
1958
|
+
path: node.id ?? ""
|
|
1959
|
+
/* fallback-ok: diagnostic path label; constraint nodes without an explicit id fall back to an empty path */
|
|
1960
|
+
});
|
|
1961
|
+
return;
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
({ reference, movers } = pickReferenceTarget(targets, localSlot, graph, anchorProp, moverProp));
|
|
1965
|
+
if (moverProp) {
|
|
1966
|
+
const score = computeFreedomScore(moverProp, localSlot, graph);
|
|
1967
|
+
if (score <= 0) {
|
|
1968
|
+
graph.diagnostics.push({
|
|
1969
|
+
level: "warning",
|
|
1970
|
+
message: `AlignConstraint(${node.id}): mover="${moverProp}" is ${describeFreedomContext(moverProp, localSlot, graph)}. Aligning may break sibling layout.`,
|
|
1971
|
+
path: node.id ?? ""
|
|
1972
|
+
/* fallback-ok: diagnostic path label; constraint nodes without an explicit id fall back to an empty path */
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
} else if (!anchorProp) {
|
|
1976
|
+
const scored = targets.map((t) => ({ id: t, score: computeFreedomScore(t, localSlot, graph) }));
|
|
1977
|
+
const allLow = scored.every((s) => s.score <= 0);
|
|
1978
|
+
const allMainAxis = scored.every((s) => s.score === 0);
|
|
1979
|
+
const sameStackAllMain = allMainAxis && new Set(targets.map((t) => graph.parentMap.get(t))).size === 1;
|
|
1980
|
+
if (allLow && !sameStackAllMain) {
|
|
1981
|
+
graph.diagnostics.push({
|
|
1982
|
+
level: "warning",
|
|
1983
|
+
message: `AlignConstraint(${node.id}): all targets have low freedom on ${localSlot}. Alignment may break sibling layout. ` + targets.map((t) => `${t} is ${describeFreedomContext(t, localSlot, graph)}`).join("; ") + ".",
|
|
1984
|
+
path: node.id ?? ""
|
|
1985
|
+
/* fallback-ok: diagnostic path label; constraint nodes without an explicit id fall back to an empty path */
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
const alignRefs = node.props.alignRefs ?? {};
|
|
1990
|
+
const refMeasure = alignRefs[reference] ?? reference;
|
|
1991
|
+
ensureSlot(graph, refMeasure, worldSlot);
|
|
1992
|
+
if (alignMode !== "start") {
|
|
1993
|
+
ensureSlot(graph, refMeasure, sizeSlot);
|
|
1994
|
+
}
|
|
1995
|
+
for (const moverId of movers) {
|
|
1996
|
+
const moverParentId = graph.parentMap.get(moverId);
|
|
1997
|
+
if (!moverParentId) continue;
|
|
1998
|
+
const moverMeasure = alignRefs[moverId] ?? moverId;
|
|
1999
|
+
const stackCtx = stackMainAxisContext(moverId, localSlot, graph);
|
|
2000
|
+
const refStackCtx = stackMainAxisContext(reference, localSlot, graph);
|
|
2001
|
+
const hasMoverPath = moverMeasure !== moverId;
|
|
2002
|
+
const useSuffixShift = stackCtx !== null && !hasMoverPath && (refStackCtx === null || refStackCtx.stackId === stackCtx.stackId || anchorProp !== void 0);
|
|
2003
|
+
if (useSuffixShift && stackCtx) {
|
|
2004
|
+
applySuffixShiftAlign(
|
|
2005
|
+
graph,
|
|
2006
|
+
node,
|
|
2007
|
+
moverId,
|
|
2008
|
+
stackCtx.stackId,
|
|
2009
|
+
stackCtx.index,
|
|
2010
|
+
refMeasure,
|
|
2011
|
+
moverMeasure,
|
|
2012
|
+
alignMode,
|
|
2013
|
+
strength,
|
|
2014
|
+
worldSlot,
|
|
2015
|
+
baseMainSlot(localSlot),
|
|
2016
|
+
sizeSlot,
|
|
2017
|
+
localSlot
|
|
2018
|
+
);
|
|
2019
|
+
continue;
|
|
2020
|
+
}
|
|
2021
|
+
ensureSlot(graph, moverParentId, worldSlot);
|
|
2022
|
+
ensureSlot(graph, moverId, localSlot);
|
|
2023
|
+
const opId = `op.${node.kind}.${node.id}.${moverId}.${localSlot}`;
|
|
2024
|
+
const outputSlotId = slotId(moverId, localSlot);
|
|
2025
|
+
const inputSlots = [
|
|
2026
|
+
slotId(refMeasure, worldSlot),
|
|
2027
|
+
slotId(moverParentId, worldSlot)
|
|
2028
|
+
];
|
|
2029
|
+
const localSlotKind = localSlot;
|
|
2030
|
+
if (alignMode === "center" || alignMode === "end") {
|
|
2031
|
+
ensureSlot(graph, refMeasure, sizeSlot);
|
|
2032
|
+
inputSlots.push(slotId(refMeasure, sizeSlot));
|
|
2033
|
+
if (moverMeasure === moverId) {
|
|
2034
|
+
ensureSlot(graph, moverId, sizeSlot);
|
|
2035
|
+
inputSlots.push(slotId(moverId, sizeSlot));
|
|
2036
|
+
} else {
|
|
2037
|
+
const pathLocalYSlots = collectPathLocalSlots(
|
|
2038
|
+
moverMeasure,
|
|
2039
|
+
moverId,
|
|
2040
|
+
localSlotKind,
|
|
2041
|
+
graph
|
|
2042
|
+
);
|
|
2043
|
+
ensureSlot(graph, moverMeasure, sizeSlot);
|
|
2044
|
+
for (const s of pathLocalYSlots) inputSlots.push(s);
|
|
2045
|
+
inputSlots.push(slotId(moverMeasure, sizeSlot));
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
addCandidate(graph, outputSlotId, void 0, `${node.kind}(${node.id})`, strength, opId);
|
|
2049
|
+
addOperation(graph, opId, "alignDelta", inputSlots, [outputSlotId], (inputs) => {
|
|
2050
|
+
const refWorld = num(inputs[0]);
|
|
2051
|
+
const moverParentWorld = num(inputs[1]);
|
|
2052
|
+
if (alignMode === "center") {
|
|
2053
|
+
const refSize = num(inputs[2]);
|
|
2054
|
+
const refCenter = refWorld + refSize / 2;
|
|
2055
|
+
if (!hasMoverPath) {
|
|
2056
|
+
const moverSize = num(inputs[3]);
|
|
2057
|
+
return [refCenter - moverParentWorld - moverSize / 2];
|
|
2058
|
+
}
|
|
2059
|
+
const pathSlots = inputs.slice(3, -1);
|
|
2060
|
+
const moverMeasureSize = num(inputs[inputs.length - 1]);
|
|
2061
|
+
const internalOffset = pathSlots.reduce((sum, v) => sum + num(v), 0) + moverMeasureSize / 2;
|
|
2062
|
+
return [refCenter - moverParentWorld - internalOffset];
|
|
2063
|
+
}
|
|
2064
|
+
if (alignMode === "end") {
|
|
2065
|
+
const refSize = num(inputs[2]);
|
|
2066
|
+
const refEnd = refWorld + refSize;
|
|
2067
|
+
if (!hasMoverPath) {
|
|
2068
|
+
const moverSize = num(inputs[3]);
|
|
2069
|
+
return [refEnd - moverParentWorld - moverSize];
|
|
2070
|
+
}
|
|
2071
|
+
const pathSlots = inputs.slice(3, -1);
|
|
2072
|
+
const moverMeasureSize = num(inputs[inputs.length - 1]);
|
|
2073
|
+
const internalOffset = pathSlots.reduce((sum, v) => sum + num(v), 0) + moverMeasureSize;
|
|
2074
|
+
return [refEnd - moverParentWorld - internalOffset];
|
|
2075
|
+
}
|
|
2076
|
+
return [refWorld - moverParentWorld];
|
|
2077
|
+
});
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
function applySuffixShiftAlign(graph, node, moverId, stackId, index, refMeasure, moverMeasure, alignMode, strength, worldSlot, baseMainSlotKind, sizeSlot, _localSlot) {
|
|
2081
|
+
const ssSlotId = suffixShiftSlotId(stackId, index);
|
|
2082
|
+
ensureSlot(graph, stackId, `suffixShift.${index}`);
|
|
2083
|
+
addResolver(graph, ssSlotId, "max");
|
|
2084
|
+
ensureSlot(graph, refMeasure, worldSlot);
|
|
2085
|
+
ensureSlot(graph, stackId, worldSlot);
|
|
2086
|
+
ensureSlot(graph, moverId, baseMainSlotKind);
|
|
2087
|
+
const opId = `op.${node.kind}.${node.id}.${moverId}.suffixShift`;
|
|
2088
|
+
addCandidate(graph, ssSlotId, void 0, `${node.kind}(${node.id}).suffix`, strength, opId);
|
|
2089
|
+
const inputSlots = [
|
|
2090
|
+
slotId(refMeasure, worldSlot),
|
|
2091
|
+
slotId(stackId, worldSlot),
|
|
2092
|
+
slotId(moverId, baseMainSlotKind)
|
|
2093
|
+
];
|
|
2094
|
+
if (alignMode === "center" || alignMode === "end") {
|
|
2095
|
+
ensureSlot(graph, refMeasure, sizeSlot);
|
|
2096
|
+
inputSlots.push(slotId(refMeasure, sizeSlot));
|
|
2097
|
+
ensureSlot(graph, moverMeasure, sizeSlot);
|
|
2098
|
+
inputSlots.push(slotId(moverMeasure, sizeSlot));
|
|
2099
|
+
}
|
|
2100
|
+
addOperation(graph, opId, "suffixShiftDelta", inputSlots, [ssSlotId], (inputs) => {
|
|
2101
|
+
const refWorld = num(inputs[0]);
|
|
2102
|
+
const stackWorld = num(inputs[1]);
|
|
2103
|
+
const baseLocal = num(inputs[2]);
|
|
2104
|
+
let delta;
|
|
2105
|
+
if (alignMode === "center") {
|
|
2106
|
+
const refSize = num(inputs[3]);
|
|
2107
|
+
const moverSize = num(inputs[4]);
|
|
2108
|
+
delta = refWorld + refSize / 2 - stackWorld - baseLocal - moverSize / 2;
|
|
2109
|
+
} else if (alignMode === "end") {
|
|
2110
|
+
const refSize = num(inputs[3]);
|
|
2111
|
+
const moverSize = num(inputs[4]);
|
|
2112
|
+
delta = refWorld + refSize - stackWorld - baseLocal - moverSize;
|
|
2113
|
+
} else {
|
|
2114
|
+
delta = refWorld - stackWorld - baseLocal;
|
|
2115
|
+
}
|
|
2116
|
+
return [Math.max(0, delta)];
|
|
2117
|
+
});
|
|
2118
|
+
}
|
|
2119
|
+
function applyEqualize(rule, node, graph) {
|
|
2120
|
+
const targets = node.props.targets;
|
|
2121
|
+
if (!targets || targets.length < 2) return;
|
|
2122
|
+
const strength = node.props.strength ?? rule.default_priority;
|
|
2123
|
+
const strategy = getStringProp(node, "strategy", rule.default_strategy ?? CONSTRAINT_DEFAULTS.equalizeStrategy);
|
|
2124
|
+
const outputSlotName = rule.slot;
|
|
2125
|
+
const inputSlotName = rule.content_slot;
|
|
2126
|
+
if (!outputSlotName || !inputSlotName) return;
|
|
2127
|
+
const constraintId = node.id;
|
|
2128
|
+
const aggSlotId = `${constraintId}._agg`;
|
|
2129
|
+
ensureSlot(graph, constraintId, "_agg");
|
|
2130
|
+
const gatherOpId = `op.${node.kind}.${constraintId}.gather`;
|
|
2131
|
+
const gatherInputs = [];
|
|
2132
|
+
for (const targetId of targets) {
|
|
2133
|
+
ensureSlot(graph, targetId, inputSlotName);
|
|
2134
|
+
gatherInputs.push(slotId(targetId, inputSlotName));
|
|
2135
|
+
}
|
|
2136
|
+
addCandidate(graph, aggSlotId, void 0, `${node.kind}(${constraintId}).agg`, "required", gatherOpId);
|
|
2137
|
+
addOperation(graph, gatherOpId, strategy, gatherInputs, [aggSlotId], (inputs) => {
|
|
2138
|
+
const vals = inputs.map((v) => num(v));
|
|
2139
|
+
switch (strategy) {
|
|
2140
|
+
case "min":
|
|
2141
|
+
return [Math.min(...vals)];
|
|
2142
|
+
case "first":
|
|
2143
|
+
return [num(vals[0])];
|
|
2144
|
+
default:
|
|
2145
|
+
return [Math.max(...vals)];
|
|
2146
|
+
}
|
|
2147
|
+
});
|
|
2148
|
+
const distributeOpId = `op.${node.kind}.${constraintId}.dist`;
|
|
2149
|
+
const distributeOutputs = [];
|
|
2150
|
+
for (const targetId of targets) {
|
|
2151
|
+
ensureSlot(graph, targetId, outputSlotName);
|
|
2152
|
+
const sid = slotId(targetId, outputSlotName);
|
|
2153
|
+
distributeOutputs.push(sid);
|
|
2154
|
+
addCandidate(graph, sid, void 0, `${node.kind}(${constraintId})`, strength, distributeOpId);
|
|
2155
|
+
}
|
|
2156
|
+
addOperation(graph, distributeOpId, "copy", [aggSlotId], distributeOutputs, (inputs) => {
|
|
2157
|
+
return targets.map(() => num(inputs[0]));
|
|
2158
|
+
});
|
|
2159
|
+
}
|
|
2160
|
+
function applyEnforceOrder(rule, node, graph) {
|
|
2161
|
+
const targets = node.props.targets;
|
|
2162
|
+
if (!targets || targets.length < 2) return;
|
|
2163
|
+
const axis = getStringProp(node, "axis", CONSTRAINT_DEFAULTS.orderAxis);
|
|
2164
|
+
const strength = node.props.strength ?? rule.default_priority;
|
|
2165
|
+
const posSlot = rule.axis_to_slot[axis];
|
|
2166
|
+
const sizeSlot = rule.axis_to_size_slot[axis];
|
|
2167
|
+
for (let i = 1; i < targets.length; i++) {
|
|
2168
|
+
const prev = targets[i - 1];
|
|
2169
|
+
const curr = targets[i];
|
|
2170
|
+
ensureSlot(graph, prev, posSlot);
|
|
2171
|
+
ensureSlot(graph, prev, sizeSlot);
|
|
2172
|
+
ensureSlot(graph, curr, posSlot);
|
|
2173
|
+
const opId = `op.order.${node.id}.${i}`;
|
|
2174
|
+
const inputSlots = [`${prev}.${posSlot}`, `${prev}.${sizeSlot}`];
|
|
2175
|
+
const outputSlotId = `${curr}.${posSlot}`;
|
|
2176
|
+
addCandidate(graph, outputSlotId, void 0, `order(${node.id})`, strength, opId);
|
|
2177
|
+
addOperation(graph, opId, "identity", inputSlots, [outputSlotId], (inputs) => {
|
|
2178
|
+
const prevPos = num(inputs[0]);
|
|
2179
|
+
const prevSize = num(inputs[1]);
|
|
2180
|
+
return [prevPos + prevSize];
|
|
2181
|
+
});
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
function applyEnforceMinGap(rule, node, graph) {
|
|
2185
|
+
const targets = node.props.targets;
|
|
2186
|
+
if (!targets || targets.length < 2) return;
|
|
2187
|
+
const axis = getStringProp(node, "axis", CONSTRAINT_DEFAULTS.orderAxis);
|
|
2188
|
+
const strength = node.props.strength ?? rule.default_priority;
|
|
2189
|
+
const posSlot = rule.axis_to_position_slot[axis];
|
|
2190
|
+
const sizeSlot = rule.axis_to_size_slot[axis];
|
|
2191
|
+
const minGap = getNumericProp(node, rule.min_gap_from, 0);
|
|
2192
|
+
for (let i = 1; i < targets.length; i++) {
|
|
2193
|
+
const prev = targets[i - 1];
|
|
2194
|
+
const curr = targets[i];
|
|
2195
|
+
ensureSlot(graph, prev, posSlot);
|
|
2196
|
+
ensureSlot(graph, prev, sizeSlot);
|
|
2197
|
+
ensureSlot(graph, curr, posSlot);
|
|
2198
|
+
const opId = `op.gap.${node.id}.${i}`;
|
|
2199
|
+
const inputSlots = [`${prev}.${posSlot}`, `${prev}.${sizeSlot}`];
|
|
2200
|
+
const outputSlotId = `${curr}.${posSlot}`;
|
|
2201
|
+
addCandidate(graph, outputSlotId, void 0, `gap(${node.id})`, strength, opId);
|
|
2202
|
+
addOperation(graph, opId, "identity", inputSlots, [outputSlotId], (inputs) => {
|
|
2203
|
+
const prevPos = num(inputs[0]);
|
|
2204
|
+
const prevSize = num(inputs[1]);
|
|
2205
|
+
return [prevPos + prevSize + minGap];
|
|
2206
|
+
});
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
function applyClampInside(rule, node, graph) {
|
|
2210
|
+
const targets = node.props.targets;
|
|
2211
|
+
if (!targets || targets.length < 2) return;
|
|
2212
|
+
const strength = node.props.strength ?? rule.default_priority;
|
|
2213
|
+
const containerId = targets[0];
|
|
2214
|
+
const contentIds = targets.slice(1);
|
|
2215
|
+
for (const contentId of contentIds) {
|
|
2216
|
+
for (let pi = 0; pi < rule.position_slots.length; pi++) {
|
|
2217
|
+
const posSlot = rule.position_slots[pi];
|
|
2218
|
+
const sizeSlot = rule.size_slots[pi];
|
|
2219
|
+
const containerSizeSlot = sizeSlot;
|
|
2220
|
+
ensureSlot(graph, containerId, containerSizeSlot);
|
|
2221
|
+
ensureSlot(graph, contentId, posSlot);
|
|
2222
|
+
ensureSlot(graph, contentId, sizeSlot);
|
|
2223
|
+
const opId = `op.keepInside.${node.id}.${contentId}.${posSlot}`;
|
|
2224
|
+
const inputSlots = [
|
|
2225
|
+
`${containerId}.${containerSizeSlot}`,
|
|
2226
|
+
`${contentId}.${posSlot}`,
|
|
2227
|
+
`${contentId}.${sizeSlot}`
|
|
2228
|
+
];
|
|
2229
|
+
const outputSlotId = `${contentId}.${posSlot}`;
|
|
2230
|
+
addCandidate(graph, outputSlotId, void 0, `keepInside(${node.id})`, strength, opId);
|
|
2231
|
+
addOperation(graph, opId, "clamp", inputSlots, [outputSlotId], (inputs) => {
|
|
2232
|
+
const containerSize = num(inputs[0]);
|
|
2233
|
+
const currentPos = num(inputs[1]);
|
|
2234
|
+
const contentSize = num(inputs[2]);
|
|
2235
|
+
const maxPos = containerSize - contentSize;
|
|
2236
|
+
return [Math.max(0, Math.min(currentPos, maxPos))];
|
|
2237
|
+
});
|
|
2238
|
+
}
|
|
2229
2239
|
}
|
|
2230
|
-
return map;
|
|
2231
2240
|
}
|
|
2232
|
-
|
|
2233
|
-
|
|
2241
|
+
var CONSTRAINT_HANDLERS = {
|
|
2242
|
+
world_align: applyWorldAlign,
|
|
2243
|
+
equalize: applyEqualize,
|
|
2244
|
+
enforce_order: applyEnforceOrder,
|
|
2245
|
+
enforce_min_gap: applyEnforceMinGap,
|
|
2246
|
+
clamp_inside: applyClampInside
|
|
2247
|
+
};
|
|
2248
|
+
function applyConstraintFromRule(kind, node, graph) {
|
|
2249
|
+
const rule = constraintRules[kind];
|
|
2250
|
+
if (!rule) return false;
|
|
2251
|
+
const handler = CONSTRAINT_HANDLERS[rule.operation];
|
|
2252
|
+
if (!handler) return false;
|
|
2253
|
+
handler(rule, node, graph);
|
|
2254
|
+
return true;
|
|
2234
2255
|
}
|
|
2235
|
-
var
|
|
2236
|
-
function
|
|
2237
|
-
|
|
2238
|
-
return _allowedPropsMap.get(kind);
|
|
2256
|
+
var textMeasurer = new SimpleTextMeasurer();
|
|
2257
|
+
function setTextMeasurer(m) {
|
|
2258
|
+
textMeasurer = m;
|
|
2239
2259
|
}
|
|
2240
|
-
function
|
|
2241
|
-
const
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2260
|
+
function applyRootRule(rule, node, graph) {
|
|
2261
|
+
const id = node.id;
|
|
2262
|
+
const width = getNumericProp(node, "width", numericParamDefault(rule, "width"));
|
|
2263
|
+
const height = getNumericProp(node, "height", numericParamDefault(rule, "height"));
|
|
2264
|
+
const padding = getNumericProp(node, "padding", numericParamDefault(rule, "padding"));
|
|
2265
|
+
ensureSlot(graph, id, "resolvedWidth", width);
|
|
2266
|
+
ensureSlot(graph, id, "resolvedHeight", height);
|
|
2267
|
+
ensureSlot(graph, id, "availableWidth", width - padding * 2);
|
|
2268
|
+
ensureSlot(graph, id, "availableHeight", height - padding * 2);
|
|
2269
|
+
addCandidate(graph, slotId(id, "resolvedWidth"), width, "document(explicit)", "required");
|
|
2270
|
+
addCandidate(graph, slotId(id, "resolvedHeight"), height, "document(explicit)", "required");
|
|
2271
|
+
if (node.children) {
|
|
2272
|
+
for (const child of node.children) {
|
|
2273
|
+
if (child.id && !isConstraintKind(child.kind)) {
|
|
2274
|
+
ensureSlot(graph, child.id, "localX");
|
|
2275
|
+
ensureSlot(graph, child.id, "localY");
|
|
2276
|
+
addCandidate(graph, slotId(child.id, "localX"), padding, `document(${id}).origin`, "weak");
|
|
2277
|
+
addCandidate(graph, slotId(child.id, "localY"), padding, `document(${id}).origin`, "weak");
|
|
2278
|
+
}
|
|
2247
2279
|
}
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
function applyStackRule(rule, axisConfig, kindName, node, graph, parentId) {
|
|
2283
|
+
const id = node.id;
|
|
2284
|
+
const gap = getNumericProp(node, "gap", numericParamDefault(rule, "gap"));
|
|
2285
|
+
const padding = getNumericProp(node, "padding", numericParamDefault(rule, "padding"));
|
|
2286
|
+
const children = childrenOf(node);
|
|
2287
|
+
registerSizeSlots(node, graph, parentId);
|
|
2288
|
+
ensureSlot(graph, id, "contentWidth");
|
|
2289
|
+
ensureSlot(graph, id, "contentHeight");
|
|
2290
|
+
const childIds = children.filter((c) => !isConstraintKind(c.kind)).map((c) => c.id);
|
|
2291
|
+
if (childIds.length === 0) return;
|
|
2292
|
+
graph.childrenOrderMap.set(id, childIds);
|
|
2293
|
+
const mainSlot = axisConfig.main_slot;
|
|
2294
|
+
const crossSlot = axisConfig.cross_slot;
|
|
2295
|
+
const mainSize = axisConfig.main_size;
|
|
2296
|
+
const crossSize = axisConfig.cross_size;
|
|
2297
|
+
const contentMainSize = axisConfig.content_main_size;
|
|
2298
|
+
const contentCrossSize = axisConfig.content_cross_size;
|
|
2299
|
+
const baseMain = baseMainSlot(mainSlot);
|
|
2300
|
+
const opId = `op.${kindName}.${id}`;
|
|
2301
|
+
const inputSlots = [];
|
|
2302
|
+
for (const childId of childIds) {
|
|
2303
|
+
ensureSlot(graph, childId, mainSize);
|
|
2304
|
+
ensureSlot(graph, childId, crossSize);
|
|
2305
|
+
ensureSlot(graph, childId, baseMain);
|
|
2306
|
+
ensureSlot(graph, childId, crossSlot);
|
|
2307
|
+
inputSlots.push(slotId(childId, mainSize));
|
|
2308
|
+
}
|
|
2309
|
+
const baseOutputs = [
|
|
2310
|
+
...childIds.map((cid) => slotId(cid, baseMain)),
|
|
2311
|
+
slotId(id, contentMainSize),
|
|
2312
|
+
slotId(id, mainSize)
|
|
2313
|
+
];
|
|
2314
|
+
for (const cid of childIds) {
|
|
2315
|
+
addCandidate(graph, slotId(cid, baseMain), void 0, `${kindName}(${id})`, "strong", opId);
|
|
2316
|
+
}
|
|
2317
|
+
addCandidate(graph, slotId(id, contentMainSize), void 0, `${kindName}(${id}).content`, "strong", opId);
|
|
2318
|
+
addCandidate(graph, slotId(id, mainSize), void 0, `${kindName}(${id}).wrap`, "normal", opId);
|
|
2319
|
+
addOperation(graph, opId, "stackPosition", inputSlots, baseOutputs, (inputs) => {
|
|
2320
|
+
let pos = padding;
|
|
2321
|
+
const positions = [];
|
|
2322
|
+
for (let i = 0; i < inputs.length; i++) {
|
|
2323
|
+
positions.push(pos);
|
|
2324
|
+
pos += inputs[i] + (i < inputs.length - 1 ? gap : 0);
|
|
2252
2325
|
}
|
|
2326
|
+
const contentMain = pos - padding;
|
|
2327
|
+
const totalMain = contentMain + padding * 2;
|
|
2328
|
+
return [...positions, contentMain, totalMain];
|
|
2329
|
+
});
|
|
2330
|
+
const suffixShiftSlotIds = [];
|
|
2331
|
+
for (let i = 0; i < childIds.length; i++) {
|
|
2332
|
+
const ssId = suffixShiftSlotId(id, i);
|
|
2333
|
+
ensureSlot(graph, id, `suffixShift.${i}`);
|
|
2334
|
+
addCandidate(graph, ssId, 0, `${kindName}(${id}).suffixShift.${i}`, "weak");
|
|
2335
|
+
addResolver(graph, ssId, "max");
|
|
2336
|
+
suffixShiftSlotIds.push(ssId);
|
|
2253
2337
|
}
|
|
2254
|
-
|
|
2255
|
-
|
|
2338
|
+
const composeOpId = `op.${kindName}.compose.${id}`;
|
|
2339
|
+
const composeInputs = [
|
|
2340
|
+
...childIds.map((cid) => slotId(cid, baseMain)),
|
|
2341
|
+
...suffixShiftSlotIds
|
|
2342
|
+
];
|
|
2343
|
+
const composeOutputs = childIds.map((cid) => slotId(cid, mainSlot));
|
|
2344
|
+
for (const cid of childIds) {
|
|
2345
|
+
addCandidate(graph, slotId(cid, mainSlot), void 0, `${kindName}(${id}).compose`, "strong", composeOpId);
|
|
2256
2346
|
}
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
}
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2347
|
+
addOperation(graph, composeOpId, "stackCompose", composeInputs, composeOutputs, (inputs) => {
|
|
2348
|
+
const n = childIds.length;
|
|
2349
|
+
const bases = inputs.slice(0, n);
|
|
2350
|
+
const shifts = inputs.slice(n, n + n);
|
|
2351
|
+
let runningMax = 0;
|
|
2352
|
+
const result = [];
|
|
2353
|
+
for (let j = 0; j < n; j++) {
|
|
2354
|
+
runningMax = Math.max(runningMax, num(shifts[j]));
|
|
2355
|
+
result.push(num(bases[j]) + runningMax);
|
|
2356
|
+
}
|
|
2357
|
+
return result;
|
|
2358
|
+
});
|
|
2359
|
+
const mainPropName = mainSize === "resolvedWidth" ? "width" : "height";
|
|
2360
|
+
const mainAxis = mainSize === "resolvedWidth" ? "horizontal" : "vertical";
|
|
2361
|
+
const selfMainIntent = getSizeProp(node, mainPropName);
|
|
2362
|
+
const mainSizeResolvable = sizeResolvableIndependently(id, mainAxis, graph);
|
|
2363
|
+
const contentChildrenList = children.filter((c) => !isConstraintKind(c.kind));
|
|
2364
|
+
const mainFillChildIndices = [];
|
|
2365
|
+
for (let i = 0; i < childIds.length; i++) {
|
|
2366
|
+
if (getEffectiveSizeIntent(contentChildrenList[i], mainPropName) === "fill") {
|
|
2367
|
+
mainFillChildIndices.push(i);
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
const ownedByParentMain = selfMainIntent === "fill" && parentId ? classifyMainAxisFill(graph, mainSize, parentId) === "distributed" : false;
|
|
2371
|
+
const resolvableSlot = slotId(id, "stackMainResolvable");
|
|
2372
|
+
if (mainSizeResolvable && (selfMainIntent === "fill" || mainFillChildIndices.length > 0)) {
|
|
2373
|
+
ensureSlot(graph, id, "stackMainResolvable");
|
|
2374
|
+
const resolveMainOpId = `op.${kindName}.mainResolve.${id}`;
|
|
2375
|
+
if (typeof selfMainIntent === "number") {
|
|
2376
|
+
addCandidate(graph, resolvableSlot, void 0, `${kindName}(${id}).mainResolve`, "strong", resolveMainOpId);
|
|
2377
|
+
addOperation(graph, resolveMainOpId, "resolveSize", [], [resolvableSlot], () => [selfMainIntent]);
|
|
2378
|
+
} else if (!ownedByParentMain) {
|
|
2379
|
+
const parentAvailMainSlot = mainSize === "resolvedWidth" ? "availableWidth" : "availableHeight";
|
|
2380
|
+
const stackParentId = graph.parentMap.get(id);
|
|
2381
|
+
ensureSlot(graph, stackParentId, parentAvailMainSlot);
|
|
2382
|
+
addCandidate(graph, resolvableSlot, void 0, `${kindName}(${id}).mainResolve`, "strong", resolveMainOpId);
|
|
2383
|
+
addCandidate(graph, slotId(id, mainSize), void 0, `${kindName}(${id}).mainFill`, "strong", resolveMainOpId);
|
|
2384
|
+
addOperation(graph, resolveMainOpId, "resolveSize", [slotId(stackParentId, parentAvailMainSlot)], [resolvableSlot, slotId(id, mainSize)], (inputs) => {
|
|
2385
|
+
const v = num(inputs[0]);
|
|
2386
|
+
return [v, v];
|
|
2387
|
+
});
|
|
2388
|
+
}
|
|
2389
|
+
if (mainFillChildIndices.length > 0) {
|
|
2390
|
+
const distributeOpId = `op.${kindName}.mainDistribute.${id}`;
|
|
2391
|
+
const nonFillMainSlots = [];
|
|
2392
|
+
for (let i = 0; i < childIds.length; i++) {
|
|
2393
|
+
if (!mainFillChildIndices.includes(i)) nonFillMainSlots.push(slotId(childIds[i], mainSize));
|
|
2394
|
+
}
|
|
2395
|
+
const distributeInputs = [resolvableSlot, ...nonFillMainSlots];
|
|
2396
|
+
const distributeOutputs = [];
|
|
2397
|
+
for (const i of mainFillChildIndices) {
|
|
2398
|
+
const childMainSlot = slotId(childIds[i], mainSize);
|
|
2399
|
+
distributeOutputs.push(childMainSlot);
|
|
2400
|
+
addCandidate(graph, childMainSlot, void 0, `${kindName}(${id}).mainFill`, "strong", distributeOpId);
|
|
2401
|
+
const childKind = contentChildrenList[i].kind;
|
|
2402
|
+
if (childKind in MAIN_AXIS_KINDS) {
|
|
2403
|
+
const childResolvableSlot = slotId(childIds[i], "stackMainResolvable");
|
|
2404
|
+
ensureSlot(graph, childIds[i], "stackMainResolvable");
|
|
2405
|
+
distributeOutputs.push(childResolvableSlot);
|
|
2406
|
+
addCandidate(graph, childResolvableSlot, void 0, `${kindName}(${id}).mainFill`, "strong", distributeOpId);
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
const fillCount = mainFillChildIndices.length;
|
|
2410
|
+
const gapCount = childIds.length - 1;
|
|
2411
|
+
const nStructuralOutputs = distributeOutputs.length;
|
|
2412
|
+
addOperation(graph, distributeOpId, "resolveSize", distributeInputs, distributeOutputs, (inputs) => {
|
|
2413
|
+
const stackMain = num(inputs[0]);
|
|
2414
|
+
const nonFillSum = inputs.slice(1).reduce((s, v) => s + num(v), 0);
|
|
2415
|
+
const remaining = stackMain - padding * 2 - gap * gapCount - nonFillSum;
|
|
2416
|
+
const share = Math.max(0, remaining / fillCount);
|
|
2417
|
+
return new Array(nStructuralOutputs).fill(share);
|
|
2418
|
+
});
|
|
2283
2419
|
}
|
|
2284
2420
|
}
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
const
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
if (!mainAxis || mainAxis !== localSlot) return null;
|
|
2297
|
-
const order = graph.childrenOrderMap.get(parentId);
|
|
2298
|
-
if (!order) return null;
|
|
2299
|
-
const index = order.indexOf(targetId);
|
|
2300
|
-
if (index < 0) return null;
|
|
2301
|
-
return { stackId: parentId, index };
|
|
2302
|
-
}
|
|
2303
|
-
function pickReferenceTarget(targets, localSlot, graph, anchorProp, moverProp) {
|
|
2304
|
-
if (anchorProp) {
|
|
2305
|
-
return {
|
|
2306
|
-
reference: anchorProp,
|
|
2307
|
-
movers: targets.filter((t) => t !== anchorProp)
|
|
2308
|
-
};
|
|
2421
|
+
const align = getStringProp(node, "align", stringParamDefault(rule, "align"));
|
|
2422
|
+
const crossPropName = crossSize === "resolvedWidth" ? "width" : "height";
|
|
2423
|
+
const availableCrossSlot = crossSize === "resolvedWidth" ? "availableWidth" : "availableHeight";
|
|
2424
|
+
const availableMainSlot = mainSize === "resolvedWidth" ? "availableWidth" : "availableHeight";
|
|
2425
|
+
const selfCrossIntent = getSizeProp(node, crossPropName);
|
|
2426
|
+
const crossOwnedByParent = selfCrossIntent === "fill" && parentId ? classifyMainAxisFill(graph, crossSize, parentId) === "distributed" : false;
|
|
2427
|
+
const fillChildIndices = /* @__PURE__ */ new Set();
|
|
2428
|
+
for (let i = 0; i < childIds.length; i++) {
|
|
2429
|
+
if (getEffectiveSizeIntent(contentChildrenList[i], crossPropName) === "fill") {
|
|
2430
|
+
fillChildIndices.add(i);
|
|
2431
|
+
}
|
|
2309
2432
|
}
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2433
|
+
const crossInputSlots = [];
|
|
2434
|
+
for (let i = 0; i < childIds.length; i++) {
|
|
2435
|
+
if (!fillChildIndices.has(i)) {
|
|
2436
|
+
crossInputSlots.push(slotId(childIds[i], crossSize));
|
|
2437
|
+
}
|
|
2313
2438
|
}
|
|
2314
|
-
const
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2439
|
+
const maxCrossOpId = `op.${kindName}.maxCross.${id}`;
|
|
2440
|
+
addCandidate(graph, slotId(id, contentCrossSize), void 0, `${kindName}(${id}).contentCross`, "strong", maxCrossOpId);
|
|
2441
|
+
addOperation(graph, maxCrossOpId, "max", crossInputSlots, [slotId(id, contentCrossSize)], (inputs) => {
|
|
2442
|
+
return [inputs.length > 0 ? Math.max(...inputs) : 0];
|
|
2443
|
+
});
|
|
2444
|
+
const wrapCrossOpId = `op.${kindName}.wrapCross.${id}`;
|
|
2445
|
+
addCandidate(graph, slotId(id, crossSize), void 0, `${kindName}(${id}).wrapCross`, "normal", wrapCrossOpId);
|
|
2446
|
+
addOperation(graph, wrapCrossOpId, "resolveSize", [slotId(id, contentCrossSize)], [slotId(id, crossSize)], (inputs) => {
|
|
2447
|
+
return [num(inputs[0]) + padding * 2];
|
|
2448
|
+
});
|
|
2449
|
+
if (selfCrossIntent === "fill" && parentId && !crossOwnedByParent) {
|
|
2450
|
+
const parentAvailSlot = crossSize === "resolvedWidth" ? "availableWidth" : "availableHeight";
|
|
2451
|
+
ensureSlot(graph, parentId, parentAvailSlot);
|
|
2452
|
+
const crossFillOpId = `op.${kindName}.crossFill.${id}`;
|
|
2453
|
+
addCandidate(graph, slotId(id, crossSize), void 0, `${kindName}(${id}).crossFill`, "strong", crossFillOpId);
|
|
2454
|
+
addOperation(graph, crossFillOpId, "resolveSize", [slotId(id, contentCrossSize), slotId(parentId, parentAvailSlot)], [slotId(id, crossSize)], (inputs) => {
|
|
2455
|
+
const contentCross = num(inputs[0]);
|
|
2456
|
+
const parentAvail = num(inputs[1]);
|
|
2457
|
+
return [Math.max(contentCross + padding * 2, parentAvail)];
|
|
2458
|
+
});
|
|
2459
|
+
}
|
|
2460
|
+
ensureSlot(graph, id, availableCrossSlot);
|
|
2461
|
+
ensureSlot(graph, id, availableMainSlot);
|
|
2462
|
+
const availCrossOpId = `op.${kindName}.availCross.${id}`;
|
|
2463
|
+
addCandidate(graph, slotId(id, availableCrossSlot), void 0, `${kindName}(${id}).availCross`, "strong", availCrossOpId);
|
|
2464
|
+
addOperation(graph, availCrossOpId, "resolveSize", [slotId(id, crossSize)], [slotId(id, availableCrossSlot)], (inputs) => {
|
|
2465
|
+
return [Math.max(num(inputs[0]) - padding * 2, 0)];
|
|
2466
|
+
});
|
|
2467
|
+
const availMainOpId = `op.${kindName}.availMain.${id}`;
|
|
2468
|
+
addCandidate(graph, slotId(id, availableMainSlot), void 0, `${kindName}(${id}).availMain`, "strong", availMainOpId);
|
|
2469
|
+
addOperation(graph, availMainOpId, "resolveSize", [slotId(id, mainSize)], [slotId(id, availableMainSlot)], (inputs) => {
|
|
2470
|
+
return [Math.max(num(inputs[0]) - padding * 2, 0)];
|
|
2471
|
+
});
|
|
2472
|
+
const crossAlignOpId = `op.${kindName}.crossAlign.${id}`;
|
|
2473
|
+
const allChildCrossSlots = childIds.map((cid) => slotId(cid, crossSize));
|
|
2474
|
+
const crossAlignInputs = [slotId(id, availableCrossSlot), ...allChildCrossSlots];
|
|
2475
|
+
const crossAlignOutputs = childIds.map((cid) => slotId(cid, crossSlot));
|
|
2476
|
+
for (const cid of childIds) {
|
|
2477
|
+
addCandidate(graph, slotId(cid, crossSlot), void 0, `${kindName}(${id}).crossAlign`, "strong", crossAlignOpId);
|
|
2478
|
+
}
|
|
2479
|
+
addOperation(graph, crossAlignOpId, "crossAlign", crossAlignInputs, crossAlignOutputs, (inputs) => {
|
|
2480
|
+
const availCross = num(inputs[0]);
|
|
2481
|
+
const positions = [];
|
|
2482
|
+
for (let i = 0; i < childIds.length; i++) {
|
|
2483
|
+
const childCross = num(inputs[1 + i]);
|
|
2484
|
+
let crossPos = padding;
|
|
2485
|
+
if (align === "center") {
|
|
2486
|
+
crossPos = padding + (availCross - childCross) / 2;
|
|
2487
|
+
} else if (align === "end") {
|
|
2488
|
+
crossPos = padding + availCross - childCross;
|
|
2334
2489
|
}
|
|
2490
|
+
positions.push(crossPos);
|
|
2335
2491
|
}
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
const reference = scored[0].id;
|
|
2339
|
-
return { reference, movers: scored.slice(1).map((s) => s.id) };
|
|
2492
|
+
return positions;
|
|
2493
|
+
});
|
|
2340
2494
|
}
|
|
2341
|
-
function
|
|
2342
|
-
const
|
|
2343
|
-
if (
|
|
2495
|
+
function rejectMainAxisFill(node, graph, dim, priority, parentId) {
|
|
2496
|
+
const cls = classifyMainAxisFill(graph, dim, parentId);
|
|
2497
|
+
if (cls !== "circular") return cls;
|
|
2498
|
+
const id = node.id;
|
|
2499
|
+
const kind = node.kind;
|
|
2344
2500
|
const parentKind = graph.nodeKindMap.get(parentId);
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
return
|
|
2351
|
-
}
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2501
|
+
const dimName = dim === "resolvedWidth" ? "width" : "height";
|
|
2502
|
+
const rule = layoutRules[kind];
|
|
2503
|
+
const hint = rule?.size_from_axis ? (() => {
|
|
2504
|
+
const axis = getStringProp(node, "axis", stringParamDefault(rule, "axis"));
|
|
2505
|
+
const otherAxis = axis === "horizontal" ? "vertical" : "horizontal";
|
|
2506
|
+
return ` (axis="${axis}") \u2014 use axis="${otherAxis}" or give the ${kind} a fixed-size container`;
|
|
2507
|
+
})() : ` \u2014 give the ${kind} a fixed ${dimName} or place it in a fixed-size container`;
|
|
2508
|
+
graph.diagnostics.push({
|
|
2509
|
+
level: "error",
|
|
2510
|
+
message: `${kind} '${id}' fills its ${dimName} along the stacking axis of ${parentKind} '${parentId}'; a stack's main-axis size is the sum of its children, so this fill is circular and has no defined size${hint}`,
|
|
2511
|
+
path: id
|
|
2512
|
+
});
|
|
2513
|
+
addCandidate(graph, slotId(id, dim), 0, `${kind}(${id}).fill-error`, priority);
|
|
2514
|
+
return "circular";
|
|
2355
2515
|
}
|
|
2356
|
-
function
|
|
2357
|
-
const
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
if (
|
|
2365
|
-
|
|
2516
|
+
function applyContainerRule(rule, node, graph, parentId) {
|
|
2517
|
+
const id = node.id;
|
|
2518
|
+
const padding = getNumericProp(node, "padding", numericParamDefault(rule, "padding"));
|
|
2519
|
+
registerSizeSlots(node, graph, parentId);
|
|
2520
|
+
ensureSlot(graph, id, "contentWidth");
|
|
2521
|
+
ensureSlot(graph, id, "contentHeight");
|
|
2522
|
+
const widthIntent = getSizeProp(node, "width");
|
|
2523
|
+
const heightIntent = getSizeProp(node, "height");
|
|
2524
|
+
if (widthIntent === "fill" && parentId && rejectMainAxisFill(node, graph, "resolvedWidth", "normal", parentId) === "cross") {
|
|
2525
|
+
const opId = `op.box.fillWidth.${id}`;
|
|
2526
|
+
const outSid = slotId(id, "resolvedWidth");
|
|
2527
|
+
ensureSlot(graph, parentId, "availableWidth");
|
|
2528
|
+
addCandidate(graph, outSid, void 0, `box(${id}).fill`, "normal", opId);
|
|
2529
|
+
addOperation(graph, opId, "resolveSize", [slotId(parentId, "availableWidth")], [outSid], (inputs) => {
|
|
2530
|
+
return [num(inputs[0])];
|
|
2531
|
+
});
|
|
2366
2532
|
}
|
|
2367
|
-
|
|
2368
|
-
}
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
const parent = graph.parentMap.get(current);
|
|
2376
|
-
if (!parent) break;
|
|
2377
|
-
current = parent;
|
|
2533
|
+
if (heightIntent === "fill" && parentId && rejectMainAxisFill(node, graph, "resolvedHeight", "normal", parentId) === "cross") {
|
|
2534
|
+
const opId = `op.box.fillHeight.${id}`;
|
|
2535
|
+
const outSid = slotId(id, "resolvedHeight");
|
|
2536
|
+
ensureSlot(graph, parentId, "availableHeight");
|
|
2537
|
+
addCandidate(graph, outSid, void 0, `box(${id}).fill`, "normal", opId);
|
|
2538
|
+
addOperation(graph, opId, "resolveSize", [slotId(parentId, "availableHeight")], [outSid], (inputs) => {
|
|
2539
|
+
return [num(inputs[0])];
|
|
2540
|
+
});
|
|
2378
2541
|
}
|
|
2379
|
-
|
|
2380
|
-
}
|
|
2381
|
-
|
|
2382
|
-
const
|
|
2383
|
-
|
|
2384
|
-
const
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
let movers;
|
|
2394
|
-
const anchorProp = node.props.anchor;
|
|
2395
|
-
const moverProp = node.props.mover;
|
|
2396
|
-
if (anchorProp) {
|
|
2397
|
-
if (!targets.includes(anchorProp)) {
|
|
2398
|
-
graph.diagnostics.push({
|
|
2399
|
-
level: "error",
|
|
2400
|
-
message: `AlignConstraint(${node.id}): anchor="${anchorProp}" is not in targets [${targets.join(", ")}].`,
|
|
2401
|
-
path: node.id ?? ""
|
|
2402
|
-
/* fallback-ok: diagnostic path label; constraint nodes without an explicit id fall back to an empty path */
|
|
2403
|
-
});
|
|
2404
|
-
return;
|
|
2542
|
+
const wrapWidthOpId = `op.box.wrapWidth.${id}`;
|
|
2543
|
+
const wrapHeightOpId = `op.box.wrapHeight.${id}`;
|
|
2544
|
+
const shape = getStringProp(node, "shape", RENDER_DEFAULTS.box.shape);
|
|
2545
|
+
const aspectLocked = ASPECT_LOCKED_SHAPES.has(shape);
|
|
2546
|
+
const mirrorHeightToWidth = aspectLocked && heightIntent === "wrap" && typeof widthIntent === "number";
|
|
2547
|
+
const mirrorWidthToHeight = aspectLocked && widthIntent === "wrap" && typeof heightIntent === "number";
|
|
2548
|
+
if (widthIntent === "wrap") {
|
|
2549
|
+
const outSid = slotId(id, "resolvedWidth");
|
|
2550
|
+
addCandidate(graph, outSid, void 0, `box(${id}).wrap`, "weak", wrapWidthOpId);
|
|
2551
|
+
addOperation(graph, wrapWidthOpId, "resolveSize", [slotId(id, "contentWidth")], [outSid], (inputs) => {
|
|
2552
|
+
return [num(inputs[0]) + padding * 2];
|
|
2553
|
+
});
|
|
2554
|
+
if (mirrorWidthToHeight) {
|
|
2555
|
+
addCandidate(graph, outSid, heightIntent, `box(${id}).aspectLock`, "strong");
|
|
2405
2556
|
}
|
|
2406
2557
|
}
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
/* fallback-ok: diagnostic path label; constraint nodes without an explicit id fall back to an empty path */
|
|
2416
|
-
});
|
|
2417
|
-
}
|
|
2418
|
-
} else if (!anchorProp) {
|
|
2419
|
-
const scored = targets.map((t) => ({ id: t, score: computeFreedomScore(t, localSlot, graph) }));
|
|
2420
|
-
const allLow = scored.every((s) => s.score <= 0);
|
|
2421
|
-
const allMainAxis = scored.every((s) => s.score === 0);
|
|
2422
|
-
const sameStackAllMain = allMainAxis && new Set(targets.map((t) => graph.parentMap.get(t))).size === 1;
|
|
2423
|
-
if (allLow && !sameStackAllMain) {
|
|
2424
|
-
graph.diagnostics.push({
|
|
2425
|
-
level: "warning",
|
|
2426
|
-
message: `AlignConstraint(${node.id}): all targets have low freedom on ${localSlot}. Alignment may break sibling layout. ` + targets.map((t) => `${t} is ${describeFreedomContext(t, localSlot, graph)}`).join("; ") + ".",
|
|
2427
|
-
path: node.id ?? ""
|
|
2428
|
-
/* fallback-ok: diagnostic path label; constraint nodes without an explicit id fall back to an empty path */
|
|
2429
|
-
});
|
|
2558
|
+
if (heightIntent === "wrap") {
|
|
2559
|
+
const outSid = slotId(id, "resolvedHeight");
|
|
2560
|
+
addCandidate(graph, outSid, void 0, `box(${id}).wrap`, "weak", wrapHeightOpId);
|
|
2561
|
+
addOperation(graph, wrapHeightOpId, "resolveSize", [slotId(id, "contentHeight")], [outSid], (inputs) => {
|
|
2562
|
+
return [num(inputs[0]) + padding * 2];
|
|
2563
|
+
});
|
|
2564
|
+
if (mirrorHeightToWidth) {
|
|
2565
|
+
addCandidate(graph, outSid, widthIntent, `box(${id}).aspectLock`, "strong");
|
|
2430
2566
|
}
|
|
2431
2567
|
}
|
|
2432
|
-
const
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
}
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
stackCtx.index,
|
|
2453
|
-
refMeasure,
|
|
2454
|
-
moverMeasure,
|
|
2455
|
-
alignMode,
|
|
2456
|
-
strength,
|
|
2457
|
-
worldSlot,
|
|
2458
|
-
baseMainSlot(localSlot),
|
|
2459
|
-
sizeSlot,
|
|
2460
|
-
localSlot
|
|
2461
|
-
);
|
|
2462
|
-
continue;
|
|
2568
|
+
const availWidthOpId = `op.box.availW.${id}`;
|
|
2569
|
+
ensureSlot(graph, id, "availableWidth");
|
|
2570
|
+
addCandidate(graph, slotId(id, "availableWidth"), void 0, `box(${id}).availW`, "normal", availWidthOpId);
|
|
2571
|
+
addOperation(graph, availWidthOpId, "resolveSize", [slotId(id, "resolvedWidth")], [slotId(id, "availableWidth")], (inputs) => {
|
|
2572
|
+
return [Math.max(num(inputs[0]) - padding * 2, 0)];
|
|
2573
|
+
});
|
|
2574
|
+
const availHeightOpId = `op.box.availH.${id}`;
|
|
2575
|
+
ensureSlot(graph, id, "availableHeight");
|
|
2576
|
+
addCandidate(graph, slotId(id, "availableHeight"), void 0, `box(${id}).availH`, "normal", availHeightOpId);
|
|
2577
|
+
addOperation(graph, availHeightOpId, "resolveSize", [slotId(id, "resolvedHeight")], [slotId(id, "availableHeight")], (inputs) => {
|
|
2578
|
+
return [Math.max(num(inputs[0]) - padding * 2, 0)];
|
|
2579
|
+
});
|
|
2580
|
+
const children = childrenOf(node);
|
|
2581
|
+
const contentChildIds = children.filter((c) => !isConstraintKind(c.kind)).map((c) => c.id);
|
|
2582
|
+
if (contentChildIds.length > 0) {
|
|
2583
|
+
for (const childId of contentChildIds) {
|
|
2584
|
+
ensureSlot(graph, childId, "resolvedWidth");
|
|
2585
|
+
ensureSlot(graph, childId, "resolvedHeight");
|
|
2586
|
+
ensureSlot(graph, childId, "localX");
|
|
2587
|
+
ensureSlot(graph, childId, "localY");
|
|
2463
2588
|
}
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
const
|
|
2467
|
-
const
|
|
2468
|
-
const
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
ensureSlot(graph, moverMeasure, sizeSlot);
|
|
2487
|
-
for (const s of pathLocalYSlots) inputSlots.push(s);
|
|
2488
|
-
inputSlots.push(slotId(moverMeasure, sizeSlot));
|
|
2489
|
-
}
|
|
2589
|
+
const contentOpId = `op.box.content.${id}`;
|
|
2590
|
+
const childWidthSlots = contentChildIds.map((cid) => slotId(cid, "resolvedWidth"));
|
|
2591
|
+
const childHeightSlots = contentChildIds.map((cid) => slotId(cid, "resolvedHeight"));
|
|
2592
|
+
const allInputs = [...childWidthSlots, ...childHeightSlots];
|
|
2593
|
+
const contentOutputs = [slotId(id, "contentWidth"), slotId(id, "contentHeight")];
|
|
2594
|
+
addCandidate(graph, slotId(id, "contentWidth"), void 0, `box(${id}).childContent`, "normal", contentOpId);
|
|
2595
|
+
addCandidate(graph, slotId(id, "contentHeight"), void 0, `box(${id}).childContent`, "normal", contentOpId);
|
|
2596
|
+
addOperation(graph, contentOpId, "resolveSize", allInputs, contentOutputs, (inputs) => {
|
|
2597
|
+
const nChildren = contentChildIds.length;
|
|
2598
|
+
const widths = inputs.slice(0, nChildren);
|
|
2599
|
+
const heights = inputs.slice(nChildren);
|
|
2600
|
+
return [Math.max(...widths, 0), Math.max(...heights, 0)];
|
|
2601
|
+
});
|
|
2602
|
+
const hasAlignParams = rule.params?.colAlign !== void 0;
|
|
2603
|
+
const colAlign = hasAlignParams ? node.props.colAlign ?? rule.params.colAlign.default : void 0;
|
|
2604
|
+
const rowAlign = hasAlignParams ? node.props.rowAlign ?? rule.params.rowAlign.default : void 0;
|
|
2605
|
+
const alignOpId = `op.box.center.${id}`;
|
|
2606
|
+
const alignInputs = [slotId(id, "resolvedWidth"), slotId(id, "resolvedHeight"), ...childWidthSlots, ...childHeightSlots];
|
|
2607
|
+
const alignOutputs = contentChildIds.flatMap((cid) => [slotId(cid, "localX"), slotId(cid, "localY")]);
|
|
2608
|
+
for (const cid of contentChildIds) {
|
|
2609
|
+
addCandidate(graph, slotId(cid, "localX"), void 0, `box(${id}).center`, "normal", alignOpId);
|
|
2610
|
+
addCandidate(graph, slotId(cid, "localY"), void 0, `box(${id}).center`, "normal", alignOpId);
|
|
2490
2611
|
}
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
const
|
|
2494
|
-
const
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
const
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2612
|
+
addOperation(graph, alignOpId, "resolveSize", alignInputs, alignOutputs, (inputs) => {
|
|
2613
|
+
const boxW = num(inputs[0]);
|
|
2614
|
+
const boxH = num(inputs[1]);
|
|
2615
|
+
const nChildren = contentChildIds.length;
|
|
2616
|
+
const result = [];
|
|
2617
|
+
for (let i = 0; i < nChildren; i++) {
|
|
2618
|
+
const cw = num(inputs[2 + i]);
|
|
2619
|
+
const ch = num(inputs[2 + nChildren + i]);
|
|
2620
|
+
let cx;
|
|
2621
|
+
if (colAlign !== void 0) {
|
|
2622
|
+
switch (colAlign) {
|
|
2623
|
+
case "center":
|
|
2624
|
+
cx = (boxW - cw) / 2;
|
|
2625
|
+
break;
|
|
2626
|
+
case "right":
|
|
2627
|
+
cx = boxW - cw - padding;
|
|
2628
|
+
break;
|
|
2629
|
+
default:
|
|
2630
|
+
cx = padding;
|
|
2631
|
+
break;
|
|
2632
|
+
}
|
|
2633
|
+
} else {
|
|
2634
|
+
cx = (boxW - cw) / 2;
|
|
2501
2635
|
}
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2636
|
+
let cy;
|
|
2637
|
+
if (rowAlign !== void 0) {
|
|
2638
|
+
switch (rowAlign) {
|
|
2639
|
+
case "center":
|
|
2640
|
+
cy = (boxH - ch) / 2;
|
|
2641
|
+
break;
|
|
2642
|
+
case "bottom":
|
|
2643
|
+
cy = boxH - ch - padding;
|
|
2644
|
+
break;
|
|
2645
|
+
default:
|
|
2646
|
+
cy = padding;
|
|
2647
|
+
break;
|
|
2648
|
+
}
|
|
2649
|
+
} else {
|
|
2650
|
+
cy = (boxH - ch) / 2;
|
|
2513
2651
|
}
|
|
2514
|
-
|
|
2515
|
-
const moverMeasureSize = num(inputs[inputs.length - 1]);
|
|
2516
|
-
const internalOffset = pathSlots.reduce((sum, v) => sum + num(v), 0) + moverMeasureSize;
|
|
2517
|
-
return [refEnd - moverParentWorld - internalOffset];
|
|
2652
|
+
result.push(cx, cy);
|
|
2518
2653
|
}
|
|
2519
|
-
return
|
|
2654
|
+
return result;
|
|
2520
2655
|
});
|
|
2521
2656
|
}
|
|
2522
2657
|
}
|
|
2523
|
-
function
|
|
2524
|
-
const
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
ensureSlot(graph,
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2658
|
+
function applyTextMeasurementRule(rule, node, graph, parentId) {
|
|
2659
|
+
const id = node.id;
|
|
2660
|
+
const text = getStringProp(node, "text", stringParamDefault(rule, "text"));
|
|
2661
|
+
const fontSize = getNumericProp(node, "fontSize", numericParamDefault(rule, "fontSize"));
|
|
2662
|
+
const padding = getNumericProp(node, "padding", numericParamDefault(rule, "padding"));
|
|
2663
|
+
const textAlign = getStringProp(node, "textAlign", stringParamDefault(rule, "textAlign"));
|
|
2664
|
+
ensureSlot(graph, id, "resolvedWidth");
|
|
2665
|
+
ensureSlot(graph, id, "resolvedHeight");
|
|
2666
|
+
ensureSlot(graph, id, "localX");
|
|
2667
|
+
ensureSlot(graph, id, "localY");
|
|
2668
|
+
const fontWeight = node.props.fontWeight;
|
|
2669
|
+
const measurement = textMeasurer.measure(text, fontSize, void 0, fontWeight);
|
|
2670
|
+
const intrinsicW = measurement.width + padding * 2;
|
|
2671
|
+
const intrinsicH = measurement.height + padding * 2;
|
|
2672
|
+
ensureSlot(graph, id, "intrinsicWidth", intrinsicW);
|
|
2673
|
+
ensureSlot(graph, id, "intrinsicHeight", intrinsicH);
|
|
2674
|
+
addCandidate(graph, slotId(id, "resolvedWidth"), intrinsicW, `text(${id}).intrinsic`, "normal");
|
|
2675
|
+
addCandidate(graph, slotId(id, "resolvedHeight"), intrinsicH, `text(${id}).intrinsic`, "normal");
|
|
2676
|
+
if (parentId) {
|
|
2677
|
+
ensureSlot(graph, id, "contentWidth", intrinsicW);
|
|
2678
|
+
ensureSlot(graph, id, "contentHeight", intrinsicH);
|
|
2542
2679
|
}
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2680
|
+
const lineCount = measurement.lines.length;
|
|
2681
|
+
const fontMetrics = textMeasurer.metrics(fontSize, fontWeight);
|
|
2682
|
+
const { capHeight, lineHeight } = fontMetrics;
|
|
2683
|
+
let textAnchorVal;
|
|
2684
|
+
switch (textAlign) {
|
|
2685
|
+
case "start":
|
|
2686
|
+
case "left":
|
|
2687
|
+
textAnchorVal = 0;
|
|
2688
|
+
break;
|
|
2689
|
+
case "end":
|
|
2690
|
+
case "right":
|
|
2691
|
+
textAnchorVal = 2;
|
|
2692
|
+
break;
|
|
2693
|
+
default:
|
|
2694
|
+
textAnchorVal = 1;
|
|
2695
|
+
break;
|
|
2696
|
+
}
|
|
2697
|
+
ensureSlot(graph, id, "textBaseline");
|
|
2698
|
+
ensureSlot(graph, id, "textLineHeight");
|
|
2699
|
+
ensureSlot(graph, id, "textX");
|
|
2700
|
+
ensureSlot(graph, id, "textAnchor");
|
|
2701
|
+
const textLayoutOpId = `op.textLayout.${id}`;
|
|
2702
|
+
const textLayoutInputs = [slotId(id, "resolvedWidth"), slotId(id, "resolvedHeight")];
|
|
2703
|
+
const textLayoutOutputs = [
|
|
2704
|
+
slotId(id, "textBaseline"),
|
|
2705
|
+
slotId(id, "textX"),
|
|
2706
|
+
slotId(id, "textAnchor"),
|
|
2707
|
+
slotId(id, "textLineHeight")
|
|
2708
|
+
];
|
|
2709
|
+
addCandidate(graph, slotId(id, "textBaseline"), void 0, `text(${id}).layout`, "normal", textLayoutOpId);
|
|
2710
|
+
addCandidate(graph, slotId(id, "textX"), void 0, `text(${id}).layout`, "normal", textLayoutOpId);
|
|
2711
|
+
addCandidate(graph, slotId(id, "textAnchor"), void 0, `text(${id}).layout`, "normal", textLayoutOpId);
|
|
2712
|
+
addCandidate(graph, slotId(id, "textLineHeight"), void 0, `text(${id}).layout`, "normal", textLayoutOpId);
|
|
2713
|
+
addOperation(graph, textLayoutOpId, "identity", textLayoutInputs, textLayoutOutputs, (inputs) => {
|
|
2714
|
+
const w = num(inputs[0]);
|
|
2715
|
+
const h = num(inputs[1]);
|
|
2716
|
+
const visualExtent = capHeight + (lineCount - 1) * lineHeight;
|
|
2717
|
+
const baseline = (h - visualExtent) / 2 + capHeight;
|
|
2718
|
+
let tx;
|
|
2719
|
+
switch (textAnchorVal) {
|
|
2720
|
+
case 0:
|
|
2721
|
+
tx = 0;
|
|
2722
|
+
break;
|
|
2723
|
+
case 2:
|
|
2724
|
+
tx = w;
|
|
2725
|
+
break;
|
|
2726
|
+
default:
|
|
2727
|
+
tx = w / 2;
|
|
2728
|
+
break;
|
|
2558
2729
|
}
|
|
2559
|
-
return [
|
|
2730
|
+
return [baseline, tx, textAnchorVal, lineHeight];
|
|
2560
2731
|
});
|
|
2561
2732
|
}
|
|
2562
|
-
function
|
|
2563
|
-
const
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
const
|
|
2569
|
-
|
|
2570
|
-
const
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
for (const targetId of targets) {
|
|
2576
|
-
ensureSlot(graph, targetId, inputSlotName);
|
|
2577
|
-
gatherInputs.push(slotId(targetId, inputSlotName));
|
|
2733
|
+
function applyOverlayRule(rule, node, graph, parentId) {
|
|
2734
|
+
const id = node.id;
|
|
2735
|
+
const padding = getNumericProp(node, "padding", numericParamDefault(rule, "padding"));
|
|
2736
|
+
registerSizeSlots(node, graph, parentId);
|
|
2737
|
+
ensureSlot(graph, id, "contentWidth");
|
|
2738
|
+
ensureSlot(graph, id, "contentHeight");
|
|
2739
|
+
const children = childrenOf(node);
|
|
2740
|
+
const childIds = children.filter((c) => !isConstraintKind(c.kind)).map((c) => c.id);
|
|
2741
|
+
for (const childId of childIds) {
|
|
2742
|
+
ensureSlot(graph, childId, "localX", padding);
|
|
2743
|
+
ensureSlot(graph, childId, "localY", padding);
|
|
2744
|
+
addCandidate(graph, slotId(childId, "localX"), padding, `overlay(${id})`, "normal");
|
|
2745
|
+
addCandidate(graph, slotId(childId, "localY"), padding, `overlay(${id})`, "normal");
|
|
2578
2746
|
}
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
case "min":
|
|
2584
|
-
return [Math.min(...vals)];
|
|
2585
|
-
case "first":
|
|
2586
|
-
return [num(vals[0])];
|
|
2587
|
-
default:
|
|
2588
|
-
return [Math.max(...vals)];
|
|
2747
|
+
if (childIds.length > 0) {
|
|
2748
|
+
for (const childId of childIds) {
|
|
2749
|
+
ensureSlot(graph, childId, "resolvedWidth");
|
|
2750
|
+
ensureSlot(graph, childId, "resolvedHeight");
|
|
2589
2751
|
}
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2752
|
+
const contentOpId = `op.overlay.content.${id}`;
|
|
2753
|
+
const childWidthSlots = childIds.map((cid) => slotId(cid, "resolvedWidth"));
|
|
2754
|
+
const childHeightSlots = childIds.map((cid) => slotId(cid, "resolvedHeight"));
|
|
2755
|
+
const contentInputs = [...childWidthSlots, ...childHeightSlots];
|
|
2756
|
+
const contentOutputs = [slotId(id, "contentWidth"), slotId(id, "contentHeight")];
|
|
2757
|
+
addCandidate(graph, slotId(id, "contentWidth"), void 0, `overlay(${id}).childContent`, "normal", contentOpId);
|
|
2758
|
+
addCandidate(graph, slotId(id, "contentHeight"), void 0, `overlay(${id}).childContent`, "normal", contentOpId);
|
|
2759
|
+
addOperation(graph, contentOpId, "resolveSize", contentInputs, contentOutputs, (inputs) => {
|
|
2760
|
+
const nChildren = childIds.length;
|
|
2761
|
+
const widths = inputs.slice(0, nChildren);
|
|
2762
|
+
const heights = inputs.slice(nChildren);
|
|
2763
|
+
return [Math.max(...widths, 0), Math.max(...heights, 0)];
|
|
2764
|
+
});
|
|
2765
|
+
}
|
|
2766
|
+
const widthIntent = getSizeProp(node, "width");
|
|
2767
|
+
const heightIntent = getSizeProp(node, "height");
|
|
2768
|
+
if (widthIntent === "wrap") {
|
|
2769
|
+
const wrapWidthOpId = `op.overlay.wrapWidth.${id}`;
|
|
2770
|
+
const outSid = slotId(id, "resolvedWidth");
|
|
2771
|
+
addCandidate(graph, outSid, void 0, `overlay(${id}).wrap`, "weak", wrapWidthOpId);
|
|
2772
|
+
addOperation(graph, wrapWidthOpId, "resolveSize", [slotId(id, "contentWidth")], [outSid], (inputs) => {
|
|
2773
|
+
return [num(inputs[0]) + padding * 2];
|
|
2774
|
+
});
|
|
2775
|
+
}
|
|
2776
|
+
if (heightIntent === "wrap") {
|
|
2777
|
+
const wrapHeightOpId = `op.overlay.wrapHeight.${id}`;
|
|
2778
|
+
const outSid = slotId(id, "resolvedHeight");
|
|
2779
|
+
addCandidate(graph, outSid, void 0, `overlay(${id}).wrap`, "weak", wrapHeightOpId);
|
|
2780
|
+
addOperation(graph, wrapHeightOpId, "resolveSize", [slotId(id, "contentHeight")], [outSid], (inputs) => {
|
|
2781
|
+
return [num(inputs[0]) + padding * 2];
|
|
2782
|
+
});
|
|
2598
2783
|
}
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
const axis = getStringProp(node, "axis", CONSTRAINT_DEFAULTS.orderAxis);
|
|
2607
|
-
const strength = node.props.strength ?? rule.default_priority;
|
|
2608
|
-
const posSlot = rule.axis_to_slot[axis];
|
|
2609
|
-
const sizeSlot = rule.axis_to_size_slot[axis];
|
|
2610
|
-
for (let i = 1; i < targets.length; i++) {
|
|
2611
|
-
const prev = targets[i - 1];
|
|
2612
|
-
const curr = targets[i];
|
|
2613
|
-
ensureSlot(graph, prev, posSlot);
|
|
2614
|
-
ensureSlot(graph, prev, sizeSlot);
|
|
2615
|
-
ensureSlot(graph, curr, posSlot);
|
|
2616
|
-
const opId = `op.order.${node.id}.${i}`;
|
|
2617
|
-
const inputSlots = [`${prev}.${posSlot}`, `${prev}.${sizeSlot}`];
|
|
2618
|
-
const outputSlotId = `${curr}.${posSlot}`;
|
|
2619
|
-
addCandidate(graph, outputSlotId, void 0, `order(${node.id})`, strength, opId);
|
|
2620
|
-
addOperation(graph, opId, "identity", inputSlots, [outputSlotId], (inputs) => {
|
|
2621
|
-
const prevPos = num(inputs[0]);
|
|
2622
|
-
const prevSize = num(inputs[1]);
|
|
2623
|
-
return [prevPos + prevSize];
|
|
2784
|
+
if (widthIntent === "fill" && parentId && rejectMainAxisFill(node, graph, "resolvedWidth", "normal", parentId) === "cross") {
|
|
2785
|
+
const fillWidthOpId = `op.overlay.fillWidth.${id}`;
|
|
2786
|
+
const outSid = slotId(id, "resolvedWidth");
|
|
2787
|
+
ensureSlot(graph, parentId, "availableWidth");
|
|
2788
|
+
addCandidate(graph, outSid, void 0, `overlay(${id}).fill`, "normal", fillWidthOpId);
|
|
2789
|
+
addOperation(graph, fillWidthOpId, "resolveSize", [slotId(parentId, "availableWidth")], [outSid], (inputs) => {
|
|
2790
|
+
return [num(inputs[0])];
|
|
2624
2791
|
});
|
|
2625
2792
|
}
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
const sizeSlot = rule.axis_to_size_slot[axis];
|
|
2634
|
-
const minGap = getNumericProp(node, rule.min_gap_from, 0);
|
|
2635
|
-
for (let i = 1; i < targets.length; i++) {
|
|
2636
|
-
const prev = targets[i - 1];
|
|
2637
|
-
const curr = targets[i];
|
|
2638
|
-
ensureSlot(graph, prev, posSlot);
|
|
2639
|
-
ensureSlot(graph, prev, sizeSlot);
|
|
2640
|
-
ensureSlot(graph, curr, posSlot);
|
|
2641
|
-
const opId = `op.gap.${node.id}.${i}`;
|
|
2642
|
-
const inputSlots = [`${prev}.${posSlot}`, `${prev}.${sizeSlot}`];
|
|
2643
|
-
const outputSlotId = `${curr}.${posSlot}`;
|
|
2644
|
-
addCandidate(graph, outputSlotId, void 0, `gap(${node.id})`, strength, opId);
|
|
2645
|
-
addOperation(graph, opId, "identity", inputSlots, [outputSlotId], (inputs) => {
|
|
2646
|
-
const prevPos = num(inputs[0]);
|
|
2647
|
-
const prevSize = num(inputs[1]);
|
|
2648
|
-
return [prevPos + prevSize + minGap];
|
|
2793
|
+
if (heightIntent === "fill" && parentId && rejectMainAxisFill(node, graph, "resolvedHeight", "normal", parentId) === "cross") {
|
|
2794
|
+
const fillHeightOpId = `op.overlay.fillHeight.${id}`;
|
|
2795
|
+
const outSid = slotId(id, "resolvedHeight");
|
|
2796
|
+
ensureSlot(graph, parentId, "availableHeight");
|
|
2797
|
+
addCandidate(graph, outSid, void 0, `overlay(${id}).fill`, "normal", fillHeightOpId);
|
|
2798
|
+
addOperation(graph, fillHeightOpId, "resolveSize", [slotId(parentId, "availableHeight")], [outSid], (inputs) => {
|
|
2799
|
+
return [num(inputs[0])];
|
|
2649
2800
|
});
|
|
2650
2801
|
}
|
|
2802
|
+
const availWidthOpId = `op.overlay.availW.${id}`;
|
|
2803
|
+
ensureSlot(graph, id, "availableWidth");
|
|
2804
|
+
addCandidate(graph, slotId(id, "availableWidth"), void 0, `overlay(${id}).availW`, "normal", availWidthOpId);
|
|
2805
|
+
addOperation(graph, availWidthOpId, "resolveSize", [slotId(id, "resolvedWidth")], [slotId(id, "availableWidth")], (inputs) => {
|
|
2806
|
+
return [Math.max(num(inputs[0]) - padding * 2, 0)];
|
|
2807
|
+
});
|
|
2808
|
+
const availHeightOpId = `op.overlay.availH.${id}`;
|
|
2809
|
+
ensureSlot(graph, id, "availableHeight");
|
|
2810
|
+
addCandidate(graph, slotId(id, "availableHeight"), void 0, `overlay(${id}).availH`, "normal", availHeightOpId);
|
|
2811
|
+
addOperation(graph, availHeightOpId, "resolveSize", [slotId(id, "resolvedHeight")], [slotId(id, "availableHeight")], (inputs) => {
|
|
2812
|
+
return [Math.max(num(inputs[0]) - padding * 2, 0)];
|
|
2813
|
+
});
|
|
2651
2814
|
}
|
|
2652
|
-
function
|
|
2653
|
-
const
|
|
2654
|
-
|
|
2655
|
-
const
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
];
|
|
2672
|
-
const outputSlotId = `${contentId}.${posSlot}`;
|
|
2673
|
-
addCandidate(graph, outputSlotId, void 0, `keepInside(${node.id})`, strength, opId);
|
|
2674
|
-
addOperation(graph, opId, "clamp", inputSlots, [outputSlotId], (inputs) => {
|
|
2675
|
-
const containerSize = num(inputs[0]);
|
|
2676
|
-
const currentPos = num(inputs[1]);
|
|
2677
|
-
const contentSize = num(inputs[2]);
|
|
2678
|
-
const maxPos = containerSize - contentSize;
|
|
2679
|
-
return [Math.max(0, Math.min(currentPos, maxPos))];
|
|
2680
|
-
});
|
|
2681
|
-
}
|
|
2815
|
+
function applyConnectorRule(_rule, node, graph) {
|
|
2816
|
+
const id = node.id;
|
|
2817
|
+
const fromId = node.props.from;
|
|
2818
|
+
const toId = node.props.to;
|
|
2819
|
+
ensureSlot(graph, id, "resolvedWidth", 0);
|
|
2820
|
+
ensureSlot(graph, id, "resolvedHeight", 0);
|
|
2821
|
+
ensureSlot(graph, id, "localX", 0);
|
|
2822
|
+
ensureSlot(graph, id, "localY", 0);
|
|
2823
|
+
ensureSlot(graph, id, "connectorPath");
|
|
2824
|
+
if (fromId && toId) {
|
|
2825
|
+
ensureSlot(graph, fromId, "localX");
|
|
2826
|
+
ensureSlot(graph, fromId, "localY");
|
|
2827
|
+
ensureSlot(graph, fromId, "resolvedWidth");
|
|
2828
|
+
ensureSlot(graph, fromId, "resolvedHeight");
|
|
2829
|
+
ensureSlot(graph, toId, "localX");
|
|
2830
|
+
ensureSlot(graph, toId, "localY");
|
|
2831
|
+
ensureSlot(graph, toId, "resolvedWidth");
|
|
2832
|
+
ensureSlot(graph, toId, "resolvedHeight");
|
|
2833
|
+
addCandidate(graph, slotId(id, "connectorPath"), 0, `connector(${id})`, "normal");
|
|
2682
2834
|
}
|
|
2683
2835
|
}
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2836
|
+
function applyFixedSizeRule(rule, node, graph, parentId) {
|
|
2837
|
+
const id = node.id;
|
|
2838
|
+
const kind = node.kind;
|
|
2839
|
+
let widthSpec;
|
|
2840
|
+
let heightSpec;
|
|
2841
|
+
if (rule.size_from_axis) {
|
|
2842
|
+
const axis = getStringProp(node, "axis", stringParamDefault(rule, "axis"));
|
|
2843
|
+
const sizeConfig = rule.size_from_axis[axis];
|
|
2844
|
+
widthSpec = sizeConfig?.width ?? 0;
|
|
2845
|
+
heightSpec = sizeConfig?.height ?? 0;
|
|
2846
|
+
} else {
|
|
2847
|
+
widthSpec = getNumericProp(node, "width", numericParamDefault(rule, "width"));
|
|
2848
|
+
heightSpec = getNumericProp(node, "height", numericParamDefault(rule, "height"));
|
|
2849
|
+
}
|
|
2850
|
+
ensureSlot(graph, id, "localX", 0);
|
|
2851
|
+
ensureSlot(graph, id, "localY", 0);
|
|
2852
|
+
const priority = kind === "divider" ? "weak" : "normal";
|
|
2853
|
+
applyFixedSizeDimension(node, graph, "resolvedWidth", widthSpec, priority, parentId);
|
|
2854
|
+
applyFixedSizeDimension(node, graph, "resolvedHeight", heightSpec, priority, parentId);
|
|
2702
2855
|
}
|
|
2703
|
-
function
|
|
2856
|
+
function applyFixedSizeDimension(node, graph, dim, spec, priority, parentId) {
|
|
2704
2857
|
const id = node.id;
|
|
2705
|
-
const
|
|
2706
|
-
const
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
}
|
|
2858
|
+
const kind = node.kind;
|
|
2859
|
+
const outSid = slotId(id, dim);
|
|
2860
|
+
if (typeof spec === "number" && Number.isFinite(spec)) {
|
|
2861
|
+
ensureSlot(graph, id, dim, spec);
|
|
2862
|
+
addCandidate(graph, outSid, spec, `${kind}(${id})`, priority);
|
|
2863
|
+
return;
|
|
2864
|
+
}
|
|
2865
|
+
ensureSlot(graph, id, dim);
|
|
2866
|
+
if (spec === "fill" && parentId) {
|
|
2867
|
+
if (rejectMainAxisFill(node, graph, dim, priority, parentId) !== "cross") return;
|
|
2868
|
+
const dimName = dim === "resolvedWidth" ? "width" : "height";
|
|
2869
|
+
const availSlot = dim === "resolvedWidth" ? "availableWidth" : "availableHeight";
|
|
2870
|
+
const opId = `op.${kind}.fill.${dimName}.${id}`;
|
|
2871
|
+
ensureSlot(graph, parentId, availSlot);
|
|
2872
|
+
addCandidate(graph, outSid, void 0, `${kind}(${id}).fill`, priority, opId);
|
|
2873
|
+
addOperation(graph, opId, "resolveSize", [slotId(parentId, availSlot)], [outSid], (inputs) => {
|
|
2874
|
+
return [num(inputs[0])];
|
|
2875
|
+
});
|
|
2876
|
+
return;
|
|
2723
2877
|
}
|
|
2878
|
+
addCandidate(graph, outSid, 0, `${kind}(${id})`, priority);
|
|
2724
2879
|
}
|
|
2725
|
-
function
|
|
2880
|
+
function applyGridRule(rule, node, graph, parentId) {
|
|
2726
2881
|
const id = node.id;
|
|
2727
|
-
const gap = getNumericProp(node, "gap",
|
|
2728
|
-
const padding = getNumericProp(node, "padding",
|
|
2729
|
-
const
|
|
2882
|
+
const gap = getNumericProp(node, "gap", 0);
|
|
2883
|
+
const padding = getNumericProp(node, "padding", 0);
|
|
2884
|
+
const gridConfig = rule.grid;
|
|
2885
|
+
const rowKind = gridConfig.row_kind;
|
|
2886
|
+
const cellKind = gridConfig.cell_kind;
|
|
2730
2887
|
registerSizeSlots(node, graph, parentId);
|
|
2731
2888
|
ensureSlot(graph, id, "contentWidth");
|
|
2732
|
-
ensureSlot(graph, id, "contentHeight");
|
|
2733
|
-
const
|
|
2734
|
-
if (
|
|
2735
|
-
|
|
2736
|
-
const
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
const contentCrossSize = axisConfig.content_cross_size;
|
|
2742
|
-
const baseMain = baseMainSlot(mainSlot);
|
|
2743
|
-
const opId = `op.${kindName}.${id}`;
|
|
2744
|
-
const inputSlots = [];
|
|
2745
|
-
for (const childId of childIds) {
|
|
2746
|
-
ensureSlot(graph, childId, mainSize);
|
|
2747
|
-
ensureSlot(graph, childId, crossSize);
|
|
2748
|
-
ensureSlot(graph, childId, baseMain);
|
|
2749
|
-
ensureSlot(graph, childId, crossSlot);
|
|
2750
|
-
inputSlots.push(slotId(childId, mainSize));
|
|
2751
|
-
}
|
|
2752
|
-
const baseOutputs = [
|
|
2753
|
-
...childIds.map((cid) => slotId(cid, baseMain)),
|
|
2754
|
-
slotId(id, contentMainSize),
|
|
2755
|
-
slotId(id, mainSize)
|
|
2756
|
-
];
|
|
2757
|
-
for (const cid of childIds) {
|
|
2758
|
-
addCandidate(graph, slotId(cid, baseMain), void 0, `${kindName}(${id})`, "strong", opId);
|
|
2759
|
-
}
|
|
2760
|
-
addCandidate(graph, slotId(id, contentMainSize), void 0, `${kindName}(${id}).content`, "strong", opId);
|
|
2761
|
-
addCandidate(graph, slotId(id, mainSize), void 0, `${kindName}(${id}).wrap`, "normal", opId);
|
|
2762
|
-
addOperation(graph, opId, "stackPosition", inputSlots, baseOutputs, (inputs) => {
|
|
2763
|
-
let pos = padding;
|
|
2764
|
-
const positions = [];
|
|
2765
|
-
for (let i = 0; i < inputs.length; i++) {
|
|
2766
|
-
positions.push(pos);
|
|
2767
|
-
pos += inputs[i] + (i < inputs.length - 1 ? gap : 0);
|
|
2768
|
-
}
|
|
2769
|
-
const contentMain = pos - padding;
|
|
2770
|
-
const totalMain = contentMain + padding * 2;
|
|
2771
|
-
return [...positions, contentMain, totalMain];
|
|
2772
|
-
});
|
|
2773
|
-
const suffixShiftSlotIds = [];
|
|
2774
|
-
for (let i = 0; i < childIds.length; i++) {
|
|
2775
|
-
const ssId = suffixShiftSlotId(id, i);
|
|
2776
|
-
ensureSlot(graph, id, `suffixShift.${i}`);
|
|
2777
|
-
addCandidate(graph, ssId, 0, `${kindName}(${id}).suffixShift.${i}`, "weak");
|
|
2778
|
-
addResolver(graph, ssId, "max");
|
|
2779
|
-
suffixShiftSlotIds.push(ssId);
|
|
2889
|
+
ensureSlot(graph, id, "contentHeight");
|
|
2890
|
+
const rows = childrenOf(node).filter((c) => c.kind === rowKind);
|
|
2891
|
+
if (rows.length === 0) return;
|
|
2892
|
+
const rowIds = rows.map((r) => r.id);
|
|
2893
|
+
for (const rowId of rowIds) {
|
|
2894
|
+
ensureSlot(graph, rowId, "resolvedWidth");
|
|
2895
|
+
ensureSlot(graph, rowId, "resolvedHeight");
|
|
2896
|
+
ensureSlot(graph, rowId, "localX");
|
|
2897
|
+
ensureSlot(graph, rowId, "localY");
|
|
2780
2898
|
}
|
|
2781
|
-
const
|
|
2782
|
-
const
|
|
2783
|
-
|
|
2784
|
-
...
|
|
2899
|
+
const rowPosOpId = `op.grid.rowPos.${id}`;
|
|
2900
|
+
const rowHeightSlots = rowIds.map((rid) => slotId(rid, "resolvedHeight"));
|
|
2901
|
+
const rowPosOutputs = [
|
|
2902
|
+
...rowIds.map((rid) => slotId(rid, "localY")),
|
|
2903
|
+
...rowIds.map((rid) => slotId(rid, "localX")),
|
|
2904
|
+
slotId(id, "contentHeight"),
|
|
2905
|
+
slotId(id, "resolvedHeight")
|
|
2785
2906
|
];
|
|
2786
|
-
const
|
|
2787
|
-
|
|
2788
|
-
addCandidate(graph, slotId(
|
|
2907
|
+
for (const rid of rowIds) {
|
|
2908
|
+
addCandidate(graph, slotId(rid, "localY"), void 0, `grid(${id}).rowPos`, "strong", rowPosOpId);
|
|
2909
|
+
addCandidate(graph, slotId(rid, "localX"), void 0, `grid(${id}).rowX`, "normal", rowPosOpId);
|
|
2789
2910
|
}
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
result.push(num(bases[j]) + runningMax);
|
|
2911
|
+
addCandidate(graph, slotId(id, "contentHeight"), void 0, `grid(${id}).contentH`, "strong", rowPosOpId);
|
|
2912
|
+
addCandidate(graph, slotId(id, "resolvedHeight"), void 0, `grid(${id}).wrapH`, "normal", rowPosOpId);
|
|
2913
|
+
addOperation(graph, rowPosOpId, "stackPosition", rowHeightSlots, rowPosOutputs, (inputs) => {
|
|
2914
|
+
let y = padding;
|
|
2915
|
+
const yPositions = [];
|
|
2916
|
+
for (let i = 0; i < rowIds.length; i++) {
|
|
2917
|
+
yPositions.push(y);
|
|
2918
|
+
y += num(inputs[i]) + (i < rowIds.length - 1 ? gap : 0);
|
|
2799
2919
|
}
|
|
2800
|
-
|
|
2920
|
+
const contentH = y - padding;
|
|
2921
|
+
const totalH = contentH + padding * 2;
|
|
2922
|
+
const xPositions = rowIds.map(() => padding);
|
|
2923
|
+
return [...yPositions, ...xPositions, contentH, totalH];
|
|
2801
2924
|
});
|
|
2802
|
-
const
|
|
2803
|
-
const
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
const
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2925
|
+
const maxCols = Math.max(...rows.map((r) => childrenOf(r).filter((c) => c.kind === cellKind).length));
|
|
2926
|
+
const columnCellIds = [];
|
|
2927
|
+
for (let col = 0; col < maxCols; col++) {
|
|
2928
|
+
columnCellIds.push([]);
|
|
2929
|
+
}
|
|
2930
|
+
for (const row of rows) {
|
|
2931
|
+
const cells = childrenOf(row).filter((c) => c.kind === cellKind);
|
|
2932
|
+
for (let col = 0; col < cells.length && col < maxCols; col++) {
|
|
2933
|
+
columnCellIds[col].push(cells[col].id);
|
|
2811
2934
|
}
|
|
2812
2935
|
}
|
|
2813
|
-
const
|
|
2814
|
-
for (
|
|
2815
|
-
|
|
2816
|
-
|
|
2936
|
+
const cellPaddingMap = /* @__PURE__ */ new Map();
|
|
2937
|
+
for (const row of rows) {
|
|
2938
|
+
for (const cell of childrenOf(row).filter((c) => c.kind === cellKind)) {
|
|
2939
|
+
cellPaddingMap.set(cell.id, getNumericProp(cell, "padding", 0));
|
|
2817
2940
|
}
|
|
2818
2941
|
}
|
|
2819
|
-
const
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2942
|
+
const colMinWidthSlots = [];
|
|
2943
|
+
for (let col = 0; col < maxCols; col++) {
|
|
2944
|
+
const cellIds = columnCellIds[col];
|
|
2945
|
+
const colMinSlot = `${id}.colMinWidth.${col}`;
|
|
2946
|
+
colMinWidthSlots.push(colMinSlot);
|
|
2947
|
+
ensureSlot(graph, id, `colMinWidth.${col}`);
|
|
2948
|
+
if (cellIds.length < 2) {
|
|
2949
|
+
if (cellIds.length === 1) {
|
|
2950
|
+
const cid = cellIds[0];
|
|
2951
|
+
const p = num(cellPaddingMap.get(cid));
|
|
2952
|
+
const singleOpId = `op.grid.colMin.${id}.${col}`;
|
|
2953
|
+
ensureSlot(graph, cid, "contentWidth");
|
|
2954
|
+
addCandidate(graph, colMinSlot, void 0, `grid(${id}).colMin[${col}]`, "strong", singleOpId);
|
|
2955
|
+
addOperation(graph, singleOpId, "columnWidthResolve", [slotId(cid, "contentWidth")], [colMinSlot], (inputs) => {
|
|
2956
|
+
return [num(inputs[0]) + p * 2];
|
|
2957
|
+
});
|
|
2958
|
+
}
|
|
2959
|
+
continue;
|
|
2960
|
+
}
|
|
2961
|
+
const colEqOpId = `op.grid.colMin.${id}.${col}`;
|
|
2962
|
+
const widthInputs = cellIds.map((cid) => {
|
|
2963
|
+
ensureSlot(graph, cid, "contentWidth");
|
|
2964
|
+
return slotId(cid, "contentWidth");
|
|
2965
|
+
});
|
|
2966
|
+
const colPaddings = cellIds.map((cid) => num(cellPaddingMap.get(cid)));
|
|
2967
|
+
addCandidate(graph, colMinSlot, void 0, `grid(${id}).colMin[${col}]`, "strong", colEqOpId);
|
|
2968
|
+
addOperation(graph, colEqOpId, "columnWidthResolve", widthInputs, [colMinSlot], (inputs) => {
|
|
2969
|
+
const desiredWidths = inputs.map((w, i) => num(w) + colPaddings[i] * 2);
|
|
2970
|
+
return [Math.max(...desiredWidths, 0)];
|
|
2971
|
+
});
|
|
2831
2972
|
}
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
const
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
return [num(inputs[0]) + padding * 2];
|
|
2842
|
-
});
|
|
2843
|
-
const crossAlignOpId = `op.${kindName}.crossAlign.${id}`;
|
|
2844
|
-
const allChildCrossSlots = childIds.map((cid) => slotId(cid, crossSize));
|
|
2845
|
-
const crossAlignInputs = [slotId(id, availableCrossSlot), ...allChildCrossSlots];
|
|
2846
|
-
const crossAlignOutputs = childIds.map((cid) => slotId(cid, crossSlot));
|
|
2847
|
-
for (const cid of childIds) {
|
|
2848
|
-
addCandidate(graph, slotId(cid, crossSlot), void 0, `${kindName}(${id}).crossAlign`, "strong", crossAlignOpId);
|
|
2973
|
+
if (maxCols > 0) {
|
|
2974
|
+
const wrapWidthOpId = `op.grid.wrapWidth.${id}`;
|
|
2975
|
+
const wrapOutputs = [slotId(id, "contentWidth"), slotId(id, "resolvedWidth")];
|
|
2976
|
+
addCandidate(graph, slotId(id, "contentWidth"), void 0, `grid(${id}).wrapContentW`, "normal", wrapWidthOpId);
|
|
2977
|
+
addCandidate(graph, slotId(id, "resolvedWidth"), void 0, `grid(${id}).wrapW`, "normal", wrapWidthOpId);
|
|
2978
|
+
addOperation(graph, wrapWidthOpId, "resolveSize", colMinWidthSlots, wrapOutputs, (inputs) => {
|
|
2979
|
+
const contentW = inputs.reduce((sum, w) => sum + num(w), 0) + gap * Math.max(0, inputs.length - 1);
|
|
2980
|
+
return [contentW, contentW + padding * 2];
|
|
2981
|
+
});
|
|
2849
2982
|
}
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
const
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
}
|
|
2861
|
-
positions.push(crossPos);
|
|
2983
|
+
const colResolvedWidthSlots = [];
|
|
2984
|
+
if (maxCols > 0) {
|
|
2985
|
+
const colFillOpId = `op.grid.colFill.${id}`;
|
|
2986
|
+
const colFillInputs = [slotId(id, "resolvedWidth"), ...colMinWidthSlots];
|
|
2987
|
+
const colFillOutputs = [];
|
|
2988
|
+
for (let col = 0; col < maxCols; col++) {
|
|
2989
|
+
const colResSlot = `${id}.colResolvedWidth.${col}`;
|
|
2990
|
+
colResolvedWidthSlots.push(colResSlot);
|
|
2991
|
+
ensureSlot(graph, id, `colResolvedWidth.${col}`);
|
|
2992
|
+
colFillOutputs.push(colResSlot);
|
|
2993
|
+
addCandidate(graph, colResSlot, void 0, `grid(${id}).colFill[${col}]`, "strong", colFillOpId);
|
|
2862
2994
|
}
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
const kind = node.kind;
|
|
2872
|
-
const dimName = dim === "resolvedWidth" ? "width" : "height";
|
|
2873
|
-
const rule = layoutRules[kind];
|
|
2874
|
-
const hint = rule?.size_from_axis ? (() => {
|
|
2875
|
-
const axis = getStringProp(node, "axis", stringParamDefault(rule, "axis"));
|
|
2876
|
-
const otherAxis = axis === "horizontal" ? "vertical" : "horizontal";
|
|
2877
|
-
return ` (axis="${axis}") \u2014 use axis="${otherAxis}" or give the ${kind} a fixed-size container`;
|
|
2878
|
-
})() : ` \u2014 give the ${kind} a fixed ${dimName} or place it in a fixed-size container`;
|
|
2879
|
-
graph.diagnostics.push({
|
|
2880
|
-
level: "error",
|
|
2881
|
-
message: `${kind} '${id}' fills its ${dimName} along the stacking axis of ${parentKind} '${parentId}'; a stack's main-axis size is the sum of its children, so this fill is circular and has no defined size${hint}`,
|
|
2882
|
-
path: id
|
|
2883
|
-
});
|
|
2884
|
-
addCandidate(graph, slotId(id, dim), 0, `${kind}(${id}).fill-error`, priority);
|
|
2885
|
-
return true;
|
|
2886
|
-
}
|
|
2887
|
-
function applyContainerRule(rule, node, graph, parentId) {
|
|
2888
|
-
const id = node.id;
|
|
2889
|
-
const padding = getNumericProp(node, "padding", numericParamDefault(rule, "padding"));
|
|
2890
|
-
registerSizeSlots(node, graph, parentId);
|
|
2891
|
-
ensureSlot(graph, id, "contentWidth");
|
|
2892
|
-
ensureSlot(graph, id, "contentHeight");
|
|
2893
|
-
const widthIntent = getSizeProp(node, "width");
|
|
2894
|
-
const heightIntent = getSizeProp(node, "height");
|
|
2895
|
-
if (widthIntent === "fill" && parentId && !rejectMainAxisFill(node, graph, "resolvedWidth", "normal", parentId)) {
|
|
2896
|
-
const opId = `op.box.fillWidth.${id}`;
|
|
2897
|
-
const outSid = slotId(id, "resolvedWidth");
|
|
2898
|
-
ensureSlot(graph, parentId, "availableWidth");
|
|
2899
|
-
addCandidate(graph, outSid, void 0, `box(${id}).fill`, "normal", opId);
|
|
2900
|
-
addOperation(graph, opId, "resolveSize", [slotId(parentId, "availableWidth")], [outSid], (inputs) => {
|
|
2901
|
-
return [num(inputs[0])];
|
|
2995
|
+
addOperation(graph, colFillOpId, "columnFill", colFillInputs, colFillOutputs, (inputs) => {
|
|
2996
|
+
const resolvedW = num(inputs[0]);
|
|
2997
|
+
const availableW = resolvedW - padding * 2;
|
|
2998
|
+
const minWidths = inputs.slice(1).map((v) => num(v));
|
|
2999
|
+
const totalMin = minWidths.reduce((s, w) => s + w, 0) + gap * Math.max(0, maxCols - 1);
|
|
3000
|
+
const surplus = Math.max(0, availableW - totalMin);
|
|
3001
|
+
const surplusPerCol = surplus / maxCols;
|
|
3002
|
+
return minWidths.map((mw) => mw + surplusPerCol);
|
|
2902
3003
|
});
|
|
2903
3004
|
}
|
|
2904
|
-
|
|
2905
|
-
const
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
3005
|
+
for (let col = 0; col < maxCols; col++) {
|
|
3006
|
+
const cellIds = columnCellIds[col];
|
|
3007
|
+
if (cellIds.length === 0) continue;
|
|
3008
|
+
const cellWOpId = `op.grid.cellW.${id}.${col}`;
|
|
3009
|
+
const colResSlot = colResolvedWidthSlots[col];
|
|
3010
|
+
const cellWOutputs = cellIds.map((cid) => slotId(cid, "resolvedWidth"));
|
|
3011
|
+
for (const cid of cellIds) {
|
|
3012
|
+
addCandidate(graph, slotId(cid, "resolvedWidth"), void 0, `grid(${id}).cellW[${col}]`, "strong", cellWOpId);
|
|
3013
|
+
}
|
|
3014
|
+
addOperation(graph, cellWOpId, "copy", [colResSlot], cellWOutputs, (inputs) => {
|
|
3015
|
+
return cellIds.map(() => num(inputs[0]));
|
|
3016
|
+
});
|
|
3017
|
+
}
|
|
3018
|
+
for (let rowIdx = 0; rowIdx < rows.length; rowIdx++) {
|
|
3019
|
+
const cells = childrenOf(rows[rowIdx]).filter((c) => c.kind === cellKind);
|
|
3020
|
+
const cellIds = cells.map((c) => c.id);
|
|
3021
|
+
if (cellIds.length < 2) continue;
|
|
3022
|
+
const rowEqOpId = `op.grid.rowEq.${id}.${rowIdx}`;
|
|
3023
|
+
const heightInputs = cellIds.map((cid) => {
|
|
3024
|
+
ensureSlot(graph, cid, "contentHeight");
|
|
3025
|
+
return slotId(cid, "contentHeight");
|
|
3026
|
+
});
|
|
3027
|
+
const rowEqOutputs = cellIds.map((cid) => slotId(cid, "resolvedHeight"));
|
|
3028
|
+
const rowPaddings = cellIds.map((cid) => num(cellPaddingMap.get(cid)));
|
|
3029
|
+
for (const cid of cellIds) {
|
|
3030
|
+
addCandidate(graph, slotId(cid, "resolvedHeight"), void 0, `grid(${id}).rowEq[${rowIdx}]`, "strong", rowEqOpId);
|
|
3031
|
+
}
|
|
3032
|
+
addOperation(graph, rowEqOpId, "rowHeightResolve", heightInputs, rowEqOutputs, (inputs) => {
|
|
3033
|
+
const desiredHeights = inputs.map((h, i) => num(h) + rowPaddings[i] * 2);
|
|
3034
|
+
const maxH = Math.max(...desiredHeights, 0);
|
|
3035
|
+
return cellIds.map(() => maxH);
|
|
3036
|
+
});
|
|
3037
|
+
}
|
|
3038
|
+
for (const rowId of rowIds) {
|
|
3039
|
+
const rowWidthOpId = `op.grid.rowWidth.${id}.${rowId}`;
|
|
3040
|
+
const outSid = slotId(rowId, "resolvedWidth");
|
|
3041
|
+
addCandidate(graph, outSid, void 0, `grid(${id}).rowWidth`, "normal", rowWidthOpId);
|
|
3042
|
+
addOperation(graph, rowWidthOpId, "resolveSize", [slotId(id, "resolvedWidth")], [outSid], (inputs) => {
|
|
3043
|
+
return [num(inputs[0]) - padding * 2];
|
|
3044
|
+
});
|
|
3045
|
+
}
|
|
3046
|
+
for (let rowIdx = 0; rowIdx < rows.length; rowIdx++) {
|
|
3047
|
+
const cells = childrenOf(rows[rowIdx]).filter((c) => c.kind === cellKind);
|
|
3048
|
+
const cellIds = cells.map((c) => c.id);
|
|
3049
|
+
const rowHeightOpId = `op.grid.rowH.${id}.${rowIdx}`;
|
|
3050
|
+
const cellHeightInputs = cellIds.map((cid) => slotId(cid, "resolvedHeight"));
|
|
3051
|
+
const outSid = slotId(rowIds[rowIdx], "resolvedHeight");
|
|
3052
|
+
addCandidate(graph, outSid, void 0, `grid(${id}).rowH`, "normal", rowHeightOpId);
|
|
3053
|
+
addOperation(graph, rowHeightOpId, "max", cellHeightInputs, [outSid], (inputs) => {
|
|
3054
|
+
return [Math.max(...inputs, 0)];
|
|
2911
3055
|
});
|
|
2912
3056
|
}
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
3057
|
+
}
|
|
3058
|
+
function applyStubRule(node, graph, parentId) {
|
|
3059
|
+
const id = node.id;
|
|
3060
|
+
registerSizeSlots(node, graph, parentId);
|
|
3061
|
+
ensureSlot(graph, id, "contentWidth");
|
|
3062
|
+
ensureSlot(graph, id, "contentHeight");
|
|
3063
|
+
}
|
|
3064
|
+
var STACK_RULE = layoutRules["stack"];
|
|
3065
|
+
function applyLayoutFromRule(kind, node, graph, parentId) {
|
|
3066
|
+
if (STACK_RULE.applies_to && kind in STACK_RULE.applies_to) {
|
|
3067
|
+
const axisConfig = STACK_RULE.applies_to[kind];
|
|
3068
|
+
applyStackRule(STACK_RULE, axisConfig, kind, node, graph, parentId);
|
|
3069
|
+
return;
|
|
2921
3070
|
}
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
return [num(inputs[0]) + padding * 2];
|
|
2927
|
-
});
|
|
3071
|
+
let rule = layoutRules[kind];
|
|
3072
|
+
if (!rule) {
|
|
3073
|
+
applyStubRule(node, graph, parentId);
|
|
3074
|
+
return;
|
|
2928
3075
|
}
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
return [Math.max(num(inputs[0]) - padding * 2, 0)];
|
|
2934
|
-
});
|
|
2935
|
-
const availHeightOpId = `op.box.availH.${id}`;
|
|
2936
|
-
ensureSlot(graph, id, "availableHeight");
|
|
2937
|
-
addCandidate(graph, slotId(id, "availableHeight"), void 0, `box(${id}).availH`, "normal", availHeightOpId);
|
|
2938
|
-
addOperation(graph, availHeightOpId, "resolveSize", [slotId(id, "resolvedHeight")], [slotId(id, "availableHeight")], (inputs) => {
|
|
2939
|
-
return [Math.max(num(inputs[0]) - padding * 2, 0)];
|
|
2940
|
-
});
|
|
2941
|
-
const children = childrenOf(node);
|
|
2942
|
-
const contentChildIds = children.filter((c) => !isConstraintKind(c.kind)).map((c) => c.id);
|
|
2943
|
-
if (contentChildIds.length > 0) {
|
|
2944
|
-
for (const childId of contentChildIds) {
|
|
2945
|
-
ensureSlot(graph, childId, "resolvedWidth");
|
|
2946
|
-
ensureSlot(graph, childId, "resolvedHeight");
|
|
2947
|
-
ensureSlot(graph, childId, "localX");
|
|
2948
|
-
ensureSlot(graph, childId, "localY");
|
|
3076
|
+
if (rule.inherits) {
|
|
3077
|
+
const base = layoutRules[rule.inherits];
|
|
3078
|
+
if (base) {
|
|
3079
|
+
rule = { ...base, ...rule };
|
|
2949
3080
|
}
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
3081
|
+
}
|
|
3082
|
+
switch (rule.type) {
|
|
3083
|
+
case "root":
|
|
3084
|
+
applyRootRule(rule, node, graph);
|
|
3085
|
+
break;
|
|
3086
|
+
case "container":
|
|
3087
|
+
applyContainerRule(rule, node, graph, parentId);
|
|
3088
|
+
break;
|
|
3089
|
+
case "text_measurement":
|
|
3090
|
+
applyTextMeasurementRule(rule, node, graph, parentId);
|
|
3091
|
+
break;
|
|
3092
|
+
case "overlay":
|
|
3093
|
+
applyOverlayRule(rule, node, graph, parentId);
|
|
3094
|
+
break;
|
|
3095
|
+
case "connector":
|
|
3096
|
+
applyConnectorRule(rule, node, graph);
|
|
3097
|
+
break;
|
|
3098
|
+
case "fixed_size":
|
|
3099
|
+
applyFixedSizeRule(rule, node, graph, parentId);
|
|
3100
|
+
break;
|
|
3101
|
+
case "grid":
|
|
3102
|
+
applyGridRule(rule, node, graph, parentId);
|
|
3103
|
+
break;
|
|
3104
|
+
default:
|
|
3105
|
+
applyStubRule(node, graph, parentId);
|
|
3106
|
+
break;
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3109
|
+
|
|
3110
|
+
// src/ir/index.ts
|
|
3111
|
+
var IrNodeSchema = z.lazy(
|
|
3112
|
+
() => z.object({
|
|
3113
|
+
kind: z.string(),
|
|
3114
|
+
id: z.string().optional(),
|
|
3115
|
+
props: z.record(z.string(), z.unknown()),
|
|
3116
|
+
children: z.array(IrNodeSchema).optional()
|
|
3117
|
+
})
|
|
3118
|
+
);
|
|
3119
|
+
function validateNode(node, path) {
|
|
3120
|
+
if (!(node.kind in ELEMENT_CATALOG)) {
|
|
3121
|
+
throw new Error(`Invalid element kind '${node.kind}' at ${path}`);
|
|
3122
|
+
}
|
|
3123
|
+
const allowed = getAllowedProps(node.kind);
|
|
3124
|
+
if (allowed) {
|
|
3125
|
+
const unknownProps = Object.keys(node.props).filter((k) => !allowed.has(k));
|
|
3126
|
+
if (unknownProps.length > 0) {
|
|
3127
|
+
throw new Error(
|
|
3128
|
+
`Unknown properties for '${node.kind}' at ${path}: ${unknownProps.join(", ")}`
|
|
3129
|
+
);
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
if (node.children) {
|
|
3133
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
3134
|
+
validateNode(node.children[i], `${path}.children[${i}]`);
|
|
2972
3135
|
}
|
|
2973
|
-
addOperation(graph, alignOpId, "resolveSize", alignInputs, alignOutputs, (inputs) => {
|
|
2974
|
-
const boxW = num(inputs[0]);
|
|
2975
|
-
const boxH = num(inputs[1]);
|
|
2976
|
-
const nChildren = contentChildIds.length;
|
|
2977
|
-
const result = [];
|
|
2978
|
-
for (let i = 0; i < nChildren; i++) {
|
|
2979
|
-
const cw = num(inputs[2 + i]);
|
|
2980
|
-
const ch = num(inputs[2 + nChildren + i]);
|
|
2981
|
-
let cx;
|
|
2982
|
-
if (colAlign !== void 0) {
|
|
2983
|
-
switch (colAlign) {
|
|
2984
|
-
case "center":
|
|
2985
|
-
cx = (boxW - cw) / 2;
|
|
2986
|
-
break;
|
|
2987
|
-
case "right":
|
|
2988
|
-
cx = boxW - cw - padding;
|
|
2989
|
-
break;
|
|
2990
|
-
default:
|
|
2991
|
-
cx = padding;
|
|
2992
|
-
break;
|
|
2993
|
-
}
|
|
2994
|
-
} else {
|
|
2995
|
-
cx = (boxW - cw) / 2;
|
|
2996
|
-
}
|
|
2997
|
-
let cy;
|
|
2998
|
-
if (rowAlign !== void 0) {
|
|
2999
|
-
switch (rowAlign) {
|
|
3000
|
-
case "center":
|
|
3001
|
-
cy = (boxH - ch) / 2;
|
|
3002
|
-
break;
|
|
3003
|
-
case "bottom":
|
|
3004
|
-
cy = boxH - ch - padding;
|
|
3005
|
-
break;
|
|
3006
|
-
default:
|
|
3007
|
-
cy = padding;
|
|
3008
|
-
break;
|
|
3009
|
-
}
|
|
3010
|
-
} else {
|
|
3011
|
-
cy = (boxH - ch) / 2;
|
|
3012
|
-
}
|
|
3013
|
-
result.push(cx, cy);
|
|
3014
|
-
}
|
|
3015
|
-
return result;
|
|
3016
|
-
});
|
|
3017
3136
|
}
|
|
3018
3137
|
}
|
|
3019
|
-
function
|
|
3020
|
-
const
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3138
|
+
function parseIr(json) {
|
|
3139
|
+
const parsed = IrNodeSchema.parse(json);
|
|
3140
|
+
validateNode(parsed, "root");
|
|
3141
|
+
return parsed;
|
|
3142
|
+
}
|
|
3143
|
+
|
|
3144
|
+
// src/parser/tokenizer.ts
|
|
3145
|
+
var SHAPE_PATTERNS = [
|
|
3146
|
+
{ shape: "capsule", open: "([", close: "])" },
|
|
3147
|
+
{ shape: "cylinder", open: "[(", close: ")]" },
|
|
3148
|
+
{ shape: "circle", open: "((", close: "))" },
|
|
3149
|
+
{ shape: "hexagon", open: "[[", close: "]]" },
|
|
3150
|
+
{ shape: "roundedRect", open: "[", close: "]" },
|
|
3151
|
+
{ shape: "diamond", open: "{", close: "}" },
|
|
3152
|
+
{ shape: "rect", open: "(", close: ")" }
|
|
3153
|
+
];
|
|
3154
|
+
var SHAPE_ALIASES = {
|
|
3155
|
+
stadium: "capsule",
|
|
3156
|
+
pill: "capsule",
|
|
3157
|
+
rounded: "roundedRect",
|
|
3158
|
+
db: "cylinder",
|
|
3159
|
+
database: "cylinder",
|
|
3160
|
+
cyl: "cylinder",
|
|
3161
|
+
decision: "diamond",
|
|
3162
|
+
hex: "hexagon",
|
|
3163
|
+
tri: "triangle"
|
|
3164
|
+
};
|
|
3165
|
+
function parseNodeShape(rest) {
|
|
3166
|
+
let shapeOverride;
|
|
3167
|
+
let cursor = 0;
|
|
3168
|
+
if (rest.startsWith("@")) {
|
|
3169
|
+
const atMatch = rest.match(/^@(\w+)/);
|
|
3170
|
+
if (!atMatch) return null;
|
|
3171
|
+
shapeOverride = SHAPE_ALIASES[atMatch[1]] ?? atMatch[1];
|
|
3172
|
+
cursor = atMatch[0].length;
|
|
3173
|
+
}
|
|
3174
|
+
const remaining = rest.slice(cursor);
|
|
3175
|
+
for (const { shape, open, close } of SHAPE_PATTERNS) {
|
|
3176
|
+
if (!remaining.startsWith(open)) continue;
|
|
3177
|
+
const contentStart = open.length;
|
|
3178
|
+
const closeIdx = remaining.indexOf(close, contentStart);
|
|
3179
|
+
if (closeIdx === -1) continue;
|
|
3180
|
+
const afterClose = remaining.slice(closeIdx + close.length);
|
|
3181
|
+
if (afterClose.length > 0 && /^[a-zA-Z0-9_-]/.test(afterClose)) continue;
|
|
3182
|
+
let label = remaining.slice(contentStart, closeIdx);
|
|
3183
|
+
if (label.startsWith('"') && label.endsWith('"')) {
|
|
3184
|
+
label = label.slice(1, -1);
|
|
3185
|
+
}
|
|
3186
|
+
return {
|
|
3187
|
+
label,
|
|
3188
|
+
shape: shapeOverride ?? shape,
|
|
3189
|
+
shapeOverride,
|
|
3190
|
+
consumed: cursor + closeIdx + close.length
|
|
3191
|
+
};
|
|
3192
|
+
}
|
|
3193
|
+
return null;
|
|
3194
|
+
}
|
|
3195
|
+
function matchEdgeOp(s) {
|
|
3196
|
+
const trimmed = s.trimStart();
|
|
3197
|
+
for (const op of ["==>", "-.->", "-->", "---", "~~~"]) {
|
|
3198
|
+
if (!trimmed.startsWith(op)) continue;
|
|
3199
|
+
let after = trimmed.slice(op.length);
|
|
3200
|
+
let label;
|
|
3201
|
+
if (op !== "~~~" && after.startsWith("|")) {
|
|
3202
|
+
const pipeEnd = after.indexOf("|", 1);
|
|
3203
|
+
if (pipeEnd !== -1) {
|
|
3204
|
+
label = after.slice(1, pipeEnd).trim();
|
|
3205
|
+
after = after.slice(pipeEnd + 1);
|
|
3206
|
+
}
|
|
3207
|
+
}
|
|
3208
|
+
return { op, label, rest: after };
|
|
3040
3209
|
}
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
default:
|
|
3055
|
-
textAnchorVal = 1;
|
|
3056
|
-
break;
|
|
3210
|
+
return null;
|
|
3211
|
+
}
|
|
3212
|
+
function parseNodeRef(s) {
|
|
3213
|
+
const trimmed = s.trimStart();
|
|
3214
|
+
const idMatch = trimmed.match(/^([a-zA-Z_][a-zA-Z0-9_-]*)/);
|
|
3215
|
+
if (!idMatch) return null;
|
|
3216
|
+
const nodeId = idMatch[1];
|
|
3217
|
+
let after = trimmed.slice(idMatch[0].length);
|
|
3218
|
+
const shapeParsed = parseNodeShape(after);
|
|
3219
|
+
let def;
|
|
3220
|
+
if (shapeParsed) {
|
|
3221
|
+
after = after.slice(shapeParsed.consumed);
|
|
3222
|
+
def = { label: shapeParsed.label, shape: shapeParsed.shape, shapeOverride: shapeParsed.shapeOverride };
|
|
3057
3223
|
}
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
slotId(id, "textAnchor"),
|
|
3068
|
-
slotId(id, "textLineHeight")
|
|
3069
|
-
];
|
|
3070
|
-
addCandidate(graph, slotId(id, "textBaseline"), void 0, `text(${id}).layout`, "normal", textLayoutOpId);
|
|
3071
|
-
addCandidate(graph, slotId(id, "textX"), void 0, `text(${id}).layout`, "normal", textLayoutOpId);
|
|
3072
|
-
addCandidate(graph, slotId(id, "textAnchor"), void 0, `text(${id}).layout`, "normal", textLayoutOpId);
|
|
3073
|
-
addCandidate(graph, slotId(id, "textLineHeight"), void 0, `text(${id}).layout`, "normal", textLayoutOpId);
|
|
3074
|
-
addOperation(graph, textLayoutOpId, "identity", textLayoutInputs, textLayoutOutputs, (inputs) => {
|
|
3075
|
-
const w = num(inputs[0]);
|
|
3076
|
-
const h = num(inputs[1]);
|
|
3077
|
-
const visualExtent = capHeight + (lineCount - 1) * lineHeight;
|
|
3078
|
-
const baseline = (h - visualExtent) / 2 + capHeight;
|
|
3079
|
-
let tx;
|
|
3080
|
-
switch (textAnchorVal) {
|
|
3081
|
-
case 0:
|
|
3082
|
-
tx = 0;
|
|
3083
|
-
break;
|
|
3084
|
-
case 2:
|
|
3085
|
-
tx = w;
|
|
3086
|
-
break;
|
|
3087
|
-
default:
|
|
3088
|
-
tx = w / 2;
|
|
3089
|
-
break;
|
|
3224
|
+
if (after.startsWith(":::")) {
|
|
3225
|
+
const classMatch = after.slice(3).match(/^([a-zA-Z_][a-zA-Z0-9_-]*)/);
|
|
3226
|
+
if (classMatch) {
|
|
3227
|
+
if (def) {
|
|
3228
|
+
def.variant = classMatch[1];
|
|
3229
|
+
} else {
|
|
3230
|
+
def = { label: nodeId, shape: "roundedRect", variant: classMatch[1] };
|
|
3231
|
+
}
|
|
3232
|
+
after = after.slice(3 + classMatch[0].length);
|
|
3090
3233
|
}
|
|
3091
|
-
|
|
3092
|
-
}
|
|
3234
|
+
}
|
|
3235
|
+
return { nodeId, def, rest: after };
|
|
3093
3236
|
}
|
|
3094
|
-
function
|
|
3095
|
-
const
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
ensureSlot(graph, id, "contentHeight");
|
|
3100
|
-
const children = childrenOf(node);
|
|
3101
|
-
const childIds = children.filter((c) => !isConstraintKind(c.kind)).map((c) => c.id);
|
|
3102
|
-
for (const childId of childIds) {
|
|
3103
|
-
ensureSlot(graph, childId, "localX", padding);
|
|
3104
|
-
ensureSlot(graph, childId, "localY", padding);
|
|
3105
|
-
addCandidate(graph, slotId(childId, "localX"), padding, `overlay(${id})`, "normal");
|
|
3106
|
-
addCandidate(graph, slotId(childId, "localY"), padding, `overlay(${id})`, "normal");
|
|
3237
|
+
function tokenizeLine(line, lineNum) {
|
|
3238
|
+
const trimmed = line.trim();
|
|
3239
|
+
if (trimmed === "") return null;
|
|
3240
|
+
if (trimmed.startsWith("%%")) {
|
|
3241
|
+
return { type: "comment", raw: line, line: lineNum };
|
|
3107
3242
|
}
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3243
|
+
const dirMatch = trimmed.match(/^(?:flowchart|graph)\s+(TD|TB|LR)$/i);
|
|
3244
|
+
if (dirMatch) {
|
|
3245
|
+
const dirRaw = dirMatch[1].toUpperCase();
|
|
3246
|
+
const dir = dirRaw === "TB" ? "TD" : dirRaw;
|
|
3247
|
+
if (dir !== "TD" && dir !== "LR") {
|
|
3248
|
+
return null;
|
|
3112
3249
|
}
|
|
3113
|
-
|
|
3114
|
-
const childWidthSlots = childIds.map((cid) => slotId(cid, "resolvedWidth"));
|
|
3115
|
-
const childHeightSlots = childIds.map((cid) => slotId(cid, "resolvedHeight"));
|
|
3116
|
-
const contentInputs = [...childWidthSlots, ...childHeightSlots];
|
|
3117
|
-
const contentOutputs = [slotId(id, "contentWidth"), slotId(id, "contentHeight")];
|
|
3118
|
-
addCandidate(graph, slotId(id, "contentWidth"), void 0, `overlay(${id}).childContent`, "normal", contentOpId);
|
|
3119
|
-
addCandidate(graph, slotId(id, "contentHeight"), void 0, `overlay(${id}).childContent`, "normal", contentOpId);
|
|
3120
|
-
addOperation(graph, contentOpId, "resolveSize", contentInputs, contentOutputs, (inputs) => {
|
|
3121
|
-
const nChildren = childIds.length;
|
|
3122
|
-
const widths = inputs.slice(0, nChildren);
|
|
3123
|
-
const heights = inputs.slice(nChildren);
|
|
3124
|
-
return [Math.max(...widths, 0), Math.max(...heights, 0)];
|
|
3125
|
-
});
|
|
3250
|
+
return { type: "direction", raw: line, line: lineNum, dir };
|
|
3126
3251
|
}
|
|
3127
|
-
const
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
}
|
|
3252
|
+
const subMatch = trimmed.match(/^subgraph\s+(\S+)(?:\s+\[([^\]]*)\])?\s*$/);
|
|
3253
|
+
if (subMatch) {
|
|
3254
|
+
return {
|
|
3255
|
+
type: "subgraphStart",
|
|
3256
|
+
raw: line,
|
|
3257
|
+
line: lineNum,
|
|
3258
|
+
subgraphId: subMatch[1],
|
|
3259
|
+
label: subMatch[2] ?? void 0
|
|
3260
|
+
};
|
|
3136
3261
|
}
|
|
3137
|
-
if (
|
|
3138
|
-
|
|
3139
|
-
const outSid = slotId(id, "resolvedHeight");
|
|
3140
|
-
addCandidate(graph, outSid, void 0, `overlay(${id}).wrap`, "weak", wrapHeightOpId);
|
|
3141
|
-
addOperation(graph, wrapHeightOpId, "resolveSize", [slotId(id, "contentHeight")], [outSid], (inputs) => {
|
|
3142
|
-
return [num(inputs[0]) + padding * 2];
|
|
3143
|
-
});
|
|
3262
|
+
if (trimmed === "end") {
|
|
3263
|
+
return { type: "subgraphEnd", raw: line, line: lineNum };
|
|
3144
3264
|
}
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
const
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
addOperation(graph, fillWidthOpId, "resolveSize", [slotId(parentId, "availableWidth")], [outSid], (inputs) => {
|
|
3151
|
-
return [num(inputs[0])];
|
|
3152
|
-
});
|
|
3265
|
+
const localDirMatch = trimmed.match(/^direction\s+(TD|TB|LR)$/i);
|
|
3266
|
+
if (localDirMatch) {
|
|
3267
|
+
const dirRaw = localDirMatch[1].toUpperCase();
|
|
3268
|
+
const dir = dirRaw === "TB" ? "TD" : dirRaw;
|
|
3269
|
+
return { type: "localDirection", raw: line, line: lineNum, dir };
|
|
3153
3270
|
}
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3271
|
+
const classDefMatch = trimmed.match(/^classDef\s+(\S+)\s+(.+)$/);
|
|
3272
|
+
if (classDefMatch) {
|
|
3273
|
+
return {
|
|
3274
|
+
type: "classDef",
|
|
3275
|
+
raw: line,
|
|
3276
|
+
line: lineNum,
|
|
3277
|
+
className: classDefMatch[1],
|
|
3278
|
+
styles: classDefMatch[2]
|
|
3279
|
+
};
|
|
3280
|
+
}
|
|
3281
|
+
if (trimmed.startsWith("@")) {
|
|
3282
|
+
return parseDirective(trimmed, line, lineNum);
|
|
3283
|
+
}
|
|
3284
|
+
return parseEdgeOrNodeLine(trimmed, line, lineNum);
|
|
3285
|
+
}
|
|
3286
|
+
var SAME_SIZE_DEFAULT_STRATEGY = "max";
|
|
3287
|
+
function parseDirective(trimmed, raw, lineNum) {
|
|
3288
|
+
const sameWidthMatch = trimmed.match(/^@same-width(?:\s+(\w+))?:\s*(.+)$/);
|
|
3289
|
+
if (sameWidthMatch) {
|
|
3290
|
+
const strategy = sameWidthMatch[1] ?? SAME_SIZE_DEFAULT_STRATEGY;
|
|
3291
|
+
const targets = sameWidthMatch[2].split(",").map((t) => t.trim()).filter(Boolean);
|
|
3292
|
+
return {
|
|
3293
|
+
type: "directive",
|
|
3294
|
+
raw,
|
|
3295
|
+
line: lineNum,
|
|
3296
|
+
directiveType: "same-width",
|
|
3297
|
+
strategy,
|
|
3298
|
+
targets
|
|
3299
|
+
};
|
|
3300
|
+
}
|
|
3301
|
+
const sameHeightMatch = trimmed.match(/^@same-height(?:\s+(\w+))?:\s*(.+)$/);
|
|
3302
|
+
if (sameHeightMatch) {
|
|
3303
|
+
const strategy = sameHeightMatch[1] ?? SAME_SIZE_DEFAULT_STRATEGY;
|
|
3304
|
+
const targets = sameHeightMatch[2].split(",").map((t) => t.trim()).filter(Boolean);
|
|
3305
|
+
return {
|
|
3306
|
+
type: "directive",
|
|
3307
|
+
raw,
|
|
3308
|
+
line: lineNum,
|
|
3309
|
+
directiveType: "same-height",
|
|
3310
|
+
strategy,
|
|
3311
|
+
targets
|
|
3312
|
+
};
|
|
3313
|
+
}
|
|
3314
|
+
const gapMatch = trimmed.match(/^@gap\s+min=(\d+):\s*(.+)$/);
|
|
3315
|
+
if (gapMatch) {
|
|
3316
|
+
const min = parseInt(gapMatch[1], 10);
|
|
3317
|
+
const targets = gapMatch[2].split(",").map((t) => t.trim()).filter(Boolean);
|
|
3318
|
+
return {
|
|
3319
|
+
type: "directive",
|
|
3320
|
+
raw,
|
|
3321
|
+
line: lineNum,
|
|
3322
|
+
directiveType: "gap",
|
|
3323
|
+
min,
|
|
3324
|
+
targets
|
|
3325
|
+
};
|
|
3326
|
+
}
|
|
3327
|
+
const moverMatch = trimmed.match(/^@mover\s+(\S+):\s*(.+)$/);
|
|
3328
|
+
if (moverMatch) {
|
|
3329
|
+
const moverId = moverMatch[1];
|
|
3330
|
+
const targets = moverMatch[2].split(",").map((t) => t.trim()).filter(Boolean);
|
|
3331
|
+
return {
|
|
3332
|
+
type: "directive",
|
|
3333
|
+
raw,
|
|
3334
|
+
line: lineNum,
|
|
3335
|
+
directiveType: "mover",
|
|
3336
|
+
moverId,
|
|
3337
|
+
targets
|
|
3338
|
+
};
|
|
3339
|
+
}
|
|
3340
|
+
return null;
|
|
3341
|
+
}
|
|
3342
|
+
function parseEdgeOrNodeLine(trimmed, raw, lineNum) {
|
|
3343
|
+
const firstRef = parseNodeRef(trimmed);
|
|
3344
|
+
if (!firstRef) return null;
|
|
3345
|
+
let cursor = trimmed.length - firstRef.rest.length;
|
|
3346
|
+
let remaining = firstRef.rest;
|
|
3347
|
+
const edgeMatch = matchEdgeOp(remaining);
|
|
3348
|
+
if (!edgeMatch) {
|
|
3349
|
+
if (!firstRef.def) {
|
|
3350
|
+
return null;
|
|
3351
|
+
}
|
|
3352
|
+
return {
|
|
3353
|
+
type: "nodeDef",
|
|
3354
|
+
raw,
|
|
3355
|
+
line: lineNum,
|
|
3356
|
+
nodeId: firstRef.nodeId,
|
|
3357
|
+
label: firstRef.def.label,
|
|
3358
|
+
shape: firstRef.def.shape,
|
|
3359
|
+
variant: firstRef.def.variant,
|
|
3360
|
+
shapeOverride: firstRef.def.shapeOverride
|
|
3361
|
+
};
|
|
3162
3362
|
}
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
addCandidate(graph, slotId(id, "availableWidth"), void 0, `overlay(${id}).availW`, "normal", availWidthOpId);
|
|
3166
|
-
addOperation(graph, availWidthOpId, "resolveSize", [slotId(id, "resolvedWidth")], [slotId(id, "availableWidth")], (inputs) => {
|
|
3167
|
-
return [Math.max(num(inputs[0]) - padding * 2, 0)];
|
|
3168
|
-
});
|
|
3169
|
-
const availHeightOpId = `op.overlay.availH.${id}`;
|
|
3170
|
-
ensureSlot(graph, id, "availableHeight");
|
|
3171
|
-
addCandidate(graph, slotId(id, "availableHeight"), void 0, `overlay(${id}).availH`, "normal", availHeightOpId);
|
|
3172
|
-
addOperation(graph, availHeightOpId, "resolveSize", [slotId(id, "resolvedHeight")], [slotId(id, "availableHeight")], (inputs) => {
|
|
3173
|
-
return [Math.max(num(inputs[0]) - padding * 2, 0)];
|
|
3174
|
-
});
|
|
3175
|
-
}
|
|
3176
|
-
function applyConnectorRule(_rule, node, graph) {
|
|
3177
|
-
const id = node.id;
|
|
3178
|
-
const fromId = node.props.from;
|
|
3179
|
-
const toId = node.props.to;
|
|
3180
|
-
ensureSlot(graph, id, "resolvedWidth", 0);
|
|
3181
|
-
ensureSlot(graph, id, "resolvedHeight", 0);
|
|
3182
|
-
ensureSlot(graph, id, "localX", 0);
|
|
3183
|
-
ensureSlot(graph, id, "localY", 0);
|
|
3184
|
-
ensureSlot(graph, id, "connectorPath");
|
|
3185
|
-
if (fromId && toId) {
|
|
3186
|
-
ensureSlot(graph, fromId, "localX");
|
|
3187
|
-
ensureSlot(graph, fromId, "localY");
|
|
3188
|
-
ensureSlot(graph, fromId, "resolvedWidth");
|
|
3189
|
-
ensureSlot(graph, fromId, "resolvedHeight");
|
|
3190
|
-
ensureSlot(graph, toId, "localX");
|
|
3191
|
-
ensureSlot(graph, toId, "localY");
|
|
3192
|
-
ensureSlot(graph, toId, "resolvedWidth");
|
|
3193
|
-
ensureSlot(graph, toId, "resolvedHeight");
|
|
3194
|
-
addCandidate(graph, slotId(id, "connectorPath"), 0, `connector(${id})`, "normal");
|
|
3363
|
+
if (edgeMatch.op === "~~~") {
|
|
3364
|
+
return parseInvisibleEdgeChain(trimmed, firstRef, raw, lineNum);
|
|
3195
3365
|
}
|
|
3366
|
+
return parseVisibleEdgeChain(trimmed, firstRef, raw, lineNum);
|
|
3196
3367
|
}
|
|
3197
|
-
function
|
|
3198
|
-
const
|
|
3199
|
-
|
|
3200
|
-
let
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3368
|
+
function parseInvisibleEdgeChain(input, firstRef, raw, lineNum) {
|
|
3369
|
+
const segments = [];
|
|
3370
|
+
let currentId = firstRef.nodeId;
|
|
3371
|
+
let remaining = firstRef.rest;
|
|
3372
|
+
while (true) {
|
|
3373
|
+
const edgeMatch = matchEdgeOp(remaining);
|
|
3374
|
+
if (!edgeMatch || edgeMatch.op !== "~~~") break;
|
|
3375
|
+
remaining = edgeMatch.rest;
|
|
3376
|
+
const nextRef = parseNodeRef(remaining);
|
|
3377
|
+
if (!nextRef) break;
|
|
3378
|
+
segments.push({ fromId: currentId, toId: nextRef.nodeId });
|
|
3379
|
+
currentId = nextRef.nodeId;
|
|
3380
|
+
remaining = nextRef.rest;
|
|
3210
3381
|
}
|
|
3211
|
-
|
|
3212
|
-
ensureSlot(graph, id, "localY", 0);
|
|
3213
|
-
const priority = kind === "divider" ? "weak" : "normal";
|
|
3214
|
-
applyFixedSizeDimension(node, graph, "resolvedWidth", widthSpec, priority, parentId);
|
|
3215
|
-
applyFixedSizeDimension(node, graph, "resolvedHeight", heightSpec, priority, parentId);
|
|
3382
|
+
return { type: "invisibleEdge", raw, line: lineNum, segments };
|
|
3216
3383
|
}
|
|
3217
|
-
function
|
|
3218
|
-
const
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3384
|
+
function parseVisibleEdgeChain(input, firstRef, raw, lineNum) {
|
|
3385
|
+
const segments = [];
|
|
3386
|
+
let currentId = firstRef.nodeId;
|
|
3387
|
+
let currentDef = firstRef.def;
|
|
3388
|
+
let remaining = firstRef.rest;
|
|
3389
|
+
while (true) {
|
|
3390
|
+
const edgeMatch = matchEdgeOp(remaining);
|
|
3391
|
+
if (!edgeMatch || edgeMatch.op === "~~~") break;
|
|
3392
|
+
remaining = edgeMatch.rest;
|
|
3393
|
+
let colonLabel;
|
|
3394
|
+
const nextRef = parseNodeRef(remaining);
|
|
3395
|
+
if (!nextRef) break;
|
|
3396
|
+
remaining = nextRef.rest;
|
|
3397
|
+
const colonMatch = remaining.match(/^\s*:\s*(.+?)$/);
|
|
3398
|
+
if (colonMatch) {
|
|
3399
|
+
colonLabel = colonMatch[1].trim();
|
|
3400
|
+
remaining = "";
|
|
3401
|
+
}
|
|
3402
|
+
const seg = {
|
|
3403
|
+
fromId: currentId,
|
|
3404
|
+
toId: nextRef.nodeId,
|
|
3405
|
+
edgeType: edgeMatch.op,
|
|
3406
|
+
edgeLabel: edgeMatch.label ?? colonLabel
|
|
3407
|
+
};
|
|
3408
|
+
if (currentDef) {
|
|
3409
|
+
seg.fromDef = currentDef;
|
|
3410
|
+
}
|
|
3411
|
+
if (nextRef.def) {
|
|
3412
|
+
seg.toDef = nextRef.def;
|
|
3413
|
+
}
|
|
3414
|
+
segments.push(seg);
|
|
3415
|
+
currentId = nextRef.nodeId;
|
|
3416
|
+
currentDef = nextRef.def;
|
|
3225
3417
|
}
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
});
|
|
3237
|
-
return;
|
|
3418
|
+
return { type: "edge", raw, line: lineNum, segments };
|
|
3419
|
+
}
|
|
3420
|
+
function tokenize(source) {
|
|
3421
|
+
const lines = source.split("\n");
|
|
3422
|
+
const tokens = [];
|
|
3423
|
+
for (let i = 0; i < lines.length; i++) {
|
|
3424
|
+
const token = tokenizeLine(lines[i], i + 1);
|
|
3425
|
+
if (token) {
|
|
3426
|
+
tokens.push(token);
|
|
3427
|
+
}
|
|
3238
3428
|
}
|
|
3239
|
-
|
|
3429
|
+
return tokens;
|
|
3240
3430
|
}
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
const
|
|
3245
|
-
const
|
|
3246
|
-
|
|
3247
|
-
const
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
const
|
|
3252
|
-
|
|
3253
|
-
const
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3431
|
+
|
|
3432
|
+
// src/parser/parser.ts
|
|
3433
|
+
function parseDrawText(source) {
|
|
3434
|
+
const diagnostics = [];
|
|
3435
|
+
const tokens = tokenize(source);
|
|
3436
|
+
let rootDirection = "TD";
|
|
3437
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
3438
|
+
const connectors = [];
|
|
3439
|
+
const constraints = [];
|
|
3440
|
+
const classDefMap = /* @__PURE__ */ new Map();
|
|
3441
|
+
const scopeStack = [];
|
|
3442
|
+
const groups = [];
|
|
3443
|
+
const rootNodeIds = [];
|
|
3444
|
+
function currentDirection() {
|
|
3445
|
+
for (let i = scopeStack.length - 1; i >= 0; i--) {
|
|
3446
|
+
if (scopeStack[i].direction) return scopeStack[i].direction;
|
|
3447
|
+
}
|
|
3448
|
+
return rootDirection;
|
|
3259
3449
|
}
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
addCandidate(graph, slotId(rid, "localX"), void 0, `grid(${id}).rowX`, "normal", rowPosOpId);
|
|
3450
|
+
function registerNode(id, label, shape, variant) {
|
|
3451
|
+
if (!nodeMap.has(id)) {
|
|
3452
|
+
nodeMap.set(id, { id, label, shape, variant });
|
|
3453
|
+
}
|
|
3454
|
+
if (scopeStack.length > 0) {
|
|
3455
|
+
const top = scopeStack[scopeStack.length - 1];
|
|
3456
|
+
if (!top.nodeIds.includes(id)) top.nodeIds.push(id);
|
|
3457
|
+
} else {
|
|
3458
|
+
if (!rootNodeIds.includes(id)) rootNodeIds.push(id);
|
|
3459
|
+
}
|
|
3271
3460
|
}
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3461
|
+
function ensureNode(id) {
|
|
3462
|
+
if (nodeMap.has(id)) return;
|
|
3463
|
+
nodeMap.set(id, { id, label: id, shape: "roundedRect" });
|
|
3464
|
+
if (scopeStack.length > 0) {
|
|
3465
|
+
const top = scopeStack[scopeStack.length - 1];
|
|
3466
|
+
if (!top.nodeIds.includes(id)) top.nodeIds.push(id);
|
|
3467
|
+
} else {
|
|
3468
|
+
if (!rootNodeIds.includes(id)) rootNodeIds.push(id);
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
for (const token of tokens) {
|
|
3472
|
+
switch (token.type) {
|
|
3473
|
+
case "comment":
|
|
3474
|
+
break;
|
|
3475
|
+
case "direction":
|
|
3476
|
+
rootDirection = token.dir;
|
|
3477
|
+
break;
|
|
3478
|
+
case "nodeDef": {
|
|
3479
|
+
const t = token;
|
|
3480
|
+
registerNode(t.nodeId, t.label, t.shape, t.variant);
|
|
3481
|
+
break;
|
|
3482
|
+
}
|
|
3483
|
+
case "edge": {
|
|
3484
|
+
const t = token;
|
|
3485
|
+
for (const seg of t.segments) {
|
|
3486
|
+
processEdgeSegment(seg);
|
|
3487
|
+
}
|
|
3488
|
+
break;
|
|
3489
|
+
}
|
|
3490
|
+
case "invisibleEdge": {
|
|
3491
|
+
const t = token;
|
|
3492
|
+
for (const seg of t.segments) {
|
|
3493
|
+
ensureNode(seg.fromId);
|
|
3494
|
+
ensureNode(seg.toId);
|
|
3495
|
+
}
|
|
3496
|
+
const dir = currentDirection();
|
|
3497
|
+
const allIds = /* @__PURE__ */ new Set();
|
|
3498
|
+
for (const seg of t.segments) {
|
|
3499
|
+
allIds.add(seg.fromId);
|
|
3500
|
+
allIds.add(seg.toId);
|
|
3501
|
+
}
|
|
3502
|
+
constraints.push(buildAlignConstraint([...allIds], dir));
|
|
3503
|
+
break;
|
|
3504
|
+
}
|
|
3505
|
+
case "subgraphStart": {
|
|
3506
|
+
const t = token;
|
|
3507
|
+
scopeStack.push({
|
|
3508
|
+
id: t.subgraphId,
|
|
3509
|
+
label: t.label,
|
|
3510
|
+
nodeIds: []
|
|
3511
|
+
});
|
|
3512
|
+
break;
|
|
3513
|
+
}
|
|
3514
|
+
case "subgraphEnd": {
|
|
3515
|
+
if (scopeStack.length === 0) {
|
|
3516
|
+
diagnostics.push({
|
|
3517
|
+
level: "warning",
|
|
3518
|
+
message: "Unexpected 'end' without matching subgraph",
|
|
3519
|
+
path: `line:${token.line}`
|
|
3520
|
+
});
|
|
3521
|
+
break;
|
|
3522
|
+
}
|
|
3523
|
+
const frame = scopeStack.pop();
|
|
3524
|
+
groups.push({ frame, children: [...frame.nodeIds] });
|
|
3525
|
+
if (scopeStack.length > 0) {
|
|
3526
|
+
const parent = scopeStack[scopeStack.length - 1];
|
|
3527
|
+
if (!parent.nodeIds.includes(frame.id)) parent.nodeIds.push(frame.id);
|
|
3528
|
+
} else {
|
|
3529
|
+
if (!rootNodeIds.includes(frame.id)) rootNodeIds.push(frame.id);
|
|
3530
|
+
}
|
|
3531
|
+
break;
|
|
3532
|
+
}
|
|
3533
|
+
case "localDirection": {
|
|
3534
|
+
const t = token;
|
|
3535
|
+
if (scopeStack.length > 0) {
|
|
3536
|
+
scopeStack[scopeStack.length - 1].direction = t.dir;
|
|
3537
|
+
} else {
|
|
3538
|
+
rootDirection = t.dir;
|
|
3539
|
+
}
|
|
3540
|
+
break;
|
|
3541
|
+
}
|
|
3542
|
+
case "classDef": {
|
|
3543
|
+
const t = token;
|
|
3544
|
+
classDefMap.set(t.className, t.styles);
|
|
3545
|
+
break;
|
|
3546
|
+
}
|
|
3547
|
+
case "directive": {
|
|
3548
|
+
const t = token;
|
|
3549
|
+
processDirective(t);
|
|
3550
|
+
break;
|
|
3551
|
+
}
|
|
3280
3552
|
}
|
|
3281
|
-
const contentH = y - padding;
|
|
3282
|
-
const totalH = contentH + padding * 2;
|
|
3283
|
-
const xPositions = rowIds.map(() => padding);
|
|
3284
|
-
return [...yPositions, ...xPositions, contentH, totalH];
|
|
3285
|
-
});
|
|
3286
|
-
const maxCols = Math.max(...rows.map((r) => childrenOf(r).filter((c) => c.kind === cellKind).length));
|
|
3287
|
-
const columnCellIds = [];
|
|
3288
|
-
for (let col = 0; col < maxCols; col++) {
|
|
3289
|
-
columnCellIds.push([]);
|
|
3290
3553
|
}
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3554
|
+
function processEdgeSegment(seg) {
|
|
3555
|
+
if (seg.fromDef) {
|
|
3556
|
+
registerNode(seg.fromId, seg.fromDef.label, seg.fromDef.shape, seg.fromDef.variant);
|
|
3557
|
+
} else {
|
|
3558
|
+
ensureNode(seg.fromId);
|
|
3295
3559
|
}
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
cellPaddingMap.set(cell.id, getNumericProp(cell, "padding", 0));
|
|
3560
|
+
if (seg.toDef) {
|
|
3561
|
+
registerNode(seg.toId, seg.toDef.label, seg.toDef.shape, seg.toDef.variant);
|
|
3562
|
+
} else {
|
|
3563
|
+
ensureNode(seg.toId);
|
|
3301
3564
|
}
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3565
|
+
const connectorProps = {
|
|
3566
|
+
from: seg.fromId,
|
|
3567
|
+
to: seg.toId
|
|
3568
|
+
};
|
|
3569
|
+
switch (seg.edgeType) {
|
|
3570
|
+
case "-->":
|
|
3571
|
+
connectorProps.endArrow = "arrow";
|
|
3572
|
+
break;
|
|
3573
|
+
case "---":
|
|
3574
|
+
connectorProps.startArrow = "none";
|
|
3575
|
+
connectorProps.endArrow = "none";
|
|
3576
|
+
break;
|
|
3577
|
+
case "-.->":
|
|
3578
|
+
connectorProps.strokeStyle = "dashed";
|
|
3579
|
+
connectorProps.endArrow = "arrow";
|
|
3580
|
+
break;
|
|
3581
|
+
case "==>":
|
|
3582
|
+
connectorProps.strokeWidth = 3;
|
|
3583
|
+
connectorProps.endArrow = "arrow";
|
|
3584
|
+
break;
|
|
3321
3585
|
}
|
|
3322
|
-
const
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
addCandidate(graph, colMinSlot, void 0, `grid(${id}).colMin[${col}]`, "strong", colEqOpId);
|
|
3329
|
-
addOperation(graph, colEqOpId, "columnWidthResolve", widthInputs, [colMinSlot], (inputs) => {
|
|
3330
|
-
const desiredWidths = inputs.map((w, i) => num(w) + colPaddings[i] * 2);
|
|
3331
|
-
return [Math.max(...desiredWidths, 0)];
|
|
3332
|
-
});
|
|
3333
|
-
}
|
|
3334
|
-
if (maxCols > 0) {
|
|
3335
|
-
const wrapWidthOpId = `op.grid.wrapWidth.${id}`;
|
|
3336
|
-
const wrapOutputs = [slotId(id, "contentWidth"), slotId(id, "resolvedWidth")];
|
|
3337
|
-
addCandidate(graph, slotId(id, "contentWidth"), void 0, `grid(${id}).wrapContentW`, "normal", wrapWidthOpId);
|
|
3338
|
-
addCandidate(graph, slotId(id, "resolvedWidth"), void 0, `grid(${id}).wrapW`, "normal", wrapWidthOpId);
|
|
3339
|
-
addOperation(graph, wrapWidthOpId, "resolveSize", colMinWidthSlots, wrapOutputs, (inputs) => {
|
|
3340
|
-
const contentW = inputs.reduce((sum, w) => sum + num(w), 0) + gap * Math.max(0, inputs.length - 1);
|
|
3341
|
-
return [contentW, contentW + padding * 2];
|
|
3342
|
-
});
|
|
3343
|
-
}
|
|
3344
|
-
const colResolvedWidthSlots = [];
|
|
3345
|
-
if (maxCols > 0) {
|
|
3346
|
-
const colFillOpId = `op.grid.colFill.${id}`;
|
|
3347
|
-
const colFillInputs = [slotId(id, "resolvedWidth"), ...colMinWidthSlots];
|
|
3348
|
-
const colFillOutputs = [];
|
|
3349
|
-
for (let col = 0; col < maxCols; col++) {
|
|
3350
|
-
const colResSlot = `${id}.colResolvedWidth.${col}`;
|
|
3351
|
-
colResolvedWidthSlots.push(colResSlot);
|
|
3352
|
-
ensureSlot(graph, id, `colResolvedWidth.${col}`);
|
|
3353
|
-
colFillOutputs.push(colResSlot);
|
|
3354
|
-
addCandidate(graph, colResSlot, void 0, `grid(${id}).colFill[${col}]`, "strong", colFillOpId);
|
|
3586
|
+
const children = [];
|
|
3587
|
+
if (seg.edgeLabel) {
|
|
3588
|
+
children.push({
|
|
3589
|
+
kind: "label",
|
|
3590
|
+
props: { text: seg.edgeLabel }
|
|
3591
|
+
});
|
|
3355
3592
|
}
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
const surplusPerCol = surplus / maxCols;
|
|
3363
|
-
return minWidths.map((mw) => mw + surplusPerCol);
|
|
3364
|
-
});
|
|
3365
|
-
}
|
|
3366
|
-
for (let col = 0; col < maxCols; col++) {
|
|
3367
|
-
const cellIds = columnCellIds[col];
|
|
3368
|
-
if (cellIds.length === 0) continue;
|
|
3369
|
-
const cellWOpId = `op.grid.cellW.${id}.${col}`;
|
|
3370
|
-
const colResSlot = colResolvedWidthSlots[col];
|
|
3371
|
-
const cellWOutputs = cellIds.map((cid) => slotId(cid, "resolvedWidth"));
|
|
3372
|
-
for (const cid of cellIds) {
|
|
3373
|
-
addCandidate(graph, slotId(cid, "resolvedWidth"), void 0, `grid(${id}).cellW[${col}]`, "strong", cellWOpId);
|
|
3593
|
+
const connector = {
|
|
3594
|
+
kind: "connector",
|
|
3595
|
+
props: connectorProps
|
|
3596
|
+
};
|
|
3597
|
+
if (children.length > 0) {
|
|
3598
|
+
connector.children = children;
|
|
3374
3599
|
}
|
|
3375
|
-
|
|
3376
|
-
return cellIds.map(() => num(inputs[0]));
|
|
3377
|
-
});
|
|
3600
|
+
connectors.push(connector);
|
|
3378
3601
|
}
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3602
|
+
function processDirective(t) {
|
|
3603
|
+
switch (t.directiveType) {
|
|
3604
|
+
case "same-width": {
|
|
3605
|
+
const props = { targets: t.targets };
|
|
3606
|
+
if (t.strategy) props.strategy = t.strategy;
|
|
3607
|
+
constraints.push({ kind: "equalizeWidth", props });
|
|
3608
|
+
break;
|
|
3609
|
+
}
|
|
3610
|
+
case "same-height": {
|
|
3611
|
+
const props = { targets: t.targets };
|
|
3612
|
+
if (t.strategy) props.strategy = t.strategy;
|
|
3613
|
+
constraints.push({ kind: "equalizeHeight", props });
|
|
3614
|
+
break;
|
|
3615
|
+
}
|
|
3616
|
+
case "gap": {
|
|
3617
|
+
const props = {
|
|
3618
|
+
targets: t.targets,
|
|
3619
|
+
gap: t.min
|
|
3620
|
+
};
|
|
3621
|
+
constraints.push({ kind: "minGap", props });
|
|
3622
|
+
break;
|
|
3623
|
+
}
|
|
3624
|
+
case "mover": {
|
|
3625
|
+
const props = {
|
|
3626
|
+
targets: t.targets,
|
|
3627
|
+
mover: t.moverId
|
|
3628
|
+
};
|
|
3629
|
+
constraints.push({ kind: "alignConstraint", props });
|
|
3630
|
+
break;
|
|
3631
|
+
}
|
|
3392
3632
|
}
|
|
3393
|
-
addOperation(graph, rowEqOpId, "rowHeightResolve", heightInputs, rowEqOutputs, (inputs) => {
|
|
3394
|
-
const desiredHeights = inputs.map((h, i) => num(h) + rowPaddings[i] * 2);
|
|
3395
|
-
const maxH = Math.max(...desiredHeights, 0);
|
|
3396
|
-
return cellIds.map(() => maxH);
|
|
3397
|
-
});
|
|
3398
3633
|
}
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3634
|
+
const stackKind = rootDirection === "LR" ? "hstack" : "vstack";
|
|
3635
|
+
const groupNodes = /* @__PURE__ */ new Map();
|
|
3636
|
+
for (const g of groups) {
|
|
3637
|
+
const dir = g.frame.direction ?? rootDirection;
|
|
3638
|
+
const innerKind = dir === "LR" ? "hstack" : "vstack";
|
|
3639
|
+
const groupChildren = [];
|
|
3640
|
+
const innerStack = {
|
|
3641
|
+
kind: innerKind,
|
|
3642
|
+
props: { gap: 60, align: "center" },
|
|
3643
|
+
children: []
|
|
3644
|
+
};
|
|
3645
|
+
for (const childId of g.children) {
|
|
3646
|
+
const childGroup = groupNodes.get(childId);
|
|
3647
|
+
if (childGroup) {
|
|
3648
|
+
innerStack.children.push(childGroup);
|
|
3649
|
+
} else {
|
|
3650
|
+
const node = nodeMap.get(childId);
|
|
3651
|
+
if (node) {
|
|
3652
|
+
innerStack.children.push(buildBox(node));
|
|
3653
|
+
}
|
|
3654
|
+
}
|
|
3655
|
+
}
|
|
3656
|
+
groupChildren.push(innerStack);
|
|
3657
|
+
const groupNode = {
|
|
3658
|
+
kind: "group",
|
|
3659
|
+
id: g.frame.id,
|
|
3660
|
+
props: {},
|
|
3661
|
+
children: groupChildren
|
|
3662
|
+
};
|
|
3663
|
+
if (g.frame.label) {
|
|
3664
|
+
groupNode.props.label = g.frame.label;
|
|
3665
|
+
}
|
|
3666
|
+
groupNodes.set(g.frame.id, groupNode);
|
|
3406
3667
|
}
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
const
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3668
|
+
const rootChildren = [];
|
|
3669
|
+
for (const id of rootNodeIds) {
|
|
3670
|
+
const groupNode = groupNodes.get(id);
|
|
3671
|
+
if (groupNode) {
|
|
3672
|
+
rootChildren.push(groupNode);
|
|
3673
|
+
} else {
|
|
3674
|
+
const node = nodeMap.get(id);
|
|
3675
|
+
if (node) {
|
|
3676
|
+
rootChildren.push(buildBox(node));
|
|
3677
|
+
}
|
|
3678
|
+
}
|
|
3417
3679
|
}
|
|
3680
|
+
const rootStack = {
|
|
3681
|
+
kind: stackKind,
|
|
3682
|
+
props: { gap: 60, align: "center" },
|
|
3683
|
+
children: rootChildren
|
|
3684
|
+
};
|
|
3685
|
+
const documentChildren = [rootStack, ...connectors, ...constraints];
|
|
3686
|
+
const document = {
|
|
3687
|
+
kind: "document",
|
|
3688
|
+
props: { padding: 20 },
|
|
3689
|
+
children: documentChildren
|
|
3690
|
+
};
|
|
3691
|
+
return { ir: document, diagnostics };
|
|
3418
3692
|
}
|
|
3419
|
-
function
|
|
3420
|
-
const
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
ensureSlot(graph, id, "contentHeight");
|
|
3424
|
-
}
|
|
3425
|
-
var STACK_RULE = layoutRules["stack"];
|
|
3426
|
-
function applyLayoutFromRule(kind, node, graph, parentId) {
|
|
3427
|
-
if (STACK_RULE.applies_to && kind in STACK_RULE.applies_to) {
|
|
3428
|
-
const axisConfig = STACK_RULE.applies_to[kind];
|
|
3429
|
-
applyStackRule(STACK_RULE, axisConfig, kind, node, graph, parentId);
|
|
3430
|
-
return;
|
|
3431
|
-
}
|
|
3432
|
-
let rule = layoutRules[kind];
|
|
3433
|
-
if (!rule) {
|
|
3434
|
-
applyStubRule(node, graph, parentId);
|
|
3435
|
-
return;
|
|
3693
|
+
function buildBox(node) {
|
|
3694
|
+
const props = { shape: node.shape };
|
|
3695
|
+
if (node.variant) {
|
|
3696
|
+
props.variant = node.variant;
|
|
3436
3697
|
}
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3698
|
+
return {
|
|
3699
|
+
kind: "box",
|
|
3700
|
+
id: node.id,
|
|
3701
|
+
props,
|
|
3702
|
+
children: [
|
|
3703
|
+
{ kind: "text", props: { text: node.label } }
|
|
3704
|
+
]
|
|
3705
|
+
};
|
|
3706
|
+
}
|
|
3707
|
+
function buildAlignConstraint(targets, direction) {
|
|
3708
|
+
const axis = direction === "TD" ? "vertical" : "horizontal";
|
|
3709
|
+
return {
|
|
3710
|
+
kind: "alignConstraint",
|
|
3711
|
+
props: {
|
|
3712
|
+
targets,
|
|
3713
|
+
axis,
|
|
3714
|
+
align: "center"
|
|
3441
3715
|
}
|
|
3442
|
-
}
|
|
3443
|
-
switch (rule.type) {
|
|
3444
|
-
case "root":
|
|
3445
|
-
applyRootRule(rule, node, graph);
|
|
3446
|
-
break;
|
|
3447
|
-
case "container":
|
|
3448
|
-
applyContainerRule(rule, node, graph, parentId);
|
|
3449
|
-
break;
|
|
3450
|
-
case "text_measurement":
|
|
3451
|
-
applyTextMeasurementRule(rule, node, graph, parentId);
|
|
3452
|
-
break;
|
|
3453
|
-
case "overlay":
|
|
3454
|
-
applyOverlayRule(rule, node, graph, parentId);
|
|
3455
|
-
break;
|
|
3456
|
-
case "connector":
|
|
3457
|
-
applyConnectorRule(rule, node, graph);
|
|
3458
|
-
break;
|
|
3459
|
-
case "fixed_size":
|
|
3460
|
-
applyFixedSizeRule(rule, node, graph, parentId);
|
|
3461
|
-
break;
|
|
3462
|
-
case "grid":
|
|
3463
|
-
applyGridRule(rule, node, graph, parentId);
|
|
3464
|
-
break;
|
|
3465
|
-
default:
|
|
3466
|
-
applyStubRule(node, graph, parentId);
|
|
3467
|
-
break;
|
|
3468
|
-
}
|
|
3716
|
+
};
|
|
3469
3717
|
}
|
|
3470
3718
|
|
|
3471
3719
|
// src/compiler/compiler.ts
|
|
3720
|
+
import ts from "typescript";
|
|
3472
3721
|
function isParamRef(v) {
|
|
3473
3722
|
return typeof v === "object" && v !== null && v.__paramRef === true;
|
|
3474
3723
|
}
|
|
@@ -4729,148 +4978,6 @@ function collectNonFiniteGeometry(artifact) {
|
|
|
4729
4978
|
return violations;
|
|
4730
4979
|
}
|
|
4731
4980
|
|
|
4732
|
-
// src/renderer/defaults.ts
|
|
4733
|
-
var RENDER_DEFAULTS = {
|
|
4734
|
-
image: { fit: "contain" },
|
|
4735
|
-
icon: { foreground: "#666" },
|
|
4736
|
-
table: { borderRadius: 6, stroke: "#d1d5db", strokeWidth: 1, background: "white" },
|
|
4737
|
-
divider: { stroke: "#ccc", strokeWidth: 1 },
|
|
4738
|
-
cell: { fill: "none", stroke: "#e5e7eb", strokeWidth: 0.5 },
|
|
4739
|
-
text: {
|
|
4740
|
-
anchor: "middle",
|
|
4741
|
-
fontSize: 14,
|
|
4742
|
-
lineHeightFactor: SIMPLE_FONT_METRICS.LINE_HEIGHT,
|
|
4743
|
-
capHeightFactor: SIMPLE_FONT_METRICS.CAP_HEIGHT
|
|
4744
|
-
},
|
|
4745
|
-
box: { shape: "rect" },
|
|
4746
|
-
connectorLabel: { background: "#ffffff" },
|
|
4747
|
-
connector: { stroke: "#6b7280", strokeWidth: 1.5, arrowSize: 1, startArrow: "none", endArrow: "arrow" },
|
|
4748
|
-
roundedRect: { radius: 8 }
|
|
4749
|
-
};
|
|
4750
|
-
|
|
4751
|
-
// src/renderer/shapes.ts
|
|
4752
|
-
var STROKE_DASHARRAY = {
|
|
4753
|
-
dashed: "6 4",
|
|
4754
|
-
dotted: "2 3"
|
|
4755
|
-
};
|
|
4756
|
-
function styleAttrs(styles) {
|
|
4757
|
-
const parts = [];
|
|
4758
|
-
if (styles.fill != null) parts.push(`fill="${esc(styles.fill)}"`);
|
|
4759
|
-
else parts.push('fill="none"');
|
|
4760
|
-
if (styles.stroke != null) parts.push(`stroke="${esc(styles.stroke)}"`);
|
|
4761
|
-
if (styles.strokeWidth != null) parts.push(`stroke-width="${styles.strokeWidth}"`);
|
|
4762
|
-
if (styles.strokeStyle != null && styles.strokeStyle !== "solid") {
|
|
4763
|
-
const da = STROKE_DASHARRAY[String(styles.strokeStyle)];
|
|
4764
|
-
if (da) parts.push(`stroke-dasharray="${da}"`);
|
|
4765
|
-
}
|
|
4766
|
-
if (styles.opacity != null) parts.push(`opacity="${styles.opacity}"`);
|
|
4767
|
-
return parts.join(" ");
|
|
4768
|
-
}
|
|
4769
|
-
function esc(v) {
|
|
4770
|
-
return String(v).replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
4771
|
-
}
|
|
4772
|
-
function pts(coords) {
|
|
4773
|
-
return coords.map(([px, py]) => `${px},${py}`).join(" ");
|
|
4774
|
-
}
|
|
4775
|
-
function renderRect(r, sa) {
|
|
4776
|
-
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" ${sa}/>`;
|
|
4777
|
-
}
|
|
4778
|
-
function renderRoundedRect(r, styles, sa) {
|
|
4779
|
-
const rx = styles.radius != null ? Number(styles.radius) : RENDER_DEFAULTS.roundedRect.radius;
|
|
4780
|
-
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
4781
|
-
}
|
|
4782
|
-
function renderCircle(r, sa) {
|
|
4783
|
-
const radius = r.width / 2;
|
|
4784
|
-
return `<circle cx="${r.x + radius}" cy="${r.y + radius}" r="${radius}" ${sa}/>`;
|
|
4785
|
-
}
|
|
4786
|
-
function renderEllipse(r, sa) {
|
|
4787
|
-
const rx = r.width / 2;
|
|
4788
|
-
const ry = r.height / 2;
|
|
4789
|
-
return `<ellipse cx="${r.x + rx}" cy="${r.y + ry}" rx="${rx}" ry="${ry}" ${sa}/>`;
|
|
4790
|
-
}
|
|
4791
|
-
function renderDiamond(r, sa) {
|
|
4792
|
-
const cx = r.x + r.width / 2;
|
|
4793
|
-
const cy = r.y + r.height / 2;
|
|
4794
|
-
const points = [
|
|
4795
|
-
[cx, r.y],
|
|
4796
|
-
[r.x + r.width, cy],
|
|
4797
|
-
[cx, r.y + r.height],
|
|
4798
|
-
[r.x, cy]
|
|
4799
|
-
];
|
|
4800
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
4801
|
-
}
|
|
4802
|
-
function renderParallelogram(r, sa) {
|
|
4803
|
-
const skew = r.width * 0.2;
|
|
4804
|
-
const points = [
|
|
4805
|
-
[r.x + skew, r.y],
|
|
4806
|
-
[r.x + r.width, r.y],
|
|
4807
|
-
[r.x + r.width - skew, r.y + r.height],
|
|
4808
|
-
[r.x, r.y + r.height]
|
|
4809
|
-
];
|
|
4810
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
4811
|
-
}
|
|
4812
|
-
function renderCapsule(r, sa) {
|
|
4813
|
-
const rx = Math.min(r.width, r.height) / 2;
|
|
4814
|
-
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
4815
|
-
}
|
|
4816
|
-
function renderCylinder(r, sa) {
|
|
4817
|
-
const ellipseH = Math.min(r.height * 0.2, 20);
|
|
4818
|
-
const ry = ellipseH / 2;
|
|
4819
|
-
const x = r.x;
|
|
4820
|
-
const y = r.y;
|
|
4821
|
-
const w = r.width;
|
|
4822
|
-
const h = r.height;
|
|
4823
|
-
const rx = w / 2;
|
|
4824
|
-
const topArc = `M ${x},${y + ry} A ${rx},${ry} 0 0,1 ${x + w},${y + ry}`;
|
|
4825
|
-
const rightSide = `L ${x + w},${y + h - ry}`;
|
|
4826
|
-
const bottomArc = `A ${rx},${ry} 0 0,1 ${x},${y + h - ry}`;
|
|
4827
|
-
const leftSide = `L ${x},${y + ry}`;
|
|
4828
|
-
const topEllipseBack = `M ${x},${y + ry} A ${rx},${ry} 0 0,0 ${x + w},${y + ry}`;
|
|
4829
|
-
return `<path d="${topArc} ${rightSide} ${bottomArc} ${leftSide}" ${sa}/><path d="${topEllipseBack}" ${styles_stroke_only(sa)}/>`;
|
|
4830
|
-
}
|
|
4831
|
-
function styles_stroke_only(sa) {
|
|
4832
|
-
return sa.replace(/fill="[^"]*"/, 'fill="none"');
|
|
4833
|
-
}
|
|
4834
|
-
function renderHexagon(r, sa) {
|
|
4835
|
-
const cx = r.x + r.width / 2;
|
|
4836
|
-
const cy = r.y + r.height / 2;
|
|
4837
|
-
const inset = r.width * 0.25;
|
|
4838
|
-
const points = [
|
|
4839
|
-
[r.x + inset, r.y],
|
|
4840
|
-
[r.x + r.width - inset, r.y],
|
|
4841
|
-
[r.x + r.width, cy],
|
|
4842
|
-
[r.x + r.width - inset, r.y + r.height],
|
|
4843
|
-
[r.x + inset, r.y + r.height],
|
|
4844
|
-
[r.x, cy]
|
|
4845
|
-
];
|
|
4846
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
4847
|
-
}
|
|
4848
|
-
function renderTriangle(r, sa) {
|
|
4849
|
-
const points = [
|
|
4850
|
-
[r.x + r.width / 2, r.y],
|
|
4851
|
-
[r.x + r.width, r.y + r.height],
|
|
4852
|
-
[r.x, r.y + r.height]
|
|
4853
|
-
];
|
|
4854
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
4855
|
-
}
|
|
4856
|
-
var SHAPE_RENDERERS = {
|
|
4857
|
-
rect: (r, _s, sa) => renderRect(r, sa),
|
|
4858
|
-
roundedRect: (r, s, sa) => renderRoundedRect(r, s, sa),
|
|
4859
|
-
circle: (r, _s, sa) => renderCircle(r, sa),
|
|
4860
|
-
ellipse: (r, _s, sa) => renderEllipse(r, sa),
|
|
4861
|
-
diamond: (r, _s, sa) => renderDiamond(r, sa),
|
|
4862
|
-
parallelogram: (r, _s, sa) => renderParallelogram(r, sa),
|
|
4863
|
-
capsule: (r, _s, sa) => renderCapsule(r, sa),
|
|
4864
|
-
cylinder: (r, _s, sa) => renderCylinder(r, sa),
|
|
4865
|
-
hexagon: (r, _s, sa) => renderHexagon(r, sa),
|
|
4866
|
-
triangle: (r, _s, sa) => renderTriangle(r, sa)
|
|
4867
|
-
};
|
|
4868
|
-
function renderShape(shape, rect, styles) {
|
|
4869
|
-
const sa = styleAttrs(styles);
|
|
4870
|
-
const renderer = SHAPE_RENDERERS[shape] ?? SHAPE_RENDERERS.rect;
|
|
4871
|
-
return renderer(rect, styles, sa);
|
|
4872
|
-
}
|
|
4873
|
-
|
|
4874
4981
|
// src/renderer/connectors.ts
|
|
4875
4982
|
var BASE_MARKER_SIZE = 7;
|
|
4876
4983
|
var BASE_MARKER_HALF = BASE_MARKER_SIZE / 2;
|
|
@@ -5428,6 +5535,7 @@ function createGraph() {
|
|
|
5428
5535
|
dependencies: [],
|
|
5429
5536
|
parentMap: /* @__PURE__ */ new Map(),
|
|
5430
5537
|
nodeKindMap: /* @__PURE__ */ new Map(),
|
|
5538
|
+
irNodeMap: /* @__PURE__ */ new Map(),
|
|
5431
5539
|
childrenOrderMap: /* @__PURE__ */ new Map(),
|
|
5432
5540
|
diagnostics: []
|
|
5433
5541
|
};
|
|
@@ -5448,16 +5556,19 @@ function evaluate(graph, ir) {
|
|
|
5448
5556
|
return { artifact, diagnostics };
|
|
5449
5557
|
}
|
|
5450
5558
|
function buildFragments(graph, node, parentId) {
|
|
5451
|
-
const factory = FRAGMENT_MAP[node.kind];
|
|
5452
|
-
if (factory) {
|
|
5453
|
-
factory(node, graph, parentId);
|
|
5454
|
-
}
|
|
5455
5559
|
const nodeId = node.id;
|
|
5456
5560
|
if (nodeId && !isConstraintKind(node.kind)) {
|
|
5457
5561
|
graph.nodeKindMap.set(nodeId, node.kind);
|
|
5562
|
+
graph.irNodeMap.set(nodeId, node);
|
|
5458
5563
|
if (parentId) {
|
|
5459
5564
|
graph.parentMap.set(nodeId, parentId);
|
|
5460
5565
|
}
|
|
5566
|
+
}
|
|
5567
|
+
const factory = FRAGMENT_MAP[node.kind];
|
|
5568
|
+
if (factory) {
|
|
5569
|
+
factory(node, graph, parentId);
|
|
5570
|
+
}
|
|
5571
|
+
if (nodeId && !isConstraintKind(node.kind)) {
|
|
5461
5572
|
addWorldCoordOps(graph, nodeId, parentId);
|
|
5462
5573
|
}
|
|
5463
5574
|
if (node.children) {
|