maplair 4.0.0 → 4.2.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 (305) hide show
  1. package/CHANGELOG.md +178 -0
  2. package/dist/esm/Maplair.js +18 -17
  3. package/dist/esm/Maplair.js.map +1 -1
  4. package/dist/esm/_virtual/_rolldown/runtime.js +1 -2
  5. package/dist/esm/control/AttributionControl.js +25 -16
  6. package/dist/esm/control/AttributionControl.js.map +1 -1
  7. package/dist/esm/control/ButtonControl.js +10 -13
  8. package/dist/esm/control/ButtonControl.js.map +1 -1
  9. package/dist/esm/control/ContextMenu.js +2 -5
  10. package/dist/esm/control/ContextMenu.js.map +1 -1
  11. package/dist/esm/control/Control.js +10 -18
  12. package/dist/esm/control/Control.js.map +1 -1
  13. package/dist/esm/control/FullscreenControl.js +6 -9
  14. package/dist/esm/control/FullscreenControl.js.map +1 -1
  15. package/dist/esm/control/LayersControl.js +170 -65
  16. package/dist/esm/control/LayersControl.js.map +1 -1
  17. package/dist/esm/control/LegendControl.js +8 -11
  18. package/dist/esm/control/LegendControl.js.map +1 -1
  19. package/dist/esm/control/MiniMapControl.js +15 -18
  20. package/dist/esm/control/MiniMapControl.js.map +1 -1
  21. package/dist/esm/control/RotateControl.js +2 -5
  22. package/dist/esm/control/RotateControl.js.map +1 -1
  23. package/dist/esm/control/ScaleControl.js +8 -11
  24. package/dist/esm/control/ScaleControl.js.map +1 -1
  25. package/dist/esm/control/SearchControl.js +100 -19
  26. package/dist/esm/control/SearchControl.js.map +1 -1
  27. package/dist/esm/control/SideBySideControl.js +2 -5
  28. package/dist/esm/control/SideBySideControl.js.map +1 -1
  29. package/dist/esm/control/TextControl.js +6 -9
  30. package/dist/esm/control/TextControl.js.map +1 -1
  31. package/dist/esm/control/TimeControl.js +407 -0
  32. package/dist/esm/control/TimeControl.js.map +1 -0
  33. package/dist/esm/control/ZoomControl.js +23 -36
  34. package/dist/esm/control/ZoomControl.js.map +1 -1
  35. package/dist/esm/core/Class.js +28 -44
  36. package/dist/esm/core/Class.js.map +1 -1
  37. package/dist/esm/core/Events.js +22 -10
  38. package/dist/esm/core/Events.js.map +1 -1
  39. package/dist/esm/core/Handler.js +23 -14
  40. package/dist/esm/core/Handler.js.map +1 -1
  41. package/dist/esm/core/I18n.js +1 -2
  42. package/dist/esm/core/Util.js +15 -4
  43. package/dist/esm/core/Util.js.map +1 -1
  44. package/dist/esm/dom/DomEvent.DoubleTap.js +26 -24
  45. package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
  46. package/dist/esm/dom/DomEvent.PointerEvents.js +3 -18
  47. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  48. package/dist/esm/dom/DomEvent.js +18 -60
  49. package/dist/esm/dom/DomEvent.js.map +1 -1
  50. package/dist/esm/dom/DomUtil.js +15 -70
  51. package/dist/esm/dom/DomUtil.js.map +1 -1
  52. package/dist/esm/dom/Draggable.js +21 -21
  53. package/dist/esm/dom/Draggable.js.map +1 -1
  54. package/dist/esm/dom/PosAnimation.js +4 -27
  55. package/dist/esm/dom/PosAnimation.js.map +1 -1
  56. package/dist/esm/geo/LatLng.js +16 -7
  57. package/dist/esm/geo/LatLng.js.map +1 -1
  58. package/dist/esm/geo/LatLngBounds.js +9 -15
  59. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  60. package/dist/esm/geo/crs/CRS.js +1 -2
  61. package/dist/esm/geo/crs/EPSG3395.js +5 -6
  62. package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
  63. package/dist/esm/geo/crs/EPSG3857.js +5 -6
  64. package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
  65. package/dist/esm/geo/crs/EPSG4326.js +4 -5
  66. package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
  67. package/dist/esm/geo/crs/EarthCRS.js +3 -4
  68. package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
  69. package/dist/esm/geo/crs/SimpleCRS.js +4 -5
  70. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
  71. package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +5 -6
  72. package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
  73. package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +4 -5
  74. package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
  75. package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +5 -6
  76. package/dist/esm/geo/projection/SphericalMercatorProjection.js.map +1 -0
  77. package/dist/esm/geometry/Bounds.js +10 -14
  78. package/dist/esm/geometry/Bounds.js.map +1 -1
  79. package/dist/esm/geometry/LineUtil.js +37 -32
  80. package/dist/esm/geometry/LineUtil.js.map +1 -1
  81. package/dist/esm/geometry/Point.js +1 -2
  82. package/dist/esm/geometry/PolyUtil.js +24 -51
  83. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  84. package/dist/esm/geometry/Transformation.js +1 -2
  85. package/dist/esm/layer/BlanketOverlay.js +7 -10
  86. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  87. package/dist/esm/layer/Classification.js +1 -2
  88. package/dist/esm/layer/DivOverlay.js +16 -22
  89. package/dist/esm/layer/DivOverlay.js.map +1 -1
  90. package/dist/esm/layer/FeatureGroup.js +5 -4
  91. package/dist/esm/layer/FeatureGroup.js.map +1 -1
  92. package/dist/esm/layer/GeoJSON.Load.js +1 -2
  93. package/dist/esm/layer/GeoJSON.js +17 -155
  94. package/dist/esm/layer/GeoJSON.js.map +1 -1
  95. package/dist/esm/layer/GeoJSONUtil.js +74 -0
  96. package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
  97. package/dist/esm/layer/HeatLayer.js +17 -20
  98. package/dist/esm/layer/HeatLayer.js.map +1 -1
  99. package/dist/esm/layer/ImageOverlay.js +22 -29
  100. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  101. package/dist/esm/layer/Layer.js +9 -12
  102. package/dist/esm/layer/Layer.js.map +1 -1
  103. package/dist/esm/layer/LayerGroup.js +53 -3
  104. package/dist/esm/layer/LayerGroup.js.map +1 -1
  105. package/dist/esm/layer/Popup.js +35 -58
  106. package/dist/esm/layer/Popup.js.map +1 -1
  107. package/dist/esm/layer/SVGOverlay.js +3 -7
  108. package/dist/esm/layer/SVGOverlay.js.map +1 -1
  109. package/dist/esm/layer/Tooltip.js +31 -34
  110. package/dist/esm/layer/Tooltip.js.map +1 -1
  111. package/dist/esm/layer/VideoOverlay.js +13 -17
  112. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  113. package/dist/esm/layer/marker/DefaultIcon.js +38 -49
  114. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
  115. package/dist/esm/layer/marker/DivIcon.js +8 -11
  116. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  117. package/dist/esm/layer/marker/Icon.js +9 -12
  118. package/dist/esm/layer/marker/Icon.js.map +1 -1
  119. package/dist/esm/layer/marker/Marker.Drag.js +44 -5
  120. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  121. package/dist/esm/layer/marker/Marker.Move.js +5 -8
  122. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  123. package/dist/esm/layer/marker/Marker.js +115 -47
  124. package/dist/esm/layer/marker/Marker.js.map +1 -1
  125. package/dist/esm/layer/marker/MarkerClusterGroup.js +301 -0
  126. package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
  127. package/dist/esm/layer/marker/SvgIcon.js +7 -10
  128. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  129. package/dist/esm/layer/tile/GridLayer.js +89 -101
  130. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  131. package/dist/esm/layer/tile/TileLayer.js +36 -44
  132. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  133. package/dist/esm/layer/tile/WMSTileLayer.js +33 -27
  134. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  135. package/dist/esm/layer/vector/Canvas.js +8 -17
  136. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  137. package/dist/esm/layer/vector/Circle.js +6 -5
  138. package/dist/esm/layer/vector/Circle.js.map +1 -1
  139. package/dist/esm/layer/vector/CircleMarker.js +19 -10
  140. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  141. package/dist/esm/layer/vector/Path.DashAnimation.js +3 -5
  142. package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
  143. package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
  144. package/dist/esm/layer/vector/Path.js +28 -22
  145. package/dist/esm/layer/vector/Path.js.map +1 -1
  146. package/dist/esm/layer/vector/Polygon.js +22 -7
  147. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  148. package/dist/esm/layer/vector/Polyline.Decorations.js +3 -4
  149. package/dist/esm/layer/vector/Polyline.js +25 -10
  150. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  151. package/dist/esm/layer/vector/Rectangle.js +1 -2
  152. package/dist/esm/layer/vector/Renderer.getRenderer.js +17 -17
  153. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  154. package/dist/esm/layer/vector/Renderer.js +1 -2
  155. package/dist/esm/layer/vector/SVG.js +12 -9
  156. package/dist/esm/layer/vector/SVG.js.map +1 -1
  157. package/dist/esm/map/Hash.js +1 -2
  158. package/dist/esm/map/Map.Rotation.js +41 -22
  159. package/dist/esm/map/Map.Rotation.js.map +1 -1
  160. package/dist/esm/map/Map.js +125 -126
  161. package/dist/esm/map/Map.js.map +1 -1
  162. package/dist/esm/map/MapSync.js +1 -2
  163. package/dist/esm/map/handler/BoxZoomHandler.js +25 -47
  164. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  165. package/dist/esm/map/handler/DisplaceHandler.js +7 -10
  166. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  167. package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
  168. package/dist/esm/map/handler/DragHandler.js +20 -21
  169. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  170. package/dist/esm/map/handler/KeyboardHandler.js +48 -68
  171. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  172. package/dist/esm/map/handler/PinchZoomHandler.js +13 -5
  173. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  174. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -6
  175. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  176. package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
  177. package/dist/esm/map/handler/TapHoldHandler.js +13 -7
  178. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  179. package/dist/esm/package.js +2 -3
  180. package/dist/maplair-global-src.js +6495 -5981
  181. package/dist/maplair-global-src.js.map +1 -1
  182. package/dist/maplair-global.js +2 -2
  183. package/dist/maplair-global.js.map +1 -1
  184. package/dist/maplair-src.js +6206 -5673
  185. package/dist/maplair-src.js.map +1 -1
  186. package/dist/maplair.css +1 -1213
  187. package/dist/maplair.js +2 -2
  188. package/dist/maplair.js.map +1 -1
  189. package/i18n/cs.json +6 -0
  190. package/i18n/de.json +6 -0
  191. package/i18n/en.json +6 -0
  192. package/i18n/es.json +6 -0
  193. package/i18n/fr.json +6 -0
  194. package/i18n/hu.json +6 -0
  195. package/i18n/it.json +6 -0
  196. package/i18n/rm.json +6 -0
  197. package/i18n/sk.json +6 -0
  198. package/i18n/sl.json +6 -0
  199. package/package.json +11 -18
  200. package/src/Maplair.all.js +0 -1
  201. package/src/control/AttributionControl.js +25 -18
  202. package/src/control/ButtonControl.js +9 -11
  203. package/src/control/ContextMenu.js +3 -5
  204. package/src/control/Control.js +9 -19
  205. package/src/control/FullscreenControl.js +5 -7
  206. package/src/control/LayersControl.js +196 -86
  207. package/src/control/LegendControl.js +7 -9
  208. package/src/control/MiniMapControl.js +9 -11
  209. package/src/control/RotateControl.js +3 -5
  210. package/src/control/ScaleControl.js +7 -9
  211. package/src/control/SearchControl.js +102 -19
  212. package/src/control/SideBySideControl.js +3 -5
  213. package/src/control/TextControl.js +5 -7
  214. package/src/control/TimeControl.js +471 -0
  215. package/src/control/ZoomControl.js +22 -38
  216. package/src/control/index.js +1 -0
  217. package/src/core/Class.js +37 -45
  218. package/src/core/Events.js +22 -3
  219. package/src/core/Handler.js +25 -13
  220. package/src/core/Util.js +20 -2
  221. package/src/core/index.js +0 -1
  222. package/src/dom/DomEvent.DoubleTap.js +18 -10
  223. package/src/dom/DomEvent.PointerEvents.js +3 -26
  224. package/src/dom/DomEvent.js +17 -85
  225. package/src/dom/DomUtil.js +22 -78
  226. package/src/dom/Draggable.js +32 -23
  227. package/src/dom/PosAnimation.js +3 -25
  228. package/src/dom/index.js +0 -1
  229. package/src/geo/LatLng.js +20 -3
  230. package/src/geo/LatLngBounds.js +8 -15
  231. package/src/geo/crs/EPSG3395.js +4 -4
  232. package/src/geo/crs/EPSG3857.js +4 -4
  233. package/src/geo/crs/EPSG4326.js +3 -3
  234. package/src/geo/crs/EarthCRS.js +2 -8
  235. package/src/geo/crs/SimpleCRS.js +3 -3
  236. package/src/geo/index.js +1 -2
  237. package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +2 -2
  238. package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +2 -2
  239. package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +2 -2
  240. package/src/geo/projection/index.js +5 -5
  241. package/src/geometry/Bounds.js +12 -17
  242. package/src/geometry/LineUtil.js +48 -49
  243. package/src/geometry/PolyUtil.js +39 -76
  244. package/src/layer/BlanketOverlay.js +6 -10
  245. package/src/layer/DivOverlay.js +16 -27
  246. package/src/layer/FeatureGroup.js +8 -2
  247. package/src/layer/GeoJSON.js +17 -218
  248. package/src/layer/GeoJSONUtil.js +85 -0
  249. package/src/layer/HeatLayer.js +10 -12
  250. package/src/layer/ImageOverlay.js +21 -32
  251. package/src/layer/Layer.js +8 -10
  252. package/src/layer/LayerGroup.js +72 -1
  253. package/src/layer/Popup.js +37 -62
  254. package/src/layer/SVGOverlay.js +1 -5
  255. package/src/layer/Tooltip.js +34 -36
  256. package/src/layer/VideoOverlay.js +12 -15
  257. package/src/layer/marker/DefaultIcon.js +40 -58
  258. package/src/layer/marker/DivIcon.js +9 -11
  259. package/src/layer/marker/Icon.js +9 -10
  260. package/src/layer/marker/Marker.Drag.js +54 -6
  261. package/src/layer/marker/Marker.Move.js +4 -6
  262. package/src/layer/marker/Marker.js +145 -52
  263. package/src/layer/marker/MarkerClusterGroup.js +370 -0
  264. package/src/layer/marker/SvgIcon.js +7 -9
  265. package/src/layer/marker/index.js +1 -0
  266. package/src/layer/tile/GridLayer.js +108 -135
  267. package/src/layer/tile/TileLayer.js +44 -49
  268. package/src/layer/tile/WMSTileLayer.js +31 -26
  269. package/src/layer/vector/Canvas.js +13 -19
  270. package/src/layer/vector/Circle.js +9 -3
  271. package/src/layer/vector/CircleMarker.js +19 -7
  272. package/src/layer/vector/Path.DashAnimation.js +1 -2
  273. package/src/layer/vector/Path.js +30 -21
  274. package/src/layer/vector/Polygon.js +29 -6
  275. package/src/layer/vector/Polyline.js +26 -7
  276. package/src/layer/vector/Renderer.getRenderer.js +20 -19
  277. package/src/layer/vector/SVG.js +17 -7
  278. package/src/map/Map.Rotation.js +40 -8
  279. package/src/map/Map.js +158 -153
  280. package/src/map/handler/BoxZoomHandler.js +30 -50
  281. package/src/map/handler/DisplaceHandler.js +6 -8
  282. package/src/map/handler/DragHandler.js +25 -28
  283. package/src/map/handler/KeyboardHandler.js +65 -90
  284. package/src/map/handler/PinchZoomHandler.js +16 -5
  285. package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
  286. package/src/map/handler/TapHoldHandler.js +15 -4
  287. package/src/map/index.js +1 -1
  288. package/src/maplair.css +153 -98
  289. package/dist/esm/core/Browser.js +0 -100
  290. package/dist/esm/core/Browser.js.map +0 -1
  291. package/dist/esm/geo/projection/Projection.LonLat.js.map +0 -1
  292. package/dist/esm/geo/projection/Projection.Mercator.js.map +0 -1
  293. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +0 -1
  294. package/dist/esm/geo/projection/index.js +0 -14
  295. package/dist/esm/geo/projection/index.js.map +0 -1
  296. package/dist/esm/layer/marker/Marker.Rotation.js +0 -70
  297. package/dist/esm/layer/marker/Marker.Rotation.js.map +0 -1
  298. package/dist/images/layers.svg +0 -1
  299. package/dist/images/marker-icon.svg +0 -1
  300. package/dist/images/marker-shadow.svg +0 -1
  301. package/src/core/Browser.js +0 -110
  302. package/src/images/layers.svg +0 -1
  303. package/src/images/marker-icon.svg +0 -1
  304. package/src/images/marker-shadow.svg +0 -1
  305. package/src/layer/marker/Marker.Rotation.js +0 -103
