@standarx/graph 0.0.0-stage → 1.1.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 (127) hide show
  1. package/LICENSE +21 -0
  2. package/README.fr.md +438 -0
  3. package/README.md +437 -2
  4. package/THIRD_PARTY_NOTICES.md +22 -0
  5. package/assets/fonts/Inter-Regular.ttf +0 -0
  6. package/assets/fonts/Inter-SemiBold.ttf +0 -0
  7. package/assets/fonts/OFL.txt +92 -0
  8. package/dist/adapter-0bggwh8x.js +393 -0
  9. package/dist/cli-4m00785g.js +20 -0
  10. package/dist/cli-5v9761s9.js +330 -0
  11. package/dist/cli-9f1pdw5q.js +462 -0
  12. package/dist/cli-a4ax1vkc.js +172 -0
  13. package/dist/cli-abzdy8pn.js +1144 -0
  14. package/dist/cli-gh5166k6.js +1565 -0
  15. package/dist/cli-m29a3wgx.js +579 -0
  16. package/dist/cli-mzmjkk5v.js +11 -0
  17. package/dist/cli-nhmh6yxk.js +2485 -0
  18. package/dist/cli-nyckgf1t.js +4 -0
  19. package/dist/cli-sfdqkbd1.js +433 -0
  20. package/dist/cli-txrzzr2q.js +0 -0
  21. package/dist/cli-vecew2na.js +709 -0
  22. package/dist/cli-wt9dmbhm.js +560 -0
  23. package/dist/cli-ywgtv1cg.js +39 -0
  24. package/dist/cli-z3ccx2y4.js +141 -0
  25. package/dist/cli.d.ts +2 -0
  26. package/dist/cli.js +413 -0
  27. package/dist/core/index.d.ts +6 -0
  28. package/dist/core/index.js +91 -0
  29. package/dist/core/spatial.d.ts +16 -0
  30. package/dist/core/threshold.d.ts +1 -0
  31. package/dist/core/view.d.ts +80 -0
  32. package/dist/export/index.d.ts +18 -0
  33. package/dist/export/index.js +170 -0
  34. package/dist/export/pdf.d.ts +5 -0
  35. package/dist/export/png.d.ts +4 -0
  36. package/dist/format/index.d.ts +4 -0
  37. package/dist/format/index.js +69 -0
  38. package/dist/format/json-schema.d.ts +2 -0
  39. package/dist/format/schema.d.ts +787 -0
  40. package/dist/format/semantic/er.d.ts +3 -0
  41. package/dist/format/semantic/graph.d.ts +3 -0
  42. package/dist/format/semantic/sequence.d.ts +3 -0
  43. package/dist/format/semantic/shared.d.ts +14 -0
  44. package/dist/format/semantic/state.d.ts +3 -0
  45. package/dist/format/semantic/tree.d.ts +3 -0
  46. package/dist/format/transition-label.d.ts +2 -0
  47. package/dist/format/validate.d.ts +11 -0
  48. package/dist/html/index.d.ts +3 -0
  49. package/dist/html/index.js +125 -0
  50. package/dist/html/layout-worker.d.ts +1 -0
  51. package/dist/html/layout-worker.generated.d.ts +1 -0
  52. package/dist/html/mount.d.ts +12 -0
  53. package/dist/html/page.d.ts +14 -0
  54. package/dist/html/render.d.ts +7 -0
  55. package/dist/html/runtime.d.ts +1 -0
  56. package/dist/html/runtime.generated.d.ts +1 -0
  57. package/dist/html/shell.d.ts +10 -0
  58. package/dist/html/svg-adapter.d.ts +8 -0
  59. package/dist/html/ui.d.ts +34 -0
  60. package/dist/language/actions.d.ts +3 -0
  61. package/dist/language/analysis.d.ts +38 -0
  62. package/dist/language/complete.d.ts +3 -0
  63. package/dist/language/diagnostics.d.ts +14 -0
  64. package/dist/language/docs.d.ts +11 -0
  65. package/dist/language/format.d.ts +17 -0
  66. package/dist/language/hover.d.ts +3 -0
  67. package/dist/language/index.d.ts +8 -0
  68. package/dist/language/index.js +1560 -0
  69. package/dist/language/navigation.d.ts +9 -0
  70. package/dist/language/positions.d.ts +7 -0
  71. package/dist/language/symbols.d.ts +3 -0
  72. package/dist/language/types.d.ts +46 -0
  73. package/dist/layout/elk.d.ts +35 -0
  74. package/dist/layout/er.d.ts +3 -0
  75. package/dist/layout/font-metrics.d.ts +9 -0
  76. package/dist/layout/graph.d.ts +3 -0
  77. package/dist/layout/index.d.ts +5 -0
  78. package/dist/layout/index.js +16 -0
  79. package/dist/layout/measure.d.ts +10 -0
  80. package/dist/layout/sequence.d.ts +3 -0
  81. package/dist/layout/shapes.d.ts +16 -0
  82. package/dist/layout/shared.d.ts +31 -0
  83. package/dist/layout/state.d.ts +3 -0
  84. package/dist/layout/tree.d.ts +3 -0
  85. package/dist/layout/types.d.ts +198 -0
  86. package/dist/layout-worker.generated-xsmtzrfj.js +34 -0
  87. package/dist/mermaid/common.d.ts +36 -0
  88. package/dist/mermaid/er.d.ts +3 -0
  89. package/dist/mermaid/graph.d.ts +4 -0
  90. package/dist/mermaid/index.d.ts +6 -0
  91. package/dist/mermaid/index.js +6 -0
  92. package/dist/mermaid/mindmap.d.ts +3 -0
  93. package/dist/mermaid/sequence.d.ts +3 -0
  94. package/dist/mermaid/state.d.ts +3 -0
  95. package/dist/remark/index.d.ts +9 -0
  96. package/dist/remark/index.js +102 -0
  97. package/dist/shared/errors.d.ts +6 -0
  98. package/dist/shared/package-root.d.ts +5 -0
  99. package/dist/svg/escape.d.ts +1 -0
  100. package/dist/svg/index.d.ts +3 -0
  101. package/dist/svg/index.js +25 -0
  102. package/dist/svg/render.d.ts +9 -0
  103. package/dist/svg/theme.d.ts +62 -0
  104. package/dist/svg-adapter-gq5vmp6q.js +227 -0
  105. package/dist/text/build.d.ts +10 -0
  106. package/dist/text/canonical.d.ts +10 -0
  107. package/dist/text/errors.d.ts +33 -0
  108. package/dist/text/highlight.d.ts +13 -0
  109. package/dist/text/index.d.ts +33 -0
  110. package/dist/text/index.js +25 -0
  111. package/dist/text/lexer.d.ts +29 -0
  112. package/dist/text/parser.d.ts +160 -0
  113. package/dist/text/print.d.ts +6 -0
  114. package/dist/text/slug.d.ts +1 -0
  115. package/dist/text/syntax.d.ts +8 -0
  116. package/dist/version.d.ts +1 -0
  117. package/dist/webgl/adapter.d.ts +4 -0
  118. package/dist/webgl/index.d.ts +7 -0
  119. package/dist/webgl/index.js +15 -0
  120. package/dist/webgl/runtime.d.ts +1 -0
  121. package/dist/webgl/runtime.generated.d.ts +1 -0
  122. package/grammars/standargraph.tmLanguage.json +599 -0
  123. package/language-configuration.json +35 -0
  124. package/licenses/EPL-2.0.txt +277 -0
  125. package/licenses/MPL-2.0.txt +373 -0
  126. package/package.json +133 -4
  127. package/schema/graph-document.v1.json +1737 -0
@@ -0,0 +1,172 @@
1
+ import {
2
+ typesPresent,
3
+ isAdaptive,
4
+ themeStyle
5
+ } from "./cli-5v9761s9.js";
6
+
7
+ // src/shared/package-root.ts
8
+ import { existsSync, readFileSync } from "node:fs";
9
+ import { dirname, join } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ var cachedRoot;
12
+ var cachedFonts;
13
+ function isPackageRoot(directory) {
14
+ const file = join(directory, "package.json");
15
+ if (!existsSync(file))
16
+ return false;
17
+ try {
18
+ return JSON.parse(readFileSync(file, "utf8")).name === "@standarx/graph";
19
+ } catch {
20
+ return false;
21
+ }
22
+ }
23
+ function packageRoot() {
24
+ if (cachedRoot !== undefined)
25
+ return cachedRoot;
26
+ let directory = dirname(fileURLToPath(import.meta.url));
27
+ for (;; ) {
28
+ if (isPackageRoot(directory)) {
29
+ cachedRoot = directory;
30
+ return directory;
31
+ }
32
+ const parent = dirname(directory);
33
+ if (parent === directory) {
34
+ throw new Error("Cannot locate the standargraph package root");
35
+ }
36
+ directory = parent;
37
+ }
38
+ }
39
+ function loadFonts() {
40
+ if (cachedFonts === undefined) {
41
+ const directory = join(packageRoot(), "assets", "fonts");
42
+ cachedFonts = {
43
+ regular: new Uint8Array(readFileSync(join(directory, "Inter-Regular.ttf"))),
44
+ semibold: new Uint8Array(readFileSync(join(directory, "Inter-SemiBold.ttf")))
45
+ };
46
+ }
47
+ return cachedFonts;
48
+ }
49
+
50
+ // src/html/shell.ts
51
+ var STYLE = [
52
+ "*{box-sizing:border-box}",
53
+ "html,body{margin:0;height:100%}",
54
+ "body{font-family:Inter,system-ui,sans-serif;font-size:14px}",
55
+ ".sg-app{position:fixed;inset:0;display:flex;flex-direction:column;background:var(--sg-bg);color:var(--sg-fg)}",
56
+ ".sg-toolbar{display:flex;align-items:center;gap:8px;padding:8px 12px;border-bottom:1px solid var(--sg-group-stroke);background:var(--sg-group-fill)}",
57
+ ".sg-toolbar .sg-title{flex:1;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
58
+ ".sg-toolbar input,.sg-toolbar button{font:inherit;color:inherit;background:var(--sg-bg);border:1px solid var(--sg-group-stroke);border-radius:6px;padding:4px 10px}",
59
+ ".sg-toolbar button{cursor:pointer;min-width:32px}",
60
+ ".sg-toolbar button:hover{border-color:var(--sg-accent)}",
61
+ ".sg-viewport{position:relative;flex:1;overflow:hidden;cursor:grab;touch-action:none;user-select:none}",
62
+ ".sg-viewport.sg-dragging{cursor:grabbing}",
63
+ ".sg-stage{position:absolute;left:0;top:0;transform-origin:0 0}",
64
+ ".sg-stage svg{display:block}",
65
+ ".sg-groups,.sg-gl{position:absolute;inset:0;width:100%;height:100%}",
66
+ ".sg-mount .sg-app{position:absolute}",
67
+ ".sg-stage [data-kind=node],.sg-stage [data-kind=edge],.sg-stage [data-kind=participant],.sg-stage [data-kind=message],.sg-stage [data-kind=state],.sg-stage [data-kind=transition],.sg-stage [data-kind=entity],.sg-stage [data-kind=relation]{cursor:pointer}",
68
+ ".sg-stage .sg-focus [data-kind]:not(.sg-hl){opacity:.25}",
69
+ ".sg-stage .sg-lod-nolabels .sg-label,.sg-stage .sg-lod-nocaptions .sg-caption,.sg-stage .sg-lod-noedgelabels .sg-edge-label{display:none}",
70
+ ".sg-stage .sg-selected{filter:drop-shadow(0 0 3px var(--sg-accent))}",
71
+ ".sg-panel{position:absolute;top:56px;right:12px;bottom:12px;width:320px;max-width:calc(100% - 24px);overflow:auto;padding:16px;background:var(--sg-bg);border:1px solid var(--sg-group-stroke);border-radius:8px;box-shadow:0 4px 16px rgba(0,0,0,.2)}",
72
+ ".sg-panel[hidden]{display:none}",
73
+ ".sg-panel h2{margin:0 24px 12px 0;font-size:16px;overflow-wrap:anywhere}",
74
+ ".sg-panel .sg-close{position:absolute;top:8px;right:8px;font:inherit;font-size:18px;line-height:1;color:inherit;background:none;border:0;cursor:pointer}",
75
+ ".sg-panel dl{margin:0}",
76
+ ".sg-panel dt{margin-top:10px;font-size:12px;color:var(--sg-muted)}",
77
+ ".sg-panel dd{margin:2px 0 0;overflow-wrap:anywhere}",
78
+ ".sg-panel a{color:var(--sg-accent)}",
79
+ ".sg-panel .sg-data{border-collapse:collapse;width:100%}",
80
+ ".sg-panel .sg-data th,.sg-panel .sg-data td{padding:2px 6px;border:1px solid var(--sg-group-stroke);text-align:left;vertical-align:top}"
81
+ ].join("");
82
+ function escapeHtml(value) {
83
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
84
+ }
85
+ function svgViewport(svg) {
86
+ return `<main class="sg-viewport"><div class="sg-stage">${svg}</div></main>`;
87
+ }
88
+ var WEBGL_VIEWPORT = '<main class="sg-viewport"><canvas class="sg-groups"></canvas><div class="sg-gl"></div></main>';
89
+ function appMarkup(title, viewport, adaptive = false) {
90
+ return [
91
+ '<div class="sg-app">',
92
+ '<header class="sg-toolbar">',
93
+ `<span class="sg-title">${escapeHtml(title)}</span>`,
94
+ '<input class="sg-search" type="search" placeholder="Search" aria-label="Search">',
95
+ '<button class="sg-zoom-out" type="button" aria-label="Zoom out">−</button>',
96
+ '<button class="sg-zoom-in" type="button" aria-label="Zoom in">+</button>',
97
+ '<button class="sg-fit" type="button">Fit</button>',
98
+ ...adaptive ? ['<button class="sg-scheme" type="button" aria-label="Color scheme: auto" title="Color scheme: auto">Auto</button>'] : [],
99
+ "</header>",
100
+ viewport,
101
+ '<aside class="sg-panel" hidden></aside>',
102
+ "</div>"
103
+ ].join(`
104
+ `);
105
+ }
106
+
107
+ // src/html/page.ts
108
+ function escapeScript(value) {
109
+ return value.replace(/<\//g, "<\\/").replace(/<!--/g, "\\u003c!--");
110
+ }
111
+ function base64(bytes) {
112
+ return Buffer.from(bytes).toString("base64");
113
+ }
114
+ function fontFaces() {
115
+ const fonts = loadFonts();
116
+ const face = (weight, bytes) => `@font-face{font-family:Inter;font-style:normal;font-weight:${weight};src:url(data:font/ttf;base64,${base64(bytes)}) format("truetype")}`;
117
+ return face(400, fonts.regular) + face(600, fonts.semibold);
118
+ }
119
+ function withPositions(document, laidOut) {
120
+ if (document.kind !== "graph" || laidOut.kind !== "graph")
121
+ return document;
122
+ const positions = new Map(laidOut.nodes.map((node) => [node.id, { x: node.x, y: node.y }]));
123
+ return {
124
+ ...document,
125
+ nodes: document.nodes.map((node) => ({
126
+ ...node,
127
+ position: positions.get(node.id) ?? node.position
128
+ }))
129
+ };
130
+ }
131
+ function renderPage(content) {
132
+ const { document, laidOut, options } = content;
133
+ const theme = options.theme ?? "auto";
134
+ const title = options.title ?? laidOut.title ?? "Standargraph";
135
+ const json = escapeScript(JSON.stringify(withPositions(document, laidOut)));
136
+ const scene = escapeScript(JSON.stringify(laidOut));
137
+ return [
138
+ "<!doctype html>",
139
+ '<html lang="en">',
140
+ "<head>",
141
+ '<meta charset="utf-8">',
142
+ '<meta name="viewport" content="width=device-width, initial-scale=1">',
143
+ `<title>${escapeHtml(title)}</title>`,
144
+ `<style>${fontFaces()}${STYLE}${themeStyle(theme, typesPresent(laidOut))}</style>`,
145
+ "</head>",
146
+ "<body>",
147
+ appMarkup(title, content.viewport, isAdaptive(theme)),
148
+ `<script type="application/json" id="standargraph-document">${json}</script>`,
149
+ `<script type="application/json" id="standargraph-scene">${scene}</script>`,
150
+ `<script>${escapeScript(content.runtime)}</script>`,
151
+ "</body>",
152
+ "</html>",
153
+ ""
154
+ ].join(`
155
+ `);
156
+ }
157
+
158
+ // src/webgl/runtime.generated.ts
159
+ var WEBGL_RUNTIME_JS = '(()=>{var Mo=Object.create;var{getPrototypeOf:zo,defineProperty:Qa,getOwnPropertyNames:No}=Object;var Ja=Object.prototype.hasOwnProperty;function Go(e){return this[e]}var Oo,Bo,er=(e,a,n)=>{var t=e!=null&&typeof e==="object";if(t){var r=a?Oo??=new WeakMap:Bo??=new WeakMap,i=r.get(e);if(i)return i}n=e!=null?Mo(zo(e)):{};let o=a||!e||!e.__esModule||!Ja.call(e,"default")?Qa(n,"default",{value:e,enumerable:!0}):n;if(e&&typeof e==="object"||typeof e==="function"){for(let s of No(e))if(!Ja.call(o,s))Qa(o,s,{get:Go.bind(e,s),enumerable:!0})}if(t)r.set(e,o);return o};var Wo=(e,a)=>()=>(a||e((a={exports:{}}).exports,a),a.exports);var Ra=Wo(function(ph,Yr){Yr.exports=function(a){return a!==null&&typeof a==="object"&&typeof a.addUndirectedEdgeWithKey==="function"&&typeof a.dropNode==="function"&&typeof a.multi==="boolean"}});var qn=Symbol.for,tt=Symbol("kCapture"),rr=qn("events.errorMonitor"),Uo=Symbol("events.maxEventTargetListeners"),Ho=Symbol("events.maxEventTargetListenersWarned"),tr=qn("nodejs.rejection"),$o=qn("nodejs.rejection"),nr=Array.prototype.slice,nt=10,De=function(e){if(this._events===void 0||this._events===this.__proto__._events)this._events={__proto__:null},this._eventsCount=0;if(this._maxListeners??=void 0,this[tt]=e?.captureRejections?Boolean(e?.captureRejections):he[tt])this.emit=qo},he=De.prototype={};he._events=void 0;he._eventsCount=0;he._maxListeners=void 0;he.setMaxListeners=function(e){return Yn(e,"setMaxListeners",0),this._maxListeners=e,this};he.constructor=De;he.getMaxListeners=function(){return this?._maxListeners??nt};function ir(e,a){var{_events:n}=e;if(a[0]??=Error("Unhandled error."),!n)throw a[0];var t=n[rr];if(t)for(var r of nr.call(t))r.apply(e,a);var i=n.error;if(!i)throw a[0];for(var r of nr.call(i))r.apply(e,a);return!0}function Vo(e,a,n,t){a.then(void 0,function(r){queueMicrotask(()=>Xo(e,r,n,t))})}function Xo(e,a,n,t){if(typeof e[tr]==="function")e[tr](a,n,...t);else try{e[tt]=!1,e.emit("error",a)}finally{e[tt]=!0}}var jo=function(e,...a){if(e==="error")return ir(this,a);var{_events:n}=this;if(n===void 0)return!1;var t=n[e];if(t===void 0)return!1;let r=t.length>1?t.slice():t;for(let i=0,{length:o}=r;i<o;i++){let s=r[i];switch(a.length){case 0:s.call(this);break;case 1:s.call(this,a[0]);break;case 2:s.call(this,a[0],a[1]);break;case 3:s.call(this,a[0],a[1],a[2]);break;default:s.apply(this,a);break}}return!0},qo=function(e,...a){if(e==="error")return ir(this,a);var{_events:n}=this;if(n===void 0)return!1;var t=n[e];if(t===void 0)return!1;let r=t.length>1?t.slice():t;for(let i=0,{length:o}=r;i<o;i++){let s=r[i],l;switch(a.length){case 0:l=s.call(this);break;case 1:l=s.call(this,a[0]);break;case 2:l=s.call(this,a[0],a[1]);break;case 3:l=s.call(this,a[0],a[1],a[2]);break;default:l=s.apply(this,a);break}if(l!==void 0&&typeof l?.then==="function"&&l.then===Promise.prototype.then)Vo(this,l,e,a)}return!0};he.emit=jo;he.addListener=function(e,a){zt(a);var n=this._events;if(!n)n=this._events={__proto__:null},this._eventsCount=0;else if(n.newListener)this.emit("newListener",e,a.listener??a);var t=n[e];if(!t)n[e]=[a],this._eventsCount++;else{t.push(a);var r=this._maxListeners??nt;if(r>0&&t.length>r&&!t.warned)or(this,e,t)}return this};he.on=he.addListener;he.prependListener=function(e,a){zt(a);var n=this._events;if(!n)n=this._events={__proto__:null},this._eventsCount=0;else if(n.newListener)this.emit("newListener",e,a.listener??a);var t=n[e];if(!t)n[e]=[a],this._eventsCount++;else{t.unshift(a);var r=this._maxListeners??nt;if(r>0&&t.length>r&&!t.warned)or(this,e,t)}return this};function or(e,a,n){n.warned=!0;let t=Error(`Possible EventEmitter memory leak detected. ${n.length} ${String(a)} listeners added to [${e.constructor.name}]. Use emitter.setMaxListeners() to increase limit`);t.name="MaxListenersExceededWarning",t.emitter=e,t.type=a,t.count=n.length,console.warn(t)}function sr(e,a,...n){this.removeListener(e,a),a.apply(this,n)}he.once=function(e,a){zt(a);let n=sr.bind(this,e,a);return n.listener=a,this.addListener(e,n),this};he.prependOnceListener=function(e,a){zt(a);let n=sr.bind(this,e,a);return n.listener=a,this.prependListener(e,n),this};he.removeListener=function(e,a){zt(a);var{_events:n}=this;if(!n)return this;var t=n[e];if(!t)return this;var r=t.length;let i=-1;for(let o=r-1;o>=0;o--)if(t[o]===a||t[o].listener===a){i=o;break}if(i<0)return this;if(i===0)t.shift();else t.splice(i,1);if(t.length===0)delete n[e],this._eventsCount--;return this};he.off=he.removeListener;he.removeAllListeners=function(e){var{_events:a}=this;if(e&&a){if(a[e])delete a[e],this._eventsCount--}else this._events={__proto__:null};return this};he.listeners=function(e){var{_events:a}=this;if(!a)return[];var n=a[e];if(!n)return[];return n.map((t)=>t.listener??t)};he.rawListeners=function(e){var{_events:a}=this;if(!a)return[];var n=a[e];if(!n)return[];return n.slice()};he.listenerCount=function(e){var{_events:a}=this;if(!a)return 0;return a[e]?.length??0};he.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};he[tt]=!1;function Yo(e,a,n){var t=n?.signal;if(lr(t,"options.signal"),t?.aborted)throw new jn(void 0,{cause:t?.reason});return new Promise((r,i)=>{let o=(d)=>{if(e.removeListener(a,s),t!=null)rn(t,"abort",l);i(d)},s=(...d)=>{if(typeof e.removeListener==="function")e.removeListener("error",o);if(t!=null)rn(t,"abort",l);r(d)};if(ar(e,a,s,{once:!0}),a!=="error"&&typeof e.once==="function")e.once("error",o);function l(){rn(e,a,s),rn(e,"error",o),i(new jn(void 0,{cause:t?.reason}))}if(t!=null)ar(t,"abort",l,{once:!0})})}function Ko(e,a){return e.listeners(a)}function Zo(e,...a){Yn(e,"setMaxListeners",0);var n;if(a&&(n=a.length))for(let t=0;t<n;t++)a[t].setMaxListeners(e);else nt=e}function Qo(e,a){return e.listenerCount(a)}function rn(e,a,n,t){if(typeof e.removeListener==="function")e.removeListener(a,n);else e.removeEventListener(a,n,t)}function ar(e,a,n,t){if(typeof e.on==="function")if(t.once)e.once(a,n);else e.on(a,n);else e.addEventListener(a,n,t)}class jn extends Error{constructor(e="The operation was aborted",a=void 0){if(a!==void 0&&typeof a!=="object")throw ft("options","Object",a);super(e,a);this.code="ABORT_ERR",this.name="AbortError"}}function ft(e,a,n){let t=TypeError(`The "${e}" argument must be of type ${a}. Received ${n}`);return t.code="ERR_INVALID_ARG_TYPE",t}function Jo(e,a,n){let t=RangeError(`The "${e}" argument is out of range. It must be ${a}. Received ${n}`);return t.code="ERR_OUT_OF_RANGE",t}function lr(e,a){if(e!==void 0&&(e===null||typeof e!=="object"||!("aborted"in e)))throw ft(a,"AbortSignal",e)}function Yn(e,a,n,t){if(typeof e!=="number")throw ft(a,"number",e);if(n!=null&&e<n||t!=null&&e>t||(n!=null||t!=null)&&Number.isNaN(e))throw Jo(a,`${n!=null?`>= ${n}`:""}${n!=null&&t!=null?" && ":""}${t!=null?`<= ${t}`:""}`,e)}function zt(e){if(typeof e!=="function")throw TypeError("The listener must be a function")}function es(e,a){if(typeof e!=="boolean")throw ft(a,"boolean",e)}function ts(e){return e?._maxListeners??nt}function ns(e,a){if(e===void 0)throw ft("signal","AbortSignal",e);if(lr(e,"signal"),typeof a!=="function")throw ft("listener","function",a);let n;if(e.aborted)queueMicrotask(()=>a());else e.addEventListener("abort",a,{__proto__:null,once:!0}),n=()=>{e.removeEventListener("abort",a)};return{__proto__:null,[Symbol.dispose](){n?.()}}}Object.defineProperties(De,{captureRejections:{get(){return he[tt]},set(e){es(e,"EventEmitter.captureRejections"),he[tt]=e},enumerable:!0},defaultMaxListeners:{enumerable:!0,get:()=>nt,set:(e)=>{Yn(e,"defaultMaxListeners",0),nt=e}},kMaxEventTargetListeners:{value:Uo,enumerable:!1,configurable:!1,writable:!1},kMaxEventTargetListenersWarned:{value:Ho,enumerable:!1,configurable:!1,writable:!1}});Object.assign(De,{once:Yo,getEventListeners:Ko,getMaxListeners:ts,setMaxListeners:Zo,EventEmitter:De,usingDomains:!1,captureRejectionSymbol:$o,errorMonitor:rr,addAbortListener:ns,init:De,listenerCount:Qo});function as(){let e=arguments[0];for(let a=1,n=arguments.length;a<n;a++){if(!arguments[a])continue;for(let t in arguments[a])e[t]=arguments[a][t]}return e}var ye=as;if(typeof Object.assign==="function")ye=Object.assign;function Ce(e,a,n,t){let r=e._nodes.get(a),i=null;if(!r)return i;if(t==="mixed")i=r.out&&r.out[n]||r.undirected&&r.undirected[n];else if(t==="directed")i=r.out&&r.out[n];else i=r.undirected&&r.undirected[n];return i}function Te(e){return typeof e==="object"&&e!==null}function hr(e){let a;for(a in e)return!1;return!0}function Le(e,a,n){Object.defineProperty(e,a,{enumerable:!1,configurable:!1,writable:!0,value:n})}function Ge(e,a,n){let t={enumerable:!0,configurable:!0};if(typeof n==="function")t.get=n;else t.value=n,t.writable=!1;Object.defineProperty(e,a,t)}function dr(e){if(!Te(e))return!1;if(e.attributes&&!Array.isArray(e.attributes))return!1;return!0}function rs(){let e=Math.floor(Math.random()*256)&255;return()=>e++}function He(){let e=arguments,a=null,n=-1;return{[Symbol.iterator](){return this},next(){let t=null;do{if(a===null){if(n++,n>=e.length)return{done:!0};a=e[n][Symbol.iterator]()}if(t=a.next(),t.done){a=null;continue}break}while(!0);return t}}}function vt(){return{[Symbol.iterator](){return this},next(){return{done:!0}}}}class sn extends Error{constructor(e){super();this.name="GraphError",this.message=e}}class j extends sn{constructor(e){super(e);if(this.name="InvalidArgumentsGraphError",typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,j.prototype.constructor)}}class X extends sn{constructor(e){super(e);if(this.name="NotFoundGraphError",typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,X.prototype.constructor)}}class ne extends sn{constructor(e){super(e);if(this.name="UsageGraphError",typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,ne.prototype.constructor)}}function fr(e,a){this.key=e,this.attributes=a,this.clear()}fr.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.undirectedDegree=0,this.undirectedLoops=0,this.directedLoops=0,this.in={},this.out={},this.undirected={}};function gr(e,a){this.key=e,this.attributes=a,this.clear()}gr.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.directedLoops=0,this.in={},this.out={}};function vr(e,a){this.key=e,this.attributes=a,this.clear()}vr.prototype.clear=function(){this.undirectedDegree=0,this.undirectedLoops=0,this.undirected={}};function pt(e,a,n,t,r){this.key=a,this.attributes=r,this.undirected=e,this.source=n,this.target=t}pt.prototype.attach=function(){let e="out",a="in";if(this.undirected)e=a="undirected";let n=this.source.key,t=this.target.key;if(this.source[e][t]=this,this.undirected&&n===t)return;this.target[a][n]=this};pt.prototype.attachMulti=function(){let e="out",a="in",n=this.source.key,t=this.target.key;if(this.undirected)e=a="undirected";let r=this.source[e],i=r[t];if(typeof i>"u"){if(r[t]=this,!(this.undirected&&n===t))this.target[a][n]=this;return}i.previous=this,this.next=i,r[t]=this,this.target[a][n]=this};pt.prototype.detach=function(){let e=this.source.key,a=this.target.key,n="out",t="in";if(this.undirected)n=t="undirected";delete this.source[n][a],delete this.target[t][e]};pt.prototype.detachMulti=function(){let e=this.source.key,a=this.target.key,n="out",t="in";if(this.undirected)n=t="undirected";if(this.previous===void 0)if(this.next===void 0)delete this.source[n][a],delete this.target[t][e];else this.next.previous=void 0,this.source[n][a]=this.next,this.target[t][e]=this.next;else if(this.previous.next=this.next,this.next!==void 0)this.next.previous=this.previous};var pr=0,mr=1,is=2,br=3;function $e(e,a,n,t,r,i,o){let s,l,d,u;if(t=""+t,n===pr){if(s=e._nodes.get(t),!s)throw new X(`Graph.${a}: could not find the "${t}" node in the graph.`);d=r,u=i}else if(n===br){if(r=""+r,l=e._edges.get(r),!l)throw new X(`Graph.${a}: could not find the "${r}" edge in the graph.`);let c=l.source.key,g=l.target.key;if(t===c)s=l.target;else if(t===g)s=l.source;else throw new X(`Graph.${a}: the "${t}" node is not attached to the "${r}" edge (${c}, ${g}).`);d=i,u=o}else{if(l=e._edges.get(t),!l)throw new X(`Graph.${a}: could not find the "${t}" edge in the graph.`);if(n===mr)s=l.source;else s=l.target;d=r,u=i}return[s,d,u]}function os(e,a,n){e.prototype[a]=function(t,r,i){let[o,s]=$e(this,a,n,t,r,i);return o.attributes[s]}}function ss(e,a,n){e.prototype[a]=function(t,r){let[i]=$e(this,a,n,t,r);return i.attributes}}function ls(e,a,n){e.prototype[a]=function(t,r,i){let[o,s]=$e(this,a,n,t,r,i);return o.attributes.hasOwnProperty(s)}}function ds(e,a,n){e.prototype[a]=function(t,r,i,o){let[s,l,d]=$e(this,a,n,t,r,i,o);return s.attributes[l]=d,this.emit("nodeAttributesUpdated",{key:s.key,type:"set",attributes:s.attributes,name:l}),this}}function us(e,a,n){e.prototype[a]=function(t,r,i,o){let[s,l,d]=$e(this,a,n,t,r,i,o);if(typeof d!=="function")throw new j(`Graph.${a}: updater should be a function.`);let u=s.attributes,c=d(u[l]);return u[l]=c,this.emit("nodeAttributesUpdated",{key:s.key,type:"set",attributes:s.attributes,name:l}),this}}function cs(e,a,n){e.prototype[a]=function(t,r,i){let[o,s]=$e(this,a,n,t,r,i);return delete o.attributes[s],this.emit("nodeAttributesUpdated",{key:o.key,type:"remove",attributes:o.attributes,name:s}),this}}function hs(e,a,n){e.prototype[a]=function(t,r,i){let[o,s]=$e(this,a,n,t,r,i);if(!Te(s))throw new j(`Graph.${a}: provided attributes are not a plain object.`);return o.attributes=s,this.emit("nodeAttributesUpdated",{key:o.key,type:"replace",attributes:o.attributes}),this}}function fs(e,a,n){e.prototype[a]=function(t,r,i){let[o,s]=$e(this,a,n,t,r,i);if(!Te(s))throw new j(`Graph.${a}: provided attributes are not a plain object.`);return ye(o.attributes,s),this.emit("nodeAttributesUpdated",{key:o.key,type:"merge",attributes:o.attributes,data:s}),this}}function gs(e,a,n){e.prototype[a]=function(t,r,i){let[o,s]=$e(this,a,n,t,r,i);if(typeof s!=="function")throw new j(`Graph.${a}: provided updater is not a function.`);return o.attributes=s(o.attributes),this.emit("nodeAttributesUpdated",{key:o.key,type:"update",attributes:o.attributes}),this}}var vs=[{name:(e)=>`get${e}Attribute`,attacher:os},{name:(e)=>`get${e}Attributes`,attacher:ss},{name:(e)=>`has${e}Attribute`,attacher:ls},{name:(e)=>`set${e}Attribute`,attacher:ds},{name:(e)=>`update${e}Attribute`,attacher:us},{name:(e)=>`remove${e}Attribute`,attacher:cs},{name:(e)=>`replace${e}Attributes`,attacher:hs},{name:(e)=>`merge${e}Attributes`,attacher:fs},{name:(e)=>`update${e}Attributes`,attacher:gs}];function ps(e){vs.forEach(function({name:a,attacher:n}){n(e,a("Node"),pr),n(e,a("Source"),mr),n(e,a("Target"),is),n(e,a("Opposite"),br)})}function ms(e,a,n){e.prototype[a]=function(t,r){let i;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new ne(`Graph.${a}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new ne(`Graph.${a}: cannot use a {source,target} combo when asking about an edge\'s attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=""+t,s=""+r;if(r=arguments[2],i=Ce(this,o,s,n),!i)throw new X(`Graph.${a}: could not find an edge for the given path ("${o}" - "${s}").`)}else{if(n!=="mixed")throw new ne(`Graph.${a}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(t=""+t,i=this._edges.get(t),!i)throw new X(`Graph.${a}: could not find the "${t}" edge in the graph.`)}return i.attributes[r]}}function bs(e,a,n){e.prototype[a]=function(t){let r;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new ne(`Graph.${a}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>1){if(this.multi)throw new ne(`Graph.${a}: cannot use a {source,target} combo when asking about an edge\'s attributes in a MultiGraph since we cannot infer the one you want information about.`);let i=""+t,o=""+arguments[1];if(r=Ce(this,i,o,n),!r)throw new X(`Graph.${a}: could not find an edge for the given path ("${i}" - "${o}").`)}else{if(n!=="mixed")throw new ne(`Graph.${a}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(t=""+t,r=this._edges.get(t),!r)throw new X(`Graph.${a}: could not find the "${t}" edge in the graph.`)}return r.attributes}}function ys(e,a,n){e.prototype[a]=function(t,r){let i;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new ne(`Graph.${a}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new ne(`Graph.${a}: cannot use a {source,target} combo when asking about an edge\'s attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=""+t,s=""+r;if(r=arguments[2],i=Ce(this,o,s,n),!i)throw new X(`Graph.${a}: could not find an edge for the given path ("${o}" - "${s}").`)}else{if(n!=="mixed")throw new ne(`Graph.${a}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(t=""+t,i=this._edges.get(t),!i)throw new X(`Graph.${a}: could not find the "${t}" edge in the graph.`)}return i.attributes.hasOwnProperty(r)}}function xs(e,a,n){e.prototype[a]=function(t,r,i){let o;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new ne(`Graph.${a}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>3){if(this.multi)throw new ne(`Graph.${a}: cannot use a {source,target} combo when asking about an edge\'s attributes in a MultiGraph since we cannot infer the one you want information about.`);let s=""+t,l=""+r;if(r=arguments[2],i=arguments[3],o=Ce(this,s,l,n),!o)throw new X(`Graph.${a}: could not find an edge for the given path ("${s}" - "${l}").`)}else{if(n!=="mixed")throw new ne(`Graph.${a}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(t=""+t,o=this._edges.get(t),!o)throw new X(`Graph.${a}: could not find the "${t}" edge in the graph.`)}return o.attributes[r]=i,this.emit("edgeAttributesUpdated",{key:o.key,type:"set",attributes:o.attributes,name:r}),this}}function _s(e,a,n){e.prototype[a]=function(t,r,i){let o;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new ne(`Graph.${a}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>3){if(this.multi)throw new ne(`Graph.${a}: cannot use a {source,target} combo when asking about an edge\'s attributes in a MultiGraph since we cannot infer the one you want information about.`);let s=""+t,l=""+r;if(r=arguments[2],i=arguments[3],o=Ce(this,s,l,n),!o)throw new X(`Graph.${a}: could not find an edge for the given path ("${s}" - "${l}").`)}else{if(n!=="mixed")throw new ne(`Graph.${a}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(t=""+t,o=this._edges.get(t),!o)throw new X(`Graph.${a}: could not find the "${t}" edge in the graph.`)}if(typeof i!=="function")throw new j(`Graph.${a}: updater should be a function.`);return o.attributes[r]=i(o.attributes[r]),this.emit("edgeAttributesUpdated",{key:o.key,type:"set",attributes:o.attributes,name:r}),this}}function Ts(e,a,n){e.prototype[a]=function(t,r){let i;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new ne(`Graph.${a}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new ne(`Graph.${a}: cannot use a {source,target} combo when asking about an edge\'s attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=""+t,s=""+r;if(r=arguments[2],i=Ce(this,o,s,n),!i)throw new X(`Graph.${a}: could not find an edge for the given path ("${o}" - "${s}").`)}else{if(n!=="mixed")throw new ne(`Graph.${a}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(t=""+t,i=this._edges.get(t),!i)throw new X(`Graph.${a}: could not find the "${t}" edge in the graph.`)}return delete i.attributes[r],this.emit("edgeAttributesUpdated",{key:i.key,type:"remove",attributes:i.attributes,name:r}),this}}function Ss(e,a,n){e.prototype[a]=function(t,r){let i;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new ne(`Graph.${a}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new ne(`Graph.${a}: cannot use a {source,target} combo when asking about an edge\'s attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=""+t,s=""+r;if(r=arguments[2],i=Ce(this,o,s,n),!i)throw new X(`Graph.${a}: could not find an edge for the given path ("${o}" - "${s}").`)}else{if(n!=="mixed")throw new ne(`Graph.${a}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(t=""+t,i=this._edges.get(t),!i)throw new X(`Graph.${a}: could not find the "${t}" edge in the graph.`)}if(!Te(r))throw new j(`Graph.${a}: provided attributes are not a plain object.`);return i.attributes=r,this.emit("edgeAttributesUpdated",{key:i.key,type:"replace",attributes:i.attributes}),this}}function Es(e,a,n){e.prototype[a]=function(t,r){let i;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new ne(`Graph.${a}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new ne(`Graph.${a}: cannot use a {source,target} combo when asking about an edge\'s attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=""+t,s=""+r;if(r=arguments[2],i=Ce(this,o,s,n),!i)throw new X(`Graph.${a}: could not find an edge for the given path ("${o}" - "${s}").`)}else{if(n!=="mixed")throw new ne(`Graph.${a}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(t=""+t,i=this._edges.get(t),!i)throw new X(`Graph.${a}: could not find the "${t}" edge in the graph.`)}if(!Te(r))throw new j(`Graph.${a}: provided attributes are not a plain object.`);return ye(i.attributes,r),this.emit("edgeAttributesUpdated",{key:i.key,type:"merge",attributes:i.attributes,data:r}),this}}function Rs(e,a,n){e.prototype[a]=function(t,r){let i;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new ne(`Graph.${a}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new ne(`Graph.${a}: cannot use a {source,target} combo when asking about an edge\'s attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=""+t,s=""+r;if(r=arguments[2],i=Ce(this,o,s,n),!i)throw new X(`Graph.${a}: could not find an edge for the given path ("${o}" - "${s}").`)}else{if(n!=="mixed")throw new ne(`Graph.${a}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(t=""+t,i=this._edges.get(t),!i)throw new X(`Graph.${a}: could not find the "${t}" edge in the graph.`)}if(typeof r!=="function")throw new j(`Graph.${a}: provided updater is not a function.`);return i.attributes=r(i.attributes),this.emit("edgeAttributesUpdated",{key:i.key,type:"update",attributes:i.attributes}),this}}var As=[{name:(e)=>`get${e}Attribute`,attacher:ms},{name:(e)=>`get${e}Attributes`,attacher:bs},{name:(e)=>`has${e}Attribute`,attacher:ys},{name:(e)=>`set${e}Attribute`,attacher:xs},{name:(e)=>`update${e}Attribute`,attacher:_s},{name:(e)=>`remove${e}Attribute`,attacher:Ts},{name:(e)=>`replace${e}Attributes`,attacher:Ss},{name:(e)=>`merge${e}Attributes`,attacher:Es},{name:(e)=>`update${e}Attributes`,attacher:Rs}];function ws(e){As.forEach(function({name:a,attacher:n}){n(e,a("Edge"),"mixed"),n(e,a("DirectedEdge"),"directed"),n(e,a("UndirectedEdge"),"undirected")})}var Ds=[{name:"edges",type:"mixed"},{name:"inEdges",type:"directed",direction:"in"},{name:"outEdges",type:"directed",direction:"out"},{name:"inboundEdges",type:"mixed",direction:"in"},{name:"outboundEdges",type:"mixed",direction:"out"},{name:"directedEdges",type:"directed"},{name:"undirectedEdges",type:"undirected"}];function Ls(e,a,n,t){let r=!1;for(let i in a){if(i===t)continue;let o=a[i];if(r=n(o.key,o.attributes,o.source.key,o.target.key,o.source.attributes,o.target.attributes,o.undirected),e&&r)return o.key}return}function Cs(e,a,n,t){let r,i,o,s=!1;for(let l in a){if(l===t)continue;r=a[l];do{if(i=r.source,o=r.target,s=n(r.key,r.attributes,i.key,o.key,i.attributes,o.attributes,r.undirected),e&&s)return r.key;r=r.next}while(r!==void 0)}return}function Kn(e,a){let n=Object.keys(e),t=n.length,r,i=0;return{[Symbol.iterator](){return this},next(){do if(!r){if(i>=t)return{done:!0};let o=n[i++];if(o===a){r=void 0;continue}r=e[o]}else r=r.next;while(!r);return{done:!1,value:{edge:r.key,attributes:r.attributes,source:r.source.key,target:r.target.key,sourceAttributes:r.source.attributes,targetAttributes:r.target.attributes,undirected:r.undirected}}}}}function ks(e,a,n,t){let r=a[n];if(!r)return;let{source:i,target:o}=r;if(t(r.key,r.attributes,i.key,o.key,i.attributes,o.attributes,r.undirected)&&e)return r.key}function Ps(e,a,n,t){let r=a[n];if(!r)return;let i=!1;do{if(i=t(r.key,r.attributes,r.source.key,r.target.key,r.source.attributes,r.target.attributes,r.undirected),e&&i)return r.key;r=r.next}while(r!==void 0);return}function Zn(e,a){let n=e[a];if(n.next!==void 0)return{[Symbol.iterator](){return this},next(){if(!n)return{done:!0};let r={edge:n.key,attributes:n.attributes,source:n.source.key,target:n.target.key,sourceAttributes:n.source.attributes,targetAttributes:n.target.attributes,undirected:n.undirected};return n=n.next,{done:!1,value:r}}};let t=!1;return{[Symbol.iterator](){return this},next(){if(t===!0)return{done:!0};return t=!0,{done:!1,value:{edge:n.key,attributes:n.attributes,source:n.source.key,target:n.target.key,sourceAttributes:n.source.attributes,targetAttributes:n.target.attributes,undirected:n.undirected}}}}}function Fs(e,a){if(e.size===0)return[];if(a==="mixed"||a===e.type)return Array.from(e._edges.keys());let n=a==="undirected"?e.undirectedSize:e.directedSize,t=Array(n),r=a==="undirected",i=e._edges.values(),o=0,s,l;while(s=i.next(),s.done!==!0)if(l=s.value,l.undirected===r)t[o++]=l.key;return t}function yr(e,a,n,t){if(a.size===0)return;let r=n!=="mixed"&&n!==a.type,i=n==="undirected",o,s,l=!1,d=a._edges.values();while(o=d.next(),o.done!==!0){if(s=o.value,r&&s.undirected!==i)continue;let{key:u,attributes:c,source:g,target:h}=s;if(l=t(u,c,g.key,h.key,g.attributes,h.attributes,s.undirected),e&&l)return u}return}function Is(e,a){if(e.size===0)return vt();let n=a!=="mixed"&&a!==e.type,t=a==="undirected",r=e._edges.values();return{[Symbol.iterator](){return this},next(){let i,o;while(!0){if(i=r.next(),i.done)return i;if(o=i.value,n&&o.undirected!==t)continue;break}return{value:{edge:o.key,attributes:o.attributes,source:o.source.key,target:o.target.key,sourceAttributes:o.source.attributes,targetAttributes:o.target.attributes,undirected:o.undirected},done:!1}}}}function Qn(e,a,n,t,r,i){let o=a?Cs:Ls,s;if(n!=="undirected"){if(t!=="out"){if(s=o(e,r.in,i),e&&s)return s}if(t!=="in"){if(s=o(e,r.out,i,!t?r.key:void 0),e&&s)return s}}if(n!=="directed"){if(s=o(e,r.undirected,i),e&&s)return s}return}function Ms(e,a,n,t){let r=[];return Qn(!1,e,a,n,t,function(i){r.push(i)}),r}function zs(e,a,n){let t=vt();if(e!=="undirected"){if(a!=="out"&&typeof n.in<"u")t=He(t,Kn(n.in));if(a!=="in"&&typeof n.out<"u")t=He(t,Kn(n.out,!a?n.key:void 0))}if(e!=="directed"&&typeof n.undirected<"u")t=He(t,Kn(n.undirected));return t}function Jn(e,a,n,t,r,i,o){let s=n?Ps:ks,l;if(a!=="undirected"){if(typeof r.in<"u"&&t!=="out"){if(l=s(e,r.in,i,o),e&&l)return l}if(typeof r.out<"u"&&t!=="in"&&(t||r.key!==i)){if(l=s(e,r.out,i,o),e&&l)return l}}if(a!=="directed"){if(typeof r.undirected<"u"){if(l=s(e,r.undirected,i,o),e&&l)return l}}return}function Ns(e,a,n,t,r){let i=[];return Jn(!1,e,a,n,t,r,function(o){i.push(o)}),i}function Gs(e,a,n,t){let r=vt();if(e!=="undirected"){if(typeof n.in<"u"&&a!=="out"&&t in n.in)r=He(r,Zn(n.in,t));if(typeof n.out<"u"&&a!=="in"&&t in n.out&&(a||n.key!==t))r=He(r,Zn(n.out,t))}if(e!=="directed"){if(typeof n.undirected<"u"&&t in n.undirected)r=He(r,Zn(n.undirected,t))}return r}function Os(e,a){let{name:n,type:t,direction:r}=a;e.prototype[n]=function(i,o){if(t!=="mixed"&&this.type!=="mixed"&&t!==this.type)return[];if(!arguments.length)return Fs(this,t);if(arguments.length===1){i=""+i;let s=this._nodes.get(i);if(typeof s>"u")throw new X(`Graph.${n}: could not find the "${i}" node in the graph.`);return Ms(this.multi,t==="mixed"?this.type:t,r,s)}if(arguments.length===2){i=""+i,o=""+o;let s=this._nodes.get(i);if(!s)throw new X(`Graph.${n}: could not find the "${i}" source node in the graph.`);if(!this._nodes.has(o))throw new X(`Graph.${n}: could not find the "${o}" target node in the graph.`);return Ns(t,this.multi,r,s,o)}throw new j(`Graph.${n}: too many arguments (expecting 0, 1 or 2 and got ${arguments.length}).`)}}function Bs(e,a){let{name:n,type:t,direction:r}=a,i="forEach"+n[0].toUpperCase()+n.slice(1,-1);e.prototype[i]=function(d,u,c){if(t!=="mixed"&&this.type!=="mixed"&&t!==this.type)return;if(arguments.length===1)return c=d,yr(!1,this,t,c);if(arguments.length===2){d=""+d,c=u;let g=this._nodes.get(d);if(typeof g>"u")throw new X(`Graph.${i}: could not find the "${d}" node in the graph.`);return Qn(!1,this.multi,t==="mixed"?this.type:t,r,g,c)}if(arguments.length===3){d=""+d,u=""+u;let g=this._nodes.get(d);if(!g)throw new X(`Graph.${i}: could not find the "${d}" source node in the graph.`);if(!this._nodes.has(u))throw new X(`Graph.${i}: could not find the "${u}" target node in the graph.`);return Jn(!1,t,this.multi,r,g,u,c)}throw new j(`Graph.${i}: too many arguments (expecting 1, 2 or 3 and got ${arguments.length}).`)};let o="map"+n[0].toUpperCase()+n.slice(1);e.prototype[o]=function(){let d=Array.prototype.slice.call(arguments),u=d.pop(),c;if(d.length===0){let g=0;if(t!=="directed")g+=this.undirectedSize;if(t!=="undirected")g+=this.directedSize;c=Array(g);let h=0;d.push((p,y,v,f,b,m,T)=>{c[h++]=u(p,y,v,f,b,m,T)})}else c=[],d.push((g,h,p,y,v,f,b)=>{c.push(u(g,h,p,y,v,f,b))});return this[i].apply(this,d),c};let s="filter"+n[0].toUpperCase()+n.slice(1);e.prototype[s]=function(){let d=Array.prototype.slice.call(arguments),u=d.pop(),c=[];return d.push((g,h,p,y,v,f,b)=>{if(u(g,h,p,y,v,f,b))c.push(g)}),this[i].apply(this,d),c};let l="reduce"+n[0].toUpperCase()+n.slice(1);e.prototype[l]=function(){let d=Array.prototype.slice.call(arguments);if(d.length<2||d.length>4)throw new j(`Graph.${l}: invalid number of arguments (expecting 2, 3 or 4 and got ${d.length}).`);if(typeof d[d.length-1]==="function"&&typeof d[d.length-2]!=="function")throw new j(`Graph.${l}: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.`);let u,c;if(d.length===2)u=d[0],c=d[1],d=[];else if(d.length===3)u=d[1],c=d[2],d=[d[0]];else if(d.length===4)u=d[2],c=d[3],d=[d[0],d[1]];let g=c;return d.push((h,p,y,v,f,b,m)=>{g=u(g,h,p,y,v,f,b,m)}),this[i].apply(this,d),g}}function Ws(e,a){let{name:n,type:t,direction:r}=a,i="find"+n[0].toUpperCase()+n.slice(1,-1);e.prototype[i]=function(l,d,u){if(t!=="mixed"&&this.type!=="mixed"&&t!==this.type)return!1;if(arguments.length===1)return u=l,yr(!0,this,t,u);if(arguments.length===2){l=""+l,u=d;let c=this._nodes.get(l);if(typeof c>"u")throw new X(`Graph.${i}: could not find the "${l}" node in the graph.`);return Qn(!0,this.multi,t==="mixed"?this.type:t,r,c,u)}if(arguments.length===3){l=""+l,d=""+d;let c=this._nodes.get(l);if(!c)throw new X(`Graph.${i}: could not find the "${l}" source node in the graph.`);if(!this._nodes.has(d))throw new X(`Graph.${i}: could not find the "${d}" target node in the graph.`);return Jn(!0,t,this.multi,r,c,d,u)}throw new j(`Graph.${i}: too many arguments (expecting 1, 2 or 3 and got ${arguments.length}).`)};let o="some"+n[0].toUpperCase()+n.slice(1,-1);e.prototype[o]=function(){let l=Array.prototype.slice.call(arguments),d=l.pop();if(l.push((c,g,h,p,y,v,f)=>d(c,g,h,p,y,v,f)),this[i].apply(this,l))return!0;return!1};let s="every"+n[0].toUpperCase()+n.slice(1,-1);e.prototype[s]=function(){let l=Array.prototype.slice.call(arguments),d=l.pop();if(l.push((c,g,h,p,y,v,f)=>!d(c,g,h,p,y,v,f)),this[i].apply(this,l))return!1;return!0}}function Us(e,a){let{name:n,type:t,direction:r}=a,i=n.slice(0,-1)+"Entries";e.prototype[i]=function(o,s){if(t!=="mixed"&&this.type!=="mixed"&&t!==this.type)return vt();if(!arguments.length)return Is(this,t);if(arguments.length===1){o=""+o;let l=this._nodes.get(o);if(!l)throw new X(`Graph.${i}: could not find the "${o}" node in the graph.`);return zs(t,r,l)}if(arguments.length===2){o=""+o,s=""+s;let l=this._nodes.get(o);if(!l)throw new X(`Graph.${i}: could not find the "${o}" source node in the graph.`);if(!this._nodes.has(s))throw new X(`Graph.${i}: could not find the "${s}" target node in the graph.`);return Gs(t,r,l,s)}throw new j(`Graph.${i}: too many arguments (expecting 0, 1 or 2 and got ${arguments.length}).`)}}function Hs(e){Ds.forEach((a)=>{Os(e,a),Bs(e,a),Ws(e,a),Us(e,a)})}var $s=[{name:"neighbors",type:"mixed"},{name:"inNeighbors",type:"directed",direction:"in"},{name:"outNeighbors",type:"directed",direction:"out"},{name:"inboundNeighbors",type:"mixed",direction:"in"},{name:"outboundNeighbors",type:"mixed",direction:"out"},{name:"directedNeighbors",type:"directed"},{name:"undirectedNeighbors",type:"undirected"}];function ln(){this.A=null,this.B=null}ln.prototype.wrap=function(e){if(this.A===null)this.A=e;else if(this.B===null)this.B=e};ln.prototype.has=function(e){if(this.A!==null&&e in this.A)return!0;if(this.B!==null&&e in this.B)return!0;return!1};function Nt(e,a,n,t,r){for(let i in t){let o=t[i],{source:s,target:l}=o,d=s===n?l:s;if(a&&a.has(d.key))continue;let u=r(d.key,d.attributes);if(e&&u)return d.key}return}function ea(e,a,n,t,r){if(a!=="mixed"){if(a==="undirected")return Nt(e,null,t,t.undirected,r);if(typeof n==="string")return Nt(e,null,t,t[n],r)}let i=new ln,o;if(a!=="undirected"){if(n!=="out"){if(o=Nt(e,null,t,t.in,r),e&&o)return o;i.wrap(t.in)}if(n!=="in"){if(o=Nt(e,i,t,t.out,r),e&&o)return o;i.wrap(t.out)}}if(a!=="directed"){if(o=Nt(e,i,t,t.undirected,r),e&&o)return o}return}function Vs(e,a,n){if(e!=="mixed"){if(e==="undirected")return Object.keys(n.undirected);if(typeof a==="string")return Object.keys(n[a])}let t=[];return ea(!1,e,a,n,function(r){t.push(r)}),t}function Gt(e,a,n){let t=Object.keys(n),r=t.length,i=0;return{[Symbol.iterator](){return this},next(){let o=null;do{if(i>=r){if(e)e.wrap(n);return{done:!0}}let s=n[t[i++]],{source:l,target:d}=s;if(o=l===a?d:l,e&&e.has(o.key)){o=null;continue}}while(o===null);return{done:!1,value:{neighbor:o.key,attributes:o.attributes}}}}}function Xs(e,a,n){if(e!=="mixed"){if(e==="undirected")return Gt(null,n,n.undirected);if(typeof a==="string")return Gt(null,n,n[a])}let t=vt(),r=new ln;if(e!=="undirected"){if(a!=="out")t=He(t,Gt(r,n,n.in));if(a!=="in")t=He(t,Gt(r,n,n.out))}if(e!=="directed")t=He(t,Gt(r,n,n.undirected));return t}function js(e,a){let{name:n,type:t,direction:r}=a;e.prototype[n]=function(i){if(t!=="mixed"&&this.type!=="mixed"&&t!==this.type)return[];i=""+i;let o=this._nodes.get(i);if(typeof o>"u")throw new X(`Graph.${n}: could not find the "${i}" node in the graph.`);return Vs(t==="mixed"?this.type:t,r,o)}}function qs(e,a){let{name:n,type:t,direction:r}=a,i="forEach"+n[0].toUpperCase()+n.slice(1,-1);e.prototype[i]=function(d,u){if(t!=="mixed"&&this.type!=="mixed"&&t!==this.type)return;d=""+d;let c=this._nodes.get(d);if(typeof c>"u")throw new X(`Graph.${i}: could not find the "${d}" node in the graph.`);ea(!1,t==="mixed"?this.type:t,r,c,u)};let o="map"+n[0].toUpperCase()+n.slice(1);e.prototype[o]=function(d,u){let c=[];return this[i](d,(g,h)=>{c.push(u(g,h))}),c};let s="filter"+n[0].toUpperCase()+n.slice(1);e.prototype[s]=function(d,u){let c=[];return this[i](d,(g,h)=>{if(u(g,h))c.push(g)}),c};let l="reduce"+n[0].toUpperCase()+n.slice(1);e.prototype[l]=function(d,u,c){if(arguments.length<3)throw new j(`Graph.${l}: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.`);let g=c;return this[i](d,(h,p)=>{g=u(g,h,p)}),g}}function Ys(e,a){let{name:n,type:t,direction:r}=a,i=n[0].toUpperCase()+n.slice(1,-1),o="find"+i;e.prototype[o]=function(d,u){if(t!=="mixed"&&this.type!=="mixed"&&t!==this.type)return;d=""+d;let c=this._nodes.get(d);if(typeof c>"u")throw new X(`Graph.${o}: could not find the "${d}" node in the graph.`);return ea(!0,t==="mixed"?this.type:t,r,c,u)};let s="some"+i;e.prototype[s]=function(d,u){if(this[o](d,u))return!0;return!1};let l="every"+i;e.prototype[l]=function(d,u){if(this[o](d,(g,h)=>!u(g,h)))return!1;return!0}}function Ks(e,a){let{name:n,type:t,direction:r}=a,i=n.slice(0,-1)+"Entries";e.prototype[i]=function(o){if(t!=="mixed"&&this.type!=="mixed"&&t!==this.type)return vt();o=""+o;let s=this._nodes.get(o);if(typeof s>"u")throw new X(`Graph.${i}: could not find the "${o}" node in the graph.`);return Xs(t==="mixed"?this.type:t,r,s)}}function Zs(e){$s.forEach((a)=>{js(e,a),qs(e,a),Ys(e,a),Ks(e,a)})}function on(e,a,n,t,r){let i=t._nodes.values(),o=t.type,s,l,d,u,c,g,h;while(s=i.next(),s.done!==!0){let p=!1;if(l=s.value,o!=="undirected"){u=l.out;for(d in u){c=u[d];do{if(g=c.target,p=!0,h=r(l.key,g.key,l.attributes,g.attributes,c.key,c.attributes,c.undirected),e&&h)return c;c=c.next}while(c)}}if(o!=="directed"){u=l.undirected;for(d in u){if(a&&l.key>d)continue;c=u[d];do{if(g=c.target,g.key!==d)g=c.source;if(p=!0,h=r(l.key,g.key,l.attributes,g.attributes,c.key,c.attributes,c.undirected),e&&h)return c;c=c.next}while(c)}}if(n&&!p){if(h=r(l.key,null,l.attributes,null,null,null,null),e&&h)return null}}return}function Qs(e,a){let n={key:e};if(!hr(a.attributes))n.attributes=ye({},a.attributes);return n}function Js(e,a,n){let t={key:a,source:n.source.key,target:n.target.key};if(!hr(n.attributes))t.attributes=ye({},n.attributes);if(e==="mixed"&&n.undirected)t.undirected=!0;return t}function el(e){if(!Te(e))throw new j(\'Graph.import: invalid serialized node. A serialized node should be a plain object with at least a "key" property.\');if(!("key"in e))throw new j("Graph.import: serialized node is missing its key.");if("attributes"in e&&(!Te(e.attributes)||e.attributes===null))throw new j("Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.")}function tl(e){if(!Te(e))throw new j(\'Graph.import: invalid serialized edge. A serialized edge should be a plain object with at least a "source" & "target" property.\');if(!("source"in e))throw new j("Graph.import: serialized edge is missing its source.");if(!("target"in e))throw new j("Graph.import: serialized edge is missing its target.");if("attributes"in e&&(!Te(e.attributes)||e.attributes===null))throw new j("Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.");if("undirected"in e&&typeof e.undirected!=="boolean")throw new j("Graph.import: invalid undirectedness information. Undirected should be boolean or omitted.")}var nl=rs(),al=new Set(["directed","undirected","mixed"]),ur=new Set(["domain","_events","_eventsCount","_maxListeners"]),rl=[{name:(e)=>`${e}Edge`,generateKey:!0},{name:(e)=>`${e}DirectedEdge`,generateKey:!0,type:"directed"},{name:(e)=>`${e}UndirectedEdge`,generateKey:!0,type:"undirected"},{name:(e)=>`${e}EdgeWithKey`},{name:(e)=>`${e}DirectedEdgeWithKey`,type:"directed"},{name:(e)=>`${e}UndirectedEdgeWithKey`,type:"undirected"}],il={allowSelfLoops:!0,multi:!1,type:"mixed"};function ol(e,a,n){if(n&&!Te(n))throw new j(`Graph.addNode: invalid attributes. Expecting an object but got "${n}"`);if(a=""+a,n=n||{},e._nodes.has(a))throw new ne(`Graph.addNode: the "${a}" node already exist in the graph.`);let t=new e.NodeDataClass(a,n);return e._nodes.set(a,t),e.emit("nodeAdded",{key:a,attributes:n}),t}function cr(e,a,n){let t=new e.NodeDataClass(a,n);return e._nodes.set(a,t),e.emit("nodeAdded",{key:a,attributes:n}),t}function xr(e,a,n,t,r,i,o,s){if(!t&&e.type==="undirected")throw new ne(`Graph.${a}: you cannot add a directed edge to an undirected graph. Use the #.addEdge or #.addUndirectedEdge instead.`);if(t&&e.type==="directed")throw new ne(`Graph.${a}: you cannot add an undirected edge to a directed graph. Use the #.addEdge or #.addDirectedEdge instead.`);if(s&&!Te(s))throw new j(`Graph.${a}: invalid attributes. Expecting an object but got "${s}"`);if(i=""+i,o=""+o,s=s||{},!e.allowSelfLoops&&i===o)throw new ne(`Graph.${a}: source & target are the same ("${i}"), thus creating a loop explicitly forbidden by this graph \'allowSelfLoops\' option set to false.`);let l=e._nodes.get(i),d=e._nodes.get(o);if(!l)throw new X(`Graph.${a}: source node "${i}" not found.`);if(!d)throw new X(`Graph.${a}: target node "${o}" not found.`);let u={key:null,undirected:t,source:i,target:o,attributes:s};if(n)r=e._edgeKeyGenerator();else if(r=""+r,e._edges.has(r))throw new ne(`Graph.${a}: the "${r}" edge already exists in the graph.`);if(!e.multi&&(t?typeof l.undirected[o]<"u":typeof l.out[o]<"u"))throw new ne(`Graph.${a}: an edge linking "${i}" to "${o}" already exists. If you really want to add multiple edges linking those nodes, you should create a multi graph by using the \'multi\' option.`);let c=new pt(t,r,l,d,s);e._edges.set(r,c);let g=i===o;if(t){if(l.undirectedDegree++,d.undirectedDegree++,g)l.undirectedLoops++,e._undirectedSelfLoopCount++}else if(l.outDegree++,d.inDegree++,g)l.directedLoops++,e._directedSelfLoopCount++;if(e.multi)c.attachMulti();else c.attach();if(t)e._undirectedSize++;else e._directedSize++;return u.key=r,e.emit("edgeAdded",u),r}function sl(e,a,n,t,r,i,o,s,l){if(!t&&e.type==="undirected")throw new ne(`Graph.${a}: you cannot merge/update a directed edge to an undirected graph. Use the #.mergeEdge/#.updateEdge or #.addUndirectedEdge instead.`);if(t&&e.type==="directed")throw new ne(`Graph.${a}: you cannot merge/update an undirected edge to a directed graph. Use the #.mergeEdge/#.updateEdge or #.addDirectedEdge instead.`);if(s){if(l){if(typeof s!=="function")throw new j(`Graph.${a}: invalid updater function. Expecting a function but got "${s}"`)}else if(!Te(s))throw new j(`Graph.${a}: invalid attributes. Expecting an object but got "${s}"`)}i=""+i,o=""+o;let d;if(l)d=s,s=void 0;if(!e.allowSelfLoops&&i===o)throw new ne(`Graph.${a}: source & target are the same ("${i}"), thus creating a loop explicitly forbidden by this graph \'allowSelfLoops\' option set to false.`);let u=e._nodes.get(i),c=e._nodes.get(o),g,h;if(!n){if(g=e._edges.get(r),g){if(g.source.key!==i||g.target.key!==o){if(!t||g.source.key!==o||g.target.key!==i)throw new ne(`Graph.${a}: inconsistency detected when attempting to merge the "${r}" edge with "${i}" source & "${o}" target vs. ("${g.source.key}", "${g.target.key}").`)}h=g}}if(!h&&!e.multi&&u)h=t?u.undirected[o]:u.out[o];if(h){let b=[h.key,!1,!1,!1];if(l?!d:!s)return b;if(l){let m=h.attributes;h.attributes=d(m),e.emit("edgeAttributesUpdated",{type:"replace",key:h.key,attributes:h.attributes})}else ye(h.attributes,s),e.emit("edgeAttributesUpdated",{type:"merge",key:h.key,attributes:h.attributes,data:s});return b}if(s=s||{},l&&d)s=d(s);let p={key:null,undirected:t,source:i,target:o,attributes:s};if(n)r=e._edgeKeyGenerator();else if(r=""+r,e._edges.has(r))throw new ne(`Graph.${a}: the "${r}" edge already exists in the graph.`);let y=!1,v=!1;if(!u){if(u=cr(e,i,{}),y=!0,i===o)c=u,v=!0}if(!c)c=cr(e,o,{}),v=!0;g=new pt(t,r,u,c,s),e._edges.set(r,g);let f=i===o;if(t){if(u.undirectedDegree++,c.undirectedDegree++,f)u.undirectedLoops++,e._undirectedSelfLoopCount++}else if(u.outDegree++,c.inDegree++,f)u.directedLoops++,e._directedSelfLoopCount++;if(e.multi)g.attachMulti();else g.attach();if(t)e._undirectedSize++;else e._directedSize++;return p.key=r,e.emit("edgeAdded",p),[r,!0,y,v]}function gt(e,a){e._edges.delete(a.key);let{source:n,target:t,attributes:r}=a,i=a.undirected,o=n===t;if(i){if(n.undirectedDegree--,t.undirectedDegree--,o)n.undirectedLoops--,e._undirectedSelfLoopCount--}else if(n.outDegree--,t.inDegree--,o)n.directedLoops--,e._directedSelfLoopCount--;if(e.multi)a.detachMulti();else a.detach();if(i)e._undirectedSize--;else e._directedSize--;e.emit("edgeDropped",{key:a.key,attributes:r,source:n.key,target:t.key,undirected:i})}class ue extends De{constructor(e){super();if(e=ye({},il,e),typeof e.multi!=="boolean")throw new j(`Graph.constructor: invalid \'multi\' option. Expecting a boolean but got "${e.multi}".`);if(!al.has(e.type))throw new j(`Graph.constructor: invalid \'type\' option. Should be one of "mixed", "directed" or "undirected" but got "${e.type}".`);if(typeof e.allowSelfLoops!=="boolean")throw new j(`Graph.constructor: invalid \'allowSelfLoops\' option. Expecting a boolean but got "${e.allowSelfLoops}".`);let a=e.type==="mixed"?fr:e.type==="directed"?gr:vr;Le(this,"NodeDataClass",a);let n="geid_"+nl()+"_",t=0,r=()=>{let i;do i=n+t++;while(this._edges.has(i));return i};Le(this,"_attributes",{}),Le(this,"_nodes",new Map),Le(this,"_edges",new Map),Le(this,"_directedSize",0),Le(this,"_undirectedSize",0),Le(this,"_directedSelfLoopCount",0),Le(this,"_undirectedSelfLoopCount",0),Le(this,"_edgeKeyGenerator",r),Le(this,"_options",e),ur.forEach((i)=>Le(this,i,this[i])),Ge(this,"order",()=>this._nodes.size),Ge(this,"size",()=>this._edges.size),Ge(this,"directedSize",()=>this._directedSize),Ge(this,"undirectedSize",()=>this._undirectedSize),Ge(this,"selfLoopCount",()=>this._directedSelfLoopCount+this._undirectedSelfLoopCount),Ge(this,"directedSelfLoopCount",()=>this._directedSelfLoopCount),Ge(this,"undirectedSelfLoopCount",()=>this._undirectedSelfLoopCount),Ge(this,"multi",this._options.multi),Ge(this,"type",this._options.type),Ge(this,"allowSelfLoops",this._options.allowSelfLoops),Ge(this,"implementation",()=>"graphology")}_resetInstanceCounters(){this._directedSize=0,this._undirectedSize=0,this._directedSelfLoopCount=0,this._undirectedSelfLoopCount=0}hasNode(e){return this._nodes.has(""+e)}hasDirectedEdge(e,a){if(this.type==="undirected")return!1;if(arguments.length===1){let n=""+e,t=this._edges.get(n);return!!t&&!t.undirected}else if(arguments.length===2){e=""+e,a=""+a;let n=this._nodes.get(e);if(!n)return!1;return n.out.hasOwnProperty(a)}throw new j(`Graph.hasDirectedEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}hasUndirectedEdge(e,a){if(this.type==="directed")return!1;if(arguments.length===1){let n=""+e,t=this._edges.get(n);return!!t&&t.undirected}else if(arguments.length===2){e=""+e,a=""+a;let n=this._nodes.get(e);if(!n)return!1;return n.undirected.hasOwnProperty(a)}throw new j(`Graph.hasDirectedEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}hasEdge(e,a){if(arguments.length===1){let n=""+e;return this._edges.has(n)}else if(arguments.length===2){e=""+e,a=""+a;let n=this._nodes.get(e);if(!n)return!1;return typeof n.out<"u"&&n.out.hasOwnProperty(a)||typeof n.undirected<"u"&&n.undirected.hasOwnProperty(a)}throw new j(`Graph.hasEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}directedEdge(e,a){if(this.type==="undirected")return;if(e=""+e,a=""+a,this.multi)throw new ne("Graph.directedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.directedEdges instead.");let n=this._nodes.get(e);if(!n)throw new X(`Graph.directedEdge: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(a))throw new X(`Graph.directedEdge: could not find the "${a}" target node in the graph.`);let t=n.out&&n.out[a]||void 0;if(t)return t.key}undirectedEdge(e,a){if(this.type==="directed")return;if(e=""+e,a=""+a,this.multi)throw new ne("Graph.undirectedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.undirectedEdges instead.");let n=this._nodes.get(e);if(!n)throw new X(`Graph.undirectedEdge: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(a))throw new X(`Graph.undirectedEdge: could not find the "${a}" target node in the graph.`);let t=n.undirected&&n.undirected[a]||void 0;if(t)return t.key}edge(e,a){if(this.multi)throw new ne("Graph.edge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.edges instead.");e=""+e,a=""+a;let n=this._nodes.get(e);if(!n)throw new X(`Graph.edge: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(a))throw new X(`Graph.edge: could not find the "${a}" target node in the graph.`);let t=n.out&&n.out[a]||n.undirected&&n.undirected[a]||void 0;if(t)return t.key}areDirectedNeighbors(e,a){e=""+e,a=""+a;let n=this._nodes.get(e);if(!n)throw new X(`Graph.areDirectedNeighbors: could not find the "${e}" node in the graph.`);if(this.type==="undirected")return!1;return a in n.in||a in n.out}areOutNeighbors(e,a){e=""+e,a=""+a;let n=this._nodes.get(e);if(!n)throw new X(`Graph.areOutNeighbors: could not find the "${e}" node in the graph.`);if(this.type==="undirected")return!1;return a in n.out}areInNeighbors(e,a){e=""+e,a=""+a;let n=this._nodes.get(e);if(!n)throw new X(`Graph.areInNeighbors: could not find the "${e}" node in the graph.`);if(this.type==="undirected")return!1;return a in n.in}areUndirectedNeighbors(e,a){e=""+e,a=""+a;let n=this._nodes.get(e);if(!n)throw new X(`Graph.areUndirectedNeighbors: could not find the "${e}" node in the graph.`);if(this.type==="directed")return!1;return a in n.undirected}areNeighbors(e,a){e=""+e,a=""+a;let n=this._nodes.get(e);if(!n)throw new X(`Graph.areNeighbors: could not find the "${e}" node in the graph.`);if(this.type!=="undirected"){if(a in n.in||a in n.out)return!0}if(this.type!=="directed"){if(a in n.undirected)return!0}return!1}areInboundNeighbors(e,a){e=""+e,a=""+a;let n=this._nodes.get(e);if(!n)throw new X(`Graph.areInboundNeighbors: could not find the "${e}" node in the graph.`);if(this.type!=="undirected"){if(a in n.in)return!0}if(this.type!=="directed"){if(a in n.undirected)return!0}return!1}areOutboundNeighbors(e,a){e=""+e,a=""+a;let n=this._nodes.get(e);if(!n)throw new X(`Graph.areOutboundNeighbors: could not find the "${e}" node in the graph.`);if(this.type!=="undirected"){if(a in n.out)return!0}if(this.type!=="directed"){if(a in n.undirected)return!0}return!1}inDegree(e){e=""+e;let a=this._nodes.get(e);if(!a)throw new X(`Graph.inDegree: could not find the "${e}" node in the graph.`);if(this.type==="undirected")return 0;return a.inDegree}outDegree(e){e=""+e;let a=this._nodes.get(e);if(!a)throw new X(`Graph.outDegree: could not find the "${e}" node in the graph.`);if(this.type==="undirected")return 0;return a.outDegree}directedDegree(e){e=""+e;let a=this._nodes.get(e);if(!a)throw new X(`Graph.directedDegree: could not find the "${e}" node in the graph.`);if(this.type==="undirected")return 0;return a.inDegree+a.outDegree}undirectedDegree(e){e=""+e;let a=this._nodes.get(e);if(!a)throw new X(`Graph.undirectedDegree: could not find the "${e}" node in the graph.`);if(this.type==="directed")return 0;return a.undirectedDegree}inboundDegree(e){e=""+e;let a=this._nodes.get(e);if(!a)throw new X(`Graph.inboundDegree: could not find the "${e}" node in the graph.`);let n=0;if(this.type!=="directed")n+=a.undirectedDegree;if(this.type!=="undirected")n+=a.inDegree;return n}outboundDegree(e){e=""+e;let a=this._nodes.get(e);if(!a)throw new X(`Graph.outboundDegree: could not find the "${e}" node in the graph.`);let n=0;if(this.type!=="directed")n+=a.undirectedDegree;if(this.type!=="undirected")n+=a.outDegree;return n}degree(e){e=""+e;let a=this._nodes.get(e);if(!a)throw new X(`Graph.degree: could not find the "${e}" node in the graph.`);let n=0;if(this.type!=="directed")n+=a.undirectedDegree;if(this.type!=="undirected")n+=a.inDegree+a.outDegree;return n}inDegreeWithoutSelfLoops(e){e=""+e;let a=this._nodes.get(e);if(!a)throw new X(`Graph.inDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);if(this.type==="undirected")return 0;return a.inDegree-a.directedLoops}outDegreeWithoutSelfLoops(e){e=""+e;let a=this._nodes.get(e);if(!a)throw new X(`Graph.outDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);if(this.type==="undirected")return 0;return a.outDegree-a.directedLoops}directedDegreeWithoutSelfLoops(e){e=""+e;let a=this._nodes.get(e);if(!a)throw new X(`Graph.directedDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);if(this.type==="undirected")return 0;return a.inDegree+a.outDegree-a.directedLoops*2}undirectedDegreeWithoutSelfLoops(e){e=""+e;let a=this._nodes.get(e);if(!a)throw new X(`Graph.undirectedDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);if(this.type==="directed")return 0;return a.undirectedDegree-a.undirectedLoops*2}inboundDegreeWithoutSelfLoops(e){e=""+e;let a=this._nodes.get(e);if(!a)throw new X(`Graph.inboundDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);let n=0,t=0;if(this.type!=="directed")n+=a.undirectedDegree,t+=a.undirectedLoops*2;if(this.type!=="undirected")n+=a.inDegree,t+=a.directedLoops;return n-t}outboundDegreeWithoutSelfLoops(e){e=""+e;let a=this._nodes.get(e);if(!a)throw new X(`Graph.outboundDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);let n=0,t=0;if(this.type!=="directed")n+=a.undirectedDegree,t+=a.undirectedLoops*2;if(this.type!=="undirected")n+=a.outDegree,t+=a.directedLoops;return n-t}degreeWithoutSelfLoops(e){e=""+e;let a=this._nodes.get(e);if(!a)throw new X(`Graph.degreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);let n=0,t=0;if(this.type!=="directed")n+=a.undirectedDegree,t+=a.undirectedLoops*2;if(this.type!=="undirected")n+=a.inDegree+a.outDegree,t+=a.directedLoops*2;return n-t}source(e){e=""+e;let a=this._edges.get(e);if(!a)throw new X(`Graph.source: could not find the "${e}" edge in the graph.`);return a.source.key}target(e){e=""+e;let a=this._edges.get(e);if(!a)throw new X(`Graph.target: could not find the "${e}" edge in the graph.`);return a.target.key}extremities(e){e=""+e;let a=this._edges.get(e);if(!a)throw new X(`Graph.extremities: could not find the "${e}" edge in the graph.`);return[a.source.key,a.target.key]}opposite(e,a){e=""+e,a=""+a;let n=this._edges.get(a);if(!n)throw new X(`Graph.opposite: could not find the "${a}" edge in the graph.`);let t=n.source.key,r=n.target.key;if(e===t)return r;if(e===r)return t;throw new X(`Graph.opposite: the "${e}" node is not attached to the "${a}" edge (${t}, ${r}).`)}hasExtremity(e,a){e=""+e,a=""+a;let n=this._edges.get(e);if(!n)throw new X(`Graph.hasExtremity: could not find the "${e}" edge in the graph.`);return n.source.key===a||n.target.key===a}isUndirected(e){e=""+e;let a=this._edges.get(e);if(!a)throw new X(`Graph.isUndirected: could not find the "${e}" edge in the graph.`);return a.undirected}isDirected(e){e=""+e;let a=this._edges.get(e);if(!a)throw new X(`Graph.isDirected: could not find the "${e}" edge in the graph.`);return!a.undirected}isSelfLoop(e){e=""+e;let a=this._edges.get(e);if(!a)throw new X(`Graph.isSelfLoop: could not find the "${e}" edge in the graph.`);return a.source===a.target}addNode(e,a){return ol(this,e,a).key}mergeNode(e,a){if(a&&!Te(a))throw new j(`Graph.mergeNode: invalid attributes. Expecting an object but got "${a}"`);e=""+e,a=a||{};let n=this._nodes.get(e);if(n){if(a)ye(n.attributes,a),this.emit("nodeAttributesUpdated",{type:"merge",key:e,attributes:n.attributes,data:a});return[e,!1]}return n=new this.NodeDataClass(e,a),this._nodes.set(e,n),this.emit("nodeAdded",{key:e,attributes:a}),[e,!0]}updateNode(e,a){if(a&&typeof a!=="function")throw new j(`Graph.updateNode: invalid updater function. Expecting a function but got "${a}"`);e=""+e;let n=this._nodes.get(e);if(n){if(a){let r=n.attributes;n.attributes=a(r),this.emit("nodeAttributesUpdated",{type:"replace",key:e,attributes:n.attributes})}return[e,!1]}let t=a?a({}):{};return n=new this.NodeDataClass(e,t),this._nodes.set(e,n),this.emit("nodeAdded",{key:e,attributes:t}),[e,!0]}dropNode(e){e=""+e;let a=this._nodes.get(e);if(!a)throw new X(`Graph.dropNode: could not find the "${e}" node in the graph.`);let n;if(this.type!=="undirected"){for(let t in a.out){n=a.out[t];do gt(this,n),n=n.next;while(n)}for(let t in a.in){n=a.in[t];do gt(this,n),n=n.next;while(n)}}if(this.type!=="directed")for(let t in a.undirected){n=a.undirected[t];do gt(this,n),n=n.next;while(n)}this._nodes.delete(e),this.emit("nodeDropped",{key:e,attributes:a.attributes})}dropEdge(e){let a;if(arguments.length>1){let n=""+arguments[0],t=""+arguments[1];if(a=Ce(this,n,t,this.type),!a)throw new X(`Graph.dropEdge: could not find the "${n}" -> "${t}" edge in the graph.`)}else if(e=""+e,a=this._edges.get(e),!a)throw new X(`Graph.dropEdge: could not find the "${e}" edge in the graph.`);return gt(this,a),this}dropDirectedEdge(e,a){if(arguments.length<2)throw new ne("Graph.dropDirectedEdge: it does not make sense to try and drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.");if(this.multi)throw new ne("Graph.dropDirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.");e=""+e,a=""+a;let n=Ce(this,e,a,"directed");if(!n)throw new X(`Graph.dropDirectedEdge: could not find a "${e}" -> "${a}" edge in the graph.`);return gt(this,n),this}dropUndirectedEdge(e,a){if(arguments.length<2)throw new ne("Graph.dropUndirectedEdge: it does not make sense to drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.");if(this.multi)throw new ne("Graph.dropUndirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.");let n=Ce(this,e,a,"undirected");if(!n)throw new X(`Graph.dropUndirectedEdge: could not find a "${e}" -> "${a}" edge in the graph.`);return gt(this,n),this}clear(){this._edges.clear(),this._nodes.clear(),this._resetInstanceCounters(),this.emit("cleared")}clearEdges(){let e=this._nodes.values(),a;while(a=e.next(),a.done!==!0)a.value.clear();this._edges.clear(),this._resetInstanceCounters(),this.emit("edgesCleared")}getAttribute(e){return this._attributes[e]}getAttributes(){return this._attributes}hasAttribute(e){return this._attributes.hasOwnProperty(e)}setAttribute(e,a){return this._attributes[e]=a,this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:e}),this}updateAttribute(e,a){if(typeof a!=="function")throw new j("Graph.updateAttribute: updater should be a function.");let n=this._attributes[e];return this._attributes[e]=a(n),this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:e}),this}removeAttribute(e){return delete this._attributes[e],this.emit("attributesUpdated",{type:"remove",attributes:this._attributes,name:e}),this}replaceAttributes(e){if(!Te(e))throw new j("Graph.replaceAttributes: provided attributes are not a plain object.");return this._attributes=e,this.emit("attributesUpdated",{type:"replace",attributes:this._attributes}),this}mergeAttributes(e){if(!Te(e))throw new j("Graph.mergeAttributes: provided attributes are not a plain object.");return ye(this._attributes,e),this.emit("attributesUpdated",{type:"merge",attributes:this._attributes,data:e}),this}updateAttributes(e){if(typeof e!=="function")throw new j("Graph.updateAttributes: provided updater is not a function.");return this._attributes=e(this._attributes),this.emit("attributesUpdated",{type:"update",attributes:this._attributes}),this}updateEachNodeAttributes(e,a){if(typeof e!=="function")throw new j("Graph.updateEachNodeAttributes: expecting an updater function.");if(a&&!dr(a))throw new j("Graph.updateEachNodeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}");let n=this._nodes.values(),t,r;while(t=n.next(),t.done!==!0)r=t.value,r.attributes=e(r.key,r.attributes);this.emit("eachNodeAttributesUpdated",{hints:a?a:null})}updateEachEdgeAttributes(e,a){if(typeof e!=="function")throw new j("Graph.updateEachEdgeAttributes: expecting an updater function.");if(a&&!dr(a))throw new j("Graph.updateEachEdgeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}");let n=this._edges.values(),t,r,i,o;while(t=n.next(),t.done!==!0)r=t.value,i=r.source,o=r.target,r.attributes=e(r.key,r.attributes,i.key,o.key,i.attributes,o.attributes,r.undirected);this.emit("eachEdgeAttributesUpdated",{hints:a?a:null})}forEachAdjacencyEntry(e){if(typeof e!=="function")throw new j("Graph.forEachAdjacencyEntry: expecting a callback.");on(!1,!1,!1,this,e)}forEachAdjacencyEntryWithOrphans(e){if(typeof e!=="function")throw new j("Graph.forEachAdjacencyEntryWithOrphans: expecting a callback.");on(!1,!1,!0,this,e)}forEachAssymetricAdjacencyEntry(e){if(typeof e!=="function")throw new j("Graph.forEachAssymetricAdjacencyEntry: expecting a callback.");on(!1,!0,!1,this,e)}forEachAssymetricAdjacencyEntryWithOrphans(e){if(typeof e!=="function")throw new j("Graph.forEachAssymetricAdjacencyEntryWithOrphans: expecting a callback.");on(!1,!0,!0,this,e)}nodes(){return Array.from(this._nodes.keys())}forEachNode(e){if(typeof e!=="function")throw new j("Graph.forEachNode: expecting a callback.");let a=this._nodes.values(),n,t;while(n=a.next(),n.done!==!0)t=n.value,e(t.key,t.attributes)}findNode(e){if(typeof e!=="function")throw new j("Graph.findNode: expecting a callback.");let a=this._nodes.values(),n,t;while(n=a.next(),n.done!==!0)if(t=n.value,e(t.key,t.attributes))return t.key;return}mapNodes(e){if(typeof e!=="function")throw new j("Graph.mapNode: expecting a callback.");let a=this._nodes.values(),n,t,r=Array(this.order),i=0;while(n=a.next(),n.done!==!0)t=n.value,r[i++]=e(t.key,t.attributes);return r}someNode(e){if(typeof e!=="function")throw new j("Graph.someNode: expecting a callback.");let a=this._nodes.values(),n,t;while(n=a.next(),n.done!==!0)if(t=n.value,e(t.key,t.attributes))return!0;return!1}everyNode(e){if(typeof e!=="function")throw new j("Graph.everyNode: expecting a callback.");let a=this._nodes.values(),n,t;while(n=a.next(),n.done!==!0)if(t=n.value,!e(t.key,t.attributes))return!1;return!0}filterNodes(e){if(typeof e!=="function")throw new j("Graph.filterNodes: expecting a callback.");let a=this._nodes.values(),n,t,r=[];while(n=a.next(),n.done!==!0)if(t=n.value,e(t.key,t.attributes))r.push(t.key);return r}reduceNodes(e,a){if(typeof e!=="function")throw new j("Graph.reduceNodes: expecting a callback.");if(arguments.length<2)throw new j("Graph.reduceNodes: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.");let n=a,t=this._nodes.values(),r,i;while(r=t.next(),r.done!==!0)i=r.value,n=e(n,i.key,i.attributes);return n}nodeEntries(){let e=this._nodes.values();return{[Symbol.iterator](){return this},next(){let a=e.next();if(a.done)return a;let n=a.value;return{value:{node:n.key,attributes:n.attributes},done:!1}}}}export(){let e=Array(this._nodes.size),a=0;this._nodes.forEach((t,r)=>{e[a++]=Qs(r,t)});let n=Array(this._edges.size);return a=0,this._edges.forEach((t,r)=>{n[a++]=Js(this.type,r,t)}),{options:{type:this.type,multi:this.multi,allowSelfLoops:this.allowSelfLoops},attributes:this.getAttributes(),nodes:e,edges:n}}import(e,a=!1){if(e instanceof ue)return e.forEachNode((s,l)=>{if(a)this.mergeNode(s,l);else this.addNode(s,l)}),e.forEachEdge((s,l,d,u,c,g,h)=>{if(a)if(h)this.mergeUndirectedEdgeWithKey(s,d,u,l);else this.mergeDirectedEdgeWithKey(s,d,u,l);else if(h)this.addUndirectedEdgeWithKey(s,d,u,l);else this.addDirectedEdgeWithKey(s,d,u,l)}),this;if(!Te(e))throw new j("Graph.import: invalid argument. Expecting a serialized graph or, alternatively, a Graph instance.");if(e.attributes){if(!Te(e.attributes))throw new j("Graph.import: invalid attributes. Expecting a plain object.");if(a)this.mergeAttributes(e.attributes);else this.replaceAttributes(e.attributes)}let n,t,r,i,o;if(e.nodes){if(r=e.nodes,!Array.isArray(r))throw new j("Graph.import: invalid nodes. Expecting an array.");for(n=0,t=r.length;n<t;n++){i=r[n],el(i);let{key:s,attributes:l}=i;if(a)this.mergeNode(s,l);else this.addNode(s,l)}}if(e.edges){let s=!1;if(this.type==="undirected")s=!0;if(r=e.edges,!Array.isArray(r))throw new j("Graph.import: invalid edges. Expecting an array.");for(n=0,t=r.length;n<t;n++){o=r[n],tl(o);let{source:l,target:d,attributes:u,undirected:c=s}=o,g;if("key"in o)g=a?c?this.mergeUndirectedEdgeWithKey:this.mergeDirectedEdgeWithKey:c?this.addUndirectedEdgeWithKey:this.addDirectedEdgeWithKey,g.call(this,o.key,l,d,u);else g=a?c?this.mergeUndirectedEdge:this.mergeDirectedEdge:c?this.addUndirectedEdge:this.addDirectedEdge,g.call(this,l,d,u)}}return this}nullCopy(e){let a=new ue(ye({},this._options,e));return a.replaceAttributes(ye({},this.getAttributes())),a}emptyCopy(e){let a=this.nullCopy(e);return this._nodes.forEach((n,t)=>{let r=ye({},n.attributes);n=new a.NodeDataClass(t,r),a._nodes.set(t,n)}),a}copy(e){if(e=e||{},typeof e.type==="string"&&e.type!==this.type&&e.type!=="mixed")throw new ne(`Graph.copy: cannot create an incompatible copy from "${this.type}" type to "${e.type}" because this would mean losing information about the current graph.`);if(typeof e.multi==="boolean"&&e.multi!==this.multi&&e.multi!==!0)throw new ne("Graph.copy: cannot create an incompatible copy by downgrading a multi graph to a simple one because this would mean losing information about the current graph.");if(typeof e.allowSelfLoops==="boolean"&&e.allowSelfLoops!==this.allowSelfLoops&&e.allowSelfLoops!==!0)throw new ne("Graph.copy: cannot create an incompatible copy from a graph allowing self loops to one that does not because this would mean losing information about the current graph.");let a=this.emptyCopy(e),n=this._edges.values(),t,r;while(t=n.next(),t.done!==!0)r=t.value,xr(a,"copy",!1,r.undirected,r.key,r.source.key,r.target.key,ye({},r.attributes));return a}toJSON(){return this.export()}toString(){return"[object Graph]"}inspect(){let e={};this._nodes.forEach((r,i)=>{e[i]=r.attributes});let a={},n={};this._edges.forEach((r,i)=>{let o=r.undirected?"--":"->",s="",l=r.source.key,d=r.target.key,u;if(r.undirected&&l>d)u=l,l=d,d=u;let c=`(${l})${o}(${d})`;if(!i.startsWith("geid_"))s+=`[${i}]: `;else if(this.multi){if(typeof n[c]>"u")n[c]=0;else n[c]++;s+=`${n[c]}. `}s+=c,a[s]=r.attributes});let t={};for(let r in this)if(this.hasOwnProperty(r)&&!ur.has(r)&&typeof this[r]!=="function"&&typeof r!=="symbol")t[r]=this[r];return t.attributes=this._attributes,t.nodes=e,t.edges=a,Le(t,"constructor",this.constructor),t}}if(typeof Symbol<"u")ue.prototype[Symbol.for("nodejs.util.inspect.custom")]=ue.prototype.inspect;rl.forEach((e)=>{["add","merge","update"].forEach((a)=>{let n=e.name(a),t=a==="add"?xr:sl;if(e.generateKey)ue.prototype[n]=function(r,i,o){return t(this,n,!0,(e.type||this.type)==="undirected",null,r,i,o,a==="update")};else ue.prototype[n]=function(r,i,o,s){return t(this,n,!1,(e.type||this.type)==="undirected",r,i,o,s,a==="update")}})});ps(ue);ws(ue);Hs(ue);Zs(ue);class ta extends ue{constructor(e){let a=ye({type:"directed"},e);if("multi"in a&&a.multi!==!1)throw new j("DirectedGraph.from: inconsistent indication that the graph should be multi in given options!");if(a.type!=="directed")throw new j(\'DirectedGraph.from: inconsistent "\'+a.type+\'" type in given options!\');super(a)}}class na extends ue{constructor(e){let a=ye({type:"undirected"},e);if("multi"in a&&a.multi!==!1)throw new j("UndirectedGraph.from: inconsistent indication that the graph should be multi in given options!");if(a.type!=="undirected")throw new j(\'UndirectedGraph.from: inconsistent "\'+a.type+\'" type in given options!\');super(a)}}class aa extends ue{constructor(e){let a=ye({multi:!0},e);if("multi"in a&&a.multi!==!0)throw new j("MultiGraph.from: inconsistent indication that the graph should be simple in given options!");super(a)}}class ra extends ue{constructor(e){let a=ye({type:"directed",multi:!0},e);if("multi"in a&&a.multi!==!0)throw new j("MultiDirectedGraph.from: inconsistent indication that the graph should be simple in given options!");if(a.type!=="directed")throw new j(\'MultiDirectedGraph.from: inconsistent "\'+a.type+\'" type in given options!\');super(a)}}class ia extends ue{constructor(e){let a=ye({type:"undirected",multi:!0},e);if("multi"in a&&a.multi!==!0)throw new j("MultiUndirectedGraph.from: inconsistent indication that the graph should be simple in given options!");if(a.type!=="undirected")throw new j(\'MultiUndirectedGraph.from: inconsistent "\'+a.type+\'" type in given options!\');super(a)}}function mt(e){e.from=function(a,n){let t=ye({},a.options,n),r=new e(t);return r.import(a),r}}mt(ue);mt(ta);mt(na);mt(aa);mt(ra);mt(ia);ue.Graph=ue;ue.DirectedGraph=ta;ue.UndirectedGraph=na;ue.MultiGraph=aa;ue.MultiDirectedGraph=ra;ue.MultiUndirectedGraph=ia;ue.InvalidArgumentsGraphError=j;ue.NotFoundGraphError=X;ue.UsageGraphError=ne;function cn(e,a){(a==null||a>e.length)&&(a=e.length);for(var n=0,t=Array(a);n<a;n++)t[n]=e[n];return t}function hn(e,a){if(e){if(typeof e=="string")return cn(e,a);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?cn(e,a):void 0}}function ll(e){if(Array.isArray(e))return e}function dl(e,a){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var t,r,i,o,s=[],l=!0,d=!1;try{if(i=(n=n.call(e)).next,a===0){if(Object(n)!==n)return;l=!1}else for(;!(l=(t=i.call(n)).done)&&(s.push(t.value),s.length!==a);l=!0);}catch(u){d=!0,r=u}finally{try{if(!l&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(d)throw r}}return s}}function ul(){throw TypeError(`Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function le(e,a){return ll(e)||dl(e,a)||hn(e,a)||ul()}function W(e,a){var n=typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=hn(e))||a&&e&&typeof e.length=="number"){n&&(e=n);var t=0,r=function(){};return{s:r,n:function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}},e:function(l){throw l},f:r}}throw TypeError(`Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var i,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var l=n.next();return o=l.done,l},e:function(l){s=!0,i=l},f:function(){try{o||n.return==null||n.return()}finally{if(s)throw i}}}}function ke(){return Float32Array.of(1,0,0,0,1,0,0,0,1)}function dn(e,a,n){return e[0]=a,e[4]=typeof n==="number"?n:a,e}function _r(e,a){var n=Math.sin(a),t=Math.cos(a);return e[0]=t,e[1]=n,e[3]=-n,e[4]=t,e}function Tr(e,a,n){return e[6]=a,e[7]=n,e}function je(e,a){var n=e[0],t=e[1],r=e[2],i=e[3],o=e[4],s=e[5],l=e[6],d=e[7],u=e[8],c=a[0],g=a[1],h=a[2],p=a[3],y=a[4],v=a[5],f=a[6],b=a[7],m=a[8];return e[0]=c*n+g*i+h*l,e[1]=c*t+g*o+h*d,e[2]=c*r+g*s+h*u,e[3]=p*n+y*i+v*l,e[4]=p*t+y*o+v*d,e[5]=p*r+y*s+v*u,e[6]=f*n+b*i+m*l,e[7]=f*t+b*o+m*d,e[8]=f*r+b*s+m*u,e}function oa(e,a){var n=Math.cos(a),t=Math.sin(a);return{x:n*e.x+t*e.y,y:-t*e.x+n*e.y}}function xt(e,a){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:1,t=e[0],r=e[1],i=e[3],o=e[4],s=e[6],l=e[7],{x:d,y:u}=a;return{x:d*t+u*i+s*n,y:d*r+u*o+l*n}}function cl(e,a){var n=e.height/e.width,t=a.height/a.width;if(n<1&&t>1||n>1&&t<1)return 1;return Math.min(Math.max(t,1/t),Math.max(1/n,n))}function qe(e,a,n,t,r){var{angle:i,ratio:o,x:s,y:l}=e,{width:d,height:u}=a,c=ke(),g=Math.min(d,u)-2*t,h=cl(a,n);if(!r)je(c,dn(ke(),2*(g/d)*h,2*(g/u)*h)),je(c,_r(ke(),-i)),je(c,dn(ke(),1/o)),je(c,Tr(ke(),-s,-l));else je(c,Tr(ke(),s,l)),je(c,dn(ke(),o)),je(c,_r(ke(),i)),je(c,dn(ke(),d/g/2/h,u/g/2/h));return c}function Sr(e,a,n){var t=xt(e,{x:Math.cos(a.angle),y:Math.sin(a.angle)},0),{x:r,y:i}=t;return 1/Math.sqrt(Math.pow(r,2)+Math.pow(i,2))/n.width}function sa(e,a,n,t,r){var i=Math.floor(a/r*t),o=Math.floor(e.drawingBufferHeight/r-n/r*t);return[i,o]}var Ot={black:"#000000",silver:"#C0C0C0",gray:"#808080",grey:"#808080",white:"#FFFFFF",maroon:"#800000",red:"#FF0000",purple:"#800080",fuchsia:"#FF00FF",green:"#008000",lime:"#00FF00",olive:"#808000",yellow:"#FFFF00",navy:"#000080",blue:"#0000FF",teal:"#008080",aqua:"#00FFFF",darkblue:"#00008B",mediumblue:"#0000CD",darkgreen:"#006400",darkcyan:"#008B8B",deepskyblue:"#00BFFF",darkturquoise:"#00CED1",mediumspringgreen:"#00FA9A",springgreen:"#00FF7F",cyan:"#00FFFF",midnightblue:"#191970",dodgerblue:"#1E90FF",lightseagreen:"#20B2AA",forestgreen:"#228B22",seagreen:"#2E8B57",darkslategray:"#2F4F4F",darkslategrey:"#2F4F4F",limegreen:"#32CD32",mediumseagreen:"#3CB371",turquoise:"#40E0D0",royalblue:"#4169E1",steelblue:"#4682B4",darkslateblue:"#483D8B",mediumturquoise:"#48D1CC",indigo:"#4B0082",darkolivegreen:"#556B2F",cadetblue:"#5F9EA0",cornflowerblue:"#6495ED",rebeccapurple:"#663399",mediumaquamarine:"#66CDAA",dimgray:"#696969",dimgrey:"#696969",slateblue:"#6A5ACD",olivedrab:"#6B8E23",slategray:"#708090",slategrey:"#708090",lightslategray:"#778899",lightslategrey:"#778899",mediumslateblue:"#7B68EE",lawngreen:"#7CFC00",chartreuse:"#7FFF00",aquamarine:"#7FFFD4",skyblue:"#87CEEB",lightskyblue:"#87CEFA",blueviolet:"#8A2BE2",darkred:"#8B0000",darkmagenta:"#8B008B",saddlebrown:"#8B4513",darkseagreen:"#8FBC8F",lightgreen:"#90EE90",mediumpurple:"#9370DB",darkviolet:"#9400D3",palegreen:"#98FB98",darkorchid:"#9932CC",yellowgreen:"#9ACD32",sienna:"#A0522D",brown:"#A52A2A",darkgray:"#A9A9A9",darkgrey:"#A9A9A9",lightblue:"#ADD8E6",greenyellow:"#ADFF2F",paleturquoise:"#AFEEEE",lightsteelblue:"#B0C4DE",powderblue:"#B0E0E6",firebrick:"#B22222",darkgoldenrod:"#B8860B",mediumorchid:"#BA55D3",rosybrown:"#BC8F8F",darkkhaki:"#BDB76B",mediumvioletred:"#C71585",indianred:"#CD5C5C",peru:"#CD853F",chocolate:"#D2691E",tan:"#D2B48C",lightgray:"#D3D3D3",lightgrey:"#D3D3D3",thistle:"#D8BFD8",orchid:"#DA70D6",goldenrod:"#DAA520",palevioletred:"#DB7093",crimson:"#DC143C",gainsboro:"#DCDCDC",plum:"#DDA0DD",burlywood:"#DEB887",lightcyan:"#E0FFFF",lavender:"#E6E6FA",darksalmon:"#E9967A",violet:"#EE82EE",palegoldenrod:"#EEE8AA",lightcoral:"#F08080",khaki:"#F0E68C",aliceblue:"#F0F8FF",honeydew:"#F0FFF0",azure:"#F0FFFF",sandybrown:"#F4A460",wheat:"#F5DEB3",beige:"#F5F5DC",whitesmoke:"#F5F5F5",mintcream:"#F5FFFA",ghostwhite:"#F8F8FF",salmon:"#FA8072",antiquewhite:"#FAEBD7",linen:"#FAF0E6",lightgoldenrodyellow:"#FAFAD2",oldlace:"#FDF5E6",magenta:"#FF00FF",deeppink:"#FF1493",orangered:"#FF4500",tomato:"#FF6347",hotpink:"#FF69B4",coral:"#FF7F50",darkorange:"#FF8C00",lightsalmon:"#FFA07A",orange:"#FFA500",lightpink:"#FFB6C1",pink:"#FFC0CB",gold:"#FFD700",peachpuff:"#FFDAB9",navajowhite:"#FFDEAD",moccasin:"#FFE4B5",bisque:"#FFE4C4",mistyrose:"#FFE4E1",blanchedalmond:"#FFEBCD",papayawhip:"#FFEFD5",lavenderblush:"#FFF0F5",seashell:"#FFF5EE",cornsilk:"#FFF8DC",lemonchiffon:"#FFFACD",floralwhite:"#FFFAF0",snow:"#FFFAFA",lightyellow:"#FFFFE0",ivory:"#FFFFF0"},Er=new Int8Array(4),un=new Int32Array(Er.buffer,0,1),Rr=new Float32Array(Er.buffer,0,1),hl=/^\\s*rgba?\\s*\\(/,fl=/^\\s*rgba?\\s*\\(\\s*([0-9]*)\\s*,\\s*([0-9]*)\\s*,\\s*([0-9]*)(?:\\s*,\\s*(.*)?)?\\)\\s*$/;function fn(e){var a=0,n=0,t=0,r=1,i=e.toLowerCase();if(i==="transparent")return{r:0,g:0,b:0,a:0};if(i in Ot)return fn(Ot[i]);if(e[0]==="#"){if(e.length===4)a=parseInt(e.charAt(1)+e.charAt(1),16),n=parseInt(e.charAt(2)+e.charAt(2),16),t=parseInt(e.charAt(3)+e.charAt(3),16);else a=parseInt(e.charAt(1)+e.charAt(2),16),n=parseInt(e.charAt(3)+e.charAt(4),16),t=parseInt(e.charAt(5)+e.charAt(6),16);if(e.length===9)r=parseInt(e.charAt(7)+e.charAt(8),16)/255}else if(hl.test(e)){var o=e.match(fl);if(o){if(a=+o[1],n=+o[2],t=+o[3],o[4])r=+o[4]}}return{r:a,g:n,b:t,a:r}}function Ar(e){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,n=fn(e),{r:t,g:r,b:i,a:o}=n;if(a)return[t/255*o,r/255*o,i/255*o,o];return[t/255,r/255,i/255,o]}var yt={};for(bt in Ot)yt[bt]=Pe(Ot[bt]),yt[Ot[bt]]=yt[bt];var bt;function gl(e,a,n,t,r){if(un[0]=t<<24|n<<16|a<<8|e,r)un[0]=un[0]&4278190079;return Rr[0]}function Pe(e){if(e=e.toLowerCase(),typeof yt[e]<"u")return yt[e];var a=fn(e),{r:n,g:t,b:r,a:i}=a;i=i*255|0;var o=gl(n,t,r,i,!0);return yt[e]=o,o}function Ye(e,a){Rr[0]=Pe(e);var n=un[0];if(a)n=n|16777216;var t=n&255,r=n>>8&255,i=n>>16&255,o=n>>24&255;return[t,r,i,o]}function _t(e){var a=e>>>8&255,n=e>>>16&255,t=e>>>24&255,r=e&255;return(r<<24|t<<16|n<<8|a)>>>0}function la(e,a,n,t){return(n<<24|a<<16|e<<8|t)>>>0}function wr(e,a,n,t,r,i){var o=sa(e,n,t,r,i),s=le(o,2),l=s[0],d=s[1],u=new Uint8Array(4);e.bindFramebuffer(e.FRAMEBUFFER,a),e.readPixels(l,d,1,1,e.RGBA,e.UNSIGNED_BYTE,u);var c=le(u,4),g=c[0],h=c[1],p=c[2],y=c[3];return[g,h,p,y]}function Dr(e){var a=fn(e),{r:n,g:t,b:r,a:i}=a,o=(n/255).toFixed(6),s=(t/255).toFixed(6),l=(r/255).toFixed(6),d=i.toFixed(6);return"vec4(".concat(o,", ").concat(s,", ").concat(l,", ").concat(d,")")}function vl(e,a){if(typeof e!="object"||!e)return e;var n;if(typeof Symbol<"u"&&(n=e[Symbol.toPrimitive])!==void 0){var t=n.call(e,a||"default");if(typeof t!="object")return t;throw TypeError("@@toPrimitive must return a primitive value.")}return(a==="string"?String:Number)(e)}function kr(e){var a=vl(e,"string");return typeof a=="symbol"?a:a+""}function R(e,a,n){return(a=kr(a))in e?Object.defineProperty(e,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[a]=n,e}function Lr(e,a){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);a&&(t=t.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),n.push.apply(n,t)}return n}function V(e){for(var a=1;a<arguments.length;a++){var n=arguments[a]!=null?arguments[a]:{};a%2?Lr(Object(n),!0).forEach(function(t){R(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Lr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function ie(e,a){if(!(e instanceof a))throw TypeError("Cannot call a class as a function")}function Cr(e,a){for(var n=0;n<a.length;n++){var t=a[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,kr(t.key),t)}}function oe(e,a,n){return a&&Cr(e.prototype,a),n&&Cr(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function at(e){return at=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(a){return a.__proto__||Object.getPrototypeOf(a)},at(e)}function Pr(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(a){}return(Pr=function(){return!!e})()}function pl(e){if(e===void 0)throw ReferenceError("this hasn\'t been initialised - super() hasn\'t been called");return e}function ml(e,a){if(a&&(typeof a=="object"||typeof a=="function"))return a;if(a!==void 0)throw TypeError("Derived constructors may only return object or undefined");return pl(e)}function fe(e,a,n){return a=at(a),ml(e,Pr()?Reflect.construct(a,n||[],at(e).constructor):a.apply(e,n))}function da(e,a){return da=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,t){return n.__proto__=t,n},da(e,a)}function ge(e,a){if(typeof a!="function"&&a!==null)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(a&&a.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),a&&da(e,a)}function bl(e){if(Array.isArray(e))return cn(e)}function yl(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function xl(){throw TypeError(`Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function J(e){return bl(e)||yl(e)||hn(e)||xl()}function se(e){return se=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(a){return typeof a}:function(a){return a&&typeof Symbol=="function"&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},se(e)}function Fe(e){return se(e)==="object"&&e!==null&&"attribute"in e}function Bt(){var e=`\nfloat sdf_circle(vec2 uv, float size) {\n return length(uv) - size;\n}\n`;return{name:"circle",glsl:e,uniforms:[]}}function ua(e){var a,n=WebGL2RenderingContext,t=n.UNSIGNED_BYTE,r=(a=e===null||e===void 0?void 0:e.color)!==null&&a!==void 0?a:{attribute:"color"};if(!Fe(r)){var i=r,o=`\nvec4 layer_fill() {\n return `.concat(Dr(i),`;\n}\n`);return{name:"fill",uniforms:[],attributes:[],glsl:o}}var s=r.attribute,l=`\nvec4 layer_fill(vec4 v_fillColor) {\n return v_fillColor;\n}\n`;return{name:"fill",uniforms:[],attributes:[{name:"fillColor",size:4,type:t,normalized:!0,source:s}],glsl:l}}function ca(e,a){if(typeof e==="string"){var n=Ar(e).map(function(d){return d.toFixed(6)}),t=le(n,4),r=t[0],i=t[1],o=t[2],s=t[3];return{glsl:"vec4(".concat(r,", ").concat(i,", ").concat(o,", ").concat(s,")"),attributes:[],needsNodeColors:!1}}if("node"in e&&e.node)return{glsl:e.node==="source"?"v_sourceColor":"v_targetColor",attributes:[],needsNodeColors:!0};var l=e;return{glsl:"v_".concat(a),attributes:[{name:"a_".concat(a),size:4,type:WebGL2RenderingContext.UNSIGNED_BYTE,normalized:!0,source:l.attribute,defaultValue:l.default}],needsNodeColors:!1}}function Ke(e){var a=e===null||e===void 0?void 0:e.color;if(a===void 0){var n=`\n// Plain solid color layer\nvec4 layer_plain(EdgeContext ctx) {\n return v_color;\n}\n`;return{name:"plain",glsl:n,uniforms:[],attributes:[]}}var t=ca(a,"plainColor"),r=`\n// Plain solid color layer\nvec4 layer_plain(EdgeContext ctx) {\n return `.concat(t.glsl,`;\n}\n`);return{name:"plain",glsl:r,uniforms:[],attributes:t.attributes,needsNodeColors:t.needsNodeColors}}function ha(){var e=`\n// Position at parameter t ∈ [0, 1]\nvec2 path_straight_position(float t, vec2 source, vec2 target) {\n return mix(source, target, t);\n}\n\n// Total length of the path (analytical - more efficient than sampling)\nfloat path_straight_length(vec2 source, vec2 target) {\n return length(target - source);\n}\n`;return{name:"straight",segments:1,minBodyLengthRatio:0,linearParameterization:!0,glsl:e,uniforms:[],attributes:[]}}function fa(e){var a=e!==null&&e!==void 0?e:{},n=a.segments,t=n===void 0?32:n,r=`\nconst float LOOP_PI = 3.141592653589793;\n\nfloat loopWorldRadius() {\n float nodeWorldRadius = v_sourceNodeSize * u_correctionRatio / u_sizeRatio;\n return max(v_loopRadius * nodeWorldRadius, 0.001);\n}\n\n// Cubic Bézier with P0 = P3 = source.\n// Control points extend outward orthogonal to the node surface at exit/entry angles.\nvec2 path_loop_position(float t, vec2 source, vec2 target) {\n float R = loopWorldRadius();\n float angle = v_loopAngle + (v_loopFixedOrientation > 0.5 ? u_cameraAngle : 0.0);\n float halfSpread = v_loopSpread * 0.5;\n\n float exitAngle = angle - halfSpread;\n float entryAngle = angle + halfSpread;\n\n // Control point distance: at t=0.5 the Bézier reaches 0.75 * cpDist * cos(halfSpread)\n // from source. Solve for cpDist so the loop tip reaches exactly R.\n float cpDist = R / (0.75 * cos(halfSpread));\n\n vec2 cp1 = source + cpDist * vec2(cos(exitAngle), sin(exitAngle));\n vec2 cp2 = source + cpDist * vec2(cos(entryAngle), sin(entryAngle));\n\n float u = 1.0 - t;\n vec2 d1 = cp1 - source;\n vec2 d2 = cp2 - source;\n return source + 3.0 * t * u * (u * d1 + t * d2);\n}\n\n// Approximate arc length via chord sampling\nfloat path_loop_length(vec2 source, vec2 target) {\n float len = 0.0;\n vec2 prev = path_loop_position(0.0, source, target);\n const int STEPS = 16;\n for (int i = 1; i <= STEPS; i++) {\n float t = float(i) / float(STEPS);\n vec2 cur = path_loop_position(t, source, target);\n len += length(cur - prev);\n prev = cur;\n }\n return len;\n}\n`;return{name:"loop",segments:t,glsl:r,needsNodeSize:!0,uniforms:[],attributes:[{name:"loopRadius",size:1,type:WebGL2RenderingContext.FLOAT},{name:"loopAngle",size:1,type:WebGL2RenderingContext.FLOAT},{name:"loopSpread",size:1,type:WebGL2RenderingContext.FLOAT},{name:"loopFixedOrientation",size:1,type:WebGL2RenderingContext.FLOAT}],variables:{loopRadius:{type:"number",default:4},loopAngle:{type:"number",default:Math.PI/4},loopSpread:{type:"number",default:80*Math.PI/180},loopFixedOrientation:{type:"number",default:0}},spread:{variable:"loopRadius",compute:function(o){return o+4}}}}function Fr(e){return se(e)==="object"&&"glsl"in e&&!("attributes"in e)}function Ir(e){return se(e)==="object"&&"glsl"in e&&!("attributes"in e)}var Wt={shapes:[Bt()],variables:{},layers:[ua()],label:{},backdrop:{},labelAttachments:{}},Tt={paths:[ha(),fa()],extremities:[],variables:{},layers:[Ke()],defaultHead:"none",defaultTail:"none",label:{}},gn=["nodes","topNodes"],vn=["edges","topEdges"],pn=[].concat(vn,gn),Mr={nodes:Wt,edges:Tt,depthLayers:J(pn)};var _l=function(a){return a},Tl=function(a){return a*a},Sl=function(a){return a*(2-a)},El=function(a){if((a*=2)<1)return 0.5*a*a;return-0.5*(--a*(a-2)-1)},Rl=function(a){return a*a*a},Al=function(a){return--a*a*a+1},wl=function(a){if((a*=2)<1)return 0.5*a*a*a;return 0.5*((a-=2)*a*a+2)},Dl=function(a){return a===0?0:Math.pow(2,10*(a-1))},Ll=function(a){return a===1?1:1-Math.pow(2,-10*a)},Cl=function(a){if(a===0)return 0;if(a===1)return 1;if(a<0.5)return Math.pow(2,10*(2*a-1))/2;return(2-Math.pow(2,-10*(2*a-1)))/2},ga={linear:_l,quadraticIn:Tl,quadraticOut:Sl,quadraticInOut:El,cubicIn:Rl,cubicOut:Al,cubicInOut:wl,exponentialIn:Dl,exponentialOut:Ll,exponentialInOut:Cl};function mn(e){if(!e)return ga.linear;if(typeof e==="function")return e;return ga[e]}function pa(e){return se(e)==="object"&&e!==null&&"attribute"in e}function Gr(e){return typeof e==="function"}function Or(e){return se(e)==="object"&&e!==null&&"when"in e&&typeof e.when==="function"&&"then"in e}function Br(e){return se(e)==="object"&&e!==null&&"whenState"in e&&"then"in e}function Wr(e){return se(e)==="object"&&e!==null&&"whenData"in e&&"then"in e}var kl={isHovered:!1,isLabelHovered:!1,isHidden:!1,isHighlighted:!1,isDragged:!1},Pl={isHovered:!1,isLabelHovered:!1,isHidden:!1,isHighlighted:!1,parallelIndex:0,parallelCount:1},Fl={isIdle:!0,isPanning:!1,isZooming:!1,isDragging:!1,hasHovered:!1,hasHighlighted:!1};function Ur(e){return V(V({},kl),e)}function Hr(e){return V(V({},Pl),e)}function ma(e){return V(V({},Fl),e)}var Il={x:{attribute:"x"},y:{attribute:"y"},size:{whenState:"isHovered",then:{attribute:"size",defaultValue:12},else:{attribute:"size",defaultValue:10}},color:{attribute:"color",defaultValue:"#666"},label:{attribute:"label"},visibility:{whenState:"isHidden",then:"hidden",else:"visible"},labelVisibility:{whenState:"isHovered",then:"visible",else:"auto"},backdropVisibility:{whenState:"isHovered",then:"visible",else:"hidden"},backdropColor:"#ffffff",backdropShadowColor:"rgba(0, 0, 0, 0.5)",backdropShadowBlur:12,backdropPadding:6},Ml={size:{attribute:"size",defaultValue:1},color:{attribute:"color",defaultValue:"#ccc"},label:{attribute:"label"},visibility:{whenState:"isHidden",then:"hidden",else:"visible"}};var yn={nodes:V(V({},Il),{},{depth:{whenState:"isHovered",then:"topNodes",else:"nodes"}}),edges:V(V({},Ml),{},{depth:{whenState:["isHighlighted","isHovered"],then:"topEdges",else:"edges"}})};function zl(e){return"min"in e||"max"in e||"minValue"in e||"maxValue"in e||"easing"in e}function Nl(e){return"dict"in e}function xn(e,a){if(typeof e==="string")return a[e]===!0;if(Array.isArray(e))return e.every(function(n){return a[n]===!0});if(se(e)==="object"&&e!==null)return Object.entries(e).every(function(n){var t=le(n,2),r=t[0],i=t[1];return a[r]===i});return!1}function Gl(e,a){var n=a[e.attribute];if(n===void 0)return e.defaultValue;return n}function Ol(e,a,n){var t,r,i,o,s=a[e.attribute];if(s===void 0)return e.defaultValue;var l=Number(s);if(isNaN(l))return e.defaultValue;if(e.min===void 0&&e.max===void 0)return l;var d=(t=e.minValue)!==null&&t!==void 0?t:l,u=(r=e.maxValue)!==null&&r!==void 0?r:l;if(u===d){var c;return(c=e.min)!==null&&c!==void 0?c:l}var g=(l-d)/(u-d);g=Math.max(0,Math.min(1,g));var h=mn(e.easing);g=h(g);var p=(i=e.min)!==null&&i!==void 0?i:0,y=(o=e.max)!==null&&o!==void 0?o:1;return p+g*(y-p)}function Bl(e,a){var n=a[e.attribute];if(n===void 0)return e.defaultValue;var t=String(n);if(t in e.dict)return e.dict[t];return e.defaultValue}function Wl(e,a,n){if(Nl(e))return Bl(e,a);if(zl(e))return Ol(e,a);return Gl(e,a)}function $r(e,a){if(typeof e==="string")return!!a[e];if(Array.isArray(e))return e.every(function(n){return!!a[n]});if(se(e)==="object"&&e!==null)return Object.entries(e).every(function(n){var t=le(n,2),r=t[0],i=t[1];return a[r]===i});return!1}function bn(e,a,n,t,r,i){if(e===null||e===void 0)return i;if(se(e)!=="object"&&typeof e!=="function")return e;if(Or(e)){var o=e.when(a,n,t,r)?e.then:e.else;if(o===void 0)return i;return bn(o,a,n,t,r,i)}if(Br(e)){var s=xn(e.whenState,n)?e.then:e.else;if(s===void 0)return i;return bn(s,a,n,t,r,i)}if(Wr(e)){var l=$r(e.whenData,a)?e.then:e.else;if(l===void 0)return i;return bn(l,a,n,t,r,i)}if(Gr(e)){var d=e(a,n,t,r);return d!==null&&d!==void 0?d:i}if(pa(e)){var u=Wl(e,a);return u!==null&&u!==void 0?u:i}return e}function Oe(e){if(e===null||e===void 0)return"static";if(Or(e))return"graph-state";if(Br(e)){var a=Oe(e.then),n=e.else!==void 0?Oe(e.else):"static";return Ie("item-state",Ie(a,n))}if(Wr(e)){var t=Oe(e.then),r=e.else!==void 0?Oe(e.else):"static";return Ie(t,r)}if(Gr(e))return"graph-state";if(pa(e))return"static";return"static"}function Ie(e,a){if(e==="graph-state"||a==="graph-state")return"graph-state";if(e==="item-state"||a==="item-state")return"item-state";return"static"}function ba(e){if(!e)return{dependency:"static",xAttribute:null,yAttribute:null};var a=Array.isArray(e)?e:[e],n="static",t=null,r=null,i=W(a),o;try{for(i.s();!(o=i.n()).done;){var s=o.value;if("matchData"in s&&"cases"in s){var l=s.cases;for(var d=0,u=Object.values(l);d<u.length;d++){var c=u[d];for(var g=0,h=Object.values(c);g<h.length;g++){var p=h[g];n=Ie(n,Oe(p))}}}else if("matchState"in s&&"cases"in s){n=Ie(n,"item-state");var y=s.cases;for(var v=0,f=Object.values(y);v<f.length;v++){var b=f[v];for(var m=0,T=Object.values(b);m<T.length;m++){var _=T[m];n=Ie(n,Oe(_))}}}else if("when"in s&&"then"in s)n="graph-state";else if("whenState"in s){n=Ie(n,"item-state");var x=s.then;if(x&&se(x)==="object")for(var S=0,E=Object.values(x);S<E.length;S++){var D=E[S];n=Ie(n,Oe(D))}var A=s.else;if(A&&se(A)==="object")for(var L=0,w=Object.values(A);L<w.length;L++){var M=w[L];n=Ie(n,Oe(M))}}else if("whenData"in s){var C=s.then;if(C&&se(C)==="object")for(var z=0,O=Object.values(C);z<O.length;z++){var N=O[z];n=Ie(n,Oe(N))}var F=s.else;if(F&&se(F)==="object")for(var P=0,B=Object.values(F);P<B.length;P++){var Y=B[P];n=Ie(n,Oe(Y))}}else for(var q=0,re=Object.entries(s);q<re.length;q++){var Z=le(re[q],2),ee=Z[0],Ee=Z[1];if(xa.has(ee))continue;if(n=Ie(n,Oe(Ee)),(ee==="x"||ee==="y")&&pa(Ee)){var de=Ee.attribute;if(ee==="x"&&!t)t=de;if(ee==="y"&&!r)r=de}}}}catch(U){i.e(U)}finally{i.f()}return{dependency:n,xAttribute:t,yAttribute:r}}var Ve={size:10,color:"#666",opacity:1,shape:"circle",rotationAlignment:"viewport",labelRotationAlignment:"viewport",visibility:"visible",depth:"nodes",zIndex:0,label:"",labelColor:"#000",labelSize:12,labelFont:"sans-serif",labelVisibility:"auto",labelPosition:"right",labelAngle:0,labelDepth:"nodes",backdropVisibility:"hidden",backdropColor:"transparent",backdropShadowColor:"transparent",backdropShadowBlur:0,backdropPadding:0,backdropBorderColor:"transparent",backdropBorderWidth:0,backdropCornerRadius:0,backdropLabelPadding:-1,backdropArea:"both",labelAttachment:null,labelAttachmentPlacement:"below"},ya={size:1,color:"#ccc",opacity:1,path:"straight",selfLoopPath:"loop",parallelSpread:0.25,tail:"none",head:"none",visibility:"visible",depth:"edges",zIndex:0,label:"",labelColor:"#666",labelVisibility:"auto",labelDepth:"edges"},xa=new Set(["when","whenState","whenData","then","else"]),zr=Object.keys(Ve),Ul=Object.values(Ve),Nr=Object.keys(ya),Hl=Object.values(ya);function St(e,a,n,t,r,i,o){for(var s in a){var l;if(xa.has(s))continue;var d=(l=e[s])!==null&&l!==void 0?l:o[s];e[s]=bn(a[s],n,t,r,i,d)}if("depth"in a&&!("labelDepth"in a))e.labelDepth=e.depth}function Vr(e,a,n,t,r,i,o){var s=W(a),l;try{for(s.s();!(l=s.n()).done;){var d=l.value;if("matchData"in d&&"cases"in d){var u,c=String((u=n[d.matchData])!==null&&u!==void 0?u:""),g=d.cases;if(c in g)St(e,g[c],n,t,r,i,o)}else if("matchState"in d&&"cases"in d){var h,p=String((h=t[d.matchState])!==null&&h!==void 0?h:""),y=d.cases;if(p in y)St(e,y[p],n,t,r,i,o)}else if("when"in d&&"then"in d){var v=d.when;if(!v(n,t,r,i))continue;St(e,d.then,n,t,r,i,o)}else if("whenState"in d&&"then"in d){if(!xn(d.whenState,t))continue;St(e,d.then,n,t,r,i,o)}else if("whenData"in d&&"then"in d){if(!$r(d.whenData,n))continue;St(e,d.then,n,t,r,i,o)}else St(e,d,n,t,r,i,o)}}catch(f){s.e(f)}finally{s.f()}}function _a(e,a,n,t,r,i){var o=i||{},s=o;for(var l=0,d=zr.length;l<d;l++)s[zr[l]]=Ul[l];if(s.x=void 0,s.y=void 0,s.labelBackgroundColor=void 0,s.labelBackgroundPadding=void 0,s.labelCursor=void 0,!e){var u,c,g,h,p;return s.x=(u=a.x)!==null&&u!==void 0?u:0,s.y=(c=a.y)!==null&&c!==void 0?c:0,o.size=(g=a.size)!==null&&g!==void 0?g:10,o.color=(h=a.color)!==null&&h!==void 0?h:"#666",o.label=(p=a.label)!==null&&p!==void 0?p:"",o}var y=Array.isArray(e)?e:[e];return Vr(s,y,a,n,t,r,Ve),o}function Ta(e,a,n,t,r,i){var o=i||{},s=o;for(var l=0,d=Nr.length;l<d;l++)s[Nr[l]]=Hl[l];if(!e){var u,c,g;return o.size=(u=a.size)!==null&&u!==void 0?u:1,o.color=(c=a.color)!==null&&c!==void 0?c:"#ccc",o.label=(g=a.label)!==null&&g!==void 0?g:"",o}var h=Array.isArray(e)?e:[e];if(Vr(s,h,a,n,t,r,ya),typeof s.labelPosition==="number")s.labelPosition=void 0;return o}function $l(e,a,n){var t,r;if(e===void 0||e===null)return n;if(typeof e==="function")return(t=e(a))!==null&&t!==void 0?t:n;if(se(e)==="object"&&"when"in e){var i,o=e,s=o.when(a),l=s?o.then:o.else;if(l===void 0)return n;if(typeof l==="function")return(i=l(a))!==null&&i!==void 0?i:n;return l!==null&&l!==void 0?l:n}if(se(e)==="object"&&"whenState"in e){var d,u=e,c=xn(u.whenState,a),g=c?u.then:u.else;if(g===void 0)return n;if(typeof g==="function")return(d=g(a))!==null&&d!==void 0?d:n;return g!==null&&g!==void 0?g:n}return(r=e)!==null&&r!==void 0?r:n}function Sa(e,a){var n={};if(!e)return n;var t=Array.isArray(e)?e:[e],r=W(t),i;try{for(r.s();!(i=r.n()).done;){var o=i.value;if("when"in o&&"then"in o){var s=o.when(a),l=s?o.then:o.else;if(l&&se(l)==="object")va(n,l,a)}else if("whenState"in o&&"then"in o){var d=xn(o.whenState,a),u=d?o.then:o.else;if(u&&se(u)==="object")va(n,u,a)}else va(n,o,a)}}catch(c){r.e(c)}finally{r.f()}return n}function va(e,a,n){for(var t=0,r=Object.entries(a);t<r.length;t++){var i=le(r[t],2),o=i[0],s=i[1];if(xa.has(o))continue;e[o]=$l(s,n)}}var _n=function(e){function a(){var n;return ie(this,a),n=fe(this,a),n.rawEmitter=n,n}return ge(a,e),oe(a)}(De);var Xr=Mr;function Ea(e,a){var n=a.size;if(n===0)return;var t=e.length;e.length+=n;var r=0;a.forEach(function(i){e[t+r]=i,r++})}function jr(e){e=e||{};for(var a=0,n=arguments.length<=1?0:arguments.length-1;a<n;a++){var t=a+1<1||arguments.length<=a+1?void 0:arguments[a+1];if(!t)continue;Object.assign(e,t)}return e}function Et(e,a){for(var n in a){if(!Object.prototype.hasOwnProperty.call(a,n))continue;if(a[n]!==e[n])return!0}return!1}function qr(e,a){var n=e,t=a;for(var r in n){if(!Object.prototype.hasOwnProperty.call(n,r))continue;if(n[r]!==t[r])return!1}for(var i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;if(t[i]!==n[i])return!1}return!0}function rt(e,a,n){if(n)e.add(a);else e.delete(a)}var Kr=er(Ra());var Zr={easing:"quadraticInOut",duration:150};function Ze(e){return e.labelVisibility==="visible"&&e.visibility!=="hidden"}function Aa(e){return e.backdropVisibility==="visible"&&e.visibility!=="hidden"}function Tn(e){return[e.rotationAlignment==="graph"?1:0,e.labelRotationAlignment==="graph"?1:0]}function wa(e,a,n){var t=e[a];if(!t)return;for(var r=0;r<t.length;r++){var i=t[r];if(n<i.offset||n>=i.offset+i.count)continue;if(i.count===1)t.splice(r,1);else if(n===i.offset)i.offset++,i.count--;else if(n===i.offset+i.count-1)i.count--;else{var o=n+1,s=i.offset+i.count-o;i.count=n-i.offset,t.splice(r+1,0,{offset:o,count:s})}return}}function Da(e,a,n){if(!e[a]){e[a]=[{offset:n,count:1}];return}var t=e[a],r=t.length;for(var i=0;i<t.length;i++)if(n<t[i].offset){r=i;break}var o=r>0?t[r-1]:null,s=r<t.length?t[r]:null,l=o&&o.offset+o.count===n,d=s&&n+1===s.offset;if(l&&d)o.count+=1+s.count,t.splice(r,1);else if(l)o.count++;else if(d)s.offset--,s.count++;else t.splice(r,0,{offset:n,count:1})}function Qr(e){if(!Kr.default(e))throw Error("Sigma: invalid graph instance.")}function Sn(e){var a=le(e.x,2),n=a[0],t=a[1],r=le(e.y,2),i=r[0],o=r[1],s=Math.max(t-n,o-i),l=(t+n)/2,d=(o+i)/2;if(s===0||Math.abs(s)===1/0||isNaN(s))s=1;if(isNaN(l))l=0;if(isNaN(d))d=0;var u=function(g){return{x:0.5+(g.x-l)/s,y:0.5+(g.y-d)/s}};return u.applyTo=function(c){c.x=0.5+(c.x-l)/s,c.y=0.5+(c.y-d)/s},u.inverse=function(c){return{x:l+s*(c.x-0.5),y:d+s*(c.y-0.5)}},u.ratio=s,u}var En={hideEdgesOnMove:!1,hideLabelsOnMove:!1,renderLabels:!0,renderEdgeLabels:!1,edgeLabelAnchors:"nodeLabels",enableEdgeEvents:!1,nodeLabelEvents:!1,edgeLabelEvents:!1,pickingDownSizingRatio:2,nodePickingPadding:0,edgePickingPadding:4,labelPickingPadding:10,stagePadding:30,minEdgeThickness:1.7,antiAliasingFeather:1,antialiasEdges:!0,antialiasNodes:!0,dragTimeout:100,draggedEventsTolerance:3,inertiaDuration:200,inertiaRatio:3,zoomDuration:250,zoomingRatio:1.7,doubleClickTimeout:300,doubleClickZoomingRatio:2.2,doubleClickZoomingDuration:200,tapMoveTolerance:10,zoomToSizeRatioFunction:Math.sqrt,itemSizesReference:"positions",autoRescale:!0,autoRescaleContent:"positions",enableNodeDrag:!1,getDraggedNodes:function(a){return[a]},dragPositionToAttributes:null,labelDensity:1,labelGridCellSize:100,labelRenderedSizeThreshold:6,labelPixelSnapping:!0,minCameraRatio:null,maxCameraRatio:null,enableCameraZooming:!0,enableCameraPanning:!0,enableCameraRotation:!0,enableCameraMouseRotation:!0,cameraPanBoundaries:null,gestureTarget:"graph",sharedGestureWheelMessage:"Use Ctrl + scroll to zoom the graph",sharedGestureAppleWheelMessage:"Use ⌘ + scroll to zoom the graph",sharedGestureTouchMessage:"Use two fingers to move the graph",allowInvalidContainer:!1,DEBUG_displayPickingLayer:!1,DEBUG_logShaders:!1,DEBUG_logRenderStats:!1,DEBUG_gpuTimerQueries:!1};function Rn(e){if(typeof e.labelDensity!=="number"||e.labelDensity<0)throw Error("Settings: invalid `labelDensity`. Expecting a positive number.");var{minCameraRatio:a,maxCameraRatio:n}=e;if(typeof a==="number"&&typeof n==="number"&&n<a)throw Error("Settings: invalid camera ratio boundaries. Expecting `maxCameraRatio` to be greater than `minCameraRatio`.")}function Jr(e){return jr({},En,e)}var Vl=new Set(["italic","oblique"]),Xl=new Set(["bold","bolder","lighter"]);function An(e){var a="normal",n="normal",t=e.trim(),r=t.split(/\\s+/),i=0;for(var o=0;o<r.length;o++){var s=r[o].toLowerCase();if(Vl.has(s))n=s,i=o+1;else if(Xl.has(s)||/^\\d{3}$/.test(s))a=s,i=o+1;else if(s==="normal")i=o+1;else break}var l=r.slice(i).join(" ");return{family:l||t,weight:a,style:n}}function Rt(e,a,n){var t=document.createElement(e);if(a)for(var r in a)t.style[r]=a[r];if(n)for(var i in n)t.setAttribute(i,n[i]);return t}function Ut(){if(typeof window.devicePixelRatio<"u")return window.devicePixelRatio;return 1}function jl(e){var a=e.type===WebGL2RenderingContext.FLOAT&&!e.normalized,n=e.type===WebGL2RenderingContext.UNSIGNED_BYTE&&e.size===4&&e.normalized;if(!a&&!n)throw Error(\'Attribute "\'.concat(e.name,\'" is invalid: only non-normalized FLOAT and normalized UNSIGNED_BYTE with size 4 are supported.\'));return e.normalized?1:e.size}function La(e){var a=0;return e.forEach(function(n){return a+=jl(n)}),a}function di(e,a,n){var t=e==="VERTEX"?a.VERTEX_SHADER:a.FRAGMENT_SHADER,r=a.createShader(t);if(r===null)throw Error("loadShader: error while creating the shader");a.shaderSource(r,n),a.compileShader(r);var i=a.getShaderParameter(r,a.COMPILE_STATUS);if(!i){var o=a.getShaderInfoLog(r);throw a.deleteShader(r),Error(`loadShader: error while compiling the shader:\n`.concat(o,`\n`).concat(n))}return r}function ka(e,a){return di("VERTEX",e,a)}function Pa(e,a){return di("FRAGMENT",e,a)}function Fa(e,a){var n=e.createProgram();if(n===null)throw Error("loadProgram: error while creating the program.");var t,r;for(t=0,r=a.length;t<r;t++)e.attachShader(n,a[t]);e.linkProgram(n);var i=e.getProgramParameter(n,e.LINK_STATUS);if(!i){var o=e.getProgramInfoLog(n);throw e.deleteProgram(n),Error("loadProgram: error while linking the program: ".concat(o))}return n}function ei(e){var{gl:a,buffer:n,program:t,vertexShader:r,fragmentShader:i}=e;a.deleteShader(r),a.deleteShader(i),a.deleteProgram(t),a.deleteBuffer(n)}function ve(e){return e%1===0?e.toFixed(1):e.toString()}var Pn=new Map,ui=new Map,ql=0;function ci(e,a){var n,t=(n=e.variables)===null||n===void 0||(n=n[a.source||a.name.replace(/^a_/,"")])===null||n===void 0?void 0:n.default,r=typeof t==="number"?t:typeof a.defaultValue==="number"?a.defaultValue:0;return ve(r)}function Fn(e,a,n){var t,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:function(o){return"v_".concat(o.name.replace(/^a_/,""))},i=[a,n].concat(J(e.uniforms.filter(function(o){return o.type==="float"}).map(function(o){var s;return ve((s=o.value)!==null&&s!==void 0?s:0)})),J(((t=e.attributes)!==null&&t!==void 0?t:[]).map(r)));return"sdf_".concat(e.name,"(").concat(i.join(", "),")")}function Yl(e){var a,n=e.name,t=e.uniforms.filter(function(o){return o.type==="float"&&o.value!==void 0&&o.value!==0}).map(function(o){return"".concat(o.name.replace("u_",""),"=").concat(o.value)}).sort(),r=((a=e.attributes)!==null&&a!==void 0?a:[]).map(function(o){var s;return"".concat(o.name,"@").concat((s=o.source)!==null&&s!==void 0?s:"","=").concat(ci(e,o))}),i=[].concat(J(t),J(r));if(i.length>0)n+="#"+i.join("#");return n}function Kl(e){var a=Yl(e);if(!Pn.has(a)){var n={},t=W(e.uniforms),r;try{for(t.s();!(r=t.n()).done;){var i=r.value;if(i.type==="float"&&i.value!==void 0)n[i.name]=i.value}}catch(o){t.e(o)}finally{t.f()}Pn.set(a,{shape:e,uniformValues:n,slug:a}),ui.set(a,ql++)}return a}function jt(e){var a;return(a=ui.get(e))!==null&&a!==void 0?a:-1}function hi(e){var a=[],n=new Set,t=new Set,r=/mat2 rotate2D\\(float angle\\)\\s*\\{[^}]+\\}/,i=W(e),o;try{for(i.s();!(o=i.n()).done;){var s=o.value;if(t.has(s.name))continue;t.add(s.name);var l=s.glsl;if(r.test(l))if(n.has("rotate2D"))l=l.replace(r,"");else n.add("rotate2D");a.push(l)}}catch(d){i.e(d)}finally{i.f()}return a.join(`\n`)}function Zl(){return hi(Array.from(Pn.values()).map(function(e){return e.shape}))}function Ql(e){var a=Array.from(Pn.entries());if(a.length===0)return`\nfloat querySDF(int shapeId, vec2 uv, float size) {\n return length(uv) - size;\n}\n`;var n=a.map(function(t,r){var i=le(t,2),o=i[0],s=i[1].shape,l=Fn(s,"uv","size",function(d){var u=d.name.replace(/^a_/,"");return e!==null&&e!==void 0&&e.has(u)?"g_".concat(u):ci(s,d)});return" case ".concat(r,": return ").concat(l,"; // ").concat(o)}).join(`\n`);return`\nfloat querySDF(int shapeId, vec2 uv, float size) {\n switch (shapeId) {\n`.concat(n,`\n default: return length(uv) - size;\n }\n}\n`)}function Ia(e){return hi(e)}function qt(e){return J(new Map(e.flatMap(function(a){return a.uniforms}).map(function(a){return[a.name,a]})).values())}function Jl(e,a){if(e.length===0)return`\nvoid queryNodeSDF(int shapeId, vec2 uv, float size) {\n context.sdf = length(uv) - size;\n context.inradiusFactor = 1.0;\n}\n`;var n=function(c){return Fn(c,"uv","size")},t=function(c){var g,h;return(g=c.inradiusFactorGLSL)!==null&&g!==void 0?g:ve((h=c.inradiusFactor)!==null&&h!==void 0?h:1)};if(e.length===1){var r=e[0];return`\nvoid queryNodeSDF(int shapeId, vec2 uv, float size) {\n context.sdf = `.concat(n(r),`;\n context.inradiusFactor = `).concat(t(r),`;\n}\n`)}var i=e.map(function(u,c){return" case ".concat(c,": // ").concat(u.name,`\n context.sdf = `).concat(n(u),`;\n context.inradiusFactor = `).concat(t(u),`;\n break;`)}).join(`\n`),o=e[0],s="",l="shapeId";if(a&&a.length>1){var d=a.map(function(u,c){return" case ".concat(u,": return ").concat(c,"; // ").concat(e[c].name)}).join(`\n`);s=`\nint globalToLocalShapeId(int globalId) {\n switch (globalId) {\n`.concat(d,`\n default: return 0;\n }\n}\n`),l="globalToLocalShapeId(shapeId)"}return"".concat(s,`\nvoid queryNodeSDF(int shapeId, vec2 uv, float size) {\n switch (`).concat(l,`) {\n`).concat(i,`\n default:\n context.sdf = `).concat(n(o),`;\n context.inradiusFactor = `).concat(t(o),`;\n }\n}\n`)}var wt={right:0,left:1,above:2,below:3,over:4},Dt=5,Ma=3,fi=`\nfloat matrixScaleX = length(vec2(u_matrix[0][0], u_matrix[1][0]));\nfloat nodeRadiusGraphSpace = nodeSize * u_correctionRatio / u_sizeRatio * 2.0;\nfloat nodeRadiusNDC = nodeRadiusGraphSpace * matrixScaleX;\nfloat nodeRadiusPixels = nodeRadiusNDC * u_resolution.x / 2.0;\n`,In=`\nmat2 rotate2D(float angle) {\n float c = cos(angle);\n float s = sin(angle);\n return mat2(c, -s, s, c);\n}\n`,gi=`\nvec2 getLabelDirection(float positionMode) {\n if (positionMode < 0.5) return vec2(1.0, 0.0); // Right\n if (positionMode < 1.5) return vec2(-1.0, 0.0); // Left\n if (positionMode < 2.5) return vec2(0.0, -1.0); // Above\n if (positionMode < 3.5) return vec2(0.0, 1.0); // Below\n return vec2(0.0); // Over (centered)\n}\n`,ed=`\nfloat sdfBox(vec2 p, vec2 halfSize) {\n vec2 d = abs(p) - halfSize;\n return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0);\n}\n`,td=`\nfloat sdfRotatedBox(vec2 p, vec2 halfSize, float angle) {\n float c = cos(-angle);\n float s = sin(-angle);\n vec2 rotatedP = mat2(c, -s, s, c) * p;\n return sdfBox(rotatedP, halfSize);\n}\n`,nd=`\nfloat sdfRoundedBox(vec2 p, vec2 halfSize, float radius) {\n vec2 d = abs(p) - halfSize + radius;\n return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - radius;\n}\n`,ad=`\nfloat sdfRoundedRotatedBox(vec2 p, vec2 halfSize, float angle, float radius) {\n float c = cos(-angle);\n float s = sin(-angle);\n vec2 rotatedP = mat2(c, -s, s, c) * p;\n return sdfRoundedBox(rotatedP, halfSize, radius);\n}\n`,vi=`\nvec2 labelBoxCenter(float positionMode, float labelStart, vec2 halfSize, float textHalfY) {\n if (positionMode < 0.5) return vec2(labelStart + halfSize.x, 0.0); // right\n if (positionMode < 1.5) return vec2(-(labelStart + halfSize.x), 0.0); // left\n if (positionMode < 2.5) return vec2(0.0, -(labelStart + textHalfY)); // above\n if (positionMode < 3.5) return vec2(0.0, labelStart + textHalfY); // below\n return vec2(0.0); // over\n}\n`,za=2,Xe=`\nvec4 readNodeData(sampler2D nodeDataTexture, int nodeDataTextureWidth, int nodeIndex) {\n int t = nodeIndex * `.concat(za,`;\n ivec2 coord = ivec2(t % nodeDataTextureWidth, t / nodeDataTextureWidth);\n return texelFetch(nodeDataTexture, coord, 0);\n}\n`),ot=`\nvec4 readNodeFlags(sampler2D nodeDataTexture, int nodeDataTextureWidth, int nodeIndex) {\n int t = nodeIndex * `.concat(za,` + 1;\n ivec2 coord = ivec2(t % nodeDataTextureWidth, t / nodeDataTextureWidth);\n return texelFetch(nodeDataTexture, coord, 0);\n}\n`),rd=`\nvec4 readNodeColor(sampler2D nodeDataTexture, int nodeDataTextureWidth, int nodeIndex) {\n int t = nodeIndex * `.concat(za,` + 1;\n ivec2 coord = ivec2(t % nodeDataTextureWidth, t / nodeDataTextureWidth);\n vec4 texel = texelFetch(nodeDataTexture, coord, 0);\n float r = floor(texel.b / 65536.0);\n float g = floor(mod(texel.b, 65536.0) / 256.0);\n float b = mod(texel.b, 256.0);\n return vec4(r / 255.0, g / 255.0, b / 255.0, texel.a);\n}\n`),Lt=`\nvec4 readFrameTexel(sampler2D frameTexture, int frameTextureWidth, int index) {\n ivec2 coord = ivec2(index % frameTextureWidth, index / frameTextureWidth);\n return texelFetch(frameTexture, coord, 0);\n}\n`;function id(e,a){var n=function(o){return Fn(o,"uv","size")};if(e.length===1)return{code:ti(n(e[0])),multiShape:!1};var t=e.map(function(i,o){return" case ".concat(a?a[o]:o,": return ").concat(n(i),";")}).join(`\n`),r=`\nfloat queryShapeSDF(int shapeId, vec2 uv, float size) {\n switch (shapeId) {\n`.concat(t,`\n default: return `).concat(n(e[0]),`;\n }\n}\nint g_shapeId;\n`).concat(ti("queryShapeSDF(g_shapeId, uv, size)"),`\n`);return{code:r,multiShape:!0}}function ti(e){return`\nfloat findEdgeDistance(vec2 direction, float size) {\n float lo = 0.0, hi = 2.0;\n for (int i = 0; i < 8; i++) {\n float mid = (lo + hi) * 0.5;\n vec2 uv = direction * mid;\n if (`.concat(e,` < 0.0) lo = mid; else hi = mid;\n }\n return (lo + hi) * 0.5;\n}\n`)}function od(e,a){for(;!{}.hasOwnProperty.call(e,a)&&(e=at(e))!==null;);return e}function Ca(){return Ca=typeof Reflect<"u"&&Reflect.get?Reflect.get.bind():function(e,a,n){var t=od(e,a);if(t){var r=Object.getOwnPropertyDescriptor(t,a);return r.get?r.get.call(arguments.length<3?e:n):r.value}},Ca.apply(null,arguments)}function xe(e,a,n,t){var r=Ca(at(1&t?e.prototype:e),a,n);return 2&t&&typeof r=="function"?function(i){return r.apply(n,i)}:r}var sd=1024,ld=1.5,pi=-1,Mn=function(){function e(a,n){var t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:sd;ie(this,e),R(this,"texture",null),R(this,"dirty",!1),R(this,"dirtyRangeStart",1/0),R(this,"dirtyRangeEnd",-1),R(this,"indexMap",new Map),R(this,"freeIndices",[]),R(this,"nextIndex",0),this.gl=a,this.maxTextureSize=a.getParameter(a.MAX_TEXTURE_SIZE),this.TEXELS_PER_ITEM=n,this.capacity=this.roundUpToPowerOfTwo(t);var r=this.computeTextureDimensions(this.capacity);this.textureWidth=r.width,this.textureHeight=r.height,this.data=new Float32Array(this.textureWidth*this.textureHeight*4),this.createTexture()}return oe(e,[{key:"computeTextureDimensions",value:function(n){var t=n*this.TEXELS_PER_ITEM,r=Math.min(t,this.maxTextureSize),i=Math.ceil(t/r);return{width:r,height:i}}},{key:"roundUpToPowerOfTwo",value:function(n){return Math.pow(2,Math.ceil(Math.log2(Math.max(1,n))))}},{key:"createTexture",value:function(){var n=this.gl;this.texture=n.createTexture(),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,this.texture),n.texImage2D(n.TEXTURE_2D,0,n.RGBA32F,this.textureWidth,this.textureHeight,0,n.RGBA,n.FLOAT,this.data),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null)}},{key:"resize",value:function(n){if(n<=this.capacity)return;var t=this.roundUpToPowerOfTwo(Math.ceil(n*ld)),r=this.gl,i=this.computeTextureDimensions(t),o=new Float32Array(i.width*i.height*4);if(o.set(this.data),this.texture)r.deleteTexture(this.texture);this.data=o,this.capacity=t,this.textureWidth=i.width,this.textureHeight=i.height,this.createTexture(),this.dirty=!0,this.dirtyRangeStart=0,this.dirtyRangeEnd=this.nextIndex}},{key:"allocate",value:function(n){var t=this.indexMap.get(n);if(t!==void 0)return t;var r;if(this.freeIndices.length>0)r=this.freeIndices.pop();else if(r=this.nextIndex++,r>=this.capacity)this.resize(r+1);return this.indexMap.set(n,r),r}},{key:"free",value:function(n){var t=this.indexMap.get(n);if(t===void 0)return;this.indexMap.delete(n),this.freeIndices.push(t);var r=t*this.TEXELS_PER_ITEM*4;for(var i=0;i<this.TEXELS_PER_ITEM*4;i++)this.data[r+i]=0;this.markDirty(t)}},{key:"getIndex",value:function(n){var t;return(t=this.indexMap.get(n))!==null&&t!==void 0?t:-1}},{key:"has",value:function(n){return this.indexMap.has(n)}},{key:"markDirty",value:function(n){this.dirty=!0,this.dirtyRangeStart=Math.min(this.dirtyRangeStart,n),this.dirtyRangeEnd=Math.max(this.dirtyRangeEnd,n+1)}},{key:"upload",value:function(){if(!this.dirty||!this.texture)return;var n=this.gl,t=this.textureWidth;n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,this.texture);var r=this.dirtyRangeStart*this.TEXELS_PER_ITEM,i=Math.min(this.dirtyRangeEnd*this.TEXELS_PER_ITEM,this.capacity*this.TEXELS_PER_ITEM);if(r<i){var o=Math.floor(r/t),s=Math.floor((i-1)/t);for(var l=o;l<=s;l++){var d=l*t,u=Math.min(d+t,this.capacity*this.TEXELS_PER_ITEM),c=Math.max(r,d),g=Math.min(i,u);if(c<g){var h=c-d,p=g-c,y=this.data.subarray(c*4,g*4);n.texSubImage2D(n.TEXTURE_2D,0,h,l,p,1,n.RGBA,n.FLOAT,y)}}}n.bindTexture(n.TEXTURE_2D,null),this.dirty=!1,this.dirtyRangeStart=1/0,this.dirtyRangeEnd=-1}},{key:"bind",value:function(n){var t=this.gl;t.activeTexture(t.TEXTURE0+n),t.bindTexture(t.TEXTURE_2D,this.texture)}},{key:"getTexture",value:function(){return this.texture}},{key:"getCapacity",value:function(){return this.capacity}},{key:"getTextureWidth",value:function(){return this.textureWidth}},{key:"getTextureHeight",value:function(){return this.textureHeight}},{key:"getTexelsPerItem",value:function(){return this.TEXELS_PER_ITEM}},{key:"getCount",value:function(){return this.indexMap.size}},{key:"getHighWaterMark",value:function(){return this.nextIndex}},{key:"isDirty",value:function(){return this.dirty}},{key:"clear",value:function(){this.indexMap.clear(),this.freeIndices=[],this.nextIndex=0,this.data.fill(0),this.dirty=!0,this.dirtyRangeStart=0,this.dirtyRangeEnd=this.capacity}},{key:"restore",value:function(){this.createTexture(),this.dirty=!1,this.dirtyRangeStart=1/0,this.dirtyRangeEnd=-1}},{key:"kill",value:function(){if(this.texture)this.gl.deleteTexture(this.texture),this.texture=null;this.indexMap.clear(),this.freeIndices=[]}}])}();function Me(e){var a={},n={},t=0,r=W(e),i;try{for(r.s();!(i=r.n()).done;){var o=i.value,s=W(o.attributes),l;try{for(s.s();!(l=s.n()).done;){var d=l.value,u=d.name.replace(/^a_/,"");if(!(u in a))a[u]=t,n[u]=d,t+=d.size}}catch(c){s.e(c)}finally{s.f()}}}catch(c){r.e(c)}finally{r.f()}return{floatsPerItem:t,texelsPerItem:Math.max(1,Math.ceil(t/4)),offsets:a,specs:n}}var zn=function(e){function a(n,t,r){var i;return ie(this,a),i=fe(this,a,[n,t.texelsPerItem,r]),i.floatsPerItem=t.floatsPerItem,i}return ge(a,e),oe(a,[{key:"updateAllAttributes",value:function(t,r){var i=this.indexMap.get(t);if(i===void 0)i=this.allocate(t);var o=i*this.TEXELS_PER_ITEM*4,s=Math.min(r.length,this.floatsPerItem);for(var l=0;l<s;l++)this.data[o+l]=r[l];this.markDirty(i)}},{key:"updateAllAttributesAtRow",value:function(t,r){if(t>=this.capacity)this.resize(t+1);var i=t*this.TEXELS_PER_ITEM*4,o=Math.min(r.length,this.floatsPerItem);for(var s=0;s<o;s++)this.data[i+s]=r[s];this.markDirty(t)}}])}(Mn);function Nn(e,a,n){var t=[],r=new Set;for(var i=0;i<e.length;i++){var o=e[i],s=W(o.attributes),l;try{for(s.s();!(l=s.n()).done;){var d=l.value,u=d.name.replace(/^a_/,"");if(r.has(u))continue;r.add(u);var c=a.offsets[u];if(c===void 0)continue;var g=n===null||n===void 0?void 0:n.get(i);t.push({sourceKey:d.source||u,packedOffset:c,size:d.size,isColor:d.size===4&&!!d.normalized,defaultNum:typeof d.defaultValue==="number"?d.defaultValue:d.defaultValue===!0?1:0,defaultColor:typeof d.defaultValue==="string"?d.defaultValue:"",sourceIndex:i,hasLifecycleHook:!!(g!==null&&g!==void 0&&g.getAttributeData)})}}catch(h){s.e(h)}finally{s.f()}}return t}function Gn(e,a,n,t,r,i){n.fill(0);for(var o=0,s=e.length;o<s;o++){var l=e[o],d=l.packedOffset,u=void 0;if(l.hasLifecycleHook){var c=r.get(l.sourceIndex-i);if(u=c.getAttributeData(a,l.sourceKey),u===null)u=a[l.sourceKey]}else u=a[l.sourceKey];if(l.isColor){var g=typeof u==="string"?u:l.defaultColor||t,h=Ye(g),p=le(h,4),y=p[0],v=p[1],f=p[2],b=p[3];n[d]=y/255,n[d+1]=v/255,n[d+2]=f/255,n[d+3]=b/255}else if(l.size===1)n[d]=typeof u==="number"?u:typeof u==="boolean"?u?1:0:l.defaultNum;else{var m=Array.isArray(u)?u:null;if(m)for(var T=0;T<l.size;T++){var _;n[d+T]=(_=m[T])!==null&&_!==void 0?_:0}}}}var wn=["r","g","b","a"];function At(e,a){var{offsets:n,specs:t,texelsPerItem:r,floatsPerItem:i}=e,o=Object.keys(n);if(o.length===0||i===0)return{fetchCode:"",varyingAssignments:""};var{varPrefix:s,baseTexelExpr:l,textureWidthUniform:d,textureSamplerUniform:u,outputPrefix:c}=a,g=c===void 0?"v_":c,h=[];h.push(" int ".concat(s,"BaseTexel = ").concat(l,";")),h.push("");for(var p=0;p<r;p++)h.push(" ivec2 ".concat(s,"Coord").concat(p," = ivec2((").concat(s,"BaseTexel + ").concat(p,") % ").concat(d,", (").concat(s,"BaseTexel + ").concat(p,") / ").concat(d,");")),h.push(" vec4 ".concat(s,"Texel").concat(p," = texelFetch(").concat(u,", ").concat(s,"Coord").concat(p,", 0);"));h.push("");var y=[],v=function(){var T=b[f],_=t[T],x=n[T],S=Math.floor(x/4),E=x%4,D="".concat(s,"Texel").concat(S),A="".concat(s,"Texel").concat(S+1),L="".concat(s,"Fetched_").concat(T);if(_.size===1)h.push(" float ".concat(L," = ").concat(D,".").concat(wn[E],";"));else if(_.size===4&&E===0)h.push(" vec4 ".concat(L," = ").concat(D,";"));else{var w=E+_.size;if(w<=4){var M="vec".concat(_.size),C=wn.slice(E,w).join("");h.push(" ".concat(M," ").concat(L," = ").concat(D,".").concat(C,";"))}else{var z=_.size===4?"vec4":"vec".concat(_.size),O=wn.slice(E).map(function(P){return"".concat(D,".").concat(P)}),N=wn.slice(0,w-4).map(function(P){return"".concat(A,".").concat(P)}),F=[].concat(J(O),J(N)).join(", ");h.push(" ".concat(z," ").concat(L," = ").concat(z,"(").concat(F,");"))}}y.push(" ".concat(g).concat(T," = ").concat(L,";"))};for(var f=0,b=o;f<b.length;f++)v();return{fetchCode:h.join(`\n`),varyingAssignments:y.join(`\n`)}}function Na(e,a,n){if(!a||n.type==="sampler2D")return;switch(n.type){case"float":e.uniform1f(a,n.value);break;case"int":case"bool":e.uniform1i(a,n.value);break;case"vec2":e.uniform2fv(a,n.value);break;case"vec3":e.uniform3fv(a,n.value);break;case"vec4":e.uniform4fv(a,n.value);break;case"mat3":e.uniformMatrix3fv(a,!1,n.value);break;case"mat4":e.uniformMatrix4fv(a,!1,n.value);break}}var dd=R(R(R(R(R(R(R(R({},WebGL2RenderingContext.BOOL,1),WebGL2RenderingContext.BYTE,1),WebGL2RenderingContext.UNSIGNED_BYTE,1),WebGL2RenderingContext.SHORT,2),WebGL2RenderingContext.UNSIGNED_SHORT,2),WebGL2RenderingContext.INT,4),WebGL2RenderingContext.UNSIGNED_INT,4),WebGL2RenderingContext.FLOAT,4);function Dn(e){var a=e.match(/^(#version[^\\n]*\\n)/);if(a)return a[1]+`#define PICKING_MODE\n`+e.slice(a[1].length);return`#define PICKING_MODE\n`+e}var st=function(){function e(a,n,t){ie(this,e),R(this,"floats",new Float32Array),R(this,"ints",new Uint32Array),R(this,"constantArray",new Float32Array),R(this,"capacity",0),R(this,"verticesCount",0),R(this,"bufferGeneration",0),R(this,"uploadedGeneration",new Map),R(this,"constantBufferGeneration",0),R(this,"uploadedConstantGeneration",new Map),R(this,"renderOffset",0),R(this,"renderCount",-1),R(this,"debugStats",{drawCalls:0,verticesDrawn:0,bufferUploadBytes:0}),R(this,"shadersLogged",!1),R(this,"pickProgram",null);var r=this.getDefinition();if(this.VERTICES=r.VERTICES,this.VERTEX_SHADER_SOURCE=r.VERTEX_SHADER_SOURCE,this.FRAGMENT_SHADER_SOURCE=r.FRAGMENT_SHADER_SOURCE,this.UNIFORMS=r.UNIFORMS,this.ATTRIBUTES=r.ATTRIBUTES,this.METHOD=r.METHOD,this.CONSTANT_ATTRIBUTES="CONSTANT_ATTRIBUTES"in r?r.CONSTANT_ATTRIBUTES:[],this.CONSTANT_DATA="CONSTANT_DATA"in r?r.CONSTANT_DATA:[],this.isInstanced="CONSTANT_ATTRIBUTES"in r,this.ATTRIBUTES_ITEMS_COUNT=La(this.ATTRIBUTES),this.STRIDE=this.VERTICES*this.ATTRIBUTES_ITEMS_COUNT,this.renderer=t,this.normalProgram=this.getProgramInfo("normal",a,r.VERTEX_SHADER_SOURCE,r.FRAGMENT_SHADER_SOURCE,null),this.pickProgram=this.getProgramInfo("pick",a,Dn(r.VERTEX_SHADER_SOURCE),Dn(r.FRAGMENT_SHADER_SOURCE),null),this.isInstanced){var i=La(this.CONSTANT_ATTRIBUTES);if(this.CONSTANT_DATA.length!==this.VERTICES)throw Error("Program: error while getting constant data (expected ".concat(this.VERTICES," items, received ").concat(this.CONSTANT_DATA.length," instead)"));this.constantArray=new Float32Array(this.CONSTANT_DATA.length*i);for(var o=0;o<this.CONSTANT_DATA.length;o++){var s=this.CONSTANT_DATA[o];if(s.length!==i)throw Error("Program: error while getting constant data (one vector has ".concat(s.length," items instead of ").concat(i,")"));for(var l=0;l<s.length;l++)this.constantArray[o*i+l]=s[l]}this.STRIDE=this.ATTRIBUTES_ITEMS_COUNT}}return oe(e,[{key:"kill",value:function(){if(ei(this.normalProgram),this.pickProgram)ei(this.pickProgram)}},{key:"resetDebugStats",value:function(){this.debugStats.drawCalls=0,this.debugStats.verticesDrawn=0,this.debugStats.bufferUploadBytes=0}},{key:"getProgramInfo",value:function(n,t,r,i,o){var s=t.createBuffer();if(s===null)throw Error("Program: error while creating the WebGL buffer.");var l=ka(t,r),d=Pa(t,i),u=Fa(t,[l,d]),c={};this.UNIFORMS.forEach(function(p){var y=t.getUniformLocation(u,p);if(y)c[p]=y});var g={};this.ATTRIBUTES.forEach(function(p){g[p.name]=t.getAttribLocation(u,p.name)});var h;if(this.isInstanced){if(this.CONSTANT_ATTRIBUTES.forEach(function(p){g[p.name]=t.getAttribLocation(u,p.name)}),h=t.createBuffer(),h===null)throw Error("Program: error while creating the WebGL constant buffer.")}return{name:n,program:u,gl:t,frameBuffer:o,buffer:s,constantBuffer:h||{},uniformLocations:c,attributeLocations:g,isPicking:n==="pick",vertexShader:l,fragmentShader:d}}},{key:"bindProgram",value:function(n){var t=this,r=0,{gl:i,buffer:o}=n;if(!this.isInstanced){if(i.bindBuffer(i.ARRAY_BUFFER,o),r=0,this.ATTRIBUTES.forEach(function(u){return r+=t.bindAttribute(u,n,r)}),this.uploadedGeneration.get(o)!==this.bufferGeneration){var s;if(i.bufferData(i.ARRAY_BUFFER,this.floats,i.DYNAMIC_DRAW),this.uploadedGeneration.set(o,this.bufferGeneration),(s=this.renderer)!==null&&s!==void 0&&s.getSetting("DEBUG_logRenderStats"))this.debugStats.bufferUploadBytes+=this.floats.byteLength}}else{if(i.bindBuffer(i.ARRAY_BUFFER,n.constantBuffer),r=0,this.CONSTANT_ATTRIBUTES.forEach(function(u){return r+=t.bindAttribute(u,n,r,!1)}),this.uploadedConstantGeneration.get(n.constantBuffer)!==this.constantBufferGeneration){var l;if(i.bufferData(i.ARRAY_BUFFER,this.constantArray,i.STATIC_DRAW),this.uploadedConstantGeneration.set(n.constantBuffer,this.constantBufferGeneration),(l=this.renderer)!==null&&l!==void 0&&l.getSetting("DEBUG_logRenderStats"))this.debugStats.bufferUploadBytes+=this.constantArray.byteLength}if(i.bindBuffer(i.ARRAY_BUFFER,n.buffer),r=this.renderOffset*this.ATTRIBUTES_ITEMS_COUNT*Float32Array.BYTES_PER_ELEMENT,this.ATTRIBUTES.forEach(function(u){return r+=t.bindAttribute(u,n,r,!0)}),this.uploadedGeneration.get(o)!==this.bufferGeneration){var d;if(i.bufferData(i.ARRAY_BUFFER,this.floats,i.DYNAMIC_DRAW),this.uploadedGeneration.set(o,this.bufferGeneration),(d=this.renderer)!==null&&d!==void 0&&d.getSetting("DEBUG_logRenderStats"))this.debugStats.bufferUploadBytes+=this.floats.byteLength}}i.bindBuffer(i.ARRAY_BUFFER,null)}},{key:"unbindProgram",value:function(n){var t=this;if(!this.isInstanced)this.ATTRIBUTES.forEach(function(r){return t.unbindAttribute(r,n)});else this.CONSTANT_ATTRIBUTES.forEach(function(r){return t.unbindAttribute(r,n,!1)}),this.ATTRIBUTES.forEach(function(r){return t.unbindAttribute(r,n,!0)})}},{key:"bindAttribute",value:function(n,t,r,i){var o=dd[n.type];if(typeof o!=="number")throw Error(\'Program.bind: yet unsupported attribute type "\'.concat(n.type,\'"\'));var s=t.attributeLocations[n.name],l=t.gl;if(s!==-1){l.enableVertexAttribArray(s);var d=!this.isInstanced?this.ATTRIBUTES_ITEMS_COUNT*Float32Array.BYTES_PER_ELEMENT:(i?this.ATTRIBUTES_ITEMS_COUNT:La(this.CONSTANT_ATTRIBUTES))*Float32Array.BYTES_PER_ELEMENT;if(l.vertexAttribPointer(s,n.size,n.type,n.normalized||!1,d,r),this.isInstanced&&i)l.vertexAttribDivisor(s,1)}return n.size*o}},{key:"unbindAttribute",value:function(n,t,r){var i=t.attributeLocations[n.name],o=t.gl;if(i!==-1){if(o.disableVertexAttribArray(i),this.isInstanced&&r)o.vertexAttribDivisor(i,0)}}},{key:"reallocate",value:function(n){if(n===this.capacity)return;this.capacity=n,this.verticesCount=this.VERTICES*n,this.floats=new Float32Array(!this.isInstanced?this.verticesCount*this.ATTRIBUTES_ITEMS_COUNT:this.capacity*this.ATTRIBUTES_ITEMS_COUNT),this.ints=new Uint32Array(this.floats.buffer),this.invalidateBuffers()}},{key:"invalidateBuffers",value:function(){this.bufferGeneration++,this.constantBufferGeneration++}},{key:"hasNothingToRender",value:function(){return this.verticesCount===0}},{key:"setTypedUniform",value:function(n,t){var r;Na(t.gl,(r=t.uniformLocations[n.name])!==null&&r!==void 0?r:null,n)}},{key:"renderProgram",value:function(n,t){var{gl:r,program:i,isPicking:o}=t;if(o)r.disable(r.BLEND);else r.enable(r.BLEND);r.useProgram(i),this.setUniforms(n,t),this.drawWebGL(this.METHOD,t)}},{key:"render",value:function(n,t,r){var i;if(!this.shadersLogged&&(i=this.renderer)!==null&&i!==void 0&&i.getSetting("DEBUG_logShaders"))this.shadersLogged=!0,console.log("[sigma] DEBUG_logShaders: ".concat(this.constructor.name),{normal:{vertexShaderSource:this.VERTEX_SHADER_SOURCE,fragmentShaderSource:this.FRAGMENT_SHADER_SOURCE},pick:{vertexShaderSource:Dn(this.VERTEX_SHADER_SOURCE),fragmentShaderSource:Dn(this.FRAGMENT_SHADER_SOURCE)}});if(this.hasNothingToRender())return;this.renderOffset=t!==null&&t!==void 0?t:0,this.renderCount=r!==null&&r!==void 0?r:-1;var o=this.normalProgram.gl;if(o.bindFramebuffer(o.FRAMEBUFFER,null),o.viewport(0,0,n.width*n.pixelRatio,n.height*n.pixelRatio),this.bindProgram(this.normalProgram),this.renderProgram(n,this.normalProgram),this.unbindProgram(this.normalProgram),this.pickProgram&&n.pickingFrameBuffer){var s=Math.ceil(n.width*n.pixelRatio/n.downSizingRatio),l=Math.ceil(n.height*n.pixelRatio/n.downSizingRatio);o.bindFramebuffer(o.FRAMEBUFFER,n.pickingFrameBuffer),o.viewport(0,0,s,l),this.bindProgram(this.pickProgram),this.renderProgram(n,this.pickProgram),this.unbindProgram(this.pickProgram),o.bindFramebuffer(o.FRAMEBUFFER,null),o.viewport(0,0,n.width*n.pixelRatio,n.height*n.pixelRatio)}}},{key:"drawWebGL",value:function(n,t){var r,i=t.gl,o=this.renderCount>=0?this.renderCount:this.capacity;if((r=this.renderer)!==null&&r!==void 0&&r.getSetting("DEBUG_logRenderStats"))this.debugStats.drawCalls++,this.debugStats.verticesDrawn+=o*this.VERTICES;if(!this.isInstanced)i.drawArrays(n,this.renderOffset*this.VERTICES,o*this.VERTICES);else i.drawArraysInstanced(n,0,this.VERTICES,o)}}])}(),et=2,Yt=7,mi={below:0,above:1,left:2,right:3};function ud(){var e=`#version 300 es\nprecision highp float;\n\nuniform mat3 u_matrix;\nuniform vec2 u_resolution;\nuniform float u_labelPixelSnapping;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\nuniform float u_cameraAngle;\nuniform float u_pixelRatio;\nuniform float u_labelMargin;\nuniform float u_zoomLabelSizeRatio;\n\nuniform sampler2D u_nodeDataTexture;\nuniform int u_nodeDataTextureWidth;\nuniform sampler2D u_nodeFrameTexture;\nuniform int u_nodeFrameTextureWidth;\n\n// Atlas size is fixed at 2048×2048 — matches AttachmentManager.ATLAS_SIZE.\nuniform sampler2D u_atlasTexture;\nconst vec2 u_atlasSize = vec2(2048.0);\n\n// Per-instance\nin float a_nodeIndex; // node-data texture index\nin vec4 a_atlasRect; // x, y, width, height in atlas pixels\nin vec2 a_attachmentSize; // attachment dimensions (CSS px)\nin float a_positionMode; // label position: 0=right 1=left 2=above 3=below 4=over\nin float a_attachmentPlacement; // 0=below 1=above 2=left 3=right (relative to label)\nin float a_labelWidth; // label width (CSS px)\nin float a_labelHeight; // label height: font line box (CSS px)\nin float a_textHeight; // actual glyph height (CSS px)\nin float a_labelAngle; // label rotation angle (radians)\n\n// Per-vertex (constant)\nin vec2 a_quadCorner; // [-1,-1], [1,-1], [-1,1], [1,1]\n\nout vec2 v_texCoord;\n\n`.concat(Xe,`\n`).concat(ot,`\n`).concat(Lt,`\n`).concat(vi,`\n`).concat(In,`\n\nvoid main() {\n int nodeIdx = int(a_nodeIndex);\n\n // Node data: (x, y, size, shapeId).\n vec4 nodeData = readNodeData(u_nodeDataTexture, u_nodeDataTextureWidth, nodeIdx);\n vec2 nodePos = nodeData.xy;\n float nodeSize = nodeData.z;\n\n // Normalized edge distance from the shared frame texture (the frame-pass ran\n // the SDF search once; we just read the result).\n float edgeDist = readFrameTexel(u_nodeFrameTexture, u_nodeFrameTextureWidth, nodeIdx).r;\n\n // Per-node label rotation alignment: 0 = viewport, 1 = label turns with camera.\n float labelRotation = readNodeFlags(u_nodeDataTexture, u_nodeDataTextureWidth, nodeIdx).g;\n\n vec3 nodeClip = u_matrix * vec3(nodePos, 1.0);\n\n // Node radius in physical pixels (matches label/background).\n float matrixScaleX = length(vec2(u_matrix[0][0], u_matrix[1][0]));\n float nodeRadiusGraphSpace = nodeSize * u_correctionRatio / u_sizeRatio * 2.0;\n float nodeRadiusPixels = nodeRadiusGraphSpace * matrixScaleX * u_resolution.x / 2.0;\n\n // CSS-px inputs -> physical px, scaled by the zoom-dependent label ratio, so\n // the attachment stays glued to the label box exactly as the label scales.\n float zoomScale = u_zoomLabelSizeRatio;\n vec2 labelHalf = vec2(a_labelWidth, a_labelHeight) * 0.5 * zoomScale * u_pixelRatio;\n vec2 attachHalf = a_attachmentSize * 0.5 * zoomScale * u_pixelRatio;\n float gap = `).concat(et.toFixed(1),` * zoomScale * u_pixelRatio;\n float labelMargin = u_labelMargin * zoomScale * u_pixelRatio;\n\n // Graph-aligned labels add the camera angle so the attachment orbits with the box.\n mat2 labelRotMat = rotate2D(a_labelAngle - labelRotation * u_cameraAngle);\n\n // Label box center relative to the node center (pre-rotation). The shape-aware\n // edge distance comes from the frame texture, so placement matches the label.\n vec2 boxCenter = vec2(0.0);\n if (a_positionMode < 4.0) {\n float labelStart = nodeRadiusPixels * edgeDist + labelMargin;\n float textHalf = a_textHeight * 0.5 * zoomScale * u_pixelRatio;\n boxCenter = labelBoxCenter(a_positionMode, labelStart, labelHalf, textHalf);\n }\n\n // Horizontal anchor of below/above attachments tracks the label position, so\n // the attachment hangs from the label edge nearest the node (or is centered\n // when the label itself is node-centered): right->left, left->right, else center.\n float anchorX = 0.0;\n if (a_positionMode < 0.5) anchorX = -labelHalf.x + attachHalf.x; // right label\n else if (a_positionMode < 1.5) anchorX = labelHalf.x - attachHalf.x; // left label\n\n // Attachment center relative to the box (pre-rotation, Y-down). This offset\n // depends only on the box, the gap and the attachment size — never the shape.\n vec2 attachCenter;\n if (a_attachmentPlacement < 0.5) {\n // below\n attachCenter = boxCenter + vec2(anchorX, labelHalf.y + gap + attachHalf.y);\n } else if (a_attachmentPlacement < 1.5) {\n // above\n attachCenter = boxCenter + vec2(anchorX, -(labelHalf.y + gap + attachHalf.y));\n } else if (a_attachmentPlacement < 2.5) {\n // left, top-aligned\n attachCenter = boxCenter + vec2(-(labelHalf.x + gap + attachHalf.x), -labelHalf.y + attachHalf.y);\n } else {\n // right, top-aligned\n attachCenter = boxCenter + vec2(labelHalf.x + gap + attachHalf.x, -labelHalf.y + attachHalf.y);\n }\n\n // Rotate the whole assembly by the label angle, around the node center.\n vec2 rotatedCenter = labelRotMat * attachCenter;\n vec2 cornerOffset = labelRotMat * (a_quadCorner * attachHalf);\n\n // Node center in screen px (Y-down).\n vec2 nodeScreen = vec2(\n (nodeClip.x + 1.0) * u_resolution.x,\n (1.0 - nodeClip.y) * u_resolution.y\n ) * 0.5;\n\n // Snap node center to the pixel grid so label/backdrop/attachment move as one.\n vec2 snapDelta = (round(nodeScreen) - nodeScreen) * u_labelPixelSnapping;\n\n // Snap the quad\'s top-left to integer pixels so atlas texels map 1:1.\n vec2 centerScreen = nodeScreen + rotatedCenter + snapDelta;\n vec2 topLeft = centerScreen - attachHalf;\n topLeft = mix(topLeft, round(topLeft), u_labelPixelSnapping);\n centerScreen = topLeft + attachHalf;\n\n vec2 vertexScreen = centerScreen + cornerOffset;\n gl_Position = vec4(\n vertexScreen.x * 2.0 / u_resolution.x - 1.0,\n 1.0 - vertexScreen.y * 2.0 / u_resolution.y,\n 0.0, 1.0\n );\n\n vec2 texOrigin = a_atlasRect.xy / u_atlasSize;\n vec2 texSize = a_atlasRect.zw / u_atlasSize;\n vec2 uv = (a_quadCorner + 1.0) / 2.0;\n v_texCoord = texOrigin + uv * texSize;\n}\n`);return e}var cd=`#version 300 es\nprecision highp float;\n\nuniform sampler2D u_atlasTexture;\n\nin vec2 v_texCoord;\n\nlayout(location = 0) out vec4 fragColor;\n#ifdef PICKING_MODE\nlayout(location = 1) out vec4 pickColor;\n#endif\n\nvoid main() {\n // Canvas textures are premultiplied; output directly for (ONE, 1-SRC_ALPHA) blending\n vec4 color = texture(u_atlasTexture, v_texCoord);\n if (color.a < 0.01) discard;\n fragColor = color;\n#ifdef PICKING_MODE\n pickColor = vec4(0.0); // Attachments are not pickable\n#endif\n}\n`;function hd(e,a,n,t){var r,i,o=t.label,s=o===void 0?{}:o,l=(r=s.margin)!==null&&r!==void 0?r:Dt,d=(i=s.zoomToLabelSizeRatioFunction)!==null&&i!==void 0?i:function(){return 1},u=ud(),c=cd,g=function(h){function p(){var y;ie(this,p);for(var v=arguments.length,f=Array(v),b=0;b<v;b++)f[b]=arguments[b];return y=fe(this,p,[].concat(f)),R(y,"totalCount",0),R(y,"bufferCapacity",0),y}return ge(p,h),oe(p,[{key:"getDefinition",value:function(){var v=WebGL2RenderingContext,{FLOAT:f,TRIANGLE_STRIP:b}=v;return{VERTICES:4,VERTEX_SHADER_SOURCE:u,FRAGMENT_SHADER_SOURCE:c,METHOD:b,UNIFORMS:["u_matrix","u_resolution","u_labelPixelSnapping","u_sizeRatio","u_correctionRatio","u_cameraAngle","u_pixelRatio","u_labelMargin","u_zoomLabelSizeRatio","u_nodeDataTexture","u_nodeDataTextureWidth","u_nodeFrameTexture","u_nodeFrameTextureWidth","u_atlasTexture"],ATTRIBUTES:[{name:"a_nodeIndex",size:1,type:f},{name:"a_atlasRect",size:4,type:f},{name:"a_attachmentSize",size:2,type:f},{name:"a_positionMode",size:1,type:f},{name:"a_attachmentPlacement",size:1,type:f},{name:"a_labelWidth",size:1,type:f},{name:"a_labelHeight",size:1,type:f},{name:"a_textHeight",size:1,type:f},{name:"a_labelAngle",size:1,type:f}],CONSTANT_ATTRIBUTES:[{name:"a_quadCorner",size:2,type:f}],CONSTANT_DATA:[[-1,-1],[1,-1],[-1,1],[1,1]]}}},{key:"processAttachment",value:function(v,f){var b=this.floats,m=v*this.STRIDE;b[m++]=f.nodeIndex,b[m++]=f.atlasX,b[m++]=f.atlasY,b[m++]=f.atlasW,b[m++]=f.atlasH,b[m++]=f.attachWidth,b[m++]=f.attachHeight,b[m++]=f.positionMode,b[m++]=f.attachmentPlacement,b[m++]=f.labelWidth,b[m++]=f.labelHeight,b[m++]=f.textHeight,b[m++]=f.labelAngle}},{key:"setUniforms",value:function(v,f){var{gl:b,uniformLocations:m}=f;b.uniformMatrix3fv(m.u_matrix,!1,v.matrix),b.uniform2f(m.u_resolution,v.width*v.pixelRatio,v.height*v.pixelRatio),b.uniform1f(m.u_labelPixelSnapping,v.labelPixelSnapping),b.uniform1f(m.u_sizeRatio,v.sizeRatio),b.uniform1f(m.u_correctionRatio,v.correctionRatio),b.uniform1f(m.u_cameraAngle,v.cameraAngle),b.uniform1f(m.u_pixelRatio,v.pixelRatio),b.uniform1f(m.u_labelMargin,p.labelMargin),b.uniform1f(m.u_zoomLabelSizeRatio,1/d(v.zoomRatio)),b.uniform1i(m.u_nodeDataTexture,v.nodeDataTextureUnit),b.uniform1i(m.u_nodeDataTextureWidth,v.nodeDataTextureWidth),b.uniform1i(m.u_nodeFrameTexture,v.nodeFrameTextureUnit),b.uniform1i(m.u_nodeFrameTextureWidth,v.nodeFrameTextureWidth),b.uniform1i(m.u_atlasTexture,Yt)}},{key:"reallocateAttachments",value:function(v){if(this.totalCount=v,v>this.bufferCapacity)this.bufferCapacity=Math.max(v,Math.ceil(this.bufferCapacity*1.5)||10),xe(p,"reallocate",this,3)([this.bufferCapacity])}},{key:"hasNothingToRender",value:function(){return this.totalCount===0}},{key:"drawWebGL",value:function(v,f){var b=f.gl;if(this.totalCount===0)return;b.drawArraysInstanced(v,0,this.VERTICES,this.totalCount)}}])}(st);return R(g,"labelMargin",l),new g(e,a,n)}var Qe=5;function On(e,a){return[].concat(J(a),J(e.map(function(n){var t;return{attributes:(t=n.attributes)!==null&&t!==void 0?t:[]}})))}function Ct(e,a){var n=Me(On(e,a)),t=new Set(e.flatMap(function(d){var u;return(u=d.attributes)!==null&&u!==void 0?u:[]}).map(function(d){return d.name.replace(/^a_/,"")})),r={},i={},o=W(t),s;try{for(o.s();!(s=o.n()).done;){var l=s.value;r[l]=n.offsets[l],i[l]=n.specs[l]}}catch(d){o.e(d)}finally{o.f()}return V(V({},n),{},{offsets:r,specs:i})}function fd(e,a){var n=new Set(["u_matrix","u_sizeRatio","u_correctionRatio","u_cameraAngle","u_pickingPadding","u_nodeDataTexture","u_layerAttributeTexture"]),t=new Set,r=e.flatMap(function(h){return h.uniforms}).filter(function(h){if(n.has(h.name)||t.has(h.name))return!1;return t.add(h.name),!0}).map(function(h){return"uniform ".concat(h.type," ").concat(h.name,";")}).join(`\n`),i=a.flatMap(function(h){return h.uniforms}).filter(function(h){if(n.has(h.name)||t.has(h.name))return!1;return t.add(h.name),!0}).map(function(h){return"uniform ".concat(h.type," ").concat(h.name,";")}).join(`\n`),o=On(e,a),s=new Set,l=o.flatMap(function(h){return h.attributes}).filter(function(h){var p=h.name.replace(/^a_/,"");if(s.has(p))return!1;return s.add(p),!0}).map(function(h){var p=h.name.replace(/^a_/,""),y=h.size===1?"float":"vec".concat(h.size);return"out ".concat(y," v_").concat(p,";")}).join(`\n`),d=At(Me(o),{varPrefix:"layer",baseTexelExpr:"nodeIdx * u_layerAttributeTexelsPerNode",textureWidthUniform:"u_layerAttributeTextureWidth",textureSamplerUniform:"u_layerAttributeTexture"}),{fetchCode:u,varyingAssignments:c}=d,g=`#version 300 es\n\n// Standard node attributes (per instance) - minimal buffer usage\nin float a_nodeIndex; // Index into node data texture AND layer attribute texture\nin vec4 a_id; // Node ID for picking\nin float a_opacity; // Node opacity, applied once to the final fragment\n\n// Constant attributes (per vertex, same for all instances)\nin vec2 a_quadCorner; // (-1,-1), (1,-1), (1,1), (-1,1) for quad corners\n\n// Standard uniforms\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\nuniform float u_cameraAngle;\n#ifdef PICKING_MODE\nuniform float u_pickingPadding;\n#endif\nuniform sampler2D u_nodeDataTexture;\nuniform int u_nodeDataTextureWidth;\n\n// Layer attribute texture uniforms\nuniform sampler2D u_layerAttributeTexture;\nuniform int u_layerAttributeTextureWidth;\nuniform int u_layerAttributeTexelsPerNode;\n\n`.concat(r,`\n`).concat(i,`\n\n// Standard varyings\nout vec2 v_uv; // Normalized coordinates [-1, 1]\nout vec4 v_id;\nout float v_opacity;\nout float v_antialiasingWidth; // Width for antialiasing in UV space\nout float v_pixelSize; // Node size in pixels (for pixel-mode borders)\nout float v_pixelToUV; // Conversion factor: multiply by this to convert screen pixels to UV units\nout float v_shapeId; // Shape ID for multi-shape programs\n\n// Layer varyings\n`).concat(l,`\n\n// Node-data fetch helpers (geometry texel + rotation-flags texel)\n`).concat(Xe,`\n`).concat(ot,`\n\nvoid main() {\n // Fetch node geometry: vec4(x, y, size, shapeId).\n int nodeIdx = int(a_nodeIndex);\n\n // Hidden nodes are flagged with a negative row by NodeProgram.process(). Push\n // the whole quad outside the clip volume: every vertex lands at the same\n // out-of-range position, so the primitive is fully clipped and rasterizes\n // nothing — neither to the frame buffer nor to the picking buffer.\n if (nodeIdx < 0) {\n gl_Position = vec4(2.0, 0.0, 0.0, 1.0);\n v_id = vec4(0.0);\n return;\n }\n\n vec4 nodeData = readNodeData(u_nodeDataTexture, u_nodeDataTextureWidth, nodeIdx);\n vec2 a_position = nodeData.xy;\n float a_size = nodeData.z;\n v_shapeId = nodeData.w; // Pass shape ID to fragment shader\n\n // Per-node rotation alignment: 0 = viewport (screen-upright), 1 = graph.\n float nodeRotation = readNodeFlags(u_nodeDataTexture, u_nodeDataTextureWidth, nodeIdx).r;\n\n`).concat(u,`\n\n // Calculate the actual size in pixels\n float size = a_size * u_correctionRatio / u_sizeRatio * 2.0;\n\n // In PICKING_MODE, inflate the quad by nodePickingPadding pixels on each side\n #ifdef PICKING_MODE\n float paddedSize = size + u_pickingPadding * u_correctionRatio;\n vec2 offset = a_quadCorner * paddedSize;\n #else\n vec2 offset = a_quadCorner * size;\n #endif\n // Counter-rotate the quad offset so viewport-aligned nodes stay upright as the\n // camera turns. Graph-aligned nodes (nodeRotation=1) skip it and turn with the\n // camera. The angle scales by (1 - nodeRotation) so both fall out of one path.\n {\n float ca = u_cameraAngle * (1.0 - nodeRotation);\n float c = cos(ca);\n float s = sin(ca);\n offset = mat2(c, s, -s, c) * offset;\n }\n vec2 position = a_position + offset;\n\n gl_Position = vec4(\n (u_matrix * vec3(position, 1)).xy,\n 0,\n 1\n );\n\n // In PICKING_MODE, UV is scaled beyond [-1, 1] to match the inflated quad\n #ifdef PICKING_MODE\n v_uv = a_quadCorner * (paddedSize / size);\n #else\n v_uv = a_quadCorner;\n #endif\n\n // Pass ID to fragment shader\n v_id = a_id;\n v_opacity = a_opacity;\n\n // Pass pixel size for layers that need pixel-mode calculations\n // Multiply by 2 because \'size\' is half-width (offset from center), not full diameter\n v_pixelSize = size * 2.0;\n\n // Conversion factor from screen pixels to UV units\n // Same derivation as v_antialiasingWidth which represents ~1 pixel in UV space\n // P pixels in UV space = P * u_correctionRatio / size\n v_pixelToUV = u_correctionRatio / size;\n\n // We use an antialiasing width of 1px (so v_pixelToUV)\n v_antialiasingWidth = v_pixelToUV;\n\n // Pass layer attributes to fragment shader (fetched from texture)\n`).concat(c,`\n}\n`);return g}function gd(e,a,n){var t=arguments.length>3&&arguments[3]!==void 0?arguments[3]:!0,r=a.map(function(p,y){var v="layer_".concat(p.name),f=[].concat(J(p.attributes.map(function(b){return"v_".concat(b.name.replace(/^a_/,""))})),J(p.uniforms.map(function(b){return b.name}))).join(", ");return" // Layer ".concat(y+1,": ").concat(p.name,`\n color = blendOver(color, `).concat(v,"(").concat(f,"));")}).join(`\n\n`),i=new Set(["u_correctionRatio"]),o=new Set,s=e.flatMap(function(p){return p.uniforms}).filter(function(p){if(i.has(p.name)||o.has(p.name))return!1;return o.add(p.name),!0}).map(function(p){return"uniform ".concat(p.type," ").concat(p.name,";")}).join(`\n`),l=a.flatMap(function(p){return p.uniforms}).filter(function(p){if(i.has(p.name)||o.has(p.name))return!1;return o.add(p.name),!0}).map(function(p){return"uniform ".concat(p.type," ").concat(p.name,";")}).join(`\n`),d=new Set,u=On(e,a).flatMap(function(p){return p.attributes}).filter(function(p){var y=p.name.replace(/^a_/,"");if(d.has(y))return!1;return d.add(y),!0}).map(function(p){var y=p.name.replace(/^a_/,""),v=p.size===1?"float":"vec".concat(p.size);return"in ".concat(v," v_").concat(y,";")}).join(`\n`),c=Ia(e),g=Jl(e,n),h=`#version 300 es\nprecision highp float;\n\n// Standard varyings\nin vec2 v_uv;\nin vec4 v_id;\nin float v_opacity;\nin float v_antialiasingWidth;\nin float v_pixelSize;\nin float v_pixelToUV;\nin float v_shapeId; // Shape ID for multi-shape programs\n\n// Standard uniforms (needed for some layer calculations like pixel-mode borders)\nuniform float u_correctionRatio;\n#ifdef PICKING_MODE\nuniform float u_pickingPadding;\n#endif\n\n// Shape uniforms\n`.concat(s,`\n\n// Layer uniforms\n`).concat(l,`\n\n// Layer varyings\n`).concat(u,`\n\n// Fragment output (single target - picking handled via separate pass)\nout vec4 fragColor;\n\n// LayerContext struct - provides rendering context to all layers\nstruct LayerContext {\n float sdf; // Signed distance from shape boundary (negative inside)\n vec2 uv; // UV coordinates [-1, 1], center at (0,0)\n float shapeSize; // Effective shape size (~diameter) in UV space (1.0 - aaWidth)\n float shapeHalfSize; // Effective shape half size (~radius) in UV space\n float pixelSize; // Node full size (~diameter) in screen pixels\n float aaWidth; // Anti-aliasing width for smooth transitions\n float correctionRatio; // Scaling factor for consistent rendering across zoom levels\n float pixelToUV; // Conversion factor: multiply screen pixels by this to get UV units\n float inradiusFactor; // Ratio of inradius to circumradius (shape depth factor)\n};\n\nLayerContext context; // Global instance, populated before layer calls\n\n// Alpha "over" compositing for layer blending\nvec4 blendOver(vec4 bg, vec4 fg) {\n float a = fg.a;\n return vec4(mix(bg.rgb, fg.rgb, a), bg.a + a * (1.0 - bg.a));\n}\n\n// SDF shape functions\n`).concat(c,`\n\n// Shape selector function (sets context.sdf and context.inradiusFactor)\n`).concat(g,`\n\n// Layer functions\n`).concat(a.map(function(p){return p.glsl}).join(`\n\n`),`\n\nvoid main() {\n // 1. Setup LayerContext (available to all layer functions)\n context.shapeSize = 1.0 - v_antialiasingWidth;\n context.shapeHalfSize = context.shapeSize * 0.5;\n context.pixelSize = v_pixelSize;\n context.uv = v_uv;\n context.aaWidth = v_antialiasingWidth;\n context.correctionRatio = u_correctionRatio;\n context.pixelToUV = v_pixelToUV;\n\n // Query shape SDF based on shapeId (sets context.sdf and context.inradiusFactor)\n queryNodeSDF(int(v_shapeId), v_uv, context.shapeSize);\n\n // 2. Early discard for pixels fully outside the shape (with AA margin)\n // In PICKING_MODE, allow extra fragments up to the picking padding distance\n #ifdef PICKING_MODE\n if (context.sdf > u_pickingPadding * v_pixelToUV + context.aaWidth) discard;\n #else\n if (context.sdf > context.aaWidth) discard;\n #endif\n\n // 3. Apply layers sequentially with "over" compositing\n vec4 color = vec4(0.0);\n\n`).concat(r,`\n\n #ifdef PICKING_MODE\n // Picking pass: output node ID for pixels within the picking area.\n if (context.sdf > u_pickingPadding * v_pixelToUV) discard;\n fragColor = v_id;\n #else\n`).concat(t?` // Visual pass: apply antialiasing at shape boundary, node opacity once\n // smoothstep provides smooth transition from opaque to transparent\n float alpha = smoothstep(context.aaWidth, -context.aaWidth, context.sdf) * v_opacity;`:` // Visual pass: hard-edged (no anti-aliasing gradient) shape boundary, node opacity applied once\n float alpha = (context.sdf < 0.0 ? 1.0 : 0.0) * v_opacity;`,`\n // Mix with transparent to fade both color AND alpha together (avoids bright halo)\n fragColor = mix(vec4(0.0), color, alpha);\n #endif\n}\n`);return h}function vd(e,a){var n=new Set;return n.add("u_matrix"),n.add("u_sizeRatio"),n.add("u_correctionRatio"),n.add("u_cameraAngle"),n.add("u_pickingPadding"),n.add("u_nodeDataTexture"),n.add("u_nodeDataTextureWidth"),n.add("u_layerAttributeTexture"),n.add("u_layerAttributeTextureWidth"),n.add("u_layerAttributeTexelsPerNode"),e.forEach(function(t){t.uniforms.forEach(function(r){return n.add(r.name)})}),a.forEach(function(t){t.uniforms.forEach(function(r){return n.add(r.name)})}),Array.from(n)}function pd(e){var a=WebGL2RenderingContext,{UNSIGNED_BYTE:n,FLOAT:t}=a;return[{name:"a_nodeIndex",size:1,type:t},{name:"a_id",size:4,type:n,normalized:!0},{name:"a_opacity",size:1,type:t}]}function ni(e){var{shapes:a,layers:n,shapeGlobalIds:t,antialias:r}=e,i=r===void 0?!0:r;return{vertexShader:fd(a,n),fragmentShader:gd(a,n,t,i),uniforms:vd(a,n),attributes:pd()}}function bi(e,a,n){var t=Ct(e,a),r=t.specs;return Object.keys(r).map(function(i){return"flat ".concat(n," ").concat(r[i].size===1?"float":"vec".concat(r[i].size)," v_").concat(i,";")}).join(`\n`)}function md(e){var a,n,{shapes:t,layers:r,shapeGlobalIds:i}=e,o=At(Ct(t,r),{varPrefix:"nodeAttr",baseTexelExpr:"nodeIdx * u_layerAttributeTexelsPerNode",textureWidthUniform:"u_layerAttributeTextureWidth",textureSamplerUniform:"u_layerAttributeTexture"}),s=t.length===1?"float inradiusFactor = ".concat(ve((a=t[0].inradiusFactor)!==null&&a!==void 0?a:1),";"):"float inradiusFactor = ".concat(ve((n=t[0].inradiusFactor)!==null&&n!==void 0?n:1),`;\n switch (int(shapeId)) {\n`).concat(t.map(function(d,u){var c,g=i?i[u]:u;return" case ".concat(g,": inradiusFactor = ").concat(ve((c=d.inradiusFactor)!==null&&c!==void 0?c:1),"; break;")}).join(`\n`),`\n default: break;\n }`),l=`#version 300 es\n\nin float a_nodeIndex;\nin float a_labelWidth;\nin float a_labelHeight;\nin float a_textHeight;\nin float a_positionMode;\nin float a_labelAngle;\nin vec4 a_backdropColor;\nin vec4 a_backdropShadowColor;\nin float a_backdropShadowBlur;\nin float a_backdropPadding;\nin vec4 a_backdropBorderColor;\nin vec4 a_backdropExtra; // [borderWidth, cornerRadius, labelPadding, area]\nin vec2 a_labelBoxOffset;\nin vec2 a_quadCorner;\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\nuniform float u_cameraAngle;\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\nuniform float u_labelMargin;\nuniform float u_zoomLabelSizeRatio;\nuniform float u_labelPixelSnapping;\nuniform sampler2D u_nodeDataTexture;\nuniform int u_nodeDataTextureWidth;\nuniform sampler2D u_nodeFrameTexture;\nuniform int u_nodeFrameTextureWidth;\nuniform sampler2D u_layerAttributeTexture;\nuniform int u_layerAttributeTextureWidth;\nuniform int u_layerAttributeTexelsPerNode;\n\nout vec2 v_uv;\nout vec2 v_nodeCenter;\nout float v_nodeRadius;\nout vec2 v_labelCenter;\nout vec2 v_labelHalfSize;\nout float v_aaWidth;\nout float v_shapeId;\nout float v_nodeRotation;\nout float v_labelAngle;\nout vec4 v_backdropColor;\nout vec4 v_backdropShadowColor;\nout float v_backdropShadowBlur;\nout float v_backdropPadding;\nout vec4 v_backdropBorderColor;\nout float v_backdropBorderWidth;\nout float v_backdropCornerRadius;\nout float v_backdropArea;\n`.concat(bi(t,r,"out"),`\n\n`).concat(Xe,`\n`).concat(ot,`\n`).concat(Lt,`\n\nvoid main() {\n int nodeIdx = int(a_nodeIndex);\n`).concat(o.fetchCode,`\n`).concat(o.varyingAssignments,`\n\n // Node data: (x, y, size, shapeId). shapeId (global) is forwarded to the\n // fragment shader, which keeps the shape SDF for the outline.\n vec4 nodeData = readNodeData(u_nodeDataTexture, u_nodeDataTextureWidth, nodeIdx);\n vec2 nodePosition = nodeData.xy;\n float nodeSize = nodeData.z;\n float shapeId = nodeData.w;\n\n // Per-node rotation alignment (0 = viewport, 1 = graph). nodeRotation drives\n // the fragment\'s shape outline; labelRotation turns the label box with camera.\n vec4 nodeFlags = readNodeFlags(u_nodeDataTexture, u_nodeDataTextureWidth, nodeIdx);\n float nodeRotation = nodeFlags.r;\n float labelRotation = nodeFlags.g;\n v_nodeRotation = nodeRotation;\n\n `).concat(fi,`\n // CSS pixel attributes are multiplied by u_pixelRatio to match nodeRadiusPixels,\n // which is already in physical pixels (nodeRadiusNDC * u_resolution.x / 2.0).\n float padding = a_backdropPadding * u_pixelRatio;\n float shadowBlur = a_backdropShadowBlur * u_pixelRatio;\n // Unpack a_backdropExtra: [borderWidth, cornerRadius, labelPadding, area]\n float borderWidth = a_backdropExtra.x * u_pixelRatio;\n float cornerRadius = a_backdropExtra.y * u_pixelRatio;\n float labelPad = a_backdropExtra.z * u_pixelRatio;\n float backdropArea = a_backdropExtra.w;\n // Use 2x shadowBlur so the Gaussian fully decays before the quad edge\n float totalExpansion = shadowBlur * 2.0 + borderWidth;\n float enlargedRadius = nodeRadiusPixels + padding;\n\n // Circumscribed radius for the quad bounds. Non-circular shapes reach past\n // their inradius out to their circumradius (= enlargedRadius / inradiusFactor),\n // in any direction once rotated. The axis-aligned quad must contain that, or\n // the fill/shadow gets clipped (square corners, triangle tip, etc.).\n `).concat(s,`\n float boundRadius = enlargedRadius / inradiusFactor;\n\n // Apply zoom-dependent label size scaling\n float zoomScale = u_zoomLabelSizeRatio;\n float labelW = a_labelWidth * zoomScale * u_pixelRatio;\n float labelH = a_labelHeight * zoomScale * u_pixelRatio;\n float labelMargin = u_labelMargin * zoomScale * u_pixelRatio;\n\n // Only apply labelPad when a label is actually present\n float effectiveLabelPad = labelW > 0.0 ? labelPad : 0.0;\n vec2 labelHalfSize = vec2(labelW * 0.5 + effectiveLabelPad, labelH * 0.5 + effectiveLabelPad);\n vec2 labelOffset = vec2(0.0);\n\n // Effective label angle: intrinsic angle plus the camera angle when the label\n // is graph-aligned, so the box orbits the node in lockstep with the frame-pass.\n float labelAngle = a_labelAngle - labelRotation * u_cameraAngle;\n float la_c = cos(labelAngle);\n float la_s = sin(labelAngle);\n mat2 labelRotMat = mat2(la_c, -la_s, la_s, la_c);\n\n vec3 nodeClip = u_matrix * vec3(nodePosition, 1.0);\n vec2 snapDelta = vec2(0.0);\n\n if (labelW > 0.0) {\n // labelW > 0.0 means this node\'s label is displayed, so the frame-pass wrote\n // its edge distance this frame.\n float edgeDistPixels = nodeRadiusPixels * readFrameTexel(u_nodeFrameTexture, u_nodeFrameTextureWidth, nodeIdx).r;\n // labelMargin matches the label shader\'s margin (gap from node edge to text)\n float labelStart = edgeDistPixels + labelMargin;\n // Above/below center on the actual glyph height, not the font line box, so\n // the box stays aligned with the rendered text (matches labelBoxCenter()).\n float textHalf = a_textHeight * zoomScale * u_pixelRatio * 0.5;\n\n // Snap node center to pixel grid so label/backdrop/attachment move as a unit\n vec2 nodeScreen = vec2(\n (nodeClip.x + 1.0) * u_resolution.x,\n (1.0 - nodeClip.y) * u_resolution.y\n ) * 0.5;\n snapDelta = (round(nodeScreen) - nodeScreen) * u_labelPixelSnapping;\n\n if (a_positionMode < 0.5) {\n // Right: box spans from node center to text end + padding\n float boxRightEdge = labelStart + labelW + labelPad;\n labelOffset = vec2(boxRightEdge * 0.5, 0.0);\n labelHalfSize.x = boxRightEdge * 0.5;\n } else if (a_positionMode < 1.5) {\n // Left: mirror of right\n float boxLeftEdge = labelStart + labelW + labelPad;\n labelOffset = vec2(-boxLeftEdge * 0.5, 0.0);\n labelHalfSize.x = boxLeftEdge * 0.5;\n } else if (a_positionMode < 2.5) {\n // Above: text bottom at labelStart, centered horizontally\n labelOffset = vec2(0.0, -(labelStart + textHalf));\n } else if (a_positionMode < 3.5) {\n // Below: text top at labelStart, centered horizontally\n labelOffset = vec2(0.0, labelStart + textHalf);\n }\n // over (>=4): labelOffset stays (0,0) — text centered on the node.\n\n // The attachment-cover shift is in label space (like the attachment itself),\n // so rotate it together with the position offset — otherwise the box drifts\n // off the attachment as the label angle grows.\n labelOffset = labelRotMat * (labelOffset + a_labelBoxOffset * zoomScale * u_pixelRatio);\n }\n\n // For node-only mode, zero out label dimensions\n if (backdropArea > 0.5 && backdropArea < 1.5) {\n labelHalfSize = vec2(0.0);\n labelOffset = vec2(0.0);\n }\n\n vec2 minBound, maxBound;\n\n bool hasLabelBounds = labelW > 0.0 && (backdropArea > 1.5 || backdropArea < 0.5);\n\n if (hasLabelBounds) {\n // Union with label bounds (area=both) or label-only bounds (area=label)\n vec2 labelMin, labelMax;\n\n if (a_labelAngle != 0.0) {\n vec2 corner1 = labelOffset + labelRotMat * vec2(-labelHalfSize.x, -labelHalfSize.y);\n vec2 corner2 = labelOffset + labelRotMat * vec2(labelHalfSize.x, -labelHalfSize.y);\n vec2 corner3 = labelOffset + labelRotMat * vec2(labelHalfSize.x, labelHalfSize.y);\n vec2 corner4 = labelOffset + labelRotMat * vec2(-labelHalfSize.x, labelHalfSize.y);\n labelMin = min(min(corner1, corner2), min(corner3, corner4));\n labelMax = max(max(corner1, corner2), max(corner3, corner4));\n } else {\n labelMin = labelOffset - labelHalfSize;\n labelMax = labelOffset + labelHalfSize;\n }\n\n if (backdropArea > 1.5) {\n // Label-only: bounds from label rect only\n minBound = labelMin - totalExpansion;\n maxBound = labelMax + totalExpansion;\n } else {\n // Both: union of node + label\n minBound = min(-vec2(boundRadius), labelMin) - totalExpansion;\n maxBound = max(vec2(boundRadius), labelMax) + totalExpansion;\n }\n } else {\n // Node-only or no visible label\n float totalRadius = boundRadius + totalExpansion;\n minBound = -vec2(totalRadius);\n maxBound = vec2(totalRadius);\n }\n\n vec2 quadSize = maxBound - minBound;\n vec2 quadCenter = (minBound + maxBound) * 0.5;\n\n vec2 localPos = quadCenter + a_quadCorner * quadSize * 0.5 + snapDelta;\n vec2 ndcOffset = localPos * 2.0 / u_resolution;\n ndcOffset.y = -ndcOffset.y;\n\n gl_Position = vec4(nodeClip.xy + ndcOffset, 0.0, 1.0);\n\n v_uv = localPos;\n v_nodeCenter = vec2(0.0);\n v_nodeRadius = nodeRadiusPixels;\n v_labelCenter = labelOffset;\n v_labelHalfSize = labelHalfSize;\n v_aaWidth = 1.0;\n v_shapeId = shapeId;\n v_labelAngle = labelAngle;\n v_backdropColor = a_backdropColor;\n v_backdropShadowColor = a_backdropShadowColor;\n v_backdropShadowBlur = a_backdropShadowBlur;\n v_backdropPadding = a_backdropPadding;\n v_backdropBorderColor = a_backdropBorderColor;\n v_backdropBorderWidth = borderWidth;\n v_backdropCornerRadius = cornerRadius;\n v_backdropArea = backdropArea;\n}\n`);return l}function bd(e){var{shapes:a,layers:n,shapeGlobalIds:t}=e,r=Ia(a),i=qt(a).map(function(g){return"uniform ".concat(g.type," ").concat(g.name,";")}).join(`\n`),o=function(h){return Fn(h,"nodeUV","1.0")},s;if(a.length===1)s="float nodeSdfNormalized = ".concat(o(a[0]),";");else{var l=a.map(function(g,h){var p=t?t[h]:h;return" case ".concat(p,": nodeSdfNormalized = ").concat(o(g),"; break;")}).join(`\n`),d=o(a[0]);s=`float nodeSdfNormalized;\n int shapeId = int(v_shapeId);\n switch (shapeId) {\n`.concat(l,`\n default: nodeSdfNormalized = `).concat(d,`;\n }`)}var u=`float effectiveRadius = max(enlargedRadius - cornerRadius, 0.01);\n float ca = u_cameraAngle * v_nodeRotation;\n float ca_c = cos(ca);\n float ca_s = sin(ca);\n vec2 rotatedScreenUV = mat2(ca_c, -ca_s, ca_s, ca_c) * screenUV;\n vec2 nodeUV = vec2(rotatedScreenUV.x, -rotatedScreenUV.y) / effectiveRadius;`,c=`#version 300 es\nprecision highp float;\n\nin vec2 v_uv;\nin vec2 v_nodeCenter;\nin float v_nodeRadius;\nin vec2 v_labelCenter;\nin vec2 v_labelHalfSize;\nin float v_aaWidth;\nin float v_shapeId;\nin float v_nodeRotation;\nin float v_labelAngle;\nin vec4 v_backdropColor;\nin vec4 v_backdropShadowColor;\nin float v_backdropShadowBlur;\nin float v_backdropPadding;\nin vec4 v_backdropBorderColor;\nin float v_backdropBorderWidth;\nin float v_backdropCornerRadius;\nin float v_backdropArea;\n`.concat(bi(a,n,"in"),`\n\nuniform float u_cameraAngle;\n`).concat(i,`\n\nlayout(location = 0) out vec4 fragColor;\nlayout(location = 1) out vec4 fragPicking;\n\n`).concat(r,`\n`).concat(ed,`\n`).concat(td,`\n`).concat(nd,`\n`).concat(ad,`\n\nvoid main() {\n vec4 backdropColor = v_backdropColor;\n vec4 shadowColor = v_backdropShadowColor;\n float shadowBlur = v_backdropShadowBlur;\n float padding = v_backdropPadding;\n vec4 borderColor = v_backdropBorderColor;\n float borderWidth = v_backdropBorderWidth;\n float cornerRadius = v_backdropCornerRadius;\n\n float enlargedRadius = v_nodeRadius + padding;\n vec2 screenUV = v_uv - v_nodeCenter;\n `).concat(u,`\n\n // Query the correct shape SDF based on shapeId\n `).concat(s,`\n float nodeSdfPixels = nodeSdfNormalized * effectiveRadius - cornerRadius;\n\n // Label SDF with optional corner radius and rotation\n float labelSdfPixels;\n if (v_labelHalfSize.x > 0.0) {\n vec2 labelP = v_uv - v_labelCenter;\n labelSdfPixels = sdfRoundedRotatedBox(labelP, v_labelHalfSize, v_labelAngle, cornerRadius);\n } else {\n labelSdfPixels = 10000.0;\n }\n\n // Select area: 0=both, 1=node, 2=label\n float combinedSdf;\n if (v_backdropArea > 1.5) {\n combinedSdf = labelSdfPixels;\n } else if (v_backdropArea > 0.5) {\n combinedSdf = nodeSdfPixels;\n } else {\n combinedSdf = min(nodeSdfPixels, labelSdfPixels);\n }\n\n // Fill + border composite\n float outerEdge = smoothstep(v_aaWidth, -v_aaWidth, combinedSdf);\n vec4 background;\n if (borderWidth > 0.5) {\n float innerEdge = smoothstep(v_aaWidth, -v_aaWidth, combinedSdf + borderWidth);\n float fillAlpha = innerEdge * backdropColor.a;\n vec4 fill = vec4(backdropColor.rgb * fillAlpha, fillAlpha);\n float borderAlpha = (outerEdge - innerEdge) * borderColor.a;\n vec4 border = vec4(borderColor.rgb * borderAlpha, borderAlpha);\n background = fill + border * (1.0 - fill.a);\n } else {\n float fillAlpha = outerEdge * backdropColor.a;\n background = vec4(backdropColor.rgb * fillAlpha, fillAlpha);\n }\n\n // Gaussian-like shadow falloff (mimics canvas shadowBlur)\n vec4 shadow = vec4(0.0);\n float sigma = shadowBlur / 2.5;\n if (sigma > 0.001) {\n float shadowDist = max(0.0, combinedSdf);\n float shadowAlpha = exp(-(shadowDist * shadowDist) / (2.0 * sigma * sigma)) * shadowColor.a;\n shadow = vec4(shadowColor.rgb * shadowAlpha, shadowAlpha);\n }\n\n fragColor = background + shadow * (1.0 - background.a);\n fragPicking = vec4(0.0);\n}\n`);return c}function yd(e){var a=["u_matrix","u_sizeRatio","u_correctionRatio","u_cameraAngle","u_resolution","u_pixelRatio","u_labelMargin","u_zoomLabelSizeRatio","u_labelPixelSnapping","u_nodeDataTexture","u_nodeDataTextureWidth","u_nodeFrameTexture","u_nodeFrameTextureWidth","u_layerAttributeTexture","u_layerAttributeTextureWidth","u_layerAttributeTexelsPerNode"],n=W(qt(e)),t;try{for(n.s();!(t=n.n()).done;){var r=t.value;if(!a.includes(r.name))a.push(r.name)}}catch(i){n.e(i)}finally{n.f()}return a}function xd(e){return{vertexShader:md(e),fragmentShader:bd(e),uniforms:yd(e.shapes)}}function _d(e,a,n,t){var r,i,o=t.label,s=o===void 0?{}:o,{shapes:l,layers:d,getAttributeTexture:u,shapeGlobalIds:c}=t;if(l.length===0)throw Error("createBackdropProgram: at least one shape must be provided in \'shapes\'");var g=(r=s.margin)!==null&&r!==void 0?r:5,h=(i=s.zoomToLabelSizeRatioFunction)!==null&&i!==void 0?i:function(){return 1},p={shapes:l,layers:d,shapeGlobalIds:c},y=xd(p),v=function(f){function b(){var m;ie(this,b);for(var T=arguments.length,_=Array(T),x=0;x<T;x++)_[x]=arguments[x];return m=fe(this,b,[].concat(_)),R(m,"totalBackdropCount",0),R(m,"bufferCapacity",0),m}return ge(b,f),oe(b,[{key:"getDefinition",value:function(){var T=WebGL2RenderingContext,{FLOAT:_,TRIANGLE_STRIP:x}=T;return{VERTICES:4,VERTEX_SHADER_SOURCE:y.vertexShader,FRAGMENT_SHADER_SOURCE:y.fragmentShader,METHOD:x,UNIFORMS:y.uniforms,ATTRIBUTES:[{name:"a_nodeIndex",size:1,type:_},{name:"a_labelWidth",size:1,type:_},{name:"a_labelHeight",size:1,type:_},{name:"a_textHeight",size:1,type:_},{name:"a_positionMode",size:1,type:_},{name:"a_labelAngle",size:1,type:_},{name:"a_backdropColor",size:4,type:_},{name:"a_backdropShadowColor",size:4,type:_},{name:"a_backdropShadowBlur",size:1,type:_},{name:"a_backdropPadding",size:1,type:_},{name:"a_backdropBorderColor",size:4,type:_},{name:"a_backdropExtra",size:4,type:_},{name:"a_labelBoxOffset",size:2,type:_}],CONSTANT_ATTRIBUTES:[{name:"a_quadCorner",size:2,type:_}],CONSTANT_DATA:[[-1,-1],[1,-1],[-1,1],[1,1]]}}},{key:"processBackdrop",value:function(T,_){var x=this.floats,S=this.STRIDE,E=T*S;x[E++]=_.nodeIndex,x[E++]=_.labelWidth,x[E++]=_.labelHeight,x[E++]=_.textHeight,x[E++]=wt[_.position],x[E++]=_.labelAngle,x[E++]=_.backdropColor[0],x[E++]=_.backdropColor[1],x[E++]=_.backdropColor[2],x[E++]=_.backdropColor[3],x[E++]=_.backdropShadowColor[0],x[E++]=_.backdropShadowColor[1],x[E++]=_.backdropShadowColor[2],x[E++]=_.backdropShadowColor[3],x[E++]=_.backdropShadowBlur,x[E++]=_.backdropPadding,x[E++]=_.backdropBorderColor[0],x[E++]=_.backdropBorderColor[1],x[E++]=_.backdropBorderColor[2],x[E++]=_.backdropBorderColor[3],x[E++]=_.backdropBorderWidth,x[E++]=_.backdropCornerRadius,x[E++]=_.backdropLabelPadding,x[E++]=_.backdropArea,x[E++]=_.labelBoxOffset[0],x[E++]=_.labelBoxOffset[1]}},{key:"setUniforms",value:function(T,_){var{gl:x,uniformLocations:S}=_;x.uniformMatrix3fv(S.u_matrix,!1,T.matrix),x.uniform1f(S.u_sizeRatio,T.sizeRatio),x.uniform1f(S.u_correctionRatio,T.correctionRatio),x.uniform1f(S.u_cameraAngle,T.cameraAngle),x.uniform2f(S.u_resolution,T.width*T.pixelRatio,T.height*T.pixelRatio),x.uniform1f(S.u_pixelRatio,T.pixelRatio),x.uniform1f(S.u_labelMargin,b.labelMargin),x.uniform1f(S.u_zoomLabelSizeRatio,1/h(T.zoomRatio)),x.uniform1f(S.u_labelPixelSnapping,T.labelPixelSnapping),x.uniform1i(S.u_nodeDataTexture,T.nodeDataTextureUnit),x.uniform1i(S.u_nodeDataTextureWidth,T.nodeDataTextureWidth),x.uniform1i(S.u_nodeFrameTexture,T.nodeFrameTextureUnit),x.uniform1i(S.u_nodeFrameTextureWidth,T.nodeFrameTextureWidth);var E=u();if(S.u_layerAttributeTexture&&E)E.bind(Qe),x.uniform1i(S.u_layerAttributeTexture,Qe),x.uniform1i(S.u_layerAttributeTextureWidth,E.getTextureWidth()),x.uniform1i(S.u_layerAttributeTexelsPerNode,E.getTexelsPerItem());var D=W(qt(l)),A;try{for(D.s();!(A=D.n()).done;){var L=A.value;this.setTypedUniform(L,_)}}catch(w){D.e(w)}finally{D.f()}}},{key:"hasNothingToRender",value:function(){return this.totalBackdropCount===0}},{key:"drawWebGL",value:function(T,_){var x=_.gl;if(this.totalBackdropCount===0)return;if(!this.isInstanced)x.drawArrays(T,0,this.totalBackdropCount*this.VERTICES);else x.drawArraysInstanced(T,0,this.VERTICES,this.totalBackdropCount)}},{key:"reallocate",value:function(T){if(this.totalBackdropCount=T,T>this.bufferCapacity)this.bufferCapacity=Math.max(T,Math.ceil(this.bufferCapacity*1.5)||10),xe(b,"reallocate",this,3)([this.bufferCapacity])}}])}(st);return R(v,"labelMargin",g),new v(e,a,n)}var yi=function(e){function a(){var n;ie(this,a);for(var t=arguments.length,r=Array(t),i=0;i<t;i++)r[i]=arguments[i];return n=fe(this,a,[].concat(r)),R(n,"totalCharacterCount",0),R(n,"bufferCapacity",0),n}return ge(a,e),oe(a,[{key:"processLabel",value:function(t,r,i){if(i.hidden||!i.text)return 0;var o=i.text,s=o.length;for(var l=0;l<s;l++){var d=o[l];this.processCharacter(r+l,i,d,l)}return s}},{key:"hasNothingToRender",value:function(){return this.totalCharacterCount===0}},{key:"drawWebGL",value:function(t,r){var i=r.gl;if(this.totalCharacterCount===0)return;if(!this.isInstanced)i.drawArrays(t,0,this.totalCharacterCount*this.VERTICES);else i.drawArraysInstanced(t,0,this.VERTICES,this.totalCharacterCount)}},{key:"reallocate",value:function(t){if(this.totalCharacterCount=t,t>this.bufferCapacity)this.bufferCapacity=Math.max(t,Math.ceil(this.bufferCapacity*1.5)||1000),xe(a,"reallocate",this,3)([this.bufferCapacity])}}])}(st);function Td(){var e=`#version 300 es\n\nin float a_nodeIndex;\nin vec4 a_id;\nin vec4 a_color;\nin float a_labelWidth;\nin float a_labelHeight;\nin float a_textHeight;\nin float a_positionMode;\nin float a_labelAngle;\nin float a_padding;\nin vec2 a_quadCorner;\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\nuniform float u_cameraAngle;\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\nuniform float u_labelMargin;\nuniform float u_zoomLabelSizeRatio;\nuniform float u_labelPixelSnapping;\nuniform float u_pickingPadding;\nuniform sampler2D u_nodeDataTexture;\nuniform int u_nodeDataTextureWidth;\nuniform sampler2D u_nodeFrameTexture;\nuniform int u_nodeFrameTextureWidth;\n\nout vec4 v_id;\nout vec4 v_color;\n\n`.concat(Xe,`\n`).concat(ot,`\n`).concat(Lt,`\n`).concat(vi,`\n\nvoid main() {\n int nodeIdx = int(a_nodeIndex);\n\n // Node data: (x, y, size, shapeId).\n vec4 nodeData = readNodeData(u_nodeDataTexture, u_nodeDataTextureWidth, nodeIdx);\n vec2 nodePosition = nodeData.xy;\n float nodeSize = nodeData.z;\n\n // Shape-aware edge distance, read once from the shared frame texture.\n float edgeDist = readFrameTexel(u_nodeFrameTexture, u_nodeFrameTextureWidth, nodeIdx).r;\n\n // Per-node label rotation alignment: 0 = viewport, 1 = label turns with camera.\n float labelRotation = readNodeFlags(u_nodeDataTexture, u_nodeDataTextureWidth, nodeIdx).g;\n\n `).concat(fi,`\n\n float zoomScale = u_zoomLabelSizeRatio;\n float labelW = a_labelWidth * zoomScale * u_pixelRatio;\n float labelH = a_labelHeight * zoomScale * u_pixelRatio;\n float labelMargin = u_labelMargin * zoomScale * u_pixelRatio;\n#ifdef PICKING_MODE\n float padding = u_pickingPadding * u_pixelRatio;\n#else\n float padding = a_padding * u_pixelRatio;\n#endif\n\n if (labelW <= 0.0) {\n gl_Position = vec4(2.0, 0.0, 0.0, 1.0);\n v_id = vec4(0.0);\n v_color = vec4(0.0);\n return;\n }\n\n vec2 labelHalfSize = vec2(labelW * 0.5 + padding, labelH * 0.5 + padding);\n vec2 labelOffset = vec2(0.0);\n\n // Graph-aligned labels add the camera angle so the rect orbits with the text.\n float labelAngle = a_labelAngle - labelRotation * u_cameraAngle;\n float la_c = cos(labelAngle);\n float la_s = sin(labelAngle);\n mat2 labelRotMat = mat2(la_c, -la_s, la_s, la_c);\n\n vec3 nodeClip = u_matrix * vec3(nodePosition, 1.0);\n vec2 nodeScreen = vec2(\n (nodeClip.x + 1.0) * u_resolution.x,\n (1.0 - nodeClip.y) * u_resolution.y\n ) * 0.5;\n vec2 snapDelta = (round(nodeScreen) - nodeScreen) * u_labelPixelSnapping;\n\n if (a_positionMode < 4.0) {\n float labelStart = nodeRadiusPixels * edgeDist + labelMargin;\n float textHalf = a_textHeight * zoomScale * u_pixelRatio * 0.5;\n // Box center uses the text half-size; the padding expands the quad below.\n labelOffset = labelRotMat * labelBoxCenter(a_positionMode, labelStart, vec2(labelW * 0.5, labelH * 0.5), textHalf);\n }\n\n // Rotate the rect with the label so it stays aligned with the (rotated) text.\n vec2 localPos = labelOffset + labelRotMat * (a_quadCorner * labelHalfSize);\n vec2 ndcOffset = (localPos + snapDelta) * 2.0 / u_resolution;\n ndcOffset.y = -ndcOffset.y;\n\n gl_Position = vec4(nodeClip.xy + ndcOffset, 0.0, 1.0);\n v_id = a_id;\n v_color = a_color;\n}\n`);return e}var Sd=`#version 300 es\nprecision highp float;\n\nin vec4 v_id;\nin vec4 v_color;\n\nout vec4 fragColor;\n\nvoid main() {\n #ifdef PICKING_MODE\n fragColor = v_id;\n #else\n if (v_color.a <= 0.0) discard;\n // v_color is non-premultiplied RGBA (0-1); convert to premultiplied for blending\n fragColor = vec4(v_color.rgb * v_color.a, v_color.a);\n #endif\n}\n`;function Ed(e,a,n,t){var r,i,o=t.label,s=o===void 0?{}:o,l=(r=s.margin)!==null&&r!==void 0?r:Dt,d=(i=s.zoomToLabelSizeRatioFunction)!==null&&i!==void 0?i:function(){return 1},u=Td(),c=function(g){function h(){var p;ie(this,h);for(var y=arguments.length,v=Array(y),f=0;f<y;f++)v[f]=arguments[f];return p=fe(this,h,[].concat(v)),R(p,"totalCount",0),R(p,"bufferCapacity",0),p}return ge(h,g),oe(h,[{key:"getDefinition",value:function(){var y=WebGL2RenderingContext,{FLOAT:v,UNSIGNED_BYTE:f,TRIANGLE_STRIP:b}=y;return{VERTICES:4,VERTEX_SHADER_SOURCE:u,FRAGMENT_SHADER_SOURCE:Sd,METHOD:b,UNIFORMS:["u_matrix","u_sizeRatio","u_correctionRatio","u_cameraAngle","u_resolution","u_pixelRatio","u_labelMargin","u_zoomLabelSizeRatio","u_labelPixelSnapping","u_pickingPadding","u_nodeDataTexture","u_nodeDataTextureWidth","u_nodeFrameTexture","u_nodeFrameTextureWidth"],ATTRIBUTES:[{name:"a_nodeIndex",size:1,type:v},{name:"a_id",size:4,type:f,normalized:!0},{name:"a_color",size:4,type:f,normalized:!0},{name:"a_labelWidth",size:1,type:v},{name:"a_labelHeight",size:1,type:v},{name:"a_textHeight",size:1,type:v},{name:"a_positionMode",size:1,type:v},{name:"a_labelAngle",size:1,type:v},{name:"a_padding",size:1,type:v}],CONSTANT_ATTRIBUTES:[{name:"a_quadCorner",size:2,type:v}],CONSTANT_DATA:[[-1,-1],[1,-1],[-1,1],[1,1]]}}},{key:"processLabelBackground",value:function(y,v){var f=this.floats,b=this.ints,m=y*this.STRIDE;f[m++]=v.nodeIndex,b[m++]=v.id,f[m++]=v.color,f[m++]=v.labelWidth,f[m++]=v.labelHeight,f[m++]=v.textHeight,f[m++]=v.positionMode,f[m++]=v.labelAngle,f[m++]=v.padding}},{key:"setUniforms",value:function(y,v){var{gl:f,uniformLocations:b}=v;f.uniformMatrix3fv(b.u_matrix,!1,y.matrix),f.uniform1f(b.u_sizeRatio,y.sizeRatio),f.uniform1f(b.u_correctionRatio,y.correctionRatio),f.uniform1f(b.u_cameraAngle,y.cameraAngle),f.uniform2f(b.u_resolution,y.width*y.pixelRatio,y.height*y.pixelRatio),f.uniform1f(b.u_pixelRatio,y.pixelRatio),f.uniform1f(b.u_labelMargin,h.labelMargin),f.uniform1f(b.u_zoomLabelSizeRatio,1/d(y.zoomRatio)),f.uniform1f(b.u_labelPixelSnapping,y.labelPixelSnapping),f.uniform1f(b.u_pickingPadding,y.labelPickingPadding),f.uniform1i(b.u_nodeDataTexture,y.nodeDataTextureUnit),f.uniform1i(b.u_nodeDataTextureWidth,y.nodeDataTextureWidth),f.uniform1i(b.u_nodeFrameTexture,y.nodeFrameTextureUnit),f.uniform1i(b.u_nodeFrameTextureWidth,y.nodeFrameTextureWidth)}},{key:"hasNothingToRender",value:function(){return this.totalCount===0}},{key:"drawWebGL",value:function(y,v){var f=v.gl;if(this.totalCount===0)return;f.drawArraysInstanced(f.TRIANGLE_STRIP,0,this.VERTICES,this.totalCount)}},{key:"reallocate",value:function(y){if(this.totalCount=y,y>this.bufferCapacity)this.bufferCapacity=Math.max(y,Math.ceil(this.bufferCapacity*1.5)||10),xe(h,"reallocate",this,3)([this.bufferCapacity])}}])}(st);return R(c,"labelMargin",l),new c(e,a,n)}var Be={fontSize:64,buffer:8,radius:24,cutoff:0.25,maxTextureSize:2048,debounceTimeout:100},Ht=2,Vt=100000000000000000000;function Rd(e,a,n,t,r){var i=e+r*4,o=document.createElement("canvas");o.width=i,o.height=i;var s=o.getContext("2d",{willReadFrequently:!0});return s.font="".concat(t," ").concat(n," ").concat(e,"px ").concat(a),s.textBaseline="alphabetic",s.textAlign="left",s.fillStyle="black",{ctx:s,canvasSize:i,gridOuter:new Float64Array(i*i),gridInner:new Float64Array(i*i),f:new Float64Array(i),z:new Float64Array(i+1),v:new Uint16Array(i)}}function Ad(e,a,n,t,r){var{ctx:i,canvasSize:o}=e,s=i.measureText(a),{width:l,actualBoundingBoxAscent:d,actualBoundingBoxDescent:u,actualBoundingBoxLeft:c,actualBoundingBoxRight:g}=s,h=Math.ceil(d),p=Math.ceil(c),y=Math.max(0,Math.min(o-n,Math.ceil(c)+Math.ceil(g))),v=Math.min(o-n,h+Math.ceil(u)),f=y+2*n,b=v+2*n,m=Math.max(f*b,0),T=new Uint8ClampedArray(m),_={data:T,width:f,height:b,glyphWidth:y,glyphHeight:v,glyphTop:h,glyphLeft:p,glyphAdvance:l};if(y===0||v===0)return _;var{gridInner:x,gridOuter:S}=e;i.clearRect(n,n,y,v),i.fillText(a,n+p,n+h);var E=i.getImageData(n,n,y,v);S.fill(Vt,0,m),x.fill(0,0,m);for(var D=0;D<v;D++)for(var A=0;A<y;A++){var L=E.data[4*(D*y+A)+3]/255;if(L===0)continue;var w=(D+n)*f+A+n;if(L===1)S[w]=0,x[w]=Vt;else{var M=0.5-L;S[w]=M>0?M*M:0,x[w]=M<0?M*M:0}}ai(S,0,0,f,b,f,e.f,e.v,e.z),ai(x,n,n,y,v,f,e.f,e.v,e.z);for(var C=0;C<m;C++){var z=Math.sqrt(S[C])-Math.sqrt(x[C]);T[C]=Math.round(255-255*(z/t+r))}return _}function ai(e,a,n,t,r,i,o,s,l){for(var d=a;d<a+t;d++)ri(e,n*i+d,i,r,o,s,l);for(var u=n;u<n+r;u++)ri(e,u*i+a,1,t,o,s,l)}function ri(e,a,n,t,r,i,o){i[0]=0,o[0]=-Vt,o[1]=Vt,r[0]=e[a];for(var s=1,l=0,d=0;s<t;s++){r[s]=e[a+s*n];var u=s*s;do{var c=i[l];d=(r[s]-r[c]+u-c*c)/(s-c)/2}while(d<=o[l]&&--l>-1);l++,i[l]=s,o[l]=d,o[l+1]=Vt}for(var g=0,h=0;g<t;g++){while(o[h+1]<g)h++;var p=i[h],y=g-p;e[a+g*n]=r[p]+y*y}}var it=function(e){function a(){var n,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return ie(this,a),n=fe(this,a),R(n,"fonts",new Map),R(n,"textures",[]),R(n,"cursor",{x:0,y:0,rowHeight:0,atlasIndex:0}),R(n,"pendingGlyphs",[]),R(n,"debounceTimer",null),n.options=V(V({},Be),t),n.canvas=document.createElement("canvas"),n.canvas.width=n.options.maxTextureSize,n.canvas.height=n.options.maxTextureSize,n.ctx=n.canvas.getContext("2d",{willReadFrequently:!0}),n.measureCanvas=document.createElement("canvas"),n.measureCtx=n.measureCanvas.getContext("2d"),n.textures.push(n.ctx.getImageData(0,0,1,1)),n}return ge(a,e),oe(a,[{key:"getFontKey",value:function(t){return"".concat(t.family,"-").concat(t.weight,"-").concat(t.style)}},{key:"registerFont",value:function(t){var r=this.getFontKey(t);if(this.fonts.has(r))return r;var i=Rd(this.options.fontSize,t.family,t.weight,t.style,this.options.buffer);return this.fonts.set(r,{descriptor:t,generator:i,glyphs:new Map}),r}},{key:"ensureGlyphs",value:function(t,r){var i=this.fonts.get(r);if(!i)throw Error(\'Font "\'.concat(r,\'" is not registered. Call registerFont() first.\'));var o=!1,s=W(t),l;try{for(s.s();!(l=s.n()).done;){var d=l.value,u=d.codePointAt(0);if(u===void 0)continue;if(!i.glyphs.has(u))this.pendingGlyphs.push({fontKey:r,charCode:u}),o=!0}}catch(c){s.e(c)}finally{s.f()}if(o)this.scheduleTextureGeneration()}},{key:"measureText",value:function(t,r){var i=this.fonts.get(r);if(!i)throw Error(\'Font "\'.concat(r,\'" is not registered.\'));var o=i.descriptor,{family:s,weight:l,style:d}=o;return this.measureCtx.font="".concat(d," ").concat(l," ").concat(this.options.fontSize,"px ").concat(s),this.measureCtx.measureText(t).width}},{key:"getGlyph",value:function(t,r){var i=this.fonts.get(r);if(!i)return;return i.glyphs.get(t)}},{key:"getTextures",value:function(){return this.textures}},{key:"getFontCount",value:function(){return this.fonts.size}},{key:"getGlyphCount",value:function(){var t=0,r=W(this.fonts.values()),i;try{for(r.s();!(i=r.n()).done;){var o=i.value;t+=o.glyphs.size}}catch(s){r.e(s)}finally{r.f()}return t}},{key:"hasPendingGlyphs",value:function(){return this.pendingGlyphs.length>0}},{key:"flush",value:function(){if(this.debounceTimer)clearTimeout(this.debounceTimer),this.debounceTimer=null;this.generateTextures()}},{key:"destroy",value:function(){if(this.debounceTimer)clearTimeout(this.debounceTimer);this.fonts.clear(),this.textures=[],this.pendingGlyphs=[],this.removeAllListeners()}},{key:"scheduleTextureGeneration",value:function(){var t=this;if(this.debounceTimer!==null)return;if(this.options.debounceTimeout===null)this.generateTextures();else this.debounceTimer=setTimeout(function(){t.debounceTimer=null,t.generateTextures()},this.options.debounceTimeout)}},{key:"generateTextures",value:function(){if(this.pendingGlyphs.length===0)return;var t=this.options,{maxTextureSize:r,buffer:i,radius:o,cutoff:s}=t,l=W(this.pendingGlyphs),d;try{for(l.s();!(d=l.n()).done;){var u=d.value,{fontKey:c,charCode:g}=u,h=this.fonts.get(c);if(!h||h.glyphs.has(g))continue;var p=String.fromCodePoint(g),y=Ad(h.generator,p,i,o,s),{width:v,height:f}=y;if(this.cursor.x+v+Ht>r)this.cursor.x=0,this.cursor.y+=this.cursor.rowHeight+Ht,this.cursor.rowHeight=0;if(this.cursor.y+f+Ht>r)this.finalizeCurrentTexture(),this.cursor={x:0,y:0,rowHeight:0,atlasIndex:this.cursor.atlasIndex+1},this.ctx.clearRect(0,0,r,r);var b=y.data,m=new Uint8ClampedArray(v*f*4);for(var T=0;T<b.length;T++){var _=T*4;m[_]=255,m[_+1]=255,m[_+2]=255,m[_+3]=b[T]}var x=new ImageData(m,v,f);this.ctx.putImageData(x,this.cursor.x,this.cursor.y);var S={charCode:g,width:y.glyphWidth,height:y.glyphHeight,bearingX:-y.glyphLeft-i,bearingY:y.glyphTop+i,advance:y.glyphAdvance,atlasX:this.cursor.x,atlasY:this.cursor.y,atlasWidth:v,atlasHeight:f,atlasIndex:this.cursor.atlasIndex};h.glyphs.set(g,S),this.cursor.x+=v+Ht,this.cursor.rowHeight=Math.max(this.cursor.rowHeight,f)}}catch(E){l.e(E)}finally{l.f()}this.finalizeCurrentTexture(),this.pendingGlyphs=[],this.emit(a.ATLAS_UPDATED_EVENT,{textures:this.textures,glyphCount:this.getGlyphCount()})}},{key:"finalizeCurrentTexture",value:function(){var t=this.options.maxTextureSize,r=this.cursor.y>0||this.cursor.rowHeight>0,i=Math.min(t,Math.max(this.cursor.x,r?t:1)),o=Math.min(t,this.cursor.y+this.cursor.rowHeight+Ht),s=this.ctx.getImageData(0,0,i,o);if(this.cursor.atlasIndex>=this.textures.length)this.textures.push(s);else this.textures[this.cursor.atlasIndex]=s}}])}(De);R(it,"ATLAS_UPDATED_EVENT","atlasUpdated");var wd=Be.fontSize;function Dd(){var e=` // -------------------------------------------------------------------------\n // Step 3: Calculate position offset from the shared edge distance\n // -------------------------------------------------------------------------\n vec2 positionOffset = vec2(0.0);\n\n if (a_positionMode < 4.0) {\n vec2 screenDir = getLabelDirection(a_positionMode);\n float boundaryDistPixels = nodeRadiusPixels * edgeDist;\n positionOffset = screenDir * (boundaryDistPixels + margin);\n }`,a=`#version 300 es\n\n// ============================================================================\n// Attributes\n// ============================================================================\n\n// Per-character (instanced)\nin float a_nodeIndex; // Index into node data texture\nin vec2 a_charOffset; // Character offset from label origin (pixels)\nin vec2 a_charSize; // Character dimensions (pixels)\nin vec4 a_texCoords; // Atlas coords: (x, y, width, height) in pixels\nin vec4 a_color; // Text color (RGBA)\nin float a_margin; // Gap between node edge and label (pixels)\nin float a_positionMode; // Position: 0=right, 1=left, 2=above, 3=below, 4=over\nin float a_labelWidth; // Total label width (pixels)\nin float a_labelHeight; // Label height (pixels)\nin float a_verticalCenter; // Vertical center offset from baseline (pixels)\nin float a_textHeight; // Actual text height: maxAscent + maxDescent (pixels)\nin float a_labelAngle; // Label rotation angle (radians)\n\n// Per-vertex (constant quad corners)\nin vec2 a_quadCorner; // Quad corner: [-1,-1], [1,-1], [-1,1], [1,1]\n\n// ============================================================================\n// Uniforms\n// ============================================================================\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\nuniform float u_cameraAngle;\nuniform vec2 u_resolution;\nuniform vec2 u_atlasSize;\nuniform sampler2D u_nodeDataTexture;\nuniform int u_nodeDataTextureWidth;\nuniform sampler2D u_nodeFrameTexture;\nuniform int u_nodeFrameTextureWidth;\nuniform float u_zoomLabelSizeRatio;\nuniform float u_labelPixelSnapping;\nuniform float u_pixelRatio;\n\n// ============================================================================\n// Varyings\n// ============================================================================\n\nout vec2 v_texCoord;\nout vec4 v_color;\nout float v_fontScale;\n\n// ============================================================================\n// Constants\n// ============================================================================\n\nconst float bias = 255.0 / 254.0;\nconst float ATLAS_FONT_SIZE = `.concat(ve(wd),`;\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n`).concat(Xe,`\n`).concat(ot,`\n`).concat(Lt,`\n`).concat(gi,`\n\n// ============================================================================\n// Main\n// ============================================================================\n\nvoid main() {\n // -------------------------------------------------------------------------\n // Step 0: Fetch node data + shared edge distance from textures\n // -------------------------------------------------------------------------\n // Node-data texture format: vec4(x, y, size, shapeId)\n // 2D texture layout: texCoord = (index % width, index / width)\n int nodeIdx = int(a_nodeIndex);\n vec4 nodeData = readNodeData(u_nodeDataTexture, u_nodeDataTextureWidth, nodeIdx);\n vec2 a_anchorPosition = nodeData.xy;\n float a_nodeSize = nodeData.z;\n\n // Normalized edge distance from the shared frame texture (the frame-pass ran\n // the SDF search once; the label just reads the result).\n float edgeDist = readFrameTexel(u_nodeFrameTexture, u_nodeFrameTextureWidth, nodeIdx).r;\n\n // Per-node label rotation alignment: 0 = viewport, 1 = label turns with camera.\n float labelRotation = readNodeFlags(u_nodeDataTexture, u_nodeDataTextureWidth, nodeIdx).g;\n\n // Apply zoom-dependent label size scaling\n // Positional values are in CSS pixels; multiply by u_pixelRatio to convert to\n // physical pixels, which is what the NDC conversion (/ u_resolution) expects.\n float zoomScale = u_zoomLabelSizeRatio;\n float margin = a_margin * zoomScale * u_pixelRatio;\n vec2 charOffset = a_charOffset * zoomScale * u_pixelRatio;\n vec2 charSize = a_charSize * zoomScale * u_pixelRatio;\n float labelWidth = a_labelWidth * zoomScale * u_pixelRatio;\n float labelHeight = a_labelHeight * zoomScale;\n\n // Font scale: ratio of CSS label size to the base atlas font size.\n // Divided by u_pixelRatio because the atlas is generated at ATLAS_FONT_SIZE * pixelRatio,\n // which cancels out the u_pixelRatio in the fragment shader\'s gamma formula and keeps\n // the anti-aliasing band width consistent across pixel densities.\n v_fontScale = a_labelHeight * zoomScale / (ATLAS_FONT_SIZE * u_pixelRatio);\n\n // -------------------------------------------------------------------------\n // Step 1: Transform node position to clip space\n // -------------------------------------------------------------------------\n vec3 anchorClip = u_matrix * vec3(a_anchorPosition, 1.0);\n\n // -------------------------------------------------------------------------\n // Step 2: Convert node size to screen pixels\n // -------------------------------------------------------------------------\n float matrixScaleX = length(vec2(u_matrix[0][0], u_matrix[1][0]));\n float nodeRadiusGraphSpace = a_nodeSize * u_correctionRatio / u_sizeRatio * 2.0;\n float nodeRadiusNDC = nodeRadiusGraphSpace * matrixScaleX;\n float nodeRadiusPixels = nodeRadiusNDC * u_resolution.x / 2.0;\n\n`).concat(e,`\n\n // -------------------------------------------------------------------------\n // Step 4: Calculate final vertex position\n // -------------------------------------------------------------------------\n vec2 cornerOffset = (a_quadCorner + 1.0) * 0.5;\n vec2 charPixelPos = positionOffset + charOffset + cornerOffset * charSize;\n\n // Apply text alignment based on position mode\n float verticalCenter = a_verticalCenter * zoomScale * u_pixelRatio;\n float textHeight = a_textHeight * zoomScale * u_pixelRatio;\n float baselineToDescent = textHeight / 2.0 - verticalCenter;\n float baselineToAscent = textHeight / 2.0 + verticalCenter;\n\n if (a_positionMode < 0.5) {\n // Right: vertically center\n charPixelPos.y += verticalCenter;\n } else if (a_positionMode < 1.5) {\n // Left: right-align and vertically center\n charPixelPos.x -= labelWidth;\n charPixelPos.y += verticalCenter;\n } else if (a_positionMode < 2.5) {\n // Above: center horizontally, bottom of text at anchor\n charPixelPos.x -= labelWidth * 0.5;\n charPixelPos.y -= baselineToDescent;\n } else if (a_positionMode < 3.5) {\n // Below: center horizontally, top of text at anchor\n charPixelPos.x -= labelWidth * 0.5;\n charPixelPos.y += baselineToAscent;\n } else {\n // Over: center both\n charPixelPos.x -= labelWidth * 0.5;\n charPixelPos.y += verticalCenter;\n }\n\n // Apply label angle rotation. Graph-aligned labels add the camera angle so the\n // whole label orbits the node in lockstep with the frame-pass edge distance.\n float labelAngle = a_labelAngle - labelRotation * u_cameraAngle;\n float la_c = cos(labelAngle);\n float la_s = sin(labelAngle);\n mat2 labelRotMat = mat2(la_c, -la_s, la_s, la_c);\n charPixelPos = labelRotMat * charPixelPos;\n\n // Snap node center to pixel grid so label/backdrop/attachment move as a unit\n vec2 nodeScreen = vec2(\n (anchorClip.x + 1.0) * u_resolution.x,\n (1.0 - anchorClip.y) * u_resolution.y\n ) * 0.5;\n charPixelPos += (round(nodeScreen) - nodeScreen) * u_labelPixelSnapping;\n\n // Convert to NDC (flip Y: screen Y-down -> clip Y-up)\n vec2 ndcOffset = vec2(charPixelPos.x, -charPixelPos.y) * 2.0 / u_resolution;\n gl_Position = vec4(anchorClip.xy + ndcOffset, 0.0, 1.0);\n\n // -------------------------------------------------------------------------\n // Step 5: Texture coordinates\n // -------------------------------------------------------------------------\n v_texCoord = (a_texCoords.xy + cornerOffset * a_texCoords.zw) / u_atlasSize;\n\n // -------------------------------------------------------------------------\n // Step 6: Pass color\n // -------------------------------------------------------------------------\n v_color = a_color;\n v_color.a *= bias;\n}\n`);return a}function Ld(){var e=`#version 300 es\nprecision highp float;\n\nin vec2 v_texCoord;\nin vec4 v_color;\nin float v_fontScale;\n\nuniform sampler2D u_atlas;\nuniform float u_gamma;\nuniform float u_sdfBuffer;\nuniform float u_pixelRatio;\n\n// Fragment output (single target - picking handled via separate pass)\nout vec4 fragColor;\n\nvoid main() {\n #ifdef PICKING_MODE\n // Labels are not pickable - discard all fragments in picking mode\n fragColor = vec4(0.0);\n discard;\n #else\n // Sample SDF value from atlas (high = inside glyph, low = outside)\n float sdfValue = texture(u_atlas, v_texCoord).a;\n\n // Edge threshold: 1.0 - cutoff = 0.75 for default cutoff=0.25\n // This is where the glyph edge is located in the SDF\n float edgeThreshold = 1.0 - u_sdfBuffer;\n\n // Gamma controls the anti-aliasing band width.\n // Scale inversely with font scale so small labels get a wider AA band\n // (smoother) and large labels get a tighter band (sharper).\n float gamma = u_gamma / (u_pixelRatio * v_fontScale);\n\n // Pure gamma-based anti-aliasing using smoothstep\n // The AA band extends from (threshold - gamma) to (threshold + gamma)\n float alpha = smoothstep(edgeThreshold - gamma, edgeThreshold + gamma, sdfValue);\n\n // Premultiplied alpha output for correct blending\n float finalAlpha = v_color.a * alpha;\n fragColor = vec4(v_color.rgb * finalAlpha, finalAlpha);\n #endif\n}\n`;return e}function Cd(){return["u_matrix","u_sizeRatio","u_correctionRatio","u_cameraAngle","u_resolution","u_atlasSize","u_atlas","u_gamma","u_sdfBuffer","u_pixelRatio","u_nodeDataTexture","u_nodeDataTextureWidth","u_nodeFrameTexture","u_nodeFrameTextureWidth","u_zoomLabelSizeRatio","u_labelPixelSnapping"]}function kd(){return{vertexShader:Dd(),fragmentShader:Ld(),uniforms:Cd()}}function Pd(e,a,n,t){var r,i,o=t.label,s=o===void 0?{}:o,l=(r=s.margin)!==null&&r!==void 0?r:Dt,d=(i=s.zoomToLabelSizeRatioFunction)!==null&&i!==void 0?i:function(){return 1},u=kd(),c=function(g){function h(p,y,v){var f,b,m,T;if(ie(this,h),T=fe(this,h,[p,y,v]),R(T,"atlasTexture",null),R(T,"atlasNeedsUpdate",!1),R(T,"labelGlyphCache",new Map),T.atlasFontSize=Be.fontSize*Ut(),T.atlasManager=new it({fontSize:T.atlasFontSize}),T.gamma=0.025,T.sdfBuffer=Be.cutoff,T.atlasTexture=p.createTexture(),!T.atlasTexture)throw Error("NodeLabelProgram: failed to create atlas texture");p.bindTexture(p.TEXTURE_2D,T.atlasTexture),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_S,p.CLAMP_TO_EDGE),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_T,p.CLAMP_TO_EDGE),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MIN_FILTER,p.LINEAR),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MAG_FILTER,p.LINEAR),p.bindTexture(p.TEXTURE_2D,null),T.atlasManager.on(it.ATLAS_UPDATED_EVENT,function(){T.atlasNeedsUpdate=!0});var _={family:((f=s.font)===null||f===void 0?void 0:f.family)||"sans-serif",weight:((b=s.font)===null||b===void 0?void 0:b.weight)||"normal",style:((m=s.font)===null||m===void 0?void 0:m.style)||"normal"};return T.defaultFontKey=T.atlasManager.registerFont(_),T}return ge(h,g),oe(h,[{key:"getDefinition",value:function(){var y=WebGL2RenderingContext,{FLOAT:v,UNSIGNED_BYTE:f,TRIANGLE_STRIP:b}=y;return{VERTICES:4,VERTEX_SHADER_SOURCE:u.vertexShader,FRAGMENT_SHADER_SOURCE:u.fragmentShader,METHOD:b,UNIFORMS:u.uniforms,ATTRIBUTES:[{name:"a_nodeIndex",size:1,type:v},{name:"a_charOffset",size:2,type:v},{name:"a_charSize",size:2,type:v},{name:"a_texCoords",size:4,type:v},{name:"a_color",size:4,type:f,normalized:!0},{name:"a_margin",size:1,type:v},{name:"a_positionMode",size:1,type:v},{name:"a_labelWidth",size:1,type:v},{name:"a_labelHeight",size:1,type:v},{name:"a_verticalCenter",size:1,type:v},{name:"a_textHeight",size:1,type:v},{name:"a_labelAngle",size:1,type:v}],CONSTANT_ATTRIBUTES:[{name:"a_quadCorner",size:2,type:v}],CONSTANT_DATA:[[-1,-1],[1,-1],[-1,1],[1,1]]}}},{key:"prepareLabelGlyphs",value:function(y,v){if(v.hidden||!v.text){this.labelGlyphCache.delete(y);return}var f=v.text,b=v.fontKey||this.defaultFontKey;this.atlasManager.ensureGlyphs(f,b);var m=[],T=[],_=0,x=0,S=0,E=W(f),D;try{for(E.s();!(D=E.n()).done;){var A=D.value,L=A.codePointAt(0);if(L===void 0){m.push(void 0),T.push(_);continue}var w=this.atlasManager.getGlyph(L,b);if(m.push(w),T.push(_),w)_+=w.advance,x=Math.max(x,w.bearingY),S=Math.max(S,w.atlasHeight-w.bearingY)}}catch(M){E.e(M)}finally{E.f()}this.labelGlyphCache.set(y,{glyphs:m,xOffsets:T,totalWidth:_,totalHeight:x+S,verticalCenterOffset:(x-S)/2})}},{key:"processCharacter",value:function(y,v,f,b){var m=this.floats,T=this.STRIDE,_=y*T,x=this.labelGlyphCache.get(v.parentKey);if(!x||!x.glyphs[b]){for(var S=0;S<T;S++)m[_+S]=0;return}var E=x.glyphs[b],D=x.xOffsets[b],A=v.size/this.atlasFontSize,L=Pe(v.color),w=_;m[w++]=v.nodeIndex,m[w++]=(D+E.bearingX)*A,m[w++]=-E.bearingY*A,m[w++]=E.atlasWidth*A,m[w++]=E.atlasHeight*A,m[w++]=E.atlasX,m[w++]=E.atlasY,m[w++]=E.atlasWidth,m[w++]=E.atlasHeight,m[w++]=L,m[w++]=v.margin,m[w++]=wt[v.position],m[w++]=x.totalWidth*A,m[w++]=v.size,m[w++]=x.verticalCenterOffset*A,m[w++]=x.totalHeight*A,m[w++]=v.labelAngle}},{key:"processLabel",value:function(y,v,f){return this.prepareLabelGlyphs(y,f),xe(h,"processLabel",this,3)([y,v,f])}},{key:"updateAtlasTexture",value:function(){if(!this.atlasNeedsUpdate)return;var y=this.normalProgram.gl,v=this.atlasManager.getTextures();if(v.length===0)return;var f=v[0];y.bindTexture(y.TEXTURE_2D,this.atlasTexture),y.texImage2D(y.TEXTURE_2D,0,y.RGBA,f.width,f.height,0,y.RGBA,y.UNSIGNED_BYTE,f.data),y.bindTexture(y.TEXTURE_2D,null),this.atlasNeedsUpdate=!1}},{key:"setUniforms",value:function(y,v){var{gl:f,uniformLocations:b}=v;f.uniformMatrix3fv(b.u_matrix,!1,y.matrix),f.uniform1f(b.u_sizeRatio,y.sizeRatio),f.uniform1f(b.u_correctionRatio,y.correctionRatio),f.uniform1f(b.u_cameraAngle,y.cameraAngle),f.uniform2f(b.u_resolution,y.width*y.pixelRatio,y.height*y.pixelRatio);var m=this.atlasManager.getTextures();if(m.length>0)f.uniform2f(b.u_atlasSize,m[0].width,m[0].height);else f.uniform2f(b.u_atlasSize,1,1);if(f.activeTexture(f.TEXTURE0),f.bindTexture(f.TEXTURE_2D,this.atlasTexture),f.uniform1i(b.u_atlas,0),b.u_nodeDataTexture!==void 0)f.uniform1i(b.u_nodeDataTexture,y.nodeDataTextureUnit);if(b.u_nodeDataTextureWidth!==void 0)f.uniform1i(b.u_nodeDataTextureWidth,y.nodeDataTextureWidth);f.uniform1i(b.u_nodeFrameTexture,y.nodeFrameTextureUnit),f.uniform1i(b.u_nodeFrameTextureWidth,y.nodeFrameTextureWidth),f.uniform1f(b.u_gamma,this.gamma),f.uniform1f(b.u_sdfBuffer,this.sdfBuffer),f.uniform1f(b.u_pixelRatio,y.pixelRatio),f.uniform1f(b.u_zoomLabelSizeRatio,1/h.zoomToLabelSizeRatioFunction(y.zoomRatio)),f.uniform1f(b.u_labelPixelSnapping,y.labelPixelSnapping)}},{key:"renderProgram",value:function(y,v){if(this.updateAtlasTexture(),this.atlasManager.hasPendingGlyphs())this.atlasManager.flush(),this.updateAtlasTexture();xe(h,"renderProgram",this,3)([y,v])}},{key:"registerFont",value:function(y){var v=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"normal",f=arguments.length>2&&arguments[2]!==void 0?arguments[2]:"normal";return this.atlasManager.registerFont({family:y,weight:v,style:f})}},{key:"getAtlasManager",value:function(){return this.atlasManager}},{key:"measureLabel",value:function(y,v,f){var b=f||this.defaultFontKey;if(this.atlasManager.ensureGlyphs(y,b),this.atlasManager.hasPendingGlyphs())this.atlasManager.flush();var m=0,T=0,_=0,x=W(y),S;try{for(x.s();!(S=x.n()).done;){var E=S.value,D=E.codePointAt(0);if(D===void 0)continue;var A=this.atlasManager.getGlyph(D,b);if(A)m+=A.advance,T=Math.max(T,A.bearingY),_=Math.max(_,A.atlasHeight-A.bearingY)}}catch(w){x.e(w)}finally{x.f()}var L=v/this.atlasFontSize;return{width:m*L,height:v,textHeight:(T+_)*L}}},{key:"ensureGlyphsReady",value:function(y,v){var f=v||this.defaultFontKey,b=W(y),m;try{for(b.s();!(m=b.n()).done;){var T=m.value;this.atlasManager.ensureGlyphs(T,f)}}catch(_){b.e(_)}finally{b.f()}this.atlasManager.flush()}},{key:"kill",value:function(){var y=this.normalProgram.gl;if(this.atlasTexture)y.deleteTexture(this.atlasTexture),this.atlasTexture=null;this.atlasManager.destroy(),this.labelGlyphCache.clear(),xe(h,"kill",this,3)([])}}])}(yi);return R(c,"labelMargin",l),R(c,"zoomToLabelSizeRatioFunction",d),new c(e,a,n)}var Fd=`#version 300 es\nprecision highp float;\n\nin float v_edgeDist;\n\n// R32F target: only the .r channel is stored.\nout vec4 fragColor;\n\nvoid main() {\n fragColor = vec4(v_edgeDist, 0.0, 0.0, 0.0);\n}\n`;function Id(e,a,n){var t=Ia(e),r=qt(e).map(function(p){return"uniform ".concat(p.type," ").concat(p.name,";")}).join(`\n`),i=id(e,n),{code:o,multiShape:s}=i,l=Ct(e,a),d=Object.keys(l.specs).map(function(p){return"float v_".concat(p,";")}).join(`\n`),u=At(l,{varPrefix:"nodeAttr",baseTexelExpr:"nodeIdx * u_layerAttributeTexelsPerNode",textureWidthUniform:"u_layerAttributeTextureWidth",textureSamplerUniform:"u_layerAttributeTexture"}),{fetchCode:c,varyingAssignments:g}=u,h=`#version 300 es\nprecision highp float;\n\nuniform float u_cameraAngle;\nuniform sampler2D u_nodeDataTexture;\nuniform int u_nodeDataTextureWidth;\nuniform float u_frameTextureWidth;\nuniform float u_frameTextureHeight;\nuniform sampler2D u_layerAttributeTexture;\nuniform int u_layerAttributeTextureWidth;\nuniform int u_layerAttributeTexelsPerNode;\n`.concat(r,`\n\nin float a_nodeIndex; // node-data texture index (also the target frame texel)\nin float a_positionMode; // 0=right 1=left 2=above 3=below 4=over\nin float a_labelAngle; // intrinsic label angle (radians)\n\nout float v_edgeDist;\n\n// Shape attributes (plain globals: this pass is vertex-only)\n`).concat(d,`\n\n`).concat(Xe,`\n`).concat(ot,`\n`).concat(t,`\n`).concat(o,`\n`).concat(gi,`\n\nvoid main() {\n int nodeIdx = int(a_nodeIndex);\n`).concat(c,`\n`).concat(g,`\n `).concat(s?`// Multi-shape: the shape id lives in the node-data texture\'s .w channel:\n g_shapeId = int(readNodeData(u_nodeDataTexture, u_nodeDataTextureWidth, nodeIdx).w);`:"// Single-shape mode, shape id not needed",`\n\n // Per-node rotation alignment (0 = viewport, 1 = graph).\n vec4 nodeFlags = readNodeFlags(u_nodeDataTexture, u_nodeDataTextureWidth, nodeIdx);\n float nodeRotation = nodeFlags.r;\n float labelRotation = nodeFlags.g;\n\n // Effective angle: intrinsic (style-given) plus the camera angle when the label\n // is graph-aligned. The companions place the box at this same angle.\n float effectiveAngle = a_labelAngle - labelRotation * u_cameraAngle;\n\n // The "over" mode (4) sits on the node center, so it has no edge distance.\n float edgeDist = 0.0;\n if (a_positionMode < 4.0) {\n vec2 screenDir = getLabelDirection(a_positionMode);\n // Rotate by the effective label angle. Inlined rather than via rotate2D()\n // because the shape SDFs (getShapeGLSLForShapes) already define that helper\n // for multi-shape programs, and redefining it would be a GLSL error.\n float ea_c = cos(effectiveAngle);\n float ea_s = sin(effectiveAngle);\n vec2 rotatedScreenDir = mat2(ea_c, -ea_s, ea_s, ea_c) * screenDir;\n // Screen (Y-down) -> SDF (Y-up).\n vec2 sdfDir = vec2(rotatedScreenDir.x, -rotatedScreenDir.y);\n // Counter-rotate into the shape\'s local frame for graph-aligned nodes, so the\n // boundary is queried against the shape\'s actual on-screen orientation.\n float nodeCa = -u_cameraAngle * nodeRotation;\n float nc = cos(nodeCa), ns = sin(nodeCa);\n sdfDir = mat2(nc, -ns, ns, nc) * sdfDir;\n edgeDist = findEdgeDistance(sdfDir, 1.0);\n }\n v_edgeDist = edgeDist;\n\n // Scatter to this node\'s texel center in the frame texture.\n float x = mod(a_nodeIndex, u_frameTextureWidth);\n float y = floor(a_nodeIndex / u_frameTextureWidth);\n vec2 ndc = (vec2(x, y) + 0.5) / vec2(u_frameTextureWidth, u_frameTextureHeight) * 2.0 - 1.0;\n gl_Position = vec4(ndc, 0.0, 1.0);\n gl_PointSize = 1.0;\n}\n`);return h}var xi=function(){function e(a,n){ie(this,e),R(this,"uniformLocations",{});var{shapes:t,layers:r,shapeGlobalIds:i}=n;if(t.length===0)throw Error("NodeLabelFramePass: at least one shape must be provided");this.gl=a,this.shapeUniforms=qt(t),this.hasAttributeData=Object.keys(Ct(t,r).offsets).length>0,this.vertexShader=ka(a,Id(t,r,i)),this.fragmentShader=Pa(a,Fd),this.program=Fa(a,[this.vertexShader,this.fragmentShader]);var o=["u_cameraAngle","u_nodeDataTexture","u_nodeDataTextureWidth","u_frameTextureWidth","u_frameTextureHeight","u_layerAttributeTexture","u_layerAttributeTextureWidth","u_layerAttributeTexelsPerNode"].concat(J(this.shapeUniforms.map(function(f){return f.name}))),s=W(o),l;try{for(s.s();!(l=s.n()).done;){var d=l.value;this.uniformLocations[d]=a.getUniformLocation(this.program,d)}}catch(f){s.e(f)}finally{s.f()}var u=e.FLOATS_PER_POINT*4;this.vao=a.createVertexArray(),this.buffer=a.createBuffer(),a.bindVertexArray(this.vao),a.bindBuffer(a.ARRAY_BUFFER,this.buffer);var c=W([["a_nodeIndex",0],["a_positionMode",4],["a_labelAngle",8]]),g;try{for(c.s();!(g=c.n()).done;){var h=le(g.value,2),p=h[0],y=h[1],v=a.getAttribLocation(this.program,p);if(v>=0)a.enableVertexAttribArray(v),a.vertexAttribPointer(v,1,a.FLOAT,!1,u,y)}}catch(f){c.e(f)}finally{c.f()}a.bindVertexArray(null)}return oe(e,[{key:"run",value:function(n,t,r,i,o){if(t===0)return;var s=this.gl;s.useProgram(this.program),s.bindVertexArray(this.vao),s.bindBuffer(s.ARRAY_BUFFER,this.buffer),s.bufferData(s.ARRAY_BUFFER,n.subarray(0,t*e.FLOATS_PER_POINT),s.DYNAMIC_DRAW);var l=this.uniformLocations;if(s.uniform1f(l.u_cameraAngle,i.cameraAngle),s.uniform1i(l.u_nodeDataTexture,i.nodeDataTextureUnit),s.uniform1i(l.u_nodeDataTextureWidth,i.nodeDataTextureWidth),s.uniform1f(l.u_frameTextureWidth,r.getTextureWidth()),s.uniform1f(l.u_frameTextureHeight,r.getTextureHeight()),this.hasAttributeData&&o){if(o.bind(Qe),l.u_layerAttributeTexture)s.uniform1i(l.u_layerAttributeTexture,Qe);if(l.u_layerAttributeTextureWidth)s.uniform1i(l.u_layerAttributeTextureWidth,o.getTextureWidth());if(l.u_layerAttributeTexelsPerNode)s.uniform1i(l.u_layerAttributeTexelsPerNode,o.getTexelsPerItem())}var d=W(this.shapeUniforms),u;try{for(d.s();!(u=d.n()).done;){var c=u.value;Na(s,this.uniformLocations[c.name],c)}}catch(g){d.e(g)}finally{d.f()}r.bindAsRenderTarget(),s.disable(s.BLEND),s.disable(s.DEPTH_TEST),s.drawArrays(s.POINTS,0,t),s.bindFramebuffer(s.FRAMEBUFFER,null),s.bindVertexArray(null)}},{key:"kill",value:function(){var n=this.gl;n.deleteProgram(this.program),n.deleteShader(this.vertexShader),n.deleteShader(this.fragmentShader),n.deleteBuffer(this.buffer),n.deleteVertexArray(this.vao)}}])}();R(xi,"FLOATS_PER_POINT",3);function _i(e,a,n,t,r){var i,o=t.label,s=o===void 0?{}:o,l=t.shapes;if(l.length===0)throw Error("createNodeProgram: at least one shape must be provided in \'shapes\'");var d={},u=[],c;l.forEach(function(S,E){var D=Kl(S);if(E===0)c=D;d[S.name]=E,u[E]=jt(D)});var g=J(t.layers),h=ni({shapes:l,layers:g,shapeGlobalIds:l.length>1?u:void 0,antialias:r}),p=Pd(e,null,n,{label:s}),y=_d(e,null,n,{shapes:l,layers:g,getAttributeTexture:function(){return x.getAttributeTexture()},label:s,shapeGlobalIds:l.length>1?u:void 0}),v=Ed(e,a,n,{label:s}),f=t.labelAttachments&&Object.keys(t.labelAttachments).length>0?hd(e,null,n,{label:s}):null,b=new xi(e,{shapes:l,layers:g,shapeGlobalIds:l.length>1?u:void 0}),m=On(l,g),T=Me(m),_=(i=function(S){function E(D,A,L){var w;ie(this,E),w=fe(this,E,[D,A,L]),R(w,"layerLifecycles",new Map),R(w,"layersNeedingRegeneration",new Set),R(w,"attrDescriptors",[]),w._pickingBuffer=A;var M=_.layerTextures.get(D);if(!M)M=new zn(D,T),_.layerTextures.set(D,M);w.layerAttributeTexture=M;var C=_.textureRefCounts.get(D)||0;_.textureRefCounts.set(D,C+1),w.packedAttributeData=new Float32Array(T.floatsPerItem),g.forEach(function(O,N){if(O.lifecycle){var F={gl:D,renderer:{refresh:function(){return L.refresh()}},getUniformLocation:function(Y){return D.getUniformLocation(w.normalProgram.program,Y)},requestShaderRegeneration:function(){w.layersNeedingRegeneration.add(N)},requestRefresh:function(){L.refresh()}},P=O.lifecycle(F);w.layerLifecycles.set(N,P)}}),w.layerLifecycles.forEach(function(O){var N;(N=O.init)===null||N===void 0||N.call(O)});var z=new Map;return w.layerLifecycles.forEach(function(O,N){if(O.getAttributeData)z.set(N,O)}),w.attrDescriptors=Nn(m,T,z),w}return ge(E,S),oe(E,[{key:"getDefinition",value:function(){var A=WebGL2RenderingContext,{FLOAT:L,TRIANGLE_STRIP:w}=A;return{VERTICES:4,VERTEX_SHADER_SOURCE:h.vertexShader,FRAGMENT_SHADER_SOURCE:h.fragmentShader,METHOD:w,UNIFORMS:h.uniforms,ATTRIBUTES:h.attributes,CONSTANT_ATTRIBUTES:[{name:"a_quadCorner",size:2,type:L}],CONSTANT_DATA:[[-1,-1],[1,-1],[-1,1],[1,1]]}}},{key:"maybeRegenerateShaders",value:function(){var A=this;if(this.layersNeedingRegeneration.size===0)return;g=g.map(function(N,F){if(A.layersNeedingRegeneration.has(F)){var P=A.layerLifecycles.get(F);if(P!==null&&P!==void 0&&P.regenerate){var B=P.regenerate();return V(V({},B),{},{lifecycle:N.lifecycle})}}return N}),this.layersNeedingRegeneration.clear(),h=ni({shapes:l,layers:g,shapeGlobalIds:l.length>1?u:void 0,antialias:this.renderer.getSetting("antialiasNodes")});var L=this.normalProgram.gl,w=this.normalProgram,{program:M,buffer:C,vertexShader:z,fragmentShader:O}=w;L.deleteProgram(M),L.deleteBuffer(C),L.deleteShader(z),L.deleteShader(O),this.normalProgram=this.getProgramInfo("normal",L,h.vertexShader,h.fragmentShader,this._pickingBuffer)}},{key:"getAttributeTexture",value:function(){return this.layerAttributeTexture}},{key:"uploadLayerTexture",value:function(){this.layerAttributeTexture.upload()}},{key:"process",value:function(A,L,w,M){var C=L*this.STRIDE;if(w.visibility==="hidden"){for(var z=C+this.STRIDE;C<z;C++)this.floats[C]=0;this.floats[L*this.STRIDE]=pi;return}this.processVisibleItem(_t(A),C,w,M)}},{key:"processVisibleItem",value:function(A,L,w,M){var C,z=this.floats,O=this.ints;if(z[L++]=M,O[L++]=A,z[L++]=(C=w.opacity)!==null&&C!==void 0?C:1,T.floatsPerItem===0)return;var N=this.packedAttributeData;Gn(this.attrDescriptors,w,N,w.color,this.layerLifecycles,0),this.layerAttributeTexture.updateAllAttributesAtRow(M,N)}},{key:"setUniforms",value:function(A,L){var w=this,{gl:M,uniformLocations:C}=L;if(C.u_matrix)M.uniformMatrix3fv(C.u_matrix,!1,A.matrix);if(C.u_sizeRatio)M.uniform1f(C.u_sizeRatio,A.sizeRatio);if(C.u_correctionRatio)M.uniform1f(C.u_correctionRatio,A.correctionRatio);if(C.u_pickingPadding)M.uniform1f(C.u_pickingPadding,A.nodePickingPadding);if(C.u_cameraAngle)M.uniform1f(C.u_cameraAngle,A.cameraAngle);if(C.u_nodeDataTexture)M.uniform1i(C.u_nodeDataTexture,A.nodeDataTextureUnit);if(C.u_nodeDataTextureWidth)M.uniform1i(C.u_nodeDataTextureWidth,A.nodeDataTextureWidth);if(C.u_layerAttributeTexture)this.layerAttributeTexture.bind(Qe),M.uniform1i(C.u_layerAttributeTexture,Qe);if(C.u_layerAttributeTextureWidth)M.uniform1i(C.u_layerAttributeTextureWidth,this.layerAttributeTexture.getTextureWidth());if(C.u_layerAttributeTexelsPerNode)M.uniform1i(C.u_layerAttributeTexelsPerNode,this.layerAttributeTexture.getTexelsPerItem());l.forEach(function(z){z.uniforms.forEach(function(O){w.setTypedUniform(O,L)})}),g.forEach(function(z){z.uniforms.forEach(function(O){w.setTypedUniform(O,L)})})}},{key:"render",value:function(A,L,w){this.maybeRegenerateShaders(),xe(E,"render",this,3)([A,L,w])}},{key:"renderProgram",value:function(A,L){var{gl:w,program:M}=L;if(w.useProgram(M),L===this.normalProgram)this.layerLifecycles.forEach(function(C){var z;(z=C.beforeRender)===null||z===void 0||z.call(C)});xe(E,"renderProgram",this,3)([A,L])}},{key:"kill",value:function(){this.layerLifecycles.forEach(function(w){var M;(M=w.kill)===null||M===void 0||M.call(w)}),this.layerLifecycles.clear();var A=this.normalProgram.gl,L=(_.textureRefCounts.get(A)||1)-1;if(L<=0)this.layerAttributeTexture.kill(),_.layerTextures.delete(A),_.textureRefCounts.delete(A);else _.textureRefCounts.set(A,L);xe(E,"kill",this,3)([])}}])}(st),R(i,"layerTextures",new WeakMap),R(i,"textureRefCounts",new WeakMap),i),x=new _(e,null,n);return{nodeProgram:x,labelProgram:p,backdropProgram:y,labelBackgroundProgram:v,attachmentProgram:f,framePass:b,shapeSlug:c,shapeNameToIndex:l.length>1?d:void 0,shapeGlobalIds:l.length>1?u:void 0}}var Je=6;function Kt(e){var{offsets:a,specs:n,floatsPerItem:t}=e,r=Object.keys(a);if(r.length===0||t===0)return{uniformDeclarations:"",uniformNames:[],vertexVaryingDeclarations:"",fragmentVaryingDeclarations:"",fetchCode:"",varyingAssignments:""};var i=`\nuniform sampler2D u_edgeAttributeTexture;\nuniform int u_edgeAttributeTextureWidth;\nuniform int u_edgeAttributeTexelsPerEdge;`,o=["u_edgeAttributeTexture","u_edgeAttributeTextureWidth","u_edgeAttributeTexelsPerEdge"],s=r.map(function(h){var p=n[h].size===1?"float":"vec".concat(n[h].size);return"".concat(p," v_").concat(h,";")}),l=s.map(function(h){return"out ".concat(h)}).join(`\n`),d=s.map(function(h){return"in ".concat(h)}).join(`\n`),u=At(e,{varPrefix:"attr",baseTexelExpr:"edgeIdx * u_edgeAttributeTexelsPerEdge",textureWidthUniform:"u_edgeAttributeTextureWidth",textureSamplerUniform:"u_edgeAttributeTexture"}),{fetchCode:c,varyingAssignments:g}=u;return{uniformDeclarations:i,uniformNames:o,vertexVaryingDeclarations:l,fragmentVaryingDeclarations:d,fetchCode:c,varyingAssignments:g}}function Md(e){return`\nfloat findSourceClampT_`.concat(e,`(vec2 source, float sourceSize, int sourceShapeId, float sourceRotateAlign, vec2 target, float margin) {\n float lo = 0.0, hi = 0.5;\n float nodeExtent = sourceSize * u_correctionRatio / u_sizeRatio * 2.0;\n float effectiveSize = 1.0 - u_correctionRatio / nodeExtent;\n\n // Counter-rotate the query point so viewport-aligned nodes (rotateAlign=0) are\n // clamped against their on-screen orientation; graph-aligned nodes skip it.\n float ca = u_cameraAngle * (1.0 - sourceRotateAlign);\n float rc = cos(ca), rs = sin(ca);\n mat2 rot = mat2(rc, -rs, rs, rc);\n\n for (int i = 0; i < 12; i++) {\n float mid = (lo + hi) * 0.5;\n vec2 pos = path_`).concat(e,`_position(mid, source, target);\n vec2 localPos = rot * ((pos - source) / nodeExtent);\n float sdf = querySDF(sourceShapeId, localPos, effectiveSize);\n if (sdf < 0.0) lo = mid;\n else hi = mid;\n }\n\n float pathLen = path_`).concat(e,`_length(source, target);\n float marginT = (margin * u_correctionRatio / u_sizeRatio) / pathLen;\n return (lo + hi) * 0.5 + marginT;\n}\n`)}function zd(e){return`\nfloat findTargetClampT_`.concat(e,`(vec2 source, vec2 target, float targetSize, int targetShapeId, float targetRotateAlign, float margin) {\n float lo = 0.5, hi = 1.0;\n float nodeExtent = targetSize * u_correctionRatio / u_sizeRatio * 2.0;\n float effectiveSize = 1.0 - u_correctionRatio / nodeExtent;\n\n // See findSourceClampT_ for the rotation rationale.\n float ca = u_cameraAngle * (1.0 - targetRotateAlign);\n float rc = cos(ca), rs = sin(ca);\n mat2 rot = mat2(rc, -rs, rs, rc);\n\n for (int i = 0; i < 12; i++) {\n float mid = (lo + hi) * 0.5;\n vec2 pos = path_`).concat(e,`_position(mid, source, target);\n vec2 localPos = rot * ((pos - target) / nodeExtent);\n float sdf = querySDF(targetShapeId, localPos, effectiveSize);\n if (sdf < 0.0) hi = mid;\n else lo = mid;\n }\n\n float pathLen = path_`).concat(e,`_length(source, target);\n float marginT = (margin * u_correctionRatio / u_sizeRatio) / pathLen;\n return (lo + hi) * 0.5 - marginT;\n}\n`)}function Ti(e){return`\n// Auto-generated numerical tangent (from position via finite differences)\nvec2 path_`.concat(e,`_tangent(float t, vec2 source, vec2 target) {\n float epsilon = 0.001;\n float t1 = max(0.0, t - epsilon);\n float t2 = min(1.0, t + epsilon);\n vec2 p1 = path_`).concat(e,`_position(t1, source, target);\n vec2 p2 = path_`).concat(e,`_position(t2, source, target);\n return normalize(p2 - p1);\n}\n\n// Auto-generated normal (perpendicular to tangent)\nvec2 path_`).concat(e,`_normal(float t, vec2 source, vec2 target) {\n vec2 tangent = path_`).concat(e,`_tangent(t, source, target);\n return vec2(-tangent.y, tangent.x);\n}\n`)}function Nd(e){return`\n// Auto-generated path length (samples position 16 times)\nfloat path_`.concat(e,`_length(vec2 source, vec2 target) {\n float len = 0.0;\n vec2 prev = path_`).concat(e,`_position(0.0, source, target);\n for (int i = 1; i <= 16; i++) {\n float t = float(i) / 16.0;\n vec2 curr = path_`).concat(e,`_position(t, source, target);\n len += length(curr - prev);\n prev = curr;\n }\n return len;\n}\n`)}function Gd(e){return`\n// Auto-generated closest_t (coarse sample + ternary search)\nfloat path_`.concat(e,`_closest_t(vec2 p, vec2 source, vec2 target) {\n // Coarse search: find best among 10 samples\n float bestT = 0.0;\n float bestDist = 1e10;\n for (int i = 0; i <= 10; i++) {\n float t = float(i) / 10.0;\n vec2 pos = path_`).concat(e,`_position(t, source, target);\n float d = length(p - pos);\n if (d < bestDist) {\n bestDist = d;\n bestT = t;\n }\n }\n\n // Refine with ternary search\n float lo = max(0.0, bestT - 0.1);\n float hi = min(1.0, bestT + 0.1);\n for (int i = 0; i < 10; i++) {\n float mid1 = lo + (hi - lo) / 3.0;\n float mid2 = hi - (hi - lo) / 3.0;\n float d1 = length(p - path_`).concat(e,`_position(mid1, source, target));\n float d2 = length(p - path_`).concat(e,`_position(mid2, source, target));\n if (d1 < d2) {\n hi = mid2;\n } else {\n lo = mid1;\n }\n }\n return (lo + hi) * 0.5;\n}\n`)}function Od(e){return`\n// Auto-generated signed distance (via closest_t + normal)\nfloat path_`.concat(e,`_distance(vec2 p, vec2 source, vec2 target) {\n float closestT = path_`).concat(e,`_closest_t(p, source, target);\n vec2 closest = path_`).concat(e,`_position(closestT, source, target);\n vec2 diff = p - closest;\n float dist = length(diff);\n if (dist < 0.0001) return 0.0;\n\n // Get normal at closest point\n vec2 normal = path_`).concat(e,`_normal(closestT, source, target);\n return dist * sign(dot(diff, normal));\n}\n`)}function Bd(e){return`\n// Auto-generated t_at_distance (binary search)\nfloat path_`.concat(e,`_t_at_distance(float targetDist, vec2 source, vec2 target) {\n if (targetDist <= 0.0) return 0.0;\n\n float totalLen = path_`).concat(e,`_length(source, target);\n if (targetDist >= totalLen) return 1.0;\n\n // Binary search for t\n float lo = 0.0, hi = 1.0;\n for (int i = 0; i < 12; i++) {\n float mid = (lo + hi) * 0.5;\n\n // Compute arc length from 0 to mid\n float arcLen = 0.0;\n vec2 prev = path_`).concat(e,`_position(0.0, source, target);\n for (int j = 1; j <= 8; j++) {\n float t = mid * float(j) / 8.0;\n vec2 curr = path_`).concat(e,`_position(t, source, target);\n arcLen += length(curr - prev);\n prev = curr;\n }\n\n if (arcLen < targetDist) {\n lo = mid;\n } else {\n hi = mid;\n }\n }\n return (lo + hi) * 0.5;\n}\n`)}function Ln(e,a){var n=new RegExp("\\\\b(float|vec[234]|void|int|bool)\\\\s+".concat(a,"\\\\s*\\\\("));return n.test(e)}function Si(e,a){var n=[];if(!Ln(a,"path_".concat(e,"_length")))n.push(Nd(e));if(!Ln(a,"path_".concat(e,"_closest_t")))n.push(Gd(e));if(!Ln(a,"path_".concat(e,"_distance")))n.push(Od(e));if(!Ln(a,"path_".concat(e,"_t_at_distance")))n.push(Bd(e));if(n.length>0)return`\n// ============================================================================\n// Auto-generated fallback functions (path only provided position)\n// ============================================================================\n`.concat(n.join(`\n`));return""}function Ei(e){var a,n,t,{paths:r,layers:i}=e,o=(a=e.extremities)!==null&&a!==void 0?a:[];if(r.length===0)throw Error("At least one path is required in \'paths\'");if(i.length===0)throw Error("At least one layer is required in \'layers\'");var s=(n=e.defaultHead)!==null&&n!==void 0?n:"none",l=(t=e.defaultTail)!==null&&t!==void 0?t:"none";return{paths:r,extremities:o,layers:i,path:r[0],layer:i[0],defaultHead:s,defaultTail:l}}var Ri=WebGL2RenderingContext,{FLOAT:Xt,UNSIGNED_BYTE:ii}=Ri;function Wd(e,a,n){var t=new Set(["u_matrix","u_sizeRatio","u_correctionRatio","u_zoomRatio","u_pixelRatio","u_cameraAngle","u_minEdgeThickness","u_pickingPadding","u_nodeDataTexture","u_nodeDataTextureWidth","u_edgeDataTexture","u_edgeDataTextureWidth","u_edgeFrameTexture","u_edgeFrameTextureWidth","u_edgeAttributeTexture","u_edgeAttributeTextureWidth","u_edgeAttributeTexelsPerEdge"]),r=new Set(t);return e.forEach(function(i){return i.uniforms.forEach(function(o){return r.add(o.name)})}),a.forEach(function(i){return i.uniforms.forEach(function(o){return r.add(o.name)})}),n.forEach(function(i){return i.uniforms.forEach(function(o){return r.add(o.name)})}),Array.from(r)}function Ga(e){var a=new Set,n=[],t=W(e),r;try{for(t.s();!(r=t.n()).done;){var i=r.value;if(!a.has(i.name))a.add(i.name),n.push("// Path: ".concat(i.name)),n.push(i.glsl),n.push(Ti(i.name)),n.push(Si(i.name,i.glsl))}}catch(o){t.e(o)}finally{t.f()}return n.join(`\n\n`)}function Ud(e){var a=[],n=W(e),t;try{for(n.s();!(t=n.n()).done;){var r=t.value;a.push("// Extremity: ".concat(r.name)),a.push(r.glsl)}}catch(i){n.e(i)}finally{n.f()}return a.join(`\n\n`)}var Hd=[{queryName:"queryPathPosition",pathFunc:"position",returnType:"vec2",params:"float t, vec2 source, vec2 target",args:"t, source, target"},{queryName:"queryPathTangent",pathFunc:"tangent",returnType:"vec2",params:"float t, vec2 source, vec2 target",args:"t, source, target"},{queryName:"queryPathNormal",pathFunc:"normal",returnType:"vec2",params:"float t, vec2 source, vec2 target",args:"t, source, target"},{queryName:"queryPathLength",pathFunc:"length",returnType:"float",params:"vec2 source, vec2 target",args:"source, target"},{queryName:"queryPathClosestT",pathFunc:"closest_t",returnType:"float",params:"vec2 p, vec2 source, vec2 target",args:"p, source, target"}];function $d(e,a){var{queryName:n,pathFunc:t,returnType:r,params:i,args:o}=a;if(e.length===1)return"".concat(r," ").concat(n,"(int pathId, ").concat(i,`) {\n return path_`).concat(e[0].name,"_").concat(t,"(").concat(o,`);\n}`);var s=e.map(function(l,d){return" case ".concat(d,": return path_").concat(l.name,"_").concat(t,"(").concat(o,");")}).join(`\n`);return"".concat(r," ").concat(n,"(int pathId, ").concat(i,`) {\n switch (pathId) {\n`).concat(s,`\n default: return path_`).concat(e[0].name,"_").concat(t,"(").concat(o,`);\n }\n}`)}function Oa(e){return Hd.map(function(a){return $d(e,a)}).join(`\n\n`)}function Vd(e){if(e.length===1)return`float queryExtremitySDF(int extremityId, vec2 uv, float lengthRatio, float widthRatio) {\n return extremity_`.concat(e[0].name,`(uv, lengthRatio, widthRatio);\n}`);var a=e.map(function(n,t){return" case ".concat(t,": return extremity_").concat(n.name,"(uv, lengthRatio, widthRatio);")}).join(`\n`);return`float queryExtremitySDF(int extremityId, vec2 uv, float lengthRatio, float widthRatio) {\n switch (extremityId) {\n`.concat(a,`\n default: return extremity_`).concat(e[0].name,`(uv, lengthRatio, widthRatio);\n }\n}`)}function Xd(e){var a=[],n=W(e),t;try{for(n.s();!(t=n.n()).done;){var r=t.value;a.push(Md(r.name)),a.push(zd(r.name))}}catch(s){n.e(s)}finally{n.f()}if(e.length===1)a.push(`\nfloat queryFindSourceClampT(int pathId, vec2 source, float sourceSize, int sourceShapeId, float sourceRotateAlign, vec2 target, float margin) {\n return findSourceClampT_`.concat(e[0].name,`(source, sourceSize, sourceShapeId, sourceRotateAlign, target, margin);\n}\n\nfloat queryFindTargetClampT(int pathId, vec2 source, vec2 target, float targetSize, int targetShapeId, float targetRotateAlign, float margin) {\n return findTargetClampT_`).concat(e[0].name,`(source, target, targetSize, targetShapeId, targetRotateAlign, margin);\n}`));else{var i=e.map(function(s,l){return" case ".concat(l,": return findSourceClampT_").concat(s.name,"(source, sourceSize, sourceShapeId, sourceRotateAlign, target, margin);")}).join(`\n`),o=e.map(function(s,l){return" case ".concat(l,": return findTargetClampT_").concat(s.name,"(source, target, targetSize, targetShapeId, targetRotateAlign, margin);")}).join(`\n`);a.push(`\nfloat queryFindSourceClampT(int pathId, vec2 source, float sourceSize, int sourceShapeId, float sourceRotateAlign, vec2 target, float margin) {\n switch (pathId) {\n`.concat(i,`\n default: return findSourceClampT_`).concat(e[0].name,`(source, sourceSize, sourceShapeId, sourceRotateAlign, target, margin);\n }\n}\n\nfloat queryFindTargetClampT(int pathId, vec2 source, vec2 target, float targetSize, int targetShapeId, float targetRotateAlign, float margin) {\n switch (pathId) {\n`).concat(o,`\n default: return findTargetClampT_`).concat(e[0].name,`(source, target, targetSize, targetShapeId, targetRotateAlign, margin);\n }\n}`))}return a.join(`\n\n`)}function jd(e,a,n,t,r){var i=Me([].concat(J(e),J(n))),o=Kt(i),s=Ct(t,r),l=Object.keys(s.offsets),d=function(S){var E=s.specs[S].size;return E===1?"float":"vec".concat(E)},u=l.map(function(x){return"".concat(d(x)," v_source_").concat(x,`;\n`).concat(d(x)," v_target_").concat(x,";")}).join(`\n`),c=At(s,{varPrefix:"srcNodeAttr",baseTexelExpr:"srcIdx * u_layerAttributeTexelsPerNode",textureWidthUniform:"u_layerAttributeTextureWidth",textureSamplerUniform:"u_layerAttributeTexture",outputPrefix:"v_source_"}),g=At(s,{varPrefix:"tgtNodeAttr",baseTexelExpr:"tgtIdx * u_layerAttributeTexelsPerNode",textureWidthUniform:"u_layerAttributeTextureWidth",textureSamplerUniform:"u_layerAttributeTexture",outputPrefix:"v_target_"}),h=l.map(function(x){return"".concat(d(x)," g_").concat(x,";")}).join(`\n`),p=l.map(function(x){return" g_".concat(x," = v_source_").concat(x,";")}).join(`\n`),y=l.map(function(x){return" g_".concat(x," = v_target_").concat(x,";")}).join(`\n`),v=new Set,f=[],b=function(S){if(!v.has(S.name))v.add(S.name),f.push("uniform ".concat(S.type," ").concat(S.name,";"))};e.forEach(function(x){return x.uniforms.forEach(b)}),a.forEach(function(x){return x.uniforms.forEach(b)});var m=a.map(function(x){return ve(x.widthFactor)}).join(", "),T=Math.max.apply(Math,J(e.map(function(x){return x.minBodyLengthRatio||0}))),_=`#version 300 es\n\n// Node and edge data textures\nuniform sampler2D u_nodeDataTexture;\nuniform int u_nodeDataTextureWidth;\nuniform sampler2D u_edgeDataTexture;\nuniform int u_edgeDataTextureWidth;\n\n// Edge attribute texture (for path-specific attributes like curvature)\n`.concat(o.uniformDeclarations,`\n\n// Node attribute texture (for node shape attributes)\nuniform sampler2D u_layerAttributeTexture;\nuniform int u_layerAttributeTextureWidth;\nuniform int u_layerAttributeTexelsPerNode;\n\n// Render params needed for clamping\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\nuniform float u_cameraAngle;\nuniform float u_minEdgeThickness;\n\n// Edge-frame texture dimensions, for scattering each point to its texel\nuniform float u_frameTextureWidth;\nuniform float u_frameTextureHeight;\n\n// Custom path/extremity uniforms\n`).concat(f.join(`\n`),`\n\n// Path attribute varyings — assigned so path functions can read them as globals\n`).concat(o.vertexVaryingDeclarations,`\n\n// Node size varyings — read by path functions like loop\nout float v_sourceNodeSize;\nout float v_targetNodeSize;\n\n// Node shape attributes per endpoint, and the ones querySDF reads\n`).concat(u,`\n`).concat(h,`\n\n// Scattered output written to the edge-frame texel: [tStart, tEnd, straightenFactor, pathLength]\nout vec4 v_clamp;\n\n// Extremity width factor array (needed for extremityScale computation)\nconst float EXTREMITY_WIDTH_FACTORS[`).concat(a.length,"] = float[](").concat(m,`);\n\n// Node-data fetch helpers (geometry texel + rotation-flags texel)\n`).concat(Xe,`\n`).concat(ot,`\n\n// Shape SDFs for node boundary clamping\n`).concat(Zl(),`\n`).concat(Ql(new Set(l)),`\n\n// Path functions\n`).concat(Ga(e),`\n`).concat(Oa(e),`\n`).concat(Xd(e),`\n\nvoid main() {\n // One point per edge-data row; the row index is the edge-frame texel target.\n int edgeIdx = gl_VertexID;\n int texel0Idx = edgeIdx * 2;\n int texel1Idx = edgeIdx * 2 + 1;\n ivec2 edgeTexCoord0 = ivec2(texel0Idx % u_edgeDataTextureWidth, texel0Idx / u_edgeDataTextureWidth);\n ivec2 edgeTexCoord1 = ivec2(texel1Idx % u_edgeDataTextureWidth, texel1Idx / u_edgeDataTextureWidth);\n vec4 edgeData0 = texelFetch(u_edgeDataTexture, edgeTexCoord0, 0);\n vec4 edgeData1 = texelFetch(u_edgeDataTexture, edgeTexCoord1, 0);\n\n int srcIdx = int(edgeData0.x);\n int tgtIdx = int(edgeData0.y);\n float a_thickness = edgeData0.z;\n float a_headLengthRatio = edgeData1.x;\n float a_tailLengthRatio = edgeData1.y;\n int pathId = int(edgeData1.z);\n int extremityPacked = int(edgeData1.w);\n int headId = extremityPacked >> 4;\n int tailId = extremityPacked & 15;\n\n // Fetch path/layer attributes and assign to path-function globals\n`).concat(o.fetchCode,`\n`).concat(o.varyingAssignments,`\n\n // Fetch node shape attributes for both endpoints\n`).concat(c.fetchCode,`\n`).concat(c.varyingAssignments,`\n`).concat(g.fetchCode,`\n`).concat(g.varyingAssignments,`\n\n // Fetch node geometry (texel 0) and rotation flags (texel 1).\n vec4 srcNodeData = readNodeData(u_nodeDataTexture, u_nodeDataTextureWidth, srcIdx);\n vec4 tgtNodeData = readNodeData(u_nodeDataTexture, u_nodeDataTextureWidth, tgtIdx);\n\n vec2 a_source = srcNodeData.xy;\n vec2 a_target = tgtNodeData.xy;\n float a_sourceSize = srcNodeData.z;\n float a_targetSize = tgtNodeData.z;\n float a_sourceShapeId = srcNodeData.w;\n float a_targetShapeId = tgtNodeData.w;\n // Per-node rotation alignment (0 = viewport, 1 = graph), for boundary clamping.\n float a_sourceRotateAlign = readNodeFlags(u_nodeDataTexture, u_nodeDataTextureWidth, srcIdx).r;\n float a_targetRotateAlign = readNodeFlags(u_nodeDataTexture, u_nodeDataTextureWidth, tgtIdx).r;\n\n v_sourceNodeSize = a_sourceSize;\n v_targetNodeSize = a_targetSize;\n\n float headLengthRatio = a_headLengthRatio;\n float tailLengthRatio = a_tailLengthRatio;\n float headWidthFactor = EXTREMITY_WIDTH_FACTORS[headId];\n float tailWidthFactor = EXTREMITY_WIDTH_FACTORS[tailId];\n float minBodyLengthRatio = `).concat(ve(T),`;\n\n // Thickness in WebGL units (needed to compute clamping margin and extremity lengths)\n float pixelsThickness = max(a_thickness, u_minEdgeThickness * u_sizeRatio);\n float webGLThickness = pixelsThickness * u_correctionRatio / u_sizeRatio;\n\n // SDF clamping: find where the edge body meets the node boundaries. Always\n // searched (ungated) so labels get a true boundary clamp; the body re-applies\n // its extremity gating in-shader.\n`).concat(p,`\n float tStart = queryFindSourceClampT(pathId, a_source, a_sourceSize, int(a_sourceShapeId), a_sourceRotateAlign, a_target, 0.0);\n`).concat(y,`\n float tEnd = queryFindTargetClampT(pathId, a_source, a_target, a_targetSize, int(a_targetShapeId), a_targetRotateAlign, 0.0);\n\n // straightenFactor (frame .z) is consumed only by the body, which runs to the\n // node center when an extremity is absent. Derive the straightening math from\n // these gated clamps — not the ungated boundary ones above — so it matches the\n // geometry it drives. The ungated tStart/tEnd remain what labels read.\n float bodyTStart = tailLengthRatio > 0.0 ? tStart : 0.0;\n float bodyTEnd = headLengthRatio > 0.0 ? tEnd : 1.0;\n\n // Path length and zone boundaries (needed for straightening check)\n float pathLength = queryPathLength(pathId, a_source, a_target);\n float visibleLength = pathLength * (bodyTEnd - bodyTStart);\n\n float headLength = headLengthRatio * webGLThickness;\n float tailLength = tailLengthRatio * webGLThickness;\n float minBodyLength = minBodyLengthRatio * webGLThickness;\n\n float totalNeededLength = headLength + tailLength + minBodyLength;\n float extremityScale = 1.0;\n if (totalNeededLength > visibleLength && totalNeededLength > 0.0001) {\n extremityScale = visibleLength / totalNeededLength;\n headLength *= extremityScale;\n tailLength *= extremityScale;\n }\n\n float headLengthT = pathLength > 0.0001 ? headLength / pathLength : 0.0;\n float tailLengthT = pathLength > 0.0001 ? tailLength / pathLength : 0.0;\n\n float tTailEnd = bodyTStart + tailLengthT;\n float tHeadStart = bodyTEnd - headLengthT;\n if (tTailEnd > tHeadStart) {\n float mid = (bodyTStart + bodyTEnd) * 0.5;\n tTailEnd = mid;\n tHeadStart = mid;\n }\n\n // Straighten factor: blend toward straight line when path twists in extremity zones\n float straightenFactor = 0.0;\n {\n float maxDeviation = 0.0;\n if (tailLengthT > 0.0001) {\n vec2 tailTang = queryPathTangent(pathId, tTailEnd, a_source, a_target);\n vec2 tailChord = queryPathPosition(pathId, bodyTStart, a_source, a_target)\n - queryPathPosition(pathId, tTailEnd, a_source, a_target);\n float tailChordLen = length(tailChord);\n if (tailChordLen > 0.0001) {\n maxDeviation = max(maxDeviation, 1.0 - dot(-tailTang, tailChord / tailChordLen));\n }\n }\n if (headLengthT > 0.0001) {\n vec2 headTang = queryPathTangent(pathId, tHeadStart, a_source, a_target);\n vec2 headChord = queryPathPosition(pathId, bodyTEnd, a_source, a_target)\n - queryPathPosition(pathId, tHeadStart, a_source, a_target);\n float headChordLen = length(headChord);\n if (headChordLen > 0.0001) {\n maxDeviation = max(maxDeviation, 1.0 - dot(headTang, headChord / headChordLen));\n }\n }\n straightenFactor = smoothstep(0.035, 0.5, maxDeviation);\n }\n\n // When straightening, blend the ungated tStart/tEnd (the label-facing clamps)\n // toward straight-line clamp positions.\n if (straightenFactor > 0.001) {\n if (tailLengthRatio > 0.0) {\n`).concat(p,`\n float srcExtent = a_sourceSize * u_correctionRatio / u_sizeRatio * 2.0;\n float srcEffective = 1.0 - u_correctionRatio / srcExtent;\n float srcCa = u_cameraAngle * (1.0 - a_sourceRotateAlign);\n mat2 srcRot = mat2(cos(srcCa), -sin(srcCa), sin(srcCa), cos(srcCa));\n float lo = 0.0, hi = 0.5;\n for (int i = 0; i < 12; i++) {\n float mid = (lo + hi) * 0.5;\n vec2 pos = mix(a_source, a_target, mid);\n vec2 localPos = srcRot * ((pos - a_source) / srcExtent);\n float sdf = querySDF(int(a_sourceShapeId), localPos, srcEffective);\n if (sdf < 0.0) lo = mid; else hi = mid;\n }\n tStart = mix(tStart, (lo + hi) * 0.5, straightenFactor);\n }\n if (headLengthRatio > 0.0) {\n`).concat(y,`\n float tgtExtent = a_targetSize * u_correctionRatio / u_sizeRatio * 2.0;\n float tgtEffective = 1.0 - u_correctionRatio / tgtExtent;\n float tgtCa = u_cameraAngle * (1.0 - a_targetRotateAlign);\n mat2 tgtRot = mat2(cos(tgtCa), -sin(tgtCa), sin(tgtCa), cos(tgtCa));\n float lo = 0.5, hi = 1.0;\n for (int i = 0; i < 12; i++) {\n float mid = (lo + hi) * 0.5;\n vec2 pos = mix(a_source, a_target, mid);\n vec2 localPos = tgtRot * ((pos - a_target) / tgtExtent);\n float sdf = querySDF(int(a_targetShapeId), localPos, tgtEffective);\n if (sdf < 0.0) hi = mid; else lo = mid;\n }\n tEnd = mix(tEnd, (lo + hi) * 0.5, straightenFactor);\n }\n }\n\n v_clamp = vec4(tStart, tEnd, straightenFactor, pathLength);\n\n // Scatter this point to its edge\'s texel center in the frame texture.\n float x = mod(float(edgeIdx), u_frameTextureWidth);\n float y = floor(float(edgeIdx) / u_frameTextureWidth);\n vec2 ndc = (vec2(x, y) + 0.5) / vec2(u_frameTextureWidth, u_frameTextureHeight) * 2.0 - 1.0;\n gl_Position = vec4(ndc, 0.0, 1.0);\n gl_PointSize = 1.0;\n}\n`);return _}var Cn=0,oi=1,kn=2;function qd(e,a,n){var t=[];if(n)t.push([Cn,0,-1],[Cn,0,1]),t.push([Cn,1,-1],[Cn,1,1]);for(var r=0;r<=e;r++){var i=r/e;t.push([oi,i,-1],[oi,i,1])}if(a)t.push([kn,0,-1],[kn,0,1]),t.push([kn,1,-1],[kn,1,1]);return{data:t,attributes:[{name:"a_zone",size:1,type:Xt},{name:"a_zoneT",size:1,type:Xt},{name:"a_side",size:1,type:Xt}],verticesPerEdge:t.length}}function Yd(e,a,n,t){var r=Me([].concat(J(e),J(n))),i=Kt(r),o=new Set(["u_matrix","u_sizeRatio","u_correctionRatio","u_zoomRatio","u_pixelRatio","u_cameraAngle","u_minEdgeThickness","u_pickingPadding","u_nodeDataTexture"]),s=new Set,l=[],d=function(f){if(!o.has(f.name)&&!s.has(f.name))s.add(f.name),l.push("uniform ".concat(f.type," ").concat(f.name,";"))};e.forEach(function(v){return v.uniforms.forEach(d)}),a.forEach(function(v){return v.uniforms.forEach(d)}),n.forEach(function(v){return v.uniforms.forEach(d)});var u=t.map(function(v){var f=v.size===1?"float":"vec".concat(v.size);return"in ".concat(f," ").concat(v.name,";")}).join(`\n`),c=a.map(function(v){return ve(v.widthFactor)}).join(", "),g=Math.max.apply(Math,J(e.map(function(v){return v.minBodyLengthRatio||0}))),h=n.some(function(v){return v.needsNodeColors}),p=e.some(function(v){return v.needsNodeSize}),y=`#version 300 es\n\n// Constant attributes (per vertex)\n`.concat(u,`\n\n// Per-edge attributes\n// Edge data (source/target indices, thickness, extremity ratios, path/extremity IDs)\n// is fetched from edge data texture via edge index\nin float a_edgeIndex; // Index into edge data texture\nin vec4 a_color; // Edge color\nin vec4 a_id; // Edge ID for picking\nin float a_opacity; // Edge opacity\n\n// Standard uniforms\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\nuniform float u_zoomRatio;\nuniform float u_pixelRatio;\nuniform float u_cameraAngle;\nuniform float u_minEdgeThickness;\n#ifdef PICKING_MODE\nuniform float u_pickingPadding;\n#endif\nuniform sampler2D u_nodeDataTexture;\nuniform int u_nodeDataTextureWidth;\nuniform sampler2D u_edgeDataTexture;\nuniform int u_edgeDataTextureWidth;\nuniform sampler2D u_edgeFrameTexture;\nuniform int u_edgeFrameTextureWidth;\n\n// Edge path attribute texture uniforms\n`).concat(i.uniformDeclarations,`\n\n// Custom uniforms\n`).concat(l.join(`\n`),`\n\n// Standard varyings\nout vec4 v_color;\nout float v_opacity;\nout vec4 v_id;\nout float v_thickness; // Edge body thickness (in consistent units)\nout float v_t;\nout float v_tStart;\nout float v_tEnd;\nout float v_side;\nout float v_antialiasingWidth; // Anti-aliasing width (normalized: u_correctionRatio / thickness)\nout vec2 v_source;\nout vec2 v_target;\nout float v_edgeLength;\n`).concat(p?`\nout float v_sourceNodeSize; // Source node size (mirrored in labels/generator.ts as plain float)\nout float v_targetNodeSize; // Target node size (mirrored in labels/generator.ts as plain float)`:"",`\n`).concat(h?`\nout vec4 v_sourceColor;\nout vec4 v_targetColor;`:"",`\n// Zone varyings\nout float v_zone; // 0=tail, 1=body, 2=head\nout float v_zoneT; // Position within zone [0,1]\nout float v_headLengthRatio; // Head length as ratio of thickness\nout float v_tailLengthRatio; // Tail length as ratio of thickness\nout float v_headWidthRatio; // Head width factor\nout float v_tailWidthRatio; // Tail width factor\n\n// Multi-path/extremity varyings\nflat out int v_pathId;\nflat out int v_headId;\nflat out int v_tailId;\n\n// Path/layer attribute varyings (fetched from edge attribute texture)\n`).concat(i.vertexVaryingDeclarations,`\n\nconst float bias = 255.0 / 254.0;\n\n// Width factor array for extremities (shared pool for head/tail)\nconst float EXTREMITY_WIDTH_FACTORS[`).concat(a.length,"] = float[](").concat(c,`);\n\n// All path functions\n`).concat(Ga(e),`\n\n// Path selector functions\n`).concat(Oa(e),`\n\n// Node-data fetch helper (geometry texel of the two-texel node stride)\n`).concat(Xe,`\n`).concat(h?rd:"",`\n// Per-edge clamp from the frame-pass (tStart, tEnd, straightenFactor, pathLength)\n`).concat(Lt,`\n\nvoid main() {\n // Fetch edge data from edge texture (2 texels per edge)\n // Texel 0: sourceNodeIndex, targetNodeIndex, thickness, reserved\n // Texel 1: headLengthRatio, tailLengthRatio, pathId, (headId << 4) | tailId\n int edgeIdx = int(a_edgeIndex);\n\n // Hidden edges are flagged with a negative row by EdgeProgram.process(). Push\n // the whole primitive outside the clip volume: every vertex lands at the same\n // out-of-range position, so it is fully clipped and rasterizes nothing —\n // neither to the frame buffer nor to the picking buffer.\n if (edgeIdx < 0) {\n gl_Position = vec4(2.0, 0.0, 0.0, 1.0);\n v_color = vec4(0.0);\n v_id = vec4(0.0);\n return;\n }\n\n int texel0Idx = edgeIdx * 2;\n int texel1Idx = edgeIdx * 2 + 1;\n ivec2 edgeTexCoord0 = ivec2(texel0Idx % u_edgeDataTextureWidth, texel0Idx / u_edgeDataTextureWidth);\n ivec2 edgeTexCoord1 = ivec2(texel1Idx % u_edgeDataTextureWidth, texel1Idx / u_edgeDataTextureWidth);\n vec4 edgeData0 = texelFetch(u_edgeDataTexture, edgeTexCoord0, 0);\n vec4 edgeData1 = texelFetch(u_edgeDataTexture, edgeTexCoord1, 0);\n\n // Unpack edge data\n int srcIdx = int(edgeData0.x);\n int tgtIdx = int(edgeData0.y);\n float a_thickness = edgeData0.z;\n // edgeData0.w is now reserved (curvature moved to path attribute texture)\n float a_headLengthRatio = edgeData1.x;\n float a_tailLengthRatio = edgeData1.y;\n int pathId = int(edgeData1.z);\n int extremityPacked = int(edgeData1.w);\n int headId = extremityPacked >> 4;\n int tailId = extremityPacked & 15;\n\n // Fetch path/layer attributes from edge attribute texture\n`).concat(i.fetchCode,`\n\n // Assign path/layer attribute varyings\n`).concat(i.varyingAssignments,`\n\n // Fetch source and target node geometry (texel 0 of the two-texel node stride)\n vec4 srcNodeData = readNodeData(u_nodeDataTexture, u_nodeDataTextureWidth, srcIdx);\n vec4 tgtNodeData = readNodeData(u_nodeDataTexture, u_nodeDataTextureWidth, tgtIdx);\n\n vec2 a_source = srcNodeData.xy;\n vec2 a_target = tgtNodeData.xy;\n`).concat(p?`\n // Assign node size varyings early (path functions like loops need them during clamping)\n v_sourceNodeSize = srcNodeData.z;\n v_targetNodeSize = tgtNodeData.z;`:"",`\n`).concat(h?`\n v_sourceColor = readNodeColor(u_nodeDataTexture, u_nodeDataTextureWidth, srcIdx);\n v_targetColor = readNodeColor(u_nodeDataTexture, u_nodeDataTextureWidth, tgtIdx);`:"",`\n\n // Convert thickness to WebGL units\n float minThickness = u_minEdgeThickness;\n float pixelsThickness = max(a_thickness, minThickness * u_sizeRatio);\n float webGLThickness = pixelsThickness * u_correctionRatio / u_sizeRatio;\n\n // Extremity parameters from ID lookups (shared pool)\n float headLengthRatio = a_headLengthRatio;\n float tailLengthRatio = a_tailLengthRatio;\n float headWidthFactor = EXTREMITY_WIDTH_FACTORS[headId];\n float tailWidthFactor = EXTREMITY_WIDTH_FACTORS[tailId];\n float minBodyLengthRatio = `).concat(ve(g),`;\n\n // Per-edge values from the frame-pass texture (read by edge index).\n // tStart/tEnd are the ungated boundary clamps: re-apply the body\'s extremity\n // gating here (no extremity → body runs to the node center, 0/1).\n vec4 frameClamp = readFrameTexel(u_edgeFrameTexture, u_edgeFrameTextureWidth, edgeIdx);\n float tStart = a_tailLengthRatio > 0.0 ? frameClamp.x : 0.0;\n float tEnd = a_headLengthRatio > 0.0 ? frameClamp.y : 1.0;\n float straightenFactor = frameClamp.z;\n float pathLength = frameClamp.w;\n\n // Anti-aliasing width (~1 pixel, normalized by thickness)\n float antialiasingWidth = u_correctionRatio / webGLThickness;\n\n float visibleLength = pathLength * (tEnd - tStart);\n\n // Compute extremity lengths in world units\n float headLength = headLengthRatio * webGLThickness;\n float tailLength = tailLengthRatio * webGLThickness;\n float minBodyLength = minBodyLengthRatio * webGLThickness;\n\n // Handle short edges: scale down extremities if needed\n float totalNeededLength = headLength + tailLength + minBodyLength;\n float extremityScale = 1.0;\n if (totalNeededLength > visibleLength && totalNeededLength > 0.0001) {\n extremityScale = visibleLength / totalNeededLength;\n headLength *= extremityScale;\n tailLength *= extremityScale;\n }\n\n // Convert lengths to t-values\n float headLengthT = pathLength > 0.0001 ? headLength / pathLength : 0.0;\n float tailLengthT = pathLength > 0.0001 ? tailLength / pathLength : 0.0;\n\n // Zone boundaries in t-space\n float tTailEnd = tStart + tailLengthT;\n float tHeadStart = tEnd - headLengthT;\n\n // Ensure body has non-negative length\n if (tTailEnd > tHeadStart) {\n float mid = (tStart + tEnd) * 0.5;\n tTailEnd = mid;\n tHeadStart = mid;\n }\n\n // Convert to webGL units for geometry expansion\n float aaWidthWebGL = antialiasingWidth * webGLThickness;\n\n // Extra geometry width for picking padding (0 in visual mode)\n #ifdef PICKING_MODE\n float pickingPaddingWebGL = u_pickingPadding * u_correctionRatio;\n #else\n float pickingPaddingWebGL = 0.0;\n #endif\n\n // Straight-line direction and normal (for blending when straightenFactor > 0)\n vec2 straightDir = length(a_target - a_source) > 0.0001\n ? normalize(a_target - a_source) : vec2(1.0, 0.0);\n vec2 straightNormal = vec2(-straightDir.y, straightDir.x);\n\n // Zone-based vertex processing using path selectors\n vec2 position;\n vec2 normal;\n float t;\n float zone = a_zone;\n float zoneT = a_zoneT;\n float side = a_side;\n\n // Scaled extremity width factors (geometry must be at least as wide as body)\n float scaledTailWidth = max(tailWidthFactor * extremityScale, 1.0);\n float scaledHeadWidth = max(headWidthFactor * extremityScale, 1.0);\n\n if (zone < 0.5) {\n // TAIL ZONE: rectangular quad with scaled width\n vec2 tang = queryPathTangent(pathId, tTailEnd, a_source, a_target);\n normal = vec2(-tang.y, tang.x);\n vec2 centerPos = mix(queryPathPosition(pathId, tStart, a_source, a_target),\n queryPathPosition(pathId, tTailEnd, a_source, a_target), zoneT);\n float halfWidth = webGLThickness * scaledTailWidth * 0.5 + aaWidthWebGL + pickingPaddingWebGL;\n position = centerPos + normal * side * halfWidth;\n t = mix(tStart, tTailEnd, zoneT);\n\n } else if (zone < 1.5) {\n // BODY ZONE: follows path curvature with width = 1.0\n t = mix(tTailEnd, tHeadStart, zoneT);\n normal = queryPathNormal(pathId, t, a_source, a_target);\n float halfWidth = webGLThickness * 0.5 + aaWidthWebGL + pickingPaddingWebGL;\n position = queryPathPosition(pathId, t, a_source, a_target) + normal * side * halfWidth;\n\n } else {\n // HEAD ZONE: rectangular quad with scaled width\n vec2 tang = queryPathTangent(pathId, tHeadStart, a_source, a_target);\n normal = vec2(-tang.y, tang.x);\n vec2 centerPos = mix(queryPathPosition(pathId, tHeadStart, a_source, a_target),\n queryPathPosition(pathId, tEnd, a_source, a_target), zoneT);\n float halfWidth = webGLThickness * scaledHeadWidth * 0.5 + aaWidthWebGL + pickingPaddingWebGL;\n position = centerPos + normal * side * halfWidth;\n t = mix(tHeadStart, tEnd, zoneT);\n }\n\n // Blend toward straight line based on path twist in extremity zones\n if (straightenFactor > 0.001) {\n float zoneWidth = zone < 0.5 ? webGLThickness * scaledTailWidth * 0.5 + aaWidthWebGL + pickingPaddingWebGL :\n zone < 1.5 ? webGLThickness * 0.5 + aaWidthWebGL + pickingPaddingWebGL :\n webGLThickness * scaledHeadWidth * 0.5 + aaWidthWebGL + pickingPaddingWebGL;\n vec2 straightPos = mix(a_source, a_target, t) + straightNormal * side * zoneWidth;\n position = mix(position, straightPos, straightenFactor);\n }\n\n gl_Position = vec4((u_matrix * vec3(position, 1.0)).xy, 0.0, 1.0);\n\n // Pass varyings to fragment shader\n v_color = a_color;\n v_color.a *= bias;\n v_opacity = a_opacity;\n v_id = a_id;\n v_thickness = webGLThickness;\n v_t = t;\n v_tStart = tStart;\n v_tEnd = tEnd;\n v_side = side;\n v_antialiasingWidth = antialiasingWidth;\n v_source = a_source;\n v_target = a_target;\n v_edgeLength = pathLength;\n\n // Zone varyings\n v_zone = zone;\n v_zoneT = zoneT;\n v_headLengthRatio = headLengthRatio * extremityScale;\n v_tailLengthRatio = tailLengthRatio * extremityScale;\n // Scale extremity width proportionally with length when crushed\n v_headWidthRatio = headWidthFactor * extremityScale;\n v_tailWidthRatio = tailWidthFactor * extremityScale;\n\n // Multi-path varyings\n v_pathId = pathId;\n v_headId = headId;\n v_tailId = tailId;\n}\n`);return y}function Kd(e,a,n,t){var r=Me([].concat(J(e),J(n))),i=Kt(r),o=new Set(["u_matrix","u_sizeRatio","u_correctionRatio","u_zoomRatio","u_pixelRatio","u_cameraAngle","u_minEdgeThickness","u_pickingPadding"]),s=new Set,l=[],d=function(b){if(!o.has(b.name)&&!s.has(b.name))s.add(b.name),l.push("uniform ".concat(b.type," ").concat(b.name,";"))};e.forEach(function(f){return f.uniforms.forEach(d)}),a.forEach(function(f){return f.uniforms.forEach(d)}),n.forEach(function(f){return f.uniforms.forEach(d)});var u=a.map(function(f){var b;return ve((b=f.baseRatio)!==null&&b!==void 0?b:0.5)}).join(", "),c=function(b){var m,T;return a.length>1?"EXTREMITY_BASE_RATIOS[".concat(b,"]"):ve((m=(T=a[0])===null||T===void 0?void 0:T.baseRatio)!==null&&m!==void 0?m:0.5)},g=a.some(function(f){return!Fe(f.length)?f.length>0:!0}),h=n.some(function(f){return f.needsNodeColors}),p=e.some(function(f){return f.needsNodeSize}),y=n.map(function(f,b){return" // Layer ".concat(b+1,": ").concat(f.name,`\n color = blendOver(color, layer_`).concat(f.name,"(context));")}).join(`\n\n`),v=`#version 300 es\nprecision highp float;\n\n// Standard varyings\nin vec4 v_color;\nin float v_opacity;\nin vec4 v_id;\nin float v_thickness; // Edge body thickness\nin float v_t;\nin float v_tStart;\nin float v_tEnd;\nin float v_side;\nin float v_antialiasingWidth; // Anti-aliasing width (normalized: u_correctionRatio / thickness)\nin vec2 v_source;\nin vec2 v_target;\nin float v_edgeLength;\n`.concat(p?`\nin float v_sourceNodeSize; // Source node size (mirrored in labels/generator.ts as plain float)\nin float v_targetNodeSize; // Target node size (mirrored in labels/generator.ts as plain float)`:"",`\n`).concat(h?`\nin vec4 v_sourceColor;\nin vec4 v_targetColor;`:"",`\n// Zone varyings\nin float v_zone; // 0=tail, 1=body, 2=head\nin float v_zoneT; // Position within zone [0,1]\nin float v_headLengthRatio; // Head length as ratio of thickness (scaled for short edges)\nin float v_tailLengthRatio; // Tail length as ratio of thickness (scaled for short edges)\nin float v_headWidthRatio; // Head width factor\nin float v_tailWidthRatio; // Tail width factor\n\n// Multi-path/extremity varyings\nflat in int v_pathId;\nflat in int v_headId;\nflat in int v_tailId;\n\n// Path/layer attribute varyings (from vertex shader texture fetch)\n`).concat(i.fragmentVaryingDeclarations,`\n\n// Standard uniforms (needed by some path types)\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\nuniform float u_cameraAngle;\n#ifdef PICKING_MODE\nuniform float u_pickingPadding;\n#endif\n\n// Custom uniforms\n`).concat(l.join(`\n`),`\n\n// Fragment output (single target - picking handled via separate pass)\nout vec4 fragColor;\n\n`).concat(a.length>1?`// Base ratio array for extremities (shared pool for head/tail)\nconst float EXTREMITY_BASE_RATIOS[`.concat(a.length,"] = float[](").concat(u,");"):"",`\n\n// EdgeContext struct\nstruct EdgeContext {\n float t; // Position along path [0, 1]\n float sdf; // Signed distance from centerline\n vec2 position; // World position\n vec2 tangent; // Path tangent\n vec2 normal; // Path normal\n float thickness; // Edge thickness\n float aaWidth; // Anti-aliasing width\n float edgeLength; // Total path length\n float tStart; // Clamped start t\n float tEnd; // Clamped end t\n float distanceFromSource; // Arc distance from source\n float distanceToTarget; // Arc distance to target\n};\n\nEdgeContext context;\n\n// Alpha "over" compositing for layer blending\nvec4 blendOver(vec4 bg, vec4 fg) {\n float a = fg.a;\n return vec4(mix(bg.rgb, fg.rgb, a), bg.a + a * (1.0 - bg.a));\n}\n\n// All path functions\n`).concat(Ga(e),`\n\n// Path selector functions\n`).concat(Oa(e),`\n\n// All extremity functions\n`).concat(Ud(a),`\n\n// Extremity SDF selector (shared pool for head/tail)\n`).concat(Vd(a),`\n\n// Layer functions\n`).concat(n.map(function(f){return f.glsl}).join(`\n\n`),`\n\n// Helper: Compute arc length using path selector\nfloat computeArcLengthMulti(int pathId, float t0, float t1, vec2 source, vec2 target, int samples) {\n float arcLen = 0.0;\n vec2 prev = queryPathPosition(pathId, t0, source, target);\n for (int i = 1; i <= samples; i++) {\n float t = t0 + (t1 - t0) * float(i) / float(samples);\n vec2 curr = queryPathPosition(pathId, t, source, target);\n arcLen += length(curr - prev);\n prev = curr;\n }\n return arcLen;\n}\n\nvoid main() {\n // Compute normalized t within visible edge (0 = start, 1 = end)\n float tNorm = (v_t - v_tStart) / max(v_tEnd - v_tStart, 0.0001);\n\n // Edge body half-thickness\n float halfThickness = v_thickness * 0.5;\n\n // Convert normalized AA width to webGL units (~1 pixel)\n float aaWidthWebGL = v_antialiasingWidth * v_thickness;\n\n // Distance from centerline based on v_side interpolation\n float zoneWidthFactor = v_zone < 0.5 ? v_tailWidthRatio :\n v_zone < 1.5 ? 1.0 :\n v_headWidthRatio;\n // In PICKING_MODE, inflate halfGeometryWidth to match the inflated vertex geometry\n #ifdef PICKING_MODE\n float halfGeometryWidth = halfThickness * zoneWidthFactor + aaWidthWebGL + u_pickingPadding * aaWidthWebGL;\n #else\n float halfGeometryWidth = halfThickness * zoneWidthFactor + aaWidthWebGL;\n #endif\n float distFromCenter = abs(v_side) * halfGeometryWidth;\n\n // Populate EdgeContext (for layer functions)\n context.t = tNorm;\n context.sdf = distFromCenter - halfThickness;\n context.position = queryPathPosition(v_pathId, v_t, v_source, v_target);\n context.tangent = queryPathTangent(v_pathId, v_t, v_source, v_target);\n context.normal = vec2(-context.tangent.y, context.tangent.x);\n context.thickness = v_thickness;\n context.aaWidth = aaWidthWebGL;\n context.edgeLength = v_edgeLength;\n context.tStart = v_tStart;\n context.tEnd = v_tEnd;\n\n // Compute arc distances\n float visibleLength = v_edgeLength * (v_tEnd - v_tStart);\n float pathT = v_t;\n float pathTNorm = tNorm;\n`).concat(e.every(function(f){return f.linearParameterization})?` // All paths have linear parameterization: t maps directly to arc distance\n context.distanceFromSource = pathTNorm * visibleLength;\n context.distanceToTarget = (1.0 - pathTNorm) * visibleLength;`:e.every(function(f){return!f.linearParameterization})?` // No paths have linear parameterization: use numerical integration\n context.distanceFromSource = computeArcLengthMulti(v_pathId, v_tStart, pathT, v_source, v_target, 16);\n context.distanceToTarget = computeArcLengthMulti(v_pathId, pathT, v_tEnd, v_source, v_target, 16);`:` // Mixed parameterization: use analytical for linear paths, numerical for others\n if (`.concat(e.filter(function(f){return f.linearParameterization}).map(function(f){return"v_pathId == ".concat(e.indexOf(f))}).join(" || "),`) {\n context.distanceFromSource = pathTNorm * visibleLength;\n context.distanceToTarget = (1.0 - pathTNorm) * visibleLength;\n } else {\n context.distanceFromSource = computeArcLengthMulti(v_pathId, v_tStart, pathT, v_source, v_target, 16);\n context.distanceToTarget = computeArcLengthMulti(v_pathId, pathT, v_tEnd, v_source, v_target, 16);\n }`),`\n\n // Compute SDF based on zone using extremity selector (shared pool)\n float bodySDF = distFromCenter - halfThickness;\n float finalSDF;\n\n`).concat(g?` // Base ratios, from baseRatioLookup\n float headBaseRatio = `.concat(c("v_headId"),`;\n float tailBaseRatio = `).concat(c("v_tailId"),`;\n\n if (v_zone < 0.5) {\n // TAIL ZONE: v_zoneT goes 0 (tip) to 1 (base)\n vec2 uv = vec2((1.0 - v_zoneT) * v_tailLengthRatio, v_side * v_tailWidthRatio * 0.5);\n float tailSDF = queryExtremitySDF(v_tailId, uv, v_tailLengthRatio, v_tailWidthRatio) * v_thickness;\n\n // Apply union only near base (v_zoneT > 1 - baseRatio)\n if (v_zoneT > 1.0 - tailBaseRatio) {\n finalSDF = min(tailSDF, bodySDF);\n } else {\n finalSDF = tailSDF;\n }\n } else if (v_zone < 1.5) {\n // BODY ZONE: distance from centerline\n finalSDF = bodySDF;\n } else {\n // HEAD ZONE: v_zoneT goes 0 (base) to 1 (tip)\n vec2 uv = vec2(v_zoneT * v_headLengthRatio, v_side * v_headWidthRatio * 0.5);\n float headSDF = queryExtremitySDF(v_headId, uv, v_headLengthRatio, v_headWidthRatio) * v_thickness;\n\n // Apply union only near base (v_zoneT < baseRatio)\n if (v_zoneT < headBaseRatio) {\n finalSDF = min(headSDF, bodySDF);\n } else {\n finalSDF = headSDF;\n }\n }`):` // No extremity draws tail/head geometry, so every vertex is body zone.\n finalSDF = bodySDF;`,`\n\n #ifdef PICKING_MODE\n // Picking pass: output edge ID for pixels within the picking area\n if (finalSDF > u_pickingPadding * aaWidthWebGL) discard;\n fragColor = v_id;\n #else\n`).concat(t?` // Visual pass: anti-aliased edge with layers, edge opacity applied once\n float alpha = smoothstep(aaWidthWebGL, -aaWidthWebGL, finalSDF) * v_opacity;`:` // Visual pass: hard-edged (no anti-aliasing gradient) edge with layers, edge opacity applied once\n float alpha = (finalSDF < 0.0 ? 1.0 : 0.0) * v_opacity;`,`\n if (alpha < 0.01) discard;\n\n // Apply layers sequentially with "over" compositing\n vec4 color = vec4(0.0);\n\n`).concat(y,`\n\n // Mix with transparent to fade both color AND alpha (pre-multiplied alpha for correct blending)\n fragColor = mix(vec4(0.0), color, alpha);\n #endif\n}\n`);return v}function Zd(e,a,n){var t=!Fe(a.length)?a.length>0:!0,r=!Fe(n.length)?n.length>0:!0;if(e.generateConstantData){var i=e.generateConstantData();return{data:i.data,attributes:i.attributes,verticesPerEdge:i.verticesPerEdge}}return qd(e.segments,t,r)}function si(e){var a,n=Ei(e),{paths:t,extremities:r,layers:i}=n,o=(a=e.antialias)!==null&&a!==void 0?a:!0,s=new Map,l=new Map,d=new Map,u=W(t),c;try{for(u.s();!(c=u.n()).done;){var g=c.value,h=W(r),p;try{for(h.s();!(p=h.n()).done;){var y=p.value,v=W(r),f;try{for(v.s();!(f=v.n()).done;){var b=f.value,m="".concat(g.name,":").concat(y.name,":").concat(b.name),T=Zd(g,y,b);s.set(m,T.verticesPerEdge),l.set(m,T.data);var _=W(T.attributes),x;try{for(_.s();!(x=_.n()).done;){var S=x.value;if(!d.has(S.name))d.set(S.name,S)}}catch(Z){_.e(Z)}finally{_.f()}}}catch(Z){v.e(Z)}finally{v.f()}}}catch(Z){h.e(Z)}finally{h.f()}}}catch(Z){u.e(Z)}finally{u.f()}var E=Array.from(d.values()),D={};E.forEach(function(Z,ee){D[Z.name]=ee});var A=0,L="",w=W(s),M;try{for(w.s();!(M=w.n()).done;){var C=le(M.value,2),z=C[0],O=C[1];if(O>A)A=O,L=z}}catch(Z){w.e(Z)}finally{w.f()}var N=l.get(L)||[],F=L.split(":"),P=le(F,1),B=P[0],Y=t.find(function(Z){return Z.name===B}),q=[];if(Y!==null&&Y!==void 0&&Y.generateConstantData)q=Y.generateConstantData().attributes;else q=[{name:"a_zone"},{name:"a_zoneT"},{name:"a_side"}];var re=N.map(function(Z){var ee=Array(E.length).fill(0);return q.forEach(function(Ee,de){var U=D[Ee.name];if(U!==void 0&&de<Z.length)ee[U]=Z[de]}),ee});return{vertexShader:Yd(t,r,i,E),fragmentShader:Kd(t,r,i,o),uniforms:Wd(t,r,i),attributes:Qd(),verticesPerEdge:A,constantData:re,constantAttributes:E,vertexCountsPerCombination:s,constantDataPerCombination:l}}function Qd(e,a,n){return[{name:"a_edgeIndex",size:1,type:Xt},{name:"a_color",size:4,type:ii,normalized:!0},{name:"a_id",size:4,type:ii,normalized:!0},{name:"a_opacity",size:1,type:Xt}]}var Jd=`#version 300 es\nprecision highp float;\n\nin vec4 v_clamp;\n\n// RGBA32F target: stores (tStart, tEnd, straightenFactor, pathLength).\nout vec4 fragColor;\n\nvoid main() {\n fragColor = v_clamp;\n}\n`,eu=function(){function e(a,n){ie(this,e),R(this,"uniformLocations",{});var{paths:t,extremities:r,layers:i,nodeShapes:o,nodeLayers:s}=n;this.gl=a,this.hasAttributeData=Me([].concat(J(t),J(i))).floatsPerItem>0,this.hasNodeAttributeData=Object.keys(Ct(o,s).offsets).length>0,this.vertexShader=ka(a,jd(t,r,i,o,s)),this.fragmentShader=Pa(a,Jd),this.program=Fa(a,[this.vertexShader,this.fragmentShader]);var l=new Set;this.customUniforms=[];for(var d=0,u=[].concat(J(t),J(r));d<u.length;d++){var c=u[d],g=W(c.uniforms),h;try{for(g.s();!(h=g.n()).done;){var p=h.value;if(l.has(p.name))continue;l.add(p.name),this.customUniforms.push(p)}}catch(m){g.e(m)}finally{g.f()}}var y=["u_sizeRatio","u_correctionRatio","u_cameraAngle","u_minEdgeThickness","u_nodeDataTexture","u_nodeDataTextureWidth","u_edgeDataTexture","u_edgeDataTextureWidth","u_edgeAttributeTexture","u_edgeAttributeTextureWidth","u_edgeAttributeTexelsPerEdge","u_layerAttributeTexture","u_layerAttributeTextureWidth","u_layerAttributeTexelsPerNode","u_frameTextureWidth","u_frameTextureHeight"].concat(J(this.customUniforms.map(function(m){return m.name}))),v=W(y),f;try{for(v.s();!(f=v.n()).done;){var b=f.value;this.uniformLocations[b]=a.getUniformLocation(this.program,b)}}catch(m){v.e(m)}finally{v.f()}this.vao=a.createVertexArray()}return oe(e,[{key:"run",value:function(n,t,r,i,o){if(r===0)return;var s=this.gl,l=this.uniformLocations;if(s.useProgram(this.program),s.bindVertexArray(this.vao),l.u_sizeRatio)s.uniform1f(l.u_sizeRatio,n.sizeRatio);if(l.u_correctionRatio)s.uniform1f(l.u_correctionRatio,n.correctionRatio);if(l.u_cameraAngle)s.uniform1f(l.u_cameraAngle,n.cameraAngle);if(l.u_minEdgeThickness)s.uniform1f(l.u_minEdgeThickness,n.minEdgeThickness);if(l.u_nodeDataTexture)s.uniform1i(l.u_nodeDataTexture,n.nodeDataTextureUnit);if(l.u_nodeDataTextureWidth)s.uniform1i(l.u_nodeDataTextureWidth,n.nodeDataTextureWidth);if(l.u_edgeDataTexture)s.uniform1i(l.u_edgeDataTexture,n.edgeDataTextureUnit);if(l.u_edgeDataTextureWidth)s.uniform1i(l.u_edgeDataTextureWidth,n.edgeDataTextureWidth);if(l.u_frameTextureWidth)s.uniform1f(l.u_frameTextureWidth,t.getTextureWidth());if(l.u_frameTextureHeight)s.uniform1f(l.u_frameTextureHeight,t.getTextureHeight());if(this.hasAttributeData&&i){if(i.bind(Je),l.u_edgeAttributeTexture)s.uniform1i(l.u_edgeAttributeTexture,Je);if(l.u_edgeAttributeTextureWidth)s.uniform1i(l.u_edgeAttributeTextureWidth,i.getTextureWidth());if(l.u_edgeAttributeTexelsPerEdge)s.uniform1i(l.u_edgeAttributeTexelsPerEdge,i.getTexelsPerItem())}if(this.hasNodeAttributeData&&o){if(o.bind(Qe),l.u_layerAttributeTexture)s.uniform1i(l.u_layerAttributeTexture,Qe);if(l.u_layerAttributeTextureWidth)s.uniform1i(l.u_layerAttributeTextureWidth,o.getTextureWidth());if(l.u_layerAttributeTexelsPerNode)s.uniform1i(l.u_layerAttributeTexelsPerNode,o.getTexelsPerItem())}var d=W(this.customUniforms),u;try{for(d.s();!(u=d.n()).done;){var c=u.value;Na(s,this.uniformLocations[c.name],c)}}catch(g){d.e(g)}finally{d.f()}t.bindAsRenderTarget(),s.disable(s.BLEND),s.disable(s.DEPTH_TEST),s.drawArrays(s.POINTS,0,r),s.bindFramebuffer(s.FRAMEBUFFER,null),s.bindVertexArray(null)}},{key:"kill",value:function(){var n=this.gl;n.deleteProgram(this.program),n.deleteShader(this.vertexShader),n.deleteShader(this.fragmentShader),n.deleteVertexArray(this.vao)}}])}();function $t(e,a,n,t,r,i){if(e.length===1)return"".concat(t," ").concat(a,"(int pathId, ").concat(r,`) {\n return path_`).concat(e[0].name,"_").concat(n,"(").concat(i,`);\n}`);var o=e.map(function(s,l){return" case ".concat(l,": return path_").concat(s.name,"_").concat(n,"(").concat(i,");")}).join(`\n`);return"".concat(t," ").concat(a,"(int pathId, ").concat(r,`) {\n switch (pathId) {\n`).concat(o,`\n default: return path_`).concat(e[0].name,"_").concat(n,"(").concat(i,`);\n }\n}`)}var tu=`\nvec3 computeEdgeLabelBodyBounds(\n float tStart, float tEnd, float pathLength,\n float webGLThickness, float headLengthRatio, float tailLengthRatio\n) {\n float visibleLength = pathLength * (tEnd - tStart);\n\n float headLength = headLengthRatio * webGLThickness;\n float tailLength = tailLengthRatio * webGLThickness;\n float totalNeededLength = headLength + tailLength;\n if (totalNeededLength > visibleLength && totalNeededLength > 0.0001) {\n float extremityScale = visibleLength / totalNeededLength;\n headLength *= extremityScale;\n tailLength *= extremityScale;\n }\n\n float bodyStartDist = tStart * pathLength + tailLength;\n float bodyEndDist = tEnd * pathLength - headLength;\n return vec3(bodyStartDist, bodyEndDist, max(bodyEndDist - bodyStartDist, 0.0));\n}\n`;function nu(e,a){var n=ve(e),t=ve(a);return`\nfloat computeEdgeLabelAlpha(float bodyLength, float textWidthWebGL) {\n float ratio = textWidthWebGL > 0.0001 ? min(bodyLength / textWidthWebGL, 1.0) : 1.0;\n if (ratio < `.concat(n,`) return 0.0;\n if (ratio < `).concat(t,") return (ratio - ").concat(n,") / (").concat(t," - ").concat(n,`);\n return 1.0;\n}\n`)}var au=`\nfloat computeEdgeLabelScreenDir(int pathId, float t, vec2 source, vec2 target, mat3 matrix) {\n vec2 tangent = queryPathTangent(pathId, t, source, target);\n return (matrix * vec3(tangent, 0.0)).x < 0.0 ? -1.0 : 1.0;\n}\n`,ru=`\nfloat computeEdgeLabelPerpOffset(\n float positionMode,\n float halfThickness, float marginWebGL, float halfTextHeight,\n float readingSign, float screenDir\n) {\n float magnitude = halfThickness + marginWebGL + halfTextHeight;\n if (positionMode == 1.0) return magnitude * readingSign;\n if (positionMode == 2.0) return -magnitude * readingSign;\n if (positionMode == 3.0) return magnitude * screenDir;\n return 0.0;\n}\n`;function Ai(e){var{paths:a,minVisibilityThreshold:n,fullVisibilityThreshold:t}=e,r=a.some(function(s){return s.hasSharpCorners}),i=a.map(function(s){return"// --- Path: ".concat(s.name,` ---\n`).concat(s.glsl,`\n\n// Tangent/normal functions: analytical if provided, otherwise numerical\n`).concat(s.analyticalTangentGlsl||Ti(s.name),`\n\n// Auto-generated fallbacks for any missing path functions\n`).concat(Si(s.name,s.glsl),`\n\n// Corner skip helpers (for paths with sharp corners like step/taxi)\n`).concat(s.cornerSkipGlsl||"",`\n`)}).join(`\n`),o=r?`// Corner function selectors (only some paths have sharp corners)\nvec2 queryGetCornerTs(int pathId, vec2 source, vec2 target) {\n switch (pathId) {\n`.concat(a.map(function(s,l){return s.hasSharpCorners?" case ".concat(l,": return path_").concat(s.name,"_getCornerTs(source, target);"):" case ".concat(l,": return vec2(-1.0, -1.0); // No corners for ").concat(s.name)}).join(`\n`),`\n default: return vec2(-1.0, -1.0);\n }\n}\n\nvec2 queryGetCornerConcavity(int pathId, vec2 source, vec2 target, float perpOffset) {\n switch (pathId) {\n`).concat(a.map(function(s,l){return s.hasSharpCorners?" case ".concat(l,": return path_").concat(s.name,"_getCornerConcavity(source, target, perpOffset);"):" case ".concat(l,": return vec2(0.0, 0.0); // No corners for ").concat(s.name)}).join(`\n`),`\n default: return vec2(0.0, 0.0);\n }\n}`):"";return`\n// ============================================================================\n// Node data fetch (geometry texel) and per-edge clamp fetch (edge-frame texture)\n// ============================================================================\n\n`.concat(Xe,`\n`).concat(Lt,`\n\n// ============================================================================\n// Path Functions (one block per path)\n// ============================================================================\n\n`).concat(i,`\n\n// ============================================================================\n// Path Query Selectors (dispatch by pathId)\n// ============================================================================\n\n`).concat($t(a,"queryPathPosition","position","vec2","float t, vec2 source, vec2 target","t, source, target"),`\n\n`).concat($t(a,"queryPathTangent","tangent","vec2","float t, vec2 source, vec2 target","t, source, target"),`\n\n`).concat($t(a,"queryPathNormal","normal","vec2","float t, vec2 source, vec2 target","t, source, target"),`\n\n`).concat($t(a,"queryPathLength","length","float","vec2 source, vec2 target","source, target"),`\n\n`).concat($t(a,"queryPathTAtDistance","t_at_distance","float","float dist, vec2 source, vec2 target","dist, source, target"),`\n\n`).concat(o,`\n\n// ============================================================================\n// Shared helpers (body bounds, alpha ramp, screen direction, perpendicular offset)\n// ============================================================================\n\n`).concat(tu,`\n`).concat(nu(n,t),`\n`).concat(au,`\n`).concat(ru,`\n`)}var iu=Be.fontSize,ou=new Map,wi=24,li=(wi+1)*2;function su(e){var{paths:a,fontSizeMode:n,headLengthRatio:t,tailLengthRatio:r,minVisibilityThreshold:i,fullVisibilityThreshold:o,keepUpright:s}=e,l=n==="scaled",d=Ke(),u=Me([].concat(J(a),[d])),c=Kt(u),g=`#version 300 es\n\n// Per-instance attributes\nin float a_edgeIndex;\nin float a_edgeAttrIndex;\nin float a_baseFontSize;\nin float a_totalTextWidth;\nin float a_positionMode;\nin float a_margin;\nin float a_padding;\nin vec4 a_color;\nin vec4 a_id;\n\n// Per-vertex (constant) attribute: strip vertex index\nin float a_vertexIndex;\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\nuniform float u_pixelRatio;\nuniform float u_cameraAngle;\nuniform vec2 u_resolution;\nuniform sampler2D u_nodeDataTexture;\nuniform int u_nodeDataTextureWidth;\nuniform sampler2D u_edgeDataTexture;\nuniform int u_edgeDataTextureWidth;\nuniform sampler2D u_edgeFrameTexture; // Per-edge clamp (tStart, tEnd, straightenFactor, pathLength)\nuniform int u_edgeFrameTextureWidth;\n`.concat(l?"uniform float u_zoomSizeRatio;":"",`\n\n`).concat(c.uniformDeclarations,`\n\nout vec4 v_color;\nout vec4 v_id;\nout float v_alphaModifier;\n\nconst float ATLAS_FONT_SIZE = `).concat(ve(iu),`;\nconst float HEAD_RATIO = `).concat(ve(t),`;\nconst float TAIL_RATIO = `).concat(ve(r),`;\nconst int RIBBON_SEGMENTS = `).concat(wi,`;\n\n// Path attribute varyings (declared as plain locals since this shader has no FS inputs for them)\n`).concat(c.vertexVaryingDeclarations.replace(/out /g,""),`\n\n// Node size variables used by some path functions (self-loops, etc.)\nfloat v_sourceNodeSize;\nfloat v_targetNodeSize;\n\n// Shared preamble: shape SDFs, path functions + selectors, clamp, helpers.\n`).concat(Ai({paths:a,minVisibilityThreshold:i,fullVisibilityThreshold:o}),`\n\nvoid main() {\n int vIdx = int(a_vertexIndex);\n int pairIdx = vIdx / 2;\n int side = vIdx - pairIdx * 2; // 0 = left/bottom, 1 = right/top\n\n // --- Fetch edge data (2 texels per edge) ---\n int edgeIdx = int(a_edgeIndex);\n int texel0Idx = edgeIdx * 2;\n int texel1Idx = edgeIdx * 2 + 1;\n ivec2 e0 = ivec2(texel0Idx % u_edgeDataTextureWidth, texel0Idx / u_edgeDataTextureWidth);\n ivec2 e1 = ivec2(texel1Idx % u_edgeDataTextureWidth, texel1Idx / u_edgeDataTextureWidth);\n vec4 edgeData0 = texelFetch(u_edgeDataTexture, e0, 0);\n vec4 edgeData1 = texelFetch(u_edgeDataTexture, e1, 0);\n\n int srcIdx = int(edgeData0.x);\n int tgtIdx = int(edgeData0.y);\n float thickness = edgeData0.z;\n int pathId = int(edgeData1.z);\n\n // --- Fetch path attributes (curvature, etc.) ---\n {\n int edgeIdx = int(a_edgeAttrIndex);\n`).concat(c.fetchCode,`\n`).concat(c.varyingAssignments,`\n }\n\n // --- Fetch node data: geometry (texel 0) + rotation flags (texel 1) ---\n vec4 srcN = readNodeData(u_nodeDataTexture, u_nodeDataTextureWidth, srcIdx);\n vec4 tgtN = readNodeData(u_nodeDataTexture, u_nodeDataTextureWidth, tgtIdx);\n\n vec2 source = srcN.xy;\n vec2 target = tgtN.xy;\n float sourceSize = srcN.z;\n float targetSize = tgtN.z;\n v_sourceNodeSize = sourceSize;\n v_targetNodeSize = targetSize;\n\n // --- Pixel-to-graph conversion (fixed font mode) ---\n float matrixScaleX = length(vec2(u_matrix[0][0], u_matrix[1][0]));\n float pixelToGraph = 2.0 / (matrixScaleX * u_resolution.x);\n\n float webGLThickness = thickness * u_correctionRatio / u_sizeRatio;\n\n // --- Body bounds (shared with edge label shader) ---\n vec4 edgeClamp = readFrameTexel(u_edgeFrameTexture, u_edgeFrameTextureWidth, edgeIdx);\n vec3 bodyBounds = computeEdgeLabelBodyBounds(\n edgeClamp.x, edgeClamp.y, edgeClamp.w,\n webGLThickness, HEAD_RATIO, TAIL_RATIO\n );\n float bodyStartDist = bodyBounds.x;\n float bodyEndDist = bodyBounds.y;\n float bodyLength = bodyBounds.z;\n\n // --- Text dimensions ---\n float baseFontSize = a_baseFontSize;\n `).concat(l?`float fontScale = baseFontSize / ATLAS_FONT_SIZE * u_zoomSizeRatio;\n float textWidthWebGL = a_totalTextWidth * fontScale * u_correctionRatio / u_sizeRatio;\n float halfTextHeight = baseFontSize * 0.35 * u_zoomSizeRatio * u_correctionRatio / u_sizeRatio;\n float marginWebGL = a_margin * u_zoomSizeRatio * u_correctionRatio / u_sizeRatio;`:`float fontScale = baseFontSize / ATLAS_FONT_SIZE;\n float textWidthWebGL = a_totalTextWidth * fontScale * pixelToGraph;\n float halfTextHeight = baseFontSize * 0.35 * pixelToGraph;\n float marginWebGL = a_margin * pixelToGraph;`,`\n float paddingWebGL = a_padding * pixelToGraph;\n\n // --- Alpha modifier (shared with edge label shader) ---\n float alphaModifier = computeEdgeLabelAlpha(bodyLength, textWidthWebGL);\n if (alphaModifier <= 0.0 || textWidthWebGL <= 0.0) {\n gl_Position = vec4(2.0, 0.0, 0.0, 1.0);\n v_color = vec4(0.0);\n v_id = vec4(0.0);\n v_alphaModifier = 0.0;\n return;\n }\n\n // --- Perpendicular offset (shared with edge label shader) ---\n float bodyCenterDist = (bodyStartDist + bodyEndDist) * 0.5;\n float centerT = queryPathTAtDistance(pathId, bodyCenterDist, source, target);\n float screenDir = computeEdgeLabelScreenDir(pathId, centerT, source, target, u_matrix);\n float readingSign = `).concat(s?"screenDir":"1.0",`;\n float halfThickness = webGLThickness * 0.5;\n float perpOffset = computeEdgeLabelPerpOffset(\n a_positionMode, halfThickness, marginWebGL, halfTextHeight, readingSign, screenDir\n );\n\n // --- Ribbon span (clipped to body) ---\n float halfTextWebGL = textWidthWebGL * 0.5;\n float labelStartDist = max(bodyCenterDist - halfTextWebGL, bodyStartDist);\n float labelEndDist = min(bodyCenterDist + halfTextWebGL, bodyEndDist);\n\n // Sample centerline at this pair, then apply perpendicular offset.\n // The ribbon follows the centerline path (simple & robust); for curved edges\n // this closely matches the offset path the characters sit on.\n float u = float(pairIdx) / float(RIBBON_SEGMENTS);\n float arcDist = mix(labelStartDist, labelEndDist, u);\n float t = queryPathTAtDistance(pathId, arcDist, source, target);\n vec2 pos = queryPathPosition(pathId, t, source, target);\n vec2 tan = queryPathTangent(pathId, t, source, target);\n vec2 perp = vec2(-tan.y, tan.x);\n\n vec2 centerPos = pos + perp * perpOffset;\n\n float halfRibbon = halfTextHeight + paddingWebGL;\n float sideSign = side == 0 ? -1.0 : 1.0;\n vec2 ribbonPos = centerPos + perp * (sideSign * halfRibbon);\n\n vec3 clipPos = u_matrix * vec3(ribbonPos, 1.0);\n gl_Position = vec4(clipPos.xy, 0.0, 1.0);\n\n v_color = a_color;\n v_id = a_id;\n v_alphaModifier = alphaModifier;\n}\n`);return g}var lu=`#version 300 es\nprecision highp float;\n\nin vec4 v_color;\nin vec4 v_id;\nin float v_alphaModifier;\n\nout vec4 fragColor;\n\nvoid main() {\n#ifdef PICKING_MODE\n if (v_alphaModifier <= 0.0) discard;\n fragColor = v_id;\n#else\n float alpha = v_color.a * v_alphaModifier;\n if (alpha <= 0.0) discard;\n fragColor = vec4(v_color.rgb * alpha, alpha);\n#endif\n}\n`;function du(e,a,n,t){var r=t.shaderConfig,{paths:i,fontSizeMode:o}=r;if(i.length===0)throw Error("createEdgeLabelBackgroundProgram: shaderConfig must declare at least one path");var s=Ke(),l=Me([].concat(J(i),[s])),d=Nn([].concat(J(i),[s]),l),u=su(r),c=function(g){function h(p,y,v){var f;return ie(this,h),f=fe(this,h,[p,y,v]),R(f,"totalCount",0),R(f,"bufferCapacity",0),R(f,"edgeAttributeTexture",null),f.edgeAttributeTexture=new zn(p,l),f.packedAttributeData=new Float32Array(l.floatsPerItem),f}return ge(h,g),oe(h,[{key:"getDefinition",value:function(){var y=WebGL2RenderingContext,{FLOAT:v,UNSIGNED_BYTE:f,TRIANGLE_STRIP:b}=y,m=[];for(var T=0;T<li;T++)m.push([T]);var _=["u_matrix","u_sizeRatio","u_correctionRatio","u_pixelRatio","u_cameraAngle","u_resolution","u_nodeDataTexture","u_nodeDataTextureWidth","u_edgeDataTexture","u_edgeDataTextureWidth","u_edgeFrameTexture","u_edgeFrameTextureWidth"];if(o==="scaled")_.push("u_zoomSizeRatio");if(l.floatsPerItem>0)_.push("u_edgeAttributeTexture","u_edgeAttributeTextureWidth","u_edgeAttributeTexelsPerEdge");return{VERTICES:li,VERTEX_SHADER_SOURCE:u,FRAGMENT_SHADER_SOURCE:lu,METHOD:b,UNIFORMS:_,ATTRIBUTES:[{name:"a_edgeIndex",size:1,type:v},{name:"a_edgeAttrIndex",size:1,type:v},{name:"a_baseFontSize",size:1,type:v},{name:"a_totalTextWidth",size:1,type:v},{name:"a_positionMode",size:1,type:v},{name:"a_margin",size:1,type:v},{name:"a_padding",size:1,type:v},{name:"a_color",size:4,type:f,normalized:!0},{name:"a_id",size:4,type:f,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_vertexIndex",size:1,type:v}],CONSTANT_DATA:m}}},{key:"processEdgeLabelBackground",value:function(y,v,f){var b=0;if(this.edgeAttributeTexture&&l.floatsPerItem>0){b=this.edgeAttributeTexture.allocate(v);var m=this.packedAttributeData;Gn(d,f.edgeAttributes,m,"",ou,0),this.edgeAttributeTexture.updateAllAttributes(v,m)}var T=this.floats,_=this.ints,x=y*this.STRIDE;T[x++]=f.edgeIndex,T[x++]=b,T[x++]=f.baseFontSize,T[x++]=f.totalTextWidth,T[x++]=f.positionMode,T[x++]=f.margin,T[x++]=f.padding,T[x++]=f.color,_[x++]=f.id}},{key:"setUniforms",value:function(y,v){var{gl:f,uniformLocations:b}=v;if(f.uniformMatrix3fv(b.u_matrix,!1,y.matrix),f.uniform1f(b.u_sizeRatio,y.sizeRatio),f.uniform1f(b.u_correctionRatio,y.correctionRatio),f.uniform1f(b.u_pixelRatio,y.pixelRatio),f.uniform1f(b.u_cameraAngle,y.cameraAngle),f.uniform2f(b.u_resolution,y.width,y.height),b.u_nodeDataTexture!==void 0)f.uniform1i(b.u_nodeDataTexture,y.nodeDataTextureUnit);if(b.u_nodeDataTextureWidth!==void 0)f.uniform1i(b.u_nodeDataTextureWidth,y.nodeDataTextureWidth);if(b.u_edgeDataTexture!==void 0)f.uniform1i(b.u_edgeDataTexture,y.edgeDataTextureUnit);if(b.u_edgeDataTextureWidth!==void 0)f.uniform1i(b.u_edgeDataTextureWidth,y.edgeDataTextureWidth);if(b.u_edgeFrameTexture!==void 0)f.uniform1i(b.u_edgeFrameTexture,y.edgeFrameTextureUnit);if(b.u_edgeFrameTextureWidth!==void 0)f.uniform1i(b.u_edgeFrameTextureWidth,y.edgeFrameTextureWidth);if(o==="scaled"&&b.u_zoomSizeRatio!==void 0){var m=this.renderer.getSetting("zoomToSizeRatioFunction");f.uniform1f(b.u_zoomSizeRatio,1/m(y.zoomRatio))}if(this.edgeAttributeTexture&&l.floatsPerItem>0&&b.u_edgeAttributeTexture!==void 0)this.edgeAttributeTexture.bind(Je),f.uniform1i(b.u_edgeAttributeTexture,Je),f.uniform1i(b.u_edgeAttributeTextureWidth,this.edgeAttributeTexture.getTextureWidth()),f.uniform1i(b.u_edgeAttributeTexelsPerEdge,this.edgeAttributeTexture.getTexelsPerItem())}},{key:"renderProgram",value:function(y,v){if(this.edgeAttributeTexture&&l.floatsPerItem>0)this.edgeAttributeTexture.upload();xe(h,"renderProgram",this,3)([y,v])}},{key:"kill",value:function(){if(this.edgeAttributeTexture)this.edgeAttributeTexture.kill(),this.edgeAttributeTexture=null;xe(h,"kill",this,3)([])}},{key:"drawWebGL",value:function(y,v){var f=v.gl;if(this.totalCount===0)return;f.drawArraysInstanced(f.TRIANGLE_STRIP,0,this.VERTICES,this.totalCount)}},{key:"reallocate",value:function(y){if(this.totalCount=y,y>this.bufferCapacity)this.bufferCapacity=Math.max(y,Math.ceil(this.bufferCapacity*1.5)||10),xe(h,"reallocate",this,3)([this.bufferCapacity])}}])}(st);return new c(e,a,n)}function Di(e){var a,n,t,r,i,o;return{paths:e.paths,headLengthRatio:(a=e.headLengthRatio)!==null&&a!==void 0?a:0,tailLengthRatio:(n=e.tailLengthRatio)!==null&&n!==void 0?n:0,fontSizeMode:(t=e.fontSizeMode)!==null&&t!==void 0?t:"fixed",minVisibilityThreshold:(r=e.minVisibilityThreshold)!==null&&r!==void 0?r:0.7,fullVisibilityThreshold:(i=e.fullVisibilityThreshold)!==null&&i!==void 0?i:0.8,keepUpright:(o=e.keepUpright)!==null&&o!==void 0?o:!0}}var uu=Be.fontSize,cu=0.265625;function hu(e){var{paths:a,hasBorder:n}=e,t=n===void 0?!1:n,r=e.fontSizeMode,i=r===void 0?"fixed":r,o=e.minVisibilityThreshold,s=o===void 0?0.5:o,l=e.fullVisibilityThreshold,d=l===void 0?0.6:l,u=e.keepUpright,c=u===void 0?!0:u,g=i==="scaled",h=a.some(function(b){return b.hasSharpCorners}),p=Ke(),y=Me([].concat(J(a),[p])),v=Kt(y),f=`#version 300 es\n\n// ============================================================================\n// Attributes - Per Character (Instanced)\n// ============================================================================\n\n// Edge geometry: indices for texture lookup\n// Edge data (source/target node indices, thickness, head/tail ratios) is fetched from edge data texture\n// Edge path attributes (curvature, etc.) are fetched from edge attribute texture\nin float a_edgeIndex; // Index into edge data texture\nin float a_edgeAttrIndex; // Index into edge attribute texture (for curvature, etc.)\nin float a_baseFontSize; // Base font size in pixels (per-label)\n\n// Character metrics (in glyph units = atlas font size pixels)\nin vec4 a_charMetrics; // (charTextOffset, charAdvance, totalTextWidth, positionMode)\nin vec4 a_charDims; // (charSize.x, charSize.y, charOffset.x, charOffset.y)\n\n// Atlas texture coordinates\nin vec4 a_texCoords; // (x, y, width, height) in atlas pixels\n\n// Label parameters\nin vec2 a_labelParams; // (margin, unused)\n\n// Appearance\nin vec4 a_color; // Character color (RGBA, normalized)\n`.concat(t?"in vec4 a_borderColor; // Border color (RGBA, normalized)":"",`\n\n// ============================================================================\n// Attributes - Per Vertex (Constant)\n// ============================================================================\n\nin vec2 a_quadCorner; // Quad corner: (0,0), (1,0), (0,1), (1,1)\n\n// ============================================================================\n// Uniforms\n// ============================================================================\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\nuniform float u_pixelRatio;\nuniform float u_cameraAngle; // Required by node shape SDFs\n// u_sdfBufferPixels kept for ABI compatibility but unused in shader\nuniform float u_sdfBufferPixels;\nuniform vec2 u_resolution;\nuniform vec2 u_atlasSize;\nuniform sampler2D u_nodeDataTexture; // Shared texture with node position/size/shape data\nuniform int u_nodeDataTextureWidth; // Width of 2D node data texture for coordinate calculation\nuniform sampler2D u_edgeDataTexture; // Shared texture with edge data\nuniform int u_edgeDataTextureWidth; // Width of 2D edge data texture for coordinate calculation\nuniform sampler2D u_edgeFrameTexture; // Per-edge clamp (tStart, tEnd, straightenFactor, pathLength)\nuniform int u_edgeFrameTextureWidth;\n`).concat(g?"uniform float u_zoomSizeRatio; // Zoom-based size ratio from zoomToSizeRatioFunction":"",`\n\n// Edge path attribute texture uniforms (for curvature and other path attributes)\n`).concat(v.uniformDeclarations,`\n\n// ============================================================================\n// Varyings\n// ============================================================================\n\nout vec2 v_texCoord;\nout vec4 v_color;\n`).concat(t?"out vec4 v_borderColor;":"",`\nout float v_edgeFade; // 0 = fully visible, 1 = fully faded (outside body)\nout float v_alphaModifier; // 0-1 based on label visibility ratio\nout float v_fontScale; // Ratio of rendered font size to atlas font size\n`).concat(t?"out float v_positionMode; // Position mode for conditional border (0=over needs border)":"",`\n\n// ============================================================================\n// Constants\n// ============================================================================\n\nconst float bias = 255.0 / 254.0;\nconst float FADE_WIDTH_PIXELS = 15.0; // Width of fade gradient in pixels\nconst float ATLAS_FONT_SIZE = `).concat(ve(uu),`; // Base font size used in SDF atlas\nconst float VERTICAL_CENTER_RATIO = `).concat(ve(cu),`; // Baseline to visual center ratio\n\n// ============================================================================\n// Path Attribute Variables (set in main, used by path functions)\n// ============================================================================\n// Path attributes are fetched from the edge attribute texture and stored in\n// variables with v_ prefix (e.g., v_curvature) for path functions to access.\n`).concat(v.vertexVaryingDeclarations.replace(/out /g,""),`\n\n// Node size variables (set in main, used by some path functions like loops).\n// These mirror the v_sourceNodeSize / v_targetNodeSize varyings in generator.ts,\n// but are plain floats here since the label shader is vertex-only.\nfloat v_sourceNodeSize;\nfloat v_targetNodeSize;\n\n// Shared preamble: shape SDFs, path functions + selectors, clamp, helpers.\n`).concat(Ai({paths:a,minVisibilityThreshold:s,fullVisibilityThreshold:d}),`\n\n// ============================================================================\n// Main\n// ============================================================================\n\nvoid main() {\n // -------------------------------------------------------------------------\n // Fetch edge data from edge texture (2 texels per edge)\n // -------------------------------------------------------------------------\n // Texel 0: sourceNodeIndex, targetNodeIndex, thickness, reserved\n // Texel 1: headLengthRatio, tailLengthRatio, pathId, extremityIds\n int edgeIdx = int(a_edgeIndex);\n int texel0Idx = edgeIdx * 2;\n int texel1Idx = edgeIdx * 2 + 1;\n ivec2 edgeTexCoord0 = ivec2(texel0Idx % u_edgeDataTextureWidth, texel0Idx / u_edgeDataTextureWidth);\n ivec2 edgeTexCoord1 = ivec2(texel1Idx % u_edgeDataTextureWidth, texel1Idx / u_edgeDataTextureWidth);\n vec4 edgeData0 = texelFetch(u_edgeDataTexture, edgeTexCoord0, 0);\n vec4 edgeData1 = texelFetch(u_edgeDataTexture, edgeTexCoord1, 0);\n\n // Unpack edge data\n int srcIdx = int(edgeData0.x);\n int tgtIdx = int(edgeData0.y);\n float thickness = edgeData0.z;\n // edgeData0.w is reserved\n float headLengthRatio = edgeData1.x;\n float tailLengthRatio = edgeData1.y;\n int pathId = int(edgeData1.z); // Path type for multi-path support\n float baseFontSize = a_baseFontSize;\n\n // -------------------------------------------------------------------------\n // Fetch path attributes from edge attribute texture\n // -------------------------------------------------------------------------\n // Note: The fetch code uses \'edgeIdx\' variable, so we set it to the attribute texture index\n {\n int edgeIdx = int(a_edgeAttrIndex); // Use attribute texture index for path attributes\n`).concat(v.fetchCode,`\n`).concat(v.varyingAssignments,`\n }\n\n // -------------------------------------------------------------------------\n // Fetch node data from node texture (geometry texel + rotation-flags texel)\n // -------------------------------------------------------------------------\n vec4 srcNodeData = readNodeData(u_nodeDataTexture, u_nodeDataTextureWidth, srcIdx);\n vec4 tgtNodeData = readNodeData(u_nodeDataTexture, u_nodeDataTextureWidth, tgtIdx);\n\n vec2 source = srcNodeData.xy;\n vec2 target = tgtNodeData.xy;\n float sourceSize = srcNodeData.z;\n float targetSize = tgtNodeData.z;\n v_sourceNodeSize = sourceSize;\n v_targetNodeSize = targetSize;\n float charTextOffset = a_charMetrics.x;\n float charAdvance = a_charMetrics.y;\n float totalTextWidth = a_charMetrics.z;\n float positionMode = a_charMetrics.w;\n vec2 charSize = a_charDims.xy;\n vec2 charOffset = a_charDims.zw;\n float margin = a_labelParams.x;\n\n // -------------------------------------------------------------------------\n // Compute pixel-to-graph conversion (for fixed font size mode)\n // -------------------------------------------------------------------------\n // This converts screen pixels to graph units such that N pixels on screen\n // becomes N pixels regardless of zoom level.\n // matrixScaleX is how much the matrix scales graph units to clip space\n float matrixScaleX = length(vec2(u_matrix[0][0], u_matrix[1][0]));\n float pixelToGraph = 2.0 / (matrixScaleX * u_resolution.x);\n\n // -------------------------------------------------------------------------\n // Step 1: Convert thickness to WebGL units\n // -------------------------------------------------------------------------\n float webGLThickness = thickness * u_correctionRatio / u_sizeRatio;\n\n // -------------------------------------------------------------------------\n // Step 2: Compute body bounds (truncated at node boundaries + extremities)\n // -------------------------------------------------------------------------\n vec4 edgeClamp = readFrameTexel(u_edgeFrameTexture, u_edgeFrameTextureWidth, edgeIdx);\n vec3 bodyBounds = computeEdgeLabelBodyBounds(\n edgeClamp.x, edgeClamp.y, edgeClamp.w,\n webGLThickness, headLengthRatio, tailLengthRatio\n );\n float bodyStartDist = bodyBounds.x;\n float bodyEndDist = bodyBounds.y;\n float bodyLength = bodyBounds.z;\n\n // -------------------------------------------------------------------------\n // Step 3: Compute font scale and text dimensions\n // -------------------------------------------------------------------------\n // Font size modes:\n // - "fixed": Constant pixel size regardless of zoom, using pixelToGraph conversion\n // - "scaled": Scales with zoom using zoomToSizeRatioFunction\n `).concat(g?`// Scaled mode: font scales with zoom\n float fontScale = baseFontSize / ATLAS_FONT_SIZE * u_zoomSizeRatio;\n // Convert glyph-unit metrics to WebGL units (scales with zoom)\n float textWidthWebGL = totalTextWidth * fontScale * u_correctionRatio / u_sizeRatio;\n float charOffsetWebGL = charTextOffset * fontScale * u_correctionRatio / u_sizeRatio;\n float charAdvanceWebGL = charAdvance * fontScale * u_correctionRatio / u_sizeRatio;`:`// Fixed mode: font stays constant in screen pixels\n float fontScale = baseFontSize / ATLAS_FONT_SIZE;\n // Convert glyph-unit metrics to graph units using pixelToGraph (zoom-independent)\n float textWidthWebGL = totalTextWidth * fontScale * pixelToGraph;\n float charOffsetWebGL = charTextOffset * fontScale * pixelToGraph;\n float charAdvanceWebGL = charAdvance * fontScale * pixelToGraph;`,`\n\n // Font scale varying for fragment shader gamma scaling.\n // Ratio of rendered font size to atlas font size — used to tighten the\n // anti-aliasing band for large labels so they stay sharp.\n v_fontScale = fontScale;\n\n // -------------------------------------------------------------------------\n // Step 4: Alpha modifier from how much of the label fits in the body\n // -------------------------------------------------------------------------\n float alphaModifier = computeEdgeLabelAlpha(bodyLength, textWidthWebGL);\n\n // -------------------------------------------------------------------------\n // Step 5: Compute character center offset (truncation check moved to after curvature adjustment)\n // -------------------------------------------------------------------------\n // Body center in arc distance\n float bodyCenterDist = (bodyStartDist + bodyEndDist) * 0.5;\n\n float centerT = queryPathTAtDistance(pathId, bodyCenterDist, source, target);\n float screenDir = computeEdgeLabelScreenDir(pathId, centerT, source, target, u_matrix);\n\n // Reversed labels lay their characters out from target to source\n float readingSign = `).concat(c?"screenDir":"1.0",`;\n\n // Character center position relative to label center (on centerline, before curvature adjustment)\n float charCenterOffset = readingSign * (charOffsetWebGL + charAdvanceWebGL * 0.5 - textWidthWebGL * 0.5);\n\n // -------------------------------------------------------------------------\n // Step 6: Compute perpendicular offset based on position mode\n // -------------------------------------------------------------------------\n // Position modes: 0=over, 1=above, 2=below, 3=auto\n // Needed early for curvature-adaptive character spacing in Step 7\n float halfThickness = webGLThickness * 0.5;\n `).concat(g?`// Scaled mode: margin and text height scale with zoom (same factor as font)\n float marginWebGL = margin * u_zoomSizeRatio * u_correctionRatio / u_sizeRatio;\n float halfTextHeight = baseFontSize * 0.35 * u_zoomSizeRatio * u_correctionRatio / u_sizeRatio;`:`// Fixed mode: margin and text height stay constant in screen pixels\n float marginWebGL = margin * pixelToGraph;\n float halfTextHeight = baseFontSize * 0.35 * pixelToGraph;`,`\n float perpOffset = computeEdgeLabelPerpOffset(\n positionMode, halfThickness, marginWebGL, halfTextHeight, readingSign, screenDir\n );\n\n // -------------------------------------------------------------------------\n // Step 7: Position character on path using offset path traversal\n // -------------------------------------------------------------------------\n // For "over" mode (perpOffset = 0), use simple centerline placement\n // For above/below modes, walk along the offset path to find correct position\n float charT;\n\n if (perpOffset == 0.0) {\n // Simple case: place on centerline\n float charArcDist = bodyCenterDist + charCenterOffset;\n charT = queryPathTAtDistance(pathId, charArcDist, source, target);\n } else {\n // Offset path traversal: walk along the offset curve to find character position\n // This ensures even character spacing regardless of curvature\n\n `).concat(h?`// -----------------------------------------------------------------------\n // Corner skip setup for step/taxi edges with above/below labels\n // -----------------------------------------------------------------------\n // At concave corners (inner side of the bend), characters would bunch up\n // because the offset path has near-zero arc length. We detect corner\n // crossings during the offset path traversal and add skip distance.\n\n // Get corner t values and concavity\n vec2 cornerTs = queryGetCornerTs(pathId, source, target);\n vec2 concavity = queryGetCornerConcavity(pathId, source, target, perpOffset);\n\n // Skip distance in graph units, proportional to on-screen font size\n // For fixed mode: use pixelToGraph so gap stays constant regardless of zoom\n // For scaled mode: use the same conversion as text width\n `.concat(g?"float skipDistGraph = STEP_INNER_CORNER_SKIP_FACTOR * baseFontSize * u_zoomSizeRatio * u_correctionRatio / u_sizeRatio;":"float skipDistGraph = STEP_INNER_CORNER_SKIP_FACTOR * baseFontSize * pixelToGraph;",`\n\n // Corner t values for detecting crossings during traversal\n float corner1T = cornerTs.x;\n float corner2T = cornerTs.y;\n bool corner1IsConcave = concavity.x > 0.5;\n bool corner2IsConcave = concavity.y > 0.5;`):"",`\n\n // Target distance along offset path from center\n float targetOffsetDist = abs(charCenterOffset);\n\n // Handle center character (charCenterOffset ≈ 0) - no search needed\n if (targetOffsetDist < 0.0001) {\n charT = centerT;\n } else {\n vec2 centerPos = queryPathPosition(pathId, centerT, source, target);\n vec2 centerNormal = queryPathNormal(pathId, centerT, source, target);\n vec2 offsetCenter = centerPos + centerNormal * perpOffset;\n\n float searchDir = charCenterOffset > 0.0 ? 1.0 : -1.0;\n\n // Search bounds (t values for body start and end)\n float tBodyStart = queryPathTAtDistance(pathId, bodyStartDist, source, target);\n float tBodyEnd = queryPathTAtDistance(pathId, bodyEndDist, source, target);\n\n // Walk along offset path to find character position\n float accumDist = 0.0;\n vec2 prevOffsetPos = offsetCenter;\n float prevT = centerT;\n float foundT = centerT;\n\n // Search range depends on direction\n float tSearchEnd = searchDir > 0.0 ? tBodyEnd : tBodyStart;\n\n `).concat(h?`// Track which concave corners we\'ve crossed to add skip distance\n bool crossedCorner1 = false;\n bool crossedCorner2 = false;\n float effectiveTargetDist = targetOffsetDist;`:"",`\n\n const int STEPS = 32;\n for (int i = 1; i <= STEPS; i++) {\n // Step along centerline t, from center toward target\n float stepT = centerT + searchDir * float(i) * abs(tSearchEnd - centerT) / float(STEPS);\n\n `).concat(h?`// Check for concave corner crossings and add skip distance\n // Corner 1 crossing check\n if (corner1IsConcave && !crossedCorner1) {\n bool crossingCorner1 = (searchDir > 0.0)\n ? (prevT < corner1T && stepT >= corner1T)\n : (prevT > corner1T && stepT <= corner1T);\n if (crossingCorner1) {\n crossedCorner1 = true;\n effectiveTargetDist += skipDistGraph;\n }\n }\n\n // Corner 2 crossing check\n if (corner2IsConcave && !crossedCorner2) {\n bool crossingCorner2 = (searchDir > 0.0)\n ? (prevT < corner2T && stepT >= corner2T)\n : (prevT > corner2T && stepT <= corner2T);\n if (crossingCorner2) {\n crossedCorner2 = true;\n effectiveTargetDist += skipDistGraph;\n }\n }`:"",`\n\n // Compute offset position at this t\n vec2 stepPos = queryPathPosition(pathId, stepT, source, target);\n vec2 stepNormal = queryPathNormal(pathId, stepT, source, target);\n vec2 offsetPos = stepPos + stepNormal * perpOffset;\n\n // Distance along offset path\n float segDist = length(offsetPos - prevOffsetPos);\n\n `).concat(h?`if (accumDist + segDist >= effectiveTargetDist) {\n // Interpolate within segment to find exact t\n float remaining = effectiveTargetDist - accumDist;\n float segT = remaining / max(segDist, 0.0001);\n foundT = mix(prevT, stepT, segT);\n break;\n }`:`if (accumDist + segDist >= targetOffsetDist) {\n // Interpolate within segment to find exact t\n float remaining = targetOffsetDist - accumDist;\n float segT = remaining / max(segDist, 0.0001);\n foundT = mix(prevT, stepT, segT);\n break;\n }`,`\n\n accumDist += segDist;\n prevOffsetPos = offsetPos;\n prevT = stepT;\n // Update foundT to last valid position in case loop exhausts without finding target\n foundT = stepT;\n }\n\n charT = foundT;\n }\n }\n\n // Get position and tangent at final character position\n vec2 pathPos = queryPathPosition(pathId, charT, source, target);\n vec2 tangent = queryPathTangent(pathId, charT, source, target);\n\n // Compute perpendicular direction (90 degrees from tangent)\n vec2 perpDir = vec2(-tangent.y, tangent.x);\n\n // Apply perpendicular offset to path position\n vec2 offsetPathPos = pathPos + perpDir * perpOffset;\n\n // -------------------------------------------------------------------------\n // Step 8: Build character quad\n // -------------------------------------------------------------------------\n // Character size in screen pixels\n vec2 charSizePixels = charSize * fontScale;\n\n // Character offset from origin to the atlas region\'s top-left corner.\n // bearingX/bearingY already include the SDF buffer.\n vec2 charOffsetPixels = charOffset * fontScale;\n\n // The character\'s local X offset from pathPos (which is at character center)\n float charLocalX = -charAdvance * 0.5 * fontScale;\n\n // Build quad position:\n // - Start at character origin (charLocalX on X axis, 0 on Y axis = baseline)\n // - Add bearing offset to get to atlas region corner\n // - Add quad corner * size to get vertex position\n vec2 quadPos;\n quadPos.x = charLocalX + charOffsetPixels.x + a_quadCorner.x * charSizePixels.x;\n // charOffset.y = -bearingY (negated), so -charOffsetPixels.y = bearingY * fontScale\n // (distance from baseline to atlas region top, positive = upward)\n // Quad corner (0,0) = bottom-left, (1,1) = top-right\n quadPos.y = -charOffsetPixels.y - charSizePixels.y * (1.0 - a_quadCorner.y);\n\n // Center vertically on the path by offsetting by half the visual text height\n // VERTICAL_CENTER_RATIO is the distance from baseline to visual center as a ratio of atlas font size\n float verticalCenterOffset = VERTICAL_CENTER_RATIO * ATLAS_FONT_SIZE * fontScale;\n quadPos.y -= verticalCenterOffset;\n\n // -------------------------------------------------------------------------\n // Step 9: Rotate quad to align with tangent\n // -------------------------------------------------------------------------\n // Rotation matrix from the reading direction\n // readingDir = (cos(angle), sin(angle)), so we can build rotation directly\n vec2 readingDir = tangent * readingSign;\n mat2 rotation = mat2(readingDir.x, readingDir.y, -readingDir.y, readingDir.x);\n\n // Convert pixel offset to WebGL units for rotation\n `).concat(g?"vec2 quadPosWebGL = quadPos * u_correctionRatio / u_sizeRatio; // Scaled mode":"vec2 quadPosWebGL = quadPos * pixelToGraph; // Fixed mode: use pixelToGraph for zoom-independent size",`\n\n // Rotate around character center on path\n vec2 rotatedOffset = rotation * quadPosWebGL;\n\n // Final position in graph space (using offset path position for above/below modes)\n vec2 worldPos = offsetPathPos + rotatedOffset;\n\n // -------------------------------------------------------------------------\n // Step 10: Transform to clip space\n // -------------------------------------------------------------------------\n vec3 clipPos = u_matrix * vec3(worldPos, 1.0);\n gl_Position = vec4(clipPos.xy, 0.0, 1.0);\n\n // -------------------------------------------------------------------------\n // Step 11: Texture coordinates\n // -------------------------------------------------------------------------\n // Flip Y for texture coordinates (texture Y goes down, quad Y goes up)\n vec2 texCorner = vec2(a_quadCorner.x, 1.0 - a_quadCorner.y);\n v_texCoord = (a_texCoords.xy + texCorner * a_texCoords.zw) / u_atlasSize;\n\n // -------------------------------------------------------------------------\n // Step 12: Pass color, border color, and alpha modifier\n // -------------------------------------------------------------------------\n v_color = a_color;\n v_color.a *= bias;\n`).concat(t?` v_borderColor = a_borderColor;\n v_borderColor.a *= bias;\n v_positionMode = positionMode;`:"",`\n v_alphaModifier = alphaModifier;\n\n // -------------------------------------------------------------------------\n // Step 13: Compute edge fade for soft truncation\n // -------------------------------------------------------------------------\n // Convert fade width from pixels to WebGL units\n `).concat(g?"float fadeWidthWebGL = FADE_WIDTH_PIXELS * u_correctionRatio / u_sizeRatio;":"float fadeWidthWebGL = FADE_WIDTH_PIXELS * pixelToGraph;",`\n\n // Compute the arc position of THIS VERTEX (not just character center)\n // The quad extends from charCenter - advance/2 to charCenter + advance/2\n // a_quadCorner.x is 0 for left edge, 1 for right edge\n float vertexLocalOffset = readingSign * (a_quadCorner.x - 0.5) * charAdvanceWebGL;\n float vertexArcOffset = charCenterOffset + vertexLocalOffset;\n\n // Compute distance from body edges (positive = inside body, negative = outside)\n float halfBody = bodyLength * 0.5;\n float distFromStart = vertexArcOffset + halfBody; // Distance from body start edge\n float distFromEnd = halfBody - vertexArcOffset; // Distance from body end edge\n float distFromEdge = min(distFromStart, distFromEnd);\n\n // Compute fade: 0 = fully visible (deep inside body), 1 = fully faded (at body edge)\n // Fade goes from 0 (at 2*fadeWidth inside) to 1 (at body edge)\n // This ensures text is fully transparent before reaching extremities\n v_edgeFade = 1.0 - smoothstep(0.0, fadeWidthWebGL * 2.0, distFromEdge);\n}\n`);return f}function fu(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},a=e.hasBorder,n=a===void 0?!1:a,t=`#version 300 es\nprecision highp float;\n\nin vec2 v_texCoord;\nin vec4 v_color;\n`.concat(n?"in vec4 v_borderColor;":"",`\nin float v_edgeFade; // 0 = fully visible, 1 = fully faded\nin float v_alphaModifier; // 0-1 based on label visibility ratio\nin float v_fontScale; // Ratio of rendered font size to atlas font size\n`).concat(n?"in float v_positionMode; // Position mode (0=over, 1=above, 2=below, 3=auto)":"",`\n\nuniform sampler2D u_atlas;\nuniform float u_gamma;\nuniform float u_sdfBuffer;\nuniform float u_pixelRatio;\n`).concat(n?"uniform float u_borderWidth; // Border width in SDF units (normalized)":"",`\n\n// Fragment output (single target - picking handled via separate pass)\nout vec4 fragColor;\n\nvoid main() {\n #ifdef PICKING_MODE\n // Edge labels are not pickable - discard all fragments in picking mode\n fragColor = vec4(0.0);\n discard;\n #else\n // SDF stores normalized distance: 0.5 = on edge, >0.5 = inside glyph\n float sdfValue = texture(u_atlas, v_texCoord).a;\n\n // Edge threshold accounting for SDF buffer padding\n float edge = 1.0 - u_sdfBuffer;\n\n // Scale gamma inversely with font scale so small labels get a wider AA band\n // (smoother) and large labels get a tighter band (sharper).\n float aaWidth = u_gamma / (u_pixelRatio * v_fontScale);\n\n // Apply edge fade for soft truncation at body boundaries\n // Also apply visibility-based alpha modifier for short edge labels\n float edgeAlpha = (1.0 - v_edgeFade) * v_alphaModifier;\n\n`).concat(n?` // Fill alpha: fully opaque inside the glyph\n float fillAlpha = smoothstep(edge - aaWidth, edge + aaWidth, sdfValue);\n\n // Only apply border for "over" position mode (v_positionMode == 0.0)\n // Labels positioned above/below/auto don\'t overlap the edge line and don\'t need borders\n if (v_positionMode < 0.5) {\n // Border rendering: compute alpha for both fill and border regions\n // Border extends from (edge - borderWidth) to edge\n float borderEdge = edge - u_borderWidth;\n\n // Border alpha: opaque in the border region (between borderEdge and edge)\n float borderAlpha = smoothstep(borderEdge - aaWidth, borderEdge + aaWidth, sdfValue);\n\n // Composite: fill on top of border\n // Border is visible where borderAlpha > 0 but fillAlpha < 1\n vec3 borderColorPremult = v_borderColor.rgb * v_borderColor.a * borderAlpha * edgeAlpha;\n vec3 fillColorPremult = v_color.rgb * v_color.a * fillAlpha * edgeAlpha;\n\n // Blend fill over border (fill replaces border where fill is opaque)\n float finalBorderAlpha = borderAlpha * (1.0 - fillAlpha);\n vec3 finalColor = fillColorPremult + v_borderColor.rgb * v_borderColor.a * finalBorderAlpha * edgeAlpha;\n float finalAlpha = (v_color.a * fillAlpha + v_borderColor.a * finalBorderAlpha) * edgeAlpha;\n\n fragColor = vec4(finalColor, finalAlpha);\n } else {\n // No border for above/below/auto positions - simple text rendering\n float finalAlpha = v_color.a * fillAlpha * edgeAlpha;\n fragColor = vec4(v_color.rgb * finalAlpha, finalAlpha);\n }`:` // Smooth transition from transparent to opaque at glyph edge\n float alpha = smoothstep(edge - aaWidth, edge + aaWidth, sdfValue);\n\n // Premultiplied alpha output\n float finalAlpha = v_color.a * alpha * edgeAlpha;\n fragColor = vec4(v_color.rgb * finalAlpha, finalAlpha);`,`\n #endif\n}\n`);return t}function gu(e){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:"fixed",t=["u_matrix","u_sizeRatio","u_correctionRatio","u_pixelRatio","u_cameraAngle","u_sdfBufferPixels","u_resolution","u_atlasSize","u_atlas","u_gamma","u_sdfBuffer","u_nodeDataTexture","u_nodeDataTextureWidth","u_edgeDataTexture","u_edgeDataTextureWidth","u_edgeFrameTexture","u_edgeFrameTextureWidth","u_edgeAttributeTexture","u_edgeAttributeTextureWidth","u_edgeAttributeTexelsPerEdge"];if(n==="scaled")t.push("u_zoomSizeRatio");if(a)t.push("u_borderWidth");var r=W(e),i;try{for(r.s();!(i=r.n()).done;){var o=i.value,s=W(o.uniforms),l;try{for(s.s();!(l=s.n()).done;){var d=l.value;if(!t.includes(d.name))t.push(d.name)}}catch(u){s.e(u)}finally{s.f()}}}catch(u){r.e(u)}finally{r.f()}return t}function vu(e){var a=e.hasBorder,n=a===void 0?!1:a,t=e.fontSizeMode,r=t===void 0?"fixed":t;return{vertexShader:hu(e),fragmentShader:fu({hasBorder:n}),uniforms:gu(e.paths,n,r)}}var pu=new Map;function mu(e){switch(e){case"over":return 0;case"above":return 1;case"below":return 2;case"auto":return 3;default:return 0}}function bu(e,a,n,t){var{color:r,margin:i,textBorder:o}=t,s=Di(t),{paths:l,fontSizeMode:d,minVisibilityThreshold:u,fullVisibilityThreshold:c,keepUpright:g}=s,h=!!o,p=vu({paths:l,hasBorder:h,fontSizeMode:d,minVisibilityThreshold:u,fullVisibilityThreshold:c,keepUpright:g}),y=function(v){function f(b,m,T){var _;ie(this,f),_=fe(this,f,[b,m,T]),R(_,"atlasTexture",null),R(_,"atlasNeedsUpdate",!1),R(_,"refreshTimeout",null),R(_,"labelGlyphCache",new Map),R(_,"edgeAttributeTexture",null);var x=Ke();if(_.attributeLayout=Me([].concat(J(l),[x])),_.attrDescriptors=Nn([].concat(J(l),[x]),_.attributeLayout),_.edgeAttributeTexture=new zn(b,_.attributeLayout),_.packedAttributeData=new Float32Array(_.attributeLayout.floatsPerItem),_.atlasManager=new it,_.gamma=0.025,_.sdfBuffer=Be.cutoff,_.atlasTexture=b.createTexture(),!_.atlasTexture)throw Error("EdgeLabelProgram: failed to create atlas texture");b.bindTexture(b.TEXTURE_2D,_.atlasTexture),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.LINEAR),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.LINEAR),b.bindTexture(b.TEXTURE_2D,null),_.atlasManager.on(it.ATLAS_UPDATED_EVENT,function(){if(_.atlasNeedsUpdate=!0,_.refreshTimeout!==null)clearTimeout(_.refreshTimeout);_.refreshTimeout=setTimeout(function(){_.refreshTimeout=null,_.renderer.refresh()},0)});var S={family:"sans-serif",weight:"normal",style:"normal"};return _.defaultFontKey=_.atlasManager.registerFont(S),_}return ge(f,v),oe(f,[{key:"getDefinition",value:function(){var m=WebGL2RenderingContext,{FLOAT:T,UNSIGNED_BYTE:_,TRIANGLE_STRIP:x}=m,S=new Set,E=[],D=W(l),A;try{for(D.s();!(A=D.n()).done;){var L=A.value,w=W(L.attributes),M;try{for(w.s();!(M=w.n()).done;){var C=M.value,z=C.name.startsWith("a_")?C.name:"a_".concat(C.name);if(!S.has(z))S.add(z),E.push({name:z,size:C.size,type:C.type})}}catch(O){w.e(O)}finally{w.f()}}}catch(O){D.e(O)}finally{D.f()}return{VERTICES:4,VERTEX_SHADER_SOURCE:p.vertexShader,FRAGMENT_SHADER_SOURCE:p.fragmentShader,METHOD:x,UNIFORMS:p.uniforms,ATTRIBUTES:[{name:"a_edgeIndex",size:1,type:T},{name:"a_edgeAttrIndex",size:1,type:T},{name:"a_baseFontSize",size:1,type:T},{name:"a_charMetrics",size:4,type:T},{name:"a_charDims",size:4,type:T},{name:"a_texCoords",size:4,type:T},{name:"a_labelParams",size:2,type:T},{name:"a_color",size:4,type:_,normalized:!0}].concat(J(h?[{name:"a_borderColor",size:4,type:_,normalized:!0}]:[]),J(E.filter(function(O){return!["a_curvature","curvature"].includes(O.name)}))),CONSTANT_ATTRIBUTES:[{name:"a_quadCorner",size:2,type:T}],CONSTANT_DATA:[[0,0],[1,0],[0,1],[1,1]]}}},{key:"prepareLabelGlyphs",value:function(m,T){if(T.hidden||!T.text){this.labelGlyphCache.delete(m);return}var _=T.text,x=T.fontKey||this.defaultFontKey;this.atlasManager.ensureGlyphs(_,x);var S=[],E=[],D=0,A=W(_),L;try{for(A.s();!(L=A.n()).done;){var w=L.value,M=w.codePointAt(0);if(M===void 0){S.push(void 0),E.push(D);continue}var C=this.atlasManager.getGlyph(M,x);if(S.push(C),E.push(D),C)D+=C.advance}}catch(z){A.e(z)}finally{A.f()}this.labelGlyphCache.set(m,{glyphs:S,xOffsets:E,totalWidth:D})}},{key:"processCharacter",value:function(m,T,_,x){var S,E,D,A=this.floats,L=this.STRIDE,w=m*L,M=this.labelGlyphCache.get(T.parentKey);if(!M||!M.glyphs[x]){for(var C=0;C<L;C++)A[w+C]=0;return}var z=M.glyphs[x],O=M.xOffsets[x],N=f.labelColor,F=N&&se(N)==="object"&&"color"in N&&N.color?N.color:T.color,P=Pe(F),B=w;A[B++]=T.edgeIndex,A[B++]=(S=(E=this.edgeAttributeTexture)===null||E===void 0?void 0:E.getIndex(T.parentKey))!==null&&S!==void 0?S:0,A[B++]=T.size,A[B++]=O,A[B++]=z.advance,A[B++]=M.totalWidth,A[B++]=mu(T.position),A[B++]=z.atlasWidth,A[B++]=z.atlasHeight,A[B++]=z.bearingX,A[B++]=-z.bearingY,A[B++]=z.atlasX,A[B++]=z.atlasY,A[B++]=z.atlasWidth,A[B++]=z.atlasHeight;var Y=(D=f.labelMargin)!==null&&D!==void 0?D:T.margin;if(A[B++]=Y,A[B++]=0,A[B++]=P,h&&o){var q;if(typeof o.color==="string")q=o.color;else q=o.color.color||"#ffffff";A[B++]=Pe(q)}var re=new Set,Z=W(l),ee;try{for(Z.s();!(ee=Z.n()).done;){var Ee=ee.value,de=W(Ee.attributes),U;try{for(de.s();!(U=de.n()).done;){var ae=U.value,be=ae.name.startsWith("a_")?ae.name.slice(2):ae.name;if(be==="curvature")continue;if(!re.has(be)){re.add(be);for(var I=0;I<ae.size;I++)A[B++]=0}}}catch(k){de.e(k)}finally{de.f()}}}catch(k){Z.e(k)}finally{Z.f()}}},{key:"processEdgeLabel",value:function(m,T,_){if(this.prepareLabelGlyphs(m,_),this.edgeAttributeTexture&&!_.hidden&&_.text){this.edgeAttributeTexture.allocate(m);var x=this.packedAttributeData;Gn(this.attrDescriptors,_.edgeAttributes,x,"",pu,0),this.edgeAttributeTexture.updateAllAttributes(m,x)}return xe(f,"processLabel",this,3)([m,T,_])}},{key:"updateAtlasTexture",value:function(){if(!this.atlasNeedsUpdate)return;var m=this.normalProgram.gl,T=this.atlasManager.getTextures();if(T.length===0)return;var _=T[0];m.bindTexture(m.TEXTURE_2D,this.atlasTexture),m.texImage2D(m.TEXTURE_2D,0,m.RGBA,_.width,_.height,0,m.RGBA,m.UNSIGNED_BYTE,_.data),m.bindTexture(m.TEXTURE_2D,null),this.atlasNeedsUpdate=!1}},{key:"setUniforms",value:function(m,T){var{gl:_,uniformLocations:x}=T,S=this.atlasManager.getTextures(),E=S.length>0?[S[0].width,S[0].height]:[1,1];if(_.uniformMatrix3fv(x.u_matrix,!1,m.matrix),_.uniform1f(x.u_sizeRatio,m.sizeRatio),_.uniform1f(x.u_correctionRatio,m.correctionRatio),_.uniform1f(x.u_pixelRatio,m.pixelRatio),_.uniform1f(x.u_cameraAngle,m.cameraAngle),_.uniform1f(x.u_sdfBufferPixels,Be.buffer),_.uniform2f(x.u_resolution,m.width,m.height),_.uniform2f(x.u_atlasSize,E[0],E[1]),_.uniform1f(x.u_gamma,this.gamma),_.uniform1f(x.u_sdfBuffer,this.sdfBuffer),_.activeTexture(_.TEXTURE0),_.bindTexture(_.TEXTURE_2D,this.atlasTexture),_.uniform1i(x.u_atlas,0),x.u_nodeDataTexture!==void 0)_.uniform1i(x.u_nodeDataTexture,m.nodeDataTextureUnit);if(x.u_nodeDataTextureWidth!==void 0)_.uniform1i(x.u_nodeDataTextureWidth,m.nodeDataTextureWidth);if(x.u_edgeDataTexture!==void 0)_.uniform1i(x.u_edgeDataTexture,m.edgeDataTextureUnit);if(x.u_edgeDataTextureWidth!==void 0)_.uniform1i(x.u_edgeDataTextureWidth,m.edgeDataTextureWidth);if(x.u_edgeFrameTexture!==void 0)_.uniform1i(x.u_edgeFrameTexture,m.edgeFrameTextureUnit);if(x.u_edgeFrameTextureWidth!==void 0)_.uniform1i(x.u_edgeFrameTextureWidth,m.edgeFrameTextureWidth);if(h&&o&&x.u_borderWidth!==void 0){var D=o.width/Be.buffer*this.sdfBuffer;_.uniform1f(x.u_borderWidth,D)}if(this.edgeAttributeTexture&&x.u_edgeAttributeTexture!==void 0)this.edgeAttributeTexture.bind(Je),_.uniform1i(x.u_edgeAttributeTexture,Je),_.uniform1i(x.u_edgeAttributeTextureWidth,this.edgeAttributeTexture.getTextureWidth()),_.uniform1i(x.u_edgeAttributeTexelsPerEdge,this.edgeAttributeTexture.getTexelsPerItem());if(d==="scaled"&&x.u_zoomSizeRatio!==void 0){var A=this.renderer.getSetting("zoomToSizeRatioFunction"),L=1/A(m.zoomRatio);_.uniform1f(x.u_zoomSizeRatio,L)}}},{key:"renderProgram",value:function(m,T){if(this.updateAtlasTexture(),this.atlasManager.hasPendingGlyphs())this.atlasManager.flush(),this.updateAtlasTexture();if(this.edgeAttributeTexture)this.edgeAttributeTexture.upload();xe(f,"renderProgram",this,3)([m,T])}},{key:"registerFont",value:function(m){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"normal",_=arguments.length>2&&arguments[2]!==void 0?arguments[2]:"normal";return this.atlasManager.registerFont({family:m,weight:T,style:_})}},{key:"getAtlasManager",value:function(){return this.atlasManager}},{key:"ensureGlyphsReady",value:function(m,T){var _=T||this.defaultFontKey,x=W(m),S;try{for(x.s();!(S=x.n()).done;){var E=S.value;this.atlasManager.ensureGlyphs(E,_)}}catch(D){x.e(D)}finally{x.f()}this.atlasManager.flush()}},{key:"measureLabelAtlasWidth",value:function(m,T){var _=T||this.defaultFontKey;if(this.atlasManager.ensureGlyphs(m,_),this.atlasManager.hasPendingGlyphs())this.atlasManager.flush();var x=0,S=W(m),E;try{for(S.s();!(E=S.n()).done;){var D=E.value,A=D.codePointAt(0);if(A===void 0)continue;var L=this.atlasManager.getGlyph(A,_);if(L)x+=L.advance}}catch(w){S.e(w)}finally{S.f()}return x}},{key:"measureLabel",value:function(m,T,_){var x=this.measureLabelAtlasWidth(m,_),S=T/Be.fontSize;return{width:x*S,height:T,textHeight:T}}},{key:"kill",value:function(){var m=this.normalProgram.gl;if(this.refreshTimeout!==null)clearTimeout(this.refreshTimeout),this.refreshTimeout=null;if(this.atlasTexture)m.deleteTexture(this.atlasTexture),this.atlasTexture=null;if(this.edgeAttributeTexture)this.edgeAttributeTexture.kill(),this.edgeAttributeTexture=null;this.atlasManager.destroy(),this.labelGlyphCache.clear(),xe(f,"kill",this,3)([])}}])}(yi);return R(y,"labelColor",r),R(y,"labelMargin",i),new y(e,a,n)}function yu(){var e=`\n// No extremity - always returns positive (outside)\nfloat extremity_none(vec2 uv, float lengthRatio, float widthRatio) {\n return 1.0;\n}\n`;return{name:"none",glsl:e,length:0,widthFactor:1,margin:0,uniforms:[],attributes:[]}}function Li(e,a,n,t,r,i,o){var s,l,d=Ei(t),{paths:u,layers:c,defaultHead:g,defaultTail:h}=d,p=[yu()].concat(J(d.extremities)),y={},v={};u.forEach(function(w,M){return y[w.name]=M}),p.forEach(function(w,M){return v[w.name]=M});var f=(s=v[g])!==null&&s!==void 0?s:0,b=(l=v[h])!==null&&l!==void 0?l:0,m=null,T=Me([].concat(J(u),J(c))),_=function(w){function M(C,z,O){var N;if(ie(this,M),!m)m=si({paths:u,extremities:p,layers:c,antialias:r});N=fe(this,M,[C,z,O]),R(N,"layerLifecycles",new Map),R(N,"needsShaderRegeneration",!1),R(N,"edgeAttributeTexture",null),R(N,"layout",T),R(N,"attrDescriptors",[]),R(N,"lifecycleIndexOffset",u.length),N._pickingBuffer=z,N.edgeAttributeTexture=new zn(C,N.layout),N.packedAttributeData=new Float32Array(N.layout.floatsPerItem),c.forEach(function(P,B){if(P.lifecycle){var Y={gl:C,renderer:{refresh:function(){return O.refresh()}},getUniformLocation:function(re){return C.getUniformLocation(N.normalProgram.program,re)},requestShaderRegeneration:function(){N.needsShaderRegeneration=!0},requestRefresh:function(){O.refresh()}};N.layerLifecycles.set(B,P.lifecycle(Y))}}),N.layerLifecycles.forEach(function(P){var B;return(B=P.init)===null||B===void 0?void 0:B.call(P)});var F=new Map;return N.layerLifecycles.forEach(function(P,B){if(P.getAttributeData)F.set(u.length+B,P)}),N.attrDescriptors=Nn([].concat(J(u),J(c)),N.layout,F),N}return ge(M,w),oe(M,[{key:"getAttributeTexture",value:function(){return this.edgeAttributeTexture}},{key:"resolveEdgeIds",value:function(z,O,N){var F=z,P=0,B=f,Y=b,q=O?F.selfLoopPath:N&&F.parallelPath?F.parallelPath:F.path;if(q&&y[q]!==void 0)P=y[q];if(F.head&&F.head!=="none"&&v[F.head]!==void 0)B=v[F.head];if(F.tail&&F.tail!=="none"&&v[F.tail]!==void 0)Y=v[F.tail];var re=p[B],Z=p[Y];return{pathId:P,headId:B,tailId:Y,headLengthRatio:!Fe(re.length)?re.length:0,tailLengthRatio:!Fe(Z.length)?Z.length:0}}},{key:"getDefinition",value:function(){var z=WebGL2RenderingContext,O=z.TRIANGLE_STRIP,N=O,F=m;return{VERTICES:F.verticesPerEdge,VERTEX_SHADER_SOURCE:F.vertexShader,FRAGMENT_SHADER_SOURCE:F.fragmentShader,METHOD:N,UNIFORMS:F.uniforms,ATTRIBUTES:F.attributes,CONSTANT_ATTRIBUTES:F.constantAttributes,CONSTANT_DATA:F.constantData}}},{key:"maybeRegenerateShaders",value:function(){var z=this;if(!this.needsShaderRegeneration)return;this.needsShaderRegeneration=!1;var O=c.map(function(re,Z){var ee=z.layerLifecycles.get(Z);if(ee!==null&&ee!==void 0&&ee.regenerate)return ee.regenerate();return re});m=si({paths:u,extremities:p,layers:O,antialias:this.renderer.getSetting("antialiasEdges")});var N=this.normalProgram.gl,F=this.normalProgram,{program:P,buffer:B,vertexShader:Y,fragmentShader:q}=F;N.deleteProgram(P),N.deleteBuffer(B),N.deleteShader(Y),N.deleteShader(q),this.normalProgram=this.getProgramInfo("normal",N,m.vertexShader,m.fragmentShader,this._pickingBuffer)}},{key:"process",value:function(z,O,N,F,P,B){var Y=O*this.STRIDE;if(P.visibility==="hidden"||N.visibility==="hidden"||F.visibility==="hidden"){for(var q=Y+this.STRIDE;Y<q;Y++)this.floats[Y]=0;this.floats[O*this.STRIDE]=pi;return}this.processVisibleItem(_t(z),Y,N,F,P,B)}},{key:"processVisibleItem",value:function(z,O,N,F,P,B){var Y,q=this.floats,re=this.ints;q[O++]=B,q[O++]=Pe(P.color),re[O++]=z,q[O++]=(Y=P.opacity)!==null&&Y!==void 0?Y:1;var Z=this.packedAttributeData;Gn(this.attrDescriptors,P,Z,P.color,this.layerLifecycles,this.lifecycleIndexOffset),this.edgeAttributeTexture.updateAllAttributesAtRow(B,Z)}},{key:"setUniforms",value:function(z,O){var N=this,{gl:F,uniformLocations:P}=O;if(P.u_matrix)F.uniformMatrix3fv(P.u_matrix,!1,z.matrix);if(P.u_sizeRatio)F.uniform1f(P.u_sizeRatio,z.sizeRatio);if(P.u_correctionRatio)F.uniform1f(P.u_correctionRatio,z.correctionRatio);if(P.u_zoomRatio)F.uniform1f(P.u_zoomRatio,z.zoomRatio);if(P.u_pixelRatio)F.uniform1f(P.u_pixelRatio,z.pixelRatio);if(P.u_cameraAngle)F.uniform1f(P.u_cameraAngle,z.cameraAngle);if(P.u_feather)F.uniform1f(P.u_feather,z.antiAliasingFeather);if(P.u_minEdgeThickness)F.uniform1f(P.u_minEdgeThickness,z.minEdgeThickness);if(P.u_pickingPadding)F.uniform1f(P.u_pickingPadding,z.edgePickingPadding);if(P.u_nodeDataTexture)F.uniform1i(P.u_nodeDataTexture,z.nodeDataTextureUnit);if(P.u_nodeDataTextureWidth)F.uniform1i(P.u_nodeDataTextureWidth,z.nodeDataTextureWidth);if(P.u_edgeDataTexture)F.uniform1i(P.u_edgeDataTexture,z.edgeDataTextureUnit);if(P.u_edgeDataTextureWidth)F.uniform1i(P.u_edgeDataTextureWidth,z.edgeDataTextureWidth);if(P.u_edgeFrameTexture)F.uniform1i(P.u_edgeFrameTexture,z.edgeFrameTextureUnit);if(P.u_edgeFrameTextureWidth)F.uniform1i(P.u_edgeFrameTextureWidth,z.edgeFrameTextureWidth);if(this.edgeAttributeTexture&&this.layout.floatsPerItem>0){if(this.edgeAttributeTexture.bind(Je),P.u_edgeAttributeTexture)F.uniform1i(P.u_edgeAttributeTexture,Je);if(P.u_edgeAttributeTextureWidth)F.uniform1i(P.u_edgeAttributeTextureWidth,this.edgeAttributeTexture.getTextureWidth());if(P.u_edgeAttributeTexelsPerEdge)F.uniform1i(P.u_edgeAttributeTexelsPerEdge,this.edgeAttributeTexture.getTexelsPerItem())}var B=new Set;u.forEach(function(Y){Y.uniforms.forEach(function(q){if(B.has(q.name))return;B.add(q.name),N.setTypedUniform(q,O)})}),p.forEach(function(Y){Y.uniforms.forEach(function(q){if(B.has(q.name))return;B.add(q.name),N.setTypedUniform(q,O)})}),c.forEach(function(Y){Y.uniforms.forEach(function(q){if(B.has(q.name))return;B.add(q.name),N.setTypedUniform(q,O)})})}},{key:"render",value:function(z,O,N){this.maybeRegenerateShaders(),xe(M,"render",this,3)([z,O,N])}},{key:"renderProgram",value:function(z,O){this.layerLifecycles.forEach(function(N){var F;return(F=N.beforeRender)===null||F===void 0?void 0:F.call(N)}),xe(M,"renderProgram",this,3)([z,O])}},{key:"uploadAttributeTexture",value:function(){if(this.edgeAttributeTexture&&this.layout.floatsPerItem>0)this.edgeAttributeTexture.upload()}},{key:"kill",value:function(){if(this.layerLifecycles.forEach(function(z){var O;return(O=z.kill)===null||O===void 0?void 0:O.call(z)}),this.edgeAttributeTexture)this.edgeAttributeTexture.kill(),this.edgeAttributeTexture=null;xe(M,"kill",this,3)([])}}])}(st),x=p[f],S=p[b],E=V({paths:u,headLengthRatio:!Fe(x.length)?x.length:0,tailLengthRatio:!Fe(S.length)?S.length:0},t.label),D=Di(E),A=function(){return{labelProgram:bu(e,null,n,E),labelBackgroundProgram:du(e,a,n,{shaderConfig:D})}},L=new eu(e,{paths:u,extremities:p,layers:c,nodeShapes:i,nodeLayers:o});return{edgeProgram:new _(e,null,n),createLabelPrograms:A,framePass:L}}function xu(e){return se(e)==="object"&&"uniforms"in e&&Array.isArray(e.uniforms)}function _u(e){return se(e)==="object"&&"uniforms"in e&&"attributes"in e&&"glsl"in e}function Tu(e){return se(e)==="object"&&"uniforms"in e&&"attributes"in e&&"segments"in e}function Su(e){return se(e)==="object"&&"uniforms"in e&&"attributes"in e&&"length"in e}function Eu(e){return se(e)==="object"&&"uniforms"in e&&"attributes"in e&&"glsl"in e}function Ru(e){return se(e)==="object"&&"glsl"in e&&"name"in e&&!("uniforms"in e)}function Au(e){return se(e)==="object"&&"glsl"in e&&"name"in e&&!("uniforms"in e)}function wu(e){return se(e)==="object"&&"glsl"in e&&"name"in e&&!("uniforms"in e)}function Du(e){if(xu(e))return e;if(Ru(e))return{name:e.name,glsl:e.glsl,inradiusFactor:e.inradiusFactor,uniforms:[]};throw Error("Invalid node shape specification: ".concat(JSON.stringify(e)))}function Lu(e){if(_u(e))return e;if(Fr(e))return{name:e.name,glsl:e.glsl,uniforms:[],attributes:[]};throw Error("Invalid node layer specification: ".concat(JSON.stringify(e)))}function Cu(e){if(Tu(e))return e;if(Au(e))return{name:e.name,glsl:e.glsl,segments:e.segments,uniforms:[],attributes:[]};throw Error("Invalid edge path specification: ".concat(JSON.stringify(e)))}function ku(e){if(Eu(e))return e;if(Ir(e))return{name:e.name,glsl:e.glsl,uniforms:[],attributes:[]};throw Error("Invalid edge layer specification: ".concat(JSON.stringify(e)))}function Pu(e){if(Su(e))return e;if(wu(e))return{name:e.name,glsl:e.glsl,length:e.length,widthFactor:e.widthFactor,margin:0,uniforms:[],attributes:[]};throw Error("Invalid edge extremity specification: ".concat(JSON.stringify(e)))}function Ci(e){var a,n,t=(a=e===null||e===void 0?void 0:e.shapes)!==null&&a!==void 0?a:Wt.shapes,r=(n=e===null||e===void 0?void 0:e.layers)!==null&&n!==void 0?n:Wt.layers,i=t.map(Du),o=r.map(Lu);if(i.length===0)throw Error("At least one node shape must be specified.");if(o.length===0)throw Error("At least one node layer must be specified.");return{shapes:i,layers:o}}function Fu(e){var a,n,t,r=(a=e===null||e===void 0?void 0:e.paths)!==null&&a!==void 0?a:Tt.paths,i=(n=e===null||e===void 0?void 0:e.extremities)!==null&&n!==void 0?n:Tt.extremities,o=(t=e===null||e===void 0?void 0:e.layers)!==null&&t!==void 0?t:Tt.layers,s=r.map(Cu),l=i.map(Pu).filter(function(u){return u!==null}),d=o.map(ku);if(s.length===0)throw Error("At least one edge path must be specified.");if(d.length===0)throw Error("At least one edge layer must be specified.");return{paths:s,extremities:l,layers:d}}function ki(e,a){var n={},t=W(e),r;try{for(t.s();!(r=t.n()).done;){var i=r.value;if(i.variables)Object.assign(n,i.variables)}}catch(o){t.e(o)}finally{t.f()}return Object.assign(n,a||{}),n}function Pi(e,a,n,t,r){var i=Ci(t),{shapes:o,layers:s}=i,l=ki(o,t===null||t===void 0?void 0:t.variables),d=_i(e,a,n,{shapes:o,layers:s,label:t===null||t===void 0?void 0:t.label,backdrop:t===null||t===void 0?void 0:t.backdrop,labelAttachments:t===null||t===void 0?void 0:t.labelAttachments},r);return V(V({},d),{},{variables:l})}function Fi(e,a,n,t,r,i){var o=Fu(t),{paths:s,extremities:l,layers:d}=o,u=Ci(i),{shapes:c,layers:g}=u,h=ki(s,t===null||t===void 0?void 0:t.variables),p=Li(e,a,n,{paths:s,extremities:l,layers:d,defaultHead:t===null||t===void 0?void 0:t.defaultHead,defaultTail:t===null||t===void 0?void 0:t.defaultTail,label:t===null||t===void 0?void 0:t.label},r,c,g);return V(V({},p),{},{variables:h,paths:s})}var Iu=2;function Ii(e,a,n){var t=arguments.length>3&&arguments[3]!==void 0?arguments[3]:Iu,r=a.canvas,{width:i,height:o}=r,{x:s,y:l,rowHeight:d,maxRowWidth:u}=n,c={},g=[],h=W(e),p;try{for(h.s();!(p=h.n()).done;){var y=p.value,v=y.width+t,f=y.height+t;if(v>i||f>o||s+v>i&&l+d+f>o){g.push(y);continue}if(s+v>i)u=Math.max(u,s),s=0,l+=d,d=f;y.draw(a,s,l),c[y.key]={x:s,y:l,width:y.width,height:y.height},s+=v,d=Math.max(d,f)}}catch(b){h.e(b)}finally{h.f()}return u=Math.max(u,s),{atlas:c,cursor:{x:s,y:l,rowHeight:d,maxRowWidth:u},remaining:g}}function Re(e,a,n,t){var r=Object.defineProperty;try{r({},"",{})}catch(i){r=0}Re=function(i,o,s,l){function d(u,c){Re(i,u,function(g){return this._invoke(u,c,g)})}o?r?r(i,o,{value:s,enumerable:!l,configurable:!l,writable:!l}):i[o]=s:(d("next",0),d("throw",1),d("return",2))},Re(e,a,n,t)}function Ae(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,a,n=typeof Symbol=="function"?Symbol:{},t=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(h,p,y,v){var f=p&&p.prototype instanceof s?p:s,b=Object.create(f.prototype);return Re(b,"_invoke",function(m,T,_){var x,S,E,D=0,A=_||[],L=!1,w={p:0,n:0,v:e,a:M,f:M.bind(e,4),d:function(C,z){return x=C,S=0,E=e,w.n=z,o}};function M(C,z){for(S=C,E=z,a=0;!L&&D&&!O&&a<A.length;a++){var O,N=A[a],F=w.p,P=N[2];C>3?(O=P===z)&&(E=N[(S=N[4])?5:(S=3,3)],N[4]=N[5]=e):N[0]<=F&&((O=C<2&&F<N[1])?(S=0,w.v=z,w.n=N[1]):F<P&&(O=C<3||N[0]>z||z>P)&&(N[4]=C,N[5]=z,w.n=P,S=0))}if(O||C>1)return o;throw L=!0,z}return function(C,z,O){if(D>1)throw TypeError("Generator is already running");for(L&&z===1&&M(z,O),S=z,E=O;(a=S<2?e:E)||!L;){x||(S?S<3?(S>1&&(w.n=-1),M(S,E)):w.n=E:w.v=E);try{if(D=2,x){if(S||(C="next"),a=x[C]){if(!(a=a.call(x,E)))throw TypeError("iterator result is not an object");if(!a.done)return a;E=a.value,S<2&&(S=0)}else S===1&&(a=x.return)&&a.call(x),S<2&&(E=TypeError("The iterator does not provide a \'"+C+"\' method"),S=1);x=e}else if((a=(L=w.n<0)?E:m.call(T,w))!==o)break}catch(N){x=e,S=1,E=N}finally{D=1}}return{value:a,done:L}}}(h,y,v),!0),b}var o={};function s(){}function l(){}function d(){}a=Object.getPrototypeOf;var u=[][t]?a(a([][t]())):(Re(a={},t,function(){return this}),a),c=d.prototype=s.prototype=Object.create(u);function g(h){return Object.setPrototypeOf?Object.setPrototypeOf(h,d):(h.__proto__=d,Re(h,r,"GeneratorFunction")),h.prototype=Object.create(c),h}return l.prototype=d,Re(c,"constructor",d),Re(d,"constructor",l),l.displayName="GeneratorFunction",Re(d,r,"GeneratorFunction"),Re(c),Re(c,r,"Generator"),Re(c,t,function(){return this}),Re(c,"toString",function(){return"[object Generator]"}),(Ae=function(){return{w:i,m:g}})()}function Mi(e,a,n,t,r,i,o){try{var s=e[i](o),l=s.value}catch(d){return void n(d)}s.done?a(l):Promise.resolve(l).then(t,r)}function Pt(e){return function(){var a=this,n=arguments;return new Promise(function(t,r){var i=e.apply(a,n);function o(l){Mi(i,t,r,o,s,"next",l)}function s(l){Mi(i,t,r,o,s,"throw",l)}o(void 0)})}}var Bn=new Map,zi=!1;function Mu(e){return new Promise(function(a,n){var t=new FileReader;t.onload=function(){return a(t.result)},t.onerror=n,t.readAsDataURL(e)})}function zu(e){if(!Bn.has(e)){var a=fetch(e).then(function(n){return n.blob()}).then(Mu).catch(function(){return Bn.delete(e),null});Bn.set(e,a)}return Bn.get(e)}function Nu(e){return Ba.apply(this,arguments)}function Ba(){return Ba=Pt(Ae().m(function e(a){var n,t,r;return Ae().w(function(i){while(!0)switch(i.n){case 0:return n=document.createElement("div"),n.innerHTML=a,t=Array.from(n.querySelectorAll("img[src]")),r=t.filter(function(o){return!o.getAttribute("src").startsWith("data:")}),i.n=1,Promise.all(r.map(function(){var o=Pt(Ae().m(function s(l){var d;return Ae().w(function(u){while(!0)switch(u.n){case 0:return u.n=1,zu(l.getAttribute("src"));case 1:if(d=u.v,d)l.setAttribute("src",d);case 2:return u.a(2)}},s)}));return function(s){return o.apply(this,arguments)}}()));case 1:return i.a(2,n.innerHTML)}},e)})),Ba.apply(this,arguments)}function Ni(e){return Wa.apply(this,arguments)}function Wa(){return Wa=Pt(Ae().m(function e(a){var n,t,r,i,o,s,l,d,u,c,g,h,p,y=arguments;return Ae().w(function(v){while(!0)switch(v.n){case 0:if(n=y.length>1&&y[1]!==void 0?y[1]:1,t=a instanceof SVGElement?new XMLSerializer().serializeToString(a):a,r=new DOMParser,i=r.parseFromString(t,"image/svg+xml"),o=i.querySelector("svg"),o){v.n=1;break}return v.a(2,null);case 1:if(s=parseFloat(o.getAttribute("width")||""),l=parseFloat(o.getAttribute("height")||""),!(s>0)||!(l>0)){if(d=o.getAttribute("viewBox"),d)u=d.trim().split(/[\\s,]+/),s=parseFloat(u[2]),l=parseFloat(u[3])}if(!(!(s>0)||!(l>0))){v.n=2;break}return console.warn("Sigma: SVG label attachment has no parseable dimensions — skipped."),v.a(2,null);case 2:return c=Math.ceil(s*n),g=Math.ceil(l*n),h=new Blob([t],{type:"image/svg+xml"}),p=URL.createObjectURL(h),v.a(2,new Promise(function(f){var b=new Image;b.onload=function(){var m=document.createElement("canvas");m.width=c,m.height=g,m.getContext("2d").drawImage(b,0,0,c,g),URL.revokeObjectURL(p);try{m.getContext("2d").getImageData(0,0,1,1)}catch(T){if(T instanceof DOMException&&T.name==="SecurityError"){if(!zi)zi=!0,console.warn(\'Sigma: A label attachment was skipped because the rendered canvas is tainted. SVG with <foreignObject> (used by the "html" attachment type) is blocked in Chromium and Safari. Use type: "canvas" with Canvas 2D rendering instead.\');f(null);return}throw T}f(m)},b.onerror=function(){URL.revokeObjectURL(p),f(null)},b.src=p}))}},e)})),Wa.apply(this,arguments)}function Gu(e,a){var n=document.createElement("div");n.style.cssText="position:fixed;left:-99999px;top:0;visibility:hidden;width:max-content;height:max-content",n.innerHTML=(a?"<style>".concat(a,"</style>"):"")+e,document.body.appendChild(n);var t=n.getBoundingClientRect(),{width:r,height:i}=t;return document.body.removeChild(n),{width:Math.ceil(r),height:Math.ceil(i)}}function Ou(e,a,n,t){return Ua.apply(this,arguments)}function Ua(){return Ua=Pt(Ae().m(function e(a,n,t,r){var i,o,s,l,d,u,c,g,h=arguments;return Ae().w(function(p){while(!0)switch(p.n){case 0:return i=h.length>4&&h[4]!==void 0?h[4]:1,o=a instanceof HTMLElement?a.outerHTML:a,p.n=1,Nu(o);case 1:if(s=p.v,t==null||r==null)l=Gu(s,n),t=t!==null&&t!==void 0?t:l.width,r=r!==null&&r!==void 0?r:l.height;return d=Math.ceil(t*i),u=Math.ceil(r*i),c=n?"<style>".concat(n,"</style>"):"",g=\'<svg xmlns="http://www.w3.org/2000/svg" \'+\'width="\'.concat(d,\'" height="\').concat(u,\'" viewBox="0 0 \').concat(t," ").concat(r,\'">\')+\'<foreignObject width="\'.concat(t,\'" height="\').concat(r,\'">\')+\'<body xmlns="http://www.w3.org/1999/xhtml" style="margin:0;padding:0">\'.concat(c).concat(s,"</body>")+"</foreignObject></svg>",p.a(2,Ni(g,1))}},e)})),Ua.apply(this,arguments)}function Bu(e){return Ha.apply(this,arguments)}function Ha(){return Ha=Pt(Ae().m(function e(a){var n,t=arguments,r;return Ae().w(function(i){while(!0)switch(i.n){case 0:n=t.length>1&&t[1]!==void 0?t[1]:1,r=a.type,i.n=r==="canvas"?1:r==="svg"?2:r==="html"?3:4;break;case 1:return i.a(2,a.canvas);case 2:return i.a(2,Ni(a.svg,n));case 3:return i.a(2,Ou(a.html,a.css,a.width,a.height,n));case 4:return i.a(2)}},e)})),Ha.apply(this,arguments)}var kt=2048,Gi=function(){function e(a,n,t){ie(this,e),R(this,"cache",new Map),R(this,"pending",new Set),R(this,"atlas",{}),R(this,"glTexture",null),R(this,"dirty",!0),this.gl=a,this.renderers=n,this.scheduleRender=t,this.packCanvas=document.createElement("canvas"),this.packCanvas.width=kt,this.packCanvas.height=kt,this.packCtx=this.packCanvas.getContext("2d")}return oe(e,[{key:"renderAttachment",value:function(n,t,r){var i=this,o="".concat(n,":").concat(t);if(this.cache.has(o)||this.pending.has(o))return;var s=this.renderers[t];if(!s)return;var l=s(r);if(!l)return;this.pending.add(o);var d=r.pixelRatio;Promise.resolve(l).then(function(){var u=Pt(Ae().m(function c(g){var h;return Ae().w(function(p){while(!0)switch(p.n){case 0:if(i.pending.has(o)){p.n=1;break}return p.a(2);case 1:if(i.pending.delete(o),g){p.n=2;break}return p.a(2);case 2:return p.n=3,Bu(g,d);case 3:if(h=p.v,!(!h||h.width===0||h.height===0)){p.n=4;break}return p.a(2);case 4:i.cache.set(o,{image:h,width:h.width,height:h.height}),i.dirty=!0,i.scheduleRender();case 5:return p.a(2)}},c)}));return function(c){return u.apply(this,arguments)}}())}},{key:"regenerateAtlas",value:function(){if(!this.dirty)return;this.dirty=!1;var n=[];if(this.cache.forEach(function(d,u){n.push({key:u,width:d.width,height:d.height,draw:function(g,h,p){g.drawImage(d.image,h,p)}})}),n.length===0){this.atlas={},this.deleteGLTexture();return}var t={x:0,y:0,rowHeight:0,maxRowWidth:0};this.packCtx.clearRect(0,0,kt,kt);var r=Ii(n,this.packCtx,t),{atlas:i,remaining:o}=r;if(this.atlas=i,o.length>0)console.warn("Sigma: ".concat(o.length," label attachment(s) could not fit in the ").concat(kt,"x").concat(kt," atlas and will not be rendered."));this.deleteGLTexture();var s=this.gl,l=s.createTexture();s.activeTexture(s.TEXTURE0+Yt),s.bindTexture(s.TEXTURE_2D,l),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,s.RGBA,s.UNSIGNED_BYTE,this.packCanvas),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),this.glTexture=l}},{key:"bindTexture",value:function(n){if(!this.glTexture)return;var t=this.gl;t.activeTexture(t.TEXTURE0+n),t.bindTexture(t.TEXTURE_2D,this.glTexture)}},{key:"getEntry",value:function(n,t){var r="".concat(n,":").concat(t);return this.atlas[r]||null}},{key:"invalidateNode",value:function(n){var t="".concat(n,":"),r=W(this.cache.keys()),i;try{for(r.s();!(i=r.n()).done;){var o=i.value;if(o.startsWith(t))this.cache.delete(o),this.dirty=!0}}catch(u){r.e(u)}finally{r.f()}var s=W(this.pending),l;try{for(s.s();!(l=s.n()).done;){var d=l.value;if(d.startsWith(t))this.pending.delete(d)}}catch(u){s.e(u)}finally{s.f()}}},{key:"restore",value:function(){this.glTexture=null,this.dirty=!0}},{key:"clear",value:function(){this.cache.clear(),this.pending.clear(),this.atlas={},this.dirty=!0,this.deleteGLTexture()}},{key:"kill",value:function(){this.clear(),this.packCanvas=null,this.packCtx=null,this.gl=null}},{key:"deleteGLTexture",value:function(){if(this.glTexture)this.gl.deleteTexture(this.glTexture),this.glTexture=null}}])}(),$a=function(){function e(a){ie(this,e),R(this,"buckets",new Map),R(this,"keyDepth",new Map);var n=W(a),t;try{for(n.s();!(t=n.n()).done;){var r=t.value;this.buckets.set(r,new Set)}}catch(i){n.e(i)}finally{n.f()}}return oe(e,[{key:"has",value:function(n){return this.keyDepth.has(n)}},{key:"getBucket",value:function(n){return this.buckets.get(n)}},{key:"set",value:function(n,t){var r,i=this.keyDepth.get(n);if(i===t)return;var o=this.buckets.get(t);if(!o)throw Error(\'Sigma: "\'.concat(t,\'" is not a declared depth layer\'));if(i!==void 0)(r=this.buckets.get(i))===null||r===void 0||r.delete(n);o.add(n),this.keyDepth.set(n,t)}},{key:"remove",value:function(n){var t=this.keyDepth.get(n);if(t===void 0)return;this.buckets.get(t).delete(n),this.keyDepth.delete(n)}},{key:"clearAll",value:function(){var n=W(this.buckets.values()),t;try{for(n.s();!(t=n.n()).done;){var r=t.value;r.clear()}}catch(i){n.e(i)}finally{n.f()}this.keyDepth.clear()}},{key:"getSorted",value:function(n,t){var r=this.buckets.get(n);if(!r||r.size===0)return[];return J(r).sort(function(i,o){return t(i)-t(o)})}}])}(),Oi=function(e){function a(n,t){return ie(this,a),fe(this,a,[n,2,t])}return ge(a,e),oe(a,[{key:"updateNode",value:function(t,r,i,o,s,l,d,u){var c=this.indexMap.get(t);if(c===void 0)throw Error(\'Node "\'.concat(t,\'" not allocated in NodeDataTexture\'));var g=Ye(u),h=le(g,4),p=h[0],y=h[1],v=h[2],f=h[3],b=c*2*4;this.data[b]=r,this.data[b+1]=i,this.data[b+2]=o,this.data[b+3]=s,this.data[b+4]=l,this.data[b+5]=d,this.data[b+6]=p*65536+y*256+v,this.data[b+7]=f/255,this.markDirty(c)}}])}(Mn),Wu=1024,Uu=1.5,Va=function(){function e(a,n){var t;if(ie(this,e),R(this,"texture",null),R(this,"framebuffer",null),!a.getExtension("EXT_color_buffer_float"))throw Error("sigma: EXT_color_buffer_float is required for label/edge placement but is unavailable in this WebGL2 context.");this.gl=a,this.maxTextureSize=a.getParameter(a.MAX_TEXTURE_SIZE),this.channels=n.channels,this.capacity=this.roundUpToPowerOfTwo((t=n.initialCapacity)!==null&&t!==void 0?t:Wu);var r=this.computeDimensions(this.capacity);this.textureWidth=r.width,this.textureHeight=r.height,this.create()}return oe(e,[{key:"roundUpToPowerOfTwo",value:function(n){return Math.pow(2,Math.ceil(Math.log2(Math.max(1,n))))}},{key:"computeDimensions",value:function(n){var t=Math.min(n,this.maxTextureSize),r=Math.ceil(n/t);return{width:t,height:r}}},{key:"create",value:function(){var n=this.gl,t=this.channels===1?n.R32F:n.RGBA32F,r=this.channels===1?n.RED:n.RGBA;if(this.texture=n.createTexture(),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,this.texture),n.texImage2D(n.TEXTURE_2D,0,t,this.textureWidth,this.textureHeight,0,r,n.FLOAT,null),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),this.framebuffer=n.createFramebuffer(),n.bindFramebuffer(n.FRAMEBUFFER,this.framebuffer),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,this.texture,0),n.checkFramebufferStatus(n.FRAMEBUFFER)!==n.FRAMEBUFFER_COMPLETE)throw Error("sigma: float framebuffer for frame-pass placement is incomplete.");n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null)}},{key:"ensureCapacity",value:function(n){if(n<=this.capacity)return;var t=this.gl;this.capacity=this.roundUpToPowerOfTwo(Math.ceil(n*Uu));var r=this.computeDimensions(this.capacity);if(this.textureWidth=r.width,this.textureHeight=r.height,this.texture)t.deleteTexture(this.texture);if(this.framebuffer)t.deleteFramebuffer(this.framebuffer);this.create()}},{key:"bindAsRenderTarget",value:function(){var n=this.gl;n.bindFramebuffer(n.FRAMEBUFFER,this.framebuffer),n.viewport(0,0,this.textureWidth,this.textureHeight)}},{key:"bind",value:function(n){var t=this.gl;t.activeTexture(t.TEXTURE0+n),t.bindTexture(t.TEXTURE_2D,this.texture)}},{key:"getTexture",value:function(){return this.texture}},{key:"getTextureWidth",value:function(){return this.textureWidth}},{key:"getTextureHeight",value:function(){return this.textureHeight}},{key:"restore",value:function(){this.gl.getExtension("EXT_color_buffer_float"),this.create()}},{key:"kill",value:function(){var n=this.gl;if(this.texture)n.deleteTexture(this.texture),this.texture=null;if(this.framebuffer)n.deleteFramebuffer(this.framebuffer),this.framebuffer=null}}])}(),Bi=function(e){function a(n,t){return ie(this,a),fe(this,a,[n,2,t])}return ge(a,e),oe(a,[{key:"updateEdge",value:function(t,r,i,o,s,l){var d=arguments.length>6&&arguments[6]!==void 0?arguments[6]:0,u=arguments.length>7&&arguments[7]!==void 0?arguments[7]:0,c=arguments.length>8&&arguments[8]!==void 0?arguments[8]:0,g=this.indexMap.get(t);if(g===void 0)throw Error(\'Edge "\'.concat(t,\'" not allocated in EdgeDataTexture\'));var h=g*this.TEXELS_PER_ITEM*4;this.data[h+0]=r,this.data[h+1]=i,this.data[h+2]=o,this.data[h+3]=0,this.data[h+4]=s,this.data[h+5]=l,this.data[h+6]=d,this.data[h+7]=(u&15)<<4|c&15,this.markDirty(g)}}])}(Mn);var Qh=er(Ra());function Hu(e,a){if(e==null)return{};var n={};for(var t in e)if({}.hasOwnProperty.call(e,t)){if(a.indexOf(t)!==-1)continue;n[t]=e[t]}return n}function Wi(e,a){if(e==null)return{};var n,t,r=Hu(e,a);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(t=0;t<i.length;t++)n=i[t],a.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var $u=["factor"],Vu=["factor"],Ui=1.5,Xa={x:0.5,y:0.5,angle:0,ratio:1},Hi=function(e){function a(){var n;ie(this,a);for(var t=arguments.length,r=Array(t),i=0;i<t;i++)r[i]=arguments[i];return n=fe(this,a,[].concat(r)),R(n,"minRatio",null),R(n,"maxRatio",null),R(n,"enabled",!0),R(n,"enabledZooming",!0),R(n,"enabledPanning",!0),R(n,"enabledRotation",!0),R(n,"constrainState",null),R(n,"state",V({},Xa)),R(n,"previousState",V({},Xa)),R(n,"nextFrame",null),R(n,"currentAnimationFrom",null),R(n,"currentAnimationTo",null),R(n,"animationCallback",null),n}return ge(a,e),oe(a,[{key:"x",get:function(){return this.state.x}},{key:"y",get:function(){return this.state.y}},{key:"angle",get:function(){return this.state.angle}},{key:"ratio",get:function(){return this.state.ratio}},{key:"getState",value:function(){return V({},this.state)}},{key:"getPreviousState",value:function(){return V({},this.previousState)}},{key:"getBoundedRatio",value:function(t){var r=t;if(typeof this.minRatio==="number")r=Math.max(r,this.minRatio);if(typeof this.maxRatio==="number")r=Math.min(r,this.maxRatio);return r}},{key:"validateState",value:function(t){var r=this.getState();if(this.enabledPanning&&typeof t.x==="number")r.x=t.x;if(this.enabledPanning&&typeof t.y==="number")r.y=t.y;if(this.enabledZooming&&typeof t.ratio==="number")r.ratio=this.getBoundedRatio(t.ratio);if(this.enabledRotation&&typeof t.angle==="number")r.angle=t.angle;return this.constrainState?this.constrainState(r):r}},{key:"isAnimating",value:function(){return this.nextFrame!==null}},{key:"setState",value:function(t){if(!this.enabled)return this;var r=this.validateState(t);if(qr(this.state,r))return this;return this.previousState=this.state,this.state=r,this.emit("updated",this.getState()),this}},{key:"updateState",value:function(t){return this.setState(t(this.getState())),this}},{key:"animate",value:function(t,r){var i=this;if(!this.enabled)return Promise.resolve();return new Promise(function(o){return i.runAnimation(t,V(V({},Zr),r),o)})}},{key:"cancelAnimation",value:function(){if(this.nextFrame!==null)cancelAnimationFrame(this.nextFrame),this.nextFrame=null;return this.resolveAnimation(),this.emitAnimationEnd(!1),this}},{key:"zoomIn",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=t.factor,i=r===void 0?Ui:r,o=Wi(t,$u);return this.animate({ratio:this.ratio/i},o)}},{key:"zoomOut",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=t.factor,i=r===void 0?Ui:r,o=Wi(t,Vu);return this.animate({ratio:this.ratio*i},o)}},{key:"reset",value:function(t){return this.animate(Xa,t)}},{key:"runAnimation",value:function(t,r,i){var o=this,s=mn(r.easing),l=Date.now(),d=this.getState(),u=this.validateState(t),c=function(){if(!o.enabled){o.cancelAnimation();return}var h=r.duration>0?(Date.now()-l)/r.duration:1;if(h>=1){o.nextFrame=null,o.setState(u),o.resolveAnimation(),o.emitAnimationEnd(!0);return}var p=s(h);o.setState({x:d.x+(u.x-d.x)*p,y:d.y+(u.y-d.y)*p,angle:d.angle+(u.angle-d.angle)*p,ratio:d.ratio+(u.ratio-d.ratio)*p}),o.nextFrame=requestAnimationFrame(c)};this.cancelAnimation(),this.currentAnimationFrom=d,this.currentAnimationTo=u,this.animationCallback=i,this.emit("animationStart",{from:d,to:u}),c()}},{key:"resolveAnimation",value:function(){var t=this.animationCallback;if(this.animationCallback=null,t)t()}},{key:"emitAnimationEnd",value:function(t){var r=this.currentAnimationFrom,i=this.currentAnimationTo;if(!r||!i)return;this.currentAnimationFrom=null,this.currentAnimationTo=null,this.emit("animationEnd",{from:r,to:i,completed:t})}}],[{key:"from",value:function(t){var r=new a;return r.setState(t)}}])}(_n);function we(e,a){var n=a.getBoundingClientRect();return{x:e.clientX-n.left,y:e.clientY-n.top}}function We(e,a){var n=V(V({},we(e,a)),{},{sigmaDefaultPrevented:!1,preventSigmaDefault:function(){n.sigmaDefaultPrevented=!0},original:e});return n}function lt(e){var a="x"in e?e:V(V({},e.touches[0]||e.previousTouches[0]),{},{original:e.original,sigmaDefaultPrevented:e.sigmaDefaultPrevented,preventSigmaDefault:function(){e.sigmaDefaultPrevented=!0,a.sigmaDefaultPrevented=!0}});return a}function Xu(e,a){var n=We(e,a);return n.delta=io(e),n}var ju=2;function Hn(e){var a=[];for(var n=0,t=Math.min(e.length,ju);n<t;n++)a.push(e[n]);return a}function Zt(e,a,n){var t={touches:Hn(e.touches).map(function(r){return we(r,n)}),previousTouches:a.map(function(r){return we(r,n)}),sigmaDefaultPrevented:!1,preventSigmaDefault:function(){t.sigmaDefaultPrevented=!0},original:e};return t}function io(e){if(typeof e.deltaY<"u")return e.deltaY*-3/360;if(typeof e.detail<"u")return e.detail/-9;throw Error("Captor: could not extract delta from event.")}var oo=function(e){function a(n,t){var r;return ie(this,a),r=fe(this,a),r.container=n,r.renderer=t,r}return ge(a,e),oe(a)}(_n),qu=["doubleClickTimeout","doubleClickZoomingDuration","doubleClickZoomingRatio","dragTimeout","draggedEventsTolerance","enableCameraMouseRotation","gestureTarget","inertiaDuration","inertiaRatio","zoomDuration","zoomingRatio"],Yu=qu.reduce(function(e,a){return V(V({},e),{},R({},a,En[a]))},{});function Qt(e){return e instanceof PointerEvent&&e.pointerType==="touch"}var Ku=function(e){function a(n,t){var r;return ie(this,a),r=fe(this,a,[n,t]),R(r,"enabled",!0),R(r,"draggedEvents",0),R(r,"downStartTime",null),R(r,"lastMouseX",null),R(r,"lastMouseY",null),R(r,"isMouseDown",!1),R(r,"isMoving",!1),R(r,"isPanningStage",!1),R(r,"movingTimeout",null),R(r,"startCameraState",null),R(r,"clicks",0),R(r,"doubleClickTimeout",null),R(r,"isRightMouseDown",!1),R(r,"startRotationAngle",null),R(r,"startCameraAngle",null),R(r,"currentWheelDirection",0),R(r,"lastWheelAnimationId",0),R(r,"settings",Yu),r.handleRightClick=r.handleRightClick.bind(r),r.handleDown=r.handleDown.bind(r),r.handleUp=r.handleUp.bind(r),r.handleMove=r.handleMove.bind(r),r.handleWheel=r.handleWheel.bind(r),r.handleLeave=r.handleLeave.bind(r),r.handleEnter=r.handleEnter.bind(r),n.addEventListener("contextmenu",r.handleRightClick,{capture:!1}),n.addEventListener("pointerdown",r.handleDown,{capture:!1}),n.addEventListener("wheel",r.handleWheel,{capture:!1,passive:!1}),n.addEventListener("pointerleave",r.handleLeave,{capture:!1}),n.addEventListener("pointerenter",r.handleEnter,{capture:!1}),document.addEventListener("pointermove",r.handleMove,{capture:!1}),document.addEventListener("pointerup",r.handleUp,{capture:!1}),r}return ge(a,e),oe(a,[{key:"kill",value:function(){var t=this.container;t.removeEventListener("contextmenu",this.handleRightClick),t.removeEventListener("pointerdown",this.handleDown),t.removeEventListener("wheel",this.handleWheel),t.removeEventListener("pointerleave",this.handleLeave),t.removeEventListener("pointerenter",this.handleEnter),document.removeEventListener("pointermove",this.handleMove),document.removeEventListener("pointerup",this.handleUp)}},{key:"handleClick",value:function(t){var r=this;if(!this.enabled)return;if(this.clicks++,this.clicks===2){if(this.clicks=0,typeof this.doubleClickTimeout==="number")clearTimeout(this.doubleClickTimeout),this.doubleClickTimeout=null;return this.handleDoubleClick(t)}if(setTimeout(function(){r.clicks=0,r.doubleClickTimeout=null},this.settings.doubleClickTimeout),this.draggedEvents<this.settings.draggedEventsTolerance)this.emit("click",We(t,this.container))}},{key:"handleRightClick",value:function(t){if(!this.enabled)return;if(this.settings.enableCameraMouseRotation)t.preventDefault();this.emit("rightClick",We(t,this.container))}},{key:"handleDoubleClick",value:function(t){if(!this.enabled)return;t.preventDefault(),t.stopPropagation();var r=We(t,this.container);if(this.emit("doubleClick",r),r.sigmaDefaultPrevented)return;var i=this.renderer.getCamera(),o=i.getBoundedRatio(i.getState().ratio/this.settings.doubleClickZoomingRatio);i.animate(this.renderer.getViewportZoomedState(we(t,this.container),o),{easing:"quadraticInOut",duration:this.settings.doubleClickZoomingDuration})}},{key:"handleDown",value:function(t){if(!this.enabled||Qt(t))return;if(t.button===0){this.startCameraState=this.renderer.getCamera().getState();var r=we(t,this.container),{x:i,y:o}=r;this.lastMouseX=i,this.lastMouseY=o,this.draggedEvents=0,this.downStartTime=Date.now(),this.isMouseDown=!0}if(t.button===2&&this.settings.enableCameraMouseRotation){var s=we(t,this.container),{x:l,y:d}=s,u=this.container.offsetWidth/2,c=this.container.offsetHeight/2;this.startRotationAngle=Math.atan2(d-c,l-u),this.startCameraAngle=this.renderer.getCamera().getState().angle,this.isRightMouseDown=!0}this.emit("mousedown",We(t,this.container))}},{key:"handleUp",value:function(t){var r=this;if(!this.enabled||Qt(t)||!this.isMouseDown&&!this.isRightMouseDown)return;if(this.isRightMouseDown){this.isRightMouseDown=!1,this.startRotationAngle=null,this.startCameraAngle=null,this.emit("mouseup",We(t,this.container));return}var i=this.renderer.getCamera();if(this.isMouseDown=!1,this.isPanningStage)this.isPanningStage=!1,this.renderer._setPanning(!1);if(typeof this.movingTimeout==="number")clearTimeout(this.movingTimeout),this.movingTimeout=null;var o=we(t,this.container),{x:s,y:l}=o,d=i.getState(),u=i.getPreviousState();if(this.isMoving)i.animate({x:d.x+this.settings.inertiaRatio*(d.x-u.x),y:d.y+this.settings.inertiaRatio*(d.y-u.y)},{duration:this.settings.inertiaDuration,easing:"quadraticOut"});else if(this.lastMouseX!==s||this.lastMouseY!==l)i.setState({x:d.x,y:d.y});if(this.isMoving=!1,setTimeout(function(){var c=r.draggedEvents>0;r.draggedEvents=0;var g=r.renderer.getSetting("hideEdgesOnMove")||r.renderer.getSetting("hideLabelsOnMove");if(c&&g)r.renderer.refresh()},0),this.emit("mouseup",We(t,this.container)),t.target===this.container||t.composedPath()[0]===this.container)this.handleClick(t)}},{key:"handleMove",value:function(t){var r=this;if(!this.enabled||Qt(t))return;var i=We(t,this.container);if(this.emit("mousemovebody",i),t.target===this.container||t.composedPath()[0]===this.container)this.emit("mousemove",i);if(this.isMouseDown)this.draggedEvents++;if(i.sigmaDefaultPrevented)return;if(this.isMouseDown){if(this.isMoving=!0,typeof this.movingTimeout==="number")clearTimeout(this.movingTimeout);this.movingTimeout=window.setTimeout(function(){r.movingTimeout=null,r.isMoving=!1},this.settings.dragTimeout);var o=this.renderer.getCamera(),s=we(t,this.container),{x:l,y:d}=s,u=this.renderer.viewportToFramedGraph({x:this.lastMouseX,y:this.lastMouseY}),c=this.renderer.viewportToFramedGraph({x:l,y:d}),g=u.x-c.x,h=u.y-c.y,p=o.getState(),y=p.x+g,v=p.y+h;if(!this.isPanningStage)this.isPanningStage=!0,this.renderer._setPanning(!0);o.setState({x:y,y:v}),this.lastMouseX=l,this.lastMouseY=d,t.preventDefault(),t.stopPropagation()}if(this.isRightMouseDown){var f=we(t,this.container),{x:b,y:m}=f,T=this.container.offsetWidth/2,_=this.container.offsetHeight/2,x=Math.atan2(m-_,b-T),S=x-this.startRotationAngle,E=this.renderer.getCamera();E.setState({angle:this.startCameraAngle+S}),t.preventDefault(),t.stopPropagation()}}},{key:"handleLeave",value:function(t){if(Qt(t))return;this.emit("mouseleave",We(t,this.container))}},{key:"handleEnter",value:function(t){if(Qt(t))return;this.emit("mouseenter",We(t,this.container))}},{key:"handleWheel",value:function(t){var r=this,i=this.renderer.getCamera();if(!this.enabled||!i.enabledZooming)return;var o=Xu(t,this.container);if(this.emit("wheel",o),o.sigmaDefaultPrevented)return;var s=this.settings.gestureTarget;if(s==="page")return;if(s==="shared"&&!t.ctrlKey&&!t.metaKey){this.renderer._showGestureHint("wheel");return}var l=io(t);if(!l)return;t.preventDefault(),t.stopPropagation();var d=i.getState().ratio,u=l>0?1/this.settings.zoomingRatio:this.settings.zoomingRatio,c=i.getBoundedRatio(d*u),g=l>0?1:-1,h=Date.now();if(d===c)return;if(this.currentWheelDirection===g&&this.lastWheelTriggerTime&&h-this.lastWheelTriggerTime<this.settings.zoomDuration/5)return;var p=++this.lastWheelAnimationId;i.animate(this.renderer.getViewportZoomedState(we(t,this.container),c),{easing:"quadraticOut",duration:this.settings.zoomDuration}).then(function(){if(r.lastWheelAnimationId===p)r.currentWheelDirection=0}),this.currentWheelDirection=g,this.lastWheelTriggerTime=h}},{key:"setSettings",value:function(t){this.settings=t}}])}(oo),Zu=["dragTimeout","gestureTarget","inertiaDuration","inertiaRatio","doubleClickTimeout","doubleClickZoomingRatio","doubleClickZoomingDuration","tapMoveTolerance"],Qu=Zu.reduce(function(e,a){return V(V({},e),{},R({},a,En[a]))},{}),Ju=function(e){function a(n,t){var r;return ie(this,a),r=fe(this,a,[n,t]),R(r,"enabled",!0),R(r,"isMoving",!1),R(r,"hasMoved",!1),R(r,"isPanningStage",!1),R(r,"isZoomingStage",!1),R(r,"touchMode",0),R(r,"startTouchesPositions",[]),R(r,"lastTouches",[]),R(r,"lastTap",null),R(r,"settings",Qu),r.handleStart=r.handleStart.bind(r),r.handleLeave=r.handleLeave.bind(r),r.handleMove=r.handleMove.bind(r),n.addEventListener("touchstart",r.handleStart,{capture:!1}),n.addEventListener("touchcancel",r.handleLeave,{capture:!1}),document.addEventListener("touchend",r.handleLeave,{capture:!1,passive:!1}),document.addEventListener("touchmove",r.handleMove,{capture:!1,passive:!1}),r}return ge(a,e),oe(a,[{key:"kill",value:function(){var t=this.container;t.removeEventListener("touchstart",this.handleStart),t.removeEventListener("touchcancel",this.handleLeave),document.removeEventListener("touchend",this.handleLeave),document.removeEventListener("touchmove",this.handleMove)}},{key:"getDimensions",value:function(){return{width:this.container.offsetWidth,height:this.container.offsetHeight}}},{key:"doesCapture",value:function(t){var r=this.settings.gestureTarget;if(r==="graph")return!0;if(r==="page")return!1;return t>=2}},{key:"syncStageFlags",value:function(){var t=this.touchMode===1&&this.hasMoved,r=this.touchMode===2;if(t!==this.isPanningStage)this.isPanningStage=t,this.renderer._setPanning(t);if(r!==this.isZoomingStage)this.isZoomingStage=r,this.renderer._setZooming(r)}},{key:"handleStart",value:function(t){var r=this;if(!this.enabled)return;var i=Hn(t.touches);if(this.touchMode=i.length,this.startCameraState=this.renderer.getCamera().getState(),this.startTouchesPositions=i.map(function(h){return we(h,r.container)}),this.touchMode===2){var o=le(this.startTouchesPositions,2),s=o[0],{x:l,y:d}=s,u=o[1],{x:c,y:g}=u;this.startTouchesAngle=Math.atan2(g-d,c-l),this.startTouchesDistance=Math.sqrt(Math.pow(c-l,2)+Math.pow(g-d,2))}if(this.syncStageFlags(),this.emit("touchdown",Zt(t,this.lastTouches,this.container)),this.lastTouches=i,this.lastTouchesPositions=this.startTouchesPositions,t.cancelable&&(this.doesCapture(t.touches.length)||this.renderer._hasNodeDrag()))t.preventDefault()}},{key:"handleLeave",value:function(t){if(!this.enabled||!this.startTouchesPositions.length)return;if(t.cancelable&&this.doesCapture(this.touchMode))t.preventDefault();if(this.movingTimeout)this.isMoving=!1,clearTimeout(this.movingTimeout);switch(this.touchMode){case 2:if(t.touches.length===1){this.handleStart(t);break}case 1:if(this.isMoving){var r=this.renderer.getCamera(),i=r.getState(),o=r.getPreviousState();r.animate({x:i.x+this.settings.inertiaRatio*(i.x-o.x),y:i.y+this.settings.inertiaRatio*(i.y-o.y)},{duration:this.settings.inertiaDuration,easing:"quadraticOut"})}this.hasMoved=!1,this.isMoving=!1,this.touchMode=0;break}if(this.syncStageFlags(),this.emit("touchup",Zt(t,this.lastTouches,this.container)),!t.touches.length){var s=we(this.lastTouches[0],this.container),l=this.startTouchesPositions[0],d=Math.pow(s.x-l.x,2)+Math.pow(s.y-l.y,2);if(!t.touches.length&&d<Math.pow(this.settings.tapMoveTolerance,2))if(this.lastTap&&Date.now()-this.lastTap.time<this.settings.doubleClickTimeout){var u=Zt(t,this.lastTouches,this.container);if(this.emit("doubletap",u),this.lastTap=null,!u.sigmaDefaultPrevented&&this.settings.gestureTarget!=="page"){var c=this.renderer.getCamera(),g=c.getBoundedRatio(c.getState().ratio/this.settings.doubleClickZoomingRatio);c.animate(this.renderer.getViewportZoomedState(s,g),{easing:"quadraticInOut",duration:this.settings.doubleClickZoomingDuration})}}else{var h=Zt(t,this.lastTouches,this.container);this.emit("tap",h),this.lastTap={time:Date.now(),position:h.touches[0]||h.previousTouches[0]}}}this.lastTouches=Hn(t.touches),this.startTouchesPositions=[]}},{key:"handleMove",value:function(t){var r=this;if(!this.enabled||!this.startTouchesPositions.length)return;var i=this.doesCapture(t.touches.length);if(i)t.preventDefault();var o=Hn(t.touches),s=o.map(function(q){return we(q,r.container)}),l=this.lastTouches;this.lastTouches=o,this.lastTouchesPositions=s;var d=Zt(t,l,this.container);if(this.emit("touchmove",d),d.sigmaDefaultPrevented)return;if(this.hasMoved||(this.hasMoved=s.some(function(q,re){var Z=r.startTouchesPositions[re];return Z&&(q.x!==Z.x||q.y!==Z.y)})),!this.hasMoved)return;if(!i){if(this.settings.gestureTarget==="shared")this.renderer._showGestureHint("touch");return}if(this.isMoving=!0,this.syncStageFlags(),this.movingTimeout)clearTimeout(this.movingTimeout);this.movingTimeout=window.setTimeout(function(){r.isMoving=!1},this.settings.dragTimeout);var u=this.renderer.getCamera(),c=this.startCameraState,g=this.renderer.getSetting("stagePadding");switch(this.touchMode){case 1:{var h=this.renderer.viewportToFramedGraph((this.startTouchesPositions||[])[0]),{x:p,y}=h,v=this.renderer.viewportToFramedGraph(s[0]),{x:f,y:b}=v;u.setState({x:c.x+p-f,y:c.y+y-b});break}case 2:{var m={x:0.5,y:0.5,angle:0,ratio:1},T=s[0],{x:_,y:x}=T,S=s[1],{x:E,y:D}=S,A=Math.atan2(D-x,E-_)-this.startTouchesAngle,L=Math.hypot(D-x,E-_)/this.startTouchesDistance,w=u.getBoundedRatio(c.ratio/L);m.ratio=w,m.angle=c.angle+A;var M=this.getDimensions(),C=this.renderer.viewportToFramedGraph((this.startTouchesPositions||[])[0],{cameraState:c}),z=Math.min(M.width,M.height)-2*g,O=z/M.width,N=z/M.height,F=w/z,P=_-z/2/O,B=x-z/2/N,Y=oa({x:P,y:B},m.angle);P=Y.x,B=Y.y,m.x=C.x-P*F,m.y=C.y+B*F,u.setState(m);break}}}},{key:"setSettings",value:function(t){this.settings=t}}])}(oo),ec=function(){function e(a,n,t,r){ie(this,e),R(this,"pendingNode",null),R(this,"session",null),this.graph=a,this.viewportToGraph=n,this.setNodesState=t,this.emit=r}return oe(e,[{key:"start",value:function(n,t,r,i,o){var s=r(n),l=!1;if(this.emit("nodeDragStart",{node:n,allDraggedNodes:s,event:t,preventSigmaDefault:function(){l=!0}}),l)return!1;var d=new Map,u=W(s),c;try{for(u.s();!(c=u.n()).done;){var g=c.value;d.set(g,{x:this.graph.getNodeAttribute(g,i),y:this.graph.getNodeAttribute(g,o)})}}catch(h){u.e(h)}finally{u.f()}return this.session={node:n,allNodes:s,startPosition:this.viewportToGraph(t),startNodePositions:d,xAttr:i,yAttr:o},this.setNodesState(s,{isDragged:!0}),!0}},{key:"applyMove",value:function(n,t){var r=this.session,{allNodes:i,startNodePositions:o,startPosition:s,xAttr:l,yAttr:d}=r,u=this.viewportToGraph(n),c={x:u.x-s.x,y:u.y-s.y},g=W(i),h;try{for(g.s();!(h=g.n()).done;){var p=h.value,y=o.get(p);if(!y||!this.graph.hasNode(p))continue;var v={x:y.x+c.x,y:y.y+c.y};if(t)this.graph.mergeNodeAttributes(p,t(v,p));else this.graph.setNodeAttribute(p,l,v.x),this.graph.setNodeAttribute(p,d,v.y)}}catch(f){g.e(f)}finally{g.f()}}},{key:"end",value:function(){if(this.pendingNode=null,!this.session)return null;var n=this.session,{node:t,allNodes:r}=n;return this.setNodesState(r,{isDragged:!1}),this.session=null,{node:t,allNodes:r}}},{key:"removeNode",value:function(n){if(n===this.pendingNode)this.pendingNode=null;if(!this.session)return;if(this.session.node===n)this.setNodesState(this.session.allNodes,{isDragged:!1}),this.session=null;else if(this.session.allNodes.includes(n))this.session.allNodes=this.session.allNodes.filter(function(t){return t!==n}),this.session.startNodePositions.delete(n)}},{key:"clear",value:function(){this.pendingNode=null,this.session=null}}])}();function $i(e,a){return e<a?"".concat(e,"\\x00").concat(a):"".concat(a,"\\x00").concat(e)}var tc=function(){function e(a,n){ie(this,e),R(this,"groups",new Map),R(this,"edgeToGroupKey",new Map),this.graph=a,this.onGroupChanged=n}return oe(e,[{key:"getGroupKey",value:function(n){return $i(this.graph.source(n),this.graph.target(n))}},{key:"sortGroup",value:function(n,t){var r=this,i=t.split("\\x00")[0];n.sort(function(o,s){var l=r.graph.source(o)===i||!r.graph.isDirected(o)?0:1,d=r.graph.source(s)===i||!r.graph.isDirected(s)?0:1;return l-d})}},{key:"register",value:function(n){var t=this.getGroupKey(n),r=this.groups.get(t);if(!r)r=[],this.groups.set(t,r);if(!r.includes(n))r.push(n);if(this.edgeToGroupKey.set(n,t),r.length>1)this.sortGroup(r,t);this.onGroupChanged(r,r.length)}},{key:"unregister",value:function(n){var t=this.edgeToGroupKey.get(n);if(!t)return;this.edgeToGroupKey.delete(n);var r=this.groups.get(t);if(!r)return;var i=r.indexOf(n);if(i!==-1)r.splice(i,1);if(r.length===0)this.groups.delete(t);else this.onGroupChanged(r,r.length)}},{key:"getGroup",value:function(n){var t,r=this.edgeToGroupKey.get(n);if(!r)return[];return(t=this.groups.get(r))!==null&&t!==void 0?t:[]}},{key:"getSiblings",value:function(n){return this.getGroup(n).filter(function(t){return t!==n})}},{key:"rebuild",value:function(){var n=this;this.groups.clear(),this.edgeToGroupKey.clear(),this.graph.forEachEdge(function(l,d,u,c){var g=$i(u,c),h=n.groups.get(g);if(!h)h=[],n.groups.set(g,h);h.push(l),n.edgeToGroupKey.set(l,g)});var t=W(this.groups),r;try{for(t.s();!(r=t.n()).done;){var i=le(r.value,2),o=i[0],s=i[1];if(s.length>1)this.sortGroup(s,o);this.onGroupChanged(s,s.length)}}catch(l){t.e(l)}finally{t.f()}}},{key:"clear",value:function(){this.groups.clear(),this.edgeToGroupKey.clear()}}])}();function Vi(e,a){var n;if(e===!1||e==="extend"||e==="separate")return e;var t=e[a];if(t!==void 0)return t;return(n=e.default)!==null&&n!==void 0?n:!1}function Xi(e){if(e===!1)return!1;if(e==="extend"||e==="separate")return!0;return Object.values(e).some(function(a){return a==="extend"||a==="separate"})}function ji(e){if(e==="separate")return!0;if(e===!1||e==="extend")return!1;if(e.default==="separate")return!0;return Object.values(e).includes("separate")}var Se={node:{parent:null,eventSuffix:"Node",payloadKey:"node",isEnabled:function(){return!0},writesPickingThisFrame:function(){return!0},setHover:function(a,n,t){return a.setNodeState(n,{isHovered:t})},getCursor:function(a,n){var t;return(t=a.nodeDataCache[n])===null||t===void 0?void 0:t.cursor},isHitValid:function(a,n){var t;return((t=a.nodeDataCache[n])===null||t===void 0?void 0:t.visibility)!=="hidden"}},edge:{parent:null,eventSuffix:"Edge",payloadKey:"edge",isEnabled:function(a){return!!a.settings.enableEdgeEvents},writesPickingThisFrame:function(a){return!!a.settings.enableEdgeEvents},setHover:function(a,n,t){return a.setEdgeState(n,{isHovered:t})},getCursor:function(a,n){var t;return(t=a.edgeDataCache[n])===null||t===void 0?void 0:t.cursor}},nodeLabel:{parent:"node",eventSuffix:"NodeLabel",payloadKey:"node",isEnabled:function(a){return ji(a.settings.nodeLabelEvents)},writesPickingThisFrame:function(a){return Xi(a.settings.nodeLabelEvents)},setHover:function(a,n,t){return a.setNodeState(n,{isLabelHovered:t})},getCursor:function(a,n){var t;return(t=a.nodeDataCache[n])===null||t===void 0?void 0:t.labelCursor},resolveForVerb:function(a,n,t){var r=Vi(t.settings.nodeLabelEvents,n);if(r===!1)return null;if(r==="extend")return{kind:"node",key:a.key};return a}},edgeLabel:{parent:"edge",eventSuffix:"EdgeLabel",payloadKey:"edge",isEnabled:function(a){return ji(a.settings.edgeLabelEvents)},writesPickingThisFrame:function(a){return Xi(a.settings.edgeLabelEvents)},setHover:function(a,n,t){return a.setEdgeState(n,{isLabelHovered:t})},getCursor:function(a,n){var t;return(t=a.edgeDataCache[n])===null||t===void 0?void 0:t.labelCursor},resolveForVerb:function(a,n,t){var r=Vi(t.settings.edgeLabelEvents,n);if(r===!1)return null;if(r==="extend")return{kind:"edge",key:a.key};return a}}},ct=["node","edge","nodeLabel","edgeLabel"];function nc(){return{lookup:[null],idsByKind:{node:new Map,edge:new Map,nodeLabel:new Map,edgeLabel:new Map},nextId:1}}function ut(e,a,n){var t;return(t=e.idsByKind[a].get(n))!==null&&t!==void 0?t:0}function Wn(e,a){var n=W(ct),t;try{for(n.s();!(t=n.n()).done;){var r=t.value;if(r===a||Se[r].parent===a){var i=W(e.idsByKind[r].values()),o;try{for(i.s();!(o=i.n()).done;){var s=o.value;e.lookup[s]=null}}catch(g){i.e(g)}finally{i.f()}e.idsByKind[r]=new Map}}}catch(g){n.e(g)}finally{n.f()}var l=1,d=W(ct),u;try{for(d.s();!(u=d.n()).done;){var c=u.value;if(c===a)break;l+=e.idsByKind[c].size}}catch(g){d.e(g)}finally{d.f()}e.nextId=l}function qi(e,a,n){var t=e.nextId++;return e.idsByKind[a].set(n,t),e.lookup[t]={kind:a,key:n},t}function Yi(e,a,n){for(var t=0,r=$n(a);t<r.length;t++){var i=r[t],o=e.idsByKind[i].get(n);if(o===void 0)continue;e.lookup[o]=null,e.idsByKind[i].delete(n)}}function ac(e,a){var n=W(ct),t;try{for(n.s();!(t=n.n()).done;){var r=t.value;if(Se[r].parent===null)continue;var i=W(e.idsByKind[r].values()),o;try{for(i.s();!(o=i.n()).done;){var s=o.value;e.lookup[s]=null}}catch(_){i.e(_)}finally{i.f()}e.idsByKind[r]=new Map}}catch(_){n.e(_)}finally{n.f()}e.nextId=1;var l=W(ct),d;try{for(l.s();!(d=l.n()).done;){var u=d.value;if(Se[u].parent!==null)continue;var c=W(e.idsByKind[u].values()),g;try{for(c.s();!(g=c.n()).done;){var h=g.value;if(h>=e.nextId)e.nextId=h+1}}catch(_){c.e(_)}finally{c.f()}}}catch(_){l.e(_)}finally{l.f()}var p=W(ct),y;try{for(p.s();!(y=p.n()).done;){var v=y.value,f=Se[v];if(f.parent===null||!f.isEnabled(a))continue;var b=W(e.idsByKind[f.parent].keys()),m;try{for(b.s();!(m=b.n()).done;){var T=m.value;e.idsByKind[v].set(T,e.nextId),e.lookup[e.nextId]={kind:v,key:T},e.nextId++}}catch(_){b.e(_)}finally{b.f()}}}catch(_){p.e(_)}finally{p.f()}}function rc(e,a){var n=W(ct),t;try{for(n.s();!(t=n.n()).done;){var r=t.value,i=e[r],o=a[r];if(i===o)continue;if(i.size!==o.size)return!1;var s=W(i),l;try{for(s.s();!(l=s.n()).done;){var d=le(l.value,2),u=d[0],c=d[1];if(o.get(u)!==c)return!1}}catch(g){s.e(g)}finally{s.f()}}}catch(g){n.e(g)}finally{n.f()}return!0}function Ki(e,a,n){Se[a.kind].setHover(e,a.key,n)}function ic(e,a){return Se[a.kind].getCursor(e,a.key)}function Jt(e,a){return"".concat(a).concat(Se[e].eventSuffix)}function en(e,a){return V(V({},a),{},R({},Se[e.kind].payloadKey,e.key))}function oc(e,a,n){var t=Se[a.kind].resolveForVerb;return t?t(a,n,e):a}function sc(e,a){var n=Se[a.kind].isHitValid;return n?n(e,a.key):!0}function $n(e){return ct.filter(function(a){return a===e||Se[a].parent===e})}function so(e,a,n){if(a)a=oc(e,a,n);if(a&&!sc(e,a))a=null;return a}function ja(e,a,n){var t=n==="wheel"?e.stateManager.hovered:e.getHitAtPosition(a);return so(e,t,n)}function lc(e,a){if(!e||!a)return e===a;return e.kind===a.kind&&e.key===a.key}function lo(e,a,n){var t={event:n,preventSigmaDefault:function(){return n.preventSigmaDefault()}},r=e.dragManager.session,i=r?{kind:"node",key:r.node}:so(e,a,"enter"),o=e.stateManager,s=o.hovered;if(lc(s,i))return;if(s)Ki(e,s,!1),e.emit(Jt(s.kind,"leave"),en(s,t));if(o.setHovered(i),i)Ki(e,i,!0),e.emit(Jt(i.kind,"enter"),en(i,t));e.updateContainerCursor()}function dc(e,a,n,t){t.handleResize=function(){return e.scheduleRefresh()},window.addEventListener("resize",t.handleResize),t.handleMove=function(i){e.hoverResolver.pointerMoved(lt(i))},t.handleMoveBody=function(i){var o=lt(i),s=e.dragManager;if(s.pendingNode&&!s.session){var l=e.nodeStyleAnalysis,{xAttribute:d,yAttribute:u}=l,c=e.settings;s.start(s.pendingNode,o,c.getDraggedNodes,d||"x",u||"y"),s.pendingNode=null}if(s.session)s.applyMove(o,e.settings.dragPositionToAttributes),e.emit("nodeDrag",{node:s.session.node,allDraggedNodes:s.session.allNodes,event:o}),o.preventSigmaDefault();e.emit("moveBody",{event:o,preventSigmaDefault:function(){return o.preventSigmaDefault()}})},t.handleLeave=function(i){var o=lt(i),s={event:o,preventSigmaDefault:function(){return o.preventSigmaDefault()}};e.hoverResolver.pointerLeft(),lo(e,null,o),e.emit("leaveStage",s)},t.handleEnter=function(i){var o=lt(i);e.emit("enterStage",{event:o,preventSigmaDefault:function(){return o.preventSigmaDefault()}})};var r=function(o){return function(s){var l=lt(s),d={event:l,preventSigmaDefault:function(){return l.preventSigmaDefault()}},u=ja(e,l,o);if(u){e.emit(Jt(u.kind,o),en(u,d));return}e.emit("".concat(o,"Stage"),d)}};t.handleClick=r("click"),t.handleRightClick=r("rightClick"),t.handleDoubleClick=r("doubleClick"),t.handleWheel=r("wheel"),t.handleDown=function(i){var o=lt(i),s={event:o,preventSigmaDefault:function(){return o.preventSigmaDefault()}},l=ja(e,o,"down");if(l){if(l.kind==="node"&&e.settings.enableNodeDrag)e.dragManager.pendingNode=l.key;e.emit(Jt(l.kind,"down"),en(l,s));return}e.emit("downStage",s)},t.handleUp=function(i){var o=lt(i),s={event:o,preventSigmaDefault:function(){return o.preventSigmaDefault()}},l=e.dragManager.end();if(l)e.emit("nodeDragEnd",V({node:l.node,allDraggedNodes:l.allNodes},s));var d=ja(e,o,"up");if(d){e.emit(Jt(d.kind,"up"),en(d,s));return}e.emit("upStage",s)},a.on("mousemove",t.handleMove),a.on("mousemovebody",t.handleMoveBody),a.on("click",t.handleClick),a.on("rightClick",t.handleRightClick),a.on("doubleClick",t.handleDoubleClick),a.on("wheel",t.handleWheel),a.on("mousedown",t.handleDown),a.on("mouseup",t.handleUp),a.on("mouseleave",t.handleLeave),a.on("mouseenter",t.handleEnter),n.on("touchdown",t.handleDown),n.on("touchdown",t.handleMove),n.on("touchup",t.handleUp),n.on("touchmove",t.handleMove),n.on("tap",t.handleClick),n.on("doubletap",t.handleDoubleClick),n.on("touchmove",t.handleMoveBody)}function uc(e,a){var n=e.graph,t=new Set(["x","y","zIndex","type"]);a.eachNodeAttributesUpdatedGraphUpdate=function(r){var i,o=(i=r.hints)===null||i===void 0?void 0:i.attributes,s=!o||o.some(function(l){return t.has(l)});e.refresh({partialGraph:{nodes:n.nodes()},skipIndexation:!s,schedule:!0})},a.eachEdgeAttributesUpdatedGraphUpdate=function(r){var i,o=(i=r.hints)===null||i===void 0?void 0:i.attributes,s=o&&["zIndex","type"].some(function(l){return o===null||o===void 0?void 0:o.includes(l)});e.refresh({partialGraph:{edges:n.edges()},skipIndexation:!s,schedule:!0})},a.addNodeGraphUpdate=function(r){e.refresh({partialGraph:{nodes:[r.key]},skipIndexation:!1,schedule:!0})},a.updateNodeGraphUpdate=function(r){e.refresh({partialGraph:{nodes:[r.key]},skipIndexation:!1,schedule:!0})},a.dropNodeGraphUpdate=function(r){e.removeNode(r.key),e.scheduleProcess()},a.addEdgeGraphUpdate=function(r){var i=r.key;e.markNodesDirty([r.source,r.target]),e.edgeGroups.register(i);var o=e.edgeGroups.getSiblings(i);e.refresh({partialGraph:{edges:[i].concat(J(o))},schedule:!0})},a.updateEdgeGraphUpdate=function(r){e.refresh({partialGraph:{edges:[r.key]},skipIndexation:!1,schedule:!0})},a.dropEdgeGraphUpdate=function(r){var i=r.key;e.markNodesDirty([r.source,r.target]);var o=e.edgeGroups.getSiblings(i);e.edgeGroups.unregister(i),e.removeEdge(i);var s=W(o),l;try{for(s.s();!(l=s.n()).done;){var d=l.value;e.addEdge(d)}}catch(u){s.e(u)}finally{s.f()}e.scheduleProcess()},a.clearEdgesGraphUpdate=function(){e.clearEdgeState(),e.clearEdgeIndices(),e.refresh({schedule:!0})},a.clearGraphUpdate=function(){e.clearEdgeState(),e.clearNodeState(),e.clearEdgeIndices(),e.clearNodeIndices(),e.refresh({schedule:!0})},n.on("nodeAdded",a.addNodeGraphUpdate),n.on("nodeDropped",a.dropNodeGraphUpdate),n.on("nodeAttributesUpdated",a.updateNodeGraphUpdate),n.on("eachNodeAttributesUpdated",a.eachNodeAttributesUpdatedGraphUpdate),n.on("edgeAdded",a.addEdgeGraphUpdate),n.on("edgeDropped",a.dropEdgeGraphUpdate),n.on("edgeAttributesUpdated",a.updateEdgeGraphUpdate),n.on("eachEdgeAttributesUpdated",a.eachEdgeAttributesUpdatedGraphUpdate),n.on("edgesCleared",a.clearEdgesGraphUpdate),n.on("cleared",a.clearGraphUpdate)}function cc(e,a){e.removeListener("nodeAdded",a.addNodeGraphUpdate),e.removeListener("nodeDropped",a.dropNodeGraphUpdate),e.removeListener("nodeAttributesUpdated",a.updateNodeGraphUpdate),e.removeListener("eachNodeAttributesUpdated",a.eachNodeAttributesUpdatedGraphUpdate),e.removeListener("edgeAdded",a.addEdgeGraphUpdate),e.removeListener("edgeDropped",a.dropEdgeGraphUpdate),e.removeListener("edgeAttributesUpdated",a.updateEdgeGraphUpdate),e.removeListener("eachEdgeAttributesUpdated",a.eachEdgeAttributesUpdatedGraphUpdate),e.removeListener("edgesCleared",a.clearEdgesGraphUpdate),e.removeListener("cleared",a.clearGraphUpdate)}var hc={x:0.5,y:0.5,angle:0,ratio:1},fc=8,gc=0.001;function vc(e){var{coords:a,nodeData:n,dimensions:t,stagePadding:r,zoomToSizeRatioFunction:i,itemSizesReference:o,fitLabels:s,nodeLabelBox:l}=e,d=Object.keys(a);if(!d.length)return e.extent;var u=i(1)||1,c=o==="positions",{width:g,height:h}=t,p=e.extent;for(var y=0;y<fc;y++){var v=Sn(p),f={width:p.x[1]-p.x[0]||1,height:p.y[1]-p.y[0]||1},b=qe(hc,t,f,r),m=Zi(b,v({x:0,y:0}),g,h),T=Zi(b,v({x:1,y:0}),g,h),_=Math.hypot(T.x-m.x,T.y-m.y)||1,x=1/0,S=-1/0,E=1/0,D=-1/0;for(var A=0,L=d.length;A<L;A++){var w=d[A],M=n[w],C=M.size/u*(c?_:1),z=-C,O=C,N=-C,F=C;if(s){var P=l(M,C);if(P){if(P.minX<z)z=P.minX;if(P.maxX>O)O=P.maxX;if(P.minY<N)N=P.minY;if(P.maxY>F)F=P.maxY}}var B=a[w],{x:Y,y:q}=B;x=Math.min(x,Y+z/_),S=Math.max(S,Y+O/_),E=Math.min(E,q-F/_),D=Math.max(D,q-N/_)}var re={x:[x,S],y:[E,D]},Z=Math.max(re.x[1]-re.x[0],re.y[1]-re.y[0])||1,ee=Math.max(Math.abs(re.x[0]-p.x[0]),Math.abs(re.x[1]-p.x[1]),Math.abs(re.y[0]-p.y[0]),Math.abs(re.y[1]-p.y[1]));if(p=re,ee/Z<gc)break}return p}function Zi(e,a,n,t){var r=xt(e,a);return{x:(1+r.x)*n/2,y:(1-r.y)*t/2}}var pc=typeof navigator<"u"&&/Mac|iP(hone|ad|od)/.test(navigator.platform),mc=1500,bc=`.sigma-gesture-hint {\n position: absolute;\n inset: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n text-align: center;\n padding: 1em;\n background: #00000066;\n color: #ffffff;\n font-size: 1em;\n pointer-events: none;\n transition: opacity 0.1s;\n}`;function Qi(e){var a,n,t=Rt("style");t.textContent=e,document.head.appendChild(t);var r=((a=(n=t.sheet)===null||n===void 0?void 0:n.cssRules.length)!==null&&a!==void 0?a:0)>0;return t.remove(),r}var dt=null;function yc(){if(dt===null){if(dt=bc,Qi("@scope {}"))dt=`@scope {\n`.concat(dt,`\n}`);if(Qi("@layer sigma-gesture-hint {}"))dt=`@layer sigma-gesture-hint {\n`.concat(dt,`\n}`)}return dt}var xc=function(){function e(a){ie(this,e),R(this,"hideTimeout",null),this.styleElement=Rt("style"),this.styleElement.textContent=yc(),a.appendChild(this.styleElement),this.element=Rt("div",{opacity:"0"},{class:"sigma-gesture-hint"}),a.appendChild(this.element)}return oe(e,[{key:"show",value:function(n,t){var r=this,i=n==="touch"?t.sharedGestureTouchMessage:pc?t.sharedGestureAppleWheelMessage:t.sharedGestureWheelMessage;if(!i)return;if(this.element.textContent=i,this.element.style.opacity="1",typeof this.hideTimeout==="number")clearTimeout(this.hideTimeout);this.hideTimeout=window.setTimeout(function(){r.hideTimeout=null,r.element.style.opacity="0"},mc)}},{key:"kill",value:function(){if(typeof this.hideTimeout==="number")clearTimeout(this.hideTimeout);this.styleElement.remove(),this.element.remove()}}])}(),_c=function(){function e(a){ie(this,e),R(this,"readBuffer",null),R(this,"fence",null),R(this,"result",new Uint8Array(4)),R(this,"generation",0),R(this,"readGeneration",0),R(this,"lastEvent",null),R(this,"active",!1),R(this,"dirty",!1),R(this,"rafId",null),R(this,"killed",!1),this.options=a}return oe(e,[{key:"pointerMoved",value:function(n){if(this.lastEvent=n,this.active=!0,this.options.isRenderPending())return;this.request()}},{key:"pointerLeft",value:function(){this.active=!1,this.dirty=!1}},{key:"frameRendered",value:function(){this.request()}},{key:"invalidate",value:function(){this.generation++}},{key:"request",value:function(){if(this.killed||!this.active||!this.lastEvent)return;if(this.fence){this.dirty=!0;return}this.startRead()}},{key:"startRead",value:function(){var n=this.options,{gl:t,getFrameBuffer:r,getPixelRatio:i,getDownSizingRatio:o}=n;this.readGeneration=this.generation;var s=this.lastEvent,l=sa(t,s.x,s.y,i(),o()),d=le(l,2),u=d[0],c=d[1];if(!this.readBuffer)this.readBuffer=t.createBuffer();t.bindFramebuffer(t.FRAMEBUFFER,r()),t.bindBuffer(t.PIXEL_PACK_BUFFER,this.readBuffer),t.bufferData(t.PIXEL_PACK_BUFFER,4,t.STREAM_READ),t.readPixels(u,c,1,1,t.RGBA,t.UNSIGNED_BYTE,0),t.bindBuffer(t.PIXEL_PACK_BUFFER,null),t.bindFramebuffer(t.FRAMEBUFFER,null),this.fence=t.fenceSync(t.SYNC_GPU_COMMANDS_COMPLETE,0),t.flush(),this.schedulePoll(s)}},{key:"schedulePoll",value:function(n){var t=this;this.rafId=requestAnimationFrame(function(){t.rafId=null,t.poll(n)})}},{key:"poll",value:function(n){var t=this.options,{gl:r,onIndex:i}=t;if(this.killed||!this.fence)return;var o=r.clientWaitSync(this.fence,0,0);if(o===r.TIMEOUT_EXPIRED){this.schedulePoll(n);return}if(r.deleteSync(this.fence),this.fence=null,o!==r.WAIT_FAILED&&this.readGeneration===this.generation){r.bindBuffer(r.PIXEL_PACK_BUFFER,this.readBuffer),r.getBufferSubData(r.PIXEL_PACK_BUFFER,0,this.result),r.bindBuffer(r.PIXEL_PACK_BUFFER,null);var s=le(this.result,4),l=s[0],d=s[1],u=s[2],c=s[3];if(this.active)i(la(l,d,u,c),n)}if(this.dirty){if(this.dirty=!1,this.active&&this.lastEvent&&!this.options.isRenderPending())this.startRead()}}},{key:"reset",value:function(){if(this.rafId!==null)cancelAnimationFrame(this.rafId);this.rafId=null,this.fence=null,this.readBuffer=null,this.dirty=!1}},{key:"kill",value:function(){if(this.killed=!0,this.rafId!==null)cancelAnimationFrame(this.rafId);this.rafId=null;var n=this.options.gl;if(this.fence)n.deleteSync(this.fence);if(this.fence=null,this.readBuffer)n.deleteBuffer(this.readBuffer);this.readBuffer=null}}])}(),Ji=function(){function e(a,n){ie(this,e),this.key=a,this.size=n}return oe(e,null,[{key:"compare",value:function(n,t){if(n.size>t.size)return-1;if(n.size<t.size)return 1;if(n.key>t.key)return 1;return-1}}])}(),Un=function(){function e(){ie(this,e),R(this,"width",0),R(this,"height",0),R(this,"cellSize",0),R(this,"columns",0),R(this,"rows",0),R(this,"cells",{})}return oe(e,[{key:"resizeAndClear",value:function(n,t){this.width=n.width,this.height=n.height,this.cellSize=t,this.columns=Math.ceil(n.width/t),this.rows=Math.ceil(n.height/t),this.cells={}}},{key:"getIndex",value:function(n){var t=Math.floor(n.x/this.cellSize),r=Math.floor(n.y/this.cellSize);return r*this.columns+t}},{key:"add",value:function(n,t,r){var i=new Ji(n,t),o=this.getIndex(r),s=this.cells[o];if(!s)s=[],this.cells[o]=s;s.push(i)}},{key:"organize",value:function(){for(var n in this.cells){var t=this.cells[n];t.sort(Ji.compare)}}},{key:"getLabelsToDisplay",value:function(n,t,r){var i=this.cellSize*this.cellSize,o=i/n/n,s=o*t/i,l=Math.ceil(s),d=[];if(r){var u=Math.max(0,Math.floor(r.x1/this.cellSize)),c=Math.min(this.columns-1,Math.floor(r.x2/this.cellSize)),g=Math.max(0,Math.floor(r.y1/this.cellSize)),h=Math.min(this.rows-1,Math.floor(r.y2/this.cellSize));for(var p=g;p<=h;p++)for(var y=u;y<=c;y++){var v=p*this.columns+y,f=this.cells[v];if(!f)continue;for(var b=0;b<Math.min(l,f.length);b++)d.push(f[b].key)}}else for(var m in this.cells){var T=this.cells[m];for(var _=0;_<Math.min(l,T.length);_++)d.push(T[_].key)}return d}}])}();function Tc(e){var{graph:a,hoveredNode:n,highlightedNodes:t,displayedNodeLabels:r}=e,i=new Set,o=new Set(t);if(n)o.add(n);var s=W(o),l;try{for(s.s();!(l=s.n()).done;){var d=l.value;if(!a.hasNode(d))continue;a.forEachEdge(d,function(h){i.add(h)})}}catch(h){s.e(h)}finally{s.f()}var u=W(r),c;try{var g=function(){var p=c.value;if(o.has(p))return 1;a.forEachEdge(p,function(y,v,f,b){var m=f===p?b:f;if(r.has(m))i.add(y)})};for(u.s();!(c=u.n()).done;)if(g())continue}catch(h){u.e(h)}finally{u.f()}return Array.from(i)}var Ft=150,It=50,Sc={both:0,node:1,label:2},Ec={over:0,above:1,below:2,auto:3},eo=12,Rc=3,Ac=function(){function e(a){ie(this,e),R(this,"labelGrid",new Un),R(this,"edgeAnchorGrid",new Un),R(this,"displayedNodeLabels",new Set),R(this,"displayedEdgeLabels",new Set),R(this,"edgeLabelCandidates",[]),R(this,"renderedNodeLabels",new Set),R(this,"labelSizeCache",new Map),R(this,"framePassPoints",new Float32Array(0)),R(this,"labelsDirty",!0),this.internals=a}return oe(e,[{key:"resetFrame",value:function(){this.displayedNodeLabels=new Set,this.renderedNodeLabels=new Set,this.labelSizeCache.clear()}},{key:"clearEdgeLabels",value:function(){this.displayedEdgeLabels=new Set}},{key:"resetLabelGrid",value:function(){this.labelGrid=new Un,this.edgeAnchorGrid=new Un}},{key:"processWebGLLabels",value:function(n){var t,r=this.internals,{labelProgram:i,primitives:o,nodeDataCache:s}=r,l=(o===null||o===void 0||(t=o.nodes)===null||t===void 0||(t=t.label)===null||t===void 0||(t=t.font)===null||t===void 0?void 0:t.family)||"sans-serif",d=new Map;for(var u=0,c=n.length;u<c;u++){var g=n[u],h=s[g];if(h.visibility==="hidden"||!h.label)continue;var p=h.labelFont||l,y=d.get(p);if(y)y.push(h.label);else d.set(p,[h.label])}var v=W(d),f;try{for(v.s();!(f=v.n()).done;){var b=le(f.value,2),m=b[0],T=b[1],_=An(m),{family:x,weight:S,style:E}=_,D=i.registerFont(x,S,E);i.ensureGlyphsReady(T,D)}}catch(A){v.e(A)}finally{v.f()}}},{key:"measureNodeLabel",value:function(n){var t,r;if(!n.label)return{width:0,height:0,textHeight:0};var i=this.internals,{labelProgram:o,primitives:s}=i,l=(t=n.labelSize)!==null&&t!==void 0?t:14,d=n.labelFont||(s===null||s===void 0||(r=s.nodes)===null||r===void 0||(r=r.label)===null||r===void 0||(r=r.font)===null||r===void 0?void 0:r.family)||"sans-serif",u="".concat(n.label,"|").concat(l,"|").concat(d);if(this.labelSizeCache.has(u))return this.labelSizeCache.get(u);var c=An(d),{family:g,weight:h,style:p}=c,y=o.registerFont(g,h,p),v=o.measureLabel(n.label,l,y);return this.labelSizeCache.set(u,v),v}},{key:"nodeLabelBox",value:function(n,t){var r,i,o,s,l;if(n.visibility==="hidden"||n.labelVisibility==="hidden")return null;var d=this.measureNodeLabel(n),{width:u,height:c,textHeight:g}=d;if(!u)return null;var h=(r=(i=this.internals.primitives)===null||i===void 0||(i=i.nodes)===null||i===void 0||(i=i.label)===null||i===void 0?void 0:i.margin)!==null&&r!==void 0?r:Dt,p=t+h,y=n.labelBackgroundColor?(o=n.labelBackgroundPadding)!==null&&o!==void 0?o:Ma:0,v=u/2,f=c/2,b=v+y,m=f+y,T=g/2,_=0,x=0;switch((s=n.labelPosition)!==null&&s!==void 0?s:"right"){case"left":_=-(p+v);break;case"above":x=-(p+T);break;case"below":x=p+T;break;case"over":break;default:_=p+v}var S=(l=n.labelAngle)!==null&&l!==void 0?l:0,E=oa({x:_,y:x},S),{x:D,y:A}=E,L=Math.abs(Math.cos(S)),w=Math.abs(Math.sin(S)),M=L*b+w*m,C=w*b+L*m;return{minX:D-M,maxX:D+M,minY:A-C,maxY:A+C}}},{key:"computeDisplayedNodeLabels",value:function(){var n=this.internals.getCameraState(),t=this.internals.getDimensions(),{width:r,height:i}=t,o=this.internals.viewportToFramedGraph({x:-Ft,y:-It}),s=this.internals.viewportToFramedGraph({x:r+Ft,y:-It}),l=this.internals.viewportToFramedGraph({x:-Ft,y:i+It}),d=this.internals.viewportToFramedGraph({x:r+Ft,y:i+It}),u=Math.min(o.x,s.x,l.x,d.x),c=Math.max(o.x,s.x,l.x,d.x),g=Math.min(o.y,s.y,l.y,d.y),h=Math.max(o.y,s.y,l.y,d.y),p=qe({x:0.5,y:0.5,ratio:1,angle:0},{width:r,height:i},this.internals.getGraphDimensions(),this.internals.getStagePadding()),y=function(P){var B=xt(p,P);return{x:(1+B.x)*r/2,y:(1-B.y)*i/2}},v=y({x:u,y:g}),f=y({x:c,y:g}),b=y({x:u,y:h}),m=y({x:c,y:h}),T={x1:Math.min(v.x,f.x,b.x,m.x),y1:Math.min(v.y,f.y,b.y,m.y),x2:Math.max(v.x,f.x,b.x,m.x),y2:Math.max(v.y,f.y,b.y,m.y)},_=this.internals,{settings:x,nodeDataCache:S,nodesWithForcedLabels:E}=_,D=this.labelGrid.getLabelsToDisplay(n.ratio,x.labelDensity,T);Ea(D,E);for(var A=0,L=D.length;A<L;A++){var w=D[A],M=S[w];if(this.displayedNodeLabels.has(w))continue;if(M.visibility==="hidden"||M.labelVisibility==="hidden")continue;if(!M.label)continue;if(M.x<u||M.x>c||M.y<g||M.y>h)continue;var C=this.internals.framedGraphToViewport(M),{x:z,y:O}=C,N=this.internals.scaleSize(M.size);if(!Ze(M)&&N<x.labelRenderedSizeThreshold)continue;if(z<-Ft-N||z>r+Ft+N||O<-It-N||O>i+It+N)continue;this.displayedNodeLabels.add(w)}}},{key:"buildFramePassPoints",value:function(){var n=this.internals,{nodeDataCache:t,nodeDataTexture:r}=n;if(!r)return{data:this.framePassPoints,count:0};var i=this.displayedNodeLabels.size*3;if(this.framePassPoints.length<i)this.framePassPoints=new Float32Array(i);var o=this.framePassPoints,s=0,l=W(this.displayedNodeLabels),d;try{for(l.s();!(d=l.n()).done;){var u,c,g=d.value,h=t[g];if(!h)continue;var p=r.getIndex(g);if(p<0)continue;o[s*3]=p,o[s*3+1]=(u=wt[h.labelPosition||Ve.labelPosition])!==null&&u!==void 0?u:0,o[s*3+2]=(c=h.labelAngle)!==null&&c!==void 0?c:0,s++}}catch(y){l.e(y)}finally{l.f()}return{data:o,count:s}}},{key:"renderWebGLLabels",value:function(n,t){var r=this.internals,{nodeDataCache:i,labelProgram:o,primitives:s,nodeDataTexture:l}=r,d=[],u=W(this.displayedNodeLabels),c;try{for(u.s();!(c=u.n()).done;){var g=c.value;if(this.renderedNodeLabels.has(g))continue;var h=i[g];if(t&&h.labelDepth!==t)continue;this.renderedNodeLabels.add(g),d.push(g)}}catch(de){u.e(de)}finally{u.f()}if(d.length===0)return;if(this.labelsDirty){var p,y,v,f=0;for(var b=0,m=d.length;b<m;b++){var T=i[d[b]];f+=T.label.length}o.reallocate(f);var _=14,x=(p=s===null||s===void 0||(y=s.nodes)===null||y===void 0||(y=y.label)===null||y===void 0?void 0:y.margin)!==null&&p!==void 0?p:Dt,S=Ve.labelPosition,E=(s===null||s===void 0||(v=s.nodes)===null||v===void 0||(v=v.label)===null||v===void 0||(v=v.font)===null||v===void 0?void 0:v.family)||"sans-serif",D=new Map,A=0;for(var L=0,w=d.length;L<w;L++){var M,C,z,O,N=d[L],F=i[N],P=F.labelFont||E,B=D.get(P);if(B===void 0){var Y=An(P),{family:q,weight:re,style:Z}=Y;B=o.registerFont(q,re,Z),D.set(P,B)}var ee={text:F.label,x:F.x,y:F.y,size:(M=F.labelSize)!==null&&M!==void 0?M:_,color:F.labelColor,nodeSize:F.size,margin:x,position:(C=F.labelPosition)!==null&&C!==void 0?C:S,hidden:!1,forceLabel:Ze(F),type:"default",zIndex:(z=F.zIndex)!==null&&z!==void 0?z:0,parentType:"node",parentKey:N,fontKey:B,labelAngle:(O=F.labelAngle)!==null&&O!==void 0?O:0,nodeIndex:l.getIndex(N)},Ee=o.processLabel(N,A,ee);A+=Ee}o.invalidateBuffers()}o.render(n)}},{key:"renderBackdrops",value:function(n,t){var r=this.internals,{backdropProgram:i,nodeDataCache:o,nodesWithBackdrop:s,attachmentManager:l,pixelRatio:d,nodeDataTexture:u}=r,c=[],g=W(s),h;try{for(g.s();!(h=g.n()).done;){var p,y=h.value,v=o[y];if(!v||v.visibility==="hidden")continue;if(t&&v.depth!==t)continue;var f=(p=u===null||u===void 0?void 0:u.getIndex(y))!==null&&p!==void 0?p:-1;if(f<0)continue;c.push({key:y,nodeIndex:f})}}catch(pe){g.e(pe)}finally{g.f()}if(c.length===0)return;i.reallocate(c.length);for(var b=0;b<c.length;b++){var m,T,_,x,S,E,D,A,L=c[b],{key:w,nodeIndex:M}=L,C=o[w],z=this.displayedNodeLabels.has(w),O=z?this.measureNodeLabel(C):{width:0,height:0,textHeight:0},{textHeight:N,width:F,height:P}=O,B=0,Y=0;if(z&&C.labelAttachment&&l){var q=l.getEntry(w,C.labelAttachment);if(q){var re=C.labelAttachmentPlacement||"below";if(re==="below"||re==="above"){var Z=q.height/d;P+=Z+et,F=Math.max(F,q.width/d),Y=re==="below"?(Z+et)/2:-(Z+et)/2}else{var ee=q.width/d;F+=ee+et,P=Math.max(P,q.height/d),B=re==="right"?(ee+et)/2:-(ee+et)/2}}}var Ee=C.backdropColor?Ye(C.backdropColor):[255,255,255,255],de=C.backdropShadowColor?Ye(C.backdropShadowColor):[0,0,0,128],U=Ee.map(function(pe){return pe/255}),ae=de.map(function(pe){return pe/255}),be=(m=C.backdropShadowBlur)!==null&&m!==void 0?m:12,I=(T=C.backdropPadding)!==null&&T!==void 0?T:6,k=C.backdropBorderColor?Ye(C.backdropBorderColor):[0,0,0,0],G=k.map(function(pe){return pe/255}),H=(_=C.backdropBorderWidth)!==null&&_!==void 0?_:0,K=(x=C.backdropCornerRadius)!==null&&x!==void 0?x:0,te=(S=C.backdropLabelPadding)!==null&&S!==void 0?S:-1,Q=te<0?I:te,ce=(E=Sc[(D=C.backdropArea)!==null&&D!==void 0?D:"both"])!==null&&E!==void 0?E:0,Ne={key:w,nodeIndex:M,label:C.label,labelWidth:F,labelHeight:P,textHeight:N,type:"default",position:C.labelPosition||Ve.labelPosition,labelAngle:(A=C.labelAngle)!==null&&A!==void 0?A:0,backdropColor:U,backdropShadowColor:ae,backdropShadowBlur:be,backdropPadding:I,backdropBorderColor:G,backdropBorderWidth:H,backdropCornerRadius:K,backdropLabelPadding:Q,backdropArea:ce,labelBoxOffset:[B,Y]};i.processBackdrop(b,Ne)}i.invalidateBuffers(),i.render(n)}},{key:"renderLabelBackgrounds",value:function(n,t){var r=this.internals,{labelBackgroundProgram:i,nodeDataCache:o,nodeDataTexture:s}=r,l=Se.nodeLabel.writesPickingThisFrame(this.internals),d=[],u=W(this.displayedNodeLabels),c;try{for(u.s();!(c=u.n()).done;){var g=c.value,h=o[g];if(!h||h.visibility==="hidden")continue;if(t&&h.labelDepth!==t)continue;if(!l&&!h.labelBackgroundColor)continue;d.push(g)}}catch(M){u.e(M)}finally{u.f()}if(d.length===0)return;i.reallocate(d.length);for(var p=0;p<d.length;p++){var y,v,f,b,m=d[p],T=o[m],_=(y=s===null||s===void 0?void 0:s.getIndex(m))!==null&&y!==void 0?y:-1;if(_<0)continue;var x=this.measureNodeLabel(T),{width:S,height:E,textHeight:D}=x,A=ut(this.internals.pickingState,"nodeLabel",m)||ut(this.internals.pickingState,"node",m),L=T.labelBackgroundColor?Pe(T.labelBackgroundColor):Pe("transparent"),w={nodeIndex:_,id:_t(A),color:L,labelWidth:S,labelHeight:E,textHeight:D,positionMode:(v=wt[T.labelPosition||Ve.labelPosition])!==null&&v!==void 0?v:0,labelAngle:(f=T.labelAngle)!==null&&f!==void 0?f:0,padding:(b=T.labelBackgroundPadding)!==null&&b!==void 0?b:Ma};i.processLabelBackground(p,w)}i.invalidateBuffers(),i.render(n)}},{key:"cacheAttachments",value:function(n){var t=this.internals,{attachmentManager:r,pixelRatio:i,nodeDataCache:o,nodesWithBackdrop:s,graph:l}=t;if(!r)return;var d=W(s),u;try{for(d.s();!(u=d.n()).done;){var c=u.value;if(!this.displayedNodeLabels.has(c))continue;var g=o[c];if(!g||g.visibility==="hidden")continue;if(n&&g.depth!==n)continue;if(!g.labelAttachment)continue;var h=l.getNodeAttributes(c),p=this.measureNodeLabel(g),{width:y,height:v}=p,f={node:c,attributes:h,pixelRatio:i,labelWidth:y,labelHeight:v};r.renderAttachment(c,g.labelAttachment,f)}}catch(b){d.e(b)}finally{d.f()}r.regenerateAtlas()}},{key:"renderAttachments",value:function(n,t){var r=this.internals,{attachmentManager:i,attachmentProgram:o,nodeDataCache:s,nodesWithBackdrop:l,pixelRatio:d,nodeDataTexture:u}=r;if(!i||!o)return;var c=0;o.reallocateAttachments(l.size);var g=W(l),h;try{for(g.s();!(h=g.n()).done;){var p,y,v,f,b=h.value;if(!this.displayedNodeLabels.has(b))continue;var m=s[b];if(!m||m.visibility==="hidden")continue;if(t&&m.labelDepth!==t)continue;if(!m.labelAttachment)continue;var T=i.getEntry(b,m.labelAttachment);if(!T)continue;var _=(p=u===null||u===void 0?void 0:u.getIndex(b))!==null&&p!==void 0?p:-1;if(_<0)continue;var x=this.measureNodeLabel(m),{width:S,height:E,textHeight:D}=x,A=(y=mi[m.labelAttachmentPlacement||"below"])!==null&&y!==void 0?y:0;o.processAttachment(c,{nodeIndex:_,atlasX:T.x,atlasY:T.y,atlasW:T.width,atlasH:T.height,attachWidth:T.width/d,attachHeight:T.height/d,positionMode:(v=wt[m.labelPosition||Ve.labelPosition])!==null&&v!==void 0?v:0,attachmentPlacement:A,labelWidth:S,labelHeight:E,textHeight:D,labelAngle:(f=m.labelAngle)!==null&&f!==void 0?f:0}),c++}}catch(L){g.e(L)}finally{g.f()}if(c===0)return;o.reallocateAttachments(c),i.bindTexture(Yt),o.invalidateBuffers(),o.render(n)}},{key:"computeDisplayedEdgeLabels",value:function(){var n=this.internals,{graph:t,stateManager:r,settings:i,edgesWithForcedLabels:o}=n,s=r.getHighlightedNodes(),l=i.edgeLabelAnchors==="allNodes"?new Set(this.edgeAnchorGrid.getLabelsToDisplay(this.internals.getCameraState().ratio,i.labelDensity)):this.displayedNodeLabels,d=r.hovered,u=Tc({graph:t,hoveredNode:(d===null||d===void 0?void 0:d.kind)==="node"?d.key:null,displayedNodeLabels:l,highlightedNodes:s});Ea(u,o),this.edgeLabelCandidates=u,this.displayedEdgeLabels=new Set}},{key:"filterEdgeLabelsForDepth",value:function(n){var t=this.internals,{graph:r,nodeDataCache:i,edgeDataCache:o}=t,s=[],l=new Set;for(var d=0,u=this.edgeLabelCandidates.length;d<u;d++){var c=this.edgeLabelCandidates[d];if(l.has(c))continue;l.add(c);var g=r.extremities(c),h=i[g[0]],p=i[g[1]],y=o[c];if(!y||!h||!p)continue;if(y.visibility==="hidden"||y.labelVisibility==="hidden"||h.visibility==="hidden"||p.visibility==="hidden")continue;if(n&&y.labelDepth!==n)continue;if(!y.label)continue;s.push(c)}return s}},{key:"renderEdgeLabels",value:function(n,t){var r=this.internals,{graph:i,nodeDataCache:o,edgeDataCache:s,primitives:l,edgeLabelProgram:d,nodeDataTexture:u,edgeDataTexture:c}=r;if(!d)return;var g=this.filterEdgeLabelsForDepth(t),h=W(g),p;try{for(h.s();!(p=h.n()).done;){var y=p.value;this.displayedEdgeLabels.add(y)}}catch(ee){h.e(ee)}finally{h.f()}if(g.length===0)return;if(this.labelsDirty){var v,f,b=0,m=W(g),T;try{for(m.s();!(T=m.n()).done;){var _=T.value;b+=s[_].label.length}}catch(ee){m.e(ee)}finally{m.f()}d.reallocate(b);var x=(v=l===null||l===void 0||(f=l.edges)===null||f===void 0||(f=f.label)===null||f===void 0?void 0:f.margin)!==null&&v!==void 0?v:5,S="over",E=0,D=W(g),A;try{for(D.s();!(A=D.n()).done;){var L,w,M=A.value,C=i.extremities(M),z=C[0],O=C[1],N=o[z],F=o[O],P=s[M],B=u.getIndex(z),Y=u.getIndex(O),q=c.getIndex(M),re={text:P.label,x:(N.x+F.x)/2,y:(N.y+F.y)/2,size:eo,color:P.labelColor,nodeSize:0,nodeIndex:-1,margin:x,position:(L=P.labelPosition)!==null&&L!==void 0?L:S,hidden:!1,forceLabel:Ze(P),type:"default",zIndex:(w=P.zIndex)!==null&&w!==void 0?w:0,parentType:"edge",parentKey:M,fontKey:"",labelAngle:0,sourceX:N.x,sourceY:N.y,targetX:F.x,targetY:F.y,sourceSize:N.size,targetSize:F.size,sourceShape:N.shape||"circle",targetShape:F.shape||"circle",edgeSize:P.size,offset:0,edgeAttributes:P,sourceNodeIndex:B,targetNodeIndex:Y,edgeIndex:q},Z=d.processEdgeLabel(M,E,re);E+=Z}}catch(ee){D.e(ee)}finally{D.f()}d.invalidateBuffers()}d.render(n)}},{key:"renderEdgeLabelBackgrounds",value:function(n,t){var r,i,o=this.internals,{edgeLabelBackgroundProgram:s,edgeLabelProgram:l,edgeDataCache:d,primitives:u,edgeDataTexture:c}=o;if(!c||!l||!s)return;var g=Se.edgeLabel.writesPickingThisFrame(this.internals),h=(r=u===null||u===void 0||(i=u.edges)===null||i===void 0||(i=i.label)===null||i===void 0?void 0:i.margin)!==null&&r!==void 0?r:5,p="over",y=this.filterEdgeLabelsForDepth(t),v=[],f=W(y),b;try{for(f.s();!(b=f.n()).done;){var m=b.value;if(!g&&!d[m].labelBackgroundColor)continue;v.push(m)}}catch(N){f.e(N)}finally{f.f()}if(v.length===0)return;s.reallocate(v.length);for(var T=0;T<v.length;T++){var _,x,S,E=v[T],D=d[E],A=D.label,L=l.measureLabelAtlasWidth(A),w=(_=D.labelPosition)!==null&&_!==void 0?_:p,M=typeof w==="string"?(x=Ec[w])!==null&&x!==void 0?x:0:0,C=ut(this.internals.pickingState,"edgeLabel",E)||ut(this.internals.pickingState,"edge",E),z=D.labelBackgroundColor?Pe(D.labelBackgroundColor):Pe("transparent"),O={edgeIndex:c.getIndex(E),baseFontSize:eo,totalTextWidth:L,positionMode:M,margin:h,padding:(S=D.labelBackgroundPadding)!==null&&S!==void 0?S:Rc,color:z,id:_t(C),edgeAttributes:D};s.processEdgeLabelBackground(T,E,O)}s.invalidateBuffers(),s.render(n)}}])}();var wc=function(){function e(a,n,t,r){ie(this,e),R(this,"nodeStates",new Map),R(this,"edgeStates",new Map),R(this,"hovered",null),R(this,"dirtyNodes",new Set),R(this,"dirtyEdges",new Set),R(this,"graphStateChanged",!1),R(this,"graphStateFlagsDirty",!1),this.scheduleRefresh=a,this.customNodeStateDefaults=n,this.customEdgeStateDefaults=t,this.customGraphStateDefaults=r,this.graphState=ma(r)}return oe(e,[{key:"getNodeState",value:function(n){n=""+n;var t=this.nodeStates.get(n);if(!t)t=Ur(this.customNodeStateDefaults),this.nodeStates.set(n,t);return t}},{key:"getEdgeState",value:function(n){n=""+n;var t=this.edgeStates.get(n);if(!t)t=Hr(this.customEdgeStateDefaults),this.edgeStates.set(n,t);return t}},{key:"getGraphState",value:function(){return this.flushGraphStateFlags(),this.graphState}},{key:"getHighlightedNodes",value:function(){var n=new Set,t=W(this.nodeStates),r;try{for(t.s();!(r=t.n()).done;){var i=le(r.value,2),o=i[0],s=i[1];if(s.isHighlighted)n.add(o)}}catch(l){t.e(l)}finally{t.f()}return n}},{key:"setNodeState",value:function(n,t){n=""+n;var r=this.getNodeState(n);if(!Et(r,t))return;var i=V(V({},r),t);this.nodeStates.set(n,i),this.dirtyNodes.add(n),this.updateHoveredNodeTracking(n,r,i),this.graphStateFlagsDirty=!0,this.scheduleRefresh()}},{key:"setEdgeState",value:function(n,t){n=""+n;var r=this.getEdgeState(n);if(!Et(r,t))return;var i=V(V({},r),t);this.edgeStates.set(n,i),this.dirtyEdges.add(n),this.updateHoveredEdgeTracking(n,r,i),this.graphStateFlagsDirty=!0,this.scheduleRefresh()}},{key:"setGraphState",value:function(n){if(!Et(this.graphState,n))return;var t=V(V({},this.graphState),n);t.isIdle=!t.isPanning&&!t.isZooming&&!t.isDragging,this.graphState=t,this.graphStateChanged=!0,this.scheduleRefresh()}},{key:"setNodesState",value:function(n,t){var r=!1,i=W(n),o;try{for(i.s();!(o=i.n()).done;){var s=o.value;s=""+s;var l=this.getNodeState(s);if(!Et(l,t))continue;var d=V(V({},l),t);this.nodeStates.set(s,d),this.dirtyNodes.add(s),this.updateHoveredNodeTracking(s,l,d),r=!0}}catch(u){i.e(u)}finally{i.f()}if(r)this.graphStateFlagsDirty=!0,this.scheduleRefresh()}},{key:"setEdgesState",value:function(n,t){var r=!1,i=W(n),o;try{for(i.s();!(o=i.n()).done;){var s=o.value;s=""+s;var l=this.getEdgeState(s);if(!Et(l,t))continue;var d=V(V({},l),t);this.edgeStates.set(s,d),this.dirtyEdges.add(s),this.updateHoveredEdgeTracking(s,l,d),r=!0}}catch(u){i.e(u)}finally{i.f()}if(r)this.graphStateFlagsDirty=!0,this.scheduleRefresh()}},{key:"markNodesDirty",value:function(n){var t=W(n),r;try{for(t.s();!(r=t.n()).done;){var i=r.value;this.dirtyNodes.add(i)}}catch(o){t.e(o)}finally{t.f()}this.scheduleRefresh()}},{key:"removeNode",value:function(n){this.nodeStates.delete(n),this.dirtyNodes.delete(n),this.clearHoveredFor("node",n),this.graphStateFlagsDirty=!0,this.scheduleRefresh()}},{key:"removeEdge",value:function(n){this.edgeStates.delete(n),this.dirtyEdges.delete(n),this.clearHoveredFor("edge",n),this.graphStateFlagsDirty=!0,this.scheduleRefresh()}},{key:"pruneNodes",value:function(n){var t=W(this.nodeStates.keys()),r;try{for(t.s();!(r=t.n()).done;){var i=r.value;if(!n(i))this.removeNode(i)}}catch(o){t.e(o)}finally{t.f()}}},{key:"pruneEdges",value:function(n){var t=W(this.edgeStates.keys()),r;try{for(t.s();!(r=t.n()).done;){var i=r.value;if(!n(i))this.removeEdge(i)}}catch(o){t.e(o)}finally{t.f()}}},{key:"clearNodes",value:function(){this.nodeStates.clear(),this.dirtyNodes.clear(),this.clearHoveredForKinds($n("node")),this.graphStateFlagsDirty=!0,this.scheduleRefresh()}},{key:"clearEdges",value:function(){this.edgeStates.clear(),this.dirtyEdges.clear(),this.clearHoveredForKinds($n("edge")),this.graphStateFlagsDirty=!0,this.scheduleRefresh()}},{key:"resetGraphState",value:function(){this.graphState=ma(this.customGraphStateDefaults),this.graphStateChanged=!1,this.graphStateFlagsDirty=!1}},{key:"clearDirtyTracking",value:function(){this.dirtyNodes.clear(),this.dirtyEdges.clear(),this.graphStateChanged=!1}},{key:"setHovered",value:function(n){this.hovered=n}},{key:"clearHoveredFor",value:function(n,t){if(this.hovered&&this.hovered.key===t&&$n(n).includes(this.hovered.kind))this.hovered=null}},{key:"clearHoveredForKinds",value:function(n){if(this.hovered&&n.includes(this.hovered.kind))this.hovered=null}},{key:"updateGraphStateFromNodes",value:function(){var n,t=!1,r=!1,i=!1,o=W(this.nodeStates),s;try{for(o.s();!(s=o.n()).done;){var l=le(s.value,2),d=l[1];if(d.isHovered)t=!0;if(d.isHighlighted)r=!0;if(d.isDragged)i=!0;if(t&&r&&i)break}}catch(c){o.e(c)}finally{o.f()}if(!t&&((n=this.hovered)===null||n===void 0?void 0:n.kind)==="edge")t=!0;var u=!this.graphState.isPanning&&!this.graphState.isZooming&&!i;if(this.graphState.hasHovered!==t||this.graphState.hasHighlighted!==r||this.graphState.isDragging!==i||this.graphState.isIdle!==u)this.graphStateChanged=!0;this.graphState=V(V({},this.graphState),{},{hasHovered:t,hasHighlighted:r,isDragging:i,isIdle:u})}},{key:"updateGraphStateFromEdges",value:function(){var n,t=((n=this.hovered)===null||n===void 0?void 0:n.kind)==="node";if(!t){var r=W(this.edgeStates),i;try{for(r.s();!(i=r.n()).done;){var o=le(i.value,2),s=o[1];if(s.isHovered){t=!0;break}}}catch(l){r.e(l)}finally{r.f()}}if(this.graphState.hasHovered!==t)this.graphStateChanged=!0;this.graphState=V(V({},this.graphState),{},{hasHovered:t})}},{key:"flushGraphStateFlags",value:function(){if(!this.graphStateFlagsDirty)return;this.updateGraphStateFromNodes(),this.updateGraphStateFromEdges(),this.graphStateFlagsDirty=!1}},{key:"updateHoveredNodeTracking",value:function(n,t,r){var i;if(t.isHovered===r.isHovered)return;if(r.isHovered){var o;if(((o=this.hovered)===null||o===void 0?void 0:o.kind)==="node"&&this.hovered.key!==n){var s=this.hovered.key,l=this.getNodeState(s);this.nodeStates.set(s,V(V({},l),{},{isHovered:!1})),this.dirtyNodes.add(s)}this.hovered={kind:"node",key:n}}else if(((i=this.hovered)===null||i===void 0?void 0:i.kind)==="node"&&this.hovered.key===n)this.hovered=null}},{key:"updateHoveredEdgeTracking",value:function(n,t,r){var i;if(t.isHovered===r.isHovered)return;if(r.isHovered){var o;if(((o=this.hovered)===null||o===void 0?void 0:o.kind)==="edge"&&this.hovered.key!==n){var s=this.hovered.key,l=this.getEdgeState(s);this.edgeStates.set(s,V(V({},l),{},{isHovered:!1})),this.dirtyEdges.add(s)}this.hovered={kind:"edge",key:n}}else if(((i=this.hovered)===null||i===void 0?void 0:i.kind)==="edge"&&this.hovered.key===n)this.hovered=null}}])}(),to=1,no=2,ao=3,ro=4,Dc=function(e){function a(n,t){var r,i,o,s,l,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};ie(this,a),l=fe(this,a),R(l,"nodeReducer",null),R(l,"edgeReducer",null),R(l,"stageCanvas",null),R(l,"mouseLayer",null),R(l,"gestureHint",null),R(l,"extraElements",{}),R(l,"webGLContext",null),R(l,"pickingFrameBuffer",null),R(l,"pickingTexture",null),R(l,"pickingDepthBuffer",null),R(l,"activeListeners",{}),R(l,"nodeVariableEntries",[]),R(l,"edgeVariableEntries",[]),R(l,"edgePathsByName",new Map),R(l,"nodeProgramIndex",{}),R(l,"edgeProgramIndex",{}),R(l,"edgeTextureIndexCache",{}),R(l,"nodeGraphCoords",{}),R(l,"nodeExtent",{x:[0,1],y:[0,1]}),R(l,"matrix",ke()),R(l,"invMatrix",ke()),R(l,"correctionRatio",1),R(l,"frameId",0),R(l,"customBBox",null),R(l,"gpuTimerExt",void 0),R(l,"activeGpuTimerQuery",null),R(l,"pendingGpuTimerQueries",[]),R(l,"normalizationFunction",Sn({x:[0,1],y:[0,1]})),R(l,"graphToViewportRatio",1),R(l,"pickingState",nc()),R(l,"prevNodeVisibilities",{}),R(l,"width",0),R(l,"height",0),R(l,"autoRescaleFrozen",!1),R(l,"stylesDeclaration",null),R(l,"resolvedStageStyle",{}),R(l,"renderFrame",null),R(l,"contextLost",!1),R(l,"pendingProcess","full"),R(l,"needToRefreshState",!1),R(l,"checkEdgesEventsFrame",null),R(l,"edgeStyleAnalysis",{dependency:"static",xAttribute:null,yAttribute:null}),R(l,"depthLayers",J(pn)),R(l,"customLayerPrograms",new Map),R(l,"nodeShapeSlug",null),R(l,"sdfAtlas",null),R(l,"depthRanges",{nodes:{},edges:{}}),R(l,"nodeBaseDepth",{}),R(l,"edgeBaseDepth",{});var{primitives:u,styles:c,settings:g}=d,h=g===void 0?{}:g,{nodeReducer:p,edgeReducer:y,customNodeState:v,customEdgeState:f,customGraphState:b}=d;l.stateManager=new wc(function(){return l.scheduleStateRefresh()},v,f,b);var m=u!==null&&u!==void 0?u:Xr;l.stylesDeclaration=c?{nodes:(r=c.nodes)!==null&&r!==void 0?r:yn.nodes,edges:(i=c.edges)!==null&&i!==void 0?i:yn.edges,stage:c.stage}:yn,l.nodeReducer=p!==null&&p!==void 0?p:null,l.edgeReducer=y!==null&&y!==void 0?y:null;var T=ba(l.stylesDeclaration.nodes);if(l.nodeReducer)T.dependency="graph-state";if(l.edgeStyleAnalysis=ba(l.stylesDeclaration.edges),l.edgeReducer)l.edgeStyleAnalysis.dependency="graph-state";if(l.stylesDeclaration.stage)l.resolvedStageStyle=Sa(l.stylesDeclaration.stage,l.stateManager.graphState);var _=Jr(h);if(Rn(_),_.enableNodeDrag){var{xAttribute:x,yAttribute:S}=T;if((!x||!S)&&!_.dragPositionToAttributes)throw Error(\'Sigma: `enableNodeDrag` is true but position attribute names could not be inferred from styles. Either use attribute bindings for x/y in your node styles (e.g. `x: { attribute: "x" }`), or provide a `dragPositionToAttributes` setting.\')}if(Qr(n),!(t instanceof HTMLElement))throw Error("Sigma: container should be an html element.");l.container=t,l.edgeGroups=new tc(n,function(F,P){for(var B=0;B<F.length;B++){var Y=l.stateManager.getEdgeState(F[B]);Y.parallelIndex=B,Y.parallelCount=P}});var E=new ec(n,l.viewportToGraph.bind(l),l.setNodesState.bind(l),function(F,P){return l.emit(F,P)});if(l.depthLayers=(o=m.depthLayers)!==null&&o!==void 0?o:J(pn),!(c!==null&&c!==void 0&&c.nodes)&&!gn.every(function(F){return l.depthLayers.includes(F)}))throw Error("Sigma: depthLayers must include ".concat(gn.join(", ")," for the built-in node styles."));if(!(c!==null&&c!==void 0&&c.edges)&&!vn.every(function(F){return l.depthLayers.includes(F)}))throw Error("Sigma: depthLayers must include ".concat(vn.join(", ")," for the built-in edge styles."));if(l.itemBuckets={nodes:new $a(l.depthLayers),edges:new $a(l.depthLayers)},l.initWebGLContext(),l.mouseLayer=Rt("div",{position:"absolute",touchAction:"none",userSelect:"none"},{class:"sigma-mouse"}),l.container.appendChild(l.mouseLayer),l.resolvedStageStyle.background)l.container.style.backgroundColor=l.resolvedStageStyle.background;if(l.resolvedStageStyle.cursor)l.container.style.cursor=l.resolvedStageStyle.cursor;var D=new Oi(l.webGLContext),A=new Va(l.webGLContext,{channels:1}),L=new Bi(l.webGLContext),w=new Va(l.webGLContext,{channels:4}),M=l.webGLContext,C=new _c({gl:M,getFrameBuffer:function(){return l.pickingFrameBuffer},getPixelRatio:function(){return l.internals.pixelRatio},getDownSizingRatio:function(){return l.internals.settings.pickingDownSizingRatio},isRenderPending:function(){return l.renderFrame!==null},onIndex:function(P,B){var Y;return lo(l.internals,(Y=l.pickingState.lookup[P])!==null&&Y!==void 0?Y:null,B)}}),z=l.initPrograms(m,_),O=m===null||m===void 0||(s=m.nodes)===null||s===void 0?void 0:s.labelAttachments,N=null;if(O&&Object.keys(O).length>0)N=new Gi(M,O,function(){return l.scheduleRender()});return l.internals=V(V({nodeDataCache:{},edgeDataCache:{},nodesWithForcedLabels:new Set,nodesWithBackdrop:new Set,edgesWithForcedLabels:new Set,settings:_,primitives:m,pixelRatio:Ut(),graph:n,stateManager:l.stateManager,dragManager:E,hoverResolver:C,nodeStyleAnalysis:T,pickingState:l.pickingState},z),{},{attachmentManager:N,nodeDataTexture:D,nodeFrameTexture:A,edgeDataTexture:L,edgeFrameTexture:w,getDimensions:function(){return l.getDimensions()},getGraphDimensions:function(){return l.getGraphDimensions()},getStagePadding:function(){return l.getStagePadding()},getCameraState:function(){return l.camera.getState()},getHitAtPosition:function(P){return l.getHitAtPosition(P)},setNodeState:function(P,B){return l.setNodeState(P,B)},setEdgeState:function(P,B){return l.setEdgeState(P,B)},updateContainerCursor:function(){return l.updateContainerCursor()},scheduleRefresh:function(){return l.scheduleRefresh()},viewportToFramedGraph:function(P){return l.viewportToFramedGraph(P)},viewportToGraph:function(P){return l.viewportToGraph(P)},framedGraphToViewport:function(P){return l.framedGraphToViewport(P)},scaleSize:function(P){return l.scaleSize(P)},emit:function(P,B){return l.emit(P,B)}}),l.labelRenderer=new Ac(l.internals),l.resize(),l.initializeWebGLLabels(),l.camera=new Hi,l.bindCameraHandlers(),l.mouseCaptor=new Ku(l.mouseLayer,l),l.mouseCaptor.setSettings(l.internals.settings),l.touchCaptor=new Ju(l.mouseLayer,l),l.touchCaptor.setSettings(l.internals.settings),l.bindEventHandlers(),l.bindGraphHandlers(),l.handleSettingsUpdate(),l.refresh(),l}return ge(a,e),oe(a,[{key:"initializeWebGLLabels",value:function(){this.sdfAtlas=new it,this.sdfAtlas.registerFont({family:"sans-serif",weight:"normal",style:"normal"})}},{key:"resetWebGLTexture",value:function(){var t=this.webGLContext;if(!this.pickingFrameBuffer)return this;var r=Math.ceil(this.width*this.internals.pixelRatio/this.internals.settings.pickingDownSizingRatio),i=Math.ceil(this.height*this.internals.pixelRatio/this.internals.settings.pickingDownSizingRatio);if(t.bindFramebuffer(t.FRAMEBUFFER,this.pickingFrameBuffer),this.pickingTexture)t.deleteTexture(this.pickingTexture);var o=t.createTexture();if(o)t.bindTexture(t.TEXTURE_2D,o),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,r,i,0,t.RGBA,t.UNSIGNED_BYTE,null),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,o,0),this.pickingTexture=o;if(this.pickingDepthBuffer)t.deleteRenderbuffer(this.pickingDepthBuffer);var s=t.createRenderbuffer();if(s)t.bindRenderbuffer(t.RENDERBUFFER,s),t.renderbufferStorage(t.RENDERBUFFER,t.DEPTH_COMPONENT16,r,i),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,s),this.pickingDepthBuffer=s;return t.bindFramebuffer(t.FRAMEBUFFER,null),this}},{key:"bindCameraHandlers",value:function(){var t=this;return this.activeListeners.camera=function(){t.refreshMatrices(),t.labelRenderer.labelsDirty=!0,t.scheduleRender()},this.activeListeners.cameraAnimationStart=function(r){var{from:i,to:o}=r;if(i.ratio!==o.ratio)t.stateManager.setGraphState({isZooming:!0})},this.activeListeners.cameraAnimationEnd=function(){t.stateManager.setGraphState({isZooming:!1})},this.camera.on("updated",this.activeListeners.camera),this.camera.on("animationStart",this.activeListeners.cameraAnimationStart),this.camera.on("animationEnd",this.activeListeners.cameraAnimationEnd),this}},{key:"unbindCameraHandlers",value:function(){return this.camera.removeListener("updated",this.activeListeners.camera),this.camera.removeListener("animationStart",this.activeListeners.cameraAnimationStart),this.camera.removeListener("animationEnd",this.activeListeners.cameraAnimationEnd),this}},{key:"getHitAtPosition",value:function(t){var r;if(this.contextLost)return null;var i=this.webGLContext;i.bindFramebuffer(i.FRAMEBUFFER,this.pickingFrameBuffer);var o=wr(i,this.pickingFrameBuffer,t.x,t.y,this.internals.pixelRatio,this.internals.settings.pickingDownSizingRatio),s=la.apply(void 0,J(o));return(r=this.pickingState.lookup[s])!==null&&r!==void 0?r:null}},{key:"bindEventHandlers",value:function(){return dc(this.internals,this.mouseCaptor,this.touchCaptor,this.activeListeners),this}},{key:"bindGraphHandlers",value:function(){var t=this;return uc({graph:this.internals.graph,edgeGroups:this.edgeGroups,updateNode:this.updateNode.bind(this),removeNode:this.removeNode.bind(this),addEdge:this.addEdge.bind(this),updateEdge:this.updateEdge.bind(this),removeEdge:this.removeEdge.bind(this),clearEdgeState:this.clearEdgeState.bind(this),clearNodeState:this.clearNodeState.bind(this),clearEdgeIndices:this.clearEdgeIndices.bind(this),clearNodeIndices:this.clearNodeIndices.bind(this),refresh:this.refresh.bind(this),scheduleProcess:function(){t.pendingProcess="full",t.scheduleRender()},markNodesDirty:function(i){if(t.internals.nodeStyleAnalysis.dependency!=="graph-state")return;t.stateManager.markNodesDirty(i)}},this.activeListeners),this}},{key:"unbindGraphHandlers",value:function(){cc(this.internals.graph,this.activeListeners)}},{key:"getNodeShapeId",value:function(t){if(this.internals.nodeShapeMap&&this.internals.nodeGlobalShapeIds&&t.shape&&t.shape in this.internals.nodeShapeMap)return this.internals.nodeGlobalShapeIds[this.internals.nodeShapeMap[t.shape]];return jt(t.shape||"circle")}},{key:"processNodes",value:function(){var t=this,r=this.internals.graph,i=this.internals.settings,o=this.getDimensions(),{autoRescale:s,autoRescaleContent:l}=i,d=this.nodeExtent;if(s===!1){var{width:u,height:c}=o;d={x:[-u/2,u/2],y:[-c/2,c/2]}}else if(s!=="once"||!this.autoRescaleFrozen){if(d=this.computeNodeExtent(),l!=="positions"&&!this.customBBox)d=vc({extent:d,coords:this.nodeGraphCoords,nodeData:this.internals.nodeDataCache,dimensions:o,stagePadding:this.getStagePadding(),zoomToSizeRatioFunction:i.zoomToSizeRatioFunction,itemSizesReference:i.itemSizesReference,fitLabels:l==="labels",nodeLabelBox:function(Y,q){return t.labelRenderer.nodeLabelBox(Y,q)}});if(s==="once")this.autoRescaleFrozen=!0}this.nodeExtent=d,this.normalizationFunction=Sn(this.customBBox||this.nodeExtent);var g=new Hi,h=qe(g.getState(),o,this.getGraphDimensions(),this.getStagePadding());this.labelRenderer.labelGrid.resizeAndClear(o,i.labelGridCellSize),this.labelRenderer.edgeAnchorGrid.resizeAndClear(o,i.labelGridCellSize);var p=i.renderEdgeLabels&&i.edgeLabelAnchors==="allNodes",y=!1;Wn(this.pickingState,"node");var v=r.nodes();for(var f=0,b=v.length;f<b;f++){var m=v[f],T=this.internals.nodeDataCache[m],_=this.nodeGraphCoords[m];if(T.x=_.x,T.y=_.y,this.normalizationFunction.applyTo(T),T.visibility!==this.prevNodeVisibilities[m])y=!0;if(typeof T.label==="string"&&T.visibility!=="hidden"&&T.labelVisibility!=="hidden")this.labelRenderer.labelGrid.add(m,T.size,this.framedGraphToViewport(T,{matrix:h}));if(p&&T.visibility!=="hidden")this.labelRenderer.edgeAnchorGrid.add(m,T.size,this.framedGraphToViewport(T,{matrix:h}))}this.labelRenderer.labelGrid.organize(),this.labelRenderer.edgeAnchorGrid.organize(),this.nodeProgram.reallocate(v.length);var x=0;this.depthRanges.nodes={},this.nodeBaseDepth={};var S=this.internals.nodeDataCache,E=W(this.depthLayers),D;try{for(E.s();!(D=E.n()).done;){var A=D.value,L=this.itemBuckets.nodes.getSorted(A,function(B){return S[B].zIndex});if(L.length===0)continue;this.depthRanges.nodes[A]=[{offset:x,count:L.length}];var w=W(L),M;try{for(w.s();!(M=w.n()).done;){var C=M.value;this.nodeBaseDepth[C]=A,qi(this.pickingState,"node",C),this.addNodeToProgram(C,x++)}}catch(B){w.e(B)}finally{w.f()}}}catch(B){E.e(B)}finally{E.f()}this.nodeProgram.invalidateBuffers();for(var z=0,O=v.length;z<O;z++)this.prevNodeVisibilities[v[z]]=this.internals.nodeDataCache[v[z]].visibility;this.labelRenderer.processWebGLLabels(v);var N=W(this.customLayerPrograms.values()),F;try{for(N.s();!(F=N.n()).done;){var P=F.value.program;if(P.cacheData)P.cacheData()}}catch(B){N.e(B)}finally{N.f()}return y}},{key:"processEdges",value:function(){var t=this.internals.graph,r=t.edges();this.edgeProgram.reallocate(r.length);var i=0;Wn(this.pickingState,"edge"),this.depthRanges.edges={},this.edgeBaseDepth={};var o=this.internals.edgeDataCache,s=W(this.depthLayers),l;try{for(s.s();!(l=s.n()).done;){var d=l.value,u=this.itemBuckets.edges.getSorted(d,function(p){return o[p].zIndex});if(u.length===0)continue;this.depthRanges.edges[d]=[{offset:i,count:u.length}];var c=W(u),g;try{for(c.s();!(g=c.n()).done;){var h=g.value;this.edgeBaseDepth[h]=d,qi(this.pickingState,"edge",h),this.addEdgeToProgram(h,i++)}}catch(p){c.e(p)}finally{c.f()}}}catch(p){s.e(p)}finally{s.f()}this.edgeProgram.invalidateBuffers()}},{key:"updateNodeDepthRanges",value:function(t,r,i){var o=this.nodeProgramIndex[t];if(o===void 0)return;wa(this.depthRanges.nodes,r,o),Da(this.depthRanges.nodes,i,o)}},{key:"updateEdgeDepthRanges",value:function(t,r,i){var o=this.edgeProgramIndex[t];if(o===void 0)return;wa(this.depthRanges.edges,r,o),Da(this.depthRanges.edges,i,o)}},{key:"handleSettingsUpdate",value:function(){var t=this,r=this.internals.settings;if(this.camera.minRatio=r.minCameraRatio,this.camera.maxRatio=r.maxCameraRatio,this.camera.enabledZooming=r.enableCameraZooming,this.camera.enabledPanning=r.enableCameraPanning,this.camera.enabledRotation=r.enableCameraRotation,r.cameraPanBoundaries)this.camera.constrainState=function(i){return t.cleanCameraState(i,r.cameraPanBoundaries&&se(r.cameraPanBoundaries)==="object"?r.cameraPanBoundaries:{})};else this.camera.constrainState=null;if(this.camera.setState(this.camera.getState()),this.mouseLayer.style.touchAction=r.gestureTarget==="graph"?"none":r.gestureTarget==="shared"?"pan-x pan-y":"auto",r.gestureTarget!=="shared"&&this.gestureHint)this.gestureHint.kill(),this.gestureHint=null;return this.mouseCaptor.setSettings(this.internals.settings),this.touchCaptor.setSettings(this.internals.settings),this}},{key:"cleanCameraState",value:function(t){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=r.tolerance,o=i===void 0?0:i,s=r.boundaries,l=V({},t),d=s||this.nodeExtent,u=le(d.x,2),c=u[0],g=u[1],h=le(d.y,2),p=h[0],y=h[1],v=[this.graphToViewport({x:c,y:p},{cameraState:t}),this.graphToViewport({x:g,y:p},{cameraState:t}),this.graphToViewport({x:c,y},{cameraState:t}),this.graphToViewport({x:g,y},{cameraState:t})],f=1/0,b=-1/0,m=1/0,T=-1/0;v.forEach(function(C){var{x:z,y:O}=C;f=Math.min(f,z),b=Math.max(b,z),m=Math.min(m,O),T=Math.max(T,O)});var _=b-f,x=T-m,S=this.getDimensions(),{width:E,height:D}=S,A=0,L=0;if(_>=E){if(b<E-o)A=b-(E-o);else if(f>o)A=f-o}else if(b>E+o)A=b-(E+o);else if(f<-o)A=f+o;if(x>=D){if(T<D-o)L=T-(D-o);else if(m>o)L=m-o}else if(T>D+o)L=T-(D+o);else if(m<-o)L=m+o;if(A||L){var w=this.viewportToFramedGraph({x:0,y:0},{cameraState:t}),M=this.viewportToFramedGraph({x:A,y:L},{cameraState:t});A=M.x-w.x,L=M.y-w.y,l.x+=A,l.y+=L}return l}},{key:"refreshMatrices",value:function(){var t=this.camera.getState(),r=this.getDimensions(),i=this.getGraphDimensions(),o=this.getStagePadding();this.matrix=qe(t,r,i,o),this.invMatrix=qe(t,r,i,o,!0),this.correctionRatio=Sr(this.matrix,t,r),this.graphToViewportRatio=this.getGraphToViewportRatio()}},{key:"processData",value:function(){var t;this.emit("beforeProcess"),(t=this.internals.attachmentManager)===null||t===void 0||t.clear();var r=V({},this.pickingState.idsByKind),i=this.processNodes();if(this.pendingProcess==="full"||i)this.processEdges();if(ac(this.pickingState,this.internals),!rc(r,this.pickingState.idsByKind))this.internals.hoverResolver.invalidate();this.pendingProcess="none",this.emit("afterProcess")}},{key:"render",value:function(){var t=this;if(this.contextLost)return this;this.emit("beforeRender");var r=function(){return t.internals.hoverResolver.frameRendered(),t.emit("afterRender"),t};if(this.renderFrame)cancelAnimationFrame(this.renderFrame),this.renderFrame=null;if(this.resize(),this.pendingProcess!=="none"||this.needToRefreshState)this.labelRenderer.labelsDirty=!0;if(this.pendingProcess!=="none")this.processData();if(this.needToRefreshState)this.refreshState();if(this.needToRefreshState=!1,this.stateManager.clearDirtyTracking(),this.pendingProcess!=="none")this.processData();if(this.clear(),this.resetWebGLTexture(),!this.internals.graph.order)return r();var i=this.mouseCaptor,o=this.camera.isAnimating()||i.isMoving||i.draggedEvents||i.currentWheelDirection;if(this.refreshMatrices(),this.frameId++,this.internals.settings.renderEdgeLabels&&!this.internals.edgeLabelProgram){var s=this.createEdgeLabelPrograms(),{labelProgram:l,labelBackgroundProgram:d}=s;this.internals.edgeLabelProgram=l,this.internals.edgeLabelBackgroundProgram=d}var u=this.internals.settings.DEBUG_logRenderStats?this.getDebugPrograms():null;if(u)u.forEach(function(ee){return ee.resetDebugStats()});if(this.internals.settings.DEBUG_gpuTimerQueries)this.beginGpuTimerQuery();this.internals.nodeFrameTexture.ensureCapacity(this.internals.nodeDataTexture.getCapacity()),this.internals.edgeFrameTexture.ensureCapacity(this.internals.edgeDataTexture.getCapacity());var c=this.getRenderParams(),g=Se.edge.writesPickingThisFrame(this.internals)?c:V(V({},c),{},{pickingFrameBuffer:null});this.labelRenderer.resetFrame();var h=this.webGLContext,p=Math.ceil(this.width*this.internals.pixelRatio/this.internals.settings.pickingDownSizingRatio),y=Math.ceil(this.height*this.internals.pixelRatio/this.internals.settings.pickingDownSizingRatio);if(h.bindFramebuffer(h.FRAMEBUFFER,this.pickingFrameBuffer),h.viewport(0,0,p,y),h.clear(h.COLOR_BUFFER_BIT|h.DEPTH_BUFFER_BIT),h.bindFramebuffer(h.FRAMEBUFFER,null),h.viewport(0,0,this.width*this.internals.pixelRatio,this.height*this.internals.pixelRatio),h.clear(h.COLOR_BUFFER_BIT|h.DEPTH_BUFFER_BIT),this.internals.nodeDataTexture.upload(),this.internals.edgeDataTexture.upload(),this.nodeProgram.uploadLayerTexture(),this.edgeProgram.uploadAttributeTexture(),this.emit("afterTexturesUpload"),this.internals.nodeDataTexture.bind(ao),this.internals.edgeDataTexture.bind(ro),this.edgeFramePass.run(c,this.internals.edgeFrameTexture,this.internals.edgeDataTexture.getHighWaterMark(),this.edgeProgram.getAttributeTexture(),this.nodeProgram.getAttributeTexture()),this.internals.edgeFrameTexture.bind(to),this.internals.settings.renderLabels){this.labelRenderer.computeDisplayedNodeLabels();var v=this.labelRenderer.buildFramePassPoints(),{data:f,count:b}=v;this.nodeFramePass.run(f,b,this.internals.nodeFrameTexture,c,this.nodeProgram.getAttributeTexture()),this.internals.nodeFrameTexture.bind(no)}if(this.internals.settings.renderEdgeLabels)this.labelRenderer.computeDisplayedEdgeLabels();var m=W(this.customLayerPrograms.values()),T;try{for(m.s();!(T=m.n()).done;){var _=T.value.program;if(_.preRender)_.preRender(c)}}catch(ee){m.e(ee)}finally{m.f()}h.bindFramebuffer(h.FRAMEBUFFER,null),h.viewport(0,0,this.width*this.internals.pixelRatio,this.height*this.internals.pixelRatio),h.blendFunc(h.ONE,h.ONE_MINUS_SRC_ALPHA);var x=!this.internals.settings.hideLabelsOnMove||!o,S=W(this.depthLayers),E;try{for(S.s();!(E=S.n()).done;){var D=E.value,A=W(this.customLayerPrograms.values()),L;try{for(A.s();!(L=A.n()).done;){var w=L.value;if(w.depth===D)w.program.render(c)}}catch(ee){A.e(ee)}finally{A.f()}var M=this.depthRanges.edges[D];if(M&&(!this.internals.settings.hideEdgesOnMove||!o)){var C=W(M),z;try{for(C.s();!(z=C.n()).done;){var O=z.value,{offset:N,count:F}=O;if(F>0)this.edgeProgram.render(g,N,F)}}catch(ee){C.e(ee)}finally{C.f()}}if(this.internals.settings.renderEdgeLabels&&x)this.labelRenderer.renderEdgeLabelBackgrounds(Se.edgeLabel.writesPickingThisFrame(this.internals)?c:V(V({},c),{},{pickingFrameBuffer:null}),D),this.labelRenderer.renderEdgeLabels(c,D);this.labelRenderer.cacheAttachments(D),this.labelRenderer.renderBackdrops(V(V({},c),{},{pickingFrameBuffer:null}),D);var P=this.depthRanges.nodes[D];if(P){var B=W(P),Y;try{for(B.s();!(Y=B.n()).done;){var q=Y.value,{offset:re,count:Z}=q;if(Z>0)this.nodeProgram.render(c,re,Z)}}catch(ee){B.e(ee)}finally{B.f()}}if(!x)continue;if(this.labelRenderer.renderAttachments(V(V({},c),{},{pickingFrameBuffer:null}),D),this.labelRenderer.renderLabelBackgrounds(Se.nodeLabel.writesPickingThisFrame(this.internals)?c:V(V({},c),{},{pickingFrameBuffer:null}),D),this.internals.settings.renderLabels)this.labelRenderer.renderWebGLLabels(c,D)}}catch(ee){S.e(ee)}finally{S.f()}if(this.labelRenderer.labelsDirty=!1,this.internals.settings.DEBUG_displayPickingLayer)h.bindFramebuffer(h.READ_FRAMEBUFFER,this.pickingFrameBuffer),h.bindFramebuffer(h.DRAW_FRAMEBUFFER,null),h.blitFramebuffer(0,0,p,y,0,0,this.width*this.internals.pixelRatio,this.height*this.internals.pixelRatio,h.COLOR_BUFFER_BIT,h.NEAREST);if(this.internals.settings.DEBUG_gpuTimerQueries)this.endGpuTimerQuery();if(this.pollGpuTimerQueries(),u)this.logRenderStats(u);return r()}},{key:"getDebugPrograms",value:function(){return[this.nodeProgram,this.edgeProgram,this.internals.labelProgram,this.internals.edgeLabelProgram,this.internals.edgeLabelBackgroundProgram,this.internals.backdropProgram,this.internals.labelBackgroundProgram,this.internals.attachmentProgram].filter(function(t){return t!==null})}},{key:"logRenderStats",value:function(t){var r={},i=W(t),o;try{for(i.s();!(o=i.n()).done;){var s=o.value;r[s.constructor.name]=V({},s.debugStats)}}catch(l){i.e(l)}finally{i.f()}console.log("[sigma] DEBUG_logRenderStats: frame #".concat(this.frameId)),console.table(r)}},{key:"getGpuTimerExtension",value:function(){if(this.gpuTimerExt===void 0){if(this.gpuTimerExt=this.webGLContext.getExtension("EXT_disjoint_timer_query_webgl2"),!this.gpuTimerExt)console.warn("Sigma: DEBUG_gpuTimerQueries is enabled, but this browser/driver doesn\'t support EXT_disjoint_timer_query_webgl2.")}return this.gpuTimerExt}},{key:"beginGpuTimerQuery",value:function(){var t=this.getGpuTimerExtension();if(!t)return;var r=this.webGLContext,i=r.createQuery();if(!i)return;r.beginQuery(t.TIME_ELAPSED_EXT,i),this.activeGpuTimerQuery=i}},{key:"endGpuTimerQuery",value:function(){if(!this.gpuTimerExt||!this.activeGpuTimerQuery)return;this.webGLContext.endQuery(this.gpuTimerExt.TIME_ELAPSED_EXT),this.pendingGpuTimerQueries.push({query:this.activeGpuTimerQuery,frameId:this.frameId}),this.activeGpuTimerQuery=null}},{key:"pollGpuTimerQueries",value:function(){if(this.pendingGpuTimerQueries.length===0)return;var t=this.webGLContext,r=this.gpuTimerExt;if(!r){this.pendingGpuTimerQueries.forEach(function(c){var g=c.query;return t.deleteQuery(g)}),this.pendingGpuTimerQueries=[];return}var i=t.getParameter(r.GPU_DISJOINT_EXT),o=[],s=W(this.pendingGpuTimerQueries),l;try{for(s.s();!(l=s.n()).done;){var d=l.value;if(!t.getQueryParameter(d.query,t.QUERY_RESULT_AVAILABLE)){o.push(d);continue}if(!i){var u=t.getQueryParameter(d.query,t.QUERY_RESULT);console.log("[sigma] DEBUG_gpuTimerQueries: frame #".concat(d.frameId," GPU time = ").concat((u/1e6).toFixed(2),"ms"))}t.deleteQuery(d.query)}}catch(c){s.e(c)}finally{s.f()}this.pendingGpuTimerQueries=o}},{key:"postEvaluateNode",value:function(t,r,i){var o=t;if(o.x===void 0)o.x=r.x;if(o.y===void 0)o.y=r.y;t.highlighted=i.isHighlighted;for(var s=0,l=this.nodeVariableEntries.length;s<l;s++){var d,u,c=le(this.nodeVariableEntries[s],2),g=c[0],h=c[1];o[g]=(d=(u=o[g])!==null&&u!==void 0?u:r[g])!==null&&d!==void 0?d:h.default}}},{key:"addNode",value:function(t){var r=this.internals.graph.getNodeAttributes(t),i=this.stateManager.getNodeState(t),o=this.internals.nodeDataCache[t]||{};if(_a(this.stylesDeclaration.nodes,r,i,this.stateManager.graphState,this.internals.graph,o),this.postEvaluateNode(o,r,i),this.nodeReducer){var s=this.nodeReducer(t,o,r,i,this.stateManager.graphState,this.internals.graph);o=V(V({},o),s)}if(typeof o.x!=="number"||typeof o.y!=="number")throw Error(\'Sigma: could not find a valid position (x, y) for node "\'.concat(t,\'". \')+"Provide coordinates via node attributes, styles, or a nodeReducer.");if(this.internals.nodeShapeMap){if(!o.shape||!(o.shape in this.internals.nodeShapeMap))o.shape=Object.keys(this.internals.nodeShapeMap)[0]}else if(this.nodeShapeSlug)o.shape=this.nodeShapeSlug;this.internals.nodeDataCache[t]=o,this.nodeGraphCoords[t]={x:o.x,y:o.y},rt(this.internals.nodesWithForcedLabels,t,Ze(o)),rt(this.internals.nodesWithBackdrop,t,Aa(o)),this.itemBuckets.nodes.set(t,o.depth)}},{key:"updateNode",value:function(t){this.addNode(t);var r=this.internals.nodeDataCache[t];this.normalizationFunction.applyTo(r)}},{key:"removeNode",value:function(t){Yi(this.pickingState,"node",t),this.itemBuckets.nodes.remove(t),delete this.internals.nodeDataCache[t],delete this.nodeGraphCoords[t],delete this.nodeProgramIndex[t],this.internals.nodeDataTexture.free(t),this.internals.dragManager.removeNode(t),this.stateManager.removeNode(t),this.internals.nodesWithForcedLabels.delete(t),this.internals.nodesWithBackdrop.delete(t)}},{key:"postEvaluateEdge",value:function(t,r){var i=t;for(var o=0,s=this.edgeVariableEntries.length;o<s;o++){var l,d,u=le(this.edgeVariableEntries[o],2),c=u[0],g=u[1];i[c]=(l=(d=i[c])!==null&&d!==void 0?d:r[c])!==null&&l!==void 0?l:g.default}}},{key:"applyEdgeSpread",value:function(t,r,i){var o;if(i.parallelCount<=1)return;var s=this.internals.graph.source(t),l=this.internals.graph.target(t),d=s===l,u=d?r.selfLoopPath||r.path:r.parallelPath||r.path,c=u?this.edgePathsByName.get(u):void 0;if(!(c!==null&&c!==void 0&&c.spread))return;var g=(o=r.parallelSpread)!==null&&o!==void 0?o:0.25,h=c.spread.compute(i.parallelIndex,i.parallelCount,g);if(!d&&this.internals.graph.isDirected(t)&&s>l)h=-h;r[c.spread.variable]=h}},{key:"addEdge",value:function(t){var r=this.internals.graph.getEdgeAttributes(t),i=this.stateManager.getEdgeState(t),o={};if(Ta(this.stylesDeclaration.edges,r,i,this.stateManager.graphState,this.internals.graph,o),this.postEvaluateEdge(o,r),this.edgeReducer){var s=this.edgeReducer(t,o,r,i,this.stateManager.graphState,this.internals.graph);o=V(V({},o),s)}this.applyEdgeSpread(t,o,i),this.internals.edgeDataCache[t]=o,rt(this.internals.edgesWithForcedLabels,t,Ze(o)),this.itemBuckets.edges.set(t,o.depth)}},{key:"updateEdge",value:function(t){this.addEdge(t)}},{key:"removeEdge",value:function(t){this.itemBuckets.edges.remove(t),delete this.internals.edgeDataCache[t],delete this.edgeProgramIndex[t],delete this.edgeTextureIndexCache[t],this.internals.edgeDataTexture.free(t),Yi(this.pickingState,"edge",t),this.stateManager.removeEdge(t),this.internals.edgesWithForcedLabels.delete(t)}},{key:"clearNodeIndices",value:function(){var t;if(this.labelRenderer.resetLabelGrid(),!this.autoRescaleFrozen)this.nodeExtent={x:[0,1],y:[0,1]};this.internals.nodeDataCache={},this.nodeGraphCoords={},this.nodeProgramIndex={},(t=this.internals.nodeDataTexture)===null||t===void 0||t.clear(),this.internals.nodesWithForcedLabels.clear(),this.internals.nodesWithBackdrop.clear(),this.prevNodeVisibilities={},this.itemBuckets.nodes.clearAll(),this.depthRanges.nodes={},this.nodeBaseDepth={}}},{key:"clearEdgeIndices",value:function(){var t;this.internals.edgeDataCache={},this.edgeProgramIndex={},this.edgeTextureIndexCache={},(t=this.internals.edgeDataTexture)===null||t===void 0||t.clear(),this.internals.edgesWithForcedLabels.clear(),this.itemBuckets.edges.clearAll(),this.depthRanges.edges={},this.edgeBaseDepth={},this.edgeGroups.clear()}},{key:"clearIndices",value:function(){this.clearEdgeIndices(),this.clearNodeIndices()}},{key:"clearNodeState",value:function(){this.labelRenderer.resetFrame(),this.internals.nodesWithBackdrop.clear(),this.internals.dragManager.clear(),this.autoRescaleFrozen=!1,this.stateManager.clearNodes(),Wn(this.pickingState,"node")}},{key:"clearEdgeState",value:function(){this.labelRenderer.clearEdgeLabels(),this.stateManager.clearEdges(),Wn(this.pickingState,"edge")}},{key:"clearState",value:function(){this.clearEdgeState(),this.clearNodeState(),this.stateManager.resetGraphState()}},{key:"addNodeToProgram",value:function(t,r){var i,o=this.internals.nodeDataCache[t];this.internals.nodeDataTexture.allocate(t),(i=this.internals.nodeDataTexture).updateNode.apply(i,[t,o.x,o.y,o.size,this.getNodeShapeId(o)].concat(J(Tn(o)),[o.color]));var s=this.internals.nodeDataTexture.getIndex(t);this.nodeProgram.process(ut(this.pickingState,"node",t),r,o,s),this.nodeProgramIndex[t]=r}},{key:"addEdgeToProgram",value:function(t,r){var i,o,s=this.internals.edgeDataCache[t],l=this.internals.graph.source(t),d=this.internals.graph.target(t),u=this.internals.edgeDataTexture.allocate(t);this.edgeTextureIndexCache[t]=u;var c=l===d,g=!c&&((i=(o=this.stateManager.getEdgeState(t))===null||o===void 0?void 0:o.parallelCount)!==null&&i!==void 0?i:1)>1,h=this.edgeProgram.resolveEdgeIds(s,c,g),{pathId:p,headId:y,tailId:v,headLengthRatio:f,tailLengthRatio:b}=h;this.internals.edgeDataTexture.updateEdge(t,this.internals.nodeDataTexture.getIndex(l),this.internals.nodeDataTexture.getIndex(d),s.size,f,b,p,y,v),this.edgeProgram.process(ut(this.pickingState,"edge",t),r,this.internals.nodeDataCache[l],this.internals.nodeDataCache[d],s,u),this.edgeProgramIndex[t]=r}},{key:"getRenderParams",value:function(){return{frameId:this.frameId,matrix:this.matrix,invMatrix:this.invMatrix,width:this.width,height:this.height,pixelRatio:this.internals.pixelRatio,zoomRatio:this.camera.ratio,cameraAngle:this.camera.angle,sizeRatio:1/this.scaleSize(),correctionRatio:this.correctionRatio,downSizingRatio:this.internals.settings.pickingDownSizingRatio,minEdgeThickness:this.internals.settings.minEdgeThickness,antiAliasingFeather:this.internals.settings.antiAliasingFeather,nodePickingPadding:this.internals.settings.nodePickingPadding,edgePickingPadding:this.internals.settings.edgePickingPadding,labelPickingPadding:this.internals.settings.labelPickingPadding,nodeDataTextureUnit:ao,nodeDataTextureWidth:this.internals.nodeDataTexture.getTextureWidth(),nodeFrameTextureUnit:no,nodeFrameTextureWidth:this.internals.nodeFrameTexture.getTextureWidth(),edgeDataTextureUnit:ro,edgeDataTextureWidth:this.internals.edgeDataTexture.getTextureWidth(),edgeFrameTextureUnit:to,edgeFrameTextureWidth:this.internals.edgeFrameTexture.getTextureWidth(),pickingFrameBuffer:this.pickingFrameBuffer,labelPixelSnapping:this.internals.settings.labelPixelSnapping?1:0}}},{key:"getStagePadding",value:function(){var t=this.internals.settings,{stagePadding:r,autoRescale:i}=t;return i?r||0:0}},{key:"getLayerElement",value:function(t){if(t==="mouse")return this.mouseLayer;var r=this.extraElements[t];if(!r)throw Error(\'Sigma: layer "\'.concat(t,\'" does not exist\'));return r}},{key:"initWebGLContext",value:function(){var t=this,r=this.createWebGLContext("stage");this.stageCanvas=this.extraElements.stage,this.webGLContext=r,this.stageCanvas.addEventListener("webglcontextlost",function(i){if(!t.webGLContext)return;if(i.preventDefault(),t.contextLost=!0,t.renderFrame)cancelAnimationFrame(t.renderFrame),t.renderFrame=null;t.gpuTimerExt=void 0,t.activeGpuTimerQuery=null,t.pendingGpuTimerQueries=[],t.emit("webglContextLost")}),this.stageCanvas.addEventListener("webglcontextrestored",function(){requestAnimationFrame(function(){if(t.webGLContext&&!t.webGLContext.isContextLost())t.restoreWebGLContext()})}),this.initPickingFramebuffer()}},{key:"initPickingFramebuffer",value:function(){var t=this.webGLContext,r=t.createFramebuffer();if(!r)throw Error("Sigma: cannot create picking frame buffer");t.bindFramebuffer(t.FRAMEBUFFER,r);var i=t.createTexture();if(!i)throw Error("Sigma: cannot create picking texture");t.bindTexture(t.TEXTURE_2D,i),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,null),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,i,0);var o=t.createRenderbuffer();if(!o)throw Error("Sigma: cannot create picking depth buffer");if(t.bindRenderbuffer(t.RENDERBUFFER,o),t.renderbufferStorage(t.RENDERBUFFER,t.DEPTH_COMPONENT16,1,1),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,o),t.checkFramebufferStatus(t.FRAMEBUFFER)!==t.FRAMEBUFFER_COMPLETE)throw Error("Sigma: picking framebuffer is not complete");t.bindFramebuffer(t.FRAMEBUFFER,null),this.pickingFrameBuffer=r,this.pickingTexture=i,this.pickingDepthBuffer=o}},{key:"initPrograms",value:function(t,r){var i=this,o=this.webGLContext,s=Pi(o,this.pickingFrameBuffer,i,t===null||t===void 0?void 0:t.nodes,r.antialiasNodes),{nodeProgram:l,labelProgram:d,backdropProgram:u,labelBackgroundProgram:c,attachmentProgram:g,framePass:h,shapeSlug:p,shapeNameToIndex:y,shapeGlobalIds:v,variables:f}=s;if(this.nodeProgram=l,this.nodeFramePass=h,this.nodeVariableEntries=Object.entries(f),p)this.nodeShapeSlug=p;var b=Fi(o,this.pickingFrameBuffer,i,t===null||t===void 0?void 0:t.edges,r.antialiasEdges,t===null||t===void 0?void 0:t.nodes),{edgeProgram:m,createLabelPrograms:T,framePass:_,variables:x,paths:S}=b;return this.createEdgeLabelPrograms=T,this.edgeProgram=m,this.edgeFramePass=_,this.edgeVariableEntries=Object.entries(x),this.edgePathsByName=new Map(S.map(function(E){return[E.name,E]})),{labelProgram:d,edgeLabelProgram:null,edgeLabelBackgroundProgram:null,backdropProgram:u,labelBackgroundProgram:c,attachmentProgram:g,nodeShapeMap:y!==null&&y!==void 0?y:null,nodeGlobalShapeIds:v!==null&&v!==void 0?v:null}}},{key:"restoreWebGLContext",value:function(){var t,r,i,o,s,l=this.internals;this.initPickingFramebuffer(),(t=l.nodeDataTexture)===null||t===void 0||t.restore(),(r=l.nodeFrameTexture)===null||r===void 0||r.restore(),(i=l.edgeDataTexture)===null||i===void 0||i.restore(),(o=l.edgeFrameTexture)===null||o===void 0||o.restore(),(s=l.attachmentManager)===null||s===void 0||s.restore(),l.hoverResolver.reset(),Object.assign(l,this.initPrograms(l.primitives,l.settings));var d=W(this.customLayerPrograms.values()),u;try{for(d.s();!(u=d.n()).done;){var c=u.value;c.program.kill(),c.program=c.factory(this.webGLContext)}}catch(g){d.e(g)}finally{d.f()}this.contextLost=!1,this.emit("webglContextRestored"),this.refresh()}},{key:"createLayer",value:function(t,r){var i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(this.extraElements[t])throw Error(\'Sigma: a layer named "\'.concat(t,\'" already exists\'));var o=Rt(r,{position:"absolute"},{class:"sigma-".concat(t)});if(i.style)Object.assign(o.style,i.style);if(this.extraElements[t]=o,"beforeLayer"in i&&i.beforeLayer)this.getLayerElement(i.beforeLayer).before(o);else if("afterLayer"in i&&i.afterLayer)this.getLayerElement(i.afterLayer).after(o);else this.container.appendChild(o);return o}},{key:"createCanvas",value:function(t){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.createLayer(t,"canvas",r)}},{key:"createWebGLContext",value:function(t){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=this.createCanvas(t,r);if(r.hidden)i.remove();var o=i.getContext("webgl2",V({preserveDrawingBuffer:!1,antialias:!1,depth:!0},r));if(!o)throw Error("Sigma: WebGL 2 is not supported by your browser. Please use a modern browser (Chrome 56+, Firefox 51+, Safari 15+, Edge 79+).");return o.blendFunc(o.ONE,o.ONE_MINUS_SRC_ALPHA),o}},{key:"killLayer",value:function(t){if(t==="stage"||t==="mouse")throw Error(\'Sigma: cannot kill built-in layer "\'.concat(t,\'"\'));var r=this.extraElements[t];if(!r)throw Error("Sigma: cannot kill layer ".concat(t,", which does not exist"));return r.remove(),delete this.extraElements[t],this}},{key:"getWebGLContext",value:function(){if(!this.webGLContext)throw Error("Sigma: WebGL context is not available");return this.webGLContext}},{key:"getNodeDataTexture",value:function(){if(!this.internals.nodeDataTexture)throw Error("Sigma: node data texture is not available");return this.internals.nodeDataTexture}},{key:"getNormalizationFunction",value:function(){return this.normalizationFunction}},{key:"addCustomLayerProgram",value:function(t,r,i){var o;if(!this.depthLayers.includes(r))throw Error(\'Sigma: cannot add custom layer program at depth "\'.concat(r,\'", \')+"it must be declared in primitives.depthLayers. Current layers: ".concat(this.depthLayers.join(", ")));(o=this.customLayerPrograms.get(t))===null||o===void 0||o.program.kill();var s=i(this.webGLContext);if(this.customLayerPrograms.set(t,{depth:r,factory:i,program:s}),s.cacheData)s.cacheData();return this.scheduleRender(),this}},{key:"removeCustomLayerProgram",value:function(t){var r=this.customLayerPrograms.get(t);if(r)r.program.kill(),this.customLayerPrograms.delete(t),this.scheduleRender();return this}},{key:"getCamera",value:function(){return this.camera}},{key:"setCamera",value:function(t){return this.camera.cancelAnimation(),this.unbindCameraHandlers(),this.camera=t,this.bindCameraHandlers(),this.scheduleRender(),this}},{key:"getContainer",value:function(){return this.container}},{key:"getGraph",value:function(){return this.internals.graph}},{key:"setGraph",value:function(t){if(t===this.internals.graph)return this;if(this.stateManager.pruneNodes(function(r){return t.hasNode(r)}),this.stateManager.pruneEdges(function(r){return t.hasEdge(r)}),this.unbindGraphHandlers(),this.checkEdgesEventsFrame!==null)cancelAnimationFrame(this.checkEdgesEventsFrame),this.checkEdgesEventsFrame=null;return this.internals.graph=t,this.autoRescaleFrozen=!1,this.bindGraphHandlers(),this.refresh(),this}},{key:"getMouseCaptor",value:function(){return this.mouseCaptor}},{key:"getTouchCaptor",value:function(){return this.touchCaptor}},{key:"getDimensions",value:function(){return{width:this.width,height:this.height}}},{key:"getGraphDimensions",value:function(){var t=this.customBBox||this.nodeExtent;return{width:t.x[1]-t.x[0]||1,height:t.y[1]-t.y[0]||1}}},{key:"getNodeDisplayData",value:function(t){var r=this.internals.nodeDataCache[t];return r?Object.assign({},r):void 0}},{key:"getEdgeDisplayData",value:function(t){var r=this.internals.edgeDataCache[t];return r?Object.assign({},r):void 0}},{key:"getNodeState",value:function(t){return this.stateManager.getNodeState(t)}},{key:"getEdgeState",value:function(t){return this.stateManager.getEdgeState(t)}},{key:"getGraphState",value:function(){return this.stateManager.getGraphState()}},{key:"setNodeState",value:function(t,r){return this.stateManager.setNodeState(t,r),this}},{key:"setEdgeState",value:function(t,r){return this.stateManager.setEdgeState(t,r),this}},{key:"setGraphState",value:function(t){return this.stateManager.setGraphState(t),this}},{key:"_setPanning",value:function(t){this.stateManager.setGraphState({isPanning:t})}},{key:"_setZooming",value:function(t){this.stateManager.setGraphState({isZooming:t})}},{key:"_hasNodeDrag",value:function(){var t=this.internals.dragManager;return!!(t.pendingNode||t.session)}},{key:"_showGestureHint",value:function(t){var r=this.internals.settings;if(r.gestureTarget!=="shared")return;this.gestureHint=this.gestureHint||new xc(this.container),this.gestureHint.show(t,r)}},{key:"setNodesState",value:function(t,r){return this.stateManager.setNodesState(t,r),this}},{key:"setEdgesState",value:function(t,r){return this.stateManager.setEdgesState(t,r),this}},{key:"updateContainerCursor",value:function(){var t=this.stateManager.hovered,r=this.resolvedStageStyle.cursor||"";this.container.style.cursor=t?ic(this.internals,t)||r:r}},{key:"refreshStageStyle",value:function(){if(this.resolvedStageStyle=Sa(this.stylesDeclaration.stage,this.stateManager.graphState),this.resolvedStageStyle.background!==void 0)this.container.style.backgroundColor=this.resolvedStageStyle.background;this.updateContainerCursor()}},{key:"getNodeDisplayedLabels",value:function(){return new Set(this.labelRenderer.displayedNodeLabels)}},{key:"getEdgeDisplayedLabels",value:function(){return new Set(this.labelRenderer.displayedEdgeLabels)}},{key:"getSettings",value:function(){return V({},this.internals.settings)}},{key:"getSetting",value:function(t){return this.internals.settings[t]}},{key:"getStyles",value:function(){return V({},this.stylesDeclaration)}},{key:"getPrimitives",value:function(){return V({},this.internals.primitives)}},{key:"setSetting",value:function(t,r){return this.internals.settings[t]=r,Rn(this.internals.settings),this.handleSettingsUpdate(),this.scheduleRefresh(),this}},{key:"updateSetting",value:function(t,r){return this.setSetting(t,r(this.internals.settings[t])),this}},{key:"setSettings",value:function(t){return this.internals.settings=V(V({},this.internals.settings),t),Rn(this.internals.settings),this.handleSettingsUpdate(),this.scheduleRefresh(),this}},{key:"resize",value:function(t){var r=this.width,i=this.height;if(this.width=this.container.offsetWidth,this.height=this.container.offsetHeight,this.internals.pixelRatio=Ut(),this.width===0)if(this.internals.settings.allowInvalidContainer)this.width=1;else throw Error("Sigma: Container has no width. You can set the allowInvalidContainer setting to true to stop seeing this error.");if(this.height===0)if(this.internals.settings.allowInvalidContainer)this.height=1;else throw Error("Sigma: Container has no height. You can set the allowInvalidContainer setting to true to stop seeing this error.");if(!t&&r===this.width&&i===this.height)return this;this.labelRenderer.labelsDirty=!0;for(var o=0,s=[this.mouseLayer].concat(J(Object.values(this.extraElements)));o<s.length;o++){var l=s[o];l.style.width=this.width+"px",l.style.height=this.height+"px"}if(this.webGLContext)this.stageCanvas.setAttribute("width",this.width*this.internals.pixelRatio+"px"),this.stageCanvas.setAttribute("height",this.height*this.internals.pixelRatio+"px"),this.webGLContext.viewport(0,0,this.width*this.internals.pixelRatio,this.height*this.internals.pixelRatio);return this.emit("resize"),this}},{key:"clear",value:function(){return this.emit("beforeClear"),this.webGLContext.bindFramebuffer(WebGLRenderingContext.FRAMEBUFFER,null),this.webGLContext.clear(WebGLRenderingContext.COLOR_BUFFER_BIT),this.emit("afterClear"),this}},{key:"scheduleStateRefresh",value:function(){this.needToRefreshState=!0,this.scheduleRender()}},{key:"refreshState",value:function(){var t=this,r;this.stateManager.flushGraphStateFlags();var i=this.stateManager.graphStateChanged&&this.internals.nodeStyleAnalysis.dependency==="graph-state",o=this.stateManager.graphStateChanged&&this.edgeStyleAnalysis.dependency==="graph-state",s=!1;if(i)this.internals.graph.forEachNode(function(p){if(t.refreshNodeState(p))s=!0});else if(this.internals.nodeStyleAnalysis.dependency!=="static"){var l=W(this.stateManager.dirtyNodes),d;try{for(l.s();!(d=l.n()).done;){var u=d.value;if(this.refreshNodeState(u))s=!0}}catch(p){l.e(p)}finally{l.f()}}if(o)this.internals.graph.forEachEdge(function(p){if(t.refreshEdgeState(p))s=!0});else if(this.edgeStyleAnalysis.dependency!=="static"){var c=W(this.stateManager.dirtyEdges),g;try{for(c.s();!(g=c.n()).done;){var h=g.value;if(this.refreshEdgeState(h))s=!0}}catch(p){c.e(p)}finally{c.f()}}if(this.stateManager.graphStateChanged&&(r=this.stylesDeclaration)!==null&&r!==void 0&&r.stage)this.refreshStageStyle();if(this.stateManager.clearDirtyTracking(),s)this.pendingProcess="full"}},{key:"refreshNodeState",value:function(t){var r=this.internals.nodeDataCache[t];if(!r||this.nodeReducer){var i,o,s,l,d=(i=this.internals.nodeDataCache[t])===null||i===void 0?void 0:i.depth,u=(o=this.internals.nodeDataCache[t])===null||o===void 0?void 0:o.zIndex,c=(s=this.internals.nodeDataCache[t])===null||s===void 0?void 0:s.labelAttachment;this.updateNode(t);var g=this.internals.nodeDataCache[t];if(this.internals.attachmentManager&&g.labelAttachment!==c)this.internals.attachmentManager.invalidateNode(t);var h;if(this.internals.nodeShapeMap&&this.internals.nodeGlobalShapeIds&&g.shape&&g.shape in this.internals.nodeShapeMap)h=this.internals.nodeGlobalShapeIds[this.internals.nodeShapeMap[g.shape]];else h=jt(g.shape||"circle");if((l=this.internals.nodeDataTexture).updateNode.apply(l,[t,g.x,g.y,g.size,h].concat(J(Tn(g)),[g.color])),d&&g.depth!==d)this.updateNodeDepthRanges(t,d,g.depth);var p=this.nodeProgramIndex[t];if(p!==void 0)this.addNodeToProgram(t,p),this.nodeProgram.invalidateBuffers();return u!==void 0&&g.zIndex!==u}var y=this.internals.graph.getNodeAttributes(t),v=this.stateManager.getNodeState(t),{size:f,shape:b,depth:m,zIndex:T,labelAttachment:_,rotationAlignment:x,labelRotationAlignment:S,color:E}=r;_a(this.stylesDeclaration.nodes,y,v,this.stateManager.graphState,this.internals.graph,r),this.postEvaluateNode(r,y,v);var D=this.nodeGraphCoords[t],A=r.x!==D.x||r.y!==D.y;if(A)D.x=r.x,D.y=r.y;if(this.normalizationFunction.applyTo(r),this.internals.nodeShapeMap){if(!r.shape||!(r.shape in this.internals.nodeShapeMap))r.shape=Object.keys(this.internals.nodeShapeMap)[0]}else if(this.nodeShapeSlug)r.shape=this.nodeShapeSlug;if(this.internals.attachmentManager&&r.labelAttachment!==_)this.internals.attachmentManager.invalidateNode(t);if(rt(this.internals.nodesWithForcedLabels,t,Ze(r)),rt(this.internals.nodesWithBackdrop,t,Aa(r)),A||r.size!==f||r.shape!==b||r.rotationAlignment!==x||r.labelRotationAlignment!==S||r.color!==E){var L,w;if(this.internals.nodeShapeMap&&this.internals.nodeGlobalShapeIds&&r.shape&&r.shape in this.internals.nodeShapeMap)w=this.internals.nodeGlobalShapeIds[this.internals.nodeShapeMap[r.shape]];else w=jt(r.shape||"circle");(L=this.internals.nodeDataTexture).updateNode.apply(L,[t,r.x,r.y,r.size,w].concat(J(Tn(r)),[r.color]))}if(this.itemBuckets.nodes.set(t,r.depth),r.depth!==m)this.updateNodeDepthRanges(t,m,r.depth);var M=this.nodeProgramIndex[t];if(M!==void 0)this.addNodeToProgram(t,M),this.nodeProgram.invalidateBuffers();return r.zIndex!==T}},{key:"refreshEdgeState",value:function(t){var r=this.internals.edgeDataCache[t];if(!r||this.edgeReducer){var i=r===null||r===void 0?void 0:r.depth,o=r===null||r===void 0?void 0:r.zIndex;this.updateEdge(t);var s=this.internals.edgeDataCache[t];if(i&&s.depth!==i)this.updateEdgeDepthRanges(t,i,s.depth);var l=this.edgeProgramIndex[t];if(l!==void 0)this.addEdgeToProgram(t,l),this.edgeProgram.invalidateBuffers();return o!==void 0&&s.zIndex!==o}var d=this.internals.graph.getEdgeAttributes(t),u=this.stateManager.getEdgeState(t),{depth:c,zIndex:g,size:h,path:p,selfLoopPath:y,parallelPath:v,head:f,tail:b}=r;if(Ta(this.stylesDeclaration.edges,d,u,this.stateManager.graphState,this.internals.graph,r),this.postEvaluateEdge(r,d),this.applyEdgeSpread(t,r,u),rt(this.internals.edgesWithForcedLabels,t,Ze(r)),this.itemBuckets.edges.set(t,r.depth),r.depth!==c)this.updateEdgeDepthRanges(t,c,r.depth);var m=this.edgeProgramIndex[t];if(m!==void 0){var T=r.size!==h||r.path!==p||r.selfLoopPath!==y||r.parallelPath!==v||r.head!==f||r.tail!==b;if(T)this.addEdgeToProgram(t,m),this.edgeProgram.invalidateBuffers();else{var _=this.internals.graph.source(t),x=this.internals.graph.target(t),S=this.internals.nodeDataCache[_],E=this.internals.nodeDataCache[x],D=this.edgeTextureIndexCache[t];this.edgeProgram.process(ut(this.pickingState,"edge",t),m,S,E,r,D),this.edgeProgram.invalidateBuffers()}}return r.zIndex!==g}},{key:"refresh",value:function(t){var r=this,i=(t===null||t===void 0?void 0:t.skipIndexation)!==void 0?t===null||t===void 0?void 0:t.skipIndexation:!1,o=(t===null||t===void 0?void 0:t.schedule)!==void 0?t.schedule:!1,s=!t||!t.partialGraph;if(s)this.clearEdgeIndices(),this.clearNodeIndices(),this.internals.graph.forEachNode(function(S){return r.addNode(S)}),this.edgeGroups.rebuild(),this.internals.graph.forEachEdge(function(S){return r.addEdge(S)}),this.pendingProcess="full";else{var l,d,u=((l=t.partialGraph)===null||l===void 0?void 0:l.nodes)||[];for(var c=0,g=(u===null||u===void 0?void 0:u.length)||0;c<g;c++){var h,p,y=""+u[c],v=(h=this.internals.nodeDataCache[y])===null||h===void 0?void 0:h.labelAttachment;if(this.updateNode(y),this.internals.attachmentManager&&((p=this.internals.nodeDataCache[y])!==null&&p!==void 0&&p.labelAttachment||v))this.internals.attachmentManager.invalidateNode(y);if(i){var f=this.nodeProgramIndex[y];if(f===void 0)throw Error(\'Sigma: node "\'.concat(y,`" can\'t be repaint`));this.addNodeToProgram(y,f)}}if(i&&u.length>0)this.nodeProgram.invalidateBuffers(),this.labelRenderer.labelsDirty=!0;var b=(t===null||t===void 0||(d=t.partialGraph)===null||d===void 0?void 0:d.edges)||[];for(var m=0,T=b.length;m<T;m++){var _=""+b[m];if(this.updateEdge(_),i){var x=this.edgeProgramIndex[_];if(x===void 0)throw Error(\'Sigma: edge "\'.concat(_,`" can\'t be repaint`));this.addEdgeToProgram(_,x)}}if(i&&b.length>0)this.edgeProgram.invalidateBuffers(),this.labelRenderer.labelsDirty=!0;if(!i&&this.pendingProcess!=="full")this.pendingProcess=b.length>0?"full":"nodes"}if(o)this.scheduleRender();else this.render();return this}},{key:"scheduleRender",value:function(){var t=this;if(!this.renderFrame)this.renderFrame=requestAnimationFrame(function(){t.render()});return this}},{key:"scheduleRefresh",value:function(t){return this.refresh(V(V({},t),{},{schedule:!0}))}},{key:"getViewportZoomedState",value:function(t,r){var i=this.camera.getState(),{ratio:o,angle:s,x:l,y:d}=i,u=this.internals.settings,{minCameraRatio:c,maxCameraRatio:g}=u;if(typeof g==="number")r=Math.min(r,g);if(typeof c==="number")r=Math.max(r,c);var h=r/o,p={x:this.width/2,y:this.height/2},y=this.viewportToFramedGraph(t),v=this.viewportToFramedGraph(p);return{angle:s,x:(y.x-v.x)*(1-h)+l,y:(y.y-v.y)*(1-h)+d,ratio:r}}},{key:"viewRectangle",value:function(){var t=this.viewportToFramedGraph({x:0,y:0}),r=this.viewportToFramedGraph({x:this.width,y:0}),i=this.viewportToFramedGraph({x:0,y:this.height});return{x1:t.x,y1:t.y,x2:r.x,y2:r.y,height:r.y-i.y}}},{key:"framedGraphToViewport",value:function(t){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=!!r.cameraState||!!r.viewportDimensions||!!r.graphDimensions||!!r.padding,o=r.matrix||(i?qe(r.cameraState||this.camera.getState(),r.viewportDimensions||this.getDimensions(),r.graphDimensions||this.getGraphDimensions(),r.padding||this.getStagePadding()):this.matrix),s=xt(o,t);return{x:(1+s.x)*this.width/2,y:(1-s.y)*this.height/2}}},{key:"viewportToFramedGraph",value:function(t){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=!!r.cameraState||!!r.viewportDimensions||!!r.graphDimensions||!!r.padding,o=r.matrix||(i?qe(r.cameraState||this.camera.getState(),r.viewportDimensions||this.getDimensions(),r.graphDimensions||this.getGraphDimensions(),r.padding||this.getStagePadding(),!0):this.invMatrix),s=xt(o,{x:t.x/this.width*2-1,y:1-t.y/this.height*2});if(isNaN(s.x))s.x=0;if(isNaN(s.y))s.y=0;return s}},{key:"viewportToGraph",value:function(t){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.normalizationFunction.inverse(this.viewportToFramedGraph(t,r))}},{key:"graphToViewport",value:function(t){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.framedGraphToViewport(this.normalizationFunction(t),r)}},{key:"graphToFramedGraph",value:function(t){return this.normalizationFunction(t)}},{key:"framedGraphToGraph",value:function(t){return this.normalizationFunction.inverse(t)}},{key:"getGraphToViewportRatio",value:function(){var t={x:0,y:0},r={x:1,y:1},i=Math.sqrt(Math.pow(t.x-r.x,2)+Math.pow(t.y-r.y,2)),o=this.graphToViewport(t),s=this.graphToViewport(r),l=Math.sqrt(Math.pow(o.x-s.x,2)+Math.pow(o.y-s.y,2));return l/i}},{key:"computeNodeExtent",value:function(){var t=this.nodeGraphCoords,r=Object.keys(t);if(!r.length)return{x:[0,1],y:[0,1]};var i=1/0,o=-1/0,s=1/0,l=-1/0;for(var d=0,u=r.length;d<u;d++){var c=t[r[d]],{x:g,y:h}=c;if(g<i)i=g;if(g>o)o=g;if(h<s)s=h;if(h>l)l=h}return{x:[i,o],y:[s,l]}}},{key:"getBBox",value:function(){return this.nodeExtent}},{key:"getCustomBBox",value:function(){return this.customBBox}},{key:"setCustomBBox",value:function(t){return this.customBBox=t,this.scheduleRender(),this}},{key:"kill",value:function(){var t,r,i,o,s;if(this.emit("kill"),this.removeAllListeners(),this.camera.cancelAnimation(),this.unbindCameraHandlers(),window.removeEventListener("resize",this.activeListeners.handleResize),this.mouseCaptor.kill(),this.touchCaptor.kill(),this.internals.hoverResolver.kill(),this.unbindGraphHandlers(),this.clearIndices(),this.clearState(),this.internals.nodeDataCache={},this.internals.edgeDataCache={},this.renderFrame)cancelAnimationFrame(this.renderFrame),this.renderFrame=null;var l=this.container;while(l.firstChild)l.removeChild(l.firstChild);this.nodeProgram.kill(),this.nodeFramePass.kill(),this.edgeProgram.kill(),this.edgeFramePass.kill(),this.internals.labelProgram.kill(),(t=this.internals.edgeLabelProgram)===null||t===void 0||t.kill(),(r=this.internals.edgeLabelBackgroundProgram)===null||r===void 0||r.kill(),this.internals.backdropProgram.kill(),this.internals.labelBackgroundProgram.kill(),(i=this.internals.attachmentProgram)===null||i===void 0||i.kill(),(o=this.internals.attachmentManager)===null||o===void 0||o.kill(),this.internals.attachmentProgram=null,this.internals.attachmentManager=null;var d=W(this.customLayerPrograms.values()),u;try{for(d.s();!(u=d.n()).done;){var c=u.value.program;c.kill()}}catch(p){d.e(p)}finally{d.f()}if(this.customLayerPrograms.clear(),this.sdfAtlas)this.sdfAtlas=null;if(this.internals.nodeDataTexture)this.internals.nodeDataTexture.kill(),this.internals.nodeDataTexture=null;if(this.internals.nodeFrameTexture)this.internals.nodeFrameTexture.kill(),this.internals.nodeFrameTexture=null;if(this.internals.edgeDataTexture)this.internals.edgeDataTexture.kill(),this.internals.edgeDataTexture=null;if(this.internals.edgeFrameTexture)this.internals.edgeFrameTexture.kill(),this.internals.edgeFrameTexture=null;if(this.webGLContext){var g;(g=this.webGLContext.getExtension("WEBGL_lose_context"))===null||g===void 0||g.loseContext(),this.webGLContext=null}(s=this.gestureHint)===null||s===void 0||s.kill(),this.gestureHint=null,this.mouseLayer.remove();for(var h in this.extraElements)this.extraElements[h].remove();this.extraElements={}}},{key:"scaleSize",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.camera.ratio;return t/this.internals.settings.zoomToSizeRatioFunction(r)*(this.getSetting("itemSizesReference")==="positions"?r*this.graphToViewportRatio:1)}},{key:"getStageCanvas",value:function(){return this.stageCanvas}},{key:"getMouseLayer",value:function(){return this.mouseLayer}}])}(_n);var uo=Dc;function co(e,a){if(typeof e==="number")return e;if(se(e)==="object"&&e!==null&&"attribute"in e)return a;return a}function ho(e){var a=e!==null&&e!==void 0?e:{},{cornerRadius:n,rotation:t}=a,r=co(n,0),i=co(t,0),o=`\n`.concat(In,`\nfloat sdf_diamond(vec2 uv, float size, float cornerRadius, float rotation) {\n // Apply rotation if needed\n vec2 p = uv;\n if (rotation != 0.0) {\n p = rotate2D(rotation) * p;\n }\n\n // Diamond SDF - using rhombus formula from Inigo Quilez\n // https://iquilezles.org/articles/distfunctions2d/\n // For a diamond (square rotated 45°), b = (size, size)\n vec2 b = vec2(size, -size);\n p = abs(p);\n float h = clamp((dot(b, p) + b.y * b.y) / dot(b, b), 0.0, 1.0);\n p -= b * vec2(h, h - 1.0);\n float d = length(p) * sign(p.x);\n\n // Apply corner radius if specified\n if (cornerRadius > 0.0) {\n d = d + cornerRadius;\n }\n\n return d;\n}\n`);return{name:"diamond",glsl:o,uniforms:[{name:"u_cornerRadius",type:"float",value:r},{name:"u_rotation",type:"float",value:i}],inradiusFactor:Math.SQRT1_2}}function fo(e){var a=e!==null&&e!==void 0?e:{},n=a.aspectRatio,t=n===void 0?{attribute:"aspectRatio"}:n,{cornerRadius:r,rotation:i}=a,o=`\n`.concat(In,`\nfloat sdf_rectangle(vec2 uv, float size, float cornerRadius, float rotation, float aspectRatio) {\n // Apply rotation if needed\n vec2 p = uv;\n if (rotation != 0.0) {\n p = rotate2D(rotation) * p;\n }\n\n vec2 halfExtent = aspectRatio >= 1.0 ? vec2(size, size / aspectRatio) : vec2(size * aspectRatio, size);\n // Keeps thin rectangles from growing past their half extent\n float radius = min(cornerRadius, min(halfExtent.x, halfExtent.y));\n\n // Based on Inigo Quilez\'s box SDF: https://iquilezles.org/articles/distfunctions2d/\n vec2 d = abs(p) - (halfExtent - radius);\n return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - radius;\n}\n`),s=[{name:"u_cornerRadius",type:"float",value:typeof r==="number"?r:0},{name:"u_rotation",type:"float",value:typeof i==="number"?i:0}],l=function(h){return"0.70710678 / max(".concat(h,", 1.0 / ").concat(h,")")};if(!Fe(t))return{name:"rectangle",glsl:o,uniforms:[].concat(s,[{name:"u_aspectRatio",type:"float",value:t}]),inradiusFactor:Math.SQRT1_2,inradiusFactorGLSL:l(ve(t))};var{attribute:d,default:u}=t,c=u===void 0?1:u;return{name:"rectangle",glsl:o,uniforms:s,attributes:[{name:"aspectRatio",size:1,type:WebGL2RenderingContext.FLOAT,source:d}],variables:R({},d,{type:"number",default:c}),inradiusFactor:Math.SQRT1_2,inradiusFactorGLSL:l("v_aspectRatio")}}var go=1.25;var Lc={size:12,weight:"regular"};var vo=30,po=20;var ff=Math.ceil(go*Lc.size+6);function Cc(e,a){return e.x<=a.x+a.width&&a.x<=e.x+e.width&&e.y<=a.y+a.height&&a.y<=e.y+e.height}function mo(e,a){let n=e.length,t=1/0,r=1/0,i=-1/0,o=-1/0;for(let{box:m}of e)t=Math.min(t,m.x),r=Math.min(r,m.y),i=Math.max(i,m.x+m.width),o=Math.max(o,m.y+m.height);if(n===0)t=r=0,i=o=1;let s=Math.max(1,i-t),l=Math.max(1,o-r),d=a??Math.max(32,Math.sqrt(s*l/Math.max(1,n))*2);while((Math.floor(s/d)+1)*(Math.floor(l/d)+1)>262144)d*=1.5;let u=Math.floor(s/d)+1,c=Math.floor(l/d)+1,g=new Map,h=[],p=(m)=>Math.min(u-1,Math.max(0,Math.floor((m-t)/d))),y=(m)=>Math.min(c-1,Math.max(0,Math.floor((m-r)/d)));e.forEach(({box:m},T)=>{let _=p(m.x),x=p(m.x+m.width),S=y(m.y),E=y(m.y+m.height);if((x-_+1)*(E-S+1)>64){h.push(T);return}for(let D=S;D<=E;D++)for(let A=_;A<=x;A++){let L=D*u+A,w=g.get(L);if(w===void 0)g.set(L,[T]);else w.push(T)}});let v=new Int32Array(n),f=0;function b(m){f+=1;let T=[],_=(x)=>{if(v[x]===f)return;v[x]=f;let S=e[x];if(Cc(S.box,m))T.push(S.value)};if(m.x<=i&&m.x+m.width>=t&&m.y<=o&&m.y+m.height>=r){let x=p(m.x),S=p(m.x+m.width),E=y(m.y),D=y(m.y+m.height);for(let A=E;A<=D;A++)for(let L=x;L<=S;L++){let w=g.get(A*u+L);if(w===void 0)continue;for(let M of w)_(M)}}for(let x of h)_(x);return T}return{size:n,query:b,at:(m,T)=>b({x:m,y:T,width:0,height:0})}}function kc(e){throw Error(`Unsupported scene: ${JSON.stringify(e)}`)}var Pc=0.05,Fc=8,Ic=7,Mc=14,zc=11,Nc=12,Gc=4,Oc=100,bo=16,Vn=new Set,yo=0,qa=1,Mt=2,Bc=3;function ze(e,a){return`${e}:${a}`}function Wc(e,a,n,t,r,i){let o=r-n,s=i-t,l=o*o+s*s,d=l===0?0:Math.max(0,Math.min(1,((e-n)*o+(a-t)*s)/l));return Math.hypot(e-(n+d*o),a-(t+d*s))}function Uc(e){let[a,n,t,r]=e;if(a===void 0||n===void 0||t===void 0||r===void 0)return[...e];let i=[];for(let o=0;o<bo;o++){let s=o/(bo-1),l=1-s,d=l*l*l,u=3*l*l*s,c=3*l*s*s,g=s*s*s;i.push({x:d*a.x+u*n.x+c*t.x+g*r.x,y:d*a.y+u*n.y+c*t.y+g*r.y})}return i}function xo(e,a,n){return a>=e.x&&a<=e.x+e.width&&n>=e.y&&n<=e.y+e.height}function Hc(e,a){if(e.length!==a.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==a[n])return!1;return!0}function _o(e,a={}){let n=a.minScale??Pc,t=a.maxScale??Fc,r=a.padding??0,i=a.labelMinPx??Ic,o=Math.max(1,e.width),s=Math.max(1,e.height),l=[],d=new Map,u=[],c=new Map,g=[];function h(I,k,G,H=0,K=!1){let te=l.length,Q=ze(I,k);return l.push({ref:{kind:I,id:k},key:Q,depth:H,container:K,item:G}),d.set(Q,te),te}function p(I,k,G,H,K,te){let Q={x:Math.min(G,K),y:Math.min(H,te),width:Math.abs(K-G),height:Math.abs(te-H)};u.push({box:Q,value:{entry:I,role:k,box:Q,x1:G,y1:H,x2:K,y2:te}})}function y(I,k,G,H,K){p(I,yo,k,G,k+H,G+K)}function v(I,k){let G=k[0];if(G===void 0)return;if(k.length===1)p(I,qa,G.x,G.y,G.x,G.y);for(let H=1;H<k.length;H++){let K=k[H-1],te=k[H];p(I,qa,K.x,K.y,te.x,te.y)}}function f(I,k){let G=c.get(I);if(G===void 0)c.set(I,G=new Set);G.add(k)}switch(e.kind){case"graph":{for(let k of e.groups){let G=h("group",k.id,k,k.depth,!0);y(G,k.x,k.y,k.width,k.height)}let I=[];for(let k of e.edges){let G=h("edge",k.id,k);if(I.push(G),v(G,k.points),k.labelBox!==void 0){let H=k.labelBox;p(G,Mt,H.x,H.y,H.x+H.width,H.y+H.height)}}for(let k of e.nodes){let G=h("node",k.id,k);y(G,k.x,k.y,k.width,k.height),g.push({index:G,label:k.label.toLowerCase(),id:k.id.toLowerCase()})}e.edges.forEach((k,G)=>{let H=l[I[G]].key,K=ze("node",k.from),te=ze("node",k.to);for(let[Q,ce]of[[K,te],[te,K]]){if(!d.has(Q))continue;if(f(Q,H),d.has(ce))f(Q,ce)}if(d.has(K))f(H,K);if(d.has(te))f(H,te)});break}case"sequence":{for(let I of e.participants){let k=h("participant",I.id,I);y(k,I.x,I.y,I.width,I.height),p(k,Bc,I.lifelineX,I.y+I.height,I.lifelineX,e.lifelineBottom),g.push({index:k,label:I.label.toLowerCase(),id:I.id.toLowerCase()})}for(let I of e.messages){let k=String(I.index),G=h("message",k,I);if(I.self){let Q=I.x1+vo,ce=I.y+po;v(G,[{x:I.x1,y:I.y},{x:Q,y:I.y},{x:Q,y:ce},{x:I.x1,y:ce}])}else v(G,[{x:I.x1,y:I.y},{x:I.x2,y:I.y}]);if(I.labelBox!==void 0){let Q=I.labelBox;p(G,Mt,Q.x,Q.y,Q.x+Q.width,Q.y+Q.height)}let H=l[G].key,K=ze("participant",I.from),te=ze("participant",I.to);for(let[Q,ce]of[[K,te],[te,K]]){if(!d.has(Q))continue;if(f(Q,H),d.has(ce))f(Q,ce)}if(d.has(K))f(H,K);if(d.has(te))f(H,te)}break}case"state":{let I=(G)=>{let H=h("state",G.id,G,G.depth,G.composite);y(H,G.x,G.y,G.width,G.height),g.push({index:H,label:G.label.toLowerCase(),id:G.id.toLowerCase()})};e.states.filter((G)=>G.composite).sort((G,H)=>G.depth-H.depth).forEach(I);let k=[];for(let G of e.transitions){let H=h("transition",G.id,G);if(k.push(H),v(H,G.points),G.labelBox!==void 0){let K=G.labelBox;p(H,Mt,K.x,K.y,K.x+K.width,K.y+K.height)}}e.states.filter((G)=>!G.composite).forEach(I),e.transitions.forEach((G,H)=>{let K=l[k[H]].key,te=ze("state",G.from),Q=ze("state",G.to);for(let[ce,Ne]of[[te,Q],[Q,te]]){if(!d.has(ce))continue;if(f(ce,K),d.has(Ne))f(ce,Ne)}if(d.has(te))f(K,te);if(d.has(Q))f(K,Q)});break}case"er":{let I=[];for(let k of e.relations){let G=h("relation",k.id,k);if(I.push(G),v(G,k.points),k.labelBox!==void 0){let H=k.labelBox;p(G,Mt,H.x,H.y,H.x+H.width,H.y+H.height)}}for(let k of e.entities){let G=h("entity",k.id,k);y(G,k.x,k.y,k.width,k.height),g.push({index:G,label:[k.label,...k.attributes.map((H)=>H.name)].join(" ").toLowerCase(),id:k.id.toLowerCase()})}e.relations.forEach((k,G)=>{let H=l[I[G]].key,K=ze("entity",k.from),te=ze("entity",k.to);for(let[Q,ce]of[[K,te],[te,K]]){if(!d.has(Q))continue;if(f(Q,H),d.has(ce))f(Q,ce)}if(d.has(K))f(H,K);if(d.has(te))f(H,te)});break}case"tree":{let I=[];for(let k of e.edges){let G=h("edge",k.id,k);I.push(G),v(G,k.curve==="bezier"?Uc(k.points):k.points)}for(let k of e.nodes){let G=h("node",k.id,k);y(G,k.x,k.y,k.width,k.height),g.push({index:G,label:k.label.toLowerCase(),id:k.id.toLowerCase()})}e.edges.forEach((k,G)=>{let H=l[I[G]].key,K=ze("node",k.from),te=ze("node",k.to);for(let[Q,ce]of[[K,te],[te,K]]){if(!d.has(Q))continue;if(f(Q,H),d.has(ce))f(Q,ce)}if(d.has(K))f(H,K);if(d.has(te))f(H,te)});break}default:kc(e)}let b=mo(u),m=l.length,T=new Int32Array(m),_=0,x={x:0,y:0,scale:1},S={width:0,height:0},E=-1,D=-1,A="",L=Vn,w={focused:!1,active:Vn},M=Z(),C=null,z=B(1),O=0,N=new Set,F=!1,P=new Set;function B(I){return{labels:Mc*I>=i,captions:zc*I>=i,edgeLabels:Nc*I>=i}}function Y(){let{width:I,height:k}=S;if(I<=0||k<=0)return n;let G=Math.min(Math.max(1,I-2*r)/o,Math.max(1,k-2*r)/s);return Math.min(n,G)}function q(I){return Math.min(t,Math.max(Y(),I))}function re(I){if(I.x===x.x&&I.y===x.y&&I.scale===x.scale)return;x=I,N.add("camera"),F=!0}function Z(){let{width:I,height:k}=S;if(I<=0||k<=0){let te=new Int32Array(m);for(let Q=0;Q<m;Q++)te[Q]=Q;return te}let G=Oc/x.scale,H=b.query({x:-x.x/x.scale-G,y:-x.y/x.scale-G,width:I/x.scale+2*G,height:k/x.scale+2*G});_+=1;let K=[];for(let te of H){if(T[te.entry]===_)continue;T[te.entry]=_,K.push(te.entry)}return Int32Array.from(K).sort()}function ee(){if(!F)return;F=!1;let I=B(x.scale);if(I.labels!==z.labels||I.captions!==z.captions||I.edgeLabels!==z.edgeLabels)z=I,N.add("lod");let k=Z();if(!Hc(k,M))M=k,C=null,N.add("visible")}function Ee(){if(ee(),N.size===0)return;let I=N;N=new Set;for(let k of[...P])k(I)}function de(I){O+=1;try{I()}finally{if(O-=1,O===0)Ee()}}function U(){if(E>=0){let I=l[E],k=new Set([I.key]);for(let G of c.get(I.key)??[])k.add(G);w={focused:!0,active:k}}else if(A!=="")w={focused:!0,active:L};else w={focused:!1,active:Vn}}function ae(I){if(I===null)return-1;return d.get(ze(I.kind,I.id))??-1}return{scene:e,camera:()=>({...x}),viewport:()=>({...S}),setViewport(I,k){if(I===S.width&&k===S.height)return;de(()=>{S={width:I,height:k},N.add("viewport"),F=!0})},setCamera(I){if(![I.x,I.y,I.scale].every(Number.isFinite)||I.scale<=0)return;de(()=>re({x:I.x,y:I.y,scale:q(I.scale)}))},fit(){let{width:I,height:k}=S;if(I<=0||k<=0)return;de(()=>{let G=Math.min(Math.max(1,I-2*r)/o,Math.max(1,k-2*r)/s),H=q(Math.min(G,1));re({scale:H,x:(I-e.width*H)/2,y:(k-e.height*H)/2})})},panBy(I,k){if(I===0&&k===0)return;de(()=>re({x:x.x+I,y:x.y+k,scale:x.scale}))},zoomAt(I,k,G){if(!Number.isFinite(I)||I<=0)return;de(()=>{let H=q(x.scale*I),K=H/x.scale;re({scale:H,x:k-(k-x.x)*K,y:G-(G-x.y)*K})})},screenToWorld:(I,k)=>({x:(I-x.x)/x.scale,y:(k-x.y)/x.scale}),worldToScreen:(I,k)=>({x:I*x.scale+x.x,y:k*x.scale+x.y}),hitTest(I,k){let G=(I-x.x)/x.scale,H=(k-x.y)/x.scale,K=Gc/x.scale,te=b.query({x:G-K,y:H-K,width:2*K,height:2*K}),Q=-1,ce=-1,Ne=1/0,pe=-1,Xn=-1;for(let _e of te){let nn=l[_e.entry];if(_e.role===yo){if(!xo(_e.box,G,H))continue;if(nn.container){if(nn.depth>Xn||nn.depth===Xn&&_e.entry>pe)pe=_e.entry,Xn=nn.depth}else if(_e.entry>Q)Q=_e.entry}else if(_e.role===qa||_e.role===Mt){let an=_e.role===Mt?xo(_e.box,G,H)?0:1/0:Wc(G,H,_e.x1,_e.y1,_e.x2,_e.y2);if(an<=K&&(an<Ne||an===Ne&&_e.entry>ce))ce=_e.entry,Ne=an}}let Za=Q>=0?Q:ce>=0?ce:pe;return Za>=0?l[Za].ref:null},visible(){if(C===null)C=Array.from(M,(I)=>l[I].ref);return{items:C,count:M.length}},lod:()=>z,hover(I){let k=ae(I);if(k===E)return;de(()=>{E=k,U(),N.add("hover")})},select(I){let k=ae(I);if(k===D)return;de(()=>{D=k,N.add("selection")})},search(I){let k=I.trim().toLowerCase();if(k===A)return;de(()=>{if(A=k,k==="")L=Vn;else{let G=new Set;for(let H of g)if(H.label.includes(k)||H.id.includes(k))G.add(l[H.index].key);L=G}U(),N.add("search")})},hovered:()=>E>=0?l[E].ref:null,selected:()=>D>=0?l[D].ref:null,highlight:()=>w,item(I){let k=ae(I);return k>=0?l[k].item:void 0},subscribe(I){return P.add(I),()=>{P.delete(I)}},batch:de}}function To(e){let{event:a,guard:n,action:t}=e;return[a,n===void 0?void 0:`[${n}]`,t===void 0?void 0:`/ ${t}`].filter((r)=>r!==void 0).join(" ")}var $c=4,Vc=/^[\\s\\u0000-\\u001f]*(javascript|data|vbscript):/i,Xc;function Ue(e){let a=(Xc??document).querySelector(`.${e}`);if(a===null)throw Error(`Missing element .${e}`);return a}function me(e,a,n){let t=document.createElement(e);if(a!==void 0)t.textContent=a;if(n!==void 0)t.className=n;return t}var jc={initial:"Initial",final:"Final",choice:"Choice",fork:"Fork",join:"Join",history:"History"},qc={one:"1","zero-or-one":"0..1","one-or-more":"1..*","zero-or-more":"0..*"},Eo="standargraph-scheme",Ya=["auto","light","dark"];function Yc(){try{let e=localStorage.getItem(Eo);return e==="light"||e==="dark"?e:"auto"}catch{return"auto"}}function Kc(e){try{localStorage.setItem(Eo,e)}catch{return}}function Zc(e){let a=e.getAttribute("data-sg-scheme");return a==="light"||a==="dark"?a:"auto"}function So(e,a,n=!0){if(a==="auto")e.removeAttribute("data-sg-scheme");else e.setAttribute("data-sg-scheme",a);let t=e.querySelector(".sg-scheme");if(t!==null){let r=`Color scheme: ${a}`;t.textContent=a[0].toUpperCase()+a.slice(1),t.setAttribute("aria-label",r),t.title=r}if(n)Kc(a);e.dispatchEvent(new CustomEvent("sg-scheme",{bubbles:!0,detail:a}))}function Ro(e){let a=e.querySelector(".sg-scheme");if(a===null)return;So(e,Yc(),!1),a.addEventListener("click",()=>{let n=Ya[(Ya.indexOf(Zc(e))+1)%Ya.length];So(e,n)})}function Ao(e,a,n){let t=a.kind==="graph"?a.edges??[]:[];function r(f){return t[f]?.id??`e${f}`}function i(f,b,m){let T=me("dt",b),_=me("dd");if(typeof m==="string")_.textContent=m;else _.appendChild(m);f.append(T,_)}function o(f){if(Vc.test(f))return document.createTextNode(f);let b=me("a",f);return b.href=f,b.target="_blank",b.rel="noopener noreferrer",b}function s(f,b){if(b===void 0)return;let m=b.provenance;if(m!==void 0){if(i(f,"Source",m.source),m.confidence!==void 0)i(f,"Confidence",m.confidence);if(m.tool!==void 0)i(f,"Tool",m.tool)}if(b.coverage!==void 0)i(f,"Coverage",`${Math.round(b.coverage*1000)/10}%`);if(b.freshness!==void 0){let T=new Date(b.freshness);i(f,"Freshness",Number.isNaN(T.getTime())?b.freshness:T.toLocaleString())}if(b.data!==void 0){let T=me("table",void 0,"sg-data");for(let[_,x]of Object.entries(b.data)){let S=me("tr");S.append(me("th",_),me("td",String(x))),T.appendChild(S)}i(f,"Data",T)}}let l=new Map;if(a.kind==="graph")a.nodes.forEach((f,b)=>l.set(f.id,b));let d=new Map;if(a.kind==="state")a.states.forEach((f,b)=>d.set(f.id,b));let u=new Map;if(a.kind==="er")a.entities.forEach((f,b)=>u.set(f.id,b));let c=new Map;if(a.kind==="tree")a.nodes.forEach((f,b)=>c.set(f.id,b));let g,h,p;function y(f,b){let m=me("dl"),T=b,_;if(f==="node"&&a.kind==="graph"){let S=a.nodes[l.get(b)??-1];if(S===void 0)return;if(T=S.label??S.id,_=S.meta,i(m,"Kind","Node"),S.type!==void 0)i(m,"Type",S.type);if(S.description!==void 0)i(m,"Description",S.description);if(S.link!==void 0)i(m,"Link",o(S.link))}else if(f==="node"&&a.kind==="tree"){let S=a.nodes[c.get(b)??-1];if(S===void 0)return;if(T=S.label,_=S.meta,i(m,"Kind","Node"),S.parent!==void 0){let D=a.nodes[c.get(S.parent)??-1];i(m,"Parent",D?.label??S.parent)}let E=e.item({kind:"node",id:b});if(E!==void 0&&"depth"in E)i(m,"Depth",String(E.depth));if(S.type!==void 0)i(m,"Type",S.type);if(S.description!==void 0)i(m,"Description",S.description);if(S.link!==void 0)i(m,"Link",o(S.link))}else if(f==="edge"&&a.kind==="graph"){if(g===void 0)g=new Map,t.forEach((E,D)=>{let A=r(D);if(!g.has(A))g.set(A,D)});let S=t[g.get(b)??-1];if(S===void 0)return;if(T=S.label??`${S.from} → ${S.to}`,_=S.meta,i(m,"Kind","Edge"),i(m,"Connection",`${S.from} → ${S.to}`),S.type!==void 0)i(m,"Type",S.type)}else if(f==="participant"&&a.kind==="sequence"){let S=a.participants.find((E)=>E.id===b);if(S===void 0)return;if(T=S.label??S.id,_=S.meta,i(m,"Kind","Participant"),S.type!==void 0)i(m,"Type",S.type)}else if(f==="message"&&a.kind==="sequence"){let S=a.messages[Number(b)];if(S===void 0)return;T=S.label??`${S.from} → ${S.to}`,_=S.meta,i(m,"Kind","Message"),i(m,"Connection",`${S.from} → ${S.to}`),i(m,"Style",S.style??"sync")}else if(f==="state"&&a.kind==="state"){let S=a.states[d.get(b)??-1];if(S===void 0)return;if(T=S.label??S.id,_=S.meta,i(m,"Kind",S.pseudo===void 0?"State":jc[S.pseudo]),S.type!==void 0)i(m,"Type",S.type);if(S.actions!==void 0&&S.actions.length>0){let E=me("div");for(let D of S.actions)E.appendChild(me("div",D));i(m,"Actions",E)}if(S.description!==void 0)i(m,"Description",S.description);if(S.link!==void 0)i(m,"Link",o(S.link))}else if(f==="transition"&&a.kind==="state"){let S=a.transitions??[];if(h===void 0)h=new Map,S.forEach((D,A)=>{let L=D.id??`t${A}`;if(!h.has(L))h.set(L,A)});let E=S[h.get(b)??-1];if(E===void 0)return;if(T=To(E)||`${E.from} → ${E.to}`,_=E.meta,i(m,"Connection",`${E.from} → ${E.to}`),E.event!==void 0)i(m,"Event",E.event);if(E.guard!==void 0)i(m,"Guard",E.guard);if(E.action!==void 0)i(m,"Action",E.action);if(E.type!==void 0)i(m,"Type",E.type)}else if(f==="entity"&&a.kind==="er"){let S=a.entities[u.get(b)??-1];if(S===void 0)return;if(T=S.label??S.id,_=S.meta,S.type!==void 0)i(m,"Type",S.type);if(S.description!==void 0)i(m,"Description",S.description);if(S.link!==void 0)i(m,"Link",o(S.link));let E=S.attributes??[];if(E.length>0){let D=me("table",void 0,"sg-data"),A=me("tr");for(let L of["Name","Type","Keys","Null","Note"])A.appendChild(me("th",L));D.appendChild(A);for(let L of E){let w=me("tr");w.append(me("td",L.name),me("td",L.type??""),me("td",(L.keys??[]).join(", ")),me("td",L.nullable===!0?"yes":""),me("td",L.note??"")),D.appendChild(w)}i(m,"Attributes",D)}}else if(f==="relation"&&a.kind==="er"){let S=a.relations??[];if(p===void 0)p=new Map,S.forEach((D,A)=>{let L=D.id??`r${A}`;if(!p.has(L))p.set(L,A)});let E=S[p.get(b)??-1];if(E===void 0)return;if(T=E.label??`${E.from} → ${E.to}`,_=E.meta,i(m,"Connection",`${E.from} → ${E.to}`),E.fromCardinality!==void 0||E.toCardinality!==void 0){let D=(A)=>A===void 0?"-":qc[A];i(m,"Cardinality",`${D(E.fromCardinality)} → ${D(E.toCardinality)}`)}if(i(m,"Identifying",E.identifying===!1?"no":"yes"),E.type!==void 0)i(m,"Type",E.type)}else return;s(m,_);let x=me("button","×","sg-close");x.type="button",x.setAttribute("aria-label","Close"),x.addEventListener("click",()=>e.select(null)),n.replaceChildren(x,me("h2",T),m),n.hidden=!1}let v=(f)=>{if(f.key==="Escape"&&!n.hidden)e.select(null)};return document.addEventListener("keydown",v),{update(){let f=e.selected();if(f===null){n.hidden=!0,n.replaceChildren();return}y(f.kind,f.id)},destroy(){document.removeEventListener("keydown",v)}}}function wo(e){let{view:a,viewport:n,search:t}=e,r=n.getBoundingClientRect(),i={pointer:null,dragging:!1,lastWheel:-1/0,rect:()=>r,resize:p,destroy(){y.disconnect()}},o=null,s=0,l=0,d=0,u=0,c=!1;n.addEventListener("pointerdown",(v)=>{if(v.button!==0)return;o=v.pointerId,s=v.clientX,l=v.clientY,d=v.clientX,u=v.clientY,c=!1}),n.addEventListener("pointermove",(v)=>{if(o===v.pointerId){let f=Math.hypot(v.clientX-s,v.clientY-l);if(!c&&f<$c)return;if(!c)c=!0,i.dragging=!0,n.setPointerCapture(v.pointerId),n.classList.add("sg-dragging");a.panBy(v.clientX-d,v.clientY-u),d=v.clientX,u=v.clientY;return}if(o!==null)return;i.pointer={x:v.clientX-r.left,y:v.clientY-r.top},e.onPointer()});function g(v){if(o!==v.pointerId)return;o=null,i.dragging=!1,n.classList.remove("sg-dragging")}n.addEventListener("pointerup",g),n.addEventListener("pointercancel",g),n.addEventListener("click",(v)=>{if(c){c=!1,v.preventDefault();return}let f=e.pick(v,v.clientX-r.left,v.clientY-r.top);if(f!==null)v.preventDefault(),a.select(f);else if(v.target instanceof Element&&v.target.closest("a")!==null)v.preventDefault()}),n.addEventListener("wheel",(v)=>{v.preventDefault(),i.lastWheel=performance.now(),a.zoomAt(Math.exp(-v.deltaY*0.0015),v.clientX-r.left,v.clientY-r.top)},{passive:!1}),n.addEventListener("mouseleave",()=>{i.pointer=null,a.hover(null)});function h(v){let f=a.viewport();a.zoomAt(v,f.width/2,f.height/2)}Ue("sg-zoom-in").addEventListener("click",()=>h(1.25)),Ue("sg-zoom-out").addEventListener("click",()=>h(0.8)),Ue("sg-fit").addEventListener("click",()=>a.fit()),t.addEventListener("input",()=>a.search(t.value));function p(){r=n.getBoundingClientRect(),a.batch(()=>{a.setViewport(n.clientWidth,n.clientHeight),a.fit()}),e.onResize?.()}let y=new ResizeObserver(p);return y.observe(n),a.batch(()=>{a.setViewport(n.clientWidth,n.clientHeight),a.fit()}),i}var Ka=150,Do=0.25,Lo=1.5;function Po(e){let a=e.trim();if(a.startsWith("#")){let t=a.length===4?a.slice(1).split("").map((i)=>i+i).join(""):a.slice(1,7),r=Number.parseInt(t,16);return[r>>16&255,r>>8&255,r&255]}let n=a.match(/[\\d.]+/g)?.map(Number)??[0,0,0];return[n[0]??0,n[1]??0,n[2]??0]}function tn(e,a,n){return[e[0]+(a[0]-e[0])*n,e[1]+(a[1]-e[1])*n,e[2]+(a[2]-e[2])*n]}function ht(e){return`rgb(${Math.round(e[0])},${Math.round(e[1])},${Math.round(e[2])})`}function Co(e){let[a,n,t]=e.map((r)=>{let i=r/255;return i<=0.03928?i/12.92:((i+0.055)/1.055)**2.4});return 0.2126*a+0.7152*n+0.0722*t}function ko(e,a){let[n,t]=[Co(e),Co(a)].sort((r,i)=>i-r);return(n+0.05)/(t+0.05)}function Qc(e,a){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("class","sg-root"),t.style.display="none";let r=(d)=>{let u=document.createElementNS("http://www.w3.org/2000/svg","g");if(d!==void 0)u.setAttribute("data-type",d);let c=document.createElementNS("http://www.w3.org/2000/svg","rect");return c.setAttribute("class","sg-node"),u.append(c),t.append(u),c},i=r(void 0),o=a.map((d)=>[d,r(d)]);e.append(t);let s=getComputedStyle(i).fill,l=new Map;for(let[d,u]of o){let c=getComputedStyle(u).fill;if(c!==s)l.set(d,Po(c))}return t.remove(),l}function Fo(e,a){if(a.kind!=="graph")return;let n=a,t=fo({aspectRatio:{attribute:"aspect",default:3},cornerRadius:0.18}),r=ho(),i=Bt(),o=Ue("sg-app"),s=Ue("sg-viewport"),l=Ue("sg-gl"),d=Ue("sg-groups"),u=Ue("sg-panel"),c=Ue("sg-search");Ro(o);let g="Inter, system-ui, sans-serif",h=[...new Set(n.nodes.flatMap((U)=>U.type===void 0?[]:[U.type]))],p=()=>{let U=getComputedStyle(o),ae=(be)=>Po(U.getPropertyValue(be));return{bg:ae("--sg-bg"),fg:ae("--sg-fg"),muted:ae("--sg-muted"),stroke:ae("--sg-node-stroke"),edge:ae("--sg-edge"),groupFill:ht(ae("--sg-group-fill")),groupStroke:ht(ae("--sg-group-stroke")),accent:ht(ae("--sg-accent")),typed:Qc(o,h)}},y=p(),v=_o(n),f=Ao(v,e,u),b=new ue({multi:!0,type:"directed"}),m=(U)=>U?.provenance?.confidence,T=(U)=>{let{bg:ae,fg:be,muted:I,stroke:k,typed:G}=y,H=m(U.meta),K=U.type===void 0?void 0:G.get(U.type),te=K??k,Q=H==="unknown"?tn(I,ae,0.55):H==="inferred"?tn(te,ae,0.88):K??tn(te,ae,0.75);return{color:ht(Q),labelColor:ht(ko(Q,be)>=ko(Q,ae)?be:ae)}},_=(U)=>{let ae=m(U.meta);return ht(ae==="unknown"?tn(y.edge,y.bg,0.7):ae==="inferred"?tn(y.edge,y.bg,0.4):y.edge)};for(let U of n.nodes)b.addNode(U.id,{x:U.x+U.width/2,y:-(U.y+U.height/2),size:U.width/2,aspect:U.width/U.height,shape:U.shape==="diamond"?r.name:U.shape==="circle"?i.name:t.name,label:U.label,...T(U)});for(let U of n.edges){if(!b.hasNode(U.from)||!b.hasNode(U.to))continue;b.addEdgeWithKey(U.id,U.from,U.to,{size:Lo,color:_(U),directed:U.directed})}let x=v.highlight(),S=v.selected(),E=()=>({backdropVisibility:"visible",backdropColor:y.accent,backdropPadding:4}),D={opacity:Do,labelVisibility:"hidden"},A=1,L=new uo(b,l,{primitives:{nodes:{shapes:[t,r,i],label:{zoomToLabelSizeRatioFunction:(U)=>U/A}}},styles:{nodes:{x:{attribute:"x"},y:{attribute:"y"},size:{attribute:"size"},color:{attribute:"color"},shape:{attribute:"shape"},label:{attribute:"label"},labelColor:{attribute:"labelColor"},labelPosition:"over",labelSize:14,labelFont:`600 ${g}`},edges:{size:{attribute:"size"},color:{attribute:"color"}}},settings:{itemSizesReference:"positions",zoomToSizeRatioFunction:(U)=>U,autoRescale:!1,enableCameraRotation:!1,enableNodeDrag:!1,renderLabels:v.lod().labels,renderEdgeLabels:!1,hideEdgesOnMove:!1,hideLabelsOnMove:!1,labelRenderedSizeThreshold:0,labelDensity:1000},nodeReducer(U){let ae={};if(x.focused&&!x.active.has(`node:${U}`))Object.assign(ae,D);if(S!==null&&S.kind==="node"&&S.id===U)Object.assign(ae,E());return ae},edgeReducer(U){if(S!==null&&S.kind==="edge"&&S.id===U)return{color:y.accent,size:Lo*2};if(x.focused&&!x.active.has(`edge:${U}`))return{opacity:Do};return{}}});L.getMouseCaptor().kill(),L.getTouchCaptor().kill(),L.setCustomBBox({x:[0,n.width],y:[-n.height,0]});function w(){let U=(k,G,H)=>L.graphToViewport({x:H,y:0},{cameraState:{x:k,y:G,ratio:1,angle:0}}),ae=U(0.5,0.5,0),{width:be,height:I}=L.getDimensions();return{unit:U(0.5,0.5,1).x-ae.x,span:ae.x-U(1.5,0.5,0).x,offsetX:ae.x-be/2,offsetY:ae.y-I/2}}let M=w();A=M.unit;function C(){let U=v.camera(),{width:ae,height:be}=v.viewport(),{unit:I,span:k,offsetX:G,offsetY:H}=M,K=I/U.scale;L.getCamera().setState({ratio:K,x:0.5+(G-(U.x-ae/2)*K)/k,y:0.5+((U.y-be/2)*K-H)/k,angle:0})}let z=d.getContext("2d");function O(){let U=window.devicePixelRatio||1,{width:ae,height:be}=v.viewport(),I=Math.round(ae*U),k=Math.round(be*U);if(d.width!==I||d.height!==k)d.width=I,d.height=k;let G=z;G.setTransform(1,0,0,1,0,0),G.clearRect(0,0,I,k);let H=v.camera();G.setTransform(U*H.scale,0,0,U*H.scale,U*H.x,U*H.y),G.lineWidth=1/H.scale;let{groupFill:K,groupStroke:te}=y;G.fillStyle=K,G.strokeStyle=te;let Q=v.lod().edgeLabels,ce=ht(y.muted);G.font=`600 12px ${g}`,G.textBaseline="top";for(let Ne of v.visible().items){if(Ne.kind!=="group")continue;let pe=v.item({kind:"group",id:Ne.id});if(pe===void 0)continue;if(G.beginPath(),G.roundRect(pe.x,pe.y,pe.width,pe.height,8),G.fill(),G.stroke(),Q&&pe.label!==void 0)G.fillStyle=ce,G.fillText(pe.label,pe.x+12,pe.y+8),G.fillStyle=K}}L.on("afterRender",()=>{if(O(),o.dataset.sgReady===void 0)o.dataset.sgReady="1"});let N=!1,F=!1,P=0,B=0;function Y(){if(P=performance.now(),B===0)B=window.setTimeout(q,Ka)}function q(){let U=Ka-(performance.now()-P);if(U>1){B=window.setTimeout(q,U);return}if(B=0,de.pointer!==null)ee()}function re(){let U=de.pointer;if(U===null||de.dragging)return;if(performance.now()-de.lastWheel<Ka)return;let ae=v.hitTest(U.x,U.y);de.pointer=null,v.hover(ae!==null&&ae.kind==="node"?ae:null)}function Z(){if(re(),N=!1,F)F=!1,x=v.highlight(),S=v.selected(),L.refresh({skipIndexation:!0,schedule:!0})}function ee(){if(N)return;N=!0,requestAnimationFrame(Z)}v.subscribe((U)=>{if(U.has("selection"))f.update();if(U.has("camera"))Y(),C();if(U.has("lod"))L.setSetting("renderLabels",v.lod().labels);if(U.has("hover")||U.has("search")||U.has("selection"))F=!0;ee()});function Ee(U,ae,be){let I=v.hitTest(ae,be);return I===null||I.kind==="group"?null:I}let de=wo({view:v,viewport:s,search:c,pick:Ee,onPointer:ee,onResize(){L.resize(),M=w(),A=M.unit,C(),O()}});return o.addEventListener("sg-scheme",()=>{y=p();for(let U of n.nodes)b.mergeNodeAttributes(U.id,T(U));for(let U of n.edges)if(b.hasEdge(U.id))b.setEdgeAttribute(U.id,"color",_(U));O(),L.refresh()}),L.resize(),M=w(),A=M.unit,C(),L.refresh(),{view:v,destroy(){de.destroy(),f.destroy(),clearTimeout(B),L.kill()}}}function Io(e){return JSON.parse(document.getElementById(e).textContent??"{}")}Fo(Io("standargraph-document"),Io("standargraph-scene"));})();';
160
+
161
+ // src/webgl/index.ts
162
+ function renderWebglHtml2(document, laidOut, options = {}) {
163
+ return renderPage({
164
+ document,
165
+ laidOut,
166
+ options,
167
+ viewport: WEBGL_VIEWPORT,
168
+ runtime: WEBGL_RUNTIME_JS
169
+ });
170
+ }
171
+
172
+ export { loadFonts, STYLE, svgViewport, WEBGL_VIEWPORT, appMarkup, renderPage, renderWebglHtml2 };