@accelint/map-toolkit 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/CHANGELOG.md +49 -24
  2. package/catalog-info.yaml +5 -7
  3. package/dist/cursor-coordinates/index.d.ts +14 -3
  4. package/dist/cursor-coordinates/index.js +16 -3
  5. package/dist/cursor-coordinates/use-cursor-coordinates.d.ts +20 -6
  6. package/dist/cursor-coordinates/use-cursor-coordinates.js +247 -128
  7. package/dist/cursor-coordinates/use-cursor-coordinates.js.map +1 -1
  8. package/dist/deckgl/base-map/constants.d.ts +14 -12
  9. package/dist/deckgl/base-map/constants.js +26 -12
  10. package/dist/deckgl/base-map/constants.js.map +1 -1
  11. package/dist/deckgl/base-map/events.d.ts +6 -4
  12. package/dist/deckgl/base-map/events.js +18 -4
  13. package/dist/deckgl/base-map/events.js.map +1 -1
  14. package/dist/deckgl/base-map/index.d.ts +45 -18
  15. package/dist/deckgl/base-map/index.js +216 -148
  16. package/dist/deckgl/base-map/index.js.map +1 -1
  17. package/dist/deckgl/base-map/provider.d.ts +48 -32
  18. package/dist/deckgl/base-map/provider.js +122 -11
  19. package/dist/deckgl/base-map/provider.js.map +1 -1
  20. package/dist/deckgl/base-map/types.d.ts +49 -39
  21. package/dist/deckgl/base-map/types.js +11 -2
  22. package/dist/deckgl/index.d.ts +18 -13
  23. package/dist/deckgl/index.js +19 -6
  24. package/dist/deckgl/symbol-layer/fiber.d.ts +21 -10
  25. package/dist/deckgl/symbol-layer/fiber.js +18 -3
  26. package/dist/deckgl/symbol-layer/fiber.js.map +1 -1
  27. package/dist/deckgl/symbol-layer/index.d.ts +68 -54
  28. package/dist/deckgl/symbol-layer/index.js +105 -85
  29. package/dist/deckgl/symbol-layer/index.js.map +1 -1
  30. package/dist/deckgl/text-layer/character-sets.d.ts +19 -17
  31. package/dist/deckgl/text-layer/character-sets.js +40 -19
  32. package/dist/deckgl/text-layer/character-sets.js.map +1 -1
  33. package/dist/deckgl/text-layer/default-settings.d.ts +16 -2
  34. package/dist/deckgl/text-layer/default-settings.js +42 -18
  35. package/dist/deckgl/text-layer/default-settings.js.map +1 -1
  36. package/dist/deckgl/text-layer/fiber.d.ts +38 -27
  37. package/dist/deckgl/text-layer/fiber.js +18 -3
  38. package/dist/deckgl/text-layer/fiber.js.map +1 -1
  39. package/dist/deckgl/text-layer/index.d.ts +39 -25
  40. package/dist/deckgl/text-layer/index.js +47 -29
  41. package/dist/deckgl/text-layer/index.js.map +1 -1
  42. package/dist/decorators/deckgl.d.ts +16 -2
  43. package/dist/decorators/deckgl.js +25 -7
  44. package/dist/decorators/deckgl.js.map +1 -1
  45. package/dist/map-cursor/events.d.ts +16 -0
  46. package/dist/map-cursor/events.js +27 -0
  47. package/dist/map-cursor/events.js.map +1 -0
  48. package/dist/map-cursor/index.d.ts +17 -0
  49. package/dist/map-cursor/index.js +18 -0
  50. package/dist/map-cursor/store.d.ts +93 -0
  51. package/dist/map-cursor/store.js +351 -0
  52. package/dist/map-cursor/store.js.map +1 -0
  53. package/dist/map-cursor/types.d.ts +81 -0
  54. package/dist/map-cursor/types.js +12 -0
  55. package/dist/map-cursor/use-map-cursor.d.ts +99 -0
  56. package/dist/map-cursor/use-map-cursor.js +116 -0
  57. package/dist/map-cursor/use-map-cursor.js.map +1 -0
  58. package/dist/map-mode/events.d.ts +11 -9
  59. package/dist/map-mode/events.js +43 -9
  60. package/dist/map-mode/events.js.map +1 -1
  61. package/dist/map-mode/index.d.ts +17 -6
  62. package/dist/map-mode/index.js +18 -5
  63. package/dist/map-mode/store.d.ts +26 -3
  64. package/dist/map-mode/store.js +329 -265
  65. package/dist/map-mode/store.js.map +1 -1
  66. package/dist/map-mode/types.d.ts +49 -35
  67. package/dist/map-mode/types.js +11 -2
  68. package/dist/map-mode/use-map-mode.d.ts +21 -7
  69. package/dist/map-mode/use-map-mode.js +66 -23
  70. package/dist/map-mode/use-map-mode.js.map +1 -1
  71. package/dist/maplibre/constants.d.ts +10 -8
  72. package/dist/maplibre/constants.js +22 -8
  73. package/dist/maplibre/constants.js.map +1 -1
  74. package/dist/maplibre/hooks/use-maplibre.d.ts +17 -2
  75. package/dist/maplibre/hooks/use-maplibre.js +77 -31
  76. package/dist/maplibre/hooks/use-maplibre.js.map +1 -1
  77. package/dist/maplibre/index.d.ts +15 -3
  78. package/dist/maplibre/index.js +17 -4
  79. package/dist/viewport/constants.d.ts +8 -6
  80. package/dist/viewport/constants.js +20 -6
  81. package/dist/viewport/constants.js.map +1 -1
  82. package/dist/viewport/index.d.ts +18 -13
  83. package/dist/viewport/index.js +19 -6
  84. package/dist/viewport/types.d.ts +27 -17
  85. package/dist/viewport/types.js +11 -2
  86. package/dist/viewport/use-viewport-state.d.ts +29 -14
  87. package/dist/viewport/use-viewport-state.js +200 -87
  88. package/dist/viewport/use-viewport-state.js.map +1 -1
  89. package/dist/viewport/utils.d.ts +25 -10
  90. package/dist/viewport/utils.js +67 -37
  91. package/dist/viewport/utils.js.map +1 -1
  92. package/dist/viewport/viewport-size.d.ts +27 -15
  93. package/dist/viewport/viewport-size.js +54 -11
  94. package/dist/viewport/viewport-size.js.map +1 -1
  95. package/package.json +107 -78
  96. package/dist/cursor-coordinates/index.js.map +0 -1
  97. package/dist/deckgl/base-map/types.js.map +0 -1
  98. package/dist/deckgl/index.js.map +0 -1
  99. package/dist/map-mode/index.js.map +0 -1
  100. package/dist/map-mode/types.js.map +0 -1
  101. package/dist/maplibre/index.js.map +0 -1
  102. package/dist/metafile-esm.json +0 -1
  103. package/dist/viewport/index.js.map +0 -1
  104. package/dist/viewport/types.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/maplibre/hooks/use-maplibre.ts"],"names":["MapLibre"],"mappings":";;;AAiDO,SAAS,WAAA,CACd,IAAA,EACA,QAAA,EACA,OAAA,EACA;AACA,EAAA,MAAM,MAAA,GAAS,OAAwB,IAAI,CAAA;AAG3C,EAAA,MAAM,UAAA,GAAa,OAAO,OAAO,CAAA;AAEjC,EAAA,MAAM,QAAA,GAAW,OAAO,QAAQ,CAAA;AAGhC,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,IAAA,IAAQ,CAAC,MAAA,CAAO,OAAA,EAAS;AAC3B,MAAA,MAAA,CAAO,OAAA,GAAU,IAAIA,GAAA,CAAS;AAAA,QAC5B,GAAG,UAAA,CAAW,OAAA;AAAA,QACd,OAAO,QAAA,CAAS;AAAA,OACjB,CAAA;AAED,MAAA,MAAA,CAAO,OAAA,CAAQ,IAAA,CAAK,YAAA,EAAc,MAAM;AACtC,QAAA,MAAA,CAAO,OAAA,EAAS,aAAA,CAAc,EAAE,IAAA,EAAM,YAAY,CAAA;AAClD,QAAA,MAAA,CAAO,OAAA,EAAS,WAAW,IAAI,CAAA;AAAA,MACjC,CAAC,CAAA;AAED,MAAA,OAAO,MAAM;AACX,QAAA,IAAI,OAAO,OAAA,EAAS;AAClB,UAAA,MAAA,CAAO,OAAA,CAAQ,cAAc,IAAI,CAAA;AACjC,UAAA,MAAA,CAAO,QAAQ,MAAA,EAAO;AACtB,UAAA,MAAA,CAAO,OAAA,GAAU,IAAA;AAAA,QACnB;AAAA,MACF,CAAA;AAAA,IACF;AAAA,EACF,CAAA,EAAG,CAAC,IAAI,CAAC,CAAA;AAGT,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,OAAO,OAAA,EAAS;AAClB,MAAA,MAAA,CAAO,OAAA,CAAQ,SAAS,QAAQ,CAAA;AAAA,IAClC;AAAA,EACF,CAAA,EAAG,CAAC,QAAQ,CAAC,CAAA;AAEb,EAAA,OAAO,MAAA,CAAO,OAAA;AAChB","file":"use-maplibre.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 { type IControl, Map as MapLibre, type MapOptions } from 'maplibre-gl';\nimport { useEffect, useRef } from 'react';\n\n/**\n * Hook to integrate a MapLibre GL map with a Deck.gl instance.\n *\n * This hook manages the lifecycle of a MapLibre map, including initialization,\n * style updates, and cleanup. It ensures the Deck.gl control is properly added\n * to the map and handles cleanup when the component unmounts.\n *\n * @param deck - The Deck.gl IControl instance to add to the map\n * @param styleUrl - The MapLibre style URL to use for the map\n * @param options - MapLibre map options (container, center, zoom, etc.)\n * @returns The MapLibre map instance, or null if not yet initialized\n *\n * @example\n * ```tsx\n * function MapComponent() {\n * const deckglInstance = useDeckgl();\n * const container = useId();\n *\n * const mapOptions = useMemo(() => ({\n * container,\n * center: [-122.4, 37.8],\n * zoom: 12,\n * }), [container]);\n *\n * useMapLibre(\n * deckglInstance as IControl,\n * 'https://tiles.example.com/style.json',\n * mapOptions\n * );\n *\n * return <div id={container} />;\n * }\n * ```\n */\nexport function useMapLibre(\n deck: IControl | null,\n styleUrl: string,\n options: MapOptions,\n) {\n const mapRef = useRef<MapLibre | null>(null);\n // Using a ref for options to avoid re-creating the map when options object reference changes\n // The map is only created once on mount, options changes after that are ignored\n const optionsRef = useRef(options);\n // using a ref in the initial setup so that it doesn't cause a re-run of the effect on change\n const styleRef = useRef(styleUrl);\n\n // Initialize MapLibre instance once\n useEffect(() => {\n if (deck && !mapRef.current) {\n mapRef.current = new MapLibre({\n ...optionsRef.current,\n style: styleRef.current,\n });\n\n mapRef.current.once('style.load', () => {\n mapRef.current?.setProjection({ type: 'mercator' });\n mapRef.current?.addControl(deck);\n });\n\n return () => {\n if (mapRef.current) {\n mapRef.current.removeControl(deck);\n mapRef.current.remove();\n mapRef.current = null;\n }\n };\n }\n }, [deck]);\n\n // Update style when it changes\n useEffect(() => {\n if (mapRef.current) {\n mapRef.current.setStyle(styleUrl);\n }\n }, [styleUrl]);\n\n return mapRef.current;\n}\n"]}
1
+ {"version":3,"file":"use-maplibre.js","names":["MapLibre"],"sources":["../../../src/maplibre/hooks/use-maplibre.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 { type IControl, Map as MapLibre, type MapOptions } from 'maplibre-gl';\nimport { useEffect, useRef } from 'react';\n\n/**\n * Hook to integrate a MapLibre GL map with a Deck.gl instance.\n *\n * This hook manages the lifecycle of a MapLibre map, including initialization,\n * style updates, and cleanup. It ensures the Deck.gl control is properly added\n * to the map and handles cleanup when the component unmounts.\n *\n * @param deck - The Deck.gl IControl instance to add to the map\n * @param styleUrl - The MapLibre style URL to use for the map\n * @param options - MapLibre map options (container, center, zoom, etc.)\n * @returns The MapLibre map instance, or null if not yet initialized\n *\n * @example\n * ```tsx\n * function MapComponent() {\n * const deckglInstance = useDeckgl();\n * const container = useId();\n *\n * const mapOptions = useMemo(() => ({\n * container,\n * center: [-122.4, 37.8],\n * zoom: 12,\n * }), [container]);\n *\n * useMapLibre(\n * deckglInstance as IControl,\n * 'https://tiles.example.com/style.json',\n * mapOptions\n * );\n *\n * return <div id={container} />;\n * }\n * ```\n */\nexport function useMapLibre(\n deck: IControl | null,\n styleUrl: string,\n options: MapOptions,\n) {\n const mapRef = useRef<MapLibre | null>(null);\n // Using a ref for options to avoid re-creating the map when options object reference changes\n // The map is only created once on mount, options changes after that are ignored\n const optionsRef = useRef(options);\n // using a ref in the initial setup so that it doesn't cause a re-run of the effect on change\n const styleRef = useRef(styleUrl);\n\n // Initialize MapLibre instance once\n useEffect(() => {\n if (deck && !mapRef.current) {\n mapRef.current = new MapLibre({\n ...optionsRef.current,\n style: styleRef.current,\n });\n\n mapRef.current.once('style.load', () => {\n mapRef.current?.setProjection({ type: 'mercator' });\n mapRef.current?.addControl(deck);\n });\n\n return () => {\n if (mapRef.current) {\n mapRef.current.removeControl(deck);\n mapRef.current.remove();\n mapRef.current = null;\n }\n };\n }\n }, [deck]);\n\n // Update style when it changes\n useEffect(() => {\n if (mapRef.current) {\n mapRef.current.setStyle(styleUrl);\n }\n }, [styleUrl]);\n\n return mapRef.current;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,SAAgB,YACd,MACA,UACA,SACA;CACA,MAAM,SAAS,OAAwB,KAAK;CAG5C,MAAM,aAAa,OAAO,QAAQ;CAElC,MAAM,WAAW,OAAO,SAAS;AAGjC,iBAAgB;AACd,MAAI,QAAQ,CAAC,OAAO,SAAS;AAC3B,UAAO,UAAU,IAAIA,IAAS;IAC5B,GAAG,WAAW;IACd,OAAO,SAAS;IACjB,CAAC;AAEF,UAAO,QAAQ,KAAK,oBAAoB;AACtC,WAAO,SAAS,cAAc,EAAE,MAAM,YAAY,CAAC;AACnD,WAAO,SAAS,WAAW,KAAK;KAChC;AAEF,gBAAa;AACX,QAAI,OAAO,SAAS;AAClB,YAAO,QAAQ,cAAc,KAAK;AAClC,YAAO,QAAQ,QAAQ;AACvB,YAAO,UAAU;;;;IAItB,CAAC,KAAK,CAAC;AAGV,iBAAgB;AACd,MAAI,OAAO,QACT,QAAO,QAAQ,SAAS,SAAS;IAElC,CAAC,SAAS,CAAC;AAEd,QAAO,OAAO"}
@@ -1,3 +1,15 @@
1
- export { INITIAL_VIEW_STATE } from './constants.js';
2
- export { useMapLibre } from './hooks/use-maplibre.js';
3
- import 'maplibre-gl';
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 { INITIAL_VIEW_STATE } from "./constants.js";
14
+ import { useMapLibre } from "./hooks/use-maplibre.js";
15
+ export { INITIAL_VIEW_STATE, useMapLibre };
@@ -1,4 +1,17 @@
1
- export { INITIAL_VIEW_STATE } from './constants.js';
2
- export { useMapLibre } from './hooks/use-maplibre.js';
3
- //# sourceMappingURL=index.js.map
4
- //# sourceMappingURL=index.js.map
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 { INITIAL_VIEW_STATE } from "./constants.js";
15
+ import { useMapLibre } from "./hooks/use-maplibre.js";
16
+
17
+ export { INITIAL_VIEW_STATE, useMapLibre };
@@ -1,9 +1,11 @@
1
+ //#region src/viewport/constants.d.ts
1
2
  declare const UNIT_MAP: {
2
- readonly km: "kilometers";
3
- readonly m: "meters";
4
- readonly nm: "nauticalmiles";
5
- readonly mi: "miles";
6
- readonly ft: "feet";
3
+ readonly km: "kilometers";
4
+ readonly m: "meters";
5
+ readonly nm: "nauticalmiles";
6
+ readonly mi: "miles";
7
+ readonly ft: "feet";
7
8
  };
8
-
9
+ //#endregion
9
10
  export { UNIT_MAP };
11
+ //# sourceMappingURL=constants.d.ts.map
@@ -1,11 +1,25 @@
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/viewport/constants.ts
1
15
  const UNIT_MAP = {
2
- km: "kilometers",
3
- m: "meters",
4
- nm: "nauticalmiles",
5
- mi: "miles",
6
- ft: "feet"
16
+ km: "kilometers",
17
+ m: "meters",
18
+ nm: "nauticalmiles",
19
+ mi: "miles",
20
+ ft: "feet"
7
21
  };
8
22
 
23
+ //#endregion
9
24
  export { UNIT_MAP };
10
- //# sourceMappingURL=constants.js.map
11
25
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/viewport/constants.ts"],"names":[],"mappings":"AAYO,MAAM,QAAA,GAAW;AAAA,EACtB,EAAA,EAAI,YAAA;AAAA,EACJ,CAAA,EAAG,QAAA;AAAA,EACH,EAAA,EAAI,eAAA;AAAA,EACJ,EAAA,EAAI,OAAA;AAAA,EACJ,EAAA,EAAI;AACN","file":"constants.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\nexport const UNIT_MAP = {\n km: 'kilometers',\n m: 'meters',\n nm: 'nauticalmiles',\n mi: 'miles',\n ft: 'feet',\n} as const;\n"]}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../../src/viewport/constants.ts"],"sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport const UNIT_MAP = {\n km: 'kilometers',\n m: 'meters',\n nm: 'nauticalmiles',\n mi: 'miles',\n ft: 'feet',\n} as const;\n"],"mappings":";;;;;;;;;;;;;;AAYA,MAAa,WAAW;CACtB,IAAI;CACJ,GAAG;CACH,IAAI;CACJ,IAAI;CACJ,IAAI;CACL"}
@@ -1,13 +1,18 @@
1
- export { UNIT_MAP } from './constants.js';
2
- export { UseViewportStateProps, clearViewportState, useViewportState } from './use-viewport-state.js';
3
- export { getViewportSize } from './utils.js';
4
- export { ViewportSize, ViewportSizeProps } from './viewport-size.js';
5
- export { GeoCoordinate, GetViewportSizeArgs, SupportedDistanceUnit } from './types.js';
6
- import 'react';
7
- import '@accelint/core';
8
- import '../deckgl/base-map/types.js';
9
- import '@accelint/bus';
10
- import '@deck.gl/core';
11
- import 'mjolnir.js';
12
- import '../deckgl/base-map/events.js';
13
- import 'react/jsx-runtime';
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 { UNIT_MAP } from "./constants.js";
14
+ import { UseViewportStateProps, clearViewportState, useViewportState } from "./use-viewport-state.js";
15
+ import { GeoCoordinate, GetViewportSizeArgs, SupportedDistanceUnit } from "./types.js";
16
+ import { getViewportSize } from "./utils.js";
17
+ import { ViewportSize, ViewportSizeProps } from "./viewport-size.js";
18
+ export { type GeoCoordinate, type GetViewportSizeArgs, type SupportedDistanceUnit, UNIT_MAP, type UseViewportStateProps, ViewportSize, type ViewportSizeProps, clearViewportState, getViewportSize, useViewportState };
@@ -1,6 +1,19 @@
1
- export { UNIT_MAP } from './constants.js';
2
- export { clearViewportState, useViewportState } from './use-viewport-state.js';
3
- export { getViewportSize } from './utils.js';
4
- export { ViewportSize } from './viewport-size.js';
5
- //# sourceMappingURL=index.js.map
6
- //# sourceMappingURL=index.js.map
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 { UNIT_MAP } from "./constants.js";
15
+ import { clearViewportState, useViewportState } from "./use-viewport-state.js";
16
+ import { getViewportSize } from "./utils.js";
17
+ import { ViewportSize } from "./viewport-size.js";
18
+
19
+ export { UNIT_MAP, ViewportSize, clearViewportState, getViewportSize, useViewportState };
@@ -1,22 +1,32 @@
1
- import { Bounds } from '../deckgl/base-map/types.js';
2
- import { UNIT_MAP } from './constants.js';
3
- import '@accelint/bus';
4
- import '@accelint/core';
5
- import '@deck.gl/core';
6
- import 'mjolnir.js';
7
- import '../deckgl/base-map/events.js';
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
+ */
8
12
 
