maplair 4.3.0 → 4.5.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.
Files changed (191) hide show
  1. package/CHANGELOG.md +151 -8
  2. package/dist/esm/control/AttributionControl.js +30 -13
  3. package/dist/esm/control/AttributionControl.js.map +1 -1
  4. package/dist/esm/control/ButtonControl.js +0 -1
  5. package/dist/esm/control/ButtonControl.js.map +1 -1
  6. package/dist/esm/control/ContextMenu.js +1 -1
  7. package/dist/esm/control/ContextMenu.js.map +1 -1
  8. package/dist/esm/control/Control.js +16 -11
  9. package/dist/esm/control/Control.js.map +1 -1
  10. package/dist/esm/control/FullscreenControl.js +0 -1
  11. package/dist/esm/control/FullscreenControl.js.map +1 -1
  12. package/dist/esm/control/LayersControl.js +46 -27
  13. package/dist/esm/control/LayersControl.js.map +1 -1
  14. package/dist/esm/control/RotateControl.js +0 -1
  15. package/dist/esm/control/RotateControl.js.map +1 -1
  16. package/dist/esm/control/ScaleControl.js +7 -8
  17. package/dist/esm/control/ScaleControl.js.map +1 -1
  18. package/dist/esm/control/SideBySideControl.js +3 -2
  19. package/dist/esm/control/SideBySideControl.js.map +1 -1
  20. package/dist/esm/control/ZoomControl.js +14 -13
  21. package/dist/esm/control/ZoomControl.js.map +1 -1
  22. package/dist/esm/core/Events.js +3 -2
  23. package/dist/esm/core/Events.js.map +1 -1
  24. package/dist/esm/core/Util.js +17 -5
  25. package/dist/esm/core/Util.js.map +1 -1
  26. package/dist/esm/dom/DomEvent.PointerEvents.js +72 -2
  27. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  28. package/dist/esm/dom/DomEvent.js +4 -7
  29. package/dist/esm/dom/DomEvent.js.map +1 -1
  30. package/dist/esm/dom/DomUtil.js +5 -5
  31. package/dist/esm/dom/DomUtil.js.map +1 -1
  32. package/dist/esm/dom/Draggable.js +10 -8
  33. package/dist/esm/dom/Draggable.js.map +1 -1
  34. package/dist/esm/geo/LatLng.js +24 -35
  35. package/dist/esm/geo/LatLng.js.map +1 -1
  36. package/dist/esm/geo/LatLngBounds.js +6 -3
  37. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  38. package/dist/esm/geometry/Bounds.js +2 -2
  39. package/dist/esm/geometry/Bounds.js.map +1 -1
  40. package/dist/esm/geometry/Point.js +16 -19
  41. package/dist/esm/geometry/Point.js.map +1 -1
  42. package/dist/esm/geometry/PolyUtil.js +10 -3
  43. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  44. package/dist/esm/geometry/Transformation.js +1 -7
  45. package/dist/esm/geometry/Transformation.js.map +1 -1
  46. package/dist/esm/layer/BlanketOverlay.js +3 -2
  47. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  48. package/dist/esm/layer/DivOverlay.js +25 -25
  49. package/dist/esm/layer/DivOverlay.js.map +1 -1
  50. package/dist/esm/layer/ImageOverlay.js +8 -5
  51. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  52. package/dist/esm/layer/Layer.js +12 -7
  53. package/dist/esm/layer/Layer.js.map +1 -1
  54. package/dist/esm/layer/Popup.js +33 -15
  55. package/dist/esm/layer/Popup.js.map +1 -1
  56. package/dist/esm/layer/Tooltip.js +48 -56
  57. package/dist/esm/layer/Tooltip.js.map +1 -1
  58. package/dist/esm/layer/VideoOverlay.js +2 -2
  59. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  60. package/dist/esm/layer/marker/DivIcon.js +4 -8
  61. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  62. package/dist/esm/layer/marker/Icon.js +37 -17
  63. package/dist/esm/layer/marker/Icon.js.map +1 -1
  64. package/dist/esm/layer/marker/Marker.Drag.js +11 -12
  65. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  66. package/dist/esm/layer/marker/Marker.js +54 -53
  67. package/dist/esm/layer/marker/Marker.js.map +1 -1
  68. package/dist/esm/layer/marker/SvgIcon.js +1 -1
  69. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  70. package/dist/esm/layer/tile/GridLayer.js +29 -21
  71. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  72. package/dist/esm/layer/tile/TileLayer.js +19 -15
  73. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  74. package/dist/esm/layer/tile/WMSTileLayer.js +7 -3
  75. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  76. package/dist/esm/layer/vector/Canvas.js +45 -94
  77. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  78. package/dist/esm/layer/vector/Circle.js +8 -9
  79. package/dist/esm/layer/vector/Circle.js.map +1 -1
  80. package/dist/esm/layer/vector/CircleMarker.js +15 -4
  81. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  82. package/dist/esm/layer/vector/Path.ZoomStyles.js +4 -1
  83. package/dist/esm/layer/vector/Path.ZoomStyles.js.map +1 -1
  84. package/dist/esm/layer/vector/Path.js +10 -5
  85. package/dist/esm/layer/vector/Path.js.map +1 -1
  86. package/dist/esm/layer/vector/Polygon.js +10 -11
  87. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  88. package/dist/esm/layer/vector/Polyline.js +19 -26
  89. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  90. package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
  91. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  92. package/dist/esm/layer/vector/Renderer.js +16 -0
  93. package/dist/esm/layer/vector/Renderer.js.map +1 -1
  94. package/dist/esm/layer/vector/SVG.js +3 -3
  95. package/dist/esm/layer/vector/SVG.js.map +1 -1
  96. package/dist/esm/map/Map.Rotation.js +9 -11
  97. package/dist/esm/map/Map.Rotation.js.map +1 -1
  98. package/dist/esm/map/Map.js +158 -71
  99. package/dist/esm/map/Map.js.map +1 -1
  100. package/dist/esm/map/MapSync.js +2 -5
  101. package/dist/esm/map/MapSync.js.map +1 -1
  102. package/dist/esm/map/handler/BoxZoomHandler.js +4 -0
  103. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  104. package/dist/esm/map/handler/DisplaceHandler.js +68 -30
  105. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  106. package/dist/esm/map/handler/DragHandler.js +7 -2
  107. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  108. package/dist/esm/map/handler/KeyboardHandler.js +3 -5
  109. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  110. package/dist/esm/map/handler/PinchZoomHandler.js +4 -7
  111. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  112. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -7
  113. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  114. package/dist/esm/map/handler/TapDragZoomHandler.js +2 -5
  115. package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
  116. package/dist/esm/map/handler/TapHoldHandler.js +8 -20
  117. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  118. package/dist/esm/package.js +1 -1
  119. package/dist/maplair-global-src.js +970 -810
  120. package/dist/maplair-global-src.js.map +1 -1
  121. package/dist/maplair-global.js +2 -2
  122. package/dist/maplair-global.js.map +1 -1
  123. package/dist/maplair-src.js +970 -810
  124. package/dist/maplair-src.js.map +1 -1
  125. package/dist/maplair.css +1 -1
  126. package/dist/maplair.js +2 -2
  127. package/dist/maplair.js.map +1 -1
  128. package/i18n/en.json +1 -0
  129. package/package.json +1 -1
  130. package/src/control/AttributionControl.js +37 -11
  131. package/src/control/ButtonControl.js +0 -1
  132. package/src/control/ContextMenu.js +1 -1
  133. package/src/control/Control.js +13 -16
  134. package/src/control/FullscreenControl.js +0 -1
  135. package/src/control/LayersControl.js +61 -37
  136. package/src/control/RotateControl.js +0 -1
  137. package/src/control/ScaleControl.js +10 -8
  138. package/src/control/SideBySideControl.js +4 -2
  139. package/src/control/ZoomControl.js +11 -13
  140. package/src/core/Events.js +6 -2
  141. package/src/core/Util.js +17 -4
  142. package/src/dom/DomEvent.PointerEvents.js +68 -2
  143. package/src/dom/DomEvent.js +5 -17
  144. package/src/dom/DomUtil.js +5 -5
  145. package/src/dom/Draggable.js +11 -8
  146. package/src/geo/LatLng.js +24 -37
  147. package/src/geo/LatLngBounds.js +10 -4
  148. package/src/geometry/Bounds.js +3 -3
  149. package/src/geometry/Point.js +22 -28
  150. package/src/geometry/PolyUtil.js +12 -3
  151. package/src/geometry/Transformation.js +1 -8
  152. package/src/layer/BlanketOverlay.js +6 -3
  153. package/src/layer/DivOverlay.js +30 -32
  154. package/src/layer/ImageOverlay.js +12 -9
  155. package/src/layer/Layer.js +19 -7
  156. package/src/layer/Popup.js +41 -21
  157. package/src/layer/Tooltip.js +50 -70
  158. package/src/layer/VideoOverlay.js +2 -2
  159. package/src/layer/marker/DivIcon.js +3 -6
  160. package/src/layer/marker/Icon.js +41 -20
  161. package/src/layer/marker/Marker.Drag.js +22 -24
  162. package/src/layer/marker/Marker.js +71 -64
  163. package/src/layer/marker/SvgIcon.js +1 -1
  164. package/src/layer/tile/GridLayer.js +41 -30
  165. package/src/layer/tile/TileLayer.js +31 -21
  166. package/src/layer/tile/WMSTileLayer.js +4 -2
  167. package/src/layer/vector/Canvas.js +53 -149
  168. package/src/layer/vector/Circle.js +13 -13
  169. package/src/layer/vector/CircleMarker.js +16 -3
  170. package/src/layer/vector/Path.ZoomStyles.js +5 -3
  171. package/src/layer/vector/Path.js +11 -5
  172. package/src/layer/vector/Polygon.js +11 -10
  173. package/src/layer/vector/Polyline.js +20 -21
  174. package/src/layer/vector/Renderer.getRenderer.js +2 -1
  175. package/src/layer/vector/Renderer.js +21 -3
  176. package/src/layer/vector/SVG.js +3 -3
  177. package/src/map/Map.Rotation.js +13 -9
  178. package/src/map/Map.js +195 -83
  179. package/src/map/MapSync.js +2 -2
  180. package/src/map/handler/BoxZoomHandler.js +5 -0
  181. package/src/map/handler/DisplaceHandler.js +53 -7
  182. package/src/map/handler/DragHandler.js +5 -5
  183. package/src/map/handler/KeyboardHandler.js +5 -10
  184. package/src/map/handler/PinchZoomHandler.js +4 -4
  185. package/src/map/handler/ScrollWheelZoomHandler.js +4 -4
  186. package/src/map/handler/TapDragZoomHandler.js +2 -2
  187. package/src/map/handler/TapHoldHandler.js +13 -25
  188. package/src/maplair.css +50 -10
  189. package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
  190. package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
  191. package/src/dom/DomEvent.DoubleTap.js +0 -143
