maplair 4.1.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/dist/esm/Maplair.js +5 -4
- package/dist/esm/Maplair.js.map +1 -1
- package/dist/esm/_virtual/_rolldown/runtime.js +1 -2
- package/dist/esm/control/AttributionControl.js +1 -2
- package/dist/esm/control/ButtonControl.js +1 -2
- package/dist/esm/control/ContextMenu.js +1 -2
- package/dist/esm/control/Control.js +1 -2
- package/dist/esm/control/FullscreenControl.js +1 -2
- package/dist/esm/control/LayersControl.js +27 -31
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +1 -2
- package/dist/esm/control/MiniMapControl.js +1 -2
- package/dist/esm/control/RotateControl.js +1 -2
- package/dist/esm/control/ScaleControl.js +1 -2
- package/dist/esm/control/SearchControl.js +1 -2
- package/dist/esm/control/SideBySideControl.js +1 -2
- package/dist/esm/control/TextControl.js +1 -2
- package/dist/esm/control/TimeControl.js +1 -2
- package/dist/esm/control/ZoomControl.js +18 -29
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +2 -9
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +2 -2
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +10 -3
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/I18n.js +1 -2
- package/dist/esm/core/Util.js +2 -3
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +1 -2
- package/dist/esm/dom/DomEvent.PointerEvents.js +1 -2
- package/dist/esm/dom/DomEvent.js +10 -18
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +1 -2
- package/dist/esm/dom/Draggable.js +4 -3
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +1 -2
- package/dist/esm/geo/LatLng.js +1 -2
- package/dist/esm/geo/LatLngBounds.js +9 -15
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geo/crs/CRS.js +1 -2
- package/dist/esm/geo/crs/EPSG3395.js +4 -5
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +4 -5
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +3 -4
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +1 -2
- package/dist/esm/geo/crs/SimpleCRS.js +3 -4
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +4 -5
- package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
- package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +3 -4
- package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
- package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +4 -5
- package/dist/esm/geo/projection/SphericalMercatorProjection.js.map +1 -0
- package/dist/esm/geometry/Bounds.js +10 -14
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +2 -3
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/Point.js +1 -2
- package/dist/esm/geometry/PolyUtil.js +17 -25
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +1 -2
- package/dist/esm/layer/BlanketOverlay.js +1 -2
- package/dist/esm/layer/Classification.js +1 -2
- package/dist/esm/layer/DivOverlay.js +2 -3
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/FeatureGroup.js +5 -4
- package/dist/esm/layer/FeatureGroup.js.map +1 -1
- package/dist/esm/layer/GeoJSON.Load.js +1 -2
- package/dist/esm/layer/GeoJSON.js +8 -10
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +1 -2
- package/dist/esm/layer/HeatLayer.js +2 -3
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +2 -3
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +1 -2
- package/dist/esm/layer/LayerGroup.js +2 -3
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +9 -16
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +1 -2
- package/dist/esm/layer/Tooltip.js +16 -17
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +1 -2
- package/dist/esm/layer/marker/DefaultIcon.js +29 -7
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +1 -2
- package/dist/esm/layer/marker/Icon.js +2 -2
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +43 -4
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +4 -6
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +54 -14
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +1 -2
- package/dist/esm/layer/marker/SvgIcon.js +1 -2
- package/dist/esm/layer/tile/GridLayer.js +4 -4
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +8 -8
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +5 -4
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +7 -14
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +5 -3
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +2 -3
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +1 -2
- package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
- package/dist/esm/layer/vector/Path.js +1 -2
- package/dist/esm/layer/vector/Polygon.js +2 -3
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +1 -2
- package/dist/esm/layer/vector/Polyline.js +2 -3
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Rectangle.js +1 -2
- package/dist/esm/layer/vector/Renderer.getRenderer.js +4 -5
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.js +1 -2
- package/dist/esm/layer/vector/SVG.js +7 -4
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Hash.js +1 -2
- package/dist/esm/map/Map.Rotation.js +31 -16
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +10 -17
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +1 -2
- package/dist/esm/map/handler/BoxZoomHandler.js +20 -40
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +1 -2
- package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
- package/dist/esm/map/handler/DragHandler.js +1 -2
- package/dist/esm/map/handler/KeyboardHandler.js +23 -43
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +1 -2
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +1 -2
- package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
- package/dist/esm/map/handler/TapHoldHandler.js +1 -2
- package/dist/esm/package.js +2 -3
- package/dist/maplair-global-src.js +489 -613
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +2 -2
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +485 -609
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1263
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/package.json +4 -8
- package/src/Maplair.all.js +0 -1
- package/src/control/LayersControl.js +39 -52
- package/src/control/ZoomControl.js +17 -31
- package/src/core/Class.js +5 -14
- package/src/core/Events.js +2 -0
- package/src/core/Handler.js +11 -1
- package/src/core/Util.js +1 -1
- package/src/dom/DomEvent.js +9 -19
- package/src/dom/Draggable.js +5 -1
- package/src/geo/LatLngBounds.js +8 -15
- package/src/geo/crs/EPSG3395.js +3 -3
- package/src/geo/crs/EPSG3857.js +3 -3
- package/src/geo/crs/EPSG4326.js +2 -2
- package/src/geo/crs/SimpleCRS.js +2 -2
- package/src/geo/index.js +1 -2
- package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +1 -1
- package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +1 -1
- package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +1 -1
- package/src/geo/projection/index.js +5 -5
- package/src/geometry/Bounds.js +12 -17
- package/src/geometry/LineUtil.js +1 -1
- package/src/geometry/PolyUtil.js +23 -31
- package/src/layer/DivOverlay.js +1 -1
- package/src/layer/FeatureGroup.js +8 -2
- package/src/layer/GeoJSON.js +10 -13
- package/src/layer/HeatLayer.js +1 -1
- package/src/layer/ImageOverlay.js +2 -2
- package/src/layer/LayerGroup.js +1 -1
- package/src/layer/Popup.js +9 -19
- package/src/layer/Tooltip.js +19 -17
- package/src/layer/marker/DefaultIcon.js +33 -5
- package/src/layer/marker/Icon.js +2 -0
- package/src/layer/marker/Marker.Drag.js +53 -5
- package/src/layer/marker/Marker.Move.js +3 -4
- package/src/layer/marker/Marker.js +64 -13
- package/src/layer/tile/GridLayer.js +5 -2
- package/src/layer/tile/TileLayer.js +9 -6
- package/src/layer/tile/WMSTileLayer.js +5 -2
- package/src/layer/vector/Canvas.js +10 -14
- package/src/layer/vector/Circle.js +7 -1
- package/src/layer/vector/CircleMarker.js +2 -1
- package/src/layer/vector/Polygon.js +1 -1
- package/src/layer/vector/Polyline.js +1 -1
- package/src/layer/vector/Renderer.getRenderer.js +4 -3
- package/src/layer/vector/SVG.js +12 -2
- package/src/map/Map.Rotation.js +28 -4
- package/src/map/Map.js +17 -21
- package/src/map/handler/BoxZoomHandler.js +21 -42
- package/src/map/handler/KeyboardHandler.js +34 -53
- package/src/maplair.css +5 -0
- package/dist/esm/geo/projection/Projection.LonLat.js.map +0 -1
- package/dist/esm/geo/projection/Projection.Mercator.js.map +0 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +0 -1
- package/dist/esm/geo/projection/index.js +0 -14
- package/dist/esm/geo/projection/index.js.map +0 -1
- package/dist/esm/layer/marker/Marker.Rotation.js +0 -70
- package/dist/esm/layer/marker/Marker.Rotation.js.map +0 -1
- package/src/layer/marker/Marker.Rotation.js +0 -103
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { disableClickPropagation, disableScrollPropagation } from "../dom/DomEvent.js";
|
|
2
2
|
import { create } from "../dom/DomUtil.js";
|
|
3
3
|
import { Control } from "./Control.js";
|
|
4
|
-
|
|
4
|
+
// src/control/TextControl.js
|
|
5
5
|
/** @import {ControlOptions} from './Control.js' */
|
|
6
6
|
/**
|
|
7
7
|
* Options of `TextControl`.
|
|
@@ -75,7 +75,6 @@ var TextControl = class TextControl extends Control {
|
|
|
75
75
|
container.hidden = !content;
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
|
-
//#endregion
|
|
79
78
|
export { TextControl };
|
|
80
79
|
|
|
81
80
|
//# sourceMappingURL=TextControl.js.map
|
|
@@ -3,7 +3,7 @@ import { create } from "../dom/DomUtil.js";
|
|
|
3
3
|
import { Control } from "./Control.js";
|
|
4
4
|
import { I18n } from "../core/I18n.js";
|
|
5
5
|
import { ButtonControl } from "./ButtonControl.js";
|
|
6
|
-
|
|
6
|
+
// src/control/TimeControl.js
|
|
7
7
|
/** @import {ControlOptions} from './Control.js' */
|
|
8
8
|
/** @import {MaplairMap} from '../map/Map.js' */
|
|
9
9
|
/** @import {Layer} from '../layer/Layer.js' */
|
|
@@ -402,7 +402,6 @@ var TimeControl = class TimeControl extends Control {
|
|
|
402
402
|
return this;
|
|
403
403
|
}
|
|
404
404
|
};
|
|
405
|
-
//#endregion
|
|
406
405
|
export { TimeControl };
|
|
407
406
|
|
|
408
407
|
//# sourceMappingURL=TimeControl.js.map
|
|
@@ -2,7 +2,7 @@ import { disableClickPropagation, on, stop } from "../dom/DomEvent.js";
|
|
|
2
2
|
import { create } from "../dom/DomUtil.js";
|
|
3
3
|
import { Control } from "./Control.js";
|
|
4
4
|
import { I18n } from "../core/I18n.js";
|
|
5
|
-
|
|
5
|
+
// src/control/ZoomControl.js
|
|
6
6
|
/** @import {ControlOptions} from './Control.js' */
|
|
7
7
|
/** @import {MaplairMap} from '../map/Map.js' */
|
|
8
8
|
/**
|
|
@@ -56,8 +56,8 @@ var ZoomControl = class ZoomControl extends Control {
|
|
|
56
56
|
*/
|
|
57
57
|
onAdd(map) {
|
|
58
58
|
const zoomName = "maplair-control-zoom", container = create("div", `${zoomName} maplair-bar`), options = this.options;
|
|
59
|
-
this._zoomInButton = this._createButton(options.zoomInText, I18n.translate("Zoom in"), `${zoomName}-in`, container, this.
|
|
60
|
-
this._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate("Zoom out"), `${zoomName}-out`, container, this.
|
|
59
|
+
this._zoomInButton = this._createButton(options.zoomInText, I18n.translate("Zoom in"), `${zoomName}-in`, container, (e) => this._zoom(e, 1));
|
|
60
|
+
this._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate("Zoom out"), `${zoomName}-out`, container, (e) => this._zoom(e, -1));
|
|
61
61
|
this._updateDisabled();
|
|
62
62
|
map.on("zoomend zoomlevelschange", this._updateDisabled, this);
|
|
63
63
|
return container;
|
|
@@ -87,16 +87,11 @@ var ZoomControl = class ZoomControl extends Control {
|
|
|
87
87
|
this._updateDisabled();
|
|
88
88
|
return this;
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
_zoomOut(e) {
|
|
97
|
-
if (!this._disabled && this._map._zoom > this._map.getMinZoom()) {
|
|
98
|
-
this._map._setUserEvent(e);
|
|
99
|
-
this._map.zoomOut(this._map.options.zoomDelta * (e.shiftKey ? 3 : 1));
|
|
90
|
+
_zoom(e, dir) {
|
|
91
|
+
const map = this._map;
|
|
92
|
+
if (!this._disabled && (dir > 0 ? map._zoom < map.getMaxZoom() : map._zoom > map.getMinZoom())) {
|
|
93
|
+
map._setUserEvent(e);
|
|
94
|
+
map.zoomIn(dir * map.options.zoomDelta * (e.shiftKey ? 3 : 1));
|
|
100
95
|
}
|
|
101
96
|
}
|
|
102
97
|
_createButton(html, title, className, container, fn) {
|
|
@@ -106,24 +101,19 @@ var ZoomControl = class ZoomControl extends Control {
|
|
|
106
101
|
link.title = title;
|
|
107
102
|
link.setAttribute("aria-label", title);
|
|
108
103
|
disableClickPropagation(link);
|
|
109
|
-
on(link, "click",
|
|
110
|
-
|
|
111
|
-
|
|
104
|
+
on(link, "click", (e) => {
|
|
105
|
+
stop(e);
|
|
106
|
+
fn.call(this, e);
|
|
107
|
+
this._refocusOnMap(e);
|
|
108
|
+
});
|
|
112
109
|
return link;
|
|
113
110
|
}
|
|
114
111
|
_updateDisabled() {
|
|
115
|
-
const map = this._map
|
|
116
|
-
this._zoomInButton.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (this._disabled || map._zoom === map.getMinZoom()) {
|
|
121
|
-
this._zoomOutButton.classList.add(className);
|
|
122
|
-
this._zoomOutButton.setAttribute("aria-disabled", "true");
|
|
123
|
-
}
|
|
124
|
-
if (this._disabled || map._zoom === map.getMaxZoom()) {
|
|
125
|
-
this._zoomInButton.classList.add(className);
|
|
126
|
-
this._zoomInButton.setAttribute("aria-disabled", "true");
|
|
112
|
+
const map = this._map;
|
|
113
|
+
for (const [button, limit] of [[this._zoomInButton, map.getMaxZoom()], [this._zoomOutButton, map.getMinZoom()]]) {
|
|
114
|
+
const disabled = this._disabled || map._zoom === limit;
|
|
115
|
+
button.classList.toggle("maplair-disabled", disabled);
|
|
116
|
+
button.setAttribute("aria-disabled", `${disabled}`);
|
|
127
117
|
}
|
|
128
118
|
}
|
|
129
119
|
/**
|
|
@@ -141,7 +131,6 @@ var ZoomControl = class ZoomControl extends Control {
|
|
|
141
131
|
});
|
|
142
132
|
}
|
|
143
133
|
};
|
|
144
|
-
//#endregion
|
|
145
134
|
export { ZoomControl };
|
|
146
135
|
|
|
147
136
|
//# sourceMappingURL=ZoomControl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZoomControl.js","names":["DomUtil.create"
|
|
1
|
+
{"version":3,"file":"ZoomControl.js","names":["DomUtil.create"],"sources":["../../../src/control/ZoomControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * Options of `ZoomControl`.\n * @typedef {object} ZoomControlOptions\n * @property {string} [position='topleft'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {string} [zoomInText='<span aria-hidden=\"true\">+</span>'] The text set on\n * the 'zoom in' button.\n * @property {string} [zoomOutText='<span aria-hidden=\"true\">−</span>'] The text\n * set on the 'zoom out' button.\n * @extends ControlOptions\n */\n\n/**\n * Map options of `ZoomControl`.\n * @typedef {object} ZoomControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [zoomControl=true] Whether a [zoom control](#control-zoom) is\n * added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `ZoomControl`.\n * @typedef {object} ZoomControlMapProperties\n * @lends MaplairMap\n * @property {ZoomControl} zoomControl The default zoom control (only available if the\n * [`zoomControl` option](#map-zoomcontrol) was `true` when creating the map).\n */\n\n/**\n * A basic zoom control with two buttons (zoom in and zoom out). It is put on the map by\n * default unless you set its [`zoomControl` option](#map-zoomcontrol) to `false`.\n */\nexport class ZoomControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft',\n\t\tzoomInText: '<span aria-hidden=\"true\">+</span>',\n\t\tzoomOutText: '<span aria-hidden=\"true\">−</span>',\n\t};\n\n\t/**\n\t * Creates a zoom control.\n\t * @param {...ZoomControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(ZoomControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tconst zoomName = 'maplair-control-zoom',\n\t\tcontainer = DomUtil.create('div', `${zoomName} maplair-bar`),\n\t\toptions = this.options;\n\n\t\tthis._zoomInButton = this._createButton(options.zoomInText, I18n.translate('Zoom in'),\n\t\t\t`${zoomName}-in`, container, e => this._zoom(e, 1));\n\t\tthis._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate('Zoom out'),\n\t\t\t`${zoomName}-out`, container, e => this._zoom(e, -1));\n\n\t\tthis._updateDisabled();\n\t\tmap.on('zoomend zoomlevelschange', this._updateDisabled, this);\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off('zoomend zoomlevelschange', this._updateDisabled, this);\n\t}\n\n\t/**\n\t * Disables the zoom buttons.\n\t * @returns {this}\n\t */\n\tdisable() {\n\t\tthis._disabled = true;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Enables the zoom buttons (if the zoom level allows).\n\t * @returns {this}\n\t */\n\tenable() {\n\t\tthis._disabled = false;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\t_zoom(e, dir) {\n\t\tconst map = this._map;\n\t\tif (!this._disabled && (dir > 0 ? map._zoom < map.getMaxZoom() : map._zoom > map.getMinZoom())) {\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap.zoomIn(dir * map.options.zoomDelta * (e.shiftKey ? 3 : 1));\n\t\t}\n\t}\n\n\t_createButton(html, title, className, container, fn) {\n\t\tconst link = DomUtil.create('button', className, container);\n\t\tlink.type = 'button';\n\t\tlink.innerHTML = html;\n\t\tlink.title = title;\n\t\tlink.setAttribute('aria-label', title);\n\n\t\tDomEvent.disableClickPropagation(link);\n\t\tDomEvent.on(link, 'click', (e) => {\n\t\t\tDomEvent.stop(e);\n\t\t\tfn.call(this, e);\n\t\t\tthis._refocusOnMap(e);\n\t\t});\n\n\t\treturn link;\n\t}\n\n\t_updateDisabled() {\n\t\tconst map = this._map;\n\t\tfor (const [button, limit] of [[this._zoomInButton, map.getMaxZoom()], [this._zoomOutButton, map.getMinZoom()]]) {\n\t\t\tconst disabled = this._disabled || map._zoom === limit;\n\t\t\tbutton.classList.toggle('maplair-disabled', disabled);\n\t\t\tbutton.setAttribute('aria-disabled', `${disabled}`);\n\t\t}\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tzoomControl: true\n\t\t});\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tif (this.options.zoomControl) {\n\t\t\t\tthis.zoomControl = new ZoomControl();\n\t\t\t\tthis.addControl(this.zoomControl);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;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Z,KAAK,YAAY;EACjB,KAAK,QAAQ;EACb,KAAK,aAAa,cAAc,KAAK;EAErC,wBAAiC,IAAI;EACrC,GAAY,MAAM,UAAU,MAAM;GACjC,KAAc,CAAC;GACf,GAAG,KAAK,MAAM,CAAC;GACf,KAAK,cAAc,CAAC;EACrB,CAAC;EAED,OAAO;CACR;CAEA,kBAAkB;EACjB,MAAM,MAAM,KAAK;EACjB,KAAK,MAAM,CAAC,QAAQ,UAAU,CAAC,CAAC,KAAK,eAAe,IAAI,WAAW,CAAC,GAAG,CAAC,KAAK,gBAAgB,IAAI,WAAW,CAAC,CAAC,GAAG;GAChH,MAAM,WAAW,KAAK,aAAa,IAAI,UAAU;GACjD,OAAO,UAAU,OAAO,oBAAoB,QAAQ;GACpD,OAAO,aAAa,iBAAiB,GAAG,UAAU;EACnD;CACD;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,aAAa,KACd,CAAC;EAED,WAAW,YAAY,WAAY;GAClC,IAAI,KAAK,QAAQ,aAAa;IAC7B,KAAK,cAAc,IAAI,YAAY;IACnC,KAAK,WAAW,KAAK,WAAW;GACjC;EACD,CAAC;CACF;AACD"}
|
package/dist/esm/core/Class.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setOptions } from "./Util.js";
|
|
2
|
-
|
|
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.
|
|
@@ -157,15 +157,9 @@ var Class = class {
|
|
|
157
157
|
* @returns {T}
|
|
158
158
|
*/
|
|
159
159
|
static include(props) {
|
|
160
|
-
for (const k of
|
|
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
161
|
if (props.options) this.mergeOptions(props.options);
|
|
162
162
|
return this;
|
|
163
|
-
function* getAllMethodNames(obj) {
|
|
164
|
-
do {
|
|
165
|
-
if (obj === Object || obj === Object.prototype) break;
|
|
166
|
-
for (const k of Object.getOwnPropertyNames(obj)) yield k;
|
|
167
|
-
} while ((obj = Object.getPrototypeOf(obj)) !== null);
|
|
168
|
-
}
|
|
169
163
|
}
|
|
170
164
|
/**
|
|
171
165
|
* [Merges `options`](#class-options) into the `defaultOptions` of the class.
|
|
@@ -230,7 +224,6 @@ var Class = class {
|
|
|
230
224
|
return this;
|
|
231
225
|
}
|
|
232
226
|
};
|
|
233
|
-
//#endregion
|
|
234
227
|
export { Class };
|
|
235
228
|
|
|
236
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 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 (const k of
|
|
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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e,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"}
|
package/dist/esm/core/Events.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { falseFn, splitWords, stamp } from "./Util.js";
|
|
2
2
|
import { Class } from "./Class.js";
|
|
3
|
-
|
|
3
|
+
// src/core/Events.js
|
|
4
4
|
const warnedEvents = /* @__PURE__ */ new Set();
|
|
5
5
|
/** @import {LatLng} from '../geo/LatLng.js' */
|
|
6
6
|
/** @import {LatLngBounds} from '../geo/LatLngBounds.js' */
|
|
@@ -382,12 +382,12 @@ var Evented = class Evented extends Class {
|
|
|
382
382
|
}
|
|
383
383
|
_propagateEvent(e) {
|
|
384
384
|
for (const p of Object.values(this._eventParents ?? {})) p.fire(e.type, {
|
|
385
|
+
layer: e.target,
|
|
385
386
|
propagatedFrom: e.target,
|
|
386
387
|
...e
|
|
387
388
|
}, true);
|
|
388
389
|
}
|
|
389
390
|
};
|
|
390
|
-
//#endregion
|
|
391
391
|
export { Evented };
|
|
392
392
|
|
|
393
393
|
//# 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\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,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3B,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\t// `layer` is the Leaflet 1 name of `propagatedFrom`, left out of the types to steer new code to the new one\n\t\t\tp.fire(e.type, {\n\t\t\t\tlayer: e.target,\n\t\t\t\tpropagatedFrom: e.target,\n\t\t\t\t...e\n\t\t\t}, true);\n\t\t}\n\t}\n};\n"],"mappings":";;;AAGA,MAAM,+BAAe,IAAI,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuM7B,IAAa,UAAb,MAAa,gBAAgB,MAAM;;;;;;;;;;;;CAYlC,GAAG,OAAO,IAAI,SAAS;EAGtB,IAAI,OAAO,UAAU,UACpB,KAAK,MAAM,CAAC,MAAM,MAAM,OAAO,QAAQ,KAAK,GAG3C,KAAK,IAAI,MAAM,GAAG,EAAE;OAKrB,KAAK,MAAM,QAAQA,WAAgB,KAAK,GACvC,KAAK,IAAI,MAAM,IAAI,OAAO;EAI5B,OAAO;CACR;;;;;;;;;;;;;CAcA,IAAI,OAAO,IAAI,SAAS;EAEvB,IAAI,CAAC,UAAU,QAAQ;GAEtB,OAAO,KAAK;GACZ,OAAO,KAAK;EAEb,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OAAO;CACR;CAEA,gBAAgB,GAAG;EAClB,KAAK,MAAM,KAAK,OAAO,OAAO,KAAK,iBAAiB,CAAC,CAAC,GAErD,EAAE,KAAK,EAAE,MAAM;GACd,OAAO,EAAE;GACT,gBAAgB,EAAE;GAClB,GAAG;EACJ,GAAG,IAAI;CAET;AACD"}
|
package/dist/esm/core/Handler.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Class } from "./Class.js";
|
|
2
|
-
|
|
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`
|
|
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
|
|
@@ -49,6 +49,14 @@ var Handler = class Handler extends Class {
|
|
|
49
49
|
return !!this._enabled;
|
|
50
50
|
}
|
|
51
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
|
+
/**
|
|
52
60
|
* Adds a new handler of this class to the given map with the given name, which is
|
|
53
61
|
* then available as the property of the map with this name.
|
|
54
62
|
* @template {typeof Handler} T
|
|
@@ -62,7 +70,6 @@ var Handler = class Handler extends Class {
|
|
|
62
70
|
return this;
|
|
63
71
|
}
|
|
64
72
|
};
|
|
65
|
-
//#endregion
|
|
66
73
|
export { Handler };
|
|
67
74
|
|
|
68
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`
|
|
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"}
|
package/dist/esm/core/I18n.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { template } from "./Util.js";
|
|
2
|
-
|
|
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
|
package/dist/esm/core/Util.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
-
|
|
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
|
|
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
|
|
@@ -139,7 +139,6 @@ function template(str, data) {
|
|
|
139
139
|
return value;
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
|
-
//#endregion
|
|
143
142
|
export { Util_exports, falseFn, formatNum, lastId, setOptions, splitWords, stamp, template, throttle, wrapNum };
|
|
144
143
|
|
|
145
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
|
|
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,O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;;;;;;;AAWnB,SAAgB,SAAS,KAAK,MAAM;CACnC,OAAO,IAAI,QAAQ,aAAa,KAAK,QAAQ;EAC5C,IAAI,QAAQ,KAAK;EAEjB,IAAI,UAAU,KAAA,GACb,MAAM,IAAI,MAAM,kCAAkC,KAAK;OAEjD,IAAI,OAAO,UAAU,YAC3B,QAAQ,MAAM,IAAI;EAEnB,OAAO;CACR,CAAC;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/dom/DomEvent.DoubleTap.js
|
|
2
2
|
function makeDblclick(ev) {
|
|
3
3
|
const init = {
|
|
4
4
|
bubbles: ev.bubbles,
|
|
@@ -85,7 +85,6 @@ function removeDoubleTapListener(obj, handlers) {
|
|
|
85
85
|
obj.removeEventListener("pointerdown", handlers.onPointerDown, true);
|
|
86
86
|
obj.removeEventListener("click", handlers.simDblclick);
|
|
87
87
|
}
|
|
88
|
-
//#endregion
|
|
89
88
|
export { addDoubleTapListener, removeDoubleTapListener };
|
|
90
89
|
|
|
91
90
|
//# sourceMappingURL=DomEvent.DoubleTap.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
-
|
|
2
|
+
// src/dom/DomEvent.PointerEvents.js
|
|
3
3
|
var DomEvent_PointerEvents_exports = /* @__PURE__ */ __exportAll({
|
|
4
4
|
disablePointerDetection: () => disablePointerDetection,
|
|
5
5
|
enablePointerDetection: () => enablePointerDetection,
|
|
@@ -50,7 +50,6 @@ function _onDelete(e) {
|
|
|
50
50
|
function getPointers() {
|
|
51
51
|
return [...activePointers.values()];
|
|
52
52
|
}
|
|
53
|
-
//#endregion
|
|
54
53
|
export { DomEvent_PointerEvents_exports, disablePointerDetection, enablePointerDetection, getPointers };
|
|
55
54
|
|
|
56
55
|
//# sourceMappingURL=DomEvent.PointerEvents.js.map
|