@florasync/leaflet-geokit 0.8.3 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/ARCHITECTURE.md +195 -0
  2. package/CHANGELOG.md +8 -0
  3. package/README.md +146 -11
  4. package/custom-toolbar.html +165 -0
  5. package/dist/django/index.js +8993 -5090
  6. package/dist/django/index.js.map +1 -1
  7. package/dist/leaflet-geokit.es.js +21536 -5994
  8. package/dist/leaflet-geokit.es.js.map +1 -1
  9. package/dist/leaflet-geokit.external.es.js +18006 -2461
  10. package/dist/leaflet-geokit.external.es.js.map +1 -1
  11. package/dist/leaflet-geokit.umd.js +263 -60
  12. package/dist/leaflet-geokit.umd.js.map +1 -1
  13. package/dist/preact/index-DCKj0r6a.js +8545 -0
  14. package/dist/preact/index-DCKj0r6a.js.map +1 -0
  15. package/dist/preact/index.js +1 -1
  16. package/dist/preact-bundled/index.js +9002 -5089
  17. package/dist/preact-bundled/index.js.map +1 -1
  18. package/dist/react/index-DCKj0r6a.js +8545 -0
  19. package/dist/react/index-DCKj0r6a.js.map +1 -0
  20. package/dist/react/index.js +1 -1
  21. package/dist/react-bundled/index.js +9040 -5127
  22. package/dist/react-bundled/index.js.map +1 -1
  23. package/dist/types/components/LeafletDrawMapElement.d.ts +42 -3
  24. package/dist/types/django/index.d.ts +2 -2
  25. package/dist/types/external.d.ts +9 -3
  26. package/dist/types/index.d.ts +9 -3
  27. package/dist/types/lib/FeatureStore.d.ts +2 -2
  28. package/dist/types/lib/LayerRegistry.d.ts +19 -0
  29. package/dist/types/lib/MapController.d.ts +95 -5
  30. package/dist/types/lib/draw/L.Draw.Move.d.ts +1 -0
  31. package/dist/types/lib/draw/move-pointer.d.ts +12 -0
  32. package/dist/types/lib/layer-cake/LayerCakeManager.d.ts +10 -2
  33. package/dist/types/lib/layer-style-panel.d.ts +3 -0
  34. package/dist/types/lib/marker-icons.d.ts +1 -1
  35. package/dist/types/lib/providers.d.ts +64 -0
  36. package/dist/types/lib/snapping.d.ts +30 -0
  37. package/dist/types/lib/tool-buttons.d.ts +3 -1
  38. package/dist/types/lib/tool-capabilities.d.ts +27 -0
  39. package/dist/types/lib/toolbar-accessibility.d.ts +3 -0
  40. package/dist/types/lib/toolbar-layout.d.ts +14 -0
  41. package/dist/types/lib/toolbar-styles.d.ts +2 -0
  42. package/dist/types/preact/core.d.ts +2 -2
  43. package/dist/types/preact/index.d.ts +2 -2
  44. package/dist/types/preact-bundled/index.d.ts +3 -3
  45. package/dist/types/react/core.d.ts +2 -2
  46. package/dist/types/react/index.d.ts +2 -2
  47. package/dist/types/react-bundled/index.d.ts +3 -3
  48. package/dist/types/types/events.d.ts +15 -1
  49. package/dist/types/types/layers.d.ts +65 -0
  50. package/dist/types/types/public.d.ts +160 -5
  51. package/dist/types/utils/geojson-pipeline.d.ts +51 -0
  52. package/dist/types/utils/geojson.d.ts +15 -2
  53. package/dist/types/utils/grower-geometry.d.ts +107 -0
  54. package/docs/accessibility.md +142 -0
  55. package/docs/api-reference.md +249 -0
  56. package/docs/custom-toolbar.md +168 -0
  57. package/docs/diagnostics.md +216 -0
  58. package/docs/geojson-pipelines.md +145 -0
  59. package/docs/google-maps-adapter-spike.md +77 -0
  60. package/docs/grower-geometry.md +237 -0
  61. package/docs/grower-measurement.md +23 -0
  62. package/docs/integration-recipes.md +301 -0
  63. package/docs/layers.md +136 -0
  64. package/docs/providers.md +191 -0
  65. package/docs/release-verification.md +75 -0
  66. package/docs/shims/django.md +102 -0
  67. package/docs/shims/preact.md +98 -0
  68. package/docs/shims/react.md +98 -0
  69. package/docs/snapping-and-measurements.md +42 -0
  70. package/docs/tool-capabilities.md +131 -0
  71. package/docs/tool-lifecycle.md +124 -0
  72. package/docs/toolbar-layout.md +158 -0
  73. package/docs/toolbar-styling.md +118 -0
  74. package/package.json +35 -3
  75. package/dist/preact/index-BMfJn-mD.js +0 -4632
  76. package/dist/preact/index-BMfJn-mD.js.map +0 -1
  77. package/dist/react/index-BMfJn-mD.js +0 -4632
  78. package/dist/react/index-BMfJn-mD.js.map +0 -1
