@defra/interactive-map 0.0.52-alpha → 0.0.54-alpha

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 (194) hide show
  1. package/dist/css/index.css +1 -1
  2. package/dist/esm/im-core.js +1 -1
  3. package/dist/esm/im-shell.js +1 -1
  4. package/dist/umd/im-core.js +1 -1
  5. package/dist/umd/index.js +1 -1
  6. package/docs/api/context.md +30 -12
  7. package/docs/api/marker-config.md +16 -8
  8. package/docs/api/symbol-config.md +24 -9
  9. package/docs/api/symbol-registry.md +49 -14
  10. package/docs/api.md +11 -3
  11. package/docs/plugins/datasets.md +6 -10
  12. package/docs/plugins/draw.md +2 -1
  13. package/docs/plugins/map-key.md +47 -4
  14. package/package.json +1 -1
  15. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  16. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  17. package/plugins/beta/map-styles/dist/umd/index.js +1 -1
  18. package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  19. package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
  20. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  21. package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
  22. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  23. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  24. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  25. package/plugins/datasets/src/adapters/esri/esriLayerAdapter.js +6 -6
  26. package/plugins/datasets/src/adapters/esri/registry/esriDataset.test.js +1 -1
  27. package/plugins/datasets/src/adapters/maplibre/layerBuilders.js +10 -10
  28. package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +22 -6
  29. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +9 -3
  30. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +18 -3
  31. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +3 -3
  32. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +20 -27
  33. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +16 -70
  34. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +30 -115
  35. package/plugins/datasets/src/adapters/openlayers/layerBuilders.js +11 -13
  36. package/plugins/datasets/src/adapters/openlayers/layerBuilders.test.js +11 -3
  37. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.js +48 -19
  38. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +101 -13
  39. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +27 -28
  40. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +51 -32
  41. package/plugins/datasets/src/fetch/createDynamicSource.js +2 -2
  42. package/plugins/datasets/src/initialise/DatasetsInit.jsx +2 -2
  43. package/plugins/datasets/src/initialise/defaults.js +16 -27
  44. package/plugins/datasets/src/initialise/defaults.test.js +25 -57
  45. package/plugins/datasets/src/initialise/initialiseDatasets.js +1 -4
  46. package/plugins/datasets/src/reducers/__data__/demoDatasets.js +1 -3
  47. package/plugins/datasets/src/reducers/mappedDatasetsReducer.test.js +1 -1
  48. package/plugins/datasets/src/registry/dataset.js +23 -17
  49. package/plugins/datasets/src/registry/dataset.test.js +114 -11
  50. package/plugins/datasets/src/registry/mapboxStyleDataset.js +1 -1
  51. package/plugins/datasets/src/registry/mapboxStyleDataset.test.js +1 -1
  52. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  53. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  54. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  55. package/plugins/draw/dist/esm/index.js +1 -1
  56. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  57. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  58. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  59. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  60. package/plugins/draw/dist/umd/index.js +1 -1
  61. package/plugins/draw/src/DrawInit.jsx +7 -5
  62. package/plugins/draw/src/DrawInit.test.jsx +18 -2
  63. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +11 -5
  64. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -11
  65. package/plugins/draw/src/adapters/maplibre/mapboxDraw.js +12 -9
  66. package/plugins/draw/src/adapters/maplibre/mapboxDraw.test.js +18 -0
  67. package/plugins/draw/src/adapters/maplibre/pointSymbolImages.js +81 -56
  68. package/plugins/draw/src/adapters/maplibre/pointSymbolImages.test.js +149 -80
  69. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +7 -6
  70. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +22 -25
  71. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +26 -8
  72. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +58 -16
  73. package/plugins/draw/src/adapters/openlayers/core/styles.js +33 -20
  74. package/plugins/draw/src/adapters/openlayers/core/styles.test.js +47 -21
  75. package/plugins/draw/src/adapters/openlayers/olDraw.js +16 -12
  76. package/plugins/draw/src/adapters/openlayers/olDraw.test.js +27 -32
  77. package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.js +44 -49
  78. package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.test.js +100 -119
  79. package/plugins/draw/src/defaults.js +2 -6
  80. package/plugins/draw/src/utils/stripInternalProperties.test.js +2 -1
  81. package/plugins/draw/src/utils/symbolKeys.js +3 -4
  82. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  83. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  84. package/plugins/interact/dist/umd/index.js +1 -1
  85. package/plugins/map-key/dist/css/index.css +1 -1
  86. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  87. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -2
  88. package/plugins/map-key/dist/umd/index.js +1 -1
  89. package/plugins/map-key/src/components/Key/Key.jsx +8 -4
  90. package/plugins/map-key/src/components/Key/Key.module.scss +144 -53
  91. package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +36 -3
  92. package/plugins/map-key/src/components/Key/KeyGroupItem.test.jsx +44 -2
  93. package/plugins/map-key/src/components/Key/KeyItem.jsx +2 -2
  94. package/plugins/map-key/src/components/Key/KeySvg.jsx +19 -18
  95. package/plugins/map-key/src/components/Key/KeySvg.test.jsx +25 -18
  96. package/plugins/map-key/src/components/Key/KeySvgPattern.jsx +1 -2
  97. package/plugins/map-key/src/components/Key/KeySvgPattern.test.jsx +3 -1
  98. package/plugins/map-key/src/components/Key/KeySvgRamp.jsx +35 -6
  99. package/plugins/map-key/src/components/Key/KeySvgRamp.test.jsx +56 -16
  100. package/plugins/map-key/src/components/Key/KeySvgSymbol.jsx +26 -12
  101. package/plugins/map-key/src/components/Key/KeySvgSymbol.test.jsx +24 -74
  102. package/plugins/map-key/src/components/Key/MapKey.jsx +3 -1
  103. package/plugins/map-key/src/components/Key/svgProperties.js +8 -2
  104. package/plugins/map-key/src/components/Key/useRampOrientation.js +61 -0
  105. package/plugins/map-key/src/components/Key/useRampOrientation.test.jsx +155 -0
  106. package/plugins/map-key/src/index.js +34 -0
  107. package/plugins/map-key/src/reducers/mergeKeyGroupItems.test.js +15 -0
  108. package/plugins/map-key/src/registry/index.js +0 -2
  109. package/plugins/map-key/src/registry/index.test.js +1 -9
  110. package/plugins/map-key/src/utils/groupStyles.js +5 -2
  111. package/plugins/menu/src/registry/index.js +0 -2
  112. package/plugins/menu/src/registry/index.test.js +1 -9
  113. package/plugins/search/dist/esm/im-search-plugin.js +1 -1
  114. package/plugins/search/dist/umd/im-search-plugin.js +1 -1
  115. package/plugins/search/dist/umd/index.js +1 -1
  116. package/plugins/search/src/Search.jsx +0 -1
  117. package/plugins/search/src/components/Form/Form.jsx +3 -3
  118. package/plugins/search/src/components/Suggestions/Suggestions.jsx +2 -0
  119. package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +6 -0
  120. package/plugins/search/src/defaults.js +3 -0
  121. package/plugins/search/src/events/formHandlers.js +3 -9
  122. package/plugins/search/src/events/formHandlers.test.js +6 -9
  123. package/plugins/search/src/events/inputHandlers.js +8 -2
  124. package/plugins/search/src/events/inputHandlers.test.js +20 -0
  125. package/plugins/search/src/events/suggestionHandlers.js +3 -5
  126. package/plugins/search/src/events/suggestionHandlers.test.js +5 -8
  127. package/plugins/search/src/utils/showResult.js +9 -0
  128. package/plugins/search/src/utils/showResult.test.js +16 -0
  129. package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
  130. package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  131. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  132. package/providers/beta/openlayers/dist/umd/index.js +1 -1
  133. package/providers/beta/openlayers/src/openlayersProvider.js +102 -2
  134. package/providers/beta/openlayers/src/openlayersProvider.test.js +95 -0
  135. package/providers/beta/openlayers/src/utils/highlightFeatures.js +20 -25
  136. package/providers/beta/openlayers/src/utils/highlightFeatures.test.js +73 -38
  137. package/providers/beta/openlayers/src/utils/patternImages.js +61 -0
  138. package/providers/beta/openlayers/src/utils/patternImages.test.js +74 -0
  139. package/providers/beta/openlayers/src/utils/symbolImages.js +103 -95
  140. package/providers/beta/openlayers/src/utils/symbolImages.test.js +136 -85
  141. package/providers/mapProvider.js +53 -1
  142. package/providers/mapProvider.test.js +6 -0
  143. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  144. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  145. package/providers/maplibre/dist/umd/index.js +1 -1
  146. package/providers/maplibre/src/maplibreProvider.js +50 -17
  147. package/providers/maplibre/src/maplibreProvider.test.js +74 -20
  148. package/providers/maplibre/src/utils/highlightFeatures.js +19 -14
  149. package/providers/maplibre/src/utils/highlightFeatures.test.js +20 -14
  150. package/providers/maplibre/src/utils/patternImages.js +46 -29
  151. package/providers/maplibre/src/utils/patternImages.test.js +52 -4
  152. package/providers/maplibre/src/utils/symbolImages.js +80 -39
  153. package/providers/maplibre/src/utils/symbolImages.test.js +157 -54
  154. package/src/App/components/Hints/Hints.module.scss +1 -1
  155. package/src/App/components/Markers/Markers.jsx +16 -25
  156. package/src/App/components/Markers/Markers.test.jsx +34 -48
  157. package/src/App/components/Markers/SymbolLabelMarker.jsx +1 -1
  158. package/src/App/components/Markers/SymbolMarker.jsx +1 -1
  159. package/src/App/components/Viewport/Viewport.jsx +6 -4
  160. package/src/App/components/Viewport/Viewport.test.jsx +18 -1
  161. package/src/App/hooks/useMapAnnouncements.js +7 -2
  162. package/src/App/hooks/useMapAnnouncements.test.js +13 -2
  163. package/src/App/hooks/useModalPanelBehaviour.js +3 -1
  164. package/src/App/initialiseApp.js +1 -1
  165. package/src/App/store/ServiceProvider.jsx +12 -3
  166. package/src/App/store/ServiceProvider.test.jsx +39 -0
  167. package/src/InteractiveMap/InteractiveMap.js +3 -3
  168. package/src/config/appConfig.js +1 -5
  169. package/src/config/mapSizeScales.js +8 -0
  170. package/src/config/symbolConfig.js +101 -25
  171. package/src/services/mapFocus.js +64 -0
  172. package/src/services/mapFocus.test.js +76 -0
  173. package/src/services/patternRegistry.js +97 -76
  174. package/src/services/patternRegistry.test.js +19 -1
  175. package/src/services/symbolComposer.js +184 -0
  176. package/src/services/symbolComposer.test.js +132 -0
  177. package/src/services/symbolRegistry.js +326 -155
  178. package/src/services/symbolRegistry.test.js +334 -32
  179. package/src/types.js +11 -5
  180. package/src/utils/detectInterfaceType.js +16 -5
  181. package/src/utils/detectInterfaceType.test.js +32 -0
  182. package/src/utils/hashString.js +23 -0
  183. package/src/utils/hashString.test.js +29 -0
  184. package/src/utils/imageDataCache.js +43 -0
  185. package/src/utils/imageDataCache.test.js +38 -0
  186. package/src/utils/pathBounds.js +330 -0
  187. package/src/utils/pathBounds.test.js +145 -0
  188. package/src/utils/patternUtils.js +0 -8
  189. package/src/utils/patternUtils.test.js +0 -25
  190. package/src/utils/recentImageSets.js +35 -0
  191. package/src/utils/recentImageSets.test.js +46 -0
  192. package/src/utils/symbolUtils.js +26 -29
  193. package/src/utils/symbolUtils.test.js +27 -41
  194. package/plugins/map-key/dist/umd/im-map-key-plugin.js.LICENSE.txt +0 -1
