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,5 +1,5 @@
1
1
  import { setOptions } from "./Util.js";
2
- //#region src/core/Class.js
2
+ // src/core/Class.js
3
3
  /**
4
4
  * Class powers the OOP facilities of Maplair and is used to create almost all of the
5
5
  * Maplair classes documented here.
@@ -10,28 +10,24 @@ import { setOptions } from "./Util.js";
10
10
  *
11
11
  * <h3 id="class-options">Options</h3>
12
12
  *
13
- * `options` is a special property that will be merged with the parent class options
14
- * instead of overriding them completely, which makes managing configuration of objects
15
- * and default values convenient. Use `setDefaultOptions()` in a static block to
16
- * configure options:
13
+ * `options` is a special property whose defaults, the static `defaultOptions` of the
14
+ * class, are merged with those of the parent class instead of overriding them
15
+ * completely, which makes managing configuration of objects and default values
16
+ * convenient:
17
17
  *
18
18
  * ```js
19
19
  * class MyClass extends Class {
20
- * static {
21
- * this.setDefaultOptions({
22
- * myOption1: 'foo',
23
- * myOption2: 'bar'
24
- * });
25
- * }
20
+ * static defaultOptions = {
21
+ * myOption1: 'foo',
22
+ * myOption2: 'bar'
23
+ * };
26
24
  * }
27
25
  *
28
26
  * class MyChildClass extends MyClass {
29
- * static {
30
- * this.setDefaultOptions({
31
- * myOption1: 'baz',
32
- * myOption3: 5
33
- * });
34
- * }
27
+ * static defaultOptions = {
28
+ * myOption1: 'baz',
29
+ * myOption3: 5
30
+ * };
35
31
  * }
36
32
  *
37
33
  * const a = new MyChildClass();
@@ -46,12 +42,10 @@ import { setOptions } from "./Util.js";
46
42
  *
47
43
  * ```js
48
44
  * class MyClass extends Class {
49
- * static {
50
- * this.setDefaultOptions({
51
- * foo: 'bar',
52
- * bla: 5
53
- * });
54
- * }
45
+ * static defaultOptions = {
46
+ * foo: 'bar',
47
+ * bla: 5
48
+ * };
55
49
  *
56
50
  * constructor(options) {
57
51
  * super();
@@ -163,42 +157,32 @@ var Class = class {
163
157
  * @returns {T}
164
158
  */
165
159
  static include(props) {
166
- const parentOptions = this.prototype.options;
167
- for (const k of getAllMethodNames(props)) this.prototype[k] = props[k];
168
- if (props.options) {
169
- this.prototype.options = parentOptions;
170
- this.mergeOptions(props.options);
171
- }
160
+ for (let obj = props; obj && obj !== Object.prototype; obj = Object.getPrototypeOf(obj)) for (const k of Object.getOwnPropertyNames(obj)) if (k !== "constructor" && k !== "options") this.prototype[k] = props[k];
161
+ if (props.options) this.mergeOptions(props.options);
172
162
  return this;
173
- function* getAllMethodNames(obj) {
174
- do {
175
- if (obj === Object || obj === Object.prototype) break;
176
- for (const k of Object.getOwnPropertyNames(obj)) yield k;
177
- } while ((obj = Object.getPrototypeOf(obj)) !== void 0);
178
- }
179
163
  }
180
164
  /**
181
- * Configures the [default `options`](#class-options) on the prototype of this class.
165
+ * [Merges `options`](#class-options) into the `defaultOptions` of the class.
182
166
  * @template {typeof Class} T
183
167
  * @this {T}
184
168
  * @param {object} options
185
169
  * @returns {T}
186
170
  */