@@ -0,0 +1,195 @@
1
+ # Architecture: Leaflet GeoKit
2
+
3
+ This is a map of the implemented library, not a future implementation plan.
4
+ GeoKit exposes a framework-agnostic custom element backed by Leaflet and
5
+ Leaflet.draw. The canonical tag is `<leaflet-geokit>`; `<leaflet-draw-map>` is a
6
+ registered compatibility alias. Host applications own persistence, authentication,
7
+ vendor credentials, and framework UI.
8
+
9
+ For task-oriented examples start with [integration recipes](docs/integration-recipes.md).
10
+ The [README](README.md) describes the public API; the source contracts are
11
+ [public.ts](src/types/public.ts), [events.ts](src/types/events.ts), and
12
+ [layers.ts](src/types/layers.ts).
13
+
14
+ ## Runtime boundaries
15
+
16
+ ```mermaid
17
+ flowchart TD
18
+ Host[Host app / React / Preact / Django shim] --> Element[LeafletDrawMapElement]
19
+ Element --> Controller[MapController]
20
+ Controller --> Leaflet[Leaflet map + Leaflet.draw + ruler]
21
+ Controller --> Store[FeatureStore: GeoJSON by string ID]
22
+ Controller --> Registry[LayerRegistry: named presentation groups]
23
+ Controller --> Cake[LayerCakeManager + CakeBaker]
24
+ Controller --> Toolbar[Toolbar styling / layout / accessibility / capabilities]
25
+ Controller --> Provider[Raster provider or injected basemap adapter]
26
+ Element --> Events[DOM status / diagnostic / draw / tool / layer events]
27
+ Events --> Host
28
+ Pipeline[GeoJSON pipeline / grower geometry helpers] --> Host
29
+ ```
30
+
31
+ ### Custom element and lifecycle
32
+
33
+ [LeafletDrawMapElement](src/components/LeafletDrawMapElement.ts) owns Shadow DOM,
34
+ configuration attributes/properties, style injection, status snapshots, and the
35
+ public method/event bridge. On connection it constructs and initializes a
36
+ controller; on disconnection it destroys the controller and removes its listeners.
37
+ Give the host an explicit height and attach readiness/error listeners before
38
+ connecting it. Custom-element registration alone is not map readiness.
39
+
40
+ Public status states are `uninitialized`, `initializing`, `ready`, `loading`, and
41
+ `error`. `leaflet-geokit:status` reports readiness, busy state and feature count;
42
+ `leaflet-geokit:diagnostic` and `leaflet-draw:error` expose failures. Recoverable
43
+ errors can leave the map usable. `dev-overlay` is a compatibility flag, not an
44
+ implemented debugging overlay. Logging defaults to `debug` and supports a custom
45
+ logger; do not assume diagnostic output is appropriate for sensitive data.
46
+
47
+ ### Controller and map ownership
48
+
49
+ [MapController](src/lib/MapController.ts) owns the Leaflet map, drawn FeatureGroup,
50
+ feature-to-rendered-layer bindings, basemap, draw/ruler controls, active tool
51
+ commands, and editing sessions. It translates Leaflet changes into store updates
52
+ and public callbacks. It also manages structural reconfiguration, read-only tool
53
+ behavior, snapping, measurement overlays and cleanup. Integrations should use the
54
+ element API rather than reach into the Shadow DOM or private Leaflet handlers.
55
+
56
+ [FeatureStore](src/lib/FeatureStore.ts) is map-agnostic: it stores GeoJSON by string
57
+ ID, provides CRUD and computes coordinate bounds. It does **not** own Leaflet
58
+ layers or bidirectional Leaflet bindings. IDs come from `feature.id`, then
59
+ `properties.id`, then generated UUIDs. Legacy store operations use shallow copies;
60
+ clone a snapshot when retaining an independent editing baseline.
61
+
62
+ [LayerRegistry](src/lib/LayerRegistry.ts) stores detached presentation records:
63
+ name, kind, visibility, order, feature membership and portable style. Hiding a
64
+ group removes its rendered features from the editable group, not the data store.
65
+ The `base` record is reserved. Default GeoJSON export is feature data;
66
+ `preserveLayers: true` explicitly persists registry metadata. See
67
+ [named layers and layer-cake sessions](docs/layers.md) for invariants and restoration.
68
+
69
+ ## Data and geometry
70
+
71
+ The element exposes `getGeoJSON`, `importGeoJSON`, `exportGeoJSON`, legacy
72
+ `loadGeoJSON`/`addFeatures`, per-feature CRUD and view-fitting helpers. Import
73
+ supports replace/add behavior, optional validation, named groups and optional
74
+ layer restoration. `loadGeoJSON` replaces without automatically fitting bounds.
75
+
76
+ [geojson-pipeline.ts](src/utils/geojson-pipeline.ts) implements validation,
77
+ normalization, text/URL ingestion, diagnostic export, diff and patch helpers.
78
+ Validation is opt-in on map imports (`validate: true`); its preflight runs after
79
+ the ingest hook and before destructive replacement. Multi/collection geometries
80
+ expand into editing features, with reserved provenance for diagnostic source
81
+ export. Validation is not a general GIS topology/reprojection service. Read the
82
+ [GeoJSON pipeline contract](docs/geojson-pipelines.md) for ID, provenance,
83
+ validation and legacy export differences.
84
+
85
+ [grower-geometry.ts](src/utils/grower-geometry.ts) supplies Turf-backed geometry
86
+ operations, measurements and guides, exported by the root and external entries.
87
+ See [grower geometry](docs/grower-geometry.md) and
88
+ [snapping and measurements](docs/snapping-and-measurements.md). These utilities
89
+ are distinct from the controller's interactive tools: calculating geometry does
90
+ not automatically import it or create a visible map layer.
91
+
92
+ [LayerCakeManager](src/lib/layer-cake/LayerCakeManager.ts) manages concentric-circle
93
+ draft sessions. [CakeBaker](src/lib/layer-cake/CakeBaker.ts) produces saved core/ring
94
+ polygons. The public session API allows external controls to update radii, style
95
+ and name, then save or cancel. A saved polygon group is not an editable draft
96
+ session; see [layers](docs/layers.md).
97
+
98
+ ## Tools, events and host-owned UI
99
+
100
+ Tool activation is public: `activateTool`, `triggerTool`, `deactivateTool`, and
101
+ `leaflet-geokit:tool-command` share a correlated lifecycle. Command acknowledgement
102
+ is not necessarily interaction completion. Read
103
+ [tool lifecycle](docs/tool-lifecycle.md) for commanded/started/completed/cancelled/
104
+ failed events and [tool capabilities](docs/tool-capabilities.md) for readiness,
105
+ read-only, selection and provider prerequisites.
106
+
107
+ Existing `leaflet-draw:ready`, `created`, `edited`, `deleted`, `ingest`, `export`,
108
+ and `error` events coexist with the newer tool and layer event families.
109
+ `leaflet-geokit:layers-changed` drives a host sidebar;
110
+ `leaflet-geokit:layer-style-request` is synchronously cancelable so a host can
111
+ replace the built-in style panel. Listen on the element: not every legacy event
112
+ bubbles. Event constants and payload types are exported from root and external.
113
+
114
+ Managed `toolbarGroups` and `toolButtonConfig` are data-driven; visual customization
115
+ uses CSS custom properties, parts, named slots and optional trusted renderers.
116
+ Do not depend on generated Leaflet class order or private DOM layout. Dedicated
117
+ contracts are maintained in:
118
+
119
+ - [Toolbar styling](docs/toolbar-styling.md): tokens, parts, states, icons and slots.
120
+ - [Toolbar layout](docs/toolbar-layout.md): zones, responsive placement and overflow.
121
+ - [Accessibility](docs/accessibility.md): labels, focus, keyboard and touch behavior.
122
+
123
+ ## Providers and security
124
+
125
+ [TileProviderFactory](src/lib/TileProviderFactory.ts) retains OSM/HERE and custom
126
+ raster URL behavior. [providers.ts](src/lib/providers.ts) exports raster factories,
127
+ a dependency-injected MapLibre basemap shim, and configuration diagnostics.
128
+ `setBasemapAdapter` swaps only the basemap after readiness; geometry and
129
+ Leaflet.draw remain owned by GeoKit. Reconnection restores raster configuration.
130
+
131
+ `DrawEngineAdapter` is a design port, not an implemented replacement drawing
132
+ engine. The MapLibre seam does not bundle a WebGL renderer, PMTiles transport,
133
+ offline cache, Google Maps support or vendor provisioning. The
134
+ [provider guide](docs/providers.md) describes the optional bridge, teardown,
135
+ attribution and production-verification obligations; the
136
+ [Google adapter spike](docs/google-maps-adapter-spike.md) records a separate study.
137
+
138
+ Treat icon/popover HTML, attribution, theme CSS and adapter code as trusted host
139
+ input. Sanitize untrusted content. Browser keys are visible even when assigned
140
+ through properties; never ship server credentials. Hosts own URL allowlists,
141
+ CORS, upload limits, persistence authorization and concurrency controls.
142
+
143
+ ## Package entries and SSR
144
+
145
+ [package.json](package.json) is authoritative for supported subpaths.
146
+
147
+ | Entry | Responsibility | Server import boundary |
148
+ | ----------------------------------- | -------------------------------------------------------------------- | ---------------------------------------------------------------------- |
149
+ | `@florasync/leaflet-geokit` | Bundled browser component, types, pipeline/geometry/provider helpers | Browser-only runtime registration |
150
+ | `/external` | Browser component with Leaflet/Draw/ruler JS externalized | Browser-only; not an SSR entry |
151
+ | `/react`, `/preact` | Additive framework wrappers; host-owned Leaflet assets | Wrapper module import is SSR-safe; registration is deferred to effects |
152
+ | `/react-bundled`, `/preact-bundled` | Self-provisioned framework wrappers | Eager root import; browser-only |
153
+ | `/django` | Browser textarea/form bridge (`initDjangoGeokit`) | Eager root import; browser-only |
154
+
155
+ Both browser component entries directly access `customElements`; the element
156
+ extends `HTMLElement` and its runtime imports the mapping stack. Pure helper
157
+ implementations do **not** make a root named import SSR-safe. There is no exported
158
+ `/utils`, `/geojson`, `/providers` or `/ssr` runtime subpath. Type-only root imports
159
+ are erased by TypeScript. Use client-only dynamic imports for browser entries.
160
+
161
+ The additive wrappers use [ensure-element.ts](src/shims/ensure-element.ts) to load
162
+ the root lazily in the browser. Their SSR-safe module import does not mean a map
163
+ renders on the server. React/Preact runtimes remain consumer-provided optional
164
+ peers. See the [integration recipes](docs/integration-recipes.md) and existing
165
+ [React](docs/shims/react.md), [Preact](docs/shims/preact.md), and
166
+ [Django](docs/shims/django.md) guides.
167
+
168
+ ## Build, assets and verification
169
+
170
+ The build emits declarations and uses separate Vite configurations for the root,
171
+ external, Django and framework entries. Root output includes ESM/UMD; the other
172
+ exported entries are ESM. Vite targets ES2019. Bundled mode injects Leaflet/Draw
173
+ styles inside Shadow DOM and configures marker assets. External hosts must supply
174
+ a compatible shared Leaflet stack; opting out of injected styles does not make
175
+ ordinary document CSS cross the Shadow DOM boundary.
176
+
177
+ Vitest unit/integration tests and Playwright browser suites are present, not
178
+ planned work. [tests](tests) cover stores, pipelines, providers, lifecycle,
179
+ wrappers and presentation contracts; [e2e](e2e) exercises real map interactions.
180
+ HTML harnesses include `irrigation-draw-mode.html`, `layer-manager.html`,
181
+ `external.html`, and the React/Preact variants.
182
+
183
+ ```sh
184
+ npm run typecheck
185
+ npm run test:unit
186
+ npm run build
187
+ npm run test:e2e
188
+ ```
189
+
190
+ Use `npm run test:unit:focused -- tests/<suite>.spec.ts` for a targeted check
191
+ without global coverage thresholds. Specialized Playwright configs exist for
192
+ layers, providers, layout, touch, accessibility, capabilities, snapping and
193
+ release checks. Their fixture-based passes do not validate live vendor service
194
+ availability. [PUBLISHING.md](PUBLISHING.md) owns release instructions and
195
+ [CHANGELOG.md](CHANGELOG.md) records shipped changes.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.9.0 - 2026-10-02
6
+
7
+ - Added host-controlled toolbar capabilities, lifecycle events, keyboard accessibility, responsive layout, and extensible styling for polished custom map controls.
8
+ - Added named layer registration, visibility and style management, provider adapters, and a layer-manager harness for application-owned layer workflows.
9
+ - Added GeoJSON validation and transformation pipelines, snapping and measurement primitives, grower-oriented geometry utilities, and public type coverage for the new APIs.
10
+ - Hardened pointer-driven feature movement and expanded unit and Playwright coverage across tool activation, touch geometry, accessibility, providers, layers, snapping, and consumer-facing contracts.
11
+ - Documented the new toolbar, layer, provider, GeoJSON, geometry, snapping, measurement, and Google Maps adapter surfaces.
12
+
5
13
  ## 0.8.3 - 2026-08-28
