@mapcairn/map 0.0.0-stage → 0.1.0-rc.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 (315) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +167 -2
  3. package/dist/chrome/Attribution/Attribution.js +304 -0
  4. package/dist/chrome/Attribution/Attribution.js.map +1 -0
  5. package/dist/chrome/Attribution/Attribution.styles.js +10 -0
  6. package/dist/chrome/Attribution/Attribution.styles.js.map +1 -0
  7. package/dist/chrome/Attribution/AttributionSkeleton.js +29 -0
  8. package/dist/chrome/Attribution/AttributionSkeleton.js.map +1 -0
  9. package/dist/chrome/ChromeSkeleton/ChromeSkeleton.js +83 -0
  10. package/dist/chrome/ChromeSkeleton/ChromeSkeleton.js.map +1 -0
  11. package/dist/chrome/EndStack/EndStack.js +157 -0
  12. package/dist/chrome/EndStack/EndStack.js.map +1 -0
  13. package/dist/chrome/EndStack/EndStack.styles.js +12 -0
  14. package/dist/chrome/EndStack/EndStack.styles.js.map +1 -0
  15. package/dist/chrome/EndStack/EndStackSkeleton.js +78 -0
  16. package/dist/chrome/EndStack/EndStackSkeleton.js.map +1 -0
  17. package/dist/chrome/EndStack/endStackHeight.js +22 -0
  18. package/dist/chrome/EndStack/endStackHeight.js.map +1 -0
  19. package/dist/chrome/MapChrome/MapChrome.js +488 -0
  20. package/dist/chrome/MapChrome/MapChrome.js.map +1 -0
  21. package/dist/chrome/MapChrome/MapChrome.styles.js +15 -0
  22. package/dist/chrome/MapChrome/MapChrome.styles.js.map +1 -0
  23. package/dist/chrome/MapChrome/chromeSurface.js +18 -0
  24. package/dist/chrome/MapChrome/chromeSurface.js.map +1 -0
  25. package/dist/chrome/MapChrome/chromeVars.js +71 -0
  26. package/dist/chrome/MapChrome/chromeVars.js.map +1 -0
  27. package/dist/chrome/MapChrome/mapKeyPlacement.js +41 -0
  28. package/dist/chrome/MapChrome/mapKeyPlacement.js.map +1 -0
  29. package/dist/chrome/MapChrome/sharesWidth.js +13 -0
  30. package/dist/chrome/MapChrome/sharesWidth.js.map +1 -0
  31. package/dist/chrome/MapReadout/MapReadout.js +199 -0
  32. package/dist/chrome/MapReadout/MapReadout.js.map +1 -0
  33. package/dist/chrome/MapReadout/MapReadout.styles.js +14 -0
  34. package/dist/chrome/MapReadout/MapReadout.styles.js.map +1 -0
  35. package/dist/chrome/Sheet/Sheet.js +412 -0
  36. package/dist/chrome/Sheet/Sheet.js.map +1 -0
  37. package/dist/chrome/Sheet/Sheet.styles.js +14 -0
  38. package/dist/chrome/Sheet/Sheet.styles.js.map +1 -0
  39. package/dist/chrome/focusRegistry.js +76 -0
  40. package/dist/chrome/focusRegistry.js.map +1 -0
  41. package/dist/chrome/layoutContext.js +30 -0
  42. package/dist/chrome/layoutContext.js.map +1 -0
  43. package/dist/chrome/useScrollEdges.js +53 -0
  44. package/dist/chrome/useScrollEdges.js.map +1 -0
  45. package/dist/host/MapContext.js +16 -0
  46. package/dist/host/MapContext.js.map +1 -0
  47. package/dist/host/MapView.js +189 -0
  48. package/dist/host/MapView.js.map +1 -0
  49. package/dist/host/MapView.styles.js +16 -0
  50. package/dist/host/MapView.styles.js.map +1 -0
  51. package/dist/host/overlays/AccuracyCircle.js +36 -0
  52. package/dist/host/overlays/AccuracyCircle.js.map +1 -0
  53. package/dist/host/overlays/CentreCrosshair.js +40 -0
  54. package/dist/host/overlays/CentreCrosshair.js.map +1 -0
  55. package/dist/host/overlays/DrawOverlay.js +221 -0
  56. package/dist/host/overlays/DrawOverlay.js.map +1 -0
  57. package/dist/host/overlays/MapOverlayLayer.js +27 -0
  58. package/dist/host/overlays/MapOverlayLayer.js.map +1 -0
  59. package/dist/host/overlays/MeasureOverlay.js +87 -0
  60. package/dist/host/overlays/MeasureOverlay.js.map +1 -0
  61. package/dist/host/overlays/PinMarker.js +40 -0
  62. package/dist/host/overlays/PinMarker.js.map +1 -0
  63. package/dist/host/overlays/geometry.js +41 -0
  64. package/dist/host/overlays/geometry.js.map +1 -0
  65. package/dist/host/overlays/overlays.styles.js +27 -0
  66. package/dist/host/overlays/overlays.styles.js.map +1 -0
  67. package/dist/host/pointerTargets.js +22 -0
  68. package/dist/host/pointerTargets.js.map +1 -0
  69. package/dist/host/useLongPress.js +102 -0
  70. package/dist/host/useLongPress.js.map +1 -0
  71. package/dist/host/useMapEngine.js +352 -0
  72. package/dist/host/useMapEngine.js.map +1 -0
  73. package/dist/host/usePointerPosition.js +60 -0
  74. package/dist/host/usePointerPosition.js.map +1 -0
  75. package/dist/index.d.ts +3845 -0
  76. package/dist/index.js +89 -0
  77. package/dist/layers/CatalogueStatus.js +138 -0
  78. package/dist/layers/CatalogueStatus.js.map +1 -0
  79. package/dist/layers/DateTimeControl.js +101 -0
  80. package/dist/layers/DateTimeControl.js.map +1 -0
  81. package/dist/layers/FeatureCard.js +147 -0
  82. package/dist/layers/FeatureCard.js.map +1 -0
  83. package/dist/layers/FeatureChoices.js +101 -0
  84. package/dist/layers/FeatureChoices.js.map +1 -0
  85. package/dist/layers/FeatureGlyph.js +56 -0
  86. package/dist/layers/FeatureGlyph.js.map +1 -0
  87. package/dist/layers/IdentifyStatus.js +36 -0
  88. package/dist/layers/IdentifyStatus.js.map +1 -0
  89. package/dist/layers/LayerItem.js +321 -0
  90. package/dist/layers/LayerItem.js.map +1 -0
  91. package/dist/layers/LayerKey.js +36 -0
  92. package/dist/layers/LayerKey.js.map +1 -0
  93. package/dist/layers/Layers.styles.js +50 -0
  94. package/dist/layers/Layers.styles.js.map +1 -0
  95. package/dist/layers/LayersSection.js +267 -0
  96. package/dist/layers/LayersSection.js.map +1 -0
  97. package/dist/layers/MapDataLayers.js +261 -0
  98. package/dist/layers/MapDataLayers.js.map +1 -0
  99. package/dist/layers/MapKey.js +131 -0
  100. package/dist/layers/MapKey.js.map +1 -0
  101. package/dist/layers/MapKey.styles.js +16 -0
  102. package/dist/layers/MapKey.styles.js.map +1 -0
  103. package/dist/layers/MarkerGlyph.js +84 -0
  104. package/dist/layers/MarkerGlyph.js.map +1 -0
  105. package/dist/layers/SelectionProvider.js +27 -0
  106. package/dist/layers/SelectionProvider.js.map +1 -0
  107. package/dist/layers/ShapeGlyph.js +122 -0
  108. package/dist/layers/ShapeGlyph.js.map +1 -0
  109. package/dist/layers/TurnOffActions.js +147 -0
  110. package/dist/layers/TurnOffActions.js.map +1 -0
  111. package/dist/layers/answersTap.js +16 -0
  112. package/dist/layers/answersTap.js.map +1 -0
  113. package/dist/layers/catalogueNotice.js +65 -0
  114. package/dist/layers/catalogueNotice.js.map +1 -0
  115. package/dist/layers/catalogueReconcile.js +55 -0
  116. package/dist/layers/catalogueReconcile.js.map +1 -0
  117. package/dist/layers/catalogueView.js +32 -0
  118. package/dist/layers/catalogueView.js.map +1 -0
  119. package/dist/layers/featureTitle.js +14 -0
  120. package/dist/layers/featureTitle.js.map +1 -0
  121. package/dist/layers/identifyFeedback.js +30 -0
  122. package/dist/layers/identifyFeedback.js.map +1 -0
  123. package/dist/layers/identifyRun.js +148 -0
  124. package/dist/layers/identifyRun.js.map +1 -0
  125. package/dist/layers/layerStatus.js +13 -0
  126. package/dist/layers/layerStatus.js.map +1 -0
  127. package/dist/layers/loadOutcome.js +107 -0
  128. package/dist/layers/loadOutcome.js.map +1 -0
  129. package/dist/layers/loadReport.js +33 -0
  130. package/dist/layers/loadReport.js.map +1 -0
  131. package/dist/layers/loadRequests.js +73 -0
  132. package/dist/layers/loadRequests.js.map +1 -0
  133. package/dist/layers/mapFeatures.js +307 -0
  134. package/dist/layers/mapFeatures.js.map +1 -0
  135. package/dist/layers/mapKeyBlocks.js +24 -0
  136. package/dist/layers/mapKeyBlocks.js.map +1 -0
  137. package/dist/layers/reveal.js +119 -0
  138. package/dist/layers/reveal.js.map +1 -0
  139. package/dist/layers/selectionMessages.js +53 -0
  140. package/dist/layers/selectionMessages.js.map +1 -0
  141. package/dist/layers/selectionResolve.js +111 -0
  142. package/dist/layers/selectionResolve.js.map +1 -0
  143. package/dist/layers/useDataLayers.js +940 -0
  144. package/dist/layers/useDataLayers.js.map +1 -0
  145. package/dist/layers/useFeatureSelection.js +179 -0
  146. package/dist/layers/useFeatureSelection.js.map +1 -0
  147. package/dist/layers/useScrolls.js +37 -0
  148. package/dist/layers/useScrolls.js.map +1 -0
  149. package/dist/panels/BasemapPicker/BasemapPicker.js +169 -0
  150. package/dist/panels/BasemapPicker/BasemapPicker.js.map +1 -0
  151. package/dist/panels/BasemapPicker/BasemapPicker.styles.js +42 -0
  152. package/dist/panels/BasemapPicker/BasemapPicker.styles.js.map +1 -0
  153. package/dist/panels/ExportSection/ExportSection.js +91 -0
  154. package/dist/panels/ExportSection/ExportSection.js.map +1 -0
  155. package/dist/panels/HelpSection/HelpSection.js +163 -0
  156. package/dist/panels/HelpSection/HelpSection.js.map +1 -0
  157. package/dist/panels/HelpSection/HelpSection.styles.js +9 -0
  158. package/dist/panels/HelpSection/HelpSection.styles.js.map +1 -0
  159. package/dist/panels/PinSection/PinSection.js +39 -0
  160. package/dist/panels/PinSection/PinSection.js.map +1 -0
  161. package/dist/panels/Section/Section.js +43 -0
  162. package/dist/panels/Section/Section.js.map +1 -0
  163. package/dist/panels/Section/Section.styles.js +13 -0
  164. package/dist/panels/Section/Section.styles.js.map +1 -0
  165. package/dist/panels/SettingsSection/LanguageField.js +126 -0
  166. package/dist/panels/SettingsSection/LanguageField.js.map +1 -0
  167. package/dist/panels/SettingsSection/SettingsSection.js +175 -0
  168. package/dist/panels/SettingsSection/SettingsSection.js.map +1 -0
  169. package/dist/panels/SettingsSection/SettingsSection.styles.js +9 -0
  170. package/dist/panels/SettingsSection/SettingsSection.styles.js.map +1 -0
  171. package/dist/panels/ShapesSection/ShapesSection.js +229 -0
  172. package/dist/panels/ShapesSection/ShapesSection.js.map +1 -0
  173. package/dist/panels/ShapesSection/ShapesSection.styles.js +7 -0
  174. package/dist/panels/ShapesSection/ShapesSection.styles.js.map +1 -0
  175. package/dist/panels/SheetContent/SheetContent.js +92 -0
  176. package/dist/panels/SheetContent/SheetContent.js.map +1 -0
  177. package/dist/panels/SheetContent/SheetContent.styles.js +6 -0
  178. package/dist/panels/SheetContent/SheetContent.styles.js.map +1 -0
  179. package/dist/services/ServicesProvider.js +42 -0
  180. package/dist/services/ServicesProvider.js.map +1 -0
  181. package/dist/services/activeMessages.js +140 -0
  182. package/dist/services/activeMessages.js.map +1 -0
  183. package/dist/services/basemapAvailability.js +78 -0
  184. package/dist/services/basemapAvailability.js.map +1 -0
  185. package/dist/services/englishMessages.js +10 -0
  186. package/dist/services/englishMessages.js.map +1 -0
  187. package/dist/services/hooks.js +214 -0
  188. package/dist/services/hooks.js.map +1 -0
  189. package/dist/styles.css +2866 -0
  190. package/dist/styles.css.d.ts +1 -0
  191. package/dist/tools/Directions/Directions.styles.js +25 -0
  192. package/dist/tools/Directions/Directions.styles.js.map +1 -0
  193. package/dist/tools/Directions/DirectionsOverlay.js +46 -0
  194. package/dist/tools/Directions/DirectionsOverlay.js.map +1 -0
  195. package/dist/tools/Directions/DirectionsPanel.js +428 -0
  196. package/dist/tools/Directions/DirectionsPanel.js.map +1 -0
  197. package/dist/tools/Directions/MapDirections.js +84 -0
  198. package/dist/tools/Directions/MapDirections.js.map +1 -0
  199. package/dist/tools/Directions/useDirections.js +226 -0
  200. package/dist/tools/Directions/useDirections.js.map +1 -0
  201. package/dist/tools/Directions/useFreeCentre.js +30 -0
  202. package/dist/tools/Directions/useFreeCentre.js.map +1 -0
  203. package/dist/tools/DrawToolbar/DrawMapBindings.js +34 -0
  204. package/dist/tools/DrawToolbar/DrawMapBindings.js.map +1 -0
  205. package/dist/tools/DrawToolbar/DrawToolbar.js +296 -0
  206. package/dist/tools/DrawToolbar/DrawToolbar.js.map +1 -0
  207. package/dist/tools/DrawToolbar/DrawToolbar.styles.js +21 -0
  208. package/dist/tools/DrawToolbar/DrawToolbar.styles.js.map +1 -0
  209. package/dist/tools/DrawToolbar/imageDrawing.js +24 -0
  210. package/dist/tools/DrawToolbar/imageDrawing.js.map +1 -0
  211. package/dist/tools/DrawToolbar/useDraw.js +543 -0
  212. package/dist/tools/DrawToolbar/useDraw.js.map +1 -0
  213. package/dist/tools/MeasureToolbar/MeasureToolbar.js +116 -0
  214. package/dist/tools/MeasureToolbar/MeasureToolbar.js.map +1 -0
  215. package/dist/tools/MeasureToolbar/MeasureToolbar.styles.js +12 -0
  216. package/dist/tools/MeasureToolbar/MeasureToolbar.styles.js.map +1 -0
  217. package/dist/tools/MeasureToolbar/useMeasure.js +75 -0
  218. package/dist/tools/MeasureToolbar/useMeasure.js.map +1 -0
  219. package/dist/tools/PinCard/PinCard.js +174 -0
  220. package/dist/tools/PinCard/PinCard.js.map +1 -0
  221. package/dist/tools/PinCard/PinCard.styles.js +16 -0
  222. package/dist/tools/PinCard/PinCard.styles.js.map +1 -0
  223. package/dist/tools/PinCard/useReverseAddress.js +77 -0
  224. package/dist/tools/PinCard/useReverseAddress.js.map +1 -0
  225. package/dist/tools/SearchPill/SearchPill.js +292 -0
  226. package/dist/tools/SearchPill/SearchPill.js.map +1 -0
  227. package/dist/tools/SearchPill/SearchPill.styles.js +16 -0
  228. package/dist/tools/SearchPill/SearchPill.styles.js.map +1 -0
  229. package/dist/tools/SearchPill/SearchPillSkeleton.js +41 -0
  230. package/dist/tools/SearchPill/SearchPillSkeleton.js.map +1 -0
  231. package/dist/tools/SearchPill/useSearch.js +143 -0
  232. package/dist/tools/SearchPill/useSearch.js.map +1 -0
  233. package/dist/tools/SearchPill/useSuggestions.js +105 -0
  234. package/dist/tools/SearchPill/useSuggestions.js.map +1 -0
  235. package/dist/tools/Tour/TourCard.js +156 -0
  236. package/dist/tools/Tour/TourCard.js.map +1 -0
  237. package/dist/tools/Tour/TourCard.styles.js +10 -0
  238. package/dist/tools/Tour/TourCard.styles.js.map +1 -0
  239. package/dist/tools/Tour/useTour.js +110 -0
  240. package/dist/tools/Tour/useTour.js.map +1 -0
  241. package/dist/tools/locate/useLocate.js +94 -0
  242. package/dist/tools/locate/useLocate.js.map +1 -0
  243. package/dist/ui/Button/Button.js +36 -0
  244. package/dist/ui/Button/Button.js.map +1 -0
  245. package/dist/ui/Button/Button.styles.js +17 -0
  246. package/dist/ui/Button/Button.styles.js.map +1 -0
  247. package/dist/ui/Chip/Chip.js +37 -0
  248. package/dist/ui/Chip/Chip.js.map +1 -0
  249. package/dist/ui/Chip/Chip.styles.js +29 -0
  250. package/dist/ui/Chip/Chip.styles.js.map +1 -0
  251. package/dist/ui/ControlGroup/ControlGroup.js +23 -0
  252. package/dist/ui/ControlGroup/ControlGroup.js.map +1 -0
  253. package/dist/ui/ControlGroup/ControlGroup.styles.js +6 -0
  254. package/dist/ui/ControlGroup/ControlGroup.styles.js.map +1 -0
  255. package/dist/ui/EmptyState/EmptyState.js +37 -0
  256. package/dist/ui/EmptyState/EmptyState.js.map +1 -0
  257. package/dist/ui/EmptyState/EmptyState.styles.js +10 -0
  258. package/dist/ui/EmptyState/EmptyState.styles.js.map +1 -0
  259. package/dist/ui/Icon/Icon.js +28 -0
  260. package/dist/ui/Icon/Icon.js.map +1 -0
  261. package/dist/ui/Icon/Icon.styles.js +8 -0
  262. package/dist/ui/Icon/Icon.styles.js.map +1 -0
  263. package/dist/ui/IconButton/IconButton.js +47 -0
  264. package/dist/ui/IconButton/IconButton.js.map +1 -0
  265. package/dist/ui/IconButton/IconButton.styles.js +27 -0
  266. package/dist/ui/IconButton/IconButton.styles.js.map +1 -0
  267. package/dist/ui/Isolate/Isolate.js +26 -0
  268. package/dist/ui/Isolate/Isolate.js.map +1 -0
  269. package/dist/ui/Isolate/fillSlots.js +27 -0
  270. package/dist/ui/Isolate/fillSlots.js.map +1 -0
  271. package/dist/ui/ListRow/ListRow.js +59 -0
  272. package/dist/ui/ListRow/ListRow.js.map +1 -0
  273. package/dist/ui/ListRow/ListRow.styles.js +30 -0
  274. package/dist/ui/ListRow/ListRow.styles.js.map +1 -0
  275. package/dist/ui/LiveRegion/LiveRegion.js +88 -0
  276. package/dist/ui/LiveRegion/LiveRegion.js.map +1 -0
  277. package/dist/ui/LiveRegion/announcer.js +114 -0
  278. package/dist/ui/LiveRegion/announcer.js.map +1 -0
  279. package/dist/ui/SegmentedControl/SegmentedControl.js +55 -0
  280. package/dist/ui/SegmentedControl/SegmentedControl.js.map +1 -0
  281. package/dist/ui/SegmentedControl/SegmentedControl.styles.js +9 -0
  282. package/dist/ui/SegmentedControl/SegmentedControl.styles.js.map +1 -0
  283. package/dist/ui/SkipLink/SkipLink.js +35 -0
  284. package/dist/ui/SkipLink/SkipLink.js.map +1 -0
  285. package/dist/ui/SkipLink/SkipLink.styles.js +6 -0
  286. package/dist/ui/SkipLink/SkipLink.styles.js.map +1 -0
  287. package/dist/ui/Slider/Slider.js +68 -0
  288. package/dist/ui/Slider/Slider.js.map +1 -0
  289. package/dist/ui/Slider/Slider.styles.js +13 -0
  290. package/dist/ui/Slider/Slider.styles.js.map +1 -0
  291. package/dist/ui/StatusMessage/StatusMessage.js +124 -0
  292. package/dist/ui/StatusMessage/StatusMessage.js.map +1 -0
  293. package/dist/ui/StatusMessage/StatusMessage.styles.js +28 -0
  294. package/dist/ui/StatusMessage/StatusMessage.styles.js.map +1 -0
  295. package/dist/ui/StatusMessage/StatusMessageFocus.js +30 -0
  296. package/dist/ui/StatusMessage/StatusMessageFocus.js.map +1 -0
  297. package/dist/ui/Surface/Surface.js +22 -0
  298. package/dist/ui/Surface/Surface.js.map +1 -0
  299. package/dist/ui/Surface/Surface.styles.js +27 -0
  300. package/dist/ui/Surface/Surface.styles.js.map +1 -0
  301. package/dist/ui/Switch/Switch.js +58 -0
  302. package/dist/ui/Switch/Switch.js.map +1 -0
  303. package/dist/ui/Switch/Switch.styles.js +13 -0
  304. package/dist/ui/Switch/Switch.styles.js.map +1 -0
  305. package/dist/ui/Tooltip/Tooltip.js +66 -0
  306. package/dist/ui/Tooltip/Tooltip.js.map +1 -0
  307. package/dist/ui/Tooltip/Tooltip.styles.js +6 -0
  308. package/dist/ui/Tooltip/Tooltip.styles.js.map +1 -0
  309. package/dist/ui/Tooltip/inheritColours.js +27 -0
  310. package/dist/ui/Tooltip/inheritColours.js.map +1 -0
  311. package/dist/ui/VisuallyHidden/VisuallyHidden.js +16 -0
  312. package/dist/ui/VisuallyHidden/VisuallyHidden.js.map +1 -0
  313. package/dist/ui/VisuallyHidden/VisuallyHidden.styles.js +6 -0
  314. package/dist/ui/VisuallyHidden/VisuallyHidden.styles.js.map +1 -0
  315. package/package.json +82 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDraw.js","names":[],"sources":["../../../src/tools/DrawToolbar/useDraw.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n announceDrawEvent,\n type Bounds,\n createDrawReducer,\n DRAW_ISSUE_MESSAGES,\n type DrawAction,\n type DrawIssue,\n type DrawKeyEvent,\n type DrawKind,\n type DrawSelection,\n type DrawShape,\n type DrawState,\n decodeShapes,\n describeAxisSuggestion,\n describeShapeImport,\n distanceMetres,\n draftOf,\n drawKeyCommand,\n editHandlesFor,\n encodeShapes,\n exportableShapes,\n FileOpenError,\n formatShapeMeasure,\n initialDrawState,\n type LatLng,\n MAX_DRAWING_SHAPES,\n MAX_IMPORT_BYTES,\n MAX_SHARE_SHAPES,\n type MapAdapter,\n type MapClickEvent,\n type MapEditHandle,\n type MapHandleDrag,\n type MapProjection,\n type Message,\n message,\n type ParsedHandleId,\n parseHandleId,\n parseShapeFile,\n pickShape,\n SHAPE_FILE_TYPES,\n selectedShape,\n shapeInputBounds,\n shapesToCsv,\n shapesToGeoJsonText,\n shapesToWkt,\n suggestWktAxisOrder,\n type UnitSystem,\n unsharableShapes,\n validateShape,\n type WktAxisOrder,\n} from \"@mapcairn/core\";\nimport { useLatestRef } from \"@mapcairn/react\";\nimport {\n useCallback,\n useEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n} from \"react\";\nimport { overlayPlacement } from \"../../host/overlays/geometry\";\nimport {\n useClipboard,\n useFileOpener,\n useFileSaver,\n useFormatMessage,\n useMessages,\n useSettings,\n useUrlState,\n} from \"../../services\";\nimport { useAnnounce } from \"../../ui/LiveRegion\";\n\n/**\n * How long a moved vertex must stay still before the new measure is announced, in milliseconds.\n *\n * @internal\n */\nexport const DRAW_ANNOUNCE_DELAY_MS = 800;\n\n/** How near, in CSS pixels, a tap must be to a shape's edge, line or point to select it. */\nconst SHAPE_PICK_TOLERANCE_PX = 12;\n\n/** The name of the GeoJSON file. */\nconst GEOJSON_FILENAME = \"mapcairn-shapes.geojson\";\n\n/** The name of the CSV file. */\nconst CSV_FILENAME = \"mapcairn-shapes.csv\";\n\n/** The name of the WKT file. */\nconst WKT_FILENAME = \"mapcairn-shapes.wkt\";\n\n/** What to say when no file could be opened. A cancelled picker says nothing. */\nconst FILE_OPEN_MESSAGES: Readonly<\n Record<Exclude<FileOpenError[\"kind\"], \"cancelled\">, Message>\n> = {\n \"too-large\": describeShapeImport({ ok: false, refusal: \"too-large\" }),\n unreadable: message(\"tools.draw.file.unreadable\", {}),\n unsupported: message(\"tools.draw.file.unsupported\", {}),\n};\n\n/** Added to an import's result when the shapes are more than a link can carry. */\nconst LINK_LIMIT_NOTE = message(\"tools.draw.linkLimitNote\", {\n max: MAX_SHARE_SHAPES,\n});\n\n/** The outcome of an export or a copy, shown beside the buttons and announced. */\nexport interface DrawFeedback {\n readonly kind: \"success\" | \"error\";\n readonly text: string;\n /**\n * Set on an import that read nothing because the file fits only this\n * other WKT axis order: the order that {@link UseDraw.rereadImport} reads\n * the same file in.\n */\n readonly readAs?: WktAxisOrder;\n}\n\n/** Options for {@link useDraw}. */\nexport interface UseDrawOptions {\n /** The unit system for the readout and the announcements. */\n readonly units: UnitSystem;\n /** Whether the Draw tool is open. Handles, clicks and keys only work then. */\n readonly active: boolean;\n /** Returns the mounted adapter, or null. Read when a position or the map centre is needed. */\n readonly getAdapter: () => MapAdapter | null;\n}\n\n/** What {@link useDraw} returns. */\nexport interface UseDraw {\n readonly state: DrawState;\n readonly shapes: readonly DrawShape[];\n readonly mode: DrawKind;\n readonly selection: DrawSelection | null;\n /** The shape being drawn, or null. */\n readonly draft: DrawShape | null;\n /** The selected shape, or null. */\n readonly selected: DrawShape | null;\n /** A line for the toolbar, such as \"Polygon 1, 3 points\", or \"Nothing drawn yet\". */\n readonly status: string;\n /** The measures of the shape being drawn or selected, such as \"1.2 ha · 480 m\". Empty when none. */\n readonly measure: string;\n /** Why the selected shape is not valid after an edit, or null. */\n readonly issue: DrawIssue | null;\n /** What to do about {@link UseDraw.issue}, or an empty string. */\n readonly issueMessage: string;\n readonly canUndo: boolean;\n readonly canRedo: boolean;\n /** The handles to give the map adapter: those of the selected shape while the tool is open. */\n readonly handles: readonly MapEditHandle[];\n /** The handle a mouse is over, or null. */\n readonly hoveredHandle: string | null;\n /** The outcome of the last export or copy, until the shapes change. */\n readonly feedback: DrawFeedback | null;\n /** What the last import added or why it added nothing, until the shapes change again. */\n readonly importFeedback: DrawFeedback | null;\n\n readonly setMode: (kind: DrawKind) => void;\n /** Adds a point, or starts a shape, at a position. */\n readonly addPoint: (at: LatLng) => void;\n /** Adds a point at the map centre, or moves the selected vertex there. */\n readonly placeAtCentre: () => void;\n /** Moves the selected vertex to a position. */\n readonly moveSelectedTo: (at: LatLng) => void;\n /** Moves the selected vertex by screen pixels (positive x is right, positive y is down). */\n readonly nudge: (dx: number, dy: number) => void;\n readonly undo: () => void;\n readonly redo: () => void;\n readonly finish: () => void;\n readonly cancel: () => void;\n /** Removes the shape being drawn without a word, when Done closes the tool. */\n readonly discardDraft: () => void;\n /**\n * Selects a shape, and a vertex of it when `vertex` is a number. Without\n * `vertex`, a point or a circle selects its one vertex, so the arrow keys\n * and Move to map centre work on it; any other shape selects as a whole.\n */\n readonly select: (shapeId: string, vertex?: number | null) => void;\n readonly deselect: () => void;\n readonly stepVertex: (delta: 1 | -1) => void;\n /** Removes the selected vertex. */\n readonly removeVertex: () => void;\n /** Adds a vertex at the map centre after the selected one. */\n readonly insertAtCentre: () => void;\n readonly deleteSelected: () => void;\n readonly deleteShape: (shapeId: string) => void;\n readonly clear: () => void;\n /** Sets the selected circle's radius to its distance from the map centre. */\n readonly setRadiusToCentre: () => void;\n /** Multiplies the selected circle's radius. */\n readonly scaleRadius: (factor: number) => void;\n /** A click or tap on the map. Starts, extends or selects a shape. */\n readonly onMapClick: (event: Pick<MapClickEvent, \"latlng\" | \"point\">) => void;\n /** A step of a press on an edit handle, from the adapter. */\n readonly onHandleDrag: (drag: MapHandleDrag) => void;\n readonly onHandleHover: (id: string | null) => void;\n /** Runs a key press as a draw command. Returns true when it was one, so the caller can stop the key. */\n readonly keyCommand: (event: DrawKeyEvent) => boolean;\n readonly exportGeoJson: () => Promise<void>;\n readonly exportCsv: () => Promise<void>;\n readonly exportWkt: () => Promise<void>;\n /** Copies a link with the shapes in it, built from the current address. */\n readonly copyLink: () => Promise<void>;\n /**\n * Asks the person for a GeoJSON, CSV or WKT file and adds its shapes as one undo\n * step. Call it straight from a press, so the browser shows the picker.\n * @returns The box holding the shapes it added, for the map to fit, or\n * null when it added none, including when the host has no file opener.\n */\n readonly importFile: () => Promise<Bounds | null>;\n /** The order of the two numbers in a WKT position that an import reads: longitude first until changed. Kept for the session only. */\n readonly wktAxisOrder: WktAxisOrder;\n /** Chooses the order by hand. An offer to read the last file the other way, and the file it kept, are dropped. */\n readonly setWktAxisOrder: (order: WktAxisOrder) => void;\n /**\n * Reads the file whose import offered {@link DrawFeedback.readAs} again in\n * `order`, and keeps `order` as the WKT axis order.\n * @returns The box holding the shapes it added, as {@link UseDraw.importFile}\n * does, or null when it added none or there is no such file.\n */\n readonly rereadImport: (order: WktAxisOrder) => Bounds | null;\n}\n\n/** A drag in progress: which handle it began on and which vertex it moves now. */\ninterface DragSession {\n readonly shapeId: string;\n kind: \"vertex\" | \"midpoint\" | \"radius\";\n index: number;\n readonly key: string;\n}\n\n/** What pressing a handle selects: a vertex, or the shape for a radius handle. A midpoint selects nothing until it is used. */\nfunction pressAction(parsed: ParsedHandleId): DrawAction | null {\n if (parsed.kind === \"midpoint\") {\n return null;\n }\n return {\n type: \"select\",\n shapeId: parsed.shapeId,\n vertex: parsed.kind === \"vertex\" ? parsed.index : null,\n };\n}\n\n/** A tap on a midpoint adds a vertex there; a tap on anything else is already handled by the press. */\nfunction tapAction(\n current: DragSession,\n drag: MapHandleDrag,\n state: DrawState,\n projection: MapProjection,\n): DrawAction | null {\n if (drag.moved || current.kind !== \"midpoint\") {\n return null;\n }\n const handle = editHandlesFor(state.shapes, state.selection, projection).find(\n (candidate) => candidate.id === drag.id,\n );\n return handle\n ? {\n type: \"insertVertex\",\n shapeId: current.shapeId,\n index: current.index,\n at: handle.position,\n }\n : null;\n}\n\n/**\n * What a drag step does. A midpoint becomes a new vertex under the pointer,\n * which the rest of the drag then moves, so one drag is one undo step.\n */\nfunction moveAction(\n current: DragSession,\n drag: MapHandleDrag,\n state: DrawState,\n): DrawAction | null {\n if (current.kind === \"midpoint\") {\n current.kind = \"vertex\";\n return {\n type: \"insertVertex\",\n shapeId: current.shapeId,\n index: current.index,\n at: drag.latlng,\n coalesceKey: current.key,\n };\n }\n if (current.kind === \"vertex\") {\n return {\n type: \"moveVertex\",\n shapeId: current.shapeId,\n index: current.index,\n to: drag.latlng,\n coalesceKey: current.key,\n };\n }\n const middle = state.shapes.find(\n (candidate) => candidate.id === current.shapeId,\n )?.vertices[0];\n return middle\n ? {\n type: \"setRadius\",\n shapeId: current.shapeId,\n metres: distanceMetres(middle, drag.latlng),\n coalesceKey: current.key,\n }\n : null;\n}\n\nfunction initialState(\n encoded: string | undefined,\n reducer: (state: DrawState, action: DrawAction) => DrawState,\n): DrawState {\n const shapes = encoded ? decodeShapes(encoded) : null;\n return shapes\n ? reducer(initialDrawState, { type: \"load\", shapes })\n : initialDrawState;\n}\n\n/** The line for the toolbar: what is drawn or selected, or how many shapes there are. */\nfunction statusText(\n format: (message: Message) => string,\n draft: DrawShape | null,\n selected: DrawShape | null,\n count: number,\n): string {\n if (draft) {\n return format(\n message(\"tools.draw.status.drawing\", {\n label: draft.label,\n count: draft.vertices.length,\n }),\n );\n }\n if (selected) {\n return selected.label;\n }\n return format(\n count > 0\n ? message(\"tools.draw.status.shapes\", { count })\n : message(\"tools.draw.status.empty\", {}),\n );\n}\n\n/**\n * The state of the Draw tool: the shapes, what is selected, undo, and every\n * way to change them, by pointer and by keyboard.\n *\n * @remarks The pure rules live in core (`drawReducer` and friends). This hook\n * adds what needs the map and the ports: the map centre and projection for\n * \"at map centre\", nudges and shape picking; the announcer; the file saver\n * and the clipboard for export; and the address for a link with shapes.\n *\n * Shapes belong to the app, not to the toolbar, so they stay on the map when\n * the tool closes. Nothing is stored, and nothing reaches the address bar:\n * shapes are read once, from a link that carries them, and written only into\n * the link {@link UseDraw.copyLink} builds.\n *\n * Announcements follow the reducer's `lastEvent`, so a drag that moves a\n * vertex many times is announced once, {@link DRAW_ANNOUNCE_DELAY_MS} after\n * it settles, and a refusal is announced assertively.\n */\nexport function useDraw({\n units,\n active,\n getAdapter,\n}: UseDrawOptions): UseDraw {\n const announce = useAnnounce();\n const announceRef = useLatestRef(announce);\n const messages = useMessages();\n const format = useFormatMessage();\n const formatRef = useLatestRef(format);\n const fileSaver = useFileSaver();\n const clipboard = useClipboard();\n const url = useUrlState();\n const reducer = useMemo(() => createDrawReducer(messages), [messages]);\n const [state, dispatch] = useReducer(reducer, undefined, () =>\n initialState(url.read().shapes, reducer),\n );\n const stateRef = useLatestRef(state);\n const getAdapterRef = useLatestRef(getAdapter);\n const { projection } = useSettings().settings;\n const projectionRef = useLatestRef(projection);\n const activeRef = useLatestRef(active);\n const [hoveredHandle, setHoveredHandle] = useState<string | null>(null);\n const [feedback, setFeedback] = useState<DrawFeedback | null>(null);\n const [importFeedback, setImportFeedback] = useState<DrawFeedback | null>(\n null,\n );\n const fileOpener = useFileOpener();\n const importAbort = useRef<AbortController | null>(null);\n const [wktAxisOrder, setWktAxisOrder] = useState<WktAxisOrder>(\"lng-lat\");\n const wktAxisOrderRef = useLatestRef(wktAxisOrder);\n const offeredText = useRef<string | null>(null);\n const session = useRef<DragSession | null>(null);\n const dragCount = useRef(0);\n\n const { shapes, selection, lastEvent } = state;\n const draft = draftOf(state);\n const selected = selectedShape(state);\n\n // Only a new event is announced: a change of units or of the shapes alone is not.\n const unitsRef = useLatestRef(units);\n useEffect(() => {\n const text = announceDrawEvent(\n lastEvent,\n stateRef.current.shapes,\n unitsRef.current,\n );\n if (!text) {\n return;\n }\n const delay =\n lastEvent?.type === \"vertex-moved\" ? DRAW_ANNOUNCE_DELAY_MS : 0;\n const timer = setTimeout(() => {\n announceRef.current(text, {\n priority: lastEvent?.type === \"rejected\" ? \"assertive\" : \"polite\",\n });\n }, delay);\n return () => clearTimeout(timer);\n }, [lastEvent, stateRef, unitsRef, announceRef]);\n\n // What was exported or copied no longer describes the shapes once they\n // change, and an import's result lasts only through the change it made.\n // biome-ignore lint/correctness/useExhaustiveDependencies: the shapes are the trigger\n useEffect(() => {\n setFeedback(null);\n if (lastEvent?.type !== \"imported\") {\n setImportFeedback(null);\n offeredText.current = null;\n }\n }, [shapes]);\n\n useEffect(() => () => importAbort.current?.abort(), []);\n\n const act = useCallback((action: DrawAction) => dispatch(action), []);\n const setMode = useCallback(\n (kind: DrawKind) => act({ type: \"setMode\", kind }),\n [act],\n );\n const undo = useCallback(() => act({ type: \"undo\" }), [act]);\n const redo = useCallback(() => act({ type: \"redo\" }), [act]);\n const finish = useCallback(() => act({ type: \"finish\" }), [act]);\n const cancel = useCallback(() => act({ type: \"cancel\" }), [act]);\n const clear = useCallback(() => act({ type: \"clear\" }), [act]);\n const deselect = useCallback(() => act({ type: \"deselect\" }), [act]);\n const select = useCallback(\n (shapeId: string, vertex?: number | null) => {\n const shape = stateRef.current.shapes.find(\n (candidate) => candidate.id === shapeId,\n );\n // A point or a circle has one vertex that matters: its centre.\n const single = shape?.kind === \"point\" || shape?.kind === \"circle\";\n const centre = single ? 0 : null;\n act({\n type: \"select\",\n shapeId,\n vertex: vertex === undefined ? centre : vertex,\n });\n },\n [act, stateRef],\n );\n const stepVertex = useCallback(\n (delta: 1 | -1) => act({ type: \"stepVertex\", delta }),\n [act],\n );\n const deleteShape = useCallback(\n (shapeId: string) => act({ type: \"deleteShape\", shapeId }),\n [act],\n );\n const discardDraft = useCallback(() => {\n if (draftOf(stateRef.current)) {\n dispatch({ type: \"cancel\" });\n }\n }, [stateRef]);\n\n const centre = useCallback(\n () => getAdapterRef.current()?.getView().center ?? null,\n [getAdapterRef],\n );\n\n const moveSelectedTo = useCallback(\n (at: LatLng) => {\n const { selection: current } = stateRef.current;\n if (current && current.vertex !== null) {\n dispatch({\n type: \"moveVertex\",\n shapeId: current.shapeId,\n index: current.vertex,\n to: at,\n });\n }\n },\n [stateRef],\n );\n\n const addPoint = useCallback(\n (at: LatLng) => dispatch({ type: \"addVertex\", at }),\n [],\n );\n\n const placeAtCentre = useCallback(() => {\n const at = centre();\n if (!at) {\n return;\n }\n if (stateRef.current.selection?.vertex != null) {\n moveSelectedTo(at);\n } else {\n addPoint(at);\n }\n }, [centre, stateRef, moveSelectedTo, addPoint]);\n\n const nudge = useCallback(\n (dx: number, dy: number) => {\n const adapter = getAdapterRef.current();\n const current = stateRef.current;\n const shape = selectedShape(current);\n const vertex = current.selection?.vertex ?? null;\n const from =\n shape && vertex !== null ? shape.vertices[vertex] : undefined;\n if (!adapter || !shape || vertex === null || !from) {\n return;\n }\n const point = adapter.project(from);\n dispatch({\n type: \"moveVertex\",\n shapeId: shape.id,\n index: vertex,\n to: adapter.unproject({ x: point.x + dx, y: point.y + dy }),\n coalesceKey: `nudge:${shape.id}:${vertex}`,\n });\n },\n [getAdapterRef, stateRef],\n );\n\n const removeVertex = useCallback(() => {\n const current = stateRef.current.selection;\n if (current && current.vertex !== null) {\n dispatch({\n type: \"removeVertex\",\n shapeId: current.shapeId,\n index: current.vertex,\n });\n }\n }, [stateRef]);\n\n const insertAtCentre = useCallback(() => {\n const at = centre();\n const current = stateRef.current.selection;\n if (at && current && current.vertex !== null) {\n dispatch({\n type: \"insertVertex\",\n shapeId: current.shapeId,\n index: current.vertex + 1,\n at,\n });\n }\n }, [centre, stateRef]);\n\n const deleteSelected = useCallback(() => {\n const current = stateRef.current.selection;\n if (current) {\n dispatch({ type: \"deleteShape\", shapeId: current.shapeId });\n }\n }, [stateRef]);\n\n const setRadius = useCallback(\n (metres: number, key?: string) => {\n const shape = selectedShape(stateRef.current);\n if (shape?.kind === \"circle\") {\n dispatch({\n type: \"setRadius\",\n shapeId: shape.id,\n metres,\n ...(key === undefined ? {} : { coalesceKey: key }),\n });\n }\n },\n [stateRef],\n );\n\n const setRadiusToCentre = useCallback(() => {\n const shape = selectedShape(stateRef.current);\n const at = centre();\n const middle = shape?.vertices[0];\n if (shape?.kind === \"circle\" && at && middle) {\n setRadius(distanceMetres(middle, at));\n }\n }, [centre, setRadius, stateRef]);\n\n const scaleRadius = useCallback(\n (factor: number) => {\n const shape = selectedShape(stateRef.current);\n if (shape?.kind === \"circle\" && shape.radiusMetres !== undefined) {\n setRadius(shape.radiusMetres * factor, \"radius-scale\");\n }\n },\n [setRadius, stateRef],\n );\n\n const onMapClick = useCallback(\n (event: Pick<MapClickEvent, \"latlng\" | \"point\">) => {\n if (!activeRef.current) {\n return;\n }\n const adapter = getAdapterRef.current();\n const current = stateRef.current;\n if (adapter && !draftOf(current)) {\n const hit = pickShape(\n current.shapes,\n event.point,\n overlayPlacement(adapter, adapter.getView(), projectionRef.current),\n SHAPE_PICK_TOLERANCE_PX,\n false,\n );\n if (hit) {\n select(hit);\n return;\n }\n }\n dispatch({ type: \"addVertex\", at: event.latlng });\n },\n [activeRef, getAdapterRef, stateRef, select, projectionRef],\n );\n\n const onHandleDrag = useCallback(\n (drag: MapHandleDrag) => {\n if (drag.phase === \"start\") {\n const parsed = parseHandleId(drag.id);\n session.current = parsed\n ? {\n shapeId: parsed.shapeId,\n kind: parsed.kind,\n index: parsed.index,\n key: `drag:${++dragCount.current}`,\n }\n : null;\n const action = parsed ? pressAction(parsed) : null;\n if (action) {\n dispatch(action);\n }\n return;\n }\n const current = session.current;\n if (!current) {\n return;\n }\n if (drag.phase === \"end\") {\n session.current = null;\n }\n const action =\n drag.phase === \"end\"\n ? tapAction(current, drag, stateRef.current, projectionRef.current)\n : moveAction(current, drag, stateRef.current);\n if (action) {\n dispatch(action);\n }\n },\n [stateRef, projectionRef],\n );\n\n const keyCommand = useCallback(\n (event: DrawKeyEvent): boolean => {\n if (!activeRef.current) {\n return false;\n }\n const command = drawKeyCommand(stateRef.current, event);\n if (!command) {\n return false;\n }\n if (command.type === \"dispatch\") {\n dispatch(command.action);\n } else if (command.type === \"nudge\") {\n nudge(command.dx, command.dy);\n } else {\n placeAtCentre();\n }\n return true;\n },\n [activeRef, stateRef, nudge, placeAtCentre],\n );\n\n const report = useCallback(\n (kind: DrawFeedback[\"kind\"], said: Message) => {\n setFeedback({ kind, text: formatRef.current(said) });\n announceRef.current(said, {\n priority: kind === \"error\" ? \"assertive\" : \"polite\",\n });\n },\n [announceRef, formatRef],\n );\n\n const exportFile = useCallback(\n async (\n filename: string,\n mimeType: string,\n build: (shapes: readonly DrawShape[]) => string,\n ) => {\n const ready = exportableShapes(stateRef.current.shapes);\n if (ready.length === 0) {\n report(\"error\", message(\"tools.draw.nothingToExport\", {}));\n return;\n }\n const result = await fileSaver.save({\n filename,\n mimeType,\n content: build(ready),\n });\n if (result.ok) {\n report(\n \"success\",\n message(\"tools.draw.saved\", { count: ready.length, filename }),\n );\n } else {\n report(\"error\", message(\"tools.draw.saveFailed\", {}));\n }\n },\n [fileSaver, report, stateRef],\n );\n\n const exportGeoJson = useCallback(\n () =>\n exportFile(GEOJSON_FILENAME, \"application/geo+json\", shapesToGeoJsonText),\n [exportFile],\n );\n\n const exportCsv = useCallback(\n () => exportFile(CSV_FILENAME, \"text/csv;charset=utf-8\", shapesToCsv),\n [exportFile],\n );\n\n const exportWkt = useCallback(\n () => exportFile(WKT_FILENAME, \"text/plain;charset=utf-8\", shapesToWkt),\n [exportFile],\n );\n\n const copyLink = useCallback(async () => {\n const current = stateRef.current.shapes;\n const encoded = encodeShapes(current);\n const leftOut = unsharableShapes(current).length;\n if (encoded === null) {\n report(\"error\", message(\"tools.draw.tooManyToShare\", {}));\n return;\n }\n if (encoded === \"\") {\n report(\n \"error\",\n leftOut === 0\n ? message(\"tools.draw.nothingToShare\", {})\n : message(\"tools.draw.nothingToCopy\", { count: leftOut }),\n );\n return;\n }\n const result = await clipboard.writeText(\n url.link({ ...url.read(), shapes: encoded }),\n );\n if (!result.ok) {\n report(\"error\", message(\"tools.draw.linkCopyFailed\", {}));\n return;\n }\n report(\n \"success\",\n leftOut === 0\n ? message(\"tools.draw.linkCopied\", {})\n : message(\"tools.draw.linkCopiedLeftOut\", { count: leftOut }),\n );\n }, [clipboard, report, stateRef, url]);\n\n const reportImport = useCallback(\n (kind: DrawFeedback[\"kind\"], said: Message, readAs?: WktAxisOrder) => {\n setImportFeedback({\n kind,\n text: formatRef.current(said),\n ...(readAs ? { readAs } : {}),\n });\n announceRef.current(said, {\n priority: kind === \"error\" ? \"assertive\" : \"polite\",\n });\n },\n [announceRef, formatRef],\n );\n\n /** Adds what the text holds, read in `order`, or says why not; the box of the shapes it added. */\n const importText = useCallback(\n (text: string, order: WktAxisOrder): Bounds | null => {\n const suggested = suggestWktAxisOrder(text, order);\n if (suggested) {\n offeredText.current = text;\n reportImport(\"error\", describeAxisSuggestion(suggested), suggested);\n return null;\n }\n offeredText.current = null;\n const result = parseShapeFile(text, { wktAxisOrder: order });\n const words = describeShapeImport(result);\n if (!result.ok || result.shapes.length === 0) {\n reportImport(\"error\", words);\n return null;\n }\n if (\n stateRef.current.shapes.length + result.shapes.length >\n MAX_DRAWING_SHAPES\n ) {\n reportImport(\n \"error\",\n describeShapeImport({ ok: false, refusal: \"drawing-full\" }),\n );\n return null;\n }\n const total =\n exportableShapes(stateRef.current.shapes).length + result.shapes.length;\n dispatch({ type: \"import\", shapes: result.shapes });\n reportImport(\n \"success\",\n total > MAX_SHARE_SHAPES\n ? message(\"common.followedBy\", {\n first: words,\n second: LINK_LIMIT_NOTE,\n })\n : words,\n );\n return shapeInputBounds(result.shapes) ?? null;\n },\n [reportImport, stateRef],\n );\n\n /** A choice made by hand: the offer to read a file the other way no longer applies, so it and the file it kept are dropped. */\n const chooseWktAxisOrder = useCallback((order: WktAxisOrder) => {\n setWktAxisOrder(order);\n offeredText.current = null;\n setImportFeedback((current) => (current?.readAs ? null : current));\n }, []);\n\n const rereadImport = useCallback(\n (order: WktAxisOrder): Bounds | null => {\n setWktAxisOrder(order);\n return offeredText.current === null\n ? null\n : importText(offeredText.current, order);\n },\n [importText],\n );\n\n const importFile = useCallback(async (): Promise<Bounds | null> => {\n if (!fileOpener) {\n return null;\n }\n importAbort.current?.abort();\n const controller = new AbortController();\n importAbort.current = controller;\n let text: string;\n try {\n // Opened before any await, so the browser still sees the press.\n ({ text } = await fileOpener.open({\n accept: SHAPE_FILE_TYPES,\n maxBytes: MAX_IMPORT_BYTES,\n signal: controller.signal,\n }));\n } catch (error) {\n const kind = error instanceof FileOpenError ? error.kind : \"unreadable\";\n if (kind !== \"cancelled\") {\n offeredText.current = null;\n reportImport(\"error\", FILE_OPEN_MESSAGES[kind]);\n }\n return null;\n }\n return importText(text, wktAxisOrderRef.current);\n }, [fileOpener, importText, reportImport, wktAxisOrderRef]);\n\n const handles = useMemo(\n () => (active ? editHandlesFor(shapes, selection, projection) : []),\n [active, shapes, selection, projection],\n );\n\n const issue = useMemo(\n () => (selected?.done ? validateShape(selected) : null),\n [selected],\n );\n\n const focus = draft ?? selected;\n const status = statusText(format, draft, selected, shapes.length);\n\n return {\n state,\n shapes,\n mode: state.mode,\n selection,\n draft,\n selected,\n status,\n measure: focus ? formatShapeMeasure(focus, units, messages) : \"\",\n issue,\n issueMessage: issue ? formatRef.current(DRAW_ISSUE_MESSAGES[issue]) : \"\",\n canUndo: state.past.length > 0,\n canRedo: state.future.length > 0,\n handles,\n hoveredHandle,\n feedback,\n importFeedback,\n setMode,\n addPoint,\n placeAtCentre,\n moveSelectedTo,\n nudge,\n undo,\n redo,\n finish,\n cancel,\n discardDraft,\n select,\n deselect,\n stepVertex,\n removeVertex,\n insertAtCentre,\n deleteSelected,\n deleteShape,\n clear,\n setRadiusToCentre,\n scaleRadius,\n onMapClick,\n onHandleDrag,\n onHandleHover: setHoveredHandle,\n keyCommand,\n exportGeoJson,\n exportCsv,\n exportWkt,\n copyLink,\n importFile,\n wktAxisOrder,\n setWktAxisOrder: chooseWktAxisOrder,\n rereadImport,\n };\n}\n"],"mappings":";;;;;;;;;;;;AA+EA,IAAa,yBAAyB;;AAGtC,IAAM,0BAA0B;;AAGhC,IAAM,mBAAmB;;AAGzB,IAAM,eAAe;;AAGrB,IAAM,eAAe;;AAGrB,IAAM,qBAEF;CACF,aAAa,oBAAoB;EAAE,IAAI;EAAO,SAAS;CAAY,CAAC;CACpE,YAAY,QAAQ,8BAA8B,CAAC,CAAC;CACpD,aAAa,QAAQ,+BAA+B,CAAC,CAAC;AACxD;;AAGA,IAAM,kBAAkB,QAAQ,4BAA4B,EAC1D,KAAK,iBACP,CAAC;;AAgID,SAAS,YAAY,QAA2C;CAC9D,IAAI,OAAO,SAAS,YAClB,OAAO;CAET,OAAO;EACL,MAAM;EACN,SAAS,OAAO;EAChB,QAAQ,OAAO,SAAS,WAAW,OAAO,QAAQ;CACpD;AACF;;AAGA,SAAS,UACP,SACA,MACA,OACA,YACmB;CACnB,IAAI,KAAK,SAAS,QAAQ,SAAS,YACjC,OAAO;CAET,MAAM,SAAS,eAAe,MAAM,QAAQ,MAAM,WAAW,UAAU,CAAC,CAAC,MACtE,cAAc,UAAU,OAAO,KAAK,EACvC;CACA,OAAO,SACH;EACE,MAAM;EACN,SAAS,QAAQ;EACjB,OAAO,QAAQ;EACf,IAAI,OAAO;CACb,IACA;AACN;;;;;AAMA,SAAS,WACP,SACA,MACA,OACmB;CACnB,IAAI,QAAQ,SAAS,YAAY;EAC/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X;CAEA,MAAM,QAAQ,SAAS;CACvB,MAAM,SAAS,WAAW,QAAQ,OAAO,UAAU,OAAO,MAAM;CAEhE,OAAO;EACL;EACA;EACA,MAAM,MAAM;EACZ;EACA;EACA;EACA;EACA,SAAS,QAAQ,mBAAmB,OAAO,OAAO,QAAQ,IAAI;EAC9D;EACA,cAAc,QAAQ,UAAU,QAAQ,oBAAoB,MAAM,IAAI;EACtE,SAAS,MAAM,KAAK,SAAS;EAC7B,SAAS,MAAM,OAAO,SAAS;EAC/B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,eAAe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA,iBAAiB;EACjB;CACF;AACF"}
