austere-axi 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -6,10 +6,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __esm = (fn, res, err) => function __init() {
9
+ var __esm = (fn2, res, err) => function __init() {
10
10
  if (err) throw err[0];
11
11
  try {
12
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
+ return fn2 && (res = (0, fn2[__getOwnPropNames(fn2)[0]])(fn2 = 0)), res;
13
13
  } catch (e) {
14
14
  throw err = [e], e;
15
15
  }
@@ -496,7 +496,7 @@ var require_ci_info = __commonJS({
496
496
  function readArtifact(html) {
497
497
  const text = String(html);
498
498
  const m = PROGRAM_RE.exec(text);
499
- const rt = RUNTIME_RE.exec(text);
499
+ const rt2 = RUNTIME_RE.exec(text);
500
500
  const t = TITLE_RE.exec(text);
501
501
  let program = null;
502
502
  let programStart = -1;
@@ -515,7 +515,7 @@ function readArtifact(html) {
515
515
  programStart,
516
516
  programEnd,
517
517
  programLine,
518
- runtimeSrc: rt ? rt[1] : null,
518
+ runtimeSrc: rt2 ? rt2[1] : null,
519
519
  title: t ? decodeEntities(t[1].trim()) : "",
520
520
  shell
521
521
  };
@@ -605,7 +605,7 @@ var init_paths = __esm({
605
605
  HERE = path.dirname(fileURLToPath(import.meta.url));
606
606
  BUNDLED = true;
607
607
  ASSET_DIR = BUNDLED ? HERE : path.resolve(HERE, "../../dist");
608
- VERSION = true ? "0.1.0" : JSON.parse(fs.readFileSync(path.resolve(HERE, "../../package.json"), "utf8")).version;
608
+ VERSION = true ? "0.2.0" : JSON.parse(fs.readFileSync(path.resolve(HERE, "../../package.json"), "utf8")).version;
609
609
  CLI_ENTRY = BUNDLED ? fileURLToPath(import.meta.url) : path.resolve(HERE, "main.js");
610
610
  }
611
611
  });
@@ -992,7 +992,7 @@ data: ${JSON.stringify(data)}
992
992
  const items = [];
993
993
  let end = false;
994
994
  for (const e of entries) {
995
- for (const it of e.items || []) items.push(it);
995
+ for (const it2 of e.items || []) items.push(it2);
996
996
  if (e.end) end = true;
997
997
  }
998
998
  const body = {
@@ -1170,11 +1170,11 @@ data: ${JSON.stringify(data)}
1170
1170
  const clean = path4.normalize(rel).replace(/^(\.\.[/\\])+/, "");
1171
1171
  const file2 = path4.join(ASSET_DIR, clean);
1172
1172
  if (!file2.startsWith(ASSET_DIR + path4.sep)) return send(res, 404, "not found");
1173
- fs7.stat(file2, (err, st) => {
1174
- if (err || !st.isFile()) return send(res, 404, "not found");
1173
+ fs7.stat(file2, (err, st2) => {
1174
+ if (err || !st2.isFile()) return send(res, 404, "not found");
1175
1175
  res.writeHead(200, {
1176
1176
  "content-type": MIME[path4.extname(file2)] || "application/octet-stream",
1177
- "content-length": st.size,
1177
+ "content-length": st2.size,
1178
1178
  "cache-control": "no-cache",
1179
1179
  "x-content-type-options": "nosniff"
1180
1180
  });
@@ -1200,11 +1200,11 @@ data: ${JSON.stringify(data)}
1200
1200
  if (!file2.startsWith(dir + path4.sep) || decoded.split(/[/\\]/).some((p) => p.startsWith("."))) {
1201
1201
  return send(res, 404, "not found");
1202
1202
  }
1203
- fs7.stat(file2, (err, st) => {
1204
- if (err || !st.isFile() || st.size > 64 * 1024 * 1024) return send(res, 404, "not found");
1203
+ fs7.stat(file2, (err, st2) => {
1204
+ if (err || !st2.isFile() || st2.size > 64 * 1024 * 1024) return send(res, 404, "not found");
1205
1205
  res.writeHead(200, {
1206
1206
  "content-type": MIME[path4.extname(file2).toLowerCase()] || "application/octet-stream",
1207
- "content-length": st.size,
1207
+ "content-length": st2.size,
1208
1208
  "cache-control": "no-cache",
1209
1209
  "x-content-type-options": "nosniff"
1210
1210
  });
@@ -1306,7 +1306,7 @@ data: ${JSON.stringify(snapshot)}
1306
1306
  const items = Array.isArray(body.items) ? body.items.filter((x) => x && typeof x === "object").slice(0, 200) : [];
1307
1307
  if (s.status === "ended") return send(res, 409, { error: "session has ended" });
1308
1308
  if (!items.length && !body.end) return send(res, 400, { error: "nothing to send" });
1309
- for (const it of items) it.id = it.id || newId("i");
1309
+ for (const it2 of items) it2.id = it2.id || newId("i");
1310
1310
  let entry = null;
1311
1311
  if (items.length) entry = store.addUserBatch(s, items, { end: !!body.end });
1312
1312
  if (body.end) {
@@ -2347,14 +2347,14 @@ function promiseAllObject(promisesObj) {
2347
2347
  }
2348
2348
  function randomString(length = 10) {
2349
2349
  const chars = "abcdefghijklmnopqrstuvwxyz";
2350
- let str = "";
2350
+ let str2 = "";
2351
2351
  for (let i = 0; i < length; i++) {
2352
- str += chars[Math.floor(Math.random() * chars.length)];
2352
+ str2 += chars[Math.floor(Math.random() * chars.length)];
2353
2353
  }
2354
- return str;
2354
+ return str2;
2355
2355
  }
2356
- function esc(str) {
2357
- return JSON.stringify(str);
2356
+ function esc(str2) {
2357
+ return JSON.stringify(str2);
2358
2358
  }
2359
2359
  function slugify(input2) {
2360
2360
  return input2.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
@@ -2468,8 +2468,8 @@ var primitiveTypes = /* @__PURE__ */ new Set([
2468
2468
  "symbol",
2469
2469
  "undefined"
2470
2470
  ]);
2471
- function escapeRegex(str) {
2472
- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2471
+ function escapeRegex(str2) {
2472
+ return str2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2473
2473
  }
2474
2474
  function clone(inst, def, params) {
2475
2475
  const cl = new inst._zod.constr(def ?? inst._zod.def);
@@ -2735,13 +2735,13 @@ function getSizableOrigin(input2) {
2735
2735
  return "unknown";
2736
2736
  }
2737
2737
  var highSurrogate = /[\uD800-\uDBFF]/;
2738
- function codePointLength(str) {
2739
- const units = str.length;
2740
- if (!highSurrogate.test(str))
2738
+ function codePointLength(str2) {
2739
+ const units = str2.length;
2740
+ if (!highSurrogate.test(str2))
2741
2741
  return units;
2742
2742
  let count = units;
2743
2743
  for (let i = 0; i < units - 1; i++) {
2744
- if ((str.charCodeAt(i) & 64512) === 55296 && (str.charCodeAt(i + 1) & 64512) === 56320) {
2744
+ if ((str2.charCodeAt(i) & 64512) === 55296 && (str2.charCodeAt(i + 1) & 64512) === 56320) {
2745
2745
  count--;
2746
2746
  i++;
2747
2747
  }
@@ -2867,11 +2867,11 @@ function derived(computes, table) {
2867
2867
  }
2868
2868
  return table;
2869
2869
  }
2870
- function defineBound(proto, key, fn) {
2870
+ function defineBound(proto, key, fn2) {
2871
2871
  Object.defineProperty(proto, key, {
2872
2872
  configurable: true,
2873
2873
  get() {
2874
- return this == null ? fn : own(this, key, fn.bind(this));
2874
+ return this == null ? fn2 : own(this, key, fn2.bind(this));
2875
2875
  },
2876
2876
  set(value) {
2877
2877
  own(this, key, value);
@@ -2943,9 +2943,9 @@ function installLazyProp(inst, key, make, enumerable) {
2943
2943
  }
2944
2944
  var CONSTANT_CATCH = "~constantCatch";
2945
2945
  function constantCatch(value) {
2946
- const fn = () => value;
2947
- fn[CONSTANT_CATCH] = true;
2948
- return fn;
2946
+ const fn2 = () => value;
2947
+ fn2[CONSTANT_CATCH] = true;
2948
+ return fn2;
2949
2949
  }
2950
2950
 
2951
2951
  // node_modules/zod/v4/core/core.js
@@ -3029,8 +3029,8 @@ function $constructor(name, initializer3, proto, params) {
3029
3029
  init(inst, def);
3030
3030
  const deferred = inst._zod.deferred;
3031
3031
  if (deferred) {
3032
- for (const fn of deferred) {
3033
- fn();
3032
+ for (const fn2 of deferred) {
3033
+ fn2();
3034
3034
  }
3035
3035
  inst._zod.deferred = void 0;
3036
3036
  }
@@ -3267,7 +3267,7 @@ function finalizeParams(callee, params) {
3267
3267
  return { callee: params?.callee ?? callee, Err: params?.Err };
3268
3268
  }
3269
3269
  var _parse = (_Err) => {
3270
- const fn = (schema, value, _ctx, _params) => {
3270
+ const fn2 = (schema, value, _ctx, _params) => {
3271
3271
  const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
3272
3272
  const result = schema._zod.run({ value, issues: [] }, ctx);
3273
3273
  if (result instanceof Promise) {
@@ -3275,28 +3275,28 @@ var _parse = (_Err) => {
3275
3275
  }
3276
3276
  if (result.issues.length) {
3277
3277
  const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
3278
- captureStackTrace(e, _params?.callee ?? fn);
3278
+ captureStackTrace(e, _params?.callee ?? fn2);
3279
3279
  throw e;
3280
3280
  }
3281
3281
  return result.value;
3282
3282
  };
3283
- return fn;
3283
+ return fn2;
3284
3284
  };
3285
3285
  var parse = /* @__PURE__ */ _parse($ZodRealError);
3286
3286
  var _parseAsync = (_Err) => {
3287
- const fn = async (schema, value, _ctx, params) => {
3287
+ const fn2 = async (schema, value, _ctx, params) => {
3288
3288
  const ctx = _ctx ? { ..._ctx, async: true } : { async: true };
3289
3289
  let result = schema._zod.run({ value, issues: [] }, ctx);
3290
3290
  if (result instanceof Promise)
3291
3291
  result = await result;
3292
3292
  if (result.issues.length) {
3293
3293
  const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
3294
- captureStackTrace(e, params?.callee ?? fn);
3294
+ captureStackTrace(e, params?.callee ?? fn2);
3295
3295
  throw e;
3296
3296
  }
3297
3297
  return result.value;
3298
3298
  };
3299
- return fn;
3299
+ return fn2;
3300
3300
  };
3301
3301
  var parseAsync = /* @__PURE__ */ _parseAsync($ZodRealError);
3302
3302
  var _safeParse = (_Err) => (schema, value, _ctx) => {
@@ -3371,36 +3371,36 @@ var validateAsync = async (schema, value, _ctx) => {
3371
3371
  };
3372
3372
  var _encode = (_Err) => {
3373
3373
  const parse4 = _parse(_Err);
3374
- const fn = (schema, value, _ctx, _params) => {
3374
+ const fn2 = (schema, value, _ctx, _params) => {
3375
3375
  const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
3376
- return parse4(schema, value, ctx, finalizeParams(fn, _params));
3376
+ return parse4(schema, value, ctx, finalizeParams(fn2, _params));
3377
3377
  };
3378
- return fn;
3378
+ return fn2;
3379
3379
  };
3380
3380
  var encode = /* @__PURE__ */ _encode($ZodRealError);
3381
3381
  var _decode = (_Err) => {
3382
3382
  const parse4 = _parse(_Err);
3383
- const fn = (schema, value, _ctx, _params) => {
3384
- return parse4(schema, value, _ctx, finalizeParams(fn, _params));
3383
+ const fn2 = (schema, value, _ctx, _params) => {
3384
+ return parse4(schema, value, _ctx, finalizeParams(fn2, _params));
3385
3385
  };
3386
- return fn;
3386
+ return fn2;
3387
3387
  };
3388
3388
  var decode = /* @__PURE__ */ _decode($ZodRealError);
3389
3389
  var _encodeAsync = (_Err) => {
3390
3390
  const parseAsync3 = _parseAsync(_Err);
3391
- const fn = async (schema, value, _ctx, _params) => {
3391
+ const fn2 = async (schema, value, _ctx, _params) => {
3392
3392
  const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
3393
- return await parseAsync3(schema, value, ctx, finalizeParams(fn, _params));
3393
+ return await parseAsync3(schema, value, ctx, finalizeParams(fn2, _params));
3394
3394
  };
3395
- return fn;
3395
+ return fn2;
3396
3396
  };
3397
3397
  var encodeAsync = /* @__PURE__ */ _encodeAsync($ZodRealError);
3398
3398
  var _decodeAsync = (_Err) => {
3399
3399
  const parseAsync3 = _parseAsync(_Err);
3400
- const fn = async (schema, value, _ctx, _params) => {
3401
- return await parseAsync3(schema, value, _ctx, finalizeParams(fn, _params));
3400
+ const fn2 = async (schema, value, _ctx, _params) => {
3401
+ return await parseAsync3(schema, value, _ctx, finalizeParams(fn2, _params));
3402
3402
  };
3403
- return fn;
3403
+ return fn2;
3404
3404
  };
3405
3405
  var decodeAsync = /* @__PURE__ */ _decodeAsync($ZodRealError);
3406
3406
  var _safeEncode = (_Err) => (schema, value, _ctx) => {
@@ -4079,10 +4079,10 @@ var Doc = class {
4079
4079
  this.closed = closed;
4080
4080
  }
4081
4081
  // the compiler catches a child's throw and keeps writing into this doc, so the indent has to unwind with it
4082
- indented(fn) {
4082
+ indented(fn2) {
4083
4083
  this.indent += 1;
4084
4084
  try {
4085
- fn(this);
4085
+ fn2(this);
4086
4086
  } finally {
4087
4087
  this.indent -= 1;
4088
4088
  }
@@ -4128,8 +4128,8 @@ var $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
4128
4128
  const defChecks = inst._zod.def.checks;
4129
4129
  const checks = inst._zod.traits.has("$ZodCheck") ? [inst, ...defChecks ?? []] : defChecks?.length ? [...defChecks] : [];
4130
4130
  for (const ch of checks) {
4131
- for (const fn of ch._zod.onattach) {
4132
- fn(inst);
4131
+ for (const fn2 of ch._zod.onattach) {
4132
+ fn2(inst);
4133
4133
  }
4134
4134
  }
4135
4135
  if (checks.length === 0) {
@@ -5628,8 +5628,8 @@ var $ZodTuple = /* @__PURE__ */ $constructor("$ZodTuple", (inst, def) => {
5628
5628
  for (let i = 0; i < items.length; i++) {
5629
5629
  const r = items[i]._zod.run({ value: input2[i], issues: [] }, ctx);
5630
5630
  if (r instanceof Promise) {
5631
- proms.push(r.then((rr) => {
5632
- itemResults[i] = rr;
5631
+ proms.push(r.then((rr2) => {
5632
+ itemResults[i] = rr2;
5633
5633
  }));
5634
5634
  } else {
5635
5635
  itemResults[i] = r;
@@ -9351,11 +9351,11 @@ var error20 = () => {
9351
9351
  return `\u05D2\u05D3\u05D5\u05DC \u05DE\u05D3\u05D9: ${subject} ${verb} \u05DC\u05D4\u05DB\u05D9\u05DC ${comparison}`.trim();
9352
9352
  }
9353
9353
  const adj = issue2.inclusive ? "<=" : "<";
9354
- const be = verbFor(issue2.origin ?? "value");
9354
+ const be2 = verbFor(issue2.origin ?? "value");
9355
9355
  if (sizing?.unit) {
9356
- return `${sizing.longLabel} \u05DE\u05D3\u05D9: ${subject} ${be} ${adj}${issue2.maximum.toString()} ${sizing.unit}`;
9356
+ return `${sizing.longLabel} \u05DE\u05D3\u05D9: ${subject} ${be2} ${adj}${issue2.maximum.toString()} ${sizing.unit}`;
9357
9357
  }
9358
- return `${sizing?.longLabel ?? "\u05D2\u05D3\u05D5\u05DC"} \u05DE\u05D3\u05D9: ${subject} ${be} ${adj}${issue2.maximum.toString()}`;
9358
+ return `${sizing?.longLabel ?? "\u05D2\u05D3\u05D5\u05DC"} \u05DE\u05D3\u05D9: ${subject} ${be2} ${adj}${issue2.maximum.toString()}`;
9359
9359
  }
9360
9360
  case "too_small": {
9361
9361
  const sizing = getSizing(issue2.origin);
@@ -9377,11 +9377,11 @@ var error20 = () => {
9377
9377
  return `\u05E7\u05D8\u05DF \u05DE\u05D3\u05D9: ${subject} ${verb} \u05DC\u05D4\u05DB\u05D9\u05DC ${comparison}`.trim();
9378
9378
  }
9379
9379
  const adj = issue2.inclusive ? ">=" : ">";
9380
- const be = verbFor(issue2.origin ?? "value");
9380
+ const be2 = verbFor(issue2.origin ?? "value");
9381
9381
  if (sizing?.unit) {
9382
- return `${sizing.shortLabel} \u05DE\u05D3\u05D9: ${subject} ${be} ${adj}${issue2.minimum.toString()} ${sizing.unit}`;
9382
+ return `${sizing.shortLabel} \u05DE\u05D3\u05D9: ${subject} ${be2} ${adj}${issue2.minimum.toString()} ${sizing.unit}`;
9383
9383
  }
9384
- return `${sizing?.shortLabel ?? "\u05E7\u05D8\u05DF"} \u05DE\u05D3\u05D9: ${subject} ${be} ${adj}${issue2.minimum.toString()}`;
9384
+ return `${sizing?.shortLabel ?? "\u05E7\u05D8\u05DF"} \u05DE\u05D3\u05D9: ${subject} ${be2} ${adj}${issue2.minimum.toString()}`;
9385
9385
  }
9386
9386
  case "invalid_format": {
9387
9387
  const _issue = issue2;
@@ -14571,18 +14571,18 @@ ${code}` : code : "";
14571
14571
  const factoryCode = `return (input) => {
14572
14572
  ${code}
14573
14573
  }`;
14574
- let fn;
14574
+ let fn2;
14575
14575
  try {
14576
14576
  const factory = new F(...constantNames, factoryCode);
14577
- fn = factory(...constantValues);
14577
+ fn2 = factory(...constantValues);
14578
14578
  } catch (err) {
14579
14579
  throw new ZodCompileUnsupportedError(`this schema (generated code failed to evaluate: ${err.message})`);
14580
14580
  }
14581
14581
  if (options?.debug) {
14582
- fn.code = fullCode;
14582
+ fn2.code = fullCode;
14583
14583
  }
14584
- fn.definite = ctx.definite;
14585
- return fn;
14584
+ fn2.definite = ctx.definite;
14585
+ return fn2;
14586
14586
  }
14587
14587
  function addConstant(ctx, value) {
14588
14588
  for (const [name2, v] of ctx.constants) {
@@ -14593,9 +14593,9 @@ function addConstant(ctx, value) {
14593
14593
  ctx.constants.set(name, value);
14594
14594
  return name;
14595
14595
  }
14596
- function addUserConstant(ctx, fn) {
14596
+ function addUserConstant(ctx, fn2) {
14597
14597
  ctx.definite = false;
14598
- return addConstant(ctx, fn);
14598
+ return addConstant(ctx, fn2);
14599
14599
  }
14600
14600
  function newVar(ctx) {
14601
14601
  return `v${ctx.varCounter++}`;
@@ -15989,8 +15989,8 @@ function generatePipeCheck(doc, ctx, schema, accessor) {
15989
15989
  return generateCheck(doc, ctx, def.out, inputOutput);
15990
15990
  }
15991
15991
  }
15992
- function isAsyncFunction(fn) {
15993
- return typeof fn === "function" && (fn.constructor.name === "AsyncFunction" || fn[Symbol.toStringTag] === "AsyncFunction");
15992
+ function isAsyncFunction(fn2) {
15993
+ return typeof fn2 === "function" && (fn2.constructor.name === "AsyncFunction" || fn2[Symbol.toStringTag] === "AsyncFunction");
15994
15994
  }
15995
15995
  function generateCustomCheck(doc, ctx, schema, accessor) {
15996
15996
  const def = schema._zod.def;
@@ -16883,10 +16883,10 @@ function _file(Class2, params) {
16883
16883
  });
16884
16884
  }
16885
16885
  // @__NO_SIDE_EFFECTS__
16886
- function _transform(Class2, fn) {
16886
+ function _transform(Class2, fn2) {
16887
16887
  return new Class2({
16888
16888
  type: "transform",
16889
- transform: fn
16889
+ transform: fn2
16890
16890
  });
16891
16891
  }
16892
16892
  // @__NO_SIDE_EFFECTS__
@@ -16974,29 +16974,29 @@ function _promise(Class2, innerType) {
16974
16974
  });
16975
16975
  }
16976
16976
  // @__NO_SIDE_EFFECTS__
16977
- function _custom(Class2, fn, _params) {
16977
+ function _custom(Class2, fn2, _params) {
16978
16978
  const norm = normalizeParams(_params);
16979
16979
  norm.abort ?? (norm.abort = true);
16980
16980
  const schema = new Class2({
16981
16981
  type: "custom",
16982
16982
  check: "custom",
16983
- fn,
16983
+ fn: fn2,
16984
16984
  ...norm
16985
16985
  });
16986
16986
  return schema;
16987
16987
  }
16988
16988
  // @__NO_SIDE_EFFECTS__
16989
- function _refine(Class2, fn, _params) {
16989
+ function _refine(Class2, fn2, _params) {
16990
16990
  const schema = new Class2({
16991
16991
  type: "custom",
16992
16992
  check: "custom",
16993
- fn,
16993
+ fn: fn2,
16994
16994
  ...normalizeParams(_params)
16995
16995
  });
16996
16996
  return schema;
16997
16997
  }
16998
16998
  // @__NO_SIDE_EFFECTS__
16999
- function _superRefine(fn, params) {
16999
+ function _superRefine(fn2, params) {
17000
17000
  const ch = /* @__PURE__ */ _check((payload) => {
17001
17001
  payload.addIssue = (issue2) => {
17002
17002
  if (typeof issue2 === "string") {
@@ -17013,17 +17013,17 @@ function _superRefine(fn, params) {
17013
17013
  payload.issues.push(issue(_issue));
17014
17014
  }
17015
17015
  };
17016
- return fn(payload.value, payload);
17016
+ return fn2(payload.value, payload);
17017
17017
  }, params);
17018
17018
  return ch;
17019
17019
  }
17020
17020
  // @__NO_SIDE_EFFECTS__
17021
- function _check(fn, params) {
17021
+ function _check(fn2, params) {
17022
17022
  const ch = new $ZodCheck({
17023
17023
  check: "custom",
17024
17024
  ...normalizeParams(params)
17025
17025
  });
17026
- ch._zod.check = fn;
17026
+ ch._zod.check = fn2;
17027
17027
  return ch;
17028
17028
  }
17029
17029
  // @__NO_SIDE_EFFECTS__
@@ -18802,8 +18802,8 @@ var ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
18802
18802
  superRefine(refinement, params) {
18803
18803
  return this.check(superRefine(refinement, params));
18804
18804
  },
18805
- overwrite(fn) {
18806
- return this.check(_overwrite(fn));
18805
+ overwrite(fn2) {
18806
+ return this.check(_overwrite(fn2));
18807
18807
  },
18808
18808
  optional() {
18809
18809
  return optional(this);
@@ -18865,8 +18865,8 @@ var ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
18865
18865
  isNullable() {
18866
18866
  return this.safeParse(null).success;
18867
18867
  },
18868
- apply(fn, ...args) {
18869
- return args.length === 0 ? fn(this) : fn(this, ...args);
18868
+ apply(fn2, ...args) {
18869
+ return args.length === 0 ? fn2(this) : fn2(this, ...args);
18870
18870
  },
18871
18871
  // Overrides core's `~standard` to add `jsonSchema`. Must stay a prototype entry: redefining it per instance demotes instances to dictionary mode.
18872
18872
  get "~standard"() {
@@ -19926,10 +19926,10 @@ var ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
19926
19926
  return payload;
19927
19927
  };
19928
19928
  });
19929
- function transform(fn) {
19929
+ function transform(fn2) {
19930
19930
  return new ZodTransform({
19931
19931
  type: "transform",
19932
- transform: fn
19932
+ transform: fn2
19933
19933
  });
19934
19934
  }
19935
19935
  var ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
@@ -20156,22 +20156,22 @@ var ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
20156
20156
  ZodType.init(inst, def);
20157
20157
  inst._zod.processJSONSchema = (ctx, json2, params) => customProcessor(inst, ctx, json2, params);
20158
20158
  });
20159
- function check(fn) {
20159
+ function check(fn2) {
20160
20160
  const ch = new $ZodCheck({
20161
20161
  check: "custom"
20162
20162
  // ...util.normalizeParams(params),
20163
20163
  });
20164
- ch._zod.check = fn;
20164
+ ch._zod.check = fn2;
20165
20165
  return ch;
20166
20166
  }
20167
- function custom(fn, _params) {
20168
- return _custom(ZodCustom, fn ?? (() => true), _params);
20167
+ function custom(fn2, _params) {
20168
+ return _custom(ZodCustom, fn2 ?? (() => true), _params);
20169
20169
  }
20170
- function refine(fn, _params = {}) {
20171
- return _refine(ZodCustom, fn, _params);
20170
+ function refine(fn2, _params = {}) {
20171
+ return _refine(ZodCustom, fn2, _params);
20172
20172
  }
20173
- function superRefine(fn, params) {
20174
- return _superRefine(fn, params);
20173
+ function superRefine(fn2, params) {
20174
+ return _superRefine(fn2, params);
20175
20175
  }
20176
20176
  var describe2 = describe;
20177
20177
  var meta2 = meta;
@@ -20215,10 +20215,10 @@ function json(params) {
20215
20215
  });
20216
20216
  return jsonSchema;
20217
20217
  }
20218
- function preprocess(fn, schema) {
20218
+ function preprocess(fn2, schema) {
20219
20219
  return new ZodPreprocess({
20220
20220
  type: "pipe",
20221
- in: transform(fn),
20221
+ in: transform(fn2),
20222
20222
  out: schema
20223
20223
  });
20224
20224
  }
@@ -21010,7 +21010,7 @@ function fromJSONSchema(schema, params) {
21010
21010
  // node_modules/zod/v4/core/visit.js
21011
21011
  var RESOLVING = /* @__PURE__ */ Symbol("z.visit/resolving");
21012
21012
  function visit(schema, fnOrHandlers) {
21013
- const fn = typeof fnOrHandlers === "function" ? fnOrHandlers : (node2, rewritten) => {
21013
+ const fn2 = typeof fnOrHandlers === "function" ? fnOrHandlers : (node2, rewritten) => {
21014
21014
  const h = fnOrHandlers[node2._zod.def.type];
21015
21015
  return h ? h(node2, rewritten) : node2;
21016
21016
  };
@@ -21027,7 +21027,7 @@ function visit(schema, fnOrHandlers) {
21027
21027
  return cached2;
21028
21028
  cache2.set(s, RESOLVING);
21029
21029
  const inner = mapInner(s);
21030
- const mapped = fn(inner, inner !== s);
21030
+ const mapped = fn2(inner, inner !== s);
21031
21031
  cache2.set(s, mapped);
21032
21032
  return mapped;
21033
21033
  }
@@ -22286,8 +22286,8 @@ function parseExpression(tokens) {
22286
22286
  adv();
22287
22287
  const entries = [];
22288
22288
  while (cur().t !== 6 && cur().t !== 13) {
22289
- const kt = cur();
22290
- const key = kt.t === 16 || kt.t === 14 || kt.t === 17 || kt.t === 15 ? (adv(), String(kt.v)) : kt.t === 18 ? (adv(), kt.v.replace(/^\$/, "")) : (adv(), "?");
22289
+ const kt2 = cur();
22290
+ const key = kt2.t === 16 || kt2.t === 14 || kt2.t === 17 || kt2.t === 15 ? (adv(), String(kt2.v)) : kt2.t === 18 ? (adv(), kt2.v.replace(/^\$/, "")) : (adv(), "?");
22291
22291
  eat(8);
22292
22292
  entries.push([key, parseExpr(0)]);
22293
22293
  if (cur().t === 7) adv();
@@ -23182,8 +23182,8 @@ function split(tokens) {
23182
23182
  let depth = 0;
23183
23183
  let ternaryDepth = 0;
23184
23184
  while (pos < tokens.length && tokens[pos].t !== 13) {
23185
- const tt = tokens[pos].t;
23186
- if (tt === 0 && depth <= 0 && ternaryDepth <= 0) {
23185
+ const tt2 = tokens[pos].t;
23186
+ if (tt2 === 0 && depth <= 0 && ternaryDepth <= 0) {
23187
23187
  let peek = pos + 1;
23188
23188
  while (peek < tokens.length && tokens[peek].t === 0) peek++;
23189
23189
  const nextT = peek < tokens.length ? tokens[peek].t : 13;
@@ -23193,14 +23193,14 @@ function split(tokens) {
23193
23193
  }
23194
23194
  break;
23195
23195
  }
23196
- if (tt === 0) {
23196
+ if (tt2 === 0) {
23197
23197
  pos++;
23198
23198
  continue;
23199
23199
  }
23200
- if (tt === 1 || tt === 3 || tt === 5) depth++;
23201
- else if ((tt === 2 || tt === 4 || tt === 6) && depth > 0) depth--;
23202
- else if (tt === 34 && depth === 0) ternaryDepth++;
23203
- else if (tt === 8 && depth === 0 && ternaryDepth > 0) ternaryDepth--;
23200
+ if (tt2 === 1 || tt2 === 3 || tt2 === 5) depth++;
23201
+ else if ((tt2 === 2 || tt2 === 4 || tt2 === 6) && depth > 0) depth--;
23202
+ else if (tt2 === 34 && depth === 0) ternaryDepth++;
23203
+ else if (tt2 === 8 && depth === 0 && ternaryDepth > 0) ternaryDepth--;
23204
23204
  expr.push(tokens[pos++]);
23205
23205
  }
23206
23206
  if (expr.length) stmts.push({
@@ -23547,9 +23547,9 @@ function compileSchema(schema) {
23547
23547
  map2.set(name, { params: compileParams(def, defs) });
23548
23548
  }
23549
23549
  map2.callDefs = new Map(BUILTIN_CALLS);
23550
- for (const [name, fn] of Object.entries(schema.functions ?? {})) map2.callDefs.set(name, {
23550
+ for (const [name, fn2] of Object.entries(schema.functions ?? {})) map2.callDefs.set(name, {
23551
23551
  kind: "function",
23552
- params: compileParams(fn.params, defs)
23552
+ params: compileParams(fn2.params, defs)
23553
23553
  });
23554
23554
  for (const [name, action] of Object.entries(schema.actions ?? {})) map2.callDefs.set(name, {
23555
23555
  kind: "action",
@@ -23755,6 +23755,3269 @@ function nextLineContinuesTernary(src, from) {
23755
23755
  return src[j] === "?" || src[j] === ":";
23756
23756
  }
23757
23757
 
23758
+ // node_modules/@dagrejs/dagre/dist/dagre.esm.js
23759
+ var Te = Object.defineProperty;
23760
+ var Sn = (e, n, t) => n in e ? Te(e, n, { enumerable: true, configurable: true, writable: true, value: t }) : e[n] = t;
23761
+ var Mn = (e, n) => {
23762
+ for (var t in n) Te(e, t, { get: n[t], enumerable: true });
23763
+ };
23764
+ var je = (e, n, t) => Sn(e, typeof n != "symbol" ? n + "" : n, t);
23765
+ var ie = {};
23766
+ Mn(ie, { Graph: () => T, alg: () => H });
23767
+ var Pn = Object.defineProperty;
23768
+ var Se = (e, n) => {
23769
+ for (var t in n) Pn(e, t, { get: n[t], enumerable: true });
23770
+ };
23771
+ var Q = class {
23772
+ constructor(e) {
23773
+ 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 = () => {
23774
+ }, this._defaultEdgeLabelFn = () => {
23775
+ }, 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"] = {});
23776
+ }
23777
+ isDirected() {
23778
+ return this._isDirected;
23779
+ }
23780
+ isMultigraph() {
23781
+ return this._isMultigraph;
23782
+ }
23783
+ isCompound() {
23784
+ return this._isCompound;
23785
+ }
23786
+ setGraph(e) {
23787
+ return this._label = e, this;
23788
+ }
23789
+ graph() {
23790
+ return this._label;
23791
+ }
23792
+ setDefaultNodeLabel(e) {
23793
+ return typeof e != "function" ? this._defaultNodeLabelFn = () => e : this._defaultNodeLabelFn = e, this;
23794
+ }
23795
+ nodeCount() {
23796
+ return this._nodeCount;
23797
+ }
23798
+ nodes() {
23799
+ return Object.keys(this._nodes);
23800
+ }
23801
+ sources() {
23802
+ return this.nodes().filter((e) => Object.keys(this._in[e]).length === 0);
23803
+ }
23804
+ sinks() {
23805
+ return this.nodes().filter((e) => Object.keys(this._out[e]).length === 0);
23806
+ }
23807
+ setNodes(e, n) {
23808
+ return e.forEach((t) => {
23809
+ n !== void 0 ? this.setNode(t, n) : this.setNode(t);
23810
+ }), this;
23811
+ }
23812
+ setNode(e, n) {
23813
+ 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);
23814
+ }
23815
+ node(e) {
23816
+ return this._nodes[e];
23817
+ }
23818
+ hasNode(e) {
23819
+ return e in this._nodes;
23820
+ }
23821
+ removeNode(e) {
23822
+ if (e in this._nodes) {
23823
+ let n = (t) => this.removeEdge(this._edgeObjs[t]);
23824
+ delete this._nodes[e], this._isCompound && (this._removeFromParentsChildList(e), delete this._parent[e], this.children(e).forEach((t) => {
23825
+ this.setParent(t);
23826
+ }), 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;
23827
+ }
23828
+ return this;
23829
+ }
23830
+ setParent(e, n) {
23831
+ if (!this._isCompound) throw new Error("Cannot set parent in a non-compound graph");
23832
+ if (n === void 0) n = "\0";
23833
+ else {
23834
+ n += "";
23835
+ 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");
23836
+ this.setNode(n);
23837
+ }
23838
+ return this.setNode(e), this._removeFromParentsChildList(e), this._parent[e] = n, this._children[n][e] = true, this;
23839
+ }
23840
+ parent(e) {
23841
+ if (this._isCompound) {
23842
+ let n = this._parent[e];
23843
+ if (n !== "\0") return n;
23844
+ }
23845
+ }
23846
+ children(e = "\0") {
23847
+ if (this._isCompound) {
23848
+ let n = this._children[e];
23849
+ if (n) return Object.keys(n);
23850
+ } else {
23851
+ if (e === "\0") return this.nodes();
23852
+ if (this.hasNode(e)) return [];
23853
+ }
23854
+ return [];
23855
+ }
23856
+ predecessors(e) {
23857
+ let n = this._preds[e];
23858
+ if (n) return Object.keys(n);
23859
+ }
23860
+ successors(e) {
23861
+ let n = this._sucs[e];
23862
+ if (n) return Object.keys(n);
23863
+ }
23864
+ neighbors(e) {
23865
+ let n = this.predecessors(e);
23866
+ if (n) {
23867
+ let t = new Set(n), r = this.successors(e);
23868
+ if (r) for (let o of r) t.add(o);
23869
+ return Array.from(t.values());
23870
+ }
23871
+ }
23872
+ isLeaf(e) {
23873
+ var n;
23874
+ let t;
23875
+ return this.isDirected() ? t = this.successors(e) : t = this.neighbors(e), ((n = t == null ? void 0 : t.length) != null ? n : 0) === 0;
23876
+ }
23877
+ filterNodes(e) {
23878
+ let n = new this.constructor({ directed: this._isDirected, multigraph: this._isMultigraph, compound: this._isCompound });
23879
+ n.setGraph(this.graph()), Object.entries(this._nodes).forEach(([o, i]) => {
23880
+ e(o) && n.setNode(o, i);
23881
+ }), Object.values(this._edgeObjs).forEach((o) => {
23882
+ n.hasNode(o.v) && n.hasNode(o.w) && n.setEdge(o, this.edge(o));
23883
+ });
23884
+ let t = {}, r = (o) => {
23885
+ let i = this.parent(o);
23886
+ return !i || n.hasNode(i) ? (t[o] = i, i) : i in t ? t[i] : r(i);
23887
+ };
23888
+ return this._isCompound && n.nodes().forEach((o) => n.setParent(o, r(o))), n;
23889
+ }
23890
+ setDefaultEdgeLabel(e) {
23891
+ return typeof e != "function" ? this._defaultEdgeLabelFn = () => e : this._defaultEdgeLabelFn = e, this;
23892
+ }
23893
+ edgeCount() {
23894
+ return this._edgeCount;
23895
+ }
23896
+ edges() {
23897
+ return Object.values(this._edgeObjs);
23898
+ }
23899
+ setPath(e, n) {
23900
+ return e.reduce((t, r) => (n !== void 0 ? this.setEdge(t, r, n) : this.setEdge(t, r), r)), this;
23901
+ }
23902
+ setEdge(e, n, t, r) {
23903
+ let o, i, s, a, l = false;
23904
+ typeof e == "object" && e !== null && "v" in e ? (o = e.v, i = e.w, s = e.name, arguments.length === 2 && (a = n, l = true)) : (o = e, i = n, s = r, arguments.length > 2 && (a = t, l = true)), o = "" + o, i = "" + i, s !== void 0 && (s = "" + s);
23905
+ let u = z2(this._isDirected, o, i, s);
23906
+ if (u in this._edgeLabels) return l && (this._edgeLabels[u] = a), this;
23907
+ if (s !== void 0 && !this._isMultigraph) throw new Error("Cannot set a named edge when isMultigraph = false");
23908
+ this.setNode(o), this.setNode(i), this._edgeLabels[u] = l ? a : this._defaultEdgeLabelFn(o, i, s);
23909
+ let d = Fn(this._isDirected, o, i, s);
23910
+ return o = d.v, i = d.w, Object.freeze(d), this._edgeObjs[u] = d, Re(this._preds[i], o), Re(this._sucs[o], i), this._in[i][u] = d, this._out[o][u] = d, this._edgeCount++, this;
23911
+ }
23912
+ edge(e, n, t) {
23913
+ let r = arguments.length === 1 ? oe(this._isDirected, e) : z2(this._isDirected, e, n, t);
23914
+ return this._edgeLabels[r];
23915
+ }
23916
+ edgeAsObj(e, n, t) {
23917
+ let r = arguments.length === 1 ? this.edge(e) : this.edge(e, n, t);
23918
+ return typeof r != "object" || r === null ? { label: r } : r;
23919
+ }
23920
+ hasEdge(e, n, t) {
23921
+ return (arguments.length === 1 ? oe(this._isDirected, e) : z2(this._isDirected, e, n, t)) in this._edgeLabels;
23922
+ }
23923
+ removeEdge(e, n, t) {
23924
+ let r = arguments.length === 1 ? oe(this._isDirected, e) : z2(this._isDirected, e, n, t), o = this._edgeObjs[r];
23925
+ if (o) {
23926
+ let i = o.v, s = o.w;
23927
+ delete this._edgeLabels[r], delete this._edgeObjs[r], Ie(this._preds[s], i), Ie(this._sucs[i], s), delete this._in[s][r], delete this._out[i][r], this._edgeCount--;
23928
+ }
23929
+ return this;
23930
+ }
23931
+ inEdges(e, n) {
23932
+ return this.isDirected() ? this.filterEdges(this._in[e], e, n) : this.nodeEdges(e, n);
23933
+ }
23934
+ outEdges(e, n) {
23935
+ return this.isDirected() ? this.filterEdges(this._out[e], e, n) : this.nodeEdges(e, n);
23936
+ }
23937
+ nodeEdges(e, n) {
23938
+ if (e in this._nodes) return this.filterEdges({ ...this._in[e], ...this._out[e] }, e, n);
23939
+ }
23940
+ _removeFromParentsChildList(e) {
23941
+ delete this._children[this._parent[e]][e];
23942
+ }
23943
+ filterEdges(e, n, t) {
23944
+ if (!e) return;
23945
+ let r = Object.values(e);
23946
+ return t ? r.filter((o) => o.v === n && o.w === t || o.v === t && o.w === n) : r;
23947
+ }
23948
+ };
23949
+ function Re(e, n) {
23950
+ e[n] ? e[n]++ : e[n] = 1;
23951
+ }
23952
+ function Ie(e, n) {
23953
+ e[n] !== void 0 && !--e[n] && delete e[n];
23954
+ }
23955
+ function z2(e, n, t, r) {
23956
+ let o = "" + n, i = "" + t;
23957
+ if (!e && o > i) {
23958
+ let s = o;
23959
+ o = i, i = s;
23960
+ }
23961
+ return o + "" + i + "" + (r === void 0 ? "\0" : r);
23962
+ }
23963
+ function Fn(e, n, t, r) {
23964
+ let o = "" + n, i = "" + t;
23965
+ if (!e && o > i) {
23966
+ let a = o;
23967
+ o = i, i = a;
23968
+ }
23969
+ let s = { v: o, w: i };
23970
+ return r && (s.name = r), s;
23971
+ }
23972
+ function oe(e, n) {
23973
+ return z2(e, n.v, n.w, n.name);
23974
+ }
23975
+ var Dn = {};
23976
+ Se(Dn, { read: () => Bn, write: () => An });
23977
+ function An(e) {
23978
+ let n = { options: { directed: e.isDirected(), multigraph: e.isMultigraph(), compound: e.isCompound() }, nodes: Vn(e), edges: Yn(e) }, t = e.graph();
23979
+ return t !== void 0 && (n.value = structuredClone(t)), n;
23980
+ }
23981
+ function Vn(e) {
23982
+ return e.nodes().map((n) => {
23983
+ let t = e.node(n), r = e.parent(n), o = { v: n };
23984
+ return t !== void 0 && (o.value = t), r !== void 0 && (o.parent = r), o;
23985
+ });
23986
+ }
23987
+ function Yn(e) {
23988
+ return e.edges().map((n) => {
23989
+ let t = e.edge(n), r = { v: n.v, w: n.w };
23990
+ return n.name !== void 0 && (r.name = n.name), t !== void 0 && (r.value = t), r;
23991
+ });
23992
+ }
23993
+ function Bn(e) {
23994
+ let n = new Q(e.options);
23995
+ return e.value !== void 0 && n.setGraph(e.value), e.nodes.forEach((t) => {
23996
+ n.setNode(t.v, t.value), t.parent && n.setParent(t.v, t.parent);
23997
+ }), e.edges.forEach((t) => {
23998
+ n.setEdge({ v: t.v, w: t.w, name: t.name }, t.value);
23999
+ }), n;
24000
+ }
24001
+ var H = {};
24002
+ Se(H, { CycleException: () => K, bellmanFord: () => Me, components: () => zn, dijkstra: () => J, dijkstraAll: () => $n, findCycles: () => Un, floydWarshall: () => Kn, isAcyclic: () => Zn, postorder: () => nt, preorder: () => tt, prim: () => rt, shortestPaths: () => ot, tarjan: () => Fe, topsort: () => De });
24003
+ var Wn = () => 1;
24004
+ function Me(e, n, t, r) {
24005
+ return Xn(e, String(n), t || Wn, r || function(o) {
24006
+ var i;
24007
+ return (i = e.outEdges(o)) != null ? i : [];
24008
+ });
24009
+ }
24010
+ function Xn(e, n, t, r) {
24011
+ let o = {}, i, s = 0, a = e.nodes(), l = function(c) {
24012
+ let f = o[c.v], h = o[c.w];
24013
+ if (!f || !h) return;
24014
+ let g = t(c);
24015
+ f.distance + g < h.distance && (o[c.w] = { distance: f.distance + g, predecessor: c.v }, i = true);
24016
+ }, u = function() {
24017
+ a.forEach(function(c) {
24018
+ r(c).forEach(function(f) {
24019
+ let h = f.v === c ? f.v : f.w, g = h === f.v ? f.w : f.v;
24020
+ l({ v: h, w: g });
24021
+ });
24022
+ });
24023
+ };
24024
+ a.forEach(function(c) {
24025
+ let f = c === n ? 0 : Number.POSITIVE_INFINITY;
24026
+ o[c] = { distance: f, predecessor: "" };
24027
+ });
24028
+ let d = a.length;
24029
+ for (let c = 1; c < d && (i = false, s++, u(), !!i); c++) ;
24030
+ if (s === d - 1 && (i = false, u(), i)) throw new Error("The graph contains a negative weight cycle");
24031
+ return o;
24032
+ }
24033
+ function zn(e) {
24034
+ let n = {}, t = [], r;
24035
+ function o(i) {
24036
+ var s, a;
24037
+ i in n || (n[i] = true, r.push(i), (s = e.successors(i)) == null || s.forEach(o), (a = e.predecessors(i)) == null || a.forEach(o));
24038
+ }
24039
+ return e.nodes().forEach(function(i) {
24040
+ r = [], o(i), r.length && t.push(r);
24041
+ }), t;
24042
+ }
24043
+ var Pe = class {
24044
+ constructor() {
24045
+ this._arr = [], this._keyIndices = {};
24046
+ }
24047
+ size() {
24048
+ return this._arr.length;
24049
+ }
24050
+ keys() {
24051
+ return this._arr.map((e) => e.key);
24052
+ }
24053
+ has(e) {
24054
+ return e in this._keyIndices;
24055
+ }
24056
+ priority(e) {
24057
+ let n = this._keyIndices[e];
24058
+ if (n !== void 0) return this._arr[n].priority;
24059
+ }
24060
+ min() {
24061
+ if (this.size() === 0) throw new Error("Queue underflow");
24062
+ return this._arr[0].key;
24063
+ }
24064
+ add(e, n) {
24065
+ let t = this._keyIndices, r = String(e);
24066
+ if (!(r in t)) {
24067
+ let o = this._arr, i = o.length;
24068
+ return t[r] = i, o.push({ key: r, priority: n }), this._decrease(i), true;
24069
+ }
24070
+ return false;
24071
+ }
24072
+ removeMin() {
24073
+ if (this.size() === 0) throw new Error("Queue underflow");
24074
+ this._swap(0, this._arr.length - 1);
24075
+ let e = this._arr.pop();
24076
+ return delete this._keyIndices[e.key], this._heapify(0), e.key;
24077
+ }
24078
+ decrease(e, n) {
24079
+ let t = this._keyIndices[e];
24080
+ if (t === void 0) throw new Error(`Key not found: ${e}`);
24081
+ let r = this._arr[t].priority;
24082
+ if (n > r) throw new Error(`New priority is greater than current priority. Key: ${e} Old: ${r} New: ${n}`);
24083
+ this._arr[t].priority = n, this._decrease(t);
24084
+ }
24085
+ _heapify(e) {
24086
+ let n = this._arr, t = 2 * e, r = t + 1, o = e;
24087
+ t < n.length && (o = n[t].priority < n[o].priority ? t : o, r < n.length && (o = n[r].priority < n[o].priority ? r : o), o !== e && (this._swap(e, o), this._heapify(o)));
24088
+ }
24089
+ _decrease(e) {
24090
+ let n = this._arr, t = n[e].priority, r;
24091
+ for (; e !== 0 && (r = e >> 1, !(n[r].priority < t)); ) this._swap(e, r), e = r;
24092
+ }
24093
+ _swap(e, n) {
24094
+ let t = this._arr, r = this._keyIndices, o = t[e], i = t[n];
24095
+ t[e] = i, t[n] = o, r[i.key] = e, r[o.key] = n;
24096
+ }
24097
+ };
24098
+ var Hn = () => 1;
24099
+ function J(e, n, t, r) {
24100
+ let o = function(i) {
24101
+ var s;
24102
+ return (s = e.outEdges(i)) != null ? s : [];
24103
+ };
24104
+ return qn(e, String(n), t || Hn, r || o);
24105
+ }
24106
+ function qn(e, n, t, r) {
24107
+ let o = {}, i = new Pe(), s, a, l = function(u) {
24108
+ let d = u.v !== s ? u.v : u.w, c = o[d];
24109
+ if (!c) return;
24110
+ let f = t(u), h = a.distance + f;
24111
+ if (f < 0) throw new Error("dijkstra does not allow negative edge weights. Bad edge: " + u + " Weight: " + f);
24112
+ h < c.distance && (c.distance = h, c.predecessor = s, i.decrease(d, h));
24113
+ };
24114
+ for (e.nodes().forEach(function(u) {
24115
+ let d = u === n ? 0 : Number.POSITIVE_INFINITY;
24116
+ o[u] = { distance: d, predecessor: "" }, i.add(u, d);
24117
+ }); i.size() > 0; ) {
24118
+ s = i.removeMin();
24119
+ let u = o[s];
24120
+ if (!u || u.distance === Number.POSITIVE_INFINITY) break;
24121
+ a = u, r(s).forEach(l);
24122
+ }
24123
+ return o;
24124
+ }
24125
+ function $n(e, n, t) {
24126
+ return e.nodes().reduce(function(r, o) {
24127
+ return r[o] = J(e, o, n, t), r;
24128
+ }, {});
24129
+ }
24130
+ function Fe(e) {
24131
+ let n = 0, t = [], r = {}, o = [];
24132
+ function i(s) {
24133
+ var a;
24134
+ let l = r[s] = { onStack: true, lowlink: n, index: n++ };
24135
+ if (t.push(s), (a = e.successors(s)) == null || a.forEach(function(u) {
24136
+ if (u in r) {
24137
+ let d = r[u];
24138
+ d != null && d.onStack && (l.lowlink = Math.min(l.lowlink, d.index));
24139
+ } else {
24140
+ i(u);
24141
+ let d = r[u];
24142
+ d && (l.lowlink = Math.min(l.lowlink, d.lowlink));
24143
+ }
24144
+ }), l.lowlink === l.index) {
24145
+ let u = [], d;
24146
+ do {
24147
+ d = t.pop();
24148
+ let c = r[d];
24149
+ c && (c.onStack = false), u.push(d);
24150
+ } while (s !== d);
24151
+ o.push(u);
24152
+ }
24153
+ }
24154
+ return e.nodes().forEach(function(s) {
24155
+ s in r || i(s);
24156
+ }), o;
24157
+ }
24158
+ function Un(e) {
24159
+ return Fe(e).filter(function(n) {
24160
+ var t;
24161
+ let r = n[0];
24162
+ return r ? n.length > 1 || n.length === 1 && ((t = e.outEdges(r, r)) != null ? t : []).length > 0 : false;
24163
+ });
24164
+ }
24165
+ var Jn = () => 1;
24166
+ function Kn(e, n, t) {
24167
+ return Qn(e, n || Jn, t || function(r) {
24168
+ var o;
24169
+ return (o = e.outEdges(r)) != null ? o : [];
24170
+ });
24171
+ }
24172
+ function Qn(e, n, t) {
24173
+ let r = {}, o = e.nodes();
24174
+ return o.forEach(function(i) {
24175
+ let s = {};
24176
+ r[i] = s, s[i] = { distance: 0, predecessor: "" }, o.forEach(function(a) {
24177
+ i !== a && (s[a] = { distance: Number.POSITIVE_INFINITY, predecessor: "" });
24178
+ }), t(i).forEach(function(a) {
24179
+ let l = a.v === i ? a.w : a.v, u = n(a);
24180
+ s[l] = { distance: u, predecessor: i };
24181
+ });
24182
+ }), o.forEach(function(i) {
24183
+ let s = r[i];
24184
+ s && o.forEach(function(a) {
24185
+ let l = r[a];
24186
+ l && o.forEach(function(u) {
24187
+ let d = l[i], c = s[u], f = l[u];
24188
+ if (d && c && f) {
24189
+ let h = d.distance + c.distance;
24190
+ h < f.distance && (f.distance = h, f.predecessor = c.predecessor);
24191
+ }
24192
+ });
24193
+ });
24194
+ }), r;
24195
+ }
24196
+ var K = class extends Error {
24197
+ constructor(e) {
24198
+ super(e), this.name = "CycleException";
24199
+ }
24200
+ };
24201
+ function De(e) {
24202
+ let n = {}, t = {}, r = [];
24203
+ function o(i) {
24204
+ var s;
24205
+ if (i in t) throw new K();
24206
+ i in n || (t[i] = true, n[i] = true, (s = e.predecessors(i)) == null || s.forEach(o), delete t[i], r.push(i));
24207
+ }
24208
+ if (e.sinks().forEach(o), Object.keys(n).length !== e.nodeCount()) throw new K();
24209
+ return r;
24210
+ }
24211
+ function Zn(e) {
24212
+ try {
24213
+ De(e);
24214
+ } catch (n) {
24215
+ if (n instanceof K) return false;
24216
+ throw n;
24217
+ }
24218
+ return true;
24219
+ }
24220
+ function et(e, n, t, r, o) {
24221
+ Array.isArray(n) || (n = [n]);
24222
+ let i = ((a) => {
24223
+ var l;
24224
+ return (l = e.isDirected() ? e.successors(a) : e.neighbors(a)) != null ? l : [];
24225
+ }), s = {};
24226
+ return n.forEach(function(a) {
24227
+ if (!e.hasNode(a)) throw new Error("Graph does not have node: " + a);
24228
+ o = Ae(e, a, t === "post", s, i, r, o);
24229
+ }), o;
24230
+ }
24231
+ function Ae(e, n, t, r, o, i, s) {
24232
+ return n in r || (r[n] = true, t || (s = i(s, n)), o(n).forEach(function(a) {
24233
+ s = Ae(e, a, t, r, o, i, s);
24234
+ }), t && (s = i(s, n))), s;
24235
+ }
24236
+ function Ve(e, n, t) {
24237
+ return et(e, n, t, function(r, o) {
24238
+ return r.push(o), r;
24239
+ }, []);
24240
+ }
24241
+ function nt(e, n) {
24242
+ return Ve(e, n, "post");
24243
+ }
24244
+ function tt(e, n) {
24245
+ return Ve(e, n, "pre");
24246
+ }
24247
+ function rt(e, n) {
24248
+ var t;
24249
+ let r = new Q(), o = {}, i = new Pe(), s;
24250
+ function a(d) {
24251
+ let c = d.v === s ? d.w : d.v, f = i.priority(c);
24252
+ if (f !== void 0) {
24253
+ let h = n(d);
24254
+ h < f && (o[c] = s, i.decrease(c, h));
24255
+ }
24256
+ }
24257
+ if (e.nodeCount() === 0) return r;
24258
+ e.nodes().forEach(function(d) {
24259
+ i.add(d, Number.POSITIVE_INFINITY), r.setNode(d);
24260
+ });
24261
+ let l = e.nodes()[0];
24262
+ l !== void 0 && i.decrease(l, 0);
24263
+ let u = false;
24264
+ for (; i.size() > 0; ) {
24265
+ if (s = i.removeMin(), s in o) r.setEdge(s, o[s]);
24266
+ else {
24267
+ if (u) throw new Error("Input graph is not connected: " + e);
24268
+ u = true;
24269
+ }
24270
+ (t = e.nodeEdges(s)) == null || t.forEach(a);
24271
+ }
24272
+ return r;
24273
+ }
24274
+ function ot(e, n, t, r) {
24275
+ return it(e, n, t, r != null ? r : ((o) => {
24276
+ var i;
24277
+ return (i = e.outEdges(o)) != null ? i : [];
24278
+ }));
24279
+ }
24280
+ function it(e, n, t, r) {
24281
+ if (t === void 0) return J(e, n, t, r);
24282
+ let o = false, i = e.nodes();
24283
+ for (let s = 0; s < i.length; s++) {
24284
+ let a = i[s];
24285
+ if (a === void 0) continue;
24286
+ let l = r(a);
24287
+ for (let u = 0; u < l.length; u++) {
24288
+ let d = l[u];
24289
+ if (!d) continue;
24290
+ let c = d.v === a ? d.v : d.w, f = c === d.v ? d.w : d.v;
24291
+ t({ v: c, w: f }) < 0 && (o = true);
24292
+ }
24293
+ if (o) return Me(e, n, t, r);
24294
+ }
24295
+ return J(e, n, t, r);
24296
+ }
24297
+ var T = Q;
24298
+ function M(e, n, t, r) {
24299
+ let o = r;
24300
+ for (; e.hasNode(o); ) o = $(r);
24301
+ return t.dummy = n, e.setNode(o, t), o;
24302
+ }
24303
+ function Ye(e) {
24304
+ let n = new T().setGraph(e.graph());
24305
+ return e.nodes().forEach((t) => n.setNode(t, e.node(t))), e.edges().forEach((t) => {
24306
+ let r = n.edge(t.v, t.w) || { weight: 0, minlen: 1 }, o = e.edge(t);
24307
+ n.setEdge(t.v, t.w, { weight: r.weight + o.weight, minlen: Math.max(r.minlen, o.minlen) });
24308
+ }), n;
24309
+ }
24310
+ function Z(e) {
24311
+ let n = new T({ multigraph: e.isMultigraph() }).setGraph(e.graph());
24312
+ return e.nodes().forEach((t) => {
24313
+ e.children(t).length || n.setNode(t, e.node(t));
24314
+ }), e.edges().forEach((t) => {
24315
+ n.setEdge(t, e.edge(t));
24316
+ }), n;
24317
+ }
24318
+ function se(e, n) {
24319
+ let t = e.x, r = e.y, o = n.x - t, i = n.y - r, s = e.width / 2, a = e.height / 2;
24320
+ if (!o && !i) throw new Error("Not possible to find intersection inside of the rectangle");
24321
+ let l, u;
24322
+ return o === 0 || Math.abs(i) * s > Math.abs(o) * a ? (i < 0 && (a = -a), l = a * o / i, u = a) : (o < 0 && (s = -s), l = s, u = s * i / o), { x: t + l, y: r + u };
24323
+ }
24324
+ function P(e) {
24325
+ let n = D(de(e) + 1).map(() => []);
24326
+ return e.nodes().forEach((t) => {
24327
+ let r = e.node(t), o = r.rank;
24328
+ o !== void 0 && (n[o] || (n[o] = []), n[o][r.order] = t);
24329
+ }), n;
24330
+ }
24331
+ function Be(e) {
24332
+ let n = e.nodes().map((r) => {
24333
+ let o = e.node(r).rank;
24334
+ return o === void 0 ? Number.MAX_VALUE : o;
24335
+ }), t = S(Math.min, n);
24336
+ e.nodes().forEach((r) => {
24337
+ let o = e.node(r);
24338
+ Object.hasOwn(o, "rank") && (o.rank -= t);
24339
+ });
24340
+ }
24341
+ function We(e) {
24342
+ let n = e.nodes().map((s) => e.node(s).rank).filter((s) => s !== void 0), t = S(Math.min, n), r = [];
24343
+ e.nodes().forEach((s) => {
24344
+ let a = e.node(s).rank - t;
24345
+ r[a] || (r[a] = []), r[a].push(s);
24346
+ });
24347
+ let o = 0, i = e.graph().nodeRankFactor;
24348
+ Array.from(r).forEach((s, a) => {
24349
+ s === void 0 && a % i !== 0 ? --o : s !== void 0 && o && s.forEach((l) => e.node(l).rank += o);
24350
+ });
24351
+ }
24352
+ function ae(e, n, t, r) {
24353
+ let o = { width: 0, height: 0 };
24354
+ return arguments.length >= 4 && (o.rank = t, o.order = r), M(e, "border", o, n);
24355
+ }
24356
+ function st(e, n = Xe) {
24357
+ let t = [];
24358
+ for (let r = 0; r < e.length; r += n) {
24359
+ let o = e.slice(r, r + n);
24360
+ t.push(o);
24361
+ }
24362
+ return t;
24363
+ }
24364
+ var Xe = 65535;
24365
+ function S(e, n) {
24366
+ if (n.length > Xe) {
24367
+ let t = st(n);
24368
+ return e(...t.map((r) => e(...r)));
24369
+ } else return e(...n);
24370
+ }
24371
+ function de(e) {
24372
+ let t = e.nodes().map((r) => {
24373
+ let o = e.node(r).rank;
24374
+ return o === void 0 ? Number.MIN_VALUE : o;
24375
+ });
24376
+ return S(Math.max, t);
24377
+ }
24378
+ function ze(e, n) {
24379
+ let t = { lhs: [], rhs: [] };
24380
+ return e.forEach((r) => {
24381
+ n(r) ? t.lhs.push(r) : t.rhs.push(r);
24382
+ }), t;
24383
+ }
24384
+ function le(e, n) {
24385
+ let t = Date.now();
24386
+ try {
24387
+ return n();
24388
+ } finally {
24389
+ console.log(e + " time: " + (Date.now() - t) + "ms");
24390
+ }
24391
+ }
24392
+ function q(e, n) {
24393
+ return n();
24394
+ }
24395
+ var at = 0;
24396
+ function $(e) {
24397
+ let n = ++at;
24398
+ return e + ("" + n);
24399
+ }
24400
+ function D(e, n, t = 1) {
24401
+ n == null && (n = e, e = 0);
24402
+ let r = (i) => i < n;
24403
+ t < 0 && (r = (i) => n < i);
24404
+ let o = [];
24405
+ for (let i = e; r(i); i += t) o.push(i);
24406
+ return o;
24407
+ }
24408
+ function W(e, n) {
24409
+ let t = {};
24410
+ for (let r of n) e[r] !== void 0 && (t[r] = e[r]);
24411
+ return t;
24412
+ }
24413
+ function X(e, n) {
24414
+ let t;
24415
+ return typeof n == "string" ? t = (r) => r[n] : t = n, Object.entries(e).reduce((r, [o, i]) => (r[o] = t(i, o), r), {});
24416
+ }
24417
+ function He(e, n) {
24418
+ return e.reduce((t, r, o) => (t[r] = n[o], t), {});
24419
+ }
24420
+ var V = "\0";
24421
+ function ee(e, n, t) {
24422
+ var u, d, c, f, h, g;
24423
+ if (!(e && n && t && n.dummy === "edge" && t.dummy === "edge" && n.edgeObj && t.edgeObj && e[n.edgeObj.v] && e[t.edgeObj.v] && e[n.edgeObj.w] && e[t.edgeObj.w])) return 0;
24424
+ let r = true;
24425
+ n.edgeObj.w === t.edgeObj.w && (r = false);
24426
+ let o = r ? (d = (u = e[n.edgeObj.v]) == null ? void 0 : u.rank) != null ? d : NaN + 1 : (f = (c = e[n.edgeObj.w]) == null ? void 0 : c.rank) != null ? f : NaN - 1, i = Object.entries(e).find((m) => {
24427
+ var L, y;
24428
+ return ((L = m[1].edgeObj) == null ? void 0 : L.v) === n.edgeObj.v && ((y = m[1].edgeObj) == null ? void 0 : y.w) === n.edgeObj.w && m[1].rank === o;
24429
+ }), s = Object.entries(e).find((m) => {
24430
+ var L, y;
24431
+ return ((L = m[1].edgeObj) == null ? void 0 : L.v) === t.edgeObj.v && ((y = m[1].edgeObj) == null ? void 0 : y.w) === t.edgeObj.w && m[1].rank === o;
24432
+ });
24433
+ if (!i || !s) return 0;
24434
+ let a = (h = i[1].order) != null ? h : NaN, l = (g = s[1].order) != null ? g : NaN;
24435
+ return isNaN(a - l) ? 0 : a - l;
24436
+ }
24437
+ var ue = "3.1.3";
24438
+ var ce = class {
24439
+ constructor() {
24440
+ je(this, "_sentinel");
24441
+ let n = {};
24442
+ n._next = n._prev = n, this._sentinel = n;
24443
+ }
24444
+ dequeue() {
24445
+ let n = this._sentinel, t = n._prev;
24446
+ if (t !== n) return qe(t), t;
24447
+ }
24448
+ enqueue(n) {
24449
+ let t = this._sentinel;
24450
+ n._prev && n._next && qe(n), n._next = t._next, t._next._prev = n, t._next = n, n._prev = t;
24451
+ }
24452
+ toString() {
24453
+ let n = [], t = this._sentinel, r = t._prev;
24454
+ for (; r !== t; ) n.push(JSON.stringify(r, dt)), r = r._prev;
24455
+ return "[" + n.join(", ") + "]";
24456
+ }
24457
+ };
24458
+ function qe(e) {
24459
+ e._prev._next = e._next, e._next._prev = e._prev, delete e._next, delete e._prev;
24460
+ }
24461
+ function dt(e, n) {
24462
+ if (e !== "_next" && e !== "_prev") return n;
24463
+ }
24464
+ var $e = ce;
24465
+ var lt = () => 1;
24466
+ function be(e, n) {
24467
+ if (e.nodeCount() <= 1) return [];
24468
+ let t = ct(e, n || lt);
24469
+ return ut(t.graph, t.buckets, t.zeroIdx).flatMap((o) => e.outEdges(o.v, o.w) || []);
24470
+ }
24471
+ function ut(e, n, t) {
24472
+ var a;
24473
+ let r = [], o = n[n.length - 1], i = n[0], s;
24474
+ for (; e.nodeCount(); ) {
24475
+ for (; s = i.dequeue(); ) fe(e, n, t, s);
24476
+ for (; s = o.dequeue(); ) fe(e, n, t, s);
24477
+ if (e.nodeCount()) {
24478
+ for (let l = n.length - 2; l > 0; --l) if (s = (a = n[l]) == null ? void 0 : a.dequeue(), s) {
24479
+ r = r.concat(fe(e, n, t, s, true) || []);
24480
+ break;
24481
+ }
24482
+ }
24483
+ }
24484
+ return r;
24485
+ }
24486
+ function fe(e, n, t, r, o) {
24487
+ let i = [], s = o ? i : void 0;
24488
+ return (e.inEdges(r.v) || []).forEach((a) => {
24489
+ let l = e.edge(a), u = e.node(a.v);
24490
+ o && i.push({ v: a.v, w: a.w }), u.out -= l, he(n, t, u);
24491
+ }), (e.outEdges(r.v) || []).forEach((a) => {
24492
+ let l = e.edge(a), u = a.w, d = e.node(u);
24493
+ d.in -= l, he(n, t, d);
24494
+ }), e.removeNode(r.v), s;
24495
+ }
24496
+ function ct(e, n) {
24497
+ let t = new T(), r = 0, o = 0;
24498
+ e.nodes().forEach((a) => {
24499
+ t.setNode(a, { v: a, in: 0, out: 0 });
24500
+ }), e.edges().forEach((a) => {
24501
+ let l = t.edge(a.v, a.w) || 0, u = n(a), d = l + u;
24502
+ t.setEdge(a.v, a.w, d);
24503
+ let c = t.node(a.v), f = t.node(a.w);
24504
+ o = Math.max(o, c.out += u), r = Math.max(r, f.in += u);
24505
+ });
24506
+ let i = ft(o + r + 3).map(() => new $e()), s = r + 1;
24507
+ return t.nodes().forEach((a) => {
24508
+ he(i, s, t.node(a));
24509
+ }), { graph: t, buckets: i, zeroIdx: s };
24510
+ }
24511
+ function he(e, n, t) {
24512
+ var r, o, i;
24513
+ t.out ? t.in ? (i = e[t.out - t.in + n]) == null || i.enqueue(t) : (o = e[e.length - 1]) == null || o.enqueue(t) : (r = e[0]) == null || r.enqueue(t);
24514
+ }
24515
+ function ft(e) {
24516
+ let n = [];
24517
+ for (let t = 0; t < e; t++) n.push(t);
24518
+ return n;
24519
+ }
24520
+ function Ue(e, n) {
24521
+ (e.graph().acyclicer === "greedy" ? be(e, r(e)) : ht(e, n != null ? n : null)).forEach((o) => {
24522
+ let i = e.edge(o);
24523
+ e.removeEdge(o), i.forwardName = o.name, i.reversed = true, e.setEdge(o.w, o.v, i, $("rev"));
24524
+ });
24525
+ function r(o) {
24526
+ return (i) => o.edge(i).weight;
24527
+ }
24528
+ }
24529
+ function ht(e, n) {
24530
+ let t = [], r = {}, o = {};
24531
+ function i(l) {
24532
+ Object.hasOwn(o, l) || (o[l] = true, r[l] = true, e.outEdges(l).forEach((u) => {
24533
+ Object.hasOwn(r, u.w) ? t.push(u) : i(u.w);
24534
+ }), delete r[l]);
24535
+ }
24536
+ function s(l) {
24537
+ var u;
24538
+ Object.hasOwn(o, l) || (o[l] = true, r[l] = true, (u = e.outEdges(l)) == null || u.forEach((d) => {
24539
+ var c, f;
24540
+ Object.hasOwn(r, d.w) || ((c = n.node(l)) == null ? void 0 : c.rank) > ((f = n.node(d.w)) == null ? void 0 : f.rank) && bt(e, d.w, d) ? t.push(d) : s(d.w);
24541
+ }), delete r[l]);
24542
+ }
24543
+ let a = i;
24544
+ return n && typeof n.node == "function" && (a = s), e.sources().forEach(a), e.nodes().forEach(a), t;
24545
+ }
24546
+ function Je(e) {
24547
+ e.edges().forEach((n) => {
24548
+ let t = e.edge(n);
24549
+ if (t.reversed) {
24550
+ e.removeEdge(n);
24551
+ let r = t.forwardName;
24552
+ delete t.reversed, delete t.forwardName, e.setEdge(n.w, n.v, t, r);
24553
+ }
24554
+ });
24555
+ }
24556
+ function bt(e, n, t) {
24557
+ let r = /* @__PURE__ */ new Set();
24558
+ function o(i) {
24559
+ var s;
24560
+ if (e.sources().includes(i)) return true;
24561
+ r.add(i);
24562
+ for (let a of (s = e.inEdges(i)) != null ? s : []) if (!(a.v === t.v && a.w === t.w) && !r.has(a.v) && o(a.v)) return true;
24563
+ return false;
24564
+ }
24565
+ return o(n);
24566
+ }
24567
+ function Ke(e) {
24568
+ e.graph().dummyChains = [], e.edges().forEach((n) => pt(e, n));
24569
+ }
24570
+ function pt(e, n) {
24571
+ let t = n.v, r = e.node(t).rank, o = n.w, i = e.node(o).rank, s = n.name, a = e.edge(n), l = a.labelRank;
24572
+ if (i === r + 1) return;
24573
+ e.removeEdge(n);
24574
+ let u, d, c;
24575
+ for (c = 0, ++r; r < i; ++c, ++r) a.points = [], d = { width: 0, height: 0, edgeLabel: a, edgeObj: n, rank: r }, u = M(e, "edge", d, "_d"), r === l && (d.width = a.width, d.height = a.height, d.dummy = "edge-label", d.labelpos = a.labelpos), e.setEdge(t, u, { weight: a.weight }, s), c === 0 && e.graph().dummyChains.push(u), t = u;
24576
+ e.setEdge(t, o, { weight: a.weight }, s);
24577
+ }
24578
+ function Qe(e) {
24579
+ e.graph().dummyChains.forEach((n) => {
24580
+ let t = e.node(n), r = t.edgeLabel, o;
24581
+ for (e.setEdge(t.edgeObj, r); t.dummy; ) o = e.successors(n)[0], e.removeNode(n), r.points.push({ x: t.x, y: t.y }), t.dummy === "edge-label" && (r.x = t.x, r.y = t.y, r.width = t.width, r.height = t.height), n = o, t = e.node(n);
24582
+ });
24583
+ }
24584
+ function U(e) {
24585
+ let n = {};
24586
+ function t(r) {
24587
+ let o = e.node(r);
24588
+ if (Object.hasOwn(n, r)) return o.rank;
24589
+ n[r] = true;
24590
+ let i = e.outEdges(r), s = i ? i.map((l) => l == null ? Number.POSITIVE_INFINITY : t(l.w) - e.edge(l).minlen) : [], a = S(Math.min, s);
24591
+ return a === Number.POSITIVE_INFINITY && (a = 0), o.rank = a;
24592
+ }
24593
+ e.sources().forEach(t);
24594
+ }
24595
+ function A(e, n) {
24596
+ return e.node(n.w).rank - e.node(n.v).rank - e.edge(n).minlen;
24597
+ }
24598
+ var ne = Et;
24599
+ function Et(e) {
24600
+ let n = new T({ directed: false }), t = e.nodes();
24601
+ if (t.length === 0) throw new Error("Graph must have at least one node");
24602
+ let r = t[0], o = e.nodeCount();
24603
+ n.setNode(r, {});
24604
+ let i, s;
24605
+ for (; Lt(n, e) < o && (i = yt(n, e), !!i); ) s = n.hasNode(i.v) ? A(e, i) : -A(e, i), wt(n, e, s);
24606
+ return n;
24607
+ }
24608
+ function Lt(e, n) {
24609
+ function t(r) {
24610
+ let o = n.nodeEdges(r);
24611
+ o && o.forEach((i) => {
24612
+ let s = i.v, a = r === s ? i.w : s;
24613
+ !e.hasNode(a) && !A(n, i) && (e.setNode(a, {}), e.setEdge(r, a, {}), t(a));
24614
+ });
24615
+ }
24616
+ return e.nodes().forEach(t), e.nodeCount();
24617
+ }
24618
+ function yt(e, n) {
24619
+ return n.edges().reduce((r, o) => {
24620
+ let i = Number.POSITIVE_INFINITY;
24621
+ return e.hasNode(o.v) !== e.hasNode(o.w) && (i = A(n, o)), i < r[0] ? [i, o] : r;
24622
+ }, [Number.POSITIVE_INFINITY, null])[1];
24623
+ }
24624
+ function wt(e, n, t) {
24625
+ e.nodes().forEach((r) => n.node(r).rank += t);
24626
+ }
24627
+ var { preorder: Nt, postorder: Gt } = H;
24628
+ var en = Y;
24629
+ Y.initLowLimValues = pe;
24630
+ Y.initCutValues = ge;
24631
+ Y.calcCutValue = nn;
24632
+ Y.leaveEdge = rn;
24633
+ Y.enterEdge = on;
24634
+ Y.exchangeEdges = sn;
24635
+ function Y(e) {
24636
+ e = Ye(e), U(e);
24637
+ let n = ne(e);
24638
+ pe(n), ge(n, e);
24639
+ let t, r;
24640
+ for (; t = rn(n); ) r = on(n, e, t), sn(n, e, t, r);
24641
+ }
24642
+ function ge(e, n) {
24643
+ let t = Gt(e, e.nodes());
24644
+ t = t.slice(0, t.length - 1), t.forEach((r) => vt(e, n, r));
24645
+ }
24646
+ function vt(e, n, t) {
24647
+ let o = e.node(t).parent, i = e.edge(t, o);
24648
+ i.cutvalue = nn(e, n, t);
24649
+ }
24650
+ function nn(e, n, t) {
24651
+ let o = e.node(t).parent, i = true, s = n.edge(t, o), a = 0;
24652
+ s || (i = false, s = n.edge(o, t)), a = s.weight;
24653
+ let l = n.nodeEdges(t);
24654
+ return l && l.forEach((u) => {
24655
+ let d = u.v === t, c = d ? u.w : u.v;
24656
+ if (c !== o) {
24657
+ let f = d === i, h = n.edge(u).weight;
24658
+ if (a += f ? h : -h, xt(e, t, c)) {
24659
+ let m = e.edge(t, c).cutvalue;
24660
+ a += f ? -m : m;
24661
+ }
24662
+ }
24663
+ }), a;
24664
+ }
24665
+ function pe(e, n) {
24666
+ arguments.length < 2 && (n = e.nodes()[0]), tn(e, {}, 1, n);
24667
+ }
24668
+ function tn(e, n, t, r, o) {
24669
+ let i = t, s = e.node(r);
24670
+ n[r] = true;
24671
+ let a = e.neighbors(r);
24672
+ return a && a.forEach((l) => {
24673
+ Object.hasOwn(n, l) || (t = tn(e, n, t, l, r));
24674
+ }), s.low = i, s.lim = t++, o ? s.parent = o : delete s.parent, t;
24675
+ }
24676
+ function rn(e) {
24677
+ return e.edges().find((n) => e.edge(n).cutvalue < 0);
24678
+ }
24679
+ function on(e, n, t) {
24680
+ let r = t.v, o = t.w;
24681
+ n.hasEdge(r, o) || (r = t.w, o = t.v);
24682
+ let i = e.node(r), s = e.node(o), a = i, l = false;
24683
+ return i.lim > s.lim && (a = s, l = true), n.edges().filter((d) => l === Ze(e, e.node(d.v), a) && l !== Ze(e, e.node(d.w), a)).reduce((d, c) => A(n, c) < A(n, d) ? c : d);
24684
+ }
24685
+ function sn(e, n, t, r) {
24686
+ let o = t.v, i = t.w;
24687
+ e.removeEdge(o, i), e.setEdge(r.v, r.w, {}), pe(e), ge(e, n), kt(e, n);
24688
+ }
24689
+ function kt(e, n) {
24690
+ let t = e.nodes().find((o) => !e.node(o).parent);
24691
+ if (!t) return;
24692
+ let r = Nt(e, [t]);
24693
+ r = r.slice(1), r.forEach((o) => {
24694
+ let s = e.node(o).parent, a = n.edge(o, s), l = false;
24695
+ a || (a = n.edge(s, o), l = true), n.node(o).rank = n.node(s).rank + (l ? a.minlen : -a.minlen);
24696
+ });
24697
+ }
24698
+ function xt(e, n, t) {
24699
+ return e.hasEdge(n, t);
24700
+ }
24701
+ function Ze(e, n, t) {
24702
+ return t.low <= n.lim && n.lim <= t.lim;
24703
+ }
24704
+ var dn = _t;
24705
+ function _t(e) {
24706
+ let n = e.graph().ranker;
24707
+ if (typeof n == "function") return n(e);
24708
+ switch (n) {
24709
+ case "network-simplex":
24710
+ an(e);
24711
+ break;
24712
+ case "tight-tree":
24713
+ Ct(e);
24714
+ break;
24715
+ case "longest-path":
24716
+ Ot(e);
24717
+ break;
24718
+ case "none":
24719
+ break;
24720
+ default:
24721
+ an(e);
24722
+ }
24723
+ }
24724
+ var Ot = U;
24725
+ function Ct(e) {
24726
+ U(e), ne(e);
24727
+ }
24728
+ function an(e) {
24729
+ en(e);
24730
+ }
24731
+ var ln = Tt;
24732
+ function Tt(e) {
24733
+ let n = Rt(e), t = e.graph();
24734
+ if (!Array.isArray(t.dummyChains)) return;
24735
+ t.dummyChains.forEach((o) => {
24736
+ let i = e.node(o), s = i.edgeObj, a = jt(e, n, s.v, s.w), l = a.path, u = a.lca, d = 0, c = l[d], f = true;
24737
+ for (; o !== s.w; ) {
24738
+ if (i = e.node(o), f) {
24739
+ for (; (c = l[d]) !== u && e.node(c).maxRank < i.rank; ) d++;
24740
+ c === u && (f = false);
24741
+ }
24742
+ if (!f) {
24743
+ for (; d < l.length - 1 && e.node(l[d + 1]).minRank <= i.rank; ) d++;
24744
+ c = l[d];
24745
+ }
24746
+ c !== void 0 && e.setParent(o, c), o = e.successors(o)[0];
24747
+ }
24748
+ });
24749
+ }
24750
+ function jt(e, n, t, r) {
24751
+ let o = [], i = [], s = Math.min(n[t].low, n[r].low), a = Math.max(n[t].lim, n[r].lim), l;
24752
+ l = t;
24753
+ do
24754
+ l = e.parent(l), o.push(l);
24755
+ while (l && (n[l].low > s || a > n[l].lim));
24756
+ let u = l, d = r;
24757
+ for (; (d = e.parent(d)) !== u; ) i.push(d);
24758
+ return { path: o.concat(i.reverse()), lca: u };
24759
+ }
24760
+ function Rt(e) {
24761
+ let n = {}, t = 0;
24762
+ function r(o) {
24763
+ let i = t;
24764
+ e.children(o).forEach(r), n[o] = { low: i, lim: t++ };
24765
+ }
24766
+ return e.children(V).forEach(r), n;
24767
+ }
24768
+ function un(e) {
24769
+ let n = M(e, "root", {}, "_root"), t = It(e), r = Object.values(t), o = S(Math.max, r) - 1, i = 2 * o + 1;
24770
+ e.graph().nestingRoot = n, e.edges().forEach((a) => e.edge(a).minlen *= i);
24771
+ let s = St(e) + 1;
24772
+ e.children(V).forEach((a) => {
24773
+ cn(e, n, i, s, o, t, a);
24774
+ }), e.graph().nodeRankFactor = i;
24775
+ }
24776
+ function cn(e, n, t, r, o, i, s) {
24777
+ var c;
24778
+ let a = e.children(s);
24779
+ if (!a.length) {
24780
+ s !== n && e.setEdge(n, s, { weight: 0, minlen: t });
24781
+ return;
24782
+ }
24783
+ let l = ae(e, "_bt"), u = ae(e, "_bb"), d = e.node(s);
24784
+ e.setParent(l, s), d.borderTop = l, e.setParent(u, s), d.borderBottom = u, a.forEach((f) => {
24785
+ var b;
24786
+ cn(e, n, t, r, o, i, f);
24787
+ let h = e.node(f), g = h.borderTop ? h.borderTop : f, m = h.borderBottom ? h.borderBottom : f, L = h.borderTop ? r : 2 * r, y = g !== m ? 1 : o - ((b = i[s]) != null ? b : 0) + 1;
24788
+ e.setEdge(l, g, { weight: L, minlen: y, nestingEdge: true }), e.setEdge(m, u, { weight: L, minlen: y, nestingEdge: true });
24789
+ }), e.parent(s) || e.setEdge(n, l, { weight: 0, minlen: o + ((c = i[s]) != null ? c : 0) });
24790
+ }
24791
+ function It(e) {
24792
+ let n = {};
24793
+ function t(r, o) {
24794
+ let i = e.children(r);
24795
+ i && i.length && i.forEach((s) => t(s, o + 1)), n[r] = o;
24796
+ }
24797
+ return e.children(V).forEach((r) => t(r, 1)), n;
24798
+ }
24799
+ function St(e) {
24800
+ return e.edges().reduce((n, t) => n + e.edge(t).weight, 0);
24801
+ }
24802
+ function fn(e) {
24803
+ let n = e.graph();
24804
+ e.removeNode(n.nestingRoot), delete n.nestingRoot, e.edges().forEach((t) => {
24805
+ e.edge(t).nestingEdge && e.removeEdge(t);
24806
+ });
24807
+ }
24808
+ var bn = Pt;
24809
+ function Pt(e) {
24810
+ function n(t) {
24811
+ let r = e.children(t), o = e.node(t);
24812
+ if (r.length && r.forEach(n), o && Object.hasOwn(o, "minRank")) {
24813
+ o.borderLeft = [], o.borderRight = [];
24814
+ for (let i = o.minRank, s = o.maxRank + 1; i < s; ++i) hn(e, "borderLeft", "_bl", t, o, i), hn(e, "borderRight", "_br", t, o, i);
24815
+ }
24816
+ }
24817
+ e.children(V).forEach(n);
24818
+ }
24819
+ function hn(e, n, t, r, o, i) {
24820
+ let s = { width: 0, height: 0, rank: i, borderType: n }, a = o[n][i - 1], l = M(e, "border", s, t);
24821
+ o[n][i] = l, e.setParent(l, r), a && e.setEdge(a, l, { weight: 1 });
24822
+ }
24823
+ function pn(e) {
24824
+ var t;
24825
+ let n = (t = e.graph().rankdir) == null ? void 0 : t.toLowerCase();
24826
+ (n === "lr" || n === "rl") && En(e);
24827
+ }
24828
+ function mn(e) {
24829
+ var t;
24830
+ let n = (t = e.graph().rankdir) == null ? void 0 : t.toLowerCase();
24831
+ (n === "bt" || n === "rl") && Ft(e), (n === "lr" || n === "rl") && (Dt(e), En(e));
24832
+ }
24833
+ function En(e) {
24834
+ e.nodes().forEach((n) => gn(e.node(n))), e.edges().forEach((n) => gn(e.edge(n)));
24835
+ }
24836
+ function gn(e) {
24837
+ let n = e.width;
24838
+ e.width = e.height, e.height = n;
24839
+ }
24840
+ function Ft(e) {
24841
+ e.nodes().forEach((n) => me(e.node(n))), e.edges().forEach((n) => {
24842
+ var r;
24843
+ let t = e.edge(n);
24844
+ (r = t.points) == null || r.forEach(me), Object.hasOwn(t, "y") && me(t);
24845
+ });
24846
+ }
24847
+ function me(e) {
24848
+ e.y = -e.y;
24849
+ }
24850
+ function Dt(e) {
24851
+ e.nodes().forEach((n) => Ee(e.node(n))), e.edges().forEach((n) => {
24852
+ var r;
24853
+ let t = e.edge(n);
24854
+ (r = t.points) == null || r.forEach(Ee), Object.hasOwn(t, "x") && Ee(t);
24855
+ });
24856
+ }
24857
+ function Ee(e) {
24858
+ let n = e.x;
24859
+ e.x = e.y, e.y = n;
24860
+ }
24861
+ function Le(e, n = null) {
24862
+ let t = {}, r = e.nodes().filter((d) => !e.children(d).length), o = r.map((d) => e.node(d).rank), i = S(Math.max, o), s = D(i + 1).map(() => []);
24863
+ function a(d) {
24864
+ if (t[d]) return;
24865
+ t[d] = true;
24866
+ let c = e.node(d);
24867
+ s[c.rank].push(d);
24868
+ let f = e.successors(d);
24869
+ f && [...f].sort((g, m) => u(g, m)).forEach(a);
24870
+ }
24871
+ r.sort((d, c) => e.node(d).rank - e.node(c).rank).forEach(a);
24872
+ function u(d, c) {
24873
+ let f = e.node(d), h = e.node(c);
24874
+ return ee(n, f, h);
24875
+ }
24876
+ return s;
24877
+ }
24878
+ function ye(e, n) {
24879
+ let t = 0;
24880
+ for (let r = 1; r < n.length; ++r) t += Vt(e, n[r - 1], n[r]);
24881
+ return t;
24882
+ }
24883
+ function Vt(e, n, t) {
24884
+ let r = He(t, t.map((u, d) => d)), o = n.flatMap((u) => {
24885
+ let d = e.outEdges(u);
24886
+ return d ? d.map((c) => ({ pos: r[c.w], weight: e.edge(c).weight })).sort((c, f) => c.pos - f.pos) : [];
24887
+ }), i = 1;
24888
+ for (; i < t.length; ) i <<= 1;
24889
+ let s = 2 * i - 1;
24890
+ i -= 1;
24891
+ let a = new Array(s).fill(0), l = 0;
24892
+ return o.forEach((u) => {
24893
+ let d = u.pos + i;
24894
+ a[d] += u.weight;
24895
+ let c = 0;
24896
+ for (; d > 0; ) d % 2 && (c += a[d + 1]), d = d - 1 >> 1, a[d] += u.weight;
24897
+ l += u.weight * c;
24898
+ }), l;
24899
+ }
24900
+ function we(e, n = []) {
24901
+ return n.map((t) => {
24902
+ let r = e.inEdges(t);
24903
+ if (!r || !r.length) return { v: t };
24904
+ {
24905
+ let o = r.reduce((i, s) => {
24906
+ let a = e.edge(s), l = e.node(s.v);
24907
+ return { sum: i.sum + a.weight * l.order, weight: i.weight + a.weight };
24908
+ }, { sum: 0, weight: 0 });
24909
+ return { v: t, barycenter: o.sum / o.weight, weight: o.weight };
24910
+ }
24911
+ });
24912
+ }
24913
+ function Ne(e, n) {
24914
+ let t = {};
24915
+ e.forEach((o, i) => {
24916
+ let s = { indegree: 0, in: [], out: [], vs: [o.v], i };
24917
+ o.barycenter !== void 0 && (s.barycenter = o.barycenter, s.weight = o.weight), t[o.v] = s;
24918
+ }), n.edges().forEach((o) => {
24919
+ let i = t[o.v], s = t[o.w];
24920
+ i !== void 0 && s !== void 0 && (s.indegree++, i.out.push(s));
24921
+ });
24922
+ let r = Object.values(t).filter((o) => !o.indegree);
24923
+ return Yt(r);
24924
+ }
24925
+ function Yt(e) {
24926
+ let n = [];
24927
+ function t(o) {
24928
+ return (i) => {
24929
+ i.merged || (i.barycenter === void 0 || o.barycenter === void 0 || i.barycenter >= o.barycenter) && Bt(o, i);
24930
+ };
24931
+ }
24932
+ function r(o) {
24933
+ return (i) => {
24934
+ i.in.push(o), --i.indegree === 0 && e.push(i);
24935
+ };
24936
+ }
24937
+ for (; e.length; ) {
24938
+ let o = e.pop();
24939
+ n.push(o), o.in.reverse().forEach(t(o)), o.out.forEach(r(o));
24940
+ }
24941
+ return n.filter((o) => !o.merged).map((o) => W(o, ["vs", "i", "barycenter", "weight"]));
24942
+ }
24943
+ function Bt(e, n) {
24944
+ let t = 0, r = 0;
24945
+ e.weight && (t += e.barycenter * e.weight, r += e.weight), n.weight && (t += n.barycenter * n.weight, r += n.weight), e.vs = n.vs.concat(e.vs), e.barycenter = t / r, e.weight = r, e.i = Math.min(n.i, e.i), n.merged = true;
24946
+ }
24947
+ function Ge(e, n, t, r, o) {
24948
+ let i = {}, s = null, a = null, l = o;
24949
+ typeof n == "boolean" ? (l = n, i = {}) : n && (i = n, s = t != null ? t : null, a = r != null ? r : null);
24950
+ let u = ze(e, (y) => Object.hasOwn(y, "barycenter")), d = u.lhs, c = u.rhs.sort((y, b) => b.i - y.i), f = [], h = 0, g = 0, m = 0;
24951
+ d.sort(Wt(a, s, !!l));
24952
+ for (let [y, b] of Object.entries(i)) {
24953
+ let p = d.findIndex((E) => E.vs[0] === y);
24954
+ d.splice(p + 1, 0, b);
24955
+ }
24956
+ m = Ln(f, c, m), d.forEach((y) => {
24957
+ m += y.vs.length, f.push(y.vs), h += y.barycenter * y.weight, g += y.weight, m = Ln(f, c, m);
24958
+ });
24959
+ let L = { vs: f.flat(1) };
24960
+ return g && (L.barycenter = h / g, L.weight = g), L;
24961
+ }
24962
+ function Ln(e, n, t) {
24963
+ let r;
24964
+ for (; n.length && (r = n[n.length - 1]).i <= t; ) n.pop(), e.push(r.vs), t++;
24965
+ return t;
24966
+ }
24967
+ function Wt(e, n, t) {
24968
+ return (r, o) => {
24969
+ if (r.barycenter < o.barycenter) return -1;
24970
+ if (r.barycenter > o.barycenter) return 1;
24971
+ if (e && (typeof r.vs[0] == "string" || typeof o.vs[0] == "string")) {
24972
+ let i = e.node(r.vs[0]), s = e.node(o.vs[0]), a = ee(n, i, s);
24973
+ if (a !== 0) return a;
24974
+ }
24975
+ return t ? o.i - r.i : r.i - o.i;
24976
+ };
24977
+ }
24978
+ function te(e, n, t, r, o) {
24979
+ var y, b, p, E, w, k, _, O, j, R, I;
24980
+ let i = null, s = o;
24981
+ typeof r == "boolean" ? (s = r, i = null) : r !== void 0 && (i = r);
24982
+ let a = e.children(n), l = e.node(n), u = l ? l.borderLeft : void 0, d = l ? l.borderRight : void 0, c = {};
24983
+ u && (a = a.filter((v) => v !== u && v !== d));
24984
+ let f = we(e, a);
24985
+ f.forEach((v) => {
24986
+ if (e.children(v.v).length) {
24987
+ let { result: x } = te(e, v.v, t, i, s);
24988
+ c[v.v] = x, Object.hasOwn(x, "barycenter") && zt(v, x);
24989
+ }
24990
+ });
24991
+ let h = Ne(f, t);
24992
+ Xt(h, c);
24993
+ let g = {}, m = false;
24994
+ for (let v = 0; v < h.length; v++) for (let x = v + 1; x < h.length; x++) if (!(!h[v] || !h[x] || !((y = h[v]) != null && y.barycenter) || !((b = h[x]) != null && b.barycenter)) && ((p = h[v]) == null ? void 0 : p.barycenter) === h[x].barycenter) {
24995
+ let G = (w = (E = h[v]) == null ? void 0 : E.vs[0]) != null ? w : "", N = (_ = (k = h[x]) == null ? void 0 : k.vs[0]) != null ? _ : "", C = e.node(G), B = e.node(N);
24996
+ if (C.dummy === "edge" && B.dummy === "edge" && ((O = C.edgeObj) == null ? void 0 : O.v) === ((j = B.edgeObj) == null ? void 0 : j.v) && ((R = C.edgeObj) == null ? void 0 : R.w) === ((I = B.edgeObj) == null ? void 0 : I.w)) if (C.edgeLabel.reversed) {
24997
+ g[N] = h[v], h.splice(v, 1), v--;
24998
+ break;
24999
+ } else g[G] || (g[G] = h[x], h.splice(x, 1), x--);
25000
+ else m = true;
25001
+ }
25002
+ let L = Ge(h, g, i, e, s);
25003
+ if (u && d) {
25004
+ L.vs = [u, L.vs, d].flat(1);
25005
+ let v = e.predecessors(u);
25006
+ if (v && v.length) {
25007
+ let x = e.node(v[0]), G = e.predecessors(d), N = e.node(G[0]);
25008
+ Object.hasOwn(L, "barycenter") || (L.barycenter = 0, L.weight = 0), L.barycenter = (L.barycenter * L.weight + x.order + N.order) / (L.weight + 2), L.weight += 2;
25009
+ }
25010
+ }
25011
+ return Object.defineProperty(L, "result", { value: L, enumerable: false, configurable: true, writable: true }), Object.defineProperty(L, "usedBias", { value: m, enumerable: false, configurable: true, writable: true }), L;
25012
+ }
25013
+ function Xt(e, n) {
25014
+ e.forEach((t) => {
25015
+ t.vs = t.vs.flatMap((r) => n[r] ? n[r].vs : r);
25016
+ });
25017
+ }
25018
+ function zt(e, n) {
25019
+ 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);
25020
+ }
25021
+ function ve(e, n, t, r) {
25022
+ r || (r = e.nodes());
25023
+ let o = Ht(e), i = new T({ compound: true }).setGraph({ root: o }).setDefaultNodeLabel((s) => e.node(s));
25024
+ return r.forEach((s) => {
25025
+ let a = e.node(s), l = e.parent(s);
25026
+ if (a.rank === n || a.minRank <= n && n <= a.maxRank) {
25027
+ i.setNode(s), i.setParent(s, l || o);
25028
+ let u = e[t](s);
25029
+ u && u.forEach((d) => {
25030
+ let c = d.v === s ? d.w : d.v, f = i.edge(c, s), h = f !== void 0 ? f.weight : 0;
25031
+ i.setEdge(c, s, { weight: e.edge(d).weight + h });
25032
+ }), Object.hasOwn(a, "minRank") && i.setNode(s, { borderLeft: a.borderLeft[n], borderRight: a.borderRight[n] });
25033
+ }
25034
+ }), i;
25035
+ }
25036
+ function Ht(e) {
25037
+ let n;
25038
+ for (; e.hasNode(n = $("_root")); ) ;
25039
+ return n;
25040
+ }
25041
+ function ke(e, n, t) {
25042
+ let r = {}, o;
25043
+ t.forEach((i) => {
25044
+ let s = e.parent(i), a, l;
25045
+ for (; s; ) {
25046
+ if (a = e.parent(s), a ? (l = r[a], r[a] = s) : (l = o, o = s), l && l !== s) {
25047
+ n.setEdge(l, s);
25048
+ return;
25049
+ }
25050
+ s = a;
25051
+ }
25052
+ });
25053
+ }
25054
+ function re(e, n = {}, t = null) {
25055
+ if (typeof n.customOrder == "function") {
25056
+ n.customOrder(e, re);
25057
+ return;
25058
+ }
25059
+ let r = de(e), o = yn(e, D(1, r + 1), "inEdges"), i = yn(e, D(r - 1, -1, -1), "outEdges"), s = Le(e, t);
25060
+ if (wn(e, s), n.disableOptimalOrderHeuristic) return;
25061
+ let a = Number.POSITIVE_INFINITY, l, u = n.constraints || [];
25062
+ for (let d = 0, c = 0; c < 4; ++d, ++c) {
25063
+ qt(d % 2 ? o : i, d % 4 >= 2, u, t), s = P(e);
25064
+ let f = ye(e, s);
25065
+ f < a ? (c = 0, l = Object.assign({}, s), a = f) : f === a && (l = structuredClone(s));
25066
+ }
25067
+ wn(e, l);
25068
+ }
25069
+ function yn(e, n, t) {
25070
+ let r = /* @__PURE__ */ new Map(), o = (i, s) => {
25071
+ r.has(i) || r.set(i, []), r.get(i).push(s);
25072
+ };
25073
+ for (let i of e.nodes()) {
25074
+ let s = e.node(i);
25075
+ 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);
25076
+ }
25077
+ return n.map(function(i) {
25078
+ return ve(e, i, t, r.get(i) || []);
25079
+ });
25080
+ }
25081
+ function qt(e, n, t, r) {
25082
+ let o = true, i = new T();
25083
+ e.forEach(function(s) {
25084
+ t.forEach((d) => i.setEdge(d.left, d.right));
25085
+ let a = s.graph().root, { result: l, usedBias: u } = te(s, a, i, r, o);
25086
+ n && u && (o = !o), l.vs.forEach((d, c) => s.node(d).order = c), ke(s, i, l.vs);
25087
+ });
25088
+ }
25089
+ function wn(e, n) {
25090
+ Object.values(n).forEach((t) => t.forEach((r, o) => e.node(r).order = o));
25091
+ }
25092
+ function $t(e, n) {
25093
+ let t = {};
25094
+ function r(o, i) {
25095
+ let s = 0, a = 0, l = o.length, u = i[i.length - 1];
25096
+ return i.forEach((d, c) => {
25097
+ let f = Jt(e, d), h = f ? e.node(f).order : l;
25098
+ (f || d === u) && (i.slice(a, c + 1).forEach((g) => {
25099
+ let m = e.predecessors(g);
25100
+ m && m.forEach((L) => {
25101
+ let y = e.node(L), b = y.order;
25102
+ (b < s || h < b) && !(y.dummy && e.node(g).dummy) && Gn(t, L, g);
25103
+ });
25104
+ }), a = c + 1, s = h);
25105
+ }), i;
25106
+ }
25107
+ return n.length && n.reduce(r), t;
25108
+ }
25109
+ function Ut(e, n) {
25110
+ let t = {};
25111
+ function r(a) {
25112
+ var l;
25113
+ return ((l = e.node(a)) == null ? void 0 : l.dummy) === "border";
25114
+ }
25115
+ if (!e.nodes().some(r)) return t;
25116
+ function i(a, l, u, d, c) {
25117
+ D(l, u).forEach((f) => {
25118
+ let h = a[f];
25119
+ if (h !== void 0 && e.node(h).dummy) {
25120
+ let g = e.predecessors(h);
25121
+ g && g.forEach((m) => {
25122
+ if (m === void 0) return;
25123
+ let L = e.node(m);
25124
+ L.dummy && (L.order < d || L.order > c) && Gn(t, m, h);
25125
+ });
25126
+ }
25127
+ });
25128
+ }
25129
+ function s(a, l) {
25130
+ let u = -1, d = -1, c = 0;
25131
+ return l.forEach((f, h) => {
25132
+ if (r(f)) {
25133
+ let g = e.predecessors(f);
25134
+ if (g && g.length) {
25135
+ let m = g[0];
25136
+ if (m === void 0) return;
25137
+ d = e.node(m).order, i(l, c, h, u, d), c = h, u = d;
25138
+ }
25139
+ }
25140
+ i(l, c, l.length, d, a.length);
25141
+ }), l;
25142
+ }
25143
+ return n.length && n.reduce(s), t;
25144
+ }
25145
+ function Jt(e, n) {
25146
+ if (e.node(n).dummy) {
25147
+ let t = e.predecessors(n);
25148
+ if (t) return t.find((r) => e.node(r).dummy);
25149
+ }
25150
+ }
25151
+ function Gn(e, n, t) {
25152
+ if (n > t) {
25153
+ let o = n;
25154
+ n = t, t = o;
25155
+ }
25156
+ let r = e[n];
25157
+ r || (e[n] = r = {}), r[t] = true;
25158
+ }
25159
+ function Kt(e, n, t) {
25160
+ if (n > t) {
25161
+ let o = n;
25162
+ n = t, t = o;
25163
+ }
25164
+ let r = e[n];
25165
+ return r !== void 0 && Object.hasOwn(r, t);
25166
+ }
25167
+ function Qt(e, n, t, r, o) {
25168
+ let i = {}, s = {}, a = {};
25169
+ return n.forEach((l) => {
25170
+ l.forEach((u, d) => {
25171
+ i[u] = u, s[u] = u, a[u] = d;
25172
+ });
25173
+ }), n.forEach((l) => {
25174
+ let u = -1, d = -1, c = false, f = l, h = l.findIndex((g) => (o == null ? void 0 : o.includes(g)) || Nn(g, e, o));
25175
+ h > 0 && (f = [l[h], ...l.slice(0, h), ...l.slice(h + 1)], c = true), f.forEach((g) => {
25176
+ var L;
25177
+ let m = r(g);
25178
+ if (m && m.length) {
25179
+ o != null && o.includes(g) && (m = m.filter((p) => Nn(p, e, o)));
25180
+ let y = m.sort((p, E) => {
25181
+ let w = a[p], k = a[E];
25182
+ return (w !== void 0 ? w : 0) - (k !== void 0 ? k : 0);
25183
+ }), b = (y.length - 1) / 2;
25184
+ for (let p = Math.floor(b), E = Math.ceil(b); p <= E; ++p) {
25185
+ let w = y[p];
25186
+ if (w === void 0) continue;
25187
+ let k = a[w];
25188
+ if (k !== void 0 && s[g] === g && u < k && a[w] !== d && !Kt(t, g, w)) {
25189
+ let _ = i[w];
25190
+ _ !== void 0 && (s[w] = g, s[g] = i[g] = _, u = k, c && (u = -1, d = (L = a[w]) != null ? L : -1, c = false));
25191
+ }
25192
+ }
25193
+ }
25194
+ });
25195
+ }), { root: i, align: s };
25196
+ }
25197
+ function Zt(e, n, t, r, o = false) {
25198
+ let i = {}, s = er(e, n, t, o), a = o ? "borderLeft" : "borderRight";
25199
+ function l(h, g) {
25200
+ let m = s.nodes().slice(), L = {}, y = m.pop();
25201
+ for (; y; ) {
25202
+ if (L[y]) h(y);
25203
+ else {
25204
+ L[y] = true, m.push(y);
25205
+ for (let b of g(y)) m.push(b);
25206
+ }
25207
+ y = m.pop();
25208
+ }
25209
+ }
25210
+ function u(h) {
25211
+ let g = s.inEdges(h);
25212
+ g ? i[h] = g.reduce((m, L) => {
25213
+ var p;
25214
+ let y = (p = i[L.v]) != null ? p : 0, b = s.edge(L);
25215
+ return Math.max(m, y + (b !== void 0 ? b : 0));
25216
+ }, 0) : i[h] = 0;
25217
+ }
25218
+ function d(h) {
25219
+ let g = s.outEdges(h), m = Number.POSITIVE_INFINITY;
25220
+ g && (m = g.reduce((y, b) => {
25221
+ let p = i[b.w], E = s.edge(b);
25222
+ return Math.min(y, (p !== void 0 ? p : 0) - (E !== void 0 ? E : 0));
25223
+ }, Number.POSITIVE_INFINITY));
25224
+ let L = e.node(h);
25225
+ m !== Number.POSITIVE_INFINITY && L.borderType !== a && (i[h] = Math.max(i[h] !== void 0 ? i[h] : 0, m));
25226
+ }
25227
+ function c(h) {
25228
+ return s.predecessors(h) || [];
25229
+ }
25230
+ function f(h) {
25231
+ return s.successors(h) || [];
25232
+ }
25233
+ return l(u, c), l(d, f), Object.keys(r).forEach((h) => {
25234
+ var m;
25235
+ let g = t[h];
25236
+ g !== void 0 && (i[h] = (m = i[g]) != null ? m : 0);
25237
+ }), i;
25238
+ }
25239
+ function er(e, n, t, r) {
25240
+ let o = new T(), i = e.graph(), s = or(i.nodesep, i.edgesep, r);
25241
+ return n.forEach((a) => {
25242
+ let l;
25243
+ a.forEach((u) => {
25244
+ let d = t[u];
25245
+ if (d !== void 0) {
25246
+ if (o.setNode(d), l !== void 0) {
25247
+ let c = t[l];
25248
+ if (c !== void 0) {
25249
+ let f = o.edge(c, d);
25250
+ o.setEdge(c, d, Math.max(s(e, u, l), f || 0));
25251
+ }
25252
+ }
25253
+ l = u;
25254
+ }
25255
+ });
25256
+ }), o;
25257
+ }
25258
+ function nr(e, n) {
25259
+ return Object.values(n).reduce((t, r) => {
25260
+ let o = Number.NEGATIVE_INFINITY, i = Number.POSITIVE_INFINITY;
25261
+ Object.entries(r).forEach(([a, l]) => {
25262
+ let u = ir(e, a) / 2;
25263
+ o = Math.max(l + u, o), i = Math.min(l - u, i);
25264
+ });
25265
+ let s = o - i;
25266
+ return s < t[0] && (t = [s, r]), t;
25267
+ }, [Number.POSITIVE_INFINITY, null])[1];
25268
+ }
25269
+ function tr(e, n) {
25270
+ let t = Object.values(n), r = S(Math.min, t), o = S(Math.max, t);
25271
+ ["u", "d"].forEach((i) => {
25272
+ ["l", "r"].forEach((s) => {
25273
+ let a = i + s, l = e[a];
25274
+ if (!l || l === n) return;
25275
+ let u = Object.values(l), d = r - S(Math.min, u);
25276
+ s !== "l" && (d = o - S(Math.max, u)), d && (e[a] = X(l, (c) => c + d));
25277
+ });
25278
+ });
25279
+ }
25280
+ function rr(e, n = void 0) {
25281
+ let t = e.ul;
25282
+ return t ? X(t, (r, o) => {
25283
+ var s, a;
25284
+ if (n) {
25285
+ let l = n.toLowerCase(), u = e[l];
25286
+ if (u && u[o] !== void 0) return u[o];
25287
+ }
25288
+ let i = Object.values(e).map((l) => {
25289
+ let u = l[o];
25290
+ return u !== void 0 ? u : 0;
25291
+ }).sort((l, u) => l - u);
25292
+ return (((s = i[1]) != null ? s : 0) + ((a = i[2]) != null ? a : 0)) / 2;
25293
+ }) : {};
25294
+ }
25295
+ function vn(e, n) {
25296
+ let t = P(e), r = Object.assign($t(e, t), Ut(e, t)), o = {}, i;
25297
+ ["u", "d"].forEach((a) => {
25298
+ i = a === "u" ? t : Object.values(t).reverse(), ["l", "r"].forEach((l) => {
25299
+ l === "r" && (i = i.map((f) => Object.values(f).reverse()));
25300
+ let d = Qt(e, i, r, (f) => (a === "u" ? e.predecessors(f) : e.successors(f)) || [], n), c = Zt(e, i, d.root, d.align, l === "r");
25301
+ l === "r" && (c = X(c, (f) => -f)), o[a + l] = c;
25302
+ });
25303
+ });
25304
+ let s = nr(e, o);
25305
+ return tr(o, s), rr(o, e.graph().align);
25306
+ }
25307
+ function or(e, n, t) {
25308
+ return (r, o, i) => {
25309
+ let s = r.node(o), a = r.node(i), l = 0, u;
25310
+ if (l += s.width / 2, Object.hasOwn(s, "labelpos")) switch (s.labelpos.toLowerCase()) {
25311
+ case "l":
25312
+ u = -s.width / 2;
25313
+ break;
25314
+ case "r":
25315
+ u = s.width / 2;
25316
+ break;
25317
+ }
25318
+ if (u && (l += t ? u : -u), u = void 0, l += (s.dummy ? n : e) / 2, l += (a.dummy ? n : e) / 2, l += a.width / 2, Object.hasOwn(a, "labelpos")) switch (a.labelpos.toLowerCase()) {
25319
+ case "l":
25320
+ u = a.width / 2;
25321
+ break;
25322
+ case "r":
25323
+ u = -a.width / 2;
25324
+ break;
25325
+ }
25326
+ return u && (l += t ? u : -u), l;
25327
+ };
25328
+ }
25329
+ function ir(e, n) {
25330
+ return e.node(n).width;
25331
+ }
25332
+ function Nn(e, n, t) {
25333
+ var s;
25334
+ if (!t) return false;
25335
+ let r = (s = n.node(e)) == null ? void 0 : s.edgeObj;
25336
+ if (!r || n.node(e).edgeLabel.reversed) return false;
25337
+ let o = t.indexOf(r == null ? void 0 : r.v), i = t.indexOf(r == null ? void 0 : r.w);
25338
+ return o !== -1 && i !== -1 && o === (i + 1) % t.length || o === (i - 1) % t.length;
25339
+ }
25340
+ function kn(e, n) {
25341
+ e = Z(e), sr(e), Object.entries(vn(e, n)).forEach(([t, r]) => e.node(t).x = r);
25342
+ }
25343
+ function sr(e) {
25344
+ let n = P(e), t = e.graph(), r = t.ranksep, o = t.rankalign, i = 0;
25345
+ n.forEach((s) => {
25346
+ let a = s.reduce((l, u) => {
25347
+ var c;
25348
+ let d = (c = e.node(u).height) != null ? c : 0;
25349
+ return l > d ? l : d;
25350
+ }, 0);
25351
+ s.forEach((l) => {
25352
+ let u = e.node(l);
25353
+ o === "top" ? u.y = i + u.height / 2 : o === "bottom" ? u.y = i + a - u.height / 2 : u.y = i + a / 2;
25354
+ }), i += a + r;
25355
+ });
25356
+ }
25357
+ var xn = /* @__PURE__ */ new WeakMap();
25358
+ function Oe(e, n = {}) {
25359
+ return In(e, q, n), e;
25360
+ }
25361
+ function _n(e, n, t) {
25362
+ let r = n;
25363
+ for (; r !== void 0; ) {
25364
+ let o = e.parent(r);
25365
+ if (o === t) return r;
25366
+ r = o;
25367
+ }
25368
+ }
25369
+ function In(e, n, t) {
25370
+ var y;
25371
+ let r = e.nodes().filter((b) => e.children(b).length), o = {};
25372
+ r.forEach((b) => {
25373
+ let p = e.node(b);
25374
+ if (p && p.rankdir) {
25375
+ let E = new T({ multigraph: true, compound: true });
25376
+ E.setGraph({ rankdir: p.rankdir });
25377
+ let w = e.children(b);
25378
+ w.forEach((G) => {
25379
+ let N = { ...e.node(G) };
25380
+ E.setNode(G, N);
25381
+ let C = e.parent(G);
25382
+ C && C !== b && w.includes(C) && E.setParent(G, C);
25383
+ });
25384
+ let k = /* @__PURE__ */ new Set();
25385
+ e.edges().forEach((G) => {
25386
+ let N = _n(e, G.v, b), C = _n(e, G.w, b);
25387
+ if (N === G.v && C === G.w) E.setEdge(G, { ...e.edge(G) });
25388
+ else if (N && C && N !== C) {
25389
+ let B = `${N}\0${C}`;
25390
+ k.has(B) || (k.add(B), E.setEdge(N, C, { ...e.edge(G) }));
25391
+ }
25392
+ }), In(E, n, t);
25393
+ let _ = Rn(E);
25394
+ Cn(_, n, t, null), Tn(E, _);
25395
+ let O = 1 / 0, j = 1 / 0, R = -1 / 0, I = -1 / 0;
25396
+ E.nodes().forEach((G) => {
25397
+ if (G === b) return;
25398
+ let N = E.node(G);
25399
+ N && typeof N.x == "number" && typeof N.y == "number" && typeof N.width == "number" && typeof N.height == "number" && (O = Math.min(O, N.x - N.width / 2), R = Math.max(R, N.x + N.width / 2), j = Math.min(j, N.y - N.height / 2), I = Math.max(I, N.y + N.height / 2));
25400
+ }), (!isFinite(O) || !isFinite(j) || !isFinite(R) || !isFinite(I)) && (O = j = 0, R = I = 0);
25401
+ let v = R - O, x = I - j;
25402
+ o[b] = { minX: O, minY: j, maxX: R, maxY: I, width: v, height: x, offsetX: O, offsetY: j }, p._dagreClusterSubgraph = E;
25403
+ }
25404
+ });
25405
+ let i = [], s = (b) => {
25406
+ let p = [], E = (e.children(b) || []).filter((w) => w !== b);
25407
+ for (; E.length > 0; ) {
25408
+ let w = E.shift();
25409
+ p.push(w), (e.children(w) || []).filter((k) => k !== w).forEach((k) => E.push(k));
25410
+ }
25411
+ return p;
25412
+ }, a = /* @__PURE__ */ new Map();
25413
+ r.forEach((b) => {
25414
+ let p = e.node(b);
25415
+ p && p.rankdir && o[b] && a.set(b, (e.children(b) || []).filter((E) => E !== b));
25416
+ });
25417
+ let l = new Set([...a.values()].flat()), u = /* @__PURE__ */ new Map();
25418
+ a.forEach((b, p) => {
25419
+ l.has(p) || u.set(p, s(p));
25420
+ });
25421
+ let d = new Set([...u.values()].flat()), c = (b) => {
25422
+ for (let [p, E] of u) if (E.includes(b)) return p;
25423
+ return b;
25424
+ }, f = [];
25425
+ e.edges().forEach((b) => {
25426
+ (d.has(b.v) || d.has(b.w)) && f.push({ edge: b, label: e.edge(b) });
25427
+ });
25428
+ let h = /* @__PURE__ */ new Map();
25429
+ d.forEach((b) => {
25430
+ let p = e.parent(b);
25431
+ h.set(b, typeof p == "string" ? p : void 0);
25432
+ }), u.forEach((b, p) => {
25433
+ let E = e.node(p), w = [];
25434
+ b.forEach((O) => {
25435
+ let j = e.node(O);
25436
+ j && (w.push({ id: O, node: j, parent: h.get(O) }), e.removeNode(O));
25437
+ });
25438
+ let k = f.filter(({ edge: O }) => b.includes(O.v) || b.includes(O.w)), _ = o[p];
25439
+ E && (i.push({ clusterId: p, subgraph: E._dagreClusterSubgraph, bounds: _, children: b, removedNodes: w, removedEdges: k }), E.width = _.width, E.height = _.height);
25440
+ });
25441
+ let g = /* @__PURE__ */ new Set();
25442
+ f.forEach(({ edge: b, label: p }) => {
25443
+ let E = c(b.v), w = c(b.w);
25444
+ if (E !== w && e.hasNode(E) && e.hasNode(w)) {
25445
+ let k = `${E}\0${w}`;
25446
+ g.has(k) || (g.add(k), e.setEdge(E, w, { ...p, width: 0, height: 0 }));
25447
+ }
25448
+ });
25449
+ let m = Rn(e), L = Cn(m, n, t, (y = xn.get(e)) != null ? y : null);
25450
+ xn.set(e, L), Tn(e, m), g.forEach((b) => {
25451
+ let p = b.indexOf("\0"), E = b.slice(0, p), w = b.slice(p + 1);
25452
+ e.hasEdge(E, w) && e.removeEdge(E, w);
25453
+ }), i.forEach(({ clusterId: b, subgraph: p, bounds: E, removedNodes: w, removedEdges: k }) => {
25454
+ var v, x;
25455
+ let _ = e.node(b), O = (v = _ == null ? void 0 : _.x) != null ? v : 0, j = (x = _ == null ? void 0 : _.y) != null ? x : 0, R = (E.minX + E.maxX) / 2, I = (E.minY + E.maxY) / 2;
25456
+ w.forEach(({ id: G, node: N, parent: C }) => {
25457
+ e.setNode(G, N), C !== void 0 && e.setParent(G, C);
25458
+ }), k.forEach(({ edge: G, label: N }) => {
25459
+ e.setEdge(G, N);
25460
+ }), p.nodes().forEach((G) => {
25461
+ if (G === b) return;
25462
+ let N = p.node(G), C = e.node(G);
25463
+ C && N && typeof N.x == "number" && typeof N.y == "number" && (C.x = O + (N.x - R), C.y = j + (N.y - I));
25464
+ }), On(e, p, O - R, j - I), delete _._dagreClusterSubgraph;
25465
+ }), r.forEach((b) => {
25466
+ var w, k;
25467
+ let p = e.node(b), E = o[b];
25468
+ if (p && p.rankdir && p._dagreClusterSubgraph && E) {
25469
+ let _ = p._dagreClusterSubgraph, O = (w = p.x) != null ? w : 0, j = (k = p.y) != null ? k : 0, R = (E.minX + E.maxX) / 2, I = (E.minY + E.maxY) / 2;
25470
+ _.nodes().forEach((v) => {
25471
+ if (v === b) return;
25472
+ let x = _.node(v), G = e.node(v);
25473
+ if (G && x && typeof x.x == "number" && typeof x.y == "number") {
25474
+ let N = x.x - R, C = x.y - I;
25475
+ G.x = O + N, G.y = j + C;
25476
+ }
25477
+ }), On(e, _, O - R, j - I), delete p._dagreClusterSubgraph;
25478
+ }
25479
+ });
25480
+ }
25481
+ function On(e, n, t, r) {
25482
+ n.edges().forEach((o) => {
25483
+ if (!e.hasEdge(o)) return;
25484
+ let i = n.edge(o), s = e.edge(o);
25485
+ s.points = i.points.map((a) => ({ x: a.x + t, y: a.y + r })), Object.hasOwn(i, "x") && (s.x = i.x + t, s.y = i.y + r);
25486
+ });
25487
+ }
25488
+ function Cn(e, n, t, r = null) {
25489
+ var l, u;
25490
+ let o = (t == null ? void 0 : t.useDynamic) !== false, i = o && (l = r == null ? void 0 : r.graph) != null ? l : null, s = o && (u = r == null ? void 0 : r.rawNodes) != null ? u : null;
25491
+ n(" makeSpaceForEdgeLabels", () => br(e)), n(" removeSelfEdges", () => Gr(e)), n(" acyclic", () => Ue(e, i)), n(" nestingGraph.run", () => un(e)), n(" rank", () => dn(Z(e))), n(" injectEdgeLabelProxies", () => gr(e)), n(" removeEmptyRanks", () => We(e)), n(" nestingGraph.cleanup", () => fn(e)), n(" normalizeRanks", () => Be(e)), n(" assignRankMinMax", () => pr(e)), n(" removeEdgeLabelProxies", () => mr(e)), n(" normalize.run", () => Ke(e)), n(" parentDummyChains", () => ln(e)), n(" addBorderSegments", () => bn(e)), n(" order", () => re(e, t, s)), n(" insertSelfEdges", () => vr(e)), n(" adjustCoordinateSystem", () => pn(e)), n(" position", () => kn(e, t.corePath)), n(" positionSelfEdges", () => kr(e));
25492
+ let a = JSON.parse(JSON.stringify(e._nodes));
25493
+ return n(" removeBorderNodes", () => Nr(e)), n(" normalize.undo", () => Qe(e)), n(" fixupEdgeLabelCoords", () => yr(e)), n(" undoCoordinateSystem", () => mn(e)), n(" translateGraph", () => Er(e)), n(" assignNodeIntersects", () => Lr(e)), n(" reversePoints", () => wr(e)), n(" acyclic.undo", () => Je(e)), { graph: e, rawNodes: a };
25494
+ }
25495
+ function Tn(e, n) {
25496
+ e.nodes().forEach((t) => {
25497
+ let r = e.node(t), o = n.node(t);
25498
+ r && (r.x = o.x, r.y = o.y, r.order = o.order, r.rank = o.rank, n.children(t).length && (r.width = o.width, r.height = o.height));
25499
+ }), e.edges().forEach((t) => {
25500
+ let r = e.edge(t), o = n.edge(t);
25501
+ r.points = o.points, Object.hasOwn(o, "x") && (r.x = o.x, r.y = o.y);
25502
+ }), e.graph().width = n.graph().width, e.graph().height = n.graph().height;
25503
+ }
25504
+ var ar = ["nodesep", "edgesep", "ranksep", "marginx", "marginy"];
25505
+ var dr = { ranksep: 50, edgesep: 20, nodesep: 50, rankdir: "TB", rankalign: "center" };
25506
+ var lr = ["acyclicer", "ranker", "rankdir", "align", "rankalign"];
25507
+ var ur = ["width", "height", "rank"];
25508
+ var jn = { width: 0, height: 0 };
25509
+ var cr = ["minlen", "weight", "width", "height", "labeloffset"];
25510
+ var fr = { minlen: 1, weight: 1, width: 0, height: 0, labeloffset: 10, labelpos: "r" };
25511
+ var hr = ["labelpos"];
25512
+ function Rn(e) {
25513
+ let n = new T({ multigraph: true, compound: true }), t = _e(e.graph());
25514
+ return n.setGraph(Object.assign({}, dr, xe(t, ar), W(t, lr))), e.nodes().forEach((r) => {
25515
+ let o = _e(e.node(r)), i = xe(o, ur);
25516
+ Object.keys(jn).forEach((a) => {
25517
+ i[a] === void 0 && (i[a] = jn[a]);
25518
+ }), n.setNode(r, i);
25519
+ let s = e.parent(r);
25520
+ s !== void 0 && n.setParent(r, s);
25521
+ }), e.edges().forEach((r) => {
25522
+ let o = _e(e.edge(r));
25523
+ n.setEdge(r, Object.assign({}, fr, xe(o, cr), W(o, hr)));
25524
+ }), n;
25525
+ }
25526
+ function br(e) {
25527
+ let n = e.graph();
25528
+ n.ranksep /= 2, e.edges().forEach((t) => {
25529
+ var o;
25530
+ let r = e.edge(t);
25531
+ r.minlen *= 2, ((o = r.labelpos) != null ? o : "r").toLowerCase() !== "c" && (n.rankdir === "TB" || n.rankdir === "BT" ? r.width += r.labeloffset : r.height += r.labeloffset);
25532
+ });
25533
+ }
25534
+ function gr(e) {
25535
+ e.edges().forEach((n) => {
25536
+ let t = e.edge(n);
25537
+ if (t.width && t.height) {
25538
+ let r = e.node(n.v), i = { rank: (e.node(n.w).rank - r.rank) / 2 + r.rank, e: n };
25539
+ M(e, "edge-proxy", i, "_ep");
25540
+ }
25541
+ });
25542
+ }
25543
+ function pr(e) {
25544
+ let n = 0;
25545
+ e.nodes().forEach((t) => {
25546
+ let r = e.node(t);
25547
+ r.borderTop && (r.minRank = e.node(r.borderTop).rank, r.maxRank = e.node(r.borderBottom).rank, n = Math.max(n, r.maxRank));
25548
+ }), e.graph().maxRank = n;
25549
+ }
25550
+ function mr(e) {
25551
+ e.nodes().forEach((n) => {
25552
+ let t = e.node(n);
25553
+ if (t.dummy === "edge-proxy") {
25554
+ let r = t;
25555
+ e.edge(r.e).labelRank = t.rank, e.removeNode(n);
25556
+ }
25557
+ });
25558
+ }
25559
+ function Er(e) {
25560
+ let n = Number.POSITIVE_INFINITY, t = 0, r = Number.POSITIVE_INFINITY, o = 0, i = e.graph(), s = i.marginx || 0, a = i.marginy || 0;
25561
+ function l(u) {
25562
+ let d = u.x, c = u.y, f = u.width, h = u.height;
25563
+ n = Math.min(n, d - f / 2), t = Math.max(t, d + f / 2), r = Math.min(r, c - h / 2), o = Math.max(o, c + h / 2);
25564
+ }
25565
+ e.nodes().forEach((u) => l(e.node(u))), e.edges().forEach((u) => {
25566
+ let d = e.edge(u);
25567
+ Object.hasOwn(d, "x") && l(d);
25568
+ }), n -= s, r -= a, e.nodes().forEach((u) => {
25569
+ let d = e.node(u);
25570
+ d.x -= n, d.y -= r;
25571
+ }), e.edges().forEach((u) => {
25572
+ let d = e.edge(u);
25573
+ d.points.forEach((c) => {
25574
+ c.x -= n, c.y -= r;
25575
+ }), Object.hasOwn(d, "x") && (d.x -= n), Object.hasOwn(d, "y") && (d.y -= r);
25576
+ }), i.width = t - n + s, i.height = o - r + a;
25577
+ }
25578
+ function Lr(e) {
25579
+ e.edges().forEach((n) => {
25580
+ if (n.v === n.w) return;
25581
+ let t = e.edge(n), r = e.node(n.v), o = e.node(n.w), i, s;
25582
+ t.points ? (i = t.points[0], s = t.points[t.points.length - 1]) : (t.points = [], i = o, s = r), t.points.unshift(se(r, i)), t.points.push(se(o, s));
25583
+ });
25584
+ }
25585
+ function yr(e) {
25586
+ e.edges().forEach((n) => {
25587
+ let t = e.edge(n);
25588
+ if (Object.hasOwn(t, "x")) switch ((t.labelpos === "l" || t.labelpos === "r") && (t.width -= t.labeloffset), t.labelpos) {
25589
+ case "l":
25590
+ t.x -= t.width / 2 + t.labeloffset;
25591
+ break;
25592
+ case "r":
25593
+ t.x += t.width / 2 + t.labeloffset;
25594
+ break;
25595
+ }
25596
+ });
25597
+ }
25598
+ function wr(e) {
25599
+ e.edges().forEach((n) => {
25600
+ let t = e.edge(n);
25601
+ t.reversed && t.points.reverse();
25602
+ });
25603
+ }
25604
+ function Nr(e) {
25605
+ e.nodes().forEach((n) => {
25606
+ if (e.children(n).length) {
25607
+ let t = e.node(n), r = 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]);
25608
+ t.width = Math.abs(s.x - i.x), t.height = Math.abs(o.y - r.y), t.x = i.x + t.width / 2, t.y = r.y + t.height / 2;
25609
+ }
25610
+ }), e.nodes().forEach((n) => {
25611
+ e.node(n).dummy === "border" && e.removeNode(n);
25612
+ });
25613
+ }
25614
+ function Gr(e) {
25615
+ e.edges().forEach((n) => {
25616
+ if (n.v === n.w) {
25617
+ let t = e.node(n.v);
25618
+ t.selfEdges || (t.selfEdges = []), t.selfEdges.push({ e: n, label: e.edge(n) }), e.removeEdge(n);
25619
+ }
25620
+ });
25621
+ }
25622
+ function vr(e) {
25623
+ P(e).forEach((t) => {
25624
+ let r = 0;
25625
+ t.forEach((o, i) => {
25626
+ let s = e.node(o);
25627
+ typeof s.rank != "number" && (s.rank = 0), s.order = i + r, (s.selfEdges || []).forEach((a) => {
25628
+ M(e, "selfedge", { width: a.label.width, height: a.label.height, rank: s.rank, order: i + ++r, e: a.e, edgeLabel: a.label }, "_se"), (!Array.isArray(a.label.points) || a.label.points.length !== 7) && (a.label.points = [{ x: 0, y: -10 }, { x: 0, y: -10 }, { x: 0, y: 0 }, { x: 0, y: 10 }, { x: 0, y: 10 }, { x: 0, y: 0 }, { x: 0, y: 0 }]);
25629
+ }), delete s.selfEdges;
25630
+ });
25631
+ });
25632
+ }
25633
+ function kr(e) {
25634
+ e.nodes().forEach((n) => {
25635
+ let t = e.node(n), r = (o) => typeof o == "number" && isFinite(o);
25636
+ if (t.dummy === "selfedge") {
25637
+ let o = t, i = e.node(o.e.v), s = r(i == null ? void 0 : i.x) ? i.x : 0, a = r(i == null ? void 0 : i.y) ? i.y : 0, l = r(i == null ? void 0 : i.width) ? i.width : 0, u = r(i == null ? void 0 : i.height) ? i.height : 0, d = r(t.x) ? t.x : s, c = r(t.y) ? t.y : a, f = l / 2, h = u / 2;
25638
+ o.edgeLabel.points = [{ x: d + f, y: c - h }, { x: d + f, y: c - h }, { x: d, y: c }, { x: d - f, y: c + h }, { x: d - f, y: c + h }, { x: d, y: c }, { x: d, y: c }], o.edgeLabel.x = d, o.edgeLabel.y = c, e.setEdge(o.e, o.edgeLabel), e.removeNode(n);
25639
+ } else t && Array.isArray(t.selfEdges) && t.selfEdges.forEach((o) => {
25640
+ if (!Array.isArray(o.label.points) || o.label.points.length !== 7) {
25641
+ let i = r(t.x) ? t.x : 0, s = r(t.y) ? t.y : 0, a = r(t.width) ? t.width : 0, l = r(t.height) ? t.height : 0, u = a / 2, d = l / 2;
25642
+ o.label.points = [{ x: i + u, y: s - d }, { x: i + u, y: s - d }, { x: i, y: s }, { x: i - u, y: s + d }, { x: i - u, y: s + d }, { x: i, y: s }, { x: i, y: s }];
25643
+ }
25644
+ });
25645
+ });
25646
+ }
25647
+ function xe(e, n) {
25648
+ return X(W(e, n), Number);
25649
+ }
25650
+ function _e(e) {
25651
+ let n = {};
25652
+ return e && Object.entries(e).forEach(([t, r]) => {
25653
+ typeof t == "string" && (t = t.toLowerCase()), n[t] = r;
25654
+ }), n;
25655
+ }
25656
+ function Ce(e) {
25657
+ let n = P(e), t = new T({ compound: true, multigraph: true }).setGraph({});
25658
+ return e.nodes().forEach((r) => {
25659
+ t.setNode(r, { label: r }), t.setParent(r, "layer" + e.node(r).rank);
25660
+ }), e.edges().forEach((r) => t.setEdge(r.v, r.w, {}, r.name)), n.forEach((r, o) => {
25661
+ let i = "layer" + o;
25662
+ t.setNode(i, { rank: "same" }), r.reduce((s, a) => (t.setEdge(s, a, { style: "invis" }), a));
25663
+ }), t;
25664
+ }
25665
+ var xr = { graphlib: ie, version: ue, layout: Oe, debug: Ce, util: { time: le, notime: q } };
25666
+ var Uo = xr;
25667
+
25668
+ // src/runtime/components/_architecture-lanes.js
25669
+ var LANES = {
25670
+ margin: 16,
25671
+ // around the drawing
25672
+ lanePad: 14,
25673
+ // inside a lane frame
25674
+ head: 30,
25675
+ // lane heading band
25676
+ headSize: 12,
25677
+ // lane heading text
25678
+ colGap: 18,
25679
+ // between boxes side by side in a lane
25680
+ rowGap: 34,
25681
+ // between rows; grows when routes need more tracks
25682
+ gutter: 52,
25683
+ // between lanes; grows with labels and routes
25684
+ bottom: 18,
25685
+ // routing channel under the last row, inside the lanes
25686
+ track: 9,
25687
+ // spacing of parallel lines in a channel
25688
+ clear: 9,
25689
+ // routes keep this far from boxes
25690
+ stub: 14,
25691
+ // straight run out of a port before any bend
25692
+ laneMinW: 170,
25693
+ laneMaxHeadW: 300
25694
+ };
25695
+ function runLanes(model) {
25696
+ const plan = planColumns(model);
25697
+ if (!plan) return null;
25698
+ if (!plan.layout) plan.layout = routeWithGrowth(model, plan.sizes, () => placeColumns(plan.lanes, plan.byId, plan.rowCount, plan.sizes, model));
25699
+ return plan.layout;
25700
+ }
25701
+ function lanesPlanWidth(model) {
25702
+ return planColumns(model)?.width ?? 0;
25703
+ }
25704
+ var plans = /* @__PURE__ */ new WeakMap();
25705
+ function planColumns(model) {
25706
+ if (plans.has(model)) return plans.get(model);
25707
+ const lanes = prepareLanes(model);
25708
+ if (!lanes) {
25709
+ plans.set(model, null);
25710
+ return null;
25711
+ }
25712
+ const byId = new Map(model.nodes.map((n) => [n.id, n]));
25713
+ const rowCount = assignGlobalRows(lanes, model.edges);
25714
+ const sizes = /* @__PURE__ */ new Map();
25715
+ initialGutters(lanes, model.edges).forEach((g, i) => sizes.set(`g${i}`, g));
25716
+ const rowOf = /* @__PURE__ */ new Map();
25717
+ for (const lane of lanes) for (const [g, ids] of lane.phys) for (const id of ids) rowOf.set(id, { g, lane });
25718
+ for (const e of model.edges) {
25719
+ const a = rowOf.get(e.from);
25720
+ const b = rowOf.get(e.to);
25721
+ const lb = sizeEdgeLabel(e.label);
25722
+ if (!a || !b || !lb || a.lane !== b.lane || Math.abs(a.g - b.g) !== 1) continue;
25723
+ const key = `r${Math.min(a.g, b.g)}`;
25724
+ sizes.set(key, Math.max(sizes.get(key) ?? LANES.rowGap, lb.height + 30));
25725
+ }
25726
+ const plan = { lanes, byId, rowCount, sizes, width: placeColumns(lanes, byId, rowCount, sizes, model).width, layout: null };
25727
+ plans.set(model, plan);
25728
+ return plan;
25729
+ }
25730
+ function runStackedLanes(model, targetWidth) {
25731
+ const lanes = prepareLanes(model);
25732
+ if (!lanes) return null;
25733
+ assignGlobalRows(lanes, model.edges);
25734
+ for (const lane of lanes) lane.rows.sort((a, b) => a.g - b.g);
25735
+ const byId = new Map(model.nodes.map((n) => [n.id, n]));
25736
+ const sizes = /* @__PURE__ */ new Map([
25737
+ ["left", 22],
25738
+ ["right", 22]
25739
+ ]);
25740
+ const layout = routeWithGrowth(model, sizes, () => placeBands(lanes, byId, sizes, model, targetWidth), STACKED_MAX_CHANNEL);
25741
+ if (layout) layout.rankdir = "stacked";
25742
+ return layout;
25743
+ }
25744
+ var STACKED_MAX_CHANNEL = 22 + 6 * 9;
25745
+ function prepareLanes(model) {
25746
+ const lanes = assignLanes(model);
25747
+ if (!lanes) return null;
25748
+ const byId = new Map(model.nodes.map((n) => [n.id, n]));
25749
+ for (const lane of lanes) lane.rows = applyPins(laneRows(lane, model.edges), byId);
25750
+ return lanes;
25751
+ }
25752
+ function routeWithGrowth(model, sizes, place, maxSize = Infinity) {
25753
+ let result = null;
25754
+ for (let pass = 0; pass < 2; pass++) {
25755
+ const geo = place();
25756
+ const routed = routeAll(geo, model);
25757
+ result = { geo, routed };
25758
+ const grow = channelShortfall(geo, routed);
25759
+ let changed = false;
25760
+ for (const [key, need] of grow) {
25761
+ const next = Math.min(maxSize, Math.max(sizes.get(key) || 0, need));
25762
+ if (next > (sizes.get(key) || 0)) {
25763
+ sizes.set(key, next);
25764
+ changed = true;
25765
+ }
25766
+ }
25767
+ if (!changed) break;
25768
+ }
25769
+ return finish(result, model);
25770
+ }
25771
+ function assignLanes(model) {
25772
+ const top = model.groups.filter((g) => !g.parent);
25773
+ if (!top.length) return null;
25774
+ const laneOf = /* @__PURE__ */ new Map();
25775
+ const lanes = top.map((group) => ({ group, nodes: [] }));
25776
+ for (const lane of lanes) {
25777
+ for (const m of lane.group.members) {
25778
+ if (laneOf.has(m)) continue;
25779
+ laneOf.set(m, lane);
25780
+ lane.nodes.push(m);
25781
+ }
25782
+ }
25783
+ const loose = model.nodes.map((n) => n.id).filter((id) => !laneOf.has(id));
25784
+ if (loose.length) {
25785
+ const isLoose = new Set(loose);
25786
+ let out = 0;
25787
+ let inn = 0;
25788
+ for (const e of model.edges) {
25789
+ if (isLoose.has(e.from) && !isLoose.has(e.to)) out++;
25790
+ if (!isLoose.has(e.from) && isLoose.has(e.to)) inn++;
25791
+ }
25792
+ const lane = { group: null, nodes: loose };
25793
+ for (const id of loose) laneOf.set(id, lane);
25794
+ if (out >= inn) lanes.unshift(lane);
25795
+ else lanes.push(lane);
25796
+ }
25797
+ lanes.forEach((lane, i) => {
25798
+ lane.index = i;
25799
+ });
25800
+ for (const lane of lanes) lane.laneOf = laneOf;
25801
+ return lanes;
25802
+ }
25803
+ function laneRows(lane, edges) {
25804
+ const ids = lane.nodes;
25805
+ const pos = new Map(ids.map((id, i) => [id, i]));
25806
+ const inLane = (id) => pos.has(id);
25807
+ const intra = edges.filter((e) => e.from !== e.to && inLane(e.from) && inLane(e.to));
25808
+ const parent = new Map(ids.map((id) => [id, id]));
25809
+ const find = (x) => {
25810
+ while (parent.get(x) !== x) {
25811
+ parent.set(x, parent.get(parent.get(x)));
25812
+ x = parent.get(x);
25813
+ }
25814
+ return x;
25815
+ };
25816
+ for (const e of intra) parent.set(find(e.from), find(e.to));
25817
+ const adj = new Map(ids.map((id) => [id, []]));
25818
+ for (const e of intra) adj.get(e.from).push(e.to);
25819
+ const state = /* @__PURE__ */ new Map();
25820
+ const kept = [];
25821
+ for (const root of ids) {
25822
+ if (state.get(root)) continue;
25823
+ const stack = [[root, 0]];
25824
+ state.set(root, 1);
25825
+ while (stack.length) {
25826
+ const top = stack[stack.length - 1];
25827
+ const [u, k] = top;
25828
+ const next = adj.get(u)[k];
25829
+ if (next === void 0) {
25830
+ state.set(u, 2);
25831
+ stack.pop();
25832
+ continue;
25833
+ }
25834
+ top[1]++;
25835
+ if (state.get(next) === 1) continue;
25836
+ kept.push([u, next]);
25837
+ if (!state.get(next)) {
25838
+ state.set(next, 1);
25839
+ stack.push([next, 0]);
25840
+ }
25841
+ }
25842
+ }
25843
+ const rank = new Map(ids.map((id) => [id, 0]));
25844
+ for (let changed = true, guard = 0; changed && guard <= ids.length; guard++) {
25845
+ changed = false;
25846
+ for (const [u, v] of kept) {
25847
+ if (rank.get(v) < rank.get(u) + 1) {
25848
+ rank.set(v, rank.get(u) + 1);
25849
+ changed = true;
25850
+ }
25851
+ }
25852
+ }
25853
+ const blocks = /* @__PURE__ */ new Map();
25854
+ for (const id of ids) {
25855
+ const root = find(id);
25856
+ if (!blocks.has(root)) blocks.set(root, []);
25857
+ blocks.get(root).push(id);
25858
+ }
25859
+ const rows = [];
25860
+ for (const members2 of [...blocks.values()].sort((a, b) => pos.get(a[0]) - pos.get(b[0]))) {
25861
+ const byRank = /* @__PURE__ */ new Map();
25862
+ for (const id of members2) {
25863
+ const r = rank.get(id);
25864
+ if (!byRank.has(r)) byRank.set(r, []);
25865
+ byRank.get(r).push(id);
25866
+ }
25867
+ for (const r of [...byRank.keys()].sort((a, b) => a - b)) {
25868
+ const ids2 = byRank.get(r);
25869
+ if (ids2.length <= 2) rows.push({ ids: ids2, pin: null });
25870
+ else for (const id of ids2) rows.push({ ids: [id], pin: null });
25871
+ }
25872
+ }
25873
+ return rows;
25874
+ }
25875
+ function applyPins(rows, byId) {
25876
+ const out = [];
25877
+ const pinned = /* @__PURE__ */ new Map();
25878
+ for (const row of rows) {
25879
+ const free = [];
25880
+ for (const id of row.ids) {
25881
+ const pin = byId.get(id)?.row;
25882
+ if (!pin) {
25883
+ free.push(id);
25884
+ continue;
25885
+ }
25886
+ if (!pinned.has(pin)) {
25887
+ const pr2 = { ids: [], pin };
25888
+ pinned.set(pin, pr2);
25889
+ out.push(pr2);
25890
+ }
25891
+ pinned.get(pin).ids.push(id);
25892
+ }
25893
+ if (free.length) out.push({ ids: free, pin: null });
25894
+ }
25895
+ return out;
25896
+ }
25897
+ function isotonic(values, weights) {
25898
+ const blocks = [];
25899
+ for (let k = 0; k < values.length; k++) {
25900
+ blocks.push({ s: values[k] * weights[k], w: weights[k], n: 1 });
25901
+ while (blocks.length > 1) {
25902
+ const b = blocks[blocks.length - 1];
25903
+ const a = blocks[blocks.length - 2];
25904
+ if (a.s / a.w <= b.s / b.w) break;
25905
+ a.s += b.s;
25906
+ a.w += b.w;
25907
+ a.n += b.n;
25908
+ blocks.pop();
25909
+ }
25910
+ }
25911
+ const out = [];
25912
+ for (const b of blocks) for (let k = 0; k < b.n; k++) out.push(b.s / b.w);
25913
+ return out;
25914
+ }
25915
+ function assignGlobalRows(lanes, edges) {
25916
+ const rowOf = /* @__PURE__ */ new Map();
25917
+ for (const lane of lanes) for (const r of lane.rows) for (const id of r.ids) rowOf.set(id, r);
25918
+ const laneOf = lanes[0].laneOf;
25919
+ const neighbors = /* @__PURE__ */ new Map();
25920
+ const link = (a, b) => {
25921
+ if (!neighbors.has(a)) neighbors.set(a, []);
25922
+ neighbors.get(a).push(b);
25923
+ };
25924
+ for (const e of edges) {
25925
+ const a = rowOf.get(e.from);
25926
+ const b = rowOf.get(e.to);
25927
+ if (!a || !b || laneOf.get(e.from) === laneOf.get(e.to)) continue;
25928
+ link(a, b);
25929
+ link(b, a);
25930
+ }
25931
+ for (const lane of lanes) lane.rows.forEach((r, i) => r.g = r.pin ?? i + 1);
25932
+ for (let sweep = 0; sweep < 8; sweep++) {
25933
+ for (const lane of sweep % 2 ? [...lanes].reverse() : lanes) {
25934
+ const free = lane.rows.filter((r) => !r.pin);
25935
+ const taken = new Set(lane.rows.filter((r) => r.pin).map((r) => r.pin));
25936
+ const want = [];
25937
+ const weight = [];
25938
+ free.forEach((r, i) => {
25939
+ const ns = neighbors.get(r);
25940
+ want.push(ns ? ns.reduce((sum, x) => sum + x.g, 0) / ns.length - (i + 1) : 0);
25941
+ weight.push(ns ? ns.length : 0.05);
25942
+ });
25943
+ const fit = isotonic(want, weight);
25944
+ let prev = 0;
25945
+ free.forEach((r, i) => {
25946
+ let g = Math.max(prev + 1, Math.max(0, Math.round(fit[i])) + i + 1);
25947
+ while (taken.has(g)) g++;
25948
+ r.g = g;
25949
+ prev = g;
25950
+ });
25951
+ }
25952
+ }
25953
+ const used = [...new Set(lanes.flatMap((l) => l.rows.map((r) => r.g)))].sort((a, b) => a - b);
25954
+ const index = new Map(used.map((g, i) => [g, i]));
25955
+ for (const lane of lanes) {
25956
+ lane.phys = /* @__PURE__ */ new Map();
25957
+ for (const r of lane.rows) {
25958
+ const g = index.get(r.g);
25959
+ if (!lane.phys.has(g)) lane.phys.set(g, []);
25960
+ lane.phys.get(g).push(...r.ids);
25961
+ }
25962
+ }
25963
+ return used.length;
25964
+ }
25965
+ var GUTTER_LABEL_W = 96;
25966
+ function initialGutters(lanes, edges) {
25967
+ const laneOf = lanes[0].laneOf;
25968
+ const gutters = new Array(Math.max(0, lanes.length - 1)).fill(LANES.gutter);
25969
+ const crossing = new Array(gutters.length).fill(0);
25970
+ for (const e of edges) {
25971
+ const a = laneOf.get(e.from)?.index;
25972
+ const b = laneOf.get(e.to)?.index;
25973
+ if (a === void 0 || b === void 0 || a === b) continue;
25974
+ const lo = Math.min(a, b);
25975
+ const hi = Math.max(a, b);
25976
+ for (let i = lo; i < hi; i++) crossing[i]++;
25977
+ const lb = sizeEdgeLabel(e.label);
25978
+ if (lb) {
25979
+ const g = b > a ? a : a - 1;
25980
+ gutters[g] = Math.max(gutters[g], (narrowLabel(e.label, GUTTER_LABEL_W)?.width ?? lb.width) + 22);
25981
+ }
25982
+ }
25983
+ return gutters.map((g, i) => Math.max(g, 24 + crossing[i] * LANES.track));
25984
+ }
25985
+ function sizeLaneHeads(lanes, inner) {
25986
+ for (const lane of lanes) {
25987
+ const label = lane.group?.label || "";
25988
+ lane.headLine = label ? wrapText(label, LANES.headSize, inner(lane), 1, true)[0] : "";
25989
+ }
25990
+ }
25991
+ function placeColumns(lanes, byId, rowCount, sizes, model) {
25992
+ const L = LANES;
25993
+ const natural = new Map(model.nodes.map((n) => [n.id, sizeNode(n)]));
25994
+ const nested = model.groups.some((g) => g.parent);
25995
+ const headH = (lanes.some((l) => l.group?.label) ? L.head : 0) + (nested ? 16 : 0);
25996
+ const gutter = (i) => sizes.get(`g${i}`) ?? L.gutter;
25997
+ const rowGap = (g) => sizes.get(`r${g}`) ?? L.rowGap;
25998
+ for (const lane of lanes) {
25999
+ let inner = L.laneMinW;
26000
+ for (const ids of lane.phys.values()) {
26001
+ const w = ids.reduce((sum, id) => sum + natural.get(id).width, 0) + L.colGap * (ids.length - 1);
26002
+ inner = Math.max(inner, w);
26003
+ }
26004
+ const label = lane.group?.label || "";
26005
+ if (label) inner = Math.max(inner, Math.min(textWidth(label, L.headSize, true) + 4, L.laneMaxHeadW));
26006
+ lane.inner = inner;
26007
+ }
26008
+ sizeLaneHeads(lanes, (lane) => lane.inner);
26009
+ const sized = /* @__PURE__ */ new Map();
26010
+ for (const lane of lanes) {
26011
+ for (const ids of lane.phys.values()) {
26012
+ const sum = ids.reduce((acc, id) => acc + natural.get(id).width, 0);
26013
+ const extra = (lane.inner - sum - L.colGap * (ids.length - 1)) / ids.length;
26014
+ for (const id of ids) sized.set(id, sizeNode(byId.get(id), Math.floor(natural.get(id).width + extra)));
26015
+ }
26016
+ }
26017
+ const rowH = new Array(rowCount).fill(0);
26018
+ for (const lane of lanes) for (const [g, ids] of lane.phys) for (const id of ids) rowH[g] = Math.max(rowH[g], sized.get(id).height);
26019
+ const rowTop = [];
26020
+ let y = L.margin + headH + L.lanePad;
26021
+ for (let g = 0; g < rowCount; g++) {
26022
+ rowTop[g] = y;
26023
+ y += rowH[g] + (g < rowCount - 1 ? rowGap(g) : 0);
26024
+ }
26025
+ const contentBottom = y;
26026
+ const frameTop = L.margin;
26027
+ const frameBottom = contentBottom + L.bottom + L.lanePad;
26028
+ let x = L.margin;
26029
+ const boxes = /* @__PURE__ */ new Map();
26030
+ for (const lane of lanes) {
26031
+ const w = lane.inner + L.lanePad * 2;
26032
+ lane.frame = { x, y: frameTop, w, h: frameBottom - frameTop };
26033
+ for (const [g, ids] of lane.phys) {
26034
+ let bx = x + L.lanePad;
26035
+ for (const id of ids) {
26036
+ const b = sized.get(id);
26037
+ boxes.set(id, { ...b, x: bx, y: Math.round(rowTop[g] + (rowH[g] - b.height) / 2), rowIndex: g, laneIndex: lane.index });
26038
+ bx += b.width + L.colGap;
26039
+ }
26040
+ }
26041
+ x += w + (lane.index < lanes.length - 1 ? gutter(lane.index) : 0);
26042
+ }
26043
+ const width = x + L.margin;
26044
+ const height = frameBottom + L.margin;
26045
+ const channels = [];
26046
+ lanes.forEach((lane, i) => {
26047
+ if (i < lanes.length - 1) channels.push({ key: `g${i}`, axis: "x", lo: lane.frame.x + lane.frame.w, hi: lanes[i + 1].frame.x });
26048
+ });
26049
+ for (let g = 0; g < rowCount - 1; g++) channels.push({ key: `r${g}`, axis: "y", lo: rowTop[g] + rowH[g], hi: rowTop[g + 1] });
26050
+ channels.push({ key: "bottom", axis: "y", lo: contentBottom, hi: frameBottom - 4, fixed: true });
26051
+ channels.push({ key: "outL", axis: "x", lo: 0, hi: L.margin, fixed: true }, { key: "outR", axis: "x", lo: width - L.margin, hi: width, fixed: true });
26052
+ channels.push({ key: "outB", axis: "y", lo: frameBottom, hi: height, fixed: true });
26053
+ const frameLines = { xs: lanes.flatMap((l) => [l.frame.x, l.frame.x + l.frame.w]), ys: [frameTop, frameBottom] };
26054
+ const sides = (e) => {
26055
+ const a = boxes.get(e.from);
26056
+ const b = boxes.get(e.to);
26057
+ if (a.laneIndex !== b.laneIndex) return b.laneIndex > a.laneIndex ? ["right", "left"] : ["left", "right"];
26058
+ if (b.rowIndex > a.rowIndex) return ["bottom", "top"];
26059
+ if (b.rowIndex < a.rowIndex) return ["top", "bottom"];
26060
+ return b.x > a.x ? ["right", "left"] : ["left", "right"];
26061
+ };
26062
+ return { lanes, boxes, channels, frameLines, sides, width, height };
26063
+ }
26064
+ function placeBands(lanes, byId, sizes, model, targetWidth) {
26065
+ const L = LANES;
26066
+ const left = sizes.get("left");
26067
+ const right = sizes.get("right");
26068
+ const target = (targetWidth || 360) / 0.85;
26069
+ const room = Math.max(180, Math.min(720, target - left - right - L.lanePad * 2 - 4));
26070
+ sizeLaneHeads(lanes, () => room);
26071
+ const boxes = /* @__PURE__ */ new Map();
26072
+ const channels = [];
26073
+ const x0 = left + L.lanePad;
26074
+ let y = L.margin;
26075
+ let seq2 = 0;
26076
+ let prevBottom = null;
26077
+ let prevLine = [];
26078
+ const nested = model.groups.some((g) => g.parent);
26079
+ for (const lane of lanes) {
26080
+ const top = y;
26081
+ y += (lane.headLine ? L.head : 0) + (nested ? 16 : 0) + L.lanePad;
26082
+ if (prevBottom !== null) channels.push({ key: `band${lane.index}`, axis: "y", lo: prevBottom, hi: top, fixed: true });
26083
+ let first = true;
26084
+ for (const row of lane.rows) {
26085
+ const natural = row.ids.map((id) => sizeNode(byId.get(id)));
26086
+ const fits = natural.reduce((sum, n) => sum + n.width, 0) + L.colGap * (row.ids.length - 1) <= room;
26087
+ const lines = fits ? [row.ids] : row.ids.map((id) => [id]);
26088
+ for (const ids of lines) {
26089
+ if (!first) {
26090
+ let gap = sizes.get(`s${seq2}`) ?? 30;
26091
+ for (const e of model.edges) {
26092
+ const lb = sizeEdgeLabel(e.label);
26093
+ if (!lb) continue;
26094
+ const pair = (p, q2) => prevLine.includes(p) && ids.includes(q2);
26095
+ if (pair(e.from, e.to) || pair(e.to, e.from)) gap = Math.max(gap, lb.height + 30);
26096
+ }
26097
+ channels.push({ key: `s${seq2}`, axis: "y", lo: y, hi: y + gap });
26098
+ y += gap;
26099
+ }
26100
+ first = false;
26101
+ const w = (room - L.colGap * (ids.length - 1)) / ids.length;
26102
+ const sized = ids.map((id) => sizeNode(byId.get(id), Math.floor(w)));
26103
+ const h = Math.max(...sized.map((b) => b.height));
26104
+ let bx = x0;
26105
+ ids.forEach((id, k) => {
26106
+ boxes.set(id, { ...sized[k], x: bx, y: Math.round(y + (h - sized[k].height) / 2), rowIndex: seq2, laneIndex: lane.index });
26107
+ bx += sized[k].width + L.colGap;
26108
+ });
26109
+ y += h;
26110
+ seq2++;
26111
+ prevLine = ids;
26112
+ }
26113
+ }
26114
+ y += L.lanePad;
26115
+ lane.frame = { x: left, y: top, w: room + L.lanePad * 2, h: y - top };
26116
+ prevBottom = y;
26117
+ y += 26;
26118
+ }
26119
+ const width = left + room + L.lanePad * 2 + right;
26120
+ const height = prevBottom + L.margin;
26121
+ channels.push({ key: "left", axis: "x", lo: 0, hi: left }, { key: "right", axis: "x", lo: width - right, hi: width });
26122
+ const frameLines = { xs: [left, width - right], ys: lanes.flatMap((l) => [l.frame.y, l.frame.y + l.frame.h]) };
26123
+ const sides = (e) => {
26124
+ const a = boxes.get(e.from);
26125
+ const b = boxes.get(e.to);
26126
+ if (a.rowIndex === b.rowIndex) return b.x > a.x ? ["right", "left"] : ["left", "right"];
26127
+ if (b.rowIndex === a.rowIndex + 1 && b.x < a.x + a.width && a.x < b.x + b.width) return ["bottom", "top"];
26128
+ return b.rowIndex > a.rowIndex ? ["right", "right"] : ["left", "left"];
26129
+ };
26130
+ return { lanes, boxes, channels, frameLines, sides, width, height };
26131
+ }
26132
+ function trackPositions(lo, hi) {
26133
+ const room = hi - lo - 12;
26134
+ if (room < 0) return [(lo + hi) / 2];
26135
+ const n = Math.min(SEARCH.maxTracks, Math.floor(room / LANES.track) + 1);
26136
+ const mid = (lo + hi) / 2;
26137
+ return Array.from({ length: n }, (_, k) => mid + (k - (n - 1) / 2) * LANES.track);
26138
+ }
26139
+ function routeAll(geo, model) {
26140
+ const { boxes } = geo;
26141
+ const edges = [];
26142
+ const loops = [];
26143
+ for (const e of model.edges) {
26144
+ if (!boxes.has(e.from) || !boxes.has(e.to)) continue;
26145
+ if (e.from === e.to) {
26146
+ loops.push(e);
26147
+ continue;
26148
+ }
26149
+ const [fromSide, toSide] = geo.sides(e);
26150
+ const a = boxes.get(e.from);
26151
+ const b = boxes.get(e.to);
26152
+ edges.push({ id: e.id, from: e.from, to: e.to, fromSide: openSide(a, fromSide, b, boxes), toSide: openSide(b, toSide, a, boxes) });
26153
+ }
26154
+ const xs = [];
26155
+ const ys = [];
26156
+ for (const c of geo.channels) (c.axis === "x" ? xs : ys).push(...trackPositions(c.lo, c.hi));
26157
+ const routes = routeOrthogonal({
26158
+ boxes,
26159
+ edges,
26160
+ xLines: xs,
26161
+ yLines: ys,
26162
+ avoid: geo.frameLines,
26163
+ bounds: { x0: 1, y0: 1, x1: geo.width - 1, y1: geo.height - 1 }
26164
+ });
26165
+ for (const e of loops) {
26166
+ const b = boxes.get(e.from);
26167
+ const r = b.x + b.width;
26168
+ const bottom = b.y + b.height;
26169
+ routes.set(e.id, [
26170
+ { x: r - 30, y: bottom },
26171
+ { x: r - 30, y: bottom + 14 },
26172
+ { x: r + 12, y: bottom + 14 },
26173
+ { x: r + 12, y: bottom - 14 },
26174
+ { x: r, y: bottom - 14 }
26175
+ ]);
26176
+ }
26177
+ return routes;
26178
+ }
26179
+ function openSide(box, side, other, boxes) {
26180
+ const reach = LANES.stub + LANES.clear + 2;
26181
+ const blocked = (sd) => {
26182
+ for (const o of boxes.values()) {
26183
+ if (o === box) continue;
26184
+ const ySpan = o.y < box.y + box.height && box.y < o.y + o.height;
26185
+ const xSpan = o.x < box.x + box.width && box.x < o.x + o.width;
26186
+ if (sd === "right" && ySpan && o.x >= box.x + box.width && o.x - (box.x + box.width) < reach) return true;
26187
+ if (sd === "left" && ySpan && o.x + o.width <= box.x && box.x - (o.x + o.width) < reach) return true;
26188
+ if (sd === "bottom" && xSpan && o.y >= box.y + box.height && o.y - (box.y + box.height) < reach) return true;
26189
+ if (sd === "top" && xSpan && o.y + o.height <= box.y && box.y - (o.y + o.height) < reach) return true;
26190
+ }
26191
+ return false;
26192
+ };
26193
+ if (!blocked(side)) return side;
26194
+ const towardY = other.y + other.height / 2 >= box.y + box.height / 2 ? ["bottom", "top"] : ["top", "bottom"];
26195
+ const towardX = other.x + other.width / 2 >= box.x + box.width / 2 ? ["right", "left"] : ["left", "right"];
26196
+ const order = side === "left" || side === "right" ? towardY : towardX;
26197
+ return order.find((sd) => !blocked(sd)) || side;
26198
+ }
26199
+ function channelShortfall(geo, routes) {
26200
+ const vertical = [];
26201
+ const horizontal = [];
26202
+ for (const pts of routes.values()) {
26203
+ for (let i = 1; i < pts.length; i++) {
26204
+ const a = pts[i - 1];
26205
+ const b = pts[i];
26206
+ if (a.x === b.x && a.y !== b.y) vertical.push(a.x);
26207
+ else if (a.y === b.y && a.x !== b.x) horizontal.push(a.y);
26208
+ }
26209
+ }
26210
+ const need = /* @__PURE__ */ new Map();
26211
+ for (const c of geo.channels) {
26212
+ if (c.fixed) continue;
26213
+ const lines = c.axis === "x" ? vertical : horizontal;
26214
+ const used = new Set(lines.filter((v) => v > c.lo && v < c.hi).map((v) => Math.round(v))).size;
26215
+ if (used >= trackPositions(c.lo, c.hi).length) need.set(c.key, 24 + (used + 2) * LANES.track);
26216
+ }
26217
+ return need;
26218
+ }
26219
+ var NORMAL = { left: [-1, 0], right: [1, 0], top: [0, -1], bottom: [0, 1] };
26220
+ function placePorts(boxes, edges) {
26221
+ const sides = /* @__PURE__ */ new Map();
26222
+ const add = (node2, side, other, edge, end) => {
26223
+ const key = `${node2}\0${side}`;
26224
+ if (!sides.has(key)) sides.set(key, { node: node2, side, items: [] });
26225
+ sides.get(key).items.push({ other, edge, end });
26226
+ };
26227
+ for (const e of edges) {
26228
+ add(e.from, e.fromSide, e.to, e, "fromPort");
26229
+ add(e.to, e.toSide, e.from, e, "toPort");
26230
+ }
26231
+ for (const { node: node2, side, items } of sides.values()) {
26232
+ const b = boxes.get(node2);
26233
+ const horizontal = side === "left" || side === "right";
26234
+ const lo = horizontal ? b.y + 9 : b.x + 12;
26235
+ const hi = horizontal ? b.y + b.height - 9 : b.x + b.width - 12;
26236
+ for (const it2 of items) {
26237
+ const o = boxes.get(it2.other);
26238
+ const oLo = horizontal ? o.y : o.x;
26239
+ const oHi = horizontal ? o.y + o.height : o.x + o.width;
26240
+ const sLo = horizontal ? b.y : b.x;
26241
+ const sHi = horizontal ? b.y + b.height : b.x + b.width;
26242
+ const overlap = Math.min(oHi, sHi) - Math.max(oLo, sLo);
26243
+ const want = overlap > 18 ? (Math.min(oHi, sHi) + Math.max(oLo, sLo)) / 2 : (oLo + oHi) / 2;
26244
+ it2.want = Math.min(hi, Math.max(lo, want));
26245
+ }
26246
+ items.sort((a, c) => a.want - c.want);
26247
+ const gap = Math.min(14, items.length > 1 ? (hi - lo) / (items.length - 1) : 14);
26248
+ let prev = -Infinity;
26249
+ for (const it2 of items) {
26250
+ it2.pos = Math.max(it2.want, prev + gap);
26251
+ prev = it2.pos;
26252
+ }
26253
+ const over = prev - hi;
26254
+ if (over > 0) {
26255
+ let next = Infinity;
26256
+ for (let k = items.length - 1; k >= 0; k--) {
26257
+ items[k].pos = Math.min(items[k].pos, hi, next - gap);
26258
+ next = items[k].pos;
26259
+ }
26260
+ }
26261
+ for (const it2 of items) {
26262
+ const pos = Math.round(it2.pos);
26263
+ const p = horizontal ? { x: side === "left" ? b.x : b.x + b.width, y: pos } : { x: pos, y: side === "top" ? b.y : b.y + b.height };
26264
+ it2.edge[it2.end] = p;
26265
+ }
26266
+ }
26267
+ }
26268
+ var Heap = class {
26269
+ constructor() {
26270
+ this.k = [];
26271
+ this.v = [];
26272
+ }
26273
+ push(item, key) {
26274
+ const { k, v } = this;
26275
+ let i = k.length;
26276
+ k.push(key);
26277
+ v.push(item);
26278
+ while (i > 0) {
26279
+ const p = i - 1 >> 1;
26280
+ if (k[p] <= key) break;
26281
+ k[i] = k[p];
26282
+ v[i] = v[p];
26283
+ i = p;
26284
+ }
26285
+ k[i] = key;
26286
+ v[i] = item;
26287
+ }
26288
+ /** Pops the smallest; its key is left in this.top. */
26289
+ pop() {
26290
+ const { k, v } = this;
26291
+ const item = v[0];
26292
+ this.top = k[0];
26293
+ const lastK = k.pop();
26294
+ const lastV = v.pop();
26295
+ const n = k.length;
26296
+ if (n) {
26297
+ let i = 0;
26298
+ for (; ; ) {
26299
+ const l = i * 2 + 1;
26300
+ if (l >= n) break;
26301
+ const m = l + 1 < n && k[l + 1] < k[l] ? l + 1 : l;
26302
+ if (k[m] >= lastK) break;
26303
+ k[i] = k[m];
26304
+ v[i] = v[m];
26305
+ i = m;
26306
+ }
26307
+ k[i] = lastK;
26308
+ v[i] = lastV;
26309
+ }
26310
+ return item;
26311
+ }
26312
+ get size() {
26313
+ return this.k.length;
26314
+ }
26315
+ };
26316
+ var COST = { bend: 36, overlap: 8, cross: 22, hug: 0.6 };
26317
+ var SEARCH = { weight: 1.5, maxSteps: 12e4, maxTracks: 14 };
26318
+ function routeOrthogonal({ boxes, edges, xLines = [], yLines = [], avoid = { xs: [], ys: [] }, bounds }) {
26319
+ const C = LANES.clear;
26320
+ const S2 = LANES.stub;
26321
+ placePorts(boxes, edges);
26322
+ const stubOf = (p, side) => ({ x: p.x + NORMAL[side][0] * S2, y: p.y + NORMAL[side][1] * S2 });
26323
+ const rnd = (v) => Math.round(v * 2) / 2;
26324
+ const hugXs = /* @__PURE__ */ new Set();
26325
+ const hugYs = /* @__PURE__ */ new Set();
26326
+ const xsAll = [...xLines];
26327
+ const ysAll = [...yLines];
26328
+ for (const b of boxes.values()) {
26329
+ xsAll.push(b.x - C, b.x + b.width + C);
26330
+ ysAll.push(b.y - C, b.y + b.height + C);
26331
+ hugXs.add(rnd(b.x - C)).add(rnd(b.x + b.width + C));
26332
+ hugYs.add(rnd(b.y - C)).add(rnd(b.y + b.height + C));
26333
+ }
26334
+ for (const x of avoid.xs) hugXs.add(rnd(x));
26335
+ for (const y of avoid.ys) hugYs.add(rnd(y));
26336
+ for (const e of edges) {
26337
+ for (const [p, side] of [
26338
+ [e.fromPort, e.fromSide],
26339
+ [e.toPort, e.toSide]
26340
+ ]) {
26341
+ const st2 = stubOf(p, side);
26342
+ xsAll.push(p.x, st2.x);
26343
+ ysAll.push(p.y, st2.y);
26344
+ }
26345
+ }
26346
+ const uniq = (arr, lo, hi) => [...new Set(arr.map(rnd))].filter((v) => v >= lo && v <= hi).sort((a, b) => a - b);
26347
+ const xs = uniq(xsAll, bounds.x0, bounds.x1);
26348
+ const ys = uniq(ysAll, bounds.y0, bounds.y1);
26349
+ const nx = xs.length;
26350
+ const ny = ys.length;
26351
+ const xi = new Map(xs.map((v, i) => [v, i]));
26352
+ const yi = new Map(ys.map((v, i) => [v, i]));
26353
+ const ix = (v) => xi.get(rnd(v));
26354
+ const iy = (v) => yi.get(rnd(v));
26355
+ const hugX = Uint8Array.from(xs, (x) => hugXs.has(x) ? 1 : 0);
26356
+ const hugY = Uint8Array.from(ys, (y) => hugYs.has(y) ? 1 : 0);
26357
+ const hBlock = new Uint8Array(nx * ny);
26358
+ const vBlock = new Uint8Array(nx * ny);
26359
+ const firstAbove = (arr, v) => {
26360
+ let lo = 0;
26361
+ let hi = arr.length;
26362
+ while (lo < hi) {
26363
+ const mid = lo + hi >> 1;
26364
+ if (arr[mid] > v) hi = mid;
26365
+ else lo = mid + 1;
26366
+ }
26367
+ return lo;
26368
+ };
26369
+ for (const b of boxes.values()) {
26370
+ const x0 = b.x - C;
26371
+ const x1 = b.x + b.width + C;
26372
+ const y0 = b.y - C;
26373
+ const y1 = b.y + b.height + C;
26374
+ const iA = firstAbove(xs, x0);
26375
+ const iB = firstAbove(xs, x1 - 1e-9);
26376
+ const jA = firstAbove(ys, y0);
26377
+ const jB = firstAbove(ys, y1 - 1e-9);
26378
+ for (let j = jA; j < jB; j++) {
26379
+ for (let i = Math.max(0, iA - 1); i < Math.min(nx - 1, iB); i++) {
26380
+ const mx = (xs[i] + xs[i + 1]) / 2;
26381
+ if (mx > x0 && mx < x1) hBlock[j * nx + i] = 1;
26382
+ }
26383
+ }
26384
+ for (let i = iA; i < iB; i++) {
26385
+ for (let j = Math.max(0, jA - 1); j < Math.min(ny - 1, jB); j++) {
26386
+ const my = (ys[j] + ys[j + 1]) / 2;
26387
+ if (my > y0 && my < y1) vBlock[j * nx + i] = 1;
26388
+ }
26389
+ }
26390
+ }
26391
+ const hUse = new Uint16Array(nx * ny);
26392
+ const vUse = new Uint16Array(nx * ny);
26393
+ const hPass = new Uint16Array(nx * ny);
26394
+ const vPass = new Uint16Array(nx * ny);
26395
+ const N = nx * ny * 4;
26396
+ const dist = new Float64Array(N);
26397
+ const prev = new Int32Array(N);
26398
+ const seen = new Uint32Array(N);
26399
+ let stamp = 0;
26400
+ const DX = [1, -1, 0, 0];
26401
+ const DY = [0, 0, 1, -1];
26402
+ const dirOf = (side) => ({ right: 0, left: 1, bottom: 2, top: 3 })[side];
26403
+ const reverse = [1, 0, 3, 2];
26404
+ const routes = /* @__PURE__ */ new Map();
26405
+ const order = [...edges].sort(
26406
+ (a, b) => Math.abs(a.fromPort.x - a.toPort.x) + Math.abs(a.fromPort.y - a.toPort.y) - (Math.abs(b.fromPort.x - b.toPort.x) + Math.abs(b.fromPort.y - b.toPort.y))
26407
+ );
26408
+ const solid = [...boxes.entries()];
26409
+ for (const e of order) {
26410
+ const a = e.fromPort;
26411
+ const b = e.toPort;
26412
+ if ((a.x === b.x || a.y === b.y) && dirOf(e.fromSide) === reverse[dirOf(e.toSide)] && towards(a, b, e.fromSide)) {
26413
+ const seg = { x0: Math.min(a.x, b.x), y0: Math.min(a.y, b.y), x1: Math.max(a.x, b.x), y1: Math.max(a.y, b.y) };
26414
+ const blocked = solid.some(([id, r]) => id !== e.from && id !== e.to && seg.x0 < r.x + r.width && r.x < seg.x1 && seg.y0 < r.y + r.height && r.y < seg.y1);
26415
+ if (!blocked) {
26416
+ routes.set(e.id, [a, b]);
26417
+ const path7 = [];
26418
+ const [i0, j0, i1, j1] = [ix(a.x), iy(a.y), ix(b.x), iy(b.y)];
26419
+ if (j0 === j1) for (let i = Math.min(i0, i1); i <= Math.max(i0, i1); i++) path7.push([i, j0]);
26420
+ else for (let j = Math.min(j0, j1); j <= Math.max(j0, j1); j++) path7.push([i0, j]);
26421
+ if (path7.every(([i, j]) => i !== void 0 && j !== void 0)) mark(path7);
26422
+ continue;
26423
+ }
26424
+ }
26425
+ const st2 = stubOf(e.fromPort, e.fromSide);
26426
+ const tt2 = stubOf(e.toPort, e.toSide);
26427
+ const si = ix(st2.x);
26428
+ const sj = iy(st2.y);
26429
+ const ti = ix(tt2.x);
26430
+ const tj = iy(tt2.y);
26431
+ let path6 = null;
26432
+ if (si !== void 0 && sj !== void 0 && ti !== void 0 && tj !== void 0) {
26433
+ path6 = search(si, sj, dirOf(e.fromSide), ti, tj, reverse[dirOf(e.toSide)]);
26434
+ }
26435
+ const pts = path6 ? path6.map(([i, j]) => ({ x: xs[i], y: ys[j] })) : elbow(st2, tt2, e.fromSide);
26436
+ if (path6) mark(path6);
26437
+ routes.set(e.id, simplify([e.fromPort, ...pts, e.toPort]));
26438
+ }
26439
+ return routes;
26440
+ function search(si, sj, sd, ti, tj, endDir) {
26441
+ stamp++;
26442
+ const W2 = SEARCH.weight;
26443
+ const tx = xs[ti];
26444
+ const ty = ys[tj];
26445
+ const heap = new Heap();
26446
+ const start = (sj * nx + si) * 4 + sd;
26447
+ dist[start] = 0;
26448
+ prev[start] = -1;
26449
+ seen[start] = stamp;
26450
+ heap.push(start, W2 * (Math.abs(xs[si] - tx) + Math.abs(ys[sj] - ty)));
26451
+ let best = -1;
26452
+ let bestCost = Infinity;
26453
+ let steps2 = 0;
26454
+ while (heap.size) {
26455
+ const st2 = heap.pop();
26456
+ if (heap.top >= bestCost) break;
26457
+ if (++steps2 > SEARCH.maxSteps) break;
26458
+ const d = st2 & 3;
26459
+ const p = st2 >> 2;
26460
+ const i = p % nx;
26461
+ const j = (p - i) / nx;
26462
+ const cost = dist[st2];
26463
+ if (heap.top > cost + W2 * (Math.abs(xs[i] - tx) + Math.abs(ys[j] - ty)) + 1e-6) continue;
26464
+ if (i === ti && j === tj) {
26465
+ const total = cost + (d === endDir ? 0 : COST.bend * (d === reverse[endDir] ? 3 : 1));
26466
+ if (total < bestCost) {
26467
+ bestCost = total;
26468
+ best = st2;
26469
+ }
26470
+ continue;
26471
+ }
26472
+ for (let d2 = 0; d2 < 4; d2++) {
26473
+ if (d2 === reverse[d]) continue;
26474
+ const i2 = i + DX[d2];
26475
+ const j2 = j + DY[d2];
26476
+ if (i2 < 0 || j2 < 0 || i2 >= nx || j2 >= ny) continue;
26477
+ const horizontal = d2 < 2;
26478
+ const seg = horizontal ? j * nx + (i2 < i ? i2 : i) : (j2 < j ? j2 : j) * nx + i;
26479
+ if (horizontal ? hBlock[seg] : vBlock[seg]) continue;
26480
+ const len = horizontal ? Math.abs(xs[i2] - xs[i]) : Math.abs(ys[j2] - ys[j]);
26481
+ let c = len * ((horizontal ? hugY[j] : hugX[i]) ? 1 + COST.hug : 1);
26482
+ if (d2 !== d) c += COST.bend;
26483
+ const used = horizontal ? hUse[seg] : vUse[seg];
26484
+ if (used) c += used * COST.overlap * len;
26485
+ const p2 = j2 * nx + i2;
26486
+ if (horizontal ? vPass[p2] : hPass[p2]) c += COST.cross;
26487
+ const st22 = p2 * 4 + d2;
26488
+ const nd = cost + c;
26489
+ if (seen[st22] !== stamp || nd < dist[st22]) {
26490
+ seen[st22] = stamp;
26491
+ dist[st22] = nd;
26492
+ prev[st22] = st2;
26493
+ heap.push(st22, nd + W2 * (Math.abs(xs[i2] - tx) + Math.abs(ys[j2] - ty)));
26494
+ }
26495
+ }
26496
+ }
26497
+ if (best < 0) return null;
26498
+ const out = [];
26499
+ for (let st2 = best; st2 >= 0; st2 = prev[st2]) {
26500
+ const p = st2 >> 2;
26501
+ out.push([p % nx, Math.floor(p / nx)]);
26502
+ }
26503
+ return out.reverse();
26504
+ }
26505
+ function mark(path6) {
26506
+ for (let k = 1; k < path6.length; k++) {
26507
+ const [i0, j0] = path6[k - 1];
26508
+ const [i1, j1] = path6[k];
26509
+ if (j0 === j1) {
26510
+ hUse[j0 * nx + Math.min(i0, i1)]++;
26511
+ hPass[j0 * nx + i0]++;
26512
+ hPass[j1 * nx + i1]++;
26513
+ } else {
26514
+ vUse[Math.min(j0, j1) * nx + i0]++;
26515
+ vPass[j0 * nx + i0]++;
26516
+ vPass[j1 * nx + i1]++;
26517
+ }
26518
+ }
26519
+ }
26520
+ }
26521
+ function towards(a, b, side) {
26522
+ if (side === "right") return b.x > a.x;
26523
+ if (side === "left") return b.x < a.x;
26524
+ if (side === "bottom") return b.y > a.y;
26525
+ return b.y < a.y;
26526
+ }
26527
+ function elbow(s, t, fromSide) {
26528
+ if (fromSide === "left" || fromSide === "right") {
26529
+ const mx = (s.x + t.x) / 2;
26530
+ return [s, { x: mx, y: s.y }, { x: mx, y: t.y }, t];
26531
+ }
26532
+ const my = (s.y + t.y) / 2;
26533
+ return [s, { x: s.x, y: my }, { x: t.x, y: my }, t];
26534
+ }
26535
+ function simplify(pts) {
26536
+ const out = [];
26537
+ for (const p of pts) {
26538
+ const last = out[out.length - 1];
26539
+ if (last && last.x === p.x && last.y === p.y) continue;
26540
+ if (out.length >= 2) {
26541
+ const a = out[out.length - 2];
26542
+ if (a.x === last.x && last.x === p.x || a.y === last.y && last.y === p.y) out.pop();
26543
+ }
26544
+ out.push(p);
26545
+ }
26546
+ return out;
26547
+ }
26548
+ function narrowLabel(label, width) {
26549
+ if (label.split(/[\s/\-_.:]+/).some((word) => textWidth(word, SIZES.edge) > width - 12)) return null;
26550
+ if (textWidth(label, SIZES.edge) + 12 <= width) return null;
26551
+ const lines = wrapText(label, SIZES.edge, width - 12, 2);
26552
+ return { lines, width: Math.max(...lines.map((l) => textWidth(l, SIZES.edge))) + 12, height: 6 + lines.length * 13 };
26553
+ }
26554
+ var rectsOverlap = (a, b, pad = 0) => a.x0 < b.x1 + pad && b.x0 < a.x1 + pad && a.y0 < b.y1 + pad && b.y0 < a.y1 + pad;
26555
+ function placeLabels(edges, routes, geo) {
26556
+ const { boxes } = geo;
26557
+ const bounds = { x0: 2, y0: 2, x1: geo.width - 2, y1: geo.height - 2 };
26558
+ const boxRects = [...boxes.values()].map((b) => ({ x0: b.x, y0: b.y, x1: b.x + b.width, y1: b.y + b.height }));
26559
+ const solid = [...boxRects];
26560
+ for (const lane of geo.lanes) {
26561
+ if (!lane.headLine) continue;
26562
+ const f = lane.frame;
26563
+ solid.push({ x0: f.x + 8, y0: f.y + 4, x1: f.x + 20 + textWidth(lane.headLine, LANES.headSize + 1, true), y1: f.y + LANES.head - 2 });
26564
+ }
26565
+ for (const pts of routes.values()) {
26566
+ if (pts.length < 2) continue;
26567
+ const a = pts[pts.length - 2];
26568
+ const b = pts[pts.length - 1];
26569
+ const ux = Math.sign(b.x - a.x);
26570
+ const uy = Math.sign(b.y - a.y);
26571
+ const tail = { x: b.x - ux * 12, y: b.y - uy * 12 };
26572
+ solid.push({ x0: Math.min(tail.x, b.x) - 6, y0: Math.min(tail.y, b.y) - 6, x1: Math.max(tail.x, b.x) + 6, y1: Math.max(tail.y, b.y) + 6 });
26573
+ }
26574
+ const gutters = geo.channels.filter((c) => c.axis === "x" && !c.fixed);
26575
+ const inGutter = (x) => gutters.some((c) => x > c.lo && x < c.hi);
26576
+ const placed = [];
26577
+ const out = /* @__PURE__ */ new Map();
26578
+ const area = (r, list) => list.reduce((sum, b) => sum + Math.max(0, Math.min(r.x1, b.x1) - Math.max(r.x0, b.x0)) * Math.max(0, Math.min(r.y1, b.y1) - Math.max(r.y0, b.y0)), 0);
26579
+ for (const e of edges) {
26580
+ const full = sizeEdgeLabel(e.label);
26581
+ const pts = routes.get(e.id);
26582
+ if (!full || !pts || pts.length < 2) continue;
26583
+ const segs = [];
26584
+ for (let k = 1; k < pts.length; k++) {
26585
+ const a = pts[k - 1];
26586
+ const b = pts[k];
26587
+ const len = Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
26588
+ const vertical = a.x === b.x;
26589
+ const score = len + (vertical ? 0 : 20) + (inGutter((a.x + b.x) / 2) ? 200 : 0);
26590
+ segs.push({ a, b, vertical, score });
26591
+ }
26592
+ segs.sort((p, q2) => q2.score - p.score);
26593
+ const sizesToTry = [full, ...[GUTTER_LABEL_W, 76].filter((w) => w < full.width).map((w) => narrowLabel(e.label, w)).filter(Boolean)];
26594
+ let choice = null;
26595
+ let best = null;
26596
+ for (const lb of sizesToTry) {
26597
+ for (const seg of segs) {
26598
+ const offsets = seg.vertical ? [[0, 0], [lb.width / 2 - 5, 0], [-(lb.width / 2 - 5), 0]] : [[0, 0], [0, -(lb.height / 2 - 3)], [0, lb.height / 2 - 3]];
26599
+ const len = Math.abs(seg.a.x - seg.b.x) + Math.abs(seg.a.y - seg.b.y);
26600
+ const step = Math.min(0.5, Math.max(6 / Math.max(1, len), 1 / 40));
26601
+ const ts = [0.5];
26602
+ for (let d = step; d < 0.5; d += step) ts.push(0.5 - d, 0.5 + d);
26603
+ for (const [dx, dy] of offsets) {
26604
+ for (const t of ts) {
26605
+ const cx = seg.a.x + (seg.b.x - seg.a.x) * t + dx;
26606
+ const cy = seg.a.y + (seg.b.y - seg.a.y) * t + dy;
26607
+ const r = { x0: cx - lb.width / 2, y0: cy - lb.height / 2, x1: cx + lb.width / 2, y1: cy + lb.height / 2 };
26608
+ if (r.x0 < bounds.x0 || r.x1 > bounds.x1 || r.y0 < bounds.y0 || r.y1 > bounds.y1) continue;
26609
+ const cost = area(r, boxRects) * 4 + area(r, solid) + area(r, placed) * 2;
26610
+ if (!best || cost < best.cost) best = { cx, cy, r, lb, cost };
26611
+ if (solid.some((q2) => rectsOverlap(r, q2, 3)) || placed.some((q2) => rectsOverlap(r, q2, 3))) continue;
26612
+ choice = { cx, cy, r, lb };
26613
+ break;
26614
+ }
26615
+ if (choice) break;
26616
+ }
26617
+ if (choice) break;
26618
+ }
26619
+ if (choice) break;
26620
+ }
26621
+ if (!choice) {
26622
+ if (best) choice = best;
26623
+ else {
26624
+ const seg = segs[0];
26625
+ const lb = sizesToTry[sizesToTry.length - 1];
26626
+ const cx = Math.min(bounds.x1 - lb.width / 2, Math.max(bounds.x0 + lb.width / 2, (seg.a.x + seg.b.x) / 2));
26627
+ const cy = Math.min(bounds.y1 - lb.height / 2, Math.max(bounds.y0 + lb.height / 2, (seg.a.y + seg.b.y) / 2));
26628
+ choice = { cx, cy, lb, r: { x0: cx - lb.width / 2, y0: cy - lb.height / 2, x1: cx + lb.width / 2, y1: cy + lb.height / 2 } };
26629
+ }
26630
+ }
26631
+ placed.push(choice.r);
26632
+ out.set(e.id, { cx: choice.cx, cy: choice.cy, width: choice.lb.width, height: choice.lb.height, lines: choice.lb.lines });
26633
+ }
26634
+ return out;
26635
+ }
26636
+ function finish({ geo, routed }, model) {
26637
+ const { boxes, lanes } = geo;
26638
+ const nodes = model.nodes.filter((n) => boxes.has(n.id)).map((n) => ({ ...n, ...boxes.get(n.id) }));
26639
+ const labels = placeLabels(model.edges, routed, geo);
26640
+ const edges = model.edges.filter((e) => routed.has(e.id)).map((e) => ({ ...e, orthogonal: true, points: routed.get(e.id), labelBox: labels.get(e.id) || null }));
26641
+ const groups = [];
26642
+ for (const lane of lanes) {
26643
+ if (!lane.group) continue;
26644
+ const f = lane.frame;
26645
+ groups.push({ ...lane.group, lane: true, labelLine: lane.headLine, x: f.x, y: f.y, width: f.w, height: f.h });
26646
+ }
26647
+ for (const g of model.groups) {
26648
+ if (!g.parent) continue;
26649
+ const ms = g.members.map((id) => boxes.get(id)).filter(Boolean);
26650
+ if (!ms.length) continue;
26651
+ const pad = 9;
26652
+ const x0 = Math.min(...ms.map((b) => b.x)) - pad;
26653
+ const y0 = Math.min(...ms.map((b) => b.y)) - pad - (g.label ? 6 : 0);
26654
+ const x1 = Math.max(...ms.map((b) => b.x + b.width)) + pad;
26655
+ const y1 = Math.max(...ms.map((b) => b.y + b.height)) + pad;
26656
+ const labelLine = g.label ? wrapText(g.label, SIZES.group, Math.max(24, x1 - x0 - 24 - 14), 1)[0] : "";
26657
+ groups.push({ ...g, labelLine, x: x0, y: y0, width: x1 - x0, height: y1 - y0 });
26658
+ }
26659
+ let width = geo.width;
26660
+ let height = geo.height;
26661
+ for (const e of edges) {
26662
+ for (const p of e.points) {
26663
+ width = Math.max(width, Math.ceil(p.x + 8));
26664
+ height = Math.max(height, Math.ceil(p.y + 8));
26665
+ }
26666
+ if (e.labelBox) {
26667
+ width = Math.max(width, Math.ceil(e.labelBox.cx + e.labelBox.width / 2 + 6));
26668
+ height = Math.max(height, Math.ceil(e.labelBox.cy + e.labelBox.height / 2 + 6));
26669
+ }
26670
+ }
26671
+ return { rankdir: "lanes", nodes, edges, groups, width, height };
26672
+ }
26673
+
26674
+ // src/runtime/components/_architecture-model.js
26675
+ var NODE_KINDS = ["frontend", "backend", "database", "messagebus", "cloud", "security", "external"];
26676
+ var EDGE_STYLES = ["solid", "dashed", "emphasis", "security"];
26677
+ var GROUP_KINDS = ["region", "security", "plain"];
26678
+ var DIRECTIONS = ["auto", "right", "down", "lanes"];
26679
+ var NODE_TONES = ["info", "success", "warning", "danger", "strong"];
26680
+ var EDGE_TONES = ["info", "success", "warning", "danger"];
26681
+ var SIZES = {
26682
+ label: 13,
26683
+ detail: 11,
26684
+ tag: 10,
26685
+ edge: 11,
26686
+ group: 11,
26687
+ nodeMinW: 128,
26688
+ nodeMaxW: 232,
26689
+ edgeMaxW: 176,
26690
+ padX: 14,
26691
+ icon: 15,
26692
+ tagRow: 17
26693
+ };
26694
+ var DEFAULT_TARGET_WIDTH = 900;
26695
+ var LANES_TARGET_WIDTH = 1180;
26696
+ var LANES_SCROLL_WIDTH = 1e3;
26697
+ function textWidth(text, size, mono = false) {
26698
+ let w = 0;
26699
+ for (const ch of String(text ?? "")) w += charUnits(ch, mono);
26700
+ return Math.ceil(w * size);
26701
+ }
26702
+ function charUnits(ch, mono) {
26703
+ if (mono) return 0.62;
26704
+ if (ch.charCodeAt(0) > 11903) return 1.02;
26705
+ if (/[ilI.,:;'|!()[\]{} ]/.test(ch)) return 0.32;
26706
+ if (/[mwMW@%&]/.test(ch)) return 0.88;
26707
+ if (/[A-Z0-9#$?_~]/.test(ch)) return 0.68;
26708
+ return 0.57;
26709
+ }
26710
+ function wrapText(text, size, maxWidth, maxLines = 2, mono = false) {
26711
+ const words = (String(text ?? "").trim().match(/[^\s/\-_.:]*[\s/\-_.:]?/g) || []).filter(Boolean);
26712
+ const lines = [];
26713
+ let line = "";
26714
+ const push = (s) => lines.push(s.trimEnd());
26715
+ for (const word of words) {
26716
+ if (lines.length > maxLines) break;
26717
+ if (textWidth(line + word, size, mono) <= maxWidth) {
26718
+ line += word;
26719
+ continue;
26720
+ }
26721
+ if (line) push(line);
26722
+ line = "";
26723
+ let rest = word;
26724
+ while (lines.length <= maxLines && textWidth(rest, size, mono) > maxWidth) {
26725
+ let cut = 0;
26726
+ let units = 0;
26727
+ for (const ch of rest) {
26728
+ const u = charUnits(ch, mono);
26729
+ if (cut > 0 && Math.ceil((units + u) * size) > maxWidth) break;
26730
+ units += u;
26731
+ cut += ch.length;
26732
+ }
26733
+ push(rest.slice(0, cut));
26734
+ rest = rest.slice(cut);
26735
+ }
26736
+ line = rest;
26737
+ }
26738
+ if (line) push(line);
26739
+ if (lines.length <= maxLines) return lines.length ? lines : [""];
26740
+ const kept = lines.slice(0, maxLines);
26741
+ let last = Array.from(kept[maxLines - 1]);
26742
+ while (last.length && textWidth(`${last.join("")}\u2026`, size, mono) > maxWidth) last.pop();
26743
+ kept[maxLines - 1] = `${last.join("").trimEnd()}\u2026`;
26744
+ return kept;
26745
+ }
26746
+ var isElement = (v) => v && typeof v === "object" && v.props && typeof v.props === "object";
26747
+ var str = (v) => typeof v === "string" ? v : v == null ? "" : String(v);
26748
+ function buildModel(props) {
26749
+ const problems = [];
26750
+ const nodes = /* @__PURE__ */ new Map();
26751
+ const seenEls = /* @__PURE__ */ new Map();
26752
+ let anon = 0;
26753
+ const addNode = (el) => {
26754
+ if (!isElement(el)) return null;
26755
+ if (seenEls.has(el)) return seenEls.get(el);
26756
+ const id = el.statementId || `_node${anon++}`;
26757
+ if (!nodes.has(id)) {
26758
+ const p = el.props;
26759
+ const label = str(p.label).trim() || id;
26760
+ nodes.set(id, {
26761
+ id,
26762
+ named: !!el.statementId,
26763
+ label,
26764
+ kind: NODE_KINDS.includes(p.kind) ? p.kind : "backend",
26765
+ detail: str(p.detail).trim(),
26766
+ tag: str(p.tag).trim(),
26767
+ tone: NODE_TONES.includes(p.tone) ? p.tone : "",
26768
+ row: Number.isInteger(p.row) && p.row > 0 ? Math.min(p.row, 200) : null
26769
+ });
26770
+ }
26771
+ seenEls.set(el, id);
26772
+ return id;
26773
+ };
26774
+ for (const el of Array.isArray(props?.nodes) ? props.nodes : []) addNode(el);
26775
+ const edges = [];
26776
+ const edgeIds = /* @__PURE__ */ new Set();
26777
+ for (const el of Array.isArray(props?.edges) ? props.edges : []) {
26778
+ if (!isElement(el)) continue;
26779
+ const id = el.statementId || `_edge${anon++}`;
26780
+ if (edgeIds.has(id)) continue;
26781
+ const from = addNode(el.props.from);
26782
+ const to = addNode(el.props.to);
26783
+ if (!from || !to) continue;
26784
+ edgeIds.add(id);
26785
+ edges.push({
26786
+ id,
26787
+ named: !!el.statementId,
26788
+ from,
26789
+ to,
26790
+ label: str(el.props.label).trim(),
26791
+ style: EDGE_STYLES.includes(el.props.style) ? el.props.style : "solid",
26792
+ tone: EDGE_TONES.includes(el.props.tone) ? el.props.tone : ""
26793
+ });
26794
+ }
26795
+ const groups = [];
26796
+ const groupIds = /* @__PURE__ */ new Set();
26797
+ for (const el of Array.isArray(props?.groups) ? props.groups : []) {
26798
+ if (!isElement(el)) continue;
26799
+ const id = el.statementId || `_group${anon++}`;
26800
+ if (groupIds.has(id)) continue;
26801
+ const members2 = [...new Set((Array.isArray(el.props.members) ? el.props.members : []).map(addNode).filter(Boolean))];
26802
+ if (!members2.length) continue;
26803
+ groupIds.add(id);
26804
+ groups.push({
26805
+ id,
26806
+ named: !!el.statementId,
26807
+ label: str(el.props.label).trim(),
26808
+ kind: GROUP_KINDS.includes(el.props.kind) ? el.props.kind : "region",
26809
+ members: members2
26810
+ });
26811
+ }
26812
+ nestGroups(groups, problems);
26813
+ const direction = DIRECTIONS.includes(props?.direction) ? props.direction : "auto";
26814
+ return { nodes: [...nodes.values()], edges, groups, direction, problems };
26815
+ }
26816
+ function nestGroups(groups, problems) {
26817
+ const bySize = [...groups].sort((a, b) => a.members.length - b.members.length);
26818
+ for (const g of bySize) {
26819
+ const set2 = new Set(g.members);
26820
+ g.parent = bySize.find((o) => o !== g && o.members.length >= g.members.length && bySize.indexOf(o) > bySize.indexOf(g) && g.members.every((m) => o.members.includes(m)))?.id ?? null;
26821
+ g.memberSet = set2;
26822
+ }
26823
+ const owner = /* @__PURE__ */ new Map();
26824
+ for (const g of bySize) {
26825
+ for (const m of g.members) {
26826
+ if (!owner.has(m)) owner.set(m, g.id);
26827
+ else {
26828
+ let first = groups.find((x) => x.id === owner.get(m));
26829
+ if (!isAncestor(groups, g.id, first.id)) {
26830
+ for (let up = groups.find((x) => x.id === first.parent); up; up = groups.find((x) => x.id === up.parent)) {
26831
+ if (g.members.every((x) => up.memberSet.has(x))) break;
26832
+ first = up;
26833
+ }
26834
+ problems.push(
26835
+ `Groups ${first.named ? first.id : `"${first.label}"`} and ${g.named ? g.id : `"${g.label}"`} share ${m} but neither contains the other; it is drawn in the first. Nest one group inside the other or remove ${m} from one.`
26836
+ );
26837
+ }
26838
+ }
26839
+ }
26840
+ }
26841
+ for (const g of groups) g.directMembers = g.members.filter((m) => owner.get(m) === g.id);
26842
+ }
26843
+ function isAncestor(groups, ancestorId, id) {
26844
+ let cur = groups.find((g) => g.id === id);
26845
+ while (cur?.parent) {
26846
+ if (cur.parent === ancestorId) return true;
26847
+ cur = groups.find((g) => g.id === cur.parent);
26848
+ }
26849
+ return false;
26850
+ }
26851
+ function detailLinesFor(detail, width) {
26852
+ if (!detail) return [];
26853
+ const parts = detail.split("\n").map((t) => t.trim()).filter(Boolean);
26854
+ const lines = [];
26855
+ for (let i = 0; i < parts.length; i++) {
26856
+ if (lines.length === 2) {
26857
+ const last = lines.pop().replace(/…$/, "");
26858
+ lines.push(wrapText(`${last} ${parts.slice(i).join(" ")}`, SIZES.detail, width, 1, true)[0]);
26859
+ break;
26860
+ }
26861
+ lines.push(...wrapText(parts[i], SIZES.detail, width, 2 - lines.length, true));
26862
+ }
26863
+ return lines;
26864
+ }
26865
+ function sizeNode(node2, forceWidth = 0) {
26866
+ const { label, detail, tag, nodeMinW, nodeMaxW, padX, icon } = SIZES;
26867
+ const glyph = node2.tone === "danger" && !node2.tag ? 20 : 0;
26868
+ const natural = Math.max(
26869
+ textWidth(node2.label, label) + icon + 6 + glyph,
26870
+ ...String(node2.detail || "").split("\n").map((t) => textWidth(t.trim(), detail, true)),
26871
+ // With a tag, the risk glyph sits beside the chip in the tag row.
26872
+ node2.tag ? textWidth(node2.tag, tag) + 14 + (node2.tone === "danger" ? 18 : 0) : 0
26873
+ );
26874
+ const width = forceWidth || Math.min(nodeMaxW, Math.max(nodeMinW, natural + padX * 2));
26875
+ const labelLines = wrapText(node2.label, label, width - padX * 2 - icon - 6 - glyph, 2);
26876
+ const detailLines = detailLinesFor(node2.detail, width - padX * 2);
26877
+ const tagLine = node2.tag ? wrapText(node2.tag, tag, width - padX * 2 - 14, 1)[0] : "";
26878
+ const tagRow = tagLine ? SIZES.tagRow : 0;
26879
+ const height = 16 + tagRow + labelLines.length * 17 + detailLines.length * 15 + (detailLines.length ? 1 : 0) + 8;
26880
+ return { width, height, labelLines, detailLines, tagLine, tagRow };
26881
+ }
26882
+ function sizeEdgeLabel(label) {
26883
+ if (!label) return null;
26884
+ const lines = wrapText(label, SIZES.edge, SIZES.edgeMaxW - 12, 2);
26885
+ const width = Math.max(...lines.map((l) => textWidth(l, SIZES.edge))) + 12;
26886
+ return { lines, width, height: 6 + lines.length * 13 };
26887
+ }
26888
+ function runLayout(model, rankdir) {
26889
+ const g = new Uo.graphlib.Graph({ compound: true, multigraph: true });
26890
+ g.setGraph({ rankdir, nodesep: rankdir === "LR" ? 26 : 34, ranksep: rankdir === "LR" ? 46 : 42, edgesep: 14, marginx: 18, marginy: 14 });
26891
+ g.setDefaultEdgeLabel(() => ({}));
26892
+ const boxes = /* @__PURE__ */ new Map();
26893
+ for (const n of model.nodes) {
26894
+ const box = sizeNode(n);
26895
+ boxes.set(n.id, box);
26896
+ g.setNode(n.id, { width: box.width, height: box.height });
26897
+ }
26898
+ for (const grp of model.groups) g.setNode(`group:${grp.id}`, {});
26899
+ for (const grp of model.groups) {
26900
+ if (grp.parent) g.setParent(`group:${grp.id}`, `group:${grp.parent}`);
26901
+ for (const m of grp.directMembers) g.setParent(m, `group:${grp.id}`);
26902
+ }
26903
+ const labels = new Map(model.edges.map((e) => [e.id, sizeEdgeLabel(e.label)]));
26904
+ for (const e of model.edges) {
26905
+ const lb = labels.get(e.id);
26906
+ g.setEdge(e.from, e.to, lb ? { width: lb.width, height: lb.height, labelpos: "c" } : {}, e.id);
26907
+ }
26908
+ Uo.layout(g);
26909
+ const nodes = model.nodes.map((n) => {
26910
+ const p = g.node(n.id);
26911
+ const box = boxes.get(n.id);
26912
+ return { ...n, ...box, x: p.x - box.width / 2, y: p.y - box.height / 2 };
26913
+ });
26914
+ const edges = model.edges.map((e) => {
26915
+ const d = g.edge({ v: e.from, w: e.to, name: e.id }) || {};
26916
+ const lb = labels.get(e.id);
26917
+ return {
26918
+ ...e,
26919
+ points: (d.points || []).map((pt2) => ({ x: pt2.x, y: pt2.y })),
26920
+ labelBox: lb ? { cx: d.x, cy: d.y, width: lb.width, height: lb.height, lines: lb.lines } : null
26921
+ };
26922
+ });
26923
+ const groups = model.groups.map((grp) => {
26924
+ const p = g.node(`group:${grp.id}`) || {};
26925
+ const width2 = p.width ?? 0;
26926
+ const labelLine = grp.label ? wrapText(grp.label, SIZES.group, Math.max(24, width2 - 24 - 14), 1)[0] : "";
26927
+ return { ...grp, labelLine, x: (p.x ?? 0) - width2 / 2, y: (p.y ?? 0) - (p.height ?? 0) / 2, width: width2, height: p.height ?? 0 };
26928
+ });
26929
+ const gr2 = g.graph();
26930
+ let width = Math.ceil(gr2.width || 0);
26931
+ let height = Math.ceil(gr2.height || 0);
26932
+ for (const e of edges) {
26933
+ if (e.from !== e.to) continue;
26934
+ const n = nodes.find((x) => x.id === e.from);
26935
+ const d = g.edge({ v: e.from, w: e.to, name: e.id }) || {};
26936
+ const r = n.x + n.width;
26937
+ const b = n.y + n.height;
26938
+ const cx = n.x + n.width / 2;
26939
+ const cy = n.y + n.height / 2;
26940
+ const placed = Number.isFinite(d.x) && Number.isFinite(d.y);
26941
+ if (rankdir === "TB") {
26942
+ const lx = placed ? d.x : r + 30 + (e.labelBox ? e.labelBox.width / 2 : 0);
26943
+ const reach = Math.max(r + 18, e.labelBox ? lx - e.labelBox.width / 2 - 3 : lx);
26944
+ const y1 = cy - n.height * 0.22;
26945
+ const y2 = cy + n.height * 0.22;
26946
+ e.points = [
26947
+ { x: r, y: y1 },
26948
+ { x: reach, y: y1 - 8 },
26949
+ { x: reach, y: y2 + 8 },
26950
+ { x: r, y: y2 }
26951
+ ];
26952
+ if (e.labelBox) e.labelBox = { ...e.labelBox, cx: Math.max(lx, reach + 3 + e.labelBox.width / 2), cy };
26953
+ } else {
26954
+ const ly = placed ? d.y : b + 30 + (e.labelBox ? e.labelBox.height / 2 : 0);
26955
+ const reach = Math.max(b + 16, e.labelBox ? ly - e.labelBox.height / 2 - 3 : ly);
26956
+ const spread = Math.min(30, n.width * 0.3);
26957
+ e.points = [
26958
+ { x: cx - spread, y: b },
26959
+ { x: cx - spread - 8, y: reach },
26960
+ { x: cx + spread + 8, y: reach },
26961
+ { x: cx + spread, y: b }
26962
+ ];
26963
+ if (e.labelBox) e.labelBox = { ...e.labelBox, cx, cy: Math.max(ly, reach + 3 + e.labelBox.height / 2) };
26964
+ }
26965
+ const xs = e.points.map((p) => p.x);
26966
+ const ys = e.points.map((p) => p.y);
26967
+ if (e.labelBox) {
26968
+ xs.push(e.labelBox.cx + e.labelBox.width / 2);
26969
+ ys.push(e.labelBox.cy + e.labelBox.height / 2);
26970
+ }
26971
+ width = Math.max(width, Math.ceil(Math.max(...xs) + 12));
26972
+ height = Math.max(height, Math.ceil(Math.max(...ys) + 10));
26973
+ }
26974
+ return { rankdir, nodes, edges, groups, width, height };
26975
+ }
26976
+ var LEGIBLE_SCALE = 0.85;
26977
+ function scaleAt(layout, targetWidth = DEFAULT_TARGET_WIDTH) {
26978
+ return Math.min(1, targetWidth / Math.max(1, layout.width));
26979
+ }
26980
+ function layoutModel(model, targetWidth = DEFAULT_TARGET_WIDTH) {
26981
+ if (!model.nodes.length) return null;
26982
+ if (model.direction === "right") return runLayout(model, "LR");
26983
+ if (model.direction === "down") return runLayout(model, "TB");
26984
+ const planned = model.direction === "lanes" ? lanesPlanWidth(model) : 0;
26985
+ if (planned) {
26986
+ if (planned * LEGIBLE_SCALE <= targetWidth || targetWidth >= LANES_SCROLL_WIDTH) return runLanes(model);
26987
+ return runStackedLanes(model, targetWidth);
26988
+ }
26989
+ const lr2 = runLayout(model, "LR");
26990
+ if (scaleAt(lr2, targetWidth) >= LEGIBLE_SCALE) return lr2;
26991
+ const tb = runLayout(model, "TB");
26992
+ if (scaleAt(tb, targetWidth) >= LEGIBLE_SCALE) return tb;
26993
+ return scaleAt(lr2, targetWidth) > scaleAt(tb, targetWidth) * 1.1 ? lr2 : tb;
26994
+ }
26995
+ function architectureNotes(props) {
26996
+ const model = buildModel(props);
26997
+ const notes = model.problems.map((message) => ({ code: "architecture", message }));
26998
+ if (!model.nodes.length) return notes;
26999
+ const layoutNote = (message) => notes.push({ code: "architecture-layout", message });
27000
+ if (model.direction === "lanes") {
27001
+ const lanes = runLanes(model);
27002
+ if (!lanes) layoutNote('direction "lanes" needs Groups (each top-level Group is a column); without any it lays out as auto.');
27003
+ else if (scaleAt(lanes, LANES_TARGET_WIDTH) < LEGIBLE_SCALE)
27004
+ layoutNote(
27005
+ `These lanes need about ${lanes.width}px; a laptop page gives about ${LANES_TARGET_WIDTH}px, so they scroll sideways there (narrow screens stack them as bands). To fit: fewer lanes, fewer boxes side by side, shorter edge labels.`
27006
+ );
27007
+ } else {
27008
+ const l = layoutModel(model, DEFAULT_TARGET_WIDTH);
27009
+ if (scaleAt(l, DEFAULT_TARGET_WIDTH) < LEGIBLE_SCALE) {
27010
+ const forced = model.direction === "right" || model.direction === "down";
27011
+ const auto = forced ? layoutModel({ ...model, direction: "auto" }, DEFAULT_TARGET_WIDTH) : l;
27012
+ const advice = forced && scaleAt(auto, DEFAULT_TARGET_WIDTH) >= LEGIBLE_SCALE ? "Leave direction out (auto) to fit the page." : 'To fit: split it into smaller diagrams, or use direction "lanes" if it divides into owners or tiers.';
27013
+ layoutNote(
27014
+ `${forced ? `direction "${model.direction}" makes this` : "This diagram is"} about ${l.width}px wide, more than the page gives (about ${DEFAULT_TARGET_WIDTH}px), so it scrolls sideways. ${advice}`
27015
+ );
27016
+ }
27017
+ }
27018
+ return notes;
27019
+ }
27020
+
23758
27021
  // src/cli/check.js
23759
27022
  var parser = null;
23760
27023
  var customParsers = /* @__PURE__ */ new WeakMap();
@@ -23776,6 +27039,19 @@ function statementLines(html) {
23776
27039
  for (const s of splitStatements(art.program)) out.set(s.id, { line: art.programLine + s.line - 1, text: s.text });
23777
27040
  return out;
23778
27041
  }
27042
+ function elementsOf(root, typeName) {
27043
+ const out = [];
27044
+ const seen = /* @__PURE__ */ new Set();
27045
+ const stack = [root];
27046
+ while (stack.length) {
27047
+ const v = stack.pop();
27048
+ if (!v || typeof v !== "object" || seen.has(v)) continue;
27049
+ seen.add(v);
27050
+ if (v.typeName === typeName && v.props) out.push(v);
27051
+ for (const child of Array.isArray(v) ? v : Object.values(v.props || {})) stack.push(child);
27052
+ }
27053
+ return out;
27054
+ }
23779
27055
  function checkHtml(html, { schema } = {}) {
23780
27056
  const art = readArtifact(html);
23781
27057
  const result = { ok: true, errors: [], warnings: [], statements: 0, title: art.title, hasMermaid: false };
@@ -23805,7 +27081,11 @@ function checkHtml(html, { schema } = {}) {
23805
27081
  return result;
23806
27082
  }
23807
27083
  result.statements = parsed.meta.statementCount;
27084
+ const seen = /* @__PURE__ */ new Set();
23808
27085
  for (const e of parsed.meta.errors) {
27086
+ const key = `${e.severity}\0${e.code}\0${e.statementId}\0${e.message}`;
27087
+ if (seen.has(key)) continue;
27088
+ seen.add(key);
23809
27089
  const entry = {
23810
27090
  code: e.code,
23811
27091
  statement: e.statementId,
@@ -23837,6 +27117,17 @@ function checkHtml(html, { schema } = {}) {
23837
27117
  if (parsed.meta.incomplete) {
23838
27118
  result.errors.push({ code: "incomplete", message: "The program ends mid-statement (an unclosed string or bracket)." });
23839
27119
  }
27120
+ const diagrams = /* @__PURE__ */ new Set();
27121
+ for (const el of elementsOf(parsed.root, "Architecture")) {
27122
+ if (el.statementId && diagrams.has(el.statementId)) continue;
27123
+ diagrams.add(el.statementId);
27124
+ try {
27125
+ for (const note of architectureNotes(el.props)) {
27126
+ result.warnings.push({ code: note.code, statement: el.statementId, line: lineOf(el.statementId), message: note.message });
27127
+ }
27128
+ } catch {
27129
+ }
27130
+ }
23840
27131
  const dupes = /* @__PURE__ */ new Map();
23841
27132
  for (const s of splitStatements(art.program)) dupes.set(s.id, (dupes.get(s.id) || 0) + 1);
23842
27133
  for (const [id, n] of dupes) {
@@ -24091,7 +27382,9 @@ FEEDBACK (what poll returns)
24091
27382
 
24092
27383
  CHECK verifies syntax, component names, required props, unresolved references and
24093
27384
  statements unreachable from root. Mermaid syntax is only checked when it renders; failures
24094
- show in the reviewer's panel and can come back as render_error.
27385
+ show in the reviewer's panel and can come back as render_error. CHECK does not judge how
27386
+ a page looks: open it for that. It does warn when an Architecture diagram will not fit the
27387
+ page (it would scroll sideways).
24095
27388
 
24096
27389
  WHEN TO USE
24097
27390
  Plans, comparisons, decisions, reviews, reports: anything easier to grasp as a page.
@@ -24238,33 +27531,33 @@ function describeItems(abs, items) {
24238
27531
  lines = statementLines(fs8.readFileSync(abs, "utf8"));
24239
27532
  } catch {
24240
27533
  }
24241
- const at = (id) => {
27534
+ const at2 = (id) => {
24242
27535
  const l = lines.get(id);
24243
27536
  if (!l) return {};
24244
27537
  const first = l.text.split("\n")[0];
24245
27538
  return { line: l.line, source: first.length > 110 ? first.slice(0, 109) + "\u2026" : first };
24246
27539
  };
24247
- return items.map((it) => {
24248
- if (it.kind === "annotation") {
24249
- const o = { annotation: `${it.target} (${it.component})`, ...at(it.target) };
24250
- const within = (it.path || []).slice(0, -1).filter((p) => p !== "root");
27540
+ return items.map((it2) => {
27541
+ if (it2.kind === "annotation") {
27542
+ const o = { annotation: `${it2.target} (${it2.component})`, ...at2(it2.target) };
27543
+ const within = (it2.path || []).slice(0, -1).filter((p) => p !== "root");
24251
27544
  if (within.length) o.within = within.join(" > ");
24252
- if (it.selection) o.selection = it.selection;
24253
- else if (it.excerpt) o.excerpt = it.excerpt;
24254
- if (it.detail) o.detail = it.detail;
24255
- o.note = it.note || "(no note: the selection itself is the point)";
27545
+ if (it2.selection) o.selection = it2.selection;
27546
+ else if (it2.excerpt) o.excerpt = it2.excerpt;
27547
+ if (it2.detail) o.detail = it2.detail;
27548
+ o.note = it2.note || "(no note: the selection itself is the point)";
24256
27549
  return o;
24257
27550
  }
24258
- if (it.kind === "action") {
24259
- const o = { action: it.message };
24260
- if (it.form) o.form = it.form;
24261
- if (it.context !== void 0) o.context = it.context;
27551
+ if (it2.kind === "action") {
27552
+ const o = { action: it2.message };
27553
+ if (it2.form) o.form = it2.form;
27554
+ if (it2.context !== void 0) o.context = it2.context;
24262
27555
  return o;
24263
27556
  }
24264
- if (it.kind === "render-error") {
24265
- return { render_error: it.statement || "(page)", ...at(it.statement), error: it.message, note: it.note };
27557
+ if (it2.kind === "render-error") {
27558
+ return { render_error: it2.statement || "(page)", ...at2(it2.statement), error: it2.message, note: it2.note };
24266
27559
  }
24267
- return { message: it.text ?? it.note ?? "" };
27560
+ return { message: it2.text ?? it2.note ?? "" };
24268
27561
  });
24269
27562
  }
24270
27563
  var NEXT = {
@@ -24456,3 +27749,8 @@ main().catch((err) => {
24456
27749
  process.stdout.write(format({ status: "error", error: String(err?.message || err) }) + "\n");
24457
27750
  process.exitCode = 1;
24458
27751
  });
27752
+ /*! Bundled license information:
27753
+
27754
+ @dagrejs/dagre/dist/dagre.esm.js:
27755
+ (*! For license information please see dagre.esm.js.LEGAL.txt *)
27756
+ */