maplair 4.0.0-alpha.2 → 4.1.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 +140 -38
- package/LICENSE +1 -1
- package/README.md +10 -9
- package/dist/esm/Maplair.js +14 -14
- package/dist/esm/control/AttributionControl.js +24 -14
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +9 -11
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -3
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +9 -16
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +5 -7
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +144 -35
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +7 -9
- package/dist/esm/control/LegendControl.js.map +1 -1
- package/dist/esm/control/MiniMapControl.js +14 -16
- package/dist/esm/control/MiniMapControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +1 -3
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +7 -9
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SearchControl.js +100 -18
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +1 -3
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/TextControl.js +5 -7
- package/dist/esm/control/TextControl.js.map +1 -1
- package/dist/esm/control/TimeControl.js +408 -0
- package/dist/esm/control/TimeControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +5 -7
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +28 -37
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +21 -8
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +13 -11
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/Util.js +13 -1
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +25 -22
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +2 -16
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +8 -42
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +14 -68
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +17 -18
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +3 -25
- package/dist/esm/dom/PosAnimation.js.map +1 -1
- package/dist/esm/geo/LatLng.js +34 -6
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +19 -7
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geo/crs/CRS.js +4 -3
- package/dist/esm/geo/crs/CRS.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3395.js +1 -1
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +1 -1
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +1 -1
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +2 -2
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js +3 -3
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js +3 -3
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +3 -3
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +19 -7
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +36 -30
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/Point.js +23 -5
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +9 -28
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +6 -8
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +15 -20
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/GeoJSON.js +9 -145
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +75 -0
- package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
- package/dist/esm/layer/HeatLayer.js +15 -17
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +20 -26
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +8 -10
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/LayerGroup.js +51 -0
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +27 -43
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +2 -5
- package/dist/esm/layer/SVGOverlay.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +15 -17
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +12 -15
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DefaultIcon.js +15 -48
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +8 -10
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +9 -12
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +2 -3
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +63 -35
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +302 -0
- package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
- package/dist/esm/layer/marker/SvgIcon.js +6 -8
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +86 -98
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +28 -36
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +28 -23
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +1 -3
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +2 -2
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +17 -7
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +2 -3
- package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +27 -20
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +20 -4
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +2 -2
- package/dist/esm/layer/vector/Polyline.js +24 -8
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +14 -13
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +5 -5
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +15 -11
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +135 -129
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +5 -7
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +6 -8
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +20 -20
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +37 -37
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +12 -3
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -4
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +12 -5
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +6326 -5625
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +3 -3
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +9010 -8290
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +148 -98
- package/dist/maplair.js +3 -3
- package/dist/maplair.js.map +1 -1
- package/i18n/cs.json +6 -0
- package/i18n/de.json +6 -0
- package/i18n/en.json +6 -0
- package/i18n/es.json +6 -0
- package/i18n/fr.json +6 -0
- package/i18n/hu.json +6 -0
- package/i18n/it.json +6 -0
- package/i18n/rm.json +6 -0
- package/i18n/sk.json +6 -0
- package/i18n/sl.json +6 -0
- package/package.json +12 -14
- package/src/control/AttributionControl.js +25 -18
- package/src/control/ButtonControl.js +9 -11
- package/src/control/ContextMenu.js +3 -5
- package/src/control/Control.js +9 -19
- package/src/control/FullscreenControl.js +5 -7
- package/src/control/LayersControl.js +159 -36
- package/src/control/LegendControl.js +7 -9
- package/src/control/MiniMapControl.js +9 -11
- package/src/control/RotateControl.js +3 -5
- package/src/control/ScaleControl.js +7 -9
- package/src/control/SearchControl.js +104 -21
- package/src/control/SideBySideControl.js +3 -5
- package/src/control/TextControl.js +5 -7
- package/src/control/TimeControl.js +471 -0
- package/src/control/ZoomControl.js +5 -7
- package/src/control/index.js +1 -0
- package/src/core/Class.js +35 -34
- package/src/core/Events.js +22 -3
- package/src/core/Handler.js +14 -12
- package/src/core/Util.js +19 -1
- package/src/core/index.js +0 -1
- package/src/dom/DomEvent.DoubleTap.js +18 -10
- package/src/dom/DomEvent.PointerEvents.js +3 -26
- package/src/dom/DomEvent.js +8 -66
- package/src/dom/DomUtil.js +22 -78
- package/src/dom/Draggable.js +27 -22
- package/src/dom/PosAnimation.js +3 -25
- package/src/dom/index.js +0 -1
- package/src/geo/LatLng.js +40 -4
- package/src/geo/LatLngBounds.js +20 -7
- package/src/geo/crs/CRS.js +4 -3
- package/src/geo/crs/EPSG3395.js +1 -1
- package/src/geo/crs/EPSG3857.js +1 -1
- package/src/geo/crs/EPSG4326.js +1 -1
- package/src/geo/crs/EarthCRS.js +2 -8
- package/src/geo/crs/SimpleCRS.js +1 -1
- package/src/geo/projection/Projection.LonLat.js +3 -3
- package/src/geo/projection/Projection.Mercator.js +3 -3
- package/src/geo/projection/Projection.SphericalMercator.js +3 -3
- package/src/geometry/Bounds.js +20 -7
- package/src/geometry/LineUtil.js +47 -48
- package/src/geometry/Point.js +24 -5
- package/src/geometry/PolyUtil.js +15 -44
- package/src/layer/BlanketOverlay.js +6 -10
- package/src/layer/DivOverlay.js +15 -26
- package/src/layer/GeoJSON.js +7 -205
- package/src/layer/GeoJSONUtil.js +85 -0
- package/src/layer/HeatLayer.js +9 -11
- package/src/layer/ImageOverlay.js +19 -30
- package/src/layer/Layer.js +8 -10
- package/src/layer/LayerGroup.js +71 -0
- package/src/layer/Popup.js +31 -46
- package/src/layer/SVGOverlay.js +1 -5
- package/src/layer/Tooltip.js +15 -19
- package/src/layer/VideoOverlay.js +12 -15
- package/src/layer/marker/DefaultIcon.js +15 -61
- package/src/layer/marker/DivIcon.js +10 -12
- package/src/layer/marker/Icon.js +9 -12
- package/src/layer/marker/Marker.Drag.js +1 -1
- package/src/layer/marker/Marker.Move.js +2 -3
- package/src/layer/marker/Marker.js +83 -41
- package/src/layer/marker/MarkerClusterGroup.js +370 -0
- package/src/layer/marker/SvgIcon.js +7 -9
- package/src/layer/marker/index.js +1 -0
- package/src/layer/tile/GridLayer.js +104 -134
- package/src/layer/tile/TileLayer.js +35 -43
- package/src/layer/tile/WMSTileLayer.js +26 -24
- package/src/layer/vector/Canvas.js +3 -5
- package/src/layer/vector/Circle.js +5 -2
- package/src/layer/vector/CircleMarker.js +17 -6
- package/src/layer/vector/Path.DashAnimation.js +1 -2
- package/src/layer/vector/Path.js +30 -21
- package/src/layer/vector/Polygon.js +28 -5
- package/src/layer/vector/Polyline.js +26 -7
- package/src/layer/vector/Renderer.getRenderer.js +17 -17
- package/src/layer/vector/SVG.js +5 -5
- package/src/map/Map.Rotation.js +19 -11
- package/src/map/Map.js +163 -154
- package/src/map/handler/BoxZoomHandler.js +9 -8
- package/src/map/handler/DisplaceHandler.js +6 -8
- package/src/map/handler/DragHandler.js +26 -29
- package/src/map/handler/KeyboardHandler.js +44 -50
- package/src/map/handler/PinchZoomHandler.js +16 -5
- package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
- package/src/map/handler/TapHoldHandler.js +15 -4
- package/src/map/index.js +1 -1
- package/src/maplair.css +148 -98
- package/dist/esm/core/Browser.js +0 -100
- package/dist/esm/core/Browser.js.map +0 -1
- package/dist/images/layers.svg +0 -1
- package/dist/images/marker-icon.svg +0 -1
- package/dist/images/marker-shadow.svg +0 -1
- package/src/core/Browser.js +0 -110
- package/src/images/layers.svg +0 -1
- package/src/images/marker-icon.svg +0 -1
- package/src/images/marker-shadow.svg +0 -1
|
@@ -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
|
|
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 getAllMethodNames(props)) {\n\t\t\tif (k !== 'constructor' && k !== 'options') {\n\t\t\t\tthis.prototype[k] = props[k];\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\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)) !== null);\n\t\t}\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}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GACmB;EAG7D,WAAgB,IAAI;CACrB;;;;;;;;;CAUA,cAAc,MAAM,KAAK,aAAa;EACrC,MAAM,OAAO,KAAK;EAClB,IAAI,SAAS,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"}
|
package/dist/esm/core/Events.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { falseFn, splitWords, stamp } from "./Util.js";
|
|
2
2
|
import { Class } from "./Class.js";
|
|
3
3
|
//#region 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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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.
|
|
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;
|
|
@@ -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 ?? {})) {\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+LA,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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K,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, {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AAA;EAIV,OAAO;CACR;CAGA,SAAS,MAAM,IAAI,SAAS;EAC3B,IAAI,CAAC,KAAK,SACT,OAAO;EAGR,MAAM,YAAY,KAAK,QAAQ;EAC/B,IAAI,CAAC,IACJ,OAAO,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"}
|
package/dist/esm/core/Handler.js
CHANGED
|
@@ -48,17 +48,19 @@ var Handler = class Handler extends Class {
|
|
|
48
48
|
enabled() {
|
|
49
49
|
return !!this._enabled;
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* @
|
|
56
|
-
* @param {
|
|
57
|
-
* @
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
map
|
|
61
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Adds a new handler of this class to the given map with the given name, which is
|
|
53
|
+
* then available as the property of the map with this name.
|
|
54
|
+
* @template {typeof Handler} T
|
|
55
|
+
* @this {T}
|
|
56
|
+
* @param {MaplairMap} map
|
|
57
|
+
* @param {string} name
|
|
58
|
+
* @returns {T}
|
|
59
|
+
*/
|
|
60
|
+
static addTo(map, name) {
|
|
61
|
+
map.addHandler(name, this);
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
62
64
|
};
|
|
63
65
|
//#endregion
|
|
64
66
|
export { Handler };
|
|
@@ -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
|
|
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\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;;;;;;;;;;CAWA,OAAO,MAAM,KAAK,MAAM;EACvB,IAAI,WAAW,MAAM,IAAI;EACzB,OAAO;CACR;AACD"}
|
package/dist/esm/core/Util.js
CHANGED
|
@@ -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"))
|
|
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}'`
|
|
@@ -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\
|
|
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\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,UA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B,OAAO,eAAe,CAAC,CAAC,CAAC,kBAAkB,OAAO,SAAS;EAGrG,gBAAgB,IAAI,KAAK,QAAQ;CAClC;CACA,OAAO;AACR;AAEA,MAAM,aAAa;;;;;;;;;;AAWnB,SAAgB,SAAS,KAAK,MAAM;CACnC,OAAO,IAAI,QAAQ,aAAa,KAAK,QAAQ;EAC5C,IAAI,QAAQ,KAAK;EAEjB,IAAI,UAAU,KAAA,GACb,MAAM,IAAI,MAAM,kCAAkC,KAAK;OAEjD,IAAI,OAAO,UAAU,YAC3B,QAAQ,MAAM,IAAI;EAEnB,OAAO;CACR,CAAC;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { getPropagationPath } from "./DomEvent.js";
|
|
2
1
|
//#region src/dom/DomEvent.DoubleTap.js
|
|
3
2
|
function makeDblclick(ev) {
|
|
4
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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 (
|
|
60
|
-
const path =
|
|
61
|
-
if (path.some((el) => el instanceof HTMLLabelElement && el.
|
|
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,6 +82,7 @@ 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
88
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DomEvent.DoubleTap.js","names":[
|
|
1
|
+
{"version":3,"file":"DomEvent.DoubleTap.js","names":[],"sources":["../../../src/dom/DomEvent.DoubleTap.js"],"sourcesContent":["/*\n * Extends the event handling code with double tap support for mobile browsers.\n *\n * Note: currently most browsers fire native dblclick, with only a few exceptions\n * (see https://github.com/Leaflet/Leaflet/issues/7012#issuecomment-595087386)\n */\n\nfunction makeDblclick(ev) {\n\tconst init = {\n\t\t// EventInit\n\t\tbubbles: ev.bubbles,\n\t\tcancelable: ev.cancelable,\n\t\tcomposed: ev.composed,\n\n\t\t// UIEventInit\n\t\tdetail: 2,\n\t\tview: ev.view,\n\n\t\t// mouseEventInit\n\t\tscreenX: ev.screenX,\n\t\tscreenY: ev.screenY,\n\t\tclientX: ev.clientX,\n\t\tclientY: ev.clientY,\n\t\tctrlKey: ev.ctrlKey,\n\t\tshiftKey: ev.shiftKey,\n\t\taltKey: ev.altKey,\n\t\tmetaKey: ev.metaKey,\n\t\tbutton: ev.button,\n\t\tbuttons: ev.buttons,\n\t\trelatedTarget: ev.relatedTarget,\n\t\tregion: ev.region,\n\t};\n\n\tlet newEvent;\n\t// The `click` event received should be a PointerEvent - but some\n\t// Firefox versions still use MouseEvent.\n\tif (ev instanceof PointerEvent) {\n\t\tnewEvent = new PointerEvent('dblclick', {\n\t\t\t...init,\n\t\t\tpointerId: ev.pointerId,\n\t\t\twidth: ev.width,\n\t\t\theight: ev.height,\n\t\t\tpressure: ev.pressure,\n\t\t\ttangentialPressure: ev.tangentialPressure,\n\t\t\ttiltX: ev.tiltX,\n\t\t\ttiltY: ev.tiltY,\n\t\t\ttwist: ev.twist,\n\t\t\tpointerType: ev.pointerType,\n\t\t\tisPrimary: ev.isPrimary,\n\t\t});\n\t} else {\n\t\tnewEvent = new MouseEvent('dblclick', init);\n\t}\n\treturn newEvent;\n}\n\nconst delay = 200;\n\n/**\n * Adds a `dblclick` listener which also handles double taps (simulating `dblclick`\n * on platforms which don't fire it for touch events).\n * @param {EventTarget} obj\n * @param {(ev: MouseEvent) => void} handler\n * @returns {{dblclick: (ev: MouseEvent) => void, simDblclick: (ev: PointerEvent) => void}}\n * The listeners to pass to `removeDoubleTapListener`.\n */\nexport function addDoubleTapListener(obj, handler) {\n\t// Most browsers handle double tap natively\n\tobj.addEventListener('dblclick', handler);\n\n\t// On some platforms the browser doesn't fire native dblclicks for touch events.\n\t// It seems that in all such cases `detail` property of `click` event is always `1`.\n\t// So here we rely on that fact to avoid excessive 'dblclick' simulation when not needed.\n\tlet last = 0,\n\tdetail,\n\tpointerType;\n\n\t// iOS Safari reports `pointerType: 'mouse'` on clicks from touch (WebKit bug 282988), so we take it from the\n\t// pointerdown instead; capturing so that it's seen even if a child (e.g. a control) stops its propagation.\n\tfunction onPointerDown(ev) {\n\t\tpointerType = ev.pointerType;\n\t}\n\n\tfunction simDblclick(ev) {\n\t\tif (ev.detail !== 1) {\n\t\t\tdetail = ev.detail; // keep in sync to avoid false dblclick in some cases\n\t\t\treturn;\n\t\t}\n\n\t\tif (pointerType === 'mouse' ||\n\t\t\t(ev.sourceCapabilities && !ev.sourceCapabilities.firesTouchEvents)) {\n\n\t\t\treturn;\n\t\t}\n\n\t\t// When clicking on an <input>, the browser generates a click on its\n\t\t// <label> (and vice versa) triggering two clicks in quick succession.\n\t\t// This ignores clicks on elements which are a label with a 'for'\n\t\t// attribute (or children of such a label), but not children of\n\t\t// a <input>.\n\t\tconst path = ev.composedPath();\n\t\tif (path.some(el => el instanceof HTMLLabelElement && el.htmlFor) &&\n\t\t\t!path.some(el => (\n\t\t\t\tel instanceof HTMLInputElement ||\n\t\t\t\t\tel instanceof HTMLSelectElement\n\t\t\t))\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst now = Date.now();\n\t\tif (now - last <= delay) {\n\t\t\tdetail++;\n\t\t\tif (detail === 2) {\n\t\t\t\tev.target.dispatchEvent(makeDblclick(ev));\n\t\t\t}\n\t\t} else {\n\t\t\tdetail = 1;\n\t\t}\n\t\tlast = now;\n\t}\n\n\tobj.addEventListener('pointerdown', onPointerDown, true);\n\tobj.addEventListener('click', simDblclick);\n\n\treturn {\n\t\tdblclick: handler,\n\t\tonPointerDown,\n\t\tsimDblclick\n\t};\n}\n\n/**\n * Removes the listeners added by `addDoubleTapListener`.\n * @param {EventTarget} obj\n * @param {{dblclick: (ev: MouseEvent) => void, simDblclick: (ev: PointerEvent) => void}} handlers\n * @returns {void}\n */\nexport function removeDoubleTapListener(obj, handlers) {\n\tobj.removeEventListener('dblclick', handlers.dblclick);\n\tobj.removeEventListener('pointerdown', handlers.onPointerDown, true);\n\tobj.removeEventListener('click', handlers.simDblclick);\n}\n"],"mappings":";AAOA,SAAS,aAAa,IAAI;CACzB,MAAM,OAAO;EAEZ,SAAS,GAAG;EACZ,YAAY,GAAG;EACf,UAAU,GAAG;EAGb,QAAQ;EACR,MAAM,GAAG;EAGT,SAAS,GAAG;EACZ,SAAS,GAAG;EACZ,SAAS,GAAG;EACZ,SAAS,GAAG;EACZ,SAAS,GAAG;EACZ,UAAU,GAAG;EACb,QAAQ,GAAG;EACX,SAAS,GAAG;EACZ,QAAQ,GAAG;EACX,SAAS,GAAG;EACZ,eAAe,GAAG;EAClB,QAAQ,GAAG;CACZ;CAEA,IAAI;CAGJ,IAAI,cAAc,cACjB,WAAW,IAAI,aAAa,YAAY;EACvC,GAAG;EACH,WAAW,GAAG;EACd,OAAO,GAAG;EACV,QAAQ,GAAG;EACX,UAAU,GAAG;EACb,oBAAoB,GAAG;EACvB,OAAO,GAAG;EACV,OAAO,GAAG;EACV,OAAO,GAAG;EACV,aAAa,GAAG;EAChB,WAAW,GAAG;CACf,CAAC;MAED,WAAW,IAAI,WAAW,YAAY,IAAI;CAE3C,OAAO;AACR;AAEA,MAAM,QAAQ;;;;;;;;;AAUd,SAAgB,qBAAqB,KAAK,SAAS;CAElD,IAAI,iBAAiB,YAAY,OAAO;CAKxC,IAAI,OAAO,GACX,QACA;CAIA,SAAS,cAAc,IAAI;EAC1B,cAAc,GAAG;CAClB;CAEA,SAAS,YAAY,IAAI;EACxB,IAAI,GAAG,WAAW,GAAG;GACpB,SAAS,GAAG;GACZ;EACD;EAEA,IAAI,gBAAgB,WAClB,GAAG,sBAAsB,CAAC,GAAG,mBAAmB,kBAEjD;EAQD,MAAM,OAAO,GAAG,aAAa;EAC7B,IAAI,KAAK,MAAK,OAAM,cAAc,oBAAoB,GAAG,OAAO,KAC/D,CAAC,KAAK,MAAK,OACV,cAAc,oBACb,cAAc,iBACf,GAED;EAGD,MAAM,MAAM,KAAK,IAAI;EACrB,IAAI,MAAM,QAAQ,OAAO;GACxB;GACA,IAAI,WAAW,GACd,GAAG,OAAO,cAAc,aAAa,EAAE,CAAC;EAE1C,OACC,SAAS;EAEV,OAAO;CACR;CAEA,IAAI,iBAAiB,eAAe,eAAe,IAAI;CACvD,IAAI,iBAAiB,SAAS,WAAW;CAEzC,OAAO;EACN,UAAU;EACV;EACA;CACD;AACD;;;;;;;AAQA,SAAgB,wBAAwB,KAAK,UAAU;CACtD,IAAI,oBAAoB,YAAY,SAAS,QAAQ;CACrD,IAAI,oBAAoB,eAAe,SAAS,eAAe,IAAI;CACnE,IAAI,oBAAoB,SAAS,SAAS,WAAW;AACtD"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
//#region src/dom/DomEvent.PointerEvents.js
|
|
3
3
|
var DomEvent_PointerEvents_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
-
cleanupPointers: () => cleanupPointers,
|
|
5
4
|
disablePointerDetection: () => disablePointerDetection,
|
|
6
5
|
enablePointerDetection: () => enablePointerDetection,
|
|
7
6
|
getPointers: () => getPointers
|
|
@@ -33,7 +32,7 @@ function disablePointerDetection(el) {
|
|
|
33
32
|
el.removeEventListener("pointercancel", _onDelete, { capture: true });
|
|
34
33
|
}
|
|
35
34
|
function _onSet(e) {
|
|
36
|
-
e.target.setPointerCapture(e.pointerId);
|
|
35
|
+
if (e.isTrusted) e.target.setPointerCapture(e.pointerId);
|
|
37
36
|
activePointers.set(e.pointerId, e);
|
|
38
37
|
}
|
|
39
38
|
function _onUpdate(e) {
|
|
@@ -51,20 +50,7 @@ function _onDelete(e) {
|
|
|
51
50
|
function getPointers() {
|
|
52
51
|
return [...activePointers.values()];
|
|
53
52
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Clears the detected pointers on the document.
|
|
56
|
-
* Note: This function should be not necessary to call, as the pointers are
|
|
57
|
-
* automatically cleared with `pointerup`, `pointercancel` and `pointerout` events.
|
|
58
|
-
* @group Pointer detection
|
|
59
|
-
* @returns {void}
|
|
60
|
-
*/
|
|
61
|
-
function cleanupPointers() {
|
|
62
|
-
for (const e of activePointers.values()) try {
|
|
63
|
-
e.target.releasePointerCapture(e.pointerId);
|
|
64
|
-
} catch {}
|
|
65
|
-
activePointers.clear();
|
|
66
|
-
}
|
|
67
53
|
//#endregion
|
|
68
|
-
export { DomEvent_PointerEvents_exports,
|
|
54
|
+
export { DomEvent_PointerEvents_exports, disablePointerDetection, enablePointerDetection, getPointers };
|
|
69
55
|
|
|
70
56
|
//# sourceMappingURL=DomEvent.PointerEvents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DomEvent.PointerEvents.js","names":[],"sources":["../../../src/dom/DomEvent.PointerEvents.js"],"sourcesContent":["// DomEvent.PointerEvents: detects the pointers that are currently active on the\n// document.\n\nconst activePointers = new Map();\n\n/**\n * Enables pointer detection and capture for the document.\n * @group Pointer detection\n * @param {EventTarget} el\n * @returns {void}\n */\nfunction enablePointerDetection(el) {\n\tel.addEventListener('pointerdown', _onSet, {capture: true});\n\tel.addEventListener('pointermove', _onUpdate, {capture: true});\n\tel.addEventListener('pointerup', _onDelete, {capture: true});\n\tel.addEventListener('pointercancel', _onDelete, {capture: true});\n\tactivePointers.clear();\n}\n\n/**\n * Disables pointer detection and capture for the document.\n * @group Pointer detection\n * @param {EventTarget} el\n * @returns {void}\n */\nfunction disablePointerDetection(el) {\n\tel.removeEventListener('pointerdown', _onSet, {capture: true});\n\tel.removeEventListener('pointermove', _onUpdate, {capture: true});\n\tel.removeEventListener('pointerup', _onDelete, {capture: true});\n\tel.removeEventListener('pointercancel', _onDelete, {capture: true});\n}\n\n//
|
|
1
|
+
{"version":3,"file":"DomEvent.PointerEvents.js","names":[],"sources":["../../../src/dom/DomEvent.PointerEvents.js"],"sourcesContent":["// DomEvent.PointerEvents: detects the pointers that are currently active on the\n// document.\n\nconst activePointers = new Map();\n\n/**\n * Enables pointer detection and capture for the document.\n * @group Pointer detection\n * @param {EventTarget} el\n * @returns {void}\n */\nfunction enablePointerDetection(el) {\n\tel.addEventListener('pointerdown', _onSet, {capture: true});\n\tel.addEventListener('pointermove', _onUpdate, {capture: true});\n\tel.addEventListener('pointerup', _onDelete, {capture: true});\n\tel.addEventListener('pointercancel', _onDelete, {capture: true});\n\tactivePointers.clear();\n}\n\n/**\n * Disables pointer detection and capture for the document.\n * @group Pointer detection\n * @param {EventTarget} el\n * @returns {void}\n */\nfunction disablePointerDetection(el) {\n\tel.removeEventListener('pointerdown', _onSet, {capture: true});\n\tel.removeEventListener('pointermove', _onUpdate, {capture: true});\n\tel.removeEventListener('pointerup', _onDelete, {capture: true});\n\tel.removeEventListener('pointercancel', _onDelete, {capture: true});\n}\n\n// capturing throws for synthetic pointers the browser doesn't know about, so only capture real ones\nfunction _onSet(e) {\n\tif (e.isTrusted) { e.target.setPointerCapture(e.pointerId); }\n\tactivePointers.set(e.pointerId, e);\n}\n\nfunction _onUpdate(e) {\n\tif (activePointers.has(e.pointerId)) {\n\t\tactivePointers.set(e.pointerId, e);\n\t}\n}\n\nfunction _onDelete(e) {\n\t// released already if the document has nested maps (e.g. an overview map)\n\tif (e.target.hasPointerCapture(e.pointerId)) {\n\t\te.target.releasePointerCapture(e.pointerId);\n\t}\n\tactivePointers.delete(e.pointerId);\n}\n\n/**\n * Returns the active pointers on the document.\n * @group Pointer detection\n * @returns {PointerEvent[]}\n */\nfunction getPointers() {\n\treturn [...activePointers.values()];\n}\n\nexport {\n\tenablePointerDetection,\n\tdisablePointerDetection,\n\tgetPointers\n};\n\n"],"mappings":";;;;;;;AAGA,MAAM,iCAAiB,IAAI,IAAI;;;;;;;AAQ/B,SAAS,uBAAuB,IAAI;CACnC,GAAG,iBAAiB,eAAe,QAAQ,EAAC,SAAS,KAAI,CAAC;CAC1D,GAAG,iBAAiB,eAAe,WAAW,EAAC,SAAS,KAAI,CAAC;CAC7D,GAAG,iBAAiB,aAAa,WAAW,EAAC,SAAS,KAAI,CAAC;CAC3D,GAAG,iBAAiB,iBAAiB,WAAW,EAAC,SAAS,KAAI,CAAC;CAC/D,eAAe,MAAM;AACtB;;;;;;;AAQA,SAAS,wBAAwB,IAAI;CACpC,GAAG,oBAAoB,eAAe,QAAQ,EAAC,SAAS,KAAI,CAAC;CAC7D,GAAG,oBAAoB,eAAe,WAAW,EAAC,SAAS,KAAI,CAAC;CAChE,GAAG,oBAAoB,aAAa,WAAW,EAAC,SAAS,KAAI,CAAC;CAC9D,GAAG,oBAAoB,iBAAiB,WAAW,EAAC,SAAS,KAAI,CAAC;AACnE;AAGA,SAAS,OAAO,GAAG;CAClB,IAAI,EAAE,WAAa,EAAE,OAAO,kBAAkB,EAAE,SAAS;CACzD,eAAe,IAAI,EAAE,WAAW,CAAC;AAClC;AAEA,SAAS,UAAU,GAAG;CACrB,IAAI,eAAe,IAAI,EAAE,SAAS,GACjC,eAAe,IAAI,EAAE,WAAW,CAAC;AAEnC;AAEA,SAAS,UAAU,GAAG;CAErB,IAAI,EAAE,OAAO,kBAAkB,EAAE,SAAS,GACzC,EAAE,OAAO,sBAAsB,EAAE,SAAS;CAE3C,eAAe,OAAO,EAAE,SAAS;AAClC;;;;;;AAOA,SAAS,cAAc;CACtB,OAAO,CAAC,GAAG,eAAe,OAAO,CAAC;AACnC"}
|
package/dist/esm/dom/DomEvent.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { splitWords, stamp } from "../core/Util.js";
|
|
3
3
|
import { Point } from "../geometry/Point.js";
|
|
4
|
-
import Browser_default from "../core/Browser.js";
|
|
5
4
|
import { addDoubleTapListener, removeDoubleTapListener } from "./DomEvent.DoubleTap.js";
|
|
6
5
|
import { DomEvent_PointerEvents_exports } from "./DomEvent.PointerEvents.js";
|
|
7
6
|
import { getScale } from "./DomUtil.js";
|
|
@@ -11,7 +10,6 @@ var DomEvent_exports = /* @__PURE__ */ __exportAll({
|
|
|
11
10
|
disableClickPropagation: () => disableClickPropagation,
|
|
12
11
|
disableScrollPropagation: () => disableScrollPropagation,
|
|
13
12
|
getPointerPosition: () => getPointerPosition,
|
|
14
|
-
getPropagationPath: () => getPropagationPath,
|
|
15
13
|
getWheelDelta: () => getWheelDelta,
|
|
16
14
|
getWheelPxFactor: () => getWheelPxFactor,
|
|
17
15
|
isExternalTarget: () => isExternalTarget,
|
|
@@ -72,28 +70,14 @@ function batchRemove(obj, filterFn) {
|
|
|
72
70
|
if (!filterFn || filterFn(type)) removeOne(obj, type, null, null, id);
|
|
73
71
|
}
|
|
74
72
|
}
|
|
75
|
-
const pointerSubst = {
|
|
76
|
-
pointerenter: "pointerover",
|
|
77
|
-
pointerleave: "pointerout",
|
|
78
|
-
wheel: typeof window === "undefined" ? false : !("onwheel" in window) && "mousewheel"
|
|
79
|
-
};
|
|
80
73
|
function addOne(obj, type, fn, context) {
|
|
81
74
|
const id = type + stamp(fn) + (context ? `_${stamp(context)}` : "");
|
|
82
75
|
if (obj[eventsKey] && obj[eventsKey][id]) return this;
|
|
83
76
|
let handler = function(e) {
|
|
84
77
|
return fn.call(context || obj, e);
|
|
85
78
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
else if ("addEventListener" in obj) {
|
|
89
|
-
if (type === "wheel" || type === "mousewheel") obj.addEventListener(pointerSubst[type] || type, handler, { passive: false });
|
|
90
|
-
else if (type === "pointerenter" || type === "pointerleave") {
|
|
91
|
-
handler = function(e) {
|
|
92
|
-
if (isExternalTarget(obj, e)) originalHandler(e);
|
|
93
|
-
};
|
|
94
|
-
obj.addEventListener(pointerSubst[type], handler, false);
|
|
95
|
-
} else obj.addEventListener(type, originalHandler, false);
|
|
96
|
-
} else obj.attachEvent(`on${type}`, handler);
|
|
79
|
+
if (type === "dblclick") handler = addDoubleTapListener(obj, handler);
|
|
80
|
+
else obj.addEventListener(type, handler, type === "wheel" ? { passive: false } : false);
|
|
97
81
|
obj[eventsKey] ??= {};
|
|
98
82
|
obj[eventsKey][id] = handler;
|
|
99
83
|
}
|
|
@@ -101,9 +85,8 @@ function removeOne(obj, type, fn, context, id) {
|
|
|
101
85
|
id ??= type + stamp(fn) + (context ? `_${stamp(context)}` : "");
|
|
102
86
|
const handler = obj[eventsKey] && obj[eventsKey][id];
|
|
103
87
|
if (!handler) return this;
|
|
104
|
-
if (
|
|
105
|
-
else
|
|
106
|
-
else obj.detachEvent(`on${type}`, handler);
|
|
88
|
+
if (type === "dblclick") removeDoubleTapListener(obj, handler);
|
|
89
|
+
else obj.removeEventListener(type, handler, false);
|
|
107
90
|
obj[eventsKey][id] = null;
|
|
108
91
|
}
|
|
109
92
|
/**
|
|
@@ -167,15 +150,6 @@ function stop(e) {
|
|
|
167
150
|
return this;
|
|
168
151
|
}
|
|
169
152
|
/**
|
|
170
|
-
* Returns an array containing the `HTMLElement`s that the given DOM event
|
|
171
|
-
* should propagate to (if not stopped).
|
|
172
|
-
* @param {Event} ev
|
|
173
|
-
* @returns {EventTarget[]}
|
|
174
|
-
*/
|
|
175
|
-
function getPropagationPath(ev) {
|
|
176
|
-
return ev.composedPath();
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
153
|
* Gets normalized pointer position from a DOM event relative to the
|
|
180
154
|
* `container` (border excluded) or to the whole page if not specified.
|
|
181
155
|
* @param {MouseEvent|Touch} e
|
|
@@ -192,8 +166,7 @@ function getPointerPosition(e, container) {
|
|
|
192
166
|
* @returns {number}
|
|
193
167
|
*/
|
|
194
168
|
function getWheelPxFactor() {
|
|
195
|
-
|
|
196
|
-
return Browser_default.linux && Browser_default.chrome ? ratio : Browser_default.mac ? ratio * 3 : ratio > 0 ? 2 * ratio : 1;
|
|
169
|
+
return window.devicePixelRatio * 2;
|
|
197
170
|
}
|
|
198
171
|
/**
|
|
199
172
|
* Gets normalized wheel delta from a wheel DOM event, in vertical
|
|
@@ -208,23 +181,16 @@ function getWheelDelta(e) {
|
|
|
208
181
|
}
|
|
209
182
|
/**
|
|
210
183
|
* Checks if the pointer really left/entered the element `el` (for
|
|
211
|
-
* `
|
|
184
|
+
* `pointerover`/`pointerout`).
|
|
212
185
|
* @internal
|
|
213
186
|
* @param {Node} el
|
|
214
187
|
* @param {MouseEvent} e
|
|
215
188
|
* @returns {boolean}
|
|
216
189
|
*/
|
|
217
190
|
function isExternalTarget(el, e) {
|
|
218
|
-
|
|
219
|
-
if (!related) return true;
|
|
220
|
-
try {
|
|
221
|
-
while (related && related !== el) related = related.parentNode;
|
|
222
|
-
} catch (err) {
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
225
|
-
return related !== el;
|
|
191
|
+
return !el.contains(e.relatedTarget);
|
|
226
192
|
}
|
|
227
193
|
//#endregion
|
|
228
|
-
export { DomEvent_exports, DomEvent_PointerEvents_exports as PointerEvents, disableClickPropagation, disableScrollPropagation, getPointerPosition,
|
|
194
|
+
export { DomEvent_exports, DomEvent_PointerEvents_exports as PointerEvents, disableClickPropagation, disableScrollPropagation, getPointerPosition, getWheelDelta, getWheelPxFactor, isExternalTarget, off, on, preventDefault, stop, stopPropagation };
|
|
229
195
|
|
|
230
196
|
//# sourceMappingURL=DomEvent.js.map
|