@element-editor/adapter-maplibre 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/AGENTS.md +119 -0
  2. package/LICENSE +21 -0
  3. package/README.md +82 -2
  4. package/basemaps/sprite.json +1 -0
  5. package/basemaps/sprite.png +0 -0
  6. package/basemaps/sprite@2x.json +1 -0
  7. package/basemaps/sprite@2x.png +0 -0
  8. package/basemaps/thumbs/dark.webp +0 -0
  9. package/basemaps/thumbs/light.webp +0 -0
  10. package/basemaps/thumbs/osm.webp +0 -0
  11. package/basemaps/thumbs/streets.webp +0 -0
  12. package/basemaps/thumbs/terrain.webp +0 -0
  13. package/dist/adapter-maplibre.css +1 -0
  14. package/dist/basemapIds-2GdXIJS1.cjs +1 -0
  15. package/dist/basemapIds-CVTxeXkr.js +11 -0
  16. package/dist/basemaps.cjs +1 -0
  17. package/dist/basemaps.d.cts +2 -0
  18. package/dist/basemaps.d.ts +2 -0
  19. package/dist/basemaps.es.js +10 -0
  20. package/dist/catalog-Cnqi23GZ.cjs +1 -0
  21. package/dist/catalog-gI-xABuu.js +10 -0
  22. package/dist/dark-C5d5FijX.cjs +1 -0
  23. package/dist/dark-CcJT_yHE.js +13 -0
  24. package/dist/index.cjs +26 -0
  25. package/dist/index.d.cts +2 -0
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.es.js +3792 -0
  28. package/dist/light-Cf5tUOoP.js +13 -0
  29. package/dist/light-DCtd1z4V.cjs +1 -0
  30. package/dist/src/BasemapControl.d.cts +47 -0
  31. package/dist/src/BasemapControl.d.ts +47 -0
  32. package/dist/src/ElementEditorControls.d.cts +113 -0
  33. package/dist/src/ElementEditorControls.d.ts +113 -0
  34. package/dist/src/basemapIds.d.cts +10 -0
  35. package/dist/src/basemapIds.d.ts +10 -0
  36. package/dist/src/basemaps/catalog.d.cts +7 -0
  37. package/dist/src/basemaps/catalog.d.ts +7 -0
  38. package/dist/src/basemaps/index.d.cts +3 -0
  39. package/dist/src/basemaps/index.d.ts +3 -0
  40. package/dist/src/basemaps/style.d.cts +61 -0
  41. package/dist/src/basemaps/style.d.ts +61 -0
  42. package/dist/src/components/BoundaryLayer.d.cts +11 -0
  43. package/dist/src/components/BoundaryLayer.d.ts +11 -0
  44. package/dist/src/components/BoxSelectHandler.d.cts +13 -0
  45. package/dist/src/components/BoxSelectHandler.d.ts +13 -0
  46. package/dist/src/components/DrawingLayer.d.cts +8 -0
  47. package/dist/src/components/DrawingLayer.d.ts +8 -0
  48. package/dist/src/components/DrawingPreviewLayer.d.cts +8 -0
  49. package/dist/src/components/DrawingPreviewLayer.d.ts +8 -0
  50. package/dist/src/components/FeatureInteractionLayer.d.cts +8 -0
  51. package/dist/src/components/FeatureInteractionLayer.d.ts +8 -0
  52. package/dist/src/components/FeatureLayer.d.cts +15 -0
  53. package/dist/src/components/FeatureLayer.d.ts +15 -0
  54. package/dist/src/components/GeometryProcessingPreview.d.cts +8 -0
  55. package/dist/src/components/GeometryProcessingPreview.d.ts +8 -0
  56. package/dist/src/components/MeasurePreviewLayer.d.cts +9 -0
  57. package/dist/src/components/MeasurePreviewLayer.d.ts +9 -0
  58. package/dist/src/components/MeasurementTooltip.d.cts +6 -0
  59. package/dist/src/components/MeasurementTooltip.d.ts +6 -0
  60. package/dist/src/components/OsmTraceHandler.d.cts +8 -0
  61. package/dist/src/components/OsmTraceHandler.d.ts +8 -0
  62. package/dist/src/components/PreciseCoordsOverlay.d.cts +10 -0
  63. package/dist/src/components/PreciseCoordsOverlay.d.ts +10 -0
  64. package/dist/src/components/SnapController.d.cts +9 -0
  65. package/dist/src/components/SnapController.d.ts +9 -0
  66. package/dist/src/components/TextEditOverlay.d.cts +9 -0
  67. package/dist/src/components/TextEditOverlay.d.ts +9 -0
  68. package/dist/src/components/TransformControls.d.cts +8 -0
  69. package/dist/src/components/TransformControls.d.ts +8 -0
  70. package/dist/src/components/VertexEditor.d.cts +15 -0
  71. package/dist/src/components/VertexEditor.d.ts +15 -0
  72. package/dist/src/contexts/FeatureStyleContext.d.cts +9 -0
  73. package/dist/src/contexts/FeatureStyleContext.d.ts +9 -0
  74. package/dist/src/contexts/MapControllerContext.d.cts +2 -0
  75. package/dist/src/contexts/MapControllerContext.d.ts +2 -0
  76. package/dist/src/contexts/StyleEpochContext.d.cts +7 -0
  77. package/dist/src/contexts/StyleEpochContext.d.ts +7 -0
  78. package/dist/src/elementLayers.d.cts +17 -0
  79. package/dist/src/elementLayers.d.ts +17 -0
  80. package/dist/src/hooks/lastPointer.d.cts +18 -0
  81. package/dist/src/hooks/lastPointer.d.ts +18 -0
  82. package/dist/src/hooks/useCursorWhileMode.d.cts +20 -0
  83. package/dist/src/hooks/useCursorWhileMode.d.ts +20 -0
  84. package/dist/src/hooks/useModifierDragCursor.d.cts +8 -0
  85. package/dist/src/hooks/useModifierDragCursor.d.ts +8 -0
  86. package/dist/src/index.d.cts +30 -0
  87. package/dist/src/index.d.ts +30 -0
  88. package/dist/src/store/StoreContext.d.cts +1 -0
  89. package/dist/src/store/StoreContext.d.ts +1 -0
  90. package/dist/src/utils/accentPaint.d.cts +13 -0
  91. package/dist/src/utils/accentPaint.d.ts +13 -0
  92. package/dist/src/utils/boxSelect.d.cts +4 -0
  93. package/dist/src/utils/boxSelect.d.ts +4 -0
  94. package/dist/src/utils/darkStyle.d.cts +8 -0
  95. package/dist/src/utils/darkStyle.d.ts +8 -0
  96. package/dist/src/utils/featureTooltip.d.cts +16 -0
  97. package/dist/src/utils/featureTooltip.d.ts +16 -0
  98. package/dist/src/utils/findPartAtPoint.d.cts +2 -0
  99. package/dist/src/utils/findPartAtPoint.d.ts +2 -0
  100. package/dist/src/utils/freehandCommitFlag.d.cts +2 -0
  101. package/dist/src/utils/freehandCommitFlag.d.ts +2 -0
  102. package/dist/src/utils/freshFeature.d.cts +3 -0
  103. package/dist/src/utils/freshFeature.d.ts +3 -0
  104. package/dist/src/utils/geojson.d.cts +10 -0
  105. package/dist/src/utils/geojson.d.ts +10 -0
  106. package/dist/src/utils/liveFeatureSource.d.cts +6 -0
  107. package/dist/src/utils/liveFeatureSource.d.ts +6 -0
  108. package/dist/src/utils/measureClickFlag.d.cts +2 -0
  109. package/dist/src/utils/measureClickFlag.d.ts +2 -0
  110. package/dist/src/utils/modifierDragFlag.d.cts +2 -0
  111. package/dist/src/utils/modifierDragFlag.d.ts +2 -0
  112. package/dist/src/utils/rafThrottle.d.cts +11 -0
  113. package/dist/src/utils/rafThrottle.d.ts +11 -0
  114. package/dist/src/utils/snapping.d.cts +25 -0
  115. package/dist/src/utils/snapping.d.ts +25 -0
  116. package/dist/src/utils/toolCursor.d.cts +3 -0
  117. package/dist/src/utils/toolCursor.d.ts +3 -0
  118. package/dist/streets-Bakdn2nG.cjs +1 -0
  119. package/dist/streets-D0l2l7xn.js +13 -0
  120. package/dist/style-873tzaoH.cjs +1 -0
  121. package/dist/style-mSgM9UsZ.js +75 -0
  122. package/dist/terrain-CUJe0pn4.cjs +1 -0
  123. package/dist/terrain-CZOhjFPd.js +13 -0
  124. package/package.json +124 -3