@@ -1 +1 @@
1
- {"version":3,"file":"ZoomControl.js","names":["DomUtil.create"],"sources":["../../../src/control/ZoomControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * Options of `ZoomControl`.\n * @typedef {object} ZoomControlOptions\n * @property {string} [position='topleft'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {string} [zoomInText='<span aria-hidden=\"true\">+</span>'] The text set on\n * the 'zoom in' button.\n * @property {string} [zoomOutText='<span aria-hidden=\"true\">&#x2212;</span>'] The text\n * set on the 'zoom out' button.\n * @extends ControlOptions\n */\n\n/**\n * Map options of `ZoomControl`.\n * @typedef {object} ZoomControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [zoomControl=true] Whether a [zoom control](#control-zoom) is\n * added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `ZoomControl`.\n * @typedef {object} ZoomControlMapProperties\n * @lends MaplairMap\n * @property {ZoomControl} zoomControl The default zoom control (only available if the\n * [`zoomControl` option](#map-zoomcontrol) was `true` when creating the map).\n */\n\n/**\n * A basic zoom control with two buttons (zoom in and zoom out). It is put on the map by\n * default unless you set its [`zoomControl` option](#map-zoomcontrol) to `false`.\n */\nexport class ZoomControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft',\n\t\tzoomInText: '<span aria-hidden=\"true\">+</span>',\n\t\tzoomOutText: '<span aria-hidden=\"true\">&#x2212;</span>',\n\t};\n\n\t/**\n\t * Creates a zoom control.\n\t * @param {...ZoomControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(ZoomControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tconst zoomName = 'maplair-control-zoom',\n\t\tcontainer = DomUtil.create('div', `${zoomName} maplair-bar`),\n\t\toptions = this.options;\n\n\t\tthis._zoomInButton = this._createButton(options.zoomInText, I18n.translate('Zoom in'),\n\t\t\t`${zoomName}-in`, container, e => this._zoom(e, 1));\n\t\tthis._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate('Zoom out'),\n\t\t\t`${zoomName}-out`, container, e => this._zoom(e, -1));\n\n\t\tthis._updateDisabled();\n\t\tmap.on('zoomend zoomlevelschange', this._updateDisabled, this);\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off('zoomend zoomlevelschange', this._updateDisabled, this);\n\t}\n\n\t/**\n\t * Disables the zoom buttons.\n\t * @returns {this}\n\t */\n\tdisable() {\n\t\tthis._disabled = true;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Enables the zoom buttons (if the zoom level allows).\n\t * @returns {this}\n\t */\n\tenable() {\n\t\tthis._disabled = false;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\t_zoom(e, dir) {\n\t\tconst map = this._map;\n\t\tif (!this._disabled && (dir > 0 ? map._zoom < map.getMaxZoom() : map._zoom > map.getMinZoom())) {\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap.zoomIn(dir * map.options.zoomDelta * (e.shiftKey ? 3 : 1));\n\t\t}\n\t}\n\n\t_createButton(html, title, className, container, fn) {\n\t\tconst link = DomUtil.create('button', className, container);\n\t\tlink.type = 'button';\n\t\tlink.innerHTML = html;\n\t\tlink.title = title;\n\t\tlink.setAttribute('aria-label', title);\n\n\t\tDomEvent.disableClickPropagation(link);\n\t\tDomEvent.on(link, 'click', (e) => {\n\t\t\tDomEvent.stop(e);\n\t\t\tfn.call(this, e);\n\t\t\tthis._refocusOnMap(e);\n\t\t});\n\n\t\treturn link;\n\t}\n\n\t_updateDisabled() {\n\t\tconst map = this._map;\n\t\tfor (const [button, limit] of [[this._zoomInButton, map.getMaxZoom()], [this._zoomOutButton, map.getMinZoom()]]) {\n\t\t\tconst disabled = this._disabled || map._zoom === limit;\n\t\t\tbutton.classList.toggle('maplair-disabled', disabled);\n\t\t\tbutton.setAttribute('aria-disabled', `${disabled}`);\n\t\t}\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\tzoomControl: true\n\t\t});\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tif (this.options.zoomControl) {\n\t\t\t\tthis.zoomControl = new ZoomControl();\n\t\t\t\tthis.addControl(this.zoomControl);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,cAAb,MAAa,oBAAoB,QAAQ;CAExC,OAAO,iBAAiB;EACvB,UAAU;EACV,YAAY;EACZ,aAAa;CACd;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,WAAW;CAC/B;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,WAAW,wBACjB,YAAYA,OAAe,OAAO,GAAG,SAAS,aAAa,GAC3D,UAAU,KAAK;EAEf,KAAK,gBAAiB,KAAK,cAAc,QAAQ,YAAY,KA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B,IAAI,WAAW,CAAC,CAAC,GAAG;GAChH,MAAM,WAAW,KAAK,aAAa,IAAI,UAAU;GACjD,OAAO,UAAU,OAAO,oBAAoB,QAAQ;GACpD,OAAO,aAAa,iBAAiB,GAAG,UAAU;EACnD;CACD;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,aAAa,KACd,CAAC;EAED,WAAW,YAAY,WAAY;GAClC,IAAI,KAAK,QAAQ,aAAa;IAC7B,KAAK,cAAc,IAAI,YAAY;IACnC,KAAK,WAAW,KAAK,WAAW;GACjC;EACD,CAAC;CACF;AACD"}
1
+ {"version":3,"file":"ZoomControl.js","names":["DomUtil.create"],"sources":["../../../src/control/ZoomControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * Options of `ZoomControl`.\n * @typedef {object} ZoomControlOptions\n * @property {string} [position='topleft'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {string} [zoomInText] The HTML of the 'zoom in' button, a plus sign drawn\n * in SVG by default.\n * @property {string} [zoomOutText] The HTML of the 'zoom out' button, a minus sign\n * drawn in SVG by default.\n * @extends ControlOptions\n */\n\n/**\n * Map options of `ZoomControl`.\n * @typedef {object} ZoomControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [zoomControl=true] Whether a [zoom control](#control-zoom) is\n * added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `ZoomControl`.\n * @typedef {object} ZoomControlMapProperties\n * @lends MaplairMap\n * @property {ZoomControl} zoomControl The default zoom control (only available if the\n * [`zoomControl` option](#map-zoomcontrol) was `true` when creating the map).\n */\n\n/**\n * A basic zoom control with two buttons (zoom in and zoom out). It is put on the map by\n * default unless you set its [`zoomControl` option](#map-zoomcontrol) to `false`.\n */\nexport class ZoomControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft',\n\t\tzoomInText: '<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12M6 0v12\"/></svg>',\n\t\tzoomOutText: '<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12\"/></svg>',\n\t};\n\n\t/**\n\t * Creates a zoom control.\n\t * @param {...ZoomControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(ZoomControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @returns {HTMLElement}\n\t */\n\tonAdd() {\n\t\tconst zoomName = 'maplair-control-zoom',\n\t\tcontainer = DomUtil.create('div', `${zoomName} maplair-bar`),\n\t\toptions = this.options;\n\n\t\tthis._zoomInButton = this._createButton(options.zoomInText, I18n.translate('Zoom in'),\n\t\t\t`${zoomName}-in`, container, e => this._zoom(e, 1));\n\t\tthis._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate('Zoom out'),\n\t\t\t`${zoomName}-out`, container, e => this._zoom(e, -1));\n\n\t\tthis._updateDisabled();\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @returns {Record<string, Function>}\n\t */\n\tgetEvents() {\n\t\treturn {zoomend: this._updateDisabled, zoomlevelschange: this._updateDisabled};\n\t}\n\n\t/**\n\t * Disables the zoom buttons.\n\t * @returns {this}\n\t */\n\tdisable() {\n\t\tthis._disabled = true;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Enables the zoom buttons (if the zoom level allows).\n\t * @returns {this}\n\t */\n\tenable() {\n\t\tthis._disabled = false;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\t_zoom(e, dir) {\n\t\tconst map = this._map;\n\t\tif (!this._disabled && (dir > 0 ? map._zoom < map.getMaxZoom() : map._zoom > map.getMinZoom())) {\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap.zoomIn(dir * map.options.zoomDelta * (e.shiftKey ? 3 : 1));\n\t\t}\n\t}\n\n\t_createButton(html, title, className, container, fn) {\n\t\tconst link = DomUtil.create('button', className, container);\n\t\tlink.type = 'button';\n\t\tlink.innerHTML = html;\n\t\tlink.title = title;\n\t\tlink.setAttribute('aria-label', title);\n\n\t\tDomEvent.disableClickPropagation(link);\n\t\tDomEvent.on(link, 'click', (e) => {\n\t\t\tDomEvent.stop(e);\n\t\t\tfn.call(this, e);\n\t\t});\n\n\t\treturn link;\n\t}\n\n\t_updateDisabled() {\n\t\tconst map = this._map;\n\t\tif (!map) { return; } // `onAdd` applies the state\n\t\tfor (const [button, limit] of [[this._zoomInButton, map.getMaxZoom()], [this._zoomOutButton, map.getMinZoom()]]) {\n\t\t\tconst disabled = this._disabled || map._zoom === limit;\n\t\t\tbutton.classList.toggle('maplair-disabled', disabled);\n\t\t\tbutton.setAttribute('aria-disabled', `${disabled}`);\n\t\t}\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\tzoomControl: true\n\t\t});\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tif (this.options.zoomControl) {\n\t\t\t\tthis.zoomControl = new ZoomControl();\n\t\t\t\tthis.addControl(this.zoomControl);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,cAAb,MAAa,oBAAoB,QAAQ;CAExC,OAAO,iBAAiB;EACvB,UAAU;EACV,YAAY;EACZ,aAAa;CACd;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,WAAW;CAC/B;;;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ACZ,KAAK,MAAM,CAAC,QAAQ,UAAU,CAAC,CAAC,KAAK,eAAe,IAAI,WAAW,CAAC,GAAG,CAAC,KAAK,gBAAgB,IAAI,WAAW,CAAC,CAAC,GAAG;GAChH,MAAM,WAAW,KAAK,aAAa,IAAI,UAAU;GACjD,OAAO,UAAU,OAAO,oBAAoB,QAAQ;GACpD,OAAO,aAAa,iBAAiB,GAAG,UAAU;EACnD;CACD;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,aAAa,KACd,CAAC;EAED,WAAW,YAAY,WAAY;GAClC,IAAI,KAAK,QAAQ,aAAa;IAC7B,KAAK,cAAc,IAAI,YAAY;IACnC,KAAK,WAAW,KAAK,WAAW;GACjC;EACD,CAAC;CACF;AACD"}
@@ -248,8 +248,9 @@ var Evented = class Evented extends Class {
248
248
  };
249
249
  if (_once) newListener.once = true;
250
250
  this._events ??= {};
251
- this._events[type] ??= /* @__PURE__ */ new Set();
252
- this._events[type].add(newListener);
251
+ let listeners = this._events[type] ??= /* @__PURE__ */ new Set();
252
+ if (this._firingCount) this._events[type] = listeners = new Set(listeners);
253
+ listeners.add(newListener);
253
254
  if (contexts) contexts.set(context, newListener);
254
255
  else this._listenerIndex[type].set(fn, /* @__PURE__ */ new Map([[context, newListener]]));
255
256
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Events.js","names":["Util.splitWords","Util.falseFn","Util.stamp"],"sources":["../../../src/core/Events.js"],"sourcesContent":["import {Class} from './Class.js';\nimport * as Util from './Util.js';\n\nconst warnedEvents = new Set();\n/** @import {LatLng} from '../geo/LatLng.js' */\n/** @import {LatLngBounds} from '../geo/LatLngBounds.js' */\n/** @import {Point} from '../geometry/Point.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n/** @import {Layer} from '../layer/Layer.js' */\n/** @import {Popup} from '../layer/Popup.js' */\n/** @import {Tooltip} from '../layer/Tooltip.js' */\n\n/**\n * The base event object, the argument of event listeners. All other event objects\n * contain these properties too. Whenever a class inheriting from `Evented` fires an\n * event, a listener function is called with an event object containing information\n * about the event, which depends on the event type. For example:\n *\n * ```js\n * map.on('click', function(ev) {\n * alert(ev.latlng); // ev is an event object (MaplairPointerEvent in this case)\n * });\n * ```\n *\n * @typedef {object} MaplairEvent\n * @property {string} type The event type (e.g. `'click'`).\n * @property {any} target The object that fired the event. For propagated events, the\n * last object in the propagation chain that fired the event.\n * @property {any} sourceTarget The object that originally fired the event. For\n * non-propagated events, this will be the same as the `target`.\n * @property {any} [propagatedFrom] For propagated events, the last object that\n * propagated the event to its event parent.\n */\n\n/**\n * A listener of events, called with the event object, which has more properties\n * depending on the event type (see the event objects below).\n * @typedef {(event: MaplairEvent & Record<string, any>) => void} EventListener\n */\n\n/**\n * The event object of keyboard events.\n * @typedef {object} MaplairKeyboardEvent\n * @property {KeyboardEvent} originalEvent The original\n * [DOM `KeyboardEvent`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent)\n * that triggered this Maplair event.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of pointer events (`click`, `pointermove`, …).\n * @typedef {object} MaplairPointerEvent\n * @property {LatLng} latlng The geographical point where the pointer event occurred.\n * @property {Point} layerPoint Pixel coordinates of the point where the pointer event\n * occurred relative to the map layer.\n * @property {Point} containerPoint Pixel coordinates of the point where the pointer\n * event occurred relative to the map container.\n * @property {MouseEvent|PointerEvent} originalEvent The original\n * [DOM `MouseEvent`](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent) or\n * [DOM `PointerEvent`](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent)\n * that triggered this Maplair event.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `locationfound`.\n * @typedef {object} LocationEvent\n * @property {LatLng} latlng Detected geographical location of the user.\n * @property {LatLngBounds} bounds Geographical bounds of the area user is located in\n * (with respect to the accuracy of location).\n * @property {number} accuracy Accuracy of location in meters.\n * @property {number} altitude Height of the position above the WGS84 ellipsoid in meters.\n * @property {number} altitudeAccuracy Accuracy of altitude in meters.\n * @property {number} heading The direction of travel in degrees counting clockwise from true North.\n * @property {number} speed Current velocity in meters per second.\n * @property {number} timestamp The time when the position was acquired.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of errors, e.g. `locationerror`.\n * @typedef {object} MaplairErrorEvent\n * @property {string} message Error message.\n * @property {number} [code] Error code (if applicable).\n * @extends MaplairEvent\n */\n\n/**\n * The event object of adding and removing layers.\n * @typedef {object} LayerEvent\n * @property {Layer} layer The layer that was added or removed.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of the layers control.\n * @typedef {object} LayersControlEvent\n * @property {Layer} layer The layer that was added or removed.\n * @property {string} name The name of the layer that was added or removed.\n * @property {Event} [originalEvent] The DOM event of the click on the entry in the\n * layers control, `undefined` if the layer was added or removed by code.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of tile events.\n * @typedef {object} TileEvent\n * @property {HTMLElement} tile The tile element (image).\n * @property {Point} coords Point object with the tile's `x`, `y`, and `z` (zoom level) coordinates.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `tileerror`.\n * @typedef {object} TileErrorEvent\n * @property {any} error Error passed to the tile's `done()` callback.\n * @extends TileEvent\n */\n\n/**\n * The event object of `resize`.\n * @typedef {object} ResizeEvent\n * @property {Point} oldSize The old size before resize event.\n * @property {Point} newSize The new size after the resize event.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `crschange`.\n * @typedef {object} CrsChangeEvent\n * @property {CRS} oldCrs The CRS of the map before the change.\n * @property {CRS} crs The new CRS of the map.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `worldcopyjump`.\n * @typedef {object} WorldCopyJumpEvent\n * @property {number} worlds The signed number of world widths by which the map pane moved.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of adding GeoJSON features.\n * @typedef {object} GeoJSONEvent\n * @property {Layer} layer The layer for the GeoJSON feature that is being added to the map.\n * @property {object} properties GeoJSON properties of the feature.\n * @property {string} geometryType GeoJSON geometry type of the feature.\n * @property {string|number} [id] GeoJSON ID of the feature (if present).\n * @extends MaplairEvent\n */\n\n/**\n * The event object of opening and closing popups.\n * @typedef {object} PopupEvent\n * @property {Popup} popup The popup that was opened or closed.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of opening and closing tooltips.\n * @typedef {object} TooltipEvent\n * @property {Tooltip} tooltip The tooltip that was opened or closed.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `dragend`.\n * @typedef {object} DragEndEvent\n * @property {number} distance The distance in pixels the draggable element was moved by.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `zoomanim`.\n * @typedef {object} ZoomAnimEvent\n * @property {LatLng} center The current center of the map.\n * @property {number} zoom The current zoom level of the map.\n * @property {boolean} [noUpdate] Whether layers should update their contents due to this event.\n * @extends MaplairEvent\n */\n\n/**\n * A set of methods shared between event-powered classes (like `Map` and `Marker`). Generally, events allow you to execute some function when something happens with an object (e.g. the user clicks on the map, causing the map to fire `'click'` event).\n *\n * @example\n *\n * ```js\n * map.on('click', function(e) {\n * \talert(e.latlng);\n * } );\n * ```\n *\n * Maplair deals with event listeners by reference, so if you want to add a listener and then remove it, define it as a function:\n *\n * ```js\n * function onClick(e) { ... }\n *\n * map.on('click', onClick);\n * map.off('click', onClick);\n * ```\n */\nexport class Evented extends Class {\n\t/**\n\t * Adds a listener function (`fn`) to a particular event type of the object. You can\n\t * optionally specify the context of the listener (object the this keyword will point\n\t * to). You can also pass several space-separated types (e.g. `'click dblclick'`).\n\t * Alternatively, adds a set of type/listener pairs, e.g.\n\t * `{click: onClick, pointermove: onPointerMove}`, with the context as second argument.\n\t * @param {string|Record<string, EventListener>} types\n\t * @param {EventListener|object} [fn]\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\ton(types, fn, context) {\n\n\t\t// types can be a map of types/handlers\n\t\tif (typeof types === 'object') {\n\t\t\tfor (const [type, f] of Object.entries(types)) {\n\t\t\t\t// we don't process space-separated events here for performance;\n\t\t\t\t// it's a hot path since Layer uses the on(obj) syntax\n\t\t\t\tthis._on(type, f, fn);\n\t\t\t}\n\n\t\t} else {\n\t\t\t// types can be a string of space-separated words\n\t\t\tfor (const type of Util.splitWords(types)) {\n\t\t\t\tthis._on(type, fn, context);\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes a previously added listener function. If no function is specified, it will\n\t * remove all the listeners of that particular event from the object. Note that if you\n\t * passed a custom context to `on`, you must pass the same context to `off` in order to\n\t * remove the listener. Alternatively, removes a set of type/listener pairs. Without\n\t * arguments, removes all listeners to all events on the object, including implicitly\n\t * attached events.\n\t * @param {string|Record<string, EventListener>} [types]\n\t * @param {EventListener|object} [fn]\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\toff(types, fn, context) {\n\n\t\tif (!arguments.length) {\n\t\t\t// clear all listeners if called without arguments\n\t\t\tdelete this._events;\n\t\t\tdelete this._listenerIndex;\n\n\t\t} else if (typeof types === 'object') {\n\t\t\tfor (const [type, f] of Object.entries(types)) {\n\t\t\t\tthis._off(type, f, fn);\n\t\t\t}\n\n\t\t} else {\n\t\t\tconst removeAll = arguments.length === 1;\n\t\t\tfor (const type of Util.splitWords(types)) {\n\t\t\t\tif (removeAll) {\n\t\t\t\t\tthis._off(type);\n\t\t\t\t} else {\n\t\t\t\t\tthis._off(type, fn, context);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tstatic __REMOVED_EVENTS = {\n\t\tmousedown: 'pointerdown',\n\t\tmouseup: 'pointerup',\n\t\tmouseover: 'pointerover',\n\t\tmouseout: 'pointerout',\n\t\tmousemove: 'pointermove',\n\t\tkeypress: 'keydown'\n\t};\n\n\t// attach listener (without syntactic sugar now)\n\t_on(type, fn, context, _once) {\n\t\t// To be removed in maplair 3\n\t\tif (Object.hasOwn(Evented.__REMOVED_EVENTS, type) && !warnedEvents.has(type)) {\n\t\t\twarnedEvents.add(type);\n\t\t\tconsole.error(`The event ${type} has been removed in Maplair. Use ${Evented.__REMOVED_EVENTS[type]} instead.`);\n\t\t}\n\n\t\tif (typeof fn !== 'function') {\n\t\t\tconsole.warn(`wrong listener type: ${typeof fn}`);\n\t\t\treturn;\n\t\t}\n\n\t\tif (context === this) {\n\t\t\t// Less memory footprint.\n\t\t\tcontext = undefined;\n\t\t}\n\n\t\t// check if fn already there\n\t\tconst contexts = this._getListenerIndex(type).get(fn);\n\t\tif (contexts?.has(context)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newListener = {fn, ctx: context};\n\t\tif (_once) {\n\t\t\tnewListener.once = true;\n\t\t}\n\n\t\tthis._events ??= {};\n\t\t// a Set keeps the listeners in order, and allows removing them in constant time\n\t\tthis._events[type] ??= new Set();\n\t\tthis._events[type].add(newListener);\n\n\t\tif (contexts) {\n\t\t\tcontexts.set(context, newListener);\n\t\t} else {\n\t\t\tthis._listenerIndex[type].set(fn, new Map([[context, newListener]]));\n\t\t}\n\t}\n\n\t// Listeners of the given event type, indexed by function and context, so that\n\t// adding and removing listeners doesn't need to scan all listeners of the type\n\t// (e.g. each marker listens to the map's `zoom` events with the same function).\n\t_getListenerIndex(type) {\n\t\tthis._listenerIndex ??= {};\n\t\treturn (this._listenerIndex[type] ??= new Map());\n\t}\n\n\t_off(type, fn, context) {\n\t\tif (!this._events) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet listeners = this._events[type];\n\t\tif (!listeners) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (arguments.length === 1) { // remove all\n\t\t\tif (this._firingCount) {\n\t\t\t\t// Set all removed listeners to noop\n\t\t\t\t// so they are not called if remove happens in fire\n\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\tlistener.fn = Util.falseFn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// clear all listeners for a type if function isn't specified\n\t\t\tdelete this._events[type];\n\t\t\tdelete this._listenerIndex?.[type];\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof fn !== 'function') {\n\t\t\tconsole.warn(`wrong listener type: ${typeof fn}`);\n\t\t\treturn;\n\t\t}\n\n\t\t// find fn and remove it\n\t\tif (context === this) {\n\t\t\tcontext = undefined;\n\t\t}\n\t\tconst contexts = this._listenerIndex?.[type]?.get(fn),\n\t\tlistener = contexts?.get(context);\n\t\tif (listener) {\n\t\t\tcontexts.delete(context);\n\t\t\tif (!contexts.size) {\n\t\t\t\tthis._listenerIndex[type].delete(fn);\n\t\t\t}\n\t\t\tif (this._firingCount) {\n\t\t\t\t// set the removed listener to noop so that's not called if remove happens in fire\n\t\t\t\tlistener.fn = Util.falseFn;\n\n\t\t\t\t/* copy listeners in case events are being fired */\n\t\t\t\tthis._events[type] = listeners = new Set(listeners);\n\t\t\t}\n\t\t\tlisteners.delete(listener);\n\t\t}\n\t}\n\n\t/**\n\t * Fires an event of the specified type. You can optionally provide a data\n\t * object — the first argument of the listener function will contain its\n\t * properties. The event can optionally be propagated to event parents.\n\t * @param {string} type\n\t * @param {object} [data]\n\t * @param {boolean} [propagate]\n\t * @returns {this}\n\t */\n\tfire(type, data, propagate) {\n\t\tif (!this.listens(type, propagate)) { return this; }\n\n\t\tconst event = {\n\t\t\t...data,\n\t\t\ttype,\n\t\t\ttarget: this,\n\t\t\tsourceTarget: data?.sourceTarget || this\n\t\t};\n\n\t\tif (this._events) {\n\t\t\tconst listeners = this._events[type];\n\t\t\tif (listeners) {\n\t\t\t\tthis._firingCount = (this._firingCount + 1) || 1;\n\t\t\t\tfor (const l of listeners) {\n\t\t\t\t\t// off overwrites l.fn, so we need to copy fn to a variable\n\t\t\t\t\tconst fn = l.fn;\n\t\t\t\t\tif (l.once) {\n\t\t\t\t\t\tthis.off(type, fn, l.ctx);\n\t\t\t\t\t}\n\t\t\t\t\tfn.call(l.ctx || this, event);\n\t\t\t\t}\n\n\t\t\t\tthis._firingCount--;\n\t\t\t}\n\t\t}\n\n\t\tif (propagate) {\n\t\t\t// propagate the event to parents (set with addEventParent)\n\t\t\tthis._propagateEvent(event);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns `true` if a particular event type has any listeners attached to it (or the\n\t * given listener function, with the given context). The verification can optionally\n\t * be propagated, it will return `true` if parents have the listener attached to it.\n\t * Called as `listens(type, propagate?)` or `listens(type, fn, context?, propagate?)`.\n\t * @param {string} type\n\t * @param {EventListener|boolean} [fn]\n\t * @param {object} [context]\n\t * @param {boolean} [propagate]\n\t * @returns {boolean}\n\t */\n\tlistens(type, fn, context, propagate) {\n\t\tif (typeof type !== 'string') {\n\t\t\tconsole.warn('\"string\" type argument expected');\n\t\t}\n\n\t\t// we don't overwrite the input `fn` value, because we need to use it for propagation\n\t\tlet _fn = fn;\n\t\tif (typeof fn !== 'function') {\n\t\t\tpropagate = !!fn;\n\t\t\t_fn = undefined;\n\t\t\tcontext = undefined;\n\t\t}\n\n\t\tif (this._events?.[type]?.size) {\n\t\t\tif (this._listens(type, _fn, context) !== false) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\tif (propagate) {\n\t\t\t// also check parents for listeners if event propagates\n\t\t\tfor (const p of Object.values(this._eventParents ?? {})) {\n\t\t\t\tif (p.listens(type, fn, context, propagate)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t// returns whether the given listener (or any listener, if no `fn` is given) is registered\n\t_listens(type, fn, context) {\n\t\tif (!this._events) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst listeners = this._events[type];\n\t\tif (!fn) {\n\t\t\treturn !!listeners?.size;\n\t\t}\n\n\t\tif (context === this) {\n\t\t\t// Less memory footprint.\n\t\t\tcontext = undefined;\n\t\t}\n\n\t\treturn !!this._listenerIndex?.[type]?.get(fn)?.has(context);\n\n\t}\n\n\t/**\n\t * Behaves as [`on(…)`](#evented-on), except the listener will only get fired once and then removed.\n\t * @param {string|Record<string, EventListener>} types\n\t * @param {EventListener|object} [fn]\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\tonce(types, fn, context) {\n\n\t\t// types can be a map of types/handlers\n\t\tif (typeof types === 'object') {\n\t\t\tfor (const [type, f] of Object.entries(types)) {\n\t\t\t\t// we don't process space-separated events here for performance;\n\t\t\t\t// it's a hot path since Layer uses the on(obj) syntax\n\t\t\t\tthis._on(type, f, fn, true);\n\t\t\t}\n\n\t\t} else {\n\t\t\t// types can be a string of space-separated words\n\t\t\tfor (const type of Util.splitWords(types)) {\n\t\t\t\tthis._on(type, fn, context, true);\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds an event parent - an `Evented` that will receive propagated events.\n\t * @param {Evented} obj\n\t * @returns {this}\n\t */\n\taddEventParent(obj) {\n\t\tthis._eventParents ??= {};\n\t\tthis._eventParents[Util.stamp(obj)] = obj;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes an event parent, so it will stop receiving propagated events.\n\t * @param {Evented} obj\n\t * @returns {this}\n\t */\n\tremoveEventParent(obj) {\n\t\tif (this._eventParents) {\n\t\t\tdelete this._eventParents[Util.stamp(obj)];\n\t\t}\n\t\treturn this;\n\t}\n\n\t_propagateEvent(e) {\n\t\tfor (const p of Object.values(this._eventParents ?? {})) {\n\t\t\t// `layer` is the Leaflet 1 name of `propagatedFrom`, left out of the types to steer new code to the new one\n\t\t\tp.fire(e.type, {\n\t\t\t\tlayer: e.target,\n\t\t\t\tpropagatedFrom: e.target,\n\t\t\t\t...e\n\t\t\t}, true);\n\t\t}\n\t}\n};\n"],"mappings":";;;AAGA,MAAM,+BAAe,IAAI,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuM7B,IAAa,UAAb,MAAa,gBAAgB,MAAM;;;;;;;;;;;;CAYlC,GAAG,OAAO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Q,KAAK,GAG3C,KAAK,IAAI,MAAM,GAAG,IAAI,IAAI;OAK3B,KAAK,MAAM,QAAQD,WAAgB,KAAK,GACvC,KAAK,IAAI,MAAM,IAAI,SAAS,IAAI;EAIlC,OAAO;CACR;;;;;;CAOA,eAAe,KAAK;EACnB,KAAK,kBAAkB,CAAC;EACxB,KAAK,cAAcE,MAAW,GAAG,KAAK;EACtC,OAAO;CACR;;;;;;CAOA,kBAAkB,KAAK;EACtB,IAAI,KAAK,eACR,OAAO,KAAK,cAAcA,MAAW,GAAG;EAEzC,OAAO;CACR;CAEA,gBAAgB,GAAG;EAClB,KAAK,MAAM,KAAK,OAAO,OAAO,KAAK,iBAAiB,CAAC,CAAC,GAErD,EAAE,KAAK,EAAE,MAAM;GACd,OAAO,EAAE;GACT,gBAAgB,EAAE;GAClB,GAAG;EACJ,GAAG,IAAI;CAET;AACD"}
1
+ {"version":3,"file":"Events.js","names":["Util.splitWords","Util.falseFn","Util.stamp"],"sources":["../../../src/core/Events.js"],"sourcesContent":["import {Class} from './Class.js';\nimport * as Util from './Util.js';\n\nconst warnedEvents = new Set();\n/** @import {LatLng} from '../geo/LatLng.js' */\n/** @import {LatLngBounds} from '../geo/LatLngBounds.js' */\n/** @import {Point} from '../geometry/Point.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n/** @import {Layer} from '../layer/Layer.js' */\n/** @import {Popup} from '../layer/Popup.js' */\n/** @import {Tooltip} from '../layer/Tooltip.js' */\n\n/**\n * The base event object, the argument of event listeners. All other event objects\n * contain these properties too. Whenever a class inheriting from `Evented` fires an\n * event, a listener function is called with an event object containing information\n * about the event, which depends on the event type. For example:\n *\n * ```js\n * map.on('click', function(ev) {\n * alert(ev.latlng); // ev is an event object (MaplairPointerEvent in this case)\n * });\n * ```\n *\n * @typedef {object} MaplairEvent\n * @property {string} type The event type (e.g. `'click'`).\n * @property {any} target The object that fired the event. For propagated events, the\n * last object in the propagation chain that fired the event.\n * @property {any} sourceTarget The object that originally fired the event. For\n * non-propagated events, this will be the same as the `target`.\n * @property {any} [propagatedFrom] For propagated events, the last object that\n * propagated the event to its event parent.\n */\n\n/**\n * A listener of events, called with the event object, which has more properties\n * depending on the event type (see the event objects below).\n * @typedef {(event: MaplairEvent & Record<string, any>) => void} EventListener\n */\n\n/**\n * The event object of keyboard events.\n * @typedef {object} MaplairKeyboardEvent\n * @property {KeyboardEvent} originalEvent The original\n * [DOM `KeyboardEvent`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent)\n * that triggered this Maplair event.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of pointer events (`click`, `pointermove`, …).\n * @typedef {object} MaplairPointerEvent\n * @property {LatLng} latlng The geographical point where the pointer event occurred.\n * @property {Point} layerPoint Pixel coordinates of the point where the pointer event\n * occurred relative to the map layer.\n * @property {Point} containerPoint Pixel coordinates of the point where the pointer\n * event occurred relative to the map container.\n * @property {MouseEvent|PointerEvent} originalEvent The original\n * [DOM `MouseEvent`](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent) or\n * [DOM `PointerEvent`](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent)\n * that triggered this Maplair event.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `locationfound`.\n * @typedef {object} LocationEvent\n * @property {LatLng} latlng Detected geographical location of the user.\n * @property {LatLngBounds} bounds Geographical bounds of the area user is located in\n * (with respect to the accuracy of location).\n * @property {number} accuracy Accuracy of location in meters.\n * @property {number} altitude Height of the position above the WGS84 ellipsoid in meters.\n * @property {number} altitudeAccuracy Accuracy of altitude in meters.\n * @property {number} heading The direction of travel in degrees counting clockwise from true North.\n * @property {number} speed Current velocity in meters per second.\n * @property {number} timestamp The time when the position was acquired.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of errors, e.g. `locationerror`.\n * @typedef {object} MaplairErrorEvent\n * @property {string} message Error message.\n * @property {number} [code] Error code (if applicable).\n * @extends MaplairEvent\n */\n\n/**\n * The event object of adding and removing layers.\n * @typedef {object} LayerEvent\n * @property {Layer} layer The layer that was added or removed.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of the layers control.\n * @typedef {object} LayersControlEvent\n * @property {Layer} layer The layer that was added or removed.\n * @property {string} name The name of the layer that was added or removed.\n * @property {Event} [originalEvent] The DOM event of the click on the entry in the\n * layers control, `undefined` if the layer was added or removed by code.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of tile events.\n * @typedef {object} TileEvent\n * @property {HTMLElement} tile The tile element (image).\n * @property {Point} coords Point object with the tile's `x`, `y`, and `z` (zoom level) coordinates.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `tileerror`.\n * @typedef {object} TileErrorEvent\n * @property {any} error Error passed to the tile's `done()` callback.\n * @extends TileEvent\n */\n\n/**\n * The event object of `resize`.\n * @typedef {object} ResizeEvent\n * @property {Point} oldSize The old size before resize event.\n * @property {Point} newSize The new size after the resize event.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `crschange`.\n * @typedef {object} CrsChangeEvent\n * @property {CRS} oldCrs The CRS of the map before the change.\n * @property {CRS} crs The new CRS of the map.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `worldcopyjump`.\n * @typedef {object} WorldCopyJumpEvent\n * @property {number} worlds The signed number of world widths by which the map pane moved.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of adding GeoJSON features.\n * @typedef {object} GeoJSONEvent\n * @property {Layer} layer The layer for the GeoJSON feature that is being added to the map.\n * @property {object} properties GeoJSON properties of the feature.\n * @property {string} geometryType GeoJSON geometry type of the feature.\n * @property {string|number} [id] GeoJSON ID of the feature (if present).\n * @extends MaplairEvent\n */\n\n/**\n * The event object of opening and closing popups.\n * @typedef {object} PopupEvent\n * @property {Popup} popup The popup that was opened or closed.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of opening and closing tooltips.\n * @typedef {object} TooltipEvent\n * @property {Tooltip} tooltip The tooltip that was opened or closed.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `dragend`.\n * @typedef {object} DragEndEvent\n * @property {number} distance The distance in pixels the draggable element was moved by.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `zoomanim`.\n * @typedef {object} ZoomAnimEvent\n * @property {LatLng} center The current center of the map.\n * @property {number} zoom The current zoom level of the map.\n * @property {boolean} [noUpdate] Whether layers should update their contents due to this event.\n * @extends MaplairEvent\n */\n\n/**\n * A set of methods shared between event-powered classes (like `Map` and `Marker`). Generally, events allow you to execute some function when something happens with an object (e.g. the user clicks on the map, causing the map to fire `'click'` event).\n *\n * @example\n *\n * ```js\n * map.on('click', function(e) {\n * \talert(e.latlng);\n * } );\n * ```\n *\n * Maplair deals with event listeners by reference, so if you want to add a listener and then remove it, define it as a function:\n *\n * ```js\n * function onClick(e) { ... }\n *\n * map.on('click', onClick);\n * map.off('click', onClick);\n * ```\n */\nexport class Evented extends Class {\n\t/**\n\t * Adds a listener function (`fn`) to a particular event type of the object. You can\n\t * optionally specify the context of the listener (object the this keyword will point\n\t * to). You can also pass several space-separated types (e.g. `'click dblclick'`).\n\t * Alternatively, adds a set of type/listener pairs, e.g.\n\t * `{click: onClick, pointermove: onPointerMove}`, with the context as second argument.\n\t * @param {string|Record<string, EventListener>} types\n\t * @param {EventListener|object} [fn]\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\ton(types, fn, context) {\n\n\t\t// types can be a map of types/handlers\n\t\tif (typeof types === 'object') {\n\t\t\tfor (const [type, f] of Object.entries(types)) {\n\t\t\t\t// we don't process space-separated events here for performance;\n\t\t\t\t// it's a hot path since Layer uses the on(obj) syntax\n\t\t\t\tthis._on(type, f, fn);\n\t\t\t}\n\n\t\t} else {\n\t\t\t// types can be a string of space-separated words\n\t\t\tfor (const type of Util.splitWords(types)) {\n\t\t\t\tthis._on(type, fn, context);\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes a previously added listener function. If no function is specified, it will\n\t * remove all the listeners of that particular event from the object. Note that if you\n\t * passed a custom context to `on`, you must pass the same context to `off` in order to\n\t * remove the listener. Alternatively, removes a set of type/listener pairs. Without\n\t * arguments, removes all listeners to all events on the object, including implicitly\n\t * attached events.\n\t * @param {string|Record<string, EventListener>} [types]\n\t * @param {EventListener|object} [fn]\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\toff(types, fn, context) {\n\n\t\tif (!arguments.length) {\n\t\t\t// clear all listeners if called without arguments\n\t\t\tdelete this._events;\n\t\t\tdelete this._listenerIndex;\n\n\t\t} else if (typeof types === 'object') {\n\t\t\tfor (const [type, f] of Object.entries(types)) {\n\t\t\t\tthis._off(type, f, fn);\n\t\t\t}\n\n\t\t} else {\n\t\t\tconst removeAll = arguments.length === 1;\n\t\t\tfor (const type of Util.splitWords(types)) {\n\t\t\t\tif (removeAll) {\n\t\t\t\t\tthis._off(type);\n\t\t\t\t} else {\n\t\t\t\t\tthis._off(type, fn, context);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tstatic __REMOVED_EVENTS = {\n\t\tmousedown: 'pointerdown',\n\t\tmouseup: 'pointerup',\n\t\tmouseover: 'pointerover',\n\t\tmouseout: 'pointerout',\n\t\tmousemove: 'pointermove',\n\t\tkeypress: 'keydown'\n\t};\n\n\t// attach listener (without syntactic sugar now)\n\t_on(type, fn, context, _once) {\n\t\t// To be removed in maplair 3\n\t\tif (Object.hasOwn(Evented.__REMOVED_EVENTS, type) && !warnedEvents.has(type)) {\n\t\t\twarnedEvents.add(type);\n\t\t\tconsole.error(`The event ${type} has been removed in Maplair. Use ${Evented.__REMOVED_EVENTS[type]} instead.`);\n\t\t}\n\n\t\tif (typeof fn !== 'function') {\n\t\t\tconsole.warn(`wrong listener type: ${typeof fn}`);\n\t\t\treturn;\n\t\t}\n\n\t\tif (context === this) {\n\t\t\t// Less memory footprint.\n\t\t\tcontext = undefined;\n\t\t}\n\n\t\t// check if fn already there\n\t\tconst contexts = this._getListenerIndex(type).get(fn);\n\t\tif (contexts?.has(context)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newListener = {fn, ctx: context};\n\t\tif (_once) {\n\t\t\tnewListener.once = true;\n\t\t}\n\n\t\tthis._events ??= {};\n\t\t// a Set keeps the listeners in order, and allows removing them in constant time\n\t\tlet listeners = this._events[type] ??= new Set();\n\t\tif (this._firingCount) {\n\t\t\t// copy the listeners being fired, so that the new one is called from the next fire on\n\t\t\tthis._events[type] = listeners = new Set(listeners);\n\t\t}\n\t\tlisteners.add(newListener);\n\n\t\tif (contexts) {\n\t\t\tcontexts.set(context, newListener);\n\t\t} else {\n\t\t\tthis._listenerIndex[type].set(fn, new Map([[context, newListener]]));\n\t\t}\n\t}\n\n\t// Listeners of the given event type, indexed by function and context, so that\n\t// adding and removing listeners doesn't need to scan all listeners of the type\n\t// (e.g. each marker listens to the map's `zoom` events with the same function).\n\t_getListenerIndex(type) {\n\t\tthis._listenerIndex ??= {};\n\t\treturn (this._listenerIndex[type] ??= new Map());\n\t}\n\n\t_off(type, fn, context) {\n\t\tif (!this._events) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet listeners = this._events[type];\n\t\tif (!listeners) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (arguments.length === 1) { // remove all\n\t\t\tif (this._firingCount) {\n\t\t\t\t// Set all removed listeners to noop\n\t\t\t\t// so they are not called if remove happens in fire\n\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\tlistener.fn = Util.falseFn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// clear all listeners for a type if function isn't specified\n\t\t\tdelete this._events[type];\n\t\t\tdelete this._listenerIndex?.[type];\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof fn !== 'function') {\n\t\t\tconsole.warn(`wrong listener type: ${typeof fn}`);\n\t\t\treturn;\n\t\t}\n\n\t\t// find fn and remove it\n\t\tif (context === this) {\n\t\t\tcontext = undefined;\n\t\t}\n\t\tconst contexts = this._listenerIndex?.[type]?.get(fn),\n\t\tlistener = contexts?.get(context);\n\t\tif (listener) {\n\t\t\tcontexts.delete(context);\n\t\t\tif (!contexts.size) {\n\t\t\t\tthis._listenerIndex[type].delete(fn);\n\t\t\t}\n\t\t\tif (this._firingCount) {\n\t\t\t\t// set the removed listener to noop so that's not called if remove happens in fire\n\t\t\t\tlistener.fn = Util.falseFn;\n\n\t\t\t\t/* copy listeners in case events are being fired */\n\t\t\t\tthis._events[type] = listeners = new Set(listeners);\n\t\t\t}\n\t\t\tlisteners.delete(listener);\n\t\t}\n\t}\n\n\t/**\n\t * Fires an event of the specified type. You can optionally provide a data\n\t * object — the first argument of the listener function will contain its\n\t * properties. The event can optionally be propagated to event parents.\n\t * @param {string} type\n\t * @param {object} [data]\n\t * @param {boolean} [propagate]\n\t * @returns {this}\n\t */\n\tfire(type, data, propagate) {\n\t\tif (!this.listens(type, propagate)) { return this; }\n\n\t\tconst event = {\n\t\t\t...data,\n\t\t\ttype,\n\t\t\ttarget: this,\n\t\t\tsourceTarget: data?.sourceTarget || this\n\t\t};\n\n\t\tif (this._events) {\n\t\t\tconst listeners = this._events[type];\n\t\t\tif (listeners) {\n\t\t\t\tthis._firingCount = (this._firingCount + 1) || 1;\n\t\t\t\tfor (const l of listeners) {\n\t\t\t\t\t// off overwrites l.fn, so we need to copy fn to a variable\n\t\t\t\t\tconst fn = l.fn;\n\t\t\t\t\tif (l.once) {\n\t\t\t\t\t\tthis.off(type, fn, l.ctx);\n\t\t\t\t\t}\n\t\t\t\t\tfn.call(l.ctx || this, event);\n\t\t\t\t}\n\n\t\t\t\tthis._firingCount--;\n\t\t\t}\n\t\t}\n\n\t\tif (propagate) {\n\t\t\t// propagate the event to parents (set with addEventParent)\n\t\t\tthis._propagateEvent(event);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns `true` if a particular event type has any listeners attached to it (or the\n\t * given listener function, with the given context). The verification can optionally\n\t * be propagated, it will return `true` if parents have the listener attached to it.\n\t * Called as `listens(type, propagate?)` or `listens(type, fn, context?, propagate?)`.\n\t * @param {string} type\n\t * @param {EventListener|boolean} [fn]\n\t * @param {object} [context]\n\t * @param {boolean} [propagate]\n\t * @returns {boolean}\n\t */\n\tlistens(type, fn, context, propagate) {\n\t\tif (typeof type !== 'string') {\n\t\t\tconsole.warn('\"string\" type argument expected');\n\t\t}\n\n\t\t// we don't overwrite the input `fn` value, because we need to use it for propagation\n\t\tlet _fn = fn;\n\t\tif (typeof fn !== 'function') {\n\t\t\tpropagate = !!fn;\n\t\t\t_fn = undefined;\n\t\t\tcontext = undefined;\n\t\t}\n\n\t\tif (this._events?.[type]?.size) {\n\t\t\tif (this._listens(type, _fn, context) !== false) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\tif (propagate) {\n\t\t\t// also check parents for listeners if event propagates\n\t\t\tfor (const p of Object.values(this._eventParents ?? {})) {\n\t\t\t\tif (p.listens(type, fn, context, propagate)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t// returns whether the given listener (or any listener, if no `fn` is given) is registered\n\t_listens(type, fn, context) {\n\t\tif (!this._events) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst listeners = this._events[type];\n\t\tif (!fn) {\n\t\t\treturn !!listeners?.size;\n\t\t}\n\n\t\tif (context === this) {\n\t\t\t// Less memory footprint.\n\t\t\tcontext = undefined;\n\t\t}\n\n\t\treturn !!this._listenerIndex?.[type]?.get(fn)?.has(context);\n\n\t}\n\n\t/**\n\t * Behaves as [`on(…)`](#evented-on), except the listener will only get fired once and then removed.\n\t * @param {string|Record<string, EventListener>} types\n\t * @param {EventListener|object} [fn]\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\tonce(types, fn, context) {\n\n\t\t// types can be a map of types/handlers\n\t\tif (typeof types === 'object') {\n\t\t\tfor (const [type, f] of Object.entries(types)) {\n\t\t\t\t// we don't process space-separated events here for performance;\n\t\t\t\t// it's a hot path since Layer uses the on(obj) syntax\n\t\t\t\tthis._on(type, f, fn, true);\n\t\t\t}\n\n\t\t} else {\n\t\t\t// types can be a string of space-separated words\n\t\t\tfor (const type of Util.splitWords(types)) {\n\t\t\t\tthis._on(type, fn, context, true);\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds an event parent - an `Evented` that will receive propagated events.\n\t * @param {Evented} obj\n\t * @returns {this}\n\t */\n\taddEventParent(obj) {\n\t\tthis._eventParents ??= {};\n\t\tthis._eventParents[Util.stamp(obj)] = obj;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes an event parent, so it will stop receiving propagated events.\n\t * @param {Evented} obj\n\t * @returns {this}\n\t */\n\tremoveEventParent(obj) {\n\t\tif (this._eventParents) {\n\t\t\tdelete this._eventParents[Util.stamp(obj)];\n\t\t}\n\t\treturn this;\n\t}\n\n\t_propagateEvent(e) {\n\t\tfor (const p of Object.values(this._eventParents ?? {})) {\n\t\t\t// `layer` is the Leaflet 1 name of `propagatedFrom`, left out of the types to steer new code to the new one\n\t\t\tp.fire(e.type, {\n\t\t\t\tlayer: e.target,\n\t\t\t\tpropagatedFrom: e.target,\n\t\t\t\t...e\n\t\t\t}, true);\n\t\t}\n\t}\n};\n"],"mappings":";;;AAGA,MAAM,+BAAe,IAAI,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuM7B,IAAa,UAAb,MAAa,gBAAgB,MAAM;;;;;;;;;;;;CAYlC,GAAG,OAAO,IAAI,SAAS;EAGtB,IAAI,OAAO,UAAU,UACpB,KAAK,MAAM,CAAC,MAAM,MAAM,OAAO,QAAQ,KAAK,GAG3C,KAAK,IAAI,MAAM,GAAG,EAAE;OAKrB,KAAK,MAAM,QAAQA,WAAgB,KAAK,GACvC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AM,IAAI,SAAS,IAAI;EAIlC,OAAO;CACR;;;;;;CAOA,eAAe,KAAK;EACnB,KAAK,kBAAkB,CAAC;EACxB,KAAK,cAAcE,MAAW,GAAG,KAAK;EACtC,OAAO;CACR;;;;;;CAOA,kBAAkB,KAAK;EACtB,IAAI,KAAK,eACR,OAAO,KAAK,cAAcA,MAAW,GAAG;EAEzC,OAAO;CACR;CAEA,gBAAgB,GAAG;EAClB,KAAK,MAAM,KAAK,OAAO,OAAO,KAAK,iBAAiB,CAAC,CAAC,GAErD,EAAE,KAAK,EAAE,MAAM;GACd,OAAO,EAAE;GACT,gBAAgB,EAAE;GAClB,GAAG;EACJ,GAAG,IAAI;CAET;AACD"}
@@ -9,6 +9,7 @@ var Util_exports = /* @__PURE__ */ __exportAll({
9
9
  stamp: () => stamp,
10
10
  template: () => template,
11
11
  throttle: () => throttle,
12
+ toNumber: () => toNumber,
12
13
  wrapNum: () => wrapNum
13
14
  });
14
15
  /**
@@ -83,11 +84,21 @@ function falseFn() {
83
84
  * @param {number|false} [precision]
84
85
  * @returns {number}
85
86
  */
86
- function formatNum(num, precision) {
87
+ function formatNum(num, precision = 6) {
87
88
  if (precision === false) return num;
88
- const pow = 10 ** (precision === void 0 ? 6 : precision);
89
+ const pow = 10 ** precision;
89
90
  return Math.round(num * pow) / pow;
90
91
  }
92
+ /**
93
+ * Returns `value` if it's a number (including `Infinity`), converts it if it's a
94
+ * numeric string, and returns `NaN` for anything else, unlike `Number()`, which turns
95
+ * `''`, `null` and booleans into `0` or `1`.
96
+ * @param {unknown} value
97
+ * @returns {number}
98
+ */
99
+ function toNumber(value) {
100
+ return typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? +value : NaN;
101
+ }
91
102
  const WHITESPACE_RE = /\s+/;
92
103
  /**
93
104
  * Trims and splits the string on whitespace and returns the array of parts.
@@ -95,7 +106,8 @@ const WHITESPACE_RE = /\s+/;
95
106
  * @returns {string[]}
96
107
  */
97
108
  function splitWords(str) {
98
- return str.trim().split(WHITESPACE_RE);
109
+ const trimmed = str.trim();
110
+ return WHITESPACE_RE.test(trimmed) ? trimmed.split(WHITESPACE_RE) : [trimmed];
99
111
  }
100
112
  /**
101
113
  * Merges the given properties to the `options` of the `obj` object, returning the
@@ -121,7 +133,7 @@ function getDefaultOptions(cls) {
121
133
  }
122
134
  return defaults;
123
135
  }
124
- const templateRe = /\{ *([\w_ -]+) *\}/g;
136
+ const templateRe = /\{ *([\w_ -]+?) *\}/g;
125
137
  /**
126
138
  * Simple templating facility, accepts a template string of the form `'Hello {a}, {b}'`
127
139
  * and a data object like `{a: 'foo', b: 'bar'}`, returns evaluated string
@@ -139,6 +151,6 @@ function template(str, data) {
139
151
  return value;
140
152
  });
141
153
  }
142
- export { Util_exports, falseFn, formatNum, lastId, setOptions, splitWords, stamp, template, throttle, wrapNum };
154
+ export { Util_exports, falseFn, formatNum, lastId, setOptions, splitWords, stamp, template, throttle, toNumber, wrapNum };
143
155
 
144
156
  //# sourceMappingURL=Util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Util.js","names":[],"sources":["../../../src/core/Util.js"],"sourcesContent":["// Util: various utility functions, used by Maplair internally.\n\n/**\n * Last unique ID used by [`stamp()`](#util-stamp).\n * @type {number}\n */\nexport let lastId = 0;\n\n/**\n * Returns the unique ID of an object, assigning it one if it doesn't have it.\n * @param {object} obj\n * @returns {number}\n */\nexport function stamp(obj) {\n\tif (!('_maplair_id' in obj)) {\n\t\tobj['_maplair_id'] = ++lastId;\n\t}\n\treturn obj._maplair_id;\n}\n\n/**\n * Returns a function which executes function `fn` with the given scope `context`\n * (so that the `this` keyword refers to `context` inside `fn`'s code). The function\n * `fn` will be called no more than one time per given amount of `time`. The arguments\n * received by the bound function will be any arguments passed when binding the\n * function, followed by any arguments passed when invoking the bound function.\n * @param {(...args: any[]) => void} fn\n * @param {number} time In milliseconds.\n * @param {object} [context]\n * @returns {(...args: any[]) => void}\n */\nexport function throttle(fn, time, context) {\n\tlet lock, queuedArgs;\n\n\tfunction later() {\n\t\t// reset lock and call if queued\n\t\tlock = false;\n\t\tif (queuedArgs) {\n\t\t\twrapperFn.apply(context, queuedArgs);\n\t\t\tqueuedArgs = false;\n\t\t}\n\t}\n\n\tfunction wrapperFn(...args) {\n\t\tif (lock) {\n\t\t\t// called too soon, queue to call later\n\t\t\tqueuedArgs = args;\n\n\t\t} else {\n\t\t\t// call and lock until later\n\t\t\tfn.apply(context, args);\n\t\t\tsetTimeout(later, time);\n\t\t\tlock = true;\n\t\t}\n\t}\n\n\treturn wrapperFn;\n}\n\n/**\n * Returns the number `x` modulo `range` in such a way so it lies within\n * `range[0]` and `range[1]`. The returned value will always be smaller than\n * `range[1]` unless `includeMax` is set to `true`.\n * @param {number} x\n * @param {[number, number]} range\n * @param {boolean} [includeMax]\n * @returns {number}\n */\nexport function wrapNum(x, range, includeMax) {\n\tconst max = range[1],\n\tmin = range[0],\n\td = max - min;\n\treturn x === max && includeMax ? x : ((x - min) % d + d) % d + min;\n}\n\n/**\n * A function which always returns `false`.\n * @returns {false}\n */\nexport function falseFn() { return false; }\n\n/**\n * Returns the number `num` rounded with specified `precision`.\n * The default `precision` value is 6 decimal places.\n * `false` can be passed to skip any processing (can be useful to avoid round-off errors).\n * @param {number} num\n * @param {number|false} [precision]\n * @returns {number}\n */\nexport function formatNum(num, precision) {\n\tif (precision === false) { return num; }\n\tconst pow = 10 ** (precision === undefined ? 6 : precision);\n\treturn Math.round(num * pow) / pow;\n}\n\nconst WHITESPACE_RE = /\\s+/;\n\n/**\n * Trims and splits the string on whitespace and returns the array of parts.\n * @param {string} str\n * @returns {string[]}\n */\nexport function splitWords(str) {\n\treturn str.trim().split(WHITESPACE_RE);\n}\n\n/**\n * Merges the given properties to the `options` of the `obj` object, returning the\n * resulting options. See `Class options`.\n * @param {object} obj\n * @param {object} [options]\n * @returns {object}\n */\nexport function setOptions(obj, options) {\n\tif (!Object.hasOwn(obj, 'options')) {\n\t\tconst defaults = getDefaultOptions(obj.constructor) ?? obj.options;\n\t\tobj.options = defaults ? Object.create(defaults) : {};\n\t}\n\tfor (const i in options) {\n\t\tif (Object.hasOwn(options, i)) {\n\t\t\tobj.options[i] = options[i];\n\t\t}\n\t}\n\treturn obj.options;\n}\n\nconst chainedDefaults = new WeakMap(); // class -> the defaultOptions object it was chained with\n\n// Links the `defaultOptions` of each class in the chain to its parent's, so defaults are inherited and stay live.\n// Done on first use because a static field can't do it in its initializer and stay tree-shakeable.\nfunction getDefaultOptions(cls) {\n\tconst defaults = cls?.defaultOptions;\n\tif (defaults && chainedDefaults.get(cls) !== defaults) {\n\t\tfor (let c = cls; c.defaultOptions; c = Object.getPrototypeOf(c)) {\n\t\t\tif (Object.hasOwn(c, 'defaultOptions')) {\n\t\t\t\tObject.setPrototypeOf(c.defaultOptions, Object.getPrototypeOf(c).defaultOptions ?? Object.prototype);\n\t\t\t}\n\t\t}\n\t\tchainedDefaults.set(cls, defaults);\n\t}\n\treturn defaults;\n}\n\nconst templateRe = /\\{ *([\\w_ -]+) *\\}/g;\n\n/**\n * Simple templating facility, accepts a template string of the form `'Hello {a}, {b}'`\n * and a data object like `{a: 'foo', b: 'bar'}`, returns evaluated string\n * `('Hello foo, bar')`. You can also specify functions instead of strings for\n * data values — they will be evaluated passing `data` as an argument.\n * @param {string} str\n * @param {Record<string, any>} data\n * @returns {string}\n */\nexport function template(str, data) {\n\treturn str.replace(templateRe, (str, key) => {\n\t\tlet value = data[key];\n\n\t\tif (value === undefined) {\n\t\t\tthrow new Error(`No value provided for variable ${str}`);\n\n\t\t} else if (typeof value === 'function') {\n\t\t\tvalue = value(data);\n\t\t}\n\t\treturn value;\n\t});\n}\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;AAMA,IAAW,SAAS;;;;;;AAOpB,SAAgB,MAAM,KAAK;CAC1B,IAAI,EAAE,iBAAiB,MACtB,IAAI,iBAAiB,EAAE;CAExB,OAAO,IAAI;AACZ;;;;;;;;;;;;AAaA,SAAgB,SAAS,IAAI,MAAM,SA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ACtD,KAAK,IAAI,IAAI,KAAK,EAAE,gBAAgB,IAAI,OAAO,eAAe,CAAC,GAC9D,IAAI,OAAO,OAAO,GAAG,gBAAgB,GACpC,OAAO,eAAe,EAAE,gBAAgB,OAAO,eAAe,CAAC,CAAC,CAAC,kBAAkB,OAAO,SAAS;EAGrG,gBAAgB,IAAI,KAAK,QAAQ;CAClC;CACA,OAAO;AACR;AAEA,MAAM,aAAa;;;;;;;;;;AAWnB,SAAgB,SAAS,KAAK,MAAM;CACnC,OAAO,IAAI,QAAQ,aAAa,KAAK,QAAQ;EAC5C,IAAI,QAAQ,KAAK;EAEjB,IAAI,UAAU,KAAA,GACb,MAAM,IAAI,MAAM,kCAAkC,KAAK;OAEjD,IAAI,OAAO,UAAU,YAC3B,QAAQ,MAAM,IAAI;EAEnB,OAAO;CACR,CAAC;AACF"}
1
+ {"version":3,"file":"Util.js","names":[],"sources":["../../../src/core/Util.js"],"sourcesContent":["// Util: various utility functions, used by Maplair internally.\n\n/**\n * Last unique ID used by [`stamp()`](#util-stamp).\n * @type {number}\n */\nexport let lastId = 0;\n\n/**\n * Returns the unique ID of an object, assigning it one if it doesn't have it.\n * @param {object} obj\n * @returns {number}\n */\nexport function stamp(obj) {\n\tif (!('_maplair_id' in obj)) {\n\t\tobj['_maplair_id'] = ++lastId;\n\t}\n\treturn obj._maplair_id;\n}\n\n/**\n * Returns a function which executes function `fn` with the given scope `context`\n * (so that the `this` keyword refers to `context` inside `fn`'s code). The function\n * `fn` will be called no more than one time per given amount of `time`. The arguments\n * received by the bound function will be any arguments passed when binding the\n * function, followed by any arguments passed when invoking the bound function.\n * @param {(...args: any[]) => void} fn\n * @param {number} time In milliseconds.\n * @param {object} [context]\n * @returns {(...args: any[]) => void}\n */\nexport function throttle(fn, time, context) {\n\tlet lock, queuedArgs;\n\n\tfunction later() {\n\t\t// reset lock and call if queued\n\t\tlock = false;\n\t\tif (queuedArgs) {\n\t\t\twrapperFn.apply(context, queuedArgs);\n\t\t\tqueuedArgs = false;\n\t\t}\n\t}\n\n\tfunction wrapperFn(...args) {\n\t\tif (lock) {\n\t\t\t// called too soon, queue to call later\n\t\t\tqueuedArgs = args;\n\n\t\t} else {\n\t\t\t// call and lock until later\n\t\t\tfn.apply(context, args);\n\t\t\tsetTimeout(later, time);\n\t\t\tlock = true;\n\t\t}\n\t}\n\n\treturn wrapperFn;\n}\n\n/**\n * Returns the number `x` modulo `range` in such a way so it lies within\n * `range[0]` and `range[1]`. The returned value will always be smaller than\n * `range[1]` unless `includeMax` is set to `true`.\n * @param {number} x\n * @param {[number, number]} range\n * @param {boolean} [includeMax]\n * @returns {number}\n */\nexport function wrapNum(x, range, includeMax) {\n\tconst max = range[1],\n\tmin = range[0],\n\td = max - min;\n\treturn x === max && includeMax ? x : ((x - min) % d + d) % d + min;\n}\n\n/**\n * A function which always returns `false`.\n * @returns {false}\n */\nexport function falseFn() { return false; }\n\n/**\n * Returns the number `num` rounded with specified `precision`.\n * The default `precision` value is 6 decimal places.\n * `false` can be passed to skip any processing (can be useful to avoid round-off errors).\n * @param {number} num\n * @param {number|false} [precision]\n * @returns {number}\n */\nexport function formatNum(num, precision = 6) {\n\tif (precision === false) { return num; }\n\tconst pow = 10 ** precision;\n\treturn Math.round(num * pow) / pow;\n}\n\n/**\n * Returns `value` if it's a number (including `Infinity`), converts it if it's a\n * numeric string, and returns `NaN` for anything else, unlike `Number()`, which turns\n * `''`, `null` and booleans into `0` or `1`.\n * @param {unknown} value\n * @returns {number}\n */\nexport function toNumber(value) {\n\treturn typeof value === 'number' ? value : typeof value === 'string' && value.trim() !== '' ? +value : NaN;\n}\n\nconst WHITESPACE_RE = /\\s+/;\n\n/**\n * Trims and splits the string on whitespace and returns the array of parts.\n * @param {string} str\n * @returns {string[]}\n */\nexport function splitWords(str) {\n\t// a single word is the common case, and splitting allocates a lot more than the array\n\tconst trimmed = str.trim();\n\treturn WHITESPACE_RE.test(trimmed) ? trimmed.split(WHITESPACE_RE) : [trimmed];\n}\n\n/**\n * Merges the given properties to the `options` of the `obj` object, returning the\n * resulting options. See `Class options`.\n * @param {object} obj\n * @param {object} [options]\n * @returns {object}\n */\nexport function setOptions(obj, options) {\n\tif (!Object.hasOwn(obj, 'options')) {\n\t\tconst defaults = getDefaultOptions(obj.constructor) ?? obj.options;\n\t\tobj.options = defaults ? Object.create(defaults) : {};\n\t}\n\tfor (const i in options) {\n\t\tif (Object.hasOwn(options, i)) {\n\t\t\tobj.options[i] = options[i];\n\t\t}\n\t}\n\treturn obj.options;\n}\n\nconst chainedDefaults = new WeakMap(); // class -> the defaultOptions object it was chained with\n\n// Links the `defaultOptions` of each class in the chain to its parent's, so defaults are inherited and stay live.\n// Done on first use because a static field can't do it in its initializer and stay tree-shakeable.\nfunction getDefaultOptions(cls) {\n\tconst defaults = cls?.defaultOptions;\n\tif (defaults && chainedDefaults.get(cls) !== defaults) {\n\t\tfor (let c = cls; c.defaultOptions; c = Object.getPrototypeOf(c)) {\n\t\t\tif (Object.hasOwn(c, 'defaultOptions')) {\n\t\t\t\tObject.setPrototypeOf(c.defaultOptions, Object.getPrototypeOf(c).defaultOptions ?? Object.prototype);\n\t\t\t}\n\t\t}\n\t\tchainedDefaults.set(cls, defaults);\n\t}\n\treturn defaults;\n}\n\nconst templateRe = /\\{ *([\\w_ -]+?) *\\}/g;\n\n/**\n * Simple templating facility, accepts a template string of the form `'Hello {a}, {b}'`\n * and a data object like `{a: 'foo', b: 'bar'}`, returns evaluated string\n * `('Hello foo, bar')`. You can also specify functions instead of strings for\n * data values — they will be evaluated passing `data` as an argument.\n * @param {string} str\n * @param {Record<string, any>} data\n * @returns {string}\n */\nexport function template(str, data) {\n\treturn str.replace(templateRe, (str, key) => {\n\t\tlet value = data[key];\n\n\t\tif (value === undefined) {\n\t\t\tthrow new Error(`No value provided for variable ${str}`);\n\n\t\t} else if (typeof value === 'function') {\n\t\t\tvalue = value(data);\n\t\t}\n\t\treturn value;\n\t});\n}\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;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BAAkB,IAAI,WAAW,KAAK,IAAI;EAC3D,IAAI,UAAU,WAAW,OAAO,OAAO,QAAQ,IAAI,CAAC;CACrD;CACA,KAAK,MAAM,KAAK,SACf,IAAI,OAAO,OAAO,SAAS,CAAC,GAC3B,IAAI,QAAQ,KAAK,QAAQ;CAG3B,OAAO,IAAI;AACZ;AAEA,MAAM,kCAAkB,IAAI,QAAQ;AAIpC,SAAS,kBAAkB,KAAK;CAC/B,MAAM,WAAW,KAAK;CACtB,IAAI,YAAY,gBAAgB,IAAI,GAAG,MAAM,UAAU;EACtD,KAAK,IAAI,IAAI,KAAK,EAAE,gBAAgB,IAAI,OAAO,eAAe,CAAC,GAC9D,IAAI,OAAO,OAAO,GAAG,gBAAgB,GACpC,OAAO,eAAe,EAAE,gBAAgB,OAAO,eAAe,CAAC,CAAC,CAAC,kBAAkB,OAAO,SAAS;EAGrG,gBAAgB,IAAI,KAAK,QAAQ;CAClC;CACA,OAAO;AACR;AAEA,MAAM,aAAa;;;;;;;;;;AAWnB,SAAgB,SAAS,KAAK,MAAM;CACnC,OAAO,IAAI,QAAQ,aAAa,KAAK,QAAQ;EAC5C,IAAI,QAAQ,KAAK;EAEjB,IAAI,UAAU,KAAA,GACb,MAAM,IAAI,MAAM,kCAAkC,KAAK;OAEjD,IAAI,OAAO,UAAU,YAC3B,QAAQ,MAAM,IAAI;EAEnB,OAAO;CACR,CAAC;AACF"}
@@ -3,9 +3,12 @@ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
3
3
  var DomEvent_PointerEvents_exports = /* @__PURE__ */ __exportAll({
4
4
  disablePointerDetection: () => disablePointerDetection,
5
5
  enablePointerDetection: () => enablePointerDetection,
6
- getPointers: () => getPointers
6
+ getPointers: () => getPointers,
7
+ isClickDisabled: () => isClickDisabled,
8
+ simulateDblclick: () => simulateDblclick
7
9
  });
8
10
  const activePointers = /* @__PURE__ */ new Map();
11
+ let lastPointerType;
9
12
  /**
10
13
  * Enables pointer detection and capture for the document.
11
14
  * @group Pointer detection
@@ -31,7 +34,24 @@ function disablePointerDetection(el) {
31
34
  el.removeEventListener("pointerup", _onDelete, { capture: true });
32
35
  el.removeEventListener("pointercancel", _onDelete, { capture: true });
33
36
  }
37
+ /**
38
+ * Whether `el` is inside an element that `DomEvent.disableClickPropagation` was called
39
+ * on (before reaching `container`), or detached from the DOM.
40
+ * @internal
41
+ * @param {Node|null} el
42
+ * @param {EventTarget|null} container
43
+ * @returns {boolean}
44
+ */
45
+ function isClickDisabled(el, container) {
46
+ while (el && el !== container) {
47
+ if (el["_maplair_disable_click"] || !el.parentNode) return true;
48
+ el = el.parentNode;
49
+ }
50
+ return false;
51
+ }
34
52
  function _onSet(e) {
53
+ lastPointerType = e.pointerType;
54
+ if (isClickDisabled(e.target, e.currentTarget)) return;
35
55
  if (e.isTrusted) e.target.setPointerCapture(e.pointerId);
36
56
  activePointers.set(e.pointerId, e);
37
57
  }
@@ -50,6 +70,56 @@ function _onDelete(e) {
50
70
  function getPointers() {
51
71
  return [...activePointers.values()];
52
72
  }
53
- export { DomEvent_PointerEvents_exports, disablePointerDetection, enablePointerDetection, getPointers };
73
+ const dblclickProps = [
74
+ "bubbles",
75
+ "cancelable",
76
+ "composed",
77
+ "view",
78
+ "screenX",
79
+ "screenY",
80
+ "clientX",
81
+ "clientY",
82
+ "ctrlKey",
83
+ "shiftKey",
84
+ "altKey",
85
+ "metaKey",
86
+ "button",
87
+ "buttons",
88
+ "relatedTarget"
89
+ ];
90
+ let lastClickTime = 0;
91
+ let lastClick;
92
+ let lastClickMap;
93
+ let clickCount = 0;
94
+ /**
95
+ * Fires a `dblclick` on double tap where the browser doesn't (like iOS Safari),
96
+ * which is where it always reports `detail: 1` on clicks (see Leaflet#7012). The
97
+ * pointer type comes from `pointerdown`, because iOS Safari reports `mouse` on
98
+ * clicks from touch (WebKit bug 282988). Called by the map for clicks in it.
99
+ * @internal
100
+ * @param {MouseEvent} e
101
+ * @param {HTMLElement} mapContainer The container of the map, two taps make a double
102
+ * tap only in the same map.
103
+ * @returns {void}
104
+ */
105
+ function simulateDblclick(e, mapContainer) {
106
+ if (e === lastClick) return;
107
+ lastClick = e;
108
+ const target = e.target;
109
+ if (e.detail !== 1 || lastPointerType === "mouse" || target.closest("label")) {
110
+ clickCount = 0;
111
+ return;
112
+ }
113
+ const now = Date.now();
114
+ clickCount = now - lastClickTime <= 200 && mapContainer === lastClickMap ? clickCount + 1 : 1;
115
+ lastClickTime = now;
116
+ lastClickMap = mapContainer;
117
+ if (clickCount === 2) {
118
+ const init = { detail: 2 };
119
+ for (const prop of dblclickProps) init[prop] = e[prop];
120
+ target.dispatchEvent(new MouseEvent("dblclick", init));
121
+ }
122
+ }
123
+ export { DomEvent_PointerEvents_exports, disablePointerDetection, enablePointerDetection, getPointers, isClickDisabled, simulateDblclick };
54
124
 
55
125
  //# sourceMappingURL=DomEvent.PointerEvents.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DomEvent.PointerEvents.js","names":[],"sources":["../../../src/dom/DomEvent.PointerEvents.js"],"sourcesContent":["// DomEvent.PointerEvents: detects the pointers that are currently active on the\n// document.\n\nconst activePointers = new Map();\n\n/**\n * Enables pointer detection and capture for the document.\n * @group Pointer detection\n * @param {EventTarget} el\n * @returns {void}\n */\nfunction enablePointerDetection(el) {\n\tel.addEventListener('pointerdown', _onSet, {capture: true});\n\tel.addEventListener('pointermove', _onUpdate, {capture: true});\n\tel.addEventListener('pointerup', _onDelete, {capture: true});\n\tel.addEventListener('pointercancel', _onDelete, {capture: true});\n\tactivePointers.clear();\n}\n\n/**\n * Disables pointer detection and capture for the document.\n * @group Pointer detection\n * @param {EventTarget} el\n * @returns {void}\n */\nfunction disablePointerDetection(el) {\n\tel.removeEventListener('pointerdown', _onSet, {capture: true});\n\tel.removeEventListener('pointermove', _onUpdate, {capture: true});\n\tel.removeEventListener('pointerup', _onDelete, {capture: true});\n\tel.removeEventListener('pointercancel', _onDelete, {capture: true});\n}\n\n// capturing throws for synthetic pointers the browser doesn't know about, so only capture real ones\nfunction _onSet(e) {\n\tif (e.isTrusted) { e.target.setPointerCapture(e.pointerId); }\n\tactivePointers.set(e.pointerId, e);\n}\n\nfunction _onUpdate(e) {\n\tif (activePointers.has(e.pointerId)) {\n\t\tactivePointers.set(e.pointerId, e);\n\t}\n}\n\nfunction _onDelete(e) {\n\t// released already if the document has nested maps (e.g. an overview map)\n\tif (e.target.hasPointerCapture(e.pointerId)) {\n\t\te.target.releasePointerCapture(e.pointerId);\n\t}\n\tactivePointers.delete(e.pointerId);\n}\n\n/**\n * Returns the active pointers on the document.\n * @group Pointer detection\n * @returns {PointerEvent[]}\n */\nfunction getPointers() {\n\treturn [...activePointers.values()];\n}\n\nexport {\n\tenablePointerDetection,\n\tdisablePointerDetection,\n\tgetPointers\n};\n\n"],"mappings":";;;;;;;AAGA,MAAM,iCAAiB,IAAI,IAAI;;;;;;;AAQ/B,SAAS,uBAAuB,IAAI;CACnC,GAAG,iBAAiB,eAAe,QAAQ,EAAC,SAAS,KAAI,CAAC;CAC1D,GAAG,iBAAiB,eAAe,WAAW,EAAC,SAAS,KAAI,CAAC;CAC7D,GAAG,iBAAiB,aAAa,WAAW,EAAC,SAAS,KAAI,CAAC;CAC3D,GAAG,iBAAiB,iBAAiB,WAAW,EAAC,SAAS,KAAI,CAAC;CAC/D,eAAe,MAAM;AACtB;;;;;;;AAQA,SAAS,wBAAwB,IAAI;CACpC,GAAG,oBAAoB,eAAe,QAAQ,EAAC,SAAS,KAAI,CAAC;CAC7D,GAAG,oBAAoB,eAAe,WAAW,EAAC,SAAS,KAAI,CAAC;CAChE,GAAG,oBAAoB,aAAa,WAAW,EAAC,SAAS,KAAI,CAAC;CAC9D,GAAG,oBAAoB,iBAAiB,WAAW,EAAC,SAAS,KAAI,CAAC;AACnE;AAGA,SAAS,OAAO,GAAG;CAClB,IAAI,EAAE,WAAa,EAAE,OAAO,kBAAkB,EAAE,SAAS;CACzD,eAAe,IAAI,EAAE,WAAW,CAAC;AAClC;AAEA,SAAS,UAAU,GAAG;CACrB,IAAI,eAAe,IAAI,EAAE,SAAS,GACjC,eAAe,IAAI,EAAE,WAAW,CAAC;AAEnC;AAEA,SAAS,UAAU,GAAG;CAErB,IAAI,EAAE,OAAO,kBAAkB,EAAE,SAAS,GACzC,EAAE,OAAO,sBAAsB,EAAE,SAAS;CAE3C,eAAe,OAAO,EAAE,SAAS;AAClC;;;;;;AAOA,SAAS,cAAc;CACtB,OAAO,CAAC,GAAG,eAAe,OAAO,CAAC;AACnC"}
1
+ {"version":3,"file":"DomEvent.PointerEvents.js","names":[],"sources":["../../../src/dom/DomEvent.PointerEvents.js"],"sourcesContent":["// DomEvent.PointerEvents: detects the pointers that are currently active on the\n// document.\n\nconst activePointers = new Map();\n\nlet lastPointerType;\n\n/**\n * Enables pointer detection and capture for the document.\n * @group Pointer detection\n * @param {EventTarget} el\n * @returns {void}\n */\nfunction enablePointerDetection(el) {\n\tel.addEventListener('pointerdown', _onSet, {capture: true});\n\tel.addEventListener('pointermove', _onUpdate, {capture: true});\n\tel.addEventListener('pointerup', _onDelete, {capture: true});\n\tel.addEventListener('pointercancel', _onDelete, {capture: true});\n\tactivePointers.clear();\n}\n\n/**\n * Disables pointer detection and capture for the document.\n * @group Pointer detection\n * @param {EventTarget} el\n * @returns {void}\n */\nfunction disablePointerDetection(el) {\n\tel.removeEventListener('pointerdown', _onSet, {capture: true});\n\tel.removeEventListener('pointermove', _onUpdate, {capture: true});\n\tel.removeEventListener('pointerup', _onDelete, {capture: true});\n\tel.removeEventListener('pointercancel', _onDelete, {capture: true});\n}\n\n/**\n * Whether `el` is inside an element that `DomEvent.disableClickPropagation` was called\n * on (before reaching `container`), or detached from the DOM.\n * @internal\n * @param {Node|null} el\n * @param {EventTarget|null} container\n * @returns {boolean}\n */\nfunction isClickDisabled(el, container) {\n\twhile (el && el !== container) {\n\t\tif (el['_maplair_disable_click'] || !el.parentNode) { return true; }\n\t\tel = el.parentNode;\n\t}\n\treturn false;\n}\n\nfunction _onSet(e) {\n\tlastPointerType = e.pointerType;\n\t// pointers in controls and popups can't start map interactions, and capturing them breaks native widgets there\n\t// (like the clear button of a search input), so leave them to the browser\n\tif (isClickDisabled(e.target, e.currentTarget)) { return; }\n\t// capturing throws for synthetic pointers the browser doesn't know about, so only capture real ones\n\tif (e.isTrusted) { e.target.setPointerCapture(e.pointerId); }\n\tactivePointers.set(e.pointerId, e);\n}\n\nfunction _onUpdate(e) {\n\tif (activePointers.has(e.pointerId)) {\n\t\tactivePointers.set(e.pointerId, e);\n\t}\n}\n\nfunction _onDelete(e) {\n\t// released already if the document has nested maps (e.g. an overview map)\n\tif (e.target.hasPointerCapture(e.pointerId)) {\n\t\te.target.releasePointerCapture(e.pointerId);\n\t}\n\tactivePointers.delete(e.pointerId);\n}\n\n/**\n * Returns the active pointers on the document.\n * @group Pointer detection\n * @returns {PointerEvent[]}\n */\nfunction getPointers() {\n\treturn [...activePointers.values()];\n}\n\nconst dblclickProps = ['bubbles', 'cancelable', 'composed', 'view', 'screenX', 'screenY', 'clientX', 'clientY',\n\t'ctrlKey', 'shiftKey', 'altKey', 'metaKey', 'button', 'buttons', 'relatedTarget'];\n\nlet lastClickTime = 0,\nlastClick,\nlastClickMap,\nclickCount = 0;\n\n/**\n * Fires a `dblclick` on double tap where the browser doesn't (like iOS Safari),\n * which is where it always reports `detail: 1` on clicks (see Leaflet#7012). The\n * pointer type comes from `pointerdown`, because iOS Safari reports `mouse` on\n * clicks from touch (WebKit bug 282988). Called by the map for clicks in it.\n * @internal\n * @param {MouseEvent} e\n * @param {HTMLElement} mapContainer The container of the map, two taps make a double\n * tap only in the same map.\n * @returns {void}\n */\nfunction simulateDblclick(e, mapContainer) {\n\t// a click in a nested map (e.g. an overview map) counts for the innermost one only\n\tif (e === lastClick) { return; }\n\tlastClick = e;\n\tconst target = e.target;\n\n\t// a click on a label is followed by a click on its input, so it would count as a double tap\n\tif (e.detail !== 1 || lastPointerType === 'mouse' || target.closest('label')) {\n\t\tclickCount = 0;\n\t\treturn;\n\t}\n\tconst now = Date.now();\n\tclickCount = now - lastClickTime <= 200 && mapContainer === lastClickMap ? clickCount + 1 : 1;\n\tlastClickTime = now;\n\tlastClickMap = mapContainer;\n\n\tif (clickCount === 2) {\n\t\tconst init = {detail: 2};\n\t\tfor (const prop of dblclickProps) { init[prop] = e[prop]; }\n\t\ttarget.dispatchEvent(new MouseEvent('dblclick', init));\n\t}\n}\n\nexport {\n\tenablePointerDetection,\n\tdisablePointerDetection,\n\tgetPointers,\n\tisClickDisabled,\n\tsimulateDblclick\n};\n\n"],"mappings":";;;;;;;;;AAGA,MAAM,iCAAiB,IAAI,IAAI;AAE/B,IAAI;;;;;;;AAQJ,SAAS,uBAAuB,IAAI;CACnC,GAAG,iBAAiB,eAAe,QAAQ,EAAC,SAAS,KAAI,CAAC;CAC1D,GAAG,iBAAiB,eAAe,WAAW,EAAC,SAAS,KAAI,CAAC;CAC7D,GAAG,iBAAiB,aAAa,WAAW,EAAC,SAAS,KAAI,CAAC;CAC3D,GAAG,iBAAiB,iBAAiB,WAAW,EAAC,SAAS,KAAI,CAAC;CAC/D,eAAe,MAAM;AACtB;;;;;;;AAQA,SAAS,wBAAwB,IAAI;CACpC,GAAG,oBAAoB,eAAe,QAAQ,EAAC,SAAS,KAAI,CAAC;CAC7D,GAAG,oBAAoB,eAAe,WAAW,EAAC,SAAS,KAAI,CAAC;CAChE,GAAG,oBAAoB,aAAa,WAAW,EAAC,SAAS,KAAI,CAAC;CAC9D,GAAG,oBAAoB,iBAAiB,WAAW,EAAC,SAAS,KAAI,CAAC;AACnE;;;;;;;;;AAUA,SAAS,gBAAgB,IAAI,WAAW;CACvC,OAAO,MAAM,OAAO,WAAW;EAC9B,IAAI,GAAG,6BAA6B,CAAC,GAAG,YAAc,OAAO;EAC7D,KAAK,GAAG;CACT;CACA,OAAO;AACR;AAEA,SAAS,OAAO,GAAG;CAClB,kBAAkB,EAAE;CAGpB,IAAI,gBAAgB,EAAE,QAAQ,EAAE,aAAa,GAAK;CAElD,IAAI,EAAE,WAAa,EAAE,OAAO,kBAAkB,EAAE,SAAS;CACzD,eAAe,IAAI,EAAE,WAAW,CAAC;AAClC;AAEA,SAAS,UAAU,GAAG;CACrB,IAAI,eAAe,IAAI,EAAE,SAAS,GACjC,eAAe,IAAI,EAAE,WAAW,CAAC;AAEnC;AAEA,SAAS,UAAU,GAAG;CAErB,IAAI,EAAE,OAAO,kBAAkB,EAAE,SAAS,GACzC,EAAE,OAAO,sBAAsB,EAAE,SAAS;CAE3C,eAAe,OAAO,EAAE,SAAS;AAClC;;;;;;AAOA,SAAS,cAAc;CACtB,OAAO,CAAC,GAAG,eAAe,OAAO,CAAC;AACnC;AAEA,MAAM,gBAAgB;CAAC;CAAW;CAAc;CAAY;CAAQ;CAAW;CAAW;CAAW;CACpG;CAAW;CAAY;CAAU;CAAW;CAAU;CAAW;AAAe;AAEjF,IAAI,gBAAgB;AACpB,IAAA;AACA,IAAA;AACA,IAAA,aAAa;;;;;;;;;;;;AAab,SAAS,iBAAiB,GAAG,cAAc;CAE1C,IAAI,MAAM,WAAa;CACvB,YAAY;CACZ,MAAM,SAAS,EAAE;CAGjB,IAAI,EAAE,WAAW,KAAK,oBAAoB,WAAW,OAAO,QAAQ,OAAO,GAAG;EAC7E,aAAa;EACb;CACD;CACA,MAAM,MAAM,KAAK,IAAI;CACrB,aAAa,MAAM,iBAAiB,OAAO,iBAAiB,eAAe,aAAa,IAAI;CAC5F,gBAAgB;CAChB,eAAe;CAEf,IAAI,eAAe,GAAG;EACrB,MAAM,OAAO,EAAC,QAAQ,EAAC;EACvB,KAAK,MAAM,QAAQ,eAAiB,KAAK,QAAQ,EAAE;EACnD,OAAO,cAAc,IAAI,WAAW,YAAY,IAAI,CAAC;CACtD;AACD"}
@@ -1,7 +1,6 @@
1
1
  import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
2
  import { splitWords, stamp } from "../core/Util.js";
3
3
  import { Point } from "../geometry/Point.js";
4
- import { addDoubleTapListener, removeDoubleTapListener } from "./DomEvent.DoubleTap.js";
5
4
  import { DomEvent_PointerEvents_exports } from "./DomEvent.PointerEvents.js";
6
5
  import { getScale } from "./DomUtil.js";
7
6
  // src/dom/DomEvent.js
@@ -71,11 +70,10 @@ function batchRemove(obj, filterFn) {
71
70
  function addOne(obj, type, fn, context) {
72
71
  const id = type + stamp(fn) + (context ? `_${stamp(context)}` : "");
73
72
  if (obj[eventsKey] && obj[eventsKey][id]) return;
74
- let handler = function(e) {
73
+ const handler = function(e) {
75
74
  return fn.call(context || obj, e);
76
75
  };
77
- if (type === "dblclick") handler = addDoubleTapListener(obj, handler);
78
- else obj.addEventListener(type, handler, type === "wheel" ? { passive: false } : false);
76
+ obj.addEventListener(type, handler, type === "wheel" ? { passive: false } : false);
79
77
  obj[eventsKey] ??= {};
80
78
  obj[eventsKey][id] = handler;
81
79
  }
@@ -83,8 +81,7 @@ function removeOne(obj, type, fn, context, id) {
83
81
  id ??= type + stamp(fn) + (context ? `_${stamp(context)}` : "");
84
82
  const handler = obj[eventsKey] && obj[eventsKey][id];
85
83
  if (!handler) return;
86
- if (type === "dblclick") removeDoubleTapListener(obj, handler);
87
- else obj.removeEventListener(type, handler, false);
84
+ obj.removeEventListener(type, handler, false);
88
85
  obj[eventsKey][id] = null;
89
86
  }
90
87
  /**
@@ -170,7 +167,7 @@ function getWheelPxFactor() {
170
167
  * @returns {number}
171
168
  */
172
169
  function getWheelDelta(e) {
173
- return e.deltaY && e.deltaMode === 0 ? -e.deltaY / getWheelPxFactor() : e.deltaY && e.deltaMode === 1 ? -e.deltaY * 20 : e.deltaY && e.deltaMode === 2 ? -e.deltaY * 60 : e.deltaX || e.deltaZ ? 0 : 0;
170
+ return -e.deltaY * (e.deltaMode ? e.deltaMode === 1 ? 20 : 60 : 1 / getWheelPxFactor()) || 0;
174
171
  }
175
172
  /**
176
173
  * Checks if the pointer really left/entered the element `el` (for
@@ -1 +1 @@
1
- {"version":3,"file":"DomEvent.js","names":["Util.splitWords","Util.stamp"],"sources":["../../../src/dom/DomEvent.js"],"sourcesContent":["import {Point} from '../geometry/Point.js';\nimport * as Util from '../core/Util.js';\nimport {addDoubleTapListener, removeDoubleTapListener} from './DomEvent.DoubleTap.js';\nimport {getScale} from './DomUtil.js';\n\nimport * as PointerEvents from './DomEvent.PointerEvents.js';\nexport {PointerEvents};\n\n// DomEvent: utility functions to work with the\n// [DOM events](https://developer.mozilla.org/docs/Web/API/Event), used by Maplair\n// internally. The functions return the `DomEvent` namespace for chaining.\n\n// Inspired by John Resig, Dean Edwards and YUI addEvent implementations.\n\n/**\n * Adds a listener function (`fn`) to a particular DOM event type of the\n * element `obj`. You can optionally specify the context of the listener\n * (object the `this` keyword will point to). You can also pass several\n * space-separated types (e.g. `'click dblclick'`). Alternatively, adds a set of\n * type/listener pairs, e.g. `{click: onClick, pointermove: onPointerMove}`, with the\n * context as third argument.\n * @param {EventTarget} obj\n * @param {string|Record<string, (ev: any) => void>} types\n * @param {((ev: any) => void)|object} [fn]\n * @param {object} [context]\n * @returns {void}\n */\nexport function on(obj, types, fn, context) {\n\n\tif (types && typeof types === 'object') {\n\t\tfor (const [type, listener] of Object.entries(types)) {\n\t\t\taddOne(obj, type, listener, fn);\n\t\t}\n\t} else {\n\t\tfor (const type of Util.splitWords(types)) {\n\t\t\taddOne(obj, type, fn, context);\n\t\t}\n\t}\n}\n\nconst eventsKey = '_maplair_events';\n\n/**\n * Removes a previously added listener function.\n * Note that if you passed a custom context to on, you must pass the same\n * context to `off` in order to remove the listener. Alternatively, removes a set of\n * type/listener pairs, e.g. `{click: onClick, pointermove: onPointerMove}`; with\n * `types` only, removes all previously added listeners of given types; with the\n * element only, removes all previously added listeners from the given element.\n * @param {EventTarget} obj\n * @param {string|Record<string, (ev: any) => void>} [types]\n * @param {((ev: any) => void)|object} [fn]\n * @param {object} [context]\n * @returns {void}\n */\nexport function off(obj, types, fn, context) {\n\n\tif (arguments.length === 1) {\n\t\tbatchRemove(obj);\n\t\tdelete obj[eventsKey];\n\n\t} else if (types && typeof types === 'object') {\n\t\tfor (const [type, listener] of Object.entries(types)) {\n\t\t\tremoveOne(obj, type, listener, fn);\n\t\t}\n\n\t} else {\n\t\ttypes = Util.splitWords(types);\n\n\t\tif (arguments.length === 2) {\n\t\t\tbatchRemove(obj, type => types.includes(type));\n\t\t} else {\n\t\t\tfor (const type of types) {\n\t\t\t\tremoveOne(obj, type, fn, context);\n\t\t\t}\n\t\t}\n\t}\n}\n\nconst DIGIT_RE = /\\d/;\n\nfunction batchRemove(obj, filterFn) {\n\tfor (const id of Object.keys(obj[eventsKey] ?? {})) {\n\t\tconst type = id.split(DIGIT_RE)[0];\n\t\tif (!filterFn || filterFn(type)) {\n\t\t\tremoveOne(obj, type, null, null, id);\n\t\t}\n\t}\n}\n\nfunction addOne(obj, type, fn, context) {\n\tconst id = type + Util.stamp(fn) + (context ? `_${Util.stamp(context)}` : '');\n\n\tif (obj[eventsKey] && obj[eventsKey][id]) { return; }\n\n\tlet handler = function (e) {\n\t\treturn fn.call(context || obj, e);\n\t};\n\n\tif (type === 'dblclick') {\n\t\thandler = addDoubleTapListener(obj, handler);\n\t} else {\n\t\tobj.addEventListener(type, handler, type === 'wheel' ? {passive: false} : false);\n\t}\n\n\tobj[eventsKey] ??= {};\n\tobj[eventsKey][id] = handler;\n}\n\nfunction removeOne(obj, type, fn, context, id) {\n\tid ??= type + Util.stamp(fn) + (context ? `_${Util.stamp(context)}` : '');\n\tconst handler = obj[eventsKey] && obj[eventsKey][id];\n\n\tif (!handler) { return; }\n\n\tif (type === 'dblclick') {\n\t\tremoveDoubleTapListener(obj, handler);\n\t} else {\n\t\tobj.removeEventListener(type, handler, false);\n\t}\n\n\tobj[eventsKey][id] = null;\n}\n\n/**\n * Stop the given event from propagation to parent elements. Used inside the listener\n * functions:\n * ```js\n * DomEvent.on(div, 'click', DomEvent.stopPropagation);\n * ```\n * Also accepts a Maplair event with an `originalEvent`.\n * @param {Event|{originalEvent: Event}} e\n * @returns {void}\n */\nexport function stopPropagation(e) {\n\n\t// feature detection rather than `instanceof Event`, which fails for events from other windows (e.g. iframes)\n\tif (e.stopPropagation) {\n\t\te.stopPropagation();\n\t} else if (e.originalEvent) { // In case of Maplair event.\n\t\te.originalEvent._stopped = true;\n\t} else {\n\t\t// custom Maplair event\n\t\tconsole.debug('Unsupported event', e);\n\t}\n}\n\n/**\n * Adds `stopPropagation` to the element's `'wheel'` events (plus browser variants).\n * @param {HTMLElement} el\n * @returns {void}\n */\nexport function disableScrollPropagation(el) {\n\taddOne(el, 'wheel', stopPropagation);\n}\n\n/**\n * Adds `stopPropagation` to the element's `'dblclick'`, `'contextmenu'`\n * and `'pointerdown'` events (plus browser variants).\n * For `'click'` events, prevents the map from handling the click\n * while still allowing the native DOM click event to propagate normally.\n * @param {HTMLElement} el\n * @returns {void}\n */\nexport function disableClickPropagation(el) {\n\ton(el, 'pointerdown dblclick contextmenu', stopPropagation);\n\tel['_maplair_disable_click'] = true;\n}\n\n/**\n * Prevents the default action of the DOM Event `e` from happening (such as\n * following a link in the href of the a element, or doing a POST request\n * with page reload when a `<form>` is submitted).\n * Use it inside listener functions.\n * @param {Event} e\n * @returns {void}\n */\nexport function preventDefault(e) {\n\te.preventDefault?.();\n}\n\n/**\n * Does `stopPropagation` and `preventDefault` at the same time.\n * @param {Event} e\n * @returns {void}\n */\nexport function stop(e) {\n\tpreventDefault(e);\n\tstopPropagation(e);\n}\n\n/**\n * Gets normalized pointer position from a DOM event relative to the\n * `container` (border excluded) or to the whole page if not specified.\n * @param {MouseEvent|Touch} e\n * @param {HTMLElement} [container]\n * @returns {Point}\n */\nexport function getPointerPosition(e, container) {\n\tif (!container) {\n\t\treturn new Point(e.clientX, e.clientY);\n\t}\n\n\tconst scale = getScale(container),\n\toffset = scale.boundingClientRect; // left and top values are in page scale (like the event clientX/Y)\n\n\treturn new Point(\n\t\t// offset.left/top values are in page scale (like clientX/Y),\n\t\t// whereas clientLeft/Top (border width) values are the original values (before CSS scale applies).\n\t\t(e.clientX - offset.left) / scale.x - container.clientLeft,\n\t\t(e.clientY - offset.top) / scale.y - container.clientTop\n\t);\n}\n\n/**\n * Gets the wheel pixel factor based on the devicePixelRatio.\n * @returns {number}\n */\nexport function getWheelPxFactor() {\n\t// We need double the scroll pixels (see #7403 and #4538)\n\treturn window.devicePixelRatio * 2;\n}\n\n/**\n * Gets normalized wheel delta from a wheel DOM event, in vertical\n * pixels scrolled (negative if scrolling down).\n * Events from pointing devices without precise scrolling are mapped to\n * a best guess of 60 pixels.\n * @param {WheelEvent} e\n * @returns {number}\n */\nexport function getWheelDelta(e) {\n\treturn (e.deltaY && e.deltaMode === 0) ? -e.deltaY / getWheelPxFactor() : // Pixels\n\t\t(e.deltaY && e.deltaMode === 1) ? -e.deltaY * 20 : // Lines\n\t\t(e.deltaY && e.deltaMode === 2) ? -e.deltaY * 60 : // Pages\n\t\t(e.deltaX || e.deltaZ) ? 0 :\t// Skip horizontal/depth wheel events\n\t\t0;\n}\n\n/**\n * Checks if the pointer really left/entered the element `el` (for\n * `pointerover`/`pointerout`).\n * @internal\n * @param {Node} el\n * @param {MouseEvent} e\n * @returns {boolean}\n */\nexport function isExternalTarget(el, e) {\n\treturn !el.contains(e.relatedTarget);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,GAAG,KAAK,OAAO,IAAI,SAAS;CAE3C,IAAI,SAAS,OAAO,UAAU,UAC7B,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,KAAK,GAClD,OAAO,KAAK,MAAM,UAAU,EAAE;MAG/B,KAAK,MAAM,QAAQA,WAAgB,KAAK,GACvC,OAAO,KAAK,MAAM,IAAI,OAAO;AAGhC;AAEA,MAAM,YAAY;;;;;;;;;;;;;;AAelB,SAAgB,IAAI,KAAK,OAAO,IAAI,SAAS;CAE5C,IAAI,UAAU,WAAW,GAAG;EAC3B,YAAY,GAAG;EACf,OAAO,IAAI;CAEZ,OAAO,IAAI,SAAS,O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"file":"DomEvent.js","names":["Util.splitWords","Util.stamp"],"sources":["../../../src/dom/DomEvent.js"],"sourcesContent":["import {Point} from '../geometry/Point.js';\nimport * as Util from '../core/Util.js';\nimport {getScale} from './DomUtil.js';\n\nimport * as PointerEvents from './DomEvent.PointerEvents.js';\nexport {PointerEvents};\n\n// DomEvent: utility functions to work with the\n// [DOM events](https://developer.mozilla.org/docs/Web/API/Event), used by Maplair\n// internally. The functions return the `DomEvent` namespace for chaining.\n\n// Inspired by John Resig, Dean Edwards and YUI addEvent implementations.\n\n/**\n * Adds a listener function (`fn`) to a particular DOM event type of the\n * element `obj`. You can optionally specify the context of the listener\n * (object the `this` keyword will point to). You can also pass several\n * space-separated types (e.g. `'click dblclick'`). Alternatively, adds a set of\n * type/listener pairs, e.g. `{click: onClick, pointermove: onPointerMove}`, with the\n * context as third argument.\n * @param {EventTarget} obj\n * @param {string|Record<string, (ev: any) => void>} types\n * @param {((ev: any) => void)|object} [fn]\n * @param {object} [context]\n * @returns {void}\n */\nexport function on(obj, types, fn, context) {\n\n\tif (types && typeof types === 'object') {\n\t\tfor (const [type, listener] of Object.entries(types)) {\n\t\t\taddOne(obj, type, listener, fn);\n\t\t}\n\t} else {\n\t\tfor (const type of Util.splitWords(types)) {\n\t\t\taddOne(obj, type, fn, context);\n\t\t}\n\t}\n}\n\nconst eventsKey = '_maplair_events';\n\n/**\n * Removes a previously added listener function.\n * Note that if you passed a custom context to on, you must pass the same\n * context to `off` in order to remove the listener. Alternatively, removes a set of\n * type/listener pairs, e.g. `{click: onClick, pointermove: onPointerMove}`; with\n * `types` only, removes all previously added listeners of given types; with the\n * element only, removes all previously added listeners from the given element.\n * @param {EventTarget} obj\n * @param {string|Record<string, (ev: any) => void>} [types]\n * @param {((ev: any) => void)|object} [fn]\n * @param {object} [context]\n * @returns {void}\n */\nexport function off(obj, types, fn, context) {\n\n\tif (arguments.length === 1) {\n\t\tbatchRemove(obj);\n\t\tdelete obj[eventsKey];\n\n\t} else if (types && typeof types === 'object') {\n\t\tfor (const [type, listener] of Object.entries(types)) {\n\t\t\tremoveOne(obj, type, listener, fn);\n\t\t}\n\n\t} else {\n\t\ttypes = Util.splitWords(types);\n\n\t\tif (arguments.length === 2) {\n\t\t\tbatchRemove(obj, type => types.includes(type));\n\t\t} else {\n\t\t\tfor (const type of types) {\n\t\t\t\tremoveOne(obj, type, fn, context);\n\t\t\t}\n\t\t}\n\t}\n}\n\nconst DIGIT_RE = /\\d/;\n\nfunction batchRemove(obj, filterFn) {\n\tfor (const id of Object.keys(obj[eventsKey] ?? {})) {\n\t\tconst type = id.split(DIGIT_RE)[0];\n\t\tif (!filterFn || filterFn(type)) {\n\t\t\tremoveOne(obj, type, null, null, id);\n\t\t}\n\t}\n}\n\nfunction addOne(obj, type, fn, context) {\n\tconst id = type + Util.stamp(fn) + (context ? `_${Util.stamp(context)}` : '');\n\n\tif (obj[eventsKey] && obj[eventsKey][id]) { return; }\n\n\tconst handler = function (e) {\n\t\treturn fn.call(context || obj, e);\n\t};\n\n\tobj.addEventListener(type, handler, type === 'wheel' ? {passive: false} : false);\n\n\tobj[eventsKey] ??= {};\n\tobj[eventsKey][id] = handler;\n}\n\nfunction removeOne(obj, type, fn, context, id) {\n\tid ??= type + Util.stamp(fn) + (context ? `_${Util.stamp(context)}` : '');\n\tconst handler = obj[eventsKey] && obj[eventsKey][id];\n\n\tif (!handler) { return; }\n\n\tobj.removeEventListener(type, handler, false);\n\n\tobj[eventsKey][id] = null;\n}\n\n/**\n * Stop the given event from propagation to parent elements. Used inside the listener\n * functions:\n * ```js\n * DomEvent.on(div, 'click', DomEvent.stopPropagation);\n * ```\n * Also accepts a Maplair event with an `originalEvent`.\n * @param {Event|{originalEvent: Event}} e\n * @returns {void}\n */\nexport function stopPropagation(e) {\n\n\t// feature detection rather than `instanceof Event`, which fails for events from other windows (e.g. iframes)\n\tif (e.stopPropagation) {\n\t\te.stopPropagation();\n\t} else if (e.originalEvent) { // In case of Maplair event.\n\t\te.originalEvent._stopped = true;\n\t} else {\n\t\t// custom Maplair event\n\t\tconsole.debug('Unsupported event', e);\n\t}\n}\n\n/**\n * Adds `stopPropagation` to the element's `'wheel'` events (plus browser variants).\n * @param {HTMLElement} el\n * @returns {void}\n */\nexport function disableScrollPropagation(el) {\n\taddOne(el, 'wheel', stopPropagation);\n}\n\n/**\n * Adds `stopPropagation` to the element's `'dblclick'`, `'contextmenu'`\n * and `'pointerdown'` events (plus browser variants).\n * For `'click'` events, prevents the map from handling the click\n * while still allowing the native DOM click event to propagate normally.\n * @param {HTMLElement} el\n * @returns {void}\n */\nexport function disableClickPropagation(el) {\n\ton(el, 'pointerdown dblclick contextmenu', stopPropagation);\n\tel['_maplair_disable_click'] = true;\n}\n\n/**\n * Prevents the default action of the DOM Event `e` from happening (such as\n * following a link in the href of the a element, or doing a POST request\n * with page reload when a `<form>` is submitted).\n * Use it inside listener functions.\n * @param {Event} e\n * @returns {void}\n */\nexport function preventDefault(e) {\n\te.preventDefault?.();\n}\n\n/**\n * Does `stopPropagation` and `preventDefault` at the same time.\n * @param {Event} e\n * @returns {void}\n */\nexport function stop(e) {\n\tpreventDefault(e);\n\tstopPropagation(e);\n}\n\n/**\n * Gets normalized pointer position from a DOM event relative to the\n * `container` (border excluded) or to the whole page if not specified.\n * @param {MouseEvent|Touch} e\n * @param {HTMLElement} [container]\n * @returns {Point}\n */\nexport function getPointerPosition(e, container) {\n\tif (!container) {\n\t\treturn new Point(e.clientX, e.clientY);\n\t}\n\n\tconst scale = getScale(container),\n\toffset = scale.boundingClientRect; // left and top values are in page scale (like the event clientX/Y)\n\n\treturn new Point(\n\t\t// offset.left/top values are in page scale (like clientX/Y),\n\t\t// whereas clientLeft/Top (border width) values are the original values (before CSS scale applies).\n\t\t(e.clientX - offset.left) / scale.x - container.clientLeft,\n\t\t(e.clientY - offset.top) / scale.y - container.clientTop\n\t);\n}\n\n/**\n * Gets the wheel pixel factor based on the devicePixelRatio.\n * @returns {number}\n */\nexport function getWheelPxFactor() {\n\t// We need double the scroll pixels (see #7403 and #4538)\n\treturn window.devicePixelRatio * 2;\n}\n\n/**\n * Gets normalized wheel delta from a wheel DOM event, in vertical\n * pixels scrolled (negative if scrolling down).\n * Events from pointing devices without precise scrolling are mapped to\n * a best guess of 60 pixels.\n * @param {WheelEvent} e\n * @returns {number}\n */\nexport function getWheelDelta(e) {\n\t// scaled per delta mode: pixels, lines, pages; horizontal and depth scrolling give 0\n\treturn -e.deltaY * (e.deltaMode ? e.deltaMode === 1 ? 20 : 60 : 1 / getWheelPxFactor()) || 0;\n}\n\n/**\n * Checks if the pointer really left/entered the element `el` (for\n * `pointerover`/`pointerout`).\n * @internal\n * @param {Node} el\n * @param {MouseEvent} e\n * @returns {boolean}\n */\nexport function isExternalTarget(el, e) {\n\treturn !el.contains(e.relatedTarget);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,GAAG,KAAK,OAAO,IAAI,SAAS;CAE3C,IAAI,SAAS,OAAO,UAAU,UAC7B,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,KAAK,GAClD,OAAO,KAAK,MAAM,UAAU,EAAE;MAG/B,KAAK,MAAM,QAAQA,WAAgB,KAAK,GACvC,OAAO,KAAK,MAAM,IAAI,OAAO;AAGhC;AAEA,MAAM,YAAY;;;;;;;;;;;;;;AAelB,SAAgB,IAAI,KAAK,OAAO,IAAI,SAAS;CAE5C,IAAI,UAAU,WAAW,GAAG;EAC3B,YAAY,GAAG;EACf,OAAO,IAAI;CAEZ,OAAO,IAAI,SAAS,OAAO,UAAU,UACpC,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,KAAK,GAClD,UAAU,KAAK,MAAM,UAAU,EAAE;MAG5B;EACN,QAAQA,WAAgB,KAAK;EAE7B,IAAI,UAAU,WAAW,GACxB,YAAY,MAAK,SAAQ,MAAM,SAAS,IAAI,CAAC;OAE7C,KAAK,MAAM,QAAQ,OAClB,UAAU,KAAK,MAA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eAAe;CAC1D,GAAG,4BAA4B;AAChC;;;;;;;;;AAUA,SAAgB,eAAe,GAAG;CACjC,EAAE,iBAAiB;AACpB;;;;;;AAOA,SAAgB,KAAK,GAAG;CACvB,eAAe,CAAC;CAChB,gBAAgB,CAAC;AAClB;;;;;;;;AASA,SAAgB,mBAAmB,GAAG,WAAW;CAChD,IAAI,CAAC,WACJ,OAAO,IAAI,MAAM,EAAE,SAAS,EAAE,OAAO;CAGtC,MAAM,QAAQ,SAAS,SAAS,GAChC,SAAS,MAAM;CAEf,OAAO,IAAI,OAGT,EAAE,UAAU,OAAO,QAAQ,MAAM,IAAI,UAAU,aAC/C,EAAE,UAAU,OAAO,OAAO,MAAM,IAAI,UAAU,SAChD;AACD;;;;;AAMA,SAAgB,mBAAmB;CAElC,OAAO,OAAO,mBAAmB;AAClC;;;;;;;;;AAUA,SAAgB,cAAc,GAAG;CAEhC,OAAO,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,IAAI,KAAK,KAAK,IAAI,iBAAiB,MAAM;AAC5F;;;;;;;;;AAUA,SAAgB,iBAAiB,IAAI,GAAG;CACvC,OAAO,CAAC,GAAG,SAAS,EAAE,aAAa;AACpC"}
@@ -35,7 +35,7 @@ function get(id) {
35
35
  function create(tagName, className, container) {
36
36
  const el = document.createElement(tagName);
37
37
  el.className = className ?? "";
38
- container?.appendChild(el);
38
+ container?.append(el);
39
39
  return el;
40
40
  }
41
41
  /**
@@ -47,8 +47,8 @@ function create(tagName, className, container) {
47
47
  function toFront(el) {
48
48
  const parent = el.parentNode;
49
49
  if (!parent || parent.lastChild === el) return;
50
- if (el.matches(":hover")) while (el.nextSibling) parent.insertBefore(el.nextSibling, el);
51
- else parent.appendChild(el);
50
+ if (el.matches(":hover")) while (el.nextSibling) el.before(el.nextSibling);
51
+ else parent.append(el);
52
52
  }
53
53
  /**
54
54
  * Makes `el` the first child of its parent, so it renders behind the other children.
@@ -58,8 +58,8 @@ function toFront(el) {
58
58
  function toBack(el) {
59
59
  const parent = el.parentNode;
60
60
  if (!parent || parent.firstChild === el) return;
61
- if (el.matches(":hover")) while (el.previousSibling) parent.insertBefore(el.previousSibling, el.nextSibling);
62
- else parent.insertBefore(el, parent.firstChild);
61
+ if (el.matches(":hover")) while (el.previousSibling) el.after(el.previousSibling);
62
+ else parent.prepend(el);
63
63
  }
64
64
  /**
65
65
  * Resets the 3D CSS transform of `el` so it is translated by `offset` pixels
@@ -1 +1 @@
1
- {"version":3,"file":"DomUtil.js","names":["DomEvent.preventDefault"],"sources":["../../../src/dom/DomUtil.js"],"sourcesContent":["import * as DomEvent from './DomEvent.js';\nimport {Point} from '../geometry/Point.js';\n\n// DomUtil: utility functions to work with the\n// [DOM](https://developer.mozilla.org/docs/Web/API/Document_Object_Model)\n// tree, used by Maplair internally.\n//\n// Most functions expecting or returning a `HTMLElement` also work for\n// SVG elements. The only difference is that classes refer to CSS classes\n// in HTML and SVG classes in SVG.\n\n/**\n * Returns an element given its DOM id, or returns the element itself\n * if it was passed directly.\n * @param {string|HTMLElement} id\n * @returns {HTMLElement|null}\n */\nexport function get(id) {\n\treturn typeof id === 'string' ? document.getElementById(id) : id;\n}\n\n/**\n * Creates an HTML element with `tagName`, sets its class to `className`, and\n * optionally appends it to `container` element.\n * @param {string} tagName\n * @param {string} [className]\n * @param {HTMLElement} [container]\n * @returns {HTMLElement}\n */\nexport function create(tagName, className, container) {\n\tconst el = document.createElement(tagName);\n\tel.className = className ?? '';\n\n\tcontainer?.appendChild(el);\n\treturn el;\n}\n\n/**\n * Makes `el` the last child of its parent, so it renders in front of the other\n * children.\n * @param {Element} el\n * @returns {void}\n */\nexport function toFront(el) {\n\tconst parent = el.parentNode;\n\tif (!parent || parent.lastChild === el) { return; }\n\n\t// re-inserting a hovered node (e.g. bringToFront in a pointerover handler) makes Chromium 144+ fire a repeated\n\t// pointerover and lose the next pointerout (#10129), so move the nodes after it instead\n\tif (el.matches(':hover')) {\n\t\twhile (el.nextSibling) { parent.insertBefore(el.nextSibling, el); }\n\t} else {\n\t\tparent.appendChild(el);\n\t}\n}\n\n/**\n * Makes `el` the first child of its parent, so it renders behind the other children.\n * @param {Element} el\n * @returns {void}\n */\nexport function toBack(el) {\n\tconst parent = el.parentNode;\n\tif (!parent || parent.firstChild === el) { return; }\n\n\tif (el.matches(':hover')) { // see toFront\n\t\twhile (el.previousSibling) { parent.insertBefore(el.previousSibling, el.nextSibling); }\n\t} else {\n\t\tparent.insertBefore(el, parent.firstChild);\n\t}\n}\n\n/**\n * Resets the 3D CSS transform of `el` so it is translated by `offset` pixels\n * and optionally scaled by `scale`. Does not have an effect if the\n * browser doesn't support 3D CSS transforms.\n * @param {HTMLElement|SVGElement} el\n * @param {Point} [offset]\n * @param {number} [scale]\n * @returns {void}\n */\nexport function setTransform(el, offset, scale) {\n\tconst pos = offset ?? new Point(0, 0);\n\n\t// same format as browsers serialize it, so that unchanged positions can be skipped\n\tconst transform = `translate3d(${pos.x}px, ${pos.y}px, 0px)${scale ? ` scale(${scale})` : ''}`;\n\tif (el.style.transform !== transform) {\n\t\tel.style.transform = transform;\n\t}\n}\n\nconst positions = new WeakMap();\n\n/**\n * Sets the position of `el` to coordinates specified by `point` using a CSS translate\n * (used by Maplair internally to position its layers). With `flat`, the translate is 2D,\n * so `el` is painted into its parent's compositor layer instead of getting a layer of its own.\n * @param {HTMLElement|SVGElement} el\n * @param {Point} point\n * @param {boolean} [flat]\n * @returns {void}\n */\nexport function setPosition(el, point, flat) {\n\tpositions.set(el, point);\n\tif (flat) {\n\t\tel.style.transform = `translate(${point.x}px, ${point.y}px)`;\n\t} else {\n\t\tsetTransform(el, point);\n\t}\n}\n\n/**\n * Returns the coordinates of an element previously positioned with setPosition.\n * @param {HTMLElement|SVGElement} el\n * @returns {Point}\n */\nexport function getPosition(el) {\n\t// this method is only used for elements previously positioned using setPosition,\n\t// so it's safe to cache the position for performance\n\treturn positions.get(el) ?? new Point(0, 0);\n}\n\n/**\n * Prevents the user from generating `dragstart` DOM events, usually generated when\n * the user drags an image.\n * @returns {void}\n */\nexport function disableImageDrag() {\n\tDomEvent.on(window, 'dragstart', DomEvent.preventDefault);\n}\n\n/**\n * Cancels the effects of a previous\n * [`DomUtil.disableImageDrag`](#domutil-disableimagedrag).\n * @returns {void}\n */\nexport function enableImageDrag() {\n\tDomEvent.off(window, 'dragstart', DomEvent.preventDefault);\n}\n\n/**\n * Finds the closest parent node which size (width and height) is not null.\n * @param {HTMLElement} element\n * @returns {HTMLElement}\n */\nexport function getSizedParentNode(element) {\n\tdo {\n\t\telement = element.parentNode;\n\t} while ((!element.offsetWidth || !element.offsetHeight) && element !== document.body);\n\treturn element;\n}\n\n/**\n * Computes the CSS scale currently applied on the element.\n * Returns an object with `x` and `y` members as horizontal and vertical scales\n * respectively, and `boundingClientRect` as the result of\n * [`getBoundingClientRect()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect).\n * @param {HTMLElement} element\n * @returns {{x: number, y: number, boundingClientRect: DOMRect}}\n */\nexport function getScale(element) {\n\tconst rect = element.getBoundingClientRect();\n\n\treturn {\n\t\tx: rect.width / element.offsetWidth || 1,\n\t\ty: rect.height / element.offsetHeight || 1,\n\t\tboundingClientRect: rect\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiBA,SAAgB,IAAI,IAAI;CACvB,OAAO,OAAO,OAAO,WAAW,SAAS,eAAe,EAAE,IAAI;AAC/D;;;;;;;;;AAUA,SAAgB,OAAO,SAAS,WAAW,WAAW;CACrD,MAAM,KAAK,SAAS,cAAc,OAAO;CACzC,GAAG,YAAY,aAAa;CAE5B,WAAW,YAAY,EAAE;CACzB,OAAO;AACR;;;;;;;AAQA,SAAgB,QAAQ,IAAI;CAC3B,MAAM,SAAS,GAAG;CAClB,IAAI,CAAC,UAAU,OAAO,cAAc,IAAM;CAI1C,IAAI,GAAG,QAAQ,QAAQ,GACtB,OAAO,GAAG,aAAe,OAAO,aAAa,GAAG,aAAa,EAAE;MAE/D,OAAO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SAAS,QAAQ,gBAAgB;EACzC,oBAAoB;CACrB;AACD"}
1
+ {"version":3,"file":"DomUtil.js","names":["DomEvent.preventDefault"],"sources":["../../../src/dom/DomUtil.js"],"sourcesContent":["import * as DomEvent from './DomEvent.js';\nimport {Point} from '../geometry/Point.js';\n\n// DomUtil: utility functions to work with the\n// [DOM](https://developer.mozilla.org/docs/Web/API/Document_Object_Model)\n// tree, used by Maplair internally.\n//\n// Most functions expecting or returning a `HTMLElement` also work for\n// SVG elements. The only difference is that classes refer to CSS classes\n// in HTML and SVG classes in SVG.\n\n/**\n * Returns an element given its DOM id, or returns the element itself\n * if it was passed directly.\n * @param {string|HTMLElement} id\n * @returns {HTMLElement|null}\n */\nexport function get(id) {\n\treturn typeof id === 'string' ? document.getElementById(id) : id;\n}\n\n/**\n * Creates an HTML element with `tagName`, sets its class to `className`, and\n * optionally appends it to `container` element.\n * @param {string} tagName\n * @param {string} [className]\n * @param {HTMLElement} [container]\n * @returns {HTMLElement}\n */\nexport function create(tagName, className, container) {\n\tconst el = document.createElement(tagName);\n\tel.className = className ?? '';\n\n\tcontainer?.append(el);\n\treturn el;\n}\n\n/**\n * Makes `el` the last child of its parent, so it renders in front of the other\n * children.\n * @param {Element} el\n * @returns {void}\n */\nexport function toFront(el) {\n\tconst parent = el.parentNode;\n\tif (!parent || parent.lastChild === el) { return; }\n\n\t// re-inserting a hovered node (e.g. bringToFront in a pointerover handler) makes Chromium 144+ fire a repeated\n\t// pointerover and lose the next pointerout (#10129), so move the nodes after it instead\n\tif (el.matches(':hover')) {\n\t\twhile (el.nextSibling) { el.before(el.nextSibling); }\n\t} else {\n\t\tparent.append(el);\n\t}\n}\n\n/**\n * Makes `el` the first child of its parent, so it renders behind the other children.\n * @param {Element} el\n * @returns {void}\n */\nexport function toBack(el) {\n\tconst parent = el.parentNode;\n\tif (!parent || parent.firstChild === el) { return; }\n\n\tif (el.matches(':hover')) { // see toFront\n\t\twhile (el.previousSibling) { el.after(el.previousSibling); }\n\t} else {\n\t\tparent.prepend(el);\n\t}\n}\n\n/**\n * Resets the 3D CSS transform of `el` so it is translated by `offset` pixels\n * and optionally scaled by `scale`. Does not have an effect if the\n * browser doesn't support 3D CSS transforms.\n * @param {HTMLElement|SVGElement} el\n * @param {Point} [offset]\n * @param {number} [scale]\n * @returns {void}\n */\nexport function setTransform(el, offset, scale) {\n\tconst pos = offset ?? new Point(0, 0);\n\n\t// same format as browsers serialize it, so that unchanged positions can be skipped\n\tconst transform = `translate3d(${pos.x}px, ${pos.y}px, 0px)${scale ? ` scale(${scale})` : ''}`;\n\tif (el.style.transform !== transform) {\n\t\tel.style.transform = transform;\n\t}\n}\n\nconst positions = new WeakMap();\n\n/**\n * Sets the position of `el` to coordinates specified by `point` using a CSS translate\n * (used by Maplair internally to position its layers). With `flat`, the translate is 2D,\n * so `el` is painted into its parent's compositor layer instead of getting a layer of its own.\n * @param {HTMLElement|SVGElement} el\n * @param {Point} point\n * @param {boolean} [flat]\n * @returns {void}\n */\nexport function setPosition(el, point, flat) {\n\tpositions.set(el, point);\n\tif (flat) {\n\t\tel.style.transform = `translate(${point.x}px, ${point.y}px)`;\n\t} else {\n\t\tsetTransform(el, point);\n\t}\n}\n\n/**\n * Returns the coordinates of an element previously positioned with setPosition.\n * @param {HTMLElement|SVGElement} el\n * @returns {Point}\n */\nexport function getPosition(el) {\n\t// this method is only used for elements previously positioned using setPosition,\n\t// so it's safe to cache the position for performance\n\treturn positions.get(el) ?? new Point(0, 0);\n}\n\n/**\n * Prevents the user from generating `dragstart` DOM events, usually generated when\n * the user drags an image.\n * @returns {void}\n */\nexport function disableImageDrag() {\n\tDomEvent.on(window, 'dragstart', DomEvent.preventDefault);\n}\n\n/**\n * Cancels the effects of a previous\n * [`DomUtil.disableImageDrag`](#domutil-disableimagedrag).\n * @returns {void}\n */\nexport function enableImageDrag() {\n\tDomEvent.off(window, 'dragstart', DomEvent.preventDefault);\n}\n\n/**\n * Finds the closest parent node which size (width and height) is not null.\n * @param {HTMLElement} element\n * @returns {HTMLElement}\n */\nexport function getSizedParentNode(element) {\n\tdo {\n\t\telement = element.parentNode;\n\t} while ((!element.offsetWidth || !element.offsetHeight) && element !== document.body);\n\treturn element;\n}\n\n/**\n * Computes the CSS scale currently applied on the element.\n * Returns an object with `x` and `y` members as horizontal and vertical scales\n * respectively, and `boundingClientRect` as the result of\n * [`getBoundingClientRect()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect).\n * @param {HTMLElement} element\n * @returns {{x: number, y: number, boundingClientRect: DOMRect}}\n */\nexport function getScale(element) {\n\tconst rect = element.getBoundingClientRect();\n\n\treturn {\n\t\tx: rect.width / element.offsetWidth || 1,\n\t\ty: rect.height / element.offsetHeight || 1,\n\t\tboundingClientRect: rect\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiBA,SAAgB,IAAI,IAAI;CACvB,OAAO,OAAO,OAAO,WAAW,SAAS,eAAe,EAAE,IAAI;AAC/D;;;;;;;;;AAUA,SAAgB,OAAO,SAAS,WAAW,WAAW;CACrD,MAAM,KAAK,SAAS,cAAc,OAAO;CACzC,GAAG,YAAY,aAAa;CAE5B,WAAW,OAAO,EAAE;CACpB,OAAO;AACR;;;;;;;AAQA,SAAgB,QAAQ,IAAI;CAC3B,MAAM,SAAS,GAAG;CAClB,IAAI,CAAC,UAAU,OAAO,cAAc,IAAM;CAI1C,IAAI,GAAG,QAAQ,QAAQ,GACtB,OAAO,GAAG,aAAe,GAAG,OAAO,GAAG,WAAW;MAEjD,OAAO,OAAO,EAAE;AAElB;;;;;;AAOA,SAAgB,OAAO,IAAI;CAC1B,MAAM,SAAS,GAAG;CAClB,IAAI,CAAC,UAAU,OAAO,eAAe,IAAM;CAE3C,IAAI,GAAG,QAAQ,QAAQ,GACtB,OAAO,GAAG,iBAAmB,GAAG,MAAM,GAAG,eAAe;MAExD,OAAO,QAAQ,EAAE;AAEnB;;;;;;;;;;AAWA,SAAgB,aAAa,IAAI,QAAQ,OAAO;CAC/C,MAAM,MAAM,UAAU,IAAI,MAAM,GAAG,CAAC;CAGpC,MAAM,YAAY,eAAe,IAAI,EAAE,MAAM,IAAI,EAAE,UAAU,QAAQ,UAAU,MAAM,KAAK;CAC1F,IAAI,GAAG,MAAM,cAAc,WAC1B,GAAG,MAAM,YAAY;AAEvB;AAEA,MAAM,4BAAY,IAAI,QAAQ;;;;;;;;;;AAW9B,SAAgB,YAAY,IAAI,OAAO,MAAM;CAC5C,UAAU,IAAI,IAAI,KAAK;CACvB,IAAI,MACH,GAAG,MAAM,YAAY,aAAa,MAAM,EAAE,MAAM,MAAM,EAAE;MAExD,aAAa,IAAI,KAAK;AAExB;;;;;;AAOA,SAAgB,YAAY,IAAI;CAG/B,OAAO,UAAU,IAAI,EAAE,KAAK,IAAI,MAAM,GAAG,CAAC;AAC3C;;;;;;AAOA,SAAgB,mBAAmB;CAClC,GAAY,QAAQ,aAAaA,cAAuB;AACzD;;;;;;AAOA,SAAgB,kBAAkB;CACjC,IAAa,QAAQ,aAAaA,cAAuB;AAC1D;;;;;;AAOA,SAAgB,mBAAmB,SAAS;CAC3C;EACC,UAAU,QAAQ;SACT,CAAC,QAAQ,eAAe,CAAC,QAAQ,iBAAiB,YAAY,SAAS;CACjF,OAAO;AACR;;;;;;;;;AAUA,SAAgB,SAAS,SAAS;CACjC,MAAM,OAAO,QAAQ,sBAAsB;CAE3C,OAAO;EACN,GAAG,KAAK,QAAQ,QAAQ,eAAe;EACvC,GAAG,KAAK,SAAS,QAAQ,gBAAgB;EACzC,oBAAoB;CACrB;AACD"}
@@ -14,9 +14,13 @@ import { Evented } from "../core/Events.js";
14
14
  * pointer drag).
15
15
  */
16
16
  /**
17
- * The event object of `dragstart`, `predrag` and `drag` of `Draggable`.
17
+ * The event object of `dragstart`, `predrag` and `drag` of `Draggable`, and of
18
+ * `movestart` and `dragstart` of draggable markers.
18
19
  * @typedef {object} DraggableEvent
19
- * @property {PointerEvent} originalEvent The DOM event of the pointer which drags.
20
+ * @property {PointerEvent|KeyboardEvent} originalEvent The DOM event of the pointer which
21
+ * drags: for `dragstart`, the `pointermove` that moved the pointer past `clickTolerance`
22
+ * (not the `pointerdown`), or the `keydown` of an arrow key that moves a focused
23
+ * draggable marker.
20
24
  * @extends MaplairEvent
21
25
  */
22
26
  /**
@@ -76,13 +80,13 @@ var Draggable = class Draggable extends Evented {
76
80
  }
77
81
  _onDown(e) {
78
82
  this._moved = false;
79
- if (this._element.classList.contains("maplair-zoom-anim")) return;
80
83
  const pointers = getPointers().length;
81
84
  if (pointers > 1) {
82
85
  if (Draggable._dragging === this) this.finishDrag();
83
86
  return;
84
87
  }
85
- if (Draggable._dragging || e.shiftKey || e.button !== 0 && e.pointerType !== "touch") return;
88
+ const boxZoom = e.shiftKey && this._element.closest(".maplair-container")?.classList.contains("maplair-box-zoom");
89
+ if (Draggable._dragging || boxZoom || e.button !== 0 && e.pointerType !== "touch") return;
86
90
  Draggable._dragging = this;
87
91
  disableImageDrag();
88
92
  if (this._moving) return;
@@ -140,10 +144,8 @@ var Draggable = class Draggable extends Evented {
140
144
  finishDrag(noInertia) {
141
145
  this._draggingContainer?.classList.remove("maplair-dragging");
142
146
  this._draggingContainer = null;
143
- if (this._lastTarget) {
144
- this._lastTarget.classList.remove("maplair-drag-target");
145
- this._lastTarget = null;
146
- }
147
+ this._lastTarget?.classList.remove("maplair-drag-target");
148
+ this._lastTarget = null;
147
149
  off(this._dragStartTarget, "pointermove", this._onMove, this);
148
150
  off(this._dragStartTarget, "pointerup pointercancel lostpointercapture", this._onUp, this);
149
151
  enableImageDrag();