@eyeon/map 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/README.md +18 -1
  2. package/dist/assets/MapViewer.css +1 -1
  3. package/dist/assets/index.css +1 -1
  4. package/dist/chunks/MapViewer.js +1988 -358
  5. package/dist/chunks/MapViewer.js.map +1 -1
  6. package/dist/chunks/graph-tools.js +202 -109
  7. package/dist/chunks/graph-tools.js.map +1 -1
  8. package/dist/chunks/stacking.js +1426 -0
  9. package/dist/chunks/stacking.js.map +1 -0
  10. package/dist/core/filletPolygon.d.ts +10 -0
  11. package/dist/core/filletPolygon.d.ts.map +1 -0
  12. package/dist/core/geometry/index.d.ts +41 -4
  13. package/dist/core/geometry/index.d.ts.map +1 -1
  14. package/dist/core/hostChrome.d.ts +20 -0
  15. package/dist/core/hostChrome.d.ts.map +1 -0
  16. package/dist/core/import/index.d.ts +52 -3
  17. package/dist/core/import/index.d.ts.map +1 -1
  18. package/dist/core/import/svgStyle.d.ts +21 -0
  19. package/dist/core/import/svgStyle.d.ts.map +1 -0
  20. package/dist/core/import/svgTransform.d.ts +49 -0
  21. package/dist/core/import/svgTransform.d.ts.map +1 -0
  22. package/dist/core/index.d.ts +6 -0
  23. package/dist/core/index.d.ts.map +1 -1
  24. package/dist/core/index.js +89 -279
  25. package/dist/core/index.js.map +1 -1
  26. package/dist/core/layerStyles.d.ts +44 -0
  27. package/dist/core/layerStyles.d.ts.map +1 -0
  28. package/dist/core/mediaUrl.d.ts +3 -0
  29. package/dist/core/mediaUrl.d.ts.map +1 -0
  30. package/dist/core/outdoorDecoration.d.ts +16 -0
  31. package/dist/core/outdoorDecoration.d.ts.map +1 -0
  32. package/dist/core/publish/index.d.ts +8 -2
  33. package/dist/core/publish/index.d.ts.map +1 -1
  34. package/dist/core/routing/graph-tools.d.ts +28 -2
  35. package/dist/core/routing/graph-tools.d.ts.map +1 -1
  36. package/dist/core/routing/pathfinding.d.ts.map +1 -1
  37. package/dist/core/stacking.d.ts +61 -0
  38. package/dist/core/stacking.d.ts.map +1 -0
  39. package/dist/core/types.d.ts +31 -0
  40. package/dist/core/types.d.ts.map +1 -1
  41. package/dist/editor/MapEditor.d.ts +28 -16
  42. package/dist/editor/MapEditor.d.ts.map +1 -1
  43. package/dist/editor/canvas/EditorCanvas.d.ts +56 -6
  44. package/dist/editor/canvas/EditorCanvas.d.ts.map +1 -1
  45. package/dist/editor/canvas/OutdoorSvgUnderlay.d.ts +7 -0
  46. package/dist/editor/canvas/OutdoorSvgUnderlay.d.ts.map +1 -0
  47. package/dist/editor/canvas/coords.d.ts +51 -0
  48. package/dist/editor/canvas/coords.d.ts.map +1 -0
  49. package/dist/editor/canvas/editorFill.d.ts +10 -0
  50. package/dist/editor/canvas/editorFill.d.ts.map +1 -0
  51. package/dist/editor/canvas/editorHover.d.ts +14 -0
  52. package/dist/editor/canvas/editorHover.d.ts.map +1 -0
  53. package/dist/editor/canvas/underlayHint.d.ts +5 -0
  54. package/dist/editor/canvas/underlayHint.d.ts.map +1 -0
  55. package/dist/editor/connectorAssignments.d.ts +64 -0
  56. package/dist/editor/connectorAssignments.d.ts.map +1 -0
  57. package/dist/editor/draftOps.d.ts +22 -0
  58. package/dist/editor/draftOps.d.ts.map +1 -0
  59. package/dist/editor/editorSectionReturn.d.ts +12 -0
  60. package/dist/editor/editorSectionReturn.d.ts.map +1 -0
  61. package/dist/editor/floorsListReturn.d.ts +5 -0
  62. package/dist/editor/floorsListReturn.d.ts.map +1 -0
  63. package/dist/editor/geometryEdit.d.ts +54 -0
  64. package/dist/editor/geometryEdit.d.ts.map +1 -0
  65. package/dist/editor/hexColor.d.ts +4 -0
  66. package/dist/editor/hexColor.d.ts.map +1 -0
  67. package/dist/editor/history.d.ts +31 -0
  68. package/dist/editor/history.d.ts.map +1 -0
  69. package/dist/editor/index.css +1497 -143
  70. package/dist/editor/index.d.ts +9 -3
  71. package/dist/editor/index.d.ts.map +1 -1
  72. package/dist/editor/index.js +6377 -601
  73. package/dist/editor/index.js.map +1 -1
  74. package/dist/editor/labelText.d.ts +15 -0
  75. package/dist/editor/labelText.d.ts.map +1 -0
  76. package/dist/editor/labels.d.ts +5 -0
  77. package/dist/editor/labels.d.ts.map +1 -0
  78. package/dist/editor/panels/ConnectorAssign.d.ts +12 -0
  79. package/dist/editor/panels/ConnectorAssign.d.ts.map +1 -0
  80. package/dist/editor/panels/FloorsPanel.d.ts +64 -0
  81. package/dist/editor/panels/FloorsPanel.d.ts.map +1 -0
  82. package/dist/editor/panels/ImportReviewPanel.d.ts +22 -0
  83. package/dist/editor/panels/ImportReviewPanel.d.ts.map +1 -0
  84. package/dist/editor/panels/Inspector.d.ts +6 -3
  85. package/dist/editor/panels/Inspector.d.ts.map +1 -1
  86. package/dist/editor/panels/LeftRail.d.ts +26 -11
  87. package/dist/editor/panels/LeftRail.d.ts.map +1 -1
  88. package/dist/editor/panels/PreviewOverlay.d.ts +11 -2
  89. package/dist/editor/panels/PreviewOverlay.d.ts.map +1 -1
  90. package/dist/editor/pathRings.d.ts +79 -0
  91. package/dist/editor/pathRings.d.ts.map +1 -0
  92. package/dist/editor/portalSurface.d.ts +37 -0
  93. package/dist/editor/portalSurface.d.ts.map +1 -0
  94. package/dist/editor/previewDocument.d.ts +9 -0
  95. package/dist/editor/previewDocument.d.ts.map +1 -0
  96. package/dist/editor/railAssignments.d.ts +22 -0
  97. package/dist/editor/railAssignments.d.ts.map +1 -0
  98. package/dist/editor/routeStubs.d.ts +103 -0
  99. package/dist/editor/routeStubs.d.ts.map +1 -0
  100. package/dist/editor/snapPoint.d.ts +5 -0
  101. package/dist/editor/snapPoint.d.ts.map +1 -0
  102. package/dist/editor/splitJoin.d.ts +78 -0
  103. package/dist/editor/splitJoin.d.ts.map +1 -0
  104. package/dist/editor/tools.d.ts +49 -0
  105. package/dist/editor/tools.d.ts.map +1 -0
  106. package/dist/test-maps/shops-at-south-town/BASE - Shops At South Town.ai +26703 -28
  107. package/dist/test-maps/shops-at-south-town/LF - Shops At South Town.ai +4459 -0
  108. package/dist/test-maps/shops-at-south-town/SVG/BASE - Shops At South Town.svg +567 -0
  109. package/dist/test-maps/shops-at-south-town/SVG/LF - Shops At South Town.svg +238 -0
  110. package/dist/test-maps/shops-at-south-town/SVG/UF - Shops At South Town.svg +276 -0
  111. package/dist/test-maps/shops-at-south-town/UF - Shops At South Town.ai +4131 -1
  112. package/dist/ui/ModernSelect.d.ts +14 -0
  113. package/dist/ui/ModernSelect.d.ts.map +1 -0
  114. package/dist/ui/selectSearch.d.ts +9 -0
  115. package/dist/ui/selectSearch.d.ts.map +1 -0
  116. package/dist/viewer/MapViewer.d.ts +14 -3
  117. package/dist/viewer/MapViewer.d.ts.map +1 -1
  118. package/dist/viewer/camera.d.ts +37 -0
  119. package/dist/viewer/camera.d.ts.map +1 -0
  120. package/dist/viewer/components/CameraRig.d.ts +18 -0
  121. package/dist/viewer/components/CameraRig.d.ts.map +1 -0
  122. package/dist/viewer/components/LevelMeshes.d.ts +6 -1
  123. package/dist/viewer/components/LevelMeshes.d.ts.map +1 -1
  124. package/dist/viewer/components/MapScene.d.ts +6 -1
  125. package/dist/viewer/components/MapScene.d.ts.map +1 -1
  126. package/dist/viewer/components/SvgVectorLayer.d.ts +18 -0
  127. package/dist/viewer/components/SvgVectorLayer.d.ts.map +1 -0
  128. package/dist/viewer/index.css +236 -37
  129. package/dist/viewer/index.d.ts +4 -0
  130. package/dist/viewer/index.d.ts.map +1 -1
  131. package/dist/viewer/index.js +9 -4
  132. package/dist/viewer/index.js.map +1 -1
  133. package/dist/viewer/ui/MapControls.d.ts +22 -0
  134. package/dist/viewer/ui/MapControls.d.ts.map +1 -0
  135. package/dist/viewer/ui/RuntimeChrome.d.ts +3 -3
  136. package/dist/viewer/ui/RuntimeChrome.d.ts.map +1 -1
  137. package/package.json +7 -3
  138. package/dist/chunks/pathfinding.js +0 -343
  139. package/dist/chunks/pathfinding.js.map +0 -1
