@knowvah/dot-engine 2.12.3 → 2.13.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.
Files changed (92) hide show
  1. package/dist/api.js +13 -2
  2. package/dist/api.js.map +2 -2
  3. package/dist/common/clust-map.d.ts +16 -0
  4. package/dist/common/clust-map.d.ts.map +1 -0
  5. package/dist/common/htmltable-emit.d.ts +9 -6
  6. package/dist/common/htmltable-emit.d.ts.map +1 -1
  7. package/dist/common/layers.d.ts +9 -0
  8. package/dist/common/layers.d.ts.map +1 -1
  9. package/dist/common/poly-gencode.d.ts.map +1 -1
  10. package/dist/common/xlabels-place.d.ts.map +1 -1
  11. package/dist/errors.d.ts +11 -3
  12. package/dist/errors.d.ts.map +1 -1
  13. package/dist/gvc/anchor.d.ts +17 -19
  14. package/dist/gvc/anchor.d.ts.map +1 -1
  15. package/dist/gvc/context.d.ts +7 -0
  16. package/dist/gvc/context.d.ts.map +1 -1
  17. package/dist/gvc/device-cluster.d.ts +9 -0
  18. package/dist/gvc/device-cluster.d.ts.map +1 -1
  19. package/dist/gvc/device.d.ts +2 -1
  20. package/dist/gvc/device.d.ts.map +1 -1
  21. package/dist/gvc/emit-walk.d.ts +7 -0
  22. package/dist/gvc/emit-walk.d.ts.map +1 -1
  23. package/dist/gvc/job.d.ts +13 -6
  24. package/dist/gvc/job.d.ts.map +1 -1
  25. package/dist/gvc/viewport.d.ts +14 -0
  26. package/dist/gvc/viewport.d.ts.map +1 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +631 -498
  29. package/dist/index.js.map +4 -4
  30. package/dist/layout/dot/classify.d.ts.map +1 -1
  31. package/dist/layout/dot/compound.d.ts +0 -4
  32. package/dist/layout/dot/compound.d.ts.map +1 -1
  33. package/dist/layout/dot/ns-range.d.ts.map +1 -1
  34. package/dist/layout/fdp/cluster-edges.d.ts.map +1 -1
  35. package/dist/model/cgraph-ops.d.ts +7 -0
  36. package/dist/model/cgraph-ops.d.ts.map +1 -1
  37. package/dist/model/graph.d.ts +12 -2
  38. package/dist/model/graph.d.ts.map +1 -1
  39. package/dist/parser/builder.d.ts +11 -10
  40. package/dist/parser/builder.d.ts.map +1 -1
  41. package/dist/parser/graph-attr-syms.d.ts +35 -0
  42. package/dist/parser/graph-attr-syms.d.ts.map +1 -0
  43. package/dist/render/dot/agwrite.d.ts +6 -7
  44. package/dist/render/dot/agwrite.d.ts.map +1 -1
  45. package/dist/render/dot/attrs.d.ts +5 -0
  46. package/dist/render/dot/attrs.d.ts.map +1 -1
  47. package/dist/render/json-cluster-edge.d.ts +3 -2
  48. package/dist/render/json-cluster-edge.d.ts.map +1 -1
  49. package/dist/render/json.d.ts +7 -1
  50. package/dist/render/json.d.ts.map +1 -1
  51. package/dist/render/map.d.ts +14 -10
  52. package/dist/render/map.d.ts.map +1 -1
  53. package/dist/render/svg-graph.d.ts.map +1 -1
  54. package/dist/render/svg-id.d.ts +9 -0
  55. package/dist/render/svg-id.d.ts.map +1 -1
  56. package/dist/render.js +713 -581
  57. package/dist/render.js.map +4 -4
  58. package/dist/util/printf-round.d.ts +8 -0
  59. package/dist/util/printf-round.d.ts.map +1 -1
  60. package/package.json +1 -1
  61. package/src/common/clust-map.ts +58 -0
  62. package/src/common/htmltable-emit.ts +87 -7
  63. package/src/common/layers.ts +25 -4
  64. package/src/common/poly-gencode.ts +3 -11
  65. package/src/common/xlabels-place.ts +22 -4
  66. package/src/errors.ts +13 -3
  67. package/src/gvc/anchor.ts +18 -30
  68. package/src/gvc/context.ts +21 -6
  69. package/src/gvc/device-cluster.ts +16 -0
  70. package/src/gvc/device.ts +20 -20
  71. package/src/gvc/emit-walk.ts +11 -1
  72. package/src/gvc/job.ts +17 -9
  73. package/src/gvc/viewport.ts +27 -6
  74. package/src/index.ts +1 -0
  75. package/src/layout/dot/classify.ts +23 -1
  76. package/src/layout/dot/compound.ts +1 -21
  77. package/src/layout/dot/ns-range.ts +41 -5
  78. package/src/layout/fdp/cluster-edges.ts +2 -23
  79. package/src/model/cgraph-ops.ts +12 -0
  80. package/src/model/graph.ts +13 -2
  81. package/src/parser/builder.ts +67 -100
  82. package/src/parser/graph-attr-syms.ts +62 -0
  83. package/src/render/dot/agwrite.ts +12 -12
  84. package/src/render/dot/attrs.ts +6 -2
  85. package/src/render/json-cluster-edge.ts +8 -4
  86. package/src/render/json.ts +15 -8
  87. package/src/render/map.ts +49 -58
  88. package/src/render/svg-cluster.ts +3 -3
  89. package/src/render/svg-graph.ts +1 -3
  90. package/src/render/svg-helpers.ts +6 -6
  91. package/src/render/svg-id.ts +23 -5
  92. package/src/util/printf-round.ts +11 -0
package/dist/render.js CHANGED
@@ -7,6 +7,92 @@ function resetRenderState() {
7
7
  for (const reset2 of resets) reset2();
8
8
  }
9
9
 
10
+ // src/common/agerr.ts
11
+ var PREFIX_ERROR = "Error";
12
+ var PREFIX_WARNING = "Warning";
13
+ var PREFIX_SEP = ": ";
14
+ var DEL = 127;
15
+ var LAST_CNTRL = 31;
16
+ var WHITESPACE = /* @__PURE__ */ new Set([9, 10, 11, 12, 13]);
17
+ var OCTAL_WIDTH = 3;
18
+ var OCTAL_RADIX = 8;
19
+ var lastLevel = "warning";
20
+ var pending = { line: null, channel: "warn" };
21
+ var usererrf = null;
22
+ registerRenderState(() => {
23
+ flushPending();
24
+ lastLevel = "warning";
25
+ });
26
+ function escapeControl(message) {
27
+ let out = "";
28
+ for (const ch of message) {
29
+ const c = ch.codePointAt(0);
30
+ if ((c <= LAST_CNTRL || c === DEL) && !WHITESPACE.has(c)) {
31
+ out += `\\${c.toString(OCTAL_RADIX).padStart(OCTAL_WIDTH, "0")}`;
32
+ } else out += ch;
33
+ }
34
+ return out;
35
+ }
36
+ function agerrLineOn(channel, line) {
37
+ flushPending();
38
+ writeLine(channel, line);
39
+ }
40
+ function flushPending() {
41
+ if (pending.line === null) return;
42
+ const { line, channel } = pending;
43
+ pending.line = null;
44
+ writeLine(channel, line);
45
+ }
46
+ function writeLine(channel, line) {
47
+ if (usererrf !== null) usererrf(`${line}
48
+ `);
49
+ else if (channel === "warn") console.warn(escapeControl(line));
50
+ else console.error(escapeControl(line));
51
+ }
52
+ function assemble(level, msg) {
53
+ if (level === "prev") return msg;
54
+ const prefix = level === "error" ? PREFIX_ERROR : PREFIX_WARNING;
55
+ return `${prefix}${PREFIX_SEP}${msg}`;
56
+ }
57
+ function outToUser(errf, level, msg) {
58
+ if (level !== "prev") {
59
+ errf(level === "error" ? PREFIX_ERROR : PREFIX_WARNING);
60
+ errf(PREFIX_SEP);
61
+ }
62
+ errf(msg);
63
+ }
64
+ function channelOf(level) {
65
+ const eff = level === "prev" ? lastLevel : level;
66
+ return eff === "warning" ? "warn" : "error";
67
+ }
68
+ function emit(level, msg, channel, hold) {
69
+ const target = channel ?? channelOf(level);
70
+ if (level !== "prev") lastLevel = level;
71
+ if (usererrf !== null) {
72
+ flushPending();
73
+ outToUser(usererrf, level, hold ? msg : `${msg}
74
+ `);
75
+ return;
76
+ }
77
+ const text = assemble(level, msg);
78
+ if (pending.line === null) {
79
+ pending.channel = target;
80
+ pending.line = text;
81
+ } else pending.line += text;
82
+ if (!hold) flushPending();
83
+ }
84
+ function agerr(level, msg, channel) {
85
+ emit(level, msg, channel, false);
86
+ }
87
+ function agerrPartial(level, msg, channel) {
88
+ emit(level, msg, channel, true);
89
+ }
90
+ var agerrorf = (msg, channel) => agerr("error", msg, channel);
91
+ var agwarningf = (msg, channel) => agerr("warning", msg, channel);
92
+ function agerrFinished(line, channel) {
93
+ agerrLineOn(channel ?? (line.startsWith(PREFIX_WARNING) ? "warn" : "error"), line);
94
+ }
95
+
10
96
  // src/errors.ts