@@ -0,0 +1,116 @@
1
+ import { useMessages } from "../../services/hooks.js";
2
+ import { Button } from "../../ui/Button/Button.js";
3
+ import { IconButton } from "../../ui/IconButton/IconButton.js";
4
+ import { Isolate } from "../../ui/Isolate/Isolate.js";
5
+ import { SegmentedControl } from "../../ui/SegmentedControl/SegmentedControl.js";
6
+ import { Surface } from "../../ui/Surface/Surface.js";
7
+ import { VisuallyHidden } from "../../ui/VisuallyHidden/VisuallyHidden.js";
8
+ import { actions, hint, modes, readout, root, row, toolbar } from "./MeasureToolbar.styles.js";
9
+ import { Crosshair, Trash2, Undo2 } from "lucide-react";
10
+ import { useEffect, useRef } from "react";
11
+ import { jsx, jsxs } from "react/jsx-runtime";
12
+ // src/tools/MeasureToolbar/MeasureToolbar.tsx
13
+ /**
14
+ * The measure toolbar: a Distance or Area switch, the running total, buttons
15
+ * to add a point at the map centre, undo and clear, and Done. It sits in a
16
+ * landmark named "Measurement", so it is inside a landmark wherever the host
17
+ * places it.
18
+ *
19
+ * On mount focus moves to its first button, because the person has just
20
+ * chosen Measure and the next thing to do is here. The bottom-centre slot it
21
+ * sits in is what the slots below it ride above.
22
+ * @remarks The total is plain text. It is read out by the announcer after the
23
+ * points settle (see `useMeasure`), not by a live region of its own.
24
+ * The controls are all reachable with Tab rather than a single roving tab
25
+ * stop, which keeps the mode switch's own arrow keys unambiguous.
26
+ * The published edge is `getBoundingClientRect().top`, in viewport pixels,
27
+ * which equals the chrome container's own coordinates when the container
28
+ * fills the viewport.
29
+ */
30
+ function MeasureToolbar({ measure, onAddPointAtCentre, onDone }) {
31
+ const { mode, points, readout: readout$1, setMode, undo, clear } = measure;
32
+ const { t } = useMessages();
33
+ const modeOptions = [{
34
+ value: "distance",
35
+ label: t("tools.measure.distance", {})
36
+ }, {
37
+ value: "area",
38
+ label: t("tools.measure.area", {})
39
+ }];
40
+ const rootRef = useRef(null);
41
+ const empty = points.length === 0;
42
+ useEffect(() => {
43
+ rootRef.current?.querySelector("button")?.focus();
44
+ }, []);
45
+ return /* @__PURE__ */ jsx("section", {
46
+ ref: rootRef,
47
+ "aria-label": t("tools.measure.region", {}),
48
+ className: root,
49
+ "data-chrome": "measure-toolbar",
50
+ children: /* @__PURE__ */ jsxs(Surface, {
51
+ role: "toolbar",
52
+ "aria-label": t("tools.measure.label", {}),
53
+ className: toolbar,
54
+ "data-testid": "measure-toolbar",
55
+ children: [
56
+ /* @__PURE__ */ jsxs("div", {
57
+ className: row,
58
+ children: [/* @__PURE__ */ jsx(SegmentedControl, {
59
+ className: modes,
60
+ label: t("tools.measure.label", {}),
61
+ options: modeOptions,
62
+ value: mode,
63
+ onValueChange: (next) => setMode(next),
64
+ "data-testid": "measure-mode"
65
+ }), /* @__PURE__ */ jsxs("p", {
66
+ className: readout,
67
+ children: [/* @__PURE__ */ jsxs(VisuallyHidden, { children: [t("tools.measure.total", {}), " "] }), /* @__PURE__ */ jsx("span", {
68
+ "data-testid": "measure-readout",
69
+ children: /* @__PURE__ */ jsx(Isolate, { children: readout$1 })
70
+ })]
71
+ })]
72
+ }),
73
+ /* @__PURE__ */ jsxs("div", {
74
+ className: row,
75
+ children: [/* @__PURE__ */ jsxs("div", {
76
+ className: actions,
77
+ children: [
78
+ /* @__PURE__ */ jsx(IconButton, {
79
+ label: t("tools.addPointAtCentre", {}),
80
+ icon: Crosshair,
81
+ "data-testid": "measure-add-point",
82
+ onClick: onAddPointAtCentre
83
+ }),
84
+ /* @__PURE__ */ jsx(IconButton, {
85
+ label: t("tools.measure.undo", {}),
86
+ icon: Undo2,
87
+ mirrorInRtl: true,
88
+ disabled: empty,
89
+ "data-testid": "measure-undo",
90
+ onClick: undo
91
+ }),
92
+ /* @__PURE__ */ jsx(IconButton, {
93
+ label: t("tools.measure.clear", {}),
94
+ icon: Trash2,
95
+ disabled: empty,
96
+ "data-testid": "measure-clear",
97
+ onClick: clear
98
+ })
99
+ ]
100
+ }), /* @__PURE__ */ jsx(Button, {
101
+ "data-testid": "measure-done",
102
+ onClick: onDone,
103
+ children: t("tools.done", {})
104
+ })]
105
+ }),
106
+ /* @__PURE__ */ jsx("p", {
107
+ className: hint,
108
+ children: t("tools.measure.hint", {})
109
+ })
110
+ ]
111
+ })
112
+ });
113
+ }
114
+ export { MeasureToolbar };
115
+
116
+ //# sourceMappingURL=MeasureToolbar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MeasureToolbar.js","names":["styles.root","styles.toolbar","styles.row","styles.modes","styles.readout","readout","styles.actions","styles.hint"],"sources":["../../../src/tools/MeasureToolbar/MeasureToolbar.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { Crosshair, Trash2, Undo2 } from \"lucide-react\";\nimport { useEffect, useRef } from \"react\";\nimport { useMessages } from \"../../services\";\nimport { Button } from \"../../ui/Button\";\nimport { IconButton } from \"../../ui/IconButton\";\nimport { Isolate } from \"../../ui/Isolate\";\nimport { SegmentedControl } from \"../../ui/SegmentedControl\";\nimport { Surface } from \"../../ui/Surface\";\nimport { VisuallyHidden } from \"../../ui/VisuallyHidden\";\nimport * as styles from \"./MeasureToolbar.css\";\nimport type { MeasureMode, UseMeasure } from \"./useMeasure\";\n\n/** Props for {@link MeasureToolbar}. */\nexport interface MeasureToolbarProps {\n /** The measurement state from `useMeasure`. */\n readonly measure: UseMeasure;\n /** Called by \"Add point at map centre\", the keyboard and single-tap way to place a point. */\n readonly onAddPointAtCentre: () => void;\n /** Called by \"Done\". */\n readonly onDone: () => void;\n}\n\n/**\n * The measure toolbar: a Distance or Area switch, the running total, buttons\n * to add a point at the map centre, undo and clear, and Done. It sits in a\n * landmark named \"Measurement\", so it is inside a landmark wherever the host\n * places it.\n *\n * On mount focus moves to its first button, because the person has just\n * chosen Measure and the next thing to do is here. The bottom-centre slot it\n * sits in is what the slots below it ride above.\n * @remarks The total is plain text. It is read out by the announcer after the\n * points settle (see `useMeasure`), not by a live region of its own.\n * The controls are all reachable with Tab rather than a single roving tab\n * stop, which keeps the mode switch's own arrow keys unambiguous.\n * The published edge is `getBoundingClientRect().top`, in viewport pixels,\n * which equals the chrome container's own coordinates when the container\n * fills the viewport.\n */\nexport function MeasureToolbar({\n measure,\n onAddPointAtCentre,\n onDone,\n}: MeasureToolbarProps) {\n const { mode, points, readout, setMode, undo, clear } = measure;\n const { t } = useMessages();\n const modeOptions = [\n { value: \"distance\", label: t(\"tools.measure.distance\", {}) },\n { value: \"area\", label: t(\"tools.measure.area\", {}) },\n ] as const;\n const rootRef = useRef<HTMLElement>(null);\n const empty = points.length === 0;\n\n useEffect(() => {\n rootRef.current?.querySelector(\"button\")?.focus();\n }, []);\n\n return (\n <section\n ref={rootRef}\n aria-label={t(\"tools.measure.region\", {})}\n className={styles.root}\n data-chrome=\"measure-toolbar\"\n >\n <Surface\n role=\"toolbar\"\n aria-label={t(\"tools.measure.label\", {})}\n className={styles.toolbar}\n data-testid=\"measure-toolbar\"\n >\n <div className={styles.row}>\n <SegmentedControl\n className={styles.modes}\n label={t(\"tools.measure.label\", {})}\n options={modeOptions}\n value={mode}\n onValueChange={(next) => setMode(next as MeasureMode)}\n data-testid=\"measure-mode\"\n />\n <p className={styles.readout}>\n <VisuallyHidden>{t(\"tools.measure.total\", {})} </VisuallyHidden>\n <span data-testid=\"measure-readout\">\n <Isolate>{readout}</Isolate>\n </span>\n </p>\n </div>\n <div className={styles.row}>\n <div className={styles.actions}>\n <IconButton\n label={t(\"tools.addPointAtCentre\", {})}\n icon={Crosshair}\n data-testid=\"measure-add-point\"\n onClick={onAddPointAtCentre}\n />\n <IconButton\n label={t(\"tools.measure.undo\", {})}\n icon={Undo2}\n mirrorInRtl\n disabled={empty}\n data-testid=\"measure-undo\"\n onClick={undo}\n />\n <IconButton\n label={t(\"tools.measure.clear\", {})}\n icon={Trash2}\n disabled={empty}\n data-testid=\"measure-clear\"\n onClick={clear}\n />\n </div>\n <Button data-testid=\"measure-done\" onClick={onDone}>\n {t(\"tools.done\", {})}\n </Button>\n </div>\n <p className={styles.hint}>{t(\"tools.measure.hint\", {})}</p>\n </Surface>\n </section>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,eAAe,EAC7B,SACA,oBACA,UACsB;CACtB,MAAM,EAAE,MAAM,QAAQ,SAAA,WAAS,SAAS,MAAM,UAAU;CACxD,MAAM,EAAE,MAAM,YAAY;CAC1B,MAAM,cAAc,CAClB;EAAE,OAAO;EAAY,OAAO,EAAE,0BAA0B,CAAC,CAAC;CAAE,GAC5D;EAAE,OAAO;EAAQ,OAAO,EAAE,sBAAsB,CAAC,CAAC;CAAE,CACtD;CACA,MAAM,UAAU,OAAoB,IAAI;CACxC,MAAM,QAAQ,OAAO,WAAW;CAEhC,gBAAgB;EACd,QAAQ,SAAS,cAAc,QAAQ,CAAC,EAAE,MAAM;CAClD,GAAG,CAAC,CAAC;CAEL,OACE,oBAAC,WAAD;EACE,KAAK;EACL,cAAY,EAAE,wBAAwB,CAAC,CAAC;EACxC,WAAWA;EACX,eAAY;EAEZ,UAAA,qBAAC,SAAD;GACE,MAAK;GACL,cAAY,EAAE,uBAAuB,CAAC,CAAC;GACvC,WAAWC;G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var row = "ph4deg2";
6
+ var modes = "ph4deg3";
7
+ var readout = "ph4deg4";
8
+ var actions = "ph4deg5";
9
+ var hint = "ph4deg6";
10
+ export { actions, hint, modes, readout, root, row, toolbar };
11
+
12
+ //# sourceMappingURL=MeasureToolbar.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MeasureToolbar.styles.js","names":[],"sources":[],"mappings":""}
@@ -0,0 +1,75 @@
1
+ import { useMessages } from "../../services/hooks.js";
2
+ import { useAnnounce } from "../../ui/LiveRegion/LiveRegion.js";
3
+ import { announceMeasureTotal, formatArea, formatDistance, measureLineDistance, measurePolygonArea } from "@mapcairn/core";
4
+ import { useCallback, useEffect, useMemo, useState } from "react";
5
+ import { useLatestRef } from "@mapcairn/react";
6
+ // src/tools/MeasureToolbar/useMeasure.ts
7
+ /**
8
+ * How long the points must stay still before the total is announced.
9
+ *
10
+ * @internal
11
+ */
12
+ var MEASURE_ANNOUNCE_DELAY_MS = 800;
13
+ /**
14
+ * The state of one measurement: the points the user has placed, the mode and
15
+ * the total, worked out with the core geodesic maths (WGS 84, not flat
16
+ * pixels).
17
+ *
18
+ * The total is announced through the app-wide announcer only after the points
19
+ * have been still for {@link MEASURE_ANNOUNCE_DELAY_MS}, so adding points in
20
+ * quick succession or dragging a vertex gives one announcement at the end,
21
+ * not one per change. Nothing is announced before there is a total.
22
+ * @param units - The unit system for the readout and the announcement.
23
+ */
24
+ function useMeasure(units) {
25
+ const announce = useAnnounce();
26
+ const announceRef = useLatestRef(announce);
27
+ const messages = useMessages();
28
+ const [mode, setModeState] = useState("distance");
29
+ const [points, setPoints] = useState([]);
30
+ const total = useMemo(() => {
31
+ const positions = points.map((point) => [point.lng, point.lat]);
32
+ if (mode === "distance") {
33
+ const kilometres = measureLineDistance(positions);
34
+ return kilometres === null ? null : kilometres * 1e3;
35
+ }
36
+ return measurePolygonArea(positions);
37
+ }, [mode, points]);
38
+ const readout = mode === "distance" ? formatDistance(total ?? 0, units, messages) : formatArea(total ?? 0, units, messages);
39
+ useEffect(() => {
40
+ if (total === null) return;
41
+ const timer = setTimeout(() => {
42
+ announceRef.current(announceMeasureTotal(mode, total, units));
43
+ }, 800);
44
+ return () => clearTimeout(timer);
45
+ }, [
46
+ mode,
47
+ total,
48
+ units,
49
+ announceRef
50
+ ]);
51
+ return {
52
+ mode,
53
+ points,
54
+ total,
55
+ readout,
56
+ addPoint: useCallback((point) => {
57
+ setPoints((current) => [...current, point]);
58
+ }, []),
59
+ movePoint: useCallback((index, point) => {
60
+ setPoints((current) => index < 0 || index >= current.length ? current : current.map((existing, at) => at === index ? point : existing));
61
+ }, []),
62
+ undo: useCallback(() => {
63
+ setPoints((current) => current.length === 0 ? current : current.slice(0, -1));
64
+ }, []),
65
+ clear: useCallback(() => {
66
+ setPoints((current) => current.length === 0 ? current : []);
67
+ }, []),
68
+ setMode: useCallback((next) => {
69
+ setModeState(next);
70
+ }, [])
71
+ };
72
+ }
73
+ export { MEASURE_ANNOUNCE_DELAY_MS, useMeasure };
74
+
75
+ //# sourceMappingURL=useMeasure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMeasure.js","names":[],"sources":["../../../src/tools/MeasureToolbar/useMeasure.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n announceMeasureTotal,\n formatArea,\n formatDistance,\n type LatLng,\n measureLineDistance,\n measurePolygonArea,\n type UnitSystem,\n} from \"@mapcairn/core\";\nimport { useLatestRef } from \"@mapcairn/react\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { useMessages } from \"../../services\";\nimport { useAnnounce } from \"../../ui/LiveRegion\";\n\n/** What is being measured. */\nexport type MeasureMode = \"distance\" | \"area\";\n\n/**\n * How long the points must stay still before the total is announced.\n *\n * @internal\n */\nexport const MEASURE_ANNOUNCE_DELAY_MS = 800;\n\n/** What {@link useMeasure} returns. */\nexport interface UseMeasure {\n readonly mode: MeasureMode;\n /** The vertices, in the order they were added. */\n readonly points: readonly LatLng[];\n /**\n * The total in metres (`distance`) or square metres (`area`), measured\n * along the geodesic. `null` until there are enough points: two for a\n * distance, three for an area.\n */\n readonly total: number | null;\n /** The total as text in the chosen units, for example \"1.25 km\". \"0 m\" or \"0 m²\" until there are enough points. */\n readonly readout: string;\n /** Adds a vertex at the end. */\n readonly addPoint: (point: LatLng) => void;\n /** Moves the vertex at `index`, for example while it is dragged. Out-of-range indexes are ignored. */\n readonly movePoint: (index: number, point: LatLng) => void;\n /** Removes the last vertex. Does nothing with no points. */\n readonly undo: () => void;\n /** Removes every vertex. */\n readonly clear: () => void;\n /** Switches between distance and area, keeping the points. */\n readonly setMode: (mode: MeasureMode) => void;\n}\n\n/**\n * The state of one measurement: the points the user has placed, the mode and\n * the total, worked out with the core geodesic maths (WGS 84, not flat\n * pixels).\n *\n * The total is announced through the app-wide announcer only after the points\n * have been still for {@link MEASURE_ANNOUNCE_DELAY_MS}, so adding points in\n * quick succession or dragging a vertex gives one announcement at the end,\n * not one per change. Nothing is announced before there is a total.\n * @param units - The unit system for the readout and the announcement.\n */\nexport function useMeasure(units: UnitSystem): UseMeasure {\n const announce = useAnnounce();\n const announceRef = useLatestRef(announce);\n const messages = useMessages();\n const [mode, setModeState] = useState<MeasureMode>(\"distance\");\n const [points, setPoints] = useState<readonly LatLng[]>([]);\n\n const total = useMemo(() => {\n // The maths takes [longitude, latitude], the reverse of LatLng.\n const positions = points.map((point) => [point.lng, point.lat]);\n if (mode === \"distance\") {\n const kilometres = measureLineDistance(positions);\n return kilometres === null ? null : kilometres * 1000;\n }\n return measurePolygonArea(positions);\n }, [mode, points]);\n\n const readout =\n mode === \"distance\"\n ? formatDistance(total ?? 0, units, messages)\n : formatArea(total ?? 0, units, messages);\n\n useEffect(() => {\n if (total === null) {\n return;\n }\n const timer = setTimeout(() => {\n announceRef.current(announceMeasureTotal(mode, total, units));\n }, MEASURE_ANNOUNCE_DELAY_MS);\n return () => clearTimeout(timer);\n }, [mode, total, units, announceRef]);\n\n const addPoint = useCallback((point: LatLng) => {\n setPoints((current) => [...current, point]);\n }, []);\n\n const movePoint = useCallback((index: number, point: LatLng) => {\n setPoints((current) =>\n index < 0 || index >= current.length\n ? current\n : current.map((existing, at) => (at === index ? point : existing)),\n );\n }, []);\n\n const undo = useCallback(() => {\n setPoints((current) =>\n current.length === 0 ? current : current.slice(0, -1),\n );\n }, []);\n\n const clear = useCallback(() => {\n setPoints((current) => (current.length === 0 ? current : []));\n }, []);\n\n const setMode = useCallback((next: MeasureMode) => {\n setModeState(next);\n }, []);\n\n return {\n mode,\n points,\n total,\n readout,\n addPoint,\n movePoint,\n undo,\n clear,\n setMode,\n };\n}\n"],"mappings":";;;;;;;;;;;AAwBA,IAAa,4BAA4B;;;;;;;;;;;;AAsCzC,SAAgB,WAAW,OAA+B;CACxD,MAAM,WAAW,YAAY;CAC7B,MAAM,cAAc,aAAa,QAAQ;CACzC,MAAM,WAAW,YAAY;CAC7B,MAAM,CAAC,MAAM,gBAAgB,SAAsB,UAAU;CAC7D,MAAM,CAAC,QAAQ,aAAa,SAA4B,CAAC,CAAC;CAE1D,MAAM,QAAQ,cAAc;EAE1B,MAAM,YAAY,OAAO,KAAK,UAAU,CAAC,MAAM,KAAK,MAAM,GAAG,CAAC;EAC9D,IAAI,SAAS,YAAY;GACvB,MAAM,aAAa,oBAAoB,SAAS;GAChD,OAAO,eAAe,OAAO,OAAO,aAAa;EACnD;EACA,OAAO,mBAAmB,SAAS;CACrC,GAAG,CAAC,MAAM,MAAM,CAAC;CAEjB,MAAM,UACJ,SAAS,aACL,eAAe,SAAS,GAAG,OAAO,QAAQ,IAC1C,WAAW,SAAS,GAAG,OAAO,QAAQ;CAE5C,gBAAgB;EACd,IAAI,UAAU,MACZ;EAEF,MAAM,QAAQ,iBAAiB;GAC7B,YAAY,QAAQ,qBAAqB,MAAM,OAAO,KAAK,CAAC;EAC9D,GAAA,GAA4B;EAC5B,aAAa,aAAa,KAAK;CACjC,GAAG;EAAC;EAAM;EAAO;EAAO;CAAW,CAAC;CA4BpC,OAAO;EACL;EACA;EACA;EACA;EACA,UA/Be,aAAa,UAAkB;GAC9C,WAAW,YAAY,CAAC,GAAG,SAAS,KAAK,CAAC;EAC5C,GAAG,CAAC,CA6BF;EACA,WA5BgB,aAAa,OAAe,UAAkB;GAC9D,WAAW,YACT,QAAQ,KAAK,SAAS,QAAQ,SAC1B,UACA,QAAQ,KAAK,UAAU,OAAQ,OAAO,QAAQ,QAAQ,QAAS,CACrE;EACF,GAAG,CAAC,CAsBF;EACA,MArBW,kBAAkB;GAC7B,WAAW,YACT,QAAQ,WAAW,IAAI,UAAU,QAAQ,MAAM,GAAG,EAAE,CACtD;EACF,GAAG,CAAC,CAiBF;EACA,OAhBY,kBAAkB;GAC9B,WAAW,YAAa,QAAQ,WAAW,IAAI,UAAU,CAAC,CAAE;EAC9D,GAAG,CAAC,CAcF;EACA,SAbc,aAAa,SAAsB;GACjD,aAAa,IAAI;EACnB,GAAG,CAAC,CAWF;CACF;AACF"}
@@ -0,0 +1,174 @@
1
+ import { useClipboard, useMessages } from "../../services/hooks.js";
2
+ import { Button } from "../../ui/Button/Button.js";
3
+ import { Icon } from "../../ui/Icon/Icon.js";
4
+ import { IconButton } from "../../ui/IconButton/IconButton.js";
5
+ import { Isolate } from "../../ui/Isolate/Isolate.js";
6
+ import { useAnnounce } from "../../ui/LiveRegion/LiveRegion.js";
7
+ import { actions, address, card, coordinates, feedback, feedbackError, feedbackOk, header, heading, lookup, note } from "./PinCard.styles.js";
8
+ import { useReverseAddress } from "./useReverseAddress.js";
9
+ import { announceAddressError, announceAddressFound, announceAddressNotFound, announceCopied, formatLatLng } from "@mapcairn/core";
10
+ import { Check, Copy, MapPinned, Trash2, TriangleAlert, X } from "lucide-react";
11
+ import { useEffect, useId, useRef, useState } from "react";
12
+ import { jsx, jsxs } from "react/jsx-runtime";
13
+ // src/tools/PinCard/PinCard.tsx
14
+ /**
15
+ * The content of the pin surface: a heading, the coordinates as selectable
16
+ * text, "Copy coordinates" and "Clear pin" buttons, and an address lookup
17
+ * that the user starts.
18
+ *
19
+ * The lookup sends the pin's position, rounded to about 11 m, to a third
20
+ * party, so nothing is sent until "Look up address" is pressed. While it
21
+ * runs the button is busy; the address, "No address found here." or an error
22
+ * with "Try again" follows, and the announcer says the same. Moving the pin
23
+ * puts the card back to not looked up.
24
+ *
25
+ * The card has no position or surface of its own; the sheet or peek that
26
+ * holds it provides both. Copying shows "Copied" or "Could not copy" inline
27
+ * with an icon, and the announcer says the same, so neither relies on colour
28
+ * or on sight alone.
29
+ */
30
+ function PinCard({ position, onClear, onClose, headingLevel = 2, headingRef, lookupNote }) {
31
+ const clipboard = useClipboard();
32
+ const { t } = useMessages();
33
+ const announce = useAnnounce();
34
+ const { state: address$1, lookUp } = useReverseAddress(position);
35
+ const noteId = useId();
36
+ const addressRef = useRef(null);
37
+ const [copy, setCopy] = useState("idle");
38
+ const latest = useRef(0);
39
+ const { lat, lng } = position;
40
+ const Heading = `h${headingLevel}`;
41
+ const coordinates$1 = formatLatLng(position);
42
+ useEffect(() => {
43
+ setCopy("idle");
44
+ latest.current += 1;
45
+ return () => {
46
+ latest.current += 1;
47
+ };
48
+ }, [lat, lng]);
49
+ const { status: addressStatus } = address$1;
50
+ const addressText = address$1.status === "found" ? address$1.text : "";
51
+ useEffect(() => {
52
+ if (addressStatus === "found" || addressStatus === "none") {
53
+ if (document.activeElement === document.body && addressRef.current) addressRef.current.focus();
54
+ else announce(addressStatus === "found" ? announceAddressFound(addressText) : announceAddressNotFound(), { priority: "polite" });
55
+ } else if (addressStatus === "error") announce(announceAddressError(), { priority: "assertive" });
56
+ }, [
57
+ addressStatus,
58
+ addressText,
59
+ announce
60
+ ]);
61
+ const handleCopy = async () => {
62
+ latest.current += 1;
63
+ const request = latest.current;
64
+ const result = await clipboard.writeText(coordinates$1);
65
+ if (request !== latest.current) return;
66
+ setCopy(result.ok ? "copied" : "failed");
67
+ announce(announceCopied(result.ok), { priority: result.ok ? "polite" : "assertive" });
68
+ };
69
+ return /* @__PURE__ */ jsxs("div", {
70
+ className: card,
71
+ "data-testid": "pin-card",
72
+ children: [
73
+ /* @__PURE__ */ jsxs("div", {
74
+ className: header,
75
+ children: [/* @__PURE__ */ jsx(Heading, {
76
+ ref: headingRef,
77
+ tabIndex: -1,
78
+ className: heading,
79
+ "data-testid": "pin-card-heading",
80
+ children: t("tools.pin.heading", {})
81
+ }), onClose ? /* @__PURE__ */ jsx(IconButton, {
82
+ label: t("tools.pin.close", {}),
83
+ icon: X,
84
+ size: "compact",
85
+ "data-testid": "pin-card-close",
86
+ onClick: onClose
87
+ }) : null]
88
+ }),
89
+ /* @__PURE__ */ jsx("p", {
90
+ className: coordinates,
91
+ "data-testid": "pin-coordinates",
92
+ children: /* @__PURE__ */ jsx(Isolate, {
93
+ figure: true,
94
+ children: coordinates$1
95
+ })
96
+ }),
97
+ address$1.status === "found" || address$1.status === "none" ? /* @__PURE__ */ jsx("p", {
98
+ ref: addressRef,
99
+ tabIndex: -1,
100
+ className: address,
101
+ "data-testid": "pin-address",
102
+ children: address$1.status === "found" ? /* @__PURE__ */ jsx(Isolate, { children: address$1.text }) : t("tools.pin.noAddress", {})
103
+ }) : null,
104
+ address$1.status === "idle" || address$1.status === "loading" || address$1.status === "error" ? /* @__PURE__ */ jsxs("div", {
105
+ className: lookup,
106
+ children: [
107
+ /* @__PURE__ */ jsx(Button, {
108
+ variant: "secondary",
109
+ icon: MapPinned,
110
+ busy: address$1.status === "loading",
111
+ "aria-describedby": noteId,
112
+ "data-testid": address$1.status === "error" ? "pin-lookup-retry" : "pin-lookup",
113
+ onClick: lookUp,
114
+ children: address$1.status === "error" ? t("tools.tryAgain", {}) : t("tools.pin.lookUp", {})
115
+ }),
116
+ address$1.status === "loading" ? /* @__PURE__ */ jsx("p", {
117
+ className: address,
118
+ "data-testid": "pin-address-loading",
119
+ children: t("tools.pin.lookingUp", {})
120
+ }) : null,
121
+ address$1.status === "error" ? /* @__PURE__ */ jsxs("p", {
122
+ className: feedback,
123
+ "data-testid": "pin-address-error",
124
+ children: [/* @__PURE__ */ jsx(Icon, {
125
+ icon: TriangleAlert,
126
+ className: feedbackError
127
+ }), t("tools.pin.lookupFailed", {})]
128
+ }) : null,
129
+ /* @__PURE__ */ jsx("p", {
130
+ className: note,
131
+ id: noteId,
132
+ "data-testid": "pin-lookup-note",
133
+ children: lookupNote ?? t("tools.pin.lookupNote", {})
134
+ })
135
+ ]
136
+ }) : null,
137
+ /* @__PURE__ */ jsxs("div", {
138
+ className: actions,
139
+ children: [/* @__PURE__ */ jsx(Button, {
140
+ variant: "secondary",
141
+ icon: Copy,
142
+ "data-testid": "pin-copy",
143
+ onClick: handleCopy,
144
+ children: t("tools.pin.copy", {})
145
+ }), /* @__PURE__ */ jsx(Button, {
146
+ variant: "quiet",
147
+ icon: Trash2,
148
+ "data-testid": "pin-clear",
149
+ onClick: onClear,
150
+ children: t("tools.pin.clear", {})
151
+ })]
152
+ }),
153
+ copy === "copied" ? /* @__PURE__ */ jsxs("p", {
154
+ className: feedback,
155
+ "data-testid": "pin-copy-feedback",
156
+ children: [/* @__PURE__ */ jsx(Icon, {
157
+ icon: Check,
158
+ className: feedbackOk
159
+ }), t("tools.pin.copied", {})]
160
+ }) : null,
161
+ copy === "failed" ? /* @__PURE__ */ jsxs("p", {
162
+ className: feedback,
163
+ "data-testid": "pin-copy-feedback",
164
+ children: [/* @__PURE__ */ jsx(Icon, {
165
+ icon: TriangleAlert,
166
+ className: feedbackError
167
+ }), t("tools.pin.copyFailed", {})]
168
+ }) : null
169
+ ]
170
+ });
171
+ }
172
+ export { PinCard };
173
+
174
+ //# sourceMappingURL=PinCard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PinCard.js","names":["address","coordinates","styles.card","styles.header","styles.heading","styles.coordinates","styles.address","styles.lookup","styles.feedback","styles.feedbackError","styles.note","styles.actions","styles.feedbackOk"],"sources":["../../../src/tools/PinCard/PinCard.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n announceAddressError,\n announceAddressFound,\n announceAddressNotFound,\n announceCopied,\n formatLatLng,\n type LatLng,\n} from \"@mapcairn/core\";\nimport { Check, Copy, MapPinned, Trash2, TriangleAlert, X } from \"lucide-react\";\nimport {\n type ReactNode,\n type Ref,\n useEffect,\n useId,\n useRef,\n useState,\n} from \"react\";\nimport { useClipboard, useMessages } from \"../../services/hooks\";\nimport { Button } from \"../../ui/Button\";\nimport { Icon } from \"../../ui/Icon\";\nimport { IconButton } from \"../../ui/IconButton\";\nimport { Isolate } from \"../../ui/Isolate\";\nimport { useAnnounce } from \"../../ui/LiveRegion\";\nimport * as styles from \"./PinCard.css\";\nimport { useReverseAddress } from \"./useReverseAddress\";\n\n/** Props for {@link PinCard}. */\nexport interface PinCardProps {\n /** Where the pin is. */\n readonly position: LatLng;\n /** Called when the user chooses \"Clear pin\". */\n readonly onClear: () => void;\n /** When given, a close button is shown that calls it. */\n readonly onClose?: () => void;\n /** The level of the \"Dropped pin\" heading, so it fits the host's outline. Defaults to 2. */\n readonly headingLevel?: 2 | 3 | 4;\n /**\n * Receives the heading element, which takes focus by script (`tabIndex`\n * -1), so the sheet that opens the card can move focus to it.\n */\n readonly headingRef?: Ref<HTMLHeadingElement>;\n /**\n * What the address lookup sends and to whom, shown under the \"Look up\n * address\" button, which it describes. Defaults to the catalogue's\n * `tools.pin.lookupNote`, which does not name the service because the SDK\n * does not know which one a host uses. A host names its search provider\n * here. Phrasing content only: it sits inside a paragraph.\n */\n readonly lookupNote?: ReactNode;\n}\n\ntype CopyStatus = \"idle\" | \"copied\" | \"failed\";\n\n/**\n * The content of the pin surface: a heading, the coordinates as selectable\n * text, \"Copy coordinates\" and \"Clear pin\" buttons, and an address lookup\n * that the user starts.\n *\n * The lookup sends the pin's position, rounded to about 11 m, to a third\n * party, so nothing is sent until \"Look up address\" is pressed. While it\n * runs the button is busy; the address, \"No address found here.\" or an error\n * with \"Try again\" follows, and the announcer says the same. Moving the pin\n * puts the card back to not looked up.\n *\n * The card has no position or surface of its own; the sheet or peek that\n * holds it provides both. Copying shows \"Copied\" or \"Could not copy\" inline\n * with an icon, and the announcer says the same, so neither relies on colour\n * or on sight alone.\n */\nexport function PinCard({\n position,\n onClear,\n onClose,\n headingLevel = 2,\n headingRef,\n lookupNote,\n}: PinCardProps) {\n const clipboard = useClipboard();\n const { t } = useMessages();\n const announce = useAnnounce();\n const { state: address, lookUp } = useReverseAddress(position);\n const noteId = useId();\n const addressRef = useRef<HTMLParagraphElement>(null);\n const [copy, setCopy] = useState<CopyStatus>(\"idle\");\n const latest = useRef(0);\n const { lat, lng } = position;\n const Heading = `h${headingLevel}` as const;\n const coordinates = formatLatLng(position);\n\n // A copy that finishes after the pin moved, or the card closed, is stale.\n // biome-ignore lint/correctness/useExhaustiveDependencies: lat and lng are the triggers, not values read in the effect\n useEffect(() => {\n setCopy(\"idle\");\n latest.current += 1;\n return () => {\n latest.current += 1;\n };\n }, [lat, lng]);\n\n const { status: addressStatus } = address;\n const addressText = address.status === \"found\" ? address.text : \"\";\n // The lookup button gives way to the address. When focus was on it, focus\n // moves to the address, which a screen reader reads, so only a person whose\n // focus is elsewhere needs the announcement.\n useEffect(() => {\n if (addressStatus === \"found\" || addressStatus === \"none\") {\n if (document.activeElement === document.body && addressRef.current) {\n addressRef.current.focus();\n } else {\n announce(\n addressStatus === \"found\"\n ? announceAddressFound(addressText)\n : announceAddressNotFound(),\n { priority: \"polite\" },\n );\n }\n } else if (addressStatus === \"error\") {\n announce(announceAddressError(), { priority: \"assertive\" });\n }\n }, [addressStatus, addressText, announce]);\n\n const handleCopy = async () => {\n latest.current += 1;\n const request = latest.current;\n const result = await clipboard.writeText(coordinates);\n if (request !== latest.current) {\n return;\n }\n setCopy(result.ok ? \"copied\" : \"failed\");\n announce(announceCopied(result.ok), {\n priority: result.ok ? \"polite\" : \"assertive\",\n });\n };\n\n return (\n <div className={styles.card} data-testid=\"pin-card\">\n <div className={styles.header}>\n <Heading\n ref={headingRef}\n tabIndex={-1}\n className={styles.heading}\n data-testid=\"pin-card-heading\"\n >\n {t(\"tools.pin.heading\", {})}\n </Heading>\n {onClose ? (\n <IconButton\n label={t(\"tools.pin.close\", {})}\n icon={X}\n size=\"compact\"\n data-testid=\"pin-card-close\"\n onClick={onClose}\n />\n ) : null}\n </div>\n <p className={styles.coordinates} data-testid=\"pin-coordinates\">\n <Isolate figure>{coordinates}</Isolate>\n </p>\n {address.status === \"found\" || address.status === \"none\" ? (\n <p\n ref={addressRef}\n tabIndex={-1}\n className={styles.address}\n data-testid=\"pin-address\"\n >\n {address.status === \"found\" ? (\n <Isolate>{address.text}</Isolate>\n ) : (\n t(\"tools.pin.noAddress\", {})\n )}\n </p>\n ) : null}\n {address.status === \"idle\" ||\n address.status === \"loading\" ||\n address.status === \"error\" ? (\n <div className={styles.lookup}>\n <Button\n variant=\"secondary\"\n icon={MapPinned}\n busy={address.status === \"loading\"}\n aria-describedby={noteId}\n data-testid={\n address.status === \"error\" ? \"pin-lookup-retry\" : \"pin-lookup\"\n }\n onClick={lookUp}\n >\n {address.status === \"error\"\n ? t(\"tools.tryAgain\", {})\n : t(\"tools.pin.lookUp\", {})}\n </Button>\n {address.status === \"loading\" ? (\n <p className={styles.address} data-testid=\"pin-address-loading\">\n {t(\"tools.pin.lookingUp\", {})}\n </p>\n ) : null}\n {address.status === \"error\" ? (\n <p className={styles.feedback} data-testid=\"pin-address-error\">\n <Icon icon={TriangleAlert} className={styles.feedbackError} />\n {t(\"tools.pin.lookupFailed\", {})}\n </p>\n ) : null}\n <p className={styles.note} id={noteId} data-testid=\"pin-lookup-note\">\n {lookupNote ?? t(\"tools.pin.lookupNote\", {})}\n </p>\n </div>\n ) : null}\n <div className={styles.actions}>\n <Button\n variant=\"secondary\"\n icon={Copy}\n data-testid=\"pin-copy\"\n onClick={handleCopy}\n >\n {t(\"tools.pin.copy\", {})}\n </Button>\n <Button\n variant=\"quiet\"\n icon={Trash2}\n data-testid=\"pin-clear\"\n onClick={onClear}\n >\n {t(\"tools.pin.clear\", {})}\n </Button>\n </div>\n {copy === \"copied\" ? (\n <p className={styles.feedback} data-testid=\"pin-copy-feedback\">\n <Icon icon={Check} className={styles.feedbackOk} />\n {t(\"tools.pin.copied\", {})}\n </p>\n ) : null}\n {copy === \"failed\" ? (\n <p className={styles.feedback} data-testid=\"pin-copy-feedback\">\n <Icon icon={TriangleAlert} className={styles.feedbackError} />\n {t(\"tools.pin.copyFailed\", {})}\n </p>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,SAAgB,QAAQ,EACtB,UACA,SACA,SACA,eAAe,GACf,YACA,cACe;CACf,MAAM,YAAY,aAAa;CAC/B,MAAM,EAAE,MAAM,YAAY;CAC1B,MAAM,WAAW,YAAY;CAC7B,MAAM,EAAE,OAAOA,WAAS,WAAW,kBAAkB,QAAQ;CAC7D,MAAM,SAAS,MAAM;CACrB,MAAM,aAAa,OAA6B,IAAI;CACpD,MAAM,CAAC,MAAM,WAAW,SAAqB,MAAM;CACnD,MAAM,SAAS,OAAO,CAAC;CACvB,MAAM,EAAE,KAAK,QAAQ;CACrB,MAAM,UAAU,IAAI;CACpB,MAAMC,gBAAc,aAAa,QAAQ;CAIzC,gBAAgB;EACd,QAAQ,MAAM;EACd,OAAO,WAAW;EAClB,aAAa;GACX,OAAO,WAAW;EACpB;CACF,GAAG,CAAC,KAAK,GAAG,CAAC;CAEb,MAAM,EAAE,QAAQ,kBAAkBD;CAClC,MAAM,cAAcA,UAAQ,WAAW,UAAUA,UAAQ,OAAO;CAIhE,gBAAgB;EACd,IAAI,kBAAkB,WAAW,kBAAkB,QAAQ;GACzD,IAAI,SAAS,kBAAkB,SAAS,QAAQ,WAAW,SACzD,WAAW,QAAQ,MAAM;QAEzB,SACE,kBAAkB,UACd,qBAAqB,WAAW,IAChC,wBAAwB,GAC5B,EAAE,UAAU,SAAS,CACvB;EAEJ,O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,GAC5D,EAAE,wBAAwB,CAAC,CAAC,CAC5B;GACD,CAAA,IAAA;EACD;;AAET"}
@@ -0,0 +1,16 @@
1
+ /* empty css */
2
+ // src/tools/PinCard/PinCard.css.ts
3
+ var card = "mjs0ej0";
4
+ var header = "mjs0ej1";
5
+ var heading = "mjs0ej2";
6
+ var coordinates = "mjs0ej3";
7
+ var address = "mjs0ej4";
8
+ var lookup = "mjs0ej5";
9
+ var note = "mjs0ej6";
10
+ var actions = "mjs0ej7";
11
+ var feedback = "mjs0ej8";
12
+ var feedbackOk = "mjs0ej9";
13
+ var feedbackError = "mjs0eja";
14
+ export { actions, address, card, coordinates, feedback, feedbackError, feedbackOk, header, heading, lookup, note };
15
+
16
+ //# sourceMappingURL=PinCard.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PinCard.styles.js","names":[],"sources":[],"mappings":""}
@@ -0,0 +1,77 @@
1
+ import { useSearchProvider } from "../../services/hooks.js";
2
+ import { roundForLookup } from "@mapcairn/core";
3
+ import { useCallback, useEffect, useRef, useState } from "react";
4
+ // src/tools/PinCard/useReverseAddress.ts
5
+ /** Joins a place's label and secondary label into one address line. */
6
+ function addressLine(result) {
7
+ return result.secondaryLabel ? `${result.label}, ${result.secondaryLabel}` : result.label;
8
+ }
9
+ /**
10
+ * Looks up the address at a position with the search provider's `reverse`,
11
+ * but only when `lookUp` is called, because the position leaves the device.
12
+ * The provider receives the position rounded with `roundForLookup`.
13
+ *
14
+ * @remarks Moving the position, or unmounting, aborts the lookup in flight and
15
+ * returns the state to `idle`. An aborted lookup never changes state, and an
16
+ * answer is only ever shown for the position it was asked for. A failed
17
+ * lookup is `error`, which callers should show with a way to try again.
18
+ */
19
+ function useReverseAddress({ lat, lng }) {
20
+ const provider = useSearchProvider();
21
+ const [tracked, setTracked] = useState({
22
+ lat,
23
+ lng,
24
+ state: { status: "idle" }
25
+ });
26
+ const controller = useRef(null);
27
+ useEffect(() => {
28
+ setTracked({
29
+ lat,
30
+ lng,
31
+ state: { status: "idle" }
32
+ });
33
+ return () => {
34
+ controller.current?.abort();
35
+ controller.current = null;
36
+ };
37
+ }, [
38
+ provider,
39
+ lat,
40
+ lng
41
+ ]);
42
+ const lookUp = useCallback(() => {
43
+ controller.current?.abort();
44
+ const current = new AbortController();
45
+ controller.current = current;
46
+ const settle = (settled) => {
47
+ if (!current.signal.aborted) setTracked({
48
+ lat,
49
+ lng,
50
+ state: settled
51
+ });
52
+ };
53
+ setTracked({
54
+ lat,
55
+ lng,
56
+ state: { status: "loading" }
57
+ });
58
+ provider.reverse(roundForLookup({
59
+ lat,
60
+ lng
61
+ }), { signal: current.signal }).then((result) => settle(result === null ? { status: "none" } : {
62
+ status: "found",
63
+ text: addressLine(result)
64
+ }), () => settle({ status: "error" }));
65
+ }, [
66
+ provider,
67
+ lat,
68
+ lng
69
+ ]);
70
+ return {
71
+ state: tracked.lat === lat && tracked.lng === lng ? tracked.state : { status: "idle" },
72
+ lookUp
73
+ };
74
+ }
75
+ export { useReverseAddress };
76
+
77
+ //# sourceMappingURL=useReverseAddress.js.map