maplair 4.0.0-alpha.1

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 (262) hide show
  1. package/CHANGELOG.md +2804 -0
  2. package/LICENSE +27 -0
  3. package/README.md +40 -0
  4. package/dist/esm/Maplair.js +71 -0
  5. package/dist/esm/Maplair.js.map +1 -0
  6. package/dist/esm/_virtual/_rolldown/runtime.js +13 -0
  7. package/dist/esm/control/AttributionControl.js +79 -0
  8. package/dist/esm/control/AttributionControl.js.map +1 -0
  9. package/dist/esm/control/Control.js +81 -0
  10. package/dist/esm/control/Control.js.map +1 -0
  11. package/dist/esm/control/LayersControl.js +220 -0
  12. package/dist/esm/control/LayersControl.js.map +1 -0
  13. package/dist/esm/control/ScaleControl.js +72 -0
  14. package/dist/esm/control/ScaleControl.js.map +1 -0
  15. package/dist/esm/control/ZoomControl.js +86 -0
  16. package/dist/esm/control/ZoomControl.js.map +1 -0
  17. package/dist/esm/core/Browser.js +31 -0
  18. package/dist/esm/core/Browser.js.map +1 -0
  19. package/dist/esm/core/Class.js +52 -0
  20. package/dist/esm/core/Class.js.map +1 -0
  21. package/dist/esm/core/Events.js +149 -0
  22. package/dist/esm/core/Events.js.map +1 -0
  23. package/dist/esm/core/Handler.js +32 -0
  24. package/dist/esm/core/Handler.js.map +1 -0
  25. package/dist/esm/core/I18n.js +36 -0
  26. package/dist/esm/core/I18n.js.map +1 -0
  27. package/dist/esm/core/Util.js +71 -0
  28. package/dist/esm/core/Util.js.map +1 -0
  29. package/dist/esm/dom/DomEvent.DoubleTap.js +74 -0
  30. package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -0
  31. package/dist/esm/dom/DomEvent.PointerEvents.js +46 -0
  32. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -0
  33. package/dist/esm/dom/DomEvent.js +135 -0
  34. package/dist/esm/dom/DomEvent.js.map +1 -0
  35. package/dist/esm/dom/DomUtil.js +107 -0
  36. package/dist/esm/dom/DomUtil.js.map +1 -0
  37. package/dist/esm/dom/Draggable.js +107 -0
  38. package/dist/esm/dom/Draggable.js.map +1 -0
  39. package/dist/esm/dom/PosAnimation.js +56 -0
  40. package/dist/esm/dom/PosAnimation.js.map +1 -0
  41. package/dist/esm/geo/LatLng.js +65 -0
  42. package/dist/esm/geo/LatLng.js.map +1 -0
  43. package/dist/esm/geo/LatLngBounds.js +114 -0
  44. package/dist/esm/geo/LatLngBounds.js.map +1 -0
  45. package/dist/esm/geo/crs/CRS.js +51 -0
  46. package/dist/esm/geo/crs/CRS.js.map +1 -0
  47. package/dist/esm/geo/crs/EPSG3395.js +16 -0
  48. package/dist/esm/geo/crs/EPSG3395.js.map +1 -0
  49. package/dist/esm/geo/crs/EPSG3857.js +19 -0
  50. package/dist/esm/geo/crs/EPSG3857.js.map +1 -0
  51. package/dist/esm/geo/crs/EPSG4326.js +13 -0
  52. package/dist/esm/geo/crs/EPSG4326.js.map +1 -0
  53. package/dist/esm/geo/crs/EarthCRS.js +14 -0
  54. package/dist/esm/geo/crs/EarthCRS.js.map +1 -0
  55. package/dist/esm/geo/crs/SimpleCRS.js +23 -0
  56. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -0
  57. package/dist/esm/geo/projection/Projection.LonLat.js +19 -0
  58. package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -0
  59. package/dist/esm/geo/projection/Projection.Mercator.js +33 -0
  60. package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -0
  61. package/dist/esm/geo/projection/Projection.SphericalMercator.js +27 -0
  62. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -0
  63. package/dist/esm/geo/projection/index.js +14 -0
  64. package/dist/esm/geo/projection/index.js.map +1 -0
  65. package/dist/esm/geometry/Bounds.js +91 -0
  66. package/dist/esm/geometry/Bounds.js.map +1 -0
  67. package/dist/esm/geometry/LineUtil.js +169 -0
  68. package/dist/esm/geometry/LineUtil.js.map +1 -0
  69. package/dist/esm/geometry/Point.js +119 -0
  70. package/dist/esm/geometry/Point.js.map +1 -0
  71. package/dist/esm/geometry/PolyUtil.js +89 -0
  72. package/dist/esm/geometry/PolyUtil.js.map +1 -0
  73. package/dist/esm/geometry/Transformation.js +34 -0
  74. package/dist/esm/geometry/Transformation.js.map +1 -0
  75. package/dist/esm/layer/BlanketOverlay.js +87 -0
  76. package/dist/esm/layer/BlanketOverlay.js.map +1 -0
  77. package/dist/esm/layer/DivOverlay.js +192 -0
  78. package/dist/esm/layer/DivOverlay.js.map +1 -0
  79. package/dist/esm/layer/FeatureGroup.js +40 -0
  80. package/dist/esm/layer/FeatureGroup.js.map +1 -0
  81. package/dist/esm/layer/GeoJSON.js +192 -0
  82. package/dist/esm/layer/GeoJSON.js.map +1 -0
  83. package/dist/esm/layer/ImageOverlay.js +140 -0
  84. package/dist/esm/layer/ImageOverlay.js.map +1 -0
  85. package/dist/esm/layer/Layer.js +119 -0
  86. package/dist/esm/layer/Layer.js.map +1 -0
  87. package/dist/esm/layer/LayerGroup.js +58 -0
  88. package/dist/esm/layer/LayerGroup.js.map +1 -0
  89. package/dist/esm/layer/Popup.js +224 -0
  90. package/dist/esm/layer/Popup.js.map +1 -0
  91. package/dist/esm/layer/SVGOverlay.js +21 -0
  92. package/dist/esm/layer/SVGOverlay.js.map +1 -0
  93. package/dist/esm/layer/Tooltip.js +228 -0
  94. package/dist/esm/layer/Tooltip.js.map +1 -0
  95. package/dist/esm/layer/VideoOverlay.js +54 -0
  96. package/dist/esm/layer/VideoOverlay.js.map +1 -0
  97. package/dist/esm/layer/marker/DefaultIcon.js +50 -0
  98. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -0
  99. package/dist/esm/layer/marker/DivIcon.js +37 -0
  100. package/dist/esm/layer/marker/DivIcon.js.map +1 -0
  101. package/dist/esm/layer/marker/Icon.js +65 -0
  102. package/dist/esm/layer/marker/Icon.js.map +1 -0
  103. package/dist/esm/layer/marker/Marker.Drag.js +77 -0
  104. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -0
  105. package/dist/esm/layer/marker/Marker.js +235 -0
  106. package/dist/esm/layer/marker/Marker.js.map +1 -0
  107. package/dist/esm/layer/tile/GridLayer.js +447 -0
  108. package/dist/esm/layer/tile/GridLayer.js.map +1 -0
  109. package/dist/esm/layer/tile/TileLayer.js +139 -0
  110. package/dist/esm/layer/tile/TileLayer.js.map +1 -0
  111. package/dist/esm/layer/tile/WMSTileLayer.js +68 -0
  112. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -0
  113. package/dist/esm/layer/vector/Canvas.js +292 -0
  114. package/dist/esm/layer/vector/Canvas.js.map +1 -0
  115. package/dist/esm/layer/vector/Circle.js +35 -0
  116. package/dist/esm/layer/vector/Circle.js.map +1 -0
  117. package/dist/esm/layer/vector/CircleMarker.js +69 -0
  118. package/dist/esm/layer/vector/CircleMarker.js.map +1 -0
  119. package/dist/esm/layer/vector/Path.js +68 -0
  120. package/dist/esm/layer/vector/Path.js.map +1 -0
  121. package/dist/esm/layer/vector/Polygon.js +70 -0
  122. package/dist/esm/layer/vector/Polygon.js.map +1 -0
  123. package/dist/esm/layer/vector/Polyline.js +152 -0
  124. package/dist/esm/layer/vector/Polyline.js.map +1 -0
  125. package/dist/esm/layer/vector/Rectangle.js +25 -0
  126. package/dist/esm/layer/vector/Rectangle.js.map +1 -0
  127. package/dist/esm/layer/vector/Renderer.getRenderer.js +31 -0
  128. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -0
  129. package/dist/esm/layer/vector/Renderer.js +39 -0
  130. package/dist/esm/layer/vector/Renderer.js.map +1 -0
  131. package/dist/esm/layer/vector/SVG.js +115 -0
  132. package/dist/esm/layer/vector/SVG.js.map +1 -0
  133. package/dist/esm/map/Map.js +844 -0
  134. package/dist/esm/map/Map.js.map +1 -0
  135. package/dist/esm/map/handler/BoxZoomHandler.js +105 -0
  136. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -0
  137. package/dist/esm/map/handler/DoubleClickZoomHandler.js +27 -0
  138. package/dist/esm/map/handler/DoubleClickZoomHandler.js.map +1 -0
  139. package/dist/esm/map/handler/DragHandler.js +133 -0
  140. package/dist/esm/map/handler/DragHandler.js.map +1 -0
  141. package/dist/esm/map/handler/KeyboardHandler.js +117 -0
  142. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -0
  143. package/dist/esm/map/handler/PinchZoomHandler.js +96 -0
  144. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -0
  145. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +50 -0
  146. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -0
  147. package/dist/esm/map/handler/TapHoldHandler.js +77 -0
  148. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -0
  149. package/dist/esm/package.js +6 -0
  150. package/dist/esm/package.js.map +1 -0
  151. package/dist/images/layers.svg +1 -0
  152. package/dist/images/logo.svg +1 -0
  153. package/dist/images/marker-icon.svg +1 -0
  154. package/dist/images/marker-shadow.svg +1 -0
  155. package/dist/maplair-global-src.js +6810 -0
  156. package/dist/maplair-global-src.js.map +1 -0
  157. package/dist/maplair-global.js +12 -0
  158. package/dist/maplair-global.js.map +1 -0
  159. package/dist/maplair-src.js +6704 -0
  160. package/dist/maplair-src.js.map +1 -0
  161. package/dist/maplair.css +730 -0
  162. package/dist/maplair.js +7 -0
  163. package/dist/maplair.js.map +1 -0
  164. package/i18n/cs.json +12 -0
  165. package/i18n/de.json +12 -0
  166. package/i18n/en.json +12 -0
  167. package/i18n/es.json +12 -0
  168. package/i18n/fr.json +12 -0
  169. package/i18n/hu.json +12 -0
  170. package/i18n/it.json +12 -0
  171. package/i18n/rm.json +12 -0
  172. package/i18n/sk.json +12 -0
  173. package/i18n/sl.json +12 -0
  174. package/package.json +87 -0
  175. package/src/Maplair.js +24 -0
  176. package/src/control/AttributionControl.js +147 -0
  177. package/src/control/Control.js +174 -0
  178. package/src/control/LayersControl.js +444 -0
  179. package/src/control/ScaleControl.js +141 -0
  180. package/src/control/ZoomControl.js +147 -0
  181. package/src/control/index.js +5 -0
  182. package/src/core/Browser.js +75 -0
  183. package/src/core/Class.js +97 -0
  184. package/src/core/Events.js +334 -0
  185. package/src/core/Handler.js +59 -0
  186. package/src/core/I18n.js +76 -0
  187. package/src/core/Util.js +122 -0
  188. package/src/core/index.js +8 -0
  189. package/src/dom/DomEvent.DoubleTap.js +120 -0
  190. package/src/dom/DomEvent.PointerEvents.js +75 -0
  191. package/src/dom/DomEvent.js +282 -0
  192. package/src/dom/DomUtil.js +175 -0
  193. package/src/dom/Draggable.js +204 -0
  194. package/src/dom/PosAnimation.js +115 -0
  195. package/src/dom/index.js +9 -0
  196. package/src/geo/LatLng.js +163 -0
  197. package/src/geo/LatLngBounds.js +260 -0
  198. package/src/geo/crs/CRS.js +143 -0
  199. package/src/geo/crs/EPSG3395.js +19 -0
  200. package/src/geo/crs/EPSG3857.js +26 -0
  201. package/src/geo/crs/EPSG4326.js +21 -0
  202. package/src/geo/crs/EarthCRS.js +32 -0
  203. package/src/geo/crs/SimpleCRS.js +35 -0
  204. package/src/geo/crs/index.js +6 -0
  205. package/src/geo/index.js +7 -0
  206. package/src/geo/projection/Projection.LonLat.js +30 -0
  207. package/src/geo/projection/Projection.Mercator.js +53 -0
  208. package/src/geo/projection/Projection.SphericalMercator.js +46 -0
  209. package/src/geo/projection/index.js +26 -0
  210. package/src/geometry/Bounds.js +222 -0
  211. package/src/geometry/LineUtil.js +299 -0
  212. package/src/geometry/Point.js +239 -0
  213. package/src/geometry/PolyUtil.js +129 -0
  214. package/src/geometry/Transformation.js +67 -0
  215. package/src/geometry/index.js +8 -0
  216. package/src/images/layers.svg +1 -0
  217. package/src/images/logo.svg +1 -0
  218. package/src/images/marker-icon.svg +1 -0
  219. package/src/images/marker-shadow.svg +1 -0
  220. package/src/layer/BlanketOverlay.js +171 -0
  221. package/src/layer/DivOverlay.js +353 -0
  222. package/src/layer/FeatureGroup.js +93 -0
  223. package/src/layer/GeoJSON.js +432 -0
  224. package/src/layer/ImageOverlay.js +279 -0
  225. package/src/layer/Layer.js +273 -0
  226. package/src/layer/LayerGroup.js +129 -0
  227. package/src/layer/Popup.js +528 -0
  228. package/src/layer/SVGOverlay.js +47 -0
  229. package/src/layer/Tooltip.js +469 -0
  230. package/src/layer/VideoOverlay.js +111 -0
  231. package/src/layer/index.js +18 -0
  232. package/src/layer/marker/DefaultIcon.js +79 -0
  233. package/src/layer/marker/DivIcon.js +76 -0
  234. package/src/layer/marker/Icon.js +164 -0
  235. package/src/layer/marker/Marker.Drag.js +161 -0
  236. package/src/layer/marker/Marker.js +465 -0
  237. package/src/layer/marker/index.js +5 -0
  238. package/src/layer/tile/GridLayer.js +901 -0
  239. package/src/layer/tile/TileLayer.js +299 -0
  240. package/src/layer/tile/WMSTileLayer.js +133 -0
  241. package/src/layer/tile/index.js +3 -0
  242. package/src/layer/vector/Canvas.js +479 -0
  243. package/src/layer/vector/Circle.js +87 -0
  244. package/src/layer/vector/CircleMarker.js +110 -0
  245. package/src/layer/vector/Path.js +145 -0
  246. package/src/layer/vector/Polygon.js +160 -0
  247. package/src/layer/vector/Polyline.js +296 -0
  248. package/src/layer/vector/Rectangle.js +52 -0
  249. package/src/layer/vector/Renderer.getRenderer.js +48 -0
  250. package/src/layer/vector/Renderer.js +75 -0
  251. package/src/layer/vector/SVG.js +216 -0
  252. package/src/layer/vector/index.js +10 -0
  253. package/src/map/Map.js +1830 -0
  254. package/src/map/handler/BoxZoomHandler.js +156 -0
  255. package/src/map/handler/DoubleClickZoomHandler.js +62 -0
  256. package/src/map/handler/DragHandler.js +240 -0
  257. package/src/map/handler/KeyboardHandler.js +188 -0
  258. package/src/map/handler/PinchZoomHandler.js +157 -0
  259. package/src/map/handler/ScrollWheelZoomHandler.js +98 -0
  260. package/src/map/handler/TapHoldHandler.js +111 -0
  261. package/src/map/index.js +8 -0
  262. package/src/maplair.css +730 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Util.js","names":[],"sources":["../../../src/core/Util.js"],"sourcesContent":["/*\n * @namespace Util\n *\n * Various utility functions, used by Maplair internally.\n */\n\n// @property lastId: Number\n// Last unique ID used by [`stamp()`](#util-stamp)\nexport let lastId = 0;\n\n// @function stamp(obj: Object): Number\n// Returns the unique ID of an object, assigning it one if it doesn't have it.\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// @function throttle(fn: Function, time: Number, context: Object): Function\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.\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// @function wrapNum(num: Number, range: Number[], includeMax?: Boolean): Number\n// Returns the number `num` modulo `range` in such a way so it lies within\n// `range[0]` and `range[1]`. The returned value will be always smaller than\n// `range[1]` unless `includeMax` is set to `true`.\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// @function falseFn(): Function\n// Returns a function which always returns `false`.\nexport function falseFn() { return false; }\n\n// @function formatNum(num: Number, precision?: Number|false): Number\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).\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// @function splitWords(str: String): String[]\n// Trims and splits the string on whitespace and returns the array of parts.\nexport function splitWords(str) {\n\treturn str.trim().split(WHITESPACE_RE);\n}\n\n// @function setOptions(obj: Object, options: Object): Object\n// Merges the given properties to the `options` of the `obj` object, returning the resulting options. See `Class options`.\nexport function setOptions(obj, options) {\n\tif (!Object.hasOwn(obj, 'options')) {\n\t\tobj.options = obj.options ? Object.create(obj.options) : {};\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 templateRe = /\\{ *([\\w_ -]+) *\\}/g;\n\n// @function template(str: String, data: Object): String\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.\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":";;;;;;;;;;;;;AAQA,IAAW,SAAS;AAIpB,SAAgB,MAAM,KAAK;CAC1B,IAAI,EAAE,iBAAiB,MACtB,IAAI,iBAAiB,EAAE;CAExB,OAAO,IAAI;AACZ;AAQA,SAAgB,SAAS,IAAI,MAAM,SAAS;CAC3C,IAAI,MAAM;CAEV,SAAS,QAAQ;EAEhB,OAAO;EACP,IAAI,YAAY;GACf,UAAU,MAAM,SAAS,UAAU;GACnC,aAAa;EACd;C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js
