5 lines
4.7 KiB
JavaScript
5 lines
4.7 KiB
JavaScript
/* interact.js 1.10.27 | https://raw.github.com/taye/interact.js/main/LICENSE */
|
|
|
|
import*as arr from"../utils/arr.prod.js";import browser from"../utils/browser.prod.js";import clone from"../utils/clone.prod.js";import{trySelector,getElementRect,nodeContains,matchesUpTo}from"../utils/domUtils.prod.js";import extend from"../utils/extend.prod.js";import is from"../utils/is.prod.js";import isNonNativeEvent from"../utils/isNonNativeEvent.prod.js";import normalize from"../utils/normalizeListeners.prod.js";import{getWindow}from"../utils/window.prod.js";import{Eventable}from"./Eventable.prod.js";var OnOffMethod=function(t){return t[t.On=0]="On",t[t.Off=1]="Off",t}(OnOffMethod||{});class Interactable{get _defaults(){return{base:{},perAction:{},actions:{}}}constructor(t,e,s,i){this.target=void 0,this.options=void 0,this._actions=void 0,this.events=new Eventable,this._context=void 0,this._win=void 0,this._doc=void 0,this._scopeEvents=void 0,this._actions=e.actions,this.target=t,this._context=e.context||s,this._win=getWindow(trySelector(t)?this._context:t),this._doc=this._win.document,this._scopeEvents=i,this.set(e)}setOnEvents(t,e){return is.func(e.onstart)&&this.on(t+"start",e.onstart),is.func(e.onmove)&&this.on(t+"move",e.onmove),is.func(e.onend)&&this.on(t+"end",e.onend),is.func(e.oninertiastart)&&this.on(t+"inertiastart",e.oninertiastart),this}updatePerActionListeners(t,e,s){var i;const n=null==(i=this._actions.map[t])?void 0:i.filterEventType,o=t=>(null==n||n(t))&&isNonNativeEvent(t,this._actions);(is.array(e)||is.object(e))&&this._onOff(OnOffMethod.Off,t,e,void 0,o),(is.array(s)||is.object(s))&&this._onOff(OnOffMethod.On,t,s,void 0,o)}setPerAction(t,e){const s=this._defaults;for(const i in e){const n=i,o=this.options[t],r=e[n];"listeners"===n&&this.updatePerActionListeners(t,o.listeners,r),is.array(r)?o[n]=arr.from(r):is.plainObject(r)?(o[n]=extend(o[n]||{},clone(r)),is.object(s.perAction[n])&&"enabled"in s.perAction[n]&&(o[n].enabled=!1!==r.enabled)):is.bool(r)&&is.object(s.perAction[n])?o[n].enabled=r:o[n]=r}}getRect(t){return t=t||(is.element(this.target)?this.target:null),is.string(this.target)&&(t=t||this._context.querySelector(this.target)),getElementRect(t)}rectChecker(t){return is.func(t)?(this.getRect=e=>{const s=extend({},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(trySelector(e)||is.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 is.string(t)?Array.from(this._context.querySelectorAll(t)):is.func(t)&&t.getAllElements?t.getAllElements():is.element(t)?[t]:[]}context(){return this._context}inContext(t){return this._context===t.ownerDocument||nodeContains(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||!!is.element(s)&&(is.string(t)?matchesUpTo(s,t,e):!!is.element(t)&&nodeContains(t,s))}testIgnore(t,e,s){return!(!t||!is.element(s))&&(is.string(t)?matchesUpTo(s,t,e):!!is.element(t)&&nodeContains(t,s))}fire(t){return this.events.fire(t),this}_onOff(t,e,s,i,n){is.object(e)&&!is.array(e)&&(i=s,s=null);const o=normalize(e,s,n);for(let e in o){"wheel"===e&&(e=browser.wheelEvent);for(const s of o[e])isNonNativeEvent(e,this._actions)?this.events[t===OnOffMethod.On?"on":"off"](e,s):is.string(this.target)?this._scopeEvents[t===OnOffMethod.On?"addDelegate":"removeDelegate"](this.target,this._context,e,s,i):this._scopeEvents[t===OnOffMethod.On?"add":"remove"](this.target,e,s,i)}return this}on(t,e,s){return this._onOff(OnOffMethod.On,t,e,s)}off(t,e,s){return this._onOff(OnOffMethod.Off,t,e,s)}set(t){const e=this._defaults;is.object(t)||(t={}),this.options=clone(e.base);for(const s in this._actions.methodDict){const i=s,n=this._actions.methodDict[i];this.options[i]={},this.setPerAction(i,extend(extend({},e.perAction),e.actions[i])),this[n](t[i])}for(const e in t)"getRect"!==e?is.func(this[e])&&this[e](t[e]):this.rectChecker(t.getRect);return this}unset(){if(is.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:i,context:n,listeners:o}=e[s];i===this.target&&n===this._context&&e.splice(s,1);for(let e=o.length-1;e>=0;e--)this._scopeEvents.removeDelegate(this.target,this._context,t,o[e][0],o[e][1])}}else this._scopeEvents.remove(this.target,"all")}}export{Interactable};
|
|
//# sourceMappingURL=Interactable.prod.js.map
|