@diagrammo/dgmo 0.48.2 → 0.50.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/.cursorrules +12 -3
- package/.github/copilot-instructions.md +12 -3
- package/.windsurfrules +12 -3
- package/SKILL.md +12 -3
- package/dist/advanced.d.ts +851 -1
- package/dist/advanced.js +601 -177
- package/dist/auto.css +63 -0
- package/dist/auto.js +220 -110
- package/dist/auto.mjs +45920 -33167
- package/dist/block.css +63 -0
- package/dist/block.d.ts +13 -5
- package/dist/block.js +239 -62
- package/dist/{charts-d3-QOZHKTCT.js → charts-d3-DKUD7MQE.js} +9 -8
- package/dist/{chunk-3MQQNXPD.js → chunk-2C56LEML.js} +3 -3
- package/dist/{chunk-L66GEFB6.js → chunk-2JJ2KNPI.js} +4 -4
- package/dist/{chunk-6SM5NJQH.js → chunk-2QYTMIRR.js} +4 -4
- package/dist/{chunk-RJE5JTVK.js → chunk-3G6TMNVF.js} +7 -7
- package/dist/{chunk-MO5YHHMQ.js → chunk-3LKM6FMW.js} +2 -2
- package/dist/{chunk-76OWZ3BA.js → chunk-3P2DKJCG.js} +2 -2
- package/dist/chunk-3TDRHT4J.js +1043 -0
- package/dist/chunk-3XPUDB7B.js +420 -0
- package/dist/{chunk-2LACINWN.js → chunk-3ZPC476N.js} +7 -7
- package/dist/{chunk-G2H74XJZ.js → chunk-4BMJQFNK.js} +8 -8
- package/dist/{chunk-THXCFRTU.js → chunk-4S723I74.js} +9 -9
- package/dist/{chunk-6NYWYNBI.js → chunk-4XK3FLFB.js} +3 -3
- package/dist/chunk-5JSWBPZZ.js +607 -0
- package/dist/{chunk-WCT3NYCV.js → chunk-5LWQH6QV.js} +1 -1
- package/dist/{chunk-7DTWEFUE.js → chunk-5Z736BSU.js} +8 -8
- package/dist/{chunk-ERLBPDGU.js → chunk-6BFZKBGD.js} +2 -2
- package/dist/{chunk-6HO5ZTXK.js → chunk-6IAA2QQ2.js} +2 -2
- package/dist/{chunk-H6PI3KJT.js → chunk-6IUAK7RZ.js} +2 -2
- package/dist/{chunk-RTLBSQ3G.js → chunk-6M5PJFQG.js} +3 -3
- package/dist/{chunk-Z5CGSFJB.js → chunk-6X4AKWLF.js} +4 -4
- package/dist/{chunk-OJR3MQYV.js → chunk-6ZT4U37Q.js} +291 -52
- package/dist/{chunk-5QXL4NYS.js → chunk-7G2ER4CY.js} +10 -5
- package/dist/chunk-7PQYTZMA.js +681 -0
- package/dist/{chunk-OURHMODR.js → chunk-7RB5Q6MB.js} +11 -11
- package/dist/{chunk-YAA6IID3.js → chunk-7UEMZREK.js} +2 -2
- package/dist/{chunk-AN2MOO5T.js → chunk-A3WQVFBS.js} +3 -3
- package/dist/{chunk-VOKGH627.js → chunk-AHGF2YYA.js} +13 -3
- package/dist/{chunk-CI2G3OEB.js → chunk-ASS5YYIZ.js} +12 -12
- package/dist/{chunk-TYS6CSS5.js → chunk-BCYVE3N5.js} +2 -2
- package/dist/chunk-BDXC7MDK.js +2395 -0
- package/dist/chunk-BTUTZMPT.js +482 -0
- package/dist/{chunk-YGJTDXVR.js → chunk-C4GQDB5L.js} +2 -2
- package/dist/{chunk-Y2ZE3MSG.js → chunk-C63UWAKM.js} +2 -2
- package/dist/{chunk-725LDASD.js → chunk-CLD2OKV7.js} +2 -2
- package/dist/{chunk-WBRZJOEC.js → chunk-CMCR5WBW.js} +3 -3
- package/dist/{chunk-IZMRON6C.js → chunk-CVV36CWI.js} +2 -2
- package/dist/chunk-DMJJ3CEQ.js +254 -0
- package/dist/{chunk-MZSBFAPJ.js → chunk-EJTKV7CY.js} +9 -9
- package/dist/{chunk-FITOLXSX.js → chunk-EOFPYPAU.js} +26 -2
- package/dist/{chunk-X5LCYCL5.js → chunk-ER5SCQWQ.js} +5 -5
- package/dist/{chunk-4OHACBGX.js → chunk-F2L5GCQ4.js} +2 -2
- package/dist/{chunk-FCIIHT24.js → chunk-F5UDBSJY.js} +7 -7
- package/dist/{chunk-3JLKYGBQ.js → chunk-F7BFXWNQ.js} +2 -2
- package/dist/{chunk-FANX6UJR.js → chunk-FAL7NOK3.js} +11 -11
- package/dist/{chunk-BUPDIHML.js → chunk-FB2WHOEQ.js} +4 -4
- package/dist/chunk-FL4IOQ37.js +379 -0
- package/dist/{chunk-LIOHW36Z.js → chunk-GBE54KY6.js} +6 -5
- package/dist/{chunk-RUNNI6VE.js → chunk-GL5UZ6NY.js} +3 -3
- package/dist/{chunk-4GRI7MEB.js → chunk-GPWHQ5FJ.js} +6 -6
- package/dist/chunk-GROQGHCT.js +960 -0
- package/dist/{chunk-SGZYXELT.js → chunk-H73FP42Q.js} +9 -6
- package/dist/{chunk-PBAHEPLQ.js → chunk-HGN652MU.js} +7 -6
- package/dist/{chunk-3SMGIJDD.js → chunk-HHXOONLX.js} +13 -1
- package/dist/{chunk-QOOUC2J5.js → chunk-HQCHYB5F.js} +2 -2
- package/dist/{chunk-AELOBFW5.js → chunk-I4IFRCUB.js} +3 -3
- package/dist/{chunk-GMR5MFHJ.js → chunk-I7F2A35O.js} +2 -2
- package/dist/{chunk-T2OE3YQB.js → chunk-IA3FJYWR.js} +3 -3
- package/dist/chunk-IAEC4KLA.js +492 -0
- package/dist/chunk-IVKC4GID.js +32 -0
- package/dist/{chunk-HSH73DP6.js → chunk-JFYIP7XU.js} +139 -39
- package/dist/{chunk-CKNVO24D.js → chunk-JZNMXEIV.js} +2 -2
- package/dist/chunk-KJXIHOVL.js +940 -0
- package/dist/chunk-L2ZTFHAY.js +331 -0
- package/dist/{chunk-B7JUCQUA.js → chunk-M5RXSRO2.js} +4 -4
- package/dist/{chunk-ULOEATBZ.js → chunk-NFFIKVNO.js} +106 -29
- package/dist/{chunk-PZMETGLY.js → chunk-NISQC5KW.js} +358 -122
- package/dist/chunk-O4VUFXIH.js +574 -0
- package/dist/{chunk-RVMRZAPB.js → chunk-O76UD6VJ.js} +3 -3
- package/dist/{chunk-JM4LEPY3.js → chunk-O7NUCTFU.js} +2 -2
- package/dist/{chunk-JED6ZDEE.js → chunk-O7WP4ZD4.js} +2 -2
- package/dist/{chunk-EVCVDTXE.js → chunk-OHQEMBLI.js} +3 -3
- package/dist/{chunk-ZBWMSD5N.js → chunk-ONA5KPV3.js} +4 -4
- package/dist/{chunk-Y3J7VR52.js → chunk-OTAL43EH.js} +34 -2
- package/dist/{chunk-WCSOJFU3.js → chunk-OTP5KVLO.js} +3 -3
- package/dist/{chunk-RYEGFMUO.js → chunk-PGEGPSCZ.js} +2 -2
- package/dist/{chunk-ZO27FGJS.js → chunk-PH5X4GIP.js} +2 -2
- package/dist/{chunk-ZJEL4H2R.js → chunk-PJUGRJHJ.js} +9 -9
- package/dist/{chunk-ZGR7ULFJ.js → chunk-PLZI6KPM.js} +26 -14
- package/dist/{chunk-3R5POCTZ.js → chunk-PMN3Q7RJ.js} +6 -6
- package/dist/{chunk-YGJZWZTY.js → chunk-PZFVK3IH.js} +2 -2
- package/dist/chunk-Q4V4XQWV.js +158 -0
- package/dist/chunk-QDFNCATJ.js +325 -0
- package/dist/{chunk-QEBUY5NY.js → chunk-QFQ35BTO.js} +4 -4
- package/dist/chunk-QQJUTGQH.js +135 -0
- package/dist/{chunk-PWIHZ6NJ.js → chunk-QUJGFNFN.js} +4 -4
- package/dist/{chunk-J5FIXQRT.js → chunk-R56LASIN.js} +4 -4
- package/dist/{chunk-SRTU6HMQ.js → chunk-RV26LTUU.js} +8 -8
- package/dist/chunk-RV6A2B5S.js +354 -0
- package/dist/{chunk-EB6FPQUP.js → chunk-S5GRONXL.js} +3 -3
- package/dist/{chunk-5MLYVTYM.js → chunk-SCHXJTZL.js} +2 -2
- package/dist/{chunk-T3UBLACL.js → chunk-SCQ5VPUF.js} +19 -5
- package/dist/{chunk-PBHE5UG6.js → chunk-SGFZZAUO.js} +46 -12
- package/dist/{chunk-BUVJFRPY.js → chunk-SU2VBK4L.js} +4 -4
- package/dist/{chunk-SML67VPV.js → chunk-T4BRO3Z6.js} +3 -3
- package/dist/{chunk-NURGB5Z4.js → chunk-TSA237IM.js} +2 -2
- package/dist/chunk-TWCLK2GA.js +273 -0
- package/dist/{chunk-IJZFN3HM.js → chunk-TWQUYVP3.js} +4 -4
- package/dist/{chunk-DKEPS5LH.js → chunk-U2HGPLZS.js} +36 -2
- package/dist/{chunk-B65G5DNL.js → chunk-URSQLCTR.js} +3 -3
- package/dist/{chunk-ILKORZ3H.js → chunk-UUS2GIJZ.js} +7 -7
- package/dist/{chunk-XAKEUMEJ.js → chunk-UXOSVCLJ.js} +4 -4
- package/dist/{chunk-QLCCJEJI.js → chunk-WCUHAQKB.js} +2 -2
- package/dist/{chunk-WVAJFAIA.js → chunk-WWN566I7.js} +257 -101
- package/dist/{chunk-IPWPWM6R.js → chunk-X2NMFTG3.js} +111 -10
- package/dist/{chunk-UWN33VNX.js → chunk-XCLHOZAM.js} +10 -10
- package/dist/{chunk-P235SVAH.js → chunk-XDXNDSKO.js} +2 -2
- package/dist/chunk-XHVV4NVW.js +51 -0
- package/dist/{chunk-33LCUH4H.js → chunk-XMVQ5F4M.js} +4 -4
- package/dist/{chunk-MITI6NOL.js → chunk-YA7D2N2O.js} +11 -11
- package/dist/{chunk-7JEGTRLD.js → chunk-YB3FW24O.js} +3 -3
- package/dist/chunk-YNRDWYZP.js +295 -0
- package/dist/{chunk-44CM72SQ.js → chunk-YZLMKW4T.js} +3 -3
- package/dist/chunk-Z6XJQ6KO.js +452 -0
- package/dist/cli.cjs +179 -133
- package/dist/clock.d.ts +10 -0
- package/dist/clock.js +235 -0
- package/dist/countdown.d.ts +12 -0
- package/dist/countdown.js +450 -0
- package/dist/dgmo-router-QOMFCOOV.js +84 -0
- package/dist/dimensions-P5FSX2QN.js +22 -0
- package/dist/editor.js +43 -2
- package/dist/element.js +220 -110
- package/dist/element.mjs +45920 -33167
- package/dist/{flowchart-parser-ZNSKIBVR.js → flowchart-parser-OE4WHLTF.js} +4 -4
- package/dist/{flowchart-renderer-SNDSII4D.js → flowchart-renderer-GPCSMTOR.js} +8 -8
- package/dist/highlight.d.ts +17 -1
- package/dist/highlight.js +163 -6
- package/dist/index.d.ts +5 -1
- package/dist/index.js +199 -233
- package/dist/{layout-HRBZPFCN.js → layout-34CLNICW.js} +5 -5
- package/dist/layout-46366KBT.js +10 -0
- package/dist/{layout-HWDSRX5E.js → layout-5BG6DFCU.js} +6 -6
- package/dist/layout-6RDJHS6E.js +9 -0
- package/dist/{layout-7QXCNOVS.js → layout-7H4H46CS.js} +3 -3
- package/dist/{layout-46N4JJYK.js → layout-7SKMFYHL.js} +5 -5
- package/dist/{layout-EE6GE46Y.js → layout-DC4TVXER.js} +5 -5
- package/dist/layout-FGQWRYYW.js +14 -0
- package/dist/{layout-S2QBYSK2.js → layout-NXG63LWH.js} +3 -3
- package/dist/{layout-N76NR4ZO.js → layout-PUQCB6AN.js} +7 -7
- package/dist/{layout-HYZPWAK5.js → layout-QNUQLEHU.js} +3 -3
- package/dist/{layout-UM5F4DJB.js → layout-T3OZU5QW.js} +5 -5
- package/dist/layout-TJIWF7EM.js +14 -0
- package/dist/layout-VYELEAW7.js +14 -0
- package/dist/{layout-5RA6QWR6.js → layout-WZHNDT2O.js} +6 -6
- package/dist/{layout-search-OYV77HHS.js → layout-search-QS44PI5R.js} +6 -6
- package/dist/{parser-6BTRLKRZ.js → parser-45DENHFZ.js} +4 -4
- package/dist/{parser-TFZFBVWN.js → parser-4AI5ZN5F.js} +3 -3
- package/dist/{parser-XDVELHRK.js → parser-4P36TUVD.js} +4 -4
- package/dist/{parser-ZSDPZYQP.js → parser-5AURY4A6.js} +4 -4
- package/dist/{parser-N5O4IHUN.js → parser-A2BEFMGK.js} +4 -4
- package/dist/parser-B5FVS7O6.js +11 -0
- package/dist/{parser-NGU3ETO6.js → parser-C2HF2C2E.js} +4 -4
- package/dist/parser-CSFUN3CT.js +14 -0
- package/dist/{parser-TRTHDFPP.js → parser-D3QT6GWN.js} +5 -5
- package/dist/parser-D5637H5H.js +15 -0
- package/dist/{parser-VQP2UJ6W.js → parser-DFFEDKHH.js} +3 -3
- package/dist/parser-DOKMZXVZ.js +13 -0
- package/dist/parser-FMPCVFRK.js +15 -0
- package/dist/{parser-Y6WTBU76.js → parser-HYRTF3DO.js} +3 -3
- package/dist/{parser-I6KXEYFK.js → parser-I2UIJKVQ.js} +4 -4
- package/dist/{parser-O5J4VBII.js → parser-IBWNAPY4.js} +3 -3
- package/dist/{parser-PQ3POX45.js → parser-KUQWRPIT.js} +4 -4
- package/dist/{parser-2MFP2H2E.js → parser-LWKKBNSA.js} +3 -3
- package/dist/{parser-OV7NOBW6.js → parser-O4QFCUW7.js} +5 -5
- package/dist/{parser-IXSZZQHY.js → parser-PGMQDD4G.js} +4 -4
- package/dist/{parser-3STE62GB.js → parser-Q4QKCIWQ.js} +4 -4
- package/dist/parser-QTOB4KFL.js +14 -0
- package/dist/{parser-2EWECDSA.js → parser-QYYM4QVW.js} +4 -4
- package/dist/{parser-4OGOBJJ4.js → parser-RZMQP7MM.js} +4 -4
- package/dist/parser-RZPVAQVX.js +11 -0
- package/dist/parser-SOUJOEYI.js +13 -0
- package/dist/{parser-4FL2CMDG.js → parser-UQE5OWZI.js} +5 -5
- package/dist/{parser-NRAI6O25.js → parser-WAV5JRPT.js} +4 -4
- package/dist/{parser-KNSQSKQO.js → parser-YLKYBRIT.js} +5 -5
- package/dist/{parser-XKRP7QKP.js → parser-YS7TOS2K.js} +3 -3
- package/dist/{parser-AQETEVRW.js → parser-ZSOWUBML.js} +5 -5
- package/dist/{parser-CFZD5IBL.js → parser-ZTBATMLX.js} +4 -4
- package/dist/{renderer-VACVQYML.js → renderer-35HSIDMZ.js} +8 -8
- package/dist/{renderer-5MYBMBYO.js → renderer-4ITCHBT7.js} +5 -5
- package/dist/{renderer-CLJHQPBJ.js → renderer-67NPCBIS.js} +11 -11
- package/dist/{renderer-5NDVNDAZ.js → renderer-6GHYK7DX.js} +9 -9
- package/dist/{renderer-Z7I3W2PP.js → renderer-6RNGHC5Z.js} +8 -8
- package/dist/renderer-72LGR2YF.js +14 -0
- package/dist/{renderer-KQB7UGDS.js → renderer-7RH2SI3B.js} +3 -3
- package/dist/renderer-7SWMIFMM.js +21 -0
- package/dist/renderer-BBCEFILK.js +24 -0
- package/dist/{renderer-JGBKUCZD.js → renderer-BSW7SRIZ.js} +4 -4
- package/dist/{renderer-BYCNMBF7.js → renderer-BY533UWU.js} +11 -11
- package/dist/{renderer-6W5462RB.js → renderer-BZSBPTZJ.js} +9 -9
- package/dist/{renderer-7MVLWWQD.js → renderer-CXUC4KAD.js} +9 -9
- package/dist/{renderer-QIWVHWZO.js → renderer-DAXMXIKD.js} +3 -3
- package/dist/renderer-FZUKFUNZ.js +23 -0
- package/dist/renderer-G2NLGNKF.js +17 -0
- package/dist/renderer-GO3FE3RA.js +24 -0
- package/dist/{renderer-ZGNTUWC4.js → renderer-HPGR6USK.js} +8 -8
- package/dist/{renderer-UV6MI64M.js → renderer-HVCU2C3Z.js} +3 -3
- package/dist/renderer-ICJN2SA2.js +24 -0
- package/dist/{renderer-AWWAF6XD.js → renderer-INEXO7B6.js} +10 -10
- package/dist/{renderer-YY2OSF6E.js → renderer-KDYCFRBX.js} +8 -8
- package/dist/renderer-KY4KQBTF.js +19 -0
- package/dist/{renderer-B2OMQIQG.js → renderer-LBN65V45.js} +13 -13
- package/dist/{renderer-N43WR5GV.js → renderer-MGBWOCXG.js} +10 -10
- package/dist/{renderer-PGX2TKVS.js → renderer-O4JKUGKO.js} +8 -8
- package/dist/{renderer-4JHRUBE6.js → renderer-OOGFODWP.js} +10 -10
- package/dist/{renderer-6EEZHMH4.js → renderer-Q6ZKPLS6.js} +9 -9
- package/dist/{renderer-RPOA5YPZ.js → renderer-SZQ326M5.js} +12 -12
- package/dist/{renderer-ZRNG54CW.js → renderer-TKG6LS4U.js} +11 -11
- package/dist/{renderer-W4M6QLIJ.js → renderer-TQMZGDAX.js} +13 -13
- package/dist/renderer-radial-JELMHQ24.js +21 -0
- package/dist/{resolver-NOAA7ID7.js → resolver-FHBCO3PL.js} +3 -3
- package/dist/{state-parser-Z2V23ATR.js → state-parser-3REXRK3R.js} +4 -4
- package/dist/{state-renderer-B4DQBM6M.js → state-renderer-XYLNRWXR.js} +8 -8
- package/docs/ai-integration.md +12 -3
- package/docs/language-reference.md +429 -24
- package/gallery/fixtures/body.dgmo +17 -0
- package/gallery/fixtures/bracket.dgmo +30 -0
- package/gallery/fixtures/clock.dgmo +8 -0
- package/gallery/fixtures/countdown.dgmo +3 -0
- package/gallery/fixtures/family.dgmo +23 -0
- package/gallery/fixtures/goal.dgmo +4 -0
- package/gallery/fixtures/sketch.dgmo +22 -0
- package/package.json +12 -4
- package/dist/chunk-ODZVHU3R.js +0 -153
- package/dist/dgmo-router-X35VLZLM.js +0 -73
- package/dist/dimensions-J3FHIMJ6.js +0 -22
- package/dist/layout-5T6RH5M6.js +0 -14
- package/dist/layout-G23F7LDH.js +0 -9
- package/dist/layout-OB3RI63S.js +0 -14
- package/dist/parser-JAL2HD4I.js +0 -13
- package/dist/renderer-SMIBCRVB.js +0 -24
- package/dist/renderer-radial-C32GPJQ7.js +0 -21
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SKETCH_DIAGNOSTIC_CODES
|
|
3
|
+
} from "./chunk-XHVV4NVW.js";
|
|
4
|
+
import {
|
|
5
|
+
makeDgmoError
|
|
6
|
+
} from "./chunk-CXK4DZH3.js";
|
|
7
|
+
|
|
8
|
+
// src/sketch/geometry.ts
|
|
9
|
+
var SKETCH_PHI = (1 + Math.sqrt(5)) / 2;
|
|
10
|
+
var SKETCH_GEOMETRY = {
|
|
11
|
+
/** px per grid cell (the dot-grid pitch) */
|
|
12
|
+
cellPx: 26,
|
|
13
|
+
/** universal footprint width, in grid cells */
|
|
14
|
+
footprintCellsW: 8,
|
|
15
|
+
/**
|
|
16
|
+
* Legacy — the gap is now a derived half-unit (footprint/2 per axis), not
|
|
17
|
+
* these cell counts. Kept only so the shape of SKETCH_GEOMETRY is stable.
|
|
18
|
+
*/
|
|
19
|
+
gapCellsX: 4,
|
|
20
|
+
gapCellsY: 4,
|
|
21
|
+
/** box reserved top band, px (spec decision 12) */
|
|
22
|
+
bandPx: 44,
|
|
23
|
+
/** box frame padding around the children bbox, px */
|
|
24
|
+
boxPadPx: 26,
|
|
25
|
+
/** edge-ring (connect hook) width as a fraction of footprint height */
|
|
26
|
+
ringFrac: 0.22
|
|
27
|
+
};
|
|
28
|
+
var SKETCH_FOOT_W = SKETCH_GEOMETRY.footprintCellsW * SKETCH_GEOMETRY.cellPx;
|
|
29
|
+
var SKETCH_FOOT_H = 2 * Math.round(SKETCH_FOOT_W / SKETCH_PHI / 2);
|
|
30
|
+
var SKETCH_HALF_SLOT_X = SKETCH_FOOT_W / 2;
|
|
31
|
+
var SKETCH_HALF_SLOT_Y = SKETCH_FOOT_H / 2;
|
|
32
|
+
var SKETCH_SEP = 3;
|
|
33
|
+
var SKETCH_SLOT_X = SKETCH_HALF_SLOT_X * SKETCH_SEP;
|
|
34
|
+
var SKETCH_SLOT_Y = SKETCH_HALF_SLOT_Y * SKETCH_SEP;
|
|
35
|
+
function sketchSlotToPx(c, r) {
|
|
36
|
+
return { x: c * SKETCH_HALF_SLOT_X, y: r * SKETCH_HALF_SLOT_Y };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/sketch/collapse.ts
|
|
40
|
+
function collapseSketch(parsed, collapsedLabels) {
|
|
41
|
+
const collapsed = collapsedLabels ?? new Set(parsed.boxes.filter((b) => b.collapsed).map((b) => b.label));
|
|
42
|
+
if (collapsed.size === 0) {
|
|
43
|
+
return {
|
|
44
|
+
nodes: parsed.nodes,
|
|
45
|
+
boxes: parsed.boxes,
|
|
46
|
+
virtualBoxes: [],
|
|
47
|
+
edges: parsed.edges,
|
|
48
|
+
collapsedChildCounts: /* @__PURE__ */ new Map()
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const virtualBoxes = parsed.boxes.filter((b) => collapsed.has(b.label));
|
|
52
|
+
const boxes = parsed.boxes.filter((b) => !collapsed.has(b.label));
|
|
53
|
+
const nodeToVirtual = /* @__PURE__ */ new Map();
|
|
54
|
+
const collapsedChildCounts = /* @__PURE__ */ new Map();
|
|
55
|
+
for (const box of virtualBoxes) {
|
|
56
|
+
collapsedChildCounts.set(box.label, box.children.length);
|
|
57
|
+
for (const childId of box.children) nodeToVirtual.set(childId, box.id);
|
|
58
|
+
}
|
|
59
|
+
const nodes = parsed.nodes.filter((n) => !nodeToVirtual.has(n.id));
|
|
60
|
+
const edges = [];
|
|
61
|
+
const seen = /* @__PURE__ */ new Set();
|
|
62
|
+
for (const edge of parsed.edges) {
|
|
63
|
+
const sourceId = nodeToVirtual.get(edge.sourceId) ?? edge.sourceId;
|
|
64
|
+
const targetId = nodeToVirtual.get(edge.targetId) ?? edge.targetId;
|
|
65
|
+
if (sourceId === targetId) continue;
|
|
66
|
+
const key = `${sourceId}|${targetId}|${edge.label ?? ""}|${edge.heads}|${edge.dashed}`;
|
|
67
|
+
if (seen.has(key)) continue;
|
|
68
|
+
seen.add(key);
|
|
69
|
+
edges.push({ ...edge, sourceId, targetId });
|
|
70
|
+
}
|
|
71
|
+
return { nodes, boxes, virtualBoxes, edges, collapsedChildCounts };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/sketch/layout.ts
|
|
75
|
+
function unitRect(c, r) {
|
|
76
|
+
return { c, r, w: SKETCH_SEP, h: SKETCH_SEP };
|
|
77
|
+
}
|
|
78
|
+
function rectsOverlap(a, b) {
|
|
79
|
+
return a.c < b.c + b.w && b.c < a.c + a.w && a.r < b.r + b.h && b.r < a.r + a.h;
|
|
80
|
+
}
|
|
81
|
+
function collidesAny(rect, occupied) {
|
|
82
|
+
for (const o of occupied) if (rectsOverlap(rect, o)) return true;
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
function nearestFree(base, occupied) {
|
|
86
|
+
if (!collidesAny(base, occupied)) return { c: base.c, r: base.r };
|
|
87
|
+
for (let d = 1; d <= 200; d++) {
|
|
88
|
+
const candidates = [];
|
|
89
|
+
for (let dc = -d; dc <= d; dc++) {
|
|
90
|
+
const dr = d - Math.abs(dc);
|
|
91
|
+
candidates.push({ c: base.c + dc, r: base.r + dr });
|
|
92
|
+
if (dr !== 0) candidates.push({ c: base.c + dc, r: base.r - dr });
|
|
93
|
+
}
|
|
94
|
+
candidates.sort((a, b) => {
|
|
95
|
+
const costA = (a.r < base.r ? 2 : 0) + (a.c < base.c ? 1 : 0);
|
|
96
|
+
const costB = (b.r < base.r ? 2 : 0) + (b.c < base.c ? 1 : 0);
|
|
97
|
+
return costA - costB || a.r - b.r || a.c - b.c;
|
|
98
|
+
});
|
|
99
|
+
for (const cand of candidates) {
|
|
100
|
+
if (!collidesAny({ ...base, c: cand.c, r: cand.r }, occupied)) {
|
|
101
|
+
return cand;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return { c: base.c, r: base.r };
|
|
106
|
+
}
|
|
107
|
+
function layoutChildren(box, nodesById, warn) {
|
|
108
|
+
const occupied = [];
|
|
109
|
+
const children = [];
|
|
110
|
+
const pending = [];
|
|
111
|
+
for (const id of box.children) {
|
|
112
|
+
const node = nodesById.get(id);
|
|
113
|
+
if (!node) continue;
|
|
114
|
+
if (node.at === null) {
|
|
115
|
+
pending.push(node);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const target = unitRect(node.at.c, node.at.r);
|
|
119
|
+
const spot = nearestFree(target, occupied);
|
|
120
|
+
if (spot.c !== node.at.c || spot.r !== node.at.r) {
|
|
121
|
+
warn(node.lineNumber, node.label);
|
|
122
|
+
}
|
|
123
|
+
occupied.push(unitRect(spot.c, spot.r));
|
|
124
|
+
children.push({ node, c: spot.c, r: spot.r });
|
|
125
|
+
}
|
|
126
|
+
let flowRow = occupied.length > 0 ? Math.max(...occupied.map((o) => o.r)) + SKETCH_SEP : 0;
|
|
127
|
+
let flowCol = 0;
|
|
128
|
+
const wrapAt = Math.max(
|
|
129
|
+
SKETCH_SEP * 3,
|
|
130
|
+
occupied.length > 0 ? Math.max(...occupied.map((o) => o.c)) + SKETCH_SEP : SKETCH_SEP * 3
|
|
131
|
+
);
|
|
132
|
+
for (const node of pending) {
|
|
133
|
+
let placed = false;
|
|
134
|
+
while (!placed) {
|
|
135
|
+
const rect = unitRect(flowCol, flowRow);
|
|
136
|
+
if (!collidesAny(rect, occupied)) {
|
|
137
|
+
occupied.push(rect);
|
|
138
|
+
children.push({ node, c: flowCol, r: flowRow });
|
|
139
|
+
placed = true;
|
|
140
|
+
}
|
|
141
|
+
flowCol += SKETCH_SEP;
|
|
142
|
+
if (flowCol > wrapAt) {
|
|
143
|
+
flowCol = 0;
|
|
144
|
+
flowRow += SKETCH_SEP;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
let extent;
|
|
149
|
+
if (occupied.length === 0) {
|
|
150
|
+
extent = { c: 0, r: 0, w: SKETCH_SEP, h: SKETCH_SEP };
|
|
151
|
+
} else {
|
|
152
|
+
const cMin = Math.min(...occupied.map((o) => o.c));
|
|
153
|
+
const rMin = Math.min(...occupied.map((o) => o.r));
|
|
154
|
+
const cMax = Math.max(...occupied.map((o) => o.c + o.w));
|
|
155
|
+
const rMax = Math.max(...occupied.map((o) => o.r + o.h));
|
|
156
|
+
extent = { c: cMin, r: rMin, w: cMax - cMin, h: rMax - rMin };
|
|
157
|
+
}
|
|
158
|
+
return { children, extent };
|
|
159
|
+
}
|
|
160
|
+
function layoutSketch(parsed, options = {}) {
|
|
161
|
+
const diagnostics = [];
|
|
162
|
+
const overlapWarn = (line, label) => {
|
|
163
|
+
diagnostics.push(
|
|
164
|
+
makeDgmoError(
|
|
165
|
+
line,
|
|
166
|
+
`Shape "${label}" overlapped another at its authored position \u2014 moved to the nearest free slot`,
|
|
167
|
+
"warning",
|
|
168
|
+
SKETCH_DIAGNOSTIC_CODES.OVERLAP_RESOLVED
|
|
169
|
+
)
|
|
170
|
+
);
|
|
171
|
+
};
|
|
172
|
+
const collapsed = collapseSketch(parsed, options.collapsedBoxes);
|
|
173
|
+
const nodesById = new Map(collapsed.nodes.map((n) => [n.id, n]));
|
|
174
|
+
const padHsX = SKETCH_GEOMETRY.boxPadPx / SKETCH_HALF_SLOT_X;
|
|
175
|
+
const padHsY = SKETCH_GEOMETRY.boxPadPx / SKETCH_HALF_SLOT_Y;
|
|
176
|
+
const bandHs = SKETCH_GEOMETRY.bandPx / SKETCH_HALF_SLOT_Y;
|
|
177
|
+
const boxLocal = /* @__PURE__ */ new Map();
|
|
178
|
+
const inExpandedBox = /* @__PURE__ */ new Set();
|
|
179
|
+
for (const box of collapsed.boxes) {
|
|
180
|
+
const local = layoutChildren(box, nodesById, overlapWarn);
|
|
181
|
+
boxLocal.set(box.id, local);
|
|
182
|
+
for (const child of local.children) inExpandedBox.add(child.node.id);
|
|
183
|
+
}
|
|
184
|
+
const rootUnits = [];
|
|
185
|
+
for (const node of collapsed.nodes) {
|
|
186
|
+
if (!inExpandedBox.has(node.id)) rootUnits.push({ kind: "shape", node });
|
|
187
|
+
}
|
|
188
|
+
for (const box of collapsed.virtualBoxes) {
|
|
189
|
+
rootUnits.push({ kind: "virtual", box });
|
|
190
|
+
}
|
|
191
|
+
for (const box of collapsed.boxes) {
|
|
192
|
+
rootUnits.push({ kind: "box", box });
|
|
193
|
+
}
|
|
194
|
+
rootUnits.sort((a, b) => {
|
|
195
|
+
const la = a.kind === "shape" ? a.node.lineNumber : a.box.lineNumber;
|
|
196
|
+
const lb = b.kind === "shape" ? b.node.lineNumber : b.box.lineNumber;
|
|
197
|
+
return la - lb;
|
|
198
|
+
});
|
|
199
|
+
const rectFor = (unit, c, r) => {
|
|
200
|
+
if (unit.kind === "box") {
|
|
201
|
+
const local = boxLocal.get(unit.box.id);
|
|
202
|
+
return {
|
|
203
|
+
c: c + local.extent.c - padHsX,
|
|
204
|
+
r: r + local.extent.r - bandHs,
|
|
205
|
+
w: local.extent.w + 2 * padHsX,
|
|
206
|
+
h: local.extent.h + bandHs + padHsY
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return unitRect(c, r);
|
|
210
|
+
};
|
|
211
|
+
const occupied = [];
|
|
212
|
+
const placedAt = /* @__PURE__ */ new Map();
|
|
213
|
+
const pending = [];
|
|
214
|
+
for (const unit of rootUnits) {
|
|
215
|
+
const at = unit.kind === "shape" ? unit.node.at : unit.box.at;
|
|
216
|
+
if (at === null) {
|
|
217
|
+
pending.push(unit);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
const base = rectFor(unit, at.c, at.r);
|
|
221
|
+
let spot = { c: at.c, r: at.r };
|
|
222
|
+
if (collidesAny(base, occupied)) {
|
|
223
|
+
const freed = nearestFree(base, occupied);
|
|
224
|
+
spot = {
|
|
225
|
+
c: at.c + (freed.c - base.c),
|
|
226
|
+
r: at.r + (freed.r - base.r)
|
|
227
|
+
};
|
|
228
|
+
const line = unit.kind === "shape" ? unit.node.lineNumber : unit.box.lineNumber;
|
|
229
|
+
const label = unit.kind === "shape" ? unit.node.label : unit.box.label;
|
|
230
|
+
overlapWarn(line, label);
|
|
231
|
+
}
|
|
232
|
+
occupied.push(rectFor(unit, spot.c, spot.r));
|
|
233
|
+
placedAt.set(unit, spot);
|
|
234
|
+
}
|
|
235
|
+
let flowRow = occupied.length > 0 ? Math.ceil(Math.max(...occupied.map((o) => o.r + o.h))) : 0;
|
|
236
|
+
let flowCol = 0;
|
|
237
|
+
const wrapAt = Math.max(
|
|
238
|
+
SKETCH_SEP * 4,
|
|
239
|
+
occupied.length > 0 ? Math.ceil(Math.max(...occupied.map((o) => o.c + o.w))) : SKETCH_SEP * 4
|
|
240
|
+
);
|
|
241
|
+
for (const unit of pending) {
|
|
242
|
+
let placed = false;
|
|
243
|
+
while (!placed) {
|
|
244
|
+
const rect = rectFor(unit, flowCol, flowRow);
|
|
245
|
+
if (!collidesAny(rect, occupied)) {
|
|
246
|
+
occupied.push(rect);
|
|
247
|
+
placedAt.set(unit, { c: flowCol, r: flowRow });
|
|
248
|
+
placed = true;
|
|
249
|
+
}
|
|
250
|
+
flowCol += SKETCH_SEP;
|
|
251
|
+
if (flowCol > wrapAt) {
|
|
252
|
+
flowCol = 0;
|
|
253
|
+
flowRow += SKETCH_SEP;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const allRects = rootUnits.map((u) => {
|
|
258
|
+
const spot = placedAt.get(u);
|
|
259
|
+
return rectFor(u, spot.c, spot.r);
|
|
260
|
+
});
|
|
261
|
+
const cMin = allRects.length > 0 ? Math.min(...allRects.map((r) => r.c)) : 0;
|
|
262
|
+
const rMin = allRects.length > 0 ? Math.min(...allRects.map((r) => r.r)) : 0;
|
|
263
|
+
const toPx = (c, r) => ({
|
|
264
|
+
x: (c - cMin) * SKETCH_HALF_SLOT_X,
|
|
265
|
+
y: (r - rMin) * SKETCH_HALF_SLOT_Y
|
|
266
|
+
});
|
|
267
|
+
const nodes = [];
|
|
268
|
+
const boxes = [];
|
|
269
|
+
for (const unit of rootUnits) {
|
|
270
|
+
const spot = placedAt.get(unit);
|
|
271
|
+
if (unit.kind === "shape") {
|
|
272
|
+
const { x, y } = toPx(spot.c, spot.r);
|
|
273
|
+
nodes.push({
|
|
274
|
+
id: unit.node.id,
|
|
275
|
+
label: unit.node.label,
|
|
276
|
+
shape: unit.node.shape,
|
|
277
|
+
metadata: unit.node.metadata,
|
|
278
|
+
...unit.node.description && { description: unit.node.description },
|
|
279
|
+
lineNumber: unit.node.lineNumber,
|
|
280
|
+
slot: spot,
|
|
281
|
+
x,
|
|
282
|
+
y,
|
|
283
|
+
w: SKETCH_FOOT_W,
|
|
284
|
+
h: SKETCH_FOOT_H
|
|
285
|
+
});
|
|
286
|
+
} else if (unit.kind === "virtual") {
|
|
287
|
+
const { x, y } = toPx(spot.c, spot.r);
|
|
288
|
+
nodes.push({
|
|
289
|
+
id: unit.box.id,
|
|
290
|
+
label: unit.box.label,
|
|
291
|
+
shape: "rectangle",
|
|
292
|
+
metadata: unit.box.metadata,
|
|
293
|
+
lineNumber: unit.box.lineNumber,
|
|
294
|
+
slot: spot,
|
|
295
|
+
x,
|
|
296
|
+
y,
|
|
297
|
+
w: SKETCH_FOOT_W,
|
|
298
|
+
h: SKETCH_FOOT_H,
|
|
299
|
+
isCollapsedBox: true,
|
|
300
|
+
childCount: collapsed.collapsedChildCounts.get(unit.box.label) ?? 0
|
|
301
|
+
});
|
|
302
|
+
} else {
|
|
303
|
+
const local = boxLocal.get(unit.box.id);
|
|
304
|
+
let minX = Infinity;
|
|
305
|
+
let minY = Infinity;
|
|
306
|
+
let maxX = -Infinity;
|
|
307
|
+
let maxY = -Infinity;
|
|
308
|
+
for (const child of local.children) {
|
|
309
|
+
const abs = toPx(spot.c + child.c, spot.r + child.r);
|
|
310
|
+
nodes.push({
|
|
311
|
+
id: child.node.id,
|
|
312
|
+
label: child.node.label,
|
|
313
|
+
shape: child.node.shape,
|
|
314
|
+
metadata: child.node.metadata,
|
|
315
|
+
...child.node.description && {
|
|
316
|
+
description: child.node.description
|
|
317
|
+
},
|
|
318
|
+
boxLabel: unit.box.label,
|
|
319
|
+
lineNumber: child.node.lineNumber,
|
|
320
|
+
slot: { c: spot.c + child.c, r: spot.r + child.r },
|
|
321
|
+
x: abs.x,
|
|
322
|
+
y: abs.y,
|
|
323
|
+
w: SKETCH_FOOT_W,
|
|
324
|
+
h: SKETCH_FOOT_H
|
|
325
|
+
});
|
|
326
|
+
minX = Math.min(minX, abs.x);
|
|
327
|
+
minY = Math.min(minY, abs.y);
|
|
328
|
+
maxX = Math.max(maxX, abs.x + SKETCH_FOOT_W);
|
|
329
|
+
maxY = Math.max(maxY, abs.y + SKETCH_FOOT_H);
|
|
330
|
+
}
|
|
331
|
+
if (minX === Infinity) {
|
|
332
|
+
const origin = toPx(spot.c, spot.r);
|
|
333
|
+
minX = origin.x;
|
|
334
|
+
minY = origin.y + SKETCH_GEOMETRY.bandPx;
|
|
335
|
+
maxX = origin.x + SKETCH_FOOT_W;
|
|
336
|
+
maxY = minY;
|
|
337
|
+
}
|
|
338
|
+
boxes.push({
|
|
339
|
+
id: unit.box.id,
|
|
340
|
+
label: unit.box.label,
|
|
341
|
+
metadata: unit.box.metadata,
|
|
342
|
+
lineNumber: unit.box.lineNumber,
|
|
343
|
+
x: minX - SKETCH_GEOMETRY.boxPadPx,
|
|
344
|
+
y: minY - SKETCH_GEOMETRY.bandPx,
|
|
345
|
+
w: maxX - minX + 2 * SKETCH_GEOMETRY.boxPadPx,
|
|
346
|
+
h: maxY - minY + SKETCH_GEOMETRY.bandPx + SKETCH_GEOMETRY.boxPadPx,
|
|
347
|
+
bandH: SKETCH_GEOMETRY.bandPx
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
{
|
|
352
|
+
const centerOf = (id) => {
|
|
353
|
+
const n = nodes.find((nd) => nd.id === id);
|
|
354
|
+
if (n) return { x: n.x + n.w / 2, y: n.y + n.h / 2 };
|
|
355
|
+
const b = boxes.find((bx) => bx.id === id);
|
|
356
|
+
if (b) return { x: b.x + b.w / 2, y: b.y + b.h / 2 };
|
|
357
|
+
return null;
|
|
358
|
+
};
|
|
359
|
+
const segHitsRect = (ax, ay, bx, by, rx0, ry0, rx1, ry1) => {
|
|
360
|
+
let t0 = 0;
|
|
361
|
+
let t1 = 1;
|
|
362
|
+
const p = [-(bx - ax), bx - ax, -(by - ay), by - ay];
|
|
363
|
+
const q = [ax - rx0, rx1 - ax, ay - ry0, ry1 - ay];
|
|
364
|
+
for (let i = 0; i < 4; i++) {
|
|
365
|
+
if (p[i] === 0) {
|
|
366
|
+
if (q[i] < 0) return false;
|
|
367
|
+
} else {
|
|
368
|
+
const t = q[i] / p[i];
|
|
369
|
+
if (p[i] < 0) {
|
|
370
|
+
if (t > t1) return false;
|
|
371
|
+
if (t > t0) t0 = t;
|
|
372
|
+
} else {
|
|
373
|
+
if (t < t0) return false;
|
|
374
|
+
if (t < t1) t1 = t;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return t0 <= t1;
|
|
379
|
+
};
|
|
380
|
+
const warned = /* @__PURE__ */ new Set();
|
|
381
|
+
for (let pass = 0; pass < 4; pass++) {
|
|
382
|
+
let moved = false;
|
|
383
|
+
for (const n of nodes) {
|
|
384
|
+
if (n.boxLabel) continue;
|
|
385
|
+
for (const e of collapsed.edges) {
|
|
386
|
+
if (e.sourceId === n.id || e.targetId === n.id) continue;
|
|
387
|
+
const a = centerOf(e.sourceId);
|
|
388
|
+
const b = centerOf(e.targetId);
|
|
389
|
+
if (!a || !b) continue;
|
|
390
|
+
if (!segHitsRect(a.x, a.y, b.x, b.y, n.x, n.y, n.x + n.w, n.y + n.h))
|
|
391
|
+
continue;
|
|
392
|
+
const ncx = n.x + n.w / 2;
|
|
393
|
+
const ncy = n.y + n.h / 2;
|
|
394
|
+
const m = n;
|
|
395
|
+
if (Math.abs(b.x - a.x) >= Math.abs(b.y - a.y)) {
|
|
396
|
+
const lineY = a.y + (b.y - a.y) * (ncx - a.x) / (b.x - a.x || 1);
|
|
397
|
+
let dir = ncy >= lineY ? 1 : -1;
|
|
398
|
+
if (n.slot.r + dir * SKETCH_SEP < 0) dir = 1;
|
|
399
|
+
m.y += dir * SKETCH_SLOT_Y;
|
|
400
|
+
m.slot = { c: n.slot.c, r: n.slot.r + dir * SKETCH_SEP };
|
|
401
|
+
} else {
|
|
402
|
+
const lineX = a.x + (b.x - a.x) * (ncy - a.y) / (b.y - a.y || 1);
|
|
403
|
+
let dir = ncx >= lineX ? 1 : -1;
|
|
404
|
+
if (n.slot.c + dir * SKETCH_SEP < 0) dir = 1;
|
|
405
|
+
m.x += dir * SKETCH_SLOT_X;
|
|
406
|
+
m.slot = { c: n.slot.c + dir * SKETCH_SEP, r: n.slot.r };
|
|
407
|
+
}
|
|
408
|
+
if (!warned.has(n.id)) {
|
|
409
|
+
overlapWarn(n.lineNumber, n.label);
|
|
410
|
+
warned.add(n.id);
|
|
411
|
+
}
|
|
412
|
+
moved = true;
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (!moved) break;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
let width = 0;
|
|
420
|
+
let height = 0;
|
|
421
|
+
for (const n of nodes) {
|
|
422
|
+
width = Math.max(width, n.x + n.w);
|
|
423
|
+
height = Math.max(height, n.y + n.h);
|
|
424
|
+
}
|
|
425
|
+
for (const b of boxes) {
|
|
426
|
+
width = Math.max(width, b.x + b.w);
|
|
427
|
+
height = Math.max(height, b.y + b.h);
|
|
428
|
+
}
|
|
429
|
+
return {
|
|
430
|
+
nodes,
|
|
431
|
+
boxes,
|
|
432
|
+
edges: collapsed.edges,
|
|
433
|
+
width,
|
|
434
|
+
height,
|
|
435
|
+
diagnostics
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export {
|
|
440
|
+
SKETCH_GEOMETRY,
|
|
441
|
+
SKETCH_FOOT_W,
|
|
442
|
+
SKETCH_FOOT_H,
|
|
443
|
+
SKETCH_HALF_SLOT_X,
|
|
444
|
+
SKETCH_HALF_SLOT_Y,
|
|
445
|
+
SKETCH_SEP,
|
|
446
|
+
SKETCH_SLOT_X,
|
|
447
|
+
SKETCH_SLOT_Y,
|
|
448
|
+
sketchSlotToPx,
|
|
449
|
+
collapseSketch,
|
|
450
|
+
layoutSketch
|
|
451
|
+
};
|
|
452
|
+
//# sourceMappingURL=chunk-Z6XJQ6KO.js.map
|