chiltepin-render 0.34.0 → 0.34.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3114,11 +3114,16 @@ var TY = new Set(
3114
3114
  );
3115
3115
  var TOKEN_RE = /(\/\*[\s\S]*?\*\/|\/\/[^\n]*|#[^\n]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)|(\b\d[\w.]*)|([A-Za-z_$][\w$]*)/g;
3116
3116
  var MD_LANGS = /* @__PURE__ */ new Set(["md", "markdown", "mdx"]);
3117
+ var PLAIN_LANGS = /* @__PURE__ */ new Set(["text", "txt", "plain", "plaintext", "prompt", "none"]);
3117
3118
  function highlightCode(code, lang) {
3118
3119
  if (code.length === 0) return "";
3119
- if (lang !== void 0 && MD_LANGS.has(lang.trim().toLowerCase())) {
3120
+ const label = lang?.trim().toLowerCase();
3121
+ if (label !== void 0 && MD_LANGS.has(label)) {
3120
3122
  return highlightMarkdown(String(code));
3121
3123
  }
3124
+ if (label !== void 0 && PLAIN_LANGS.has(label)) {
3125
+ return escapeHtml(String(code));
3126
+ }
3122
3127
  const src = String(code);
3123
3128
  let out = "";
3124
3129
  let last = 0;
@@ -4011,2487 +4016,2495 @@ function nodeCellAttrs(col, row, w2) {
4011
4016
  return ` data-col="${col}" data-row="${row}"${w2 !== void 0 ? ` data-w="${w2}"` : ""}`;
4012
4017
  }
4013
4018
 
4014
- // ../../node_modules/.pnpm/@dagrejs+dagre@3.0.0/node_modules/@dagrejs/dagre/dist/dagre.esm.js
4015
- var ge = Object.defineProperty;
4016
- var hn = (e, n, t) => n in e ? ge(e, n, { enumerable: true, configurable: true, writable: true, value: t }) : e[n] = t;
4017
- var fn = (e, n) => {
4018
- for (var t in n) ge(e, t, { get: n[t], enumerable: true });
4019
+ // src/svg/glyphs.ts
4020
+ var GENERIC_BOX = "box";
4021
+ var PATHS = {
4022
+ // λ
4023
+ function: "M3 2 H5 L10.5 12 M7.6 7 L3.5 12",
4024
+ // pail: elliptical rim, tapered sides
4025
+ bucket: "M2 3.5 a5 1.6 0 0 0 10 0 a5 1.6 0 0 0 -10 0 M2 3.5 L3.5 12.5 H10.5 L12 3.5",
4026
+ // three message bars
4027
+ queue: "M3 1.5 V12.5 M7 1.5 V12.5 M11 1.5 V12.5",
4028
+ // one in, fan out to three
4029
+ topic: "M1.5 7 H5.5 M5.5 7 L11.5 2.5 M5.5 7 H12 M5.5 7 L11.5 11.5",
4030
+ // stacked memory slabs
4031
+ cache: "M1.5 4.5 L7 2 L12.5 4.5 L7 7 Z M1.5 8 L7 10.5 L12.5 8 M1.5 11 L7 13.5 L12.5 11",
4032
+ // the cylinder
4033
+ db: "M1.5 3 a5.5 2.2 0 0 0 11 0 a5.5 2.2 0 0 0 -11 0 V11 a5.5 2.2 0 0 0 11 0 V3",
4034
+ // cloud
4035
+ cdn: "M3.5 12 a3 3 0 0 1 0.3 -6 a4 4 0 0 1 7.6 1 a2.5 2.5 0 0 1 0.6 5 Z",
4036
+ // splitter: one lane in, three out
4037
+ lb: "M1.5 7 H5 M5 7 L9 3 H12.5 M5 7 H12.5 M5 7 L9 11 H12.5",
4038
+ // double chevron
4039
+ gateway: "M2 1.5 L7 7 L2 12.5 M7.5 1.5 L12.5 7 L7.5 12.5",
4040
+ // hexagon with a core
4041
+ pod: "M7 1.2 L12.2 4.1 V9.9 L7 12.8 L1.8 9.9 V4.1 Z M5.2 7 a1.8 1.8 0 1 0 3.6 0 a1.8 1.8 0 1 0 -3.6 0",
4042
+ // wheel: ring + four spokes
4043
+ cluster: "M1.5 7 a5.5 5.5 0 1 0 11 0 a5.5 5.5 0 1 0 -11 0 M7 1.5 V4.5 M7 9.5 V12.5 M1.5 7 H4.5 M9.5 7 H12.5",
4044
+ // head + shoulders
4045
+ user: "M4.5 4.5 a2.5 2.5 0 1 0 5 0 a2.5 2.5 0 1 0 -5 0 M2.5 13 a4.5 4.5 0 0 1 9 0",
4046
+ // window with a header band
4047
+ browser: "M1.5 2.5 H12.5 V11.5 H1.5 Z M1.5 5.5 H12.5",
4048
+ // phone
4049
+ mobile: "M4 1.5 H10 a1 1 0 0 1 1 1 V11.5 a1 1 0 0 1 -1 1 H4 a1 1 0 0 1 -1 -1 V2.5 a1 1 0 0 1 1 -1 Z M6 11 H8",
4050
+ // clock
4051
+ cron: "M1.5 7 a5.5 5.5 0 1 0 11 0 a5.5 5.5 0 1 0 -11 0 M7 3.5 V7 L9.5 8.5",
4052
+ // four-point spark
4053
+ ml: "M7 1.5 L8.4 5.6 L12.5 7 L8.4 8.4 L7 12.5 L5.6 8.4 L1.5 7 L5.6 5.6 Z",
4054
+ // padlock
4055
+ secret: "M3 6.5 H11 V13 H3 Z M4.5 6.5 V4.5 a2.5 2.5 0 0 1 5 0 V6.5",
4056
+ // three sliders
4057
+ config: "M1.5 3.5 H12.5 M1.5 7 H12.5 M1.5 10.5 H12.5 M4.5 2 V5 M9.5 5.5 V8.5 M6 9 V12",
4058
+ // replica set: two overlapping squares
4059
+ deployment: "M1.5 5 H9 V12.5 H1.5 Z M4 5 V2.5 H11.5 V10 H9",
4060
+ // arrow into a door
4061
+ ingress: "M1.5 7 H8 M5.5 4.5 L8 7 L5.5 9.5 M10 1.5 H12.5 V12.5 H10",
4062
+ // two rack slabs
4063
+ node: "M2 2 H12 V6 H2 Z M2 8 H12 V12 H2 Z M4.5 4 H6.5 M4.5 10 H6.5",
4064
+ // folder tab
4065
+ namespace: "M1.5 3.5 H5.5 L7 5 H12.5 V12 H1.5 Z",
4066
+ box: "M2 2 H12 V12 H2 Z"
4019
4067
  };
4020
- var pe = (e, n, t) => hn(e, n + "" , t);
4021
- var z = {};
4022
- fn(z, { Graph: () => p, alg: () => R, json: () => ye, version: () => pn });
4023
- var bn = Object.defineProperty;
4024
- var Le = (e, n) => {
4025
- for (var t in n) bn(e, t, { get: n[t], enumerable: true });
4068
+ var ALIAS = {
4069
+ function: "function",
4070
+ lambda: "function",
4071
+ bucket: "bucket",
4072
+ s3: "bucket",
4073
+ blob: "bucket",
4074
+ object: "bucket",
4075
+ queue: "queue",
4076
+ sqs: "queue",
4077
+ mq: "queue",
4078
+ broker: "queue",
4079
+ rabbitmq: "queue",
4080
+ topic: "topic",
4081
+ sns: "topic",
4082
+ kafka: "topic",
4083
+ kinesis: "topic",
4084
+ stream: "topic",
4085
+ cache: "cache",
4086
+ redis: "cache",
4087
+ memcached: "cache",
4088
+ db: "db",
4089
+ database: "db",
4090
+ store: "db",
4091
+ postgres: "db",
4092
+ mysql: "db",
4093
+ mongo: "db",
4094
+ mongodb: "db",
4095
+ dynamo: "db",
4096
+ cdn: "cdn",
4097
+ lb: "lb",
4098
+ gateway: "gateway",
4099
+ proxy: "gateway",
4100
+ pod: "pod",
4101
+ cluster: "cluster",
4102
+ user: "user",
4103
+ person: "user",
4104
+ actor: "user",
4105
+ browser: "browser",
4106
+ web: "browser",
4107
+ mobile: "mobile",
4108
+ cron: "cron",
4109
+ scheduler: "cron",
4110
+ job: "cron",
4111
+ cronjob: "cron",
4112
+ ml: "ml",
4113
+ model: "ml",
4114
+ llm: "ml",
4115
+ agent: "ml",
4116
+ ai: "ml",
4117
+ secret: "secret",
4118
+ secrets: "secret",
4119
+ vault: "secret",
4120
+ kms: "secret",
4121
+ config: "config",
4122
+ configmap: "config",
4123
+ settings: "config",
4124
+ deployment: "deployment",
4125
+ ingress: "ingress",
4126
+ node: "node",
4127
+ vm: "node",
4128
+ server: "node",
4129
+ host: "node",
4130
+ namespace: "namespace"
4026
4131
  };
4027
- var p = class {
4028
- constructor(e) {
4029
- this._isDirected = true, this._isMultigraph = false, this._isCompound = false, this._nodes = {}, this._in = {}, this._preds = {}, this._out = {}, this._sucs = {}, this._edgeObjs = {}, this._edgeLabels = {}, this._nodeCount = 0, this._edgeCount = 0, this._defaultNodeLabelFn = () => {
4030
- }, this._defaultEdgeLabelFn = () => {
4031
- }, e && (this._isDirected = "directed" in e ? e.directed : true, this._isMultigraph = "multigraph" in e ? e.multigraph : false, this._isCompound = "compound" in e ? e.compound : false), this._isCompound && (this._parent = {}, this._children = {}, this._children["\0"] = {});
4032
- }
4033
- isDirected() {
4034
- return this._isDirected;
4035
- }
4036
- isMultigraph() {
4037
- return this._isMultigraph;
4038
- }
4039
- isCompound() {
4040
- return this._isCompound;
4041
- }
4042
- setGraph(e) {
4043
- return this._label = e, this;
4044
- }
4045
- graph() {
4046
- return this._label;
4047
- }
4048
- setDefaultNodeLabel(e) {
4049
- return typeof e != "function" ? this._defaultNodeLabelFn = () => e : this._defaultNodeLabelFn = e, this;
4050
- }
4051
- nodeCount() {
4052
- return this._nodeCount;
4053
- }
4054
- nodes() {
4055
- return Object.keys(this._nodes);
4056
- }
4057
- sources() {
4058
- return this.nodes().filter((e) => Object.keys(this._in[e]).length === 0);
4059
- }
4060
- sinks() {
4061
- return this.nodes().filter((e) => Object.keys(this._out[e]).length === 0);
4062
- }
4063
- setNodes(e, n) {
4064
- return e.forEach((t) => {
4065
- n !== void 0 ? this.setNode(t, n) : this.setNode(t);
4066
- }), this;
4067
- }
4068
- setNode(e, n) {
4069
- return e in this._nodes ? (arguments.length > 1 && (this._nodes[e] = n), this) : (this._nodes[e] = arguments.length > 1 ? n : this._defaultNodeLabelFn(e), this._isCompound && (this._parent[e] = "\0", this._children[e] = {}, this._children["\0"][e] = true), this._in[e] = {}, this._preds[e] = {}, this._out[e] = {}, this._sucs[e] = {}, ++this._nodeCount, this);
4070
- }
4071
- node(e) {
4072
- return this._nodes[e];
4073
- }
4074
- hasNode(e) {
4075
- return e in this._nodes;
4076
- }
4077
- removeNode(e) {
4078
- if (e in this._nodes) {
4079
- let n = (t) => this.removeEdge(this._edgeObjs[t]);
4080
- delete this._nodes[e], this._isCompound && (this._removeFromParentsChildList(e), delete this._parent[e], this.children(e).forEach((t) => {
4081
- this.setParent(t);
4082
- }), delete this._children[e]), Object.keys(this._in[e]).forEach(n), delete this._in[e], delete this._preds[e], Object.keys(this._out[e]).forEach(n), delete this._out[e], delete this._sucs[e], --this._nodeCount;
4083
- }
4084
- return this;
4085
- }
4086
- setParent(e, n) {
4087
- if (!this._isCompound) throw new Error("Cannot set parent in a non-compound graph");
4088
- if (n === void 0) n = "\0";
4089
- else {
4090
- n += "";
4091
- for (let t = n; t !== void 0; t = this.parent(t)) if (t === e) throw new Error("Setting " + n + " as parent of " + e + " would create a cycle");
4092
- this.setNode(n);
4093
- }
4094
- return this.setNode(e), this._removeFromParentsChildList(e), this._parent[e] = n, this._children[n][e] = true, this;
4095
- }
4096
- parent(e) {
4097
- if (this._isCompound) {
4098
- let n = this._parent[e];
4099
- if (n !== "\0") return n;
4100
- }
4101
- }
4102
- children(e = "\0") {
4103
- if (this._isCompound) {
4104
- let n = this._children[e];
4105
- if (n) return Object.keys(n);
4106
- } else {
4107
- if (e === "\0") return this.nodes();
4108
- if (this.hasNode(e)) return [];
4109
- }
4110
- return [];
4111
- }
4112
- predecessors(e) {
4113
- let n = this._preds[e];
4114
- if (n) return Object.keys(n);
4115
- }
4116
- successors(e) {
4117
- let n = this._sucs[e];
4118
- if (n) return Object.keys(n);
4119
- }
4120
- neighbors(e) {
4121
- let n = this.predecessors(e);
4122
- if (n) {
4123
- let t = new Set(n);
4124
- for (let r5 of this.successors(e)) t.add(r5);
4125
- return Array.from(t.values());
4126
- }
4127
- }
4128
- isLeaf(e) {
4129
- let n;
4130
- return this.isDirected() ? n = this.successors(e) : n = this.neighbors(e), n.length === 0;
4131
- }
4132
- filterNodes(e) {
4133
- let n = new this.constructor({ directed: this._isDirected, multigraph: this._isMultigraph, compound: this._isCompound });
4134
- n.setGraph(this.graph()), Object.entries(this._nodes).forEach(([o, i]) => {
4135
- e(o) && n.setNode(o, i);
4136
- }), Object.values(this._edgeObjs).forEach((o) => {
4137
- n.hasNode(o.v) && n.hasNode(o.w) && n.setEdge(o, this.edge(o));
4138
- });
4139
- let t = {}, r5 = (o) => {
4140
- let i = this.parent(o);
4141
- return !i || n.hasNode(i) ? (t[o] = i != null ? i : void 0, i != null ? i : void 0) : i in t ? t[i] : r5(i);
4142
- };
4143
- return this._isCompound && n.nodes().forEach((o) => n.setParent(o, r5(o))), n;
4144
- }
4145
- setDefaultEdgeLabel(e) {
4146
- return typeof e != "function" ? this._defaultEdgeLabelFn = () => e : this._defaultEdgeLabelFn = e, this;
4147
- }
4148
- edgeCount() {
4149
- return this._edgeCount;
4150
- }
4151
- edges() {
4152
- return Object.values(this._edgeObjs);
4153
- }
4154
- setPath(e, n) {
4155
- return e.reduce((t, r5) => (n !== void 0 ? this.setEdge(t, r5, n) : this.setEdge(t, r5), r5)), this;
4156
- }
4157
- setEdge(e, n, t, r5) {
4158
- let o, i, s, a, d = false;
4159
- typeof e == "object" && e !== null && "v" in e ? (o = e.v, i = e.w, s = e.name, arguments.length === 2 && (a = n, d = true)) : (o = e, i = n, s = r5, arguments.length > 2 && (a = t, d = true)), o = "" + o, i = "" + i, s !== void 0 && (s = "" + s);
4160
- let l = C(this._isDirected, o, i, s);
4161
- if (l in this._edgeLabels) return d && (this._edgeLabels[l] = a), this;
4162
- if (s !== void 0 && !this._isMultigraph) throw new Error("Cannot set a named edge when isMultigraph = false");
4163
- this.setNode(o), this.setNode(i), this._edgeLabels[l] = d ? a : this._defaultEdgeLabelFn(o, i, s);
4164
- let u = gn(this._isDirected, o, i, s);
4165
- return o = u.v, i = u.w, Object.freeze(u), this._edgeObjs[l] = u, me(this._preds[i], o), me(this._sucs[o], i), this._in[i][l] = u, this._out[o][l] = u, this._edgeCount++, this;
4132
+ function glyphNameFor(kind) {
4133
+ return ALIAS[(kind ?? "").trim().toLowerCase()] ?? GENERIC_BOX;
4134
+ }
4135
+ function hasGlyph(kind) {
4136
+ return (kind ?? "").trim().toLowerCase() in ALIAS;
4137
+ }
4138
+ function cloudGlyph(kind, x2, y, c = "var(--muted)") {
4139
+ const d = PATHS[glyphNameFor(kind)];
4140
+ return `<path d="${d}" transform="translate(${x2} ${y})" fill="none" stroke="${c}" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round"/>`;
4141
+ }
4142
+
4143
+ // src/svg/blockStyle.ts
4144
+ var KNOWN_NODE_KINDS = [
4145
+ "client",
4146
+ "service",
4147
+ "microservice",
4148
+ "compute",
4149
+ "container",
4150
+ "data",
4151
+ "store",
4152
+ "db",
4153
+ "database",
4154
+ "postgres",
4155
+ "mysql",
4156
+ "mongo",
4157
+ "mongodb",
4158
+ "dynamo",
4159
+ "bucket",
4160
+ "blob",
4161
+ "object",
4162
+ "s3",
4163
+ "queue",
4164
+ "mq",
4165
+ "broker",
4166
+ "sqs",
4167
+ "rabbitmq",
4168
+ "cache",
4169
+ "redis",
4170
+ "memcached",
4171
+ "gateway",
4172
+ "lb",
4173
+ "proxy",
4174
+ "function",
4175
+ "lambda",
4176
+ "cdn",
4177
+ "external",
4178
+ "producer",
4179
+ "topic",
4180
+ "consumer",
4181
+ "context",
4182
+ "firewall",
4183
+ "waf",
4184
+ "shield",
4185
+ "dns",
4186
+ "auth",
4187
+ "identity",
4188
+ "idp",
4189
+ "iam",
4190
+ "oauth",
4191
+ "sso",
4192
+ "monitor",
4193
+ "observability",
4194
+ "metrics",
4195
+ "logs",
4196
+ "tracing",
4197
+ "apm",
4198
+ "scheduler",
4199
+ "cron",
4200
+ "job",
4201
+ "stream",
4202
+ "kafka",
4203
+ "kinesis",
4204
+ "warehouse",
4205
+ "lake",
4206
+ "analytics",
4207
+ "bi",
4208
+ "search",
4209
+ "index",
4210
+ "elasticsearch",
4211
+ "opensearch",
4212
+ "registry",
4213
+ "ci",
4214
+ "cicd",
4215
+ "pipeline",
4216
+ "git",
4217
+ "repo",
4218
+ "scm",
4219
+ "device",
4220
+ "iot",
4221
+ "email",
4222
+ "sms",
4223
+ "config",
4224
+ "settings",
4225
+ "ml",
4226
+ "model",
4227
+ "llm",
4228
+ "agent",
4229
+ "ai",
4230
+ "user",
4231
+ "person",
4232
+ "actor",
4233
+ "browser",
4234
+ "web",
4235
+ "mobile",
4236
+ "vm",
4237
+ "server",
4238
+ "host",
4239
+ "secrets",
4240
+ "vault",
4241
+ "kms",
4242
+ "notification",
4243
+ "webhook",
4244
+ "worker",
4245
+ "etl",
4246
+ "shard",
4247
+ "shards",
4248
+ "sharded",
4249
+ "replica",
4250
+ "replicas",
4251
+ "replicaset",
4252
+ "users",
4253
+ "crowd",
4254
+ "region",
4255
+ "geo",
4256
+ "globe",
4257
+ // `preset: k8s` vocabulary (namespaces are groups; these are the node kinds).
4258
+ "deployment",
4259
+ "pod",
4260
+ "ingress",
4261
+ "configmap",
4262
+ "secret",
4263
+ "cronjob",
4264
+ "node",
4265
+ "namespace",
4266
+ "cluster",
4267
+ "sns"
4268
+ ];
4269
+ var SKIN = {};
4270
+ var def = (kinds, skin) => {
4271
+ for (const k2 of kinds) SKIN[k2] = skin;
4272
+ };
4273
+ var primary = (chip3) => ({ chip: chip3, primary: true, fill: "paper", dashed: false });
4274
+ var secondary = (chip3) => ({ chip: chip3, primary: false, fill: "paper-2", dashed: false });
4275
+ var external = (chip3) => ({ chip: chip3, primary: true, fill: "paper", dashed: true });
4276
+ def(["client", "user", "person", "actor", "users", "crowd", "browser", "web", "mobile", "device", "iot"], primary("CLIENT"));
4277
+ def(["service", "microservice", "compute", "container", "worker", "etl"], primary("SVC"));
4278
+ def(["data"], primary("DATA"));
4279
+ def(["store", "db", "database", "postgres", "mysql", "mongo", "mongodb", "dynamo"], secondary("DB"));
4280
+ def(["shard", "shards", "sharded", "replica", "replicas", "replicaset"], secondary("DB"));
4281
+ def(["bucket", "blob", "object", "s3"], secondary("BUCKET"));
4282
+ def(["warehouse", "lake"], secondary("WAREHOUSE"));
4283
+ def(["queue", "mq", "broker", "sqs", "rabbitmq"], secondary("QUEUE"));
4284
+ def(["topic"], secondary("TOPIC"));
4285
+ def(["stream", "kafka", "kinesis"], secondary("BUS"));
4286
+ def(["cache", "redis", "memcached"], secondary("CACHE"));
4287
+ def(["search", "index", "elasticsearch", "opensearch"], secondary("SEARCH"));
4288
+ def(["registry"], secondary("REGISTRY"));
4289
+ def(["gateway", "proxy"], primary("GATEWAY"));
4290
+ def(["lb"], primary("LB"));
4291
+ def(["function", "lambda"], primary("FN"));
4292
+ def(["cdn"], external("EDGE"));
4293
+ def(["external"], external("EXT"));
4294
+ def(["producer"], primary("PRODUCER"));
4295
+ def(["consumer"], primary("CONSUMER"));
4296
+ def(["context"], primary("CONTEXT"));
4297
+ def(["firewall", "waf", "shield"], primary("WAF"));
4298
+ def(["dns"], external("DNS"));
4299
+ def(["auth", "identity", "idp", "iam", "oauth", "sso"], primary("AUTH"));
4300
+ def(["monitor", "observability", "metrics", "logs", "tracing", "apm"], primary("OBS"));
4301
+ def(["scheduler", "cron", "job"], primary("CRON"));
4302
+ def(["analytics", "bi"], primary("ANALYTICS"));
4303
+ def(["ci", "cicd", "pipeline"], primary("CI"));
4304
+ def(["git", "repo", "scm"], secondary("GIT"));
4305
+ def(["email", "sms"], external("EMAIL"));
4306
+ def(["config", "settings"], secondary("CONFIG"));
4307
+ def(["ml", "model", "llm", "agent", "ai"], primary("AI"));
4308
+ def(["vm", "server", "host"], primary("HOST"));
4309
+ def(["secrets", "vault", "kms"], secondary("SECRETS"));
4310
+ def(["notification", "webhook"], external("WEBHOOK"));
4311
+ def(["region", "geo", "globe"], external("REGION"));
4312
+ def(["deployment"], primary("DEPLOY"));
4313
+ def(["pod"], primary("POD"));
4314
+ def(["ingress"], primary("INGRESS"));
4315
+ def(["configmap"], secondary("CONFIG"));
4316
+ def(["secret"], secondary("SECRETS"));
4317
+ def(["cronjob"], primary("CRON"));
4318
+ def(["node"], primary("NODE"));
4319
+ def(["namespace"], secondary("NS"));
4320
+ def(["cluster"], primary("CLUSTER"));
4321
+ def(["sns"], secondary("TOPIC"));
4322
+ function nodeSkin(kind) {
4323
+ const k2 = (kind ?? "").trim().toLowerCase();
4324
+ if (k2 === "") return { chip: "", primary: true, fill: "paper", dashed: false };
4325
+ return SKIN[k2] ?? primary(k2.toUpperCase());
4326
+ }
4327
+ function skinFill(sk, accent = false) {
4328
+ if (accent) return "var(--accent-tint)";
4329
+ return sk.fill === "paper-2" ? "var(--paper-2)" : "var(--paper)";
4330
+ }
4331
+ function nodeGlyph(kind, x2, y, c) {
4332
+ const k2 = (kind ?? "").toLowerCase();
4333
+ if (k2 === "store" || k2 === "db" || k2 === "database" || k2 === "postgres" || k2 === "mysql" || k2 === "mongo" || k2 === "mongodb" || k2 === "dynamo") {
4334
+ return `<g stroke="${c}" stroke-width="1.3" fill="none"><ellipse cx="${x2 + 8}" cy="${y + 3}" rx="7" ry="3"/><path d="M${x2 + 1} ${y + 3} V ${y + 13}"/><path d="M${x2 + 15} ${y + 3} V ${y + 13}"/><path d="M${x2 + 1} ${y + 13} a 7 3 0 0 0 14 0"/></g>`;
4166
4335
  }
4167
- edge(e, n, t) {
4168
- let r5 = arguments.length === 1 ? Y(this._isDirected, e) : C(this._isDirected, e, n, t);
4169
- return this._edgeLabels[r5];
4336
+ if (k2 === "bucket" || k2 === "blob" || k2 === "object" || k2 === "s3") {
4337
+ return `<g stroke="${c}" stroke-width="1.3" fill="none"><ellipse cx="${x2 + 8}" cy="${y + 3}" rx="7" ry="2.5"/><path d="M${x2 + 1.5} ${y + 3} L ${x2 + 3.5} ${y + 14} L ${x2 + 12.5} ${y + 14} L ${x2 + 14.5} ${y + 3}"/></g>`;
4170
4338
  }
4171
- edgeAsObj(e, n, t) {
4172
- let r5 = arguments.length === 1 ? this.edge(e) : this.edge(e, n, t);
4173
- return typeof r5 != "object" ? { label: r5 } : r5;
4339
+ if (k2 === "queue" || k2 === "topic" || k2 === "mq" || k2 === "broker" || k2 === "sqs" || k2 === "rabbitmq") {
4340
+ return `<g stroke="${c}" stroke-width="1.6"><path d="M${x2 + 2} ${y + 1} V ${y + 14}"/><path d="M${x2 + 8} ${y + 1} V ${y + 14}"/><path d="M${x2 + 14} ${y + 1} V ${y + 14}"/></g>`;
4174
4341
  }
4175
- hasEdge(e, n, t) {
4176
- return (arguments.length === 1 ? Y(this._isDirected, e) : C(this._isDirected, e, n, t)) in this._edgeLabels;
4342
+ if (k2 === "firewall" || k2 === "waf" || k2 === "shield") {
4343
+ return `<path d="M${x2 + 8} ${y} L ${x2 + 15} ${y + 3} V ${y + 9} Q ${x2 + 15} ${y + 14} ${x2 + 8} ${y + 16} Q ${x2 + 1} ${y + 14} ${x2 + 1} ${y + 9} V ${y + 3} Z" fill="none" stroke="${c}" stroke-width="1.3"/>`;
4177
4344
  }
4178
- removeEdge(e, n, t) {
4179
- let r5 = arguments.length === 1 ? Y(this._isDirected, e) : C(this._isDirected, e, n, t), o = this._edgeObjs[r5];
4180
- if (o) {
4181
- let i = o.v, s = o.w;
4182
- delete this._edgeLabels[r5], delete this._edgeObjs[r5], Ee(this._preds[s], i), Ee(this._sucs[i], s), delete this._in[s][r5], delete this._out[i][r5], this._edgeCount--;
4183
- }
4184
- return this;
4345
+ if (k2 === "dns") {
4346
+ return `<g stroke="${c}" stroke-width="1.2" fill="none"><circle cx="${x2 + 8}" cy="${y + 8}" r="7"/><ellipse cx="${x2 + 8}" cy="${y + 8}" rx="3" ry="7"/><path d="M${x2 + 1.5} ${y + 8} H ${x2 + 14.5}"/></g>`;
4185
4347
  }
4186
- inEdges(e, n) {
4187
- return this.isDirected() ? this.filterEdges(this._in[e], e, n) : this.nodeEdges(e, n);
4348
+ if (k2 === "auth" || k2 === "identity" || k2 === "idp" || k2 === "iam" || k2 === "oauth" || k2 === "sso") {
4349
+ return `<g stroke="${c}" stroke-width="1.4" fill="none"><circle cx="${x2 + 5}" cy="${y + 8}" r="3.5"/><path d="M${x2 + 8.5} ${y + 8} H ${x2 + 15} M${x2 + 12.5} ${y + 8} V ${y + 11.5} M${x2 + 15} ${y + 8} V ${y + 10.5}"/></g>`;
4188
4350
  }
4189
- outEdges(e, n) {
4190
- return this.isDirected() ? this.filterEdges(this._out[e], e, n) : this.nodeEdges(e, n);
4351
+ if (k2 === "monitor" || k2 === "observability" || k2 === "metrics" || k2 === "logs" || k2 === "tracing" || k2 === "apm") {
4352
+ return `<path d="M${x2} ${y + 9} H ${x2 + 4} L ${x2 + 6.5} ${y + 3} L ${x2 + 9.5} ${y + 13} L ${x2 + 12} ${y + 9} H ${x2 + 16}" fill="none" stroke="${c}" stroke-width="1.5" stroke-linejoin="round"/>`;
4191
4353
  }
4192
- nodeEdges(e, n) {
4193
- if (e in this._nodes) return this.filterEdges({ ...this._in[e], ...this._out[e] }, e, n);
4354
+ if (k2 === "scheduler" || k2 === "cron" || k2 === "job") {
4355
+ return `<g stroke="${c}" stroke-width="1.3" fill="none"><circle cx="${x2 + 8}" cy="${y + 8}" r="7"/><path d="M${x2 + 8} ${y + 4} V ${y + 8} L ${x2 + 11.5} ${y + 10}"/></g>`;
4194
4356
  }
4195
- _removeFromParentsChildList(e) {
4196
- delete this._children[this._parent[e]][e];
4357
+ if (k2 === "stream" || k2 === "kafka" || k2 === "kinesis") {
4358
+ const wave = (dy) => `<path d="M${x2 + 1} ${y + 4 + dy} q 3.5 -3 7 0 t 7 0" fill="none" stroke="${c}" stroke-width="1.4"/>`;
4359
+ return `<g>${wave(0)}${wave(4.5)}${wave(9)}</g>`;
4197
4360
  }
4198
- filterEdges(e, n, t) {
4199
- if (!e) return;
4200
- let r5 = Object.values(e);
4201
- return t ? r5.filter((o) => o.v === n && o.w === t || o.v === t && o.w === n) : r5;
4361
+ if (k2 === "warehouse" || k2 === "lake") {
4362
+ return `<g stroke="${c}" stroke-width="1.3" fill="none"><ellipse cx="${x2 + 8}" cy="${y + 3}" rx="7" ry="3"/><path d="M${x2 + 1} ${y + 3} V ${y + 13}"/><path d="M${x2 + 15} ${y + 3} V ${y + 13}"/><path d="M${x2 + 1} ${y + 8} a 7 3 0 0 0 14 0"/><path d="M${x2 + 1} ${y + 13} a 7 3 0 0 0 14 0"/></g>`;
4202
4363
  }
4203
- };
4204
- function me(e, n) {
4205
- e[n] ? e[n]++ : e[n] = 1;
4206
- }
4207
- function Ee(e, n) {
4208
- e[n] !== void 0 && !--e[n] && delete e[n];
4209
- }
4210
- function C(e, n, t, r5) {
4211
- let o = "" + n, i = "" + t;
4212
- if (!e && o > i) {
4213
- let s = o;
4214
- o = i, i = s;
4364
+ if (k2 === "search" || k2 === "index") {
4365
+ return `<g stroke="${c}" stroke-width="1.4" fill="none"><circle cx="${x2 + 6.5}" cy="${y + 6.5}" r="5"/><path d="M${x2 + 10.5} ${y + 10.5} L ${x2 + 15} ${y + 15}"/></g>`;
4215
4366
  }
4216
- return o + "" + i + "" + (r5 === void 0 ? "\0" : r5);
4217
- }
4218
- function gn(e, n, t, r5) {
4219
- let o = "" + n, i = "" + t;
4220
- if (!e && o > i) {
4221
- let a = o;
4222
- o = i, i = a;
4367
+ if (k2 === "ml" || k2 === "model" || k2 === "llm" || k2 === "agent" || k2 === "ai") {
4368
+ return `<path d="M${x2 + 8} ${y + 1} L ${x2 + 9.8} ${y + 6.2} L ${x2 + 15} ${y + 8} L ${x2 + 9.8} ${y + 9.8} L ${x2 + 8} ${y + 15} L ${x2 + 6.2} ${y + 9.8} L ${x2 + 1} ${y + 8} L ${x2 + 6.2} ${y + 6.2} Z" fill="${c}"/>`;
4223
4369
  }
4224
- let s = { v: o, w: i };
4225
- return r5 && (s.name = r5), s;
4226
- }
4227
- function Y(e, n) {
4228
- return C(e, n.v, n.w, n.name);
4229
- }
4230
- var pn = "4.0.1";
4231
- var ye = {};
4232
- Le(ye, { read: () => yn, write: () => mn });
4233
- function mn(e) {
4234
- let n = { options: { directed: e.isDirected(), multigraph: e.isMultigraph(), compound: e.isCompound() }, nodes: En(e), edges: Ln(e) }, t = e.graph();
4235
- return t !== void 0 && (n.value = structuredClone(t)), n;
4236
- }
4237
- function En(e) {
4238
- return e.nodes().map((n) => {
4239
- let t = e.node(n), r5 = e.parent(n), o = { v: n };
4240
- return t !== void 0 && (o.value = t), r5 !== void 0 && (o.parent = r5), o;
4241
- });
4242
- }
4243
- function Ln(e) {
4244
- return e.edges().map((n) => {
4245
- let t = e.edge(n), r5 = { v: n.v, w: n.w };
4246
- return n.name !== void 0 && (r5.name = n.name), t !== void 0 && (r5.value = t), r5;
4247
- });
4248
- }
4249
- function yn(e) {
4250
- let n = new p(e.options);
4251
- return e.value !== void 0 && n.setGraph(e.value), e.nodes.forEach((t) => {
4252
- n.setNode(t.v, t.value), t.parent && n.setParent(t.v, t.parent);
4253
- }), e.edges.forEach((t) => {
4254
- n.setEdge({ v: t.v, w: t.w, name: t.name }, t.value);
4255
- }), n;
4256
- }
4257
- var R = {};
4258
- Le(R, { CycleException: () => D, bellmanFord: () => we, components: () => Gn, dijkstra: () => F, dijkstraAll: () => _n, findCycles: () => xn, floydWarshall: () => On, isAcyclic: () => Cn, postorder: () => Pn, preorder: () => Mn, prim: () => jn, shortestPaths: () => Sn, tarjan: () => Ge, topsort: () => ke });
4259
- var wn = () => 1;
4260
- function we(e, n, t, r5) {
4261
- return Nn(e, String(n), t || wn, r5 || function(o) {
4262
- return e.outEdges(o);
4263
- });
4264
- }
4265
- function Nn(e, n, t, r5) {
4266
- let o = {}, i, s = 0, a = e.nodes(), d = function(c) {
4267
- let h = t(c);
4268
- o[c.v].distance + h < o[c.w].distance && (o[c.w] = { distance: o[c.v].distance + h, predecessor: c.v }, i = true);
4269
- }, l = function() {
4270
- a.forEach(function(c) {
4271
- r5(c).forEach(function(h) {
4272
- let f = h.v === c ? h.v : h.w, g = f === h.v ? h.w : h.v;
4273
- d({ v: f, w: g });
4274
- });
4275
- });
4276
- };
4277
- a.forEach(function(c) {
4278
- let h = c === n ? 0 : Number.POSITIVE_INFINITY;
4279
- o[c] = { distance: h, predecessor: "" };
4280
- });
4281
- let u = a.length;
4282
- for (let c = 1; c < u && (i = false, s++, l(), !!i); c++) ;
4283
- if (s === u - 1 && (i = false, l(), i)) throw new Error("The graph contains a negative weight cycle");
4284
- return o;
4285
- }
4286
- function Gn(e) {
4287
- let n = {}, t = [], r5;
4288
- function o(i) {
4289
- i in n || (n[i] = true, r5.push(i), e.successors(i).forEach(o), e.predecessors(i).forEach(o));
4370
+ if (k2 === "user" || k2 === "person" || k2 === "actor") {
4371
+ return `<g fill="${c}"><circle cx="${x2 + 8}" cy="${y + 4.5}" r="3.5"/><path d="M ${x2 + 2} ${y + 15} a 6 6.5 0 0 1 12 0 z"/></g>`;
4290
4372
  }
4291
- return e.nodes().forEach(function(i) {
4292
- r5 = [], o(i), r5.length && t.push(r5);
4293
- }), t;
4294
- }
4295
- var Ne = class {
4296
- constructor() {
4297
- this._arr = [], this._keyIndices = {};
4373
+ if (k2 === "browser" || k2 === "web") {
4374
+ return `<g stroke="${c}" stroke-width="1.3" fill="none"><rect x="${x2 + 1}" y="${y + 2}" width="14" height="12" rx="2"/><path d="M${x2 + 1} ${y + 6} H ${x2 + 15}"/></g>`;
4298
4375
  }
4299
- size() {
4300
- return this._arr.length;
4376
+ if (k2 === "mobile") {
4377
+ return `<g stroke="${c}" stroke-width="1.3" fill="none"><rect x="${x2 + 4}" y="${y + 1}" width="8" height="14" rx="2"/><path d="M${x2 + 7} ${y + 12.5} H ${x2 + 9}"/></g>`;
4301
4378
  }
4302
- keys() {
4303
- return this._arr.map((e) => e.key);
4379
+ if (k2 === "vm" || k2 === "server" || k2 === "host") {
4380
+ return `<g stroke="${c}" stroke-width="1.3" fill="none"><rect x="${x2 + 2}" y="${y + 2}" width="12" height="5" rx="1.2"/><rect x="${x2 + 2}" y="${y + 9}" width="12" height="5" rx="1.2"/><path d="M${x2 + 4.5} ${y + 4.5} H ${x2 + 7} M${x2 + 4.5} ${y + 11.5} H ${x2 + 7}"/></g>`;
4304
4381
  }
4305
- has(e) {
4306
- return e in this._keyIndices;
4382
+ if (k2 === "secrets" || k2 === "vault" || k2 === "kms") {
4383
+ return `<g stroke="${c}" stroke-width="1.3" fill="none"><rect x="${x2 + 3}" y="${y + 7}" width="10" height="8" rx="1.5"/><path d="M${x2 + 5} ${y + 7} V ${y + 5} a 3 3 0 0 1 6 0 V ${y + 7}"/></g>`;
4307
4384
  }
4308
- priority(e) {
4309
- let n = this._keyIndices[e];
4310
- if (n !== void 0) return this._arr[n].priority;
4385
+ if (k2 === "notification" || k2 === "webhook") {
4386
+ return `<g stroke="${c}" stroke-width="1.3" fill="none"><path d="M${x2 + 3} ${y + 11} a 5 5 0 0 1 1.6 -3.6 V ${y + 5} a 3.4 3.4 0 0 1 6.8 0 v 2.4 a 5 5 0 0 1 1.6 3.6 z"/><path d="M${x2 + 6.5} ${y + 13.5} a 1.5 1.5 0 0 0 3 0"/></g>`;
4311
4387
  }
4312
- min() {
4313
- if (this.size() === 0) throw new Error("Queue underflow");
4314
- return this._arr[0].key;
4388
+ if (k2 === "email" || k2 === "sms") {
4389
+ return `<g stroke="${c}" stroke-width="1.3" fill="none"><rect x="${x2 + 1}" y="${y + 3}" width="14" height="10" rx="1.5"/><path d="M${x2 + 1.5} ${y + 4} L ${x2 + 8} ${y + 9} L ${x2 + 14.5} ${y + 4}"/></g>`;
4315
4390
  }
4316
- add(e, n) {
4317
- let t = this._keyIndices, r5 = String(e);
4318
- if (!(r5 in t)) {
4319
- let o = this._arr, i = o.length;
4320
- return t[r5] = i, o.push({ key: r5, priority: n }), this._decrease(i), true;
4321
- }
4322
- return false;
4391
+ if (k2 === "registry") {
4392
+ return `<g stroke="${c}" stroke-width="1.2" fill="none"><rect x="${x2 + 1}" y="${y + 8}" width="6" height="6" rx="1"/><rect x="${x2 + 9}" y="${y + 8}" width="6" height="6" rx="1"/><rect x="${x2 + 5}" y="${y + 1}" width="6" height="6" rx="1"/></g>`;
4323
4393
  }
4324
- removeMin() {
4325
- this._swap(0, this._arr.length - 1);
4326
- let e = this._arr.pop();
4327
- return delete this._keyIndices[e.key], this._heapify(0), e.key;
4394
+ if (k2 === "ci" || k2 === "cicd" || k2 === "pipeline") {
4395
+ return `<g stroke="${c}" stroke-width="1.3" fill="none"><circle cx="${x2 + 8}" cy="${y + 8}" r="7"/><path d="M${x2 + 6} ${y + 5} L ${x2 + 11.5} ${y + 8} L ${x2 + 6} ${y + 11} Z" fill="${c}" stroke="none"/></g>`;
4328
4396
  }
4329
- decrease(e, n) {
4330
- let t = this._keyIndices[e];
4331
- if (t === void 0) throw new Error(`Key not found: ${e}`);
4332
- let r5 = this._arr[t].priority;
4333
- if (n > r5) throw new Error(`New priority is greater than current priority. Key: ${e} Old: ${r5} New: ${n}`);
4334
- this._arr[t].priority = n, this._decrease(t);
4397
+ if (k2 === "git" || k2 === "repo" || k2 === "scm") {
4398
+ return `<g stroke="${c}" stroke-width="1.3" fill="none"><circle cx="${x2 + 4}" cy="${y + 3.5}" r="2.5"/><circle cx="${x2 + 4}" cy="${y + 12.5}" r="2.5"/><circle cx="${x2 + 12}" cy="${y + 6}" r="2.5"/><path d="M${x2 + 4} ${y + 6} V ${y + 10} M${x2 + 4} ${y + 8} q 0 -2 3 -2 h 2.5"/></g>`;
4335
4399
  }
4336
- _heapify(e) {
4337
- let n = this._arr, t = 2 * e, r5 = t + 1, o = e;
4338
- t < n.length && (o = n[t].priority < n[o].priority ? t : o, r5 < n.length && (o = n[r5].priority < n[o].priority ? r5 : o), o !== e && (this._swap(e, o), this._heapify(o)));
4400
+ if (k2 === "device" || k2 === "iot") {
4401
+ return `<g stroke="${c}" stroke-width="1.2" fill="none"><rect x="${x2 + 4}" y="${y + 4}" width="8" height="8" rx="1.5"/><path d="M${x2 + 6} ${y + 4} V ${y + 1} M${x2 + 10} ${y + 4} V ${y + 1} M${x2 + 6} ${y + 15} V ${y + 12} M${x2 + 10} ${y + 15} V ${y + 12} M${x2 + 4} ${y + 6} H ${x2 + 1} M${x2 + 4} ${y + 10} H ${x2 + 1} M${x2 + 15} ${y + 6} H ${x2 + 12} M${x2 + 15} ${y + 10} H ${x2 + 12}"/></g>`;
4339
4402
  }
4340
- _decrease(e) {
4341
- let n = this._arr, t = n[e].priority, r5;
4342
- for (; e !== 0 && (r5 = e >> 1, !(n[r5].priority < t)); ) this._swap(e, r5), e = r5;
4403
+ if (k2 === "analytics" || k2 === "bi") {
4404
+ return `<g fill="${c}"><rect x="${x2 + 1}" y="${y + 9}" width="3.4" height="6" rx="0.8"/><rect x="${x2 + 6.3}" y="${y + 5}" width="3.4" height="10" rx="0.8"/><rect x="${x2 + 11.6}" y="${y + 1}" width="3.4" height="14" rx="0.8"/></g>`;
4343
4405
  }
4344
- _swap(e, n) {
4345
- let t = this._arr, r5 = this._keyIndices, o = t[e], i = t[n];
4346
- t[e] = i, t[n] = o, r5[i.key] = e, r5[o.key] = n;
4406
+ if (k2 === "config" || k2 === "settings") {
4407
+ return `<g stroke="${c}" stroke-width="1.3" fill="none"><circle cx="${x2 + 8}" cy="${y + 8}" r="4"/><path d="M${x2 + 8} ${y + 1} V ${y + 3.5} M${x2 + 8} ${y + 12.5} V ${y + 15} M${x2 + 1} ${y + 8} H ${x2 + 3.5} M${x2 + 12.5} ${y + 8} H ${x2 + 15} M${x2 + 3} ${y + 3} L ${x2 + 5} ${y + 5} M${x2 + 11} ${y + 11} L ${x2 + 13} ${y + 13} M${x2 + 13} ${y + 3} L ${x2 + 11} ${y + 5} M${x2 + 5} ${y + 11} L ${x2 + 3} ${y + 13}"/></g>`;
4347
4408
  }
4348
- };
4349
- var kn = () => 1;
4350
- function F(e, n, t, r5) {
4351
- let o = function(i) {
4352
- return e.outEdges(i);
4353
- };
4354
- return vn(e, String(n), t || kn, r5 || o);
4355
- }
4356
- function vn(e, n, t, r5) {
4357
- let o = {}, i = new Ne(), s, a, d = function(l) {
4358
- let u = l.v !== s ? l.v : l.w, c = o[u], h = t(l), f = a.distance + h;
4359
- if (h < 0) throw new Error("dijkstra does not allow negative edge weights. Bad edge: " + l + " Weight: " + h);
4360
- f < c.distance && (c.distance = f, c.predecessor = s, i.decrease(u, f));
4361
- };
4362
- for (e.nodes().forEach(function(l) {
4363
- let u = l === n ? 0 : Number.POSITIVE_INFINITY;
4364
- o[l] = { distance: u, predecessor: "" }, i.add(l, u);
4365
- }); i.size() > 0 && (s = i.removeMin(), a = o[s], a.distance !== Number.POSITIVE_INFINITY); ) r5(s).forEach(d);
4366
- return o;
4367
- }
4368
- function _n(e, n, t) {
4369
- return e.nodes().reduce(function(r5, o) {
4370
- return r5[o] = F(e, o, n, t), r5;
4371
- }, {});
4372
- }
4373
- function Ge(e) {
4374
- let n = 0, t = [], r5 = {}, o = [];
4375
- function i(s) {
4376
- let a = r5[s] = { onStack: true, lowlink: n, index: n++ };
4377
- if (t.push(s), e.successors(s).forEach(function(d) {
4378
- d in r5 ? r5[d].onStack && (a.lowlink = Math.min(a.lowlink, r5[d].index)) : (i(d), a.lowlink = Math.min(a.lowlink, r5[d].lowlink));
4379
- }), a.lowlink === a.index) {
4380
- let d = [], l;
4381
- do
4382
- l = t.pop(), r5[l].onStack = false, d.push(l);
4383
- while (s !== l);
4384
- o.push(d);
4385
- }
4409
+ if (k2 === "cache" || k2 === "redis" || k2 === "memcached") {
4410
+ const slab = (dy) => `<path d="M${x2 + 1} ${y + 5 + dy} L${x2 + 8} ${y + 2 + dy} L${x2 + 15} ${y + 5 + dy} L${x2 + 8} ${y + 8 + dy} Z" fill="none" stroke="${c}" stroke-width="1.2"/>`;
4411
+ return `<g>${slab(0)}${slab(3.5)}${slab(7)}</g>`;
4386
4412
  }
4387
- return e.nodes().forEach(function(s) {
4388
- s in r5 || i(s);
4389
- }), o;
4390
- }
4391
- function xn(e) {
4392
- return Ge(e).filter(function(n) {
4393
- return n.length > 1 || n.length === 1 && e.hasEdge(n[0], n[0]);
4394
- });
4395
- }
4396
- var Tn = () => 1;
4397
- function On(e, n, t) {
4398
- return In(e, n || Tn, t || function(r5) {
4399
- return e.outEdges(r5);
4400
- });
4401
- }
4402
- function In(e, n, t) {
4403
- let r5 = {}, o = e.nodes();
4404
- return o.forEach(function(i) {
4405
- r5[i] = {}, r5[i][i] = { distance: 0, predecessor: "" }, o.forEach(function(s) {
4406
- i !== s && (r5[i][s] = { distance: Number.POSITIVE_INFINITY, predecessor: "" });
4407
- }), t(i).forEach(function(s) {
4408
- let a = s.v === i ? s.w : s.v, d = n(s);
4409
- r5[i][a] = { distance: d, predecessor: i };
4410
- });
4411
- }), o.forEach(function(i) {
4412
- let s = r5[i];
4413
- o.forEach(function(a) {
4414
- let d = r5[a];
4415
- o.forEach(function(l) {
4416
- let u = d[i], c = s[l], h = d[l], f = u.distance + c.distance;
4417
- f < h.distance && (h.distance = f, h.predecessor = c.predecessor);
4418
- });
4419
- });
4420
- }), r5;
4421
- }
4422
- var D = class extends Error {
4423
- constructor(...e) {
4424
- super(...e);
4413
+ if (k2 === "function" || k2 === "lambda") {
4414
+ return `<text x="${x2 + 7}" y="${y + 14}" font-family="Georgia, serif" font-size="17" font-style="italic" font-weight="700" fill="${c}" text-anchor="middle">\u0192</text>`;
4425
4415
  }
4426
- };
4427
- function ke(e) {
4428
- let n = {}, t = {}, r5 = [];
4429
- function o(i) {
4430
- if (i in t) throw new D();
4431
- i in n || (t[i] = true, n[i] = true, e.predecessors(i).forEach(o), delete t[i], r5.push(i));
4416
+ if (k2 === "cdn" || k2 === "external") {
4417
+ return `<path d="M${x2 + 3} ${y + 13} a 4 4 0 0 1 0.5 -8 a 5 5 0 0 1 9.5 1.2 a 3 3 0 0 1 1 6.8 z" fill="none" stroke="${c}" stroke-width="1.3"/>`;
4432
4418
  }
4433
- if (e.sinks().forEach(o), Object.keys(n).length !== e.nodeCount()) throw new D();
4434
- return r5;
4435
- }
4436
- function Cn(e) {
4437
- try {
4438
- ke(e);
4439
- } catch (n) {
4440
- if (n instanceof D) return false;
4441
- throw n;
4419
+ if (k2 === "gateway" || k2 === "lb" || k2 === "proxy") {
4420
+ return `<g stroke="${c}" stroke-width="1.5" fill="none"><path d="M${x2 + 2} ${y + 1} L ${x2 + 8} ${y + 7} L ${x2 + 2} ${y + 13}"/><path d="M${x2 + 8} ${y + 1} L ${x2 + 14} ${y + 7} L ${x2 + 8} ${y + 13}"/></g>`;
4442
4421
  }
4443
- return true;
4444
- }
4445
- function Rn(e, n, t, r5, o) {
4446
- Array.isArray(n) || (n = [n]);
4447
- let i = ((a) => {
4448
- var d;
4449
- return (d = e.isDirected() ? e.successors(a) : e.neighbors(a)) != null ? d : [];
4450
- }), s = {};
4451
- return n.forEach(function(a) {
4452
- if (!e.hasNode(a)) throw new Error("Graph does not have node: " + a);
4453
- o = ve(e, a, t === "post", s, i, r5, o);
4454
- }), o;
4455
- }
4456
- function ve(e, n, t, r5, o, i, s) {
4457
- return n in r5 || (r5[n] = true, t || (s = i(s, n)), o(n).forEach(function(a) {
4458
- s = ve(e, a, t, r5, o, i, s);
4459
- }), t && (s = i(s, n))), s;
4460
- }
4461
- function _e(e, n, t) {
4462
- return Rn(e, n, t, function(r5, o) {
4463
- return r5.push(o), r5;
4464
- }, []);
4465
- }
4466
- function Pn(e, n) {
4467
- return _e(e, n, "post");
4468
- }
4469
- function Mn(e, n) {
4470
- return _e(e, n, "pre");
4422
+ if (k2 === "service" || k2 === "microservice" || k2 === "compute" || k2 === "container" || k2 === "worker" || k2 === "etl") {
4423
+ return `<g stroke="${c}" stroke-width="1.3"><rect x="${x2 + 4}" y="${y + 1}" width="11" height="11" rx="1.5" fill="none"/><rect x="${x2 + 1}" y="${y + 4}" width="11" height="11" rx="1.5" fill="var(--paper)"/></g>`;
4424
+ }
4425
+ return hasGlyph(k2) ? cloudGlyph(k2, x2, y, c) : "";
4471
4426
  }
4472
- function jn(e, n) {
4473
- let t = new p(), r5 = {}, o = new Ne(), i;
4474
- function s(d) {
4475
- let l = d.v === i ? d.w : d.v, u = o.priority(l);
4476
- if (u !== void 0) {
4477
- let c = n(d);
4478
- c < u && (r5[l] = i, o.decrease(l, c));
4479
- }
4427
+ var SKIN_EDGE = {
4428
+ solid: { stroke: "var(--muted)", sw: 1.5, dash: "", marker: "skArrow", err: false },
4429
+ dashed: { stroke: "var(--muted)", sw: 1.5, dash: "5 4", marker: "skOpen", err: false },
4430
+ forbidden: { stroke: "var(--negative)", sw: 1.5, dash: "4 3", marker: "skErr", err: true },
4431
+ error: { stroke: "var(--negative)", sw: 1.5, dash: "", marker: "skErr", err: true }
4432
+ };
4433
+
4434
+ // ../../node_modules/.pnpm/@dagrejs+dagre@3.0.0/node_modules/@dagrejs/dagre/dist/dagre.esm.js
4435
+ var ge = Object.defineProperty;
4436
+ var hn = (e, n, t) => n in e ? ge(e, n, { enumerable: true, configurable: true, writable: true, value: t }) : e[n] = t;
4437
+ var fn = (e, n) => {
4438
+ for (var t in n) ge(e, t, { get: n[t], enumerable: true });
4439
+ };
4440
+ var pe = (e, n, t) => hn(e, n + "" , t);
4441
+ var z = {};
4442
+ fn(z, { Graph: () => p, alg: () => R, json: () => ye, version: () => pn });
4443
+ var bn = Object.defineProperty;
4444
+ var Le = (e, n) => {
4445
+ for (var t in n) bn(e, t, { get: n[t], enumerable: true });
4446
+ };
4447
+ var p = class {
4448
+ constructor(e) {
4449
+ this._isDirected = true, this._isMultigraph = false, this._isCompound = false, this._nodes = {}, this._in = {}, this._preds = {}, this._out = {}, this._sucs = {}, this._edgeObjs = {}, this._edgeLabels = {}, this._nodeCount = 0, this._edgeCount = 0, this._defaultNodeLabelFn = () => {
4450
+ }, this._defaultEdgeLabelFn = () => {
4451
+ }, e && (this._isDirected = "directed" in e ? e.directed : true, this._isMultigraph = "multigraph" in e ? e.multigraph : false, this._isCompound = "compound" in e ? e.compound : false), this._isCompound && (this._parent = {}, this._children = {}, this._children["\0"] = {});
4480
4452
  }
4481
- if (e.nodeCount() === 0) return t;
4482
- e.nodes().forEach(function(d) {
4483
- o.add(d, Number.POSITIVE_INFINITY), t.setNode(d);
4484
- }), o.decrease(e.nodes()[0], 0);
4485
- let a = false;
4486
- for (; o.size() > 0; ) {
4487
- if (i = o.removeMin(), i in r5) t.setEdge(i, r5[i]);
4488
- else {
4489
- if (a) throw new Error("Input graph is not connected: " + e);
4490
- a = true;
4491
- }
4492
- e.nodeEdges(i).forEach(s);
4453
+ isDirected() {
4454
+ return this._isDirected;
4493
4455
  }
4494
- return t;
4495
- }
4496
- function Sn(e, n, t, r5) {
4497
- return Fn(e, n, t, r5 != null ? r5 : ((o) => {
4498
- let i = e.outEdges(o);
4499
- return i != null ? i : [];
4500
- }));
4501
- }
4502
- function Fn(e, n, t, r5) {
4503
- if (t === void 0) return F(e, n, t, r5);
4504
- let o = false, i = e.nodes();
4505
- for (let s = 0; s < i.length; s++) {
4506
- let a = r5(i[s]);
4507
- for (let d = 0; d < a.length; d++) {
4508
- let l = a[d], u = l.v === i[s] ? l.v : l.w, c = u === l.v ? l.w : l.v;
4509
- t({ v: u, w: c }) < 0 && (o = true);
4510
- }
4511
- if (o) return we(e, n, t, r5);
4456
+ isMultigraph() {
4457
+ return this._isMultigraph;
4512
4458
  }
4513
- return F(e, n, t, r5);
4514
- }
4515
- function w(e, n, t, r5) {
4516
- let o = r5;
4517
- for (; e.hasNode(o); ) o = j(r5);
4518
- return t.dummy = n, e.setNode(o, t), o;
4519
- }
4520
- function xe(e) {
4521
- let n = new p().setGraph(e.graph());
4522
- return e.nodes().forEach((t) => n.setNode(t, e.node(t))), e.edges().forEach((t) => {
4523
- let r5 = n.edge(t.v, t.w) || { weight: 0, minlen: 1 }, o = e.edge(t);
4524
- n.setEdge(t.v, t.w, { weight: r5.weight + o.weight, minlen: Math.max(r5.minlen, o.minlen) });
4525
- }), n;
4526
- }
4527
- function A(e) {
4528
- let n = new p({ multigraph: e.isMultigraph() }).setGraph(e.graph());
4529
- return e.nodes().forEach((t) => {
4530
- e.children(t).length || n.setNode(t, e.node(t));
4531
- }), e.edges().forEach((t) => {
4532
- n.setEdge(t, e.edge(t));
4533
- }), n;
4534
- }
4535
- function H(e, n) {
4536
- let t = e.x, r5 = e.y, o = n.x - t, i = n.y - r5, s = e.width / 2, a = e.height / 2;
4537
- if (!o && !i) throw new Error("Not possible to find intersection inside of the rectangle");
4538
- let d, l;
4539
- return Math.abs(i) * s > Math.abs(o) * a ? (i < 0 && (a = -a), d = a * o / i, l = a) : (o < 0 && (s = -s), d = s, l = s * i / o), { x: t + d, y: r5 + l };
4540
- }
4541
- function N(e) {
4542
- let n = k(X(e) + 1).map(() => []);
4543
- return e.nodes().forEach((t) => {
4544
- let r5 = e.node(t), o = r5.rank;
4545
- o !== void 0 && (n[o] || (n[o] = []), n[o][r5.order] = t);
4546
- }), n;
4547
- }
4548
- function Te(e) {
4549
- let n = e.nodes().map((r5) => {
4550
- let o = e.node(r5).rank;
4551
- return o === void 0 ? Number.MAX_VALUE : o;
4552
- }), t = L(Math.min, n);
4553
- e.nodes().forEach((r5) => {
4554
- let o = e.node(r5);
4555
- Object.hasOwn(o, "rank") && (o.rank -= t);
4556
- });
4557
- }
4558
- function Oe(e) {
4559
- let n = e.nodes().map((s) => e.node(s).rank).filter((s) => s !== void 0), t = L(Math.min, n), r5 = [];
4560
- e.nodes().forEach((s) => {
4561
- let a = e.node(s).rank - t;
4562
- r5[a] || (r5[a] = []), r5[a].push(s);
4563
- });
4564
- let o = 0, i = e.graph().nodeRankFactor;
4565
- Array.from(r5).forEach((s, a) => {
4566
- s === void 0 && a % i !== 0 ? --o : s !== void 0 && o && s.forEach((d) => e.node(d).rank += o);
4567
- });
4568
- }
4569
- function q(e, n, t, r5) {
4570
- let o = { width: 0, height: 0 };
4571
- return arguments.length >= 4 && (o.rank = t, o.order = r5), w(e, "border", o, n);
4572
- }
4573
- function Dn(e, n = Ie) {
4574
- let t = [];
4575
- for (let r5 = 0; r5 < e.length; r5 += n) {
4576
- let o = e.slice(r5, r5 + n);
4577
- t.push(o);
4459
+ isCompound() {
4460
+ return this._isCompound;
4578
4461
  }
4579
- return t;
4580
- }
4581
- var Ie = 65535;
4582
- function L(e, n) {
4583
- if (n.length > Ie) {
4584
- let t = Dn(n);
4585
- return e(...t.map((r5) => e(...r5)));
4586
- } else return e(...n);
4587
- }
4588
- function X(e) {
4589
- let t = e.nodes().map((r5) => {
4590
- let o = e.node(r5).rank;
4591
- return o === void 0 ? Number.MIN_VALUE : o;
4592
- });
4593
- return L(Math.max, t);
4594
- }
4595
- function Ce(e, n) {
4596
- let t = { lhs: [], rhs: [] };
4597
- return e.forEach((r5) => {
4598
- n(r5) ? t.lhs.push(r5) : t.rhs.push(r5);
4599
- }), t;
4600
- }
4601
- function P(e, n) {
4602
- let t = Date.now();
4603
- try {
4604
- return n();
4605
- } finally {
4606
- console.log(e + " time: " + (Date.now() - t) + "ms");
4462
+ setGraph(e) {
4463
+ return this._label = e, this;
4607
4464
  }
4608
- }
4609
- function M(e, n) {
4610
- return n();
4611
- }
4612
- var An = 0;
4613
- function j(e) {
4614
- let n = ++An;
4615
- return e + ("" + n);
4616
- }
4617
- function k(e, n, t = 1) {
4618
- n == null && (n = e, e = 0);
4619
- let r5 = (i) => i < n;
4620
- t < 0 && (r5 = (i) => n < i);
4621
- let o = [];
4622
- for (let i = e; r5(i); i += t) o.push(i);
4623
- return o;
4624
- }
4625
- function T(e, n) {
4626
- let t = {};
4627
- for (let r5 of n) e[r5] !== void 0 && (t[r5] = e[r5]);
4628
- return t;
4629
- }
4630
- function O(e, n) {
4631
- let t;
4632
- return typeof n == "string" ? t = (r5) => r5[n] : t = n, Object.entries(e).reduce((r5, [o, i]) => (r5[o] = t(i, o), r5), {});
4633
- }
4634
- function Re(e, n) {
4635
- return e.reduce((t, r5, o) => (t[r5] = n[o], t), {});
4636
- }
4637
- var _ = "\0";
4638
- var U = "3.0.0";
4639
- var K = class {
4640
- constructor() {
4641
- pe(this, "_sentinel");
4642
- let n = {};
4643
- n._next = n._prev = n, this._sentinel = n;
4465
+ graph() {
4466
+ return this._label;
4644
4467
  }
4645
- dequeue() {
4646
- let n = this._sentinel, t = n._prev;
4647
- if (t !== n) return Pe(t), t;
4468
+ setDefaultNodeLabel(e) {
4469
+ return typeof e != "function" ? this._defaultNodeLabelFn = () => e : this._defaultNodeLabelFn = e, this;
4648
4470
  }
4649
- enqueue(n) {
4650
- let t = this._sentinel;
4651
- n._prev && n._next && Pe(n), n._next = t._next, t._next._prev = n, t._next = n, n._prev = t;
4471
+ nodeCount() {
4472
+ return this._nodeCount;
4652
4473
  }
4653
- toString() {
4654
- let n = [], t = this._sentinel, r5 = t._prev;
4655
- for (; r5 !== t; ) n.push(JSON.stringify(r5, Vn)), r5 = r5._prev;
4656
- return "[" + n.join(", ") + "]";
4474
+ nodes() {
4475
+ return Object.keys(this._nodes);
4657
4476
  }
4658
- };
4659
- function Pe(e) {
4660
- e._prev._next = e._next, e._next._prev = e._prev, delete e._next, delete e._prev;
4477
+ sources() {
4478
+ return this.nodes().filter((e) => Object.keys(this._in[e]).length === 0);
4479
+ }
4480
+ sinks() {
4481
+ return this.nodes().filter((e) => Object.keys(this._out[e]).length === 0);
4482
+ }
4483
+ setNodes(e, n) {
4484
+ return e.forEach((t) => {
4485
+ n !== void 0 ? this.setNode(t, n) : this.setNode(t);
4486
+ }), this;
4487
+ }
4488
+ setNode(e, n) {
4489
+ return e in this._nodes ? (arguments.length > 1 && (this._nodes[e] = n), this) : (this._nodes[e] = arguments.length > 1 ? n : this._defaultNodeLabelFn(e), this._isCompound && (this._parent[e] = "\0", this._children[e] = {}, this._children["\0"][e] = true), this._in[e] = {}, this._preds[e] = {}, this._out[e] = {}, this._sucs[e] = {}, ++this._nodeCount, this);
4490
+ }
4491
+ node(e) {
4492
+ return this._nodes[e];
4493
+ }
4494
+ hasNode(e) {
4495
+ return e in this._nodes;
4496
+ }
4497
+ removeNode(e) {
4498
+ if (e in this._nodes) {
4499
+ let n = (t) => this.removeEdge(this._edgeObjs[t]);
4500
+ delete this._nodes[e], this._isCompound && (this._removeFromParentsChildList(e), delete this._parent[e], this.children(e).forEach((t) => {
4501
+ this.setParent(t);
4502
+ }), delete this._children[e]), Object.keys(this._in[e]).forEach(n), delete this._in[e], delete this._preds[e], Object.keys(this._out[e]).forEach(n), delete this._out[e], delete this._sucs[e], --this._nodeCount;
4503
+ }
4504
+ return this;
4505
+ }
4506
+ setParent(e, n) {
4507
+ if (!this._isCompound) throw new Error("Cannot set parent in a non-compound graph");
4508
+ if (n === void 0) n = "\0";
4509
+ else {
4510
+ n += "";
4511
+ for (let t = n; t !== void 0; t = this.parent(t)) if (t === e) throw new Error("Setting " + n + " as parent of " + e + " would create a cycle");
4512
+ this.setNode(n);
4513
+ }
4514
+ return this.setNode(e), this._removeFromParentsChildList(e), this._parent[e] = n, this._children[n][e] = true, this;
4515
+ }
4516
+ parent(e) {
4517
+ if (this._isCompound) {
4518
+ let n = this._parent[e];
4519
+ if (n !== "\0") return n;
4520
+ }
4521
+ }
4522
+ children(e = "\0") {
4523
+ if (this._isCompound) {
4524
+ let n = this._children[e];
4525
+ if (n) return Object.keys(n);
4526
+ } else {
4527
+ if (e === "\0") return this.nodes();
4528
+ if (this.hasNode(e)) return [];
4529
+ }
4530
+ return [];
4531
+ }
4532
+ predecessors(e) {
4533
+ let n = this._preds[e];
4534
+ if (n) return Object.keys(n);
4535
+ }
4536
+ successors(e) {
4537
+ let n = this._sucs[e];
4538
+ if (n) return Object.keys(n);
4539
+ }
4540
+ neighbors(e) {
4541
+ let n = this.predecessors(e);
4542
+ if (n) {
4543
+ let t = new Set(n);
4544
+ for (let r5 of this.successors(e)) t.add(r5);
4545
+ return Array.from(t.values());
4546
+ }
4547
+ }
4548
+ isLeaf(e) {
4549
+ let n;
4550
+ return this.isDirected() ? n = this.successors(e) : n = this.neighbors(e), n.length === 0;
4551
+ }
4552
+ filterNodes(e) {
4553
+ let n = new this.constructor({ directed: this._isDirected, multigraph: this._isMultigraph, compound: this._isCompound });
4554
+ n.setGraph(this.graph()), Object.entries(this._nodes).forEach(([o, i]) => {
4555
+ e(o) && n.setNode(o, i);
4556
+ }), Object.values(this._edgeObjs).forEach((o) => {
4557
+ n.hasNode(o.v) && n.hasNode(o.w) && n.setEdge(o, this.edge(o));
4558
+ });
4559
+ let t = {}, r5 = (o) => {
4560
+ let i = this.parent(o);
4561
+ return !i || n.hasNode(i) ? (t[o] = i != null ? i : void 0, i != null ? i : void 0) : i in t ? t[i] : r5(i);
4562
+ };
4563
+ return this._isCompound && n.nodes().forEach((o) => n.setParent(o, r5(o))), n;
4564
+ }
4565
+ setDefaultEdgeLabel(e) {
4566
+ return typeof e != "function" ? this._defaultEdgeLabelFn = () => e : this._defaultEdgeLabelFn = e, this;
4567
+ }
4568
+ edgeCount() {
4569
+ return this._edgeCount;
4570
+ }
4571
+ edges() {
4572
+ return Object.values(this._edgeObjs);
4573
+ }
4574
+ setPath(e, n) {
4575
+ return e.reduce((t, r5) => (n !== void 0 ? this.setEdge(t, r5, n) : this.setEdge(t, r5), r5)), this;
4576
+ }
4577
+ setEdge(e, n, t, r5) {
4578
+ let o, i, s, a, d = false;
4579
+ typeof e == "object" && e !== null && "v" in e ? (o = e.v, i = e.w, s = e.name, arguments.length === 2 && (a = n, d = true)) : (o = e, i = n, s = r5, arguments.length > 2 && (a = t, d = true)), o = "" + o, i = "" + i, s !== void 0 && (s = "" + s);
4580
+ let l = C(this._isDirected, o, i, s);
4581
+ if (l in this._edgeLabels) return d && (this._edgeLabels[l] = a), this;
4582
+ if (s !== void 0 && !this._isMultigraph) throw new Error("Cannot set a named edge when isMultigraph = false");
4583
+ this.setNode(o), this.setNode(i), this._edgeLabels[l] = d ? a : this._defaultEdgeLabelFn(o, i, s);
4584
+ let u = gn(this._isDirected, o, i, s);
4585
+ return o = u.v, i = u.w, Object.freeze(u), this._edgeObjs[l] = u, me(this._preds[i], o), me(this._sucs[o], i), this._in[i][l] = u, this._out[o][l] = u, this._edgeCount++, this;
4586
+ }
4587
+ edge(e, n, t) {
4588
+ let r5 = arguments.length === 1 ? Y(this._isDirected, e) : C(this._isDirected, e, n, t);
4589
+ return this._edgeLabels[r5];
4590
+ }
4591
+ edgeAsObj(e, n, t) {
4592
+ let r5 = arguments.length === 1 ? this.edge(e) : this.edge(e, n, t);
4593
+ return typeof r5 != "object" ? { label: r5 } : r5;
4594
+ }
4595
+ hasEdge(e, n, t) {
4596
+ return (arguments.length === 1 ? Y(this._isDirected, e) : C(this._isDirected, e, n, t)) in this._edgeLabels;
4597
+ }
4598
+ removeEdge(e, n, t) {
4599
+ let r5 = arguments.length === 1 ? Y(this._isDirected, e) : C(this._isDirected, e, n, t), o = this._edgeObjs[r5];
4600
+ if (o) {
4601
+ let i = o.v, s = o.w;
4602
+ delete this._edgeLabels[r5], delete this._edgeObjs[r5], Ee(this._preds[s], i), Ee(this._sucs[i], s), delete this._in[s][r5], delete this._out[i][r5], this._edgeCount--;
4603
+ }
4604
+ return this;
4605
+ }
4606
+ inEdges(e, n) {
4607
+ return this.isDirected() ? this.filterEdges(this._in[e], e, n) : this.nodeEdges(e, n);
4608
+ }
4609
+ outEdges(e, n) {
4610
+ return this.isDirected() ? this.filterEdges(this._out[e], e, n) : this.nodeEdges(e, n);
4611
+ }
4612
+ nodeEdges(e, n) {
4613
+ if (e in this._nodes) return this.filterEdges({ ...this._in[e], ...this._out[e] }, e, n);
4614
+ }
4615
+ _removeFromParentsChildList(e) {
4616
+ delete this._children[this._parent[e]][e];
4617
+ }
4618
+ filterEdges(e, n, t) {
4619
+ if (!e) return;
4620
+ let r5 = Object.values(e);
4621
+ return t ? r5.filter((o) => o.v === n && o.w === t || o.v === t && o.w === n) : r5;
4622
+ }
4623
+ };
4624
+ function me(e, n) {
4625
+ e[n] ? e[n]++ : e[n] = 1;
4661
4626
  }
4662
- function Vn(e, n) {
4663
- if (e !== "_next" && e !== "_prev") return n;
4627
+ function Ee(e, n) {
4628
+ e[n] !== void 0 && !--e[n] && delete e[n];
4664
4629
  }
4665
- var Me = K;
4666
- var Wn = () => 1;
4667
- function Q(e, n) {
4668
- if (e.nodeCount() <= 1) return [];
4669
- let t = Yn(e, n || Wn);
4670
- return Bn(t.graph, t.buckets, t.zeroIdx).flatMap((o) => e.outEdges(o.v, o.w) || []);
4630
+ function C(e, n, t, r5) {
4631
+ let o = "" + n, i = "" + t;
4632
+ if (!e && o > i) {
4633
+ let s = o;
4634
+ o = i, i = s;
4635
+ }
4636
+ return o + "" + i + "" + (r5 === void 0 ? "\0" : r5);
4671
4637
  }
4672
- function Bn(e, n, t) {
4673
- var a;
4674
- let r5 = [], o = n[n.length - 1], i = n[0], s;
4675
- for (; e.nodeCount(); ) {
4676
- for (; s = i.dequeue(); ) $(e, n, t, s);
4677
- for (; s = o.dequeue(); ) $(e, n, t, s);
4678
- if (e.nodeCount()) {
4679
- for (let d = n.length - 2; d > 0; --d) if (s = (a = n[d]) == null ? void 0 : a.dequeue(), s) {
4680
- r5 = r5.concat($(e, n, t, s, true) || []);
4681
- break;
4682
- }
4683
- }
4638
+ function gn(e, n, t, r5) {
4639
+ let o = "" + n, i = "" + t;
4640
+ if (!e && o > i) {
4641
+ let a = o;
4642
+ o = i, i = a;
4684
4643
  }
4685
- return r5;
4644
+ let s = { v: o, w: i };
4645
+ return r5 && (s.name = r5), s;
4686
4646
  }
4687
- function $(e, n, t, r5, o) {
4688
- let i = [], s = o ? i : void 0;
4689
- return (e.inEdges(r5.v) || []).forEach((a) => {
4690
- let d = e.edge(a), l = e.node(a.v);
4691
- o && i.push({ v: a.v, w: a.w }), l.out -= d, J(n, t, l);
4692
- }), (e.outEdges(r5.v) || []).forEach((a) => {
4693
- let d = e.edge(a), l = a.w, u = e.node(l);
4694
- u.in -= d, J(n, t, u);
4695
- }), e.removeNode(r5.v), s;
4647
+ function Y(e, n) {
4648
+ return C(e, n.v, n.w, n.name);
4696
4649
  }
4697
- function Yn(e, n) {
4698
- let t = new p(), r5 = 0, o = 0;
4699
- e.nodes().forEach((a) => {
4700
- t.setNode(a, { v: a, in: 0, out: 0 });
4701
- }), e.edges().forEach((a) => {
4702
- let d = t.edge(a.v, a.w) || 0, l = n(a), u = d + l;
4703
- t.setEdge(a.v, a.w, u);
4704
- let c = t.node(a.v), h = t.node(a.w);
4705
- o = Math.max(o, c.out += l), r5 = Math.max(r5, h.in += l);
4650
+ var pn = "4.0.1";
4651
+ var ye = {};
4652
+ Le(ye, { read: () => yn, write: () => mn });
4653
+ function mn(e) {
4654
+ let n = { options: { directed: e.isDirected(), multigraph: e.isMultigraph(), compound: e.isCompound() }, nodes: En(e), edges: Ln(e) }, t = e.graph();
4655
+ return t !== void 0 && (n.value = structuredClone(t)), n;
4656
+ }
4657
+ function En(e) {
4658
+ return e.nodes().map((n) => {
4659
+ let t = e.node(n), r5 = e.parent(n), o = { v: n };
4660
+ return t !== void 0 && (o.value = t), r5 !== void 0 && (o.parent = r5), o;
4706
4661
  });
4707
- let i = zn(o + r5 + 3).map(() => new Me()), s = r5 + 1;
4708
- return t.nodes().forEach((a) => {
4709
- J(i, s, t.node(a));
4710
- }), { graph: t, buckets: i, zeroIdx: s };
4711
4662
  }
4712
- function J(e, n, t) {
4713
- var r5, o, i;
4714
- t.out ? t.in ? (i = e[t.out - t.in + n]) == null || i.enqueue(t) : (o = e[e.length - 1]) == null || o.enqueue(t) : (r5 = e[0]) == null || r5.enqueue(t);
4663
+ function Ln(e) {
4664
+ return e.edges().map((n) => {
4665
+ let t = e.edge(n), r5 = { v: n.v, w: n.w };
4666
+ return n.name !== void 0 && (r5.name = n.name), t !== void 0 && (r5.value = t), r5;
4667
+ });
4715
4668
  }
4716
- function zn(e) {
4717
- let n = [];
4718
- for (let t = 0; t < e; t++) n.push(t);
4719
- return n;
4669
+ function yn(e) {
4670
+ let n = new p(e.options);
4671
+ return e.value !== void 0 && n.setGraph(e.value), e.nodes.forEach((t) => {
4672
+ n.setNode(t.v, t.value), t.parent && n.setParent(t.v, t.parent);
4673
+ }), e.edges.forEach((t) => {
4674
+ n.setEdge({ v: t.v, w: t.w, name: t.name }, t.value);
4675
+ }), n;
4720
4676
  }
4721
- function je(e) {
4722
- (e.graph().acyclicer === "greedy" ? Q(e, t(e)) : Hn(e)).forEach((r5) => {
4723
- let o = e.edge(r5);
4724
- e.removeEdge(r5), o.forwardName = r5.name, o.reversed = true, e.setEdge(r5.w, r5.v, o, j("rev"));
4677
+ var R = {};
4678
+ Le(R, { CycleException: () => D, bellmanFord: () => we, components: () => Gn, dijkstra: () => F, dijkstraAll: () => _n, findCycles: () => xn, floydWarshall: () => On, isAcyclic: () => Cn, postorder: () => Pn, preorder: () => Mn, prim: () => jn, shortestPaths: () => Sn, tarjan: () => Ge, topsort: () => ke });
4679
+ var wn = () => 1;
4680
+ function we(e, n, t, r5) {
4681
+ return Nn(e, String(n), t || wn, r5 || function(o) {
4682
+ return e.outEdges(o);
4725
4683
  });
4726
- function t(r5) {
4727
- return (o) => r5.edge(o).weight;
4728
- }
4729
4684
  }
4730
- function Hn(e) {
4731
- let n = [], t = {}, r5 = {};
4732
- function o(i) {
4733
- Object.hasOwn(r5, i) || (r5[i] = true, t[i] = true, e.outEdges(i).forEach((s) => {
4734
- Object.hasOwn(t, s.w) ? n.push(s) : o(s.w);
4735
- }), delete t[i]);
4685
+ function Nn(e, n, t, r5) {
4686
+ let o = {}, i, s = 0, a = e.nodes(), d = function(c) {
4687
+ let h = t(c);
4688
+ o[c.v].distance + h < o[c.w].distance && (o[c.w] = { distance: o[c.v].distance + h, predecessor: c.v }, i = true);
4689
+ }, l = function() {
4690
+ a.forEach(function(c) {
4691
+ r5(c).forEach(function(h) {
4692
+ let f = h.v === c ? h.v : h.w, g = f === h.v ? h.w : h.v;
4693
+ d({ v: f, w: g });
4694
+ });
4695
+ });
4696
+ };
4697
+ a.forEach(function(c) {
4698
+ let h = c === n ? 0 : Number.POSITIVE_INFINITY;
4699
+ o[c] = { distance: h, predecessor: "" };
4700
+ });
4701
+ let u = a.length;
4702
+ for (let c = 1; c < u && (i = false, s++, l(), !!i); c++) ;
4703
+ if (s === u - 1 && (i = false, l(), i)) throw new Error("The graph contains a negative weight cycle");
4704
+ return o;
4705
+ }
4706
+ function Gn(e) {
4707
+ let n = {}, t = [], r5;
4708
+ function o(i) {
4709
+ i in n || (n[i] = true, r5.push(i), e.successors(i).forEach(o), e.predecessors(i).forEach(o));
4736
4710
  }
4737
- return e.nodes().forEach(o), n;
4711
+ return e.nodes().forEach(function(i) {
4712
+ r5 = [], o(i), r5.length && t.push(r5);
4713
+ }), t;
4738
4714
  }
4739
- function Se(e) {
4740
- e.edges().forEach((n) => {
4741
- let t = e.edge(n);
4742
- if (t.reversed) {
4743
- e.removeEdge(n);
4744
- let r5 = t.forwardName;
4745
- delete t.reversed, delete t.forwardName, e.setEdge(n.w, n.v, t, r5);
4715
+ var Ne = class {
4716
+ constructor() {
4717
+ this._arr = [], this._keyIndices = {};
4718
+ }
4719
+ size() {
4720
+ return this._arr.length;
4721
+ }
4722
+ keys() {
4723
+ return this._arr.map((e) => e.key);
4724
+ }
4725
+ has(e) {
4726
+ return e in this._keyIndices;
4727
+ }
4728
+ priority(e) {
4729
+ let n = this._keyIndices[e];
4730
+ if (n !== void 0) return this._arr[n].priority;
4731
+ }
4732
+ min() {
4733
+ if (this.size() === 0) throw new Error("Queue underflow");
4734
+ return this._arr[0].key;
4735
+ }
4736
+ add(e, n) {
4737
+ let t = this._keyIndices, r5 = String(e);
4738
+ if (!(r5 in t)) {
4739
+ let o = this._arr, i = o.length;
4740
+ return t[r5] = i, o.push({ key: r5, priority: n }), this._decrease(i), true;
4746
4741
  }
4747
- });
4748
- }
4749
- function Fe(e) {
4750
- e.graph().dummyChains = [], e.edges().forEach((n) => Xn(e, n));
4742
+ return false;
4743
+ }
4744
+ removeMin() {
4745
+ this._swap(0, this._arr.length - 1);
4746
+ let e = this._arr.pop();
4747
+ return delete this._keyIndices[e.key], this._heapify(0), e.key;
4748
+ }
4749
+ decrease(e, n) {
4750
+ let t = this._keyIndices[e];
4751
+ if (t === void 0) throw new Error(`Key not found: ${e}`);
4752
+ let r5 = this._arr[t].priority;
4753
+ if (n > r5) throw new Error(`New priority is greater than current priority. Key: ${e} Old: ${r5} New: ${n}`);
4754
+ this._arr[t].priority = n, this._decrease(t);
4755
+ }
4756
+ _heapify(e) {
4757
+ let n = this._arr, t = 2 * e, r5 = t + 1, o = e;
4758
+ t < n.length && (o = n[t].priority < n[o].priority ? t : o, r5 < n.length && (o = n[r5].priority < n[o].priority ? r5 : o), o !== e && (this._swap(e, o), this._heapify(o)));
4759
+ }
4760
+ _decrease(e) {
4761
+ let n = this._arr, t = n[e].priority, r5;
4762
+ for (; e !== 0 && (r5 = e >> 1, !(n[r5].priority < t)); ) this._swap(e, r5), e = r5;
4763
+ }
4764
+ _swap(e, n) {
4765
+ let t = this._arr, r5 = this._keyIndices, o = t[e], i = t[n];
4766
+ t[e] = i, t[n] = o, r5[i.key] = e, r5[o.key] = n;
4767
+ }
4768
+ };
4769
+ var kn = () => 1;
4770
+ function F(e, n, t, r5) {
4771
+ let o = function(i) {
4772
+ return e.outEdges(i);
4773
+ };
4774
+ return vn(e, String(n), t || kn, r5 || o);
4751
4775
  }
4752
- function Xn(e, n) {
4753
- let t = n.v, r5 = e.node(t).rank, o = n.w, i = e.node(o).rank, s = n.name, a = e.edge(n), d = a.labelRank;
4754
- if (i === r5 + 1) return;
4755
- e.removeEdge(n);
4756
- let l, u, c;
4757
- for (c = 0, ++r5; r5 < i; ++c, ++r5) a.points = [], u = { width: 0, height: 0, edgeLabel: a, edgeObj: n, rank: r5 }, l = w(e, "edge", u, "_d"), r5 === d && (u.width = a.width, u.height = a.height, u.dummy = "edge-label", u.labelpos = a.labelpos), e.setEdge(t, l, { weight: a.weight }, s), c === 0 && e.graph().dummyChains.push(l), t = l;
4758
- e.setEdge(t, o, { weight: a.weight }, s);
4776
+ function vn(e, n, t, r5) {
4777
+ let o = {}, i = new Ne(), s, a, d = function(l) {
4778
+ let u = l.v !== s ? l.v : l.w, c = o[u], h = t(l), f = a.distance + h;
4779
+ if (h < 0) throw new Error("dijkstra does not allow negative edge weights. Bad edge: " + l + " Weight: " + h);
4780
+ f < c.distance && (c.distance = f, c.predecessor = s, i.decrease(u, f));
4781
+ };
4782
+ for (e.nodes().forEach(function(l) {
4783
+ let u = l === n ? 0 : Number.POSITIVE_INFINITY;
4784
+ o[l] = { distance: u, predecessor: "" }, i.add(l, u);
4785
+ }); i.size() > 0 && (s = i.removeMin(), a = o[s], a.distance !== Number.POSITIVE_INFINITY); ) r5(s).forEach(d);
4786
+ return o;
4759
4787
  }
4760
- function De(e) {
4761
- e.graph().dummyChains.forEach((n) => {
4762
- let t = e.node(n), r5 = t.edgeLabel, o;
4763
- for (e.setEdge(t.edgeObj, r5); t.dummy; ) o = e.successors(n)[0], e.removeNode(n), r5.points.push({ x: t.x, y: t.y }), t.dummy === "edge-label" && (r5.x = t.x, r5.y = t.y, r5.width = t.width, r5.height = t.height), n = o, t = e.node(n);
4764
- });
4788
+ function _n(e, n, t) {
4789
+ return e.nodes().reduce(function(r5, o) {
4790
+ return r5[o] = F(e, o, n, t), r5;
4791
+ }, {});
4765
4792
  }
4766
- function S(e) {
4767
- let n = {};
4768
- function t(r5) {
4769
- let o = e.node(r5);
4770
- if (Object.hasOwn(n, r5)) return o.rank;
4771
- n[r5] = true;
4772
- let i = e.outEdges(r5), s = i ? i.map((d) => d == null ? Number.POSITIVE_INFINITY : t(d.w) - e.edge(d).minlen) : [], a = L(Math.min, s);
4773
- return a === Number.POSITIVE_INFINITY && (a = 0), o.rank = a;
4793
+ function Ge(e) {
4794
+ let n = 0, t = [], r5 = {}, o = [];
4795
+ function i(s) {
4796
+ let a = r5[s] = { onStack: true, lowlink: n, index: n++ };
4797
+ if (t.push(s), e.successors(s).forEach(function(d) {
4798
+ d in r5 ? r5[d].onStack && (a.lowlink = Math.min(a.lowlink, r5[d].index)) : (i(d), a.lowlink = Math.min(a.lowlink, r5[d].lowlink));
4799
+ }), a.lowlink === a.index) {
4800
+ let d = [], l;
4801
+ do
4802
+ l = t.pop(), r5[l].onStack = false, d.push(l);
4803
+ while (s !== l);
4804
+ o.push(d);
4805
+ }
4774
4806
  }
4775
- e.sources().forEach(t);
4807
+ return e.nodes().forEach(function(s) {
4808
+ s in r5 || i(s);
4809
+ }), o;
4776
4810
  }
4777
- function v(e, n) {
4778
- return e.node(n.w).rank - e.node(n.v).rank - e.edge(n).minlen;
4811
+ function xn(e) {
4812
+ return Ge(e).filter(function(n) {
4813
+ return n.length > 1 || n.length === 1 && e.hasEdge(n[0], n[0]);
4814
+ });
4779
4815
  }
4780
- var V = Kn;
4781
- function Kn(e) {
4782
- let n = new p({ directed: false }), t = e.nodes();
4783
- if (t.length === 0) throw new Error("Graph must have at least one node");
4784
- let r5 = t[0], o = e.nodeCount();
4785
- n.setNode(r5, {});
4786
- let i, s;
4787
- for (; $n(n, e) < o && (i = Jn(n, e), !!i); ) s = n.hasNode(i.v) ? v(e, i) : -v(e, i), Qn(n, e, s);
4788
- return n;
4816
+ var Tn = () => 1;
4817
+ function On(e, n, t) {
4818
+ return In(e, n || Tn, t || function(r5) {
4819
+ return e.outEdges(r5);
4820
+ });
4789
4821
  }
4790
- function $n(e, n) {
4791
- function t(r5) {
4792
- let o = n.nodeEdges(r5);
4793
- o && o.forEach((i) => {
4794
- let s = i.v, a = r5 === s ? i.w : s;
4795
- !e.hasNode(a) && !v(n, i) && (e.setNode(a, {}), e.setEdge(r5, a, {}), t(a));
4822
+ function In(e, n, t) {
4823
+ let r5 = {}, o = e.nodes();
4824
+ return o.forEach(function(i) {
4825
+ r5[i] = {}, r5[i][i] = { distance: 0, predecessor: "" }, o.forEach(function(s) {
4826
+ i !== s && (r5[i][s] = { distance: Number.POSITIVE_INFINITY, predecessor: "" });
4827
+ }), t(i).forEach(function(s) {
4828
+ let a = s.v === i ? s.w : s.v, d = n(s);
4829
+ r5[i][a] = { distance: d, predecessor: i };
4830
+ });
4831
+ }), o.forEach(function(i) {
4832
+ let s = r5[i];
4833
+ o.forEach(function(a) {
4834
+ let d = r5[a];
4835
+ o.forEach(function(l) {
4836
+ let u = d[i], c = s[l], h = d[l], f = u.distance + c.distance;
4837
+ f < h.distance && (h.distance = f, h.predecessor = c.predecessor);
4838
+ });
4796
4839
  });
4840
+ }), r5;
4841
+ }
4842
+ var D = class extends Error {
4843
+ constructor(...e) {
4844
+ super(...e);
4797
4845
  }
4798
- return e.nodes().forEach(t), e.nodeCount();
4846
+ };
4847
+ function ke(e) {
4848
+ let n = {}, t = {}, r5 = [];
4849
+ function o(i) {
4850
+ if (i in t) throw new D();
4851
+ i in n || (t[i] = true, n[i] = true, e.predecessors(i).forEach(o), delete t[i], r5.push(i));
4852
+ }
4853
+ if (e.sinks().forEach(o), Object.keys(n).length !== e.nodeCount()) throw new D();
4854
+ return r5;
4799
4855
  }
4800
- function Jn(e, n) {
4801
- return n.edges().reduce((r5, o) => {
4802
- let i = Number.POSITIVE_INFINITY;
4803
- return e.hasNode(o.v) !== e.hasNode(o.w) && (i = v(n, o)), i < r5[0] ? [i, o] : r5;
4804
- }, [Number.POSITIVE_INFINITY, null])[1];
4856
+ function Cn(e) {
4857
+ try {
4858
+ ke(e);
4859
+ } catch (n) {
4860
+ if (n instanceof D) return false;
4861
+ throw n;
4862
+ }
4863
+ return true;
4805
4864
  }
4806
- function Qn(e, n, t) {
4807
- e.nodes().forEach((r5) => n.node(r5).rank += t);
4865
+ function Rn(e, n, t, r5, o) {
4866
+ Array.isArray(n) || (n = [n]);
4867
+ let i = ((a) => {
4868
+ var d;
4869
+ return (d = e.isDirected() ? e.successors(a) : e.neighbors(a)) != null ? d : [];
4870
+ }), s = {};
4871
+ return n.forEach(function(a) {
4872
+ if (!e.hasNode(a)) throw new Error("Graph does not have node: " + a);
4873
+ o = ve(e, a, t === "post", s, i, r5, o);
4874
+ }), o;
4808
4875
  }
4809
- var { preorder: Zn, postorder: et } = R;
4810
- var Ve = x;
4811
- x.initLowLimValues = ee;
4812
- x.initCutValues = Z;
4813
- x.calcCutValue = We;
4814
- x.leaveEdge = Ye;
4815
- x.enterEdge = ze;
4816
- x.exchangeEdges = He;
4817
- function x(e) {
4818
- e = xe(e), S(e);
4819
- let n = V(e);
4820
- ee(n), Z(n, e);
4821
- let t, r5;
4822
- for (; t = Ye(n); ) r5 = ze(n, e, t), He(n, e, t, r5);
4876
+ function ve(e, n, t, r5, o, i, s) {
4877
+ return n in r5 || (r5[n] = true, t || (s = i(s, n)), o(n).forEach(function(a) {
4878
+ s = ve(e, a, t, r5, o, i, s);
4879
+ }), t && (s = i(s, n))), s;
4823
4880
  }
4824
- function Z(e, n) {
4825
- let t = et(e, e.nodes());
4826
- t = t.slice(0, t.length - 1), t.forEach((r5) => nt(e, n, r5));
4881
+ function _e(e, n, t) {
4882
+ return Rn(e, n, t, function(r5, o) {
4883
+ return r5.push(o), r5;
4884
+ }, []);
4827
4885
  }
4828
- function nt(e, n, t) {
4829
- let o = e.node(t).parent, i = e.edge(t, o);
4830
- i.cutvalue = We(e, n, t);
4886
+ function Pn(e, n) {
4887
+ return _e(e, n, "post");
4831
4888
  }
4832
- function We(e, n, t) {
4833
- let o = e.node(t).parent, i = true, s = n.edge(t, o), a = 0;
4834
- s || (i = false, s = n.edge(o, t)), a = s.weight;
4835
- let d = n.nodeEdges(t);
4836
- return d && d.forEach((l) => {
4837
- let u = l.v === t, c = u ? l.w : l.v;
4838
- if (c !== o) {
4839
- let h = u === i, f = n.edge(l).weight;
4840
- if (a += h ? f : -f, rt(e, t, c)) {
4841
- let b = e.edge(t, c).cutvalue;
4842
- a += h ? -b : b;
4843
- }
4889
+ function Mn(e, n) {
4890
+ return _e(e, n, "pre");
4891
+ }
4892
+ function jn(e, n) {
4893
+ let t = new p(), r5 = {}, o = new Ne(), i;
4894
+ function s(d) {
4895
+ let l = d.v === i ? d.w : d.v, u = o.priority(l);
4896
+ if (u !== void 0) {
4897
+ let c = n(d);
4898
+ c < u && (r5[l] = i, o.decrease(l, c));
4844
4899
  }
4845
- }), a;
4900
+ }
4901
+ if (e.nodeCount() === 0) return t;
4902
+ e.nodes().forEach(function(d) {
4903
+ o.add(d, Number.POSITIVE_INFINITY), t.setNode(d);
4904
+ }), o.decrease(e.nodes()[0], 0);
4905
+ let a = false;
4906
+ for (; o.size() > 0; ) {
4907
+ if (i = o.removeMin(), i in r5) t.setEdge(i, r5[i]);
4908
+ else {
4909
+ if (a) throw new Error("Input graph is not connected: " + e);
4910
+ a = true;
4911
+ }
4912
+ e.nodeEdges(i).forEach(s);
4913
+ }
4914
+ return t;
4846
4915
  }
4847
- function ee(e, n) {
4848
- arguments.length < 2 && (n = e.nodes()[0]), Be(e, {}, 1, n);
4916
+ function Sn(e, n, t, r5) {
4917
+ return Fn(e, n, t, r5 != null ? r5 : ((o) => {
4918
+ let i = e.outEdges(o);
4919
+ return i != null ? i : [];
4920
+ }));
4849
4921
  }
4850
- function Be(e, n, t, r5, o) {
4851
- let i = t, s = e.node(r5);
4852
- n[r5] = true;
4853
- let a = e.neighbors(r5);
4854
- return a && a.forEach((d) => {
4855
- Object.hasOwn(n, d) || (t = Be(e, n, t, d, r5));
4856
- }), s.low = i, s.lim = t++, o ? s.parent = o : delete s.parent, t;
4922
+ function Fn(e, n, t, r5) {
4923
+ if (t === void 0) return F(e, n, t, r5);
4924
+ let o = false, i = e.nodes();
4925
+ for (let s = 0; s < i.length; s++) {
4926
+ let a = r5(i[s]);
4927
+ for (let d = 0; d < a.length; d++) {
4928
+ let l = a[d], u = l.v === i[s] ? l.v : l.w, c = u === l.v ? l.w : l.v;
4929
+ t({ v: u, w: c }) < 0 && (o = true);
4930
+ }
4931
+ if (o) return we(e, n, t, r5);
4932
+ }
4933
+ return F(e, n, t, r5);
4857
4934
  }
4858
- function Ye(e) {
4859
- return e.edges().find((n) => e.edge(n).cutvalue < 0);
4935
+ function w(e, n, t, r5) {
4936
+ let o = r5;
4937
+ for (; e.hasNode(o); ) o = j(r5);
4938
+ return t.dummy = n, e.setNode(o, t), o;
4860
4939
  }
4861
- function ze(e, n, t) {
4862
- let r5 = t.v, o = t.w;
4863
- n.hasEdge(r5, o) || (r5 = t.w, o = t.v);
4864
- let i = e.node(r5), s = e.node(o), a = i, d = false;
4865
- return i.lim > s.lim && (a = s, d = true), n.edges().filter((u) => d === Ae(e, e.node(u.v), a) && d !== Ae(e, e.node(u.w), a)).reduce((u, c) => v(n, c) < v(n, u) ? c : u);
4940
+ function xe(e) {
4941
+ let n = new p().setGraph(e.graph());
4942
+ return e.nodes().forEach((t) => n.setNode(t, e.node(t))), e.edges().forEach((t) => {
4943
+ let r5 = n.edge(t.v, t.w) || { weight: 0, minlen: 1 }, o = e.edge(t);
4944
+ n.setEdge(t.v, t.w, { weight: r5.weight + o.weight, minlen: Math.max(r5.minlen, o.minlen) });
4945
+ }), n;
4866
4946
  }
4867
- function He(e, n, t, r5) {
4868
- let o = t.v, i = t.w;
4869
- e.removeEdge(o, i), e.setEdge(r5.v, r5.w, {}), ee(e), Z(e, n), tt(e, n);
4947
+ function A(e) {
4948
+ let n = new p({ multigraph: e.isMultigraph() }).setGraph(e.graph());
4949
+ return e.nodes().forEach((t) => {
4950
+ e.children(t).length || n.setNode(t, e.node(t));
4951
+ }), e.edges().forEach((t) => {
4952
+ n.setEdge(t, e.edge(t));
4953
+ }), n;
4870
4954
  }
4871
- function tt(e, n) {
4872
- let t = e.nodes().find((o) => !e.node(o).parent);
4873
- if (!t) return;
4874
- let r5 = Zn(e, [t]);
4875
- r5 = r5.slice(1), r5.forEach((o) => {
4876
- let s = e.node(o).parent, a = n.edge(o, s), d = false;
4877
- a || (a = n.edge(s, o), d = true), n.node(o).rank = n.node(s).rank + (d ? a.minlen : -a.minlen);
4955
+ function H(e, n) {
4956
+ let t = e.x, r5 = e.y, o = n.x - t, i = n.y - r5, s = e.width / 2, a = e.height / 2;
4957
+ if (!o && !i) throw new Error("Not possible to find intersection inside of the rectangle");
4958
+ let d, l;
4959
+ return Math.abs(i) * s > Math.abs(o) * a ? (i < 0 && (a = -a), d = a * o / i, l = a) : (o < 0 && (s = -s), d = s, l = s * i / o), { x: t + d, y: r5 + l };
4960
+ }
4961
+ function N(e) {
4962
+ let n = k(X(e) + 1).map(() => []);
4963
+ return e.nodes().forEach((t) => {
4964
+ let r5 = e.node(t), o = r5.rank;
4965
+ o !== void 0 && (n[o] || (n[o] = []), n[o][r5.order] = t);
4966
+ }), n;
4967
+ }
4968
+ function Te(e) {
4969
+ let n = e.nodes().map((r5) => {
4970
+ let o = e.node(r5).rank;
4971
+ return o === void 0 ? Number.MAX_VALUE : o;
4972
+ }), t = L(Math.min, n);
4973
+ e.nodes().forEach((r5) => {
4974
+ let o = e.node(r5);
4975
+ Object.hasOwn(o, "rank") && (o.rank -= t);
4878
4976
  });
4879
4977
  }
4880
- function rt(e, n, t) {
4881
- return e.hasEdge(n, t);
4978
+ function Oe(e) {
4979
+ let n = e.nodes().map((s) => e.node(s).rank).filter((s) => s !== void 0), t = L(Math.min, n), r5 = [];
4980
+ e.nodes().forEach((s) => {
4981
+ let a = e.node(s).rank - t;
4982
+ r5[a] || (r5[a] = []), r5[a].push(s);
4983
+ });
4984
+ let o = 0, i = e.graph().nodeRankFactor;
4985
+ Array.from(r5).forEach((s, a) => {
4986
+ s === void 0 && a % i !== 0 ? --o : s !== void 0 && o && s.forEach((d) => e.node(d).rank += o);
4987
+ });
4882
4988
  }
4883
- function Ae(e, n, t) {
4884
- return t.low <= n.lim && n.lim <= t.lim;
4989
+ function q(e, n, t, r5) {
4990
+ let o = { width: 0, height: 0 };
4991
+ return arguments.length >= 4 && (o.rank = t, o.order = r5), w(e, "border", o, n);
4885
4992
  }
4886
- var Xe = ot;
4887
- function ot(e) {
4888
- let n = e.graph().ranker;
4889
- if (typeof n == "function") return n(e);
4890
- switch (n) {
4891
- case "network-simplex":
4892
- qe(e);
4893
- break;
4894
- case "tight-tree":
4895
- st(e);
4896
- break;
4897
- case "longest-path":
4898
- it(e);
4899
- break;
4900
- case "none":
4901
- break;
4902
- default:
4903
- qe(e);
4993
+ function Dn(e, n = Ie) {
4994
+ let t = [];
4995
+ for (let r5 = 0; r5 < e.length; r5 += n) {
4996
+ let o = e.slice(r5, r5 + n);
4997
+ t.push(o);
4904
4998
  }
4999
+ return t;
4905
5000
  }
4906
- var it = S;
4907
- function st(e) {
4908
- S(e), V(e);
4909
- }
4910
- function qe(e) {
4911
- Ve(e);
5001
+ var Ie = 65535;
5002
+ function L(e, n) {
5003
+ if (n.length > Ie) {
5004
+ let t = Dn(n);
5005
+ return e(...t.map((r5) => e(...r5)));
5006
+ } else return e(...n);
4912
5007
  }
4913
- var Ue = at;
4914
- function at(e) {
4915
- let n = lt(e);
4916
- e.graph().dummyChains.forEach((t) => {
4917
- let r5 = e.node(t), o = r5.edgeObj, i = dt(e, n, o.v, o.w), s = i.path, a = i.lca, d = 0, l = s[d], u = true;
4918
- for (; t !== o.w; ) {
4919
- if (r5 = e.node(t), u) {
4920
- for (; (l = s[d]) !== a && e.node(l).maxRank < r5.rank; ) d++;
4921
- l === a && (u = false);
4922
- }
4923
- if (!u) {
4924
- for (; d < s.length - 1 && e.node(s[d + 1]).minRank <= r5.rank; ) d++;
4925
- l = s[d];
4926
- }
4927
- l !== void 0 && e.setParent(t, l), t = e.successors(t)[0];
4928
- }
5008
+ function X(e) {
5009
+ let t = e.nodes().map((r5) => {
5010
+ let o = e.node(r5).rank;
5011
+ return o === void 0 ? Number.MIN_VALUE : o;
4929
5012
  });
5013
+ return L(Math.max, t);
4930
5014
  }
4931
- function dt(e, n, t, r5) {
4932
- let o = [], i = [], s = Math.min(n[t].low, n[r5].low), a = Math.max(n[t].lim, n[r5].lim), d;
4933
- d = t;
4934
- do
4935
- d = e.parent(d), o.push(d);
4936
- while (d && (n[d].low > s || a > n[d].lim));
4937
- let l = d, u = r5;
4938
- for (; (u = e.parent(u)) !== l; ) i.push(u);
4939
- return { path: o.concat(i.reverse()), lca: l };
5015
+ function Ce(e, n) {
5016
+ let t = { lhs: [], rhs: [] };
5017
+ return e.forEach((r5) => {
5018
+ n(r5) ? t.lhs.push(r5) : t.rhs.push(r5);
5019
+ }), t;
4940
5020
  }
4941
- function lt(e) {
4942
- let n = {}, t = 0;
4943
- function r5(o) {
4944
- let i = t;
4945
- e.children(o).forEach(r5), n[o] = { low: i, lim: t++ };
5021
+ function P(e, n) {
5022
+ let t = Date.now();
5023
+ try {
5024
+ return n();
5025
+ } finally {
5026
+ console.log(e + " time: " + (Date.now() - t) + "ms");
4946
5027
  }
4947
- return e.children(_).forEach(r5), n;
4948
5028
  }
4949
- function Ke(e) {
4950
- let n = w(e, "root", {}, "_root"), t = ut(e), r5 = Object.values(t), o = L(Math.max, r5) - 1, i = 2 * o + 1;
4951
- e.graph().nestingRoot = n, e.edges().forEach((a) => e.edge(a).minlen *= i);
4952
- let s = ct(e) + 1;
4953
- e.children(_).forEach((a) => $e(e, n, i, s, o, t, a)), e.graph().nodeRankFactor = i;
5029
+ function M(e, n) {
5030
+ return n();
4954
5031
  }
4955
- function $e(e, n, t, r5, o, i, s) {
4956
- var c;
4957
- let a = e.children(s);
4958
- if (!a.length) {
4959
- s !== n && e.setEdge(n, s, { weight: 0, minlen: t });
4960
- return;
4961
- }
4962
- let d = q(e, "_bt"), l = q(e, "_bb"), u = e.node(s);
4963
- e.setParent(d, s), u.borderTop = d, e.setParent(l, s), u.borderBottom = l, a.forEach((h) => {
4964
- var y;
4965
- $e(e, n, t, r5, o, i, h);
4966
- let f = e.node(h), g = f.borderTop ? f.borderTop : h, b = f.borderBottom ? f.borderBottom : h, m = f.borderTop ? r5 : 2 * r5, E = g !== b ? 1 : o - ((y = i[s]) != null ? y : 0) + 1;
4967
- e.setEdge(d, g, { weight: m, minlen: E, nestingEdge: true }), e.setEdge(b, l, { weight: m, minlen: E, nestingEdge: true });
4968
- }), e.parent(s) || e.setEdge(n, d, { weight: 0, minlen: o + ((c = i[s]) != null ? c : 0) });
5032
+ var An = 0;
5033
+ function j(e) {
5034
+ let n = ++An;
5035
+ return e + ("" + n);
4969
5036
  }
4970
- function ut(e) {
4971
- let n = {};
4972
- function t(r5, o) {
4973
- let i = e.children(r5);
4974
- i && i.length && i.forEach((s) => t(s, o + 1)), n[r5] = o;
5037
+ function k(e, n, t = 1) {
5038
+ n == null && (n = e, e = 0);
5039
+ let r5 = (i) => i < n;
5040
+ t < 0 && (r5 = (i) => n < i);
5041
+ let o = [];
5042
+ for (let i = e; r5(i); i += t) o.push(i);
5043
+ return o;
5044
+ }
5045
+ function T(e, n) {
5046
+ let t = {};
5047
+ for (let r5 of n) e[r5] !== void 0 && (t[r5] = e[r5]);
5048
+ return t;
5049
+ }
5050
+ function O(e, n) {
5051
+ let t;
5052
+ return typeof n == "string" ? t = (r5) => r5[n] : t = n, Object.entries(e).reduce((r5, [o, i]) => (r5[o] = t(i, o), r5), {});
5053
+ }
5054
+ function Re(e, n) {
5055
+ return e.reduce((t, r5, o) => (t[r5] = n[o], t), {});
5056
+ }
5057
+ var _ = "\0";
5058
+ var U = "3.0.0";
5059
+ var K = class {
5060
+ constructor() {
5061
+ pe(this, "_sentinel");
5062
+ let n = {};
5063
+ n._next = n._prev = n, this._sentinel = n;
4975
5064
  }
4976
- return e.children(_).forEach((r5) => t(r5, 1)), n;
5065
+ dequeue() {
5066
+ let n = this._sentinel, t = n._prev;
5067
+ if (t !== n) return Pe(t), t;
5068
+ }
5069
+ enqueue(n) {
5070
+ let t = this._sentinel;
5071
+ n._prev && n._next && Pe(n), n._next = t._next, t._next._prev = n, t._next = n, n._prev = t;
5072
+ }
5073
+ toString() {
5074
+ let n = [], t = this._sentinel, r5 = t._prev;
5075
+ for (; r5 !== t; ) n.push(JSON.stringify(r5, Vn)), r5 = r5._prev;
5076
+ return "[" + n.join(", ") + "]";
5077
+ }
5078
+ };
5079
+ function Pe(e) {
5080
+ e._prev._next = e._next, e._next._prev = e._prev, delete e._next, delete e._prev;
4977
5081
  }
4978
- function ct(e) {
4979
- return e.edges().reduce((n, t) => n + e.edge(t).weight, 0);
5082
+ function Vn(e, n) {
5083
+ if (e !== "_next" && e !== "_prev") return n;
4980
5084
  }
4981
- function Je(e) {
4982
- let n = e.graph();
4983
- e.removeNode(n.nestingRoot), delete n.nestingRoot, e.edges().forEach((t) => {
4984
- e.edge(t).nestingEdge && e.removeEdge(t);
4985
- });
5085
+ var Me = K;
5086
+ var Wn = () => 1;
5087
+ function Q(e, n) {
5088
+ if (e.nodeCount() <= 1) return [];
5089
+ let t = Yn(e, n || Wn);
5090
+ return Bn(t.graph, t.buckets, t.zeroIdx).flatMap((o) => e.outEdges(o.v, o.w) || []);
4986
5091
  }
4987
- var Ze = ft;
4988
- function ft(e) {
4989
- function n(t) {
4990
- let r5 = e.children(t), o = e.node(t);
4991
- if (r5.length && r5.forEach(n), Object.hasOwn(o, "minRank")) {
4992
- o.borderLeft = [], o.borderRight = [];
4993
- for (let i = o.minRank, s = o.maxRank + 1; i < s; ++i) Qe(e, "borderLeft", "_bl", t, o, i), Qe(e, "borderRight", "_br", t, o, i);
5092
+ function Bn(e, n, t) {
5093
+ var a;
5094
+ let r5 = [], o = n[n.length - 1], i = n[0], s;
5095
+ for (; e.nodeCount(); ) {
5096
+ for (; s = i.dequeue(); ) $(e, n, t, s);
5097
+ for (; s = o.dequeue(); ) $(e, n, t, s);
5098
+ if (e.nodeCount()) {
5099
+ for (let d = n.length - 2; d > 0; --d) if (s = (a = n[d]) == null ? void 0 : a.dequeue(), s) {
5100
+ r5 = r5.concat($(e, n, t, s, true) || []);
5101
+ break;
5102
+ }
4994
5103
  }
4995
5104
  }
4996
- e.children(_).forEach(n);
4997
- }
4998
- function Qe(e, n, t, r5, o, i) {
4999
- let s = { width: 0, height: 0, rank: i, borderType: n }, a = o[n][i - 1], d = w(e, "border", s, t);
5000
- o[n][i] = d, e.setParent(d, r5), a && e.setEdge(a, d, { weight: 1 });
5105
+ return r5;
5001
5106
  }
5002
- function nn(e) {
5003
- var t;
5004
- let n = (t = e.graph().rankdir) == null ? void 0 : t.toLowerCase();
5005
- (n === "lr" || n === "rl") && rn(e);
5107
+ function $(e, n, t, r5, o) {
5108
+ let i = [], s = o ? i : void 0;
5109
+ return (e.inEdges(r5.v) || []).forEach((a) => {
5110
+ let d = e.edge(a), l = e.node(a.v);
5111
+ o && i.push({ v: a.v, w: a.w }), l.out -= d, J(n, t, l);
5112
+ }), (e.outEdges(r5.v) || []).forEach((a) => {
5113
+ let d = e.edge(a), l = a.w, u = e.node(l);
5114
+ u.in -= d, J(n, t, u);
5115
+ }), e.removeNode(r5.v), s;
5006
5116
  }
5007
- function tn(e) {
5008
- var t;
5009
- let n = (t = e.graph().rankdir) == null ? void 0 : t.toLowerCase();
5010
- (n === "bt" || n === "rl") && bt(e), (n === "lr" || n === "rl") && (gt(e), rn(e));
5117
+ function Yn(e, n) {
5118
+ let t = new p(), r5 = 0, o = 0;
5119
+ e.nodes().forEach((a) => {
5120
+ t.setNode(a, { v: a, in: 0, out: 0 });
5121
+ }), e.edges().forEach((a) => {
5122
+ let d = t.edge(a.v, a.w) || 0, l = n(a), u = d + l;
5123
+ t.setEdge(a.v, a.w, u);
5124
+ let c = t.node(a.v), h = t.node(a.w);
5125
+ o = Math.max(o, c.out += l), r5 = Math.max(r5, h.in += l);
5126
+ });
5127
+ let i = zn(o + r5 + 3).map(() => new Me()), s = r5 + 1;
5128
+ return t.nodes().forEach((a) => {
5129
+ J(i, s, t.node(a));
5130
+ }), { graph: t, buckets: i, zeroIdx: s };
5011
5131
  }
5012
- function rn(e) {
5013
- e.nodes().forEach((n) => en(e.node(n))), e.edges().forEach((n) => en(e.edge(n)));
5132
+ function J(e, n, t) {
5133
+ var r5, o, i;
5134
+ t.out ? t.in ? (i = e[t.out - t.in + n]) == null || i.enqueue(t) : (o = e[e.length - 1]) == null || o.enqueue(t) : (r5 = e[0]) == null || r5.enqueue(t);
5014
5135
  }
5015
- function en(e) {
5016
- let n = e.width;
5017
- e.width = e.height, e.height = n;
5136
+ function zn(e) {
5137
+ let n = [];
5138
+ for (let t = 0; t < e; t++) n.push(t);
5139
+ return n;
5018
5140
  }
5019
- function bt(e) {
5020
- e.nodes().forEach((n) => ne(e.node(n))), e.edges().forEach((n) => {
5021
- var r5;
5022
- let t = e.edge(n);
5023
- (r5 = t.points) == null || r5.forEach(ne), Object.hasOwn(t, "y") && ne(t);
5141
+ function je(e) {
5142
+ (e.graph().acyclicer === "greedy" ? Q(e, t(e)) : Hn(e)).forEach((r5) => {
5143
+ let o = e.edge(r5);
5144
+ e.removeEdge(r5), o.forwardName = r5.name, o.reversed = true, e.setEdge(r5.w, r5.v, o, j("rev"));
5024
5145
  });
5146
+ function t(r5) {
5147
+ return (o) => r5.edge(o).weight;
5148
+ }
5025
5149
  }
5026
- function ne(e) {
5027
- e.y = -e.y;
5150
+ function Hn(e) {
5151
+ let n = [], t = {}, r5 = {};
5152
+ function o(i) {
5153
+ Object.hasOwn(r5, i) || (r5[i] = true, t[i] = true, e.outEdges(i).forEach((s) => {
5154
+ Object.hasOwn(t, s.w) ? n.push(s) : o(s.w);
5155
+ }), delete t[i]);
5156
+ }
5157
+ return e.nodes().forEach(o), n;
5028
5158
  }
5029
- function gt(e) {
5030
- e.nodes().forEach((n) => te(e.node(n))), e.edges().forEach((n) => {
5031
- var r5;
5159
+ function Se(e) {
5160
+ e.edges().forEach((n) => {
5032
5161
  let t = e.edge(n);
5033
- (r5 = t.points) == null || r5.forEach(te), Object.hasOwn(t, "x") && te(t);
5162
+ if (t.reversed) {
5163
+ e.removeEdge(n);
5164
+ let r5 = t.forwardName;
5165
+ delete t.reversed, delete t.forwardName, e.setEdge(n.w, n.v, t, r5);
5166
+ }
5034
5167
  });
5035
5168
  }
5036
- function te(e) {
5037
- let n = e.x;
5038
- e.x = e.y, e.y = n;
5169
+ function Fe(e) {
5170
+ e.graph().dummyChains = [], e.edges().forEach((n) => Xn(e, n));
5039
5171
  }
5040
- function re(e) {
5041
- let n = {}, t = e.nodes().filter((d) => !e.children(d).length), r5 = t.map((d) => e.node(d).rank), o = L(Math.max, r5), i = k(o + 1).map(() => []);
5042
- function s(d) {
5043
- if (n[d]) return;
5044
- n[d] = true;
5045
- let l = e.node(d);
5046
- i[l.rank].push(d);
5047
- let u = e.successors(d);
5048
- u && u.forEach(s);
5049
- }
5050
- return t.sort((d, l) => e.node(d).rank - e.node(l).rank).forEach(s), i;
5172
+ function Xn(e, n) {
5173
+ let t = n.v, r5 = e.node(t).rank, o = n.w, i = e.node(o).rank, s = n.name, a = e.edge(n), d = a.labelRank;
5174
+ if (i === r5 + 1) return;
5175
+ e.removeEdge(n);
5176
+ let l, u, c;
5177
+ for (c = 0, ++r5; r5 < i; ++c, ++r5) a.points = [], u = { width: 0, height: 0, edgeLabel: a, edgeObj: n, rank: r5 }, l = w(e, "edge", u, "_d"), r5 === d && (u.width = a.width, u.height = a.height, u.dummy = "edge-label", u.labelpos = a.labelpos), e.setEdge(t, l, { weight: a.weight }, s), c === 0 && e.graph().dummyChains.push(l), t = l;
5178
+ e.setEdge(t, o, { weight: a.weight }, s);
5051
5179
  }
5052
- function oe(e, n) {
5053
- let t = 0;
5054
- for (let r5 = 1; r5 < n.length; ++r5) t += mt(e, n[r5 - 1], n[r5]);
5055
- return t;
5180
+ function De(e) {
5181
+ e.graph().dummyChains.forEach((n) => {
5182
+ let t = e.node(n), r5 = t.edgeLabel, o;
5183
+ for (e.setEdge(t.edgeObj, r5); t.dummy; ) o = e.successors(n)[0], e.removeNode(n), r5.points.push({ x: t.x, y: t.y }), t.dummy === "edge-label" && (r5.x = t.x, r5.y = t.y, r5.width = t.width, r5.height = t.height), n = o, t = e.node(n);
5184
+ });
5056
5185
  }
5057
- function mt(e, n, t) {
5058
- let r5 = Re(t, t.map((l, u) => u)), o = n.flatMap((l) => {
5059
- let u = e.outEdges(l);
5060
- return u ? u.map((c) => ({ pos: r5[c.w], weight: e.edge(c).weight })).sort((c, h) => c.pos - h.pos) : [];
5061
- }), i = 1;
5062
- for (; i < t.length; ) i <<= 1;
5063
- let s = 2 * i - 1;
5064
- i -= 1;
5065
- let a = new Array(s).fill(0), d = 0;
5066
- return o.forEach((l) => {
5067
- let u = l.pos + i;
5068
- a[u] += l.weight;
5069
- let c = 0;
5070
- for (; u > 0; ) u % 2 && (c += a[u + 1]), u = u - 1 >> 1, a[u] += l.weight;
5071
- d += l.weight * c;
5072
- }), d;
5186
+ function S(e) {
5187
+ let n = {};
5188
+ function t(r5) {
5189
+ let o = e.node(r5);
5190
+ if (Object.hasOwn(n, r5)) return o.rank;
5191
+ n[r5] = true;
5192
+ let i = e.outEdges(r5), s = i ? i.map((d) => d == null ? Number.POSITIVE_INFINITY : t(d.w) - e.edge(d).minlen) : [], a = L(Math.min, s);
5193
+ return a === Number.POSITIVE_INFINITY && (a = 0), o.rank = a;
5194
+ }
5195
+ e.sources().forEach(t);
5073
5196
  }
5074
- function ie(e, n = []) {
5075
- return n.map((t) => {
5076
- let r5 = e.inEdges(t);
5077
- if (!r5 || !r5.length) return { v: t };
5078
- {
5079
- let o = r5.reduce((i, s) => {
5080
- let a = e.edge(s), d = e.node(s.v);
5081
- return { sum: i.sum + a.weight * d.order, weight: i.weight + a.weight };
5082
- }, { sum: 0, weight: 0 });
5083
- return { v: t, barycenter: o.sum / o.weight, weight: o.weight };
5084
- }
5085
- });
5197
+ function v(e, n) {
5198
+ return e.node(n.w).rank - e.node(n.v).rank - e.edge(n).minlen;
5086
5199
  }
5087
- function se(e, n) {
5088
- let t = {};
5089
- e.forEach((o, i) => {
5090
- let s = { indegree: 0, in: [], out: [], vs: [o.v], i };
5091
- o.barycenter !== void 0 && (s.barycenter = o.barycenter, s.weight = o.weight), t[o.v] = s;
5092
- }), n.edges().forEach((o) => {
5093
- let i = t[o.v], s = t[o.w];
5094
- i !== void 0 && s !== void 0 && (s.indegree++, i.out.push(s));
5095
- });
5096
- let r5 = Object.values(t).filter((o) => !o.indegree);
5097
- return Et(r5);
5200
+ var V = Kn;
5201
+ function Kn(e) {
5202
+ let n = new p({ directed: false }), t = e.nodes();
5203
+ if (t.length === 0) throw new Error("Graph must have at least one node");
5204
+ let r5 = t[0], o = e.nodeCount();
5205
+ n.setNode(r5, {});
5206
+ let i, s;
5207
+ for (; $n(n, e) < o && (i = Jn(n, e), !!i); ) s = n.hasNode(i.v) ? v(e, i) : -v(e, i), Qn(n, e, s);
5208
+ return n;
5098
5209
  }
5099
- function Et(e) {
5100
- let n = [];
5101
- function t(o) {
5102
- return (i) => {
5103
- i.merged || (i.barycenter === void 0 || o.barycenter === void 0 || i.barycenter >= o.barycenter) && Lt(o, i);
5104
- };
5105
- }
5106
- function r5(o) {
5107
- return (i) => {
5108
- i.in.push(o), --i.indegree === 0 && e.push(i);
5109
- };
5110
- }
5111
- for (; e.length; ) {
5112
- let o = e.pop();
5113
- n.push(o), o.in.reverse().forEach(t(o)), o.out.forEach(r5(o));
5210
+ function $n(e, n) {
5211
+ function t(r5) {
5212
+ let o = n.nodeEdges(r5);
5213
+ o && o.forEach((i) => {
5214
+ let s = i.v, a = r5 === s ? i.w : s;
5215
+ !e.hasNode(a) && !v(n, i) && (e.setNode(a, {}), e.setEdge(r5, a, {}), t(a));
5216
+ });
5114
5217
  }
5115
- return n.filter((o) => !o.merged).map((o) => T(o, ["vs", "i", "barycenter", "weight"]));
5218
+ return e.nodes().forEach(t), e.nodeCount();
5116
5219
  }
5117
- function Lt(e, n) {
5118
- let t = 0, r5 = 0;
5119
- e.weight && (t += e.barycenter * e.weight, r5 += e.weight), n.weight && (t += n.barycenter * n.weight, r5 += n.weight), e.vs = n.vs.concat(e.vs), e.barycenter = t / r5, e.weight = r5, e.i = Math.min(n.i, e.i), n.merged = true;
5220
+ function Jn(e, n) {
5221
+ return n.edges().reduce((r5, o) => {
5222
+ let i = Number.POSITIVE_INFINITY;
5223
+ return e.hasNode(o.v) !== e.hasNode(o.w) && (i = v(n, o)), i < r5[0] ? [i, o] : r5;
5224
+ }, [Number.POSITIVE_INFINITY, null])[1];
5120
5225
  }
5121
- function ae(e, n) {
5122
- let t = Ce(e, (u) => Object.hasOwn(u, "barycenter")), r5 = t.lhs, o = t.rhs.sort((u, c) => c.i - u.i), i = [], s = 0, a = 0, d = 0;
5123
- r5.sort(yt(!!n)), d = on(i, o, d), r5.forEach((u) => {
5124
- d += u.vs.length, i.push(u.vs), s += u.barycenter * u.weight, a += u.weight, d = on(i, o, d);
5125
- });
5126
- let l = { vs: i.flat(1) };
5127
- return a && (l.barycenter = s / a, l.weight = a), l;
5226
+ function Qn(e, n, t) {
5227
+ e.nodes().forEach((r5) => n.node(r5).rank += t);
5128
5228
  }
5129
- function on(e, n, t) {
5130
- let r5;
5131
- for (; n.length && (r5 = n[n.length - 1]).i <= t; ) n.pop(), e.push(r5.vs), t++;
5132
- return t;
5229
+ var { preorder: Zn, postorder: et } = R;
5230
+ var Ve = x;
5231
+ x.initLowLimValues = ee;
5232
+ x.initCutValues = Z;
5233
+ x.calcCutValue = We;
5234
+ x.leaveEdge = Ye;
5235
+ x.enterEdge = ze;
5236
+ x.exchangeEdges = He;
5237
+ function x(e) {
5238
+ e = xe(e), S(e);
5239
+ let n = V(e);
5240
+ ee(n), Z(n, e);
5241
+ let t, r5;
5242
+ for (; t = Ye(n); ) r5 = ze(n, e, t), He(n, e, t, r5);
5133
5243
  }
5134
- function yt(e) {
5135
- return (n, t) => n.barycenter < t.barycenter ? -1 : n.barycenter > t.barycenter ? 1 : e ? t.i - n.i : n.i - t.i;
5244
+ function Z(e, n) {
5245
+ let t = et(e, e.nodes());
5246
+ t = t.slice(0, t.length - 1), t.forEach((r5) => nt(e, n, r5));
5136
5247
  }
5137
- function W(e, n, t, r5) {
5138
- let o = e.children(n), i = e.node(n), s = i ? i.borderLeft : void 0, a = i ? i.borderRight : void 0, d = {};
5139
- s && (o = o.filter((h) => h !== s && h !== a));
5140
- let l = ie(e, o);
5141
- l.forEach((h) => {
5142
- if (e.children(h.v).length) {
5143
- let f = W(e, h.v, t, r5);
5144
- d[h.v] = f, Object.hasOwn(f, "barycenter") && Nt(h, f);
5145
- }
5146
- });
5147
- let u = se(l, t);
5148
- wt(u, d);
5149
- let c = ae(u, r5);
5150
- if (s && a) {
5151
- c.vs = [s, c.vs, a].flat(1);
5152
- let h = e.predecessors(s);
5153
- if (h && h.length) {
5154
- let f = e.node(h[0]), g = e.predecessors(a), b = e.node(g[0]);
5155
- Object.hasOwn(c, "barycenter") || (c.barycenter = 0, c.weight = 0), c.barycenter = (c.barycenter * c.weight + f.order + b.order) / (c.weight + 2), c.weight += 2;
5248
+ function nt(e, n, t) {
5249
+ let o = e.node(t).parent, i = e.edge(t, o);
5250
+ i.cutvalue = We(e, n, t);
5251
+ }
5252
+ function We(e, n, t) {
5253
+ let o = e.node(t).parent, i = true, s = n.edge(t, o), a = 0;
5254
+ s || (i = false, s = n.edge(o, t)), a = s.weight;
5255
+ let d = n.nodeEdges(t);
5256
+ return d && d.forEach((l) => {
5257
+ let u = l.v === t, c = u ? l.w : l.v;
5258
+ if (c !== o) {
5259
+ let h = u === i, f = n.edge(l).weight;
5260
+ if (a += h ? f : -f, rt(e, t, c)) {
5261
+ let b = e.edge(t, c).cutvalue;
5262
+ a += h ? -b : b;
5263
+ }
5156
5264
  }
5157
- }
5158
- return c;
5265
+ }), a;
5159
5266
  }
5160
- function wt(e, n) {
5161
- e.forEach((t) => {
5162
- t.vs = t.vs.flatMap((r5) => n[r5] ? n[r5].vs : r5);
5163
- });
5267
+ function ee(e, n) {
5268
+ arguments.length < 2 && (n = e.nodes()[0]), Be(e, {}, 1, n);
5164
5269
  }
5165
- function Nt(e, n) {
5166
- e.barycenter !== void 0 ? (e.barycenter = (e.barycenter * e.weight + n.barycenter * n.weight) / (e.weight + n.weight), e.weight += n.weight) : (e.barycenter = n.barycenter, e.weight = n.weight);
5270
+ function Be(e, n, t, r5, o) {
5271
+ let i = t, s = e.node(r5);
5272
+ n[r5] = true;
5273
+ let a = e.neighbors(r5);
5274
+ return a && a.forEach((d) => {
5275
+ Object.hasOwn(n, d) || (t = Be(e, n, t, d, r5));
5276
+ }), s.low = i, s.lim = t++, o ? s.parent = o : delete s.parent, t;
5167
5277
  }
5168
- function de(e, n, t, r5) {
5169
- r5 || (r5 = e.nodes());
5170
- let o = Gt(e), i = new p({ compound: true }).setGraph({ root: o }).setDefaultNodeLabel((s) => e.node(s));
5171
- return r5.forEach((s) => {
5172
- let a = e.node(s), d = e.parent(s);
5173
- if (a.rank === n || a.minRank <= n && n <= a.maxRank) {
5174
- i.setNode(s), i.setParent(s, d || o);
5175
- let l = e[t](s);
5176
- l && l.forEach((u) => {
5177
- let c = u.v === s ? u.w : u.v, h = i.edge(c, s), f = h !== void 0 ? h.weight : 0;
5178
- i.setEdge(c, s, { weight: e.edge(u).weight + f });
5179
- }), Object.hasOwn(a, "minRank") && i.setNode(s, { borderLeft: a.borderLeft[n], borderRight: a.borderRight[n] });
5180
- }
5181
- }), i;
5278
+ function Ye(e) {
5279
+ return e.edges().find((n) => e.edge(n).cutvalue < 0);
5182
5280
  }
5183
- function Gt(e) {
5184
- let n;
5185
- for (; e.hasNode(n = j("_root")); ) ;
5186
- return n;
5281
+ function ze(e, n, t) {
5282
+ let r5 = t.v, o = t.w;
5283
+ n.hasEdge(r5, o) || (r5 = t.w, o = t.v);
5284
+ let i = e.node(r5), s = e.node(o), a = i, d = false;
5285
+ return i.lim > s.lim && (a = s, d = true), n.edges().filter((u) => d === Ae(e, e.node(u.v), a) && d !== Ae(e, e.node(u.w), a)).reduce((u, c) => v(n, c) < v(n, u) ? c : u);
5187
5286
  }
5188
- function le(e, n, t) {
5189
- let r5 = {}, o;
5190
- t.forEach((i) => {
5191
- let s = e.parent(i), a, d;
5192
- for (; s; ) {
5193
- if (a = e.parent(s), a ? (d = r5[a], r5[a] = s) : (d = o, o = s), d && d !== s) {
5194
- n.setEdge(d, s);
5195
- return;
5196
- }
5197
- s = a;
5198
- }
5287
+ function He(e, n, t, r5) {
5288
+ let o = t.v, i = t.w;
5289
+ e.removeEdge(o, i), e.setEdge(r5.v, r5.w, {}), ee(e), Z(e, n), tt(e, n);
5290
+ }
5291
+ function tt(e, n) {
5292
+ let t = e.nodes().find((o) => !e.node(o).parent);
5293
+ if (!t) return;
5294
+ let r5 = Zn(e, [t]);
5295
+ r5 = r5.slice(1), r5.forEach((o) => {
5296
+ let s = e.node(o).parent, a = n.edge(o, s), d = false;
5297
+ a || (a = n.edge(s, o), d = true), n.node(o).rank = n.node(s).rank + (d ? a.minlen : -a.minlen);
5199
5298
  });
5200
5299
  }
5201
- function B(e, n = {}) {
5202
- if (typeof n.customOrder == "function") {
5203
- n.customOrder(e, B);
5204
- return;
5205
- }
5206
- let t = X(e), r5 = sn(e, k(1, t + 1), "inEdges"), o = sn(e, k(t - 1, -1, -1), "outEdges"), i = re(e);
5207
- if (an(e, i), n.disableOptimalOrderHeuristic) return;
5208
- let s = Number.POSITIVE_INFINITY, a, d = n.constraints || [];
5209
- for (let l = 0, u = 0; u < 4; ++l, ++u) {
5210
- kt(l % 2 ? r5 : o, l % 4 >= 2, d), i = N(e);
5211
- let c = oe(e, i);
5212
- c < s ? (u = 0, a = Object.assign({}, i), s = c) : c === s && (a = structuredClone(i));
5213
- }
5214
- an(e, a);
5300
+ function rt(e, n, t) {
5301
+ return e.hasEdge(n, t);
5215
5302
  }
5216
- function sn(e, n, t) {
5217
- let r5 = /* @__PURE__ */ new Map(), o = (i, s) => {
5218
- r5.has(i) || r5.set(i, []), r5.get(i).push(s);
5219
- };
5220
- for (let i of e.nodes()) {
5221
- let s = e.node(i);
5222
- if (typeof s.rank == "number" && o(s.rank, i), typeof s.minRank == "number" && typeof s.maxRank == "number") for (let a = s.minRank; a <= s.maxRank; a++) a !== s.rank && o(a, i);
5303
+ function Ae(e, n, t) {
5304
+ return t.low <= n.lim && n.lim <= t.lim;
5305
+ }
5306
+ var Xe = ot;
5307
+ function ot(e) {
5308
+ let n = e.graph().ranker;
5309
+ if (typeof n == "function") return n(e);
5310
+ switch (n) {
5311
+ case "network-simplex":
5312
+ qe(e);
5313
+ break;
5314
+ case "tight-tree":
5315
+ st(e);
5316
+ break;
5317
+ case "longest-path":
5318
+ it(e);
5319
+ break;
5320
+ case "none":
5321
+ break;
5322
+ default:
5323
+ qe(e);
5223
5324
  }
5224
- return n.map(function(i) {
5225
- return de(e, i, t, r5.get(i) || []);
5226
- });
5227
5325
  }
5228
- function kt(e, n, t) {
5229
- let r5 = new p();
5230
- e.forEach(function(o) {
5231
- t.forEach((a) => r5.setEdge(a.left, a.right));
5232
- let i = o.graph().root, s = W(o, i, r5, n);
5233
- s.vs.forEach((a, d) => o.node(a).order = d), le(o, r5, s.vs);
5326
+ var it = S;
5327
+ function st(e) {
5328
+ S(e), V(e);
5329
+ }
5330
+ function qe(e) {
5331
+ Ve(e);
5332
+ }
5333
+ var Ue = at;
5334
+ function at(e) {
5335
+ let n = lt(e);
5336
+ e.graph().dummyChains.forEach((t) => {
5337
+ let r5 = e.node(t), o = r5.edgeObj, i = dt(e, n, o.v, o.w), s = i.path, a = i.lca, d = 0, l = s[d], u = true;
5338
+ for (; t !== o.w; ) {
5339
+ if (r5 = e.node(t), u) {
5340
+ for (; (l = s[d]) !== a && e.node(l).maxRank < r5.rank; ) d++;
5341
+ l === a && (u = false);
5342
+ }
5343
+ if (!u) {
5344
+ for (; d < s.length - 1 && e.node(s[d + 1]).minRank <= r5.rank; ) d++;
5345
+ l = s[d];
5346
+ }
5347
+ l !== void 0 && e.setParent(t, l), t = e.successors(t)[0];
5348
+ }
5234
5349
  });
5235
5350
  }
5236
- function an(e, n) {
5237
- Object.values(n).forEach((t) => t.forEach((r5, o) => e.node(r5).order = o));
5351
+ function dt(e, n, t, r5) {
5352
+ let o = [], i = [], s = Math.min(n[t].low, n[r5].low), a = Math.max(n[t].lim, n[r5].lim), d;
5353
+ d = t;
5354
+ do
5355
+ d = e.parent(d), o.push(d);
5356
+ while (d && (n[d].low > s || a > n[d].lim));
5357
+ let l = d, u = r5;
5358
+ for (; (u = e.parent(u)) !== l; ) i.push(u);
5359
+ return { path: o.concat(i.reverse()), lca: l };
5238
5360
  }
5239
- function vt(e, n) {
5240
- let t = {};
5241
- function r5(o, i) {
5242
- let s = 0, a = 0, d = o.length, l = i[i.length - 1];
5243
- return i.forEach((u, c) => {
5244
- let h = xt(e, u), f = h ? e.node(h).order : d;
5245
- (h || u === l) && (i.slice(a, c + 1).forEach((g) => {
5246
- let b = e.predecessors(g);
5247
- b && b.forEach((m) => {
5248
- let E = e.node(m), y = E.order;
5249
- (y < s || f < y) && !(E.dummy && e.node(g).dummy) && dn(t, m, g);
5250
- });
5251
- }), a = c + 1, s = f);
5252
- }), i;
5361
+ function lt(e) {
5362
+ let n = {}, t = 0;
5363
+ function r5(o) {
5364
+ let i = t;
5365
+ e.children(o).forEach(r5), n[o] = { low: i, lim: t++ };
5253
5366
  }
5254
- return n.length && n.reduce(r5), t;
5367
+ return e.children(_).forEach(r5), n;
5255
5368
  }
5256
- function _t(e, n) {
5257
- let t = {};
5258
- function r5(i, s, a, d, l) {
5259
- k(s, a).forEach((u) => {
5260
- let c = i[u];
5261
- if (c !== void 0 && e.node(c).dummy) {
5262
- let h = e.predecessors(c);
5263
- h && h.forEach((f) => {
5264
- if (f === void 0) return;
5265
- let g = e.node(f);
5266
- g.dummy && (g.order < d || g.order > l) && dn(t, f, c);
5267
- });
5268
- }
5269
- });
5270
- }
5271
- function o(i, s) {
5272
- let a = -1, d = -1, l = 0;
5273
- return s.forEach((u, c) => {
5274
- if (e.node(u).dummy === "border") {
5275
- let h = e.predecessors(u);
5276
- if (h && h.length) {
5277
- let f = h[0];
5278
- if (f === void 0) return;
5279
- d = e.node(f).order, r5(s, l, c, a, d), l = c, a = d;
5280
- }
5281
- }
5282
- r5(s, l, s.length, d, i.length);
5283
- }), s;
5284
- }
5285
- return n.length && n.reduce(o), t;
5369
+ function Ke(e) {
5370
+ let n = w(e, "root", {}, "_root"), t = ut(e), r5 = Object.values(t), o = L(Math.max, r5) - 1, i = 2 * o + 1;
5371
+ e.graph().nestingRoot = n, e.edges().forEach((a) => e.edge(a).minlen *= i);
5372
+ let s = ct(e) + 1;
5373
+ e.children(_).forEach((a) => $e(e, n, i, s, o, t, a)), e.graph().nodeRankFactor = i;
5286
5374
  }
5287
- function xt(e, n) {
5288
- if (e.node(n).dummy) {
5289
- let t = e.predecessors(n);
5290
- if (t) return t.find((r5) => e.node(r5).dummy);
5375
+ function $e(e, n, t, r5, o, i, s) {
5376
+ var c;
5377
+ let a = e.children(s);
5378
+ if (!a.length) {
5379
+ s !== n && e.setEdge(n, s, { weight: 0, minlen: t });
5380
+ return;
5291
5381
  }
5382
+ let d = q(e, "_bt"), l = q(e, "_bb"), u = e.node(s);
5383
+ e.setParent(d, s), u.borderTop = d, e.setParent(l, s), u.borderBottom = l, a.forEach((h) => {
5384
+ var y;
5385
+ $e(e, n, t, r5, o, i, h);
5386
+ let f = e.node(h), g = f.borderTop ? f.borderTop : h, b = f.borderBottom ? f.borderBottom : h, m = f.borderTop ? r5 : 2 * r5, E = g !== b ? 1 : o - ((y = i[s]) != null ? y : 0) + 1;
5387
+ e.setEdge(d, g, { weight: m, minlen: E, nestingEdge: true }), e.setEdge(b, l, { weight: m, minlen: E, nestingEdge: true });
5388
+ }), e.parent(s) || e.setEdge(n, d, { weight: 0, minlen: o + ((c = i[s]) != null ? c : 0) });
5292
5389
  }
5293
- function dn(e, n, t) {
5294
- if (n > t) {
5295
- let o = n;
5296
- n = t, t = o;
5390
+ function ut(e) {
5391
+ let n = {};
5392
+ function t(r5, o) {
5393
+ let i = e.children(r5);
5394
+ i && i.length && i.forEach((s) => t(s, o + 1)), n[r5] = o;
5297
5395
  }
5298
- let r5 = e[n];
5299
- r5 || (e[n] = r5 = {}), r5[t] = true;
5396
+ return e.children(_).forEach((r5) => t(r5, 1)), n;
5300
5397
  }
5301
- function Tt(e, n, t) {
5302
- if (n > t) {
5303
- let o = n;
5304
- n = t, t = o;
5305
- }
5306
- let r5 = e[n];
5307
- return r5 !== void 0 && Object.hasOwn(r5, t);
5398
+ function ct(e) {
5399
+ return e.edges().reduce((n, t) => n + e.edge(t).weight, 0);
5308
5400
  }
5309
- function Ot(e, n, t, r5) {
5310
- let o = {}, i = {}, s = {};
5311
- return n.forEach((a) => {
5312
- a.forEach((d, l) => {
5313
- o[d] = d, i[d] = d, s[d] = l;
5314
- });
5315
- }), n.forEach((a) => {
5316
- let d = -1;
5317
- a.forEach((l) => {
5318
- let u = r5(l);
5319
- if (u && u.length) {
5320
- let c = u.sort((f, g) => {
5321
- let b = s[f], m = s[g];
5322
- return (b !== void 0 ? b : 0) - (m !== void 0 ? m : 0);
5323
- }), h = (c.length - 1) / 2;
5324
- for (let f = Math.floor(h), g = Math.ceil(h); f <= g; ++f) {
5325
- let b = c[f];
5326
- if (b === void 0) continue;
5327
- let m = s[b];
5328
- if (m !== void 0 && i[l] === l && d < m && !Tt(t, l, b)) {
5329
- let E = o[b];
5330
- E !== void 0 && (i[b] = l, i[l] = o[l] = E, d = m);
5331
- }
5332
- }
5333
- }
5334
- });
5335
- }), { root: o, align: i };
5401
+ function Je(e) {
5402
+ let n = e.graph();
5403
+ e.removeNode(n.nestingRoot), delete n.nestingRoot, e.edges().forEach((t) => {
5404
+ e.edge(t).nestingEdge && e.removeEdge(t);
5405
+ });
5336
5406
  }
5337
- function It(e, n, t, r5, o = false) {
5338
- let i = {}, s = Ct(e, n, t, o), a = o ? "borderLeft" : "borderRight";
5339
- function d(f, g) {
5340
- let b = s.nodes().slice(), m = {}, E = b.pop();
5341
- for (; E; ) {
5342
- if (m[E]) f(E);
5343
- else {
5344
- m[E] = true, b.push(E);
5345
- for (let y of g(E)) b.push(y);
5346
- }
5347
- E = b.pop();
5407
+ var Ze = ft;
5408
+ function ft(e) {
5409
+ function n(t) {
5410
+ let r5 = e.children(t), o = e.node(t);
5411
+ if (r5.length && r5.forEach(n), Object.hasOwn(o, "minRank")) {
5412
+ o.borderLeft = [], o.borderRight = [];
5413
+ for (let i = o.minRank, s = o.maxRank + 1; i < s; ++i) Qe(e, "borderLeft", "_bl", t, o, i), Qe(e, "borderRight", "_br", t, o, i);
5348
5414
  }
5349
5415
  }
5350
- function l(f) {
5351
- let g = s.inEdges(f);
5352
- g ? i[f] = g.reduce((b, m) => {
5353
- var I;
5354
- let E = (I = i[m.v]) != null ? I : 0, y = s.edge(m);
5355
- return Math.max(b, E + (y !== void 0 ? y : 0));
5356
- }, 0) : i[f] = 0;
5357
- }
5358
- function u(f) {
5359
- let g = s.outEdges(f), b = Number.POSITIVE_INFINITY;
5360
- g && (b = g.reduce((E, y) => {
5361
- let I = i[y.w], be = s.edge(y);
5362
- return Math.min(E, (I !== void 0 ? I : 0) - (be !== void 0 ? be : 0));
5363
- }, Number.POSITIVE_INFINITY));
5364
- let m = e.node(f);
5365
- b !== Number.POSITIVE_INFINITY && m.borderType !== a && (i[f] = Math.max(i[f] !== void 0 ? i[f] : 0, b));
5366
- }
5367
- function c(f) {
5368
- return s.predecessors(f) || [];
5369
- }
5370
- function h(f) {
5371
- return s.successors(f) || [];
5372
- }
5373
- return d(l, c), d(u, h), Object.keys(r5).forEach((f) => {
5374
- var b;
5375
- let g = t[f];
5376
- g !== void 0 && (i[f] = (b = i[g]) != null ? b : 0);
5377
- }), i;
5416
+ e.children(_).forEach(n);
5378
5417
  }
5379
- function Ct(e, n, t, r5) {
5380
- let o = new p(), i = e.graph(), s = jt(i.nodesep, i.edgesep, r5);
5381
- return n.forEach((a) => {
5382
- let d;
5383
- a.forEach((l) => {
5384
- let u = t[l];
5385
- if (u !== void 0) {
5386
- if (o.setNode(u), d !== void 0) {
5387
- let c = t[d];
5388
- if (c !== void 0) {
5389
- let h = o.edge(c, u);
5390
- o.setEdge(c, u, Math.max(s(e, l, d), h || 0));
5391
- }
5392
- }
5393
- d = l;
5394
- }
5395
- });
5396
- }), o;
5418
+ function Qe(e, n, t, r5, o, i) {
5419
+ let s = { width: 0, height: 0, rank: i, borderType: n }, a = o[n][i - 1], d = w(e, "border", s, t);
5420
+ o[n][i] = d, e.setParent(d, r5), a && e.setEdge(a, d, { weight: 1 });
5397
5421
  }
5398
- function Rt(e, n) {
5399
- return Object.values(n).reduce((t, r5) => {
5400
- let o = Number.NEGATIVE_INFINITY, i = Number.POSITIVE_INFINITY;
5401
- Object.entries(r5).forEach(([a, d]) => {
5402
- let l = St(e, a) / 2;
5403
- o = Math.max(d + l, o), i = Math.min(d - l, i);
5404
- });
5405
- let s = o - i;
5406
- return s < t[0] && (t = [s, r5]), t;
5407
- }, [Number.POSITIVE_INFINITY, null])[1];
5422
+ function nn(e) {
5423
+ var t;
5424
+ let n = (t = e.graph().rankdir) == null ? void 0 : t.toLowerCase();
5425
+ (n === "lr" || n === "rl") && rn(e);
5408
5426
  }
5409
- function Pt(e, n) {
5410
- let t = Object.values(n), r5 = L(Math.min, t), o = L(Math.max, t);
5411
- ["u", "d"].forEach((i) => {
5412
- ["l", "r"].forEach((s) => {
5413
- let a = i + s, d = e[a];
5414
- if (!d || d === n) return;
5415
- let l = Object.values(d), u = r5 - L(Math.min, l);
5416
- s !== "l" && (u = o - L(Math.max, l)), u && (e[a] = O(d, (c) => c + u));
5417
- });
5418
- });
5427
+ function tn(e) {
5428
+ var t;
5429
+ let n = (t = e.graph().rankdir) == null ? void 0 : t.toLowerCase();
5430
+ (n === "bt" || n === "rl") && bt(e), (n === "lr" || n === "rl") && (gt(e), rn(e));
5419
5431
  }
5420
- function Mt(e, n = void 0) {
5421
- let t = e.ul;
5422
- return t ? O(t, (r5, o) => {
5423
- var s, a;
5424
- if (n) {
5425
- let d = n.toLowerCase(), l = e[d];
5426
- if (l && l[o] !== void 0) return l[o];
5427
- }
5428
- let i = Object.values(e).map((d) => {
5429
- let l = d[o];
5430
- return l !== void 0 ? l : 0;
5431
- }).sort((d, l) => d - l);
5432
- return (((s = i[1]) != null ? s : 0) + ((a = i[2]) != null ? a : 0)) / 2;
5433
- }) : {};
5432
+ function rn(e) {
5433
+ e.nodes().forEach((n) => en(e.node(n))), e.edges().forEach((n) => en(e.edge(n)));
5434
5434
  }
5435
- function ln(e) {
5436
- let n = N(e), t = Object.assign(vt(e, n), _t(e, n)), r5 = {}, o;
5437
- ["u", "d"].forEach((s) => {
5438
- o = s === "u" ? n : Object.values(n).reverse(), ["l", "r"].forEach((a) => {
5439
- a === "r" && (o = o.map((c) => Object.values(c).reverse()));
5440
- let l = Ot(e, o, t, (c) => (s === "u" ? e.predecessors(c) : e.successors(c)) || []), u = It(e, o, l.root, l.align, a === "r");
5441
- a === "r" && (u = O(u, (c) => -c)), r5[s + a] = u;
5442
- });
5435
+ function en(e) {
5436
+ let n = e.width;
5437
+ e.width = e.height, e.height = n;
5438
+ }
5439
+ function bt(e) {
5440
+ e.nodes().forEach((n) => ne(e.node(n))), e.edges().forEach((n) => {
5441
+ var r5;
5442
+ let t = e.edge(n);
5443
+ (r5 = t.points) == null || r5.forEach(ne), Object.hasOwn(t, "y") && ne(t);
5443
5444
  });
5444
- let i = Rt(e, r5);
5445
- return Pt(r5, i), Mt(r5, e.graph().align);
5446
5445
  }
5447
- function jt(e, n, t) {
5448
- return (r5, o, i) => {
5449
- let s = r5.node(o), a = r5.node(i), d = 0, l;
5450
- if (d += s.width / 2, Object.hasOwn(s, "labelpos")) switch (s.labelpos.toLowerCase()) {
5451
- case "l":
5452
- l = -s.width / 2;
5453
- break;
5454
- case "r":
5455
- l = s.width / 2;
5456
- break;
5457
- }
5458
- if (l && (d += t ? l : -l), l = void 0, d += (s.dummy ? n : e) / 2, d += (a.dummy ? n : e) / 2, d += a.width / 2, Object.hasOwn(a, "labelpos")) switch (a.labelpos.toLowerCase()) {
5459
- case "l":
5460
- l = a.width / 2;
5461
- break;
5462
- case "r":
5463
- l = -a.width / 2;
5464
- break;
5465
- }
5466
- return l && (d += t ? l : -l), d;
5467
- };
5468
- }
5469
- function St(e, n) {
5470
- return e.node(n).width;
5471
- }
5472
- function un(e) {
5473
- e = A(e), Ft(e), Object.entries(ln(e)).forEach(([n, t]) => e.node(n).x = t);
5474
- }
5475
- function Ft(e) {
5476
- let n = N(e), t = e.graph(), r5 = t.ranksep, o = t.rankalign, i = 0;
5477
- n.forEach((s) => {
5478
- let a = s.reduce((d, l) => {
5479
- var c;
5480
- let u = (c = e.node(l).height) != null ? c : 0;
5481
- return d > u ? d : u;
5482
- }, 0);
5483
- s.forEach((d) => {
5484
- let l = e.node(d);
5485
- o === "top" ? l.y = i + l.height / 2 : o === "bottom" ? l.y = i + a - l.height / 2 : l.y = i + a / 2;
5486
- }), i += a + r5;
5487
- });
5446
+ function ne(e) {
5447
+ e.y = -e.y;
5488
5448
  }
5489
- function he(e, n = {}) {
5490
- let t = n.debugTiming ? P : M;
5491
- return t("layout", () => {
5492
- let r5 = t(" buildLayoutGraph", () => Xt(e));
5493
- return t(" runLayout", () => Dt(r5, t, n)), t(" updateInputGraph", () => At(e, r5)), r5;
5449
+ function gt(e) {
5450
+ e.nodes().forEach((n) => te(e.node(n))), e.edges().forEach((n) => {
5451
+ var r5;
5452
+ let t = e.edge(n);
5453
+ (r5 = t.points) == null || r5.forEach(te), Object.hasOwn(t, "x") && te(t);
5494
5454
  });
5495
5455
  }
5496
- function Dt(e, n, t) {
5497
- n(" makeSpaceForEdgeLabels", () => Ut(e)), n(" removeSelfEdges", () => rr(e)), n(" acyclic", () => je(e)), n(" nestingGraph.run", () => Ke(e)), n(" rank", () => Xe(A(e))), n(" injectEdgeLabelProxies", () => Kt(e)), n(" removeEmptyRanks", () => Oe(e)), n(" nestingGraph.cleanup", () => Je(e)), n(" normalizeRanks", () => Te(e)), n(" assignRankMinMax", () => $t(e)), n(" removeEdgeLabelProxies", () => Jt(e)), n(" normalize.run", () => Fe(e)), n(" parentDummyChains", () => Ue(e)), n(" addBorderSegments", () => Ze(e)), n(" order", () => B(e, t)), n(" insertSelfEdges", () => or(e)), n(" adjustCoordinateSystem", () => nn(e)), n(" position", () => un(e)), n(" positionSelfEdges", () => ir(e)), n(" removeBorderNodes", () => tr(e)), n(" normalize.undo", () => De(e)), n(" fixupEdgeLabelCoords", () => er(e)), n(" undoCoordinateSystem", () => tn(e)), n(" translateGraph", () => Qt(e)), n(" assignNodeIntersects", () => Zt(e)), n(" reversePoints", () => nr(e)), n(" acyclic.undo", () => Se(e));
5456
+ function te(e) {
5457
+ let n = e.x;
5458
+ e.x = e.y, e.y = n;
5498
5459
  }
5499
- function At(e, n) {
5500
- e.nodes().forEach((t) => {
5501
- let r5 = e.node(t), o = n.node(t);
5502
- r5 && (r5.x = o.x, r5.y = o.y, r5.order = o.order, r5.rank = o.rank, n.children(t).length && (r5.width = o.width, r5.height = o.height));
5503
- }), e.edges().forEach((t) => {
5504
- let r5 = e.edge(t), o = n.edge(t);
5505
- r5.points = o.points, Object.hasOwn(o, "x") && (r5.x = o.x, r5.y = o.y);
5506
- }), e.graph().width = n.graph().width, e.graph().height = n.graph().height;
5460
+ function re(e) {
5461
+ let n = {}, t = e.nodes().filter((d) => !e.children(d).length), r5 = t.map((d) => e.node(d).rank), o = L(Math.max, r5), i = k(o + 1).map(() => []);
5462
+ function s(d) {
5463
+ if (n[d]) return;
5464
+ n[d] = true;
5465
+ let l = e.node(d);
5466
+ i[l.rank].push(d);
5467
+ let u = e.successors(d);
5468
+ u && u.forEach(s);
5469
+ }
5470
+ return t.sort((d, l) => e.node(d).rank - e.node(l).rank).forEach(s), i;
5507
5471
  }
5508
- var Vt = ["nodesep", "edgesep", "ranksep", "marginx", "marginy"];
5509
- var Wt = { ranksep: 50, edgesep: 20, nodesep: 50, rankdir: "TB", rankalign: "center" };
5510
- var Bt = ["acyclicer", "ranker", "rankdir", "align", "rankalign"];
5511
- var Yt = ["width", "height", "rank"];
5512
- var cn = { width: 0, height: 0 };
5513
- var zt = ["minlen", "weight", "width", "height", "labeloffset"];
5514
- var Ht = { minlen: 1, weight: 1, width: 0, height: 0, labeloffset: 10, labelpos: "r" };
5515
- var qt = ["labelpos"];
5516
- function Xt(e) {
5517
- let n = new p({ multigraph: true, compound: true }), t = ce(e.graph());
5518
- return n.setGraph(Object.assign({}, Wt, ue(t, Vt), T(t, Bt))), e.nodes().forEach((r5) => {
5519
- let o = ce(e.node(r5)), i = ue(o, Yt);
5520
- Object.keys(cn).forEach((a) => {
5521
- i[a] === void 0 && (i[a] = cn[a]);
5522
- }), n.setNode(r5, i);
5523
- let s = e.parent(r5);
5524
- s !== void 0 && n.setParent(r5, s);
5525
- }), e.edges().forEach((r5) => {
5526
- let o = ce(e.edge(r5));
5527
- n.setEdge(r5, Object.assign({}, Ht, ue(o, zt), T(o, qt)));
5528
- }), n;
5472
+ function oe(e, n) {
5473
+ let t = 0;
5474
+ for (let r5 = 1; r5 < n.length; ++r5) t += mt(e, n[r5 - 1], n[r5]);
5475
+ return t;
5529
5476
  }
5530
- function Ut(e) {
5531
- let n = e.graph();
5532
- n.ranksep /= 2, e.edges().forEach((t) => {
5533
- let r5 = e.edge(t);
5534
- r5.minlen *= 2, r5.labelpos.toLowerCase() !== "c" && (n.rankdir === "TB" || n.rankdir === "BT" ? r5.width += r5.labeloffset : r5.height += r5.labeloffset);
5535
- });
5477
+ function mt(e, n, t) {
5478
+ let r5 = Re(t, t.map((l, u) => u)), o = n.flatMap((l) => {
5479
+ let u = e.outEdges(l);
5480
+ return u ? u.map((c) => ({ pos: r5[c.w], weight: e.edge(c).weight })).sort((c, h) => c.pos - h.pos) : [];
5481
+ }), i = 1;
5482
+ for (; i < t.length; ) i <<= 1;
5483
+ let s = 2 * i - 1;
5484
+ i -= 1;
5485
+ let a = new Array(s).fill(0), d = 0;
5486
+ return o.forEach((l) => {
5487
+ let u = l.pos + i;
5488
+ a[u] += l.weight;
5489
+ let c = 0;
5490
+ for (; u > 0; ) u % 2 && (c += a[u + 1]), u = u - 1 >> 1, a[u] += l.weight;
5491
+ d += l.weight * c;
5492
+ }), d;
5536
5493
  }
5537
- function Kt(e) {
5538
- e.edges().forEach((n) => {
5539
- let t = e.edge(n);
5540
- if (t.width && t.height) {
5541
- let r5 = e.node(n.v), i = { rank: (e.node(n.w).rank - r5.rank) / 2 + r5.rank, e: n };
5542
- w(e, "edge-proxy", i, "_ep");
5494
+ function ie(e, n = []) {
5495
+ return n.map((t) => {
5496
+ let r5 = e.inEdges(t);
5497
+ if (!r5 || !r5.length) return { v: t };
5498
+ {
5499
+ let o = r5.reduce((i, s) => {
5500
+ let a = e.edge(s), d = e.node(s.v);
5501
+ return { sum: i.sum + a.weight * d.order, weight: i.weight + a.weight };
5502
+ }, { sum: 0, weight: 0 });
5503
+ return { v: t, barycenter: o.sum / o.weight, weight: o.weight };
5543
5504
  }
5544
5505
  });
5545
5506
  }
5546
- function $t(e) {
5547
- let n = 0;
5548
- e.nodes().forEach((t) => {
5549
- let r5 = e.node(t);
5550
- r5.borderTop && (r5.minRank = e.node(r5.borderTop).rank, r5.maxRank = e.node(r5.borderBottom).rank, n = Math.max(n, r5.maxRank));
5551
- }), e.graph().maxRank = n;
5552
- }
5553
- function Jt(e) {
5554
- e.nodes().forEach((n) => {
5555
- let t = e.node(n);
5556
- if (t.dummy === "edge-proxy") {
5557
- let r5 = t;
5558
- e.edge(r5.e).labelRank = t.rank, e.removeNode(n);
5559
- }
5507
+ function se(e, n) {
5508
+ let t = {};
5509
+ e.forEach((o, i) => {
5510
+ let s = { indegree: 0, in: [], out: [], vs: [o.v], i };
5511
+ o.barycenter !== void 0 && (s.barycenter = o.barycenter, s.weight = o.weight), t[o.v] = s;
5512
+ }), n.edges().forEach((o) => {
5513
+ let i = t[o.v], s = t[o.w];
5514
+ i !== void 0 && s !== void 0 && (s.indegree++, i.out.push(s));
5560
5515
  });
5516
+ let r5 = Object.values(t).filter((o) => !o.indegree);
5517
+ return Et(r5);
5561
5518
  }
5562
- function Qt(e) {
5563
- let n = Number.POSITIVE_INFINITY, t = 0, r5 = Number.POSITIVE_INFINITY, o = 0, i = e.graph(), s = i.marginx || 0, a = i.marginy || 0;
5564
- function d(l) {
5565
- let u = l.x, c = l.y, h = l.width, f = l.height;
5566
- n = Math.min(n, u - h / 2), t = Math.max(t, u + h / 2), r5 = Math.min(r5, c - f / 2), o = Math.max(o, c + f / 2);
5519
+ function Et(e) {
5520
+ let n = [];
5521
+ function t(o) {
5522
+ return (i) => {
5523
+ i.merged || (i.barycenter === void 0 || o.barycenter === void 0 || i.barycenter >= o.barycenter) && Lt(o, i);
5524
+ };
5567
5525
  }
5568
- e.nodes().forEach((l) => d(e.node(l))), e.edges().forEach((l) => {
5569
- let u = e.edge(l);
5570
- Object.hasOwn(u, "x") && d(u);
5571
- }), n -= s, r5 -= a, e.nodes().forEach((l) => {
5572
- let u = e.node(l);
5573
- u.x -= n, u.y -= r5;
5574
- }), e.edges().forEach((l) => {
5575
- let u = e.edge(l);
5576
- u.points.forEach((c) => {
5577
- c.x -= n, c.y -= r5;
5578
- }), Object.hasOwn(u, "x") && (u.x -= n), Object.hasOwn(u, "y") && (u.y -= r5);
5579
- }), i.width = t - n + s, i.height = o - r5 + a;
5526
+ function r5(o) {
5527
+ return (i) => {
5528
+ i.in.push(o), --i.indegree === 0 && e.push(i);
5529
+ };
5530
+ }
5531
+ for (; e.length; ) {
5532
+ let o = e.pop();
5533
+ n.push(o), o.in.reverse().forEach(t(o)), o.out.forEach(r5(o));
5534
+ }
5535
+ return n.filter((o) => !o.merged).map((o) => T(o, ["vs", "i", "barycenter", "weight"]));
5580
5536
  }
5581
- function Zt(e) {
5582
- e.edges().forEach((n) => {
5583
- let t = e.edge(n), r5 = e.node(n.v), o = e.node(n.w), i, s;
5584
- t.points ? (i = t.points[0], s = t.points[t.points.length - 1]) : (t.points = [], i = o, s = r5), t.points.unshift(H(r5, i)), t.points.push(H(o, s));
5585
- });
5537
+ function Lt(e, n) {
5538
+ let t = 0, r5 = 0;
5539
+ e.weight && (t += e.barycenter * e.weight, r5 += e.weight), n.weight && (t += n.barycenter * n.weight, r5 += n.weight), e.vs = n.vs.concat(e.vs), e.barycenter = t / r5, e.weight = r5, e.i = Math.min(n.i, e.i), n.merged = true;
5586
5540
  }
5587
- function er(e) {
5588
- e.edges().forEach((n) => {
5589
- let t = e.edge(n);
5590
- if (Object.hasOwn(t, "x")) switch ((t.labelpos === "l" || t.labelpos === "r") && (t.width -= t.labeloffset), t.labelpos) {
5591
- case "l":
5592
- t.x -= t.width / 2 + t.labeloffset;
5593
- break;
5594
- case "r":
5595
- t.x += t.width / 2 + t.labeloffset;
5596
- break;
5597
- }
5541
+ function ae(e, n) {
5542
+ let t = Ce(e, (u) => Object.hasOwn(u, "barycenter")), r5 = t.lhs, o = t.rhs.sort((u, c) => c.i - u.i), i = [], s = 0, a = 0, d = 0;
5543
+ r5.sort(yt(!!n)), d = on(i, o, d), r5.forEach((u) => {
5544
+ d += u.vs.length, i.push(u.vs), s += u.barycenter * u.weight, a += u.weight, d = on(i, o, d);
5598
5545
  });
5546
+ let l = { vs: i.flat(1) };
5547
+ return a && (l.barycenter = s / a, l.weight = a), l;
5599
5548
  }
5600
- function nr(e) {
5601
- e.edges().forEach((n) => {
5602
- let t = e.edge(n);
5603
- t.reversed && t.points.reverse();
5604
- });
5549
+ function on(e, n, t) {
5550
+ let r5;
5551
+ for (; n.length && (r5 = n[n.length - 1]).i <= t; ) n.pop(), e.push(r5.vs), t++;
5552
+ return t;
5605
5553
  }
5606
- function tr(e) {
5607
- e.nodes().forEach((n) => {
5608
- if (e.children(n).length) {
5609
- let t = e.node(n), r5 = e.node(t.borderTop), o = e.node(t.borderBottom), i = e.node(t.borderLeft[t.borderLeft.length - 1]), s = e.node(t.borderRight[t.borderRight.length - 1]);
5610
- t.width = Math.abs(s.x - i.x), t.height = Math.abs(o.y - r5.y), t.x = i.x + t.width / 2, t.y = r5.y + t.height / 2;
5611
- }
5612
- }), e.nodes().forEach((n) => {
5613
- e.node(n).dummy === "border" && e.removeNode(n);
5614
- });
5554
+ function yt(e) {
5555
+ return (n, t) => n.barycenter < t.barycenter ? -1 : n.barycenter > t.barycenter ? 1 : e ? t.i - n.i : n.i - t.i;
5615
5556
  }
5616
- function rr(e) {
5617
- e.edges().forEach((n) => {
5618
- if (n.v === n.w) {
5619
- let t = e.node(n.v);
5620
- t.selfEdges || (t.selfEdges = []), t.selfEdges.push({ e: n, label: e.edge(n) }), e.removeEdge(n);
5557
+ function W(e, n, t, r5) {
5558
+ let o = e.children(n), i = e.node(n), s = i ? i.borderLeft : void 0, a = i ? i.borderRight : void 0, d = {};
5559
+ s && (o = o.filter((h) => h !== s && h !== a));
5560
+ let l = ie(e, o);
5561
+ l.forEach((h) => {
5562
+ if (e.children(h.v).length) {
5563
+ let f = W(e, h.v, t, r5);
5564
+ d[h.v] = f, Object.hasOwn(f, "barycenter") && Nt(h, f);
5621
5565
  }
5622
5566
  });
5623
- }
5624
- function or(e) {
5625
- N(e).forEach((t) => {
5626
- let r5 = 0;
5627
- t.forEach((o, i) => {
5628
- let s = e.node(o);
5629
- s.order = i + r5, (s.selfEdges || []).forEach((a) => {
5630
- w(e, "selfedge", { width: a.label.width, height: a.label.height, rank: s.rank, order: i + ++r5, e: a.e, label: a.label }, "_se");
5631
- }), delete s.selfEdges;
5632
- });
5567
+ let u = se(l, t);
5568
+ wt(u, d);
5569
+ let c = ae(u, r5);
5570
+ if (s && a) {
5571
+ c.vs = [s, c.vs, a].flat(1);
5572
+ let h = e.predecessors(s);
5573
+ if (h && h.length) {
5574
+ let f = e.node(h[0]), g = e.predecessors(a), b = e.node(g[0]);
5575
+ Object.hasOwn(c, "barycenter") || (c.barycenter = 0, c.weight = 0), c.barycenter = (c.barycenter * c.weight + f.order + b.order) / (c.weight + 2), c.weight += 2;
5576
+ }
5577
+ }
5578
+ return c;
5579
+ }
5580
+ function wt(e, n) {
5581
+ e.forEach((t) => {
5582
+ t.vs = t.vs.flatMap((r5) => n[r5] ? n[r5].vs : r5);
5633
5583
  });
5634
5584
  }
5635
- function ir(e) {
5636
- e.nodes().forEach((n) => {
5637
- let t = e.node(n);
5638
- if (t.dummy === "selfedge") {
5639
- let r5 = t, o = e.node(r5.e.v), i = o.x + o.width / 2, s = o.y, a = t.x - i, d = o.height / 2;
5640
- e.setEdge(r5.e, r5.label), e.removeNode(n), r5.label.points = [{ x: i + 2 * a / 3, y: s - d }, { x: i + 5 * a / 6, y: s - d }, { x: i + a, y: s }, { x: i + 5 * a / 6, y: s + d }, { x: i + 2 * a / 3, y: s + d }], r5.label.x = t.x, r5.label.y = t.y;
5585
+ function Nt(e, n) {
5586
+ e.barycenter !== void 0 ? (e.barycenter = (e.barycenter * e.weight + n.barycenter * n.weight) / (e.weight + n.weight), e.weight += n.weight) : (e.barycenter = n.barycenter, e.weight = n.weight);
5587
+ }
5588
+ function de(e, n, t, r5) {
5589
+ r5 || (r5 = e.nodes());
5590
+ let o = Gt(e), i = new p({ compound: true }).setGraph({ root: o }).setDefaultNodeLabel((s) => e.node(s));
5591
+ return r5.forEach((s) => {
5592
+ let a = e.node(s), d = e.parent(s);
5593
+ if (a.rank === n || a.minRank <= n && n <= a.maxRank) {
5594
+ i.setNode(s), i.setParent(s, d || o);
5595
+ let l = e[t](s);
5596
+ l && l.forEach((u) => {
5597
+ let c = u.v === s ? u.w : u.v, h = i.edge(c, s), f = h !== void 0 ? h.weight : 0;
5598
+ i.setEdge(c, s, { weight: e.edge(u).weight + f });
5599
+ }), Object.hasOwn(a, "minRank") && i.setNode(s, { borderLeft: a.borderLeft[n], borderRight: a.borderRight[n] });
5641
5600
  }
5642
- });
5601
+ }), i;
5643
5602
  }
5644
- function ue(e, n) {
5645
- return O(T(e, n), Number);
5603
+ function Gt(e) {
5604
+ let n;
5605
+ for (; e.hasNode(n = j("_root")); ) ;
5606
+ return n;
5646
5607
  }
5647
- function ce(e) {
5648
- let n = {};
5649
- return e && Object.entries(e).forEach(([t, r5]) => {
5650
- typeof t == "string" && (t = t.toLowerCase()), n[t] = r5;
5651
- }), n;
5608
+ function le(e, n, t) {
5609
+ let r5 = {}, o;
5610
+ t.forEach((i) => {
5611
+ let s = e.parent(i), a, d;
5612
+ for (; s; ) {
5613
+ if (a = e.parent(s), a ? (d = r5[a], r5[a] = s) : (d = o, o = s), d && d !== s) {
5614
+ n.setEdge(d, s);
5615
+ return;
5616
+ }
5617
+ s = a;
5618
+ }
5619
+ });
5652
5620
  }
5653
- function fe(e) {
5654
- let n = N(e), t = new p({ compound: true, multigraph: true }).setGraph({});
5655
- return e.nodes().forEach((r5) => {
5656
- t.setNode(r5, { label: r5 }), t.setParent(r5, "layer" + e.node(r5).rank);
5657
- }), e.edges().forEach((r5) => t.setEdge(r5.v, r5.w, {}, r5.name)), n.forEach((r5, o) => {
5658
- let i = "layer" + o;
5659
- t.setNode(i, { rank: "same" }), r5.reduce((s, a) => (t.setEdge(s, a, { style: "invis" }), a));
5660
- }), t;
5621
+ function B(e, n = {}) {
5622
+ if (typeof n.customOrder == "function") {
5623
+ n.customOrder(e, B);
5624
+ return;
5625
+ }
5626
+ let t = X(e), r5 = sn(e, k(1, t + 1), "inEdges"), o = sn(e, k(t - 1, -1, -1), "outEdges"), i = re(e);
5627
+ if (an(e, i), n.disableOptimalOrderHeuristic) return;
5628
+ let s = Number.POSITIVE_INFINITY, a, d = n.constraints || [];
5629
+ for (let l = 0, u = 0; u < 4; ++l, ++u) {
5630
+ kt(l % 2 ? r5 : o, l % 4 >= 2, d), i = N(e);
5631
+ let c = oe(e, i);
5632
+ c < s ? (u = 0, a = Object.assign({}, i), s = c) : c === s && (a = structuredClone(i));
5633
+ }
5634
+ an(e, a);
5661
5635
  }
5662
- var sr = { graphlib: z, version: U, layout: he, debug: fe, util: { time: P, notime: M } };
5663
- var To = sr;
5664
-
5665
- // src/blocks/autoLayout.ts
5666
- function ensureGrid(items, edges, rankdir) {
5667
- const allPlaced = items.length > 0 && items.every((n) => n.col !== void 0 && n.row !== void 0);
5668
- if (allPlaced) {
5669
- return items.map((n) => ({ ...n, col: n.col, row: n.row }));
5636
+ function sn(e, n, t) {
5637
+ let r5 = /* @__PURE__ */ new Map(), o = (i, s) => {
5638
+ r5.has(i) || r5.set(i, []), r5.get(i).push(s);
5639
+ };
5640
+ for (let i of e.nodes()) {
5641
+ let s = e.node(i);
5642
+ if (typeof s.rank == "number" && o(s.rank, i), typeof s.minRank == "number" && typeof s.maxRank == "number") for (let a = s.minRank; a <= s.maxRank; a++) a !== s.rank && o(a, i);
5670
5643
  }
5671
- const grid = autoGrid(
5672
- items.map((n) => n.id),
5673
- edges,
5674
- rankdir
5675
- );
5676
- return items.map((n) => {
5677
- const g = grid.get(n.id) ?? { col: 1, row: 1 };
5678
- return { ...n, col: g.col, row: g.row };
5644
+ return n.map(function(i) {
5645
+ return de(e, i, t, r5.get(i) || []);
5679
5646
  });
5680
5647
  }
5681
- function autoGrid(ids, edges, rankdir) {
5682
- const idSet = new Set(ids);
5683
- const g = new To.graphlib.Graph();
5684
- g.setGraph({ rankdir, nodesep: 16, ranksep: 16, marginx: 0, marginy: 0 });
5685
- g.setDefaultEdgeLabel(() => ({}));
5686
- for (const id of ids) g.setNode(id, { width: 10, height: 10 });
5687
- for (const e of edges) {
5688
- if (e.from !== e.to && idSet.has(e.from) && idSet.has(e.to)) g.setEdge(e.from, e.to);
5689
- }
5690
- To.layout(g);
5691
- const pos3 = ids.map((id) => {
5692
- const n = g.node(id);
5693
- return { id, x: Math.round(n?.x ?? 0), y: Math.round(n?.y ?? 0) };
5648
+ function kt(e, n, t) {
5649
+ let r5 = new p();
5650
+ e.forEach(function(o) {
5651
+ t.forEach((a) => r5.setEdge(a.left, a.right));
5652
+ let i = o.graph().root, s = W(o, i, r5, n);
5653
+ s.vs.forEach((a, d) => o.node(a).order = d), le(o, r5, s.vs);
5694
5654
  });
5695
- const out = /* @__PURE__ */ new Map();
5696
- if (rankdir === "TB") {
5697
- const ranks = [...new Set(pos3.map((p2) => p2.y))].sort((a, b) => a - b);
5698
- ranks.forEach((yv, ri) => {
5699
- pos3.filter((p2) => p2.y === yv).sort((a, b) => a.x - b.x).forEach((p2, ci) => out.set(p2.id, { col: ci + 1, row: ri + 1 }));
5700
- });
5701
- } else {
5702
- const ranks = [...new Set(pos3.map((p2) => p2.x))].sort((a, b) => a - b);
5703
- ranks.forEach((xv, ci) => {
5704
- pos3.filter((p2) => p2.x === xv).sort((a, b) => a.y - b.y).forEach((p2, ri) => out.set(p2.id, { col: ci + 1, row: ri + 1 }));
5655
+ }
5656
+ function an(e, n) {
5657
+ Object.values(n).forEach((t) => t.forEach((r5, o) => e.node(r5).order = o));
5658
+ }
5659
+ function vt(e, n) {
5660
+ let t = {};
5661
+ function r5(o, i) {
5662
+ let s = 0, a = 0, d = o.length, l = i[i.length - 1];
5663
+ return i.forEach((u, c) => {
5664
+ let h = xt(e, u), f = h ? e.node(h).order : d;
5665
+ (h || u === l) && (i.slice(a, c + 1).forEach((g) => {
5666
+ let b = e.predecessors(g);
5667
+ b && b.forEach((m) => {
5668
+ let E = e.node(m), y = E.order;
5669
+ (y < s || f < y) && !(E.dummy && e.node(g).dummy) && dn(t, m, g);
5670
+ });
5671
+ }), a = c + 1, s = f);
5672
+ }), i;
5673
+ }
5674
+ return n.length && n.reduce(r5), t;
5675
+ }
5676
+ function _t(e, n) {
5677
+ let t = {};
5678
+ function r5(i, s, a, d, l) {
5679
+ k(s, a).forEach((u) => {
5680
+ let c = i[u];
5681
+ if (c !== void 0 && e.node(c).dummy) {
5682
+ let h = e.predecessors(c);
5683
+ h && h.forEach((f) => {
5684
+ if (f === void 0) return;
5685
+ let g = e.node(f);
5686
+ g.dummy && (g.order < d || g.order > l) && dn(t, f, c);
5687
+ });
5688
+ }
5705
5689
  });
5706
5690
  }
5707
- return out;
5691
+ function o(i, s) {
5692
+ let a = -1, d = -1, l = 0;
5693
+ return s.forEach((u, c) => {
5694
+ if (e.node(u).dummy === "border") {
5695
+ let h = e.predecessors(u);
5696
+ if (h && h.length) {
5697
+ let f = h[0];
5698
+ if (f === void 0) return;
5699
+ d = e.node(f).order, r5(s, l, c, a, d), l = c, a = d;
5700
+ }
5701
+ }
5702
+ r5(s, l, s.length, d, i.length);
5703
+ }), s;
5704
+ }
5705
+ return n.length && n.reduce(o), t;
5708
5706
  }
5709
-
5710
- // src/blocks/flow.ts
5711
- var AI_CHIP = {
5712
- agent: "AGENT",
5713
- llm: "LLM",
5714
- tool: "TOOL",
5715
- human: "HUMAN",
5716
- memory: "MEMORY"
5717
- };
5718
- function flowRevealOrder(nodes, edges) {
5719
- const ids = new Set(nodes.map((n) => n.id));
5720
- const indeg = /* @__PURE__ */ new Map();
5721
- const outs = /* @__PURE__ */ new Map();
5722
- for (const n of nodes) {
5723
- indeg.set(n.id, 0);
5724
- outs.set(n.id, []);
5707
+ function xt(e, n) {
5708
+ if (e.node(n).dummy) {
5709
+ let t = e.predecessors(n);
5710
+ if (t) return t.find((r5) => e.node(r5).dummy);
5725
5711
  }
5726
- for (const e of edges) {
5727
- if (!ids.has(e.from) || !ids.has(e.to) || e.from === e.to) continue;
5728
- indeg.set(e.to, (indeg.get(e.to) ?? 0) + 1);
5729
- outs.get(e.from)?.push(e.to);
5712
+ }
5713
+ function dn(e, n, t) {
5714
+ if (n > t) {
5715
+ let o = n;
5716
+ n = t, t = o;
5730
5717
  }
5731
- let roots = nodes.filter((n) => n.kind === "start").map((n) => n.id);
5732
- if (roots.length === 0) roots = nodes.filter((n) => (indeg.get(n.id) ?? 0) === 0).map((n) => n.id);
5733
- if (roots.length === 0 && nodes[0] !== void 0) roots = [nodes[0].id];
5734
- const order = /* @__PURE__ */ new Map();
5735
- const queue = [...roots];
5736
- while (queue.length > 0) {
5737
- const id = queue.shift();
5738
- if (order.has(id)) continue;
5739
- order.set(id, order.size);
5740
- for (const to of outs.get(id) ?? []) {
5741
- const d = (indeg.get(to) ?? 0) - 1;
5742
- indeg.set(to, d);
5743
- if (d <= 0 && !order.has(to)) queue.push(to);
5744
- }
5718
+ let r5 = e[n];
5719
+ r5 || (e[n] = r5 = {}), r5[t] = true;
5720
+ }
5721
+ function Tt(e, n, t) {
5722
+ if (n > t) {
5723
+ let o = n;
5724
+ n = t, t = o;
5745
5725
  }
5746
- for (const n of nodes) if (!order.has(n.id)) order.set(n.id, order.size);
5747
- return order;
5726
+ let r5 = e[n];
5727
+ return r5 !== void 0 && Object.hasOwn(r5, t);
5748
5728
  }
5749
- var ERR_LABEL_RE = /^(no|fail|failed|error|reject|rejected)\b/i;
5750
- var CELL_W = 160;
5751
- var CELL_H = 64;
5752
- var NODE_W = 150;
5753
- var NODE_H = 52;
5754
- function renderFlowSvg(data) {
5755
- const edges = data.edges ?? [];
5756
- const groups = data.groups ?? [];
5757
- const rawNodes = data.nodes ?? [];
5758
- const quick = !(rawNodes.length > 0 && rawNodes.every((n) => n.col !== void 0 && n.row !== void 0));
5759
- const nodes = ensureGrid(rawNodes, edges, data.dir ?? "LR");
5760
- const cellW = CELL_W;
5761
- const cellH = CELL_H;
5762
- const gapX = 56;
5763
- const gapY = 48;
5764
- const nestPad = nestingPads(groups);
5765
- const padX = (groups.length > 0 ? GROUP_PADS.padX : 22) + nestPad.padX;
5766
- const padTop = (groups.length > 0 ? GROUP_PADS.padTop : 22) + nestPad.padTop;
5767
- const padBot = (groups.length > 0 ? GROUP_PADS.padBot : 18) + nestPad.padBot;
5768
- const gx = groupExtent(groups);
5769
- const cols = Math.max(1, ...nodes.map((n) => n.col + ((n.w ?? 1) - 1)), gx.cols);
5770
- const rows = Math.max(1, ...nodes.map((n) => n.row), gx.rows);
5771
- const xOf = (c) => padX + (c - 1) * (cellW + gapX);
5772
- const yOf = (r5) => padTop + (r5 - 1) * (cellH + gapY);
5773
- const cellFor = (n) => ({
5774
- x: xOf(n.col),
5775
- y: yOf(n.row),
5776
- w: (n.w ?? 1) * cellW + ((n.w ?? 1) - 1) * gapX,
5777
- h: cellH
5778
- });
5779
- const boxFor = (n) => {
5780
- const c = cellFor(n);
5781
- if ((n.kind ?? "process") === "decision") return c;
5782
- const dx = (cellW - NODE_W) / 2;
5783
- const dy = (cellH - NODE_H) / 2;
5784
- return { x: c.x + dx, y: c.y + dy, w: c.w - dx * 2, h: NODE_H };
5785
- };
5786
- const byId = new Map(nodes.map((n) => [n.id, n]));
5787
- const width = padX * 2 + cols * cellW + (cols - 1) * gapX;
5788
- const height = padTop + rows * cellH + (rows - 1) * gapY + padBot;
5789
- const isErrEdge = (e) => e.kind === "error" || ERR_LABEL_RE.test(e.label ?? "");
5790
- const errTargets = new Set(edges.filter(isErrEdge).map((e) => e.to));
5791
- const accentIds = new Set(
5792
- nodes.filter((n) => n.kind === "end" && !errTargets.has(n.id) && !ERR_LABEL_RE.test(n.label)).map((n) => n.id)
5793
- );
5794
- const gridMeta = gridMetaAttrs({ quick, cols, rows, cellW, cellH, gapX, gapY, padX, padTop });
5795
- const a11y = svgName("Flowchart", data.title, [countPhrase(nodes.length, "step")]);
5796
- let s = `<svg viewBox="0 0 ${width} ${height}"${a11y.attrs}${gridMeta}>${a11y.title}`;
5797
- if (groups.length > 0) s += gridGroupsSvg(groups, { xOf, yOf, cellW, cellH, gapX, gapY, skin: true });
5798
- const used = { plain: false, dashed: false, error: false, accent: false };
5799
- const pending = [];
5800
- const lanes = edgeLanes(edges);
5801
- const order = flowRevealOrder(nodes, edges);
5802
- const stepOf = (id) => order.get(id) ?? 0;
5803
- const entries = entryPortOffsets(edges, (id) => {
5804
- const n = byId.get(id);
5805
- return n !== void 0 ? boxFor(n) : void 0;
5806
- });
5807
- s += `<g${bl("edges")}>`;
5808
- edges.forEach((e, ei) => {
5809
- const A2 = byId.get(e.from);
5810
- const B3 = byId.get(e.to);
5811
- if (!A2 || !B3) return;
5812
- const p2 = ortho(boxFor(A2), boxFor(B3), lanes[ei] ?? 0, entries[ei] ?? 0);
5813
- const isErr = isErrEdge(e);
5814
- const isAccent = !isErr && accentIds.has(e.to);
5815
- const isDashed = !isErr && e.kind === "dashed";
5816
- const stroke = isErr ? "var(--negative)" : isAccent ? "var(--accent)" : "var(--muted)";
5817
- const marker2 = isErr ? "skErr" : isAccent ? "skAccent" : isDashed ? "skOpen" : "skArrow";
5818
- const sw = isAccent ? 1.75 : 1.5;
5819
- const dash = isDashed ? ' stroke-dasharray="5 4"' : "";
5820
- if (isErr) used.error = true;
5821
- else if (isAccent) used.accent = true;
5822
- else if (isDashed) used.dashed = true;
5823
- else used.plain = true;
5824
- const reveal = Math.max(stepOf(e.from), stepOf(e.to));
5825
- s += `<path d="${p2.d}" fill="none" stroke="${stroke}" stroke-width="${sw}"${dash} marker-end="url(#${marker2})"${bp(`edges.${ei}`)}${revealAttr(reveal)}/>`;
5826
- pending.push({
5827
- lx: p2.lx,
5828
- ly: p2.ly,
5829
- ...e.label !== void 0 ? { label: e.label } : {},
5830
- err: isErr,
5831
- accent: isAccent,
5832
- path: `edges.${ei}`,
5833
- reveal
5729
+ function Ot(e, n, t, r5) {
5730
+ let o = {}, i = {}, s = {};
5731
+ return n.forEach((a) => {
5732
+ a.forEach((d, l) => {
5733
+ o[d] = d, i[d] = d, s[d] = l;
5834
5734
  });
5835
- });
5836
- s += `</g>`;
5837
- const kindsUsed = /* @__PURE__ */ new Set();
5838
- s += `<g${bl("nodes")}>`;
5839
- nodes.forEach((n, ni) => {
5840
- const kind = n.kind ?? "process";
5841
- kindsUsed.add(kind);
5842
- const r5 = boxFor(n);
5843
- const cx = r5.x + r5.w / 2;
5844
- const cy = r5.y + r5.h / 2;
5845
- const accent = accentIds.has(n.id);
5846
- const chip3 = AI_CHIP[kind];
5847
- const secondary2 = kind === "start" || kind === "memory";
5848
- const stroke = accent ? "var(--accent)" : secondary2 ? "var(--rule-solid)" : "var(--ink)";
5849
- const sw = accent ? 1.5 : secondary2 ? 1 : 1.5;
5850
- const fill = accent ? "var(--accent-tint)" : secondary2 ? "var(--paper-2)" : "var(--paper)";
5851
- const dash = kind === "human" ? ' stroke-dasharray="4 3"' : "";
5852
- let shape;
5853
- if (kind === "decision") {
5854
- shape = `<polygon points="${cx},${r5.y} ${r5.x + r5.w},${cy} ${cx},${r5.y + r5.h} ${r5.x},${cy}" fill="${fill}" stroke="${stroke}" stroke-width="${sw}" stroke-linejoin="round"/>`;
5855
- } else if (kind === "start" || kind === "end") {
5856
- shape = `<rect x="${r5.x}" y="${r5.y}" width="${r5.w}" height="${r5.h}" rx="${r5.h / 2}" fill="${fill}" stroke="${stroke}" stroke-width="${sw}"/>`;
5857
- } else {
5858
- shape = `<rect x="${r5.x}" y="${r5.y}" width="${r5.w}" height="${r5.h}" rx="4" fill="${fill}" stroke="${stroke}" stroke-width="${sw}"${dash}/>`;
5859
- }
5860
- if (chip3 !== void 0) {
5861
- shape += `<text x="${r5.x + 8}" y="${r5.y + 11}" class="blk-chip t-sub">${chip3}</text>`;
5862
- }
5863
- const nl = n.label.indexOf("\n");
5864
- const name = nl >= 0 ? n.label.slice(0, nl) : n.label;
5865
- const sub = nl >= 0 ? n.label.slice(nl + 1).replace(/\s+/g, " ").trim() : "";
5866
- const maxChars = kind === "decision" ? 18 : 20;
5867
- const lines = sub.length > 0 ? wrapText(name, maxChars, 1) : wrapText(name, maxChars, 2);
5868
- const tone = accent ? " c-accent" : "";
5869
- const dy = chip3 !== void 0 ? 4 : 0;
5870
- let texts = "";
5871
- if (sub.length > 0) {
5872
- texts = `<text x="${cx}" y="${cy - 1 + dy}" class="fc-label t-name${tone}">${escapeHtml(lines[0] ?? name)}</text><text x="${cx}" y="${cy + 12 + dy}" class="fc-sub t-sub" text-anchor="middle">${escapeHtml(sub)}</text>`;
5873
- } else {
5874
- texts = lines.map(
5875
- (ln2, j2) => `<text x="${cx}" y="${cy + 4.5 + dy - (lines.length - 1) * 7.5 + j2 * 15}" class="fc-label t-name${tone}">${escapeHtml(ln2)}</text>`
5876
- ).join("");
5735
+ }), n.forEach((a) => {
5736
+ let d = -1;
5737
+ a.forEach((l) => {
5738
+ let u = r5(l);
5739
+ if (u && u.length) {
5740
+ let c = u.sort((f, g) => {
5741
+ let b = s[f], m = s[g];
5742
+ return (b !== void 0 ? b : 0) - (m !== void 0 ? m : 0);
5743
+ }), h = (c.length - 1) / 2;
5744
+ for (let f = Math.floor(h), g = Math.ceil(h); f <= g; ++f) {
5745
+ let b = c[f];
5746
+ if (b === void 0) continue;
5747
+ let m = s[b];
5748
+ if (m !== void 0 && i[l] === l && d < m && !Tt(t, l, b)) {
5749
+ let E = o[b];
5750
+ E !== void 0 && (i[b] = l, i[l] = o[l] = E, d = m);
5751
+ }
5752
+ }
5753
+ }
5754
+ });
5755
+ }), { root: o, align: i };
5756
+ }
5757
+ function It(e, n, t, r5, o = false) {
5758
+ let i = {}, s = Ct(e, n, t, o), a = o ? "borderLeft" : "borderRight";
5759
+ function d(f, g) {
5760
+ let b = s.nodes().slice(), m = {}, E = b.pop();
5761
+ for (; E; ) {
5762
+ if (m[E]) f(E);
5763
+ else {
5764
+ m[E] = true, b.push(E);
5765
+ for (let y of g(E)) b.push(y);
5766
+ }
5767
+ E = b.pop();
5877
5768
  }
5878
- s += `<g${bp(`nodes.${ni}`)}${nodeCellAttrs(n.col, n.row, n.w ?? 1)}${revealAttr(stepOf(n.id))}>${shape}${texts}</g>`;
5879
- });
5880
- s += `</g>`;
5881
- const { overlay, legend: steps } = edgeLabelLayer(pending, nodes.map((n) => boxFor(n)), { skin: true });
5882
- s += overlay;
5883
- s += `</svg>`;
5884
- const items = [];
5885
- if (kindsUsed.has("start")) items.push({ swatch: "node-fill2", label: "start" });
5886
- if (kindsUsed.has("process")) items.push({ swatch: "node", label: "step" });
5887
- if (kindsUsed.has("decision")) items.push({ swatch: "node", label: "decision (diamond)" });
5888
- if (kindsUsed.has("agent")) items.push({ swatch: "node", label: "AGENT \xB7 autonomous step" });
5889
- if (kindsUsed.has("llm")) items.push({ swatch: "node", label: "LLM \xB7 model call" });
5890
- if (kindsUsed.has("tool")) items.push({ swatch: "node", label: "TOOL \xB7 retrieval / API / code" });
5891
- if (kindsUsed.has("human")) items.push({ swatch: "node-dashed", label: "HUMAN \xB7 review gate" });
5892
- if (kindsUsed.has("memory")) items.push({ swatch: "node-fill2", label: "MEMORY \xB7 store" });
5893
- if (kindsUsed.has("end") && [...accentIds].length < nodes.filter((n) => n.kind === "end").length) {
5894
- items.push({ swatch: "node", label: "exit" });
5895
5769
  }
5896
- if (used.plain) items.push({ swatch: "edge", label: "next" });
5897
- if (used.dashed) items.push({ swatch: "edge-dashed", label: "optional" });
5898
- if (used.error) items.push({ swatch: "edge-error", label: "error path" });
5899
- if (accentIds.size > 0) items.push({ swatch: "node-accent", label: "happy path" });
5900
- return { svg: s + steps, legend: renderLegend(items) };
5901
- }
5902
- function renderFlowFrame(data, tag) {
5903
- const { svg, legend } = renderFlowSvg(data);
5904
- return diagramFrame(
5905
- {
5906
- tag,
5907
- ...data.title !== void 0 ? { title: data.title } : {},
5908
- ...data.description !== void 0 ? { desc: data.description } : {},
5909
- ...legend.length > 0 ? { legendHtml: legend } : {}
5910
- },
5911
- svg
5912
- );
5770
+ function l(f) {
5771
+ let g = s.inEdges(f);
5772
+ g ? i[f] = g.reduce((b, m) => {
5773
+ var I;
5774
+ let E = (I = i[m.v]) != null ? I : 0, y = s.edge(m);
5775
+ return Math.max(b, E + (y !== void 0 ? y : 0));
5776
+ }, 0) : i[f] = 0;
5777
+ }
5778
+ function u(f) {
5779
+ let g = s.outEdges(f), b = Number.POSITIVE_INFINITY;
5780
+ g && (b = g.reduce((E, y) => {
5781
+ let I = i[y.w], be = s.edge(y);
5782
+ return Math.min(E, (I !== void 0 ? I : 0) - (be !== void 0 ? be : 0));
5783
+ }, Number.POSITIVE_INFINITY));
5784
+ let m = e.node(f);
5785
+ b !== Number.POSITIVE_INFINITY && m.borderType !== a && (i[f] = Math.max(i[f] !== void 0 ? i[f] : 0, b));
5786
+ }
5787
+ function c(f) {
5788
+ return s.predecessors(f) || [];
5789
+ }
5790
+ function h(f) {
5791
+ return s.successors(f) || [];
5792
+ }
5793
+ return d(l, c), d(u, h), Object.keys(r5).forEach((f) => {
5794
+ var b;
5795
+ let g = t[f];
5796
+ g !== void 0 && (i[f] = (b = i[g]) != null ? b : 0);
5797
+ }), i;
5913
5798
  }
5914
- function renderFlow(data) {
5915
- return renderFlowFrame(data, data.variant === "dag" ? "DAG" : "FLOW");
5799
+ function Ct(e, n, t, r5) {
5800
+ let o = new p(), i = e.graph(), s = jt(i.nodesep, i.edgesep, r5);
5801
+ return n.forEach((a) => {
5802
+ let d;
5803
+ a.forEach((l) => {
5804
+ let u = t[l];
5805
+ if (u !== void 0) {
5806
+ if (o.setNode(u), d !== void 0) {
5807
+ let c = t[d];
5808
+ if (c !== void 0) {
5809
+ let h = o.edge(c, u);
5810
+ o.setEdge(c, u, Math.max(s(e, l, d), h || 0));
5811
+ }
5812
+ }
5813
+ d = l;
5814
+ }
5815
+ });
5816
+ }), o;
5916
5817
  }
5917
-
5918
- // src/blocks/state.ts
5919
- var ERR_RE = /\b(error|fail|failed|failure|reject|rejected|cancel|cancelled|canceled|abort|aborted|timeout|timed out|expired|dead)\b/i;
5920
- function nameLines(s) {
5921
- return wrapText(s.name ?? "", 23, 3);
5818
+ function Rt(e, n) {
5819
+ return Object.values(n).reduce((t, r5) => {
5820
+ let o = Number.NEGATIVE_INFINITY, i = Number.POSITIVE_INFINITY;
5821
+ Object.entries(r5).forEach(([a, d]) => {
5822
+ let l = St(e, a) / 2;
5823
+ o = Math.max(d + l, o), i = Math.min(d - l, i);
5824
+ });
5825
+ let s = o - i;
5826
+ return s < t[0] && (t = [s, r5]), t;
5827
+ }, [Number.POSITIVE_INFINITY, null])[1];
5922
5828
  }
5923
- function rectFor(s, cellW, cellH, gapX, gapY, padX, padTop) {
5924
- const cx = padX + (s.col - 1) * (cellW + gapX) + cellW / 2;
5925
- const cy = padTop + (s.row - 1) * (cellH + gapY) + cellH / 2;
5926
- if (s.kind === "start" || s.kind === "terminal") {
5927
- return { x: cx - 13, y: cy - 13, w: 26, h: 26, cx, cy };
5928
- }
5929
- const lines = nameLines(s);
5930
- const longest2 = Math.max(0, ...lines.map((ln2) => ln2.length));
5931
- const pw = Math.max(96, Math.min(longest2 * 8 + 26, cellW + gapX - 26));
5932
- const ph = 46 + (Math.max(1, lines.length) - 1) * 15;
5933
- return { x: cx - pw / 2, y: cy - ph / 2, w: pw, h: ph, cx, cy };
5829
+ function Pt(e, n) {
5830
+ let t = Object.values(n), r5 = L(Math.min, t), o = L(Math.max, t);
5831
+ ["u", "d"].forEach((i) => {
5832
+ ["l", "r"].forEach((s) => {
5833
+ let a = i + s, d = e[a];
5834
+ if (!d || d === n) return;
5835
+ let l = Object.values(d), u = r5 - L(Math.min, l);
5836
+ s !== "l" && (u = o - L(Math.max, l)), u && (e[a] = O(d, (c) => c + u));
5837
+ });
5838
+ });
5934
5839
  }
5935
- function pillCls(kind) {
5936
- if (kind === "terminal") return "pill pill-end";
5937
- if (kind === "wait") return "pill pill-wait";
5938
- if (kind === "start") return "pill pill-init";
5939
- return "pill pill-active";
5840
+ function Mt(e, n = void 0) {
5841
+ let t = e.ul;
5842
+ return t ? O(t, (r5, o) => {
5843
+ var s, a;
5844
+ if (n) {
5845
+ let d = n.toLowerCase(), l = e[d];
5846
+ if (l && l[o] !== void 0) return l[o];
5847
+ }
5848
+ let i = Object.values(e).map((d) => {
5849
+ let l = d[o];
5850
+ return l !== void 0 ? l : 0;
5851
+ }).sort((d, l) => d - l);
5852
+ return (((s = i[1]) != null ? s : 0) + ((a = i[2]) != null ? a : 0)) / 2;
5853
+ }) : {};
5940
5854
  }
5941
- function renderState(data) {
5942
- const trans = data.transitions ?? [];
5943
- const rawStates = data.states ?? [];
5944
- const quick = !(rawStates.length > 0 && rawStates.every((n) => n.col !== void 0 && n.row !== void 0));
5945
- const states = ensureGrid(rawStates, trans, data.dir ?? "LR");
5946
- const cellW = 168;
5947
- const cellH = 64;
5948
- const gapX = 74;
5949
- const gapY = 60;
5950
- const groups = data.groups ?? [];
5951
- const nestPad = nestingPads(groups);
5952
- const padX = (groups.length > 0 ? GROUP_PADS.padX : 30) + nestPad.padX;
5953
- const padTop = (groups.length > 0 ? GROUP_PADS.padTop : 30) + nestPad.padTop;
5954
- const padBot = (groups.length > 0 ? GROUP_PADS.padBot : 20) + nestPad.padBot;
5955
- const gx = groupExtent(groups);
5956
- const cols = Math.max(1, ...states.map((s2) => s2.col), gx.cols);
5957
- const rows = Math.max(1, ...states.map((s2) => s2.row), gx.rows);
5958
- const width = padX * 2 + cols * cellW + (cols - 1) * gapX;
5959
- const height = padTop * 2 + rows * cellH + (rows - 1) * gapY + padBot;
5960
- const byId = new Map(states.map((s2) => [s2.id, s2]));
5961
- const isErrTerminal = (s2) => s2 !== void 0 && s2.kind === "terminal" && (ERR_RE.test(s2.name ?? "") || ERR_RE.test(s2.id));
5962
- const successExits = states.filter((s2) => s2.kind === "terminal" && !isErrTerminal(s2));
5963
- const accentId = successExits.length === 1 ? successExits[0]?.id : void 0;
5964
- const gridMeta = gridMetaAttrs({ quick, cols, rows, cellW, cellH, gapX, gapY, padX, padTop });
5965
- const a11y = svgName("State machine", data.title, [
5966
- countPhrase(states.length, "state"),
5967
- countPhrase(trans.length, "transition")
5968
- ]);
5969
- let s = `<svg viewBox="0 0 ${width} ${height}"${a11y.attrs}${gridMeta}>${a11y.title}`;
5970
- if (groups.length > 0) {
5971
- const xOf = (c) => padX + (c - 1) * (cellW + gapX);
5972
- const yOf = (r5) => padTop + (r5 - 1) * (cellH + gapY);
5973
- s += gridGroupsSvg(groups, { xOf, yOf, cellW, cellH, gapX, gapY, skin: true });
5974
- }
5975
- const numbered = trans.length >= 4;
5976
- const labels = [];
5977
- const used = { plain: false, error: false, accent: false };
5978
- const lanes = edgeLanes(trans);
5979
- const avoid = states.map((st2) => {
5980
- const r5 = rectFor(st2, cellW, cellH, gapX, gapY, padX, padTop);
5981
- return { x: r5.x, y: r5.y, w: r5.w, h: r5.h };
5982
- });
5983
- const entries = entryPortOffsets(trans, (id) => {
5984
- const n = byId.get(id);
5985
- return n !== void 0 ? rectFor(n, cellW, cellH, gapX, gapY, padX, padTop) : void 0;
5855
+ function ln(e) {
5856
+ let n = N(e), t = Object.assign(vt(e, n), _t(e, n)), r5 = {}, o;
5857
+ ["u", "d"].forEach((s) => {
5858
+ o = s === "u" ? n : Object.values(n).reverse(), ["l", "r"].forEach((a) => {
5859
+ a === "r" && (o = o.map((c) => Object.values(c).reverse()));
5860
+ let l = Ot(e, o, t, (c) => (s === "u" ? e.predecessors(c) : e.successors(c)) || []), u = It(e, o, l.root, l.align, a === "r");
5861
+ a === "r" && (u = O(u, (c) => -c)), r5[s + a] = u;
5862
+ });
5986
5863
  });
5987
- trans.forEach((t, ti) => {
5988
- const A2 = byId.get(t.from);
5989
- const B3 = byId.get(t.to);
5990
- if (!A2 || !B3) return;
5991
- const label = t.event + (t.guard !== void 0 ? ` ${t.guard}` : "");
5992
- const isErr = isErrTerminal(B3);
5993
- const isAccent = !isErr && accentId !== void 0 && t.to === accentId;
5994
- const stroke = isErr ? "var(--negative)" : isAccent ? "var(--accent)" : "var(--muted)";
5995
- const marker2 = isErr ? "skErr" : isAccent ? "skAccent" : "skArrow";
5996
- const sw = isAccent ? 1.75 : 1.5;
5997
- const tone = isErr ? "error" : isAccent ? "accent" : "muted";
5998
- if (isErr) used.error = true;
5999
- else if (isAccent) used.accent = true;
6000
- else used.plain = true;
6001
- const tAttrs = bp(`transitions.${ti}`) + revealAttr(ti);
6002
- if (t.from === t.to) {
6003
- const r5 = rectFor(A2, cellW, cellH, gapX, gapY, padX, padTop);
6004
- s += `<path d="M ${r5.cx - 12} ${r5.y} C ${r5.cx - 30} ${r5.y - 32}, ${r5.cx + 30} ${r5.y - 32}, ${r5.cx + 12} ${r5.y}" fill="none" stroke="${stroke}" stroke-width="${sw}" marker-end="url(#${marker2})"${tAttrs}/>`;
6005
- const at2 = { lx: r5.cx, ly: r5.y - 28 };
6006
- const mark2 = numbered ? edgeStep(at2, ti + 1, isErr, true) : edgeMask(at2, label, tone);
6007
- labels.push(`<g${tAttrs}>${mark2}</g>`);
6008
- return;
5864
+ let i = Rt(e, r5);
5865
+ return Pt(r5, i), Mt(r5, e.graph().align);
5866
+ }
5867
+ function jt(e, n, t) {
5868
+ return (r5, o, i) => {
5869
+ let s = r5.node(o), a = r5.node(i), d = 0, l;
5870
+ if (d += s.width / 2, Object.hasOwn(s, "labelpos")) switch (s.labelpos.toLowerCase()) {
5871
+ case "l":
5872
+ l = -s.width / 2;
5873
+ break;
5874
+ case "r":
5875
+ l = s.width / 2;
5876
+ break;
6009
5877
  }
6010
- const p2 = ortho(
6011
- rectFor(A2, cellW, cellH, gapX, gapY, padX, padTop),
6012
- rectFor(B3, cellW, cellH, gapX, gapY, padX, padTop),
6013
- lanes[ti] ?? 0,
6014
- entries[ti] ?? 0
6015
- );
6016
- s += `<path d="${p2.d}" fill="none" stroke="${stroke}" stroke-width="${sw}" marker-end="url(#${marker2})"${tAttrs}/>`;
6017
- const mark = numbered ? edgeStep(dodge(p2.lx, p2.ly, avoid), ti + 1, isErr, true) : edgeMask(p2, label, tone);
6018
- labels.push(`<g${tAttrs}>${mark}</g>`);
6019
- });
6020
- const kinds = { active: false, wait: false, start: false, end: false, errEnd: false };
6021
- s += `<g${bl("states")}>`;
6022
- states.forEach((st2, si) => {
6023
- const r5 = rectFor(st2, cellW, cellH, gapX, gapY, padX, padTop);
6024
- const place = nodeCellAttrs(st2.col, st2.row);
6025
- if (st2.kind === "start") {
6026
- kinds.start = true;
6027
- s += `<circle cx="${r5.cx}" cy="${r5.cy}" r="10" fill="var(--ink)"${bp(`states.${si}`)}${place}/>`;
6028
- } else if (st2.kind === "terminal") {
6029
- const accent = st2.id === accentId;
6030
- const err = isErrTerminal(st2);
6031
- if (err) kinds.errEnd = true;
6032
- else if (!accent) kinds.end = true;
6033
- const tone = accent ? "var(--accent)" : err ? "var(--negative)" : "var(--ink)";
6034
- const fill = accent ? "var(--accent-tint)" : err ? "var(--negative-tint)" : "var(--paper)";
6035
- s += `<g${bp(`states.${si}`)}${place}><circle cx="${r5.cx}" cy="${r5.cy}" r="12" fill="${fill}" stroke="${tone}" stroke-width="1.5"/><circle cx="${r5.cx}" cy="${r5.cy}" r="6" fill="${tone}"/></g>`;
6036
- } else {
6037
- const wait = st2.kind === "wait";
6038
- if (wait) kinds.wait = true;
6039
- else kinds.active = true;
6040
- const fill = wait ? "var(--paper-2)" : "var(--paper)";
6041
- const stroke = wait ? "var(--rule-solid)" : "var(--ink)";
6042
- const sw = wait ? 1 : 1.5;
6043
- const lines = nameLines(st2);
6044
- const nameText = lines.length <= 1 ? `<text x="${r5.cx}" y="${r5.cy + 4.5}" class="t-name" text-anchor="middle"${bp(`states.${si}.name`)}>${escapeHtml(st2.name ?? "")}</text>` : `<g${bp(`states.${si}.name`)}>` + lines.map(
6045
- (ln2, j2) => `<text x="${r5.cx}" y="${r5.cy + 4.5 - (lines.length - 1) * 7.5 + j2 * 15}" class="t-name" text-anchor="middle">${escapeHtml(ln2)}</text>`
6046
- ).join("") + `</g>`;
6047
- s += `<g${bp(`states.${si}`)}${place}><rect x="${r5.x}" y="${r5.y}" width="${r5.w}" height="${r5.h}" rx="23" fill="${fill}" stroke="${stroke}" stroke-width="${sw}"/>` + nameText + `</g>`;
5878
+ if (l && (d += t ? l : -l), l = void 0, d += (s.dummy ? n : e) / 2, d += (a.dummy ? n : e) / 2, d += a.width / 2, Object.hasOwn(a, "labelpos")) switch (a.labelpos.toLowerCase()) {
5879
+ case "l":
5880
+ l = a.width / 2;
5881
+ break;
5882
+ case "r":
5883
+ l = -a.width / 2;
5884
+ break;
6048
5885
  }
5886
+ return l && (d += t ? l : -l), d;
5887
+ };
5888
+ }
5889
+ function St(e, n) {
5890
+ return e.node(n).width;
5891
+ }
5892
+ function un(e) {
5893
+ e = A(e), Ft(e), Object.entries(ln(e)).forEach(([n, t]) => e.node(n).x = t);
5894
+ }
5895
+ function Ft(e) {
5896
+ let n = N(e), t = e.graph(), r5 = t.ranksep, o = t.rankalign, i = 0;
5897
+ n.forEach((s) => {
5898
+ let a = s.reduce((d, l) => {
5899
+ var c;
5900
+ let u = (c = e.node(l).height) != null ? c : 0;
5901
+ return d > u ? d : u;
5902
+ }, 0);
5903
+ s.forEach((d) => {
5904
+ let l = e.node(d);
5905
+ o === "top" ? l.y = i + l.height / 2 : o === "bottom" ? l.y = i + a - l.height / 2 : l.y = i + a / 2;
5906
+ }), i += a + r5;
6049
5907
  });
6050
- s += `</g>`;
6051
- s += labels.join("");
6052
- s += `</svg>`;
6053
- const name = (id) => byId.get(id)?.name ?? id;
6054
- const numCell = (ti) => numbered ? `<td class="t-num"><span class="edge-step"><b>${ti + 1}</b></span></td>` : "";
6055
- const rows2 = trans.map(
6056
- (t, ti) => `<tr${bp(`transitions.${ti}`)}${revealAttr(ti)}>` + numCell(ti) + `<td><span class="${pillCls(byId.get(t.from)?.kind)}">${escapeHtml(name(t.from))}</span></td><td style="font-family:var(--font-mono);font-size:11px"${bp(`transitions.${ti}.event`)}>${escapeHtml(t.event)}</td><td class="c-soft" style="font-size:11px"${bp(`transitions.${ti}.guard`)}>${escapeHtml(t.guard ?? "\u2014")}</td><td><span class="${pillCls(byId.get(t.to)?.kind)}">${escapeHtml(name(t.to))}</span></td></tr>`
6057
- ).join("");
6058
- const table = trans.length > 0 ? `<table class="transition-table"><thead><tr>${numbered ? "<th>\u2116</th>" : ""}<th>From</th><th>Event</th><th>Guard</th><th>To</th></tr></thead><tbody${bl("transitions")}>${rows2}</tbody></table>` : "";
6059
- const items = [];
6060
- if (kinds.start) items.push({ swatch: "chip", chip: "\u25CF", label: "start" });
6061
- if (kinds.active) items.push({ swatch: "node", label: "state" });
6062
- if (kinds.wait) items.push({ swatch: "node-fill2", label: "waiting" });
6063
- if (kinds.end) items.push({ swatch: "chip", chip: "\u25C9", label: "end" });
6064
- if (used.plain) items.push({ swatch: "edge", label: "transition" });
6065
- if (kinds.errEnd) items.push({ swatch: "node-negative", label: "error exit" });
6066
- if (used.error) items.push({ swatch: "edge-error", label: "error transition" });
6067
- if (accentId !== void 0) items.push({ swatch: "node-accent", label: "success exit" });
6068
- const legend = renderLegend(items);
6069
- return diagramFrame(
6070
- {
6071
- tag: "STATE",
6072
- ...data.title !== void 0 ? { title: data.title } : {},
6073
- ...data.description !== void 0 ? { desc: data.description } : {},
6074
- ...legend.length > 0 ? { legendHtml: legend } : {},
6075
- ...table.length > 0 ? { footerHtml: table } : {}
6076
- },
6077
- s
6078
- );
6079
5908
  }
6080
-
6081
- // src/svg/glyphs.ts
6082
- var GENERIC_BOX = "box";
6083
- var PATHS = {
6084
- // λ
6085
- function: "M3 2 H5 L10.5 12 M7.6 7 L3.5 12",
6086
- // pail: elliptical rim, tapered sides
6087
- bucket: "M2 3.5 a5 1.6 0 0 0 10 0 a5 1.6 0 0 0 -10 0 M2 3.5 L3.5 12.5 H10.5 L12 3.5",
6088
- // three message bars
6089
- queue: "M3 1.5 V12.5 M7 1.5 V12.5 M11 1.5 V12.5",
6090
- // one in, fan out to three
6091
- topic: "M1.5 7 H5.5 M5.5 7 L11.5 2.5 M5.5 7 H12 M5.5 7 L11.5 11.5",
6092
- // stacked memory slabs
6093
- cache: "M1.5 4.5 L7 2 L12.5 4.5 L7 7 Z M1.5 8 L7 10.5 L12.5 8 M1.5 11 L7 13.5 L12.5 11",
6094
- // the cylinder
6095
- db: "M1.5 3 a5.5 2.2 0 0 0 11 0 a5.5 2.2 0 0 0 -11 0 V11 a5.5 2.2 0 0 0 11 0 V3",
6096
- // cloud
6097
- cdn: "M3.5 12 a3 3 0 0 1 0.3 -6 a4 4 0 0 1 7.6 1 a2.5 2.5 0 0 1 0.6 5 Z",
6098
- // splitter: one lane in, three out
6099
- lb: "M1.5 7 H5 M5 7 L9 3 H12.5 M5 7 H12.5 M5 7 L9 11 H12.5",
6100
- // double chevron
6101
- gateway: "M2 1.5 L7 7 L2 12.5 M7.5 1.5 L12.5 7 L7.5 12.5",
6102
- // hexagon with a core
6103
- pod: "M7 1.2 L12.2 4.1 V9.9 L7 12.8 L1.8 9.9 V4.1 Z M5.2 7 a1.8 1.8 0 1 0 3.6 0 a1.8 1.8 0 1 0 -3.6 0",
6104
- // wheel: ring + four spokes
6105
- cluster: "M1.5 7 a5.5 5.5 0 1 0 11 0 a5.5 5.5 0 1 0 -11 0 M7 1.5 V4.5 M7 9.5 V12.5 M1.5 7 H4.5 M9.5 7 H12.5",
6106
- // head + shoulders
6107
- user: "M4.5 4.5 a2.5 2.5 0 1 0 5 0 a2.5 2.5 0 1 0 -5 0 M2.5 13 a4.5 4.5 0 0 1 9 0",
6108
- // window with a header band
6109
- browser: "M1.5 2.5 H12.5 V11.5 H1.5 Z M1.5 5.5 H12.5",
6110
- // phone
6111
- mobile: "M4 1.5 H10 a1 1 0 0 1 1 1 V11.5 a1 1 0 0 1 -1 1 H4 a1 1 0 0 1 -1 -1 V2.5 a1 1 0 0 1 1 -1 Z M6 11 H8",
6112
- // clock
6113
- cron: "M1.5 7 a5.5 5.5 0 1 0 11 0 a5.5 5.5 0 1 0 -11 0 M7 3.5 V7 L9.5 8.5",
6114
- // four-point spark
6115
- ml: "M7 1.5 L8.4 5.6 L12.5 7 L8.4 8.4 L7 12.5 L5.6 8.4 L1.5 7 L5.6 5.6 Z",
6116
- // padlock
6117
- secret: "M3 6.5 H11 V13 H3 Z M4.5 6.5 V4.5 a2.5 2.5 0 0 1 5 0 V6.5",
6118
- // three sliders
6119
- config: "M1.5 3.5 H12.5 M1.5 7 H12.5 M1.5 10.5 H12.5 M4.5 2 V5 M9.5 5.5 V8.5 M6 9 V12",
6120
- // replica set: two overlapping squares
6121
- deployment: "M1.5 5 H9 V12.5 H1.5 Z M4 5 V2.5 H11.5 V10 H9",
6122
- // arrow into a door
6123
- ingress: "M1.5 7 H8 M5.5 4.5 L8 7 L5.5 9.5 M10 1.5 H12.5 V12.5 H10",
6124
- // two rack slabs
6125
- node: "M2 2 H12 V6 H2 Z M2 8 H12 V12 H2 Z M4.5 4 H6.5 M4.5 10 H6.5",
6126
- // folder tab
6127
- namespace: "M1.5 3.5 H5.5 L7 5 H12.5 V12 H1.5 Z",
6128
- box: "M2 2 H12 V12 H2 Z"
6129
- };
6130
- var ALIAS = {
6131
- function: "function",
6132
- lambda: "function",
6133
- bucket: "bucket",
6134
- s3: "bucket",
6135
- blob: "bucket",
6136
- object: "bucket",
6137
- queue: "queue",
6138
- sqs: "queue",
6139
- mq: "queue",
6140
- broker: "queue",
6141
- rabbitmq: "queue",
6142
- topic: "topic",
6143
- sns: "topic",
6144
- kafka: "topic",
6145
- kinesis: "topic",
6146
- stream: "topic",
6147
- cache: "cache",
6148
- redis: "cache",
6149
- memcached: "cache",
6150
- db: "db",
6151
- database: "db",
6152
- store: "db",
6153
- postgres: "db",
6154
- mysql: "db",
6155
- mongo: "db",
6156
- mongodb: "db",
6157
- dynamo: "db",
6158
- cdn: "cdn",
6159
- lb: "lb",
6160
- gateway: "gateway",
6161
- proxy: "gateway",
6162
- pod: "pod",
6163
- cluster: "cluster",
6164
- user: "user",
6165
- person: "user",
6166
- actor: "user",
6167
- browser: "browser",
6168
- web: "browser",
6169
- mobile: "mobile",
6170
- cron: "cron",
6171
- scheduler: "cron",
6172
- job: "cron",
6173
- cronjob: "cron",
6174
- ml: "ml",
6175
- model: "ml",
6176
- llm: "ml",
6177
- agent: "ml",
6178
- ai: "ml",
6179
- secret: "secret",
6180
- secrets: "secret",
6181
- vault: "secret",
6182
- kms: "secret",
6183
- config: "config",
6184
- configmap: "config",
6185
- settings: "config",
6186
- deployment: "deployment",
6187
- ingress: "ingress",
6188
- node: "node",
6189
- vm: "node",
6190
- server: "node",
6191
- host: "node",
6192
- namespace: "namespace"
6193
- };
6194
- function glyphNameFor(kind) {
6195
- return ALIAS[(kind ?? "").trim().toLowerCase()] ?? GENERIC_BOX;
5909
+ function he(e, n = {}) {
5910
+ let t = n.debugTiming ? P : M;
5911
+ return t("layout", () => {
5912
+ let r5 = t(" buildLayoutGraph", () => Xt(e));
5913
+ return t(" runLayout", () => Dt(r5, t, n)), t(" updateInputGraph", () => At(e, r5)), r5;
5914
+ });
6196
5915
  }
6197
- function hasGlyph(kind) {
6198
- return (kind ?? "").trim().toLowerCase() in ALIAS;
5916
+ function Dt(e, n, t) {
5917
+ n(" makeSpaceForEdgeLabels", () => Ut(e)), n(" removeSelfEdges", () => rr(e)), n(" acyclic", () => je(e)), n(" nestingGraph.run", () => Ke(e)), n(" rank", () => Xe(A(e))), n(" injectEdgeLabelProxies", () => Kt(e)), n(" removeEmptyRanks", () => Oe(e)), n(" nestingGraph.cleanup", () => Je(e)), n(" normalizeRanks", () => Te(e)), n(" assignRankMinMax", () => $t(e)), n(" removeEdgeLabelProxies", () => Jt(e)), n(" normalize.run", () => Fe(e)), n(" parentDummyChains", () => Ue(e)), n(" addBorderSegments", () => Ze(e)), n(" order", () => B(e, t)), n(" insertSelfEdges", () => or(e)), n(" adjustCoordinateSystem", () => nn(e)), n(" position", () => un(e)), n(" positionSelfEdges", () => ir(e)), n(" removeBorderNodes", () => tr(e)), n(" normalize.undo", () => De(e)), n(" fixupEdgeLabelCoords", () => er(e)), n(" undoCoordinateSystem", () => tn(e)), n(" translateGraph", () => Qt(e)), n(" assignNodeIntersects", () => Zt(e)), n(" reversePoints", () => nr(e)), n(" acyclic.undo", () => Se(e));
6199
5918
  }
6200
- function cloudGlyph(kind, x2, y, c = "var(--muted)") {
6201
- const d = PATHS[glyphNameFor(kind)];
6202
- return `<path d="${d}" transform="translate(${x2} ${y})" fill="none" stroke="${c}" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round"/>`;
5919
+ function At(e, n) {
5920
+ e.nodes().forEach((t) => {
5921
+ let r5 = e.node(t), o = n.node(t);
5922
+ r5 && (r5.x = o.x, r5.y = o.y, r5.order = o.order, r5.rank = o.rank, n.children(t).length && (r5.width = o.width, r5.height = o.height));
5923
+ }), e.edges().forEach((t) => {
5924
+ let r5 = e.edge(t), o = n.edge(t);
5925
+ r5.points = o.points, Object.hasOwn(o, "x") && (r5.x = o.x, r5.y = o.y);
5926
+ }), e.graph().width = n.graph().width, e.graph().height = n.graph().height;
6203
5927
  }
6204
-
6205
- // src/svg/blockStyle.ts
6206
- var KNOWN_NODE_KINDS = [
6207
- "client",
6208
- "service",
6209
- "microservice",
6210
- "compute",
6211
- "container",
6212
- "data",
6213
- "store",
6214
- "db",
6215
- "database",
6216
- "postgres",
6217
- "mysql",
6218
- "mongo",
6219
- "mongodb",
6220
- "dynamo",
6221
- "bucket",
6222
- "blob",
6223
- "object",
6224
- "s3",
6225
- "queue",
6226
- "mq",
6227
- "broker",
6228
- "sqs",
6229
- "rabbitmq",
6230
- "cache",
6231
- "redis",
6232
- "memcached",
6233
- "gateway",
6234
- "lb",
6235
- "proxy",
6236
- "function",
6237
- "lambda",
6238
- "cdn",
6239
- "external",
6240
- "producer",
6241
- "topic",
6242
- "consumer",
6243
- "context",
6244
- "firewall",
6245
- "waf",
6246
- "shield",
6247
- "dns",
6248
- "auth",
6249
- "identity",
6250
- "idp",
6251
- "iam",
6252
- "oauth",
6253
- "sso",
6254
- "monitor",
6255
- "observability",
6256
- "metrics",
6257
- "logs",
6258
- "tracing",
6259
- "apm",
6260
- "scheduler",
6261
- "cron",
6262
- "job",
6263
- "stream",
6264
- "kafka",
6265
- "kinesis",
6266
- "warehouse",
6267
- "lake",
6268
- "analytics",
6269
- "bi",
6270
- "search",
6271
- "index",
6272
- "elasticsearch",
6273
- "opensearch",
6274
- "registry",
6275
- "ci",
6276
- "cicd",
6277
- "pipeline",
6278
- "git",
6279
- "repo",
6280
- "scm",
6281
- "device",
6282
- "iot",
6283
- "email",
6284
- "sms",
6285
- "config",
6286
- "settings",
6287
- "ml",
6288
- "model",
6289
- "llm",
6290
- "agent",
6291
- "ai",
6292
- "user",
6293
- "person",
6294
- "actor",
6295
- "browser",
6296
- "web",
6297
- "mobile",
6298
- "vm",
6299
- "server",
6300
- "host",
6301
- "secrets",
6302
- "vault",
6303
- "kms",
6304
- "notification",
6305
- "webhook",
6306
- "worker",
6307
- "etl",
6308
- "shard",
6309
- "shards",
6310
- "sharded",
6311
- "replica",
6312
- "replicas",
6313
- "replicaset",
6314
- "users",
6315
- "crowd",
6316
- "region",
6317
- "geo",
6318
- "globe",
6319
- // `preset: k8s` vocabulary (namespaces are groups; these are the node kinds).
6320
- "deployment",
6321
- "pod",
6322
- "ingress",
6323
- "configmap",
6324
- "secret",
6325
- "cronjob",
6326
- "node",
6327
- "namespace",
6328
- "cluster",
6329
- "sns"
6330
- ];
6331
- var SKIN = {};
6332
- var def = (kinds, skin) => {
6333
- for (const k2 of kinds) SKIN[k2] = skin;
6334
- };
6335
- var primary = (chip3) => ({ chip: chip3, primary: true, fill: "paper", dashed: false });
6336
- var secondary = (chip3) => ({ chip: chip3, primary: false, fill: "paper-2", dashed: false });
6337
- var external = (chip3) => ({ chip: chip3, primary: true, fill: "paper", dashed: true });
6338
- def(["client", "user", "person", "actor", "users", "crowd", "browser", "web", "mobile", "device", "iot"], primary("CLIENT"));
6339
- def(["service", "microservice", "compute", "container", "worker", "etl"], primary("SVC"));
6340
- def(["data"], primary("DATA"));
6341
- def(["store", "db", "database", "postgres", "mysql", "mongo", "mongodb", "dynamo"], secondary("DB"));
6342
- def(["shard", "shards", "sharded", "replica", "replicas", "replicaset"], secondary("DB"));
6343
- def(["bucket", "blob", "object", "s3"], secondary("BUCKET"));
6344
- def(["warehouse", "lake"], secondary("WAREHOUSE"));
6345
- def(["queue", "mq", "broker", "sqs", "rabbitmq"], secondary("QUEUE"));
6346
- def(["topic"], secondary("TOPIC"));
6347
- def(["stream", "kafka", "kinesis"], secondary("BUS"));
6348
- def(["cache", "redis", "memcached"], secondary("CACHE"));
6349
- def(["search", "index", "elasticsearch", "opensearch"], secondary("SEARCH"));
6350
- def(["registry"], secondary("REGISTRY"));
6351
- def(["gateway", "proxy"], primary("GATEWAY"));
6352
- def(["lb"], primary("LB"));
6353
- def(["function", "lambda"], primary("FN"));
6354
- def(["cdn"], external("EDGE"));
6355
- def(["external"], external("EXT"));
6356
- def(["producer"], primary("PRODUCER"));
6357
- def(["consumer"], primary("CONSUMER"));
6358
- def(["context"], primary("CONTEXT"));
6359
- def(["firewall", "waf", "shield"], primary("WAF"));
6360
- def(["dns"], external("DNS"));
6361
- def(["auth", "identity", "idp", "iam", "oauth", "sso"], primary("AUTH"));
6362
- def(["monitor", "observability", "metrics", "logs", "tracing", "apm"], primary("OBS"));
6363
- def(["scheduler", "cron", "job"], primary("CRON"));
6364
- def(["analytics", "bi"], primary("ANALYTICS"));
6365
- def(["ci", "cicd", "pipeline"], primary("CI"));
6366
- def(["git", "repo", "scm"], secondary("GIT"));
6367
- def(["email", "sms"], external("EMAIL"));
6368
- def(["config", "settings"], secondary("CONFIG"));
6369
- def(["ml", "model", "llm", "agent", "ai"], primary("AI"));
6370
- def(["vm", "server", "host"], primary("HOST"));
6371
- def(["secrets", "vault", "kms"], secondary("SECRETS"));
6372
- def(["notification", "webhook"], external("WEBHOOK"));
6373
- def(["region", "geo", "globe"], external("REGION"));
6374
- def(["deployment"], primary("DEPLOY"));
6375
- def(["pod"], primary("POD"));
6376
- def(["ingress"], primary("INGRESS"));
6377
- def(["configmap"], secondary("CONFIG"));
6378
- def(["secret"], secondary("SECRETS"));
6379
- def(["cronjob"], primary("CRON"));
6380
- def(["node"], primary("NODE"));
6381
- def(["namespace"], secondary("NS"));
6382
- def(["cluster"], primary("CLUSTER"));
6383
- def(["sns"], secondary("TOPIC"));
6384
- function nodeSkin(kind) {
6385
- const k2 = (kind ?? "").trim().toLowerCase();
6386
- if (k2 === "") return { chip: "", primary: true, fill: "paper", dashed: false };
6387
- return SKIN[k2] ?? primary(k2.toUpperCase());
5928
+ var Vt = ["nodesep", "edgesep", "ranksep", "marginx", "marginy"];
5929
+ var Wt = { ranksep: 50, edgesep: 20, nodesep: 50, rankdir: "TB", rankalign: "center" };
5930
+ var Bt = ["acyclicer", "ranker", "rankdir", "align", "rankalign"];
5931
+ var Yt = ["width", "height", "rank"];
5932
+ var cn = { width: 0, height: 0 };
5933
+ var zt = ["minlen", "weight", "width", "height", "labeloffset"];
5934
+ var Ht = { minlen: 1, weight: 1, width: 0, height: 0, labeloffset: 10, labelpos: "r" };
5935
+ var qt = ["labelpos"];
5936
+ function Xt(e) {
5937
+ let n = new p({ multigraph: true, compound: true }), t = ce(e.graph());
5938
+ return n.setGraph(Object.assign({}, Wt, ue(t, Vt), T(t, Bt))), e.nodes().forEach((r5) => {
5939
+ let o = ce(e.node(r5)), i = ue(o, Yt);
5940
+ Object.keys(cn).forEach((a) => {
5941
+ i[a] === void 0 && (i[a] = cn[a]);
5942
+ }), n.setNode(r5, i);
5943
+ let s = e.parent(r5);
5944
+ s !== void 0 && n.setParent(r5, s);
5945
+ }), e.edges().forEach((r5) => {
5946
+ let o = ce(e.edge(r5));
5947
+ n.setEdge(r5, Object.assign({}, Ht, ue(o, zt), T(o, qt)));
5948
+ }), n;
5949
+ }
5950
+ function Ut(e) {
5951
+ let n = e.graph();
5952
+ n.ranksep /= 2, e.edges().forEach((t) => {
5953
+ let r5 = e.edge(t);
5954
+ r5.minlen *= 2, r5.labelpos.toLowerCase() !== "c" && (n.rankdir === "TB" || n.rankdir === "BT" ? r5.width += r5.labeloffset : r5.height += r5.labeloffset);
5955
+ });
5956
+ }
5957
+ function Kt(e) {
5958
+ e.edges().forEach((n) => {
5959
+ let t = e.edge(n);
5960
+ if (t.width && t.height) {
5961
+ let r5 = e.node(n.v), i = { rank: (e.node(n.w).rank - r5.rank) / 2 + r5.rank, e: n };
5962
+ w(e, "edge-proxy", i, "_ep");
5963
+ }
5964
+ });
5965
+ }
5966
+ function $t(e) {
5967
+ let n = 0;
5968
+ e.nodes().forEach((t) => {
5969
+ let r5 = e.node(t);
5970
+ r5.borderTop && (r5.minRank = e.node(r5.borderTop).rank, r5.maxRank = e.node(r5.borderBottom).rank, n = Math.max(n, r5.maxRank));
5971
+ }), e.graph().maxRank = n;
5972
+ }
5973
+ function Jt(e) {
5974
+ e.nodes().forEach((n) => {
5975
+ let t = e.node(n);
5976
+ if (t.dummy === "edge-proxy") {
5977
+ let r5 = t;
5978
+ e.edge(r5.e).labelRank = t.rank, e.removeNode(n);
5979
+ }
5980
+ });
5981
+ }
5982
+ function Qt(e) {
5983
+ let n = Number.POSITIVE_INFINITY, t = 0, r5 = Number.POSITIVE_INFINITY, o = 0, i = e.graph(), s = i.marginx || 0, a = i.marginy || 0;
5984
+ function d(l) {
5985
+ let u = l.x, c = l.y, h = l.width, f = l.height;
5986
+ n = Math.min(n, u - h / 2), t = Math.max(t, u + h / 2), r5 = Math.min(r5, c - f / 2), o = Math.max(o, c + f / 2);
5987
+ }
5988
+ e.nodes().forEach((l) => d(e.node(l))), e.edges().forEach((l) => {
5989
+ let u = e.edge(l);
5990
+ Object.hasOwn(u, "x") && d(u);
5991
+ }), n -= s, r5 -= a, e.nodes().forEach((l) => {
5992
+ let u = e.node(l);
5993
+ u.x -= n, u.y -= r5;
5994
+ }), e.edges().forEach((l) => {
5995
+ let u = e.edge(l);
5996
+ u.points.forEach((c) => {
5997
+ c.x -= n, c.y -= r5;
5998
+ }), Object.hasOwn(u, "x") && (u.x -= n), Object.hasOwn(u, "y") && (u.y -= r5);
5999
+ }), i.width = t - n + s, i.height = o - r5 + a;
6000
+ }
6001
+ function Zt(e) {
6002
+ e.edges().forEach((n) => {
6003
+ let t = e.edge(n), r5 = e.node(n.v), o = e.node(n.w), i, s;
6004
+ t.points ? (i = t.points[0], s = t.points[t.points.length - 1]) : (t.points = [], i = o, s = r5), t.points.unshift(H(r5, i)), t.points.push(H(o, s));
6005
+ });
6006
+ }
6007
+ function er(e) {
6008
+ e.edges().forEach((n) => {
6009
+ let t = e.edge(n);
6010
+ if (Object.hasOwn(t, "x")) switch ((t.labelpos === "l" || t.labelpos === "r") && (t.width -= t.labeloffset), t.labelpos) {
6011
+ case "l":
6012
+ t.x -= t.width / 2 + t.labeloffset;
6013
+ break;
6014
+ case "r":
6015
+ t.x += t.width / 2 + t.labeloffset;
6016
+ break;
6017
+ }
6018
+ });
6019
+ }
6020
+ function nr(e) {
6021
+ e.edges().forEach((n) => {
6022
+ let t = e.edge(n);
6023
+ t.reversed && t.points.reverse();
6024
+ });
6025
+ }
6026
+ function tr(e) {
6027
+ e.nodes().forEach((n) => {
6028
+ if (e.children(n).length) {
6029
+ let t = e.node(n), r5 = e.node(t.borderTop), o = e.node(t.borderBottom), i = e.node(t.borderLeft[t.borderLeft.length - 1]), s = e.node(t.borderRight[t.borderRight.length - 1]);
6030
+ t.width = Math.abs(s.x - i.x), t.height = Math.abs(o.y - r5.y), t.x = i.x + t.width / 2, t.y = r5.y + t.height / 2;
6031
+ }
6032
+ }), e.nodes().forEach((n) => {
6033
+ e.node(n).dummy === "border" && e.removeNode(n);
6034
+ });
6035
+ }
6036
+ function rr(e) {
6037
+ e.edges().forEach((n) => {
6038
+ if (n.v === n.w) {
6039
+ let t = e.node(n.v);
6040
+ t.selfEdges || (t.selfEdges = []), t.selfEdges.push({ e: n, label: e.edge(n) }), e.removeEdge(n);
6041
+ }
6042
+ });
6043
+ }
6044
+ function or(e) {
6045
+ N(e).forEach((t) => {
6046
+ let r5 = 0;
6047
+ t.forEach((o, i) => {
6048
+ let s = e.node(o);
6049
+ s.order = i + r5, (s.selfEdges || []).forEach((a) => {
6050
+ w(e, "selfedge", { width: a.label.width, height: a.label.height, rank: s.rank, order: i + ++r5, e: a.e, label: a.label }, "_se");
6051
+ }), delete s.selfEdges;
6052
+ });
6053
+ });
6054
+ }
6055
+ function ir(e) {
6056
+ e.nodes().forEach((n) => {
6057
+ let t = e.node(n);
6058
+ if (t.dummy === "selfedge") {
6059
+ let r5 = t, o = e.node(r5.e.v), i = o.x + o.width / 2, s = o.y, a = t.x - i, d = o.height / 2;
6060
+ e.setEdge(r5.e, r5.label), e.removeNode(n), r5.label.points = [{ x: i + 2 * a / 3, y: s - d }, { x: i + 5 * a / 6, y: s - d }, { x: i + a, y: s }, { x: i + 5 * a / 6, y: s + d }, { x: i + 2 * a / 3, y: s + d }], r5.label.x = t.x, r5.label.y = t.y;
6061
+ }
6062
+ });
6063
+ }
6064
+ function ue(e, n) {
6065
+ return O(T(e, n), Number);
6066
+ }
6067
+ function ce(e) {
6068
+ let n = {};
6069
+ return e && Object.entries(e).forEach(([t, r5]) => {
6070
+ typeof t == "string" && (t = t.toLowerCase()), n[t] = r5;
6071
+ }), n;
6388
6072
  }
6389
- function skinFill(sk, accent = false) {
6390
- if (accent) return "var(--accent-tint)";
6391
- return sk.fill === "paper-2" ? "var(--paper-2)" : "var(--paper)";
6073
+ function fe(e) {
6074
+ let n = N(e), t = new p({ compound: true, multigraph: true }).setGraph({});
6075
+ return e.nodes().forEach((r5) => {
6076
+ t.setNode(r5, { label: r5 }), t.setParent(r5, "layer" + e.node(r5).rank);
6077
+ }), e.edges().forEach((r5) => t.setEdge(r5.v, r5.w, {}, r5.name)), n.forEach((r5, o) => {
6078
+ let i = "layer" + o;
6079
+ t.setNode(i, { rank: "same" }), r5.reduce((s, a) => (t.setEdge(s, a, { style: "invis" }), a));
6080
+ }), t;
6392
6081
  }
6393
- function nodeGlyph(kind, x2, y, c) {
6394
- const k2 = (kind ?? "").toLowerCase();
6395
- if (k2 === "store" || k2 === "db" || k2 === "database" || k2 === "postgres" || k2 === "mysql" || k2 === "mongo" || k2 === "mongodb" || k2 === "dynamo") {
6396
- return `<g stroke="${c}" stroke-width="1.3" fill="none"><ellipse cx="${x2 + 8}" cy="${y + 3}" rx="7" ry="3"/><path d="M${x2 + 1} ${y + 3} V ${y + 13}"/><path d="M${x2 + 15} ${y + 3} V ${y + 13}"/><path d="M${x2 + 1} ${y + 13} a 7 3 0 0 0 14 0"/></g>`;
6397
- }
6398
- if (k2 === "bucket" || k2 === "blob" || k2 === "object" || k2 === "s3") {
6399
- return `<g stroke="${c}" stroke-width="1.3" fill="none"><ellipse cx="${x2 + 8}" cy="${y + 3}" rx="7" ry="2.5"/><path d="M${x2 + 1.5} ${y + 3} L ${x2 + 3.5} ${y + 14} L ${x2 + 12.5} ${y + 14} L ${x2 + 14.5} ${y + 3}"/></g>`;
6400
- }
6401
- if (k2 === "queue" || k2 === "topic" || k2 === "mq" || k2 === "broker" || k2 === "sqs" || k2 === "rabbitmq") {
6402
- return `<g stroke="${c}" stroke-width="1.6"><path d="M${x2 + 2} ${y + 1} V ${y + 14}"/><path d="M${x2 + 8} ${y + 1} V ${y + 14}"/><path d="M${x2 + 14} ${y + 1} V ${y + 14}"/></g>`;
6403
- }
6404
- if (k2 === "firewall" || k2 === "waf" || k2 === "shield") {
6405
- return `<path d="M${x2 + 8} ${y} L ${x2 + 15} ${y + 3} V ${y + 9} Q ${x2 + 15} ${y + 14} ${x2 + 8} ${y + 16} Q ${x2 + 1} ${y + 14} ${x2 + 1} ${y + 9} V ${y + 3} Z" fill="none" stroke="${c}" stroke-width="1.3"/>`;
6406
- }
6407
- if (k2 === "dns") {
6408
- return `<g stroke="${c}" stroke-width="1.2" fill="none"><circle cx="${x2 + 8}" cy="${y + 8}" r="7"/><ellipse cx="${x2 + 8}" cy="${y + 8}" rx="3" ry="7"/><path d="M${x2 + 1.5} ${y + 8} H ${x2 + 14.5}"/></g>`;
6409
- }
6410
- if (k2 === "auth" || k2 === "identity" || k2 === "idp" || k2 === "iam" || k2 === "oauth" || k2 === "sso") {
6411
- return `<g stroke="${c}" stroke-width="1.4" fill="none"><circle cx="${x2 + 5}" cy="${y + 8}" r="3.5"/><path d="M${x2 + 8.5} ${y + 8} H ${x2 + 15} M${x2 + 12.5} ${y + 8} V ${y + 11.5} M${x2 + 15} ${y + 8} V ${y + 10.5}"/></g>`;
6412
- }
6413
- if (k2 === "monitor" || k2 === "observability" || k2 === "metrics" || k2 === "logs" || k2 === "tracing" || k2 === "apm") {
6414
- return `<path d="M${x2} ${y + 9} H ${x2 + 4} L ${x2 + 6.5} ${y + 3} L ${x2 + 9.5} ${y + 13} L ${x2 + 12} ${y + 9} H ${x2 + 16}" fill="none" stroke="${c}" stroke-width="1.5" stroke-linejoin="round"/>`;
6415
- }
6416
- if (k2 === "scheduler" || k2 === "cron" || k2 === "job") {
6417
- return `<g stroke="${c}" stroke-width="1.3" fill="none"><circle cx="${x2 + 8}" cy="${y + 8}" r="7"/><path d="M${x2 + 8} ${y + 4} V ${y + 8} L ${x2 + 11.5} ${y + 10}"/></g>`;
6418
- }
6419
- if (k2 === "stream" || k2 === "kafka" || k2 === "kinesis") {
6420
- const wave = (dy) => `<path d="M${x2 + 1} ${y + 4 + dy} q 3.5 -3 7 0 t 7 0" fill="none" stroke="${c}" stroke-width="1.4"/>`;
6421
- return `<g>${wave(0)}${wave(4.5)}${wave(9)}</g>`;
6422
- }
6423
- if (k2 === "warehouse" || k2 === "lake") {
6424
- return `<g stroke="${c}" stroke-width="1.3" fill="none"><ellipse cx="${x2 + 8}" cy="${y + 3}" rx="7" ry="3"/><path d="M${x2 + 1} ${y + 3} V ${y + 13}"/><path d="M${x2 + 15} ${y + 3} V ${y + 13}"/><path d="M${x2 + 1} ${y + 8} a 7 3 0 0 0 14 0"/><path d="M${x2 + 1} ${y + 13} a 7 3 0 0 0 14 0"/></g>`;
6425
- }
6426
- if (k2 === "search" || k2 === "index") {
6427
- return `<g stroke="${c}" stroke-width="1.4" fill="none"><circle cx="${x2 + 6.5}" cy="${y + 6.5}" r="5"/><path d="M${x2 + 10.5} ${y + 10.5} L ${x2 + 15} ${y + 15}"/></g>`;
6428
- }
6429
- if (k2 === "ml" || k2 === "model" || k2 === "llm" || k2 === "agent" || k2 === "ai") {
6430
- return `<path d="M${x2 + 8} ${y + 1} L ${x2 + 9.8} ${y + 6.2} L ${x2 + 15} ${y + 8} L ${x2 + 9.8} ${y + 9.8} L ${x2 + 8} ${y + 15} L ${x2 + 6.2} ${y + 9.8} L ${x2 + 1} ${y + 8} L ${x2 + 6.2} ${y + 6.2} Z" fill="${c}"/>`;
6431
- }
6432
- if (k2 === "user" || k2 === "person" || k2 === "actor") {
6433
- return `<g fill="${c}"><circle cx="${x2 + 8}" cy="${y + 4.5}" r="3.5"/><path d="M ${x2 + 2} ${y + 15} a 6 6.5 0 0 1 12 0 z"/></g>`;
6434
- }
6435
- if (k2 === "browser" || k2 === "web") {
6436
- return `<g stroke="${c}" stroke-width="1.3" fill="none"><rect x="${x2 + 1}" y="${y + 2}" width="14" height="12" rx="2"/><path d="M${x2 + 1} ${y + 6} H ${x2 + 15}"/></g>`;
6437
- }
6438
- if (k2 === "mobile") {
6439
- return `<g stroke="${c}" stroke-width="1.3" fill="none"><rect x="${x2 + 4}" y="${y + 1}" width="8" height="14" rx="2"/><path d="M${x2 + 7} ${y + 12.5} H ${x2 + 9}"/></g>`;
6440
- }
6441
- if (k2 === "vm" || k2 === "server" || k2 === "host") {
6442
- return `<g stroke="${c}" stroke-width="1.3" fill="none"><rect x="${x2 + 2}" y="${y + 2}" width="12" height="5" rx="1.2"/><rect x="${x2 + 2}" y="${y + 9}" width="12" height="5" rx="1.2"/><path d="M${x2 + 4.5} ${y + 4.5} H ${x2 + 7} M${x2 + 4.5} ${y + 11.5} H ${x2 + 7}"/></g>`;
6443
- }
6444
- if (k2 === "secrets" || k2 === "vault" || k2 === "kms") {
6445
- return `<g stroke="${c}" stroke-width="1.3" fill="none"><rect x="${x2 + 3}" y="${y + 7}" width="10" height="8" rx="1.5"/><path d="M${x2 + 5} ${y + 7} V ${y + 5} a 3 3 0 0 1 6 0 V ${y + 7}"/></g>`;
6446
- }
6447
- if (k2 === "notification" || k2 === "webhook") {
6448
- return `<g stroke="${c}" stroke-width="1.3" fill="none"><path d="M${x2 + 3} ${y + 11} a 5 5 0 0 1 1.6 -3.6 V ${y + 5} a 3.4 3.4 0 0 1 6.8 0 v 2.4 a 5 5 0 0 1 1.6 3.6 z"/><path d="M${x2 + 6.5} ${y + 13.5} a 1.5 1.5 0 0 0 3 0"/></g>`;
6449
- }
6450
- if (k2 === "email" || k2 === "sms") {
6451
- return `<g stroke="${c}" stroke-width="1.3" fill="none"><rect x="${x2 + 1}" y="${y + 3}" width="14" height="10" rx="1.5"/><path d="M${x2 + 1.5} ${y + 4} L ${x2 + 8} ${y + 9} L ${x2 + 14.5} ${y + 4}"/></g>`;
6452
- }
6453
- if (k2 === "registry") {
6454
- return `<g stroke="${c}" stroke-width="1.2" fill="none"><rect x="${x2 + 1}" y="${y + 8}" width="6" height="6" rx="1"/><rect x="${x2 + 9}" y="${y + 8}" width="6" height="6" rx="1"/><rect x="${x2 + 5}" y="${y + 1}" width="6" height="6" rx="1"/></g>`;
6455
- }
6456
- if (k2 === "ci" || k2 === "cicd" || k2 === "pipeline") {
6457
- return `<g stroke="${c}" stroke-width="1.3" fill="none"><circle cx="${x2 + 8}" cy="${y + 8}" r="7"/><path d="M${x2 + 6} ${y + 5} L ${x2 + 11.5} ${y + 8} L ${x2 + 6} ${y + 11} Z" fill="${c}" stroke="none"/></g>`;
6458
- }
6459
- if (k2 === "git" || k2 === "repo" || k2 === "scm") {
6460
- return `<g stroke="${c}" stroke-width="1.3" fill="none"><circle cx="${x2 + 4}" cy="${y + 3.5}" r="2.5"/><circle cx="${x2 + 4}" cy="${y + 12.5}" r="2.5"/><circle cx="${x2 + 12}" cy="${y + 6}" r="2.5"/><path d="M${x2 + 4} ${y + 6} V ${y + 10} M${x2 + 4} ${y + 8} q 0 -2 3 -2 h 2.5"/></g>`;
6082
+ var sr = { graphlib: z, version: U, layout: he, debug: fe, util: { time: P, notime: M } };
6083
+ var To = sr;
6084
+
6085
+ // src/blocks/autoLayout.ts
6086
+ function ensureGrid(items, edges, rankdir) {
6087
+ const allPlaced = items.length > 0 && items.every((n) => n.col !== void 0 && n.row !== void 0);
6088
+ if (allPlaced) {
6089
+ return items.map((n) => ({ ...n, col: n.col, row: n.row }));
6461
6090
  }
6462
- if (k2 === "device" || k2 === "iot") {
6463
- return `<g stroke="${c}" stroke-width="1.2" fill="none"><rect x="${x2 + 4}" y="${y + 4}" width="8" height="8" rx="1.5"/><path d="M${x2 + 6} ${y + 4} V ${y + 1} M${x2 + 10} ${y + 4} V ${y + 1} M${x2 + 6} ${y + 15} V ${y + 12} M${x2 + 10} ${y + 15} V ${y + 12} M${x2 + 4} ${y + 6} H ${x2 + 1} M${x2 + 4} ${y + 10} H ${x2 + 1} M${x2 + 15} ${y + 6} H ${x2 + 12} M${x2 + 15} ${y + 10} H ${x2 + 12}"/></g>`;
6091
+ const grid = autoGrid(
6092
+ items.map((n) => n.id),
6093
+ edges,
6094
+ rankdir
6095
+ );
6096
+ return items.map((n) => {
6097
+ const g = grid.get(n.id) ?? { col: 1, row: 1 };
6098
+ return { ...n, col: g.col, row: g.row };
6099
+ });
6100
+ }
6101
+ function autoGrid(ids, edges, rankdir) {
6102
+ const idSet = new Set(ids);
6103
+ const g = new To.graphlib.Graph();
6104
+ g.setGraph({ rankdir, nodesep: 16, ranksep: 16, marginx: 0, marginy: 0 });
6105
+ g.setDefaultEdgeLabel(() => ({}));
6106
+ for (const id of ids) g.setNode(id, { width: 10, height: 10 });
6107
+ for (const e of edges) {
6108
+ if (e.from !== e.to && idSet.has(e.from) && idSet.has(e.to)) g.setEdge(e.from, e.to);
6464
6109
  }
6465
- if (k2 === "analytics" || k2 === "bi") {
6466
- return `<g fill="${c}"><rect x="${x2 + 1}" y="${y + 9}" width="3.4" height="6" rx="0.8"/><rect x="${x2 + 6.3}" y="${y + 5}" width="3.4" height="10" rx="0.8"/><rect x="${x2 + 11.6}" y="${y + 1}" width="3.4" height="14" rx="0.8"/></g>`;
6110
+ To.layout(g);
6111
+ const pos3 = ids.map((id) => {
6112
+ const n = g.node(id);
6113
+ return { id, x: Math.round(n?.x ?? 0), y: Math.round(n?.y ?? 0) };
6114
+ });
6115
+ const out = /* @__PURE__ */ new Map();
6116
+ if (rankdir === "TB") {
6117
+ const ranks = [...new Set(pos3.map((p2) => p2.y))].sort((a, b) => a - b);
6118
+ ranks.forEach((yv, ri) => {
6119
+ pos3.filter((p2) => p2.y === yv).sort((a, b) => a.x - b.x).forEach((p2, ci) => out.set(p2.id, { col: ci + 1, row: ri + 1 }));
6120
+ });
6121
+ } else {
6122
+ const ranks = [...new Set(pos3.map((p2) => p2.x))].sort((a, b) => a - b);
6123
+ ranks.forEach((xv, ci) => {
6124
+ pos3.filter((p2) => p2.x === xv).sort((a, b) => a.y - b.y).forEach((p2, ri) => out.set(p2.id, { col: ci + 1, row: ri + 1 }));
6125
+ });
6467
6126
  }
6468
- if (k2 === "config" || k2 === "settings") {
6469
- return `<g stroke="${c}" stroke-width="1.3" fill="none"><circle cx="${x2 + 8}" cy="${y + 8}" r="4"/><path d="M${x2 + 8} ${y + 1} V ${y + 3.5} M${x2 + 8} ${y + 12.5} V ${y + 15} M${x2 + 1} ${y + 8} H ${x2 + 3.5} M${x2 + 12.5} ${y + 8} H ${x2 + 15} M${x2 + 3} ${y + 3} L ${x2 + 5} ${y + 5} M${x2 + 11} ${y + 11} L ${x2 + 13} ${y + 13} M${x2 + 13} ${y + 3} L ${x2 + 11} ${y + 5} M${x2 + 5} ${y + 11} L ${x2 + 3} ${y + 13}"/></g>`;
6127
+ return out;
6128
+ }
6129
+
6130
+ // src/blocks/flow.ts
6131
+ var AI_CHIP = {
6132
+ agent: "AGENT",
6133
+ llm: "LLM",
6134
+ tool: "TOOL",
6135
+ human: "HUMAN",
6136
+ memory: "MEMORY"
6137
+ };
6138
+ function flowRevealOrder(nodes, edges) {
6139
+ const ids = new Set(nodes.map((n) => n.id));
6140
+ const indeg = /* @__PURE__ */ new Map();
6141
+ const outs = /* @__PURE__ */ new Map();
6142
+ for (const n of nodes) {
6143
+ indeg.set(n.id, 0);
6144
+ outs.set(n.id, []);
6470
6145
  }
6471
- if (k2 === "cache" || k2 === "redis" || k2 === "memcached") {
6472
- const slab = (dy) => `<path d="M${x2 + 1} ${y + 5 + dy} L${x2 + 8} ${y + 2 + dy} L${x2 + 15} ${y + 5 + dy} L${x2 + 8} ${y + 8 + dy} Z" fill="none" stroke="${c}" stroke-width="1.2"/>`;
6473
- return `<g>${slab(0)}${slab(3.5)}${slab(7)}</g>`;
6146
+ for (const e of edges) {
6147
+ if (!ids.has(e.from) || !ids.has(e.to) || e.from === e.to) continue;
6148
+ indeg.set(e.to, (indeg.get(e.to) ?? 0) + 1);
6149
+ outs.get(e.from)?.push(e.to);
6474
6150
  }
6475
- if (k2 === "function" || k2 === "lambda") {
6476
- return `<text x="${x2 + 7}" y="${y + 14}" font-family="Georgia, serif" font-size="17" font-style="italic" font-weight="700" fill="${c}" text-anchor="middle">\u0192</text>`;
6151
+ let roots = nodes.filter((n) => n.kind === "start").map((n) => n.id);
6152
+ if (roots.length === 0) roots = nodes.filter((n) => (indeg.get(n.id) ?? 0) === 0).map((n) => n.id);
6153
+ if (roots.length === 0 && nodes[0] !== void 0) roots = [nodes[0].id];
6154
+ const order = /* @__PURE__ */ new Map();
6155
+ const queue = [...roots];
6156
+ while (queue.length > 0) {
6157
+ const id = queue.shift();
6158
+ if (order.has(id)) continue;
6159
+ order.set(id, order.size);
6160
+ for (const to of outs.get(id) ?? []) {
6161
+ const d = (indeg.get(to) ?? 0) - 1;
6162
+ indeg.set(to, d);
6163
+ if (d <= 0 && !order.has(to)) queue.push(to);
6164
+ }
6477
6165
  }
6478
- if (k2 === "cdn" || k2 === "external") {
6479
- return `<path d="M${x2 + 3} ${y + 13} a 4 4 0 0 1 0.5 -8 a 5 5 0 0 1 9.5 1.2 a 3 3 0 0 1 1 6.8 z" fill="none" stroke="${c}" stroke-width="1.3"/>`;
6166
+ for (const n of nodes) if (!order.has(n.id)) order.set(n.id, order.size);
6167
+ return order;
6168
+ }
6169
+ var ERR_LABEL_RE = /^(no|fail|failed|error|reject|rejected)\b/i;
6170
+ var CELL_W = 160;
6171
+ var CELL_H = 64;
6172
+ var NODE_W = 150;
6173
+ var NODE_H = 52;
6174
+ function renderFlowSvg(data) {
6175
+ const edges = data.edges ?? [];
6176
+ const groups = data.groups ?? [];
6177
+ const rawNodes = data.nodes ?? [];
6178
+ const quick = !(rawNodes.length > 0 && rawNodes.every((n) => n.col !== void 0 && n.row !== void 0));
6179
+ const nodes = ensureGrid(rawNodes, edges, data.dir ?? "LR");
6180
+ const cellW = CELL_W;
6181
+ const cellH = CELL_H;
6182
+ const gapX = 56;
6183
+ const gapY = 48;
6184
+ const nestPad = nestingPads(groups);
6185
+ const padX = (groups.length > 0 ? GROUP_PADS.padX : 22) + nestPad.padX;
6186
+ const padTop = (groups.length > 0 ? GROUP_PADS.padTop : 22) + nestPad.padTop;
6187
+ const padBot = (groups.length > 0 ? GROUP_PADS.padBot : 18) + nestPad.padBot;
6188
+ const gx = groupExtent(groups);
6189
+ const cols = Math.max(1, ...nodes.map((n) => n.col + ((n.w ?? 1) - 1)), gx.cols);
6190
+ const rows = Math.max(1, ...nodes.map((n) => n.row), gx.rows);
6191
+ const xOf = (c) => padX + (c - 1) * (cellW + gapX);
6192
+ const yOf = (r5) => padTop + (r5 - 1) * (cellH + gapY);
6193
+ const cellFor = (n) => ({
6194
+ x: xOf(n.col),
6195
+ y: yOf(n.row),
6196
+ w: (n.w ?? 1) * cellW + ((n.w ?? 1) - 1) * gapX,
6197
+ h: cellH
6198
+ });
6199
+ const boxFor = (n) => {
6200
+ const c = cellFor(n);
6201
+ if ((n.kind ?? "process") === "decision") return c;
6202
+ const dx = (cellW - NODE_W) / 2;
6203
+ const dy = (cellH - NODE_H) / 2;
6204
+ return { x: c.x + dx, y: c.y + dy, w: c.w - dx * 2, h: NODE_H };
6205
+ };
6206
+ const byId = new Map(nodes.map((n) => [n.id, n]));
6207
+ const width = padX * 2 + cols * cellW + (cols - 1) * gapX;
6208
+ const height = padTop + rows * cellH + (rows - 1) * gapY + padBot;
6209
+ const isErrEdge = (e) => e.kind === "error" || ERR_LABEL_RE.test(e.label ?? "");
6210
+ const errTargets = new Set(edges.filter(isErrEdge).map((e) => e.to));
6211
+ const accentIds = new Set(
6212
+ nodes.filter((n) => n.kind === "end" && !errTargets.has(n.id) && !ERR_LABEL_RE.test(n.label)).map((n) => n.id)
6213
+ );
6214
+ const gridMeta = gridMetaAttrs({ quick, cols, rows, cellW, cellH, gapX, gapY, padX, padTop });
6215
+ const a11y = svgName("Flowchart", data.title, [countPhrase(nodes.length, "step")]);
6216
+ let s = `<svg viewBox="0 0 ${width} ${height}"${a11y.attrs}${gridMeta}>${a11y.title}`;
6217
+ if (groups.length > 0) s += gridGroupsSvg(groups, { xOf, yOf, cellW, cellH, gapX, gapY, skin: true });
6218
+ const used = { plain: false, dashed: false, error: false, accent: false };
6219
+ const pending = [];
6220
+ const lanes = edgeLanes(edges);
6221
+ const order = flowRevealOrder(nodes, edges);
6222
+ const stepOf = (id) => order.get(id) ?? 0;
6223
+ const entries = entryPortOffsets(edges, (id) => {
6224
+ const n = byId.get(id);
6225
+ return n !== void 0 ? boxFor(n) : void 0;
6226
+ });
6227
+ s += `<g${bl("edges")}>`;
6228
+ edges.forEach((e, ei) => {
6229
+ const A2 = byId.get(e.from);
6230
+ const B3 = byId.get(e.to);
6231
+ if (!A2 || !B3) return;
6232
+ const p2 = ortho(boxFor(A2), boxFor(B3), lanes[ei] ?? 0, entries[ei] ?? 0);
6233
+ const isErr = isErrEdge(e);
6234
+ const isAccent = !isErr && accentIds.has(e.to);
6235
+ const isDashed = !isErr && e.kind === "dashed";
6236
+ const stroke = isErr ? "var(--negative)" : isAccent ? "var(--accent)" : "var(--muted)";
6237
+ const marker2 = isErr ? "skErr" : isAccent ? "skAccent" : isDashed ? "skOpen" : "skArrow";
6238
+ const sw = isAccent ? 1.75 : 1.5;
6239
+ const dash = isDashed ? ' stroke-dasharray="5 4"' : "";
6240
+ if (isErr) used.error = true;
6241
+ else if (isAccent) used.accent = true;
6242
+ else if (isDashed) used.dashed = true;
6243
+ else used.plain = true;
6244
+ const reveal = Math.max(stepOf(e.from), stepOf(e.to));
6245
+ s += `<path d="${p2.d}" fill="none" stroke="${stroke}" stroke-width="${sw}"${dash} marker-end="url(#${marker2})"${bp(`edges.${ei}`)}${revealAttr(reveal)}/>`;
6246
+ pending.push({
6247
+ lx: p2.lx,
6248
+ ly: p2.ly,
6249
+ ...e.label !== void 0 ? { label: e.label } : {},
6250
+ err: isErr,
6251
+ accent: isAccent,
6252
+ path: `edges.${ei}`,
6253
+ reveal
6254
+ });
6255
+ });
6256
+ s += `</g>`;
6257
+ const kindsUsed = /* @__PURE__ */ new Set();
6258
+ s += `<g${bl("nodes")}>`;
6259
+ nodes.forEach((n, ni) => {
6260
+ const kind = n.kind ?? "process";
6261
+ kindsUsed.add(kind);
6262
+ const r5 = boxFor(n);
6263
+ const cx = r5.x + r5.w / 2;
6264
+ const cy = r5.y + r5.h / 2;
6265
+ const accent = accentIds.has(n.id);
6266
+ const chip3 = AI_CHIP[kind];
6267
+ const secondary2 = kind === "start" || kind === "memory";
6268
+ const stroke = accent ? "var(--accent)" : secondary2 ? "var(--rule-solid)" : "var(--ink)";
6269
+ const sw = accent ? 1.5 : secondary2 ? 1 : 1.5;
6270
+ const fill = accent ? "var(--accent-tint)" : secondary2 ? "var(--paper-2)" : "var(--paper)";
6271
+ const dash = kind === "human" ? ' stroke-dasharray="4 3"' : "";
6272
+ let shape;
6273
+ if (kind === "decision") {
6274
+ shape = `<polygon points="${cx},${r5.y} ${r5.x + r5.w},${cy} ${cx},${r5.y + r5.h} ${r5.x},${cy}" fill="${fill}" stroke="${stroke}" stroke-width="${sw}" stroke-linejoin="round"/>`;
6275
+ } else if (kind === "start" || kind === "end") {
6276
+ shape = `<rect x="${r5.x}" y="${r5.y}" width="${r5.w}" height="${r5.h}" rx="${r5.h / 2}" fill="${fill}" stroke="${stroke}" stroke-width="${sw}"/>`;
6277
+ } else {
6278
+ shape = `<rect x="${r5.x}" y="${r5.y}" width="${r5.w}" height="${r5.h}" rx="4" fill="${fill}" stroke="${stroke}" stroke-width="${sw}"${dash}/>`;
6279
+ }
6280
+ if (chip3 !== void 0) {
6281
+ shape += `<text x="${r5.x + 8}" y="${r5.y + 11}" class="blk-chip t-sub">${chip3}</text>`;
6282
+ }
6283
+ const nl = n.label.indexOf("\n");
6284
+ const name = nl >= 0 ? n.label.slice(0, nl) : n.label;
6285
+ const sub = nl >= 0 ? n.label.slice(nl + 1).replace(/\s+/g, " ").trim() : "";
6286
+ const maxChars = kind === "decision" ? 18 : 20;
6287
+ const lines = sub.length > 0 ? wrapText(name, maxChars, 1) : wrapText(name, maxChars, 2);
6288
+ const tone = accent ? " c-accent" : "";
6289
+ const dy = chip3 !== void 0 ? 4 : 0;
6290
+ let texts = "";
6291
+ if (kind === "agent" || kind === "llm") {
6292
+ const nm = wrapText(name, 17, 1)[0] ?? name;
6293
+ texts = nodeGlyph("agent", r5.x + 10, r5.y + 19, accent ? "var(--accent)" : "var(--ink)");
6294
+ texts += `<text x="${r5.x + 30}" y="${r5.y + 30}" class="al-name${tone}">${escapeHtml(nm)}</text>`;
6295
+ if (sub.length > 0) {
6296
+ const chipW = Math.min(r5.w - 20, 12 + sub.length * 5.6);
6297
+ texts += `<rect x="${r5.x + 10}" y="${r5.y + 36}" width="${chipW.toFixed(1)}" height="13" rx="3" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/><text x="${(r5.x + 10 + chipW / 2).toFixed(1)}" y="${r5.y + 45.5}" text-anchor="middle" class="al-chip">${escapeHtml(sub)}</text>`;
6298
+ }
6299
+ } else if (sub.length > 0) {
6300
+ texts = `<text x="${cx}" y="${cy - 1 + dy}" class="fc-label t-name${tone}">${escapeHtml(lines[0] ?? name)}</text><text x="${cx}" y="${cy + 12 + dy}" class="fc-sub t-sub" text-anchor="middle">${escapeHtml(sub)}</text>`;
6301
+ } else {
6302
+ texts = lines.map(
6303
+ (ln2, j2) => `<text x="${cx}" y="${cy + 4.5 + dy - (lines.length - 1) * 7.5 + j2 * 15}" class="fc-label t-name${tone}">${escapeHtml(ln2)}</text>`
6304
+ ).join("");
6305
+ }
6306
+ s += `<g${bp(`nodes.${ni}`)}${nodeCellAttrs(n.col, n.row, n.w ?? 1)}${revealAttr(stepOf(n.id))}>${shape}${texts}</g>`;
6307
+ });
6308
+ s += `</g>`;
6309
+ const { overlay, legend: steps } = edgeLabelLayer(pending, nodes.map((n) => boxFor(n)), { skin: true });
6310
+ s += overlay;
6311
+ s += `</svg>`;
6312
+ const items = [];
6313
+ if (kindsUsed.has("start")) items.push({ swatch: "node-fill2", label: "start" });
6314
+ if (kindsUsed.has("process")) items.push({ swatch: "node", label: "step" });
6315
+ if (kindsUsed.has("decision")) items.push({ swatch: "node", label: "decision (diamond)" });
6316
+ if (kindsUsed.has("agent")) items.push({ swatch: "node", label: "AGENT \xB7 autonomous step" });
6317
+ if (kindsUsed.has("llm")) items.push({ swatch: "node", label: "LLM \xB7 model call" });
6318
+ if (kindsUsed.has("tool")) items.push({ swatch: "node", label: "TOOL \xB7 retrieval / API / code" });
6319
+ if (kindsUsed.has("human")) items.push({ swatch: "node-dashed", label: "HUMAN \xB7 review gate" });
6320
+ if (kindsUsed.has("memory")) items.push({ swatch: "node-fill2", label: "MEMORY \xB7 store" });
6321
+ if (kindsUsed.has("end") && [...accentIds].length < nodes.filter((n) => n.kind === "end").length) {
6322
+ items.push({ swatch: "node", label: "exit" });
6480
6323
  }
6481
- if (k2 === "gateway" || k2 === "lb" || k2 === "proxy") {
6482
- return `<g stroke="${c}" stroke-width="1.5" fill="none"><path d="M${x2 + 2} ${y + 1} L ${x2 + 8} ${y + 7} L ${x2 + 2} ${y + 13}"/><path d="M${x2 + 8} ${y + 1} L ${x2 + 14} ${y + 7} L ${x2 + 8} ${y + 13}"/></g>`;
6324
+ if (used.plain) items.push({ swatch: "edge", label: "next" });
6325
+ if (used.dashed) items.push({ swatch: "edge-dashed", label: "optional" });
6326
+ if (used.error) items.push({ swatch: "edge-error", label: "error path" });
6327
+ if (accentIds.size > 0) items.push({ swatch: "node-accent", label: "happy path" });
6328
+ return { svg: s + steps, legend: renderLegend(items) };
6329
+ }
6330
+ function renderFlowFrame(data, tag) {
6331
+ const { svg, legend } = renderFlowSvg(data);
6332
+ return diagramFrame(
6333
+ {
6334
+ tag,
6335
+ ...data.title !== void 0 ? { title: data.title } : {},
6336
+ ...data.description !== void 0 ? { desc: data.description } : {},
6337
+ ...legend.length > 0 ? { legendHtml: legend } : {}
6338
+ },
6339
+ svg
6340
+ );
6341
+ }
6342
+ function renderFlow(data) {
6343
+ return renderFlowFrame(data, data.variant === "dag" ? "DAG" : "FLOW");
6344
+ }
6345
+
6346
+ // src/blocks/state.ts
6347
+ var ERR_RE = /\b(error|fail|failed|failure|reject|rejected|cancel|cancelled|canceled|abort|aborted|timeout|timed out|expired|dead)\b/i;
6348
+ function nameLines(s) {
6349
+ return wrapText(s.name ?? "", 23, 3);
6350
+ }
6351
+ function rectFor(s, cellW, cellH, gapX, gapY, padX, padTop) {
6352
+ const cx = padX + (s.col - 1) * (cellW + gapX) + cellW / 2;
6353
+ const cy = padTop + (s.row - 1) * (cellH + gapY) + cellH / 2;
6354
+ if (s.kind === "start" || s.kind === "terminal") {
6355
+ return { x: cx - 13, y: cy - 13, w: 26, h: 26, cx, cy };
6483
6356
  }
6484
- if (k2 === "service" || k2 === "microservice" || k2 === "compute" || k2 === "container" || k2 === "worker" || k2 === "etl") {
6485
- return `<g stroke="${c}" stroke-width="1.3"><rect x="${x2 + 4}" y="${y + 1}" width="11" height="11" rx="1.5" fill="none"/><rect x="${x2 + 1}" y="${y + 4}" width="11" height="11" rx="1.5" fill="var(--paper)"/></g>`;
6357
+ const lines = nameLines(s);
6358
+ const longest2 = Math.max(0, ...lines.map((ln2) => ln2.length));
6359
+ const pw = Math.max(96, Math.min(longest2 * 8 + 26, cellW + gapX - 26));
6360
+ const ph = 46 + (Math.max(1, lines.length) - 1) * 15;
6361
+ return { x: cx - pw / 2, y: cy - ph / 2, w: pw, h: ph, cx, cy };
6362
+ }
6363
+ function pillCls(kind) {
6364
+ if (kind === "terminal") return "pill pill-end";
6365
+ if (kind === "wait") return "pill pill-wait";
6366
+ if (kind === "start") return "pill pill-init";
6367
+ return "pill pill-active";
6368
+ }
6369
+ function renderState(data) {
6370
+ const trans = data.transitions ?? [];
6371
+ const rawStates = data.states ?? [];
6372
+ const quick = !(rawStates.length > 0 && rawStates.every((n) => n.col !== void 0 && n.row !== void 0));
6373
+ const states = ensureGrid(rawStates, trans, data.dir ?? "LR");
6374
+ const cellW = 168;
6375
+ const cellH = 64;
6376
+ const gapX = 74;
6377
+ const gapY = 60;
6378
+ const groups = data.groups ?? [];
6379
+ const nestPad = nestingPads(groups);
6380
+ const padX = (groups.length > 0 ? GROUP_PADS.padX : 30) + nestPad.padX;
6381
+ const padTop = (groups.length > 0 ? GROUP_PADS.padTop : 30) + nestPad.padTop;
6382
+ const padBot = (groups.length > 0 ? GROUP_PADS.padBot : 20) + nestPad.padBot;
6383
+ const gx = groupExtent(groups);
6384
+ const cols = Math.max(1, ...states.map((s2) => s2.col), gx.cols);
6385
+ const rows = Math.max(1, ...states.map((s2) => s2.row), gx.rows);
6386
+ const width = padX * 2 + cols * cellW + (cols - 1) * gapX;
6387
+ const height = padTop * 2 + rows * cellH + (rows - 1) * gapY + padBot;
6388
+ const byId = new Map(states.map((s2) => [s2.id, s2]));
6389
+ const isErrTerminal = (s2) => s2 !== void 0 && s2.kind === "terminal" && (ERR_RE.test(s2.name ?? "") || ERR_RE.test(s2.id));
6390
+ const successExits = states.filter((s2) => s2.kind === "terminal" && !isErrTerminal(s2));
6391
+ const accentId = successExits.length === 1 ? successExits[0]?.id : void 0;
6392
+ const gridMeta = gridMetaAttrs({ quick, cols, rows, cellW, cellH, gapX, gapY, padX, padTop });
6393
+ const a11y = svgName("State machine", data.title, [
6394
+ countPhrase(states.length, "state"),
6395
+ countPhrase(trans.length, "transition")
6396
+ ]);
6397
+ let s = `<svg viewBox="0 0 ${width} ${height}"${a11y.attrs}${gridMeta}>${a11y.title}`;
6398
+ if (groups.length > 0) {
6399
+ const xOf = (c) => padX + (c - 1) * (cellW + gapX);
6400
+ const yOf = (r5) => padTop + (r5 - 1) * (cellH + gapY);
6401
+ s += gridGroupsSvg(groups, { xOf, yOf, cellW, cellH, gapX, gapY, skin: true });
6486
6402
  }
6487
- return hasGlyph(k2) ? cloudGlyph(k2, x2, y, c) : "";
6403
+ const numbered = trans.length >= 4;
6404
+ const labels = [];
6405
+ const used = { plain: false, error: false, accent: false };
6406
+ const lanes = edgeLanes(trans);
6407
+ const avoid = states.map((st2) => {
6408
+ const r5 = rectFor(st2, cellW, cellH, gapX, gapY, padX, padTop);
6409
+ return { x: r5.x, y: r5.y, w: r5.w, h: r5.h };
6410
+ });
6411
+ const entries = entryPortOffsets(trans, (id) => {
6412
+ const n = byId.get(id);
6413
+ return n !== void 0 ? rectFor(n, cellW, cellH, gapX, gapY, padX, padTop) : void 0;
6414
+ });
6415
+ trans.forEach((t, ti) => {
6416
+ const A2 = byId.get(t.from);
6417
+ const B3 = byId.get(t.to);
6418
+ if (!A2 || !B3) return;
6419
+ const label = t.event + (t.guard !== void 0 ? ` ${t.guard}` : "");
6420
+ const isErr = isErrTerminal(B3);
6421
+ const isAccent = !isErr && accentId !== void 0 && t.to === accentId;
6422
+ const stroke = isErr ? "var(--negative)" : isAccent ? "var(--accent)" : "var(--muted)";
6423
+ const marker2 = isErr ? "skErr" : isAccent ? "skAccent" : "skArrow";
6424
+ const sw = isAccent ? 1.75 : 1.5;
6425
+ const tone = isErr ? "error" : isAccent ? "accent" : "muted";
6426
+ if (isErr) used.error = true;
6427
+ else if (isAccent) used.accent = true;
6428
+ else used.plain = true;
6429
+ const tAttrs = bp(`transitions.${ti}`) + revealAttr(ti);
6430
+ if (t.from === t.to) {
6431
+ const r5 = rectFor(A2, cellW, cellH, gapX, gapY, padX, padTop);
6432
+ s += `<path d="M ${r5.cx - 12} ${r5.y} C ${r5.cx - 30} ${r5.y - 32}, ${r5.cx + 30} ${r5.y - 32}, ${r5.cx + 12} ${r5.y}" fill="none" stroke="${stroke}" stroke-width="${sw}" marker-end="url(#${marker2})"${tAttrs}/>`;
6433
+ const at2 = { lx: r5.cx, ly: r5.y - 28 };
6434
+ const mark2 = numbered ? edgeStep(at2, ti + 1, isErr, true) : edgeMask(at2, label, tone);
6435
+ labels.push(`<g${tAttrs}>${mark2}</g>`);
6436
+ return;
6437
+ }
6438
+ const p2 = ortho(
6439
+ rectFor(A2, cellW, cellH, gapX, gapY, padX, padTop),
6440
+ rectFor(B3, cellW, cellH, gapX, gapY, padX, padTop),
6441
+ lanes[ti] ?? 0,
6442
+ entries[ti] ?? 0
6443
+ );
6444
+ s += `<path d="${p2.d}" fill="none" stroke="${stroke}" stroke-width="${sw}" marker-end="url(#${marker2})"${tAttrs}/>`;
6445
+ const mark = numbered ? edgeStep(dodge(p2.lx, p2.ly, avoid), ti + 1, isErr, true) : edgeMask(p2, label, tone);
6446
+ labels.push(`<g${tAttrs}>${mark}</g>`);
6447
+ });
6448
+ const kinds = { active: false, wait: false, start: false, end: false, errEnd: false };
6449
+ s += `<g${bl("states")}>`;
6450
+ states.forEach((st2, si) => {
6451
+ const r5 = rectFor(st2, cellW, cellH, gapX, gapY, padX, padTop);
6452
+ const place = nodeCellAttrs(st2.col, st2.row);
6453
+ if (st2.kind === "start") {
6454
+ kinds.start = true;
6455
+ s += `<circle cx="${r5.cx}" cy="${r5.cy}" r="10" fill="var(--ink)"${bp(`states.${si}`)}${place}/>`;
6456
+ } else if (st2.kind === "terminal") {
6457
+ const accent = st2.id === accentId;
6458
+ const err = isErrTerminal(st2);
6459
+ if (err) kinds.errEnd = true;
6460
+ else if (!accent) kinds.end = true;
6461
+ const tone = accent ? "var(--accent)" : err ? "var(--negative)" : "var(--ink)";
6462
+ const fill = accent ? "var(--accent-tint)" : err ? "var(--negative-tint)" : "var(--paper)";
6463
+ s += `<g${bp(`states.${si}`)}${place}><circle cx="${r5.cx}" cy="${r5.cy}" r="12" fill="${fill}" stroke="${tone}" stroke-width="1.5"/><circle cx="${r5.cx}" cy="${r5.cy}" r="6" fill="${tone}"/></g>`;
6464
+ } else {
6465
+ const wait = st2.kind === "wait";
6466
+ if (wait) kinds.wait = true;
6467
+ else kinds.active = true;
6468
+ const fill = wait ? "var(--paper-2)" : "var(--paper)";
6469
+ const stroke = wait ? "var(--rule-solid)" : "var(--ink)";
6470
+ const sw = wait ? 1 : 1.5;
6471
+ const lines = nameLines(st2);
6472
+ const nameText = lines.length <= 1 ? `<text x="${r5.cx}" y="${r5.cy + 4.5}" class="t-name" text-anchor="middle"${bp(`states.${si}.name`)}>${escapeHtml(st2.name ?? "")}</text>` : `<g${bp(`states.${si}.name`)}>` + lines.map(
6473
+ (ln2, j2) => `<text x="${r5.cx}" y="${r5.cy + 4.5 - (lines.length - 1) * 7.5 + j2 * 15}" class="t-name" text-anchor="middle">${escapeHtml(ln2)}</text>`
6474
+ ).join("") + `</g>`;
6475
+ s += `<g${bp(`states.${si}`)}${place}><rect x="${r5.x}" y="${r5.y}" width="${r5.w}" height="${r5.h}" rx="23" fill="${fill}" stroke="${stroke}" stroke-width="${sw}"/>` + nameText + `</g>`;
6476
+ }
6477
+ });
6478
+ s += `</g>`;
6479
+ s += labels.join("");
6480
+ s += `</svg>`;
6481
+ const name = (id) => byId.get(id)?.name ?? id;
6482
+ const numCell = (ti) => numbered ? `<td class="t-num"><span class="edge-step"><b>${ti + 1}</b></span></td>` : "";
6483
+ const rows2 = trans.map(
6484
+ (t, ti) => `<tr${bp(`transitions.${ti}`)}${revealAttr(ti)}>` + numCell(ti) + `<td><span class="${pillCls(byId.get(t.from)?.kind)}">${escapeHtml(name(t.from))}</span></td><td style="font-family:var(--font-mono);font-size:11px"${bp(`transitions.${ti}.event`)}>${escapeHtml(t.event)}</td><td class="c-soft" style="font-size:11px"${bp(`transitions.${ti}.guard`)}>${escapeHtml(t.guard ?? "\u2014")}</td><td><span class="${pillCls(byId.get(t.to)?.kind)}">${escapeHtml(name(t.to))}</span></td></tr>`
6485
+ ).join("");
6486
+ const table = trans.length > 0 ? `<table class="transition-table"><thead><tr>${numbered ? "<th>\u2116</th>" : ""}<th>From</th><th>Event</th><th>Guard</th><th>To</th></tr></thead><tbody${bl("transitions")}>${rows2}</tbody></table>` : "";
6487
+ const items = [];
6488
+ if (kinds.start) items.push({ swatch: "chip", chip: "\u25CF", label: "start" });
6489
+ if (kinds.active) items.push({ swatch: "node", label: "state" });
6490
+ if (kinds.wait) items.push({ swatch: "node-fill2", label: "waiting" });
6491
+ if (kinds.end) items.push({ swatch: "chip", chip: "\u25C9", label: "end" });
6492
+ if (used.plain) items.push({ swatch: "edge", label: "transition" });
6493
+ if (kinds.errEnd) items.push({ swatch: "node-negative", label: "error exit" });
6494
+ if (used.error) items.push({ swatch: "edge-error", label: "error transition" });
6495
+ if (accentId !== void 0) items.push({ swatch: "node-accent", label: "success exit" });
6496
+ const legend = renderLegend(items);
6497
+ return diagramFrame(
6498
+ {
6499
+ tag: "STATE",
6500
+ ...data.title !== void 0 ? { title: data.title } : {},
6501
+ ...data.description !== void 0 ? { desc: data.description } : {},
6502
+ ...legend.length > 0 ? { legendHtml: legend } : {},
6503
+ ...table.length > 0 ? { footerHtml: table } : {}
6504
+ },
6505
+ s
6506
+ );
6488
6507
  }
6489
- var SKIN_EDGE = {
6490
- solid: { stroke: "var(--muted)", sw: 1.5, dash: "", marker: "skArrow", err: false },
6491
- dashed: { stroke: "var(--muted)", sw: 1.5, dash: "5 4", marker: "skOpen", err: false },
6492
- forbidden: { stroke: "var(--negative)", sw: 1.5, dash: "4 3", marker: "skErr", err: true },
6493
- error: { stroke: "var(--negative)", sw: 1.5, dash: "", marker: "skErr", err: true }
6494
- };
6495
6508
 
6496
6509
  // src/svg/dfdShapes.ts
6497
6510
  function dfdKindOf(kind) {