@knowvah/dot-engine 2.12.3 → 2.12.4

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 (80) hide show
  1. package/dist/api.js +12 -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/gvc/anchor.d.ts +17 -19
  12. package/dist/gvc/anchor.d.ts.map +1 -1
  13. package/dist/gvc/device-cluster.d.ts +9 -0
  14. package/dist/gvc/device-cluster.d.ts.map +1 -1
  15. package/dist/gvc/device.d.ts +2 -1
  16. package/dist/gvc/device.d.ts.map +1 -1
  17. package/dist/gvc/emit-walk.d.ts +7 -0
  18. package/dist/gvc/emit-walk.d.ts.map +1 -1
  19. package/dist/gvc/job.d.ts +13 -6
  20. package/dist/gvc/job.d.ts.map +1 -1
  21. package/dist/gvc/viewport.d.ts +14 -0
  22. package/dist/gvc/viewport.d.ts.map +1 -1
  23. package/dist/index.js +557 -469
  24. package/dist/index.js.map +4 -4
  25. package/dist/layout/dot/compound.d.ts +0 -4
  26. package/dist/layout/dot/compound.d.ts.map +1 -1
  27. package/dist/layout/fdp/cluster-edges.d.ts.map +1 -1
  28. package/dist/model/cgraph-ops.d.ts +7 -0
  29. package/dist/model/cgraph-ops.d.ts.map +1 -1
  30. package/dist/model/graph.d.ts +12 -2
  31. package/dist/model/graph.d.ts.map +1 -1
  32. package/dist/parser/builder.d.ts +11 -10
  33. package/dist/parser/builder.d.ts.map +1 -1
  34. package/dist/parser/graph-attr-syms.d.ts +35 -0
  35. package/dist/parser/graph-attr-syms.d.ts.map +1 -0
  36. package/dist/render/dot/agwrite.d.ts +6 -7
  37. package/dist/render/dot/agwrite.d.ts.map +1 -1
  38. package/dist/render/dot/attrs.d.ts +5 -0
  39. package/dist/render/dot/attrs.d.ts.map +1 -1
  40. package/dist/render/json-cluster-edge.d.ts +3 -2
  41. package/dist/render/json-cluster-edge.d.ts.map +1 -1
  42. package/dist/render/json.d.ts +7 -1
  43. package/dist/render/json.d.ts.map +1 -1
  44. package/dist/render/map.d.ts +14 -10
  45. package/dist/render/map.d.ts.map +1 -1
  46. package/dist/render/svg-graph.d.ts.map +1 -1
  47. package/dist/render/svg-id.d.ts +9 -0
  48. package/dist/render/svg-id.d.ts.map +1 -1
  49. package/dist/render.js +643 -555
  50. package/dist/render.js.map +4 -4
  51. package/dist/util/printf-round.d.ts +8 -0
  52. package/dist/util/printf-round.d.ts.map +1 -1
  53. package/package.json +1 -1
  54. package/src/common/clust-map.ts +58 -0
  55. package/src/common/htmltable-emit.ts +87 -7
  56. package/src/common/layers.ts +25 -4
  57. package/src/common/poly-gencode.ts +3 -11
  58. package/src/common/xlabels-place.ts +22 -4
  59. package/src/gvc/anchor.ts +18 -30
  60. package/src/gvc/device-cluster.ts +16 -0
  61. package/src/gvc/device.ts +20 -20
  62. package/src/gvc/emit-walk.ts +11 -1
  63. package/src/gvc/job.ts +17 -9
  64. package/src/gvc/viewport.ts +27 -6
  65. package/src/layout/dot/compound.ts +1 -21
  66. package/src/layout/fdp/cluster-edges.ts +2 -23
  67. package/src/model/cgraph-ops.ts +12 -0
  68. package/src/model/graph.ts +13 -2
  69. package/src/parser/builder.ts +67 -100
  70. package/src/parser/graph-attr-syms.ts +62 -0
  71. package/src/render/dot/agwrite.ts +12 -12
  72. package/src/render/dot/attrs.ts +6 -2
  73. package/src/render/json-cluster-edge.ts +8 -4
  74. package/src/render/json.ts +15 -8
  75. package/src/render/map.ts +49 -58
  76. package/src/render/svg-cluster.ts +3 -3
  77. package/src/render/svg-graph.ts +1 -3
  78. package/src/render/svg-helpers.ts +6 -6
  79. package/src/render/svg-id.ts +23 -5
  80. package/src/util/printf-round.ts +11 -0