6
14
 
7
15
  - Upgraded `uuid` to a patched release so consumer audits no longer inherit GHSA-w5hq-g745-h8pq through GeoKit.
package/README.md CHANGED
@@ -14,7 +14,18 @@ Primary sources
14
14
 
15
15
  Documentation quick-links
16
16
 
17
+ - Branded toolbar, external layer-cake button, trust boundaries and screenshot checklist: [docs/custom-toolbar.md](docs/custom-toolbar.md); runnable [plain HTML example](custom-toolbar.html).
18
+ - Public API tables: [docs/api-reference.md](docs/api-reference.md).
19
+ - Integration recipes (including SSR): [docs/integration-recipes.md](docs/integration-recipes.md).
20
+ - Diagnostic event catalog and troubleshooting: [docs/diagnostics.md](docs/diagnostics.md).
21
+ - Release and packed-consumer verification: [docs/release-verification.md](docs/release-verification.md).
22
+ - Provider v2 contracts, diagnostics, MapLibre/PMTiles shim and security: [docs/providers.md](docs/providers.md)
23
+ - Optional Google Maps adapter spike: [docs/google-maps-adapter-spike.md](docs/google-maps-adapter-spike.md)
24
+ - Validated GeoJSON adapters, metadata round trips, diff/patch: [docs/geojson-pipelines.md](docs/geojson-pipelines.md)
17
25
  - Architecture overview: [ARCHITECTURE.md](ARCHITECTURE.md)