13
+ import { Bounds } from "../deckgl/base-map/types.js";
14
+ import { UNIT_MAP } from "./constants.js";
15
+
16
+ //#region src/viewport/types.d.ts
9
17
  type SupportedDistanceUnit = keyof typeof UNIT_MAP;
10
18
  type GetViewportSizeArgs = {
11
- bounds: Bounds;
12
- zoom: number;
13
- /** Viewport width in pixels */
14
- width: number;
15
- /** Viewport height in pixels */
16
- height: number;
17
- unit?: SupportedDistanceUnit;
18
- formatter?: Intl.NumberFormat;
19
+ /** Geographic bounds, undefined if viewport not yet initialized */
20
+ bounds?: Bounds;
21
+ zoom: number;
22
+ /** Viewport width in pixels */
23
+ width: number;
24
+ /** Viewport height in pixels */
25
+ height: number;
26
+ unit?: SupportedDistanceUnit;
27
+ formatter?: Intl.NumberFormat;
19
28
  };
20
29
  type GeoCoordinate = [longitude: number, latitude: number];
21
-
22
- export type { GeoCoordinate, GetViewportSizeArgs, SupportedDistanceUnit };
30
+ //#endregion
31
+ export { GeoCoordinate, GetViewportSizeArgs, SupportedDistanceUnit };
32
+ //# sourceMappingURL=types.d.ts.map
@@ -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,16 +1,25 @@
1
- import { useSyncExternalStore } from 'react';
2
- import { UniqueId } from '@accelint/core';
3
- import { MapViewportPayload } from '../deckgl/base-map/types.js';
4
- import '@accelint/bus';
5
- import '@deck.gl/core';
6
- import 'mjolnir.js';
7
- import '../deckgl/base-map/events.js';
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
+ */
8
12
 
