@accelint/map-toolkit 0.3.1 → 0.4.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 +13 -0
- package/catalog-info.yaml +5 -5
- package/dist/cursor-coordinates/index.d.ts +14 -3
- package/dist/cursor-coordinates/index.js +16 -3
- package/dist/cursor-coordinates/use-cursor-coordinates.d.ts +20 -6
- package/dist/cursor-coordinates/use-cursor-coordinates.js +247 -128
- package/dist/cursor-coordinates/use-cursor-coordinates.js.map +1 -1
- package/dist/deckgl/base-map/constants.d.ts +14 -12
- package/dist/deckgl/base-map/constants.js +26 -12
- package/dist/deckgl/base-map/constants.js.map +1 -1
- package/dist/deckgl/base-map/events.d.ts +6 -4
- package/dist/deckgl/base-map/events.js +18 -4
- package/dist/deckgl/base-map/events.js.map +1 -1
- package/dist/deckgl/base-map/index.d.ts +45 -18
- package/dist/deckgl/base-map/index.js +216 -148
- package/dist/deckgl/base-map/index.js.map +1 -1
- package/dist/deckgl/base-map/provider.d.ts +48 -32
- package/dist/deckgl/base-map/provider.js +122 -11
- package/dist/deckgl/base-map/provider.js.map +1 -1
- package/dist/deckgl/base-map/types.d.ts +49 -39
- package/dist/deckgl/base-map/types.js +11 -2
- package/dist/deckgl/index.d.ts +18 -13
- package/dist/deckgl/index.js +19 -6
- package/dist/deckgl/symbol-layer/fiber.d.ts +21 -10
- package/dist/deckgl/symbol-layer/fiber.js +18 -3
- package/dist/deckgl/symbol-layer/fiber.js.map +1 -1
- package/dist/deckgl/symbol-layer/index.d.ts +68 -54
- package/dist/deckgl/symbol-layer/index.js +105 -85
- package/dist/deckgl/symbol-layer/index.js.map +1 -1
- package/dist/deckgl/text-layer/character-sets.d.ts +19 -17
- package/dist/deckgl/text-layer/character-sets.js +40 -19
- package/dist/deckgl/text-layer/character-sets.js.map +1 -1
- package/dist/deckgl/text-layer/default-settings.d.ts +16 -2
- package/dist/deckgl/text-layer/default-settings.js +42 -18
- package/dist/deckgl/text-layer/default-settings.js.map +1 -1
- package/dist/deckgl/text-layer/fiber.d.ts +38 -27
- package/dist/deckgl/text-layer/fiber.js +18 -3
- package/dist/deckgl/text-layer/fiber.js.map +1 -1
- package/dist/deckgl/text-layer/index.d.ts +39 -25
- package/dist/deckgl/text-layer/index.js +47 -29
- package/dist/deckgl/text-layer/index.js.map +1 -1
- package/dist/decorators/deckgl.d.ts +16 -2
- package/dist/decorators/deckgl.js +25 -7
- package/dist/decorators/deckgl.js.map +1 -1
- package/dist/map-cursor/events.d.ts +16 -0
- package/dist/map-cursor/events.js +27 -0
- package/dist/map-cursor/events.js.map +1 -0
- package/dist/map-cursor/index.d.ts +17 -0
- package/dist/map-cursor/index.js +18 -0
- package/dist/map-cursor/store.d.ts +93 -0
- package/dist/map-cursor/store.js +351 -0
- package/dist/map-cursor/store.js.map +1 -0
- package/dist/map-cursor/types.d.ts +81 -0
- package/dist/map-cursor/types.js +12 -0
- package/dist/map-cursor/use-map-cursor.d.ts +99 -0
- package/dist/map-cursor/use-map-cursor.js +116 -0
- package/dist/map-cursor/use-map-cursor.js.map +1 -0
- package/dist/map-mode/events.d.ts +11 -9
- package/dist/map-mode/events.js +43 -9
- package/dist/map-mode/events.js.map +1 -1
- package/dist/map-mode/index.d.ts +17 -6
- package/dist/map-mode/index.js +18 -5
- package/dist/map-mode/store.d.ts +26 -3
- package/dist/map-mode/store.js +329 -265
- package/dist/map-mode/store.js.map +1 -1
- package/dist/map-mode/types.d.ts +49 -35
- package/dist/map-mode/types.js +11 -2
- package/dist/map-mode/use-map-mode.d.ts +21 -7
- package/dist/map-mode/use-map-mode.js +66 -23
- package/dist/map-mode/use-map-mode.js.map +1 -1
- package/dist/maplibre/constants.d.ts +10 -8
- package/dist/maplibre/constants.js +22 -8
- package/dist/maplibre/constants.js.map +1 -1
- package/dist/maplibre/hooks/use-maplibre.d.ts +17 -2
- package/dist/maplibre/hooks/use-maplibre.js +77 -31
- package/dist/maplibre/hooks/use-maplibre.js.map +1 -1
- package/dist/maplibre/index.d.ts +15 -3
- package/dist/maplibre/index.js +17 -4
- package/dist/viewport/constants.d.ts +8 -6
- package/dist/viewport/constants.js +20 -6
- package/dist/viewport/constants.js.map +1 -1
- package/dist/viewport/index.d.ts +18 -13
- package/dist/viewport/index.js +19 -6
- package/dist/viewport/types.d.ts +27 -17
- package/dist/viewport/types.js +11 -2
- package/dist/viewport/use-viewport-state.d.ts +29 -14
- package/dist/viewport/use-viewport-state.js +200 -87
- package/dist/viewport/use-viewport-state.js.map +1 -1
- package/dist/viewport/utils.d.ts +25 -10
- package/dist/viewport/utils.js +67 -37
- package/dist/viewport/utils.js.map +1 -1
- package/dist/viewport/viewport-size.d.ts +27 -15
- package/dist/viewport/viewport-size.js +54 -11
- package/dist/viewport/viewport-size.js.map +1 -1
- package/package.json +55 -28
- package/dist/cursor-coordinates/index.js.map +0 -1
- package/dist/deckgl/base-map/types.js.map +0 -1
- package/dist/deckgl/index.js.map +0 -1
- package/dist/map-mode/index.js.map +0 -1
- package/dist/map-mode/types.js.map +0 -1
- package/dist/maplibre/index.js.map +0 -1
- package/dist/metafile-esm.json +0 -1
- package/dist/viewport/index.js.map +0 -1
- package/dist/viewport/types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/map-mode/store.ts"],"names":[],"mappings":";;;;AAkBA,MAAM,YAAA,GAAe,SAAA;AAMrB,MAAM,UAAA,GAAa,UAAU,WAAA,EAA8B;AAyB3D,MAAM,SAAA,uBAAgB,GAAA,EAA4B;AAMlD,MAAM,oBAAA,uBAA2B,GAAA,EAA+B;AAOhE,MAAM,gBAAA,uBAAuB,GAAA,EAA0B;AAMvD,MAAM,iBAAA,uBAAwB,GAAA,EAA4B;AAK1D,MAAM,aAAA,uBAAoB,GAAA,EAA4B;AAKtD,MAAM,sBAAA,uBAA6B,GAAA,EAGjC;AAKF,SAAS,iBAAiB,UAAA,EAAoC;AAC5D,EAAA,IAAI,CAAC,SAAA,CA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AA,CAAiB,GAAA,CAAI,UAAU,CAAA;AAC7C,EAAA,IAAI,KAAA,EAAO;AACT,IAAA,KAAA,EAAM;AACN,IAAA,gBAAA,CAAiB,OAAO,UAAU,CAAA;AAAA,EACpC;AAGA,EAAA,SAAA,CAAU,OAAO,UAAU,CAAA;AAC3B,EAAA,oBAAA,CAAqB,OAAO,UAAU,CAAA;AACtC,EAAA,iBAAA,CAAkB,OAAO,UAAU,CAAA;AACnC,EAAA,aAAA,CAAc,OAAO,UAAU,CAAA;AAC/B,EAAA,sBAAA,CAAuB,OAAO,UAAU,CAAA;AAC1C","file":"store.js","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 { uuid } from '@accelint/core';\nimport { MapModeEvents } from './events';\nimport type { UniqueId } from '@accelint/core';\nimport type { MapModeEventType, ModeChangeDecisionPayload } from './types';\n\nconst DEFAULT_MODE = 'default';\n\n/**\n * Typed event bus instance for map mode events.\n * Provides type-safe event emission and listening for all map mode state changes.\n */\nconst mapModeBus = Broadcast.getInstance<MapModeEventType>();\n\n/**\n * Internal type for tracking pending authorization requests.\n * @internal\n */\ntype PendingRequest = {\n authId: string;\n desiredMode: string;\n currentMode: string;\n requestOwner: string;\n};\n\n/**\n * Type representing the state for a single map mode instance\n */\ntype MapModeState = {\n mode: string;\n modeOwners: Map<string, string>;\n pendingRequests: Map<string, PendingRequest>;\n};\n\n/**\n * Store for map mode state keyed by instanceId\n */\nconst modeStore = new Map<UniqueId, MapModeState>();\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 map mode instance, 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, () => string>();\n\n/**\n * Cache of requestModeChange functions per instanceId to maintain referential stability\n */\nconst requestModeChangeCache = new Map<\n UniqueId,\n (desiredMode: string, requestOwner: string) => void\n>();\n\n/**\n * Get or create mode state for a given instanceId\n */\nfunction getOrCreateState(instanceId: UniqueId): MapModeState {\n if (!modeStore.has(instanceId)) {\n modeStore.set(instanceId, {\n mode: DEFAULT_MODE,\n modeOwners: new Map(),\n pendingRequests: new Map(),\n });\n }\n // biome-ignore lint/style/noNonNullAssertion: State guaranteed to exist after has() check above\n return modeStore.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 if (subscribers) {\n for (const onStoreChange of subscribers) {\n onStoreChange();\n }\n }\n}\n\n/**\n * Determine if a mode change request should be auto-accepted without authorization\n */\nfunction shouldAutoAcceptRequest(\n state: MapModeState,\n desiredMode: string,\n requestOwner: string,\n): boolean {\n const currentModeOwner = state.modeOwners.get(state.mode);\n const desiredModeOwner = state.modeOwners.get(desiredMode);\n\n // Owner returning to default mode\n if (desiredMode === DEFAULT_MODE && requestOwner === currentModeOwner) {\n return true;\n }\n\n // Owner switching between their own modes\n if (requestOwner === currentModeOwner) {\n return true;\n }\n\n // No ownership conflicts exist\n if (!(currentModeOwner || desiredModeOwner)) {\n return true;\n }\n\n // Entering an owned mode from default mode\n if (state.mode === DEFAULT_MODE && requestOwner === desiredModeOwner) {\n return true;\n }\n\n return false;\n}\n\n/**\n * Set mode and emit change event\n */\nfunction setMode(\n instanceId: UniqueId,\n state: MapModeState,\n newMode: string,\n): void {\n const previousMode = state.mode;\n state.mode = newMode;\n\n mapModeBus.emit(MapModeEvents.changed, {\n previousMode,\n currentMode: newMode,\n id: instanceId,\n });\n\n notifySubscribers(instanceId);\n}\n\n/**\n * Approve a request and reject all others\n */\nfunction approveRequestAndRejectOthers(\n instanceId: UniqueId,\n state: MapModeState,\n approvedRequest: PendingRequest,\n excludeAuthId: string,\n decisionOwner: string,\n reason: string,\n emitApproval: boolean,\n): void {\n // Collect all other pending requests to emit rejections for\n const requestsToReject: PendingRequest[] = [];\n for (const request of state.pendingRequests.values()) {\n if (request.authId !== excludeAuthId) {\n requestsToReject.push(request);\n }\n }\n\n // Clear all pending requests BEFORE changing mode\n state.pendingRequests.clear();\n\n // Change mode\n setMode(instanceId, state, approvedRequest.desiredMode);\n\n // Store the new mode's owner (unless it's default mode)\n if (approvedRequest.desiredMode !== DEFAULT_MODE) {\n state.modeOwners.set(\n approvedRequest.desiredMode,\n approvedRequest.requestOwner,\n );\n }\n\n // Emit approval decision if requested\n if (emitApproval) {\n mapModeBus.emit(MapModeEvents.changeDecision, {\n authId: approvedRequest.authId,\n approved: true,\n owner: decisionOwner,\n reason,\n id: instanceId,\n });\n }\n\n // Emit rejection events for all other pending requests\n for (const request of requestsToReject) {\n mapModeBus.emit(MapModeEvents.changeDecision, {\n authId: request.authId,\n approved: false,\n owner: decisionOwner,\n reason: 'Request auto-rejected because another request was approved',\n id: instanceId,\n });\n }\n}\n\n/**\n * Handle pending requests when returning to default mode\n */\nfunction handlePendingRequestsOnDefaultMode(\n instanceId: UniqueId,\n state: MapModeState,\n previousMode: string,\n): void {\n const firstEntry = Array.from(state.pendingRequests.values())[0];\n if (!firstEntry) {\n return;\n }\n\n const previousModeOwner = state.modeOwners.get(previousMode);\n\n if (!previousModeOwner) {\n return;\n }\n\n // If the first pending request is for default mode, reject all requests\n if (firstEntry.desiredMode === DEFAULT_MODE) {\n const allRequests = Array.from(state.pendingRequests.values());\n state.pendingRequests.clear();\n\n for (const request of allRequests) {\n mapModeBus.emit(MapModeEvents.changeDecision, {\n authId: request.authId,\n approved: false,\n owner: previousModeOwner,\n reason: 'Request rejected - already in requested mode',\n id: instanceId,\n } satisfies ModeChangeDecisionPayload);\n }\n } else {\n // Auto-accept the first pending request for a different mode\n approveRequestAndRejectOthers(\n instanceId,\n state,\n firstEntry,\n firstEntry.authId,\n previousModeOwner,\n 'Auto-accepted when mode owner returned to default',\n true,\n );\n }\n}\n\n/**\n * Handle authorization decision\n *\n * Processes approval/rejection decisions from mode owners. Only the current mode's owner\n * can make authorization decisions. If a decision comes from a non-owner, a warning is\n * logged and the decision is ignored to prevent unauthorized mode changes.\n *\n * @param instanceId - The unique identifier for this map instance\n * @param state - The mode state for this instance\n * @param payload - The authorization decision containing authId, approved status, and owner\n */\nfunction handleAuthorizationDecision(\n instanceId: UniqueId,\n state: MapModeState,\n payload: {\n approved: boolean;\n authId: string;\n owner: string;\n },\n): void {\n const { approved, authId, owner: decisionOwner } = payload;\n\n // Verify decision is from current mode's owner\n // Logs a warning if unauthorized component attempts to make decisions\n const currentModeOwner = state.modeOwners.get(state.mode);\n if (decisionOwner !== currentModeOwner) {\n console.warn(\n `[MapMode] Authorization decision from \"${decisionOwner}\" ignored - not the owner of mode \"${state.mode}\" (owner: ${currentModeOwner || 'none'})`,\n );\n return;\n }\n\n // Find the request with matching authId\n let matchingRequestOwner: string | null = null;\n let matchingRequest: PendingRequest | null = null;\n\n for (const [requestOwner, request] of state.pendingRequests.entries()) {\n if (request.authId === authId) {\n matchingRequestOwner = requestOwner;\n matchingRequest = request;\n break;\n }\n }\n\n if (!(matchingRequest && matchingRequestOwner)) {\n return;\n }\n\n if (approved) {\n approveRequestAndRejectOthers(\n instanceId,\n state,\n matchingRequest,\n authId,\n decisionOwner,\n '',\n false,\n );\n } else {\n state.pendingRequests.delete(matchingRequestOwner);\n }\n}\n\n/**\n * Handle mode change request logic\n */\nfunction handleModeChangeRequest(\n instanceId: UniqueId,\n state: MapModeState,\n desiredMode: string,\n requestOwner: string,\n): void {\n const desiredModeOwner = state.modeOwners.get(desiredMode);\n\n // Check if this request should be auto-accepted\n if (shouldAutoAcceptRequest(state, desiredMode, requestOwner)) {\n setMode(instanceId, state, desiredMode);\n\n // Store the desired mode's owner unless it's default\n if (desiredMode !== DEFAULT_MODE && !desiredModeOwner) {\n state.modeOwners.set(desiredMode, requestOwner);\n }\n\n // Clear requester's pending request since mode changed successfully\n state.pendingRequests.delete(requestOwner);\n return;\n }\n\n // Otherwise, send authorization request\n const authId = uuid();\n\n state.pendingRequests.set(requestOwner, {\n authId,\n desiredMode,\n currentMode: state.mode,\n requestOwner,\n });\n\n mapModeBus.emit(MapModeEvents.changeAuthorization, {\n authId,\n desiredMode,\n currentMode: state.mode,\n id: instanceId,\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 events fire.\n * This prevents creating N bus listeners for N React components.\n *\n * @param instanceId - The unique identifier for the map mode instance\n */\nfunction ensureBusListener(instanceId: UniqueId): void {\n if (busUnsubscribers.has(instanceId)) {\n return; // Already listening\n }\n\n const state = getOrCreateState(instanceId);\n\n // Listen for mode change requests\n const unsubRequest = mapModeBus.on(MapModeEvents.changeRequest, (event) => {\n const { desiredMode, owner: requestOwner, id } = event.payload;\n\n // Filter: only handle if targeted at this map\n if (id !== instanceId || desiredMode === state.mode) {\n return;\n }\n\n handleModeChangeRequest(instanceId, state, desiredMode, requestOwner);\n });\n\n // Listen for authorization decisions\n const unsubDecision = mapModeBus.on(MapModeEvents.changeDecision, (event) => {\n const { id, approved, authId, owner } = event.payload;\n\n // Filter: only handle if targeted at this map\n if (id !== instanceId) {\n return;\n }\n\n handleAuthorizationDecision(instanceId, state, { approved, authId, owner });\n });\n\n // Listen for mode changes to handle pending requests\n const unsubChanged = mapModeBus.on(MapModeEvents.changed, (event) => {\n const { currentMode, previousMode, id } = event.payload;\n\n // Filter: only handle if targeted at this map\n if (id !== instanceId) {\n return;\n }\n\n // When mode owner changes to default mode, handle pending requests\n if (currentMode === DEFAULT_MODE && state.pendingRequests.size > 0) {\n handlePendingRequestsOnDefaultMode(instanceId, state, previousMode);\n }\n });\n\n // Store composite cleanup function\n busUnsubscribers.set(instanceId, () => {\n unsubRequest();\n unsubDecision();\n unsubChanged();\n });\n}\n\n/**\n * Cleans up the bus listener if no React subscribers remain.\n *\n * @param instanceId - The unique identifier for the map mode instance\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 modeStore.delete(instanceId);\n componentSubscribers.delete(instanceId);\n subscriptionCache.delete(instanceId);\n snapshotCache.delete(instanceId);\n requestModeChangeCache.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 map mode state when the last subscriber unsubscribes.\n *\n * @param instanceId - The unique identifier for the map mode instance\n * @returns A subscription function for useSyncExternalStore\n */\nexport function getOrCreateSubscription(\n instanceId: UniqueId,\n): (onStoreChange: () => void) => () => void {\n const subscription =\n subscriptionCache.get(instanceId) ??\n ((onStoreChange: () => void) => {\n // Ensure state exists\n getOrCreateState(instanceId);\n\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 string returned gets equality checked, so it needs to be stable or React re-renders unnecessarily.\n *\n * @param instanceId - The unique identifier for the map mode instance\n * @returns A snapshot function for useSyncExternalStore\n */\nexport function getOrCreateSnapshot(instanceId: UniqueId): () => string {\n const snapshot =\n snapshotCache.get(instanceId) ??\n (() => {\n const state = modeStore.get(instanceId);\n if (!state) {\n return DEFAULT_MODE;\n }\n return state.mode;\n });\n\n snapshotCache.set(instanceId, snapshot);\n\n return snapshot;\n}\n\n/**\n * Creates or retrieves a cached requestModeChange function for a given instanceId.\n * This maintains referential stability for the function reference.\n *\n * @param instanceId - The unique identifier for the map mode instance\n * @returns A requestModeChange function for this instance\n */\nexport function getOrCreateRequestModeChange(\n instanceId: UniqueId,\n): (desiredMode: string, requestOwner: string) => void {\n const requestModeChange =\n requestModeChangeCache.get(instanceId) ??\n ((desiredMode: string, requestOwner: string) => {\n const trimmedDesiredMode = desiredMode.trim();\n const trimmedRequestOwner = requestOwner.trim();\n\n if (!trimmedDesiredMode) {\n throw new Error('requestModeChange requires non-empty desiredMode');\n }\n if (!trimmedRequestOwner) {\n throw new Error('requestModeChange requires non-empty requestOwner');\n }\n\n mapModeBus.emit(MapModeEvents.changeRequest, {\n desiredMode: trimmedDesiredMode,\n owner: trimmedRequestOwner,\n id: instanceId,\n });\n });\n\n requestModeChangeCache.set(instanceId, requestModeChange);\n\n return requestModeChange;\n}\n\n/**\n * Get the owner of the current mode for a given map instance\n * @internal - For internal map-toolkit use only\n */\nexport function getCurrentModeOwner(instanceId: UniqueId): string | undefined {\n const state = modeStore.get(instanceId);\n if (!state) {\n return undefined;\n }\n return state.modeOwners.get(state.mode);\n}\n\n/**\n * Manually clear map mode 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 map mode instance to clear\n *\n * @example\n * ```tsx\n * // Manual cleanup (rarely needed)\n * clearMapModeState('my-map-instance');\n * ```\n */\nexport function clearMapModeState(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 modeStore.delete(instanceId);\n componentSubscribers.delete(instanceId);\n subscriptionCache.delete(instanceId);\n snapshotCache.delete(instanceId);\n requestModeChangeCache.delete(instanceId);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"store.js","names":["requestsToReject: PendingRequest[]","matchingRequestOwner: string | null","matchingRequest: PendingRequest | null"],"sources":["../../src/map-mode/store.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 { uuid } from '@accelint/core';\nimport { MapModeEvents } from './events';\nimport type { UniqueId } from '@accelint/core';\nimport type { MapModeEventType, ModeChangeDecisionPayload } from './types';\n\nconst DEFAULT_MODE = 'default';\n\n/**\n * Typed event bus instance for map mode events.\n * Provides type-safe event emission and listening for all map mode state changes.\n */\nconst mapModeBus = Broadcast.getInstance<MapModeEventType>();\n\n/**\n * Internal type for tracking pending authorization requests.\n * @internal\n */\ntype PendingRequest = {\n authId: string;\n desiredMode: string;\n currentMode: string;\n requestOwner: string;\n};\n\n/**\n * Type representing the state for a single map mode instance\n */\ntype MapModeState = {\n mode: string;\n modeOwners: Map<string, string>;\n pendingRequests: Map<string, PendingRequest>;\n};\n\n/**\n * Store for map mode state keyed by instanceId\n */\nconst modeStore = new Map<UniqueId, MapModeState>();\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 map mode instance, 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, () => string>();\n\n/**\n * Cache of server snapshot functions per instanceId to maintain referential stability.\n * Server snapshots always return default mode since mode state is client-only.\n */\nconst serverSnapshotCache = new Map<UniqueId, () => string>();\n\n/**\n * Cache of requestModeChange functions per instanceId to maintain referential stability\n */\nconst requestModeChangeCache = new Map<\n UniqueId,\n (desiredMode: string, requestOwner: string) => void\n>();\n\n/**\n * Get or create mode state for a given instanceId\n */\nfunction getOrCreateState(instanceId: UniqueId): MapModeState {\n if (!modeStore.has(instanceId)) {\n modeStore.set(instanceId, {\n mode: DEFAULT_MODE,\n modeOwners: new Map(),\n pendingRequests: new Map(),\n });\n }\n // biome-ignore lint/style/noNonNullAssertion: State guaranteed to exist after has() check above\n return modeStore.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 if (subscribers) {\n for (const onStoreChange of subscribers) {\n onStoreChange();\n }\n }\n}\n\n/**\n * Determine if a mode change request should be auto-accepted without authorization\n */\nfunction shouldAutoAcceptRequest(\n state: MapModeState,\n desiredMode: string,\n requestOwner: string,\n): boolean {\n const currentModeOwner = state.modeOwners.get(state.mode);\n const desiredModeOwner = state.modeOwners.get(desiredMode);\n\n // Owner returning to default mode\n if (desiredMode === DEFAULT_MODE && requestOwner === currentModeOwner) {\n return true;\n }\n\n // Owner switching between their own modes\n if (requestOwner === currentModeOwner) {\n return true;\n }\n\n // No ownership conflicts exist\n if (!(currentModeOwner || desiredModeOwner)) {\n return true;\n }\n\n // Entering an owned mode from default mode\n if (state.mode === DEFAULT_MODE && requestOwner === desiredModeOwner) {\n return true;\n }\n\n return false;\n}\n\n/**\n * Set mode and emit change event\n */\nfunction setMode(\n instanceId: UniqueId,\n state: MapModeState,\n newMode: string,\n): void {\n const previousMode = state.mode;\n state.mode = newMode;\n\n mapModeBus.emit(MapModeEvents.changed, {\n previousMode,\n currentMode: newMode,\n id: instanceId,\n });\n\n notifySubscribers(instanceId);\n}\n\n/**\n * Approve a request and reject all others\n */\nfunction approveRequestAndRejectOthers(\n instanceId: UniqueId,\n state: MapModeState,\n approvedRequest: PendingRequest,\n excludeAuthId: string,\n decisionOwner: string,\n reason: string,\n emitApproval: boolean,\n): void {\n // Collect all other pending requests to emit rejections for\n const requestsToReject: PendingRequest[] = [];\n for (const request of state.pendingRequests.values()) {\n if (request.authId !== excludeAuthId) {\n requestsToReject.push(request);\n }\n }\n\n // Clear all pending requests BEFORE changing mode\n state.pendingRequests.clear();\n\n // Change mode\n setMode(instanceId, state, approvedRequest.desiredMode);\n\n // Store the new mode's owner (unless it's default mode)\n if (approvedRequest.desiredMode !== DEFAULT_MODE) {\n state.modeOwners.set(\n approvedRequest.desiredMode,\n approvedRequest.requestOwner,\n );\n }\n\n // Emit approval decision if requested\n if (emitApproval) {\n mapModeBus.emit(MapModeEvents.changeDecision, {\n authId: approvedRequest.authId,\n approved: true,\n owner: decisionOwner,\n reason,\n id: instanceId,\n });\n }\n\n // Emit rejection events for all other pending requests\n for (const request of requestsToReject) {\n mapModeBus.emit(MapModeEvents.changeDecision, {\n authId: request.authId,\n approved: false,\n owner: decisionOwner,\n reason: 'Request auto-rejected because another request was approved',\n id: instanceId,\n });\n }\n}\n\n/**\n * Handle pending requests when returning to default mode\n */\nfunction handlePendingRequestsOnDefaultMode(\n instanceId: UniqueId,\n state: MapModeState,\n previousMode: string,\n): void {\n const firstEntry = Array.from(state.pendingRequests.values())[0];\n if (!firstEntry) {\n return;\n }\n\n const previousModeOwner = state.modeOwners.get(previousMode);\n\n if (!previousModeOwner) {\n return;\n }\n\n // If the first pending request is for default mode, reject all requests\n if (firstEntry.desiredMode === DEFAULT_MODE) {\n const allRequests = Array.from(state.pendingRequests.values());\n state.pendingRequests.clear();\n\n for (const request of allRequests) {\n mapModeBus.emit(MapModeEvents.changeDecision, {\n authId: request.authId,\n approved: false,\n owner: previousModeOwner,\n reason: 'Request rejected - already in requested mode',\n id: instanceId,\n } satisfies ModeChangeDecisionPayload);\n }\n } else {\n // Auto-accept the first pending request for a different mode\n approveRequestAndRejectOthers(\n instanceId,\n state,\n firstEntry,\n firstEntry.authId,\n previousModeOwner,\n 'Auto-accepted when mode owner returned to default',\n true,\n );\n }\n}\n\n/**\n * Handle authorization decision\n *\n * Processes approval/rejection decisions from mode owners. Only the current mode's owner\n * can make authorization decisions. If a decision comes from a non-owner, a warning is\n * logged and the decision is ignored to prevent unauthorized mode changes.\n *\n * @param instanceId - The unique identifier for this map instance\n * @param state - The mode state for this instance\n * @param payload - The authorization decision containing authId, approved status, and owner\n */\nfunction handleAuthorizationDecision(\n instanceId: UniqueId,\n state: MapModeState,\n payload: {\n approved: boolean;\n authId: string;\n owner: string;\n },\n): void {\n const { approved, authId, owner: decisionOwner } = payload;\n\n // Verify decision is from current mode's owner\n // Logs a warning if unauthorized component attempts to make decisions\n const currentModeOwner = state.modeOwners.get(state.mode);\n if (decisionOwner !== currentModeOwner) {\n console.warn(\n `[MapMode] Authorization decision from \"${decisionOwner}\" ignored - not the owner of mode \"${state.mode}\" (owner: ${currentModeOwner || 'none'})`,\n );\n return;\n }\n\n // Find the request with matching authId\n let matchingRequestOwner: string | null = null;\n let matchingRequest: PendingRequest | null = null;\n\n for (const [requestOwner, request] of state.pendingRequests.entries()) {\n if (request.authId === authId) {\n matchingRequestOwner = requestOwner;\n matchingRequest = request;\n break;\n }\n }\n\n if (!(matchingRequest && matchingRequestOwner)) {\n return;\n }\n\n if (approved) {\n approveRequestAndRejectOthers(\n instanceId,\n state,\n matchingRequest,\n authId,\n decisionOwner,\n '',\n false,\n );\n } else {\n state.pendingRequests.delete(matchingRequestOwner);\n }\n}\n\n/**\n * Handle mode change request logic\n */\nfunction handleModeChangeRequest(\n instanceId: UniqueId,\n state: MapModeState,\n desiredMode: string,\n requestOwner: string,\n): void {\n const desiredModeOwner = state.modeOwners.get(desiredMode);\n\n // Check if this request should be auto-accepted\n if (shouldAutoAcceptRequest(state, desiredMode, requestOwner)) {\n setMode(instanceId, state, desiredMode);\n\n // Store the desired mode's owner unless it's default\n if (desiredMode !== DEFAULT_MODE && !desiredModeOwner) {\n state.modeOwners.set(desiredMode, requestOwner);\n }\n\n // Clear requester's pending request since mode changed successfully\n state.pendingRequests.delete(requestOwner);\n return;\n }\n\n // Otherwise, send authorization request\n const authId = uuid();\n\n state.pendingRequests.set(requestOwner, {\n authId,\n desiredMode,\n currentMode: state.mode,\n requestOwner,\n });\n\n mapModeBus.emit(MapModeEvents.changeAuthorization, {\n authId,\n desiredMode,\n currentMode: state.mode,\n id: instanceId,\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 events fire.\n * This prevents creating N bus listeners for N React components.\n *\n * @param instanceId - The unique identifier for the map mode instance\n */\nfunction ensureBusListener(instanceId: UniqueId): void {\n if (busUnsubscribers.has(instanceId)) {\n return; // Already listening\n }\n\n const state = getOrCreateState(instanceId);\n\n // Listen for mode change requests\n const unsubRequest = mapModeBus.on(MapModeEvents.changeRequest, (event) => {\n const { desiredMode, owner: requestOwner, id } = event.payload;\n\n // Filter: only handle if targeted at this map\n if (id !== instanceId || desiredMode === state.mode) {\n return;\n }\n\n handleModeChangeRequest(instanceId, state, desiredMode, requestOwner);\n });\n\n // Listen for authorization decisions\n const unsubDecision = mapModeBus.on(MapModeEvents.changeDecision, (event) => {\n const { id, approved, authId, owner } = event.payload;\n\n // Filter: only handle if targeted at this map\n if (id !== instanceId) {\n return;\n }\n\n handleAuthorizationDecision(instanceId, state, { approved, authId, owner });\n });\n\n // Listen for mode changes to handle pending requests\n const unsubChanged = mapModeBus.on(MapModeEvents.changed, (event) => {\n const { currentMode, previousMode, id } = event.payload;\n\n // Filter: only handle if targeted at this map\n if (id !== instanceId) {\n return;\n }\n\n // When mode owner changes to default mode, handle pending requests\n if (currentMode === DEFAULT_MODE && state.pendingRequests.size > 0) {\n handlePendingRequestsOnDefaultMode(instanceId, state, previousMode);\n }\n });\n\n // Store composite cleanup function\n busUnsubscribers.set(instanceId, () => {\n unsubRequest();\n unsubDecision();\n unsubChanged();\n });\n}\n\n/**\n * Cleans up the bus listener if no React subscribers remain.\n *\n * @param instanceId - The unique identifier for the map mode instance\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 modeStore.delete(instanceId);\n componentSubscribers.delete(instanceId);\n subscriptionCache.delete(instanceId);\n snapshotCache.delete(instanceId);\n serverSnapshotCache.delete(instanceId);\n requestModeChangeCache.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 map mode state when the last subscriber unsubscribes.\n *\n * @param instanceId - The unique identifier for the map mode instance\n * @returns A subscription function for useSyncExternalStore\n */\nexport function getOrCreateSubscription(\n instanceId: UniqueId,\n): (onStoreChange: () => void) => () => void {\n const subscription =\n subscriptionCache.get(instanceId) ??\n ((onStoreChange: () => void) => {\n // Ensure state exists\n getOrCreateState(instanceId);\n\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 string returned gets equality checked, so it needs to be stable or React re-renders unnecessarily.\n *\n * @param instanceId - The unique identifier for the map mode instance\n * @returns A snapshot function for useSyncExternalStore\n */\nexport function getOrCreateSnapshot(instanceId: UniqueId): () => string {\n const snapshot =\n snapshotCache.get(instanceId) ??\n (() => {\n const state = modeStore.get(instanceId);\n if (!state) {\n return DEFAULT_MODE;\n }\n return state.mode;\n });\n\n snapshotCache.set(instanceId, snapshot);\n\n return snapshot;\n}\n\n/**\n * Creates or retrieves a cached server snapshot function for a given instanceId.\n * Server snapshots always return the default mode since mode state is client-only.\n * Required for SSR/RSC compatibility with useSyncExternalStore.\n *\n * @param instanceId - The unique identifier for the map mode instance\n * @returns A server snapshot function for useSyncExternalStore\n */\nexport function getOrCreateServerSnapshot(instanceId: UniqueId): () => string {\n const serverSnapshot =\n serverSnapshotCache.get(instanceId) ?? (() => DEFAULT_MODE);\n\n serverSnapshotCache.set(instanceId, serverSnapshot);\n\n return serverSnapshot;\n}\n\n/**\n * Creates or retrieves a cached requestModeChange function for a given instanceId.\n * This maintains referential stability for the function reference.\n *\n * @param instanceId - The unique identifier for the map mode instance\n * @returns A requestModeChange function for this instance\n */\nexport function getOrCreateRequestModeChange(\n instanceId: UniqueId,\n): (desiredMode: string, requestOwner: string) => void {\n const requestModeChange =\n requestModeChangeCache.get(instanceId) ??\n ((desiredMode: string, requestOwner: string) => {\n const trimmedDesiredMode = desiredMode.trim();\n const trimmedRequestOwner = requestOwner.trim();\n\n if (!trimmedDesiredMode) {\n throw new Error('requestModeChange requires non-empty desiredMode');\n }\n if (!trimmedRequestOwner) {\n throw new Error('requestModeChange requires non-empty requestOwner');\n }\n\n mapModeBus.emit(MapModeEvents.changeRequest, {\n desiredMode: trimmedDesiredMode,\n owner: trimmedRequestOwner,\n id: instanceId,\n });\n });\n\n requestModeChangeCache.set(instanceId, requestModeChange);\n\n return requestModeChange;\n}\n\n/**\n * Get the owner of the current mode for a given map instance\n * @internal - For internal map-toolkit use only\n */\nexport function getCurrentModeOwner(instanceId: UniqueId): string | undefined {\n const state = modeStore.get(instanceId);\n if (!state) {\n return undefined;\n }\n return state.modeOwners.get(state.mode);\n}\n\n/**\n * Manually clear map mode 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 map mode instance to clear\n *\n * @example\n * ```tsx\n * // Manual cleanup (rarely needed)\n * clearMapModeState('my-map-instance');\n * ```\n */\nexport function clearMapModeState(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 modeStore.delete(instanceId);\n componentSubscribers.delete(instanceId);\n subscriptionCache.delete(instanceId);\n snapshotCache.delete(instanceId);\n serverSnapshotCache.delete(instanceId);\n requestModeChangeCache.delete(instanceId);\n}\n"],"mappings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
|
|
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 { MapModeEvents } from "./events.js";
|
|
14
|
+
import { Payload } from "@accelint/bus";
|
|
15
|
+
import { UniqueId } from "@accelint/core";
|
|
4
16
|
|
|
17
|
+
//#region src/map-mode/types.d.ts
|
|
5
18
|
/**
|
|
6
19
|
* Payload emitted when the map mode has successfully changed.
|
|
7
20
|
*/
|
|
8
21
|
type ModeChangedPayload = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
22
|
+
/** The mode before the change */
|
|
23
|
+
previousMode: string;
|
|
24
|
+
/** The mode after the change */
|
|
25
|
+
currentMode: string;
|
|
26
|
+
/** The ID of the map this event is for */
|
|
27
|
+
id: UniqueId;
|
|
15
28
|
};
|
|
16
29
|
/**
|
|
17
30
|
* Payload for requesting a map mode change.
|
|
18
31
|
* This initiates the mode change flow.
|
|
19
32
|
*/
|
|
20
33
|
type ModeChangeRequestPayload = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
/** The mode being requested */
|
|
35
|
+
desiredMode: string;
|
|
36
|
+
/** The identifier of the component requesting the mode change */
|
|
37
|
+
owner: string;
|
|
38
|
+
/** The ID of the map this event is for */
|
|
39
|
+
id: UniqueId;
|
|
27
40
|
};
|
|
28
41
|
/**
|
|
29
42
|
* Payload emitted when a mode change requires authorization.
|
|
30
43
|
* This is sent to the current mode owner to approve or reject the request.
|
|
31
44
|
*/
|
|
32
45
|
type ModeChangeAuthorizationPayload = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
/** Unique identifier for this authorization request */
|
|
47
|
+
authId: string;
|
|
48
|
+
/** The mode being requested */
|
|
49
|
+
desiredMode: string;
|
|
50
|
+
/** The current active mode */
|
|
51
|
+
currentMode: string;
|
|
52
|
+
/** The ID of the map this event is for */
|
|
53
|
+
id: UniqueId;
|
|
41
54
|
};
|
|
42
55
|
/**
|
|
43
56
|
* Payload for an authorization decision from the current mode owner.
|
|
44
57
|
* This completes the authorization flow.
|
|
45
58
|
*/
|
|
46
59
|
type ModeChangeDecisionPayload = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
/** The authId from the corresponding authorization request */
|
|
61
|
+
authId: string;
|
|
62
|
+
/** Whether the mode change was approved */
|
|
63
|
+
approved: boolean;
|
|
64
|
+
/** The identifier of the component making the decision (must be current mode owner) */
|
|
65
|
+
owner: string;
|
|
66
|
+
/** Optional reason for rejection */
|
|
67
|
+
reason?: string;
|
|
68
|
+
/** The ID of the map this event is for */
|
|
69
|
+
id: UniqueId;
|
|
57
70
|
};
|
|
58
71
|
/**
|
|
59
72
|
* Event type for mode change notifications.
|
|
@@ -79,5 +92,6 @@ type ModeChangeDecisionEvent = Payload<typeof MapModeEvents.changeDecision, Mode
|
|
|
79
92
|
* Union type of all map mode event types that can be emitted through the event bus.
|
|
80
93
|
*/
|
|
81
94
|
type MapModeEventType = ModeChangedEvent | ModeChangeRequestEvent | ModeChangeAuthorizationEvent | ModeChangeDecisionEvent;
|
|
82
|
-
|
|
83
|
-
export
|
|
95
|
+
//#endregion
|
|
96
|
+
export { MapModeEventType, ModeChangeAuthorizationEvent, ModeChangeAuthorizationPayload, ModeChangeDecisionEvent, ModeChangeDecisionPayload, ModeChangeRequestEvent, ModeChangeRequestPayload, ModeChangedEvent, ModeChangedPayload };
|
|
97
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/map-mode/types.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
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
|
+
*/
|
|
1
12
|
|
|
2
|
-
//# sourceMappingURL=types.js.map
|
|
3
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
|
|
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
|
+
*/
|
|
2
12
|
|
|
13
|
+
import { UniqueId } from "@accelint/core";
|
|
14
|
+
|
|
15
|
+
//#region src/map-mode/use-map-mode.d.ts
|
|
3
16
|
/**
|
|
4
17
|
* Return value for the useMapMode hook
|
|
5
18
|
*/
|
|
6
19
|
type UseMapModeReturn = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
20
|
+
/** The current active map mode */
|
|
21
|
+
mode: string;
|
|
22
|
+
/** Function to request a mode change with ownership */
|
|
23
|
+
requestModeChange: (desiredMode: string, requestOwner: string) => void;
|
|
11
24
|
};
|
|
12
25
|
/**
|
|
13
26
|
* Hook to access the map mode state and actions.
|
|
@@ -48,5 +61,6 @@ type UseMapModeReturn = {
|
|
|
48
61
|
* ```
|
|
49
62
|
*/
|
|
50
63
|
declare function useMapMode(id?: UniqueId): UseMapModeReturn;
|
|
51
|
-
|
|
52
|
-
export {
|
|
64
|
+
//#endregion
|
|
65
|
+
export { UseMapModeReturn, useMapMode };
|
|
66
|
+
//# sourceMappingURL=use-map-mode.d.ts.map
|
|
@@ -1,29 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
*/
|
|
5
12
|
|
|
13
|
+
|
|
14
|
+
'use client';
|
|
15
|
+
|
|
16
|
+
import { getOrCreateRequestModeChange, getOrCreateServerSnapshot, getOrCreateSnapshot, getOrCreateSubscription } from "./store.js";
|
|
17
|
+
import { MapContext } from "../deckgl/base-map/provider.js";
|
|
18
|
+
import { useContext, useMemo, useSyncExternalStore } from "react";
|
|
19
|
+
|
|
20
|
+
//#region src/map-mode/use-map-mode.ts
|
|
21
|
+
/**
|
|
22
|
+
* Hook to access the map mode state and actions.
|
|
23
|
+
*
|
|
24
|
+
* This hook uses `useSyncExternalStore` to subscribe to map mode state changes,
|
|
25
|
+
* providing concurrent-safe mode state updates. Uses a fan-out pattern where
|
|
26
|
+
* a single bus listener per map instance notifies N React component subscribers.
|
|
27
|
+
*
|
|
28
|
+
* @param id - Optional map instance ID. If not provided, will use the ID from `MapContext`.
|
|
29
|
+
* @returns The current map mode and requestModeChange function
|
|
30
|
+
* @throws Error if no `id` is provided and hook is used outside of `MapProvider`
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* // Inside MapProvider (within BaseMap children) - uses context
|
|
35
|
+
* // Only Deck.gl layer components can be children
|
|
36
|
+
* function CustomDeckLayer() {
|
|
37
|
+
* const { mode, requestModeChange } = useMapMode();
|
|
38
|
+
*
|
|
39
|
+
* const handleClick = (info: PickingInfo) => {
|
|
40
|
+
* requestModeChange('editing', 'custom-layer-id');
|
|
41
|
+
* };
|
|
42
|
+
*
|
|
43
|
+
* return <ScatterplotLayer onClick={handleClick} />;
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```tsx
|
|
49
|
+
* // Outside MapProvider - pass id directly
|
|
50
|
+
* function ExternalControl({ mapId }: { mapId: UniqueId }) {
|
|
51
|
+
* const { mode, requestModeChange } = useMapMode(mapId);
|
|
52
|
+
*
|
|
53
|
+
* return <button onClick={() => requestModeChange('default', 'external')}>
|
|
54
|
+
* Reset to Default (current: {mode})
|
|
55
|
+
* </button>;
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
6
59
|
function useMapMode(id) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
getOrCreateSubscription(actualId),
|
|
16
|
-
getOrCreateSnapshot(actualId)
|
|
17
|
-
);
|
|
18
|
-
return useMemo(
|
|
19
|
-
() => ({
|
|
20
|
-
mode,
|
|
21
|
-
requestModeChange: getOrCreateRequestModeChange(actualId)
|
|
22
|
-
}),
|
|
23
|
-
[mode, actualId]
|
|
24
|
-
);
|
|
60
|
+
const contextId = useContext(MapContext);
|
|
61
|
+
const actualId = id ?? contextId;
|
|
62
|
+
if (!actualId) throw new Error("useMapMode requires either an id parameter or to be used within a MapProvider");
|
|
63
|
+
const mode = useSyncExternalStore(getOrCreateSubscription(actualId), getOrCreateSnapshot(actualId), getOrCreateServerSnapshot(actualId));
|
|
64
|
+
return useMemo(() => ({
|
|
65
|
+
mode,
|
|
66
|
+
requestModeChange: getOrCreateRequestModeChange(actualId)
|
|
67
|
+
}), [mode, actualId]);
|
|
25
68
|
}
|
|
26
69
|
|
|
70
|
+
//#endregion
|
|
27
71
|
export { useMapMode };
|
|
28
|
-
//# sourceMappingURL=use-map-mode.js.map
|
|
29
72
|
//# sourceMappingURL=use-map-mode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"use-map-mode.js","names":[],"sources":["../../src/map-mode/use-map-mode.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'use client';\n\nimport 'client-only';\nimport { useContext, useMemo, useSyncExternalStore } from 'react';\nimport { MapContext } from '../deckgl/base-map/provider';\nimport {\n getOrCreateRequestModeChange,\n getOrCreateServerSnapshot,\n getOrCreateSnapshot,\n getOrCreateSubscription,\n} from './store';\nimport type { UniqueId } from '@accelint/core';\n\n/**\n * Return value for the useMapMode hook\n */\nexport type UseMapModeReturn = {\n /** The current active map mode */\n mode: string;\n /** Function to request a mode change with ownership */\n requestModeChange: (desiredMode: string, requestOwner: string) => void;\n};\n\n/**\n * Hook to access the map mode state and actions.\n *\n * This hook uses `useSyncExternalStore` to subscribe to map mode 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 * @param id - Optional map instance ID. If not provided, will use the ID from `MapContext`.\n * @returns The current map mode and requestModeChange function\n * @throws Error if no `id` is provided and hook is used outside of `MapProvider`\n *\n * @example\n * ```tsx\n * // Inside MapProvider (within BaseMap children) - uses context\n * // Only Deck.gl layer components can be children\n * function CustomDeckLayer() {\n * const { mode, requestModeChange } = useMapMode();\n *\n * const handleClick = (info: PickingInfo) => {\n * requestModeChange('editing', 'custom-layer-id');\n * };\n *\n * return <ScatterplotLayer onClick={handleClick} />;\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Outside MapProvider - pass id directly\n * function ExternalControl({ mapId }: { mapId: UniqueId }) {\n * const { mode, requestModeChange } = useMapMode(mapId);\n *\n * return <button onClick={() => requestModeChange('default', 'external')}>\n * Reset to Default (current: {mode})\n * </button>;\n * }\n * ```\n */\nexport function useMapMode(id?: UniqueId): UseMapModeReturn {\n const contextId = useContext(MapContext);\n const actualId = id ?? contextId;\n\n if (!actualId) {\n throw new Error(\n 'useMapMode requires either an id parameter or to be used within a MapProvider',\n );\n }\n\n // Subscribe to store using useSyncExternalStore with fan-out pattern\n // Third parameter provides server snapshot for SSR/RSC compatibility\n const mode = useSyncExternalStore(\n getOrCreateSubscription(actualId),\n getOrCreateSnapshot(actualId),\n getOrCreateServerSnapshot(actualId),\n );\n\n // Memoize the return value to prevent unnecessary re-renders\n return useMemo(\n () => ({\n mode,\n requestModeChange: getOrCreateRequestModeChange(actualId),\n }),\n [mode, actualId],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,SAAgB,WAAW,IAAiC;CAC1D,MAAM,YAAY,WAAW,WAAW;CACxC,MAAM,WAAW,MAAM;AAEvB,KAAI,CAAC,SACH,OAAM,IAAI,MACR,gFACD;CAKH,MAAM,OAAO,qBACX,wBAAwB,SAAS,EACjC,oBAAoB,SAAS,EAC7B,0BAA0B,SAAS,CACpC;AAGD,QAAO,eACE;EACL;EACA,mBAAmB,6BAA6B,SAAS;EAC1D,GACD,CAAC,MAAM,SAAS,CACjB"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
//#region src/maplibre/constants.d.ts
|
|
1
2
|
declare const INITIAL_VIEW_STATE: {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
longitude: number;
|
|
4
|
+
latitude: number;
|
|
5
|
+
zoom: number;
|
|
6
|
+
minZoom: number;
|
|
7
|
+
maxZoom: number;
|
|
8
|
+
pitch: number;
|
|
9
|
+
bearing: number;
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
+
//#endregion
|
|
11
12
|
export { INITIAL_VIEW_STATE };
|
|
13
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1,13 +1,27 @@
|
|
|
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
|
+
//#region src/maplibre/constants.ts
|
|
1
15
|
const INITIAL_VIEW_STATE = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
16
|
+
longitude: -77.0369,
|
|
17
|
+
latitude: 38.9072,
|
|
18
|
+
zoom: 4,
|
|
19
|
+
minZoom: 1,
|
|
20
|
+
maxZoom: 22,
|
|
21
|
+
pitch: 0,
|
|
22
|
+
bearing: 0
|
|
9
23
|
};
|
|
10
24
|
|
|
25
|
+
//#endregion
|
|
11
26
|
export { INITIAL_VIEW_STATE };
|
|
12
|
-
//# sourceMappingURL=constants.js.map
|
|
13
27
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,4 +1,18 @@
|
|
|
1
|
-
|
|
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 { IControl, Map, MapOptions } from "maplibre-gl";
|
|
14
|
+
|
|
15
|
+
//#region src/maplibre/hooks/use-maplibre.d.ts
|
|
2
16
|
|
|
3
17
|
/**
|
|
4
18
|
* Hook to integrate a MapLibre GL map with a Deck.gl instance.
|
|
@@ -35,5 +49,6 @@ import { IControl, MapOptions, Map } from 'maplibre-gl';
|
|
|
35
49
|
* ```
|
|
36
50
|
*/
|
|
37
51
|
declare function useMapLibre(deck: IControl | null, styleUrl: string, options: MapOptions): Map | null;
|
|
38
|
-
|
|
52
|
+
//#endregion
|
|
39
53
|
export { useMapLibre };
|
|
54
|
+
//# sourceMappingURL=use-maplibre.d.ts.map
|
|
@@ -1,37 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
+
*/
|
|
3
12
|
|
|
13
|
+
|
|
14
|
+
import { useEffect, useRef } from "react";
|
|
15
|
+
import { Map } from "maplibre-gl";
|
|
16
|
+
|
|
17
|
+
//#region src/maplibre/hooks/use-maplibre.ts
|
|
18
|
+
/**
|
|
19
|
+
* Hook to integrate a MapLibre GL map with a Deck.gl instance.
|
|
20
|
+
*
|
|
21
|
+
* This hook manages the lifecycle of a MapLibre map, including initialization,
|
|
22
|
+
* style updates, and cleanup. It ensures the Deck.gl control is properly added
|
|
23
|
+
* to the map and handles cleanup when the component unmounts.
|
|
24
|
+
*
|
|
25
|
+
* @param deck - The Deck.gl IControl instance to add to the map
|
|
26
|
+
* @param styleUrl - The MapLibre style URL to use for the map
|
|
27
|
+
* @param options - MapLibre map options (container, center, zoom, etc.)
|
|
28
|
+
* @returns The MapLibre map instance, or null if not yet initialized
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* function MapComponent() {
|
|
33
|
+
* const deckglInstance = useDeckgl();
|
|
34
|
+
* const container = useId();
|
|
35
|
+
*
|
|
36
|
+
* const mapOptions = useMemo(() => ({
|
|
37
|
+
* container,
|
|
38
|
+
* center: [-122.4, 37.8],
|
|
39
|
+
* zoom: 12,
|
|
40
|
+
* }), [container]);
|
|
41
|
+
*
|
|
42
|
+
* useMapLibre(
|
|
43
|
+
* deckglInstance as IControl,
|
|
44
|
+
* 'https://tiles.example.com/style.json',
|
|
45
|
+
* mapOptions
|
|
46
|
+
* );
|
|
47
|
+
*
|
|
48
|
+
* return <div id={container} />;
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
4
52
|
function useMapLibre(deck, styleUrl, options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}, [styleUrl]);
|
|
32
|
-
return mapRef.current;
|
|
53
|
+
const mapRef = useRef(null);
|
|
54
|
+
const optionsRef = useRef(options);
|
|
55
|
+
const styleRef = useRef(styleUrl);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (deck && !mapRef.current) {
|
|
58
|
+
mapRef.current = new Map({
|
|
59
|
+
...optionsRef.current,
|
|
60
|
+
style: styleRef.current
|
|
61
|
+
});
|
|
62
|
+
mapRef.current.once("style.load", () => {
|
|
63
|
+
mapRef.current?.setProjection({ type: "mercator" });
|
|
64
|
+
mapRef.current?.addControl(deck);
|
|
65
|
+
});
|
|
66
|
+
return () => {
|
|
67
|
+
if (mapRef.current) {
|
|
68
|
+
mapRef.current.removeControl(deck);
|
|
69
|
+
mapRef.current.remove();
|
|
70
|
+
mapRef.current = null;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}, [deck]);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (mapRef.current) mapRef.current.setStyle(styleUrl);
|
|
77
|
+
}, [styleUrl]);
|
|
78
|
+
return mapRef.current;
|
|
33
79
|
}
|
|
34
80
|
|
|
81
|
+
//#endregion
|
|
35
82
|
export { useMapLibre };
|
|
36
|
-
//# sourceMappingURL=use-maplibre.js.map
|
|
37
83
|
//# sourceMappingURL=use-maplibre.js.map
|