@element-editor/adapter-leaflet 0.0.0-stage → 0.2.1

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 (119) hide show
  1. package/AGENTS.md +80 -0
  2. package/LICENSE +21 -0
  3. package/README.md +45 -2
  4. package/dist/ElementEditorControls.d.cts +111 -0
  5. package/dist/ElementEditorControls.d.ts +111 -0
  6. package/dist/adapter-leaflet.css +1 -0
  7. package/dist/components/BoundaryLayer.d.cts +5 -0
  8. package/dist/components/BoundaryLayer.d.ts +5 -0
  9. package/dist/components/DrawingLayer.d.cts +3 -0
  10. package/dist/components/DrawingLayer.d.ts +3 -0
  11. package/dist/components/DrawingPreviewLayer.d.cts +1 -0
  12. package/dist/components/DrawingPreviewLayer.d.ts +1 -0
  13. package/dist/components/FeatureInteractionLayer.d.cts +6 -0
  14. package/dist/components/FeatureInteractionLayer.d.ts +6 -0
  15. package/dist/components/GeometryProcessingPreview.d.cts +1 -0
  16. package/dist/components/GeometryProcessingPreview.d.ts +1 -0
  17. package/dist/components/MeasurePreviewLayer.d.cts +1 -0
  18. package/dist/components/MeasurePreviewLayer.d.ts +1 -0
  19. package/dist/components/MeasurementTooltip.d.cts +1 -0
  20. package/dist/components/MeasurementTooltip.d.ts +1 -0
  21. package/dist/components/PendingPointMarker.d.cts +2 -0
  22. package/dist/components/PendingPointMarker.d.ts +2 -0
  23. package/dist/components/RoutePreviewLayer.d.cts +1 -0
  24. package/dist/components/RoutePreviewLayer.d.ts +1 -0
  25. package/dist/components/SnapController.d.cts +1 -0
  26. package/dist/components/SnapController.d.ts +1 -0
  27. package/dist/components/TextLabelLayer.d.cts +10 -0
  28. package/dist/components/TextLabelLayer.d.ts +10 -0
  29. package/dist/components/TransformControls.d.cts +1 -0
  30. package/dist/components/TransformControls.d.ts +1 -0
  31. package/dist/components/featureLayers/FeatureElements.d.cts +28 -0
  32. package/dist/components/featureLayers/FeatureElements.d.ts +28 -0
  33. package/dist/components/featureLayers/GeometryCollectionLayer.d.cts +13 -0
  34. package/dist/components/featureLayers/GeometryCollectionLayer.d.ts +13 -0
  35. package/dist/components/featureLayers/LineLayer.d.cts +14 -0
  36. package/dist/components/featureLayers/LineLayer.d.ts +14 -0
  37. package/dist/components/featureLayers/MultiLineLayer.d.cts +13 -0
  38. package/dist/components/featureLayers/MultiLineLayer.d.ts +13 -0
  39. package/dist/components/featureLayers/MultiPointLayer.d.cts +12 -0
  40. package/dist/components/featureLayers/MultiPointLayer.d.ts +12 -0
  41. package/dist/components/featureLayers/MultiPolygonLayer.d.cts +13 -0
  42. package/dist/components/featureLayers/MultiPolygonLayer.d.ts +13 -0
  43. package/dist/components/featureLayers/POIMarker.d.cts +13 -0
  44. package/dist/components/featureLayers/POIMarker.d.ts +13 -0
  45. package/dist/components/featureLayers/PolygonLayer.d.cts +14 -0
  46. package/dist/components/featureLayers/PolygonLayer.d.ts +14 -0
  47. package/dist/components/featureLayers/mountQueue.d.cts +41 -0
  48. package/dist/components/featureLayers/mountQueue.d.ts +41 -0
  49. package/dist/components/featureLayers/renderer.d.cts +25 -0
  50. package/dist/components/featureLayers/renderer.d.ts +25 -0
  51. package/dist/components/featureLayers/shared.d.cts +44 -0
  52. package/dist/components/featureLayers/shared.d.ts +44 -0
  53. package/dist/components/featureLayers/useProgressiveMount.d.cts +30 -0
  54. package/dist/components/featureLayers/useProgressiveMount.d.ts +30 -0
  55. package/dist/components/previews/CirclePreview.d.cts +1 -0
  56. package/dist/components/previews/CirclePreview.d.ts +1 -0
  57. package/dist/components/previews/LinePreview.d.cts +1 -0
  58. package/dist/components/previews/LinePreview.d.ts +1 -0
  59. package/dist/components/previews/PolygonPreview.d.cts +1 -0
  60. package/dist/components/previews/PolygonPreview.d.ts +1 -0
  61. package/dist/components/previews/RectPreview.d.cts +1 -0
  62. package/dist/components/previews/RectPreview.d.ts +1 -0
  63. package/dist/components/tools/BoxSelectHandler.d.cts +16 -0
  64. package/dist/components/tools/BoxSelectHandler.d.ts +16 -0
  65. package/dist/components/tools/MapClickHandler.d.cts +6 -0
  66. package/dist/components/tools/MapClickHandler.d.ts +6 -0
  67. package/dist/components/tools/MultiDragHandler.d.cts +9 -0
  68. package/dist/components/tools/MultiDragHandler.d.ts +9 -0
  69. package/dist/components/tools/OsmTraceHandler.d.cts +1 -0
  70. package/dist/components/tools/OsmTraceHandler.d.ts +1 -0
  71. package/dist/components/tools/VertexEditor.d.cts +13 -0
  72. package/dist/components/tools/VertexEditor.d.ts +13 -0
  73. package/dist/contexts/FeatureStyleContext.d.cts +15 -0
  74. package/dist/contexts/FeatureStyleContext.d.ts +15 -0
  75. package/dist/contexts/MapControllerContext.d.cts +2 -0
  76. package/dist/contexts/MapControllerContext.d.ts +2 -0
  77. package/dist/hooks/lastPointer.d.cts +13 -0
  78. package/dist/hooks/lastPointer.d.ts +13 -0
  79. package/dist/hooks/useCursorWhileMode.d.cts +23 -0
  80. package/dist/hooks/useCursorWhileMode.d.ts +23 -0
  81. package/dist/hooks/useDuplicateDrag.d.cts +9 -0
  82. package/dist/hooks/useDuplicateDrag.d.ts +9 -0
  83. package/dist/hooks/useFeatureDrag.d.cts +20 -0
  84. package/dist/hooks/useFeatureDrag.d.ts +20 -0
  85. package/dist/hooks/useMapInteractionMachine.d.cts +13 -0
  86. package/dist/hooks/useMapInteractionMachine.d.ts +13 -0
  87. package/dist/hooks/useModifierDragCursor.d.cts +9 -0
  88. package/dist/hooks/useModifierDragCursor.d.ts +9 -0
  89. package/dist/hooks/usePartDrag.d.cts +23 -0
  90. package/dist/hooks/usePartDrag.d.ts +23 -0
  91. package/dist/index.cjs +52 -0
  92. package/dist/index.d.cts +27 -0
  93. package/dist/index.d.ts +27 -0
  94. package/dist/index.es.js +4246 -0
  95. package/dist/store/StoreContext.d.cts +1 -0
  96. package/dist/store/StoreContext.d.ts +1 -0
  97. package/dist/utils/boxSelect.d.cts +4 -0
  98. package/dist/utils/boxSelect.d.ts +4 -0
  99. package/dist/utils/dragUtils.d.cts +12 -0
  100. package/dist/utils/dragUtils.d.ts +12 -0
  101. package/dist/utils/featureTooltip.d.cts +19 -0
  102. package/dist/utils/featureTooltip.d.ts +19 -0
  103. package/dist/utils/freehandCommitFlag.d.cts +2 -0
  104. package/dist/utils/freehandCommitFlag.d.ts +2 -0
  105. package/dist/utils/freshFeature.d.cts +17 -0
  106. package/dist/utils/freshFeature.d.ts +17 -0
  107. package/dist/utils/geojson.d.cts +3 -0
  108. package/dist/utils/geojson.d.ts +3 -0
  109. package/dist/utils/measureClickFlag.d.cts +2 -0
  110. package/dist/utils/measureClickFlag.d.ts +2 -0
  111. package/dist/utils/modifierDragFlag.d.cts +2 -0
  112. package/dist/utils/modifierDragFlag.d.ts +2 -0
  113. package/dist/utils/pinPath.d.cts +2 -0
  114. package/dist/utils/pinPath.d.ts +2 -0
  115. package/dist/utils/rafThrottle.d.cts +11 -0
  116. package/dist/utils/rafThrottle.d.ts +11 -0
  117. package/dist/utils/snapping.d.cts +25 -0
  118. package/dist/utils/snapping.d.ts +25 -0
  119. package/package.json +98 -3