@@ -7,7 +7,7 @@ export function MapKey ({
7
7
  mapState: { mapStyle },
8
8
  pluginConfig: { noKeyItemText },
9
9
  pluginState,
10
- services: { eventBus }
10
+ services: { eventBus, symbolRegistry, patternRegistry }
11
11
  }) {
12
12
  const [datasetRegistry, setDatasetRegistry] = useState(getDatasetRegistry())
13
13
  // Lazily seed from the registry (already populated whenever the key is opened after
@@ -58,6 +58,8 @@ export function MapKey ({
58
58
  keyGroups={keyGroups}
59
59
  hasGroups={hasGroups}
60
60
  mapStyle={mapStyle}
61
+ symbolRegistry={symbolRegistry}
62
+ patternRegistry={patternRegistry}
61
63
  />
62
64
  )
63
65
  }
@@ -1,6 +1,11 @@
1
+ const HALF = 0.5
2
+
1
3
  export const SVG_SIZE = 20 // Width and height attributes of the svg element
2
- export const SVG_CENTER = SVG_SIZE / 2
3
- const SVG_SYMBOL_SIZE = 44 // Width and height attributes of the svg element if its a marker or point feature symbol
4
+ export const SVG_CENTER = SVG_SIZE * HALF
5
+ export const SVG_SYMBOL_SIZE = 44 // Width and height attributes of the svg element if its a marker or point feature symbol
6
+ // Largest a symbol is drawn in the key: built-in symbols top out at 49 at medium and draw 1:1;
7
+ // a bigger custom symbol is scaled down to this so it can't spill far past its row
8
+ export const KEY_SYMBOL_MAX_SIZE = 56
4
9
 
5
10
  export const svgProps = {
6
11
  xmlns: 'http://www.w3.org/2000/svg',
@@ -16,5 +21,6 @@ export const svgSymbolProps = {
16
21
  ...svgProps,
17
22
  width: SVG_SYMBOL_SIZE,
18
23
  height: SVG_SYMBOL_SIZE,
24
+ viewBox: `0 0 ${SVG_SYMBOL_SIZE} ${SVG_SYMBOL_SIZE}`,
19
25
  className: 'im-c-map-key-symbol im-c-map-key-symbol--point'
20
26
  }
@@ -0,0 +1,61 @@
1
+ import { useLayoutEffect, useState } from 'react'
2
+
3
+ export const HORIZONTAL = 'horizontal'
4
+ export const VERTICAL = 'vertical'
5
+
6
+ let measureContext
7
+ const getMeasureContext = () => {
8
+ if (measureContext === undefined) {
9
+ measureContext = document.createElement('canvas').getContext('2d') ?? null
10
+ }
11
+ return measureContext
12
+ }
13
+
14
+ // Whether every label fits on one line in an equal share of the list's width. Both ramp
15
+ // orientations share the list's side padding and gap, so the result doesn't depend on which
16
+ // orientation is currently rendered. Returns null when there's nothing to measure yet.
17
+ const labelsFitHorizontally = (list, labels) => {
18
+ const label = list.querySelector('.im-c-map-key-list__item-label')
19
+ const context = getMeasureContext()
20
+ if (!label || !context || !list.clientWidth) {
21
+ return null
22
+ }
23
+ const { fontStyle, fontWeight, fontSize, fontFamily } = getComputedStyle(label)
24
+ context.font = `${fontStyle} ${fontWeight} ${fontSize} ${fontFamily}`
25
+ const listStyle = getComputedStyle(list)
26
+ const gap = Number.parseFloat(listStyle.columnGap) || 0
27
+ const padding = (Number.parseFloat(listStyle.paddingLeft) || 0) + (Number.parseFloat(listStyle.paddingRight) || 0)
28
+ const columnWidth = (list.clientWidth - padding - gap * (labels.length - 1)) / labels.length
29
+ return labels.every(text => context.measureText(text).width <= columnWidth)
30
+ }
31
+
32
+ // A ramp is horizontal when every label fits on one line under its band, otherwise vertical.
33
+ // Measured before paint, and again when the list resizes or web fonts finish loading.
34
+ export const useRampOrientation = (listRef, labels, isRamp, hasStroke) => {
35
+ const [fits, setFits] = useState(true)
36
+ const labelsKey = labels.join('\n')
37
+
38
+ useLayoutEffect(() => {
39
+ const list = listRef.current
40
+ if (!isRamp || !list) {
41
+ return undefined
42
+ }
43
+ let active = true
44
+ const update = () => {
45
+ const result = active ? labelsFitHorizontally(list, labels) : null
46
+ if (result !== null) {
47
+ setFits(result)
48
+ }
49
+ }
50
+ update()
51
+ const observer = typeof ResizeObserver === 'function' ? new ResizeObserver(update) : null
52
+ observer?.observe(list)
53
+ document.fonts?.ready.then(update, () => {})
54
+ return () => {
55
+ active = false
56
+ observer?.disconnect()
57
+ }
58
+ }, [isRamp, hasStroke, labelsKey])
59
+
60
+ return fits ? HORIZONTAL : VERTICAL
61
+ }
@@ -0,0 +1,155 @@
1
+ import { useRef } from 'react'
2
+ import { render, act } from '@testing-library/react'
3
+ import { useRampOrientation } from './useRampOrientation.js'
4
+
5
+ // Each character measures 10px wide
6
+ const measureText = jest.fn(text => ({ width: text.length * 10 }))
7
+ jest.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({ font: '', measureText })
8
+
9
+ let resizeCallback
10
+ let observe
11
+ let disconnect
12
+
13
+ const TestRamp = ({ labels, isRamp = true, width, padding = 0 }) => {
14
+ const listRef = useRef(null)
15
+ const setList = (list) => {
16
+ if (list) {
17
+ Object.defineProperty(list, 'clientWidth', { configurable: true, get: () => width })
18
+ }
19
+ listRef.current = list
20
+ }
21
+ const orientation = useRampOrientation(listRef, labels, isRamp, false)
22
+ return (
23
+ <dl ref={setList} data-orientation={orientation} style={{ paddingLeft: `${padding}px`, paddingRight: `${padding}px` }}>
24
+ {labels.map(label => <dd key={label} className='im-c-map-key-list__item-label'>{label}</dd>)}
25
+ </dl>
26
+ )
27
+ }
28
+
29
+ const getOrientation = (container) => container.querySelector('dl').dataset.orientation
30
+
31
+ beforeEach(() => {
32
+ jest.clearAllMocks()
33
+ observe = jest.fn()
34
+ disconnect = jest.fn()
35
+ globalThis.ResizeObserver = jest.fn(callback => {
36
+ resizeCallback = callback
37
+ return { observe, disconnect }
38
+ })
39
+ })
40
+
41
+ afterEach(() => {
42
+ delete globalThis.ResizeObserver
43
+ })
44
+
45
+ describe('useRampOrientation', () => {
46
+ it('is horizontal when every label fits in an equal column', () => {
47
+ // 3 columns of 100px; longest label is 90px
48
+ const { container } = render(<TestRamp labels={['Low', 'Medium', 'Very high']} width={300} />)
49
+ expect(getOrientation(container)).toBe('horizontal')
50
+ })
51
+
52
+ it('is vertical when any label is wider than its column', () => {
53
+ // 3 columns of 50px; 'Medium' is 60px
54
+ const { container } = render(<TestRamp labels={['Low', 'Medium', 'High']} width={150} />)
55
+ expect(getOrientation(container)).toBe('vertical')
56
+ })
57
+
58
+ it('subtracts the list padding from the available width', () => {
59
+ // 2 columns of 30px after 20px padding either side; 'High' is 40px
60
+ const { container } = render(<TestRamp labels={['Low', 'High']} width={100} padding={20} />)
61
+ expect(getOrientation(container)).toBe('vertical')
62
+ })
63
+
64
+ it('re-measures when the list resizes', () => {
65
+ const labels = ['Low', 'Medium', 'High']
66
+ const { container, rerender } = render(<TestRamp labels={labels} width={150} />)
67
+ expect(getOrientation(container)).toBe('vertical')
68
+ rerender(<TestRamp labels={labels} width={300} />)
69
+ act(() => resizeCallback())
70
+ expect(getOrientation(container)).toBe('horizontal')
71
+ })
72
+
73
+ it('keeps its current orientation while the list has no width', () => {
74
+ const { container } = render(<TestRamp labels={['Low', 'Medium', 'High']} width={0} />)
75
+ expect(getOrientation(container)).toBe('horizontal')
76
+ })
77
+
78
+ it('does not measure or observe when the group is not a ramp', () => {
79
+ const { container } = render(<TestRamp labels={['Low', 'Medium', 'High']} width={150} isRamp={false} />)
80
+ expect(getOrientation(container)).toBe('horizontal')
81
+ expect(measureText).not.toHaveBeenCalled()
82
+ expect(globalThis.ResizeObserver).not.toHaveBeenCalled()
83
+ })
84
+
85
+ it('still measures when ResizeObserver is unavailable', () => {
86
+ delete globalThis.ResizeObserver
87
+ const { container } = render(<TestRamp labels={['Low', 'Medium', 'High']} width={150} />)
88
+ expect(getOrientation(container)).toBe('vertical')
89
+ })
90
+
91
+ describe('when web fonts load', () => {
92
+ let resolveFonts
93
+ let rejectFonts
94
+
95
+ beforeEach(() => {
96
+ Object.defineProperty(document, 'fonts', {
97
+ configurable: true,
98
+ value: { ready: new Promise((resolve, reject) => { resolveFonts = resolve; rejectFonts = reject }) }
99
+ })
100
+ })
101
+
102
+ afterEach(() => {
103
+ delete document.fonts
104
+ })
105
+
106
+ it('re-measures', async () => {
107
+ const labels = ['Low', 'Medium', 'High']
108
+ const { container, rerender } = render(<TestRamp labels={labels} width={150} />)
109
+ expect(getOrientation(container)).toBe('vertical')
110
+ rerender(<TestRamp labels={labels} width={300} />)
111
+ await act(async () => resolveFonts())
112
+ expect(getOrientation(container)).toBe('horizontal')
113
+ })
114
+
115
+ it('ignores a font loading failure', async () => {
116
+ const { container } = render(<TestRamp labels={['Low', 'Medium', 'High']} width={150} />)
117
+ measureText.mockClear()
118
+ await act(async () => rejectFonts(new Error('font failed')))
119
+ expect(measureText).not.toHaveBeenCalled()
120
+ expect(getOrientation(container)).toBe('vertical')
121
+ })
122
+
123
+ it('does not measure after unmount', async () => {
124
+ const { unmount } = render(<TestRamp labels={['Low', 'Medium', 'High']} width={150} />)
125
+ unmount()
126
+ measureText.mockClear()
127
+ await act(async () => resolveFonts())
128
+ expect(measureText).not.toHaveBeenCalled()
129
+ })
130
+ })
131
+
132
+ it('stays horizontal when a canvas context is unavailable', () => {
133
+ // A fresh copy of the module, so its cached measuring context is unset. The pure entry point
134
+ // doesn't register cleanup hooks, which can't be added from inside a test.
135
+ jest.isolateModules(() => {
136
+ const { renderHook } = require('@testing-library/react/pure')
137
+ const { useRampOrientation: isolatedUseRampOrientation } = require('./useRampOrientation.js')
138
+ HTMLCanvasElement.prototype.getContext.mockReturnValueOnce(null)
139
+ const list = document.createElement('dl')
140
+ list.innerHTML = '<dd class="im-c-map-key-list__item-label">Medium</dd>'
141
+ Object.defineProperty(list, 'clientWidth', { get: () => 10 })
142
+ const { result, unmount } = renderHook(() => isolatedUseRampOrientation({ current: list }, ['Medium'], true, false))
143
+ expect(result.current).toBe('horizontal')
144
+ expect(measureText).not.toHaveBeenCalled()
145
+ unmount()
146
+ })
147
+ })
148
+
149
+ it('stops observing on unmount', () => {
150
+ const { unmount } = render(<TestRamp labels={['Low']} width={150} />)
151
+ expect(observe).toHaveBeenCalled()
152
+ unmount()
153
+ expect(disconnect).toHaveBeenCalled()
154
+ })
155
+ })
@@ -1,5 +1,39 @@
1
1
  import './mapKey.scss'
2
2
 
3
+ /**
4
+ * Display options for a group of key entries.
5
+ *
6
+ * @typedef {Object} MapKeyGroupConfig
7
+ *
8
+ * @property {string} [groupLabel]
9
+ * Heading shown above the group. Replaces the heading the group's entries provide.
10
+ *
11
+ * @property {'ramp'} [groupStyle]
12
+ * How the group's entries are laid out. `'ramp'` shows them as touching bands, each filled with the
13
+ * entry's fill or fill pattern and outlined in its stroke colour: in a row with each label centred
14
+ * below its band when every label fits on one line, otherwise stacked with each label beside its
15
+ * band. When any entry has a stroke, the bands are separated by a small gap. A group with any
16
+ * symbol entries is shown without a groupStyle.
17
+ */
18
+
19
+ /**
20
+ * Options for the map key plugin.
21
+ *
22
+ * @typedef {Object} MapKeyPluginOptions
23
+ *
24
+ * @property {string} [noKeyItemText='No features displayed']
25
+ * Text shown in the key panel when it has no visible entries to display.
26
+ *
27
+ * @property {Object<string, MapKeyGroupConfig>} [groups]
28
+ * Display options for key groups, keyed by group id.
29
+ */
30
+
31
+ /**
32
+ * Creates the map key plugin.
33
+ *
34
+ * @param {MapKeyPluginOptions} [options]
35
+ * @returns {import('../../../src/types.js').PluginDescriptor}
36
+ */
3
37
  export default function createPlugin (options = {}) {
4
38
  return {
5
39
  noKeyItemText: 'No features displayed',
@@ -40,6 +40,21 @@ describe('mergeKeyGroupItems', () => {
40
40
  ])
41
41
  })
42
42
 
43
+ it('merges a matched group even when the incoming item has no keyDefinitions array', () => {
44
+ attachPluginStateRef({
45
+ current: {
46
+ groups: [{ id: 'group-1', type: 'group', groupLabel: 'Group 1' }],
47
+ keyDefinitions: [{ id: 'k1', groupId: 'group-1' }]
48
+ }
49
+ })
50
+
51
+ const items = [{ id: 'group-1' }]
52
+
53
+ expect(mergeKeyGroupItems(items)).toEqual([
54
+ { id: 'group-1', type: 'group', groupLabel: 'Group 1', keyDefinitions: [{ id: 'k1', groupId: 'group-1' }] }
55
+ ])
56
+ })
57
+
43
58
  it('reuses the cached plugin-state groups when the ref object is unchanged', () => {
44
59
  const ref = { current: { groups: [{ id: 'group-1', type: 'group', groupLabel: 'Group 1' }], keyDefinitions: [{ id: 'k1', groupId: 'group-1' }] } }
45
60
  attachPluginStateRef(ref)
@@ -1,3 +1 @@
1
1
  export { getDatasetRegistry } from './getDatasetRegistry.js'
2
- export { patternRegistry } from '../../../../src/services/patternRegistry.js'
3
- export { symbolRegistry } from '../../../../src/services/symbolRegistry.js'
@@ -1,15 +1,7 @@
1
- import { getDatasetRegistry, patternRegistry, symbolRegistry } from './index.js'
1
+ import { getDatasetRegistry } from './index.js'
2
2
 
3
3
  describe('registry/index', () => {
4
4
  it('exports getDatasetRegistry as a function', () => {
5
5
  expect(typeof getDatasetRegistry).toBe('function')
6
6
  })
7
-
8
- it('exports patternRegistry', () => {
9
- expect(patternRegistry).toBeDefined()
10
- })
11
-
12
- it('exports symbolRegistry', () => {
13
- expect(symbolRegistry).toBeDefined()
14
- })
15
7
  })
@@ -1,7 +1,10 @@
1
- export const HORIZONTAL_RAMP = 'horizontal-ramp'
1
+ /**
2
+ * `groupStyle` value that lays a group's entries out as a ramp of touching bands.
3
+ */
4
+ export const RAMP = 'ramp'
2
5
 
3
6
  const groupStyles = {
4
- HORIZONTAL_RAMP
7
+ RAMP
5
8
  }
6
9
 
7
10
  export default groupStyles
@@ -1,3 +1 @@
1
1
  export { getDatasetRegistry } from './getDatasetRegistry.js'
2
- export { patternRegistry } from '../../../../src/services/patternRegistry.js'
3
- export { symbolRegistry } from '../../../../src/services/symbolRegistry.js'
@@ -1,15 +1,7 @@
1
- import { getDatasetRegistry, patternRegistry, symbolRegistry } from './index.js'
1
+ import { getDatasetRegistry } from './index.js'
2
2
 
3
3
  describe('registry/index', () => {
4
4
  it('exports getDatasetRegistry as a function', () => {
5
5
  expect(typeof getDatasetRegistry).toBe('function')
6
6
  })
7
-
8
- it('exports patternRegistry', () => {
9
- expect(patternRegistry).toBeDefined()
10
- })
11
-
12
- it('exports symbolRegistry', () => {
13
- expect(symbolRegistry).toBeDefined()
14
- })
15
7
  })
@@ -1 +1 @@
1
- import{useEffect as e,useRef as t,useLayoutEffect as r}from"preact/compat";import{jsx as n,jsxs as a}from"preact/jsx-runtime";import i from"@babel/runtime/helpers/defineProperty";import s from"@babel/runtime/helpers/objectWithoutProperties";import o from"@babel/runtime/helpers/taggedTemplateLiteral";import l from"@babel/runtime/helpers/asyncToGenerator";var c={expanded:!1,showMarker:!0,placeholder:"Search",minSearchLength:3,maxSuggestions:8,noResultsMessage:"No results available",searchErrorMessage:"Sorry, there was a problem with search"},u="search";function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function h(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?d(Object(r),!0).forEach(function(t){i(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var p={TOGGLE_EXPANDED:(e,t)=>h(h({},e),{},{isExpanded:t,areSuggestionsVisible:t,hasFetchedSuggestions:!1,hasSearchError:!1}),SET_KEYBOARD_FOCUS_WITHIN:(e,t)=>h(h({},e),{},{hasKeyboardFocusWithin:t,areSuggestionsVisible:!0}),INPUT_BLUR:(e,t)=>h(h({},e),{},{hasKeyboardFocusWithin:!1,areSuggestionsVisible:e.areSuggestionsVisible&&"keyboard"!==t,selectedIndex:-1}),SET_VALUE:(e,t)=>h(h({},e),{},{value:t}),UPDATE_SUGGESTIONS:(e,t)=>h(h({},e),{},{suggestions:t.results,hasFetchedSuggestions:!0,hasSearchError:t.hasError}),SHOW_SUGGESTIONS:e=>h(h({},e),{},{areSuggestionsVisible:!0,hasFetchedSuggestions:!1,hasSearchError:!1}),HIDE_SUGGESTIONS:e=>h(h({},e),{},{areSuggestionsVisible:!1,hasFetchedSuggestions:!1,hasSearchError:!1}),SET_SELECTED:(e,t)=>h(h({},e),{},{selectedIndex:t,areSuggestionsVisible:t>=0})},g=e=>{var{id:t,pluginState:r,handleSuggestionClick:a}=e;return n("ul",{id:"".concat(t,"-search-suggestions"),role:"listbox","aria-labelledby":"".concat(t,"-search-input"),className:"im-c-search-suggestions",style:r.areSuggestionsVisible&&r.suggestions.length?void 0:{display:"none"},children:r.suggestions.map((e,i)=>n("li",{id:"".concat(t,"-search-suggestion-").concat(i),className:"im-c-search-suggestions__item",role:"option","aria-selected":r.selectedIndex===i,"aria-setsize":r.suggestions.length,"aria-posinset":i+1,onClick:()=>a(e),children:n("span",{className:"im-c-search-suggestions__label",dangerouslySetInnerHTML:{__html:e.marked}})},"".concat(t,"-").concat(e.type,"-").concat(e.id)))})};function f(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}var m=(e,t,r)=>function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?f(Object(r),!0).forEach(function(t){i(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):f(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}({display:e.expanded||t.isExpanded?"flex":void 0},"mobile"!==r.breakpoint&&(null==e?void 0:e.width)&&{width:e.width}),y=t=>{var{id:r,pluginState:i,pluginConfig:s,appState:o,inputRef:l,events:c,services:u,children:d}=t,{areSuggestionsVisible:h,hasFetchedSuggestions:p,hasSearchError:f,suggestions:y=[]}=i,{noResultsMessage:b,searchErrorMessage:E}=s;e(()=>{h&&p&&u.announce(((e,t,r,n)=>{if(t)return r;if(0===e)return n;var a=1===e?"result":"results";return"".concat(e," ").concat(a," available")})(y.length,f,E,b))},[y,p]);var v=["im-c-search-form",s.expanded&&"im-c-search-form--default-expanded","im-c-panel"].filter(Boolean).join(" "),w=h&&p&&(f||!y.length);return a("form",{id:"".concat(r,"-search-form"),role:"search",className:v,style:m(s,i,o),"aria-controls":"".concat(r,"-viewport"),onSubmit:e=>c.handleSubmit(e,o,i),children:[n("button",{type:"submit",style:{display:"none"},"aria-hidden":"true",tabIndex:-1,children:"Submit"}),a("div",{className:"im-c-search__input-container".concat(i.hasKeyboardFocusWithin?" im-c-search__input-container--keyboard-focus-within":""),children:[n("label",{htmlFor:"".concat(r,"-search-input"),className:"im-u-visually-hidden",children:s.placeholder}),n("input",{id:"".concat(r,"-search-input"),className:"im-c-search__input",type:"search",role:"combobox","aria-expanded":i.suggestionsVisible,"aria-controls":"".concat(r,"-search-suggestions"),"aria-activedescendant":i.selectedIndex>=0?"".concat(r,"-search-suggestion-").concat(i.selectedIndex):void 0,"aria-describedby":i.value?void 0:"".concat(r,"-search-hint"),"aria-autocomplete":"list",autoComplete:"off",placeholder:s.placeholder,name:"".concat(r,"-search-input"),spellCheck:!1,enterKeyHint:"search",value:i.value,onClick:c.handleInputClick,onChange:c.handleInputChange,onFocus:()=>c.handleInputFocus(o.interfaceType),onBlur:()=>c.handleInputBlur(o.interfaceType),onKeyDown:e=>c.handleInputKeyDown(e,i),ref:l}),n("span",{id:"".concat(r,"-search-hint"),className:"im-c-search__hint",children:"When search results are available use up and down arrows to review and enter to select. Touch device users, explore by touch or with swipe gestures."}),d]}),w&&n("div",{className:"im-c-search__status","aria-hidden":"true",children:f?E:b}),n(g,{id:r,appState:o,pluginState:i,handleSuggestionClick:e=>c.handleSuggestionClick(e,o)})]})},b=e=>{var{defaultExpanded:t,onClick:r,closeIcon:a}=e;return n("button",{"aria-label":"Close search",className:"im-c-map-button im-c-search-close-button",type:"button",onClick:r,style:t?{display:"none"}:void 0,children:a&&n("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",dangerouslySetInnerHTML:{__html:a}})})},E=e=>{var{defaultExpanded:t,submitIcon:r}=e;return n("button",{"aria-label":"Search",className:"im-c-map-button im-c-search-submit-button",type:"submit",style:t?void 0:{display:"none"},children:r&&n("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",dangerouslySetInnerHTML:{__html:r}})})};let v=" ";class w{static get separator(){return v}static set separator(e){v=e}static parse(e){if(!isNaN(parseFloat(e))&&isFinite(e))return Number(e);const t=String(e).trim().replace(/^-/,"").replace(/[NSEW]$/i,"").split(/[^0-9.,]+/);if(""==t[t.length-1]&&t.splice(t.length-1),""==t)return NaN;let r=null;switch(t.length){case 3:r=t[0]/1+t[1]/60+t[2]/3600;break;case 2:r=t[0]/1+t[1]/60;break;case 1:r=t[0];break;default:return NaN}return/^-|[WS]$/i.test(e.trim())&&(r=-r),Number(r)}static toDms(e,t="d",r=void 0){if(isNaN(e))return null;if("string"==typeof e&&""==e.trim())return null;if("boolean"==typeof e)return null;if(e==1/0)return null;if(null==e)return null;if(void 0===r)switch(t){case"d":case"deg":r=4;break;case"dm":case"deg+min":r=2;break;case"dms":case"deg+min+sec":r=0;break;default:t="d",r=4}e=Math.abs(e);let n=null,a=null,i=null,s=null;switch(t){default:case"d":case"deg":a=e.toFixed(r),a<100&&(a="0"+a),a<10&&(a="0"+a),n=a+"°";break;case"dm":case"deg+min":a=Math.floor(e),i=(60*e%60).toFixed(r),60==i&&(i=(0).toFixed(r),a++),a=("000"+a).slice(-3),i<10&&(i="0"+i),n=a+"°"+w.separator+i+"′";break;case"dms":case"deg+min+sec":a=Math.floor(e),i=Math.floor(3600*e/60)%60,s=(3600*e%60).toFixed(r),60==s&&(s=(0).toFixed(r),i++),60==i&&(i=0,a++),a=("000"+a).slice(-3),i=("00"+i).slice(-2),s<10&&(s="0"+s),n=a+"°"+w.separator+i+"′"+w.separator+s+"″"}return n}static toLat(e,t,r){const n=w.toDms(w.wrap90(e),t,r);return null===n?"–":n.slice(1)+w.separator+(e<0?"S":"N")}static toLon(e,t,r){const n=w.toDms(w.wrap180(e),t,r);return null===n?"–":n+w.separator+(e<0?"W":"E")}static toBrng(e,t,r){const n=w.toDms(w.wrap360(e),t,r);return null===n?"–":n.replace("360","0")}static fromLocale(e){const t=123456.789.toLocaleString(),r={thousands:t.slice(3,4),decimal:t.slice(7,8)};return e.replace(r.thousands,"⁜").replace(r.decimal,".").replace("⁜",",")}static toLocale(e){const t=123456.789.toLocaleString(),r={thousands:t.slice(3,4),decimal:t.slice(7,8)};return e.replace(/,([0-9])/,"⁜$1").replace(".",r.decimal).replace("⁜",r.thousands)}static compassPoint(e,t=3){if(![1,2,3].includes(Number(t)))throw new RangeError(`invalid precision ‘${t}’`);e=w.wrap360(e);const r=4*2**(t-1);return["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"][Math.round(e*r/360)%r*16/r]}static wrap90(e){if(-90<=e&&e<=90)return e;const t=e,r=360;return 1*Math.abs(((t-90)%r+r)%r-180)-90}static wrap180(e){if(-180<=e&&e<=180)return e;const t=360;return((360*e/t-180)%t+t)%t-180}static wrap360(e){if(0<=e&&e<360)return e;const t=360;return(360*e/t%t+t)%t}}Number.prototype.toRadians=function(){return this*Math.PI/180},Number.prototype.toDegrees=function(){return 180*this/Math.PI};class S{constructor(e,t,r){if(isNaN(e)||isNaN(t)||isNaN(r))throw new TypeError(`invalid vector [${e},${t},${r}]`);this.x=Number(e),this.y=Number(t),this.z=Number(r)}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}plus(e){if(!(e instanceof S))throw new TypeError("v is not Vector3d object");return new S(this.x+e.x,this.y+e.y,this.z+e.z)}minus(e){if(!(e instanceof S))throw new TypeError("v is not Vector3d object");return new S(this.x-e.x,this.y-e.y,this.z-e.z)}times(e){if(isNaN(e))throw new TypeError(`invalid scalar value ‘${e}’`);return new S(this.x*e,this.y*e,this.z*e)}dividedBy(e){if(isNaN(e))throw new TypeError(`invalid scalar value ‘${e}’`);return new S(this.x/e,this.y/e,this.z/e)}dot(e){if(!(e instanceof S))throw new TypeError("v is not Vector3d object");return this.x*e.x+this.y*e.y+this.z*e.z}cross(e){if(!(e instanceof S))throw new TypeError("v is not Vector3d object");const t=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,n=this.x*e.y-this.y*e.x;return new S(t,r,n)}negate(){return new S(-this.x,-this.y,-this.z)}unit(){const e=this.length;if(1==e)return this;if(0==e)return this;const t=this.x/e,r=this.y/e,n=this.z/e;return new S(t,r,n)}angleTo(e,t=void 0){if(!(e instanceof S))throw new TypeError("v is not Vector3d object");if(!(t instanceof S||null==t))throw new TypeError("n is not Vector3d object");const r=null==t||this.cross(e).dot(t)>=0?1:-1,n=this.cross(e).length*r,a=this.dot(e);return Math.atan2(n,a)}rotateAround(e,t){if(!(e instanceof S))throw new TypeError("axis is not Vector3d object");const r=t.toRadians(),n=this.unit(),a=e.unit(),i=Math.sin(r),s=Math.cos(r),o=1-s,l=a.x,c=a.y,u=a.z,d=[[o*l*l+s,o*l*c-i*u,o*l*u+i*c],[o*l*c+i*u,o*c*c+s,o*c*u-i*l],[o*l*u-i*c,o*c*u+i*l,o*u*u+s]],h=[d[0][0]*n.x+d[0][1]*n.y+d[0][2]*n.z,d[1][0]*n.x+d[1][1]*n.y+d[1][2]*n.z,d[2][0]*n.x+d[2][1]*n.y+d[2][2]*n.z];return new S(h[0],h[1],h[2])}toString(e=3){return`[${this.x.toFixed(e)},${this.y.toFixed(e)},${this.z.toFixed(e)}]`}}Number.prototype.toRadians=function(){return this*Math.PI/180},Number.prototype.toDegrees=function(){return 180*this/Math.PI};const O={WGS84:{a:6378137,b:6356752.314245,f:1/298.257223563}},N={WGS84:{ellipsoid:O.WGS84}};Object.freeze(O.WGS84),Object.freeze(N.WGS84);class T{constructor(e,t,r=0){if(isNaN(e)||null==e)throw new TypeError(`invalid lat ‘${e}’`);if(isNaN(t)||null==t)throw new TypeError(`invalid lon ‘${t}’`);if(isNaN(r)||null==r)throw new TypeError(`invalid height ‘${r}’`);this._lat=w.wrap90(Number(e)),this._lon=w.wrap180(Number(t)),this._height=Number(r)}get lat(){return this._lat}get latitude(){return this._lat}set lat(e){if(this._lat=isNaN(e)?w.wrap90(w.parse(e)):w.wrap90(Number(e)),isNaN(this._lat))throw new TypeError(`invalid lat ‘${e}’`)}set latitude(e){if(this._lat=isNaN(e)?w.wrap90(w.parse(e)):w.wrap90(Number(e)),isNaN(this._lat))throw new TypeError(`invalid latitude ‘${e}’`)}get lon(){return this._lon}get lng(){return this._lon}get longitude(){return this._lon}set lon(e){if(this._lon=isNaN(e)?w.wrap180(w.parse(e)):w.wrap180(Number(e)),isNaN(this._lon))throw new TypeError(`invalid lon ‘${e}’`)}set lng(e){if(this._lon=isNaN(e)?w.wrap180(w.parse(e)):w.wrap180(Number(e)),isNaN(this._lon))throw new TypeError(`invalid lng ‘${e}’`)}set longitude(e){if(this._lon=isNaN(e)?w.wrap180(w.parse(e)):w.wrap180(Number(e)),isNaN(this._lon))throw new TypeError(`invalid longitude ‘${e}’`)}get height(){return this._height}set height(e){if(this._height=Number(e),isNaN(this._height))throw new TypeError(`invalid height ‘${e}’`)}get datum(){return this._datum}set datum(e){this._datum=e}static get ellipsoids(){return O}static get datums(){return N}static parse(...e){if(0==e.length)throw new TypeError("invalid (empty) point");let t,r,n;if("object"==typeof e[0]&&(1==e.length||!isNaN(parseFloat(e[1])))){const a=e[0];if("Point"==a.type&&Array.isArray(a.coordinates)?([r,t,n]=a.coordinates,n=n||0):(null!=a.latitude&&(t=a.latitude),null!=a.lat&&(t=a.lat),null!=a.longitude&&(r=a.longitude),null!=a.lng&&(r=a.lng),null!=a.lon&&(r=a.lon),null!=a.height&&(n=a.height),t=w.wrap90(w.parse(t)),r=w.wrap180(w.parse(r))),null!=e[1]&&(n=e[1]),isNaN(t)||isNaN(r))throw new TypeError(`invalid point ‘${JSON.stringify(e[0])}’`)}if("string"==typeof e[0]&&2==e[0].split(",").length&&([t,r]=e[0].split(","),t=w.wrap90(w.parse(t)),r=w.wrap180(w.parse(r)),n=e[1]||0,isNaN(t)||isNaN(r)))throw new TypeError(`invalid point ‘${e[0]}’`);if(null==t&&null==r&&([t,r]=e,t=w.wrap90(w.parse(t)),r=w.wrap180(w.parse(r)),n=e[2]||0,isNaN(t)||isNaN(r)))throw new TypeError(`invalid point ‘${e.toString()}’`);return new this(t,r,n)}toCartesian(){const e=this.datum?this.datum.ellipsoid:this.referenceFrame?this.referenceFrame.ellipsoid:O.WGS84,t=this.lat.toRadians(),r=this.lon.toRadians(),n=this.height,{a:a,f:i}=e,s=Math.sin(t),o=Math.cos(t),l=Math.sin(r),c=Math.cos(r),u=2*i-i*i,d=a/Math.sqrt(1-u*s*s);return new _((d+n)*o*c,(d+n)*o*l,(d*(1-u)+n)*s)}equals(e){if(!(e instanceof T))throw new TypeError(`invalid point ‘${e}’`);return!(Math.abs(this.lat-e.lat)>Number.EPSILON)&&(!(Math.abs(this.lon-e.lon)>Number.EPSILON)&&(!(Math.abs(this.height-e.height)>Number.EPSILON)&&(this.datum==e.datum&&(this.referenceFrame==e.referenceFrame&&this.epoch==e.epoch))))}toString(e="d",t=void 0,r=null){if(!["d","dm","dms","n"].includes(e))throw new RangeError(`invalid format ‘${e}’`);const n=(this.height>=0?" +":" ")+this.height.toFixed(r)+"m";if("n"==e){null==t&&(t=4);return`${this.lat.toFixed(t)}, ${this.lon.toFixed(t)}${null==r?"":n}`}return`${w.toLat(this.lat,e,t)}, ${w.toLon(this.lon,e,t)}${null==r?"":n}`}}class _ extends S{constructor(e,t,r){super(e,t,r)}toLatLon(e=O.WGS84){if(!e||!e.a)throw new TypeError(`invalid ellipsoid ‘${e}’`);const{x:t,y:r,z:n}=this,{a:a,b:i,f:s}=e,o=2*s-s*s,l=o/(1-o),c=Math.sqrt(t*t+r*r),u=i*n/(a*c)*(1+l*i/Math.sqrt(c*c+n*n)),d=u/Math.sqrt(1+u*u),h=d/u,p=isNaN(h)?0:Math.atan2(n+l*i*d*d*d,c-o*a*h*h*h),g=Math.atan2(r,t),f=Math.sin(p),m=c*Math.cos(p)+n*f-a*a/(a/Math.sqrt(1-o*f*f));return new T(p.toDegrees(),g.toDegrees(),m)}toString(e=0){return`[${this.x.toFixed(e)},${this.y.toFixed(e)},${this.z.toFixed(e)}]`}}const x={WGS84:{a:6378137,b:6356752.314245,f:1/298.257223563},Airy1830:{a:6377563.396,b:6356256.909,f:1/299.3249646},AiryModified:{a:6377340.189,b:6356034.448,f:1/299.3249646},Bessel1841:{a:6377397.155,b:6356078.962818,f:1/299.1528128},Clarke1866:{a:6378206.4,b:6356583.8,f:1/294.978698214},Clarke1880IGN:{a:6378249.2,b:6356515,f:1/293.466021294},GRS80:{a:6378137,b:6356752.31414,f:1/298.257222101},Intl1924:{a:6378388,b:6356911.946,f:1/297},WGS72:{a:6378135,b:6356750.5,f:1/298.26}},M={ED50:{ellipsoid:x.Intl1924,transform:[89.5,93.8,123.1,-1.2,0,0,.156]},ETRS89:{ellipsoid:x.GRS80,transform:[0,0,0,0,0,0,0]},Irl1975:{ellipsoid:x.AiryModified,transform:[-482.53,130.596,-564.557,-8.15,1.042,.214,.631]},NAD27:{ellipsoid:x.Clarke1866,transform:[8,-160,-176,0,0,0,0]},NAD83:{ellipsoid:x.GRS80,transform:[.9956,-1.9103,-.5215,-62e-5,.025915,.009426,.011599]},NTF:{ellipsoid:x.Clarke1880IGN,transform:[168,60,-320,0,0,0,0]},OSGB36:{ellipsoid:x.Airy1830,transform:[-446.448,125.157,-542.06,20.4894,-.1502,-.247,-.8421]},Potsdam:{ellipsoid:x.Bessel1841,transform:[-582,-105,-414,-8.3,1.04,.35,-3.08]},TokyoJapan:{ellipsoid:x.Bessel1841,transform:[148,-507,-685,0,0,0,0]},WGS72:{ellipsoid:x.WGS72,transform:[0,0,-4.5,-.22,0,0,.554]},WGS84:{ellipsoid:x.WGS84,transform:[0,0,0,0,0,0,0]}};Object.keys(x).forEach(e=>Object.freeze(x[e])),Object.keys(M).forEach(e=>{Object.freeze(M[e]),Object.freeze(M[e].transform)});class D extends T{constructor(e,t,r=0,n=M.WGS84){if(!n||null==n.ellipsoid)throw new TypeError(`unrecognised datum ‘${n}’`);super(e,t,r),this._datum=n}get datum(){return this._datum}static get ellipsoids(){return x}static get datums(){return M}static parse(...e){let t=M.WGS84;if((4==e.length||3==e.length&&"object"==typeof e[2])&&(t=e.pop()),!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);const r=super.parse(...e);return r._datum=t,r}convertDatum(e){if(!e||null==e.ellipsoid)throw new TypeError(`unrecognised datum ‘${e}’`);return this.toCartesian().convertDatum(e).toLatLon()}toCartesian(){const e=super.toCartesian();return new R(e.x,e.y,e.z,this.datum)}}class R extends _{constructor(e,t,r,n=void 0){if(n&&null==n.ellipsoid)throw new TypeError(`unrecognised datum ‘${n}’`);super(e,t,r),n&&(this._datum=n)}get datum(){return this._datum}set datum(e){if(!e||null==e.ellipsoid)throw new TypeError(`unrecognised datum ‘${e}’`);this._datum=e}toLatLon(e=void 0){e&&(console.info("datum parameter to Cartesian_Datum.toLatLon is deprecated: set datum before calling toLatLon()"),this.datum=e);const t=this.datum||M.WGS84;if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);const r=super.toLatLon(t.ellipsoid);return new D(r.lat,r.lon,r.height,this.datum)}convertDatum(e){if(!e||null==e.ellipsoid)throw new TypeError(`unrecognised datum ‘${e}’`);if(!this.datum)throw new TypeError("cartesian coordinate has no datum");let t=null,r=null;null!=this.datum&&this.datum!=M.WGS84||(t=this,r=e.transform),e==M.WGS84&&(t=this,r=this.datum.transform.map(e=>-e)),null==r&&(t=this.convertDatum(M.WGS84),r=e.transform);const n=t.applyTransform(r);return n.datum=e,n}applyTransform(e){const{x:t,y:r,z:n}=this,a=e[0],i=e[1],s=e[2],o=e[3]/1e6+1,l=(e[4]/3600).toRadians(),c=(e[5]/3600).toRadians(),u=(e[6]/3600).toRadians();return new R(a+t*o-r*u+n*c,i+t*u+r*o-n*l,s-t*c+r*l+n*o)}}const j={trueOrigin:{lat:49,lon:-2},scaleFactor:.9996012717,ellipsoid:D.ellipsoids.Airy1830};class P{constructor(e,t){if(this.easting=Number(e),this.northing=Number(t),isNaN(e)||this.easting<0||this.easting>7e5)throw new RangeError(`invalid easting ‘${e}’`);if(isNaN(t)||this.northing<0||this.northing>13e5)throw new RangeError(`invalid northing ‘${t}’`)}toLatLon(e=D.datums.WGS84){const{easting:t,northing:r}=this,{a:n,b:a}=j.ellipsoid,i=j.trueOrigin.lat.toRadians(),s=j.trueOrigin.lon.toRadians(),o=-1e5,l=j.scaleFactor,c=1-a*a/(n*n),u=(n-a)/(n+a),d=u*u,h=u*u*u;let p=i,g=0;do{p=(r-o-g)/(n*l)+p;g=a*l*((1+u+5/4*d+5/4*h)*(p-i)-(3*u+3*u*u+21/8*h)*Math.sin(p-i)*Math.cos(p+i)+(15/8*d+15/8*h)*Math.sin(2*(p-i))*Math.cos(2*(p+i))-35/24*h*Math.sin(3*(p-i))*Math.cos(3*(p+i)))}while(Math.abs(r-o-g)>=1e-5);const f=Math.cos(p),m=Math.sin(p),y=n*l/Math.sqrt(1-c*m*m),b=n*l*(1-c)/Math.pow(1-c*m*m,1.5),E=y/b-1,v=Math.tan(p),w=v*v,S=w*w,O=1/f,N=y*y*y,T=N*y*y,_=t-4e5,x=_*_,M=x*_,R=x*x,P=M*x;p=p-v/(2*b*y)*x+v/(24*b*N)*(5+3*w+E-9*w*E)*R-v/(720*b*T)*(61+90*w+45*S)*(R*x);const k=s+O/y*_-O/(6*N)*(y/b+2*w)*M+O/(120*T)*(5+28*w+24*S)*P-O/(5040*(T*y*y))*(61+662*w+1320*S+720*(S*w))*(P*x);let A=new G(p.toDegrees(),k.toDegrees(),0,D.datums.OSGB36);return e!=D.datums.OSGB36&&(A=A.convertDatum(e),A=new G(A.lat,A.lon,A.height,A.datum)),A}static parse(e){let t=(e=String(e).trim()).match(/^(\d+),\s*(\d+)$/);if(t)return new P(t[1],t[2]);if(t=e.match(/^[HNST][ABCDEFGHJKLMNOPQRSTUVWXYZ]\s*[0-9]+\s*[0-9]+$/i),!t)throw new Error(`invalid grid reference ‘${e}’`);let r=e.toUpperCase().charCodeAt(0)-"A".charCodeAt(0),n=e.toUpperCase().charCodeAt(1)-"A".charCodeAt(0);r>7&&r--,n>7&&n--;const a=(r-2)%5*5+n%5,i=19-5*Math.floor(r/5)-Math.floor(n/5);let s=e.slice(2).trim().split(/\s+/);if(1==s.length&&(s=[s[0].slice(0,s[0].length/2),s[0].slice(s[0].length/2)]),s[0].length!=s[1].length)throw new Error(`invalid grid reference ‘${e}’`);s[0]=s[0].padEnd(5,"0"),s[1]=s[1].padEnd(5,"0");const o=a+s[0],l=i+s[1];return new P(o,l)}toString(e=10){if(![0,2,4,6,8,10,12,14,16].includes(Number(e)))throw new RangeError(`invalid precision ‘${e}’`);let{easting:t,northing:r}=this;if(0==e){const e={useGrouping:!1,minimumIntegerDigits:6,maximumFractionDigits:3};return`${t.toLocaleString("en",e)},${r.toLocaleString("en",e)}`}const n=Math.floor(t/1e5),a=Math.floor(r/1e5);let i=19-a-(19-a)%5+Math.floor((n+10)/5),s=5*(19-a)%25+n%5;i>7&&i++,s>7&&s++;const o=String.fromCharCode(i+"A".charCodeAt(0),s+"A".charCodeAt(0));return t=Math.floor(t%1e5/Math.pow(10,5-e/2)),r=Math.floor(r%1e5/Math.pow(10,5-e/2)),t=t.toString().padStart(e/2,"0"),r=r.toString().padStart(e/2,"0"),`${o} ${t} ${r}`}}class G extends D{toOsGrid(){const e=this.datum==D.datums.OSGB36?this:this.convertDatum(D.datums.OSGB36),t=e.lat.toRadians(),r=e.lon.toRadians(),{a:n,b:a}=j.ellipsoid,i=j.trueOrigin.lat.toRadians(),s=j.trueOrigin.lon.toRadians(),o=j.scaleFactor,l=1-a*a/(n*n),c=(n-a)/(n+a),u=c*c,d=c*c*c,h=Math.cos(t),p=Math.sin(t),g=n*o/Math.sqrt(1-l*p*p),f=n*o*(1-l)/Math.pow(1-l*p*p,1.5),m=g/f-1,y=a*o*((1+c+5/4*u+5/4*d)*(t-i)-(3*c+3*c*c+21/8*d)*Math.sin(t-i)*Math.cos(t+i)+(15/8*u+15/8*d)*Math.sin(2*(t-i))*Math.cos(2*(t+i))-35/24*d*Math.sin(3*(t-i))*Math.cos(3*(t+i))),b=h*h*h,E=b*h*h,v=Math.tan(t)*Math.tan(t),w=v*v,S=r-s,O=S*S,N=O*S,T=N*S,_=T*S;let x=y+-1e5+g/2*p*h*O+g/24*p*b*(5-v+9*m)*T+g/720*p*E*(61-58*v+w)*(_*S),M=4e5+g*h*S+g/6*b*(g/f-v)*N+g/120*E*(5-18*v+w+14*m-58*v*m)*_;x=Number(x.toFixed(3)),M=Number(M.toFixed(3));try{return new P(M,x)}catch(t){throw new Error(`${t.message} from (${e.lat.toFixed(6)},${e.lon.toFixed(6)}).toOsGrid()`)}}convertDatum(e){const t=super.convertDatum(e);return new G(t.lat,t.lon,t.height,t.datum)}}var k;function A(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function C(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?A(Object(r),!0).forEach(function(t){i(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):A(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var I=500,L=e=>{var t=e.GAZETTEER_ENTRY,r="eng"===t.NAME2_LANG?t.NAME2:t.NAME1;return e.GAZETTEER_ENTRY.NAME1=r,e.GAZETTEER_ENTRY.NAME1_LANG="eng",e},$=(e,t)=>{var r,n,a,i,{MBR_XMIN:s,MBR_YMIN:o,MBR_XMAX:l,MBR_YMAX:c,GEOMETRY_X:u,GEOMETRY_Y:d}=t;if(null==s?(r=u-I,n=d-I,a=u+I,i=d+I):(r=s,n=o,a=l,i=c),"EPSG:27700"===e)return[r,n,a,i];if("EPSG:4326"===e){var h=new P(r,n).toLatLon(),p=new P(a,i).toLatLon();return[h.lon,h.lat,p.lon,p.lat].map(e=>Math.round(1e6*e)/1e6)}throw new Error("Unsupported CRS: ".concat(e))},F=(e,t)=>{var{GEOMETRY_X:r,GEOMETRY_Y:n}=t;if("EPSG:27700"===e)return[r,n];if("EPSG:4326"===e){var a=new P(r,n).toLatLon();return[Math.round(1e6*a.lon)/1e6,Math.round(1e6*a.lat)/1e6]}throw new Error("Unsupported CRS: ".concat(e))},W=function(e,t,r,n){var a,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:8;if(!e||e.error||0===(null===(a=e.header)||void 0===a?void 0:a.totalresults))return[];var s=e.results;return s=((e,t)=>{var r=t.toLowerCase().replace(/,/g,"").split(" ");return e.map(L).filter(e=>r.some(r=>{return e.GAZETTEER_ENTRY.NAME1.toLowerCase().includes(r)||(n=(n=t).replace(/\s/g,""),/^(([A-Z]{1,2}\d[A-Z\d]?|ASCN|STHL|TDCU|BBND|[BFS]IQQ|PCRN|TKCA) ?\d[A-Z]{2}|BFPO ?\d{1,4}|(KY\d|MSR|VG|AI)[ -]?\d{4}|[A-Z]{2} ?\d{2}|GE ?CX|GIR ?0A{2}|SAN ?TA1)$/i.test(n));var n}))})(s,t),s=((e,t)=>e.filter(e=>{var r,n=null==e||null===(r=e.GAZETTEER_ENTRY)||void 0===r||null===(r=r.COUNTRY)||void 0===r?void 0:r.toLowerCase();return n&&t.includes(n)}))(s=(e=>Array.from(new Map(e.map(e=>[e.GAZETTEER_ENTRY.ID,e])).values()))(s),r),(s=s.slice(0,i)).map(e=>C(C({id:e.GAZETTEER_ENTRY.ID,bounds:$(n,e.GAZETTEER_ENTRY),point:F(n,e.GAZETTEER_ENTRY)},((e,t)=>{var r,n,a,i,{NAME1:s,COUNTY_UNITARY:l,DISTRICT_BOROUGH:c,POSTCODE_DISTRICT:u,LOCAL_TYPE:d}=t,h="".concat(["City","Postcode"].includes(d)?"":u+", ").concat("City"===d?"":l||c),p="".concat(s).concat(h?", "+h:"");return{text:p,marked:(r=p,n=e,a=n.replace(/\s+/g,"").split("").join(String.raw(k||(k=o(["s*"],["\\s*"])))),i=new RegExp("(".concat(a,")"),"i"),r.replace(i,"<mark>$1</mark>"))}})(t,e.GAZETTEER_ENTRY)),{},{type:"os-names"}))};var U=e=>{var{url:t,options:r}=e;return new Request(t,r)},B=function(){var e=l(function*(e,t,r){var n,a={url:null===(n=e.urlTemplate)||void 0===n?void 0:n.replace("{query}",encodeURIComponent(t)),options:{method:"GET"}};if(e.buildRequest){var i=e.buildRequest(t,()=>a);return i instanceof Request?i:U(i)}return U(r?yield r(a,t):a)});return function(t,r,n){return e.apply(this,arguments)}}(),z=function(){var e=l(function*(e,t,r){try{var n=yield fetch(t);if(!n.ok)return console.error("Fetch error for ".concat(e.label||"dataset",": ").concat(n.status)),{error:!0};var a=yield n.json();return e.parseResults(a,r)}catch(t){return console.error("Network error for ".concat(e.label||"dataset",":"),t),{error:!0}}});return function(t,r,n){return e.apply(this,arguments)}}(),Y=function(){var e=l(function*(e,t,r,n){var a=(e=>e.replaceAll(/[^a-zA-Z0-9\s\-.,]/g,"").trim())(e),i=t.filter(t=>{var r=!t.includeRegex||t.includeRegex.test(e),n=!!t.excludeRegex&&t.excludeRegex.test(a);return r&&!n}),s=[],o=!1;for(var l of i){var c=yield B(l,a,n),u=yield z(l,c,a);if(null!=u&&u.error?o=!0:null!=u&&u.length&&(s=[...s,...u]),l.exclusive&&s.length)break}return r({type:"UPDATE_SUGGESTIONS",payload:{results:s,hasError:o}}),{results:s,sanitisedValue:a}});return function(t,r,n,a){return e.apply(this,arguments)}}();function V(e){var{mapProvider:t,bounds:r,point:n,markers:a,showMarker:i,markerOptions:s}=e;t.fitToBounds(r),i&&a.add("search",n,s)}function q(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function H(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?q(Object(r),!0).forEach(function(t){i(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):q(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var K=e=>{var t;return(null==e||null===(t=e.current)||void 0===t?void 0:t.search)||document.querySelector(".im-c-map-button--search")},Z=(e,t,r)=>{var n,a=K(t);if("Tab"===e.key&&a){var i=Array.from(document.querySelectorAll("input, button, select, textarea, a[href], [tabindex]")).filter(e=>e.tabIndex>=0&&!e.disabled&&e.getClientRects().length>0),s=i[i.indexOf(e.target)+(e.shiftKey?-1:1)];if(null===(n=r.current)||void 0===n||!n.contains(s)){var o=e.shiftKey?a:i[i.indexOf(a)+1];o&&(e.preventDefault(),o.focus())}}},X=e=>{var{dispatch:t,services:r,viewportRef:n,searchContainerRef:a,mapProvider:i,markers:s,datasets:o,transformRequest:u,showMarker:d,markerOptions:h}=e,p="";return{handleTabOut(e,t){Z(e,t,a)},handleCloseClick(e,n){var a,i,o;t({type:"TOGGLE_EXPANDED",payload:!1}),t({type:"UPDATE_SUGGESTIONS",payload:{results:[],hasError:!1}}),t({type:"SET_VALUE",payload:""}),a=null==n?void 0:n.buttonRefs,i=0,o=()=>{var e=K(a);e&&(e.focus(),document.activeElement===e)||i<30&&(i+=1,requestAnimationFrame(o))},requestAnimationFrame(o),s.remove("search"),r.eventBus.emit("search:clear"),r.eventBus.emit("search:close")},handleSubmit:(e,a,g)=>l(function*(){e.preventDefault();var{suggestions:l,selectedIndex:f,value:m}=g,y=null==m?void 0:m.trim();if(t({type:"SET_SELECTED",payload:-1}),t({type:"HIDE_SUGGESTIONS"}),f>=0){var b,E=l[f];return t({type:"SET_VALUE",payload:E.text}),null===(b=n.current)||void 0===b||b.focus(),V({mapProvider:i,bounds:E.bounds,point:E.point,markers:s,showMarker:d,markerOptions:h}),void r.eventBus.emit("search:match",H({query:E.text},E))}if(!((null==y?void 0:y.length)<c.minSearchLength)){var v=l;if(!l.length||y!==p){var{results:w,sanitisedValue:S}=yield Y(y,o,t,u);v=w,p=S}if(v.length){var O;null===(O=n.current)||void 0===O||O.focus(),"mobile"===a.breakpoint&&(t({type:"TOGGLE_EXPANDED",payload:!1}),r.eventBus.emit("search:close"));var N=v[0];V({mapProvider:i,bounds:N.bounds,point:N.point,markers:s,showMarker:d,markerOptions:h}),r.eventBus.emit("search:match",H({query:m},N))}}})()}};function J(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}var Q=e=>{var{dispatch:t,services:r,mapProvider:n,markers:a,showMarker:s,markerOptions:o,viewportRef:l}=e,c=(e,t)=>{var r;return t>=0?"".concat(null===(r=e[t])||void 0===r?void 0:r.text,". ").concat(t+1," of ").concat(e.length," is highlighted"):"".concat(e.length," suggestions available")};return{handleSuggestionClick(e,c){var u;t({type:"SET_VALUE",payload:e.text}),t({type:"HIDE_SUGGESTIONS"}),t({type:"SET_SELECTED",payload:-1}),"mobile"===c.breakpoint&&(t({type:"TOGGLE_EXPANDED",payload:!1}),r.eventBus.emit("search:close")),null===(u=l.current)||void 0===u||u.focus(),V({mapProvider:n,bounds:e.bounds,point:e.point,markers:a,showMarker:s,markerOptions:o}),r.eventBus.emit("search:match",function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?J(Object(r),!0).forEach(function(t){i(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):J(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}({query:e.text},e))},handleInputKeyDown(e,n){var{suggestions:a,selectedIndex:i}=n;switch(e.key){case"ArrowDown":if(null==a||!a.length)return;if(e.preventDefault(),i<a.length-1){var s=i+1;r.announce(c(a,s)),t({type:"SET_SELECTED",payload:s}),t({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:!1})}break;case"ArrowUp":if(null==a||!a.length)return;e.preventDefault();var o=i>0?i-1:-1;r.announce(c(a,o)),t({type:"SET_SELECTED",payload:o}),t({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:o<0});break;case"Escape":e.preventDefault(),t({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:!0}),t({type:"HIDE_SUGGESTIONS"}),t({type:"SET_SELECTED",payload:-1})}}}};function ee(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function te(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ee(Object(r),!0).forEach(function(t){i(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ee(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function re(e){var t,r,n,a,{dispatch:i,searchContainerRef:s}=e,o=(t=t=>Y(t,e.datasets,i,e.transformRequest),r=350,n=null,a=function(){for(var e=arguments.length,a=new Array(e),i=0;i<e;i++)a[i]=arguments[i];clearTimeout(n),n=setTimeout(()=>{t(...a)},r)},a.cancel=()=>{n&&(clearTimeout(n),n=null)},a),l=X(e),u=(e=>{var{dispatch:t,debouncedFetchSuggestions:r}=e;return{handleInputClick(){t({type:"SHOW_SUGGESTIONS"})},handleInputFocus(e){t({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:"keyboard"===e})},handleInputBlur(e){t({type:"INPUT_BLUR",payload:e})},handleInputChange(e){var n=e.target.value;if(t({type:"SET_VALUE",payload:n}),n.length<c.minSearchLength)return r.cancel(),t({type:"UPDATE_SUGGESTIONS",payload:{results:[],hasError:!1}}),void t({type:"HIDE_SUGGESTIONS"});t({type:"SHOW_SUGGESTIONS"}),r(n)}}})(te(te({},e),{},{debouncedFetchSuggestions:o})),d=Q(e);return te(te(te(te({},l),u),d),{},{handleOutside(t){s.current.contains(t.target)||(i({type:"TOGGLE_EXPANDED",payload:!1}),e.services.eventBus.emit("search:close"))}})}var ne=["marker"];function ae(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}var ie={reducer:{initialState:{isExpanded:!1,hasKeyboardFocusWithin:!1,value:"",suggestions:[],areSuggestionsVisible:!1,hasFetchedSuggestions:!1,hasSearchError:!1,selectedIndex:-1},actions:p},applicationModes:{[u]:{}},buttons:[{id:"search",label:"Search",iconId:"search",ariaControls:e=>{var{appConfig:t}=e;return"".concat(t.id,"-search-form")},expandedWhen:e=>{var{pluginState:t}=e;return t.isExpanded},excludeWhen:e=>{var{pluginConfig:t}=e;return Boolean(t.expanded)},keepFocus:!0,onClick:(e,t)=>{var{pluginState:r,services:n}=t;r.dispatch({type:"TOGGLE_EXPANDED",payload:!0}),n.eventBus.emit("search:open")},mobile:{slot:"top-right",showLabel:!1},tablet:{slot:"top-left",showLabel:!1},desktop:{slot:"top-left",showLabel:!1}}],controls:[{id:"search",mobile:{slot:"header"},tablet:{slot:"top-left"},desktop:{slot:"top-left"},render:function(o){var{appConfig:l,iconRegistry:c,pluginState:d,pluginConfig:h,appState:p,mapState:g,services:f,mapProvider:m,setApplicationMode:v,clearApplicationMode:w}=o,{id:S}=l,{interfaceType:O}=p,{expanded:N,customDatasets:T,osNamesURL:_,regions:x,maxSuggestions:M}=h,{dispatch:D,isExpanded:R,areSuggestionsVisible:j,suggestions:P}=d,G=c.close,k=c.search,A=t(null),C=t(null),I=p.layoutRefs.viewportRef,L=function(e){var{customDatasets:t=[],osNamesURL:r,crs:n,regions:a=["england","scotland","wales"],maxSuggestions:i}=e;return r?[{name:"osNames",urlTemplate:r,parseResults:(e,t)=>W(e,t,a,n,i),includeRegex:/[a-zA-Z0-9]/,excludeRegex:/^(?:[a-z]{2}\s*(?:\d{3}\s*\d{3}|\d{4}\s*\d{4}|\d{5}\s*\d{5})|\d+\s*,?\s*\d+)$/i},...t]:t}({customDatasets:T,osNamesURL:_,regions:x,maxSuggestions:M,crs:m.crs}),$=t(null);if(!$.current){var{marker:F}=h,U=s(h,ne);$.current=re(function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ae(Object(r),!0).forEach(function(t){i(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ae(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}({dispatch:D,datasets:L,services:f,mapProvider:m,viewportRef:I,searchContainerRef:A,markers:g.markers,markerOptions:F},U))}var B=$.current,z=R||!!(N&&j&&P.length);return e(()=>{var e;R&&(null===(e=C.current)||void 0===e||e.focus())},[R]),r(()=>{if(R)return v(u),()=>w(u)},[R]),r(()=>{if(z)return I.current.style.pointerEvents="none",document.addEventListener("focusin",B.handleOutside),document.addEventListener("pointerdown",B.handleOutside),()=>{I.current.style.pointerEvents="auto",document.removeEventListener("focusin",B.handleOutside),document.removeEventListener("pointerdown",B.handleOutside)}},[R,O,j,P]),n("div",{className:"im-c-search".concat(N||R?"":" im-c-search--collapsed"),ref:A,onKeyDown:e=>B.handleTabOut(e,p.buttonRefs),children:a(y,{id:S,pluginState:d,pluginConfig:h,appState:p,inputRef:C,events:B,services:f,children:[n(b,{defaultExpanded:N,onClick:e=>B.handleCloseClick(e,p),closeIcon:G}),n(E,{defaultExpanded:N,submitIcon:k})]})})}}],icons:[{id:"search",svgContent:'<path d="m21 21-4.34-4.34"></path><circle cx="11" cy="11" r="8"></circle>'}]},se=Object.freeze({__proto__:null,manifest:ie});export{c as D,se as m};
1
+ import{useEffect as e,useRef as t,useLayoutEffect as r}from"preact/compat";import{jsx as n,jsxs as a}from"preact/jsx-runtime";import s from"@babel/runtime/helpers/defineProperty";import i from"@babel/runtime/helpers/objectWithoutProperties";import o from"@babel/runtime/helpers/taggedTemplateLiteral";import l from"@babel/runtime/helpers/asyncToGenerator";var c={expanded:!1,showMarker:!0,placeholder:"Search",minSearchLength:3,maxSuggestions:8,noResultsMessage:"No results available",searchErrorMessage:"Sorry, there was a problem with search"},u="search";function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function h(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?d(Object(r),!0).forEach(function(t){s(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var p={TOGGLE_EXPANDED:(e,t)=>h(h({},e),{},{isExpanded:t,areSuggestionsVisible:t,hasFetchedSuggestions:!1,hasSearchError:!1}),SET_KEYBOARD_FOCUS_WITHIN:(e,t)=>h(h({},e),{},{hasKeyboardFocusWithin:t,areSuggestionsVisible:!0}),INPUT_BLUR:(e,t)=>h(h({},e),{},{hasKeyboardFocusWithin:!1,areSuggestionsVisible:e.areSuggestionsVisible&&"keyboard"!==t,selectedIndex:-1}),SET_VALUE:(e,t)=>h(h({},e),{},{value:t}),UPDATE_SUGGESTIONS:(e,t)=>h(h({},e),{},{suggestions:t.results,hasFetchedSuggestions:!0,hasSearchError:t.hasError}),SHOW_SUGGESTIONS:e=>h(h({},e),{},{areSuggestionsVisible:!0,hasFetchedSuggestions:!1,hasSearchError:!1}),HIDE_SUGGESTIONS:e=>h(h({},e),{},{areSuggestionsVisible:!1,hasFetchedSuggestions:!1,hasSearchError:!1}),SET_SELECTED:(e,t)=>h(h({},e),{},{selectedIndex:t,areSuggestionsVisible:t>=0})},g=e=>{var{id:t,pluginState:r,handleSuggestionClick:a}=e;return n("ul",{id:"".concat(t,"-search-suggestions"),role:"listbox","aria-labelledby":"".concat(t,"-search-input"),className:"im-c-search-suggestions",style:r.areSuggestionsVisible&&r.suggestions.length?void 0:{display:"none"},onMouseDown:e=>e.preventDefault(),children:r.suggestions.map((e,s)=>n("li",{id:"".concat(t,"-search-suggestion-").concat(s),className:"im-c-search-suggestions__item",role:"option","aria-selected":r.selectedIndex===s,"aria-setsize":r.suggestions.length,"aria-posinset":s+1,onClick:()=>a(e),children:n("span",{className:"im-c-search-suggestions__label",dangerouslySetInnerHTML:{__html:e.marked}})},"".concat(t,"-").concat(e.type,"-").concat(e.id)))})};function m(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}var f=(e,t,r)=>function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?m(Object(r),!0).forEach(function(t){s(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):m(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}({display:e.expanded||t.isExpanded?"flex":void 0},"mobile"!==r.breakpoint&&(null==e?void 0:e.width)&&{width:e.width}),y=t=>{var{id:r,pluginState:s,pluginConfig:i,appState:o,inputRef:l,events:c,services:u,children:d}=t,{areSuggestionsVisible:h,hasFetchedSuggestions:p,hasSearchError:m,suggestions:y=[]}=s,{noResultsMessage:b,searchErrorMessage:E}=i;e(()=>{h&&p&&u.announce(((e,t,r,n)=>{if(t)return r;if(0===e)return n;var a=1===e?"result":"results";return"".concat(e," ").concat(a," available")})(y.length,m,E,b))},[y,p]);var v=["im-c-search-form",i.expanded&&"im-c-search-form--default-expanded","im-c-panel"].filter(Boolean).join(" "),w=h&&p&&(m||!y.length);return a("form",{id:"".concat(r,"-search-form"),role:"search",className:v,style:f(i,s,o),"aria-controls":"".concat(r,"-viewport"),onSubmit:e=>c.handleSubmit(e,o,s),children:[n("button",{type:"submit",style:{display:"none"},"aria-hidden":"true",tabIndex:-1,children:"Submit"}),a("div",{className:"im-c-search__input-container".concat(s.hasKeyboardFocusWithin?" im-c-search__input-container--keyboard-focus-within":""),children:[n("label",{htmlFor:"".concat(r,"-search-input"),className:"im-u-visually-hidden",children:i.placeholder}),n("input",{id:"".concat(r,"-search-input"),className:"im-c-search__input",type:"search",role:"combobox","aria-expanded":s.suggestionsVisible,"aria-controls":"".concat(r,"-search-suggestions"),"aria-activedescendant":s.selectedIndex>=0?"".concat(r,"-search-suggestion-").concat(s.selectedIndex):void 0,"aria-describedby":s.value?void 0:"".concat(r,"-search-hint"),"aria-autocomplete":"list",autoComplete:"off",placeholder:i.placeholder,name:"".concat(r,"-search-input"),spellCheck:!1,enterKeyHint:"search",value:s.value,onClick:c.handleInputClick,onChange:e=>c.handleInputChange(e,s),onFocus:()=>c.handleInputFocus(o.interfaceType),onBlur:()=>c.handleInputBlur(o.interfaceType),onKeyDown:e=>c.handleInputKeyDown(e,s),ref:l}),n("span",{id:"".concat(r,"-search-hint"),className:"im-c-search__hint",children:"When search results are available use up and down arrows to review and enter to select. Touch device users, explore by touch or with swipe gestures."}),d]}),w&&n("div",{className:"im-c-search__status","aria-hidden":"true",children:m?E:b}),n(g,{id:r,appState:o,pluginState:s,handleSuggestionClick:e=>c.handleSuggestionClick(e,o)})]})},b=e=>{var{defaultExpanded:t,onClick:r,closeIcon:a}=e;return n("button",{"aria-label":"Close search",className:"im-c-map-button im-c-search-close-button",type:"button",onClick:r,style:t?{display:"none"}:void 0,children:a&&n("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",dangerouslySetInnerHTML:{__html:a}})})},E=e=>{var{defaultExpanded:t,submitIcon:r}=e;return n("button",{"aria-label":"Search",className:"im-c-map-button im-c-search-submit-button",type:"submit",style:t?void 0:{display:"none"},children:r&&n("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",dangerouslySetInnerHTML:{__html:r}})})};let v=" ";class w{static get separator(){return v}static set separator(e){v=e}static parse(e){if(!isNaN(parseFloat(e))&&isFinite(e))return Number(e);const t=String(e).trim().replace(/^-/,"").replace(/[NSEW]$/i,"").split(/[^0-9.,]+/);if(""==t[t.length-1]&&t.splice(t.length-1),""==t)return NaN;let r=null;switch(t.length){case 3:r=t[0]/1+t[1]/60+t[2]/3600;break;case 2:r=t[0]/1+t[1]/60;break;case 1:r=t[0];break;default:return NaN}return/^-|[WS]$/i.test(e.trim())&&(r=-r),Number(r)}static toDms(e,t="d",r=void 0){if(isNaN(e))return null;if("string"==typeof e&&""==e.trim())return null;if("boolean"==typeof e)return null;if(e==1/0)return null;if(null==e)return null;if(void 0===r)switch(t){case"d":case"deg":r=4;break;case"dm":case"deg+min":r=2;break;case"dms":case"deg+min+sec":r=0;break;default:t="d",r=4}e=Math.abs(e);let n=null,a=null,s=null,i=null;switch(t){default:case"d":case"deg":a=e.toFixed(r),a<100&&(a="0"+a),a<10&&(a="0"+a),n=a+"°";break;case"dm":case"deg+min":a=Math.floor(e),s=(60*e%60).toFixed(r),60==s&&(s=(0).toFixed(r),a++),a=("000"+a).slice(-3),s<10&&(s="0"+s),n=a+"°"+w.separator+s+"′";break;case"dms":case"deg+min+sec":a=Math.floor(e),s=Math.floor(3600*e/60)%60,i=(3600*e%60).toFixed(r),60==i&&(i=(0).toFixed(r),s++),60==s&&(s=0,a++),a=("000"+a).slice(-3),s=("00"+s).slice(-2),i<10&&(i="0"+i),n=a+"°"+w.separator+s+"′"+w.separator+i+"″"}return n}static toLat(e,t,r){const n=w.toDms(w.wrap90(e),t,r);return null===n?"–":n.slice(1)+w.separator+(e<0?"S":"N")}static toLon(e,t,r){const n=w.toDms(w.wrap180(e),t,r);return null===n?"–":n+w.separator+(e<0?"W":"E")}static toBrng(e,t,r){const n=w.toDms(w.wrap360(e),t,r);return null===n?"–":n.replace("360","0")}static fromLocale(e){const t=123456.789.toLocaleString(),r={thousands:t.slice(3,4),decimal:t.slice(7,8)};return e.replace(r.thousands,"⁜").replace(r.decimal,".").replace("⁜",",")}static toLocale(e){const t=123456.789.toLocaleString(),r={thousands:t.slice(3,4),decimal:t.slice(7,8)};return e.replace(/,([0-9])/,"⁜$1").replace(".",r.decimal).replace("⁜",r.thousands)}static compassPoint(e,t=3){if(![1,2,3].includes(Number(t)))throw new RangeError(`invalid precision ‘${t}’`);e=w.wrap360(e);const r=4*2**(t-1);return["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"][Math.round(e*r/360)%r*16/r]}static wrap90(e){if(-90<=e&&e<=90)return e;const t=e,r=360;return 1*Math.abs(((t-90)%r+r)%r-180)-90}static wrap180(e){if(-180<=e&&e<=180)return e;const t=360;return((360*e/t-180)%t+t)%t-180}static wrap360(e){if(0<=e&&e<360)return e;const t=360;return(360*e/t%t+t)%t}}Number.prototype.toRadians=function(){return this*Math.PI/180},Number.prototype.toDegrees=function(){return 180*this/Math.PI};class S{constructor(e,t,r){if(isNaN(e)||isNaN(t)||isNaN(r))throw new TypeError(`invalid vector [${e},${t},${r}]`);this.x=Number(e),this.y=Number(t),this.z=Number(r)}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}plus(e){if(!(e instanceof S))throw new TypeError("v is not Vector3d object");return new S(this.x+e.x,this.y+e.y,this.z+e.z)}minus(e){if(!(e instanceof S))throw new TypeError("v is not Vector3d object");return new S(this.x-e.x,this.y-e.y,this.z-e.z)}times(e){if(isNaN(e))throw new TypeError(`invalid scalar value ‘${e}’`);return new S(this.x*e,this.y*e,this.z*e)}dividedBy(e){if(isNaN(e))throw new TypeError(`invalid scalar value ‘${e}’`);return new S(this.x/e,this.y/e,this.z/e)}dot(e){if(!(e instanceof S))throw new TypeError("v is not Vector3d object");return this.x*e.x+this.y*e.y+this.z*e.z}cross(e){if(!(e instanceof S))throw new TypeError("v is not Vector3d object");const t=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,n=this.x*e.y-this.y*e.x;return new S(t,r,n)}negate(){return new S(-this.x,-this.y,-this.z)}unit(){const e=this.length;if(1==e)return this;if(0==e)return this;const t=this.x/e,r=this.y/e,n=this.z/e;return new S(t,r,n)}angleTo(e,t=void 0){if(!(e instanceof S))throw new TypeError("v is not Vector3d object");if(!(t instanceof S||null==t))throw new TypeError("n is not Vector3d object");const r=null==t||this.cross(e).dot(t)>=0?1:-1,n=this.cross(e).length*r,a=this.dot(e);return Math.atan2(n,a)}rotateAround(e,t){if(!(e instanceof S))throw new TypeError("axis is not Vector3d object");const r=t.toRadians(),n=this.unit(),a=e.unit(),s=Math.sin(r),i=Math.cos(r),o=1-i,l=a.x,c=a.y,u=a.z,d=[[o*l*l+i,o*l*c-s*u,o*l*u+s*c],[o*l*c+s*u,o*c*c+i,o*c*u-s*l],[o*l*u-s*c,o*c*u+s*l,o*u*u+i]],h=[d[0][0]*n.x+d[0][1]*n.y+d[0][2]*n.z,d[1][0]*n.x+d[1][1]*n.y+d[1][2]*n.z,d[2][0]*n.x+d[2][1]*n.y+d[2][2]*n.z];return new S(h[0],h[1],h[2])}toString(e=3){return`[${this.x.toFixed(e)},${this.y.toFixed(e)},${this.z.toFixed(e)}]`}}Number.prototype.toRadians=function(){return this*Math.PI/180},Number.prototype.toDegrees=function(){return 180*this/Math.PI};const O={WGS84:{a:6378137,b:6356752.314245,f:1/298.257223563}},N={WGS84:{ellipsoid:O.WGS84}};Object.freeze(O.WGS84),Object.freeze(N.WGS84);class T{constructor(e,t,r=0){if(isNaN(e)||null==e)throw new TypeError(`invalid lat ‘${e}’`);if(isNaN(t)||null==t)throw new TypeError(`invalid lon ‘${t}’`);if(isNaN(r)||null==r)throw new TypeError(`invalid height ‘${r}’`);this._lat=w.wrap90(Number(e)),this._lon=w.wrap180(Number(t)),this._height=Number(r)}get lat(){return this._lat}get latitude(){return this._lat}set lat(e){if(this._lat=isNaN(e)?w.wrap90(w.parse(e)):w.wrap90(Number(e)),isNaN(this._lat))throw new TypeError(`invalid lat ‘${e}’`)}set latitude(e){if(this._lat=isNaN(e)?w.wrap90(w.parse(e)):w.wrap90(Number(e)),isNaN(this._lat))throw new TypeError(`invalid latitude ‘${e}’`)}get lon(){return this._lon}get lng(){return this._lon}get longitude(){return this._lon}set lon(e){if(this._lon=isNaN(e)?w.wrap180(w.parse(e)):w.wrap180(Number(e)),isNaN(this._lon))throw new TypeError(`invalid lon ‘${e}’`)}set lng(e){if(this._lon=isNaN(e)?w.wrap180(w.parse(e)):w.wrap180(Number(e)),isNaN(this._lon))throw new TypeError(`invalid lng ‘${e}’`)}set longitude(e){if(this._lon=isNaN(e)?w.wrap180(w.parse(e)):w.wrap180(Number(e)),isNaN(this._lon))throw new TypeError(`invalid longitude ‘${e}’`)}get height(){return this._height}set height(e){if(this._height=Number(e),isNaN(this._height))throw new TypeError(`invalid height ‘${e}’`)}get datum(){return this._datum}set datum(e){this._datum=e}static get ellipsoids(){return O}static get datums(){return N}static parse(...e){if(0==e.length)throw new TypeError("invalid (empty) point");let t,r,n;if("object"==typeof e[0]&&(1==e.length||!isNaN(parseFloat(e[1])))){const a=e[0];if("Point"==a.type&&Array.isArray(a.coordinates)?([r,t,n]=a.coordinates,n=n||0):(null!=a.latitude&&(t=a.latitude),null!=a.lat&&(t=a.lat),null!=a.longitude&&(r=a.longitude),null!=a.lng&&(r=a.lng),null!=a.lon&&(r=a.lon),null!=a.height&&(n=a.height),t=w.wrap90(w.parse(t)),r=w.wrap180(w.parse(r))),null!=e[1]&&(n=e[1]),isNaN(t)||isNaN(r))throw new TypeError(`invalid point ‘${JSON.stringify(e[0])}’`)}if("string"==typeof e[0]&&2==e[0].split(",").length&&([t,r]=e[0].split(","),t=w.wrap90(w.parse(t)),r=w.wrap180(w.parse(r)),n=e[1]||0,isNaN(t)||isNaN(r)))throw new TypeError(`invalid point ‘${e[0]}’`);if(null==t&&null==r&&([t,r]=e,t=w.wrap90(w.parse(t)),r=w.wrap180(w.parse(r)),n=e[2]||0,isNaN(t)||isNaN(r)))throw new TypeError(`invalid point ‘${e.toString()}’`);return new this(t,r,n)}toCartesian(){const e=this.datum?this.datum.ellipsoid:this.referenceFrame?this.referenceFrame.ellipsoid:O.WGS84,t=this.lat.toRadians(),r=this.lon.toRadians(),n=this.height,{a:a,f:s}=e,i=Math.sin(t),o=Math.cos(t),l=Math.sin(r),c=Math.cos(r),u=2*s-s*s,d=a/Math.sqrt(1-u*i*i);return new _((d+n)*o*c,(d+n)*o*l,(d*(1-u)+n)*i)}equals(e){if(!(e instanceof T))throw new TypeError(`invalid point ‘${e}’`);return!(Math.abs(this.lat-e.lat)>Number.EPSILON)&&(!(Math.abs(this.lon-e.lon)>Number.EPSILON)&&(!(Math.abs(this.height-e.height)>Number.EPSILON)&&(this.datum==e.datum&&(this.referenceFrame==e.referenceFrame&&this.epoch==e.epoch))))}toString(e="d",t=void 0,r=null){if(!["d","dm","dms","n"].includes(e))throw new RangeError(`invalid format ‘${e}’`);const n=(this.height>=0?" +":" ")+this.height.toFixed(r)+"m";if("n"==e){null==t&&(t=4);return`${this.lat.toFixed(t)}, ${this.lon.toFixed(t)}${null==r?"":n}`}return`${w.toLat(this.lat,e,t)}, ${w.toLon(this.lon,e,t)}${null==r?"":n}`}}class _ extends S{constructor(e,t,r){super(e,t,r)}toLatLon(e=O.WGS84){if(!e||!e.a)throw new TypeError(`invalid ellipsoid ‘${e}’`);const{x:t,y:r,z:n}=this,{a:a,b:s,f:i}=e,o=2*i-i*i,l=o/(1-o),c=Math.sqrt(t*t+r*r),u=s*n/(a*c)*(1+l*s/Math.sqrt(c*c+n*n)),d=u/Math.sqrt(1+u*u),h=d/u,p=isNaN(h)?0:Math.atan2(n+l*s*d*d*d,c-o*a*h*h*h),g=Math.atan2(r,t),m=Math.sin(p),f=c*Math.cos(p)+n*m-a*a/(a/Math.sqrt(1-o*m*m));return new T(p.toDegrees(),g.toDegrees(),f)}toString(e=0){return`[${this.x.toFixed(e)},${this.y.toFixed(e)},${this.z.toFixed(e)}]`}}const x={WGS84:{a:6378137,b:6356752.314245,f:1/298.257223563},Airy1830:{a:6377563.396,b:6356256.909,f:1/299.3249646},AiryModified:{a:6377340.189,b:6356034.448,f:1/299.3249646},Bessel1841:{a:6377397.155,b:6356078.962818,f:1/299.1528128},Clarke1866:{a:6378206.4,b:6356583.8,f:1/294.978698214},Clarke1880IGN:{a:6378249.2,b:6356515,f:1/293.466021294},GRS80:{a:6378137,b:6356752.31414,f:1/298.257222101},Intl1924:{a:6378388,b:6356911.946,f:1/297},WGS72:{a:6378135,b:6356750.5,f:1/298.26}},M={ED50:{ellipsoid:x.Intl1924,transform:[89.5,93.8,123.1,-1.2,0,0,.156]},ETRS89:{ellipsoid:x.GRS80,transform:[0,0,0,0,0,0,0]},Irl1975:{ellipsoid:x.AiryModified,transform:[-482.53,130.596,-564.557,-8.15,1.042,.214,.631]},NAD27:{ellipsoid:x.Clarke1866,transform:[8,-160,-176,0,0,0,0]},NAD83:{ellipsoid:x.GRS80,transform:[.9956,-1.9103,-.5215,-62e-5,.025915,.009426,.011599]},NTF:{ellipsoid:x.Clarke1880IGN,transform:[168,60,-320,0,0,0,0]},OSGB36:{ellipsoid:x.Airy1830,transform:[-446.448,125.157,-542.06,20.4894,-.1502,-.247,-.8421]},Potsdam:{ellipsoid:x.Bessel1841,transform:[-582,-105,-414,-8.3,1.04,.35,-3.08]},TokyoJapan:{ellipsoid:x.Bessel1841,transform:[148,-507,-685,0,0,0,0]},WGS72:{ellipsoid:x.WGS72,transform:[0,0,-4.5,-.22,0,0,.554]},WGS84:{ellipsoid:x.WGS84,transform:[0,0,0,0,0,0,0]}};Object.keys(x).forEach(e=>Object.freeze(x[e])),Object.keys(M).forEach(e=>{Object.freeze(M[e]),Object.freeze(M[e].transform)});class D extends T{constructor(e,t,r=0,n=M.WGS84){if(!n||null==n.ellipsoid)throw new TypeError(`unrecognised datum ‘${n}’`);super(e,t,r),this._datum=n}get datum(){return this._datum}static get ellipsoids(){return x}static get datums(){return M}static parse(...e){let t=M.WGS84;if((4==e.length||3==e.length&&"object"==typeof e[2])&&(t=e.pop()),!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);const r=super.parse(...e);return r._datum=t,r}convertDatum(e){if(!e||null==e.ellipsoid)throw new TypeError(`unrecognised datum ‘${e}’`);return this.toCartesian().convertDatum(e).toLatLon()}toCartesian(){const e=super.toCartesian();return new R(e.x,e.y,e.z,this.datum)}}class R extends _{constructor(e,t,r,n=void 0){if(n&&null==n.ellipsoid)throw new TypeError(`unrecognised datum ‘${n}’`);super(e,t,r),n&&(this._datum=n)}get datum(){return this._datum}set datum(e){if(!e||null==e.ellipsoid)throw new TypeError(`unrecognised datum ‘${e}’`);this._datum=e}toLatLon(e=void 0){e&&(console.info("datum parameter to Cartesian_Datum.toLatLon is deprecated: set datum before calling toLatLon()"),this.datum=e);const t=this.datum||M.WGS84;if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);const r=super.toLatLon(t.ellipsoid);return new D(r.lat,r.lon,r.height,this.datum)}convertDatum(e){if(!e||null==e.ellipsoid)throw new TypeError(`unrecognised datum ‘${e}’`);if(!this.datum)throw new TypeError("cartesian coordinate has no datum");let t=null,r=null;null!=this.datum&&this.datum!=M.WGS84||(t=this,r=e.transform),e==M.WGS84&&(t=this,r=this.datum.transform.map(e=>-e)),null==r&&(t=this.convertDatum(M.WGS84),r=e.transform);const n=t.applyTransform(r);return n.datum=e,n}applyTransform(e){const{x:t,y:r,z:n}=this,a=e[0],s=e[1],i=e[2],o=e[3]/1e6+1,l=(e[4]/3600).toRadians(),c=(e[5]/3600).toRadians(),u=(e[6]/3600).toRadians();return new R(a+t*o-r*u+n*c,s+t*u+r*o-n*l,i-t*c+r*l+n*o)}}const G={trueOrigin:{lat:49,lon:-2},scaleFactor:.9996012717,ellipsoid:D.ellipsoids.Airy1830};class k{constructor(e,t){if(this.easting=Number(e),this.northing=Number(t),isNaN(e)||this.easting<0||this.easting>7e5)throw new RangeError(`invalid easting ‘${e}’`);if(isNaN(t)||this.northing<0||this.northing>13e5)throw new RangeError(`invalid northing ‘${t}’`)}toLatLon(e=D.datums.WGS84){const{easting:t,northing:r}=this,{a:n,b:a}=G.ellipsoid,s=G.trueOrigin.lat.toRadians(),i=G.trueOrigin.lon.toRadians(),o=-1e5,l=G.scaleFactor,c=1-a*a/(n*n),u=(n-a)/(n+a),d=u*u,h=u*u*u;let p=s,g=0;do{p=(r-o-g)/(n*l)+p;g=a*l*((1+u+5/4*d+5/4*h)*(p-s)-(3*u+3*u*u+21/8*h)*Math.sin(p-s)*Math.cos(p+s)+(15/8*d+15/8*h)*Math.sin(2*(p-s))*Math.cos(2*(p+s))-35/24*h*Math.sin(3*(p-s))*Math.cos(3*(p+s)))}while(Math.abs(r-o-g)>=1e-5);const m=Math.cos(p),f=Math.sin(p),y=n*l/Math.sqrt(1-c*f*f),b=n*l*(1-c)/Math.pow(1-c*f*f,1.5),E=y/b-1,v=Math.tan(p),w=v*v,S=w*w,O=1/m,N=y*y*y,T=N*y*y,_=t-4e5,x=_*_,M=x*_,R=x*x,k=M*x;p=p-v/(2*b*y)*x+v/(24*b*N)*(5+3*w+E-9*w*E)*R-v/(720*b*T)*(61+90*w+45*S)*(R*x);const j=i+O/y*_-O/(6*N)*(y/b+2*w)*M+O/(120*T)*(5+28*w+24*S)*k-O/(5040*(T*y*y))*(61+662*w+1320*S+720*(S*w))*(k*x);let A=new P(p.toDegrees(),j.toDegrees(),0,D.datums.OSGB36);return e!=D.datums.OSGB36&&(A=A.convertDatum(e),A=new P(A.lat,A.lon,A.height,A.datum)),A}static parse(e){let t=(e=String(e).trim()).match(/^(\d+),\s*(\d+)$/);if(t)return new k(t[1],t[2]);if(t=e.match(/^[HNST][ABCDEFGHJKLMNOPQRSTUVWXYZ]\s*[0-9]+\s*[0-9]+$/i),!t)throw new Error(`invalid grid reference ‘${e}’`);let r=e.toUpperCase().charCodeAt(0)-"A".charCodeAt(0),n=e.toUpperCase().charCodeAt(1)-"A".charCodeAt(0);r>7&&r--,n>7&&n--;const a=(r-2)%5*5+n%5,s=19-5*Math.floor(r/5)-Math.floor(n/5);let i=e.slice(2).trim().split(/\s+/);if(1==i.length&&(i=[i[0].slice(0,i[0].length/2),i[0].slice(i[0].length/2)]),i[0].length!=i[1].length)throw new Error(`invalid grid reference ‘${e}’`);i[0]=i[0].padEnd(5,"0"),i[1]=i[1].padEnd(5,"0");const o=a+i[0],l=s+i[1];return new k(o,l)}toString(e=10){if(![0,2,4,6,8,10,12,14,16].includes(Number(e)))throw new RangeError(`invalid precision ‘${e}’`);let{easting:t,northing:r}=this;if(0==e){const e={useGrouping:!1,minimumIntegerDigits:6,maximumFractionDigits:3};return`${t.toLocaleString("en",e)},${r.toLocaleString("en",e)}`}const n=Math.floor(t/1e5),a=Math.floor(r/1e5);let s=19-a-(19-a)%5+Math.floor((n+10)/5),i=5*(19-a)%25+n%5;s>7&&s++,i>7&&i++;const o=String.fromCharCode(s+"A".charCodeAt(0),i+"A".charCodeAt(0));return t=Math.floor(t%1e5/Math.pow(10,5-e/2)),r=Math.floor(r%1e5/Math.pow(10,5-e/2)),t=t.toString().padStart(e/2,"0"),r=r.toString().padStart(e/2,"0"),`${o} ${t} ${r}`}}class P extends D{toOsGrid(){const e=this.datum==D.datums.OSGB36?this:this.convertDatum(D.datums.OSGB36),t=e.lat.toRadians(),r=e.lon.toRadians(),{a:n,b:a}=G.ellipsoid,s=G.trueOrigin.lat.toRadians(),i=G.trueOrigin.lon.toRadians(),o=G.scaleFactor,l=1-a*a/(n*n),c=(n-a)/(n+a),u=c*c,d=c*c*c,h=Math.cos(t),p=Math.sin(t),g=n*o/Math.sqrt(1-l*p*p),m=n*o*(1-l)/Math.pow(1-l*p*p,1.5),f=g/m-1,y=a*o*((1+c+5/4*u+5/4*d)*(t-s)-(3*c+3*c*c+21/8*d)*Math.sin(t-s)*Math.cos(t+s)+(15/8*u+15/8*d)*Math.sin(2*(t-s))*Math.cos(2*(t+s))-35/24*d*Math.sin(3*(t-s))*Math.cos(3*(t+s))),b=h*h*h,E=b*h*h,v=Math.tan(t)*Math.tan(t),w=v*v,S=r-i,O=S*S,N=O*S,T=N*S,_=T*S;let x=y+-1e5+g/2*p*h*O+g/24*p*b*(5-v+9*f)*T+g/720*p*E*(61-58*v+w)*(_*S),M=4e5+g*h*S+g/6*b*(g/m-v)*N+g/120*E*(5-18*v+w+14*f-58*v*f)*_;x=Number(x.toFixed(3)),M=Number(M.toFixed(3));try{return new k(M,x)}catch(t){throw new Error(`${t.message} from (${e.lat.toFixed(6)},${e.lon.toFixed(6)}).toOsGrid()`)}}convertDatum(e){const t=super.convertDatum(e);return new P(t.lat,t.lon,t.height,t.datum)}}var j;function A(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function C(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?A(Object(r),!0).forEach(function(t){s(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):A(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var I=500,L=e=>{var t=e.GAZETTEER_ENTRY,r="eng"===t.NAME2_LANG?t.NAME2:t.NAME1;return e.GAZETTEER_ENTRY.NAME1=r,e.GAZETTEER_ENTRY.NAME1_LANG="eng",e},$=(e,t)=>{var r,n,a,s,{MBR_XMIN:i,MBR_YMIN:o,MBR_XMAX:l,MBR_YMAX:c,GEOMETRY_X:u,GEOMETRY_Y:d}=t;if(null==i?(r=u-I,n=d-I,a=u+I,s=d+I):(r=i,n=o,a=l,s=c),"EPSG:27700"===e)return[r,n,a,s];if("EPSG:4326"===e){var h=new k(r,n).toLatLon(),p=new k(a,s).toLatLon();return[h.lon,h.lat,p.lon,p.lat].map(e=>Math.round(1e6*e)/1e6)}throw new Error("Unsupported CRS: ".concat(e))},F=(e,t)=>{var{GEOMETRY_X:r,GEOMETRY_Y:n}=t;if("EPSG:27700"===e)return[r,n];if("EPSG:4326"===e){var a=new k(r,n).toLatLon();return[Math.round(1e6*a.lon)/1e6,Math.round(1e6*a.lat)/1e6]}throw new Error("Unsupported CRS: ".concat(e))},W=function(e,t,r,n){var a,s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:8;if(!e||e.error||0===(null===(a=e.header)||void 0===a?void 0:a.totalresults))return[];var i=e.results;return i=((e,t)=>{var r=t.toLowerCase().replace(/,/g,"").split(" ");return e.map(L).filter(e=>r.some(r=>{return e.GAZETTEER_ENTRY.NAME1.toLowerCase().includes(r)||(n=(n=t).replace(/\s/g,""),/^(([A-Z]{1,2}\d[A-Z\d]?|ASCN|STHL|TDCU|BBND|[BFS]IQQ|PCRN|TKCA) ?\d[A-Z]{2}|BFPO ?\d{1,4}|(KY\d|MSR|VG|AI)[ -]?\d{4}|[A-Z]{2} ?\d{2}|GE ?CX|GIR ?0A{2}|SAN ?TA1)$/i.test(n));var n}))})(i,t),i=((e,t)=>e.filter(e=>{var r,n=null==e||null===(r=e.GAZETTEER_ENTRY)||void 0===r||null===(r=r.COUNTRY)||void 0===r?void 0:r.toLowerCase();return n&&t.includes(n)}))(i=(e=>Array.from(new Map(e.map(e=>[e.GAZETTEER_ENTRY.ID,e])).values()))(i),r),(i=i.slice(0,s)).map(e=>C(C({id:e.GAZETTEER_ENTRY.ID,bounds:$(n,e.GAZETTEER_ENTRY),point:F(n,e.GAZETTEER_ENTRY)},((e,t)=>{var r,n,a,s,{NAME1:i,COUNTY_UNITARY:l,DISTRICT_BOROUGH:c,POSTCODE_DISTRICT:u,LOCAL_TYPE:d}=t,h="".concat(["City","Postcode"].includes(d)?"":u+", ").concat("City"===d?"":l||c),p="".concat(i).concat(h?", "+h:"");return{text:p,marked:(r=p,n=e,a=n.replace(/\s+/g,"").split("").join(String.raw(j||(j=o(["s*"],["\\s*"])))),s=new RegExp("(".concat(a,")"),"i"),r.replace(s,"<mark>$1</mark>"))}})(t,e.GAZETTEER_ENTRY)),{},{type:"os-names"}))};var U=e=>{var{url:t,options:r}=e;return new Request(t,r)},B=function(){var e=l(function*(e,t,r){var n,a={url:null===(n=e.urlTemplate)||void 0===n?void 0:n.replace("{query}",encodeURIComponent(t)),options:{method:"GET"}};if(e.buildRequest){var s=e.buildRequest(t,()=>a);return s instanceof Request?s:U(s)}return U(r?yield r(a,t):a)});return function(t,r,n){return e.apply(this,arguments)}}(),z=function(){var e=l(function*(e,t,r){try{var n=yield fetch(t);if(!n.ok)return console.error("Fetch error for ".concat(e.label||"dataset",": ").concat(n.status)),{error:!0};var a=yield n.json();return e.parseResults(a,r)}catch(t){return console.error("Network error for ".concat(e.label||"dataset",":"),t),{error:!0}}});return function(t,r,n){return e.apply(this,arguments)}}(),Y=function(){var e=l(function*(e,t,r,n){var a=(e=>e.replaceAll(/[^a-zA-Z0-9\s\-.,]/g,"").trim())(e),s=t.filter(t=>{var r=!t.includeRegex||t.includeRegex.test(e),n=!!t.excludeRegex&&t.excludeRegex.test(a);return r&&!n}),i=[],o=!1;for(var l of s){var c=yield B(l,a,n),u=yield z(l,c,a);if(null!=u&&u.error?o=!0:null!=u&&u.length&&(i=[...i,...u]),l.exclusive&&i.length)break}return r({type:"UPDATE_SUGGESTIONS",payload:{results:i,hasError:o}}),{results:i,sanitisedValue:a}});return function(t,r,n,a){return e.apply(this,arguments)}}();function V(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}var q=e=>{var{suggestion:t,query:r,services:n,mapProvider:a,markers:i,showMarker:o,markerOptions:l}=e;n.focusMap({message:"Map moved to {query}".replace("{query}",r)}),function(e){var{mapProvider:t,bounds:r,point:n,markers:a,showMarker:s,markerOptions:i}=e;t.fitToBounds(r),s&&a.add("search",n,i)}({mapProvider:a,bounds:t.bounds,point:t.point,markers:i,showMarker:o,markerOptions:l}),n.eventBus.emit("search:match",function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?V(Object(r),!0).forEach(function(t){s(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):V(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}({query:r},t))},H=e=>{var t;return(null==e||null===(t=e.current)||void 0===t?void 0:t.search)||document.querySelector(".im-c-map-button--search")},K=(e,t,r)=>{var n,a=H(t);if("Tab"===e.key&&a){var s=Array.from(document.querySelectorAll("input, button, select, textarea, a[href], [tabindex]")).filter(e=>e.tabIndex>=0&&!e.disabled&&e.getClientRects().length>0),i=s[s.indexOf(e.target)+(e.shiftKey?-1:1)];if(null===(n=r.current)||void 0===n||!n.contains(i)){var o=e.shiftKey?a:s[s.indexOf(a)+1];o&&(e.preventDefault(),o.focus())}}},Z=e=>{var{dispatch:t,services:r,searchContainerRef:n,mapProvider:a,markers:s,datasets:i,transformRequest:o,showMarker:u,markerOptions:d}=e,h="";return{handleTabOut(e,t){K(e,t,n)},handleCloseClick(e,n){var a,i,o;t({type:"TOGGLE_EXPANDED",payload:!1}),t({type:"UPDATE_SUGGESTIONS",payload:{results:[],hasError:!1}}),t({type:"SET_VALUE",payload:""}),a=null==n?void 0:n.buttonRefs,i=0,o=()=>{var e=H(a);e&&(e.focus(),document.activeElement===e)||i<30&&(i+=1,requestAnimationFrame(o))},requestAnimationFrame(o),s.remove("search"),r.eventBus.emit("search:clear"),r.eventBus.emit("search:close")},handleSubmit:(e,n,p)=>l(function*(){e.preventDefault();var{suggestions:l,selectedIndex:g,value:m}=p,f=null==m?void 0:m.trim();if(t({type:"SET_SELECTED",payload:-1}),t({type:"HIDE_SUGGESTIONS"}),g>=0){var y=l[g];return t({type:"SET_VALUE",payload:y.text}),void q({suggestion:y,query:y.text,services:r,mapProvider:a,markers:s,showMarker:u,markerOptions:d})}if(!((null==f?void 0:f.length)<c.minSearchLength)){var b=l;if(!l.length||f!==h){var{results:E,sanitisedValue:v}=yield Y(f,i,t,o);b=E,h=v}b.length&&("mobile"===n.breakpoint&&(t({type:"TOGGLE_EXPANDED",payload:!1}),r.eventBus.emit("search:close")),q({suggestion:b[0],query:m,services:r,mapProvider:a,markers:s,showMarker:u,markerOptions:d}))}})()}};function X(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function J(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?X(Object(r),!0).forEach(function(t){s(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):X(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Q(e){var t,r,n,a,{dispatch:s,searchContainerRef:i}=e,o=(t=t=>Y(t,e.datasets,s,e.transformRequest),r=350,n=null,a=function(){for(var e=arguments.length,a=new Array(e),s=0;s<e;s++)a[s]=arguments[s];clearTimeout(n),n=setTimeout(()=>{t(...a)},r)},a.cancel=()=>{n&&(clearTimeout(n),n=null)},a),l=Z(e),u=(e=>{var{dispatch:t,debouncedFetchSuggestions:r}=e;return{handleInputClick(){t({type:"SHOW_SUGGESTIONS"})},handleInputFocus(e){t({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:"keyboard"===e})},handleInputBlur(e){t({type:"INPUT_BLUR",payload:e})},handleInputChange(e,n){var a=e.target.value;if(t({type:"SET_VALUE",payload:a}),(null==n?void 0:n.selectedIndex)>=0&&(t({type:"SET_SELECTED",payload:-1}),t({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:!0})),a.length<c.minSearchLength)return r.cancel(),t({type:"UPDATE_SUGGESTIONS",payload:{results:[],hasError:!1}}),void t({type:"HIDE_SUGGESTIONS"});t({type:"SHOW_SUGGESTIONS"}),r(a)}}})(J(J({},e),{},{debouncedFetchSuggestions:o})),d=(e=>{var{dispatch:t,services:r,mapProvider:n,markers:a,showMarker:s,markerOptions:i}=e,o=(e,t)=>{var r;return t>=0?"".concat(null===(r=e[t])||void 0===r?void 0:r.text,". ").concat(t+1," of ").concat(e.length," is highlighted"):"".concat(e.length," suggestions available")};return{handleSuggestionClick(e,o){t({type:"SET_VALUE",payload:e.text}),t({type:"HIDE_SUGGESTIONS"}),t({type:"SET_SELECTED",payload:-1}),"mobile"===o.breakpoint&&(t({type:"TOGGLE_EXPANDED",payload:!1}),r.eventBus.emit("search:close")),q({suggestion:e,query:e.text,services:r,mapProvider:n,markers:a,showMarker:s,markerOptions:i})},handleInputKeyDown(e,n){var{suggestions:a,selectedIndex:s}=n;switch(e.key){case"ArrowDown":if(null==a||!a.length)return;if(e.preventDefault(),s<a.length-1){var i=s+1;r.announce(o(a,i)),t({type:"SET_SELECTED",payload:i}),t({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:!1})}break;case"ArrowUp":if(null==a||!a.length)return;e.preventDefault();var l=s>0?s-1:-1;r.announce(o(a,l)),t({type:"SET_SELECTED",payload:l}),t({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:l<0});break;case"Escape":e.preventDefault(),t({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:!0}),t({type:"HIDE_SUGGESTIONS"}),t({type:"SET_SELECTED",payload:-1})}}}})(e);return J(J(J(J({},l),u),d),{},{handleOutside(t){i.current.contains(t.target)||(s({type:"TOGGLE_EXPANDED",payload:!1}),e.services.eventBus.emit("search:close"))}})}var ee=["marker"];function te(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}var re={reducer:{initialState:{isExpanded:!1,hasKeyboardFocusWithin:!1,value:"",suggestions:[],areSuggestionsVisible:!1,hasFetchedSuggestions:!1,hasSearchError:!1,selectedIndex:-1},actions:p},applicationModes:{[u]:{}},buttons:[{id:"search",label:"Search",iconId:"search",ariaControls:e=>{var{appConfig:t}=e;return"".concat(t.id,"-search-form")},expandedWhen:e=>{var{pluginState:t}=e;return t.isExpanded},excludeWhen:e=>{var{pluginConfig:t}=e;return Boolean(t.expanded)},keepFocus:!0,onClick:(e,t)=>{var{pluginState:r,services:n}=t;r.dispatch({type:"TOGGLE_EXPANDED",payload:!0}),n.eventBus.emit("search:open")},mobile:{slot:"top-right",showLabel:!1},tablet:{slot:"top-left",showLabel:!1},desktop:{slot:"top-left",showLabel:!1}}],controls:[{id:"search",mobile:{slot:"header"},tablet:{slot:"top-left"},desktop:{slot:"top-left"},render:function(o){var{appConfig:l,iconRegistry:c,pluginState:d,pluginConfig:h,appState:p,mapState:g,services:m,mapProvider:f,setApplicationMode:v,clearApplicationMode:w}=o,{id:S}=l,{interfaceType:O}=p,{expanded:N,customDatasets:T,osNamesURL:_,regions:x,maxSuggestions:M}=h,{dispatch:D,isExpanded:R,areSuggestionsVisible:G,suggestions:k}=d,P=c.close,j=c.search,A=t(null),C=t(null),I=p.layoutRefs.viewportRef,L=function(e){var{customDatasets:t=[],osNamesURL:r,crs:n,regions:a=["england","scotland","wales"],maxSuggestions:s}=e;return r?[{name:"osNames",urlTemplate:r,parseResults:(e,t)=>W(e,t,a,n,s),includeRegex:/[a-zA-Z0-9]/,excludeRegex:/^(?:[a-z]{2}\s*(?:\d{3}\s*\d{3}|\d{4}\s*\d{4}|\d{5}\s*\d{5})|\d+\s*,?\s*\d+)$/i},...t]:t}({customDatasets:T,osNamesURL:_,regions:x,maxSuggestions:M,crs:f.crs}),$=t(null);if(!$.current){var{marker:F}=h,U=i(h,ee);$.current=Q(function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?te(Object(r),!0).forEach(function(t){s(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):te(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}({dispatch:D,datasets:L,services:m,mapProvider:f,searchContainerRef:A,markers:g.markers,markerOptions:F},U))}var B=$.current,z=R||!!(N&&G&&k.length);return e(()=>{var e;R&&(null===(e=C.current)||void 0===e||e.focus())},[R]),r(()=>{if(R)return v(u),()=>w(u)},[R]),r(()=>{if(z)return I.current.style.pointerEvents="none",document.addEventListener("focusin",B.handleOutside),document.addEventListener("pointerdown",B.handleOutside),()=>{I.current.style.pointerEvents="auto",document.removeEventListener("focusin",B.handleOutside),document.removeEventListener("pointerdown",B.handleOutside)}},[R,O,G,k]),n("div",{className:"im-c-search".concat(N||R?"":" im-c-search--collapsed"),ref:A,onKeyDown:e=>B.handleTabOut(e,p.buttonRefs),children:a(y,{id:S,pluginState:d,pluginConfig:h,appState:p,inputRef:C,events:B,services:m,children:[n(b,{defaultExpanded:N,onClick:e=>B.handleCloseClick(e,p),closeIcon:P}),n(E,{defaultExpanded:N,submitIcon:j})]})})}}],icons:[{id:"search",svgContent:'<path d="m21 21-4.34-4.34"></path><circle cx="11" cy="11" r="8"></circle>'}]},ne=Object.freeze({__proto__:null,manifest:re});export{c as D,ne as m};