@@ -0,0 +1,3792 @@
1
+ "use client";
2
+ import { jsx as X, jsxs as fe, Fragment as lt } from "react/jsx-runtime";
3
+ import { useContext as pt, createContext as Nt, useEffect as K, useState as le, useRef as $, useCallback as ve, useMemo as Bt, memo as ao, useLayoutEffect as uo, forwardRef as In, useImperativeHandle as fo } from "react";
4
+ import { canProcessShape as _t, warnOnce as Rn, DEFAULT_FEATURE_COLOR_ON_DARK as go, createClickRepeatGuard as yo, routingError as po, CLICK_TOOL_MODES as ho, CLICK_SLOP_PX as mo, makeCircleCoords as vo, makeRectCoords as xo, isMultiGeometry as ht, getPartCount as wo, getPartGeometry as At, placeBox as Fn, commitTopoMove as on, vertexEditPatch as So, commitTopoInsert as wt, commitTopoDelete as rn, rdp as bo, withXY as Ve, setPartGeometry as Lo, insertedPosition as sn, transformUpdates as Eo, getMercatorLatCorrectionRatio as Te, unproject as Ot, project as me, offsetGeometry as $t, applyVisualTransform as Po, toRadians as Ke, mapPositions as _n, vertexEditNotice as Co, fitPadding as jt, addPickedFeature as Mo, OSM_PICK_OVERLAY_COLORS as at, unionPieces as ko, tileCandidateResult as Io, OSM_PICK_MIN_ZOOM as Ro, overpassRadiusForZoom as Fo, tileCandidates as _o, normalizeFitBoundsTarget as Ao, visibleCenterOffset as cn, loadErrorCode as ln } from "@element-editor/core/internal";
5
+ import { useAccentPalette as To, useDataStore as he, useUIStore as W, useElementEditorConfig as ke, useGeoStore as Le, useEmit as Ue, useIsEventForEditor as zt, featureLabel as Do, ContextMenu as Ko, VertexSelectionBar as No, FeatureMapContextMenu as Bo, useAccentStyle as Oo, useTheme as An, runGeometryWorkerOperation as $o, MapControllerProvider as jo, EventProvider as zo, useAdapterControls as Ho, useKeyboardShortcuts as Vo, useApplyAccentToRoot as Xo, useReportThemeFromRoot as Yo, preloadEditorPanelsWhenIdle as Go, useSetMapController as Wo, BasemapPicker as Uo } from "@element-editor/ui";
6
+ import { ActiveDrawingToolbar as gi, EditingToolbar as yi, ElementEditorUIProvider as pi, FloatingToolbar as hi, GeoStoreProvider as mi, MapControllerProvider as vi, StoreContext as xi, useDataStore as wi, useGeoStore as Si, useKeyboardShortcuts as bi, useMapController as Li, useSetMapController as Ei, useUIStore as Pi } from "@element-editor/ui";
7
+ import { useOptionalEmit as Tn, useRouting as Zo, applyRootTokens as qo, useContextMenu as Jo } from "@element-editor/ui/internal";
8
+ import { readAccentPalette as Dn, DEFAULT_FEATURE_COLOR as Kn, fetchRoute as an, getGeometryBBox as Nn, formatLength as mt, formatArea as Ht, fetchOverpassFeatures as Qo, overpassErrorMessage as er, OverpassError as tr, readStorage as nr, writeStorage as or, ElementEditorError as Tt } from "@element-editor/core";
9
+ import { ElementEditorError as Mi } from "@element-editor/core";
10
+ import De from "maplibre-gl";
11
+ import { Crosshair as rr, Trash as sr } from "@phosphor-icons/react";
12
+ import { createPortal as Ze } from "react-dom";
13
+ import { transformRotate as ir } from "@turf/transform-rotate";
14
+ import { featureCollection as cr, lineString as We, polygon as ut } from "@turf/helpers";
15
+ import { bbox as Bn } from "@turf/bbox";
16
+ import lr from "@turf/boolean-intersects";
17
+ import { length as _e } from "@turf/length";
18
+ import { area as dt } from "@turf/area";
19
+ import { g as ar, r as ur } from "./basemapIds-CVTxeXkr.js";
20
+ import { distance as Pe } from "@turf/distance";
21
+ function Ie() {
22
+ return { type: "FeatureCollection", features: [] };
23
+ }
24
+ const dr = "elm-features", On = /* @__PURE__ */ new WeakMap();
25
+ function fr(e, t, n) {
26
+ On.set(e, { features: t, uniqueIds: n });
27
+ }
28
+ function Vt(e, t) {
29
+ const n = e.getSource(dr), o = On.get(e);
30
+ if (!(!n || !o || t.size === 0))
31
+ try {
32
+ if (o.uniqueIds) {
33
+ const i = [];
34
+ let l = !0;
35
+ for (const [u, c] of t)
36
+ if (c.type === "GeometryCollection") {
37
+ if (c.geometries.length !== 1) {
38
+ l = !1;
39
+ break;
40
+ }
41
+ i.push({ id: u, newGeometry: c.geometries[0] });
42
+ } else
43
+ i.push({ id: u, newGeometry: c });
44
+ if (l) {
45
+ n.updateData({ update: i });
46
+ return;
47
+ }
48
+ }
49
+ const r = /* @__PURE__ */ new Map(), s = o.features.map((i) => {
50
+ var c;
51
+ const l = (c = i.properties) == null ? void 0 : c.id, u = t.get(l);
52
+ if (!u) return i;
53
+ if (u.type === "GeometryCollection") {
54
+ const v = r.get(l) ?? 0;
55
+ r.set(l, v + 1);
56
+ const d = u.geometries[v];
57
+ return d ? { ...i, geometry: d } : i;
58
+ }
59
+ return { ...i, geometry: u };
60
+ });
61
+ n.setData({ type: "FeatureCollection", features: s });
62
+ } catch {
63
+ }
64
+ }
65
+ const $n = Nt(void 0);
66
+ function gr({
67
+ getFeatureStyle: e,
68
+ children: t
69
+ }) {
70
+ return /* @__PURE__ */ X($n.Provider, { value: e, children: t });
71
+ }
72
+ function yr() {
73
+ return pt($n);
74
+ }
75
+ function pr(e) {
76
+ let t, n, o;
77
+ const r = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());
78
+ if (r) {
79
+ const i = r[1].length === 3 ? r[1].replace(/./g, (l) => l + l) : r[1];
80
+ t = parseInt(i.slice(0, 2), 16), n = parseInt(i.slice(2, 4), 16), o = parseInt(i.slice(4, 6), 16);
81
+ } else {
82
+ const i = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i.exec(e.trim());
83
+ if (!i) return null;
84
+ t = +i[1], n = +i[2], o = +i[3];
85
+ }
86
+ const s = (i) => {
87
+ const l = i / 255;
88
+ return l <= 0.03928 ? l / 12.92 : ((l + 0.055) / 1.055) ** 2.4;
89
+ };
90
+ return 0.2126 * s(t) + 0.7152 * s(n) + 0.0722 * s(o);
91
+ }
92
+ function un(e) {
93
+ var t, n, o;
94
+ try {
95
+ const r = (n = (t = e.getStyle()) == null ? void 0 : t.layers) == null ? void 0 : n.find((l) => l.type === "background"), s = (o = r == null ? void 0 : r.paint) == null ? void 0 : o["background-color"];
96
+ if (typeof s != "string") return !1;
97
+ const i = pr(s);
98
+ return i !== null && i < 0.18;
99
+ } catch {
100
+ return !1;
101
+ }
102
+ }
103
+ const jn = Nt(0), vt = () => pt(jn);
104
+ function Ne(e, t, n = Dn(e.getContainer())) {
105
+ for (const [o, r, s] of t)
106
+ e.getLayer(o) && e.setPaintProperty(o, r, s(n));
107
+ }
108
+ function qe(e, t) {
109
+ const n = To(e.getContainer());
110
+ return K(() => {
111
+ Ne(e, t, n);
112
+ }, [e, t, n]), n;
113
+ }
114
+ const ge = "elm-features", Xt = "elm-features-line-hit", hr = 16, ft = ["boolean", ["feature-state", "hovered"], !1], mr = ["boolean", ["feature-state", "fresh"], !1], St = (e, t, n) => [
115
+ "case",
116
+ ["boolean", ["feature-state", "selected"], !1],
117
+ e,
118
+ ["coalesce", ...t, ["case", ft, n.hover, n.color]]
119
+ ], dn = [["get", "_fillColor"], ["get", "_color"]], vr = { color: Kn, hover: "#64748b", casing: "rgba(255, 255, 255, 0.7)" }, xr = { color: go, hover: "#cbd5e1", casing: "rgba(15, 23, 42, 0.5)" }, zn = (e) => [
120
+ ["elm-features-fill", "fill-color", (t) => St(t[500], dn, e)],
121
+ ["elm-features-line-casing", "line-color", () => e.casing],
122
+ ["elm-features-line", "line-color", (t) => St(t[500], [["get", "_color"]], e)],
123
+ // A fresh point: one accent step darker instead of a snap ring on it.
124
+ ["elm-features-point", "circle-color", (t) => ["case", mr, t[600], St(t[500], dn, e)]]
125
+ ], Hn = zn(vr), wr = zn(xr), Yt = ["in", ["geometry-type"], ["literal", ["LineString", "MultiLineString"]]], fn = ["coalesce", ["get", "_weight"], ["case", Yt, 3.5, 1.8]], gn = [
126
+ "case",
127
+ ["boolean", ["feature-state", "selected"], !1],
128
+ ["case", Yt, 4, 2.5],
129
+ ft,
130
+ ["+", fn, 0.7],
131
+ fn
132
+ ], Sr = 1.5;
133
+ function br(e) {
134
+ e.getSource(ge) || (e.addSource(ge, {
135
+ type: "geojson",
136
+ data: Ie(),
137
+ promoteId: "id"
138
+ // use each feature's `id` property as the MapLibre feature ID
139
+ }), e.addLayer({
140
+ id: "elm-features-fill",
141
+ type: "fill",
142
+ source: ge,
143
+ filter: ["in", ["geometry-type"], ["literal", ["Polygon", "MultiPolygon"]]],
144
+ paint: {
145
+ "fill-opacity": [
146
+ "case",
147
+ ["boolean", ["feature-state", "selected"], !1],
148
+ 0.28,
149
+ ft,
150
+ ["max", ["coalesce", ["get", "_fillOpacity"], 0.13], 0.22],
151
+ ["coalesce", ["get", "_fillOpacity"], 0.13]
152
+ ]
153
+ }
154
+ }), e.addLayer({
155
+ id: "elm-features-line-casing",
156
+ type: "line",
157
+ source: ge,
158
+ filter: Yt,
159
+ paint: {
160
+ "line-width": ["+", gn, 2 * Sr],
161
+ "line-opacity": ["coalesce", ["get", "_opacity"], 1]
162
+ }
163
+ }), e.addLayer({
164
+ id: "elm-features-line",
165
+ type: "line",
166
+ source: ge,
167
+ filter: [
168
+ "in",
169
+ ["geometry-type"],
170
+ ["literal", ["LineString", "MultiLineString", "Polygon", "MultiPolygon"]]
171
+ ],
172
+ paint: {
173
+ "line-width": gn,
174
+ "line-opacity": ["coalesce", ["get", "_opacity"], 1]
175
+ }
176
+ }), e.addLayer({
177
+ id: Xt,
178
+ type: "line",
179
+ source: ge,
180
+ filter: ["in", ["geometry-type"], ["literal", ["LineString", "MultiLineString"]]],
181
+ paint: { "line-width": hr, "line-color": "#000", "line-opacity": 0 }
182
+ }), e.addLayer({
183
+ id: "elm-features-point",
184
+ type: "circle",
185
+ source: ge,
186
+ filter: [
187
+ "all",
188
+ ["in", ["geometry-type"], ["literal", ["Point", "MultiPoint"]]],
189
+ ["!=", ["get", "_isText"], "true"]
190
+ ],
191
+ paint: {
192
+ "circle-radius": [
193
+ "case",
194
+ ["boolean", ["feature-state", "selected"], !1],
195
+ 10,
196
+ ft,
197
+ 9,
198
+ 8
199
+ ],
200
+ "circle-opacity": ["coalesce", ["get", "_fillOpacity"], 1],
201
+ "circle-stroke-width": 2,
202
+ "circle-stroke-color": "#ffffff"
203
+ }
204
+ }), e.getGlyphs() ? e.addLayer({
205
+ id: "elm-features-text",
206
+ type: "symbol",
207
+ source: ge,
208
+ filter: ["==", ["get", "_isText"], "true"],
209
+ layout: {
210
+ "text-field": ["get", "name"],
211
+ // OpenFreeMap's glyph server only has Noto Sans (Open Sans 404s), see basemaps/index.ts.
212
+ "text-font": ["Noto Sans Regular"],
213
+ "text-size": 14,
214
+ "text-allow-overlap": !0
215
+ },
216
+ paint: {
217
+ "text-color": "#ffffff",
218
+ "text-halo-color": Kn,
219
+ "text-halo-width": 2
220
+ }
221
+ }) : Rn("maplibre-no-glyphs", 'The map style has no `glyphs`, so Element can\'t show text features. Use a style with glyphs that serve "Noto Sans Regular".'), Ne(e, Hn));
222
+ }
223
+ function Lr(e) {
224
+ for (const t of ["elm-features-text", "elm-features-point", Xt, "elm-features-line", "elm-features-line-casing", "elm-features-fill"])
225
+ e.getLayer(t) && e.removeLayer(t);
226
+ e.getSource(ge) && e.removeSource(ge);
227
+ }
228
+ const Be = ["elm-features-fill", "elm-features-line", Xt, "elm-features-point"];
229
+ function Er({ map: e }) {
230
+ const t = he((A) => A.features), n = he((A) => A.groups), o = he((A) => A.selectedIds), r = W((A) => A.editingMode), s = W((A) => A.geometryPreview !== null), i = W((A) => A.bufferCreateNew), l = yr(), u = ke().featureColor, c = vt(), [v, d] = le(() => un(e));
231
+ K(() => {
232
+ const A = () => d(un(e));
233
+ return A(), e.on("styledata", A), () => {
234
+ e.off("styledata", A);
235
+ };
236
+ }, [e, c]);
237
+ const g = v ? wr : Hn, w = qe(e, g);
238
+ K(() => {
239
+ Ne(e, g, w);
240
+ }, [c]);
241
+ const P = Tn(), T = $(!1);
242
+ K(() => {
243
+ T.current || e.getGlyphs() || (T.current = !0, P == null || P({
244
+ type: "error",
245
+ code: "unsupported",
246
+ source: "basemap",
247
+ quiet: !0,
248
+ message: 'The map style has no glyphs, so text features are not shown. Use a style whose glyphs serve "Noto Sans Regular".'
249
+ }));
250
+ }, [e, c, P]);
251
+ const M = s && (r === "simplify-shape" || r === "smooth-shape" || r === "buffer-shape" && !i) ? o : null;
252
+ K(() => {
253
+ const A = e.getSource(ge);
254
+ if (!A) return;
255
+ const D = new Set(n.filter((C) => C.hidden).map((C) => C.id)), q = M ? new Set(M) : null, y = t.filter((C) => !(C.hidden || C.groupId && D.has(C.groupId) || q != null && q.has(C.id) && _t(C.geometry.type))), f = [];
256
+ let b = !0;
257
+ for (const C of y) {
258
+ const { _validation: R, ...I } = C, a = l == null ? void 0 : l(C), x = {}, p = (a == null ? void 0 : a.color) ?? u;
259
+ if (p !== void 0 && (x._color = p), a && (a.fillColor !== void 0 && (x._fillColor = a.fillColor), a.opacity !== void 0 && (x._opacity = a.opacity), a.fillOpacity !== void 0 && (x._fillOpacity = a.fillOpacity), a.weight !== void 0 && (x._weight = a.weight)), C.geometry.type === "GeometryCollection") {
260
+ C.geometry.geometries.length > 1 && (b = !1);
261
+ for (const m of C.geometry.geometries)
262
+ f.push({
263
+ ...I,
264
+ geometry: m,
265
+ properties: { ...I.properties, ...x, id: C.id }
266
+ });
267
+ } else
268
+ f.push({
269
+ ...I,
270
+ properties: { ...I.properties, ...x, id: C.id }
271
+ });
272
+ }
273
+ A.setData({ type: "FeatureCollection", features: f }), fr(e, f, b);
274
+ }, [t, n, e, M, l, u, c]);
275
+ const N = $(/* @__PURE__ */ new Set()), E = $(c);
276
+ return K(() => {
277
+ if (!e.getSource(ge)) return;
278
+ E.current !== c && (E.current = c, N.current = /* @__PURE__ */ new Set());
279
+ const A = N.current, D = new Set(o);
280
+ for (const q of A)
281
+ D.has(q) || e.setFeatureState({ source: ge, id: q }, { selected: !1 });
282
+ for (const q of D)
283
+ A.has(q) || e.setFeatureState({ source: ge, id: q }, { selected: !0 });
284
+ N.current = D;
285
+ }, [o, e, c]), null;
286
+ }
287
+ function bt(e, t, n) {
288
+ e.getSource(ge) && (n && e.setFeatureState({ source: ge, id: n }, { hovered: !1 }), t && e.setFeatureState({ source: ge, id: t }, { hovered: !0 }));
289
+ }
290
+ function Vn(e, t, n, o, r = 15, s = /* @__PURE__ */ new Set()) {
291
+ const i = n.project([e, t]), l = i.x, u = i.y;
292
+ let c = 1 / 0, v = null, d = null, g = 1 / 0, w = 0, P = 0, T = !1, _ = null;
293
+ const M = r + 1;
294
+ let N = 1 / 0, E = -1 / 0, A = 1 / 0, D = -1 / 0;
295
+ for (const [b, C] of [[l - M, u - M], [l + M, u - M], [l - M, u + M], [l + M, u + M]]) {
296
+ const R = n.unproject([b, C]);
297
+ R.lng < N && (N = R.lng), R.lng > E && (E = R.lng), R.lat < A && (A = R.lat), R.lat > D && (D = R.lat);
298
+ }
299
+ let q = "";
300
+ function y(b, C = !0) {
301
+ if (!b || b.length === 0) return;
302
+ let R = -1, I = 0, a = 0;
303
+ for (let x = 0; x < b.length; x++) {
304
+ const p = b[x];
305
+ if (!(p[0] < N || p[0] > E || p[1] < A || p[1] > D)) {
306
+ if (R !== x) {
307
+ const F = n.project(p);
308
+ I = F.x, a = F.y, R = x;
309
+ }
310
+ const m = Math.hypot(l - I, u - a);
311
+ m < c && (c = m, v = p, d = q);
312
+ }
313
+ if (C && x < b.length - 1) {
314
+ const m = b[x + 1];
315
+ if (p[0] < N && m[0] < N || p[0] > E && m[0] > E || p[1] < A && m[1] < A || p[1] > D && m[1] > D) continue;
316
+ if (R !== x) {
317
+ const k = n.project(p);
318
+ I = k.x, a = k.y;
319
+ }
320
+ const F = I, S = a, L = n.project(m);
321
+ R = x + 1, I = L.x, a = L.y;
322
+ const B = (F - L.x) ** 2 + (S - L.y) ** 2;
323
+ let V = F, j = S;
324
+ if (B !== 0) {
325
+ let k = ((l - F) * (L.x - F) + (u - S) * (L.y - S)) / B;
326
+ k = Math.max(0, Math.min(1, k)), V = F + k * (L.x - F), j = S + k * (L.y - S);
327
+ }
328
+ const h = Math.hypot(l - V, u - j);
329
+ h < g && (g = h, w = V, P = j, T = !0, _ = q);
330
+ }
331
+ }
332
+ }
333
+ function f(b) {
334
+ switch (b.type) {
335
+ case "Point":
336
+ y([b.coordinates]);
337
+ break;
338
+ case "MultiPoint":
339
+ y(b.coordinates, !1);
340
+ break;
341
+ case "LineString":
342
+ y(b.coordinates);
343
+ break;
344
+ case "Polygon":
345
+ case "MultiLineString":
346
+ for (const C of b.coordinates) y(C);
347
+ break;
348
+ case "MultiPolygon":
349
+ for (const C of b.coordinates)
350
+ for (const R of C) y(R);
351
+ break;
352
+ case "GeometryCollection":
353
+ for (const C of b.geometries) f(C);
354
+ break;
355
+ }
356
+ }
357
+ for (const b of o)
358
+ if (!s.has(b.id)) {
359
+ if (b.bbox) {
360
+ const [C, R, I, a] = b.bbox;
361
+ if (I < N || C > E || a < A || R > D) continue;
362
+ }
363
+ q = b.id, f(b.geometry);
364
+ }
365
+ if (c <= r && v)
366
+ return {
367
+ lnglat: v,
368
+ isVertex: !0,
369
+ featureId: d ?? void 0
370
+ };
371
+ if (g <= r && T) {
372
+ const b = n.unproject([w, P]);
373
+ return {
374
+ lnglat: [b.lng, b.lat],
375
+ isVertex: !1,
376
+ featureId: _ ?? void 0
377
+ };
378
+ }
379
+ return null;
380
+ }
381
+ function Dt(e, t, n, o = 15) {
382
+ const r = e.project(t), s = e.project(n), i = s.x - r.x, l = s.y - r.y, u = Math.hypot(i, l);
383
+ if (u < 1) return n;
384
+ const c = Math.atan2(l, i), v = o * Math.PI / 180, d = Math.round(c / v) * v, g = r.x + u * Math.cos(d), w = r.y + u * Math.sin(d), P = e.unproject([g, w]);
385
+ return [P.lng, P.lat];
386
+ }
387
+ let Kt = !1;
388
+ function Pr() {
389
+ Kt = !0, Promise.resolve().then(() => {
390
+ Kt = !1;
391
+ });
392
+ }
393
+ function Cr() {
394
+ return Kt;
395
+ }
396
+ let Xn = 0;
397
+ function Mr() {
398
+ Xn = Date.now();
399
+ }
400
+ function kr() {
401
+ return Date.now() - Xn < 200;
402
+ }
403
+ let Yn = 0;
404
+ function Lt() {
405
+ Yn = Date.now();
406
+ }
407
+ function Gn() {
408
+ return Date.now() - Yn < 200;
409
+ }
410
+ const Ge = (e) => e !== "none" ? "crosshair" : "", Ir = 3, yn = 5;
411
+ function Rr({ map: e, routingApiKey: t }) {
412
+ const { uiStore: n, dataStore: o } = Le(), r = Zo(t), s = ke().network.fetch, i = $(null);
413
+ i.current = r === !1 ? null : { ...r, fetch: s };
414
+ const l = Ue(), u = zt(), c = W((y) => y.editingMode), v = W((y) => y.cancelDrawing), d = W((y) => y.routeWaypoints), g = $(d);
415
+ K(() => {
416
+ g.current = d;
417
+ }, [d]);
418
+ const w = $(null), P = $(null), T = $(null), _ = $(!1), M = $(!1), N = $(!1), E = $(null), A = $(yo()).current, D = $(!1), q = ve(
419
+ async (y) => {
420
+ if (!(y.length < 2)) {
421
+ n.getState().setRoutePreview(null, !0);
422
+ try {
423
+ if (!i.current) throw new Error("routing is off");
424
+ const f = await an(y, i.current);
425
+ g.current.length >= 2 && n.getState().setRoutePreview(f, !1);
426
+ } catch (f) {
427
+ const b = po(f);
428
+ l({ type: "error", code: b.code, source: "routing", message: b.message, error: b }), n.getState().setRoutePreview(y, !1);
429
+ }
430
+ }
431
+ },
432
+ [n, l]
433
+ );
434
+ return K(() => {
435
+ const y = e.getCanvas();
436
+ function f() {
437
+ D.current || (D.current = !0, e.dragPan.enable(), y.style.cursor = "grab");
438
+ }
439
+ function b() {
440
+ if (!D.current) return;
441
+ D.current = !1;
442
+ const p = n.getState().editingMode;
443
+ y.style.cursor = Ge(p), (p === "draw-rect" || p === "draw-circle" || p === "draw-freehand") && e.dragPan.disable();
444
+ }
445
+ const C = (p) => {
446
+ if (p.key === "Shift" && (M.current = !0), !!u(p)) {
447
+ if (p.code === "Space") {
448
+ const m = p.target;
449
+ if (m && (m.tagName === "INPUT" || m.tagName === "TEXTAREA" || m.isContentEditable)) return;
450
+ p.preventDefault(), n.getState().editingMode !== "none" && f();
451
+ return;
452
+ }
453
+ if (p.key === "Escape") {
454
+ const { selectedMeasurementId: m, setSelectedMeasurementId: F } = n.getState();
455
+ if (m) {
456
+ F(null);
457
+ return;
458
+ }
459
+ v();
460
+ return;
461
+ }
462
+ if (p.key === "Enter") {
463
+ const m = n.getState();
464
+ if (m.editingMode === "measure") {
465
+ m.completeMeasure();
466
+ return;
467
+ }
468
+ }
469
+ if (p.key === "Backspace" || p.key === "Delete") {
470
+ const m = n.getState();
471
+ if (m.selectedMeasurementId) {
472
+ m.removeMeasurement(m.selectedMeasurementId);
473
+ return;
474
+ }
475
+ const F = m.editingMode;
476
+ if (F === "measure") {
477
+ m.removeLastMeasurePoint();
478
+ return;
479
+ }
480
+ if (F === "draw-line" || F === "slice-shape") {
481
+ m.removeLastLineVertex();
482
+ return;
483
+ }
484
+ if (F === "draw-polygon" || F === "cut-hole") {
485
+ m.removeLastPolygonVertex();
486
+ return;
487
+ }
488
+ if (F === "draw-route") {
489
+ m.removeLastRouteWaypoint();
490
+ return;
491
+ }
492
+ }
493
+ }
494
+ }, R = (p) => {
495
+ if (p.code === "Space") {
496
+ b();
497
+ return;
498
+ }
499
+ p.key === "Shift" && (M.current = !1);
500
+ }, I = () => b(), a = () => {
501
+ y.style.cursor = "grabbing";
502
+ }, x = () => {
503
+ y.style.cursor = D.current ? "grab" : Ge(n.getState().editingMode);
504
+ };
505
+ return window.addEventListener("keydown", C), window.addEventListener("keyup", R), window.addEventListener("blur", I), e.on("dragstart", a), e.on("dragend", x), () => {
506
+ window.removeEventListener("keydown", C), window.removeEventListener("keyup", R), window.removeEventListener("blur", I), e.off("dragstart", a), e.off("dragend", x);
507
+ };
508
+ }, [v, n, e, u]), K(() => {
509
+ e.getCanvas().style.cursor = Ge(c);
510
+ }, [c, e]), K(() => {
511
+ c === "draw-freehand" ? e.dragPan.disable() : (e.dragPan.enable(), _.current = !1);
512
+ }, [c, e]), K(() => (c !== "none" ? e.doubleClickZoom.disable() : e.doubleClickZoom.enable(), () => {
513
+ e.doubleClickZoom.enable();
514
+ }), [c, e]), K(() => {
515
+ var C;
516
+ if (!ho.includes(c)) return;
517
+ const y = (C = e.handlers) == null ? void 0 : C._handlersById, f = [y == null ? void 0 : y.mapEvent, y == null ? void 0 : y.mousePan].filter((R) => typeof (R == null ? void 0 : R._clickTolerance) == "number"), b = f.map((R) => R._clickTolerance);
518
+ for (const R of f) R._clickTolerance = mo;
519
+ return () => f.forEach((R, I) => {
520
+ R._clickTolerance = b[I];
521
+ });
522
+ }, [c, e]), K(() => (c !== "none" ? e.boxZoom.disable() : e.boxZoom.enable(), () => {
523
+ e.boxZoom.enable();
524
+ }), [c, e]), K(() => () => {
525
+ P.current && clearTimeout(P.current), T.current && T.current.abort();
526
+ }, []), K(() => {
527
+ const y = (a) => a.metaKey || a.ctrlKey || a.altKey, f = (a) => {
528
+ if (!y(a.originalEvent) && !D.current) {
529
+ if (c === "draw-freehand") {
530
+ _.current = !0, n.getState().clearFreehandPoints(), n.getState().addFreehandPoint([a.lngLat.lng, a.lngLat.lat]);
531
+ return;
532
+ }
533
+ if (c === "draw-rect") {
534
+ e.dragPan.disable(), o.getState().selectedIds.length > 0 && o.setState({ selectedIds: [] });
535
+ const x = n.getState().snappedCoord ?? [a.lngLat.lng, a.lngLat.lat];
536
+ n.getState().setRectCorner(x), N.current = !0, E.current = { x: a.point.x, y: a.point.y };
537
+ return;
538
+ }
539
+ if (c === "draw-circle") {
540
+ e.dragPan.disable(), o.getState().selectedIds.length > 0 && o.setState({ selectedIds: [] });
541
+ const x = n.getState().snappedCoord ?? [a.lngLat.lng, a.lngLat.lat];
542
+ n.getState().setCircleCenter(x), N.current = !0, E.current = { x: a.point.x, y: a.point.y };
543
+ return;
544
+ }
545
+ }
546
+ }, b = (a) => {
547
+ if (c === "draw-freehand" && _.current) {
548
+ _.current = !1;
549
+ const F = e.getZoom(), S = 156543.03392 * Math.cos(a.lngLat.lat * Math.PI / 180) / Math.pow(2, F), L = Ir * S / 111320;
550
+ n.getState().commitFreehand(L), Lt();
551
+ return;
552
+ }
553
+ if (!N.current) return;
554
+ N.current = !1, e.dragPan.enable();
555
+ const x = E.current, p = x ? Math.hypot(a.point.x - x.x, a.point.y - x.y) : 0;
556
+ E.current = null;
557
+ const m = n.getState();
558
+ if (c === "draw-rect") {
559
+ const F = m.rectCorner;
560
+ if (!F) return;
561
+ if (p < yn) {
562
+ n.setState({ rectCorner: null });
563
+ return;
564
+ }
565
+ const S = m.snappedCoord ?? [a.lngLat.lng, a.lngLat.lat], L = M.current || a.originalEvent.shiftKey;
566
+ m.commitRect(F, S, {}, L), Lt();
567
+ return;
568
+ }
569
+ if (c === "draw-circle") {
570
+ const F = m.circleCenter;
571
+ if (!F) return;
572
+ let S;
573
+ if (p < yn) {
574
+ const V = e.unproject([a.point.x + 25, a.point.y]);
575
+ S = [V.lng, V.lat];
576
+ } else
577
+ S = m.snappedCoord ?? [a.lngLat.lng, a.lngLat.lat];
578
+ const L = S[0] - F[0], B = S[1] - F[1];
579
+ Math.hypot(L, B) >= 1e-6 && (m.commitCircle(F, S, {}), Lt());
580
+ return;
581
+ }
582
+ }, C = (a) => {
583
+ const x = n.getState();
584
+ if (c === "draw-freehand" && _.current) {
585
+ x.addFreehandPoint([a.lngLat.lng, a.lngLat.lat]);
586
+ return;
587
+ }
588
+ if (c === "draw-route" && g.current.length > 0) {
589
+ const p = [a.lngLat.lng, a.lngLat.lat];
590
+ x.setRouteCursorPos(p), x.setRouteCursorPreview(null), P.current && clearTimeout(P.current), T.current && T.current.abort();
591
+ const m = g.current[g.current.length - 1];
592
+ P.current = setTimeout(async () => {
593
+ const F = new AbortController();
594
+ T.current = F;
595
+ try {
596
+ if (!i.current) return;
597
+ const S = await an([m, p], { ...i.current, signal: F.signal });
598
+ F.signal.aborted || n.getState().setRouteCursorPreview(S);
599
+ } catch {
600
+ }
601
+ }, 400);
602
+ }
603
+ if ((c === "draw-polygon" || c === "cut-hole") && x.polygonInProgress.length >= 3) {
604
+ const p = x.polygonInProgress[0], m = e.project(p), F = Math.hypot(a.point.x - m.x, a.point.y - m.y);
605
+ e.getCanvas().style.cursor = F <= 48 ? "pointer" : "crosshair";
606
+ }
607
+ }, R = (a) => {
608
+ const x = A.click(a.originalEvent);
609
+ if (y(a.originalEvent) || kr() || D.current || Gn()) return;
610
+ const p = n.getState();
611
+ if (c === "measure") {
612
+ if (x || Cr()) return;
613
+ p.selectedMeasurementId && p.setSelectedMeasurementId(null);
614
+ const S = p.snappedCoord ?? [a.lngLat.lng, a.lngLat.lat];
615
+ p.addMeasurePoint(S);
616
+ return;
617
+ }
618
+ ["place-point", "draw-line", "draw-polygon", "draw-route", "draw-circle", "draw-rect"].includes(c) && o.getState().selectedIds.length > 0 && o.setState({ selectedIds: [] });
619
+ const F = p.snappedCoord ?? [a.lngLat.lng, a.lngLat.lat];
620
+ if (c === "place-point") {
621
+ if (x) return;
622
+ p.commitPoint(F);
623
+ return;
624
+ }
625
+ if (c === "draw-line" || c === "draw-polygon" || c === "draw-route" || c === "cut-hole" || c === "slice-shape") {
626
+ let S = F;
627
+ if (M.current || a.originalEvent.shiftKey) {
628
+ const L = c === "draw-line" || c === "slice-shape" ? p.lineInProgress : p.polygonInProgress;
629
+ L.length >= 1 && (S = Dt(e, L[L.length - 1], S));
630
+ }
631
+ if ((c === "draw-polygon" || c === "cut-hole") && p.polygonInProgress.length >= 2) {
632
+ const L = p.polygonInProgress[0], B = e.project(L);
633
+ if (Math.hypot(a.point.x - B.x, a.point.y - B.y) <= 48) {
634
+ c === "draw-polygon" ? p.commitPolygon({}) : p.commitCutHole();
635
+ return;
636
+ }
637
+ }
638
+ if (x) return;
639
+ if (c === "draw-line" || c === "slice-shape") p.addLineVertex(S);
640
+ else if (c === "draw-polygon" || c === "cut-hole") p.addPolygonVertex(S);
641
+ else if (c === "draw-route") {
642
+ w.current = { waypoints: [...g.current], preview: p.routePreview }, P.current && (clearTimeout(P.current), P.current = null), T.current && (T.current.abort(), T.current = null), p.setRouteCursorPos(null), p.setRouteCursorPreview(null), p.addRouteWaypoint(S);
643
+ const L = [...g.current, S];
644
+ q(L);
645
+ }
646
+ return;
647
+ }
648
+ }, I = () => {
649
+ if (!A.isDouble()) return;
650
+ const a = n.getState();
651
+ if (c === "measure") {
652
+ a.completeMeasure();
653
+ return;
654
+ }
655
+ c === "draw-line" ? a.commitLine({}) : c === "draw-polygon" ? a.commitPolygon({}) : c === "cut-hole" ? a.commitCutHole() : c === "slice-shape" ? a.commitSliceShape() : c === "draw-route" && (w.current && (n.setState({
656
+ routeWaypoints: w.current.waypoints,
657
+ routePreview: w.current.preview,
658
+ routeLoading: !1
659
+ }), w.current = null), a.commitRoute());
660
+ };
661
+ return e.on("mousedown", f), e.on("mouseup", b), e.on("mousemove", C), e.on("click", R), e.on("dblclick", I), () => {
662
+ e.off("mousedown", f), e.off("mouseup", b), e.off("mousemove", C), e.off("click", R), e.off("dblclick", I);
663
+ };
664
+ }, [c, e, q, n, o]), null;
665
+ }
666
+ function pn(e) {
667
+ var t, n;
668
+ return `${e.editingMode}|${e.lineInProgress.length}|${e.polygonInProgress.length}|${e.circleCenter}|${e.rectCorner}|${e.routeWaypoints.length}|${((t = e.routePreview) == null ? void 0 : t.length) ?? 0}|${((n = e.routeCursorPreview) == null ? void 0 : n.length) ?? 0}|${e.freehandPoints.length}`;
669
+ }
670
+ const Se = "elm-preview", Wn = [
671
+ ["elm-preview-fill", "fill-color", (e) => e[500]],
672
+ ["elm-preview-line", "line-color", (e) => e[500]],
673
+ ["elm-preview-vertex", "circle-color", (e) => e[500]]
674
+ ];
675
+ function Fr(e) {
676
+ e.getSource(Se) || (e.addSource(Se, { type: "geojson", data: Ie() }), e.addLayer({
677
+ id: "elm-preview-fill",
678
+ type: "fill",
679
+ source: Se,
680
+ filter: ["==", ["geometry-type"], "Polygon"],
681
+ paint: { "fill-opacity": 0.13 }
682
+ }), e.addLayer({
683
+ id: "elm-preview-line",
684
+ type: "line",
685
+ source: Se,
686
+ filter: ["in", ["geometry-type"], ["literal", ["LineString", "Polygon"]]],
687
+ paint: { "line-width": 2, "line-dasharray": [4, 3] }
688
+ }), e.addLayer({
689
+ id: "elm-preview-vertex",
690
+ type: "circle",
691
+ source: Se,
692
+ filter: ["all", ["==", ["geometry-type"], "Point"], ["!=", ["get", "_isFirst"], !0]],
693
+ paint: {
694
+ "circle-radius": 5,
695
+ "circle-stroke-width": 2,
696
+ "circle-stroke-color": "#ffffff"
697
+ }
698
+ }), e.addLayer({
699
+ id: "elm-preview-first-vertex",
700
+ type: "circle",
701
+ source: Se,
702
+ filter: ["==", ["get", "_isFirst"], !0],
703
+ paint: {
704
+ "circle-radius": 7,
705
+ "circle-color": "#22c55e",
706
+ "circle-stroke-width": 2,
707
+ "circle-stroke-color": "#ffffff"
708
+ }
709
+ }), Ne(e, Wn));
710
+ }
711
+ function _r(e) {
712
+ for (const t of ["elm-preview-first-vertex", "elm-preview-vertex", "elm-preview-line", "elm-preview-fill"])
713
+ e.getLayer(t) && e.removeLayer(t);
714
+ e.getSource(Se) && e.removeSource(Se);
715
+ }
716
+ function Fe(e, t) {
717
+ const n = e.getSource(Se);
718
+ n && n.setData({ type: "FeatureCollection", features: t });
719
+ }
720
+ function Ar({ map: e }) {
721
+ qe(e, Wn);
722
+ const { uiStore: t, dataStore: n } = Le(), o = W((c) => c.editingMode), r = he((c) => c.geometryMode), s = $(r);
723
+ K(() => {
724
+ s.current = r;
725
+ }, [r]);
726
+ const i = $(null), l = $(!1);
727
+ K(() => {
728
+ const c = (g) => {
729
+ i.current = [g.lngLat.lng, g.lngLat.lat], u();
730
+ }, v = (g) => {
731
+ g.key === "Shift" && (l.current = !0);
732
+ }, d = (g) => {
733
+ g.key === "Shift" && (l.current = !1);
734
+ };
735
+ return e.on("mousemove", c), window.addEventListener("keydown", v), window.addEventListener("keyup", d), () => {
736
+ e.off("mousemove", c), window.removeEventListener("keydown", v), window.removeEventListener("keyup", d);
737
+ };
738
+ }, [e]), K(() => {
739
+ let c = pn(t.getState());
740
+ return t.subscribe((d) => {
741
+ const g = pn(d);
742
+ g !== c && (c = g, u());
743
+ });
744
+ }, [t]), K(() => {
745
+ i.current = null, o === "none" && Fe(e, []);
746
+ }, [o, e]);
747
+ function u() {
748
+ const c = t.getState(), v = i.current, d = [];
749
+ if (c.editingMode === "draw-line" || c.editingMode === "slice-shape") {
750
+ const g = c.lineInProgress;
751
+ if (g.length === 0) return Fe(e, []);
752
+ let w = v ?? g[g.length - 1];
753
+ l.current && g.length >= 1 && (w = Dt(e, g[g.length - 1], w));
754
+ const P = [...g, w];
755
+ d.push({ type: "Feature", properties: {}, geometry: { type: "LineString", coordinates: P } }), g.forEach((T, _) => {
756
+ d.push({ type: "Feature", properties: { _isFirst: _ === 0 }, geometry: { type: "Point", coordinates: T } });
757
+ });
758
+ }
759
+ if (c.editingMode === "draw-polygon" || c.editingMode === "cut-hole") {
760
+ const g = c.polygonInProgress;
761
+ if (g.length === 0) return Fe(e, []);
762
+ let w = v ?? g[g.length - 1];
763
+ l.current && g.length >= 1 && (w = Dt(e, g[g.length - 1], w));
764
+ const P = [...g, w, g[0]];
765
+ g.length >= 2 ? d.push({ type: "Feature", properties: {}, geometry: { type: "Polygon", coordinates: [P] } }) : d.push({ type: "Feature", properties: {}, geometry: { type: "LineString", coordinates: P } }), g.forEach((T, _) => {
766
+ d.push({ type: "Feature", properties: { _isFirst: _ === 0 }, geometry: { type: "Point", coordinates: T } });
767
+ });
768
+ }
769
+ if (c.editingMode === "draw-circle") {
770
+ const g = c.circleCenter;
771
+ if (!g) return Fe(e, []);
772
+ const w = v ?? g, P = vo(g, w, s.current, 64);
773
+ d.push({ type: "Feature", properties: {}, geometry: { type: "Polygon", coordinates: [P] } }), d.push({ type: "Feature", properties: { _isFirst: !0 }, geometry: { type: "Point", coordinates: g } }), d.push({ type: "Feature", properties: {}, geometry: { type: "Point", coordinates: w } });
774
+ }
775
+ if (c.editingMode === "draw-rect") {
776
+ const g = c.rectCorner;
777
+ if (!g) return Fe(e, []);
778
+ const P = xo(g, v ?? g, s.current, l.current);
779
+ d.push({ type: "Feature", properties: {}, geometry: { type: "Polygon", coordinates: [P] } });
780
+ }
781
+ if (c.editingMode === "draw-route") {
782
+ const g = c.routeWaypoints;
783
+ if (g.length === 0) return Fe(e, []);
784
+ const w = c.routePreview ?? g;
785
+ w.length >= 2 && d.push({ type: "Feature", properties: {}, geometry: { type: "LineString", coordinates: w } });
786
+ const P = c.routeCursorPreview ?? (v ? [g[g.length - 1], v] : null);
787
+ P && P.length >= 2 && d.push({ type: "Feature", properties: {}, geometry: { type: "LineString", coordinates: P } }), g.forEach((T, _) => {
788
+ d.push({ type: "Feature", properties: { _isFirst: _ === 0 }, geometry: { type: "Point", coordinates: T } });
789
+ });
790
+ }
791
+ if (c.editingMode === "draw-freehand") {
792
+ const g = c.freehandPoints;
793
+ g.length >= 2 && d.push({ type: "Feature", properties: {}, geometry: { type: "LineString", coordinates: g } });
794
+ }
795
+ Fe(e, d);
796
+ }
797
+ return null;
798
+ }
799
+ function hn(e, t) {
800
+ const [n, o] = e;
801
+ let r = !1;
802
+ for (let s = 0, i = t.length - 1; s < t.length; i = s++) {
803
+ const [l, u] = t[s], [c, v] = t[i];
804
+ u > o != v > o && n < (c - l) * (o - u) / (v - u + 1e-20) + l && (r = !r);
805
+ }
806
+ return r;
807
+ }
808
+ function mn(e, t) {
809
+ if (t.length === 0 || !hn(e, t[0])) return !1;
810
+ for (let n = 1; n < t.length; n++)
811
+ if (hn(e, t[n])) return !1;
812
+ return !0;
813
+ }
814
+ function Tr(e, t, n) {
815
+ const o = n[0] - t[0], r = n[1] - t[1];
816
+ if (o === 0 && r === 0) {
817
+ const v = e[0] - t[0], d = e[1] - t[1];
818
+ return v * v + d * d;
819
+ }
820
+ const s = Math.max(0, Math.min(1, ((e[0] - t[0]) * o + (e[1] - t[1]) * r) / (o * o + r * r))), i = t[0] + s * o, l = t[1] + s * r, u = e[0] - i, c = e[1] - l;
821
+ return u * u + c * c;
822
+ }
823
+ function tt(e, t) {
824
+ let n = 1 / 0;
825
+ for (let o = 0; o < t.length - 1; o++) {
826
+ const r = Tr(e, t[o], t[o + 1]);
827
+ r < n && (n = r);
828
+ }
829
+ return n;
830
+ }
831
+ function Dr(e, t) {
832
+ if (!ht(e)) return null;
833
+ const n = wo(e);
834
+ if (n === 0) return null;
835
+ if (e.type === "MultiPolygon") {
836
+ for (let s = 0; s < n; s++)
837
+ if (mn(t, e.coordinates[s]))
838
+ return s;
839
+ let o = 0, r = 1 / 0;
840
+ for (let s = 0; s < n; s++) {
841
+ const i = tt(t, e.coordinates[s][0]);
842
+ i < r && (r = i, o = s);
843
+ }
844
+ return o;
845
+ }
846
+ if (e.type === "MultiLineString") {
847
+ let o = 0, r = 1 / 0;
848
+ const s = e.coordinates;
849
+ for (let i = 0; i < n; i++) {
850
+ const l = tt(t, s[i]);
851
+ l < r && (r = l, o = i);
852
+ }
853
+ return o;
854
+ }
855
+ if (e.type === "MultiPoint") {
856
+ let o = 0, r = 1 / 0;
857
+ const s = e.coordinates;
858
+ for (let i = 0; i < n; i++) {
859
+ const l = t[0] - s[i][0], u = t[1] - s[i][1], c = l * l + u * u;
860
+ c < r && (r = c, o = i);
861
+ }
862
+ return o;
863
+ }
864
+ if (e.type === "GeometryCollection") {
865
+ for (let s = 0; s < n; s++) {
866
+ const i = At(e, s);
867
+ if (i.type === "Polygon" && mn(t, i.coordinates))
868
+ return s;
869
+ }
870
+ let o = 0, r = 1 / 0;
871
+ for (let s = 0; s < n; s++) {
872
+ const i = At(e, s);
873
+ let l = 1 / 0;
874
+ if (i.type === "Point") {
875
+ const u = t[0] - i.coordinates[0], c = t[1] - i.coordinates[1];
876
+ l = u * u + c * c;
877
+ } else i.type === "LineString" ? l = tt(t, i.coordinates) : i.type === "Polygon" && (l = tt(t, i.coordinates[0]));
878
+ l < r && (r = l, o = s);
879
+ }
880
+ return o;
881
+ }
882
+ return null;
883
+ }
884
+ function Un({ map: e, coords: t, onSave: n, onClose: o }) {
885
+ const r = Ue(), [s, i] = le(t[0].toFixed(6)), [l, u] = le(t[1].toFixed(6)), [c, v] = le(() => {
886
+ const w = e.project(t);
887
+ return { x: w.x, y: w.y };
888
+ }), d = $(null);
889
+ K(() => {
890
+ const w = () => {
891
+ const P = e.project(t);
892
+ v({ x: P.x, y: P.y });
893
+ };
894
+ return e.on("move", w), e.on("zoom", w), e.on("resize", w), () => {
895
+ e.off("move", w), e.off("zoom", w), e.off("resize", w);
896
+ };
897
+ }, [e, t]), K(() => {
898
+ var w, P;
899
+ (w = d.current) == null || w.focus(), (P = d.current) == null || P.select();
900
+ }, []);
901
+ function g() {
902
+ const w = parseFloat(s), P = parseFloat(l);
903
+ if (isNaN(w) || isNaN(P)) {
904
+ r({ type: "warning", message: "Invalid coordinates" });
905
+ return;
906
+ }
907
+ n([w, P]), r({ type: "success", message: "Coordinate updated" }), o();
908
+ }
909
+ return Ze(
910
+ /* @__PURE__ */ X(
911
+ "div",
912
+ {
913
+ "data-elm-theme": !0,
914
+ style: {
915
+ position: "absolute",
916
+ left: c.x,
917
+ top: c.y - 16,
918
+ transform: "translate(-50%, -100%)",
919
+ zIndex: 500,
920
+ pointerEvents: "auto"
921
+ },
922
+ onMouseDown: (w) => w.stopPropagation(),
923
+ onDoubleClick: (w) => w.stopPropagation(),
924
+ onContextMenu: (w) => w.stopPropagation(),
925
+ children: /* @__PURE__ */ fe(
926
+ "div",
927
+ {
928
+ className: "flex flex-col gap-2 min-w-[160px] bg-(--elm-surface,var(--color-white))/95 backdrop-blur-md border border-(--elm-border-strong,var(--color-slate-300)) rounded-elm-control shadow-elm-control p-2 text-(--elm-text,var(--color-slate-800))",
929
+ onKeyDown: (w) => {
930
+ w.key === "Enter" ? g() : w.key === "Escape" && o();
931
+ },
932
+ children: [
933
+ /* @__PURE__ */ X("p", { className: "text-xs font-semibold m-0 leading-none", children: "Precise coordinates" }),
934
+ /* @__PURE__ */ fe("label", { className: "flex items-center gap-2 text-xs text-(--elm-text-muted,var(--color-slate-500))", children: [
935
+ "Lat:",
936
+ /* @__PURE__ */ X(
937
+ "input",
938
+ {
939
+ ref: d,
940
+ type: "text",
941
+ inputMode: "decimal",
942
+ value: l,
943
+ onChange: (w) => u(w.target.value),
944
+ className: "flex-1 w-full min-w-0 border border-(--elm-border,var(--color-slate-200)) rounded-elm-chip px-1.5 py-0.5 text-xs outline-none focus:border-primary-400"
945
+ }
946
+ )
947
+ ] }),
948
+ /* @__PURE__ */ fe("label", { className: "flex items-center gap-2 text-xs text-(--elm-text-muted,var(--color-slate-500))", children: [
949
+ "Lng:",
950
+ /* @__PURE__ */ X(
951
+ "input",
952
+ {
953
+ type: "text",
954
+ inputMode: "decimal",
955
+ value: s,
956
+ onChange: (w) => i(w.target.value),
957
+ className: "flex-1 w-full min-w-0 border border-(--elm-border,var(--color-slate-200)) rounded-elm-chip px-1.5 py-0.5 text-xs outline-none focus:border-primary-400"
958
+ }
959
+ )
960
+ ] }),
961
+ /* @__PURE__ */ fe("div", { className: "flex items-center justify-end gap-1 mt-1", children: [
962
+ /* @__PURE__ */ X(
963
+ "button",
964
+ {
965
+ type: "button",
966
+ onClick: o,
967
+ className: "px-2 py-1 text-xs text-(--elm-text-muted,var(--color-slate-500)) hover:bg-(--elm-surface-hover,var(--color-slate-100)) rounded-elm-chip transition-colors",
968
+ children: "Cancel"
969
+ }
970
+ ),
971
+ /* @__PURE__ */ X(
972
+ "button",
973
+ {
974
+ type: "button",
975
+ onClick: g,
976
+ className: "px-2 py-1 text-xs text-white bg-primary-500 hover:bg-primary-600 rounded-elm-chip transition-colors font-medium",
977
+ children: "Save"
978
+ }
979
+ )
980
+ ] })
981
+ ]
982
+ }
983
+ )
984
+ }
985
+ ),
986
+ e.getCanvasContainer()
987
+ );
988
+ }
989
+ const Et = "elm-features";
990
+ let Xe = null;
991
+ const Gt = () => Xe;
992
+ function Pt(e, t) {
993
+ Xe !== t && (e.getSource(Et) && (Xe && e.setFeatureState({ source: Et, id: Xe }, { fresh: !1 }), t && e.setFeatureState({ source: Et, id: t }, { fresh: !0 })), Xe = t);
994
+ }
995
+ let ae = null, Wt = !1, Ut = null, Zt = 0, qt = 0;
996
+ function Jt(e) {
997
+ return e.ctrlKey || e.metaKey || e.altKey;
998
+ }
999
+ function Zn(e) {
1000
+ Jt(e) && ae && (ae.style.display = "none");
1001
+ }
1002
+ function qn(e) {
1003
+ Jt(e) || Wt || Ut && ae && ae.textContent && (ae.style.display = "", gt(Zt, qt));
1004
+ }
1005
+ function Jn(e) {
1006
+ if (!ae) return;
1007
+ gt(e.clientX, e.clientY);
1008
+ const t = e.target;
1009
+ !!(t != null && t.closest(".maplibregl-canvas-container, .maplibregl-canvas")) || (ae.style.display = "none");
1010
+ }
1011
+ function gt(e, t) {
1012
+ if (Zt = e, qt = t, !ae || ae.style.display === "none") return;
1013
+ const { left: n, top: o } = Fn(e, t, ae.offsetWidth, ae.offsetHeight, { x: "center", y: "before", gapY: 12 });
1014
+ ae.style.left = n + "px", ae.style.top = o + "px";
1015
+ }
1016
+ function Kr() {
1017
+ return ae || (ae = document.createElement("div"), ae.className = "elm-feature-tooltip", ae.style.cssText = "position:fixed;pointer-events:none;z-index:10000;display:none", document.body.appendChild(ae), window.addEventListener("keydown", Zn), window.addEventListener("keyup", qn), document.addEventListener("mousemove", Jn, { passive: !0 })), ae;
1018
+ }
1019
+ function Nr(e, t, n) {
1020
+ var i, l;
1021
+ if (Wt) return;
1022
+ const o = t.getState();
1023
+ if (!o.showFeatureNameOnHover || o.vertexEditActive || Gt() === e.id) {
1024
+ ct();
1025
+ return;
1026
+ }
1027
+ const r = Do(e);
1028
+ if (!r) return;
1029
+ const s = Kr();
1030
+ s.textContent = r, qo(s, (l = (i = n == null ? void 0 : n.target) == null ? void 0 : i.closest) == null ? void 0 : l.call(i, "[data-elm-theme]")), Ut = e.id, n && gt(n.clientX, n.clientY), n && Jt(n) ? s.style.display = "none" : (s.style.display = "", gt(Zt, qt));
1031
+ }
1032
+ function ct() {
1033
+ Ut = null, ae && (ae.remove(), ae = null, window.removeEventListener("keydown", Zn), window.removeEventListener("keyup", qn), document.removeEventListener("mousemove", Jn));
1034
+ }
1035
+ function Ce(e) {
1036
+ Wt = e, e && ae && (ae.style.display = "none");
1037
+ }
1038
+ function ze(e) {
1039
+ let t = 0, n = null;
1040
+ const o = () => {
1041
+ t = 0;
1042
+ const r = n;
1043
+ n = null, r && e(...r);
1044
+ };
1045
+ return {
1046
+ schedule(...r) {
1047
+ n = r, t || (t = requestAnimationFrame(o));
1048
+ },
1049
+ flush() {
1050
+ t && cancelAnimationFrame(t), o();
1051
+ },
1052
+ cancel() {
1053
+ t && cancelAnimationFrame(t), t = 0, n = null;
1054
+ }
1055
+ };
1056
+ }
1057
+ function Oe(e, t) {
1058
+ return ht(e) ? t == null ? null : At(e, t) : e;
1059
+ }
1060
+ function nt(e, t, n) {
1061
+ return ht(e) && t != null ? Lo(e, t, n) : n;
1062
+ }
1063
+ function ot(e) {
1064
+ return e.type === "Point" ? [[e.coordinates]] : e.type === "MultiPoint" ? [e.coordinates] : e.type === "LineString" ? [e.coordinates] : e.type === "Polygon" ? e.coordinates : [];
1065
+ }
1066
+ function Ct(e, t) {
1067
+ e.style.background = t ? "var(--color-primary-500)" : "#ffffff", e.style.borderColor = t ? "var(--color-primary-700)" : "var(--color-primary-500)", e.dataset.elmSelected = t ? "1" : "0";
1068
+ }
1069
+ let vn = !1;
1070
+ function Br() {
1071
+ if (vn) return;
1072
+ const e = document.createElement("style");
1073
+ e.textContent = ".elm-midpoint-marker{pointer-events:auto!important}", document.head.appendChild(e), vn = !0;
1074
+ }
1075
+ function xn(e, t = !1) {
1076
+ if (t) {
1077
+ const o = document.createElement("div");
1078
+ o.classList.add("elm-midpoint-marker"), o.style.cssText = "width:24px;height:24px;display:flex;align-items:center;justify-content:center;cursor:pointer;background:rgba(0,0,0,0.001)";
1079
+ const r = document.createElement("div");
1080
+ return r.style.cssText = [
1081
+ "width:12px",
1082
+ "height:12px",
1083
+ "background:#ffffff",
1084
+ "border:2px solid var(--color-primary-500)",
1085
+ "box-shadow:0 1px 3px rgba(0,0,0,0.35)",
1086
+ "transform:rotate(45deg)",
1087
+ "border-radius:3px",
1088
+ "transition:all 0.1s"
1089
+ ].join(";"), o.appendChild(r), o.addEventListener("mouseenter", () => {
1090
+ r.style.background = "var(--color-primary-100)";
1091
+ }), o.addEventListener("mouseleave", () => {
1092
+ r.style.background = "#ffffff";
1093
+ }), o;
1094
+ }
1095
+ const n = document.createElement("div");
1096
+ return n.classList.add("elm-vertex"), n.style.cssText = [
1097
+ "width:12px",
1098
+ "height:12px",
1099
+ `background:${e ? "var(--color-primary-500)" : "#ffffff"}`,
1100
+ `border:2px solid ${e ? "var(--color-primary-700)" : "var(--color-primary-500)"}`,
1101
+ "border-radius:3px",
1102
+ "cursor:pointer",
1103
+ "box-shadow:0 1px 3px rgba(0,0,0,0.35)",
1104
+ "transition:background 0.15s"
1105
+ ].join(";"), n.dataset.elmSelected = e ? "1" : "0", n.addEventListener("mouseenter", () => {
1106
+ n.style.background = "var(--color-primary-100)";
1107
+ }), n.addEventListener("mouseleave", () => {
1108
+ n.style.background = n.dataset.elmSelected === "1" ? "var(--color-primary-500)" : "#ffffff";
1109
+ }), n;
1110
+ }
1111
+ const rt = 500, wn = 15;
1112
+ function Sn(e, t, n) {
1113
+ const o = t.map((d, g) => g);
1114
+ if (t.length <= rt) return { indices: o, capped: !1 };
1115
+ const r = e.getBounds(), s = o.filter((d) => r.contains(t[d]));
1116
+ if (s.length <= rt) return { indices: s, capped: !0 };
1117
+ const i = [0];
1118
+ let l = e.project(t[s[0]]);
1119
+ for (let d = 1; d < s.length; d++) {
1120
+ const g = e.project(t[s[d]]);
1121
+ i.push(i[d - 1] + Math.hypot(g.x - l.x, g.y - l.y)), l = g;
1122
+ }
1123
+ const u = i[i.length - 1], c = /* @__PURE__ */ new Set();
1124
+ let v = 0;
1125
+ for (let d = 0; d < rt; d++) {
1126
+ const g = u === 0 ? d : d * u / rt;
1127
+ for (; v < i.length - 1 && i[v + 1] < g; ) v++;
1128
+ c.add(s[v]);
1129
+ }
1130
+ for (const d of s) n(d) && c.add(d);
1131
+ return { indices: [...c].sort((d, g) => d - g), capped: !0 };
1132
+ }
1133
+ function Or(e, t) {
1134
+ const n = (e[0] + t[0]) / 2, o = (i) => Math.log(Math.tan(Math.PI / 4 + i * Math.PI / 180 / 2)), s = ((i) => (2 * Math.atan(Math.exp(i)) - Math.PI / 2) * 180 / Math.PI)((o(e[1]) + o(t[1])) / 2);
1135
+ return [n, s];
1136
+ }
1137
+ function $r({ map: e, feature: t, initialSelectedIndices: n }) {
1138
+ var j;
1139
+ const { dataStore: o, uiStore: r } = Le(), s = Ue(), i = zt(), l = he((h) => h.selectedIds), u = W((h) => h.selectedPartIndex), c = $([]), [v, d] = le(() => n && n.length > 0 ? new Set(n.map((h) => `0:${h}`)) : /* @__PURE__ */ new Set()), g = $(v);
1140
+ K(() => {
1141
+ g.current = v;
1142
+ }, [v]);
1143
+ const w = $(/* @__PURE__ */ new Map()), [P, T] = le(null), _ = ve(() => T(null), []), [M, N] = le(null);
1144
+ K(() => {
1145
+ d(/* @__PURE__ */ new Set()), T(null), N(null);
1146
+ }, [t.id, u]);
1147
+ const E = $(n);
1148
+ K(() => {
1149
+ n !== E.current && (E.current = n, !(!n || n.length === 0) && d((h) => {
1150
+ const k = new Set(h);
1151
+ for (const O of n) k.add(`0:${O}`);
1152
+ for (const O of n) {
1153
+ const z = w.current.get(`0:${O}`);
1154
+ z && Ct(z, !0);
1155
+ }
1156
+ return k;
1157
+ }));
1158
+ }, [n]);
1159
+ function A(h) {
1160
+ Vt(e, /* @__PURE__ */ new Map([[t.id, h]]));
1161
+ }
1162
+ function D(h) {
1163
+ const k = nt(t.geometry, u, h);
1164
+ o.getState().updateFeature(t.id, So(t, k));
1165
+ }
1166
+ const q = $(!1);
1167
+ K(() => {
1168
+ const h = (k) => {
1169
+ q.current = k.metaKey || k.ctrlKey;
1170
+ };
1171
+ return window.addEventListener("keydown", h), window.addEventListener("keyup", h), () => {
1172
+ window.removeEventListener("keydown", h), window.removeEventListener("keyup", h);
1173
+ };
1174
+ }, []);
1175
+ function y() {
1176
+ Br(), c.current.forEach((z) => z.remove()), c.current = [], w.current = /* @__PURE__ */ new Map(), f.current = [], b.current = null, C.current = !1;
1177
+ const h = Oe(t.geometry, u);
1178
+ if (!h) return;
1179
+ const k = ot(h), O = g.current;
1180
+ I.current = !1, k.forEach((z, G) => {
1181
+ const H = h.type === "Polygon" ? z.slice(0, -1) : z, te = Sn(e, H, (Z) => O.has(`${G}:${Z}`));
1182
+ te.capped && (I.current = !0);
1183
+ for (const Z of te.indices) {
1184
+ const ne = H[Z], se = `${G}:${Z}`, ie = xn(O.has(se));
1185
+ w.current.set(se, ie);
1186
+ const re = new De.Marker({ element: ie, draggable: !0 }).setLngLat(ne).addTo(e);
1187
+ let J = !1;
1188
+ ie.addEventListener("click", (Y) => {
1189
+ if (Y.stopPropagation(), Y.preventDefault(), J) {
1190
+ J = !1;
1191
+ return;
1192
+ }
1193
+ Y.shiftKey ? d((ee) => {
1194
+ const oe = new Set(ee);
1195
+ oe.has(se) ? oe.delete(se) : oe.add(se);
1196
+ const Q = w.current.get(se);
1197
+ return Q && Ct(Q, oe.has(se)), oe;
1198
+ }) : (d(/* @__PURE__ */ new Set([se])), w.current.forEach((ee, oe) => Ct(ee, oe === se)));
1199
+ }), re.on("dragstart", () => {
1200
+ J = !0, C.current = !0, o.getState().takeSnapshot(), document.querySelectorAll(".elm-midpoint-marker").forEach((Y) => {
1201
+ Y.style.display = "none";
1202
+ }), Ce(!0);
1203
+ });
1204
+ const ce = [ne[0], ne[1]], U = ze(() => {
1205
+ const Y = re.getLngLat(), ee = [Y.lng, Y.lat], oe = Mt(h, G, Z, ee);
1206
+ A(nt(t.geometry, u, oe));
1207
+ });
1208
+ re.on("drag", () => U.schedule()), re.on("dragend", () => {
1209
+ U.cancel();
1210
+ const Y = re.getLngLat(), ee = [Y.lng, Y.lat], oe = Mt(h, G, Z, ee);
1211
+ if (D(oe), r.getState().topoEditEnabled && !q.current) {
1212
+ const Q = o.getState();
1213
+ Q.updateFeatures(on(
1214
+ Q.features,
1215
+ t.id,
1216
+ ce,
1217
+ ee
1218
+ ));
1219
+ }
1220
+ Ce(!1), C.current = !1, setTimeout(() => {
1221
+ J = !1;
1222
+ }, 50);
1223
+ }), ie.addEventListener("contextmenu", (Y) => {
1224
+ Y.preventDefault(), Y.stopPropagation(), T({ ringIdx: G, vertIdx: Z, x: Y.clientX, y: Y.clientY });
1225
+ }), c.current.push(re);
1226
+ }
1227
+ if (H.length >= 2) {
1228
+ const Z = h.type === "Polygon" ? H.length : H.length - 1, ne = [];
1229
+ for (let ie = 0; ie < Z; ie++) ne.push(Or(H[ie], H[(ie + 1) % H.length]));
1230
+ const se = Sn(e, ne, () => !1);
1231
+ se.capped && (I.current = !0);
1232
+ for (const ie of se.indices) {
1233
+ const re = H[ie], J = H[(ie + 1) % H.length], ce = ne[ie], U = xn(!1, !0);
1234
+ U.style.display = "none", f.current.push({ el: U, a: re, b: J });
1235
+ const Y = new De.Marker({ element: U, draggable: !0 }).setLngLat(ce).addTo(e);
1236
+ let ee = !1;
1237
+ Y.on("dragstart", () => {
1238
+ ee = !0, C.current = !0, o.getState().takeSnapshot(), Ce(!0);
1239
+ });
1240
+ const oe = ze(() => {
1241
+ const Q = Y.getLngLat(), de = [Q.lng, Q.lat], ue = He(h, G, ie + 1, de);
1242
+ A(nt(t.geometry, u, ue));
1243
+ });
1244
+ Y.on("drag", () => oe.schedule()), Y.on("dragend", () => {
1245
+ oe.cancel();
1246
+ const Q = Y.getLngLat(), de = [Q.lng, Q.lat], ue = He(h, G, ie + 1, de);
1247
+ if (D(ue), r.getState().topoEditEnabled) {
1248
+ const Re = o.getState();
1249
+ Re.updateFeatures(wt(
1250
+ Re.features,
1251
+ t.id,
1252
+ re,
1253
+ J,
1254
+ de
1255
+ ));
1256
+ }
1257
+ setTimeout(() => {
1258
+ ee = !1;
1259
+ }, 50), Ce(!1), C.current = !1;
1260
+ }), U.addEventListener("click", (Q) => {
1261
+ if (Q.stopPropagation(), ee) {
1262
+ ee = !1;
1263
+ return;
1264
+ }
1265
+ o.getState().takeSnapshot();
1266
+ const de = He(h, G, ie + 1, ce);
1267
+ if (D(de), r.getState().topoEditEnabled) {
1268
+ const ue = o.getState();
1269
+ ue.updateFeatures(wt(
1270
+ ue.features,
1271
+ t.id,
1272
+ re,
1273
+ J,
1274
+ ce
1275
+ ));
1276
+ }
1277
+ }), c.current.push(Y);
1278
+ }
1279
+ }
1280
+ });
1281
+ }
1282
+ const f = $([]), b = $(null), C = $(!1);
1283
+ K(() => {
1284
+ const h = (z) => {
1285
+ if (z === b.current) return;
1286
+ const G = f.current;
1287
+ b.current !== null && G[b.current] && (G[b.current].el.style.display = "none"), z !== null && (G[z].el.style.display = "flex"), b.current = z;
1288
+ }, k = (z) => {
1289
+ if (C.current) return;
1290
+ const { x: G, y: H } = z.point;
1291
+ let te = -1, Z = 1 / 0;
1292
+ f.current.forEach(({ a: se, b: ie }, re) => {
1293
+ const J = e.project(se), ce = e.project(ie), U = ce.x - J.x, Y = ce.y - J.y, ee = U * U + Y * Y, oe = ee ? Math.max(0, Math.min(1, ((G - J.x) * U + (H - J.y) * Y) / ee)) : 0, Q = (J.x + oe * U - G) ** 2 + (J.y + oe * Y - H) ** 2;
1294
+ Q < Z && (Z = Q, te = re);
1295
+ });
1296
+ const ne = b.current === null ? 22 : 36;
1297
+ h(te >= 0 && Z <= ne * ne ? te : null);
1298
+ }, O = (z) => {
1299
+ const G = z.originalEvent.relatedTarget;
1300
+ !C.current && !(G instanceof Node && e.getContainer().contains(G)) && h(null);
1301
+ };
1302
+ return e.on("mousemove", k), e.on("mouseout", O), () => {
1303
+ e.off("mousemove", k), e.off("mouseout", O);
1304
+ };
1305
+ }, [e]);
1306
+ const R = $(() => {
1307
+ });
1308
+ R.current = (h) => {
1309
+ var ee, oe;
1310
+ const k = h.originalEvent;
1311
+ if (C.current || k.button !== 0 || k.shiftKey || (oe = (ee = k.target) == null ? void 0 : ee.closest) != null && oe.call(ee, ".maplibregl-marker")) return;
1312
+ const O = Oe(t.geometry, u);
1313
+ if (!O || O.type !== "Polygon" && O.type !== "LineString") return;
1314
+ const z = O.type === "Polygon";
1315
+ let G = null, H = wn * wn;
1316
+ if (ot(O).forEach((Q, de) => {
1317
+ const ue = z ? Q.slice(0, -1) : Q, Re = z ? ue.length : ue.length - 1;
1318
+ if (ue.length < 2) return;
1319
+ let xe = e.project(ue[0]);
1320
+ for (let Ee = 0; Ee < Re; Ee++) {
1321
+ const Je = ue[(Ee + 1) % ue.length], xt = e.project(Je), Qe = xt.x - xe.x, et = xt.y - xe.y, en = Qe * Qe + et * et, tn = en ? Math.max(0, Math.min(1, ((h.point.x - xe.x) * Qe + (h.point.y - xe.y) * et) / en)) : 0, nn = (xe.x + tn * Qe - h.point.x) ** 2 + (xe.y + tn * et - h.point.y) ** 2;
1322
+ nn < H && (H = nn, G = { ringIdx: de, seg: Ee, a: ue[Ee], b: Je }), xe = xt;
1323
+ }
1324
+ }), !G) return;
1325
+ const { ringIdx: te, seg: Z, a: ne, b: se } = G;
1326
+ h.preventDefault();
1327
+ const ie = h.point;
1328
+ let re = [h.lngLat.lng, h.lngLat.lat], J = !1;
1329
+ const ce = ze(() => {
1330
+ A(nt(t.geometry, u, He(O, te, Z + 1, re)));
1331
+ }), U = (Q) => {
1332
+ if (!J) {
1333
+ if (Math.hypot(Q.point.x - ie.x, Q.point.y - ie.y) < 3) return;
1334
+ J = !0, C.current = !0, o.getState().takeSnapshot(), document.querySelectorAll(".elm-midpoint-marker").forEach((ue) => {
1335
+ ue.style.display = "none";
1336
+ }), b.current = null, Ce(!0);
1337
+ }
1338
+ re = [Q.lngLat.lng, Q.lngLat.lat];
1339
+ const de = Q.originalEvent.metaKey || Q.originalEvent.ctrlKey;
1340
+ if (r.getState().snapEnabled && !de) {
1341
+ const ue = Vn(re[0], re[1], e, o.getState().features, 15, /* @__PURE__ */ new Set([t.id]));
1342
+ ue && (re = ue.lnglat);
1343
+ }
1344
+ ce.schedule();
1345
+ }, Y = () => {
1346
+ if (e.off("mousemove", U), window.removeEventListener("mouseup", Y), ce.cancel(), !!J) {
1347
+ if (D(He(O, te, Z + 1, re)), z && r.getState().topoEditEnabled) {
1348
+ const Q = o.getState();
1349
+ Q.updateFeatures(wt(Q.features, t.id, ne, se, re));
1350
+ }
1351
+ Ce(!1), C.current = !1;
1352
+ }
1353
+ };
1354
+ e.on("mousemove", U), window.addEventListener("mouseup", Y);
1355
+ }, K(() => {
1356
+ const h = (k) => R.current(k);
1357
+ return e.on("mousedown", h), () => {
1358
+ e.off("mousedown", h);
1359
+ };
1360
+ }, [e]);
1361
+ const I = $(!1), a = $(y);
1362
+ a.current = y, K(() => {
1363
+ const h = () => {
1364
+ I.current && a.current();
1365
+ };
1366
+ return e.on("moveend", h), () => {
1367
+ e.off("moveend", h);
1368
+ };
1369
+ }, [e]), K(() => (y(), () => {
1370
+ c.current.forEach((h) => h.remove()), c.current = [], w.current = /* @__PURE__ */ new Map();
1371
+ }), [t, e, l, u]);
1372
+ function x(h, k) {
1373
+ const O = Oe(t.geometry, u);
1374
+ if (!O) return;
1375
+ const z = jr(O, h, k);
1376
+ if (!z) {
1377
+ s({ type: "warning", message: `Cannot delete: ${O.type === "Polygon" ? "an area needs at least 3" : O.type === "LineString" ? "a line needs at least 2" : "at least 1"} points` });
1378
+ return;
1379
+ }
1380
+ const G = ot(O)[h][k];
1381
+ if (o.getState().takeSnapshot(), D(z), d(/* @__PURE__ */ new Set()), O.type === "Polygon" && r.getState().topoEditEnabled) {
1382
+ const H = o.getState();
1383
+ H.updateFeatures(rn(H.features, t.id, [G]));
1384
+ }
1385
+ }
1386
+ function p() {
1387
+ const h = g.current;
1388
+ if (h.size === 0) return;
1389
+ const k = Oe(t.geometry, u);
1390
+ if (!k) return;
1391
+ const O = /* @__PURE__ */ new Map();
1392
+ for (const z of h) {
1393
+ const [G, H] = z.split(":"), te = Number(G), Z = Number(H), ne = O.get(te) ?? [];
1394
+ ne.push(Z), O.set(te, ne);
1395
+ }
1396
+ if (k.type === "LineString") {
1397
+ const z = k.coordinates, G = new Set(O.get(0) ?? []), H = z.filter((te, Z) => !G.has(Z));
1398
+ if (H.length < 2) {
1399
+ s({ type: "warning", message: "Cannot delete: a line needs at least 2 points" });
1400
+ return;
1401
+ }
1402
+ o.getState().takeSnapshot(), D({ type: "LineString", coordinates: H }), d(/* @__PURE__ */ new Set());
1403
+ return;
1404
+ }
1405
+ if (k.type === "MultiPoint") {
1406
+ const z = k.coordinates, G = new Set(O.get(0) ?? []), H = z.filter((te, Z) => !G.has(Z));
1407
+ if (H.length < 1) {
1408
+ s({ type: "warning", message: "Cannot delete: at least 1 point required" });
1409
+ return;
1410
+ }
1411
+ o.getState().takeSnapshot(), D({ type: "MultiPoint", coordinates: H }), d(/* @__PURE__ */ new Set());
1412
+ return;
1413
+ }
1414
+ if (k.type === "Polygon") {
1415
+ const z = k.coordinates, G = [];
1416
+ for (let H = 0; H < z.length; H++) {
1417
+ const te = z[H], Z = te.slice(0, -1), ne = new Set(O.get(H) ?? []);
1418
+ if (ne.size === 0) {
1419
+ G.push(te);
1420
+ continue;
1421
+ }
1422
+ const se = Z.filter((ie, re) => !ne.has(re));
1423
+ if (se.length < 3) {
1424
+ s({ type: "warning", message: "Cannot delete: an area needs at least 3 points" });
1425
+ return;
1426
+ }
1427
+ G.push([...se, se[0]]);
1428
+ }
1429
+ if (o.getState().takeSnapshot(), D({ type: "Polygon", coordinates: G }), d(/* @__PURE__ */ new Set()), r.getState().topoEditEnabled) {
1430
+ const H = [...O].flatMap(([Z, ne]) => ne.map((se) => z[Z][se])), te = o.getState();
1431
+ te.updateFeatures(rn(te.features, t.id, H));
1432
+ }
1433
+ return;
1434
+ }
1435
+ }
1436
+ function m() {
1437
+ if (g.current.size < 3) {
1438
+ s({ type: "warning", message: "Select at least 3 points to simplify" });
1439
+ return;
1440
+ }
1441
+ const h = Oe(t.geometry, u);
1442
+ if (!h || h.type !== "LineString" && h.type !== "Polygon") return;
1443
+ const k = /* @__PURE__ */ new Map();
1444
+ for (const U of g.current) {
1445
+ const [Y, ee] = U.split(":"), oe = Number(Y), Q = Number(ee), de = k.get(oe) ?? [];
1446
+ de.push(Q), k.set(oe, de);
1447
+ }
1448
+ if (k.size !== 1) {
1449
+ s({ type: "warning", message: "Selection must stay within one ring/line to simplify" });
1450
+ return;
1451
+ }
1452
+ const [O, z] = Array.from(k.entries())[0], G = z.sort((U, Y) => U - Y), H = G[0], te = G[G.length - 1], Z = h.type === "Polygon", ne = Z ? h.coordinates[O].slice(0, -1) : h.coordinates, se = ne.slice(H, te + 1), ie = bo(se, 1e-5), re = se.length - ie.length;
1453
+ if (re === 0) {
1454
+ s({ type: "warning", message: "Nothing to remove: no selected point sits on a straight line" });
1455
+ return;
1456
+ }
1457
+ const J = [...ne.slice(0, H), ...ie, ...ne.slice(te + 1)], ce = Z ? 3 : 2;
1458
+ if (J.length < ce) {
1459
+ s({ type: "warning", message: `Cannot simplify: ${Z ? "an area needs at least 3" : "a line needs at least 2"} points` });
1460
+ return;
1461
+ }
1462
+ if (o.getState().takeSnapshot(), Z) {
1463
+ const U = h.coordinates.map(
1464
+ (Y, ee) => ee === O ? [...J, J[0]] : Y
1465
+ );
1466
+ D({ type: "Polygon", coordinates: U });
1467
+ } else
1468
+ D({ type: "LineString", coordinates: J });
1469
+ d(/* @__PURE__ */ new Set()), s({ type: "success", message: `Removed ${re} extra point${re !== 1 ? "s" : ""}` });
1470
+ }
1471
+ K(() => {
1472
+ if (v.size === 0) return;
1473
+ function h(k) {
1474
+ if (k.key !== "Delete" && k.key !== "Backspace") return;
1475
+ const O = k.target;
1476
+ O && (O.tagName === "INPUT" || O.tagName === "TEXTAREA" || O.isContentEditable) || i(k) && (k.preventDefault(), k.stopPropagation(), p());
1477
+ }
1478
+ return window.addEventListener("keydown", h, { capture: !0 }), () => window.removeEventListener("keydown", h, { capture: !0 });
1479
+ }, [v]);
1480
+ const F = v.size > 0, S = P && (() => {
1481
+ const h = `${P.ringIdx}:${P.vertIdx}`, k = v.has(h) && v.size > 1;
1482
+ return /* @__PURE__ */ X(
1483
+ Ko,
1484
+ {
1485
+ x: P.x,
1486
+ y: P.y,
1487
+ onClose: _,
1488
+ items: [
1489
+ { label: "Edit coordinates…", icon: /* @__PURE__ */ X(rr, { size: 16 }), onClick: () => N({ ringIdx: P.ringIdx, vertIdx: P.vertIdx }) },
1490
+ { separator: !0 },
1491
+ {
1492
+ label: k ? `Delete ${v.size} points` : "Delete point",
1493
+ icon: /* @__PURE__ */ X(sr, { size: 16 }),
1494
+ onClick: () => k ? p() : x(P.ringIdx, P.vertIdx)
1495
+ }
1496
+ ]
1497
+ }
1498
+ );
1499
+ })(), L = M && Oe(t.geometry, u), B = L && M ? (j = ot(L)[M.ringIdx]) == null ? void 0 : j[M.vertIdx] : void 0, V = M && L && B && /* @__PURE__ */ X(
1500
+ Un,
1501
+ {
1502
+ map: e,
1503
+ coords: B,
1504
+ onSave: (h) => {
1505
+ if (o.getState().takeSnapshot(), D(Mt(L, M.ringIdx, M.vertIdx, h)), L.type === "Polygon" && r.getState().topoEditEnabled) {
1506
+ const k = o.getState();
1507
+ k.updateFeatures(on(k.features, t.id, B, h));
1508
+ }
1509
+ },
1510
+ onClose: () => N(null)
1511
+ },
1512
+ `${M.ringIdx}:${M.vertIdx}`
1513
+ );
1514
+ return /* @__PURE__ */ fe(lt, { children: [
1515
+ S,
1516
+ V,
1517
+ F && /* @__PURE__ */ X(
1518
+ No,
1519
+ {
1520
+ mapContainer: e.getContainer(),
1521
+ count: v.size,
1522
+ onSimplify: m,
1523
+ onDelete: p
1524
+ }
1525
+ )
1526
+ ] });
1527
+ }
1528
+ function Mt(e, t, n, o) {
1529
+ if (e.type === "Point") return { type: "Point", coordinates: Ve(e.coordinates, o) };
1530
+ if (e.type === "MultiPoint") {
1531
+ const r = [...e.coordinates];
1532
+ return r[n] = Ve(r[n], o), { type: "MultiPoint", coordinates: r };
1533
+ }
1534
+ if (e.type === "LineString") {
1535
+ const r = [...e.coordinates];
1536
+ return r[n] = Ve(r[n], o), { type: "LineString", coordinates: r };
1537
+ }
1538
+ return e.type === "Polygon" ? { type: "Polygon", coordinates: e.coordinates.map((s, i) => {
1539
+ if (i !== t) return s;
1540
+ const l = [...s];
1541
+ return l[n] = Ve(l[n], o), n === 0 && (l[l.length - 1] = l[0]), l;
1542
+ }) } : e;
1543
+ }
1544
+ function jr(e, t, n) {
1545
+ if (e.type === "LineString") {
1546
+ const o = e.coordinates.filter((r, s) => s !== n);
1547
+ return o.length < 2 ? null : { type: "LineString", coordinates: o };
1548
+ }
1549
+ if (e.type === "Polygon") {
1550
+ const r = e.coordinates[t].slice(0, -1);
1551
+ if (r.length <= 3) return null;
1552
+ const s = r.filter((l, u) => u !== n);
1553
+ return { type: "Polygon", coordinates: e.coordinates.map(
1554
+ (l, u) => u === t ? [...s, s[0]] : l
1555
+ ) };
1556
+ }
1557
+ if (e.type === "MultiPoint") {
1558
+ const o = e.coordinates.filter((r, s) => s !== n);
1559
+ return o.length < 1 ? null : { type: "MultiPoint", coordinates: o };
1560
+ }
1561
+ return null;
1562
+ }
1563
+ function He(e, t, n, o) {
1564
+ if (e.type === "LineString") {
1565
+ const r = [...e.coordinates];
1566
+ return r.splice(n, 0, sn(r[n - 1], r[n], o)), { type: "LineString", coordinates: r };
1567
+ }
1568
+ if (e.type === "Polygon") {
1569
+ const s = e.coordinates[t].slice(0, -1);
1570
+ return s.splice(n, 0, sn(s[n - 1], s[n % s.length], o)), { type: "Polygon", coordinates: e.coordinates.map(
1571
+ (l, u) => u === t ? [...s, s[0]] : l
1572
+ ) };
1573
+ }
1574
+ return e;
1575
+ }
1576
+ function zr(e, t, n) {
1577
+ if (!n) return [t[0] - e[0], t[1] - e[1]];
1578
+ const o = me(e), r = me(t);
1579
+ return [r[0] - o[0], r[1] - o[1]];
1580
+ }
1581
+ function st(e, t, n) {
1582
+ return $t({ type: "MultiPoint", coordinates: e }, t, n).coordinates;
1583
+ }
1584
+ function Hr(e, t, n) {
1585
+ let o = !1;
1586
+ for (let r = 0, s = t.length - 1; r < t.length; s = r++) {
1587
+ const i = t[r], l = t[s];
1588
+ i.y > e.y != l.y > e.y && e.x < (l.x - i.x) * (e.y - i.y) / (l.y - i.y) + i.x && (o = !o);
1589
+ const u = l.x - i.x, c = l.y - i.y, v = u * u + c * c, d = v ? Math.max(0, Math.min(1, ((e.x - i.x) * u + (e.y - i.y) * c) / v)) : 0;
1590
+ if (Math.hypot(i.x + d * u - e.x, i.y + d * c - e.y) <= n) return !0;
1591
+ }
1592
+ return o;
1593
+ }
1594
+ const Vr = 3, Xr = 8;
1595
+ function it(e) {
1596
+ const t = cr(e), [n, o, r, s] = Bn(t), i = (n + r) / 2, l = Zr(o, s);
1597
+ return {
1598
+ corners: [
1599
+ [n, s],
1600
+ [r, s],
1601
+ [r, o],
1602
+ [n, o]
1603
+ ],
1604
+ edges: [
1605
+ [i, s],
1606
+ [r, l],
1607
+ [i, o],
1608
+ [n, l]
1609
+ ],
1610
+ // The box centre (rotation pivot, Alt-scale anchor), not the vertex mean.
1611
+ center: [i, l],
1612
+ rotateHandle: [i, s]
1613
+ };
1614
+ }
1615
+ function kt(e, t, n) {
1616
+ const [o, r] = t, s = Ke(n), i = Math.cos(s), l = Math.sin(s), u = Te(r);
1617
+ return e.map(([c, v]) => {
1618
+ const d = (c - o) * u, g = v - r;
1619
+ return [
1620
+ o + (d * i - g * l) / u,
1621
+ r + (d * l + g * i)
1622
+ ];
1623
+ });
1624
+ }
1625
+ function Yr(e, t, n, o, r) {
1626
+ const [s, i] = t, l = Ke(r), u = Math.cos(l), c = Math.sin(l), v = Te(i);
1627
+ return e.map(([d, g]) => {
1628
+ const w = (d - s) * v, P = g - i, T = w * u + P * c, _ = -w * c + P * u, M = T * n, N = _ * o, E = M * u - N * c, A = M * c + N * u;
1629
+ return [s + E / v, i + A];
1630
+ });
1631
+ }
1632
+ function Gr(e, t, n, o) {
1633
+ const r = me(t), s = Ke(o), i = Math.cos(s), l = Math.sin(s);
1634
+ function u(c) {
1635
+ const v = me(c), d = v[0] - r[0], g = v[1] - r[1], w = d * i + g * l, P = -d * l + g * i, T = w * n, _ = P * n, M = T * i - _ * l, N = T * l + _ * i;
1636
+ return Ot([r[0] + M, r[1] + N]);
1637
+ }
1638
+ return { ...e, geometry: _n(e.geometry, u) };
1639
+ }
1640
+ function Wr(e, t, n, o) {
1641
+ const r = me(t), s = Ke(o), i = Math.cos(s), l = Math.sin(s);
1642
+ return e.map((u) => {
1643
+ const c = me(u), v = c[0] - r[0], d = c[1] - r[1], g = v * i + d * l, w = -v * l + d * i, P = g * n, T = w * n, _ = P * i - T * l, M = P * l + T * i;
1644
+ return Ot([r[0] + _, r[1] + M]);
1645
+ });
1646
+ }
1647
+ function Ur(e, t, n, o, r) {
1648
+ const [s, i] = t, l = Ke(r), u = Math.cos(l), c = Math.sin(l), v = Te(i);
1649
+ function d(g) {
1650
+ const w = (g[0] - s) * v, P = g[1] - i, T = w * u + P * c, _ = -w * c + P * u, M = T * n, N = _ * o, E = M * u - N * c, A = M * c + N * u;
1651
+ return [s + E / v, i + A];
1652
+ }
1653
+ return { ...e, geometry: _n(e.geometry, d) };
1654
+ }
1655
+ function Zr(e, t) {
1656
+ return Ot([0, (me([0, e])[1] + me([0, t])[1]) / 2])[1];
1657
+ }
1658
+ function qr(e, t, n, o) {
1659
+ const r = o ? e.initialBbox.center : e.origin, s = Math.cos(Ke(e.rotationAngle)), i = Math.sin(Ke(e.rotationAngle));
1660
+ let l;
1661
+ if (n) {
1662
+ const _ = me(r);
1663
+ l = (M) => {
1664
+ const N = me(M), E = N[0] - _[0], A = N[1] - _[1];
1665
+ return [E * s + A * i, -E * i + A * s];
1666
+ };
1667
+ } else {
1668
+ const _ = Te(r[1]);
1669
+ l = (M) => {
1670
+ const N = (M[0] - r[0]) * _, E = M[1] - r[1];
1671
+ return [N * s + E * i, -N * i + E * s];
1672
+ };
1673
+ }
1674
+ const [u, c] = l(e.startLngLat), [v, d] = l(t), g = e.edgeIndex === 0 || e.edgeIndex === 2, w = e.edgeIndex === 1 || e.edgeIndex === 3, P = (_) => Math.abs(_) < 0.01 ? _ < 0 ? -0.01 : 0.01 : _, T = (_, M) => Math.abs(M) > 1e-9 ? _ / M : 1;
1675
+ if (n) {
1676
+ let _;
1677
+ if (g) _ = T(d, c);
1678
+ else if (w) _ = T(v, u);
1679
+ else {
1680
+ const M = u * u + c * c;
1681
+ _ = M > 1e-18 ? (v * u + d * c) / M : 1;
1682
+ }
1683
+ return { origin: r, uniform: !0, factor: P(_) };
1684
+ }
1685
+ return {
1686
+ origin: r,
1687
+ uniform: !1,
1688
+ scaleX: w || !g ? P(T(v, u)) : 1,
1689
+ scaleY: g || !w ? P(T(d, c)) : 1
1690
+ };
1691
+ }
1692
+ function Jr(e, t, n, o) {
1693
+ const r = n.uniform ? (s) => Wr(s, n.origin, n.factor, o) : (s) => Yr(s, n.origin, n.scaleX, n.scaleY, o);
1694
+ return {
1695
+ features: e.map((s) => n.uniform ? Gr(s, n.origin, n.factor, o) : Ur(s, n.origin, n.scaleX, n.scaleY, o)),
1696
+ box: {
1697
+ corners: r(t.corners),
1698
+ edges: r(t.edges),
1699
+ center: r([t.center])[0],
1700
+ rotateHandle: r([t.rotateHandle])[0]
1701
+ }
1702
+ };
1703
+ }
1704
+ function Qr(e) {
1705
+ return e === "nw" || e === "se" ? "nwse-resize" : e === "ne" || e === "sw" ? "nesw-resize" : e === "n" || e === "s" ? "ns-resize" : e === "e" || e === "w" ? "ew-resize" : "grab";
1706
+ }
1707
+ function It(e) {
1708
+ const t = document.createElement("div");
1709
+ if (e === "rotate") {
1710
+ t.style.cssText = [
1711
+ "position:relative",
1712
+ "display:flex",
1713
+ "align-items:center",
1714
+ "justify-content:center",
1715
+ "width:16px",
1716
+ "height:32px",
1717
+ "cursor:grab"
1718
+ ].join(";");
1719
+ const n = document.createElement("div");
1720
+ n.style.cssText = "position:absolute;bottom:0;left:50%;transform:translateX(-50%);width:2px;height:24px;background:var(--color-primary-600);", t.appendChild(n);
1721
+ const o = document.createElement("div");
1722
+ o.style.cssText = [
1723
+ "position:absolute",
1724
+ "top:0",
1725
+ "left:50%",
1726
+ "transform:translateX(-50%)",
1727
+ "width:16px",
1728
+ "height:16px",
1729
+ "background:#ffffff",
1730
+ "border:2px solid var(--color-primary-600)",
1731
+ "border-radius:50%",
1732
+ "box-shadow:0 1px 3px rgba(0,0,0,0.35)",
1733
+ "display:flex",
1734
+ "align-items:center",
1735
+ "justify-content:center"
1736
+ ].join(";");
1737
+ const r = document.createElement("div");
1738
+ return r.style.cssText = "width:6px;height:6px;background:var(--color-primary-600);border-radius:50%;", o.appendChild(r), t.appendChild(o), t;
1739
+ }
1740
+ return t.style.cssText = [
1741
+ "width:12px",
1742
+ "height:12px",
1743
+ "background:#ffffff",
1744
+ "border:2px solid var(--color-primary-600)",
1745
+ "border-radius:3px",
1746
+ `cursor:${Qr(e)}`,
1747
+ "box-shadow:0 1px 3px rgba(0,0,0,0.35)"
1748
+ ].join(";"), t;
1749
+ }
1750
+ function es({ map: e, features: t }) {
1751
+ const { dataStore: n, uiStore: o } = Le(), r = he((y) => y.selectedIds), s = W((y) => y.transformActive), i = W((y) => y.setTransformDragging), l = $(t);
1752
+ l.current = t;
1753
+ const [u, c] = le(null), v = $(null);
1754
+ v.current = u;
1755
+ const d = $(0), g = r.join(",");
1756
+ K(() => {
1757
+ c(null), d.current = 0;
1758
+ }, [g]);
1759
+ const w = $(null), P = $(null), T = $([]);
1760
+ function _() {
1761
+ T.current.forEach((y) => y.remove()), T.current = [];
1762
+ }
1763
+ function M(y) {
1764
+ const f = /* @__PURE__ */ new Map();
1765
+ for (const b of y) f.set(String(b.id ?? ""), b.geometry);
1766
+ Vt(e, f);
1767
+ }
1768
+ function N(y) {
1769
+ const f = T.current;
1770
+ if (f.length === 9) {
1771
+ for (let b = 0; b < 4; b++) f[b].setLngLat(y.corners[b]);
1772
+ for (let b = 0; b < 4; b++) f[4 + b].setLngLat(y.edges[b]);
1773
+ f[8].setLngLat(y.rotateHandle);
1774
+ }
1775
+ }
1776
+ const E = $(null);
1777
+ K(() => {
1778
+ if (!s || t.length === 0) return;
1779
+ _();
1780
+ const y = v.current ?? it(t), f = ["nw", "ne", "se", "sw"], b = ["n", "e", "s", "w"], C = [];
1781
+ y.corners.forEach((R, I) => {
1782
+ const a = It(f[I]), x = new De.Marker({ element: a, draggable: !1 }).setLngLat(R).addTo(e);
1783
+ a.addEventListener("mousedown", (p) => D(p, I, !1)), C.push(x);
1784
+ }), y.edges.forEach((R, I) => {
1785
+ const a = It(b[I]), x = new De.Marker({ element: a, draggable: !1 }).setLngLat(R).addTo(e);
1786
+ a.addEventListener("mousedown", (p) => D(p, I, !0)), C.push(x);
1787
+ });
1788
+ {
1789
+ const R = It("rotate"), I = new De.Marker({ element: R, anchor: "bottom", draggable: !1 }).setLngLat(y.rotateHandle).addTo(e);
1790
+ R.addEventListener("mousedown", (a) => q(a)), C.push(I);
1791
+ }
1792
+ return T.current = C, () => {
1793
+ _();
1794
+ };
1795
+ }, [s, g, u, e]), K(() => {
1796
+ function y(S) {
1797
+ const L = e.getCanvasContainer().getBoundingClientRect(), B = e.unproject([S.clientX - L.left, S.clientY - L.top]);
1798
+ return [B.lng, B.lat];
1799
+ }
1800
+ const f = ze(I);
1801
+ let b = null;
1802
+ function C(S) {
1803
+ E.current && (S.preventDefault(), b = { clientX: S.clientX, clientY: S.clientY }, f.schedule(S));
1804
+ }
1805
+ function R(S) {
1806
+ var L;
1807
+ S.key !== "Shift" && S.key !== "Alt" || ((L = E.current) == null ? void 0 : L.type) !== "scale" || !b || (S.preventDefault(), f.schedule({ ...b, shiftKey: S.shiftKey, altKey: S.altKey }));
1808
+ }
1809
+ function I(S) {
1810
+ const L = E.current;
1811
+ if (!L) return;
1812
+ const [B, V] = y(S), j = n.getState().geometryMode;
1813
+ if (L.type === "move") {
1814
+ if (!L.moving) {
1815
+ const H = e.getCanvasContainer().getBoundingClientRect();
1816
+ if (Math.hypot(S.clientX - H.left - L.startPoint.x, S.clientY - H.top - L.startPoint.y) < Vr) return;
1817
+ L.moving = !0, i(!0);
1818
+ }
1819
+ const h = j === "visual", k = zr(L.startLngLat, [B, V], h), O = L.initialFeatures.map((H) => ({ ...H, geometry: $t(H.geometry, k, h) })), z = L.initialBbox, G = {
1820
+ corners: st(z.corners, k, h),
1821
+ edges: st(z.edges, k, h),
1822
+ center: st([z.center], k, h)[0],
1823
+ rotateHandle: st([z.rotateHandle], k, h)[0]
1824
+ };
1825
+ w.current = O, P.current = G, M(O), N(G);
1826
+ } else if (L.type === "rotate") {
1827
+ const h = L.center, k = Te(h[1]), O = V - h[1], z = j === "visual" ? (B - h[0]) * k : B - h[0], H = (Math.atan2(O, z) - L.initialAngle) * (180 / Math.PI), te = L.initialFeatures.map(
1828
+ (ne) => j === "visual" ? Po(ne, h, 1, 1, H) : ir(ne, H, { pivot: h })
1829
+ ), Z = {
1830
+ corners: kt(L.initialBbox.corners, h, H),
1831
+ edges: kt(L.initialBbox.edges, h, H),
1832
+ center: h,
1833
+ rotateHandle: kt([L.initialBbox.rotateHandle], h, H)[0]
1834
+ };
1835
+ w.current = te, P.current = Z, M(te), N(Z);
1836
+ } else if (L.type === "scale") {
1837
+ const h = L.rotationAngle, k = qr({
1838
+ initialBbox: L.initialBbox,
1839
+ origin: L.origin,
1840
+ startLngLat: L.startLngLat,
1841
+ edgeIndex: L.edgeIndex,
1842
+ rotationAngle: h
1843
+ }, [B, V], S.shiftKey, S.altKey), O = Jr(L.initialFeatures, L.initialBbox, k, h);
1844
+ w.current = O.features, P.current = O.box, M(O.features), N(O.box);
1845
+ }
1846
+ }
1847
+ function a() {
1848
+ f.flush();
1849
+ const S = E.current;
1850
+ if (!S) return;
1851
+ const L = w.current, B = P.current, V = S.type === "rotate";
1852
+ if (E.current = null, b = null, w.current = null, P.current = null, e.dragPan.enable(), i(!1), S.type === "move" && L) {
1853
+ const j = e.getContainer(), h = (k) => k.stopPropagation();
1854
+ j.addEventListener("click", h, !0), setTimeout(() => j.removeEventListener("click", h, !0), 0);
1855
+ }
1856
+ if (L && (n.getState().takeSnapshot(), n.getState().updateFeatures(Eo(
1857
+ n.getState().features,
1858
+ L.flatMap((j) => j.id == null || j.id === "" ? [] : [{ id: String(j.id), geometry: j.geometry }]),
1859
+ o.getState().topoEditEnabled
1860
+ ))), B) {
1861
+ if (V) {
1862
+ const j = B.center, h = B.edges[1], k = Te(j[1]), O = (h[0] - j[0]) * k, z = h[1] - j[1];
1863
+ d.current = Math.atan2(z, O) * (180 / Math.PI);
1864
+ }
1865
+ c(B);
1866
+ }
1867
+ }
1868
+ function x(S, L, B) {
1869
+ S.preventDefault(), S.stopPropagation(), e.dragPan.disable();
1870
+ const V = v.current ?? it(l.current), [j, h] = y(S), k = B ? V.edges[(L + 2) % 4] : V.corners[(L + 2) % 4];
1871
+ E.current = {
1872
+ type: "scale",
1873
+ initialFeatures: structuredClone(l.current),
1874
+ initialBbox: V,
1875
+ rotationAngle: d.current,
1876
+ origin: k,
1877
+ startLngLat: [j, h],
1878
+ edgeIndex: B ? L : void 0
1879
+ }, i(!0);
1880
+ }
1881
+ function p(S) {
1882
+ S.preventDefault(), S.stopPropagation(), e.dragPan.disable();
1883
+ const L = v.current ?? it(l.current), B = L.center, [V, j] = y(S), h = n.getState().geometryMode, k = Te(B[1]), O = j - B[1], z = h === "visual" ? (V - B[0]) * k : V - B[0];
1884
+ E.current = {
1885
+ type: "rotate",
1886
+ initialFeatures: structuredClone(l.current),
1887
+ initialBbox: L,
1888
+ rotationAngle: d.current,
1889
+ center: B,
1890
+ initialAngle: Math.atan2(O, z)
1891
+ }, i(!0);
1892
+ }
1893
+ function m(S) {
1894
+ if (E.current || S.button !== 0 || S.shiftKey || S.altKey || S.ctrlKey || S.metaKey || S.target !== e.getCanvas()) return;
1895
+ const L = o.getState();
1896
+ if (!L.transformActive || L.readonly || L.editingMode !== "none" || L.vertexEditActive) return;
1897
+ const B = l.current;
1898
+ if (B.length === 0) return;
1899
+ const V = v.current ?? it(B), j = e.getCanvasContainer().getBoundingClientRect(), h = { x: S.clientX - j.left, y: S.clientY - j.top };
1900
+ Hr(h, V.corners.map((k) => e.project(k)), Xr) && (S.preventDefault(), S.stopPropagation(), e.dragPan.disable(), E.current = {
1901
+ type: "move",
1902
+ initialFeatures: structuredClone(B),
1903
+ initialBbox: V,
1904
+ rotationAngle: d.current,
1905
+ startLngLat: y(S),
1906
+ startPoint: h,
1907
+ moving: !1
1908
+ });
1909
+ }
1910
+ const F = e.getContainer();
1911
+ return F.addEventListener("mousedown", m, !0), A.current.handleScaleStart = x, A.current.handleRotateStart = p, document.addEventListener("mousemove", C), document.addEventListener("mouseup", a), document.addEventListener("keydown", R), document.addEventListener("keyup", R), () => {
1912
+ f.cancel(), F.removeEventListener("mousedown", m, !0), document.removeEventListener("mousemove", C), document.removeEventListener("mouseup", a), document.removeEventListener("keydown", R), document.removeEventListener("keyup", R);
1913
+ };
1914
+ }, [e, n, o, i]);
1915
+ const A = $({
1916
+ handleScaleStart: () => {
1917
+ },
1918
+ handleRotateStart: () => {
1919
+ }
1920
+ });
1921
+ function D(y, f, b) {
1922
+ A.current.handleScaleStart(y, f, b);
1923
+ }
1924
+ function q(y) {
1925
+ A.current.handleRotateStart(y);
1926
+ }
1927
+ return null;
1928
+ }
1929
+ function ts({ map: e, feature: t, onDone: n }) {
1930
+ const o = he((d) => d.updateFeature), [r, s] = le(
1931
+ t.properties.name ?? ""
1932
+ ), [i, l] = le(() => {
1933
+ const d = t.geometry.coordinates, g = e.project(d);
1934
+ return { x: g.x, y: g.y };
1935
+ }), u = $(null);
1936
+ K(() => {
1937
+ const d = t.geometry.coordinates, g = () => {
1938
+ const w = e.project(d);
1939
+ l({ x: w.x, y: w.y });
1940
+ };
1941
+ return e.on("move", g), e.on("zoom", g), e.on("resize", g), () => {
1942
+ e.off("move", g), e.off("zoom", g), e.off("resize", g);
1943
+ };
1944
+ }, [e, t.geometry]), K(() => {
1945
+ const d = setTimeout(() => {
1946
+ var g, w;
1947
+ (g = u.current) == null || g.focus(), (w = u.current) == null || w.select();
1948
+ }, 0);
1949
+ return () => clearTimeout(d);
1950
+ }, []);
1951
+ function c() {
1952
+ const d = r;
1953
+ d !== (t.properties.name ?? "") && o(t.id, {
1954
+ properties: { ...t.properties, name: d }
1955
+ }), n();
1956
+ }
1957
+ const v = e.getCanvasContainer();
1958
+ return Ze(
1959
+ /* @__PURE__ */ X(
1960
+ "div",
1961
+ {
1962
+ "data-elm-theme": !0,
1963
+ style: {
1964
+ position: "absolute",
1965
+ left: i.x,
1966
+ top: i.y,
1967
+ transform: "translate(-50%, -50%)",
1968
+ zIndex: 500,
1969
+ pointerEvents: "auto"
1970
+ },
1971
+ onMouseDown: (d) => d.stopPropagation(),
1972
+ onDoubleClick: (d) => d.stopPropagation(),
1973
+ onContextMenu: (d) => d.stopPropagation(),
1974
+ children: /* @__PURE__ */ fe("div", { className: "grid items-center justify-items-center bg-white/95 backdrop-blur-md border border-slate-800 text-slate-800 rounded px-3 py-1.5 text-sm font-medium shadow-lg", children: [
1975
+ /* @__PURE__ */ X(
1976
+ "div",
1977
+ {
1978
+ className: "invisible whitespace-pre pointer-events-none col-start-1 row-start-1 min-w-[12px] px-[2px] leading-tight",
1979
+ "aria-hidden": !0,
1980
+ children: r + " "
1981
+ }
1982
+ ),
1983
+ /* @__PURE__ */ X(
1984
+ "textarea",
1985
+ {
1986
+ ref: u,
1987
+ value: r,
1988
+ onChange: (d) => s(d.target.value),
1989
+ onKeyDown: (d) => {
1990
+ d.key === "Enter" && !d.shiftKey ? (d.preventDefault(), c()) : d.key === "Escape" && (d.preventDefault(), n());
1991
+ },
1992
+ onBlur: c,
1993
+ className: "col-start-1 row-start-1 bg-transparent outline-none resize-none overflow-hidden whitespace-pre text-center leading-tight min-w-0 min-h-0 px-[2px] w-full h-full m-0 border-none",
1994
+ rows: 1
1995
+ }
1996
+ )
1997
+ ] })
1998
+ }
1999
+ ),
2000
+ v
2001
+ );
2002
+ }
2003
+ function ns([e, t, n, o], r, s, i, l) {
2004
+ return e >= r && n <= i && t >= s && o <= l;
2005
+ }
2006
+ function os(e, t) {
2007
+ if (e === t) return !0;
2008
+ if (e.length !== t.length) return !1;
2009
+ const n = new Set(e);
2010
+ return t.every((o) => n.has(o));
2011
+ }
2012
+ function rs({ map: e, onVertexBoxSelect: t }) {
2013
+ const { dataStore: n } = Le(), o = W((d) => d.editingMode), r = W((d) => d.vertexEditActive), s = W((d) => d.transformActive), i = W((d) => d.readonly), l = $(o), u = $(r), c = $(s), v = $(i);
2014
+ return l.current = o, u.current = r, c.current = s, v.current = i, K(() => {
2015
+ const d = e.getCanvas(), g = e.getContainer(), w = (P) => {
2016
+ if (!P.shiftKey || v.current || c.current) return;
2017
+ const T = u.current;
2018
+ if (!T && l.current !== "none") return;
2019
+ P.preventDefault(), e.dragPan.disable(), e.boxZoom.disable();
2020
+ const _ = P.clientX, M = P.clientY, N = g.getBoundingClientRect(), E = [...n.getState().selectedIds], A = document.createElement("div");
2021
+ A.style.cssText = [
2022
+ "position:absolute",
2023
+ "pointer-events:none",
2024
+ "border:2px solid var(--color-primary-500)",
2025
+ "background:color-mix(in srgb, var(--color-primary-500) 8%, transparent)",
2026
+ "z-index:9999",
2027
+ "border-radius:2px"
2028
+ ].join(";"), g.appendChild(A);
2029
+ let D = !1, q = 0;
2030
+ function y(a) {
2031
+ const x = Math.min(_, a.clientX) - N.left, p = Math.min(M, a.clientY) - N.top, m = Math.max(_, a.clientX) - N.left, F = Math.max(M, a.clientY) - N.top, S = e.unproject([x, p]), L = e.unproject([m, F]);
2032
+ return {
2033
+ boxW: S.lng,
2034
+ boxE: L.lng,
2035
+ boxN: S.lat,
2036
+ boxS: L.lat,
2037
+ overlayX: x,
2038
+ overlayY: p,
2039
+ overlayW: m - x,
2040
+ overlayH: F - p
2041
+ };
2042
+ }
2043
+ function f(a) {
2044
+ const { boxW: x, boxE: p, boxN: m, boxS: F } = y(a), S = n.getState(), L = new Set(S.groups.filter((h) => h.hidden).map((h) => h.id)), B = S.features.filter(
2045
+ (h) => !h.hidden && (!h.groupId || !L.has(h.groupId))
2046
+ ), V = {
2047
+ type: "Feature",
2048
+ properties: {},
2049
+ geometry: {
2050
+ type: "Polygon",
2051
+ coordinates: [[
2052
+ [x, F],
2053
+ [p, F],
2054
+ [p, m],
2055
+ [x, m],
2056
+ [x, F]
2057
+ ]]
2058
+ }
2059
+ }, j = [];
2060
+ for (const h of B) {
2061
+ if (h.geometry.type === "Point") {
2062
+ const [te, Z] = h.geometry.coordinates;
2063
+ te >= x && te <= p && Z >= F && Z <= m && j.push(h.id);
2064
+ continue;
2065
+ }
2066
+ const k = h.bbox ?? Nn(h.geometry), [O, z, G, H] = k;
2067
+ if (G >= x && O <= p && H >= F && z <= m) {
2068
+ if (ns(k, x, F, p, m)) {
2069
+ j.push(h.id);
2070
+ continue;
2071
+ }
2072
+ try {
2073
+ lr(V, h) && j.push(h.id);
2074
+ } catch {
2075
+ j.push(h.id);
2076
+ }
2077
+ }
2078
+ }
2079
+ return j;
2080
+ }
2081
+ function b(a) {
2082
+ const x = new Set(E);
2083
+ a.forEach((F) => x.add(F));
2084
+ const p = Array.from(x), m = n.getState();
2085
+ os(m.selectedIds, p) && m.selectedGroupId === null || m.setSelection(p);
2086
+ }
2087
+ function C(a) {
2088
+ const x = n.getState().selectedIds[0];
2089
+ if (!x) return null;
2090
+ const p = n.getState().features.find((j) => j.id === x);
2091
+ if (!p) return null;
2092
+ let m;
2093
+ if (p.geometry.type === "LineString")
2094
+ m = p.geometry.coordinates;
2095
+ else if (p.geometry.type === "Polygon")
2096
+ m = p.geometry.coordinates[0].slice(0, -1);
2097
+ else
2098
+ return null;
2099
+ const { boxW: F, boxE: S, boxN: L, boxS: B } = y(a), V = [];
2100
+ for (let j = 0; j < m.length; j++) {
2101
+ const [h, k] = m[j];
2102
+ h >= F && h <= S && k >= B && k <= L && V.push(j);
2103
+ }
2104
+ return { id: x, indices: V };
2105
+ }
2106
+ const R = (a) => {
2107
+ const x = Math.abs(a.clientX - _), p = Math.abs(a.clientY - M);
2108
+ if (!D && x < 5 && p < 5) return;
2109
+ D = !0;
2110
+ const { overlayX: m, overlayY: F, overlayW: S, overlayH: L } = y(a);
2111
+ A.style.left = `${m}px`, A.style.top = `${F}px`, A.style.width = `${S}px`, A.style.height = `${L}px`, !T && Date.now() - q > 30 && (b(f(a)), q = Date.now());
2112
+ }, I = (a) => {
2113
+ if (A.remove(), e.dragPan.enable(), e.boxZoom.enable(), window.removeEventListener("mousemove", R), window.removeEventListener("mouseup", I), !D) return;
2114
+ if (T) {
2115
+ const p = C(a);
2116
+ p && p.indices.length > 0 && t && t(p.id, p.indices);
2117
+ return;
2118
+ }
2119
+ const x = f(a);
2120
+ if (b(x), x.length === 0 && E.length === 1 && t) {
2121
+ const p = n.getState().features.find((m) => m.id === E[0]);
2122
+ if (p && (p.geometry.type === "LineString" || p.geometry.type === "Polygon")) {
2123
+ const m = C(a);
2124
+ m && m.indices.length > 0 && t(m.id, m.indices);
2125
+ }
2126
+ }
2127
+ };
2128
+ window.addEventListener("mousemove", R), window.addEventListener("mouseup", I);
2129
+ };
2130
+ return d.addEventListener("mousedown", w), () => d.removeEventListener("mousedown", w);
2131
+ }, [e, n, t]), null;
2132
+ }
2133
+ function ss(e) {
2134
+ return e && "style" in e ? e : null;
2135
+ }
2136
+ function is(e) {
2137
+ const t = $(null), n = $(!1), o = $({ value: "", priority: "" });
2138
+ function r(l, u, c = "important") {
2139
+ l.style.setProperty("cursor", u, c);
2140
+ }
2141
+ K(() => {
2142
+ if (e) return;
2143
+ function l(u) {
2144
+ if (!n.current) return;
2145
+ const c = t.current;
2146
+ if (!c) return;
2147
+ const v = u.ctrlKey || u.metaKey, d = u.altKey;
2148
+ v || d ? r(c, d ? "copy" : "move") : r(c, o.current.value, o.current.priority);
2149
+ }
2150
+ return window.addEventListener("keydown", l), window.addEventListener("keyup", l), () => {
2151
+ window.removeEventListener("keydown", l), window.removeEventListener("keyup", l);
2152
+ };
2153
+ }, [e]);
2154
+ const s = ve((l, u, c) => {
2155
+ const v = ss(l), d = v !== null && v === t.current && n.current;
2156
+ t.current = v, n.current = !0, c !== void 0 ? o.current = { value: c, priority: "" } : d || (o.current = {
2157
+ value: (v == null ? void 0 : v.style.getPropertyValue("cursor")) ?? "",
2158
+ priority: (v == null ? void 0 : v.style.getPropertyPriority("cursor")) ?? ""
2159
+ });
2160
+ const g = u;
2161
+ v && g && (g.ctrlKey || g.metaKey || g.altKey) ? r(v, g.altKey ? "copy" : "move") : v && c !== void 0 && r(v, c, "");
2162
+ }, []), i = ve((l) => {
2163
+ n.current = !1, t.current && (l !== void 0 ? r(t.current, l, "") : r(t.current, o.current.value, o.current.priority), t.current = null), o.current = { value: "", priority: "" };
2164
+ }, []);
2165
+ return Bt(() => ({ enter: s, leave: i }), [s, i]);
2166
+ }
2167
+ let Ye = { x: -1, y: -1, ctrlKey: !1, metaKey: !1, altKey: !1 };
2168
+ if (typeof window < "u") {
2169
+ window.addEventListener("mousemove", (n) => {
2170
+ Ye = { x: n.clientX, y: n.clientY, ctrlKey: n.ctrlKey, metaKey: n.metaKey, altKey: n.altKey };
2171
+ }, { capture: !0, passive: !0 });
2172
+ const e = (n) => {
2173
+ Ye = { x: n.clientX, y: n.clientY, ctrlKey: n.ctrlKey, metaKey: n.metaKey, altKey: n.altKey };
2174
+ };
2175
+ window.addEventListener("pointerdown", e, { capture: !0, passive: !0 }), window.addEventListener("mousedown", e, { capture: !0, passive: !0 });
2176
+ const t = (n) => {
2177
+ Ye = { ...Ye, ctrlKey: n.ctrlKey, metaKey: n.metaKey, altKey: n.altKey };
2178
+ };
2179
+ window.addEventListener("keydown", t, { capture: !0 }), window.addEventListener("keyup", t, { capture: !0 });
2180
+ }
2181
+ function cs() {
2182
+ return Ye;
2183
+ }
2184
+ function $e(e, t, n) {
2185
+ if (!n.every((o) => e.getLayer(o))) return [];
2186
+ try {
2187
+ return e.queryRenderedFeatures(t, { layers: n });
2188
+ } catch {
2189
+ return [];
2190
+ }
2191
+ }
2192
+ function ls(e) {
2193
+ const t = "elm-drag-ghost";
2194
+ e.getSource(t) || (e.addSource(t, { type: "geojson", data: { type: "FeatureCollection", features: [] } }), e.addLayer({
2195
+ id: "elm-drag-ghost-fill",
2196
+ type: "fill",
2197
+ source: t,
2198
+ filter: ["in", ["geometry-type"], ["literal", ["Polygon", "MultiPolygon"]]],
2199
+ paint: { "fill-opacity": 0.18 }
2200
+ }), e.addLayer({
2201
+ id: "elm-drag-ghost-line",
2202
+ type: "line",
2203
+ source: t,
2204
+ filter: [
2205
+ "in",
2206
+ ["geometry-type"],
2207
+ ["literal", ["LineString", "MultiLineString", "Polygon", "MultiPolygon"]]
2208
+ ],
2209
+ paint: { "line-opacity": 0.6, "line-width": 2, "line-dasharray": [3, 3] }
2210
+ }), e.addLayer({
2211
+ id: "elm-drag-ghost-point",
2212
+ type: "circle",
2213
+ source: t,
2214
+ filter: ["in", ["geometry-type"], ["literal", ["Point", "MultiPoint"]]],
2215
+ paint: {
2216
+ "circle-radius": 7,
2217
+ "circle-opacity": 0.6,
2218
+ "circle-stroke-color": "#ffffff",
2219
+ "circle-stroke-width": 2
2220
+ }
2221
+ }), Ne(e, Qn));
2222
+ }
2223
+ function as(e) {
2224
+ for (const t of ["elm-drag-ghost-point", "elm-drag-ghost-line", "elm-drag-ghost-fill"])
2225
+ e.getLayer(t) && e.removeLayer(t);
2226
+ e.getSource("elm-drag-ghost") && e.removeSource("elm-drag-ghost");
2227
+ }
2228
+ const Qn = [
2229
+ ["elm-drag-ghost-fill", "fill-color", (e) => e[500]],
2230
+ ["elm-drag-ghost-line", "line-color", (e) => e[500]],
2231
+ ["elm-drag-ghost-point", "circle-color", (e) => e[500]]
2232
+ ];
2233
+ function us({ map: e }) {
2234
+ qe(e, Qn);
2235
+ const { dataStore: t, uiStore: n } = Le(), o = Ue(), r = he((a) => a.features), s = he((a) => a.selectedIds), i = W((a) => a.vertexEditActive), l = W((a) => a.transformActive), u = W((a) => a.editingMode), c = W((a) => a.readonly);
2236
+ K(() => {
2237
+ ct();
2238
+ }, [r.length, i]), K(() => {
2239
+ if (!i) return;
2240
+ const a = t.getState(), x = a.selectedIds.length === 1 ? a.features.find((m) => m.id === a.selectedIds[0]) : void 0, p = Co(x);
2241
+ p && o({ type: "warning", message: p });
2242
+ }, [i, t, o]);
2243
+ const v = $(!1);
2244
+ K(() => {
2245
+ if (!l || v.current) return;
2246
+ const a = t.getState(), x = a.selectedIds.length === 1 ? a.features.find((p) => p.id === a.selectedIds[0]) : void 0;
2247
+ (x == null ? void 0 : x._drawType) === "route" && (o({ type: "warning", message: "Transforming may break road alignment." }), v.current = !0);
2248
+ }, [l, s, t, o]);
2249
+ const d = $(null), g = $(null), [w, P] = le(null), [T, _] = le(null), [M, N] = le(null);
2250
+ K(() => {
2251
+ !i && M && N(null);
2252
+ }, [i, M]);
2253
+ const E = is(c), A = Jo();
2254
+ K(() => {
2255
+ if (c) return;
2256
+ const a = e.getCanvasContainer(), x = (p) => {
2257
+ var k, O;
2258
+ p.preventDefault();
2259
+ const m = a.getBoundingClientRect(), F = [p.clientX - m.left, p.clientY - m.top], S = $e(e, F, Be);
2260
+ if (S.length === 0) return;
2261
+ const L = String(S[0].id ?? ((k = S[0].properties) == null ? void 0 : k.id) ?? "");
2262
+ if (!L) return;
2263
+ const B = t.getState(), V = B.features.find((z) => z.id === L);
2264
+ if (!V) return;
2265
+ const j = B.selectedIds;
2266
+ j.length >= 2 && j.includes(L) || B.selectFeature(L);
2267
+ const h = V.geometry.type === "Point" && ((O = V.properties) == null ? void 0 : O._isText) !== "true";
2268
+ A.open(p.clientX, p.clientY, {
2269
+ feature: V,
2270
+ requestPreciseCoords: h ? () => _(L) : void 0
2271
+ });
2272
+ };
2273
+ return a.addEventListener("contextmenu", x), () => {
2274
+ a.removeEventListener("contextmenu", x);
2275
+ };
2276
+ }, [c, t, e, A]), K(() => {
2277
+ const a = u !== "none", x = (F = !0) => {
2278
+ bt(e, null, d.current), d.current = null, F && Pt(e, null), ct(), E.leave(a ? void 0 : "");
2279
+ }, p = (F) => {
2280
+ var V, j;
2281
+ if (e.dragPan.isActive() || (V = g.current) != null && V.dragging) return;
2282
+ const S = $e(e, F.point, Be), L = S.length > 0 ? String(S[0].id ?? ((j = S[0].properties) == null ? void 0 : j.id)) : null;
2283
+ if (L === d.current) return;
2284
+ if (!L) {
2285
+ x();
2286
+ return;
2287
+ }
2288
+ Gt() !== L && Pt(e, null), a || bt(e, L, d.current), d.current = L;
2289
+ const B = t.getState().features.find((h) => h.id === L);
2290
+ B ? Nr(B, n, F.originalEvent) : ct(), E.enter(e.getCanvas(), F.originalEvent, a ? void 0 : "pointer");
2291
+ };
2292
+ e.on("mousemove", p);
2293
+ const m = () => x();
2294
+ return e.on("mouseout", m), () => {
2295
+ e.off("mousemove", p), e.off("mouseout", m);
2296
+ try {
2297
+ x(!1);
2298
+ } catch {
2299
+ }
2300
+ };
2301
+ }, [u, e, t, n, E]);
2302
+ const D = $(r);
2303
+ K(() => {
2304
+ const a = D.current;
2305
+ if (D.current = r, r.length <= a.length) return;
2306
+ const p = e.getCanvas().getBoundingClientRect(), m = cs();
2307
+ if (m.x < p.left || m.x > p.right || m.y < p.top || m.y > p.bottom) return;
2308
+ const F = new Set(a.map((h) => h.id)), S = new Set(r.filter((h) => !F.has(h.id)).map((h) => h.id)), L = [m.x - p.left, m.y - p.top], B = () => {
2309
+ var h;
2310
+ try {
2311
+ const k = e.unproject(L), O = $e(e, e.project(k), Be)[0], z = O ? String(O.id ?? ((h = O.properties) == null ? void 0 : h.id)) : null;
2312
+ z && S.has(z) && Pt(e, z), e.fire("mousemove", {
2313
+ // A real Point: a plain { x, y } makes every listener's
2314
+ // queryRenderedFeatures(e.point) hit the whole viewport, so the
2315
+ // hover tooltip named whichever feature was on top (not under the cursor).
2316
+ // `map.project` returns the map's own Point class (a `new Point` from the
2317
+ // peer copy fails maplibre's instanceof check when the host bundles its own
2318
+ // maplibre, e.g. MapTiler SDK) and avoids a named import from CJS maplibre-gl.
2319
+ point: e.project(k),
2320
+ lngLat: k,
2321
+ originalEvent: new MouseEvent("mousemove", {
2322
+ clientX: m.x,
2323
+ clientY: m.y,
2324
+ ctrlKey: m.ctrlKey,
2325
+ metaKey: m.metaKey,
2326
+ altKey: m.altKey
2327
+ })
2328
+ });
2329
+ } catch {
2330
+ }
2331
+ };
2332
+ let V = !1;
2333
+ const j = () => {
2334
+ V || B();
2335
+ };
2336
+ return e.once("idle", j), () => {
2337
+ V = !0, e.off("idle", j);
2338
+ };
2339
+ }, [r.length, e]), K(() => {
2340
+ if (c || u !== "none") return;
2341
+ const a = (x) => {
2342
+ var L;
2343
+ if (Gn()) return;
2344
+ const p = $e(e, x.point, Be), m = t.getState();
2345
+ if (p.length === 0) {
2346
+ i ? n.getState().setVertexEditActive(!1) : m.clearSelection();
2347
+ return;
2348
+ }
2349
+ const F = p[0], S = String(F.id ?? ((L = F.properties) == null ? void 0 : L.id) ?? "");
2350
+ if (S)
2351
+ if (x.originalEvent.shiftKey) {
2352
+ const B = m.selectedIds;
2353
+ B.includes(S) ? m.setSelection(B.filter((V) => V !== S)) : m.setSelection([...B, S]);
2354
+ } else
2355
+ m.selectedIds.length === 1 && m.selectedIds[0] === S || m.selectFeature(S);
2356
+ };
2357
+ return e.on("click", a), () => {
2358
+ e.off("click", a);
2359
+ };
2360
+ }, [c, u, i, t, n, e]), K(() => {
2361
+ if (c || u !== "none") return;
2362
+ const a = (x) => {
2363
+ var S, L;
2364
+ const p = $e(e, x.point, Be);
2365
+ if (p.length === 0) return;
2366
+ x.preventDefault();
2367
+ const m = String(p[0].id ?? ((S = p[0].properties) == null ? void 0 : S.id) ?? "");
2368
+ if (!m) return;
2369
+ const F = t.getState().features.find((B) => B.id === m);
2370
+ if (F) {
2371
+ if (((L = F.properties) == null ? void 0 : L._isText) === "true") {
2372
+ t.getState().selectFeature(m), P(m);
2373
+ return;
2374
+ }
2375
+ if (t.getState().selectFeature(m), ht(F.geometry)) {
2376
+ const B = Dr(F.geometry, [x.lngLat.lng, x.lngLat.lat]);
2377
+ n.getState().setSelectedPartIndex(B);
2378
+ } else
2379
+ n.getState().setSelectedPartIndex(null);
2380
+ n.getState().setVertexEditActive(!0);
2381
+ }
2382
+ };
2383
+ return e.on("dblclick", a), () => {
2384
+ e.off("dblclick", a);
2385
+ };
2386
+ }, [c, u, t, n, e]), K(() => {
2387
+ if (c || i) return;
2388
+ const x = u !== "none", p = (m) => {
2389
+ var re;
2390
+ if (m.originalEvent.shiftKey) return;
2391
+ const F = m.originalEvent.altKey, S = m.originalEvent.ctrlKey || m.originalEvent.metaKey;
2392
+ if (x && !F && !S) return;
2393
+ const L = $e(e, m.point, Be);
2394
+ if (L.length === 0) return;
2395
+ const B = String(L[0].id ?? ((re = L[0].properties) == null ? void 0 : re.id) ?? "");
2396
+ if (!B) return;
2397
+ const V = t.getState();
2398
+ if (V.selectedIds.includes(B) && V.selectedIds.length >= 2 && !F && !S) return;
2399
+ V.selectedIds.includes(B) || V.selectFeature(B);
2400
+ const h = t.getState().selectedIds, k = h.includes(B) ? h : [B], O = new Map(
2401
+ k.flatMap((J) => {
2402
+ const ce = V.features.find((U) => U.id === J);
2403
+ return ce ? [[J, ce.geometry]] : [];
2404
+ })
2405
+ ), z = F, G = V.geometryMode, H = [m.lngLat.lng, m.lngLat.lat], te = G === "visual" ? me(H) : H;
2406
+ e.dragPan.disable(), g.current = {
2407
+ featureIds: k,
2408
+ startLngLat: H,
2409
+ startProjected: te,
2410
+ geometryMode: G,
2411
+ startCoords: O,
2412
+ dragging: !1,
2413
+ duplicate: z
2414
+ };
2415
+ const Z = /* @__PURE__ */ new Map(), ne = ze((J, ce) => {
2416
+ const U = g.current;
2417
+ if (!U) return;
2418
+ const Y = J - U.startLngLat[0], ee = ce - U.startLngLat[1];
2419
+ let oe;
2420
+ if (U.geometryMode === "visual") {
2421
+ const Q = [U.startLngLat[0] + Y, U.startLngLat[1] + ee], de = me(Q);
2422
+ oe = [de[0] - U.startProjected[0], de[1] - U.startProjected[1]];
2423
+ } else
2424
+ oe = [Y, ee];
2425
+ for (const Q of U.featureIds) {
2426
+ const de = U.startCoords.get(Q);
2427
+ de && Z.set(Q, $t(de, oe, U.geometryMode === "visual"));
2428
+ }
2429
+ if (U.duplicate) {
2430
+ const Q = e.getSource("elm-drag-ghost");
2431
+ if (Q) {
2432
+ const de = t.getState(), ue = [];
2433
+ for (const Re of U.featureIds) {
2434
+ const xe = de.features.find((Je) => Je.id === Re), Ee = Z.get(Re);
2435
+ xe && Ee && ue.push({
2436
+ type: "Feature",
2437
+ properties: {},
2438
+ geometry: Ee
2439
+ });
2440
+ }
2441
+ try {
2442
+ Q.setData({ type: "FeatureCollection", features: ue });
2443
+ } catch {
2444
+ }
2445
+ }
2446
+ } else
2447
+ Vt(e, Z);
2448
+ }), se = (J) => {
2449
+ const ce = g.current;
2450
+ if (!ce) return;
2451
+ const U = J.lngLat.lng - ce.startLngLat[0], Y = J.lngLat.lat - ce.startLngLat[1], ee = Math.hypot(U, Y);
2452
+ !ce.dragging && ee < 1e-5 || (ce.dragging || (ce.dragging = !0, e.getCanvas().style.cursor = "grabbing", Ce(!0)), ne.schedule(J.lngLat.lng, J.lngLat.lat));
2453
+ }, ie = () => {
2454
+ ne.flush();
2455
+ const J = g.current;
2456
+ if (g.current = null, e.dragPan.enable(), J != null && J.dragging) {
2457
+ const ce = Ge(n.getState().editingMode);
2458
+ if (E.leave(ce), e.getCanvas().style.cursor = ce, bt(e, null, d.current), d.current = null, Ce(!1), Mr(), t.getState().takeSnapshot(), J.duplicate) {
2459
+ const U = [];
2460
+ for (const ee of J.featureIds) {
2461
+ const oe = Z.get(ee);
2462
+ oe && U.push({ sourceId: ee, geometry: oe });
2463
+ }
2464
+ t.getState().duplicateFeaturesAtPosition(U);
2465
+ const Y = e.getSource("elm-drag-ghost");
2466
+ Y == null || Y.setData({ type: "FeatureCollection", features: [] });
2467
+ } else
2468
+ t.getState().updateFeatures(J.featureIds.flatMap((U) => {
2469
+ const Y = Z.get(U);
2470
+ return Y ? [{ id: U, patch: { geometry: Y } }] : [];
2471
+ }));
2472
+ }
2473
+ e.off("mousemove", se), e.off("mouseup", ie);
2474
+ };
2475
+ e.on("mousemove", se), e.on("mouseup", ie);
2476
+ };
2477
+ return e.on("mousedown", p), () => {
2478
+ e.off("mousedown", p);
2479
+ };
2480
+ }, [c, u, i, t, n, e, E]);
2481
+ const q = s.length === 1 ? r.find((a) => a.id === s[0]) ?? null : null, y = r.filter((a) => s.includes(a.id)), f = A.state && /* @__PURE__ */ X(
2482
+ Bo,
2483
+ {
2484
+ x: A.state.x,
2485
+ y: A.state.y,
2486
+ data: A.state.data,
2487
+ onClose: A.close
2488
+ }
2489
+ ), b = w ? r.find((a) => a.id === w) ?? null : null, C = b && /* @__PURE__ */ X(
2490
+ ts,
2491
+ {
2492
+ map: e,
2493
+ feature: b,
2494
+ onDone: () => P(null)
2495
+ }
2496
+ ), R = T ? r.find((a) => a.id === T) ?? null : null, I = R && R.geometry.type === "Point" && /* @__PURE__ */ X(
2497
+ Un,
2498
+ {
2499
+ map: e,
2500
+ coords: R.geometry.coordinates,
2501
+ onSave: (a) => {
2502
+ t.getState().takeSnapshot(), t.getState().updateFeature(R.id, { geometry: { type: "Point", coordinates: Ve(R.geometry.coordinates, a) } });
2503
+ },
2504
+ onClose: () => _(null)
2505
+ }
2506
+ );
2507
+ return c || u !== "none" ? /* @__PURE__ */ fe(lt, { children: [
2508
+ f,
2509
+ C,
2510
+ I
2511
+ ] }) : /* @__PURE__ */ fe(lt, { children: [
2512
+ i && q && /* @__PURE__ */ X(
2513
+ $r,
2514
+ {
2515
+ map: e,
2516
+ feature: q,
2517
+ initialSelectedIndices: M ?? void 0
2518
+ }
2519
+ ),
2520
+ /* @__PURE__ */ X(
2521
+ rs,
2522
+ {
2523
+ map: e,
2524
+ onVertexBoxSelect: (a, x) => {
2525
+ if (i && s.length === 1 && s[0] === a) {
2526
+ N(x);
2527
+ return;
2528
+ }
2529
+ t.getState().selectFeature(a), n.getState().setSelectedPartIndex(null), N(x), n.getState().setVertexEditActive(!0);
2530
+ }
2531
+ }
2532
+ ),
2533
+ l && !i && y.length >= 1 && /* @__PURE__ */ X(es, { map: e, features: y }),
2534
+ f,
2535
+ C,
2536
+ I
2537
+ ] });
2538
+ }
2539
+ const Me = "elm-snap", eo = [
2540
+ ["elm-snap-vertex", "circle-color", (e) => e[500]]
2541
+ ];
2542
+ function ds(e) {
2543
+ e.getSource(Me) || (e.addSource(Me, { type: "geojson", data: Ie() }), e.addLayer({
2544
+ id: "elm-snap-vertex",
2545
+ type: "circle",
2546
+ source: Me,
2547
+ filter: ["==", ["get", "_kind"], "vertex"],
2548
+ paint: {
2549
+ "circle-radius": 6,
2550
+ "circle-stroke-width": 2,
2551
+ "circle-stroke-color": "#ffffff"
2552
+ }
2553
+ }), e.addLayer({
2554
+ id: "elm-snap-edge",
2555
+ type: "symbol",
2556
+ source: Me,
2557
+ filter: ["==", ["get", "_kind"], "edge"],
2558
+ layout: {
2559
+ "icon-image": "elm-snap-diamond",
2560
+ "icon-size": 1,
2561
+ "icon-allow-overlap": !0,
2562
+ "icon-ignore-placement": !0
2563
+ }
2564
+ }), Ne(e, eo));
2565
+ }
2566
+ function fs(e) {
2567
+ for (const t of ["elm-snap-edge", "elm-snap-vertex"])
2568
+ e.getLayer(t) && e.removeLayer(t);
2569
+ e.getSource(Me) && e.removeSource(Me);
2570
+ }
2571
+ const bn = /* @__PURE__ */ new WeakMap();
2572
+ function to(e, t) {
2573
+ const n = e.hasImage("elm-snap-diamond");
2574
+ if (n && bn.get(e) === t) return;
2575
+ const o = 16, r = document.createElement("canvas");
2576
+ r.width = o, r.height = o;
2577
+ const s = r.getContext("2d");
2578
+ if (!s) return;
2579
+ s.clearRect(0, 0, o, o), s.save(), s.translate(o / 2, o / 2), s.rotate(Math.PI / 4), s.fillStyle = t, s.strokeStyle = "#ffffff", s.lineWidth = 2;
2580
+ const i = 8;
2581
+ s.fillRect(-i / 2, -i / 2, i, i), s.strokeRect(-i / 2, -i / 2, i, i), s.restore();
2582
+ const l = s.getImageData(0, 0, o, o);
2583
+ n ? e.updateImage("elm-snap-diamond", l) : e.addImage("elm-snap-diamond", l), bn.set(e, t);
2584
+ }
2585
+ function gs({ map: e }) {
2586
+ const { uiStore: t, dataStore: n } = Le(), o = W((u) => u.editingMode), r = W((u) => u.snapEnabled), s = he((u) => u.features), i = W((u) => u.vertexEditActive), l = qe(e, eo);
2587
+ return K(() => {
2588
+ to(e, l[400]);
2589
+ const u = o !== "none" || i, c = () => {
2590
+ t.getState().snappedCoord && t.getState().setSnappedCoord(null);
2591
+ const T = e.getSource(Me);
2592
+ T == null || T.setData(Ie());
2593
+ };
2594
+ if (!u) {
2595
+ c();
2596
+ return;
2597
+ }
2598
+ const d = ze((T) => {
2599
+ var D;
2600
+ if (!r) {
2601
+ c();
2602
+ return;
2603
+ }
2604
+ const _ = T.originalEvent;
2605
+ if (_.metaKey || _.ctrlKey) {
2606
+ c();
2607
+ return;
2608
+ }
2609
+ const M = _.target;
2610
+ if ((D = M == null ? void 0 : M.closest) != null && D.call(M, ".elm-midpoint-marker")) {
2611
+ c();
2612
+ return;
2613
+ }
2614
+ const N = Gt(), E = Vn(T.lngLat.lng, T.lngLat.lat, e, s, 15, new Set(N ? [N] : []));
2615
+ if (!E) {
2616
+ c();
2617
+ return;
2618
+ }
2619
+ if (i && E.isVertex) {
2620
+ const q = new Set(n.getState().selectedIds);
2621
+ if (E.featureId && q.has(E.featureId)) {
2622
+ c();
2623
+ return;
2624
+ }
2625
+ }
2626
+ t.getState().setSnappedCoord(E.lnglat);
2627
+ const A = e.getSource(Me);
2628
+ A == null || A.setData({
2629
+ type: "FeatureCollection",
2630
+ features: [{
2631
+ type: "Feature",
2632
+ properties: { _kind: E.isVertex ? "vertex" : "edge" },
2633
+ geometry: { type: "Point", coordinates: E.lnglat }
2634
+ }]
2635
+ });
2636
+ }), g = (T) => d.schedule(T), w = () => d.flush(), P = () => {
2637
+ d.cancel(), c();
2638
+ };
2639
+ return e.on("mousemove", g), e.on("mouseout", P), window.addEventListener("pointerdown", w, !0), window.addEventListener("pointerup", w, !0), () => {
2640
+ d.cancel(), e.off("mousemove", g), e.off("mouseout", P), window.removeEventListener("pointerdown", w, !0), window.removeEventListener("pointerup", w, !0);
2641
+ };
2642
+ }, [o, r, s, i, e, t, n, l]), null;
2643
+ }
2644
+ function ci({ map: e }) {
2645
+ const t = he((n) => n.features);
2646
+ return K(() => {
2647
+ if (t.length === 0) return;
2648
+ let n = 1 / 0, o = 1 / 0, r = -1 / 0, s = -1 / 0;
2649
+ for (const i of t) {
2650
+ const [l, u, c, v] = i.bbox || Nn(i.geometry);
2651
+ l < n && (n = l), u < o && (o = u), c > r && (r = c), v > s && (s = v);
2652
+ }
2653
+ n !== 1 / 0 && e.fitBounds([[n, o], [r, s]], { padding: jt(e.getContainer()), maxZoom: 16, duration: 600 });
2654
+ }, []), null;
2655
+ }
2656
+ function ys({ map: e }) {
2657
+ const t = W((o) => o.boundaryAutofitBbox), n = W((o) => o.setBoundaryAutofitBbox);
2658
+ return K(() => {
2659
+ if (!t) return;
2660
+ const [o, r, s, i] = t;
2661
+ e.fitBounds([[s, o], [i, r]], { padding: jt(e.getContainer()), maxZoom: 10, duration: 1 }), n(null);
2662
+ }, [t, n, e]), null;
2663
+ }
2664
+ const be = "elm-processing-preview", no = [
2665
+ ["elm-processing-preview-fill", "fill-color", (e) => e[500]],
2666
+ ["elm-processing-preview-line", "line-color", (e) => e[500]]
2667
+ ];
2668
+ function ps(e) {
2669
+ e.getSource(be) || (e.addSource(be, { type: "geojson", data: Ie() }), e.addLayer({
2670
+ id: "elm-processing-preview-ghost",
2671
+ type: "fill",
2672
+ source: be,
2673
+ filter: ["==", ["get", "_ghost"], !0],
2674
+ paint: {
2675
+ "fill-color": "#6b7280",
2676
+ "fill-opacity": 0.07
2677
+ }
2678
+ }), e.addLayer({
2679
+ id: "elm-processing-preview-ghost-line",
2680
+ type: "line",
2681
+ source: be,
2682
+ filter: ["==", ["get", "_ghost"], !0],
2683
+ paint: {
2684
+ "line-color": "#6b7280",
2685
+ "line-opacity": 0.35,
2686
+ "line-width": 1.5,
2687
+ "line-dasharray": [4, 4]
2688
+ }
2689
+ }), e.addLayer({
2690
+ id: "elm-processing-preview-fill",
2691
+ type: "fill",
2692
+ source: be,
2693
+ filter: ["!=", ["get", "_ghost"], !0],
2694
+ paint: {
2695
+ "fill-opacity": [
2696
+ "case",
2697
+ ["boolean", ["get", "_bufferNew"], !1],
2698
+ 0.12,
2699
+ 0.2
2700
+ ]
2701
+ }
2702
+ }), e.addLayer({
2703
+ id: "elm-processing-preview-line",
2704
+ type: "line",
2705
+ source: be,
2706
+ filter: ["!=", ["get", "_ghost"], !0],
2707
+ paint: {
2708
+ "line-width": [
2709
+ "case",
2710
+ ["boolean", ["get", "_bufferNew"], !1],
2711
+ 2,
2712
+ 2.5
2713
+ ],
2714
+ "line-dasharray": [
2715
+ "case",
2716
+ ["boolean", ["get", "_bufferNew"], !1],
2717
+ ["literal", [8, 5]],
2718
+ ["literal", [1, 0]]
2719
+ ]
2720
+ }
2721
+ }), Ne(e, no));
2722
+ }
2723
+ function hs(e) {
2724
+ for (const t of [
2725
+ "elm-processing-preview-line",
2726
+ "elm-processing-preview-fill",
2727
+ "elm-processing-preview-ghost-line",
2728
+ "elm-processing-preview-ghost"
2729
+ ])
2730
+ e.getLayer(t) && e.removeLayer(t);
2731
+ e.getSource(be) && e.removeSource(be);
2732
+ }
2733
+ function Ln(e, t) {
2734
+ return { type: "Feature", properties: t, geometry: e };
2735
+ }
2736
+ function ms({ map: e }) {
2737
+ qe(e, no);
2738
+ const t = vt(), n = W((l) => l.editingMode), o = W((l) => l.geometryPreview), r = W((l) => l.bufferCreateNew), s = he((l) => l.selectedIds[0] ?? null), i = he((l) => {
2739
+ var u;
2740
+ return s ? ((u = l.features.find((c) => c.id === s)) == null ? void 0 : u.geometry) ?? null : null;
2741
+ });
2742
+ return K(() => {
2743
+ const l = e.getSource(be);
2744
+ if (!l) return;
2745
+ if (!(n === "simplify-shape" || n === "smooth-shape" || n === "buffer-shape") || !o) {
2746
+ l.setData({ type: "FeatureCollection", features: [] });
2747
+ return;
2748
+ }
2749
+ if (!_t(o.type)) {
2750
+ l.setData({ type: "FeatureCollection", features: [] });
2751
+ return;
2752
+ }
2753
+ const c = n === "buffer-shape", v = c && !r && i && _t(i.type), d = [];
2754
+ v && d.push(Ln(i, { _ghost: !0 })), d.push(
2755
+ Ln(o, {
2756
+ _bufferNew: c && r
2757
+ })
2758
+ ), l.setData({ type: "FeatureCollection", features: d });
2759
+ }, [n, o, r, i, e, t]), null;
2760
+ }
2761
+ function oo(e, t, n) {
2762
+ const [o, r] = le(null), [s, i] = le(t);
2763
+ return s !== t && (i(t), r(null)), K(() => {
2764
+ const l = (c) => {
2765
+ n && r([c.lngLat.lng, c.lngLat.lat]);
2766
+ }, u = () => r(null);
2767
+ return e.on("mousemove", l), e.on("mouseout", u), () => {
2768
+ e.off("mousemove", l), e.off("mouseout", u);
2769
+ };
2770
+ }, [e, n]), o;
2771
+ }
2772
+ const we = "#e74c3c", En = "#ff2d1a", Pn = "#c0392b", ye = "elm-measure-preview", Rt = [
2773
+ "elm-measure-hit-line",
2774
+ "elm-measure-hit-fill"
2775
+ ];
2776
+ function vs(e) {
2777
+ e.getSource(ye) || (e.addSource(ye, { type: "geojson", data: Ie() }), e.addLayer({
2778
+ id: "elm-measure-area-fill",
2779
+ type: "fill",
2780
+ source: ye,
2781
+ filter: ["all", ["==", ["get", "_kind"], "area"], ["==", ["geometry-type"], "Polygon"]],
2782
+ paint: {
2783
+ "fill-color": [
2784
+ "case",
2785
+ ["boolean", ["get", "_selected"], !1],
2786
+ Pn,
2787
+ ["boolean", ["get", "_hovered"], !1],
2788
+ En,
2789
+ we
2790
+ ],
2791
+ "fill-opacity": [
2792
+ "case",
2793
+ ["boolean", ["get", "_selected"], !1],
2794
+ 0.15,
2795
+ ["boolean", ["get", "_hovered"], !1],
2796
+ 0.12,
2797
+ 0.08
2798
+ ]
2799
+ }
2800
+ }), e.addLayer({
2801
+ id: "elm-measure-live-area",
2802
+ type: "fill",
2803
+ source: ye,
2804
+ filter: ["all", ["==", ["get", "_kind"], "live-area"], ["==", ["geometry-type"], "Polygon"]],
2805
+ paint: { "fill-color": we, "fill-opacity": 0.08 }
2806
+ }), e.addLayer({
2807
+ id: "elm-measure-line",
2808
+ type: "line",
2809
+ source: ye,
2810
+ filter: [
2811
+ "all",
2812
+ ["in", ["get", "_kind"], ["literal", ["segment", "live-line", "live-perimeter", "live-area"]]],
2813
+ ["==", ["geometry-type"], "LineString"]
2814
+ ],
2815
+ paint: {
2816
+ "line-color": [
2817
+ "case",
2818
+ ["boolean", ["get", "_selected"], !1],
2819
+ Pn,
2820
+ ["boolean", ["get", "_hovered"], !1],
2821
+ En,
2822
+ we
2823
+ ],
2824
+ "line-width": 3,
2825
+ "line-opacity": [
2826
+ "case",
2827
+ ["boolean", ["get", "_selected"], !1],
2828
+ 1,
2829
+ ["boolean", ["get", "_hovered"], !1],
2830
+ 1,
2831
+ 0.9
2832
+ ],
2833
+ // MapLibre dash values are MULTIPLES of line-width (not pixels). At
2834
+ // line-width 3, [10, 6] would render as 30px dash / 18px gap — way
2835
+ // longer than Leaflet's pixel-based "10 6". Divide by 3 to match.
2836
+ "line-dasharray": [3.33, 2]
2837
+ }
2838
+ }), e.addLayer({
2839
+ id: "elm-measure-ghost",
2840
+ type: "line",
2841
+ source: ye,
2842
+ filter: ["==", ["get", "_kind"], "ghost"],
2843
+ paint: {
2844
+ "line-color": we,
2845
+ "line-width": 3,
2846
+ "line-opacity": 0.45,
2847
+ // MapLibre dash values are MULTIPLES of line-width (not pixels). At
2848
+ // line-width 3, [10, 6] would render as 30px dash / 18px gap — way
2849
+ // longer than Leaflet's pixel-based "10 6". Divide by 3 to match.
2850
+ "line-dasharray": [3.33, 2]
2851
+ }
2852
+ }), e.addLayer({
2853
+ id: "elm-measure-close-hint",
2854
+ type: "line",
2855
+ source: ye,
2856
+ filter: ["==", ["get", "_kind"], "close-hint"],
2857
+ paint: {
2858
+ "line-color": we,
2859
+ "line-width": 2,
2860
+ "line-opacity": 0.25,
2861
+ // line-width is 2 here; pixel-equivalent of leaflet's "6 6" → [3, 3].
2862
+ "line-dasharray": [3, 3]
2863
+ }
2864
+ }), e.addLayer({
2865
+ id: "elm-measure-hit-line",
2866
+ type: "line",
2867
+ source: ye,
2868
+ filter: ["==", ["get", "_kind"], "segment"],
2869
+ paint: {
2870
+ "line-color": we,
2871
+ "line-width": 16,
2872
+ "line-opacity": 0
2873
+ }
2874
+ }), e.addLayer({
2875
+ id: "elm-measure-hit-fill",
2876
+ type: "fill",
2877
+ source: ye,
2878
+ filter: ["all", ["==", ["get", "_kind"], "area"], ["==", ["geometry-type"], "Polygon"]],
2879
+ paint: { "fill-color": we, "fill-opacity": 0 }
2880
+ }), e.addLayer({
2881
+ id: "elm-measure-vertex",
2882
+ type: "circle",
2883
+ source: ye,
2884
+ filter: [
2885
+ "all",
2886
+ ["==", ["geometry-type"], "Point"],
2887
+ ["!=", ["get", "_isFirst"], !0]
2888
+ ],
2889
+ paint: {
2890
+ "circle-radius": 5,
2891
+ "circle-color": we,
2892
+ "circle-stroke-width": 2,
2893
+ "circle-stroke-color": "#ffffff"
2894
+ }
2895
+ }), e.addLayer({
2896
+ id: "elm-measure-first-vertex",
2897
+ type: "circle",
2898
+ source: ye,
2899
+ filter: [
2900
+ "all",
2901
+ ["==", ["geometry-type"], "Point"],
2902
+ ["==", ["get", "_isFirst"], !0]
2903
+ ],
2904
+ paint: {
2905
+ "circle-radius": 5,
2906
+ "circle-color": "#ffffff",
2907
+ "circle-stroke-width": 2.5,
2908
+ "circle-stroke-color": we
2909
+ }
2910
+ }));
2911
+ }
2912
+ function xs(e) {
2913
+ for (const t of [
2914
+ "elm-measure-first-vertex",
2915
+ "elm-measure-vertex",
2916
+ "elm-measure-hit-fill",
2917
+ "elm-measure-hit-line",
2918
+ "elm-measure-close-hint",
2919
+ "elm-measure-ghost",
2920
+ "elm-measure-line",
2921
+ "elm-measure-live-area",
2922
+ "elm-measure-area-fill"
2923
+ ])
2924
+ e.getLayer(t) && e.removeLayer(t);
2925
+ e.getSource(ye) && e.removeSource(ye);
2926
+ }
2927
+ function ws(e, t) {
2928
+ const n = e.getSource(ye);
2929
+ n && n.setData({ type: "FeatureCollection", features: t });
2930
+ }
2931
+ let pe = null;
2932
+ function Ss(e, t, n) {
2933
+ pe || (pe = document.createElement("div"), pe.className = "elm-feature-tooltip", pe.style.cssText = "position:fixed;pointer-events:none;z-index:10000;transform:translate(-50%,-100%);margin-top:-12px", document.body.appendChild(pe)), pe.textContent = e, ro(t, n);
2934
+ }
2935
+ function ro(e, t) {
2936
+ pe && (pe.style.left = e + "px", pe.style.top = t + "px");
2937
+ }
2938
+ function Cn() {
2939
+ pe == null || pe.remove(), pe = null;
2940
+ }
2941
+ function bs(e, t, n, o) {
2942
+ try {
2943
+ if (t === "distance" && e.length >= 2) return mt(_e(We(e)) * 1e3, n);
2944
+ if (t === "area" && e.length >= 3) return Ht(dt(ut([[...e, e[0]]])), o);
2945
+ } catch {
2946
+ }
2947
+ return null;
2948
+ }
2949
+ function so({
2950
+ map: e,
2951
+ position: t,
2952
+ parts: n,
2953
+ onRemove: o
2954
+ }) {
2955
+ const r = $(null), [s] = le(() => document.createElement("div"));
2956
+ return K(() => {
2957
+ const i = new De.Marker({
2958
+ element: s,
2959
+ // 'left' anchor → the host's LEFT edge sits on the latlng. Combined
2960
+ // with the offset, the pill begins 12px right of the underlying point.
2961
+ anchor: "left",
2962
+ offset: [12, 0]
2963
+ }).setLngLat(t).addTo(e);
2964
+ return r.current = i, () => {
2965
+ i.remove(), r.current = null;
2966
+ };
2967
+ }, [e, s]), K(() => {
2968
+ var i;
2969
+ (i = r.current) == null || i.setLngLat(t);
2970
+ }, [t[0], t[1]]), Ze(
2971
+ /* @__PURE__ */ fe(
2972
+ "div",
2973
+ {
2974
+ className: "elm-measure-label",
2975
+ style: {
2976
+ display: "inline-flex",
2977
+ alignItems: "center",
2978
+ gap: 7,
2979
+ pointerEvents: o ? "auto" : "none",
2980
+ userSelect: "none",
2981
+ whiteSpace: "nowrap"
2982
+ },
2983
+ children: [
2984
+ /* @__PURE__ */ fe("span", { children: [
2985
+ /* @__PURE__ */ X("span", { style: { fontWeight: 600 }, children: n.value }),
2986
+ /* @__PURE__ */ fe("span", { style: { fontWeight: 400, opacity: 0.85 }, children: [
2987
+ " ",
2988
+ n.unit
2989
+ ] })
2990
+ ] }),
2991
+ o && /* @__PURE__ */ X(
2992
+ "button",
2993
+ {
2994
+ className: "elm-measure-close",
2995
+ onClick: (i) => {
2996
+ i.stopPropagation(), o();
2997
+ },
2998
+ title: "Clear measurement",
2999
+ style: { marginRight: "-5px" },
3000
+ children: /* @__PURE__ */ fe("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: [
3001
+ /* @__PURE__ */ X("line", { x1: "1.5", y1: "1.5", x2: "8.5", y2: "8.5" }),
3002
+ /* @__PURE__ */ X("line", { x1: "8.5", y1: "1.5", x2: "1.5", y2: "8.5" })
3003
+ ] })
3004
+ }
3005
+ )
3006
+ ]
3007
+ }
3008
+ ),
3009
+ s
3010
+ );
3011
+ }
3012
+ const Ls = ao(function({
3013
+ map: t,
3014
+ m: n
3015
+ }) {
3016
+ const o = W((c) => c.removeMeasurement), { units: r } = ke(), s = { unit: r.length, display: r.display, precision: r.precision }, i = { unit: r.area, display: r.display, precision: r.precision }, l = Bt(() => {
3017
+ try {
3018
+ if (n.mode === "distance" && n.points.length >= 2)
3019
+ return mt(_e(We(n.points)) * 1e3, s);
3020
+ if (n.mode === "area" && n.points.length >= 3)
3021
+ return Ht(dt(ut([n.points])), i);
3022
+ } catch {
3023
+ }
3024
+ return null;
3025
+ }, [n, s.unit, s.display, s.precision, i.unit, i.display, i.precision]), u = n.mode === "area" ? n.points[n.points.length - 2] : n.points[n.points.length - 1];
3026
+ return !l || !u ? null : /* @__PURE__ */ X(
3027
+ so,
3028
+ {
3029
+ map: t,
3030
+ position: u,
3031
+ parts: l,
3032
+ onRemove: () => o(n.id)
3033
+ }
3034
+ );
3035
+ });
3036
+ function Es({ map: e }) {
3037
+ const t = vt(), n = W((y) => y.editingMode), o = W((y) => y.measurePoints), r = W((y) => y.measureMode), s = W((y) => y.completedMeasurements), i = W((y) => y.selectedMeasurementId), l = W((y) => y.snappedCoord), u = W((y) => y.toggleMeasurementSelection), c = W((y) => y.setSelectedMeasurementId), v = oo(e, n, n === "measure"), { units: d } = ke(), g = { unit: d.length, display: d.display, precision: d.precision }, w = { unit: d.area, display: d.display, precision: d.precision }, [P, T] = le(null), _ = n === "measure", M = _ ? l ?? v : null, N = o.length > 0 ? o[o.length - 1] : null;
3038
+ K(() => {
3039
+ const y = [];
3040
+ for (const f of s) {
3041
+ const b = P === f.id, C = i === f.id;
3042
+ if (f.mode === "distance") {
3043
+ for (let I = 0; I < f.points.length - 1; I++)
3044
+ y.push({
3045
+ type: "Feature",
3046
+ properties: { _kind: "segment", _id: f.id, _segIdx: I, _hovered: b, _selected: C },
3047
+ geometry: { type: "LineString", coordinates: [f.points[I], f.points[I + 1]] }
3048
+ });
3049
+ f.points.forEach((I, a) => {
3050
+ y.push({
3051
+ type: "Feature",
3052
+ properties: { _kind: "dot", _id: f.id, _isFirst: a === 0 },
3053
+ geometry: { type: "Point", coordinates: I }
3054
+ });
3055
+ });
3056
+ } else
3057
+ y.push({
3058
+ type: "Feature",
3059
+ properties: { _kind: "area", _id: f.id, _hovered: b, _selected: C },
3060
+ geometry: { type: "Polygon", coordinates: [f.points] }
3061
+ }), y.push({
3062
+ type: "Feature",
3063
+ properties: { _kind: "segment", _id: f.id, _hovered: b, _selected: C },
3064
+ geometry: { type: "LineString", coordinates: f.points }
3065
+ }), f.points.slice(0, -1).forEach((I, a) => {
3066
+ y.push({
3067
+ type: "Feature",
3068
+ properties: { _kind: "dot", _id: f.id, _isFirst: a === 0 },
3069
+ geometry: { type: "Point", coordinates: I }
3070
+ });
3071
+ });
3072
+ }
3073
+ _ && o.length >= 2 && y.push({
3074
+ type: "Feature",
3075
+ properties: { _kind: "live-line" },
3076
+ geometry: { type: "LineString", coordinates: o }
3077
+ }), _ && r === "area" && o.length >= 3 && y.push({
3078
+ type: "Feature",
3079
+ properties: { _kind: "live-area" },
3080
+ geometry: { type: "Polygon", coordinates: [[...o, o[0]]] }
3081
+ }), _ && M && N && y.push({
3082
+ type: "Feature",
3083
+ properties: { _kind: "ghost" },
3084
+ geometry: { type: "LineString", coordinates: [N, M] }
3085
+ }), _ && r === "area" && M && o.length >= 2 && y.push({
3086
+ type: "Feature",
3087
+ properties: { _kind: "close-hint" },
3088
+ geometry: { type: "LineString", coordinates: [M, o[0]] }
3089
+ }), _ && o.forEach((f, b) => {
3090
+ y.push({
3091
+ type: "Feature",
3092
+ properties: { _kind: "live-dot", _isFirst: b === 0 },
3093
+ geometry: { type: "Point", coordinates: f }
3094
+ });
3095
+ }), ws(e, y);
3096
+ }, [
3097
+ e,
3098
+ _,
3099
+ o,
3100
+ r,
3101
+ s,
3102
+ P,
3103
+ i,
3104
+ M,
3105
+ N,
3106
+ t
3107
+ ]), K(() => {
3108
+ const y = (I) => {
3109
+ var p, m;
3110
+ const a = (p = I.features) == null ? void 0 : p[0];
3111
+ if (!a) return;
3112
+ const x = (m = a.properties) == null ? void 0 : m._id;
3113
+ x && (Pr(), I.originalEvent.stopPropagation(), u(x));
3114
+ }, f = (I) => {
3115
+ var F, S, L, B;
3116
+ const a = (F = I.features) == null ? void 0 : F[0];
3117
+ if (!a) return;
3118
+ const x = (S = a.properties) == null ? void 0 : S._id;
3119
+ if (!x) return;
3120
+ T(x);
3121
+ const p = (L = a.properties) == null ? void 0 : L._kind, m = (B = a.properties) == null ? void 0 : B._segIdx;
3122
+ if (p === "segment" && typeof m == "number") {
3123
+ const V = s.find((j) => j.id === x);
3124
+ if (V && V.mode === "distance") {
3125
+ const j = V.points[m], h = V.points[m + 1];
3126
+ if (j && h) {
3127
+ const k = mt(_e(We([j, h])) * 1e3, g);
3128
+ Ss(`${k.value} ${k.unit}`, I.originalEvent.clientX, I.originalEvent.clientY);
3129
+ }
3130
+ }
3131
+ }
3132
+ }, b = (I) => {
3133
+ var p, m;
3134
+ const a = (p = I.features) == null ? void 0 : p[0];
3135
+ if (!a) return;
3136
+ ((m = a.properties) == null ? void 0 : m._kind) === "segment" && ro(I.originalEvent.clientX, I.originalEvent.clientY);
3137
+ }, C = () => {
3138
+ T(null), Cn();
3139
+ }, R = (I) => {
3140
+ try {
3141
+ e.queryRenderedFeatures(I.point, { layers: Rt }).length === 0 && c(null);
3142
+ } catch {
3143
+ }
3144
+ };
3145
+ for (const I of Rt)
3146
+ e.on("click", I, y), e.on("mouseenter", I, f), e.on("mousemove", I, b), e.on("mouseleave", I, C);
3147
+ return e.on("click", R), () => {
3148
+ for (const I of Rt)
3149
+ e.off("click", I, y), e.off("mouseenter", I, f), e.off("mousemove", I, b), e.off("mouseleave", I, C);
3150
+ e.off("click", R), Cn();
3151
+ };
3152
+ }, [e, u, c, s, g.unit, g.display, g.precision]);
3153
+ const E = r === "distance" ? 1 : 2, A = M && o.length >= E ? [...o, M] : o, D = bs(A, r, g, w), q = M ?? N;
3154
+ return /* @__PURE__ */ fe(lt, { children: [
3155
+ s.map((y) => /* @__PURE__ */ X(Ls, { map: e, m: y }, y.id)),
3156
+ D && q && /* @__PURE__ */ X(so, { map: e, position: q, parts: D })
3157
+ ] });
3158
+ }
3159
+ const Ae = "elm-osm-trace";
3160
+ let Mn = !1;
3161
+ function Ps() {
3162
+ if (Mn) return;
3163
+ const e = document.createElement("style");
3164
+ e.textContent = `
3165
+ @keyframes elm-osm-pulse {
3166
+ 0% { transform: scale(0.6); opacity: 0.7; }
3167
+ 100% { transform: scale(3); opacity: 0; }
3168
+ }
3169
+ @keyframes elm-osm-spin {
3170
+ to { transform: rotate(360deg); }
3171
+ }
3172
+ .elm-osm-pulse-ring {
3173
+ width: 64px; height: 64px; border-radius: 50%;
3174
+ background: color-mix(in srgb, var(--color-primary-500) 20%, transparent);
3175
+ animation: elm-osm-pulse 1.4s ease-out infinite;
3176
+ pointer-events: none;
3177
+ }
3178
+ .elm-osm-spinner {
3179
+ width: 24px; height: 24px; border-radius: 50%;
3180
+ border: 4px solid color-mix(in srgb, var(--color-primary-500) 20%, transparent);
3181
+ border-top-color: var(--color-primary-500);
3182
+ animation: elm-osm-spin 0.8s linear infinite;
3183
+ pointer-events: none;
3184
+ }
3185
+ `, document.head.appendChild(e), Mn = !0;
3186
+ }
3187
+ function Cs(e) {
3188
+ e.getSource(Ae) || (e.addSource(Ae, { type: "geojson", data: Ie() }), e.addLayer({
3189
+ id: "elm-osm-trace-fill",
3190
+ type: "fill",
3191
+ source: Ae,
3192
+ paint: {
3193
+ "fill-color": ["get", "_color"],
3194
+ "fill-opacity": [
3195
+ "case",
3196
+ ["boolean", ["get", "_hovered"], !1],
3197
+ 0.3,
3198
+ 0.12
3199
+ ]
3200
+ }
3201
+ }), e.addLayer({
3202
+ id: "elm-osm-trace-line",
3203
+ type: "line",
3204
+ source: Ae,
3205
+ paint: {
3206
+ "line-color": ["get", "_color"],
3207
+ "line-width": [
3208
+ "case",
3209
+ ["boolean", ["get", "_hovered"], !1],
3210
+ 3,
3211
+ 2
3212
+ ],
3213
+ "line-opacity": [
3214
+ "case",
3215
+ ["boolean", ["get", "_hovered"], !1],
3216
+ 1,
3217
+ 0.7
3218
+ ]
3219
+ }
3220
+ }));
3221
+ }
3222
+ function Ms(e) {
3223
+ for (const t of ["elm-osm-trace-line", "elm-osm-trace-fill"])
3224
+ e.getLayer(t) && e.removeLayer(t);
3225
+ e.getSource(Ae) && e.removeSource(Ae);
3226
+ }
3227
+ function ks(e, t, n) {
3228
+ const o = e.getSource(Ae);
3229
+ if (!o) return;
3230
+ if (!t) {
3231
+ o.setData(Ie());
3232
+ return;
3233
+ }
3234
+ const r = t.map((s, i) => ({
3235
+ type: "Feature",
3236
+ properties: {
3237
+ _color: at[i % at.length],
3238
+ _hovered: n === i,
3239
+ _idx: i
3240
+ },
3241
+ geometry: s.geometry
3242
+ }));
3243
+ o.setData({ type: "FeatureCollection", features: r });
3244
+ }
3245
+ const Is = /* @__PURE__ */ new Set(["building", "landuse", "landcover", "park", "water", "aeroway"]);
3246
+ function Rs(e, t) {
3247
+ const n = [], o = /* @__PURE__ */ new Map();
3248
+ for (const s of e.queryRenderedFeatures([t.x, t.y])) {
3249
+ if (!s.sourceLayer || !Is.has(s.sourceLayer) || s.id == null || s.geometry.type !== "Polygon" && s.geometry.type !== "MultiPolygon") continue;
3250
+ n.push({ source: s.source, sourceLayer: s.sourceLayer, id: s.id, properties: s.properties, geometry: s.geometry });
3251
+ const i = `${s.source}
3252
+ ${s.sourceLayer}`, l = o.get(i);
3253
+ l ? l.ids.add(s.id) : o.set(i, { source: s.source, sourceLayer: s.sourceLayer, ids: /* @__PURE__ */ new Set([s.id]) });
3254
+ }
3255
+ const r = [];
3256
+ for (const { source: s, sourceLayer: i, ids: l } of o.values())
3257
+ for (const u of e.querySourceFeatures(s, { sourceLayer: i, filter: ["in", ["id"], ["literal", [...l]]] }))
3258
+ r.push({ source: s, sourceLayer: i, id: u.id, properties: u.properties, geometry: u.geometry });
3259
+ return _o(n, r);
3260
+ }
3261
+ async function Fs(e, t) {
3262
+ let n = e.pieces.length === 1 ? e.pieces[0].geometry : null;
3263
+ if (!n)
3264
+ try {
3265
+ n = await $o({ type: "boolean", op: "union", features: e.pieces });
3266
+ } catch {
3267
+ n = await ko(e.pieces);
3268
+ }
3269
+ return Io(e, n, t);
3270
+ }
3271
+ function _s({ map: e }) {
3272
+ const { dataStore: t, uiStore: n } = Le(), o = ke().network, r = $(o);
3273
+ r.current = o;
3274
+ const s = Ue(), i = zt(), l = W((y) => y.editingMode), [u, c] = le(null), [v, d] = le(null), g = Oo(), w = An(), P = $(null), T = $(null), _ = $(null), M = $(null);
3275
+ K(() => () => {
3276
+ _.current && (_.current.remove(), _.current = null);
3277
+ }, [e]);
3278
+ const N = vt();
3279
+ K(() => {
3280
+ ks(e, u, v);
3281
+ }, [e, u, v, N]);
3282
+ const E = ve(
3283
+ (y) => Mo(t.getState(), n.getState(), y),
3284
+ [t, n]
3285
+ ), A = ve(() => {
3286
+ _.current && (_.current.remove(), _.current = null);
3287
+ }, []), D = ve(() => {
3288
+ c(null), d(null), P.current = null, A(), T.current && (T.current.abort(), T.current = null);
3289
+ }, [A]), q = ve((y) => {
3290
+ const f = P.current;
3291
+ if (D(), !("pieces" in y)) {
3292
+ E(y);
3293
+ return;
3294
+ }
3295
+ if (!f) return;
3296
+ const b = new AbortController();
3297
+ T.current = b, Fs(y, f).then((C) => {
3298
+ b.signal.aborted || (T.current = null, C && E(C));
3299
+ });
3300
+ }, [E, D]);
3301
+ return K(() => {
3302
+ if (!u && l !== "pick-shape") return;
3303
+ function y(f) {
3304
+ f.key === "Escape" && i(f) && D();
3305
+ }
3306
+ return window.addEventListener("keydown", y), () => window.removeEventListener("keydown", y);
3307
+ }, [u, l, D, i]), K(() => {
3308
+ if (l !== "pick-shape") return;
3309
+ const y = (f) => {
3310
+ if (e.getZoom() < Ro) {
3311
+ s({ type: "warning", message: "Zoom in further to use the picker" });
3312
+ return;
3313
+ }
3314
+ f.originalEvent.preventDefault(), D();
3315
+ const b = new AbortController();
3316
+ T.current = b;
3317
+ const C = f.lngLat.lng, R = f.lngLat.lat;
3318
+ P.current = [C, R], Ps();
3319
+ const I = document.createElement("div");
3320
+ I.style.cssText = "width:64px;height:64px;pointer-events:none;display:flex;align-items:center;justify-content:center;", I.innerHTML = `
3321
+ <div class="elm-osm-pulse-ring" style="position:absolute"></div>
3322
+ <div class="elm-osm-spinner"></div>
3323
+ `, _.current = new De.Marker({ element: I, anchor: "center" }).setLngLat([C, R]).addTo(e);
3324
+ const a = Rs(e, f.point), { overpass: x, fetch: p } = r.current, m = x === !1;
3325
+ (a.length > 0 || m ? Promise.resolve(a) : Qo(R, C, Fo(e.getZoom()), [C, R], { ...x, fetch: p, signal: b.signal })).then((S) => {
3326
+ A(), S.length === 0 ? (s({ type: "warning", message: m ? "No shape here in the basemap" : "No features found here" }), D()) : S.length === 1 ? q(S[0]) : c(S);
3327
+ }).catch((S) => {
3328
+ (S == null ? void 0 : S.name) !== "AbortError" && (A(), s({ type: "error", code: S instanceof tr ? S.code : "unknown", source: "picker", message: er(S), cause: S }), D());
3329
+ });
3330
+ };
3331
+ return e.on("click", y), () => {
3332
+ e.off("click", y);
3333
+ };
3334
+ }, [l, e, D, A, q, s]), K(() => {
3335
+ if (!u || !P.current) return;
3336
+ const y = P.current;
3337
+ let f;
3338
+ function b() {
3339
+ if (!M.current) {
3340
+ f = requestAnimationFrame(b);
3341
+ return;
3342
+ }
3343
+ const C = e.project(y), R = e.getContainer().getBoundingClientRect();
3344
+ M.current.style.left = `${R.left + C.x + 16}px`, M.current.style.top = `${R.top + C.y - 8}px`, f = requestAnimationFrame(b);
3345
+ }
3346
+ return f = requestAnimationFrame(b), () => cancelAnimationFrame(f);
3347
+ }, [u, e]), K(() => {
3348
+ if (!u) return;
3349
+ const y = (I) => {
3350
+ var m, F;
3351
+ const a = (m = I.features) == null ? void 0 : m[0];
3352
+ if (!a) return;
3353
+ const x = (F = a.properties) == null ? void 0 : F._idx;
3354
+ if (typeof x != "number") return;
3355
+ I.originalEvent.stopPropagation();
3356
+ const p = u[x];
3357
+ p && q(p);
3358
+ }, f = (I) => {
3359
+ var p, m;
3360
+ const a = (p = I.features) == null ? void 0 : p[0];
3361
+ if (!a) return;
3362
+ const x = (m = a.properties) == null ? void 0 : m._idx;
3363
+ typeof x == "number" && d(x), e.getCanvas().style.cursor = "pointer";
3364
+ }, b = () => {
3365
+ e.getCanvas().style.cursor = Ge(n.getState().editingMode);
3366
+ }, C = () => {
3367
+ d(null), b();
3368
+ }, R = ["elm-osm-trace-fill", "elm-osm-trace-line"];
3369
+ for (const I of R)
3370
+ e.on("click", I, y), e.on("mouseenter", I, f), e.on("mouseleave", I, C);
3371
+ return () => {
3372
+ for (const I of R)
3373
+ e.off("click", I, y), e.off("mouseenter", I, f), e.off("mouseleave", I, C);
3374
+ b();
3375
+ };
3376
+ }, [u, e, q, n]), K(() => {
3377
+ l !== "pick-shape" && D();
3378
+ }, [l, D]), u ? Ze(
3379
+ /* @__PURE__ */ X("div", { ref: M, "data-elm-portal": !0, "data-elm-theme": w, style: { ...g, position: "fixed", zIndex: 1e4 }, children: /* @__PURE__ */ X("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: u.map((y, f) => /* @__PURE__ */ fe(
3380
+ "button",
3381
+ {
3382
+ onClick: () => q(y),
3383
+ onMouseEnter: () => d(f),
3384
+ onMouseLeave: () => d(null),
3385
+ className: `w-full text-left px-3 py-2 flex items-center gap-2 transition-colors ${v === f ? "bg-primary-50 dark:bg-white/5" : "hover:bg-(--elm-surface-hover,var(--color-gray-50)) dark:hover:bg-elm-surface-hover"}`,
3386
+ children: [
3387
+ /* @__PURE__ */ X(
3388
+ "span",
3389
+ {
3390
+ className: "w-2.5 h-2.5 rounded-full shrink-0",
3391
+ style: { background: at[f % at.length] }
3392
+ }
3393
+ ),
3394
+ /* @__PURE__ */ fe("span", { className: "flex flex-col min-w-0", children: [
3395
+ /* @__PURE__ */ X("span", { className: "font-medium text-(--elm-text,var(--color-gray-800)) dark:text-(--elm-text,var(--color-gray-100)) truncate", children: y.name || `Unnamed ${y.type.toLowerCase()}` }),
3396
+ /* @__PURE__ */ X("span", { className: "text-xs text-(--elm-text-subtle,var(--color-gray-400))", children: y.type })
3397
+ ] })
3398
+ ]
3399
+ },
3400
+ "key" in y ? y.key : `${y.osmId}/${f}`
3401
+ )) }) }),
3402
+ document.body
3403
+ ) : null;
3404
+ }
3405
+ const kn = "elm-features";
3406
+ function As(e) {
3407
+ br(e), Fr(e), ds(e), ps(e), vs(e), ls(e), Cs(e), to(e, Dn(e.getContainer())[400]);
3408
+ }
3409
+ function Ts(e) {
3410
+ Ms(e), as(e), Lr(e), _r(e), fs(e), hs(e), xs(e), e.hasImage("elm-snap-diamond") && e.removeImage("elm-snap-diamond");
3411
+ }
3412
+ function Ds(e, t) {
3413
+ let n, o = !1;
3414
+ const r = () => {
3415
+ if (o) return;
3416
+ const i = e.getSource(kn);
3417
+ if (!(i && i === n)) {
3418
+ o = !0;
3419
+ try {
3420
+ As(e);
3421
+ } catch {
3422
+ return;
3423
+ } finally {
3424
+ o = !1;
3425
+ }
3426
+ (!ar(e) || n && !i) && ur(e, e.getStyle()), n = e.getSource(kn), t();
3427
+ }
3428
+ };
3429
+ r();
3430
+ const s = ["styledata", "style.load", "load"];
3431
+ for (const i of s) e.on(i, r);
3432
+ return () => {
3433
+ for (const i of s) e.off(i, r);
3434
+ };
3435
+ }
3436
+ function Ks({ map: e }) {
3437
+ const { units: t } = ke(), n = { unit: t.length, display: t.display, precision: t.precision }, o = { unit: t.area, display: t.display, precision: t.precision }, r = (f) => {
3438
+ const { value: b, unit: C } = mt(f * 1e3, n);
3439
+ return `${b} ${C}`;
3440
+ }, s = (f) => {
3441
+ const { value: b, unit: C } = Ht(f, o);
3442
+ return `${b} ${C}`;
3443
+ }, i = W((f) => f.showMeasurements), l = W((f) => f.editingMode), u = W((f) => f.snappedCoord), c = W((f) => f.lineInProgress), v = W((f) => f.polygonInProgress), d = W((f) => f.circleCenter), g = W((f) => f.rectCorner), w = W((f) => f.freehandPoints), P = W((f) => f.freehandClosed), T = W((f) => f.routeWaypoints), _ = oo(e, l, l !== "none"), [M, N] = le(null), E = u ?? _;
3444
+ K(() => {
3445
+ if (!E) {
3446
+ N(null);
3447
+ return;
3448
+ }
3449
+ N(e.project(E));
3450
+ const f = () => N(E ? e.project(E) : null);
3451
+ return e.on("move", f), e.on("zoom", f), () => {
3452
+ e.off("move", f), e.off("zoom", f);
3453
+ };
3454
+ }, [e, E == null ? void 0 : E[0], E == null ? void 0 : E[1]]);
3455
+ const A = $(null), [D, q] = le({ w: 0, h: 0 });
3456
+ if (uo(() => {
3457
+ const f = A.current;
3458
+ f && (f.offsetWidth !== D.w || f.offsetHeight !== D.h) && q({ w: f.offsetWidth, h: f.offsetHeight });
3459
+ }), !i || l === "none" || !E || !M) return null;
3460
+ const y = [];
3461
+ try {
3462
+ if (l === "place-point")
3463
+ y.push({ label: "", value: `${E[1].toFixed(6)}, ${E[0].toFixed(6)}` });
3464
+ else if (l === "draw-line" || l === "slice-shape") {
3465
+ const f = [...c, E];
3466
+ if (f.length >= 2) {
3467
+ const b = We(f);
3468
+ y.push({ label: "Length", value: r(_e(b)) }), y.push({ label: "Segment length", value: r(Pe(f[f.length - 2], f[f.length - 1])) });
3469
+ }
3470
+ y.push({ label: "", value: `${E[1].toFixed(6)}, ${E[0].toFixed(6)}` });
3471
+ } else if (l === "draw-polygon" || l === "cut-hole") {
3472
+ const f = [...v, E];
3473
+ if (f.length >= 3) {
3474
+ const b = [...f, f[0]], C = ut([b]);
3475
+ y.push({ label: "Area", value: s(dt(C)) }), y.push({ label: "Perimeter", value: r(_e(C)) });
3476
+ const R = Bn(C);
3477
+ y.push({ label: "Height", value: r(Pe([R[0], R[1]], [R[0], R[3]])) }), y.push({ label: "Width", value: r(Pe([R[0], R[1]], [R[2], R[1]])) });
3478
+ } else f.length === 2 && y.push({ label: "Segment length", value: r(Pe(f[0], f[1])) });
3479
+ y.push({ label: "", value: `${E[1].toFixed(6)}, ${E[0].toFixed(6)}` });
3480
+ } else if (l === "draw-circle") {
3481
+ if (d) {
3482
+ const f = Pe(d, E);
3483
+ y.push({ label: "Radius", value: r(f) }), y.push({ label: "Area", value: s(Math.PI * (f * 1e3) * (f * 1e3)) });
3484
+ }
3485
+ y.push({ label: "", value: `${E[1].toFixed(6)}, ${E[0].toFixed(6)}` });
3486
+ } else if (l === "draw-rect") {
3487
+ if (g) {
3488
+ const f = Pe([g[0], g[1]], [E[0], g[1]]), b = Pe([g[0], g[1]], [g[0], E[1]]), C = f * b * 1e6;
3489
+ y.push({ label: "Area", value: s(C) }), y.push({ label: "Width", value: r(f) }), y.push({ label: "Height", value: r(b) });
3490
+ }
3491
+ y.push({ label: "", value: `${E[1].toFixed(6)}, ${E[0].toFixed(6)}` });
3492
+ } else if (l === "draw-route") {
3493
+ const f = [...T, E];
3494
+ f.length >= 2 && y.push({ label: "Straight distance", value: r(Pe(f[f.length - 2], f[f.length - 1])) }), y.push({ label: "", value: `${E[1].toFixed(6)}, ${E[0].toFixed(6)}` });
3495
+ } else if (l === "draw-freehand") {
3496
+ if (w.length >= 3 && P) {
3497
+ const f = [...w, w[0]], b = ut([f]);
3498
+ y.push({ label: "Area", value: s(dt(b)) }), y.push({ label: "Perimeter", value: r(_e(b)) });
3499
+ } else if (w.length >= 2) {
3500
+ const f = We(w);
3501
+ y.push({ label: "Length", value: r(_e(f)) });
3502
+ }
3503
+ y.push({ label: "", value: `${E[1].toFixed(6)}, ${E[0].toFixed(6)}` });
3504
+ }
3505
+ } catch {
3506
+ }
3507
+ return y.length === 0 ? null : Ze(
3508
+ /* @__PURE__ */ X(
3509
+ "div",
3510
+ {
3511
+ ref: A,
3512
+ className: "elm-measurement-tooltip",
3513
+ style: {
3514
+ position: "absolute",
3515
+ ...Fn(M.x, M.y, D.w, D.h, {
3516
+ x: "after",
3517
+ y: "center",
3518
+ gapX: 20,
3519
+ bounds: { left: 0, top: 0, right: e.getContainer().clientWidth, bottom: e.getContainer().clientHeight }
3520
+ }),
3521
+ zIndex: 700,
3522
+ pointerEvents: "none",
3523
+ whiteSpace: "nowrap",
3524
+ // Light in both modes by default (an on-map label); follows the design tokens once set.
3525
+ background: "var(--elm-surface, white)",
3526
+ border: "1px solid var(--elm-border, rgb(229, 231, 235))",
3527
+ boxShadow: "var(--elm-shadow-control, 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1))",
3528
+ borderRadius: "calc(var(--elm-radius-control, 6px) + 2px)",
3529
+ padding: 12,
3530
+ fontSize: 12,
3531
+ color: "var(--elm-text-secondary, rgb(75, 85, 99))",
3532
+ fontFamily: "var(--elm-font, ui-sans-serif, system-ui, sans-serif)"
3533
+ },
3534
+ children: /* @__PURE__ */ X("div", { style: { display: "flex", flexDirection: "column", gap: 4, textAlign: "left" }, children: y.map((f, b) => /* @__PURE__ */ fe("div", { style: { display: "flex", gap: 8, alignItems: "center", lineHeight: 1.3 }, children: [
3535
+ f.label && /* @__PURE__ */ fe("span", { style: { fontWeight: 600, color: "var(--elm-text, rgb(17, 24, 39))" }, children: [
3536
+ f.label,
3537
+ ":"
3538
+ ] }),
3539
+ /* @__PURE__ */ X("span", { children: f.value })
3540
+ ] }, b)) })
3541
+ }
3542
+ ),
3543
+ e.getContainer()
3544
+ );
3545
+ }
3546
+ const Qt = Nt(null);
3547
+ function li() {
3548
+ const e = pt(Qt);
3549
+ if (!e) throw new Error("useMapLibre must be used inside ElementEditorControls");
3550
+ return e;
3551
+ }
3552
+ const Ns = () => pt(Qt);
3553
+ function Bs({ map: e }) {
3554
+ const t = Wo();
3555
+ return K(() => {
3556
+ t({
3557
+ // MapController's public contract is `[lat, lng]` (Leaflet convention —
3558
+ // the UI package normalises to that). MapLibre natively uses `[lng, lat]`,
3559
+ // so we swap on the boundary. Search "Go" / LocateButton / ZoomIndicator
3560
+ // all pass [lat, lng]; flipping here restores correct flyTo targets.
3561
+ // `offset`, not `padding`: MapLibre keeps a camera padding for good.
3562
+ // Points land in the middle of the visible map (clear of the open
3563
+ // panels / docked inspector / table), not under them.
3564
+ flyTo: ([n, o], r) => e.flyTo({ center: [o, n], zoom: r, offset: cn(e.getContainer()) }),
3565
+ panTo: ([n, o]) => e.panTo([o, n], { offset: cn(e.getContainer()) }),
3566
+ fitBounds: (n) => {
3567
+ const o = Ao(n);
3568
+ o && e.fitBounds(
3569
+ [[o.minLng, o.minLat], [o.maxLng, o.maxLat]],
3570
+ { padding: jt(e.getContainer()), maxZoom: 16 }
3571
+ );
3572
+ },
3573
+ getCenter: () => {
3574
+ const n = e.getCenter();
3575
+ return [n.lng, n.lat];
3576
+ },
3577
+ setZoom: (n) => {
3578
+ const o = Math.max(e.getMinZoom(), Math.min(e.getMaxZoom(), n));
3579
+ return e.setZoom(o), o;
3580
+ },
3581
+ getZoomBounds: () => ({ min: e.getMinZoom(), max: e.getMaxZoom() }),
3582
+ getMap: () => e
3583
+ });
3584
+ }, [e, t]), null;
3585
+ }
3586
+ const Os = In(
3587
+ function(t, n) {
3588
+ const { map: o, maxBounds: r } = t, { dataStore: s, uiStore: i } = Le(), l = Ho({
3589
+ initialData: t.initialData,
3590
+ schema: t.schema,
3591
+ layout: t.layout,
3592
+ readonly: t.readonly,
3593
+ tools: t.tools,
3594
+ maxFeatures: t.maxFeatures,
3595
+ engine: "maplibre",
3596
+ onChange: t.onChange,
3597
+ onSubmit: t.onSubmit,
3598
+ onValidationError: t.onValidationError,
3599
+ onFeatureAdd: t.onFeatureAdd,
3600
+ onFeatureUpdate: t.onFeatureUpdate,
3601
+ onFeatureDelete: t.onFeatureDelete,
3602
+ onSelectionChange: t.onSelectionChange,
3603
+ onFeatureSelect: t.onFeatureSelect,
3604
+ onZoomChange: t.onZoomChange,
3605
+ onToolChange: t.onToolChange
3606
+ });
3607
+ return fo(n, () => l, [l]), K(() => {
3608
+ }, [s, i, o]), Vo(o.getContainer()), Xo(o.getContainer()), Yo(o.getContainer()), K(() => {
3609
+ Go();
3610
+ }, []), K(() => {
3611
+ o.setMaxBounds(r ?? null);
3612
+ }, [o, r]), K(() => {
3613
+ const u = () => s.getState().setCurrentZoom(o.getZoom());
3614
+ return s.getState().setCurrentZoom(o.getZoom()), o.on("zoomend", u), () => {
3615
+ o.off("zoomend", u);
3616
+ };
3617
+ }, [o, s]), /* @__PURE__ */ fe(Qt.Provider, { value: o, children: [
3618
+ /* @__PURE__ */ fe(gr, { getFeatureStyle: t.getFeatureStyle, children: [
3619
+ /* @__PURE__ */ X(Bs, { map: o }),
3620
+ /* @__PURE__ */ X(ys, { map: o }),
3621
+ /* @__PURE__ */ X(Er, { map: o }),
3622
+ /* @__PURE__ */ X(us, { map: o }),
3623
+ /* @__PURE__ */ X(Rr, { map: o, routingApiKey: t.routingApiKey }),
3624
+ /* @__PURE__ */ X(Ar, { map: o }),
3625
+ /* @__PURE__ */ X(ms, { map: o }),
3626
+ /* @__PURE__ */ X(Es, { map: o }),
3627
+ /* @__PURE__ */ X(Ks, { map: o }),
3628
+ /* @__PURE__ */ X(_s, { map: o }),
3629
+ /* @__PURE__ */ X(gs, { map: o })
3630
+ ] }),
3631
+ t.children
3632
+ ] });
3633
+ }
3634
+ ), ai = In(
3635
+ function(t, n) {
3636
+ const [o, r] = le(() => t.map.isStyleLoaded()), [s, i] = le(0);
3637
+ K(() => Ds(t.map, () => {
3638
+ r(!0), i((v) => v + 1);
3639
+ }), [t.map]);
3640
+ const l = $(t.onReady);
3641
+ l.current = t.onReady;
3642
+ const u = $(null);
3643
+ if (K(() => {
3644
+ var v;
3645
+ !o || u.current === t.map || (u.current = t.map, (v = l.current) == null || v.call(l, t.map));
3646
+ }, [o, t.map]), K(() => () => {
3647
+ try {
3648
+ Ts(t.map);
3649
+ } catch {
3650
+ }
3651
+ }, [t.map]), !o) return null;
3652
+ const c = /* @__PURE__ */ X(jn.Provider, { value: s, children: /* @__PURE__ */ X(jo, { children: /* @__PURE__ */ X(Os, { ...t, ref: n }) }) });
3653
+ return t.onEvent || t.onError ? /* @__PURE__ */ X(zo, { onEvent: t.onEvent, onError: t.onError, children: c }) : c;
3654
+ }
3655
+ ), $s = ["streets", "terrain", "light", "dark", "osm"], Ft = /* @__PURE__ */ new WeakMap();
3656
+ let js = 0;
3657
+ function je(e, t) {
3658
+ if (typeof e == "string") return e;
3659
+ const n = e.id ?? e.label ?? ("url" in e ? e.url : typeof e.style == "string" ? e.style : void 0);
3660
+ return n || (t >= 0 ? `custom-${t}` : (Ft.has(e) || Ft.set(e, `custom-anon-${++js}`), Ft.get(e)));
3661
+ }
3662
+ const io = () => import("./style-mSgM9UsZ.js"), zs = () => Promise.all([io(), import("./catalog-gI-xABuu.js")]).then(([e, t]) => ({ ...e, ...t }));
3663
+ let yt = !1;
3664
+ const co = (e) => new Tt(
3665
+ "network",
3666
+ "basemap",
3667
+ `The basemap catalog could not be loaded (${e instanceof Error ? e.message : String(e)}). Reload the page to try again.`,
3668
+ { cause: e }
3669
+ );
3670
+ function lo() {
3671
+ const e = Tn(), t = $(e);
3672
+ return t.current = e, ve((n) => {
3673
+ t.current ? t.current({ type: "error", code: n.code, source: "basemap", message: n.message, error: n }) : console.error(`[element-editor] ${n.message}`);
3674
+ }, []);
3675
+ }
3676
+ function Hs(e, t, n) {
3677
+ const { theme: o } = n, r = ke().network, s = $(r);
3678
+ s.current = r;
3679
+ const [i, l] = le(null), u = lo();
3680
+ K(() => {
3681
+ let g = !0;
3682
+ return io().then((w) => g && l(w), (w) => {
3683
+ g && !yt && (yt = !0, u(co(w)));
3684
+ }), () => {
3685
+ g = !1;
3686
+ };
3687
+ }, []);
3688
+ const c = (g) => {
3689
+ const w = (i == null ? void 0 : i.resolveBasemap(g, o)) ?? g;
3690
+ return je(w, -1);
3691
+ }, v = $(void 0), d = $(n.initialApplied ? { basemap: t, theme: o } : null);
3692
+ v.current === void 0 && (v.current = d.current ? "" : null), K(() => {
3693
+ if (!e || !i) return;
3694
+ const g = c(t);
3695
+ if (v.current === "" && (v.current = je(i.resolveBasemap(d.current.basemap, d.current.theme), -1)), v.current === g) return;
3696
+ let w = !1;
3697
+ const P = (D) => D instanceof Error ? D.message : String(D), T = i.resolveBasemap(t, o), _ = typeof T == "object" && "style" in T && typeof T.style == "string", M = (D) => {
3698
+ N(), v.current = null, u(new Tt(ln(D.error), "basemap", `The basemap could not be loaded (${P(D.error)}).`, { cause: D.error }));
3699
+ }, N = () => {
3700
+ e.off("error", M), e.off("styledata", N);
3701
+ }, E = () => {
3702
+ w || !(e.isStyleLoaded() || e.getSource("elm-features")) || (w = !0, e.off("styledata", E), v.current = g, i.setBasemap(e, t, { theme: o, network: s.current }).then(() => {
3703
+ _ && !A && (e.on("error", M), e.once("styledata", N));
3704
+ }, (D) => {
3705
+ v.current = null, u(new Tt(ln(D), "basemap", `The basemap could not be switched (${P(D)}). The map keeps the previous one.`, { cause: D }));
3706
+ }));
3707
+ };
3708
+ let A = !1;
3709
+ return e.on("styledata", E), E(), () => {
3710
+ w = !0, A = !0, e.off("styledata", E), N();
3711
+ };
3712
+ }, [e, i, t, o]);
3713
+ }
3714
+ function ui(e) {
3715
+ const { basemaps: t, value: n, defaultValue: o = "auto", onChange: r, storageKey: s, initialApplied: i, size: l, tooltipSide: u } = e, c = Ns(), v = e.map ?? c, d = An(), [g, w] = le(null), P = lo();
3716
+ K(() => {
3717
+ let a = !0;
3718
+ return zs().then((x) => a && w(x), (x) => {
3719
+ a && !yt && (yt = !0, P(co(x)));
3720
+ }), () => {
3721
+ a = !1;
3722
+ };
3723
+ }, []);
3724
+ const T = ke(), _ = Bt(() => t ?? ["auto", ...$s], [t]), M = _.map(je);
3725
+ (_.filter((a) => typeof a == "object" && !a.id && !a.label && !("url" in a) && typeof a.style != "string").length > 1 || new Set(M).size < M.length) && Rn("basemap-ids", "BasemapControl: give each custom basemap a unique `id` (two entries without one, or with the same id/label, cannot be told apart).");
3726
+ const [N] = le(() => {
3727
+ const a = s ? nr(s, T) : null;
3728
+ return a ? _.find((x, p) => je(x, p) === a) : void 0;
3729
+ }), [E, A] = le(N ?? o), [D, q] = le(n !== void 0 || e.defaultValue !== void 0 || N !== void 0), y = n ?? E, f = _.indexOf(y), b = f >= 0 ? M[f] : je(y, -1);
3730
+ Hs(D || n !== void 0 ? v : null, y, {
3731
+ theme: d,
3732
+ initialApplied: D && i && b === je(o, _.indexOf(o))
3733
+ });
3734
+ const C = ve((a) => {
3735
+ const x = M.indexOf(a);
3736
+ if (x < 0) return;
3737
+ const p = _[x];
3738
+ q(!0), n === void 0 && A(p), s && (typeof p == "string" || p.id) && or(s, a, T), r == null || r(p);
3739
+ }, [M, _, n, s, r, T]);
3740
+ if (!g) return null;
3741
+ const R = (a) => {
3742
+ var x;
3743
+ return (x = g.BASEMAPS.find((p) => p.id === a)) == null ? void 0 : x.thumbnail;
3744
+ }, I = _.map((a, x) => {
3745
+ const p = M[x], m = typeof a == "string" ? g.BASEMAPS.find((F) => F.id === a) : void 0;
3746
+ return {
3747
+ id: p,
3748
+ label: a === "auto" ? "Auto" : (m == null ? void 0 : m.label) ?? (typeof a == "object" && a.label || p),
3749
+ // Auto shows both looks it switches between (light → streets, dark → dark).
3750
+ thumbnail: a === "auto" ? [R("streets"), R("dark")].every(Boolean) ? [R("streets"), R("dark")] : void 0 : typeof a == "string" ? R(a) : a.thumbnail
3751
+ };
3752
+ });
3753
+ return /* @__PURE__ */ X(Uo, { options: I, value: b, onChange: C, size: l, tooltipSide: u });
3754
+ }
3755
+ export {
3756
+ gi as ActiveDrawingToolbar,
3757
+ ui as BasemapControl,
3758
+ ys as BoundaryLayer,
3759
+ rs as BoxSelectHandler,
3760
+ Rr as DrawingLayer,
3761
+ Ar as DrawingPreviewLayer,
3762
+ yi as EditingToolbar,
3763
+ ai as ElementEditorControls,
3764
+ Mi as ElementEditorError,
3765
+ pi as ElementEditorUIProvider,
3766
+ us as FeatureInteractionLayer,
3767
+ Er as FeatureLayer,
3768
+ gr as FeatureStyleProvider,
3769
+ ci as FitBounds,
3770
+ hi as FloatingToolbar,
3771
+ mi as GeoStoreProvider,
3772
+ ms as GeometryProcessingPreview,
3773
+ vi as MapControllerProvider,
3774
+ Es as MeasurePreviewLayer,
3775
+ Ks as MeasurementTooltip,
3776
+ _s as OsmTraceHandler,
3777
+ gs as SnapController,
3778
+ xi as StoreContext,
3779
+ es as TransformControls,
3780
+ $r as VertexEditor,
3781
+ Vn as findSnapPoint,
3782
+ Dt as snapToAngle,
3783
+ Hs as useBasemap,
3784
+ wi as useDataStore,
3785
+ yr as useFeatureStyle,
3786
+ Si as useGeoStore,
3787
+ bi as useKeyboardShortcuts,
3788
+ Li as useMapController,
3789
+ li as useMapLibre,
3790
+ Ei as useSetMapController,
3791
+ Pi as useUIStore
3792
+ };