13
+ import { MapViewportPayload } from "../deckgl/base-map/types.js";
14
+ import { useSyncExternalStore } from "react";
15
+ import { UniqueId } from "@accelint/core";
16
+
17
+ //#region src/viewport/use-viewport-state.d.ts
9
18
  type UseViewportStateProps = {
10
- instanceId: UniqueId;
11
- subscribe?: Parameters<typeof useSyncExternalStore<MapViewportPayload>>[0];
12
- getSnapshot?: Parameters<typeof useSyncExternalStore<MapViewportPayload>>[1];
13
- getServerSnapshot?: Parameters<typeof useSyncExternalStore<MapViewportPayload>>[2];
19
+ instanceId: UniqueId;
20
+ subscribe?: Parameters<typeof useSyncExternalStore<MapViewportPayload>>[0];
21
+ getSnapshot?: Parameters<typeof useSyncExternalStore<MapViewportPayload>>[1];
22
+ getServerSnapshot?: Parameters<typeof useSyncExternalStore<MapViewportPayload>>[2];
14
23
  };
15
24
  /**
16
25
  * Hook to subscribe to viewport state changes for a specific view.
@@ -66,7 +75,12 @@ type UseViewportStateProps = {
66
75
  * }
67
76
  * ```
68
77
  */
69
- declare function useViewportState({ instanceId, subscribe, getSnapshot, getServerSnapshot, }: UseViewportStateProps): MapViewportPayload;
78
+ declare function useViewportState({
79
+ instanceId,
80
+ subscribe,
81
+ getSnapshot,
82
+ getServerSnapshot
83
+ }: UseViewportStateProps): MapViewportPayload;
70
84
  /**
71
85
  * Manually clear viewport state for a specific instanceId.
72
86
  * This is typically not needed as cleanup happens automatically when all subscribers unmount.
@@ -81,5 +95,6 @@ declare function useViewportState({ instanceId, subscribe, getSnapshot, getServe
81
95
  * ```
82
96
  */
