@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.
Files changed (183) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/catalog-info.yaml +5 -4
  3. package/dist/camera/index.d.ts +2 -2
  4. package/dist/camera/index.js +2 -2
  5. package/dist/camera/store.d.ts +120 -0
  6. package/dist/camera/store.js +279 -0
  7. package/dist/camera/store.js.map +1 -0
  8. package/dist/deckgl/base-map/constants.d.ts +1 -6
  9. package/dist/deckgl/base-map/constants.js +1 -6
  10. package/dist/deckgl/base-map/constants.js.map +1 -1
  11. package/dist/deckgl/base-map/controls.js +2 -0
  12. package/dist/deckgl/base-map/controls.js.map +1 -1
  13. package/dist/deckgl/base-map/index.d.ts +2 -2
  14. package/dist/deckgl/base-map/index.js +10 -11
  15. package/dist/deckgl/base-map/index.js.map +1 -1
  16. package/dist/deckgl/base-map/provider.js +1 -1
  17. package/dist/deckgl/index.d.ts +4 -4
  18. package/dist/deckgl/index.js +4 -4
  19. package/dist/deckgl/saved-viewports/storage.js +10 -2
  20. package/dist/deckgl/saved-viewports/storage.js.map +1 -1
  21. package/dist/deckgl/shapes/display-shape-layer/constants.js +5 -8
  22. package/dist/deckgl/shapes/display-shape-layer/constants.js.map +1 -1
  23. package/dist/deckgl/shapes/display-shape-layer/index.d.ts +18 -14
  24. package/dist/deckgl/shapes/display-shape-layer/index.js +63 -30
  25. package/dist/deckgl/shapes/display-shape-layer/index.js.map +1 -1
  26. package/dist/deckgl/shapes/display-shape-layer/shape-label-layer.js +2 -16
  27. package/dist/deckgl/shapes/display-shape-layer/shape-label-layer.js.map +1 -1
  28. package/dist/deckgl/shapes/display-shape-layer/store.js +58 -272
  29. package/dist/deckgl/shapes/display-shape-layer/store.js.map +1 -1
  30. package/dist/deckgl/shapes/display-shape-layer/types.d.ts +22 -11
  31. package/dist/deckgl/shapes/display-shape-layer/{use-shape-selection.d.ts → use-select-shape.d.ts} +9 -9
  32. package/dist/deckgl/shapes/display-shape-layer/{use-shape-selection.js → use-select-shape.js} +12 -12
  33. package/dist/deckgl/shapes/display-shape-layer/use-select-shape.js.map +1 -0
  34. package/dist/deckgl/shapes/display-shape-layer/utils/display-style.js +5 -66
  35. package/dist/deckgl/shapes/display-shape-layer/utils/display-style.js.map +1 -1
  36. package/dist/deckgl/shapes/display-shape-layer/utils/labels.d.ts +2 -65
  37. package/dist/deckgl/shapes/display-shape-layer/utils/labels.js +3 -121
  38. package/dist/deckgl/shapes/display-shape-layer/utils/labels.js.map +1 -1
  39. package/dist/deckgl/shapes/draw-shape-layer/constants.js +46 -0
  40. package/dist/deckgl/shapes/draw-shape-layer/constants.js.map +1 -0
  41. package/dist/deckgl/shapes/draw-shape-layer/events.d.ts +92 -0
  42. package/dist/deckgl/shapes/draw-shape-layer/events.js +56 -0
  43. package/dist/deckgl/shapes/draw-shape-layer/events.js.map +1 -0
  44. package/dist/deckgl/shapes/draw-shape-layer/fiber.d.ts +11 -0
  45. package/dist/{maplibre/constants.js → deckgl/shapes/draw-shape-layer/fiber.js} +6 -12
  46. package/dist/deckgl/shapes/draw-shape-layer/fiber.js.map +1 -0
  47. package/dist/deckgl/shapes/draw-shape-layer/index.d.ts +53 -0
  48. package/dist/deckgl/shapes/draw-shape-layer/index.js +95 -0
  49. package/dist/deckgl/shapes/draw-shape-layer/index.js.map +1 -0
  50. package/dist/deckgl/shapes/draw-shape-layer/modes/draw-circle-mode-with-tooltip.js +51 -0
  51. package/dist/deckgl/shapes/draw-shape-layer/modes/draw-circle-mode-with-tooltip.js.map +1 -0
  52. package/dist/deckgl/shapes/draw-shape-layer/modes/draw-ellipse-mode-with-tooltip.js +73 -0
  53. package/dist/deckgl/shapes/draw-shape-layer/modes/draw-ellipse-mode-with-tooltip.js.map +1 -0
  54. package/dist/deckgl/shapes/draw-shape-layer/modes/draw-line-string-mode-with-tooltip.js +87 -0
  55. package/dist/deckgl/shapes/draw-shape-layer/modes/draw-line-string-mode-with-tooltip.js.map +1 -0
  56. package/dist/deckgl/shapes/draw-shape-layer/modes/draw-polygon-mode-with-tooltip.js +88 -0
  57. package/dist/deckgl/shapes/draw-shape-layer/modes/draw-polygon-mode-with-tooltip.js.map +1 -0
  58. package/dist/deckgl/shapes/draw-shape-layer/modes/draw-rectangle-mode-with-tooltip.js +77 -0
  59. package/dist/deckgl/shapes/draw-shape-layer/modes/draw-rectangle-mode-with-tooltip.js.map +1 -0
  60. package/dist/deckgl/shapes/draw-shape-layer/modes/index.js +64 -0
  61. package/dist/deckgl/shapes/draw-shape-layer/modes/index.js.map +1 -0
  62. package/dist/deckgl/shapes/draw-shape-layer/store.js +175 -0
  63. package/dist/deckgl/shapes/draw-shape-layer/store.js.map +1 -0
  64. package/dist/deckgl/shapes/draw-shape-layer/types.d.ts +86 -0
  65. package/dist/{viewport/constants.js → deckgl/shapes/draw-shape-layer/types.js} +1 -12
  66. package/dist/deckgl/shapes/draw-shape-layer/use-draw-shape.d.ts +82 -0
  67. package/dist/deckgl/shapes/draw-shape-layer/use-draw-shape.js +112 -0
  68. package/dist/deckgl/shapes/draw-shape-layer/use-draw-shape.js.map +1 -0
  69. package/dist/deckgl/shapes/draw-shape-layer/utils/feature-conversion.js +147 -0
  70. package/dist/deckgl/shapes/draw-shape-layer/utils/feature-conversion.js.map +1 -0
  71. package/dist/deckgl/shapes/edit-shape-layer/constants.js +41 -0
  72. package/dist/deckgl/shapes/edit-shape-layer/constants.js.map +1 -0
  73. package/dist/deckgl/shapes/edit-shape-layer/events.d.ts +92 -0
  74. package/dist/deckgl/shapes/edit-shape-layer/events.js +56 -0
  75. package/dist/deckgl/shapes/edit-shape-layer/events.js.map +1 -0
  76. package/dist/deckgl/shapes/edit-shape-layer/fiber.d.ts +13 -0
  77. package/dist/deckgl/shapes/edit-shape-layer/fiber.js +14 -0
  78. package/dist/deckgl/shapes/edit-shape-layer/index.d.ts +63 -0
  79. package/dist/deckgl/shapes/edit-shape-layer/index.js +162 -0
  80. package/dist/deckgl/shapes/edit-shape-layer/index.js.map +1 -0
  81. package/dist/deckgl/shapes/edit-shape-layer/modes/base-transform-mode.js +154 -0
  82. package/dist/deckgl/shapes/edit-shape-layer/modes/base-transform-mode.js.map +1 -0
  83. package/dist/deckgl/shapes/edit-shape-layer/modes/bounding-transform-mode.js +147 -0
  84. package/dist/deckgl/shapes/edit-shape-layer/modes/bounding-transform-mode.js.map +1 -0
  85. package/dist/deckgl/shapes/edit-shape-layer/modes/circle-transform-mode.js +87 -0
  86. package/dist/deckgl/shapes/edit-shape-layer/modes/circle-transform-mode.js.map +1 -0
  87. package/dist/deckgl/shapes/edit-shape-layer/modes/index.js +61 -0
  88. package/dist/deckgl/shapes/edit-shape-layer/modes/index.js.map +1 -0
  89. package/dist/deckgl/shapes/edit-shape-layer/modes/rotate-mode-with-snap.js +109 -0
  90. package/dist/deckgl/shapes/edit-shape-layer/modes/rotate-mode-with-snap.js.map +1 -0
  91. package/dist/deckgl/shapes/edit-shape-layer/modes/scale-mode-with-free-transform.js +289 -0
  92. package/dist/deckgl/shapes/edit-shape-layer/modes/scale-mode-with-free-transform.js.map +1 -0
  93. package/dist/deckgl/shapes/edit-shape-layer/modes/vertex-transform-mode.js +121 -0
  94. package/dist/deckgl/shapes/edit-shape-layer/modes/vertex-transform-mode.js.map +1 -0
  95. package/dist/deckgl/shapes/edit-shape-layer/store.js +194 -0
  96. package/dist/deckgl/shapes/edit-shape-layer/store.js.map +1 -0
  97. package/dist/deckgl/shapes/edit-shape-layer/types.d.ts +93 -0
  98. package/dist/deckgl/shapes/edit-shape-layer/types.js +14 -0
  99. package/dist/deckgl/shapes/edit-shape-layer/use-edit-shape.d.ts +82 -0
  100. package/dist/deckgl/shapes/edit-shape-layer/use-edit-shape.js +114 -0
  101. package/dist/deckgl/shapes/edit-shape-layer/use-edit-shape.js.map +1 -0
  102. package/dist/deckgl/shapes/index.d.ts +15 -6
  103. package/dist/deckgl/shapes/index.js +12 -5
  104. package/dist/deckgl/shapes/shared/constants.d.ts +27 -32
  105. package/dist/deckgl/shapes/shared/constants.js +189 -25
  106. package/dist/deckgl/shapes/shared/constants.js.map +1 -1
  107. package/dist/deckgl/shapes/shared/events.d.ts +1 -20
  108. package/dist/deckgl/shapes/shared/events.js +1 -31
  109. package/dist/deckgl/shapes/shared/events.js.map +1 -1
  110. package/dist/deckgl/shapes/shared/hooks/use-shift-zoom-disable.js +84 -0
  111. package/dist/deckgl/shapes/shared/hooks/use-shift-zoom-disable.js.map +1 -0
  112. package/dist/deckgl/shapes/shared/types.d.ts +187 -28
  113. package/dist/deckgl/shapes/shared/types.js +55 -1
  114. package/dist/deckgl/shapes/shared/types.js.map +1 -1
  115. package/dist/deckgl/shapes/shared/utils/geometry-measurements.js +128 -0
  116. package/dist/deckgl/shapes/shared/utils/geometry-measurements.js.map +1 -0
  117. package/dist/deckgl/shapes/shared/utils/layer-config.js +50 -0
  118. package/dist/deckgl/shapes/shared/utils/layer-config.js.map +1 -0
  119. package/dist/deckgl/shapes/shared/utils/mode-utils.js +113 -0
  120. package/dist/deckgl/shapes/shared/utils/mode-utils.js.map +1 -0
  121. package/dist/deckgl/shapes/shared/utils/pick-filtering.js +57 -0
  122. package/dist/deckgl/shapes/shared/utils/pick-filtering.js.map +1 -0
  123. package/dist/deckgl/shapes/shared/utils/style-utils.d.ts +64 -0
  124. package/dist/deckgl/shapes/shared/utils/style-utils.js +101 -0
  125. package/dist/deckgl/shapes/shared/utils/style-utils.js.map +1 -0
  126. package/dist/deckgl/text-layer/default-settings.js +4 -24
  127. package/dist/deckgl/text-layer/default-settings.js.map +1 -1
  128. package/dist/deckgl/text-settings.d.ts +77 -0
  129. package/dist/deckgl/text-settings.js +83 -0
  130. package/dist/deckgl/text-settings.js.map +1 -0
  131. package/dist/map-cursor/index.d.ts +2 -2
  132. package/dist/map-cursor/index.js +2 -2
  133. package/dist/map-cursor/store.d.ts +32 -61
  134. package/dist/map-cursor/store.js +165 -294
  135. package/dist/map-cursor/store.js.map +1 -1
  136. package/dist/map-cursor/use-map-cursor.d.ts +5 -2
  137. package/dist/map-cursor/use-map-cursor.js +33 -15
  138. package/dist/map-cursor/use-map-cursor.js.map +1 -1
  139. package/dist/map-mode/index.d.ts +2 -2
  140. package/dist/map-mode/index.js +2 -2
  141. package/dist/map-mode/store.d.ts +36 -37
  142. package/dist/map-mode/store.js +131 -237
  143. package/dist/map-mode/store.js.map +1 -1
  144. package/dist/map-mode/use-map-mode.js +6 -5
  145. package/dist/map-mode/use-map-mode.js.map +1 -1
  146. package/dist/maplibre/index.d.ts +2 -2
  147. package/dist/maplibre/index.js +2 -2
  148. package/dist/shared/constants.d.ts +19 -0
  149. package/dist/shared/constants.js +33 -0
  150. package/dist/shared/constants.js.map +1 -0
  151. package/dist/shared/create-map-store.d.ts +202 -0
  152. package/dist/shared/create-map-store.js +223 -0
  153. package/dist/shared/create-map-store.js.map +1 -0
  154. package/dist/shared/units.d.ts +39 -0
  155. package/dist/shared/units.js +49 -0
  156. package/dist/shared/units.js.map +1 -0
  157. package/dist/viewport/index.d.ts +3 -3
  158. package/dist/viewport/index.js +3 -3
  159. package/dist/viewport/store.d.ts +69 -0
  160. package/dist/viewport/store.js +125 -0
  161. package/dist/viewport/store.js.map +1 -0
  162. package/dist/viewport/types.d.ts +2 -2
  163. package/dist/viewport/utils.js +2 -2
  164. package/dist/viewport/utils.js.map +1 -1
  165. package/dist/viewport/viewport-size.d.ts +2 -2
  166. package/dist/viewport/viewport-size.js +2 -2
  167. package/dist/viewport/viewport-size.js.map +1 -1
  168. package/package.json +36 -18
  169. package/dist/camera/use-camera-state.d.ts +0 -153
  170. package/dist/camera/use-camera-state.js +0 -418
  171. package/dist/camera/use-camera-state.js.map +0 -1
  172. package/dist/deckgl/shapes/display-shape-layer/constants.d.ts +0 -44
  173. package/dist/deckgl/shapes/display-shape-layer/shape-label-layer.d.ts +0 -66
  174. package/dist/deckgl/shapes/display-shape-layer/store.d.ts +0 -87
  175. package/dist/deckgl/shapes/display-shape-layer/use-shape-selection.js.map +0 -1
  176. package/dist/deckgl/shapes/display-shape-layer/utils/display-style.d.ts +0 -61
  177. package/dist/maplibre/constants.d.ts +0 -13
  178. package/dist/maplibre/constants.js.map +0 -1
  179. package/dist/viewport/constants.d.ts +0 -11
  180. package/dist/viewport/constants.js.map +0 -1
  181. package/dist/viewport/use-viewport-state.d.ts +0 -100
  182. package/dist/viewport/use-viewport-state.js +0 -222
  183. package/dist/viewport/use-viewport-state.js.map +0 -1