11
97
  var FRIENDLY_MESSAGES = {
12
98
  SYNTAX_ERROR: "There is a syntax error in the DOT source.",
@@ -30,6 +116,7 @@ var SEMANTIC_RENDER_CODES = /* @__PURE__ */ new Set([
30
116
  var DotEngineError = class extends Error {
31
117
  constructor(message, options) {
32
118
  super(message, options);
119
+ if (options?.context !== void 0) this.context = options.context;
33
120
  }
34
121
  };
35
122
  var InternalError = class extends DotEngineError {
@@ -367,8 +454,8 @@ var Graph = class {
367
454
  graphDefaultsSnapshot;
368
455
  /**
369
456
  * Keys in `attrs` the BUILDER seeded from `graphDefaultsSnapshot` rather than
370
- * the input declaring them in this scope (see builder.ts GRAPH_LABEL_INHERIT_
371
- * KEYS). cgraph distinguishes these structurally — a seeded value is inherited
457
+ * the input declaring them in this scope: every key of the snapshot the
458
+ * scope did not set (agmakeattrs). cgraph distinguishes these structurally — a seeded value is inherited
372
459
  * through the dict view and has no local symbol, while a local declaration
373
460
  * creates one even when its value equals the inherited value — so the
374
461
  * serializer needs the provenance to decide what write_dict would print.
@@ -376,6 +463,16 @@ var Graph = class {
376
463
  * @see lib/cgraph/write.c:262 write_dict
377
464
  */
378
465
  seededAttrs;
466
+ /**
467
+ * Graph-attribute keys this subgraph holds a local symbol for without having
468
+ * declared them: `unviewsubgraphsattr` gives each direct subgraph one, with
469
+ * its current value, when the parent updates its own symbol. The value is
470
+ * the `attrs` entry (absent for the empty default). A subgraph opened in
471
+ * this one later copies that value, not a nearer ancestor's newer one.
472
+ * Undefined on the root and on a subgraph that was never pinned.
473
+ * @see lib/cgraph/attr.c:232 unviewsubgraphsattr
474
+ */
475
+ pinnedAttrs;
379
476
  /**
380
477
  * Graph-attribute keys whose declaration in THIS scope was the first anywhere
381
478
  * in the graph. cgraph's `setattr` splits on exactly this: a key with no
@@ -679,22 +776,35 @@ function agGraphAttr(g, name) {
679
776
  if (own !== void 0) return own;
680
777
  return g.root.declaredGraphAttrs.has(name) ? "" : void 0;
681
778
  }
779
+ function localGraphAttrs(g) {
780
+ const local = new Map(g.attrs);
781
+ for (const key of g.seededAttrs ?? []) local.delete(key);
782
+ return local;
783
+ }
682
784
 
683
- // src/layout/fdp/cluster-edges.ts
684
- function fillMap(g, map) {
785
+ // src/common/clust-map.ts
786
+ function fillMap(g, st) {
685
787
  const n = g.info.n_cluster ?? 0;
686
788
  for (let c = 0; c < n; c++) {
687
789
  const cl = g.info.clust[c];
688
790
  const s = cl.name;
689
- if (!map.has(s)) map.set(s, cl);
690
- fillMap(cl, map);
791
+ const anon = s.startsWith(LOCALNAMEPREFIX);
792
+ if (st.map.has(s) || anon && st.anonKeyed) {
793
+ agwarningf(`Two clusters named ${s} - the second will be ignored`);
794
+ } else {
795
+ st.map.set(s, cl);
796
+ if (anon) st.anonKeyed = true;
797
+ }
798
+ fillMap(cl, st);
691
799
  }
692
800
  }
693
801
  function mkClustMap(g) {
694
- const map = /* @__PURE__ */ new Map();
695
- fillMap(g, map);
696
- return map;
802
+ const st = { map: /* @__PURE__ */ new Map(), anonKeyed: false };
803
+ fillMap(g, st);
804
+ return st.map;
697
805
  }
806
+
807
+ // src/layout/fdp/cluster-edges.ts
698
808
  function mapc(cmap, n) {
699
809
  if (n.name.startsWith("cluster")) return cmap.get(n.name) ?? null;
700
810
  return null;
@@ -881,92 +991,6 @@ function bindDotRoot(g) {
881
991
  visit(g);
882
992
  }
883
993
 
884
- // src/common/agerr.ts
885
- var PREFIX_ERROR = "Error";
886
- var PREFIX_WARNING = "Warning";
887
- var PREFIX_SEP = ": ";
888
- var DEL = 127;
889
- var LAST_CNTRL = 31;
890
- var WHITESPACE = /* @__PURE__ */ new Set([9, 10, 11, 12, 13]);
891
- var OCTAL_WIDTH = 3;
892
- var OCTAL_RADIX = 8;
893
- var lastLevel = "warning";
894
- var pending = { line: null, channel: "warn" };
895
- var usererrf = null;
896
- registerRenderState(() => {
897
- flushPending();
898
- lastLevel = "warning";
899
- });
900
- function escapeControl(message) {
901
- let out = "";
902
- for (const ch of message) {
903
- const c = ch.codePointAt(0);
904
- if ((c <= LAST_CNTRL || c === DEL) && !WHITESPACE.has(c)) {
905
- out += `\\${c.toString(OCTAL_RADIX).padStart(OCTAL_WIDTH, "0")}`;
906
- } else out += ch;
907
- }
908
- return out;
909
- }
910
- function agerrLineOn(channel, line) {
911
- flushPending();
912
- writeLine(channel, line);
913
- }
914
- function flushPending() {
915
- if (pending.line === null) return;
916
- const { line, channel } = pending;
917
- pending.line = null;
918
- writeLine(channel, line);
919
- }
920
- function writeLine(channel, line) {
921
- if (usererrf !== null) usererrf(`${line}
922
- `);
923
- else if (channel === "warn") console.warn(escapeControl(line));
924
- else console.error(escapeControl(line));
925
- }
926
- function assemble(level, msg) {
927
- if (level === "prev") return msg;
928
- const prefix = level === "error" ? PREFIX_ERROR : PREFIX_WARNING;
929
- return `${prefix}${PREFIX_SEP}${msg}`;
930
- }
931
- function outToUser(errf, level, msg) {
932
- if (level !== "prev") {
933
- errf(level === "error" ? PREFIX_ERROR : PREFIX_WARNING);
934
- errf(PREFIX_SEP);
935
- }
936
- errf(msg);
937
- }
938
- function channelOf(level) {
939
- const eff = level === "prev" ? lastLevel : level;
940
- return eff === "warning" ? "warn" : "error";
941
- }
942
- function emit(level, msg, channel, hold) {
943
- const target = channel ?? channelOf(level);
944
- if (level !== "prev") lastLevel = level;
945
- if (usererrf !== null) {
946
- flushPending();
947
- outToUser(usererrf, level, hold ? msg : `${msg}
948
- `);
949
- return;
950
- }
951
- const text = assemble(level, msg);
952
- if (pending.line === null) {
953
- pending.channel = target;
954
- pending.line = text;
955
- } else pending.line += text;
956
- if (!hold) flushPending();
957
- }
958
- function agerr(level, msg, channel) {
959
- emit(level, msg, channel, false);
960
- }
961
- function agerrPartial(level, msg, channel) {
962
- emit(level, msg, channel, true);
963
- }
964
- var agerrorf = (msg, channel) => agerr("error", msg, channel);
965
- var agwarningf = (msg, channel) => agerr("warning", msg, channel);
966
- function agerrFinished(line, channel) {
967
- agerrLineOn(channel ?? (line.startsWith(PREFIX_WARNING) ? "warn" : "error"), line);
968
- }
969
-
970
994
  // src/xdot/types.ts
971
995
  var XDOT_PARSE_ERROR = 1;
972
996
 
@@ -1521,6 +1545,9 @@ function printfFixed(v, decimals) {
1521
1545
  const fracPart = s.slice(s.length - decimals);
1522
1546
  return sign2 + intPart + "." + fracPart;
1523
1547
  }
1548
+ function printfFixed0(v) {
1549
+ return Object.is(v, -0) ? "-0" : printfFixed(v, 0);
1550
+ }
1524
1551
  function printfSig(v, sig) {
1525
1552
  if (!Number.isFinite(v)) return printfNonFinite(v);
1526
1553
  if (v === 0) return sig > 1 ? "0." + "0".repeat(sig - 1) : "0";
@@ -1721,12 +1748,7 @@ var GvcContext = class {
1721
1748
  let engine = selected;
1722
1749
  if (attr2 !== void 0 && attr2 !== "") {
1723
1750
  const override2 = this.layouts.get(attr2);
1724
- if (override2 === void 0) {
1725
- throw new RenderError(
1726
- `Layout type: "${attr2}" not recognized`,
1727
- "UNKNOWN_LAYOUT"
1728
- );
1729
- }
1751
+ if (override2 === void 0) throw this.unknownLayout(attr2);
1730
1752
  engine = override2;
1731
1753
  }
1732
1754
  undoRenderedClusterEdges(g);
@@ -1742,6 +1764,21 @@ var GvcContext = class {
1742
1764
  if (g.info) g.info.cleanup = (x) => engine.cleanup(x);
1743
1765
  if (g.info) g.info.laidOut = true;
1744
1766
  }
1767
+ /**
1768
+ * C's `agerrorf("Layout type: \"%s\" not recognized. Use one of:%s\n", ...)`
1769
+ * (`gvplugin_list` writes each type as a leading space + name), then the
1770
+ * structured error. The thrown wording may differ from the agerr text.
1771
+ * @see lib/gvc/gvlayout.c:gvLayoutJobs
1772
+ */
1773
+ unknownLayout(attr2) {
1774
+ const list = [...this.layouts.keys()].sort().map((name) => ` ${name}`).join("");
1775
+ agerrorf(`Layout type: "${attr2}" not recognized. Use one of:${list}`);
1776
+ return new RenderError(
1777
+ `Layout type: "${attr2}" not recognized. Use one of:${list}.`,
1778
+ "UNKNOWN_LAYOUT",
1779
+ { context: { layout: attr2 } }
1780
+ );
1781
+ }
1745
1782
  /**
1746
1783
  * Release engine layout state after rendering. The records themselves stay,
1747
1784
  * for getLayout, until the next layout replaces them (part-9 AD-11, see
@@ -11320,19 +11357,27 @@ var RenderJob = class {
11320
11357
  /** GD_fontnames of the root graph — selects which PostScript-alias fields the
11321
11358
  * SVG emitter uses. @see plugin/core/gvrender_core_svg.c:464 */
11322
11359
  fontnames = FontnameKind.NativeFonts;
11323
- /** Root graph's `id` attribute (GD_drawing(root)->id), '' if unset. Used as
11324
- * the `<gid>_` prefix for non-root object ids. @see lib/common/emit.c:getObjId */
11360
+ /** GD_drawing(root)->id: the root graph's `id`, substituted, '' if unset. Set
11361
+ * by render() for every renderer (drawingIdOf); the `<gid>_` prefix of
11362
+ * non-root object ids. @see lib/common/emit.c:getObjId */
11325
11363
  drawingId = "";
11326
11364
  /**
11327
- * Resolve an object's SVG id like C's getObjId (steps after layerPagePrefix):
11328
- * a non-empty DOT `id` attr wins verbatim; otherwise non-root objects are
11329
- * prefixed with `<drawingId>_` when the root graph has an id.
11330
- * @see lib/common/emit.c:getObjId:209
11365
+ * Resolve an object's id like C's getObjId. The layer half of
11366
+ * layerPagePrefix comes first (`<layer>_` after the first layer), ahead of
11367
+ * every other step. Then a non-empty DOT `id` attr wins verbatim; otherwise
11368
+ * non-root objects are prefixed with `<drawingId>_` when the root graph has
11369
+ * an id. The root's id gets the same prefix in emit_page (NotFirstPage).
11370
+ * The page half (`page<x>,<y>_`) is left out: only ps and quartz page, and
11371
+ * neither prints an id.
11372
+ * @see lib/common/emit.c:getObjId
11373
+ * @see lib/common/emit.c:layerPagePrefix
11374
+ * @see lib/common/emit.c:emit_page
11331
11375
  */
11332
11376
  objId(idAttr, defaultId, isRoot = false) {
11333
- if (idAttr !== void 0 && idAttr.length > 0) return idAttr;
11334
- if (!isRoot && this.drawingId.length > 0) return this.drawingId + "_" + defaultId;
11335
- return defaultId;
11377
+ const pfx = this.idLayerPrefix();
11378
+ if (idAttr !== void 0 && idAttr.length > 0) return pfx + idAttr;
11379
+ if (!isRoot && this.drawingId.length > 0) return pfx + this.drawingId + "_" + defaultId;
11380
+ return pfx + defaultId;
11336
11381
  }
11337
11382
  /** Active renderer plugin; set by render() before walkNodes. */
11338
11383
  renderer;
@@ -12986,7 +13031,7 @@ function emitHtmlCell(cell2, pos, renderer, job) {
12986
13031
  }
12987
13032
  emitCellDecoration(cell2, pos, renderer, job);
12988
13033
  if (cell2.nested !== void 0) {
12989
- emitHtmlLabel(cell2.nested, pos, renderer, job);
13034
+ emitHtmlTbl(cell2.nested, pos, renderer, job);
12990
13035
  } else if (cell2.image !== void 0) {
12991
13036
  emitHtmlImg(cell2.image, pos, renderer, job);
12992
13037
  } else {
@@ -13010,7 +13055,7 @@ function emitTableRules(placed, pos, renderer, job) {
13010
13055
  }
13011
13056
  });
13012
13057
  }
13013
- function emitHtmlLabel(placed, pos, renderer, job) {
13058
+ function emitHtmlTbl(placed, pos, renderer, job) {
13014
13059
  resetHtmlFillPenWidth();
13015
13060
  const anchorData = { href: placed.href, title: placed.title, target: placed.target, id: placed.id };
13016
13061
  const tblBox = absBox(placed.box, pos);
@@ -13041,6 +13086,40 @@ function emitHtmlLabel(placed, pos, renderer, job) {
13041
13086
  endHtmlAnchor(renderer, job);
13042
13087
  }
13043
13088
  }
13089
+ function allocObj(job, parent2) {
13090
+ const obj = createObjState(parent2.type);
13091
+ obj.parent = parent2;
13092
+ obj.penColor = parent2.penColor;
13093
+ obj.fillColor = parent2.fillColor;
13094
+ obj.pen = parent2.pen;
13095
+ obj.fill = parent2.fill;
13096
+ obj.penWidth = parent2.penWidth;
13097
+ obj.gradientAngle = parent2.gradientAngle;
13098
+ obj.stopColor = parent2.stopColor;
13099
+ obj.emitState = parent2.emitState;
13100
+ obj.graphObj = parent2.graphObj;
13101
+ obj.url = parent2.url;
13102
+ obj.tooltip = parent2.tooltip;
13103
+ obj.target = parent2.target;
13104
+ obj.explicitTooltip = parent2.explicitTooltip;
13105
+ job.pushObj(obj);
13106
+ }
13107
+ function freeObj(job) {
13108
+ job.popObj();
13109
+ }
13110
+ function emitHtmlLabel(placed, pos, renderer, job) {
13111
+ const parent2 = job.obj;
13112
+ if (parent2 === null) {
13113
+ emitHtmlTbl(placed, pos, renderer, job);
13114
+ return;
13115
+ }
13116
+ allocObj(job, parent2);
13117
+ try {
13118
+ emitHtmlTbl(placed, pos, renderer, job);
13119
+ } finally {
13120
+ freeObj(job);
13121
+ }
13122
+ }
13044
13123
 
13045
13124
  // src/common/poly-vertices.ts
13046
13125
  function ellipseVertices(w, h) {
@@ -17538,6 +17617,297 @@ function buildPoint(x, y) {
17538
17617
  return pt;
17539
17618
  }
17540
17619
 
17620
+ // src/gvc/anchor.ts
17621
+ function attr(attrs, key) {
17622
+ const v = attrs.get(key);
17623
+ return v !== void 0 && v !== "" ? v : void 0;
17624
+ }
17625
+ function subst(s, obj) {
17626
+ return substObjAnchor(s, obj);
17627
+ }
17628
+ function tip(s, obj) {
17629
+ return substObjAnchor(preprocessTooltip(s), obj);
17630
+ }
17631
+ function textOf(lp) {
17632
+ return lp?.text ?? null;
17633
+ }
17634
+ function pickFirst(attrs, keys, xform) {
17635
+ for (const k of keys) {
17636
+ const s = attr(attrs, k);
17637
+ if (s !== void 0) return { v: xform(s), explicit: true };
17638
+ }
17639
+ return { v: void 0, explicit: false };
17640
+ }
17641
+ function pickEdge(e, keys) {
17642
+ return pickFirst(e.attrs, keys, (s) => subst(s, e));
17643
+ }
17644
+ function pickEdgeTip(e, keys) {
17645
+ return pickFirst(e.attrs, keys, (s) => tip(s, e));
17646
+ }
17647
+ function withFallback(p, dflt, current) {
17648
+ return { v: p.v ?? dflt ?? current, explicit: p.explicit };
17649
+ }
17650
+ function resolveEdgeLabels(e, obj) {
17651
+ obj.label = textOf(e.info.label);
17652
+ obj.xlabel = textOf(e.info.xlabel) ?? obj.label;
17653
+ obj.tailLabel = textOf(e.info.tail_label) ?? obj.label;
17654
+ obj.headLabel = textOf(e.info.head_label) ?? obj.label;
17655
+ }
17656
+ function resolveEdgeUrls(e, obj) {
17657
+ const dflt = pickEdge(e, ["href", "URL"]).v;
17658
+ obj.url = withFallback(pickEdge(e, ["edgehref", "edgeURL"]), dflt, obj.url).v;
17659
+ obj.labelUrl = withFallback(pickEdge(e, ["labelhref", "labelURL"]), dflt, obj.labelUrl).v;
17660
+ const tail = withFallback(pickEdge(e, ["tailhref", "tailURL"]), dflt, obj.tailUrl);
17661
+ obj.tailUrl = tail.v;
17662
+ obj.explicitTailUrl = tail.explicit;
17663
+ const head = withFallback(pickEdge(e, ["headhref", "headURL"]), dflt, obj.headUrl);
17664
+ obj.headUrl = head.v;
17665
+ obj.explicitHeadUrl = head.explicit;
17666
+ }
17667
+ function resolveEdgeTargets(e, obj) {
17668
+ const dflt = pickEdge(e, ["target"]).v;
17669
+ const edge = withFallback(pickEdge(e, ["edgetarget"]), dflt, obj.target);
17670
+ obj.target = edge.v;
17671
+ obj.explicitEdgeTarget = edge.explicit;
17672
+ obj.labelTarget = withFallback(pickEdge(e, ["labeltarget"]), dflt, obj.labelTarget).v;
17673
+ const tail = withFallback(pickEdge(e, ["tailtarget"]), dflt, obj.tailTarget);
17674
+ obj.tailTarget = tail.v;
17675
+ obj.explicitTailTarget = tail.explicit;
17676
+ const head = withFallback(pickEdge(e, ["headtarget"]), dflt, obj.headTarget);
17677
+ obj.headTarget = head.v;
17678
+ obj.explicitHeadTarget = head.explicit;
17679
+ }
17680
+ function resolveEdgeTooltips(e, obj) {
17681
+ const t = withFallback(pickEdgeTip(e, ["tooltip", "edgetooltip"]), obj.label, obj.tooltip);
17682
+ obj.tooltip = t.v;
17683
+ obj.explicitTooltip = t.explicit;
17684
+ const lt = withFallback(pickEdgeTip(e, ["labeltooltip"]), obj.label, obj.labelTooltip);
17685
+ obj.labelTooltip = lt.v;
17686
+ obj.explicitLabelTooltip = lt.explicit;
17687
+ const tt = withFallback(pickEdgeTip(e, ["tailtooltip"]), obj.tailLabel, obj.tailTooltip);
17688
+ obj.tailTooltip = tt.v;
17689
+ obj.explicitTailTooltip = tt.explicit;
17690
+ const ht = withFallback(pickEdgeTip(e, ["headtooltip"]), obj.headLabel, obj.headTooltip);
17691
+ obj.headTooltip = ht.v;
17692
+ obj.explicitHeadTooltip = ht.explicit;
17693
+ }
17694
+ function resolveEdgeAnchor(e, id, obj) {
17695
+ resolveEdgeLabels(e, obj);
17696
+ resolveEdgeUrls(e, obj);
17697
+ resolveEdgeTargets(e, obj);
17698
+ resolveEdgeTooltips(e, obj);
17699
+ obj.id = subst(id, e);
17700
+ }
17701
+ function resolveObjAnchor(g, label, id, obj) {
17702
+ obj.label = label;
17703
+ const ga = (key) => {
17704
+ for (let s = g; s !== null; s = s.parent) {
17705
+ const v = attr(s.attrs, key);
17706
+ if (v !== void 0) return v;
17707
+ }
17708
+ return void 0;
17709
+ };
17710
+ const url = ga("href") ?? ga("URL");
17711
+ if (url !== void 0) obj.url = subst(url, g);
17712
+ const tt = ga("tooltip");
17713
+ if (tt !== void 0) {
17714
+ obj.tooltip = tip(tt, g);
17715
+ obj.explicitTooltip = true;
17716
+ } else if (label !== null) obj.tooltip = label;
17717
+ const tgt = ga("target");
17718
+ if (tgt !== void 0) obj.target = subst(tgt, g);
17719
+ obj.id = subst(id, g);
17720
+ }
17721
+ function openAnchorWith(renderer, job, url, tooltip, target, id) {
17722
+ renderer.beginAnchor?.(url ?? "", tooltip ?? "", target ?? "", id, job);
17723
+ }
17724
+ function beginAnchorIf(renderer, job) {
17725
+ const obj = job.obj;
17726
+ if (obj === null || obj.url === null && !obj.explicitTooltip) return false;
17727
+ openAnchorWith(renderer, job, obj.url, obj.tooltip, obj.target, obj.id ?? "");
17728
+ return true;
17729
+ }
17730
+ var DFLT_SAMPLE = 20;
17731
+ var MAP_HW = 2;
17732
+ function mapTransform(p, ctx) {
17733
+ return applyScale(p, ctx.translation.x, ctx.translation.y, ctx.scale.x, ctx.scale.y);
17734
+ }
17735
+ function nodeIsFilled(n) {
17736
+ return parseStyleFlags(nodeAttr(n, n.root, "style")).filled;
17737
+ }
17738
+ function nodeAttrSet(n, key) {
17739
+ const v = nodeAttr(n, n.root, key);
17740
+ return v !== void 0 && v !== "";
17741
+ }
17742
+ function nodeHasHotspot(n) {
17743
+ return nodeAttrSet(n, "href") || nodeAttrSet(n, "URL") || nodeAttrSet(n, "tooltip");
17744
+ }
17745
+ function isRectPoly(p) {
17746
+ return p.sides === 4 && Math.abs(p.orientation % 90) < 0.5 && p.distortion === 0 && p.skew === 0;
17747
+ }
17748
+ function samplePoints(n) {
17749
+ const s = n.attrs.get("samplepoints");
17750
+ if (s === void 0) return DFLT_SAMPLE;
17751
+ const v = parseInt(s, 10);
17752
+ return Number.isNaN(v) || v < 4 || v > 60 ? DFLT_SAMPLE : v;
17753
+ }
17754
+ function pEllipse(a, b, np) {
17755
+ const del = 2 * Math.PI / np;
17756
+ const ps = [];
17757
+ let theta = 0;
17758
+ for (let i = 0; i < np; i++) {
17759
+ ps.push({ x: a * Math.cos(theta), y: b * Math.sin(theta) });
17760
+ theta += del;
17761
+ }
17762
+ return ps;
17763
+ }
17764
+ function ellipseNodeMap(poly, coord, ur, nump) {
17765
+ if (poly.regular) {
17766
+ return { shape: 1 /* Circle */, pts: [coord, { x: coord.x + ur.x, y: coord.y + ur.y }] };
17767
+ }
17768
+ const pts = pEllipse(ur.x, ur.y, nump).map((p) => ({ x: p.x + coord.x, y: p.y + coord.y }));
17769
+ return { shape: 2 /* Polygon */, pts };
17770
+ }
17771
+ function generalNodeMap(poly, coord, vertices, peripheries, nump) {
17772
+ const offset = (peripheries - 1) * poly.sides;
17773
+ const pts = [];
17774
+ if (poly.sides >= nump) {
17775
+ const delta2 = Math.trunc(poly.sides / nump);
17776
+ for (let i = 0, j = 0; j < nump; i += delta2, j++) {
17777
+ const v = vertices[i + offset];
17778
+ pts.push({ x: coord.x + v.x, y: coord.y + v.y });
17779
+ }
17780
+ } else {
17781
+ for (let i = 0; i < poly.sides; i++) {
17782
+ const v = vertices[i + offset];
17783
+ pts.push({ x: coord.x + v.x, y: coord.y + v.y });
17784
+ }
17785
+ }
17786
+ return { shape: 2 /* Polygon */, pts };
17787
+ }
17788
+ function nodePolyMap(n, poly, coord, filled) {
17789
+ const peripheries = poly.peripheries < 2 ? 1 : poly.peripheries;
17790
+ const vertices = poly.vertices;
17791
+ const nump = samplePoints(n);
17792
+ const info = n.info;
17793
+ if (poly.peripheries === 0 && !filled) {
17794
+ return { shape: 0 /* Rectangle */, pts: [
17795
+ { x: coord.x - info.lw, y: coord.y - info.ht / 2 },
17796
+ { x: coord.x + info.lw, y: coord.y + info.ht / 2 }
17797
+ ] };
17798
+ }
17799
+ if (poly.sides < 3 && poly.skew === 0 && poly.distortion === 0) {
17800
+ return ellipseNodeMap(poly, coord, vertices[2 * peripheries - 1], nump);
17801
+ }
17802
+ return generalNodeMap(poly, coord, vertices, peripheries, nump);
17803
+ }
17804
+ function computeNodeUrlMap(n, obj, ctx) {
17805
+ if (!nodeHasHotspot(n)) return;
17806
+ const info = n.info;
17807
+ const coord = info.coord;
17808
+ const poly = info.shape_info;
17809
+ const filled = nodeIsFilled(n);
17810
+ const isRect = poly !== void 0 && isRectPoly(poly) && (poly.peripheries !== 0 || filled);
17811
+ let m;
17812
+ if (poly !== void 0 && poly.vertices != null && !isRect && ctx.mapPolygon) {
17813
+ m = nodePolyMap(n, poly, coord, filled);
17814
+ } else {
17815
+ m = { shape: 0 /* Rectangle */, pts: [
17816
+ { x: coord.x - info.lw, y: coord.y - info.ht / 2 },
17817
+ { x: coord.x + info.rw, y: coord.y + info.ht / 2 }
17818
+ ] };
17819
+ }
17820
+ obj.urlMapShape = m.shape;
17821
+ obj.urlMapPts = m.pts.map((p) => mapTransform(p, ctx));
17822
+ }
17823
+ function computeGraphUrlMap(obj, ctx) {
17824
+ const { ll, ur } = ctx.pageBox;
17825
+ obj.urlMapShape = 0 /* Rectangle */;
17826
+ obj.urlMapPts = [mapTransform(ll, ctx), mapTransform(ur, ctx)];
17827
+ }
17828
+ function computeClusterUrlMap(bb, obj, ctx) {
17829
+ obj.urlMapShape = 0 /* Rectangle */;
17830
+ obj.urlMapPts = [mapTransform(bb.ll, ctx), mapTransform(bb.ur, ctx)];
17831
+ }
17832
+ function computeLabelRectMap(lab, obj, ctx) {
17833
+ const dx = lab.dimen.x / 2;
17834
+ const dy = lab.dimen.y / 2;
17835
+ obj.urlMapShape = 0 /* Rectangle */;
17836
+ obj.urlMapPts = [
17837
+ mapTransform({ x: lab.pos.x - dx, y: lab.pos.y - dy }, ctx),
17838
+ mapTransform({ x: lab.pos.x + dx, y: lab.pos.y + dy }, ctx)
17839
+ ];
17840
+ }
17841
+ function checkControlPoints2(cp) {
17842
+ return ptToLine2(cp[0], cp[3], cp[1]) < MAP_HW * MAP_HW && ptToLine2(cp[0], cp[3], cp[2]) < MAP_HW * MAP_HW;
17843
+ }
17844
+ function bezierHalf(v) {
17845
+ const left2 = [];
17846
+ const right2 = [];
17847
+ bezier(v, 0.5, left2, right2);
17848
+ return { left: left2, right: right2 };
17849
+ }
17850
+ function approxBezier(cp, out) {
17851
+ if (checkControlPoints2(cp)) {
17852
+ if (out.length === 0) out.push(cp[0]);
17853
+ out.push(cp[3]);
17854
+ } else {
17855
+ const { left: left2, right: right2 } = bezierHalf(cp);
17856
+ approxBezier(left2, out);
17857
+ approxBezier(right2, out);
17858
+ }
17859
+ }
17860
+ function mkSegPts(prv, cur, nxt, w2) {
17861
+ let pp;
17862
+ let np;
17863
+ if (prv) {
17864
+ pp = prv;
17865
+ np = nxt ?? { x: 2 * (cur.x - pp.x), y: 2 * (cur.y - pp.y) };
17866
+ } else {
17867
+ np = nxt;
17868
+ pp = { x: 2 * (cur.x - np.x), y: 2 * (cur.y - np.y) };
17869
+ }
17870
+ const theta = Math.atan2(np.y - cur.y, np.x - cur.x);
17871
+ const phi = Math.atan2(pp.y - cur.y, pp.x - cur.x);
17872
+ let ang = theta - phi;
17873
+ if (ang > 0) ang -= 2 * Math.PI;
17874
+ const bis = phi + ang / 2;
17875
+ const del = { x: w2 * Math.cos(bis), y: w2 * Math.sin(bis) };
17876
+ return { p1: { x: cur.x + del.x, y: cur.y + del.y }, p2: { x: cur.x - del.x, y: cur.y - del.y } };
17877
+ }
17878
+ function mapOutputBspline(bp, w2, polys) {
17879
+ const nc = Math.trunc((bp.size - 1) / 3);
17880
+ const segs = [];
17881
+ for (let j = 0; j < nc; j++) {
17882
+ approxBezier([bp.list[3 * j], bp.list[3 * j + 1], bp.list[3 * j + 2], bp.list[3 * j + 3]], segs);
17883
+ }
17884
+ const pt1 = [];
17885
+ const pt2 = [];
17886
+ let cnt = 0;
17887
+ for (let i = 0; i < segs.length; i++) {
17888
+ const prev = i === 0 ? null : segs[i - 1];
17889
+ const next = i + 1 < segs.length ? segs[i + 1] : null;
17890
+ const seg2 = mkSegPts(prev, segs[i], next, w2);
17891
+ pt1[cnt] = seg2.p1;
17892
+ pt2[cnt] = seg2.p2;
17893
+ cnt++;
17894
+ if (i + 1 === segs.length || cnt === 50) {
17895
+ const poly = [];
17896
+ for (let k = 0; k < cnt; k++) poly.push(pt1[k]);
17897
+ for (let k = 0; k < cnt; k++) poly.push(pt2[cnt - 1 - k]);
17898
+ polys.push(poly);
17899
+ pt1[0] = pt1[cnt - 1];
17900
+ pt2[0] = pt2[cnt - 1];
17901
+ cnt = 1;
17902
+ }
17903
+ }
17904
+ }
17905
+ function computeEdgeSplineMaps(spl, w2, ctx) {
17906
+ const polys = [];
17907
+ for (const bz of spl.list) mapOutputBspline(bz, w2, polys);
17908
+ return polys.map((poly) => poly.map((p) => mapTransform(p, ctx)));
17909
+ }
17910
+
17541
17911
  // src/gvc/device-cluster.ts
17542
17912
  function applyClusterGradient(obj, fill) {
17543
17913
  obj.fill = fill.kind === "radial" ? 3 /* Radial */ : 2 /* Linear */;
@@ -17639,8 +18009,18 @@ function applyClusterFill(obj, fillRes) {
17639
18009
  applyClusterGradient(obj, fillRes);
17640
18010
  return true;
17641
18011
  }
18012
+ function beginClusterAnchor(sg, renderer, job) {
18013
+ const obj = job.obj;
18014
+ if (obj === null || obj.url === null && !obj.explicitTooltip) return false;
18015
+ renderer.emitMapRect?.(sg.info.bb, job);
18016
+ return beginAnchorIf(renderer, job);
18017
+ }
17642
18018
 
17643
18019
  // src/render/svg-id.ts
18020
+ function drawingIdOf(g) {
18021
+ const id = g.attrs.get("id");
18022
+ return id !== void 0 && id.length > 0 ? substObjAnchor(id, g) : "";
18023
+ }
17644
18024
  function svgClass(kind, classAttr) {
17645
18025
  return classAttr !== void 0 && classAttr.length > 0 ? 'class="' + kind + " " + escapeXmlTitle(classAttr) + '"' : 'class="' + kind + '"';
17646
18026
  }
@@ -17918,19 +18298,11 @@ function polyGencode(rawJob, rawNode) {
17918
18298
  const ctx = resolveNodeDrawCtx(job, n);
17919
18299
  if (ctx === null) return;
17920
18300
  const clustersLast = (job.flags & EMIT_CLUSTERS_LAST) !== 0;
17921
- const savedShape = job.obj?.urlMapShape;
17922
- const savedPts = job.obj?.urlMapPts;
17923
18301
  let inAnchor = clustersLast ? false : beginNodeAnchor(n, renderer, job);
17924
18302
  renderPeripheries(ctx.poly, ctx.coord, ctx.filled, ctx.ringCtx);
17925
18303
  if (!isPointNode(n)) renderUsershape(n, ctx);
17926
18304
  if (!isPointNode(n)) renderNodeLabel(n, ctx.coord, renderer, job);
17927
- if (clustersLast) {
17928
- if (job.obj && savedPts !== void 0 && savedShape !== void 0) {
17929
- job.obj.urlMapShape = savedShape;
17930
- job.obj.urlMapPts = savedPts;
17931
- }
17932
- inAnchor = beginNodeAnchor(n, renderer, job);
17933
- }
18305
+ if (clustersLast) inAnchor = beginNodeAnchor(n, renderer, job);
17934
18306
  if (inAnchor) renderer.endAnchor?.(job);
17935
18307
  }
17936
18308
 
@@ -19382,6 +19754,7 @@ function nonconstraintEdge(e) {
19382
19754
  var WNODE_ORDINARY = 0;
19383
19755
  var WNODE_SINGLETON = 1;
19384
19756
  var WNODE_VIRTUAL = 2;
19757
+ var INT_MAX2 = 2147483647;
19385
19758
  var CLASSIFY_WEIGHT_TABLE = [[1, 1, 1], [1, 2, 2], [1, 2, 4]];
19386
19759
  function epClass(n) {
19387
19760
  if (n.info.node_type === VIRTUAL) return WNODE_VIRTUAL;
@@ -19390,7 +19763,19 @@ function epClass(n) {
19390
19763
  }
19391
19764
  function applyVirtualWeight(e) {
19392
19765
  const t = CLASSIFY_WEIGHT_TABLE[epClass(e.tail)][epClass(e.head)];
19393
- e.info.weight = (e.info.weight ?? 1) * t;
19766
+ const w = e.info.weight ?? 1;
19767
+ if (Math.trunc(INT_MAX2 / t) < w) throw virtualWeightOverflow(e, t);
19768
+ e.info.weight = w * t;
19769
+ }
19770
+ function virtualWeightOverflow(e, t) {
19771
+ agerrorf("overflow when calculating virtual weight of edge");
19772
+ const o = e.info.to_orig ?? e;
19773
+ const name = `${o.tail.name}->${o.head.name}`;
19774
+ return new RenderError(
19775
+ `Edge "${name}" has a weight too large for the layout (weight x ${t} exceeds the 32-bit integer limit); lower its weight attribute.`,
19776
+ "RENDER_ERROR",
19777
+ { context: { edge: name } }
19778
+ );
19394
19779
  }
19395
19780
  function interclust1TRank(e) {
19396
19781
  const clust = e.tail.info.clust;
@@ -21407,7 +21792,6 @@ function svgBeginGraph(g, job) {
21407
21792
  job.devscale = { x: 1, y: -1 };
21408
21793
  job.directed = g.kind === "directed" || g.kind === "strict-directed";
21409
21794
  job.fontnames = g.info.fontnames ?? FontnameKind.NativeFonts;
21410
- job.drawingId = g.attrs.get("id") ?? "";
21411
21795
  job.write(SVG_XML_DECL);
21412
21796
  const stylesheet = g.attrs.get("stylesheet");
21413
21797
  if (stylesheet !== void 0 && stylesheet.length > 0) {
@@ -21433,7 +21817,7 @@ function svgBeginPage(g, job) {
21433
21817
  const tx = job.rotation !== 0 ? -clip.ur.x - job.margin.x / z : -clip.ll.x + job.margin.x / z;
21434
21818
  const ty = clip.ur.y + job.margin.y / z;
21435
21819
  emitGraphGroupOpen(
21436
- job.idLayerPrefix() + svgGraphId(g, job),
21820
+ svgGraphId(g, job),
21437
21821
  svgGraphClass(g),
21438
21822
  tx,
21439
21823
  ty,
@@ -21639,7 +22023,7 @@ function textAnchor(just) {
21639
22023
  return "middle";
21640
22024
  }
21641
22025
  function svgBeginNode(n, job) {
21642
- job.write('<g id="' + escapeXmlTitle(job.idLayerPrefix() + svgNodeId(n, job) + job.idLayerSuffix()) + '" ' + svgNodeClass(n) + ">\n");
22026
+ job.write('<g id="' + escapeXmlTitle(svgNodeId(n, job) + job.idLayerSuffix()) + '" ' + svgNodeClass(n) + ">\n");
21643
22027
  job.write("<title>" + escapeXmlTitle(n.name) + "</title>\n");
21644
22028
  }
21645
22029
  function svgEndNode(job) {
@@ -21653,7 +22037,7 @@ function svgBeginEdge(e, job) {
21653
22037
  const tp = e.info.tail_port?.name;
21654
22038
  const hp = e.info.head_port?.name;
21655
22039
  const raw = e.tail.name + (tp ? ":" + tp : "") + sep + e.head.name + (hp ? ":" + hp : "");
21656
- job.write('<g id="' + escapeXmlTitle(job.idLayerPrefix() + svgEdgeId(e, job)) + '" ' + svgEdgeClass(e) + ">\n");
22040
+ job.write('<g id="' + escapeXmlTitle(svgEdgeId(e, job)) + '" ' + svgEdgeClass(e) + ">\n");
21657
22041
  job.write("<title>" + escapeEdgeTitle(raw) + "</title>\n");
21658
22042
  }
21659
22043
  function svgEndEdge(job) {
@@ -21934,318 +22318,27 @@ function initJobViewportZoom(bb, size, pad) {
21934
22318
  return 1;
21935
22319
  }
21936
22320
  function setupPageClip(bb, size, pad, z) {
21937
- const jbLL = { x: bb.ll.x - pad.x, y: bb.ll.y - pad.y };
21938
- const jbUR = { x: bb.ur.x + pad.x, y: bb.ur.y + pad.y };
21939
- const sz = { x: jbUR.x - jbLL.x, y: jbUR.y - jbLL.y };
21940
- if (size !== null && size.x > 1e-3 && size.y > 1e-3) {
21941
- if (sz.x <= 1e-3) sz.x = size.x;
21942
- if (sz.y <= 1e-3) sz.y = size.y;
21943
- }
21944
22321
  const focus = { x: 0.5 * (bb.ll.x + bb.ur.x), y: 0.5 * (bb.ll.y + bb.ur.y) };
21945
- const pageSize = { x: z * sz.x / z, y: z * sz.y / z };
22322
+ const pageSize = setupPageSize(bb, size, pad, z);
21946
22323
  const ll = {
21947
22324
  x: focus.x + pageSize.x * (0 - 1 / 2),
21948
22325
  y: focus.y + pageSize.y * (0 - 1 / 2)
21949
22326
  };
21950
22327
  return { ll, ur: { x: ll.x + pageSize.x, y: ll.y + pageSize.y } };
21951
22328
  }
21952
-
21953
- // src/gvc/anchor.ts
21954
- function attr(attrs, key) {
21955
- const v = attrs.get(key);
21956
- return v !== void 0 && v !== "" ? v : void 0;
21957
- }
21958
- function subst(s, obj) {
21959
- return substObjAnchor(s, obj);
21960
- }
21961
- function tip(s, obj) {
21962
- return substObjAnchor(preprocessTooltip(s), obj);
21963
- }
21964
- function textOf(lp) {
21965
- return lp?.text ?? null;
21966
- }
21967
- function pickFirst(attrs, keys, xform) {
21968
- for (const k of keys) {
21969
- const s = attr(attrs, k);
21970
- if (s !== void 0) return { v: xform(s), explicit: true };
21971
- }
21972
- return { v: void 0, explicit: false };
21973
- }
21974
- function pickEdge(e, keys) {
21975
- return pickFirst(e.attrs, keys, (s) => subst(s, e));
21976
- }
21977
- function pickEdgeTip(e, keys) {
21978
- return pickFirst(e.attrs, keys, (s) => tip(s, e));
21979
- }
21980
- function withFallback(p, dflt, current) {
21981
- return { v: p.v ?? dflt ?? current, explicit: p.explicit };
21982
- }
21983
- function resolveEdgeLabels(e, obj) {
21984
- obj.label = textOf(e.info.label);
21985
- obj.xlabel = textOf(e.info.xlabel) ?? obj.label;
21986
- obj.tailLabel = textOf(e.info.tail_label) ?? obj.label;
21987
- obj.headLabel = textOf(e.info.head_label) ?? obj.label;
21988
- }
21989
- function resolveEdgeUrls(e, obj) {
21990
- const dflt = pickEdge(e, ["href", "URL"]).v;
21991
- obj.url = withFallback(pickEdge(e, ["edgehref", "edgeURL"]), dflt, obj.url).v;
21992
- obj.labelUrl = withFallback(pickEdge(e, ["labelhref", "labelURL"]), dflt, obj.labelUrl).v;
21993
- const tail = withFallback(pickEdge(e, ["tailhref", "tailURL"]), dflt, obj.tailUrl);
21994
- obj.tailUrl = tail.v;
21995
- obj.explicitTailUrl = tail.explicit;
21996
- const head = withFallback(pickEdge(e, ["headhref", "headURL"]), dflt, obj.headUrl);
21997
- obj.headUrl = head.v;
21998
- obj.explicitHeadUrl = head.explicit;
21999
- }
22000
- function resolveEdgeTargets(e, obj) {
22001
- const dflt = pickEdge(e, ["target"]).v;
22002
- const edge = withFallback(pickEdge(e, ["edgetarget"]), dflt, obj.target);
22003
- obj.target = edge.v;
22004
- obj.explicitEdgeTarget = edge.explicit;
22005
- obj.labelTarget = withFallback(pickEdge(e, ["labeltarget"]), dflt, obj.labelTarget).v;
22006
- const tail = withFallback(pickEdge(e, ["tailtarget"]), dflt, obj.tailTarget);
22007
- obj.tailTarget = tail.v;
22008
- obj.explicitTailTarget = tail.explicit;
22009
- const head = withFallback(pickEdge(e, ["headtarget"]), dflt, obj.headTarget);
22010
- obj.headTarget = head.v;
22011
- obj.explicitHeadTarget = head.explicit;
22012
- }
22013
- function resolveEdgeTooltips(e, obj) {
22014
- const t = withFallback(pickEdgeTip(e, ["tooltip", "edgetooltip"]), obj.label, obj.tooltip);
22015
- obj.tooltip = t.v;
22016
- obj.explicitTooltip = t.explicit;
22017
- const lt = withFallback(pickEdgeTip(e, ["labeltooltip"]), obj.label, obj.labelTooltip);
22018
- obj.labelTooltip = lt.v;
22019
- obj.explicitLabelTooltip = lt.explicit;
22020
- const tt = withFallback(pickEdgeTip(e, ["tailtooltip"]), obj.tailLabel, obj.tailTooltip);
22021
- obj.tailTooltip = tt.v;
22022
- obj.explicitTailTooltip = tt.explicit;
22023
- const ht = withFallback(pickEdgeTip(e, ["headtooltip"]), obj.headLabel, obj.headTooltip);
22024
- obj.headTooltip = ht.v;
22025
- obj.explicitHeadTooltip = ht.explicit;
22026
- }
22027
- function resolveEdgeAnchor(e, id, obj) {
22028
- resolveEdgeLabels(e, obj);
22029
- resolveEdgeUrls(e, obj);
22030
- resolveEdgeTargets(e, obj);
22031
- resolveEdgeTooltips(e, obj);
22032
- obj.id = subst(id, e);
22033
- }
22034
- function resolveObjAnchor(g, label, id, obj) {
22035
- obj.label = label;
22036
- const ga = (key) => {
22037
- for (let s = g; s !== null; s = s.parent) {
22038
- const v = attr(s.attrs, key);
22039
- if (v !== void 0) return v;
22040
- }
22041
- return void 0;
22042
- };
22043
- const url = ga("href") ?? ga("URL");
22044
- if (url !== void 0) obj.url = subst(url, g);
22045
- const tt = ga("tooltip");
22046
- if (tt !== void 0) {
22047
- obj.tooltip = tip(tt, g);
22048
- obj.explicitTooltip = true;
22049
- } else if (label !== null) obj.tooltip = label;
22050
- const tgt = ga("target");
22051
- if (tgt !== void 0) obj.target = subst(tgt, g);
22052
- obj.id = subst(id, g);
22053
- }
22054
- function openAnchorWith(renderer, job, url, tooltip, target, id) {
22055
- renderer.beginAnchor?.(url ?? "", tooltip ?? "", target ?? "", id, job);
22056
- }
22057
- function beginAnchorIf(renderer, job) {
22058
- const obj = job.obj;
22059
- if (obj === null || obj.url === null && !obj.explicitTooltip) return false;
22060
- openAnchorWith(renderer, job, obj.url, obj.tooltip, obj.target, obj.id ?? "");
22061
- return true;
22062
- }
22063
- var DFLT_SAMPLE = 20;
22064
- var MAP_HW = 2;
22065
- function mapTransform(p, ctx) {
22066
- return {
22067
- x: (p.x + ctx.pad.x - ctx.bb.ll.x) * ctx.scale + ctx.marginOff.x,
22068
- y: (ctx.bb.ur.y + ctx.pad.y - p.y) * ctx.scale + ctx.marginOff.y
22069
- };
22070
- }
22071
- function nodeIsFilled(n) {
22072
- return parseStyleFlags(nodeAttr(n, n.root, "style")).filled;
22073
- }
22074
- function nodeAttrSet(n, key) {
22075
- const v = nodeAttr(n, n.root, key);
22076
- return v !== void 0 && v !== "";
22077
- }
22078
- function nodeHasHotspot(n) {
22079
- return nodeAttrSet(n, "href") || nodeAttrSet(n, "URL") || nodeAttrSet(n, "tooltip");
22080
- }
22081
- function isRectPoly(p) {
22082
- return p.sides === 4 && Math.abs(p.orientation % 90) < 0.5 && p.distortion === 0 && p.skew === 0;
22083
- }
22084
- function samplePoints(n) {
22085
- const s = n.attrs.get("samplepoints");
22086
- if (s === void 0) return DFLT_SAMPLE;
22087
- const v = parseInt(s, 10);
22088
- return Number.isNaN(v) || v < 4 || v > 60 ? DFLT_SAMPLE : v;
22089
- }
22090
- function pEllipse(a, b, np) {
22091
- const del = 2 * Math.PI / np;
22092
- const ps = [];
22093
- let theta = 0;
22094
- for (let i = 0; i < np; i++) {
22095
- ps.push({ x: a * Math.cos(theta), y: b * Math.sin(theta) });
22096
- theta += del;
22097
- }
22098
- return ps;
22099
- }
22100
- function ellipseNodeMap(poly, coord, ur, nump) {
22101
- if (poly.regular) {
22102
- return { shape: 1 /* Circle */, pts: [coord, { x: coord.x + ur.x, y: coord.y + ur.y }] };
22103
- }
22104
- const pts = pEllipse(ur.x, ur.y, nump).map((p) => ({ x: p.x + coord.x, y: p.y + coord.y }));
22105
- return { shape: 2 /* Polygon */, pts };
22106
- }
22107
- function generalNodeMap(poly, coord, vertices, peripheries, nump) {
22108
- const offset = (peripheries - 1) * poly.sides;
22109
- const pts = [];
22110
- if (poly.sides >= nump) {
22111
- const delta2 = Math.trunc(poly.sides / nump);
22112
- for (let i = 0, j = 0; j < nump; i += delta2, j++) {
22113
- const v = vertices[i + offset];
22114
- pts.push({ x: coord.x + v.x, y: coord.y + v.y });
22115
- }
22116
- } else {
22117
- for (let i = 0; i < poly.sides; i++) {
22118
- const v = vertices[i + offset];
22119
- pts.push({ x: coord.x + v.x, y: coord.y + v.y });
22120
- }
22121
- }
22122
- return { shape: 2 /* Polygon */, pts };
22123
- }
22124
- function nodePolyMap(n, poly, coord, filled) {
22125
- const peripheries = poly.peripheries < 2 ? 1 : poly.peripheries;
22126
- const vertices = poly.vertices;
22127
- const nump = samplePoints(n);
22128
- const info = n.info;
22129
- if (poly.peripheries === 0 && !filled) {
22130
- return { shape: 0 /* Rectangle */, pts: [
22131
- { x: coord.x - info.lw, y: coord.y - info.ht / 2 },
22132
- { x: coord.x + info.lw, y: coord.y + info.ht / 2 }
22133
- ] };
22134
- }
22135
- if (poly.sides < 3 && poly.skew === 0 && poly.distortion === 0) {
22136
- return ellipseNodeMap(poly, coord, vertices[2 * peripheries - 1], nump);
22137
- }
22138
- return generalNodeMap(poly, coord, vertices, peripheries, nump);
22139
- }
22140
- function computeNodeUrlMap(n, obj, ctx) {
22141
- if (!nodeHasHotspot(n)) return;
22142
- const info = n.info;
22143
- const coord = info.coord;
22144
- const poly = info.shape_info;
22145
- const filled = nodeIsFilled(n);
22146
- const isRect = poly !== void 0 && isRectPoly(poly) && (poly.peripheries !== 0 || filled);
22147
- let m;
22148
- if (poly !== void 0 && poly.vertices != null && !isRect && ctx.mapPolygon) {
22149
- m = nodePolyMap(n, poly, coord, filled);
22150
- } else {
22151
- m = { shape: 0 /* Rectangle */, pts: [
22152
- { x: coord.x - info.lw, y: coord.y - info.ht / 2 },
22153
- { x: coord.x + info.rw, y: coord.y + info.ht / 2 }
22154
- ] };
22155
- }
22156
- obj.urlMapShape = m.shape;
22157
- obj.urlMapPts = m.pts.map((p) => mapTransform(p, ctx));
22158
- }
22159
- function computeGraphUrlMap(obj, ctx) {
22160
- const ll = { x: -ctx.pad.x, y: -ctx.pad.y };
22161
- const ur = {
22162
- x: ctx.bb.ur.x - ctx.bb.ll.x + ctx.pad.x,
22163
- y: ctx.bb.ur.y - ctx.bb.ll.y + ctx.pad.y
22164
- };
22165
- obj.urlMapShape = 0 /* Rectangle */;
22166
- obj.urlMapPts = [mapTransform(ll, ctx), mapTransform(ur, ctx)];
22167
- }
22168
- function computeClusterUrlMap(bb, obj, ctx) {
22169
- obj.urlMapShape = 0 /* Rectangle */;
22170
- obj.urlMapPts = [mapTransform(bb.ll, ctx), mapTransform(bb.ur, ctx)];
22171
- }
22172
- function computeLabelRectMap(lab, obj, ctx) {
22173
- const dx = lab.dimen.x / 2;
22174
- const dy = lab.dimen.y / 2;
22175
- obj.urlMapShape = 0 /* Rectangle */;
22176
- obj.urlMapPts = [
22177
- mapTransform({ x: lab.pos.x - dx, y: lab.pos.y - dy }, ctx),
22178
- mapTransform({ x: lab.pos.x + dx, y: lab.pos.y + dy }, ctx)
22179
- ];
22180
- }
22181
- function checkControlPoints2(cp) {
22182
- return ptToLine2(cp[0], cp[3], cp[1]) < MAP_HW * MAP_HW && ptToLine2(cp[0], cp[3], cp[2]) < MAP_HW * MAP_HW;
22183
- }
22184
- function bezierHalf(v) {
22185
- const left2 = [];
22186
- const right2 = [];
22187
- bezier(v, 0.5, left2, right2);
22188
- return { left: left2, right: right2 };
22189
- }
22190
- function approxBezier(cp, out) {
22191
- if (checkControlPoints2(cp)) {
22192
- if (out.length === 0) out.push(cp[0]);
22193
- out.push(cp[3]);
22194
- } else {
22195
- const { left: left2, right: right2 } = bezierHalf(cp);
22196
- approxBezier(left2, out);
22197
- approxBezier(right2, out);
22198
- }
22199
- }
22200
- function mkSegPts(prv, cur, nxt, w2) {
22201
- let pp;
22202
- let np;
22203
- if (prv) {
22204
- pp = prv;
22205
- np = nxt ?? { x: 2 * (cur.x - pp.x), y: 2 * (cur.y - pp.y) };
22206
- } else {
22207
- np = nxt;
22208
- pp = { x: 2 * (cur.x - np.x), y: 2 * (cur.y - np.y) };
22209
- }
22210
- const theta = Math.atan2(np.y - cur.y, np.x - cur.x);
22211
- const phi = Math.atan2(pp.y - cur.y, pp.x - cur.x);
22212
- let ang = theta - phi;
22213
- if (ang > 0) ang -= 2 * Math.PI;
22214
- const bis = phi + ang / 2;
22215
- const del = { x: w2 * Math.cos(bis), y: w2 * Math.sin(bis) };
22216
- return { p1: { x: cur.x + del.x, y: cur.y + del.y }, p2: { x: cur.x - del.x, y: cur.y - del.y } };
22217
- }
22218
- function mapOutputBspline(bp, w2, polys) {
22219
- const nc = Math.trunc((bp.size - 1) / 3);
22220
- const segs = [];
22221
- for (let j = 0; j < nc; j++) {
22222
- approxBezier([bp.list[3 * j], bp.list[3 * j + 1], bp.list[3 * j + 2], bp.list[3 * j + 3]], segs);
22223
- }
22224
- const pt1 = [];
22225
- const pt2 = [];
22226
- let cnt = 0;
22227
- for (let i = 0; i < segs.length; i++) {
22228
- const prev = i === 0 ? null : segs[i - 1];
22229
- const next = i + 1 < segs.length ? segs[i + 1] : null;
22230
- const seg2 = mkSegPts(prev, segs[i], next, w2);
22231
- pt1[cnt] = seg2.p1;
22232
- pt2[cnt] = seg2.p2;
22233
- cnt++;
22234
- if (i + 1 === segs.length || cnt === 50) {
22235
- const poly = [];
22236
- for (let k = 0; k < cnt; k++) poly.push(pt1[k]);
22237
- for (let k = 0; k < cnt; k++) poly.push(pt2[cnt - 1 - k]);
22238
- polys.push(poly);
22239
- pt1[0] = pt1[cnt - 1];
22240
- pt2[0] = pt2[cnt - 1];
22241
- cnt = 1;
22242
- }
22329
+ function setupPageSize(bb, size, pad, z) {
22330
+ const jbLL = { x: bb.ll.x - pad.x, y: bb.ll.y - pad.y };
22331
+ const jbUR = { x: bb.ur.x + pad.x, y: bb.ur.y + pad.y };
22332
+ const sz = { x: jbUR.x - jbLL.x, y: jbUR.y - jbLL.y };
22333
+ if (size !== null && size.x > 1e-3 && size.y > 1e-3) {
22334
+ if (sz.x <= 1e-3) sz.x = size.x;
22335
+ if (sz.y <= 1e-3) sz.y = size.y;
22243
22336
  }
22337
+ return { x: z * sz.x / z, y: z * sz.y / z };
22244
22338
  }
22245
- function computeEdgeSplineMaps(spl, w2, ctx) {
22246
- const polys = [];
22247
- for (const bz of spl.list) mapOutputBspline(bz, w2, polys);
22248
- return polys.map((poly) => poly.map((p) => mapTransform(p, ctx)));
22339
+ function setupPageBox(pageSize, pad) {
22340
+ const ll = { x: 0 * pageSize.x - pad.x, y: 0 * pageSize.y - pad.y };
22341
+ return { ll, ur: { x: ll.x + pageSize.x, y: ll.y + pageSize.y } };
22249
22342
  }
22250
22343
 
22251
22344
  // src/common/layers.ts
@@ -22324,6 +22417,16 @@ function edgeInLayer(info, layerNum, e) {
22324
22417
  return pn === "" || selectedLayer(info, layerNum, pn);
22325
22418
  });
22326
22419
  }
22420
+ function clustInLayer(info, layerNum, sg) {
22421
+ if (info.numLayers <= 1) return true;
22422
+ const pg = graphAttrInherited(sg, "layer") ?? "";
22423
+ if (selectedLayer(info, layerNum, pg)) return true;
22424
+ if (pg !== "") return false;
22425
+ for (const n of sg.nodes.values()) {
22426
+ if (nodeInLayer(info, layerNum, n, sg)) return true;
22427
+ }
22428
+ return false;
22429
+ }
22327
22430
  function parseLayerselect(info, p) {
22328
22431
  const picked = [];
22329
22432
  for (let i = 1; i <= info.numLayers; i++) {
@@ -22345,6 +22448,9 @@ function nodeShown(info, job, n, g) {
22345
22448
  function edgeShown(info, job, e) {
22346
22449
  return info === void 0 || job.numLayers <= 1 || edgeInLayer(info, job.layerNum, e);
22347
22450
  }
22451
+ function clusterShown(info, job, sg) {
22452
+ return info === void 0 || job.numLayers <= 1 || clustInLayer(info, job.layerNum, sg);
22453
+ }
22348
22454
  function chkOrder(g) {
22349
22455
  const p = g.attrs.get("outputorder");
22350
22456
  if (p === "nodesfirst") return "nodesfirst";
@@ -22852,20 +22958,19 @@ function drawClusterInScheme(sg, renderer, job) {
22852
22958
  renderer.beginCluster?.(sg, job);
22853
22959
  if (job.obj !== null) job.obj.id = svgClusterId(sg, job);
22854
22960
  setHtmlAnchorObj(svgClusterId(sg, job), labelTextOf2(sg.info.label), job.obj ?? void 0);
22855
- if (job.obj !== null) {
22856
- resolveObjAnchor(sg, labelTextOf2(sg.info.label), svgClusterId(sg, job), job.obj);
22857
- }
22858
- const anchored = beginAnchorIf(renderer, job);
22961
+ if (job.obj !== null) resolveObjAnchor(sg, labelTextOf2(sg.info.label), svgClusterId(sg, job), job.obj);
22962
+ const late = (job.flags & EMIT_CLUSTERS_LAST) !== 0;
22963
+ const anchored = !late && beginClusterAnchor(sg, renderer, job);
22859
22964
  if ((clusterPeripheries(sg) !== 0 || filled || isStripedCluster(sg)) && job.obj?.pen !== 0 /* None */) {
22860
22965
  renderClusterBox(sg, filled, renderer, job);
22861
22966
  }
22862
22967
  renderClusterLabel(sg, renderer, job);
22863
- if (anchored) renderer.endAnchor?.(job);
22968
+ if (anchored || late && beginClusterAnchor(sg, renderer, job)) renderer.endAnchor?.(job);
22864
22969
  renderer.endCluster?.(sg, job);
22865
22970
  }
22866
- function renderOneCluster(sg, renderer, job) {
22971
+ function renderOneCluster(sg, renderer, job, info) {
22867
22972
  const clustersLast = (job.flags & EMIT_CLUSTERS_LAST) !== 0;
22868
- if (clustersLast) renderClusters(sg, renderer, job);
22973
+ if (clustersLast) renderClusters(sg, renderer, job, info);
22869
22974
  const obj = createObjState(1 /* Cluster */);
22870
22975
  obj.emitState = 1 /* CDraw */;
22871
22976
  job.pushObj(obj);
@@ -22874,15 +22979,15 @@ function renderOneCluster(sg, renderer, job) {
22874
22979
  } finally {
22875
22980
  job.popObj();
22876
22981
  }
22877
- if (!clustersLast) renderClusters(sg, renderer, job);
22982
+ if (!clustersLast) renderClusters(sg, renderer, job, info);
22878
22983
  }
22879
- function renderClusters(g, renderer, job) {
22984
+ function renderClusters(g, renderer, job, info) {
22880
22985
  const nClust = g.info.n_cluster ?? 0;
22881
22986
  const clust = g.info.clust;
22882
22987
  if (nClust === 0 || !clust) return;
22883
22988
  for (let c = 0; c < nClust; c++) {
22884
22989
  const sg = clust[c];
22885
- if (sg) renderOneCluster(sg, renderer, job);
22990
+ if (sg && clusterShown(info, job, sg)) renderOneCluster(sg, renderer, job, info);
22886
22991
  }
22887
22992
  }
22888
22993
  function renderGraph(g, job, renderer) {
@@ -22921,9 +23026,9 @@ function renderPage(g, renderer, job, info) {
22921
23026
  });
22922
23027
  if (anchored) renderer.endAnchor?.(job);
22923
23028
  const clustersLast = (job.flags & EMIT_CLUSTERS_LAST) !== 0;
22924
- if (!clustersLast) renderClusters(g, renderer, job);
23029
+ if (!clustersLast) renderClusters(g, renderer, job, info);
22925
23030
  walkNodesAndEdges(g, renderer, job, info);
22926
- if (clustersLast) renderClusters(g, renderer, job);
23031
+ if (clustersLast) renderClusters(g, renderer, job, info);
22927
23032
  renderer.endPage?.(g, job);
22928
23033
  }
22929
23034
  function newRenderJob(ctx, format, inlineImages) {
@@ -22956,6 +23061,7 @@ function render(ctx, g, format, inlineImages = false) {
22956
23061
  job.scale = { x: z * dpiScale, y: z * dpiScale };
22957
23062
  job.rotation = parseLandscape(g) ? 90 : 0;
22958
23063
  job.renderer = renderer;
23064
+ job.drawingId = drawingIdOf(g);
22959
23065
  setRendererKnownColors(renderer.type === "svg");
22960
23066
  resetHtmlAnchorIds();
22961
23067
  for (const n of g.nodes.values()) polyInit(n, g, job.measurer);
@@ -24166,7 +24272,7 @@ function makeSelfEdge(edges, cnt, sizex, sizey, sinfo) {
24166
24272
 
24167
24273
  // src/layout/dot/position-aux.ts
24168
24274
  var CL_OFFSET = 8;
24169
- var INT_MAX2 = 2147483647;
24275
+ var INT_MAX3 = 2147483647;
24170
24276
  function clusterMarginOf(g) {
24171
24277
  let raw;
24172
24278
  for (let s = g; s !== null; s = s.parent) {
@@ -24228,9 +24334,9 @@ function graphRanksep(g) {
24228
24334
  return g.info.ranksep ?? 0;
24229
24335
  }
24230
24336
  function makeAuxEdge(u, v, len, wt) {
24231
- if (len > INT_MAX2) {
24337
+ if (len > INT_MAX3) {
24232
24338
  agerrorf(
24233
- `Edge length ${printfFixed(len, 6)} larger than maximum ${INT_MAX2} allowed.
24339
+ `Edge length ${printfFixed(len, 6)} larger than maximum ${INT_MAX3} allowed.
24234
24340
  Check for overwide node(s).`
24235
24341
  );
24236
24342
  return null;
@@ -24631,14 +24737,34 @@ function xVal(e, v, dir) {
24631
24737
  if (f) d = -d;
24632
24738
  return d < 0 ? -rv : rv;
24633
24739
  }
24740
+ var INT_MAX4 = 2147483647;
24741
+ var INT_MIN2 = -2147483648;
24742
+ function sumOverflows(sum, add2) {
24743
+ const s = sum + add2;
24744
+ return s > INT_MAX4 || s < INT_MIN2;
24745
+ }
24746
+ function cutvalOverflow(v) {
24747
+ agerrorf("overflow when computing edge weight sum");
24748
+ return new RenderError(
24749
+ `Edge weights at node "${v.name}" sum past the 32-bit integer limit; lower the weight attribute values.`,
24750
+ "RENDER_ERROR",
24751
+ { context: { node: v.name } }
24752
+ );
24753
+ }
24754
+ function sumXVals(list, v, dir, sum) {
24755
+ if (!list) return sum;
24756
+ for (let i = 0; i < list.size; i++) {
24757
+ const add2 = xVal(list.list[i], v, dir);
24758
+ if (sumOverflows(sum, add2)) throw cutvalOverflow(v);
24759
+ sum += add2;
24760
+ }
24761
+ return sum;
24762
+ }
24634
24763
  function xCutval(f) {
24635
24764
  const v = f.tail.info.par === f ? f.tail : f.head;
24636
24765
  const dir = f.tail.info.par === f ? 1 : -1;
24637
- let sum = 0;
24638
- const out = v.info.out;
24639
- if (out) for (let i = 0; i < out.size; i++) sum += xVal(out.list[i], v, dir);
24640
- const inp = v.info.in;
24641
- if (inp) for (let i = 0; i < inp.size; i++) sum += xVal(inp.list[i], v, dir);
24766
+ let sum = sumXVals(v.info.out, v, dir, 0);
24767
+ sum = sumXVals(v.info.in, v, dir, sum);
24642
24768
  f.info.cutvalue = sum;
24643
24769
  }
24644
24770
  function cutvalDescend(list, iArr, top, sp, head) {
@@ -28129,7 +28255,7 @@ function flatEdges(g) {
28129
28255
  }
28130
28256
 
28131
28257
  // src/layout/dot/position.ts
28132
- var INT_MAX3 = 2147483647;
28258
+ var INT_MAX5 = 2147483647;
28133
28259
  function setXcoordsFromRank(g) {
28134
28260
  const rankArr = g.info.rank;
28135
28261
  for (let i = graphMinrank(g); i <= graphMaxrank(g); i++) {
@@ -28178,7 +28304,7 @@ function connectGraph(g) {
28178
28304
  }
28179
28305
  function nsiter2(g) {
28180
28306
  const s = g.attrs.get("nslimit") ?? g.graphDefaultsSnapshot?.get("nslimit") ?? g.root.attrs.get("nslimit") ?? agGraphAttr(g.root, "nslimit");
28181
- if (s === void 0) return INT_MAX3;
28307
+ if (s === void 0) return INT_MAX5;
28182
28308
  return scaleClamp(g.nodes.size, parseFloat(s) || 0);
28183
28309
  }
28184
28310
  function expandRankSlots(rk, newN) {
@@ -32585,11 +32711,11 @@ function maxOutputline() {
32585
32711
  function setMaxOutputline(n) {
32586
32712
  maxOutputlineValue = n;
32587
32713
  }
32588
- var INT_MAX4 = 2147483647;
32714
+ var INT_MAX6 = 2147483647;
32589
32715
  function linelengthOf(s) {
32590
32716
  if (s === void 0 || !/^[0-9]/.test(s)) return void 0;
32591
32717
  const len = Number(/^[0-9]+/.exec(s)[0]);
32592
- if ((len === 0 || len >= MIN_OUTPUTLINE) && len <= INT_MAX4) return len;
32718
+ if ((len === 0 || len >= MIN_OUTPUTLINE) && len <= INT_MAX6) return len;
32593
32719
  return void 0;
32594
32720
  }
32595
32721
  function withLinelength(g, write) {
@@ -32881,16 +33007,13 @@ function cmapxShape(shape) {
32881
33007
  return "poly";
32882
33008
  }
32883
33009
  function cmapxCoordsRect(pts) {
32884
- return String(Math.round(pts[0].x)) + "," + String(Math.round(pts[1].y)) + "," + String(Math.round(pts[1].x)) + "," + String(Math.round(pts[0].y));
33010
+ return printfFixed0(pts[0].x) + "," + printfFixed0(pts[1].y) + "," + printfFixed0(pts[1].x) + "," + printfFixed0(pts[0].y);
32885
33011
  }
32886
33012
  function cmapxCoordsCircle(pts) {
32887
- const cx = Math.round(pts[0].x);
32888
- const cy = Math.round(pts[0].y);
32889
- const r = Math.round(pts[1].x - pts[0].x);
32890
- return String(cx) + "," + String(cy) + "," + String(r);
33013
+ return printfFixed0(pts[0].x) + "," + printfFixed0(pts[0].y) + "," + printfFixed0(pts[1].x - pts[0].x);
32891
33014
  }
32892
33015
  function cmapxCoordsPoly(pts) {
32893
- return pts.map((p) => String(Math.round(p.x)) + "," + String(Math.round(p.y))).join(",");
33016
+ return pts.map((p) => printfFixed0(p.x) + "," + printfFixed0(p.y)).join(",");
32894
33017
  }
32895
33018
  function cmapxCoords(shape, pts) {
32896
33019
  if (shape === 1 /* Circle */) return cmapxCoordsCircle(pts);
@@ -32913,12 +33036,11 @@ function mapOutputCmapx(shape, pts, a, isXml, out) {
32913
33036
  function mapOutputImap(shape, pts, url, out) {
32914
33037
  if (!url) return;
32915
33038
  if (shape === 0 /* Rectangle */) {
32916
- out.push("rect " + url + " " + Math.round(pts[0].x) + "," + Math.round(pts[1].y) + " " + Math.round(pts[1].x) + "," + Math.round(pts[0].y) + "\n");
33039
+ out.push("rect " + url + " " + printfFixed0(pts[0].x) + "," + printfFixed0(pts[1].y) + " " + printfFixed0(pts[1].x) + "," + printfFixed0(pts[0].y) + "\n");
32917
33040
  } else if (shape === 1 /* Circle */) {
32918
- const r = Math.round(pts[1].x - pts[0].x);
32919
- out.push("circle " + url + " " + Math.round(pts[0].x) + "," + Math.round(pts[0].y) + "," + String(r) + "\n");
33041
+ out.push("circle " + url + " " + printfFixed0(pts[0].x) + "," + printfFixed0(pts[0].y) + "," + printfFixed0(pts[1].x - pts[0].x) + "\n");
32920
33042
  } else {
32921
- const pairs = pts.map((p) => Math.round(p.x) + "," + Math.round(p.y)).join(" ");
33043
+ const pairs = pts.map((p) => printfFixed0(p.x) + "," + printfFixed0(p.y)).join(" ");
32922
33044
  out.push("poly " + url + " " + pairs + "\n");
32923
33045
  }
32924
33046
  }
@@ -32996,11 +33118,13 @@ function graphMapUrl(g) {
32996
33118
  }
32997
33119
  function buildMapCtx(g, job, mapPolygon) {
32998
33120
  const drawingDpi = lateDouble(g.attrs.get("dpi"), lateDouble(g.attrs.get("resolution"), 0, 0), 0);
32999
- const mapDpi = drawingDpi > 0 ? drawingDpi : 96;
33000
- const devscale = mapDpi / POINTS_PER_INCH2;
33001
- const z = initJobViewportZoom(job.bb, parseDrawingSize(g.attrs.get("size")), job.pad);
33002
- const marginOff = { x: job.margin.x * devscale, y: job.margin.y * devscale };
33003
- return { bb: job.bb, pad: job.pad, scale: z * devscale, marginOff, mapPolygon };
33121
+ const devscale = (drawingDpi > 0 ? drawingDpi : 96) / POINTS_PER_INCH2;
33122
+ const size = parseDrawingSize(g.attrs.get("size"));
33123
+ const z = initJobViewportZoom(job.bb, size, job.pad);
33124
+ const clip = setupPageClip(job.bb, size, job.pad, z);
33125
+ const pageBox = setupPageBox(setupPageSize(job.bb, size, job.pad, z), job.pad);
33126
+ const translation = { x: -clip.ll.x + job.margin.x / z, y: -clip.ur.y - job.margin.y / z };
33127
+ return { pageBox, translation, scale: { x: z * devscale, y: z * -devscale }, mapPolygon };
33004
33128
  }
33005
33129
  function anchorOf(url, tooltip, target, id) {
33006
33130
  return { url: url ?? "", tooltip: tooltip ?? "", target: target ?? "", id: id ?? "" };
@@ -33035,12 +33159,6 @@ var MapRendererBase = class {
33035
33159
  beginNode(n, job) {
33036
33160
  if (this.mapCtx !== null && job.obj !== null) computeNodeUrlMap(n, job.obj, this.mapCtx);
33037
33161
  }
33038
- beginCluster(sg, job) {
33039
- const bb = sg.info.bb;
33040
- if (this.mapCtx !== null && job.obj !== null && bb !== void 0) {
33041
- computeClusterUrlMap(bb, job.obj, this.mapCtx);
33042
- }
33043
- }
33044
33162
  endEdge(e, job) {
33045
33163
  if (this.mapCtx !== null && job.obj !== null) this.emitEdge(e, job.obj, job);
33046
33164
  }
@@ -33095,30 +33213,34 @@ var MapRendererBase = class {
33095
33213
  url: obj.labelUrl,
33096
33214
  tooltip: obj.labelTooltip,
33097
33215
  target: obj.labelTarget,
33098
- explicit: obj.explicitLabelTooltip
33216
+ explicit: obj.explicitLabelTooltip,
33217
+ suffix: "label"
33099
33218
  };
33100
33219
  this.emitEdgeLabel(e.info.label, centerA, obj, job);
33101
33220
  this.emitEdgeLabel(e.info.xlabel, centerA, obj, job);
33102
- this.emitEdgeLabel(
33103
- e.info.head_label,
33104
- { url: obj.headUrl, tooltip: obj.headTooltip, target: obj.headTarget, explicit: obj.explicitHeadTooltip },
33105
- obj,
33106
- job
33107
- );
33108
- this.emitEdgeLabel(
33109
- e.info.tail_label,
33110
- { url: obj.tailUrl, tooltip: obj.tailTooltip, target: obj.tailTarget, explicit: obj.explicitTailTooltip },
33111
- obj,
33112
- job
33113
- );
33114
- }
33115
- /** One edge label hot spot (map_label rect), if placed and url/explicit-tip.
33116
- * @see lib/common/emit.c:emit_edge_label */
33221
+ this.emitEdgeLabel(e.info.head_label, {
33222
+ url: obj.headUrl,
33223
+ tooltip: obj.headTooltip,
33224
+ target: obj.headTarget,
33225
+ explicit: obj.explicitHeadTooltip,
33226
+ suffix: "headlabel"
33227
+ }, obj, job);
33228
+ this.emitEdgeLabel(e.info.tail_label, {
33229
+ url: obj.tailUrl,
33230
+ tooltip: obj.tailTooltip,
33231
+ target: obj.tailTarget,
33232
+ explicit: obj.explicitTailTooltip,
33233
+ suffix: "taillabel"
33234
+ }, obj, job);
33235
+ }
33236
+ /** One edge label hot spot (map_label rect), if placed and url/explicit-tip; its id is
33237
+ * `<obj.id>-<suffix>` (C: `if (id)`, else NULL). @see lib/common/emit.c:emit_edge_label (2851-2876) */
33117
33238
  emitEdgeLabel(lab, la, obj, job) {
33118
33239
  const placed = lab !== void 0 && lab.set && this.mapCtx !== null;
33119
33240
  if (!placed || la.url === null && !la.explicit) return;
33120
33241
  computeLabelRectMap(lab, obj, this.mapCtx);
33121
- this.emitShape(0 /* Rectangle */, obj.urlMapPts, anchorOf(la.url, la.tooltip, la.target, obj.id), job);
33242
+ const id = obj.id === null ? null : `${obj.id}-${la.suffix}`;
33243
+ this.emitShape(0 /* Rectangle */, obj.urlMapPts, anchorOf(la.url, la.tooltip, la.target, id), job);
33122
33244
  }
33123
33245
  };
33124
33246
  var ImapRenderer = class extends MapRendererBase {
@@ -35893,15 +36015,18 @@ function buildArrays(gp, nObjs, nLbls, nClbls, et) {
35893
36015
  return { ctx };
35894
36016
  }
35895
36017
  function writeBackLabels(gp, lbls, nLbls) {
36018
+ let cnt = 0;
35896
36019
  for (let i = 0; i < nLbls; i++) {
35897
36020
  const xlp = lbls[i];
35898
36021
  if (xlp.set) {
36022
+ cnt++;
35899
36023
  const lp = xlp.lbl;
35900
36024
  lp.set = true;
35901
36025
  lp.pos = centerPt(xlp);
35902
36026
  updateBBForLabel(gp, lp);
35903
36027
  }
35904
36028
  }
36029
+ return cnt;
35905
36030
  }
35906
36031
  var XLABEL_WORK_MASK = NODE_XLABEL | EDGE_XLABEL | TAIL_LABEL | HEAD_LABEL;
35907
36032
  function needsXLabelWork(gp) {
@@ -35922,7 +36047,10 @@ function runPlacement(gp) {
35922
36047
  const force = forceStr === void 0 ? true : mapbool(forceStr);
35923
36048
  const params = { bb: { ll: ctx.bb.ll, ur: ctx.bb.ur }, force };
35924
36049
  placeLabels(ctx.objs, ctx.lbls, params);
35925
- writeBackLabels(gp, ctx.lbls, nLbls);
36050
+ const cnt = writeBackLabels(gp, ctx.lbls, nLbls);
36051
+ if (cnt !== nLbls) {
36052
+ agwarningf(`${cnt} out of ${nLbls} exterior labels positioned.`);
36053
+ }
35926
36054
  }
35927
36055
  function addXLabels(gp) {
35928
36056
  if (!needsXLabelWork(gp)) return;
@@ -37857,19 +37985,6 @@ function boxIntersectf(pp, cp, bb) {
37857
37985
  }
37858
37986
 
37859
37987
  // src/layout/dot/compound.ts
37860
- function fillClustMap(g, map) {
37861
- const nc = g.info.n_cluster ?? 0;
37862
- for (let c = 1; c <= nc; c++) {
37863
- const cl = g.info.clust[c - 1];
37864
- if (!map.has(cl.name)) map.set(cl.name, cl);
37865
- fillClustMap(cl, map);
37866
- }
37867
- }
37868
- function mkClustMap2(g) {
37869
- const map = /* @__PURE__ */ new Map();
37870
- fillClustMap(g, map);
37871
- return map;
37872
- }
37873
37988
  function arrowEndClipIdx(state3, endp) {
37874
37989
  const { e, bez } = state3;
37875
37990
  const elen = arrowClipLength(edgeArrowName(e, "head"), edgeArrowsize(e), edgePenwidthAttr(e));
@@ -38020,7 +38135,7 @@ function makeCompoundEdge(e, clustMap) {
38020
38135
  if (tailClipped && bez.sflag) restashArrow(e, bez.sp, bez.list[0], true);
38021
38136
  }
38022
38137
  function dotCompoundEdges(g) {
38023
- const clustMap = mkClustMap2(g);
38138
+ const clustMap = mkClustMap(g);
38024
38139
  for (const e of g.edges) makeCompoundEdge(e, clustMap);
38025
38140
  }
38026
38141
 
@@ -49510,7 +49625,7 @@ function springElectricalEmbedding(dim, A0, ctrl, x) {
49510
49625
 
49511
49626
  // src/layout/sfdp/init.ts
49512
49627
  var SMOOTHING_NONE = 0;
49513
- var INT_MAX5 = 2147483647;
49628
+ var INT_MAX7 = 2147483647;
49514
49629
  var ELSCHEME_PENALTY2 = 2;
49515
49630
  var EDGE_LABEL_NODE_PREFIX = "|edgelabel|";
49516
49631
  function sfdpInitDim(g) {
@@ -49579,7 +49694,7 @@ function tuneControl(g, ctrl) {
49579
49694
  }
49580
49695
  ctrl.K = lateDouble(aggetGraph(g, "K"), -1, 0);
49581
49696
  ctrl.p = -1 * lateDouble(aggetGraph(g, "repulsiveforce"), -AUTOP, 0);
49582
- ctrl.multilevels = lateInt(aggetGraph(g, "levels"), INT_MAX5, 0);
49697
+ ctrl.multilevels = lateInt(aggetGraph(g, "levels"), INT_MAX7, 0);
49583
49698
  const smoothing = aggetGraph(g, "smoothing");
49584
49699
  if (smoothing !== void 0 && smoothing.toLowerCase() !== "none" && smoothing !== String(SMOOTHING_NONE)) {
49585
49700
  throw new RenderError(
@@ -50578,7 +50693,7 @@ var AM_PORTHOXY = 11;
50578
50693
  var AM_PORTHOYX = 12;
50579
50694
  var SCALE = 10;
50580
50695
  var SCALE2 = SCALE / 2;
50581
- var INT_MAX6 = 2147483647;
50696
+ var INT_MAX8 = 2147483647;
50582
50697
  var POINTS_PER_INCH6 = 72;
50583
50698
  function cmpitem(a, b) {
50584
50699
  if (a < b) return -1;
@@ -50698,7 +50813,7 @@ function mkNConstraintG(g, list, intersect, dist5) {
50698
50813
  return cg;
50699
50814
  }
50700
50815
  function buildChain(cg, flat) {
50701
- let oldval = -INT_MAX6;
50816
+ let oldval = -INT_MAX8;
50702
50817
  let prev;
50703
50818
  let n;
50704
50819
  let lastn;
@@ -50720,7 +50835,7 @@ function buildChain(cg, flat) {
50720
50835
  }
50721
50836
  function buildVisibility(flat, intersect) {
50722
50837
  const vg = flat.map(() => []);
50723
- let oldval = -INT_MAX6;
50838
+ let oldval = -INT_MAX8;
50724
50839
  let nxt = flat.length;
50725
50840
  for (let i = 0; i < flat.length; i++) {
50726
50841
  const p = flat[i];
@@ -50771,7 +50886,7 @@ function constrainX(g, nlist, ifn, ortho) {
50771
50886
  list.insert(p);
50772
50887
  }
50773
50888
  const cg = buildConstraintGraph(g, list, ifn, distX, ortho);
50774
- rank(cg.g, 2, INT_MAX6);
50889
+ rank(cg.g, 2, INT_MAX8);
50775
50890
  for (const p of nlist) {
50776
50891
  const newpos = cnodeOf(p).info.rank ?? 0;
50777
50892
  const delta2 = newpos - p.pos.x;
@@ -50787,7 +50902,7 @@ function constrainY(g, nlist, ifn, ortho) {
50787
50902
  list.insert(p);
50788
50903
  }
50789
50904
  const cg = buildConstraintGraph(g, list, ifn, distY, ortho);
50790
- rank(cg.g, 2, INT_MAX6);
50905
+ rank(cg.g, 2, INT_MAX8);
50791
50906
  for (const p of nlist) {
50792
50907
  const newpos = cnodeOf(p).info.rank ?? 0;
50793
50908
  const delta2 = newpos - p.pos.y;
@@ -56084,7 +56199,7 @@ function emitAttachment(lp, spl, renderer, job) {
56084
56199
 
56085
56200
  // src/render/svg-cluster.ts
56086
56201
  function svgBeginCluster(sg, job) {
56087
- job.write('<g id="' + escapeXmlTitle(job.idLayerPrefix() + svgClusterId(sg, job)) + '" ' + svgClusterClass(sg) + ">\n");
56202
+ job.write('<g id="' + escapeXmlTitle(svgClusterId(sg, job)) + '" ' + svgClusterClass(sg) + ">\n");
56088
56203
  job.write("<title>" + escapeXmlTitle(sg.name) + "</title>\n");
56089
56204
  }
56090
56205
  function svgEndCluster(job) {
@@ -56463,6 +56578,7 @@ function writeDictSkips(v, inherited) {
56463
56578
  function echoGraphAttr(g, key) {
56464
56579
  const v = g.attrs.get(key);
56465
56580
  if (v === void 0) return [];
56581
+ if (g.seededAttrs?.has(key) === true) return [];
56466
56582
  if (writeDictSkips(v, g.graphDefaultsSnapshot?.get(key))) return [];
56467
56583
  return [`${key}=${agstrcanon(v)}`];
56468
56584
  }
@@ -56508,7 +56624,7 @@ function isDirected(g) {
56508
56624
 
56509
56625
  // src/render/dot/agwrite.ts
56510
56626
  var DotWriterBase = class {
56511
- /** Clusters in render order (GD_clust); filled by the renderer's endCluster. */
56627
+ /** The clusters xdot_end_cluster ran for (not all of GD_clust: inClusterTree). */
56512
56628
  clusters = [];
56513
56629
  /**
56514
56630
  * Emit `key=<canon value>` through `_agstrcanon`, as `agwrite` does for the xdot
@@ -56575,7 +56691,7 @@ var DotWriterBase = class {
56575
56691
  * a boxed graph and an unboxed child — the driver that makes an anon subgraph
56576
56692
  * under the root or a cluster "relevant". @see lib/common/output.c:safe_dcl */
56577
56693
  hasBb(g) {
56578
- return g === g.root || this.clusters.includes(g);
56694
+ return g === g.root || inClusterTree(g);
56579
56695
  }
56580
56696
  /** Anonymous subgraph with no own node/edge defaults and no graph attrs
56581
56697
  * differing from its parent → inlined into the parent. Native compares every
@@ -56583,7 +56699,7 @@ var DotWriterBase = class {
56583
56699
  * the parent, empty on the child) and `rank`. @see write.c:irrelevant_subgraph */
56584
56700
  irrelevantSubgraph(g) {
56585
56701
  if (!this.isAnonymous(g)) return false;
56586
- if (this.clusters.includes(g)) return false;
56702
+ if (inClusterTree(g)) return false;
56587
56703
  if (g.nodeDefaults.size > 0 || g.edgeDefaults.size > 0) return false;
56588
56704
  if (g.parent) {
56589
56705
  if (this.hasBb(g) !== this.hasBb(g.parent)) return false;
@@ -56601,9 +56717,8 @@ var DotWriterBase = class {
56601
56717
  * `rec_attach_bb` walks the ROOT and then `GD_clust` recursively, so a
56602
56718
  * subgraph the layout did not box is attached NEITHER `bb` NOR the label
56603
56719
  * triple — both keep the INPUT's values, which agwrite echoes. circo and
56604
- * twopi lay out no clusters at all (`GD_clust` empty — mirrored here by
56605
- * `this.clusters`, filled from endCluster), so on a re-fed dot output their
56606
- * `cluster0` comes back carrying the *previous* run's `bb` and `lp`.
56720
+ * twopi lay out no clusters (`GD_clust` empty, `inClusterTree` false), so on a
56721
+ * re-fed dot output `cluster0` carries the *previous* run's `bb` and `lp`.
56607
56722
  * @see lib/common/output.c:249 rec_attach_bb */
56608
56723
  subgGraphAttrs(sg) {
56609
56724
  const parts = [];
@@ -56635,7 +56750,7 @@ var DotWriterBase = class {
56635
56750
  * order. @see lib/cgraph/write.c:307 write_dicts
56636
56751
  */
56637
56752
  writeDicts(g, top, ctx) {
56638
- const graphParts = top ? this.graphAttrs(g) : this.clusters.includes(g) ? this.clusterAttrs(g) : this.subgGraphAttrs(g);
56753
+ const graphParts = top ? this.graphAttrs(g) : inClusterTree(g) ? this.clusterAttrs(g) : this.subgGraphAttrs(g);
56639
56754
  this.writeDict("graph", graphParts, ctx);
56640
56755
  this.writeDict("node", nodeDictParts(g, top), ctx);
56641
56756
  this.writeDict("edge", dictParts(g.edgeDefaults), ctx);
@@ -56816,13 +56931,14 @@ var DotWriterBase = class {
56816
56931
  parts.push(...graphInputParts(g, true, this.emitDraws));
56817
56932
  return parts;
56818
56933
  }
56819
- /** Cluster attribute block. C's xdot_end_cluster ALWAYS agsets `_draw_` when
56820
- * the graph has clusters (even empty, e.g. peripheries=0), so emit it
56821
- * unconditionally; `_ldraw_` only when the cluster has a label.
56934
+ /** Cluster attribute block. C's xdot_end_cluster ALWAYS agsets `_draw_` for a
56935
+ * cluster it ran for (even empty, e.g. peripheries=0); one that emit_clusters
56936
+ * skipped (clust_in_layer) keeps only a stored one. `_ldraw_` only with a label.
56822
56937
  * @see plugin/core/gvrender_core_dot.c:284 xdot_end_cluster */
56823
56938
  clusterAttrs(sg) {
56824
56939
  const d = this.drawsOf(sg);
56825
- const parts = this.emitDraws || d?.draw ? [this.drawAttr("_draw_", d?.draw ?? "")] : [];
56940
+ const drawn = this.emitDraws && this.clusters.includes(sg);
56941
+ const parts = drawn || d?.draw ? [this.drawAttr("_draw_", d?.draw ?? "")] : [];
56826
56942
  if (d?.ldraw) parts.push(this.drawAttr("_ldraw_", d.ldraw));
56827
56943
  if (sg.info.bb) parts.push('bb="' + this.bbStr(sg) + '"');
56828
56944
  parts.push(...graphLabelAttrs(sg));
@@ -61218,6 +61334,35 @@ function peg$parse(input, options) {
61218
61334
  }
61219
61335
  }
61220
61336
 
61337
+ // src/parser/graph-attr-syms.ts
61338
+ function hasLocalGraphSym(g, key) {
61339
+ if (g.parent === null) return g.declaredGraphAttrs.has(key);
61340
+ if (g.pinnedAttrs?.has(key) === true) return true;
61341
+ return g.attrs.has(key) && g.seededAttrs?.has(key) !== true;
61342
+ }
61343
+ function pinSubgraphsAttr(parent2, key) {
61344
+ for (const sub of parent2.subgraphs.values()) {
61345
+ if (!hasLocalGraphSym(sub, key)) (sub.pinnedAttrs ??= /* @__PURE__ */ new Set()).add(key);
61346
+ }
61347
+ }
61348
+ function effectiveGraphDefaults(scope) {
61349
+ const eff = /* @__PURE__ */ new Map();
61350
+ const found = /* @__PURE__ */ new Set();
61351
+ const take = (g, key) => {
61352
+ if (found.has(key)) return;
61353
+ found.add(key);
61354
+ const v = g.attrs.get(key);
61355
+ if (v !== void 0) eff.set(key, v);
61356
+ };
61357
+ for (let g = scope; g !== null; g = g.parent) {
61358
+ for (const key of g.attrs.keys()) {
61359
+ if (g.seededAttrs?.has(key) !== true) take(g, key);
61360
+ }
61361
+ for (const key of g.pinnedAttrs ?? []) take(g, key);
61362
+ }
61363
+ return eff;
61364
+ }
61365
+
61221
61366
  // src/parser/builder.ts
61222
61367
  function normaliseAttrValue(value) {
61223
61368
  return value;
@@ -61242,16 +61387,6 @@ function effectiveNodeDefaults2(scope) {
61242
61387
  }
61243
61388
  return eff;
61244
61389
  }
61245
- var GRAPH_LABEL_INHERIT_KEYS = ["label", "fontname", "fontsize", "fontcolor", "labelloc", "labeljust"];
61246
- function effectiveGraphDefaults(scope) {
61247
- const eff = /* @__PURE__ */ new Map();
61248
- for (let g = scope; g !== null; g = g.parent) {
61249
- for (const [k, v] of g.attrs) {
61250
- if (!eff.has(k)) eff.set(k, v);
61251
- }
61252
- }
61253
- return eff;
61254
- }
61255
61390
  var NodeRegistry = class {
61256
61391
  nextId = 0;
61257
61392
  reset() {
@@ -61266,29 +61401,6 @@ var NodeRegistry = class {
61266
61401
  return node;
61267
61402
  }
61268
61403
  };
61269
- var NameCollector = class _NameCollector {
61270
- static fromStmts(stmts) {
61271
- const out = [];
61272
- for (const s of stmts) _NameCollector.fromStmt(s, out);
61273
- return out;
61274
- }
61275
- static fromStmt(stmt, out) {
61276
- if (stmt.type === "node") {
61277
- out.push(stmt.id.id);
61278
- } else if (stmt.type === "edge") {
61279
- for (const item of stmt.nodes) _NameCollector.fromEndpoint(item, out);
61280
- } else if (stmt.type === "subgraph") {
61281
- out.push(..._NameCollector.fromStmts(stmt.stmts));
61282
- }
61283
- }
61284
- static fromEndpoint(item, out) {
61285
- if ("type" in item && item.type === "subgraph") {
61286
- out.push(..._NameCollector.fromStmts(item.stmts));
61287
- } else {
61288
- out.push(item.id);
61289
- }
61290
- }
61291
- };
61292
61404
  var StmtProcessor = class _StmtProcessor {
61293
61405
  constructor(registry) {
61294
61406
  this.registry = registry;
@@ -61357,22 +61469,32 @@ var StmtProcessor = class _StmtProcessor {
61357
61469
  this.anonCounter++;
61358
61470
  }
61359
61471
  processAssign(stmt, graph) {
61360
- graph.attrs.set(stmt.key, normaliseAttrValue(stmt.value));
61361
61472
  this.declareGraphAttr(graph, stmt.key);
61473
+ graph.attrs.set(stmt.key, normaliseAttrValue(stmt.value));
61362
61474
  }
61363
- /** Record a graph-attribute declaration, noting whether THIS scope was the
61364
- * first to declare the key anywhere — the branch selector in cgraph's
61365
- * setattr. @see lib/cgraph/attr.c:257 · model/graph.ts firstGraphDecl */
61475
+ /** Record a graph-attribute declaration, BEFORE its value is stored, noting
61476
+ * whether THIS scope was the first to declare the key anywhere — the branch
61477
+ * selector in cgraph's setattr. @see model/graph.ts firstGraphDecl
61478
+ * A scope that already holds a symbol for the key (the root always; the
61479
+ * first declarer, through bindattrs' empty declaration) updates it, which
61480
+ * first pins its direct subgraphs; a new local definition pins nothing.
61481
+ * A key declared in a re-opened subgraph's later body gets a local symbol,
61482
+ * so it is no longer a seeded one. @see lib/cgraph/attr.c:setattr */
61366
61483
  declareGraphAttr(graph, key) {
61367
- if (!graph.root.declaredGraphAttrs.has(key)) {
61484
+ const first = !graph.root.declaredGraphAttrs.has(key);
61485
+ if (first) {
61368
61486
  (graph.firstGraphDecl ??= /* @__PURE__ */ new Set()).add(key);
61369
61487
  graph.root.declaredGraphAttrs.add(key);
61370
61488
  }
61489
+ if (first || hasLocalGraphSym(graph, key)) pinSubgraphsAttr(graph, key);
61490
+ graph.seededAttrs?.delete(key);
61371
61491
  }
61372
61492
  processAttr(stmt, graph) {
61373
61493
  if (stmt.target === "graph") {
61374
- applyAttrs(stmt.attrs, graph.attrs);
61375
- for (const a of stmt.attrs) this.declareGraphAttr(graph, a.key);
61494
+ for (const a of stmt.attrs) {
61495
+ this.declareGraphAttr(graph, a.key);
61496
+ applyAttrs([a], graph.attrs);
61497
+ }
61376
61498
  } else if (stmt.target === "node") {
61377
61499
  applyAttrs(stmt.attrs, graph.nodeDefaults);
61378
61500
  } else {
@@ -61387,10 +61509,14 @@ var StmtProcessor = class _StmtProcessor {
61387
61509
  }
61388
61510
  }
61389
61511
  processEdgeStmt(stmt, graph, root, directed) {
61390
- const ends = stmt.nodes.map((item) => ({
61391
- nodes: this.resolveEndpoint(item, root, graph, directed),
61512
+ const refs = stmt.nodes.map((item) => ({
61513
+ ref: this.resolveEndpoint(item, root, graph, directed),
61392
61514
  port: portStringOf(item)
61393
61515
  }));
61516
+ const ends = refs.map(({ ref, port }) => ({
61517
+ nodes: ref instanceof Graph ? [...ref.nodes.values()].sort((a, b) => a.id - b.id) : ref,
61518
+ port
61519
+ }));
61394
61520
  for (let i = 0; i < ends.length - 1; i++) {
61395
61521
  this.connectEndpoints(ends[i], ends[i + 1], stmt.attrs, graph, root);
61396
61522
  }
@@ -61398,16 +61524,18 @@ var StmtProcessor = class _StmtProcessor {
61398
61524
  processSubgraph(stmt, graph, root, directed) {
61399
61525
  const sgName = stmt.id ?? `%${this.nextAnonId()}`;
61400
61526
  const prior2 = graph.subgraphs.get(sgName);
61527
+ if (prior2 !== void 0) {
61528
+ buildGraph(stmt.stmts, prior2, root, directed, this);
61529
+ return prior2;
61530
+ }
61401
61531
  const sg = new Graph(sgName, graph.kind);
61402
61532
  sg.parent = graph;
61403
61533
  sg.root = root;
61404
- if (prior2 !== void 0) sg.seq = prior2.seq;
61405
- else assignSubgSeq(graph, sg);
61534
+ assignSubgSeq(graph, sg);
61406
61535
  sg.graphDefaultsSnapshot = effectiveGraphDefaults(graph);
61407
61536
  buildGraph(stmt.stmts, sg, root, directed, this);
61408
- for (const key of GRAPH_LABEL_INHERIT_KEYS) {
61409
- const v = sg.graphDefaultsSnapshot.get(key);
61410
- if (v !== void 0 && !sg.attrs.has(key)) {
61537
+ for (const [key, v] of sg.graphDefaultsSnapshot) {
61538
+ if (!sg.attrs.has(key)) {
61411
61539
  sg.attrs.set(key, v);
61412
61540
  (sg.seededAttrs ??= /* @__PURE__ */ new Set()).add(key);
61413
61541
  }
@@ -61448,12 +61576,11 @@ var StmtProcessor = class _StmtProcessor {
61448
61576
  }
61449
61577
  }
61450
61578
  }
61579
+ /** One endpoint of an edge statement: a node item's node, or a subgraph
61580
+ * item's subgraph, which the caller expands after the whole statement. */
61451
61581
  resolveEndpoint(item, root, scope, directed) {
61452
61582
  if ("type" in item && item.type === "subgraph") {
61453
- this.processSubgraph(item, scope, root, directed);
61454
- const seen2 = /* @__PURE__ */ new Set();
61455
- const nodes = NameCollector.fromStmts(item.stmts).map((n) => this.registry.ensure(n, root, scope)).filter((nd) => seen2.has(nd.id) ? false : (seen2.add(nd.id), true));
61456
- return nodes.sort((a, b) => a.id - b.id);
61583
+ return this.processSubgraph(item, scope, root, directed);
61457
61584
  }
61458
61585
  return [this.registry.ensure(item.id, root, scope)];
61459
61586
  }
@@ -62127,7 +62254,7 @@ function collectDrawLookup(g) {
62127
62254
  for (const [nm, gChild] of gSub.subgraphs) {
62128
62255
  const xgChild = xgSub.subgraphs.get(nm);
62129
62256
  if (xgChild !== void 0) {
62130
- cluster.set(gChild, new Map(xgChild.attrs));
62257
+ cluster.set(gChild, localGraphAttrs(xgChild));
62131
62258
  correlate(gChild, xgChild);
62132
62259
  } else {
62133
62260
  correlate(gChild, xgSub);
@@ -62307,7 +62434,7 @@ function buildEdgesArray(g, ctx) {
62307
62434
  }
62308
62435
  function buildGraphObject(g, top, ctx) {
62309
62436
  const o = {};
62310
- o.name = g.name;
62437
+ o.name = agNameOf(g);
62311
62438
  if (top) {
62312
62439
  o.directed = g.kind === "directed" || g.kind === "strict-directed";
62313
62440
  o.strict = g.kind === "strict-directed" || g.kind === "strict-undirected";
@@ -62383,11 +62510,16 @@ var Json0Renderer = class extends JsonRendererBase {
62383
62510
  type = "json0";
62384
62511
  beginGraph(_g, _job) {
62385
62512
  }
62386
- /** C's json_begin_graph runs attach_attrs; buildJson overlays the same values. */
62513
+ /**
62514
+ * Attach, then write: C's json_begin_graph runs attach_attrs (which ends by
62515
+ * undoing cluster edges) before json_end_graph writes, and json0 prints what
62516
+ * that stored. Nothing overlays `bb` or an edge's `pos` here, as json's xdot
62517
+ * draw lookup does, so the write-back cannot wait until after the write.
62518
+ * @see plugin/core/gvrender_core_json.c:json_begin_graph
62519
+ */
62387
62520
  endGraph(g, job) {
62388
- const later = attachBeforeWriteWithClusterEdges(g, () => attachAttrs(g));
62521
+ attachBeforeWriteWithClusterEdges(g, () => attachAttrs(g))();
62389
62522
  job.write(buildJson(g, false));
62390
- later();
62391
62523
  }
62392
62524
  };
62393
62525
  var JsonRenderer = class extends JsonRendererBase {