83
97
  declare function clearViewportState(instanceId: UniqueId): void;
84
-
85
- export { type UseViewportStateProps, clearViewportState, useViewportState };
98
+ //#endregion
99
+ export { UseViewportStateProps, clearViewportState, useViewportState };
100
+ //# sourceMappingURL=use-viewport-state.d.ts.map
@@ -1,109 +1,222 @@
1
- import { Broadcast } from '@accelint/bus';
2
- import { useSyncExternalStore } from 'react';
3
- import { MapEvents } from '../deckgl/base-map/events.js';
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
+ */
4
12
 
13
+
14
+ import { MapEvents } from "../deckgl/base-map/events.js";
15
+ import { Broadcast } from "@accelint/bus";
16
+ import { useSyncExternalStore } from "react";
17
+
18
+ //#region src/viewport/use-viewport-state.ts
5
19
  const bus = Broadcast.getInstance();
20
+ /**
21
+ * Store for viewport state keyed by instanceId
22
+ */
6
23
  const viewportStore = /* @__PURE__ */ new Map();
24
+ /**
25
+ * Track React component subscribers per instanceId (for fan-out notifications).
26
+ * Each Set contains onStoreChange callbacks from useSyncExternalStore.
27
+ */
7
28
  const componentSubscribers = /* @__PURE__ */ new Map();
