@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
package/docs/layers.md ADDED
@@ -0,0 +1,136 @@
1
+ # Named layers and layer-cake sessions
2
+
3
+ GeoKit's framework-agnostic element API exposes a detached layer registry. Existing feature CRUD, tool commands and GeoJSON defaults remain available. This is client-side map state; there is no FloraSync API integration or vendor provisioning.
4
+
5
+ ## Registry and rendering
6
+
7
+ `getLayers(): MapLayer[]` returns back-to-front records with `id`, `name`, `kind`, `visible`, `order`, `featureIds` and portable `style`. Kinds are `base`, `drawn`, `imported`, `guide` (including references), and `measurement` (persisted measurement GeoJSON overlays). The live basemap has the reserved id `base`. Temporary ruler plugin graphics are not persisted measurement features.
8
+
9
+ Each ordinary drawing becomes a drawn layer. Each import becomes a named group; a saved cake becomes one drawn group containing its editable core/ring polygon features. Group membership is independent of feature properties. A hidden group is removed from the edit/draw feature group but its features remain in the store/export.
10
+
11
+ ```ts
12
+ await map.importGeoJSON(fenceGeoJSON, {
13
+ behavior: "add",
14
+ layer: {
15
+ id: "fences",
16
+ name: "Fence reference",
17
+ kind: "guide",
18
+ style: { color: "#735aa6", dashArray: "6 4" },
19
+ },
20
+ });
21
+ await map.importGeoJSON(measurementGeoJSON, {
22
+ behavior: "add",
23
+ layer: { name: "Measured bed lengths", kind: "measurement" },
24
+ });
25
+ const layers = map.getLayers();
26
+ await map.setLayerVisibility("fences", false);
27
+ await map.setLayerStyle("fences", {
28
+ color: "#176da5",
29
+ weight: 3,
30
+ opacity: 0.8,
31
+ });
32
+ await map.reorderLayers(layers.map((layer) => layer.id).reverse());
33
+ await map.focusLayer("fences");
34
+ await map.removeLayer("fences");
35
+ ```
36
+
37
+ - `reorderLayers` requires every current id exactly once; invalid orders do not mutate state. Order applies within Leaflet's vector/marker panes; a basemap cannot cover vector overlays simply by reordering. Marker offsets also retain Leaflet's latitude-based stacking behavior.
38
+ - `focusLayer` fits its features without changing visibility. A basemap or empty group has no feature bounds, so focus is a no-op.
39
+ - `setLayerStyle` merges a portable subset: `color`, `fillColor`, `weight` (0–100), `opacity`/`fillOpacity` (0–1), `dashArray`. Invalid numeric values fail before mutation. Paths support path styling; standard image markers support opacity, not vector fill/stroke. Tile basemaps support opacity; an optional non-tile adapter may not implement opacity.
40
+ - `removeLayer` removes all member features, including hidden features. It rejects read-only mode and the basemap. Hide the basemap instead. Visibility/style/order are presentation changes and remain available in read-only mode. Guide/measurement are semantic kinds, not separate permissions; visible features still use the existing editor.
41
+ - Individual feature updates/removals and draw deletion keep membership synchronized. An empty data group disappears. An add-import with an existing feature id retains legacy upsert semantics, moving that feature into the new import group rather than drawing a duplicate.
42
+ - Subscribe to `leaflet-geokit:layers-changed` (`detail.layers`) for a sidebar. Snapshots are detached; mutate state only through the API.
43
+
44
+ ## External cake controls
45
+
46
+ The existing public tool bus activates the same circle-drawing tool used by the toolbar:
47
+
48
+ ```ts
49
+ secondaryButton.onclick = () =>
50
+ map.dispatchEvent(
51
+ new CustomEvent("leaflet-geokit:tool-command", {
52
+ detail: {
53
+ tool: "layerCake",
54
+ source: "secondary-button",
55
+ commandId: "orchard-1",
56
+ },
57
+ }),
58
+ );
59
+ map.addEventListener("tool:layer-cake:session-started", (event) => {
60
+ renderSidebar(event.detail.session);
61
+ });
62
+ ```
63
+
64
+ The map must enable `draw-layer-cake`. Draw the first circle to begin a session. `getLayerCakeSession()` returns null before/after the session, otherwise `{ id, name, center, rings: [{ radius }], style }`. Distances are meters regardless of the ruler's display units.
65
+
66
+ ```ts
67
+ await map.updateLayerCakeSession({
68
+ name: "Orchard water zones",
69
+ radii: [100, 150, 225],
70
+ preset: "water",
71
+ });
72
+ await map.saveLayerCakeSession(); // Same save operation as the map's Save button.
73
+ // Or: await map.cancelLayerCakeSession();
74
+ ```
75
+
76
+ `radii` must have one to ten strictly increasing positive finite values. Updating replaces the session's editable circle handles; dragging those handles also updates the session. The circles keep a shared center. `name`, `radii`, `preset`, and `style` can be updated independently. Built-in presets are `crop`, `water`, and `reference`, also exported as `LAYER_STYLE_PRESETS`. Explicit style fields override the chosen preset.
77
+
78
+ Session events are DOM events on the element (bubbling/composed), and also remain available through `toolHooks`/`toolEventEmitter`:
79
+
80
+ - `tool:layer-cake:session-started`
81
+ - `tool:layer-cake:session-changed` (ring controls/dragging/sidebar edits)
82
+ - `tool:layer-cake:saved` (adds `layerId`, `featureCollection`)
83
+ - `tool:layer-cake:cancelled` (draft discarded)
84
+
85
+ Their `LayerCakeEventDetail` contains `session` and the initiating command's `source`, `commandId`, `groupId` when available. The original started event's `center`/`radius` fields and saved event's `featureCollection` remain compatible. These events supplement, not replace, the correlated `leaflet-geokit:tool-*` lifecycle. Save produces named core/ring polygons using the existing cake baker; standard polygon edit/move works afterward. Session radii are draft controls, not a reconstruction API for an already-saved cake. Cancellation, Escape, a superseding tool, clearing data, and destruction dispose draft handles/listeners. Updating/saving a missing session rejects; cancellation without a session is harmless.
86
+
87
+ ## Style panel: built in or host-owned
88
+
89
+ ```ts
90
+ map.dispatchEvent(
91
+ new CustomEvent("leaflet-geokit:tool-command", {
92
+ detail: { tool: "layerStyle", source: "sidebar" },
93
+ }),
94
+ );
95
+ ```
96
+
97
+ Without a host override this opens a compact layer selector and preset panel. It uses `part="layer-style-panel"`, `--geokit-panel-background`, and `--geokit-panel-color`. Escape/Close dismiss it and restore focus. `layerStyle`'s tool-completed event still means the panel request was handled, not that a style has been saved.
98
+
99
+ To render the editor anywhere outside the component:
100
+
101
+ ```ts
102
+ map.addEventListener("leaflet-geokit:layer-style-request", (event) => {
103
+ event.preventDefault(); // Synchronous cancellation suppresses the built-in panel.
104
+ renderHostPanel(event.detail.layers, async (id, style) => {
105
+ await map.setLayerStyle(id, style);
106
+ });
107
+ });
108
+ ```
109
+
110
+ `LayerStyleRequestDetail` is a detached snapshot; subscribe to layers-changed if a host panel needs live updates. Closing a host-owned panel is the host's responsibility. No framework or DOM node is required in the public data model.
111
+
112
+ ## Optional export/import persistence
113
+
114
+ ```ts
115
+ const snapshot = await map.exportGeoJSON({ preserveLayers: true });
116
+ await map.importGeoJSON(JSON.parse(JSON.stringify(snapshot)), {
117
+ behavior: "replace",
118
+ preserveLayers: true,
119
+ });
120
+ ```
121
+
122
+ The versioned FeatureCollection foreign member `geokit:layers` stores the registry, including order, visibility, style, names and membership. It contains no URLs, provider keys or Leaflet objects. Basemap presentation is restored, not provider configuration. Default export remains ordinary GeoJSON. Default import ignores registry metadata and groups the imported features normally. Use `preserveLayers` on **both** ends. `getGeoJSON()` remains a feature-only store snapshot.
123
+
124
+ Restoration requires replace mode, unique known feature membership, complete feature coverage and the reserved base record. Missing/invalid metadata fails before clearing current data. `preserveLayers` with add mode is deliberately rejected: silently merging conflicting layer ids/order would be ambiguous. It also works with the source export adapter when expanded feature ids remain reconstructible by the existing GeoJSON pipeline. External tools that strip foreign members lose layer presentation metadata; geometry/properties remain standard GeoJSON. Do not rely on JSON object property key order when comparing snapshots.
125
+
126
+ ## Exercised harness and checks
127
+
128
+ `npm run dev`, then open `/layer-manager.html`. The host sidebar uses only public APIs and events: secondary cake button, ring edits, save/cancel, built-in and host-owned style panels, visibility and export/restore.
129
+
130
+ ```sh
131
+ npm run typecheck
132
+ npm run test:unit:focused -- tests/layer-registry.spec.ts tests/layer-cake-manager.spec.ts tests/map-controller.spec.ts tests/tool-lifecycle.spec.ts
133
+ npx playwright test -c playwright.layers.config.ts
134
+ ```
135
+
136
+ The isolated Playwright server uses port 5191, no HMR, Chromium and deterministic tile responses for the new harness. It proves actual circle drawing/handles, sidebar session edits/save/cancel, SVG styles, hidden physical layers, exact structural registry restoration, and legacy irrigation tool-bus interaction. Public tile network availability is not part of that assertion.
@@ -0,0 +1,191 @@
1
+ # Provider abstraction v2
2
+
3
+ ## Contents
4
+
5
+ - [Compatibility and boundary](#compatibility-and-boundary)
6
+ - [Public API](#public-api)
7
+ - [MapLibre and PMTiles execution path](#maplibre-and-pmtiles-execution-path)
8
+ - [Capability diagnostics](#capability-diagnostics)
9
+ - [Security and vendor independence](#security-and-vendor-independence)
10
+ - [Verification and limitations](#verification-and-limitations)
11
+
12
+ ## Compatibility and boundary
13
+
14
+ Implemented against package version 0.8.3. Leaflet + OSM remains the default;
15
+ no vendor SDK, paid account, or new runtime dependency is added.
16
+
17
+ The existing `tile-provider="osm"`, `tile-provider="here"`, `tile-style`,
18
+ `api-key` / `here-api-key`, and custom `tile-url` / `tile-attribution` paths
19
+ remain intact. Custom URLs use `tile-url`, not a new `tile-provider="custom"`
20
+ identifier. Clear `tileProvider` to use a custom URL.
21
+
22
+ Three separate ports are declared in `src/lib/providers.ts`:
23
+
24
+ 1. `RasterTileProvider`: resolves a URL template and tile options. The legacy
25
+ OSM/HERE factory remains the source of truth; custom URLs have their own factory.
26
+ 2. `VectorBasemapProvider`: creates a fresh, unmounted Leaflet layer through an
27
+ injected renderer bridge. GeoKit retains map ownership and existing draw tools.
28
+ 3. `DrawEngineAdapter<Context, Document, Command>`: attach/read/write/execute/dispose
29
+ contract for a future draw-engine replacement. This is a **design port**, not
30
+ a claim that Leaflet.draw has been refactored or native MapLibre/Google drawing
31
+ is implemented. Current drawing and completed irrigation work are reused as-is.
32
+
33
+ Renderer-specific dependencies belong outside core. A native map renderer swap
34
+ would need a draw adapter implementing GeoJSON and public tool lifecycle parity.
35
+ Do not mistake the basemap seam for that much larger project.
36
+
37
+ ## Public API
38
+
39
+ Both root and `/external` entrypoints export the provider contracts and factories:
40
+
41
+ - `createRasterProvider({ provider: "osm" | "here", ... })`
42
+ - `createCustomRasterProvider({ urlTemplate, attribution, ... })`
43
+ - `createMapLibreBasemapAdapter({ createLayer, attribution, offline?, apiKey? })`
44
+ - `getProviderDiagnostics(provider, attribution)` (pure configuration report)
45
+
46
+ The existing element gains:
47
+
48
+ - `setBasemapAdapter(adapter)` after `ready`: replace only the basemap.
49
+ - `setBasemapAdapter(null)`: restore the current raster attributes/properties.
50
+ - `getProviderDiagnostics()`: detached configuration snapshot, or null before
51
+ initialization / after disconnect.
52
+
53
+ The adapter's layer must clean up renderer workers, event handlers and resources
54
+ in Leaflet `onRemove`. GeoKit removes it on swap and map destruction. Return a
55
+ fresh layer each time; mounted/reused layers are rejected. A synchronous vector
56
+ mount failure leaves the previous basemap active. Missing required attribution
57
+ is rejected before mounting. Async renderer load errors are the optional bridge's
58
+ responsibility; restore `null` explicitly if the host wants raster fallback.
59
+
60
+ Existing provider attributes override an active adapter when changed. Reconnect
61
+ restores raster configuration; reapply the adapter after readiness. Geometry,
62
+ feature IDs, existing draw controls, read-only state and public tool events remain
63
+ owned by GeoKit. `tile-provider-changed` reports `provider: "adapter"`; tool
64
+ capabilities report `requested/active: "adapter"` without vendor configuration.
65
+
66
+ ## MapLibre and PMTiles execution path
67
+
68
+ This release ships a **dependency-injected feasibility shim**, not a production
69
+ WebGL renderer. The next optional adapter package can use the existing public
70
+ `setBasemapAdapter` method without changing web component consumers.
71
+
72
+ Host-side experiment (not installed by this slice):
73
+
74
+ 1. Create a separate adapter/example package. Select and pin mutually compatible
75
+ `leaflet`, `maplibre-gl`, `@maplibre/maplibre-gl-leaflet`, and `pmtiles` versions.
76
+ The current upstream bridge documentation uses a named `maplibreGL` export;
77
+ older bridge versions use different registration patterns. Recheck the selected
78
+ release, rather than copying a historical global `L.maplibreGL` call.
79
+ 2. Use GeoKit's external entrypoint and one shared Leaflet instance. Load Leaflet,
80
+ draw and MapLibre styles, configure MapLibre's worker/CSP requirements, and
81
+ supply `leafletInstance` before connecting the element.
82
+ 3. Register PMTiles once per host application. Feed the bridge a style whose source
83
+ is `type: "vector", url: "pmtiles://https://your-host/region.pmtiles"`.
84
+ PMTiles is a tile archive transport, not a renderer; it also supports raster
85
+ archives. This vector bridge contract describes the rendering path, not every
86
+ source inside a MapLibre style.
87
+ 4. Wrap the bridge factory in the shipped shim:
88
+
89
+ ```ts
90
+ import { maplibreGL } from "@maplibre/maplibre-gl-leaflet";
91
+ import maplibregl from "maplibre-gl";
92
+ import { Protocol } from "pmtiles";
93
+ import { createMapLibreBasemapAdapter } from "@florasync/leaflet-geokit/external";
94
+
95
+ // Host initialization: once, using the SAME MapLibre module as the bridge.
96
+ const protocol = new Protocol();
97
+ maplibregl.addProtocol("pmtiles", protocol.tile);
98
+
99
+ // After GeoKit ready; /maps/style.json contains the PMTiles source.
100
+ mapElement.setBasemapAdapter(
101
+ createMapLibreBasemapAdapter({
102
+ createLayer: () => maplibreGL({ style: "/maps/style.json" }),
103
+ attribution: "Your licensed dataset attribution",
104
+ offline: "host-managed",
105
+ apiKey: "none",
106
+ }),
107
+ );
108
+
109
+ // Remove all maps/bridges BEFORE host-global protocol teardown.
110
+ mapElement.setBasemapAdapter(null);
111
+ maplibregl.removeProtocol("pmtiles");
112
+ ```
113
+
114
+ This recipe is sourced from upstream APIs, but the optional packages and actual
115
+ archive rendering are **not exercised by this slice**. Before production promotion:
116
+
117
+ - Verify HTTP range requests, CORS, archive content type, source-layer names,
118
+ fonts, sprites and licensing with an owned fixture archive.
119
+ - Verify offline mode with network disabled and all required assets provisioned.
120
+ `host-managed` declares potential, not a cache implementation or permission.
121
+ - Exercise pan/zoom, high-DPI, touch, resize, WebGL loss, worker/CSP failures,
122
+ renderer error fallback, repeated swaps and multiple simultaneous maps.
123
+ - Keep drawing above the basemap and pointer events with Leaflet. The upstream
124
+ bridge has no pitch/rotation support and recommends minZoom 1 plus bounds
125
+ restrictions to avoid renderer synchronization issues. Test those explicitly.
126
+ - Confirm no duplicate Leaflet/MapLibre module instances and no worker/listener
127
+ leaks on removal. Do not remove a global PMTiles protocol still used by another map.
128
+
129
+ Sources:
130
+ [MapLibre Leaflet bridge](https://github.com/maplibre/maplibre-gl-leaflet),
131
+ [PMTiles protocol integration](https://docs.protomaps.com/pmtiles/maplibre).
132
+
133
+ ## Capability diagnostics
134
+
135
+ Reports contain only: `kind`, `attribution`, `attributionRequired`, `offline`,
136
+ `apiKey`, `drawing`, `scope`. No URLs, keys, style JSON, attribution HTML, arbitrary
137
+ error payloads or vendor metadata are returned. `scope: "configuration"` explicitly
138
+ means this is not a tile-load health, key-validity or renderer-readiness probe.
139
+ Use existing provider/status events for runtime failures.
140
+
141
+ | Path | Kind | API key | Offline | Drawing |
142
+ | ---------------- | ------ | ----------------------- | ------------------ | ------------ |
143
+ | OSM public tiles | raster | none | unsupported | leaflet-draw |
144
+ | HERE built-in | raster | required | unsupported | leaflet-draw |
145
+ | Custom tile URL | raster | host-defined | unknown | leaflet-draw |
146
+ | MapLibre shim | vector | host-defined by default | unknown by default | leaflet-draw |
147
+
148
+ Attribution is `present` or `missing`, not a legal-compliance validation. Hosts
149
+ must provide the required data/vendor notices even for offline maps. Missing
150
+ attribution on a legacy custom URL is reported, not a breaking rejection.
151
+ Capability declarations are trusted host configuration, not telemetry evidence.
152
+
153
+ ## Security and vendor independence
154
+
155
+ - Never put server credentials, signing secrets, service-account material or
156
+ unrestricted paid-vendor keys into HTML, attributes, browser bundles, URLs,
157
+ diagnostics, screenshots, logs or exported GeoJSON. A key passed through a JS
158
+ property instead of an attribute is **still visible to the browser**.
159
+ - Existing HERE browser key support is compatibility, not the blessed production
160
+ path. Use a vendor-approved server-side gateway with application authentication,
161
+ rate limits and quotas when that product permits it. A proxy must not become an
162
+ open paid API relay, and cannot bypass vendor licensing or conceal keys required
163
+ by a browser SDK. See [Google adapter spike](google-maps-adapter-spike.md).
164
+ - Some SDKs necessarily use public browser identifiers. Such an optional deployment
165
+ requires an explicit security/billing decision, origin + API restrictions,
166
+ separate environments, usage monitoring, quotas and a revocation plan. These
167
+ controls reduce abuse; they do not turn browser identifiers into secrets.
168
+ - Attribution is trusted HTML passed to Leaflet. Sanitize remote/untrusted inputs.
169
+ Bridge code, style sources, worker URLs and tile URLs are trusted host input;
170
+ apply CSP/allowlists and avoid sending private grower data to an unapproved vendor.
171
+ - No automatic paid fallback, provisioning, billing integration or FloraSync API
172
+ wiring. Keep user data in GeoJSON with stable IDs and retain a tested OSM/custom
173
+ path. A commercial style or archive license must not trap user-authored geometry.
174
+ - Public OSM tiles are not an offline/bulk-download service. Self-host appropriately
175
+ licensed data for offline deployments; offline capability is not vendor permission.
176
+
177
+ ## Verification and limitations
178
+
179
+ ```sh
180
+ npm run test:unit:focused -- tests/providers.spec.ts tests/tile-provider-factory.spec.ts tests/component-tile-provider.spec.ts tests/map-controller.spec.ts
181
+ npx playwright test -c playwright.providers.config.ts
182
+ npm run typecheck
183
+ npm run build
184
+ ```
185
+
186
+ The Chromium test uses the existing irrigation harness and real Leaflet/Draw.
187
+ External raster requests are intercepted with deterministic image fixtures; HERE
188
+ credentials and service access are not tested. The vector fixture is deliberately
189
+ an injected Leaflet layer, not an imitation MapLibre renderer. It proves the shim
190
+ boundary, attribution, diagnostics, public switching and real pointer drawing with
191
+ feature preservation. Actual WebGL/PMTiles is the optional follow-on gate above.
@@ -0,0 +1,75 @@
1
+ # Release verification and consumer smoke
2
+
3
+ Run from the package root with installed dependencies (Node >=20, npm >=9).
4
+ These commands validate local source; they do not publish or authorize a release.
5
+
6
+ ```sh
7
+ npm run prettier:check
8
+ npm run lint
9
+ npm run typecheck
10
+ npm run test:unit:focused -- tests/element.spec.ts tests/toolbar-contract.spec.ts tests/tool-capabilities.spec.ts tests/tool-lifecycle.spec.ts tests/geojson-pipeline.spec.ts
11
+ npm run build
12
+ npm run pack:dry
13
+ npm run test:consumer
14
+ npx playwright test --config playwright.release.config.ts --workers=1 e2e/custom-toolbar.spec.ts e2e/irrigation-draw-mode.spec.ts e2e/public-tool-acceptance.spec.ts
15
+ ```
16
+
17
+ `pack:dry` invokes prepack and rebuilds. `test:consumer` expects a completed build,
18
+ packs with `--ignore-scripts` and `HUSKY=0` into an isolated temporary directory, checks all
19
+ export targets and required adoption docs in the actual tarball, rejects leaked
20
+ test declarations, then compiles imports of every package subpath with strict
21
+ TypeScript. It reuses installed dependency packages, not source aliases for
22
+ GeoKit, and removes its temporary consumer afterward. A missing declaration,
23
+ unresolved declaration dependency or absent export target fails the command.
24
+ This is a type-resolution smoke, not a claim that browser-only entries run in Node.
25
+ The gate compiles in strict NodeNext mode with `skipLibCheck: false`, including
26
+ transitive relative declaration imports. Some npm versions still invoke prepare
27
+ while packing with `--ignore-scripts`; `HUSKY=0` prevents hook installation.
28
+ After alias rewriting, the build normalizes relative declaration specifiers to
29
+ explicit `.js` paths using the TypeScript AST. This avoids depending on whether
30
+ the installed tsc-alias version adds extensions. Missing relative declaration
31
+ targets fail the build rather than ship unresolved imports.
32
+
33
+ For a release candidate, retain the full `npm run release:dry` (typecheck, coverage
34
+ unit suite, build, pack dry-run) and complete Playwright release suite. Focused
35
+ checks do not replace those gates. `.github/workflows/release-candidate.yml`
36
+ validates an exact source SHA and creates an immutable tarball;
37
+ `.github/workflows/npm-publish.yml` verifies approved bytes before publication.
38
+ The packed-consumer smoke is also part of `release:dry`.
39
+
40
+ ## Browser evidence
41
+
42
+ - `/custom-toolbar.html`: minimal branded toolbar, guidance popover, external
43
+ layer-cake activation/cancel, Save export and event-based activation. Its test
44
+ captures light/dark mobile/tablet/desktop screenshots.
45
+ - `/irrigation-draw-mode.html`: retain actual external-panel and secondary-toolbar
46
+ geometry creation/export assertions, not just idle button rendering.
47
+ - `e2e/public-tool-acceptance.spec.ts`: public tool interactions.
48
+ - Existing provider, GeoJSON, layer-manager, accessibility, responsive toolbar and
49
+ touch suites remain release gates; see their `e2e/*.spec.ts` sources.
50
+
51
+ Install Chromium with `npx playwright install chromium` if absent. The committed
52
+ release config uses port 5173 and may reuse a dev server outside CI. In a shared
53
+ workspace, use an owned Playwright config with a distinct strict port, no server
54
+ reuse, HMR disabled and a run-owned artifact/cache directory. Do not stop another
55
+ agent's server or rewrite shared screenshot baselines to get green results.
56
+ Use polling when host inotify watches are exhausted.
57
+
58
+ ## Publication and real consumer checks
59
+
60
+ 1. Obtain explicit release authorization for the exact reviewed source and archive.
61
+ 2. Run all release gates on that candidate; capture commands, statuses and SHA.
62
+ 3. Verify package export targets and strict packed-consumer compilation.
63
+ 4. Publish only approved bytes through the release workflow; never publish merely
64
+ because `pack:dry` passed.
65
+ 5. Download the registry tarball and compare SHA-256 and registry integrity with
66
+ the approved archive. Verify source/tag provenance separately.
67
+ 6. Load the version-pinned Django module in a real browser; require element
68
+ registration and no page errors. A 200 response alone does not prove importability.
69
+ 7. Verify the consuming app resolves the registry version, not a sibling source
70
+ alias; exercise its actual React/Preact and Django surfaces, including screenshots.
71
+
72
+ Release 0.9.0 consumer evidence is tracked on FLOA-526 and FLOA-452. New local docs
73
+ or harness edits are not retroactively present in that published archive. Keep
74
+ local verification, published artifact verification and deployed app verification
75
+ separate in handoffs.
@@ -0,0 +1,102 @@
1
+ # Django shim
2
+
3
+ This shim bridges a Django form widget (`<textarea>`) to the `<leaflet-geokit>` custom element. It keeps your form field synchronized with the map editor while letting Django submit the GeoJSON value as usual.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @florasync/leaflet-geokit
9
+ ```
10
+
11
+ ## Quick start (Django widget)
12
+
13
+ Create a widget that renders a textarea with the shim selector class:
14
+
15
+ ```python
16
+ # widgets.py
17
+ from django import forms
18
+
19
+ class LeafletGeoKitWidget(forms.Textarea):
20
+ template_name = "widgets/geokit_map.html"
21
+
22
+ class Media:
23
+ # ESM shim bundle (module script)
24
+ js = (
25
+ "https://cdn.jsdelivr.net/npm/@florasync/leaflet-geokit/dist/django/index.js",
26
+ )
27
+ css = {
28
+ "all": ("https://unpkg.com/leaflet/dist/leaflet.css",)
29
+ }
30
+
31
+ def __init__(self, attrs=None):
32
+ default_attrs = {"class": "geokit-editor-widget"}
33
+ if attrs:
34
+ default_attrs.update(attrs)
35
+ super().__init__(default_attrs)
36
+ ```
37
+
38
+ Template snippet (explicit init):
39
+
40
+ ```html
41
+ {# widgets/geokit_map.html #} {% include "django/forms/widgets/textarea.html" %}
42
+ <script type="module">
43
+ window.GeoKitDjango?.init(".geokit-editor-widget");
44
+ </script>
45
+ ```
46
+
47
+ ## Configuration via data attributes
48
+
49
+ The shim copies `data-geokit-*` attributes from the textarea onto the custom element, so you can configure the map per field without writing extra JS.
50
+
51
+ ```html
52
+ <textarea
53
+ class="geokit-editor-widget"
54
+ data-geokit-height="480"
55
+ data-geokit-latitude="39.7392"
56
+ data-geokit-longitude="-104.9903"
57
+ data-geokit-zoom="11"
58
+ data-geokit-draw-polygon
59
+ data-geokit-draw-rectangle
60
+ data-geokit-edit-features
61
+ data-geokit-delete-features
62
+ ></textarea>
63
+ ```
64
+
65
+ Notes:
66
+
67
+ - `data-geokit-height` accepts a number (pixels) or any valid CSS height string.
68
+ - Boolean attributes (e.g., `data-geokit-draw-polygon`) can be written as empty, `true`, or `1` to enable. Use `false` or `0` to skip.
69
+
70
+ ## Using the shim programmatically
71
+
72
+ ```js
73
+ import { initDjangoGeokit } from "@florasync/leaflet-geokit/django";
74
+
75
+ const handles = initDjangoGeokit(".geokit-editor-widget", {
76
+ height: 420,
77
+ elementAttributes: {
78
+ "draw-polygon": true,
79
+ "draw-rectangle": true,
80
+ "edit-features": true,
81
+ "delete-features": false,
82
+ zoom: 12,
83
+ },
84
+ onError: (error, context) => {
85
+ console.error("GeoKit Django shim error", error, context);
86
+ },
87
+ });
88
+
89
+ // Later if needed
90
+ handles.forEach((handle) => handle.destroy());
91
+ ```
92
+
93
+ ## Data flow
94
+
95
+ - The shim mounts `<leaflet-geokit>` above the textarea and hides the textarea.
96
+ - GeoJSON edits emit custom events (`leaflet-draw:*`); the shim calls `getGeoJSON()` and writes the serialized value back into the textarea.
97
+ - Initial textarea JSON (if any) is loaded into the map on `leaflet-draw:ready`.
98
+
99
+ ## Troubleshooting
100
+
101
+ - If the map is blank, make sure the field has a fixed height (use `data-geokit-height` or the shim `height` option).
102
+ - If you see a JSON parsing error, confirm the textarea contains a valid GeoJSON FeatureCollection.
@@ -0,0 +1,98 @@
1
+ # Preact shims
2
+
3
+ These shims provide lightweight Preact wrappers around the [`<leaflet-geokit>`](../../src/components/LeafletDrawMapElement.ts:17) custom element.
4
+
5
+ There are **two entrypoints**:
6
+
7
+ - External/additive wrapper (host already loads Leaflet/Draw): [`@florasync/leaflet-geokit/preact`](../../package.json:9)
8
+ - Bundled/self-provisioned wrapper (package provides Leaflet/Draw): [`@florasync/leaflet-geokit/preact-bundled`](../../package.json:9)
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @florasync/leaflet-geokit preact
14
+ ```
15
+
16
+ `preact` is a consumer-provided peer dependency for these wrappers.
17
+
18
+ ## Import
19
+
20
+ External/additive mode:
21
+
22
+ ```ts
23
+ import { PreactLeafletGeoKit } from "@florasync/leaflet-geokit/preact";
24
+ ```
25
+
26
+ Bundled/self-provisioned mode:
27
+
28
+ ```ts
29
+ import { PreactLeafletGeoKit } from "@florasync/leaflet-geokit/preact-bundled";
30
+ ```
31
+
32
+ ## Quick start
33
+
34
+ ```tsx
35
+ import { PreactLeafletGeoKit } from "@florasync/leaflet-geokit/preact";
36
+
37
+ export function MapEditor() {
38
+ return (
39
+ <PreactLeafletGeoKit
40
+ style={{ width: "100%", height: "420px" }}
41
+ attributes={{
42
+ latitude: 39.7392,
43
+ longitude: -104.9903,
44
+ zoom: 11,
45
+ "draw-polygon": true,
46
+ "draw-rectangle": true,
47
+ "edit-features": true,
48
+ }}
49
+ onChangeText={(text) => {
50
+ console.log(text);
51
+ }}
52
+ onError={(error) => console.error(error)}
53
+ />
54
+ );
55
+ }
56
+ ```
57
+
58
+ ## Choosing an entrypoint
59
+
60
+ - Use [`@florasync/leaflet-geokit/preact`](../../package.json:9) when your app already owns Leaflet + Leaflet.draw runtime and CSS.
61
+ - Use [`@florasync/leaflet-geokit/preact-bundled`](../../package.json:9) when you want this package to provide Leaflet + Leaflet.draw.
62
+
63
+ ## External Leaflet behavior (`/preact`)
64
+
65
+ By default, the wrapper mounts in external/additive mode:
66
+
67
+ - Sets `use-external-leaflet`
68
+ - Sets `skip-leaflet-styles`
69
+
70
+ So your app should load Leaflet + Leaflet.draw assets beforehand.
71
+
72
+ If needed, provide an explicit namespace via `leafletInstance`.
73
+
74
+ ## Bundled behavior (`/preact-bundled`)
75
+
76
+ By default, the bundled wrapper does **not** set external/additive flags.
77
+
78
+ - Does not set `use-external-leaflet`
79
+ - Does not set `skip-leaflet-styles`
80
+
81
+ This is the simplest path for apps that do not preload Leaflet.
82
+
83
+ ## Props (both wrappers)
84
+
85
+ - `attributes`: map of attributes forwarded to `<leaflet-geokit>`
86
+ - `externalLeaflet`: optional override of default wrapper mode (`/preact` defaults `true`, `/preact-bundled` defaults `false`)
87
+ - `leafletInstance`: explicit Leaflet namespace (`window.L` equivalent)
88
+ - `initialGeoJSONText`: loaded once after `leaflet-draw:ready`
89
+ - `onChangeText`: receives serialized GeoJSON after create/edit/delete/merge
90
+ - `onChangeGeoJSON`: receives parsed FeatureCollection object
91
+ - `onReady`: receives the underlying custom element
92
+ - `onError`: receives normalized `Error` objects
93
+
94
+ ## Notes
95
+
96
+ - Ensure the element has a fixed height.
97
+ - For strict ownership by host styles, keep `externalLeaflet` enabled and provide CSS from your app.
98
+ - Preact wrapper entrypoints do not bundle Preact runtime code; your app provides the Preact runtime.