26
+ - Public tool lifecycle: [docs/tool-lifecycle.md](docs/tool-lifecycle.md)
27
+ - Tool availability, disabled reasons and external button binding: [docs/tool-capabilities.md](docs/tool-capabilities.md)
28
+ - Named map layers, host-rendered styles and cake sessions: [docs/layers.md](docs/layers.md); run `npm run dev` and open `/layer-manager.html` for the live sidebar harness.
18
29
  - Dev harness (example): [index.html](index.html)
19
30
  - Unit tests: [tests/element.spec.ts](tests/element.spec.ts)
20
31
  - Vitest config: [vitest.config.ts](vitest.config.ts)
@@ -552,7 +563,7 @@ map!.toolbarGroups = toolbarGroups;
552
563
  Supported tool keys are `polygon`, `polyline`, `rectangle`, `circle`, `marker`,
553
564
  `layerCake`, `move`, `select`, `edit`, `delete`, `ruler`,
554
565
  `measurementSettings`, `layerStyle`, and `save`. `select` disables active draw/edit
555
- handlers; `layerStyle` emits a public trigger event for host-owned style panels;
566
+ handlers; `layerStyle` opens a preset panel (cancel `leaflet-geokit:layer-style-request` to render a host-owned panel instead);
556
567
  `save` emits `leaflet-draw:export` with the current editable GeoJSON for host
