"use strict";var C=Object.defineProperty,j=Object.defineProperties,J=Object.getOwnPropertyDescriptor,W=Object.getOwnPropertyDescriptors,X=Object.getOwnPropertyNames,k=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable;var O=(n,e,t)=>e in n?C(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,l=(n,e)=>{for(var t in e||(e={}))H.call(e,t)&&O(n,t,e[t]);if(k)for(var t of k(e))Y.call(e,t)&&O(n,t,e[t]);return n},m=(n,e)=>j(n,W(e));var q=(n,e)=>{for(var t in e)C(n,t,{get:e[t],enumerable:!0})},Q=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of X(e))!H.call(n,r)&&r!==t&&C(n,r,{get:()=>e[r],enumerable:!(i=J(e,r))||i.enumerable});return n};var Z=n=>Q(C({},"__esModule",{value:!0}),n);var o=(n,e,t)=>(O(n,typeof e!="symbol"?e+"":e,t),t);var re={};q(re,{BarActionType:()=>N,ColumnResizer:()=>D,ItemType:()=>b,Resizer:()=>I});module.exports=Z(re);var b=(t=>(t.BAR="BAR",t.SECTION="SECTION",t))(b||{}),N=(i=>(i.ACTIVATE="activate",i.MOVE="move",i.DEACTIVATE="deactivate",i))(N||{});function R(){let n=[],e=0,t=0;return{collect(i){n.push(i),i.disableResponsive||(e+=1,t+=i.currentSize)},getResult(){return{sizeInfoArray:n,flexGrowRatio:e/t}}}}function u(n){return Number.isFinite(n)&&n>0}function E(n,e,t){let{collect:i,getResult:r}=R(),s=v(n,e,-1,t),c=v(n,-e,1,t),f=e-s.remainingOffset,a=-e-c.remainingOffset;function h(z,$){z.forEach(i),i(t[n]),$.forEach(i)}if(f===-a)h(s.sizeInfoArray,c.sizeInfoArray);else if(Math.abs(f)=0:a<=i.length-1}return{sizeInfoArray:r,remainingOffset:s}}function ee(n,e){if(e.isSolid)return{remainingOffset:n,sizeInfo:e};let{nextSize:t,remainingOffset:i}=te(e.currentSize+n,e);return{sizeInfo:m(l({},e),{currentSize:t}),remainingOffset:i}}function te(n,{maxSize:e,minSize:t=0}){return ne?{nextSize:e,remainingOffset:n-e}:{nextSize:n,remainingOffset:0}}var L={x:0,y:0};function K(n,e){return e?{x:n.x-e.x,y:n.y-e.y}:L}var w={barIndex:-1,offset:0,type:"deactivate",originalCoordinate:L,defaultSizeInfoArray:[],sizeInfoArray:[],discard:!0,flexGrowRatio:0};function _(n){let e=w,t=new Set;return{dispatch(i){e=(()=>{let r={barIndex:i.barIndex,type:i.type};switch(i.type){case"activate":let{sizeInfoArray:s,flexGrowRatio:c}=n.getSizeRelatedInfo();return m(l(l({},w),r),{originalCoordinate:i.coordinate,defaultSizeInfoArray:s,sizeInfoArray:s,flexGrowRatio:c});case"move":let f=n.calculateOffset(i.coordinate,e.originalCoordinate);return m(l(l({},r),E(i.barIndex,f,e.defaultSizeInfoArray)),{offset:f,originalCoordinate:e.originalCoordinate,defaultSizeInfoArray:e.defaultSizeInfoArray,discard:!1});case"deactivate":return w}})(),t.forEach(r=>r(e))},subscribe(i){return t.add(i),()=>t.delete(i)},unsubscribeAll(){t.clear()}}}function d(n,e,t){n==null||n.dispatchEvent(new CustomEvent(e,{detail:t}))}var A=class{constructor(){o(this,"disposeFnSet",new Set);o(this,"watchResizerEvent",(e,t,i)=>{e==null||e.addEventListener(t,i);let r=()=>e==null?void 0:e.removeEventListener(t,i);return this.disposeFnSet.add(r),r});o(this,"reset",()=>{this.disposeFnSet.forEach(e=>e()),this.disposeFnSet.clear()})}};var y=class{constructor(){o(this,"infoMap",new Map);o(this,"items",[])}update(e){this.infoMap.clear(),this.items.forEach(t=>t.destroy()),this.items=e,e.forEach((t,i)=>{this.infoMap.set(t.elm,{item:t,index:i})})}reset(){this.update([])}getItems(){return this.items}getItem(e){var t,i;return(i=(t=this.infoMap.get(e))==null?void 0:t.item)!=null?i:null}getItemIndex(e){var t,i;return(i=(t=this.infoMap.get(e))==null?void 0:t.index)!=null?i:null}};var x=!0;try{window.addEventListener("test",null,{get passive(){return x={passive:!1},!0}})}catch(n){}function T({size:n}){return u(n)}function F(n){let{disableResponsive:e}=n;return T(n)&&e===void 0?!0:!!e}function G(n){return!!n&&n in b}function M(n){return e=>({"data-item-type":n,"data-item-config":JSON.stringify(e)})}function P(n){return Array.from(n.childNodes).map(e=>{if(!(e instanceof HTMLElement))return null;let t=e.getAttribute("data-item-type");return G(t)?{type:t,elm:e}:null}).filter(e=>!!e)}function B({elm:n}){var e;try{let t=JSON.parse((e=n.getAttribute("data-item-config"))!=null?e:"");return t&&typeof t=="object"?t:{}}catch(t){return{}}}function U(n){return n*2+1}function V(n){return n*2}var I=class{constructor(e){this.resizeResult=e;o(this,"isDiscarded",!1)}resizeSection(e,t){if(this.isDiscarded)return;let i=V(e),r=this.getSize(i);if(r>=0&&t.toSize>=0){let s=t.toSize-r;i===this.resizeResult.sizeInfoArray.length-1||t.preferMoveLeftBar?this.moveBar(e-1,{withOffset:-s}):this.moveBar(e,{withOffset:s})}}moveBar(e,t){this.isDiscarded||(this.resizeResult=E(U(e),t.withOffset,this.resizeResult.sizeInfoArray))}discard(){this.isDiscarded=!0}isSectionResized(e){let t=V(e);return"defaultSizeInfoArray"in this.resizeResult?this.getSize(t)!==this.resizeResult.defaultSizeInfoArray[t].currentSize:!1}isBarActivated(e){return"barIndex"in this.resizeResult?this.resizeResult.barIndex===U(e):!1}getSectionSize(e){return this.getSize(V(e))}getResult(){return m(l({},this.resizeResult),{discard:this.isDiscarded})}getTotalSize(){return this.resizeResult.sizeInfoArray.filter((e,t)=>e&&t%2===0).reduce((e,{currentSize:t})=>e+t,0)}getSize(e){let t=this.resizeResult.sizeInfoArray[e];return t?t.currentSize:-1}};var g=class{constructor(e,t,i){this.type=e;this.elm=t;this.getConfig=i;o(this,"_config");o(this,"_observer");this._config=this.getConfig(),this._observer=new MutationObserver(()=>this._config=this.getConfig()),this._observer.observe(t,{attributes:!0,attributeFilter:["data-item-config"]})}get config(){return this._config}destroy(){this._observer.disconnect()}};var S=class extends g{constructor(t,i){super("BAR",t.elm,()=>ie(t));this.dispatchBarAction=i;o(this,"isActive",!1);o(this,"isValidClick",!0);let r=[this.attachListener(this.elm,"mousedown","activate"),this.attachListener(document,"mousemove","move"),this.attachListener(document,"mouseup","deactivate"),this.attachListener(this.elm,"touchstart","activate",x),this.attachListener(document,"touchmove","move",x),this.attachListener(document,"touchend","deactivate"),this.attachListener(document,"touchcancel","deactivate")];this.destroy=()=>{super.destroy(),r.forEach(s=>s())}}static getStyle({size:t}){return{flex:`0 0 ${t}px`}}attachListener(t,i,r,s){let c=f=>{this.disableUserSelectIfResizing(f,r);let{clientX:a,clientY:h}=("touches"in f?f.touches[0]:f)||{clientX:0,clientY:0};this.triggerAction(this.elm,r,{x:a,y:h})};return t.addEventListener(i,c,s),()=>t.removeEventListener(i,c,s)}disableUserSelectIfResizing(t,i){(this.isActive||i==="activate")&&t.preventDefault()}triggerAction(t,i,r){(this.isActive||i==="activate")&&this.dispatchBarAction(t,{type:i,coordinate:r}),this.isActive&&this.isValidClick&&i==="deactivate"&&(this.isValidClick=!1,d(t,"bar:click",null)),this.updateStatusIfNeed(t,i),this.updateClickStatus(i)}updateStatusIfNeed(t,i){let r=s=>{this.isActive!==s&&(this.isActive=s,d(t,"bar:status-change",{isActive:s}))};i==="activate"?r(!0):i==="deactivate"&&r(!1)}updateClickStatus(t){this.isActive&&(t==="activate"?this.isValidClick=!0:t==="move"&&(this.isValidClick=!1))}};function ie(n){let{size:e}=B(n);return{size:u(e)?e:10}}var p=class extends g{constructor(t){super("SECTION",t.elm,()=>ne(t));o(this,"sizeInfo",null);o(this,"flexGrowRatio",0);this.updateStyle()}static getStyle({maxSize:t,minSize:i},r){let s=c=>u(c)?`${c}px`:void 0;return{overflow:"hidden",[r?"maxHeight":"maxWidth"]:s(t),[r?"minHeight":"minWidth"]:s(i)}}update({sizeInfo:t,flexGrowRatio:i}){this.sizeInfo=t,this.flexGrowRatio=i,this.updateStyle(),d(this.elm,"section:size-change",{size:t.currentSize})}updateStyle(){let{flexGrow:t,flexShrink:i,flexBasis:r}=this.getStyle();this.elm.style.flexGrow=`${t}`,this.elm.style.flexShrink=`${i}`,this.elm.style.flexBasis=`${r}px`}getStyle(){let t=u(this.config.size)?0:this.config.disableResponsive?1:0;if(this.sizeInfo){let{disableResponsive:i,currentSize:r}=this.sizeInfo;return{flexShrink:t,flexGrow:i?0:this.flexGrowRatio*r,flexBasis:i?r:0}}else{let i=this.config.size||this.config.defaultSize;return u(i)?{flexShrink:t,flexGrow:0,flexBasis:i}:{flexShrink:t,flexGrow:1,flexBasis:0}}}};function ne(n){let{size:e,defaultSize:t,maxSize:i,minSize:r,disableResponsive:s}=B(n);return{size:u(e)?e:void 0,defaultSize:u(t)?t:void 0,maxSize:u(i)?i:void 0,minSize:u(r)?r:void 0,disableResponsive:!!s}}var D=class{constructor(e){this.config=e;o(this,"styles",{container:e=>m(l({},e),{display:"flex",flexDirection:this.direction}),section:(e,t)=>l(l({},t),p.getStyle(e,this.config.vertical)),bar:(e,t)=>l(l({},t),S.getStyle(e))});o(this,"attributes",{bar:M("BAR"),section:M("SECTION")});o(this,"itemsCache",new y);o(this,"eventHub",new A);o(this,"container",null);o(this,"barStore");o(this,"dispatchBarAction",(e,t)=>{let i=this.itemsCache.getItemIndex(e);i&&this.barStore.dispatch(m(l({},t),{barIndex:i}))});this.barStore=_({calculateOffset:(t,i)=>K(t,i)[this.axis],getSizeRelatedInfo:()=>this.makeSizeInfos()})}get axis(){return this.config.vertical?"y":"x"}get dimension(){return this.config.vertical?"height":"width"}get direction(){return this.config.vertical?"column":"row"}get on(){return this.eventHub.watchResizerEvent}init(e){this.dispose(),this.container=e,e&&(this.itemsCache.update(P(e).map(t=>{switch(t.type){case"BAR":return new S(t,this.dispatchBarAction);case"SECTION":return new p(t)}})),this.initStyles(e,this.itemsCache.getItems()),this.sizeRelatedInfoChange(this.makeSizeInfos()),this.barStore.subscribe(t=>{this.monitorBarStatusChanges(t),this.sizeRelatedInfoChange(t)}))}dispose(){this.container=null,this.itemsCache.reset(),this.barStore.unsubscribeAll(),this.eventHub.reset()}getResizer(){return new I(this.makeSizeInfos())}applyResizer(e){this.sizeRelatedInfoChange(e.getResult())}sizeRelatedInfoChange(e){e.discard||(e=(()=>{if(typeof this.config.beforeApplyResizer=="function"){let t=new I(e);return this.config.beforeApplyResizer(t),t.getResult()}else return e})(),!e.discard&&e.sizeInfoArray.forEach(t=>{let i=this.itemsCache.getItem(t.elm);i instanceof p&&i.update({sizeInfo:t,flexGrowRatio:e.flexGrowRatio})}))}monitorBarStatusChanges({type:e}){switch(e){case"activate":return d(this.container,"column:activate",null);case"deactivate":return d(this.container,"column:after-resizing",null);default:return}}makeSizeInfos(){let{collect:e,getResult:t}=R();return this.itemsCache.getItems().forEach(i=>{i instanceof S&&e({elm:i.elm,disableResponsive:!0,isSolid:!0,currentSize:i.elm.getBoundingClientRect()[this.dimension]}),i instanceof p&&e({elm:i.elm,maxSize:i.config.maxSize,minSize:i.config.minSize,disableResponsive:F(i.config),isSolid:T(i.config),currentSize:i.elm.getBoundingClientRect()[this.dimension]})}),t()}initStyles(e,t){Object.assign(e.style,this.styles.container()),t.forEach(i=>{i instanceof S&&Object.assign(i.elm.style,this.styles.bar(i.config)),i instanceof p&&Object.assign(i.elm.style,this.styles.section(i.config))})}};0&&(module.exports={BarActionType,ColumnResizer,ItemType,Resizer}); //# sourceMappingURL=index.cjs.map