@@ -1,418 +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 { CameraEventTypes } from "./events.js";
15
- import { Broadcast } from "@accelint/bus";
16
- import { fitBounds } from "@math.gl/web-mercator";
17
- import { useMemo, useSyncExternalStore } from "react";
18
-
19
- //#region src/camera/use-camera-state.ts
20
- /**
21
- * Typed event bus instance for camera events.
22
- * Provides type-safe event emission and listening for all camera state changes.
23
- */
24
- const cameraBus = Broadcast.getInstance();
25
- /**
26
- * Store for camera state keyed by instanceId
27
- */
28
- const cameraStore = /* @__PURE__ */ new Map();
29
- /**
30
- * Track React component subscribers per instanceId (for fan-out notifications).
31
- * Each Set contains onStoreChange callbacks from useSyncExternalStore.
32
- */
33
- const componentSubscribers = /* @__PURE__ */ new Map();
34
- /**
35
- * Cache of bus unsubscribe functions (1 per instanceId).
36
- * This ensures we only have one bus listener per camera, regardless of
37
- * how many React components subscribe to it.
38
- */
39
- const busUnsubscribers = /* @__PURE__ */ new Map();
40
- /**
41
- * Cache of subscription functions per instanceId to avoid recreating on every render
42
- */
43
- const subscriptionCache = /* @__PURE__ */ new Map();
44
- /**
45
- * Cache of snapshot functions per instanceId to maintain referential stability
46
- */
47
- const snapshotCache = /* @__PURE__ */ new Map();
48
- /**
49
- * Cache of fallback snapshots per instanceId to maintain referential stability.
50
- * This prevents unnecessary re-renders when no camera data exists yet.
51
- */
52
- const fallbackCache = /* @__PURE__ */ new Map();
53
- function buildInitialCameraState(initialCameraState) {
54
- if (!initialCameraState) return {
55
- latitude: 0,
56
- longitude: 0,
57
- zoom: 0,
58
- pitch: 0,
59
- rotation: 0,
60
- projection: "mercator",
61
- view: "2D"
62
- };
63
- const is2Point5D = initialCameraState.view === "2.5D";
64
- const is3D = initialCameraState.view === "3D" || initialCameraState.projection === "globe";
65
- let projection;
66
- let view;
67
- if (is3D) {
68
- projection = "globe";
69
- view = "3D";
70
- } else if (is2Point5D) {
71
- projection = "mercator";
72
- view = "2.5D";
73
- } else {
74
- projection = initialCameraState.projection ?? "mercator";
75
- view = initialCameraState.view ?? "2D";
76
- }
77
- return {
78
- latitude: initialCameraState.latitude ?? 0,
79
- longitude: initialCameraState.longitude ?? 0,
80
- zoom: initialCameraState.zoom ?? 0,
81
- pitch: is2Point5D ? initialCameraState.pitch ?? 45 : 0,
82
- rotation: is3D ? 0 : initialCameraState.rotation ?? 0,
83
- projection,
84
- view
85
- };
86
- }
87
- function getOrCreateState(instanceId, initialCameraState) {
88
- if (!cameraStore.has(instanceId)) cameraStore.set(instanceId, buildInitialCameraState(initialCameraState));
89
- return cameraStore.get(instanceId);
90
- }
91
- /**
92
- * Notify all React subscribers for a given instanceId
93
- */
94
- function notifySubscribers(instanceId) {
95
- const subscribers = componentSubscribers.get(instanceId);
96
- if (subscribers) for (const onStoreChange of subscribers) onStoreChange();
97
- }
98
- /**
99
- * Ensures a single bus listener exists for the given instanceId.
100
- * All React subscribers will be notified via fan-out when the bus event fires.
101
- * This prevents creating N bus listeners for N React components.
102
- *
103
- * @param instanceId - The unique identifier for the camera
104
- * @param initialCameraState - Optional initial camera state to set when creating the listener
105
- */
106
- function ensureBusListener(instanceId, initialCameraState) {
107
- if (busUnsubscribers.has(instanceId)) return;
108
- const unsubResetCamera = cameraBus.on(CameraEventTypes.reset, ({ payload }) => {
109
- if (instanceId === payload.id) {
110
- const state = getOrCreateState(instanceId, initialCameraState);
111
- const newState = { ...buildInitialCameraState({
112
- ...state,
113
- zoom: payload.zoom === false ? state.zoom : initialCameraState?.zoom,
114
- pitch: payload.pitch === false ? state.pitch : initialCameraState?.pitch,
115
- rotation: payload.rotation === false ? state.rotation : initialCameraState?.rotation
116
- }) };
117
- cameraStore.set(instanceId, newState);
118
- notifySubscribers(instanceId);
119
- }
120
- });
121
- const unsubSetCenter = cameraBus.on(CameraEventTypes.setCenter, ({ payload }) => {
122
- if (instanceId === payload.id) {
123
- const state = getOrCreateState(instanceId, initialCameraState);
124
- const newState = {
125
- ...state,
126
- latitude: payload.latitude,
127
- longitude: payload.longitude,
128
- zoom: payload.zoom ?? state.zoom,
129
- rotation: payload.heading ?? state.rotation,
130
- pitch: payload.pitch ?? state.pitch
131
- };
132
- cameraStore.set(instanceId, newState);
133
- notifySubscribers(instanceId);
134
- }
135
- });
136
- const unsubFitBounds = cameraBus.on(CameraEventTypes.fitBounds, ({ payload }) => {
137
- if (instanceId === payload.id) {
138
- const state = getOrCreateState(instanceId, initialCameraState);
139
- const { longitude, latitude, zoom } = fitBounds({
140
- width: payload.width,
141
- height: payload.height,
142
- bounds: [[payload.bounds[0], payload.bounds[1]], [payload.bounds[2], payload.bounds[3]]],
143
- padding: payload.padding
144
- });
145
- const newState = {
146
- ...state,
147
- latitude,
148
- longitude,
149
- zoom,
150
- rotation: payload.heading ?? state.rotation,
151
- pitch: payload.pitch ?? state.pitch
152
- };
153
- cameraStore.set(instanceId, newState);
154
- notifySubscribers(instanceId);
155
- }
156
- });
157
- const unsubSetProjection = cameraBus.on(CameraEventTypes.setProjection, ({ payload }) => {
158
- if (instanceId === payload.id) {
159
- const newState = { ...getOrCreateState(instanceId, initialCameraState) };
160
- newState.projection = payload.projection;
161
- if (payload.projection === "globe") newState.view = "3D";
162
- else {
163
- newState.view = "2D";
164
- newState.pitch = 0;
165
- }
166
- cameraStore.set(instanceId, newState);
167
- notifySubscribers(instanceId);
168
- }
169
- });
170
- const unsubSetView = cameraBus.on(CameraEventTypes.setView, ({ payload }) => {
171
- if (instanceId === payload.id) {
172
- const newState = { ...getOrCreateState(instanceId, initialCameraState) };
173
- newState.view = payload.view;
174
- if (payload.view === "3D") {
175
- newState.projection = "globe";
176
- newState.pitch = 0;
177
- } else newState.projection = "mercator";
178
- if (payload.view === "2.5D") newState.pitch = 45;
179
- cameraStore.set(instanceId, newState);
180
- notifySubscribers(instanceId);
181
- }
182
- });
183
- const unsubSetZoom = cameraBus.on(CameraEventTypes.setZoom, ({ payload }) => {
184
- if (instanceId === payload.id) {
185
- const newState = { ...getOrCreateState(instanceId, initialCameraState) };
186
- newState.zoom = payload.zoom;
187
- cameraStore.set(instanceId, newState);
188
- notifySubscribers(instanceId);
189
- }
190
- });
191
- const unsubSetRotation = cameraBus.on(CameraEventTypes.setRotation, ({ payload }) => {
192
- const state = getOrCreateState(instanceId, initialCameraState);
193
- if (instanceId === payload.id && state.view !== "3D") {
194
- const newState = { ...state };
195
- newState.rotation = payload.rotation;
196
- cameraStore.set(instanceId, newState);
197
- notifySubscribers(instanceId);
198
- }
199
- });
200
- const unsubSetPitch = cameraBus.on(CameraEventTypes.setPitch, ({ payload }) => {
201
- const state = getOrCreateState(instanceId, initialCameraState);
202
- if (instanceId === payload.id && state.view === "2.5D") {
203
- const newState = { ...state };
204
- newState.pitch = payload.pitch;
205
- cameraStore.set(instanceId, newState);
206
- notifySubscribers(instanceId);
207
- }
208
- });
209
- busUnsubscribers.set(instanceId, () => {
210
- unsubResetCamera();
211
- unsubSetCenter();
212
- unsubFitBounds();
213
- unsubSetProjection();
214
- unsubSetView();
215
- unsubSetZoom();
216
- unsubSetRotation();
217
- unsubSetPitch();
218
- });
219
- }
220
- /**
221
- * Cleans up the bus listener if no React subscribers remain.
222
- *
223
- * @param instanceId - The unique identifier for the camera
224
- */
225
- function cleanupBusListenerIfNeeded(instanceId) {
226
- const subscribers = componentSubscribers.get(instanceId);
227
- if (!subscribers || subscribers.size === 0) {
228
- const unsub = busUnsubscribers.get(instanceId);
229
- if (unsub) {
230
- unsub();
231
- busUnsubscribers.delete(instanceId);
232
- }
233
- [
234
- cameraStore,
235
- componentSubscribers,
236
- subscriptionCache,
237
- snapshotCache,
238
- fallbackCache
239
- ].forEach((map) => {
240
- map.delete(instanceId);
241
- });
242
- }
243
- }
244
- /**
245
- * Creates or retrieves a cached subscription function for a given instanceId.
246
- * Uses a fan-out pattern: 1 bus listener -> N React subscribers.
247
- * Automatically cleans up camera state when the last subscriber unsubscribes.
248
- *
249
- * @param instanceId - The unique identifier for the camera
250
- * @param initialCameraState - Optional initial camera state to set when creating the listener
251
- * @returns A subscription function for useSyncExternalStore
252
- */
253
- function getOrCreateSubscription(instanceId, initialCameraState) {
254
- const subscription = subscriptionCache.get(instanceId) ?? ((onStoreChange) => {
255
- ensureBusListener(instanceId, initialCameraState);
256
- let subscriberSet = componentSubscribers.get(instanceId);
257
- if (!subscriberSet) {
258
- subscriberSet = /* @__PURE__ */ new Set();
259
- componentSubscribers.set(instanceId, subscriberSet);
260
- }
261
- subscriberSet.add(onStoreChange);
262
- return () => {
263
- const currentSubscriberSet = componentSubscribers.get(instanceId);
264
- if (currentSubscriberSet) currentSubscriberSet.delete(onStoreChange);
265
- cleanupBusListenerIfNeeded(instanceId);
266
- };
267
- });
268
- subscriptionCache.set(instanceId, subscription);
269
- return subscription;
270
- }
271
- /**
272
- * Creates or retrieves a cached snapshot function for a given instanceId.
273
- * The object returned gets equality checked, so it needs to be stable or React re-renders unnecessarily.
274
- *
275
- * @param instanceId - The unique identifier for the camera
276
- * @param initialCameraState - Initialize the snapshot with camera view information
277
- * @returns A snapshot function for useSyncExternalStore
278
- */
279
- function getOrCreateSnapshot(instanceId, initialCameraState) {
280
- const fallback = fallbackCache.get(instanceId) ?? (() => {
281
- const newFallback = {
282
- latitude: initialCameraState?.latitude ?? 0,
283
- longitude: initialCameraState?.longitude ?? 0,
284
- zoom: initialCameraState?.zoom ?? 0,
285
- pitch: 0,
286
- rotation: 0,
287
- projection: "mercator",
288
- view: "2D"
289
- };
290
- fallbackCache.set(instanceId, newFallback);
291
- return newFallback;
292
- })();
293
- const snapshot = snapshotCache.get(instanceId) ?? (() => cameraStore.get(instanceId) ?? fallback);
294
- snapshotCache.set(instanceId, snapshot);
295
- return snapshot;
296
- }
297
- /**
298
- * Updates the camera state for a given map instance and notifies subscribers.
299
- *
300
- * @param instanceId - The unique identifier for the map
301
- * @param state - The new state to set, will be merged with existing state
302
- *
303
- * @example
304
- * ```tsx
305
- * // Update camera state manually
306
- * setCameraState('my-map-instance', {
307
- * latitude: 37.7749,
308
- * longitude: -122.4194,
309
- * zoom: 10,
310
- * pitch: 30,
311
- * rotation: 0,
312
- * projection: 'mercator',
313
- * });
314
- * ```
315
- */
316
- function setCameraState(instanceId, state) {
317
- const currentState = getOrCreateState(instanceId);
318
- cameraStore.set(instanceId, {
319
- ...currentState,
320
- ...state
321
- });
322
- notifySubscribers(instanceId);
323
- }
324
- /**
325
- * Hook to access camera state actions.
326
- *
327
- * This hook uses `useSyncExternalStore` to subscribe to camera state changes,
328
- * providing concurrent-safe mode state updates. Uses a fan-out pattern where
329
- * a single bus listener per map instance notifies N React component subscribers.
330
- *
331
- * A thin wrapper around [useSyncExternalStore](https://react.dev/reference/react/useSyncExternalStore).
332
- *
333
- * @param instanceId - Unique identifier for the camera to track
334
- * @param initialCameraState - Optional initial camera state to set
335
- * @param subscribe - Optional custom subscription function
336
- * @param getSnapshot - Optional custom snapshot getter
337
- * @param getServerSnapshot - Optional server-side snapshot getter
338
- * @returns Current camera state including latitude, longitude, zoom, pitch, rotation, projection
339
- *
340
- * @example
341
- * ```tsx
342
- * function MapInfo({ instanceId }) {
343
- * const { latitude, longitude, zoom } = useCameraState({
344
- * instanceId
345
- * });
346
- *
347
- * return (
348
- * <div>
349
- * Lat: {latitude?.toFixed(2)}, Lon: {longitude?.toFixed(2)}, Zoom: {zoom}
350
- * </div>
351
- * );
352
- * }
353
- * ```
354
- *
355
- * @example
356
- * ```tsx
357
- * // With custom subscribe/getSnapshot for advanced use cases
358
- * function CustomMapInfo() {
359
- * const customSubscribe = (onStoreChange) => {
360
- * // Custom subscription logic
361
- * return () => { // cleanup }
362
- * }
363
- *
364
- * const customGetSnapshot = () => {
365
- * // Custom snapshot logic
366
- * return { latitude: 0, longitude: 0, zoom: 1 };
367
- * };
368
- *
369
- * const viewState = useCameraState({
370
- * instanceId: 'some-uuid',
371
- * subscribe: customSubscribe,
372
- * getSnapshot: customGetSnapshot,
373
- * });
374
- *
375
- * return <div>Custom camera state</div>;
376
- * }
377
- * ```
378
- */
379
- function useCameraState({ instanceId, initialCameraState, subscribe, getSnapshot, getServerSnapshot }) {
380
- const cameraState = useSyncExternalStore(subscribe ?? getOrCreateSubscription(instanceId, initialCameraState), getSnapshot ?? getOrCreateSnapshot(instanceId, initialCameraState), getServerSnapshot);
381
- return useMemo(() => ({
382
- cameraState,
383
- setCameraState
384
- }), [cameraState]);
385
- }
386
- /**
387
- * Manually clear camera state for a specific instanceId.
388
- * This is typically not needed as cleanup happens automatically when all subscribers unmount.
389
- * Use this only in advanced scenarios where manual cleanup is required.
390
- *
391
- * @param instanceId - The unique identifier for the camera to clear
392
- *
393
- * @example
394
- * ```tsx
395
- * // Manual cleanup (rarely needed)
396
- * clearCameraState('my-map-instance');
397
- * ```
398
- */
399
- function clearCameraState(instanceId) {
400
- const unsub = busUnsubscribers.get(instanceId);
401
- if (unsub) {
402
- unsub();
403
- busUnsubscribers.delete(instanceId);
404
- }
405
- [
406
- cameraStore,
407
- componentSubscribers,
408
- subscriptionCache,
409
- snapshotCache,
410
- fallbackCache
411
- ].forEach((map) => {
412
- map.delete(instanceId);
413
- });
414
- }
415
-
416
- //#endregion
417
- export { clearCameraState, useCameraState };
418
- //# sourceMappingURL=use-camera-state.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-camera-state.js","names":["projection: ProjectionType","view: ViewType","newFallback: CameraState"],"sources":["../../src/camera/use-camera-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 { fitBounds } from '@math.gl/web-mercator';\nimport { useMemo, useSyncExternalStore } from 'react';\nimport { CameraEventTypes } from './events';\nimport type { UniqueId } from '@accelint/core';\nimport type { CameraEvent, ProjectionType, ViewType } from './types';\n\n/**\n * Typed event bus instance for camera events.\n * Provides type-safe event emission and listening for all camera state changes.\n */\nconst cameraBus = Broadcast.getInstance<CameraEvent>();\n\ntype CameraState2D = {\n latitude: number;\n longitude: number;\n zoom: number;\n pitch: 0;\n rotation: number;\n projection: 'mercator';\n view: '2D';\n};\n\ntype CameraState3D = {\n latitude: number;\n longitude: number;\n zoom: number;\n pitch: 0;\n rotation: number;\n projection: 'globe';\n view: '3D';\n};\n\ntype CameraState2Point5D = {\n latitude: number;\n longitude: number;\n zoom: number;\n pitch: number;\n rotation: number;\n projection: 'mercator';\n view: '2.5D';\n};\n\nexport type CameraState = CameraState2D | CameraState3D | CameraState2Point5D;\n\nexport type UseCameraStateProps = {\n instanceId: UniqueId;\n initialCameraState?: Partial<CameraState>;\n subscribe?: Parameters<typeof useSyncExternalStore<CameraState>>[0];\n getSnapshot?: Parameters<typeof useSyncExternalStore<CameraState>>[1];\n getServerSnapshot?: Parameters<typeof useSyncExternalStore<CameraState>>[2];\n};\n\n/**\n * Store for camera state keyed by instanceId\n */\nconst cameraStore = new Map<UniqueId, CameraState>();\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 camera, 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, () => CameraState>();\n\n/**\n * Cache of fallback snapshots per instanceId to maintain referential stability.\n * This prevents unnecessary re-renders when no camera data exists yet.\n */\nconst fallbackCache = new Map<UniqueId, CameraState>();\n\n/*\n * Helper to build initial camera state from partial input\n */\nfunction buildInitialCameraState(\n initialCameraState?: Partial<CameraState>,\n): CameraState {\n if (!initialCameraState) {\n return {\n latitude: 0,\n longitude: 0,\n zoom: 0,\n pitch: 0,\n rotation: 0,\n projection: 'mercator',\n view: '2D',\n };\n }\n\n const is2Point5D = initialCameraState.view === '2.5D';\n const is3D =\n initialCameraState.view === '3D' ||\n initialCameraState.projection === 'globe';\n\n let projection: ProjectionType;\n let view: ViewType;\n\n if (is3D) {\n projection = 'globe';\n view = '3D';\n } else if (is2Point5D) {\n projection = 'mercator';\n view = '2.5D';\n } else {\n projection = initialCameraState.projection ?? 'mercator';\n view = initialCameraState.view ?? '2D';\n }\n\n return {\n latitude: initialCameraState.latitude ?? 0,\n longitude: initialCameraState.longitude ?? 0,\n zoom: initialCameraState.zoom ?? 0,\n pitch: is2Point5D ? (initialCameraState.pitch ?? 45) : 0,\n rotation: is3D ? 0 : (initialCameraState.rotation ?? 0),\n projection,\n view,\n } as CameraState;\n}\n\n/*\n * Get or create camera state for a given instanceId\n */\nfunction getOrCreateState(\n instanceId: UniqueId,\n initialCameraState?: Partial<CameraState>,\n): CameraState {\n if (!cameraStore.has(instanceId)) {\n cameraStore.set(instanceId, buildInitialCameraState(initialCameraState));\n }\n // biome-ignore lint/style/noNonNullAssertion: State guaranteed to exist after has() check above\n return cameraStore.get(instanceId)!;\n}\n\n/**\n * Notify all React subscribers for a given instanceId\n */\nfunction notifySubscribers(instanceId: UniqueId): void {\n const subscribers = componentSubscribers.get(instanceId);\n\n if (subscribers) {\n for (const onStoreChange of subscribers) {\n onStoreChange();\n }\n }\n}\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 camera\n * @param initialCameraState - Optional initial camera state to set when creating the listener\n */\nfunction ensureBusListener(\n instanceId: UniqueId,\n initialCameraState?: Partial<CameraState>,\n): void {\n if (busUnsubscribers.has(instanceId)) {\n return; // Already listening\n }\n\n const unsubResetCamera = cameraBus.on(\n CameraEventTypes.reset,\n ({ payload }) => {\n if (instanceId === payload.id) {\n const state = getOrCreateState(instanceId, initialCameraState);\n const newState = {\n ...buildInitialCameraState({\n ...state,\n zoom:\n payload.zoom === false ? state.zoom : initialCameraState?.zoom,\n pitch:\n payload.pitch === false ? state.pitch : initialCameraState?.pitch,\n rotation:\n payload.rotation === false\n ? state.rotation\n : initialCameraState?.rotation,\n } as Partial<CameraState>),\n };\n\n cameraStore.set(instanceId, newState);\n\n notifySubscribers(instanceId);\n }\n },\n );\n\n const unsubSetCenter = cameraBus.on(\n CameraEventTypes.setCenter,\n ({ payload }) => {\n if (instanceId === payload.id) {\n const state = getOrCreateState(instanceId, initialCameraState);\n const newState = {\n ...state,\n latitude: payload.latitude,\n longitude: payload.longitude,\n zoom: payload.zoom ?? state.zoom,\n rotation: payload.heading ?? state.rotation,\n pitch: payload.pitch ?? state.pitch,\n } as CameraState;\n cameraStore.set(instanceId, newState);\n notifySubscribers(instanceId);\n }\n },\n );\n\n const unsubFitBounds = cameraBus.on(\n CameraEventTypes.fitBounds,\n ({ payload }) => {\n if (instanceId === payload.id) {\n const state = getOrCreateState(instanceId, initialCameraState);\n const { longitude, latitude, zoom } = fitBounds({\n width: payload.width,\n height: payload.height,\n bounds: [\n [payload.bounds[0], payload.bounds[1]],\n [payload.bounds[2], payload.bounds[3]],\n ],\n padding: payload.padding,\n });\n const newState = {\n ...state,\n latitude: latitude,\n longitude: longitude,\n zoom: zoom,\n rotation: payload.heading ?? state.rotation,\n pitch: payload.pitch ?? state.pitch,\n } as CameraState;\n cameraStore.set(instanceId, newState);\n notifySubscribers(instanceId);\n }\n },\n );\n\n const unsubSetProjection = cameraBus.on(\n CameraEventTypes.setProjection,\n ({ payload }) => {\n if (instanceId === payload.id) {\n const state = getOrCreateState(instanceId, initialCameraState);\n const newState = { ...state };\n newState.projection = payload.projection;\n if (payload.projection === 'globe') {\n newState.view = '3D';\n } else {\n newState.view = '2D';\n newState.pitch = 0;\n }\n cameraStore.set(instanceId, newState);\n notifySubscribers(instanceId);\n }\n },\n );\n\n const unsubSetView = cameraBus.on(CameraEventTypes.setView, ({ payload }) => {\n if (instanceId === payload.id) {\n const state = getOrCreateState(instanceId, initialCameraState);\n const newState = { ...state };\n newState.view = payload.view;\n if (payload.view === '3D') {\n newState.projection = 'globe';\n newState.pitch = 0;\n } else {\n newState.projection = 'mercator';\n }\n\n if (payload.view === '2.5D') {\n newState.pitch = 45;\n }\n cameraStore.set(instanceId, newState);\n notifySubscribers(instanceId);\n }\n });\n\n const unsubSetZoom = cameraBus.on(CameraEventTypes.setZoom, ({ payload }) => {\n if (instanceId === payload.id) {\n const state = getOrCreateState(instanceId, initialCameraState);\n const newState = { ...state };\n newState.zoom = payload.zoom;\n cameraStore.set(instanceId, newState);\n notifySubscribers(instanceId);\n }\n });\n\n const unsubSetRotation = cameraBus.on(\n CameraEventTypes.setRotation,\n ({ payload }) => {\n const state = getOrCreateState(instanceId, initialCameraState);\n if (instanceId === payload.id && state.view !== '3D') {\n const newState = { ...state };\n newState.rotation = payload.rotation;\n cameraStore.set(instanceId, newState);\n notifySubscribers(instanceId);\n }\n },\n );\n\n const unsubSetPitch = cameraBus.on(\n CameraEventTypes.setPitch,\n ({ payload }) => {\n const state = getOrCreateState(instanceId, initialCameraState);\n if (instanceId === payload.id && state.view === '2.5D') {\n const newState = { ...state };\n newState.pitch = payload.pitch;\n cameraStore.set(instanceId, newState);\n notifySubscribers(instanceId);\n }\n },\n );\n\n busUnsubscribers.set(instanceId, () => {\n unsubResetCamera();\n unsubSetCenter();\n unsubFitBounds();\n unsubSetProjection();\n unsubSetView();\n unsubSetZoom();\n unsubSetRotation();\n unsubSetPitch();\n });\n}\n\n/**\n * Cleans up the bus listener if no React subscribers remain.\n *\n * @param instanceId - The unique identifier for the camera\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 [\n cameraStore,\n componentSubscribers,\n subscriptionCache,\n snapshotCache,\n fallbackCache,\n ].forEach((map) => {\n map.delete(instanceId);\n });\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 camera state when the last subscriber unsubscribes.\n *\n * @param instanceId - The unique identifier for the camera\n * @param initialCameraState - Optional initial camera state to set when creating the listener\n * @returns A subscription function for useSyncExternalStore\n */\nfunction getOrCreateSubscription(\n instanceId: UniqueId,\n initialCameraState?: Partial<CameraState>,\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, initialCameraState);\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 camera\n * @param initialCameraState - Initialize the snapshot with camera view information\n * @returns A snapshot function for useSyncExternalStore\n */\nfunction getOrCreateSnapshot(\n instanceId: UniqueId,\n initialCameraState?: Partial<CameraState>,\n): () => CameraState {\n // Get or create stable fallback reference for this instanceId\n const fallback =\n fallbackCache.get(instanceId) ??\n (() => {\n const newFallback: CameraState = {\n latitude: initialCameraState?.latitude ?? 0,\n longitude: initialCameraState?.longitude ?? 0,\n zoom: initialCameraState?.zoom ?? 0,\n pitch: 0,\n rotation: 0,\n projection: 'mercator',\n view: '2D',\n };\n fallbackCache.set(instanceId, newFallback);\n return newFallback;\n })();\n\n const snapshot =\n snapshotCache.get(instanceId) ??\n (() => cameraStore.get(instanceId) ?? fallback);\n\n snapshotCache.set(instanceId, snapshot);\n\n return snapshot;\n}\n\n/**\n * Updates the camera state for a given map instance and notifies subscribers.\n *\n * @param instanceId - The unique identifier for the map\n * @param state - The new state to set, will be merged with existing state\n *\n * @example\n * ```tsx\n * // Update camera state manually\n * setCameraState('my-map-instance', {\n * latitude: 37.7749,\n * longitude: -122.4194,\n * zoom: 10,\n * pitch: 30,\n * rotation: 0,\n * projection: 'mercator',\n * });\n * ```\n */\nfunction setCameraState(\n instanceId: UniqueId,\n state: Partial<CameraState>,\n): void {\n const currentState = getOrCreateState(instanceId);\n cameraStore.set(instanceId, { ...currentState, ...state } as CameraState);\n notifySubscribers(instanceId);\n}\n\n/**\n * Hook to access camera state actions.\n *\n * This hook uses `useSyncExternalStore` to subscribe to camera state changes,\n * providing concurrent-safe mode state updates. Uses a fan-out pattern where\n * a single bus listener per map instance notifies N React component subscribers.\n *\n * A thin wrapper around [useSyncExternalStore](https://react.dev/reference/react/useSyncExternalStore).\n *\n * @param instanceId - Unique identifier for the camera to track\n * @param initialCameraState - Optional initial camera state to set\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 camera state including latitude, longitude, zoom, pitch, rotation, projection\n *\n * @example\n * ```tsx\n * function MapInfo({ instanceId }) {\n * const { latitude, longitude, zoom } = useCameraState({\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 = useCameraState({\n * instanceId: 'some-uuid',\n * subscribe: customSubscribe,\n * getSnapshot: customGetSnapshot,\n * });\n *\n * return <div>Custom camera state</div>;\n * }\n * ```\n */\nexport function useCameraState({\n instanceId,\n initialCameraState,\n subscribe,\n getSnapshot,\n getServerSnapshot,\n}: UseCameraStateProps) {\n const cameraState = useSyncExternalStore<CameraState>(\n subscribe ?? getOrCreateSubscription(instanceId, initialCameraState),\n getSnapshot ?? getOrCreateSnapshot(instanceId, initialCameraState),\n getServerSnapshot,\n );\n\n return useMemo(\n () => ({\n cameraState,\n setCameraState,\n }),\n [cameraState],\n );\n}\n\n/**\n * Manually clear camera 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 camera to clear\n *\n * @example\n * ```tsx\n * // Manual cleanup (rarely needed)\n * clearCameraState('my-map-instance');\n * ```\n */\nexport function clearCameraState(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 [\n cameraStore,\n componentSubscribers,\n subscriptionCache,\n snapshotCache,\n fallbackCache,\n ].forEach((map) => {\n map.delete(instanceId);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,YAAY,UAAU,aAA0B;;;;AA6CtD,MAAM,8BAAc,IAAI,KAA4B;;;;;AAMpD,MAAM,uCAAuB,IAAI,KAAgC;;;;;;AAOjE,MAAM,mCAAmB,IAAI,KAA2B;;;;AAMxD,MAAM,oCAAoB,IAAI,KAA6B;;;;AAK3D,MAAM,gCAAgB,IAAI,KAAkC;;;;;AAM5D,MAAM,gCAAgB,IAAI,KAA4B;AAKtD,SAAS,wBACP,oBACa;AACb,KAAI,CAAC,mBACH,QAAO;EACL,UAAU;EACV,WAAW;EACX,MAAM;EACN,OAAO;EACP,UAAU;EACV,YAAY;EACZ,MAAM;EACP;CAGH,MAAM,aAAa,mBAAmB,SAAS;CAC/C,MAAM,OACJ,mBAAmB,SAAS,QAC5B,mBAAmB,eAAe;CAEpC,IAAIA;CACJ,IAAIC;AAEJ,KAAI,MAAM;AACR,eAAa;AACb,SAAO;YACE,YAAY;AACrB,eAAa;AACb,SAAO;QACF;AACL,eAAa,mBAAmB,cAAc;AAC9C,SAAO,mBAAmB,QAAQ;;AAGpC,QAAO;EACL,UAAU,mBAAmB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AAY,mBAAmB,EAClE,kBACD;AAED,QAAO,eACE;EACL;EACA;EACD,GACD,CAAC,YAAY,CACd;;;;;;;;;;;;;;;AAgBH,SAAgB,iBAAiB,YAA4B;CAE3D,MAAM,QAAQ,iBAAiB,IAAI,WAAW;AAC9C,KAAI,OAAO;AACT,SAAO;AACP,mBAAiB,OAAO,WAAW;;AAIrC;EACE;EACA;EACA;EACA;EACA;EACD,CAAC,SAAS,QAAQ;AACjB,MAAI,OAAO,WAAW;GACtB"}
@@ -1,44 +0,0 @@
1
- //#region src/deckgl/shapes/display-shape-layer/constants.d.ts
2
- /**
3
- * Map interaction constants
4
- * Values derived from ngc2 for consistency
5
- */
6
- declare const MAP_INTERACTION: {
7
- readonly LINE_WIDTH_MIN_PIXELS: 1;
8
- readonly ICON_SIZE: 38;
9
- readonly ICON_HOVER_SIZE_INCREASE: 5;
10
- };
11
- /**
12
- * Selection highlight configuration
13
- */
14
- declare const SELECTION_HIGHLIGHT: {
15
- readonly COLOR: [number, number, number, number];
16
- readonly ICON_SIZE_INCREASE: 8;
17
- };
18
- /**
19
- * Coffin corners configuration for Point selection/hover feedback
20
- * Coffin corners are bracket-like corners that appear around points
21
- */
22
- declare const COFFIN_CORNERS: {
23
- /** Icon name for hover state (white corners with background fill) */
24
- readonly HOVER_ICON: "coffin-corners-hover";
25
- /** Icon name for selected state (blue corners, no fill) */
26
- readonly SELECTED_ICON: "coffin-corners-selected";
27
- /** Icon name for selected+hover state (blue corners with background fill) */
28
- readonly SELECTED_HOVER_ICON: "coffin-corners-selected-hover";
29
- /** Size of the coffin corners icon */
30
- readonly SIZE: 38;
31
- };
32
- /**
33
- * Default props for DisplayShapeLayer
34
- */
35
- declare const DEFAULT_DISPLAY_PROPS: {
36
- pickable: boolean;
37
- showLabels: boolean;
38
- showHighlight: boolean;
39
- applyBaseOpacity: boolean;
40
- highlightColor: [number, number, number, number];
41
- };
42
- //#endregion
43
- export { COFFIN_CORNERS, DEFAULT_DISPLAY_PROPS, MAP_INTERACTION, SELECTION_HIGHLIGHT };
44
- //# sourceMappingURL=constants.d.ts.map
@@ -1,66 +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 { EditableShape } from "../shared/types.js";
14
- import { LabelPositionOptions } from "./utils/labels.js";
15
- import { TextLayer } from "@deck.gl/layers";
16
-
17
- //#region src/deckgl/shapes/display-shape-layer/shape-label-layer.d.ts
18
- /**
19
- * Props for creating a shape label layer
20
- */
21
- interface ShapeLabelLayerProps {
22
- /** Layer ID (defaults to DISPLAY_LABELS constant) */
23
- id?: string;
24
- /** Array of shapes to label */
25
- data: EditableShape[];
26
- /**
27
- * Global label positioning options
28
- * Per-shape properties in styleProperties take precedence
29
- */
30
- labelOptions?: LabelPositionOptions;
31
- }
32
- /**
33
- * Creates a TextLayer for rendering shape labels with intelligent positioning
34
- *
35
- * ## Features
36
- * - **Geometry-aware positioning**: Different defaults for Point, LineString, Polygon, and Circle
37
- * - **Three-tier priority system**: Per-shape properties > labelOptions > defaults
38
- * - **Coordinate anchoring**: Position labels at start/middle/end (or edge positions for circles)
39
- * - **Pixel-based offsets**: Consistent label placement at all zoom levels
40
- * - **Text-only styling**: White uppercase text with black outline for legibility
41
- * - **Position caching**: Label positions are computed once per shape using a WeakMap cache
42
- *
43
- * ## Label Positioning Priority
44
- * 1. Per-shape `styleProperties` (highest priority)
45
- * 2. Global `labelOptions` parameter
46
- * 3. Geometry-specific defaults (fallback)
47
- *
48
- * @param props - Shape label layer configuration
49
- * @returns Configured TextLayer instance
50
- *
51
- * @example
52
- * ```tsx
53
- * const labelLayer = createShapeLabelLayer({
54
- * id: 'my-labels',
55
- * data: shapes,
56
- * labelOptions: {
57
- * circleLabelCoordinateAnchor: 'top',
58
- * pointLabelOffset: [0, -20],
59
- * },
60
- * });
61
- * ```
62
- */
63
- declare function createShapeLabelLayer(props: ShapeLabelLayerProps): TextLayer<EditableShape>;
64
- //#endregion
65
- export { ShapeLabelLayerProps, createShapeLabelLayer };
66
- //# sourceMappingURL=shape-label-layer.d.ts.map
@@ -1,87 +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 { ShapeId } from "../shared/types.js";
14
- import { UniqueId } from "@accelint/core";
15
-
16
- //#region src/deckgl/shapes/display-shape-layer/store.d.ts
17
- /**
18
- * Creates or retrieves a cached subscription function for a given mapId.
19
- * Uses a fan-out pattern: 1 bus listener -> N React subscribers.
20
- * Automatically cleans up selection state when the last subscriber unsubscribes.
21
- *
22
- * @param mapId - The unique identifier for the map instance
23
- * @returns A subscription function for useSyncExternalStore
24
- */
25
- declare function getOrCreateSubscription(mapId: UniqueId): (onStoreChange: () => void) => () => void;
26
- /**
27
- * Creates or retrieves a cached snapshot function for a given mapId.
28
- * The selection ID returned gets equality checked, so it needs to be stable or React re-renders unnecessarily.
29
- *
30
- * @param mapId - The unique identifier for the map instance
31
- * @returns A snapshot function for useSyncExternalStore
32
- */
33
- declare function getOrCreateSnapshot(mapId: UniqueId): () => ShapeId | undefined;
34
- /**
35
- * Creates or retrieves a cached server snapshot function for a given mapId.
36
- * Server snapshots always return undefined since selection state is client-only.
37
- * Required for SSR/RSC compatibility with useSyncExternalStore.
38
- *
39
- * @param mapId - The unique identifier for the map instance
40
- * @returns A server snapshot function for useSyncExternalStore
41
- */
42
- declare function getOrCreateServerSnapshot(mapId: UniqueId): () => ShapeId | undefined;
43
- /**
44
- * Creates or retrieves a cached setSelectedId function for a given mapId.
45
- * This maintains referential stability for the function reference.
46
- *
47
- * @param mapId - The unique identifier for the map instance
48
- * @returns A setSelectedId function for this instance
49
- */
50
- declare function getOrCreateSetSelectedId(mapId: UniqueId): (id: ShapeId | undefined) => void;
51
- /**
52
- * Creates or retrieves a cached clearSelection function for a given mapId.
53
- * This maintains referential stability for the function reference.
54
- *
55
- * Note: This always emits a deselected event, even if nothing is currently selected.
56
- * This matches the original behavior and allows consumers to use clearSelection
57
- * as a "force deselect" without needing to check selection state first.
58
- *
59
- * @param mapId - The unique identifier for the map instance
60
- * @returns A clearSelection function for this instance
61
- */
62
- declare function getOrCreateClearSelection(mapId: UniqueId): () => void;
63
- /**
64
- * Get the current selected shape ID for a given map instance (direct access, not reactive).
65
- * @internal - For internal map-toolkit use only
66
- *
67
- * @param mapId - The unique identifier for the map instance
68
- * @returns The currently selected shape ID, or undefined
69
- */
70
- declare function getSelectedShapeId(mapId: UniqueId): ShapeId | undefined;
71
- /**
72
- * Manually clear all selection state for a specific mapId.
73
- * This is typically not needed as cleanup happens automatically when all subscribers unmount.
74
- * Use this only in advanced scenarios where manual cleanup is required.
75
- *
76
- * @param mapId - The unique identifier for the map instance to clear
77
- *
78
- * @example
79
- * ```tsx
80
- * // Manual cleanup (rarely needed)
81
- * clearSelectionState('my-map-instance');
82
- * ```
83
- */
84
- declare function clearSelectionState(mapId: UniqueId): void;
85
- //#endregion
86
- export { clearSelectionState, getOrCreateClearSelection, getOrCreateServerSnapshot, getOrCreateSetSelectedId, getOrCreateSnapshot, getOrCreateSubscription, getSelectedShapeId };
87
- //# sourceMappingURL=store.d.ts.map