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