557
568
  persistence.
558
569
 
@@ -561,6 +572,80 @@ persistence.
561
572
  property to `undefined` to return to the attribute, or `null` to clear the
562
573
  programmatic config while keeping stable `data-geokit-tool` hooks.
563
574
 
575
+ #### Toolbar styling contract (v2)
576
+
577
+ See the [keyboard and accessibility contract](docs/accessibility.md) for toolbar
578
+ navigation, save/cancel commands, focus handling, announcements, contrast/motion
579
+ tokens, and the limits of the current touch verification.
580
+
581
+ Managed `toolbarGroups` use normal CSS rules, not inline `!important` visual
582
+ styles. Defaults are 44px buttons with visible hover, focus, active and disabled
583
+ states. Existing `toolButtonConfig`, `toolbarGroups`, `data-geokit-tool`,
584
+ `themeCss` and `theme-url` APIs remain supported in bundled and external runtimes.
585
+
586
+ Public parts: `host` and `map` (the internal map-sized surface), `toolbar-group`,
587
+ `toolbar-button`, `icon`, `popover`, `active`, `disabled`, `badge`, `tooltip`.
588
+ Style the actual element box with `leaflet-geokit`, and internals via `::part`:
589
+
590
+ ```css
591
+ /* Pure CSS overrides for existing configured groups. */
592
+ leaflet-geokit {
593
+ --geokit-tool-size: 48px;
594
+ --geokit-tool-radius: 8px;
595
+ --geokit-tool-background: #edf6ee;
596
+ --geokit-toolbar-gap: 10px;
597
+ --geokit-icon-size: 24px;
598
+ }
599
+ leaflet-geokit::part(toolbar-group) {
600
+ border: 2px solid #246b45;
601
+ }
602
+ leaflet-geokit::part(toolbar-button):focus-visible {
603
+ outline: 3px solid #246b45;
604
+ }
605
+ leaflet-geokit::part(active) {
606
+ color: #124124;
607
+ }
608
+ ```
609
+
610
+ ```ts
611
+ // JS config only: no custom stylesheet required.
612
+ map.toolbarGroups = [
613
+ {
614
+ id: "care",
615
+ tools: ["polygon", "save"],
616
+ position: "bottomleft",
617
+ offset: [16, 24],
618
+ orientation: "horizontal",
619
+ gap: 12,
620
+ hideDefaultToolbar: true,
621
+ },
622
+ ];
623
+ map.toolButtonConfig = {
624
+ polygon: { title: "Draw growing space", iconSize: [28, 28] },
625
+ save: { title: "Save", ariaLabel: "Save 2 growing spaces", badge: "2" },
626
+ };
627
+ ```
628
+
629
+ For mixed CSS + config, combine those examples: public tokens override config's
630
+ visual defaults (including gap and icon size); placement and behavior stay in JS.
631
+ Per-group/per-tool overrides belong in `themeCss` or `theme-url`:
632
+
633
+ ```ts
634
+ map.themeCss = `
635
+ [data-geokit-managed-toolbar][data-geokit-toolbar-group="care"] {
636
+ --geokit-toolbar-gap: 14px;
637
+ --geokit-tool-background: #edf6ee;
638
+ }
639
+ button[data-geokit-tool="save"] { --geokit-tool-radius: 50%; }
640
+ `;
641
+ ```
642
+
643
+ The [complete styling contract](docs/toolbar-styling.md)
644
+ documents all tokens/defaults, slots, state semantics, native-control boundaries,
645
+ and placement/visibility behavior. Try the default/CSS/config/mixed selector in
646
+ `irrigation-draw-mode.html`. See [responsive zones and overflow](docs/toolbar-layout.md)
647
+ for the implemented layout builder.
648
+
564
649
  #### External Tool Triggers
