@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/index.js CHANGED
@@ -3656,8 +3656,8 @@ var Graph = class {
3656
3656
  graphDefaultsSnapshot;
3657
3657
  /**
3658
3658
  * Keys in `attrs` the BUILDER seeded from `graphDefaultsSnapshot` rather than
3659
- * the input declaring them in this scope (see builder.ts GRAPH_LABEL_INHERIT_
3660
- * KEYS). cgraph distinguishes these structurally — a seeded value is inherited
3659
+ * the input declaring them in this scope: every key of the snapshot the
3660
+ * scope did not set (agmakeattrs). cgraph distinguishes these structurally — a seeded value is inherited
3661
3661
  * through the dict view and has no local symbol, while a local declaration
3662
3662
  * creates one even when its value equals the inherited value — so the
3663
3663
  * serializer needs the provenance to decide what write_dict would print.
@@ -3665,6 +3665,16 @@ var Graph = class {
3665
3665
  * @see lib/cgraph/write.c:262 write_dict
3666
3666
  */
3667
3667
  seededAttrs;
3668
+ /**
3669
+ * Graph-attribute keys this subgraph holds a local symbol for without having
3670
+ * declared them: `unviewsubgraphsattr` gives each direct subgraph one, with
3671
+ * its current value, when the parent updates its own symbol. The value is
3672
+ * the `attrs` entry (absent for the empty default). A subgraph opened in
3673
+ * this one later copies that value, not a nearer ancestor's newer one.
3674
+ * Undefined on the root and on a subgraph that was never pinned.
3675
+ * @see lib/cgraph/attr.c:232 unviewsubgraphsattr
3676
+ */
3677
+ pinnedAttrs;
3668
3678
  /**
3669
3679
  * Graph-attribute keys whose declaration in THIS scope was the first anywhere
3670
3680
  * in the graph. cgraph's `setattr` splits on exactly this: a key with no
@@ -4116,6 +4126,40 @@ function agGraphAttr(g, name) {
4116
4126
  if (own !== void 0) return own;
4117
4127
  return g.root.declaredGraphAttrs.has(name) ? "" : void 0;
4118
4128
  }
4129
+ function localGraphAttrs(g) {
4130
+ const local = new Map(g.attrs);
4131
+ for (const key of g.seededAttrs ?? []) local.delete(key);
4132
+ return local;
4133
+ }
4134
+
4135
+ // src/parser/graph-attr-syms.ts
4136
+ function hasLocalGraphSym(g, key) {
4137
+ if (g.parent === null) return g.declaredGraphAttrs.has(key);
4138
+ if (g.pinnedAttrs?.has(key) === true) return true;
4139
+ return g.attrs.has(key) && g.seededAttrs?.has(key) !== true;
4140
+ }
4141
+ function pinSubgraphsAttr(parent2, key) {
4142
+ for (const sub of parent2.subgraphs.values()) {
4143
+ if (!hasLocalGraphSym(sub, key)) (sub.pinnedAttrs ??= /* @__PURE__ */ new Set()).add(key);
4144
+ }
4145
+ }
4146
+ function effectiveGraphDefaults(scope) {
4147
+ const eff = /* @__PURE__ */ new Map();
4148
+ const found = /* @__PURE__ */ new Set();
4149
+ const take = (g, key) => {
4150
+ if (found.has(key)) return;
4151
+ found.add(key);
4152
+ const v = g.attrs.get(key);
4153
+ if (v !== void 0) eff.set(key, v);
4154
+ };
4155
+ for (let g = scope; g !== null; g = g.parent) {
4156
+ for (const key of g.attrs.keys()) {
4157
+ if (g.seededAttrs?.has(key) !== true) take(g, key);
4158
+ }
4159
+ for (const key of g.pinnedAttrs ?? []) take(g, key);
4160
+ }
4161
+ return eff;
4162
+ }
4119
4163
 
4120
4164
  // src/parser/builder.ts
4121
4165
  function normaliseAttrValue(value) {
@@ -4141,16 +4185,6 @@ function effectiveNodeDefaults(scope) {
4141
4185
  }
4142
4186
  return eff;
4143
4187
  }
