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.js CHANGED
@@ -109,6 +109,49 @@ var ModeManager = class {
109
109
  // src/modes/draw-polygon-mode.ts
110
110
  var L3 = __toESM(require("leaflet"));
111
111
 
112
+ // src/utils/mode-styles.ts
113
+ function getModePathOptions(options, mode, defaults = {}) {
114
+ return {
115
+ ...defaults,
116
+ ...options.pathOptions || {},
117
+ ...options.modeStyles?.[mode]?.pathOptions || {}
118
+ };
119
+ }
120
+ function getModeGhostPathOptions(options, mode, defaults = {}) {
121
+ return {
122
+ ...getModePathOptions(options, mode),
123
+ ...defaults,
124
+ ...options.ghostPathOptions || {},
125
+ ...options.modeStyles?.[mode]?.ghostPathOptions || {}
126
+ };
127
+ }
128
+ function getModeVertexOptions(options, mode, defaults = {}) {
129
+ return {
130
+ ...defaults,
131
+ ...options.vertexOptions || {},
132
+ ...options.modeStyles?.[mode]?.vertexOptions || {}
133
+ };
134
+ }
135
+ function getModeHandleOptions(options, mode, defaults = {}) {
136
+ const pathOptions = getModePathOptions(options, mode);
137
+ return {
138
+ radius: 5,
139
+ color: pathOptions.color || "#3388ff",
140
+ weight: 2,
141
+ fillColor: "#fff",
142
+ fillOpacity: 1,
143
+ ...defaults,
144
+ ...options.modeStyles?.[mode]?.handleOptions || {}
145
+ };
146
+ }
147
+ function getModeSelectionPathOptions(options, mode, base = {}, defaults = {}) {
148
+ return {
149
+ ...base,
150
+ ...defaults,
151
+ ...options.modeStyles?.[mode]?.selectionPathOptions || {}
152
+ };
153
+ }
154
+
112
155
  // src/utils/snapping.ts
113
156
  var L = __toESM(require("leaflet"));
114
157
  function getSnapLatLng(map, latlng, store, options, additionalPoints = [], skipLayer) {
@@ -269,11 +312,14 @@ var DrawPolygonMode = class {
269
312
  const snapLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options, this.points) : e.latlng;
270
313
  const lastPoint = this.points[this.points.length - 1];
271
314
  if (!this.ghostLine) {
272
- this.ghostLine = L3.polyline([lastPoint, snapLatLng], {
273
- dashArray: "5, 5",
274
- color: "#3388ff",
275
- weight: 2
276
- }).addTo(this.map);
315
+ this.ghostLine = L3.polyline(
316
+ [lastPoint, snapLatLng],
317
+ getModeGhostPathOptions(this.options, "polygon" /* Polygon */, {
318
+ dashArray: "5, 5",
319
+ color: "#3388ff",
320
+ weight: 2
321
+ })
322
+ ).addTo(this.map);
277
323
  } else {
278
324
  this.ghostLine.setLatLngs([lastPoint, snapLatLng]);
279
325
  }
@@ -287,26 +333,32 @@ var DrawPolygonMode = class {
287
333
  if (this.polyline) {
288
334
  this.polyline.setLatLngs(this.points);
289
335
  } else {
290
- this.polyline = L3.polyline(this.points, { color: "#3388ff" }).addTo(this.map);
336
+ this.polyline = L3.polyline(
337
+ this.points,
338
+ getModePathOptions(this.options, "polygon" /* Polygon */, { color: "#3388ff" })
339
+ ).addTo(this.map);
291
340
  }
292
341
  if (this.points.length === 1 && this.markers.length === 0) {
293
- const marker4 = L3.circleMarker(this.points[0], {
294
- radius: 5,
295
- fillColor: "#fff",
296
- fillOpacity: 1,
297
- color: "#3388ff",
298
- weight: 2
299
- }).addTo(this.map);
300
- marker4.on("click", (e) => {
342
+ const marker3 = L3.circleMarker(
343
+ this.points[0],
344
+ getModeHandleOptions(this.options, "polygon" /* Polygon */, {
345
+ radius: 5,
346
+ color: "#3388ff"
347
+ })
348
+ ).addTo(this.map);
349
+ marker3.on("click", (e) => {
301
350
  L3.DomEvent.stopPropagation(e);
302
351
  this.finish();
303
352
  });
304
- this.markers.push(marker4);
353
+ this.markers.push(marker3);
305
354
  }
306
355
  }
307
356
  finish() {
308
357
  if (this.points.length < 3) return;
309
- const polygon7 = L3.polygon(this.points).addTo(this.map);
358
+ const polygon7 = L3.polygon(
359
+ this.points,
360
+ getModePathOptions(this.options, "polygon" /* Polygon */)
361
+ ).addTo(this.map);
310
362
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: polygon7 });
311
363
  this.reset();
312
364
  }
@@ -362,11 +414,14 @@ var DrawPolylineMode = class {
362
414
  const snapLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options, this.points) : e.latlng;
363
415
  const lastPoint = this.points[this.points.length - 1];
364
416
  if (!this.ghostLine) {
365
- this.ghostLine = L4.polyline([lastPoint, e.latlng], {
366
- dashArray: "5, 5",
367
- color: "#3388ff",
368
- weight: 2
369
- }).addTo(this.map);
417
+ this.ghostLine = L4.polyline(
418
+ [lastPoint, e.latlng],
419
+ getModeGhostPathOptions(this.options, "polyline" /* Polyline */, {
420
+ dashArray: "5, 5",
421
+ color: "#3388ff",
422
+ weight: 2
423
+ })
424
+ ).addTo(this.map);
370
425
  } else {
371
426
  this.ghostLine.setLatLngs([lastPoint, snapLatLng]);
372
427
  }
@@ -386,12 +441,18 @@ var DrawPolylineMode = class {
386
441
  if (this.polyline) {
387
442
  this.polyline.setLatLngs(this.points);
388
443
  } else {
389
- this.polyline = L4.polyline(this.points, { color: "#3388ff" }).addTo(this.map);
444
+ this.polyline = L4.polyline(
445
+ this.points,
446
+ getModePathOptions(this.options, "polyline" /* Polyline */, { color: "#3388ff" })
447
+ ).addTo(this.map);
390
448
  }
391
449
  }
392
450
  finish() {
393
451
  if (this.points.length < 2) return;
394
- const polyline6 = L4.polyline(this.points).addTo(this.map);
452
+ const polyline6 = L4.polyline(
453
+ this.points,
454
+ getModePathOptions(this.options, "polyline" /* Polyline */)
455
+ ).addTo(this.map);
395
456
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: polyline6 });
396
457
  this.reset();
397
458
  }
@@ -422,8 +483,8 @@ var DrawMarkerMode = class {
422
483
  }
423
484
  onClick(e) {
424
485
  const latlng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
425
- const marker4 = L5.marker(latlng, this.options.vertexOptions).addTo(this.map);
426
- this.map.fire(ANVIL_EVENTS.CREATED, { layer: marker4 });
486
+ const marker3 = L5.marker(latlng, getModeVertexOptions(this.options, "marker" /* Marker */)).addTo(this.map);
487
+ this.map.fire(ANVIL_EVENTS.CREATED, { layer: marker3 });
427
488
  }
428
489
  };
429
490
 
