@accelint/map-toolkit 0.6.0 → 1.0.0
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/CHANGELOG.md +68 -0
- package/catalog-info.yaml +5 -4
- package/dist/camera/index.d.ts +2 -2
- package/dist/camera/index.js +2 -2
- package/dist/camera/store.d.ts +120 -0
- package/dist/camera/store.js +279 -0
- package/dist/camera/store.js.map +1 -0
- package/dist/deckgl/base-map/constants.d.ts +1 -6
- package/dist/deckgl/base-map/constants.js +1 -6
- package/dist/deckgl/base-map/constants.js.map +1 -1
- package/dist/deckgl/base-map/controls.js +2 -0
- package/dist/deckgl/base-map/controls.js.map +1 -1
- package/dist/deckgl/base-map/index.d.ts +2 -2
- package/dist/deckgl/base-map/index.js +10 -11
- package/dist/deckgl/base-map/index.js.map +1 -1
- package/dist/deckgl/base-map/provider.js +1 -1
- package/dist/deckgl/index.d.ts +4 -4
- package/dist/deckgl/index.js +4 -4
- package/dist/deckgl/saved-viewports/storage.js +10 -2
- package/dist/deckgl/saved-viewports/storage.js.map +1 -1
- package/dist/deckgl/shapes/display-shape-layer/constants.js +5 -8
- package/dist/deckgl/shapes/display-shape-layer/constants.js.map +1 -1
- package/dist/deckgl/shapes/display-shape-layer/index.d.ts +18 -14
- package/dist/deckgl/shapes/display-shape-layer/index.js +63 -30
- package/dist/deckgl/shapes/display-shape-layer/index.js.map +1 -1
- package/dist/deckgl/shapes/display-shape-layer/shape-label-layer.js +2 -16
- package/dist/deckgl/shapes/display-shape-layer/shape-label-layer.js.map +1 -1
- package/dist/deckgl/shapes/display-shape-layer/store.js +58 -272
- package/dist/deckgl/shapes/display-shape-layer/store.js.map +1 -1
- package/dist/deckgl/shapes/display-shape-layer/types.d.ts +22 -11
- package/dist/deckgl/shapes/display-shape-layer/{use-shape-selection.d.ts → use-select-shape.d.ts} +9 -9
- package/dist/deckgl/shapes/display-shape-layer/{use-shape-selection.js → use-select-shape.js} +12 -12
- package/dist/deckgl/shapes/display-shape-layer/use-select-shape.js.map +1 -0
- package/dist/deckgl/shapes/display-shape-layer/utils/display-style.js +5 -66
- package/dist/deckgl/shapes/display-shape-layer/utils/display-style.js.map +1 -1
- package/dist/deckgl/shapes/display-shape-layer/utils/labels.d.ts +2 -65
- package/dist/deckgl/shapes/display-shape-layer/utils/labels.js +3 -121
- package/dist/deckgl/shapes/display-shape-layer/utils/labels.js.map +1 -1
- package/dist/deckgl/shapes/draw-shape-layer/constants.js +46 -0
- package/dist/deckgl/shapes/draw-shape-layer/constants.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/events.d.ts +92 -0
- package/dist/deckgl/shapes/draw-shape-layer/events.js +56 -0
- package/dist/deckgl/shapes/draw-shape-layer/events.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/fiber.d.ts +11 -0
- package/dist/{maplibre/constants.js → deckgl/shapes/draw-shape-layer/fiber.js} +6 -12
- package/dist/deckgl/shapes/draw-shape-layer/fiber.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/index.d.ts +53 -0
- package/dist/deckgl/shapes/draw-shape-layer/index.js +95 -0
- package/dist/deckgl/shapes/draw-shape-layer/index.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-circle-mode-with-tooltip.js +51 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-circle-mode-with-tooltip.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-ellipse-mode-with-tooltip.js +73 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-ellipse-mode-with-tooltip.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-line-string-mode-with-tooltip.js +87 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-line-string-mode-with-tooltip.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-polygon-mode-with-tooltip.js +88 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-polygon-mode-with-tooltip.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-rectangle-mode-with-tooltip.js +77 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-rectangle-mode-with-tooltip.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/index.js +64 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/index.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/store.js +175 -0
- package/dist/deckgl/shapes/draw-shape-layer/store.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/types.d.ts +86 -0
- package/dist/{viewport/constants.js → deckgl/shapes/draw-shape-layer/types.js} +1 -12
- package/dist/deckgl/shapes/draw-shape-layer/use-draw-shape.d.ts +82 -0
- package/dist/deckgl/shapes/draw-shape-layer/use-draw-shape.js +112 -0
- package/dist/deckgl/shapes/draw-shape-layer/use-draw-shape.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/utils/feature-conversion.js +147 -0
- package/dist/deckgl/shapes/draw-shape-layer/utils/feature-conversion.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/constants.js +41 -0
- package/dist/deckgl/shapes/edit-shape-layer/constants.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/events.d.ts +92 -0
- package/dist/deckgl/shapes/edit-shape-layer/events.js +56 -0
- package/dist/deckgl/shapes/edit-shape-layer/events.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/fiber.d.ts +13 -0
- package/dist/deckgl/shapes/edit-shape-layer/fiber.js +14 -0
- package/dist/deckgl/shapes/edit-shape-layer/index.d.ts +63 -0
- package/dist/deckgl/shapes/edit-shape-layer/index.js +162 -0
- package/dist/deckgl/shapes/edit-shape-layer/index.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/base-transform-mode.js +154 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/base-transform-mode.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/bounding-transform-mode.js +147 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/bounding-transform-mode.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/circle-transform-mode.js +87 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/circle-transform-mode.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/index.js +61 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/index.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/rotate-mode-with-snap.js +109 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/rotate-mode-with-snap.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/scale-mode-with-free-transform.js +289 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/scale-mode-with-free-transform.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/vertex-transform-mode.js +121 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/vertex-transform-mode.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/store.js +194 -0
- package/dist/deckgl/shapes/edit-shape-layer/store.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/types.d.ts +93 -0
- package/dist/deckgl/shapes/edit-shape-layer/types.js +14 -0
- package/dist/deckgl/shapes/edit-shape-layer/use-edit-shape.d.ts +82 -0
- package/dist/deckgl/shapes/edit-shape-layer/use-edit-shape.js +114 -0
- package/dist/deckgl/shapes/edit-shape-layer/use-edit-shape.js.map +1 -0
- package/dist/deckgl/shapes/index.d.ts +15 -6
- package/dist/deckgl/shapes/index.js +12 -5
- package/dist/deckgl/shapes/shared/constants.d.ts +27 -32
- package/dist/deckgl/shapes/shared/constants.js +189 -25
- package/dist/deckgl/shapes/shared/constants.js.map +1 -1
- package/dist/deckgl/shapes/shared/events.d.ts +1 -20
- package/dist/deckgl/shapes/shared/events.js +1 -31
- package/dist/deckgl/shapes/shared/events.js.map +1 -1
- package/dist/deckgl/shapes/shared/hooks/use-shift-zoom-disable.js +84 -0
- package/dist/deckgl/shapes/shared/hooks/use-shift-zoom-disable.js.map +1 -0
- package/dist/deckgl/shapes/shared/types.d.ts +187 -28
- package/dist/deckgl/shapes/shared/types.js +55 -1
- package/dist/deckgl/shapes/shared/types.js.map +1 -1
- package/dist/deckgl/shapes/shared/utils/geometry-measurements.js +128 -0
- package/dist/deckgl/shapes/shared/utils/geometry-measurements.js.map +1 -0
- package/dist/deckgl/shapes/shared/utils/layer-config.js +50 -0
- package/dist/deckgl/shapes/shared/utils/layer-config.js.map +1 -0
- package/dist/deckgl/shapes/shared/utils/mode-utils.js +113 -0
- package/dist/deckgl/shapes/shared/utils/mode-utils.js.map +1 -0
- package/dist/deckgl/shapes/shared/utils/pick-filtering.js +57 -0
- package/dist/deckgl/shapes/shared/utils/pick-filtering.js.map +1 -0
- package/dist/deckgl/shapes/shared/utils/style-utils.d.ts +64 -0
- package/dist/deckgl/shapes/shared/utils/style-utils.js +101 -0
- package/dist/deckgl/shapes/shared/utils/style-utils.js.map +1 -0
- package/dist/deckgl/text-layer/default-settings.js +4 -24
- package/dist/deckgl/text-layer/default-settings.js.map +1 -1
- package/dist/deckgl/text-settings.d.ts +77 -0
- package/dist/deckgl/text-settings.js +83 -0
- package/dist/deckgl/text-settings.js.map +1 -0
- package/dist/map-cursor/index.d.ts +2 -2
- package/dist/map-cursor/index.js +2 -2
- package/dist/map-cursor/store.d.ts +32 -61
- package/dist/map-cursor/store.js +165 -294
- package/dist/map-cursor/store.js.map +1 -1
- package/dist/map-cursor/use-map-cursor.d.ts +5 -2
- package/dist/map-cursor/use-map-cursor.js +33 -15
- package/dist/map-cursor/use-map-cursor.js.map +1 -1
- package/dist/map-mode/index.d.ts +2 -2
- package/dist/map-mode/index.js +2 -2
- package/dist/map-mode/store.d.ts +36 -37
- package/dist/map-mode/store.js +131 -237
- package/dist/map-mode/store.js.map +1 -1
- package/dist/map-mode/use-map-mode.js +6 -5
- package/dist/map-mode/use-map-mode.js.map +1 -1
- package/dist/maplibre/index.d.ts +2 -2
- package/dist/maplibre/index.js +2 -2
- package/dist/shared/constants.d.ts +19 -0
- package/dist/shared/constants.js +33 -0
- package/dist/shared/constants.js.map +1 -0
- package/dist/shared/create-map-store.d.ts +202 -0
- package/dist/shared/create-map-store.js +223 -0
- package/dist/shared/create-map-store.js.map +1 -0
- package/dist/shared/units.d.ts +39 -0
- package/dist/shared/units.js +49 -0
- package/dist/shared/units.js.map +1 -0
- package/dist/viewport/index.d.ts +3 -3
- package/dist/viewport/index.js +3 -3
- package/dist/viewport/store.d.ts +69 -0
- package/dist/viewport/store.js +125 -0
- package/dist/viewport/store.js.map +1 -0
- package/dist/viewport/types.d.ts +2 -2
- package/dist/viewport/utils.js +2 -2
- package/dist/viewport/utils.js.map +1 -1
- package/dist/viewport/viewport-size.d.ts +2 -2
- package/dist/viewport/viewport-size.js +2 -2
- package/dist/viewport/viewport-size.js.map +1 -1
- package/package.json +36 -18
- package/dist/camera/use-camera-state.d.ts +0 -153
- package/dist/camera/use-camera-state.js +0 -418
- package/dist/camera/use-camera-state.js.map +0 -1
- package/dist/deckgl/shapes/display-shape-layer/constants.d.ts +0 -44
- package/dist/deckgl/shapes/display-shape-layer/shape-label-layer.d.ts +0 -66
- package/dist/deckgl/shapes/display-shape-layer/store.d.ts +0 -87
- package/dist/deckgl/shapes/display-shape-layer/use-shape-selection.js.map +0 -1
- package/dist/deckgl/shapes/display-shape-layer/utils/display-style.d.ts +0 -61
- package/dist/maplibre/constants.d.ts +0 -13
- package/dist/maplibre/constants.js.map +0 -1
- package/dist/viewport/constants.d.ts +0 -11
- package/dist/viewport/constants.js.map +0 -1
- package/dist/viewport/use-viewport-state.d.ts +0 -100
- package/dist/viewport/use-viewport-state.js +0 -222
- package/dist/viewport/use-viewport-state.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-shape-selection.js","names":[],"sources":["../../../../src/deckgl/shapes/display-shape-layer/use-shape-selection.ts"],"sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n'use client';\n\nimport { useSyncExternalStore } from 'react';\nimport {\n getOrCreateClearSelection,\n getOrCreateServerSnapshot,\n getOrCreateSetSelectedId,\n getOrCreateSnapshot,\n getOrCreateSubscription,\n} from './store';\nimport type { UniqueId } from '@accelint/core';\nimport type { ShapeId } from '../shared/types';\n\n/**\n * Return type for useShapeSelection hook\n */\nexport interface UseShapeSelectionReturn {\n /** Currently selected shape ID, or undefined if nothing selected */\n selectedId: ShapeId | undefined;\n /** Manually set the selected shape ID (useful for programmatic selection) */\n setSelectedId: (id: ShapeId | undefined) => void;\n /** Manually clear the selection */\n clearSelection: () => void;\n}\n\n/**\n * Hook to manage shape selection state with automatic deselection\n *\n * This hook encapsulates the common pattern of:\n * 1. Listening to `shapes:selected` events and updating state\n * 2. Listening to `shapes:deselected` events and clearing state\n * 3. Listening to map clicks on empty space and emitting `shapes:deselected`\n *\n * Uses a store pattern with `useSyncExternalStore` for proper listener cleanup\n * during HMR (Hot Module Replacement) in development. The store ensures only\n * one bus listener exists per map instance, regardless of how many React\n * components subscribe.\n *\n * @param mapId - The map instance ID for event filtering\n * @returns Selection state and control functions\n *\n * @example Basic usage\n * ```tsx\n * import { useShapeSelection } from '@accelint/map-toolkit/deckgl/shapes';\n *\n * function MapWithShapes() {\n * const { selectedId } = useShapeSelection(MAP_ID);\n *\n * return (\n * <BaseMap id={MAP_ID}>\n * <displayShapeLayer\n * id=\"shapes\"\n * mapId={MAP_ID}\n * data={shapes}\n * selectedShapeId={selectedId}\n * />\n * </BaseMap>\n * );\n * }\n * ```\n *\n * @example With programmatic selection control\n * ```tsx\n * function MapWithShapes() {\n * const { selectedId, setSelectedId, clearSelection } = useShapeSelection(MAP_ID);\n *\n * return (\n * <>\n * <button onClick={() => setSelectedId(shapes[0].id)}>Select First Shape</button>\n * <button onClick={clearSelection}>Clear Selection</button>\n * <BaseMap id={MAP_ID}>\n * <displayShapeLayer\n * id=\"shapes\"\n * mapId={MAP_ID}\n * data={shapes}\n * selectedShapeId={selectedId}\n * />\n * </BaseMap>\n * </>\n * );\n * }\n * ```\n */\nexport function useShapeSelection(mapId: UniqueId): UseShapeSelectionReturn {\n // Get cached functions for this mapId (maintains referential stability)\n const subscribe = getOrCreateSubscription(mapId);\n const getSnapshot = getOrCreateSnapshot(mapId);\n const getServerSnapshot = getOrCreateServerSnapshot(mapId);\n\n // Subscribe to store changes using React's built-in external store hook\n const selectedId = useSyncExternalStore(\n subscribe,\n getSnapshot,\n getServerSnapshot,\n );\n\n // Get cached action functions (maintains referential stability)\n const setSelectedId = getOrCreateSetSelectedId(mapId);\n const clearSelection = getOrCreateClearSelection(mapId);\n\n return {\n selectedId,\n setSelectedId,\n clearSelection,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,kBAAkB,OAA0C;AAiB1E,QAAO;EACL,YAXiB,qBALD,wBAAwB,MAAM,EAC5B,oBAAoB,MAAM,EACpB,0BAA0B,MAAM,CAOzD;EAQC,eALoB,yBAAyB,MAAM;EAMnD,gBALqB,0BAA0B,MAAM;EAMtD"}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at https://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { StyledFeature } from "../../shared/types.js";
|
|
14
|
-
import { Color } from "@deck.gl/core";
|
|
15
|
-
|
|
16
|
-
//#region src/deckgl/shapes/display-shape-layer/utils/display-style.d.ts
|
|
17
|
-
/**
|
|
18
|
-
* Get fill color for a feature
|
|
19
|
-
* Colors are passed through as-is unless applyBaseOpacity is true
|
|
20
|
-
*
|
|
21
|
-
* @param feature - The styled feature
|
|
22
|
-
* @param applyBaseOpacity - When true, multiplies alpha by BASE_FILL_OPACITY (0.6)
|
|
23
|
-
* @returns RGBA color array
|
|
24
|
-
*/
|
|
25
|
-
declare function getFillColor(feature: StyledFeature, applyBaseOpacity?: boolean): Color;
|
|
26
|
-
/**
|
|
27
|
-
* Get stroke color for a feature
|
|
28
|
-
* Strokes are always rendered at their literal alpha value
|
|
29
|
-
*
|
|
30
|
-
* @param feature - The styled feature
|
|
31
|
-
* @returns RGBA color array
|
|
32
|
-
*/
|
|
33
|
-
declare function getStrokeColor(feature: StyledFeature): Color;
|
|
34
|
-
/**
|
|
35
|
-
* Get line width for a feature
|
|
36
|
-
*/
|
|
37
|
-
declare function getLineWidth(feature: StyledFeature): number;
|
|
38
|
-
/**
|
|
39
|
-
* Alias for getLineWidth (for compatibility)
|
|
40
|
-
*/
|
|
41
|
-
declare const getStrokeWidth: typeof getLineWidth;
|
|
42
|
-
/**
|
|
43
|
-
* Get dash array for stroke pattern
|
|
44
|
-
*/
|
|
45
|
-
declare function getDashArray(feature: StyledFeature): [number, number] | null;
|
|
46
|
-
/**
|
|
47
|
-
* Get hover-enhanced line width
|
|
48
|
-
*/
|
|
49
|
-
declare function getHoverLineWidth(feature: StyledFeature, isHovered: boolean): number;
|
|
50
|
-
/**
|
|
51
|
-
* Get selection highlight color
|
|
52
|
-
* Returns the default highlight color or allows custom opacity override
|
|
53
|
-
*/
|
|
54
|
-
declare function getHighlightColor(opacity?: number): [number, number, number, number];
|
|
55
|
-
/**
|
|
56
|
-
* Get highlight line width (base width + increase)
|
|
57
|
-
*/
|
|
58
|
-
declare function getHighlightLineWidth(feature: StyledFeature): number;
|
|
59
|
-
//#endregion
|
|
60
|
-
export { getDashArray, getFillColor, getHighlightColor, getHighlightLineWidth, getHoverLineWidth, getLineWidth, getStrokeColor, getStrokeWidth };
|
|
61
|
-
//# sourceMappingURL=display-style.d.ts.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region src/maplibre/constants.d.ts
|
|
2
|
-
declare const INITIAL_VIEW_STATE: {
|
|
3
|
-
longitude: number;
|
|
4
|
-
latitude: number;
|
|
5
|
-
zoom: number;
|
|
6
|
-
minZoom: number;
|
|
7
|
-
maxZoom: number;
|
|
8
|
-
pitch: number;
|
|
9
|
-
bearing: number;
|
|
10
|
-
};
|
|
11
|
-
//#endregion
|
|
12
|
-
export { INITIAL_VIEW_STATE };
|
|
13
|
-
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":[],"sources":["../../src/maplibre/constants.ts"],"sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// __private-exports\n\nexport const INITIAL_VIEW_STATE = {\n longitude: -77.0369,\n latitude: 38.9072,\n zoom: 4,\n minZoom: 1,\n maxZoom: 22,\n pitch: 0,\n bearing: 0,\n};\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,qBAAqB;CAChC,WAAW;CACX,UAAU;CACV,MAAM;CACN,SAAS;CACT,SAAS;CACT,OAAO;CACP,SAAS;CACV"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
//#region src/viewport/constants.d.ts
|
|
2
|
-
declare const UNIT_MAP: {
|
|
3
|
-
readonly km: "kilometers";
|
|
4
|
-
readonly m: "meters";
|
|
5
|
-
readonly nm: "nauticalmiles";
|
|
6
|
-
readonly mi: "miles";
|
|
7
|
-
readonly ft: "feet";
|
|
8
|
-
};
|
|
9
|
-
//#endregion
|
|
10
|
-
export { UNIT_MAP };
|
|
11
|
-
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":[],"sources":["../../src/viewport/constants.ts"],"sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport const UNIT_MAP = {\n km: 'kilometers',\n m: 'meters',\n nm: 'nauticalmiles',\n mi: 'miles',\n ft: 'feet',\n} as const;\n"],"mappings":";;;;;;;;;;;;;;AAYA,MAAa,WAAW;CACtB,IAAI;CACJ,GAAG;CACH,IAAI;CACJ,IAAI;CACJ,IAAI;CACL"}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at https://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { MapViewportPayload } from "../deckgl/base-map/types.js";
|
|
14
|
-
import { useSyncExternalStore } from "react";
|
|
15
|
-
import { UniqueId } from "@accelint/core";
|
|
16
|
-
|
|
17
|
-
//#region src/viewport/use-viewport-state.d.ts
|
|
18
|
-
type UseViewportStateProps = {
|
|
19
|
-
instanceId: UniqueId;
|
|
20
|
-
subscribe?: Parameters<typeof useSyncExternalStore<MapViewportPayload>>[0];
|
|
21
|
-
getSnapshot?: Parameters<typeof useSyncExternalStore<MapViewportPayload>>[1];
|
|
22
|
-
getServerSnapshot?: Parameters<typeof useSyncExternalStore<MapViewportPayload>>[2];
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Hook to subscribe to viewport state changes for a specific view.
|
|
26
|
-
*
|
|
27
|
-
* By default, subscribes to MapEvents.viewport events from the event bus and
|
|
28
|
-
* automatically cleans up when all subscribers unmount. For advanced use cases,
|
|
29
|
-
* custom subscribe/getSnapshot functions can be provided.
|
|
30
|
-
*
|
|
31
|
-
* A thin wrapper around [useSyncExternalStore](https://react.dev/reference/react/useSyncExternalStore).
|
|
32
|
-
*
|
|
33
|
-
* @param instanceId - Unique identifier for the viewport to track
|
|
34
|
-
* @param subscribe - Optional custom subscription function
|
|
35
|
-
* @param getSnapshot - Optional custom snapshot getter
|
|
36
|
-
* @param getServerSnapshot - Optional server-side snapshot getter
|
|
37
|
-
* @returns Current viewport state including bounds, latitude, longitude, zoom
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```tsx
|
|
41
|
-
* function MapInfo({ instanceId }) {
|
|
42
|
-
* const { bounds, latitude, longitude, zoom } = useViewportState({
|
|
43
|
-
* instanceId
|
|
44
|
-
* });
|
|
45
|
-
*
|
|
46
|
-
* return (
|
|
47
|
-
* <div>
|
|
48
|
-
* Lat: {latitude?.toFixed(2)}, Lon: {longitude?.toFixed(2)}, Zoom: {zoom}
|
|
49
|
-
* </div>
|
|
50
|
-
* );
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```tsx
|
|
56
|
-
* // With custom subscribe/getSnapshot for advanced use cases
|
|
57
|
-
* function CustomMapInfo() {
|
|
58
|
-
* const customSubscribe = (onStoreChange) => {
|
|
59
|
-
* // Custom subscription logic
|
|
60
|
-
* return () => { // cleanup }
|
|
61
|
-
* }
|
|
62
|
-
*
|
|
63
|
-
* const customGetSnapshot = () => {
|
|
64
|
-
* // Custom snapshot logic
|
|
65
|
-
* return { latitude: 0, longitude: 0, zoom: 1 };
|
|
66
|
-
* };
|
|
67
|
-
*
|
|
68
|
-
* const viewState = useViewportState({
|
|
69
|
-
* instanceId: 'some-uuid',
|
|
70
|
-
* subscribe: customSubscribe,
|
|
71
|
-
* getSnapshot: customGetSnapshot,
|
|
72
|
-
* });
|
|
73
|
-
*
|
|
74
|
-
* return <div>Custom viewport state</div>;
|
|
75
|
-
* }
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
declare function useViewportState({
|
|
79
|
-
instanceId,
|
|
80
|
-
subscribe,
|
|
81
|
-
getSnapshot,
|
|
82
|
-
getServerSnapshot
|
|
83
|
-
}: UseViewportStateProps): MapViewportPayload;
|
|
84
|
-
/**
|
|
85
|
-
* Manually clear viewport state for a specific instanceId.
|
|
86
|
-
* This is typically not needed as cleanup happens automatically when all subscribers unmount.
|
|
87
|
-
* Use this only in advanced scenarios where manual cleanup is required.
|
|
88
|
-
*
|
|
89
|
-
* @param instanceId - The unique identifier for the viewport to clear
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```tsx
|
|
93
|
-
* // Manual cleanup (rarely needed)
|
|
94
|
-
* clearViewportState('my-map-instance');
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
declare function clearViewportState(instanceId: UniqueId): void;
|
|
98
|
-
//#endregion
|
|
99
|
-
export { UseViewportStateProps, clearViewportState, useViewportState };
|
|
100
|
-
//# sourceMappingURL=use-viewport-state.d.ts.map
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at https://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import { MapEvents } from "../deckgl/base-map/events.js";
|
|
15
|
-
import { Broadcast } from "@accelint/bus";
|
|
16
|
-
import { useSyncExternalStore } from "react";
|
|
17
|
-
|
|
18
|
-
//#region src/viewport/use-viewport-state.ts
|
|
19
|
-
const bus = Broadcast.getInstance();
|
|
20
|
-
/**
|
|
21
|
-
* Store for viewport state keyed by instanceId
|
|
22
|
-
*/
|
|
23
|
-
const viewportStore = /* @__PURE__ */ new Map();
|
|
24
|
-
/**
|
|
25
|
-
* Track React component subscribers per instanceId (for fan-out notifications).
|
|
26
|
-
* Each Set contains onStoreChange callbacks from useSyncExternalStore.
|
|
27
|
-
*/
|
|
28
|
-
const componentSubscribers = /* @__PURE__ */ new Map();
|
|
29
|
-
/**
|
|
30
|
-
* Cache of bus unsubscribe functions (1 per instanceId).
|
|
31
|
-
* This ensures we only have one bus listener per viewport, regardless of
|
|
32
|
-
* how many React components subscribe to it.
|
|
33
|
-
*/
|
|
34
|
-
const busUnsubscribers = /* @__PURE__ */ new Map();
|
|
35
|
-
/**
|
|
36
|
-
* Cache of subscription functions per instanceId to avoid recreating on every render
|
|
37
|
-
*/
|
|
38
|
-
const subscriptionCache = /* @__PURE__ */ new Map();
|
|
39
|
-
/**
|
|
40
|
-
* Cache of snapshot functions per instanceId to maintain referential stability
|
|
41
|
-
*/
|
|
42
|
-
const snapshotCache = /* @__PURE__ */ new Map();
|
|
43
|
-
/**
|
|
44
|
-
* Cache of fallback snapshots per instanceId to maintain referential stability.
|
|
45
|
-
* This prevents unnecessary re-renders when no viewport data exists yet.
|
|
46
|
-
*/
|
|
47
|
-
const fallbackCache = /* @__PURE__ */ new Map();
|
|
48
|
-
/**
|
|
49
|
-
* Ensures a single bus listener exists for the given instanceId.
|
|
50
|
-
* All React subscribers will be notified via fan-out when the bus event fires.
|
|
51
|
-
* This prevents creating N bus listeners for N React components.
|
|
52
|
-
*
|
|
53
|
-
* @param instanceId - The unique identifier for the viewport
|
|
54
|
-
*/
|
|
55
|
-
function ensureBusListener(instanceId) {
|
|
56
|
-
if (busUnsubscribers.has(instanceId)) return;
|
|
57
|
-
const unsub = bus.on(MapEvents.viewport, ({ payload }) => {
|
|
58
|
-
if (instanceId === payload.id) {
|
|
59
|
-
viewportStore.set(instanceId, payload);
|
|
60
|
-
const subscribers = componentSubscribers.get(instanceId);
|
|
61
|
-
if (subscribers) for (const onStoreChange of subscribers) onStoreChange();
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
busUnsubscribers.set(instanceId, unsub);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Cleans up the bus listener if no React subscribers remain.
|
|
68
|
-
*
|
|
69
|
-
* @param instanceId - The unique identifier for the viewport
|
|
70
|
-
*/
|
|
71
|
-
function cleanupBusListenerIfNeeded(instanceId) {
|
|
72
|
-
const subscribers = componentSubscribers.get(instanceId);
|
|
73
|
-
if (!subscribers || subscribers.size === 0) {
|
|
74
|
-
const unsub = busUnsubscribers.get(instanceId);
|
|
75
|
-
if (unsub) {
|
|
76
|
-
unsub();
|
|
77
|
-
busUnsubscribers.delete(instanceId);
|
|
78
|
-
}
|
|
79
|
-
viewportStore.delete(instanceId);
|
|
80
|
-
componentSubscribers.delete(instanceId);
|
|
81
|
-
subscriptionCache.delete(instanceId);
|
|
82
|
-
snapshotCache.delete(instanceId);
|
|
83
|
-
fallbackCache.delete(instanceId);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Creates or retrieves a cached subscription function for a given instanceId.
|
|
88
|
-
* Uses a fan-out pattern: 1 bus listener -> N React subscribers.
|
|
89
|
-
* Automatically cleans up viewport state when the last subscriber unsubscribes.
|
|
90
|
-
*
|
|
91
|
-
* @param instanceId - The unique identifier for the viewport
|
|
92
|
-
* @returns A subscription function for useSyncExternalStore
|
|
93
|
-
*/
|
|
94
|
-
function getOrCreateSubscription(instanceId) {
|
|
95
|
-
const subscription = subscriptionCache.get(instanceId) ?? ((onStoreChange) => {
|
|
96
|
-
ensureBusListener(instanceId);
|
|
97
|
-
let subscriberSet = componentSubscribers.get(instanceId);
|
|
98
|
-
if (!subscriberSet) {
|
|
99
|
-
subscriberSet = /* @__PURE__ */ new Set();
|
|
100
|
-
componentSubscribers.set(instanceId, subscriberSet);
|
|
101
|
-
}
|
|
102
|
-
subscriberSet.add(onStoreChange);
|
|
103
|
-
return () => {
|
|
104
|
-
const currentSubscriberSet = componentSubscribers.get(instanceId);
|
|
105
|
-
if (currentSubscriberSet) currentSubscriberSet.delete(onStoreChange);
|
|
106
|
-
cleanupBusListenerIfNeeded(instanceId);
|
|
107
|
-
};
|
|
108
|
-
});
|
|
109
|
-
subscriptionCache.set(instanceId, subscription);
|
|
110
|
-
return subscription;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Creates or retrieves a cached snapshot function for a given instanceId.
|
|
114
|
-
* The object returned gets equality checked, so it needs to be stable or React re-renders unnecessarily.
|
|
115
|
-
*
|
|
116
|
-
* @param instanceId - The unique identifier for the viewport
|
|
117
|
-
* @returns A snapshot function for useSyncExternalStore
|
|
118
|
-
*/
|
|
119
|
-
function getOrCreateSnapshot(instanceId) {
|
|
120
|
-
const fallback = fallbackCache.get(instanceId) ?? (() => {
|
|
121
|
-
const newFallback = {
|
|
122
|
-
id: instanceId,
|
|
123
|
-
bounds: void 0,
|
|
124
|
-
latitude: NaN,
|
|
125
|
-
longitude: NaN,
|
|
126
|
-
zoom: NaN,
|
|
127
|
-
width: 0,
|
|
128
|
-
height: 0
|
|
129
|
-
};
|
|
130
|
-
fallbackCache.set(instanceId, newFallback);
|
|
131
|
-
return newFallback;
|
|
132
|
-
})();
|
|
133
|
-
const snapshot = snapshotCache.get(instanceId) ?? (() => viewportStore.get(instanceId) ?? fallback);
|
|
134
|
-
snapshotCache.set(instanceId, snapshot);
|
|
135
|
-
return snapshot;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Hook to subscribe to viewport state changes for a specific view.
|
|
139
|
-
*
|
|
140
|
-
* By default, subscribes to MapEvents.viewport events from the event bus and
|
|
141
|
-
* automatically cleans up when all subscribers unmount. For advanced use cases,
|
|
142
|
-
* custom subscribe/getSnapshot functions can be provided.
|
|
143
|
-
*
|
|
144
|
-
* A thin wrapper around [useSyncExternalStore](https://react.dev/reference/react/useSyncExternalStore).
|
|
145
|
-
*
|
|
146
|
-
* @param instanceId - Unique identifier for the viewport to track
|
|
147
|
-
* @param subscribe - Optional custom subscription function
|
|
148
|
-
* @param getSnapshot - Optional custom snapshot getter
|
|
149
|
-
* @param getServerSnapshot - Optional server-side snapshot getter
|
|
150
|
-
* @returns Current viewport state including bounds, latitude, longitude, zoom
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```tsx
|
|
154
|
-
* function MapInfo({ instanceId }) {
|
|
155
|
-
* const { bounds, latitude, longitude, zoom } = useViewportState({
|
|
156
|
-
* instanceId
|
|
157
|
-
* });
|
|
158
|
-
*
|
|
159
|
-
* return (
|
|
160
|
-
* <div>
|
|
161
|
-
* Lat: {latitude?.toFixed(2)}, Lon: {longitude?.toFixed(2)}, Zoom: {zoom}
|
|
162
|
-
* </div>
|
|
163
|
-
* );
|
|
164
|
-
* }
|
|
165
|
-
* ```
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* ```tsx
|
|
169
|
-
* // With custom subscribe/getSnapshot for advanced use cases
|
|
170
|
-
* function CustomMapInfo() {
|
|
171
|
-
* const customSubscribe = (onStoreChange) => {
|
|
172
|
-
* // Custom subscription logic
|
|
173
|
-
* return () => { // cleanup }
|
|
174
|
-
* }
|
|
175
|
-
*
|
|
176
|
-
* const customGetSnapshot = () => {
|
|
177
|
-
* // Custom snapshot logic
|
|
178
|
-
* return { latitude: 0, longitude: 0, zoom: 1 };
|
|
179
|
-
* };
|
|
180
|
-
*
|
|
181
|
-
* const viewState = useViewportState({
|
|
182
|
-
* instanceId: 'some-uuid',
|
|
183
|
-
* subscribe: customSubscribe,
|
|
184
|
-
* getSnapshot: customGetSnapshot,
|
|
185
|
-
* });
|
|
186
|
-
*
|
|
187
|
-
* return <div>Custom viewport state</div>;
|
|
188
|
-
* }
|
|
189
|
-
* ```
|
|
190
|
-
*/
|
|
191
|
-
function useViewportState({ instanceId, subscribe, getSnapshot, getServerSnapshot }) {
|
|
192
|
-
return useSyncExternalStore(subscribe ?? getOrCreateSubscription(instanceId), getSnapshot ?? getOrCreateSnapshot(instanceId), getServerSnapshot);
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Manually clear viewport state for a specific instanceId.
|
|
196
|
-
* This is typically not needed as cleanup happens automatically when all subscribers unmount.
|
|
197
|
-
* Use this only in advanced scenarios where manual cleanup is required.
|
|
198
|
-
*
|
|
199
|
-
* @param instanceId - The unique identifier for the viewport to clear
|
|
200
|
-
*
|
|
201
|
-
* @example
|
|
202
|
-
* ```tsx
|
|
203
|
-
* // Manual cleanup (rarely needed)
|
|
204
|
-
* clearViewportState('my-map-instance');
|
|
205
|
-
* ```
|
|
206
|
-
*/
|
|
207
|
-
function clearViewportState(instanceId) {
|
|
208
|
-
const unsub = busUnsubscribers.get(instanceId);
|
|
209
|
-
if (unsub) {
|
|
210
|
-
unsub();
|
|
211
|
-
busUnsubscribers.delete(instanceId);
|
|
212
|
-
}
|
|
213
|
-
viewportStore.delete(instanceId);
|
|
214
|
-
componentSubscribers.delete(instanceId);
|
|
215
|
-
subscriptionCache.delete(instanceId);
|
|
216
|
-
snapshotCache.delete(instanceId);
|
|
217
|
-
fallbackCache.delete(instanceId);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
//#endregion
|
|
221
|
-
export { clearViewportState, useViewportState };
|
|
222
|
-
//# sourceMappingURL=use-viewport-state.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-viewport-state.js","names":["newFallback: MapViewportPayload"],"sources":["../../src/viewport/use-viewport-state.ts"],"sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { Broadcast } from '@accelint/bus';\nimport { useSyncExternalStore } from 'react';\nimport { MapEvents } from '../deckgl/base-map/events';\nimport type { UniqueId } from '@accelint/core';\nimport type {\n MapEventType,\n MapViewportPayload,\n} from '../deckgl/base-map/types';\n\nconst bus = Broadcast.getInstance<MapEventType>();\n\nexport type UseViewportStateProps = {\n instanceId: UniqueId;\n subscribe?: Parameters<typeof useSyncExternalStore<MapViewportPayload>>[0];\n getSnapshot?: Parameters<typeof useSyncExternalStore<MapViewportPayload>>[1];\n getServerSnapshot?: Parameters<\n typeof useSyncExternalStore<MapViewportPayload>\n >[2];\n};\n\n/**\n * Store for viewport state keyed by instanceId\n */\nconst viewportStore = new Map<UniqueId, MapViewportPayload>();\n\n/**\n * Track React component subscribers per instanceId (for fan-out notifications).\n * Each Set contains onStoreChange callbacks from useSyncExternalStore.\n */\nconst componentSubscribers = new Map<UniqueId, Set<() => void>>();\n\n/**\n * Cache of bus unsubscribe functions (1 per instanceId).\n * This ensures we only have one bus listener per viewport, regardless of\n * how many React components subscribe to it.\n */\nconst busUnsubscribers = new Map<UniqueId, () => void>();\n\ntype Subscription = (onStoreChange: () => void) => () => void;\n/**\n * Cache of subscription functions per instanceId to avoid recreating on every render\n */\nconst subscriptionCache = new Map<UniqueId, Subscription>();\n\n/**\n * Cache of snapshot functions per instanceId to maintain referential stability\n */\nconst snapshotCache = new Map<UniqueId, () => MapViewportPayload>();\n\n/**\n * Cache of fallback snapshots per instanceId to maintain referential stability.\n * This prevents unnecessary re-renders when no viewport data exists yet.\n */\nconst fallbackCache = new Map<UniqueId, MapViewportPayload>();\n\n/**\n * Ensures a single bus listener exists for the given instanceId.\n * All React subscribers will be notified via fan-out when the bus event fires.\n * This prevents creating N bus listeners for N React components.\n *\n * @param instanceId - The unique identifier for the viewport\n */\nfunction ensureBusListener(instanceId: UniqueId): void {\n if (busUnsubscribers.has(instanceId)) {\n return; // Already listening\n }\n\n const unsub = bus.on(MapEvents.viewport, ({ payload }) => {\n if (instanceId === payload.id) {\n // Write to store once\n viewportStore.set(instanceId, payload);\n\n // Fan-out: notify all React subscribers\n const subscribers = componentSubscribers.get(instanceId);\n if (subscribers) {\n for (const onStoreChange of subscribers) {\n onStoreChange();\n }\n }\n }\n });\n\n busUnsubscribers.set(instanceId, unsub);\n}\n\n/**\n * Cleans up the bus listener if no React subscribers remain.\n *\n * @param instanceId - The unique identifier for the viewport\n */\nfunction cleanupBusListenerIfNeeded(instanceId: UniqueId): void {\n const subscribers = componentSubscribers.get(instanceId);\n\n if (!subscribers || subscribers.size === 0) {\n // No more React subscribers - clean up bus listener\n const unsub = busUnsubscribers.get(instanceId);\n if (unsub) {\n unsub();\n busUnsubscribers.delete(instanceId);\n }\n\n // Clean up all state\n viewportStore.delete(instanceId);\n componentSubscribers.delete(instanceId);\n subscriptionCache.delete(instanceId);\n snapshotCache.delete(instanceId);\n fallbackCache.delete(instanceId);\n }\n}\n\n/**\n * Creates or retrieves a cached subscription function for a given instanceId.\n * Uses a fan-out pattern: 1 bus listener -> N React subscribers.\n * Automatically cleans up viewport state when the last subscriber unsubscribes.\n *\n * @param instanceId - The unique identifier for the viewport\n * @returns A subscription function for useSyncExternalStore\n */\nfunction getOrCreateSubscription(\n instanceId: UniqueId,\n): (onStoreChange: () => void) => () => void {\n const subscription =\n subscriptionCache.get(instanceId) ??\n ((onStoreChange: () => void) => {\n // Ensure single bus listener exists for this instanceId\n ensureBusListener(instanceId);\n\n // Get or create the subscriber set for this map instance, then add this component's callback\n let subscriberSet = componentSubscribers.get(instanceId);\n if (!subscriberSet) {\n subscriberSet = new Set();\n componentSubscribers.set(instanceId, subscriberSet);\n }\n subscriberSet.add(onStoreChange);\n\n // Return cleanup function to remove this component's subscription\n return () => {\n const currentSubscriberSet = componentSubscribers.get(instanceId);\n if (currentSubscriberSet) {\n currentSubscriberSet.delete(onStoreChange);\n }\n\n // Clean up bus listener if this was the last React subscriber\n cleanupBusListenerIfNeeded(instanceId);\n };\n });\n\n subscriptionCache.set(instanceId, subscription);\n\n return subscription;\n}\n\n/**\n * Creates or retrieves a cached snapshot function for a given instanceId.\n * The object returned gets equality checked, so it needs to be stable or React re-renders unnecessarily.\n *\n * @param instanceId - The unique identifier for the viewport\n * @returns A snapshot function for useSyncExternalStore\n */\nfunction getOrCreateSnapshot(instanceId: UniqueId): () => MapViewportPayload {\n // Get or create stable fallback reference for this instanceId\n const fallback =\n fallbackCache.get(instanceId) ??\n (() => {\n const newFallback: MapViewportPayload = {\n id: instanceId,\n bounds: undefined,\n latitude: Number.NaN,\n longitude: Number.NaN,\n zoom: Number.NaN,\n width: 0,\n height: 0,\n };\n fallbackCache.set(instanceId, newFallback);\n return newFallback;\n })();\n\n const snapshot =\n snapshotCache.get(instanceId) ??\n (() => viewportStore.get(instanceId) ?? fallback);\n\n snapshotCache.set(instanceId, snapshot);\n\n return snapshot;\n}\n\n/**\n * Hook to subscribe to viewport state changes for a specific view.\n *\n * By default, subscribes to MapEvents.viewport events from the event bus and\n * automatically cleans up when all subscribers unmount. For advanced use cases,\n * custom subscribe/getSnapshot functions can be provided.\n *\n * A thin wrapper around [useSyncExternalStore](https://react.dev/reference/react/useSyncExternalStore).\n *\n * @param instanceId - Unique identifier for the viewport to track\n * @param subscribe - Optional custom subscription function\n * @param getSnapshot - Optional custom snapshot getter\n * @param getServerSnapshot - Optional server-side snapshot getter\n * @returns Current viewport state including bounds, latitude, longitude, zoom\n *\n * @example\n * ```tsx\n * function MapInfo({ instanceId }) {\n * const { bounds, latitude, longitude, zoom } = useViewportState({\n * instanceId\n * });\n *\n * return (\n * <div>\n * Lat: {latitude?.toFixed(2)}, Lon: {longitude?.toFixed(2)}, Zoom: {zoom}\n * </div>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With custom subscribe/getSnapshot for advanced use cases\n * function CustomMapInfo() {\n * const customSubscribe = (onStoreChange) => {\n * // Custom subscription logic\n * return () => { // cleanup }\n * }\n *\n * const customGetSnapshot = () => {\n * // Custom snapshot logic\n * return { latitude: 0, longitude: 0, zoom: 1 };\n * };\n *\n * const viewState = useViewportState({\n * instanceId: 'some-uuid',\n * subscribe: customSubscribe,\n * getSnapshot: customGetSnapshot,\n * });\n *\n * return <div>Custom viewport state</div>;\n * }\n * ```\n */\nexport function useViewportState({\n instanceId,\n subscribe,\n getSnapshot,\n getServerSnapshot,\n}: UseViewportStateProps) {\n return useSyncExternalStore<MapViewportPayload>(\n subscribe ?? getOrCreateSubscription(instanceId),\n getSnapshot ?? getOrCreateSnapshot(instanceId),\n getServerSnapshot,\n );\n}\n\n/**\n * Manually clear viewport state for a specific instanceId.\n * This is typically not needed as cleanup happens automatically when all subscribers unmount.\n * Use this only in advanced scenarios where manual cleanup is required.\n *\n * @param instanceId - The unique identifier for the viewport to clear\n *\n * @example\n * ```tsx\n * // Manual cleanup (rarely needed)\n * clearViewportState('my-map-instance');\n * ```\n */\nexport function clearViewportState(instanceId: UniqueId): void {\n // Unsubscribe from bus if listening\n const unsub = busUnsubscribers.get(instanceId);\n if (unsub) {\n unsub();\n busUnsubscribers.delete(instanceId);\n }\n\n // Clear all state\n viewportStore.delete(instanceId);\n componentSubscribers.delete(instanceId);\n subscriptionCache.delete(instanceId);\n snapshotCache.delete(instanceId);\n fallbackCache.delete(instanceId);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqBA,MAAM,MAAM,UAAU,aAA2B;;;;AAcjD,MAAM,gCAAgB,IAAI,KAAmC;;;;;AAM7D,MAAM,uCAAuB,IAAI,KAAgC;;;;;;AAOjE,MAAM,mCAAmB,IAAI,KAA2B;;;;AAMxD,MAAM,oCAAoB,IAAI,KAA6B;;;;AAK3D,MAAM,gCAAgB,IAAI,KAAyC;;;;;AAMnE,MAAM,gCAAgB,IAAI,KAAmC;;;;;;;;AAS7D,SAAS,kBAAkB,YAA4B;AACrD,KAAI,iBAAiB,IAAI,WAAW,CAClC;CAGF,MAAM,QAAQ,IAAI,GAAG,UAAU,WAAW,EAAE,cAAc;AACxD,MAAI,eAAe,QAAQ,IAAI;AAE7B,iBAAc,IAAI,YAAY,QAAQ;GAGtC,MAAM,cAAc,qBAAqB,IAAI,WAAW;AACxD,OAAI,YACF,MAAK,MAAM,iBAAiB,YAC1B,gBAAe;;GAIrB;AAEF,kBAAiB,IAAI,YAAY,MAAM;;;;;;;AAQzC,SAAS,2BAA2B,YAA4B;CAC9D,MAAM,cAAc,qBAAqB,IAAI,WAAW;AAExD,KAAI,CAAC,eAAe,YAAY,SAAS,GAAG;EAE1C,MAAM,QAAQ,iBAAiB,IAAI,WAAW;AAC9C,MAAI,OAAO;AACT,UAAO;AACP,oBAAiB,OAAO,WAAW;;AAIrC,gBAAc,OAAO,WAAW;AAChC,uBAAqB,OAAO,WAAW;AACvC,oBAAkB,OAAO,WAAW;AACpC,gBAAc,OAAO,WAAW;AAChC,gBAAc,OAAO,WAAW;;;;;;;;;;;AAYpC,SAAS,wBACP,YAC2C;CAC3C,MAAM,eACJ,kBAAkB,IAAI,WAAW,MAC/B,kBAA8B;AAE9B,oBAAkB,WAAW;EAG7B,IAAI,gBAAgB,qBAAqB,IAAI,WAAW;AACxD,MAAI,CAAC,eAAe;AAClB,mCAAgB,IAAI,KAAK;AACzB,wBAAqB,IAAI,YAAY,cAAc;;AAErD,gBAAc,IAAI,cAAc;AAGhC,eAAa;GACX,MAAM,uBAAuB,qBAAqB,IAAI,WAAW;AACjE,OAAI,qBACF,sBAAqB,OAAO,cAAc;AAI5C,8BAA2B,WAAW;;;AAI5C,mBAAkB,IAAI,YAAY,aAAa;AAE/C,QAAO;;;;;;;;;AAUT,SAAS,oBAAoB,YAAgD;CAE3E,MAAM,WACJ,cAAc,IAAI,WAAW,WACtB;EACL,MAAMA,cAAkC;GACtC,IAAI;GACJ,QAAQ;GACR,UAAU;GACV,WAAW;GACX,MAAM;GACN,OAAO;GACP,QAAQ;GACT;AACD,gBAAc,IAAI,YAAY,YAAY;AAC1C,SAAO;KACL;CAEN,MAAM,WACJ,cAAc,IAAI,WAAW,WACtB,cAAc,IAAI,WAAW,IAAI;AAE1C,eAAc,IAAI,YAAY,SAAS;AAEvC,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDT,SAAgB,iBAAiB,EAC/B,YACA,WACA,aACA,qBACwB;AACxB,QAAO,qBACL,aAAa,wBAAwB,WAAW,EAChD,eAAe,oBAAoB,WAAW,EAC9C,kBACD;;;;;;;;;;;;;;;AAgBH,SAAgB,mBAAmB,YAA4B;CAE7D,MAAM,QAAQ,iBAAiB,IAAI,WAAW;AAC9C,KAAI,OAAO;AACT,SAAO;AACP,mBAAiB,OAAO,WAAW;;AAIrC,eAAc,OAAO,WAAW;AAChC,sBAAqB,OAAO,WAAW;AACvC,mBAAkB,OAAO,WAAW;AACpC,eAAc,OAAO,WAAW;AAChC,eAAc,OAAO,WAAW"}
|