4144
- var GRAPH_LABEL_INHERIT_KEYS = ["label", "fontname", "fontsize", "fontcolor", "labelloc", "labeljust"];
4145
- function effectiveGraphDefaults(scope) {
4146
- const eff = /* @__PURE__ */ new Map();
4147
- for (let g = scope; g !== null; g = g.parent) {
4148
- for (const [k, v] of g.attrs) {
4149
- if (!eff.has(k)) eff.set(k, v);
4150
- }
4151
- }
4152
- return eff;
4153
- }
4154
4188
  var NodeRegistry = class {
4155
4189
  nextId = 0;
4156
4190
  reset() {
@@ -4165,29 +4199,6 @@ var NodeRegistry = class {
4165
4199
  return node;
4166
4200
  }
4167
4201
  };
4168
- var NameCollector = class _NameCollector {
4169
- static fromStmts(stmts) {
4170
- const out = [];
4171
- for (const s of stmts) _NameCollector.fromStmt(s, out);
4172
- return out;
4173
- }
4174
- static fromStmt(stmt, out) {
4175
- if (stmt.type === "node") {
4176
- out.push(stmt.id.id);
4177
- } else if (stmt.type === "edge") {
4178
- for (const item of stmt.nodes) _NameCollector.fromEndpoint(item, out);
4179
- } else if (stmt.type === "subgraph") {
4180
- out.push(..._NameCollector.fromStmts(stmt.stmts));
4181
- }
4182
- }
4183
- static fromEndpoint(item, out) {
4184
- if ("type" in item && item.type === "subgraph") {
4185
- out.push(..._NameCollector.fromStmts(item.stmts));
4186
- } else {
4187
- out.push(item.id);
4188
- }
4189
- }
4190
- };
4191
4202
  var StmtProcessor = class _StmtProcessor {
4192
4203
  constructor(registry) {
4193
4204
  this.registry = registry;
@@ -4256,22 +4267,32 @@ var StmtProcessor = class _StmtProcessor {
4256
4267
  this.anonCounter++;
4257
4268
  }
4258
4269
  processAssign(stmt, graph) {
4259
- graph.attrs.set(stmt.key, normaliseAttrValue(stmt.value));
4260
4270
  this.declareGraphAttr(graph, stmt.key);
4271
+ graph.attrs.set(stmt.key, normaliseAttrValue(stmt.value));
4261
4272
  }
4262
- /** Record a graph-attribute declaration, noting whether THIS scope was the
4263
- * first to declare the key anywhere — the branch selector in cgraph's
4264
- * setattr. @see lib/cgraph/attr.c:257 · model/graph.ts firstGraphDecl */
4273
+ /** Record a graph-attribute declaration, BEFORE its value is stored, noting
4274
+ * whether THIS scope was the first to declare the key anywhere — the branch
4275
+ * selector in cgraph's setattr. @see model/graph.ts firstGraphDecl
4276
+ * A scope that already holds a symbol for the key (the root always; the
4277
+ * first declarer, through bindattrs' empty declaration) updates it, which
4278
+ * first pins its direct subgraphs; a new local definition pins nothing.
4279
+ * A key declared in a re-opened subgraph's later body gets a local symbol,
4280
+ * so it is no longer a seeded one. @see lib/cgraph/attr.c:setattr */
4265
4281
  declareGraphAttr(graph, key) {
4266
- if (!graph.root.declaredGraphAttrs.has(key)) {
4282
+ const first = !graph.root.declaredGraphAttrs.has(key);
4283
+ if (first) {
4267
4284
  (graph.firstGraphDecl ??= /* @__PURE__ */ new Set()).add(key);
4268
4285
  graph.root.declaredGraphAttrs.add(key);
4269
4286
  }
4287
+ if (first || hasLocalGraphSym(graph, key)) pinSubgraphsAttr(graph, key);
4288
+ graph.seededAttrs?.delete(key);
4270
4289
  }
4271
4290
  processAttr(stmt, graph) {
4272
4291
  if (stmt.target === "graph") {
4273
- applyAttrs(stmt.attrs, graph.attrs);
4274
- for (const a of stmt.attrs) this.declareGraphAttr(graph, a.key);
4292
+ for (const a of stmt.attrs) {
4293
+ this.declareGraphAttr(graph, a.key);
4294
+ applyAttrs([a], graph.attrs);
4295
+ }
4275
4296
  } else if (stmt.target === "node") {
4276
4297
  applyAttrs(stmt.attrs, graph.nodeDefaults);
4277
4298
  } else {
@@ -4286,10 +4307,14 @@ var StmtProcessor = class _StmtProcessor {
4286
4307
  }
4287
4308
  }
4288
4309
  processEdgeStmt(stmt, graph, root, directed) {
4289
- const ends = stmt.nodes.map((item) => ({
4290
- nodes: this.resolveEndpoint(item, root, graph, directed),
4310
+ const refs = stmt.nodes.map((item) => ({
4311
+ ref: this.resolveEndpoint(item, root, graph, directed),
4291
4312
  port: portStringOf(item)
4292
4313
  }));
4314
+ const ends = refs.map(({ ref, port }) => ({
4315
+ nodes: ref instanceof Graph ? [...ref.nodes.values()].sort((a, b) => a.id - b.id) : ref,
4316
+ port
4317
+ }));
4293
4318
  for (let i = 0; i < ends.length - 1; i++) {
4294
4319
  this.connectEndpoints(ends[i], ends[i + 1], stmt.attrs, graph, root);
4295
4320
  }
@@ -4297,16 +4322,18 @@ var StmtProcessor = class _StmtProcessor {
4297
4322
  processSubgraph(stmt, graph, root, directed) {
4298
4323
  const sgName = stmt.id ?? `%${this.nextAnonId()}`;
4299
4324
  const prior2 = graph.subgraphs.get(sgName);
4325
+ if (prior2 !== void 0) {
4326
+ buildGraph(stmt.stmts, prior2, root, directed, this);
4327
+ return prior2;
4328
+ }
4300
4329
  const sg = new Graph(sgName, graph.kind);
4301
4330
  sg.parent = graph;
4302
4331
  sg.root = root;
4303
- if (prior2 !== void 0) sg.seq = prior2.seq;
4304
- else assignSubgSeq(graph, sg);
4332
+ assignSubgSeq(graph, sg);
4305
4333
  sg.graphDefaultsSnapshot = effectiveGraphDefaults(graph);
4306
4334
  buildGraph(stmt.stmts, sg, root, directed, this);
4307
- for (const key of GRAPH_LABEL_INHERIT_KEYS) {
4308
- const v = sg.graphDefaultsSnapshot.get(key);
4309
- if (v !== void 0 && !sg.attrs.has(key)) {
4335
+ for (const [key, v] of sg.graphDefaultsSnapshot) {
4336
+ if (!sg.attrs.has(key)) {
4310
4337
  sg.attrs.set(key, v);
4311
4338
  (sg.seededAttrs ??= /* @__PURE__ */ new Set()).add(key);
4312
4339
  }
@@ -4347,12 +4374,11 @@ var StmtProcessor = class _StmtProcessor {
4347
4374
  }
4348
4375
  }
4349
4376
  }
4377
+ /** One endpoint of an edge statement: a node item's node, or a subgraph
4378
+ * item's subgraph, which the caller expands after the whole statement. */
4350
4379
  resolveEndpoint(item, root, scope, directed) {
4351
4380
  if ("type" in item && item.type === "subgraph") {
4352
- this.processSubgraph(item, scope, root, directed);
4353
- const seen2 = /* @__PURE__ */ new Set();
4354
- 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));
4355
- return nodes.sort((a, b) => a.id - b.id);
4381
+ return this.processSubgraph(item, scope, root, directed);
4356
4382
  }
4357
4383
  return [this.registry.ensure(item.id, root, scope)];
4358
4384
  }
@@ -4677,6 +4703,7 @@ var SEMANTIC_RENDER_CODES = /* @__PURE__ */ new Set([
4677
4703
  var DotEngineError = class extends Error {
4678
4704
  constructor(message, options) {
4679
4705
  super(message, options);
4706
+ if (options?.context !== void 0) this.context = options.context;
4680
4707
  }
4681
4708
  };
4682
4709
  var InternalError = class extends DotEngineError {
@@ -5604,21 +5631,29 @@ var P_LPROMOTER = {
5604
5631
  vertices: null
5605
5632
  };
5606
5633
 
5607
- // src/layout/fdp/cluster-edges.ts
5608
- function fillMap(g, map) {
5634
+ // src/common/clust-map.ts
5635
+ function fillMap(g, st) {
5609
5636
  const n = g.info.n_cluster ?? 0;
5610
5637
  for (let c = 0; c < n; c++) {
5611
5638
  const cl = g.info.clust[c];
5612
5639
  const s = cl.name;
5613
- if (!map.has(s)) map.set(s, cl);
5614
- fillMap(cl, map);
5640
+ const anon = s.startsWith(LOCALNAMEPREFIX);
5641
+ if (st.map.has(s) || anon && st.anonKeyed) {
5642
+ agwarningf(`Two clusters named ${s} - the second will be ignored`);
5643
+ } else {
5644
+ st.map.set(s, cl);
5645
+ if (anon) st.anonKeyed = true;
5646
+ }
5647
+ fillMap(cl, st);
5615
5648
  }
5616
5649
  }
5617
5650
  function mkClustMap(g) {
5618
- const map = /* @__PURE__ */ new Map();
5619
- fillMap(g, map);
5620
- return map;
5651
+ const st = { map: /* @__PURE__ */ new Map(), anonKeyed: false };
5652
+ fillMap(g, st);
5653
+ return st.map;
5621
5654
  }
5655
+
5656
+ // src/layout/fdp/cluster-edges.ts
5622
5657
  function mapc(cmap, n) {
5623
5658
  if (n.name.startsWith("cluster")) return cmap.get(n.name) ?? null;
5624
5659
  return null;
@@ -6359,6 +6394,9 @@ function printfFixed(v, decimals) {
6359
6394
  const fracPart = s.slice(s.length - decimals);
6360
6395
  return sign2 + intPart + "." + fracPart;
6361
6396
  }
6397
+ function printfFixed0(v) {
6398
+ return Object.is(v, -0) ? "-0" : printfFixed(v, 0);
6399
+ }
6362
6400
  function printfSig(v, sig) {
6363
6401
  if (!Number.isFinite(v)) return printfNonFinite(v);
6364
6402
  if (v === 0) return sig > 1 ? "0." + "0".repeat(sig - 1) : "0";
@@ -6559,12 +6597,7 @@ var GvcContext = class {
6559
6597
  let engine = selected;
6560
6598
  if (attr2 !== void 0 && attr2 !== "") {
6561
6599
  const override2 = this.layouts.get(attr2);
6562
- if (override2 === void 0) {
6563
- throw new RenderError(
6564
- `Layout type: "${attr2}" not recognized`,
6565
- "UNKNOWN_LAYOUT"
6566
- );
6567
- }
6600
+ if (override2 === void 0) throw this.unknownLayout(attr2);
6568
6601
  engine = override2;
6569
6602
  }
6570
6603
  undoRenderedClusterEdges(g);
@@ -6580,6 +6613,21 @@ var GvcContext = class {
6580
6613
  if (g.info) g.info.cleanup = (x) => engine.cleanup(x);
6581
6614
  if (g.info) g.info.laidOut = true;
6582
6615
  }
6616
+ /**
6617
+ * C's `agerrorf("Layout type: \"%s\" not recognized. Use one of:%s\n", ...)`
6618
+ * (`gvplugin_list` writes each type as a leading space + name), then the
6619
+ * structured error. The thrown wording may differ from the agerr text.
6620
+ * @see lib/gvc/gvlayout.c:gvLayoutJobs
6621
+ */
6622
+ unknownLayout(attr2) {
6623
+ const list = [...this.layouts.keys()].sort().map((name) => ` ${name}`).join("");
6624
+ agerrorf(`Layout type: "${attr2}" not recognized. Use one of:${list}`);
6625
+ return new RenderError(
6626
+ `Layout type: "${attr2}" not recognized. Use one of:${list}.`,
6627
+ "UNKNOWN_LAYOUT",
6628
+ { context: { layout: attr2 } }
6629
+ );
6630
+ }
6583
6631
  /**
6584
6632
  * Release engine layout state after rendering. The records themselves stay,
6585
6633
  * for getLayout, until the next layout replaces them (part-9 AD-11, see
@@ -6749,19 +6797,27 @@ var RenderJob = class {
6749
6797
  /** GD_fontnames of the root graph — selects which PostScript-alias fields the
6750
6798
  * SVG emitter uses. @see plugin/core/gvrender_core_svg.c:464 */
6751
6799
  fontnames = FontnameKind.NativeFonts;
6752
- /** Root graph's `id` attribute (GD_drawing(root)->id), '' if unset. Used as
6753
- * the `<gid>_` prefix for non-root object ids. @see lib/common/emit.c:getObjId */
6800
+ /** GD_drawing(root)->id: the root graph's `id`, substituted, '' if unset. Set
6801
+ * by render() for every renderer (drawingIdOf); the `<gid>_` prefix of
6802
+ * non-root object ids. @see lib/common/emit.c:getObjId */
6754
6803
  drawingId = "";
6755
6804
  /**
6756
- * Resolve an object's SVG id like C's getObjId (steps after layerPagePrefix):
6757
- * a non-empty DOT `id` attr wins verbatim; otherwise non-root objects are
6758
- * prefixed with `<drawingId>_` when the root graph has an id.
6759
- * @see lib/common/emit.c:getObjId:209
6805
+ * Resolve an object's id like C's getObjId. The layer half of
6806
+ * layerPagePrefix comes first (`<layer>_` after the first layer), ahead of
6807
+ * every other step. Then a non-empty DOT `id` attr wins verbatim; otherwise
6808
+ * non-root objects are prefixed with `<drawingId>_` when the root graph has
6809
+ * an id. The root's id gets the same prefix in emit_page (NotFirstPage).
6810
+ * The page half (`page<x>,<y>_`) is left out: only ps and quartz page, and
6811
+ * neither prints an id.
6812
+ * @see lib/common/emit.c:getObjId
6813
+ * @see lib/common/emit.c:layerPagePrefix
6814
+ * @see lib/common/emit.c:emit_page
6760
6815
  */
6761
6816
  objId(idAttr, defaultId, isRoot = false) {
6762
- if (idAttr !== void 0 && idAttr.length > 0) return idAttr;
6763
- if (!isRoot && this.drawingId.length > 0) return this.drawingId + "_" + defaultId;
6764
- return defaultId;
6817
+ const pfx = this.idLayerPrefix();
6818
+ if (idAttr !== void 0 && idAttr.length > 0) return pfx + idAttr;
6819
+ if (!isRoot && this.drawingId.length > 0) return pfx + this.drawingId + "_" + defaultId;
6820
+ return pfx + defaultId;
6765
6821
  }
6766
6822
  /** Active renderer plugin; set by render() before walkNodes. */
6767
6823
  renderer;
@@ -21740,14 +21796,34 @@ function xVal(e, v, dir) {
21740
21796
  if (f) d = -d;
21741
21797
  return d < 0 ? -rv : rv;
21742
21798
  }
21799
+ var INT_MAX2 = 2147483647;
21800
+ var INT_MIN = -2147483648;
21801
+ function sumOverflows(sum, add2) {
21802
+ const s = sum + add2;
21803
+ return s > INT_MAX2 || s < INT_MIN;
21804
+ }
21805
+ function cutvalOverflow(v) {
21806
+ agerrorf("overflow when computing edge weight sum");
21807
+ return new RenderError(
21808
+ `Edge weights at node "${v.name}" sum past the 32-bit integer limit; lower the weight attribute values.`,
21809
+ "RENDER_ERROR",
21810
+ { context: { node: v.name } }
21811
+ );
21812
+ }
21813
+ function sumXVals(list, v, dir, sum) {
21814
+ if (!list) return sum;
21815
+ for (let i = 0; i < list.size; i++) {
21816
+ const add2 = xVal(list.list[i], v, dir);
21817
+ if (sumOverflows(sum, add2)) throw cutvalOverflow(v);
21818
+ sum += add2;
21819
+ }
21820
+ return sum;
21821
+ }
21743
21822
  function xCutval(f) {
21744
21823
  const v = f.tail.info.par === f ? f.tail : f.head;
21745
21824
  const dir = f.tail.info.par === f ? 1 : -1;
21746
- let sum = 0;
21747
- const out = v.info.out;
21748
- if (out) for (let i = 0; i < out.size; i++) sum += xVal(out.list[i], v, dir);
21749
- const inp = v.info.in;
21750
- if (inp) for (let i = 0; i < inp.size; i++) sum += xVal(inp.list[i], v, dir);
21825
+ let sum = sumXVals(v.info.out, v, dir, 0);
21826
+ sum = sumXVals(v.info.in, v, dir, sum);
21751
21827
  f.info.cutvalue = sum;
21752
21828
  }
21753
21829
  function cutvalDescend(list, iArr, top, sp, head) {
@@ -21865,14 +21941,14 @@ function dfsRange(v, par, low) {
21865
21941
  }
21866
21942
 
21867
21943
  // src/util/overflow.ts
21868
- var INT_MAX2 = 2147483647;
21869
- var INT_MIN = -2147483648;
21944
+ var INT_MAX3 = 2147483647;
21945
+ var INT_MIN2 = -2147483648;
21870
21946
  function saddSaturate(a, b) {
21871
- if (b > 0 && INT_MAX2 - b < a) {
21872
- return INT_MAX2;
21947
+ if (b > 0 && INT_MAX3 - b < a) {
21948
+ return INT_MAX3;
21873
21949
  }
21874
- if (b < 0 && INT_MIN - b > a) {
21875
- return INT_MIN;
21950
+ if (b < 0 && INT_MIN2 - b > a) {
21951
+ return INT_MIN2;
21876
21952
  }
21877
21953
  return a + b;
21878
21954
  }
@@ -24290,6 +24366,7 @@ function nonconstraintEdge(e) {
24290
24366
  var WNODE_ORDINARY = 0;
24291
24367
  var WNODE_SINGLETON = 1;
24292
24368
  var WNODE_VIRTUAL = 2;
24369
+ var INT_MAX4 = 2147483647;
24293
24370
  var CLASSIFY_WEIGHT_TABLE = [[1, 1, 1], [1, 2, 2], [1, 2, 4]];
24294
24371
  function epClass(n) {
24295
24372
  if (n.info.node_type === VIRTUAL) return WNODE_VIRTUAL;
@@ -24298,7 +24375,19 @@ function epClass(n) {
24298
24375
  }
24299
24376
  function applyVirtualWeight(e) {
24300
24377
  const t = CLASSIFY_WEIGHT_TABLE[epClass(e.tail)][epClass(e.head)];
24301
- e.info.weight = (e.info.weight ?? 1) * t;
24378
+ const w = e.info.weight ?? 1;
24379
+ if (Math.trunc(INT_MAX4 / t) < w) throw virtualWeightOverflow(e, t);
24380
+ e.info.weight = w * t;
24381
+ }
24382
+ function virtualWeightOverflow(e, t) {
24383
+ agerrorf("overflow when calculating virtual weight of edge");
24384
+ const o = e.info.to_orig ?? e;
24385
+ const name = `${o.tail.name}->${o.head.name}`;
24386
+ return new RenderError(
24387
+ `Edge "${name}" has a weight too large for the layout (weight x ${t} exceeds the 32-bit integer limit); lower its weight attribute.`,
24388
+ "RENDER_ERROR",
24389
+ { context: { edge: name } }
24390
+ );
24302
24391
  }
24303
24392
  function interclust1TRank(e) {
24304
24393
  const clust = e.tail.info.clust;
@@ -25389,7 +25478,7 @@ function emitHtmlCell(cell2, pos, renderer, job) {
25389
25478
  }
25390
25479
  emitCellDecoration(cell2, pos, renderer, job);
25391
25480
  if (cell2.nested !== void 0) {
25392
- emitHtmlLabel(cell2.nested, pos, renderer, job);
25481
+ emitHtmlTbl(cell2.nested, pos, renderer, job);
25393
25482
  } else if (cell2.image !== void 0) {
25394
25483
  emitHtmlImg(cell2.image, pos, renderer, job);
25395
25484
  } else {
@@ -25413,7 +25502,7 @@ function emitTableRules(placed, pos, renderer, job) {
25413
25502
  }
25414
25503
  });
25415
25504
  }
25416
- function emitHtmlLabel(placed, pos, renderer, job) {
25505
+ function emitHtmlTbl(placed, pos, renderer, job) {
25417
25506
  resetHtmlFillPenWidth();
25418
25507
  const anchorData = { href: placed.href, title: placed.title, target: placed.target, id: placed.id };
25419
25508
  const tblBox = absBox(placed.box, pos);
@@ -25444,6 +25533,40 @@ function emitHtmlLabel(placed, pos, renderer, job) {
25444
25533
  endHtmlAnchor(renderer, job);
25445
25534
  }
25446
25535
  }
25536
+ function allocObj(job, parent2) {
25537
+ const obj = createObjState(parent2.type);
25538
+ obj.parent = parent2;
25539
+ obj.penColor = parent2.penColor;
25540
+ obj.fillColor = parent2.fillColor;
25541
+ obj.pen = parent2.pen;
25542
+ obj.fill = parent2.fill;
25543
+ obj.penWidth = parent2.penWidth;
25544
+ obj.gradientAngle = parent2.gradientAngle;
25545
+ obj.stopColor = parent2.stopColor;
25546
+ obj.emitState = parent2.emitState;
25547
+ obj.graphObj = parent2.graphObj;
25548
+ obj.url = parent2.url;
25549
+ obj.tooltip = parent2.tooltip;
25550
+ obj.target = parent2.target;
25551
+ obj.explicitTooltip = parent2.explicitTooltip;
25552
+ job.pushObj(obj);
25553
+ }
25554
+ function freeObj(job) {
25555
+ job.popObj();
25556
+ }
25557
+ function emitHtmlLabel(placed, pos, renderer, job) {
25558
+ const parent2 = job.obj;
25559
+ if (parent2 === null) {
25560
+ emitHtmlTbl(placed, pos, renderer, job);
25561
+ return;
25562
+ }
25563
+ allocObj(job, parent2);
25564
+ try {
25565
+ emitHtmlTbl(placed, pos, renderer, job);
25566
+ } finally {
25567
+ freeObj(job);
25568
+ }
25569
+ }
25447
25570
 
25448
25571
  // src/common/poly-vertices.ts
25449
25572
  function ellipseVertices(w, h) {
@@ -26726,6 +26849,297 @@ function buildPoint(x, y) {
26726
26849
  return pt;
26727
26850
  }
26728
26851
 
26852
+ // src/gvc/anchor.ts
26853
+ function attr(attrs, key) {
26854
+ const v = attrs.get(key);
26855
+ return v !== void 0 && v !== "" ? v : void 0;
26856
+ }
26857
+ function subst(s, obj) {
26858
+ return substObjAnchor(s, obj);
26859
+ }
26860
+ function tip(s, obj) {
26861
+ return substObjAnchor(preprocessTooltip(s), obj);
26862
+ }
26863
+ function textOf(lp) {
26864
+ return lp?.text ?? null;
26865
+ }
26866
+ function pickFirst(attrs, keys, xform) {
26867
+ for (const k of keys) {
26868
+ const s = attr(attrs, k);
26869
+ if (s !== void 0) return { v: xform(s), explicit: true };
26870
+ }
26871
+ return { v: void 0, explicit: false };
26872
+ }
26873
+ function pickEdge(e, keys) {
26874
+ return pickFirst(e.attrs, keys, (s) => subst(s, e));
26875
+ }
26876
+ function pickEdgeTip(e, keys) {
26877
+ return pickFirst(e.attrs, keys, (s) => tip(s, e));
26878
+ }
26879
+ function withFallback(p, dflt, current) {
26880
+ return { v: p.v ?? dflt ?? current, explicit: p.explicit };
26881
+ }
26882
+ function resolveEdgeLabels(e, obj) {
26883
+ obj.label = textOf(e.info.label);
26884
+ obj.xlabel = textOf(e.info.xlabel) ?? obj.label;
26885
+ obj.tailLabel = textOf(e.info.tail_label) ?? obj.label;
26886
+ obj.headLabel = textOf(e.info.head_label) ?? obj.label;
26887
+ }
26888
+ function resolveEdgeUrls(e, obj) {
26889
+ const dflt = pickEdge(e, ["href", "URL"]).v;
26890
+ obj.url = withFallback(pickEdge(e, ["edgehref", "edgeURL"]), dflt, obj.url).v;
26891
+ obj.labelUrl = withFallback(pickEdge(e, ["labelhref", "labelURL"]), dflt, obj.labelUrl).v;
26892
+ const tail = withFallback(pickEdge(e, ["tailhref", "tailURL"]), dflt, obj.tailUrl);
26893
+ obj.tailUrl = tail.v;
26894
+ obj.explicitTailUrl = tail.explicit;
26895
+ const head = withFallback(pickEdge(e, ["headhref", "headURL"]), dflt, obj.headUrl);
26896
+ obj.headUrl = head.v;
26897
+ obj.explicitHeadUrl = head.explicit;
26898
+ }
26899
+ function resolveEdgeTargets(e, obj) {
26900
+ const dflt = pickEdge(e, ["target"]).v;
26901
+ const edge = withFallback(pickEdge(e, ["edgetarget"]), dflt, obj.target);
26902
+ obj.target = edge.v;
26903
+ obj.explicitEdgeTarget = edge.explicit;
26904
+ obj.labelTarget = withFallback(pickEdge(e, ["labeltarget"]), dflt, obj.labelTarget).v;
26905
+ const tail = withFallback(pickEdge(e, ["tailtarget"]), dflt, obj.tailTarget);
26906
+ obj.tailTarget = tail.v;
26907
+ obj.explicitTailTarget = tail.explicit;
26908
+ const head = withFallback(pickEdge(e, ["headtarget"]), dflt, obj.headTarget);
26909
+ obj.headTarget = head.v;
26910
+ obj.explicitHeadTarget = head.explicit;
26911
+ }
26912
+ function resolveEdgeTooltips(e, obj) {
26913
+ const t = withFallback(pickEdgeTip(e, ["tooltip", "edgetooltip"]), obj.label, obj.tooltip);
26914
+ obj.tooltip = t.v;
26915
+ obj.explicitTooltip = t.explicit;
26916
+ const lt = withFallback(pickEdgeTip(e, ["labeltooltip"]), obj.label, obj.labelTooltip);
26917
+ obj.labelTooltip = lt.v;
26918
+ obj.explicitLabelTooltip = lt.explicit;
26919
+ const tt = withFallback(pickEdgeTip(e, ["tailtooltip"]), obj.tailLabel, obj.tailTooltip);
26920
+ obj.tailTooltip = tt.v;
26921
+ obj.explicitTailTooltip = tt.explicit;
26922
+ const ht = withFallback(pickEdgeTip(e, ["headtooltip"]), obj.headLabel, obj.headTooltip);
26923
+ obj.headTooltip = ht.v;
26924
+ obj.explicitHeadTooltip = ht.explicit;
26925
+ }
26926
+ function resolveEdgeAnchor(e, id, obj) {
26927
+ resolveEdgeLabels(e, obj);
26928
+ resolveEdgeUrls(e, obj);
26929
+ resolveEdgeTargets(e, obj);
26930
+ resolveEdgeTooltips(e, obj);
26931
+ obj.id = subst(id, e);
26932
+ }
26933
+ function resolveObjAnchor(g, label, id, obj) {
26934
+ obj.label = label;
26935
+ const ga = (key) => {
26936
+ for (let s = g; s !== null; s = s.parent) {
26937
+ const v = attr(s.attrs, key);
26938
+ if (v !== void 0) return v;
26939
+ }
26940
+ return void 0;
26941
+ };
26942
+ const url = ga("href") ?? ga("URL");
26943
+ if (url !== void 0) obj.url = subst(url, g);
26944
+ const tt = ga("tooltip");
26945
+ if (tt !== void 0) {
26946
+ obj.tooltip = tip(tt, g);
26947
+ obj.explicitTooltip = true;
26948
+ } else if (label !== null) obj.tooltip = label;
26949
+ const tgt = ga("target");
26950
+ if (tgt !== void 0) obj.target = subst(tgt, g);
26951
+ obj.id = subst(id, g);
26952
+ }
26953
+ function openAnchorWith(renderer, job, url, tooltip, target, id) {
26954
+ renderer.beginAnchor?.(url ?? "", tooltip ?? "", target ?? "", id, job);
26955
+ }
26956
+ function beginAnchorIf(renderer, job) {
26957
+ const obj = job.obj;
26958
+ if (obj === null || obj.url === null && !obj.explicitTooltip) return false;
26959
+ openAnchorWith(renderer, job, obj.url, obj.tooltip, obj.target, obj.id ?? "");
26960
+ return true;
26961
+ }
26962
+ var DFLT_SAMPLE = 20;
26963
+ var MAP_HW = 2;
26964
+ function mapTransform(p, ctx) {
26965
+ return applyScale(p, ctx.translation.x, ctx.translation.y, ctx.scale.x, ctx.scale.y);
26966
+ }
26967
+ function nodeIsFilled(n) {
26968
+ return parseStyleFlags(nodeAttr(n, n.root, "style")).filled;
26969
+ }
26970
+ function nodeAttrSet(n, key) {
26971
+ const v = nodeAttr(n, n.root, key);
26972
+ return v !== void 0 && v !== "";
26973
+ }
26974
+ function nodeHasHotspot(n) {
26975
+ return nodeAttrSet(n, "href") || nodeAttrSet(n, "URL") || nodeAttrSet(n, "tooltip");
26976
+ }
26977
+ function isRectPoly(p) {
26978
+ return p.sides === 4 && Math.abs(p.orientation % 90) < 0.5 && p.distortion === 0 && p.skew === 0;
26979
+ }
26980
+ function samplePoints(n) {
26981
+ const s = n.attrs.get("samplepoints");
26982
+ if (s === void 0) return DFLT_SAMPLE;
26983
+ const v = parseInt(s, 10);
26984
+ return Number.isNaN(v) || v < 4 || v > 60 ? DFLT_SAMPLE : v;
26985
+ }
26986
+ function pEllipse(a, b, np) {
26987
+ const del = 2 * Math.PI / np;
26988
+ const ps = [];
26989
+ let theta = 0;
26990
+ for (let i = 0; i < np; i++) {
26991
+ ps.push({ x: a * Math.cos(theta), y: b * Math.sin(theta) });
26992
+ theta += del;
26993
+ }
26994
+ return ps;
26995
+ }
26996
+ function ellipseNodeMap(poly, coord, ur, nump) {
26997
+ if (poly.regular) {
26998
+ return { shape: 1 /* Circle */, pts: [coord, { x: coord.x + ur.x, y: coord.y + ur.y }] };
26999
+ }
27000
+ const pts = pEllipse(ur.x, ur.y, nump).map((p) => ({ x: p.x + coord.x, y: p.y + coord.y }));
27001
+ return { shape: 2 /* Polygon */, pts };
27002
+ }
27003
+ function generalNodeMap(poly, coord, vertices, peripheries, nump) {
27004
+ const offset = (peripheries - 1) * poly.sides;
27005
+ const pts = [];
27006
+ if (poly.sides >= nump) {
27007
+ const delta2 = Math.trunc(poly.sides / nump);
27008
+ for (let i = 0, j = 0; j < nump; i += delta2, j++) {
27009
+ const v = vertices[i + offset];
27010
+ pts.push({ x: coord.x + v.x, y: coord.y + v.y });
27011
+ }
27012
+ } else {
27013
+ for (let i = 0; i < poly.sides; i++) {
27014
+ const v = vertices[i + offset];
27015
+ pts.push({ x: coord.x + v.x, y: coord.y + v.y });
27016
+ }
27017
+ }
27018
+ return { shape: 2 /* Polygon */, pts };
27019
+ }
27020
+ function nodePolyMap(n, poly, coord, filled) {
27021
+ const peripheries = poly.peripheries < 2 ? 1 : poly.peripheries;
27022
+ const vertices = poly.vertices;
27023
+ const nump = samplePoints(n);
27024
+ const info = n.info;
27025
+ if (poly.peripheries === 0 && !filled) {
27026
+ return { shape: 0 /* Rectangle */, pts: [
27027
+ { x: coord.x - info.lw, y: coord.y - info.ht / 2 },
27028
+ { x: coord.x + info.lw, y: coord.y + info.ht / 2 }
27029
+ ] };
27030
+ }
27031
+ if (poly.sides < 3 && poly.skew === 0 && poly.distortion === 0) {
27032
+ return ellipseNodeMap(poly, coord, vertices[2 * peripheries - 1], nump);
27033
+ }
27034
+ return generalNodeMap(poly, coord, vertices, peripheries, nump);
27035
+ }
27036
+ function computeNodeUrlMap(n, obj, ctx) {
27037
+ if (!nodeHasHotspot(n)) return;
27038
+ const info = n.info;
27039
+ const coord = info.coord;
27040
+ const poly = info.shape_info;
27041
+ const filled = nodeIsFilled(n);
27042
+ const isRect = poly !== void 0 && isRectPoly(poly) && (poly.peripheries !== 0 || filled);
27043
+ let m;
27044
+ if (poly !== void 0 && poly.vertices != null && !isRect && ctx.mapPolygon) {
27045
+ m = nodePolyMap(n, poly, coord, filled);
27046
+ } else {
27047
+ m = { shape: 0 /* Rectangle */, pts: [
27048
+ { x: coord.x - info.lw, y: coord.y - info.ht / 2 },
27049
+ { x: coord.x + info.rw, y: coord.y + info.ht / 2 }
27050
+ ] };
27051
+ }
27052
+ obj.urlMapShape = m.shape;
27053
+ obj.urlMapPts = m.pts.map((p) => mapTransform(p, ctx));
27054
+ }
27055
+ function computeGraphUrlMap(obj, ctx) {
27056
+ const { ll, ur } = ctx.pageBox;
27057
+ obj.urlMapShape = 0 /* Rectangle */;
27058
+ obj.urlMapPts = [mapTransform(ll, ctx), mapTransform(ur, ctx)];
27059
+ }
27060
+ function computeClusterUrlMap(bb, obj, ctx) {
27061
+ obj.urlMapShape = 0 /* Rectangle */;
27062
+ obj.urlMapPts = [mapTransform(bb.ll, ctx), mapTransform(bb.ur, ctx)];
27063
+ }
27064
+ function computeLabelRectMap(lab, obj, ctx) {
27065
+ const dx = lab.dimen.x / 2;
27066
+ const dy = lab.dimen.y / 2;
27067
+ obj.urlMapShape = 0 /* Rectangle */;
27068
+ obj.urlMapPts = [
27069
+ mapTransform({ x: lab.pos.x - dx, y: lab.pos.y - dy }, ctx),
27070
+ mapTransform({ x: lab.pos.x + dx, y: lab.pos.y + dy }, ctx)
27071
+ ];
27072
+ }
27073
+ function checkControlPoints2(cp) {
27074
+ return ptToLine2(cp[0], cp[3], cp[1]) < MAP_HW * MAP_HW && ptToLine2(cp[0], cp[3], cp[2]) < MAP_HW * MAP_HW;
27075
+ }
27076
+ function bezierHalf(v) {
27077
+ const left2 = [];
27078
+ const right2 = [];
27079
+ bezier(v, 0.5, left2, right2);
27080
+ return { left: left2, right: right2 };
27081
+ }
27082
+ function approxBezier(cp, out) {
27083
+ if (checkControlPoints2(cp)) {
27084
+ if (out.length === 0) out.push(cp[0]);
27085
+ out.push(cp[3]);
27086
+ } else {
27087
+ const { left: left2, right: right2 } = bezierHalf(cp);
27088
+ approxBezier(left2, out);
27089
+ approxBezier(right2, out);
27090
+ }
27091
+ }
27092
+ function mkSegPts(prv, cur, nxt, w2) {
27093
+ let pp;
27094
+ let np;
27095
+ if (prv) {
27096
+ pp = prv;
27097
+ np = nxt ?? { x: 2 * (cur.x - pp.x), y: 2 * (cur.y - pp.y) };
27098
+ } else {
27099
+ np = nxt;
27100
+ pp = { x: 2 * (cur.x - np.x), y: 2 * (cur.y - np.y) };
27101
+ }
27102
+ const theta = Math.atan2(np.y - cur.y, np.x - cur.x);
27103
+ const phi = Math.atan2(pp.y - cur.y, pp.x - cur.x);
27104
+ let ang = theta - phi;
27105
+ if (ang > 0) ang -= 2 * Math.PI;
27106
+ const bis = phi + ang / 2;
27107
+ const del = { x: w2 * Math.cos(bis), y: w2 * Math.sin(bis) };
27108
+ return { p1: { x: cur.x + del.x, y: cur.y + del.y }, p2: { x: cur.x - del.x, y: cur.y - del.y } };
27109
+ }
27110
+ function mapOutputBspline(bp, w2, polys) {
27111
+ const nc = Math.trunc((bp.size - 1) / 3);
27112
+ const segs = [];
27113
+ for (let j = 0; j < nc; j++) {
27114
+ approxBezier([bp.list[3 * j], bp.list[3 * j + 1], bp.list[3 * j + 2], bp.list[3 * j + 3]], segs);
27115
+ }
27116
+ const pt1 = [];
27117
+ const pt2 = [];
27118
+ let cnt = 0;
27119
+ for (let i = 0; i < segs.length; i++) {
27120
+ const prev = i === 0 ? null : segs[i - 1];
27121
+ const next = i + 1 < segs.length ? segs[i + 1] : null;
27122
+ const seg2 = mkSegPts(prev, segs[i], next, w2);
27123
+ pt1[cnt] = seg2.p1;
27124
+ pt2[cnt] = seg2.p2;
27125
+ cnt++;
27126
+ if (i + 1 === segs.length || cnt === 50) {
27127
+ const poly = [];
27128
+ for (let k = 0; k < cnt; k++) poly.push(pt1[k]);
27129
+ for (let k = 0; k < cnt; k++) poly.push(pt2[cnt - 1 - k]);
27130
+ polys.push(poly);
27131
+ pt1[0] = pt1[cnt - 1];
27132
+ pt2[0] = pt2[cnt - 1];
27133
+ cnt = 1;
27134
+ }
27135
+ }
27136
+ }
27137
+ function computeEdgeSplineMaps(spl, w2, ctx) {
27138
+ const polys = [];
27139
+ for (const bz of spl.list) mapOutputBspline(bz, w2, polys);
27140
+ return polys.map((poly) => poly.map((p) => mapTransform(p, ctx)));
27141
+ }
27142
+
26729
27143
  // src/gvc/device-cluster.ts
26730
27144
  function applyClusterGradient(obj, fill) {
26731
27145
  obj.fill = fill.kind === "radial" ? 3 /* Radial */ : 2 /* Linear */;
@@ -26827,8 +27241,18 @@ function applyClusterFill(obj, fillRes) {
26827
27241
  applyClusterGradient(obj, fillRes);
26828
27242
  return true;
26829
27243
  }
27244
+ function beginClusterAnchor(sg, renderer, job) {
27245
+ const obj = job.obj;
27246
+ if (obj === null || obj.url === null && !obj.explicitTooltip) return false;
27247
+ renderer.emitMapRect?.(sg.info.bb, job);
27248
+ return beginAnchorIf(renderer, job);
27249
+ }
26830
27250
 
26831
27251
  // src/render/svg-id.ts
27252
+ function drawingIdOf(g) {
27253
+ const id = g.attrs.get("id");
27254
+ return id !== void 0 && id.length > 0 ? substObjAnchor(id, g) : "";
27255
+ }
26832
27256
  function svgClass(kind, classAttr) {
26833
27257
  return classAttr !== void 0 && classAttr.length > 0 ? 'class="' + kind + " " + escapeXmlTitle(classAttr) + '"' : 'class="' + kind + '"';
26834
27258
  }
@@ -27106,19 +27530,11 @@ function polyGencode(rawJob, rawNode) {
27106
27530
  const ctx = resolveNodeDrawCtx(job, n);
27107
27531
  if (ctx === null) return;
27108
27532
  const clustersLast = (job.flags & EMIT_CLUSTERS_LAST) !== 0;
27109
- const savedShape = job.obj?.urlMapShape;
27110
- const savedPts = job.obj?.urlMapPts;
27111
27533
  let inAnchor = clustersLast ? false : beginNodeAnchor(n, renderer, job);
27112
27534
  renderPeripheries(ctx.poly, ctx.coord, ctx.filled, ctx.ringCtx);
27113
27535
  if (!isPointNode(n)) renderUsershape(n, ctx);
27114
27536
  if (!isPointNode(n)) renderNodeLabel(n, ctx.coord, renderer, job);
27115
- if (clustersLast) {
27116
- if (job.obj && savedPts !== void 0 && savedShape !== void 0) {
27117
- job.obj.urlMapShape = savedShape;
27118
- job.obj.urlMapPts = savedPts;
27119
- }
27120
- inAnchor = beginNodeAnchor(n, renderer, job);
27121
- }
27537
+ if (clustersLast) inAnchor = beginNodeAnchor(n, renderer, job);
27122
27538
  if (inAnchor) renderer.endAnchor?.(job);
27123
27539
  }
27124
27540
 
@@ -28988,7 +29404,6 @@ function svgBeginGraph(g, job) {
28988
29404
  job.devscale = { x: 1, y: -1 };
28989
29405
  job.directed = g.kind === "directed" || g.kind === "strict-directed";
28990
29406
  job.fontnames = g.info.fontnames ?? FontnameKind.NativeFonts;
28991
- job.drawingId = g.attrs.get("id") ?? "";
28992
29407
  job.write(SVG_XML_DECL);
28993
29408
  const stylesheet = g.attrs.get("stylesheet");
28994
29409
  if (stylesheet !== void 0 && stylesheet.length > 0) {
@@ -29014,7 +29429,7 @@ function svgBeginPage(g, job) {
29014
29429
  const tx = job.rotation !== 0 ? -clip.ur.x - job.margin.x / z : -clip.ll.x + job.margin.x / z;
29015
29430
  const ty = clip.ur.y + job.margin.y / z;
29016
29431
  emitGraphGroupOpen(
29017
- job.idLayerPrefix() + svgGraphId(g, job),
29432
+ svgGraphId(g, job),
29018
29433
  svgGraphClass(g),
29019
29434
  tx,
29020
29435
  ty,
@@ -29220,7 +29635,7 @@ function textAnchor(just) {
29220
29635
  return "middle";
29221
29636
  }
29222
29637
  function svgBeginNode(n, job) {
29223
- job.write('<g id="' + escapeXmlTitle(job.idLayerPrefix() + svgNodeId(n, job) + job.idLayerSuffix()) + '" ' + svgNodeClass(n) + ">\n");
29638
+ job.write('<g id="' + escapeXmlTitle(svgNodeId(n, job) + job.idLayerSuffix()) + '" ' + svgNodeClass(n) + ">\n");
29224
29639
  job.write("<title>" + escapeXmlTitle(n.name) + "</title>\n");
29225
29640
  }
29226
29641
  function svgEndNode(job) {
@@ -29234,7 +29649,7 @@ function svgBeginEdge(e, job) {
29234
29649
  const tp = e.info.tail_port?.name;
29235
29650
  const hp = e.info.head_port?.name;
29236
29651
  const raw = e.tail.name + (tp ? ":" + tp : "") + sep + e.head.name + (hp ? ":" + hp : "");
29237
- job.write('<g id="' + escapeXmlTitle(job.idLayerPrefix() + svgEdgeId(e, job)) + '" ' + svgEdgeClass(e) + ">\n");
29652
+ job.write('<g id="' + escapeXmlTitle(svgEdgeId(e, job)) + '" ' + svgEdgeClass(e) + ">\n");
29238
29653
  job.write("<title>" + escapeEdgeTitle(raw) + "</title>\n");
29239
29654
  }
29240
29655
  function svgEndEdge(job) {
@@ -29515,318 +29930,27 @@ function initJobViewportZoom(bb, size, pad) {
29515
29930
  return 1;
29516
29931
  }
29517
29932
  function setupPageClip(bb, size, pad, z) {
29518
- const jbLL = { x: bb.ll.x - pad.x, y: bb.ll.y - pad.y };
29519
- const jbUR = { x: bb.ur.x + pad.x, y: bb.ur.y + pad.y };
29520
- const sz = { x: jbUR.x - jbLL.x, y: jbUR.y - jbLL.y };
29521
- if (size !== null && size.x > 1e-3 && size.y > 1e-3) {
29522
- if (sz.x <= 1e-3) sz.x = size.x;
29523
- if (sz.y <= 1e-3) sz.y = size.y;
29524
- }
29525
29933
  const focus = { x: 0.5 * (bb.ll.x + bb.ur.x), y: 0.5 * (bb.ll.y + bb.ur.y) };
29526
- const pageSize = { x: z * sz.x / z, y: z * sz.y / z };
29934
+ const pageSize = setupPageSize(bb, size, pad, z);
29527
29935
  const ll = {
29528
29936
  x: focus.x + pageSize.x * (0 - 1 / 2),
29529
29937
  y: focus.y + pageSize.y * (0 - 1 / 2)
29530
29938
  };
29531
29939
  return { ll, ur: { x: ll.x + pageSize.x, y: ll.y + pageSize.y } };
29532
29940
  }
29533
-
29534
- // src/gvc/anchor.ts
29535
- function attr(attrs, key) {
29536
- const v = attrs.get(key);
29537
- return v !== void 0 && v !== "" ? v : void 0;
29538
- }
29539
- function subst(s, obj) {
29540
- return substObjAnchor(s, obj);
29541
- }
29542
- function tip(s, obj) {
29543
- return substObjAnchor(preprocessTooltip(s), obj);
29544
- }
29545
- function textOf(lp) {
29546
- return lp?.text ?? null;
29547
- }
29548
- function pickFirst(attrs, keys, xform) {
29549
- for (const k of keys) {
29550
- const s = attr(attrs, k);
29551
- if (s !== void 0) return { v: xform(s), explicit: true };
29552
- }
29553
- return { v: void 0, explicit: false };
29554
- }
29555
- function pickEdge(e, keys) {
29556
- return pickFirst(e.attrs, keys, (s) => subst(s, e));
29557
- }
29558
- function pickEdgeTip(e, keys) {
29559
- return pickFirst(e.attrs, keys, (s) => tip(s, e));
29560
- }
29561
- function withFallback(p, dflt, current) {
29562
- return { v: p.v ?? dflt ?? current, explicit: p.explicit };
29563
- }
29564
- function resolveEdgeLabels(e, obj) {
29565
- obj.label = textOf(e.info.label);
29566
- obj.xlabel = textOf(e.info.xlabel) ?? obj.label;
29567
- obj.tailLabel = textOf(e.info.tail_label) ?? obj.label;
29568
- obj.headLabel = textOf(e.info.head_label) ?? obj.label;
29569
- }
29570
- function resolveEdgeUrls(e, obj) {
29571
- const dflt = pickEdge(e, ["href", "URL"]).v;
29572
- obj.url = withFallback(pickEdge(e, ["edgehref", "edgeURL"]), dflt, obj.url).v;
29573
- obj.labelUrl = withFallback(pickEdge(e, ["labelhref", "labelURL"]), dflt, obj.labelUrl).v;
29574
- const tail = withFallback(pickEdge(e, ["tailhref", "tailURL"]), dflt, obj.tailUrl);
29575
- obj.tailUrl = tail.v;
29576
- obj.explicitTailUrl = tail.explicit;
29577
- const head = withFallback(pickEdge(e, ["headhref", "headURL"]), dflt, obj.headUrl);
29578
- obj.headUrl = head.v;
29579
- obj.explicitHeadUrl = head.explicit;
29580
- }
29581
- function resolveEdgeTargets(e, obj) {
29582
- const dflt = pickEdge(e, ["target"]).v;
29583
- const edge = withFallback(pickEdge(e, ["edgetarget"]), dflt, obj.target);
29584
- obj.target = edge.v;
29585
- obj.explicitEdgeTarget = edge.explicit;
29586
- obj.labelTarget = withFallback(pickEdge(e, ["labeltarget"]), dflt, obj.labelTarget).v;
29587
- const tail = withFallback(pickEdge(e, ["tailtarget"]), dflt, obj.tailTarget);
29588
- obj.tailTarget = tail.v;
29589
- obj.explicitTailTarget = tail.explicit;
29590
- const head = withFallback(pickEdge(e, ["headtarget"]), dflt, obj.headTarget);
29591
- obj.headTarget = head.v;
29592
- obj.explicitHeadTarget = head.explicit;
29593
- }
29594
- function resolveEdgeTooltips(e, obj) {
29595
- const t = withFallback(pickEdgeTip(e, ["tooltip", "edgetooltip"]), obj.label, obj.tooltip);
29596
- obj.tooltip = t.v;
29597
- obj.explicitTooltip = t.explicit;
29598
- const lt = withFallback(pickEdgeTip(e, ["labeltooltip"]), obj.label, obj.labelTooltip);
29599
- obj.labelTooltip = lt.v;
29600
- obj.explicitLabelTooltip = lt.explicit;
29601
- const tt = withFallback(pickEdgeTip(e, ["tailtooltip"]), obj.tailLabel, obj.tailTooltip);
29602
- obj.tailTooltip = tt.v;
29603
- obj.explicitTailTooltip = tt.explicit;
29604
- const ht = withFallback(pickEdgeTip(e, ["headtooltip"]), obj.headLabel, obj.headTooltip);
29605
- obj.headTooltip = ht.v;
29606
- obj.explicitHeadTooltip = ht.explicit;
29607
- }
29608
- function resolveEdgeAnchor(e, id, obj) {
29609
- resolveEdgeLabels(e, obj);
29610
- resolveEdgeUrls(e, obj);
29611
- resolveEdgeTargets(e, obj);
29612
- resolveEdgeTooltips(e, obj);
29613
- obj.id = subst(id, e);
29614
- }
29615
- function resolveObjAnchor(g, label, id, obj) {
29616
- obj.label = label;
29617
- const ga = (key) => {
29618
- for (let s = g; s !== null; s = s.parent) {
29619
- const v = attr(s.attrs, key);
29620
- if (v !== void 0) return v;
29621
- }
29622
- return void 0;
29623
- };
29624
- const url = ga("href") ?? ga("URL");
29625
- if (url !== void 0) obj.url = subst(url, g);
29626
- const tt = ga("tooltip");
29627
- if (tt !== void 0) {
29628
- obj.tooltip = tip(tt, g);
29629
- obj.explicitTooltip = true;
29630
- } else if (label !== null) obj.tooltip = label;
29631
- const tgt = ga("target");
29632
- if (tgt !== void 0) obj.target = subst(tgt, g);
29633
- obj.id = subst(id, g);
29634
- }
29635
- function openAnchorWith(renderer, job, url, tooltip, target, id) {
29636
- renderer.beginAnchor?.(url ?? "", tooltip ?? "", target ?? "", id, job);
29637
- }
29638
- function beginAnchorIf(renderer, job) {
29639
- const obj = job.obj;
29640
- if (obj === null || obj.url === null && !obj.explicitTooltip) return false;
29641
- openAnchorWith(renderer, job, obj.url, obj.tooltip, obj.target, obj.id ?? "");
29642
- return true;
29643
- }
29644
- var DFLT_SAMPLE = 20;
29645
- var MAP_HW = 2;
29646
- function mapTransform(p, ctx) {
29647
- return {
29648
- x: (p.x + ctx.pad.x - ctx.bb.ll.x) * ctx.scale + ctx.marginOff.x,
29649
- y: (ctx.bb.ur.y + ctx.pad.y - p.y) * ctx.scale + ctx.marginOff.y
29650
- };
29651
- }
29652
- function nodeIsFilled(n) {
29653
- return parseStyleFlags(nodeAttr(n, n.root, "style")).filled;
29654
- }
29655
- function nodeAttrSet(n, key) {
29656
- const v = nodeAttr(n, n.root, key);
29657
- return v !== void 0 && v !== "";
29658
- }
29659
- function nodeHasHotspot(n) {
29660
- return nodeAttrSet(n, "href") || nodeAttrSet(n, "URL") || nodeAttrSet(n, "tooltip");
29661
- }
29662
- function isRectPoly(p) {
29663
- return p.sides === 4 && Math.abs(p.orientation % 90) < 0.5 && p.distortion === 0 && p.skew === 0;
29664
- }
29665
- function samplePoints(n) {
29666
- const s = n.attrs.get("samplepoints");
29667
- if (s === void 0) return DFLT_SAMPLE;
29668
- const v = parseInt(s, 10);
29669
- return Number.isNaN(v) || v < 4 || v > 60 ? DFLT_SAMPLE : v;
29670
- }
29671
- function pEllipse(a, b, np) {
29672
- const del = 2 * Math.PI / np;
29673
- const ps = [];
29674
- let theta = 0;
29675
- for (let i = 0; i < np; i++) {
29676
- ps.push({ x: a * Math.cos(theta), y: b * Math.sin(theta) });
29677
- theta += del;
29678
- }
29679
- return ps;
29680
- }
29681
- function ellipseNodeMap(poly, coord, ur, nump) {
29682
- if (poly.regular) {
29683
- return { shape: 1 /* Circle */, pts: [coord, { x: coord.x + ur.x, y: coord.y + ur.y }] };
29684
- }
29685
- const pts = pEllipse(ur.x, ur.y, nump).map((p) => ({ x: p.x + coord.x, y: p.y + coord.y }));
29686
- return { shape: 2 /* Polygon */, pts };
29687
- }
29688
- function generalNodeMap(poly, coord, vertices, peripheries, nump) {
29689
- const offset = (peripheries - 1) * poly.sides;
29690
- const pts = [];
29691
- if (poly.sides >= nump) {
29692
- const delta2 = Math.trunc(poly.sides / nump);
29693
- for (let i = 0, j = 0; j < nump; i += delta2, j++) {
29694
- const v = vertices[i + offset];
29695
- pts.push({ x: coord.x + v.x, y: coord.y + v.y });
29696
- }
29697
- } else {
29698
- for (let i = 0; i < poly.sides; i++) {
29699
- const v = vertices[i + offset];
29700
- pts.push({ x: coord.x + v.x, y: coord.y + v.y });
29701
- }
29702
- }
29703
- return { shape: 2 /* Polygon */, pts };
29704
- }
29705
- function nodePolyMap(n, poly, coord, filled) {
29706
- const peripheries = poly.peripheries < 2 ? 1 : poly.peripheries;
29707
- const vertices = poly.vertices;
29708
- const nump = samplePoints(n);
29709
- const info = n.info;
29710
- if (poly.peripheries === 0 && !filled) {
29711
- return { shape: 0 /* Rectangle */, pts: [
29712
- { x: coord.x - info.lw, y: coord.y - info.ht / 2 },
29713
- { x: coord.x + info.lw, y: coord.y + info.ht / 2 }
29714
- ] };
29715
- }
29716
- if (poly.sides < 3 && poly.skew === 0 && poly.distortion === 0) {
29717
- return ellipseNodeMap(poly, coord, vertices[2 * peripheries - 1], nump);
29718
- }
29719
- return generalNodeMap(poly, coord, vertices, peripheries, nump);
29720
- }
29721
- function computeNodeUrlMap(n, obj, ctx) {
29722
- if (!nodeHasHotspot(n)) return;
29723
- const info = n.info;
29724
- const coord = info.coord;
29725
- const poly = info.shape_info;
29726
- const filled = nodeIsFilled(n);
29727
- const isRect = poly !== void 0 && isRectPoly(poly) && (poly.peripheries !== 0 || filled);
29728
- let m;
29729
- if (poly !== void 0 && poly.vertices != null && !isRect && ctx.mapPolygon) {
29730
- m = nodePolyMap(n, poly, coord, filled);
29731
- } else {
29732
- m = { shape: 0 /* Rectangle */, pts: [
29733
- { x: coord.x - info.lw, y: coord.y - info.ht / 2 },
29734
- { x: coord.x + info.rw, y: coord.y + info.ht / 2 }
29735
- ] };
29736
- }
29737
- obj.urlMapShape = m.shape;
29738
- obj.urlMapPts = m.pts.map((p) => mapTransform(p, ctx));
29739
- }
29740
- function computeGraphUrlMap(obj, ctx) {
29741
- const ll = { x: -ctx.pad.x, y: -ctx.pad.y };
29742
- const ur = {
29743
- x: ctx.bb.ur.x - ctx.bb.ll.x + ctx.pad.x,
29744
- y: ctx.bb.ur.y - ctx.bb.ll.y + ctx.pad.y
29745
- };
29746
- obj.urlMapShape = 0 /* Rectangle */;
29747
- obj.urlMapPts = [mapTransform(ll, ctx), mapTransform(ur, ctx)];
29748
- }
29749
- function computeClusterUrlMap(bb, obj, ctx) {
29750
- obj.urlMapShape = 0 /* Rectangle */;
29751
- obj.urlMapPts = [mapTransform(bb.ll, ctx), mapTransform(bb.ur, ctx)];
29752
- }
29753
- function computeLabelRectMap(lab, obj, ctx) {
29754
- const dx = lab.dimen.x / 2;
29755
- const dy = lab.dimen.y / 2;
29756
- obj.urlMapShape = 0 /* Rectangle */;
29757
- obj.urlMapPts = [
29758
- mapTransform({ x: lab.pos.x - dx, y: lab.pos.y - dy }, ctx),
29759
- mapTransform({ x: lab.pos.x + dx, y: lab.pos.y + dy }, ctx)
29760
- ];
29761
- }
29762
- function checkControlPoints2(cp) {
29763
- return ptToLine2(cp[0], cp[3], cp[1]) < MAP_HW * MAP_HW && ptToLine2(cp[0], cp[3], cp[2]) < MAP_HW * MAP_HW;
29764
- }
29765
- function bezierHalf(v) {
29766
- const left2 = [];
29767
- const right2 = [];
29768
- bezier(v, 0.5, left2, right2);
29769
- return { left: left2, right: right2 };
29770
- }
29771
- function approxBezier(cp, out) {
29772
- if (checkControlPoints2(cp)) {
29773
- if (out.length === 0) out.push(cp[0]);
29774
- out.push(cp[3]);
29775
- } else {
29776
- const { left: left2, right: right2 } = bezierHalf(cp);
29777
- approxBezier(left2, out);
29778
- approxBezier(right2, out);
29779
- }
29780
- }
29781
- function mkSegPts(prv, cur, nxt, w2) {
29782
- let pp;
29783
- let np;
29784
- if (prv) {
29785
- pp = prv;
29786
- np = nxt ?? { x: 2 * (cur.x - pp.x), y: 2 * (cur.y - pp.y) };
29787
- } else {
29788
- np = nxt;
29789
- pp = { x: 2 * (cur.x - np.x), y: 2 * (cur.y - np.y) };
29790
- }
29791
- const theta = Math.atan2(np.y - cur.y, np.x - cur.x);
29792
- const phi = Math.atan2(pp.y - cur.y, pp.x - cur.x);
29793
- let ang = theta - phi;
29794
- if (ang > 0) ang -= 2 * Math.PI;
29795
- const bis = phi + ang / 2;
29796
- const del = { x: w2 * Math.cos(bis), y: w2 * Math.sin(bis) };
29797
- return { p1: { x: cur.x + del.x, y: cur.y + del.y }, p2: { x: cur.x - del.x, y: cur.y - del.y } };
29798
- }
29799
- function mapOutputBspline(bp, w2, polys) {
29800
- const nc = Math.trunc((bp.size - 1) / 3);
29801
- const segs = [];
29802
- for (let j = 0; j < nc; j++) {
29803
- approxBezier([bp.list[3 * j], bp.list[3 * j + 1], bp.list[3 * j + 2], bp.list[3 * j + 3]], segs);
29804
- }
29805
- const pt1 = [];
29806
- const pt2 = [];
29807
- let cnt = 0;
29808
- for (let i = 0; i < segs.length; i++) {
29809
- const prev = i === 0 ? null : segs[i - 1];
29810
- const next = i + 1 < segs.length ? segs[i + 1] : null;
29811
- const seg2 = mkSegPts(prev, segs[i], next, w2);
29812
- pt1[cnt] = seg2.p1;
29813
- pt2[cnt] = seg2.p2;
29814
- cnt++;
29815
- if (i + 1 === segs.length || cnt === 50) {
29816
- const poly = [];
29817
- for (let k = 0; k < cnt; k++) poly.push(pt1[k]);
29818
- for (let k = 0; k < cnt; k++) poly.push(pt2[cnt - 1 - k]);
29819
- polys.push(poly);
29820
- pt1[0] = pt1[cnt - 1];
29821
- pt2[0] = pt2[cnt - 1];
29822
- cnt = 1;
29823
- }
29941
+ function setupPageSize(bb, size, pad, z) {
29942
+ const jbLL = { x: bb.ll.x - pad.x, y: bb.ll.y - pad.y };
29943
+ const jbUR = { x: bb.ur.x + pad.x, y: bb.ur.y + pad.y };
29944
+ const sz = { x: jbUR.x - jbLL.x, y: jbUR.y - jbLL.y };
29945
+ if (size !== null && size.x > 1e-3 && size.y > 1e-3) {
29946
+ if (sz.x <= 1e-3) sz.x = size.x;
29947
+ if (sz.y <= 1e-3) sz.y = size.y;
29824
29948
  }
29949
+ return { x: z * sz.x / z, y: z * sz.y / z };
29825
29950
  }
29826
- function computeEdgeSplineMaps(spl, w2, ctx) {
29827
- const polys = [];
29828
- for (const bz of spl.list) mapOutputBspline(bz, w2, polys);
29829
- return polys.map((poly) => poly.map((p) => mapTransform(p, ctx)));
29951
+ function setupPageBox(pageSize, pad) {
29952
+ const ll = { x: 0 * pageSize.x - pad.x, y: 0 * pageSize.y - pad.y };
29953
+ return { ll, ur: { x: ll.x + pageSize.x, y: ll.y + pageSize.y } };
29830
29954
  }
29831
29955
 
29832
29956
  // src/common/layers.ts
@@ -29905,6 +30029,16 @@ function edgeInLayer(info, layerNum, e) {
29905
30029
  return pn === "" || selectedLayer(info, layerNum, pn);
29906
30030
  });
29907
30031
  }
30032
+ function clustInLayer(info, layerNum, sg) {
30033
+ if (info.numLayers <= 1) return true;
30034
+ const pg = graphAttrInherited(sg, "layer") ?? "";
30035
+ if (selectedLayer(info, layerNum, pg)) return true;
30036
+ if (pg !== "") return false;
30037
+ for (const n of sg.nodes.values()) {
30038
+ if (nodeInLayer(info, layerNum, n, sg)) return true;
30039
+ }
30040
+ return false;
30041
+ }
29908
30042
  function parseLayerselect(info, p) {
29909
30043
  const picked = [];
29910
30044
  for (let i = 1; i <= info.numLayers; i++) {
@@ -29926,6 +30060,9 @@ function nodeShown(info, job, n, g) {
29926
30060
  function edgeShown(info, job, e) {
29927
30061
  return info === void 0 || job.numLayers <= 1 || edgeInLayer(info, job.layerNum, e);
29928
30062
  }
30063
+ function clusterShown(info, job, sg) {
30064
+ return info === void 0 || job.numLayers <= 1 || clustInLayer(info, job.layerNum, sg);
30065
+ }
29929
30066
  function chkOrder(g) {
29930
30067
  const p = g.attrs.get("outputorder");
29931
30068
  if (p === "nodesfirst") return "nodesfirst";
@@ -30433,20 +30570,19 @@ function drawClusterInScheme(sg, renderer, job) {
30433
30570
  renderer.beginCluster?.(sg, job);
30434
30571
  if (job.obj !== null) job.obj.id = svgClusterId(sg, job);
30435
30572
  setHtmlAnchorObj(svgClusterId(sg, job), labelTextOf2(sg.info.label), job.obj ?? void 0);
30436
- if (job.obj !== null) {
30437
- resolveObjAnchor(sg, labelTextOf2(sg.info.label), svgClusterId(sg, job), job.obj);
30438
- }
30439
- const anchored = beginAnchorIf(renderer, job);
30573
+ if (job.obj !== null) resolveObjAnchor(sg, labelTextOf2(sg.info.label), svgClusterId(sg, job), job.obj);
30574
+ const late = (job.flags & EMIT_CLUSTERS_LAST) !== 0;
30575
+ const anchored = !late && beginClusterAnchor(sg, renderer, job);
30440
30576
  if ((clusterPeripheries(sg) !== 0 || filled || isStripedCluster(sg)) && job.obj?.pen !== 0 /* None */) {
30441
30577
  renderClusterBox(sg, filled, renderer, job);
30442
30578
  }
30443
30579
  renderClusterLabel(sg, renderer, job);
30444
- if (anchored) renderer.endAnchor?.(job);
30580
+ if (anchored || late && beginClusterAnchor(sg, renderer, job)) renderer.endAnchor?.(job);
30445
30581
  renderer.endCluster?.(sg, job);
30446
30582
  }
30447
- function renderOneCluster(sg, renderer, job) {
30583
+ function renderOneCluster(sg, renderer, job, info) {
30448
30584
  const clustersLast = (job.flags & EMIT_CLUSTERS_LAST) !== 0;
30449
- if (clustersLast) renderClusters(sg, renderer, job);
30585
+ if (clustersLast) renderClusters(sg, renderer, job, info);
30450
30586
  const obj = createObjState(1 /* Cluster */);
30451
30587
  obj.emitState = 1 /* CDraw */;
30452
30588
  job.pushObj(obj);
@@ -30455,15 +30591,15 @@ function renderOneCluster(sg, renderer, job) {
30455
30591
  } finally {
30456
30592
  job.popObj();
30457
30593
  }
30458
- if (!clustersLast) renderClusters(sg, renderer, job);
30594
+ if (!clustersLast) renderClusters(sg, renderer, job, info);
30459
30595
  }
30460
- function renderClusters(g, renderer, job) {
30596
+ function renderClusters(g, renderer, job, info) {
30461
30597
  const nClust = g.info.n_cluster ?? 0;
30462
30598
  const clust = g.info.clust;
30463
30599
  if (nClust === 0 || !clust) return;
30464
30600
  for (let c = 0; c < nClust; c++) {
30465
30601
  const sg = clust[c];
30466
- if (sg) renderOneCluster(sg, renderer, job);
30602
+ if (sg && clusterShown(info, job, sg)) renderOneCluster(sg, renderer, job, info);
30467
30603
  }
30468
30604
  }
30469
30605
  function renderGraph(g, job, renderer) {
@@ -30502,9 +30638,9 @@ function renderPage(g, renderer, job, info) {
30502
30638
  });
30503
30639
  if (anchored) renderer.endAnchor?.(job);
30504
30640
  const clustersLast = (job.flags & EMIT_CLUSTERS_LAST) !== 0;
30505
- if (!clustersLast) renderClusters(g, renderer, job);
30641
+ if (!clustersLast) renderClusters(g, renderer, job, info);
30506
30642
  walkNodesAndEdges(g, renderer, job, info);
30507
- if (clustersLast) renderClusters(g, renderer, job);
30643
+ if (clustersLast) renderClusters(g, renderer, job, info);
30508
30644
  renderer.endPage?.(g, job);
30509
30645
  }
30510
30646
  function newRenderJob(ctx, format, inlineImages) {
@@ -30537,6 +30673,7 @@ function render(ctx, g, format, inlineImages = false) {
30537
30673
  job.scale = { x: z * dpiScale, y: z * dpiScale };
30538
30674
  job.rotation = parseLandscape(g) ? 90 : 0;
30539
30675
  job.renderer = renderer;
30676
+ job.drawingId = drawingIdOf(g);
30540
30677
  setRendererKnownColors(renderer.type === "svg");
30541
30678
  resetHtmlAnchorIds();
30542
30679
  for (const n of g.nodes.values()) polyInit(n, g, job.measurer);
@@ -32355,7 +32492,7 @@ function flatEdges(g) {
32355
32492
  }
32356
32493
 
32357
32494
  // src/layout/dot/position.ts
32358
- var INT_MAX3 = 2147483647;
32495
+ var INT_MAX5 = 2147483647;
32359
32496
  function setXcoordsFromRank(g) {
32360
32497
  const rankArr = g.info.rank;
32361
32498
  for (let i = graphMinrank(g); i <= graphMaxrank(g); i++) {
@@ -32404,7 +32541,7 @@ function connectGraph(g) {
32404
32541
  }
32405
32542
  function nsiter2(g) {
32406
32543
  const s = g.attrs.get("nslimit") ?? g.graphDefaultsSnapshot?.get("nslimit") ?? g.root.attrs.get("nslimit") ?? agGraphAttr(g.root, "nslimit");
32407
- if (s === void 0) return INT_MAX3;
32544
+ if (s === void 0) return INT_MAX5;
32408
32545
  return scaleClamp(g.nodes.size, parseFloat(s) || 0);
32409
32546
  }
32410
32547
  function expandRankSlots(rk, newN) {
@@ -36811,11 +36948,11 @@ function maxOutputline() {
36811
36948
  function setMaxOutputline(n) {
36812
36949
  maxOutputlineValue = n;
36813
36950
  }
36814
- var INT_MAX4 = 2147483647;
36951
+ var INT_MAX6 = 2147483647;
36815
36952
  function linelengthOf(s) {
36816
36953
  if (s === void 0 || !/^[0-9]/.test(s)) return void 0;
36817
36954
  const len = Number(/^[0-9]+/.exec(s)[0]);
36818
- if ((len === 0 || len >= MIN_OUTPUTLINE) && len <= INT_MAX4) return len;
36955
+ if ((len === 0 || len >= MIN_OUTPUTLINE) && len <= INT_MAX6) return len;
36819
36956
  return void 0;
36820
36957
  }
36821
36958
  function withLinelength(g, write) {
@@ -37107,16 +37244,13 @@ function cmapxShape(shape) {
37107
37244
  return "poly";
37108
37245
  }
37109
37246
  function cmapxCoordsRect(pts) {
37110
- 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));
37247
+ return printfFixed0(pts[0].x) + "," + printfFixed0(pts[1].y) + "," + printfFixed0(pts[1].x) + "," + printfFixed0(pts[0].y);
37111
37248
  }
37112
37249
  function cmapxCoordsCircle(pts) {
37113
- const cx = Math.round(pts[0].x);
37114
- const cy = Math.round(pts[0].y);
37115
- const r = Math.round(pts[1].x - pts[0].x);
37116
- return String(cx) + "," + String(cy) + "," + String(r);
37250
+ return printfFixed0(pts[0].x) + "," + printfFixed0(pts[0].y) + "," + printfFixed0(pts[1].x - pts[0].x);
37117
37251
  }
37118
37252
  function cmapxCoordsPoly(pts) {
37119
- return pts.map((p) => String(Math.round(p.x)) + "," + String(Math.round(p.y))).join(",");
37253
+ return pts.map((p) => printfFixed0(p.x) + "," + printfFixed0(p.y)).join(",");
37120
37254
  }
37121
37255
  function cmapxCoords(shape, pts) {
37122
37256
  if (shape === 1 /* Circle */) return cmapxCoordsCircle(pts);
@@ -37139,12 +37273,11 @@ function mapOutputCmapx(shape, pts, a, isXml, out) {
37139
37273
  function mapOutputImap(shape, pts, url, out) {
37140
37274
  if (!url) return;
37141
37275
  if (shape === 0 /* Rectangle */) {
37142
- 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");
37276
+ out.push("rect " + url + " " + printfFixed0(pts[0].x) + "," + printfFixed0(pts[1].y) + " " + printfFixed0(pts[1].x) + "," + printfFixed0(pts[0].y) + "\n");
37143
37277
  } else if (shape === 1 /* Circle */) {
37144
- const r = Math.round(pts[1].x - pts[0].x);
37145
- out.push("circle " + url + " " + Math.round(pts[0].x) + "," + Math.round(pts[0].y) + "," + String(r) + "\n");
37278
+ out.push("circle " + url + " " + printfFixed0(pts[0].x) + "," + printfFixed0(pts[0].y) + "," + printfFixed0(pts[1].x - pts[0].x) + "\n");
37146
37279
  } else {
37147
- const pairs = pts.map((p) => Math.round(p.x) + "," + Math.round(p.y)).join(" ");
37280
+ const pairs = pts.map((p) => printfFixed0(p.x) + "," + printfFixed0(p.y)).join(" ");
37148
37281
  out.push("poly " + url + " " + pairs + "\n");
37149
37282
  }
37150
37283
  }
@@ -37222,11 +37355,13 @@ function graphMapUrl(g) {
37222
37355
  }
37223
37356
  function buildMapCtx(g, job, mapPolygon) {
37224
37357
  const drawingDpi = lateDouble(g.attrs.get("dpi"), lateDouble(g.attrs.get("resolution"), 0, 0), 0);
37225
- const mapDpi = drawingDpi > 0 ? drawingDpi : 96;
37226
- const devscale = mapDpi / POINTS_PER_INCH;
37227
- const z = initJobViewportZoom(job.bb, parseDrawingSize(g.attrs.get("size")), job.pad);
37228
- const marginOff = { x: job.margin.x * devscale, y: job.margin.y * devscale };
37229
- return { bb: job.bb, pad: job.pad, scale: z * devscale, marginOff, mapPolygon };
37358
+ const devscale = (drawingDpi > 0 ? drawingDpi : 96) / POINTS_PER_INCH;
37359
+ const size = parseDrawingSize(g.attrs.get("size"));
37360
+ const z = initJobViewportZoom(job.bb, size, job.pad);
37361
+ const clip = setupPageClip(job.bb, size, job.pad, z);
37362
+ const pageBox = setupPageBox(setupPageSize(job.bb, size, job.pad, z), job.pad);
37363
+ const translation = { x: -clip.ll.x + job.margin.x / z, y: -clip.ur.y - job.margin.y / z };
37364
+ return { pageBox, translation, scale: { x: z * devscale, y: z * -devscale }, mapPolygon };
37230
37365
  }
37231
37366
  function anchorOf(url, tooltip, target, id) {
37232
37367
  return { url: url ?? "", tooltip: tooltip ?? "", target: target ?? "", id: id ?? "" };
@@ -37261,12 +37396,6 @@ var MapRendererBase = class {
37261
37396
  beginNode(n, job) {
37262
37397
  if (this.mapCtx !== null && job.obj !== null) computeNodeUrlMap(n, job.obj, this.mapCtx);
37263
37398
  }
37264
- beginCluster(sg, job) {
37265
- const bb = sg.info.bb;
37266
- if (this.mapCtx !== null && job.obj !== null && bb !== void 0) {
37267
- computeClusterUrlMap(bb, job.obj, this.mapCtx);
37268
- }
37269
- }
37270
37399
  endEdge(e, job) {
37271
37400
  if (this.mapCtx !== null && job.obj !== null) this.emitEdge(e, job.obj, job);
37272
37401
  }
@@ -37321,30 +37450,34 @@ var MapRendererBase = class {
37321
37450
  url: obj.labelUrl,
37322
37451
  tooltip: obj.labelTooltip,
37323
37452
  target: obj.labelTarget,
37324
- explicit: obj.explicitLabelTooltip
37453
+ explicit: obj.explicitLabelTooltip,
37454
+ suffix: "label"
37325
37455
  };
37326
37456
  this.emitEdgeLabel(e.info.label, centerA, obj, job);
37327
37457
  this.emitEdgeLabel(e.info.xlabel, centerA, obj, job);
37328
- this.emitEdgeLabel(
37329
- e.info.head_label,
37330
- { url: obj.headUrl, tooltip: obj.headTooltip, target: obj.headTarget, explicit: obj.explicitHeadTooltip },
37331
- obj,
37332
- job
37333
- );
37334
- this.emitEdgeLabel(
37335
- e.info.tail_label,
37336
- { url: obj.tailUrl, tooltip: obj.tailTooltip, target: obj.tailTarget, explicit: obj.explicitTailTooltip },
37337
- obj,
37338
- job
37339
- );
37340
- }
37341
- /** One edge label hot spot (map_label rect), if placed and url/explicit-tip.
37342
- * @see lib/common/emit.c:emit_edge_label */
37458
+ this.emitEdgeLabel(e.info.head_label, {
37459
+ url: obj.headUrl,
37460
+ tooltip: obj.headTooltip,
37461
+ target: obj.headTarget,
37462
+ explicit: obj.explicitHeadTooltip,
37463
+ suffix: "headlabel"
37464
+ }, obj, job);
37465
+ this.emitEdgeLabel(e.info.tail_label, {
37466
+ url: obj.tailUrl,
37467
+ tooltip: obj.tailTooltip,
37468
+ target: obj.tailTarget,
37469
+ explicit: obj.explicitTailTooltip,
37470
+ suffix: "taillabel"
37471
+ }, obj, job);
37472
+ }
37473
+ /** One edge label hot spot (map_label rect), if placed and url/explicit-tip; its id is
37474
+ * `<obj.id>-<suffix>` (C: `if (id)`, else NULL). @see lib/common/emit.c:emit_edge_label (2851-2876) */
37343
37475
  emitEdgeLabel(lab, la, obj, job) {
37344
37476
  const placed = lab !== void 0 && lab.set && this.mapCtx !== null;
37345
37477
  if (!placed || la.url === null && !la.explicit) return;
37346
37478
  computeLabelRectMap(lab, obj, this.mapCtx);
37347
- this.emitShape(0 /* Rectangle */, obj.urlMapPts, anchorOf(la.url, la.tooltip, la.target, obj.id), job);
37479
+ const id = obj.id === null ? null : `${obj.id}-${la.suffix}`;
37480
+ this.emitShape(0 /* Rectangle */, obj.urlMapPts, anchorOf(la.url, la.tooltip, la.target, id), job);
37348
37481
  }
37349
37482
  };
37350
37483
  var ImapRenderer = class extends MapRendererBase {
@@ -40119,15 +40252,18 @@ function buildArrays(gp, nObjs, nLbls, nClbls, et) {
40119
40252
  return { ctx };
40120
40253
  }
40121
40254
  function writeBackLabels(gp, lbls, nLbls) {
40255
+ let cnt = 0;
40122
40256
  for (let i = 0; i < nLbls; i++) {
40123
40257
  const xlp = lbls[i];
40124
40258
  if (xlp.set) {
40259
+ cnt++;
40125
40260
  const lp = xlp.lbl;
40126
40261
  lp.set = true;
40127
40262
  lp.pos = centerPt(xlp);
40128
40263
  updateBBForLabel(gp, lp);
40129
40264
  }
40130
40265
  }
40266
+ return cnt;
40131
40267
  }
40132
40268
  var XLABEL_WORK_MASK = NODE_XLABEL | EDGE_XLABEL | TAIL_LABEL | HEAD_LABEL;
40133
40269
  function needsXLabelWork(gp) {
@@ -40148,7 +40284,10 @@ function runPlacement(gp) {
40148
40284
  const force = forceStr === void 0 ? true : mapbool(forceStr);
40149
40285
  const params = { bb: { ll: ctx.bb.ll, ur: ctx.bb.ur }, force };
40150
40286
  placeLabels(ctx.objs, ctx.lbls, params);
40151
- writeBackLabels(gp, ctx.lbls, nLbls);
40287
+ const cnt = writeBackLabels(gp, ctx.lbls, nLbls);
40288
+ if (cnt !== nLbls) {
40289
+ agwarningf(`${cnt} out of ${nLbls} exterior labels positioned.`);
40290
+ }
40152
40291
  }
40153
40292
  function addXLabels(gp) {
40154
40293
  if (!needsXLabelWork(gp)) return;
@@ -42083,19 +42222,6 @@ function boxIntersectf(pp, cp, bb) {
42083
42222
  }
42084
42223
 
42085
42224
  // src/layout/dot/compound.ts
42086
- function fillClustMap(g, map) {
42087
- const nc = g.info.n_cluster ?? 0;
42088
- for (let c = 1; c <= nc; c++) {
42089
- const cl = g.info.clust[c - 1];
42090
- if (!map.has(cl.name)) map.set(cl.name, cl);
42091
- fillClustMap(cl, map);
42092
- }
42093
- }
42094
- function mkClustMap2(g) {
42095
- const map = /* @__PURE__ */ new Map();
42096
- fillClustMap(g, map);
42097
- return map;
42098
- }
42099
42225
  function arrowEndClipIdx(state3, endp) {
42100
42226
  const { e, bez } = state3;
42101
42227
  const elen = arrowClipLength(edgeArrowName(e, "head"), edgeArrowsize(e), edgePenwidthAttr(e));
@@ -42246,7 +42372,7 @@ function makeCompoundEdge(e, clustMap) {
42246
42372
  if (tailClipped && bez.sflag) restashArrow(e, bez.sp, bez.list[0], true);
42247
42373
  }
42248
42374
  function dotCompoundEdges(g) {
42249
- const clustMap = mkClustMap2(g);
42375
+ const clustMap = mkClustMap(g);
42250
42376
  for (const e of g.edges) makeCompoundEdge(e, clustMap);
42251
42377
  }
42252
42378
 
@@ -53736,7 +53862,7 @@ function springElectricalEmbedding(dim, A0, ctrl, x) {
53736
53862
 
53737
53863
  // src/layout/sfdp/init.ts
53738
53864
  var SMOOTHING_NONE = 0;
53739
- var INT_MAX5 = 2147483647;
53865
+ var INT_MAX7 = 2147483647;
53740
53866
  var ELSCHEME_PENALTY2 = 2;
53741
53867
  var EDGE_LABEL_NODE_PREFIX = "|edgelabel|";
53742
53868
  function sfdpInitDim(g) {
@@ -53805,7 +53931,7 @@ function tuneControl(g, ctrl) {
53805
53931
  }
53806
53932
  ctrl.K = lateDouble(aggetGraph(g, "K"), -1, 0);
53807
53933
  ctrl.p = -1 * lateDouble(aggetGraph(g, "repulsiveforce"), -AUTOP, 0);
53808
- ctrl.multilevels = lateInt(aggetGraph(g, "levels"), INT_MAX5, 0);
53934
+ ctrl.multilevels = lateInt(aggetGraph(g, "levels"), INT_MAX7, 0);
53809
53935
  const smoothing = aggetGraph(g, "smoothing");
53810
53936
  if (smoothing !== void 0 && smoothing.toLowerCase() !== "none" && smoothing !== String(SMOOTHING_NONE)) {
53811
53937
  throw new RenderError(
@@ -54804,7 +54930,7 @@ var AM_PORTHOXY = 11;
54804
54930
  var AM_PORTHOYX = 12;
54805
54931
  var SCALE = 10;
54806
54932
  var SCALE2 = SCALE / 2;
54807
- var INT_MAX6 = 2147483647;
54933
+ var INT_MAX8 = 2147483647;
54808
54934
  var POINTS_PER_INCH6 = 72;
54809
54935
  function cmpitem(a, b) {
54810
54936
  if (a < b) return -1;
@@ -54924,7 +55050,7 @@ function mkNConstraintG(g, list, intersect, dist5) {
54924
55050
  return cg;
54925
55051
  }
54926
55052
  function buildChain(cg, flat) {
54927
- let oldval = -INT_MAX6;
55053
+ let oldval = -INT_MAX8;
54928
55054
  let prev;
54929
55055
  let n;
54930
55056
  let lastn;
@@ -54946,7 +55072,7 @@ function buildChain(cg, flat) {
54946
55072
  }
54947
55073
  function buildVisibility(flat, intersect) {
54948
55074
  const vg = flat.map(() => []);
54949
- let oldval = -INT_MAX6;
55075
+ let oldval = -INT_MAX8;
54950
55076
  let nxt = flat.length;
54951
55077
  for (let i = 0; i < flat.length; i++) {
54952
55078
  const p = flat[i];
@@ -54997,7 +55123,7 @@ function constrainX(g, nlist, ifn, ortho) {
54997
55123
  list.insert(p);
54998
55124
  }
54999
55125
  const cg = buildConstraintGraph(g, list, ifn, distX, ortho);
55000
- rank(cg.g, 2, INT_MAX6);
55126
+ rank(cg.g, 2, INT_MAX8);
55001
55127
  for (const p of nlist) {
55002
55128
  const newpos = cnodeOf(p).info.rank ?? 0;
55003
55129
  const delta2 = newpos - p.pos.x;
@@ -55013,7 +55139,7 @@ function constrainY(g, nlist, ifn, ortho) {
55013
55139
  list.insert(p);
55014
55140
  }
55015
55141
  const cg = buildConstraintGraph(g, list, ifn, distY, ortho);
55016
- rank(cg.g, 2, INT_MAX6);
55142
+ rank(cg.g, 2, INT_MAX8);
55017
55143
  for (const p of nlist) {
55018
55144
  const newpos = cnodeOf(p).info.rank ?? 0;
55019
55145
  const delta2 = newpos - p.pos.y;
@@ -60310,7 +60436,7 @@ function emitAttachment(lp, spl, renderer, job) {
60310
60436
 
60311
60437
  // src/render/svg-cluster.ts
60312
60438
  function svgBeginCluster(sg, job) {
60313
- job.write('<g id="' + escapeXmlTitle(job.idLayerPrefix() + svgClusterId(sg, job)) + '" ' + svgClusterClass(sg) + ">\n");
60439
+ job.write('<g id="' + escapeXmlTitle(svgClusterId(sg, job)) + '" ' + svgClusterClass(sg) + ">\n");
60314
60440
  job.write("<title>" + escapeXmlTitle(sg.name) + "</title>\n");
60315
60441
  }
60316
60442
  function svgEndCluster(job) {
@@ -60689,6 +60815,7 @@ function writeDictSkips(v, inherited) {
60689
60815
  function echoGraphAttr(g, key) {
60690
60816
  const v = g.attrs.get(key);
60691
60817
  if (v === void 0) return [];
60818
+ if (g.seededAttrs?.has(key) === true) return [];
60692
60819
  if (writeDictSkips(v, g.graphDefaultsSnapshot?.get(key))) return [];
60693
60820
  return [`${key}=${agstrcanon(v)}`];
60694
60821
  }
@@ -60734,7 +60861,7 @@ function isDirected(g) {
60734
60861
 
60735
60862
  // src/render/dot/agwrite.ts
60736
60863
  var DotWriterBase = class {
60737
- /** Clusters in render order (GD_clust); filled by the renderer's endCluster. */
60864
+ /** The clusters xdot_end_cluster ran for (not all of GD_clust: inClusterTree). */
60738
60865
  clusters = [];
60739
60866
  /**
60740
60867
  * Emit `key=<canon value>` through `_agstrcanon`, as `agwrite` does for the xdot
@@ -60801,7 +60928,7 @@ var DotWriterBase = class {
60801
60928
  * a boxed graph and an unboxed child — the driver that makes an anon subgraph
60802
60929
  * under the root or a cluster "relevant". @see lib/common/output.c:safe_dcl */
60803
60930
  hasBb(g) {
60804
- return g === g.root || this.clusters.includes(g);
60931
+ return g === g.root || inClusterTree(g);
60805
60932
  }
60806
60933
  /** Anonymous subgraph with no own node/edge defaults and no graph attrs
60807
60934
  * differing from its parent → inlined into the parent. Native compares every
@@ -60809,7 +60936,7 @@ var DotWriterBase = class {
60809
60936
  * the parent, empty on the child) and `rank`. @see write.c:irrelevant_subgraph */
60810
60937
  irrelevantSubgraph(g) {
60811
60938
  if (!this.isAnonymous(g)) return false;
60812
- if (this.clusters.includes(g)) return false;
60939
+ if (inClusterTree(g)) return false;
60813
60940
  if (g.nodeDefaults.size > 0 || g.edgeDefaults.size > 0) return false;
60814
60941
  if (g.parent) {
60815
60942
  if (this.hasBb(g) !== this.hasBb(g.parent)) return false;
@@ -60827,9 +60954,8 @@ var DotWriterBase = class {
60827
60954
  * `rec_attach_bb` walks the ROOT and then `GD_clust` recursively, so a
60828
60955
  * subgraph the layout did not box is attached NEITHER `bb` NOR the label
60829
60956
  * triple — both keep the INPUT's values, which agwrite echoes. circo and
60830
- * twopi lay out no clusters at all (`GD_clust` empty — mirrored here by
60831
- * `this.clusters`, filled from endCluster), so on a re-fed dot output their
60832
- * `cluster0` comes back carrying the *previous* run's `bb` and `lp`.
60957
+ * twopi lay out no clusters (`GD_clust` empty, `inClusterTree` false), so on a
60958
+ * re-fed dot output `cluster0` carries the *previous* run's `bb` and `lp`.
60833
60959
  * @see lib/common/output.c:249 rec_attach_bb */
60834
60960
  subgGraphAttrs(sg) {
60835
60961
  const parts = [];
@@ -60861,7 +60987,7 @@ var DotWriterBase = class {
60861
60987
  * order. @see lib/cgraph/write.c:307 write_dicts
60862
60988
  */
60863
60989
  writeDicts(g, top, ctx) {
60864
- const graphParts = top ? this.graphAttrs(g) : this.clusters.includes(g) ? this.clusterAttrs(g) : this.subgGraphAttrs(g);
60990
+ const graphParts = top ? this.graphAttrs(g) : inClusterTree(g) ? this.clusterAttrs(g) : this.subgGraphAttrs(g);
60865
60991
  this.writeDict("graph", graphParts, ctx);
60866
60992
  this.writeDict("node", nodeDictParts(g, top), ctx);
60867
60993
  this.writeDict("edge", dictParts(g.edgeDefaults), ctx);
@@ -61042,13 +61168,14 @@ var DotWriterBase = class {
61042
61168
  parts.push(...graphInputParts(g, true, this.emitDraws));
61043
61169
  return parts;
61044
61170
  }
61045
- /** Cluster attribute block. C's xdot_end_cluster ALWAYS agsets `_draw_` when
61046
- * the graph has clusters (even empty, e.g. peripheries=0), so emit it
61047
- * unconditionally; `_ldraw_` only when the cluster has a label.
61171
+ /** Cluster attribute block. C's xdot_end_cluster ALWAYS agsets `_draw_` for a
61172
+ * cluster it ran for (even empty, e.g. peripheries=0); one that emit_clusters
61173
+ * skipped (clust_in_layer) keeps only a stored one. `_ldraw_` only with a label.
61048
61174
  * @see plugin/core/gvrender_core_dot.c:284 xdot_end_cluster */
61049
61175
  clusterAttrs(sg) {
61050
61176
  const d = this.drawsOf(sg);
61051
- const parts = this.emitDraws || d?.draw ? [this.drawAttr("_draw_", d?.draw ?? "")] : [];
61177
+ const drawn = this.emitDraws && this.clusters.includes(sg);
61178
+ const parts = drawn || d?.draw ? [this.drawAttr("_draw_", d?.draw ?? "")] : [];
61052
61179
  if (d?.ldraw) parts.push(this.drawAttr("_ldraw_", d.ldraw));
61053
61180
  if (sg.info.bb) parts.push('bb="' + this.bbStr(sg) + '"');
61054
61181
  parts.push(...graphLabelAttrs(sg));
@@ -62156,7 +62283,7 @@ function collectDrawLookup(g) {
62156
62283
  for (const [nm, gChild] of gSub.subgraphs) {
62157
62284
  const xgChild = xgSub.subgraphs.get(nm);
62158
62285
  if (xgChild !== void 0) {
62159
- cluster.set(gChild, new Map(xgChild.attrs));
62286
+ cluster.set(gChild, localGraphAttrs(xgChild));
62160
62287
  correlate(gChild, xgChild);
62161
62288
  } else {
62162
62289
  correlate(gChild, xgSub);
@@ -62336,7 +62463,7 @@ function buildEdgesArray(g, ctx) {
62336
62463
  }
62337
62464
  function buildGraphObject(g, top, ctx) {
62338
62465
  const o = {};
62339
- o.name = g.name;
62466
+ o.name = agNameOf(g);
62340
62467
  if (top) {
62341
62468
  o.directed = g.kind === "directed" || g.kind === "strict-directed";
62342
62469
  o.strict = g.kind === "strict-directed" || g.kind === "strict-undirected";
@@ -62412,11 +62539,16 @@ var Json0Renderer = class extends JsonRendererBase {
62412
62539
  type = "json0";
62413
62540
  beginGraph(_g, _job) {
62414
62541
  }
62415
- /** C's json_begin_graph runs attach_attrs; buildJson overlays the same values. */
62542
+ /**
62543
+ * Attach, then write: C's json_begin_graph runs attach_attrs (which ends by
62544
+ * undoing cluster edges) before json_end_graph writes, and json0 prints what
62545
+ * that stored. Nothing overlays `bb` or an edge's `pos` here, as json's xdot
62546
+ * draw lookup does, so the write-back cannot wait until after the write.
62547
+ * @see plugin/core/gvrender_core_json.c:json_begin_graph
62548
+ */
62416
62549
  endGraph(g, job) {
62417
- const later = attachBeforeWriteWithClusterEdges(g, () => attachAttrs(g));
62550
+ attachBeforeWriteWithClusterEdges(g, () => attachAttrs(g))();
62418
62551
  job.write(buildJson(g, false));
62419
- later();
62420
62552
  }
62421
62553
  };
62422
62554
  var JsonRenderer = class extends JsonRendererBase {
@@ -63247,6 +63379,7 @@ function classifyError(err) {
63247
63379
  };
63248
63380
  if (gv.location !== void 0) out.location = gv.location;
63249
63381
  if (gv.expected !== void 0) out.expected = gv.expected;
63382
+ if (gv.context !== void 0) out.context = { ...gv.context };
63250
63383
  return out;
63251
63384
  }
63252
63385
  function renderSvg(dotSource, engine) {