29
+ /**
30
+ * Cache of bus unsubscribe functions (1 per instanceId).
31
+ * This ensures we only have one bus listener per viewport, regardless of
32
+ * how many React components subscribe to it.
33
+ */
8
34
  const busUnsubscribers = /* @__PURE__ */ new Map();
35
+ /**
36
+ * Cache of subscription functions per instanceId to avoid recreating on every render
37
+ */
9
38
  const subscriptionCache = /* @__PURE__ */ new Map();
39
+ /**
40
+ * Cache of snapshot functions per instanceId to maintain referential stability
41
+ */
10
42
  const snapshotCache = /* @__PURE__ */ new Map();
43
+ /**
44
+ * Cache of fallback snapshots per instanceId to maintain referential stability.
45
+ * This prevents unnecessary re-renders when no viewport data exists yet.
46
+ */
11
47
  const fallbackCache = /* @__PURE__ */ new Map();
48
+ /**
49
+ * Ensures a single bus listener exists for the given instanceId.
50
+ * All React subscribers will be notified via fan-out when the bus event fires.
51
+ * This prevents creating N bus listeners for N React components.
52
+ *
53
+ * @param instanceId - The unique identifier for the viewport
54
+ */
12
55
  function ensureBusListener(instanceId) {
13
- if (busUnsubscribers.has(instanceId)) {
14
- return;
15
- }
16
- const unsub = bus.on(MapEvents.viewport, ({ payload }) => {
17
- if (instanceId === payload.id) {
18
- viewportStore.set(instanceId, payload);
19
- const subscribers = componentSubscribers.get(instanceId);
20
- if (subscribers) {
21
- for (const onStoreChange of subscribers) {
22
- onStoreChange();
23
- }
24
- }
25
- }
26
- });
27
- busUnsubscribers.set(instanceId, unsub);
56
+ if (busUnsubscribers.has(instanceId)) return;
57
+ const unsub = bus.on(MapEvents.viewport, ({ payload }) => {
58
+ if (instanceId === payload.id) {
59
+ viewportStore.set(instanceId, payload);
60
+ const subscribers = componentSubscribers.get(instanceId);
61
+ if (subscribers) for (const onStoreChange of subscribers) onStoreChange();
62
+ }
63
+ });
64
+ busUnsubscribers.set(instanceId, unsub);
28
65
  }