565
650
 
566
651
  Outside DOM controls can activate any configured tool through the public custom
@@ -598,14 +683,31 @@ code to reach into Leaflet.draw toolbar internals. The legacy
598
683
  `{ action: "deactivate" }` or `{ active: false }` in its detail to use it as a
599
684
  deactivate request.
600
685
 
601
- GeoKit emits `leaflet-geokit:tool-trigger-requested`, then either
602
- `leaflet-geokit:tool-triggered` or
603
- `leaflet-geokit:tool-trigger-failed`. Event detail includes `tool`, `source`,
604
- `groupId`, `handled`, `timestamp`, and optional `error`.
605
-
606
- See `irrigation-draw-mode.html` for a working integration demo with custom
607
- icons, popovers, two toolbar groups, an external panel button, real polygon
608
- draw activation, and a custom save button.
686
+ The canonical public bus emits `leaflet-geokit:tool-command`,
687
+ `tool-commanded`, `tool-started`, `tool-completed`, `tool-cancelled`,
688
+ `tool-failed`, and `tool-state-changed`. Every phase uses exported
689
+ `ToolEventDetail` and preserves `source`, `groupId`, and `commandId`.
690
+ Committed geometry phases also contain feature ids and a GeoJSON snapshot.
691
+ All lifecycle events bubble and cross the component's Shadow DOM boundary.
692
+
693
+ Event-only hosts can dispatch `leaflet-geokit:tool-command` with
694
+ `{ tool, action?, source?, groupId?, commandId? }`. Activation is not
695
+ completion: interactive draw tools complete only when geometry is committed,
696
+ and LayerCake completes only when its manager saves. Action tools
697
+ (`save`, `layerStyle`, and `measurementSettings`) complete immediately
698
+ without replacing an active persistent tool.
699
+
700
+ The older `leaflet-geokit:tool-trigger-requested`,
701
+ `leaflet-geokit:tool-triggered`, and
702
+ `leaflet-geokit:tool-trigger-failed` events remain compatibility aliases and
703
+ now include `commandId` in addition to `tool`, `source`, `groupId`,
704
+ `handled`, `timestamp`, and optional `error`.
705
+
706
+ The [complete lifecycle contract](docs/tool-lifecycle.md) inventories all 14
707
+ tools, every activation path, ordering, switches/repeats, Escape/cancellation,
708
+ LayerCake continuation, and failure behavior. See
709
+ `irrigation-draw-mode.html` for outside start/stop/save/failure controls using
710
+ only public APIs.
609
711
 
