leaflet-anvil 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -73,6 +73,49 @@ var ModeManager = class {
73
73
  // src/modes/draw-polygon-mode.ts
74
74
  import * as L3 from "leaflet";
75
75
 
76
+ // src/utils/mode-styles.ts
77
+ function getModePathOptions(options, mode, defaults = {}) {
78
+ return {
79
+ ...defaults,
80
+ ...options.pathOptions || {},
81
+ ...options.modeStyles?.[mode]?.pathOptions || {}
82
+ };
83
+ }
84
+ function getModeGhostPathOptions(options, mode, defaults = {}) {
85
+ return {
86
+ ...getModePathOptions(options, mode),
87
+ ...defaults,
88
+ ...options.ghostPathOptions || {},
89
+ ...options.modeStyles?.[mode]?.ghostPathOptions || {}
90
+ };
91
+ }
92
+ function getModeVertexOptions(options, mode, defaults = {}) {
93
+ return {
94
+ ...defaults,
95
+ ...options.vertexOptions || {},
96
+ ...options.modeStyles?.[mode]?.vertexOptions || {}
97
+ };
98
+ }
99
+ function getModeHandleOptions(options, mode, defaults = {}) {
100
+ const pathOptions = getModePathOptions(options, mode);
101
+ return {
102
+ radius: 5,
103
+ color: pathOptions.color || "#3388ff",
104
+ weight: 2,
105
+ fillColor: "#fff",
106
+ fillOpacity: 1,
107
+ ...defaults,
108
+ ...options.modeStyles?.[mode]?.handleOptions || {}
109
+ };
110
+ }
111
+ function getModeSelectionPathOptions(options, mode, base = {}, defaults = {}) {
112
+ return {
113
+ ...base,
114
+ ...defaults,
115
+ ...options.modeStyles?.[mode]?.selectionPathOptions || {}
116
+ };
117
+ }
118
+
76
119
  // src/utils/snapping.ts
77
120
  import * as L from "leaflet";
78
121
  function getSnapLatLng(map, latlng, store, options, additionalPoints = [], skipLayer) {
@@ -233,11 +276,14 @@ var DrawPolygonMode = class {
233
276
  const snapLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options, this.points) : e.latlng;
234
277
  const lastPoint = this.points[this.points.length - 1];
235
278
  if (!this.ghostLine) {
236
- this.ghostLine = L3.polyline([lastPoint, snapLatLng], {
237
- dashArray: "5, 5",
238
- color: "#3388ff",
239
- weight: 2
240
- }).addTo(this.map);
279
+ this.ghostLine = L3.polyline(
280
+ [lastPoint, snapLatLng],
281
+ getModeGhostPathOptions(this.options, "polygon" /* Polygon */, {
282
+ dashArray: "5, 5",
283
+ color: "#3388ff",
284
+ weight: 2
285
+ })
286
+ ).addTo(this.map);
241
287
  } else {
242
288
  this.ghostLine.setLatLngs([lastPoint, snapLatLng]);
243
289
  }
@@ -251,26 +297,32 @@ var DrawPolygonMode = class {
251
297
  if (this.polyline) {
252
298
  this.polyline.setLatLngs(this.points);
253
299
  } else {
254
- this.polyline = L3.polyline(this.points, { color: "#3388ff" }).addTo(this.map);
300
+ this.polyline = L3.polyline(
301
+ this.points,
302
+ getModePathOptions(this.options, "polygon" /* Polygon */, { color: "#3388ff" })
303
+ ).addTo(this.map);
255
304
  }
256
305
  if (this.points.length === 1 && this.markers.length === 0) {
257
- const marker4 = L3.circleMarker(this.points[0], {
258
- radius: 5,
259
- fillColor: "#fff",
260
- fillOpacity: 1,
261
- color: "#3388ff",
262
- weight: 2
263
- }).addTo(this.map);
264
- marker4.on("click", (e) => {
306
+ const marker3 = L3.circleMarker(
307
+ this.points[0],
308
+ getModeHandleOptions(this.options, "polygon" /* Polygon */, {
309
+ radius: 5,
310
+ color: "#3388ff"
311
+ })
312
+ ).addTo(this.map);
313
+ marker3.on("click", (e) => {
265
314
  L3.DomEvent.stopPropagation(e);
266
315
  this.finish();
267
316
  });
268
- this.markers.push(marker4);
317
+ this.markers.push(marker3);
269
318
  }
270
319
  }
271
320
  finish() {
272
321
  if (this.points.length < 3) return;
273
- const polygon7 = L3.polygon(this.points).addTo(this.map);
322
+ const polygon7 = L3.polygon(
323
+ this.points,
324
+ getModePathOptions(this.options, "polygon" /* Polygon */)
325
+ ).addTo(this.map);
274
326
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: polygon7 });
275
327
  this.reset();
276
328
  }
@@ -326,11 +378,14 @@ var DrawPolylineMode = class {
326
378
  const snapLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options, this.points) : e.latlng;
327
379
  const lastPoint = this.points[this.points.length - 1];
328
380
  if (!this.ghostLine) {
329
- this.ghostLine = L4.polyline([lastPoint, e.latlng], {
330
- dashArray: "5, 5",
331
- color: "#3388ff",
332
- weight: 2
333
- }).addTo(this.map);
381
+ this.ghostLine = L4.polyline(
382
+ [lastPoint, e.latlng],
383
+ getModeGhostPathOptions(this.options, "polyline" /* Polyline */, {
384
+ dashArray: "5, 5",
385
+ color: "#3388ff",
386
+ weight: 2
387
+ })
388
+ ).addTo(this.map);
334
389
  } else {
335
390
  this.ghostLine.setLatLngs([lastPoint, snapLatLng]);
336
391
  }
@@ -350,12 +405,18 @@ var DrawPolylineMode = class {
350
405
  if (this.polyline) {
351
406
  this.polyline.setLatLngs(this.points);
352
407
  } else {
353
- this.polyline = L4.polyline(this.points, { color: "#3388ff" }).addTo(this.map);
408
+ this.polyline = L4.polyline(
409
+ this.points,
410
+ getModePathOptions(this.options, "polyline" /* Polyline */, { color: "#3388ff" })
411
+ ).addTo(this.map);
354
412
  }
355
413
  }
356
414
  finish() {
357
415
  if (this.points.length < 2) return;
358
- const polyline6 = L4.polyline(this.points).addTo(this.map);
416
+ const polyline6 = L4.polyline(
417
+ this.points,
418
+ getModePathOptions(this.options, "polyline" /* Polyline */)
419
+ ).addTo(this.map);
359
420
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: polyline6 });
360
421
  this.reset();
361
422
  }
@@ -386,8 +447,8 @@ var DrawMarkerMode = class {
386
447
  }
387
448
  onClick(e) {
388
449
  const latlng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
389
- const marker4 = L5.marker(latlng, this.options.vertexOptions).addTo(this.map);
390
- this.map.fire(ANVIL_EVENTS.CREATED, { layer: marker4 });
450
+ const marker3 = L5.marker(latlng, getModeVertexOptions(this.options, "marker" /* Marker */)).addTo(this.map);
451
+ this.map.fire(ANVIL_EVENTS.CREATED, { layer: marker3 });
391
452
  }
392
453
  };
393
454
 
@@ -424,7 +485,13 @@ var DrawRectangleMode = class {
424
485
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
425
486
  const bounds = L6.latLngBounds(this.startLatLng, currentLatLng);
426
487
  if (!this.rectangle) {
427
- this.rectangle = L6.rectangle(bounds, { color: "#3388ff", weight: 2 }).addTo(this.map);
488
+ this.rectangle = L6.rectangle(
489
+ bounds,
490
+ getModeGhostPathOptions(this.options, "rectangle" /* Rectangle */, {
491
+ color: "#3388ff",
492
+ weight: 2
493
+ })
494
+ ).addTo(this.map);
428
495
  } else {
429
496
  this.rectangle.setBounds(bounds);
430
497
  }
@@ -433,7 +500,10 @@ var DrawRectangleMode = class {
433
500
  if (!this.startLatLng) return;
434
501
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
435
502
  const bounds = L6.latLngBounds(this.startLatLng, currentLatLng);
436
- const rectangle3 = L6.rectangle(bounds).addTo(this.map);
503
+ const rectangle3 = L6.rectangle(
504
+ bounds,
505
+ getModePathOptions(this.options, "rectangle" /* Rectangle */)
506
+ ).addTo(this.map);
437
507
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: rectangle3 });
438
508
  this.reset();