package/dist/render.js CHANGED
@@ -367,8 +367,8 @@ var Graph = class {
367
367
  graphDefaultsSnapshot;
368
368
  /**
369
369
  * 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
370
+ * the input declaring them in this scope: every key of the snapshot the
371
+ * scope did not set (agmakeattrs). cgraph distinguishes these structurally — a seeded value is inherited
372
372
  * through the dict view and has no local symbol, while a local declaration
373
373
  * creates one even when its value equals the inherited value — so the
374
374
  * serializer needs the provenance to decide what write_dict would print.
@@ -376,6 +376,16 @@ var Graph = class {
376
376
  * @see lib/cgraph/write.c:262 write_dict
377
377
  */
378
378
  seededAttrs;
379
+ /**
380
+ * Graph-attribute keys this subgraph holds a local symbol for without having
381
+ * declared them: `unviewsubgraphsattr` gives each direct subgraph one, with
382
+ * its current value, when the parent updates its own symbol. The value is
383
+ * the `attrs` entry (absent for the empty default). A subgraph opened in
384
+ * this one later copies that value, not a nearer ancestor's newer one.
385
+ * Undefined on the root and on a subgraph that was never pinned.
386
+ * @see lib/cgraph/attr.c:232 unviewsubgraphsattr
387
+ */
388
+ pinnedAttrs;
379
389
  /**
380
390
  * Graph-attribute keys whose declaration in THIS scope was the first anywhere
381
391
  * in the graph. cgraph's `setattr` splits on exactly this: a key with no
@@ -679,22 +689,121 @@ function agGraphAttr(g, name) {
679
689
  if (own !== void 0) return own;
680
690
  return g.root.declaredGraphAttrs.has(name) ? "" : void 0;
681
691
  }
692
+ function localGraphAttrs(g) {
693
+ const local = new Map(g.attrs);
694
+ for (const key of g.seededAttrs ?? []) local.delete(key);
695
+ return local;
696
+ }
682
697
 
683
- // src/layout/fdp/cluster-edges.ts
684
- function fillMap(g, map) {
698
+ // src/common/agerr.ts
699
+ var PREFIX_ERROR = "Error";
700
+ var PREFIX_WARNING = "Warning";
701
+ var PREFIX_SEP = ": ";
702
+ var DEL = 127;
703
+ var LAST_CNTRL = 31;
704
+ var WHITESPACE = /* @__PURE__ */ new Set([9, 10, 11, 12, 13]);
705
+ var OCTAL_WIDTH = 3;
706
+ var OCTAL_RADIX = 8;
707
+ var lastLevel = "warning";
708
+ var pending = { line: null, channel: "warn" };
709
+ var usererrf = null;
710
+ registerRenderState(() => {
711
+ flushPending();
712
+ lastLevel = "warning";
713
+ });
714
+ function escapeControl(message) {
715
+ let out = "";
716
+ for (const ch of message) {
717
+ const c = ch.codePointAt(0);
718
+ if ((c <= LAST_CNTRL || c === DEL) && !WHITESPACE.has(c)) {
719
+ out += `\\${c.toString(OCTAL_RADIX).padStart(OCTAL_WIDTH, "0")}`;
720
+ } else out += ch;
721
+ }
722
+ return out;
723
+ }
724
+ function agerrLineOn(channel, line) {
725
+ flushPending();
726
+ writeLine(channel, line);
727
+ }
728
+ function flushPending() {
729
+ if (pending.line === null) return;
730
+ const { line, channel } = pending;
731
+ pending.line = null;
732
+ writeLine(channel, line);
733
+ }
734
+ function writeLine(channel, line) {
735
+ if (usererrf !== null) usererrf(`${line}
736
+ `);
737
+ else if (channel === "warn") console.warn(escapeControl(line));
738
+ else console.error(escapeControl(line));
739
+ }
740
+ function assemble(level, msg) {
741
+ if (level === "prev") return msg;
742
+ const prefix = level === "error" ? PREFIX_ERROR : PREFIX_WARNING;
743
+ return `${prefix}${PREFIX_SEP}${msg}`;
744
+ }
745
+ function outToUser(errf, level, msg) {
746
+ if (level !== "prev") {
747
+ errf(level === "error" ? PREFIX_ERROR : PREFIX_WARNING);
748
+ errf(PREFIX_SEP);
749
+ }
750
+ errf(msg);
751
+ }
752
+ function channelOf(level) {
753
+ const eff = level === "prev" ? lastLevel : level;
754
+ return eff === "warning" ? "warn" : "error";
755
+ }
756
+ function emit(level, msg, channel, hold) {
757
+ const target = channel ?? channelOf(level);
758
+ if (level !== "prev") lastLevel = level;
759
+ if (usererrf !== null) {
760
+ flushPending();
761
+ outToUser(usererrf, level, hold ? msg : `${msg}
762
+ `);
763
+ return;
764
+ }
765
+ const text = assemble(level, msg);
766
+ if (pending.line === null) {
767
+ pending.channel = target;
768
+ pending.line = text;
769
+ } else pending.line += text;
770
+ if (!hold) flushPending();
771
+ }
772
+ function agerr(level, msg, channel) {
773
+ emit(level, msg, channel, false);
774
+ }
775
+ function agerrPartial(level, msg, channel) {
776
+ emit(level, msg, channel, true);
777
+ }
778
+ var agerrorf = (msg, channel) => agerr("error", msg, channel);
779
+ var agwarningf = (msg, channel) => agerr("warning", msg, channel);
780
+ function agerrFinished(line, channel) {
781
+ agerrLineOn(channel ?? (line.startsWith(PREFIX_WARNING) ? "warn" : "error"), line);
782
+ }
783
+
784
+ // src/common/clust-map.ts
785
+ function fillMap(g, st) {
685
786
  const n = g.info.n_cluster ?? 0;
686
787
  for (let c = 0; c < n; c++) {
687
788
  const cl = g.info.clust[c];
688
789
  const s = cl.name;
689
- if (!map.has(s)) map.set(s, cl);
690
- fillMap(cl, map);
790
+ const anon = s.startsWith(LOCALNAMEPREFIX);
791
+ if (st.map.has(s) || anon && st.anonKeyed) {
792
+ agwarningf(`Two clusters named ${s} - the second will be ignored`);
793
+ } else {
794
+ st.map.set(s, cl);
795
+ if (anon) st.anonKeyed = true;
796
+ }
797
+ fillMap(cl, st);
691
798
  }
692
799
  }
693
800
  function mkClustMap(g) {
694
- const map = /* @__PURE__ */ new Map();
695
- fillMap(g, map);
696
- return map;
801
+ const st = { map: /* @__PURE__ */ new Map(), anonKeyed: false };
802
+ fillMap(g, st);
803
+ return st.map;
697
804
  }
805
+
806
+ // src/layout/fdp/cluster-edges.ts
698
807
  function mapc(cmap, n) {
699
808
  if (n.name.startsWith("cluster")) return cmap.get(n.name) ?? null;
700
809
  return null;
@@ -881,92 +990,6 @@ function bindDotRoot(g) {
881
990
  visit(g);
882
991
  }
883
992
 
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
993
  // src/xdot/types.ts
971
994
  var XDOT_PARSE_ERROR = 1;
972
995
 
@@ -1521,6 +1544,9 @@ function printfFixed(v, decimals) {
1521
1544
  const fracPart = s.slice(s.length - decimals);
1522
1545
  return sign2 + intPart + "." + fracPart;
1523
1546
  }
1547
+ function printfFixed0(v) {
1548
+ return Object.is(v, -0) ? "-0" : printfFixed(v, 0);
1549
+ }
1524
1550
  function printfSig(v, sig) {
1525
1551
  if (!Number.isFinite(v)) return printfNonFinite(v);
1526
1552
  if (v === 0) return sig > 1 ? "0." + "0".repeat(sig - 1) : "0";
@@ -11320,19 +11346,27 @@ var RenderJob = class {
11320
11346
  /** GD_fontnames of the root graph — selects which PostScript-alias fields the
11321
11347
  * SVG emitter uses. @see plugin/core/gvrender_core_svg.c:464 */
11322
11348
  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 */
11349
+ /** GD_drawing(root)->id: the root graph's `id`, substituted, '' if unset. Set
11350
+ * by render() for every renderer (drawingIdOf); the `<gid>_` prefix of
11351
+ * non-root object ids. @see lib/common/emit.c:getObjId */
11325
11352
  drawingId = "";
11326
11353
  /**
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
11354
+ * Resolve an object's id like C's getObjId. The layer half of
11355
+ * layerPagePrefix comes first (`<layer>_` after the first layer), ahead of
11356
+ * every other step. Then a non-empty DOT `id` attr wins verbatim; otherwise
11357
+ * non-root objects are prefixed with `<drawingId>_` when the root graph has
11358
+ * an id. The root's id gets the same prefix in emit_page (NotFirstPage).
11359
+ * The page half (`page<x>,<y>_`) is left out: only ps and quartz page, and
11360
+ * neither prints an id.
11361
+ * @see lib/common/emit.c:getObjId
11362
+ * @see lib/common/emit.c:layerPagePrefix
11363
+ * @see lib/common/emit.c:emit_page
11331
11364
  */
11332
11365
  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;
11366
+ const pfx = this.idLayerPrefix();
11367
+ if (idAttr !== void 0 && idAttr.length > 0) return pfx + idAttr;
11368
+ if (!isRoot && this.drawingId.length > 0) return pfx + this.drawingId + "_" + defaultId;
11369
+ return pfx + defaultId;
11336
11370
  }
11337
11371
  /** Active renderer plugin; set by render() before walkNodes. */
11338
11372
  renderer;
@@ -12986,7 +13020,7 @@ function emitHtmlCell(cell2, pos, renderer, job) {
12986
13020
  }
12987
13021
  emitCellDecoration(cell2, pos, renderer, job);
12988
13022
  if (cell2.nested !== void 0) {
12989
- emitHtmlLabel(cell2.nested, pos, renderer, job);
13023
+ emitHtmlTbl(cell2.nested, pos, renderer, job);
12990
13024
  } else if (cell2.image !== void 0) {
12991
13025
  emitHtmlImg(cell2.image, pos, renderer, job);
12992
13026
  } else {
@@ -13010,7 +13044,7 @@ function emitTableRules(placed, pos, renderer, job) {
13010
13044
  }
13011
13045
  });
13012
13046
  }
13013
- function emitHtmlLabel(placed, pos, renderer, job) {
13047
+ function emitHtmlTbl(placed, pos, renderer, job) {
13014
13048
  resetHtmlFillPenWidth();
13015
13049
  const anchorData = { href: placed.href, title: placed.title, target: placed.target, id: placed.id };
13016
13050
  const tblBox = absBox(placed.box, pos);
@@ -13041,6 +13075,40 @@ function emitHtmlLabel(placed, pos, renderer, job) {
13041
13075
  endHtmlAnchor(renderer, job);
13042
13076
  }
13043
13077
  }
13078
+ function allocObj(job, parent2) {
13079
+ const obj = createObjState(parent2.type);
13080
+ obj.parent = parent2;
13081
+ obj.penColor = parent2.penColor;
13082
+ obj.fillColor = parent2.fillColor;
13083
+ obj.pen = parent2.pen;
13084
+ obj.fill = parent2.fill;
13085
+ obj.penWidth = parent2.penWidth;
13086
+ obj.gradientAngle = parent2.gradientAngle;
13087
+ obj.stopColor = parent2.stopColor;
13088
+ obj.emitState = parent2.emitState;
13089
+ obj.graphObj = parent2.graphObj;
13090
+ obj.url = parent2.url;
13091
+ obj.tooltip = parent2.tooltip;
13092
+ obj.target = parent2.target;
13093
+ obj.explicitTooltip = parent2.explicitTooltip;
13094
+ job.pushObj(obj);
13095
+ }
13096
+ function freeObj(job) {
13097
+ job.popObj();
13098
+ }
13099
+ function emitHtmlLabel(placed, pos, renderer, job) {
13100
+ const parent2 = job.obj;
13101
+ if (parent2 === null) {
13102
+ emitHtmlTbl(placed, pos, renderer, job);
13103
+ return;
13104
+ }
13105
+ allocObj(job, parent2);
13106
+ try {
13107
+ emitHtmlTbl(placed, pos, renderer, job);
13108
+ } finally {
13109
+ freeObj(job);
13110
+ }
13111
+ }
13044
13112
 
13045
13113
  // src/common/poly-vertices.ts
13046
13114
  function ellipseVertices(w, h) {
@@ -17538,6 +17606,297 @@ function buildPoint(x, y) {
17538
17606
  return pt;
17539
17607
  }
17540
17608
 
17609
+ // src/gvc/anchor.ts
17610
+ function attr(attrs, key) {
17611
+ const v = attrs.get(key);
17612
+ return v !== void 0 && v !== "" ? v : void 0;
17613
+ }
17614
+ function subst(s, obj) {
17615
+ return substObjAnchor(s, obj);
17616
+ }
17617
+ function tip(s, obj) {
17618
+ return substObjAnchor(preprocessTooltip(s), obj);
17619
+ }
17620
+ function textOf(lp) {
17621
+ return lp?.text ?? null;
17622
+ }
17623
+ function pickFirst(attrs, keys, xform) {
17624
+ for (const k of keys) {
17625
+ const s = attr(attrs, k);
17626
+ if (s !== void 0) return { v: xform(s), explicit: true };
17627
+ }
17628
+ return { v: void 0, explicit: false };
17629
+ }
17630
+ function pickEdge(e, keys) {
17631
+ return pickFirst(e.attrs, keys, (s) => subst(s, e));
17632
+ }
17633
+ function pickEdgeTip(e, keys) {
17634
+ return pickFirst(e.attrs, keys, (s) => tip(s, e));
17635
+ }
17636
+ function withFallback(p, dflt, current) {
17637
+ return { v: p.v ?? dflt ?? current, explicit: p.explicit };
17638
+ }
17639
+ function resolveEdgeLabels(e, obj) {
17640
+ obj.label = textOf(e.info.label);
17641
+ obj.xlabel = textOf(e.info.xlabel) ?? obj.label;
17642
+ obj.tailLabel = textOf(e.info.tail_label) ?? obj.label;
17643
+ obj.headLabel = textOf(e.info.head_label) ?? obj.label;
17644
+ }
17645
+ function resolveEdgeUrls(e, obj) {
17646
+ const dflt = pickEdge(e, ["href", "URL"]).v;
17647
+ obj.url = withFallback(pickEdge(e, ["edgehref", "edgeURL"]), dflt, obj.url).v;
17648
+ obj.labelUrl = withFallback(pickEdge(e, ["labelhref", "labelURL"]), dflt, obj.labelUrl).v;
17649
+ const tail = withFallback(pickEdge(e, ["tailhref", "tailURL"]), dflt, obj.tailUrl);
17650
+ obj.tailUrl = tail.v;
17651
+ obj.explicitTailUrl = tail.explicit;
17652
+ const head = withFallback(pickEdge(e, ["headhref", "headURL"]), dflt, obj.headUrl);
17653
+ obj.headUrl = head.v;
17654
+ obj.explicitHeadUrl = head.explicit;
17655
+ }
17656
+ function resolveEdgeTargets(e, obj) {
17657
+ const dflt = pickEdge(e, ["target"]).v;
17658
+ const edge = withFallback(pickEdge(e, ["edgetarget"]), dflt, obj.target);
17659
+ obj.target = edge.v;
17660
+ obj.explicitEdgeTarget = edge.explicit;
17661
+ obj.labelTarget = withFallback(pickEdge(e, ["labeltarget"]), dflt, obj.labelTarget).v;
17662
+ const tail = withFallback(pickEdge(e, ["tailtarget"]), dflt, obj.tailTarget);
17663
+ obj.tailTarget = tail.v;
17664
+ obj.explicitTailTarget = tail.explicit;
17665
+ const head = withFallback(pickEdge(e, ["headtarget"]), dflt, obj.headTarget);
17666
+ obj.headTarget = head.v;
17667
+ obj.explicitHeadTarget = head.explicit;
17668
+ }
17669
+ function resolveEdgeTooltips(e, obj) {
17670
+ const t = withFallback(pickEdgeTip(e, ["tooltip", "edgetooltip"]), obj.label, obj.tooltip);
17671
+ obj.tooltip = t.v;
17672
+ obj.explicitTooltip = t.explicit;
17673
+ const lt = withFallback(pickEdgeTip(e, ["labeltooltip"]), obj.label, obj.labelTooltip);
17674
+ obj.labelTooltip = lt.v;
17675
+ obj.explicitLabelTooltip = lt.explicit;
17676
+ const tt = withFallback(pickEdgeTip(e, ["tailtooltip"]), obj.tailLabel, obj.tailTooltip);
17677
+ obj.tailTooltip = tt.v;
17678
+ obj.explicitTailTooltip = tt.explicit;
17679
+ const ht = withFallback(pickEdgeTip(e, ["headtooltip"]), obj.headLabel, obj.headTooltip);
17680
+ obj.headTooltip = ht.v;
17681
+ obj.explicitHeadTooltip = ht.explicit;
17682
+ }
17683
+ function resolveEdgeAnchor(e, id, obj) {
17684
+ resolveEdgeLabels(e, obj);
17685
+ resolveEdgeUrls(e, obj);
17686
+ resolveEdgeTargets(e, obj);
17687
+ resolveEdgeTooltips(e, obj);
17688
+ obj.id = subst(id, e);
17689
+ }
17690
+ function resolveObjAnchor(g, label, id, obj) {
17691
+ obj.label = label;
17692
+ const ga = (key) => {
17693
+ for (let s = g; s !== null; s = s.parent) {
17694
+ const v = attr(s.attrs, key);
17695
+ if (v !== void 0) return v;
17696
+ }
17697
+ return void 0;
17698
+ };
17699
+ const url = ga("href") ?? ga("URL");
17700
+ if (url !== void 0) obj.url = subst(url, g);
17701
+ const tt = ga("tooltip");
17702
+ if (tt !== void 0) {
17703
+ obj.tooltip = tip(tt, g);
17704
+ obj.explicitTooltip = true;
17705
+ } else if (label !== null) obj.tooltip = label;
17706
+ const tgt = ga("target");
17707
+ if (tgt !== void 0) obj.target = subst(tgt, g);
17708
+ obj.id = subst(id, g);
17709
+ }
17710
+ function openAnchorWith(renderer, job, url, tooltip, target, id) {
17711
+ renderer.beginAnchor?.(url ?? "", tooltip ?? "", target ?? "", id, job);
17712
+ }
17713
+ function beginAnchorIf(renderer, job) {
17714
+ const obj = job.obj;
17715
+ if (obj === null || obj.url === null && !obj.explicitTooltip) return false;
17716
+ openAnchorWith(renderer, job, obj.url, obj.tooltip, obj.target, obj.id ?? "");
17717
+ return true;
17718
+ }
17719
+ var DFLT_SAMPLE = 20;
17720
+ var MAP_HW = 2;
17721
+ function mapTransform(p, ctx) {
17722
+ return applyScale(p, ctx.translation.x, ctx.translation.y, ctx.scale.x, ctx.scale.y);
17723
+ }
17724
+ function nodeIsFilled(n) {
17725
+ return parseStyleFlags(nodeAttr(n, n.root, "style")).filled;
17726
+ }
17727
+ function nodeAttrSet(n, key) {
17728
+ const v = nodeAttr(n, n.root, key);
17729
+ return v !== void 0 && v !== "";
17730
+ }
17731
+ function nodeHasHotspot(n) {
17732
+ return nodeAttrSet(n, "href") || nodeAttrSet(n, "URL") || nodeAttrSet(n, "tooltip");
17733
+ }
17734
+ function isRectPoly(p) {
17735
+ return p.sides === 4 && Math.abs(p.orientation % 90) < 0.5 && p.distortion === 0 && p.skew === 0;
17736
+ }
17737
+ function samplePoints(n) {
17738
+ const s = n.attrs.get("samplepoints");
17739
+ if (s === void 0) return DFLT_SAMPLE;
17740
+ const v = parseInt(s, 10);
17741
+ return Number.isNaN(v) || v < 4 || v > 60 ? DFLT_SAMPLE : v;
17742
+ }
17743
+ function pEllipse(a, b, np) {
17744
+ const del = 2 * Math.PI / np;
17745
+ const ps = [];
17746
+ let theta = 0;
17747
+ for (let i = 0; i < np; i++) {
17748
+ ps.push({ x: a * Math.cos(theta), y: b * Math.sin(theta) });
17749
+ theta += del;
17750
+ }
17751
+ return ps;
17752
+ }
17753
+ function ellipseNodeMap(poly, coord, ur, nump) {
17754
+ if (poly.regular) {
17755
+ return { shape: 1 /* Circle */, pts: [coord, { x: coord.x + ur.x, y: coord.y + ur.y }] };
17756
+ }
17757
+ const pts = pEllipse(ur.x, ur.y, nump).map((p) => ({ x: p.x + coord.x, y: p.y + coord.y }));
17758
+ return { shape: 2 /* Polygon */, pts };
17759
+ }
17760
+ function generalNodeMap(poly, coord, vertices, peripheries, nump) {
17761
+ const offset = (peripheries - 1) * poly.sides;
17762
+ const pts = [];
17763
+ if (poly.sides >= nump) {
17764
+ const delta2 = Math.trunc(poly.sides / nump);
17765
+ for (let i = 0, j = 0; j < nump; i += delta2, j++) {
17766
+ const v = vertices[i + offset];
17767
+ pts.push({ x: coord.x + v.x, y: coord.y + v.y });
17768
+ }
17769
+ } else {
17770
+ for (let i = 0; i < poly.sides; i++) {
17771
+ const v = vertices[i + offset];
17772
+ pts.push({ x: coord.x + v.x, y: coord.y + v.y });
17773
+ }
17774
+ }
17775
+ return { shape: 2 /* Polygon */, pts };
17776
+ }
17777
+ function nodePolyMap(n, poly, coord, filled) {
17778
+ const peripheries = poly.peripheries < 2 ? 1 : poly.peripheries;
17779
+ const vertices = poly.vertices;
17780
+ const nump = samplePoints(n);
17781
+ const info = n.info;
17782
+ if (poly.peripheries === 0 && !filled) {
17783
+ return { shape: 0 /* Rectangle */, pts: [
17784
+ { x: coord.x - info.lw, y: coord.y - info.ht / 2 },
17785
+ { x: coord.x + info.lw, y: coord.y + info.ht / 2 }
17786
+ ] };
17787
+ }
17788
+ if (poly.sides < 3 && poly.skew === 0 && poly.distortion === 0) {
17789
+ return ellipseNodeMap(poly, coord, vertices[2 * peripheries - 1], nump);
17790
+ }
17791
+ return generalNodeMap(poly, coord, vertices, peripheries, nump);
17792
+ }
17793
+ function computeNodeUrlMap(n, obj, ctx) {
17794
+ if (!nodeHasHotspot(n)) return;
17795
+ const info = n.info;
17796
+ const coord = info.coord;
17797
+ const poly = info.shape_info;
17798
+ const filled = nodeIsFilled(n);
17799
+ const isRect = poly !== void 0 && isRectPoly(poly) && (poly.peripheries !== 0 || filled);
17800
+ let m;
17801
+ if (poly !== void 0 && poly.vertices != null && !isRect && ctx.mapPolygon) {
17802
+ m = nodePolyMap(n, poly, coord, filled);
17803
+ } else {
17804
+ m = { shape: 0 /* Rectangle */, pts: [
17805
+ { x: coord.x - info.lw, y: coord.y - info.ht / 2 },
17806
+ { x: coord.x + info.rw, y: coord.y + info.ht / 2 }
17807
+ ] };
17808
+ }
17809
+ obj.urlMapShape = m.shape;
17810
+ obj.urlMapPts = m.pts.map((p) => mapTransform(p, ctx));
17811
+ }
17812
+ function computeGraphUrlMap(obj, ctx) {
17813
+ const { ll, ur } = ctx.pageBox;
17814
+ obj.urlMapShape = 0 /* Rectangle */;
17815
+ obj.urlMapPts = [mapTransform(ll, ctx), mapTransform(ur, ctx)];
17816
+ }
17817
+ function computeClusterUrlMap(bb, obj, ctx) {
17818
+ obj.urlMapShape = 0 /* Rectangle */;
17819
+ obj.urlMapPts = [mapTransform(bb.ll, ctx), mapTransform(bb.ur, ctx)];
17820
+ }
17821
+ function computeLabelRectMap(lab, obj, ctx) {
17822
+ const dx = lab.dimen.x / 2;
17823
+ const dy = lab.dimen.y / 2;
17824
+ obj.urlMapShape = 0 /* Rectangle */;
17825
+ obj.urlMapPts = [
17826
+ mapTransform({ x: lab.pos.x - dx, y: lab.pos.y - dy }, ctx),
17827
+ mapTransform({ x: lab.pos.x + dx, y: lab.pos.y + dy }, ctx)
17828
+ ];
17829
+ }
17830
+ function checkControlPoints2(cp) {
17831
+ return ptToLine2(cp[0], cp[3], cp[1]) < MAP_HW * MAP_HW && ptToLine2(cp[0], cp[3], cp[2]) < MAP_HW * MAP_HW;
17832
+ }
17833
+ function bezierHalf(v) {
17834
+ const left2 = [];
17835
+ const right2 = [];
17836
+ bezier(v, 0.5, left2, right2);
17837
+ return { left: left2, right: right2 };
17838
+ }
17839
+ function approxBezier(cp, out) {
17840
+ if (checkControlPoints2(cp)) {
17841
+ if (out.length === 0) out.push(cp[0]);
17842
+ out.push(cp[3]);
17843
+ } else {
17844
+ const { left: left2, right: right2 } = bezierHalf(cp);
17845
+ approxBezier(left2, out);
17846
+ approxBezier(right2, out);
17847
+ }
17848
+ }
17849
+ function mkSegPts(prv, cur, nxt, w2) {
17850
+ let pp;
17851
+ let np;
17852
+ if (prv) {
17853
+ pp = prv;
17854
+ np = nxt ?? { x: 2 * (cur.x - pp.x), y: 2 * (cur.y - pp.y) };
17855
+ } else {
17856
+ np = nxt;
17857
+ pp = { x: 2 * (cur.x - np.x), y: 2 * (cur.y - np.y) };
17858
+ }
17859
+ const theta = Math.atan2(np.y - cur.y, np.x - cur.x);
17860
+ const phi = Math.atan2(pp.y - cur.y, pp.x - cur.x);
17861
+ let ang = theta - phi;
17862
+ if (ang > 0) ang -= 2 * Math.PI;
17863
+ const bis = phi + ang / 2;
17864
+ const del = { x: w2 * Math.cos(bis), y: w2 * Math.sin(bis) };
17865
+ return { p1: { x: cur.x + del.x, y: cur.y + del.y }, p2: { x: cur.x - del.x, y: cur.y - del.y } };
17866
+ }
17867
+ function mapOutputBspline(bp, w2, polys) {
17868
+ const nc = Math.trunc((bp.size - 1) / 3);
17869
+ const segs = [];
17870
+ for (let j = 0; j < nc; j++) {
17871
+ approxBezier([bp.list[3 * j], bp.list[3 * j + 1], bp.list[3 * j + 2], bp.list[3 * j + 3]], segs);
17872
+ }
17873
+ const pt1 = [];
17874
+ const pt2 = [];
17875
+ let cnt = 0;
17876
+ for (let i = 0; i < segs.length; i++) {
17877
+ const prev = i === 0 ? null : segs[i - 1];
17878
+ const next = i + 1 < segs.length ? segs[i + 1] : null;
17879
+ const seg2 = mkSegPts(prev, segs[i], next, w2);
17880
+ pt1[cnt] = seg2.p1;
17881
+ pt2[cnt] = seg2.p2;
17882
+ cnt++;
17883
+ if (i + 1 === segs.length || cnt === 50) {
17884
+ const poly = [];
17885
+ for (let k = 0; k < cnt; k++) poly.push(pt1[k]);
17886
+ for (let k = 0; k < cnt; k++) poly.push(pt2[cnt - 1 - k]);
17887
+ polys.push(poly);
17888
+ pt1[0] = pt1[cnt - 1];
17889
+ pt2[0] = pt2[cnt - 1];
17890
+ cnt = 1;
17891
+ }
17892
+ }
17893
+ }
17894
+ function computeEdgeSplineMaps(spl, w2, ctx) {
17895
+ const polys = [];
17896
+ for (const bz of spl.list) mapOutputBspline(bz, w2, polys);
17897
+ return polys.map((poly) => poly.map((p) => mapTransform(p, ctx)));
17898
+ }
17899
+
17541
17900
  // src/gvc/device-cluster.ts
17542
17901
  function applyClusterGradient(obj, fill) {
17543
17902
  obj.fill = fill.kind === "radial" ? 3 /* Radial */ : 2 /* Linear */;
@@ -17639,8 +17998,18 @@ function applyClusterFill(obj, fillRes) {
17639
17998
  applyClusterGradient(obj, fillRes);
17640
17999
  return true;
17641
18000
  }
18001
+ function beginClusterAnchor(sg, renderer, job) {
18002
+ const obj = job.obj;
18003
+ if (obj === null || obj.url === null && !obj.explicitTooltip) return false;
18004
+ renderer.emitMapRect?.(sg.info.bb, job);
18005
+ return beginAnchorIf(renderer, job);
18006
+ }
17642
18007
 
17643
18008
  // src/render/svg-id.ts
18009
+ function drawingIdOf(g) {
18010
+ const id = g.attrs.get("id");
18011
+ return id !== void 0 && id.length > 0 ? substObjAnchor(id, g) : "";
18012
+ }
17644
18013
  function svgClass(kind, classAttr) {
17645
18014
  return classAttr !== void 0 && classAttr.length > 0 ? 'class="' + kind + " " + escapeXmlTitle(classAttr) + '"' : 'class="' + kind + '"';
17646
18015
  }
@@ -17918,19 +18287,11 @@ function polyGencode(rawJob, rawNode) {
17918
18287
  const ctx = resolveNodeDrawCtx(job, n);
17919
18288
  if (ctx === null) return;
17920
18289
  const clustersLast = (job.flags & EMIT_CLUSTERS_LAST) !== 0;
17921
- const savedShape = job.obj?.urlMapShape;
17922
- const savedPts = job.obj?.urlMapPts;
17923
18290
  let inAnchor = clustersLast ? false : beginNodeAnchor(n, renderer, job);
17924
18291
  renderPeripheries(ctx.poly, ctx.coord, ctx.filled, ctx.ringCtx);
17925
18292
  if (!isPointNode(n)) renderUsershape(n, ctx);
17926
18293
  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
- }
18294
+ if (clustersLast) inAnchor = beginNodeAnchor(n, renderer, job);
17934
18295
  if (inAnchor) renderer.endAnchor?.(job);
17935
18296
  }
17936
18297
 
@@ -21407,7 +21768,6 @@ function svgBeginGraph(g, job) {
21407
21768
  job.devscale = { x: 1, y: -1 };
21408
21769
  job.directed = g.kind === "directed" || g.kind === "strict-directed";
21409
21770
  job.fontnames = g.info.fontnames ?? FontnameKind.NativeFonts;
21410
- job.drawingId = g.attrs.get("id") ?? "";
21411
21771
  job.write(SVG_XML_DECL);
21412
21772
  const stylesheet = g.attrs.get("stylesheet");
21413
21773
  if (stylesheet !== void 0 && stylesheet.length > 0) {
@@ -21433,7 +21793,7 @@ function svgBeginPage(g, job) {
21433
21793
  const tx = job.rotation !== 0 ? -clip.ur.x - job.margin.x / z : -clip.ll.x + job.margin.x / z;
21434
21794
  const ty = clip.ur.y + job.margin.y / z;
21435
21795
  emitGraphGroupOpen(
21436
- job.idLayerPrefix() + svgGraphId(g, job),
21796
+ svgGraphId(g, job),
21437
21797
  svgGraphClass(g),
21438
21798
  tx,
21439
21799
  ty,
@@ -21639,7 +21999,7 @@ function textAnchor(just) {
21639
21999
  return "middle";
21640
22000
  }
21641
22001
  function svgBeginNode(n, job) {
21642
- job.write('<g id="' + escapeXmlTitle(job.idLayerPrefix() + svgNodeId(n, job) + job.idLayerSuffix()) + '" ' + svgNodeClass(n) + ">\n");
22002
+ job.write('<g id="' + escapeXmlTitle(svgNodeId(n, job) + job.idLayerSuffix()) + '" ' + svgNodeClass(n) + ">\n");
21643
22003
  job.write("<title>" + escapeXmlTitle(n.name) + "</title>\n");
21644
22004
  }
21645
22005
  function svgEndNode(job) {
@@ -21653,7 +22013,7 @@ function svgBeginEdge(e, job) {
21653
22013
  const tp = e.info.tail_port?.name;
21654
22014
  const hp = e.info.head_port?.name;
21655
22015
  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");
22016
+ job.write('<g id="' + escapeXmlTitle(svgEdgeId(e, job)) + '" ' + svgEdgeClass(e) + ">\n");
21657
22017
  job.write("<title>" + escapeEdgeTitle(raw) + "</title>\n");
21658
22018
  }
21659
22019
  function svgEndEdge(job) {
@@ -21934,318 +22294,27 @@ function initJobViewportZoom(bb, size, pad) {
21934
22294
  return 1;
21935
22295
  }
21936
22296
  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
22297
  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 };
22298
+ const pageSize = setupPageSize(bb, size, pad, z);
21946
22299
  const ll = {
21947
22300
  x: focus.x + pageSize.x * (0 - 1 / 2),
21948
22301
  y: focus.y + pageSize.y * (0 - 1 / 2)
21949
22302
  };
21950
22303
  return { ll, ur: { x: ll.x + pageSize.x, y: ll.y + pageSize.y } };
21951
22304
  }
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
- }
22305
+ function setupPageSize(bb, size, pad, z) {
22306
+ const jbLL = { x: bb.ll.x - pad.x, y: bb.ll.y - pad.y };
22307
+ const jbUR = { x: bb.ur.x + pad.x, y: bb.ur.y + pad.y };
22308
+ const sz = { x: jbUR.x - jbLL.x, y: jbUR.y - jbLL.y };
22309
+ if (size !== null && size.x > 1e-3 && size.y > 1e-3) {
22310
+ if (sz.x <= 1e-3) sz.x = size.x;
22311
+ if (sz.y <= 1e-3) sz.y = size.y;
22243
22312
  }
22313
+ return { x: z * sz.x / z, y: z * sz.y / z };
22244
22314
  }
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)));
22315
+ function setupPageBox(pageSize, pad) {
22316
+ const ll = { x: 0 * pageSize.x - pad.x, y: 0 * pageSize.y - pad.y };
22317
+ return { ll, ur: { x: ll.x + pageSize.x, y: ll.y + pageSize.y } };
22249
22318
  }
22250
22319
 
22251
22320
  // src/common/layers.ts
@@ -22324,6 +22393,16 @@ function edgeInLayer(info, layerNum, e) {
22324
22393
  return pn === "" || selectedLayer(info, layerNum, pn);
22325
22394
  });
22326
22395
  }
22396
+ function clustInLayer(info, layerNum, sg) {
22397
+ if (info.numLayers <= 1) return true;
22398
+ const pg = graphAttrInherited(sg, "layer") ?? "";
22399
+ if (selectedLayer(info, layerNum, pg)) return true;
22400
+ if (pg !== "") return false;
22401
+ for (const n of sg.nodes.values()) {
22402
+ if (nodeInLayer(info, layerNum, n, sg)) return true;
22403
+ }
22404
+ return false;
22405
+ }
22327
22406
  function parseLayerselect(info, p) {
22328
22407
  const picked = [];
22329
22408
  for (let i = 1; i <= info.numLayers; i++) {
@@ -22345,6 +22424,9 @@ function nodeShown(info, job, n, g) {
22345
22424
  function edgeShown(info, job, e) {
22346
22425
  return info === void 0 || job.numLayers <= 1 || edgeInLayer(info, job.layerNum, e);
22347
22426
  }
22427
+ function clusterShown(info, job, sg) {
22428
+ return info === void 0 || job.numLayers <= 1 || clustInLayer(info, job.layerNum, sg);
22429
+ }
22348
22430
  function chkOrder(g) {
22349
22431
  const p = g.attrs.get("outputorder");
22350
22432
  if (p === "nodesfirst") return "nodesfirst";
@@ -22852,20 +22934,19 @@ function drawClusterInScheme(sg, renderer, job) {
22852
22934
  renderer.beginCluster?.(sg, job);
22853
22935
  if (job.obj !== null) job.obj.id = svgClusterId(sg, job);
22854
22936
  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);
22937
+ if (job.obj !== null) resolveObjAnchor(sg, labelTextOf2(sg.info.label), svgClusterId(sg, job), job.obj);
22938
+ const late = (job.flags & EMIT_CLUSTERS_LAST) !== 0;
22939
+ const anchored = !late && beginClusterAnchor(sg, renderer, job);
22859
22940
  if ((clusterPeripheries(sg) !== 0 || filled || isStripedCluster(sg)) && job.obj?.pen !== 0 /* None */) {
22860
22941
  renderClusterBox(sg, filled, renderer, job);
22861
22942
  }
22862
22943
  renderClusterLabel(sg, renderer, job);
22863
- if (anchored) renderer.endAnchor?.(job);
22944
+ if (anchored || late && beginClusterAnchor(sg, renderer, job)) renderer.endAnchor?.(job);
22864
22945
  renderer.endCluster?.(sg, job);
22865
22946
  }
22866
- function renderOneCluster(sg, renderer, job) {
22947
+ function renderOneCluster(sg, renderer, job, info) {
22867
22948
  const clustersLast = (job.flags & EMIT_CLUSTERS_LAST) !== 0;
22868
- if (clustersLast) renderClusters(sg, renderer, job);
22949
+ if (clustersLast) renderClusters(sg, renderer, job, info);
22869
22950
  const obj = createObjState(1 /* Cluster */);
22870
22951
  obj.emitState = 1 /* CDraw */;
22871
22952
  job.pushObj(obj);
@@ -22874,15 +22955,15 @@ function renderOneCluster(sg, renderer, job) {
22874
22955
  } finally {
22875
22956
  job.popObj();
22876
22957
  }
22877
- if (!clustersLast) renderClusters(sg, renderer, job);
22958
+ if (!clustersLast) renderClusters(sg, renderer, job, info);
22878
22959
  }
22879
- function renderClusters(g, renderer, job) {
22960
+ function renderClusters(g, renderer, job, info) {
22880
22961
  const nClust = g.info.n_cluster ?? 0;
22881
22962
  const clust = g.info.clust;
22882
22963
  if (nClust === 0 || !clust) return;
22883
22964
  for (let c = 0; c < nClust; c++) {
22884
22965
  const sg = clust[c];
22885
- if (sg) renderOneCluster(sg, renderer, job);
22966
+ if (sg && clusterShown(info, job, sg)) renderOneCluster(sg, renderer, job, info);
22886
22967
  }
22887
22968
  }
22888
22969
  function renderGraph(g, job, renderer) {
@@ -22921,9 +23002,9 @@ function renderPage(g, renderer, job, info) {
22921
23002
  });
22922
23003
  if (anchored) renderer.endAnchor?.(job);
22923
23004
  const clustersLast = (job.flags & EMIT_CLUSTERS_LAST) !== 0;
22924
- if (!clustersLast) renderClusters(g, renderer, job);
23005
+ if (!clustersLast) renderClusters(g, renderer, job, info);
22925
23006
  walkNodesAndEdges(g, renderer, job, info);
22926
- if (clustersLast) renderClusters(g, renderer, job);
23007
+ if (clustersLast) renderClusters(g, renderer, job, info);
22927
23008
  renderer.endPage?.(g, job);
22928
23009
  }
22929
23010
  function newRenderJob(ctx, format, inlineImages) {
@@ -22956,6 +23037,7 @@ function render(ctx, g, format, inlineImages = false) {
22956
23037
  job.scale = { x: z * dpiScale, y: z * dpiScale };
22957
23038
  job.rotation = parseLandscape(g) ? 90 : 0;
22958
23039
  job.renderer = renderer;
23040
+ job.drawingId = drawingIdOf(g);
22959
23041
  setRendererKnownColors(renderer.type === "svg");
22960
23042
  resetHtmlAnchorIds();
22961
23043
  for (const n of g.nodes.values()) polyInit(n, g, job.measurer);
@@ -32881,16 +32963,13 @@ function cmapxShape(shape) {
32881
32963
  return "poly";
32882
32964
  }
32883
32965
  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));
32966
+ return printfFixed0(pts[0].x) + "," + printfFixed0(pts[1].y) + "," + printfFixed0(pts[1].x) + "," + printfFixed0(pts[0].y);
32885
32967
  }
32886
32968
  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);
32969
+ return printfFixed0(pts[0].x) + "," + printfFixed0(pts[0].y) + "," + printfFixed0(pts[1].x - pts[0].x);
32891
32970
  }
32892
32971
  function cmapxCoordsPoly(pts) {
32893
- return pts.map((p) => String(Math.round(p.x)) + "," + String(Math.round(p.y))).join(",");
32972
+ return pts.map((p) => printfFixed0(p.x) + "," + printfFixed0(p.y)).join(",");
32894
32973
  }
32895
32974
  function cmapxCoords(shape, pts) {
32896
32975
  if (shape === 1 /* Circle */) return cmapxCoordsCircle(pts);
@@ -32913,12 +32992,11 @@ function mapOutputCmapx(shape, pts, a, isXml, out) {
32913
32992
  function mapOutputImap(shape, pts, url, out) {
32914
32993
  if (!url) return;
32915
32994
  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");
32995
+ out.push("rect " + url + " " + printfFixed0(pts[0].x) + "," + printfFixed0(pts[1].y) + " " + printfFixed0(pts[1].x) + "," + printfFixed0(pts[0].y) + "\n");
32917
32996
  } 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");
32997
+ out.push("circle " + url + " " + printfFixed0(pts[0].x) + "," + printfFixed0(pts[0].y) + "," + printfFixed0(pts[1].x - pts[0].x) + "\n");
32920
32998
  } else {
32921
- const pairs = pts.map((p) => Math.round(p.x) + "," + Math.round(p.y)).join(" ");
32999
+ const pairs = pts.map((p) => printfFixed0(p.x) + "," + printfFixed0(p.y)).join(" ");
32922
33000
  out.push("poly " + url + " " + pairs + "\n");
32923
33001
  }
32924
33002
  }
@@ -32996,11 +33074,13 @@ function graphMapUrl(g) {
32996
33074
  }
32997
33075
  function buildMapCtx(g, job, mapPolygon) {
32998
33076
  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 };
33077
+ const devscale = (drawingDpi > 0 ? drawingDpi : 96) / POINTS_PER_INCH2;
33078
+ const size = parseDrawingSize(g.attrs.get("size"));
33079
+ const z = initJobViewportZoom(job.bb, size, job.pad);
33080
+ const clip = setupPageClip(job.bb, size, job.pad, z);
33081
+ const pageBox = setupPageBox(setupPageSize(job.bb, size, job.pad, z), job.pad);
33082
+ const translation = { x: -clip.ll.x + job.margin.x / z, y: -clip.ur.y - job.margin.y / z };
33083
+ return { pageBox, translation, scale: { x: z * devscale, y: z * -devscale }, mapPolygon };
33004
33084
  }
33005
33085
  function anchorOf(url, tooltip, target, id) {
33006
33086
  return { url: url ?? "", tooltip: tooltip ?? "", target: target ?? "", id: id ?? "" };
@@ -33035,12 +33115,6 @@ var MapRendererBase = class {
33035
33115
  beginNode(n, job) {
33036
33116
  if (this.mapCtx !== null && job.obj !== null) computeNodeUrlMap(n, job.obj, this.mapCtx);
33037
33117
  }
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
33118
  endEdge(e, job) {
33045
33119
  if (this.mapCtx !== null && job.obj !== null) this.emitEdge(e, job.obj, job);
33046
33120
  }
@@ -33095,30 +33169,34 @@ var MapRendererBase = class {
33095
33169
  url: obj.labelUrl,
33096
33170
  tooltip: obj.labelTooltip,
33097
33171
  target: obj.labelTarget,
33098
- explicit: obj.explicitLabelTooltip
33172
+ explicit: obj.explicitLabelTooltip,
33173
+ suffix: "label"
33099
33174
  };
33100
33175
  this.emitEdgeLabel(e.info.label, centerA, obj, job);
33101
33176
  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 */
33177
+ this.emitEdgeLabel(e.info.head_label, {
33178
+ url: obj.headUrl,
33179
+ tooltip: obj.headTooltip,
33180
+ target: obj.headTarget,
33181
+ explicit: obj.explicitHeadTooltip,
33182
+ suffix: "headlabel"
33183
+ }, obj, job);
33184
+ this.emitEdgeLabel(e.info.tail_label, {
33185
+ url: obj.tailUrl,
33186
+ tooltip: obj.tailTooltip,
33187
+ target: obj.tailTarget,
33188
+ explicit: obj.explicitTailTooltip,
33189
+ suffix: "taillabel"
33190
+ }, obj, job);
33191
+ }
33192
+ /** One edge label hot spot (map_label rect), if placed and url/explicit-tip; its id is
33193
+ * `<obj.id>-<suffix>` (C: `if (id)`, else NULL). @see lib/common/emit.c:emit_edge_label (2851-2876) */
33117
33194
  emitEdgeLabel(lab, la, obj, job) {
33118
33195
  const placed = lab !== void 0 && lab.set && this.mapCtx !== null;
33119
33196
  if (!placed || la.url === null && !la.explicit) return;
33120
33197
  computeLabelRectMap(lab, obj, this.mapCtx);
33121
- this.emitShape(0 /* Rectangle */, obj.urlMapPts, anchorOf(la.url, la.tooltip, la.target, obj.id), job);
33198
+ const id = obj.id === null ? null : `${obj.id}-${la.suffix}`;
33199
+ this.emitShape(0 /* Rectangle */, obj.urlMapPts, anchorOf(la.url, la.tooltip, la.target, id), job);
33122
33200
  }
33123
33201
  };
33124
33202
  var ImapRenderer = class extends MapRendererBase {
@@ -35893,15 +35971,18 @@ function buildArrays(gp, nObjs, nLbls, nClbls, et) {
35893
35971
  return { ctx };
35894
35972
  }
35895
35973
  function writeBackLabels(gp, lbls, nLbls) {
35974
+ let cnt = 0;
35896
35975
  for (let i = 0; i < nLbls; i++) {
35897
35976
  const xlp = lbls[i];
35898
35977
  if (xlp.set) {
35978
+ cnt++;
35899
35979
  const lp = xlp.lbl;
35900
35980
  lp.set = true;
35901
35981
  lp.pos = centerPt(xlp);
35902
35982
  updateBBForLabel(gp, lp);
35903
35983
  }
35904
35984
  }
35985
+ return cnt;
35905
35986
  }
35906
35987
  var XLABEL_WORK_MASK = NODE_XLABEL | EDGE_XLABEL | TAIL_LABEL | HEAD_LABEL;
35907
35988
  function needsXLabelWork(gp) {
@@ -35922,7 +36003,10 @@ function runPlacement(gp) {
35922
36003
  const force = forceStr === void 0 ? true : mapbool(forceStr);
35923
36004
  const params = { bb: { ll: ctx.bb.ll, ur: ctx.bb.ur }, force };
35924
36005
  placeLabels(ctx.objs, ctx.lbls, params);
35925
- writeBackLabels(gp, ctx.lbls, nLbls);
36006
+ const cnt = writeBackLabels(gp, ctx.lbls, nLbls);
36007
+ if (cnt !== nLbls) {
36008
+ agwarningf(`${cnt} out of ${nLbls} exterior labels positioned.`);
36009
+ }
35926
36010
  }
35927
36011
  function addXLabels(gp) {
35928
36012
  if (!needsXLabelWork(gp)) return;
@@ -37857,19 +37941,6 @@ function boxIntersectf(pp, cp, bb) {
37857
37941
  }
37858
37942
 
37859
37943
  // 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
37944
  function arrowEndClipIdx(state3, endp) {
37874
37945
  const { e, bez } = state3;
37875
37946
  const elen = arrowClipLength(edgeArrowName(e, "head"), edgeArrowsize(e), edgePenwidthAttr(e));
@@ -38020,7 +38091,7 @@ function makeCompoundEdge(e, clustMap) {
38020
38091
  if (tailClipped && bez.sflag) restashArrow(e, bez.sp, bez.list[0], true);
38021
38092
  }
38022
38093
  function dotCompoundEdges(g) {
38023
- const clustMap = mkClustMap2(g);
38094
+ const clustMap = mkClustMap(g);
38024
38095
  for (const e of g.edges) makeCompoundEdge(e, clustMap);
38025
38096
  }
38026
38097
 
@@ -56084,7 +56155,7 @@ function emitAttachment(lp, spl, renderer, job) {
56084
56155
 
56085
56156
  // src/render/svg-cluster.ts
56086
56157
  function svgBeginCluster(sg, job) {
56087
- job.write('<g id="' + escapeXmlTitle(job.idLayerPrefix() + svgClusterId(sg, job)) + '" ' + svgClusterClass(sg) + ">\n");
56158
+ job.write('<g id="' + escapeXmlTitle(svgClusterId(sg, job)) + '" ' + svgClusterClass(sg) + ">\n");
56088
56159
  job.write("<title>" + escapeXmlTitle(sg.name) + "</title>\n");
56089
56160
  }
56090
56161
  function svgEndCluster(job) {
@@ -56463,6 +56534,7 @@ function writeDictSkips(v, inherited) {
56463
56534
  function echoGraphAttr(g, key) {
56464
56535
  const v = g.attrs.get(key);
56465
56536
  if (v === void 0) return [];
56537
+ if (g.seededAttrs?.has(key) === true) return [];
56466
56538
  if (writeDictSkips(v, g.graphDefaultsSnapshot?.get(key))) return [];
56467
56539
  return [`${key}=${agstrcanon(v)}`];
56468
56540
  }
@@ -56508,7 +56580,7 @@ function isDirected(g) {
56508
56580
 
56509
56581
  // src/render/dot/agwrite.ts
56510
56582
  var DotWriterBase = class {
56511
- /** Clusters in render order (GD_clust); filled by the renderer's endCluster. */
56583
+ /** The clusters xdot_end_cluster ran for (not all of GD_clust: inClusterTree). */
56512
56584
  clusters = [];
56513
56585
  /**
56514
56586
  * Emit `key=<canon value>` through `_agstrcanon`, as `agwrite` does for the xdot
@@ -56575,7 +56647,7 @@ var DotWriterBase = class {
56575
56647
  * a boxed graph and an unboxed child — the driver that makes an anon subgraph
56576
56648
  * under the root or a cluster "relevant". @see lib/common/output.c:safe_dcl */
56577
56649
  hasBb(g) {
56578
- return g === g.root || this.clusters.includes(g);
56650
+ return g === g.root || inClusterTree(g);
56579
56651
  }
56580
56652
  /** Anonymous subgraph with no own node/edge defaults and no graph attrs
56581
56653
  * differing from its parent → inlined into the parent. Native compares every
@@ -56583,7 +56655,7 @@ var DotWriterBase = class {
56583
56655
  * the parent, empty on the child) and `rank`. @see write.c:irrelevant_subgraph */
56584
56656
  irrelevantSubgraph(g) {
56585
56657
  if (!this.isAnonymous(g)) return false;
56586
- if (this.clusters.includes(g)) return false;
56658
+ if (inClusterTree(g)) return false;
56587
56659
  if (g.nodeDefaults.size > 0 || g.edgeDefaults.size > 0) return false;
56588
56660
  if (g.parent) {
56589
56661
  if (this.hasBb(g) !== this.hasBb(g.parent)) return false;
@@ -56601,9 +56673,8 @@ var DotWriterBase = class {
56601
56673
  * `rec_attach_bb` walks the ROOT and then `GD_clust` recursively, so a
56602
56674
  * subgraph the layout did not box is attached NEITHER `bb` NOR the label
56603
56675
  * 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`.
56676
+ * twopi lay out no clusters (`GD_clust` empty, `inClusterTree` false), so on a
56677
+ * re-fed dot output `cluster0` carries the *previous* run's `bb` and `lp`.
56607
56678
  * @see lib/common/output.c:249 rec_attach_bb */
56608
56679
  subgGraphAttrs(sg) {
56609
56680
  const parts = [];
@@ -56635,7 +56706,7 @@ var DotWriterBase = class {
56635
56706
  * order. @see lib/cgraph/write.c:307 write_dicts
56636
56707
  */
56637
56708
  writeDicts(g, top, ctx) {
56638
- const graphParts = top ? this.graphAttrs(g) : this.clusters.includes(g) ? this.clusterAttrs(g) : this.subgGraphAttrs(g);
56709
+ const graphParts = top ? this.graphAttrs(g) : inClusterTree(g) ? this.clusterAttrs(g) : this.subgGraphAttrs(g);
56639
56710
  this.writeDict("graph", graphParts, ctx);
56640
56711
  this.writeDict("node", nodeDictParts(g, top), ctx);
56641
56712
  this.writeDict("edge", dictParts(g.edgeDefaults), ctx);
@@ -56816,13 +56887,14 @@ var DotWriterBase = class {
56816
56887
  parts.push(...graphInputParts(g, true, this.emitDraws));
56817
56888
  return parts;
56818
56889
  }
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.
56890
+ /** Cluster attribute block. C's xdot_end_cluster ALWAYS agsets `_draw_` for a
56891
+ * cluster it ran for (even empty, e.g. peripheries=0); one that emit_clusters
56892
+ * skipped (clust_in_layer) keeps only a stored one. `_ldraw_` only with a label.
56822
56893
  * @see plugin/core/gvrender_core_dot.c:284 xdot_end_cluster */
56823
56894
  clusterAttrs(sg) {
56824
56895
  const d = this.drawsOf(sg);
56825
- const parts = this.emitDraws || d?.draw ? [this.drawAttr("_draw_", d?.draw ?? "")] : [];
56896
+ const drawn = this.emitDraws && this.clusters.includes(sg);
56897
+ const parts = drawn || d?.draw ? [this.drawAttr("_draw_", d?.draw ?? "")] : [];
56826
56898
  if (d?.ldraw) parts.push(this.drawAttr("_ldraw_", d.ldraw));
56827
56899
  if (sg.info.bb) parts.push('bb="' + this.bbStr(sg) + '"');
56828
56900
  parts.push(...graphLabelAttrs(sg));
@@ -61218,6 +61290,35 @@ function peg$parse(input, options) {
61218
61290
  }
61219
61291
  }
61220
61292
 
61293
+ // src/parser/graph-attr-syms.ts
61294
+ function hasLocalGraphSym(g, key) {
61295
+ if (g.parent === null) return g.declaredGraphAttrs.has(key);
61296
+ if (g.pinnedAttrs?.has(key) === true) return true;
61297
+ return g.attrs.has(key) && g.seededAttrs?.has(key) !== true;
61298
+ }
61299
+ function pinSubgraphsAttr(parent2, key) {
61300
+ for (const sub of parent2.subgraphs.values()) {
61301
+ if (!hasLocalGraphSym(sub, key)) (sub.pinnedAttrs ??= /* @__PURE__ */ new Set()).add(key);
61302
+ }
61303
+ }
61304
+ function effectiveGraphDefaults(scope) {
61305
+ const eff = /* @__PURE__ */ new Map();
61306
+ const found = /* @__PURE__ */ new Set();
61307
+ const take = (g, key) => {
61308
+ if (found.has(key)) return;
61309
+ found.add(key);
61310
+ const v = g.attrs.get(key);
61311
+ if (v !== void 0) eff.set(key, v);
61312
+ };
61313
+ for (let g = scope; g !== null; g = g.parent) {
61314
+ for (const key of g.attrs.keys()) {
61315
+ if (g.seededAttrs?.has(key) !== true) take(g, key);
61316
+ }
61317
+ for (const key of g.pinnedAttrs ?? []) take(g, key);
61318
+ }
61319
+ return eff;
61320
+ }
61321
+
61221
61322
  // src/parser/builder.ts
61222
61323
  function normaliseAttrValue(value) {
61223
61324
  return value;
@@ -61242,16 +61343,6 @@ function effectiveNodeDefaults2(scope) {
61242
61343
  }
61243
61344
  return eff;
61244
61345
  }
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
61346
  var NodeRegistry = class {
61256
61347
  nextId = 0;
61257
61348
  reset() {
@@ -61266,29 +61357,6 @@ var NodeRegistry = class {
61266
61357
  return node;
61267
61358
  }
61268
61359
  };
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
61360
  var StmtProcessor = class _StmtProcessor {
61293
61361
  constructor(registry) {
61294
61362
  this.registry = registry;
@@ -61357,22 +61425,32 @@ var StmtProcessor = class _StmtProcessor {
61357
61425
  this.anonCounter++;
61358
61426
  }
61359
61427
  processAssign(stmt, graph) {
61360
- graph.attrs.set(stmt.key, normaliseAttrValue(stmt.value));
61361
61428
  this.declareGraphAttr(graph, stmt.key);
61429
+ graph.attrs.set(stmt.key, normaliseAttrValue(stmt.value));
61362
61430
  }
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 */
61431
+ /** Record a graph-attribute declaration, BEFORE its value is stored, noting
61432
+ * whether THIS scope was the first to declare the key anywhere — the branch
61433
+ * selector in cgraph's setattr. @see model/graph.ts firstGraphDecl
61434
+ * A scope that already holds a symbol for the key (the root always; the
61435
+ * first declarer, through bindattrs' empty declaration) updates it, which
61436
+ * first pins its direct subgraphs; a new local definition pins nothing.
61437
+ * A key declared in a re-opened subgraph's later body gets a local symbol,
61438
+ * so it is no longer a seeded one. @see lib/cgraph/attr.c:setattr */
61366
61439
  declareGraphAttr(graph, key) {
61367
- if (!graph.root.declaredGraphAttrs.has(key)) {
61440
+ const first = !graph.root.declaredGraphAttrs.has(key);
61441
+ if (first) {
61368
61442
  (graph.firstGraphDecl ??= /* @__PURE__ */ new Set()).add(key);
61369
61443
  graph.root.declaredGraphAttrs.add(key);
61370
61444
  }
61445
+ if (first || hasLocalGraphSym(graph, key)) pinSubgraphsAttr(graph, key);
61446
+ graph.seededAttrs?.delete(key);
61371
61447
  }
61372
61448
  processAttr(stmt, graph) {
61373
61449
  if (stmt.target === "graph") {
61374
- applyAttrs(stmt.attrs, graph.attrs);
61375
- for (const a of stmt.attrs) this.declareGraphAttr(graph, a.key);
61450
+ for (const a of stmt.attrs) {
61451
+ this.declareGraphAttr(graph, a.key);
61452
+ applyAttrs([a], graph.attrs);
61453
+ }
61376
61454
  } else if (stmt.target === "node") {
61377
61455
  applyAttrs(stmt.attrs, graph.nodeDefaults);
61378
61456
  } else {
@@ -61387,10 +61465,14 @@ var StmtProcessor = class _StmtProcessor {
61387
61465
  }
61388
61466
  }
61389
61467
  processEdgeStmt(stmt, graph, root, directed) {
61390
- const ends = stmt.nodes.map((item) => ({
61391
- nodes: this.resolveEndpoint(item, root, graph, directed),
61468
+ const refs = stmt.nodes.map((item) => ({
61469
+ ref: this.resolveEndpoint(item, root, graph, directed),
61392
61470
  port: portStringOf(item)
61393
61471
  }));
61472
+ const ends = refs.map(({ ref, port }) => ({
61473
+ nodes: ref instanceof Graph ? [...ref.nodes.values()].sort((a, b) => a.id - b.id) : ref,
61474
+ port
61475
+ }));
61394
61476
  for (let i = 0; i < ends.length - 1; i++) {
61395
61477
  this.connectEndpoints(ends[i], ends[i + 1], stmt.attrs, graph, root);
61396
61478
  }
@@ -61398,16 +61480,18 @@ var StmtProcessor = class _StmtProcessor {
61398
61480
  processSubgraph(stmt, graph, root, directed) {
61399
61481
  const sgName = stmt.id ?? `%${this.nextAnonId()}`;
61400
61482
  const prior2 = graph.subgraphs.get(sgName);
61483
+ if (prior2 !== void 0) {
61484
+ buildGraph(stmt.stmts, prior2, root, directed, this);
61485
+ return prior2;
61486
+ }
61401
61487
  const sg = new Graph(sgName, graph.kind);
61402
61488
  sg.parent = graph;
61403
61489
  sg.root = root;
61404
- if (prior2 !== void 0) sg.seq = prior2.seq;
61405
- else assignSubgSeq(graph, sg);
61490
+ assignSubgSeq(graph, sg);
61406
61491
  sg.graphDefaultsSnapshot = effectiveGraphDefaults(graph);
61407
61492
  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)) {
61493
+ for (const [key, v] of sg.graphDefaultsSnapshot) {
61494
+ if (!sg.attrs.has(key)) {
61411
61495
  sg.attrs.set(key, v);
61412
61496
  (sg.seededAttrs ??= /* @__PURE__ */ new Set()).add(key);
61413
61497
  }
@@ -61448,12 +61532,11 @@ var StmtProcessor = class _StmtProcessor {
61448
61532
  }
61449
61533
  }
61450
61534
  }
61535
+ /** One endpoint of an edge statement: a node item's node, or a subgraph
61536
+ * item's subgraph, which the caller expands after the whole statement. */
61451
61537
  resolveEndpoint(item, root, scope, directed) {
61452
61538
  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);
61539
+ return this.processSubgraph(item, scope, root, directed);
61457
61540
  }
61458
61541
  return [this.registry.ensure(item.id, root, scope)];
61459
61542
  }
@@ -62127,7 +62210,7 @@ function collectDrawLookup(g) {
62127
62210
  for (const [nm, gChild] of gSub.subgraphs) {
62128
62211
  const xgChild = xgSub.subgraphs.get(nm);
62129
62212
  if (xgChild !== void 0) {
62130
- cluster.set(gChild, new Map(xgChild.attrs));
62213
+ cluster.set(gChild, localGraphAttrs(xgChild));
62131
62214
  correlate(gChild, xgChild);
62132
62215
  } else {
62133
62216
  correlate(gChild, xgSub);
@@ -62307,7 +62390,7 @@ function buildEdgesArray(g, ctx) {
62307
62390
  }
62308
62391
  function buildGraphObject(g, top, ctx) {
62309
62392
  const o = {};
62310
- o.name = g.name;
62393
+ o.name = agNameOf(g);
62311
62394
  if (top) {
62312
62395
  o.directed = g.kind === "directed" || g.kind === "strict-directed";
62313
62396
  o.strict = g.kind === "strict-directed" || g.kind === "strict-undirected";
@@ -62383,11 +62466,16 @@ var Json0Renderer = class extends JsonRendererBase {
62383
62466
  type = "json0";
62384
62467
  beginGraph(_g, _job) {
62385
62468
  }
62386
- /** C's json_begin_graph runs attach_attrs; buildJson overlays the same values. */
62469
+ /**
62470
+ * Attach, then write: C's json_begin_graph runs attach_attrs (which ends by
62471
+ * undoing cluster edges) before json_end_graph writes, and json0 prints what
62472
+ * that stored. Nothing overlays `bb` or an edge's `pos` here, as json's xdot
62473
+ * draw lookup does, so the write-back cannot wait until after the write.
62474
+ * @see plugin/core/gvrender_core_json.c:json_begin_graph
62475
+ */
62387
62476
  endGraph(g, job) {
62388
- const later = attachBeforeWriteWithClusterEdges(g, () => attachAttrs(g));
62477
+ attachBeforeWriteWithClusterEdges(g, () => attachAttrs(g))();
62389
62478
  job.write(buildJson(g, false));
62390
- later();
62391
62479
  }
62392
62480
  };
62393
62481
  var JsonRenderer = class extends JsonRendererBase {