187
- static setDefaultOptions(options) {
188
- setOptions(this.prototype, options);
171
+ static mergeOptions(options) {
172
+ if (!Object.hasOwn(this, "defaultOptions")) this.defaultOptions = Object.create(this.defaultOptions ?? Object.prototype);
173
+ Object.assign(this.defaultOptions, options);
189
174
  return this;
190
175
  }
191
176
  /**
192
- * [Merges `options`](#class-options) into the defaults of the class.
177
+ * Deprecated alias of `mergeOptions()`, kept for code written for Maplair 4.0.
178
+ * @deprecated Use `static defaultOptions = {…}` or `mergeOptions()`.
193
179
  * @template {typeof Class} T
194
180
  * @this {T}
195
181
  * @param {object} options
196
182
  * @returns {T}
197
183
  */
198
- static mergeOptions(options) {
199
- this.prototype.options ??= {};
200
- Object.assign(this.prototype.options, options);
201
- return this;
184
+ static setDefaultOptions(options) {
185
+ return this.mergeOptions(options);
202
186
  }
203
187
  /**
204
188
  * Adds a [constructor hook](#class-constructor-hooks) to the class: a function
@@ -219,6 +203,7 @@ var Class = class {
219
203
  return this;
220
204
  }
221
205
  constructor() {
206
+ if (this.initialize) throw new Error(`${this.constructor.name}: initialize() is not called in Maplair. Rename it to constructor() and call super() at its start.`);
222
207
  setOptions(this);
223
208
  }
224
209
  /**
@@ -239,7 +224,6 @@ var Class = class {
239
224
  return this;
240
225
  }
241
226
  };
242
- //#endregion
243
227
  export { Class };
244
228
 
245
229
  //# sourceMappingURL=Class.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Class.js","names":[],"sources":["../../../src/core/Class.js"],"sourcesContent":["import * as Util from './Util.js';\n\n// Thanks to John Resig and Dean Edwards for inspiration!\n\n/**\n * Class powers the OOP facilities of Maplair and is used to create almost all of the\n * Maplair classes documented here.\n *\n * It implements a simple classical inheritance model using JavaScript's standard\n * `extends` keyword, and introduces several special properties for convenient code\n * organization — options and init hooks.\n *\n * <h3 id=\"class-options\">Options</h3>\n *\n * `options` is a special property that will be merged with the parent class options\n * instead of overriding them completely, which makes managing configuration of objects\n * and default values convenient. Use `setDefaultOptions()` in a static block to\n * configure options:\n *\n * ```js\n * class MyClass extends Class {\n * static {\n * this.setDefaultOptions({\n * myOption1: 'foo',\n * myOption2: 'bar'\n * });\n * }\n * }\n *\n * class MyChildClass extends MyClass {\n * static {\n * this.setDefaultOptions({\n * myOption1: 'baz',\n * myOption3: 5\n * });\n * }\n * }\n *\n * const a = new MyChildClass();\n * a.options.myOption1; // 'baz'\n * a.options.myOption2; // 'bar'\n * a.options.myOption3; // 5\n * ```\n *\n * There's also [`Util.setOptions`](#util-setoptions), a method for\n * conveniently merging options passed to constructor with the defaults\n * defined in the class:\n *\n * ```js\n * class MyClass extends Class {\n * static {\n * this.setDefaultOptions({\n * foo: 'bar',\n * bla: 5\n * });\n * }\n *\n * constructor(options) {\n * super();\n * Util.setOptions(this, options);\n * ...\n * }\n * }\n *\n * const a = new MyClass({bla: 10});\n * a.options; // {foo: 'bar', bla: 10}\n * ```\n *\n * Note that the options object allows any keys, not just\n * the options defined by the class and its base classes.\n * This means you can use the options object to store\n * application specific information, as long as you avoid\n * keys that are already used by the class in question.\n *\n * <h3 id=\"class-includes\">Mixins</h3>\n *\n * You can add methods and properties from other objects using the `include` method\n * (such objects are called mixins):\n *\n * ```js\n * const MyMixin = {\n * foo() { ... },\n * bar: 5\n * };\n *\n * class MyClass extends Class {}\n *\n * MyClass.include(MyMixin);\n *\n * const a = new MyClass();\n * a.foo();\n * ```\n *\n * <h3 id=\"class-constructor-hooks\">Constructor hooks</h3>\n *\n * If you're a plugin developer, you often need to add additional initialization code\n * to existing classes (e.g. editing hooks for `Polyline`). Maplair comes with a way to\n * do it easily using the `addInitHook` method:\n *\n * ```js\n * Polyline.addInitHook(function () {\n * // ... do something in constructor additionally\n * // e.g. add event listeners, set custom properties etc.\n * this.editing = new PolylineEditor(this);\n * });\n * ```\n *\n * You can also use the following shortcut when you just need to make one additional\n * method call:\n *\n * ```js\n * MyClass.addInitHook('methodName', arg1, arg2, …);\n * ```\n *\n * The hooks of a class run at the end of its constructor, which calls\n * [`callInitHooks`](#class-callinithooks) — so they can rely on everything the\n * constructor sets up. All Maplair classes do so. Hooks of parent classes run\n * first, and parent classes without a constructor of their own (such as `Layer`\n * or `Path`) have their hooks run along with their subclasses. Each hook runs\n * once per object.\n *\n * Note that the hooks of a parent class run before the constructor of a subclass\n * continues. To support hooks on your own classes, call `this.callInitHooks()`\n * at the end of their constructor:\n *\n * ```js\n * class MyMarker extends Marker {\n * constructor(latlng, options) {\n * super(latlng, options); // runs the hooks of Marker (and of Layer etc.)\n * this.extra = 'ready';\n * this.callInitHooks(); // runs the hooks of MyMarker\n * }\n * }\n * ```\n *\n * @example\n * ```js\n * class MyClass extends Class {\n * constructor(greeter) {\n * super();\n * this.greeter = greeter;\n * this.callInitHooks(MyClass); // optional, see constructor hooks above\n * }\n *\n * greet(name) {\n * alert(this.greeter + ', ' + name)\n * }\n * }\n *\n * // create instance of MyClass, passing \"Hello\" to the constructor\n * const a = new MyClass(\"Hello\");\n *\n * // call greet method, alerting \"Hello, World\"\n * a.greet(\"World\");\n * ```\n */\nexport class Class {\n\t/**\n\t * [Includes a mixin](#class-includes) into the current class: copies the properties\n\t * of `props` (and of its prototypes) to the prototype of the class, and merges\n\t * `props.options` into its default options.\n\t * @template {typeof Class} T\n\t * @this {T}\n\t * @param {object} props\n\t * @returns {T}\n\t */\n\tstatic include(props) {\n\t\tconst parentOptions = this.prototype.options;\n\t\tfor (const k of getAllMethodNames(props)) {\n\t\t\tthis.prototype[k] = props[k];\n\t\t}\n\t\tif (props.options) {\n\t\t\tthis.prototype.options = parentOptions;\n\t\t\tthis.mergeOptions(props.options);\n\t\t}\n\t\treturn this;\n\n\t\tfunction *getAllMethodNames(obj) {\n\t\t\tdo {\n\t\t\t\tif (obj === Object || obj === Object.prototype) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tfor (const k of Object.getOwnPropertyNames(obj)) {\n\t\t\t\t\tyield k;\n\t\t\t\t}\n\t\t\t} while ((obj = Object.getPrototypeOf(obj)) !== undefined);\n\t\t}\n\t}\n\n\t/**\n\t * Configures the [default `options`](#class-options) on the prototype of this class.\n\t * @template {typeof Class} T\n\t * @this {T}\n\t * @param {object} options\n\t * @returns {T}\n\t */\n\tstatic setDefaultOptions(options) {\n\t\tUtil.setOptions(this.prototype, options);\n\t\treturn this;\n\t}\n\n\t/**\n\t * [Merges `options`](#class-options) into the defaults of the class.\n\t * @template {typeof Class} T\n\t * @this {T}\n\t * @param {object} options\n\t * @returns {T}\n\t */\n\tstatic mergeOptions(options) {\n\t\tthis.prototype.options ??= {};\n\t\tObject.assign(this.prototype.options, options);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds a [constructor hook](#class-constructor-hooks) to the class: a function\n\t * (called with the object as `this`), or the name of a method to call with the\n\t * given arguments.\n\t * @template {typeof Class} T\n\t * @this {T}\n\t * @param {((this: any) => void)|string} fn\n\t * @param {...any} args Arguments of the method `fn`.\n\t * @returns {T}\n\t */\n\tstatic addInitHook(fn, ...args) { // (Function) || (String, args...)\n\t\tconst init = typeof fn === 'function' ? fn : function () {\n\t\t\tthis[fn](...args);\n\t\t};\n\n\t\tif (!Object.hasOwn(this, '_initHooks')) { // do not use ??= here, which would find the parent class' hooks\n\t\t\tthis._initHooks = [];\n\t\t}\n\t\tthis._initHooks.push(init);\n\t\treturn this;\n\t}\n\n\tconstructor() {\n\t\tUtil.setOptions(this);\n\t}\n\n\t/**\n\t * Runs the [constructor hooks](#class-constructor-hooks) of the given class and\n\t * of its parent classes, which haven't run yet for this object. Classes call it\n\t * at the end of their constructor, e.g. `this.callInitHooks(MyClass)`.\n\t * Without `cls`, runs the hooks of all classes of this object.\n\t * @param {Function} [cls]\n\t * @returns {this}\n\t */\n\tcallInitHooks(cls = this.constructor) {\n\t\tconst done = this._initHooksCalledFor;\n\t\tif (done && (done === cls || done.prototype instanceof cls)) {\n\t\t\treturn this; // the hooks of `cls` already ran\n\t\t}\n\n\t\t// parent classes first; stop at the class whose hooks (and whose parent\n\t\t// classes' hooks) already ran, e.g. in the constructor of a parent class\n\t\tconst classes = [];\n\t\tfor (let c = cls; c && c !== Function.prototype && c !== done; c = Object.getPrototypeOf(c)) {\n\t\t\tclasses.unshift(c);\n\t\t}\n\t\tthis._initHooksCalledFor = cls;\n\n\t\tfor (const c of classes) {\n\t\t\tif (Object.hasOwn(c, '_initHooks')) {\n\t\t\t\tfor (const hook of c._initHooks) {\n\t\t\t\t\thook.call(this);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}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S,SAAS,OAAO,KAAK,qBAAqB,MACtD,OAAO;EAKR,MAAM,UAAU,CAAC;EACjB,KAAK,IAAI,IAAI,KAAK,KAAK,MAAM,SAAS,aAAa,MAAM,MAAM,IAAI,OAAO,eAAe,CAAC,GACzF,QAAQ,QAAQ,CAAC;EAElB,KAAK,sBAAsB;EAE3B,KAAK,MAAM,KAAK,SACf,IAAI,OAAO,OAAO,GAAG,YAAY,GAChC,KAAK,MAAM,QAAQ,EAAE,YACpB,KAAK,KAAK,IAAI;EAIjB,OAAO;CACR;AACD"}
1
+ {"version":3,"file":"Class.js","names":[],"sources":["../../../src/core/Class.js"],"sourcesContent":["import * as Util from './Util.js';\n\n// Thanks to John Resig and Dean Edwards for inspiration!\n\n/**\n * Class powers the OOP facilities of Maplair and is used to create almost all of the\n * Maplair classes documented here.\n *\n * It implements a simple classical inheritance model using JavaScript's standard\n * `extends` keyword, and introduces several special properties for convenient code\n * organization — options and init hooks.\n *\n * <h3 id=\"class-options\">Options</h3>\n *\n * `options` is a special property whose defaults, the static `defaultOptions` of the\n * class, are merged with those of the parent class instead of overriding them\n * completely, which makes managing configuration of objects and default values\n * convenient:\n *\n * ```js\n * class MyClass extends Class {\n * static defaultOptions = {\n * myOption1: 'foo',\n * myOption2: 'bar'\n * };\n * }\n *\n * class MyChildClass extends MyClass {\n * static defaultOptions = {\n * myOption1: 'baz',\n * myOption3: 5\n * };\n * }\n *\n * const a = new MyChildClass();\n * a.options.myOption1; // 'baz'\n * a.options.myOption2; // 'bar'\n * a.options.myOption3; // 5\n * ```\n *\n * There's also [`Util.setOptions`](#util-setoptions), a method for\n * conveniently merging options passed to constructor with the defaults\n * defined in the class:\n *\n * ```js\n * class MyClass extends Class {\n * static defaultOptions = {\n * foo: 'bar',\n * bla: 5\n * };\n *\n * constructor(options) {\n * super();\n * Util.setOptions(this, options);\n * ...\n * }\n * }\n *\n * const a = new MyClass({bla: 10});\n * a.options; // {foo: 'bar', bla: 10}\n * ```\n *\n * Note that the options object allows any keys, not just\n * the options defined by the class and its base classes.\n * This means you can use the options object to store\n * application specific information, as long as you avoid\n * keys that are already used by the class in question.\n *\n * <h3 id=\"class-includes\">Mixins</h3>\n *\n * You can add methods and properties from other objects using the `include` method\n * (such objects are called mixins):\n *\n * ```js\n * const MyMixin = {\n * foo() { ... },\n * bar: 5\n * };\n *\n * class MyClass extends Class {}\n *\n * MyClass.include(MyMixin);\n *\n * const a = new MyClass();\n * a.foo();\n * ```\n *\n * <h3 id=\"class-constructor-hooks\">Constructor hooks</h3>\n *\n * If you're a plugin developer, you often need to add additional initialization code\n * to existing classes (e.g. editing hooks for `Polyline`). Maplair comes with a way to\n * do it easily using the `addInitHook` method:\n *\n * ```js\n * Polyline.addInitHook(function () {\n * // ... do something in constructor additionally\n * // e.g. add event listeners, set custom properties etc.\n * this.editing = new PolylineEditor(this);\n * });\n * ```\n *\n * You can also use the following shortcut when you just need to make one additional\n * method call:\n *\n * ```js\n * MyClass.addInitHook('methodName', arg1, arg2, …);\n * ```\n *\n * The hooks of a class run at the end of its constructor, which calls\n * [`callInitHooks`](#class-callinithooks) — so they can rely on everything the\n * constructor sets up. All Maplair classes do so. Hooks of parent classes run\n * first, and parent classes without a constructor of their own (such as `Layer`\n * or `Path`) have their hooks run along with their subclasses. Each hook runs\n * once per object.\n *\n * Note that the hooks of a parent class run before the constructor of a subclass\n * continues. To support hooks on your own classes, call `this.callInitHooks()`\n * at the end of their constructor:\n *\n * ```js\n * class MyMarker extends Marker {\n * constructor(latlng, options) {\n * super(latlng, options); // runs the hooks of Marker (and of Layer etc.)\n * this.extra = 'ready';\n * this.callInitHooks(); // runs the hooks of MyMarker\n * }\n * }\n * ```\n *\n * @example\n * ```js\n * class MyClass extends Class {\n * constructor(greeter) {\n * super();\n * this.greeter = greeter;\n * this.callInitHooks(MyClass); // optional, see constructor hooks above\n * }\n *\n * greet(name) {\n * alert(this.greeter + ', ' + name)\n * }\n * }\n *\n * // create instance of MyClass, passing \"Hello\" to the constructor\n * const a = new MyClass(\"Hello\");\n *\n * // call greet method, alerting \"Hello, World\"\n * a.greet(\"World\");\n * ```\n */\nexport class Class {\n\t/**\n\t * [Includes a mixin](#class-includes) into the current class: copies the properties\n\t * of `props` (and of its prototypes) to the prototype of the class, and merges\n\t * `props.options` into its default options.\n\t * @template {typeof Class} T\n\t * @this {T}\n\t * @param {object} props\n\t * @returns {T}\n\t */\n\tstatic include(props) {\n\t\tfor (let obj = props; obj && obj !== Object.prototype; obj = Object.getPrototypeOf(obj)) {\n\t\t\tfor (const k of Object.getOwnPropertyNames(obj)) {\n\t\t\t\tif (k !== 'constructor' && k !== 'options') {\n\t\t\t\t\tthis.prototype[k] = props[k];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (props.options) {\n\t\t\tthis.mergeOptions(props.options);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * [Merges `options`](#class-options) into the `defaultOptions` of the class.\n\t * @template {typeof Class} T\n\t * @this {T}\n\t * @param {object} options\n\t * @returns {T}\n\t */\n\tstatic mergeOptions(options) {\n\t\tif (!Object.hasOwn(this, 'defaultOptions')) {\n\t\t\tthis.defaultOptions = Object.create(this.defaultOptions ?? Object.prototype);\n\t\t}\n\t\tObject.assign(this.defaultOptions, options);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Deprecated alias of `mergeOptions()`, kept for code written for Maplair 4.0.\n\t * @deprecated Use `static defaultOptions = {…}` or `mergeOptions()`.\n\t * @template {typeof Class} T\n\t * @this {T}\n\t * @param {object} options\n\t * @returns {T}\n\t */\n\tstatic setDefaultOptions(options) {\n\t\treturn this.mergeOptions(options);\n\t}\n\n\t/**\n\t * Adds a [constructor hook](#class-constructor-hooks) to the class: a function\n\t * (called with the object as `this`), or the name of a method to call with the\n\t * given arguments.\n\t * @template {typeof Class} T\n\t * @this {T}\n\t * @param {((this: any) => void)|string} fn\n\t * @param {...any} args Arguments of the method `fn`.\n\t * @returns {T}\n\t */\n\tstatic addInitHook(fn, ...args) { // (Function) || (String, args...)\n\t\tconst init = typeof fn === 'function' ? fn : function () {\n\t\t\tthis[fn](...args);\n\t\t};\n\n\t\tif (!Object.hasOwn(this, '_initHooks')) { // do not use ??= here, which would find the parent class' hooks\n\t\t\tthis._initHooks = [];\n\t\t}\n\t\tthis._initHooks.push(init);\n\t\treturn this;\n\t}\n\n\tconstructor() {\n\t\tif (this.initialize) {\n\t\t\tthrow new Error(`${this.constructor.name}: initialize() is not called in Maplair. ` +\n\t\t\t\t'Rename it to constructor() and call super() at its start.');\n\t\t}\n\n\t\tUtil.setOptions(this);\n\t}\n\n\t/**\n\t * Runs the [constructor hooks](#class-constructor-hooks) of the given class and\n\t * of its parent classes, which haven't run yet for this object. Classes call it\n\t * at the end of their constructor, e.g. `this.callInitHooks(MyClass)`.\n\t * Without `cls`, runs the hooks of all classes of this object.\n\t * @param {Function} [cls]\n\t * @returns {this}\n\t */\n\tcallInitHooks(cls = this.constructor) {\n\t\tconst done = this._initHooksCalledFor;\n\t\tif (done && (done === cls || done.prototype instanceof cls)) {\n\t\t\treturn this; // the hooks of `cls` already ran\n\t\t}\n\n\t\t// parent classes first; stop at the class whose hooks (and whose parent\n\t\t// classes' hooks) already ran, e.g. in the constructor of a parent class\n\t\tconst classes = [];\n\t\tfor (let c = cls; c && c !== Function.prototype && c !== done; c = Object.getPrototypeOf(c)) {\n\t\t\tclasses.unshift(c);\n\t\t}\n\t\tthis._initHooksCalledFor = cls;\n\n\t\tfor (const c of classes) {\n\t\t\tif (Object.hasOwn(c, '_initHooks')) {\n\t\t\t\tfor (const hook of c._initHooks) {\n\t\t\t\t\thook.call(this);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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sB;EAE3B,KAAK,MAAM,KAAK,SACf,IAAI,OAAO,OAAO,GAAG,YAAY,GAChC,KAAK,MAAM,QAAQ,EAAE,YACpB,KAAK,KAAK,IAAI;EAIjB,OAAO;CACR;AACD"}
@@ -1,6 +1,7 @@
1
1
  import { falseFn, splitWords, stamp } from "./Util.js";
2
2
  import { Class } from "./Class.js";
3
- //#region src/core/Events.js
3
+ // src/core/Events.js
4
+ const warnedEvents = /* @__PURE__ */ new Set();
4
5
  /** @import {LatLng} from '../geo/LatLng.js' */
5
6
  /** @import {LatLngBounds} from '../geo/LatLngBounds.js' */
6
7
  /** @import {Point} from '../geometry/Point.js' */
@@ -88,6 +89,8 @@ import { Class } from "./Class.js";
88
89
  * @typedef {object} LayersControlEvent
89
90
  * @property {Layer} layer The layer that was added or removed.
90
91
  * @property {string} name The name of the layer that was added or removed.
92
+ * @property {Event} [originalEvent] The DOM event of the click on the entry in the
93
+ * layers control, `undefined` if the layer was added or removed by code.
91
94
  * @extends MaplairEvent
92
95
  */
93
96
  /**
@@ -118,6 +121,12 @@ import { Class } from "./Class.js";
118
121
  * @extends MaplairEvent
119
122
  */
120
123
  /**
124
+ * The event object of `worldcopyjump`.
125
+ * @typedef {object} WorldCopyJumpEvent
126
+ * @property {number} worlds The signed number of world widths by which the map pane moved.
127
+ * @extends MaplairEvent
128
+ */
129
+ /**
121
130
  * The event object of adding GeoJSON features.
122
131
  * @typedef {object} GeoJSONEvent
123
132
  * @property {Layer} layer The layer for the GeoJSON feature that is being added to the map.
@@ -213,15 +222,19 @@ var Evented = class Evented extends Class {
213
222
  }
214
223
  return this;
215
224
  }
216
- static __REMOVED_EVENTS = [
217
- "mousedown",
218
- "mouseup",
219
- "mouseover",
220
- "mouseout",
221
- "mousemove"
222
- ];
225
+ static __REMOVED_EVENTS = {
226
+ mousedown: "pointerdown",
227
+ mouseup: "pointerup",
228
+ mouseover: "pointerover",
229
+ mouseout: "pointerout",
230
+ mousemove: "pointermove",
231
+ keypress: "keydown"
232
+ };
223
233
  _on(type, fn, context, _once) {
224
- if (Evented.__REMOVED_EVENTS.includes(type)) console.error(`The event ${type} has been removed. Use the PointerEvent variant instead.`);
234
+ if (Object.hasOwn(Evented.__REMOVED_EVENTS, type) && !warnedEvents.has(type)) {
235
+ warnedEvents.add(type);
236
+ console.error(`The event ${type} has been removed in Maplair. Use ${Evented.__REMOVED_EVENTS[type]} instead.`);
237
+ }
225
238
  if (typeof fn !== "function") {
226
239
  console.warn(`wrong listener type: ${typeof fn}`);
227
240
  return;
@@ -374,7 +387,6 @@ var Evented = class Evented extends Class {
374
387
  }, true);
375
388
  }
376
389
  };
377
- //#endregion
378
390
  export { Evented };
379
391
 
380
392
  //# sourceMappingURL=Events.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Events.js","names":["Util.splitWords","Util.falseFn","Util.stamp"],"sources":["../../../src/core/Events.js"],"sourcesContent":["import {Class} from './Class.js';\nimport * as Util from './Util.js';\n/** @import {LatLng} from '../geo/LatLng.js' */\n/** @import {LatLngBounds} from '../geo/LatLngBounds.js' */\n/** @import {Point} from '../geometry/Point.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n/** @import {Layer} from '../layer/Layer.js' */\n/** @import {Popup} from '../layer/Popup.js' */\n/** @import {Tooltip} from '../layer/Tooltip.js' */\n\n/**\n * The base event object, the argument of event listeners. All other event objects\n * contain these properties too. Whenever a class inheriting from `Evented` fires an\n * event, a listener function is called with an event object containing information\n * about the event, which depends on the event type. For example:\n *\n * ```js\n * map.on('click', function(ev) {\n * alert(ev.latlng); // ev is an event object (MaplairPointerEvent in this case)\n * });\n * ```\n *\n * @typedef {object} MaplairEvent\n * @property {string} type The event type (e.g. `'click'`).\n * @property {any} target The object that fired the event. For propagated events, the\n * last object in the propagation chain that fired the event.\n * @property {any} sourceTarget The object that originally fired the event. For\n * non-propagated events, this will be the same as the `target`.\n * @property {any} [propagatedFrom] For propagated events, the last object that\n * propagated the event to its event parent.\n */\n\n/**\n * A listener of events, called with the event object, which has more properties\n * depending on the event type (see the event objects below).\n * @typedef {(event: MaplairEvent & Record<string, any>) => void} EventListener\n */\n\n/**\n * The event object of keyboard events.\n * @typedef {object} MaplairKeyboardEvent\n * @property {KeyboardEvent} originalEvent The original\n * [DOM `KeyboardEvent`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent)\n * that triggered this Maplair event.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of pointer events (`click`, `pointermove`, …).\n * @typedef {object} MaplairPointerEvent\n * @property {LatLng} latlng The geographical point where the pointer event occurred.\n * @property {Point} layerPoint Pixel coordinates of the point where the pointer event\n * occurred relative to the map layer.\n * @property {Point} containerPoint Pixel coordinates of the point where the pointer\n * event occurred relative to the map container.\n * @property {MouseEvent|PointerEvent} originalEvent The original\n * [DOM `MouseEvent`](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent) or\n * [DOM `PointerEvent`](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent)\n * that triggered this Maplair event.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `locationfound`.\n * @typedef {object} LocationEvent\n * @property {LatLng} latlng Detected geographical location of the user.\n * @property {LatLngBounds} bounds Geographical bounds of the area user is located in\n * (with respect to the accuracy of location).\n * @property {number} accuracy Accuracy of location in meters.\n * @property {number} altitude Height of the position above the WGS84 ellipsoid in meters.\n * @property {number} altitudeAccuracy Accuracy of altitude in meters.\n * @property {number} heading The direction of travel in degrees counting clockwise from true North.\n * @property {number} speed Current velocity in meters per second.\n * @property {number} timestamp The time when the position was acquired.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of errors, e.g. `locationerror`.\n * @typedef {object} MaplairErrorEvent\n * @property {string} message Error message.\n * @property {number} [code] Error code (if applicable).\n * @extends MaplairEvent\n */\n\n/**\n * The event object of adding and removing layers.\n * @typedef {object} LayerEvent\n * @property {Layer} layer The layer that was added or removed.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of the layers control.\n * @typedef {object} LayersControlEvent\n * @property {Layer} layer The layer that was added or removed.\n * @property {string} name The name of the layer that was added or removed.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of tile events.\n * @typedef {object} TileEvent\n * @property {HTMLElement} tile The tile element (image).\n * @property {Point} coords Point object with the tile's `x`, `y`, and `z` (zoom level) coordinates.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `tileerror`.\n * @typedef {object} TileErrorEvent\n * @property {any} error Error passed to the tile's `done()` callback.\n * @extends TileEvent\n */\n\n/**\n * The event object of `resize`.\n * @typedef {object} ResizeEvent\n * @property {Point} oldSize The old size before resize event.\n * @property {Point} newSize The new size after the resize event.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `crschange`.\n * @typedef {object} CrsChangeEvent\n * @property {CRS} oldCrs The CRS of the map before the change.\n * @property {CRS} crs The new CRS of the map.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of adding GeoJSON features.\n * @typedef {object} GeoJSONEvent\n * @property {Layer} layer The layer for the GeoJSON feature that is being added to the map.\n * @property {object} properties GeoJSON properties of the feature.\n * @property {string} geometryType GeoJSON geometry type of the feature.\n * @property {string|number} [id] GeoJSON ID of the feature (if present).\n * @extends MaplairEvent\n */\n\n/**\n * The event object of opening and closing popups.\n * @typedef {object} PopupEvent\n * @property {Popup} popup The popup that was opened or closed.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of opening and closing tooltips.\n * @typedef {object} TooltipEvent\n * @property {Tooltip} tooltip The tooltip that was opened or closed.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `dragend`.\n * @typedef {object} DragEndEvent\n * @property {number} distance The distance in pixels the draggable element was moved by.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `zoomanim`.\n * @typedef {object} ZoomAnimEvent\n * @property {LatLng} center The current center of the map.\n * @property {number} zoom The current zoom level of the map.\n * @property {boolean} [noUpdate] Whether layers should update their contents due to this event.\n * @extends MaplairEvent\n */\n\n/**\n * A set of methods shared between event-powered classes (like `Map` and `Marker`). Generally, events allow you to execute some function when something happens with an object (e.g. the user clicks on the map, causing the map to fire `'click'` event).\n *\n * @example\n *\n * ```js\n * map.on('click', function(e) {\n * \talert(e.latlng);\n * } );\n * ```\n *\n * Maplair deals with event listeners by reference, so if you want to add a listener and then remove it, define it as a function:\n *\n * ```js\n * function onClick(e) { ... }\n *\n * map.on('click', onClick);\n * map.off('click', onClick);\n * ```\n */\nexport class Evented extends Class {\n\t/**\n\t * Adds a listener function (`fn`) to a particular event type of the object. You can\n\t * optionally specify the context of the listener (object the this keyword will point\n\t * to). You can also pass several space-separated types (e.g. `'click dblclick'`).\n\t * Alternatively, adds a set of type/listener pairs, e.g.\n\t * `{click: onClick, pointermove: onPointerMove}`, with the context as second argument.\n\t * @param {string|Record<string, EventListener>} types\n\t * @param {EventListener|object} [fn]\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\ton(types, fn, context) {\n\n\t\t// types can be a map of types/handlers\n\t\tif (typeof types === 'object') {\n\t\t\tfor (const [type, f] of Object.entries(types)) {\n\t\t\t\t// we don't process space-separated events here for performance;\n\t\t\t\t// it's a hot path since Layer uses the on(obj) syntax\n\t\t\t\tthis._on(type, f, fn);\n\t\t\t}\n\n\t\t} else {\n\t\t\t// types can be a string of space-separated words\n\t\t\tfor (const type of Util.splitWords(types)) {\n\t\t\t\tthis._on(type, fn, context);\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes a previously added listener function. If no function is specified, it will\n\t * remove all the listeners of that particular event from the object. Note that if you\n\t * passed a custom context to `on`, you must pass the same context to `off` in order to\n\t * remove the listener. Alternatively, removes a set of type/listener pairs. Without\n\t * arguments, removes all listeners to all events on the object, including implicitly\n\t * attached events.\n\t * @param {string|Record<string, EventListener>} [types]\n\t * @param {EventListener|object} [fn]\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\toff(types, fn, context) {\n\n\t\tif (!arguments.length) {\n\t\t\t// clear all listeners if called without arguments\n\t\t\tdelete this._events;\n\t\t\tdelete this._listenerIndex;\n\n\t\t} else if (typeof types === 'object') {\n\t\t\tfor (const [type, f] of Object.entries(types)) {\n\t\t\t\tthis._off(type, f, fn);\n\t\t\t}\n\n\t\t} else {\n\t\t\tconst removeAll = arguments.length === 1;\n\t\t\tfor (const type of Util.splitWords(types)) {\n\t\t\t\tif (removeAll) {\n\t\t\t\t\tthis._off(type);\n\t\t\t\t} else {\n\t\t\t\t\tthis._off(type, fn, context);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tstatic __REMOVED_EVENTS = ['mousedown', 'mouseup', 'mouseover', 'mouseout', 'mousemove'];\n\n\t// attach listener (without syntactic sugar now)\n\t_on(type, fn, context, _once) {\n\t\t// To be removed in maplair 3\n\t\tif (Evented.__REMOVED_EVENTS.includes(type)) {\n\t\t\tconsole.error(`The event ${type} has been removed. Use the PointerEvent variant instead.`);\n\t\t}\n\n\t\tif (typeof fn !== 'function') {\n\t\t\tconsole.warn(`wrong listener type: ${typeof fn}`);\n\t\t\treturn;\n\t\t}\n\n\t\tif (context === this) {\n\t\t\t// Less memory footprint.\n\t\t\tcontext = undefined;\n\t\t}\n\n\t\t// check if fn already there\n\t\tconst contexts = this._getListenerIndex(type).get(fn);\n\t\tif (contexts?.has(context)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newListener = {fn, ctx: context};\n\t\tif (_once) {\n\t\t\tnewListener.once = true;\n\t\t}\n\n\t\tthis._events ??= {};\n\t\t// a Set keeps the listeners in order, and allows removing them in constant time\n\t\tthis._events[type] ??= new Set();\n\t\tthis._events[type].add(newListener);\n\n\t\tif (contexts) {\n\t\t\tcontexts.set(context, newListener);\n\t\t} else {\n\t\t\tthis._listenerIndex[type].set(fn, new Map([[context, newListener]]));\n\t\t}\n\t}\n\n\t// Listeners of the given event type, indexed by function and context, so that\n\t// adding and removing listeners doesn't need to scan all listeners of the type\n\t// (e.g. each marker listens to the map's `zoom` events with the same function).\n\t_getListenerIndex(type) {\n\t\tthis._listenerIndex ??= {};\n\t\treturn (this._listenerIndex[type] ??= new Map());\n\t}\n\n\t_off(type, fn, context) {\n\t\tif (!this._events) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet listeners = this._events[type];\n\t\tif (!listeners) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (arguments.length === 1) { // remove all\n\t\t\tif (this._firingCount) {\n\t\t\t\t// Set all removed listeners to noop\n\t\t\t\t// so they are not called if remove happens in fire\n\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\tlistener.fn = Util.falseFn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// clear all listeners for a type if function isn't specified\n\t\t\tdelete this._events[type];\n\t\t\tdelete this._listenerIndex?.[type];\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof fn !== 'function') {\n\t\t\tconsole.warn(`wrong listener type: ${typeof fn}`);\n\t\t\treturn;\n\t\t}\n\n\t\t// find fn and remove it\n\t\tif (context === this) {\n\t\t\tcontext = undefined;\n\t\t}\n\t\tconst contexts = this._listenerIndex?.[type]?.get(fn),\n\t\tlistener = contexts?.get(context);\n\t\tif (listener) {\n\t\t\tcontexts.delete(context);\n\t\t\tif (!contexts.size) {\n\t\t\t\tthis._listenerIndex[type].delete(fn);\n\t\t\t}\n\t\t\tif (this._firingCount) {\n\t\t\t\t// set the removed listener to noop so that's not called if remove happens in fire\n\t\t\t\tlistener.fn = Util.falseFn;\n\n\t\t\t\t/* copy listeners in case events are being fired */\n\t\t\t\tthis._events[type] = listeners = new Set(listeners);\n\t\t\t}\n\t\t\tlisteners.delete(listener);\n\t\t}\n\t}\n\n\t/**\n\t * Fires an event of the specified type. You can optionally provide a data\n\t * object — the first argument of the listener function will contain its\n\t * properties. The event can optionally be propagated to event parents.\n\t * @param {string} type\n\t * @param {object} [data]\n\t * @param {boolean} [propagate]\n\t * @returns {this}\n\t */\n\tfire(type, data, propagate) {\n\t\tif (!this.listens(type, propagate)) { return this; }\n\n\t\tconst event = {\n\t\t\t...data,\n\t\t\ttype,\n\t\t\ttarget: this,\n\t\t\tsourceTarget: data?.sourceTarget || this\n\t\t};\n\n\t\tif (this._events) {\n\t\t\tconst listeners = this._events[type];\n\t\t\tif (listeners) {\n\t\t\t\tthis._firingCount = (this._firingCount + 1) || 1;\n\t\t\t\tfor (const l of listeners) {\n\t\t\t\t\t// off overwrites l.fn, so we need to copy fn to a variable\n\t\t\t\t\tconst fn = l.fn;\n\t\t\t\t\tif (l.once) {\n\t\t\t\t\t\tthis.off(type, fn, l.ctx);\n\t\t\t\t\t}\n\t\t\t\t\tfn.call(l.ctx || this, event);\n\t\t\t\t}\n\n\t\t\t\tthis._firingCount--;\n\t\t\t}\n\t\t}\n\n\t\tif (propagate) {\n\t\t\t// propagate the event to parents (set with addEventParent)\n\t\t\tthis._propagateEvent(event);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns `true` if a particular event type has any listeners attached to it (or the\n\t * given listener function, with the given context). The verification can optionally\n\t * be propagated, it will return `true` if parents have the listener attached to it.\n\t * Called as `listens(type, propagate?)` or `listens(type, fn, context?, propagate?)`.\n\t * @param {string} type\n\t * @param {EventListener|boolean} [fn]\n\t * @param {object} [context]\n\t * @param {boolean} [propagate]\n\t * @returns {boolean}\n\t */\n\tlistens(type, fn, context, propagate) {\n\t\tif (typeof type !== 'string') {\n\t\t\tconsole.warn('\"string\" type argument expected');\n\t\t}\n\n\t\t// we don't overwrite the input `fn` value, because we need to use it for propagation\n\t\tlet _fn = fn;\n\t\tif (typeof fn !== 'function') {\n\t\t\tpropagate = !!fn;\n\t\t\t_fn = undefined;\n\t\t\tcontext = undefined;\n\t\t}\n\n\t\tif (this._events?.[type]?.size) {\n\t\t\tif (this._listens(type, _fn, context) !== false) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\tif (propagate) {\n\t\t\t// also check parents for listeners if event propagates\n\t\t\tfor (const p of Object.values(this._eventParents ?? {})) {\n\t\t\t\tif (p.listens(type, fn, context, propagate)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t// returns whether the given listener (or any listener, if no `fn` is given) is registered\n\t_listens(type, fn, context) {\n\t\tif (!this._events) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst listeners = this._events[type];\n\t\tif (!fn) {\n\t\t\treturn !!listeners?.size;\n\t\t}\n\n\t\tif (context === this) {\n\t\t\t// Less memory footprint.\n\t\t\tcontext = undefined;\n\t\t}\n\n\t\treturn !!this._listenerIndex?.[type]?.get(fn)?.has(context);\n\n\t}\n\n\t/**\n\t * Behaves as [`on(…)`](#evented-on), except the listener will only get fired once and then removed.\n\t * @param {string|Record<string, EventListener>} types\n\t * @param {EventListener|object} [fn]\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\tonce(types, fn, context) {\n\n\t\t// types can be a map of types/handlers\n\t\tif (typeof types === 'object') {\n\t\t\tfor (const [type, f] of Object.entries(types)) {\n\t\t\t\t// we don't process space-separated events here for performance;\n\t\t\t\t// it's a hot path since Layer uses the on(obj) syntax\n\t\t\t\tthis._on(type, f, fn, true);\n\t\t\t}\n\n\t\t} else {\n\t\t\t// types can be a string of space-separated words\n\t\t\tfor (const type of Util.splitWords(types)) {\n\t\t\t\tthis._on(type, fn, context, true);\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds an event parent - an `Evented` that will receive propagated events.\n\t * @param {Evented} obj\n\t * @returns {this}\n\t */\n\taddEventParent(obj) {\n\t\tthis._eventParents ??= {};\n\t\tthis._eventParents[Util.stamp(obj)] = obj;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes an event parent, so it will stop receiving propagated events.\n\t * @param {Evented} obj\n\t * @returns {this}\n\t */\n\tremoveEventParent(obj) {\n\t\tif (this._eventParents) {\n\t\t\tdelete this._eventParents[Util.stamp(obj)];\n\t\t}\n\t\treturn this;\n\t}\n\n\t_propagateEvent(e) {\n\t\tfor (const p of Object.values(this._eventParents ??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CAAC,CAAC,WAAW;EAGrB,IAAI,YAAY,MAEf,UAAU,KAAA;EAGX,OAAO,CAAC,CAAC,KAAK,iBAAiB,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,OAAO;CAE3D;;;;;;;;CASA,KAAK,OAAO,IAAI,SAAS;EAGxB,IAAI,OAAO,UAAU,UACpB,KAAK,MAAM,CAAC,MAAM,MAAM,OAAO,QAAQ,KAAK,GAG3C,KAAK,IAAI,MAAM,GAAG,IAAI,IAAI;OAK3B,KAAK,MAAM,QAAQD,WAAgB,KAAK,GACvC,KAAK,IAAI,MAAM,IAAI,SAAS,IAAI;EAIlC,OAAO;CACR;;;;;;CAOA,eAAe,KAAK;EACnB,KAAK,kBAAkB,CAAC;EACxB,KAAK,cAAcE,MAAW,GAAG,KAAK;EACtC,OAAO;CACR;;;;;;CAOA,kBAAkB,KAAK;EACtB,IAAI,KAAK,eACR,OAAO,KAAK,cAAcA,MAAW,GAAG;EAEzC,OAAO;CACR;CAEA,gBAAgB,GAAG;EAClB,KAAK,MAAM,KAAK,OAAO,OAAO,KAAK,iBAAiB,CAAC,CAAC,GACrD,EAAE,KAAK,EAAE,MAAM;GACd,gBAAgB,EAAE;GAClB,GAAG;EACJ,GAAG,IAAI;CAET;AACD"}
1
+ {"version":3,"file":"Events.js","names":["Util.splitWords","Util.falseFn","Util.stamp"],"sources":["../../../src/core/Events.js"],"sourcesContent":["import {Class} from './Class.js';\nimport * as Util from './Util.js';\n\nconst warnedEvents = new Set();\n/** @import {LatLng} from '../geo/LatLng.js' */\n/** @import {LatLngBounds} from '../geo/LatLngBounds.js' */\n/** @import {Point} from '../geometry/Point.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n/** @import {Layer} from '../layer/Layer.js' */\n/** @import {Popup} from '../layer/Popup.js' */\n/** @import {Tooltip} from '../layer/Tooltip.js' */\n\n/**\n * The base event object, the argument of event listeners. All other event objects\n * contain these properties too. Whenever a class inheriting from `Evented` fires an\n * event, a listener function is called with an event object containing information\n * about the event, which depends on the event type. For example:\n *\n * ```js\n * map.on('click', function(ev) {\n * alert(ev.latlng); // ev is an event object (MaplairPointerEvent in this case)\n * });\n * ```\n *\n * @typedef {object} MaplairEvent\n * @property {string} type The event type (e.g. `'click'`).\n * @property {any} target The object that fired the event. For propagated events, the\n * last object in the propagation chain that fired the event.\n * @property {any} sourceTarget The object that originally fired the event. For\n * non-propagated events, this will be the same as the `target`.\n * @property {any} [propagatedFrom] For propagated events, the last object that\n * propagated the event to its event parent.\n */\n\n/**\n * A listener of events, called with the event object, which has more properties\n * depending on the event type (see the event objects below).\n * @typedef {(event: MaplairEvent & Record<string, any>) => void} EventListener\n */\n\n/**\n * The event object of keyboard events.\n * @typedef {object} MaplairKeyboardEvent\n * @property {KeyboardEvent} originalEvent The original\n * [DOM `KeyboardEvent`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent)\n * that triggered this Maplair event.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of pointer events (`click`, `pointermove`, …).\n * @typedef {object} MaplairPointerEvent\n * @property {LatLng} latlng The geographical point where the pointer event occurred.\n * @property {Point} layerPoint Pixel coordinates of the point where the pointer event\n * occurred relative to the map layer.\n * @property {Point} containerPoint Pixel coordinates of the point where the pointer\n * event occurred relative to the map container.\n * @property {MouseEvent|PointerEvent} originalEvent The original\n * [DOM `MouseEvent`](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent) or\n * [DOM `PointerEvent`](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent)\n * that triggered this Maplair event.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `locationfound`.\n * @typedef {object} LocationEvent\n * @property {LatLng} latlng Detected geographical location of the user.\n * @property {LatLngBounds} bounds Geographical bounds of the area user is located in\n * (with respect to the accuracy of location).\n * @property {number} accuracy Accuracy of location in meters.\n * @property {number} altitude Height of the position above the WGS84 ellipsoid in meters.\n * @property {number} altitudeAccuracy Accuracy of altitude in meters.\n * @property {number} heading The direction of travel in degrees counting clockwise from true North.\n * @property {number} speed Current velocity in meters per second.\n * @property {number} timestamp The time when the position was acquired.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of errors, e.g. `locationerror`.\n * @typedef {object} MaplairErrorEvent\n * @property {string} message Error message.\n * @property {number} [code] Error code (if applicable).\n * @extends MaplairEvent\n */\n\n/**\n * The event object of adding and removing layers.\n * @typedef {object} LayerEvent\n * @property {Layer} layer The layer that was added or removed.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of the layers control.\n * @typedef {object} LayersControlEvent\n * @property {Layer} layer The layer that was added or removed.\n * @property {string} name The name of the layer that was added or removed.\n * @property {Event} [originalEvent] The DOM event of the click on the entry in the\n * layers control, `undefined` if the layer was added or removed by code.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of tile events.\n * @typedef {object} TileEvent\n * @property {HTMLElement} tile The tile element (image).\n * @property {Point} coords Point object with the tile's `x`, `y`, and `z` (zoom level) coordinates.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `tileerror`.\n * @typedef {object} TileErrorEvent\n * @property {any} error Error passed to the tile's `done()` callback.\n * @extends TileEvent\n */\n\n/**\n * The event object of `resize`.\n * @typedef {object} ResizeEvent\n * @property {Point} oldSize The old size before resize event.\n * @property {Point} newSize The new size after the resize event.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `crschange`.\n * @typedef {object} CrsChangeEvent\n * @property {CRS} oldCrs The CRS of the map before the change.\n * @property {CRS} crs The new CRS of the map.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `worldcopyjump`.\n * @typedef {object} WorldCopyJumpEvent\n * @property {number} worlds The signed number of world widths by which the map pane moved.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of adding GeoJSON features.\n * @typedef {object} GeoJSONEvent\n * @property {Layer} layer The layer for the GeoJSON feature that is being added to the map.\n * @property {object} properties GeoJSON properties of the feature.\n * @property {string} geometryType GeoJSON geometry type of the feature.\n * @property {string|number} [id] GeoJSON ID of the feature (if present).\n * @extends MaplairEvent\n */\n\n/**\n * The event object of opening and closing popups.\n * @typedef {object} PopupEvent\n * @property {Popup} popup The popup that was opened or closed.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of opening and closing tooltips.\n * @typedef {object} TooltipEvent\n * @property {Tooltip} tooltip The tooltip that was opened or closed.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `dragend`.\n * @typedef {object} DragEndEvent\n * @property {number} distance The distance in pixels the draggable element was moved by.\n * @extends MaplairEvent\n */\n\n/**\n * The event object of `zoomanim`.\n * @typedef {object} ZoomAnimEvent\n * @property {LatLng} center The current center of the map.\n * @property {number} zoom The current zoom level of the map.\n * @property {boolean} [noUpdate] Whether layers should update their contents due to this event.\n * @extends MaplairEvent\n */\n\n/**\n * A set of methods shared between event-powered classes (like `Map` and `Marker`). Generally, events allow you to execute some function when something happens with an object (e.g. the user clicks on the map, causing the map to fire `'click'` event).\n *\n * @example\n *\n * ```js\n * map.on('click', function(e) {\n * \talert(e.latlng);\n * } );\n * ```\n *\n * Maplair deals with event listeners by reference, so if you want to add a listener and then remove it, define it as a function:\n *\n * ```js\n * function onClick(e) { ... }\n *\n * map.on('click', onClick);\n * map.off('click', onClick);\n * ```\n */\nexport class Evented extends Class {\n\t/**\n\t * Adds a listener function (`fn`) to a particular event type of the object. You can\n\t * optionally specify the context of the listener (object the this keyword will point\n\t * to). You can also pass several space-separated types (e.g. `'click dblclick'`).\n\t * Alternatively, adds a set of type/listener pairs, e.g.\n\t * `{click: onClick, pointermove: onPointerMove}`, with the context as second argument.\n\t * @param {string|Record<string, EventListener>} types\n\t * @param {EventListener|object} [fn]\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\ton(types, fn, context) {\n\n\t\t// types can be a map of types/handlers\n\t\tif (typeof types === 'object') {\n\t\t\tfor (const [type, f] of Object.entries(types)) {\n\t\t\t\t// we don't process space-separated events here for performance;\n\t\t\t\t// it's a hot path since Layer uses the on(obj) syntax\n\t\t\t\tthis._on(type, f, fn);\n\t\t\t}\n\n\t\t} else {\n\t\t\t// types can be a string of space-separated words\n\t\t\tfor (const type of Util.splitWords(types)) {\n\t\t\t\tthis._on(type, fn, context);\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes a previously added listener function. If no function is specified, it will\n\t * remove all the listeners of that particular event from the object. Note that if you\n\t * passed a custom context to `on`, you must pass the same context to `off` in order to\n\t * remove the listener. Alternatively, removes a set of type/listener pairs. Without\n\t * arguments, removes all listeners to all events on the object, including implicitly\n\t * attached events.\n\t * @param {string|Record<string, EventListener>} [types]\n\t * @param {EventListener|object} [fn]\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\toff(types, fn, context) {\n\n\t\tif (!arguments.length) {\n\t\t\t// clear all listeners if called without arguments\n\t\t\tdelete this._events;\n\t\t\tdelete this._listenerIndex;\n\n\t\t} else if (typeof types === 'object') {\n\t\t\tfor (const [type, f] of Object.entries(types)) {\n\t\t\t\tthis._off(type, f, fn);\n\t\t\t}\n\n\t\t} else {\n\t\t\tconst removeAll = arguments.length === 1;\n\t\t\tfor (const type of Util.splitWords(types)) {\n\t\t\t\tif (removeAll) {\n\t\t\t\t\tthis._off(type);\n\t\t\t\t} else {\n\t\t\t\t\tthis._off(type, fn, context);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tstatic __REMOVED_EVENTS = {\n\t\tmousedown: 'pointerdown',\n\t\tmouseup: 'pointerup',\n\t\tmouseover: 'pointerover',\n\t\tmouseout: 'pointerout',\n\t\tmousemove: 'pointermove',\n\t\tkeypress: 'keydown'\n\t};\n\n\t// attach listener (without syntactic sugar now)\n\t_on(type, fn, context, _once) {\n\t\t// To be removed in maplair 3\n\t\tif (Object.hasOwn(Evented.__REMOVED_EVENTS, type) && !warnedEvents.has(type)) {\n\t\t\twarnedEvents.add(type);\n\t\t\tconsole.error(`The event ${type} has been removed in Maplair. Use ${Evented.__REMOVED_EVENTS[type]} instead.`);\n\t\t}\n\n\t\tif (typeof fn !== 'function') {\n\t\t\tconsole.warn(`wrong listener type: ${typeof fn}`);\n\t\t\treturn;\n\t\t}\n\n\t\tif (context === this) {\n\t\t\t// Less memory footprint.\n\t\t\tcontext = undefined;\n\t\t}\n\n\t\t// check if fn already there\n\t\tconst contexts = this._getListenerIndex(type).get(fn);\n\t\tif (contexts?.has(context)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newListener = {fn, ctx: context};\n\t\tif (_once) {\n\t\t\tnewListener.once = true;\n\t\t}\n\n\t\tthis._events ??= {};\n\t\t// a Set keeps the listeners in order, and allows removing them in constant time\n\t\tthis._events[type] ??= new Set();\n\t\tthis._events[type].add(newListener);\n\n\t\tif (contexts) {\n\t\t\tcontexts.set(context, newListener);\n\t\t} else {\n\t\t\tthis._listenerIndex[type].set(fn, new Map([[context, newListener]]));\n\t\t}\n\t}\n\n\t// Listeners of the given event type, indexed by function and context, so that\n\t// adding and removing listeners doesn't need to scan all listeners of the type\n\t// (e.g. each marker listens to the map's `zoom` events with the same function).\n\t_getListenerIndex(type) {\n\t\tthis._listenerIndex ??= {};\n\t\treturn (this._listenerIndex[type] ??= new Map());\n\t}\n\n\t_off(type, fn, context) {\n\t\tif (!this._events) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet listeners = this._events[type];\n\t\tif (!listeners) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (arguments.length === 1) { // remove all\n\t\t\tif (this._firingCount) {\n\t\t\t\t// Set all removed listeners to noop\n\t\t\t\t// so they are not called if remove happens in fire\n\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\tlistener.fn = Util.falseFn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// clear all listeners for a type if function isn't specified\n\t\t\tdelete this._events[type];\n\t\t\tdelete this._listenerIndex?.[type];\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof fn !== 'function') {\n\t\t\tconsole.warn(`wrong listener type: ${typeof fn}`);\n\t\t\treturn;\n\t\t}\n\n\t\t// find fn and remove it\n\t\tif (context === this) {\n\t\t\tcontext = undefined;\n\t\t}\n\t\tconst contexts = this._listenerIndex?.[type]?.get(fn),\n\t\tlistener = contexts?.get(context);\n\t\tif (listener) {\n\t\t\tcontexts.delete(context);\n\t\t\tif (!contexts.size) {\n\t\t\t\tthis._listenerIndex[type].delete(fn);\n\t\t\t}\n\t\t\tif (this._firingCount) {\n\t\t\t\t// set the removed listener to noop so that's not called if remove happens in fire\n\t\t\t\tlistener.fn = Util.falseFn;\n\n\t\t\t\t/* copy listeners in case events are being fired */\n\t\t\t\tthis._events[type] = listeners = new Set(listeners);\n\t\t\t}\n\t\t\tlisteners.delete(listener);\n\t\t}\n\t}\n\n\t/**\n\t * Fires an event of the specified type. You can optionally provide a data\n\t * object — the first argument of the listener function will contain its\n\t * properties. The event can optionally be propagated to event parents.\n\t * @param {string} type\n\t * @param {object} [data]\n\t * @param {boolean} [propagate]\n\t * @returns {this}\n\t */\n\tfire(type, data, propagate) {\n\t\tif (!this.listens(type, propagate)) { return this; }\n\n\t\tconst event = {\n\t\t\t...data,\n\t\t\ttype,\n\t\t\ttarget: this,\n\t\t\tsourceTarget: data?.sourceTarget || this\n\t\t};\n\n\t\tif (this._events) {\n\t\t\tconst listeners = this._events[type];\n\t\t\tif (listeners) {\n\t\t\t\tthis._firingCount = (this._firingCount + 1) || 1;\n\t\t\t\tfor (const l of listeners) {\n\t\t\t\t\t// off overwrites l.fn, so we need to copy fn to a variable\n\t\t\t\t\tconst fn = l.fn;\n\t\t\t\t\tif (l.once) {\n\t\t\t\t\t\tthis.off(type, fn, l.ctx);\n\t\t\t\t\t}\n\t\t\t\t\tfn.call(l.ctx || this, event);\n\t\t\t\t}\n\n\t\t\t\tthis._firingCount--;\n\t\t\t}\n\t\t}\n\n\t\tif (propagate) {\n\t\t\t// propagate the event to parents (set with addEventParent)\n\t\t\tthis._propagateEvent(event);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns `true` if a particular event type has any listeners attached to it (or the\n\t * given listener function, with the given context). The verification can optionally\n\t * be propagated, it will return `true` if parents have the listener attached to it.\n\t * Called as `listens(type, propagate?)` or `listens(type, fn, context?, propagate?)`.\n\t * @param {string} type\n\t * @param {EventListener|boolean} [fn]\n\t * @param {object} [context]\n\t * @param {boolean} [propagate]\n\t * @returns {boolean}\n\t */\n\tlistens(type, fn, context, propagate) {\n\t\tif (typeof type !== 'string') {\n\t\t\tconsole.warn('\"string\" type argument expected');\n\t\t}\n\n\t\t// we don't overwrite the input `fn` value, because we need to use it for propagation\n\t\tlet _fn = fn;\n\t\tif (typeof fn !== 'function') {\n\t\t\tpropagate = !!fn;\n\t\t\t_fn = undefined;\n\t\t\tcontext = undefined;\n\t\t}\n\n\t\tif (this._events?.[type]?.size) {\n\t\t\tif (this._listens(type, _fn, context) !== false) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\tif (propagate) {\n\t\t\t// also check parents for listeners if event propagates\n\t\t\tfor (const p of Object.values(this._eventParents ?? {})) {\n\t\t\t\tif (p.listens(type, fn, context, propagate)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t// returns whether the given listener (or any listener, if no `fn` is given) is registered\n\t_listens(type, fn, context) {\n\t\tif (!this._events) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst listeners = this._events[type];\n\t\tif (!fn) {\n\t\t\treturn !!listeners?.size;\n\t\t}\n\n\t\tif (context === this) {\n\t\t\t// Less memory footprint.\n\t\t\tcontext = undefined;\n\t\t}\n\n\t\treturn !!this._listenerIndex?.[type]?.get(fn)?.has(context);\n\n\t}\n\n\t/**\n\t * Behaves as [`on(…)`](#evented-on), except the listener will only get fired once and then removed.\n\t * @param {string|Record<string, EventListener>} types\n\t * @param {EventListener|object} [fn]\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\tonce(types, fn, context) {\n\n\t\t// types can be a map of types/handlers\n\t\tif (typeof types === 'object') {\n\t\t\tfor (const [type, f] of Object.entries(types)) {\n\t\t\t\t// we don't process space-separated events here for performance;\n\t\t\t\t// it's a hot path since Layer uses the on(obj) syntax\n\t\t\t\tthis._on(type, f, fn, true);\n\t\t\t}\n\n\t\t} else {\n\t\t\t// types can be a string of space-separated words\n\t\t\tfor (const type of Util.splitWords(types)) {\n\t\t\t\tthis._on(type, fn, context, true);\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds an event parent - an `Evented` that will receive propagated events.\n\t * @param {Evented} obj\n\t * @returns {this}\n\t */\n\taddEventParent(obj) {\n\t\tthis._eventParents ??= {};\n\t\tthis._eventParents[Util.stamp(obj)] = obj;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes an event parent, so it will stop receiving propagated events.\n\t * @param {Evented} obj\n\t * @returns {this}\n\t */\n\tremoveEventParent(obj) {\n\t\tif (this._eventParents) {\n\t\t\tdelete this._eventParents[Util.stamp(obj)];\n\t\t}\n\t\treturn this;\n\t}\n\n\t_propagateEvent(e) {\n\t\tfor (const p of Object.values(this._eventParents ?? {})) {\n\t\t\tp.fire(e.type, {\n\t\t\t\tpropagatedFrom: e.target,\n\t\t\t\t...e\n\t\t\t}, true);\n\t\t}\n\t}\n};\n"],"mappings":";;;AAGA,MAAM,+BAAe,IAAI,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuM7B,IAAa,UAAb,MAAa,gBAAgB,MAAM;;;;;;;;;;;;CAYlC,GAAG,OAAO,IAAI,SAAS;EAGtB,IAAI,OAAO,UAAU,UACpB,KAAK,MAAM,CAAC,MAAM,MAAM,OAAO,QAAQ,KAAK,GAG3C,KAAK,IAAI,MAAM,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AI,SAAS,IAAI;EAIlC,OAAO;CACR;;;;;;CAOA,eAAe,KAAK;EACnB,KAAK,kBAAkB,CAAC;EACxB,KAAK,cAAcE,MAAW,GAAG,KAAK;EACtC,OAAO;CACR;;;;;;CAOA,kBAAkB,KAAK;EACtB,IAAI,KAAK,eACR,OAAO,KAAK,cAAcA,MAAW,GAAG;EAEzC,OAAO;CACR;CAEA,gBAAgB,GAAG;EAClB,KAAK,MAAM,KAAK,OAAO,OAAO,KAAK,iBAAiB,CAAC,CAAC,GACrD,EAAE,KAAK,EAAE,MAAM;GACd,gBAAgB,EAAE;GAClB,GAAG;EACJ,GAAG,IAAI;CAET;AACD"}
@@ -1,12 +1,12 @@
1
1
  import { Class } from "./Class.js";
2
- //#region src/core/Handler.js
2
+ // src/core/Handler.js
3
3
  /** @import {MaplairMap} from '../map/Map.js' */
4
4
  /**
5
5
  * Abstract class for map interaction handlers, the base class of the handlers that
6
6
  * are used internally to inject interaction features like dragging to classes like
7
7
  * `MaplairMap` and `Marker`.
8
8
  *
9
- * Classes inheriting from `Handler` must implement the two following extension methods:
9
+ * Classes inheriting from `Handler` implement the two following extension methods:
10
10
  *
11
11
  * * `addHooks()` is called when the handler is enabled, should add event hooks.
12
12
  * * `removeHooks()` is called when the handler is disabled, should remove the event
@@ -48,19 +48,28 @@ var Handler = class Handler extends Class {
48
48
  enabled() {
49
49
  return !!this._enabled;
50
50
  }
51
+ /**
52
+ * Called when the handler is enabled, should add event hooks.
53
+ */
54
+ addHooks() {}
55
+ /**
56
+ * Called when the handler is disabled, should remove the event hooks added previously.
57
+ */
58
+ removeHooks() {}
59
+ /**
60
+ * Adds a new handler of this class to the given map with the given name, which is
61
+ * then available as the property of the map with this name.
62
+ * @template {typeof Handler} T
63
+ * @this {T}
64
+ * @param {MaplairMap} map
65
+ * @param {string} name
66
+ * @returns {T}
67
+ */
68
+ static addTo(map, name) {
69
+ map.addHandler(name, this);
70
+ return this;
71
+ }
51
72
  };
52
- /**
53
- * Adds a new handler of this class to the given map with the given name, which is
54
- * then available as the property of the map with this name.
55
- * @param {MaplairMap} map
56
- * @param {string} name
57
- * @returns {typeof Handler}
58
- */
59
- Handler.addTo = function(map, name) {
60
- map.addHandler(name, this);
61
- return this;
62
- };
63
- //#endregion
64
73
  export { Handler };
65
74
 
66
75
  //# sourceMappingURL=Handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Handler.js","names":[],"sources":["../../../src/core/Handler.js"],"sourcesContent":["import {Class} from './Class.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * Abstract class for map interaction handlers, the base class of the handlers that\n * are used internally to inject interaction features like dragging to classes like\n * `MaplairMap` and `Marker`.\n *\n * Classes inheriting from `Handler` must implement the two following extension methods:\n *\n * * `addHooks()` is called when the handler is enabled, should add event hooks.\n * * `removeHooks()` is called when the handler is disabled, should remove the event\n * hooks added previously.\n */\nexport class Handler extends Class {\n\t/**\n\t * @param {MaplairMap} map The map the handler belongs to.\n\t */\n\tconstructor(map) {\n\t\tsuper();\n\t\tthis._map = map;\n\n\t\tthis.callInitHooks(Handler);\n\t}\n\n\t/**\n\t * Enables the handler.\n\t * @returns {this}\n\t */\n\tenable() {\n\t\tif (this._enabled) { return this; }\n\n\t\tthis._enabled = true;\n\t\tthis.addHooks();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Disables the handler.\n\t * @returns {this}\n\t */\n\tdisable() {\n\t\tif (!this._enabled) { return this; }\n\n\t\tthis._enabled = false;\n\t\tthis.removeHooks();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns `true` if the handler is enabled.\n\t * @returns {boolean}\n\t */\n\tenabled() {\n\t\treturn !!this._enabled;\n\t}\n}\n\n/**\n * Adds a new handler of this class to the given map with the given name, which is\n * then available as the property of the map with this name.\n * @param {MaplairMap} map\n * @param {string} name\n * @returns {typeof Handler}\n */\nHandler.addTo = function (map, name) {\n\tmap.addHandler(name, this);\n\treturn this;\n};\n"],"mappings":";;;;;;;;;;;;;;AAcA,IAAa,UAAb,MAAa,gBAAgB,MAAM;;;;CAIlC,YAAY,KAAK;EAChB,MAAM;EACN,KAAK,OAAO;EAEZ,KAAK,cAAc,OAAO;CAC3B;;;;;CAMA,SAAS;EACR,IAAI,KAAK,UAAY,OAAO;EAE5B,KAAK,WAAW;EAChB,KAAK,SAAS;EACd,OAAO;CACR;;;;;CAMA,UAAU;EACT,IAAI,CAAC,KAAK,UAAY,OAAO;EAE7B,KAAK,WAAW;EAChB,KAAK,YAAY;EACjB,OAAO;CACR;;;;;CAMA,UAAU;EACT,OAAO,CAAC,CAAC,KAAK;CACf;AACD;;;;;;;;AASA,QAAQ,QAAQ,SAAU,KAAK,MAAM;CACpC,IAAI,WAAW,MAAM,IAAI;CACzB,OAAO;AACR"}
1
+ {"version":3,"file":"Handler.js","names":[],"sources":["../../../src/core/Handler.js"],"sourcesContent":["import {Class} from './Class.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * Abstract class for map interaction handlers, the base class of the handlers that\n * are used internally to inject interaction features like dragging to classes like\n * `MaplairMap` and `Marker`.\n *\n * Classes inheriting from `Handler` implement the two following extension methods:\n *\n * * `addHooks()` is called when the handler is enabled, should add event hooks.\n * * `removeHooks()` is called when the handler is disabled, should remove the event\n * hooks added previously.\n */\nexport class Handler extends Class {\n\t/**\n\t * @param {MaplairMap} map The map the handler belongs to.\n\t */\n\tconstructor(map) {\n\t\tsuper();\n\t\tthis._map = map;\n\n\t\tthis.callInitHooks(Handler);\n\t}\n\n\t/**\n\t * Enables the handler.\n\t * @returns {this}\n\t */\n\tenable() {\n\t\tif (this._enabled) { return this; }\n\n\t\tthis._enabled = true;\n\t\tthis.addHooks();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Disables the handler.\n\t * @returns {this}\n\t */\n\tdisable() {\n\t\tif (!this._enabled) { return this; }\n\n\t\tthis._enabled = false;\n\t\tthis.removeHooks();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns `true` if the handler is enabled.\n\t * @returns {boolean}\n\t */\n\tenabled() {\n\t\treturn !!this._enabled;\n\t}\n\n\t/**\n\t * Called when the handler is enabled, should add event hooks.\n\t */\n\taddHooks() {}\n\n\t/**\n\t * Called when the handler is disabled, should remove the event hooks added previously.\n\t */\n\tremoveHooks() {}\n\n\t/**\n\t * Adds a new handler of this class to the given map with the given name, which is\n\t * then available as the property of the map with this name.\n\t * @template {typeof Handler} T\n\t * @this {T}\n\t * @param {MaplairMap} map\n\t * @param {string} name\n\t * @returns {T}\n\t */\n\tstatic addTo(map, name) {\n\t\tmap.addHandler(name, this);\n\t\treturn this;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,IAAa,UAAb,MAAa,gBAAgB,MAAM;;;;CAIlC,YAAY,KAAK;EAChB,MAAM;EACN,KAAK,OAAO;EAEZ,KAAK,cAAc,OAAO;CAC3B;;;;;CAMA,SAAS;EACR,IAAI,KAAK,UAAY,OAAO;EAE5B,KAAK,WAAW;EAChB,KAAK,SAAS;EACd,OAAO;CACR;;;;;CAMA,UAAU;EACT,IAAI,CAAC,KAAK,UAAY,OAAO;EAE7B,KAAK,WAAW;EAChB,KAAK,YAAY;EACjB,OAAO;CACR;;;;;CAMA,UAAU;EACT,OAAO,CAAC,CAAC,KAAK;CACf;;;;CAKA,WAAW,CAAC;;;;CAKZ,cAAc,CAAC;;;;;;;;;;CAWf,OAAO,MAAM,KAAK,MAAM;EACvB,IAAI,WAAW,MAAM,IAAI;EACzB,OAAO;CACR;AACD"}
@@ -1,5 +1,5 @@
1
1
  import { template } from "./Util.js";
2
- //#region src/core/I18n.js
2
+ // src/core/I18n.js
3
3
  /**
4
4
  * Utility functions to deal with translations.
5
5
  *
@@ -68,7 +68,6 @@ var I18n = class {
68
68
  }
69
69
  }
70
70
  };
71
- //#endregion
72
71
  export { I18n };
73
72
 
74
73
  //# sourceMappingURL=I18n.js.map
@@ -1,5 +1,5 @@
1
1
  import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
- //#region src/core/Util.js
2
+ // src/core/Util.js
3
3
  var Util_exports = /* @__PURE__ */ __exportAll({
4
4
  falseFn: () => falseFn,
5
5
  formatNum: () => formatNum,
@@ -57,7 +57,7 @@ function throttle(fn, time, context) {
57
57
  }
58
58
  /**
59
59
  * Returns the number `x` modulo `range` in such a way so it lies within
60
- * `range[0]` and `range[1]`. The returned value will be always smaller than
60
+ * `range[0]` and `range[1]`. The returned value will always be smaller than
61
61
  * `range[1]` unless `includeMax` is set to `true`.
62
62
  * @param {number} x
63
63
  * @param {[number, number]} range
@@ -105,10 +105,22 @@ function splitWords(str) {
105
105
  * @returns {object}
106
106
  */
107
107
  function setOptions(obj, options) {
108
- if (!Object.hasOwn(obj, "options")) obj.options = obj.options ? Object.create(obj.options) : {};
108
+ if (!Object.hasOwn(obj, "options")) {
109
+ const defaults = getDefaultOptions(obj.constructor) ?? obj.options;
110
+ obj.options = defaults ? Object.create(defaults) : {};
111
+ }
109
112
  for (const i in options) if (Object.hasOwn(options, i)) obj.options[i] = options[i];
110
113
  return obj.options;
111
114
  }
115
+ const chainedDefaults = /* @__PURE__ */ new WeakMap();
116
+ function getDefaultOptions(cls) {
117
+ const defaults = cls?.defaultOptions;
118
+ if (defaults && chainedDefaults.get(cls) !== defaults) {
119
+ for (let c = cls; c.defaultOptions; c = Object.getPrototypeOf(c)) if (Object.hasOwn(c, "defaultOptions")) Object.setPrototypeOf(c.defaultOptions, Object.getPrototypeOf(c).defaultOptions ?? Object.prototype);
120
+ chainedDefaults.set(cls, defaults);
121
+ }
122
+ return defaults;
123
+ }
112
124
  const templateRe = /\{ *([\w_ -]+) *\}/g;
113
125
  /**
114
126
  * Simple templating facility, accepts a template string of the form `'Hello {a}, {b}'`
@@ -127,7 +139,6 @@ function template(str, data) {
127
139
  return value;
128
140
  });
129
141
  }
130
- //#endregion
131
142
  export { Util_exports, falseFn, formatNum, lastId, setOptions, splitWords, stamp, template, throttle, wrapNum };
132
143
 
133
144
  //# sourceMappingURL=Util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Util.js","names":[],"sources":["../../../src/core/Util.js"],"sourcesContent":["// Util: various utility functions, used by Maplair internally.\n\n/**\n * Last unique ID used by [`stamp()`](#util-stamp).\n * @type {number}\n */\nexport let lastId = 0;\n\n/**\n * Returns the unique ID of an object, assigning it one if it doesn't have it.\n * @param {object} obj\n * @returns {number}\n */\nexport function stamp(obj) {\n\tif (!('_maplair_id' in obj)) {\n\t\tobj['_maplair_id'] = ++lastId;\n\t}\n\treturn obj._maplair_id;\n}\n\n/**\n * Returns a function which executes function `fn` with the given scope `context`\n * (so that the `this` keyword refers to `context` inside `fn`'s code). The function\n * `fn` will be called no more than one time per given amount of `time`. The arguments\n * received by the bound function will be any arguments passed when binding the\n * function, followed by any arguments passed when invoking the bound function.\n * @param {(...args: any[]) => void} fn\n * @param {number} time In milliseconds.\n * @param {object} [context]\n * @returns {(...args: any[]) => void}\n */\nexport function throttle(fn, time, context) {\n\tlet lock, queuedArgs;\n\n\tfunction later() {\n\t\t// reset lock and call if queued\n\t\tlock = false;\n\t\tif (queuedArgs) {\n\t\t\twrapperFn.apply(context, queuedArgs);\n\t\t\tqueuedArgs = false;\n\t\t}\n\t}\n\n\tfunction wrapperFn(...args) {\n\t\tif (lock) {\n\t\t\t// called too soon, queue to call later\n\t\t\tqueuedArgs = args;\n\n\t\t} else {\n\t\t\t// call and lock until later\n\t\t\tfn.apply(context, args);\n\t\t\tsetTimeout(later, time);\n\t\t\tlock = true;\n\t\t}\n\t}\n\n\treturn wrapperFn;\n}\n\n/**\n * Returns the number `x` modulo `range` in such a way so it lies within\n * `range[0]` and `range[1]`. The returned value will be always smaller than\n * `range[1]` unless `includeMax` is set to `true`.\n * @param {number} x\n * @param {[number, number]} range\n * @param {boolean} [includeMax]\n * @returns {number}\n */\nexport function wrapNum(x, range, includeMax) {\n\tconst max = range[1],\n\tmin = range[0],\n\td = max - min;\n\treturn x === max && includeMax ? x : ((x - min) % d + d) % d + min;\n}\n\n/**\n * A function which always returns `false`.\n * @returns {false}\n */\nexport function falseFn() { return false; }\n\n/**\n * Returns the number `num` rounded with specified `precision`.\n * The default `precision` value is 6 decimal places.\n * `false` can be passed to skip any processing (can be useful to avoid round-off errors).\n * @param {number} num\n * @param {number|false} [precision]\n * @returns {number}\n */\nexport function formatNum(num, precision) {\n\tif (precision === false) { return num; }\n\tconst pow = 10 ** (precision === undefined ? 6 : precision);\n\treturn Math.round(num * pow) / pow;\n}\n\nconst WHITESPACE_RE = /\\s+/;\n\n/**\n * Trims and splits the string on whitespace and returns the array of parts.\n * @param {string} str\n * @returns {string[]}\n */\nexport function splitWords(str) {\n\treturn str.trim().split(WHITESPACE_RE);\n}\n\n/**\n * Merges the given properties to the `options` of the `obj` object, returning the\n * resulting options. See `Class options`.\n * @param {object} obj\n * @param {object} [options]\n * @returns {object}\n */\nexport function setOptions(obj, options) {\n\tif (!Object.hasOwn(obj, 'options')) {\n\t\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/**\n * Simple templating facility, accepts a template string of the form `'Hello {a}, {b}'`\n * and a data object like `{a: 'foo', b: 'bar'}`, returns evaluated string\n * `('Hello foo, bar')`. You can also specify functions instead of strings for\n * data values — they will be evaluated passing `data` as an argument.\n * @param {string} str\n * @param {Record<string, any>} data\n * @returns {string}\n */\nexport function template(str, data) {\n\treturn str.replace(templateRe, (str, key) => {\n\t\tlet value = data[key];\n\n\t\tif (value === undefined) {\n\t\t\tthrow new Error(`No value provided for variable ${str}`);\n\n\t\t} else if (typeof value === 'function') {\n\t\t\tvalue = value(data);\n\t\t}\n\t\treturn value;\n\t});\n}\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;AAMA,IAAW,SAAS;;;;;;AAOpB,SAAgB,MAAM,KAAK;CAC1B,IAAI,EAAE,i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,aAAa,KAAK,QAAQ;EAC5C,IAAI,QAAQ,KAAK;EAEjB,IAAI,UAAU,KAAA,GACb,MAAM,IAAI,MAAM,kCAAkC,KAAK;OAEjD,IAAI,OAAO,UAAU,YAC3B,QAAQ,MAAM,IAAI;EAEnB,OAAO;CACR,CAAC;AACF"}
1
+ {"version":3,"file":"Util.js","names":[],"sources":["../../../src/core/Util.js"],"sourcesContent":["// Util: various utility functions, used by Maplair internally.\n\n/**\n * Last unique ID used by [`stamp()`](#util-stamp).\n * @type {number}\n */\nexport let lastId = 0;\n\n/**\n * Returns the unique ID of an object, assigning it one if it doesn't have it.\n * @param {object} obj\n * @returns {number}\n */\nexport function stamp(obj) {\n\tif (!('_maplair_id' in obj)) {\n\t\tobj['_maplair_id'] = ++lastId;\n\t}\n\treturn obj._maplair_id;\n}\n\n/**\n * Returns a function which executes function `fn` with the given scope `context`\n * (so that the `this` keyword refers to `context` inside `fn`'s code). The function\n * `fn` will be called no more than one time per given amount of `time`. The arguments\n * received by the bound function will be any arguments passed when binding the\n * function, followed by any arguments passed when invoking the bound function.\n * @param {(...args: any[]) => void} fn\n * @param {number} time In milliseconds.\n * @param {object} [context]\n * @returns {(...args: any[]) => void}\n */\nexport function throttle(fn, time, context) {\n\tlet lock, queuedArgs;\n\n\tfunction later() {\n\t\t// reset lock and call if queued\n\t\tlock = false;\n\t\tif (queuedArgs) {\n\t\t\twrapperFn.apply(context, queuedArgs);\n\t\t\tqueuedArgs = false;\n\t\t}\n\t}\n\n\tfunction wrapperFn(...args) {\n\t\tif (lock) {\n\t\t\t// called too soon, queue to call later\n\t\t\tqueuedArgs = args;\n\n\t\t} else {\n\t\t\t// call and lock until later\n\t\t\tfn.apply(context, args);\n\t\t\tsetTimeout(later, time);\n\t\t\tlock = true;\n\t\t}\n\t}\n\n\treturn wrapperFn;\n}\n\n/**\n * Returns the number `x` modulo `range` in such a way so it lies within\n * `range[0]` and `range[1]`. The returned value will always be smaller than\n * `range[1]` unless `includeMax` is set to `true`.\n * @param {number} x\n * @param {[number, number]} range\n * @param {boolean} [includeMax]\n * @returns {number}\n */\nexport function wrapNum(x, range, includeMax) {\n\tconst max = range[1],\n\tmin = range[0],\n\td = max - min;\n\treturn x === max && includeMax ? x : ((x - min) % d + d) % d + min;\n}\n\n/**\n * A function which always returns `false`.\n * @returns {false}\n */\nexport function falseFn() { return false; }\n\n/**\n * Returns the number `num` rounded with specified `precision`.\n * The default `precision` value is 6 decimal places.\n * `false` can be passed to skip any processing (can be useful to avoid round-off errors).\n * @param {number} num\n * @param {number|false} [precision]\n * @returns {number}\n */\nexport function formatNum(num, precision) {\n\tif (precision === false) { return num; }\n\tconst pow = 10 ** (precision === undefined ? 6 : precision);\n\treturn Math.round(num * pow) / pow;\n}\n\nconst WHITESPACE_RE = /\\s+/;\n\n/**\n * Trims and splits the string on whitespace and returns the array of parts.\n * @param {string} str\n * @returns {string[]}\n */\nexport function splitWords(str) {\n\treturn str.trim().split(WHITESPACE_RE);\n}\n\n/**\n * Merges the given properties to the `options` of the `obj` object, returning the\n * resulting options. See `Class options`.\n * @param {object} obj\n * @param {object} [options]\n * @returns {object}\n */\nexport function setOptions(obj, options) {\n\tif (!Object.hasOwn(obj, 'options')) {\n\t\tconst defaults = getDefaultOptions(obj.constructor) ?? obj.options;\n\t\tobj.options = defaults ? Object.create(defaults) : {};\n\t}\n\tfor (const i in options) {\n\t\tif (Object.hasOwn(options, i)) {\n\t\t\tobj.options[i] = options[i];\n\t\t}\n\t}\n\treturn obj.options;\n}\n\nconst chainedDefaults = new WeakMap(); // class -> the defaultOptions object it was chained with\n\n// Links the `defaultOptions` of each class in the chain to its parent's, so defaults are inherited and stay live.\n// Done on first use because a static field can't do it in its initializer and stay tree-shakeable.\nfunction getDefaultOptions(cls) {\n\tconst defaults = cls?.defaultOptions;\n\tif (defaults && chainedDefaults.get(cls) !== defaults) {\n\t\tfor (let c = cls; c.defaultOptions; c = Object.getPrototypeOf(c)) {\n\t\t\tif (Object.hasOwn(c, 'defaultOptions')) {\n\t\t\t\tObject.setPrototypeOf(c.defaultOptions, Object.getPrototypeOf(c).defaultOptions ?? Object.prototype);\n\t\t\t}\n\t\t}\n\t\tchainedDefaults.set(cls, defaults);\n\t}\n\treturn defaults;\n}\n\nconst templateRe = /\\{ *([\\w_ -]+) *\\}/g;\n\n/**\n * Simple templating facility, accepts a template string of the form `'Hello {a}, {b}'`\n * and a data object like `{a: 'foo', b: 'bar'}`, returns evaluated string\n * `('Hello foo, bar')`. You can also specify functions instead of strings for\n * data values — they will be evaluated passing `data` as an argument.\n * @param {string} str\n * @param {Record<string, any>} data\n * @returns {string}\n */\nexport function template(str, data) {\n\treturn str.replace(templateRe, (str, key) => {\n\t\tlet value = data[key];\n\n\t\tif (value === undefined) {\n\t\t\tthrow new Error(`No value provided for variable ${str}`);\n\n\t\t} else if (typeof value === 'function') {\n\t\t\tvalue = value(data);\n\t\t}\n\t\treturn value;\n\t});\n}\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;AAMA,IAAW,SAAS;;;;;;AAOpB,SAAgB,MAAM,KAAK;CAC1B,IAAI,EAAE,iBAAiB,MACtB,IAAI,iBAAiB,EAAE;CAExB,OAAO,IAAI;AACZ;;;;;;;;;;;;AAaA,SAAgB,SAAS,IAAI,MAAM,SAAS;CAC3C,IAAI,MAAM;CAEV,SAAS,QAAQ;EAEhB,OAAO;EACP,IAAI,YAAY;GACf,UAAU,MAAM,SAAS,UAAU;GACnC,aAAa;EACd;CACD;CAEA,SAAS,UAAU,GAAG,MAAM;EAC3B,IAAI,MAEH,aAAa;OAEP;GAEN,GAAG,MAAM,SAAS,IAAI;GACtB,WAAW,OAAO,IAAI;GACtB,OAAO;EACR;CACD;CAEA,OAAO;AACR;;;;;;;;;;AAWA,SAAgB,QAAQ,GAAG,OAAO,YAAY;CAC7C,MAAM,MAAM,MAAM,IAClB,MAAM,MAAM,IACZ,IAAI,MAAM;CACV,OAAO,MAAM,OAAO,aAAa,MAAM,IAAI,OAAO,IAAI,KA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AEjD,IAAI,OAAO,UAAU,YAC3B,QAAQ,MAAM,IAAI;EAEnB,OAAO;CACR,CAAC;AACF"}
@@ -1,7 +1,6 @@
1
- import { getPropagationPath } from "./DomEvent.js";
2
- //#region src/dom/DomEvent.DoubleTap.js
1
+ // src/dom/DomEvent.DoubleTap.js
3
2
  function makeDblclick(ev) {
4
- let init = {
3
+ const init = {
5
4
  bubbles: ev.bubbles,
6
5
  cancelable: ev.cancelable,
7
6
  composed: ev.composed,
@@ -21,22 +20,20 @@ function makeDblclick(ev) {
21
20
  region: ev.region
22
21
  };
23
22
  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);
23
+ if (ev instanceof PointerEvent) newEvent = new PointerEvent("dblclick", {
24
+ ...init,
25
+ pointerId: ev.pointerId,
26
+ width: ev.width,
27
+ height: ev.height,
28
+ pressure: ev.pressure,
29
+ tangentialPressure: ev.tangentialPressure,
30
+ tiltX: ev.tiltX,
31
+ tiltY: ev.tiltY,
32
+ twist: ev.twist,
33
+ pointerType: ev.pointerType,
34
+ isPrimary: ev.isPrimary
35
+ });
36
+ else newEvent = new MouseEvent("dblclick", init);
40
37
  return newEvent;
41
38
  }
42
39
  const delay = 200;
@@ -50,15 +47,18 @@ const delay = 200;
50
47
  */
51
48
  function addDoubleTapListener(obj, handler) {
52
49
  obj.addEventListener("dblclick", handler);
53
- let last = 0, detail;
50
+ let last = 0, detail, pointerType;
51
+ function onPointerDown(ev) {
52
+ pointerType = ev.pointerType;
53
+ }
54
54
  function simDblclick(ev) {
55
55
  if (ev.detail !== 1) {
56
56
  detail = ev.detail;
57
57
  return;
58
58
  }
59
- if (ev.pointerType === "mouse" || ev.sourceCapabilities && !ev.sourceCapabilities.firesTouchEvents) return;
60
- const path = getPropagationPath(ev);
61
- if (path.some((el) => el instanceof HTMLLabelElement && el.attributes.for) && !path.some((el) => el instanceof HTMLInputElement || el instanceof HTMLSelectElement)) return;
59
+ if (pointerType === "mouse" || ev.sourceCapabilities && !ev.sourceCapabilities.firesTouchEvents) return;
60
+ const path = ev.composedPath();
61
+ if (path.some((el) => el instanceof HTMLLabelElement && el.htmlFor) && !path.some((el) => el instanceof HTMLInputElement || el instanceof HTMLSelectElement)) return;
62
62
  const now = Date.now();
63
63
  if (now - last <= delay) {
64
64
  detail++;
@@ -66,9 +66,11 @@ function addDoubleTapListener(obj, handler) {
66
66
  } else detail = 1;
67
67
  last = now;
68
68
  }
69
+ obj.addEventListener("pointerdown", onPointerDown, true);
69
70
  obj.addEventListener("click", simDblclick);
70
71
  return {
71
72
  dblclick: handler,
73
+ onPointerDown,
72
74
  simDblclick
73
75
  };
74
76
  }
@@ -80,9 +82,9 @@ function addDoubleTapListener(obj, handler) {
80
82
  */
81
83
  function removeDoubleTapListener(obj, handlers) {
82
84
  obj.removeEventListener("dblclick", handlers.dblclick);
85
+ obj.removeEventListener("pointerdown", handlers.onPointerDown, true);
83
86
  obj.removeEventListener("click", handlers.simDblclick);
84
87
  }
85
- //#endregion
86
88
  export { addDoubleTapListener, removeDoubleTapListener };
87
89
 
88
90
  //# sourceMappingURL=DomEvent.DoubleTap.js.map