@@ -1,138 +1,170 @@
1
- import { D as x, n as v, d as A, p as k, a as M } from "./pathfinding.js";
2
- function b(i, l, r, s = x) {
3
- const n = i.filter((e) => r.includes(e.id));
4
- if (n.length < 2) return null;
5
- const d = n.reduce((e, u) => u.id < e.id ? u : e), o = [];
6
- for (const e of n)
7
- e.id !== d.id && A(e, d) <= s && o.push(e.id);
8
- if (o.length === 0) return null;
9
- const f = new Set(o), h = [];
10
- for (const e of l) {
11
- let u = !1;
12
- if (f.has(e.fromAnchorId) && (e.fromAnchorId = d.id, u = !0), f.has(e.toAnchorId) && (e.toAnchorId = d.id, u = !0), e.fromAnchorId === e.toAnchorId) {
13
- h.push(e.id);
1
+ import { a3 as M, T as E, R as L, M as $, U as b, ac as R, a as k, d as T, _ as S, v as y, a8 as x, a6 as _ } from "./stacking.js";
2
+ function j(o, u) {
3
+ var t, e, c, a;
4
+ const f = M(o), s = [];
5
+ for (const i of f.elements) {
6
+ if (!i.d || i.interactive || u != null && u.has(i.id) || i.id.toLowerCase().startsWith("route-path") || E(i.id) || L(i.id) || $(i.id) || b(i.id)) continue;
7
+ const n = R(i.id), l = (n == null ? void 0 : n.fill) ?? ((t = i.style) == null ? void 0 : t.fill), p = (n == null ? void 0 : n.stroke) ?? ((e = i.style) == null ? void 0 : e.stroke), I = (n == null ? void 0 : n.strokeWidth) ?? ((c = i.style) == null ? void 0 : c.strokeWidth);
8
+ s.push({
9
+ id: i.id,
10
+ d: i.d,
11
+ fill: l && l !== "none" ? l : void 0,
12
+ stroke: p && p !== "none" ? p : void 0,
13
+ strokeWidth: I,
14
+ opacity: (a = i.style) == null ? void 0 : a.opacity
15
+ });
16
+ }
17
+ return s;
18
+ }
19
+ function C(o, u, f, s = k) {
20
+ const t = o.filter((n) => f.includes(n.id));
21
+ if (t.length < 2) return null;
22
+ const e = t.reduce((n, l) => l.id < n.id ? l : n), c = [];
23
+ for (const n of t)
24
+ n.id !== e.id && y(n, e) <= s && c.push(n.id);
25
+ if (c.length === 0) return null;
26
+ const a = new Set(c), i = [];
27
+ for (const n of u) {
28
+ let l = !1;
29
+ if (a.has(n.fromAnchorId) && (n.fromAnchorId = e.id, l = !0), a.has(n.toAnchorId) && (n.toAnchorId = e.id, l = !0), n.fromAnchorId === n.toAnchorId) {
30
+ i.push(n.id);
14
31
  continue;
15
32
  }
16
- u && h.push(e.id);
33
+ l && i.push(n.id);
17
34
  }
18
35
  return {
19
- survivingAnchorId: d.id,
20
- removedAnchorIds: o,
21
- rewiredEdgeIds: h
36
+ survivingAnchorId: e.id,
37
+ removedAnchorIds: c,
38
+ rewiredEdgeIds: i
22
39
  };
23
40
  }
24
- function E(i, l = x) {
25
- const r = [], s = /* @__PURE__ */ new Set();
26
- for (let n = 0; n < i.length; n++) {
27
- if (s.has(i[n].id)) continue;
28
- const d = [i[n].id];
29
- for (let o = n + 1; o < i.length; o++)
30
- s.has(i[o].id) || i[n].levelId === i[o].levelId && A(i[n], i[o]) <= l && (d.push(i[o].id), s.add(i[o].id));
31
- d.length > 1 && (s.add(i[n].id), r.push(d));
41
+ function F(o, u = k) {
42
+ const f = [], s = /* @__PURE__ */ new Set();
43
+ for (let t = 0; t < o.length; t++) {
44
+ if (s.has(o[t].id)) continue;
45
+ const e = [o[t].id];
46
+ for (let c = t + 1; c < o.length; c++)
47
+ s.has(o[c].id) || o[t].levelId === o[c].levelId && y(o[t], o[c]) <= u && (e.push(o[c].id), s.add(o[c].id));
48
+ e.length > 1 && (s.add(o[t].id), f.push(e));
49
+ }
50
+ return f;
51
+ }
52
+ function K(o, u, f = k) {
53
+ const s = o.slice(), t = u.map((n) => ({ ...n })), e = /* @__PURE__ */ new Set();
54
+ for (const n of F(s, f)) {
55
+ const l = C(s, t, n, f);
56
+ if (l)
57
+ for (const p of l.removedAnchorIds) e.add(p);
58
+ }
59
+ const c = s.filter((n) => !e.has(n.id)), a = /* @__PURE__ */ new Set(), i = [];
60
+ for (const n of t) {
61
+ if (e.has(n.fromAnchorId) || e.has(n.toAnchorId) || n.fromAnchorId === n.toAnchorId) continue;
62
+ const l = Math.min(n.fromAnchorId, n.toAnchorId), p = Math.max(n.fromAnchorId, n.toAnchorId), I = `${l}|${p}`;
63
+ a.has(I) || (a.add(I), i.push(n));
32
64
  }
33
- return r;
65
+ return { anchors: c, edges: i };
34
66
  }
35
- function T(i, l, r, s = x) {
36
- let n = null;
37
- for (const o of l) {
38
- const f = v(i, o);
39
- f && (!n || f.distance < n.distance) && (n = { point: f.point, distance: f.distance });
67
+ function N(o, u, f, s = k) {
68
+ let t = null;
69
+ for (const c of u) {
70
+ const a = S(o, c);
71
+ a && (!t || a.distance < t.distance) && (t = { point: a.point, distance: a.distance });
40
72
  }
41
- if (!n) return null;
42
- const d = r.find(
43
- (o) => o.levelId === i.levelId && A(o, n.point) <= s
73
+ if (!t) return null;
74
+ const e = f.find(
75
+ (c) => c.levelId === o.levelId && y(c, t.point) <= s
44
76
  );
45
77
  return {
46
- unitAnchorId: i.id,
47
- junctionAnchor: d ? { x: d.x, y: d.y, existingId: d.id } : { x: n.point.x, y: n.point.y },
78
+ unitAnchorId: o.id,
79
+ junctionAnchor: e ? { x: e.x, y: e.y, existingId: e.id } : { x: t.point.x, y: t.point.y },
48
80
  edge: {
49
- fromAnchorId: i.id,
50
- toAnchorId: d == null ? void 0 : d.id
81
+ fromAnchorId: o.id,
82
+ toAnchorId: e == null ? void 0 : e.id
51
83
  }
52
84
  };
53
85
  }
54
- function C(i, l, r, s) {
55
- if (r.length === 0) return null;
56
- const n = r.flat();
57
- if (n.length === 0) return null;
58
- let d = 0, o = 0;
59
- for (const e of n)
60
- d += e.x, o += e.y;
61
- const f = { x: d / n.length, y: o / n.length }, h = k(f, r) ? f : n[0];
86
+ function U(o, u, f, s) {
87
+ if (f.length === 0) return null;
88
+ const t = f.flat();
89
+ if (t.length === 0) return null;
90
+ let e = 0, c = 0;
91
+ for (const n of t)
92
+ e += n.x, c += n.y;
93
+ const a = { x: e / t.length, y: c / t.length }, i = x(a, f) ? a : t[0];
62
94
  return {
63
95
  id: s,
64
- levelId: l,
65
- shapeId: i,
96
+ levelId: u,
97
+ shapeId: o,
66
98
  kind: "unit",
67
- x: h.x,
68
- y: h.y,
99
+ x: i.x,
100
+ y: i.y,
69
101
  connectorId: null
70
102
  };
71
103
  }
72
- function j(i, l, r = 20) {
73
- if (i.length === 0)
104
+ function G(o, u, f = 20) {
105
+ if (o.length === 0)
74
106
  return { anchors: [], edges: [] };
75
- let s = 1 / 0, n = 1 / 0, d = -1 / 0, o = -1 / 0;
76
- for (const t of i)
77
- for (const c of t)
78
- s = Math.min(s, c.x), n = Math.min(n, c.y), d = Math.max(d, c.x), o = Math.max(o, c.y);
79
- const f = Math.max(1, Math.ceil((d - s) / r)), h = Math.max(1, Math.ceil((o - n) / r)), e = [];
80
- for (let t = 0; t < h; t++)
81
- for (let c = 0; c < f; c++) {
82
- const g = s + (c + 0.5) * r, I = n + (t + 0.5) * r, m = { x: g, y: I };
83
- k(m, i) && (l.length > 0 && k(m, l) || e.push({ key: `${c},${t}`, x: g, y: I, col: c, row: t }));
107
+ let s = 1 / 0, t = 1 / 0, e = -1 / 0, c = -1 / 0;
108
+ for (const d of o)
109
+ for (const r of d)
110
+ s = Math.min(s, r.x), t = Math.min(t, r.y), e = Math.max(e, r.x), c = Math.max(c, r.y);
111
+ const a = Math.max(1, Math.ceil((e - s) / f)), i = Math.max(1, Math.ceil((c - t) / f)), n = [];
112
+ for (let d = 0; d < i; d++)
113
+ for (let r = 0; r < a; r++) {
114
+ const m = s + (r + 0.5) * f, g = t + (d + 0.5) * f, A = { x: m, y: g };
115
+ x(A, o) && (u.length > 0 && x(A, u) || n.push({ key: `${r},${d}`, x: m, y: g, col: r, row: d }));
84
116
  }
85
- const u = new Map(e.map((t) => [t.key, t])), y = e.map((t) => ({
86
- tempId: t.key,
87
- x: t.x,
88
- y: t.y,
117
+ const l = new Map(n.map((d) => [d.key, d])), p = n.map((d) => ({
118
+ tempId: d.key,
119
+ x: d.x,
120
+ y: d.y,
89
121
  kind: "junction"
90
- })), p = [], a = /* @__PURE__ */ new Set();
91
- for (const t of e) {
92
- const c = [
93
- [t.col + 1, t.row],
94
- [t.col, t.row + 1]
122
+ })), I = [], h = /* @__PURE__ */ new Set();
123
+ for (const d of n) {
124
+ const r = [
125
+ [d.col + 1, d.row],
126
+ [d.col, d.row + 1]
95
127
  ];
96
- for (const [g, I] of c) {
97
- const m = `${g},${I}`;
98
- if (!u.has(m)) continue;
99
- const w = t.key < m ? `${t.key}|${m}` : `${m}|${t.key}`;
100
- a.has(w) || (a.add(w), p.push({ fromTempId: t.key, toTempId: m }));
128
+ for (const [m, g] of r) {
129
+ const A = `${m},${g}`;
130
+ if (!l.has(A)) continue;
131
+ const v = d.key < A ? `${d.key}|${A}` : `${A}|${d.key}`;
132
+ h.has(v) || (h.add(v), I.push({ fromTempId: d.key, toTempId: A }));
101
133
  }
102
134
  }
103
- return { anchors: y, edges: p };
135
+ return { anchors: p, edges: I };
104
136
  }
105
- function D(i, l, r, s, n = x, d) {
106
- const o = [], f = [];
107
- let h = s;
108
- const e = (u, y) => {
109
- const p = o.find(
110
- (t) => A(t, { x: u, y }) <= n
137
+ function X(o, u, f, s, t = k) {
138
+ const e = [], c = [];
139
+ let a = s;
140
+ const i = (l, p) => {
141
+ const I = e.find(
142
+ (d) => y(d, { x: l, y: p }) <= t
111
143
  );
112
- if (p) return p.id;
113
- const a = h++;
114
- return o.push({
115
- id: a,
116
- levelId: l,
144
+ if (I) return I.id;
145
+ const h = a++;
146
+ return e.push({
147
+ id: h,
148
+ levelId: u,
117
149
  shapeId: null,
118
150
  kind: "junction",
119
- x: u,
120
- y,
151
+ x: l,
152
+ y: p,
121
153
  connectorId: null
122
- }), a;
154
+ }), h;
123
155
  };
124
- for (const u of i) {
125
- const y = M(u, d);
126
- for (const p of y)
127
- for (let a = 0; a < p.length - 1; a++) {
128
- const t = e(p[a].x, p[a].y), c = e(p[a + 1].x, p[a + 1].y);
129
- t === c || f.some(
130
- (I) => I.fromAnchorId === t && I.toAnchorId === c || I.fromAnchorId === c && I.toAnchorId === t
131
- ) || f.push({
132
- id: h++,
133
- mapId: r,
134
- fromAnchorId: t,
135
- toAnchorId: c,
156
+ for (const l of o) {
157
+ const p = _(l);
158
+ for (const I of p)
159
+ for (let h = 0; h < I.length - 1; h++) {
160
+ const d = i(I[h].x, I[h].y), r = i(I[h + 1].x, I[h + 1].y);
161
+ d === r || c.some(
162
+ (g) => g.fromAnchorId === d && g.toAnchorId === r || g.fromAnchorId === r && g.toAnchorId === d
163
+ ) || c.push({
164
+ id: a++,
165
+ mapId: f,
166
+ fromAnchorId: d,
167
+ toAnchorId: r,
136
168
  weight: null,
137
169
  directed: !1,
138
170
  accessible: !0,
@@ -140,14 +172,75 @@ function D(i, l, r, s, n = x, d) {
140
172
  });
141
173
  }
142
174
  }
143
- return { anchors: o, edges: f, nextId: h };
175
+ const n = K(e, c, t);
176
+ return { anchors: n.anchors, edges: n.edges, nextId: a };
177
+ }
178
+ function W(o) {
179
+ return o === "entrance" ? "entrance" : o === "connector" ? "connector" : "unit";
180
+ }
181
+ function D(o) {
182
+ return o === "entrance" ? "entrance_link" : "unit_link";
183
+ }
184
+ function P(o, u, f) {
185
+ if (x(o, u)) return "inside";
186
+ for (const s of u) {
187
+ if (s.length < 2) continue;
188
+ const t = [...s, s[0]], e = S(o, t);
189
+ if (e && e.distance <= f) return "near";
190
+ }
191
+ return null;
192
+ }
193
+ function w(o, u, f) {
194
+ if (o.length === 0) return null;
195
+ const s = o.filter((e) => (u.get(e.id) ?? 0) <= 1);
196
+ return [...s.length > 0 ? s : o].sort((e, c) => y(e, f) - y(c, f))[0] ?? null;
197
+ }
198
+ function Y(o, u, f, s = k * 3) {
199
+ const t = /* @__PURE__ */ new Map();
200
+ for (const i of u)
201
+ t.set(i.fromAnchorId, (t.get(i.fromAnchorId) ?? 0) + 1), t.set(i.toAnchorId, (t.get(i.toAnchorId) ?? 0) + 1);
202
+ const e = o.filter((i) => i.shapeId == null), c = /* @__PURE__ */ new Set();
203
+ let a = 0;
204
+ for (const i of f) {
205
+ if (!T.includes(i.kind)) continue;
206
+ const n = i.geometry.polygons ?? [];
207
+ if (n.length === 0) continue;
208
+ const l = e.filter((r) => !c.has(r.id)).map((r) => ({
209
+ anchor: r,
210
+ hit: P(r, n, s)
211
+ })).filter(
212
+ (r) => r.hit != null
213
+ );
214
+ if (l.length === 0) continue;
215
+ const p = n.flat(), I = {
216
+ x: p.reduce((r, m) => r + m.x, 0) / p.length,
217
+ y: p.reduce((r, m) => r + m.y, 0) / p.length
218
+ }, h = w(
219
+ l.filter((r) => r.hit === "inside").map((r) => r.anchor),
220
+ t,
221
+ I
222
+ ) ?? w(
223
+ l.filter((r) => r.hit === "near").map((r) => r.anchor),
224
+ t,
225
+ I
226
+ );
227
+ if (!h || (h.shapeId = i.id, h.kind = W(i.kind), c.add(h.id), a += 1, (t.get(h.id) ?? 0) > 1)) continue;
228
+ const d = D(h.kind);
229
+ for (const r of u)
230
+ (r.fromAnchorId === h.id || r.toAnchorId === h.id) && (r.kind = d);
231
+ }
232
+ return a;
144
233
  }
145
234
  export {
146
- T as a,
147
- j as b,
148
- E as f,
149
- D as i,
150
- C as u,
151
- b as w
235
+ Y as a,
236
+ N as b,
237
+ G as c,
238
+ K as d,
239
+ F as f,
240
+ X as i,
241
+ j as o,
242
+ W as r,
243
+ U as u,
244
+ C as w
152
245
  };
153
246
  //# sourceMappingURL=graph-tools.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"graph-tools.js","sources":["../../src/core/routing/graph-tools.ts"],"sourcesContent":["import type {\n AutoConnectResult,\n CmAnchor,\n CmRouteEdge,\n SkeletonSuggestion,\n Vec2,\n WeldResult,\n} from '../types';\nimport { DEFAULT_WELD_TOLERANCE } from '../types';\nimport {\n distance,\n nearestPointOnPolyline,\n pathToPolygons,\n pointInPolygons,\n} from '../geometry';\n\nexport interface AnchorLike {\n id: number;\n x: number;\n y: number;\n levelId: number;\n shapeId?: number | null;\n kind?: string;\n}\n\nexport interface EdgeLike {\n id: number;\n fromAnchorId: number;\n toAnchorId: number;\n}\n\n/**\n * Weld anchors within tolerance into the surviving (lowest id) anchor.\n * Rewires edges that referenced removed anchors.\n */\nexport function weldAnchors(\n anchors: AnchorLike[],\n edges: EdgeLike[],\n candidateIds: number[],\n tolerance = DEFAULT_WELD_TOLERANCE,\n): WeldResult | null {\n const candidates = anchors.filter((a) => candidateIds.includes(a.id));\n if (candidates.length < 2) return null;\n\n // Cluster by proximity from the first candidate's position centroid of group\n const surviving = candidates.reduce((min, a) => (a.id < min.id ? a : min));\n const removed: number[] = [];\n\n for (const a of candidates) {\n if (a.id === surviving.id) continue;\n if (distance(a, surviving) <= tolerance) {\n removed.push(a.id);\n }\n }\n\n if (removed.length === 0) return null;\n\n const removedSet = new Set(removed);\n const rewired: number[] = [];\n\n for (const edge of edges) {\n let changed = false;\n if (removedSet.has(edge.fromAnchorId)) {\n edge.fromAnchorId = surviving.id;\n changed = true;\n }\n if (removedSet.has(edge.toAnchorId)) {\n edge.toAnchorId = surviving.id;\n changed = true;\n }\n // Drop self-loops\n if (edge.fromAnchorId === edge.toAnchorId) {\n rewired.push(edge.id);\n continue;\n }\n if (changed) rewired.push(edge.id);\n }\n\n return {\n survivingAnchorId: surviving.id,\n removedAnchorIds: removed,\n rewiredEdgeIds: rewired,\n };\n}\n\n/**\n * Find all pairs of anchors within tolerance that should be welded.\n */\nexport function findWeldCandidates(\n anchors: AnchorLike[],\n tolerance = DEFAULT_WELD_TOLERANCE,\n): number[][] {\n const groups: number[][] = [];\n const used = new Set<number>();\n\n for (let i = 0; i < anchors.length; i++) {\n if (used.has(anchors[i].id)) continue;\n const group = [anchors[i].id];\n for (let j = i + 1; j < anchors.length; j++) {\n if (used.has(anchors[j].id)) continue;\n if (\n anchors[i].levelId === anchors[j].levelId &&\n distance(anchors[i], anchors[j]) <= tolerance\n ) {\n group.push(anchors[j].id);\n used.add(anchors[j].id);\n }\n }\n if (group.length > 1) {\n used.add(anchors[i].id);\n groups.push(group);\n }\n }\n return groups;\n}\n\n/**\n * Auto-connect a unit anchor to the nearest walkable segment via perpendicular projection.\n */\nexport function autoConnectUnitAnchor(\n unitAnchor: AnchorLike,\n walkablePolylines: Vec2[][],\n existingJunctions: AnchorLike[],\n weldTolerance = DEFAULT_WELD_TOLERANCE,\n): AutoConnectResult | null {\n let best: { point: Vec2; distance: number } | null = null;\n\n for (const line of walkablePolylines) {\n const hit = nearestPointOnPolyline(unitAnchor, line);\n if (hit && (!best || hit.distance < best.distance)) {\n best = { point: hit.point, distance: hit.distance };\n }\n }\n\n if (!best) return null;\n\n // Reuse existing junction if within weld tolerance\n const existing = existingJunctions.find(\n (j) =>\n j.levelId === unitAnchor.levelId &&\n distance(j, best!.point) <= weldTolerance,\n );\n\n return {\n unitAnchorId: unitAnchor.id,\n junctionAnchor: existing\n ? { x: existing.x, y: existing.y, existingId: existing.id }\n : { x: best.point.x, y: best.point.y },\n edge: {\n fromAnchorId: unitAnchor.id,\n toAnchorId: existing?.id,\n },\n };\n}\n\n/**\n * Place a unit anchor at the centroid of a shape's polygons, if the point lies inside.\n */\nexport function unitAnchorFromShape(\n shapeId: number,\n levelId: number,\n polygons: Vec2[][],\n tempId: number,\n): CmAnchor | null {\n if (polygons.length === 0) return null;\n const flat = polygons.flat();\n if (flat.length === 0) return null;\n\n let sx = 0;\n let sy = 0;\n for (const p of flat) {\n sx += p.x;\n sy += p.y;\n }\n const c = { x: sx / flat.length, y: sy / flat.length };\n\n // Prefer centroid if inside; otherwise use first polygon's average of extremes\n const point = pointInPolygons(c, polygons) ? c : flat[0];\n\n return {\n id: tempId,\n levelId,\n shapeId,\n kind: 'unit',\n x: point.x,\n y: point.y,\n connectorId: null,\n };\n}\n\n/**\n * Build a simple medial-axis-ish skeleton from walkable polygons minus voids.\n * This is a pragmatic approximation: sample a grid inside walkable, reject void cells,\n * connect adjacent free cells into a sparse graph, then prune to a polyline network.\n */\nexport function buildAutoSkeleton(\n walkablePolygons: Vec2[][],\n voidPolygons: Vec2[][],\n cellSize = 20,\n): SkeletonSuggestion {\n if (walkablePolygons.length === 0) {\n return { anchors: [], edges: [] };\n }\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n for (const poly of walkablePolygons) {\n for (const p of poly) {\n minX = Math.min(minX, p.x);\n minY = Math.min(minY, p.y);\n maxX = Math.max(maxX, p.x);\n maxY = Math.max(maxY, p.y);\n }\n }\n\n const cols = Math.max(1, Math.ceil((maxX - minX) / cellSize));\n const rows = Math.max(1, Math.ceil((maxY - minY) / cellSize));\n const free: Array<{ key: string; x: number; y: number; col: number; row: number }> = [];\n\n for (let row = 0; row < rows; row++) {\n for (let col = 0; col < cols; col++) {\n const x = minX + (col + 0.5) * cellSize;\n const y = minY + (row + 0.5) * cellSize;\n const pt = { x, y };\n if (!pointInPolygons(pt, walkablePolygons)) continue;\n if (voidPolygons.length > 0 && pointInPolygons(pt, voidPolygons)) continue;\n free.push({ key: `${col},${row}`, x, y, col, row });\n }\n }\n\n const byKey = new Map(free.map((c) => [c.key, c]));\n const anchors = free.map((c) => ({\n tempId: c.key,\n x: c.x,\n y: c.y,\n kind: 'junction' as const,\n }));\n\n const edges: Array<{ fromTempId: string; toTempId: string }> = [];\n const seen = new Set<string>();\n\n for (const cell of free) {\n const neighbors = [\n [cell.col + 1, cell.row],\n [cell.col, cell.row + 1],\n ];\n for (const [nc, nr] of neighbors) {\n const nk = `${nc},${nr}`;\n if (!byKey.has(nk)) continue;\n const edgeKey = cell.key < nk ? `${cell.key}|${nk}` : `${nk}|${cell.key}`;\n if (seen.has(edgeKey)) continue;\n seen.add(edgeKey);\n edges.push({ fromTempId: cell.key, toTempId: nk });\n }\n }\n\n return { anchors, edges };\n}\n\n/**\n * Convert route-path SVG line endpoints into welded anchors + edges.\n * This is the key converter step that repairs coincident-but-disconnected joins.\n */\nexport function importRoutePaths(\n pathDs: string[],\n levelId: number,\n mapId: number,\n startId: number,\n weldTolerance = DEFAULT_WELD_TOLERANCE,\n viewboxHeight?: number,\n): { anchors: CmAnchor[]; edges: CmRouteEdge[]; nextId: number } {\n const anchors: CmAnchor[] = [];\n const edges: CmRouteEdge[] = [];\n let nextId = startId;\n\n const findOrCreate = (x: number, y: number): number => {\n const existing = anchors.find(\n (a) => distance(a, { x, y }) <= weldTolerance,\n );\n if (existing) return existing.id;\n const id = nextId++;\n anchors.push({\n id,\n levelId,\n shapeId: null,\n kind: 'junction',\n x,\n y,\n connectorId: null,\n });\n return id;\n };\n\n for (const d of pathDs) {\n const polys = pathToPolygons(d, viewboxHeight);\n for (const poly of polys) {\n for (let i = 0; i < poly.length - 1; i++) {\n const a = findOrCreate(poly[i].x, poly[i].y);\n const b = findOrCreate(poly[i + 1].x, poly[i + 1].y);\n if (a === b) continue;\n // Avoid duplicate edges\n const dup = edges.some(\n (e) =>\n (e.fromAnchorId === a && e.toAnchorId === b) ||\n (e.fromAnchorId === b && e.toAnchorId === a),\n );\n if (dup) continue;\n edges.push({\n id: nextId++,\n mapId,\n fromAnchorId: a,\n toAnchorId: b,\n weight: null,\n directed: false,\n accessible: true,\n kind: 'walk',\n });\n }\n }\n }\n\n return { anchors, edges, nextId };\n}\n"],"names":["weldAnchors","anchors","edges","candidateIds","tolerance","DEFAULT_WELD_TOLERANCE","candidates","a","surviving","min","removed","distance","removedSet","rewired","edge","changed","findWeldCandidates","groups","used","i","group","j","autoConnectUnitAnchor","unitAnchor","walkablePolylines","existingJunctions","weldTolerance","best","line","hit","nearestPointOnPolyline","existing","unitAnchorFromShape","shapeId","levelId","polygons","tempId","flat","sx","sy","p","c","point","pointInPolygons","buildAutoSkeleton","walkablePolygons","voidPolygons","cellSize","minX","minY","maxX","maxY","poly","cols","rows","free","row","col","x","y","pt","byKey","seen","cell","neighbors","nc","nr","nk","edgeKey","importRoutePaths","pathDs","mapId","startId","viewboxHeight","nextId","findOrCreate","id","d","polys","pathToPolygons","b","e"],"mappings":";AAmCO,SAASA,EACdC,GACAC,GACAC,G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ecoration.ts","../../src/core/routing/graph-tools.ts"],"sourcesContent":["import {\n parseSvgString,\n isInteractiveGroupLabel,\n isRouteFolderLabel,\n isRoutePathLabel,\n isStoreFolderLabel,\n} from './import';\nimport { resolveLayerStyle } from './layerStyles';\n\nexport interface OutdoorDecorationPath {\n id: string;\n d: string;\n fill?: string;\n stroke?: string;\n strokeWidth?: number;\n opacity?: number;\n}\n\n/**\n * Paths the assign viewer draws from the live outdoor SVG: house-style\n * decoration (green area, parking lanes, icons) and any other\n * non-interactive art. Interactive / store folders stay out — those are\n * `cm_shapes` rows.\n */\nexport function outdoorDecorationFromSvg(\n svgText: string,\n suppressIds?: ReadonlySet<string>,\n): OutdoorDecorationPath[] {\n const parsed = parseSvgString(svgText);\n const out: OutdoorDecorationPath[] = [];\n for (const el of parsed.elements) {\n if (!el.d) continue;\n if (el.interactive) continue;\n if (suppressIds?.has(el.id)) continue;\n if (el.id.toLowerCase().startsWith('route-path')) continue;\n if (isRoutePathLabel(el.id) || isRouteFolderLabel(el.id)) continue;\n if (isInteractiveGroupLabel(el.id) || isStoreFolderLabel(el.id)) continue;\n\n const layer = resolveLayerStyle(el.id);\n const fill = layer?.fill ?? el.style?.fill;\n const stroke = layer?.stroke ?? el.style?.stroke;\n const strokeWidth = layer?.strokeWidth ?? el.style?.strokeWidth;\n out.push({\n id: el.id,\n d: el.d,\n fill: fill && fill !== 'none' ? fill : undefined,\n stroke: stroke && stroke !== 'none' ? stroke : undefined,\n strokeWidth,\n opacity: el.style?.opacity,\n });\n }\n return out;\n}\n","import type {\n AnchorKind,\n AutoConnectResult,\n CmAnchor,\n CmRouteEdge,\n ShapeGeometry,\n ShapeKind,\n SkeletonSuggestion,\n Vec2,\n WeldResult,\n} from '../types';\nimport { DEFAULT_WELD_TOLERANCE, INTERACTIVE_SHAPE_KINDS } from '../types';\nimport {\n distance,\n nearestPointOnPolyline,\n pathToPolygons,\n pointInPolygons,\n} from '../geometry';\n\nexport interface AnchorLike {\n id: number;\n x: number;\n y: number;\n levelId: number;\n shapeId?: number | null;\n kind?: string;\n}\n\nexport interface EdgeLike {\n id: number;\n fromAnchorId: number;\n toAnchorId: number;\n}\n\n/**\n * Weld anchors within tolerance into the surviving (lowest id) anchor.\n * Rewires edges that referenced removed anchors.\n */\nexport function weldAnchors(\n anchors: AnchorLike[],\n edges: EdgeLike[],\n candidateIds: number[],\n tolerance = DEFAULT_WELD_TOLERANCE,\n): WeldResult | null {\n const candidates = anchors.filter((a) => candidateIds.includes(a.id));\n if (candidates.length < 2) return null;\n\n // Cluster by proximity from the first candidate's position centroid of group\n const surviving = candidates.reduce((min, a) => (a.id < min.id ? a : min));\n const removed: number[] = [];\n\n for (const a of candidates) {\n if (a.id === surviving.id) continue;\n if (distance(a, surviving) <= tolerance) {\n removed.push(a.id);\n }\n }\n\n if (removed.length === 0) return null;\n\n const removedSet = new Set(removed);\n const rewired: number[] = [];\n\n for (const edge of edges) {\n let changed = false;\n if (removedSet.has(edge.fromAnchorId)) {\n edge.fromAnchorId = surviving.id;\n changed = true;\n }\n if (removedSet.has(edge.toAnchorId)) {\n edge.toAnchorId = surviving.id;\n changed = true;\n }\n // Drop self-loops\n if (edge.fromAnchorId === edge.toAnchorId) {\n rewired.push(edge.id);\n continue;\n }\n if (changed) rewired.push(edge.id);\n }\n\n return {\n survivingAnchorId: surviving.id,\n removedAnchorIds: removed,\n rewiredEdgeIds: rewired,\n };\n}\n\n/**\n * Find all pairs of anchors within tolerance that should be welded.\n */\nexport function findWeldCandidates(\n anchors: AnchorLike[],\n tolerance = DEFAULT_WELD_TOLERANCE,\n): number[][] {\n const groups: number[][] = [];\n const used = new Set<number>();\n\n for (let i = 0; i < anchors.length; i++) {\n if (used.has(anchors[i].id)) continue;\n const group = [anchors[i].id];\n for (let j = i + 1; j < anchors.length; j++) {\n if (used.has(anchors[j].id)) continue;\n if (\n anchors[i].levelId === anchors[j].levelId &&\n distance(anchors[i], anchors[j]) <= tolerance\n ) {\n group.push(anchors[j].id);\n used.add(anchors[j].id);\n }\n }\n if (group.length > 1) {\n used.add(anchors[i].id);\n groups.push(group);\n }\n }\n return groups;\n}\n\n/**\n * Merge coincident anchors and drop overlapping undirected edges.\n * Two SVG imports of the same ROUTES layer stack a second copy on top of\n * the first — dragging one junction then leaves the twin behind.\n */\nexport function collapseDuplicateRouteGraph<\n A extends AnchorLike,\n E extends EdgeLike,\n>(\n anchors: A[],\n edges: E[],\n tolerance = DEFAULT_WELD_TOLERANCE,\n): { anchors: A[]; edges: E[] } {\n const nextAnchors = anchors.slice();\n const nextEdges = edges.map((edge) => ({ ...edge }));\n const removed = new Set<number>();\n for (const group of findWeldCandidates(nextAnchors, tolerance)) {\n const result = weldAnchors(nextAnchors, nextEdges, group, tolerance);\n if (!result) continue;\n for (const id of result.removedAnchorIds) removed.add(id);\n }\n const alive = nextAnchors.filter((anchor) => !removed.has(anchor.id));\n const seen = new Set<string>();\n const uniqueEdges: E[] = [];\n for (const edge of nextEdges) {\n if (removed.has(edge.fromAnchorId) || removed.has(edge.toAnchorId)) continue;\n if (edge.fromAnchorId === edge.toAnchorId) continue;\n const lo = Math.min(edge.fromAnchorId, edge.toAnchorId);\n const hi = Math.max(edge.fromAnchorId, edge.toAnchorId);\n const key = `${lo}|${hi}`;\n if (seen.has(key)) continue;\n seen.add(key);\n uniqueEdges.push(edge);\n }\n return { anchors: alive, edges: uniqueEdges };\n}\n\n/**\n * Auto-connect a unit anchor to the nearest walkable segment via perpendicular projection.\n */\nexport function autoConnectUnitAnchor(\n unitAnchor: AnchorLike,\n walkablePolylines: Vec2[][],\n existingJunctions: AnchorLike[],\n weldTolerance = DEFAULT_WELD_TOLERANCE,\n): AutoConnectResult | null {\n let best: { point: Vec2; distance: number } | null = null;\n\n for (const line of walkablePolylines) {\n const hit = nearestPointOnPolyline(unitAnchor, line);\n if (hit && (!best || hit.distance < best.distance)) {\n best = { point: hit.point, distance: hit.distance };\n }\n }\n\n if (!best) return null;\n\n // Reuse existing junction if within weld tolerance\n const existing = existingJunctions.find(\n (j) =>\n j.levelId === unitAnchor.levelId &&\n distance(j, best!.point) <= weldTolerance,\n );\n\n return {\n unitAnchorId: unitAnchor.id,\n junctionAnchor: existing\n ? { x: existing.x, y: existing.y, existingId: existing.id }\n : { x: best.point.x, y: best.point.y },\n edge: {\n fromAnchorId: unitAnchor.id,\n toAnchorId: existing?.id,\n },\n };\n}\n\n/**\n * Place a unit anchor at the centroid of a shape's polygons, if the point lies inside.\n */\nexport function unitAnchorFromShape(\n shapeId: number,\n levelId: number,\n polygons: Vec2[][],\n tempId: number,\n): CmAnchor | null {\n if (polygons.length === 0) return null;\n const flat = polygons.flat();\n if (flat.length === 0) return null;\n\n let sx = 0;\n let sy = 0;\n for (const p of flat) {\n sx += p.x;\n sy += p.y;\n }\n const c = { x: sx / flat.length, y: sy / flat.length };\n\n // Prefer centroid if inside; otherwise use first polygon's average of extremes\n const point = pointInPolygons(c, polygons) ? c : flat[0];\n\n return {\n id: tempId,\n levelId,\n shapeId,\n kind: 'unit',\n x: point.x,\n y: point.y,\n connectorId: null,\n };\n}\n\n/**\n * Build a simple medial-axis-ish skeleton from walkable polygons minus voids.\n * This is a pragmatic approximation: sample a grid inside walkable, reject void cells,\n * connect adjacent free cells into a sparse graph, then prune to a polyline network.\n */\nexport function buildAutoSkeleton(\n walkablePolygons: Vec2[][],\n voidPolygons: Vec2[][],\n cellSize = 20,\n): SkeletonSuggestion {\n if (walkablePolygons.length === 0) {\n return { anchors: [], edges: [] };\n }\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n for (const poly of walkablePolygons) {\n for (const p of poly) {\n minX = Math.min(minX, p.x);\n minY = Math.min(minY, p.y);\n maxX = Math.max(maxX, p.x);\n maxY = Math.max(maxY, p.y);\n }\n }\n\n const cols = Math.max(1, Math.ceil((maxX - minX) / cellSize));\n const rows = Math.max(1, Math.ceil((maxY - minY) / cellSize));\n const free: Array<{ key: string; x: number; y: number; col: number; row: number }> = [];\n\n for (let row = 0; row < rows; row++) {\n for (let col = 0; col < cols; col++) {\n const x = minX + (col + 0.5) * cellSize;\n const y = minY + (row + 0.5) * cellSize;\n const pt = { x, y };\n if (!pointInPolygons(pt, walkablePolygons)) continue;\n if (voidPolygons.length > 0 && pointInPolygons(pt, voidPolygons)) continue;\n free.push({ key: `${col},${row}`, x, y, col, row });\n }\n }\n\n const byKey = new Map(free.map((c) => [c.key, c]));\n const anchors = free.map((c) => ({\n tempId: c.key,\n x: c.x,\n y: c.y,\n kind: 'junction' as const,\n }));\n\n const edges: Array<{ fromTempId: string; toTempId: string }> = [];\n const seen = new Set<string>();\n\n for (const cell of free) {\n const neighbors = [\n [cell.col + 1, cell.row],\n [cell.col, cell.row + 1],\n ];\n for (const [nc, nr] of neighbors) {\n const nk = `${nc},${nr}`;\n if (!byKey.has(nk)) continue;\n const edgeKey = cell.key < nk ? `${cell.key}|${nk}` : `${nk}|${cell.key}`;\n if (seen.has(edgeKey)) continue;\n seen.add(edgeKey);\n edges.push({ fromTempId: cell.key, toTempId: nk });\n }\n }\n\n return { anchors, edges };\n}\n\n/**\n * Convert route-path SVG line endpoints into welded anchors + edges.\n * This is the key converter step that repairs coincident-but-disconnected joins.\n *\n * Anchors land in raw SVG user space (Y down), the same space as shape\n * geometry. There is intentionally no viewbox-height flip here — mirroring\n * routes without mirroring shapes would silently desynchronise the two.\n */\nexport function importRoutePaths(\n pathDs: string[],\n levelId: number,\n mapId: number,\n startId: number,\n weldTolerance = DEFAULT_WELD_TOLERANCE,\n): { anchors: CmAnchor[]; edges: CmRouteEdge[]; nextId: number } {\n const anchors: CmAnchor[] = [];\n const edges: CmRouteEdge[] = [];\n let nextId = startId;\n\n const findOrCreate = (x: number, y: number): number => {\n const existing = anchors.find(\n (a) => distance(a, { x, y }) <= weldTolerance,\n );\n if (existing) return existing.id;\n const id = nextId++;\n anchors.push({\n id,\n levelId,\n shapeId: null,\n kind: 'junction',\n x,\n y,\n connectorId: null,\n });\n return id;\n };\n\n for (const d of pathDs) {\n const polys = pathToPolygons(d);\n for (const poly of polys) {\n for (let i = 0; i < poly.length - 1; i++) {\n const a = findOrCreate(poly[i].x, poly[i].y);\n const b = findOrCreate(poly[i + 1].x, poly[i + 1].y);\n if (a === b) continue;\n // Avoid duplicate edges\n const dup = edges.some(\n (e) =>\n (e.fromAnchorId === a && e.toAnchorId === b) ||\n (e.fromAnchorId === b && e.toAnchorId === a),\n );\n if (dup) continue;\n edges.push({\n id: nextId++,\n mapId,\n fromAnchorId: a,\n toAnchorId: b,\n weight: null,\n directed: false,\n accessible: true,\n kind: 'walk',\n });\n }\n }\n }\n\n const collapsed = collapseDuplicateRouteGraph(anchors, edges, weldTolerance);\n return { anchors: collapsed.anchors, edges: collapsed.edges, nextId };\n}\n\nexport function routeAnchorKindForShape(kind: ShapeKind): AnchorKind {\n if (kind === 'entrance') return 'entrance';\n if (kind === 'connector') return 'connector';\n return 'unit';\n}\n\nfunction routeLinkKind(kind: AnchorKind): CmRouteEdge['kind'] {\n return kind === 'entrance' ? 'entrance_link' : 'unit_link';\n}\n\n/** `inside` matches v1's store-mesh hit; `near` is a door-step fallback. */\nfunction pointOnPolygons(\n point: Vec2,\n polygons: Vec2[][],\n tolerance: number,\n): 'inside' | 'near' | null {\n if (pointInPolygons(point, polygons)) return 'inside';\n for (const poly of polygons) {\n if (poly.length < 2) continue;\n const closed = [...poly, poly[0]];\n const hit = nearestPointOnPolyline(point, closed);\n if (hit && hit.distance <= tolerance) return 'near';\n }\n return null;\n}\n\nfunction pickImportedShapeAnchor(\n candidates: CmAnchor[],\n degree: Map<number, number>,\n center: Vec2,\n): CmAnchor | null {\n if (candidates.length === 0) return null;\n const leaves = candidates.filter((anchor) => (degree.get(anchor.id) ?? 0) <= 1);\n const pool = leaves.length > 0 ? leaves : candidates;\n return [...pool].sort((a, b) => distance(a, center) - distance(b, center))[0] ?? null;\n}\n\nexport interface AttachableImportShape {\n id: number;\n kind: ShapeKind;\n geometry: Pick<ShapeGeometry, 'polygons'>;\n}\n\n/**\n * Same rule as v1 `assign_route_nodes_to_stores`: a route vertex that sits\n * inside (or on) an interactive shape is that store / amenity / entrance's\n * destination. Prefer a dedicated spur leaf; otherwise take the closest\n * vertex. Corridor through-points keep `walk` edges so the path stays joined.\n */\nexport function attachImportedRouteAnchors(\n anchors: CmAnchor[],\n edges: CmRouteEdge[],\n shapes: AttachableImportShape[],\n insideTolerance = DEFAULT_WELD_TOLERANCE * 3,\n): number {\n const degree = new Map<number, number>();\n for (const edge of edges) {\n degree.set(edge.fromAnchorId, (degree.get(edge.fromAnchorId) ?? 0) + 1);\n degree.set(edge.toAnchorId, (degree.get(edge.toAnchorId) ?? 0) + 1);\n }\n\n const free = anchors.filter((anchor) => anchor.shapeId == null);\n const used = new Set<number>();\n let attached = 0;\n\n for (const shape of shapes) {\n if (!INTERACTIVE_SHAPE_KINDS.includes(shape.kind)) continue;\n const polys = shape.geometry.polygons ?? [];\n if (polys.length === 0) continue;\n const hits = free\n .filter((anchor) => !used.has(anchor.id))\n .map((anchor) => ({\n anchor,\n hit: pointOnPolygons(anchor, polys, insideTolerance),\n }))\n .filter((row): row is { anchor: CmAnchor; hit: 'inside' | 'near' } =>\n row.hit != null,\n );\n if (hits.length === 0) continue;\n const verts = polys.flat();\n const center = {\n x: verts.reduce((s, p) => s + p.x, 0) / verts.length,\n y: verts.reduce((s, p) => s + p.y, 0) / verts.length,\n };\n const pick =\n pickImportedShapeAnchor(\n hits.filter((row) => row.hit === 'inside').map((row) => row.anchor),\n degree,\n center,\n ) ??\n pickImportedShapeAnchor(\n hits.filter((row) => row.hit === 'near').map((row) => row.anchor),\n degree,\n center,\n );\n if (!pick) continue;\n pick.shapeId = shape.id;\n pick.kind = routeAnchorKindForShape(shape.kind);\n used.add(pick.id);\n attached += 1;\n if ((degree.get(pick.id) ?? 0) > 1) continue;\n const linkKind = routeLinkKind(pick.kind);\n for (const edge of edges) {\n if (edge.fromAnchorId === pick.id || edge.toAnchorId === pick.id) {\n edge.kind = linkKind;\n }\n }\n }\n\n return attached;\n}\n"],"names":["outdoorDecorationFromSvg","svgText","suppressIds","parsed","parseSvgString","out","el","isRoutePathLabel","isRouteFolderLabel","isInteractiveGroupLabel","isStoreFolderLabel","layer","resolveLayerStyle","fill","_a","stroke","_b","strokeWidth","_c","_d","weldAnchors","anchors","edges","candidateIds","tolerance","DEFAULT_WELD_TOLERANCE","candidates","a","surviving","min","removed","distance","removedSet","rewired","edge","changed","findWeldCandidates","groups","used","i","group","j","collapseDuplicateRouteGraph","nextAnchors","nextEdges","result","id","alive","anchor","seen","uniqueEdges","lo","hi","key","autoConnectUnitAnchor","unitAnchor","walkablePolylines","existingJunctions","weldTolerance","best","line","hit","nearestPointOnPolyline","existing","unitAnchorFromShape","shapeId","levelId","polygons","tempId","flat","sx","sy","p","c","point","pointInPolygons","buildAutoSkeleton","walkablePolygons","voidPolygons","cellSize","minX","minY","maxX","maxY","poly","cols","rows","free","row","col","x","y","pt","byKey","cell","neighbors","nc","nr","nk","edgeKey","importRoutePaths","pathDs","mapId","startId","nextId","findOrCreate","d","polys","pathToPolygons","b","e","collapsed","routeAnchorKindForShape","kind","routeLinkKind","pointOnPolygons","closed","pickImportedShapeAnchor","degree","center","leaves","attachImportedRouteAnchors","shapes","insideTolerance","attached","shape","INTERACTIVE_SHAPE_KINDS","hits","verts","s","pick","linkKind"],"mappings":";AAwBO,SAASA,EACdC,GACAC,GACyB;;AACzB,QAAMC,IAASC,EAAeH,CAAO,GAC/BI,IAA+B,CAAA;AACrC,aAAWC,KAAMH,EAAO,UAAU;AAMhC,QALI,CAACG,EAAG,KACJA,EAAG,eACHJ,KAAA,QAAAA,EAAa,IAAII,EAAG,OACpBA,EAAG,GAAG,YAAA,EAAc,WAAW,YAAY,KAC3CC,EAAiBD,EAAG,EAAE,KAAKE,EAAmBF,EAAG,EAAE,KACnDG,EAAwBH,EAAG,EAAE,KAAKI,EAAmBJ,EAAG,EAAE,EAAG;AAEjE,UAAMK,IAAQC,EAAkBN,EA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