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