@octostar/map-component 0.2.11 → 0.2.12
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.cjs +358 -194
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +358 -194
- package/dist/index.mjs.map +1 -1
- package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
- package/dist/types/lib/deep-clone.d.ts +22 -0
- package/dist/types/lib/deep-clone.d.ts.map +1 -0
- package/dist/types/lib/geometry-equals.d.ts +15 -0
- package/dist/types/lib/geometry-equals.d.ts.map +1 -0
- package/dist/types/lib/raf-coalescer.d.ts +29 -0
- package/dist/types/lib/raf-coalescer.d.ts.map +1 -0
- package/dist/types/lib/selection-diff.d.ts +68 -0
- package/dist/types/lib/selection-diff.d.ts.map +1 -0
- package/dist/types/lib/selection-hit-test.d.ts +44 -0
- package/dist/types/lib/selection-hit-test.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-editor-canvas.d.ts","sourceRoot":"","sources":["../../../client/src/components/map-editor-canvas.tsx"],"names":[],"mappings":"AAiMA,OAAO,kCAAkC,CAAC;AAC1C,OAAO,gDAAgD,CAAC;
|
|
1
|
+
{"version":3,"file":"map-editor-canvas.d.ts","sourceRoot":"","sources":["../../../client/src/components/map-editor-canvas.tsx"],"names":[],"mappings":"AAiMA,OAAO,kCAAkC,CAAC;AAC1C,OAAO,gDAAgD,CAAC;AA0PxD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAmG5E,eAAO,MAAM,eAAe,4GA+2R1B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep-clone helpers for host-facing feature APIs, replacing per-feature
|
|
3
|
+
* `JSON.parse(JSON.stringify(...))` round trips — those serialize the whole
|
|
4
|
+
* collection into one giant string and back (hundreds of ms and a matching
|
|
5
|
+
* peak-memory spike on a 100k-feature layer). `structuredClone` skips the
|
|
6
|
+
* string entirely and is typically several times faster.
|
|
7
|
+
*
|
|
8
|
+
* Fallback semantics: values `structuredClone` rejects (functions, DOM
|
|
9
|
+
* nodes, symbols) fall back to the JSON round trip, which reproduces the
|
|
10
|
+
* previous behavior exactly (drops them). Deltas on the fast path exist
|
|
11
|
+
* only for host-supplied exotic values — Dates stay `Date` instances (were
|
|
12
|
+
* ISO strings), NaN/±Infinity survive (were null), `toJSON` is ignored —
|
|
13
|
+
* and cannot occur for JSON-parsed or mapbox-gl-draw-originated features.
|
|
14
|
+
*/
|
|
15
|
+
export declare function deepClone<T>(value: T): T;
|
|
16
|
+
/**
|
|
17
|
+
* Clone a feature array in one native call; if any feature is not
|
|
18
|
+
* structured-cloneable, degrade per feature so one exotic feature doesn't
|
|
19
|
+
* force the whole array onto the slow path.
|
|
20
|
+
*/
|
|
21
|
+
export declare function cloneFeatures(features: readonly GeoJSON.Feature[]): GeoJSON.Feature[];
|
|
22
|
+
//# sourceMappingURL=deep-clone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-clone.d.ts","sourceRoot":"","sources":["../../../client/src/lib/deep-clone.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAMxC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,SAAS,OAAO,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAMrF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allocation-free deep equality for GeoJSON geometries, matching the
|
|
3
|
+
* `JSON.stringify(a) === JSON.stringify(b)` compare it replaces (which
|
|
4
|
+
* serialized both geometries on every draw move event just to detect
|
|
5
|
+
* no-op updates).
|
|
6
|
+
*
|
|
7
|
+
* Parity quirk kept deliberately: JSON.stringify maps every non-finite
|
|
8
|
+
* number (NaN, ±Infinity) to `null`, so any two non-finite leaves compare
|
|
9
|
+
* equal here too. The caller's only job is suppressing false "changed"
|
|
10
|
+
* positives, and false-equal on non-finite garbage is the safe direction.
|
|
11
|
+
* Foreign members beyond type/coordinates/geometries/bbox are ignored
|
|
12
|
+
* (draw strips them before emitting events).
|
|
13
|
+
*/
|
|
14
|
+
export declare function geometryEquals(a: GeoJSON.Geometry | null | undefined, b: GeoJSON.Geometry | null | undefined): boolean;
|
|
15
|
+
//# sourceMappingURL=geometry-equals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry-equals.d.ts","sourceRoot":"","sources":["../../../client/src/lib/geometry-equals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA4BH,wBAAgB,cAAc,CAC5B,CAAC,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI,GAAG,SAAS,EACtC,CAAC,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI,GAAG,SAAS,GACrC,OAAO,CAgBT"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-animation-frame coalescer for expensive side-effectful work.
|
|
3
|
+
*
|
|
4
|
+
* A single user action can request the same rebuild many times in one tick
|
|
5
|
+
* (mutation handler + draw events + reactive effects). Each `schedule` call
|
|
6
|
+
* accumulates a reason and arms at most one animation frame; the callback
|
|
7
|
+
* then runs once with every reason gathered since the last run, so N
|
|
8
|
+
* triggers collapse into one pass per frame.
|
|
9
|
+
*
|
|
10
|
+
* Re-entrancy: a `schedule` issued while the callback is running arms a NEW
|
|
11
|
+
* frame instead of being dropped — a request made mid-run is never lost.
|
|
12
|
+
*/
|
|
13
|
+
/** Injectable frame source so node-env tests can drive frames by hand. */
|
|
14
|
+
export interface FrameScheduler {
|
|
15
|
+
request(cb: () => void): number;
|
|
16
|
+
cancel(handle: number): void;
|
|
17
|
+
}
|
|
18
|
+
export interface RafCoalescer<Reason extends string = string> {
|
|
19
|
+
/** Accumulate a reason; arm one animation frame if none is armed. */
|
|
20
|
+
schedule(reason: Reason): void;
|
|
21
|
+
/** True while a frame is armed. */
|
|
22
|
+
isPending(): boolean;
|
|
23
|
+
/** Run now if pending (cancels the armed frame). No-op when idle or re-entrant. */
|
|
24
|
+
flush(): void;
|
|
25
|
+
/** Disarm and drop accumulated reasons (unmount). Idempotent. */
|
|
26
|
+
cancel(): void;
|
|
27
|
+
}
|
|
28
|
+
export declare function createRafCoalescer<Reason extends string = string>(run: (reasons: ReadonlySet<Reason>) => void, scheduler?: FrameScheduler): RafCoalescer<Reason>;
|
|
29
|
+
//# sourceMappingURL=raf-coalescer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raf-coalescer.d.ts","sourceRoot":"","sources":["../../../client/src/lib/raf-coalescer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,0EAA0E;AAC1E,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,MAAM,CAAC;IAChC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,MAAM,WAAW,YAAY,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM;IAC1D,qEAAqE;IACrE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,mCAAmC;IACnC,SAAS,IAAI,OAAO,CAAC;IACrB,mFAAmF;IACnF,KAAK,IAAI,IAAI,CAAC;IACd,iEAAiE;IACjE,MAAM,IAAI,IAAI,CAAC;CAChB;AAOD,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,EAC/D,GAAG,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,KAAK,IAAI,EAC3C,SAAS,GAAE,cAA6B,GACvC,YAAY,CAAC,MAAM,CAAC,CA0CtB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { GeoJSONSourceDiff } from 'maplibre-gl';
|
|
2
|
+
/**
|
|
3
|
+
* Minimal GeoJSON source diff for selection-only changes.
|
|
4
|
+
*
|
|
5
|
+
* Selection touches exactly two painted properties per feature —
|
|
6
|
+
* `isSelected` (paint/filter input) and `_labelPriority` (label collision
|
|
7
|
+
* sort key) — so flipping a handful of features does not need the full
|
|
8
|
+
* O(total-features) rebuild + setData re-upload. The full sync records what
|
|
9
|
+
* the painted collection contains (`SelectionPaintCache`); this builder
|
|
10
|
+
* turns "painted selection → next selection" into a `updateData` diff.
|
|
11
|
+
*/
|
|
12
|
+
export interface SelectionPaintCache {
|
|
13
|
+
/** Feature ids present in the custom-features source as of the last full sync. */
|
|
14
|
+
presentIds: Set<string>;
|
|
15
|
+
/** Ids currently painted `isSelected: 1` (updated by the fast path after each diff). */
|
|
16
|
+
appliedSelectedIds: Set<string>;
|
|
17
|
+
/** Per-feature `_labelPriority` computed as if unselected. */
|
|
18
|
+
basePriorityById: Map<string, number>;
|
|
19
|
+
/**
|
|
20
|
+
* False when the painted collection had duplicate ids: maplibre's
|
|
21
|
+
* `updateData` requires unique ids on every feature and fails
|
|
22
|
+
* ASYNCHRONOUSLY (an ErrorEvent, not a throw) otherwise — so the fast
|
|
23
|
+
* path must be disabled up front rather than caught.
|
|
24
|
+
*/
|
|
25
|
+
updatable: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** Matches the paint-side `['coalesce', ['get', '_labelPriority'], 100]` default. */
|
|
28
|
+
export declare const DEFAULT_LABEL_PRIORITY = 100;
|
|
29
|
+
export declare function createSelectionPaintCache(): SelectionPaintCache;
|
|
30
|
+
/**
|
|
31
|
+
* Record one painted feature during a full sync. A duplicate id makes the
|
|
32
|
+
* cache non-updatable — see `SelectionPaintCache.updatable`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function recordPaintedFeature(cache: SelectionPaintCache, featureId: string, basePriority: number, isSelected: boolean): void;
|
|
35
|
+
/** Minimal surface of maplibre's GeoJSONSource the fast path needs. */
|
|
36
|
+
export interface UpdatableGeoJSONSource {
|
|
37
|
+
updateData(diff: GeoJSONSourceDiff): unknown;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Apply a selection-only change to the source as an updateData diff.
|
|
41
|
+
* Returns false when the caller must fall back to a full sync — no cache,
|
|
42
|
+
* non-updatable cache, missing source, or a synchronous updateData throw
|
|
43
|
+
* (the cache is then left untouched; the full sync rebuilds it). On
|
|
44
|
+
* success the cache's applied set is advanced to the painted state.
|
|
45
|
+
*/
|
|
46
|
+
export declare function applySelectionFastPath(cache: SelectionPaintCache | null, nextSelectedIds: ReadonlySet<string>, source: UpdatableGeoJSONSource | null | undefined): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Whether applySelectionState still needs its draw.changeMode call. The
|
|
49
|
+
* call is skipped only when it would be a pure no-op — nothing to select,
|
|
50
|
+
* nothing to clear, mode already right — because mapbox-gl-draw re-inits
|
|
51
|
+
* the mode even on same-mode transitions, re-rendering the whole draw
|
|
52
|
+
* store and (via its draw.render event) escalating a selection-only frame
|
|
53
|
+
* to a full rebuild.
|
|
54
|
+
*/
|
|
55
|
+
export declare function needsDrawSelectionUpdate(input: {
|
|
56
|
+
editableSelectionCount: number;
|
|
57
|
+
drawSelectedCount: number;
|
|
58
|
+
currentMode: string;
|
|
59
|
+
targetMode: string;
|
|
60
|
+
}): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Diff between the painted selection and `nextSelectedIds`, restricted to
|
|
63
|
+
* ids present in the source. Returns null when no painted feature toggles.
|
|
64
|
+
* Only ever populates `update` — the fast path must never add or remove
|
|
65
|
+
* features.
|
|
66
|
+
*/
|
|
67
|
+
export declare function buildSelectionDiff(cache: Pick<SelectionPaintCache, 'presentIds' | 'appliedSelectedIds' | 'basePriorityById'>, nextSelectedIds: ReadonlySet<string>): GeoJSONSourceDiff | null;
|
|
68
|
+
//# sourceMappingURL=selection-diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection-diff.d.ts","sourceRoot":"","sources":["../../../client/src/lib/selection-diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;;;;;;;GASG;AAEH,MAAM,WAAW,mBAAmB;IAClC,kFAAkF;IAClF,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,wFAAwF;IACxF,kBAAkB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAChC,8DAA8D;IAC9D,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC;;;;;OAKG;IACH,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,qFAAqF;AACrF,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C,wBAAgB,yBAAyB,IAAI,mBAAmB,CAO/D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,mBAAmB,EAC1B,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,OAAO,GAClB,IAAI,CAQN;AAED,uEAAuE;AACvE,MAAM,WAAW,sBAAsB;IACrC,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC;CAC9C;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,mBAAmB,GAAG,IAAI,EACjC,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,EACpC,MAAM,EAAE,sBAAsB,GAAG,IAAI,GAAG,SAAS,GAChD,OAAO,CAgBT;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAC9C,sBAAsB,EAAE,MAAM,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAMV;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,YAAY,GAAG,oBAAoB,GAAG,kBAAkB,CAAC,EAC1F,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,GACnC,iBAAiB,GAAG,IAAI,CAyB1B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hit-testing for the selection gestures (rectangle / circle / lasso /
|
|
3
|
+
* shift-drag), extracted from the four copy-pasted completion loops in
|
|
4
|
+
* map-editor-canvas.
|
|
5
|
+
*
|
|
6
|
+
* A cheap bounding-box prefilter runs before the exact turf predicates,
|
|
7
|
+
* which matters because the loops previously ran `booleanIntersects` /
|
|
8
|
+
* `booleanPointInPolygon` against EVERY feature on the map per gesture.
|
|
9
|
+
* The bbox is derived from the same raw ring coordinates turf sees — no
|
|
10
|
+
* antimeridian ±360 normalization (deliberately unlike
|
|
11
|
+
* `visible-feature-count.ts`, which wants geographic truth for counting):
|
|
12
|
+
* the prefilter must be exactly conservative w.r.t. the turf predicates,
|
|
13
|
+
* or the refactor would change selection results.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Feature groups for hit-testing: draw features first, then visible
|
|
17
|
+
* read-only layers in store order — reproducing the concat order of the
|
|
18
|
+
* inline loops this module replaced, without materializing a combined copy
|
|
19
|
+
* of every feature. Layers absent from `layers` are treated as hidden.
|
|
20
|
+
*/
|
|
21
|
+
export declare function collectVisibleFeatureGroups(drawFeatures: GeoJSON.Feature[] | null, readOnlyByLayer: ReadonlyMap<string, GeoJSON.Feature[]>, layers: readonly {
|
|
22
|
+
id: string;
|
|
23
|
+
visible: boolean;
|
|
24
|
+
}[]): GeoJSON.Feature[][];
|
|
25
|
+
export interface SelectionHitTestOptions {
|
|
26
|
+
/**
|
|
27
|
+
* The selection polygon is an axis-aligned lng/lat rectangle. For Point
|
|
28
|
+
* features the inclusive bbox containment test is then exact (turf's
|
|
29
|
+
* `booleanPointInPolygon` counts boundary points as inside too), so turf
|
|
30
|
+
* is skipped entirely.
|
|
31
|
+
*/
|
|
32
|
+
axisAlignedRectangle?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Ids of the features whose geometry hits the selection polygon, in
|
|
36
|
+
* encounter order (groups in order, features in order — matching the
|
|
37
|
+
* previous draw-then-read-only concat order). Ids are stringified with the
|
|
38
|
+
* previous truthiness check, so `id: 0` / `id: ''` / missing ids are
|
|
39
|
+
* skipped. GeometryCollection features are never selected (parity with the
|
|
40
|
+
* untyped fall-through this replaces), and a per-feature error skips just
|
|
41
|
+
* that feature.
|
|
42
|
+
*/
|
|
43
|
+
export declare function hitTestSelection(featureGroups: readonly (readonly GeoJSON.Feature[])[], selectionPolygon: GeoJSON.Feature<GeoJSON.Polygon>, options?: SelectionHitTestOptions): string[];
|
|
44
|
+
//# sourceMappingURL=selection-hit-test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection-hit-test.d.ts","sourceRoot":"","sources":["../../../client/src/lib/selection-hit-test.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AAEH;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,YAAY,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,IAAI,EACtC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,EACvD,MAAM,EAAE,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,GAClD,OAAO,CAAC,OAAO,EAAE,EAAE,CAQrB;AAED,MAAM,WAAW,uBAAuB;IACtC;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAyCD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,SAAS,CAAC,SAAS,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE,EACtD,gBAAgB,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAClD,OAAO,CAAC,EAAE,uBAAuB,GAChC,MAAM,EAAE,CAuCV"}
|