@@ -1 +1 @@
1
- {"version":3,"file":"DomEvent.DoubleTap.js","names":["DomEvent.getPropagationPath"],"sources":["../../../src/dom/DomEvent.DoubleTap.js"],"sourcesContent":["import * as DomEvent from './DomEvent.js';\n\n/*\n * Extends the event handling code with double tap support for mobile browsers.\n *\n * Note: currently most browsers fire native dblclick, with only a few exceptions\n * (see https://github.com/Leaflet/Leaflet/issues/7012#issuecomment-595087386)\n */\n\nfunction makeDblclick(ev) {\n\tlet init = {\n\t\t// EventInit\n\t\tbubbles: ev.bubbles,\n\t\tcancelable: ev.cancelable,\n\t\tcomposed: ev.composed,\n\n\t\t// UIEventInit\n\t\tdetail: 2,\n\t\tview: ev.view,\n\n\t\t// mouseEventInit\n\t\tscreenX: ev.screenX,\n\t\tscreenY: ev.screenY,\n\t\tclientX: ev.clientX,\n\t\tclientY: ev.clientY,\n\t\tctrlKey: ev.ctrlKey,\n\t\tshiftKey: ev.shiftKey,\n\t\taltKey: ev.altKey,\n\t\tmetaKey: ev.metaKey,\n\t\tbutton: ev.button,\n\t\tbuttons: ev.buttons,\n\t\trelatedTarget: ev.relatedTarget,\n\t\tregion: ev.region,\n\t};\n\n\tlet newEvent;\n\t// The `click` event received should be a PointerEvent - but some\n\t// Firefox versions still use MouseEvent.\n\tif (ev instanceof PointerEvent) {\n\t\tinit = {\n\t\t\t...init,\n\t\t\tpointerId: ev.pointerId,\n\t\t\twidth: ev.width,\n\t\t\theight: ev.height,\n\t\t\tpressure: ev.pressure,\n\t\t\ttangentialPressure: ev.tangentialPressure,\n\t\t\ttiltX: ev.tiltX,\n\t\t\ttiltY: ev.tiltY,\n\t\t\ttwist: ev.twist,\n\t\t\tpointerType: ev.pointerType,\n\t\t\tisPrimary: ev.isPrimary,\n\t\t};\n\t\tnewEvent = new PointerEvent('dblclick', init);\n\t} else {\n\t\tnewEvent = new MouseEvent('dblclick', init);\n\t}\n\treturn newEvent;\n}\n\nconst delay = 200;\n\n/**\n * Adds a `dblclick` listener which also handles double taps (simulating `dblclick`\n * on platforms which don't fire it for touch events).\n * @param {EventTarget} obj\n * @param {(ev: MouseEvent) => void} handler\n * @returns {{dblclick: (ev: MouseEvent) => void, simDblclick: (ev: PointerEvent) => void}}\n * The listeners to pass to `removeDoubleTapListener`.\n */\nexport function addDoubleTapListener(obj, handler) {\n\t// Most browsers handle double tap natively\n\tobj.addEventListener('dblclick', handler);\n\n\t// On some platforms the browser doesn't fire native dblclicks for touch events.\n\t// It seems that in all such cases `detail` property of `click` event is always `1`.\n\t// So here we rely on that fact to avoid excessive 'dblclick' simulation when not needed.\n\tlet last = 0,\n\tdetail;\n\tfunction simDblclick(ev) {\n\t\tif (ev.detail !== 1) {\n\t\t\tdetail = ev.detail; // keep in sync to avoid false dblclick in some cases\n\t\t\treturn;\n\t\t}\n\n\t\tif (ev.pointerType === 'mouse' ||\n\t\t\t(ev.sourceCapabilities && !ev.sourceCapabilities.firesTouchEvents)) {\n\n\t\t\treturn;\n\t\t}\n\n\t\t// When clicking on an <input>, the browser generates a click on its\n\t\t// <label> (and vice versa) triggering two clicks in quick succession.\n\t\t// This ignores clicks on elements which are a label with a 'for'\n\t\t// attribute (or children of such a label), but not children of\n\t\t// a <input>.\n\t\tconst path = DomEvent.getPropagationPath(ev);\n\t\tif (path.some(el => el instanceof HTMLLabelElement && el.attributes.for) &&\n\t\t\t!path.some(el => (\n\t\t\t\tel instanceof HTMLInputElement ||\n\t\t\t\t\tel instanceof HTMLSelectElement\n\t\t\t))\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst now = Date.now();\n\t\tif (now - last <= delay) {\n\t\t\tdetail++;\n\t\t\tif (detail === 2) {\n\t\t\t\tev.target.dispatchEvent(makeDblclick(ev));\n\t\t\t}\n\t\t} else {\n\t\t\tdetail = 1;\n\t\t}\n\t\tlast = now;\n\t}\n\n\tobj.addEventListener('click', simDblclick);\n\n\treturn {\n\t\tdblclick: handler,\n\t\tsimDblclick\n\t};\n}\n\n/**\n * Removes the listeners added by `addDoubleTapListener`.\n * @param {EventTarget} obj\n * @param {{dblclick: (ev: MouseEvent) => void, simDblclick: (ev: PointerEvent) => void}} handlers\n * @returns {void}\n */\nexport function removeDoubleTapListener(obj, handlers) {\n\tobj.removeEventListener('dblclick', handlers.dblclick);\n\tobj.removeEventListener('click', handlers.simDblclick);\n}\n"],"mappings":";;AASA,SAAS,aAAa,IAAI;CACzB,IAAI,OAAO;EAEV,SAAS,GAAG;EACZ,YAAY,GAAG;EACf,UAAU,GAAG;EAGb,QAAQ;EACR,MAAM,GAAG;EAGT,SAAS,GAAG;EACZ,SAAS,GAAG;EACZ,SAAS,GAAG;EACZ,SAAS,GAAG;EACZ,SAAS,GAAG;EACZ,UAAU,GAAG;EACb,QAAQ,GAAG;EACX,SAAS,GAAG;EACZ,QAAQ,GAAG;EACX,SAAS,GAAG;EACZ,eAAe,GAAG;EAClB,QAAQ,GAAG;CACZ;CAEA,IAAI;CAGJ,IAAI,cAAc,cAAc;EAC/B,OAAO;GACN,GAAG;GACH,WAAW,GAAG;GACd,OAAO,GAAG;GACV,QAAQ,GAAG;GACX,UAAU,GAAG;GACb,oBAAoB,GAAG;GACvB,OAAO,GAAG;GACV,OAAO,GAAG;GACV,OAAO,GAAG;GACV,aAAa,GAAG;GAChB,WAAW,GAAG;EACf;EACA,WAAW,IAAI,aAAa,YAAY,IAAI;CAC7C,OACC,WAAW,IAAI,WAAW,YAAY,IAAI;CAE3C,OAAO;AACR;AAEA,MAAM,QAAQ;;;;;;;;;AAUd,SAAgB,qBAAqB,KAAK,SAAS;CAElD,IAAI,iBAAiB,YAAY,OAAO;CAKxC,IAAI,OAAO,GACX;CACA,SAAS,YAAY,IAAI;EACxB,IAAI,GAAG,WAAW,GAAG;GACpB,SAAS,GAAG;GACZ;EACD;EAEA,IAAI,GAAG,gBAAgB,WACrB,GAAG,sBAAsB,CAAC,GAAG,mBAAmB,kBAEjD;EAQD,MAAM,OAAOA,mBAA4B,EAAE;EAC3C,IAAI,KAAK,MAAK,OAAM,cAAc,oBAAoB,GAAG,WAAW,GAAG,KACtE,CAAC,KAAK,MAAK,OACV,cAAc,oBACb,cAAc,iBACf,GAED;EAGD,MAAM,MAAM,KAAK,IAAI;EACrB,IAAI,MAAM,QAAQ,OAAO;GACxB;GACA,IAAI,WAAW,GACd,GAAG,OAAO,cAAc,aAAa,EAAE,CAAC;EAE1C,OACC,SAAS;EAEV,OAAO;CACR;CAEA,IAAI,iBAAiB,SAAS,WAAW;CAEzC,OAAO;EACN,UAAU;EACV;CACD;AACD;;;;;;;AAQA,SAAgB,wBAAwB,KAAK,UAAU;CACtD,IAAI,oBAAoB,YAAY,SAAS,QAAQ;CACrD,IAAI,oBAAoB,SAAS,SAAS,WAAW;AACtD"}
1
+ {"version":3,"file":"DomEvent.DoubleTap.js","names":[],"sources":["../../../src/dom/DomEvent.DoubleTap.js"],"sourcesContent":["/*\n * Extends the event handling code with double tap support for mobile browsers.\n *\n * Note: currently most browsers fire native dblclick, with only a few exceptions\n * (see https://github.com/Leaflet/Leaflet/issues/7012#issuecomment-595087386)\n */\n\nfunction makeDblclick(ev) {\n\tconst init = {\n\t\t// EventInit\n\t\tbubbles: ev.bubbles,\n\t\tcancelable: ev.cancelable,\n\t\tcomposed: ev.composed,\n\n\t\t// UIEventInit\n\t\tdetail: 2,\n\t\tview: ev.view,\n\n\t\t// mouseEventInit\n\t\tscreenX: ev.screenX,\n\t\tscreenY: ev.screenY,\n\t\tclientX: ev.clientX,\n\t\tclientY: ev.clientY,\n\t\tctrlKey: ev.ctrlKey,\n\t\tshiftKey: ev.shiftKey,\n\t\taltKey: ev.altKey,\n\t\tmetaKey: ev.metaKey,\n\t\tbutton: ev.button,\n\t\tbuttons: ev.buttons,\n\t\trelatedTarget: ev.relatedTarget,\n\t\tregion: ev.region,\n\t};\n\n\tlet newEvent;\n\t// The `click` event received should be a PointerEvent - but some\n\t// Firefox versions still use MouseEvent.\n\tif (ev instanceof PointerEvent) {\n\t\tnewEvent = new PointerEvent('dblclick', {\n\t\t\t...init,\n\t\t\tpointerId: ev.pointerId,\n\t\t\twidth: ev.width,\n\t\t\theight: ev.height,\n\t\t\tpressure: ev.pressure,\n\t\t\ttangentialPressure: ev.tangentialPressure,\n\t\t\ttiltX: ev.tiltX,\n\t\t\ttiltY: ev.tiltY,\n\t\t\ttwist: ev.twist,\n\t\t\tpointerType: ev.pointerType,\n\t\t\tisPrimary: ev.isPrimary,\n\t\t});\n\t} else {\n\t\tnewEvent = new MouseEvent('dblclick', init);\n\t}\n\treturn newEvent;\n}\n\nconst delay = 200;\n\n/**\n * Adds a `dblclick` listener which also handles double taps (simulating `dblclick`\n * on platforms which don't fire it for touch events).\n * @param {EventTarget} obj\n * @param {(ev: MouseEvent) => void} handler\n * @returns {{dblclick: (ev: MouseEvent) => void, simDblclick: (ev: PointerEvent) => void}}\n * The listeners to pass to `removeDoubleTapListener`.\n */\nexport function addDoubleTapListener(obj, handler) {\n\t// Most browsers handle double tap natively\n\tobj.addEventListener('dblclick', handler);\n\n\t// On some platforms the browser doesn't fire native dblclicks for touch events.\n\t// It seems that in all such cases `detail` property of `click` event is always `1`.\n\t// So here we rely on that fact to avoid excessive 'dblclick' simulation when not needed.\n\tlet last = 0,\n\tdetail,\n\tpointerType;\n\n\t// iOS Safari reports `pointerType: 'mouse'` on clicks from touch (WebKit bug 282988), so we take it from the\n\t// pointerdown instead; capturing so that it's seen even if a child (e.g. a control) stops its propagation.\n\tfunction onPointerDown(ev) {\n\t\tpointerType = ev.pointerType;\n\t}\n\n\tfunction simDblclick(ev) {\n\t\tif (ev.detail !== 1) {\n\t\t\tdetail = ev.detail; // keep in sync to avoid false dblclick in some cases\n\t\t\treturn;\n\t\t}\n\n\t\tif (pointerType === 'mouse' ||\n\t\t\t(ev.sourceCapabilities && !ev.sourceCapabilities.firesTouchEvents)) {\n\n\t\t\treturn;\n\t\t}\n\n\t\t// When clicking on an <input>, the browser generates a click on its\n\t\t// <label> (and vice versa) triggering two clicks in quick succession.\n\t\t// This ignores clicks on elements which are a label with a 'for'\n\t\t// attribute (or children of such a label), but not children of\n\t\t// a <input>.\n\t\tconst path = ev.composedPath();\n\t\tif (path.some(el => el instanceof HTMLLabelElement && el.htmlFor) &&\n\t\t\t!path.some(el => (\n\t\t\t\tel instanceof HTMLInputElement ||\n\t\t\t\t\tel instanceof HTMLSelectElement\n\t\t\t))\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst now = Date.now();\n\t\tif (now - last <= delay) {\n\t\t\tdetail++;\n\t\t\tif (detail === 2) {\n\t\t\t\tev.target.dispatchEvent(makeDblclick(ev));\n\t\t\t}\n\t\t} else {\n\t\t\tdetail = 1;\n\t\t}\n\t\tlast = now;\n\t}\n\n\tobj.addEventListener('pointerdown', onPointerDown, true);\n\tobj.addEventListener('click', simDblclick);\n\n\treturn {\n\t\tdblclick: handler,\n\t\tonPointerDown,\n\t\tsimDblclick\n\t};\n}\n\n/**\n * Removes the listeners added by `addDoubleTapListener`.\n * @param {EventTarget} obj\n * @param {{dblclick: (ev: MouseEvent) => void, simDblclick: (ev: PointerEvent) => void}} handlers\n * @returns {void}\n */\nexport function removeDoubleTapListener(obj, handlers) {\n\tobj.removeEventListener('dblclick', handlers.dblclick);\n\tobj.removeEventListener('pointerdown', handlers.onPointerDown, true);\n\tobj.removeEventListener('click', handlers.simDblclick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W,GACd,GAAG,OAAO,cAAc,aAAa,EAAE,CAAC;EAE1C,OACC,SAAS;EAEV,OAAO;CACR;CAEA,IAAI,iBAAiB,eAAe,eAAe,IAAI;CACvD,IAAI,iBAAiB,SAAS,WAAW;CAEzC,OAAO;EACN,UAAU;EACV;EACA;CACD;AACD;;;;;;;AAQA,SAAgB,wBAAwB,KAAK,UAAU;CACtD,IAAI,oBAAoB,YAAY,SAAS,QAAQ;CACrD,IAAI,oBAAoB,eAAe,SAAS,eAAe,IAAI;CACnE,IAAI,oBAAoB,SAAS,SAAS,WAAW;AACtD"}
@@ -1,7 +1,6 @@
1
1
  import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
- //#region src/dom/DomEvent.PointerEvents.js
2
+ // src/dom/DomEvent.PointerEvents.js
3
3
  var DomEvent_PointerEvents_exports = /* @__PURE__ */ __exportAll({
4
- cleanupPointers: () => cleanupPointers,
5
4
  disablePointerDetection: () => disablePointerDetection,
6
5
  enablePointerDetection: () => enablePointerDetection,
7
6
  getPointers: () => getPointers
@@ -33,7 +32,7 @@ function disablePointerDetection(el) {
33
32
  el.removeEventListener("pointercancel", _onDelete, { capture: true });
34
33
  }
35
34
  function _onSet(e) {
36
- e.target.setPointerCapture(e.pointerId);
35
+ if (e.isTrusted) e.target.setPointerCapture(e.pointerId);
37
36
  activePointers.set(e.pointerId, e);
38
37
  }
39
38
  function _onUpdate(e) {
@@ -51,20 +50,6 @@ function _onDelete(e) {
51
50
  function getPointers() {
52
51
  return [...activePointers.values()];
53
52
  }
54
- /**
55
- * Clears the detected pointers on the document.
56
- * Note: This function should be not necessary to call, as the pointers are
57
- * automatically cleared with `pointerup`, `pointercancel` and `pointerout` events.
58
- * @group Pointer detection
59
- * @returns {void}
60
- */
61
- function cleanupPointers() {
62
- for (const e of activePointers.values()) try {
63
- e.target.releasePointerCapture(e.pointerId);
64
- } catch {}
65
- activePointers.clear();
66
- }
67
- //#endregion
68
- export { DomEvent_PointerEvents_exports, cleanupPointers, disablePointerDetection, enablePointerDetection, getPointers };
53
+ export { DomEvent_PointerEvents_exports, disablePointerDetection, enablePointerDetection, getPointers };
69
54
 
70
55
  //# 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// NOTE: pointers are captured unconditionally, which can become a problem for\n// synthetic events. The prosthetic-hand library does handle pointer capture,\n// but others don't.\n// If this becomers an issue, replace with `e.isTrusted && e.target.setPointerCapture()`\nfunction _onSet(e) {\n\te.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\n// NOTE: idem as _onSet.\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\n/**\n * Clears the detected pointers on the document.\n * Note: This function should be not necessary to call, as the pointers are\n * automatically cleared with `pointerup`, `pointercancel` and `pointerout` events.\n * @group Pointer detection\n * @returns {void}\n */\nfunction cleanupPointers() {\n\tfor (const e of activePointers.values()) {\n\t\ttry {\n\t\t\te.target.releasePointerCapture(e.pointerId);\n\t\t} catch {\n\t\t\t// target may already be detached; capture was on a dead node\n\t\t}\n\t}\n\tactivePointers.clear();\n}\n\nexport {\n\tenablePointerDetection,\n\tdisablePointerDetection,\n\tgetPointers,\n\tcleanupPointers\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;AAMA,SAAS,OAAO,GAAG;CAClB,EAAE,OAAO,kBAAkB,EAAE,SAAS;CACtC,eAAe,IAAI,EAAE,WAAW,CAAC;AAClC;AAEA,SAAS,UAAU,GAAG;CACrB,IAAI,eAAe,IAAI,EAAE,SAAS,GACjC,eAAe,IAAI,EAAE,WAAW,CAAC;AAEnC;AAGA,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;;;;;;;;AASA,SAAS,kBAAkB;CAC1B,KAAK,MAAM,KAAK,eAAe,OAAO,GACrC,IAAI;EACH,EAAE,OAAO,sBAAsB,EAAE,SAAS;CAC3C,QAAQ,CAER;CAED,eAAe,MAAM;AACtB"}
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,17 +1,15 @@
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 Browser_default from "../core/Browser.js";
5
4
  import { addDoubleTapListener, removeDoubleTapListener } from "./DomEvent.DoubleTap.js";
6
5
  import { DomEvent_PointerEvents_exports } from "./DomEvent.PointerEvents.js";
7
6
  import { getScale } from "./DomUtil.js";
8
- //#region src/dom/DomEvent.js
7
+ // src/dom/DomEvent.js
9
8
  var DomEvent_exports = /* @__PURE__ */ __exportAll({
10
9
  PointerEvents: () => DomEvent_PointerEvents_exports,
11
10
  disableClickPropagation: () => disableClickPropagation,
12
11
  disableScrollPropagation: () => disableScrollPropagation,
13
12
  getPointerPosition: () => getPointerPosition,
14
- getPropagationPath: () => getPropagationPath,
15
13
  getWheelDelta: () => getWheelDelta,
16
14
  getWheelPxFactor: () => getWheelPxFactor,
17
15
  isExternalTarget: () => isExternalTarget,
@@ -32,12 +30,11 @@ var DomEvent_exports = /* @__PURE__ */ __exportAll({
32
30
  * @param {string|Record<string, (ev: any) => void>} types
33
31
  * @param {((ev: any) => void)|object} [fn]
34
32
  * @param {object} [context]
35
- * @returns {typeof import('./DomEvent.js')}
33
+ * @returns {void}
36
34
  */
37
35
  function on(obj, types, fn, context) {
38
36
  if (types && typeof types === "object") for (const [type, listener] of Object.entries(types)) addOne(obj, type, listener, fn);
39
37
  else for (const type of splitWords(types)) addOne(obj, type, fn, context);
40
- return this;
41
38
  }
42
39
  const eventsKey = "_maplair_events";
43
40
  /**
@@ -51,7 +48,7 @@ const eventsKey = "_maplair_events";
51
48
  * @param {string|Record<string, (ev: any) => void>} [types]
52
49
  * @param {((ev: any) => void)|object} [fn]
53
50
  * @param {object} [context]
54
- * @returns {typeof import('./DomEvent.js')}
51
+ * @returns {void}
55
52
  */
56
53
  function off(obj, types, fn, context) {
57
54
  if (arguments.length === 1) {
@@ -63,7 +60,6 @@ function off(obj, types, fn, context) {
63
60
  if (arguments.length === 2) batchRemove(obj, (type) => types.includes(type));
64
61
  else for (const type of types) removeOne(obj, type, fn, context);
65
62
  }
66
- return this;
67
63
  }
68
64
  const DIGIT_RE = /\d/;
69
65
  function batchRemove(obj, filterFn) {
@@ -72,38 +68,23 @@ function batchRemove(obj, filterFn) {
72
68
  if (!filterFn || filterFn(type)) removeOne(obj, type, null, null, id);
73
69
  }
74
70
  }
75
- const pointerSubst = {
76
- pointerenter: "pointerover",
77
- pointerleave: "pointerout",
78
- wheel: typeof window === "undefined" ? false : !("onwheel" in window) && "mousewheel"
79
- };
80
71
  function addOne(obj, type, fn, context) {
81
72
  const id = type + stamp(fn) + (context ? `_${stamp(context)}` : "");
82
- if (obj[eventsKey] && obj[eventsKey][id]) return this;
73
+ if (obj[eventsKey] && obj[eventsKey][id]) return;
83
74
  let handler = function(e) {
84
75
  return fn.call(context || obj, e);
85
76
  };
86
- const originalHandler = handler;
87
- if (Browser_default.touch && type === "dblclick") handler = addDoubleTapListener(obj, handler);
88
- else if ("addEventListener" in obj) {
89
- if (type === "wheel" || type === "mousewheel") obj.addEventListener(pointerSubst[type] || type, handler, { passive: false });
90
- else if (type === "pointerenter" || type === "pointerleave") {
91
- handler = function(e) {
92
- if (isExternalTarget(obj, e)) originalHandler(e);
93
- };
94
- obj.addEventListener(pointerSubst[type], handler, false);
95
- } else obj.addEventListener(type, originalHandler, false);
96
- } else obj.attachEvent(`on${type}`, handler);
77
+ if (type === "dblclick") handler = addDoubleTapListener(obj, handler);
78
+ else obj.addEventListener(type, handler, type === "wheel" ? { passive: false } : false);
97
79
  obj[eventsKey] ??= {};
98
80
  obj[eventsKey][id] = handler;
99
81
  }
100
82
  function removeOne(obj, type, fn, context, id) {
101
83
  id ??= type + stamp(fn) + (context ? `_${stamp(context)}` : "");
102
84
  const handler = obj[eventsKey] && obj[eventsKey][id];
103
- if (!handler) return this;
104
- if (Browser_default.touch && type === "dblclick") removeDoubleTapListener(obj, handler);
105
- else if ("removeEventListener" in obj) obj.removeEventListener(pointerSubst[type] || type, handler, false);
106
- else obj.detachEvent(`on${type}`, handler);
85
+ if (!handler) return;
86
+ if (type === "dblclick") removeDoubleTapListener(obj, handler);
87
+ else obj.removeEventListener(type, handler, false);
107
88
  obj[eventsKey][id] = null;
108
89
  }
109
90
  /**
@@ -114,22 +95,20 @@ function removeOne(obj, type, fn, context, id) {
114
95
  * ```
115
96
  * Also accepts a Maplair event with an `originalEvent`.
116
97
  * @param {Event|{originalEvent: Event}} e
117
- * @returns {typeof import('./DomEvent.js')}
98
+ * @returns {void}
118
99
  */
119
100
  function stopPropagation(e) {
120
101
  if (e.stopPropagation) e.stopPropagation();
121
102
  else if (e.originalEvent) e.originalEvent._stopped = true;
122
103
  else console.debug("Unsupported event", e);
123
- return this;
124
104
  }
125
105
  /**
126
106
  * Adds `stopPropagation` to the element's `'wheel'` events (plus browser variants).
127
107
  * @param {HTMLElement} el
128
- * @returns {typeof import('./DomEvent.js')}
108
+ * @returns {void}
129
109
  */
130
110
  function disableScrollPropagation(el) {
131
111
  addOne(el, "wheel", stopPropagation);
132
- return this;
133
112
  }
134
113
  /**
135
114
  * Adds `stopPropagation` to the element's `'dblclick'`, `'contextmenu'`
@@ -137,12 +116,11 @@ function disableScrollPropagation(el) {
137
116
  * For `'click'` events, prevents the map from handling the click
138
117
  * while still allowing the native DOM click event to propagate normally.
139
118
  * @param {HTMLElement} el
140
- * @returns {typeof import('./DomEvent.js')}
119
+ * @returns {void}
141
120
  */
142
121
  function disableClickPropagation(el) {
143
122
  on(el, "pointerdown dblclick contextmenu", stopPropagation);
144
123
  el["_maplair_disable_click"] = true;
145
- return this;
146
124
  }
147
125
  /**
148
126
  * Prevents the default action of the DOM Event `e` from happening (such as
@@ -150,30 +128,19 @@ function disableClickPropagation(el) {
150
128
  * with page reload when a `<form>` is submitted).
151
129
  * Use it inside listener functions.
152
130
  * @param {Event} e
153
- * @returns {typeof import('./DomEvent.js')}
131
+ * @returns {void}
154
132
  */
155
133
  function preventDefault(e) {
156
134
  e.preventDefault?.();
157
- return this;
158
135
  }
159
136
  /**
160
137
  * Does `stopPropagation` and `preventDefault` at the same time.
161
138
  * @param {Event} e
162
- * @returns {typeof import('./DomEvent.js')}
139
+ * @returns {void}
163
140
  */
164
141
  function stop(e) {
165
142
  preventDefault(e);
166
143
  stopPropagation(e);
167
- return this;
168
- }
169
- /**
170
- * Returns an array containing the `HTMLElement`s that the given DOM event
171
- * should propagate to (if not stopped).
172
- * @param {Event} ev
173
- * @returns {EventTarget[]}
174
- */
175
- function getPropagationPath(ev) {
176
- return ev.composedPath();
177
144
  }
178
145
  /**
179
146
  * Gets normalized pointer position from a DOM event relative to the
@@ -192,8 +159,7 @@ function getPointerPosition(e, container) {
192
159
  * @returns {number}
193
160
  */
194
161
  function getWheelPxFactor() {
195
- const ratio = window.devicePixelRatio;
196
- return Browser_default.linux && Browser_default.chrome ? ratio : Browser_default.mac ? ratio * 3 : ratio > 0 ? 2 * ratio : 1;
162
+ return window.devicePixelRatio * 2;
197
163
  }
198
164
  /**
199
165
  * Gets normalized wheel delta from a wheel DOM event, in vertical
@@ -208,23 +174,15 @@ function getWheelDelta(e) {
208
174
  }
209
175
  /**
210
176
  * Checks if the pointer really left/entered the element `el` (for
211
- * `pointerenter`/`pointerleave`).
177
+ * `pointerover`/`pointerout`).
212
178
  * @internal
213
179
  * @param {Node} el
214
180
  * @param {MouseEvent} e
215
181
  * @returns {boolean}
216
182
  */
217
183
  function isExternalTarget(el, e) {
218
- let related = e.relatedTarget;
219
- if (!related) return true;
220
- try {
221
- while (related && related !== el) related = related.parentNode;
222
- } catch (err) {
223
- return false;
224
- }
225
- return related !== el;
184
+ return !el.contains(e.relatedTarget);
226
185
  }
227
- //#endregion
228
- export { DomEvent_exports, DomEvent_PointerEvents_exports as PointerEvents, disableClickPropagation, disableScrollPropagation, getPointerPosition, getPropagationPath, getWheelDelta, getWheelPxFactor, isExternalTarget, off, on, preventDefault, stop, stopPropagation };
186
+ export { DomEvent_exports, DomEvent_PointerEvents_exports as PointerEvents, disableClickPropagation, disableScrollPropagation, getPointerPosition, getWheelDelta, getWheelPxFactor, isExternalTarget, off, on, preventDefault, stop, stopPropagation };
229
187
 
230
188
  //# sourceMappingURL=DomEvent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DomEvent.js","names":["Util.splitWords","Util.stamp","Browser"],"sources":["../../../src/dom/DomEvent.js"],"sourcesContent":["import {Point} from '../geometry/Point.js';\nimport * as Util from '../core/Util.js';\nimport Browser from '../core/Browser.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 {typeof import('./DomEvent.js')}\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\treturn this;\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 {typeof import('./DomEvent.js')}\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\treturn this;\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\nconst pointerSubst = {\n\tpointerenter: 'pointerover',\n\tpointerleave: 'pointerout',\n\twheel: typeof window === 'undefined' ? false : !('onwheel' in window) && 'mousewheel'\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 this; }\n\n\tlet handler = function (e) {\n\t\treturn fn.call(context || obj, e);\n\t};\n\n\tconst originalHandler = handler;\n\n\tif (Browser.touch && (type === 'dblclick')) {\n\t\thandler = addDoubleTapListener(obj, handler);\n\n\t} else if ('addEventListener' in obj) {\n\n\t\tif (type === 'wheel' || type === 'mousewheel') {\n\t\t\tobj.addEventListener(pointerSubst[type] || type, handler, {passive: false});\n\t\t} else if (type === 'pointerenter' || type === 'pointerleave') {\n\t\t\thandler = function (e) {\n\t\t\t\tif (isExternalTarget(obj, e)) {\n\t\t\t\t\toriginalHandler(e);\n\t\t\t\t}\n\t\t\t};\n\t\t\tobj.addEventListener(pointerSubst[type], handler, false);\n\n\t\t} else {\n\t\t\tobj.addEventListener(type, originalHandler, false);\n\t\t}\n\n\t} else {\n\t\tobj.attachEvent(`on${type}`, handler);\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 this; }\n\n\tif (Browser.touch && (type === 'dblclick')) {\n\t\tremoveDoubleTapListener(obj, handler);\n\n\t} else if ('removeEventListener' in obj) {\n\n\t\tobj.removeEventListener(pointerSubst[type] || type, handler, false);\n\n\t} else {\n\t\tobj.detachEvent(`on${type}`, handler);\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 {typeof import('./DomEvent.js')}\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\treturn this;\n}\n\n/**\n * Adds `stopPropagation` to the element's `'wheel'` events (plus browser variants).\n * @param {HTMLElement} el\n * @returns {typeof import('./DomEvent.js')}\n */\nexport function disableScrollPropagation(el) {\n\taddOne(el, 'wheel', stopPropagation);\n\treturn this;\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 {typeof import('./DomEvent.js')}\n */\nexport function disableClickPropagation(el) {\n\ton(el, 'pointerdown dblclick contextmenu', stopPropagation);\n\tel['_maplair_disable_click'] = true;\n\treturn this;\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 {typeof import('./DomEvent.js')}\n */\nexport function preventDefault(e) {\n\te.preventDefault?.();\n\treturn this;\n}\n\n/**\n * Does `stopPropagation` and `preventDefault` at the same time.\n * @param {Event} e\n * @returns {typeof import('./DomEvent.js')}\n */\nexport function stop(e) {\n\tpreventDefault(e);\n\tstopPropagation(e);\n\treturn this;\n}\n\n/**\n * Returns an array containing the `HTMLElement`s that the given DOM event\n * should propagate to (if not stopped).\n * @param {Event} ev\n * @returns {EventTarget[]}\n */\nexport function getPropagationPath(ev) {\n\treturn ev.composedPath();\n}\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) for all Browsers\n\t// except OSX (Mac) -> 3x, Chrome running on Linux 1x\n\tconst ratio = window.devicePixelRatio;\n\treturn Browser.linux && Browser.chrome ? ratio :\n\t\tBrowser.mac ? ratio * 3 :\n\t\tratio > 0 ? 2 * ratio : 1;\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 * `pointerenter`/`pointerleave`).\n * @internal\n * @param {Node} el\n * @param {MouseEvent} e\n * @returns {boolean}\n */\nexport function isExternalTarget(el, e) {\n\n\tlet related = e.relatedTarget;\n\n\tif (!related) { return true; }\n\n\ttry {\n\t\twhile (related && (related !== el)) {\n\t\t\trelated = related.parentNode;\n\t\t}\n\t} catch (err) {\n\t\treturn false;\n\t}\n\treturn (related !== el);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,GAAG,KAAK,OAAO,IAAI,SAAS;CAE3C,IAAI,SAAS,OAAO,UAAU,UAC7B,KAAK,MAAM,C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B"}
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,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AAC,GAAG,SAAS,EAAE,aAAa;AACpC"}
@@ -1,19 +1,15 @@
1
1
  import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
2
  import { Point } from "../geometry/Point.js";
3
3
  import { off, on, preventDefault } from "./DomEvent.js";
4
- //#region src/dom/DomUtil.js
4
+ // src/dom/DomUtil.js
5
5
  var DomUtil_exports = /* @__PURE__ */ __exportAll({
6
6
  create: () => create,
7
7
  disableImageDrag: () => disableImageDrag,
8
- disableTextSelection: () => disableTextSelection,
9
8
  enableImageDrag: () => enableImageDrag,
10
- enableTextSelection: () => enableTextSelection,
11
9
  get: () => get,
12
10
  getPosition: () => getPosition,
13
11
  getScale: () => getScale,
14
12
  getSizedParentNode: () => getSizedParentNode,
15
- preventOutline: () => preventOutline,
16
- restoreOutline: () => restoreOutline,
17
13
  setPosition: () => setPosition,
18
14
  setTransform: () => setTransform,
19
15
  toBack: () => toBack,
@@ -50,7 +46,9 @@ function create(tagName, className, container) {
50
46
  */
51
47
  function toFront(el) {
52
48
  const parent = el.parentNode;
53
- if (parent && parent.lastChild !== el) parent.appendChild(el);
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);
54
52
  }
55
53
  /**
56
54
  * Makes `el` the first child of its parent, so it renders behind the other children.
@@ -59,7 +57,9 @@ function toFront(el) {
59
57
  */
60
58
  function toBack(el) {
61
59
  const parent = el.parentNode;
62
- if (parent && parent.firstChild !== el) parent.insertBefore(el, parent.firstChild);
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);
63
63
  }
64
64
  /**
65
65
  * Resets the 3D CSS transform of `el` so it is translated by `offset` pixels
@@ -77,16 +77,18 @@ function setTransform(el, offset, scale) {
77
77
  }
78
78
  const positions = /* @__PURE__ */ new WeakMap();
79
79
  /**
80
- * Sets the position of `el` to coordinates specified by `point`,
81
- * using CSS translate or top/left positioning depending on the browser
82
- * (used by Maplair internally to position its layers).
80
+ * Sets the position of `el` to coordinates specified by `point` using a CSS translate
81
+ * (used by Maplair internally to position its layers). With `flat`, the translate is 2D,
82
+ * so `el` is painted into its parent's compositor layer instead of getting a layer of its own.
83
83
  * @param {HTMLElement|SVGElement} el
84
84
  * @param {Point} point
85
+ * @param {boolean} [flat]
85
86
  * @returns {void}
86
87
  */
87
- function setPosition(el, point) {
88
+ function setPosition(el, point, flat) {
88
89
  positions.set(el, point);
89
- setTransform(el, point);
90
+ if (flat) el.style.transform = `translate(${point.x}px, ${point.y}px)`;
91
+ else setTransform(el, point);
90
92
  }
91
93
  /**
92
94
  * Returns the coordinates of an element previously positioned with setPosition.
@@ -96,31 +98,6 @@ function setPosition(el, point) {
96
98
  function getPosition(el) {
97
99
  return positions.get(el) ?? new Point(0, 0);
98
100
  }
99
- const documentStyle = typeof document === "undefined" ? {} : document.documentElement.style;
100
- const userSelectProp = ["userSelect", "WebkitUserSelect"].find((prop) => prop in documentStyle);
101
- let prevUserSelect;
102
- /**
103
- * Prevents the user from selecting text in the document. Used internally
104
- * by Maplair to override the behaviour of any click-and-drag interaction on
105
- * the map. Affects drag interactions on the whole document.
106
- * @returns {void}
107
- */
108
- function disableTextSelection() {
109
- const value = documentStyle[userSelectProp];
110
- if (value === "none") return;
111
- prevUserSelect = value;
112
- documentStyle[userSelectProp] = "none";
113
- }
114
- /**
115
- * Cancels the effects of a previous
116
- * [`DomUtil.disableTextSelection`](#domutil-disabletextselection).
117
- * @returns {void}
118
- */
119
- function enableTextSelection() {
120
- if (typeof prevUserSelect === "undefined") return;
121
- documentStyle[userSelectProp] = prevUserSelect;
122
- prevUserSelect = void 0;
123
- }
124
101
  /**
125
102
  * Prevents the user from generating `dragstart` DOM events, usually generated when
126
103
  * the user drags an image.
@@ -137,37 +114,6 @@ function disableImageDrag() {
137
114
  function enableImageDrag() {
138
115
  off(window, "dragstart", preventDefault);
139
116
  }
140
- let _outlineElement;
141
- let _outlineStyle;
142
- /**
143
- * Makes the [outline](https://developer.mozilla.org/docs/Web/CSS/outline)
144
- * of the element `element` invisible. Used internally by Maplair to prevent
145
- * focusable elements from displaying an outline when the user performs a
146
- * drag interaction on them.
147
- * @param {HTMLElement} element
148
- * @returns {void}
149
- */
150
- function preventOutline(element) {
151
- while (element.tabIndex === -1) element = element.parentNode;
152
- if (!element.style) return;
153
- restoreOutline();
154
- _outlineElement = element;
155
- _outlineStyle = element.style.outlineStyle;
156
- element.style.outlineStyle = "none";
157
- on(window, "keydown", restoreOutline);
158
- }
159
- /**
160
- * Cancels the effects of a previous
161
- * [`DomUtil.preventOutline`](#domutil-preventoutline).
162
- * @returns {void}
163
- */
164
- function restoreOutline() {
165
- if (!_outlineElement) return;
166
- _outlineElement.style.outlineStyle = _outlineStyle;
167
- _outlineElement = void 0;
168
- _outlineStyle = void 0;
169
- off(window, "keydown", restoreOutline);
170
- }
171
117
  /**
172
118
  * Finds the closest parent node which size (width and height) is not null.
173
119
  * @param {HTMLElement} element
@@ -195,7 +141,6 @@ function getScale(element) {
195
141
  boundingClientRect: rect
196
142
  };
197
143
  }
198
- //#endregion
199
- export { DomUtil_exports, create, disableImageDrag, disableTextSelection, enableImageDrag, enableTextSelection, get, getPosition, getScale, getSizedParentNode, preventOutline, restoreOutline, setPosition, setTransform, toBack, toFront };
144
+ export { DomUtil_exports, create, disableImageDrag, enableImageDrag, get, getPosition, getScale, getSizedParentNode, setPosition, setTransform, toBack, toFront };
200
145
 
201
146
  //# sourceMappingURL=DomUtil.js.map
@@ -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) {\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) {\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`,\n * using CSS translate or top/left positioning depending on the browser\n * (used by Maplair internally to position its layers).\n * @param {HTMLElement|SVGElement} el\n * @param {Point} point\n * @returns {void}\n */\nexport function setPosition(el, point) {\n\tpositions.set(el, point);\n\tsetTransform(el, point);\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\nconst documentStyle = typeof document === 'undefined' ? {} : document.documentElement.style;\n// Safari still needs a vendor prefix, we need to detect with property name is supported.\nconst userSelectProp = ['userSelect', 'WebkitUserSelect'].find(prop => prop in documentStyle);\nlet prevUserSelect;\n\n/**\n * Prevents the user from selecting text in the document. Used internally\n * by Maplair to override the behaviour of any click-and-drag interaction on\n * the map. Affects drag interactions on the whole document.\n * @returns {void}\n */\nexport function disableTextSelection() {\n\tconst value = documentStyle[userSelectProp];\n\n\tif (value === 'none') {\n\t\treturn;\n\t}\n\n\tprevUserSelect = value;\n\tdocumentStyle[userSelectProp] = 'none';\n}\n\n/**\n * Cancels the effects of a previous\n * [`DomUtil.disableTextSelection`](#domutil-disabletextselection).\n * @returns {void}\n */\nexport function enableTextSelection() {\n\tif (typeof prevUserSelect === 'undefined') {\n\t\treturn;\n\t}\n\n\tdocumentStyle[userSelectProp] = prevUserSelect;\n\tprevUserSelect = undefined;\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\nlet _outlineElement, _outlineStyle;\n\n/**\n * Makes the [outline](https://developer.mozilla.org/docs/Web/CSS/outline)\n * of the element `element` invisible. Used internally by Maplair to prevent\n * focusable elements from displaying an outline when the user performs a\n * drag interaction on them.\n * @param {HTMLElement} element\n * @returns {void}\n */\nexport function preventOutline(element) {\n\twhile (element.tabIndex === -1) {\n\t\telement = element.parentNode;\n\t}\n\tif (!element.style) { return; }\n\trestoreOutline();\n\t_outlineElement = element;\n\t_outlineStyle = element.style.outlineStyle;\n\telement.style.outlineStyle = 'none';\n\tDomEvent.on(window, 'keydown', restoreOutline);\n}\n\n/**\n * Cancels the effects of a previous\n * [`DomUtil.preventOutline`](#domutil-preventoutline).\n * @returns {void}\n */\nexport function restoreOutline() {\n\tif (!_outlineElement) { return; }\n\t_outlineElement.style.outlineStyle = _outlineStyle;\n\t_outlineElement = undefined;\n\t_outlineStyle = undefined;\n\tDomEvent.off(window, 'keydown', restoreOutline);\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,cA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AAY,QAAQ,aAAaA,cAAuB;AACzD;;;;;;AAOA,SAAgB,kBAAkB;CACjC,IAAa,QAAQ,aAAaA,cAAuB;AAC1D;AAEA,IAAI;AAAiB,IAAA;;;;;;;;;AAUrB,SAAgB,eAAe,SAAS;CACvC,OAAO,QAAQ,aAAa,IAC3B,UAAU,QAAQ;CAEnB,IAAI,CAAC,QAAQ,OAAS;CACtB,eAAe;CACf,kBAAkB;CAClB,gBAAgB,QAAQ,MAAM;CAC9B,QAAQ,MAAM,eAAe;CAC7B,GAAY,QAAQ,WAAW,cAAc;AAC9C;;;;;;AAOA,SAAgB,iBAAiB;CAChC,IAAI,CAAC,iBAAmB;CACxB,gBAAgB,MAAM,eAAe;CACrC,kBAAkB,KAAA;CAClB,gBAAgB,KAAA;CAChB,IAAa,QAAQ,WAAW,cAAc;AAC/C;;;;;;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"}
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\t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