610
712
  #### Programmatic Marker Icon Override
611
713
 
@@ -794,7 +896,9 @@ console.log("Imported features with IDs:", ids);
794
896
  ```javascript
795
897
  await map.loadGeoJSON({
796
898
  type: "FeatureCollection",
797
- features: [/* ... */],
899
+ features: [
900
+ /* ... */
901
+ ],
798
902
  });
799
903
  ```
800
904
 
@@ -830,7 +934,9 @@ await map.clearLayers();
830
934
  await map.updateFeature(featureId, {
831
935
  type: "Feature",
832
936
  properties: { name: "Updated" },
833
- geometry: {/* ... */},
937
+ geometry: {
938
+ /* ... */
939
+ },
834
940
  });
835
941
  ```
836
942
 
@@ -1489,6 +1595,35 @@ Versioning and releases
1489
1595
 
1490
1596
  ---
1491
1597
 
1598
+ ## Snapping, live measurements, and grower scale
1599
+
1600
+ The component keeps snapping backward-compatible by default: enable it explicitly
1601
+ with `snapping`. Modes are `vertex`, `edge`, `grid`, and `guide`; tolerance is
1602
+ measured in screen pixels. Grid spacing is physical WGS84 meters and
1603
+ `gridOrigin` is a fixed `[longitude, latitude]` anchor (default `[0, 0]`).
1604
+ Latitude nodes use ellipsoidal meridian distance and longitude nodes use the
1605
+ parallel scale at the snapped latitude. Grid snapping is supported inside
1606
+ ±89.9° latitude and is an editing/planning aid rather than survey accuracy.
1607
+ Guide candidates come from the current layer registry and must be visible.
1608
+
1609
+ ```ts
1610
+ map.snapping = {
1611
+ enabled: true,
1612
+ modes: ["vertex", "edge", "grid", "guide"],
1613
+ tolerancePx: 14,
1614
+ gridSizeMeters: 1,
1615
+ gridOrigin: [0, 0],
1616
+ };
1617
+ map.measurementOverlay = { enabled: true, autoScale: true };
1618
+ ```
1619
+
1620
+ The live overlay follows `setMeasurementUnits("metric" | "imperial")` and
1621
+ refreshes during draw/edit. Grower helpers and `GROWER_PRESETS` are exported from
1622
+ `src/index.ts` and `src/external.ts`; add generated guide features with
1623
+ `layer: { kind: "guide" }` to make them snap targets. Invalid helper operations
1624
+ return an actionable error result and do not alter existing layers. See
1625
+ [`docs/snapping-and-measurements.md`](docs/snapping-and-measurements.md).
1626
+
1492
1627
  ## License
1493
1628
 
1494
1629
  ## MIT
@@ -0,0 +1,165 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>GeoKit branded toolbar recipe</title>
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ padding: 1rem;
11
+ font-family: system-ui, sans-serif;
12
+ background: #f4f8f2;
13
+ color: #183b27;
14
+ }
15
+ nav,
16
+ .actions {
17
+ display: flex;
18
+ flex-wrap: wrap;
19
+ gap: 0.75rem;
20
+ margin-bottom: 1rem;
21
+ }
22
+ nav a {
23
+ color: inherit;
24
+ text-underline-offset: 0.2em;
25
+ }
26
+ button {
27
+ min-height: 44px;
28
+ padding: 0.5rem 1rem;
29
+ border: 1px solid currentColor;
30
+ border-radius: 0.75rem;
31
+ background: #edf6ee;
32
+ color: #183b27;
33
+ cursor: pointer;
34
+ }
35
+ button:focus-visible {
36
+ outline: 3px solid #287d47;
37
+ outline-offset: 3px;
38
+ }
39
+ button:disabled {
40
+ opacity: 0.5;
41
+ cursor: not-allowed;
42
+ }
43
+ leaflet-geokit {
44
+ display: block;
45
+ height: 65vh;
46
+ min-height: 320px;
47
+ width: 100%;
48
+ --geokit-tool-size: 48px;
49
+ --geokit-tool-radius: 12px;
50
+ --geokit-tool-background: #edf6ee;
51
+ --geokit-tool-color: #183b27;
52
+ --geokit-tool-focus-ring: 3px solid #287d47;
53
+ --geokit-toolbar-background: #f4f8f2;
54
+ --geokit-toolbar-gap: 8px;
55
+ }
56
+ leaflet-geokit::part(toolbar-group) {
57
+ border: 1px solid #287d47;
58
+ }
59
+ @media (prefers-color-scheme: dark) {
60
+ body {
61
+ background: #15261b;
62
+ color: #e0f1de;
63
+ }
64
+ button {
65
+ background: #203d2a;
66
+ color: #e0f1de;
67
+ }
68
+ leaflet-geokit {
69
+ --geokit-tool-background: #203d2a;
70
+ --geokit-tool-color: #e0f1de;
71
+ --geokit-toolbar-background: #15261b;
72
+ --geokit-tool-hover-background: #31563c;
73
+ --geokit-tool-focus-ring: 3px solid #9fdaaa;
74
+ }
75
+ }
76
+ @media (prefers-reduced-motion: reduce) {
77
+ leaflet-geokit::part(toolbar-button) {
78
+ transition: none;
79
+ }
80
+ }
81
+ </style>
82
+ </head>
83
+ <body>
84
+ <nav aria-label="Recipe navigation">
85
+ <a href="/">Dev harness</a
86
+ ><a href="/docs/custom-toolbar.md">Toolbar recipe</a>
87
+ </nav>
88
+ <h1>Growing-space tools</h1>
89
+ <div class="actions">
90
+ <button id="cake" disabled>Build layered zone</button
91
+ ><button id="cancel" disabled>Cancel tool</button>
92
+ </div>
93
+ <p id="status" role="status">Loading map…</p>
94
+ <p id="export-status" role="status"></p>
95
+ <leaflet-geokit
96
+ id="map"
97
+ draw-polygon
98
+ draw-rectangle
99
+ draw-marker
100
+ draw-layer-cake
101
+ ></leaflet-geokit>
102
+ <script type="module">
103
+ // In a consumer bundler use: import "@florasync/leaflet-geokit";
104
+ import "/src/index.ts";
105
+ const map = document.querySelector("#map");
106
+ const cake = document.querySelector("#cake");
107
+ const cancel = document.querySelector("#cancel");
108
+ const status = document.querySelector("#status");
109
+ // Developer-owned constant, never interpolated user HTML.
110
+ const leaf =
111
+ '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="none" stroke="currentColor" stroke-width="2" d="M5 19C2 7 10 3 20 4c0 10-5 17-15 15Zm0 0L16 8"/></svg>';
112
+ map.toolButtonConfig = {
113
+ polygon: {
114
+ title: "Draw growing space",
115
+ ariaLabel: "Draw growing space",
116
+ className: "flora-primary",
117
+ iconHtml: leaf,
118
+ popover: {
119
+ title: "Boundary",
120
+ body: "Click corners, then the first point to finish.",
121
+ },
122
+ },
123
+ save: {
124
+ title: "Save growing spaces",
125
+ ariaLabel: "Save growing spaces",
126
+ },
127
+ };
128
+ map.toolbarGroups = [
129
+ {
130
+ id: "grow",
131
+ tools: ["polygon", "select", "save"],
132
+ position: "bottomleft",
133
+ orientation: "horizontal",
134
+ offset: [12, 12],
135
+ hideDefaultToolbar: true,
136
+ ariaLabel: "Growing-space tools",
137
+ },
138
+ ];
139
+ map.themeCss =
140
+ '[data-geokit-tool="polygon"].flora-primary { --geokit-tool-radius: 50%; }';
141
+ function refresh() {
142
+ const state = map.getToolCapabilities().tools.layerCake;
143
+ cake.disabled = state.state !== "enabled";
144
+ cake.title = state.reason?.message ?? "Build layered zone";
145
+ cancel.disabled = !map.status.ready;
146
+ status.textContent = map.status.ready
147
+ ? "Ready to draw"
148
+ : "Loading map…";
149
+ }
150
+ map.addEventListener("leaflet-geokit:tool-capabilities-changed", refresh);
151
+ map.addEventListener("leaflet-geokit:status", refresh);
152
+ cake.addEventListener("click", async () => {
153
+ await map.activateTool("layerCake", { source: "external-recipe" });
154
+ });
155
+ cancel.addEventListener("click", async () => {
156
+ await map.deactivateTool({ source: "external-recipe" });
157
+ });
158
+ map.addEventListener("leaflet-draw:export", (event) => {
159
+ document.querySelector("#export-status").textContent =
160
+ `Exported ${event.detail.geoJSON.features.length} growing spaces; host owns persistence.`;
161
+ });
162
+ refresh();
163
+ </script>
164
+ </body>
165
+ </html>