439
509
  }
@@ -477,7 +547,13 @@ var DrawSquareMode = class {
477
547
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
478
548
  const squareBounds = this.getSquareBounds(this.startLatLng, currentLatLng);
479
549
  if (!this.rectangle) {
480
- this.rectangle = L7.rectangle(squareBounds, { color: "#3388ff", weight: 2 }).addTo(this.map);
550
+ this.rectangle = L7.rectangle(
551
+ squareBounds,
552
+ getModeGhostPathOptions(this.options, "square" /* Square */, {
553
+ color: "#3388ff",
554
+ weight: 2
555
+ })
556
+ ).addTo(this.map);
481
557
  } else {
482
558
  this.rectangle.setBounds(squareBounds);
483
559
  }
@@ -486,12 +562,15 @@ var DrawSquareMode = class {
486
562
  if (!this.startLatLng) return;
487
563
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
488
564
  const squareBounds = this.getSquareBounds(this.startLatLng, currentLatLng);
489
- const polygon7 = L7.polygon([
490
- squareBounds.getNorthWest(),
491
- squareBounds.getNorthEast(),
492
- squareBounds.getSouthEast(),
493
- squareBounds.getSouthWest()
494
- ]).addTo(this.map);
565
+ const polygon7 = L7.polygon(
566
+ [
567
+ squareBounds.getNorthWest(),
568
+ squareBounds.getNorthEast(),
569
+ squareBounds.getSouthEast(),
570
+ squareBounds.getSouthWest()
571
+ ],
572
+ getModePathOptions(this.options, "square" /* Square */)
573
+ ).addTo(this.map);
495
574
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: polygon7 });
496
575
  this.reset();
497
576
  }
@@ -547,7 +626,13 @@ var DrawTriangleMode = class {
547
626
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
548
627
  const trianglePoints = this.getTrianglePoints(this.startLatLng, currentLatLng);
549
628
  if (!this.ghostTriangle) {
550
- this.ghostTriangle = L8.polygon(trianglePoints, { color: "#3388ff", weight: 2 }).addTo(this.map);
629
+ this.ghostTriangle = L8.polygon(
630
+ trianglePoints,
631
+ getModeGhostPathOptions(this.options, "triangle" /* Triangle */, {
632
+ color: "#3388ff",
633
+ weight: 2
634
+ })
635
+ ).addTo(this.map);
551
636
  } else {
552
637
  this.ghostTriangle.setLatLngs(trianglePoints);
553
638
  }
@@ -556,7 +641,10 @@ var DrawTriangleMode = class {
556
641
  if (!this.startLatLng) return;
557
642
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
558
643
  const trianglePoints = this.getTrianglePoints(this.startLatLng, currentLatLng);
559
- const polygon7 = L8.polygon(trianglePoints).addTo(this.map);
644
+ const polygon7 = L8.polygon(
645
+ trianglePoints,
646
+ getModePathOptions(this.options, "triangle" /* Triangle */)
647
+ ).addTo(this.map);
560
648
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: polygon7 });
561
649
  this.reset();
562
650
  }
@@ -611,7 +699,13 @@ var DrawCircleMode = class {
611
699
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
612
700
  const radius = this.map.distance(this.centerLatLng, currentLatLng);
613
701
  if (!this.circle) {
614
- this.circle = L9.circle(this.centerLatLng, { radius, color: "#3388ff", weight: 2 }).addTo(this.map);
702
+ this.circle = L9.circle(this.centerLatLng, {
703
+ radius,
704
+ ...getModeGhostPathOptions(this.options, "circle" /* Circle */, {
705
+ color: "#3388ff",
706
+ weight: 2
707
+ })
708
+ }).addTo(this.map);
615
709
  } else {
616
710
  this.circle.setRadius(radius);
617
711
  }
@@ -620,7 +714,10 @@ var DrawCircleMode = class {
620
714
  if (!this.centerLatLng) return;
621
715
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
622
716
  const radius = this.map.distance(this.centerLatLng, currentLatLng);
623
- const circle2 = L9.circle(this.centerLatLng, { radius }).addTo(this.map);
717
+ const circle2 = L9.circle(this.centerLatLng, {
718
+ radius,
719
+ ...getModePathOptions(this.options, "circle" /* Circle */)
720
+ }).addTo(this.map);
624
721
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: circle2 });
625
722
  this.reset();
626
723
  }
@@ -685,12 +782,15 @@ var FreehandMode = class {
685
782
  if (this.polyline) {
686
783
  this.polyline.setLatLngs(this.points);
687
784
  } else {
688
- this.polyline = L10.polyline(this.points, {
689
- color: "#3388ff",
690
- weight: 3,
691
- opacity: 0.8,
692
- dashArray: "5, 5"
693
- }).addTo(this.map);
785
+ this.polyline = L10.polyline(
786
+ this.points,
787
+ getModeGhostPathOptions(this.options, "freehand" /* Freehand */, {
788
+ color: "#3388ff",
789
+ weight: 3,
790
+ opacity: 0.8,
791
+ dashArray: "5, 5"
792
+ })
793
+ ).addTo(this.map);
694
794
  }
695
795
  }
696
796
  finish() {
@@ -705,7 +805,10 @@ var FreehandMode = class {
705
805
  if (finalCoords.length > 0 && (finalCoords[0][0] !== finalCoords[finalCoords.length - 1][0] || finalCoords[0][1] !== finalCoords[finalCoords.length - 1][1])) {
706
806
  finalCoords.push(finalCoords[0]);
707
807
  }
708
- const finalPolygon = L10.polygon(finalCoords.map((c) => [c[1], c[0]])).addTo(this.map);
808
+ const finalPolygon = L10.polygon(
809
+ finalCoords.map((c) => [c[1], c[0]]),
810
+ getModePathOptions(this.options, "freehand" /* Freehand */)
811
+ ).addTo(this.map);
709
812
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: finalPolygon });
710
813
  this.resetDrawing();
711
814
  }