@@ -460,7 +521,13 @@ var DrawRectangleMode = class {
460
521
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
461
522
  const bounds = L6.latLngBounds(this.startLatLng, currentLatLng);
462
523
  if (!this.rectangle) {
463
- this.rectangle = L6.rectangle(bounds, { color: "#3388ff", weight: 2 }).addTo(this.map);
524
+ this.rectangle = L6.rectangle(
525
+ bounds,
526
+ getModeGhostPathOptions(this.options, "rectangle" /* Rectangle */, {
527
+ color: "#3388ff",
528
+ weight: 2
529
+ })
530
+ ).addTo(this.map);
464
531
  } else {
465
532
  this.rectangle.setBounds(bounds);
466
533
  }
@@ -469,7 +536,10 @@ var DrawRectangleMode = class {
469
536
  if (!this.startLatLng) return;
470
537
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
471
538
  const bounds = L6.latLngBounds(this.startLatLng, currentLatLng);
472
- const rectangle3 = L6.rectangle(bounds).addTo(this.map);
539
+ const rectangle3 = L6.rectangle(
540
+ bounds,
541
+ getModePathOptions(this.options, "rectangle" /* Rectangle */)
542
+ ).addTo(this.map);
473
543
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: rectangle3 });
474
544
  this.reset();
475
545
  }
@@ -513,7 +583,13 @@ var DrawSquareMode = class {
513
583
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
514
584
  const squareBounds = this.getSquareBounds(this.startLatLng, currentLatLng);
515
585
  if (!this.rectangle) {
516
- this.rectangle = L7.rectangle(squareBounds, { color: "#3388ff", weight: 2 }).addTo(this.map);
586
+ this.rectangle = L7.rectangle(
587
+ squareBounds,
588
+ getModeGhostPathOptions(this.options, "square" /* Square */, {
589
+ color: "#3388ff",
590
+ weight: 2
591
+ })
592
+ ).addTo(this.map);
517
593
  } else {
518
594
  this.rectangle.setBounds(squareBounds);
519
595
  }
@@ -522,12 +598,15 @@ var DrawSquareMode = class {
522
598
  if (!this.startLatLng) return;
523
599
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
524
600
  const squareBounds = this.getSquareBounds(this.startLatLng, currentLatLng);
525
- const polygon7 = L7.polygon([
526
- squareBounds.getNorthWest(),
527
- squareBounds.getNorthEast(),
528
- squareBounds.getSouthEast(),
529
- squareBounds.getSouthWest()
530
- ]).addTo(this.map);
601
+ const polygon7 = L7.polygon(
602
+ [
603
+ squareBounds.getNorthWest(),
604
+ squareBounds.getNorthEast(),
605
+ squareBounds.getSouthEast(),
606
+ squareBounds.getSouthWest()
607
+ ],
608
+ getModePathOptions(this.options, "square" /* Square */)
609
+ ).addTo(this.map);
531
610
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: polygon7 });
532
611
  this.reset();
533
612
  }
@@ -583,7 +662,13 @@ var DrawTriangleMode = class {
583
662
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
584
663
  const trianglePoints = this.getTrianglePoints(this.startLatLng, currentLatLng);
585
664
  if (!this.ghostTriangle) {
586
- this.ghostTriangle = L8.polygon(trianglePoints, { color: "#3388ff", weight: 2 }).addTo(this.map);
665
+ this.ghostTriangle = L8.polygon(
666
+ trianglePoints,
667
+ getModeGhostPathOptions(this.options, "triangle" /* Triangle */, {
668
+ color: "#3388ff",
669
+ weight: 2
670
+ })
671
+ ).addTo(this.map);
587
672
  } else {
588
673
  this.ghostTriangle.setLatLngs(trianglePoints);
589
674
  }
@@ -592,7 +677,10 @@ var DrawTriangleMode = class {
592
677
  if (!this.startLatLng) return;
593
678
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
594
679
  const trianglePoints = this.getTrianglePoints(this.startLatLng, currentLatLng);
595
- const polygon7 = L8.polygon(trianglePoints).addTo(this.map);
680
+ const polygon7 = L8.polygon(
681
+ trianglePoints,
682
+ getModePathOptions(this.options, "triangle" /* Triangle */)
683
+ ).addTo(this.map);
596
684
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: polygon7 });
597
685
  this.reset();
598
686
  }
@@ -647,7 +735,13 @@ var DrawCircleMode = class {
647
735
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
648
736
  const radius = this.map.distance(this.centerLatLng, currentLatLng);
649
737
  if (!this.circle) {
650
- this.circle = L9.circle(this.centerLatLng, { radius, color: "#3388ff", weight: 2 }).addTo(this.map);
738
+ this.circle = L9.circle(this.centerLatLng, {
739
+ radius,
740
+ ...getModeGhostPathOptions(this.options, "circle" /* Circle */, {
741
+ color: "#3388ff",
742
+ weight: 2
743
+ })
744
+ }).addTo(this.map);
651
745
  } else {
652
746
  this.circle.setRadius(radius);
653
747
  }
@@ -656,7 +750,10 @@ var DrawCircleMode = class {
656
750
  if (!this.centerLatLng) return;
657
751
  const currentLatLng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
658
752
  const radius = this.map.distance(this.centerLatLng, currentLatLng);
659
- const circle2 = L9.circle(this.centerLatLng, { radius }).addTo(this.map);
753
+ const circle2 = L9.circle(this.centerLatLng, {
754
+ radius,
755
+ ...getModePathOptions(this.options, "circle" /* Circle */)
756
+ }).addTo(this.map);
660
757
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: circle2 });
661
758
  this.reset();
662
759
  }
@@ -721,12 +818,15 @@ var FreehandMode = class {
721
818
  if (this.polyline) {
722
819
  this.polyline.setLatLngs(this.points);
723
820
  } else {
724
- this.polyline = L10.polyline(this.points, {
725
- color: "#3388ff",
726
- weight: 3,
727
- opacity: 0.8,
728
- dashArray: "5, 5"
729
- }).addTo(this.map);
821
+ this.polyline = L10.polyline(
822
+ this.points,
823
+ getModeGhostPathOptions(this.options, "freehand" /* Freehand */, {
824
+ color: "#3388ff",
825
+ weight: 3,
826
+ opacity: 0.8,
827
+ dashArray: "5, 5"
828
+ })
829
+ ).addTo(this.map);
730
830
  }
731
831
  }
732
832
  finish() {
@@ -741,7 +841,10 @@ var FreehandMode = class {
741
841
  if (finalCoords.length > 0 && (finalCoords[0][0] !== finalCoords[finalCoords.length - 1][0] || finalCoords[0][1] !== finalCoords[finalCoords.length - 1][1])) {
742
842
  finalCoords.push(finalCoords[0]);
743
843
  }
744
- const finalPolygon = L10.polygon(finalCoords.map((c) => [c[1], c[0]])).addTo(this.map);
844
+ const finalPolygon = L10.polygon(
845
+ finalCoords.map((c) => [c[1], c[0]]),
846
+ getModePathOptions(this.options, "freehand" /* Freehand */)
847
+ ).addTo(this.map);
745
848
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: finalPolygon });
746
849
  this.resetDrawing();
747
850
  }
