UNPKG

@purtuga/interactions

Version:

Re-usable UI interactions.

2 lines 15.7 kB
!function(e,t,n,r,o,i,a,s,u,c,l,f,d,p,h,m,v,y,b,w,g,k,_,E,x){!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Interactions=t():e.Interactions=t()}(e,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||c.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&c.defineProperty(e,Symbol.toStringTag,{value:"Module"}),c.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=c.create(null);if(n.r(r),c.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return c.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(n,r,o){"use strict";function f(e){return(f=c.setPrototypeOf?c.getPrototypeOf:function(e){return e.__proto__||c.getPrototypeOf(e)})(e)}function d(e,t,n){return(d="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,n){var r=function(e,t){for(;!c.prototype.hasOwnProperty.call(e,t)&&null!==(e=f(e)););return e}(e,t);if(r){var o=c.getOwnPropertyDescriptor(r,t);return o.get?o.get.call(n):o.value}})(e,t,n||e)}function h(e){return(h="function"==typeof Symbol&&"symbol"===y(Symbol.iterator)?function(e){return y(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":y(e)})(e)}function y(e){return(y="function"==typeof Symbol&&"symbol"===h(Symbol.iterator)?function(e){return h(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":h(e)})(e)}function b(e,t){if(!(e instanceof t))throw new m("Cannot call a class as a function")}function w(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function g(e,t){return!t||"object"!==y(t)&&"function"!=typeof t?w(e):t}function k(e,t){return(k=c.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _(e,t){if("function"!=typeof t&&null!==t)throw new m("Super expression must either be null or a function");e.prototype=c.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&k(e,t)}function S(e){return function(e){if(u.isArray(e))return e}(e)||function(e){if(Symbol.iterator in c(e)||"[object Arguments]"===c.prototype.toString.call(e))return u.from(e)}(e)||function(){throw new m("Invalid attempt to destructure non-iterable instance")}()}o.r(r);var H=l.bind.call.bind(l.bind)(l.call.bind,l.call),P=H(c.prototype.toString),A=function(e){return"[object Object]"===P(e)},M=c.defineProperty,O=(c.defineProperties,c.keys,function(e,t,n,r,o){var i=!(arguments.length>5&&arguments[5]!==x)||arguments[5],a=arguments.length>6&&arguments[6]!==x&&arguments[6],s=!(arguments.length>7&&arguments[7]!==x)||arguments[7],u={configurable:i,enumerable:a};return r||o?(u.get=r,u.set=o):(u.writable=s,u.value=n),M(e,t,u),e}),z=[],D=(u.isArray,H(z.forEach),H(z.indexOf),H(z.splice),H(z.slice),E.log),T=E.error||D,C=(E.warn,"undefined"!=typeof Symbol&&Symbol.iterator&&Symbol.iterator,HTMLElement.prototype),R=t;R.head,H(C.appendChild),H(C.insertBefore),H(C.hasAttribute),H(C.getAttribute),H(C.setAttribute),H(C.removeAttribute);function W(e){for(var t=e||{},n=arguments.length,r=new u(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];var i,a,s=r.length,c=!1;for("boolean"==typeof e&&(c=e,t=r.shift()||{},s=r.length),i=0;i<s;i++)if(r[i])for(a in r[i])r[i].hasOwnProperty(a)&&(c&&A(t[a])&&A(r[i][a])?t[a]=W(!0,t[a],r[i][a]):t[a]=r[i][a]);return t}var j;"undefined"==typeof WeakMap?function(){var t=c.defineProperty,n=i.now()%1e9,r=j=function(){this.name="__st"+(1e9*p.random()>>>0)+n+++"__"};r.prototype={set:function(e,n){var r=e[this.name];return r&&r[0]===e?r[1]=n:t(e,this.name,{value:[e,n],writable:!0}),this},get:function(e){var t;return(t=e[this.name])&&t[0]===e?t[1]:x},delete:function(e){var t=e[this.name];return!(!t||t[0]!==e)&&(t[0]=t[1]=x,!0)},has:function(e){var t=e[this.name];return!!t&&t[0]===e}},e.WeakMap=r}():j=WeakMap;var I={stash:new j,create:function(){return new j}};function F(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),c.defineProperty(e,r.key,r)}}function N(e,t,n){return t&&F(e.prototype,t),n&&F(e,n),e}var L=Symbol("state"),U=function(){function e(){b(this,e)}return N(e,[{key:"on",value:function(e,t){var n=this;return X(this,e).add(t),function(){return X(n,e).delete(t)}}},{key:"emit",value:function(e,t){X(this,e).forEach(function(e){return e(t)})}},{key:"clear",value:function(){X(this).clear()}}]),e}();function X(e,t){return e[L]||(e[L]=new Map),t?(e[L].has(t)||e[L].set(t,new Set),e[L].get(t)):e[L]}var Y=["on","emit","clear"];function q(e){return e.key&&e.kind?B(e):B}function B(e){var t=e.kind,n=e.key,r=e.descriptor;if("method"===t&&r.value){var o=!1,i=r.value;delete r.value,delete r.writable,r.get=function(){if(function(e){if(e.constructor&&e===e.constructor.prototype)throw new v("Can not be accessed directly on constructor.prototype!")}(this),!o){o=!0;var e=i.bind(this);return O(this,n,e),o=!1,e}}}return e}function J(e,t,n,r){var o=t.split(/\s+/),i={};return o.forEach(function(t){e.addEventListener(t,n,r),i[t]={remove:function(){return e.removeEventListener(t,n,r)}}}),c.create({listeners:i,remove:function(){o.forEach(function(e){return i[e].remove()})}})}var V=new WeakMap,G=function(){function e(){b(this,e),this.init&&this.init.apply(this,arguments)}return N(e,[{key:"onDestroy",value:function(e){V.has(this)||V.set(this,new Set),V.get(this).add(e)}},{key:"destroy",value:function(){var e=V.get(this);e&&(e.forEach(function(e){try{e()}catch(e){T(e)}}),e.clear())}}]),e}();function K(e,t,n){var r=t(function(e){!function(e,t){["method","field"].forEach(function(n){t.forEach(function(t){t.kind===n&&"own"===t.placement&&te(e,t)})})}(e,o.elements)},n),o=function(e,t){var n=[],r=[],o={static:[],prototype:[],own:[]};if(e.forEach(function(e){ne(e,o)}),e.forEach(function(e){if(!$(e))return n.push(e);var t=function(e,t){for(var n=[],r=[],o=e.decorators,i=o.length-1;i>=0;i--){var a=t[e.placement];a.splice(a.indexOf(e.key),1);var s=re(e),u=ae((0,o[i])(s)||s);ne(e=u.element,t),u.finisher&&r.push(u.finisher);var c=u.extras;if(c){for(var l=0;l<c.length;l++)ne(c[l],t);n.push.apply(n,c)}}return{element:e,finishers:r,extras:n}}(e,o);n.push(t.element),n.push.apply(n,t.extras),r.push.apply(r,t.finishers)}),!t)return{elements:n,finishers:r};var i=function(e,t){for(var n=[],r=t.length-1;r>=0;r--){var o=se(e),i=ue((0,t[r])(o)||o);if(i.finisher!==x&&n.push(i.finisher),i.elements!==x){e=i.elements;for(var a=0;a<e.length-1;a++)for(var s=a+1;s<e.length;s++)if(e[a].key===e[s].key&&e[a].placement===e[s].placement)throw new m("Duplicated element ("+e[a].key+")")}}return{elements:e,finishers:n}}(n,t);return r.push.apply(r,i.finishers),i.finishers=r,i}(function(e){for(var t=[],n=function(e){return"method"===e.kind&&e.key===i.key&&e.placement===i.placement},r=0;r<e.length;r++){var o,i=e[r];if("method"===i.kind&&(o=t.find(n)))if(ee(i.descriptor)||ee(o.descriptor)){if($(i)||$(o))throw new ReferenceError("Duplicated methods ("+i.key+") can't be decorated.");o.descriptor=i.descriptor}else{if($(i)){if($(o))throw new ReferenceError("Decorators can't be placed on different accessors with for the same property ("+i.key+").");o.decorators=i.decorators}Z(i,o)}else t.push(i)}return t}(r.d.map(Q)),e);return function(e,t){var n=e.prototype;["method","field"].forEach(function(r){t.forEach(function(t){var o=t.placement;if(t.kind===r&&("static"===o||"prototype"===o)){var i="static"===o?e:n;te(i,t)}})})}(r.F,o.elements),function(e,t){for(var n=0;n<t.length;n++){var r=(0,t[n])(e);if(r!==x){if("function"!=typeof r)throw new m("Finishers must return a constructor.");e=r}}return e}(r.F,o.finishers)}function Q(e){var t,n=fe(e.key);"method"===e.kind?(t={value:e.value,writable:!0,configurable:!0,enumerable:!1},c.defineProperty(e.value,"name",{value:"symbol"===y(n)?"":n,configurable:!0})):"get"===e.kind?t={get:e.value,configurable:!0,enumerable:!1}:"set"===e.kind?t={set:e.value,configurable:!0,enumerable:!1}:"field"===e.kind&&(t={configurable:!0,writable:!0,enumerable:!0});var r={kind:"field"===e.kind?"field":"method",key:n,placement:e.static?"static":"field"===e.kind?"own":"prototype",descriptor:t};return e.decorators&&(r.decorators=e.decorators),"field"===e.kind&&(r.initializer=e.value),r}function Z(e,t){e.descriptor.get!==x?t.descriptor.get=e.descriptor.get:t.descriptor.set=e.descriptor.set}function $(e){return e.decorators&&e.decorators.length}function ee(e){return e!==x&&!(e.value===x&&e.writable===x)}function te(e,t){var n=t.descriptor;if("field"===t.kind){var r=t.initializer;n={enumerable:n.enumerable,writable:n.writable,configurable:n.configurable,value:void 0===r?void 0:r.call(e)}}c.defineProperty(e,t.key,n)}function ne(e,t,n){var r=t[e.placement];if(!n&&-1!==r.indexOf(e.key))throw new m("Duplicated element ("+e.key+")");r.push(e.key)}function re(e){var t={kind:e.kind,key:e.key,placement:e.placement,descriptor:e.descriptor};return c.defineProperty(t,Symbol.toStringTag,{value:"Descriptor",configurable:!0}),"field"===e.kind&&(t.initializer=e.initializer),t}function oe(e){if(e!==x)return S(e).map(function(e){var t=ie(e);return ce(e,"finisher","An element descriptor"),ce(e,"extras","An element descriptor"),t})}function ie(e){var t=a(e.kind);if("method"!==t&&"field"!==t)throw new m('An element descriptor\'s .kind property must be either "method" or "field", but a decorator created an element descriptor with .kind "'+t+'"');var n=fe(e.key),r=a(e.placement);if("static"!==r&&"prototype"!==r&&"own"!==r)throw new m('An element descriptor\'s .placement property must be one of "static", "prototype" or "own", but a decorator created an element descriptor with .placement "'+r+'"');var o=e.descriptor;ce(e,"elements","An element descriptor");var i={kind:t,key:n,placement:r,descriptor:c.assign({},o)};return"field"!==t?ce(e,"initializer","A method descriptor"):(ce(o,"get","The property descriptor of a field descriptor"),ce(o,"set","The property descriptor of a field descriptor"),ce(o,"value","The property descriptor of a field descriptor"),i.initializer=e.initializer),i}function ae(e){return{element:ie(e),finisher:le(e,"finisher"),extras:oe(e.extras)}}function se(e){var t={kind:"class",elements:e.map(re)};return c.defineProperty(t,Symbol.toStringTag,{value:"Descriptor",configurable:!0}),t}function ue(e){var t=a(e.kind);if("class"!==t)throw new m('A class descriptor\'s .kind property must be "class", but a decorator created a class descriptor with .kind "'+t+'"');ce(e,"key","A class descriptor"),ce(e,"placement","A class descriptor"),ce(e,"descriptor","A class descriptor"),ce(e,"initializer","A class descriptor"),ce(e,"extras","A class descriptor");var n=le(e,"finisher");return{elements:oe(e.elements),finisher:n}}function ce(e,t,n){if(e[t]!==x)throw new m(n+" can't have a ."+t+" property.")}function le(e,t){var n=e[t];if(n!==x&&"function"!=typeof n)throw new m("Expected '"+t+"' to be a function");return n}function fe(e){var t=function(e,t){if("object"!==y(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(n!==x){var r=n.call(e,t||"default");if("object"!==y(r))return r;throw new m("@@toPrimitive must return a primitive value.")}return("string"===t?a:s)(e)}(e,"string");return"symbol"===y(t)?t:a(t)}var de=I.create(),pe=Symbol("resizable.handle"),he="".concat("resize","-start"),me="".concat("resize","-end"),ve=["nHandle","neHandle","eHandle","seHandle","sHandle","swHandle","wHandle","nwHandle"],ye=/^[ns]H/,be=/^[ew]H/,we=/^touch/,ge=function(){return!1},ke=function(e){return R.createElement(e)}("template");ke.innerHTML="<div handle></div>";var _e=K([function(e){return Y.forEach(function(t){e.elements.push({key:t,kind:"method",placement:"prototype",descriptor:c.getOwnPropertyDescriptor(U.prototype,t)})}),e}],function(e,n){return{F:function(r){function o(n){var r;b(this,o),r=g(this,f(o).call(this)),e(w(w(r)));var i={opt:W({},r.constructor.defaults,n)};return de.set(w(w(r)),i),i.opt.ele.ondragstart=ge,r.emit=r.emit.bind(w(w(r))),function(){var e,n=this,r=de.get(this),o=r.opt;ve.forEach(function(i){e=null;var a=y(o[i]);if(o[i]){if("boolean"===a)(e=t.importNode(ke.content,!0).firstChild).setAttribute("class","".concat(o.handleClassPrefix," ").concat(o.handleClassPrefix,"-").concat(i.substr(0,i.indexOf("H")))),e[pe]=!0,o.ele.appendChild(e);else if("string"===a){if(!(e=o.ele.querySelector(o[i])))return}else{if(!o[i].addEventListener)return;e=o[i]}r[i]=new Ee(n,e,be.test(i)?"ew":ye.test(i)?"ns":"all"),n.onDestroy(r[i].destroy)}})}.call(w(w(r))),r}return _(o,n),o}(),d:[]}},G);var Ee=K(null,function(e,t){var n=function(n){function r(t,n,o){var i;b(this,r),i=g(this,f(r).call(this)),e(w(w(i)));var a=de.get(t).opt,s=a.ele,u=a.minWidth,c=a.minHeight;return i._emit=t.emit,i._ele=s,i._minWidth=u,i._minHeight=c,i._handle=n,i._ewMovement="all"===o||"ew"===o,i._nsMovement="all"===o||"ns"===o,i._mouseupEv=null,i._mousemoveEv=null,i._mousedownEv=null,i._boxWidth=0,i._boxHeight=0,i._handleX=0,i._handleY=0,i.connect(),i}return _(r,t),r}();return{F:n,d:[{kind:"method",key:"connect",value:function(){this._mousedownEv||(this._mousedownEv=J(this._handle,"mousedown touchstart",this.handleMouseDown,!1))}},{kind:"method",key:"disconnect",value:function(){this.stopResizing(),this._mousedownEv&&(this._mousedownEv.remove(),this._mousedownEv=null)}},{kind:"method",decorators:[q],key:"handleMouseDown",value:function(e){this._boxWidth=this._ele.clientWidth,this._boxHeight=this._ele.clientHeight,this._handleX=xe(e,"x"),this._handleY=xe(e,"y"),this._mouseupEv=J(R,"mouseup touchend",this.stopResizing,!1),this._mousemoveEv=J(R,"mousemove touchmove",this.handleMouseMoves,!1),this._emit(he)}},{kind:"method",decorators:[q],key:"handleMouseMoves",value:function(e){var t=this._boxWidth+(xe(e,"x")-this._handleX),n=this._boxHeight+(xe(e,"y")-this._handleY),r=!1;return t>=this._minWidth&&this._ewMovement&&(this._ele.style.width=t+"px",r=!0),n>=this._minHeight&&this._nsMovement&&(this._ele.style.height=n+"px",r=!0),r&&this._emit("resize"),e.stopPropagation(),e.preventDefault(),!1}},{kind:"method",decorators:[q],key:"stopResizing",value:function(){var e=!1;this._mousemoveEv&&(this._mousemoveEv.remove(),this._mousemoveEv=null,e=!0),this._mouseupEv&&(this._mouseupEv.remove(),this._mouseupEv=null,e=!0),e&&this._emit(me)}},{kind:"method",decorators:[q],key:"destroy",value:function(){d(f(n.prototype),"destroy",this).call(this),this.disconnect(),this._handle[pe]&&this._handle.parentNode&&this._handle.parentNode.removeChild(this._handle)}}]}},G);function xe(e,t){return(we.test(e.type)&&e.targetTouches?e.targetTouches.item(0):e)["client".concat(t.toUpperCase())]}_e.defaults={ele:null,minWidth:50,minHeight:50,handleClassPrefix:"handle",nHandle:!1,neHandle:!1,eHandle:!1,seHandle:!1,sHandle:!1,swHandle:!1,wHandle:!1,nwHandle:!1};o.d(r,"VERSION",function(){return Se}),o.d(r,"Resizable",function(){return _e});var Se="1.0.2"}])})}(window,document,location,setTimeout,setInterval,Date,String,Number,Array,Object,Function,atob,btoa,Math,JSON,TypeError,Error,encodeURIComponent,decodeURIComponent,requestAnimationFrame,CustomEvent,clearInterval,clearTimeout,console); //# sourceMappingURL=interactions.legacy.umd.min.js.map