uiik 1.1.0 → 1.3.0-alpha

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/index.js CHANGED
@@ -1,7 +1,2630 @@
1
1
  /**
2
- * uiik v1.1.0
2
+ * uiik v1.3.0-alpha
3
3
  * A UI interactions kit includes draggable, splittable, rotatable, selectable, etc.
4
4
  * https://github.com/holyhigh2/uiik
5
5
  * c) 2021-2023 @holyhigh2 may be freely distributed under the MIT license
6
6
  */
7
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("myfx/is"),require("myfx/collection"),require("myfx/object"),require("myfx/string"),require("myfx/tree"),require("myfx/array"),require("myfx/utils")):"function"==typeof define&&define.amd?define(["exports","myfx/is","myfx/collection","myfx/object","myfx/string","myfx/tree","myfx/array","myfx/utils"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).uiik={},e.is,e.collection,e.object,e.string,e.tree,e.array,e.utils)}(this,(function(e,t,s,o,n,i,l,r){"use strict";function a(e,t,s,o){if("a"===s&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?o:"a"===s?o.call(e):o?o.value:t.get(e)}function c(e,t,s,o,n){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?n.call(e,s):n?n.value=s:t.set(e,s),s}var d;class p{constructor(e,o){if(this.enabled=!0,d.set(this,[]),this.opts=o||{},t.isArrayLike(e)&&!t.isString(e))this.ele=s.map(e,(e=>{let s=t.isString(e)?document.querySelector(e):e;return t.isElement(s)?s:(console.error('Invalid element "'+e+'"'),!1)}));else{const o=t.isString(e)?document.querySelectorAll(e):e;if(!t.isElement(o)&&!t.isArrayLike(o))return void console.error('Invalid element "'+e+'"');this.ele=t.isArrayLike(o)?s.toArray(o):[o]}}destroy(){s.each(a(this,d,"f"),(e=>{e[0].removeEventListener(e[1],e[2],e[3])})),c(this,d,[],"f")}registerEvent(e,t,s,o=!1){const n=(e=>{this.enabled&&s(e)}).bind(this);e.addEventListener(t,n,o),a(this,d,"f").push([e,t,n,o])}disable(){this.enabled=!1}enable(){this.enabled=!0}getOptions(){return this.opts}getOption(e){return this.opts[e]}setOptions(e){o.assign(this.opts,e),this.onOptionChanged(this.opts)}setOption(e,t){this.opts[e]=t,this.onOptionChanged(this.opts)}onOptionChanged(e){}}function u(e,t){const s={x:0,y:0};let o=e.offsetParent;for(;o&&t&&o!==t;){const e=window.getComputedStyle(o);s.x+=o.offsetLeft+parseFloat(e.borderLeftWidth),s.y+=o.offsetTop+parseFloat(e.borderTopWidth),o=o.offsetParent}return s.x+=e.offsetLeft,s.y+=e.offsetTop,s}d=new WeakMap;const h=5,f="body * { pointer-events: none; }";let m;function v(){m=function(){document.styleSheets.length<1&&document.head.appendChild(document.createElement("style"));const e=s.find(document.styleSheets,(e=>!e.href));e||document.head.appendChild(document.createElement("style"));return e||s.find(document.styleSheets,(e=>!e.href))}(),null==m||m.insertRule(f,0)}function g(){null==m||m.deleteRule(0)}let y={html:"",body:""};function b(){y.body=document.body.style.cursor,y.html=document.documentElement.style.cursor}function x(e){document.body.style.cursor=document.documentElement.style.cursor=e}function w(){document.body.style.cursor=y.body,document.documentElement.style.cursor=y.html}var L,E,C;const S="uii-splittable",T="uii-splittable-handle-active";class z extends p{constructor(e,n){super(e,o.assign({handleSize:10,minSize:0,sticky:!1,inside:!1,ghost:!1},n)),L.add(this),s.each(this.ele,(e=>{"static"===window.getComputedStyle(e).position&&(e.style.position="relative"),e.classList.toggle(S,!0);const o=e.querySelectorAll(this.opts.handle),n=s.reject(e.children,(e=>!!s.includes(o,e))),i=a(this,L,"m",E).call(this,e);e.classList.toggle("v"===i?"uii-splittable-v":"uii-splittable-h",!0);const l=s.map(n,((e,s)=>t.isArray(this.opts.minSize)?this.opts.minSize[s]||0:this.opts.minSize)),r=s.map(n,((e,s)=>t.isArray(this.opts.sticky)?this.opts.sticky[s]||!1:this.opts.sticky));if(t.isEmpty(o)){const e=n.length-1;for(let t=0;t<e;t++)a(this,L,"m",C).call(this,l.slice(t,t+2),r.slice(t,t+2),this.opts,i,n[t],n[t+1])}else s.each(o,((t,s)=>{let o,n;t.parentNode.classList.contains(S)?(o=t.previousElementSibling,n=t.nextElementSibling):(n=function(e,t){let s=e.parentNode;for(;s&&s.parentNode!==t;)s=s.parentNode;return s}(t,e),o=n.previousElementSibling),a(this,L,"m",C).call(this,l.slice(s,s+2),r.slice(s,s+2),this.opts,i,o,n,t)}))}))}}function D(e,t){return new z(e,t)}L=new WeakSet,E=function(e){let t="h";let o=e.children[0].offsetTop;return s.each(e.children,(e=>{if(e.offsetTop!=o)return t="v",!1})),t},C=function(e,t,s,o,n,i,l){var r;const a=s.handleSize;if(!l){l=document.createElement("div");let e=0;s.inside||(e="v"===o?i.offsetTop:i.offsetLeft);const t=`width:${a}px;height:100%;top:0;left:${e-a/2}px;z-index:9;`,n=`height:${a}px;width:100%;left:0;top:${e-a/2}px;z-index:9;`;l.style.cssText="position: absolute;"+("v"===o?n:t),s.inside&&i.appendChild(l),null===(r=i.parentNode)||void 0===r||r.insertBefore(l,i)}l.style.cursor="v"===o?"s-resize":"e-resize",l.dataset.cursor=l.style.cursor,l.classList.add("uii-splittable-handle");const c=e[0],d=e[1];let p=t[0],u=t[1];const h=s.onStart,f=s.onSplit,m=s.onEnd,y=s.onSticky,L=s.onClone,E=s.oneSideMode,C=!E||"start"===E,S=!E||"end"===E;l.onmousedown=function(e){let t=0,r=0;const E=e.clientX,z=e.clientY;let D=1,k=0;switch(o){case"v":t=n.offsetHeight,r=i.offsetHeight,D=l.offsetHeight;break;case"h":t=n.offsetWidth,r=i.offsetWidth,D=l.offsetWidth}k=D+t+r;const M=n.style,N=i.style,$=s.ghost,W=s.ghostClass;let A=null,I="none";t<c/2?I="start":k-t-D<d/2&&(I="end");let O=!1;b();let F,q,Y="v"===o?n.offsetTop:n.offsetLeft;const R=s=>{var n;const m=s.clientX-E,g=s.clientY-z;if(!O){if(!(Math.abs(m)>1||Math.abs(g)>1))return s.preventDefault(),!1;O=!0,null==l||l.classList.add(T),$&&(A=l.cloneNode(!0),A.style.opacity="0.3",A.style.pointerEvents="none",A.classList.add("uii-splittable-handle-ghost"),A&&(W&&(A.className=A.className.replace(W,"")+" "+W),null===(n=null==l?void 0:l.parentNode)||void 0===n||n.appendChild(A),L&&L({clone:A},e))),v(),x((null==l?void 0:l.dataset.cursor)||""),h&&h({size1:t,size2:r},s)}let b=!1;if(F="v"===o?t+g:t+m,F<c/2&&p&&c>0?("none"==I&&(b=!0,I="start"),F=0):F<c?(F=c,"start"==I&&p&&(b=!0,I="none")):k-F-D<d/2&&u?("none"==I&&(b=!0,I="end"),F=k-D):k-F-D<d&&(F=k-d-D,"end"==I&&u&&(b=!0,I="none")),q=k-F-D,A)"v"===o?A.style.top=Y+F-a/2+"px":A.style.left=Y+F-a/2+"px";else{const e="v"===o?"height":"width";C&&M.setProperty(e,F+"px","important"),S&&N.setProperty(e,q+"px","important"),b&&y&&y({size1:F,size2:q,position:I},s),"v"===o?l.style.top=i.offsetTop-a/2+"px":l.style.left=i.offsetLeft-a/2+"px"}return f&&f({size1:F,size2:q},s),s.preventDefault(),!1},X=e=>{var s,c;if(document.removeEventListener("mousemove",R,!1),document.removeEventListener("mouseup",X,!1),window.removeEventListener("blur",X,!1),O){switch(o){case"v":t=(null==n?void 0:n.offsetHeight)||-1,r=(null==i?void 0:i.offsetHeight)||-1;break;case"h":t=(null==n?void 0:n.offsetWidth)||-1,r=(null==i?void 0:i.offsetWidth)||-1}if(null==l||l.classList.remove(T),A){const e="v"===o?"height":"width";C&&M.setProperty(e,F+"px","important"),S&&N.setProperty(e,q+"px","important"),"v"===o?l.style.top=Y+F-a/2+"px":l.style.left=Y+F-a/2+"px",(null===(s=A.parentNode)||void 0===s?void 0:s.contains(A))&&(null===(c=A.parentNode)||void 0===c||c.removeChild(A))}g(),w(),m&&m({size1:t,size2:r},e)}};return document.addEventListener("mousemove",R,!1),document.addEventListener("mouseup",X,!1),window.addEventListener("blur",X,!1),e.preventDefault(),!1}};const k=2,M="uii-resizable-handle",N="uii-resizable-handle-",$="uii-resizable-handle-active";class W extends p{constructor(e,n){super(e,o.assign({handleSize:8,minSize:50,dir:["n","s","e","w","ne","nw","se","sw"],ghost:!1,offset:0},n)),s.each(this.ele,(e=>{!function(e,o){const n=o.handleSize,i=o.offset||0;s.each(o.dir||["n","s","e","w","ne","nw","se","sw"],(s=>{const l=document.createElement("div");l.classList.add(M,N+s),l.setAttribute("name","handle");let r="";switch(s){case"n":r=`left:0px;top:${-i}px;width:100%;height:${n}px;`;break;case"s":r=`left:0px;bottom:${-i}px;width:100%;height:${n}px;`;break;case"w":r=`top:0px;left:${-i}px;width:${n}px;height:100%;`;break;case"e":r=`top:0px;right:${-i}px;width:${n}px;height:100%;`;break;default:switch(r=`width:${n}px;height:${n}px;z-index:9;`,s){case"ne":r+=`top:${-i}px;right:${-i}px;`;break;case"nw":r+=`top:${-i}px;left:${-i}px;`;break;case"se":r+=`bottom:${-i}px;right:${-i}px;`;break;case"sw":r+=`bottom:${-i}px;left:${-i}px;`}}!function(e,s,o,n){const i=n.onStart,l=n.onResize,r=n.onEnd,a=n.onClone;e.onmousedown=function(c){const d=o.offsetWidth,p=o.offsetHeight,u=o.offsetLeft,h=o.offsetTop;let f=!1,m=!1,y=!1,L=!1;switch(s){case"s":m=!0;break;case"e":f=!0;break;case"n":L=!0,m=!0;break;case"w":y=!0,f=!0;break;case"se":f=!0,m=!0;break;case"sw":y=!0,f=!0,m=!0;break;case"ne":L=!0,f=!0,m=!0;break;case"nw":y=!0,L=!0,f=!0,m=!0}const E=c.clientX,C=c.clientY;let S,T,z,D;t.isArray(n.minSize)?(S=n.minSize[0],T=n.minSize[1]):t.isNumber(n.minSize)&&(S=n.minSize,T=n.minSize),t.isArray(n.maxSize)?(z=n.maxSize[0],D=n.maxSize[1]):t.isNumber(n.maxSize)&&(z=n.maxSize,D=n.maxSize);const M=z?u-z+d:null,N=D?h-D+p:null,W=S?u+d-S:null,A=T?h+p-T:null,I=n.ghost,O=n.ghostClass;let F=null;const q=n.aspectRatio,Y=o.style;let R=Y,X=d,H=p,P=!1;b();const B=n=>{var r;const c=n.clientX-E,g=n.clientY-C;if(!P){if(!(Math.abs(c)>k||Math.abs(g)>k))return n.preventDefault(),!1;P=!0,e.classList.add($),I&&(t.isFunction(I)?F=I():(F=o.cloneNode(!0),F.style.opacity="0.3",F.style.pointerEvents="none"),F&&(O&&(F.className=F.className.replace(O,"")+" "+O),null===(r=o.parentNode)||void 0===r||r.appendChild(F),a&&a({clone:F},n)),R=null==F?void 0:F.style),v(),x(e.dataset.cursor||""),i&&i({w:d,h:p},n)}let b=d,w=p,Y=h,B=u;return f&&(b=d+c*(y?-1:1),S&&b<S&&(b=S),z&&b>z&&(b=z)),m&&(w=p+g*(L?-1:1),T&&w<T&&(w=T),D&&w>D&&(w=D)),L&&(Y=h+g,N&&Y<N&&(Y=N),A&&Y>A&&(Y=A)),y&&(B=u+c,M&&B<M&&(B=M),W&&B>W&&(B=W)),q?(f&&(R.width=b+"px",R.height=b/q+"px"),m&&"sw"!==s&&("nw"===s?Y=h-b/q+p:(R.width=w*q+"px",R.height=w+"px"))):(f&&(R.width=b+"px"),m&&(R.height=w+"px")),L&&(R.top=Y+"px"),y&&(R.left=B+"px"),X=b,H=w,l&&l({w:b,h:w},n),n.preventDefault(),!1},j=t=>{var s,n;document.removeEventListener("mousemove",B,!1),document.removeEventListener("mouseup",j,!1),window.removeEventListener("blur",j,!1),I&&F&&((null===(s=o.parentNode)||void 0===s?void 0:s.contains(F))&&(null===(n=o.parentNode)||void 0===n||n.removeChild(F)),Y.left=F.style.left,Y.top=F.style.top,Y.width=F.style.width,Y.height=F.style.height),P&&(e.classList.remove($),g(),w(),r&&r({w:X,h:H},t))};return document.addEventListener("mousemove",B,!1),document.addEventListener("mouseup",j,!1),window.addEventListener("blur",j,!1),c.preventDefault(),!1}}(l,s,e,o),l.style.cssText=`position: absolute;cursor: ${s}-resize;`+r,l.dataset.cursor=`${s}-resize`,e.appendChild(l)}))}(e,this.opts)}))}}function A(e,t){return new W(e,t)}var I;const O={},F="uii-draggable-active",q="uii-draggable-ghost";class Y extends p{constructor(e,r){super(e,o.assign({container:!1,threshold:0,ghost:!1,direction:"",scroll:!0,snapOptions:{tolerance:10}},r)),I.set(this,new WeakMap),this.opts.handle&&s.each(this.ele,(e=>{const t=e.querySelector(this.opts.handle);if(!t)return console.error('No handle found "'+this.opts.handle+'"'),!1;a(this,I,"f").set(e,t)})),this.onOptionChanged(this.opts),this.opts.group&&(O[this.opts.group]||(O[this.opts.group]=[]),O[this.opts.group].push(...this.ele)),s.each(this.ele,(e=>{!function(e,o,r,a){e(o,"mousedown",(e=>{var c;let d=e.currentTarget,p=e.target;if(!p)return;let f=a.get(d);if(f&&!f.contains(p))return;const m=r.filter;if(m&&s.some(o.querySelectorAll(m),(e=>e.contains(p))))return;const y=window.getComputedStyle(d),L=d.offsetParent||document.body,E=r.container,C=r.threshold||0,S=r.ghost,T=r.ghostClass,z=r.direction,D=r.onStart,k=r.onDrag,M=r.onEnd,N=r.onClone,$=y.zIndex;let W=r.zIndex||$;const A=r.classes||"",I=r.group;if(I){let e=-1;s.each(O[I],(t=>{const s=parseInt(window.getComputedStyle(t).zIndex)||0;s>e&&(e=s)})),W=e+1}const Y=r.scroll,R=r.scrollSpeed||10;let X,H;const P=r.grid;t.isArray(P)?(X=P[0],H=P[1]):t.isNumber(P)&&(X=H=P);const B=r.snap;let j;const _=(null===(c=r.snapOptions)||void 0===c?void 0:c.tolerance)||10,U=r.onSnap;let V="",Z="",G="",J=0,K=0;B&&(j=s.map(document.querySelectorAll(B),(e=>{let t=0,s=0;return i.closest(e,(e=>(t+=e.offsetLeft,s+=e.offsetTop,!1)),"offsetParent"),{x1:t,y1:s,x2:t+e.offsetWidth,y2:s+e.offsetHeight,el:e}})),i.closest(d,((e,t)=>(t>0&&(J+=e.offsetLeft,K+=e.offsetTop),!1)),"offsetParent"));const Q=d.offsetWidth+parseFloat(y.borderLeftWidth)+parseFloat(y.borderRightWidth),ee=d.offsetHeight+parseFloat(y.borderTopWidth)+parseFloat(y.borderBottomWidth);let te=0,se=0,oe=0,ne=0;E&&(oe=L.scrollWidth-Q,ne=L.scrollHeight-ee),oe<0&&(oe=0),ne<0&&(ne=0);const ie=L.getBoundingClientRect(),le=u(p,L),re=e.offsetX||0,ae=e.offsetY||0;let ce=le.x+re+L.scrollLeft,de=le.y+ae+L.scrollTop,pe=re,ue=e.offsetY;if(e.target!==d){const e=u(p,d),t=window.getComputedStyle(p);pe=e.x+re+parseFloat(t.borderLeftWidth),ue=e.y+ae+parseFloat(t.borderTopWidth)}const he=r.cursorAt;if(he){const e=he.left,s=he.top;pe=t.isString(e)?parseFloat(e)/100*d.offsetWidth:e,ue=t.isString(s)?parseFloat(s)/100*d.offsetWidth:s}const fe=d.style;let me,ve=!1,ge=null,ye=!1,be=!1,xe=!1,we=!1;b();const Le=e=>{var o;const i=e.clientX-ie.x+L.scrollLeft,a=e.clientY-ie.y+L.scrollTop;let c=i-ce,p=a-de;if(!ve){if(!(Math.abs(c)>C||Math.abs(p)>C))return e.preventDefault(),!1;{ve=!0,S&&(t.isFunction(S)?me=S(d):(me=d.cloneNode(!0),me.style.opacity="0.3",me.style.pointerEvents="none",me.style.position="absolute"),me.style.left=d.style.left,me.style.top=d.style.top,me.style.zIndex=W+"",T&&me.classList.add(...l.compact(n.split(T," "))),me.classList.add(...l.compact(n.split(A," "))),me.classList.toggle(q,!0),null===(o=d.parentNode)||void 0===o||o.appendChild(me),N&&N({clone:me},e)),d.classList.add(...l.compact(n.split(A," "))),me||(d.style.zIndex=W+""),d.classList.toggle(F,!0),D&&D({draggable:d},e),v(),r.cursor&&x(r.cursor.active||"move");const s=new Event("uii-dragactive",{bubbles:!0,cancelable:!1});d.dispatchEvent(s)}}if(Y){const t=e.clientX-ie.x,s=e.clientY-ie.y,o=ie.x+ie.width-e.clientX,n=ie.y+ie.height-e.clientY;ye=t<h,be=s<h,xe=o<h,we=n<h,ye||be||xe||we?ge||(ge=setInterval((()=>{ye?L.scrollLeft-=R:xe&&(L.scrollLeft+=R),be?L.scrollTop-=R:we&&(L.scrollTop+=R)}),20)):ge&&(clearInterval(ge),ge=null)}let u=i-pe,f=a-ue;t.isNumber(X)&&t.isNumber(H)&&(u=(u/X>>0)*X,f=(f/H>>0)*H),E&&(u<te&&(u=te),f<se&&(f=se),u>oe&&(u=oe),f>ne&&(f=ne));let m=!0,g=!1;if(B){const t=J+u,o=K+f,n=t+Q,i=o+ee;let l,r,a,c,p=NaN,h=NaN;z&&"v"!==z||s.each(j,(e=>{if(Math.abs(e.y1-o)<=_?(h=e.y1,c="t2t"):Math.abs(e.y2-o)<=_?(h=e.y2,c="t2b"):Math.abs(e.y1-i)<=_?(h=e.y1-ee,c="b2t"):Math.abs(e.y2-i)<=_&&(h=e.y2-ee,c="b2b"),h)return V=c,r=e.el,!1})),z&&"h"!==z||s.each(j,(e=>{if(Math.abs(e.x1-t)<=_?(p=e.x1,a="l2l"):Math.abs(e.x2-t)<=_?(p=e.x2,a="l2r"):Math.abs(e.x1-n)<=_?(p=e.x1-Q,a="r2l"):Math.abs(e.x2-n)<=_&&(p=e.x2-Q,a="r2r"),p)return Z=a,l=e.el,!1})),p||h?(p&&(u=p-J),h&&(f=h-K),U&&G!==Z+""+V&&(setTimeout((()=>{U({el:me||d,targetH:l,targetV:r,dirH:a,dirV:c},e)}),0),G=Z+""+V),g=!0):Z=V=G=""}return k&&!g&&!1===k({draggable:d,ox:c,oy:p,x:u,y:f},e)&&(m=!1),m&&(me?"v"===z?me.style.top=`${f}px`:"h"===z?me.style.left=`${u}px`:(me.style.left=`${u}px`,me.style.top=`${f}px`):"v"===z?fe.top=`${f}px`:"h"===z?fe.left=`${u}px`:(fe.left=`${u}px`,fe.top=`${f}px`)),e.preventDefault(),!1},Ee=e=>{var t,s;document.removeEventListener("mousemove",Le),document.removeEventListener("mouseup",Ee),window.removeEventListener("blur",Ee),Y&&ge&&(clearInterval(ge),ge=null),d.classList.remove(...l.compact(n.split(A," "))),d.style.zIndex=$,d.classList.remove(F);let o=!0;ve&&M&&(o=!1!==M({draggable:d},e));const i=new Event("uii-dragdeactive",{bubbles:!0,cancelable:!1});d.dispatchEvent(i),ve&&(g(),w(),S&&((null===(t=d.parentNode)||void 0===t?void 0:t.contains(me))&&(null===(s=d.parentNode)||void 0===s||s.removeChild(me)),!1!==o&&(fe.left=me.style.left,fe.top=me.style.top)))};return document.addEventListener("mousemove",Le),document.addEventListener("mouseup",Ee),window.addEventListener("blur",Ee),e.preventDefault(),!1}))}(this.registerEvent.bind(this),e,this.opts,a(this,I,"f")),t.isDefined(this.opts.type)&&(e.dataset.dropType=this.opts.type),e.classList.toggle("uii-draggable",!0);(a(this,I,"f").get(e)||e).classList.toggle("uii-draggable-handle",!0),t.isDefined(this.opts.cursor)&&(e.style.cursor=this.opts.cursor.default||"move",t.isDefined(this.opts.cursor.over)&&(e.dataset.cursorOver=this.opts.cursor.over,e.dataset.cursorActive=this.opts.cursor.active||"move"))}))}onOptionChanged(e){const s=e.droppable;t.isFunction(s)||(t.isUndefined(s)?e.droppable=()=>{}:t.isString(s)?e.droppable=()=>document.querySelectorAll(s):t.isArrayLike(s)?e.droppable=()=>s:t.isElement(s)&&(e.droppable=()=>[s]))}}function R(e,t){return new Y(e,t)}var X;I=new WeakMap;const H=[];class P extends p{constructor(e,t){super(e,o.assign({},t)),X.set(this,void 0),H.push(this)}bindEvent(e,t){this.registerEvent(e,"mouseenter",(o=>{a(this,X,"f")&&(t.hoverClass&&s.each(n.split(t.hoverClass," "),(t=>{e.classList.toggle(t,!0)})),a(this,X,"f").dataset.cursorOver&&x(a(this,X,"f").dataset.cursorOver),t.onEnter&&t.onEnter({draggable:a(this,X,"f"),droppable:e},o))})),this.registerEvent(e,"mouseleave",(o=>{a(this,X,"f")&&(t.hoverClass&&s.each(n.split(t.hoverClass," "),(t=>{e.classList.toggle(t,!1)})),a(this,X,"f").dataset.cursorOver&&x(a(this,X,"f").dataset.cursorActive||""),t.onLeave&&t.onLeave({draggable:a(this,X,"f"),droppable:e},o))})),this.registerEvent(e,"mousemove",(s=>{a(this,X,"f")&&t.onOver&&t.onOver({draggable:a(this,X,"f"),droppable:e},s)})),this.registerEvent(e,"mouseup",(o=>{a(this,X,"f")&&(t.hoverClass&&s.each(n.split(t.hoverClass," "),(t=>{e.classList.toggle(t,!1)})),t.onDrop&&t.onDrop({draggable:a(this,X,"f"),droppable:e},o))}))}active(e){let o=!0;const i=this.opts;t.isString(i.accepts)?o=!!e.dataset.dropType&&n.test(i.accepts,e.dataset.dropType):t.isFunction(i.accepts)&&(o=i.accepts(this.ele,e)),o&&(c(this,X,e,"f"),i.activeClass&&s.each(this.ele,(e=>{s.each(n.split(i.activeClass||""," "),(t=>{e.classList.toggle(t,!0)}))})),i.onActive&&i.onActive({draggable:e,droppables:this.ele}),s.each(this.ele,(e=>{e.classList.toggle("uii-droppable",!0),e.style.pointerEvents="initial",this.bindEvent(e,i)})))}deactive(e){if(!a(this,X,"f"))return;c(this,X,null,"f");const t=this.opts;t.activeClass&&s.each(this.ele,(e=>{s.each(n.split(t.activeClass||""," "),(t=>{e.classList.toggle(t,!1)}))})),t.onDeactive&&t.onDeactive({draggable:e,droppables:this.ele}),this.destroy()}}function B(e,t){return new P(e,t)}X=new WeakMap,document.addEventListener("uii-dragactive",(e=>{s.each(H,(t=>{t.active(e.target)}))})),document.addEventListener("uii-dragdeactive",(e=>{s.each(H,(t=>{t.deactive(e.target)}))}));const j=180/Math.PI,_=2,U="uii-rotatable",V="uii-rotatable-handle",Z="uii-rotatable-active";class G extends p{constructor(e,o){super(e,o),s.each(this.ele,(e=>{!function(e,s){var o;const n=document.createElement("div");n.className=V,n.style.cssText="\n position:absolute;\n width:12px;\n height:12px;\n border-radius:50%;\n left: calc(50% - 6px);\n top: -24px;\n ",n.style.cursor=(null===(o=s.cursor)||void 0===o?void 0:o.default)||"crosshair",function(e,s,o){const n=o.onStart,i=o.onRotate,l=o.onEnd;e.onmousedown=function(e){var r,a;const c=(window.getComputedStyle(s).transformOrigin||"").split(" "),d=s.cloneNode();d.style.cssText="transform:rotate(0);z-index:-999;position:absolute;",null===(r=s.parentElement)||void 0===r||r.appendChild(d);const p=d.getBoundingClientRect();null===(a=s.parentElement)||void 0===a||a.removeChild(d);let u=parseFloat(c[0])+p.x,h=parseFloat(c[1])+p.y,f=0,m=0;const y=window.getComputedStyle(s).transform;if(y.indexOf("matrix")>-1){const e=y.replace(/^matrix\(|\)$/gm,"").split(",");f=parseFloat(e[0]),m=parseFloat(e[1])}let L=Math.atan2(m,f)*j;L<0&&(L=360-L),L>360&&(L=360-L%360);const E=s.style;let C=Math.atan2(e.clientY-h,e.clientX-u)*j+90;C<0&&(C=360+C);const S=C-L;let T=!1;b();const z=e=>{var l;const r=e.clientX-u,a=e.clientY-h;if(!T){if(!(Math.abs(r)>_||Math.abs(a)>_))return e.preventDefault(),!1;T=!0,s.classList.toggle(Z,!0),n&&n({deg:L},e),v(),t.isDefined(o.cursor)&&x((null===(l=o.cursor)||void 0===l?void 0:l.active)||"crosshair")}return L=Math.atan2(a,r)*j+90-S,L<0&&(L=360+L),i&&i({deg:L},e),E.transform=E.transform.replace(/rotateZ\(.*?\)/,"")+" rotateZ("+L+"deg)",e.preventDefault(),!1},D=e=>{document.removeEventListener("mousemove",z,!1),document.removeEventListener("mouseup",D,!1),window.removeEventListener("blur",D,!1),T&&(g(),w(),s.classList.toggle(Z,!1),l&&l({deg:L},e))};return document.addEventListener("mousemove",z,!1),document.addEventListener("mouseup",D,!1),window.addEventListener("blur",D,!1),e.preventDefault(),!1}}(n,e,s),e.classList.toggle(U,!0),e.appendChild(n)}(e,this.opts)}))}}function J(e,t){return new G(e,t)}var K,Q,ee,te,se;class oe{constructor(e,s,n){K.set(this,void 0),c(this,K,s,"f"),this.opts={container:document.body},this.opts=o.assign(this.opts,n);const i=t.isString(e)?document.querySelector(e):e;if(!i)return void console.error('Invalid selector "'+e+'"');const l=i;this.el=i;const r=u(l,this.opts.container),a={x:r.x,y:r.y,width:l.offsetWidth,height:l.offsetHeight};this.elData={x1:a.x,y1:a.y,x2:a.x+a.width,y2:a.y+a.height},this.update()}update(){let e;e=t.isFunction(a(this,K,"f"))?a(this,K,"f").call(this):t.isString(a(this,K,"f"))?this.opts.container.querySelectorAll(a(this,K,"f")):t.isElement(a(this,K,"f"))?[a(this,K,"f")]:a(this,K,"f"),this.targetsData=s.flatMap(e,(e=>{if(!e)return[];if(!t.isElement(e))return[];const s=u(e,this.opts.container),o={x:s.x,y:s.y,width:e.offsetWidth,height:e.offsetHeight};return{x1:o.x,y1:o.y,x2:o.x+o.width,y2:o.y+o.height,el:e}}))}getOverlaps(e,t,o,n){let i=this.elData;return e&&o&&t&&n&&(i={x1:e,y1:t,x2:o,y2:n}),s.flatMap(this.targetsData,((e,t)=>i.x2<e.x1||i.x1>e.x2||i.y2<e.y1||i.y1>e.y2?[]:e.el))}getInclusions(e,t,o,n){let i=this.elData;return e&&o&&t&&n&&(i={x1:e,y1:t,x2:o,y2:n}),s.flatMap(this.targetsData,((e,t)=>i.x2>=e.x2&&i.x1<=e.x1&&i.y2>=e.y2&&i.y1<=e.y1?e.el:[]))}}function ne(e,t,s){return new oe(e,t,s)}K=new WeakMap;const ie="uii-selecting",le="uii-selected";class re extends p{constructor(e,t){super(e,o.assign({targets:[],scroll:!0},t)),Q.add(this),ee.set(this,void 0),te.set(this,void 0);const s=this.ele[0],n=document.createElement("div");n.className="uii-selector",n.style.cssText="\n position:absolute;\n left:-9999px;\n ",this.opts.class?n.className+=" "+this.opts.class:n.style.cssText+="border:1px dashed #000;",s.appendChild(n),c(this,ee,ne(n,this.opts.targets,{container:s}),"f"),a(this,Q,"m",se).call(this,n,s)}updateTargets(){a(this,ee,"f").update()}onOptionChanged(){this.updateTargets()}}function ae(e,t){return new re(e,t)}var ce;ee=new WeakMap,te=new WeakMap,Q=new WeakSet,se=function(e,o){const i=this,r=this.opts;this.registerEvent(o,"mousedown",(d=>{const p=d.target,f=r.onStart,m=r.onSelect,v=r.onEnd,g=r.mode||"overlap",y=r.scroll,b=r.scrollSpeed||10,x=r.filter,w=l.compact(n.split(r.selectingClass," ")),L=l.compact(n.split(r.selectedClass," "));if(x)if(t.isFunction(x)){if(x(p))return}else if(s.some(o.querySelectorAll(x),(e=>e.contains(p))))return;let E="";const C=o.getBoundingClientRect(),S=window.getComputedStyle(o),T=parseFloat(S.borderLeftWidth),z=parseFloat(S.borderTopWidth);let D=d.offsetX+o.scrollLeft,k=d.offsetY+o.scrollTop;if(p!==o){const e=u(p,o),t=window.getComputedStyle(p);D=e.x+d.offsetX+parseFloat(t.borderLeftWidth),k=e.y+d.offsetY+parseFloat(t.borderTopWidth)}const M=e.style;let N=[],$=[],W=D,A=k,I=!1,O=null,F=!1,q=!1,Y=!1,R=!1;const X=e=>{const t=e.clientX-C.x+o.scrollLeft-T,n=e.clientY-C.y+o.scrollTop-z,l=t-D,r=n-k;if(!I){if(!(Math.abs(l)>2||Math.abs(r)>2))return e.preventDefault(),!1;I=!0,a(this,ee,"f").update();"static"===window.getComputedStyle(o).position&&(E=o.style.position,o.style.position="relative"),s.each(a(this,te,"f"),(e=>{e.classList.toggle(le,!1)})),f&&f({selection:a(this,te,"f"),selectable:o},e)}if(y){const t=e.clientX-C.x,s=e.clientY-C.y,n=C.x+C.width-e.clientX,i=C.y+C.height-e.clientY;F=t<h,q=s<h,Y=n<h,R=i<h,F||q||Y||R?O||(O=setInterval((()=>{F?o.scrollLeft-=b:Y&&(o.scrollLeft+=b),q?o.scrollTop-=b:R&&(o.scrollTop+=b)}),20)):O&&(clearInterval(O),O=null)}let c=D,d=k,p=Math.abs(l),u=Math.abs(r);l>0&&r>0?(W=D,A=k):l<0&&r<0?(c=W=t,d=A=n):l<0?c=W=t:r<0&&(d=A=n),M.left=c+"px",M.top=d+"px",M.width=p+"px",M.height=u+"px","overlap"===g?N=a(i,ee,"f").getOverlaps(W,A,W+p,A+u):"inclusion"===g&&(N=a(i,ee,"f").getInclusions(W,A,W+p,A+u)),s.each($,(e=>{s.includes(N,e)||(e.classList.toggle(ie,!1),s.each(w,(t=>{e.classList.toggle(t,!1)})))})),s.each(N,(e=>{e.classList.toggle(ie,!0),s.each(w,(t=>{e.classList.toggle(t,!0)}))}));const v=$.length!=N.length;return $=N,v&&m&&m({selection:N,selectable:o},e),e.preventDefault(),!1},H=e=>{M.left="-9999px",M.width=M.height="0px",document.removeEventListener("mousemove",X,!1),document.removeEventListener("mouseup",H,!1),window.removeEventListener("blur",H,!1),y&&O&&(clearInterval(O),O=null),E&&(o.style.position=E),s.each(N,(e=>{s.each(w,(t=>{e.classList.toggle(t,!1)})),s.each(L,(t=>{e.classList.toggle(t,!0)})),e.classList.toggle(ie,!1),e.classList.toggle(le,!0)})),c(this,te,N,"f"),I&&v&&v({selection:N,selectable:o},e)};return document.addEventListener("mousemove",X,!1),document.addEventListener("mouseup",H,!1),window.addEventListener("blur",H,!1),d.preventDefault(),!1}))};const de={},pe="uii-sortable-ghost",ue="uii-sortable-active",he="uii-sortable-active",fe=2;class me extends p{constructor(e,i){super(e,o.merge({move:{from:!0,to:!0},scroll:!0,sort:!0},i)),ce.set(this,void 0),s.size(this.ele)>1&&!this.opts.group&&(this.opts.group="uii_sortable_"+r.alphaId()),s.each(this.ele,(e=>{e.classList.add("uii-sortable-container"),e.style.position="relative",e.style.pointerEvents="initial",function(e,o,i){e(o,"mousedown",(e=>{var r;let a=e.currentTarget,c=e.target;if(c===a)return;const d=i.filter?`:not(${i.filter})`:"",p=a.querySelectorAll(":scope > *"+d),u=i.handle?s.map(p,(e=>e.querySelector(i.handle||""))):s.toArray(p),h=l.findIndex(u,(e=>e.contains(c)));if(h<0)return;const f=p[h],m=i.ghostContainer||a,y=i.onStart,x=i.onEnd,L=i.ghostClass,E=i.group;let C=null===(r=i.move)||void 0===r?void 0:r.to;const S="copy"===C,T=(t.isFunction(C)?C:()=>!!C)(f,a),z=i.sort;i.scroll,i.scrollSpeed;let D=e.offsetX+a.scrollLeft,k=e.offsetY+a.scrollTop;b();let M=!1,N=null,$=null;const W=e=>{const r=e.clientX,c=e.clientY;let d=r-D,u=c-k;if(!M){if(!(Math.abs(d)>fe||Math.abs(u)>fe))return e.preventDefault(),!1;{let r;M=!0,N=f.cloneNode(!0),N.style.opacity="0.3",N.style.pointerEvents="none",N.style.position="fixed",N.style.zIndex="999",N.style.left=f.style.left,N.style.top=f.style.top,L&&N.classList.add(...l.compact(n.split(L," "))),N.classList.toggle(pe,!0),m.appendChild(N),S||f.classList.toggle(ue,!0),S&&(r=f.cloneNode(!0),r.classList.toggle(ue,!0)),ve={item:f,fromIndex:h,fromContainer:a,toContainer:a,moveTo:S?"copy":T,spill:i.spill,copy:r},y&&y({item:f,from:a,index:h},e),v(),z&&($=ge(i,a,S?f:r,p,h)),T&&E&&de[E]&&s.each(de[E],(([e,n])=>{const i=s.reject(n,(e=>e===o));t.isEmpty(i)||e.active(S?f:r,o,i,e.getOptions())}))}}return N.style.left=r+"px",N.style.top=c+"px",e.preventDefault(),!1},A=n=>{var i;if(document.removeEventListener("mousemove",W),document.removeEventListener("mouseup",A),window.removeEventListener("blur",A),M){g(),w(),N&&m.removeChild(N);const n=null==ve?void 0:ve.toContainer;null==ve||ve.item.classList.remove(ue),null===(i=null==ve?void 0:ve.copy)||void 0===i||i.classList.remove(ue),ve=null,$&&$(),E&&de[E]&&s.each(de[E],(([e,n])=>{const i=s.reject(n,(e=>e===o));t.isEmpty(i)||e.deactive(f,o,i,e.getOptions())})),x&&x({item:f,from:o,to:n},e)}};return document.addEventListener("mousemove",W),document.addEventListener("mouseup",A),window.addEventListener("blur",A),e.preventDefault(),!1})),e(o,"mouseleave",(e=>{var t,s;if(ve&&(i.onLeave&&i.onLeave({item:ve.item,from:ve.fromContainer,to:o},e),"copy"!==ve.moveTo))if("remove"===ve.spill)null===(t=ve.item.parentElement)||void 0===t||t.removeChild(ve.item);else if("revert"===ve.spill){null===(s=ve.item.parentElement)||void 0===s||s.removeChild(ve.item);const e=ve.fromContainer.children[ve.fromIndex];ve.fromContainer.insertBefore(ve.item,e)}})),e(o,"mouseenter",(e=>{var s;if(!ve)return;let n=ve.item;n.parentElement;const l=e.clientX,r=e.clientY,a=o.getBoundingClientRect(),c=a.width/2,d=a.height/2,p=l-a.x,u=r-a.y;let h="";if(p<c&&u<d?h="tl":p>c&&u>d?h="br":p<c&&u>d?h="bl":p>c&&u<d&&(h="tr"),i.onEnter&&i.onEnter({item:ve.item,from:ve.fromContainer,to:o,dir:h},e),ve.toContainer=o,o.getAttribute(he)){let l=!0;const r=null===(s=i.move)||void 0===s?void 0:s.from;if(l=(t.isFunction(r)?r:()=>!!r)(ve.item,ve.fromContainer,o),!l)return;if(o.contains(n))return;"copy"===ve.moveTo&&(n=ve.copy),n.parentElement&&n.parentElement.removeChild(n);let a=0;"t"===h[0]?o.insertBefore(n,o.children[0]):(o.appendChild(n),a=o.children.length-1),i.onAdd&&i.onAdd({item:n,from:ve.fromContainer,to:o,index:a},e)}else if(o===ve.fromContainer)if(ve.copy){let e=ve.copy.parentElement;e&&e.removeChild(null==ve?void 0:ve.copy)}else n.parentElement&&n.parentElement.removeChild(n),"t"===h[0]?o.insertBefore(n,o.children[0]):(o.appendChild(n),o.children.length)}))}(this.registerEvent.bind(this),e,this.opts)})),this.opts.group&&(de[this.opts.group]||(de[this.opts.group]=[]),de[this.opts.group].push([this,this.ele]))}active(e,o,i,l){var r;const a=null===(r=l.move)||void 0===r?void 0:r.from,d=t.isFunction(a)?a:()=>!!a,p=s.flatMap(i,(t=>d(e,o,t)?t:[]));s.each(p,(e=>{e.setAttribute(he,"1"),l.activeClass&&s.each(n.split(l.activeClass||""," "),(t=>{e.classList.toggle(t,!0)}))})),c(this,ce,s.map(p,(t=>{const s=t.querySelectorAll(":scope > *");return ge(l,t,e,s)})),"f"),l.onActive&&l.onActive({item:e,from:o})}deactive(e,t,o,i){s.each(o,(e=>{e.removeAttribute(he),i.activeClass&&s.each(n.split(i.activeClass||""," "),(t=>{e.classList.toggle(t,!1)}))})),s.each(a(this,ce,"f"),(e=>{e()})),i.onDeactive&&i.onDeactive({item:e,from:t})}onOptionChanged(){}}ce=new WeakMap;let ve=null;function ge(e,t,o,n,i=0){const l=s=>{const o=s.currentTarget;if(o.style.transform)return;const n=o._uiik_i;let l=(null==ve?void 0:ve.copy)||(null==ve?void 0:ve.item);t===(null==ve?void 0:ve.fromContainer)&&(l=null==ve?void 0:ve.item);let r=l.parentElement;null==r||r.removeChild(l);r===o.parentElement||(r=o.parentElement);const a=i;n>i?(i=n,null==r||r.insertBefore(l,o.nextElementSibling)):(i=n-1,null==r||r.insertBefore(l,o)),e.onChange&&e.onChange({item:l,from:null==ve?void 0:ve.fromContainer,to:t,fromIndex:a,toIndex:i},s);const c=o.offsetLeft,d=o.offsetTop,p=l.offsetLeft,u=l.offsetTop;o.style.transform=`translate3d(${p-c}px,${u-d}px,0)`,l.style.transform=`translate3d(${c-p}px,${d-u}px,0)`,l.offsetHeight,o.offsetHeight,l.style.transition="transform .15s",l.style.transform="translate3d(0px,0px,0)",o.style.transition="transform .15s",o.style.transform="translate3d(0px,0px,0)",setTimeout((()=>{o.style.transition="",o.style.transform="",l.style.transition="",l.style.transform=""}),150),s.stopPropagation(),s.preventDefault()};return s.each(n,((e,t)=>{e.style.position="relative",e!==o&&(e.style.pointerEvents="initial",e._uiik_i=t,e.addEventListener("mouseenter",l))})),()=>{s.each(n,((e,t)=>{e!==o&&e.removeEventListener("mouseenter",l)}))}}function ye(e,t){return new me(e,t)}var be="1.1.0";if(!globalThis.welcome){const e=[];["102,227,255","59,208,251","67,180,255"].forEach(((t,s)=>{const o="background:rgb("+t+");";e[s]=s<2?e[4-s]=o:"color:#fff;"+o})),console.info(`%c %c %c Uiik - UI interactions kit | v${be} %c %c `,...e,"💎 https://github.com/holyhigh2/uiik"),globalThis.welcome=!0}const xe=be;var we={VERSION:be,newSplittable:D,newResizable:A,newDraggable:R,newDroppable:B,newRotatable:J,newSelectable:ae,newSortable:ye};e.CollisionDetector=oe,e.Draggable=Y,e.Droppable=P,e.Resizable=W,e.Rotatable=G,e.Selectable=re,e.Sortable=me,e.Splittable=z,e.Uii=p,e.VERSION=xe,e.default=we,e.newCollisionDetector=ne,e.newDraggable=R,e.newDroppable=B,e.newResizable=A,e.newRotatable=J,e.newSelectable=ae,e.newSortable=ye,e.newSplittable=D,Object.defineProperty(e,"__esModule",{value:!0})}));
7
+ (function (global, factory) {
8
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('myfx/is'), require('myfx/collection'), require('myfx/object'), require('myfx/string'), require('myfx/array'), require('myfx'), require('myfx/utils')) :
9
+ typeof define === 'function' && define.amd ? define(['exports', 'myfx/is', 'myfx/collection', 'myfx/object', 'myfx/string', 'myfx/array', 'myfx', 'myfx/utils'], factory) :
10
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.uiik = {}, global.is, global.collection, global.object, global.string, global.array, null, global.utils));
11
+ })(this, (function (exports, is, collection, object, string, array, myfx, utils) { 'use strict';
12
+
13
+ /******************************************************************************
14
+ Copyright (c) Microsoft Corporation.
15
+
16
+ Permission to use, copy, modify, and/or distribute this software for any
17
+ purpose with or without fee is hereby granted.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
20
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
21
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
22
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25
+ PERFORMANCE OF THIS SOFTWARE.
26
+ ***************************************************************************** */
27
+
28
+ function __classPrivateFieldGet(receiver, state, kind, f) {
29
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
30
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
31
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
32
+ }
33
+
34
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
35
+ if (kind === "m") throw new TypeError("Private method is not writable");
36
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
37
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
38
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
39
+ }
40
+
41
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
42
+ var e = new Error(message);
43
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
44
+ };
45
+
46
+ const UtMap = new WeakMap();
47
+ const EXP_MATRIX$1 = /matrix\((?<a>[\d-.]+)\s*,\s*(?<b>[\d-.]+)\s*,\s*(?<c>[\d-.]+)\s*,\s*(?<d>[\d-.]+)\s*,\s*(?<x>[\d-.]+)\s*,\s*(?<y>[\d-.]+)\)/gim;
48
+ class UiiTransformer {
49
+ constructor(el) {
50
+ this.angle = 0;
51
+ this.el = el;
52
+ this.normalize(el);
53
+ UtMap.set(el, this);
54
+ }
55
+ normalize(el) {
56
+ let { x, y } = normalize(el);
57
+ this.x = x;
58
+ this.y = y;
59
+ return this;
60
+ }
61
+ moveTo(x, y) {
62
+ this.x = x;
63
+ this.y = y;
64
+ moveTo(this.el, this.x, this.y);
65
+ }
66
+ moveToX(x) {
67
+ this.x = x;
68
+ moveTo(this.el, this.x, this.y);
69
+ }
70
+ moveToY(y) {
71
+ this.y = y;
72
+ moveTo(this.el, this.x, this.y);
73
+ }
74
+ }
75
+ function normalize(el) {
76
+ const style = window.getComputedStyle(el);
77
+ let x = 0, y = 0;
78
+ if (el instanceof HTMLElement) {
79
+ x = (parseFloat(style.left) || 0) + (parseFloat(style.marginLeft) || 0);
80
+ y = (parseFloat(style.top) || 0) + (parseFloat(style.marginTop) || 0);
81
+ el.style.setProperty("left", "0", "important");
82
+ el.style.setProperty("top", "0", "important");
83
+ el.style.setProperty("margin", "0", "important");
84
+ }
85
+ else {
86
+ x = parseFloat(style.x || style.cx) || 0;
87
+ y = parseFloat(style.y || style.cy) || 0;
88
+ el.removeAttribute("x");
89
+ el.removeAttribute("y");
90
+ el.removeAttribute("cx");
91
+ el.removeAttribute("cy");
92
+ }
93
+ EXP_MATRIX$1.lastIndex = 0;
94
+ const rs = EXP_MATRIX$1.exec(window.getComputedStyle(el).transform);
95
+ if (rs && rs.groups) {
96
+ x += parseFloat(rs.groups.x) || 0;
97
+ y += parseFloat(rs.groups.y) || 0;
98
+ }
99
+ moveTo(el, x, y);
100
+ return { x, y };
101
+ }
102
+ function wrapper(el) {
103
+ let ut = UtMap.get(el);
104
+ if (ut)
105
+ return ut.normalize(el);
106
+ return new UiiTransformer(el);
107
+ }
108
+ function transformMove(transofrmStr, x, y, unit = false) {
109
+ return (`translate(${x}${unit ? "px" : ""},${y}${unit ? "px" : ""})` +
110
+ transofrmStr.replace(/translate\([^)]+?\)/, ""));
111
+ }
112
+ function getTranslate(el) {
113
+ let xVal = NaN, yVal = NaN;
114
+ let transformStr = "";
115
+ if (el instanceof SVGGraphicsElement) {
116
+ transformStr = el.getAttribute("transform") || "";
117
+ }
118
+ else {
119
+ let style = el.style;
120
+ transformStr = style.transform || "";
121
+ }
122
+ EXP_GET_TRANSLATE.lastIndex = 0;
123
+ const xy = EXP_GET_TRANSLATE.exec(transformStr);
124
+ if (xy && xy.groups) {
125
+ xVal = parseFloat(xy.groups.x);
126
+ yVal = parseFloat(xy.groups.y);
127
+ }
128
+ else {
129
+ EXP_GET_TRANSLATE_XY.lastIndex = 0;
130
+ const xy = EXP_GET_TRANSLATE_XY.exec(transformStr);
131
+ if (xy && xy.groups) {
132
+ if (xy.groups.dir == "X") {
133
+ xVal = parseFloat(xy.groups.v);
134
+ }
135
+ else {
136
+ yVal = parseFloat(xy.groups.v);
137
+ }
138
+ }
139
+ }
140
+ return { x: xVal, y: yVal };
141
+ }
142
+ function moveTo(el, x, y) {
143
+ if (el instanceof SVGGraphicsElement) {
144
+ el.setAttribute("transform", transformMove(el.getAttribute("transform") || "", x, y));
145
+ }
146
+ else {
147
+ let style = el.style;
148
+ style.transform = transformMove(style.transform || "", x, y, true);
149
+ }
150
+ }
151
+ const EXP_GET_TRANSLATE = /translate\(\s*(?<x>[\d.-]+)\D*,\s*(?<y>[\d.-]+)\D*\)/gim;
152
+ const EXP_GET_TRANSLATE_XY = /translate(?<dir>X|Y)\(\s*(?<v>[\d.-]+)\D*\)/gim;
153
+ function moveBy(el, x, y) {
154
+ const xy = getTranslate(el);
155
+ if (el instanceof SVGGraphicsElement) {
156
+ el.setAttribute("transform", transformMove(el.getAttribute("transform") || "", xy.x + x, xy.y + y));
157
+ }
158
+ else {
159
+ let style = el.style;
160
+ style.transform = transformMove(style.transform || "", xy.x + x, xy.y + y, true);
161
+ }
162
+ }
163
+ function rotateTo(el, deg, cx, cy) {
164
+ if (el instanceof SVGGraphicsElement) {
165
+ let transformStr = el.getAttribute("transform") || "";
166
+ let originPos = is.isDefined(cx) && is.isDefined(cy);
167
+ let origin = "";
168
+ if (originPos) {
169
+ if (el.x instanceof SVGAnimatedLength) {
170
+ cx += el.x.animVal.value;
171
+ cy += el.y.animVal.value;
172
+ }
173
+ else if (el.cx instanceof SVGAnimatedLength) {
174
+ cx += el.cx.animVal.value;
175
+ cy += el.cy.animVal.value;
176
+ }
177
+ origin = `,${cx},${cy}`;
178
+ }
179
+ transformStr =
180
+ transformStr.replace(/rotate\([^)]+?\)/, "") + ` rotate(${deg}${origin})`;
181
+ el.setAttribute("transform", transformStr);
182
+ }
183
+ else {
184
+ let style = el.style;
185
+ style.transform =
186
+ style.transform.replace(/rotate\([^)]+?\)/, "").replace(/rotateZ\([^)]+?\)/, "") +
187
+ " rotateZ(" +
188
+ deg +
189
+ "deg)";
190
+ }
191
+ }
192
+
193
+ const ONE_ANG = Math.PI / 180;
194
+ const ONE_RAD = 180 / Math.PI;
195
+ function getBox(child, parent) {
196
+ const rect = child.getBoundingClientRect();
197
+ const rs = { x: 0, y: 0, w: rect.width, h: rect.height };
198
+ parent =
199
+ parent ||
200
+ child.offsetParent ||
201
+ child.ownerSVGElement ||
202
+ child.parentElement ||
203
+ document.body;
204
+ const parentRect = parent.getBoundingClientRect();
205
+ const parentStyle = window.getComputedStyle(parent);
206
+ const parentBorderLeft = parseFloat(parentStyle.borderLeftWidth);
207
+ const parentBorderTop = parseFloat(parentStyle.borderTopWidth);
208
+ rs.x = rect.x - parentRect.x + parent.scrollLeft;
209
+ rs.y = rect.y - parentRect.y + parent.scrollTop;
210
+ if (child instanceof SVGElement) ;
211
+ else {
212
+ rs.x -= parentBorderLeft;
213
+ rs.y -= parentBorderTop;
214
+ }
215
+ return rs;
216
+ }
217
+ function getPointOffset(e, pos) {
218
+ let ox = e.offsetX || 0, oy = e.offsetY || 0;
219
+ if (e.target instanceof SVGElement) {
220
+ ox -= pos.x;
221
+ oy -= pos.y;
222
+ }
223
+ return [ox, oy];
224
+ }
225
+ function isSVGEl(el) {
226
+ return el instanceof SVGElement;
227
+ }
228
+ const EDGE_THRESHOLD = 5;
229
+ const DRAGGING_RULE = "body * { pointer-events: none; }";
230
+ let lockSheet;
231
+ function lockPage() {
232
+ lockSheet = getFirstSS();
233
+ lockSheet === null || lockSheet === void 0 ? void 0 : lockSheet.insertRule(DRAGGING_RULE, 0);
234
+ }
235
+ function unlockPage() {
236
+ lockSheet === null || lockSheet === void 0 ? void 0 : lockSheet.deleteRule(0);
237
+ }
238
+ function getFirstSS() {
239
+ if (document.styleSheets.length < 1) {
240
+ document.head.appendChild(document.createElement("style"));
241
+ }
242
+ const sheet = collection.find(document.styleSheets, (ss) => !ss.href);
243
+ if (!sheet) {
244
+ document.head.appendChild(document.createElement("style"));
245
+ }
246
+ return sheet || collection.find(document.styleSheets, (ss) => !ss.href);
247
+ }
248
+ let cursor = { html: "", body: "" };
249
+ function saveCursor() {
250
+ cursor.body = document.body.style.cursor;
251
+ cursor.html = document.documentElement.style.cursor;
252
+ }
253
+ function setCursor(cursor) {
254
+ document.body.style.cursor = document.documentElement.style.cursor = cursor;
255
+ }
256
+ function restoreCursor() {
257
+ document.body.style.cursor = cursor.body;
258
+ document.documentElement.style.cursor = cursor.html;
259
+ }
260
+ function getStyleXy(el) {
261
+ const style = window.getComputedStyle(el);
262
+ let x = 0, y = 0;
263
+ if (el instanceof SVGGraphicsElement) {
264
+ x = parseFloat(style.x || style.cx) || 0;
265
+ y = parseFloat(style.y || style.cy) || 0;
266
+ }
267
+ else {
268
+ x = parseFloat(style.left) || 0;
269
+ y = parseFloat(style.top) || 0;
270
+ }
271
+ return { x, y };
272
+ }
273
+ const EXP_MATRIX = /matrix\((?<a>[\d.-]+)\s*,\s*(?<b>[\d.-]+)\s*,\s*(?<c>[\d.-]+)\s*,\s*(?<d>[\d.-]+)\s*,\s*(?<x>[\d.-]+)\s*,\s*(?<y>[\d.-]+)\s*\)/;
274
+ function getMatrixInfo(elCStyle) {
275
+ let a = 1, b = 0, x = 0, y = 0;
276
+ let e = undefined, f = undefined;
277
+ if (elCStyle instanceof SVGGraphicsElement) {
278
+ const transMatrix = elCStyle.transform.animVal[0];
279
+ if (transMatrix) {
280
+ e = transMatrix.matrix.e;
281
+ f = transMatrix.matrix.f;
282
+ }
283
+ elCStyle = window.getComputedStyle(elCStyle);
284
+ }
285
+ else {
286
+ if (elCStyle instanceof HTMLElement) {
287
+ elCStyle = window.getComputedStyle(elCStyle);
288
+ }
289
+ }
290
+ const matched = elCStyle.transform.match(EXP_MATRIX);
291
+ if (matched && matched.groups) {
292
+ a = parseFloat(matched.groups.a);
293
+ b = parseFloat(matched.groups.b);
294
+ parseFloat(matched.groups.c);
295
+ parseFloat(matched.groups.d);
296
+ x = parseFloat(matched.groups.x);
297
+ y = parseFloat(matched.groups.y);
298
+ }
299
+ if (e && f) {
300
+ x = e;
301
+ y = f;
302
+ }
303
+ const rs = { scale: 1, angle: 0, x, y };
304
+ rs.scale = Math.sqrt(a * a + b * b);
305
+ rs.angle = Math.round(Math.atan2(b, a) * (180 / Math.PI));
306
+ return rs;
307
+ }
308
+ function getPointInContainer(event, el, elRect, elCStyle, matrixInfo) {
309
+ if (!elRect) {
310
+ elRect = el.getBoundingClientRect();
311
+ }
312
+ if (!elCStyle) {
313
+ elCStyle = window.getComputedStyle(el);
314
+ }
315
+ if (!matrixInfo) {
316
+ matrixInfo = getMatrixInfo(elCStyle);
317
+ }
318
+ const scale = matrixInfo.scale;
319
+ let x = event.clientX -
320
+ elRect.x -
321
+ (parseFloat(elCStyle.borderLeftWidth) || 0) * scale +
322
+ el.scrollLeft * scale;
323
+ let y = event.clientY -
324
+ elRect.y -
325
+ (parseFloat(elCStyle.borderTopWidth) || 0) * scale +
326
+ el.scrollTop * scale;
327
+ return { x: x / scale, y: y / scale };
328
+ }
329
+ function getRectInContainer(el, container) {
330
+ const elRect = el.getBoundingClientRect();
331
+ const containerRect = container.getBoundingClientRect();
332
+ const elCStyle = window.getComputedStyle(container);
333
+ const matrixInfo = getMatrixInfo(elCStyle);
334
+ const scale = matrixInfo.scale;
335
+ let x = elRect.x -
336
+ containerRect.x -
337
+ (parseFloat(elCStyle.borderLeftWidth) || 0) * scale +
338
+ container.scrollLeft * scale;
339
+ let y = elRect.y -
340
+ containerRect.y -
341
+ (parseFloat(elCStyle.borderTopWidth) || 0) * scale +
342
+ container.scrollTop * scale;
343
+ return {
344
+ x: x / scale,
345
+ y: y / scale,
346
+ w: elRect.width / scale,
347
+ h: elRect.height / scale,
348
+ };
349
+ }
350
+ function getCenterXy(el) {
351
+ const cStyle = window.getComputedStyle(el);
352
+ const center = cStyle.transformOrigin;
353
+ const centerPair = center.split(" ");
354
+ const ox = parseFloat(centerPair[0]);
355
+ const oy = parseFloat(centerPair[1]);
356
+ const shadowDom = el.cloneNode();
357
+ rotateTo(shadowDom, 0);
358
+ const parentEl = el.parentElement;
359
+ let startX = 0, startY = 0;
360
+ if (parentEl) {
361
+ parentEl.appendChild(shadowDom);
362
+ const offsetXY = getRectInContainer(shadowDom, parentEl);
363
+ (startX = offsetXY.x), (startY = offsetXY.y);
364
+ parentEl.removeChild(shadowDom);
365
+ }
366
+ return { sx: startX, sy: startY, x: startX + ox, y: startY + oy, ox, oy };
367
+ }
368
+
369
+ var _Uii_listeners;
370
+ class Uii {
371
+ constructor(ele, opts) {
372
+ this.enabled = true;
373
+ _Uii_listeners.set(this, []);
374
+ this.opts = opts || {};
375
+ if (is.isArrayLike(ele) && !is.isString(ele)) {
376
+ this.ele = collection.map(ele, (el) => {
377
+ let e = is.isString(el) ? document.querySelector(el) : el;
378
+ if (!is.isElement(e)) {
379
+ console.error('Invalid element "' + el + '"');
380
+ return false;
381
+ }
382
+ return e;
383
+ });
384
+ }
385
+ else {
386
+ if (is.isString(ele)) {
387
+ this.eleString = ele;
388
+ }
389
+ const el = is.isString(ele) ? document.querySelectorAll(ele) : ele;
390
+ if (!is.isElement(el) && !is.isArrayLike(el)) {
391
+ console.error('Invalid element "' + ele + '"');
392
+ return;
393
+ }
394
+ this.ele = is.isArrayLike(el) ? collection.toArray(el) : [el];
395
+ }
396
+ }
397
+ destroy() {
398
+ collection.each(__classPrivateFieldGet(this, _Uii_listeners, "f"), (ev) => {
399
+ ev[0].removeEventListener(ev[1], ev[2], ev[3]);
400
+ });
401
+ __classPrivateFieldSet(this, _Uii_listeners, [], "f");
402
+ }
403
+ addPointerDown(el, pointerDown, opts) {
404
+ const onPointerDown = pointerDown;
405
+ const threshold = opts.threshold || 0;
406
+ const toLockPage = opts.lockPage || false;
407
+ const uiiOptions = this.opts;
408
+ this.registerEvent(el, 'mousedown', (e) => {
409
+ let t = e.target;
410
+ if (!t)
411
+ return;
412
+ const hasCursor = !is.isEmpty(object.get(uiiOptions, 'cursor.active'));
413
+ const currentStyle = el.style;
414
+ const currentCStyle = window.getComputedStyle(el);
415
+ const currentRect = el.getBoundingClientRect();
416
+ let dragging = false;
417
+ const originPosX = e.clientX;
418
+ const originPosY = e.clientY;
419
+ if (hasCursor) {
420
+ saveCursor();
421
+ }
422
+ let onPointerStart;
423
+ let onPointerMove;
424
+ let onPointerEnd;
425
+ onPointerDown({
426
+ onPointerMove: (pm) => { onPointerMove = pm; },
427
+ onPointerStart: (ps) => { onPointerStart = ps; },
428
+ onPointerEnd: (pe) => { onPointerEnd = pe; },
429
+ ev: e,
430
+ pointX: e.clientX, pointY: e.clientY, target: t,
431
+ currentTarget: el, currentStyle, currentCStyle, currentRect
432
+ });
433
+ const pointerMove = (ev) => {
434
+ const offX = ev.clientX - originPosX;
435
+ const offY = ev.clientY - originPosY;
436
+ if (!dragging) {
437
+ if (Math.abs(offX) > threshold || Math.abs(offY) > threshold) {
438
+ dragging = true;
439
+ if (toLockPage) {
440
+ lockPage();
441
+ }
442
+ if (hasCursor) {
443
+ setCursor(uiiOptions.cursor.active);
444
+ }
445
+ onPointerMove && onPointerStart({ ev });
446
+ }
447
+ else {
448
+ ev.preventDefault();
449
+ return false;
450
+ }
451
+ }
452
+ onPointerMove && onPointerMove({ ev, pointX: ev.clientX, pointY: ev.clientY, offX, offY, currentStyle, currentCStyle });
453
+ };
454
+ const pointerEnd = (ev) => {
455
+ document.removeEventListener('mousemove', pointerMove, false);
456
+ document.removeEventListener('mouseup', pointerEnd, false);
457
+ window.removeEventListener('blur', pointerEnd, false);
458
+ if (dragging) {
459
+ if (toLockPage) {
460
+ unlockPage();
461
+ }
462
+ if (hasCursor) {
463
+ restoreCursor();
464
+ }
465
+ onPointerEnd && onPointerEnd({ ev, currentStyle });
466
+ }
467
+ };
468
+ document.addEventListener("mousemove", pointerMove);
469
+ document.addEventListener("mouseup", pointerEnd);
470
+ window.addEventListener("blur", pointerEnd);
471
+ e.preventDefault();
472
+ return false;
473
+ }, true);
474
+ }
475
+ registerEvent(el, event, hook, useCapture = false) {
476
+ const wrapper = ((ev) => {
477
+ if (!this.enabled)
478
+ return;
479
+ hook(ev);
480
+ }).bind(this);
481
+ el.addEventListener(event, wrapper, useCapture);
482
+ __classPrivateFieldGet(this, _Uii_listeners, "f").push([el, event, wrapper, useCapture]);
483
+ }
484
+ disable() {
485
+ this.enabled = false;
486
+ }
487
+ enable() {
488
+ this.enabled = true;
489
+ }
490
+ getOptions() {
491
+ return this.opts;
492
+ }
493
+ getOption(name) {
494
+ return this.opts[name];
495
+ }
496
+ setOptions(options) {
497
+ object.assign(this.opts, options);
498
+ this.onOptionChanged(this.opts);
499
+ }
500
+ setOption(name, value) {
501
+ this.opts[name] = value;
502
+ this.onOptionChanged(this.opts);
503
+ }
504
+ onOptionChanged(opts) { }
505
+ }
506
+ _Uii_listeners = new WeakMap();
507
+
508
+ var _Splittable_instances, _Splittable_checkDirection, _Splittable_bindHandle;
509
+ const THRESHOLD$4 = 1;
510
+ const CLASS_SPLITTABLE = "uii-splittable";
511
+ const CLASS_SPLITTABLE_HANDLE = "uii-splittable-handle";
512
+ const CLASS_SPLITTABLE_HANDLE_GHOST = "uii-splittable-handle-ghost";
513
+ const CLASS_SPLITTABLE_HANDLE_ACTIVE = "uii-splittable-handle-active";
514
+ const CLASS_SPLITTABLE_V = "uii-splittable-v";
515
+ const CLASS_SPLITTABLE_H = "uii-splittable-h";
516
+ function getRootEl(el, root) {
517
+ let rs = el.parentNode;
518
+ while (rs && rs.parentNode !== root) {
519
+ rs = rs.parentNode;
520
+ }
521
+ return rs;
522
+ }
523
+ class Splittable extends Uii {
524
+ constructor(container, opts) {
525
+ super(container, object.assign({
526
+ handleSize: 10,
527
+ minSize: 0,
528
+ sticky: false,
529
+ inside: false,
530
+ ghost: false
531
+ }, opts));
532
+ _Splittable_instances.add(this);
533
+ collection.each(this.ele, con => {
534
+ const pos = window.getComputedStyle(con).position;
535
+ if (pos === "static") {
536
+ con.style.position = "relative";
537
+ }
538
+ con.classList.toggle(CLASS_SPLITTABLE, true);
539
+ const handleDoms = con.querySelectorAll(this.opts.handle);
540
+ const children = collection.reject(con.children, c => {
541
+ if (collection.includes(handleDoms, c))
542
+ return true;
543
+ return false;
544
+ });
545
+ const dir = __classPrivateFieldGet(this, _Splittable_instances, "m", _Splittable_checkDirection).call(this, con);
546
+ con.classList.toggle(dir === 'v' ? CLASS_SPLITTABLE_V : CLASS_SPLITTABLE_H, true);
547
+ const minSizeAry = collection.map(children, (c, i) => {
548
+ if (is.isArray(this.opts.minSize)) {
549
+ return this.opts.minSize[i] || 0;
550
+ }
551
+ else {
552
+ return this.opts.minSize;
553
+ }
554
+ });
555
+ const stickyAry = collection.map(children, (c, i) => {
556
+ if (is.isArray(this.opts.sticky)) {
557
+ return this.opts.sticky[i] || false;
558
+ }
559
+ else {
560
+ return this.opts.sticky;
561
+ }
562
+ });
563
+ if (is.isEmpty(handleDoms)) {
564
+ const len = children.length - 1;
565
+ for (let i = 0; i < len; i++) {
566
+ __classPrivateFieldGet(this, _Splittable_instances, "m", _Splittable_bindHandle).call(this, minSizeAry.slice(i, i + 2), stickyAry.slice(i, i + 2), this.opts, dir, children[i], children[i + 1]);
567
+ }
568
+ }
569
+ else {
570
+ collection.each(handleDoms, (h, i) => {
571
+ const isRoot = h.parentNode.classList.contains(CLASS_SPLITTABLE);
572
+ let dom1, dom2;
573
+ if (isRoot) {
574
+ dom1 = h.previousElementSibling;
575
+ dom2 = h.nextElementSibling;
576
+ }
577
+ else {
578
+ dom2 = getRootEl(h, con);
579
+ dom1 = dom2.previousElementSibling;
580
+ }
581
+ __classPrivateFieldGet(this, _Splittable_instances, "m", _Splittable_bindHandle).call(this, minSizeAry.slice(i, i + 2), stickyAry.slice(i, i + 2), this.opts, dir, dom1, dom2, h);
582
+ });
583
+ }
584
+ });
585
+ }
586
+ }
587
+ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Splittable_checkDirection(container) {
588
+ let dir = 'h';
589
+ const child = container.children[0];
590
+ let lastY = child.offsetTop;
591
+ collection.each(container.children, c => {
592
+ if (c.offsetTop != lastY) {
593
+ dir = 'v';
594
+ return false;
595
+ }
596
+ });
597
+ return dir;
598
+ }, _Splittable_bindHandle = function _Splittable_bindHandle(minSizeAry, stickyAry, opts, dir, dom1, dom2, handle) {
599
+ var _a;
600
+ const handleSize = opts.handleSize;
601
+ if (!handle) {
602
+ handle = document.createElement('div');
603
+ let initPos = 0;
604
+ if (!opts.inside) {
605
+ initPos = (dir === 'v' ? dom2.offsetTop : dom2.offsetLeft);
606
+ }
607
+ const sensorHCss = `width:${handleSize}px;height:100%;top:0;left:${initPos - handleSize / 2}px;z-index:9;`;
608
+ const sensorVCss = `height:${handleSize}px;width:100%;left:0;top:${initPos - handleSize / 2}px;z-index:9;`;
609
+ handle.style.cssText =
610
+ 'position: absolute;' + (dir === 'v' ? sensorVCss : sensorHCss);
611
+ if (opts.inside) {
612
+ dom2.appendChild(handle);
613
+ }
614
+ (_a = dom2.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(handle, dom2);
615
+ }
616
+ handle.style.cursor = dir === 'v' ? 's-resize' : 'e-resize';
617
+ handle.dataset.cursor = handle.style.cursor;
618
+ handle.classList.add(CLASS_SPLITTABLE_HANDLE);
619
+ const minSize1 = minSizeAry[0];
620
+ const minSize2 = minSizeAry[1];
621
+ let sticky1 = stickyAry[0];
622
+ let sticky2 = stickyAry[1];
623
+ const onStart = opts.onStart;
624
+ const onSplit = opts.onSplit;
625
+ const onEnd = opts.onEnd;
626
+ const onSticky = opts.onSticky;
627
+ const onClone = opts.onClone;
628
+ const oneSideMode = opts.oneSideMode;
629
+ const updateStart = !oneSideMode || oneSideMode === 'start';
630
+ const updateEnd = !oneSideMode || oneSideMode === 'end';
631
+ this.addPointerDown(handle, ({ currentTarget, onPointerStart, onPointerMove, onPointerEnd }) => {
632
+ let originSize = 0;
633
+ let originSize1 = 0;
634
+ let splitterSize = 1;
635
+ let blockSize = 0;
636
+ switch (dir) {
637
+ case 'v':
638
+ originSize = dom1.offsetHeight;
639
+ originSize1 = dom2.offsetHeight;
640
+ splitterSize = currentTarget.offsetHeight;
641
+ break;
642
+ case 'h':
643
+ originSize = dom1.offsetWidth;
644
+ originSize1 = dom2.offsetWidth;
645
+ splitterSize = currentTarget.offsetWidth;
646
+ break;
647
+ }
648
+ blockSize = splitterSize + originSize + originSize1;
649
+ const dom1Style = dom1.style;
650
+ const dom2Style = dom2.style;
651
+ const ghost = opts.ghost;
652
+ const ghostClass = opts.ghostClass;
653
+ let ghostNode = null;
654
+ let sticked = 'none';
655
+ if (originSize < minSize1 / 2) {
656
+ sticked = 'start';
657
+ }
658
+ else if (blockSize - originSize - splitterSize < minSize2 / 2) {
659
+ sticked = 'end';
660
+ }
661
+ let startPos = dir === 'v' ? dom1.offsetTop : dom1.offsetLeft;
662
+ let ds1, anotherSize;
663
+ onPointerStart(function (args) {
664
+ const { ev } = args;
665
+ currentTarget.classList.add(CLASS_SPLITTABLE_HANDLE_ACTIVE);
666
+ if (ghost) {
667
+ ghostNode = currentTarget.cloneNode(true);
668
+ ghostNode.style.opacity = '0.3';
669
+ ghostNode.style.pointerEvents = 'none';
670
+ ghostNode.classList.add(CLASS_SPLITTABLE_HANDLE_GHOST);
671
+ if (ghostNode) {
672
+ if (ghostClass) {
673
+ ghostNode.className =
674
+ ghostNode.className.replace(ghostClass, '') + ' ' + ghostClass;
675
+ }
676
+ currentTarget.parentNode.appendChild(ghostNode);
677
+ onClone && onClone({ clone: ghostNode }, ev);
678
+ }
679
+ }
680
+ onStart && onStart({ size1: originSize, size2: originSize1 }, ev);
681
+ });
682
+ onPointerMove((args) => {
683
+ const { ev, offX, offY, currentStyle } = args;
684
+ let doSticky = false;
685
+ ds1 = dir === 'v' ? originSize + offY : originSize + offX;
686
+ if (ds1 < minSize1 / 2 && sticky1 && minSize1 > 0) {
687
+ if (sticked == 'none') {
688
+ doSticky = true;
689
+ sticked = 'start';
690
+ }
691
+ ds1 = 0;
692
+ }
693
+ else if (ds1 < minSize1) {
694
+ ds1 = minSize1;
695
+ if (sticked == 'start' && sticky1) {
696
+ doSticky = true;
697
+ sticked = 'none';
698
+ }
699
+ }
700
+ else if (blockSize - ds1 - splitterSize < minSize2 / 2 &&
701
+ sticky2) {
702
+ if (sticked == 'none') {
703
+ doSticky = true;
704
+ sticked = 'end';
705
+ }
706
+ ds1 = blockSize - splitterSize;
707
+ }
708
+ else if (blockSize - ds1 - splitterSize < minSize2) {
709
+ ds1 = blockSize - minSize2 - splitterSize;
710
+ if (sticked == 'end' && sticky2) {
711
+ doSticky = true;
712
+ sticked = 'none';
713
+ }
714
+ }
715
+ anotherSize = blockSize - ds1 - splitterSize;
716
+ if (ghostNode) {
717
+ if (dir === 'v') {
718
+ ghostNode.style.top = startPos + ds1 - handleSize / 2 + 'px';
719
+ }
720
+ else {
721
+ ghostNode.style.left = startPos + ds1 - handleSize / 2 + 'px';
722
+ console.log(ghostNode.style.left);
723
+ }
724
+ }
725
+ else {
726
+ const updateProp = dir === 'v' ? 'height' : 'width';
727
+ if (updateStart) {
728
+ dom1Style.setProperty(updateProp, ds1 + 'px', 'important');
729
+ }
730
+ if (updateEnd) {
731
+ dom2Style.setProperty(updateProp, anotherSize + 'px', 'important');
732
+ }
733
+ if (doSticky) {
734
+ onSticky && onSticky({ size1: ds1, size2: anotherSize, position: sticked }, ev);
735
+ }
736
+ if (dir === 'v') {
737
+ currentStyle.top = dom2.offsetTop - handleSize / 2 + 'px';
738
+ }
739
+ else {
740
+ currentStyle.left = dom2.offsetLeft - handleSize / 2 + 'px';
741
+ }
742
+ }
743
+ onSplit && onSplit({ size1: ds1, size2: anotherSize }, ev);
744
+ });
745
+ onPointerEnd((args) => {
746
+ var _a, _b;
747
+ const { ev, currentStyle } = args;
748
+ switch (dir) {
749
+ case 'v':
750
+ originSize = (dom1 === null || dom1 === void 0 ? void 0 : dom1.offsetHeight) || -1;
751
+ originSize1 = (dom2 === null || dom2 === void 0 ? void 0 : dom2.offsetHeight) || -1;
752
+ break;
753
+ case 'h':
754
+ originSize = (dom1 === null || dom1 === void 0 ? void 0 : dom1.offsetWidth) || -1;
755
+ originSize1 = (dom2 === null || dom2 === void 0 ? void 0 : dom2.offsetWidth) || -1;
756
+ break;
757
+ }
758
+ handle === null || handle === void 0 ? void 0 : handle.classList.remove(CLASS_SPLITTABLE_HANDLE_ACTIVE);
759
+ if (ghostNode) {
760
+ const updateProp = dir === 'v' ? 'height' : 'width';
761
+ if (updateStart) {
762
+ dom1Style.setProperty(updateProp, ds1 + 'px', 'important');
763
+ }
764
+ if (updateEnd) {
765
+ dom2Style.setProperty(updateProp, anotherSize + 'px', 'important');
766
+ }
767
+ if (dir === 'v') {
768
+ currentStyle.top = startPos + ds1 - handleSize / 2 + 'px';
769
+ }
770
+ else {
771
+ currentStyle.left = startPos + ds1 - handleSize / 2 + 'px';
772
+ }
773
+ ((_a = ghostNode.parentNode) === null || _a === void 0 ? void 0 : _a.contains(ghostNode)) && ((_b = ghostNode.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(ghostNode));
774
+ }
775
+ onEnd && onEnd({ size1: originSize, size2: originSize1 }, ev);
776
+ });
777
+ }, {
778
+ threshold: THRESHOLD$4,
779
+ lockPage: true
780
+ });
781
+ };
782
+ function newSplittable(container, opts) {
783
+ return new Splittable(container, opts);
784
+ }
785
+
786
+ const THRESHOLD$3 = 2;
787
+ const CLASS_RESIZABLE_HANDLE = "uii-resizable-handle";
788
+ const CLASS_RESIZABLE_HANDLE_DIR = "uii-resizable-handle-";
789
+ const CLASS_RESIZABLE_HANDLE_ACTIVE = "uii-resizable-handle-active";
790
+ const EXP_DIR = new RegExp(CLASS_RESIZABLE_HANDLE_DIR + "(?<dir>[nesw]+)");
791
+ class Resizable extends Uii {
792
+ constructor(els, opts) {
793
+ super(els, object.assign({
794
+ handleSize: 8,
795
+ minSize: 50,
796
+ dir: ["n", "s", "e", "w", "ne", "nw", "se", "sw"],
797
+ ghost: false,
798
+ offset: 0,
799
+ }, opts));
800
+ collection.each(this.ele, (el) => {
801
+ this.initHandle(el);
802
+ });
803
+ }
804
+ bindHandle(handle, dir, panel, opts) {
805
+ const onStart = opts.onStart;
806
+ const onResize = opts.onResize;
807
+ const onEnd = opts.onEnd;
808
+ const onClone = opts.onClone;
809
+ const uiik = this;
810
+ this.addPointerDown(handle, ({ ev, onPointerStart, onPointerMove, onPointerEnd }) => {
811
+ const onPointerDown = opts.onPointerDown;
812
+ if (onPointerDown && onPointerDown(ev) === false)
813
+ return;
814
+ let matrixInfo = getMatrixInfo(panel);
815
+ const offset = getRectInContainer(panel, panel.parentElement);
816
+ const offsetParentRect = panel.parentElement.getBoundingClientRect();
817
+ const offsetParentCStyle = window.getComputedStyle(panel.parentElement);
818
+ const panelCStyle = window.getComputedStyle(panel);
819
+ const originW = parseFloat(panelCStyle.width);
820
+ const originH = parseFloat(panelCStyle.height);
821
+ const originX = offset.x;
822
+ const originY = offset.y;
823
+ let changeW = false;
824
+ let changeH = false;
825
+ let changeX = false;
826
+ let changeY = false;
827
+ let toTransformOrigin = "";
828
+ switch (dir) {
829
+ case "s":
830
+ changeH = true;
831
+ break;
832
+ case "e":
833
+ changeW = true;
834
+ break;
835
+ case "se":
836
+ changeW = true;
837
+ changeH = true;
838
+ break;
839
+ case "n":
840
+ changeX = true;
841
+ changeY = true;
842
+ changeH = true;
843
+ toTransformOrigin = "0 0";
844
+ break;
845
+ case "w":
846
+ changeX = true;
847
+ changeY = true;
848
+ changeW = true;
849
+ toTransformOrigin = "0 0";
850
+ break;
851
+ case "sw":
852
+ case "ne":
853
+ case "nw":
854
+ changeX = true;
855
+ changeY = true;
856
+ changeW = true;
857
+ changeH = true;
858
+ toTransformOrigin = "0 0";
859
+ break;
860
+ }
861
+ let minWidth;
862
+ let minHeight;
863
+ let maxWidth;
864
+ let maxHeight;
865
+ if (is.isArray(opts.minSize)) {
866
+ minWidth = opts.minSize[0];
867
+ minHeight = opts.minSize[1];
868
+ }
869
+ else if (is.isNumber(opts.minSize)) {
870
+ minWidth = opts.minSize;
871
+ minHeight = opts.minSize;
872
+ }
873
+ if (is.isArray(opts.maxSize)) {
874
+ maxWidth = opts.maxSize[0];
875
+ maxHeight = opts.maxSize[1];
876
+ }
877
+ else if (is.isNumber(opts.maxSize)) {
878
+ maxWidth = opts.maxSize;
879
+ maxHeight = opts.maxSize;
880
+ }
881
+ const ghost = opts.ghost;
882
+ const ghostClass = opts.ghostClass;
883
+ let ghostNode = null;
884
+ const aspectRatio = opts.aspectRatio;
885
+ const panelStyle = panel.style;
886
+ let style = panelStyle;
887
+ let currentW = originW;
888
+ let currentH = originH;
889
+ let transformer;
890
+ let lastX = 0, lastY = 0;
891
+ let originalTransformOrigin = "";
892
+ let originVertex;
893
+ let vertexBeforeTransform;
894
+ let currentVertex;
895
+ let refPoint;
896
+ let k1;
897
+ onPointerStart(function (args) {
898
+ var _a;
899
+ const { ev } = args;
900
+ handle.classList.add(CLASS_RESIZABLE_HANDLE_ACTIVE);
901
+ if (ghost) {
902
+ if (is.isFunction(ghost)) {
903
+ ghostNode = ghost(panel);
904
+ }
905
+ else {
906
+ ghostNode = panel.cloneNode(true);
907
+ ghostNode.style.opacity = "0.3";
908
+ ghostNode.style.pointerEvents = "none";
909
+ }
910
+ if (ghostNode) {
911
+ if (ghostClass) {
912
+ ghostNode.className =
913
+ ghostNode.className.replace(ghostClass, "") +
914
+ " " +
915
+ ghostClass;
916
+ }
917
+ (_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(ghostNode);
918
+ transformer = wrapper(ghostNode);
919
+ onClone && onClone({ clone: ghostNode }, ev);
920
+ }
921
+ style = ghostNode === null || ghostNode === void 0 ? void 0 : ghostNode.style;
922
+ }
923
+ else {
924
+ transformer = wrapper(panel);
925
+ }
926
+ const { x, y, sx, sy } = getCenterXy(panel);
927
+ let centerX = x, centerY = y;
928
+ const deg = matrixInfo.angle * ONE_ANG;
929
+ originVertex = [
930
+ { x: 0, y: 0 },
931
+ { x: originW, y: 0 },
932
+ { x: 0, y: originH },
933
+ { x: originW, y: originH },
934
+ ];
935
+ currentVertex = vertexBeforeTransform = collection.map(originVertex, ({ x, y }) => {
936
+ const nx = (x - centerX + sx) * Math.cos(deg) -
937
+ (y - centerY + sy) * Math.sin(deg);
938
+ const ny = (x - centerX + sx) * Math.sin(deg) +
939
+ (y - centerY + sy) * Math.cos(deg);
940
+ return { x: centerX + nx, y: centerY + ny };
941
+ });
942
+ switch (dir) {
943
+ case "s":
944
+ case "e":
945
+ case "se":
946
+ refPoint = currentVertex[0];
947
+ break;
948
+ case "n":
949
+ case "w":
950
+ case "nw":
951
+ refPoint = currentVertex[3];
952
+ break;
953
+ case "sw":
954
+ refPoint = currentVertex[1];
955
+ break;
956
+ case "ne":
957
+ refPoint = currentVertex[2];
958
+ break;
959
+ }
960
+ k1 =
961
+ (currentVertex[1].y - refPoint.y) /
962
+ (currentVertex[1].x - refPoint.x);
963
+ style.transition = "none";
964
+ originalTransformOrigin = style.transformOrigin;
965
+ if (toTransformOrigin) {
966
+ style.transformOrigin = toTransformOrigin;
967
+ }
968
+ else {
969
+ style.transformOrigin = `${centerX - transformer.x}px ${centerY - transformer.y}px`;
970
+ }
971
+ onStart && onStart.call(uiik, { w: originW, h: originH }, ev);
972
+ });
973
+ onPointerMove((args) => {
974
+ const { ev } = args;
975
+ const currentXy = getPointInContainer(ev, panel.parentElement, offsetParentRect, offsetParentCStyle);
976
+ let newX = currentXy.x;
977
+ let newY = currentXy.y;
978
+ let angle = Math.atan2(newY - refPoint.y, newX - refPoint.x) * ONE_RAD -
979
+ matrixInfo.angle;
980
+ let hyLen = Math.sqrt((newX - refPoint.x) * (newX - refPoint.x) +
981
+ (newY - refPoint.y) * (newY - refPoint.y));
982
+ let pl1 = Math.abs(k1 === Infinity
983
+ ? newY - refPoint.y
984
+ : hyLen * Math.cos(angle * ONE_ANG));
985
+ let pl2 = Math.sqrt(hyLen * hyLen - pl1 * pl1);
986
+ let w = originW;
987
+ let h = originH;
988
+ let y = originY;
989
+ let x = originX;
990
+ let angl = 0;
991
+ switch (dir) {
992
+ case "s":
993
+ h = pl2;
994
+ break;
995
+ case "e":
996
+ w = pl1;
997
+ break;
998
+ case "se":
999
+ w = pl1;
1000
+ h = pl2;
1001
+ break;
1002
+ case "n":
1003
+ h = pl2;
1004
+ angl =
1005
+ Math.atan2(currentVertex[0].y - currentVertex[2].y, currentVertex[0].x - currentVertex[2].x) * ONE_RAD;
1006
+ let plh;
1007
+ if (angl === 90) {
1008
+ h = newY - currentVertex[2].y;
1009
+ x = currentVertex[2].x;
1010
+ y = newY;
1011
+ }
1012
+ else if (currentVertex[2].y > currentVertex[0].y) {
1013
+ plh = h * Math.cos(angl * ONE_ANG);
1014
+ x = currentVertex[2].x + plh;
1015
+ y = currentVertex[2].y - Math.sqrt(h * h - plh * plh);
1016
+ }
1017
+ else {
1018
+ plh = h * Math.cos((180 - angl) * ONE_ANG);
1019
+ x = currentVertex[2].x - plh;
1020
+ y = currentVertex[2].y + Math.sqrt(h * h - plh * plh);
1021
+ }
1022
+ break;
1023
+ case "w":
1024
+ w = pl1;
1025
+ angl =
1026
+ Math.atan2(currentVertex[0].y - currentVertex[1].y, currentVertex[0].x - currentVertex[1].x) * ONE_RAD;
1027
+ let plw;
1028
+ if (angl === 0) {
1029
+ w = newX - currentVertex[1].x;
1030
+ x = newX;
1031
+ y = currentVertex[1].y;
1032
+ }
1033
+ else if (currentVertex[1].y > currentVertex[0].y) {
1034
+ plw = w * Math.cos((180 - angl) * ONE_ANG);
1035
+ x = currentVertex[1].x - plw;
1036
+ y = currentVertex[1].y - Math.sqrt(w * w - plw * plw);
1037
+ }
1038
+ else {
1039
+ plw = w * Math.cos(angl * ONE_ANG);
1040
+ x = currentVertex[1].x + plw;
1041
+ y = currentVertex[1].y + Math.sqrt(w * w - plw * plw);
1042
+ }
1043
+ break;
1044
+ case "nw":
1045
+ w = pl1;
1046
+ h = pl2;
1047
+ x = newX;
1048
+ y = newY;
1049
+ if (matrixInfo.angle === 180) {
1050
+ w = newX - currentVertex[3].x;
1051
+ h = newY - currentVertex[3].y;
1052
+ }
1053
+ break;
1054
+ case "sw":
1055
+ w = pl1;
1056
+ h = pl2;
1057
+ angl =
1058
+ Math.atan2(currentVertex[0].y - currentVertex[1].y, currentVertex[0].x - currentVertex[1].x) * ONE_RAD;
1059
+ let plw1;
1060
+ if (angl === 0) {
1061
+ x = newX;
1062
+ y = currentVertex[0].y;
1063
+ }
1064
+ else if (currentVertex[1].y > currentVertex[0].y) {
1065
+ plw1 = w * Math.cos((180 - angl) * ONE_ANG);
1066
+ x = currentVertex[1].x - plw1;
1067
+ y = currentVertex[1].y - Math.sqrt(w * w - plw1 * plw1);
1068
+ }
1069
+ else {
1070
+ plw1 = w * Math.cos((180 - angl) * ONE_ANG);
1071
+ x = currentVertex[1].x - plw1;
1072
+ y = currentVertex[1].y + Math.sqrt(w * w - plw1 * plw1);
1073
+ }
1074
+ break;
1075
+ case "ne":
1076
+ w = pl1;
1077
+ h = pl2;
1078
+ angl =
1079
+ Math.atan2(currentVertex[0].y - currentVertex[2].y, currentVertex[0].x - currentVertex[2].x) * ONE_RAD;
1080
+ let plne;
1081
+ if (angl === 0) {
1082
+ x = newX;
1083
+ y = currentVertex[0].y;
1084
+ }
1085
+ else if (currentVertex[1].x > currentVertex[0].x) {
1086
+ plne = h * Math.cos((180 - angl) * ONE_ANG);
1087
+ x = currentVertex[2].x - plne;
1088
+ y = currentVertex[2].y - Math.sqrt(h * h - plne * plne);
1089
+ }
1090
+ else {
1091
+ plne = h * Math.cos(angl * ONE_ANG);
1092
+ x = currentVertex[2].x + plne;
1093
+ y = currentVertex[2].y + Math.sqrt(h * h - plne * plne);
1094
+ }
1095
+ break;
1096
+ }
1097
+ if (changeW) {
1098
+ if (minWidth && w < minWidth)
1099
+ w = minWidth;
1100
+ if (maxWidth && w > maxWidth)
1101
+ w = maxWidth;
1102
+ }
1103
+ if (changeH) {
1104
+ if (minHeight && h < minHeight)
1105
+ h = minHeight;
1106
+ if (maxHeight && h > maxHeight)
1107
+ h = maxHeight;
1108
+ }
1109
+ if (aspectRatio) {
1110
+ if (changeW) {
1111
+ style.width = w + "px";
1112
+ style.height = w / aspectRatio + "px";
1113
+ }
1114
+ if (changeH && dir !== "sw") {
1115
+ if (dir === "nw") {
1116
+ y = originY - w / aspectRatio + originH;
1117
+ }
1118
+ else {
1119
+ style.width = h * aspectRatio + "px";
1120
+ style.height = h + "px";
1121
+ }
1122
+ }
1123
+ }
1124
+ else {
1125
+ if (changeW) {
1126
+ style.width = w + "px";
1127
+ }
1128
+ if (changeH) {
1129
+ style.height = h + "px";
1130
+ }
1131
+ }
1132
+ if (changeY) {
1133
+ transformer.moveToY(y);
1134
+ }
1135
+ if (changeX) {
1136
+ transformer.moveToX(x);
1137
+ }
1138
+ lastX = x;
1139
+ lastY = y;
1140
+ currentW = w;
1141
+ currentH = h;
1142
+ onResize &&
1143
+ onResize.call(uiik, { w, h, ow: w - originW, oh: h - originH }, ev);
1144
+ });
1145
+ onPointerEnd((args) => {
1146
+ var _a, _b;
1147
+ const { ev } = args;
1148
+ if (ghost && ghostNode) {
1149
+ ((_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.contains(ghostNode)) &&
1150
+ ((_b = panel.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(ghostNode));
1151
+ panelStyle.left = ghostNode.style.left;
1152
+ panelStyle.top = ghostNode.style.top;
1153
+ moveTo(panel, lastX / matrixInfo.scale, lastY / matrixInfo.scale);
1154
+ panelStyle.width = ghostNode.style.width;
1155
+ panelStyle.height = ghostNode.style.height;
1156
+ }
1157
+ panel.style.transformOrigin = originalTransformOrigin;
1158
+ const { x, y, sx, sy } = getCenterXy(panel);
1159
+ let centerX = x, centerY = y;
1160
+ const deg = matrixInfo.angle * ONE_ANG;
1161
+ const currentVertex = collection.map(originVertex, ({ x, y }) => {
1162
+ const nx = (x - centerX + sx) * Math.cos(deg) -
1163
+ (y - centerY + sy) * Math.sin(deg);
1164
+ const ny = (x - centerX + sx) * Math.sin(deg) +
1165
+ (y - centerY + sy) * Math.cos(deg);
1166
+ return { x: centerX + nx, y: centerY + ny };
1167
+ });
1168
+ if (changeX || changeY) {
1169
+ transformer.moveTo(transformer.x - (currentVertex[0].x - lastX), transformer.y - (currentVertex[0].y - lastY));
1170
+ }
1171
+ else {
1172
+ transformer.moveTo(transformer.x - (currentVertex[0].x - vertexBeforeTransform[0].x), transformer.y - (currentVertex[0].y - vertexBeforeTransform[0].y));
1173
+ }
1174
+ handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
1175
+ onEnd && onEnd.call(uiik, { w: currentW, h: currentH }, ev);
1176
+ });
1177
+ }, {
1178
+ threshold: THRESHOLD$3,
1179
+ lockPage: true,
1180
+ });
1181
+ }
1182
+ initHandle(panel) {
1183
+ const opts = this.opts;
1184
+ let handleStr = opts.handle;
1185
+ let handles;
1186
+ if (is.isString(handleStr)) {
1187
+ handles = document.querySelectorAll(handleStr);
1188
+ }
1189
+ else if (is.isFunction(handleStr)) {
1190
+ handles = handleStr(panel);
1191
+ }
1192
+ if (!handles) {
1193
+ console.error('Can not find handles with "' + panel.outerHTML + '"');
1194
+ return;
1195
+ }
1196
+ handles = is.isArrayLike(handles) ? handles : [handles];
1197
+ collection.each(handles, (h) => {
1198
+ const className = h.getAttribute("class") || "";
1199
+ const matchRs = className.match(EXP_DIR);
1200
+ let dir = "se";
1201
+ if (matchRs) {
1202
+ dir = matchRs.groups.dir;
1203
+ }
1204
+ h.classList.add(CLASS_RESIZABLE_HANDLE);
1205
+ this.bindHandle(h, dir, panel, opts);
1206
+ h.style.cursor = `${dir}-resize`;
1207
+ h.dataset.cursor = `${dir}-resize`;
1208
+ h.setAttribute("name", "handle");
1209
+ });
1210
+ }
1211
+ }
1212
+ function newResizable(els, opts) {
1213
+ return new Resizable(els, opts);
1214
+ }
1215
+
1216
+ var _Draggable_instances, _Draggable_handleMap, _Draggable_container, _Draggable_initStyle;
1217
+ const DRAGGER_GROUPS = {};
1218
+ const CLASS_DRAGGABLE = "uii-draggable";
1219
+ const CLASS_DRAGGABLE_HANDLE = "uii-draggable-handle";
1220
+ const CLASS_DRAGGABLE_ACTIVE = "uii-draggable-active";
1221
+ const CLASS_DRAGGABLE_GHOST = "uii-draggable-ghost";
1222
+ class Draggable extends Uii {
1223
+ constructor(els, opts) {
1224
+ super(els, object.assign({
1225
+ containment: false,
1226
+ watch: true,
1227
+ threshold: 0,
1228
+ ghost: false,
1229
+ direction: "",
1230
+ scroll: true,
1231
+ snapOptions: {
1232
+ tolerance: 10,
1233
+ }
1234
+ }, opts));
1235
+ _Draggable_instances.add(this);
1236
+ _Draggable_handleMap.set(this, new WeakMap());
1237
+ _Draggable_container.set(this, null);
1238
+ if (this.opts.handle) {
1239
+ collection.each(this.ele, (el) => {
1240
+ const h = el.querySelector(this.opts.handle);
1241
+ if (!h) {
1242
+ console.error('No handle found "' + this.opts.handle + '"');
1243
+ return false;
1244
+ }
1245
+ __classPrivateFieldGet(this, _Draggable_handleMap, "f").set(el, h);
1246
+ });
1247
+ }
1248
+ this.onOptionChanged(this.opts);
1249
+ if (this.opts.group) {
1250
+ if (!DRAGGER_GROUPS[this.opts.group]) {
1251
+ DRAGGER_GROUPS[this.opts.group] = [];
1252
+ }
1253
+ DRAGGER_GROUPS[this.opts.group].push(...this.ele);
1254
+ }
1255
+ __classPrivateFieldGet(this, _Draggable_instances, "m", _Draggable_initStyle).call(this, this.ele);
1256
+ if (this.opts.containment) {
1257
+ if (is.isBoolean(this.opts.containment)) {
1258
+ __classPrivateFieldSet(this, _Draggable_container, is.isEmpty(this.ele) ? null : this.ele[0].parentElement, "f");
1259
+ }
1260
+ else if (is.isString(this.opts.containment)) {
1261
+ __classPrivateFieldSet(this, _Draggable_container, document.querySelector(this.opts.containment), "f");
1262
+ }
1263
+ else if (is.isElement(this.opts.containment)) {
1264
+ __classPrivateFieldSet(this, _Draggable_container, this.opts.containment, "f");
1265
+ }
1266
+ }
1267
+ if (this.opts.watch && this.eleString) {
1268
+ let con;
1269
+ if (is.isString(this.opts.watch)) {
1270
+ con = document.querySelector(this.opts.watch);
1271
+ }
1272
+ else {
1273
+ con = is.isEmpty(this.ele) ? null : this.ele[0].parentElement;
1274
+ }
1275
+ this.bindEvent(con || document.body, this.opts, __classPrivateFieldGet(this, _Draggable_handleMap, "f"));
1276
+ }
1277
+ else {
1278
+ collection.each(this.ele, (el) => {
1279
+ this.bindEvent(el, this.opts, __classPrivateFieldGet(this, _Draggable_handleMap, "f"));
1280
+ });
1281
+ }
1282
+ }
1283
+ bindEvent(bindTarget, opts, handleMap) {
1284
+ const container = __classPrivateFieldGet(this, _Draggable_container, "f");
1285
+ let draggableList = this.ele;
1286
+ const eleString = this.eleString;
1287
+ const initStyle = __classPrivateFieldGet(this, _Draggable_instances, "m", _Draggable_initStyle).bind(this);
1288
+ this.addPointerDown(bindTarget, ({ ev, currentTarget, currentStyle, currentCStyle, pointX, pointY, onPointerStart, onPointerMove, onPointerEnd }) => {
1289
+ var _a;
1290
+ let t = ev.target;
1291
+ if (!t)
1292
+ return;
1293
+ if (opts.watch && eleString) {
1294
+ draggableList = bindTarget.querySelectorAll(eleString);
1295
+ initStyle(draggableList);
1296
+ }
1297
+ let findRs = collection.find(draggableList, el => el.contains(t));
1298
+ if (!findRs)
1299
+ return;
1300
+ const dragDom = findRs;
1301
+ let handle = handleMap.get(dragDom);
1302
+ if (handle && !handle.contains(t)) {
1303
+ return;
1304
+ }
1305
+ const onPointerDown = opts.onPointerDown;
1306
+ if (onPointerDown && onPointerDown({ draggable: dragDom }, ev) === false)
1307
+ return;
1308
+ const filter = opts.filter;
1309
+ if (filter) {
1310
+ if (collection.some(dragDom.querySelectorAll(filter), ele => ele.contains(t)))
1311
+ return;
1312
+ }
1313
+ const offsetParent = dragDom instanceof HTMLElement ? dragDom.offsetParent || document.body : dragDom.ownerSVGElement;
1314
+ const offsetParentRect = offsetParent.getBoundingClientRect();
1315
+ const offsetParentCStyle = window.getComputedStyle(offsetParent);
1316
+ const offsetXy = getPointInContainer(ev, dragDom);
1317
+ let offsetPointX = offsetXy.x;
1318
+ let offsetPointY = offsetXy.y;
1319
+ const matrixInfo = getMatrixInfo(dragDom);
1320
+ const currentXy = getPointInContainer(ev, offsetParent, offsetParentRect, offsetParentCStyle);
1321
+ if (matrixInfo.angle != 0) {
1322
+ offsetPointX = currentXy.x - matrixInfo.x;
1323
+ offsetPointY = currentXy.y - matrixInfo.y;
1324
+ }
1325
+ const inContainer = !!container;
1326
+ const ghost = opts.ghost;
1327
+ const ghostClass = opts.ghostClass;
1328
+ const direction = opts.direction;
1329
+ const onStart = opts.onStart;
1330
+ const onDrag = opts.onDrag;
1331
+ const onEnd = opts.onEnd;
1332
+ const onClone = opts.onClone;
1333
+ const originalZIndex = currentCStyle.zIndex;
1334
+ let zIndex = opts.zIndex || originalZIndex;
1335
+ const classes = opts.classes || '';
1336
+ const group = opts.group;
1337
+ if (group) {
1338
+ let i = -1;
1339
+ collection.each(DRAGGER_GROUPS[group], el => {
1340
+ const z = parseInt(currentCStyle.zIndex) || 0;
1341
+ if (z > i)
1342
+ i = z;
1343
+ });
1344
+ zIndex = i + 1;
1345
+ }
1346
+ const scroll = opts.scroll;
1347
+ const scrollSpeed = opts.scrollSpeed || 10;
1348
+ let gridX, gridY;
1349
+ const grid = opts.grid;
1350
+ if (is.isArray(grid)) {
1351
+ gridX = grid[0];
1352
+ gridY = grid[1];
1353
+ }
1354
+ else if (is.isNumber(grid)) {
1355
+ gridX = gridY = grid;
1356
+ }
1357
+ const snapOn = opts.snap;
1358
+ let snappable;
1359
+ const snapTolerance = ((_a = opts.snapOptions) === null || _a === void 0 ? void 0 : _a.tolerance) || 10;
1360
+ const onSnap = opts.onSnap;
1361
+ let lastSnapDirY = "", lastSnapDirX = "";
1362
+ let lastSnapping = "";
1363
+ if (snapOn) {
1364
+ snappable = collection.map((container || document).querySelectorAll(snapOn), (el) => {
1365
+ const { x, y, w, h } = getRectInContainer(el, offsetParent);
1366
+ return {
1367
+ x1: x,
1368
+ y1: y,
1369
+ x2: x + w,
1370
+ y2: y + h,
1371
+ el: el,
1372
+ };
1373
+ });
1374
+ }
1375
+ const dragDomRect = dragDom.getBoundingClientRect();
1376
+ const originW = dragDomRect.width + parseFloat(currentCStyle.borderLeftWidth) + parseFloat(currentCStyle.borderRightWidth);
1377
+ const originH = dragDomRect.height + parseFloat(currentCStyle.borderTopWidth) + parseFloat(currentCStyle.borderBottomWidth);
1378
+ let minX = 0;
1379
+ let minY = 0;
1380
+ let maxX = 0;
1381
+ let maxY = 0;
1382
+ let originOffX = 0;
1383
+ let originOffY = 0;
1384
+ if (inContainer) {
1385
+ maxX = container.scrollWidth - originW;
1386
+ maxY = container.scrollHeight - originH;
1387
+ }
1388
+ if (maxX < 0)
1389
+ maxX = 0;
1390
+ if (maxY < 0)
1391
+ maxY = 0;
1392
+ let copyNode;
1393
+ let transformer;
1394
+ let timer = null;
1395
+ let toLeft = false;
1396
+ let toTop = false;
1397
+ let toRight = false;
1398
+ let toBottom = false;
1399
+ let endX = 0, endY = 0;
1400
+ onPointerStart(function (args) {
1401
+ var _a;
1402
+ const { ev } = args;
1403
+ if (ghost) {
1404
+ if (is.isFunction(ghost)) {
1405
+ copyNode = ghost(dragDom);
1406
+ }
1407
+ else {
1408
+ copyNode = dragDom.cloneNode(true);
1409
+ copyNode.style.opacity = "0.3";
1410
+ copyNode.style.pointerEvents = "none";
1411
+ copyNode.style.position = "absolute";
1412
+ }
1413
+ copyNode.style.zIndex = zIndex + '';
1414
+ if (ghostClass) {
1415
+ copyNode.classList.add(...array.compact(string.split(ghostClass, ' ')));
1416
+ }
1417
+ copyNode.classList.add(...array.compact(string.split(classes, ' ')));
1418
+ copyNode.classList.toggle(CLASS_DRAGGABLE_GHOST, true);
1419
+ (_a = dragDom.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(copyNode);
1420
+ transformer = wrapper(copyNode);
1421
+ onClone && onClone({ clone: copyNode }, ev);
1422
+ }
1423
+ else {
1424
+ transformer = wrapper(dragDom);
1425
+ }
1426
+ dragDom.classList.add(...array.compact(string.split(classes, ' ')));
1427
+ if (!copyNode)
1428
+ dragDom.style.zIndex = zIndex + '';
1429
+ dragDom.classList.toggle(CLASS_DRAGGABLE_ACTIVE, true);
1430
+ onStart && onStart({ draggable: dragDom, x: currentXy.x, y: currentXy.y }, ev);
1431
+ const customEv = new Event("uii-dragactive", { "bubbles": true, "cancelable": false });
1432
+ dragDom.dispatchEvent(customEv);
1433
+ });
1434
+ onPointerMove((args) => {
1435
+ const { ev, pointX, pointY, offX, offY } = args;
1436
+ const currentXy = getPointInContainer(ev, offsetParent, offsetParentRect, offsetParentCStyle);
1437
+ let newX = currentXy.x;
1438
+ let newY = currentXy.y;
1439
+ if (scroll) {
1440
+ const lX = pointX - offsetParentRect.x;
1441
+ const lY = pointY - offsetParentRect.y;
1442
+ const rX = offsetParentRect.x + offsetParentRect.width - pointX;
1443
+ const rY = offsetParentRect.y + offsetParentRect.height - pointY;
1444
+ toLeft = lX < EDGE_THRESHOLD;
1445
+ toTop = lY < EDGE_THRESHOLD;
1446
+ toRight = rX < EDGE_THRESHOLD;
1447
+ toBottom = rY < EDGE_THRESHOLD;
1448
+ if (toLeft || toTop
1449
+ ||
1450
+ toRight || toBottom) {
1451
+ if (!timer) {
1452
+ timer = setInterval(() => {
1453
+ if (toLeft) {
1454
+ offsetParent.scrollLeft -= scrollSpeed;
1455
+ }
1456
+ else if (toRight) {
1457
+ offsetParent.scrollLeft += scrollSpeed;
1458
+ }
1459
+ if (toTop) {
1460
+ offsetParent.scrollTop -= scrollSpeed;
1461
+ }
1462
+ else if (toBottom) {
1463
+ offsetParent.scrollTop += scrollSpeed;
1464
+ }
1465
+ }, 20);
1466
+ }
1467
+ }
1468
+ else {
1469
+ if (timer) {
1470
+ clearInterval(timer);
1471
+ timer = null;
1472
+ }
1473
+ }
1474
+ }
1475
+ let x = newX - offsetPointX + 0;
1476
+ let y = newY - offsetPointY + 0;
1477
+ if (is.isNumber(gridX) && is.isNumber(gridY)) {
1478
+ x = ((x / gridX) >> 0) * gridX;
1479
+ y = ((y / gridY) >> 0) * gridY;
1480
+ }
1481
+ if (inContainer) {
1482
+ if (originOffX + x < minX) {
1483
+ x = -0;
1484
+ }
1485
+ if (originOffY + y < minY) {
1486
+ y = -0;
1487
+ }
1488
+ if (originOffX + x > maxX) {
1489
+ x = maxX - originOffX;
1490
+ }
1491
+ if (originOffY + y > maxY) {
1492
+ y = maxY - originOffY;
1493
+ }
1494
+ }
1495
+ let canDrag = true;
1496
+ let emitSnap = false;
1497
+ if (snapOn) {
1498
+ const currPageX1 = x;
1499
+ const currPageY1 = y;
1500
+ const currPageX2 = currPageX1 + originW;
1501
+ const currPageY2 = currPageY1 + originH;
1502
+ let snapX = NaN, snapY = NaN;
1503
+ let targetX, targetY;
1504
+ let snapDirX, snapDirY;
1505
+ if (!direction || direction === "v") {
1506
+ collection.each(snappable, (data) => {
1507
+ if (Math.abs(data.y1 - currPageY1) <= snapTolerance) {
1508
+ snapY = data.y1;
1509
+ snapDirY = "t2t";
1510
+ }
1511
+ else if (Math.abs(data.y2 - currPageY1) <= snapTolerance) {
1512
+ snapY = data.y2;
1513
+ snapDirY = "t2b";
1514
+ }
1515
+ else if (Math.abs(data.y1 - currPageY2) <= snapTolerance) {
1516
+ snapY = data.y1 - originH;
1517
+ snapDirY = "b2t";
1518
+ }
1519
+ else if (Math.abs(data.y2 - currPageY2) <= snapTolerance) {
1520
+ snapY = data.y2 - originH;
1521
+ snapDirY = "b2b";
1522
+ }
1523
+ if (snapY) {
1524
+ lastSnapDirY = snapDirY;
1525
+ targetY = data.el;
1526
+ return false;
1527
+ }
1528
+ });
1529
+ }
1530
+ if (!direction || direction === "h") {
1531
+ collection.each(snappable, (data) => {
1532
+ if (Math.abs(data.x1 - currPageX1) <= snapTolerance) {
1533
+ snapX = data.x1;
1534
+ snapDirX = "l2l";
1535
+ }
1536
+ else if (Math.abs(data.x2 - currPageX1) <= snapTolerance) {
1537
+ snapX = data.x2;
1538
+ snapDirX = "l2r";
1539
+ }
1540
+ else if (Math.abs(data.x1 - currPageX2) <= snapTolerance) {
1541
+ snapX = data.x1 - originW;
1542
+ snapDirX = "r2l";
1543
+ }
1544
+ else if (Math.abs(data.x2 - currPageX2) <= snapTolerance) {
1545
+ snapX = data.x2 - originW;
1546
+ snapDirX = "r2r";
1547
+ }
1548
+ if (snapX) {
1549
+ lastSnapDirX = snapDirX;
1550
+ targetX = data.el;
1551
+ return false;
1552
+ }
1553
+ });
1554
+ }
1555
+ if (snapX || snapY) {
1556
+ if (snapX) {
1557
+ x = snapX;
1558
+ }
1559
+ if (snapY) {
1560
+ y = snapY;
1561
+ }
1562
+ if (onSnap && lastSnapping !== lastSnapDirX + "" + lastSnapDirY) {
1563
+ setTimeout(() => {
1564
+ onSnap({
1565
+ el: copyNode || dragDom,
1566
+ targetH: targetX,
1567
+ targetV: targetY,
1568
+ dirH: snapDirX,
1569
+ dirV: snapDirY,
1570
+ }, ev);
1571
+ }, 0);
1572
+ lastSnapping = lastSnapDirX + "" + lastSnapDirY;
1573
+ }
1574
+ emitSnap = true;
1575
+ }
1576
+ else {
1577
+ lastSnapDirX = lastSnapDirY = lastSnapping = "";
1578
+ }
1579
+ }
1580
+ if (onDrag && !emitSnap) {
1581
+ if (onDrag({
1582
+ draggable: dragDom,
1583
+ ox: offX,
1584
+ oy: offY,
1585
+ x: x,
1586
+ y: y
1587
+ }, ev) === false) {
1588
+ canDrag = false;
1589
+ endX = x;
1590
+ endY = y;
1591
+ }
1592
+ }
1593
+ if (canDrag) {
1594
+ if (direction === "v") {
1595
+ transformer.moveToY(y);
1596
+ }
1597
+ else if (direction === "h") {
1598
+ transformer.moveToX(x);
1599
+ }
1600
+ else {
1601
+ transformer.moveTo(x, y);
1602
+ }
1603
+ endX = x;
1604
+ endY = y;
1605
+ }
1606
+ });
1607
+ onPointerEnd((args) => {
1608
+ var _a, _b;
1609
+ const { ev, currentStyle } = args;
1610
+ if (scroll) {
1611
+ if (timer) {
1612
+ clearInterval(timer);
1613
+ timer = null;
1614
+ }
1615
+ }
1616
+ dragDom.classList.remove(...array.compact(string.split(classes, ' ')));
1617
+ currentStyle.zIndex = originalZIndex;
1618
+ dragDom.classList.remove(CLASS_DRAGGABLE_ACTIVE);
1619
+ let moveToGhost = true;
1620
+ if (onEnd) {
1621
+ moveToGhost = onEnd({ draggable: dragDom, x: endX, y: endY }, ev) === false ? false : true;
1622
+ }
1623
+ const customEv = new Event("uii-dragdeactive", { "bubbles": true, "cancelable": false });
1624
+ dragDom.dispatchEvent(customEv);
1625
+ if (ghost) {
1626
+ ((_a = dragDom.parentNode) === null || _a === void 0 ? void 0 : _a.contains(copyNode)) && ((_b = dragDom.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(copyNode));
1627
+ if (moveToGhost !== false) {
1628
+ wrapper(dragDom).moveTo(transformer.x, transformer.y);
1629
+ }
1630
+ }
1631
+ });
1632
+ }, {
1633
+ threshold: this.opts.threshold || 0,
1634
+ lockPage: true
1635
+ });
1636
+ }
1637
+ onOptionChanged(opts) {
1638
+ const droppable = opts.droppable;
1639
+ if (!is.isFunction(droppable)) {
1640
+ if (is.isUndefined(droppable)) {
1641
+ opts.droppable = () => { };
1642
+ }
1643
+ else if (is.isString(droppable)) {
1644
+ opts.droppable = () => document.querySelectorAll(droppable);
1645
+ }
1646
+ else if (is.isArrayLike(droppable)) {
1647
+ opts.droppable = () => droppable;
1648
+ }
1649
+ else if (is.isElement(droppable)) {
1650
+ opts.droppable = () => [droppable];
1651
+ }
1652
+ }
1653
+ }
1654
+ }
1655
+ _Draggable_handleMap = new WeakMap(), _Draggable_container = new WeakMap(), _Draggable_instances = new WeakSet(), _Draggable_initStyle = function _Draggable_initStyle(draggableList) {
1656
+ collection.each(draggableList, (el) => {
1657
+ if (is.isDefined(this.opts.type))
1658
+ el.dataset.dropType = this.opts.type;
1659
+ el.classList.toggle(CLASS_DRAGGABLE, true);
1660
+ const ee = __classPrivateFieldGet(this, _Draggable_handleMap, "f").get(el) || el;
1661
+ ee.classList.toggle(CLASS_DRAGGABLE_HANDLE, true);
1662
+ if (is.isDefined(this.opts.cursor)) {
1663
+ el.style.cursor = this.opts.cursor.default || 'move';
1664
+ if (is.isDefined(this.opts.cursor.over)) {
1665
+ el.dataset.cursorOver = this.opts.cursor.over;
1666
+ el.dataset.cursorActive = this.opts.cursor.active || 'move';
1667
+ }
1668
+ }
1669
+ });
1670
+ };
1671
+ function newDraggable(els, opts) {
1672
+ return new Draggable(els, opts);
1673
+ }
1674
+
1675
+ var _Droppable_active;
1676
+ const Droppables = [];
1677
+ const CLASS_DROPPABLE = "uii-droppable";
1678
+ class Droppable extends Uii {
1679
+ constructor(el, opts) {
1680
+ super(el, object.assign({}, opts));
1681
+ _Droppable_active.set(this, void 0);
1682
+ Droppables.push(this);
1683
+ }
1684
+ bindEvent(droppable, opts) {
1685
+ this.registerEvent(droppable, "mouseenter", (e) => {
1686
+ if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1687
+ return;
1688
+ if (opts.hoverClass) {
1689
+ collection.each(string.split(opts.hoverClass, ' '), cls => {
1690
+ droppable.classList.toggle(cls, true);
1691
+ });
1692
+ }
1693
+ if (__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver) {
1694
+ setCursor(__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver);
1695
+ }
1696
+ opts.onEnter && opts.onEnter({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
1697
+ });
1698
+ this.registerEvent(droppable, "mouseleave", (e) => {
1699
+ if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1700
+ return;
1701
+ if (opts.hoverClass) {
1702
+ collection.each(string.split(opts.hoverClass, ' '), cls => {
1703
+ droppable.classList.toggle(cls, false);
1704
+ });
1705
+ }
1706
+ if (__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorOver) {
1707
+ setCursor(__classPrivateFieldGet(this, _Droppable_active, "f").dataset.cursorActive || '');
1708
+ }
1709
+ opts.onLeave && opts.onLeave({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
1710
+ });
1711
+ this.registerEvent(droppable, "mousemove", (e) => {
1712
+ if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1713
+ return;
1714
+ opts.onOver && opts.onOver({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
1715
+ });
1716
+ this.registerEvent(droppable, "mouseup", (e) => {
1717
+ if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1718
+ return;
1719
+ if (opts.hoverClass) {
1720
+ collection.each(string.split(opts.hoverClass, ' '), cls => {
1721
+ droppable.classList.toggle(cls, false);
1722
+ });
1723
+ }
1724
+ opts.onDrop && opts.onDrop({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
1725
+ });
1726
+ }
1727
+ active(target) {
1728
+ let valid = true;
1729
+ const opts = this.opts;
1730
+ if (is.isString(opts.accepts)) {
1731
+ valid = !!target.dataset.dropType && string.test(opts.accepts, target.dataset.dropType);
1732
+ }
1733
+ else if (is.isFunction(opts.accepts)) {
1734
+ valid = opts.accepts(this.ele, target);
1735
+ }
1736
+ if (!valid)
1737
+ return;
1738
+ __classPrivateFieldSet(this, _Droppable_active, target, "f");
1739
+ if (opts.activeClass) {
1740
+ collection.each(this.ele, el => {
1741
+ collection.each(string.split(opts.activeClass || '', ' '), cls => {
1742
+ el.classList.toggle(cls, true);
1743
+ });
1744
+ });
1745
+ }
1746
+ opts.onActive && opts.onActive({ draggable: target, droppables: this.ele });
1747
+ collection.each(this.ele, (el) => {
1748
+ el.classList.toggle(CLASS_DROPPABLE, true);
1749
+ el.style.pointerEvents = 'initial';
1750
+ this.bindEvent(el, opts);
1751
+ });
1752
+ }
1753
+ deactive(target) {
1754
+ if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1755
+ return;
1756
+ __classPrivateFieldSet(this, _Droppable_active, null, "f");
1757
+ const opts = this.opts;
1758
+ if (opts.activeClass) {
1759
+ collection.each(this.ele, el => {
1760
+ collection.each(string.split(opts.activeClass || '', ' '), cls => {
1761
+ el.classList.toggle(cls, false);
1762
+ });
1763
+ });
1764
+ }
1765
+ opts.onDeactive && opts.onDeactive({ draggable: target, droppables: this.ele });
1766
+ this.destroy();
1767
+ }
1768
+ }
1769
+ _Droppable_active = new WeakMap();
1770
+ document.addEventListener("uii-dragactive", (e) => {
1771
+ collection.each(Droppables, dpb => {
1772
+ dpb.active(e.target);
1773
+ });
1774
+ });
1775
+ document.addEventListener("uii-dragdeactive", (e) => {
1776
+ collection.each(Droppables, dpb => {
1777
+ dpb.deactive(e.target);
1778
+ });
1779
+ });
1780
+ function newDroppable(els, opts) {
1781
+ return new Droppable(els, opts);
1782
+ }
1783
+
1784
+ const THRESHOLD$2 = 2;
1785
+ const CLASS_ROTATABLE = "uii-rotatable";
1786
+ const CLASS_ROTATABLE_HANDLE = "uii-rotatable-handle";
1787
+ const CLASS_ROTATABLE_ACTIVE = "uii-rotatable-active";
1788
+ class Rotatable extends Uii {
1789
+ constructor(els, opts) {
1790
+ super(els, opts);
1791
+ collection.each(this.ele, (el) => {
1792
+ initHandle(this, el, this.opts);
1793
+ });
1794
+ }
1795
+ }
1796
+ function initHandle(uiik, el, opts) {
1797
+ let handleStr = opts.handle;
1798
+ let handles;
1799
+ if (is.isString(handleStr)) {
1800
+ handles = document.querySelectorAll(handleStr);
1801
+ }
1802
+ else if (is.isFunction(handleStr)) {
1803
+ handles = handleStr(el);
1804
+ }
1805
+ if (!handles) {
1806
+ console.error('Can not find handles with "' + el.outerHTML + '"');
1807
+ return;
1808
+ }
1809
+ collection.each(handles, (h) => {
1810
+ var _a;
1811
+ h.classList.add(CLASS_ROTATABLE_HANDLE);
1812
+ h.style.cursor = ((_a = opts.cursor) === null || _a === void 0 ? void 0 : _a.default) || "crosshair";
1813
+ bindHandle(uiik, h, el, opts);
1814
+ });
1815
+ el.classList.toggle(CLASS_ROTATABLE, true);
1816
+ }
1817
+ function bindHandle(uiik, handle, el, opts) {
1818
+ const onStart = opts.onStart;
1819
+ const onRotate = opts.onRotate;
1820
+ const onEnd = opts.onEnd;
1821
+ let deg = 0;
1822
+ uiik.addPointerDown(handle, ({ onPointerStart, onPointerMove, onPointerEnd }) => {
1823
+ const { x, y, ox, oy } = getCenterXy(el);
1824
+ let centerX = x, centerY = y;
1825
+ let startDeg = 0;
1826
+ onPointerStart(function (args) {
1827
+ const { ev } = args;
1828
+ const currentXy = getPointInContainer(ev, el.parentElement);
1829
+ startDeg =
1830
+ Math.atan2(currentXy.y - centerY, currentXy.x - centerX) * ONE_RAD + 90;
1831
+ if (startDeg < 0)
1832
+ startDeg = 360 + startDeg;
1833
+ let matrixInfo = getMatrixInfo(el);
1834
+ startDeg -= matrixInfo.angle;
1835
+ el.classList.toggle(CLASS_ROTATABLE_ACTIVE, true);
1836
+ onStart && onStart({ deg, cx: centerX, cy: centerY }, ev);
1837
+ });
1838
+ onPointerMove((args) => {
1839
+ const { ev } = args;
1840
+ const currentXy = getPointInContainer(ev, el.parentElement);
1841
+ deg =
1842
+ Math.atan2(currentXy.y - centerY, currentXy.x - centerX) * ONE_RAD +
1843
+ 90 - startDeg;
1844
+ onRotate && onRotate({ deg, cx: centerX, cy: centerY }, ev);
1845
+ rotateTo(el, deg, ox, oy);
1846
+ });
1847
+ onPointerEnd((args) => {
1848
+ const { ev } = args;
1849
+ el.classList.toggle(CLASS_ROTATABLE_ACTIVE, false);
1850
+ onEnd && onEnd({ deg }, ev);
1851
+ });
1852
+ }, {
1853
+ threshold: THRESHOLD$2,
1854
+ lockPage: true,
1855
+ });
1856
+ }
1857
+ function newRotatable(els, opts) {
1858
+ return new Rotatable(els, opts);
1859
+ }
1860
+
1861
+ var _CollisionDetector__targets;
1862
+ class CollisionDetector {
1863
+ constructor(el, targets, opts) {
1864
+ _CollisionDetector__targets.set(this, void 0);
1865
+ __classPrivateFieldSet(this, _CollisionDetector__targets, targets, "f");
1866
+ this.opts = {
1867
+ container: document.body
1868
+ };
1869
+ this.opts = object.assign(this.opts, opts);
1870
+ const domEl = is.isString(el) ? document.querySelector(el) : el;
1871
+ if (!domEl) {
1872
+ console.error('Invalid selector "' + el + '"');
1873
+ return;
1874
+ }
1875
+ const ele = domEl;
1876
+ this.el = domEl;
1877
+ const offset = getBox(ele, this.opts.container);
1878
+ const rect = { x: offset.x, y: offset.y, width: ele.offsetWidth, height: ele.offsetHeight };
1879
+ this.elData = {
1880
+ x1: rect.x,
1881
+ y1: rect.y,
1882
+ x2: rect.x + rect.width,
1883
+ y2: rect.y + rect.height,
1884
+ };
1885
+ this.update();
1886
+ }
1887
+ update() {
1888
+ let targets;
1889
+ if (is.isFunction(__classPrivateFieldGet(this, _CollisionDetector__targets, "f"))) {
1890
+ targets = __classPrivateFieldGet(this, _CollisionDetector__targets, "f").call(this);
1891
+ }
1892
+ else if (is.isString(__classPrivateFieldGet(this, _CollisionDetector__targets, "f"))) {
1893
+ targets = this.opts.container.querySelectorAll(__classPrivateFieldGet(this, _CollisionDetector__targets, "f"));
1894
+ targets = collection.reject(targets, t => t === this.el);
1895
+ }
1896
+ else if (is.isElement(__classPrivateFieldGet(this, _CollisionDetector__targets, "f"))) {
1897
+ targets = [__classPrivateFieldGet(this, _CollisionDetector__targets, "f")];
1898
+ }
1899
+ else {
1900
+ targets = __classPrivateFieldGet(this, _CollisionDetector__targets, "f");
1901
+ }
1902
+ this.targetsData = collection.flatMap(targets, t => {
1903
+ if (!t)
1904
+ return [];
1905
+ const rect = getRectInContainer(t, this.opts.container);
1906
+ return {
1907
+ x1: rect.x,
1908
+ y1: rect.y,
1909
+ x2: rect.x + rect.w,
1910
+ y2: rect.y + rect.h,
1911
+ el: t
1912
+ };
1913
+ });
1914
+ }
1915
+ getOverlaps(x1, y1, x2, y2) {
1916
+ let elData = this.elData;
1917
+ if (x1 && x2 && y1 && y2) {
1918
+ elData = {
1919
+ x1,
1920
+ y1,
1921
+ x2,
1922
+ y2,
1923
+ };
1924
+ }
1925
+ let overlaps = collection.flatMap(this.targetsData, (td, i) => {
1926
+ if (elData.x2 < td.x1 || elData.x1 > td.x2 || elData.y2 < td.y1 || elData.y1 > td.y2)
1927
+ return [];
1928
+ return td.el;
1929
+ });
1930
+ return overlaps;
1931
+ }
1932
+ getInclusions(x1, y1, x2, y2) {
1933
+ let elData = this.elData;
1934
+ if (x1 && x2 && y1 && y2) {
1935
+ elData = {
1936
+ x1,
1937
+ y1,
1938
+ x2,
1939
+ y2,
1940
+ };
1941
+ }
1942
+ let contains = collection.flatMap(this.targetsData, (td, i) => {
1943
+ if (elData.x2 >= td.x2 && elData.x1 <= td.x1 && elData.y2 >= td.y2 && elData.y1 <= td.y1)
1944
+ return td.el;
1945
+ return [];
1946
+ });
1947
+ return contains;
1948
+ }
1949
+ }
1950
+ _CollisionDetector__targets = new WeakMap();
1951
+ function newCollisionDetector(el, targets, opts) {
1952
+ return new CollisionDetector(el, targets, opts);
1953
+ }
1954
+
1955
+ var _Selectable_instances, _Selectable__detector, _Selectable__lastSelected, _Selectable_bindEvent;
1956
+ const CLASS_SELECTOR = "uii-selector";
1957
+ const CLASS_SELECTING = "uii-selecting";
1958
+ const CLASS_SELECTED = "uii-selected";
1959
+ const THRESHOLD$1 = 2;
1960
+ class Selectable extends Uii {
1961
+ constructor(container, opts) {
1962
+ super(container, object.assign({
1963
+ targets: [],
1964
+ scroll: true,
1965
+ }, opts));
1966
+ _Selectable_instances.add(this);
1967
+ _Selectable__detector.set(this, void 0);
1968
+ _Selectable__lastSelected.set(this, void 0);
1969
+ const domEl = this.ele[0];
1970
+ let selector = document.createElement("div");
1971
+ if (domEl instanceof SVGElement) {
1972
+ selector = document.createElementNS('http://www.w3.org/2000/svg', "rect");
1973
+ }
1974
+ selector.setAttribute('class', CLASS_SELECTOR);
1975
+ selector.style.cssText = `
1976
+ position:absolute;
1977
+ left:0;top:0;
1978
+ `;
1979
+ if (this.opts.class) {
1980
+ selector.setAttribute('class', selector.getAttribute('class') + " " + this.opts.class);
1981
+ }
1982
+ else {
1983
+ selector.style.cssText += "border:1px dashed #000;stroke:#000;";
1984
+ }
1985
+ selector.style.display = 'none';
1986
+ domEl.appendChild(selector);
1987
+ __classPrivateFieldSet(this, _Selectable__detector, newCollisionDetector(selector, this.opts.targets, {
1988
+ container: domEl,
1989
+ }), "f");
1990
+ __classPrivateFieldGet(this, _Selectable_instances, "m", _Selectable_bindEvent).call(this, selector, domEl);
1991
+ }
1992
+ updateTargets() {
1993
+ __classPrivateFieldGet(this, _Selectable__detector, "f").update();
1994
+ }
1995
+ onOptionChanged() {
1996
+ this.updateTargets();
1997
+ }
1998
+ }
1999
+ _Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap(), _Selectable_instances = new WeakSet(), _Selectable_bindEvent = function _Selectable_bindEvent(selector, con) {
2000
+ const that = this;
2001
+ const opts = this.opts;
2002
+ this.addPointerDown(con, ({ ev, target, currentRect, currentCStyle, currentTarget, onPointerStart, onPointerMove, onPointerEnd }) => {
2003
+ const onStart = opts.onStart;
2004
+ const onSelect = opts.onSelect;
2005
+ const onEnd = opts.onEnd;
2006
+ const mode = opts.mode || "overlap";
2007
+ const scroll = opts.scroll;
2008
+ const scrollSpeed = opts.scrollSpeed || 10;
2009
+ const filter = opts.filter;
2010
+ const selectingClassAry = array.compact(string.split(opts.selectingClass, " "));
2011
+ const selectedClassAry = array.compact(string.split(opts.selectedClass, " "));
2012
+ if (filter) {
2013
+ if (is.isFunction(filter)) {
2014
+ if (filter(target))
2015
+ return;
2016
+ }
2017
+ else if (collection.some(con.querySelectorAll(filter), (el) => el.contains(target)))
2018
+ return;
2019
+ }
2020
+ const onPointerDown = opts.onPointerDown;
2021
+ if (onPointerDown && onPointerDown(ev) === false)
2022
+ return;
2023
+ let originPos = "";
2024
+ let matrixInfo = getMatrixInfo(currentCStyle);
2025
+ const startxy = getPointInContainer(ev, con, currentRect, currentCStyle, matrixInfo);
2026
+ let hitPosX = startxy.x;
2027
+ let hitPosY = startxy.y;
2028
+ const style = selector.style;
2029
+ let selection = [];
2030
+ let lastSelection = [];
2031
+ let x1 = hitPosX, y1 = hitPosY;
2032
+ let timer = null;
2033
+ let toLeft = false;
2034
+ let toTop = false;
2035
+ let toRight = false;
2036
+ let toBottom = false;
2037
+ onPointerStart(function (args) {
2038
+ const { ev } = args;
2039
+ __classPrivateFieldGet(that, _Selectable__detector, "f").update();
2040
+ const pos = currentCStyle.position;
2041
+ if (pos === "static") {
2042
+ originPos = con.style.position;
2043
+ con.style.position = "relative";
2044
+ }
2045
+ collection.each(__classPrivateFieldGet(that, _Selectable__lastSelected, "f"), t => {
2046
+ target.classList.toggle(CLASS_SELECTED, false);
2047
+ });
2048
+ style.display = 'block';
2049
+ onStart && onStart({ selection: __classPrivateFieldGet(that, _Selectable__lastSelected, "f"), selectable: con }, ev);
2050
+ });
2051
+ onPointerMove((args) => {
2052
+ const { ev } = args;
2053
+ const currentXy = getPointInContainer(ev, currentTarget, currentRect, currentCStyle, matrixInfo);
2054
+ let pointX = currentXy.x;
2055
+ let pointY = currentXy.y;
2056
+ let offX = pointX - hitPosX;
2057
+ let offY = pointY - hitPosY;
2058
+ if (scroll) {
2059
+ const ltX = ev.clientX - currentRect.x;
2060
+ const ltY = ev.clientY - currentRect.y;
2061
+ const rbX = currentRect.x + currentRect.width - ev.clientX;
2062
+ const rbY = currentRect.y + currentRect.height - ev.clientY;
2063
+ toLeft = ltX < EDGE_THRESHOLD;
2064
+ toTop = ltY < EDGE_THRESHOLD;
2065
+ toRight = rbX < EDGE_THRESHOLD;
2066
+ toBottom = rbY < EDGE_THRESHOLD;
2067
+ if (toLeft || toTop || toRight || toBottom) {
2068
+ if (!timer) {
2069
+ timer = setInterval(() => {
2070
+ if (toLeft) {
2071
+ con.scrollLeft -= scrollSpeed;
2072
+ }
2073
+ else if (toRight) {
2074
+ con.scrollLeft += scrollSpeed;
2075
+ }
2076
+ if (toTop) {
2077
+ con.scrollTop -= scrollSpeed;
2078
+ }
2079
+ else if (toBottom) {
2080
+ con.scrollTop += scrollSpeed;
2081
+ }
2082
+ }, 20);
2083
+ }
2084
+ }
2085
+ else {
2086
+ if (timer) {
2087
+ clearInterval(timer);
2088
+ timer = null;
2089
+ }
2090
+ }
2091
+ }
2092
+ let x = hitPosX, y = hitPosY, w = Math.abs(offX), h = Math.abs(offY);
2093
+ if (offX > 0 && offY > 0) {
2094
+ x1 = hitPosX;
2095
+ y1 = hitPosY;
2096
+ }
2097
+ else if (offX < 0 && offY < 0) {
2098
+ x = x1 = pointX;
2099
+ y = y1 = pointY;
2100
+ }
2101
+ else if (offX < 0) {
2102
+ x = x1 = pointX;
2103
+ }
2104
+ else if (offY < 0) {
2105
+ y = y1 = pointY;
2106
+ }
2107
+ style.width = w + "px";
2108
+ style.height = h + "px";
2109
+ style.transform = `translate3d(${x}px,${y}px,0)`;
2110
+ if (mode === "overlap") {
2111
+ selection = __classPrivateFieldGet(that, _Selectable__detector, "f").getOverlaps(x1, y1, x1 + w, y1 + h);
2112
+ }
2113
+ else if (mode === "inclusion") {
2114
+ selection = __classPrivateFieldGet(that, _Selectable__detector, "f").getInclusions(x1, y1, x1 + w, y1 + h);
2115
+ }
2116
+ collection.each(lastSelection, (t) => {
2117
+ if (!collection.includes(selection, t)) {
2118
+ t.classList.toggle(CLASS_SELECTING, false);
2119
+ collection.each(selectingClassAry, (cls) => {
2120
+ t.classList.toggle(cls, false);
2121
+ });
2122
+ }
2123
+ });
2124
+ collection.each(selection, (t) => {
2125
+ t.classList.toggle(CLASS_SELECTING, true);
2126
+ collection.each(selectingClassAry, (cls) => {
2127
+ t.classList.toggle(cls, true);
2128
+ });
2129
+ });
2130
+ const changed = lastSelection.length != selection.length;
2131
+ lastSelection = selection;
2132
+ if (changed && onSelect)
2133
+ onSelect({ selection, selectable: con }, ev);
2134
+ });
2135
+ onPointerEnd((args) => {
2136
+ const { ev, currentStyle } = args;
2137
+ style.display = 'none';
2138
+ if (scroll) {
2139
+ if (timer) {
2140
+ clearInterval(timer);
2141
+ timer = null;
2142
+ }
2143
+ }
2144
+ if (originPos) {
2145
+ con.style.position = originPos;
2146
+ }
2147
+ collection.each(selection, (t) => {
2148
+ collection.each(selectingClassAry, (cls) => {
2149
+ t.classList.toggle(cls, false);
2150
+ });
2151
+ collection.each(selectedClassAry, (cls) => {
2152
+ t.classList.toggle(cls, true);
2153
+ });
2154
+ t.classList.toggle(CLASS_SELECTING, false);
2155
+ t.classList.toggle(CLASS_SELECTED, true);
2156
+ });
2157
+ __classPrivateFieldSet(that, _Selectable__lastSelected, selection, "f");
2158
+ if (onEnd)
2159
+ onEnd({ selection, selectable: con }, ev);
2160
+ });
2161
+ }, {
2162
+ threshold: THRESHOLD$1,
2163
+ lockPage: true
2164
+ });
2165
+ };
2166
+ function newSelectable(container, opts) {
2167
+ return new Selectable(container, opts);
2168
+ }
2169
+
2170
+ var _Sortable_removeListenItems;
2171
+ const SORTABLE_GROUPS = {};
2172
+ const CLASS_SORTABLE_CONTAINER = "uii-sortable-container";
2173
+ const CLASS_SORTABLE_GHOST = "uii-sortable-ghost";
2174
+ const CLASS_SORTABLE_ACTIVE = "uii-sortable-active";
2175
+ const ATTR_SORTABLE_ACTIVE = "uii-sortable-active";
2176
+ const THRESHOLD = 2;
2177
+ class Sortable extends Uii {
2178
+ constructor(container, opts) {
2179
+ super(container, object.merge({
2180
+ move: {
2181
+ from: true,
2182
+ to: true,
2183
+ },
2184
+ scroll: true,
2185
+ sort: true
2186
+ }, opts));
2187
+ _Sortable_removeListenItems.set(this, void 0);
2188
+ if (collection.size(this.ele) > 1 && !this.opts.group) {
2189
+ this.opts.group = "uii_sortable_" + utils.alphaId();
2190
+ }
2191
+ collection.each(this.ele, (el) => {
2192
+ el.classList.add(CLASS_SORTABLE_CONTAINER);
2193
+ el.style.position = "relative";
2194
+ el.style.pointerEvents = "initial";
2195
+ bindContainer(this.registerEvent.bind(this), el, this.opts);
2196
+ });
2197
+ if (this.opts.group) {
2198
+ if (!SORTABLE_GROUPS[this.opts.group]) {
2199
+ SORTABLE_GROUPS[this.opts.group] = [];
2200
+ }
2201
+ SORTABLE_GROUPS[this.opts.group].push([this, this.ele]);
2202
+ }
2203
+ }
2204
+ active(draggingItem, fromContainer, toContainers, toOpts) {
2205
+ var _a;
2206
+ const moveFrom = (_a = toOpts.move) === null || _a === void 0 ? void 0 : _a.from;
2207
+ const acceptFn = is.isFunction(moveFrom) ? moveFrom : () => !!moveFrom;
2208
+ const activableContainers = collection.flatMap(toContainers, (el) => {
2209
+ const valid = acceptFn(draggingItem, fromContainer, el);
2210
+ return valid ? el : [];
2211
+ });
2212
+ collection.each(activableContainers, (el) => {
2213
+ el.setAttribute(ATTR_SORTABLE_ACTIVE, "1");
2214
+ if (toOpts.activeClass) {
2215
+ collection.each(string.split(toOpts.activeClass || "", " "), (cls) => {
2216
+ el.classList.toggle(cls, true);
2217
+ });
2218
+ }
2219
+ });
2220
+ __classPrivateFieldSet(this, _Sortable_removeListenItems, collection.map(activableContainers, (con) => {
2221
+ const filteredItems = con.querySelectorAll(":scope > *");
2222
+ return listenItems(toOpts, con, draggingItem, filteredItems);
2223
+ }), "f");
2224
+ toOpts.onActive &&
2225
+ toOpts.onActive({ item: draggingItem, from: fromContainer });
2226
+ }
2227
+ deactive(draggingItem, fromContainer, toContainers, opts) {
2228
+ collection.each(toContainers, (el) => {
2229
+ el.removeAttribute(ATTR_SORTABLE_ACTIVE);
2230
+ if (opts.activeClass) {
2231
+ collection.each(string.split(opts.activeClass || "", " "), (cls) => {
2232
+ el.classList.toggle(cls, false);
2233
+ });
2234
+ }
2235
+ });
2236
+ collection.each(__classPrivateFieldGet(this, _Sortable_removeListenItems, "f"), (fn) => {
2237
+ fn();
2238
+ });
2239
+ opts.onDeactive &&
2240
+ opts.onDeactive({ item: draggingItem, from: fromContainer });
2241
+ }
2242
+ onOptionChanged() { }
2243
+ }
2244
+ _Sortable_removeListenItems = new WeakMap();
2245
+ let DraggingData = null;
2246
+ function bindContainer(registerEvent, container, opts) {
2247
+ registerEvent(container, "mousedown", (e) => {
2248
+ var _a;
2249
+ let con = e.currentTarget;
2250
+ let t = e.target;
2251
+ if (t === con)
2252
+ return;
2253
+ const filterStr = opts.filter ? `:not(${opts.filter})` : "";
2254
+ const filteredItems = con.querySelectorAll(":scope > *" + filterStr);
2255
+ const handles = opts.handle
2256
+ ? collection.map(filteredItems, (el) => el.querySelector(opts.handle || ""))
2257
+ : collection.toArray(filteredItems);
2258
+ const i = array.findIndex(handles, (handle) => handle.contains(t));
2259
+ if (i < 0)
2260
+ return;
2261
+ const draggingItem = filteredItems[i];
2262
+ const ghostContainer = opts.ghostContainer || con;
2263
+ const onStart = opts.onStart;
2264
+ const onEnd = opts.onEnd;
2265
+ const ghostClass = opts.ghostClass;
2266
+ const group = opts.group;
2267
+ let moveTo = (_a = opts.move) === null || _a === void 0 ? void 0 : _a.to;
2268
+ const toCopy = moveTo === "copy";
2269
+ const toOutFn = is.isFunction(moveTo) ? moveTo : () => !!moveTo;
2270
+ const moveMode = toOutFn(draggingItem, con);
2271
+ const sort = opts.sort;
2272
+ opts.scroll;
2273
+ opts.scrollSpeed || 10;
2274
+ let hitPosX = e.offsetX + con.scrollLeft, hitPosY = e.offsetY + con.scrollTop;
2275
+ saveCursor();
2276
+ let dragging = false;
2277
+ let ghostNode = null;
2278
+ let removeListenItems = null;
2279
+ const dragListener = (ev) => {
2280
+ const newX = ev.clientX;
2281
+ const newY = ev.clientY;
2282
+ let offsetx = newX - hitPosX;
2283
+ let offsety = newY - hitPosY;
2284
+ if (!dragging) {
2285
+ if (Math.abs(offsetx) > THRESHOLD || Math.abs(offsety) > THRESHOLD) {
2286
+ dragging = true;
2287
+ ghostNode = draggingItem.cloneNode(true);
2288
+ ghostNode.style.opacity = "0.3";
2289
+ ghostNode.style.pointerEvents = "none";
2290
+ ghostNode.style.position = "fixed";
2291
+ ghostNode.style.zIndex = "999";
2292
+ ghostNode.style.left = draggingItem.style.left;
2293
+ ghostNode.style.top = draggingItem.style.top;
2294
+ if (ghostClass) {
2295
+ ghostNode.classList.add(...array.compact(string.split(ghostClass, " ")));
2296
+ }
2297
+ ghostNode.classList.toggle(CLASS_SORTABLE_GHOST, true);
2298
+ ghostContainer.appendChild(ghostNode);
2299
+ if (!toCopy)
2300
+ draggingItem.classList.toggle(CLASS_SORTABLE_ACTIVE, true);
2301
+ let copy = undefined;
2302
+ if (toCopy) {
2303
+ copy = draggingItem.cloneNode(true);
2304
+ copy.classList.toggle(CLASS_SORTABLE_ACTIVE, true);
2305
+ }
2306
+ DraggingData = {
2307
+ item: draggingItem,
2308
+ fromIndex: i,
2309
+ fromContainer: con,
2310
+ toContainer: con,
2311
+ moveTo: toCopy ? "copy" : moveMode,
2312
+ spill: opts.spill,
2313
+ copy
2314
+ };
2315
+ onStart && onStart({ item: draggingItem, from: con, index: i }, ev);
2316
+ lockPage();
2317
+ if (sort) {
2318
+ removeListenItems = listenItems(opts, con, toCopy ? draggingItem : copy, filteredItems, i);
2319
+ }
2320
+ if (moveMode && group && SORTABLE_GROUPS[group]) {
2321
+ collection.each(SORTABLE_GROUPS[group], ([sortable, ele]) => {
2322
+ const filtered = collection.reject(ele, (el) => el === container);
2323
+ if (is.isEmpty(filtered))
2324
+ return;
2325
+ sortable.active(toCopy ? draggingItem : copy, container, filtered, sortable.getOptions());
2326
+ });
2327
+ }
2328
+ }
2329
+ else {
2330
+ ev.preventDefault();
2331
+ return false;
2332
+ }
2333
+ }
2334
+ ghostNode.style.left = newX + "px";
2335
+ ghostNode.style.top = newY + "px";
2336
+ ev.preventDefault();
2337
+ return false;
2338
+ };
2339
+ const dragEndListener = (ev) => {
2340
+ var _a;
2341
+ document.removeEventListener("mousemove", dragListener);
2342
+ document.removeEventListener("mouseup", dragEndListener);
2343
+ window.removeEventListener("blur", dragEndListener);
2344
+ if (dragging) {
2345
+ unlockPage();
2346
+ restoreCursor();
2347
+ if (ghostNode)
2348
+ ghostContainer.removeChild(ghostNode);
2349
+ const toContainer = DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.toContainer;
2350
+ DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.item.classList.remove(CLASS_SORTABLE_ACTIVE);
2351
+ (_a = DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.copy) === null || _a === void 0 ? void 0 : _a.classList.remove(CLASS_SORTABLE_ACTIVE);
2352
+ DraggingData = null;
2353
+ if (removeListenItems)
2354
+ removeListenItems();
2355
+ if (group && SORTABLE_GROUPS[group]) {
2356
+ collection.each(SORTABLE_GROUPS[group], ([sortable, ele]) => {
2357
+ const filtered = collection.reject(ele, (el) => el === container);
2358
+ if (is.isEmpty(filtered))
2359
+ return;
2360
+ sortable.deactive(draggingItem, container, filtered, sortable.getOptions());
2361
+ });
2362
+ }
2363
+ onEnd && onEnd({ item: draggingItem, from: container, to: toContainer }, e);
2364
+ }
2365
+ };
2366
+ document.addEventListener("mousemove", dragListener);
2367
+ document.addEventListener("mouseup", dragEndListener);
2368
+ window.addEventListener("blur", dragEndListener);
2369
+ e.preventDefault();
2370
+ return false;
2371
+ });
2372
+ registerEvent(container, "mouseleave", (e) => {
2373
+ var _a, _b;
2374
+ if (!DraggingData)
2375
+ return;
2376
+ opts.onLeave &&
2377
+ opts.onLeave({
2378
+ item: DraggingData.item,
2379
+ from: DraggingData.fromContainer,
2380
+ to: container,
2381
+ }, e);
2382
+ if (DraggingData.moveTo !== 'copy') {
2383
+ if (DraggingData.spill === 'remove') {
2384
+ (_a = DraggingData.item.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(DraggingData.item);
2385
+ }
2386
+ else if (DraggingData.spill === 'revert') {
2387
+ (_b = DraggingData.item.parentElement) === null || _b === void 0 ? void 0 : _b.removeChild(DraggingData.item);
2388
+ const nextSibling = DraggingData.fromContainer.children[DraggingData.fromIndex];
2389
+ DraggingData.fromContainer.insertBefore(DraggingData.item, nextSibling);
2390
+ }
2391
+ }
2392
+ });
2393
+ registerEvent(container, "mouseenter", (e) => {
2394
+ var _a;
2395
+ if (!DraggingData)
2396
+ return;
2397
+ let draggingItem = DraggingData.item;
2398
+ draggingItem.parentElement;
2399
+ const cx = e.clientX;
2400
+ const cy = e.clientY;
2401
+ const rect = container.getBoundingClientRect();
2402
+ const centerX = rect.width / 2;
2403
+ const centerY = rect.height / 2;
2404
+ const offsetX = cx - rect.x;
2405
+ const offsetY = cy - rect.y;
2406
+ let dir = "";
2407
+ if (offsetX < centerX && offsetY < centerY) {
2408
+ dir = "tl";
2409
+ }
2410
+ else if (offsetX > centerX && offsetY > centerY) {
2411
+ dir = "br";
2412
+ }
2413
+ else if (offsetX < centerX && offsetY > centerY) {
2414
+ dir = "bl";
2415
+ }
2416
+ else if (offsetX > centerX && offsetY < centerY) {
2417
+ dir = "tr";
2418
+ }
2419
+ opts.onEnter &&
2420
+ opts.onEnter({
2421
+ item: DraggingData.item,
2422
+ from: DraggingData.fromContainer,
2423
+ to: container,
2424
+ dir,
2425
+ }, e);
2426
+ DraggingData.toContainer = container;
2427
+ if (container.getAttribute(ATTR_SORTABLE_ACTIVE)) {
2428
+ let valid = true;
2429
+ const moveFrom = (_a = opts.move) === null || _a === void 0 ? void 0 : _a.from;
2430
+ const acceptFn = is.isFunction(moveFrom) ? moveFrom : () => !!moveFrom;
2431
+ valid = acceptFn(DraggingData.item, DraggingData.fromContainer, container);
2432
+ if (!valid)
2433
+ return;
2434
+ if (container.contains(draggingItem)) {
2435
+ return;
2436
+ }
2437
+ const moveTo = DraggingData.moveTo;
2438
+ if (moveTo === "copy") {
2439
+ draggingItem = DraggingData.copy;
2440
+ }
2441
+ if (draggingItem.parentElement)
2442
+ draggingItem.parentElement.removeChild(draggingItem);
2443
+ let toIndex = 0;
2444
+ if (dir[0] === "t") {
2445
+ container.insertBefore(draggingItem, container.children[0]);
2446
+ }
2447
+ else {
2448
+ container.appendChild(draggingItem);
2449
+ toIndex = container.children.length - 1;
2450
+ }
2451
+ opts.onAdd &&
2452
+ opts.onAdd({
2453
+ item: draggingItem,
2454
+ from: DraggingData.fromContainer,
2455
+ to: container,
2456
+ index: toIndex,
2457
+ }, e);
2458
+ }
2459
+ else if (container === DraggingData.fromContainer) {
2460
+ if (DraggingData.copy) {
2461
+ let parent = DraggingData.copy.parentElement;
2462
+ if (parent)
2463
+ parent.removeChild(DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.copy);
2464
+ }
2465
+ else {
2466
+ if (draggingItem.parentElement)
2467
+ draggingItem.parentElement.removeChild(draggingItem);
2468
+ if (dir[0] === "t") {
2469
+ container.insertBefore(draggingItem, container.children[0]);
2470
+ }
2471
+ else {
2472
+ container.appendChild(draggingItem);
2473
+ container.children.length - 1;
2474
+ }
2475
+ }
2476
+ }
2477
+ });
2478
+ }
2479
+ function listenItems(opts, toContainer, draggingItem, items, fromIndex = 0) {
2480
+ const listener = (e) => {
2481
+ const ct = e.currentTarget;
2482
+ if (ct.style.transform) {
2483
+ return;
2484
+ }
2485
+ const toIndex = ct._uiik_i;
2486
+ let draggingItem = (DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.copy) || (DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.item);
2487
+ if (toContainer === (DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.fromContainer)) {
2488
+ draggingItem = DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.item;
2489
+ }
2490
+ let parent = draggingItem.parentElement;
2491
+ parent === null || parent === void 0 ? void 0 : parent.removeChild(draggingItem);
2492
+ const sameContainer = parent === ct.parentElement;
2493
+ if (!sameContainer) {
2494
+ parent = ct.parentElement;
2495
+ }
2496
+ const oldIndex = fromIndex;
2497
+ if (toIndex > fromIndex) {
2498
+ fromIndex = toIndex;
2499
+ parent === null || parent === void 0 ? void 0 : parent.insertBefore(draggingItem, ct.nextElementSibling);
2500
+ }
2501
+ else {
2502
+ fromIndex = toIndex - 1;
2503
+ parent === null || parent === void 0 ? void 0 : parent.insertBefore(draggingItem, ct);
2504
+ }
2505
+ opts.onChange &&
2506
+ opts.onChange({
2507
+ item: draggingItem,
2508
+ from: DraggingData === null || DraggingData === void 0 ? void 0 : DraggingData.fromContainer,
2509
+ to: toContainer,
2510
+ fromIndex: oldIndex,
2511
+ toIndex: fromIndex,
2512
+ }, e);
2513
+ const toPos = { x: ct.offsetLeft, y: ct.offsetTop };
2514
+ const fromPos = { x: draggingItem.offsetLeft, y: draggingItem.offsetTop };
2515
+ ct.style.transform = `translate3d(${fromPos.x - toPos.x}px,${fromPos.y - toPos.y}px,0)`;
2516
+ draggingItem.style.transform = `translate3d(${toPos.x - fromPos.x}px,${toPos.y - fromPos.y}px,0)`;
2517
+ draggingItem.offsetHeight;
2518
+ ct.offsetHeight;
2519
+ draggingItem.style.transition = "transform .15s";
2520
+ draggingItem.style.transform = `translate3d(0px,0px,0)`;
2521
+ ct.style.transition = "transform .15s";
2522
+ ct.style.transform = `translate3d(0px,0px,0)`;
2523
+ setTimeout(() => {
2524
+ ct.style.transition = "";
2525
+ ct.style.transform = ``;
2526
+ draggingItem.style.transition = "";
2527
+ draggingItem.style.transform = ``;
2528
+ }, 150);
2529
+ e.stopPropagation();
2530
+ e.preventDefault();
2531
+ };
2532
+ collection.each(items, (item, i) => {
2533
+ item.style.position = "relative";
2534
+ if (item === draggingItem)
2535
+ return;
2536
+ item.style.pointerEvents = "initial";
2537
+ item._uiik_i = i;
2538
+ item.addEventListener("mouseenter", listener);
2539
+ });
2540
+ return () => {
2541
+ collection.each(items, (item, i) => {
2542
+ if (item === draggingItem)
2543
+ return;
2544
+ item.removeEventListener("mouseenter", listener);
2545
+ });
2546
+ };
2547
+ }
2548
+ function newSortable(container, opts) {
2549
+ return new Sortable(container, opts);
2550
+ }
2551
+
2552
+ var version = "1.3.0-alpha";
2553
+ var repository = {
2554
+ type: "git",
2555
+ url: "https://github.com/holyhigh2/uiik"
2556
+ };
2557
+
2558
+ const welcome = globalThis.welcome;
2559
+ if (!welcome) {
2560
+ const ssAry = [];
2561
+ ['102,227,255', '59,208,251', '67,180,255'].forEach((v, i) => {
2562
+ const cu = 'background:rgb(' + v + ');';
2563
+ if (i < 2) {
2564
+ ssAry[i] = ssAry[5 - 1 - i] = cu;
2565
+ }
2566
+ else {
2567
+ ssAry[i] = 'color:#fff;' + cu;
2568
+ }
2569
+ });
2570
+ console.info(`%c %c %c Uiik - UI interactions kit | v${version} %c %c `, ...ssAry, `💎 ${repository.url}`);
2571
+ globalThis.welcome = true;
2572
+ }
2573
+ const VERSION = version;
2574
+ var index = {
2575
+ VERSION: version,
2576
+ newSplittable,
2577
+ newResizable,
2578
+ newDraggable,
2579
+ newDroppable,
2580
+ newRotatable,
2581
+ newSelectable,
2582
+ newSortable
2583
+ };
2584
+
2585
+ exports.CollisionDetector = CollisionDetector;
2586
+ exports.DRAGGING_RULE = DRAGGING_RULE;
2587
+ exports.Draggable = Draggable;
2588
+ exports.Droppable = Droppable;
2589
+ exports.EDGE_THRESHOLD = EDGE_THRESHOLD;
2590
+ exports.ONE_ANG = ONE_ANG;
2591
+ exports.ONE_RAD = ONE_RAD;
2592
+ exports.Resizable = Resizable;
2593
+ exports.Rotatable = Rotatable;
2594
+ exports.Selectable = Selectable;
2595
+ exports.Sortable = Sortable;
2596
+ exports.Splittable = Splittable;
2597
+ exports.Uii = Uii;
2598
+ exports.UiiTransformer = UiiTransformer;
2599
+ exports.VERSION = VERSION;
2600
+ exports["default"] = index;
2601
+ exports.getBox = getBox;
2602
+ exports.getCenterXy = getCenterXy;
2603
+ exports.getMatrixInfo = getMatrixInfo;
2604
+ exports.getPointInContainer = getPointInContainer;
2605
+ exports.getPointOffset = getPointOffset;
2606
+ exports.getRectInContainer = getRectInContainer;
2607
+ exports.getStyleXy = getStyleXy;
2608
+ exports.getTranslate = getTranslate;
2609
+ exports.isSVGEl = isSVGEl;
2610
+ exports.lockPage = lockPage;
2611
+ exports.moveBy = moveBy;
2612
+ exports.moveTo = moveTo;
2613
+ exports.newCollisionDetector = newCollisionDetector;
2614
+ exports.newDraggable = newDraggable;
2615
+ exports.newDroppable = newDroppable;
2616
+ exports.newResizable = newResizable;
2617
+ exports.newRotatable = newRotatable;
2618
+ exports.newSelectable = newSelectable;
2619
+ exports.newSortable = newSortable;
2620
+ exports.newSplittable = newSplittable;
2621
+ exports.restoreCursor = restoreCursor;
2622
+ exports.rotateTo = rotateTo;
2623
+ exports.saveCursor = saveCursor;
2624
+ exports.setCursor = setCursor;
2625
+ exports.unlockPage = unlockPage;
2626
+ exports.wrapper = wrapper;
2627
+
2628
+ Object.defineProperty(exports, '__esModule', { value: true });
2629
+
2630
+ }));