@@ -764,11 +867,14 @@ var CutMode = class {
764
867
  const snapLatLng = getSnapLatLng(this.map, e.latlng, this.store, this.options, this.points);
765
868
  const lastPoint = this.points[this.points.length - 1];
766
869
  if (!this.ghostLine) {
767
- this.ghostLine = L11.polyline([lastPoint, snapLatLng], {
768
- dashArray: "5, 5",
769
- color: "#ff0000",
770
- weight: 2
771
- }).addTo(this.map);
870
+ this.ghostLine = L11.polyline(
871
+ [lastPoint, snapLatLng],
872
+ getModeGhostPathOptions(this.options, "cut" /* Cut */, {
873
+ dashArray: "5, 5",
874
+ color: "#ff0000",
875
+ weight: 2
876
+ })
877
+ ).addTo(this.map);
772
878
  } else {
773
879
  this.ghostLine.setLatLngs([lastPoint, snapLatLng]);
774
880
  }
@@ -782,21 +888,24 @@ var CutMode = class {
782
888
  if (this.polyline) {
783
889
  this.polyline.setLatLngs(this.points);
784
890
  } else {
785
- this.polyline = L11.polyline(this.points, { color: "#ff0000" }).addTo(this.map);
891
+ this.polyline = L11.polyline(
892
+ this.points,
893
+ getModePathOptions(this.options, "cut" /* Cut */, { color: "#ff0000" })
894
+ ).addTo(this.map);
786
895
  }
787
896
  if (this.points.length === 1 && this.markers.length === 0) {
788
- const marker4 = L11.circleMarker(this.points[0], {
789
- radius: 6,
790
- fillColor: "#fff",
791
- fillOpacity: 1,
792
- color: "#ff0000",
793
- weight: 2
794
- }).addTo(this.map);
795
- marker4.on("click", (e) => {
897
+ const marker3 = L11.circleMarker(
898
+ this.points[0],
899
+ getModeHandleOptions(this.options, "cut" /* Cut */, {
900
+ radius: 6,
901
+ color: "#ff0000"
902
+ })
903
+ ).addTo(this.map);
904
+ marker3.on("click", (e) => {
796
905
  L11.DomEvent.stopPropagation(e);
797
906
  if (this.points.length >= 3) this.finish();
798
907
  });
799
- this.markers.push(marker4);
908
+ this.markers.push(marker3);
800
909
  }
801
910
  }
802
911
  finish() {
@@ -823,7 +932,9 @@ var CutMode = class {
823
932
  this.map.removeLayer(polygon7);
824
933
  const flattened = turf2.flatten(result);
825
934
  flattened.features.forEach((f) => {
826
- const l = L11.geoJSON(f).getLayers()[0];
935
+ const l = L11.geoJSON(f, {
936
+ style: getModePathOptions(this.options, "cut" /* Cut */)
937
+ }).getLayers()[0];
827
938
  l.addTo(this.map);
828
939
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: l });
829
940
  });
@@ -887,11 +998,14 @@ var SplitMode = class {
887
998
  const snapLatLng = getSnapLatLng(this.map, e.latlng, this.store, this.options, this.points);
888
999
  const lastPoint = this.points[this.points.length - 1];
889
1000
  if (!this.ghostLine) {
890
- this.ghostLine = L12.polyline([lastPoint, snapLatLng], {
891
- dashArray: "5, 5",
892
- color: "#ff3300",
893
- weight: 2
894
- }).addTo(this.map);
1001
+ this.ghostLine = L12.polyline(
1002
+ [lastPoint, snapLatLng],
1003
+ getModeGhostPathOptions(this.options, "split" /* Split */, {
1004
+ dashArray: "5, 5",
1005
+ color: "#ff3300",
1006
+ weight: 2
1007
+ })
1008
+ ).addTo(this.map);
895
1009
  } else {
896
1010
  this.ghostLine.setLatLngs([lastPoint, snapLatLng]);
897
1011
  }
@@ -905,23 +1019,28 @@ var SplitMode = class {
905
1019
  if (this.polyline) {
906
1020
  this.polyline.setLatLngs(this.points);
907
1021
  } else {
908
- this.polyline = L12.polyline(this.points, { color: "#ff3300", weight: 3 }).addTo(this.map);
1022
+ this.polyline = L12.polyline(
1023
+ this.points,
1024
+ getModePathOptions(this.options, "split" /* Split */, {
1025
+ color: "#ff3300",
1026
+ weight: 3
1027
+ })
1028
+ ).addTo(this.map);
909
1029
  }
910
1030
  const lastPoint = this.points[this.points.length - 1];
911
1031
  if (this.markers.length === 0) {
912
- const marker4 = L12.marker(lastPoint, {
913
- icon: L12.divIcon({
914
- className: "anvil-split-finish",
915
- html: '<div style="width: 10px; height: 10px; background: #ff3300; border: 2px solid white; border-radius: 50%;"></div>',
916
- iconSize: [10, 10],
917
- iconAnchor: [5, 5]
1032
+ const marker3 = L12.circleMarker(
1033
+ lastPoint,
1034
+ getModeHandleOptions(this.options, "split" /* Split */, {
1035
+ radius: 5,
1036
+ color: "#ff3300"
918
1037
  })
919
- }).addTo(this.map);
920
- marker4.on("click", (e) => {
1038
+ ).addTo(this.map);
1039
+ marker3.on("click", (e) => {
921
1040
  L12.DomEvent.stopPropagation(e);
922
1041
  this.finish();
923
1042
  });
924
- this.markers.push(marker4);
1043
+ this.markers.push(marker3);
925
1044
  } else {
926
1045
  this.markers[0].setLatLng(lastPoint);
927
1046
  }
@@ -976,7 +1095,9 @@ var SplitMode = class {
976
1095
  const processResult = (result) => {
977
1096
  const flattened = turf3.flatten(result);
978
1097
  flattened.features.forEach((f) => {
979
- const l = L12.geoJSON(f).getLayers()[0];
1098
+ const l = L12.geoJSON(f, {
1099
+ style: getModePathOptions(this.options, "split" /* Split */)
1100
+ }).getLayers()[0];
980
1101
  l.addTo(this.map);
981
1102
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: l });
982
1103
  });
@@ -1057,6 +1178,7 @@ var DragMode = class {
1057
1178
  __publicField(this, "draggingLayer", null);
1058
1179
  __publicField(this, "startLatLng", null);
1059
1180
  __publicField(this, "initialLatLngs", null);
1181
+ __publicField(this, "originalPathStyle", null);
1060
1182
  this.store.getGroup().on("layeradd", (e) => {
1061
1183
  if (this.isEnabled) {
1062
1184
  this.addLayerListener(e.layer);
@@ -1104,7 +1226,13 @@ var DragMode = class {
1104
1226
  } else if (this.draggingLayer instanceof L13.Polyline) {
1105
1227
  this.initialLatLngs = JSON.parse(JSON.stringify(this.draggingLayer.getLatLngs()));
1106
1228
  }
1107
- this.draggingLayer.setStyle({ weight: 4, color: "#ffcc00" });
1229
+ this.originalPathStyle = { ...this.draggingLayer.options };
1230
+ this.draggingLayer.setStyle(
1231
+ getModeSelectionPathOptions(this.options, "drag" /* Drag */, this.originalPathStyle, {
1232
+ weight: 4,
1233
+ color: "#ffcc00"
1234
+ })
1235
+ );
1108
1236
  }
1109
1237
  this.map.on("mousemove", this.onMouseMove, this);
1110
1238
  this.map.on("mouseup", this.onMouseUp, this);
@@ -1139,7 +1267,7 @@ var DragMode = class {
1139
1267
  onMouseUp() {
1140
1268
  if (this.draggingLayer) {
1141
1269
  if (this.draggingLayer instanceof L13.Path) {
1142
- this.draggingLayer.setStyle({ weight: 3, color: "#3388ff" });
1270
+ this.draggingLayer.setStyle(this.originalPathStyle || {});
1143
1271
  }
1144
1272
  this.map.fire(ANVIL_EVENTS.EDITED, { layer: this.draggingLayer });
1145
1273
  }
@@ -1149,16 +1277,20 @@ var DragMode = class {
1149
1277
  this.map.off("mousemove", this.onMouseMove, this);
1150
1278
  this.map.off("mouseup", this.onMouseUp, this);
1151
1279
  this.map.dragging.enable();
1280
+ if (this.draggingLayer instanceof L13.Path && this.originalPathStyle) {
1281
+ this.draggingLayer.setStyle(this.originalPathStyle);
1282
+ }
1152
1283
  this.draggingLayer = null;
1153
1284
  this.startLatLng = null;
1154
1285
  this.initialLatLngs = null;
1286
+ this.originalPathStyle = null;
1155
1287
  }
1156
1288
  };
1157
1289
 
1158
1290
  // src/modes/scale-mode.ts
1159
1291
  import * as L14 from "leaflet";
1160
1292
  var ScaleMode = class {
1161
- constructor(map, store, options) {
1293
+ constructor(map, store, options = {}) {
1162
1294
  this.map = map;
1163
1295
  this.store = store;
1164
1296
  this.options = options;
@@ -1167,6 +1299,7 @@ var ScaleMode = class {
1167
1299
  __publicField(this, "initialLatLngs", null);
1168
1300
  __publicField(this, "initialRadius", 0);
1169
1301
  __publicField(this, "initialDistance", 0);
1302
+ __publicField(this, "originalPathStyle", null);
1170
1303
  }
1171
1304
  enable() {
1172
1305
  this.store.getGroup().eachLayer((layer) => {
@@ -1195,11 +1328,20 @@ var ScaleMode = class {
1195
1328
  if (this.selectedLayer instanceof L14.Circle) {
1196
1329
  this.centerLatLng = this.selectedLayer.getLatLng();
1197
1330
  this.initialRadius = this.selectedLayer.getRadius();
1198
- } else if (this.selectedLayer instanceof L14.Path) {
1199
- const bounds = this.selectedLayer.getBounds();
1200
- this.centerLatLng = bounds.getCenter();
1201
- this.initialLatLngs = JSON.parse(JSON.stringify(this.selectedLayer.getLatLngs()));
1202
- this.selectedLayer.setStyle({ weight: 4, color: "#ffcc00" });
1331
+ }
1332
+ if (this.selectedLayer instanceof L14.Path) {
1333
+ this.originalPathStyle = { ...this.selectedLayer.options };
1334
+ this.selectedLayer.setStyle(
1335
+ getModeSelectionPathOptions(this.options, "scale" /* Scale */, this.originalPathStyle, {
1336
+ weight: 4,
1337
+ color: "#ffcc00"
1338
+ })
1339
+ );
1340
+ if (!(this.selectedLayer instanceof L14.Circle)) {
1341
+ const bounds = this.selectedLayer.getBounds();
1342
+ this.centerLatLng = bounds.getCenter();
1343
+ this.initialLatLngs = JSON.parse(JSON.stringify(this.selectedLayer.getLatLngs()));
1344
+ }
1203
1345
  }
1204
1346
  if (this.centerLatLng) {
1205
1347
  this.initialDistance = this.map.distance(this.centerLatLng, e.latlng);
@@ -1230,7 +1372,7 @@ var ScaleMode = class {
1230
1372
  onMouseUp() {
1231
1373
  if (this.selectedLayer) {
1232
1374
  if (this.selectedLayer instanceof L14.Path) {
1233
- this.selectedLayer.setStyle({ weight: 3, color: "#3388ff" });
1375
+ this.selectedLayer.setStyle(this.originalPathStyle || {});
1234
1376
  }
1235
1377
  this.map.fire(ANVIL_EVENTS.EDITED, { layer: this.selectedLayer });
1236
1378
  }
@@ -1240,16 +1382,20 @@ var ScaleMode = class {
1240
1382
  this.map.off("mousemove", this.onMouseMove, this);
1241
1383
  this.map.off("mouseup", this.onMouseUp, this);
1242
1384
  this.map.dragging.enable();
1385
+ if (this.selectedLayer instanceof L14.Path && this.originalPathStyle) {
1386
+ this.selectedLayer.setStyle(this.originalPathStyle);
1387
+ }
1243
1388
  this.selectedLayer = null;
1244
1389
  this.centerLatLng = null;
1245
1390
  this.initialLatLngs = null;
1391
+ this.originalPathStyle = null;
1246
1392
  }
1247
1393
  };
1248
1394
 
1249
1395
  // src/modes/rotate-mode.ts
1250
1396
  import * as L15 from "leaflet";
1251
1397
  var RotateMode = class {
1252
- constructor(map, store, options) {
1398
+ constructor(map, store, options = {}) {
1253
1399
  this.map = map;
1254
1400
  this.store = store;
1255
1401
  this.options = options;
@@ -1257,6 +1403,7 @@ var RotateMode = class {
1257
1403
  __publicField(this, "centerLatLng", null);
1258
1404
  __publicField(this, "initialLatLngs", null);
1259
1405
  __publicField(this, "startAngle", 0);
1406
+ __publicField(this, "originalPathStyle", null);
1260
1407
  }
1261
1408
  enable() {
1262
1409
  this.store.getGroup().eachLayer((layer) => {
@@ -1286,10 +1433,16 @@ var RotateMode = class {
1286
1433
  const bounds = pathLayer.getBounds();
1287
1434
  this.centerLatLng = bounds.getCenter();
1288
1435
  this.initialLatLngs = JSON.parse(JSON.stringify(pathLayer.getLatLngs()));
1436
+ this.originalPathStyle = { ...pathLayer.options };
1289
1437
  const point2 = this.map.latLngToContainerPoint(e.latlng);
1290
1438
  const centerPoint = this.map.latLngToContainerPoint(this.centerLatLng);
1291
1439
  this.startAngle = Math.atan2(point2.y - centerPoint.y, point2.x - centerPoint.x);
1292
- pathLayer.setStyle({ weight: 4, color: "#ffcc00" });
1440
+ pathLayer.setStyle(
1441
+ getModeSelectionPathOptions(this.options, "rotate" /* Rotate */, this.originalPathStyle, {
1442
+ weight: 4,
1443
+ color: "#ffcc00"
1444
+ })
1445
+ );
1293
1446
  this.map.on("mousemove", this.onMouseMove, this);
1294
1447
  this.map.on("mouseup", this.onMouseUp, this);
1295
1448
  this.map.dragging.disable();
@@ -1319,7 +1472,7 @@ var RotateMode = class {
1319
1472
  }
1320
1473
  onMouseUp() {
1321
1474
  if (this.selectedLayer) {
1322
- this.selectedLayer.setStyle({ weight: 3, color: "#3388ff" });
1475
+ this.selectedLayer.setStyle(this.originalPathStyle || {});
1323
1476
  this.map.fire(ANVIL_EVENTS.EDITED, { layer: this.selectedLayer });
1324
1477
  }
1325
1478
  this.stopRotating();
@@ -1328,9 +1481,13 @@ var RotateMode = class {
1328
1481
  this.map.off("mousemove", this.onMouseMove, this);
1329
1482
  this.map.off("mouseup", this.onMouseUp, this);
1330
1483
  this.map.dragging.enable();
1484
+ if (this.selectedLayer && this.originalPathStyle) {
1485
+ this.selectedLayer.setStyle(this.originalPathStyle);
1486
+ }
1331
1487
  this.selectedLayer = null;
1332
1488
  this.centerLatLng = null;
1333
1489
  this.initialLatLngs = null;
1490
+ this.originalPathStyle = null;
1334
1491
  }
1335
1492
  };
1336
1493
 
@@ -1343,6 +1500,7 @@ var UnionMode = class {
1343
1500
  this.store = store;
1344
1501
  this.options = options;
1345
1502
  __publicField(this, "firstLayer", null);
1503
+ __publicField(this, "firstLayerStyle", null);
1346
1504
  }
1347
1505
  enable() {
1348
1506
  this.store.getGroup().eachLayer((layer) => {
@@ -1366,7 +1524,13 @@ var UnionMode = class {
1366
1524
  const layer = e.target;
1367
1525
  if (!this.firstLayer) {
1368
1526
  this.firstLayer = layer;
1369
- this.firstLayer.setStyle({ color: "#ff00ff", weight: 4 });
1527
+ this.firstLayerStyle = { ...layer.options };
1528
+ this.firstLayer.setStyle(
1529
+ getModeSelectionPathOptions(this.options, "union" /* Union */, this.firstLayerStyle, {
1530
+ color: "#ff00ff",
1531
+ weight: 4
1532
+ })
1533
+ );
1370
1534
  return;
1371
1535
  }
1372
1536
  if (this.firstLayer === layer) {
@@ -1388,18 +1552,20 @@ var UnionMode = class {
1388
1552
  const flattened = turf4.flatten(united);
1389
1553
  flattened.features.forEach((f) => {
1390
1554
  const newLayerGroup = L16.geoJSON(f, {
1391
- style: this.options.pathOptions
1555
+ style: getModePathOptions(this.options, "union" /* Union */)
1392
1556
  });
1393
1557
  const l = newLayerGroup.getLayers()[0];
1394
1558
  l.addTo(this.map);
1395
1559
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: l });
1396
1560
  });
1397
1561
  this.firstLayer = null;
1562
+ this.firstLayerStyle = null;
1398
1563
  }
1399
1564
  reset() {
1400
1565
  if (this.firstLayer) {
1401
- this.firstLayer.setStyle({ color: "#3388ff", weight: 3, ...this.options.pathOptions });
1566
+ this.firstLayer.setStyle(this.firstLayerStyle || {});
1402
1567
  this.firstLayer = null;
1568
+ this.firstLayerStyle = null;
1403
1569
  }
1404
1570
  }
1405
1571
  };
@@ -1413,6 +1579,7 @@ var SubtractMode = class {
1413
1579
  this.store = store;
1414
1580
  this.options = options;
1415
1581
  __publicField(this, "baseLayer", null);
1582
+ __publicField(this, "baseLayerStyle", null);
1416
1583
  }
1417
1584
  enable() {
1418
1585
  this.store.getGroup().eachLayer((layer) => {
@@ -1436,7 +1603,13 @@ var SubtractMode = class {
1436
1603
  const layer = e.target;
1437
1604
  if (!this.baseLayer) {
1438
1605
  this.baseLayer = layer;
1439
- this.baseLayer.setStyle({ color: "#ff0000", weight: 4 });
1606
+ this.baseLayerStyle = { ...layer.options };
1607
+ this.baseLayer.setStyle(
1608
+ getModeSelectionPathOptions(this.options, "subtract" /* Subtract */, this.baseLayerStyle, {
1609
+ color: "#ff0000",
1610
+ weight: 4
1611
+ })
1612
+ );
1440
1613
  return;
1441
1614
  }
1442
1615
  if (this.baseLayer === layer) {
@@ -1453,18 +1626,22 @@ var SubtractMode = class {
1453
1626
  if (diff) {
1454
1627
  const flattened = turf5.flatten(diff);
1455
1628
  flattened.features.forEach((f) => {
1456
- const newLayerGroup = L17.geoJSON(f);
1629
+ const newLayerGroup = L17.geoJSON(f, {
1630
+ style: getModePathOptions(this.options, "subtract" /* Subtract */)
1631
+ });
1457
1632
  const l = newLayerGroup.getLayers()[0];
1458
1633
  l.addTo(this.map);
1459
1634
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: l });
1460
1635
  });
1461
1636
  }
1462
1637
  this.baseLayer = null;
1638
+ this.baseLayerStyle = null;
1463
1639
  }
1464
1640
  reset() {
1465
1641
  if (this.baseLayer) {
1466
- this.baseLayer.setStyle({ color: "#3388ff", weight: 3 });
1642
+ this.baseLayer.setStyle(this.baseLayerStyle || {});
1467
1643
  this.baseLayer = null;
1644
+ this.baseLayerStyle = null;
1468
1645
  }
1469
1646
  }
1470
1647
  };
@@ -1481,6 +1658,7 @@ var EditMode = class {
1481
1658
  __publicField(this, "ghostMarker", null);
1482
1659
  __publicField(this, "segments", []);
1483
1660
  __publicField(this, "_isDragging", false);
1661
+ __publicField(this, "originalLayerStyles", /* @__PURE__ */ new Map());
1484
1662
  }
1485
1663
  enable() {
1486
1664
  this.store.getGroup().eachLayer((layer) => {
@@ -1499,13 +1677,11 @@ var EditMode = class {
1499
1677
  layer.off("click", this.onLayerClick, this);
1500
1678
  layer.off("mousemove", this.onMouseMove, this);
1501
1679
  layer.getElement()?.style.setProperty("cursor", "");
1502
- if (layer instanceof L18.Path) {
1503
- layer.setStyle({ color: "#3388ff", weight: 3, fillOpacity: 0.2 });
1504
- }
1505
1680
  }
1506
1681
  });
1507
1682
  this.map.off("click", this.onMapClick, this);
1508
1683
  this.map.off("mousemove", this.onMouseMove, this);
1684
+ this.restoreAllPathStyles();
1509
1685
  this.clearMarkers();
1510
1686
  this.activeLayers.clear();
1511
1687
  }
@@ -1515,27 +1691,26 @@ var EditMode = class {
1515
1691
  const isMultiSelect = e.originalEvent.shiftKey || this.options.magnetic;
1516
1692
  if (!isMultiSelect) {
1517
1693
  if (this.activeLayers.has(layer) && this.activeLayers.size === 1) return;
1518
- this.activeLayers.forEach((l) => {
1519
- if (l instanceof L18.Path) l.setStyle({ color: "#3388ff", weight: 3 });
1520
- });
1694
+ this.restoreAllPathStyles();
1521
1695
  this.clearMarkers();
1522
1696
  this.activeLayers.clear();
1523
1697
  this.activeLayers.add(layer);
1524
1698
  } else {
1525
1699
  if (this.activeLayers.has(layer)) {
1526
1700
  this.activeLayers.delete(layer);
1527
- if (layer instanceof L18.Path) layer.setStyle({ color: "#3388ff", weight: 3 });
1701
+ if (layer instanceof L18.Path) this.restorePathStyle(layer);
1528
1702
  } else {
1529
1703
  this.activeLayers.add(layer);
1530
1704
  }
1531
1705
  this.clearMarkers();
1532
1706
  }
1533
1707
  this.activeLayers.forEach((l) => {
1534
- if (l instanceof L18.Path) l.setStyle({ color: "#ff00ff", weight: 4 });
1708
+ if (l instanceof L18.Path) this.applySelectionStyle(l);
1535
1709
  });
1536
1710
  this.createMarkers();
1537
1711
  }
1538
1712
  onMapClick() {
1713
+ this.restoreAllPathStyles();
1539
1714
  this.clearMarkers();
1540
1715
  this.activeLayers.clear();
1541
1716
  }
@@ -1590,17 +1765,17 @@ var EditMode = class {
1590
1765
  });
1591
1766
  this.segments = Array.from(segmentMap.values());
1592
1767
  vertexMap.forEach((group) => {
1593
- const marker4 = this.createEditMarker(group.latlng);
1594
- group.marker = marker4;
1595
- this.markers.push(marker4);
1596
- marker4.on("dragstart", () => {
1768
+ const marker3 = this.createEditMarker(group.latlng);
1769
+ group.marker = marker3;
1770
+ this.markers.push(marker3);
1771
+ marker3.on("dragstart", () => {
1597
1772
  this._isDragging = true;
1598
1773
  });
1599
- marker4.on("drag", (e) => {
1774
+ marker3.on("drag", (e) => {
1600
1775
  const mouseEvent = e;
1601
1776
  const skipLayersArray = Array.from(this.activeLayers);
1602
1777
  const additionalPoints = [
1603
- ...this.markers.filter((m) => m !== marker4).map((m) => m.getLatLng()),
1778
+ ...this.markers.filter((m) => m !== marker3).map((m) => m.getLatLng()),
1604
1779
  ...Array.from(this.activeLayers).filter((l) => l instanceof L18.Marker).map((l) => l.getLatLng())
1605
1780
  ];
1606
1781
  const snapped = getSnapLatLng(this.map, mouseEvent.latlng, this.store, this.options, additionalPoints, skipLayersArray);
@@ -1621,7 +1796,7 @@ var EditMode = class {
1621
1796
  });
1622
1797
  if (wouldIntersect) return;
1623
1798
  }
1624
- marker4.setLatLng(snapped);
1799
+ marker3.setLatLng(snapped);
1625
1800
  group.latlng = snapped;
1626
1801
  group.refs.forEach((ref) => {
1627
1802
  const fullStructure = ref.layer.getLatLngs();
@@ -1634,12 +1809,12 @@ var EditMode = class {
1634
1809
  ref.layer.redraw();
1635
1810
  });
1636
1811
  });
1637
- marker4.on("dragend", () => {
1812
+ marker3.on("dragend", () => {
1638
1813
  this._isDragging = false;
1639
1814
  this.activeLayers.forEach((l) => this.map.fire(ANVIL_EVENTS.EDITED, { layer: l }));
1640
1815
  this.refreshMarkers();
1641
1816
  });
1642
- marker4.on("contextmenu", (e) => {
1817
+ marker3.on("contextmenu", (e) => {
1643
1818
  const mouseEvent = e;
1644
1819
  L18.DomEvent.stopPropagation(mouseEvent);
1645
1820
  this.deleteVertex(group);
@@ -1668,6 +1843,9 @@ var EditMode = class {
1668
1843
  });
1669
1844
  layersToDelete.forEach((layer) => {
1670
1845
  this.activeLayers.delete(layer);
1846
+ if (layer instanceof L18.Path) {
1847
+ this.originalLayerStyles.delete(layer);
1848
+ }
1671
1849
  this.map.removeLayer(layer);
1672
1850
  this.map.fire(ANVIL_EVENTS.DELETED, { layer });
1673
1851
  });
@@ -1709,14 +1887,15 @@ var EditMode = class {
1709
1887
  }
1710
1888
  }
1711
1889
  createEditMarker(latlng) {
1890
+ const visuals = this.getEditHandleVisuals();
1712
1891
  return L18.marker(latlng, {
1713
1892
  draggable: true,
1714
1893
  zIndexOffset: 2e3,
1715
1894
  icon: L18.divIcon({
1716
1895
  className: "anvil-edit-marker",
1717
- html: '<div style="width: 12px; height: 12px; background: #fff; border: 2px solid #ff00ff; border-radius: 50%; box-sizing: border-box; box-shadow: 0 0 4px rgba(0,0,0,0.3);"></div>',
1718
- iconSize: [12, 12],
1719
- iconAnchor: [6, 6]
1896
+ html: this.createHandleHtml(visuals.size, visuals.fillColor, visuals.borderColor, visuals.borderWidth),
1897
+ iconSize: [visuals.size, visuals.size],
1898
+ iconAnchor: [visuals.size / 2, visuals.size / 2]
1720
1899
  })
1721
1900
  }).addTo(this.map);
1722
1901
  }
@@ -1728,15 +1907,16 @@ var EditMode = class {
1728
1907
  }
1729
1908
  return;
1730
1909
  }
1910
+ const visuals = this.getGhostHandleVisuals();
1731
1911
  this.ghostMarker = L18.marker(latlng, {
1732
1912
  draggable: true,
1733
1913
  opacity: 0.7,
1734
1914
  zIndexOffset: 3e3,
1735
1915
  icon: L18.divIcon({
1736
1916
  className: "anvil-ghost-marker",
1737
- html: '<div style="width: 10px; height: 10px; background: #ff00ff; border: 2px solid #fff; border-radius: 50%; box-sizing: border-box; box-shadow: 0 0 4px rgba(0,0,0,0.3);"></div>',
1738
- iconSize: [10, 10],
1739
- iconAnchor: [5, 5]
1917
+ html: this.createHandleHtml(visuals.size, visuals.fillColor, visuals.borderColor, visuals.borderWidth),
1918
+ iconSize: [visuals.size, visuals.size],
1919
+ iconAnchor: [visuals.size / 2, visuals.size / 2]
1740
1920
  })
1741
1921
  }).addTo(this.map);
1742
1922
  this.ghostMarker.on("dragstart", () => {
@@ -1805,47 +1985,48 @@ var EditMode = class {
1805
1985
  this.ghostMarker = null;
1806
1986
  }
1807
1987
  }
1808
- handleMarkerEdit(marker4) {
1809
- marker4.dragging?.enable();
1810
- marker4.on("drag", (e) => {
1988
+ handleMarkerEdit(marker3) {
1989
+ marker3.dragging?.enable();
1990
+ marker3.on("drag", (e) => {
1811
1991
  const mouseEvent = e;
1812
1992
  const additionalPoints = this.markers.map((m) => m.getLatLng());
1813
- const snapped = getSnapLatLng(this.map, mouseEvent.latlng, this.store, this.options, additionalPoints, marker4);
1814
- marker4.setLatLng(snapped);
1993
+ const snapped = getSnapLatLng(this.map, mouseEvent.latlng, this.store, this.options, additionalPoints, marker3);
1994
+ marker3.setLatLng(snapped);
1815
1995
  });
1816
- marker4.on("dragend", () => {
1817
- this.map.fire(ANVIL_EVENTS.EDITED, { layer: marker4 });
1996
+ marker3.on("dragend", () => {
1997
+ this.map.fire(ANVIL_EVENTS.EDITED, { layer: marker3 });
1818
1998
  });
1819
- marker4.on("contextmenu", (e) => {
1999
+ marker3.on("contextmenu", (e) => {
1820
2000
  const mouseEvent = e;
1821
2001
  L18.DomEvent.stopPropagation(mouseEvent);
1822
- this.activeLayers.delete(marker4);
1823
- this.map.removeLayer(marker4);
1824
- this.map.fire(ANVIL_EVENTS.DELETED, { layer: marker4 });
2002
+ this.activeLayers.delete(marker3);
2003
+ this.map.removeLayer(marker3);
2004
+ this.map.fire(ANVIL_EVENTS.DELETED, { layer: marker3 });
1825
2005
  this.refreshMarkers();
1826
2006
  });
1827
2007
  }
1828
2008
  handleCircleEdit(circle2) {
1829
- const marker4 = this.createEditMarker(circle2.getLatLng());
1830
- marker4.on("drag", (e) => {
2009
+ const marker3 = this.createEditMarker(circle2.getLatLng());
2010
+ marker3.on("drag", (e) => {
1831
2011
  const mouseEvent = e;
1832
- const additionalPoints = this.markers.filter((m) => m !== marker4).map((m) => m.getLatLng());
2012
+ const additionalPoints = this.markers.filter((m) => m !== marker3).map((m) => m.getLatLng());
1833
2013
  const snapped = getSnapLatLng(this.map, mouseEvent.latlng, this.store, this.options, additionalPoints, circle2);
1834
- marker4.setLatLng(snapped);
2014
+ marker3.setLatLng(snapped);
1835
2015
  circle2.setLatLng(snapped);
1836
2016
  });
1837
- marker4.on("dragend", () => {
2017
+ marker3.on("dragend", () => {
1838
2018
  this.map.fire(ANVIL_EVENTS.EDITED, { layer: circle2 });
1839
2019
  });
1840
- marker4.on("contextmenu", (e) => {
2020
+ marker3.on("contextmenu", (e) => {
1841
2021
  const mouseEvent = e;
1842
2022
  L18.DomEvent.stopPropagation(mouseEvent);
1843
2023
  this.activeLayers.delete(circle2);
2024
+ this.originalLayerStyles.delete(circle2);
1844
2025
  this.map.removeLayer(circle2);
1845
2026
  this.map.fire(ANVIL_EVENTS.DELETED, { layer: circle2 });
1846
2027
  this.refreshMarkers();
1847
2028
  });
1848
- this.markers.push(marker4);
2029
+ this.markers.push(marker3);
1849
2030
  }
1850
2031
  clearMarkers() {
1851
2032
  this.activeLayers.forEach((layer) => {
@@ -1864,6 +2045,64 @@ var EditMode = class {
1864
2045
  this.clearMarkers();
1865
2046
  this.createMarkers();
1866
2047
  }
2048
+ applySelectionStyle(layer) {
2049
+ if (!this.originalLayerStyles.has(layer)) {
2050
+ this.originalLayerStyles.set(layer, { ...layer.options });
2051
+ }
2052
+ layer.setStyle(
2053
+ getModeSelectionPathOptions(this.options, "edit" /* Edit */, this.originalLayerStyles.get(layer) || {}, {
2054
+ color: "#ff00ff",
2055
+ weight: 4
2056
+ })
2057
+ );
2058
+ }
2059
+ restorePathStyle(layer) {
2060
+ const original = this.originalLayerStyles.get(layer);
2061
+ if (!original) return;
2062
+ layer.setStyle(original);
2063
+ this.originalLayerStyles.delete(layer);
2064
+ }
2065
+ restoreAllPathStyles() {
2066
+ this.originalLayerStyles.forEach((style, layer) => {
2067
+ layer.setStyle(style);
2068
+ });
2069
+ this.originalLayerStyles.clear();
2070
+ }
2071
+ getEditHandleVisuals() {
2072
+ const selection = getModeSelectionPathOptions(this.options, "edit" /* Edit */, {}, { color: "#ff00ff" });
2073
+ const handle = getModeHandleOptions(this.options, "edit" /* Edit */, {
2074
+ radius: 6,
2075
+ color: selection.color || "#ff00ff",
2076
+ fillColor: "#fff",
2077
+ fillOpacity: 1,
2078
+ weight: 2
2079
+ });
2080
+ return {
2081
+ size: (handle.radius || 6) * 2,
2082
+ fillColor: handle.fillColor || "#fff",
2083
+ borderColor: handle.color || (selection.color || "#ff00ff"),
2084
+ borderWidth: handle.weight || 2
2085
+ };
2086
+ }
2087
+ getGhostHandleVisuals() {
2088
+ const selection = getModeSelectionPathOptions(this.options, "edit" /* Edit */, {}, { color: "#ff00ff" });
2089
+ const handle = getModeHandleOptions(this.options, "edit" /* Edit */, {
2090
+ radius: 5,
2091
+ color: "#fff",
2092
+ fillColor: selection.color || "#ff00ff",
2093
+ fillOpacity: 1,
2094
+ weight: 2
2095
+ });
2096
+ return {
2097
+ size: (handle.radius || 5) * 2,
2098
+ fillColor: handle.fillColor || (selection.color || "#ff00ff"),
2099
+ borderColor: handle.color || "#fff",
2100
+ borderWidth: handle.weight || 2
2101
+ };
2102
+ }
2103
+ createHandleHtml(size, fillColor, borderColor, borderWidth) {
2104
+ return `<div style="width: ${size}px; height: ${size}px; background: ${fillColor}; border: ${borderWidth}px solid ${borderColor}; border-radius: 50%; box-sizing: border-box; box-shadow: 0 0 4px rgba(0,0,0,0.3);"></div>`;
2105
+ }
1867
2106
  };
1868
2107
 
1869
2108
  // src/modes/delete-mode.ts
@@ -1938,45 +2177,117 @@ var LayerStore = class {
1938
2177
 
1939
2178
  // src/controls/anvil-control.ts
1940
2179
  import * as L21 from "leaflet";
1941
- var SVG_ATTRS = 'xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"';
1942
- var ICONS = {
1943
- // Marker: Map-Pin mit Punkt in der Mitte
1944
- ["marker" /* Marker */]: `<svg ${SVG_ATTRS}><path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z"/><circle cx="12" cy="10" r="3"/></svg>`,
1945
- // Polyline: Kurvige Route mit Endpunkten
1946
- ["polyline" /* Polyline */]: `<svg ${SVG_ATTRS}><path d="M9 19h8.5a3.5 3.5 0 0 0 0-7h-11a3.5 3.5 0 0 1 0-7H15"/><circle cx="18" cy="5" r="3"/><circle cx="6" cy="19" r="3"/></svg>`,
1947
- // Polygon: Klassische unregelmäßige 5-Eck-Form
1948
- ["polygon" /* Polygon */]: `<svg ${SVG_ATTRS}><path d="m12 2 10 7-3 12H5l-3-12Z"/></svg>`,
1949
- // Rectangle: Horizontales Rechteck
1950
- ["rectangle" /* Rectangle */]: `<svg ${SVG_ATTRS}><rect width="20" height="12" x="2" y="6" rx="2"/></svg>`,
1951
- // Square: Quadratisches Rechteck (1:1)
1952
- ["square" /* Square */]: `<svg ${SVG_ATTRS}><rect width="18" height="18" x="3" y="3" rx="2"/></svg>`,
1953
- // Triangle: Gleichschenkliges Dreieck
1954
- ["triangle" /* Triangle */]: `<svg ${SVG_ATTRS}><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/></svg>`,
1955
- // Circle: Klassischer Kreis
1956
- ["circle" /* Circle */]: `<svg ${SVG_ATTRS}><circle cx="12" cy="12" r="10"/></svg>`,
1957
- // Freehand: Geschwungene Signatur-Linie
1958
- ["freehand" /* Freehand */]: `<svg ${SVG_ATTRS}><path d="m3 16 2 2 16-16"/><path d="M7 21h14"/><path d="M3 11c0 2 2 2 2 2z"/></svg>`,
1959
- // Cut: Offene Schere
1960
- ["cut" /* Cut */]: `<svg ${SVG_ATTRS}><circle cx="6" cy="6" r="3"/><circle cx="6" cy="18" r="3"/><path d="M20 4 8.12 15.88"/><path d="M14.47 14.48 20 20"/><path d="M8.12 8.12 12 12"/></svg>`,
1961
- // Split: Linie, die eine Form teilt
1962
- ["split" /* Split */]: `<svg ${SVG_ATTRS}><path d="M3 12h18"/><path d="M8 3v18"/><path d="M16 3v18"/><rect width="18" height="18" x="3" y="3" rx="2" stroke-dasharray="4 4" opacity="0.5"/></svg>`,
1963
- // Union: Zwei verschmolzene Rechtecke
1964
- ["union" /* Union */]: `<svg ${SVG_ATTRS}><path d="M8 4H4v4"/><path d="M4 12v4a2 2 0 0 0 2 2h4"/><path d="M14 18h4v-4"/><path d="M20 10V6a2 2 0 0 0-2-2h-4"/><path d="M14 10h-4v4" stroke-dasharray="2 2"/></svg>`,
1965
- // Subtract: Hauptform mit "ausgeschnittenem" Bereich (Minus-Metapher)
1966
- ["subtract" /* Subtract */]: `<svg ${SVG_ATTRS}><path d="M4 4h16v16H4z"/><path d="M10 10h10v10H10z" stroke-dasharray="2 2" opacity="0.7"/><path d="M15 6h-6"/></svg>`,
1967
- // Drag: Vier-Wege-Pfeil (Move-Metapher)
1968
- ["drag" /* Drag */]: `<svg ${SVG_ATTRS}><path d="m5 9-3 3 3 3"/><path d="m9 5 3-3 3 3"/><path d="m15 19 3 3 3-3"/><path d="m19 9 3 3-3 3"/><path d="M2 12h20"/><path d="M12 2v20"/></svg>`,
1969
- // Scale: Diagonal-Pfeile (Maximize-Metapher)
1970
- ["scale" /* Scale */]: `<svg ${SVG_ATTRS}><path d="M15 3h6v6"/><path d="M9 21H3v-6"/><path d="M21 3 14 10"/><path d="M3 21l7-7"/></svg>`,
1971
- // Rotate: Kreispfeil mit Ziel-Icon
1972
- ["rotate" /* Rotate */]: `<svg ${SVG_ATTRS}><path d="M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/></svg>`,
1973
- // Edit: Stift, der über einen Pfad zeichnet
1974
- ["edit" /* Edit */]: `<svg ${SVG_ATTRS}><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>`,
1975
- // Delete: Mülleimer mit Deckel und Schlitzen
1976
- ["delete" /* Delete */]: `<svg ${SVG_ATTRS}><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" x2="10" y1="11" y2="17"/><line x1="14" x2="14" y1="11" y2="17"/></svg>`,
1977
- // Off: Durchgestrichener Kreis (Power-Off/Disable Metapher)
1978
- ["off" /* Off */]: `<svg ${SVG_ATTRS}><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></svg>`
1979
- };
2180
+ import {
2181
+ Circle as Circle6,
2182
+ Hand,
2183
+ MapPin,
2184
+ Move,
2185
+ Pentagon,
2186
+ Power,
2187
+ RectangleHorizontal,
2188
+ RotateCw,
2189
+ Scaling,
2190
+ Scissors,
2191
+ Split,
2192
+ Square,
2193
+ SquarePen,
2194
+ SquaresSubtract,
2195
+ SquaresUnite,
2196
+ Trash2,
2197
+ Triangle,
2198
+ Waypoints,
2199
+ createElement
2200
+ } from "lucide";
2201
+ var ANVIL_TOOLBAR_STYLE_ID = "anvil-toolbar-styles";
2202
+ var MODE_CONFIGS = [
2203
+ { id: "marker" /* Marker */, title: "Marker", icon: MapPin },
2204
+ { id: "polyline" /* Polyline */, title: "Line", icon: Waypoints },
2205
+ { id: "polygon" /* Polygon */, title: "Polygon", icon: Pentagon },
2206
+ { id: "rectangle" /* Rectangle */, title: "Rectangle", icon: RectangleHorizontal },
2207
+ { id: "square" /* Square */, title: "Square", icon: Square },
2208
+ { id: "triangle" /* Triangle */, title: "Triangle", icon: Triangle },
2209
+ { id: "circle" /* Circle */, title: "Circle", icon: Circle6 },
2210
+ { id: "freehand" /* Freehand */, title: "Freehand", icon: Hand },
2211
+ { id: "cut" /* Cut */, title: "Cut", icon: Scissors },
2212
+ { id: "split" /* Split */, title: "Split", icon: Split },
2213
+ { id: "union" /* Union */, title: "Union", icon: SquaresUnite },
2214
+ { id: "subtract" /* Subtract */, title: "Subtract", icon: SquaresSubtract },
2215
+ { id: "drag" /* Drag */, title: "Drag", icon: Move },
2216
+ { id: "scale" /* Scale */, title: "Scale", icon: Scaling },
2217
+ { id: "rotate" /* Rotate */, title: "Rotate", icon: RotateCw },
2218
+ { id: "edit" /* Edit */, title: "Edit", icon: SquarePen },
2219
+ { id: "delete" /* Delete */, title: "Delete", icon: Trash2 },
2220
+ { id: "off" /* Off */, title: "Turn Off", icon: Power }
2221
+ ];
2222
+ function ensureToolbarStyles() {
2223
+ if (typeof document === "undefined" || document.getElementById(ANVIL_TOOLBAR_STYLE_ID)) return;
2224
+ const style = document.createElement("style");
2225
+ style.id = ANVIL_TOOLBAR_STYLE_ID;
2226
+ style.textContent = `
2227
+ .anvil-toolbar-container {
2228
+ display: flex;
2229
+ flex-direction: column;
2230
+ gap: 8px;
2231
+ }
2232
+
2233
+ .anvil-toolbar-group {
2234
+ overflow: hidden;
2235
+ }
2236
+
2237
+ .anvil-toolbar-group .anvil-control-btn {
2238
+ display: flex;
2239
+ align-items: center;
2240
+ justify-content: center;
2241
+ width: 30px;
2242
+ height: 30px;
2243
+ color: #2f3b52;
2244
+ transition: background-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
2245
+ }
2246
+
2247
+ .anvil-toolbar-group .anvil-control-btn svg {
2248
+ width: 16px;
2249
+ height: 16px;
2250
+ stroke-width: 2.1;
2251
+ }
2252
+
2253
+ .anvil-toolbar-group .anvil-control-btn:hover,
2254
+ .anvil-toolbar-group .anvil-control-btn:focus-visible {
2255
+ background-color: #f3f6fb;
2256
+ color: #0f172a;
2257
+ }
2258
+
2259
+ .anvil-toolbar-group .anvil-control-btn:focus-visible {
2260
+ outline: none;
2261
+ box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.35);
2262
+ }
2263
+
2264
+ .anvil-toolbar-group .anvil-control-btn.is-active {
2265
+ background-color: #2563eb;
2266
+ color: #fff;
2267
+ box-shadow: inset 0 0 0 1px rgba(29, 78, 216, 0.45), 0 1px 3px rgba(37, 99, 235, 0.25);
2268
+ }
2269
+
2270
+ .anvil-toolbar-group .anvil-control-btn.is-active:hover,
2271
+ .anvil-toolbar-group .anvil-control-btn.is-active:focus-visible {
2272
+ background-color: #1d4ed8;
2273
+ color: #fff;
2274
+ }
2275
+ `;
2276
+ document.head.appendChild(style);
2277
+ }
2278
+ function setButtonState(button, active) {
2279
+ button.classList.toggle("is-active", active);
2280
+ button.setAttribute("aria-pressed", active ? "true" : "false");
2281
+ }
2282
+ function buildIcon(iconNode) {
2283
+ return createElement(iconNode, {
2284
+ width: 16,
2285
+ height: 16,
2286
+ "stroke-width": 2.1,
2287
+ "aria-hidden": "true",
2288
+ focusable: "false"
2289
+ });
2290
+ }
1980
2291
  var AnvilControl = class extends L21.Control {
1981
2292
  constructor(anvil, options) {
1982
2293
  super(L21.Util.extend({ position: "topleft" }, options));
@@ -1987,88 +2298,43 @@ var AnvilControl = class extends L21.Control {
1987
2298
  this._options = { ...options };
1988
2299
  }
1989
2300
  onAdd(map) {
1990
- console.log("AnvilControl: triggering onAdd");
2301
+ ensureToolbarStyles();
1991
2302
  const container = L21.DomUtil.create("div", "anvil-toolbar-container");
1992
- container.style.display = "flex";
1993
- container.style.flexDirection = "column";
1994
- container.style.gap = "10px";
1995
- const allModeConfigs = [
1996
- { id: "marker" /* Marker */, title: "Marker" },
1997
- { id: "polyline" /* Polyline */, title: "Line" },
1998
- { id: "polygon" /* Polygon */, title: "Polygon" },
1999
- { id: "rectangle" /* Rectangle */, title: "Rectangle" },
2000
- { id: "square" /* Square */, title: "Square" },
2001
- { id: "triangle" /* Triangle */, title: "Triangle" },
2002
- { id: "circle" /* Circle */, title: "Circle" },
2003
- { id: "freehand" /* Freehand */, title: "Freehand" },
2004
- { id: "cut" /* Cut */, title: "Cut" },
2005
- { id: "split" /* Split */, title: "Split" },
2006
- { id: "union" /* Union */, title: "Union" },
2007
- { id: "subtract" /* Subtract */, title: "Subtract" },
2008
- { id: "drag" /* Drag */, title: "Drag" },
2009
- { id: "scale" /* Scale */, title: "Scale" },
2010
- { id: "rotate" /* Rotate */, title: "Rotate" },
2011
- { id: "edit" /* Edit */, title: "Edit" },
2012
- { id: "delete" /* Delete */, title: "Delete" }
2013
- ];
2014
- const modesInput = this._options.modes || allModeConfigs.map((m) => m.id);
2303
+ const modesInput = this._options.modes || MODE_CONFIGS.filter(({ id }) => id !== "off" /* Off */).map(({ id }) => id);
2015
2304
  const blocks = Array.isArray(modesInput[0]) ? modesInput : [modesInput];
2305
+ const createButton = (group, config) => {
2306
+ const btn = L21.DomUtil.create("a", "anvil-control-btn", group);
2307
+ btn.href = "#";
2308
+ btn.title = config.title;
2309
+ btn.setAttribute("role", "button");
2310
+ btn.setAttribute("aria-label", config.title);
2311
+ btn.appendChild(buildIcon(config.icon));
2312
+ L21.DomEvent.disableClickPropagation(btn);
2313
+ L21.DomEvent.on(btn, "click", (e) => {
2314
+ L21.DomEvent.preventDefault(e);
2315
+ if (config.id === "off" /* Off */) {
2316
+ this._anvil.disable();
2317
+ } else {
2318
+ this._anvil.enable(config.id);
2319
+ }
2320
+ });
2321
+ this._btns[config.id] = btn;
2322
+ };
2016
2323
  blocks.forEach((block, index) => {
2017
2324
  const group = L21.DomUtil.create("div", "leaflet-bar anvil-toolbar-group", container);
2018
- group.style.display = "flex";
2019
- group.style.flexDirection = "column";
2020
- group.style.backgroundColor = "white";
2021
2325
  block.forEach((modeId) => {
2022
- const config = allModeConfigs.find((c) => c.id === modeId);
2023
- if (!config && modeId !== "off" /* Off */) return;
2024
- const id = modeId;
2025
- const title = config ? config.title : "Turn Off";
2026
- const btn = L21.DomUtil.create("a", "anvil-control-btn", group);
2027
- btn.innerHTML = ICONS[id] || title;
2028
- btn.href = "#";
2029
- btn.title = title;
2030
- btn.style.display = "flex";
2031
- btn.style.alignItems = "center";
2032
- btn.style.justifyContent = "center";
2033
- btn.style.width = "30px";
2034
- btn.style.height = "30px";
2035
- btn.style.color = "#333";
2036
- btn.style.cursor = "pointer";
2037
- L21.DomEvent.disableClickPropagation(btn);
2038
- L21.DomEvent.on(btn, "click", (e) => {
2039
- L21.DomEvent.preventDefault(e);
2040
- if (id === "off" /* Off */) {
2041
- this._anvil.disable();
2042
- } else {
2043
- this._anvil.enable(id);
2044
- }
2045
- });
2046
- this._btns[id] = btn;
2326
+ const config = MODE_CONFIGS.find(({ id }) => id === modeId);
2327
+ if (!config) return;
2328
+ createButton(group, config);
2047
2329
  });
2048
2330
  if (index === blocks.length - 1 && !this._btns["off" /* Off */]) {
2049
- const offBtn = L21.DomUtil.create("a", "anvil-control-btn", group);
2050
- offBtn.innerHTML = ICONS["off" /* Off */];
2051
- offBtn.href = "#";
2052
- offBtn.title = "Turn Off";
2053
- offBtn.style.display = "flex";
2054
- offBtn.style.alignItems = "center";
2055
- offBtn.style.justifyContent = "center";
2056
- offBtn.style.width = "30px";
2057
- offBtn.style.height = "30px";
2058
- offBtn.style.color = "#333";
2059
- offBtn.style.cursor = "pointer";
2060
- L21.DomEvent.disableClickPropagation(offBtn);
2061
- L21.DomEvent.on(offBtn, "click", (e) => {
2062
- L21.DomEvent.preventDefault(e);
2063
- this._anvil.disable();
2064
- });
2065
- this._btns["off" /* Off */] = offBtn;
2331
+ createButton(group, MODE_CONFIGS.find(({ id }) => id === "off" /* Off */));
2066
2332
  }
2067
2333
  });
2068
- const updateFn = (m) => {
2334
+ const updateFn = (mode) => {
2069
2335
  for (const id in this._btns) {
2070
- const active = id === m || id === "off" /* Off */ && !m;
2071
- this._btns[id].style.backgroundColor = active ? "#eee" : "#fff";
2336
+ const active = id === mode || id === "off" /* Off */ && !mode;
2337
+ setButtonState(this._btns[id], active);
2072
2338
  }
2073
2339
  };
2074
2340
  updateFn(null);