maplair 4.0.0-alpha.2 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -38
- package/LICENSE +1 -1
- package/README.md +10 -9
- package/dist/esm/control/SearchControl.js +1 -1
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/geo/LatLng.js +20 -2
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +19 -7
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geo/crs/CRS.js +4 -3
- package/dist/esm/geo/crs/CRS.js.map +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js +2 -2
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js +2 -2
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +2 -2
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +19 -7
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/Point.js +23 -5
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +1 -1
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +1 -1
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/GeoJSON.js +1 -1
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/Popup.js +1 -1
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +1 -1
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +2 -2
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +1 -1
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +2 -2
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +1 -1
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.js +1 -1
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +5 -5
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +19 -19
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +1 -1
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +2 -2
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +134 -73
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +3 -3
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +134 -73
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.js +3 -3
- package/dist/maplair.js.map +1 -1
- package/package.json +4 -4
- package/src/control/SearchControl.js +2 -2
- package/src/geo/LatLng.js +21 -2
- package/src/geo/LatLngBounds.js +20 -7
- package/src/geo/crs/CRS.js +4 -3
- package/src/geo/projection/Projection.LonLat.js +2 -2
- package/src/geo/projection/Projection.Mercator.js +2 -2
- package/src/geo/projection/Projection.SphericalMercator.js +2 -2
- package/src/geometry/Bounds.js +20 -7
- package/src/geometry/Point.js +24 -5
- package/src/geometry/PolyUtil.js +1 -1
- package/src/layer/DivOverlay.js +1 -1
- package/src/layer/GeoJSON.js +1 -1
- package/src/layer/Popup.js +3 -3
- package/src/layer/marker/DivIcon.js +1 -1
- package/src/layer/marker/Icon.js +2 -2
- package/src/layer/marker/Marker.Move.js +1 -1
- package/src/layer/marker/Marker.js +2 -2
- package/src/layer/tile/GridLayer.js +1 -1
- package/src/layer/vector/Polyline.js +1 -1
- package/src/map/Map.Rotation.js +7 -7
- package/src/map/Map.js +21 -21
- package/src/map/handler/DragHandler.js +1 -1
- package/src/map/handler/KeyboardHandler.js +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyboardHandler.js","names":["DomUtil.create"],"sources":["../../../../src/map/handler/KeyboardHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport {on, off, stop, disableClickPropagation, disableScrollPropagation} from '../../dom/DomEvent.js';\nimport * as DomUtil from '../../dom/DomUtil.js';\nimport {Point} from '../../geometry/Point.js';\nimport {I18n} from '../../core/I18n.js';\n/** @import {MaplairMap} from '../Map.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n\n/**\n * Map options of `KeyboardHandler`, the keyboard navigation options.\n * @typedef {object} KeyboardHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [keyboard=true] Makes the map focusable and allows users to\n * navigate the map with keyboard arrows and `+`/`-` keys.\n * @property {number} [keyboardPanDelta=80] Amount of pixels to pan when pressing an\n * arrow key.\n */\n\n/**\n * Handler of `MaplairMap` for keyboard navigation.\n * @typedef {object} KeyboardHandlerMapProperties\n * @lends MaplairMap\n * @property {KeyboardHandler} keyboard Keyboard navigation handler.\n */\n\n/**\n * Handles keyboard interaction with the map, enabled by default, see the map option\n * `keyboard`. The `?` key shows a list of the keyboard shortcuts.\n *\n * @fires MaplairMap#focus {MaplairEvent} Fired when the map gains focus.\n * @fires MaplairMap#blur {MaplairEvent} Fired when the map loses focus.\n */\nexport class KeyboardHandler extends Handler {\n\n\t/**\n\t * The [codes](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code)\n\t * of the keys for panning and zooming the map.\n\t * @type {Record<'left'|'right'|'down'|'up'|'zoomIn'|'zoomOut', string[]>}\n\t */\n\tstatic keyCodes = {\n\t\tleft: ['ArrowLeft'],\n\t\tright: ['ArrowRight'],\n\t\tdown: ['ArrowDown'],\n\t\tup: ['ArrowUp'],\n\t\tzoomIn: ['Equal', 'NumpadAdd', 'BracketRight'],\n\t\tzoomOut: ['Minus', 'NumpadSubtract', 'Digit6', 'Slash']\n\t};\n\n\t/**\n\t * @param {MaplairMap} map\n\t */\n\tconstructor(map) {\n\t\tsuper(map);\n\n\t\tthis._setPanDelta(map.options.keyboardPanDelta);\n\t\tthis._setZoomDelta(map.options.zoomDelta);\n\n\t\tthis.callInitHooks(KeyboardHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tconst container = this._map._container;\n\n\t\t// make the container focusable by tabbing\n\t\tif (container.tabIndex <= 0) {\n\t\t\tcontainer.tabIndex = '0';\n\t\t}\n\n\t\t// add aria-attribute for keyboard shortcuts to the container\n\t\tcontainer.ariaKeyShortcuts = Object.values(KeyboardHandler.keyCodes).flat().join(' ');\n\n\t\ton(container, {\n\t\t\tfocus: this._onFocus,\n\t\t\tblur: this._onBlur,\n\t\t\tpointerdown: this._onPointerDown\n\t\t}, this);\n\n\t\tthis._map.on({\n\t\t\tfocus: this._addHooks,\n\t\t\tblur: this._removeHooks\n\t\t}, this);\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tthis._removeHooks();\n\n\t\toff(this._map._container, {\n\t\t\tfocus: this._onFocus,\n\t\t\tblur: this._onBlur,\n\t\t\tpointerdown: this._onPointerDown\n\t\t}, this);\n\n\t\tthis._map.off({\n\t\t\tfocus: this._addHooks,\n\t\t\tblur: this._removeHooks\n\t\t}, this);\n\n\t\tthis._help?.remove();\n\t\tthis._help = null;\n\t}\n\n\t// Shows or hides a list of the keyboard shortcuts (on the `?` key), as popover\n\t// closed by pressing `Escape` or clicking outside of it.\n\t_toggleHelp() {\n\t\tthis._help ??= this._createHelp();\n\t\tthis._help.togglePopover();\n\t}\n\n\t_createHelp() {\n\t\tconst help = DomUtil.create('div', 'maplair-keyboard-help', this._map._container),\n\t\ttitle = I18n.translate('Keyboard shortcuts');\n\t\thelp.popover = 'auto';\n\t\thelp.setAttribute('role', 'dialog');\n\t\thelp.setAttribute('aria-label', title);\n\n\t\tDomUtil.create('h2', '', help).textContent = title;\n\t\tconst list = DomUtil.create('dl', '', help);\n\t\tfor (const [keys, description] of [\n\t\t\t[['←', '→', '↑', '↓'], I18n.translate('Pan the map')],\n\t\t\t[['+'], I18n.translate('Zoom in')],\n\t\t\t[['−'], I18n.translate('Zoom out')],\n\t\t\t[['Shift'], I18n.translate('Pan or zoom further, together with the keys above')],\n\t\t\t[['Esc'], I18n.translate('Close popup')],\n\t\t\t[['?'], I18n.translate('Show or hide the keyboard shortcuts')]\n\t\t]) {\n\t\t\tconst row = DomUtil.create('div', '', list),\n\t\t\tdt = DomUtil.create('dt', '', row);\n\t\t\tfor (const key of keys) {\n\t\t\t\tDomUtil.create('kbd', '', dt).textContent = key;\n\t\t\t}\n\t\t\tDomUtil.create('dd', '', row).textContent = description;\n\t\t}\n\n\t\tdisableClickPropagation(help);\n\t\tdisableScrollPropagation(help);\n\t\treturn help;\n\t}\n\n\t// acquire/lose focus #594, #1228, #1540\n\t_onPointerDown() {\n\t\tif (this._focused) { return; }\n\n\t\tconst body = document.body,\n\t\tdocEl = document.documentElement,\n\t\ttop = body.scrollTop || docEl.scrollTop,\n\t\tleft = body.scrollLeft || docEl.scrollLeft;\n\n\t\tthis._map._container.focus();\n\n\t\twindow.scrollTo(left, top);\n\t}\n\n\t_onFocus() {\n\t\tthis._focused = true;\n\t\tthis._map.fire('focus');\n\t}\n\n\t_onBlur() {\n\t\tthis._focused = false;\n\t\tthis._map.fire('blur');\n\t}\n\n\t_setPanDelta(panDelta) {\n\t\tconst keys = this._panKeys = {},\n\t\tcodes = KeyboardHandler.keyCodes;\n\n\t\tfor (const code of codes.left) {\n\t\t\tkeys[code] = [-1 * panDelta, 0];\n\t\t}\n\t\tfor (const code of codes.right) {\n\t\t\tkeys[code] = [panDelta, 0];\n\t\t}\n\t\tfor (const code of codes.down) {\n\t\t\tkeys[code] = [0, panDelta];\n\t\t}\n\t\tfor (const code of codes.up) {\n\t\t\tkeys[code] = [0, -1 * panDelta];\n\t\t}\n\t}\n\n\t_setZoomDelta(zoomDelta) {\n\t\tconst keys = this._zoomKeys = {},\n\t\tcodes = KeyboardHandler.keyCodes;\n\n\t\tfor (const code of codes.zoomIn) {\n\t\t\tkeys[code] = zoomDelta;\n\t\t}\n\t\tfor (const code of codes.zoomOut) {\n\t\t\tkeys[code] = -zoomDelta;\n\t\t}\n\t}\n\n\t_addHooks() {\n\t\ton(document, 'keydown', this._onKeyDown, this);\n\t}\n\n\t_removeHooks() {\n\t\toff(document, 'keydown', this._onKeyDown, this);\n\t}\n\n\t_onKeyDown(e) {\n\t\tif (e.altKey || e.ctrlKey || e.metaKey) { return; }\n\n\t\tif (e.key === '?') {\n\t\t\tthis._toggleHelp();\n\t\t\tstop(e);\n\t\t\treturn;\n\t\t}\n\n\t\tconst key = e.code,\n\t\tmap = this._map;\n\t\tlet offset;\n\n\t\tif (key in this._panKeys) {\n\t\t\tif (!map._panAnim || !map._panAnim._inProgress) {\n\t\t\t\toffset = this._panKeys[key];\n\t\t\t\tif (e.shiftKey) {\n\t\t\t\t\toffset = new Point(offset).multiplyBy(3);\n\t\t\t\t}\n\n\t\t\t\tif (map.options.maxBounds) {\n\t\t\t\t\toffset = map._limitOffset(new Point(offset), map.options.maxBounds);\n\t\t\t\t}\n\n\t\t\t\tmap._setUserEvent(e);\n\t\t\t\tif (map.options.worldCopyJump) {\n\t\t\t\t\tconst newLatLng = map.wrapLatLng(map.unproject(map.project(map.getCenter()).add(offset)));\n\t\t\t\t\tmap.panTo(newLatLng);\n\t\t\t\t} else {\n\t\t\t\t\tmap.panBy(offset);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (key in this._zoomKeys) {\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap.setZoom(map.getZoom() + (e.shiftKey ? 3 : 1) * this._zoomKeys[key]);\n\n\t\t} else if (key === 'Escape' && map._popup && map._popup.options.closeOnEscapeKey) {\n\t\t\tmap.closePopup();\n\n\t\t} else {\n\t\t\treturn;\n\t\t}\n\n\t\tstop(e);\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tkeyboard: true,\n\t\t\tkeyboardPanDelta: 80\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'keyboard', KeyboardHandler);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,kBAAb,MAAa,wBAAwB,QAAQ;;;;;;CAO5C,OAAO,WAAW;EACjB,MAAM,CAAC,WAAW;EAClB,OAAO,CAAC,YAAY;EACpB,MAAM,CAAC,WAAW;EAClB,IAAI,CAAC,SAAS;EACd,QAAQ;GAAC;GAAS;GAAa;EAAc;EAC7C,SAAS;GAAC;GAAS;GAAkB;GAAU;EAAO;CACvD;;;;CAKA,YAAY,KAAK;EAChB,MAAM,GAAG;EAET,KAAK,aAAa,IAAI,QAAQ,gBAAgB;EAC9C,KAAK,cAAc,IAAI,QAAQ,SAAS;EAExC,KAAK,cAAc,eAAe;CACnC;;;;CAKA,WAAW;EACV,MAAM,YAAY,KAAK,KAAK;EAG5B,IAAI,UAAU,YAAY,GACzB,UAAU,WAAW;EAItB,UAAU,mBAAmB,OAAO,OAAO,gBAAgB,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG;EAEpF,GAAG,WAAW;GACb,OAAO,KAAK;GACZ,MAAM,KAAK;GACX,aAAa,KAAK;EACnB,GAAG,IAAI;EAEP,KAAK,KAAK,GAAG;GACZ,OAAO,KAAK;GACZ,MAAM,KAAK;EACZ,GAAG,IAAI;CACR;;;;CAKA,cAAc;EACb,KAAK,aAAa;EAElB,IAAI,KAAK,KAAK,YAAY;GACzB,OAAO,KAAK;GACZ,MAAM,KAAK;G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,IAAI,SAAS,aAAa;IAC/C,SAAS,KAAK,SAAS;IACvB,IAAI,EAAE,UACL,SAAS,IAAI,MAAM,MAAM,CAAC,CAAC,WAAW,CAAC;IAGxC,IAAI,IAAI,QAAQ,WACf,SAAS,IAAI,aAAa,IAAI,MAAM,MAAM,GAAG,IAAI,QAAQ,SAAS;IAGnE,IAAI,cAAc,CAAC;IACnB,IAAI,IAAI,QAAQ,eAAe;KAC9B,MAAM,YAAY,IAAI,WAAW,IAAI,UAAU,IAAI,QAAQ,IAAI,UAAU,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;KACxF,IAAI,MAAM,SAAS;IACpB,OACC,IAAI,MAAM,MAAM;GAElB;SACM,IAAI,OAAO,KAAK,WAAW;GACjC,IAAI,cAAc,CAAC;GACnB,IAAI,QAAQ,IAAI,QAAQ,KAAK,EAAE,WAAW,IAAI,KAAK,KAAK,UAAU,IAAI;EAEvE,OAAO,IAAI,QAAQ,YAAY,IAAI,UAAU,IAAI,OAAO,QAAQ,kBAC/D,IAAI,WAAW;OAGf;EAGD,KAAK,CAAC;CACP;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa;GACvB,UAAU;GACV,kBAAkB;EACnB,CAAC;EAED,WAAW,YAAY,cAAc,YAAY,eAAe;CACjE;AACD"}
|
|
1
|
+
{"version":3,"file":"KeyboardHandler.js","names":["DomUtil.create"],"sources":["../../../../src/map/handler/KeyboardHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport {on, off, stop, disableClickPropagation, disableScrollPropagation} from '../../dom/DomEvent.js';\nimport * as DomUtil from '../../dom/DomUtil.js';\nimport {Point} from '../../geometry/Point.js';\nimport {I18n} from '../../core/I18n.js';\n/** @import {MaplairMap} from '../Map.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n\n/**\n * Map options of `KeyboardHandler`, the keyboard navigation options.\n * @typedef {object} KeyboardHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [keyboard=true] Makes the map focusable and allows users to\n * navigate the map with keyboard arrows and `+`/`-` keys.\n * @property {number} [keyboardPanDelta=80] Amount of pixels to pan when pressing an\n * arrow key.\n */\n\n/**\n * Handler of `MaplairMap` for keyboard navigation.\n * @typedef {object} KeyboardHandlerMapProperties\n * @lends MaplairMap\n * @property {KeyboardHandler} keyboard Keyboard navigation handler.\n */\n\n/**\n * Handles keyboard interaction with the map, enabled by default, see the map option\n * `keyboard`. The `?` key shows a list of the keyboard shortcuts.\n *\n * @fires MaplairMap#focus {MaplairEvent} Fired when the map gains focus.\n * @fires MaplairMap#blur {MaplairEvent} Fired when the map loses focus.\n */\nexport class KeyboardHandler extends Handler {\n\n\t/**\n\t * The [codes](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code)\n\t * of the keys for panning and zooming the map.\n\t * @type {Record<'left'|'right'|'down'|'up'|'zoomIn'|'zoomOut', string[]>}\n\t */\n\tstatic keyCodes = {\n\t\tleft: ['ArrowLeft'],\n\t\tright: ['ArrowRight'],\n\t\tdown: ['ArrowDown'],\n\t\tup: ['ArrowUp'],\n\t\tzoomIn: ['Equal', 'NumpadAdd', 'BracketRight'],\n\t\tzoomOut: ['Minus', 'NumpadSubtract', 'Digit6', 'Slash']\n\t};\n\n\t/**\n\t * @param {MaplairMap} map\n\t */\n\tconstructor(map) {\n\t\tsuper(map);\n\n\t\tthis._setPanDelta(map.options.keyboardPanDelta);\n\t\tthis._setZoomDelta(map.options.zoomDelta);\n\n\t\tthis.callInitHooks(KeyboardHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tconst container = this._map._container;\n\n\t\t// make the container focusable by tabbing\n\t\tif (container.tabIndex <= 0) {\n\t\t\tcontainer.tabIndex = '0';\n\t\t}\n\n\t\t// add aria-attribute for keyboard shortcuts to the container\n\t\tcontainer.ariaKeyShortcuts = Object.values(KeyboardHandler.keyCodes).flat().join(' ');\n\n\t\ton(container, {\n\t\t\tfocus: this._onFocus,\n\t\t\tblur: this._onBlur,\n\t\t\tpointerdown: this._onPointerDown\n\t\t}, this);\n\n\t\tthis._map.on({\n\t\t\tfocus: this._addHooks,\n\t\t\tblur: this._removeHooks\n\t\t}, this);\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tthis._removeHooks();\n\n\t\toff(this._map._container, {\n\t\t\tfocus: this._onFocus,\n\t\t\tblur: this._onBlur,\n\t\t\tpointerdown: this._onPointerDown\n\t\t}, this);\n\n\t\tthis._map.off({\n\t\t\tfocus: this._addHooks,\n\t\t\tblur: this._removeHooks\n\t\t}, this);\n\n\t\tthis._help?.remove();\n\t\tthis._help = null;\n\t}\n\n\t// Shows or hides a list of the keyboard shortcuts (on the `?` key), as popover\n\t// closed by pressing `Escape` or clicking outside of it.\n\t_toggleHelp() {\n\t\tthis._help ??= this._createHelp();\n\t\tthis._help.togglePopover();\n\t}\n\n\t_createHelp() {\n\t\tconst help = DomUtil.create('div', 'maplair-keyboard-help', this._map._container),\n\t\ttitle = I18n.translate('Keyboard shortcuts');\n\t\thelp.popover = 'auto';\n\t\thelp.setAttribute('role', 'dialog');\n\t\thelp.setAttribute('aria-label', title);\n\n\t\tDomUtil.create('h2', '', help).textContent = title;\n\t\tconst list = DomUtil.create('dl', '', help);\n\t\tfor (const [keys, description] of [\n\t\t\t[['←', '→', '↑', '↓'], I18n.translate('Pan the map')],\n\t\t\t[['+'], I18n.translate('Zoom in')],\n\t\t\t[['−'], I18n.translate('Zoom out')],\n\t\t\t[['Shift'], I18n.translate('Pan or zoom further, together with the keys above')],\n\t\t\t[['Esc'], I18n.translate('Close popup')],\n\t\t\t[['?'], I18n.translate('Show or hide the keyboard shortcuts')]\n\t\t]) {\n\t\t\tconst row = DomUtil.create('div', '', list),\n\t\t\tdt = DomUtil.create('dt', '', row);\n\t\t\tfor (const key of keys) {\n\t\t\t\tDomUtil.create('kbd', '', dt).textContent = key;\n\t\t\t}\n\t\t\tDomUtil.create('dd', '', row).textContent = description;\n\t\t}\n\n\t\tdisableClickPropagation(help);\n\t\tdisableScrollPropagation(help);\n\t\treturn help;\n\t}\n\n\t// acquire/lose focus #594, #1228, #1540\n\t_onPointerDown() {\n\t\tif (this._focused) { return; }\n\n\t\tconst body = document.body,\n\t\tdocEl = document.documentElement,\n\t\ttop = body.scrollTop || docEl.scrollTop,\n\t\tleft = body.scrollLeft || docEl.scrollLeft;\n\n\t\tthis._map._container.focus();\n\n\t\twindow.scrollTo(left, top);\n\t}\n\n\t_onFocus() {\n\t\tthis._focused = true;\n\t\tthis._map.fire('focus');\n\t}\n\n\t_onBlur() {\n\t\tthis._focused = false;\n\t\tthis._map.fire('blur');\n\t}\n\n\t_setPanDelta(panDelta) {\n\t\tconst keys = this._panKeys = {},\n\t\tcodes = KeyboardHandler.keyCodes;\n\n\t\tfor (const code of codes.left) {\n\t\t\tkeys[code] = [-1 * panDelta, 0];\n\t\t}\n\t\tfor (const code of codes.right) {\n\t\t\tkeys[code] = [panDelta, 0];\n\t\t}\n\t\tfor (const code of codes.down) {\n\t\t\tkeys[code] = [0, panDelta];\n\t\t}\n\t\tfor (const code of codes.up) {\n\t\t\tkeys[code] = [0, -1 * panDelta];\n\t\t}\n\t}\n\n\t_setZoomDelta(zoomDelta) {\n\t\tconst keys = this._zoomKeys = {},\n\t\tcodes = KeyboardHandler.keyCodes;\n\n\t\tfor (const code of codes.zoomIn) {\n\t\t\tkeys[code] = zoomDelta;\n\t\t}\n\t\tfor (const code of codes.zoomOut) {\n\t\t\tkeys[code] = -zoomDelta;\n\t\t}\n\t}\n\n\t_addHooks() {\n\t\ton(document, 'keydown', this._onKeyDown, this);\n\t}\n\n\t_removeHooks() {\n\t\toff(document, 'keydown', this._onKeyDown, this);\n\t}\n\n\t_onKeyDown(e) {\n\t\tif (e.altKey || e.ctrlKey || e.metaKey) { return; }\n\n\t\tif (e.key === '?') {\n\t\t\tthis._toggleHelp();\n\t\t\tstop(e);\n\t\t\treturn;\n\t\t}\n\n\t\tconst key = e.code,\n\t\tmap = this._map;\n\t\tlet offset;\n\n\t\tif (key in this._panKeys) {\n\t\t\tif (!map._panAnim || !map._panAnim._inProgress) {\n\t\t\t\toffset = this._panKeys[key];\n\t\t\t\tif (e.shiftKey) {\n\t\t\t\t\toffset = Point.from(offset).multiplyBy(3);\n\t\t\t\t}\n\n\t\t\t\tif (map.options.maxBounds) {\n\t\t\t\t\toffset = map._limitOffset(Point.from(offset), map.options.maxBounds);\n\t\t\t\t}\n\n\t\t\t\tmap._setUserEvent(e);\n\t\t\t\tif (map.options.worldCopyJump) {\n\t\t\t\t\tconst newLatLng = map.wrapLatLng(map.unproject(map.project(map.getCenter()).add(offset)));\n\t\t\t\t\tmap.panTo(newLatLng);\n\t\t\t\t} else {\n\t\t\t\t\tmap.panBy(offset);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (key in this._zoomKeys) {\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap.setZoom(map.getZoom() + (e.shiftKey ? 3 : 1) * this._zoomKeys[key]);\n\n\t\t} else if (key === 'Escape' && map._popup && map._popup.options.closeOnEscapeKey) {\n\t\t\tmap.closePopup();\n\n\t\t} else {\n\t\t\treturn;\n\t\t}\n\n\t\tstop(e);\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tkeyboard: true,\n\t\t\tkeyboardPanDelta: 80\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'keyboard', KeyboardHandler);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,kBAAb,MAAa,wBAAwB,QAAQ;;;;;;CAO5C,OAAO,WAAW;EACjB,MAAM,CAAC,WAAW;EAClB,OAAO,CAAC,YAAY;EACpB,MAAM,CAAC,WAAW;EA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