@@ -800,11 +903,14 @@ var CutMode = class {
800
903
  const snapLatLng = getSnapLatLng(this.map, e.latlng, this.store, this.options, this.points);
801
904
  const lastPoint = this.points[this.points.length - 1];
802
905
  if (!this.ghostLine) {
803
- this.ghostLine = L11.polyline([lastPoint, snapLatLng], {
804
- dashArray: "5, 5",
805
- color: "#ff0000",
806
- weight: 2
807
- }).addTo(this.map);
906
+ this.ghostLine = L11.polyline(
907
+ [lastPoint, snapLatLng],
908
+ getModeGhostPathOptions(this.options, "cut" /* Cut */, {
909
+ dashArray: "5, 5",
910
+ color: "#ff0000",
911
+ weight: 2
912
+ })
913
+ ).addTo(this.map);
808
914
  } else {
809
915
  this.ghostLine.setLatLngs([lastPoint, snapLatLng]);
810
916
  }
@@ -818,21 +924,24 @@ var CutMode = class {
818
924
  if (this.polyline) {
819
925
  this.polyline.setLatLngs(this.points);
820
926
  } else {
821
- this.polyline = L11.polyline(this.points, { color: "#ff0000" }).addTo(this.map);
927
+ this.polyline = L11.polyline(
928
+ this.points,
929
+ getModePathOptions(this.options, "cut" /* Cut */, { color: "#ff0000" })
930
+ ).addTo(this.map);
822
931
  }
823
932
  if (this.points.length === 1 && this.markers.length === 0) {
824
- const marker4 = L11.circleMarker(this.points[0], {
825
- radius: 6,
826
- fillColor: "#fff",
827
- fillOpacity: 1,
828
- color: "#ff0000",
829
- weight: 2
830
- }).addTo(this.map);
831
- marker4.on("click", (e) => {
933
+ const marker3 = L11.circleMarker(
934
+ this.points[0],
935
+ getModeHandleOptions(this.options, "cut" /* Cut */, {
936
+ radius: 6,
937
+ color: "#ff0000"
938
+ })
939
+ ).addTo(this.map);
940
+ marker3.on("click", (e) => {
832
941
  L11.DomEvent.stopPropagation(e);
833
942
  if (this.points.length >= 3) this.finish();
834
943
  });
835
- this.markers.push(marker4);
944
+ this.markers.push(marker3);
836
945
  }
837
946
  }
838
947
  finish() {
@@ -859,7 +968,9 @@ var CutMode = class {
859
968
  this.map.removeLayer(polygon7);
860
969
  const flattened = turf2.flatten(result);
861
970
  flattened.features.forEach((f) => {
862
- const l = L11.geoJSON(f).getLayers()[0];
971
+ const l = L11.geoJSON(f, {
972
+ style: getModePathOptions(this.options, "cut" /* Cut */)
973
+ }).getLayers()[0];
863
974
  l.addTo(this.map);
864
975
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: l });
865
976
  });
@@ -923,11 +1034,14 @@ var SplitMode = class {
923
1034
  const snapLatLng = getSnapLatLng(this.map, e.latlng, this.store, this.options, this.points);
924
1035
  const lastPoint = this.points[this.points.length - 1];
925
1036
  if (!this.ghostLine) {
926
- this.ghostLine = L12.polyline([lastPoint, snapLatLng], {
927
- dashArray: "5, 5",
928
- color: "#ff3300",
929
- weight: 2
930
- }).addTo(this.map);
1037
+ this.ghostLine = L12.polyline(
1038
+ [lastPoint, snapLatLng],
1039
+ getModeGhostPathOptions(this.options, "split" /* Split */, {
1040
+ dashArray: "5, 5",
1041
+ color: "#ff3300",
1042
+ weight: 2
1043
+ })
1044
+ ).addTo(this.map);
931
1045
  } else {
932
1046
  this.ghostLine.setLatLngs([lastPoint, snapLatLng]);
933
1047
  }
@@ -941,23 +1055,28 @@ var SplitMode = class {
941
1055
  if (this.polyline) {
942
1056
  this.polyline.setLatLngs(this.points);
943
1057
  } else {
944
- this.polyline = L12.polyline(this.points, { color: "#ff3300", weight: 3 }).addTo(this.map);
1058
+ this.polyline = L12.polyline(
1059
+ this.points,
1060
+ getModePathOptions(this.options, "split" /* Split */, {
1061
+ color: "#ff3300",
1062
+ weight: 3
1063
+ })
1064
+ ).addTo(this.map);
945
1065
  }
946
1066
  const lastPoint = this.points[this.points.length - 1];
947
1067
  if (this.markers.length === 0) {
948
- const marker4 = L12.marker(lastPoint, {
949
- icon: L12.divIcon({
950
- className: "anvil-split-finish",
951
- html: '<div style="width: 10px; height: 10px; background: #ff3300; border: 2px solid white; border-radius: 50%;"></div>',
952
- iconSize: [10, 10],
953
- iconAnchor: [5, 5]
1068
+ const marker3 = L12.circleMarker(
1069
+ lastPoint,
1070
+ getModeHandleOptions(this.options, "split" /* Split */, {
1071
+ radius: 5,
1072
+ color: "#ff3300"
954
1073
  })
955
- }).addTo(this.map);
956
- marker4.on("click", (e) => {
1074
+ ).addTo(this.map);
1075
+ marker3.on("click", (e) => {
957
1076
  L12.DomEvent.stopPropagation(e);
958
1077
  this.finish();
959
1078
  });
960
- this.markers.push(marker4);
1079
+ this.markers.push(marker3);
961
1080
  } else {
962
1081
  this.markers[0].setLatLng(lastPoint);
963
1082
  }
@@ -1012,7 +1131,9 @@ var SplitMode = class {
1012
1131
  const processResult = (result) => {
1013
1132
  const flattened = turf3.flatten(result);
1014
1133
  flattened.features.forEach((f) => {
1015
- const l = L12.geoJSON(f).getLayers()[0];
1134
+ const l = L12.geoJSON(f, {
1135
+ style: getModePathOptions(this.options, "split" /* Split */)
1136
+ }).getLayers()[0];
1016
1137
  l.addTo(this.map);
1017
1138
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: l });
1018
1139
  });
@@ -1093,6 +1214,7 @@ var DragMode = class {
1093
1214
  __publicField(this, "draggingLayer", null);
1094
1215
  __publicField(this, "startLatLng", null);
1095
1216
  __publicField(this, "initialLatLngs", null);
1217
+ __publicField(this, "originalPathStyle", null);
1096
1218
  this.store.getGroup().on("layeradd", (e) => {
1097
1219
  if (this.isEnabled) {
1098
1220
  this.addLayerListener(e.layer);
@@ -1140,7 +1262,13 @@ var DragMode = class {
1140
1262
  } else if (this.draggingLayer instanceof L13.Polyline) {
1141
1263
  this.initialLatLngs = JSON.parse(JSON.stringify(this.draggingLayer.getLatLngs()));
1142
1264
  }
1143
- this.draggingLayer.setStyle({ weight: 4, color: "#ffcc00" });
1265
+ this.originalPathStyle = { ...this.draggingLayer.options };
1266
+ this.draggingLayer.setStyle(
1267
+ getModeSelectionPathOptions(this.options, "drag" /* Drag */, this.originalPathStyle, {
1268
+ weight: 4,
1269
+ color: "#ffcc00"
1270
+ })
1271
+ );
1144
1272
  }
1145
1273
  this.map.on("mousemove", this.onMouseMove, this);
1146
1274
  this.map.on("mouseup", this.onMouseUp, this);
@@ -1175,7 +1303,7 @@ var DragMode = class {
1175
1303
  onMouseUp() {
1176
1304
  if (this.draggingLayer) {
1177
1305
  if (this.draggingLayer instanceof L13.Path) {
1178
- this.draggingLayer.setStyle({ weight: 3, color: "#3388ff" });
1306
+ this.draggingLayer.setStyle(this.originalPathStyle || {});
1179
1307
  }
1180
1308
  this.map.fire(ANVIL_EVENTS.EDITED, { layer: this.draggingLayer });
1181
1309
  }
@@ -1185,16 +1313,20 @@ var DragMode = class {
1185
1313
  this.map.off("mousemove", this.onMouseMove, this);
1186
1314
  this.map.off("mouseup", this.onMouseUp, this);
1187
1315
  this.map.dragging.enable();
1316
+ if (this.draggingLayer instanceof L13.Path && this.originalPathStyle) {
1317
+ this.draggingLayer.setStyle(this.originalPathStyle);
1318
+ }
1188
1319
  this.draggingLayer = null;
1189
1320
  this.startLatLng = null;
1190
1321
  this.initialLatLngs = null;
1322
+ this.originalPathStyle = null;
1191
1323
  }
1192
1324
  };
1193
1325
 
1194
1326
  // src/modes/scale-mode.ts
1195
1327
  var L14 = __toESM(require("leaflet"));
1196
1328
  var ScaleMode = class {
1197
- constructor(map, store, options) {
1329
+ constructor(map, store, options = {}) {
1198
1330
  this.map = map;
1199
1331
  this.store = store;
1200
1332
  this.options = options;
@@ -1203,6 +1335,7 @@ var ScaleMode = class {
1203
1335
  __publicField(this, "initialLatLngs", null);
1204
1336
  __publicField(this, "initialRadius", 0);
1205
1337
  __publicField(this, "initialDistance", 0);
1338
+ __publicField(this, "originalPathStyle", null);
1206
1339
  }
1207
1340
  enable() {
1208
1341
  this.store.getGroup().eachLayer((layer) => {
@@ -1231,11 +1364,20 @@ var ScaleMode = class {
1231
1364
  if (this.selectedLayer instanceof L14.Circle) {
1232
1365
  this.centerLatLng = this.selectedLayer.getLatLng();
1233
1366
  this.initialRadius = this.selectedLayer.getRadius();
1234
- } else if (this.selectedLayer instanceof L14.Path) {
1235
- const bounds = this.selectedLayer.getBounds();
1236
- this.centerLatLng = bounds.getCenter();
1237
- this.initialLatLngs = JSON.parse(JSON.stringify(this.selectedLayer.getLatLngs()));
1238
- this.selectedLayer.setStyle({ weight: 4, color: "#ffcc00" });
1367
+ }
1368
+ if (this.selectedLayer instanceof L14.Path) {
1369
+ this.originalPathStyle = { ...this.selectedLayer.options };
1370
+ this.selectedLayer.setStyle(
1371
+ getModeSelectionPathOptions(this.options, "scale" /* Scale */, this.originalPathStyle, {
1372
+ weight: 4,
1373
+ color: "#ffcc00"
1374
+ })
1375
+ );
1376
+ if (!(this.selectedLayer instanceof L14.Circle)) {
1377
+ const bounds = this.selectedLayer.getBounds();
1378
+ this.centerLatLng = bounds.getCenter();
1379
+ this.initialLatLngs = JSON.parse(JSON.stringify(this.selectedLayer.getLatLngs()));
1380
+ }
1239
1381
  }
1240
1382
  if (this.centerLatLng) {
1241
1383
  this.initialDistance = this.map.distance(this.centerLatLng, e.latlng);
@@ -1266,7 +1408,7 @@ var ScaleMode = class {
1266
1408
  onMouseUp() {
1267
1409
  if (this.selectedLayer) {
1268
1410
  if (this.selectedLayer instanceof L14.Path) {
1269
- this.selectedLayer.setStyle({ weight: 3, color: "#3388ff" });
1411
+ this.selectedLayer.setStyle(this.originalPathStyle || {});
1270
1412
  }
1271
1413
  this.map.fire(ANVIL_EVENTS.EDITED, { layer: this.selectedLayer });
1272
1414
  }
@@ -1276,16 +1418,20 @@ var ScaleMode = class {
1276
1418
  this.map.off("mousemove", this.onMouseMove, this);
1277
1419
  this.map.off("mouseup", this.onMouseUp, this);
1278
1420
  this.map.dragging.enable();
1421
+ if (this.selectedLayer instanceof L14.Path && this.originalPathStyle) {
1422
+ this.selectedLayer.setStyle(this.originalPathStyle);
1423
+ }
1279
1424
  this.selectedLayer = null;
1280
1425
  this.centerLatLng = null;
1281
1426
  this.initialLatLngs = null;
1427
+ this.originalPathStyle = null;
1282
1428
  }
1283
1429
  };
1284
1430
 
1285
1431
  // src/modes/rotate-mode.ts
1286
1432
  var L15 = __toESM(require("leaflet"));
1287
1433
  var RotateMode = class {
1288
- constructor(map, store, options) {
1434
+ constructor(map, store, options = {}) {
1289
1435
  this.map = map;
1290
1436
  this.store = store;
1291
1437
  this.options = options;
@@ -1293,6 +1439,7 @@ var RotateMode = class {
1293
1439
  __publicField(this, "centerLatLng", null);
1294
1440
  __publicField(this, "initialLatLngs", null);
1295
1441
  __publicField(this, "startAngle", 0);
1442
+ __publicField(this, "originalPathStyle", null);
1296
1443
  }
1297
1444
  enable() {
1298
1445
  this.store.getGroup().eachLayer((layer) => {
@@ -1322,10 +1469,16 @@ var RotateMode = class {
1322
1469
  const bounds = pathLayer.getBounds();
1323
1470
  this.centerLatLng = bounds.getCenter();
1324
1471
  this.initialLatLngs = JSON.parse(JSON.stringify(pathLayer.getLatLngs()));
1472
+ this.originalPathStyle = { ...pathLayer.options };
1325
1473
  const point2 = this.map.latLngToContainerPoint(e.latlng);
1326
1474
  const centerPoint = this.map.latLngToContainerPoint(this.centerLatLng);
1327
1475
  this.startAngle = Math.atan2(point2.y - centerPoint.y, point2.x - centerPoint.x);
1328
- pathLayer.setStyle({ weight: 4, color: "#ffcc00" });
1476
+ pathLayer.setStyle(
1477
+ getModeSelectionPathOptions(this.options, "rotate" /* Rotate */, this.originalPathStyle, {
1478
+ weight: 4,
1479
+ color: "#ffcc00"
1480
+ })
1481
+ );
1329
1482
  this.map.on("mousemove", this.onMouseMove, this);
1330
1483
  this.map.on("mouseup", this.onMouseUp, this);
1331
1484
  this.map.dragging.disable();
@@ -1355,7 +1508,7 @@ var RotateMode = class {
1355
1508
  }
1356
1509
  onMouseUp() {
1357
1510
  if (this.selectedLayer) {
1358
- this.selectedLayer.setStyle({ weight: 3, color: "#3388ff" });
1511
+ this.selectedLayer.setStyle(this.originalPathStyle || {});
1359
1512
  this.map.fire(ANVIL_EVENTS.EDITED, { layer: this.selectedLayer });
1360
1513
  }
1361
1514
  this.stopRotating();
@@ -1364,9 +1517,13 @@ var RotateMode = class {
1364
1517
  this.map.off("mousemove", this.onMouseMove, this);
1365
1518
  this.map.off("mouseup", this.onMouseUp, this);
1366
1519
  this.map.dragging.enable();
1520
+ if (this.selectedLayer && this.originalPathStyle) {
1521
+ this.selectedLayer.setStyle(this.originalPathStyle);
1522
+ }
1367
1523
  this.selectedLayer = null;
1368
1524
  this.centerLatLng = null;
1369
1525
  this.initialLatLngs = null;
1526
+ this.originalPathStyle = null;
1370
1527
  }
1371
1528
  };
1372
1529
 
@@ -1379,6 +1536,7 @@ var UnionMode = class {
1379
1536
  this.store = store;
1380
1537
  this.options = options;
1381
1538
  __publicField(this, "firstLayer", null);
1539
+ __publicField(this, "firstLayerStyle", null);
1382
1540
  }
1383
1541
  enable() {
1384
1542
  this.store.getGroup().eachLayer((layer) => {
@@ -1402,7 +1560,13 @@ var UnionMode = class {
1402
1560
  const layer = e.target;
1403
1561
  if (!this.firstLayer) {
1404
1562
  this.firstLayer = layer;
1405
- this.firstLayer.setStyle({ color: "#ff00ff", weight: 4 });
1563
+ this.firstLayerStyle = { ...layer.options };
1564
+ this.firstLayer.setStyle(
1565
+ getModeSelectionPathOptions(this.options, "union" /* Union */, this.firstLayerStyle, {
1566
+ color: "#ff00ff",
1567
+ weight: 4
1568
+ })
1569
+ );
1406
1570
  return;
1407
1571
  }
1408
1572
  if (this.firstLayer === layer) {
@@ -1424,18 +1588,20 @@ var UnionMode = class {
1424
1588
  const flattened = turf4.flatten(united);
1425
1589
  flattened.features.forEach((f) => {
1426
1590
  const newLayerGroup = L16.geoJSON(f, {
1427
- style: this.options.pathOptions
1591
+ style: getModePathOptions(this.options, "union" /* Union */)
1428
1592
  });
1429
1593
  const l = newLayerGroup.getLayers()[0];
1430
1594
  l.addTo(this.map);
1431
1595
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: l });
1432
1596
  });
1433
1597
  this.firstLayer = null;
1598
+ this.firstLayerStyle = null;
1434
1599
  }
1435
1600
  reset() {
1436
1601
  if (this.firstLayer) {
1437
- this.firstLayer.setStyle({ color: "#3388ff", weight: 3, ...this.options.pathOptions });
1602
+ this.firstLayer.setStyle(this.firstLayerStyle || {});
1438
1603
  this.firstLayer = null;
1604
+ this.firstLayerStyle = null;
1439
1605
  }
1440
1606
  }
1441
1607
  };
@@ -1449,6 +1615,7 @@ var SubtractMode = class {
1449
1615
  this.store = store;
1450
1616
  this.options = options;
1451
1617
  __publicField(this, "baseLayer", null);
1618
+ __publicField(this, "baseLayerStyle", null);
1452
1619
  }
1453
1620
  enable() {
1454
1621
  this.store.getGroup().eachLayer((layer) => {
@@ -1472,7 +1639,13 @@ var SubtractMode = class {
1472
1639
  const layer = e.target;
1473
1640
  if (!this.baseLayer) {
1474
1641
  this.baseLayer = layer;
1475
- this.baseLayer.setStyle({ color: "#ff0000", weight: 4 });
1642
+ this.baseLayerStyle = { ...layer.options };
1643
+ this.baseLayer.setStyle(
1644
+ getModeSelectionPathOptions(this.options, "subtract" /* Subtract */, this.baseLayerStyle, {
1645
+ color: "#ff0000",
1646
+ weight: 4
1647
+ })
1648
+ );
1476
1649
  return;
1477
1650
  }
1478
1651
  if (this.baseLayer === layer) {
@@ -1489,18 +1662,22 @@ var SubtractMode = class {
1489
1662
  if (diff) {
1490
1663
  const flattened = turf5.flatten(diff);
1491
1664
  flattened.features.forEach((f) => {
1492
- const newLayerGroup = L17.geoJSON(f);
1665
+ const newLayerGroup = L17.geoJSON(f, {
1666
+ style: getModePathOptions(this.options, "subtract" /* Subtract */)
1667
+ });
1493
1668
  const l = newLayerGroup.getLayers()[0];
1494
1669
  l.addTo(this.map);
1495
1670
  this.map.fire(ANVIL_EVENTS.CREATED, { layer: l });
1496
1671
  });
1497
1672
  }
1498
1673
  this.baseLayer = null;
1674
+ this.baseLayerStyle = null;
1499
1675
  }
1500
1676
  reset() {
1501
1677
  if (this.baseLayer) {
1502
- this.baseLayer.setStyle({ color: "#3388ff", weight: 3 });
1678
+ this.baseLayer.setStyle(this.baseLayerStyle || {});
1503
1679
  this.baseLayer = null;
1680
+ this.baseLayerStyle = null;
1504
1681
  }
1505
1682
  }
1506
1683
  };
@@ -1517,6 +1694,7 @@ var EditMode = class {
1517
1694
  __publicField(this, "ghostMarker", null);
1518
1695
  __publicField(this, "segments", []);
1519
1696
  __publicField(this, "_isDragging", false);
1697
+ __publicField(this, "originalLayerStyles", /* @__PURE__ */ new Map());
1520
1698
  }
1521
1699
  enable() {
1522
1700
  this.store.getGroup().eachLayer((layer) => {
@@ -1535,13 +1713,11 @@ var EditMode = class {
1535
1713
  layer.off("click", this.onLayerClick, this);
1536
1714
  layer.off("mousemove", this.onMouseMove, this);
1537
1715
  layer.getElement()?.style.setProperty("cursor", "");
1538
- if (layer instanceof L18.Path) {
1539
- layer.setStyle({ color: "#3388ff", weight: 3, fillOpacity: 0.2 });
1540
- }
1541
1716
  }
1542
1717
  });
1543
1718
  this.map.off("click", this.onMapClick, this);
1544
1719
  this.map.off("mousemove", this.onMouseMove, this);
1720
+ this.restoreAllPathStyles();
1545
1721
  this.clearMarkers();
1546
1722
  this.activeLayers.clear();
1547
1723
  }
@@ -1551,27 +1727,26 @@ var EditMode = class {
1551
1727
  const isMultiSelect = e.originalEvent.shiftKey || this.options.magnetic;
1552
1728
  if (!isMultiSelect) {
1553
1729
  if (this.activeLayers.has(layer) && this.activeLayers.size === 1) return;
1554
- this.activeLayers.forEach((l) => {
1555
- if (l instanceof L18.Path) l.setStyle({ color: "#3388ff", weight: 3 });
1556
- });
1730
+ this.restoreAllPathStyles();
1557
1731
  this.clearMarkers();
1558
1732
  this.activeLayers.clear();
1559
1733
  this.activeLayers.add(layer);
1560
1734
  } else {
1561
1735
  if (this.activeLayers.has(layer)) {
1562
1736
  this.activeLayers.delete(layer);
1563
- if (layer instanceof L18.Path) layer.setStyle({ color: "#3388ff", weight: 3 });
1737
+ if (layer instanceof L18.Path) this.restorePathStyle(layer);
1564
1738
  } else {
1565
1739
  this.activeLayers.add(layer);
1566
1740
  }
1567
1741
  this.clearMarkers();
1568
1742
  }
1569
1743
  this.activeLayers.forEach((l) => {
1570
- if (l instanceof L18.Path) l.setStyle({ color: "#ff00ff", weight: 4 });
1744
+ if (l instanceof L18.Path) this.applySelectionStyle(l);
1571
1745
  });
1572
1746
  this.createMarkers();
1573
1747
  }
1574
1748
  onMapClick() {
1749
+ this.restoreAllPathStyles();
1575
1750
  this.clearMarkers();
1576
1751
  this.activeLayers.clear();
1577
1752
  }
@@ -1626,17 +1801,17 @@ var EditMode = class {
1626
1801
  });
1627
1802
  this.segments = Array.from(segmentMap.values());
1628
1803
  vertexMap.forEach((group) => {
1629
- const marker4 = this.createEditMarker(group.latlng);
1630
- group.marker = marker4;
1631
- this.markers.push(marker4);
1632
- marker4.on("dragstart", () => {
1804
+ const marker3 = this.createEditMarker(group.latlng);
1805
+ group.marker = marker3;
1806
+ this.markers.push(marker3);
1807
+ marker3.on("dragstart", () => {
1633
1808
  this._isDragging = true;
1634
1809
  });
1635
- marker4.on("drag", (e) => {
1810
+ marker3.on("drag", (e) => {
1636
1811
  const mouseEvent = e;
1637
1812
  const skipLayersArray = Array.from(this.activeLayers);
1638
1813
  const additionalPoints = [
1639
- ...this.markers.filter((m) => m !== marker4).map((m) => m.getLatLng()),
1814
+ ...this.markers.filter((m) => m !== marker3).map((m) => m.getLatLng()),
1640
1815
  ...Array.from(this.activeLayers).filter((l) => l instanceof L18.Marker).map((l) => l.getLatLng())
1641
1816
  ];
1642
1817
  const snapped = getSnapLatLng(this.map, mouseEvent.latlng, this.store, this.options, additionalPoints, skipLayersArray);
@@ -1657,7 +1832,7 @@ var EditMode = class {
1657
1832
  });
1658
1833
  if (wouldIntersect) return;
1659
1834
  }
1660
- marker4.setLatLng(snapped);
1835
+ marker3.setLatLng(snapped);
1661
1836
  group.latlng = snapped;
1662
1837
  group.refs.forEach((ref) => {
1663
1838
  const fullStructure = ref.layer.getLatLngs();
@@ -1670,12 +1845,12 @@ var EditMode = class {
1670
1845
  ref.layer.redraw();
1671
1846
  });
1672
1847
  });
1673
- marker4.on("dragend", () => {
1848
+ marker3.on("dragend", () => {
1674
1849
  this._isDragging = false;
1675
1850
  this.activeLayers.forEach((l) => this.map.fire(ANVIL_EVENTS.EDITED, { layer: l }));
1676
1851
  this.refreshMarkers();
1677
1852
  });
1678
- marker4.on("contextmenu", (e) => {
1853
+ marker3.on("contextmenu", (e) => {
1679
1854
  const mouseEvent = e;
1680
1855
  L18.DomEvent.stopPropagation(mouseEvent);
1681
1856
  this.deleteVertex(group);
@@ -1704,6 +1879,9 @@ var EditMode = class {
1704
1879
  });
1705
1880
  layersToDelete.forEach((layer) => {
1706
1881
  this.activeLayers.delete(layer);
1882
+ if (layer instanceof L18.Path) {
1883
+ this.originalLayerStyles.delete(layer);
1884
+ }
1707
1885
  this.map.removeLayer(layer);
1708
1886
  this.map.fire(ANVIL_EVENTS.DELETED, { layer });
1709
1887
  });
@@ -1745,14 +1923,15 @@ var EditMode = class {
1745
1923
  }
1746
1924
  }
1747
1925
  createEditMarker(latlng) {
1926
+ const visuals = this.getEditHandleVisuals();
1748
1927
  return L18.marker(latlng, {
1749
1928
  draggable: true,
1750
1929
  zIndexOffset: 2e3,
1751
1930
  icon: L18.divIcon({
1752
1931
  className: "anvil-edit-marker",
1753
- 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>',
1754
- iconSize: [12, 12],
1755
- iconAnchor: [6, 6]
1932
+ html: this.createHandleHtml(visuals.size, visuals.fillColor, visuals.borderColor, visuals.borderWidth),
1933
+ iconSize: [visuals.size, visuals.size],
1934
+ iconAnchor: [visuals.size / 2, visuals.size / 2]
1756
1935
  })
1757
1936
  }).addTo(this.map);
1758
1937
  }
@@ -1764,15 +1943,16 @@ var EditMode = class {
1764
1943
  }
1765
1944
  return;
1766
1945
  }
1946
+ const visuals = this.getGhostHandleVisuals();
1767
1947
  this.ghostMarker = L18.marker(latlng, {
1768
1948
  draggable: true,
1769
1949
  opacity: 0.7,
1770
1950
  zIndexOffset: 3e3,
1771
1951
  icon: L18.divIcon({
1772
1952
  className: "anvil-ghost-marker",
1773
- 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>',
1774
- iconSize: [10, 10],
1775
- iconAnchor: [5, 5]
1953
+ html: this.createHandleHtml(visuals.size, visuals.fillColor, visuals.borderColor, visuals.borderWidth),
1954
+ iconSize: [visuals.size, visuals.size],
1955
+ iconAnchor: [visuals.size / 2, visuals.size / 2]
1776
1956
  })
1777
1957
  }).addTo(this.map);
1778
1958
  this.ghostMarker.on("dragstart", () => {
@@ -1841,47 +2021,48 @@ var EditMode = class {
1841
2021
  this.ghostMarker = null;
1842
2022
  }
1843
2023
  }
1844
- handleMarkerEdit(marker4) {
1845
- marker4.dragging?.enable();
1846
- marker4.on("drag", (e) => {
2024
+ handleMarkerEdit(marker3) {
2025
+ marker3.dragging?.enable();
2026
+ marker3.on("drag", (e) => {
1847
2027
  const mouseEvent = e;
1848
2028
  const additionalPoints = this.markers.map((m) => m.getLatLng());
1849
- const snapped = getSnapLatLng(this.map, mouseEvent.latlng, this.store, this.options, additionalPoints, marker4);
1850
- marker4.setLatLng(snapped);
2029
+ const snapped = getSnapLatLng(this.map, mouseEvent.latlng, this.store, this.options, additionalPoints, marker3);
2030
+ marker3.setLatLng(snapped);
1851
2031
  });
1852
- marker4.on("dragend", () => {
1853
- this.map.fire(ANVIL_EVENTS.EDITED, { layer: marker4 });
2032
+ marker3.on("dragend", () => {
2033
+ this.map.fire(ANVIL_EVENTS.EDITED, { layer: marker3 });
1854
2034
  });
1855
- marker4.on("contextmenu", (e) => {
2035
+ marker3.on("contextmenu", (e) => {
1856
2036
  const mouseEvent = e;
1857
2037
  L18.DomEvent.stopPropagation(mouseEvent);
1858
- this.activeLayers.delete(marker4);
1859
- this.map.removeLayer(marker4);
1860
- this.map.fire(ANVIL_EVENTS.DELETED, { layer: marker4 });
2038
+ this.activeLayers.delete(marker3);
2039
+ this.map.removeLayer(marker3);
2040
+ this.map.fire(ANVIL_EVENTS.DELETED, { layer: marker3 });
1861
2041
  this.refreshMarkers();
1862
2042
  });
1863
2043
  }
1864
2044
  handleCircleEdit(circle2) {
1865
- const marker4 = this.createEditMarker(circle2.getLatLng());
1866
- marker4.on("drag", (e) => {
2045
+ const marker3 = this.createEditMarker(circle2.getLatLng());
2046
+ marker3.on("drag", (e) => {
1867
2047
  const mouseEvent = e;
1868
- const additionalPoints = this.markers.filter((m) => m !== marker4).map((m) => m.getLatLng());
2048
+ const additionalPoints = this.markers.filter((m) => m !== marker3).map((m) => m.getLatLng());
1869
2049
  const snapped = getSnapLatLng(this.map, mouseEvent.latlng, this.store, this.options, additionalPoints, circle2);
1870
- marker4.setLatLng(snapped);
2050
+ marker3.setLatLng(snapped);
1871
2051
  circle2.setLatLng(snapped);
1872
2052
  });
1873
- marker4.on("dragend", () => {
2053
+ marker3.on("dragend", () => {
1874
2054
  this.map.fire(ANVIL_EVENTS.EDITED, { layer: circle2 });
1875
2055
  });
1876
- marker4.on("contextmenu", (e) => {
2056
+ marker3.on("contextmenu", (e) => {
1877
2057
  const mouseEvent = e;
1878
2058
  L18.DomEvent.stopPropagation(mouseEvent);
1879
2059
  this.activeLayers.delete(circle2);
2060
+ this.originalLayerStyles.delete(circle2);
1880
2061
  this.map.removeLayer(circle2);
1881
2062
  this.map.fire(ANVIL_EVENTS.DELETED, { layer: circle2 });
1882
2063
  this.refreshMarkers();
1883
2064
  });
1884
- this.markers.push(marker4);
2065
+ this.markers.push(marker3);
1885
2066
  }
1886
2067
  clearMarkers() {
1887
2068
  this.activeLayers.forEach((layer) => {
@@ -1900,6 +2081,64 @@ var EditMode = class {
1900
2081
  this.clearMarkers();
1901
2082
  this.createMarkers();
1902
2083
  }
2084
+ applySelectionStyle(layer) {
2085
+ if (!this.originalLayerStyles.has(layer)) {
2086
+ this.originalLayerStyles.set(layer, { ...layer.options });
2087
+ }
2088
+ layer.setStyle(
2089
+ getModeSelectionPathOptions(this.options, "edit" /* Edit */, this.originalLayerStyles.get(layer) || {}, {
2090
+ color: "#ff00ff",
2091
+ weight: 4
2092
+ })
2093
+ );
2094
+ }
2095
+ restorePathStyle(layer) {
2096
+ const original = this.originalLayerStyles.get(layer);
2097
+ if (!original) return;
2098
+ layer.setStyle(original);
2099
+ this.originalLayerStyles.delete(layer);
2100
+ }
2101
+ restoreAllPathStyles() {
2102
+ this.originalLayerStyles.forEach((style, layer) => {
2103
+ layer.setStyle(style);
2104
+ });
2105
+ this.originalLayerStyles.clear();
2106
+ }
2107
+ getEditHandleVisuals() {
2108
+ const selection = getModeSelectionPathOptions(this.options, "edit" /* Edit */, {}, { color: "#ff00ff" });
2109
+ const handle = getModeHandleOptions(this.options, "edit" /* Edit */, {
2110
+ radius: 6,
2111
+ color: selection.color || "#ff00ff",
2112
+ fillColor: "#fff",
2113
+ fillOpacity: 1,
2114
+ weight: 2
2115
+ });
2116
+ return {
2117
+ size: (handle.radius || 6) * 2,
2118
+ fillColor: handle.fillColor || "#fff",
2119
+ borderColor: handle.color || (selection.color || "#ff00ff"),
2120
+ borderWidth: handle.weight || 2
2121
+ };
2122
+ }
2123
+ getGhostHandleVisuals() {
2124
+ const selection = getModeSelectionPathOptions(this.options, "edit" /* Edit */, {}, { color: "#ff00ff" });
2125
+ const handle = getModeHandleOptions(this.options, "edit" /* Edit */, {
2126
+ radius: 5,
2127
+ color: "#fff",
2128
+ fillColor: selection.color || "#ff00ff",
2129
+ fillOpacity: 1,
2130
+ weight: 2
2131
+ });
2132
+ return {
2133
+ size: (handle.radius || 5) * 2,
2134
+ fillColor: handle.fillColor || (selection.color || "#ff00ff"),
2135
+ borderColor: handle.color || "#fff",
2136
+ borderWidth: handle.weight || 2
2137
+ };
2138
+ }
2139
+ createHandleHtml(size, fillColor, borderColor, borderWidth) {
2140
+ 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>`;
2141
+ }
1903
2142
  };
1904
2143
 
1905
2144
  // src/modes/delete-mode.ts
@@ -1974,45 +2213,97 @@ var LayerStore = class {
1974
2213
 
1975
2214
  // src/controls/anvil-control.ts
1976
2215
  var L21 = __toESM(require("leaflet"));
1977
- 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"';
1978
- var ICONS = {
1979
- // Marker: Map-Pin mit Punkt in der Mitte
1980
- ["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>`,
1981
- // Polyline: Kurvige Route mit Endpunkten
1982
- ["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>`,
1983
- // Polygon: Klassische unregelmäßige 5-Eck-Form
1984
- ["polygon" /* Polygon */]: `<svg ${SVG_ATTRS}><path d="m12 2 10 7-3 12H5l-3-12Z"/></svg>`,
1985
- // Rectangle: Horizontales Rechteck
1986
- ["rectangle" /* Rectangle */]: `<svg ${SVG_ATTRS}><rect width="20" height="12" x="2" y="6" rx="2"/></svg>`,
1987
- // Square: Quadratisches Rechteck (1:1)
1988
- ["square" /* Square */]: `<svg ${SVG_ATTRS}><rect width="18" height="18" x="3" y="3" rx="2"/></svg>`,
1989
- // Triangle: Gleichschenkliges Dreieck
1990
- ["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>`,
1991
- // Circle: Klassischer Kreis
1992
- ["circle" /* Circle */]: `<svg ${SVG_ATTRS}><circle cx="12" cy="12" r="10"/></svg>`,
1993
- // Freehand: Geschwungene Signatur-Linie
1994
- ["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>`,
1995
- // Cut: Offene Schere
1996
- ["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>`,
1997
- // Split: Linie, die eine Form teilt
1998
- ["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>`,
1999
- // Union: Zwei verschmolzene Rechtecke
2000
- ["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>`,
2001
- // Subtract: Hauptform mit "ausgeschnittenem" Bereich (Minus-Metapher)
2002
- ["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>`,
2003
- // Drag: Vier-Wege-Pfeil (Move-Metapher)
2004
- ["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>`,
2005
- // Scale: Diagonal-Pfeile (Maximize-Metapher)
2006
- ["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>`,
2007
- // Rotate: Kreispfeil mit Ziel-Icon
2008
- ["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>`,
2009
- // Edit: Stift, der über einen Pfad zeichnet
2010
- ["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>`,
2011
- // Delete: Mülleimer mit Deckel und Schlitzen
2012
- ["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>`,
2013
- // Off: Durchgestrichener Kreis (Power-Off/Disable Metapher)
2014
- ["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>`
2015
- };
2216
+ var import_lucide = require("lucide");
2217
+ var ANVIL_TOOLBAR_STYLE_ID = "anvil-toolbar-styles";
2218
+ var MODE_CONFIGS = [
2219
+ { id: "marker" /* Marker */, title: "Marker", icon: import_lucide.MapPin },
2220
+ { id: "polyline" /* Polyline */, title: "Line", icon: import_lucide.Waypoints },
2221
+ { id: "polygon" /* Polygon */, title: "Polygon", icon: import_lucide.Pentagon },
2222
+ { id: "rectangle" /* Rectangle */, title: "Rectangle", icon: import_lucide.RectangleHorizontal },
2223
+ { id: "square" /* Square */, title: "Square", icon: import_lucide.Square },
2224
+ { id: "triangle" /* Triangle */, title: "Triangle", icon: import_lucide.Triangle },
2225
+ { id: "circle" /* Circle */, title: "Circle", icon: import_lucide.Circle },
2226
+ { id: "freehand" /* Freehand */, title: "Freehand", icon: import_lucide.Hand },
2227
+ { id: "cut" /* Cut */, title: "Cut", icon: import_lucide.Scissors },
2228
+ { id: "split" /* Split */, title: "Split", icon: import_lucide.Split },
2229
+ { id: "union" /* Union */, title: "Union", icon: import_lucide.SquaresUnite },
2230
+ { id: "subtract" /* Subtract */, title: "Subtract", icon: import_lucide.SquaresSubtract },
2231
+ { id: "drag" /* Drag */, title: "Drag", icon: import_lucide.Move },
2232
+ { id: "scale" /* Scale */, title: "Scale", icon: import_lucide.Scaling },
2233
+ { id: "rotate" /* Rotate */, title: "Rotate", icon: import_lucide.RotateCw },
2234
+ { id: "edit" /* Edit */, title: "Edit", icon: import_lucide.SquarePen },
2235
+ { id: "delete" /* Delete */, title: "Delete", icon: import_lucide.Trash2 },
2236
+ { id: "off" /* Off */, title: "Turn Off", icon: import_lucide.Power }
2237
+ ];
2238
+ function ensureToolbarStyles() {
2239
+ if (typeof document === "undefined" || document.getElementById(ANVIL_TOOLBAR_STYLE_ID)) return;
2240
+ const style = document.createElement("style");
2241
+ style.id = ANVIL_TOOLBAR_STYLE_ID;
2242
+ style.textContent = `
2243
+ .anvil-toolbar-container {
2244
+ display: flex;
2245
+ flex-direction: column;
2246
+ gap: 8px;
2247
+ }
2248
+
2249
+ .anvil-toolbar-group {
2250
+ overflow: hidden;
2251
+ }
2252
+
2253
+ .anvil-toolbar-group .anvil-control-btn {
2254
+ display: flex;
2255
+ align-items: center;
2256
+ justify-content: center;
2257
+ width: 30px;
2258
+ height: 30px;
2259
+ color: #2f3b52;
2260
+ transition: background-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
2261
+ }
2262
+
2263
+ .anvil-toolbar-group .anvil-control-btn svg {
2264
+ width: 16px;
2265
+ height: 16px;
2266
+ stroke-width: 2.1;
2267
+ }
2268
+
2269
+ .anvil-toolbar-group .anvil-control-btn:hover,
2270
+ .anvil-toolbar-group .anvil-control-btn:focus-visible {
2271
+ background-color: #f3f6fb;
2272
+ color: #0f172a;
2273
+ }
2274
+
2275
+ .anvil-toolbar-group .anvil-control-btn:focus-visible {
2276
+ outline: none;
2277
+ box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.35);
2278
+ }
2279
+
2280
+ .anvil-toolbar-group .anvil-control-btn.is-active {
2281
+ background-color: #2563eb;
2282
+ color: #fff;
2283
+ box-shadow: inset 0 0 0 1px rgba(29, 78, 216, 0.45), 0 1px 3px rgba(37, 99, 235, 0.25);
2284
+ }
2285
+
2286
+ .anvil-toolbar-group .anvil-control-btn.is-active:hover,
2287
+ .anvil-toolbar-group .anvil-control-btn.is-active:focus-visible {
2288
+ background-color: #1d4ed8;
2289
+ color: #fff;
2290
+ }
2291
+ `;
2292
+ document.head.appendChild(style);
2293
+ }
2294
+ function setButtonState(button, active) {
2295
+ button.classList.toggle("is-active", active);
2296
+ button.setAttribute("aria-pressed", active ? "true" : "false");
2297
+ }
2298
+ function buildIcon(iconNode) {
2299
+ return (0, import_lucide.createElement)(iconNode, {
2300
+ width: 16,
2301
+ height: 16,
2302
+ "stroke-width": 2.1,
2303
+ "aria-hidden": "true",
2304
+ focusable: "false"
2305
+ });
2306
+ }
2016
2307
  var AnvilControl = class extends L21.Control {
2017
2308
  constructor(anvil, options) {
2018
2309
  super(L21.Util.extend({ position: "topleft" }, options));
@@ -2023,88 +2314,43 @@ var AnvilControl = class extends L21.Control {
2023
2314
  this._options = { ...options };
2024
2315
  }
2025
2316
  onAdd(map) {
2026
- console.log("AnvilControl: triggering onAdd");
2317
+ ensureToolbarStyles();
2027
2318
  const container = L21.DomUtil.create("div", "anvil-toolbar-container");
2028
- container.style.display = "flex";
2029
- container.style.flexDirection = "column";
2030
- container.style.gap = "10px";
2031
- const allModeConfigs = [
2032
- { id: "marker" /* Marker */, title: "Marker" },
2033
- { id: "polyline" /* Polyline */, title: "Line" },
2034
- { id: "polygon" /* Polygon */, title: "Polygon" },
2035
- { id: "rectangle" /* Rectangle */, title: "Rectangle" },
2036
- { id: "square" /* Square */, title: "Square" },
2037
- { id: "triangle" /* Triangle */, title: "Triangle" },
2038
- { id: "circle" /* Circle */, title: "Circle" },
2039
- { id: "freehand" /* Freehand */, title: "Freehand" },
2040
- { id: "cut" /* Cut */, title: "Cut" },
2041
- { id: "split" /* Split */, title: "Split" },
2042
- { id: "union" /* Union */, title: "Union" },
2043
- { id: "subtract" /* Subtract */, title: "Subtract" },
2044
- { id: "drag" /* Drag */, title: "Drag" },
2045
- { id: "scale" /* Scale */, title: "Scale" },
2046
- { id: "rotate" /* Rotate */, title: "Rotate" },
2047
- { id: "edit" /* Edit */, title: "Edit" },
2048
- { id: "delete" /* Delete */, title: "Delete" }
2049
- ];
2050
- const modesInput = this._options.modes || allModeConfigs.map((m) => m.id);
2319
+ const modesInput = this._options.modes || MODE_CONFIGS.filter(({ id }) => id !== "off" /* Off */).map(({ id }) => id);
2051
2320
  const blocks = Array.isArray(modesInput[0]) ? modesInput : [modesInput];
2321
+ const createButton = (group, config) => {
2322
+ const btn = L21.DomUtil.create("a", "anvil-control-btn", group);
2323
+ btn.href = "#";
2324
+ btn.title = config.title;
2325
+ btn.setAttribute("role", "button");
2326
+ btn.setAttribute("aria-label", config.title);
2327
+ btn.appendChild(buildIcon(config.icon));
2328
+ L21.DomEvent.disableClickPropagation(btn);
2329
+ L21.DomEvent.on(btn, "click", (e) => {
2330
+ L21.DomEvent.preventDefault(e);
2331
+ if (config.id === "off" /* Off */) {
2332
+ this._anvil.disable();
2333
+ } else {
2334
+ this._anvil.enable(config.id);
2335
+ }
2336
+ });
2337
+ this._btns[config.id] = btn;
2338
+ };
2052
2339
  blocks.forEach((block, index) => {
2053
2340
  const group = L21.DomUtil.create("div", "leaflet-bar anvil-toolbar-group", container);
2054
- group.style.display = "flex";
2055
- group.style.flexDirection = "column";
2056
- group.style.backgroundColor = "white";
2057
2341
  block.forEach((modeId) => {
2058
- const config = allModeConfigs.find((c) => c.id === modeId);
2059
- if (!config && modeId !== "off" /* Off */) return;
2060
- const id = modeId;
2061
- const title = config ? config.title : "Turn Off";
2062
- const btn = L21.DomUtil.create("a", "anvil-control-btn", group);
2063
- btn.innerHTML = ICONS[id] || title;
2064
- btn.href = "#";
2065
- btn.title = title;
2066
- btn.style.display = "flex";
2067
- btn.style.alignItems = "center";
2068
- btn.style.justifyContent = "center";
2069
- btn.style.width = "30px";
2070
- btn.style.height = "30px";
2071
- btn.style.color = "#333";
2072
- btn.style.cursor = "pointer";
2073
- L21.DomEvent.disableClickPropagation(btn);
2074
- L21.DomEvent.on(btn, "click", (e) => {
2075
- L21.DomEvent.preventDefault(e);
2076
- if (id === "off" /* Off */) {
2077
- this._anvil.disable();
2078
- } else {
2079
- this._anvil.enable(id);
2080
- }
2081
- });
2082
- this._btns[id] = btn;
2342
+ const config = MODE_CONFIGS.find(({ id }) => id === modeId);
2343
+ if (!config) return;
2344
+ createButton(group, config);
2083
2345
  });
2084
2346
  if (index === blocks.length - 1 && !this._btns["off" /* Off */]) {
2085
- const offBtn = L21.DomUtil.create("a", "anvil-control-btn", group);
2086
- offBtn.innerHTML = ICONS["off" /* Off */];
2087
- offBtn.href = "#";
2088
- offBtn.title = "Turn Off";
2089
- offBtn.style.display = "flex";
2090
- offBtn.style.alignItems = "center";
2091
- offBtn.style.justifyContent = "center";
2092
- offBtn.style.width = "30px";
2093
- offBtn.style.height = "30px";
2094
- offBtn.style.color = "#333";
2095
- offBtn.style.cursor = "pointer";
2096
- L21.DomEvent.disableClickPropagation(offBtn);
2097
- L21.DomEvent.on(offBtn, "click", (e) => {
2098
- L21.DomEvent.preventDefault(e);
2099
- this._anvil.disable();
2100
- });
2101
- this._btns["off" /* Off */] = offBtn;
2347
+ createButton(group, MODE_CONFIGS.find(({ id }) => id === "off" /* Off */));
2102
2348
  }
2103
2349
  });
2104
- const updateFn = (m) => {
2350
+ const updateFn = (mode) => {
2105
2351
  for (const id in this._btns) {
2106
- const active = id === m || id === "off" /* Off */ && !m;
2107
- this._btns[id].style.backgroundColor = active ? "#eee" : "#fff";
2352
+ const active = id === mode || id === "off" /* Off */ && !mode;
2353
+ setButtonState(this._btns[id], active);
2108
2354
  }
2109
2355
  };
2110
2356
  updateFn(null);