@interactjs/core
Advanced tools
Comparing version 1.10.21 to 1.10.22
import type { Scope } from '@interactjs/core/scope'; | ||
import type { Element } from '@interactjs/core/types'; | ||
import type { NativeEventTarget } from './NativeTypes'; | ||
declare module '@interactjs/core/scope' { | ||
@@ -8,8 +9,16 @@ interface Scope { | ||
} | ||
declare type Listener = (event: Event | FakeEvent) => any; | ||
interface EventOptions { | ||
capture: boolean; | ||
passive: boolean; | ||
} | ||
declare type PartialEventTarget = Partial<NativeEventTarget>; | ||
declare type ListenerEntry = { | ||
func: (event: Event | FakeEvent) => any; | ||
options: EventOptions; | ||
}; | ||
declare function install(scope: Scope): { | ||
add: (eventTarget: EventTarget, type: string, listener: Listener, optionalArg?: boolean | any) => void; | ||
remove: (eventTarget: EventTarget, type: string, listener?: 'all' | Listener, optionalArg?: boolean | any) => void; | ||
addDelegate: (selector: string, context: Node, type: string, listener: Listener, optionalArg?: any) => void; | ||
removeDelegate: (selector: string, context: Document | Element, type: string, listener?: Listener, optionalArg?: any) => void; | ||
add: (eventTarget: PartialEventTarget, type: string, listener: ListenerEntry['func'], optionalArg?: boolean | EventOptions) => void; | ||
remove: (eventTarget: PartialEventTarget, type: string, listener?: 'all' | ListenerEntry['func'], optionalArg?: boolean | EventOptions) => void; | ||
addDelegate: (selector: string, context: Node, type: string, listener: ListenerEntry['func'], optionalArg?: any) => void; | ||
removeDelegate: (selector: string, context: Document | Element, type: string, listener?: ListenerEntry['func'], optionalArg?: any) => void; | ||
delegateListener: (event: Event | FakeEvent, optionalArg?: any) => void; | ||
@@ -21,6 +30,3 @@ delegateUseCapture: (this: Element, event: Event | FakeEvent) => any; | ||
context: Node; | ||
listeners: Array<[Listener, { | ||
capture: boolean; | ||
passive: boolean; | ||
}]>; | ||
listeners: ListenerEntry[]; | ||
}[]; | ||
@@ -30,5 +36,5 @@ }; | ||
targets: { | ||
eventTarget: EventTarget; | ||
eventTarget: PartialEventTarget; | ||
events: { | ||
[type: string]: Listener[]; | ||
[type: string]: ListenerEntry[]; | ||
}; | ||
@@ -35,0 +41,0 @@ }[]; |
import * as arr from "../utils/arr.js"; | ||
import * as domUtils from "../utils/domUtils.js"; | ||
import extend from "../utils/extend.js"; | ||
import is from "../utils/is.js"; | ||
@@ -41,2 +40,3 @@ import pExtend from "../utils/pointerExtend.js"; | ||
function add(eventTarget, type, listener, optionalArg) { | ||
if (!eventTarget.addEventListener) return; | ||
const options = getOptions(optionalArg); | ||
@@ -57,5 +57,8 @@ let target = arr.find(targets, t => t.eventTarget === eventTarget); | ||
if (eventTarget.addEventListener && !arr.contains(target.events[type], listener)) { | ||
if (!arr.find(target.events[type], l => l.func === listener && optionsMatch(l.options, options))) { | ||
eventTarget.addEventListener(type, listener, eventsMethods.supportsOptions ? options : options.capture); | ||
target.events[type].push(listener); | ||
target.events[type].push({ | ||
func: listener, | ||
options | ||
}); | ||
} | ||
@@ -65,3 +68,3 @@ } | ||
function remove(eventTarget, type, listener, optionalArg) { | ||
const options = getOptions(optionalArg); | ||
if (!eventTarget.addEventListener || !eventTarget.removeEventListener) return; | ||
const targetIndex = arr.findIndex(targets, t => t.eventTarget === eventTarget); | ||
@@ -90,3 +93,4 @@ const target = targets[targetIndex]; | ||
for (let i = typeListeners.length - 1; i >= 0; i--) { | ||
remove(eventTarget, type, typeListeners[i], options); | ||
const entry = typeListeners[i]; | ||
remove(eventTarget, type, entry.func, entry.options); | ||
} | ||
@@ -96,4 +100,8 @@ | ||
} else { | ||
const options = getOptions(optionalArg); | ||
for (let i = 0; i < typeListeners.length; i++) { | ||
if (typeListeners[i] === listener) { | ||
const entry = typeListeners[i]; | ||
if (entry.func === listener && optionsMatch(entry.options, options)) { | ||
eventTarget.removeEventListener(type, listener, eventsMethods.supportsOptions ? options : options.capture); | ||
@@ -142,3 +150,6 @@ typeListeners.splice(i, 1); | ||
delegate.listeners.push([listener, options]); | ||
delegate.listeners.push({ | ||
func: listener, | ||
options | ||
}); | ||
} | ||
@@ -162,8 +173,5 @@ | ||
for (let i = listeners.length - 1; i >= 0; i--) { | ||
const [fn, { | ||
capture, | ||
passive | ||
}] = listeners[i]; // check if the listener functions and capture and passive flags match | ||
const entry = listeners[i]; // check if the listener functions and capture and passive flags match | ||
if (fn === listener && capture === options.capture && passive === options.passive) { | ||
if (entry.func === listener && optionsMatch(entry.options, options)) { | ||
// remove the listener from the array of listeners | ||
@@ -216,8 +224,5 @@ listeners.splice(i, 1); // if all listeners for this target have been removed | ||
for (const [fn, { | ||
capture, | ||
passive | ||
}] of listeners) { | ||
if (capture === options.capture && passive === options.passive) { | ||
fn(fakeEvent); | ||
for (const entry of listeners) { | ||
if (optionsMatch(entry.options, options)) { | ||
entry.func(fakeEvent); | ||
} | ||
@@ -273,8 +278,14 @@ } | ||
const options = extend({}, param); | ||
options.capture = !!param.capture; | ||
options.passive = !!param.passive; | ||
return options; | ||
return { | ||
capture: !!param.capture, | ||
passive: !!param.passive | ||
}; | ||
} | ||
function optionsMatch(a, b) { | ||
if (a === b) return true; | ||
if (typeof a === 'boolean') return !!b.capture === a && !!b.passive === false; | ||
return !!a.capture === !!b.capture && !!a.passive === !!b.passive; | ||
} | ||
export default { | ||
@@ -281,0 +292,0 @@ id: 'events', |
@@ -1,2 +0,2 @@ | ||
import*as e from"../utils/arr.prod.js";import*as t from"../utils/domUtils.prod.js";import s from"../utils/extend.prod.js";import n from"../utils/is.prod.js";import r from"../utils/pointerExtend.prod.js";import*as o from"../utils/pointerUtils.prod.js";class i{currentTarget;originalEvent;type;constructor(e){this.originalEvent=e,r(this,e)}preventOriginalDefault(){this.originalEvent.preventDefault()}stopPropagation(){this.originalEvent.stopPropagation()}stopImmediatePropagation(){this.originalEvent.stopImmediatePropagation()}}function a(e){if(!n.object(e))return{capture:!!e,passive:!1};const t=s({},e);return t.capture=!!e.capture,t.passive=!!e.passive,t}export default{id:"events",install(s){var r;const p=[],l={},c=[],u={add:v,remove:f,addDelegate(t,s,n,r,o){const i=a(o);if(!l[n]){l[n]=[];for(const e of c)v(e,n,d),v(e,n,g,!0)}const p=l[n];let u=e.find(p,(e=>e.selector===t&&e.context===s));u||(u={selector:t,context:s,listeners:[]},p.push(u)),u.listeners.push([r,i])},removeDelegate(e,t,s,n,r){const o=a(r),i=l[s];let p,c=!1;if(i)for(p=i.length-1;p>=0;p--){const r=i[p];if(r.selector===e&&r.context===t){const{listeners:e}=r;for(let r=e.length-1;r>=0;r--){const[a,{capture:l,passive:u}]=e[r];if(a===n&&l===o.capture&&u===o.passive){e.splice(r,1),e.length||(i.splice(p,1),f(t,s,d),f(t,s,g,!0)),c=!0;break}}if(c)break}}},delegateListener:d,delegateUseCapture:g,delegatedEvents:l,documents:c,targets:p,supportsOptions:!1,supportsPassive:!1};function v(t,s,n,r){const o=a(r);let i=e.find(p,(e=>e.eventTarget===t));i||(i={eventTarget:t,events:{}},p.push(i)),i.events[s]||(i.events[s]=[]),t.addEventListener&&!e.contains(i.events[s],n)&&(t.addEventListener(s,n,u.supportsOptions?o:o.capture),i.events[s].push(n))}function f(t,s,n,r){const o=a(r),i=e.findIndex(p,(e=>e.eventTarget===t)),l=p[i];if(!l||!l.events)return;if("all"===s){for(s in l.events)l.events.hasOwnProperty(s)&&f(t,s,"all");return}let c=!1;const v=l.events[s];if(v){if("all"===n){for(let e=v.length-1;e>=0;e--)f(t,s,v[e],o);return}for(let e=0;e<v.length;e++)if(v[e]===n){t.removeEventListener(s,n,u.supportsOptions?o:o.capture),v.splice(e,1),0===v.length&&(delete l.events[s],c=!0);break}}c&&!Object.keys(l.events).length&&p.splice(i,1)}function d(e,s){const r=a(s),p=new i(e),c=l[e.type],[u]=o.getEventTargets(e);let v=u;for(;n.element(v);){for(let e=0;e<c.length;e++){const s=c[e],{selector:n,context:o}=s;if(t.matchesSelector(v,n)&&t.nodeContains(o,u)&&t.nodeContains(o,v)){const{listeners:e}=s;p.currentTarget=v;for(const[t,{capture:s,passive:n}]of e)s===r.capture&&n===r.passive&&t(p)}}v=t.parentNode(v)}}function g(e){return d(e,!0)}return null==(r=s.document)||r.createElement("div").addEventListener("test",null,{get capture(){return u.supportsOptions=!0},get passive(){return u.supportsPassive=!0}}),s.events=u,u}}; | ||
import*as e from"../utils/arr.prod.js";import*as t from"../utils/domUtils.prod.js";import n from"../utils/is.prod.js";import s from"../utils/pointerExtend.prod.js";import*as o from"../utils/pointerUtils.prod.js";class r{currentTarget;originalEvent;type;constructor(e){this.originalEvent=e,s(this,e)}preventOriginalDefault(){this.originalEvent.preventDefault()}stopPropagation(){this.originalEvent.stopPropagation()}stopImmediatePropagation(){this.originalEvent.stopImmediatePropagation()}}function i(e){return n.object(e)?{capture:!!e.capture,passive:!!e.passive}:{capture:!!e,passive:!1}}function a(e,t){return e===t||("boolean"==typeof e?!!t.capture===e&&0==!!t.passive:!!e.capture==!!t.capture&&!!e.passive==!!t.passive)}export default{id:"events",install(s){var p;const l=[],c={},u=[],f={add:v,remove:d,addDelegate(t,n,s,o,r){const a=i(r);if(!c[s]){c[s]=[];for(const e of u)v(e,s,g),v(e,s,m,!0)}const p=c[s];let l=e.find(p,(e=>e.selector===t&&e.context===n));l||(l={selector:t,context:n,listeners:[]},p.push(l)),l.listeners.push({func:o,options:a})},removeDelegate(e,t,n,s,o){const r=i(o),p=c[n];let l,u=!1;if(p)for(l=p.length-1;l>=0;l--){const o=p[l];if(o.selector===e&&o.context===t){const{listeners:e}=o;for(let o=e.length-1;o>=0;o--){const i=e[o];if(i.func===s&&a(i.options,r)){e.splice(o,1),e.length||(p.splice(l,1),d(t,n,g),d(t,n,m,!0)),u=!0;break}}if(u)break}}},delegateListener:g,delegateUseCapture:m,delegatedEvents:c,documents:u,targets:l,supportsOptions:!1,supportsPassive:!1};function v(t,n,s,o){if(!t.addEventListener)return;const r=i(o);let p=e.find(l,(e=>e.eventTarget===t));p||(p={eventTarget:t,events:{}},l.push(p)),p.events[n]||(p.events[n]=[]),e.find(p.events[n],(e=>e.func===s&&a(e.options,r)))||(t.addEventListener(n,s,f.supportsOptions?r:r.capture),p.events[n].push({func:s,options:r}))}function d(t,n,s,o){if(!t.addEventListener||!t.removeEventListener)return;const r=e.findIndex(l,(e=>e.eventTarget===t)),p=l[r];if(!p||!p.events)return;if("all"===n){for(n in p.events)p.events.hasOwnProperty(n)&&d(t,n,"all");return}let c=!1;const u=p.events[n];if(u){if("all"===s){for(let e=u.length-1;e>=0;e--){const s=u[e];d(t,n,s.func,s.options)}return}{const e=i(o);for(let o=0;o<u.length;o++){const r=u[o];if(r.func===s&&a(r.options,e)){t.removeEventListener(n,s,f.supportsOptions?e:e.capture),u.splice(o,1),0===u.length&&(delete p.events[n],c=!0);break}}}}c&&!Object.keys(p.events).length&&l.splice(r,1)}function g(e,s){const p=i(s),l=new r(e),u=c[e.type],[f]=o.getEventTargets(e);let v=f;for(;n.element(v);){for(let e=0;e<u.length;e++){const n=u[e],{selector:s,context:o}=n;if(t.matchesSelector(v,s)&&t.nodeContains(o,f)&&t.nodeContains(o,v)){const{listeners:e}=n;l.currentTarget=v;for(const t of e)a(t.options,p)&&t.func(l)}}v=t.parentNode(v)}}function m(e){return g(e,!0)}return null==(p=s.document)||p.createElement("div").addEventListener("test",null,{get capture(){return f.supportsOptions=!0},get passive(){return f.supportsPassive=!0}}),s.events=f,f}}; | ||
//# sourceMappingURL=events.prod.js.map |
@@ -7,2 +7,6 @@ import type { Scope } from '@interactjs/core/scope'; | ||
declare type DeltaSource = 'page' | 'client'; | ||
declare const enum OnOffMethod { | ||
On = 0, | ||
Off = 1 | ||
} | ||
/** */ | ||
@@ -88,3 +92,3 @@ export declare class Interactable implements Partial<Eventable> { | ||
}>(iEvent: E): this; | ||
_onOff(method: 'on' | 'off', typeArg: EventTypes, listenerArg?: ListenersArg | null, options?: any): this; | ||
_onOff(method: OnOffMethod, typeArg: EventTypes, listenerArg?: ListenersArg | null, options?: any, filter?: (type: string) => boolean): this; | ||
/** | ||
@@ -91,0 +95,0 @@ * Binds a listener for an InteractEvent, pointerEvent or DOM event. |
@@ -8,8 +8,14 @@ /* eslint-disable no-dupe-class-members */ | ||
import is from "../utils/is.js"; | ||
import isNonNativeEvent from "../utils/isNonNativeEvent.js"; | ||
import normalizeListeners from "../utils/normalizeListeners.js"; | ||
import { getWindow } from "../utils/window.js"; | ||
import { Eventable } from './Eventable'; | ||
import isNonNativeEvent from './isNonNativeEvent'; | ||
var OnOffMethod; | ||
/** */ | ||
/** */ | ||
(function (OnOffMethod) { | ||
OnOffMethod[OnOffMethod["On"] = 0] = "On"; | ||
OnOffMethod[OnOffMethod["Off"] = 1] = "Off"; | ||
})(OnOffMethod || (OnOffMethod = {})); | ||
export class Interactable { | ||
@@ -66,8 +72,14 @@ /** @internal */ | ||
updatePerActionListeners(actionName, prev, cur) { | ||
var _this$_actions$map$ac; | ||
const actionFilter = (_this$_actions$map$ac = this._actions.map[actionName]) == null ? void 0 : _this$_actions$map$ac.filterEventType; | ||
const filter = type => (actionFilter == null || actionFilter(type)) && isNonNativeEvent(type, this._actions); | ||
if (is.array(prev) || is.object(prev)) { | ||
this.off(actionName, prev); | ||
this._onOff(OnOffMethod.Off, actionName, prev, undefined, filter); | ||
} | ||
if (is.array(cur) || is.object(cur)) { | ||
this.on(actionName, cur); | ||
this._onOff(OnOffMethod.On, actionName, cur, undefined, filter); | ||
} | ||
@@ -213,2 +225,20 @@ } | ||
} | ||
/** @internal */ | ||
getAllElements() { | ||
const { | ||
target | ||
} = this; | ||
if (is.string(target)) { | ||
return Array.from(this._context.querySelectorAll(target)); | ||
} | ||
if (is.func(target) && target.getAllElements) { | ||
return target.getAllElements(); | ||
} | ||
return is.element(target) ? [target] : []; | ||
} | ||
/** | ||
@@ -280,3 +310,3 @@ * Gets the selector context Node of the Interactable. The default is | ||
_onOff(method, typeArg, listenerArg, options) { | ||
_onOff(method, typeArg, listenerArg, options, filter) { | ||
if (is.object(typeArg) && !is.array(typeArg)) { | ||
@@ -287,4 +317,3 @@ options = listenerArg; | ||
const addRemove = method === 'on' ? 'add' : 'remove'; | ||
const listeners = normalizeListeners(typeArg, listenerArg); | ||
const listeners = normalizeListeners(typeArg, listenerArg, filter); | ||
@@ -299,9 +328,9 @@ for (let type in listeners) { | ||
if (isNonNativeEvent(type, this._actions)) { | ||
this.events[method](type, listener); | ||
this.events[method === OnOffMethod.On ? 'on' : 'off'](type, listener); | ||
} // delegated event | ||
else if (is.string(this.target)) { | ||
this._scopeEvents[`${addRemove}Delegate`](this.target, this._context, type, listener, options); | ||
this._scopeEvents[method === OnOffMethod.On ? 'addDelegate' : 'removeDelegate'](this.target, this._context, type, listener, options); | ||
} // remove listener from this Interactable's element | ||
else { | ||
this._scopeEvents[addRemove](this.target, type, listener, options); | ||
this._scopeEvents[method === OnOffMethod.On ? 'add' : 'remove'](this.target, type, listener, options); | ||
} | ||
@@ -326,3 +355,3 @@ } | ||
on(types, listener, options) { | ||
return this._onOff('on', types, listener, options); | ||
return this._onOff(OnOffMethod.On, types, listener, options); | ||
} | ||
@@ -342,3 +371,3 @@ /** | ||
off(types, listener, options) { | ||
return this._onOff('off', types, listener, options); | ||
return this._onOff(OnOffMethod.Off, types, listener, options); | ||
} | ||
@@ -372,2 +401,7 @@ /** | ||
for (const setting in options) { | ||
if (setting === 'getRect') { | ||
this.rectChecker(options.getRect); | ||
continue; | ||
} | ||
if (is.func(this[setting])) { | ||
@@ -374,0 +408,0 @@ ; |
@@ -1,2 +0,2 @@ | ||
import*as t from"../utils/arr.prod.js";import e from"../utils/browser.prod.js";import s from"../utils/clone.prod.js";import{getElementRect as o,matchesUpTo as n,nodeContains as i,trySelector as r}from"../utils/domUtils.prod.js";import c from"../utils/extend.prod.js";import h from"../utils/is.prod.js";import a from"../utils/normalizeListeners.prod.js";import{getWindow as l}from"../utils/window.prod.js";import{Eventable as p}from"./Eventable";import u from"./isNonNativeEvent";export class Interactable{get _defaults(){return{base:{},perAction:{},actions:{}}}options;_actions;target;events=new p;_context;_win;_doc;_scopeEvents;constructor(t,e,s,o){this._actions=e.actions,this.target=t,this._context=e.context||s,this._win=l(r(t)?this._context:t),this._doc=this._win.document,this._scopeEvents=o,this.set(e)}setOnEvents(t,e){return h.func(e.onstart)&&this.on(t+"start",e.onstart),h.func(e.onmove)&&this.on(t+"move",e.onmove),h.func(e.onend)&&this.on(t+"end",e.onend),h.func(e.oninertiastart)&&this.on(t+"inertiastart",e.oninertiastart),this}updatePerActionListeners(t,e,s){(h.array(e)||h.object(e))&&this.off(t,e),(h.array(s)||h.object(s))&&this.on(t,s)}setPerAction(e,o){const n=this._defaults;for(const i in o){const r=i,a=this.options[e],l=o[r];"listeners"===r&&this.updatePerActionListeners(e,a.listeners,l),h.array(l)?a[r]=t.from(l):h.plainObject(l)?(a[r]=c(a[r]||{},s(l)),h.object(n.perAction[r])&&"enabled"in n.perAction[r]&&(a[r].enabled=!1!==l.enabled)):h.bool(l)&&h.object(n.perAction[r])?a[r].enabled=l:a[r]=l}}getRect(t){return t=t||(h.element(this.target)?this.target:null),h.string(this.target)&&(t=t||this._context.querySelector(this.target)),o(t)}rectChecker(t){return h.func(t)?(this.getRect=e=>{const s=c({},t.apply(this,e));return"width"in s||(s.width=s.right-s.left,s.height=s.bottom-s.top),s},this):null===t?(delete this.getRect,this):this.getRect}_backCompatOption(t,e){if(r(e)||h.object(e)){this.options[t]=e;for(const s in this._actions.map)this.options[s][t]=e;return this}return this.options[t]}origin(t){return this._backCompatOption("origin",t)}deltaSource(t){return"page"===t||"client"===t?(this.options.deltaSource=t,this):this.options.deltaSource}context(){return this._context}inContext(t){return this._context===t.ownerDocument||i(this._context,t)}testIgnoreAllow(t,e,s){return!this.testIgnore(t.ignoreFrom,e,s)&&this.testAllow(t.allowFrom,e,s)}testAllow(t,e,s){return!t||!!h.element(s)&&(h.string(t)?n(s,t,e):!!h.element(t)&&i(t,s))}testIgnore(t,e,s){return!(!t||!h.element(s))&&(h.string(t)?n(s,t,e):!!h.element(t)&&i(t,s))}fire(t){return this.events.fire(t),this}_onOff(t,s,o,n){h.object(s)&&!h.array(s)&&(n=o,o=null);const i="on"===t?"add":"remove",r=a(s,o);for(let s in r){"wheel"===s&&(s=e.wheelEvent);for(const e of r[s])u(s,this._actions)?this.events[t](s,e):h.string(this.target)?this._scopeEvents[i+"Delegate"](this.target,this._context,s,e,n):this._scopeEvents[i](this.target,s,e,n)}return this}on(t,e,s){return this._onOff("on",t,e,s)}off(t,e,s){return this._onOff("off",t,e,s)}set(t){const e=this._defaults;h.object(t)||(t={}),this.options=s(e.base);for(const s in this._actions.methodDict){const o=s,n=this._actions.methodDict[o];this.options[o]={},this.setPerAction(o,c(c({},e.perAction),e.actions[o])),this[n](t[o])}for(const e in t)h.func(this[e])&&this[e](t[e]);return this}unset(){if(h.string(this.target))for(const t in this._scopeEvents.delegatedEvents){const e=this._scopeEvents.delegatedEvents[t];for(let s=e.length-1;s>=0;s--){const{selector:o,context:n,listeners:i}=e[s];o===this.target&&n===this._context&&e.splice(s,1);for(let e=i.length-1;e>=0;e--)this._scopeEvents.removeDelegate(this.target,this._context,t,i[e][0],i[e][1])}}else this._scopeEvents.remove(this.target,"all")}} | ||
import*as t from"../utils/arr.prod.js";import e from"../utils/browser.prod.js";import s from"../utils/clone.prod.js";import{getElementRect as n,matchesUpTo as o,nodeContains as i,trySelector as r}from"../utils/domUtils.prod.js";import c from"../utils/extend.prod.js";import h from"../utils/is.prod.js";import l from"../utils/isNonNativeEvent.prod.js";import a from"../utils/normalizeListeners.prod.js";import{getWindow as f}from"../utils/window.prod.js";import{Eventable as p}from"./Eventable";var u;(t=>{t[t.On=0]="On",t[t.Off=1]="Off"})(u||(u={}));export class Interactable{get _defaults(){return{base:{},perAction:{},actions:{}}}options;_actions;target;events=new p;_context;_win;_doc;_scopeEvents;constructor(t,e,s,n){this._actions=e.actions,this.target=t,this._context=e.context||s,this._win=f(r(t)?this._context:t),this._doc=this._win.document,this._scopeEvents=n,this.set(e)}setOnEvents(t,e){return h.func(e.onstart)&&this.on(t+"start",e.onstart),h.func(e.onmove)&&this.on(t+"move",e.onmove),h.func(e.onend)&&this.on(t+"end",e.onend),h.func(e.oninertiastart)&&this.on(t+"inertiastart",e.oninertiastart),this}updatePerActionListeners(t,e,s){var n;const o=null==(n=this._actions.map[t])?void 0:n.filterEventType,i=t=>(null==o||o(t))&&l(t,this._actions);(h.array(e)||h.object(e))&&this._onOff(u.Off,t,e,void 0,i),(h.array(s)||h.object(s))&&this._onOff(u.On,t,s,void 0,i)}setPerAction(e,n){const o=this._defaults;for(const i in n){const r=i,l=this.options[e],a=n[r];"listeners"===r&&this.updatePerActionListeners(e,l.listeners,a),h.array(a)?l[r]=t.from(a):h.plainObject(a)?(l[r]=c(l[r]||{},s(a)),h.object(o.perAction[r])&&"enabled"in o.perAction[r]&&(l[r].enabled=!1!==a.enabled)):h.bool(a)&&h.object(o.perAction[r])?l[r].enabled=a:l[r]=a}}getRect(t){return t=t||(h.element(this.target)?this.target:null),h.string(this.target)&&(t=t||this._context.querySelector(this.target)),n(t)}rectChecker(t){return h.func(t)?(this.getRect=e=>{const s=c({},t.apply(this,e));return"width"in s||(s.width=s.right-s.left,s.height=s.bottom-s.top),s},this):null===t?(delete this.getRect,this):this.getRect}_backCompatOption(t,e){if(r(e)||h.object(e)){this.options[t]=e;for(const s in this._actions.map)this.options[s][t]=e;return this}return this.options[t]}origin(t){return this._backCompatOption("origin",t)}deltaSource(t){return"page"===t||"client"===t?(this.options.deltaSource=t,this):this.options.deltaSource}getAllElements(){const{target:t}=this;return h.string(t)?Array.from(this._context.querySelectorAll(t)):h.func(t)&&t.getAllElements?t.getAllElements():h.element(t)?[t]:[]}context(){return this._context}inContext(t){return this._context===t.ownerDocument||i(this._context,t)}testIgnoreAllow(t,e,s){return!this.testIgnore(t.ignoreFrom,e,s)&&this.testAllow(t.allowFrom,e,s)}testAllow(t,e,s){return!t||!!h.element(s)&&(h.string(t)?o(s,t,e):!!h.element(t)&&i(t,s))}testIgnore(t,e,s){return!(!t||!h.element(s))&&(h.string(t)?o(s,t,e):!!h.element(t)&&i(t,s))}fire(t){return this.events.fire(t),this}_onOff(t,s,n,o,i){h.object(s)&&!h.array(s)&&(o=n,n=null);const r=a(s,n,i);for(let s in r){"wheel"===s&&(s=e.wheelEvent);for(const e of r[s])l(s,this._actions)?this.events[t===u.On?"on":"off"](s,e):h.string(this.target)?this._scopeEvents[t===u.On?"addDelegate":"removeDelegate"](this.target,this._context,s,e,o):this._scopeEvents[t===u.On?"add":"remove"](this.target,s,e,o)}return this}on(t,e,s){return this._onOff(u.On,t,e,s)}off(t,e,s){return this._onOff(u.Off,t,e,s)}set(t){const e=this._defaults;h.object(t)||(t={}),this.options=s(e.base);for(const s in this._actions.methodDict){const n=s,o=this._actions.methodDict[n];this.options[n]={},this.setPerAction(n,c(c({},e.perAction),e.actions[n])),this[o](t[n])}for(const e in t)"getRect"!==e?h.func(this[e])&&this[e](t[e]):this.rectChecker(t.getRect);return this}unset(){if(h.string(this.target))for(const t in this._scopeEvents.delegatedEvents){const e=this._scopeEvents.delegatedEvents[t];for(let s=e.length-1;s>=0;s--){const{selector:n,context:o,listeners:i}=e[s];n===this.target&&o===this._context&&e.splice(s,1);for(let e=i.length-1;e>=0;e--)this._scopeEvents.removeDelegate(this.target,this._context,t,i[e][0],i[e][1])}}else this._scopeEvents.remove(this.target,"all")}} | ||
//# sourceMappingURL=Interactable.prod.js.map |
import type { Interactable } from '@interactjs/core/Interactable'; | ||
import type { OptionsArg, Options } from '@interactjs/core/options'; | ||
import type { Scope } from '@interactjs/core/scope'; | ||
import type { Target, Context } from '@interactjs/core/types'; | ||
import type { Target } from '@interactjs/core/types'; | ||
declare module '@interactjs/core/scope' { | ||
@@ -15,10 +15,6 @@ interface SignalArgs { | ||
} | ||
interface InteractableScopeProp { | ||
context: Context; | ||
interactable: Interactable; | ||
} | ||
export declare class InteractableSet { | ||
list: Interactable[]; | ||
selectorMap: { | ||
[selector: string]: InteractableScopeProp[]; | ||
[selector: string]: Interactable[]; | ||
}; | ||
@@ -28,5 +24,4 @@ scope: Scope; | ||
new(target: Target, options?: any): Interactable; | ||
get(target: Target, options?: Options): Interactable; | ||
getExisting(target: Target, options?: Options): Interactable; | ||
forEachMatch<T>(node: Node, callback: (interactable: Interactable) => T): T | void; | ||
} | ||
export {}; |
@@ -18,15 +18,7 @@ import * as arr from "../utils/arr.js"; | ||
const { | ||
target, | ||
_context: context | ||
target | ||
} = interactable; | ||
const targetMappings = is.string(target) ? this.selectorMap[target] : target[this.scope.id]; | ||
const targetIndex = arr.findIndex(targetMappings, m => m.context === context); | ||
if (targetMappings[targetIndex]) { | ||
// Destroying mappingInfo's context and interactable | ||
targetMappings[targetIndex].context = null; | ||
targetMappings[targetIndex].interactable = null; | ||
} | ||
targetMappings.splice(targetIndex, 1); | ||
const interactablesOnTarget = is.string(target) ? this.selectorMap[target] : target[this.scope.id]; | ||
const targetIndex = arr.findIndex(interactablesOnTarget, i => i === interactable); | ||
interactablesOnTarget.splice(targetIndex, 1); | ||
} | ||
@@ -41,6 +33,2 @@ }); | ||
const interactable = new this.scope.Interactable(target, options, this.scope.document, this.scope.events); | ||
const mappingInfo = { | ||
context: interactable._context, | ||
interactable | ||
}; | ||
this.scope.addDocument(interactable._doc); | ||
@@ -54,3 +42,3 @@ this.list.push(interactable); | ||
this.selectorMap[target].push(mappingInfo); | ||
this.selectorMap[target].push(interactable); | ||
} else { | ||
@@ -65,3 +53,3 @@ if (!interactable.target[this.scope.id]) { | ||
; | ||
target[this.scope.id].push(mappingInfo); | ||
target[this.scope.id].push(interactable); | ||
} | ||
@@ -78,13 +66,8 @@ | ||
get(target, options) { | ||
getExisting(target, options) { | ||
const context = options && options.context || this.scope.document; | ||
const isSelector = is.string(target); | ||
const targetMappings = isSelector ? this.selectorMap[target] : target[this.scope.id]; | ||
if (!targetMappings) { | ||
return null; | ||
} | ||
const found = arr.find(targetMappings, m => m.context === context && (isSelector || m.interactable.inContext(target))); | ||
return found && found.interactable; | ||
const interactablesOnTarget = isSelector ? this.selectorMap[target] : target[this.scope.id]; | ||
if (!interactablesOnTarget) return undefined; | ||
return arr.find(interactablesOnTarget, interactable => interactable._context === context && (isSelector || interactable.inContext(target))); | ||
} | ||
@@ -91,0 +74,0 @@ |
@@ -1,2 +0,2 @@ | ||
import*as t from"../utils/arr.prod.js";import*as e from"../utils/domUtils.prod.js";import s from"../utils/extend.prod.js";import i from"../utils/is.prod.js";export class InteractableSet{list=[];selectorMap={};scope;constructor(e){this.scope=e,e.addListeners({"interactable:unset":({interactable:e})=>{const{target:s,_context:o}=e,c=i.string(s)?this.selectorMap[s]:s[this.scope.id],n=t.findIndex(c,(t=>t.context===o));c[n]&&(c[n].context=null,c[n].interactable=null),c.splice(n,1)}})}new(t,e){e=s(e||{},{actions:this.scope.actions});const o=new this.scope.Interactable(t,e,this.scope.document,this.scope.events),c={context:o._context,interactable:o};return this.scope.addDocument(o._doc),this.list.push(o),i.string(t)?(this.selectorMap[t]||(this.selectorMap[t]=[]),this.selectorMap[t].push(c)):(o.target[this.scope.id]||Object.defineProperty(t,this.scope.id,{value:[],configurable:!0}),t[this.scope.id].push(c)),this.scope.fire("interactable:new",{target:t,options:e,interactable:o,win:this.scope._win}),o}get(e,s){const o=s&&s.context||this.scope.document,c=i.string(e),n=c?this.selectorMap[e]:e[this.scope.id];if(!n)return null;const r=t.find(n,(t=>t.context===o&&(c||t.interactable.inContext(e))));return r&&r.interactable}forEachMatch(t,s){for(const o of this.list){let c;if((i.string(o.target)?i.element(t)&&e.matchesSelector(t,o.target):t===o.target)&&o.inContext(t)&&(c=s(o)),void 0!==c)return c}}} | ||
import*as t from"../utils/arr.prod.js";import*as e from"../utils/domUtils.prod.js";import s from"../utils/extend.prod.js";import i from"../utils/is.prod.js";export class InteractableSet{list=[];selectorMap={};scope;constructor(e){this.scope=e,e.addListeners({"interactable:unset":({interactable:e})=>{const{target:s}=e,o=i.string(s)?this.selectorMap[s]:s[this.scope.id],r=t.findIndex(o,(t=>t===e));o.splice(r,1)}})}new(t,e){e=s(e||{},{actions:this.scope.actions});const o=new this.scope.Interactable(t,e,this.scope.document,this.scope.events);return this.scope.addDocument(o._doc),this.list.push(o),i.string(t)?(this.selectorMap[t]||(this.selectorMap[t]=[]),this.selectorMap[t].push(o)):(o.target[this.scope.id]||Object.defineProperty(t,this.scope.id,{value:[],configurable:!0}),t[this.scope.id].push(o)),this.scope.fire("interactable:new",{target:t,options:e,interactable:o,win:this.scope._win}),o}getExisting(e,s){const o=s&&s.context||this.scope.document,r=i.string(e),c=r?this.selectorMap[e]:e[this.scope.id];if(c)return t.find(c,(t=>t._context===o&&(r||t.inContext(e))))}forEachMatch(t,s){for(const o of this.list){let r;if((i.string(o.target)?i.element(t)&&e.matchesSelector(t,o.target):t===o.target)&&o.inContext(t)&&(r=s(o)),void 0!==r)return r}}} | ||
//# sourceMappingURL=InteractableSet.prod.js.map |
@@ -5,5 +5,5 @@ /** @module interact */ | ||
import is from "../utils/is.js"; | ||
import isNonNativeEvent from "../utils/isNonNativeEvent.js"; | ||
import { warnOnce } from "../utils/misc.js"; | ||
import * as pointerUtils from "../utils/pointerUtils.js"; | ||
import isNonNativeEvent from './isNonNativeEvent'; | ||
export function createInteractStatic(scope) { | ||
@@ -36,3 +36,3 @@ /** | ||
const interact = (target, options) => { | ||
let interactable = scope.interactables.get(target, options); | ||
let interactable = scope.interactables.getExisting(target, options); | ||
@@ -58,3 +58,3 @@ if (!interactable) { | ||
interact.version = "1.10.21"; | ||
interact.version = "1.10.22"; | ||
interact.scope = scope; | ||
@@ -61,0 +61,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import t from"../utils/browser.prod.js";import*as e from"../utils/domUtils.prod.js";import o from"../utils/is.prod.js";import{warnOnce as s}from"../utils/misc.prod.js";import*as n from"../utils/pointerUtils.prod.js";import i from"./isNonNativeEvent";export function createInteractStatic(r){const c=(t,e)=>{let o=r.interactables.get(t,e);return o||(o=r.interactables.new(t,e),o.events.global=c.globalEvents),o};return c.getPointerAverage=n.pointerAverage,c.getTouchBBox=n.touchBBox,c.getTouchDistance=n.touchDistance,c.getTouchAngle=n.touchAngle,c.getElementRect=e.getElementRect,c.getElementClientRect=e.getElementClientRect,c.matchesSelector=e.matchesSelector,c.closest=e.closest,c.globalEvents={},c.version="1.10.21",c.scope=r,c.use=function(t,e){return this.scope.usePlugin(t,e),this},c.isSet=function(t,e){return!!this.scope.interactables.get(t,e&&e.context)},c.on=s((function(t,e,s){if(o.string(t)&&-1!==t.search(" ")&&(t=t.trim().split(/ +/)),o.array(t)){for(const o of t)this.on(o,e,s);return this}if(o.object(t)){for(const o in t)this.on(o,t[o],e);return this}return i(t,this.scope.actions)?this.globalEvents[t]?this.globalEvents[t].push(e):this.globalEvents[t]=[e]:this.scope.events.add(this.scope.document,t,e,{options:s}),this}),"The interact.on() method is being deprecated"),c.off=s((function(t,e,s){if(o.string(t)&&-1!==t.search(" ")&&(t=t.trim().split(/ +/)),o.array(t)){for(const o of t)this.off(o,e,s);return this}if(o.object(t)){for(const o in t)this.off(o,t[o],e);return this}if(i(t,this.scope.actions)){let o;t in this.globalEvents&&-1!==(o=this.globalEvents[t].indexOf(e))&&this.globalEvents[t].splice(o,1)}else this.scope.events.remove(this.scope.document,t,e,s);return this}),"The interact.off() method is being deprecated"),c.debug=function(){return this.scope},c.supportsTouch=()=>t.supportsTouch,c.supportsPointerEvent=()=>t.supportsPointerEvent,c.stop=function(){for(const t of this.scope.interactions.list)t.stop();return this},c.pointerMoveTolerance=function(t){return o.number(t)?(this.scope.interactions.pointerMoveTolerance=t,this):this.scope.interactions.pointerMoveTolerance},c.addDocument=function(t,e){this.scope.addDocument(t,e)},c.removeDocument=function(t){this.scope.removeDocument(t)},c} | ||
import t from"../utils/browser.prod.js";import*as e from"../utils/domUtils.prod.js";import o from"../utils/is.prod.js";import s from"../utils/isNonNativeEvent.prod.js";import{warnOnce as i}from"../utils/misc.prod.js";import*as n from"../utils/pointerUtils.prod.js";export function createInteractStatic(r){const c=(t,e)=>{let o=r.interactables.getExisting(t,e);return o||(o=r.interactables.new(t,e),o.events.global=c.globalEvents),o};return c.getPointerAverage=n.pointerAverage,c.getTouchBBox=n.touchBBox,c.getTouchDistance=n.touchDistance,c.getTouchAngle=n.touchAngle,c.getElementRect=e.getElementRect,c.getElementClientRect=e.getElementClientRect,c.matchesSelector=e.matchesSelector,c.closest=e.closest,c.globalEvents={},c.version="1.10.22",c.scope=r,c.use=function(t,e){return this.scope.usePlugin(t,e),this},c.isSet=function(t,e){return!!this.scope.interactables.get(t,e&&e.context)},c.on=i((function(t,e,i){if(o.string(t)&&-1!==t.search(" ")&&(t=t.trim().split(/ +/)),o.array(t)){for(const o of t)this.on(o,e,i);return this}if(o.object(t)){for(const o in t)this.on(o,t[o],e);return this}return s(t,this.scope.actions)?this.globalEvents[t]?this.globalEvents[t].push(e):this.globalEvents[t]=[e]:this.scope.events.add(this.scope.document,t,e,{options:i}),this}),"The interact.on() method is being deprecated"),c.off=i((function(t,e,i){if(o.string(t)&&-1!==t.search(" ")&&(t=t.trim().split(/ +/)),o.array(t)){for(const o of t)this.off(o,e,i);return this}if(o.object(t)){for(const o in t)this.off(o,t[o],e);return this}if(s(t,this.scope.actions)){let o;t in this.globalEvents&&-1!==(o=this.globalEvents[t].indexOf(e))&&this.globalEvents[t].splice(o,1)}else this.scope.events.remove(this.scope.document,t,e,i);return this}),"The interact.off() method is being deprecated"),c.debug=function(){return this.scope},c.supportsTouch=()=>t.supportsTouch,c.supportsPointerEvent=()=>t.supportsPointerEvent,c.stop=function(){for(const t of this.scope.interactions.list)t.stop();return this},c.pointerMoveTolerance=function(t){return o.number(t)?(this.scope.interactions.pointerMoveTolerance=t,this):this.scope.interactions.pointerMoveTolerance},c.addDocument=function(t,e){this.scope.addDocument(t,e)},c.removeDocument=function(t){this.scope.removeDocument(t)},c} | ||
//# sourceMappingURL=InteractStatic.prod.js.map |
@@ -1,2 +0,2 @@ | ||
import type { Point, Listeners, OrBoolean, Element } from '@interactjs/core/types'; | ||
import type { Point, Listeners, OrBoolean, Element, Rect } from '@interactjs/core/types'; | ||
export interface Defaults { | ||
@@ -13,2 +13,3 @@ base: BaseDefaults; | ||
context?: Node; | ||
getRect?: (element: Element) => Rect; | ||
} | ||
@@ -15,0 +16,0 @@ export interface PerActionDefaults { |
{ | ||
"name": "@interactjs/core", | ||
"version": "1.10.21", | ||
"version": "1.10.22", | ||
"main": "index", | ||
@@ -13,3 +13,3 @@ "module": "index", | ||
"peerDependencies": { | ||
"@interactjs/utils": "1.10.21" | ||
"@interactjs/utils": "1.10.22" | ||
}, | ||
@@ -24,3 +24,3 @@ "publishConfig": { | ||
"license": "MIT", | ||
"gitHead": "2b800f06" | ||
"gitHead": "aa616cc5" | ||
} |
import type Interaction from '@interactjs/core/Interaction'; | ||
import type { PhaseMap, InteractEvent } from './InteractEvent'; | ||
import type { Interactable } from './Interactable'; | ||
import type _NativePointerEventType from './NativePointerEventType'; | ||
import type { NativePointerEvent as NativePointerEvent_ } from './NativeTypes'; | ||
export declare type OrBoolean<T> = { | ||
@@ -95,3 +95,3 @@ [P in keyof T]: T[P] | boolean; | ||
export declare type RectChecker = (element: Element) => Rect; | ||
export declare type NativePointerEventType = typeof _NativePointerEventType; | ||
export declare type NativePointerEventType = typeof NativePointerEvent_; | ||
export declare type PointerEventType = MouseEvent | TouchEvent | Partial<NativePointerEventType> | InteractEvent; | ||
@@ -98,0 +98,0 @@ export declare type PointerType = MouseEvent | Touch | Partial<NativePointerEventType> | InteractEvent; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
453126
3410
84