@defra/interactive-map 0.0.17-alpha → 0.0.19-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.
- package/assets/css/docusaurus.css +58 -34
- package/dist/css/index.css +1 -1
- package/dist/esm/im-core.js +1 -1
- package/dist/esm/im-shell.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api/context.md +53 -7
- package/docs/api/map-style-config.md +41 -2
- package/docs/api/marker-config.md +53 -11
- package/docs/api/panel-definition.md +16 -0
- package/docs/api/symbol-config.md +160 -0
- package/docs/api/symbol-registry.md +115 -0
- package/docs/api.md +50 -23
- package/docs/assets/basic-map.jpg +0 -0
- package/docs/assets/button-first.jpg +0 -0
- package/docs/assets/maker-panel.jpg +0 -0
- package/docs/examples/add-marker-with-panel.mdx +59 -0
- package/docs/examples/basic-map.mdx +24 -0
- package/docs/examples/button-map.mdx +24 -0
- package/docs/examples/index.mdx +49 -0
- package/docs/index.mdx +1 -1
- package/docs/plugins/datasets.md +105 -9
- package/docs/plugins/interact.md +100 -44
- package/docs/plugins/search.md +15 -3
- package/docs/plugins.md +1 -1
- package/docusaurus.config.cjs +9 -1
- package/package.json +1 -1
- package/plugins/beta/datasets/dist/css/index.css +32 -14
- package/plugins/beta/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/beta/datasets/dist/esm/index.js +1 -1
- package/plugins/beta/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/beta/datasets/dist/umd/index.js +1 -1
- package/plugins/beta/datasets/src/DatasetsInit.jsx +9 -4
- package/plugins/beta/datasets/src/adapters/maplibre/layerBuilders.js +57 -11
- package/plugins/beta/datasets/src/adapters/maplibre/layerIds.js +14 -8
- package/plugins/beta/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +155 -53
- package/plugins/beta/datasets/src/adapters/maplibre/patternImages.js +27 -0
- package/plugins/beta/datasets/src/adapters/maplibre/symbolImages.js +31 -0
- package/plugins/beta/datasets/src/api/addDataset.js +1 -1
- package/plugins/beta/datasets/src/api/setData.js +4 -2
- package/plugins/beta/datasets/src/api/setStyle.js +2 -2
- package/plugins/beta/datasets/src/components/EmptyKey.jsx +7 -0
- package/plugins/beta/datasets/src/components/EmptyKey.test.jsx +21 -0
- package/plugins/beta/datasets/src/components/KeySvg.jsx +24 -0
- package/plugins/beta/datasets/src/components/KeySvgLine.jsx +19 -0
- package/plugins/beta/datasets/src/components/KeySvgPattern.jsx +15 -0
- package/plugins/beta/datasets/src/components/KeySvgRect.jsx +22 -0
- package/plugins/beta/datasets/src/components/KeySvgSymbol.jsx +16 -0
- package/plugins/beta/datasets/src/components/svgProperties.js +20 -0
- package/plugins/beta/datasets/src/datasets.js +13 -4
- package/plugins/beta/datasets/src/defaults.js +4 -2
- package/plugins/beta/datasets/src/index.js +2 -1
- package/plugins/beta/datasets/src/manifest.js +1 -1
- package/plugins/beta/datasets/src/panels/Key.jsx +11 -89
- package/plugins/beta/datasets/src/panels/Key.module.scss +24 -13
- package/plugins/beta/datasets/src/panels/Layers.module.scss +13 -7
- package/plugins/beta/datasets/src/reducer.js +6 -0
- package/plugins/beta/datasets/src/reducers/keyReducer.js +34 -0
- package/plugins/beta/datasets/src/utils/mergeSublayer.js +8 -0
- package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
- package/plugins/beta/draw-es/src/DrawInit.jsx +3 -2
- package/plugins/beta/draw-ml/dist/css/index.css +3 -0
- package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/index.js +1 -1
- package/plugins/beta/draw-ml/src/DrawInit.jsx +4 -3
- package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/umd/index.js +1 -1
- package/plugins/beta/map-styles/src/MapStyles.jsx +5 -4
- package/plugins/beta/map-styles/src/MapStylesInit.jsx +5 -4
- package/plugins/beta/scale-bar/dist/css/index.css +1 -1
- package/plugins/beta/scale-bar/src/scaleBar.scss +1 -0
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/index.js +1 -1
- package/plugins/interact/src/InteractInit.jsx +19 -8
- package/plugins/interact/src/InteractInit.test.js +26 -6
- package/plugins/interact/src/api/clear.js +1 -1
- package/plugins/interact/src/api/enable.test.js +7 -7
- package/plugins/interact/src/api/selectMarker.js +14 -0
- package/plugins/interact/src/api/selectMarker.test.js +25 -0
- package/plugins/interact/src/api/unselectMarker.js +14 -0
- package/plugins/interact/src/api/unselectMarker.test.js +14 -0
- package/plugins/interact/src/defaults.js +4 -6
- package/plugins/interact/src/events.js +27 -36
- package/plugins/interact/src/events.test.js +119 -90
- package/plugins/interact/src/hooks/useHighlightSync.js +3 -3
- package/plugins/interact/src/hooks/useHighlightSync.test.js +6 -6
- package/plugins/interact/src/hooks/useHoverCursor.js +10 -0
- package/plugins/interact/src/hooks/useHoverCursor.test.js +44 -0
- package/plugins/interact/src/hooks/useInteractionHandlers.js +111 -69
- package/plugins/interact/src/hooks/useInteractionHandlers.test.js +147 -32
- package/plugins/interact/src/manifest.js +10 -2
- package/plugins/interact/src/reducer.js +59 -5
- package/plugins/interact/src/reducer.test.js +100 -12
- package/plugins/interact/src/utils/buildStylesMap.js +17 -4
- package/plugins/interact/src/utils/buildStylesMap.test.js +16 -2
- package/plugins/interact/src/utils/featureQueries.js +11 -6
- package/plugins/interact/src/utils/featureQueries.test.js +8 -1
- package/plugins/interact/src/utils/interactionModes.js +12 -0
- package/plugins/search/dist/esm/im-search-plugin.js +1 -1
- package/plugins/search/dist/umd/im-search-plugin.js +1 -1
- package/plugins/search/src/Search.jsx +3 -1
- package/plugins/search/src/events/fetchSuggestions.js +6 -4
- package/plugins/search/src/events/fetchSuggestions.test.js +26 -4
- package/plugins/search/src/events/formHandlers.js +3 -3
- package/plugins/search/src/events/formHandlers.test.js +1 -1
- package/plugins/search/src/events/suggestionHandlers.js +2 -2
- package/plugins/search/src/events/suggestionHandlers.test.js +1 -1
- package/plugins/search/src/utils/updateMap.js +3 -3
- package/plugins/search/src/utils/updateMap.test.js +3 -3
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/appEvents.js +7 -0
- package/providers/maplibre/src/appEvents.test.js +18 -4
- package/providers/maplibre/src/maplibreProvider.js +52 -0
- package/providers/maplibre/src/maplibreProvider.test.js +105 -1
- package/providers/maplibre/src/utils/highlightFeatures.js +36 -7
- package/providers/maplibre/src/utils/highlightFeatures.test.js +153 -96
- package/providers/maplibre/src/utils/hoverCursor.js +61 -0
- package/providers/maplibre/src/utils/hoverCursor.test.js +130 -0
- package/providers/maplibre/src/utils/patternImages.js +70 -0
- package/providers/maplibre/src/utils/patternImages.test.js +180 -0
- package/providers/maplibre/src/utils/queryFeatures.js +38 -16
- package/providers/maplibre/src/utils/queryFeatures.test.js +20 -3
- package/providers/maplibre/src/utils/rasteriseToImageData.js +30 -0
- package/providers/maplibre/src/utils/rasteriseToImageData.test.js +69 -0
- package/providers/maplibre/src/utils/symbolImages.js +147 -0
- package/providers/maplibre/src/utils/symbolImages.test.js +248 -0
- package/src/App/components/Markers/Markers.jsx +122 -27
- package/src/App/components/Markers/Markers.module.scss +0 -10
- package/src/App/components/Markers/Markers.test.jsx +246 -0
- package/src/App/components/Panel/Panel.jsx +6 -6
- package/src/App/components/Panel/Panel.test.jsx +37 -0
- package/src/App/components/Viewport/Viewport.jsx +5 -15
- package/src/App/components/Viewport/Viewport.module.scss +2 -0
- package/src/App/components/Viewport/Viewport.test.jsx +16 -33
- package/src/App/hooks/useInterfaceAPI.js +7 -7
- package/src/App/hooks/useInterfaceAPI.test.js +162 -0
- package/src/App/hooks/useLayoutMeasurements.js +64 -72
- package/src/App/hooks/useMarkersAPI.js +2 -5
- package/src/App/hooks/useMarkersAPI.test.js +4 -4
- package/src/App/layout/Layout.jsx +3 -3
- package/src/App/layout/Layout.test.jsx +4 -2
- package/src/App/layout/layout.module.scss +1 -8
- package/src/App/renderer/HtmlElementHost.jsx +10 -5
- package/src/App/renderer/mapPanels.js +2 -1
- package/src/App/store/ServiceProvider.jsx +7 -5
- package/src/App/store/appActionsMap.js +4 -4
- package/src/App/store/appActionsMap.test.js +10 -0
- package/src/App/store/mapActionsMap.js +4 -6
- package/src/App/store/mapActionsMap.test.js +3 -2
- package/src/App/store/mapReducer.js +2 -1
- package/src/InteractiveMap/InteractiveMap.js +59 -11
- package/src/InteractiveMap/InteractiveMap.test.js +126 -4
- package/src/InteractiveMap/domStateManager.js +18 -6
- package/src/InteractiveMap/domStateManager.test.js +21 -0
- package/src/InteractiveMap/historyManager.js +28 -16
- package/src/InteractiveMap/historyManager.test.js +17 -0
- package/src/config/appConfig.js +2 -7
- package/src/config/appConfig.test.js +4 -15
- package/src/config/defaults.js +2 -3
- package/src/config/events.js +20 -21
- package/src/config/mapTheme.js +56 -0
- package/src/config/patternConfig.js +16 -0
- package/src/config/symbolConfig.js +80 -0
- package/src/scss/settings/_colors.scss +0 -9
- package/src/services/closeApp.js +1 -10
- package/src/services/closeApp.test.js +3 -43
- package/src/services/patternRegistry.js +40 -0
- package/src/services/patternRegistry.test.js +48 -0
- package/src/services/symbolRegistry.js +113 -0
- package/src/services/symbolRegistry.test.js +262 -0
- package/src/types.js +99 -12
- package/src/utils/mapStateSync.js +48 -10
- package/src/utils/mapStateSync.test.js +29 -9
- package/src/utils/patternUtils.js +94 -0
- package/src/utils/patternUtils.test.js +160 -0
- package/src/utils/symbolUtils.js +85 -0
- package/src/utils/symbolUtils.test.js +156 -0
- package/docs/examples.mdx +0 -70
- package/plugins/beta/datasets/src/adapters/maplibre/patternRegistry.js +0 -48
- package/plugins/beta/datasets/src/styles/patterns.js +0 -157
|
@@ -38,7 +38,7 @@ describe('getFeaturesAtPoint', () => {
|
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
describe('findMatchingFeature', () => {
|
|
41
|
-
const layerConfigMap = { layer1: { layerId: 'layer1' } }
|
|
41
|
+
const layerConfigMap = { layer1: { layerId: 'layer1' }, layer2: { layerId: 'layer2' } }
|
|
42
42
|
|
|
43
43
|
it('returns first feature matching config, null otherwise', () => {
|
|
44
44
|
const features = [
|
|
@@ -53,4 +53,11 @@ describe('findMatchingFeature', () => {
|
|
|
53
53
|
expect(findMatchingFeature([{ id: 'f4' }], layerConfigMap)).toBeNull()
|
|
54
54
|
expect(findMatchingFeature([{ id: 'f5', layer: { id: 'other' } }], {})).toBeNull()
|
|
55
55
|
})
|
|
56
|
+
|
|
57
|
+
it('prioritises point geometry over non-point when both match', () => {
|
|
58
|
+
const polygon = { id: 'p1', layer: { id: 'layer1' }, geometry: { type: 'Polygon' } }
|
|
59
|
+
const point = { id: 'p2', layer: { id: 'layer2' }, geometry: { type: 'Point' } }
|
|
60
|
+
const result = findMatchingFeature([polygon, point], layerConfigMap)
|
|
61
|
+
expect(result).toEqual({ feature: point, config: layerConfigMap.layer2 })
|
|
62
|
+
})
|
|
56
63
|
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true when selectMarker is the only active interaction mode.
|
|
3
|
+
*
|
|
4
|
+
* Used to suppress the crosshair and Select action button for touch users —
|
|
5
|
+
* markers have a sufficient tap target so neither is needed. Any other mode
|
|
6
|
+
* combination (e.g. placeMarker, selectFeature) requires the crosshair for touch.
|
|
7
|
+
*
|
|
8
|
+
* @param {string[] | null} interactionModes
|
|
9
|
+
* @returns {boolean}
|
|
10
|
+
*/
|
|
11
|
+
export const isSelectMarkerOnly = (interactionModes) =>
|
|
12
|
+
interactionModes?.length === 1 && interactionModes.includes('selectMarker')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useEffect as e,useRef as t}from"preact/compat";import{jsxs as r,jsx as n}from"preact/jsx-runtime";import a from"@babel/runtime/helpers/defineProperty";import i from"@babel/runtime/helpers/taggedTemplateLiteral";import o from"@babel/runtime/helpers/asyncToGenerator";function s(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 l(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?s(Object(r),!0).forEach(function(t){a(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var c={TOGGLE_EXPANDED:(e,t)=>l(l({},e),{},{isExpanded:t,areSuggestionsVisible:t,hasFetchedSuggestions:!1}),SET_KEYBOARD_FOCUS_WITHIN:(e,t)=>l(l({},e),{},{hasKeyboardFocusWithin:t,areSuggestionsVisible:!0}),INPUT_BLUR:(e,t)=>l(l({},e),{},{hasKeyboardFocusWithin:!1,areSuggestionsVisible:e.areSuggestionsVisible&&"keyboard"!==t,selectedIndex:-1}),SET_VALUE:(e,t)=>l(l({},e),{},{value:t}),UPDATE_SUGGESTIONS:(e,t)=>l(l({},e),{},{suggestions:t,hasFetchedSuggestions:!0}),SHOW_SUGGESTIONS:e=>l(l({},e),{},{areSuggestionsVisible:!0,hasFetchedSuggestions:!1}),HIDE_SUGGESTIONS:e=>l(l({},e),{},{areSuggestionsVisible:!1,hasFetchedSuggestions:!1}),SET_SELECTED:(e,t)=>l(l({},e),{},{selectedIndex:t,areSuggestionsVisible:t>=0})},u=e=>{var{id:t,isExpanded:a,onClick:i,buttonRef:o,searchIcon:s,showLabel:l}=e;return r("button",{"aria-label":"Open search",className:"im-c-map-button",onClick:i,"aria-controls":"".concat(t,"-search-form"),ref:o,style:a?{display:"none"}:void 0,children:[s&&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:s}}),l&&n("span",{children:"Search"})]})},d=e=>{var{id:t,pluginState:r,handleSuggestionClick:a}=e;return n("ul",{id:"".concat(t,"-search-suggestions"),role:"listbox","aria-labelledby":"".concat(t,"-search"),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}})},e.id))})};function h(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 p=(e,t,r)=>function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?h(Object(r),!0).forEach(function(t){a(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):h(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}),g=t=>{var{id:a,pluginState:i,pluginConfig:o,appState:s,inputRef:l,events:c,services:u,children:h}=t,{areSuggestionsVisible:g,hasFetchedSuggestions:f,suggestions:m=[]}=i;e(()=>{g&&f&&u.announce((e=>{if(0===e)return"No results available";var t=1===e?"result":"results";return"".concat(e," ").concat(t," available")})(m.length))},[m,f]);var y=["im-c-search-form",o.expanded&&"im-c-search-form--default-expanded","im-c-panel"].filter(Boolean).join(" "),b=g&&f&&!m.length;return r("form",{id:"".concat(a,"-search-form"),role:"search",className:y,style:p(o,i,s),"aria-controls":"".concat(a,"-viewport"),onSubmit:e=>c.handleSubmit(e,s,i),children:[n("button",{type:"submit",style:{display:"none"},"aria-hidden":"true",tabIndex:-1,children:"Submit"}),r("div",{className:"im-c-search__input-container".concat(i.hasKeyboardFocusWithin?" im-c-search__input-container--keyboard-focus-within":""),children:[n("label",{htmlFor:"".concat(a,"-search"),className:"im-u-visually-hidden",children:o.placeholder}),n("input",{id:"".concat(a,"-search"),className:"im-c-search__input",type:"search",role:"combobox","aria-expanded":i.suggestionsVisible,"aria-controls":"".concat(a,"-search-suggestions"),"aria-activedescendant":i.selectedIndex>=0?"".concat(a,"-search-suggestion-").concat(i.selectedIndex):void 0,"aria-describedby":i.value?void 0:"".concat(a,"-search-hint"),"aria-autocomplete":"list",autoComplete:"off",placeholder:o.placeholder,name:"".concat(a,"-search"),spellCheck:!1,enterKeyHint:"search",value:i.value,onClick:c.handleInputClick,onChange:c.handleInputChange,onFocus:()=>c.handleInputFocus(s.interfaceType),onBlur:()=>c.handleInputBlur(s.interfaceType),onKeyDown:e=>c.handleInputKeyDown(e,i),ref:l}),n("span",{id:"".concat(a,"-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."}),h]}),b&&n("div",{className:"im-c-search__status","aria-hidden":"true",children:"No results available"}),n(d,{id:a,appState:s,pluginState:i,handleSuggestionClick:e=>c.handleSuggestionClick(e,s)})]})},f=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}})})},m=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 y=" ";class b{static get separator(){return y}static set separator(e){y=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,o=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+"°"+b.separator+i+"′";break;case"dms":case"deg+min+sec":a=Math.floor(e),i=Math.floor(3600*e/60)%60,o=(3600*e%60).toFixed(r),60==o&&(o=(0).toFixed(r),i++),60==i&&(i=0,a++),a=("000"+a).slice(-3),i=("00"+i).slice(-2),o<10&&(o="0"+o),n=a+"°"+b.separator+i+"′"+b.separator+o+"″"}return n}static toLat(e,t,r){const n=b.toDms(b.wrap90(e),t,r);return null===n?"–":n.slice(1)+b.separator+(e<0?"S":"N")}static toLon(e,t,r){const n=b.toDms(b.wrap180(e),t,r);return null===n?"–":n+b.separator+(e<0?"W":"E")}static toBrng(e,t,r){const n=b.toDms(b.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=b.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 w{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 w))throw new TypeError("v is not Vector3d object");return new w(this.x+e.x,this.y+e.y,this.z+e.z)}minus(e){if(!(e instanceof w))throw new TypeError("v is not Vector3d object");return new w(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 w(this.x*e,this.y*e,this.z*e)}dividedBy(e){if(isNaN(e))throw new TypeError(`invalid scalar value ‘${e}’`);return new w(this.x/e,this.y/e,this.z/e)}dot(e){if(!(e instanceof w))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 w))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 w(t,r,n)}negate(){return new w(-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 w(t,r,n)}angleTo(e,t=void 0){if(!(e instanceof w))throw new TypeError("v is not Vector3d object");if(!(t instanceof w||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 w))throw new TypeError("axis is not Vector3d object");const r=t.toRadians(),n=this.unit(),a=e.unit(),i=Math.sin(r),o=Math.cos(r),s=1-o,l=a.x,c=a.y,u=a.z,d=[[s*l*l+o,s*l*c-i*u,s*l*u+i*c],[s*l*c+i*u,s*c*c+o,s*c*u-i*l],[s*l*u-i*c,s*c*u+i*l,s*u*u+o]],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 w(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 E={WGS84:{a:6378137,b:6356752.314245,f:1/298.257223563}},v={WGS84:{ellipsoid:E.WGS84}};Object.freeze(E.WGS84),Object.freeze(v.WGS84);class S{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=b.wrap90(Number(e)),this._lon=b.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)?b.wrap90(b.parse(e)):b.wrap90(Number(e)),isNaN(this._lat))throw new TypeError(`invalid lat ‘${e}’`)}set latitude(e){if(this._lat=isNaN(e)?b.wrap90(b.parse(e)):b.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)?b.wrap180(b.parse(e)):b.wrap180(Number(e)),isNaN(this._lon))throw new TypeError(`invalid lon ‘${e}’`)}set lng(e){if(this._lon=isNaN(e)?b.wrap180(b.parse(e)):b.wrap180(Number(e)),isNaN(this._lon))throw new TypeError(`invalid lng ‘${e}’`)}set longitude(e){if(this._lon=isNaN(e)?b.wrap180(b.parse(e)):b.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 E}static get datums(){return v}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=b.wrap90(b.parse(t)),r=b.wrap180(b.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=b.wrap90(b.parse(t)),r=b.wrap180(b.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=b.wrap90(b.parse(t)),r=b.wrap180(b.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:E.WGS84,t=this.lat.toRadians(),r=this.lon.toRadians(),n=this.height,{a:a,f:i}=e,o=Math.sin(t),s=Math.cos(t),l=Math.sin(r),c=Math.cos(r),u=2*i-i*i,d=a/Math.sqrt(1-u*o*o);return new O((d+n)*s*c,(d+n)*s*l,(d*(1-u)+n)*o)}equals(e){if(!(e instanceof S))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`${b.toLat(this.lat,e,t)}, ${b.toLon(this.lon,e,t)}${null==r?"":n}`}}class O extends w{constructor(e,t,r){super(e,t,r)}toLatLon(e=E.WGS84){if(!e||!e.a)throw new TypeError(`invalid ellipsoid ‘${e}’`);const{x:t,y:r,z:n}=this,{a:a,b:i,f:o}=e,s=2*o-o*o,l=s/(1-s),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-s*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-s*f*f));return new S(p.toDegrees(),g.toDegrees(),m)}toString(e=0){return`[${this.x.toFixed(e)},${this.y.toFixed(e)},${this.z.toFixed(e)}]`}}const N={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}},T={ED50:{ellipsoid:N.Intl1924,transform:[89.5,93.8,123.1,-1.2,0,0,.156]},ETRS89:{ellipsoid:N.GRS80,transform:[0,0,0,0,0,0,0]},Irl1975:{ellipsoid:N.AiryModified,transform:[-482.53,130.596,-564.557,-8.15,1.042,.214,.631]},NAD27:{ellipsoid:N.Clarke1866,transform:[8,-160,-176,0,0,0,0]},NAD83:{ellipsoid:N.GRS80,transform:[.9956,-1.9103,-.5215,-62e-5,.025915,.009426,.011599]},NTF:{ellipsoid:N.Clarke1880IGN,transform:[168,60,-320,0,0,0,0]},OSGB36:{ellipsoid:N.Airy1830,transform:[-446.448,125.157,-542.06,20.4894,-.1502,-.247,-.8421]},Potsdam:{ellipsoid:N.Bessel1841,transform:[-582,-105,-414,-8.3,1.04,.35,-3.08]},TokyoJapan:{ellipsoid:N.Bessel1841,transform:[148,-507,-685,0,0,0,0]},WGS72:{ellipsoid:N.WGS72,transform:[0,0,-4.5,-.22,0,0,.554]},WGS84:{ellipsoid:N.WGS84,transform:[0,0,0,0,0,0,0]}};Object.keys(N).forEach(e=>Object.freeze(N[e])),Object.keys(T).forEach(e=>{Object.freeze(T[e]),Object.freeze(T[e].transform)});class _ extends S{constructor(e,t,r=0,n=T.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 N}static get datums(){return T}static parse(...e){let t=T.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 x(e.x,e.y,e.z,this.datum)}}class x extends O{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||T.WGS84;if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);const r=super.toLatLon(t.ellipsoid);return new _(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!=T.WGS84||(t=this,r=e.transform),e==T.WGS84&&(t=this,r=this.datum.transform.map(e=>-e)),null==r&&(t=this.convertDatum(T.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],o=e[2],s=e[3]/1e6+1,l=(e[4]/3600).toRadians(),c=(e[5]/3600).toRadians(),u=(e[6]/3600).toRadians();return new x(a+t*s-r*u+n*c,i+t*u+r*s-n*l,o-t*c+r*l+n*s)}}const D={trueOrigin:{lat:49,lon:-2},scaleFactor:.9996012717,ellipsoid:_.ellipsoids.Airy1830};class j{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=_.datums.WGS84){const{easting:t,northing:r}=this,{a:n,b:a}=D.ellipsoid,i=D.trueOrigin.lat.toRadians(),o=D.trueOrigin.lon.toRadians(),s=-1e5,l=D.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-s-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-s-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),w=y/b-1,E=Math.tan(p),v=E*E,S=v*v,O=1/f,N=y*y*y,T=N*y*y,x=t-4e5,j=x*x,G=j*x,C=j*j,P=G*j;p=p-E/(2*b*y)*j+E/(24*b*N)*(5+3*v+w-9*v*w)*C-E/(720*b*T)*(61+90*v+45*S)*(C*j);const R=o+O/y*x-O/(6*N)*(y/b+2*v)*G+O/(120*T)*(5+28*v+24*S)*P-O/(5040*(T*y*y))*(61+662*v+1320*S+720*(S*v))*(P*j);let k=new M(p.toDegrees(),R.toDegrees(),0,_.datums.OSGB36);return e!=_.datums.OSGB36&&(k=k.convertDatum(e),k=new M(k.lat,k.lon,k.height,k.datum)),k}static parse(e){let t=(e=String(e).trim()).match(/^(\d+),\s*(\d+)$/);if(t)return new j(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 o=e.slice(2).trim().split(/\s+/);if(1==o.length&&(o=[o[0].slice(0,o[0].length/2),o[0].slice(o[0].length/2)]),o[0].length!=o[1].length)throw new Error(`invalid grid reference ‘${e}’`);o[0]=o[0].padEnd(5,"0"),o[1]=o[1].padEnd(5,"0");const s=a+o[0],l=i+o[1];return new j(s,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),o=5*(19-a)%25+n%5;i>7&&i++,o>7&&o++;const s=String.fromCharCode(i+"A".charCodeAt(0),o+"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"),`${s} ${t} ${r}`}}class M extends _{toOsGrid(){const e=this.datum==_.datums.OSGB36?this:this.convertDatum(_.datums.OSGB36),t=e.lat.toRadians(),r=e.lon.toRadians(),{a:n,b:a}=D.ellipsoid,i=D.trueOrigin.lat.toRadians(),o=D.trueOrigin.lon.toRadians(),s=D.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*s/Math.sqrt(1-l*p*p),f=n*s*(1-l)/Math.pow(1-l*p*p,1.5),m=g/f-1,y=a*s*((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,w=b*h*h,E=Math.tan(t)*Math.tan(t),v=E*E,S=r-o,O=S*S,N=O*S,T=N*S,x=T*S;let M=y+-1e5+g/2*p*h*O+g/24*p*b*(5-E+9*m)*T+g/720*p*w*(61-58*E+v)*(x*S),G=4e5+g*h*S+g/6*b*(g/f-E)*N+g/120*w*(5-18*E+v+14*m-58*E*m)*x;M=Number(M.toFixed(3)),G=Number(G.toFixed(3));try{return new j(G,M)}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 M(t.lat,t.lon,t.height,t.datum)}}var G;function C(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 P(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?C(Object(r),!0).forEach(function(t){a(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):C(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var R=500,k=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},L=(e,t)=>{var r,n,a,i,{MBR_XMIN:o,MBR_YMIN:s,MBR_XMAX:l,MBR_YMAX:c,GEOMETRY_X:u,GEOMETRY_Y:d}=t;if(null==o?(r=u-R,n=d-R,a=u+R,i=d+R):(r=o,n=s,a=l,i=c),"EPSG:27700"===e)return[r,n,a,i];if("EPSG:4326"===e){var h=new j(r,n).toLatLon(),p=new j(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))},I=(e,t)=>{var{GEOMETRY_X:r,GEOMETRY_Y:n}=t;if("EPSG:27700"===e)return[r,n];if("EPSG:4326"===e){var a=new j(r,n).toLatLon();return[Math.round(1e6*a.lon)/1e6,Math.round(1e6*a.lat)/1e6]}throw new Error("Unsupported CRS: ".concat(e))},A=(e,t,r,n)=>{var a;if(!e||e.error||0===(null===(a=e.header)||void 0===a?void 0:a.totalresults))return[];var o=e.results;return o=((e,t)=>{var r=t.toLowerCase().replace(/,/g,"").split(" ");return e.map(k).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}))})(o,t),o=((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)}))(o=(e=>Array.from(new Map(e.map(e=>[e.GAZETTEER_ENTRY.ID,e])).values()))(o),r),(o=o.slice(0,8)).map(e=>P(P({id:e.GAZETTEER_ENTRY.ID,bounds:L(n,e.GAZETTEER_ENTRY),point:I(n,e.GAZETTEER_ENTRY)},((e,t)=>{var r,n,a,o,{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(G||(G=i(["s*"],["\\s*"])))),o=new RegExp("(".concat(a,")"),"i"),r.replace(o,"<mark>$1</mark>"))}})(t,e.GAZETTEER_ENTRY)),{},{type:"os-names"}))};var $=function(){var e=o(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"}};return e.buildRequest?e.buildRequest(t,()=>a):r?yield r(a,t):a});return function(t,r,n){return e.apply(this,arguments)}}(),F=function(){var e=o(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)),null;var a=yield n.json();return e.parseResults(a,r)}catch(t){return console.error("Network error for ".concat(e.label||"dataset",":"),t),null}});return function(t,r,n){return e.apply(this,arguments)}}(),W=function(){var e=o(function*(e,t,r,n){var a=(e=>e.replace(/[^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}),o=[];for(var s of i){var l=yield $(s,a,n),c=yield F(s,l,a);if(null!=c&&c.length&&(o=[...o,...c],s.exclusive))break}return r({type:"UPDATE_SUGGESTIONS",payload:o}),{results:o,sanitisedValue:a}});return function(t,r,n,a){return e.apply(this,arguments)}}();function U(e){var{mapProvider:t,bounds:r,point:n,markers:a,showMarker:i,markerColor:o}=e;t.fitToBounds(r),i&&a.add("search",n,{color:o})}var B=3;function z(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 V(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?z(Object(r),!0).forEach(function(t){a(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):z(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Y(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 H=e=>{var{dispatch:t,services:r,mapProvider:n,markers:i,showMarker:o,markerColor:s}=e,l=(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,l){t({type:"SET_VALUE",payload:e.text}),t({type:"HIDE_SUGGESTIONS"}),t({type:"SET_SELECTED",payload:-1}),"mobile"===l.breakpoint&&(t({type:"TOGGLE_EXPANDED",payload:!1}),r.eventBus.emit("search:close")),U({mapProvider:n,bounds:e.bounds,point:e.point,markers:i,showMarker:o,markerColor:s}),r.eventBus.emit("search:match",function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Y(Object(r),!0).forEach(function(t){a(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Y(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 o=i+1;r.announce(l(a,o)),t({type:"SET_SELECTED",payload:o}),t({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:!1})}break;case"ArrowUp":if(null==a||!a.length)return;e.preventDefault();var s=i>0?i-1:-1;r.announce(l(a,s)),t({type:"SET_SELECTED",payload:s}),t({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:s<0});break;case"Escape":e.preventDefault(),t({type:"HIDE_SUGGESTIONS"}),t({type:"SET_SELECTED",payload:-1})}}}};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 Z(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){a(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}function K(e){var t,r,n,a,{dispatch:i,searchContainerRef:s}=e,l=(t=t=>W(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),c=(e=>{var{dispatch:t,services:r,viewportRef:n,mapProvider:a,markers:i,datasets:s,transformRequest:l,showMarker:c,markerColor:u}=e,d="";return{handleOpenClick(){t({type:"TOGGLE_EXPANDED",payload:!0}),r.eventBus.emit("search:open")},handleCloseClick(e,n){t({type:"TOGGLE_EXPANDED",payload:!1}),t({type:"UPDATE_SUGGESTIONS",payload:[]}),t({type:"SET_VALUE",payload:""}),setTimeout(()=>n.current.focus(),0),i.remove("search"),r.eventBus.emit("search:clear"),r.eventBus.emit("search:close")},handleSubmit:(e,h,p)=>o(function*(){e.preventDefault();var{suggestions:o,selectedIndex:g,value:f}=p,m=null==f?void 0:f.trim();if(t({type:"SET_SELECTED",payload:-1}),t({type:"HIDE_SUGGESTIONS"}),g>=0){var y,b=o[g];return t({type:"SET_VALUE",payload:b.text}),null===(y=n.current)||void 0===y||y.focus(),U({mapProvider:a,bounds:b.bounds,point:b.point,markers:i,showMarker:c,markerColor:u}),void r.eventBus.emit("search:match",V({query:b.text},b))}if(!((null==m?void 0:m.length)<B)){var w=o;if(!o.length||m!==d){var{results:E,sanitisedValue:v}=yield W(m,s,t,l);w=E,d=v}if(w.length){var S;"keyboard"===h.interfaceType&&(null===(S=n.current)||void 0===S||S.focus()),"mobile"===h.breakpoint&&(t({type:"TOGGLE_EXPANDED",payload:!1}),r.eventBus.emit("search:close"));var O=w[0];U({mapProvider:a,bounds:O.bounds,point:O.point,markers:i,showMarker:c,markerColor:u}),r.eventBus.emit("search:match",V({query:f},O))}}})()}})(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<B)return r.cancel(),t({type:"UPDATE_SUGGESTIONS",payload:[]}),void t({type:"HIDE_SUGGESTIONS"});t({type:"SHOW_SUGGESTIONS"}),r(n)}}})(Z(Z({},e),{},{debouncedFetchSuggestions:l})),d=H(e);return Z(Z(Z(Z({},c),u),d),{},{handleOutside(t){s.current.contains(t.target)||(i({type:"TOGGLE_EXPANDED",payload:!1}),e.services.eventBus.emit("search:close"))}})}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}var J={reducer:{initialState:{isExpanded:!1,hasKeyboardFocusWithin:!1,value:"",suggestions:[],areSuggestionsVisible:!1,hasFetchedSuggestions:!1,selectedIndex:-1},actions:c},controls:[{id:"search",mobile:{slot:"top-right",showLabel:!1},tablet:{slot:"top-left",showLabel:!1},desktop:{slot:"top-left",showLabel:!1},render:function(i){var o,{appConfig:s,iconRegistry:l,pluginState:c,pluginConfig:d,appState:h,mapState:p,services:y,mapProvider:b}=i,{id:w}=s,{interfaceType:E}=h,{expanded:v,customDatasets:S,osNamesURL:O,regions:N}=d,{dispatch:T,isExpanded:_,areSuggestionsVisible:x,suggestions:D}=c,j=(null==h||null===(o=h.controlConfig)||void 0===o||null===(o=o.search)||void 0===o?void 0:o[null==h?void 0:h.breakpoint].showLabel)||!1,M=l.close,G=l.search,C=t(null),P=t(null),R=t(null),k=h.layoutRefs.viewportRef,L=function(e){var{customDatasets:t=[],osNamesURL:r,crs:n,regions:a=["england","scotland","wales"]}=e;return r?[{name:"osNames",urlTemplate:r,parseResults:(e,t)=>A(e,t,a,n),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:S,osNamesURL:O,regions:N,crs:b.crs}),I=t(null);I.current||(I.current=K(function(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){a(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}({dispatch:T,datasets:L,services:y,mapProvider:b,viewportRef:k,searchContainerRef:C,markers:p.markers},d)));var $=I.current,F=_||!!(v&&x&&D.length);return e(()=>{var e;_&&(null===(e=R.current)||void 0===e||e.focus())},[_]),e(()=>{if(h.dispatch({type:"TOGGLE_HAS_EXCLUSIVE_CONTROL",payload:_}),F)return k.current.style.pointerEvents="none",document.addEventListener("focusin",$.handleOutside),document.addEventListener("pointerdown",$.handleOutside),()=>{k.current.style.pointerEvents="auto",document.removeEventListener("focusin",$.handleOutside),document.removeEventListener("pointerdown",$.handleOutside)}},[_,E,x,D]),r("div",{className:"im-c-search",ref:C,children:[!v&&n(u,{id:w,isExpanded:_,onClick:()=>$.handleOpenClick(h),buttonRef:P,searchIcon:G,showLabel:j}),r(g,{id:w,pluginState:c,pluginConfig:d,appState:h,inputRef:R,events:$,services:y,children:[n(f,{defaultExpanded:v,onClick:e=>$.handleCloseClick(e,P,h),closeIcon:M}),n(m,{defaultExpanded:v,onClick:e=>$.handleCloseClick(e,P,h),submitIcon:G})]})]})}}],icons:[{id:"search",svgContent:'<path d="m21 21-4.34-4.34"></path><circle cx="11" cy="11" r="8"></circle>'}]};export{J as manifest};
|
|
1
|
+
import{useEffect as e,useRef as t}from"preact/compat";import{jsxs as r,jsx as n}from"preact/jsx-runtime";import a from"@babel/runtime/helpers/defineProperty";import i from"@babel/runtime/helpers/objectWithoutProperties";import o from"@babel/runtime/helpers/taggedTemplateLiteral";import s from"@babel/runtime/helpers/asyncToGenerator";function l(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?l(Object(r),!0).forEach(function(t){a(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var u={TOGGLE_EXPANDED:(e,t)=>c(c({},e),{},{isExpanded:t,areSuggestionsVisible:t,hasFetchedSuggestions:!1}),SET_KEYBOARD_FOCUS_WITHIN:(e,t)=>c(c({},e),{},{hasKeyboardFocusWithin:t,areSuggestionsVisible:!0}),INPUT_BLUR:(e,t)=>c(c({},e),{},{hasKeyboardFocusWithin:!1,areSuggestionsVisible:e.areSuggestionsVisible&&"keyboard"!==t,selectedIndex:-1}),SET_VALUE:(e,t)=>c(c({},e),{},{value:t}),UPDATE_SUGGESTIONS:(e,t)=>c(c({},e),{},{suggestions:t,hasFetchedSuggestions:!0}),SHOW_SUGGESTIONS:e=>c(c({},e),{},{areSuggestionsVisible:!0,hasFetchedSuggestions:!1}),HIDE_SUGGESTIONS:e=>c(c({},e),{},{areSuggestionsVisible:!1,hasFetchedSuggestions:!1}),SET_SELECTED:(e,t)=>c(c({},e),{},{selectedIndex:t,areSuggestionsVisible:t>=0})},d=e=>{var{id:t,isExpanded:a,onClick:i,buttonRef:o,searchIcon:s,showLabel:l}=e;return r("button",{"aria-label":"Open search",className:"im-c-map-button",onClick:i,"aria-controls":"".concat(t,"-search-form"),ref:o,style:a?{display:"none"}:void 0,children:[s&&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:s}}),l&&n("span",{children:"Search"})]})},h=e=>{var{id:t,pluginState:r,handleSuggestionClick:a}=e;return n("ul",{id:"".concat(t,"-search-suggestions"),role:"listbox","aria-labelledby":"".concat(t,"-search"),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}})},e.id))})};function p(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?p(Object(r),!0).forEach(function(t){a(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(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}),g=t=>{var{id:a,pluginState:i,pluginConfig:o,appState:s,inputRef:l,events:c,services:u,children:d}=t,{areSuggestionsVisible:p,hasFetchedSuggestions:g,suggestions:m=[]}=i;e(()=>{p&&g&&u.announce((e=>{if(0===e)return"No results available";var t=1===e?"result":"results";return"".concat(e," ").concat(t," available")})(m.length))},[m,g]);var y=["im-c-search-form",o.expanded&&"im-c-search-form--default-expanded","im-c-panel"].filter(Boolean).join(" "),b=p&&g&&!m.length;return r("form",{id:"".concat(a,"-search-form"),role:"search",className:y,style:f(o,i,s),"aria-controls":"".concat(a,"-viewport"),onSubmit:e=>c.handleSubmit(e,s,i),children:[n("button",{type:"submit",style:{display:"none"},"aria-hidden":"true",tabIndex:-1,children:"Submit"}),r("div",{className:"im-c-search__input-container".concat(i.hasKeyboardFocusWithin?" im-c-search__input-container--keyboard-focus-within":""),children:[n("label",{htmlFor:"".concat(a,"-search"),className:"im-u-visually-hidden",children:o.placeholder}),n("input",{id:"".concat(a,"-search"),className:"im-c-search__input",type:"search",role:"combobox","aria-expanded":i.suggestionsVisible,"aria-controls":"".concat(a,"-search-suggestions"),"aria-activedescendant":i.selectedIndex>=0?"".concat(a,"-search-suggestion-").concat(i.selectedIndex):void 0,"aria-describedby":i.value?void 0:"".concat(a,"-search-hint"),"aria-autocomplete":"list",autoComplete:"off",placeholder:o.placeholder,name:"".concat(a,"-search"),spellCheck:!1,enterKeyHint:"search",value:i.value,onClick:c.handleInputClick,onChange:c.handleInputChange,onFocus:()=>c.handleInputFocus(s.interfaceType),onBlur:()=>c.handleInputBlur(s.interfaceType),onKeyDown:e=>c.handleInputKeyDown(e,i),ref:l}),n("span",{id:"".concat(a,"-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]}),b&&n("div",{className:"im-c-search__status","aria-hidden":"true",children:"No results available"}),n(h,{id:a,appState:s,pluginState:i,handleSuggestionClick:e=>c.handleSuggestionClick(e,s)})]})},m=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}})})},y=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 b=" ";class w{static get separator(){return b}static set separator(e){b=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,o=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,o=(3600*e%60).toFixed(r),60==o&&(o=(0).toFixed(r),i++),60==i&&(i=0,a++),a=("000"+a).slice(-3),i=("00"+i).slice(-2),o<10&&(o="0"+o),n=a+"°"+w.separator+i+"′"+w.separator+o+"″"}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 E{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 E))throw new TypeError("v is not Vector3d object");return new E(this.x+e.x,this.y+e.y,this.z+e.z)}minus(e){if(!(e instanceof E))throw new TypeError("v is not Vector3d object");return new E(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 E(this.x*e,this.y*e,this.z*e)}dividedBy(e){if(isNaN(e))throw new TypeError(`invalid scalar value ‘${e}’`);return new E(this.x/e,this.y/e,this.z/e)}dot(e){if(!(e instanceof E))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 E))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 E(t,r,n)}negate(){return new E(-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 E(t,r,n)}angleTo(e,t=void 0){if(!(e instanceof E))throw new TypeError("v is not Vector3d object");if(!(t instanceof E||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 E))throw new TypeError("axis is not Vector3d object");const r=t.toRadians(),n=this.unit(),a=e.unit(),i=Math.sin(r),o=Math.cos(r),s=1-o,l=a.x,c=a.y,u=a.z,d=[[s*l*l+o,s*l*c-i*u,s*l*u+i*c],[s*l*c+i*u,s*c*c+o,s*c*u-i*l],[s*l*u-i*c,s*c*u+i*l,s*u*u+o]],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 E(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 v={WGS84:{a:6378137,b:6356752.314245,f:1/298.257223563}},O={WGS84:{ellipsoid:v.WGS84}};Object.freeze(v.WGS84),Object.freeze(O.WGS84);class S{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 v}static get datums(){return O}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:v.WGS84,t=this.lat.toRadians(),r=this.lon.toRadians(),n=this.height,{a:a,f:i}=e,o=Math.sin(t),s=Math.cos(t),l=Math.sin(r),c=Math.cos(r),u=2*i-i*i,d=a/Math.sqrt(1-u*o*o);return new N((d+n)*s*c,(d+n)*s*l,(d*(1-u)+n)*o)}equals(e){if(!(e instanceof S))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 N extends E{constructor(e,t,r){super(e,t,r)}toLatLon(e=v.WGS84){if(!e||!e.a)throw new TypeError(`invalid ellipsoid ‘${e}’`);const{x:t,y:r,z:n}=this,{a:a,b:i,f:o}=e,s=2*o-o*o,l=s/(1-s),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-s*a*h*h*h),f=Math.atan2(r,t),g=Math.sin(p),m=c*Math.cos(p)+n*g-a*a/(a/Math.sqrt(1-s*g*g));return new S(p.toDegrees(),f.toDegrees(),m)}toString(e=0){return`[${this.x.toFixed(e)},${this.y.toFixed(e)},${this.z.toFixed(e)}]`}}const T={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}},_={ED50:{ellipsoid:T.Intl1924,transform:[89.5,93.8,123.1,-1.2,0,0,.156]},ETRS89:{ellipsoid:T.GRS80,transform:[0,0,0,0,0,0,0]},Irl1975:{ellipsoid:T.AiryModified,transform:[-482.53,130.596,-564.557,-8.15,1.042,.214,.631]},NAD27:{ellipsoid:T.Clarke1866,transform:[8,-160,-176,0,0,0,0]},NAD83:{ellipsoid:T.GRS80,transform:[.9956,-1.9103,-.5215,-62e-5,.025915,.009426,.011599]},NTF:{ellipsoid:T.Clarke1880IGN,transform:[168,60,-320,0,0,0,0]},OSGB36:{ellipsoid:T.Airy1830,transform:[-446.448,125.157,-542.06,20.4894,-.1502,-.247,-.8421]},Potsdam:{ellipsoid:T.Bessel1841,transform:[-582,-105,-414,-8.3,1.04,.35,-3.08]},TokyoJapan:{ellipsoid:T.Bessel1841,transform:[148,-507,-685,0,0,0,0]},WGS72:{ellipsoid:T.WGS72,transform:[0,0,-4.5,-.22,0,0,.554]},WGS84:{ellipsoid:T.WGS84,transform:[0,0,0,0,0,0,0]}};Object.keys(T).forEach(e=>Object.freeze(T[e])),Object.keys(_).forEach(e=>{Object.freeze(_[e]),Object.freeze(_[e].transform)});class x extends S{constructor(e,t,r=0,n=_.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 T}static get datums(){return _}static parse(...e){let t=_.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 D(e.x,e.y,e.z,this.datum)}}class D extends N{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||_.WGS84;if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);const r=super.toLatLon(t.ellipsoid);return new x(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!=_.WGS84||(t=this,r=e.transform),e==_.WGS84&&(t=this,r=this.datum.transform.map(e=>-e)),null==r&&(t=this.convertDatum(_.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],o=e[2],s=e[3]/1e6+1,l=(e[4]/3600).toRadians(),c=(e[5]/3600).toRadians(),u=(e[6]/3600).toRadians();return new D(a+t*s-r*u+n*c,i+t*u+r*s-n*l,o-t*c+r*l+n*s)}}const j={trueOrigin:{lat:49,lon:-2},scaleFactor:.9996012717,ellipsoid:x.ellipsoids.Airy1830};class M{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=x.datums.WGS84){const{easting:t,northing:r}=this,{a:n,b:a}=j.ellipsoid,i=j.trueOrigin.lat.toRadians(),o=j.trueOrigin.lon.toRadians(),s=-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,f=0;do{p=(r-s-f)/(n*l)+p;f=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-s-f)>=1e-5);const g=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),w=y/b-1,E=Math.tan(p),v=E*E,O=v*v,S=1/g,N=y*y*y,T=N*y*y,_=t-4e5,D=_*_,M=D*_,G=D*D,P=M*D;p=p-E/(2*b*y)*D+E/(24*b*N)*(5+3*v+w-9*v*w)*G-E/(720*b*T)*(61+90*v+45*O)*(G*D);const k=o+S/y*_-S/(6*N)*(y/b+2*v)*M+S/(120*T)*(5+28*v+24*O)*P-S/(5040*(T*y*y))*(61+662*v+1320*O+720*(O*v))*(P*D);let C=new R(p.toDegrees(),k.toDegrees(),0,x.datums.OSGB36);return e!=x.datums.OSGB36&&(C=C.convertDatum(e),C=new R(C.lat,C.lon,C.height,C.datum)),C}static parse(e){let t=(e=String(e).trim()).match(/^(\d+),\s*(\d+)$/);if(t)return new M(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 o=e.slice(2).trim().split(/\s+/);if(1==o.length&&(o=[o[0].slice(0,o[0].length/2),o[0].slice(o[0].length/2)]),o[0].length!=o[1].length)throw new Error(`invalid grid reference ‘${e}’`);o[0]=o[0].padEnd(5,"0"),o[1]=o[1].padEnd(5,"0");const s=a+o[0],l=i+o[1];return new M(s,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),o=5*(19-a)%25+n%5;i>7&&i++,o>7&&o++;const s=String.fromCharCode(i+"A".charCodeAt(0),o+"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"),`${s} ${t} ${r}`}}class R extends x{toOsGrid(){const e=this.datum==x.datums.OSGB36?this:this.convertDatum(x.datums.OSGB36),t=e.lat.toRadians(),r=e.lon.toRadians(),{a:n,b:a}=j.ellipsoid,i=j.trueOrigin.lat.toRadians(),o=j.trueOrigin.lon.toRadians(),s=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),f=n*s/Math.sqrt(1-l*p*p),g=n*s*(1-l)/Math.pow(1-l*p*p,1.5),m=f/g-1,y=a*s*((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,w=b*h*h,E=Math.tan(t)*Math.tan(t),v=E*E,O=r-o,S=O*O,N=S*O,T=N*O,_=T*O;let D=y+-1e5+f/2*p*h*S+f/24*p*b*(5-E+9*m)*T+f/720*p*w*(61-58*E+v)*(_*O),R=4e5+f*h*O+f/6*b*(f/g-E)*N+f/120*w*(5-18*E+v+14*m-58*E*m)*_;D=Number(D.toFixed(3)),R=Number(R.toFixed(3));try{return new M(R,D)}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 R(t.lat,t.lon,t.height,t.datum)}}var G;function P(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 k(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?P(Object(r),!0).forEach(function(t){a(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):P(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var C=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},I=(e,t)=>{var r,n,a,i,{MBR_XMIN:o,MBR_YMIN:s,MBR_XMAX:l,MBR_YMAX:c,GEOMETRY_X:u,GEOMETRY_Y:d}=t;if(null==o?(r=u-C,n=d-C,a=u+C,i=d+C):(r=o,n=s,a=l,i=c),"EPSG:27700"===e)return[r,n,a,i];if("EPSG:4326"===e){var h=new M(r,n).toLatLon(),p=new M(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))},A=(e,t)=>{var{GEOMETRY_X:r,GEOMETRY_Y:n}=t;if("EPSG:27700"===e)return[r,n];if("EPSG:4326"===e){var a=new M(r,n).toLatLon();return[Math.round(1e6*a.lon)/1e6,Math.round(1e6*a.lat)/1e6]}throw new Error("Unsupported CRS: ".concat(e))},$=(e,t,r,n)=>{var a;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,8)).map(e=>k(k({id:e.GAZETTEER_ENTRY.ID,bounds:I(n,e.GAZETTEER_ENTRY),point:A(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(G||(G=o(["s*"],["\\s*"])))),i=new RegExp("(".concat(a,")"),"i"),r.replace(i,"<mark>$1</mark>"))}})(t,e.GAZETTEER_ENTRY)),{},{type:"os-names"}))};var F=e=>{var{url:t,options:r}=e;return new Request(t,r)},W=function(){var e=s(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:F(i)}return F(r?yield r(a,t):a)});return function(t,r,n){return e.apply(this,arguments)}}(),U=function(){var e=s(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)),null;var a=yield n.json();return e.parseResults(a,r)}catch(t){return console.error("Network error for ".concat(e.label||"dataset",":"),t),null}});return function(t,r,n){return e.apply(this,arguments)}}(),B=function(){var e=s(function*(e,t,r,n){var a=(e=>e.replace(/[^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}),o=[];for(var s of i){var l=yield W(s,a,n),c=yield U(s,l,a);if(null!=c&&c.length&&(o=[...o,...c],s.exclusive))break}return r({type:"UPDATE_SUGGESTIONS",payload:o}),{results:o,sanitisedValue:a}});return function(t,r,n,a){return e.apply(this,arguments)}}();function z(e){var{mapProvider:t,bounds:r,point:n,markers:a,showMarker:i,markerOptions:o}=e;t.fitToBounds(r),i&&a.add("search",n,o)}var V=3;function Y(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?Y(Object(r),!0).forEach(function(t){a(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Y(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}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}var Z=e=>{var{dispatch:t,services:r,mapProvider:n,markers:i,showMarker:o,markerOptions:s}=e,l=(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,l){t({type:"SET_VALUE",payload:e.text}),t({type:"HIDE_SUGGESTIONS"}),t({type:"SET_SELECTED",payload:-1}),"mobile"===l.breakpoint&&(t({type:"TOGGLE_EXPANDED",payload:!1}),r.eventBus.emit("search:close")),z({mapProvider:n,bounds:e.bounds,point:e.point,markers:i,showMarker:o,markerOptions:s}),r.eventBus.emit("search:match",function(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){a(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}({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 o=i+1;r.announce(l(a,o)),t({type:"SET_SELECTED",payload:o}),t({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:!1})}break;case"ArrowUp":if(null==a||!a.length)return;e.preventDefault();var s=i>0?i-1:-1;r.announce(l(a,s)),t({type:"SET_SELECTED",payload:s}),t({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:s<0});break;case"Escape":e.preventDefault(),t({type:"HIDE_SUGGESTIONS"}),t({type:"SET_SELECTED",payload:-1})}}}};function K(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 X(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?K(Object(r),!0).forEach(function(t){a(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):K(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function J(e){var t,r,n,a,{dispatch:i,searchContainerRef:o}=e,l=(t=t=>B(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),c=(e=>{var{dispatch:t,services:r,viewportRef:n,mapProvider:a,markers:i,datasets:o,transformRequest:l,showMarker:c,markerOptions:u}=e,d="";return{handleOpenClick(){t({type:"TOGGLE_EXPANDED",payload:!0}),r.eventBus.emit("search:open")},handleCloseClick(e,n){t({type:"TOGGLE_EXPANDED",payload:!1}),t({type:"UPDATE_SUGGESTIONS",payload:[]}),t({type:"SET_VALUE",payload:""}),setTimeout(()=>n.current.focus(),0),i.remove("search"),r.eventBus.emit("search:clear"),r.eventBus.emit("search:close")},handleSubmit:(e,h,p)=>s(function*(){e.preventDefault();var{suggestions:s,selectedIndex:f,value:g}=p,m=null==g?void 0:g.trim();if(t({type:"SET_SELECTED",payload:-1}),t({type:"HIDE_SUGGESTIONS"}),f>=0){var y,b=s[f];return t({type:"SET_VALUE",payload:b.text}),null===(y=n.current)||void 0===y||y.focus(),z({mapProvider:a,bounds:b.bounds,point:b.point,markers:i,showMarker:c,markerOptions:u}),void r.eventBus.emit("search:match",H({query:b.text},b))}if(!((null==m?void 0:m.length)<V)){var w=s;if(!s.length||m!==d){var{results:E,sanitisedValue:v}=yield B(m,o,t,l);w=E,d=v}if(w.length){var O;"keyboard"===h.interfaceType&&(null===(O=n.current)||void 0===O||O.focus()),"mobile"===h.breakpoint&&(t({type:"TOGGLE_EXPANDED",payload:!1}),r.eventBus.emit("search:close"));var S=w[0];z({mapProvider:a,bounds:S.bounds,point:S.point,markers:i,showMarker:c,markerOptions:u}),r.eventBus.emit("search:match",H({query:g},S))}}})()}})(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<V)return r.cancel(),t({type:"UPDATE_SUGGESTIONS",payload:[]}),void t({type:"HIDE_SUGGESTIONS"});t({type:"SHOW_SUGGESTIONS"}),r(n)}}})(X(X({},e),{},{debouncedFetchSuggestions:l})),d=Z(e);return X(X(X(X({},c),u),d),{},{handleOutside(t){o.current.contains(t.target)||(i({type:"TOGGLE_EXPANDED",payload:!1}),e.services.eventBus.emit("search:close"))}})}var Q=["marker"];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}var te={reducer:{initialState:{isExpanded:!1,hasKeyboardFocusWithin:!1,value:"",suggestions:[],areSuggestionsVisible:!1,hasFetchedSuggestions:!1,selectedIndex:-1},actions:u},controls:[{id:"search",mobile:{slot:"top-right",showLabel:!1},tablet:{slot:"top-left",showLabel:!1},desktop:{slot:"top-left",showLabel:!1},render:function(o){var s,{appConfig:l,iconRegistry:c,pluginState:u,pluginConfig:h,appState:p,mapState:f,services:b,mapProvider:w}=o,{id:E}=l,{interfaceType:v}=p,{expanded:O,customDatasets:S,osNamesURL:N,regions:T}=h,{dispatch:_,isExpanded:x,areSuggestionsVisible:D,suggestions:j}=u,M=(null==p||null===(s=p.controlConfig)||void 0===s||null===(s=s.search)||void 0===s?void 0:s[null==p?void 0:p.breakpoint].showLabel)||!1,R=c.close,G=c.search,P=t(null),k=t(null),C=t(null),L=p.layoutRefs.viewportRef,I=function(e){var{customDatasets:t=[],osNamesURL:r,crs:n,regions:a=["england","scotland","wales"]}=e;return r?[{name:"osNames",urlTemplate:r,parseResults:(e,t)=>$(e,t,a,n),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:S,osNamesURL:N,regions:T,crs:w.crs}),A=t(null);if(!A.current){var{marker:F}=h,W=i(h,Q);A.current=J(function(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){a(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}({dispatch:_,datasets:I,services:b,mapProvider:w,viewportRef:L,searchContainerRef:P,markers:f.markers,markerOptions:F},W))}var U=A.current,B=x||!!(O&&D&&j.length);return e(()=>{var e;x&&(null===(e=C.current)||void 0===e||e.focus())},[x]),e(()=>{if(p.dispatch({type:"TOGGLE_HAS_EXCLUSIVE_CONTROL",payload:x}),B)return L.current.style.pointerEvents="none",document.addEventListener("focusin",U.handleOutside),document.addEventListener("pointerdown",U.handleOutside),()=>{L.current.style.pointerEvents="auto",document.removeEventListener("focusin",U.handleOutside),document.removeEventListener("pointerdown",U.handleOutside)}},[x,v,D,j]),r("div",{className:"im-c-search",ref:P,children:[!O&&n(d,{id:E,isExpanded:x,onClick:()=>U.handleOpenClick(p),buttonRef:k,searchIcon:G,showLabel:M}),r(g,{id:E,pluginState:u,pluginConfig:h,appState:p,inputRef:C,events:U,services:b,children:[n(m,{defaultExpanded:O,onClick:e=>U.handleCloseClick(e,k,p),closeIcon:R}),n(y,{defaultExpanded:O,onClick:e=>U.handleCloseClick(e,k,p),submitIcon:G})]})]})}}],icons:[{id:"search",svgContent:'<path d="m21 21-4.34-4.34"></path><circle cx="11" cy="11" r="8"></circle>'}]};export{te as manifest};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see im-search-plugin.js.LICENSE.txt */
|
|
2
|
-
"use strict";(this.webpackChunkdefra_DefraMap=this.webpackChunkdefra_DefraMap||[]).push([[254],{335(t,e,r){function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function i(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?o(Object(r),!0).forEach(function(e){a(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function a(t,e,r){return(e=function(t){var e=function(t){if("object"!=n(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==n(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}r.r(e),r.d(e,{manifest:()=>Et});var s={TOGGLE_EXPANDED:function(t,e){return i(i({},t),{},{isExpanded:e,areSuggestionsVisible:e,hasFetchedSuggestions:!1})},SET_KEYBOARD_FOCUS_WITHIN:function(t,e){return i(i({},t),{},{hasKeyboardFocusWithin:e,areSuggestionsVisible:!0})},INPUT_BLUR:function(t,e){return i(i({},t),{},{hasKeyboardFocusWithin:!1,areSuggestionsVisible:t.areSuggestionsVisible&&"keyboard"!==e,selectedIndex:-1})},SET_VALUE:function(t,e){return i(i({},t),{},{value:e})},UPDATE_SUGGESTIONS:function(t,e){return i(i({},t),{},{suggestions:e,hasFetchedSuggestions:!0})},SHOW_SUGGESTIONS:function(t){return i(i({},t),{},{areSuggestionsVisible:!0,hasFetchedSuggestions:!1})},HIDE_SUGGESTIONS:function(t){return i(i({},t),{},{areSuggestionsVisible:!1,hasFetchedSuggestions:!1})},SET_SELECTED:function(t,e){return i(i({},t),{},{selectedIndex:e,areSuggestionsVisible:e>=0})}},u=r(738),c=r(287),l=function(t){var e=t.id,r=t.isExpanded,n=t.onClick,o=t.buttonRef,i=t.searchIcon,a=t.showLabel;return(0,c.jsxs)("button",{"aria-label":"Open search",className:"im-c-map-button",onClick:n,"aria-controls":"".concat(e,"-search-form"),ref:o,style:r?{display:"none"}:void 0,children:[i&&(0,c.jsx)("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:i}}),a&&(0,c.jsx)("span",{children:"Search"})]})},f=function(t){var e=t.id,r=t.pluginState,n=t.handleSuggestionClick;return(0,c.jsx)("ul",{id:"".concat(e,"-search-suggestions"),role:"listbox","aria-labelledby":"".concat(e,"-search"),className:"im-c-search-suggestions",style:r.areSuggestionsVisible&&r.suggestions.length?void 0:{display:"none"},children:r.suggestions.map(function(t,o){return(0,c.jsx)("li",{id:"".concat(e,"-search-suggestion-").concat(o),className:"im-c-search-suggestions__item",role:"option","aria-selected":r.selectedIndex===o,"aria-setsize":r.suggestions.length,"aria-posinset":o+1,onClick:function(){return n(t)},children:(0,c.jsx)("span",{className:"im-c-search-suggestions__label",dangerouslySetInnerHTML:{__html:t.marked}})},t.id)})})};function p(t){return p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},p(t)}function d(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function h(t,e,r){return(e=function(t){var e=function(t){if("object"!=p(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=p(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==p(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var y=function(t,e,r){return function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?d(Object(r),!0).forEach(function(e){h(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}({display:t.expanded||e.isExpanded?"flex":void 0},"mobile"!==r.breakpoint&&(null==t?void 0:t.width)&&{width:t.width})},m=function(t){var e=t.id,r=t.pluginState,n=t.pluginConfig,o=t.appState,i=t.inputRef,a=t.events,s=t.services,l=t.children,p=r.areSuggestionsVisible,d=r.hasFetchedSuggestions,h=r.suggestions,m=void 0===h?[]:h;(0,u.useEffect)(function(){p&&d&&s.announce(function(t){if(0===t)return"No results available";var e=1===t?"result":"results";return"".concat(t," ").concat(e," available")}(m.length))},[m,d]);var b=["im-c-search-form",n.expanded&&"im-c-search-form--default-expanded","im-c-panel"].filter(Boolean).join(" "),g=p&&d&&!m.length;return(0,c.jsxs)("form",{id:"".concat(e,"-search-form"),role:"search",className:b,style:y(n,r,o),"aria-controls":"".concat(e,"-viewport"),onSubmit:function(t){return a.handleSubmit(t,o,r)},children:[(0,c.jsx)("button",{type:"submit",style:{display:"none"},"aria-hidden":"true",tabIndex:-1,children:"Submit"}),(0,c.jsxs)("div",{className:"im-c-search__input-container".concat(r.hasKeyboardFocusWithin?" im-c-search__input-container--keyboard-focus-within":""),children:[(0,c.jsx)("label",{htmlFor:"".concat(e,"-search"),className:"im-u-visually-hidden",children:n.placeholder}),(0,c.jsx)("input",{id:"".concat(e,"-search"),className:"im-c-search__input",type:"search",role:"combobox","aria-expanded":r.suggestionsVisible,"aria-controls":"".concat(e,"-search-suggestions"),"aria-activedescendant":r.selectedIndex>=0?"".concat(e,"-search-suggestion-").concat(r.selectedIndex):void 0,"aria-describedby":r.value?void 0:"".concat(e,"-search-hint"),"aria-autocomplete":"list",autoComplete:"off",placeholder:n.placeholder,name:"".concat(e,"-search"),spellCheck:!1,enterKeyHint:"search",value:r.value,onClick:a.handleInputClick,onChange:a.handleInputChange,onFocus:function(){return a.handleInputFocus(o.interfaceType)},onBlur:function(){return a.handleInputBlur(o.interfaceType)},onKeyDown:function(t){return a.handleInputKeyDown(t,r)},ref:i}),(0,c.jsx)("span",{id:"".concat(e,"-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."}),l]}),g&&(0,c.jsx)("div",{className:"im-c-search__status","aria-hidden":"true",children:"No results available"}),(0,c.jsx)(f,{id:e,appState:o,pluginState:r,handleSuggestionClick:function(t){return a.handleSuggestionClick(t,o)}})]})},b=function(t){var e=t.defaultExpanded,r=t.onClick,n=t.closeIcon;return(0,c.jsx)("button",{"aria-label":"Close search",className:"im-c-map-button im-c-search-close-button",type:"button",onClick:r,style:e?{display:"none"}:void 0,children:n&&(0,c.jsx)("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:n}})})},g=function(t){var e=t.defaultExpanded,r=t.submitIcon;return(0,c.jsx)("button",{"aria-label":"Search",className:"im-c-map-button im-c-search-submit-button",type:"submit",style:e?void 0:{display:"none"},children:r&&(0,c.jsx)("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(t){v=t}static parse(t){if(!isNaN(parseFloat(t))&&isFinite(t))return Number(t);const e=String(t).trim().replace(/^-/,"").replace(/[NSEW]$/i,"").split(/[^0-9.,]+/);if(""==e[e.length-1]&&e.splice(e.length-1),""==e)return NaN;let r=null;switch(e.length){case 3:r=e[0]/1+e[1]/60+e[2]/3600;break;case 2:r=e[0]/1+e[1]/60;break;case 1:r=e[0];break;default:return NaN}return/^-|[WS]$/i.test(t.trim())&&(r=-r),Number(r)}static toDms(t,e="d",r=void 0){if(isNaN(t))return null;if("string"==typeof t&&""==t.trim())return null;if("boolean"==typeof t)return null;if(t==1/0)return null;if(null==t)return null;if(void 0===r)switch(e){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:e="d",r=4}t=Math.abs(t);let n=null,o=null,i=null,a=null;switch(e){default:case"d":case"deg":o=t.toFixed(r),o<100&&(o="0"+o),o<10&&(o="0"+o),n=o+"°";break;case"dm":case"deg+min":o=Math.floor(t),i=(60*t%60).toFixed(r),60==i&&(i=(0).toFixed(r),o++),o=("000"+o).slice(-3),i<10&&(i="0"+i),n=o+"°"+w.separator+i+"′";break;case"dms":case"deg+min+sec":o=Math.floor(t),i=Math.floor(3600*t/60)%60,a=(3600*t%60).toFixed(r),60==a&&(a=(0).toFixed(r),i++),60==i&&(i=0,o++),o=("000"+o).slice(-3),i=("00"+i).slice(-2),a<10&&(a="0"+a),n=o+"°"+w.separator+i+"′"+w.separator+a+"″"}return n}static toLat(t,e,r){const n=w.toDms(w.wrap90(t),e,r);return null===n?"–":n.slice(1)+w.separator+(t<0?"S":"N")}static toLon(t,e,r){const n=w.toDms(w.wrap180(t),e,r);return null===n?"–":n+w.separator+(t<0?"W":"E")}static toBrng(t,e,r){const n=w.toDms(w.wrap360(t),e,r);return null===n?"–":n.replace("360","0")}static fromLocale(t){const e=123456.789.toLocaleString(),r={thousands:e.slice(3,4),decimal:e.slice(7,8)};return t.replace(r.thousands,"⁜").replace(r.decimal,".").replace("⁜",",")}static toLocale(t){const e=123456.789.toLocaleString(),r={thousands:e.slice(3,4),decimal:e.slice(7,8)};return t.replace(/,([0-9])/,"⁜$1").replace(".",r.decimal).replace("⁜",r.thousands)}static compassPoint(t,e=3){if(![1,2,3].includes(Number(e)))throw new RangeError(`invalid precision ‘${e}’`);t=w.wrap360(t);const r=4*2**(e-1);return["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"][Math.round(t*r/360)%r*16/r]}static wrap90(t){if(-90<=t&&t<=90)return t;const e=t;return 1*Math.abs(((e-90)%360+360)%360-180)-90}static wrap180(t){if(-180<=t&&t<=180)return t;const e=360;return((360*t/e-180)%e+e)%e-180}static wrap360(t){if(0<=t&&t<360)return t;const e=360;return(360*t/e%e+e)%e}}Number.prototype.toRadians=function(){return this*Math.PI/180},Number.prototype.toDegrees=function(){return 180*this/Math.PI};const S=w;class E{constructor(t,e,r){if(isNaN(t)||isNaN(e)||isNaN(r))throw new TypeError(`invalid vector [${t},${e},${r}]`);this.x=Number(t),this.y=Number(e),this.z=Number(r)}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}plus(t){if(!(t instanceof E))throw new TypeError("v is not Vector3d object");return new E(this.x+t.x,this.y+t.y,this.z+t.z)}minus(t){if(!(t instanceof E))throw new TypeError("v is not Vector3d object");return new E(this.x-t.x,this.y-t.y,this.z-t.z)}times(t){if(isNaN(t))throw new TypeError(`invalid scalar value ‘${t}’`);return new E(this.x*t,this.y*t,this.z*t)}dividedBy(t){if(isNaN(t))throw new TypeError(`invalid scalar value ‘${t}’`);return new E(this.x/t,this.y/t,this.z/t)}dot(t){if(!(t instanceof E))throw new TypeError("v is not Vector3d object");return this.x*t.x+this.y*t.y+this.z*t.z}cross(t){if(!(t instanceof E))throw new TypeError("v is not Vector3d object");const e=this.y*t.z-this.z*t.y,r=this.z*t.x-this.x*t.z,n=this.x*t.y-this.y*t.x;return new E(e,r,n)}negate(){return new E(-this.x,-this.y,-this.z)}unit(){const t=this.length;if(1==t)return this;if(0==t)return this;const e=this.x/t,r=this.y/t,n=this.z/t;return new E(e,r,n)}angleTo(t,e=void 0){if(!(t instanceof E))throw new TypeError("v is not Vector3d object");if(!(e instanceof E||null==e))throw new TypeError("n is not Vector3d object");const r=null==e||this.cross(t).dot(e)>=0?1:-1,n=this.cross(t).length*r,o=this.dot(t);return Math.atan2(n,o)}rotateAround(t,e){if(!(t instanceof E))throw new TypeError("axis is not Vector3d object");const r=e.toRadians(),n=this.unit(),o=t.unit(),i=Math.sin(r),a=Math.cos(r),s=1-a,u=o.x,c=o.y,l=o.z,f=[[s*u*u+a,s*u*c-i*l,s*u*l+i*c],[s*u*c+i*l,s*c*c+a,s*c*l-i*u],[s*u*l-i*c,s*c*l+i*u,s*l*l+a]],p=[f[0][0]*n.x+f[0][1]*n.y+f[0][2]*n.z,f[1][0]*n.x+f[1][1]*n.y+f[1][2]*n.z,f[2][0]*n.x+f[2][1]*n.y+f[2][2]*n.z];return new E(p[0],p[1],p[2])}toString(t=3){return`[${this.x.toFixed(t)},${this.y.toFixed(t)},${this.z.toFixed(t)}]`}}Number.prototype.toRadians=function(){return this*Math.PI/180},Number.prototype.toDegrees=function(){return 180*this/Math.PI};const O=E,N={WGS84:{a:6378137,b:6356752.314245,f:1/298.257223563}},T={WGS84:{ellipsoid:N.WGS84}};Object.freeze(N.WGS84),Object.freeze(T.WGS84);class j{constructor(t,e,r=0){if(isNaN(t)||null==t)throw new TypeError(`invalid lat ‘${t}’`);if(isNaN(e)||null==e)throw new TypeError(`invalid lon ‘${e}’`);if(isNaN(r)||null==r)throw new TypeError(`invalid height ‘${r}’`);this._lat=S.wrap90(Number(t)),this._lon=S.wrap180(Number(e)),this._height=Number(r)}get lat(){return this._lat}get latitude(){return this._lat}set lat(t){if(this._lat=isNaN(t)?S.wrap90(S.parse(t)):S.wrap90(Number(t)),isNaN(this._lat))throw new TypeError(`invalid lat ‘${t}’`)}set latitude(t){if(this._lat=isNaN(t)?S.wrap90(S.parse(t)):S.wrap90(Number(t)),isNaN(this._lat))throw new TypeError(`invalid latitude ‘${t}’`)}get lon(){return this._lon}get lng(){return this._lon}get longitude(){return this._lon}set lon(t){if(this._lon=isNaN(t)?S.wrap180(S.parse(t)):S.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid lon ‘${t}’`)}set lng(t){if(this._lon=isNaN(t)?S.wrap180(S.parse(t)):S.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid lng ‘${t}’`)}set longitude(t){if(this._lon=isNaN(t)?S.wrap180(S.parse(t)):S.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid longitude ‘${t}’`)}get height(){return this._height}set height(t){if(this._height=Number(t),isNaN(this._height))throw new TypeError(`invalid height ‘${t}’`)}get datum(){return this._datum}set datum(t){this._datum=t}static get ellipsoids(){return N}static get datums(){return T}static parse(...t){if(0==t.length)throw new TypeError("invalid (empty) point");let e,r,n;if("object"==typeof t[0]&&(1==t.length||!isNaN(parseFloat(t[1])))){const o=t[0];if("Point"==o.type&&Array.isArray(o.coordinates)?([r,e,n]=o.coordinates,n=n||0):(null!=o.latitude&&(e=o.latitude),null!=o.lat&&(e=o.lat),null!=o.longitude&&(r=o.longitude),null!=o.lng&&(r=o.lng),null!=o.lon&&(r=o.lon),null!=o.height&&(n=o.height),e=S.wrap90(S.parse(e)),r=S.wrap180(S.parse(r))),null!=t[1]&&(n=t[1]),isNaN(e)||isNaN(r))throw new TypeError(`invalid point ‘${JSON.stringify(t[0])}’`)}if("string"==typeof t[0]&&2==t[0].split(",").length&&([e,r]=t[0].split(","),e=S.wrap90(S.parse(e)),r=S.wrap180(S.parse(r)),n=t[1]||0,isNaN(e)||isNaN(r)))throw new TypeError(`invalid point ‘${t[0]}’`);if(null==e&&null==r&&([e,r]=t,e=S.wrap90(S.parse(e)),r=S.wrap180(S.parse(r)),n=t[2]||0,isNaN(e)||isNaN(r)))throw new TypeError(`invalid point ‘${t.toString()}’`);return new this(e,r,n)}toCartesian(){const t=this.datum?this.datum.ellipsoid:this.referenceFrame?this.referenceFrame.ellipsoid:N.WGS84,e=this.lat.toRadians(),r=this.lon.toRadians(),n=this.height,{a:o,f:i}=t,a=Math.sin(e),s=Math.cos(e),u=Math.sin(r),c=Math.cos(r),l=2*i-i*i,f=o/Math.sqrt(1-l*a*a);return new _((f+n)*s*c,(f+n)*s*u,(f*(1-l)+n)*a)}equals(t){if(!(t instanceof j))throw new TypeError(`invalid point ‘${t}’`);return!(Math.abs(this.lat-t.lat)>Number.EPSILON||Math.abs(this.lon-t.lon)>Number.EPSILON||Math.abs(this.height-t.height)>Number.EPSILON||this.datum!=t.datum||this.referenceFrame!=t.referenceFrame||this.epoch!=t.epoch)}toString(t="d",e=void 0,r=null){if(!["d","dm","dms","n"].includes(t))throw new RangeError(`invalid format ‘${t}’`);const n=(this.height>=0?" +":" ")+this.height.toFixed(r)+"m";return"n"==t?(null==e&&(e=4),`${this.lat.toFixed(e)}, ${this.lon.toFixed(e)}${null==r?"":n}`):`${S.toLat(this.lat,t,e)}, ${S.toLon(this.lon,t,e)}${null==r?"":n}`}}class _ extends O{constructor(t,e,r){super(t,e,r)}toLatLon(t=N.WGS84){if(!t||!t.a)throw new TypeError(`invalid ellipsoid ‘${t}’`);const{x:e,y:r,z:n}=this,{a:o,b:i,f:a}=t,s=2*a-a*a,u=s/(1-s),c=Math.sqrt(e*e+r*r),l=i*n/(o*c)*(1+u*i/Math.sqrt(c*c+n*n)),f=l/Math.sqrt(1+l*l),p=f/l,d=isNaN(p)?0:Math.atan2(n+u*i*f*f*f,c-s*o*p*p*p),h=Math.atan2(r,e),y=Math.sin(d),m=c*Math.cos(d)+n*y-o*o/(o/Math.sqrt(1-s*y*y));return new j(d.toDegrees(),h.toDegrees(),m)}toString(t=0){return`[${this.x.toFixed(t)},${this.y.toFixed(t)},${this.z.toFixed(t)}]`}}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}},P={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(t=>Object.freeze(x[t])),Object.keys(P).forEach(t=>{Object.freeze(P[t]),Object.freeze(P[t].transform)});class k extends j{constructor(t,e,r=0,n=P.WGS84){if(!n||null==n.ellipsoid)throw new TypeError(`unrecognised datum ‘${n}’`);super(t,e,r),this._datum=n}get datum(){return this._datum}static get ellipsoids(){return x}static get datums(){return P}static parse(...t){let e=P.WGS84;if((4==t.length||3==t.length&&"object"==typeof t[2])&&(e=t.pop()),!e||null==e.ellipsoid)throw new TypeError(`unrecognised datum ‘${e}’`);const r=super.parse(...t);return r._datum=e,r}convertDatum(t){if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);return this.toCartesian().convertDatum(t).toLatLon()}toCartesian(){const t=super.toCartesian();return new G(t.x,t.y,t.z,this.datum)}}class G extends _{constructor(t,e,r,n=void 0){if(n&&null==n.ellipsoid)throw new TypeError(`unrecognised datum ‘${n}’`);super(t,e,r),n&&(this._datum=n)}get datum(){return this._datum}set datum(t){if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);this._datum=t}toLatLon(t=void 0){t&&(console.info("datum parameter to Cartesian_Datum.toLatLon is deprecated: set datum before calling toLatLon()"),this.datum=t);const e=this.datum||P.WGS84;if(!e||null==e.ellipsoid)throw new TypeError(`unrecognised datum ‘${e}’`);const r=super.toLatLon(e.ellipsoid);return new k(r.lat,r.lon,r.height,this.datum)}convertDatum(t){if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);if(!this.datum)throw new TypeError("cartesian coordinate has no datum");let e=null,r=null;null!=this.datum&&this.datum!=P.WGS84||(e=this,r=t.transform),t==P.WGS84&&(e=this,r=this.datum.transform.map(t=>-t)),null==r&&(e=this.convertDatum(P.WGS84),r=t.transform);const n=e.applyTransform(r);return n.datum=t,n}applyTransform(t){const{x:e,y:r,z:n}=this,o=t[0],i=t[1],a=t[2],s=t[3]/1e6+1,u=(t[4]/3600).toRadians(),c=(t[5]/3600).toRadians(),l=(t[6]/3600).toRadians();return new G(o+e*s-r*l+n*c,i+e*l+r*s-n*u,a-e*c+r*u+n*s)}}const D={trueOrigin:{lat:49,lon:-2},falseOrigin:{easting:-4e5,northing:1e5},scaleFactor:.9996012717,ellipsoid:k.ellipsoids.Airy1830};class M{constructor(t,e){if(this.easting=Number(t),this.northing=Number(e),isNaN(t)||this.easting<0||this.easting>7e5)throw new RangeError(`invalid easting ‘${t}’`);if(isNaN(e)||this.northing<0||this.northing>13e5)throw new RangeError(`invalid northing ‘${e}’`)}toLatLon(t=k.datums.WGS84){const{easting:e,northing:r}=this,{a:n,b:o}=D.ellipsoid,i=D.trueOrigin.lat.toRadians(),a=D.trueOrigin.lon.toRadians(),s=-D.falseOrigin.easting,u=-D.falseOrigin.northing,c=D.scaleFactor,l=1-o*o/(n*n),f=(n-o)/(n+o),p=f*f,d=f*f*f;let h=i,y=0;do{h=(r-u-y)/(n*c)+h,y=o*c*((1+f+5/4*p+5/4*d)*(h-i)-(3*f+3*f*f+21/8*d)*Math.sin(h-i)*Math.cos(h+i)+(15/8*p+15/8*d)*Math.sin(2*(h-i))*Math.cos(2*(h+i))-35/24*d*Math.sin(3*(h-i))*Math.cos(3*(h+i)))}while(Math.abs(r-u-y)>=1e-5);const m=Math.cos(h),b=Math.sin(h),g=n*c/Math.sqrt(1-l*b*b),v=n*c*(1-l)/Math.pow(1-l*b*b,1.5),w=g/v-1,S=Math.tan(h),E=S*S,O=E*E,N=1/m,T=g*g*g,j=T*g*g,_=e-s,x=_*_,P=x*_,G=x*x,M=P*x;h=h-S/(2*v*g)*x+S/(24*v*T)*(5+3*E+w-9*E*w)*G-S/(720*v*j)*(61+90*E+45*O)*(G*x);const R=a+N/g*_-N/(6*T)*(g/v+2*E)*P+N/(120*j)*(5+28*E+24*O)*M-N/(j*g*g*5040)*(61+662*E+1320*O+O*E*720)*(M*x);let A=new C(h.toDegrees(),R.toDegrees(),0,k.datums.OSGB36);return t!=k.datums.OSGB36&&(A=A.convertDatum(t),A=new C(A.lat,A.lon,A.height,A.datum)),A}static parse(t){let e=(t=String(t).trim()).match(/^(\d+),\s*(\d+)$/);if(e)return new M(e[1],e[2]);if(e=t.match(/^[HNST][ABCDEFGHJKLMNOPQRSTUVWXYZ]\s*[0-9]+\s*[0-9]+$/i),!e)throw new Error(`invalid grid reference ‘${t}’`);let r=t.toUpperCase().charCodeAt(0)-"A".charCodeAt(0),n=t.toUpperCase().charCodeAt(1)-"A".charCodeAt(0);r>7&&r--,n>7&&n--;const o=(r-2)%5*5+n%5,i=19-5*Math.floor(r/5)-Math.floor(n/5);let a=t.slice(2).trim().split(/\s+/);if(1==a.length&&(a=[a[0].slice(0,a[0].length/2),a[0].slice(a[0].length/2)]),a[0].length!=a[1].length)throw new Error(`invalid grid reference ‘${t}’`);a[0]=a[0].padEnd(5,"0"),a[1]=a[1].padEnd(5,"0");const s=o+a[0],u=i+a[1];return new M(s,u)}toString(t=10){if(![0,2,4,6,8,10,12,14,16].includes(Number(t)))throw new RangeError(`invalid precision ‘${t}’`);let{easting:e,northing:r}=this;if(0==t){const t={useGrouping:!1,minimumIntegerDigits:6,maximumFractionDigits:3};return`${e.toLocaleString("en",t)},${r.toLocaleString("en",t)}`}const n=Math.floor(e/1e5),o=Math.floor(r/1e5);let i=19-o-(19-o)%5+Math.floor((n+10)/5),a=5*(19-o)%25+n%5;i>7&&i++,a>7&&a++;const s=String.fromCharCode(i+"A".charCodeAt(0),a+"A".charCodeAt(0));return e=Math.floor(e%1e5/Math.pow(10,5-t/2)),r=Math.floor(r%1e5/Math.pow(10,5-t/2)),e=e.toString().padStart(t/2,"0"),r=r.toString().padStart(t/2,"0"),`${s} ${e} ${r}`}}class C extends k{toOsGrid(){const t=this.datum==k.datums.OSGB36?this:this.convertDatum(k.datums.OSGB36),e=t.lat.toRadians(),r=t.lon.toRadians(),{a:n,b:o}=D.ellipsoid,i=D.trueOrigin.lat.toRadians(),a=D.trueOrigin.lon.toRadians(),s=-D.falseOrigin.easting,u=-D.falseOrigin.northing,c=D.scaleFactor,l=1-o*o/(n*n),f=(n-o)/(n+o),p=f*f,d=f*f*f,h=Math.cos(e),y=Math.sin(e),m=n*c/Math.sqrt(1-l*y*y),b=n*c*(1-l)/Math.pow(1-l*y*y,1.5),g=m/b-1,v=o*c*((1+f+5/4*p+5/4*d)*(e-i)-(3*f+3*f*f+21/8*d)*Math.sin(e-i)*Math.cos(e+i)+(15/8*p+15/8*d)*Math.sin(2*(e-i))*Math.cos(2*(e+i))-35/24*d*Math.sin(3*(e-i))*Math.cos(3*(e+i))),w=h*h*h,S=w*h*h,E=Math.tan(e)*Math.tan(e),O=E*E,N=r-a,T=N*N,j=T*N,_=j*N,x=_*N;let P=v+u+m/2*y*h*T+m/24*y*w*(5-E+9*g)*_+m/720*y*S*(61-58*E+O)*(x*N),G=s+m*h*N+m/6*w*(m/b-E)*j+m/120*S*(5-18*E+O+14*g-58*E*g)*x;P=Number(P.toFixed(3)),G=Number(G.toFixed(3));try{return new M(G,P)}catch(e){throw new Error(`${e.message} from (${t.lat.toFixed(6)},${t.lon.toFixed(6)}).toOsGrid()`)}}convertDatum(t){const e=super.convertDatum(t);return new C(e.lat,e.lon,e.height,e.datum)}}function R(t){return R="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},R(t)}var A;function I(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function L(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?I(Object(r),!0).forEach(function(e){$(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):I(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function $(t,e,r){return(e=function(t){var e=function(t){if("object"!=R(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=R(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==R(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var F=500,W=function(t){var e=t.GAZETTEER_ENTRY,r="eng"===e.NAME2_LANG?e.NAME2:e.NAME1;return t.GAZETTEER_ENTRY.NAME1=r,t.GAZETTEER_ENTRY.NAME1_LANG="eng",t},U=function(t,e){var r,n,o,i,a=e.MBR_XMIN,s=e.MBR_YMIN,u=e.MBR_XMAX,c=e.MBR_YMAX,l=e.GEOMETRY_X,f=e.GEOMETRY_Y;if(null==a?(r=l-F,n=f-F,o=l+F,i=f+F):(r=a,n=s,o=u,i=c),"EPSG:27700"===t)return[r,n,o,i];if("EPSG:4326"===t){var p=new M(r,n).toLatLon(),d=new M(o,i).toLatLon();return[p.lon,p.lat,d.lon,d.lat].map(function(t){return Math.round(1e6*t)/1e6})}throw new Error("Unsupported CRS: ".concat(t))},B=function(t,e){var r=e.GEOMETRY_X,n=e.GEOMETRY_Y;if("EPSG:27700"===t)return[r,n];if("EPSG:4326"===t){var o=new M(r,n).toLatLon();return[Math.round(1e6*o.lon)/1e6,Math.round(1e6*o.lat)/1e6]}throw new Error("Unsupported CRS: ".concat(t))};function z(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function V(t){return function(t){if(Array.isArray(t))return q(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||H(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Y(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=H(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw i}}}}function H(t,e){if(t){if("string"==typeof t)return q(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?q(t,e):void 0}}function q(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function Z(){var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof s?n:s,c=Object.create(u.prototype);return K(c,"_invoke",function(r,n,o){var i,s,u,c=0,l=o||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,r){return i=e,s=0,u=t,p.n=r,a}};function d(r,n){for(s=r,u=n,e=0;!f&&c&&!o&&e<l.length;e++){var o,i=l[e],d=p.p,h=i[2];r>3?(o=h===n)&&(u=i[(s=i[4])?5:(s=3,3)],i[4]=i[5]=t):i[0]<=d&&((o=r<2&&d<i[1])?(s=0,p.v=n,p.n=i[1]):d<h&&(o=r<3||i[0]>n||n>h)&&(i[4]=r,i[5]=n,p.n=h,s=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,h){if(c>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,h),s=l,u=h;(e=s<2?t:u)||!f;){i||(s?s<3?(s>1&&(p.n=-1),d(s,u)):p.n=u:p.v=u);try{if(c=2,i){if(s||(o="next"),e=i[o]){if(!(e=e.call(i,u)))throw TypeError("iterator result is not an object");if(!e.done)return e;u=e.value,s<2&&(s=0)}else 1===s&&(e=i.return)&&e.call(i),s<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),s=1);i=t}else if((e=(f=p.n<0)?u:r.call(n,p))!==a)break}catch(e){i=t,s=1,u=e}finally{c=1}}return{value:e,done:f}}}(r,o,i),!0),c}var a={};function s(){}function u(){}function c(){}e=Object.getPrototypeOf;var l=[][n]?e(e([][n]())):(K(e={},n,function(){return this}),e),f=c.prototype=s.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,c):(t.__proto__=c,K(t,o,"GeneratorFunction")),t.prototype=Object.create(f),t}return u.prototype=c,K(f,"constructor",c),K(c,"constructor",u),u.displayName="GeneratorFunction",K(c,o,"GeneratorFunction"),K(f),K(f,o,"Generator"),K(f,n,function(){return this}),K(f,"toString",function(){return"[object Generator]"}),(Z=function(){return{w:i,m:p}})()}function K(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}K=function(t,e,r,n){function i(e,r){K(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},K(t,e,r,n)}function X(t,e,r,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}function J(t){return function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function a(t){X(i,n,o,a,s,"next",t)}function s(t){X(i,n,o,a,s,"throw",t)}a(void 0)})}}var Q=function(t){return t.replace(/[^a-zA-Z0-9\s\-.,]/g,"").trim()},tt=function(){var t=J(Z().m(function t(e,r,n){var o,i,a;return Z().w(function(t){for(;;)switch(t.n){case 0:if(i={url:null===(o=e.urlTemplate)||void 0===o?void 0:o.replace("{query}",encodeURIComponent(r)),options:{method:"GET"}},!e.buildRequest){t.n=1;break}return t.a(2,e.buildRequest(r,function(){return i}));case 1:if(!n){t.n=3;break}return t.n=2,n(i,r);case 2:return a=t.v,t.a(2,a);case 3:return t.a(2,i)}},t)}));return function(e,r,n){return t.apply(this,arguments)}}(),et=function(){var t=J(Z().m(function t(e,r,n){var o,i,a;return Z().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,fetch(r);case 1:if((o=t.v).ok){t.n=2;break}return console.error("Fetch error for ".concat(e.label||"dataset",": ").concat(o.status)),t.a(2,null);case 2:return t.n=3,o.json();case 3:return i=t.v,t.a(2,e.parseResults(i,n));case 4:return t.p=4,a=t.v,console.error("Network error for ".concat(e.label||"dataset",":"),a),t.a(2,null)}},t,null,[[0,4]])}));return function(e,r,n){return t.apply(this,arguments)}}(),rt=function(){var t=J(Z().m(function t(e,r,n,o){var i,a,s,u,c,l,f,p,d;return Z().w(function(t){for(;;)switch(t.p=t.n){case 0:i=Q(e),a=r.filter(function(t){var r=!t.includeRegex||t.includeRegex.test(e),n=!!t.excludeRegex&&t.excludeRegex.test(i);return r&&!n}),s=[],u=Y(a),t.p=1,u.s();case 2:if((c=u.n()).done){t.n=6;break}return l=c.value,t.n=3,tt(l,i,o);case 3:return f=t.v,t.n=4,et(l,f,i);case 4:if(null==(p=t.v)||!p.length){t.n=5;break}if(s=[].concat(V(s),V(p)),!l.exclusive){t.n=5;break}return t.a(3,6);case 5:t.n=2;break;case 6:t.n=8;break;case 7:t.p=7,d=t.v,u.e(d);case 8:return t.p=8,u.f(),t.f(8);case 9:return n({type:"UPDATE_SUGGESTIONS",payload:s}),t.a(2,{results:s,sanitisedValue:i})}},t,null,[[1,7,8,9]])}));return function(e,r,n,o){return t.apply(this,arguments)}}();function nt(t){var e=t.mapProvider,r=t.bounds,n=t.point,o=t.markers,i=t.showMarker,a=t.markerColor;e.fitToBounds(r),i&&o.add("search",n,{color:a})}function ot(t){return ot="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ot(t)}function it(){var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof s?n:s,c=Object.create(u.prototype);return at(c,"_invoke",function(r,n,o){var i,s,u,c=0,l=o||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,r){return i=e,s=0,u=t,p.n=r,a}};function d(r,n){for(s=r,u=n,e=0;!f&&c&&!o&&e<l.length;e++){var o,i=l[e],d=p.p,h=i[2];r>3?(o=h===n)&&(u=i[(s=i[4])?5:(s=3,3)],i[4]=i[5]=t):i[0]<=d&&((o=r<2&&d<i[1])?(s=0,p.v=n,p.n=i[1]):d<h&&(o=r<3||i[0]>n||n>h)&&(i[4]=r,i[5]=n,p.n=h,s=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,h){if(c>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,h),s=l,u=h;(e=s<2?t:u)||!f;){i||(s?s<3?(s>1&&(p.n=-1),d(s,u)):p.n=u:p.v=u);try{if(c=2,i){if(s||(o="next"),e=i[o]){if(!(e=e.call(i,u)))throw TypeError("iterator result is not an object");if(!e.done)return e;u=e.value,s<2&&(s=0)}else 1===s&&(e=i.return)&&e.call(i),s<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),s=1);i=t}else if((e=(f=p.n<0)?u:r.call(n,p))!==a)break}catch(e){i=t,s=1,u=e}finally{c=1}}return{value:e,done:f}}}(r,o,i),!0),c}var a={};function s(){}function u(){}function c(){}e=Object.getPrototypeOf;var l=[][n]?e(e([][n]())):(at(e={},n,function(){return this}),e),f=c.prototype=s.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,c):(t.__proto__=c,at(t,o,"GeneratorFunction")),t.prototype=Object.create(f),t}return u.prototype=c,at(f,"constructor",c),at(c,"constructor",u),u.displayName="GeneratorFunction",at(c,o,"GeneratorFunction"),at(f),at(f,o,"Generator"),at(f,n,function(){return this}),at(f,"toString",function(){return"[object Generator]"}),(it=function(){return{w:i,m:p}})()}function at(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}at=function(t,e,r,n){function i(e,r){at(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},at(t,e,r,n)}function st(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function ut(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?st(Object(r),!0).forEach(function(e){ct(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):st(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function ct(t,e,r){return(e=function(t){var e=function(t){if("object"!=ot(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=ot(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ot(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function lt(t,e,r,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}function ft(t){return ft="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ft(t)}function pt(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function dt(t,e,r){return(e=function(t){var e=function(t){if("object"!=ft(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=ft(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ft(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function ht(t){return ht="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ht(t)}function yt(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function mt(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?yt(Object(r),!0).forEach(function(e){bt(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):yt(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function bt(t,e,r){return(e=function(t){var e=function(t){if("object"!=ht(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=ht(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ht(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function gt(t){var e,r,n,o=t.dispatch,i=t.searchContainerRef,a=(e=function(e){return rt(e,t.datasets,o,t.transformRequest)},r=null,n=function(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];clearTimeout(r),r=setTimeout(function(){e.apply(void 0,n)},350)},n.cancel=function(){r&&(clearTimeout(r),r=null)},n),s=function(t){var e=t.dispatch,r=t.services,n=t.viewportRef,o=t.mapProvider,i=t.markers,a=t.datasets,s=t.transformRequest,u=t.showMarker,c=t.markerColor,l="";return{handleOpenClick:function(){e({type:"TOGGLE_EXPANDED",payload:!0}),r.eventBus.emit("search:open")},handleCloseClick:function(t,n){e({type:"TOGGLE_EXPANDED",payload:!1}),e({type:"UPDATE_SUGGESTIONS",payload:[]}),e({type:"SET_VALUE",payload:""}),setTimeout(function(){return n.current.focus()},0),i.remove("search"),r.eventBus.emit("search:clear"),r.eventBus.emit("search:close")},handleSubmit:function(t,f,p){return(d=it().m(function d(){var h,y,m,b,g,v,w,S,E,O,N,T;return it().w(function(d){for(;;)switch(d.n){case 0:if(t.preventDefault(),h=p.suggestions,y=p.selectedIndex,m=p.value,b=null==m?void 0:m.trim(),e({type:"SET_SELECTED",payload:-1}),e({type:"HIDE_SUGGESTIONS"}),!(y>=0)){d.n=1;break}return v=h[y],e({type:"SET_VALUE",payload:v.text}),null===(g=n.current)||void 0===g||g.focus(),nt({mapProvider:o,bounds:v.bounds,point:v.point,markers:i,showMarker:u,markerColor:c}),r.eventBus.emit("search:match",ut({query:v.text},v)),d.a(2);case 1:if(!((null==b?void 0:b.length)<3)){d.n=2;break}return d.a(2);case 2:if(w=h,h.length&&b===l){d.n=4;break}return d.n=3,rt(b,a,e,s);case 3:S=d.v,E=S.results,O=S.sanitisedValue,w=E,l=O;case 4:w.length&&("keyboard"===f.interfaceType&&(null===(N=n.current)||void 0===N||N.focus()),"mobile"===f.breakpoint&&(e({type:"TOGGLE_EXPANDED",payload:!1}),r.eventBus.emit("search:close")),T=w[0],nt({mapProvider:o,bounds:T.bounds,point:T.point,markers:i,showMarker:u,markerColor:c}),r.eventBus.emit("search:match",ut({query:m},T)));case 5:return d.a(2)}},d)}),function(){var t=this,e=arguments;return new Promise(function(r,n){var o=d.apply(t,e);function i(t){lt(o,r,n,i,a,"next",t)}function a(t){lt(o,r,n,i,a,"throw",t)}i(void 0)})})();var d}}}(t),u=function(t){var e=t.dispatch,r=t.debouncedFetchSuggestions;return{handleInputClick:function(){e({type:"SHOW_SUGGESTIONS"})},handleInputFocus:function(t){e({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:"keyboard"===t})},handleInputBlur:function(t){e({type:"INPUT_BLUR",payload:t})},handleInputChange:function(t){var n=t.target.value;if(e({type:"SET_VALUE",payload:n}),n.length<3)return r.cancel(),e({type:"UPDATE_SUGGESTIONS",payload:[]}),void e({type:"HIDE_SUGGESTIONS"});e({type:"SHOW_SUGGESTIONS"}),r(n)}}}(mt(mt({},t),{},{debouncedFetchSuggestions:a})),c=function(t){var e=t.dispatch,r=t.services,n=t.mapProvider,o=t.markers,i=t.showMarker,a=t.markerColor,s=function(t,e){var r;return e>=0?"".concat(null===(r=t[e])||void 0===r?void 0:r.text,". ").concat(e+1," of ").concat(t.length," is highlighted"):"".concat(t.length," suggestions available")};return{handleSuggestionClick:function(t,s){e({type:"SET_VALUE",payload:t.text}),e({type:"HIDE_SUGGESTIONS"}),e({type:"SET_SELECTED",payload:-1}),"mobile"===s.breakpoint&&(e({type:"TOGGLE_EXPANDED",payload:!1}),r.eventBus.emit("search:close")),nt({mapProvider:n,bounds:t.bounds,point:t.point,markers:o,showMarker:i,markerColor:a}),r.eventBus.emit("search:match",function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?pt(Object(r),!0).forEach(function(e){dt(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):pt(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}({query:t.text},t))},handleInputKeyDown:function(t,n){var o=n.suggestions,i=n.selectedIndex;switch(t.key){case"ArrowDown":if(null==o||!o.length)return;if(t.preventDefault(),i<o.length-1){var a=i+1;r.announce(s(o,a)),e({type:"SET_SELECTED",payload:a}),e({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:!1})}break;case"ArrowUp":if(null==o||!o.length)return;t.preventDefault();var u=i>0?i-1:-1;r.announce(s(o,u)),e({type:"SET_SELECTED",payload:u}),e({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:u<0});break;case"Escape":t.preventDefault(),e({type:"HIDE_SUGGESTIONS"}),e({type:"SET_SELECTED",payload:-1})}}}}(t);return mt(mt(mt(mt({},s),u),c),{},{handleOutside:function(e){i.current.contains(e.target)||(o({type:"TOGGLE_EXPANDED",payload:!1}),t.services.eventBus.emit("search:close"))}})}function vt(t){return vt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},vt(t)}function wt(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function St(t,e,r){return(e=function(t){var e=function(t){if("object"!=vt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=vt(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==vt(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var Et={reducer:{initialState:{isExpanded:!1,hasKeyboardFocusWithin:!1,value:"",suggestions:[],areSuggestionsVisible:!1,hasFetchedSuggestions:!1,selectedIndex:-1},actions:s},controls:[{id:"search",mobile:{slot:"top-right",showLabel:!1},tablet:{slot:"top-left",showLabel:!1},desktop:{slot:"top-left",showLabel:!1},render:function(t){var e,r=t.appConfig,n=t.iconRegistry,o=t.pluginState,i=t.pluginConfig,a=t.appState,s=t.mapState,f=t.services,p=t.mapProvider,d=r.id,h=a.interfaceType,y=i.expanded,v=i.customDatasets,w=i.osNamesURL,S=i.regions,E=o.dispatch,O=o.isExpanded,N=o.areSuggestionsVisible,T=o.suggestions,j=(null==a||null===(e=a.controlConfig)||void 0===e||null===(e=e.search)||void 0===e?void 0:e[null==a?void 0:a.breakpoint].showLabel)||!1,_=n.close,x=n.search,P=(0,u.useRef)(null),k=(0,u.useRef)(null),G=(0,u.useRef)(null),D=a.layoutRefs.viewportRef,M=function(t){var e,r=t.customDatasets,n=void 0===r?[]:r,o=t.osNamesURL,i=t.crs,a=t.regions,s=void 0===a?["england","scotland","wales"]:a;return o?[].concat([{name:"osNames",urlTemplate:o,parseResults:function(t,e){return function(t,e,r,n){var o;if(!t||t.error||0===(null===(o=t.header)||void 0===o?void 0:o.totalresults))return[];var i=t.results;return i=function(t,e){var r=e.toLowerCase().replace(/,/g,"").split(" ");return t.map(W).filter(function(t){return r.some(function(r){return t.GAZETTEER_ENTRY.NAME1.toLowerCase().includes(r)||(n=(n=e).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,e),i=function(t,e){return t.filter(function(t){var r,n=null==t||null===(r=t.GAZETTEER_ENTRY)||void 0===r||null===(r=r.COUNTRY)||void 0===r?void 0:r.toLowerCase();return n&&e.includes(n)})}(i=function(t){return Array.from(new Map(t.map(function(t){return[t.GAZETTEER_ENTRY.ID,t]})).values())}(i),r),(i=i.slice(0,8)).map(function(t){return L(L({id:t.GAZETTEER_ENTRY.ID,bounds:U(n,t.GAZETTEER_ENTRY),point:B(n,t.GAZETTEER_ENTRY)},function(t,e){var r,n,o,i,a,s,u=e.NAME1,c=e.COUNTY_UNITARY,l=e.DISTRICT_BOROUGH,f=e.POSTCODE_DISTRICT,p=e.LOCAL_TYPE,d="".concat(["City","Postcode"].includes(p)?"":f+", ").concat("City"===p?"":c||l),h="".concat(u).concat(d?", "+d:"");return{text:h,marked:(r=h,n=t,a=n.replace(/\s+/g,"").split("").join(String.raw(A||(o=["s*"],(i=["\\s*"])||(i=o.slice(0)),A=Object.freeze(Object.defineProperties(o,{raw:{value:Object.freeze(i)}}))))),s=new RegExp("(".concat(a,")"),"i"),r.replace(s,"<mark>$1</mark>"))}}(e,t.GAZETTEER_ENTRY)),{},{type:"os-names"})})}(t,e,s,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}],function(t){if(Array.isArray(t))return z(t)}(e=n)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(e)||function(t,e){if(t){if("string"==typeof t)return z(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?z(t,e):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()):n}({customDatasets:v,osNamesURL:w,regions:S,crs:p.crs}),C=(0,u.useRef)(null);C.current||(C.current=gt(function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?wt(Object(r),!0).forEach(function(e){St(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):wt(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}({dispatch:E,datasets:M,services:f,mapProvider:p,viewportRef:D,searchContainerRef:P,markers:s.markers},i)));var R=C.current,I=O||!!(y&&N&&T.length);return(0,u.useEffect)(function(){var t;O&&(null===(t=G.current)||void 0===t||t.focus())},[O]),(0,u.useEffect)(function(){if(a.dispatch({type:"TOGGLE_HAS_EXCLUSIVE_CONTROL",payload:O}),I)return D.current.style.pointerEvents="none",document.addEventListener("focusin",R.handleOutside),document.addEventListener("pointerdown",R.handleOutside),function(){D.current.style.pointerEvents="auto",document.removeEventListener("focusin",R.handleOutside),document.removeEventListener("pointerdown",R.handleOutside)}},[O,h,N,T]),(0,c.jsxs)("div",{className:"im-c-search",ref:P,children:[!y&&(0,c.jsx)(l,{id:d,isExpanded:O,onClick:function(){return R.handleOpenClick(a)},buttonRef:k,searchIcon:x,showLabel:j}),(0,c.jsxs)(m,{id:d,pluginState:o,pluginConfig:i,appState:a,inputRef:G,events:R,services:f,children:[(0,c.jsx)(b,{defaultExpanded:y,onClick:function(t){return R.handleCloseClick(t,k,a)},closeIcon:_}),(0,c.jsx)(g,{defaultExpanded:y,onClick:function(t){return R.handleCloseClick(t,k,a)},submitIcon:x})]})]})}}],icons:[{id:"search",svgContent:'<path d="m21 21-4.34-4.34"></path><circle cx="11" cy="11" r="8"></circle>'}]}}}]);
|
|
2
|
+
"use strict";(this.webpackChunkdefra_DefraMap=this.webpackChunkdefra_DefraMap||[]).push([[254],{335(t,e,r){function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function i(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?o(Object(r),!0).forEach(function(e){a(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function a(t,e,r){return(e=function(t){var e=function(t){if("object"!=n(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==n(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}r.r(e),r.d(e,{manifest:()=>Nt});var s={TOGGLE_EXPANDED:function(t,e){return i(i({},t),{},{isExpanded:e,areSuggestionsVisible:e,hasFetchedSuggestions:!1})},SET_KEYBOARD_FOCUS_WITHIN:function(t,e){return i(i({},t),{},{hasKeyboardFocusWithin:e,areSuggestionsVisible:!0})},INPUT_BLUR:function(t,e){return i(i({},t),{},{hasKeyboardFocusWithin:!1,areSuggestionsVisible:t.areSuggestionsVisible&&"keyboard"!==e,selectedIndex:-1})},SET_VALUE:function(t,e){return i(i({},t),{},{value:e})},UPDATE_SUGGESTIONS:function(t,e){return i(i({},t),{},{suggestions:e,hasFetchedSuggestions:!0})},SHOW_SUGGESTIONS:function(t){return i(i({},t),{},{areSuggestionsVisible:!0,hasFetchedSuggestions:!1})},HIDE_SUGGESTIONS:function(t){return i(i({},t),{},{areSuggestionsVisible:!1,hasFetchedSuggestions:!1})},SET_SELECTED:function(t,e){return i(i({},t),{},{selectedIndex:e,areSuggestionsVisible:e>=0})}},u=r(738),c=r(287),l=function(t){var e=t.id,r=t.isExpanded,n=t.onClick,o=t.buttonRef,i=t.searchIcon,a=t.showLabel;return(0,c.jsxs)("button",{"aria-label":"Open search",className:"im-c-map-button",onClick:n,"aria-controls":"".concat(e,"-search-form"),ref:o,style:r?{display:"none"}:void 0,children:[i&&(0,c.jsx)("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:i}}),a&&(0,c.jsx)("span",{children:"Search"})]})},f=function(t){var e=t.id,r=t.pluginState,n=t.handleSuggestionClick;return(0,c.jsx)("ul",{id:"".concat(e,"-search-suggestions"),role:"listbox","aria-labelledby":"".concat(e,"-search"),className:"im-c-search-suggestions",style:r.areSuggestionsVisible&&r.suggestions.length?void 0:{display:"none"},children:r.suggestions.map(function(t,o){return(0,c.jsx)("li",{id:"".concat(e,"-search-suggestion-").concat(o),className:"im-c-search-suggestions__item",role:"option","aria-selected":r.selectedIndex===o,"aria-setsize":r.suggestions.length,"aria-posinset":o+1,onClick:function(){return n(t)},children:(0,c.jsx)("span",{className:"im-c-search-suggestions__label",dangerouslySetInnerHTML:{__html:t.marked}})},t.id)})})};function p(t){return p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},p(t)}function d(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function h(t,e,r){return(e=function(t){var e=function(t){if("object"!=p(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=p(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==p(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var y=function(t,e,r){return function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?d(Object(r),!0).forEach(function(e){h(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}({display:t.expanded||e.isExpanded?"flex":void 0},"mobile"!==r.breakpoint&&(null==t?void 0:t.width)&&{width:t.width})},m=function(t){var e=t.id,r=t.pluginState,n=t.pluginConfig,o=t.appState,i=t.inputRef,a=t.events,s=t.services,l=t.children,p=r.areSuggestionsVisible,d=r.hasFetchedSuggestions,h=r.suggestions,m=void 0===h?[]:h;(0,u.useEffect)(function(){p&&d&&s.announce(function(t){if(0===t)return"No results available";var e=1===t?"result":"results";return"".concat(t," ").concat(e," available")}(m.length))},[m,d]);var b=["im-c-search-form",n.expanded&&"im-c-search-form--default-expanded","im-c-panel"].filter(Boolean).join(" "),g=p&&d&&!m.length;return(0,c.jsxs)("form",{id:"".concat(e,"-search-form"),role:"search",className:b,style:y(n,r,o),"aria-controls":"".concat(e,"-viewport"),onSubmit:function(t){return a.handleSubmit(t,o,r)},children:[(0,c.jsx)("button",{type:"submit",style:{display:"none"},"aria-hidden":"true",tabIndex:-1,children:"Submit"}),(0,c.jsxs)("div",{className:"im-c-search__input-container".concat(r.hasKeyboardFocusWithin?" im-c-search__input-container--keyboard-focus-within":""),children:[(0,c.jsx)("label",{htmlFor:"".concat(e,"-search"),className:"im-u-visually-hidden",children:n.placeholder}),(0,c.jsx)("input",{id:"".concat(e,"-search"),className:"im-c-search__input",type:"search",role:"combobox","aria-expanded":r.suggestionsVisible,"aria-controls":"".concat(e,"-search-suggestions"),"aria-activedescendant":r.selectedIndex>=0?"".concat(e,"-search-suggestion-").concat(r.selectedIndex):void 0,"aria-describedby":r.value?void 0:"".concat(e,"-search-hint"),"aria-autocomplete":"list",autoComplete:"off",placeholder:n.placeholder,name:"".concat(e,"-search"),spellCheck:!1,enterKeyHint:"search",value:r.value,onClick:a.handleInputClick,onChange:a.handleInputChange,onFocus:function(){return a.handleInputFocus(o.interfaceType)},onBlur:function(){return a.handleInputBlur(o.interfaceType)},onKeyDown:function(t){return a.handleInputKeyDown(t,r)},ref:i}),(0,c.jsx)("span",{id:"".concat(e,"-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."}),l]}),g&&(0,c.jsx)("div",{className:"im-c-search__status","aria-hidden":"true",children:"No results available"}),(0,c.jsx)(f,{id:e,appState:o,pluginState:r,handleSuggestionClick:function(t){return a.handleSuggestionClick(t,o)}})]})},b=function(t){var e=t.defaultExpanded,r=t.onClick,n=t.closeIcon;return(0,c.jsx)("button",{"aria-label":"Close search",className:"im-c-map-button im-c-search-close-button",type:"button",onClick:r,style:e?{display:"none"}:void 0,children:n&&(0,c.jsx)("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:n}})})},g=function(t){var e=t.defaultExpanded,r=t.submitIcon;return(0,c.jsx)("button",{"aria-label":"Search",className:"im-c-map-button im-c-search-submit-button",type:"submit",style:e?void 0:{display:"none"},children:r&&(0,c.jsx)("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(t){v=t}static parse(t){if(!isNaN(parseFloat(t))&&isFinite(t))return Number(t);const e=String(t).trim().replace(/^-/,"").replace(/[NSEW]$/i,"").split(/[^0-9.,]+/);if(""==e[e.length-1]&&e.splice(e.length-1),""==e)return NaN;let r=null;switch(e.length){case 3:r=e[0]/1+e[1]/60+e[2]/3600;break;case 2:r=e[0]/1+e[1]/60;break;case 1:r=e[0];break;default:return NaN}return/^-|[WS]$/i.test(t.trim())&&(r=-r),Number(r)}static toDms(t,e="d",r=void 0){if(isNaN(t))return null;if("string"==typeof t&&""==t.trim())return null;if("boolean"==typeof t)return null;if(t==1/0)return null;if(null==t)return null;if(void 0===r)switch(e){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:e="d",r=4}t=Math.abs(t);let n=null,o=null,i=null,a=null;switch(e){default:case"d":case"deg":o=t.toFixed(r),o<100&&(o="0"+o),o<10&&(o="0"+o),n=o+"°";break;case"dm":case"deg+min":o=Math.floor(t),i=(60*t%60).toFixed(r),60==i&&(i=(0).toFixed(r),o++),o=("000"+o).slice(-3),i<10&&(i="0"+i),n=o+"°"+w.separator+i+"′";break;case"dms":case"deg+min+sec":o=Math.floor(t),i=Math.floor(3600*t/60)%60,a=(3600*t%60).toFixed(r),60==a&&(a=(0).toFixed(r),i++),60==i&&(i=0,o++),o=("000"+o).slice(-3),i=("00"+i).slice(-2),a<10&&(a="0"+a),n=o+"°"+w.separator+i+"′"+w.separator+a+"″"}return n}static toLat(t,e,r){const n=w.toDms(w.wrap90(t),e,r);return null===n?"–":n.slice(1)+w.separator+(t<0?"S":"N")}static toLon(t,e,r){const n=w.toDms(w.wrap180(t),e,r);return null===n?"–":n+w.separator+(t<0?"W":"E")}static toBrng(t,e,r){const n=w.toDms(w.wrap360(t),e,r);return null===n?"–":n.replace("360","0")}static fromLocale(t){const e=123456.789.toLocaleString(),r={thousands:e.slice(3,4),decimal:e.slice(7,8)};return t.replace(r.thousands,"⁜").replace(r.decimal,".").replace("⁜",",")}static toLocale(t){const e=123456.789.toLocaleString(),r={thousands:e.slice(3,4),decimal:e.slice(7,8)};return t.replace(/,([0-9])/,"⁜$1").replace(".",r.decimal).replace("⁜",r.thousands)}static compassPoint(t,e=3){if(![1,2,3].includes(Number(e)))throw new RangeError(`invalid precision ‘${e}’`);t=w.wrap360(t);const r=4*2**(e-1);return["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"][Math.round(t*r/360)%r*16/r]}static wrap90(t){if(-90<=t&&t<=90)return t;const e=t;return 1*Math.abs(((e-90)%360+360)%360-180)-90}static wrap180(t){if(-180<=t&&t<=180)return t;const e=360;return((360*t/e-180)%e+e)%e-180}static wrap360(t){if(0<=t&&t<360)return t;const e=360;return(360*t/e%e+e)%e}}Number.prototype.toRadians=function(){return this*Math.PI/180},Number.prototype.toDegrees=function(){return 180*this/Math.PI};const S=w;class E{constructor(t,e,r){if(isNaN(t)||isNaN(e)||isNaN(r))throw new TypeError(`invalid vector [${t},${e},${r}]`);this.x=Number(t),this.y=Number(e),this.z=Number(r)}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}plus(t){if(!(t instanceof E))throw new TypeError("v is not Vector3d object");return new E(this.x+t.x,this.y+t.y,this.z+t.z)}minus(t){if(!(t instanceof E))throw new TypeError("v is not Vector3d object");return new E(this.x-t.x,this.y-t.y,this.z-t.z)}times(t){if(isNaN(t))throw new TypeError(`invalid scalar value ‘${t}’`);return new E(this.x*t,this.y*t,this.z*t)}dividedBy(t){if(isNaN(t))throw new TypeError(`invalid scalar value ‘${t}’`);return new E(this.x/t,this.y/t,this.z/t)}dot(t){if(!(t instanceof E))throw new TypeError("v is not Vector3d object");return this.x*t.x+this.y*t.y+this.z*t.z}cross(t){if(!(t instanceof E))throw new TypeError("v is not Vector3d object");const e=this.y*t.z-this.z*t.y,r=this.z*t.x-this.x*t.z,n=this.x*t.y-this.y*t.x;return new E(e,r,n)}negate(){return new E(-this.x,-this.y,-this.z)}unit(){const t=this.length;if(1==t)return this;if(0==t)return this;const e=this.x/t,r=this.y/t,n=this.z/t;return new E(e,r,n)}angleTo(t,e=void 0){if(!(t instanceof E))throw new TypeError("v is not Vector3d object");if(!(e instanceof E||null==e))throw new TypeError("n is not Vector3d object");const r=null==e||this.cross(t).dot(e)>=0?1:-1,n=this.cross(t).length*r,o=this.dot(t);return Math.atan2(n,o)}rotateAround(t,e){if(!(t instanceof E))throw new TypeError("axis is not Vector3d object");const r=e.toRadians(),n=this.unit(),o=t.unit(),i=Math.sin(r),a=Math.cos(r),s=1-a,u=o.x,c=o.y,l=o.z,f=[[s*u*u+a,s*u*c-i*l,s*u*l+i*c],[s*u*c+i*l,s*c*c+a,s*c*l-i*u],[s*u*l-i*c,s*c*l+i*u,s*l*l+a]],p=[f[0][0]*n.x+f[0][1]*n.y+f[0][2]*n.z,f[1][0]*n.x+f[1][1]*n.y+f[1][2]*n.z,f[2][0]*n.x+f[2][1]*n.y+f[2][2]*n.z];return new E(p[0],p[1],p[2])}toString(t=3){return`[${this.x.toFixed(t)},${this.y.toFixed(t)},${this.z.toFixed(t)}]`}}Number.prototype.toRadians=function(){return this*Math.PI/180},Number.prototype.toDegrees=function(){return 180*this/Math.PI};const O=E,N={WGS84:{a:6378137,b:6356752.314245,f:1/298.257223563}},T={WGS84:{ellipsoid:N.WGS84}};Object.freeze(N.WGS84),Object.freeze(T.WGS84);class j{constructor(t,e,r=0){if(isNaN(t)||null==t)throw new TypeError(`invalid lat ‘${t}’`);if(isNaN(e)||null==e)throw new TypeError(`invalid lon ‘${e}’`);if(isNaN(r)||null==r)throw new TypeError(`invalid height ‘${r}’`);this._lat=S.wrap90(Number(t)),this._lon=S.wrap180(Number(e)),this._height=Number(r)}get lat(){return this._lat}get latitude(){return this._lat}set lat(t){if(this._lat=isNaN(t)?S.wrap90(S.parse(t)):S.wrap90(Number(t)),isNaN(this._lat))throw new TypeError(`invalid lat ‘${t}’`)}set latitude(t){if(this._lat=isNaN(t)?S.wrap90(S.parse(t)):S.wrap90(Number(t)),isNaN(this._lat))throw new TypeError(`invalid latitude ‘${t}’`)}get lon(){return this._lon}get lng(){return this._lon}get longitude(){return this._lon}set lon(t){if(this._lon=isNaN(t)?S.wrap180(S.parse(t)):S.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid lon ‘${t}’`)}set lng(t){if(this._lon=isNaN(t)?S.wrap180(S.parse(t)):S.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid lng ‘${t}’`)}set longitude(t){if(this._lon=isNaN(t)?S.wrap180(S.parse(t)):S.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid longitude ‘${t}’`)}get height(){return this._height}set height(t){if(this._height=Number(t),isNaN(this._height))throw new TypeError(`invalid height ‘${t}’`)}get datum(){return this._datum}set datum(t){this._datum=t}static get ellipsoids(){return N}static get datums(){return T}static parse(...t){if(0==t.length)throw new TypeError("invalid (empty) point");let e,r,n;if("object"==typeof t[0]&&(1==t.length||!isNaN(parseFloat(t[1])))){const o=t[0];if("Point"==o.type&&Array.isArray(o.coordinates)?([r,e,n]=o.coordinates,n=n||0):(null!=o.latitude&&(e=o.latitude),null!=o.lat&&(e=o.lat),null!=o.longitude&&(r=o.longitude),null!=o.lng&&(r=o.lng),null!=o.lon&&(r=o.lon),null!=o.height&&(n=o.height),e=S.wrap90(S.parse(e)),r=S.wrap180(S.parse(r))),null!=t[1]&&(n=t[1]),isNaN(e)||isNaN(r))throw new TypeError(`invalid point ‘${JSON.stringify(t[0])}’`)}if("string"==typeof t[0]&&2==t[0].split(",").length&&([e,r]=t[0].split(","),e=S.wrap90(S.parse(e)),r=S.wrap180(S.parse(r)),n=t[1]||0,isNaN(e)||isNaN(r)))throw new TypeError(`invalid point ‘${t[0]}’`);if(null==e&&null==r&&([e,r]=t,e=S.wrap90(S.parse(e)),r=S.wrap180(S.parse(r)),n=t[2]||0,isNaN(e)||isNaN(r)))throw new TypeError(`invalid point ‘${t.toString()}’`);return new this(e,r,n)}toCartesian(){const t=this.datum?this.datum.ellipsoid:this.referenceFrame?this.referenceFrame.ellipsoid:N.WGS84,e=this.lat.toRadians(),r=this.lon.toRadians(),n=this.height,{a:o,f:i}=t,a=Math.sin(e),s=Math.cos(e),u=Math.sin(r),c=Math.cos(r),l=2*i-i*i,f=o/Math.sqrt(1-l*a*a);return new _((f+n)*s*c,(f+n)*s*u,(f*(1-l)+n)*a)}equals(t){if(!(t instanceof j))throw new TypeError(`invalid point ‘${t}’`);return!(Math.abs(this.lat-t.lat)>Number.EPSILON||Math.abs(this.lon-t.lon)>Number.EPSILON||Math.abs(this.height-t.height)>Number.EPSILON||this.datum!=t.datum||this.referenceFrame!=t.referenceFrame||this.epoch!=t.epoch)}toString(t="d",e=void 0,r=null){if(!["d","dm","dms","n"].includes(t))throw new RangeError(`invalid format ‘${t}’`);const n=(this.height>=0?" +":" ")+this.height.toFixed(r)+"m";return"n"==t?(null==e&&(e=4),`${this.lat.toFixed(e)}, ${this.lon.toFixed(e)}${null==r?"":n}`):`${S.toLat(this.lat,t,e)}, ${S.toLon(this.lon,t,e)}${null==r?"":n}`}}class _ extends O{constructor(t,e,r){super(t,e,r)}toLatLon(t=N.WGS84){if(!t||!t.a)throw new TypeError(`invalid ellipsoid ‘${t}’`);const{x:e,y:r,z:n}=this,{a:o,b:i,f:a}=t,s=2*a-a*a,u=s/(1-s),c=Math.sqrt(e*e+r*r),l=i*n/(o*c)*(1+u*i/Math.sqrt(c*c+n*n)),f=l/Math.sqrt(1+l*l),p=f/l,d=isNaN(p)?0:Math.atan2(n+u*i*f*f*f,c-s*o*p*p*p),h=Math.atan2(r,e),y=Math.sin(d),m=c*Math.cos(d)+n*y-o*o/(o/Math.sqrt(1-s*y*y));return new j(d.toDegrees(),h.toDegrees(),m)}toString(t=0){return`[${this.x.toFixed(t)},${this.y.toFixed(t)},${this.z.toFixed(t)}]`}}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}},P={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(t=>Object.freeze(x[t])),Object.keys(P).forEach(t=>{Object.freeze(P[t]),Object.freeze(P[t].transform)});class k extends j{constructor(t,e,r=0,n=P.WGS84){if(!n||null==n.ellipsoid)throw new TypeError(`unrecognised datum ‘${n}’`);super(t,e,r),this._datum=n}get datum(){return this._datum}static get ellipsoids(){return x}static get datums(){return P}static parse(...t){let e=P.WGS84;if((4==t.length||3==t.length&&"object"==typeof t[2])&&(e=t.pop()),!e||null==e.ellipsoid)throw new TypeError(`unrecognised datum ‘${e}’`);const r=super.parse(...t);return r._datum=e,r}convertDatum(t){if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);return this.toCartesian().convertDatum(t).toLatLon()}toCartesian(){const t=super.toCartesian();return new G(t.x,t.y,t.z,this.datum)}}class G extends _{constructor(t,e,r,n=void 0){if(n&&null==n.ellipsoid)throw new TypeError(`unrecognised datum ‘${n}’`);super(t,e,r),n&&(this._datum=n)}get datum(){return this._datum}set datum(t){if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);this._datum=t}toLatLon(t=void 0){t&&(console.info("datum parameter to Cartesian_Datum.toLatLon is deprecated: set datum before calling toLatLon()"),this.datum=t);const e=this.datum||P.WGS84;if(!e||null==e.ellipsoid)throw new TypeError(`unrecognised datum ‘${e}’`);const r=super.toLatLon(e.ellipsoid);return new k(r.lat,r.lon,r.height,this.datum)}convertDatum(t){if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);if(!this.datum)throw new TypeError("cartesian coordinate has no datum");let e=null,r=null;null!=this.datum&&this.datum!=P.WGS84||(e=this,r=t.transform),t==P.WGS84&&(e=this,r=this.datum.transform.map(t=>-t)),null==r&&(e=this.convertDatum(P.WGS84),r=t.transform);const n=e.applyTransform(r);return n.datum=t,n}applyTransform(t){const{x:e,y:r,z:n}=this,o=t[0],i=t[1],a=t[2],s=t[3]/1e6+1,u=(t[4]/3600).toRadians(),c=(t[5]/3600).toRadians(),l=(t[6]/3600).toRadians();return new G(o+e*s-r*l+n*c,i+e*l+r*s-n*u,a-e*c+r*u+n*s)}}const D={trueOrigin:{lat:49,lon:-2},falseOrigin:{easting:-4e5,northing:1e5},scaleFactor:.9996012717,ellipsoid:k.ellipsoids.Airy1830};class M{constructor(t,e){if(this.easting=Number(t),this.northing=Number(e),isNaN(t)||this.easting<0||this.easting>7e5)throw new RangeError(`invalid easting ‘${t}’`);if(isNaN(e)||this.northing<0||this.northing>13e5)throw new RangeError(`invalid northing ‘${e}’`)}toLatLon(t=k.datums.WGS84){const{easting:e,northing:r}=this,{a:n,b:o}=D.ellipsoid,i=D.trueOrigin.lat.toRadians(),a=D.trueOrigin.lon.toRadians(),s=-D.falseOrigin.easting,u=-D.falseOrigin.northing,c=D.scaleFactor,l=1-o*o/(n*n),f=(n-o)/(n+o),p=f*f,d=f*f*f;let h=i,y=0;do{h=(r-u-y)/(n*c)+h,y=o*c*((1+f+5/4*p+5/4*d)*(h-i)-(3*f+3*f*f+21/8*d)*Math.sin(h-i)*Math.cos(h+i)+(15/8*p+15/8*d)*Math.sin(2*(h-i))*Math.cos(2*(h+i))-35/24*d*Math.sin(3*(h-i))*Math.cos(3*(h+i)))}while(Math.abs(r-u-y)>=1e-5);const m=Math.cos(h),b=Math.sin(h),g=n*c/Math.sqrt(1-l*b*b),v=n*c*(1-l)/Math.pow(1-l*b*b,1.5),w=g/v-1,S=Math.tan(h),E=S*S,O=E*E,N=1/m,T=g*g*g,j=T*g*g,_=e-s,x=_*_,P=x*_,G=x*x,M=P*x;h=h-S/(2*v*g)*x+S/(24*v*T)*(5+3*E+w-9*E*w)*G-S/(720*v*j)*(61+90*E+45*O)*(G*x);const A=a+N/g*_-N/(6*T)*(g/v+2*E)*P+N/(120*j)*(5+28*E+24*O)*M-N/(j*g*g*5040)*(61+662*E+1320*O+O*E*720)*(M*x);let C=new R(h.toDegrees(),A.toDegrees(),0,k.datums.OSGB36);return t!=k.datums.OSGB36&&(C=C.convertDatum(t),C=new R(C.lat,C.lon,C.height,C.datum)),C}static parse(t){let e=(t=String(t).trim()).match(/^(\d+),\s*(\d+)$/);if(e)return new M(e[1],e[2]);if(e=t.match(/^[HNST][ABCDEFGHJKLMNOPQRSTUVWXYZ]\s*[0-9]+\s*[0-9]+$/i),!e)throw new Error(`invalid grid reference ‘${t}’`);let r=t.toUpperCase().charCodeAt(0)-"A".charCodeAt(0),n=t.toUpperCase().charCodeAt(1)-"A".charCodeAt(0);r>7&&r--,n>7&&n--;const o=(r-2)%5*5+n%5,i=19-5*Math.floor(r/5)-Math.floor(n/5);let a=t.slice(2).trim().split(/\s+/);if(1==a.length&&(a=[a[0].slice(0,a[0].length/2),a[0].slice(a[0].length/2)]),a[0].length!=a[1].length)throw new Error(`invalid grid reference ‘${t}’`);a[0]=a[0].padEnd(5,"0"),a[1]=a[1].padEnd(5,"0");const s=o+a[0],u=i+a[1];return new M(s,u)}toString(t=10){if(![0,2,4,6,8,10,12,14,16].includes(Number(t)))throw new RangeError(`invalid precision ‘${t}’`);let{easting:e,northing:r}=this;if(0==t){const t={useGrouping:!1,minimumIntegerDigits:6,maximumFractionDigits:3};return`${e.toLocaleString("en",t)},${r.toLocaleString("en",t)}`}const n=Math.floor(e/1e5),o=Math.floor(r/1e5);let i=19-o-(19-o)%5+Math.floor((n+10)/5),a=5*(19-o)%25+n%5;i>7&&i++,a>7&&a++;const s=String.fromCharCode(i+"A".charCodeAt(0),a+"A".charCodeAt(0));return e=Math.floor(e%1e5/Math.pow(10,5-t/2)),r=Math.floor(r%1e5/Math.pow(10,5-t/2)),e=e.toString().padStart(t/2,"0"),r=r.toString().padStart(t/2,"0"),`${s} ${e} ${r}`}}class R extends k{toOsGrid(){const t=this.datum==k.datums.OSGB36?this:this.convertDatum(k.datums.OSGB36),e=t.lat.toRadians(),r=t.lon.toRadians(),{a:n,b:o}=D.ellipsoid,i=D.trueOrigin.lat.toRadians(),a=D.trueOrigin.lon.toRadians(),s=-D.falseOrigin.easting,u=-D.falseOrigin.northing,c=D.scaleFactor,l=1-o*o/(n*n),f=(n-o)/(n+o),p=f*f,d=f*f*f,h=Math.cos(e),y=Math.sin(e),m=n*c/Math.sqrt(1-l*y*y),b=n*c*(1-l)/Math.pow(1-l*y*y,1.5),g=m/b-1,v=o*c*((1+f+5/4*p+5/4*d)*(e-i)-(3*f+3*f*f+21/8*d)*Math.sin(e-i)*Math.cos(e+i)+(15/8*p+15/8*d)*Math.sin(2*(e-i))*Math.cos(2*(e+i))-35/24*d*Math.sin(3*(e-i))*Math.cos(3*(e+i))),w=h*h*h,S=w*h*h,E=Math.tan(e)*Math.tan(e),O=E*E,N=r-a,T=N*N,j=T*N,_=j*N,x=_*N;let P=v+u+m/2*y*h*T+m/24*y*w*(5-E+9*g)*_+m/720*y*S*(61-58*E+O)*(x*N),G=s+m*h*N+m/6*w*(m/b-E)*j+m/120*S*(5-18*E+O+14*g-58*E*g)*x;P=Number(P.toFixed(3)),G=Number(G.toFixed(3));try{return new M(G,P)}catch(e){throw new Error(`${e.message} from (${t.lat.toFixed(6)},${t.lon.toFixed(6)}).toOsGrid()`)}}convertDatum(t){const e=super.convertDatum(t);return new R(e.lat,e.lon,e.height,e.datum)}}function A(t){return A="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},A(t)}var C;function I(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function L(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?I(Object(r),!0).forEach(function(e){$(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):I(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function $(t,e,r){return(e=function(t){var e=function(t){if("object"!=A(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=A(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==A(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var F=500,W=function(t){var e=t.GAZETTEER_ENTRY,r="eng"===e.NAME2_LANG?e.NAME2:e.NAME1;return t.GAZETTEER_ENTRY.NAME1=r,t.GAZETTEER_ENTRY.NAME1_LANG="eng",t},U=function(t,e){var r,n,o,i,a=e.MBR_XMIN,s=e.MBR_YMIN,u=e.MBR_XMAX,c=e.MBR_YMAX,l=e.GEOMETRY_X,f=e.GEOMETRY_Y;if(null==a?(r=l-F,n=f-F,o=l+F,i=f+F):(r=a,n=s,o=u,i=c),"EPSG:27700"===t)return[r,n,o,i];if("EPSG:4326"===t){var p=new M(r,n).toLatLon(),d=new M(o,i).toLatLon();return[p.lon,p.lat,d.lon,d.lat].map(function(t){return Math.round(1e6*t)/1e6})}throw new Error("Unsupported CRS: ".concat(t))},B=function(t,e){var r=e.GEOMETRY_X,n=e.GEOMETRY_Y;if("EPSG:27700"===t)return[r,n];if("EPSG:4326"===t){var o=new M(r,n).toLatLon();return[Math.round(1e6*o.lon)/1e6,Math.round(1e6*o.lat)/1e6]}throw new Error("Unsupported CRS: ".concat(t))};function z(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function V(t){return function(t){if(Array.isArray(t))return q(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||H(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Y(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=H(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw i}}}}function H(t,e){if(t){if("string"==typeof t)return q(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?q(t,e):void 0}}function q(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function Z(){var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof s?n:s,c=Object.create(u.prototype);return K(c,"_invoke",function(r,n,o){var i,s,u,c=0,l=o||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,r){return i=e,s=0,u=t,p.n=r,a}};function d(r,n){for(s=r,u=n,e=0;!f&&c&&!o&&e<l.length;e++){var o,i=l[e],d=p.p,h=i[2];r>3?(o=h===n)&&(u=i[(s=i[4])?5:(s=3,3)],i[4]=i[5]=t):i[0]<=d&&((o=r<2&&d<i[1])?(s=0,p.v=n,p.n=i[1]):d<h&&(o=r<3||i[0]>n||n>h)&&(i[4]=r,i[5]=n,p.n=h,s=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,h){if(c>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,h),s=l,u=h;(e=s<2?t:u)||!f;){i||(s?s<3?(s>1&&(p.n=-1),d(s,u)):p.n=u:p.v=u);try{if(c=2,i){if(s||(o="next"),e=i[o]){if(!(e=e.call(i,u)))throw TypeError("iterator result is not an object");if(!e.done)return e;u=e.value,s<2&&(s=0)}else 1===s&&(e=i.return)&&e.call(i),s<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),s=1);i=t}else if((e=(f=p.n<0)?u:r.call(n,p))!==a)break}catch(e){i=t,s=1,u=e}finally{c=1}}return{value:e,done:f}}}(r,o,i),!0),c}var a={};function s(){}function u(){}function c(){}e=Object.getPrototypeOf;var l=[][n]?e(e([][n]())):(K(e={},n,function(){return this}),e),f=c.prototype=s.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,c):(t.__proto__=c,K(t,o,"GeneratorFunction")),t.prototype=Object.create(f),t}return u.prototype=c,K(f,"constructor",c),K(c,"constructor",u),u.displayName="GeneratorFunction",K(c,o,"GeneratorFunction"),K(f),K(f,o,"Generator"),K(f,n,function(){return this}),K(f,"toString",function(){return"[object Generator]"}),(Z=function(){return{w:i,m:p}})()}function K(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}K=function(t,e,r,n){function i(e,r){K(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},K(t,e,r,n)}function X(t,e,r,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}function J(t){return function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function a(t){X(i,n,o,a,s,"next",t)}function s(t){X(i,n,o,a,s,"throw",t)}a(void 0)})}}var Q=function(t){return t.replace(/[^a-zA-Z0-9\s\-.,]/g,"").trim()},tt=function(t){var e=t.url,r=t.options;return new Request(e,r)},et=function(){var t=J(Z().m(function t(e,r,n){var o,i,a,s;return Z().w(function(t){for(;;)switch(t.n){case 0:if(i={url:null===(o=e.urlTemplate)||void 0===o?void 0:o.replace("{query}",encodeURIComponent(r)),options:{method:"GET"}},!e.buildRequest){t.n=1;break}return a=e.buildRequest(r,function(){return i}),t.a(2,a instanceof Request?a:tt(a));case 1:if(!n){t.n=3;break}return s=tt,t.n=2,n(i,r);case 2:return t.a(2,s(t.v));case 3:return t.a(2,tt(i))}},t)}));return function(e,r,n){return t.apply(this,arguments)}}(),rt=function(){var t=J(Z().m(function t(e,r,n){var o,i,a;return Z().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,fetch(r);case 1:if((o=t.v).ok){t.n=2;break}return console.error("Fetch error for ".concat(e.label||"dataset",": ").concat(o.status)),t.a(2,null);case 2:return t.n=3,o.json();case 3:return i=t.v,t.a(2,e.parseResults(i,n));case 4:return t.p=4,a=t.v,console.error("Network error for ".concat(e.label||"dataset",":"),a),t.a(2,null)}},t,null,[[0,4]])}));return function(e,r,n){return t.apply(this,arguments)}}(),nt=function(){var t=J(Z().m(function t(e,r,n,o){var i,a,s,u,c,l,f,p,d;return Z().w(function(t){for(;;)switch(t.p=t.n){case 0:i=Q(e),a=r.filter(function(t){var r=!t.includeRegex||t.includeRegex.test(e),n=!!t.excludeRegex&&t.excludeRegex.test(i);return r&&!n}),s=[],u=Y(a),t.p=1,u.s();case 2:if((c=u.n()).done){t.n=6;break}return l=c.value,t.n=3,et(l,i,o);case 3:return f=t.v,t.n=4,rt(l,f,i);case 4:if(null==(p=t.v)||!p.length){t.n=5;break}if(s=[].concat(V(s),V(p)),!l.exclusive){t.n=5;break}return t.a(3,6);case 5:t.n=2;break;case 6:t.n=8;break;case 7:t.p=7,d=t.v,u.e(d);case 8:return t.p=8,u.f(),t.f(8);case 9:return n({type:"UPDATE_SUGGESTIONS",payload:s}),t.a(2,{results:s,sanitisedValue:i})}},t,null,[[1,7,8,9]])}));return function(e,r,n,o){return t.apply(this,arguments)}}();function ot(t){var e=t.mapProvider,r=t.bounds,n=t.point,o=t.markers,i=t.showMarker,a=t.markerOptions;e.fitToBounds(r),i&&o.add("search",n,a)}function it(t){return it="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},it(t)}function at(){var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof s?n:s,c=Object.create(u.prototype);return st(c,"_invoke",function(r,n,o){var i,s,u,c=0,l=o||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,r){return i=e,s=0,u=t,p.n=r,a}};function d(r,n){for(s=r,u=n,e=0;!f&&c&&!o&&e<l.length;e++){var o,i=l[e],d=p.p,h=i[2];r>3?(o=h===n)&&(u=i[(s=i[4])?5:(s=3,3)],i[4]=i[5]=t):i[0]<=d&&((o=r<2&&d<i[1])?(s=0,p.v=n,p.n=i[1]):d<h&&(o=r<3||i[0]>n||n>h)&&(i[4]=r,i[5]=n,p.n=h,s=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,h){if(c>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,h),s=l,u=h;(e=s<2?t:u)||!f;){i||(s?s<3?(s>1&&(p.n=-1),d(s,u)):p.n=u:p.v=u);try{if(c=2,i){if(s||(o="next"),e=i[o]){if(!(e=e.call(i,u)))throw TypeError("iterator result is not an object");if(!e.done)return e;u=e.value,s<2&&(s=0)}else 1===s&&(e=i.return)&&e.call(i),s<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),s=1);i=t}else if((e=(f=p.n<0)?u:r.call(n,p))!==a)break}catch(e){i=t,s=1,u=e}finally{c=1}}return{value:e,done:f}}}(r,o,i),!0),c}var a={};function s(){}function u(){}function c(){}e=Object.getPrototypeOf;var l=[][n]?e(e([][n]())):(st(e={},n,function(){return this}),e),f=c.prototype=s.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,c):(t.__proto__=c,st(t,o,"GeneratorFunction")),t.prototype=Object.create(f),t}return u.prototype=c,st(f,"constructor",c),st(c,"constructor",u),u.displayName="GeneratorFunction",st(c,o,"GeneratorFunction"),st(f),st(f,o,"Generator"),st(f,n,function(){return this}),st(f,"toString",function(){return"[object Generator]"}),(at=function(){return{w:i,m:p}})()}function st(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}st=function(t,e,r,n){function i(e,r){st(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},st(t,e,r,n)}function ut(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function ct(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?ut(Object(r),!0).forEach(function(e){lt(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):ut(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function lt(t,e,r){return(e=function(t){var e=function(t){if("object"!=it(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=it(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==it(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function ft(t,e,r,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}function pt(t){return pt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},pt(t)}function dt(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function ht(t,e,r){return(e=function(t){var e=function(t){if("object"!=pt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=pt(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==pt(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function yt(t){return yt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},yt(t)}function mt(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function bt(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?mt(Object(r),!0).forEach(function(e){gt(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):mt(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function gt(t,e,r){return(e=function(t){var e=function(t){if("object"!=yt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=yt(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==yt(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function vt(t){var e,r,n,o=t.dispatch,i=t.searchContainerRef,a=(e=function(e){return nt(e,t.datasets,o,t.transformRequest)},r=null,n=function(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];clearTimeout(r),r=setTimeout(function(){e.apply(void 0,n)},350)},n.cancel=function(){r&&(clearTimeout(r),r=null)},n),s=function(t){var e=t.dispatch,r=t.services,n=t.viewportRef,o=t.mapProvider,i=t.markers,a=t.datasets,s=t.transformRequest,u=t.showMarker,c=t.markerOptions,l="";return{handleOpenClick:function(){e({type:"TOGGLE_EXPANDED",payload:!0}),r.eventBus.emit("search:open")},handleCloseClick:function(t,n){e({type:"TOGGLE_EXPANDED",payload:!1}),e({type:"UPDATE_SUGGESTIONS",payload:[]}),e({type:"SET_VALUE",payload:""}),setTimeout(function(){return n.current.focus()},0),i.remove("search"),r.eventBus.emit("search:clear"),r.eventBus.emit("search:close")},handleSubmit:function(t,f,p){return(d=at().m(function d(){var h,y,m,b,g,v,w,S,E,O,N,T;return at().w(function(d){for(;;)switch(d.n){case 0:if(t.preventDefault(),h=p.suggestions,y=p.selectedIndex,m=p.value,b=null==m?void 0:m.trim(),e({type:"SET_SELECTED",payload:-1}),e({type:"HIDE_SUGGESTIONS"}),!(y>=0)){d.n=1;break}return v=h[y],e({type:"SET_VALUE",payload:v.text}),null===(g=n.current)||void 0===g||g.focus(),ot({mapProvider:o,bounds:v.bounds,point:v.point,markers:i,showMarker:u,markerOptions:c}),r.eventBus.emit("search:match",ct({query:v.text},v)),d.a(2);case 1:if(!((null==b?void 0:b.length)<3)){d.n=2;break}return d.a(2);case 2:if(w=h,h.length&&b===l){d.n=4;break}return d.n=3,nt(b,a,e,s);case 3:S=d.v,E=S.results,O=S.sanitisedValue,w=E,l=O;case 4:w.length&&("keyboard"===f.interfaceType&&(null===(N=n.current)||void 0===N||N.focus()),"mobile"===f.breakpoint&&(e({type:"TOGGLE_EXPANDED",payload:!1}),r.eventBus.emit("search:close")),T=w[0],ot({mapProvider:o,bounds:T.bounds,point:T.point,markers:i,showMarker:u,markerOptions:c}),r.eventBus.emit("search:match",ct({query:m},T)));case 5:return d.a(2)}},d)}),function(){var t=this,e=arguments;return new Promise(function(r,n){var o=d.apply(t,e);function i(t){ft(o,r,n,i,a,"next",t)}function a(t){ft(o,r,n,i,a,"throw",t)}i(void 0)})})();var d}}}(t),u=function(t){var e=t.dispatch,r=t.debouncedFetchSuggestions;return{handleInputClick:function(){e({type:"SHOW_SUGGESTIONS"})},handleInputFocus:function(t){e({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:"keyboard"===t})},handleInputBlur:function(t){e({type:"INPUT_BLUR",payload:t})},handleInputChange:function(t){var n=t.target.value;if(e({type:"SET_VALUE",payload:n}),n.length<3)return r.cancel(),e({type:"UPDATE_SUGGESTIONS",payload:[]}),void e({type:"HIDE_SUGGESTIONS"});e({type:"SHOW_SUGGESTIONS"}),r(n)}}}(bt(bt({},t),{},{debouncedFetchSuggestions:a})),c=function(t){var e=t.dispatch,r=t.services,n=t.mapProvider,o=t.markers,i=t.showMarker,a=t.markerOptions,s=function(t,e){var r;return e>=0?"".concat(null===(r=t[e])||void 0===r?void 0:r.text,". ").concat(e+1," of ").concat(t.length," is highlighted"):"".concat(t.length," suggestions available")};return{handleSuggestionClick:function(t,s){e({type:"SET_VALUE",payload:t.text}),e({type:"HIDE_SUGGESTIONS"}),e({type:"SET_SELECTED",payload:-1}),"mobile"===s.breakpoint&&(e({type:"TOGGLE_EXPANDED",payload:!1}),r.eventBus.emit("search:close")),ot({mapProvider:n,bounds:t.bounds,point:t.point,markers:o,showMarker:i,markerOptions:a}),r.eventBus.emit("search:match",function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?dt(Object(r),!0).forEach(function(e){ht(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):dt(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}({query:t.text},t))},handleInputKeyDown:function(t,n){var o=n.suggestions,i=n.selectedIndex;switch(t.key){case"ArrowDown":if(null==o||!o.length)return;if(t.preventDefault(),i<o.length-1){var a=i+1;r.announce(s(o,a)),e({type:"SET_SELECTED",payload:a}),e({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:!1})}break;case"ArrowUp":if(null==o||!o.length)return;t.preventDefault();var u=i>0?i-1:-1;r.announce(s(o,u)),e({type:"SET_SELECTED",payload:u}),e({type:"SET_KEYBOARD_FOCUS_WITHIN",payload:u<0});break;case"Escape":t.preventDefault(),e({type:"HIDE_SUGGESTIONS"}),e({type:"SET_SELECTED",payload:-1})}}}}(t);return bt(bt(bt(bt({},s),u),c),{},{handleOutside:function(e){i.current.contains(e.target)||(o({type:"TOGGLE_EXPANDED",payload:!1}),t.services.eventBus.emit("search:close"))}})}function wt(t){return wt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},wt(t)}var St=["marker"];function Et(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function Ot(t,e,r){return(e=function(t){var e=function(t){if("object"!=wt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=wt(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==wt(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var Nt={reducer:{initialState:{isExpanded:!1,hasKeyboardFocusWithin:!1,value:"",suggestions:[],areSuggestionsVisible:!1,hasFetchedSuggestions:!1,selectedIndex:-1},actions:s},controls:[{id:"search",mobile:{slot:"top-right",showLabel:!1},tablet:{slot:"top-left",showLabel:!1},desktop:{slot:"top-left",showLabel:!1},render:function(t){var e,r=t.appConfig,n=t.iconRegistry,o=t.pluginState,i=t.pluginConfig,a=t.appState,s=t.mapState,f=t.services,p=t.mapProvider,d=r.id,h=a.interfaceType,y=i.expanded,v=i.customDatasets,w=i.osNamesURL,S=i.regions,E=o.dispatch,O=o.isExpanded,N=o.areSuggestionsVisible,T=o.suggestions,j=(null==a||null===(e=a.controlConfig)||void 0===e||null===(e=e.search)||void 0===e?void 0:e[null==a?void 0:a.breakpoint].showLabel)||!1,_=n.close,x=n.search,P=(0,u.useRef)(null),k=(0,u.useRef)(null),G=(0,u.useRef)(null),D=a.layoutRefs.viewportRef,M=function(t){var e,r=t.customDatasets,n=void 0===r?[]:r,o=t.osNamesURL,i=t.crs,a=t.regions,s=void 0===a?["england","scotland","wales"]:a;return o?[].concat([{name:"osNames",urlTemplate:o,parseResults:function(t,e){return function(t,e,r,n){var o;if(!t||t.error||0===(null===(o=t.header)||void 0===o?void 0:o.totalresults))return[];var i=t.results;return i=function(t,e){var r=e.toLowerCase().replace(/,/g,"").split(" ");return t.map(W).filter(function(t){return r.some(function(r){return t.GAZETTEER_ENTRY.NAME1.toLowerCase().includes(r)||(n=(n=e).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,e),i=function(t,e){return t.filter(function(t){var r,n=null==t||null===(r=t.GAZETTEER_ENTRY)||void 0===r||null===(r=r.COUNTRY)||void 0===r?void 0:r.toLowerCase();return n&&e.includes(n)})}(i=function(t){return Array.from(new Map(t.map(function(t){return[t.GAZETTEER_ENTRY.ID,t]})).values())}(i),r),(i=i.slice(0,8)).map(function(t){return L(L({id:t.GAZETTEER_ENTRY.ID,bounds:U(n,t.GAZETTEER_ENTRY),point:B(n,t.GAZETTEER_ENTRY)},function(t,e){var r,n,o,i,a,s,u=e.NAME1,c=e.COUNTY_UNITARY,l=e.DISTRICT_BOROUGH,f=e.POSTCODE_DISTRICT,p=e.LOCAL_TYPE,d="".concat(["City","Postcode"].includes(p)?"":f+", ").concat("City"===p?"":c||l),h="".concat(u).concat(d?", "+d:"");return{text:h,marked:(r=h,n=t,a=n.replace(/\s+/g,"").split("").join(String.raw(C||(o=["s*"],(i=["\\s*"])||(i=o.slice(0)),C=Object.freeze(Object.defineProperties(o,{raw:{value:Object.freeze(i)}}))))),s=new RegExp("(".concat(a,")"),"i"),r.replace(s,"<mark>$1</mark>"))}}(e,t.GAZETTEER_ENTRY)),{},{type:"os-names"})})}(t,e,s,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}],function(t){if(Array.isArray(t))return z(t)}(e=n)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(e)||function(t,e){if(t){if("string"==typeof t)return z(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?z(t,e):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()):n}({customDatasets:v,osNamesURL:w,regions:S,crs:p.crs}),R=(0,u.useRef)(null);if(!R.current){var A=i.marker,I=function(t,e){if(null==t)return{};var r,n,o=function(t,e){if(null==t)return{};var r={};for(var n in t)if({}.hasOwnProperty.call(t,n)){if(-1!==e.indexOf(n))continue;r[n]=t[n]}return r}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(n=0;n<i.length;n++)r=i[n],-1===e.indexOf(r)&&{}.propertyIsEnumerable.call(t,r)&&(o[r]=t[r])}return o}(i,St);R.current=vt(function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?Et(Object(r),!0).forEach(function(e){Ot(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):Et(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}({dispatch:E,datasets:M,services:f,mapProvider:p,viewportRef:D,searchContainerRef:P,markers:s.markers,markerOptions:A},I))}var $=R.current,F=O||!!(y&&N&&T.length);return(0,u.useEffect)(function(){var t;O&&(null===(t=G.current)||void 0===t||t.focus())},[O]),(0,u.useEffect)(function(){if(a.dispatch({type:"TOGGLE_HAS_EXCLUSIVE_CONTROL",payload:O}),F)return D.current.style.pointerEvents="none",document.addEventListener("focusin",$.handleOutside),document.addEventListener("pointerdown",$.handleOutside),function(){D.current.style.pointerEvents="auto",document.removeEventListener("focusin",$.handleOutside),document.removeEventListener("pointerdown",$.handleOutside)}},[O,h,N,T]),(0,c.jsxs)("div",{className:"im-c-search",ref:P,children:[!y&&(0,c.jsx)(l,{id:d,isExpanded:O,onClick:function(){return $.handleOpenClick(a)},buttonRef:k,searchIcon:x,showLabel:j}),(0,c.jsxs)(m,{id:d,pluginState:o,pluginConfig:i,appState:a,inputRef:G,events:$,services:f,children:[(0,c.jsx)(b,{defaultExpanded:y,onClick:function(t){return $.handleCloseClick(t,k,a)},closeIcon:_}),(0,c.jsx)(g,{defaultExpanded:y,onClick:function(t){return $.handleCloseClick(t,k,a)},submitIcon:x})]})]})}}],icons:[{id:"search",svgContent:'<path d="m21 21-4.34-4.34"></path><circle cx="11" cy="11" r="8"></circle>'}]}}}]);
|
|
@@ -31,6 +31,7 @@ export function Search ({ appConfig, iconRegistry, pluginState, pluginConfig, ap
|
|
|
31
31
|
// This ensures factory `attachEvents` only runs once
|
|
32
32
|
const eventsRef = useRef(null)
|
|
33
33
|
if (!eventsRef.current) {
|
|
34
|
+
const { marker: markerOptions, ...restPluginConfig } = pluginConfig
|
|
34
35
|
eventsRef.current = attachEvents({
|
|
35
36
|
dispatch,
|
|
36
37
|
datasets: mergedDatasets,
|
|
@@ -39,7 +40,8 @@ export function Search ({ appConfig, iconRegistry, pluginState, pluginConfig, ap
|
|
|
39
40
|
viewportRef,
|
|
40
41
|
searchContainerRef,
|
|
41
42
|
markers: mapState.markers,
|
|
42
|
-
|
|
43
|
+
markerOptions,
|
|
44
|
+
...restPluginConfig
|
|
43
45
|
})
|
|
44
46
|
}
|
|
45
47
|
const events = eventsRef.current
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
export const sanitiseQuery = (value) => value.replace(/[^a-zA-Z0-9\s\-.,]/g, '').trim()
|
|
4
4
|
|
|
5
|
+
const toRequest = ({ url, options }) => new Request(url, options)
|
|
6
|
+
|
|
5
7
|
const getRequestConfig = async (ds, query, transformRequest) => {
|
|
6
8
|
const defaultRequest = {
|
|
7
9
|
url: ds.urlTemplate?.replace('{query}', encodeURIComponent(query)),
|
|
@@ -9,15 +11,15 @@ const getRequestConfig = async (ds, query, transformRequest) => {
|
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
if (ds.buildRequest) {
|
|
12
|
-
|
|
14
|
+
const result = ds.buildRequest(query, () => defaultRequest)
|
|
15
|
+
return result instanceof Request ? result : toRequest(result)
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
if (transformRequest) {
|
|
16
|
-
|
|
17
|
-
return transformedRequest
|
|
19
|
+
return toRequest(await transformRequest(defaultRequest, query))
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
return defaultRequest
|
|
22
|
+
return toRequest(defaultRequest)
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
/**
|
|
@@ -9,6 +9,10 @@ describe('fetchSuggestions', () => {
|
|
|
9
9
|
beforeEach(() => {
|
|
10
10
|
dispatch.mockClear()
|
|
11
11
|
global.fetch = jest.fn()
|
|
12
|
+
global.Request = jest.fn(function (url, options) {
|
|
13
|
+
this.url = url
|
|
14
|
+
if (options) { Object.assign(this, options) }
|
|
15
|
+
})
|
|
12
16
|
jest.spyOn(console, 'error').mockImplementation(() => {})
|
|
13
17
|
})
|
|
14
18
|
|
|
@@ -35,7 +39,7 @@ describe('fetchSuggestions', () => {
|
|
|
35
39
|
|
|
36
40
|
const result = await fetchSuggestions('test', datasets, dispatch)
|
|
37
41
|
|
|
38
|
-
expect(fetch).toHaveBeenCalledWith({ url: '/api?q=test',
|
|
42
|
+
expect(fetch).toHaveBeenCalledWith(expect.objectContaining({ url: '/api?q=test', method: 'GET' }))
|
|
39
43
|
expect(result.results).toEqual(['a', 'b'])
|
|
40
44
|
expect(dispatch).toHaveBeenCalledWith({
|
|
41
45
|
type: 'UPDATE_SUGGESTIONS',
|
|
@@ -77,7 +81,7 @@ describe('fetchSuggestions', () => {
|
|
|
77
81
|
|
|
78
82
|
const result = await fetchSuggestions('abc', datasets, dispatch)
|
|
79
83
|
|
|
80
|
-
expect(fetch).toHaveBeenCalledWith({ url: '/custom/abc',
|
|
84
|
+
expect(fetch).toHaveBeenCalledWith(expect.objectContaining({ url: '/custom/abc', method: 'POST' }))
|
|
81
85
|
expect(result.results).toEqual(['y'])
|
|
82
86
|
})
|
|
83
87
|
|
|
@@ -101,7 +105,7 @@ describe('fetchSuggestions', () => {
|
|
|
101
105
|
|
|
102
106
|
await fetchSuggestions('x', datasets, dispatch, transformRequest)
|
|
103
107
|
|
|
104
|
-
expect(fetch).toHaveBeenCalledWith({ url: '/t?q=x',
|
|
108
|
+
expect(fetch).toHaveBeenCalledWith(expect.objectContaining({ url: '/t?q=x', method: 'PUT' }))
|
|
105
109
|
})
|
|
106
110
|
|
|
107
111
|
test('handles fetch HTTP error', async () => {
|
|
@@ -187,6 +191,24 @@ describe('fetchSuggestions', () => {
|
|
|
187
191
|
expect(fetch).toHaveBeenCalledTimes(1)
|
|
188
192
|
})
|
|
189
193
|
|
|
194
|
+
test('uses buildRequest result directly when it returns a Request instance', async () => {
|
|
195
|
+
global.fetch.mockResolvedValueOnce({
|
|
196
|
+
ok: true,
|
|
197
|
+
json: async () => ({})
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
const datasets = [
|
|
201
|
+
{
|
|
202
|
+
buildRequest: (query) => new Request(`/custom/${query}`),
|
|
203
|
+
parseResults: () => ['z']
|
|
204
|
+
}
|
|
205
|
+
]
|
|
206
|
+
|
|
207
|
+
await fetchSuggestions('abc', datasets, dispatch)
|
|
208
|
+
|
|
209
|
+
expect(fetch).toHaveBeenCalledWith(expect.objectContaining({ url: '/custom/abc' }))
|
|
210
|
+
})
|
|
211
|
+
|
|
190
212
|
test('buildRequest can call default request builder', async () => {
|
|
191
213
|
global.fetch.mockResolvedValueOnce({
|
|
192
214
|
ok: true,
|
|
@@ -206,7 +228,7 @@ describe('fetchSuggestions', () => {
|
|
|
206
228
|
|
|
207
229
|
const result = await fetchSuggestions('hi', datasets, dispatch)
|
|
208
230
|
|
|
209
|
-
expect(fetch).toHaveBeenCalledWith({ url: '/default?q=hi',
|
|
231
|
+
expect(fetch).toHaveBeenCalledWith(expect.objectContaining({ url: '/default?q=hi', method: 'GET' }))
|
|
210
232
|
expect(result.results).toEqual(['ok'])
|
|
211
233
|
})
|
|
212
234
|
})
|