3
+ function makeDblclick(ev) {
4
+ let init = {
5
+ bubbles: ev.bubbles,
6
+ cancelable: ev.cancelable,
7
+ composed: ev.composed,
8
+ detail: 2,
9
+ view: ev.view,
10
+ screenX: ev.screenX,
11
+ screenY: ev.screenY,
12
+ clientX: ev.clientX,
13
+ clientY: ev.clientY,
14
+ ctrlKey: ev.ctrlKey,
15
+ shiftKey: ev.shiftKey,
16
+ altKey: ev.altKey,
17
+ metaKey: ev.metaKey,
18
+ button: ev.button,
19
+ buttons: ev.buttons,
20
+ relatedTarget: ev.relatedTarget,
21
+ region: ev.region
22
+ };
23
+ let newEvent;
24
+ if (ev instanceof PointerEvent) {
25
+ init = {
26
+ ...init,
27
+ pointerId: ev.pointerId,
28
+ width: ev.width,
29
+ height: ev.height,
30
+ pressure: ev.pressure,
31
+ tangentialPressure: ev.tangentialPressure,
32
+ tiltX: ev.tiltX,
33
+ tiltY: ev.tiltY,
34
+ twist: ev.twist,
35
+ pointerType: ev.pointerType,
36
+ isPrimary: ev.isPrimary
37
+ };
38
+ newEvent = new PointerEvent("dblclick", init);
39
+ } else newEvent = new MouseEvent("dblclick", init);
40
+ return newEvent;
41
+ }
42
+ const delay = 200;
43
+ function addDoubleTapListener(obj, handler) {
44
+ obj.addEventListener("dblclick", handler);
45
+ let last = 0, detail;
46
+ function simDblclick(ev) {
47
+ if (ev.detail !== 1) {
48
+ detail = ev.detail;
49
+ return;
50
+ }
51
+ if (ev.pointerType === "mouse" || ev.sourceCapabilities && !ev.sourceCapabilities.firesTouchEvents) return;
52
+ const path = getPropagationPath(ev);
53
+ if (path.some((el) => el instanceof HTMLLabelElement && el.attributes.for) && !path.some((el) => el instanceof HTMLInputElement || el instanceof HTMLSelectElement)) return;
54
+ const now = Date.now();
55
+ if (now - last <= delay) {
56
+ detail++;
57
+ if (detail === 2) ev.target.dispatchEvent(makeDblclick(ev));
58
+ } else detail = 1;
59
+ last = now;
60
+ }
61
+ obj.addEventListener("click", simDblclick);
62
+ return {
63
+ dblclick: handler,
64
+ simDblclick
65
+ };
66
+ }
67
+ function removeDoubleTapListener(obj, handlers) {
68
+ obj.removeEventListener("dblclick", handlers.dblclick);
69
+ obj.removeEventListener("click", handlers.simDblclick);
70
+ }
71
+ //#endregion
72
+ export { addDoubleTapListener, removeDoubleTapListener };
73
+
74
+ //# sourceMappingURL=DomEvent.DoubleTap.js.map
@@ -0,0 +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;\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\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;AACd,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;AAEA,SAAgB,wBAAwB,KAAK,UAAU;CACtD,IAAI,oBAAoB,YAAY,SAAS,QAAQ;CACrD,IAAI,oBAAoB,SAAS,SAAS,WAAW;AACtD"}
@@ -0,0 +1,46 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
+ //#region src/dom/DomEvent.PointerEvents.js
3
+ var DomEvent_PointerEvents_exports = /* @__PURE__ */ __exportAll({
4
+ cleanupPointers: () => cleanupPointers,
5
+ disablePointerDetection: () => disablePointerDetection,
6
+ enablePointerDetection: () => enablePointerDetection,
7
+ getPointers: () => getPointers
8
+ });
9
+ const activePointers = /* @__PURE__ */ new Map();
10
+ function enablePointerDetection(el) {
11
+ el.addEventListener("pointerdown", _onSet, { capture: true });
12
+ el.addEventListener("pointermove", _onUpdate, { capture: true });
13
+ el.addEventListener("pointerup", _onDelete, { capture: true });
14
+ el.addEventListener("pointercancel", _onDelete, { capture: true });
15
+ activePointers.clear();
16
+ }
17
+ function disablePointerDetection(el) {
18
+ el.removeEventListener("pointerdown", _onSet, { capture: true });
19
+ el.removeEventListener("pointermove", _onUpdate, { capture: true });
20
+ el.removeEventListener("pointerup", _onDelete, { capture: true });
21
+ el.removeEventListener("pointercancel", _onDelete, { capture: true });
22
+ }
23
+ function _onSet(e) {
24
+ e.target.setPointerCapture(e.pointerId);
25
+ activePointers.set(e.pointerId, e);
26
+ }
27
+ function _onUpdate(e) {
28
+ if (activePointers.has(e.pointerId)) activePointers.set(e.pointerId, e);
29
+ }
30
+ function _onDelete(e) {
31
+ e.target.releasePointerCapture(e.pointerId);
32
+ activePointers.delete(e.pointerId);
33
+ }
34
+ function getPointers() {
35
+ return [...activePointers.values()];
36
+ }
37
+ function cleanupPointers() {
38
+ for (const e of activePointers.values()) try {
39
+ e.target.releasePointerCapture(e.pointerId);
40
+ } catch {}
41
+ activePointers.clear();
42
+ }
43
+ //#endregion
44
+ export { DomEvent_PointerEvents_exports, cleanupPointers, disablePointerDetection, enablePointerDetection, getPointers };
45
+
46
+ //# sourceMappingURL=DomEvent.PointerEvents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DomEvent.PointerEvents.js","names":[],"sources":["../../../src/dom/DomEvent.PointerEvents.js"],"sourcesContent":["/*\n/* @namespace DomEvent\n * @section Pointer detection\n * Detects the pointers that are currently active on the document.\n */\n\nconst activePointers = new Map();\n\n// @function enablePointerDetection(el: HTMLElement)\n// Enables pointer detection and capture for the document.\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// @function disablePointerDetection(el: HTMLElement)\n// Disables pointer detection and capture for the document.\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\te.target.releasePointerCapture(e.pointerId);\n\tactivePointers.delete(e.pointerId);\n}\n\n// @function getPointers(): PointerEvent[]\n// Returns the active pointers on the document.\nfunction getPointers() {\n\treturn [...activePointers.values()];\n}\n\n// @function cleanupPointers()\n// Clears the detected pointers on the document.\n// Note: This function should be not necessary to call, as the pointers are automatically cleared with `pointerup`, `pointercancel` and `pointerout` events.\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":";;;;;;;;AAMA,MAAM,iCAAiB,IAAI,IAAI;AAI/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;AAIA,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;CACrB,EAAE,OAAO,sBAAsB,EAAE,SAAS;CAC1C,eAAe,OAAO,EAAE,SAAS;AAClC;AAIA,SAAS,cAAc;CACtB,OAAO,CAAC,GAAG,eAAe,OAAO,CAAC;AACnC;AAKA,SAAS,kBAAkB;CAC1B,KAAK,MAAM,KAAK,eAAe,OAAO,GACrC,IAAI;EACH,EAAE,OAAO,sBAAsB,EAAE,SAAS;CAC3C,QAAQ,CAER;CAED,eAAe,MAAM;AACtB"}
@@ -0,0 +1,135 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
+ import { splitWords, stamp } from "../core/Util.js";
3
+ import { Point } from "../geometry/Point.js";
4
+ import Browser_default from "../core/Browser.js";
5
+ import { addDoubleTapListener, removeDoubleTapListener } from "./DomEvent.DoubleTap.js";
6
+ import { DomEvent_PointerEvents_exports } from "./DomEvent.PointerEvents.js";
7
+ import { getScale } from "./DomUtil.js";
8
+ //#region src/dom/DomEvent.js
9
+ var DomEvent_exports = /* @__PURE__ */ __exportAll({
10
+ PointerEvents: () => DomEvent_PointerEvents_exports,
11
+ disableClickPropagation: () => disableClickPropagation,
12
+ disableScrollPropagation: () => disableScrollPropagation,
13
+ getPointerPosition: () => getPointerPosition,
14
+ getPropagationPath: () => getPropagationPath,
15
+ getWheelDelta: () => getWheelDelta,
16
+ getWheelPxFactor: () => getWheelPxFactor,
17
+ isExternalTarget: () => isExternalTarget,
18
+ off: () => off,
19
+ on: () => on,
20
+ preventDefault: () => preventDefault,
21
+ stop: () => stop,
22
+ stopPropagation: () => stopPropagation
23
+ });
24
+ function on(obj, types, fn, context) {
25
+ if (types && typeof types === "object") for (const [type, listener] of Object.entries(types)) addOne(obj, type, listener, fn);
26
+ else for (const type of splitWords(types)) addOne(obj, type, fn, context);
27
+ return this;
28
+ }
29
+ const eventsKey = "_maplair_events";
30
+ function off(obj, types, fn, context) {
31
+ if (arguments.length === 1) {
32
+ batchRemove(obj);
33
+ delete obj[eventsKey];
34
+ } else if (types && typeof types === "object") for (const [type, listener] of Object.entries(types)) removeOne(obj, type, listener, fn);
35
+ else {
36
+ types = splitWords(types);
37
+ if (arguments.length === 2) batchRemove(obj, (type) => types.includes(type));
38
+ else for (const type of types) removeOne(obj, type, fn, context);
39
+ }
40
+ return this;
41
+ }
42
+ const DIGIT_RE = /\d/;
43
+ function batchRemove(obj, filterFn) {
44
+ for (const id of Object.keys(obj[eventsKey] ?? {})) {
45
+ const type = id.split(DIGIT_RE)[0];
46
+ if (!filterFn || filterFn(type)) removeOne(obj, type, null, null, id);
47
+ }
48
+ }
49
+ const pointerSubst = {
50
+ pointerenter: "pointerover",
51
+ pointerleave: "pointerout",
52
+ wheel: typeof window === "undefined" ? false : !("onwheel" in window) && "mousewheel"
53
+ };
54
+ function addOne(obj, type, fn, context) {
55
+ const id = type + stamp(fn) + (context ? `_${stamp(context)}` : "");
56
+ if (obj[eventsKey] && obj[eventsKey][id]) return this;
57
+ let handler = function(e) {
58
+ return fn.call(context || obj, e);
59
+ };
60
+ const originalHandler = handler;
61
+ if (Browser_default.touch && type === "dblclick") handler = addDoubleTapListener(obj, handler);
62
+ else if ("addEventListener" in obj) {
63
+ if (type === "wheel" || type === "mousewheel") obj.addEventListener(pointerSubst[type] || type, handler, { passive: false });
64
+ else if (type === "pointerenter" || type === "pointerleave") {
65
+ handler = function(e) {
66
+ if (isExternalTarget(obj, e)) originalHandler(e);
67
+ };
68
+ obj.addEventListener(pointerSubst[type], handler, false);
69
+ } else obj.addEventListener(type, originalHandler, false);
70
+ } else obj.attachEvent(`on${type}`, handler);
71
+ obj[eventsKey] ??= {};
72
+ obj[eventsKey][id] = handler;
73
+ }
74
+ function removeOne(obj, type, fn, context, id) {
75
+ id ??= type + stamp(fn) + (context ? `_${stamp(context)}` : "");
76
+ const handler = obj[eventsKey] && obj[eventsKey][id];
77
+ if (!handler) return this;
78
+ if (Browser_default.touch && type === "dblclick") removeDoubleTapListener(obj, handler);
79
+ else if ("removeEventListener" in obj) obj.removeEventListener(pointerSubst[type] || type, handler, false);
80
+ else obj.detachEvent(`on${type}`, handler);
81
+ obj[eventsKey][id] = null;
82
+ }
83
+ function stopPropagation(e) {
84
+ if (e.stopPropagation) e.stopPropagation();
85
+ else if (e.originalEvent) e.originalEvent._stopped = true;
86
+ else console.debug("Unsupported event", e);
87
+ return this;
88
+ }
89
+ function disableScrollPropagation(el) {
90
+ addOne(el, "wheel", stopPropagation);
91
+ return this;
92
+ }
93
+ function disableClickPropagation(el) {
94
+ on(el, "pointerdown dblclick contextmenu", stopPropagation);
95
+ el["_maplair_disable_click"] = true;
96
+ return this;
97
+ }
98
+ function preventDefault(e) {
99
+ e.preventDefault?.();
100
+ return this;
101
+ }
102
+ function stop(e) {
103
+ preventDefault(e);
104
+ stopPropagation(e);
105
+ return this;
106
+ }
107
+ function getPropagationPath(ev) {
108
+ return ev.composedPath();
109
+ }
110
+ function getPointerPosition(e, container) {
111
+ if (!container) return new Point(e.clientX, e.clientY);
112
+ const scale = getScale(container), offset = scale.boundingClientRect;
113
+ return new Point((e.clientX - offset.left) / scale.x - container.clientLeft, (e.clientY - offset.top) / scale.y - container.clientTop);
114
+ }
115
+ function getWheelPxFactor() {
116
+ const ratio = window.devicePixelRatio;
117
+ return Browser_default.linux && Browser_default.chrome ? ratio : Browser_default.mac ? ratio * 3 : ratio > 0 ? 2 * ratio : 1;
118
+ }
119
+ function getWheelDelta(e) {
120
+ 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;
121
+ }
122
+ function isExternalTarget(el, e) {
123
+ let related = e.relatedTarget;
124
+ if (!related) return true;
125
+ try {
126
+ while (related && related !== el) related = related.parentNode;
127
+ } catch (err) {
128
+ return false;
129
+ }
130
+ return related !== el;
131
+ }
132
+ //#endregion
133
+ export { DomEvent_exports, DomEvent_PointerEvents_exports as PointerEvents, disableClickPropagation, disableScrollPropagation, getPointerPosition, getPropagationPath, getWheelDelta, getWheelPxFactor, isExternalTarget, off, on, preventDefault, stop, stopPropagation };
134
+
135
+ //# sourceMappingURL=DomEvent.js.map
@@ -0,0 +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/*\n * @namespace DomEvent\n * Utility functions to work with the [DOM events](https://developer.mozilla.org/docs/Web/API/Event), used by Maplair internally.\n */\n\n// Inspired by John Resig, Dean Edwards and YUI addEvent implementations.\n\n// @function on(el: HTMLElement, types: String, fn: Function, context?: Object): this\n// Adds a listener function (`fn`) to a particular DOM event type of the\n// element `el`. 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'`).\n\n// @alternative\n// @function on(el: HTMLElement, eventMap: Object, context?: Object): this\n// Adds a set of type/listener pairs, e.g. `{click: onClick, pointermove: onPointerMove}`\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// @function off(el: HTMLElement, types: String, fn: Function, context?: Object): this\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.\n\n// @alternative\n// @function off(el: HTMLElement, eventMap: Object, context?: Object): this\n// Removes a set of type/listener pairs, e.g. `{click: onClick, pointermove: onPointerMove}`\n\n// @alternative\n// @function off(el: HTMLElement, types: String): this\n// Removes all previously added listeners of given types.\n\n// @alternative\n// @function off(el: HTMLElement): this\n// Removes all previously added listeners from given HTMLElement\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// @function stopPropagation(ev: DOMEvent): this\n// Stop the given event from propagation to parent elements. Used inside the listener functions:\n// ```js\n// DomEvent.on(div, 'click', DomEvent.stopPropagation);\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// @function disableScrollPropagation(el: HTMLElement): this\n// Adds `stopPropagation` to the element's `'wheel'` events (plus browser variants).\nexport function disableScrollPropagation(el) {\n\taddOne(el, 'wheel', stopPropagation);\n\treturn this;\n}\n\n// @function disableClickPropagation(el: HTMLElement): this\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.\nexport function disableClickPropagation(el) {\n\ton(el, 'pointerdown dblclick contextmenu', stopPropagation);\n\tel['_maplair_disable_click'] = true;\n\treturn this;\n}\n\n// @function preventDefault(ev: DOMEvent): this\n// Prevents the default action of the DOM Event `ev` 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.\nexport function preventDefault(e) {\n\te.preventDefault?.();\n\treturn this;\n}\n\n// @function stop(ev: DOMEvent): this\n// Does `stopPropagation` and `preventDefault` at the same time.\nexport function stop(e) {\n\tpreventDefault(e);\n\tstopPropagation(e);\n\treturn this;\n}\n\n// @function getPropagationPath(ev: DOMEvent): Array\n// Returns an array containing the `HTMLElement`s that the given DOM event\n// should propagate to (if not stopped).\nexport function getPropagationPath(ev) {\n\treturn ev.composedPath();\n}\n\n\n// @function getPointerPosition(ev: DOMEvent, container?: HTMLElement): Point\n// Gets normalized pointer position from a DOM event relative to the\n// `container` (border excluded) or to the whole page if not specified.\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// @function getWheelPxFactor(): Number\n// Gets the wheel pixel factor based on the devicePixelRatio\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// @function getWheelDelta(ev: DOMEvent): Number\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.\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// check if element really left/entered the event target (for pointerenter/pointerleave)\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":";;;;;;;;;;;;;;;;;;;;;;;AAyBA,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;CAI/B,OAAO;AACR;AAEA,MAAM,YAAY;AAkBlB,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,WA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UAAU,OAAO,OAAO,MAAM,IAAI,UAAU,SAChD;AACD;AAIA,SAAgB,mBAAmB;CAGlC,MAAM,QAAQ,OAAO;CACrB,OAAOA,gBAAQ,SAASA,gBAAQ,SAAS,QACxCA,gBAAQ,MAAM,QAAQ,IACtB,QAAQ,IAAI,IAAI,QAAQ;AAC1B;AAOA,SAAgB,cAAc,GAAG;CAChC,OAAQ,EAAE,UAAU,EAAE,cAAc,IAAK,CAAC,EAAE,SAAS,iBAAiB,IACpE,EAAE,UAAU,EAAE,cAAc,IAAK,CAAC,EAAE,SAAS,KAC7C,EAAE,UAAU,EAAE,cAAc,IAAK,CAAC,EAAE,SAAS,KAC7C,EAAE,UAAU,EAAE,SAAU,IACzB;AACF;AAGA,SAAgB,iBAAiB,IAAI,GAAG;CAEvC,IAAI,UAAU,EAAE;CAEhB,IAAI,CAAC,SAAW,OAAO;CAEvB,IAAI;EACH,OAAO,WAAY,YAAY,IAC9B,UAAU,QAAQ;CAEpB,SAAS,KAAK;EACb,OAAO;CACR;CACA,OAAQ,YAAY;AACrB"}
@@ -0,0 +1,107 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
+ import { Point } from "../geometry/Point.js";
3
+ import { off, on, preventDefault } from "./DomEvent.js";
4
+ //#region src/dom/DomUtil.js
5
+ var DomUtil_exports = /* @__PURE__ */ __exportAll({
6
+ create: () => create,
7
+ disableImageDrag: () => disableImageDrag,
8
+ disableTextSelection: () => disableTextSelection,
9
+ enableImageDrag: () => enableImageDrag,
10
+ enableTextSelection: () => enableTextSelection,
11
+ get: () => get,
12
+ getPosition: () => getPosition,
13
+ getScale: () => getScale,
14
+ getSizedParentNode: () => getSizedParentNode,
15
+ preventOutline: () => preventOutline,
16
+ restoreOutline: () => restoreOutline,
17
+ setPosition: () => setPosition,
18
+ setTransform: () => setTransform,
19
+ toBack: () => toBack,
20
+ toFront: () => toFront
21
+ });
22
+ function get(id) {
23
+ return typeof id === "string" ? document.getElementById(id) : id;
24
+ }
25
+ function create(tagName, className, container) {
26
+ const el = document.createElement(tagName);
27
+ el.className = className ?? "";
28
+ container?.appendChild(el);
29
+ return el;
30
+ }
31
+ function toFront(el) {
32
+ const parent = el.parentNode;
33
+ if (parent && parent.lastChild !== el) parent.appendChild(el);
34
+ }
35
+ function toBack(el) {
36
+ const parent = el.parentNode;
37
+ if (parent && parent.firstChild !== el) parent.insertBefore(el, parent.firstChild);
38
+ }
39
+ function setTransform(el, offset, scale) {
40
+ const pos = offset ?? new Point(0, 0);
41
+ const transform = `translate3d(${pos.x}px, ${pos.y}px, 0px)${scale ? ` scale(${scale})` : ""}`;
42
+ if (el.style.transform !== transform) el.style.transform = transform;
43
+ }
44
+ const positions = /* @__PURE__ */ new WeakMap();
45
+ function setPosition(el, point) {
46
+ positions.set(el, point);
47
+ setTransform(el, point);
48
+ }
49
+ function getPosition(el) {
50
+ return positions.get(el) ?? new Point(0, 0);
51
+ }
52
+ const documentStyle = typeof document === "undefined" ? {} : document.documentElement.style;
53
+ const userSelectProp = ["userSelect", "WebkitUserSelect"].find((prop) => prop in documentStyle);
54
+ let prevUserSelect;
55
+ function disableTextSelection() {
56
+ const value = documentStyle[userSelectProp];
57
+ if (value === "none") return;
58
+ prevUserSelect = value;
59
+ documentStyle[userSelectProp] = "none";
60
+ }
61
+ function enableTextSelection() {
62
+ if (typeof prevUserSelect === "undefined") return;
63
+ documentStyle[userSelectProp] = prevUserSelect;
64
+ prevUserSelect = void 0;
65
+ }
66
+ function disableImageDrag() {
67
+ on(window, "dragstart", preventDefault);
68
+ }
69
+ function enableImageDrag() {
70
+ off(window, "dragstart", preventDefault);
71
+ }
72
+ let _outlineElement;
73
+ let _outlineStyle;
74
+ function preventOutline(element) {
75
+ while (element.tabIndex === -1) element = element.parentNode;
76
+ if (!element.style) return;
77
+ restoreOutline();
78
+ _outlineElement = element;
79
+ _outlineStyle = element.style.outlineStyle;
80
+ element.style.outlineStyle = "none";
81
+ on(window, "keydown", restoreOutline);
82
+ }
83
+ function restoreOutline() {
84
+ if (!_outlineElement) return;
85
+ _outlineElement.style.outlineStyle = _outlineStyle;
86
+ _outlineElement = void 0;
87
+ _outlineStyle = void 0;
88
+ off(window, "keydown", restoreOutline);
89
+ }
90
+ function getSizedParentNode(element) {
91
+ do
92
+ element = element.parentNode;
93
+ while ((!element.offsetWidth || !element.offsetHeight) && element !== document.body);
94
+ return element;
95
+ }
96
+ function getScale(element) {
97
+ const rect = element.getBoundingClientRect();
98
+ return {
99
+ x: rect.width / element.offsetWidth || 1,
100
+ y: rect.height / element.offsetHeight || 1,
101
+ boundingClientRect: rect
102
+ };
103
+ }
104
+ //#endregion
105
+ export { DomUtil_exports, create, disableImageDrag, disableTextSelection, enableImageDrag, enableTextSelection, get, getPosition, getScale, getSizedParentNode, preventOutline, restoreOutline, setPosition, setTransform, toBack, toFront };
106
+
107
+ //# sourceMappingURL=DomUtil.js.map
@@ -0,0 +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/*\n * @namespace DomUtil\n *\n * Utility functions to work with the [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// @function get(id: String|HTMLElement): HTMLElement\n// Returns an element given its DOM id, or returns the element itself\n// if it was passed directly.\nexport function get(id) {\n\treturn typeof id === 'string' ? document.getElementById(id) : id;\n}\n\n// @function create(tagName: String, className?: String, container?: HTMLElement): HTMLElement\n// Creates an HTML element with `tagName`, sets its class to `className`, and optionally appends it to `container` element.\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// @function toFront(el: HTMLElement)\n// Makes `el` the last child of its parent, so it renders in front of the other children.\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// @function toBack(el: HTMLElement)\n// Makes `el` the first child of its parent, so it renders behind the other children.\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// @function setTransform(el: HTMLElement, offset: Point, scale?: Number)\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.\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// @function setPosition(el: HTMLElement, position: Point)\n// Sets the position of `el` to coordinates specified by `position`,\n// using CSS translate or top/left positioning depending on the browser\n// (used by Maplair internally to position its layers).\nexport function setPosition(el, point) {\n\tpositions.set(el, point);\n\tsetTransform(el, point);\n}\n\n// @function getPosition(el: HTMLElement): Point\n// Returns the coordinates of an element previously positioned with setPosition.\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// @function disableTextSelection()\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.\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// @function enableTextSelection()\n// Cancels the effects of a previous [`DomUtil.disableTextSelection`](#domutil-disabletextselection).\nexport function enableTextSelection() {\n\tif (typeof prevUserSelect === 'undefined') {\n\t\treturn;\n\t}\n\n\tdocumentStyle[userSelectProp] = prevUserSelect;\n\tprevUserSelect = undefined;\n}\n\n// @function disableImageDrag()\n// Prevents the user from generating `dragstart` DOM events, usually generated when the user drags an image.\nexport function disableImageDrag() {\n\tDomEvent.on(window, 'dragstart', DomEvent.preventDefault);\n}\n\n// @function enableImageDrag()\n// Cancels the effects of a previous [`DomUtil.disableImageDrag`](#domutil-disableimagedrag).\nexport function enableImageDrag() {\n\tDomEvent.off(window, 'dragstart', DomEvent.preventDefault);\n}\n\nlet _outlineElement, _outlineStyle;\n// @function preventOutline(el: HTMLElement)\n// Makes the [outline](https://developer.mozilla.org/docs/Web/CSS/outline)\n// of the element `el` invisible. Used internally by Maplair to prevent\n// focusable elements from displaying an outline when the user performs a\n// drag interaction on them.\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// @function restoreOutline()\n// Cancels the effects of a previous [`DomUtil.preventOutline`](#domutil-preventoutline).\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// @function getSizedParentNode(el: HTMLElement): HTMLElement\n// Finds the closest parent node which size (width and height) is not null.\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// @function getScale(el: HTMLElement): Object\n// Computes the CSS scale currently applied on the element.\n// Returns an object with `x` and `y` members as horizontal and vertical scales respectively,\n// and `boundingClientRect` as the result of [`getBoundingClientRect()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect).\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;AAIA,SAAgB,OAAO,SAAS,WAAW,WAAW;CACrD,MAAM,KAAK,SAAS,cAAc,OAAO;CACzC,GAAG,YAAY,aAAa;CAE5B,WAAW,YAAY,EAAE;CACzB,OAAO;AACR;AAIA,SAAgB,QAAQ,IAAI;CAC3B,MAAM,SAAS,GAAG;CAClB,IAAI,UAAU,OAAO,cAAc,IAClC,OAAO,YAAY,EAAE;AAEvB;AAIA,SAAgB,OAAO,IAAI;CAC1B,MAAM,SAAS,GAAG;CAClB,IAAI,UAAU,OAAO,eAAe,IACnC,OAAO,aAAa,IAAI,OAAO,UAAU;AAE3C;AAMA,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;AAM9B,SAAgB,YAAY,IAAI,OAAO;CACtC,UAAU,IAAI,IAAI,KAAK;CACvB,aAAa,IAAI,KAAK;AACvB;AAIA,SAAgB,YAAY,I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AS,QAAQ,gBAAgB;EACzC,oBAAoB;CACrB;AACD"}
@@ -0,0 +1,107 @@
1
+ import { setOptions } from "../core/Util.js";
2
+ import { Point } from "../geometry/Point.js";
3
+ import { getPointers } from "./DomEvent.PointerEvents.js";
4
+ import { off, on } from "./DomEvent.js";
5
+ import { disableImageDrag, disableTextSelection, enableImageDrag, enableTextSelection, getPosition, getScale, getSizedParentNode, preventOutline, setPosition } from "./DomUtil.js";
6
+ import { Evented } from "../core/Events.js";
7
+ //#region src/dom/Draggable.js
8
+ var Draggable = class Draggable extends Evented {
9
+ static {
10
+ this.setDefaultOptions({ clickTolerance: 3 });
11
+ }
12
+ constructor(element, dragStartTarget, preventOutline, options) {
13
+ super();
14
+ setOptions(this, options);
15
+ this._element = element;
16
+ this._dragStartTarget = dragStartTarget ?? element;
17
+ this._preventOutline = preventOutline;
18
+ this.callInitHooks(Draggable);
19
+ }
20
+ enable() {
21
+ if (this._enabled) return;
22
+ on(this._dragStartTarget, "pointerdown", this._onDown, this);
23
+ this._enabled = true;
24
+ }
25
+ disable() {
26
+ if (!this._enabled) return;
27
+ if (Draggable._dragging === this) this.finishDrag(true);
28
+ off(this._dragStartTarget, "pointerdown", this._onDown, this);
29
+ this._enabled = false;
30
+ this._moved = false;
31
+ }
32
+ _onDown(e) {
33
+ this._moved = false;
34
+ if (this._element.classList.contains("maplair-zoom-anim")) return;
35
+ if (getPointers().length !== 1) {
36
+ if (Draggable._dragging === this) this.finishDrag();
37
+ return;
38
+ }
39
+ if (Draggable._dragging || e.shiftKey || e.button !== 0 && e.pointerType !== "touch") return;
40
+ Draggable._dragging = this;
41
+ if (this._preventOutline) preventOutline(this._element);
42
+ disableImageDrag();
43
+ disableTextSelection();
44
+ if (this._moving) return;
45
+ this.fire("down");
46
+ const sizedParent = getSizedParentNode(this._element);
47
+ this._startPoint = new Point(e.clientX, e.clientY);
48
+ this._startPos = getPosition(this._element);
49
+ this._parentScale = getScale(sizedParent);
50
+ on(this._dragStartTarget, "pointermove", this._onMove, this);
51
+ on(this._dragStartTarget, "pointerup pointercancel", this._onUp, this);
52
+ }
53
+ _onMove(e) {
54
+ if (getPointers().length > 1) {
55
+ this._moved = true;
56
+ return;
57
+ }
58
+ const offset = new Point(e.clientX, e.clientY)._subtract(this._startPoint);
59
+ if (!offset.x && !offset.y) return;
60
+ if (Math.abs(offset.x) + Math.abs(offset.y) < this.options.clickTolerance) return;
61
+ offset.x /= this._parentScale.x;
62
+ offset.y /= this._parentScale.y;
63
+ if (e.cancelable) e.preventDefault();
64
+ if (!this._moved) {
65
+ this.fire("dragstart");
66
+ this._moved = true;
67
+ this._element.ownerDocument.body.classList.add("maplair-dragging");
68
+ this._lastTarget = e.target ?? e.srcElement;
69
+ this._lastTarget.classList.add("maplair-drag-target");
70
+ }
71
+ this._newPos = this._startPos.add(offset);
72
+ this._moving = true;
73
+ this._lastEvent = e;
74
+ this._updatePosition();
75
+ }
76
+ _updatePosition() {
77
+ const e = { originalEvent: this._lastEvent };
78
+ this.fire("predrag", e);
79
+ setPosition(this._element, this._newPos);
80
+ this.fire("drag", e);
81
+ }
82
+ _onUp() {
83
+ this.finishDrag();
84
+ }
85
+ finishDrag(noInertia) {
86
+ this._element.ownerDocument.body.classList.remove("maplair-dragging");
87
+ if (this._lastTarget) {
88
+ this._lastTarget.classList.remove("maplair-drag-target");
89
+ this._lastTarget = null;
90
+ }
91
+ off(this._dragStartTarget, "pointermove", this._onMove, this);
92
+ off(this._dragStartTarget, "pointerup pointercancel", this._onUp, this);
93
+ enableImageDrag();
94
+ enableTextSelection();
95
+ const fireDragend = this._moved && this._moving;
96
+ this._moving = false;
97
+ Draggable._dragging = false;
98
+ if (fireDragend) this.fire("dragend", {
99
+ noInertia,
100
+ distance: this._newPos.distanceTo(this._startPos)
101
+ });
102
+ }
103
+ };
104
+ //#endregion
105
+ export { Draggable };
106
+
107
+ //# sourceMappingURL=Draggable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Draggable.js","names":["PointerEvents.getPointers","DomUtil.getSizedParentNode","DomUtil.getPosition","DomUtil.getScale"],"sources":["../../../src/dom/Draggable.js"],"sourcesContent":["import {Evented} from '../core/Events.js';\nimport * as DomEvent from './DomEvent.js';\nimport * as DomUtil from './DomUtil.js';\nimport * as Util from '../core/Util.js';\nimport {Point} from '../geometry/Point.js';\nimport * as PointerEvents from './DomEvent.PointerEvents.js';\n\n/*\n * @class Draggable\n * @inherits Evented\n *\n * A class for making DOM elements draggable.\n * Used internally for map and marker dragging. Works on any DOM element\n *\n * @example\n * ```js\n * const draggable = new Draggable(elementToDrag);\n * draggable.enable();\n * ```\n */\n\nexport class Draggable extends Evented {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\t// @section\n\t\t\t// @aka Draggable options\n\t\t\t// @option clickTolerance: Number = 3\n\t\t\t// The max number of pixels a user can shift the pointer during a click\n\t\t\t// for it to be considered a valid click (as opposed to a pointer drag).\n\t\t\tclickTolerance: 3\n\t\t});\n\t}\n\n\t// @constructor Draggable(el: HTMLElement, dragHandle?: HTMLElement, preventOutline?: Boolean, options?: Draggable options)\n\t// Creates a `Draggable` object for moving `el` when you start dragging the `dragHandle` element (equals `el` itself by default).\n\tconstructor(element, dragStartTarget, preventOutline, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\n\t\tthis._element = element;\n\t\tthis._dragStartTarget = dragStartTarget ?? element;\n\t\tthis._preventOutline = preventOutline;\n\n\t\tthis.callInitHooks(Draggable);\n\t}\n\n\t// @method enable()\n\t// Enables the dragging ability\n\tenable() {\n\t\tif (this._enabled) { return; }\n\n\t\tDomEvent.on(this._dragStartTarget, 'pointerdown', this._onDown, this);\n\n\t\tthis._enabled = true;\n\t}\n\n\t// @method disable()\n\t// Disables the dragging ability\n\tdisable() {\n\t\tif (!this._enabled) { return; }\n\n\t\t// If we're currently dragging this draggable,\n\t\t// disabling it counts as first ending the drag.\n\t\tif (Draggable._dragging === this) {\n\t\t\tthis.finishDrag(true);\n\t\t}\n\n\t\tDomEvent.off(this._dragStartTarget, 'pointerdown', this._onDown, this);\n\n\t\tthis._enabled = false;\n\t\tthis._moved = false;\n\t}\n\n\t_onDown(e) {\n\t\tthis._moved = false;\n\n\t\tif (this._element.classList.contains('maplair-zoom-anim')) { return; }\n\n\t\tif (PointerEvents.getPointers().length !== 1) {\n\t\t\t// Finish dragging to avoid conflict with touchZoom\n\t\t\tif (Draggable._dragging === this) {\n\t\t\t\tthis.finishDrag();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (Draggable._dragging || e.shiftKey || (e.button !== 0 && e.pointerType !== 'touch')) { return; }\n\t\tDraggable._dragging = this; // Prevent dragging multiple objects at once.\n\n\t\tif (this._preventOutline) {\n\t\t\tDomUtil.preventOutline(this._element);\n\t\t}\n\n\t\tDomUtil.disableImageDrag();\n\t\tDomUtil.disableTextSelection();\n\n\t\tif (this._moving) { return; }\n\n\t\t// @event down: Event\n\t\t// Fired when a drag is about to start.\n\t\tthis.fire('down');\n\n\t\tconst sizedParent = DomUtil.getSizedParentNode(this._element);\n\n\t\tthis._startPoint = new Point(e.clientX, e.clientY);\n\t\tthis._startPos = DomUtil.getPosition(this._element);\n\n\t\t// Cache the scale, so that we can continuously compensate for it during drag (_onMove).\n\t\tthis._parentScale = DomUtil.getScale(sizedParent);\n\n\t\tDomEvent.on(this._dragStartTarget, 'pointermove', this._onMove, this);\n\t\tDomEvent.on(this._dragStartTarget, 'pointerup pointercancel', this._onUp, this);\n\t}\n\n\t_onMove(e) {\n\t\tif (PointerEvents.getPointers().length > 1) {\n\t\t\tthis._moved = true;\n\t\t\treturn;\n\t\t}\n\n\t\tconst offset = new Point(e.clientX, e.clientY)._subtract(this._startPoint);\n\n\t\tif (!offset.x && !offset.y) { return; }\n\t\tif (Math.abs(offset.x) + Math.abs(offset.y) < this.options.clickTolerance) { return; }\n\n\t\t// We assume that the parent container's position, border and scale do not change for the duration of the drag.\n\t\t// Therefore there is no need to account for the position and border (they are eliminated by the subtraction)\n\t\t// and we can use the cached value for the scale.\n\t\toffset.x /= this._parentScale.x;\n\t\toffset.y /= this._parentScale.y;\n\n\t\tif (e.cancelable) {\n\t\t\te.preventDefault();\n\t\t}\n\n\t\tif (!this._moved) {\n\t\t\t// @event dragstart: Event\n\t\t\t// Fired when a drag starts\n\t\t\tthis.fire('dragstart');\n\n\t\t\tthis._moved = true;\n\n\t\t\tthis._element.ownerDocument.body.classList.add('maplair-dragging');\n\n\t\t\tthis._lastTarget = e.target ?? e.srcElement;\n\t\t\tthis._lastTarget.classList.add('maplair-drag-target');\n\t\t}\n\n\t\tthis._newPos = this._startPos.add(offset);\n\t\tthis._moving = true;\n\n\t\tthis._lastEvent = e;\n\t\tthis._updatePosition();\n\t}\n\n\t_updatePosition() {\n\t\tconst e = {originalEvent: this._lastEvent};\n\n\t\t// @event predrag: Event\n\t\t// Fired continuously during dragging *before* each corresponding\n\t\t// update of the element's position.\n\t\tthis.fire('predrag', e);\n\t\tDomUtil.setPosition(this._element, this._newPos);\n\n\t\t// @event drag: Event\n\t\t// Fired continuously during dragging.\n\t\tthis.fire('drag', e);\n\t}\n\n\t_onUp() {\n\t\tthis.finishDrag();\n\t}\n\n\tfinishDrag(noInertia) {\n\t\tthis._element.ownerDocument.body.classList.remove('maplair-dragging');\n\n\t\tif (this._lastTarget) {\n\t\t\tthis._lastTarget.classList.remove('maplair-drag-target');\n\t\t\tthis._lastTarget = null;\n\t\t}\n\n\t\tDomEvent.off(this._dragStartTarget, 'pointermove', this._onMove, this);\n\t\tDomEvent.off(this._dragStartTarget, 'pointerup pointercancel', this._onUp, this);\n\n\t\tDomUtil.enableImageDrag();\n\t\tDomUtil.enableTextSelection();\n\n\t\tconst fireDragend = this._moved && this._moving;\n\n\t\tthis._moving = false;\n\t\tDraggable._dragging = false;\n\n\t\tif (fireDragend) {\n\t\t\t// @event dragend: DragEndEvent\n\t\t\t// Fired when the drag ends.\n\t\t\tthis.fire('dragend', {\n\t\t\t\tnoInertia,\n\t\t\t\td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AK,SAAS,IAAI;EACrE,IAAa,KAAK,kBAAkB,2BAA2B,KAAK,OAAO,IAAI;EAE/E,gBAAwB;EACxB,oBAA4B;EAE5B,MAAM,cAAc,KAAK,UAAU,KAAK;EAExC,KAAK,UAAU;EACf,UAAU,YAAY;EAEtB,IAAI,aAGH,KAAK,KAAK,WAAW;GACpB;GACA,UAAU,KAAK,QAAQ,WAAW,KAAK,SAAS;EACjD,CAAC;CAEH;AAED"}
@@ -0,0 +1,56 @@
1
+ import { getPosition, setPosition } from "./DomUtil.js";
2
+ import { Evented } from "../core/Events.js";
3
+ //#region src/dom/PosAnimation.js
4
+ var PosAnimation = class PosAnimation extends Evented {
5
+ constructor(...args) {
6
+ super(...args);
7
+ this.callInitHooks(PosAnimation);
8
+ }
9
+ run(el, newPos, duration, easeLinearity) {
10
+ this.stop();
11
+ this._el = el;
12
+ this._inProgress = true;
13
+ this._duration = duration ?? .25;
14
+ this._easeOutPower = 1 / Math.max(easeLinearity ?? .5, .2);
15
+ this._startPos = getPosition(el);
16
+ this._offset = newPos.subtract(this._startPos);
17
+ this._startTime = Date.now();
18
+ this.fire("start");
19
+ this._animate();
20
+ }
21
+ stop() {
22
+ if (!this._inProgress) return;
23
+ this._step(true);
24
+ this._complete();
25
+ }
26
+ _animate() {
27
+ this._animId = requestAnimationFrame(this._animate.bind(this));
28
+ this._step();
29
+ }
30
+ _step(round) {
31
+ const elapsed = Date.now() - this._startTime, duration = this._duration * 1e3;
32
+ if (elapsed < duration) this._runFrame(this._easeOut(elapsed / duration), round);
33
+ else {
34
+ this._runFrame(1);
35
+ this._complete();
36
+ }
37
+ }
38
+ _runFrame(progress, round) {
39
+ const pos = this._startPos.add(this._offset.multiplyBy(progress));
40
+ if (round) pos._round();
41
+ setPosition(this._el, pos);
42
+ this.fire("step");
43
+ }
44
+ _complete() {
45
+ cancelAnimationFrame(this._animId);
46
+ this._inProgress = false;
47
+ this.fire("end");
48
+ }
49
+ _easeOut(t) {
50
+ return 1 - (1 - t) ** this._easeOutPower;
51
+ }
52
+ };
53
+ //#endregion
54
+ export { PosAnimation };
55
+
56
+ //# sourceMappingURL=PosAnimation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PosAnimation.js","names":["DomUtil.getPosition"],"sources":["../../../src/dom/PosAnimation.js"],"sourcesContent":["import {Evented} from '../core/Events.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n\n\n/*\n * @class PosAnimation\n * @inherits Evented\n * Used internally for panning animations and utilizing CSS Transitions for modern browsers.\n *\n * @example\n * ```js\n * const myPositionMarker = new Marker([48.864716, 2.294694]).addTo(map);\n *\n * myPositionMarker.on(\"click\", function() {\n * \tconst pos = map.latLngToLayerPoint(myPositionMarker.getLatLng());\n * \tpos.y -= 25;\n * \tconst fx = new PosAnimation();\n *\n * \tfx.once('end',function() {\n * \t\tpos.y += 25;\n * \t\tfx.run(myPositionMarker._icon, pos, 0.8);\n * \t});\n *\n * \tfx.run(myPositionMarker._icon, pos, 0.3);\n * });\n *\n * ```\n *\n * @constructor PosAnimation()\n * Creates a `PosAnimation` object.\n *\n */\n\nexport class PosAnimation extends Evented {\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(PosAnimation);\n\t}\n\n\t// @method run(el: HTMLElement, newPos: Point, duration?: Number, easeLinearity?: Number)\n\t// Run an animation of a given element to a new position, optionally setting\n\t// duration in seconds (`0.25` by default) and easing linearity factor (3rd\n\t// argument of the [cubic bezier curve](https://cubic-bezier.com/#0,0,.5,1),\n\t// `0.5` by default).\n\trun(el, newPos, duration, easeLinearity) {\n\t\tthis.stop();\n\n\t\tthis._el = el;\n\t\tthis._inProgress = true;\n\t\tthis._duration = duration ?? 0.25;\n\t\tthis._easeOutPower = 1 / Math.max(easeLinearity ?? 0.5, 0.2);\n\n\t\tthis._startPos = DomUtil.getPosition(el);\n\t\tthis._offset = newPos.subtract(this._startPos);\n\t\tthis._startTime = Date.now();\n\n\t\t// @event start: Event\n\t\t// Fired when the animation starts\n\t\tthis.fire('start');\n\n\t\tthis._animate();\n\t}\n\n\t// @method stop()\n\t// Stops the animation (if currently running).\n\tstop() {\n\t\tif (!this._inProgress) { return; }\n\n\t\tthis._step(true);\n\t\tthis._complete();\n\t}\n\n\t_animate() {\n\t\t// animation loop\n\t\tthis._animId = requestAnimationFrame(this._animate.bind(this));\n\t\tthis._step();\n\t}\n\n\t_step(round) {\n\t\tconst elapsed = (Date.now()) - this._startTime,\n\t\tduration = this._duration * 1000;\n\n\t\tif (elapsed < duration) {\n\t\t\tthis._runFrame(this._easeOut(elapsed / duration), round);\n\t\t} else {\n\t\t\tthis._runFrame(1);\n\t\t\tthis._complete();\n\t\t}\n\t}\n\n\t_runFrame(progress, round) {\n\t\tconst pos = this._startPos.add(this._offset.multiplyBy(progress));\n\t\tif (round) {\n\t\t\tpos._round();\n\t\t}\n\t\tDomUtil.setPosition(this._el, pos);\n\n\t\t// @event step: Event\n\t\t// Fired continuously during the animation.\n\t\tthis.fire('step');\n\t}\n\n\t_complete() {\n\t\tcancelAnimationFrame(this._animId);\n\n\t\tthis._inProgress = false;\n\t\t// @event end: Event\n\t\t// Fired when the animation ends.\n\t\tthis.fire('end');\n\t}\n\n\t_easeOut(t) {\n\t\treturn 1 - (1 - t) ** this._easeOutPower;\n\t}\n}\n"],"mappings":";;;AAiCA,IAAa,eAAb,MAAa,qBAAqB,QAAQ;CACzC,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,YAAY;CAChC;CAOA,IAAI,IAAI,QAAQ,UAAU,eAAe;EACxC,KAAK,KAAK;EAEV,KAAK,MAAM;EACX,KAAK,cAAc;EACnB,KAAK,YAAY,YAAY;EAC7B,KAAK,gBAAgB,IAAI,KAAK,IAAI,iBAAiB,IAAK,EAAG;EAE3D,KAAK,YAAYA,YAAoB,EAAE;EACvC,KAAK,UAAU,OAAO,SAAS,KAAK,SAAS;EAC7C,KAAK,aAAa,KAAK,IAAI;EAI3B,KAAK,KAAK,O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