66
+ /**
67
+ * Cleans up the bus listener if no React subscribers remain.
68
+ *
69
+ * @param instanceId - The unique identifier for the viewport
70
+ */
29
71
  function cleanupBusListenerIfNeeded(instanceId) {
30
- const subscribers = componentSubscribers.get(instanceId);
31
- if (!subscribers || subscribers.size === 0) {
32
- const unsub = busUnsubscribers.get(instanceId);
33
- if (unsub) {
34
- unsub();
35
- busUnsubscribers.delete(instanceId);
36
- }
37
- viewportStore.delete(instanceId);
38
- componentSubscribers.delete(instanceId);
39
- subscriptionCache.delete(instanceId);
40
- snapshotCache.delete(instanceId);
41
- fallbackCache.delete(instanceId);
42
- }
72
+ const subscribers = componentSubscribers.get(instanceId);
73
+ if (!subscribers || subscribers.size === 0) {
74
+ const unsub = busUnsubscribers.get(instanceId);
75
+ if (unsub) {
76
+ unsub();
77
+ busUnsubscribers.delete(instanceId);
78
+ }
79
+ viewportStore.delete(instanceId);
80
+ componentSubscribers.delete(instanceId);
81
+ subscriptionCache.delete(instanceId);
82
+ snapshotCache.delete(instanceId);
83
+ fallbackCache.delete(instanceId);
84
+ }
43
85
  }
