@diagrammo/dgmo 0.46.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/advanced.d.cts +3 -855
- package/dist/advanced.d.ts +3 -855
- package/dist/advanced.js +541 -70107
- package/dist/analyzer-UYKBXAKR.js +15 -0
- package/dist/auto.cjs +1 -1
- package/dist/auto.js +1 -1
- package/dist/auto.mjs +1 -1
- package/dist/block.js +83 -69417
- package/dist/calculator-LDYQCDDY.js +11 -0
- package/dist/charts-d3-QOZHKTCT.js +25 -0
- package/dist/chunk-2DXMZRWJ.js +800 -0
- package/dist/chunk-2LACINWN.js +786 -0
- package/dist/chunk-33LCUH4H.js +893 -0
- package/dist/chunk-3CIOJ5YJ.js +35 -0
- package/dist/chunk-3HDBAXF5.js +86 -0
- package/dist/chunk-3JLKYGBQ.js +290 -0
- package/dist/chunk-3MQQNXPD.js +415 -0
- package/dist/chunk-3R5POCTZ.js +967 -0
- package/dist/chunk-3SMGIJDD.js +112 -0
- package/dist/chunk-44CM72SQ.js +409 -0
- package/dist/chunk-4GRI7MEB.js +1604 -0
- package/dist/chunk-4OHACBGX.js +606 -0
- package/dist/chunk-5DH3KYFH.js +21 -0
- package/dist/chunk-5MLYVTYM.js +76 -0
- package/dist/chunk-5QXL4NYS.js +553 -0
- package/dist/chunk-5WRI5ZAA.js +31 -0
- package/dist/chunk-6EK55ART.js +117 -0
- package/dist/chunk-6FZYCKXB.js +2065 -0
- package/dist/chunk-6HO5ZTXK.js +277 -0
- package/dist/chunk-6KFWC4CO.js +7 -0
- package/dist/chunk-6MTWIQVO.js +121 -0
- package/dist/chunk-6NYWYNBI.js +329 -0
- package/dist/chunk-6SM5NJQH.js +620 -0
- package/dist/chunk-725LDASD.js +422 -0
- package/dist/chunk-76OWZ3BA.js +130 -0
- package/dist/chunk-7JEGTRLD.js +338 -0
- package/dist/chunk-A44USUV7.js +923 -0
- package/dist/chunk-A4GOY3PE.js +25 -0
- package/dist/chunk-A4VFQH5G.js +251 -0
- package/dist/chunk-AELOBFW5.js +375 -0
- package/dist/chunk-AN2MOO5T.js +522 -0
- package/dist/chunk-BMR4CIEO.js +41 -0
- package/dist/chunk-BS7SV7C3.js +51 -0
- package/dist/chunk-BUPDIHML.js +613 -0
- package/dist/chunk-BUVJFRPY.js +887 -0
- package/dist/chunk-C3Z4DX3V.js +112 -0
- package/dist/chunk-CI2G3OEB.js +1818 -0
- package/dist/chunk-CKNVO24D.js +54 -0
- package/dist/chunk-CUVHQHZ7.js +391 -0
- package/dist/chunk-CXK4DZH3.js +114 -0
- package/dist/chunk-DKEPS5LH.js +315 -0
- package/dist/chunk-DU7W62N5.js +487 -0
- package/dist/chunk-DZAQBW35.js +751 -0
- package/dist/chunk-EB6FPQUP.js +316 -0
- package/dist/chunk-EMS2SK26.js +376 -0
- package/dist/chunk-ERLBPDGU.js +510 -0
- package/dist/chunk-EVCVDTXE.js +732 -0
- package/dist/chunk-FCIIHT24.js +384 -0
- package/dist/chunk-FFUN5D66.js +97 -0
- package/dist/chunk-FITOLXSX.js +714 -0
- package/dist/chunk-FMDSF3OV.js +68 -0
- package/dist/chunk-FNB3PNGF.js +410 -0
- package/dist/chunk-G2H74XJZ.js +2104 -0
- package/dist/chunk-GMR5MFHJ.js +339 -0
- package/dist/chunk-H6PI3KJT.js +305 -0
- package/dist/chunk-I46X5VUA.js +59 -0
- package/dist/chunk-I5IGB56C.js +255 -0
- package/dist/chunk-IH6ZMVQ5.js +3950 -0
- package/dist/chunk-IJZFN3HM.js +463 -0
- package/dist/chunk-IPWPWM6R.js +3079 -0
- package/dist/chunk-IYULMRBE.js +23 -0
- package/dist/chunk-IZMRON6C.js +167 -0
- package/dist/chunk-J5FIXQRT.js +813 -0
- package/dist/chunk-JED6ZDEE.js +73 -0
- package/dist/chunk-JEUJOX5X.js +136 -0
- package/dist/chunk-JM4LEPY3.js +436 -0
- package/dist/chunk-L3UHP6TD.js +101 -0
- package/dist/chunk-L66GEFB6.js +524 -0
- package/dist/chunk-LIOHW36Z.js +469 -0
- package/dist/chunk-LP7EC4MI.js +16 -0
- package/dist/chunk-MITI6NOL.js +548 -0
- package/dist/chunk-MO5YHHMQ.js +168 -0
- package/dist/chunk-MZSBFAPJ.js +885 -0
- package/dist/chunk-NNAAJVBU.js +9 -0
- package/dist/chunk-NOTA6TEI.js +47 -0
- package/dist/chunk-NURGB5Z4.js +335 -0
- package/dist/chunk-NX4EQS3U.js +1062 -0
- package/dist/chunk-NXMESY4J.js +1 -0
- package/dist/chunk-OJR3MQYV.js +1458 -0
- package/dist/chunk-OURHMODR.js +454 -0
- package/dist/chunk-P235SVAH.js +1057 -0
- package/dist/chunk-P4RH4OSP.js +1038 -0
- package/dist/chunk-P6T66CCZ.js +226 -0
- package/dist/chunk-PBAHEPLQ.js +223 -0
- package/dist/chunk-PBHE5UG6.js +1530 -0
- package/dist/chunk-PDKUANDZ.js +35 -0
- package/dist/chunk-PWIHZ6NJ.js +296 -0
- package/dist/chunk-QEBUY5NY.js +1685 -0
- package/dist/chunk-QLCCJEJI.js +253 -0
- package/dist/chunk-QOOUC2J5.js +52 -0
- package/dist/chunk-QYTPPDAO.js +402 -0
- package/dist/chunk-R3XI2VC7.js +801 -0
- package/dist/chunk-RCERWOJR.js +154 -0
- package/dist/chunk-RJE5JTVK.js +362 -0
- package/dist/chunk-RTLBSQ3G.js +1155 -0
- package/dist/chunk-RUNNI6VE.js +448 -0
- package/dist/chunk-RVMRZAPB.js +354 -0
- package/dist/chunk-RYEGFMUO.js +955 -0
- package/dist/chunk-RZCF2VVM.js +528 -0
- package/dist/chunk-SML67VPV.js +1025 -0
- package/dist/chunk-SQ7IY53Q.js +44 -0
- package/dist/chunk-SQAG3UXH.js +161 -0
- package/dist/chunk-SRTU6HMQ.js +1851 -0
- package/dist/chunk-T2OE3YQB.js +550 -0
- package/dist/chunk-T3UBLACL.js +299 -0
- package/dist/chunk-TLVIHFRO.js +296 -0
- package/dist/chunk-TYS6CSS5.js +52 -0
- package/dist/chunk-U6EQI3U6.js +130 -0
- package/dist/chunk-UJ4FJLBF.js +86 -0
- package/dist/chunk-ULOEATBZ.js +347 -0
- package/dist/chunk-UNCCZ3NU.js +127 -0
- package/dist/chunk-USZW2HHU.js +197 -0
- package/dist/chunk-UWN33VNX.js +1610 -0
- package/dist/chunk-UZ7EZW3B.js +40 -0
- package/dist/chunk-VOKGH627.js +37 -0
- package/dist/chunk-WBRZJOEC.js +204 -0
- package/dist/chunk-WCSOJFU3.js +380 -0
- package/dist/chunk-WCT3NYCV.js +160 -0
- package/dist/chunk-WVAJFAIA.js +529 -0
- package/dist/chunk-X5LCYCL5.js +394 -0
- package/dist/chunk-XAKEUMEJ.js +1256 -0
- package/dist/chunk-Y2ZE3MSG.js +590 -0
- package/dist/chunk-Y3J7VR52.js +646 -0
- package/dist/chunk-Y5QGVTVC.js +33 -0
- package/dist/chunk-YAA6IID3.js +548 -0
- package/dist/chunk-YGJTDXVR.js +692 -0
- package/dist/chunk-YRYKTYMQ.js +186 -0
- package/dist/chunk-YYVTBZZC.js +61 -0
- package/dist/chunk-Z5CGSFJB.js +647 -0
- package/dist/chunk-Z72XRXD4.js +787 -0
- package/dist/chunk-ZGR7ULFJ.js +978 -0
- package/dist/chunk-ZJEL4H2R.js +851 -0
- package/dist/chunk-ZO27FGJS.js +554 -0
- package/dist/collapse-CLPJD2RL.js +11 -0
- package/dist/collapse-SLINJQW6.js +9 -0
- package/dist/collapse-ZWUFFCK2.js +9 -0
- package/dist/compute-G55RG53N.js +8 -0
- package/dist/dgmo-router-DZCIDUO5.js +73 -0
- package/dist/dimensions-J3FHIMJ6.js +22 -0
- package/dist/element.cjs +1 -1
- package/dist/element.js +1 -1
- package/dist/element.mjs +1 -1
- package/dist/flowchart-parser-ZNSKIBVR.js +21 -0
- package/dist/flowchart-renderer-ZAEOL4DX.js +35 -0
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +3 -469
- package/dist/index.d.ts +3 -469
- package/dist/index.js +137 -69685
- package/dist/layout-46N4JJYK.js +17 -0
- package/dist/layout-5RA6QWR6.js +26 -0
- package/dist/layout-5T6RH5M6.js +14 -0
- package/dist/layout-7QXCNOVS.js +13 -0
- package/dist/layout-EE6GE46Y.js +17 -0
- package/dist/layout-G23F7LDH.js +9 -0
- package/dist/layout-HRBZPFCN.js +23 -0
- package/dist/layout-HWDSRX5E.js +20 -0
- package/dist/layout-HYZPWAK5.js +18 -0
- package/dist/layout-N76NR4ZO.js +19 -0
- package/dist/layout-OB3RI63S.js +14 -0
- package/dist/layout-S2QBYSK2.js +15 -0
- package/dist/layout-UM5F4DJB.js +15 -0
- package/dist/layout-search-OYV77HHS.js +1655 -0
- package/dist/load-data-EHDDZ5ZS.js +8 -0
- package/dist/palettes-PRJ2RI6D.js +56 -0
- package/dist/parser-2MFP2H2E.js +11 -0
- package/dist/parser-3STE62GB.js +21 -0
- package/dist/parser-4FL2CMDG.js +18 -0
- package/dist/parser-4OGOBJJ4.js +13 -0
- package/dist/parser-6BTRLKRZ.js +15 -0
- package/dist/parser-AQETEVRW.js +21 -0
- package/dist/parser-CFZD5IBL.js +12 -0
- package/dist/parser-FUSKFGZN.js +16 -0
- package/dist/parser-I6KXEYFK.js +13 -0
- package/dist/parser-IXSZZQHY.js +18 -0
- package/dist/parser-JAL2HD4I.js +13 -0
- package/dist/parser-KNSQSKQO.js +20 -0
- package/dist/parser-N5O4IHUN.js +13 -0
- package/dist/parser-NGU3ETO6.js +16 -0
- package/dist/parser-NRAI6O25.js +19 -0
- package/dist/parser-O5J4VBII.js +11 -0
- package/dist/parser-OV7NOBW6.js +21 -0
- package/dist/parser-PQ3POX45.js +23 -0
- package/dist/parser-TFZFBVWN.js +11 -0
- package/dist/parser-TRTHDFPP.js +18 -0
- package/dist/parser-VQP2UJ6W.js +11 -0
- package/dist/parser-XDVELHRK.js +13 -0
- package/dist/parser-XKRP7QKP.js +11 -0
- package/dist/parser-Y6WTBU76.js +14 -0
- package/dist/parser-ZSDPZYQP.js +12 -0
- package/dist/renderer-2XQQQ6QR.js +28 -0
- package/dist/renderer-5NDVNDAZ.js +26 -0
- package/dist/renderer-6EEZHMH4.js +26 -0
- package/dist/renderer-6W5462RB.js +43 -0
- package/dist/renderer-7MVLWWQD.js +22 -0
- package/dist/renderer-AWWAF6XD.js +33 -0
- package/dist/renderer-BYCNMBF7.js +34 -0
- package/dist/renderer-CLJHQPBJ.js +29 -0
- package/dist/renderer-GHPZMFU2.js +15 -0
- package/dist/renderer-JGBKUCZD.js +16 -0
- package/dist/renderer-KQB7UGDS.js +19 -0
- package/dist/renderer-PGX2TKVS.js +24 -0
- package/dist/renderer-QIWVHWZO.js +15 -0
- package/dist/renderer-RPOA5YPZ.js +35 -0
- package/dist/renderer-SMIBCRVB.js +24 -0
- package/dist/renderer-T7YKC5VP.js +28 -0
- package/dist/renderer-TOCOVLHS.js +37 -0
- package/dist/renderer-UWA5XS74.js +39 -0
- package/dist/renderer-VACVQYML.js +25 -0
- package/dist/renderer-W4M6QLIJ.js +37 -0
- package/dist/renderer-WZRREQ2P.js +23 -0
- package/dist/renderer-YY2OSF6E.js +27 -0
- package/dist/renderer-Z7I3W2PP.js +24 -0
- package/dist/renderer-ZGNTUWC4.js +22 -0
- package/dist/renderer-ZTR3DER3.js +19 -0
- package/dist/renderer-radial-C32GPJQ7.js +21 -0
- package/dist/resolver-NOAA7ID7.js +13 -0
- package/dist/state-collapse-HCGD6IVJ.js +8 -0
- package/dist/state-parser-Z2V23ATR.js +18 -0
- package/dist/state-renderer-RFYHSP4K.js +34 -0
- package/dist/themes-1-CuKpeH.d.cts +908 -0
- package/dist/themes-1-CuKpeH.d.ts +908 -0
- package/package.json +1 -1
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// src/utils/svg-embed.ts
|
|
2
|
+
function normalizeSvgForEmbed(input) {
|
|
3
|
+
let svg = input;
|
|
4
|
+
const rootMatch = svg.match(/<svg[^>]*>/);
|
|
5
|
+
const rootTag = rootMatch?.[0] ?? "";
|
|
6
|
+
if (rootTag && !rootTag.includes("viewBox")) {
|
|
7
|
+
const wh = rootTag.match(/width="(\d+)"[^>]*height="(\d+)"/);
|
|
8
|
+
if (wh) {
|
|
9
|
+
svg = svg.replace(/<svg/, `<svg viewBox="0 0 ${wh[1]} ${wh[2]}"`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const tight = computeBBox(svg);
|
|
13
|
+
if (tight && tight.width > 0 && tight.height > 0) {
|
|
14
|
+
const pad = 16;
|
|
15
|
+
const x = tight.x - pad;
|
|
16
|
+
const y = tight.y - pad;
|
|
17
|
+
const w = tight.width + pad * 2;
|
|
18
|
+
const h = tight.height + pad * 2;
|
|
19
|
+
const canvas = readViewBox(svg);
|
|
20
|
+
const TOL = 2;
|
|
21
|
+
const MIN_COVERAGE = 0.5;
|
|
22
|
+
const trustworthy = !canvas || x >= canvas.x - TOL && y >= canvas.y - TOL && x + w <= canvas.x + canvas.width + TOL && y + h <= canvas.y + canvas.height + TOL && w >= canvas.width * MIN_COVERAGE && h >= canvas.height * MIN_COVERAGE;
|
|
23
|
+
if (trustworthy) {
|
|
24
|
+
const vb = `${x} ${y} ${w} ${h}`;
|
|
25
|
+
svg = svg.replace(/(<svg[^>]*?)viewBox="[^"]*"/, `$1viewBox="${vb}"`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
svg = svg.replace(/(<svg[^>]*?) width="[^"]*"/g, "$1");
|
|
29
|
+
svg = svg.replace(/(<svg[^>]*?) height="[^"]*"/g, "$1");
|
|
30
|
+
svg = svg.replace(/(<svg[^>]*?style="[^"]*?)background:[^;"]*;?\s*/g, "$1");
|
|
31
|
+
svg = svg.replace(/<svg\s{2,}/g, "<svg ");
|
|
32
|
+
return svg;
|
|
33
|
+
}
|
|
34
|
+
function getEmbedSvgViewBox(svg) {
|
|
35
|
+
const tight = computeBBox(svg);
|
|
36
|
+
if (!tight || tight.width <= 0 || tight.height <= 0) return null;
|
|
37
|
+
const pad = 16;
|
|
38
|
+
return {
|
|
39
|
+
x: tight.x - pad,
|
|
40
|
+
y: tight.y - pad,
|
|
41
|
+
width: tight.width + pad * 2,
|
|
42
|
+
height: tight.height + pad * 2
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function readViewBox(svg) {
|
|
46
|
+
const m = svg.match(/<svg[^>]*?\bviewBox="([^"]+)"/);
|
|
47
|
+
if (!m) return null;
|
|
48
|
+
const n = m[1].trim().split(/[\s,]+/).map(Number);
|
|
49
|
+
if (n.length !== 4 || n.some((v) => !Number.isFinite(v)) || n[2] <= 0 || n[3] <= 0)
|
|
50
|
+
return null;
|
|
51
|
+
return { x: n[0], y: n[1], width: n[2], height: n[3] };
|
|
52
|
+
}
|
|
53
|
+
function computeBBox(svg) {
|
|
54
|
+
const xs = [];
|
|
55
|
+
const ys = [];
|
|
56
|
+
function push(x, y) {
|
|
57
|
+
if (Number.isFinite(x) && Number.isFinite(y)) {
|
|
58
|
+
xs.push(x);
|
|
59
|
+
ys.push(y);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function attr(tag, name) {
|
|
63
|
+
const m = tag.match(new RegExp(`\\b${name}="([^"]*)"`));
|
|
64
|
+
if (!m) return null;
|
|
65
|
+
const n = parseFloat(m[1]);
|
|
66
|
+
return Number.isFinite(n) ? n : null;
|
|
67
|
+
}
|
|
68
|
+
for (const m of svg.matchAll(/<rect\b[^>]*?\/?>/g)) {
|
|
69
|
+
const tag = m[0];
|
|
70
|
+
const x = attr(tag, "x");
|
|
71
|
+
const y = attr(tag, "y");
|
|
72
|
+
const w = attr(tag, "width");
|
|
73
|
+
const h = attr(tag, "height");
|
|
74
|
+
if (x !== null && y !== null && w !== null && h !== null) {
|
|
75
|
+
push(x, y);
|
|
76
|
+
push(x + w, y + h);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const m of svg.matchAll(/<line\b[^>]*?\/?>/g)) {
|
|
80
|
+
const tag = m[0];
|
|
81
|
+
const x1 = attr(tag, "x1");
|
|
82
|
+
const y1 = attr(tag, "y1");
|
|
83
|
+
const x2 = attr(tag, "x2");
|
|
84
|
+
const y2 = attr(tag, "y2");
|
|
85
|
+
if (x1 !== null && y1 !== null && x2 !== null && y2 !== null) {
|
|
86
|
+
push(x1, y1);
|
|
87
|
+
push(x2, y2);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (const m of svg.matchAll(/<circle\b[^>]*?\/?>/g)) {
|
|
91
|
+
const tag = m[0];
|
|
92
|
+
const cx = attr(tag, "cx");
|
|
93
|
+
const cy = attr(tag, "cy");
|
|
94
|
+
const r = attr(tag, "r");
|
|
95
|
+
if (cx !== null && cy !== null && r !== null) {
|
|
96
|
+
push(cx - r, cy - r);
|
|
97
|
+
push(cx + r, cy + r);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
for (const m of svg.matchAll(/<ellipse\b[^>]*?\/?>/g)) {
|
|
101
|
+
const tag = m[0];
|
|
102
|
+
const cx = attr(tag, "cx");
|
|
103
|
+
const cy = attr(tag, "cy");
|
|
104
|
+
const rx = attr(tag, "rx");
|
|
105
|
+
const ry = attr(tag, "ry");
|
|
106
|
+
if (cx !== null && cy !== null && rx !== null && ry !== null) {
|
|
107
|
+
push(cx - rx, cy - ry);
|
|
108
|
+
push(cx + rx, cy + ry);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for (const m of svg.matchAll(/<text\b([^>]*?)>([\s\S]*?)<\/text>/g)) {
|
|
112
|
+
const tag = `<text${m[1]}>`;
|
|
113
|
+
const text = m[2].replace(/<[^>]+>/g, "");
|
|
114
|
+
const x = attr(tag, "x");
|
|
115
|
+
const y = attr(tag, "y");
|
|
116
|
+
if (x !== null && y !== null) {
|
|
117
|
+
const w = text.length * 7;
|
|
118
|
+
const anchor = tag.match(/\btext-anchor="([^"]*)"/)?.[1] ?? "start";
|
|
119
|
+
const left = anchor === "middle" ? x - w / 2 : anchor === "end" ? x - w : x;
|
|
120
|
+
const right = anchor === "middle" ? x + w / 2 : anchor === "end" ? x : x + w;
|
|
121
|
+
push(left, y - 14);
|
|
122
|
+
push(right, y + 4);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
for (const m of svg.matchAll(/<path\b[^>]*?\bd="([^"]+)"/g)) {
|
|
126
|
+
const d = m[1];
|
|
127
|
+
const nums = d.match(/-?\d+(?:\.\d+)?/g);
|
|
128
|
+
if (!nums) continue;
|
|
129
|
+
for (let i = 0; i + 1 < nums.length; i += 2) {
|
|
130
|
+
push(parseFloat(nums[i]), parseFloat(nums[i + 1]));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
for (const m of svg.matchAll(
|
|
134
|
+
/<(?:polygon|polyline)\b[^>]*?\bpoints="([^"]+)"/g
|
|
135
|
+
)) {
|
|
136
|
+
const nums = m[1].match(/-?\d+(?:\.\d+)?/g);
|
|
137
|
+
if (!nums) continue;
|
|
138
|
+
for (let i = 0; i + 1 < nums.length; i += 2) {
|
|
139
|
+
push(parseFloat(nums[i]), parseFloat(nums[i + 1]));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (xs.length === 0 || ys.length === 0) return null;
|
|
143
|
+
const minX = Math.min(...xs);
|
|
144
|
+
const maxX = Math.max(...xs);
|
|
145
|
+
const minY = Math.min(...ys);
|
|
146
|
+
const maxY = Math.max(...ys);
|
|
147
|
+
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export {
|
|
151
|
+
normalizeSvgForEmbed,
|
|
152
|
+
getEmbedSvgViewBox
|
|
153
|
+
};
|
|
154
|
+
//# sourceMappingURL=chunk-RCERWOJR.js.map
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import {
|
|
2
|
+
renderIntegratedLegend
|
|
3
|
+
} from "./chunk-PWIHZ6NJ.js";
|
|
4
|
+
import {
|
|
5
|
+
getMaxLegendReservedHeight
|
|
6
|
+
} from "./chunk-YAA6IID3.js";
|
|
7
|
+
import {
|
|
8
|
+
TITLE_FONT_SIZE,
|
|
9
|
+
TITLE_FONT_WEIGHT,
|
|
10
|
+
TITLE_Y
|
|
11
|
+
} from "./chunk-A4GOY3PE.js";
|
|
12
|
+
import {
|
|
13
|
+
FONT_FAMILY
|
|
14
|
+
} from "./chunk-6KFWC4CO.js";
|
|
15
|
+
import {
|
|
16
|
+
LEGEND_GROUP_GAP
|
|
17
|
+
} from "./chunk-QOOUC2J5.js";
|
|
18
|
+
import {
|
|
19
|
+
measureText
|
|
20
|
+
} from "./chunk-WCT3NYCV.js";
|
|
21
|
+
import {
|
|
22
|
+
isBlockNode
|
|
23
|
+
} from "./chunk-NNAAJVBU.js";
|
|
24
|
+
import {
|
|
25
|
+
mix
|
|
26
|
+
} from "./chunk-P6T66CCZ.js";
|
|
27
|
+
import {
|
|
28
|
+
resolveTagColor,
|
|
29
|
+
tagAttrKey
|
|
30
|
+
} from "./chunk-QLCCJEJI.js";
|
|
31
|
+
|
|
32
|
+
// src/block/renderer.ts
|
|
33
|
+
import * as d3Selection from "d3-selection";
|
|
34
|
+
|
|
35
|
+
// src/block/layout.ts
|
|
36
|
+
var BLOCK_GAP = 12;
|
|
37
|
+
var BLOCK_PAD = 10;
|
|
38
|
+
var BLOCK_LEAF_H = 46;
|
|
39
|
+
var BLOCK_HEADER_H = 28;
|
|
40
|
+
var BLOCK_COLLAPSED_H = 46;
|
|
41
|
+
var BLOCK_BAR_H = 6;
|
|
42
|
+
var MIN_COL = 104;
|
|
43
|
+
var MAX_COL = 250;
|
|
44
|
+
var LABEL_FS = 13;
|
|
45
|
+
function layoutBlock(grid, opts = {}) {
|
|
46
|
+
const collapsed = opts.collapsed ?? /* @__PURE__ */ new Set();
|
|
47
|
+
const node = layoutGrid(grid, 0, 0, null, collapsed);
|
|
48
|
+
return { width: node.w, height: node.h, items: node.items };
|
|
49
|
+
}
|
|
50
|
+
function maxSpanSum(g) {
|
|
51
|
+
return Math.max(
|
|
52
|
+
1,
|
|
53
|
+
...g.rows.map((r) => r.reduce((s, c) => s + (c.span || 1), 0))
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
function leafW(node) {
|
|
57
|
+
return Math.max(
|
|
58
|
+
MIN_COL,
|
|
59
|
+
Math.min(MAX_COL, measureText(node.label, LABEL_FS) + 2 * BLOCK_PAD + 14)
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
function gridColW(g) {
|
|
63
|
+
let m = MIN_COL;
|
|
64
|
+
for (const row of g.rows)
|
|
65
|
+
for (const c of row) {
|
|
66
|
+
if (!isBlockNode(c)) continue;
|
|
67
|
+
const iw = c.grid ? intrinsicGridW(c.grid) + 2 * BLOCK_PAD : leafW(c);
|
|
68
|
+
m = Math.max(m, iw / (c.span || 1));
|
|
69
|
+
}
|
|
70
|
+
return m;
|
|
71
|
+
}
|
|
72
|
+
function intrinsicGridW(g) {
|
|
73
|
+
const cols = g.cols ?? maxSpanSum(g);
|
|
74
|
+
return cols * gridColW(g) + (cols + 1) * BLOCK_GAP;
|
|
75
|
+
}
|
|
76
|
+
function layoutGrid(g, ox, oy, forceColW, collapsed) {
|
|
77
|
+
const cols = g.cols ?? maxSpanSum(g);
|
|
78
|
+
const colW = forceColW ?? gridColW(g);
|
|
79
|
+
const gridW = cols * colW + (cols + 1) * BLOCK_GAP;
|
|
80
|
+
let cy = oy + BLOCK_GAP;
|
|
81
|
+
const items = [];
|
|
82
|
+
let maxRight = ox + BLOCK_GAP;
|
|
83
|
+
for (const row of g.rows) {
|
|
84
|
+
let cx = ox + BLOCK_GAP;
|
|
85
|
+
let rowH = BLOCK_LEAF_H;
|
|
86
|
+
const rowItems = [];
|
|
87
|
+
for (const cell of row) {
|
|
88
|
+
const span = cell.span || 1;
|
|
89
|
+
const cw = span * colW + (span - 1) * BLOCK_GAP;
|
|
90
|
+
if (!isBlockNode(cell)) {
|
|
91
|
+
rowItems.push({ type: "empty", x: cx, y: cy, w: cw, h: BLOCK_LEAF_H });
|
|
92
|
+
cx += cw + BLOCK_GAP;
|
|
93
|
+
maxRight = Math.max(maxRight, cx - BLOCK_GAP);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (cell.grid && collapsed.has(cell.id)) {
|
|
97
|
+
const item = {
|
|
98
|
+
type: "collapsed",
|
|
99
|
+
x: cx,
|
|
100
|
+
y: cy,
|
|
101
|
+
w: cw,
|
|
102
|
+
h: BLOCK_COLLAPSED_H,
|
|
103
|
+
label: cell.label,
|
|
104
|
+
node: cell,
|
|
105
|
+
lineNumber: cell.lineNumber
|
|
106
|
+
};
|
|
107
|
+
rowItems.push(item);
|
|
108
|
+
rowH = Math.max(rowH, BLOCK_COLLAPSED_H);
|
|
109
|
+
cx += cw + BLOCK_GAP;
|
|
110
|
+
maxRight = Math.max(maxRight, cx - BLOCK_GAP);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (cell.grid) {
|
|
114
|
+
const innerCols = cell.grid.cols ?? maxSpanSum(cell.grid);
|
|
115
|
+
const innerColW = Math.max(
|
|
116
|
+
MIN_COL * 0.66,
|
|
117
|
+
(cw - 2 * BLOCK_PAD - (innerCols + 1) * BLOCK_GAP) / innerCols
|
|
118
|
+
);
|
|
119
|
+
const inner = layoutGrid(
|
|
120
|
+
cell.grid,
|
|
121
|
+
cx + BLOCK_PAD,
|
|
122
|
+
cy + BLOCK_HEADER_H,
|
|
123
|
+
innerColW,
|
|
124
|
+
collapsed
|
|
125
|
+
);
|
|
126
|
+
const h = BLOCK_HEADER_H + inner.h + BLOCK_PAD;
|
|
127
|
+
rowItems.push({
|
|
128
|
+
type: "container",
|
|
129
|
+
x: cx,
|
|
130
|
+
y: cy,
|
|
131
|
+
w: cw,
|
|
132
|
+
h,
|
|
133
|
+
label: cell.label,
|
|
134
|
+
node: cell,
|
|
135
|
+
lineNumber: cell.lineNumber,
|
|
136
|
+
inner: inner.items
|
|
137
|
+
});
|
|
138
|
+
rowH = Math.max(rowH, h);
|
|
139
|
+
cx += cw + BLOCK_GAP;
|
|
140
|
+
maxRight = Math.max(maxRight, cx - BLOCK_GAP);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
rowItems.push({
|
|
144
|
+
type: "leaf",
|
|
145
|
+
x: cx,
|
|
146
|
+
y: cy,
|
|
147
|
+
w: cw,
|
|
148
|
+
h: BLOCK_LEAF_H,
|
|
149
|
+
label: cell.label,
|
|
150
|
+
node: cell,
|
|
151
|
+
lineNumber: cell.lineNumber
|
|
152
|
+
});
|
|
153
|
+
cx += cw + BLOCK_GAP;
|
|
154
|
+
maxRight = Math.max(maxRight, cx - BLOCK_GAP);
|
|
155
|
+
}
|
|
156
|
+
items.push(...rowItems);
|
|
157
|
+
cy += rowH + BLOCK_GAP;
|
|
158
|
+
}
|
|
159
|
+
const fitW = Math.max(gridW, maxRight - ox + BLOCK_GAP);
|
|
160
|
+
return { x: ox, y: oy, w: fitW, h: cy - oy, items };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/block/renderer.ts
|
|
164
|
+
var PADDING = 12;
|
|
165
|
+
var TITLE_BAND = 36;
|
|
166
|
+
var MIN_EXPORT_WIDTH = 220;
|
|
167
|
+
var LEGEND_POSITION = {
|
|
168
|
+
placement: "top-center",
|
|
169
|
+
titleRelation: "below-title"
|
|
170
|
+
};
|
|
171
|
+
function renderBlockForExport(container, parsed, palette, isDark, exportDims, options) {
|
|
172
|
+
renderBlock(container, parsed, palette, isDark, exportDims, {
|
|
173
|
+
exportMode: true,
|
|
174
|
+
...options
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function renderBlock(container, parsed, palette, isDark, exportDims, options = {}) {
|
|
178
|
+
if (parsed.error || parsed.top.rows.length === 0) return;
|
|
179
|
+
d3Selection.select(container).selectAll(":not([data-d3-tooltip])").remove();
|
|
180
|
+
const opts = parsed.options;
|
|
181
|
+
const showTitle = !!parsed.title;
|
|
182
|
+
const titleH = showTitle ? TITLE_BAND : 0;
|
|
183
|
+
const collapsed = options.collapsed ?? authoredCollapsedIds(parsed);
|
|
184
|
+
const layout = layoutBlock(parsed.top, { collapsed });
|
|
185
|
+
const legend = !opts.noLegend ? buildBlockLegend(parsed) : null;
|
|
186
|
+
let width;
|
|
187
|
+
let height;
|
|
188
|
+
if (options.exportMode) {
|
|
189
|
+
width = Math.max(layout.width, MIN_EXPORT_WIDTH) + PADDING * 2;
|
|
190
|
+
} else {
|
|
191
|
+
width = exportDims?.width ?? container.clientWidth;
|
|
192
|
+
}
|
|
193
|
+
const legendReserve = legend ? getMaxLegendReservedHeight(
|
|
194
|
+
{ groups: legend.groups, position: LEGEND_POSITION, mode: "preview" },
|
|
195
|
+
width
|
|
196
|
+
) + LEGEND_GROUP_GAP : 0;
|
|
197
|
+
const areaY = titleH + legendReserve + PADDING;
|
|
198
|
+
if (options.exportMode) {
|
|
199
|
+
height = areaY + layout.height + PADDING;
|
|
200
|
+
} else {
|
|
201
|
+
height = exportDims?.height ?? container.clientHeight;
|
|
202
|
+
}
|
|
203
|
+
if (width <= 0 || height <= 0) return;
|
|
204
|
+
const areaX = PADDING;
|
|
205
|
+
const areaW = Math.max(1, width - PADDING * 2);
|
|
206
|
+
const areaH = Math.max(1, height - areaY - PADDING);
|
|
207
|
+
const scale = Math.min(1, areaW / layout.width, areaH / layout.height);
|
|
208
|
+
const offsetX = areaX + (areaW - layout.width * scale) / 2;
|
|
209
|
+
const offsetY = areaY;
|
|
210
|
+
const svg = d3Selection.select(container).append("svg").attr("width", width).attr("height", height).attr("viewBox", `0 0 ${width} ${height}`).attr("preserveAspectRatio", "xMidYMin meet").attr("xmlns", "http://www.w3.org/2000/svg").attr("class", "dgmo-block").style("font-family", FONT_FAMILY);
|
|
211
|
+
if (showTitle) {
|
|
212
|
+
const title = svg.append("text").attr("class", "chart-title").attr("x", width / 2).attr("y", TITLE_Y).attr("text-anchor", "middle").attr("fill", palette.text).attr("font-family", FONT_FAMILY).attr("font-size", TITLE_FONT_SIZE).attr("font-weight", TITLE_FONT_WEIGHT).text(parsed.title);
|
|
213
|
+
if (parsed.titleLineNumber !== null) {
|
|
214
|
+
title.attr("data-line-number", parsed.titleLineNumber);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const activeGroup = parsed.tagGroups.length > 0 ? parsed.tagGroups[0].name : null;
|
|
218
|
+
const neutral = mix(palette.text, palette.bg, 22);
|
|
219
|
+
const root = svg.append("g").attr("class", "dgmo-block-cells").attr("transform", `translate(${offsetX},${offsetY}) scale(${scale})`);
|
|
220
|
+
drawItems(root, layout.items, {
|
|
221
|
+
palette,
|
|
222
|
+
tagGroups: parsed.tagGroups,
|
|
223
|
+
activeGroup,
|
|
224
|
+
activeKey: activeGroup ? tagAttrKey(activeGroup) : null,
|
|
225
|
+
neutral,
|
|
226
|
+
solidFill: opts.solidFill,
|
|
227
|
+
onToggle: options.onToggle
|
|
228
|
+
});
|
|
229
|
+
if (legend) {
|
|
230
|
+
const legendG = svg.append("g").attr("class", "dgmo-block-legend").attr("transform", `translate(0, ${titleH})`);
|
|
231
|
+
renderIntegratedLegend(legendG, {
|
|
232
|
+
groups: legend.groups,
|
|
233
|
+
palette: {
|
|
234
|
+
bg: palette.bg,
|
|
235
|
+
surface: palette.surface,
|
|
236
|
+
text: palette.text,
|
|
237
|
+
textMuted: palette.textMuted,
|
|
238
|
+
primary: palette.primary
|
|
239
|
+
},
|
|
240
|
+
isDark,
|
|
241
|
+
width,
|
|
242
|
+
mode: options.exportMode ? "export" : "preview",
|
|
243
|
+
position: LEGEND_POSITION,
|
|
244
|
+
activeGroup: legend.activeGroup
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function colorOf(node, ctx) {
|
|
249
|
+
if (!node || !ctx.activeGroup) return null;
|
|
250
|
+
return resolveTagColor(node.metadata, ctx.tagGroups, ctx.activeGroup) ?? null;
|
|
251
|
+
}
|
|
252
|
+
function clipLabel(s, maxWidth, fs) {
|
|
253
|
+
if (measureText(s, fs) <= maxWidth) return s;
|
|
254
|
+
let lo = 0;
|
|
255
|
+
let hi = s.length;
|
|
256
|
+
while (lo < hi) {
|
|
257
|
+
const mid = Math.ceil((lo + hi) / 2);
|
|
258
|
+
if (measureText(s.slice(0, mid) + "\u2026", fs) <= maxWidth) lo = mid;
|
|
259
|
+
else hi = mid - 1;
|
|
260
|
+
}
|
|
261
|
+
return lo <= 0 ? "" : s.slice(0, lo) + "\u2026";
|
|
262
|
+
}
|
|
263
|
+
var clipCounter = 0;
|
|
264
|
+
function drawItems(g, items, ctx, path = []) {
|
|
265
|
+
const { palette, solidFill: solid } = ctx;
|
|
266
|
+
for (const it of items) {
|
|
267
|
+
if (it.type === "empty") {
|
|
268
|
+
g.append("rect").attr("x", it.x).attr("y", it.y).attr("width", it.w).attr("height", it.h).attr("rx", 7).attr("fill", "none").attr("stroke", ctx.neutral).attr("stroke-width", 1).attr("stroke-dasharray", "3 4").attr("opacity", 0.7);
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const node = it.node;
|
|
272
|
+
const itemPath = [...path, node.id];
|
|
273
|
+
const color = colorOf(node, ctx);
|
|
274
|
+
const stroke = color ?? ctx.neutral;
|
|
275
|
+
const cell = g.append("g").attr("class", "dgmo-block-cell").attr("data-block-id", node.id).attr("data-block-path", itemPath.join(" / "));
|
|
276
|
+
if (it.lineNumber !== void 0)
|
|
277
|
+
cell.attr("data-line-number", it.lineNumber);
|
|
278
|
+
if (ctx.activeKey) {
|
|
279
|
+
const v = node.metadata[ctx.activeKey];
|
|
280
|
+
if (v) cell.attr(`data-tag-${ctx.activeKey}`, v);
|
|
281
|
+
}
|
|
282
|
+
if (it.type === "collapsed") {
|
|
283
|
+
const fill2 = color ? solid ? color : mix(color, palette.bg, 12) : palette.surface;
|
|
284
|
+
const cid = `dgmo-block-clip-${clipCounter++}`;
|
|
285
|
+
cell.append("clipPath").attr("id", cid).append("rect").attr("x", it.x).attr("y", it.y).attr("width", it.w).attr("height", it.h).attr("rx", 10);
|
|
286
|
+
cell.append("rect").attr("x", it.x).attr("y", it.y).attr("width", it.w).attr("height", it.h).attr("rx", 10).attr("fill", fill2).attr("stroke", stroke).attr("stroke-width", 1.5);
|
|
287
|
+
cell.append("text").attr("x", it.x + it.w / 2).attr("y", it.y + it.h / 2 + 4).attr("text-anchor", "middle").attr("font-size", 12.5).attr("font-weight", 700).attr("fill", palette.text).text(clipLabel(it.label ?? "", it.w - 24, 12.5));
|
|
288
|
+
cell.append("rect").attr("x", it.x).attr("y", it.y + it.h - BLOCK_BAR_H).attr("width", it.w).attr("height", BLOCK_BAR_H).attr("fill", solid && color ? palette.text : stroke).attr("clip-path", `url(#${cid})`);
|
|
289
|
+
bindToggle(cell, it, ctx, it.h);
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (it.type === "container") {
|
|
293
|
+
const fill2 = color ? solid ? color : mix(color, palette.bg, 7) : palette.surface;
|
|
294
|
+
cell.append("rect").attr("x", it.x).attr("y", it.y).attr("width", it.w).attr("height", it.h).attr("rx", 10).attr("fill", fill2).attr("stroke", stroke).attr("stroke-width", 1.5);
|
|
295
|
+
const sizeMetric = Math.min(it.w, it.h * 2.5);
|
|
296
|
+
const headerFs = Math.max(
|
|
297
|
+
13,
|
|
298
|
+
Math.min(20, Math.round(13 + (sizeMetric - 220) / 70))
|
|
299
|
+
);
|
|
300
|
+
const grow = (headerFs - 13) / (20 - 13);
|
|
301
|
+
const headerOpacity = 0.92 - grow * 0.3;
|
|
302
|
+
const headerY = it.y + Math.round(headerFs * 0.7) + 7;
|
|
303
|
+
cell.append("text").attr("x", it.x + it.w / 2).attr("y", headerY).attr("text-anchor", "middle").attr("font-size", headerFs).attr("font-weight", 700).attr("fill", palette.text).attr("opacity", headerOpacity).text(clipLabel(it.label ?? "", it.w - 24, headerFs));
|
|
304
|
+
bindToggle(cell, it, ctx, BLOCK_HEADER_H);
|
|
305
|
+
if (it.inner) drawItems(g, it.inner, ctx, itemPath);
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
const fill = color ? solid ? color : mix(color, palette.bg, 14) : palette.bg;
|
|
309
|
+
cell.attr("data-leaf", "true");
|
|
310
|
+
cell.append("rect").attr("x", it.x).attr("y", it.y).attr("width", it.w).attr("height", it.h).attr("rx", 8).attr("fill", fill).attr("stroke", stroke).attr("stroke-width", 1.25);
|
|
311
|
+
cell.append("text").attr("x", it.x + it.w / 2).attr("y", it.y + it.h / 2 + 5).attr("text-anchor", "middle").attr("font-size", 13).attr("font-weight", 600).attr("fill", palette.text).text(clipLabel(it.label ?? "", it.w - 16, 13));
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function bindToggle(cell, it, ctx, hitH) {
|
|
315
|
+
if (!ctx.onToggle || !it.node || it.lineNumber === void 0) return;
|
|
316
|
+
const id = it.node.id;
|
|
317
|
+
const ln = it.lineNumber;
|
|
318
|
+
cell.append("rect").attr("x", it.x).attr("y", it.y).attr("width", it.w).attr("height", hitH).attr("rx", 10).attr("fill", "transparent").style("cursor", "pointer").on("click", () => ctx.onToggle(id, ln));
|
|
319
|
+
}
|
|
320
|
+
function authoredCollapsedIds(parsed) {
|
|
321
|
+
const into = /* @__PURE__ */ new Set();
|
|
322
|
+
collectCollapsed(parsed, into);
|
|
323
|
+
return into;
|
|
324
|
+
}
|
|
325
|
+
function collectCollapsed(parsed, into) {
|
|
326
|
+
const walk = (grid) => {
|
|
327
|
+
for (const row of grid.rows)
|
|
328
|
+
for (const c of row)
|
|
329
|
+
if (isBlockNode(c)) {
|
|
330
|
+
if (c.collapsed && c.grid) into.add(c.id);
|
|
331
|
+
if (c.grid) walk(c.grid);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
walk(parsed.top);
|
|
335
|
+
}
|
|
336
|
+
function buildBlockLegend(parsed) {
|
|
337
|
+
if (parsed.tagGroups.length === 0) return null;
|
|
338
|
+
const tg = parsed.tagGroups[0];
|
|
339
|
+
const key = tagAttrKey(tg.name);
|
|
340
|
+
const used = /* @__PURE__ */ new Set();
|
|
341
|
+
const walk = (grid) => {
|
|
342
|
+
for (const row of grid.rows)
|
|
343
|
+
for (const c of row)
|
|
344
|
+
if (isBlockNode(c)) {
|
|
345
|
+
const v = c.metadata[key];
|
|
346
|
+
if (v) used.add(v.toLowerCase());
|
|
347
|
+
if (c.grid) walk(c.grid);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
walk(parsed.top);
|
|
351
|
+
const entries = tg.entries.filter((e) => used.has(e.value.toLowerCase())).map((e) => ({ value: e.value, color: e.color }));
|
|
352
|
+
if (entries.length === 0) return null;
|
|
353
|
+
return { groups: [{ name: tg.name, entries }], activeGroup: tg.name };
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export {
|
|
357
|
+
layoutBlock,
|
|
358
|
+
renderBlockForExport,
|
|
359
|
+
renderBlock,
|
|
360
|
+
authoredCollapsedIds
|
|
361
|
+
};
|
|
362
|
+
//# sourceMappingURL=chunk-RJE5JTVK.js.map
|