@@ -0,0 +1,4246 @@
1
+ "use client";
2
+ import En, { useSyncExternalStore as Ho, useRef as $, useCallback as Fe, useEffect as Q, useMemo as _e, useContext as yt, createContext as Ln, memo as Ze, useState as de, startTransition as Bo, useLayoutEffect as $o, forwardRef as uo, useImperativeHandle as Vo } from "react";
3
+ import { useMap as be, useMapEvents as je, Polygon as He, Polyline as ve, Marker as Le, Popup as go, Tooltip as hn } from "react-leaflet";
4
+ import { placeBox as fo, transformUpdates as Xo, getMercatorLatCorrectionRatio as pt, offsetGeometry as Jt, applyVisualTransform as zo, unproject as kn, project as ke, toRadians as ht, mapPositions as po, commitTopoInsert as cn, findTopologicalNeighbors as Go, groupNeighborsByFeature as Yo, commitTopoDelete as yn, vertexEditPatch as bt, insertedPosition as Yn, withXY as zt, applyTopoMove as jn, neighbourPatch as jo, commitTopoMove as Uo, makeCircleCoords as Wo, makeRectCoords as Zo, translateGeometryVisually as We, getPartGeometry as qo, setPartGeometry as Jo, offsetSimpleGeometry as Qo, translateGeometrySpatially as er, canProcessShape as vn, rdp as tr, vertexEditNotice as nr, fitPadding as Dn, createClickRepeatGuard as or, CLICK_TOOL_MODES as rr, CLICK_SLOP_PX as ir, routingError as sr, addPickedFeature as ar, OSM_PICK_MIN_ZOOM as lr, overpassRadiusForZoom as cr, OSM_PICK_OVERLAY_COLORS as xt, isLineGeometryType as ur, normalizeBounds as dr, normalizeFitBoundsTarget as gr, visibleCenterOffset as fr } from "@element-editor/core/internal";
5
+ import { featureLabel as pr, useAccentPalette as ut, useGeoStore as De, useDataStore as Se, useUIStore as K, useEmit as Nt, useIsEventForEditor as Qt, ContextMenu as mr, VertexSelectionBar as hr, FeatureMapContextMenu as yr, useElementEditorConfig as kt, useAccentStyle as vr, useTheme as wr, EventProvider as xr, useAdapterControls as Sr, useKeyboardShortcuts as br, useApplyAccentToRoot as Pr, useReportThemeFromRoot as Cr, preloadEditorPanelsWhenIdle as Mr, useSetMapController as Er } from "@element-editor/ui";
6
+ import { ActiveDrawingToolbar as ia, EditingToolbar as sa, ElementEditorUIProvider as aa, FloatingToolbar as la, GeoStoreProvider as ca, MapControllerProvider as ua, StoreContext as da, useDataStore as ga, useGeoStore as fa, useKeyboardShortcuts as pa, useMapController as ma, useSetMapController as ha, useUIStore as ya } from "@element-editor/ui";
7
+ import { applyRootTokens as Lr, useContextMenu as kr, useRouting as Dr, useServiceAttribution as Ir } from "@element-editor/ui/internal";
8
+ import { getGeometryBBox as In, readAccentPalette as Ar, DEFAULT_FEATURE_COLOR as Te, accentPalette as Rr, getFeatureBBox as mo, fetchRoute as Un, formatLength as Gt, formatArea as An, fetchOverpassFeatures as Fr, overpassErrorMessage as Tr, OverpassError as Or } from "@element-editor/core";
9
+ import { ElementEditorError as wa } from "@element-editor/core";
10
+ import { jsx as w, jsxs as le, Fragment as xe } from "react/jsx-runtime";
11
+ import Xe, { divIcon as Oe, Canvas as Rt, Polygon as Nr, Polyline as _r, marker as Kr, latLng as Hr } from "leaflet";
12
+ import { transformRotate as Br } from "@turf/transform-rotate";
13
+ import { featureCollection as $r, lineString as Tt, polygon as Yt } from "@turf/helpers";
14
+ import { bbox as ho } from "@turf/bbox";
15
+ import Vr from "@turf/boolean-intersects";
16
+ import { Check as yo, Crosshair as Xr, Trash as zr } from "@phosphor-icons/react";
17
+ import { length as ft } from "@turf/length";
18
+ import { area as jt } from "@turf/area";
19
+ import { distance as lt } from "@turf/distance";
20
+ import { createPortal as vo } from "react-dom";
21
+ let Ot = null, Ct = [];
22
+ const wn = /* @__PURE__ */ new Set(), Gr = () => Ot;
23
+ function Rn(t) {
24
+ if (Ct = [], Ot !== t) {
25
+ Ot = t;
26
+ for (const e of wn) e();
27
+ }
28
+ }
29
+ function Yr(t, e, n) {
30
+ Ct = e.filter((o) => o.geometry.type !== "Point" && wo(t, o, n));
31
+ }
32
+ function jr(t, e) {
33
+ Ct.length && (Ct = Ct.filter((n) => wo(t, n, e)));
34
+ }
35
+ function Ur(t) {
36
+ return Ct.some((e) => e.id === t) && Rn(t), Ot === t;
37
+ }
38
+ function Wr(t) {
39
+ return Ho(Zr, () => Ot === t);
40
+ }
41
+ function Zr(t) {
42
+ return wn.add(t), () => {
43
+ wn.delete(t);
44
+ };
45
+ }
46
+ const Kt = 10;
47
+ function wo(t, e, n) {
48
+ const o = e.bbox ?? In(e.geometry), r = t.latLngToContainerPoint([o[1], o[0]]), a = t.latLngToContainerPoint([o[3], o[2]]);
49
+ return n.x >= r.x - Kt && n.x <= a.x + Kt && n.y >= a.y - Kt && n.y <= r.y + Kt;
50
+ }
51
+ let Pe = null, Fn = !1, Tn = null, ot = null, en = 0, tn = 0;
52
+ function On(t) {
53
+ return t.ctrlKey || t.metaKey || t.altKey;
54
+ }
55
+ function xo(t) {
56
+ On(t) && Pe && (Pe.style.display = "none");
57
+ }
58
+ function So(t) {
59
+ On(t) || Fn || Tn && Pe && Pe.textContent && (Pe.style.display = "", Ut(en, tn));
60
+ }
61
+ function bo(t) {
62
+ if (!Pe) return;
63
+ Ut(t.clientX, t.clientY);
64
+ const e = t.target;
65
+ e != null && e.closest(".leaflet-container") || (Pe.style.display = "none");
66
+ }
67
+ function Wn(t) {
68
+ requestAnimationFrame(() => {
69
+ if (ot !== t.target || t.target._map) return;
70
+ const e = document.elementFromPoint(en, tn);
71
+ e != null && e.closest(".leaflet-interactive") || Nn();
72
+ });
73
+ }
74
+ function Ut(t, e) {
75
+ if (en = t, tn = e, !Pe || Pe.style.display === "none") return;
76
+ const { left: n, top: o } = fo(t, e, Pe.offsetWidth, Pe.offsetHeight, { x: "center", y: "before", gapY: 12 });
77
+ Pe.style.left = n + "px", Pe.style.top = o + "px";
78
+ }
79
+ function qr() {
80
+ return Pe || (Pe = document.createElement("div"), Pe.className = "elm-feature-tooltip", Pe.style.cssText = "position:fixed;pointer-events:none;z-index:10000;display:none", document.body.appendChild(Pe), window.addEventListener("keydown", xo), window.addEventListener("keyup", So), document.addEventListener("mousemove", bo, { passive: !0 })), Pe;
81
+ }
82
+ function Po(t) {
83
+ ot !== t && (ot == null || ot.off("remove", Wn), ot = t, ot == null || ot.on("remove", Wn));
84
+ }
85
+ function Nn() {
86
+ Po(null), Tn = null, Pe && (Pe.remove(), Pe = null, window.removeEventListener("keydown", xo), window.removeEventListener("keyup", So), document.removeEventListener("mousemove", bo));
87
+ }
88
+ function Dt(t, e, n, o, r) {
89
+ var s, u;
90
+ if (Fn) return;
91
+ const a = n.getState();
92
+ if (Ur(e.id) || !a.showFeatureNameOnHover || a.vertexEditActive) {
93
+ Nn();
94
+ return;
95
+ }
96
+ const i = pr(e);
97
+ if (!i) return;
98
+ const l = qr();
99
+ l.textContent = i, Lr(l, (u = (s = r == null ? void 0 : r.target) == null ? void 0 : s.closest) == null ? void 0 : u.call(s, "[data-elm-theme]")), Tn = e.id, Po(t), r && Ut(r.clientX, r.clientY), r && On(r) ? l.style.display = "none" : (l.style.display = "", Ut(en, tn));
100
+ }
101
+ function ct(t) {
102
+ t && Rn(null), Nn();
103
+ }
104
+ function Ue(t) {
105
+ Fn = t, t && Pe && (Pe.style.display = "none");
106
+ }
107
+ function Jr(t, e) {
108
+ const n = t.phase;
109
+ return n === e ? t : n === "Idle" && e === "MouseDown" ? { ...t, phase: e } : n === "MouseDown" && (e === "Dragging" || e === "MouseUp") ? { ...t, phase: e } : n === "Dragging" && e === "MouseUp" ? { ...t, phase: e } : n === "MouseUp" && e === "Click" ? { ...t, phase: e } : (n === "Click" || n === "MouseUp") && e === "Idle" ? { ...t, phase: e } : e === "MouseDown" ? { ...t, phase: e } : { ...t, phase: e };
110
+ }
111
+ function Qr(t) {
112
+ const e = be(), n = $({
113
+ phase: "Idle",
114
+ suppressMapClick: !1,
115
+ suppressFeatureClick: !1,
116
+ suppressVertexExit: !1,
117
+ doubleClickGestureSuppressed: !1
118
+ }), o = $(t);
119
+ o.current = t;
120
+ const r = Fe((s) => {
121
+ n.current = Jr(n.current, s);
122
+ }, []), a = Fe((s) => {
123
+ n.current = { ...n.current, ...s };
124
+ }, []), i = Fe(() => {
125
+ n.current.doubleClickGestureSuppressed && a({ doubleClickGestureSuppressed: !1 }), o.current || e.doubleClickZoom.enable();
126
+ }, [e, a]), l = Fe(() => {
127
+ a({ doubleClickGestureSuppressed: !0 }), e.doubleClickZoom.disable(), requestAnimationFrame(i);
128
+ }, [e, i, a]);
129
+ return Q(() => {
130
+ if (t) {
131
+ e.doubleClickZoom.disable();
132
+ return;
133
+ }
134
+ n.current.doubleClickGestureSuppressed || e.doubleClickZoom.enable();
135
+ }, [t, e]), je({
136
+ mousedown: () => {
137
+ r("MouseDown");
138
+ },
139
+ mousemove: () => {
140
+ n.current.phase === "MouseDown" && r("Dragging");
141
+ },
142
+ mouseup: () => {
143
+ const s = n.current;
144
+ (s.phase === "Dragging" || s.phase === "MouseDown") && r("MouseUp");
145
+ },
146
+ click: () => {
147
+ r("Click");
148
+ }
149
+ }), _e(() => ({
150
+ getPhase: () => n.current.phase,
151
+ markDragStart: () => {
152
+ r("Dragging"), Ue(!0);
153
+ },
154
+ markDragEnd: () => {
155
+ r("MouseUp"), a({ suppressMapClick: !0 }), Ue(!1);
156
+ },
157
+ shouldHandleFeatureClick: (s = !1) => s ? !1 : n.current.suppressFeatureClick ? (a({ suppressFeatureClick: !1 }), r("Idle"), !1) : !0,
158
+ markFeatureClick: () => {
159
+ r("Click"), a({ suppressMapClick: !0 });
160
+ },
161
+ shouldHandleMapClick: () => n.current.suppressMapClick ? (a({ suppressMapClick: !1 }), r("Idle"), !1) : !0,
162
+ suppressNextVertexExit: () => {
163
+ a({ suppressVertexExit: !0 });
164
+ },
165
+ shouldHandleVertexExit: () => n.current.suppressVertexExit ? (a({ suppressVertexExit: !1 }), !1) : !0,
166
+ suppressDoubleClickZoomForGesture: l
167
+ }), [r, a, l]);
168
+ }
169
+ const Co = Ln(void 0);
170
+ function Mo({
171
+ getFeatureStyle: t,
172
+ children: e
173
+ }) {
174
+ return /* @__PURE__ */ w(Co.Provider, { value: t, children: e });
175
+ }
176
+ function Eo() {
177
+ return yt(Co);
178
+ }
179
+ let Pt = { x: -1, y: -1, ctrlKey: !1, metaKey: !1, altKey: !1 };
180
+ if (typeof window < "u") {
181
+ window.addEventListener("mousemove", (n) => {
182
+ Pt = { x: n.clientX, y: n.clientY, ctrlKey: n.ctrlKey, metaKey: n.metaKey, altKey: n.altKey };
183
+ }, { capture: !0, passive: !0 });
184
+ const t = (n) => {
185
+ Pt = { x: n.clientX, y: n.clientY, ctrlKey: n.ctrlKey, metaKey: n.metaKey, altKey: n.altKey };
186
+ };
187
+ window.addEventListener("pointerdown", t, { capture: !0, passive: !0 }), window.addEventListener("mousedown", t, { capture: !0, passive: !0 });
188
+ const e = (n) => {
189
+ Pt = { ...Pt, ctrlKey: n.ctrlKey, metaKey: n.metaKey, altKey: n.altKey };
190
+ };
191
+ window.addEventListener("keydown", e, { capture: !0 }), window.addEventListener("keyup", e, { capture: !0 });
192
+ }
193
+ function nn() {
194
+ return Pt;
195
+ }
196
+ function ei(t) {
197
+ var r;
198
+ if (!t) return !1;
199
+ const e = (r = t.getBoundingClientRect) == null ? void 0 : r.call(t);
200
+ if (!e) return !1;
201
+ const { x: n, y: o } = nn();
202
+ return n < 0 || o < 0 ? !1 : n >= e.left && n <= e.right && o >= e.top && o <= e.bottom;
203
+ }
204
+ let St = null;
205
+ function ti(t, e, n = 40) {
206
+ const { x: o, y: r } = Pt;
207
+ if (o < 0 || r < 0) return !1;
208
+ const a = t.getContainer();
209
+ (!St || St.el !== a) && (St = { el: a, rect: a.getBoundingClientRect() }, requestAnimationFrame(() => {
210
+ St = null;
211
+ }));
212
+ const i = t.latLngToContainerPoint(e);
213
+ return Math.abs(St.rect.left + i.x - o) <= n && Math.abs(St.rect.top + i.y - r) <= n;
214
+ }
215
+ function G(t) {
216
+ return [t[1], t[0]];
217
+ }
218
+ function ea(t) {
219
+ return [t[1], t[0]];
220
+ }
221
+ function un(t) {
222
+ const e = t !== "rotate";
223
+ let n = "";
224
+ return t === "nw" || t === "se" ? n = "cursor-nwse-resize" : t === "ne" || t === "sw" ? n = "cursor-nesw-resize" : t === "n" || t === "s" ? n = "cursor-ns-resize" : (t === "e" || t === "w") && (n = "cursor-ew-resize"), Xe.divIcon({
225
+ className: "",
226
+ html: e ? `<div class="w-3 h-3 bg-white border-2 border-primary-600 shadow-md rounded-sm ${n} hover:scale-125 transition-transform"></div>` : `<div class="group relative flex items-center justify-center">
227
+ <div class="w-0.5 h-6 bg-primary-600"></div>
228
+ <div
229
+ class="absolute -top-3 w-4 h-4 bg-white border-2 border-primary-600 shadow-md rounded-full hover:scale-125 transition-transform flex items-center justify-center"
230
+ style="cursor: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImJsYWNrIiBzdHJva2Utd2lkdGg9IjIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCI+PGcgZmlsdGVyPSJkcm9wLXNoYWRvdygwIDAgMXB4IHdoaXRlKSBkcm9wLXNoYWRvdygwIDAgMXB4IHdoaXRlKSI+PHBhdGggZD0iTTIxLjUgMnY2aC02TTIxLjM0IDE1LjU3YTEwIDEwIDAgMSAxLS41OS05LjVsMS4yNSAxLjkzIi8+PC9nPjwvc3ZnPg==') 12 12, grab;"
231
+ >
232
+ <div class="w-1.5 h-1.5 bg-primary-600 rounded-full"></div>
233
+ </div>
234
+ </div>`,
235
+ iconSize: e ? [12, 12] : [16, 32],
236
+ iconAnchor: e ? [6, 6] : [8, 32]
237
+ });
238
+ }
239
+ function dn(t) {
240
+ const e = $r(t), [n, o, r, a] = ho(e), i = (n + r) / 2, l = si(o, a);
241
+ return {
242
+ corners: [
243
+ [n, a],
244
+ [r, a],
245
+ [r, o],
246
+ [n, o]
247
+ ],
248
+ edges: [
249
+ [i, a],
250
+ [r, l],
251
+ [i, o],
252
+ [n, l]
253
+ ],
254
+ // The box centre (rotation pivot, Alt-scale anchor), not the vertex mean.
255
+ center: [i, l],
256
+ rotateHandle: [i, a]
257
+ };
258
+ }
259
+ function gn(t, e, n) {
260
+ const [o, r] = e, a = ht(n), i = Math.cos(a), l = Math.sin(a), s = pt(r);
261
+ return t.map(([u, g]) => {
262
+ const P = (u - o) * s, d = g - r;
263
+ return [
264
+ o + (P * i - d * l) / s,
265
+ r + (P * l + d * i)
266
+ ];
267
+ });
268
+ }
269
+ function ni(t, e, n, o, r) {
270
+ const [a, i] = e, l = ht(r), s = Math.cos(l), u = Math.sin(l), g = pt(i);
271
+ return t.map(([P, d]) => {
272
+ const p = (P - a) * g, C = d - i, M = p * s + C * u, S = -p * u + C * s, m = M * n, y = S * o, x = m * s - y * u, f = m * u + y * s;
273
+ return [a + x / g, i + f];
274
+ });
275
+ }
276
+ function oi(t, e, n, o) {
277
+ const r = ke(e), a = ht(o), i = Math.cos(a), l = Math.sin(a);
278
+ function s(u) {
279
+ const g = ke(u), P = g[0] - r[0], d = g[1] - r[1], p = P * i + d * l, C = -P * l + d * i, M = p * n, S = C * n, m = M * i - S * l, y = M * l + S * i;
280
+ return kn([r[0] + m, r[1] + y]);
281
+ }
282
+ return { ...t, geometry: po(t.geometry, s) };
283
+ }
284
+ function ri(t, e, n, o) {
285
+ const r = ke(e), a = ht(o), i = Math.cos(a), l = Math.sin(a);
286
+ return t.map((s) => {
287
+ const u = ke(s), g = u[0] - r[0], P = u[1] - r[1], d = g * i + P * l, p = -g * l + P * i, C = d * n, M = p * n, S = C * i - M * l, m = C * l + M * i;
288
+ return kn([r[0] + S, r[1] + m]);
289
+ });
290
+ }
291
+ function ii(t, e, n, o, r) {
292
+ const [a, i] = e, l = ht(r), s = Math.cos(l), u = Math.sin(l), g = pt(i);
293
+ function P(d) {
294
+ const p = (d[0] - a) * g, C = d[1] - i, M = p * s + C * u, S = -p * u + C * s, m = M * n, y = S * o, x = m * s - y * u, f = m * u + y * s;
295
+ return [a + x / g, i + f];
296
+ }
297
+ return { ...t, geometry: po(t.geometry, P) };
298
+ }
299
+ function si(t, e) {
300
+ return kn([0, (ke([0, t])[1] + ke([0, e])[1]) / 2])[1];
301
+ }
302
+ function ai(t, e, n, o) {
303
+ const r = o ? t.initialBbox.center : t.origin, a = Math.cos(ht(t.rotationAngle)), i = Math.sin(ht(t.rotationAngle));
304
+ let l;
305
+ if (n) {
306
+ const S = ke(r);
307
+ l = (m) => {
308
+ const y = ke(m), x = y[0] - S[0], f = y[1] - S[1];
309
+ return [x * a + f * i, -x * i + f * a];
310
+ };
311
+ } else {
312
+ const S = pt(r[1]);
313
+ l = (m) => {
314
+ const y = (m[0] - r[0]) * S, x = m[1] - r[1];
315
+ return [y * a + x * i, -y * i + x * a];
316
+ };
317
+ }
318
+ const [s, u] = l(t.startLngLat), [g, P] = l(e), d = t.edgeIndex === 0 || t.edgeIndex === 2, p = t.edgeIndex === 1 || t.edgeIndex === 3, C = (S) => Math.abs(S) < 0.01 ? S < 0 ? -0.01 : 0.01 : S, M = (S, m) => Math.abs(m) > 1e-9 ? S / m : 1;
319
+ if (n) {
320
+ let S;
321
+ if (d) S = M(P, u);
322
+ else if (p) S = M(g, s);
323
+ else {
324
+ const m = s * s + u * u;
325
+ S = m > 1e-18 ? (g * s + P * u) / m : 1;
326
+ }
327
+ return { origin: r, uniform: !0, factor: C(S) };
328
+ }
329
+ return {
330
+ origin: r,
331
+ uniform: !1,
332
+ scaleX: p || !d ? C(M(g, s)) : 1,
333
+ scaleY: d || !p ? C(M(P, u)) : 1
334
+ };
335
+ }
336
+ function li(t, e, n, o) {
337
+ const r = n.uniform ? (a) => ri(a, n.origin, n.factor, o) : (a) => ni(a, n.origin, n.scaleX, n.scaleY, o);
338
+ return {
339
+ features: t.map((a) => n.uniform ? oi(a, n.origin, n.factor, o) : ii(a, n.origin, n.scaleX, n.scaleY, o)),
340
+ box: {
341
+ corners: r(e.corners),
342
+ edges: r(e.edges),
343
+ center: r([e.center])[0],
344
+ rotateHandle: r([e.rotateHandle])[0]
345
+ }
346
+ };
347
+ }
348
+ function ci(t, e, n) {
349
+ if (!n) return [e[0] - t[0], e[1] - t[1]];
350
+ const o = ke(t), r = ke(e);
351
+ return [r[0] - o[0], r[1] - o[1]];
352
+ }
353
+ function Ht(t, e, n) {
354
+ return Jt({ type: "MultiPoint", coordinates: t }, e, n).coordinates;
355
+ }
356
+ function ui(t, e, n) {
357
+ let o = !1;
358
+ for (let r = 0, a = e.length - 1; r < e.length; a = r++) {
359
+ const i = e[r], l = e[a];
360
+ if (i.y > t.y != l.y > t.y && t.x < (l.x - i.x) * (t.y - i.y) / (l.y - i.y) + i.x && (o = !o), Xe.LineUtil.pointToSegmentDistance(t, i, l) <= n) return !0;
361
+ }
362
+ return o;
363
+ }
364
+ const di = 3, gi = 8, fi = Ze(function() {
365
+ const e = be(), n = ut(e.getContainer())[500], { dataStore: o, uiStore: r } = De(), a = Se((R) => R.selectedIds), i = Se((R) => R.features), l = K((R) => R.transformActive), s = K((R) => R.setTransformDragging), [u, g] = de(null), [P, d] = de(null), p = $(null), C = $(null);
366
+ p.current = u, C.current = P;
367
+ const [M, S] = de(null), m = $(0), y = a.join(",");
368
+ Q(() => {
369
+ S(null), m.current = 0;
370
+ }, [y]);
371
+ const x = $(null), f = Fe((R) => {
372
+ const c = e.getContainer().getBoundingClientRect();
373
+ return e.containerPointToLatLng(Xe.point(R.clientX - c.left, R.clientY - c.top));
374
+ }, [e]);
375
+ Q(() => {
376
+ let R = null;
377
+ function c(j) {
378
+ x.current && (j.preventDefault(), R = { clientX: j.clientX, clientY: j.clientY }, B(j));
379
+ }
380
+ function E(j) {
381
+ var ce;
382
+ j.key !== "Shift" && j.key !== "Alt" || ((ce = x.current) == null ? void 0 : ce.type) !== "scale" || !R || (j.preventDefault(), B({ ...R, shiftKey: j.shiftKey, altKey: j.altKey }));
383
+ }
384
+ function B(j) {
385
+ if (!x.current) return;
386
+ const ce = f(j), te = ce.lat, ue = ce.lng, X = x.current, v = o.getState().geometryMode;
387
+ if (X.type === "move") {
388
+ if (!X.moving) {
389
+ const q = e.getContainer().getBoundingClientRect();
390
+ if (X.startPoint.distanceTo(Xe.point(j.clientX - q.left, j.clientY - q.top)) < di) return;
391
+ X.moving = !0, s(!0);
392
+ }
393
+ const U = v === "visual", ee = ci(X.startLatLng, [ue, te], U);
394
+ g(X.initialFeatures.map((q) => ({ ...q, geometry: Jt(q.geometry, ee, U) }))), d({
395
+ corners: Ht(X.initialBbox.corners, ee, U),
396
+ edges: Ht(X.initialBbox.edges, ee, U),
397
+ center: Ht([X.initialBbox.center], ee, U)[0],
398
+ rotateHandle: Ht([X.initialBbox.rotateHandle], ee, U)[0]
399
+ });
400
+ } else if (X.type === "rotate") {
401
+ const U = pt(X.center[1]), ee = te - X.center[1], q = v === "visual" ? (ue - X.center[0]) * U : ue - X.center[0], ne = (Math.atan2(ee, q) - X.initialAngle) * (180 / Math.PI), fe = X.initialFeatures.map(
402
+ (we) => v === "visual" ? zo(we, X.center, 1, 1, ne) : Br(we, ne, { pivot: X.center })
403
+ );
404
+ g(fe);
405
+ const W = X.center;
406
+ d({
407
+ corners: gn(X.initialBbox.corners, W, ne),
408
+ edges: gn(X.initialBbox.edges, W, ne),
409
+ center: W,
410
+ rotateHandle: gn([X.initialBbox.rotateHandle], W, ne)[0]
411
+ });
412
+ } else if (X.type === "scale") {
413
+ const U = X.rotationAngle, ee = ai({
414
+ initialBbox: X.initialBbox,
415
+ origin: X.origin,
416
+ startLngLat: X.startLatLng,
417
+ edgeIndex: X.edgeIndex,
418
+ rotationAngle: U
419
+ }, [ue, te], j.shiftKey, j.altKey), q = li(X.initialFeatures, X.initialBbox, ee, U);
420
+ g(q.features), d(q.box);
421
+ }
422
+ }
423
+ function J() {
424
+ if (!x.current) return;
425
+ const j = p.current, ce = C.current, te = x.current.type === "rotate", ue = x.current.type === "move";
426
+ if (x.current.rotationAngle, x.current = null, e.dragging.enable(), s(!1), !ue || j) {
427
+ const X = e.getContainer(), v = (U) => U.stopPropagation();
428
+ X.addEventListener("click", v, !0), setTimeout(() => X.removeEventListener("click", v, !0), 0);
429
+ }
430
+ if (j && (o.getState().takeSnapshot(), o.getState().updateFeatures(Xo(
431
+ o.getState().features,
432
+ j.map((X) => ({ id: String(X.id), geometry: X.geometry })),
433
+ r.getState().topoEditEnabled
434
+ ))), ce && (S(ce), te)) {
435
+ const X = ce.center, v = ce.edges[1], U = pt(X[1]), ee = (v[0] - X[0]) * U, q = v[1] - X[1];
436
+ m.current = Math.atan2(q, ee) * (180 / Math.PI);
437
+ }
438
+ g(null), d(null), R = null;
439
+ }
440
+ return document.addEventListener("mousemove", c), document.addEventListener("mouseup", J), document.addEventListener("keydown", E), document.addEventListener("keyup", E), () => {
441
+ document.removeEventListener("mousemove", c), document.removeEventListener("mouseup", J), document.removeEventListener("keydown", E), document.removeEventListener("keyup", E);
442
+ };
443
+ }, [e, f, s]);
444
+ const h = $(null);
445
+ if (h.current = null, je({
446
+ mousedown(R) {
447
+ var j, ce;
448
+ const c = h.current, E = R.originalEvent;
449
+ if (!c || x.current || E.button !== 0 || E.shiftKey || E.altKey || E.ctrlKey || E.metaKey) return;
450
+ const B = r.getState();
451
+ if (B.readonly || B.editingMode !== "none" || B.vertexEditActive || (ce = (j = E.target) == null ? void 0 : j.closest) != null && ce.call(j, ".leaflet-marker-icon")) return;
452
+ const J = c.box.corners.map((te) => e.latLngToContainerPoint(G(te)));
453
+ ui(R.containerPoint, J, gi) && (E.preventDefault(), e.dragging.disable(), x.current = {
454
+ type: "move",
455
+ initialFeatures: structuredClone(c.features),
456
+ initialBbox: c.box,
457
+ rotationAngle: m.current,
458
+ startLatLng: [R.latlng.lng, R.latlng.lat],
459
+ startPoint: R.containerPoint,
460
+ moving: !1
461
+ });
462
+ }
463
+ }), !l || a.length === 0) return null;
464
+ const I = new Set(a), z = i.filter((R) => I.has(R.id));
465
+ if (z.length === 0) return null;
466
+ const k = P || M || dn(z);
467
+ P || (h.current = { box: k, features: z });
468
+ const { corners: H, edges: D, rotateHandle: _ } = k, F = [...H, H[0]].map(G);
469
+ function Y(R) {
470
+ var c, E, B, J;
471
+ (E = (c = R.originalEvent) == null ? void 0 : c.preventDefault) == null || E.call(c), (J = (B = R.originalEvent) == null ? void 0 : B.stopPropagation) == null || J.call(B), e.dragging.disable();
472
+ }
473
+ function L(R) {
474
+ Y(R);
475
+ const c = M || dn(z), E = c.center, B = f(R.originalEvent), J = o.getState().geometryMode, j = pt(E[1]), ce = B.lat - E[1], te = J === "visual" ? (B.lng - E[0]) * j : B.lng - E[0];
476
+ x.current = {
477
+ type: "rotate",
478
+ initialFeatures: structuredClone(z),
479
+ initialBbox: c,
480
+ rotationAngle: m.current,
481
+ center: E,
482
+ initialAngle: Math.atan2(ce, te)
483
+ }, s(!0);
484
+ }
485
+ function V(R, c, E) {
486
+ Y(R);
487
+ const B = M || dn(z), J = f(R.originalEvent), j = E ? B.edges[(c + 2) % 4] : B.corners[(c + 2) % 4];
488
+ x.current = {
489
+ type: "scale",
490
+ initialFeatures: structuredClone(z),
491
+ initialBbox: B,
492
+ rotationAngle: m.current,
493
+ origin: j,
494
+ startLatLng: [J.lng, J.lat],
495
+ edgeIndex: E ? c : void 0
496
+ }, s(!0);
497
+ }
498
+ return /* @__PURE__ */ le(xe, { children: [
499
+ u == null ? void 0 : u.map((R) => R.geometry.type === "Polygon" ? /* @__PURE__ */ w(
500
+ He,
501
+ {
502
+ positions: R.geometry.coordinates.map((c) => c.map(G)),
503
+ pathOptions: { color: n, weight: 2, fillOpacity: 0.1, dashArray: "5 5" },
504
+ interactive: !1
505
+ },
506
+ R.id
507
+ ) : R.geometry.type === "MultiPolygon" ? /* @__PURE__ */ w(
508
+ He,
509
+ {
510
+ positions: R.geometry.coordinates.map((c) => c.map((E) => E.map(G))),
511
+ pathOptions: { color: n, weight: 2, fillOpacity: 0.1, dashArray: "5 5" },
512
+ interactive: !1
513
+ },
514
+ R.id
515
+ ) : R.geometry.type === "LineString" ? /* @__PURE__ */ w(
516
+ ve,
517
+ {
518
+ positions: R.geometry.coordinates.map(G),
519
+ pathOptions: { color: n, weight: 2, dashArray: "5 5" },
520
+ interactive: !1
521
+ },
522
+ R.id
523
+ ) : R.geometry.type === "MultiLineString" ? /* @__PURE__ */ w(
524
+ ve,
525
+ {
526
+ positions: R.geometry.coordinates.map((c) => c.map(G)),
527
+ pathOptions: { color: n, weight: 2, dashArray: "5 5" },
528
+ interactive: !1
529
+ },
530
+ R.id
531
+ ) : null),
532
+ /* @__PURE__ */ w(
533
+ ve,
534
+ {
535
+ positions: F,
536
+ pathOptions: { color: n, weight: 1.5, dashArray: "4 4", fill: !1 },
537
+ interactive: !1
538
+ }
539
+ ),
540
+ H.map((R, c) => /* @__PURE__ */ w(
541
+ Le,
542
+ {
543
+ position: G(R),
544
+ icon: un(["nw", "ne", "se", "sw"][c]),
545
+ draggable: !1,
546
+ eventHandlers: { mousedown: (E) => V(E, c, !1) }
547
+ },
548
+ `corner-${c}`
549
+ )),
550
+ D.map((R, c) => /* @__PURE__ */ w(
551
+ Le,
552
+ {
553
+ position: G(R),
554
+ icon: un(["n", "e", "s", "w"][c]),
555
+ draggable: !1,
556
+ eventHandlers: { mousedown: (E) => V(E, c, !0) }
557
+ },
558
+ `edge-${c}`
559
+ )),
560
+ /* @__PURE__ */ w(
561
+ Le,
562
+ {
563
+ position: G(_),
564
+ icon: un("rotate"),
565
+ draggable: !1,
566
+ eventHandlers: { mousedown: (R) => L(R) }
567
+ }
568
+ )
569
+ ] });
570
+ });
571
+ function pi([t, e, n, o], r, a, i, l) {
572
+ return t >= r && n <= i && e >= a && o <= l;
573
+ }
574
+ function mi(t, e) {
575
+ if (t === e) return !0;
576
+ if (t.length !== e.length) return !1;
577
+ const n = new Set(t);
578
+ return e.every((o) => n.has(o));
579
+ }
580
+ function hi({ onSelect: t, onDragStart: e, readonly: n, getInitialVertexIndices: o, onVertexBoxPreview: r }) {
581
+ const { dataStore: a } = De(), i = be(), l = K((M) => M.editingMode), s = K((M) => M.transformActive), u = K((M) => M.vertexEditActive), g = Se((M) => M.setSelection), P = $(l), d = $(s), p = $(u), C = $(g);
582
+ return P.current = l, d.current = s, p.current = u, C.current = g, Q(() => (i.boxZoom.disable(), () => {
583
+ i.boxZoom.enable();
584
+ }), [i]), je({
585
+ mousedown(M) {
586
+ var V, R;
587
+ if (!M.originalEvent.shiftKey || n || d.current) return;
588
+ const S = p.current;
589
+ if (!S && P.current !== "none") return;
590
+ const m = M.originalEvent.clientX, y = M.originalEvent.clientY;
591
+ let x = !1, f = null;
592
+ const h = [...a.getState().selectedIds];
593
+ let I = 0;
594
+ const z = S ? new Set((o == null ? void 0 : o()) ?? []) : null;
595
+ let k = 0;
596
+ function H(c) {
597
+ const E = i.getContainer().getBoundingClientRect(), B = Math.min(m, c.clientX) - E.left, J = Math.min(y, c.clientY) - E.top, j = Math.max(m, c.clientX) - E.left, ce = Math.max(y, c.clientY) - E.top, te = i.containerPointToLatLng([B, J]), ue = i.containerPointToLatLng([j, ce]);
598
+ return {
599
+ latMin: Math.min(te.lat, ue.lat),
600
+ latMax: Math.max(te.lat, ue.lat),
601
+ lngMin: Math.min(te.lng, ue.lng),
602
+ lngMax: Math.max(te.lng, ue.lng)
603
+ };
604
+ }
605
+ function D(c) {
606
+ const E = a.getState().selectedIds[0];
607
+ if (!E) return null;
608
+ const B = a.getState().features.find((v) => v.id === E);
609
+ if (!B) return null;
610
+ let J;
611
+ if (B.geometry.type === "LineString")
612
+ J = B.geometry.coordinates;
613
+ else if (B.geometry.type === "Polygon")
614
+ J = B.geometry.coordinates[0].slice(0, -1);
615
+ else
616
+ return null;
617
+ const { latMin: j, latMax: ce, lngMin: te, lngMax: ue } = H(c), X = [];
618
+ for (let v = 0; v < J.length; v++) {
619
+ const [U, ee] = J[v];
620
+ U >= te && U <= ue && ee >= j && ee <= ce && X.push(v);
621
+ }
622
+ return { id: E, indices: X };
623
+ }
624
+ function _(c) {
625
+ const E = i.getContainer().getBoundingClientRect(), B = Math.min(m, c.clientX) - E.left, J = Math.min(y, c.clientY) - E.top, j = Math.max(m, c.clientX) - E.left, ce = Math.max(y, c.clientY) - E.top, te = i.containerPointToLatLng([B, J]), ue = i.containerPointToLatLng([j, ce]), X = Math.min(te.lat, ue.lat), v = Math.max(te.lat, ue.lat), U = Math.min(te.lng, ue.lng), ee = Math.max(te.lng, ue.lng), q = a.getState(), ge = new Set(q.groups.filter((he) => he.hidden).map((he) => he.id)), ne = q.features.filter((he) => !he.groupId || !ge.has(he.groupId)), fe = {
626
+ type: "Feature",
627
+ properties: {},
628
+ geometry: {
629
+ type: "Polygon",
630
+ coordinates: [[
631
+ [U, X],
632
+ [ee, X],
633
+ [ee, v],
634
+ [U, v],
635
+ [U, X]
636
+ ]]
637
+ }
638
+ }, W = [];
639
+ for (const he of ne)
640
+ if (he.geometry.type === "Point") {
641
+ const [Ie, Be] = he.geometry.coordinates;
642
+ Ie >= U && Ie <= ee && Be >= X && Be <= v && W.push(he.id);
643
+ } else {
644
+ const Ie = he.bbox || In(he.geometry), [Be, ze, re, Me] = Ie;
645
+ if (Be <= ee && re >= U && ze <= v && Me >= X) {
646
+ if (pi(Ie, U, X, ee, v)) {
647
+ W.push(he.id);
648
+ continue;
649
+ }
650
+ try {
651
+ Vr(fe, he) && W.push(he.id);
652
+ } catch {
653
+ W.push(he.id);
654
+ }
655
+ }
656
+ }
657
+ let we = h;
658
+ if (W.length > 0) {
659
+ const he = new Set(h);
660
+ W.forEach((Ie) => he.add(Ie)), we = Array.from(he);
661
+ }
662
+ mi(q.selectedIds, we) && q.selectedGroupId === null || Bo(() => {
663
+ C.current(we);
664
+ });
665
+ }
666
+ function F(c) {
667
+ var J;
668
+ const E = Math.abs(c.clientX - m), B = Math.abs(c.clientY - y);
669
+ if (!(!x && E < 5 && B < 5)) {
670
+ if (!x) {
671
+ x = !0, e(), i.dragging.disable(), document.body.style.userSelect = "none", (J = window.getSelection()) == null || J.removeAllRanges(), f = document.createElement("div");
672
+ const j = Ar(i.getContainer())[500];
673
+ f.style.cssText = [
674
+ "position:fixed",
675
+ // Body-level and outside the scoped preflight — size by the border box explicitly.
676
+ "box-sizing:border-box",
677
+ `left:${m}px`,
678
+ `top:${y}px`,
679
+ "width:0",
680
+ "height:0",
681
+ `border:2px dashed ${j}`,
682
+ `background:color-mix(in srgb, ${j} 8%, transparent)`,
683
+ "pointer-events:none",
684
+ "z-index:10000"
685
+ ].join(";"), document.body.appendChild(f);
686
+ }
687
+ if (f) {
688
+ const j = Math.min(m, c.clientX), ce = Math.min(y, c.clientY);
689
+ f.style.left = `${j}px`, f.style.top = `${ce}px`, f.style.width = `${Math.abs(c.clientX - m)}px`, f.style.height = `${Math.abs(c.clientY - y)}px`;
690
+ }
691
+ if (!S && Date.now() - I > 30 && (_(c), I = Date.now()), S && r && Date.now() - k > 30) {
692
+ const j = D(c);
693
+ if (j) {
694
+ const ce = new Set(z ?? []);
695
+ for (const te of j.indices) ce.add(te);
696
+ r(j.id, [...ce].sort((te, ue) => te - ue));
697
+ }
698
+ k = Date.now();
699
+ }
700
+ }
701
+ }
702
+ function Y(c) {
703
+ var j, ce;
704
+ const E = ((ce = (j = document.querySelector(".leaflet-container")) == null ? void 0 : j.ownerDocument) == null ? void 0 : ce.defaultView) || window;
705
+ if (E.removeEventListener("mousemove", F), E.removeEventListener("mouseup", Y), !x) return;
706
+ if (i.dragging.enable(), document.body.style.userSelect = "", f && document.body.removeChild(f), S) {
707
+ const te = D(c);
708
+ if (te) {
709
+ const ue = new Set(z ?? []);
710
+ for (const v of te.indices) ue.add(v);
711
+ const X = [...ue].sort((v, U) => v - U);
712
+ X.length > 0 && t(te.id, X);
713
+ }
714
+ return;
715
+ }
716
+ if (_(c), !(a.getState().selectedIds.length > h.length)) {
717
+ const te = i.getContainer().getBoundingClientRect(), ue = Math.min(m, c.clientX) - te.left, X = Math.min(y, c.clientY) - te.top, v = Math.max(m, c.clientX) - te.left, U = Math.max(y, c.clientY) - te.top, ee = i.containerPointToLatLng([ue, X]), q = i.containerPointToLatLng([v, U]), ge = Math.min(ee.lat, q.lat), ne = Math.max(ee.lat, q.lat), fe = Math.min(ee.lng, q.lng), W = Math.max(ee.lng, q.lng), we = a.getState(), he = new Set(we.groups.filter((re) => re.hidden).map((re) => re.id)), Ie = we.features.filter((re) => !re.groupId || !he.has(re.groupId));
718
+ let Be = null, ze = [];
719
+ for (const re of Ie) {
720
+ if (!we.selectedIds.includes(re.id)) continue;
721
+ let Me;
722
+ if (re.geometry.type === "LineString")
723
+ Me = re.geometry.coordinates;
724
+ else if (re.geometry.type === "Polygon")
725
+ Me = re.geometry.coordinates[0].slice(0, -1);
726
+ else
727
+ continue;
728
+ const $e = Me.reduce((rt, [it, wt], T) => (it >= fe && it <= W && wt >= ge && wt <= ne && rt.push(T), rt), []);
729
+ $e.length > ze.length && (Be = re.id, ze = $e);
730
+ }
731
+ Be && ze.length > 0 && t(Be, ze);
732
+ }
733
+ }
734
+ const L = ((R = (V = document.querySelector(".leaflet-container")) == null ? void 0 : V.ownerDocument) == null ? void 0 : R.defaultView) || window;
735
+ L.addEventListener("mousemove", F), L.addEventListener("mouseup", Y);
736
+ }
737
+ }), null;
738
+ }
739
+ function xn(t, e) {
740
+ return Math.hypot(t.x - e.x, t.y - e.y);
741
+ }
742
+ function yi(t, e, n) {
743
+ const o = (e.x - n.x) ** 2 + (e.y - n.y) ** 2;
744
+ if (o === 0) return { distance: xn(t, e), closest: e };
745
+ let r = ((t.x - e.x) * (n.x - e.x) + (t.y - e.y) * (n.y - e.y)) / o;
746
+ r = Math.max(0, Math.min(1, r));
747
+ const a = { x: e.x + r * (n.x - e.x), y: e.y + r * (n.y - e.y) };
748
+ return { distance: xn(t, a), closest: a };
749
+ }
750
+ function Sn(t, e, n, o, r = 15, a = /* @__PURE__ */ new Set()) {
751
+ const i = n.latLngToLayerPoint([e, t]);
752
+ let l = 1 / 0, s = null, u = 1 / 0, g = null;
753
+ const P = r + 1, d = n.layerPointToLatLng([i.x - P, i.y - P]), p = n.layerPointToLatLng([i.x + P, i.y + P]), C = Math.min(d.lng, p.lng), M = Math.max(d.lng, p.lng), S = Math.min(d.lat, p.lat), m = Math.max(d.lat, p.lat), y = (h) => h[0] < C || h[0] > M || h[1] < S || h[1] > m;
754
+ function x(h, I = !0) {
755
+ if (!h || h.length === 0) return;
756
+ let z = -1, k = null;
757
+ const H = (D) => {
758
+ if (D === z) return k;
759
+ const _ = h[D];
760
+ return n.latLngToLayerPoint([_[1], _[0]]);
761
+ };
762
+ for (let D = 0; D < h.length; D++) {
763
+ const _ = h[D], F = y(_);
764
+ let Y = null;
765
+ if (!F) {
766
+ Y = H(D);
767
+ const L = xn(i, Y);
768
+ L < l && (l = L, s = _);
769
+ }
770
+ if (I && D < h.length - 1) {
771
+ const L = h[D + 1];
772
+ if (_[0] < C && L[0] < C || _[0] > M && L[0] > M || _[1] < S && L[1] < S || _[1] > m && L[1] > m) continue;
773
+ const V = Y ?? H(D), R = n.latLngToLayerPoint([L[1], L[0]]);
774
+ z = D + 1, k = R;
775
+ const { distance: c, closest: E } = yi(i, V, R);
776
+ c < u && (u = c, g = E);
777
+ }
778
+ }
779
+ }
780
+ function f(h) {
781
+ switch (h.type) {
782
+ case "Point":
783
+ x([h.coordinates]);
784
+ break;
785
+ case "MultiPoint":
786
+ x(h.coordinates, !1);
787
+ break;
788
+ case "LineString":
789
+ x(h.coordinates);
790
+ break;
791
+ case "Polygon":
792
+ case "MultiLineString":
793
+ for (const I of h.coordinates) x(I);
794
+ break;
795
+ case "MultiPolygon":
796
+ for (const I of h.coordinates)
797
+ for (const z of I) x(z);
798
+ break;
799
+ case "GeometryCollection":
800
+ for (const I of h.geometries) f(I);
801
+ break;
802
+ }
803
+ }
804
+ for (const h of o)
805
+ if (!a.has(h.id)) {
806
+ if (h.bbox) {
807
+ const [I, z, k, H] = h.bbox;
808
+ if (k < C || I > M || H < S || z > m) continue;
809
+ }
810
+ f(h.geometry);
811
+ }
812
+ if (l <= r && s)
813
+ return { latlng: s, isVertex: !0 };
814
+ if (u <= r && g) {
815
+ const h = n.layerPointToLatLng(g);
816
+ return { latlng: [h.lng, h.lat], isVertex: !1 };
817
+ }
818
+ return null;
819
+ }
820
+ function Lo(t, e, n, o = 15) {
821
+ const r = t.latLngToContainerPoint([e[1], e[0]]), a = t.latLngToContainerPoint([n[1], n[0]]), i = a.x - r.x, l = a.y - r.y, s = Math.hypot(i, l);
822
+ if (s < 1) return n;
823
+ const u = Math.atan2(l, i), g = o * Math.PI / 180, P = Math.round(u / g) * g, d = r.x + s * Math.cos(P), p = r.y + s * Math.sin(P), C = t.containerPointToLatLng([d, p]);
824
+ return [C.lng, C.lat];
825
+ }
826
+ function bn(t) {
827
+ let e = 0, n = null;
828
+ const o = () => {
829
+ e = 0;
830
+ const r = n;
831
+ n = null, r && t(...r);
832
+ };
833
+ return {
834
+ schedule(...r) {
835
+ n = r, e || (e = requestAnimationFrame(o));
836
+ },
837
+ flush() {
838
+ e && cancelAnimationFrame(e), o();
839
+ },
840
+ cancel() {
841
+ e && cancelAnimationFrame(e), e = 0, n = null;
842
+ }
843
+ };
844
+ }
845
+ let Zn = !1;
846
+ function vi() {
847
+ if (Zn) return;
848
+ const t = document.createElement("style");
849
+ t.textContent = [
850
+ ".elm-midpoint-marker{pointer-events:auto!important}",
851
+ ".elm-vertex:hover{background:var(--color-primary-100)!important}"
852
+ ].join(""), document.head.appendChild(t), Zn = !0;
853
+ }
854
+ const wi = Oe({
855
+ className: "",
856
+ html: '<div class="elm-vertex" style="width:12px;height:12px;background:#ffffff;border:2px solid var(--color-primary-500);border-radius:3px;box-shadow:0 1px 3px rgba(0,0,0,0.3);cursor:pointer;transition:background 0.15s"></div>',
857
+ iconSize: [12, 12],
858
+ iconAnchor: [6, 6]
859
+ }), xi = Oe({
860
+ className: "",
861
+ html: '<div class="elm-vertex" style="width:12px;height:12px;background:var(--color-primary-500);border:2px solid var(--color-primary-700);border-radius:3px;box-shadow:0 1px 3px rgba(0,0,0,0.3);cursor:pointer;transition:background 0.15s"></div>',
862
+ iconSize: [12, 12],
863
+ iconAnchor: [6, 6]
864
+ }), Si = Oe({
865
+ className: "elm-midpoint-marker",
866
+ html: '<div style="width:24px;height:24px;display:flex;align-items:center;justify-content:center;cursor:pointer" class="group"><div class="bg-white border-2 border-primary-500 shadow group-hover:bg-primary-100 transition-colors" style="width:12px;height:12px;transform:rotate(45deg);border-radius:3px"></div></div>',
867
+ iconSize: [24, 24],
868
+ iconAnchor: [12, 12]
869
+ });
870
+ typeof document < "u" && vi();
871
+ const Ft = Math.PI / 180, qn = 85.0511287798;
872
+ function Bt(t) {
873
+ const e = Math.max(Math.min(t, qn), -qn);
874
+ return Math.log(Math.tan(Math.PI / 4 + e * Ft / 2));
875
+ }
876
+ function Jn(t, e, n) {
877
+ if (t.length <= n) return t;
878
+ const o = new Float64Array(t.length);
879
+ for (let u = 1; u < t.length; u++)
880
+ o[u] = o[u - 1] + Math.hypot(e[2 * u] - e[2 * u - 2], e[2 * u + 1] - e[2 * u - 1]);
881
+ const r = o[o.length - 1];
882
+ if (r === 0) return t.slice(0, n);
883
+ const a = r / n, i = [];
884
+ let l = 0, s = -1;
885
+ for (let u = 0; u < n; u++) {
886
+ const g = u * a;
887
+ for (; l < o.length - 1 && o[l + 1] < g; ) l++;
888
+ l !== s && (i.push(t[l]), s = l);
889
+ }
890
+ return i;
891
+ }
892
+ function bi(t, e) {
893
+ const n = (r) => Math.log(Math.tan(Math.PI / 4 + r * Math.PI / 180 / 2)), o = (r) => (2 * Math.atan(Math.exp(r)) - Math.PI / 2) * 180 / Math.PI;
894
+ return [(t[0] + e[0]) / 2, o((n(t[1]) + n(e[1])) / 2)];
895
+ }
896
+ function Pi(t, e, n, o, r, a) {
897
+ const i = r - n, l = a - o, s = i * i + l * l, u = s === 0 ? 0 : Math.max(0, Math.min(1, ((t - n) * i + (e - o) * l) / s)), g = t - (n + u * i), P = e - (o + u * l);
898
+ return g * g + P * P;
899
+ }
900
+ function fn() {
901
+ document.querySelectorAll(".elm-midpoint-marker").forEach((t) => {
902
+ t.style.display = "none";
903
+ });
904
+ }
905
+ function Ci({
906
+ feature: t,
907
+ selectedIndices: e,
908
+ onExit: n,
909
+ onDeleteSelected: o,
910
+ onSelectIndices: r,
911
+ onFeatureClick: a,
912
+ readonly: i
913
+ }) {
914
+ var zn, Gn;
915
+ const { dataStore: l, uiStore: s } = De(), u = Nt(), g = Qt(), P = Se((b) => b.updateFeature), d = t.geometry.type === "Polygon", p = d ? t.geometry.coordinates[0].slice(0, -1) : t.geometry.coordinates, C = _e(() => {
916
+ const b = new Float64Array(p.length * 2);
917
+ for (let A = 0; A < p.length; A++)
918
+ b[2 * A] = p[A][0] * Ft, b[2 * A + 1] = Bt(p[A][1]);
919
+ return b;
920
+ }, [t.geometry]), M = _e(() => new Set(e), [e]), [S, m] = de(null), [y, x] = de({ lng: "", lat: "" }), [f, h] = de(null), I = Fe(() => h(null), []), [z, k] = de(null), H = $(null), D = $(null), _ = $(0), [F] = de(() => bn((b) => b()));
921
+ Q(() => () => F.cancel(), [F]);
922
+ const Y = $(/* @__PURE__ */ new Map()), L = $(/* @__PURE__ */ new Map()), V = $(/* @__PURE__ */ new Map()), R = $(null), c = $(!1);
923
+ Q(() => {
924
+ const b = (A) => {
925
+ c.current = A.metaKey || A.ctrlKey;
926
+ };
927
+ return window.addEventListener("keydown", b), window.addEventListener("keyup", b), () => {
928
+ window.removeEventListener("keydown", b), window.removeEventListener("keyup", b);
929
+ };
930
+ }, []);
931
+ const [E, B] = de(0), J = be();
932
+ je({
933
+ click: () => {
934
+ Date.now() < _.current || n();
935
+ },
936
+ moveend: () => B((b) => b + 1),
937
+ // Hover detection at the map level — Leaflet's per-path mousemove fires
938
+ // unreliably (skipped for the right edge of a square in our probe) and a
939
+ // map-level handler with a pixel-distance check is rock-solid by
940
+ // comparison. Hysteresis (22 px enter, 36 px exit) prevents flicker as
941
+ // the cursor approaches the midpoint marker.
942
+ mousemove: (b) => {
943
+ if (i || H.current !== null) return;
944
+ const { idx: A, px: N } = rt(b.latlng), Z = it.current !== null ? T : wt;
945
+ N <= Z && A >= 0 ? pe(A) : pe(null);
946
+ },
947
+ mouseout: () => {
948
+ H.current === null && pe(null);
949
+ }
950
+ }), Q(() => {
951
+ document.querySelectorAll(".elm-midpoint-marker").forEach((b) => {
952
+ b.style.display = "";
953
+ });
954
+ }, [t]), Q(() => {
955
+ var N, O;
956
+ if (e.length === 0 || i) return;
957
+ function b(Z) {
958
+ var se;
959
+ ((se = document.activeElement) == null ? void 0 : se.tagName) !== "INPUT" && g(Z) && (Z.key === "Delete" || Z.key === "Backspace") && (Z.preventDefault(), o());
960
+ }
961
+ const A = ((O = (N = document.querySelector(".leaflet-container")) == null ? void 0 : N.ownerDocument) == null ? void 0 : O.defaultView) || window;
962
+ return A.addEventListener("keydown", b), () => A.removeEventListener("keydown", b);
963
+ }, [e.length, o, i, g]);
964
+ function j(b) {
965
+ const A = d ? t.geometry.coordinates[0] : t.geometry.coordinates;
966
+ if (A.length < 2) return null;
967
+ let N = null;
968
+ return b.eachLayer((O) => {
969
+ if (!N) {
970
+ if (d && O instanceof Xe.Polygon) {
971
+ const Z = Array.isArray(O.getLatLngs()[0]) ? O.getLatLngs()[0] : O.getLatLngs();
972
+ Z.length >= 2 && Math.abs(Z[0].lng - A[0][0]) < 1e-6 && Math.abs(Z[0].lat - A[0][1]) < 1e-6 && Math.abs(Z[1].lng - A[1][0]) < 1e-6 && Math.abs(Z[1].lat - A[1][1]) < 1e-6 && (N = O);
973
+ } else if (!d && O instanceof Xe.Polyline && !(O instanceof Xe.Polygon)) {
974
+ if ((O.options.opacity ?? 1) < 0.01) return;
975
+ const Z = O.getLatLngs();
976
+ Z.length >= 2 && Math.abs(Z[0].lng - A[0][0]) < 1e-6 && Math.abs(Z[0].lat - A[0][1]) < 1e-6 && Math.abs(Z[1].lng - A[1][0]) < 1e-6 && Math.abs(Z[1].lat - A[1][1]) < 1e-6 && (N = O);
977
+ }
978
+ }
979
+ }), N;
980
+ }
981
+ function ce(b, A) {
982
+ if (A.geometry.type !== "Polygon" && A.geometry.type !== "MultiPolygon") return null;
983
+ const N = A.geometry.type === "Polygon" ? A.geometry.coordinates[0] : A.geometry.coordinates[0][0];
984
+ if (N.length < 2) return null;
985
+ let O = null;
986
+ return b.eachLayer((Z) => {
987
+ var ye;
988
+ if (O || !(Z instanceof Xe.Polygon) || Z.options.opacity != null && Z.options.opacity < 0.01) return;
989
+ const se = Array.isArray((ye = Z.getLatLngs()[0]) == null ? void 0 : ye[0]) ? Z.getLatLngs()[0][0] : Array.isArray(Z.getLatLngs()[0]) ? Z.getLatLngs()[0] : Z.getLatLngs();
990
+ se.length >= 2 && Math.abs(se[0].lng - N[0][0]) < 1e-6 && Math.abs(se[0].lat - N[0][1]) < 1e-6 && Math.abs(se[1].lng - N[1][0]) < 1e-6 && Math.abs(se[1].lat - N[1][1]) < 1e-6 && (O = Z);
991
+ }), O;
992
+ }
993
+ function te(b, A) {
994
+ for (const [N, O] of Y.current) {
995
+ const Z = L.current.get(N);
996
+ if (!Z) continue;
997
+ let se = V.current.get(N);
998
+ if (!se) {
999
+ const Ae = ce(b, Z);
1000
+ if (!Ae) continue;
1001
+ se = Ae, V.current.set(N, se);
1002
+ }
1003
+ const ye = jn(Z.geometry, O, A);
1004
+ ye.type === "Polygon" ? se.setLatLngs(ye.coordinates.map(
1005
+ (Ae) => Ae.map(([Ee, Re]) => Xe.latLng(Re, Ee))
1006
+ )) : ye.type === "MultiPolygon" && se.setLatLngs(ye.coordinates.map(
1007
+ (Ae) => Ae.map((Ee) => Ee.map(([Re, Ke]) => Xe.latLng(Ke, Re)))
1008
+ ));
1009
+ }
1010
+ }
1011
+ function ue(b) {
1012
+ l.getState().updateFeatures([...Y.current].flatMap(([A, N]) => {
1013
+ const O = L.current.get(A);
1014
+ return O ? [{ id: A, patch: jo(O, jn(O.geometry, N, b)) }] : [];
1015
+ })), Y.current.clear(), L.current.clear(), V.current.clear();
1016
+ }
1017
+ function X(b) {
1018
+ if (!s.getState().topoEditEnabled) return;
1019
+ const A = l.getState().features, N = Go(A, t.id, [b]);
1020
+ Y.current = Yo(N);
1021
+ const O = /* @__PURE__ */ new Map();
1022
+ for (const Z of Y.current.keys()) {
1023
+ const se = A.find((ye) => ye.id === Z);
1024
+ se && O.set(Z, se);
1025
+ }
1026
+ L.current = O, V.current.clear(), R.current = b;
1027
+ }
1028
+ function v(b) {
1029
+ const { lat: A, lng: N } = b.target.getLatLng(), O = b.originalEvent, Z = (O == null ? void 0 : O.metaKey) || (O == null ? void 0 : O.ctrlKey);
1030
+ if (!s.getState().snapEnabled || Z) return { lng: N, lat: A };
1031
+ const se = b.target._map;
1032
+ if (!se) return { lng: N, lat: A };
1033
+ const ye = Sn(N, A, se, l.getState().features, 15, /* @__PURE__ */ new Set([t.id]));
1034
+ return ye ? (s.getState().setSnappedCoord(ye.latlng), { lng: ye.latlng[0], lat: ye.latlng[1] }) : (s.getState().snappedCoord && s.getState().setSnappedCoord(null), { lng: N, lat: A });
1035
+ }
1036
+ function U(b, A) {
1037
+ const N = b.target._map;
1038
+ if (!N || (D.current || (D.current = j(N)), !D.current)) return;
1039
+ const O = A.map(([Z, se]) => Xe.latLng(se, Z));
1040
+ d ? D.current.setLatLngs([O]) : D.current.setLatLngs(O);
1041
+ }
1042
+ function ee(b) {
1043
+ D.current = null;
1044
+ const A = s.getState().snappedCoord;
1045
+ s.getState().setSnappedCoord(null);
1046
+ const { lat: N, lng: O } = b.target.getLatLng();
1047
+ return A ? { lng: A[0], lat: A[1] } : { lng: O, lat: N };
1048
+ }
1049
+ function q(b, A, N) {
1050
+ const O = [...t.geometry.coordinates[0]];
1051
+ return O[b] = zt(O[b], [A, N]), b === 0 && (O[O.length - 1] = O[0]), O;
1052
+ }
1053
+ function ge(b, A, N) {
1054
+ const O = [...t.geometry.coordinates];
1055
+ return O[b] = zt(O[b], [A, N]), O;
1056
+ }
1057
+ function ne(b, A, N) {
1058
+ const O = [...t.geometry.coordinates[0]];
1059
+ return O.splice(b + 1, 0, Yn(O[b], O[b + 1], [A, N])), O[O.length - 1] = O[0], O;
1060
+ }
1061
+ function fe(b, A, N) {
1062
+ const O = [...t.geometry.coordinates];
1063
+ return O.splice(b + 1, 0, Yn(O[b], O[b + 1], [A, N])), O;
1064
+ }
1065
+ function W(b) {
1066
+ P(t.id, bt(t, { type: "Polygon", coordinates: [b] }));
1067
+ }
1068
+ function we(b) {
1069
+ P(t.id, bt(t, { type: "LineString", coordinates: b })), a();
1070
+ }
1071
+ function he(b, A) {
1072
+ const { lng: N, lat: O } = v(A);
1073
+ if (d ? U(A, q(b, N, O)) : U(A, ge(b, N, O)), Y.current.size > 0) {
1074
+ const Z = A.target._map;
1075
+ if (Z) {
1076
+ const se = R.current, ye = c.current && se ? se : [N, O];
1077
+ te(Z, ye);
1078
+ }
1079
+ }
1080
+ }
1081
+ function Ie(b, A) {
1082
+ const { lng: N, lat: O } = ee(A);
1083
+ if (d ? W(q(b, N, O)) : we(ge(b, N, O)), Y.current.size > 0)
1084
+ if (c.current) {
1085
+ const Z = A.target._map, se = R.current;
1086
+ Z && se && te(Z, se), Y.current.clear(), L.current.clear(), V.current.clear(), R.current = null;
1087
+ } else
1088
+ ue([N, O]), R.current = null;
1089
+ }
1090
+ function Be(b, A) {
1091
+ const { lng: N, lat: O } = v(A), Z = [...t.geometry.coordinates[0]];
1092
+ if (Z.splice(b + 1, 0, [N, O]), d) U(A, Z);
1093
+ else {
1094
+ const se = [...t.geometry.coordinates];
1095
+ se.splice(b + 1, 0, [N, O]), U(A, se);
1096
+ }
1097
+ }
1098
+ function ze(b, A) {
1099
+ const { lng: N, lat: O } = ee(A);
1100
+ d ? W(ne(b, N, O)) : we(fe(b, N, O)), d && s.getState().topoEditEnabled && l.getState().updateFeatures(cn(
1101
+ l.getState().features,
1102
+ t.id,
1103
+ p[b],
1104
+ p[(b + 1) % p.length],
1105
+ [N, O]
1106
+ ));
1107
+ }
1108
+ function re(b, A, N) {
1109
+ const O = p[b];
1110
+ l.getState().takeSnapshot(), d ? W(q(b, A, N)) : we(ge(b, A, N)), d && s.getState().topoEditEnabled && l.getState().updateFeatures(Uo(
1111
+ l.getState().features,
1112
+ t.id,
1113
+ O,
1114
+ [A, N]
1115
+ ));
1116
+ }
1117
+ function Me(b) {
1118
+ if (i) return;
1119
+ if (p.length <= (d ? 3 : 2)) {
1120
+ u({ type: "warning", message: `Cannot delete: ${d ? "an area needs at least 3" : "a line needs at least 2"} points` });
1121
+ return;
1122
+ }
1123
+ const A = p[b];
1124
+ if (l.getState().takeSnapshot(), r([]), d) {
1125
+ const N = t.geometry.coordinates[0].filter((O, Z) => Z !== b);
1126
+ b === 0 && (N[N.length - 1] = N[0]), W(N);
1127
+ } else
1128
+ we(t.geometry.coordinates.filter((N, O) => O !== b));
1129
+ d && s.getState().topoEditEnabled && l.getState().updateFeatures(yn(
1130
+ l.getState().features,
1131
+ t.id,
1132
+ [A]
1133
+ ));
1134
+ }
1135
+ function $e(b, A) {
1136
+ if (A.originalEvent.stopPropagation(), i) return;
1137
+ l.getState().takeSnapshot();
1138
+ const { lat: N, lng: O } = A.latlng;
1139
+ d ? W(ne(b, O, N)) : we(fe(b, O, N)), d && s.getState().topoEditEnabled && l.getState().updateFeatures(cn(
1140
+ l.getState().features,
1141
+ t.id,
1142
+ p[b],
1143
+ p[(b + 1) % p.length],
1144
+ [O, N]
1145
+ ));
1146
+ }
1147
+ function rt(b) {
1148
+ const A = b.lng * Ft, N = Bt(b.lat), O = p.length, Z = d ? O : O - 1;
1149
+ let se = -1, ye = 1 / 0;
1150
+ for (let Ae = 0; Ae < Z; Ae++) {
1151
+ const Ee = (Ae + 1) % O, Re = Pi(A, N, C[2 * Ae], C[2 * Ae + 1], C[2 * Ee], C[2 * Ee + 1]);
1152
+ Re < ye && (ye = Re, se = Ae);
1153
+ }
1154
+ return { idx: se, px: Math.sqrt(ye) * J.options.crs.scale(J.getZoom()) / (2 * Math.PI) };
1155
+ }
1156
+ const it = $(null), wt = 22, T = 36, oe = 15;
1157
+ function pe(b) {
1158
+ b !== it.current && (it.current = b, k(b));
1159
+ }
1160
+ function ae(b) {
1161
+ if (i) return;
1162
+ const A = b.target._map;
1163
+ if (!A) return;
1164
+ const { idx: N, px: O } = rt(b.latlng);
1165
+ if (N < 0 || O > oe) return;
1166
+ b.originalEvent.stopPropagation(), b.originalEvent.preventDefault();
1167
+ const Z = s.getState().snappedCoord;
1168
+ let se = Z ? Z[0] : b.latlng.lng, ye = Z ? Z[1] : b.latlng.lat;
1169
+ Z && s.getState().setSnappedCoord(null), l.getState().takeSnapshot(), fn(), A.dragging.disable(), Ue(!0);
1170
+ const Ae = j(A);
1171
+ function Ee(Ve) {
1172
+ let at = Ve.latlng.lng, nt = Ve.latlng.lat;
1173
+ if (s.getState().snapEnabled) {
1174
+ const Ge = Sn(at, nt, A, l.getState().features, 15, /* @__PURE__ */ new Set([t.id]));
1175
+ Ge ? (s.getState().setSnappedCoord(Ge.latlng), at = Ge.latlng[0], nt = Ge.latlng[1]) : s.getState().snappedCoord && s.getState().setSnappedCoord(null);
1176
+ }
1177
+ if (se = at, ye = nt, Ae)
1178
+ if (d) {
1179
+ const Ge = [...t.geometry.coordinates[0]];
1180
+ Ge.splice(N + 1, 0, [at, nt]), Ae.setLatLngs([Ge.map(([an, ln]) => Xe.latLng(ln, an))]);
1181
+ } else {
1182
+ const Ge = [...t.geometry.coordinates];
1183
+ Ge.splice(N + 1, 0, [at, nt]), Ae.setLatLngs(Ge.map(([an, ln]) => Xe.latLng(ln, an)));
1184
+ }
1185
+ }
1186
+ const Re = bn(Ee), Ke = Re.schedule;
1187
+ function et() {
1188
+ A.off("mousemove", Ke), A.off("mouseup", et), Re.flush(), A.dragging.enable(), s.getState().setSnappedCoord(null), _.current = Date.now() + 200, Ue(!1), d ? W(ne(N, se, ye)) : we(fe(N, se, ye)), d && s.getState().topoEditEnabled && l.getState().updateFeatures(cn(
1189
+ l.getState().features,
1190
+ t.id,
1191
+ p[N],
1192
+ p[(N + 1) % p.length],
1193
+ [se, ye]
1194
+ ));
1195
+ }
1196
+ A.on("mousemove", Ke), A.on("mouseup", et);
1197
+ }
1198
+ function ie(b, A) {
1199
+ A.originalEvent.stopPropagation(), !i && (A.originalEvent.shiftKey ? r(M.has(b) ? e.filter((N) => N !== b) : [...e, b].sort((N, O) => N - O)) : r([b]));
1200
+ }
1201
+ function me(b, A) {
1202
+ A.originalEvent.preventDefault(), A.originalEvent.stopPropagation(), !i && h({ index: b, x: A.originalEvent.clientX, y: A.originalEvent.clientY });
1203
+ }
1204
+ function Ne(b) {
1205
+ const [A, N] = p[b];
1206
+ x({ lng: A.toFixed(6), lat: N.toFixed(6) }), m(b);
1207
+ }
1208
+ function Ce() {
1209
+ if (S === null) return;
1210
+ const b = parseFloat(y.lng), A = parseFloat(y.lat);
1211
+ !isNaN(b) && !isNaN(A) ? (re(S, b, A), m(null), u({ type: "success", message: "Coordinate updated" })) : u({ type: "warning", message: "Invalid coordinates" });
1212
+ }
1213
+ const qe = S !== null ? (zn = p[S]) == null ? void 0 : zn[0] : void 0, Je = S !== null ? (Gn = p[S]) == null ? void 0 : Gn[1] : void 0, Qe = _e(
1214
+ () => qe === void 0 || Je === void 0 ? null : [Je, qe],
1215
+ [qe, Je]
1216
+ ), st = be(), dt = 500, { visibleVertexIndices: gt, midpoints: Ko } = _e(() => {
1217
+ const b = st.getBounds(), A = b.getWest() * Ft, N = b.getEast() * Ft, O = Bt(b.getSouth()), Z = Bt(b.getNorth()), se = [];
1218
+ for (let Ee = 0; Ee < p.length; Ee++) {
1219
+ const Re = C[2 * Ee], Ke = C[2 * Ee + 1];
1220
+ Re >= A && Re <= N && Ke >= O && Ke <= Z && se.push(Ee);
1221
+ }
1222
+ let ye = se;
1223
+ if (se.length > dt) {
1224
+ const Ee = new Float64Array(se.length * 2);
1225
+ se.forEach((Re, Ke) => {
1226
+ Ee[2 * Ke] = C[2 * Re], Ee[2 * Ke + 1] = C[2 * Re + 1];
1227
+ }), ye = Jn(se, Ee, dt);
1228
+ }
1229
+ if (se.length > dt) {
1230
+ const Ee = new Set(ye), Re = new Set(se);
1231
+ let Ke = !1;
1232
+ for (const et of M)
1233
+ Re.has(et) && !Ee.has(et) && (ye.push(et), Ke = !0);
1234
+ Ke && (ye = [...ye].sort((et, Ve) => et - Ve));
1235
+ }
1236
+ const Ae = [];
1237
+ if (!i) {
1238
+ const Ee = d ? p.length : p.length - 1, Re = [], Ke = [];
1239
+ for (let Ve = 0; Ve < Ee; Ve++) {
1240
+ const at = (Ve + 1) % p.length, nt = (C[2 * Ve] + C[2 * at]) / 2, Ge = (C[2 * Ve + 1] + C[2 * at + 1]) / 2;
1241
+ nt >= A && nt <= N && Ge >= O && Ge <= Z && (Re.push(Ve), Ke.push(nt, Ge));
1242
+ }
1243
+ const et = Jn(Re, Ke, dt);
1244
+ for (const Ve of et) Ae.push({ index: Ve, coord: bi(p[Ve], p[(Ve + 1) % p.length]) });
1245
+ }
1246
+ return { visibleVertexIndices: ye, midpoints: Ae };
1247
+ }, [t.geometry, C, E, i, M, st]), Xn = _e(() => p.map(G), [t.geometry]);
1248
+ return /* @__PURE__ */ le(xe, { children: [
1249
+ !i && (d ? /* @__PURE__ */ w(
1250
+ He,
1251
+ {
1252
+ positions: [Xn],
1253
+ pathOptions: { weight: 2 * oe, opacity: 0, fillOpacity: 0, className: "cursor-pointer" },
1254
+ bubblingMouseEvents: !1,
1255
+ eventHandlers: { mousedown: ae }
1256
+ }
1257
+ ) : /* @__PURE__ */ w(
1258
+ ve,
1259
+ {
1260
+ positions: Xn,
1261
+ pathOptions: { weight: 2 * oe, opacity: 0, className: "cursor-pointer" },
1262
+ bubblingMouseEvents: !1,
1263
+ eventHandlers: { mousedown: ae }
1264
+ }
1265
+ )),
1266
+ !i && Ko.filter((b) => b.index === z).map((b) => /* @__PURE__ */ w(
1267
+ Le,
1268
+ {
1269
+ position: G(b.coord),
1270
+ icon: Si,
1271
+ draggable: !0,
1272
+ eventHandlers: {
1273
+ click: (A) => $e(b.index, A),
1274
+ dragstart: () => {
1275
+ l.getState().takeSnapshot(), fn(), H.current = b.index, Ue(!0);
1276
+ },
1277
+ drag: (A) => F.schedule(() => Be(b.index, A)),
1278
+ dragend: (A) => {
1279
+ F.flush(), ze(b.index, A), H.current = null, Ue(!1);
1280
+ }
1281
+ }
1282
+ },
1283
+ `mid-${b.coord[0].toFixed(8)},${b.coord[1].toFixed(8)}`
1284
+ )),
1285
+ gt.map((b) => {
1286
+ const A = p[b];
1287
+ return /* @__PURE__ */ w(
1288
+ Le,
1289
+ {
1290
+ position: G(A),
1291
+ icon: M.has(b) ? xi : wi,
1292
+ draggable: !i,
1293
+ eventHandlers: {
1294
+ dragstart: () => {
1295
+ l.getState().takeSnapshot(), fn(), X(p[b]), Ue(!0);
1296
+ },
1297
+ drag: (N) => F.schedule(() => he(b, N)),
1298
+ dragend: (N) => {
1299
+ F.flush(), Ie(b, N), Ue(!1);
1300
+ },
1301
+ click: (N) => ie(b, N),
1302
+ contextmenu: (N) => me(b, N)
1303
+ }
1304
+ },
1305
+ `v-${A[0].toFixed(8)},${A[1].toFixed(8)}-${b}`
1306
+ );
1307
+ }),
1308
+ S !== null && Qe && /* @__PURE__ */ w(go, { position: Qe, eventHandlers: { remove: () => m(null) }, autoClose: !1, closeOnClick: !1, children: /* @__PURE__ */ le(
1309
+ "div",
1310
+ {
1311
+ className: "flex flex-col gap-2 min-w-[140px]",
1312
+ onKeyDown: (b) => {
1313
+ b.key === "Enter" && Ce(), b.key === "Escape" && m(null);
1314
+ },
1315
+ children: [
1316
+ /* @__PURE__ */ w("p", { className: "text-xs font-semibold text-(--elm-text-secondary,var(--color-gray-700)) m-0 leading-none", children: "Precise coordinates" }),
1317
+ /* @__PURE__ */ le("div", { className: "flex flex-col gap-1", children: [
1318
+ /* @__PURE__ */ le("label", { className: "flex items-center gap-2 text-xs text-(--elm-text-muted,var(--color-gray-500))", children: [
1319
+ "Lat:",
1320
+ /* @__PURE__ */ w(
1321
+ "input",
1322
+ {
1323
+ type: "text",
1324
+ value: y.lat,
1325
+ onChange: (b) => x((A) => ({ ...A, lat: b.target.value })),
1326
+ className: "flex-1 w-full min-w-0 border border-(--elm-border,var(--color-gray-200)) rounded-elm-chip px-1.5 py-0.5 text-xs outline-none focus:border-primary-400"
1327
+ }
1328
+ )
1329
+ ] }),
1330
+ /* @__PURE__ */ le("label", { className: "flex items-center gap-2 text-xs text-(--elm-text-muted,var(--color-gray-500))", children: [
1331
+ "Lng:",
1332
+ /* @__PURE__ */ w(
1333
+ "input",
1334
+ {
1335
+ type: "text",
1336
+ value: y.lng,
1337
+ onChange: (b) => x((A) => ({ ...A, lng: b.target.value })),
1338
+ className: "flex-1 w-full min-w-0 border border-(--elm-border,var(--color-gray-200)) rounded-elm-chip px-1.5 py-0.5 text-xs outline-none focus:border-primary-400"
1339
+ }
1340
+ )
1341
+ ] })
1342
+ ] }),
1343
+ /* @__PURE__ */ le("div", { className: "flex items-center justify-end gap-1 mt-1", children: [
1344
+ /* @__PURE__ */ w(
1345
+ "button",
1346
+ {
1347
+ onClick: () => m(null),
1348
+ className: "px-2 py-1 text-xs text-(--elm-text-muted,var(--color-gray-500)) hover:bg-(--elm-surface-hover,var(--color-gray-100)) rounded-elm-chip transition-colors",
1349
+ children: "Cancel"
1350
+ }
1351
+ ),
1352
+ /* @__PURE__ */ le(
1353
+ "button",
1354
+ {
1355
+ onClick: Ce,
1356
+ className: "px-2 py-1 text-xs text-white bg-primary-500 hover:bg-primary-600 rounded-elm-chip transition-colors font-medium flex items-center gap-1",
1357
+ children: [
1358
+ /* @__PURE__ */ w(yo, { size: 12, weight: "bold" }),
1359
+ " Save"
1360
+ ]
1361
+ }
1362
+ )
1363
+ ] })
1364
+ ]
1365
+ }
1366
+ ) }),
1367
+ f && (() => {
1368
+ const b = M.has(f.index) && e.length > 1;
1369
+ return /* @__PURE__ */ w(
1370
+ mr,
1371
+ {
1372
+ x: f.x,
1373
+ y: f.y,
1374
+ onClose: I,
1375
+ items: [
1376
+ { label: "Edit coordinates…", icon: /* @__PURE__ */ w(Xr, { size: 16 }), onClick: () => Ne(f.index) },
1377
+ { separator: !0 },
1378
+ {
1379
+ label: b ? `Delete ${e.length} points` : "Delete point",
1380
+ icon: /* @__PURE__ */ w(zr, { size: 16 }),
1381
+ onClick: () => b ? o() : Me(f.index)
1382
+ }
1383
+ ]
1384
+ }
1385
+ );
1386
+ })()
1387
+ ] });
1388
+ }
1389
+ function on(t, e) {
1390
+ const [n, o] = de(null), [r, a] = de(t);
1391
+ return r !== t && (a(t), o(null)), je({
1392
+ mousemove(i) {
1393
+ e && o([i.latlng.lng, i.latlng.lat]);
1394
+ },
1395
+ mouseout() {
1396
+ o(null);
1397
+ }
1398
+ }), n;
1399
+ }
1400
+ function Mi() {
1401
+ return Oe({
1402
+ className: "",
1403
+ html: '<div class="w-2.5 h-2.5 rounded-full border-2 border-white shadow bg-emerald-500"></div>',
1404
+ iconSize: [10, 10],
1405
+ iconAnchor: [5, 5]
1406
+ });
1407
+ }
1408
+ function Ei() {
1409
+ const t = ut(be().getContainer())[500], e = K((s) => s.circleCenter), n = K((s) => s.editingMode), o = K((s) => s.snappedCoord), r = on(n, n === "draw-circle"), a = Se((s) => s.geometryMode);
1410
+ if (n !== "draw-circle") return null;
1411
+ const i = o ?? r, l = e && i ? Wo(e, i, a).map(G) : null;
1412
+ return /* @__PURE__ */ le(xe, { children: [
1413
+ e && /* @__PURE__ */ w(Le, { position: G(e), icon: Mi(), interactive: !1 }),
1414
+ l && /* @__PURE__ */ w(
1415
+ He,
1416
+ {
1417
+ positions: l,
1418
+ pathOptions: { color: t, weight: 2, opacity: 0.8, dashArray: "6 4", fillOpacity: 0.1 },
1419
+ interactive: !1
1420
+ }
1421
+ )
1422
+ ] });
1423
+ }
1424
+ function Li(t) {
1425
+ return Oe({
1426
+ className: "",
1427
+ html: `<div class="w-2.5 h-2.5 rounded-full border-2 border-white shadow ${t ? "bg-emerald-500" : "bg-primary-500"}"></div>`,
1428
+ iconSize: [10, 10],
1429
+ iconAnchor: [5, 5]
1430
+ });
1431
+ }
1432
+ function ki() {
1433
+ return Oe({
1434
+ className: "closing-node",
1435
+ html: '<div class="flex items-center justify-center w-full h-full group"><div class="w-4 h-4 rounded-full border-[3px] border-white shadow-lg bg-emerald-500 group-hover:scale-[1.5] group-hover:bg-emerald-400 transition-transform duration-200"></div></div>',
1436
+ iconSize: [48, 48],
1437
+ iconAnchor: [24, 24]
1438
+ });
1439
+ }
1440
+ function Di() {
1441
+ const t = K((o) => o.polygonInProgress), e = K((o) => o.commitPolygon);
1442
+ if (t.length === 0) return null;
1443
+ const n = t.map(G);
1444
+ return /* @__PURE__ */ le(xe, { children: [
1445
+ t.length >= 3 && /* @__PURE__ */ w(
1446
+ He,
1447
+ {
1448
+ positions: n,
1449
+ pathOptions: { color: Te, weight: 2, opacity: 0.7, dashArray: "6 4", fillOpacity: 0.1 },
1450
+ interactive: !1
1451
+ }
1452
+ ),
1453
+ t.length >= 2 && /* @__PURE__ */ w(
1454
+ ve,
1455
+ {
1456
+ positions: n,
1457
+ pathOptions: { color: Te, weight: 2, opacity: 0.7, dashArray: "6 4" },
1458
+ interactive: !1
1459
+ }
1460
+ ),
1461
+ t.map((o, r) => {
1462
+ const a = r === 0 && t.length >= 3;
1463
+ return /* @__PURE__ */ w(
1464
+ Le,
1465
+ {
1466
+ position: G(o),
1467
+ icon: a ? ki() : Li(r === 0),
1468
+ interactive: a,
1469
+ eventHandlers: a ? {
1470
+ click: (i) => {
1471
+ i.originalEvent.stopPropagation(), e({});
1472
+ }
1473
+ } : void 0
1474
+ },
1475
+ a ? "closing-node" : `point-${r}`
1476
+ );
1477
+ })
1478
+ ] });
1479
+ }
1480
+ function Ii() {
1481
+ return Oe({
1482
+ className: "",
1483
+ html: '<div class="w-2.5 h-2.5 rounded-full border-2 border-white shadow bg-emerald-500"></div>',
1484
+ iconSize: [10, 10],
1485
+ iconAnchor: [5, 5]
1486
+ });
1487
+ }
1488
+ function Ai() {
1489
+ const t = ut(be().getContainer())[500], e = K((g) => g.rectCorner), n = K((g) => g.editingMode), o = K((g) => g.snappedCoord), r = on(n, n === "draw-rect"), [a, i] = de(!1);
1490
+ je({
1491
+ mousemove(g) {
1492
+ n === "draw-rect" && i(g.originalEvent.shiftKey);
1493
+ }
1494
+ }), Q(() => {
1495
+ var p, C;
1496
+ if (n !== "draw-rect") {
1497
+ i(!1);
1498
+ return;
1499
+ }
1500
+ const g = (M) => {
1501
+ M.key === "Shift" && i(!0);
1502
+ }, P = (M) => {
1503
+ M.key === "Shift" && i(!1);
1504
+ }, d = ((C = (p = document.querySelector(".leaflet-container")) == null ? void 0 : p.ownerDocument) == null ? void 0 : C.defaultView) || window;
1505
+ return d.addEventListener("keydown", g), d.addEventListener("keyup", P), () => {
1506
+ d.removeEventListener("keydown", g), d.removeEventListener("keyup", P);
1507
+ };
1508
+ }, [n]);
1509
+ const l = Se((g) => g.geometryMode);
1510
+ if (n !== "draw-rect") return null;
1511
+ const s = o ?? r;
1512
+ let u = null;
1513
+ return e && s && (u = Zo(e, s, l, a).map(G)), /* @__PURE__ */ le(xe, { children: [
1514
+ e && /* @__PURE__ */ w(Le, { position: G(e), icon: Ii(), interactive: !1 }),
1515
+ u && /* @__PURE__ */ w(
1516
+ He,
1517
+ {
1518
+ positions: u,
1519
+ pathOptions: {
1520
+ color: a ? "#f472b6" : t,
1521
+ weight: 2,
1522
+ opacity: 0.8,
1523
+ dashArray: "6 4",
1524
+ fillOpacity: 0.1
1525
+ },
1526
+ interactive: !1
1527
+ }
1528
+ )
1529
+ ] });
1530
+ }
1531
+ function Ri(t) {
1532
+ return Oe({
1533
+ className: "",
1534
+ html: `<div class="w-2.5 h-2.5 rounded-full border-2 border-white shadow ${t ? "bg-emerald-500" : "bg-primary-500"}"></div>`,
1535
+ iconSize: [10, 10],
1536
+ iconAnchor: [5, 5]
1537
+ });
1538
+ }
1539
+ function Fi() {
1540
+ const t = ut(be().getContainer())[500], e = K((o) => o.lineInProgress);
1541
+ if (e.length === 0) return null;
1542
+ const n = e.map(G);
1543
+ return /* @__PURE__ */ le(xe, { children: [
1544
+ e.length >= 2 && /* @__PURE__ */ w(
1545
+ ve,
1546
+ {
1547
+ positions: n,
1548
+ pathOptions: { color: t, weight: 2, opacity: 0.7, dashArray: "6 4" },
1549
+ interactive: !1
1550
+ }
1551
+ ),
1552
+ e.map((o, r) => /* @__PURE__ */ w(Le, { position: G(o), icon: Ri(r === 0), interactive: !1 }, r))
1553
+ ] });
1554
+ }
1555
+ function Ti({ onMapClick: t }) {
1556
+ return je({ click: t }), null;
1557
+ }
1558
+ function Oi({ onDragDelta: t, onDragEnd: e, onDuplicateDragChange: n, readonly: o }) {
1559
+ const { dataStore: r } = De(), a = be(), i = K((s) => s.editingMode), l = $(i);
1560
+ return l.current = i, je({
1561
+ mousedown(s) {
1562
+ if (o) return;
1563
+ const u = r.getState();
1564
+ if (l.current !== "none") return;
1565
+ const g = s.originalEvent.altKey, P = s.originalEvent.ctrlKey || s.originalEvent.metaKey;
1566
+ if (!g && !P || u.selectedIds.length < 2) return;
1567
+ const d = s.originalEvent.target;
1568
+ if (!(d.closest(".leaflet-overlay-pane path") || d.closest(".leaflet-marker-icon") || d.matches("canvas.leaflet-interactive"))) return;
1569
+ s.originalEvent.preventDefault(), s.originalEvent.stopPropagation(), a.dragging.disable();
1570
+ const C = g;
1571
+ C && n(!0);
1572
+ const M = ke([s.latlng.lng, s.latlng.lat]);
1573
+ let S = !1;
1574
+ function m(x) {
1575
+ S || Ue(!0), S = !0;
1576
+ const f = ke([x.latlng.lng, x.latlng.lat]);
1577
+ t([f[0] - M[0], f[1] - M[1]]);
1578
+ }
1579
+ function y(x) {
1580
+ if (a.off("mousemove", m), a.off("mouseup", y), a.dragging.enable(), Ue(!1), !S) return;
1581
+ const f = ke([x.latlng.lng, x.latlng.lat]);
1582
+ e([f[0] - M[0], f[1] - M[1]], C);
1583
+ }
1584
+ a.on("mousemove", m), a.on("mouseup", y);
1585
+ }
1586
+ }), null;
1587
+ }
1588
+ const _n = "M10 0C4.477 0 0 4.477 0 10c0 7 10 18 10 18s10-11 10-18C20 4.477 15.523 0 10 0zM10 5.5a3.5 3.5 0 1 0 0 7a3.5 3.5 0 1 0 0-7z";
1589
+ function Ni() {
1590
+ return Oe({
1591
+ className: "",
1592
+ html: `<div style="position:relative;width:20px;height:28px">
1593
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="28" viewBox="0 0 20 28" style="position:relative;z-index:1;display:block">
1594
+ <path d="${_n}" fill-rule="evenodd" style="fill:var(--color-primary-500)"/>
1595
+ </svg>
1596
+ </div>`,
1597
+ iconSize: [20, 28],
1598
+ iconAnchor: [10, 28]
1599
+ });
1600
+ }
1601
+ function _i() {
1602
+ const t = K((e) => e.dialogState);
1603
+ return t.type !== "new-point" ? null : /* @__PURE__ */ w(Le, { position: G(t.coords), icon: Ni(), interactive: !1 });
1604
+ }
1605
+ let ko = 0;
1606
+ function pn() {
1607
+ ko = Date.now();
1608
+ }
1609
+ function Ki() {
1610
+ return Date.now() - ko < 200;
1611
+ }
1612
+ const Wt = 16, mn = "elmIdleFeatures", $t = { color: "#ffffff", width: 1.5, opacity: 0.7, maxPaths: 5e3 }, Hi = Rt.extend({
1613
+ /** Lines get a thin light casing under their stroke (LINE_CASING), so they read over busy raster tiles. */
1614
+ // It costs a second stroke per line: above LINE_CASING.maxPaths paths on the canvas
1615
+ // (where a dense map gains nothing from it anyway) there's none, so panning 50k
1616
+ // lines stays as fast as before.
1617
+ _initPath(t) {
1618
+ this._pathCount = (this._pathCount ?? 0) + 1, Rt.prototype._initPath.call(this, t);
1619
+ },
1620
+ _removePath(t) {
1621
+ this._pathCount = Math.max(0, (this._pathCount ?? 0) - 1), Rt.prototype._removePath.call(this, t);
1622
+ },
1623
+ _fillStroke(t, e) {
1624
+ const n = e.options;
1625
+ (this._pathCount ?? 0) <= $t.maxPaths && n.stroke !== !1 && !n.fill && "_parts" in e && (n.opacity ?? 1) > 0.05 && !n.dashArray && (t.globalAlpha = (n.opacity ?? 1) * $t.opacity, t.lineWidth = (n.weight ?? 3) + 2 * $t.width, t.strokeStyle = $t.color, t.lineCap = "round", t.lineJoin = "round", t.setLineDash([]), t.stroke()), Rt.prototype._fillStroke.call(this, t, e);
1626
+ },
1627
+ _onMouseMove(t) {
1628
+ if (this._map) {
1629
+ if (this._map.dragging.moving() || this._map._animatingZoom) {
1630
+ this._fireEvent(!1, t);
1631
+ return;
1632
+ }
1633
+ this._handleMouseHover(t, this._map.mouseEventToLayerPoint(t));
1634
+ }
1635
+ },
1636
+ _handleMouseHover(t, e) {
1637
+ if (this._mouseHoverThrottled) {
1638
+ this._trailingHover = [t, e], this._fireEvent(this._hoveredLayer ? [this._hoveredLayer] : !1, t);
1639
+ return;
1640
+ }
1641
+ this._trailingHover = null, Rt.prototype._handleMouseHover.call(this, t, e), clearTimeout(this._trailingTimer), this._trailingTimer = setTimeout(() => {
1642
+ const n = this._trailingHover;
1643
+ this._trailingHover = null, n && this._map && this._hoverHitTest(n[0], n[1]);
1644
+ }, 33);
1645
+ },
1646
+ /** Leaflet's hover hit test (topmost interactive path wins) without re-firing the mousemove. */
1647
+ _hoverHitTest(t, e) {
1648
+ let n;
1649
+ for (let o = this._drawFirst; o; o = o.next)
1650
+ o.layer.options.interactive && o.layer._containsPoint(e) && (n = o.layer);
1651
+ n !== (this._hoveredLayer ?? void 0) && (this._handleMouseOut(t), n && (this._container.classList.add("leaflet-interactive"), this._fireEvent([n], t, "mouseover"), this._hoveredLayer = n));
1652
+ }
1653
+ }), Do = Ln(void 0);
1654
+ function Bi(t, e) {
1655
+ const n = _e(() => {
1656
+ if (e === "canvas")
1657
+ return t.getPane(mn) || (t.createPane(mn).style.zIndex = "399"), new Hi({ pane: mn, padding: 0.25, tolerance: 6 });
1658
+ }, [t, e]);
1659
+ return Q(() => {
1660
+ if (!n) return;
1661
+ const o = t.getPane("overlayPane");
1662
+ return o.style.pointerEvents = "none", () => {
1663
+ n.remove(), o.style.pointerEvents = "";
1664
+ };
1665
+ }, [t, n]), n;
1666
+ }
1667
+ function Zt(t) {
1668
+ var e;
1669
+ return t.getElement() ?? ((e = t._renderer) == null ? void 0 : e._container);
1670
+ }
1671
+ function rn(t, e, n) {
1672
+ const o = yt(Do), r = t ? void 0 : o;
1673
+ return Q(() => {
1674
+ var i, l;
1675
+ let a = !1;
1676
+ for (const s of e()) {
1677
+ if (!s) continue;
1678
+ const u = s._map;
1679
+ u && s.options.renderer !== r && (u.removeLayer(s), s.options.renderer = r, (i = n == null ? void 0 : n.before) == null || i.call(n, s, !!r), u.addLayer(s), a = !0), t && s.bringToFront();
1680
+ }
1681
+ a && ((l = n == null ? void 0 : n.after) == null || l.call(n));
1682
+ }, [t, r]), r;
1683
+ }
1684
+ const Kn = { color: Te, weight: 3.5, opacity: 0.9 }, Hn = { color: Te, fillColor: Te, weight: 2, opacity: 0.9, fillOpacity: 0.15 }, Bn = { opacity: 1, fillOpacity: 0.28 };
1685
+ function $i(t, e) {
1686
+ if (!(!t && !e))
1687
+ return (n) => {
1688
+ const o = t == null ? void 0 : t(n), r = (o == null ? void 0 : o.color) ?? e, a = (o == null ? void 0 : o.fillColor) ?? r;
1689
+ return !r && !a ? o ?? void 0 : { ...o, ...r && { color: r }, ...a && { fillColor: a } };
1690
+ };
1691
+ }
1692
+ function vt(t) {
1693
+ var e;
1694
+ return ((e = Eo()) == null ? void 0 : e(t)) ?? void 0;
1695
+ }
1696
+ const $n = (t) => (t == null ? void 0 : t.fillColor) ?? (t == null ? void 0 : t.color);
1697
+ function Mt(t, e, n) {
1698
+ return { ...t, ...e, ...n };
1699
+ }
1700
+ function Et(t, e, n) {
1701
+ if (!t) return n;
1702
+ const o = (e ? Nr : _r).prototype.options, r = {};
1703
+ for (const a of Object.keys(t)) r[a] = o[a];
1704
+ return { ...r, ...n };
1705
+ }
1706
+ const It = Ln(Rr());
1707
+ function At(t, e, n) {
1708
+ return (o) => {
1709
+ o.originalEvent.preventDefault(), o.originalEvent.stopPropagation(), !(e || !n) && n({ feature: t, x: o.originalEvent.clientX, y: o.originalEvent.clientY });
1710
+ };
1711
+ }
1712
+ function Lt(t, e = !1, n) {
1713
+ const o = e || t, r = o ? "var(--color-primary-500)" : n ?? Te;
1714
+ return Oe({
1715
+ className: "",
1716
+ html: `<div style="position:relative;width:20px;height:28px">
1717
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="28" viewBox="0 0 20 28" style="position:relative;z-index:1;display:block">
1718
+ <path d="${_n}" fill-rule="evenodd"${!o && r === Te ? ' data-elm-plain="1"' : ""} style="fill:${r}"/>
1719
+ </svg>
1720
+ </div>`,
1721
+ iconSize: [20, 28],
1722
+ iconAnchor: [10, 28]
1723
+ });
1724
+ }
1725
+ function mt(t, e) {
1726
+ var o, r;
1727
+ const n = (r = (o = t == null ? void 0 : t.getElement) == null ? void 0 : o.call(t)) == null ? void 0 : r.querySelector("path[data-elm-plain]");
1728
+ n && (n.style.fill = e ? "#334155" : Te);
1729
+ }
1730
+ const Vt = /* @__PURE__ */ new Map();
1731
+ function qt(t = Te) {
1732
+ let e = Vt.get(t);
1733
+ return e || (Vt.size >= 256 && Vt.clear(), Vt.set(t, e = Lt(!1, !1, t))), e;
1734
+ }
1735
+ function Pn(t = Te) {
1736
+ return Oe({
1737
+ className: "",
1738
+ html: `<div style="position:relative;width:20px;height:28px;opacity:0.3">
1739
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="28" viewBox="0 0 20 28" style="display:block">
1740
+ <path d="${_n}" fill-rule="evenodd" style="fill:${t}"/>
1741
+ </svg>
1742
+ </div>`,
1743
+ iconSize: [20, 28],
1744
+ iconAnchor: [10, 28]
1745
+ });
1746
+ }
1747
+ function Io(t, e) {
1748
+ const n = $(!1);
1749
+ return {
1750
+ isDupDrag: t ? n.current : e,
1751
+ setDuplicateDrag: (r) => {
1752
+ n.current = r;
1753
+ },
1754
+ resetDuplicateDrag: () => {
1755
+ n.current = !1;
1756
+ }
1757
+ };
1758
+ }
1759
+ const Vi = {
1760
+ weight: 3,
1761
+ opacity: 0.5,
1762
+ dashArray: "6 4",
1763
+ interactive: !1
1764
+ }, Xi = {
1765
+ weight: 2,
1766
+ opacity: 0.5,
1767
+ fillOpacity: 0.15,
1768
+ dashArray: "6 4",
1769
+ interactive: !1
1770
+ };
1771
+ function Ao(t, e, n) {
1772
+ return typeof t[0] == "number" ? [t[0] + e, t[1] + n] : t.map((o) => Ao(o, e, n));
1773
+ }
1774
+ function Cn(t, e, n, o) {
1775
+ if (!e) return { display: t, ghost: null };
1776
+ const r = o === "visual" ? We(t, e[0], e[1]) : Ao(t, e[0], e[1]);
1777
+ return n ? { display: t, ghost: r } : { display: r, ghost: null };
1778
+ }
1779
+ function zi(t) {
1780
+ return t && "style" in t ? t : null;
1781
+ }
1782
+ const Xt = /* @__PURE__ */ new Set();
1783
+ let Qn = !1;
1784
+ function Gi() {
1785
+ if (Qn || typeof window > "u") return;
1786
+ Qn = !0;
1787
+ const t = (e) => {
1788
+ for (const n of Xt) n(e);
1789
+ };
1790
+ window.addEventListener("keydown", t), window.addEventListener("keyup", t);
1791
+ }
1792
+ function _t(t) {
1793
+ const e = $(null), n = $(!1), o = $({ value: "", priority: "" });
1794
+ function r(g, P, d = "important") {
1795
+ g.style.setProperty("cursor", P, d);
1796
+ }
1797
+ const a = $(t);
1798
+ a.current = t;
1799
+ const i = $((g) => {
1800
+ if (a.current || !n.current) return;
1801
+ const P = e.current;
1802
+ if (!P) return;
1803
+ const d = g.ctrlKey || g.metaKey, p = g.altKey;
1804
+ d || p ? r(P, p ? "copy" : "move") : r(P, o.current.value, o.current.priority);
1805
+ }).current;
1806
+ Q(() => () => {
1807
+ Xt.delete(i);
1808
+ }, [i]);
1809
+ const l = Fe((g, P) => {
1810
+ const d = zi(g), p = d !== null && d === e.current && n.current;
1811
+ e.current = d, n.current = !0, Gi(), Xt.add(i), p || (o.current = {
1812
+ value: (d == null ? void 0 : d.style.getPropertyValue("cursor")) ?? "",
1813
+ priority: (d == null ? void 0 : d.style.getPropertyPriority("cursor")) ?? ""
1814
+ });
1815
+ const C = P;
1816
+ d && C && (C.ctrlKey || C.metaKey || C.altKey) && r(d, C.altKey ? "copy" : "move");
1817
+ }, []), s = Fe(() => {
1818
+ n.current = !1, Xt.delete(i), e.current && (r(e.current, o.current.value, o.current.priority), e.current = null), o.current = { value: "", priority: "" };
1819
+ }, []), u = Fe((g) => {
1820
+ n.current && (s(), l(g, nn()));
1821
+ }, [l, s]);
1822
+ return { enter: l, leave: s, retarget: u };
1823
+ }
1824
+ const eo = Oe({ className: "hidden" }), Yi = Ze(function({
1825
+ feature: e,
1826
+ selected: n,
1827
+ isMultiSelected: o,
1828
+ multiDragDelta: r,
1829
+ multiDuplicateDrag: a,
1830
+ readonly: i,
1831
+ suppressDoubleClickZoomForGesture: l
1832
+ }) {
1833
+ const { dataStore: s } = De(), u = Se((c) => c.updateFeature), g = e.geometry.coordinates, [P, d] = de(null), p = $(null), C = $(null), M = $(null), S = $(null), m = $(!1), { isDupDrag: y, setDuplicateDrag: x, resetDuplicateDrag: f } = Io(P, a), h = $(null), [I, z] = de(!e.properties.name), [k, H] = de(!1), D = _t(i), _ = p.current ?? P, F = o && r ? r : _, { display: Y, ghost: L } = Cn(g, F, y, s.getState().geometryMode);
1834
+ function V(c) {
1835
+ if (i) return;
1836
+ m.current = !1;
1837
+ const E = c.originalEvent.altKey, B = c.originalEvent.ctrlKey || c.originalEvent.metaKey;
1838
+ if (!E && !B || o && s.getState().selectedIds.length >= 2) return;
1839
+ c.originalEvent.preventDefault(), c.originalEvent.stopPropagation();
1840
+ const J = c.target._map || window._leafletMap;
1841
+ if (!J) return;
1842
+ J.dragging.disable();
1843
+ const j = E;
1844
+ if (x(j), s.getState().geometryMode === "visual") {
1845
+ const X = ke([c.latlng.lng, c.latlng.lat]);
1846
+ S.current = { lng: X[0], lat: X[1] };
1847
+ } else
1848
+ S.current = { lng: c.latlng.lng, lat: c.latlng.lat };
1849
+ !n && !o && s.getState().selectFeature(e.id), d([0, 0]);
1850
+ function te(X) {
1851
+ var ge, ne;
1852
+ if (!S.current) return;
1853
+ m.current || Ue(!0), m.current = !0;
1854
+ const v = s.getState().geometryMode, U = v === "visual" ? (() => {
1855
+ const fe = ke([X.latlng.lng, X.latlng.lat]);
1856
+ return [fe[0] - S.current.lng, fe[1] - S.current.lat];
1857
+ })() : [X.latlng.lng - S.current.lng, X.latlng.lat - S.current.lat];
1858
+ p.current = U;
1859
+ const ee = v === "visual" ? We(g, U[0], U[1]) : [g[0] + U[0], g[1] + U[1]], q = G(ee);
1860
+ j ? (ge = M.current) == null || ge.setLatLng(q) : (ne = C.current) == null || ne.setLatLng(q);
1861
+ }
1862
+ function ue(X) {
1863
+ if (J.off("mousemove", te), J.off("mouseup", ue), J.dragging.enable(), Ue(!1), !S.current || !m.current) {
1864
+ S.current = null, f(), p.current = null, d(null);
1865
+ return;
1866
+ }
1867
+ const v = s.getState().geometryMode;
1868
+ let U, ee;
1869
+ if (v === "visual") {
1870
+ const ge = ke([X.latlng.lng, X.latlng.lat]);
1871
+ U = ge[0] - S.current.lng, ee = ge[1] - S.current.lat;
1872
+ } else
1873
+ U = X.latlng.lng - S.current.lng, ee = X.latlng.lat - S.current.lat;
1874
+ S.current = null, f(), p.current = null, d(null);
1875
+ const q = v === "visual" ? We(g, U, ee) : zt(g, [g[0] + U, g[1] + ee]);
1876
+ j ? s.getState().duplicateFeaturesAtPosition([{ sourceId: e.id, geometry: { type: "Point", coordinates: q } }]) : u(e.id, { geometry: { type: "Point", coordinates: q } });
1877
+ }
1878
+ J.on("mousemove", te), J.on("mouseup", ue);
1879
+ }
1880
+ const R = e.properties.name || "";
1881
+ return Q(() => {
1882
+ n || z(!1);
1883
+ }, [n]), Q(() => {
1884
+ I && h.current && setTimeout(() => {
1885
+ var c;
1886
+ return (c = h.current) == null ? void 0 : c.focus();
1887
+ }, 50);
1888
+ }, [I]), /* @__PURE__ */ le(xe, { children: [
1889
+ /* @__PURE__ */ w(
1890
+ Le,
1891
+ {
1892
+ ref: (c) => {
1893
+ C.current = c;
1894
+ },
1895
+ position: G(Y),
1896
+ icon: eo,
1897
+ eventHandlers: {
1898
+ mousedown: V,
1899
+ click: (c) => {
1900
+ c.originalEvent.stopPropagation(), c.originalEvent.shiftKey && !i ? s.getState().toggleSelection(e.id) : !n && !o && s.getState().selectFeature(e.id), !i && !c.originalEvent.shiftKey && setTimeout(() => {
1901
+ var E;
1902
+ return (E = h.current) == null ? void 0 : E.focus();
1903
+ }, 50);
1904
+ }
1905
+ },
1906
+ children: /* @__PURE__ */ w(
1907
+ hn,
1908
+ {
1909
+ permanent: !0,
1910
+ interactive: !0,
1911
+ direction: "center",
1912
+ className: "!bg-transparent !border-0 !shadow-none !p-0",
1913
+ eventHandlers: {
1914
+ click: (c) => {
1915
+ c.originalEvent.stopPropagation(), c.originalEvent.shiftKey && !i ? s.getState().toggleSelection(e.id) : !i && !n && s.getState().selectFeature(e.id), !i && !c.originalEvent.shiftKey && n && setTimeout(() => {
1916
+ var E;
1917
+ return (E = h.current) == null ? void 0 : E.focus();
1918
+ }, 50);
1919
+ },
1920
+ dblclick: (c) => {
1921
+ c.originalEvent.stopPropagation(), l == null || l(), i || (s.getState().selectFeature(e.id), z(!0));
1922
+ },
1923
+ mouseover: (c) => {
1924
+ var E, B;
1925
+ D.enter((B = (E = c.target).getElement) == null ? void 0 : B.call(E), c.originalEvent), H(!0);
1926
+ },
1927
+ mouseout: () => {
1928
+ D.leave(), H(!1);
1929
+ },
1930
+ mousedown: () => {
1931
+ }
1932
+ },
1933
+ children: /* @__PURE__ */ w(
1934
+ "div",
1935
+ {
1936
+ className: `flex items-center justify-center w-max px-3 py-1.5 rounded text-sm font-medium transition-colors border ${I && !F ? "bg-white/95 backdrop-blur-md border border-gray-800 text-gray-800" : n ? "bg-primary-500 text-white" : k ? "bg-slate-700 text-white" : "bg-slate-600 text-white"} ${F && !y ? "cursor-grabbing opacity-80" : ""}`,
1937
+ onMouseDown: (c) => {
1938
+ c.target === h.current && c.stopPropagation();
1939
+ },
1940
+ children: i || !I || F ? /* @__PURE__ */ w("div", { className: "whitespace-pre min-w-[12px] text-center text-inherit cursor-pointer leading-tight", children: R || " " }) : /* @__PURE__ */ le("div", { className: "grid items-center justify-items-center text-center leading-tight", children: [
1941
+ /* @__PURE__ */ w(
1942
+ "div",
1943
+ {
1944
+ className: "invisible whitespace-pre pointer-events-none col-start-1 row-start-1 min-w-[12px] px-[2px]",
1945
+ "aria-hidden": "true",
1946
+ children: R + " "
1947
+ }
1948
+ ),
1949
+ /* @__PURE__ */ w(
1950
+ "textarea",
1951
+ {
1952
+ ref: h,
1953
+ autoFocus: !0,
1954
+ value: R,
1955
+ onChange: (c) => {
1956
+ u(e.id, { properties: { ...e.properties, name: c.target.value } });
1957
+ },
1958
+ onKeyDown: (c) => {
1959
+ c.key === "Enter" && !c.shiftKey && (c.preventDefault(), z(!1), s.getState().selectFeature(null));
1960
+ },
1961
+ onBlur: () => z(!1),
1962
+ className: "bg-transparent outline-none resize-none overflow-hidden text-center text-inherit whitespace-pre min-w-0 min-h-0 col-start-1 row-start-1 px-[2px] w-full h-full m-0 border-none justify-self-stretch self-stretch"
1963
+ }
1964
+ )
1965
+ ] })
1966
+ }
1967
+ )
1968
+ }
1969
+ )
1970
+ }
1971
+ ),
1972
+ L && /* @__PURE__ */ w(
1973
+ Le,
1974
+ {
1975
+ ref: (c) => {
1976
+ M.current = c;
1977
+ },
1978
+ position: G(L),
1979
+ icon: eo,
1980
+ draggable: !1,
1981
+ opacity: 0.5,
1982
+ interactive: !1,
1983
+ children: /* @__PURE__ */ w(hn, { permanent: !0, direction: "center", className: "!bg-transparent !border-0 !shadow-none !p-0", children: /* @__PURE__ */ w("div", { className: "flex items-center justify-center w-max px-3 py-1.5 rounded text-sm font-medium border bg-primary-500/60 text-white/80 border-primary-400/40", style: { borderStyle: "dashed" }, children: /* @__PURE__ */ w("div", { className: "whitespace-pre min-w-[12px] text-center text-inherit leading-tight", children: R || " " }) }) })
1984
+ }
1985
+ )
1986
+ ] });
1987
+ });
1988
+ function sn(t, e, n, o, r, a, i) {
1989
+ const { dataStore: l, uiStore: s } = De(), u = Se((f) => f.updateFeature), g = be(), [P, d] = de(null), p = $(null), C = $(null), M = $(!1), S = $(i);
1990
+ S.current = i;
1991
+ const m = p.current ?? P, y = n && o ? o : m;
1992
+ function x(f, h) {
1993
+ if (r || (M.current = !1, !h.originalEvent.ctrlKey && !h.originalEvent.metaKey) || n && l.getState().selectedIds.length >= 2) return;
1994
+ if (h.originalEvent.preventDefault(), h.originalEvent.stopPropagation(), g.dragging.disable(), l.getState().geometryMode === "visual") {
1995
+ const H = ke([h.latlng.lng, h.latlng.lat]);
1996
+ C.current = { lng: H[0], lat: H[1] };
1997
+ } else
1998
+ C.current = { lng: h.latlng.lng, lat: h.latlng.lat };
1999
+ !e && !n && l.getState().selectFeature(t.id), d([0, 0]);
2000
+ function z(H) {
2001
+ if (!C.current) return;
2002
+ a.markDragStart(), M.current = !0;
2003
+ const D = l.getState().geometryMode, _ = D === "visual" ? (() => {
2004
+ const Y = ke([H.latlng.lng, H.latlng.lat]);
2005
+ return [Y[0] - C.current.lng, Y[1] - C.current.lat];
2006
+ })() : [H.latlng.lng - C.current.lng, H.latlng.lat - C.current.lat];
2007
+ p.current = _;
2008
+ const F = e ? s.getState().selectedPartIndex : null;
2009
+ S.current ? S.current(_, D, F) : d(_);
2010
+ }
2011
+ function k(H) {
2012
+ if (g.off("mousemove", z), g.off("mouseup", k), g.dragging.enable(), !C.current || !M.current) {
2013
+ C.current = null, p.current = null, d(null);
2014
+ return;
2015
+ }
2016
+ const D = C.current, _ = l.getState().geometryMode;
2017
+ let F, Y;
2018
+ if (_ === "visual") {
2019
+ const c = ke([H.latlng.lng, H.latlng.lat]);
2020
+ F = c[0] - D.lng, Y = c[1] - D.lat;
2021
+ } else
2022
+ F = H.latlng.lng - D.lng, Y = H.latlng.lat - D.lat;
2023
+ C.current = null, p.current = null, d(null), l.getState().takeSnapshot();
2024
+ const L = [F, Y], V = _ === "visual", R = s.getState().selectedPartIndex;
2025
+ if (R != null) {
2026
+ const c = qo(t.geometry, R), E = Jo(t.geometry, R, Qo(c, L, V));
2027
+ u(t.id, { geometry: E });
2028
+ } else
2029
+ u(t.id, { geometry: Jt(t.geometry, L, V) });
2030
+ a.markDragEnd();
2031
+ }
2032
+ g.on("mousemove", z), g.on("mouseup", k);
2033
+ }
2034
+ return { effectiveDelta: y, dragged: M, handleMouseDown: x };
2035
+ }
2036
+ function ji({ geom: t, delta: e, keyPrefix: n, active: o, selectedPart: r, linePathOptions: a, polyPathOptions: i, pinSelected: l, pinMultiSelected: s, pinIdle: u, handlers: g, visual: P = !1 }) {
2037
+ const d = e ? (y) => We(y, e[0], e[1]) : (y) => y, p = e ? P ? (y) => We([y], e[0], e[1])[0] : ([y, x]) => [y + e[0], x + e[1]] : (y) => y, C = { ...a, opacity: 0.25 }, M = { ...i, opacity: 0.2, fillOpacity: 0.08 }, S = r ? a : C, m = r ? i : M;
2038
+ if (t.type === "Point")
2039
+ return /* @__PURE__ */ w(
2040
+ Le,
2041
+ {
2042
+ position: G(p(t.coordinates)),
2043
+ icon: o ? r ? Lt(l, s, u) : Pn(u) : qt(u),
2044
+ draggable: !1,
2045
+ eventHandlers: g
2046
+ }
2047
+ );
2048
+ if (t.type === "MultiPoint")
2049
+ return /* @__PURE__ */ w(xe, { children: t.coordinates.map((y, x) => /* @__PURE__ */ w(
2050
+ Le,
2051
+ {
2052
+ position: G(p(y)),
2053
+ icon: o ? r ? Lt(l, s, u) : Pn(u) : qt(u),
2054
+ draggable: !1,
2055
+ eventHandlers: g
2056
+ },
2057
+ `${n}-pt${x}`
2058
+ )) });
2059
+ if (t.type === "LineString") {
2060
+ const y = (e ? d(t.coordinates) : t.coordinates).map(G);
2061
+ return /* @__PURE__ */ le(xe, { children: [
2062
+ /* @__PURE__ */ w(ve, { positions: y, pathOptions: S, interactive: !1 }),
2063
+ /* @__PURE__ */ w(ve, { positions: y, pathOptions: { color: "#000", weight: Wt, opacity: 1e-3 }, eventHandlers: g })
2064
+ ] });
2065
+ }
2066
+ if (t.type === "MultiLineString") {
2067
+ const y = e ? d(t.coordinates) : t.coordinates;
2068
+ return /* @__PURE__ */ w(xe, { children: y.map((x, f) => {
2069
+ const h = x.map(G);
2070
+ return /* @__PURE__ */ le(En.Fragment, { children: [
2071
+ /* @__PURE__ */ w(ve, { positions: h, pathOptions: S, interactive: !1 }),
2072
+ /* @__PURE__ */ w(ve, { positions: h, pathOptions: { color: "#000", weight: Wt, opacity: 1e-3 }, eventHandlers: g })
2073
+ ] }, `${n}-ln${f}`);
2074
+ }) });
2075
+ }
2076
+ if (t.type === "Polygon") {
2077
+ const x = (e ? d(t.coordinates) : t.coordinates).map((f) => f.map(G));
2078
+ return /* @__PURE__ */ w(He, { positions: x, pathOptions: m, eventHandlers: g });
2079
+ }
2080
+ if (t.type === "MultiPolygon") {
2081
+ const y = e ? d(t.coordinates) : t.coordinates;
2082
+ return /* @__PURE__ */ w(xe, { children: y.map((x, f) => {
2083
+ const h = x.map((I) => I.map(G));
2084
+ return /* @__PURE__ */ w(He, { positions: h, pathOptions: m, eventHandlers: g }, `${n}-part${f}`);
2085
+ }) });
2086
+ }
2087
+ return null;
2088
+ }
2089
+ const Ui = Ze(
2090
+ function({ feature: e, selected: n, isMultiSelected: o, multiDragDelta: r, readonly: a, interaction: i, onContextMenu: l }) {
2091
+ const { dataStore: s, uiStore: u } = De(), g = Se((D) => D.toggleSelection), P = K((D) => D.setSelectedPartIndex), d = K((D) => D.selectedPartIndex), [p, C] = de(!1), { effectiveDelta: M, dragged: S, handleMouseDown: m } = sn(e, n, o, r, a, i), y = yt(It)[500], x = vt(e);
2092
+ if (e.geometry.type !== "GeometryCollection") return null;
2093
+ function f(D) {
2094
+ return {
2095
+ mouseover: (_) => {
2096
+ Dt(_.target, e, u, _.latlng, _.originalEvent), C(!0), mt(_.target, !0);
2097
+ },
2098
+ mouseout: (_) => {
2099
+ ct(_.target), C(!1), mt(_.target, !1);
2100
+ },
2101
+ click: (_) => {
2102
+ if (u.getState().editingMode === "none")
2103
+ if (_.originalEvent.stopPropagation(), _.originalEvent.shiftKey && !a) {
2104
+ if (!i.shouldHandleFeatureClick(S.current)) return;
2105
+ g(e.id);
2106
+ } else if (n) {
2107
+ if (S.current) return;
2108
+ i.markFeatureClick(), P(d === D ? null : D);
2109
+ } else {
2110
+ if (!i.shouldHandleFeatureClick(S.current)) return;
2111
+ i.markFeatureClick(), s.getState().selectFeature(e.id);
2112
+ }
2113
+ },
2114
+ mousedown: (_) => m(D, _),
2115
+ contextmenu: At(e, a, l)
2116
+ };
2117
+ }
2118
+ const h = o || n || !!M, I = n && d != null, z = o || n || !!M, k = z ? Et(x, !1, { color: o || n ? y : Te, weight: n ? 4.5 : 3.5, opacity: p ? 1 : 0.9 }) : Mt(Kn, x, p ? { opacity: 1 } : null), H = z ? Et(x, !0, {
2119
+ color: o || n ? y : Te,
2120
+ fillColor: o || n ? y : Te,
2121
+ weight: n ? 3 : 2,
2122
+ opacity: p ? 1 : 0.9,
2123
+ fillOpacity: n ? 0.25 : p ? 0.28 : 0.15,
2124
+ className: M ? "cursor-grabbing" : ""
2125
+ }) : Mt(Hn, x, p ? Bn : null);
2126
+ return /* @__PURE__ */ w(xe, { children: e.geometry.geometries.map((D, _) => {
2127
+ const F = M ? I ? _ === d ? M : null : M : null, L = !I || d === _;
2128
+ return /* @__PURE__ */ w(En.Fragment, { children: /* @__PURE__ */ w(ji, { geom: D, delta: F, keyPrefix: `gc-${_}`, active: h, selectedPart: L, linePathOptions: k, polyPathOptions: H, pinSelected: n, pinMultiSelected: o, pinIdle: $n(x), handlers: f(_), visual: s.getState().geometryMode === "visual" }) }, _);
2129
+ }) });
2130
+ },
2131
+ (t, e) => t.feature === e.feature && t.selected === e.selected && t.isMultiSelected === e.isMultiSelected && t.multiDragDelta === e.multiDragDelta && t.readonly === e.readonly && t.interaction === e.interaction
2132
+ );
2133
+ function Vn(t, e, n, o, r, a, i, l, s, u) {
2134
+ const { dataStore: g } = De(), P = Se((D) => D.updateFeature), d = be(), [p, C] = de(null), M = $(null), S = $(null), m = $(!1), { isDupDrag: y, setDuplicateDrag: x, resetDuplicateDrag: f } = Io(p, i), h = M.current ?? p, I = r && a ? a : h, { display: z, ghost: k } = Cn(n, I, y, g.getState().geometryMode);
2135
+ function H(D) {
2136
+ if (l) return;
2137
+ m.current = !1;
2138
+ const _ = D.originalEvent.altKey, F = D.originalEvent.ctrlKey || D.originalEvent.metaKey;
2139
+ if (!_ && !F || r && g.getState().selectedIds.length >= 2) return;
2140
+ D.originalEvent.preventDefault(), D.originalEvent.stopPropagation(), d.dragging.disable();
2141
+ const Y = _;
2142
+ if (x(Y), g.getState().geometryMode === "visual") {
2143
+ const c = ke([D.latlng.lng, D.latlng.lat]);
2144
+ S.current = { lng: c[0], lat: c[1] };
2145
+ } else
2146
+ S.current = { lng: D.latlng.lng, lat: D.latlng.lat };
2147
+ !o && !r && g.getState().selectFeature(t.id), C([0, 0]);
2148
+ function V(c) {
2149
+ if (!S.current) return;
2150
+ s.markDragStart(), m.current = !0;
2151
+ const E = g.getState().geometryMode, B = E === "visual" ? (() => {
2152
+ const J = ke([c.latlng.lng, c.latlng.lat]);
2153
+ return [J[0] - S.current.lng, J[1] - S.current.lat];
2154
+ })() : [c.latlng.lng - S.current.lng, c.latlng.lat - S.current.lat];
2155
+ M.current = B, u(Cn(n, B, !1, E).display, Y);
2156
+ }
2157
+ function R(c) {
2158
+ if (d.off("mousemove", V), d.off("mouseup", R), d.dragging.enable(), !S.current || !m.current) {
2159
+ S.current = null, f(), M.current = null, C(null);
2160
+ return;
2161
+ }
2162
+ const E = S.current, B = g.getState().geometryMode;
2163
+ let J, j;
2164
+ if (B === "visual") {
2165
+ const ue = ke([c.latlng.lng, c.latlng.lat]);
2166
+ J = ue[0] - E.lng, j = ue[1] - E.lat;
2167
+ } else
2168
+ J = c.latlng.lng - E.lng, j = c.latlng.lat - E.lat;
2169
+ S.current = null, f(), M.current = null, C(null);
2170
+ const ce = B === "visual" ? We(n, J, j) : er(n, [E.lng, E.lat], [c.latlng.lng, c.latlng.lat]), te = { type: e, coordinates: ce };
2171
+ Y ? g.getState().duplicateFeaturesAtPosition([{ sourceId: t.id, geometry: te }]) : (g.getState().takeSnapshot(), P(t.id, { geometry: te })), s.markDragEnd();
2172
+ }
2173
+ d.on("mousemove", V), d.on("mouseup", R);
2174
+ }
2175
+ return { effectiveDelta: I, display: z, ghost: k, dragged: m, handleMouseDown: H };
2176
+ }
2177
+ const Wi = Ze(
2178
+ function({ feature: e, selected: n, isMultiSelected: o, onVertexEdit: r, multiDragDelta: a, multiDuplicateDrag: i, readonly: l, interaction: s, onContextMenu: u }) {
2179
+ const { dataStore: g, uiStore: P } = De(), d = Se((L) => L.toggleSelection), p = yt(It)[500], C = e.geometry.coordinates, M = $(null), S = $(null), m = $(null), [y, x] = de(!1), f = _t(l), h = vt(e), I = rn(n || o, () => [M.current, m.current], {
2180
+ before: (L, V) => {
2181
+ L === M.current && (L.options.interactive = V);
2182
+ },
2183
+ after: () => {
2184
+ const L = (I ? M : m).current;
2185
+ L && f.retarget(Zt(L));
2186
+ }
2187
+ }), { effectiveDelta: z, display: k, ghost: H, dragged: D, handleMouseDown: _ } = Vn(
2188
+ e,
2189
+ "LineString",
2190
+ C,
2191
+ n,
2192
+ o,
2193
+ a,
2194
+ i,
2195
+ l,
2196
+ s,
2197
+ (L, V) => {
2198
+ var R;
2199
+ return (R = (V ? S : M).current) == null ? void 0 : R.setLatLngs(L.map(G));
2200
+ }
2201
+ ), F = _e(() => k.map(G), [k]), Y = {
2202
+ mouseover: (L) => {
2203
+ f.enter(Zt(L.target), L.originalEvent), Dt(L.target, e, P, L.latlng, L.originalEvent), P.getState().vertexEditActive || x(!0);
2204
+ },
2205
+ mouseout: (L) => {
2206
+ f.leave(), ct(L.target), x(!1);
2207
+ },
2208
+ click: (L) => {
2209
+ P.getState().editingMode === "none" && (L.originalEvent.stopPropagation(), s.shouldHandleFeatureClick(D.current) && (L.originalEvent.shiftKey && !l ? d(e.id) : (s.markFeatureClick(), g.getState().selectFeature(e.id))));
2210
+ },
2211
+ dblclick: (L) => {
2212
+ P.getState().editingMode === "none" && (L.originalEvent.stopPropagation(), l || r());
2213
+ },
2214
+ contextmenu: At(e, l, u),
2215
+ mousedown: _
2216
+ };
2217
+ return /* @__PURE__ */ le(xe, { children: [
2218
+ /* @__PURE__ */ w(
2219
+ ve,
2220
+ {
2221
+ ref: (L) => {
2222
+ M.current = L;
2223
+ },
2224
+ positions: F,
2225
+ pathOptions: n || o || z ? Et(h, !1, {
2226
+ color: o || n ? p : Te,
2227
+ weight: n || y ? 4.5 : 3.5,
2228
+ opacity: y ? 1 : 0.9
2229
+ }) : Mt(Kn, h, y ? { weight: 4.5, opacity: 1 } : null),
2230
+ renderer: I,
2231
+ interactive: !!I,
2232
+ eventHandlers: Y
2233
+ }
2234
+ ),
2235
+ !I && /* @__PURE__ */ w(
2236
+ ve,
2237
+ {
2238
+ ref: (L) => {
2239
+ m.current = L;
2240
+ },
2241
+ positions: F,
2242
+ pathOptions: { color: "#000", weight: Wt, opacity: 1e-3 },
2243
+ eventHandlers: Y
2244
+ }
2245
+ ),
2246
+ H && /* @__PURE__ */ w(
2247
+ ve,
2248
+ {
2249
+ ref: (L) => {
2250
+ S.current = L;
2251
+ },
2252
+ positions: H.map(G),
2253
+ pathOptions: { ...Vi, color: p }
2254
+ }
2255
+ )
2256
+ ] });
2257
+ },
2258
+ (t, e) => t.feature === e.feature && t.selected === e.selected && t.isMultiSelected === e.isMultiSelected && t.multiDragDelta === e.multiDragDelta && t.multiDuplicateDrag === e.multiDuplicateDrag && t.readonly === e.readonly && t.interaction === e.interaction
2259
+ ), Zi = Ze(
2260
+ function({ feature: e, selected: n, isMultiSelected: o, multiDragDelta: r, readonly: a, interaction: i, onContextMenu: l }) {
2261
+ const { dataStore: s, uiStore: u } = De(), g = Se((L) => L.toggleSelection), P = K((L) => L.setSelectedPartIndex), d = K((L) => L.selectedPartIndex), p = e.geometry.coordinates, [C, M] = de(!1), S = $(/* @__PURE__ */ new Map()), m = $(/* @__PURE__ */ new Map()), y = vt(e), x = rn(n || o, () => [...S.current.values(), ...m.current.values()], {
2262
+ before: (L, V) => {
2263
+ [...S.current.values()].includes(L) && (L.options.interactive = V);
2264
+ }
2265
+ }), { effectiveDelta: f, dragged: h, handleMouseDown: I } = sn(
2266
+ e,
2267
+ n,
2268
+ o,
2269
+ r,
2270
+ a,
2271
+ i,
2272
+ (L, V, R) => {
2273
+ for (let c = 0; c < p.length; c++) {
2274
+ if (R != null && R !== c) continue;
2275
+ const E = S.current.get(c);
2276
+ if (!E) continue;
2277
+ const B = V === "visual" ? We([p[c]], L[0], L[1])[0] : p[c].map(([J, j]) => [J + L[0], j + L[1]]);
2278
+ E.setLatLngs(B.map(G));
2279
+ }
2280
+ }
2281
+ ), z = yt(It)[500], k = n ? d : null, D = p.map((L, V) => f && (k == null || k === V) ? s.getState().geometryMode === "visual" ? We([L], f[0], f[1])[0] : L.map(([c, E]) => [c + f[0], E + f[1]]) : L).map((L) => L.map(G)), _ = n && d != null, F = o || n || f ? Et(y, !1, {
2282
+ color: o || n ? z : Te,
2283
+ weight: n ? 4.5 : 3.5,
2284
+ opacity: C ? 1 : 0.9
2285
+ }) : Mt(Kn, y, C ? { opacity: 1 } : null), Y = { ...F, opacity: 0.25 };
2286
+ return /* @__PURE__ */ w(xe, { children: D.map((L, V) => {
2287
+ const c = !_ || d === V ? F : Y, E = {
2288
+ mouseover: () => {
2289
+ u.getState().vertexEditActive || M(!0);
2290
+ },
2291
+ mouseout: () => M(!1),
2292
+ click: (B) => {
2293
+ if (u.getState().editingMode === "none")
2294
+ if (B.originalEvent.stopPropagation(), B.originalEvent.shiftKey && !a) {
2295
+ if (!i.shouldHandleFeatureClick(h.current)) return;
2296
+ g(e.id);
2297
+ } else if (n) {
2298
+ if (h.current) return;
2299
+ i.markFeatureClick(), P(d === V ? null : V);
2300
+ } else {
2301
+ if (!i.shouldHandleFeatureClick(h.current)) return;
2302
+ i.markFeatureClick(), s.getState().selectFeature(e.id);
2303
+ }
2304
+ },
2305
+ dblclick: (B) => {
2306
+ u.getState().editingMode === "none" && B.originalEvent.stopPropagation();
2307
+ },
2308
+ mousedown: (B) => I(V, B),
2309
+ contextmenu: At(e, a, l)
2310
+ };
2311
+ return /* @__PURE__ */ le(En.Fragment, { children: [
2312
+ /* @__PURE__ */ w(
2313
+ ve,
2314
+ {
2315
+ ref: (B) => {
2316
+ B ? S.current.set(V, B) : S.current.delete(V);
2317
+ },
2318
+ positions: L,
2319
+ pathOptions: c,
2320
+ renderer: x,
2321
+ interactive: !!x,
2322
+ eventHandlers: E
2323
+ }
2324
+ ),
2325
+ !x && /* @__PURE__ */ w(
2326
+ ve,
2327
+ {
2328
+ ref: (B) => {
2329
+ B ? m.current.set(V, B) : m.current.delete(V);
2330
+ },
2331
+ positions: L,
2332
+ pathOptions: { color: "#000", weight: Wt, opacity: 1e-3 },
2333
+ eventHandlers: E
2334
+ }
2335
+ )
2336
+ ] }, `line-part-${V}`);
2337
+ }) });
2338
+ },
2339
+ (t, e) => t.feature === e.feature && t.selected === e.selected && t.isMultiSelected === e.isMultiSelected && t.multiDragDelta === e.multiDragDelta && t.readonly === e.readonly && t.interaction === e.interaction
2340
+ ), qi = Ze(
2341
+ function({ feature: e, selected: n, isMultiSelected: o, multiDragDelta: r, readonly: a, interaction: i, onContextMenu: l }) {
2342
+ const { dataStore: s, uiStore: u } = De(), g = Se((k) => k.toggleSelection), P = K((k) => k.setSelectedPartIndex), d = K((k) => k.selectedPartIndex), p = e.geometry.coordinates, C = $n(vt(e)), M = $(/* @__PURE__ */ new Map()), S = _t(a), { effectiveDelta: m, dragged: y, handleMouseDown: x } = sn(
2343
+ e,
2344
+ n,
2345
+ o,
2346
+ r,
2347
+ a,
2348
+ i,
2349
+ (k, H, D) => {
2350
+ for (let _ = 0; _ < p.length; _++) {
2351
+ if (D != null && D !== _) continue;
2352
+ const F = M.current.get(_);
2353
+ if (!F) continue;
2354
+ const Y = p[_], L = H === "visual" ? We([Y], k[0], k[1])[0] : [Y[0] + k[0], Y[1] + k[1]];
2355
+ F.setLatLng(G(L));
2356
+ }
2357
+ }
2358
+ ), f = n ? d : null, h = p.map((k, H) => m && (f == null || f === H) ? s.getState().geometryMode === "visual" ? We([k], m[0], m[1])[0] : [k[0] + m[0], k[1] + m[1]] : k), I = o || n || !!m, z = n && d != null;
2359
+ return /* @__PURE__ */ w(xe, { children: h.map((k, H) => /* @__PURE__ */ w(
2360
+ Le,
2361
+ {
2362
+ ref: (D) => {
2363
+ D ? M.current.set(H, D) : M.current.delete(H);
2364
+ },
2365
+ position: G(k),
2366
+ icon: I ? z && d !== H ? Pn(C) : Lt(n && (!z || d === H), o, C) : qt(C),
2367
+ draggable: !1,
2368
+ eventHandlers: {
2369
+ mouseover: (D) => {
2370
+ var _, F;
2371
+ S.enter((F = (_ = D.target).getElement) == null ? void 0 : F.call(_), D.originalEvent), Dt(D.target, e, u, D.latlng, D.originalEvent), u.getState().vertexEditActive || mt(D.target, !0);
2372
+ },
2373
+ mouseout: (D) => {
2374
+ S.leave(), ct(D.target), mt(D.target, !1);
2375
+ },
2376
+ click: (D) => {
2377
+ if (u.getState().editingMode === "none")
2378
+ if (D.originalEvent.stopPropagation(), D.originalEvent.shiftKey && !a) {
2379
+ if (!i.shouldHandleFeatureClick(y.current)) return;
2380
+ g(e.id);
2381
+ } else if (n) {
2382
+ if (y.current) return;
2383
+ i.markFeatureClick(), P(d === H ? null : H);
2384
+ } else {
2385
+ if (!i.shouldHandleFeatureClick(y.current)) return;
2386
+ i.markFeatureClick(), s.getState().selectFeature(e.id);
2387
+ }
2388
+ },
2389
+ mousedown: (D) => x(H, D),
2390
+ contextmenu: At(e, a, l)
2391
+ }
2392
+ },
2393
+ `pt-${k[0].toFixed(8)},${k[1].toFixed(8)}-${H}`
2394
+ )) });
2395
+ },
2396
+ (t, e) => t.feature === e.feature && t.selected === e.selected && t.isMultiSelected === e.isMultiSelected && t.multiDragDelta === e.multiDragDelta && t.readonly === e.readonly && t.interaction === e.interaction
2397
+ ), Ji = Ze(
2398
+ function({ feature: e, selected: n, isMultiSelected: o, multiDragDelta: r, onVertexEdit: a, readonly: i, interaction: l, onContextMenu: s }) {
2399
+ const { dataStore: u, uiStore: g } = De(), P = Se((L) => L.toggleSelection), d = K((L) => L.setSelectedPartIndex), p = K((L) => L.selectedPartIndex), C = e.geometry.coordinates, [M, S] = de(!1), m = $(/* @__PURE__ */ new Map()), y = vt(e), x = rn(n || o, () => m.current.values()), { effectiveDelta: f, dragged: h, handleMouseDown: I } = sn(
2400
+ e,
2401
+ n,
2402
+ o,
2403
+ r,
2404
+ i,
2405
+ l,
2406
+ (L, V, R) => {
2407
+ for (let c = 0; c < C.length; c++) {
2408
+ if (R != null && R !== c) continue;
2409
+ const E = m.current.get(c);
2410
+ if (!E) continue;
2411
+ const B = V === "visual" ? We([C[c]], L[0], L[1])[0] : C[c].map((J) => J.map(([j, ce]) => [j + L[0], ce + L[1]]));
2412
+ E.setLatLngs(B.map((J) => J.map(G)));
2413
+ }
2414
+ }
2415
+ ), z = yt(It)[500], k = n ? p : null, H = _e(() => C.map((L, V) => f && (k == null || k === V) ? u.getState().geometryMode === "visual" ? We([L], f[0], f[1])[0] : L.map((c) => c.map(([E, B]) => [E + f[0], B + f[1]])) : L), [C, f, k]), D = _e(() => H.map((L) => L.map((V) => V.map(G))), [H]), _ = n && p != null, F = o || n || f ? Et(y, !0, {
2416
+ color: o || n ? z : Te,
2417
+ fillColor: o || n ? z : Te,
2418
+ weight: n ? 3 : 2,
2419
+ opacity: M ? 1 : 0.9,
2420
+ fillOpacity: n ? 0.25 : M ? 0.28 : 0.15,
2421
+ className: f ? "cursor-grabbing" : ""
2422
+ }) : Mt(Hn, y, M ? Bn : null), Y = { ...F, opacity: 0.2, fillOpacity: 0.08 };
2423
+ return /* @__PURE__ */ w(xe, { children: D.map((L, V) => /* @__PURE__ */ w(
2424
+ He,
2425
+ {
2426
+ ref: (R) => {
2427
+ R ? m.current.set(V, R) : m.current.delete(V);
2428
+ },
2429
+ positions: L,
2430
+ renderer: x,
2431
+ pathOptions: _ && p !== V ? Y : F,
2432
+ eventHandlers: {
2433
+ mouseover: (R) => {
2434
+ Dt(R.target, e, g, R.latlng, R.originalEvent), g.getState().vertexEditActive || S(!0);
2435
+ },
2436
+ mouseout: (R) => {
2437
+ ct(R.target), S(!1);
2438
+ },
2439
+ click: (R) => {
2440
+ if (g.getState().editingMode === "none")
2441
+ if (R.originalEvent.stopPropagation(), R.originalEvent.shiftKey && !i) {
2442
+ if (!l.shouldHandleFeatureClick(h.current)) return;
2443
+ P(e.id);
2444
+ } else if (n) {
2445
+ if (h.current) return;
2446
+ l.markFeatureClick(), d(p === V ? null : V);
2447
+ } else {
2448
+ if (!l.shouldHandleFeatureClick(h.current)) return;
2449
+ l.markFeatureClick(), u.getState().selectFeature(e.id);
2450
+ }
2451
+ },
2452
+ dblclick: (R) => {
2453
+ g.getState().editingMode === "none" && (R.originalEvent.stopPropagation(), i || a());
2454
+ },
2455
+ mousedown: (R) => I(V, R),
2456
+ contextmenu: At(e, i, s)
2457
+ }
2458
+ },
2459
+ `poly-part-${V}`
2460
+ )) });
2461
+ },
2462
+ (t, e) => t.feature === e.feature && t.selected === e.selected && t.isMultiSelected === e.isMultiSelected && t.multiDragDelta === e.multiDragDelta && t.readonly === e.readonly && t.interaction === e.interaction
2463
+ ), Qi = Ze(
2464
+ function({ feature: e, selected: n, isMultiSelected: o, multiDragDelta: r, multiDuplicateDrag: a, readonly: i, interaction: l, onContextMenu: s }) {
2465
+ const { dataStore: u } = De(), g = be(), { uiStore: P } = De(), d = Nt(), p = Se((c) => c.updateFeature), C = Se((c) => c.toggleSelection), M = e.geometry.coordinates, [S, m] = de(!1), y = $n(vt(e)), [x, f] = de({ lng: "", lat: "" }), h = $(null), I = $(null), { effectiveDelta: z, display: k, ghost: H, dragged: D, handleMouseDown: _ } = Vn(
2466
+ e,
2467
+ "Point",
2468
+ M,
2469
+ n,
2470
+ o,
2471
+ r,
2472
+ a,
2473
+ i,
2474
+ l,
2475
+ (c, E) => {
2476
+ var B;
2477
+ return (B = (E ? I : h).current) == null ? void 0 : B.setLatLng(G(c));
2478
+ }
2479
+ ), F = _t(i);
2480
+ Q(() => {
2481
+ var E, B;
2482
+ if (i) return;
2483
+ const c = (B = (E = h.current) == null ? void 0 : E.getElement) == null ? void 0 : B.call(E);
2484
+ if (!(!c || !ti(g, G(M)) || !ei(c)))
2485
+ return Rn(e.id), F.enter(c, nn()), P.getState().vertexEditActive || mt(h.current, !0), () => {
2486
+ F.leave();
2487
+ };
2488
+ }, [e.id, i]);
2489
+ const Y = Wr(e.id);
2490
+ Q(() => {
2491
+ var c, E, B;
2492
+ (B = (E = (c = h.current) == null ? void 0 : c.getElement) == null ? void 0 : E.call(c)) == null || B.classList.toggle("elm-pin-fresh", Y);
2493
+ });
2494
+ function L() {
2495
+ f({ lng: M[0].toFixed(6), lat: M[1].toFixed(6) }), m(!0);
2496
+ }
2497
+ function V(c) {
2498
+ c.originalEvent.preventDefault(), c.originalEvent.stopPropagation(), !i && s && s({
2499
+ feature: e,
2500
+ x: c.originalEvent.clientX,
2501
+ y: c.originalEvent.clientY,
2502
+ requestPreciseCoords: L
2503
+ });
2504
+ }
2505
+ function R() {
2506
+ const c = parseFloat(x.lng), E = parseFloat(x.lat);
2507
+ !isNaN(c) && !isNaN(E) ? (u.getState().takeSnapshot(), p(e.id, { geometry: { type: "Point", coordinates: zt(M, [c, E]) } }), m(!1), d({ type: "success", message: "Coordinate updated" })) : d({ type: "warning", message: "Invalid coordinates" });
2508
+ }
2509
+ return /* @__PURE__ */ le(xe, { children: [
2510
+ /* @__PURE__ */ w(
2511
+ Le,
2512
+ {
2513
+ ref: (c) => {
2514
+ h.current = c;
2515
+ },
2516
+ position: G(k),
2517
+ icon: n || o || S || z ? Lt(n, o, y) : qt(y),
2518
+ draggable: !1,
2519
+ eventHandlers: {
2520
+ mouseover: (c) => {
2521
+ var E, B;
2522
+ F.enter((B = (E = c.target).getElement) == null ? void 0 : B.call(E), c.originalEvent), Dt(c.target, e, P, c.latlng, c.originalEvent), P.getState().vertexEditActive || mt(h.current, !0);
2523
+ },
2524
+ mouseout: (c) => {
2525
+ F.leave(), ct(c.target), mt(c.target, !1);
2526
+ },
2527
+ click: (c) => {
2528
+ P.getState().editingMode === "none" && (c.originalEvent.stopPropagation(), l.shouldHandleFeatureClick(D.current) && (c.originalEvent.shiftKey && !i ? C(e.id) : (l.markFeatureClick(), u.getState().selectFeature(e.id))));
2529
+ },
2530
+ contextmenu: V,
2531
+ mousedown: _
2532
+ },
2533
+ children: S && /* @__PURE__ */ w(
2534
+ go,
2535
+ {
2536
+ eventHandlers: { remove: () => m(!1) },
2537
+ autoClose: !1,
2538
+ closeOnClick: !1,
2539
+ children: /* @__PURE__ */ le("div", { className: "flex flex-col gap-2 min-w-[140px]", onKeyDown: (c) => {
2540
+ c.key === "Enter" && R(), c.key === "Escape" && m(!1);
2541
+ }, children: [
2542
+ /* @__PURE__ */ w("p", { className: "text-xs font-semibold text-(--elm-text-secondary,var(--color-gray-700)) m-0 leading-none", children: "Precise coordinates" }),
2543
+ /* @__PURE__ */ le("div", { className: "flex flex-col gap-1", children: [
2544
+ /* @__PURE__ */ le("label", { className: "flex items-center gap-2 text-xs text-(--elm-text-muted,var(--color-gray-500))", children: [
2545
+ "Lat:",
2546
+ /* @__PURE__ */ w("input", { type: "text", value: x.lat, onChange: (c) => f((E) => ({ ...E, lat: c.target.value })), className: "flex-1 w-full min-w-0 border border-(--elm-border,var(--color-gray-200)) rounded-elm-chip px-1.5 py-0.5 text-xs outline-none focus:border-primary-400" })
2547
+ ] }),
2548
+ /* @__PURE__ */ le("label", { className: "flex items-center gap-2 text-xs text-(--elm-text-muted,var(--color-gray-500))", children: [
2549
+ "Lng:",
2550
+ /* @__PURE__ */ w("input", { type: "text", value: x.lng, onChange: (c) => f((E) => ({ ...E, lng: c.target.value })), className: "flex-1 w-full min-w-0 border border-(--elm-border,var(--color-gray-200)) rounded-elm-chip px-1.5 py-0.5 text-xs outline-none focus:border-primary-400" })
2551
+ ] })
2552
+ ] }),
2553
+ /* @__PURE__ */ le("div", { className: "flex items-center justify-end gap-1 mt-1", children: [
2554
+ /* @__PURE__ */ w("button", { onClick: () => m(!1), className: "px-2 py-1 text-xs text-(--elm-text-muted,var(--color-gray-500)) hover:bg-(--elm-surface-hover,var(--color-gray-100)) rounded-elm-chip transition-colors", children: "Cancel" }),
2555
+ /* @__PURE__ */ le("button", { onClick: R, className: "px-2 py-1 text-xs text-white bg-primary-500 hover:bg-primary-600 rounded-elm-chip transition-colors font-medium flex items-center gap-1", children: [
2556
+ /* @__PURE__ */ w(yo, { size: 12, weight: "bold" }),
2557
+ " Save"
2558
+ ] })
2559
+ ] })
2560
+ ] })
2561
+ }
2562
+ )
2563
+ }
2564
+ ),
2565
+ H && /* @__PURE__ */ w(
2566
+ Le,
2567
+ {
2568
+ ref: (c) => {
2569
+ I.current = c;
2570
+ },
2571
+ position: G(H),
2572
+ icon: Lt(!0, !1),
2573
+ opacity: 0.5,
2574
+ interactive: !1
2575
+ }
2576
+ )
2577
+ ] });
2578
+ },
2579
+ (t, e) => t.feature === e.feature && t.selected === e.selected && t.isMultiSelected === e.isMultiSelected && t.multiDragDelta === e.multiDragDelta && t.multiDuplicateDrag === e.multiDuplicateDrag && t.readonly === e.readonly && t.interaction === e.interaction
2580
+ ), es = Ze(
2581
+ function({ feature: e, selected: n, isMultiSelected: o, multiDragDelta: r, multiDuplicateDrag: a, onVertexEdit: i, readonly: l, interaction: s, onContextMenu: u }) {
2582
+ const { dataStore: g, uiStore: P } = De(), d = Se((F) => F.toggleSelection), p = yt(It)[500], C = e.geometry.coordinates, M = $(null), S = $(null), [m, y] = de(!1), x = _t(l), f = vt(e), h = rn(n || o, () => [M.current], {
2583
+ after: () => {
2584
+ M.current && x.retarget(Zt(M.current));
2585
+ }
2586
+ }), { effectiveDelta: I, display: z, ghost: k, dragged: H, handleMouseDown: D } = Vn(
2587
+ e,
2588
+ "Polygon",
2589
+ C,
2590
+ n,
2591
+ o,
2592
+ r,
2593
+ a,
2594
+ l,
2595
+ s,
2596
+ (F, Y) => {
2597
+ var L;
2598
+ return (L = (Y ? S : M).current) == null ? void 0 : L.setLatLngs(F.map((V) => V.map(G)));
2599
+ }
2600
+ ), _ = _e(() => z.map((F) => F.map(G)), [z]);
2601
+ return /* @__PURE__ */ le(xe, { children: [
2602
+ /* @__PURE__ */ w(
2603
+ He,
2604
+ {
2605
+ ref: (F) => {
2606
+ M.current = F;
2607
+ },
2608
+ positions: _,
2609
+ renderer: h,
2610
+ pathOptions: o || n || I ? Et(f, !0, {
2611
+ color: o || n ? p : Te,
2612
+ fillColor: o || n ? p : Te,
2613
+ weight: n ? 3 : 2,
2614
+ opacity: m ? 1 : 0.9,
2615
+ fillOpacity: n ? 0.25 : m ? 0.28 : 0.15,
2616
+ className: I ? "cursor-grabbing" : ""
2617
+ }) : Mt(Hn, f, m ? Bn : null),
2618
+ eventHandlers: {
2619
+ mouseover: (F) => {
2620
+ x.enter(Zt(F.target), F.originalEvent), Dt(F.target, e, P, F.latlng, F.originalEvent), P.getState().vertexEditActive || y(!0);
2621
+ },
2622
+ mouseout: (F) => {
2623
+ x.leave(), ct(F.target), y(!1);
2624
+ },
2625
+ click: (F) => {
2626
+ P.getState().editingMode === "none" && (F.originalEvent.stopPropagation(), s.shouldHandleFeatureClick(H.current) && (F.originalEvent.shiftKey && !l ? d(e.id) : (s.markFeatureClick(), g.getState().selectFeature(e.id))));
2627
+ },
2628
+ dblclick: (F) => {
2629
+ P.getState().editingMode === "none" && (F.originalEvent.stopPropagation(), l || i());
2630
+ },
2631
+ contextmenu: At(e, l, u),
2632
+ mousedown: D
2633
+ }
2634
+ }
2635
+ ),
2636
+ k && /* @__PURE__ */ w(
2637
+ He,
2638
+ {
2639
+ ref: (F) => {
2640
+ S.current = F;
2641
+ },
2642
+ positions: k.map((F) => F.map(G)),
2643
+ pathOptions: { ...Xi, color: p, fillColor: p }
2644
+ }
2645
+ )
2646
+ ] });
2647
+ },
2648
+ (t, e) => t.feature === e.feature && t.selected === e.selected && t.isMultiSelected === e.isMultiSelected && t.multiDragDelta === e.multiDragDelta && t.multiDuplicateDrag === e.multiDuplicateDrag && t.readonly === e.readonly && t.interaction === e.interaction
2649
+ ), ts = { items: [], pos: 0, bounds: null };
2650
+ function Ro(t, e) {
2651
+ if (!e) return t;
2652
+ const n = (e.e - e.w) / 4, o = (e.n - e.s) / 4, r = e.w + n, a = e.e - n, i = e.s + o, l = e.n - o, s = [], u = [];
2653
+ for (const g of t) {
2654
+ const [P, d, p, C] = mo(g);
2655
+ (p >= r && P <= a && C >= i && d <= l ? s : u).push(g);
2656
+ }
2657
+ return s.concat(u);
2658
+ }
2659
+ function ns(t, e, n, o) {
2660
+ let r = t.length;
2661
+ if (e.pos < e.items.length && t.length > n) {
2662
+ const l = /* @__PURE__ */ new Set();
2663
+ for (let s = e.pos; s < e.items.length; s++) l.add(e.items[s].id);
2664
+ r = 0;
2665
+ for (const s of t) l.has(s.id) || r++;
2666
+ }
2667
+ r > n && (n = 0);
2668
+ const a = t.length > n ? Ro(t, o) : t, i = Math.min(n, a.length);
2669
+ return { now: a.slice(0, i), queue: { items: a, pos: i, bounds: o } };
2670
+ }
2671
+ function os(t, e, n, o) {
2672
+ let { items: r, pos: a } = t;
2673
+ n !== t.bounds && a < r.length && (r = Ro(r.slice(a), n), a = 0);
2674
+ const i = [];
2675
+ for (; a < r.length && i.length < e; ) {
2676
+ const l = r[a++];
2677
+ o(l.id) || i.push(l);
2678
+ }
2679
+ return { chunk: i, queue: { items: r, pos: a, bounds: n } };
2680
+ }
2681
+ const rs = 8, to = 50, is = 1e3, no = Ze(function({ items: e }) {
2682
+ return /* @__PURE__ */ w(xe, { children: e });
2683
+ });
2684
+ function ss({ tick: t, onEffect: e }) {
2685
+ return Q(e, [t]), null;
2686
+ }
2687
+ function as(t, e, n, o, r) {
2688
+ const a = $(/* @__PURE__ */ new Map()), i = $({ inputs: [], elements: [], groups: /* @__PURE__ */ new Map(), queue: ts }), l = $(0), [s, u] = de(0), g = $({ msPerFeature: 0.16, chunk: to, renderMs: 0, effectStart: 0 }), P = [t, ...r], d = _e(() => {
2689
+ const C = i.current, M = a.current, S = l.current, m = g.current.chunk;
2690
+ if (C.inputs.length === P.length && C.inputs.every((F, Y) => F === P[Y])) {
2691
+ const { chunk: F, queue: Y } = os(C.queue, m, n, (B) => M.has(B)), L = performance.now(), V = [], R = /* @__PURE__ */ new Map();
2692
+ o(F, () => !0, !0).forEach((B, J) => {
2693
+ B && (V.push(B), R.set(F[J].id, S));
2694
+ });
2695
+ let { elements: c, groups: E } = C;
2696
+ return V.length && (E = new Map(E).set(S, V), c = [...c, /* @__PURE__ */ w(no, { items: V }, S)]), { elements: c, groups: E, queue: Y, added: R, mountedIds: null, n: V.length, start: L };
2697
+ }
2698
+ const y = [...t].reverse(), x = (F) => !M.has(F.id) && !e(F), { now: f, queue: h } = ns(y.filter(x), C.queue, m, n), I = new Set(f.map((F) => F.id)), z = o(y, (F) => !x(F) || I.has(F.id), !1), k = /* @__PURE__ */ new Map(), H = /* @__PURE__ */ new Map();
2699
+ z.forEach((F, Y) => {
2700
+ if (!F) return;
2701
+ const L = y[Y].id, V = M.get(L) ?? S;
2702
+ k.set(L, V);
2703
+ const R = H.get(V);
2704
+ R ? R.push(F) : H.set(V, [F]);
2705
+ });
2706
+ const D = /* @__PURE__ */ new Map();
2707
+ return { elements: [...H].map(([F, Y]) => {
2708
+ const L = C.groups.get(F), V = L && L.length === Y.length && L.every((R, c) => R === Y[c]) ? L : Y;
2709
+ return D.set(F, V), /* @__PURE__ */ w(no, { items: V }, F);
2710
+ }), groups: D, queue: h, added: null, mountedIds: k, n: 0, start: 0 };
2711
+ }, [...P, s]);
2712
+ $o(() => {
2713
+ g.current.renderMs = performance.now() - d.start;
2714
+ }, [d]);
2715
+ const p = Fe(() => {
2716
+ g.current.effectStart = performance.now();
2717
+ }, []);
2718
+ return Q(() => {
2719
+ if (d.mountedIds) a.current = d.mountedIds;
2720
+ else for (const [S, m] of d.added) a.current.set(S, m);
2721
+ i.current = { inputs: P, elements: d.elements, groups: d.groups, queue: d.queue }, d.groups.has(l.current) && l.current++;
2722
+ const C = g.current;
2723
+ if (d.n >= 20) {
2724
+ const S = C.renderMs + performance.now() - C.effectStart;
2725
+ C.msPerFeature = C.msPerFeature * 0.5 + S / d.n * 0.5, C.chunk = Math.round(Math.min(is, Math.max(to, rs / C.msPerFeature)));
2726
+ }
2727
+ if (d.queue.pos >= d.queue.items.length) return;
2728
+ const M = setTimeout(() => u((S) => S + 1));
2729
+ return () => clearTimeout(M);
2730
+ }, [d]), /* @__PURE__ */ le(xe, { children: [
2731
+ /* @__PURE__ */ w(ss, { tick: d, onEffect: p }),
2732
+ d.elements
2733
+ ] });
2734
+ }
2735
+ const ls = Ze(function({
2736
+ culledFeatures: e,
2737
+ multiSelectedSet: n,
2738
+ transformDragging: o,
2739
+ selectedFeatureId: r,
2740
+ editingMode: a,
2741
+ geometryPreview: i,
2742
+ bufferCreateNew: l,
2743
+ multiDragDelta: s,
2744
+ multiDuplicateDrag: u,
2745
+ readonly: g,
2746
+ interaction: P,
2747
+ openFeatureCtxMenu: d,
2748
+ vertexEditId: p,
2749
+ viewBounds: C,
2750
+ onVertexEdit: M
2751
+ }) {
2752
+ const S = $({ shared: [], byId: /* @__PURE__ */ new Map() });
2753
+ return as(e, (m) => n.has(m.id) || m.id === p, C, (m, y, x) => {
2754
+ const f = S.current, h = [u, g, P, d];
2755
+ h.some((k, H) => k !== f.shared[H]) && (f.byId = /* @__PURE__ */ new Map()), f.shared = h;
2756
+ const I = x ? f.byId : /* @__PURE__ */ new Map(), z = m.map((k) => {
2757
+ if (!y(k)) return null;
2758
+ const H = n.has(k.id);
2759
+ if (o && (H || k.id === r) || (a === "simplify-shape" || a === "smooth-shape" || a === "buffer-shape" && !l) && i !== null && k.id === r && vn(k.geometry.type)) return null;
2760
+ const D = H ? s : null, _ = k.id === r, F = f.byId.get(k.id);
2761
+ if (F && F.f === k && F.sel === _ && F.multi === H && F.delta === D)
2762
+ return I.set(k.id, F), F.el;
2763
+ const Y = k.geometry.type === "Point" ? k.properties._isText === "true" ? /* @__PURE__ */ w(Yi, { feature: k, selected: k.id === r, isMultiSelected: H, multiDragDelta: D, multiDuplicateDrag: u, readonly: g, suppressDoubleClickZoomForGesture: P.suppressDoubleClickZoomForGesture }, k.id) : /* @__PURE__ */ w(Qi, { feature: k, selected: k.id === r, isMultiSelected: H, multiDragDelta: D, multiDuplicateDrag: u, readonly: g, interaction: P, onContextMenu: d }, k.id) : k.geometry.type === "MultiPoint" ? /* @__PURE__ */ w(qi, { feature: k, selected: k.id === r, isMultiSelected: H, multiDragDelta: D, readonly: g, interaction: P, onContextMenu: d }, k.id) : k.geometry.type === "Polygon" ? /* @__PURE__ */ w(es, { feature: k, selected: k.id === r, isMultiSelected: H, multiDragDelta: D, multiDuplicateDrag: u, onVertexEdit: () => {
2764
+ g || M(k.id);
2765
+ }, readonly: g, interaction: P, onContextMenu: d }, k.id) : k.geometry.type === "MultiPolygon" ? /* @__PURE__ */ w(Ji, { feature: k, selected: k.id === r, isMultiSelected: H, multiDragDelta: D, onVertexEdit: () => {
2766
+ g || M(k.id);
2767
+ }, readonly: g, interaction: P, onContextMenu: d }, k.id) : k.geometry.type === "MultiLineString" ? /* @__PURE__ */ w(Zi, { feature: k, selected: k.id === r, isMultiSelected: H, multiDragDelta: D, readonly: g, interaction: P, onContextMenu: d }, k.id) : k.geometry.type === "GeometryCollection" ? /* @__PURE__ */ w(Ui, { feature: k, selected: k.id === r, isMultiSelected: H, multiDragDelta: D, readonly: g, interaction: P, onContextMenu: d }, k.id) : /* @__PURE__ */ w(
2768
+ Wi,
2769
+ {
2770
+ feature: k,
2771
+ selected: k.id === r,
2772
+ isMultiSelected: H,
2773
+ multiDragDelta: D,
2774
+ multiDuplicateDrag: u,
2775
+ onVertexEdit: () => {
2776
+ g || M(k.id);
2777
+ },
2778
+ readonly: g,
2779
+ interaction: P,
2780
+ onContextMenu: d
2781
+ },
2782
+ k.id
2783
+ );
2784
+ return I.set(k.id, { f: k, sel: _, multi: H, delta: D, el: Y }), Y;
2785
+ });
2786
+ return f.byId = I, z;
2787
+ }, [n, o, r, a, i, l, s, u, g, P, d, p]);
2788
+ });
2789
+ function cs({ children: t }) {
2790
+ const e = Eo(), n = kt().featureColor, o = _e(() => $i(e, n), [e, n]);
2791
+ return /* @__PURE__ */ w(Mo, { getFeatureStyle: o, children: t });
2792
+ }
2793
+ function ta() {
2794
+ const { dataStore: t } = De(), e = be();
2795
+ return Q(() => {
2796
+ const n = t.getState().features;
2797
+ if (n.length === 0) return;
2798
+ let o = 1 / 0, r = 1 / 0, a = -1 / 0, i = -1 / 0;
2799
+ for (const l of n) {
2800
+ const [s, u, g, P] = l.bbox || In(l.geometry);
2801
+ s < o && (o = s), u < r && (r = u), g > a && (a = g), P > i && (i = P);
2802
+ }
2803
+ if (o !== 1 / 0) {
2804
+ const l = Dn(e.getContainer());
2805
+ e.fitBounds([[r, o], [i, a]], { paddingTopLeft: [l.left, l.top], paddingBottomRight: [l.right, l.bottom], maxZoom: 16 });
2806
+ }
2807
+ }, []), null;
2808
+ }
2809
+ function us({ renderer: t = "canvas" } = {}) {
2810
+ const { dataStore: e, uiStore: n } = De(), o = Nt(), r = Qt(), a = Se((T) => T.features), i = Se((T) => T.groups), l = Se((T) => T.selectedIds), s = l.length === 1 ? l[0] : null, u = Se((T) => T.clearSelection), g = Se((T) => T.selectFeature), P = Se((T) => T.updateFeature), d = K((T) => T.closeDialog), p = K((T) => T.setVertexEditActive), C = K((T) => T.setTransformActive), M = K((T) => T.transformActive), S = K((T) => T.vertexEditActive), m = K((T) => T.transformDragging), y = K((T) => T.editingMode), x = K((T) => T.geometryPreview), f = K((T) => T.bufferCreateNew), h = K((T) => T.readonly), [I, z] = de(null);
2811
+ function k(T) {
2812
+ z(T), p(!!T);
2813
+ }
2814
+ const H = $(!1), D = Qr(!!I || y !== "none");
2815
+ function _(T, oe = !1) {
2816
+ const pe = e.getState().features.find((ie) => ie.id === T);
2817
+ if (!pe) return;
2818
+ const ae = nr(pe);
2819
+ ae && o({ type: "warning", message: ae }), oe && D.suppressDoubleClickZoomForGesture(), D.suppressNextVertexExit(), k(T), Y([]);
2820
+ }
2821
+ Q(() => {
2822
+ ct(null);
2823
+ }, [a.length]), Q(() => {
2824
+ ct(null);
2825
+ }, [y, S]), Q(() => {
2826
+ M && !s && l.length === 0 && C(!1);
2827
+ }, [s, l.length, M, C]), Q(() => {
2828
+ I && M && C(!1);
2829
+ }, [I, M, C]), Q(() => {
2830
+ if (!M) return;
2831
+ const T = s ? e.getState().features.find((oe) => oe.id === s) : null;
2832
+ (T == null ? void 0 : T._drawType) === "route" && !H.current && (o({ type: "warning", message: "Transforming may break road alignment." }), H.current = !0);
2833
+ }, [M, s, e, o]);
2834
+ const [F, Y] = de([]), [L, V] = de(null), [R, c] = de(!1), E = be(), B = ut(E.getContainer()), J = Bi(E, t), j = kr(), ce = j.open, te = Fe((T) => {
2835
+ const { feature: oe, x: pe, y: ae, requestPreciseCoords: ie } = T, me = e.getState().selectedIds;
2836
+ me.length >= 2 && me.includes(oe.id) || e.getState().selectFeature(oe.id), ce(pe, ae, { feature: oe, requestPreciseCoords: ie });
2837
+ }, [e, ce]), ue = Fe((T, oe) => {
2838
+ V(null), D.markDragEnd();
2839
+ const pe = new Map(e.getState().features.map((ie) => [ie.id, ie])), ae = e.getState().selectedIds.flatMap((ie) => {
2840
+ const me = pe.get(ie);
2841
+ return me ? [{ id: ie, geometry: Jt(me.geometry, T, !1) }] : [];
2842
+ });
2843
+ oe ? e.getState().duplicateFeaturesAtPosition(ae.map(({ id: ie, geometry: me }) => ({ sourceId: ie, geometry: me }))) : (e.getState().takeSnapshot(), e.getState().updateFeatures(ae.map(({ id: ie, geometry: me }) => ({ id: ie, patch: { geometry: me } }))));
2844
+ }, [e, D]), [X, v] = de(null);
2845
+ function U() {
2846
+ const T = E.getBounds().pad(0.5);
2847
+ v({ w: T.getWest(), s: T.getSouth(), e: T.getEast(), n: T.getNorth() });
2848
+ }
2849
+ Q(() => {
2850
+ U();
2851
+ }, []), je({
2852
+ moveend: U,
2853
+ zoomend: U,
2854
+ // Suppress the browser's native context menu anywhere on the map. Feature
2855
+ // layers call preventDefault themselves; this catches bare-map right-clicks.
2856
+ contextmenu: (T) => {
2857
+ T.originalEvent.preventDefault();
2858
+ },
2859
+ mousemove: (T) => jr(E, T.containerPoint)
2860
+ });
2861
+ const ee = $(a);
2862
+ Q(() => {
2863
+ const T = ee.current;
2864
+ if (ee.current = a, a.length <= T.length) return;
2865
+ const { x: oe, y: pe } = nn(), ae = E.getContainer().getBoundingClientRect();
2866
+ if (oe < ae.left || oe > ae.right || pe < ae.top || pe > ae.bottom) return;
2867
+ const ie = new Set(T.map((me) => me.id));
2868
+ Yr(E, a.filter((me) => !ie.has(me.id)), { x: oe - ae.left, y: pe - ae.top });
2869
+ }, [a, E]);
2870
+ const q = _e(() => {
2871
+ const T = new Set(i.filter((oe) => oe.hidden).map((oe) => oe.id));
2872
+ return a.filter(
2873
+ (oe) => !oe.hidden && (!oe.groupId || !T.has(oe.groupId))
2874
+ );
2875
+ }, [a, i]), ge = _e(() => new Set(l), [l]), ne = $([]), fe = _e(() => {
2876
+ let T = q;
2877
+ if (X) {
2878
+ const pe = new Set(l);
2879
+ s && pe.add(s), I && pe.add(I), T = q.filter((ae) => {
2880
+ if (pe.has(ae.id)) return !0;
2881
+ const [ie, me, Ne, Ce] = mo(ae);
2882
+ return Ne >= X.w && ie <= X.e && Ce >= X.s && me <= X.n;
2883
+ });
2884
+ }
2885
+ const oe = ne.current;
2886
+ return oe.length === T.length && T.every((pe, ae) => pe === oe[ae]) ? oe : (ne.current = T, T);
2887
+ }, [q, X, l, s, I]), W = I ? q.find((T) => T.id === I && (T.geometry.type === "LineString" || T.geometry.type === "Polygon")) ?? null : null, we = Fe((T, oe) => {
2888
+ if (he.current === T) {
2889
+ Y((pe) => {
2890
+ const ae = new Set(pe);
2891
+ for (const ie of oe) ae.add(ie);
2892
+ return Array.from(ae).sort((ie, me) => ie - me);
2893
+ });
2894
+ return;
2895
+ }
2896
+ _(T), Y(oe);
2897
+ }, [D]);
2898
+ Q(() => {
2899
+ I && s !== I && (k(null), Y([]));
2900
+ }, [s, I]), Q(() => {
2901
+ !S && I && (z(null), Y([]));
2902
+ }, [S, I]), Q(() => {
2903
+ var pe, ae;
2904
+ if (h) return;
2905
+ function T(ie) {
2906
+ if (ie.key !== "n" && ie.key !== "N" || ie.metaKey || ie.ctrlKey || ie.altKey || !r(ie)) return;
2907
+ const me = ie.target;
2908
+ if (me.tagName === "INPUT" || me.tagName === "TEXTAREA" || me.tagName === "SELECT" || n.getState().dialogState.type !== "closed") return;
2909
+ const Ne = e.getState().selectedIds.length === 1 ? e.getState().selectedIds[0] : null;
2910
+ if (Ne)
2911
+ if (ie.preventDefault(), I === Ne)
2912
+ k(null), Y([]);
2913
+ else {
2914
+ const Ce = e.getState().features.find((qe) => qe.id === Ne);
2915
+ if (!Ce || Ce.geometry.type !== "LineString" && Ce.geometry.type !== "Polygon") return;
2916
+ _(Ne);
2917
+ }
2918
+ }
2919
+ const oe = ((ae = (pe = document.querySelector(".leaflet-container")) == null ? void 0 : pe.ownerDocument) == null ? void 0 : ae.defaultView) || window;
2920
+ return oe.addEventListener("keydown", T), () => oe.removeEventListener("keydown", T);
2921
+ }, [I, n, e, h, D, r]);
2922
+ const he = $(I);
2923
+ Q(() => {
2924
+ he.current = I;
2925
+ }, [I]);
2926
+ const Ie = $(F);
2927
+ Q(() => {
2928
+ Ie.current = F;
2929
+ }, [F]), Q(() => {
2930
+ var pe, ae;
2931
+ if (h) return;
2932
+ function T(ie) {
2933
+ if (ie.key !== "Enter" || ie.metaKey || ie.ctrlKey || ie.altKey || !r(ie)) return;
2934
+ const me = ie.target;
2935
+ if (me && (me.tagName === "INPUT" || me.tagName === "TEXTAREA" || me.isContentEditable)) return;
2936
+ const Ne = n.getState(), Ce = Ne.editingMode;
2937
+ if (!(Ce === "none" || Ce === "draw-rect" || Ce === "draw-circle" || Ce === "place-point" || Ce === "draw-freehand" || Ce === "pick-shape" || Ce === "draw-line" && Ne.lineInProgress.length < 2 || Ce === "draw-polygon" && Ne.polygonInProgress.length < 3 || Ce === "draw-route" && Ne.routeWaypoints.length < 2) || n.getState().dialogState.type !== "closed") return;
2938
+ const Je = e.getState().selectedIds.length === 1 ? e.getState().selectedIds[0] : null;
2939
+ if (Je)
2940
+ if (ie.preventDefault(), ie.stopPropagation(), Ce !== "none" && n.getState().setEditingMode("none"), he.current === Je)
2941
+ k(null), Y([]);
2942
+ else {
2943
+ const Qe = e.getState().features.find((st) => st.id === Je);
2944
+ if (!Qe || Qe.geometry.type !== "LineString" && Qe.geometry.type !== "Polygon") return;
2945
+ _(Je);
2946
+ }
2947
+ }
2948
+ const oe = ((ae = (pe = document.querySelector(".leaflet-container")) == null ? void 0 : pe.ownerDocument) == null ? void 0 : ae.defaultView) || window;
2949
+ return oe.addEventListener("keydown", T, { capture: !0 }), () => oe.removeEventListener("keydown", T, { capture: !0 });
2950
+ }, [n, e, h, D, r]);
2951
+ function Be() {
2952
+ if (!D.shouldHandleVertexExit()) return;
2953
+ k(null), Y([]);
2954
+ const T = n.getState().dialogState;
2955
+ (T.type !== "edit" || T.featureId === I) && d();
2956
+ }
2957
+ const ze = Fe(() => {
2958
+ if (!W || F.length === 0 || h) return;
2959
+ e.getState().takeSnapshot();
2960
+ const T = W.geometry.type === "Polygon", oe = new Set(F);
2961
+ if (T) {
2962
+ const ae = W.geometry.coordinates[0].slice(0, -1).filter((ie, me) => !oe.has(me));
2963
+ if (ae.length < 3) {
2964
+ o({ type: "warning", message: "Cannot delete: an area needs at least 3 points" });
2965
+ return;
2966
+ }
2967
+ ae.push(ae[0]), P(W.id, bt(W, { type: "Polygon", coordinates: [ae] }));
2968
+ } else {
2969
+ const ae = W.geometry.coordinates.filter((ie, me) => !oe.has(me));
2970
+ if (ae.length < 2) {
2971
+ o({ type: "warning", message: "Cannot delete: a line needs at least 2 points" });
2972
+ return;
2973
+ }
2974
+ P(W.id, bt(W, { type: "LineString", coordinates: ae }));
2975
+ }
2976
+ if (T && n.getState().topoEditEnabled) {
2977
+ const pe = W.geometry.coordinates[0], ae = F.map((ie) => pe[ie]);
2978
+ e.getState().updateFeatures(yn(
2979
+ e.getState().features,
2980
+ W.id,
2981
+ ae
2982
+ ));
2983
+ }
2984
+ Y([]);
2985
+ }, [W, F, P, h, n, e, o]), re = Fe(() => {
2986
+ if (!W || F.length < 3 || h) {
2987
+ h || o({ type: "warning", message: "Select at least 3 points to simplify" });
2988
+ return;
2989
+ }
2990
+ const T = W.geometry.type === "Polygon", oe = T ? W.geometry.coordinates[0].slice(0, -1) : W.geometry.coordinates, pe = [...F].sort((Qe, st) => Qe - st), ae = pe[0], ie = pe[pe.length - 1], me = oe.slice(ae, ie + 1), Ne = tr(me, 1e-5), Ce = me.length - Ne.length;
2991
+ if (Ce === 0) {
2992
+ o({ type: "warning", message: "Nothing to remove: no selected point sits on a straight line" });
2993
+ return;
2994
+ }
2995
+ const qe = [...oe.slice(0, ae), ...Ne, ...oe.slice(ie + 1)], Je = T ? 3 : 2;
2996
+ if (qe.length < Je) {
2997
+ o({ type: "warning", message: `Cannot simplify: ${T ? "an area needs at least 3" : "a line needs at least 2"} points` });
2998
+ return;
2999
+ }
3000
+ if (e.getState().takeSnapshot(), T) {
3001
+ const Qe = [...qe, qe[0]];
3002
+ if (P(W.id, bt(W, { type: "Polygon", coordinates: [Qe] })), n.getState().topoEditEnabled) {
3003
+ const st = new Set(Ne.map((gt) => `${gt[0]},${gt[1]}`)), dt = me.filter((gt) => !st.has(`${gt[0]},${gt[1]}`));
3004
+ dt.length > 0 && e.getState().updateFeatures(yn(
3005
+ e.getState().features,
3006
+ W.id,
3007
+ dt
3008
+ ));
3009
+ }
3010
+ } else
3011
+ P(W.id, bt(W, { type: "LineString", coordinates: qe }));
3012
+ Y([]), o({ type: "success", message: `Removed ${Ce} extra point${Ce !== 1 ? "s" : ""}` });
3013
+ }, [W, F, P, h, n, e, o]), Me = $(_);
3014
+ Me.current = _;
3015
+ const $e = Fe((T) => Me.current(T, !0), []), [rt, it] = de(!1);
3016
+ Q(() => it(!0), []);
3017
+ const wt = rt && !!W && F.length > 0 && !h;
3018
+ return /* @__PURE__ */ le(It.Provider, { value: B, children: [
3019
+ /* @__PURE__ */ w(Ti, { onMapClick: (T) => {
3020
+ n.getState().editingMode === "none" && (Ki() || n.getState().vertexEditActive || T.originalEvent.shiftKey || D.shouldHandleMapClick() && (n.getState().transformActive && n.getState().setTransformActive(!1), l.length > 0 && !h && u(), s && (g(null), d())));
3021
+ } }),
3022
+ /* @__PURE__ */ w(Oi, { onDragDelta: V, onDragEnd: (T, oe) => {
3023
+ c(!1), ue(T, oe);
3024
+ }, onDuplicateDragChange: c, readonly: h }),
3025
+ /* @__PURE__ */ w(Do.Provider, { value: J, children: /* @__PURE__ */ w(cs, { children: /* @__PURE__ */ w(
3026
+ ls,
3027
+ {
3028
+ culledFeatures: fe,
3029
+ multiSelectedSet: ge,
3030
+ transformDragging: m,
3031
+ selectedFeatureId: s,
3032
+ editingMode: y,
3033
+ geometryPreview: x,
3034
+ bufferCreateNew: f,
3035
+ multiDragDelta: L,
3036
+ multiDuplicateDrag: R,
3037
+ readonly: h,
3038
+ interaction: D,
3039
+ openFeatureCtxMenu: te,
3040
+ vertexEditId: I,
3041
+ viewBounds: X,
3042
+ onVertexEdit: $e
3043
+ }
3044
+ ) }) }, t),
3045
+ W && /* @__PURE__ */ w(
3046
+ Ci,
3047
+ {
3048
+ feature: (y === "simplify-shape" || y === "smooth-shape") && x ? { ...W, geometry: x } : W,
3049
+ selectedIndices: F,
3050
+ onExit: Be,
3051
+ onDeleteSelected: ze,
3052
+ onSelectIndices: Y,
3053
+ onFeatureClick: () => {
3054
+ D.markFeatureClick();
3055
+ },
3056
+ readonly: h
3057
+ }
3058
+ ),
3059
+ /* @__PURE__ */ w(
3060
+ hi,
3061
+ {
3062
+ onSelect: we,
3063
+ onDragStart: () => {
3064
+ D.markDragStart(), D.suppressNextVertexExit();
3065
+ },
3066
+ readonly: h,
3067
+ getInitialVertexIndices: () => Ie.current,
3068
+ onVertexBoxPreview: (T, oe) => {
3069
+ he.current === T && Y(oe);
3070
+ }
3071
+ }
3072
+ ),
3073
+ /* @__PURE__ */ w(Fi, {}),
3074
+ /* @__PURE__ */ w(Di, {}),
3075
+ /* @__PURE__ */ w(Ei, {}),
3076
+ /* @__PURE__ */ w(Ai, {}),
3077
+ /* @__PURE__ */ w(fi, {}),
3078
+ /* @__PURE__ */ w(_i, {}),
3079
+ wt && /* @__PURE__ */ w(
3080
+ hr,
3081
+ {
3082
+ mapContainer: E.getContainer(),
3083
+ count: F.length,
3084
+ onSimplify: re,
3085
+ onDelete: ze
3086
+ }
3087
+ ),
3088
+ j.state && /* @__PURE__ */ w(
3089
+ yr,
3090
+ {
3091
+ x: j.state.x,
3092
+ y: j.state.y,
3093
+ data: j.state.data,
3094
+ onClose: j.close
3095
+ }
3096
+ )
3097
+ ] });
3098
+ }
3099
+ let Mn = !1;
3100
+ function ds() {
3101
+ Mn = !0, Promise.resolve().then(() => {
3102
+ Mn = !1;
3103
+ });
3104
+ }
3105
+ function gs() {
3106
+ return Mn;
3107
+ }
3108
+ let Fo = 0;
3109
+ function oo() {
3110
+ Fo = Date.now();
3111
+ }
3112
+ function fs() {
3113
+ return Date.now() - Fo < 200;
3114
+ }
3115
+ const ps = 3, ro = 5;
3116
+ function ms({ routingApiKey: t } = {}) {
3117
+ const { uiStore: e, dataStore: n } = De(), o = Dr(t), r = kt().network.fetch, a = $(null);
3118
+ a.current = o === !1 ? null : { ...o, fetch: r };
3119
+ const i = Nt(), l = Qt(), s = be(), u = K((v) => v.editingMode), g = K((v) => v.commitPoint), P = K((v) => v.addLineVertex), d = K((v) => v.addPolygonVertex), p = K((v) => v.setCircleCenter), C = K((v) => v.commitCircle), M = K((v) => v.setRectCorner), S = K((v) => v.commitRect), m = K((v) => v.cancelDrawing), y = K((v) => v.addRouteWaypoint), x = K((v) => v.setRoutePreview), f = K((v) => v.setRouteCursorPos), h = K((v) => v.setRouteCursorPreview), I = K((v) => v.routeWaypoints), z = K((v) => v.removeLastLineVertex), k = K((v) => v.removeLastPolygonVertex), H = K((v) => v.removeLastRouteWaypoint), D = K((v) => v.removeLastMeasurePoint), _ = K((v) => v.addFreehandPoint), F = K((v) => v.clearFreehandPoints), Y = K((v) => v.commitFreehand), L = $(null), V = $(null), R = $(!1), c = $(!1), E = $(!1), B = $(!1), J = $(!1), j = $(null), ce = $(or()).current;
3120
+ Q(() => {
3121
+ if (!rr.includes(u)) return;
3122
+ const v = s.dragging._draggable;
3123
+ if (!v) return;
3124
+ const U = v.options.clickTolerance;
3125
+ return v.options.clickTolerance = ir, () => {
3126
+ v.options.clickTolerance = U;
3127
+ };
3128
+ }, [u, s]), Q(() => {
3129
+ var Be, ze;
3130
+ const v = s.getContainer();
3131
+ function U() {
3132
+ E.current || (E.current = !0, s.dragging.enable(), v.style.setProperty("cursor", "grab", "important"));
3133
+ }
3134
+ function ee() {
3135
+ if (!E.current) return;
3136
+ E.current = !1, v.style.removeProperty("cursor");
3137
+ const re = e.getState().editingMode;
3138
+ re !== "none" && !B.current && (v.style.cursor = re === "pick-shape" ? "pointer" : "crosshair"), ["draw-freehand", "draw-rect", "draw-circle"].includes(re) && s.dragging.disable();
3139
+ }
3140
+ function q() {
3141
+ B.current || E.current || (B.current = !0, v.style.removeProperty("cursor"));
3142
+ }
3143
+ function ge() {
3144
+ if (!B.current) return;
3145
+ B.current = !1, oo();
3146
+ const re = e.getState().editingMode;
3147
+ re !== "none" && !E.current && (v.style.cursor = re === "pick-shape" ? "pointer" : "crosshair");
3148
+ }
3149
+ const ne = () => {
3150
+ E.current && v.style.setProperty("cursor", "grabbing", "important");
3151
+ }, fe = () => {
3152
+ E.current && v.style.setProperty("cursor", "grab", "important");
3153
+ };
3154
+ v.addEventListener("mousedown", ne), v.addEventListener("mouseup", fe);
3155
+ const W = (re) => {
3156
+ if (re.key === "Meta" || re.key === "Control" || re.key === "Alt") {
3157
+ q();
3158
+ return;
3159
+ }
3160
+ if (re.key === "Shift" && (c.current = !0), !!l(re)) {
3161
+ if (re.code === "Space") {
3162
+ const Me = re.target;
3163
+ if (Me.tagName === "INPUT" || Me.tagName === "TEXTAREA" || Me.isContentEditable) return;
3164
+ re.preventDefault(), U();
3165
+ return;
3166
+ }
3167
+ if (re.key === "Escape") {
3168
+ const { selectedMeasurementId: Me, setSelectedMeasurementId: $e } = e.getState();
3169
+ if (Me) {
3170
+ $e(null);
3171
+ return;
3172
+ }
3173
+ m();
3174
+ }
3175
+ if (re.key === "Enter" && e.getState().editingMode === "measure") {
3176
+ e.getState().completeMeasure();
3177
+ return;
3178
+ }
3179
+ if (re.key === "Backspace" || re.key === "Delete") {
3180
+ const Me = e.getState();
3181
+ if (Me.selectedMeasurementId) {
3182
+ Me.removeMeasurement(Me.selectedMeasurementId);
3183
+ return;
3184
+ }
3185
+ const $e = Me.editingMode;
3186
+ if ($e === "measure") {
3187
+ D();
3188
+ return;
3189
+ }
3190
+ if ($e === "draw-line" || $e === "slice-shape") {
3191
+ z();
3192
+ return;
3193
+ }
3194
+ if ($e === "draw-polygon" || $e === "cut-hole") {
3195
+ k();
3196
+ return;
3197
+ }
3198
+ if ($e === "draw-route") {
3199
+ H();
3200
+ return;
3201
+ }
3202
+ }
3203
+ }
3204
+ }, we = (re) => {
3205
+ if (re.code === "Space") {
3206
+ ee();
3207
+ return;
3208
+ }
3209
+ re.key === "Shift" && (c.current = !1), (re.key === "Meta" || re.key === "Control" || re.key === "Alt") && !re.metaKey && !re.ctrlKey && !re.altKey && ge();
3210
+ }, he = () => {
3211
+ ee(), ge();
3212
+ }, Ie = ((ze = (Be = document.querySelector(".leaflet-container")) == null ? void 0 : Be.ownerDocument) == null ? void 0 : ze.defaultView) || window;
3213
+ return Ie.addEventListener("keydown", W), Ie.addEventListener("keyup", we), Ie.addEventListener("blur", he), () => {
3214
+ Ie.removeEventListener("keydown", W), Ie.removeEventListener("keyup", we), Ie.removeEventListener("blur", he), v.removeEventListener("mousedown", ne), v.removeEventListener("mouseup", fe), ee();
3215
+ };
3216
+ }, [m, z, k, H, D, e, s, l]);
3217
+ const te = $(I);
3218
+ Q(() => {
3219
+ te.current = I;
3220
+ }, [I]);
3221
+ const ue = $(null), X = Fe(async (v) => {
3222
+ if (!(v.length < 2)) {
3223
+ x(null, !0);
3224
+ try {
3225
+ if (!a.current) throw new Error("routing is off");
3226
+ const U = await Un(v, a.current);
3227
+ te.current.length >= 2 && x(U, !1);
3228
+ } catch (U) {
3229
+ const ee = sr(U);
3230
+ i({ type: "error", code: ee.code, source: "routing", message: ee.message, error: ee }), x(v, !1);
3231
+ }
3232
+ }
3233
+ }, [x, i, e]);
3234
+ return je({
3235
+ mousedown(v) {
3236
+ if (u === "draw-freehand") {
3237
+ R.current = !0, F(), _([v.latlng.lng, v.latlng.lat]);
3238
+ return;
3239
+ }
3240
+ if (!(E.current || B.current)) {
3241
+ if (u === "draw-rect") {
3242
+ s.dragging.disable(), n.getState().selectedIds.length > 0 && n.setState({ selectedIds: [] });
3243
+ const U = e.getState().snappedCoord ?? [v.latlng.lng, v.latlng.lat];
3244
+ M(U), J.current = !0, j.current = { x: v.containerPoint.x, y: v.containerPoint.y };
3245
+ return;
3246
+ }
3247
+ if (u === "draw-circle") {
3248
+ s.dragging.disable(), n.getState().selectedIds.length > 0 && n.setState({ selectedIds: [] });
3249
+ const U = e.getState().snappedCoord ?? [v.latlng.lng, v.latlng.lat];
3250
+ p(U), J.current = !0, j.current = { x: v.containerPoint.x, y: v.containerPoint.y };
3251
+ return;
3252
+ }
3253
+ }
3254
+ },
3255
+ mouseup(v) {
3256
+ if (u === "draw-freehand" && R.current) {
3257
+ R.current = !1;
3258
+ const q = s.getZoom(), ge = 156543.03392 * Math.cos(v.latlng.lat * Math.PI / 180) / Math.pow(2, q), ne = ps * ge / 111320;
3259
+ Y(ne), pn();
3260
+ return;
3261
+ }
3262
+ if (!J.current) {
3263
+ (B.current || v.originalEvent.metaKey || v.originalEvent.ctrlKey || v.originalEvent.altKey) && oo();
3264
+ return;
3265
+ }
3266
+ J.current = !1;
3267
+ const U = j.current, ee = U ? Math.hypot(v.containerPoint.x - U.x, v.containerPoint.y - U.y) : 0;
3268
+ if (j.current = null, u === "draw-rect") {
3269
+ const q = e.getState().rectCorner;
3270
+ if (!q) return;
3271
+ if (ee < ro) {
3272
+ e.setState({ rectCorner: null });
3273
+ return;
3274
+ }
3275
+ const ge = e.getState().snappedCoord ?? [v.latlng.lng, v.latlng.lat], ne = c.current || v.originalEvent.shiftKey;
3276
+ S(q, ge, {}, ne), pn();
3277
+ return;
3278
+ }
3279
+ if (u === "draw-circle") {
3280
+ const q = e.getState().circleCenter;
3281
+ if (!q) return;
3282
+ let ge;
3283
+ if (ee < ro) {
3284
+ const W = v.containerPoint, we = s.containerPointToLatLng([W.x + 25, W.y]);
3285
+ ge = [we.lng, we.lat];
3286
+ } else
3287
+ ge = e.getState().snappedCoord ?? [v.latlng.lng, v.latlng.lat];
3288
+ const ne = ge[0] - q[0], fe = ge[1] - q[1];
3289
+ Math.hypot(ne, fe) >= 1e-6 && (C(q, ge, {}), pn());
3290
+ return;
3291
+ }
3292
+ },
3293
+ mousemove(v) {
3294
+ if (u === "draw-freehand" && R.current) {
3295
+ _([v.latlng.lng, v.latlng.lat]);
3296
+ return;
3297
+ }
3298
+ if ((u === "draw-polygon" || u === "cut-hole") && e.getState().polygonInProgress.length >= 3) {
3299
+ const q = e.getState().polygonInProgress[0], ge = s.latLngToLayerPoint([q[1], q[0]]), ne = Math.hypot(v.layerPoint.x - ge.x, v.layerPoint.y - ge.y);
3300
+ s.getContainer().style.cursor = ne <= 48 ? "pointer" : "crosshair";
3301
+ return;
3302
+ }
3303
+ if (u !== "draw-route" || te.current.length === 0) return;
3304
+ const U = [v.latlng.lng, v.latlng.lat];
3305
+ f(U), h(null), L.current && clearTimeout(L.current), V.current && V.current.abort();
3306
+ const ee = te.current[te.current.length - 1];
3307
+ L.current = setTimeout(async () => {
3308
+ const q = new AbortController();
3309
+ V.current = q;
3310
+ try {
3311
+ if (!a.current) return;
3312
+ const ge = await Un([ee, U], { ...a.current, signal: q.signal });
3313
+ q.signal.aborted || h(ge);
3314
+ } catch {
3315
+ }
3316
+ }, 400);
3317
+ },
3318
+ click(v) {
3319
+ var ee, q, ge;
3320
+ const U = ce.click(v.originalEvent);
3321
+ if (!((ee = v.originalEvent.target) != null && ee.closest(".leaflet-tooltip"))) {
3322
+ if (u === "measure") {
3323
+ if (U || gs()) return;
3324
+ const ne = v.originalEvent.target;
3325
+ if ((q = ne == null ? void 0 : ne.closest) != null && q.call(ne, "path") || (ge = ne == null ? void 0 : ne.closest) != null && ge.call(ne, ".elm-measure-label")) return;
3326
+ const fe = e.getState();
3327
+ fe.selectedMeasurementId && fe.setSelectedMeasurementId(null);
3328
+ const W = fe.snappedCoord ?? [v.latlng.lng, v.latlng.lat];
3329
+ fe.addMeasurePoint(W);
3330
+ return;
3331
+ }
3332
+ if (!(v.originalEvent.metaKey || v.originalEvent.ctrlKey || v.originalEvent.altKey) && !fs()) {
3333
+ if (["place-point", "draw-line", "draw-polygon", "draw-route"].includes(u) && n.getState().selectedIds.length > 0 && n.setState({ selectedIds: [] }), u === "place-point") {
3334
+ if (U) return;
3335
+ const ne = e.getState().snappedCoord ?? [v.latlng.lng, v.latlng.lat];
3336
+ g(ne);
3337
+ return;
3338
+ }
3339
+ if (u === "draw-line" || u === "draw-polygon" || u === "draw-route" || u === "cut-hole" || u === "slice-shape") {
3340
+ let ne = e.getState().snappedCoord ?? [v.latlng.lng, v.latlng.lat];
3341
+ if (c.current || v.originalEvent.shiftKey) {
3342
+ const fe = e.getState();
3343
+ let W = null;
3344
+ (u === "draw-line" || u === "slice-shape") && fe.lineInProgress.length >= 1 ? W = fe.lineInProgress[fe.lineInProgress.length - 1] : (u === "draw-polygon" || u === "cut-hole") && fe.polygonInProgress.length >= 1 && (W = fe.polygonInProgress[fe.polygonInProgress.length - 1]), W && (ne = Lo(s, W, ne, 15));
3345
+ }
3346
+ if ((u === "draw-polygon" || u === "cut-hole") && e.getState().polygonInProgress.length >= 2) {
3347
+ const fe = e.getState(), W = fe.polygonInProgress[0], we = s.latLngToLayerPoint([W[1], W[0]]);
3348
+ if (Math.hypot(v.layerPoint.x - we.x, v.layerPoint.y - we.y) <= 48) {
3349
+ u === "draw-polygon" ? fe.commitPolygon({}) : u === "cut-hole" && fe.commitCutHole();
3350
+ return;
3351
+ }
3352
+ }
3353
+ if (U) return;
3354
+ if (u === "draw-line" || u === "slice-shape") P(ne);
3355
+ else if (u === "draw-polygon" || u === "cut-hole") d(ne);
3356
+ else if (u === "draw-route") {
3357
+ ue.current = { waypoints: [...te.current], preview: e.getState().routePreview }, L.current && (clearTimeout(L.current), L.current = null), V.current && (V.current.abort(), V.current = null), f(null), h(null), y(ne);
3358
+ const fe = [...te.current, ne];
3359
+ X(fe);
3360
+ }
3361
+ }
3362
+ }
3363
+ }
3364
+ },
3365
+ dblclick() {
3366
+ if (!ce.isDouble()) return;
3367
+ const v = e.getState();
3368
+ if (u === "measure") {
3369
+ v.completeMeasure();
3370
+ return;
3371
+ }
3372
+ u === "draw-line" ? v.commitLine({}) : u === "draw-polygon" ? v.commitPolygon({}) : u === "cut-hole" ? v.commitCutHole() : u === "slice-shape" ? v.commitSliceShape() : u === "draw-route" && (ue.current && (e.setState({
3373
+ routeWaypoints: ue.current.waypoints,
3374
+ routePreview: ue.current.preview,
3375
+ routeLoading: !1
3376
+ }), ue.current = null), v.commitRoute());
3377
+ }
3378
+ }), Q(() => {
3379
+ const v = s.getContainer();
3380
+ u !== "none" ? (v.style.cursor = u === "pick-shape" ? "pointer" : "crosshair", v.classList.add("drawing-mode")) : (v.style.cursor = "", v.classList.remove("drawing-mode"));
3381
+ }, [u, s]), Q(() => () => {
3382
+ L.current && clearTimeout(L.current), V.current && V.current.abort();
3383
+ }, []), Q(() => {
3384
+ ["draw-freehand", "draw-rect", "draw-circle"].includes(u) ? E.current || s.dragging.disable() : (s.dragging.enable(), R.current = !1);
3385
+ }, [u, s]), null;
3386
+ }
3387
+ function hs() {
3388
+ const t = be(), e = ut(t.getContainer())[500], n = K((m) => m.editingMode), o = K((m) => m.lineInProgress), r = K((m) => m.polygonInProgress), a = K((m) => m.freehandPoints), i = K((m) => m.freehandClosed), l = K((m) => m.snappedCoord), [s, u] = de(null), [g, P] = de(!1);
3389
+ Q(() => {
3390
+ const m = (x) => {
3391
+ x.key === "Shift" && P(!0);
3392
+ }, y = (x) => {
3393
+ x.key === "Shift" && P(!1);
3394
+ };
3395
+ return window.addEventListener("keydown", m), window.addEventListener("keyup", y), () => {
3396
+ window.removeEventListener("keydown", m), window.removeEventListener("keyup", y);
3397
+ };
3398
+ }, []), je({
3399
+ mousemove(m) {
3400
+ n === "draw-line" || n === "draw-polygon" || n === "slice-shape" || n === "cut-hole" ? (u([m.latlng.lng, m.latlng.lat]), P(m.originalEvent.shiftKey)) : s && u(null);
3401
+ },
3402
+ mouseout() {
3403
+ u(null);
3404
+ }
3405
+ });
3406
+ let d = l ?? s, p = null;
3407
+ (n === "draw-line" || n === "slice-shape") && o.length >= 1 ? p = o[o.length - 1] : (n === "draw-polygon" || n === "cut-hole") && r.length >= 1 && (p = r[r.length - 1]);
3408
+ const C = g && p !== null && d !== null;
3409
+ if (C && p && d && (d = Lo(t, p, d, 15)), n === "draw-freehand" && a.length >= 2) {
3410
+ const m = a[0], y = a[a.length - 1];
3411
+ return /* @__PURE__ */ le(xe, { children: [
3412
+ /* @__PURE__ */ w(
3413
+ ve,
3414
+ {
3415
+ positions: a.map(G),
3416
+ pathOptions: { color: e, weight: 2, opacity: 0.8 },
3417
+ interactive: !1
3418
+ }
3419
+ ),
3420
+ i && /* @__PURE__ */ w(
3421
+ ve,
3422
+ {
3423
+ positions: [G(y), G(m)],
3424
+ pathOptions: { color: e, weight: 2, opacity: 0.4, dashArray: "6 5" },
3425
+ interactive: !1
3426
+ }
3427
+ )
3428
+ ] });
3429
+ }
3430
+ if (!d) return null;
3431
+ const M = C ? "#db2777" : e, S = C ? "#db2777" : e;
3432
+ if ((n === "draw-line" || n === "slice-shape") && p)
3433
+ return /* @__PURE__ */ w(
3434
+ ve,
3435
+ {
3436
+ positions: [G(p), G(d)],
3437
+ pathOptions: { color: M, weight: 2, opacity: 0.4, dashArray: "6 5" },
3438
+ interactive: !1
3439
+ }
3440
+ );
3441
+ if ((n === "draw-polygon" || n === "cut-hole") && p) {
3442
+ const m = r[0];
3443
+ return /* @__PURE__ */ le(xe, { children: [
3444
+ /* @__PURE__ */ w(
3445
+ ve,
3446
+ {
3447
+ positions: [G(p), G(d)],
3448
+ pathOptions: { color: S, weight: 2, opacity: 0.4, dashArray: "6 5" },
3449
+ interactive: !1
3450
+ }
3451
+ ),
3452
+ r.length >= 2 && /* @__PURE__ */ w(
3453
+ ve,
3454
+ {
3455
+ positions: [G(d), G(m)],
3456
+ pathOptions: { color: S, weight: 2, opacity: 0.25, dashArray: "4 6" },
3457
+ interactive: !1
3458
+ }
3459
+ )
3460
+ ] });
3461
+ }
3462
+ return null;
3463
+ }
3464
+ function ys(t) {
3465
+ return Oe({
3466
+ className: "",
3467
+ html: `<div class="w-3 h-3 ${t ? "bg-primary-500 rounded-full" : "bg-primary-400 rotate-45 rounded-sm"} border-2 border-white shadow-md"></div>`,
3468
+ iconSize: [12, 12],
3469
+ iconAnchor: [6, 6]
3470
+ });
3471
+ }
3472
+ function vs() {
3473
+ var d;
3474
+ const { dataStore: t, uiStore: e } = De(), n = K((p) => p.snapEnabled), o = K((p) => p.snappedCoord), r = K((p) => p.editingMode), a = K((p) => p.vertexEditActive), i = n && (r !== "none" || a), l = $(null), s = be();
3475
+ function u(p) {
3476
+ var f, h;
3477
+ const C = p.originalEvent.metaKey || p.originalEvent.ctrlKey;
3478
+ if (!i || C) {
3479
+ e.getState().snappedCoord && e.getState().setSnappedCoord(null);
3480
+ return;
3481
+ }
3482
+ const M = (f = p.originalEvent) == null ? void 0 : f.target;
3483
+ if ((h = M == null ? void 0 : M.closest) != null && h.call(M, ".elm-midpoint-marker")) {
3484
+ e.getState().snappedCoord && e.getState().setSnappedCoord(null);
3485
+ return;
3486
+ }
3487
+ const S = t.getState().features, m = Gr(), y = new Set(m ? [m] : []), x = Sn(p.latlng.lng, p.latlng.lat, s, S, 15, y);
3488
+ x ? a && x.isVertex ? (l.current = null, e.getState().snappedCoord && e.getState().setSnappedCoord(null)) : (l.current = { isVertex: x.isVertex }, e.getState().setSnappedCoord(x.latlng)) : (l.current = null, e.getState().snappedCoord && e.getState().setSnappedCoord(null));
3489
+ }
3490
+ const g = $(u);
3491
+ g.current = u;
3492
+ const [P] = de(() => bn((p) => g.current(p)));
3493
+ return Q(() => {
3494
+ const p = () => P.flush();
3495
+ return window.addEventListener("pointerdown", p, !0), window.addEventListener("pointerup", p, !0), () => {
3496
+ P.cancel(), window.removeEventListener("pointerdown", p, !0), window.removeEventListener("pointerup", p, !0);
3497
+ };
3498
+ }, [P]), je({
3499
+ mousemove(p) {
3500
+ P.schedule(p);
3501
+ },
3502
+ mouseout() {
3503
+ P.cancel(), e.getState().snappedCoord && e.getState().setSnappedCoord(null);
3504
+ }
3505
+ }), !i || !o ? null : /* @__PURE__ */ w(
3506
+ Le,
3507
+ {
3508
+ position: G(o),
3509
+ icon: ys(((d = l.current) == null ? void 0 : d.isVertex) ?? !0),
3510
+ interactive: !1,
3511
+ zIndexOffset: 1e4
3512
+ }
3513
+ );
3514
+ }
3515
+ function ws(t) {
3516
+ const e = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
3517
+ return t < 26 ? e[t] : e[Math.floor(t / 26) - 1] + e[t % 26];
3518
+ }
3519
+ function xs(t, e) {
3520
+ return Oe({
3521
+ className: "",
3522
+ html: `<div style="
3523
+ width:22px;height:22px;border-radius:50%;
3524
+ background:${e ? "var(--color-primary-700)" : "var(--color-primary-500)"};border:2px solid white;
3525
+ box-shadow:0 1px 4px rgba(0,0,0,0.35);
3526
+ display:flex;align-items:center;justify-content:center;
3527
+ font-size:10px;font-weight:700;color:white;font-family:monospace;
3528
+ line-height:1;
3529
+ ">${t}</div>`,
3530
+ iconSize: [22, 22],
3531
+ iconAnchor: [11, 11]
3532
+ });
3533
+ }
3534
+ function Ss() {
3535
+ const t = ut(be().getContainer()), e = K((g) => g.editingMode), n = K((g) => g.routeWaypoints), o = K((g) => g.routePreview), r = K((g) => g.routeLoading), a = K((g) => g.routeCursorPos), i = K((g) => g.routeCursorPreview);
3536
+ if (e !== "draw-route" || n.length === 0) return null;
3537
+ const l = o ?? n, s = n[n.length - 1], u = a ? i ?? [s, a] : null;
3538
+ return /* @__PURE__ */ le(xe, { children: [
3539
+ l.length >= 2 && /* @__PURE__ */ w(
3540
+ ve,
3541
+ {
3542
+ positions: l.map(G),
3543
+ pathOptions: {
3544
+ color: t[700],
3545
+ weight: 3,
3546
+ opacity: r ? 0.5 : 0.9,
3547
+ dashArray: r ? "6 6" : void 0
3548
+ }
3549
+ }
3550
+ ),
3551
+ u && u.length >= 2 && /* @__PURE__ */ w(
3552
+ ve,
3553
+ {
3554
+ positions: u.map(G),
3555
+ pathOptions: {
3556
+ color: t[700],
3557
+ weight: 2,
3558
+ opacity: i ? 0.55 : 0.3,
3559
+ dashArray: "6 5"
3560
+ }
3561
+ }
3562
+ ),
3563
+ n.map((g, P) => /* @__PURE__ */ w(
3564
+ Le,
3565
+ {
3566
+ position: G(g),
3567
+ icon: xs(ws(P), P === n.length - 1),
3568
+ interactive: !1
3569
+ },
3570
+ `wp-${g[0].toFixed(8)},${g[1].toFixed(8)}-${P}`
3571
+ ))
3572
+ ] });
3573
+ }
3574
+ function bs() {
3575
+ const t = be(), e = K((o) => o.boundaryAutofitBbox), n = K((o) => o.setBoundaryAutofitBbox);
3576
+ return Q(() => {
3577
+ if (!e) return;
3578
+ const [o, r, a, i] = e, l = Dn(t.getContainer());
3579
+ t.fitBounds([[o, a], [r, i]], { paddingTopLeft: [l.left, l.top], paddingBottomRight: [l.right, l.bottom], maxZoom: 10, duration: 1 }), n(null);
3580
+ }, [t, e, n]), null;
3581
+ }
3582
+ const Ps = Oe({ className: "hidden" });
3583
+ function Cs() {
3584
+ const { units: t } = kt(), e = { unit: t.length, display: t.display, precision: t.precision }, n = { unit: t.area, display: t.display, precision: t.precision }, o = (f) => {
3585
+ const { value: h, unit: I } = Gt(f * 1e3, e);
3586
+ return `${h} ${I}`;
3587
+ }, r = (f) => {
3588
+ const { value: h, unit: I } = An(f, n);
3589
+ return `${h} ${I}`;
3590
+ }, a = K((f) => f.showMeasurements), i = K((f) => f.editingMode), l = K((f) => f.snappedCoord), s = on(i, i !== "none"), u = K((f) => f.lineInProgress), g = K((f) => f.polygonInProgress), P = K((f) => f.circleCenter), d = K((f) => f.rectCorner), p = K((f) => f.freehandPoints), C = K((f) => f.freehandClosed), M = K((f) => f.routeWaypoints), S = be(), m = $(null);
3591
+ if (Q(() => {
3592
+ var _;
3593
+ const f = (_ = m.current) == null ? void 0 : _.getElement(), h = l ?? s;
3594
+ if (!f || !h) return;
3595
+ f.style.margin = "0";
3596
+ const I = f.getBoundingClientRect(), z = S.getContainer().getBoundingClientRect(), k = S.latLngToContainerPoint(G(h)), { left: H, top: D } = fo(z.left + k.x, z.top + k.y, I.width, I.height, { x: "after", y: "center", gapX: 20, bounds: z });
3597
+ f.style.marginLeft = `${H - I.left}px`, f.style.marginTop = `${D - I.top}px`;
3598
+ }), !a || i === "none") return null;
3599
+ const y = l ?? s;
3600
+ if (!y) return null;
3601
+ const x = [];
3602
+ try {
3603
+ if (i === "place-point")
3604
+ x.push({ label: "", value: `${y[1].toFixed(6)}, ${y[0].toFixed(6)}` });
3605
+ else if (i === "draw-line" || i === "slice-shape") {
3606
+ const f = [...u, y];
3607
+ if (f.length >= 2) {
3608
+ const h = Tt(f);
3609
+ x.push({ label: "Length", value: o(ft(h)) }), x.push({ label: "Segment length", value: o(lt(f[f.length - 2], f[f.length - 1])) });
3610
+ }
3611
+ x.push({ label: "", value: `${y[1].toFixed(6)}, ${y[0].toFixed(6)}` });
3612
+ } else if (i === "draw-polygon" || i === "cut-hole") {
3613
+ const f = [...g, y];
3614
+ if (f.length >= 3) {
3615
+ const h = [...f, f[0]], I = Yt([h]);
3616
+ x.push({ label: "Area", value: r(jt(I)) }), x.push({ label: "Perimeter", value: o(ft(I)) });
3617
+ const z = ho(I);
3618
+ x.push({ label: "Height", value: o(lt([z[0], z[1]], [z[0], z[3]])) }), x.push({ label: "Width", value: o(lt([z[0], z[1]], [z[2], z[1]])) });
3619
+ } else f.length === 2 && x.push({ label: "Segment length", value: o(lt(f[0], f[1])) });
3620
+ x.push({ label: "", value: `${y[1].toFixed(6)}, ${y[0].toFixed(6)}` });
3621
+ } else if (i === "draw-circle") {
3622
+ if (P) {
3623
+ const f = lt(P, y);
3624
+ x.push({ label: "Radius", value: o(f) }), x.push({ label: "Area", value: r(Math.PI * (f * 1e3) * (f * 1e3)) });
3625
+ }
3626
+ x.push({ label: "", value: `${y[1].toFixed(6)}, ${y[0].toFixed(6)}` });
3627
+ } else if (i === "draw-rect") {
3628
+ if (d) {
3629
+ const f = lt([d[0], d[1]], [y[0], d[1]]), h = lt([d[0], d[1]], [d[0], y[1]]), I = f * h * 1e6;
3630
+ x.push({ label: "Area", value: r(I) }), x.push({ label: "Width", value: o(f) }), x.push({ label: "Height", value: o(h) });
3631
+ }
3632
+ x.push({ label: "", value: `${y[1].toFixed(6)}, ${y[0].toFixed(6)}` });
3633
+ } else if (i === "draw-route") {
3634
+ const f = [...M, y];
3635
+ f.length >= 2 && x.push({ label: "Straight distance", value: o(lt(f[f.length - 2], f[f.length - 1])) }), x.push({ label: "", value: `${y[1].toFixed(6)}, ${y[0].toFixed(6)}` });
3636
+ } else if (i === "draw-freehand") {
3637
+ if (p.length >= 3 && C) {
3638
+ const f = [...p, p[0]], h = Yt([f]);
3639
+ x.push({ label: "Area", value: r(jt(h)) }), x.push({ label: "Perimeter", value: o(ft(h)) });
3640
+ } else if (p.length >= 2) {
3641
+ const f = Tt(p);
3642
+ x.push({ label: "Length", value: o(ft(f)) });
3643
+ }
3644
+ x.push({ label: "", value: `${y[1].toFixed(6)}, ${y[0].toFixed(6)}` });
3645
+ }
3646
+ } catch {
3647
+ }
3648
+ return x.length === 0 ? null : /* @__PURE__ */ w(Le, { position: G(y), icon: Ps, interactive: !1, zIndexOffset: 99999, children: /* @__PURE__ */ w(hn, { ref: m, permanent: !0, direction: "right", offset: [20, 0], className: "before:!hidden !bg-(--elm-surface,var(--color-white)) !border !border-(--elm-border,var(--color-gray-200)) !shadow-elm-control !rounded-elm-card !p-3 !text-xs !text-(--elm-text-secondary,var(--color-gray-600)) !font-elm pointer-events-none !whitespace-nowrap", children: /* @__PURE__ */ w("div", { className: "space-y-1 text-left", children: x.map((f, h) => /* @__PURE__ */ le("div", { className: "flex gap-2 items-center leading-snug", children: [
3649
+ f.label && /* @__PURE__ */ le("span", { className: "font-semibold text-(--elm-text,var(--color-gray-900))", children: [
3650
+ f.label,
3651
+ ":"
3652
+ ] }),
3653
+ /* @__PURE__ */ w("span", { children: f.value })
3654
+ ] }, h)) }) }) });
3655
+ }
3656
+ const tt = "#e74c3c", Ms = "#ff2d1a", Es = "#c0392b", To = Oe({
3657
+ className: "",
3658
+ html: `<div style="width:10px;height:10px;border-radius:50%;border:2.5px solid ${tt};background:white;box-shadow:0 1px 4px rgba(0,0,0,0.25)"></div>`,
3659
+ iconSize: [10, 10],
3660
+ iconAnchor: [5, 5]
3661
+ }), Oo = Oe({
3662
+ className: "",
3663
+ html: `<div style="width:10px;height:10px;border-radius:50%;background:${tt};border:2px solid white;box-shadow:0 1px 4px rgba(0,0,0,0.25)"></div>`,
3664
+ iconSize: [10, 10],
3665
+ iconAnchor: [5, 5]
3666
+ });
3667
+ let Ye = null;
3668
+ function No(t) {
3669
+ Ye && (Ye.style.left = t.clientX + "px", Ye.style.top = t.clientY + "px");
3670
+ }
3671
+ function Ls(t, e, n) {
3672
+ Ye || (Ye = document.createElement("div"), Ye.className = "elm-feature-tooltip", Ye.style.cssText = "position:fixed;pointer-events:none;z-index:10000;transform:translate(-50%,-100%);margin-top:-12px", document.body.appendChild(Ye), document.addEventListener("mousemove", No, { passive: !0 })), Ye.textContent = t, Ye.style.left = e + "px", Ye.style.top = n + "px";
3673
+ }
3674
+ function io() {
3675
+ Ye && (Ye.remove(), Ye = null, document.removeEventListener("mousemove", No));
3676
+ }
3677
+ function ks(t, e, n, o) {
3678
+ try {
3679
+ if (e === "distance" && t.length >= 2) return Gt(ft(Tt(t)) * 1e3, n);
3680
+ if (e === "area" && t.length >= 3) return An(jt(Yt([[...t, t[0]]])), o);
3681
+ } catch {
3682
+ }
3683
+ return null;
3684
+ }
3685
+ const Ds = Oe({
3686
+ className: "elm-measure-label-host",
3687
+ html: "",
3688
+ iconSize: [0, 0],
3689
+ iconAnchor: [-12, 0]
3690
+ // shifts the host's anchor 12px LEFT, so the content sits 12px RIGHT of the latlng
3691
+ });
3692
+ function _o({
3693
+ map: t,
3694
+ position: e,
3695
+ parts: n,
3696
+ onRemove: o
3697
+ }) {
3698
+ const r = $(null), [a, i] = de(null);
3699
+ return Q(() => {
3700
+ const l = Kr([e[1], e[0]], {
3701
+ icon: Ds,
3702
+ // Always interactive=false on the marker itself; the close button below
3703
+ // gets pointer-events:auto via CSS so it can still be clicked.
3704
+ interactive: !1,
3705
+ keyboard: !1,
3706
+ zIndexOffset: 700
3707
+ }).addTo(t);
3708
+ return r.current = l, i(l.getElement() ?? null), () => {
3709
+ l.remove(), r.current = null, i(null);
3710
+ };
3711
+ }, [t]), Q(() => {
3712
+ var l;
3713
+ (l = r.current) == null || l.setLatLng([e[1], e[0]]);
3714
+ }, [e[0], e[1]]), a ? vo(
3715
+ /* @__PURE__ */ le(
3716
+ "div",
3717
+ {
3718
+ className: "elm-measure-label",
3719
+ style: {
3720
+ // Vertically centre the pill on the latLng. Horizontal offset comes
3721
+ // from the icon's iconAnchor (-12,0).
3722
+ transform: "translateY(-50%)",
3723
+ display: "inline-flex",
3724
+ alignItems: "center",
3725
+ gap: 7,
3726
+ pointerEvents: o ? "auto" : "none",
3727
+ userSelect: "none",
3728
+ whiteSpace: "nowrap"
3729
+ },
3730
+ children: [
3731
+ /* @__PURE__ */ le("span", { children: [
3732
+ /* @__PURE__ */ w("span", { style: { fontWeight: 600 }, children: n.value }),
3733
+ /* @__PURE__ */ le("span", { style: { fontWeight: 400, opacity: 0.85 }, children: [
3734
+ " ",
3735
+ n.unit
3736
+ ] })
3737
+ ] }),
3738
+ o && /* @__PURE__ */ w(
3739
+ "button",
3740
+ {
3741
+ className: "elm-measure-close",
3742
+ onClick: (l) => {
3743
+ l.stopPropagation(), o();
3744
+ },
3745
+ title: "Clear measurement",
3746
+ style: { marginRight: "-5px" },
3747
+ children: /* @__PURE__ */ le("svg", { width: "10", height: "10", viewBox: "0 0 10 10", fill: "none", stroke: "rgba(255,255,255,0.8)", strokeWidth: "1.5", strokeLinecap: "round", children: [
3748
+ /* @__PURE__ */ w("line", { x1: "1.5", y1: "1.5", x2: "8.5", y2: "8.5" }),
3749
+ /* @__PURE__ */ w("line", { x1: "8.5", y1: "1.5", x2: "1.5", y2: "8.5" })
3750
+ ] })
3751
+ }
3752
+ )
3753
+ ]
3754
+ }
3755
+ ),
3756
+ a
3757
+ ) : null;
3758
+ }
3759
+ const Is = Ze(function({
3760
+ map: e,
3761
+ m: n
3762
+ }) {
3763
+ const o = K((m) => m.removeMeasurement), r = K((m) => m.toggleMeasurementSelection), a = K((m) => m.selectedMeasurementId === n.id), [i, l] = de(!1), { units: s } = kt(), u = { unit: s.length, display: s.display, precision: s.precision }, g = { unit: s.area, display: s.display, precision: s.precision };
3764
+ Q(() => () => io(), []);
3765
+ const P = _e(() => {
3766
+ try {
3767
+ if (n.mode === "distance" && n.points.length >= 2)
3768
+ return Gt(ft(Tt(n.points)) * 1e3, u);
3769
+ if (n.mode === "area" && n.points.length >= 3)
3770
+ return An(jt(Yt([n.points])), g);
3771
+ } catch {
3772
+ }
3773
+ return null;
3774
+ }, [n, u.unit, u.display, u.precision, g.unit, g.display, g.precision]), d = n.mode === "area" ? n.points[n.points.length - 2] : n.points[n.points.length - 1], p = n.mode === "area" ? n.points.slice(0, -1) : n.points, C = a ? Es : i ? Ms : tt, M = a || i ? 1 : 0.9, S = (m) => {
3775
+ ds(), m.originalEvent.stopPropagation(), r(n.id);
3776
+ };
3777
+ return /* @__PURE__ */ le(xe, { children: [
3778
+ n.mode === "distance" ? n.points.slice(0, -1).map((m, y) => {
3779
+ const x = n.points[y + 1], f = Gt(ft(Tt([m, x])) * 1e3, u), h = `${f.value} ${f.unit}`;
3780
+ return /* @__PURE__ */ w(
3781
+ ve,
3782
+ {
3783
+ positions: [G(m), G(x)],
3784
+ pathOptions: { color: tt, weight: 16, opacity: 0, className: "elm-measure-segment" },
3785
+ interactive: !0,
3786
+ eventHandlers: {
3787
+ mouseover: (I) => {
3788
+ l(!0), Ls(h, I.originalEvent.clientX, I.originalEvent.clientY);
3789
+ },
3790
+ mouseout: () => {
3791
+ l(!1), io();
3792
+ },
3793
+ click: S
3794
+ }
3795
+ },
3796
+ `seg-${y}`
3797
+ );
3798
+ }) : /* @__PURE__ */ w(
3799
+ ve,
3800
+ {
3801
+ positions: n.points.map(G),
3802
+ pathOptions: { color: tt, weight: 16, opacity: 0 },
3803
+ interactive: !0,
3804
+ eventHandlers: {
3805
+ mouseover: () => l(!0),
3806
+ mouseout: () => l(!1),
3807
+ click: S
3808
+ }
3809
+ }
3810
+ ),
3811
+ /* @__PURE__ */ w(
3812
+ ve,
3813
+ {
3814
+ positions: n.points.map(G),
3815
+ pathOptions: { color: C, weight: 3, opacity: M, dashArray: "10 6" },
3816
+ interactive: !1
3817
+ }
3818
+ ),
3819
+ n.mode === "area" && n.points.length >= 3 && /* @__PURE__ */ w(
3820
+ He,
3821
+ {
3822
+ positions: n.points.map(G),
3823
+ pathOptions: { color: C, weight: 0, fillColor: C, fillOpacity: a ? 0.15 : i ? 0.12 : 0.08 },
3824
+ interactive: !0,
3825
+ eventHandlers: {
3826
+ click: S,
3827
+ mouseover: () => l(!0),
3828
+ mouseout: () => l(!1)
3829
+ }
3830
+ }
3831
+ ),
3832
+ p.map((m, y) => /* @__PURE__ */ w(
3833
+ Le,
3834
+ {
3835
+ position: G(m),
3836
+ icon: y === 0 ? To : Oo,
3837
+ interactive: !1,
3838
+ zIndexOffset: 1e3 + y
3839
+ },
3840
+ y
3841
+ )),
3842
+ P && d && /* @__PURE__ */ w(
3843
+ _o,
3844
+ {
3845
+ map: e,
3846
+ position: d,
3847
+ parts: P,
3848
+ onRemove: () => o(n.id)
3849
+ }
3850
+ )
3851
+ ] });
3852
+ });
3853
+ function As() {
3854
+ const t = be(), e = K((y) => y.editingMode), n = K((y) => y.measurePoints), o = K((y) => y.measureMode), r = K((y) => y.completedMeasurements), a = K((y) => y.snappedCoord), i = K((y) => y.setSelectedMeasurementId), l = on(e, e === "measure"), { units: s } = kt(), u = { unit: s.length, display: s.display, precision: s.precision }, g = { unit: s.area, display: s.display, precision: s.precision };
3855
+ je({
3856
+ click(y) {
3857
+ var x, f;
3858
+ (f = (x = y.originalEvent.target) == null ? void 0 : x.closest) != null && f.call(x, "path") || i(null);
3859
+ }
3860
+ });
3861
+ const P = e === "measure";
3862
+ if (!P && n.length === 0 && r.length === 0) return null;
3863
+ const d = P ? a ?? l : null, p = n.length > 0 ? n[n.length - 1] : null, C = o === "distance" ? 1 : 2, M = d && n.length >= C ? [...n, d] : n, S = ks(M, o, u, g), m = d ?? p;
3864
+ return /* @__PURE__ */ le(xe, { children: [
3865
+ r.map((y) => /* @__PURE__ */ w(Is, { map: t, m: y }, y.id)),
3866
+ n.length >= 2 && /* @__PURE__ */ w(
3867
+ ve,
3868
+ {
3869
+ positions: n.map(G),
3870
+ pathOptions: { color: tt, weight: 3, opacity: 0.9, dashArray: "10 6" },
3871
+ interactive: !1
3872
+ }
3873
+ ),
3874
+ o === "area" && n.length >= 3 && /* @__PURE__ */ w(
3875
+ He,
3876
+ {
3877
+ positions: n.map(G),
3878
+ pathOptions: { color: tt, weight: 0, fillColor: tt, fillOpacity: 0.08 },
3879
+ interactive: !1
3880
+ }
3881
+ ),
3882
+ d && p && /* @__PURE__ */ w(
3883
+ ve,
3884
+ {
3885
+ positions: [G(p), G(d)],
3886
+ pathOptions: { color: tt, weight: 3, opacity: 0.45, dashArray: "10 6" },
3887
+ interactive: !1
3888
+ }
3889
+ ),
3890
+ o === "area" && d && n.length >= 2 && /* @__PURE__ */ w(
3891
+ ve,
3892
+ {
3893
+ positions: [G(d), G(n[0])],
3894
+ pathOptions: { color: tt, weight: 2, opacity: 0.25, dashArray: "6 6" },
3895
+ interactive: !1
3896
+ }
3897
+ ),
3898
+ n.map((y, x) => /* @__PURE__ */ w(
3899
+ Le,
3900
+ {
3901
+ position: G(y),
3902
+ icon: x === 0 ? To : Oo,
3903
+ interactive: !1,
3904
+ zIndexOffset: 1e3 + x
3905
+ },
3906
+ x
3907
+ )),
3908
+ S && m && /* @__PURE__ */ w(_o, { map: t, position: m, parts: S })
3909
+ ] });
3910
+ }
3911
+ let so = !1;
3912
+ function Rs() {
3913
+ if (so) return;
3914
+ const t = document.createElement("style");
3915
+ t.textContent = `
3916
+ @keyframes elm-osm-pulse {
3917
+ 0% { transform: scale(0.6); opacity: 0.7; }
3918
+ 100% { transform: scale(3); opacity: 0; }
3919
+ }
3920
+ @keyframes elm-osm-spin {
3921
+ to { transform: rotate(360deg); }
3922
+ }
3923
+ .elm-osm-pulse-ring {
3924
+ width: 64px; height: 64px; border-radius: 50%;
3925
+ background: color-mix(in srgb, var(--color-primary-500) 20%, transparent);
3926
+ animation: elm-osm-pulse 1.4s ease-out infinite;
3927
+ pointer-events: none;
3928
+ }
3929
+ .elm-osm-spinner {
3930
+ width: 24px; height: 24px; border-radius: 50%;
3931
+ border: 4px solid color-mix(in srgb, var(--color-primary-500) 20%, transparent);
3932
+ border-top-color: var(--color-primary-500);
3933
+ animation: elm-osm-spin 0.8s linear infinite;
3934
+ pointer-events: none;
3935
+ }
3936
+ `, document.head.appendChild(t), so = !0;
3937
+ }
3938
+ const Fs = () => (Rs(), Xe.divIcon({
3939
+ className: "",
3940
+ html: `<div style="width:64px;height:64px;position:relative;display:flex;align-items:center;justify-content:center">
3941
+ <div class="elm-osm-pulse-ring" style="position:absolute"></div>
3942
+ <div class="elm-osm-spinner"></div>
3943
+ </div>`,
3944
+ iconSize: [64, 64],
3945
+ iconAnchor: [32, 32]
3946
+ }));
3947
+ function Ts() {
3948
+ const t = be(), { dataStore: e, uiStore: n } = De(), o = kt().network, r = $(o);
3949
+ r.current = o;
3950
+ const a = Nt(), i = Qt(), l = K((h) => h.editingMode), [s, u] = de(null), [g, P] = de(null), d = vr(), p = wr(), C = $(null), M = $(null), S = $(null), m = $(null);
3951
+ Q(() => () => {
3952
+ var h, I;
3953
+ (h = S.current) == null || h.remove(), (I = M.current) == null || I.abort();
3954
+ }, []);
3955
+ const y = Fe(
3956
+ (h) => ar(e.getState(), n.getState(), h),
3957
+ [e, n]
3958
+ ), x = Fe(() => {
3959
+ S.current && (S.current.remove(), S.current = null);
3960
+ }, []), f = Fe(() => {
3961
+ u(null), P(null), C.current = null, x(), M.current && (M.current.abort(), M.current = null);
3962
+ }, [x]);
3963
+ return Q(() => {
3964
+ if (!s && l !== "pick-shape") return;
3965
+ function h(I) {
3966
+ I.key === "Escape" && i(I) && f();
3967
+ }
3968
+ return window.addEventListener("keydown", h), () => window.removeEventListener("keydown", h);
3969
+ }, [s, l, f, i]), je({
3970
+ click(h) {
3971
+ if (l !== "pick-shape") return;
3972
+ if (t.getZoom() < lr) {
3973
+ a({ type: "warning", message: "Zoom in further to use the picker" });
3974
+ return;
3975
+ }
3976
+ h.originalEvent.preventDefault(), f();
3977
+ const I = new AbortController();
3978
+ M.current = I;
3979
+ const { lat: z, lng: k } = h.latlng;
3980
+ C.current = h.latlng, S.current = Xe.marker(h.latlng, { icon: Fs(), interactive: !1 }).addTo(t);
3981
+ const { overpass: H, fetch: D } = r.current;
3982
+ if (H === !1) {
3983
+ x(), f();
3984
+ return;
3985
+ }
3986
+ Fr(z, k, cr(t.getZoom()), [k, z], { ...H, fetch: D, signal: I.signal }).then((_) => {
3987
+ x(), _.length === 0 ? (a({ type: "warning", message: "No features found here" }), f()) : _.length === 1 ? (y(_[0]), f()) : u(_);
3988
+ }).catch((_) => {
3989
+ (_ == null ? void 0 : _.name) !== "AbortError" && (x(), a({ type: "error", code: _ instanceof Or ? _.code : "unknown", source: "picker", message: Tr(_), cause: _ }), f());
3990
+ });
3991
+ }
3992
+ }), Q(() => {
3993
+ l !== "pick-shape" && f();
3994
+ }, [l, f]), Q(() => {
3995
+ if (!s || !C.current) return;
3996
+ const h = C.current;
3997
+ let I;
3998
+ function z() {
3999
+ if (!m.current) {
4000
+ I = requestAnimationFrame(z);
4001
+ return;
4002
+ }
4003
+ const k = t.latLngToContainerPoint(h), H = t.getContainer().getBoundingClientRect();
4004
+ m.current.style.left = `${H.left + k.x + 16}px`, m.current.style.top = `${H.top + k.y - 8}px`, I = requestAnimationFrame(z);
4005
+ }
4006
+ return I = requestAnimationFrame(z), () => cancelAnimationFrame(I);
4007
+ }, [s, t]), /* @__PURE__ */ le(xe, { children: [
4008
+ s && s.map((h, I) => /* @__PURE__ */ w(
4009
+ He,
4010
+ {
4011
+ positions: h.geometry.coordinates[0].map(G),
4012
+ pathOptions: {
4013
+ color: xt[I % xt.length],
4014
+ fillColor: xt[I % xt.length],
4015
+ weight: g === I ? 3 : 2,
4016
+ opacity: g === I ? 1 : 0.7,
4017
+ fillOpacity: g === I ? 0.3 : 0.12
4018
+ },
4019
+ eventHandlers: {
4020
+ click: (z) => {
4021
+ z.originalEvent.stopPropagation(), y(h), f();
4022
+ },
4023
+ mouseover: () => P(I),
4024
+ mouseout: () => P(null)
4025
+ }
4026
+ },
4027
+ `${h.osmId}/${I}`
4028
+ )),
4029
+ s && vo(
4030
+ /* @__PURE__ */ w("div", { ref: m, "data-elm-portal": !0, "data-elm-theme": p, style: { ...d, position: "fixed", zIndex: 1e4 }, children: /* @__PURE__ */ w("div", { className: "bg-elm-surface/95 backdrop-blur-md border border-elm-border/80 text-elm-text-secondary shadow-elm rounded-elm overflow-hidden min-w-[180px] max-w-[280px] text-sm py-1", children: s.map((h, I) => /* @__PURE__ */ le(
4031
+ "button",
4032
+ {
4033
+ onClick: () => {
4034
+ y(h), f();
4035
+ },
4036
+ onMouseEnter: () => P(I),
4037
+ onMouseLeave: () => P(null),
4038
+ className: `w-full text-left px-3 py-2 flex items-center gap-2 transition-colors ${g === I ? "bg-primary-50 dark:bg-white/5" : "hover:bg-(--elm-surface-hover,var(--color-gray-50)) dark:hover:bg-elm-surface-hover"}`,
4039
+ children: [
4040
+ /* @__PURE__ */ w(
4041
+ "span",
4042
+ {
4043
+ className: "w-2.5 h-2.5 rounded-full shrink-0",
4044
+ style: { background: xt[I % xt.length] }
4045
+ }
4046
+ ),
4047
+ /* @__PURE__ */ le("span", { className: "flex flex-col min-w-0", children: [
4048
+ /* @__PURE__ */ w("span", { className: "font-medium text-(--elm-text,var(--color-gray-800)) dark:text-(--elm-text,var(--color-gray-100)) truncate", children: h.name || `Unnamed ${h.type.toLowerCase()}` }),
4049
+ /* @__PURE__ */ w("span", { className: "text-xs text-(--elm-text-subtle,var(--color-gray-400))", children: h.type })
4050
+ ] })
4051
+ ]
4052
+ },
4053
+ `${h.osmId}/${I}`
4054
+ )) }) }),
4055
+ document.body
4056
+ )
4057
+ ] });
4058
+ }
4059
+ function ao({ geom: t, pathOptions: e }) {
4060
+ switch (t.type) {
4061
+ case "Polygon":
4062
+ return /* @__PURE__ */ w(He, { positions: t.coordinates.map((n) => n.map(G)), pathOptions: e });
4063
+ case "MultiPolygon":
4064
+ return /* @__PURE__ */ w(He, { positions: t.coordinates.map((n) => n.map((o) => o.map(G))), pathOptions: e });
4065
+ case "LineString":
4066
+ return /* @__PURE__ */ w(ve, { positions: t.coordinates.map(G), pathOptions: { ...e, fill: !1 } });
4067
+ case "MultiLineString":
4068
+ return /* @__PURE__ */ w(ve, { positions: t.coordinates.map((n) => n.map(G)), pathOptions: { ...e, fill: !1 } });
4069
+ default:
4070
+ return null;
4071
+ }
4072
+ }
4073
+ function Os() {
4074
+ const t = ut(be().getContainer())[500], e = K((g) => g.editingMode), n = K((g) => g.geometryPreview), o = K((g) => g.bufferCreateNew), r = Se((g) => g.selectedIds[0] ?? null), a = Se((g) => {
4075
+ var P;
4076
+ return r ? ((P = g.features.find((d) => d.id === r)) == null ? void 0 : P.geometry) ?? null : null;
4077
+ });
4078
+ if (!(e === "simplify-shape" || e === "smooth-shape" || e === "buffer-shape") || !n || !vn(n.type)) return null;
4079
+ const l = e === "buffer-shape", s = l && !o && a && vn(a.type), u = ur(n.type);
4080
+ return /* @__PURE__ */ le(xe, { children: [
4081
+ s && /* @__PURE__ */ w(
4082
+ ao,
4083
+ {
4084
+ geom: a,
4085
+ pathOptions: {
4086
+ color: "#6b7280",
4087
+ fillColor: "#6b7280",
4088
+ fillOpacity: 0.07,
4089
+ weight: 1.5,
4090
+ opacity: 0.35,
4091
+ dashArray: "4 4",
4092
+ interactive: !1
4093
+ }
4094
+ }
4095
+ ),
4096
+ /* @__PURE__ */ w(
4097
+ ao,
4098
+ {
4099
+ geom: n,
4100
+ pathOptions: {
4101
+ color: t,
4102
+ fillColor: t,
4103
+ fillOpacity: l && o ? 0.12 : 0.2,
4104
+ // A line preview is the whole shape: draw it at line-feature weight.
4105
+ weight: u ? 3 : l && o ? 2 : 2.5,
4106
+ opacity: 1,
4107
+ dashArray: l && o ? "8 5" : void 0,
4108
+ interactive: !1
4109
+ }
4110
+ }
4111
+ )
4112
+ ] });
4113
+ }
4114
+ function lo(t, e, n) {
4115
+ const [o, r] = fr(t.getContainer());
4116
+ return !o && !r ? Hr(e) : t.unproject(t.project(e, n).subtract([o, r]), n);
4117
+ }
4118
+ function Ns({ routingApiKey: t }) {
4119
+ const e = be(), n = Er(), { dataStore: o } = De();
4120
+ Q(() => {
4121
+ o.getState().setCurrentZoom(e.getZoom());
4122
+ const a = () => o.getState().setCurrentZoom(e.getZoom());
4123
+ return e.on("zoomend", a), () => {
4124
+ e.off("zoomend", a);
4125
+ };
4126
+ }, [e, o]), Q(() => {
4127
+ n({
4128
+ // Points land in the middle of the visible map (clear of the open
4129
+ // panels / docked inspector / table), not under them.
4130
+ flyTo: (a, i) => e.flyTo(lo(e, a, i), i, { duration: 1.2 }),
4131
+ panTo: (a) => e.flyTo(lo(e, a, e.getZoom()), e.getZoom(), { duration: 0.5 }),
4132
+ fitBounds: (a) => {
4133
+ const i = gr(a);
4134
+ if (!i) return;
4135
+ const l = Dn(e.getContainer());
4136
+ e.flyToBounds(
4137
+ [[i.minLat, i.minLng], [i.maxLat, i.maxLng]],
4138
+ { paddingTopLeft: [l.left, l.top], paddingBottomRight: [l.right, l.bottom], maxZoom: 16, duration: 1.2 }
4139
+ );
4140
+ },
4141
+ getCenter: () => {
4142
+ const a = e.getCenter();
4143
+ return [a.lng, a.lat];
4144
+ },
4145
+ setZoom: (a) => {
4146
+ const i = Math.max(e.getMinZoom(), Math.min(e.getMaxZoom(), a));
4147
+ return e.setZoom(i, { animate: !1 }), i;
4148
+ },
4149
+ getZoomBounds: () => ({ min: e.getMinZoom(), max: e.getMaxZoom() }),
4150
+ getMap: () => e
4151
+ });
4152
+ }, [e, n]);
4153
+ const r = Ir(t);
4154
+ return Q(() => {
4155
+ var a;
4156
+ if (r)
4157
+ return (a = e.attributionControl) == null || a.addAttribution(r), () => {
4158
+ var i;
4159
+ (i = e.attributionControl) == null || i.removeAttribution(r);
4160
+ };
4161
+ }, [e, r]), null;
4162
+ }
4163
+ const na = uo(function(e, n) {
4164
+ return e.onEvent || e.onError ? /* @__PURE__ */ w(xr, { onEvent: e.onEvent, onError: e.onError, children: /* @__PURE__ */ w(co, { ...e, ref: n }) }) : /* @__PURE__ */ w(co, { ...e, ref: n });
4165
+ }), co = uo(function(e, n) {
4166
+ const o = be(), { dataStore: r, uiStore: a } = De(), i = Sr({
4167
+ initialData: e.initialData,
4168
+ schema: e.schema,
4169
+ layout: e.layout,
4170
+ readonly: e.readonly,
4171
+ tools: e.tools,
4172
+ maxFeatures: e.maxFeatures,
4173
+ engine: "leaflet",
4174
+ onChange: e.onChange,
4175
+ onSubmit: e.onSubmit,
4176
+ onValidationError: e.onValidationError,
4177
+ onFeatureAdd: e.onFeatureAdd,
4178
+ onFeatureUpdate: e.onFeatureUpdate,
4179
+ onFeatureDelete: e.onFeatureDelete,
4180
+ onSelectionChange: e.onSelectionChange,
4181
+ onFeatureSelect: e.onFeatureSelect,
4182
+ onZoomChange: e.onZoomChange,
4183
+ onToolChange: e.onToolChange
4184
+ });
4185
+ Vo(n, () => i, [i]), Q(() => {
4186
+ }, [r, a, o]), br(o.getContainer()), Pr(o.getContainer()), Cr(o.getContainer()), Q(() => {
4187
+ Mr();
4188
+ }, []), Q(() => {
4189
+ const u = dr(e.bounds);
4190
+ o.setMaxBounds(u ? [[u[1], u[0]], [u[3], u[2]]] : void 0);
4191
+ }, [o, e.bounds]);
4192
+ const l = $(e.onReady);
4193
+ l.current = e.onReady;
4194
+ const s = $(null);
4195
+ return Q(() => {
4196
+ s.current !== o && (s.current = o, o.whenReady(() => {
4197
+ var u;
4198
+ return (u = l.current) == null ? void 0 : u.call(l, o);
4199
+ }));
4200
+ }, [o]), /* @__PURE__ */ le(Mo, { getFeatureStyle: e.getFeatureStyle, children: [
4201
+ /* @__PURE__ */ w(Ns, { routingApiKey: e.routingApiKey }),
4202
+ /* @__PURE__ */ w(bs, {}),
4203
+ /* @__PURE__ */ w(us, { renderer: e.renderer }),
4204
+ /* @__PURE__ */ w(ms, { routingApiKey: e.routingApiKey }),
4205
+ /* @__PURE__ */ w(hs, {}),
4206
+ /* @__PURE__ */ w(vs, {}),
4207
+ /* @__PURE__ */ w(Ss, {}),
4208
+ /* @__PURE__ */ w(Cs, {}),
4209
+ /* @__PURE__ */ w(As, {}),
4210
+ /* @__PURE__ */ w(Ts, {}),
4211
+ /* @__PURE__ */ w(Os, {})
4212
+ ] });
4213
+ });
4214
+ export {
4215
+ ia as ActiveDrawingToolbar,
4216
+ bs as BoundaryLayer,
4217
+ ms as DrawingLayer,
4218
+ hs as DrawingPreviewLayer,
4219
+ sa as EditingToolbar,
4220
+ na as ElementEditorControls,
4221
+ wa as ElementEditorError,
4222
+ aa as ElementEditorUIProvider,
4223
+ us as FeatureInteractionLayer,
4224
+ Mo as FeatureStyleProvider,
4225
+ ta as FitBounds,
4226
+ la as FloatingToolbar,
4227
+ ca as GeoStoreProvider,
4228
+ ua as MapControllerProvider,
4229
+ Cs as MeasurementTooltip,
4230
+ Ss as RoutePreviewLayer,
4231
+ vs as SnapController,
4232
+ da as StoreContext,
4233
+ fi as TransformControls,
4234
+ Sn as findSnapPoint,
4235
+ Lo as snapToAngle,
4236
+ ea as toGeoJSON,
4237
+ G as toLeaflet,
4238
+ ga as useDataStore,
4239
+ Eo as useFeatureStyle,
4240
+ fa as useGeoStore,
4241
+ pa as useKeyboardShortcuts,
4242
+ ma as useMapController,
4243
+ Qr as useMapInteractionMachine,
4244
+ ha as useSetMapController,
4245
+ ya as useUIStore
4246
+ };