86
+ /**
87
+ * Creates or retrieves a cached subscription function for a given instanceId.
88
+ * Uses a fan-out pattern: 1 bus listener -> N React subscribers.
89
+ * Automatically cleans up viewport state when the last subscriber unsubscribes.
90
+ *
91
+ * @param instanceId - The unique identifier for the viewport
92
+ * @returns A subscription function for useSyncExternalStore
93
+ */
44
94
  function getOrCreateSubscription(instanceId) {
45
- const subscription = subscriptionCache.get(instanceId) ?? ((onStoreChange) => {
46
- ensureBusListener(instanceId);
47
- let subscriberSet = componentSubscribers.get(instanceId);
48
- if (!subscriberSet) {
49
- subscriberSet = /* @__PURE__ */ new Set();
50
- componentSubscribers.set(instanceId, subscriberSet);
51
- }
52
- subscriberSet.add(onStoreChange);
53
- return () => {
54
- const currentSubscriberSet = componentSubscribers.get(instanceId);
55
- if (currentSubscriberSet) {
56
- currentSubscriberSet.delete(onStoreChange);
57
- }
58
- cleanupBusListenerIfNeeded(instanceId);
59
- };
60
- });
61
- subscriptionCache.set(instanceId, subscription);
62
- return subscription;
95
+ const subscription = subscriptionCache.get(instanceId) ?? ((onStoreChange) => {
96
+ ensureBusListener(instanceId);
97
+ let subscriberSet = componentSubscribers.get(instanceId);
98
+ if (!subscriberSet) {
99
+ subscriberSet = /* @__PURE__ */ new Set();
100
+ componentSubscribers.set(instanceId, subscriberSet);
101
+ }
102
+ subscriberSet.add(onStoreChange);
103
+ return () => {
104
+ const currentSubscriberSet = componentSubscribers.get(instanceId);
105
+ if (currentSubscriberSet) currentSubscriberSet.delete(onStoreChange);
106
+ cleanupBusListenerIfNeeded(instanceId);
107
+ };
108
+ });
109
+ subscriptionCache.set(instanceId, subscription);
110
+ return subscription;
63
111
  }
112
+ /**
113
+ * Creates or retrieves a cached snapshot function for a given instanceId.
114
+ * The object returned gets equality checked, so it needs to be stable or React re-renders unnecessarily.
115
+ *
116
+ * @param instanceId - The unique identifier for the viewport
117
+ * @returns A snapshot function for useSyncExternalStore
118
+ */
64
119
  function getOrCreateSnapshot(instanceId) {
65
- const fallback = fallbackCache.get(instanceId) ?? (() => {
66
- const newFallback = {
67
- id: instanceId,
68
- bounds: [Number.NaN, Number.NaN, Number.NaN, Number.NaN],
69
- latitude: Number.NaN,
70
- longitude: Number.NaN,
71
- zoom: Number.NaN,
72
- width: 0,
73
- height: 0
74
- };
75
- fallbackCache.set(instanceId, newFallback);
76
- return newFallback;
77
- })();
78
- const snapshot = snapshotCache.get(instanceId) ?? (() => viewportStore.get(instanceId) ?? fallback);
79
- snapshotCache.set(instanceId, snapshot);
80
- return snapshot;
120
+ const fallback = fallbackCache.get(instanceId) ?? (() => {
121
+ const newFallback = {
122
+ id: instanceId,
123
+ bounds: void 0,
124
+ latitude: NaN,
125
+ longitude: NaN,
126
+ zoom: NaN,
127
+ width: 0,
128
+ height: 0
129
+ };
130
+ fallbackCache.set(instanceId, newFallback);
131
+ return newFallback;
132
+ })();
133
+ const snapshot = snapshotCache.get(instanceId) ?? (() => viewportStore.get(instanceId) ?? fallback);
134
+ snapshotCache.set(instanceId, snapshot);
135
+ return snapshot;
81
136
  }
82
- function useViewportState({
83
- instanceId,
84
- subscribe,
85
- getSnapshot,
86
- getServerSnapshot
87
- }) {
88
- return useSyncExternalStore(
89
- subscribe ?? getOrCreateSubscription(instanceId),
90
- getSnapshot ?? getOrCreateSnapshot(instanceId),
91
- getServerSnapshot
92
- );
137
+ /**
138
+ * Hook to subscribe to viewport state changes for a specific view.
139
+ *
140
+ * By default, subscribes to MapEvents.viewport events from the event bus and
141
+ * automatically cleans up when all subscribers unmount. For advanced use cases,
142
+ * custom subscribe/getSnapshot functions can be provided.
143
+ *
144
+ * A thin wrapper around [useSyncExternalStore](https://react.dev/reference/react/useSyncExternalStore).
145
+ *
146
+ * @param instanceId - Unique identifier for the viewport to track
147
+ * @param subscribe - Optional custom subscription function
148
+ * @param getSnapshot - Optional custom snapshot getter
149
+ * @param getServerSnapshot - Optional server-side snapshot getter
150
+ * @returns Current viewport state including bounds, latitude, longitude, zoom
151
+ *
152
+ * @example
153
+ * ```tsx
154
+ * function MapInfo({ instanceId }) {
155
+ * const { bounds, latitude, longitude, zoom } = useViewportState({
156
+ * instanceId
157
+ * });
158
+ *
159
+ * return (
160
+ * <div>
161
+ * Lat: {latitude?.toFixed(2)}, Lon: {longitude?.toFixed(2)}, Zoom: {zoom}
162
+ * </div>
163
+ * );
164
+ * }
165
+ * ```
166
+ *
167
+ * @example
168
+ * ```tsx
169
+ * // With custom subscribe/getSnapshot for advanced use cases
170
+ * function CustomMapInfo() {
171
+ * const customSubscribe = (onStoreChange) => {
172
+ * // Custom subscription logic
173
+ * return () => { // cleanup }
174
+ * }
175
+ *
176
+ * const customGetSnapshot = () => {
177
+ * // Custom snapshot logic
178
+ * return { latitude: 0, longitude: 0, zoom: 1 };
179
+ * };
180
+ *
181
+ * const viewState = useViewportState({
182
+ * instanceId: 'some-uuid',
183
+ * subscribe: customSubscribe,
184
+ * getSnapshot: customGetSnapshot,
185
+ * });
186
+ *
187
+ * return <div>Custom viewport state</div>;
188
+ * }
189
+ * ```
190
+ */
191
+ function useViewportState({ instanceId, subscribe, getSnapshot, getServerSnapshot }) {
192
+ return useSyncExternalStore(subscribe ?? getOrCreateSubscription(instanceId), getSnapshot ?? getOrCreateSnapshot(instanceId), getServerSnapshot);
93
193
  }
194
+ /**
195
+ * Manually clear viewport state for a specific instanceId.
196
+ * This is typically not needed as cleanup happens automatically when all subscribers unmount.
197
+ * Use this only in advanced scenarios where manual cleanup is required.
198
+ *
199
+ * @param instanceId - The unique identifier for the viewport to clear
200
+ *
201
+ * @example
202
+ * ```tsx
203
+ * // Manual cleanup (rarely needed)
204
+ * clearViewportState('my-map-instance');
205
+ * ```
206
+ */
94
207
  function clearViewportState(instanceId) {
95
- const unsub = busUnsubscribers.get(instanceId);
96
- if (unsub) {
97
- unsub();
98
- busUnsubscribers.delete(instanceId);
99
- }
100
- viewportStore.delete(instanceId);
101
- componentSubscribers.delete(instanceId);
102
- subscriptionCache.delete(instanceId);
103
- snapshotCache.delete(instanceId);
104
- fallbackCache.delete(instanceId);
208
+ const unsub = busUnsubscribers.get(instanceId);
209
+ if (unsub) {
210
+ unsub();
211
+ busUnsubscribers.delete(instanceId);
212
+ }
213
+ viewportStore.delete(instanceId);
214
+ componentSubscribers.delete(instanceId);
215
+ subscriptionCache.delete(instanceId);
216
+ snapshotCache.delete(instanceId);
217
+ fallbackCache.delete(instanceId);
105
218
  }
106
219
 
220
+ //#endregion
107
221
  export { clearViewportState, useViewportState };
108
- //# sourceMappingURL=use-viewport-state.js.map
109
222
  //# sourceMappingURL=use-viewport-state.js.map