tanuki-ui
Version:
HTML-first React component library with semantic elements, multi-OS themes, and production-ready visual node editor
2 lines (1 loc) โข 34.4 kB
JavaScript
"use strict";var ae=e=>{throw TypeError(e)};var Ie=(e,t,n)=>t.has(e)||ae("Cannot "+n);var O=(e,t,n)=>(Ie(e,t,"read from private field"),n?n.call(e):t.get(e)),_=(e,t,n)=>t.has(e)?ae("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),c=require("react"),ce=require("./vendor/useMeasure-C21c-kl-.js");function Pe(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const C=Pe(c);var je=typeof window<"u",Me=je?c.useLayoutEffect:c.useEffect;const _e="lytbase",ze={base:_e},ie=e=>f.jsx("div",{className:ze.base,children:e.children});ie.displayName="ScrollView";const $e="lytbaseE4I",Be="lytaside",ke="lytrsz",Ze="lytmainTjq",z={base:$e,aside:Be,resizer:ke,main:Ze},Xe=240,ue=120,de=480,He=(e,t)=>{const[n,a]=C.useState(t);return C.useEffect(()=>{if(e){if(typeof window>"u")return;const r=window.localStorage.getItem(e);if(r){const l=Number(r);isNaN(l)||a(Math.min(Math.max(l,ue),de))}}},[e]),C.useEffect(()=>{if(e){if(typeof window>"u")return;window.localStorage.setItem(e,String(n))}},[n,e]),[n,a]},pe=({aside:e,children:t,asideId:n,minAsideWidth:a=ue,maxAsideWidth:r=de})=>{const l=n?`SidebarLayout:width:${n}`:void 0,[o,i]=He(l,Xe),u=C.useRef(null),s=C.useRef(!1),b=C.useRef(null),d=C.useCallback(g=>{var m;if(g.type==="pointerdown")s.current=!0,b.current=((m=document.querySelector(`.${z.base}`))==null?void 0:m.getBoundingClientRect())??null;else if(g.type==="pointermove"&&s.current&&b.current){const p=Math.min(Math.max(g.pageX-b.current.left,a),r);i(p)}else g.type==="pointerend"&&(s.current=!1,b.current=null)},[a,r]);return ce.useObservePointer(u,d),f.jsxs("div",{className:z.base,children:[f.jsx("aside",{className:z.aside,style:{width:o},"aria-label":n,id:n,children:e}),f.jsx("div",{className:z.resizer,ref:u,role:"separator","aria-orientation":"vertical",tabIndex:0,"aria-label":"resize",style:{left:o-4}}),f.jsx("main",{className:z.main,children:t})]})};pe.displayName="SidebarLayout";const Ue="lytbasefvK",Ve="lythdr",Fe="lytmain",Y={base:Ue,header:Ve,main:Fe},fe=({header:e,children:t})=>f.jsxs("div",{className:Y.base,children:[f.jsx("header",{className:Y.header,children:e}),f.jsx("div",{className:Y.main,children:t})]});fe.displayName="HeaderMainLayout";const Ge="lytautsiz",Ye="lytbody",se={autoSizer:Ge,body:Ye},ge=e=>{const t=C.useRef(null),[n]=ce.useMeasure(t);return f.jsx("div",{ref:t,className:se.autoSizer,children:f.jsx("div",{className:se.body,children:n&&e.children(n)})})};ge.displayName="AutoSizer";const We="lytbasebSr",Ke="lythdrTR2",qe="lytmainzoo",Je="lytftr",Qe="lytctn",$={base:We,header:Ke,main:qe,footer:Je,content:Qe},be=({header:e,children:t,footer:n})=>f.jsxs("div",{className:$.base,children:[e&&f.jsx("header",{className:$.header,children:e}),f.jsx("main",{className:$.main,children:t}),n&&f.jsx("footer",{className:$.footer,children:n})]}),et=({children:e})=>f.jsx("div",{className:$.content,children:e});be.Content=et;const tt=({source:e,className:t})=>{const n=c.useRef(null);if(Me(()=>{const a=n.current;if(a)return e instanceof HTMLVideoElement||e instanceof HTMLImageElement||e instanceof HTMLCanvasElement||e instanceof HTMLObjectElement||e instanceof HTMLIFrameElement?(a.appendChild(e),()=>{a.contains(e)&&a.removeChild(e)}):()=>{}},[e]),typeof e=="string")return f.jsx("img",{src:e,className:t});if(typeof e=="object"&&"src"in e&&typeof e.src=="string"){const a="alt"in e&&typeof e.alt=="string"?e.alt:"";return f.jsx("img",{src:e.src,alt:a,className:t})}return f.jsx("div",{ref:n,className:t,children:c.isValidElement(e)?c.cloneElement(e,{}):f.jsx("div",{className:t,children:"Unsupported media type"})})},nt=()=>{const[e,t]=c.useState(0);return c.useEffect(()=>{if(typeof window>"u")return;const n=()=>{t(window.scrollY)};return window.addEventListener("scroll",n),()=>window.removeEventListener("scroll",n)},[]),e},Q=typeof window<"u"?c.useLayoutEffect:c.useEffect,W=new Map,rt=e=>{var a,r,l;const t="ovs-";if(W.has(t))return W.get(t);const n=new(l=class{constructor(){_(this,a,new Map);_(this,r,new ResizeObserver((o,i)=>{o.forEach(u=>{const s=O(this,a).get(u.target);s&&s(u,i)})}))}observe(o,i){return O(this,a).set(o,i),O(this,r).observe(o),()=>{O(this,a).delete(o),O(this,r).unobserve(o)}}},a=new WeakMap,r=new WeakMap,l);return W.set(t,n),n};function ee(e,{box:t}){const[n,a]=c.useState(null);c.useEffect(()=>e.current?rt().observe(e.current,(o,i)=>{a(o)}):void 0,[t,e.current]);const r=c.useMemo(()=>{var l;if(n)if(((l=n.borderBoxSize)==null?void 0:l.length)>0){const o=n.borderBoxSize[0];return new DOMRect(0,0,o.inlineSize,o.blockSize)}else return n.contentRect},[n]);return{entry:n,rect:r}}const at="lytbaseSh4",st="lythdri1w",ot="lytcover",lt="lytbody7_6",U={base:at,header:st,cover:ot,body:lt},he=({cover:e,children:t})=>{const n=C.useRef(null),a=C.useRef(null),r=nt(),l=C.useRef(r);l.current=r;const o=C.useRef(void 0),{rect:i}=ee(n,{});return Object.is(o.current,i)||(o.current=i),Q(()=>{const u=n.current,s=a.current;if(!s||!u)return;let b=Number.NaN,d;const g=()=>{const p=o.current;if(!p)return;const v=p.height-l.current;v!==b&&(s.style.opacity="1",s.style.height=`${v}px`,b=v),(p.x>=0||p.y>=0||p.width>0)&&d!==p&&(s.style.left=`${p.x}px`,s.style.top=`${p.y}px`,s.style.width=`${p.width}px`,d=p)};let m=requestAnimationFrame(function p(){g(),m=requestAnimationFrame(p)});return()=>{cancelAnimationFrame(m)}},[]),f.jsxs("div",{className:U.base,children:[f.jsx("div",{className:U.cover,ref:a,children:f.jsx(tt,{source:e})}),f.jsx("div",{ref:n,className:U.header,children:f.jsx("div",{className:U.body,children:t})})]})};he.displayName="StickyHeader";const ct="lytpage",it="lytline",ut="lytghost",B={page:ct,line:it,ghost:ut},dt=()=>{let e=0;const t=new Map;return n=>{if(n===void 0)return;if(t.has(n))return t.get(n);const a=e++;return t.set(n,a),a}},pt=dt(),K=new Map,ft=e=>{var a,r,l;const t=`ovs-threshold:${e.threshold}-rootMargin:${e.rootMargin}-root:${pt(e.root)}`;if(K.has(t))return K.get(t);const n=new(l=class{constructor(){_(this,a,new Map);_(this,r,new IntersectionObserver(o=>{o.forEach(i=>{const u=O(this,a).get(i.target);u&&u(i)})},e))}observe(o,i){return O(this,a).set(o,i),O(this,r).observe(o),()=>{O(this,a).delete(o),O(this,r).unobserve(o)}}},a=new WeakMap,r=new WeakMap,l);return K.set(t,n),n},oe=Object.freeze({x:0,y:0,width:0,height:0,top:0,right:0,bottom:0,left:0});function me(e,{threshold:t=0,rootMargin:n="0px",root:a=null}){const[r,l]=c.useState(null);return c.useEffect(()=>e.current?ft({threshold:t,rootMargin:n,root:a}).observe(e.current,i=>{l({isIntersecting:i.isIntersecting,boundingClientRect:i.boundingClientRect,intersectionRatio:i.intersectionRatio,intersectionRect:i.intersectionRect,rootBounds:i.rootBounds,target:i.target,time:i.time})}):void 0,[t,n,a,e.current]),c.useMemo(()=>({isIntersecting:(r==null?void 0:r.isIntersecting)??!1,boundingClientRect:(r==null?void 0:r.boundingClientRect)??oe,intersectionRatio:(r==null?void 0:r.intersectionRatio)??0,intersectionRect:(r==null?void 0:r.intersectionRect)??oe,rootBounds:(r==null?void 0:r.rootBounds)??null,target:(r==null?void 0:r.target)??e.current,time:(r==null?void 0:r.time)??0}),[r])}const F=C.createContext(new Proxy({},{get:()=>{throw new Error("Context not initialized")}}));F.displayName="ParavirtualScrollContext";const ve=C.memo(({children:e,direction:t="vertical",chunkSize:n=1})=>{const[a,r]=C.useState(()=>({cache:new Map,offsets:[],totalSize:0})),l=C.useCallback((m,p)=>{r(v=>{if(v.cache.get(m)===p)return v;const h=new Map(v.cache);h.set(m,p);const S=[],T=Array.from(h.keys()).reduce((R,E)=>{const L=h.get(E)??0;return S[E]=R,R+=L,R},0);return{cache:h,offsets:S,totalSize:T}})},[]),o=C.useMemo(()=>{const m={position:"relative"};return t==="vertical"?m.minHeight=a.totalSize:(m.minWidth=a.totalSize,m.display="flex"),m},[a.totalSize,t]),i=C.useRef(null),[u,s]=C.useState(null);C.useEffect(()=>{if(!i.current)return;let m=i.current.parentElement;for(;m;){const p=window.getComputedStyle(m),v=p.overflow+p.overflowY+p.overflowX;if(v.includes("auto")||v.includes("scroll")){s(m);return}m=m.parentElement}s(null)},[]);const b=C.useMemo(()=>({dimensionCache:a.cache,offsets:a.offsets,updateDimension:l,scrollContainer:u,direction:t,chunkSize:n}),[a.cache,a.offsets,l,u,t,n]),d=C.useMemo(()=>C.Children.toArray(e),[e]),g=C.useMemo(()=>{if(n<=1)return d.map((p,v)=>({children:[p],chunkIndex:v}));const m=[];for(let p=0;p<d.length;p+=n)m.push({children:d.slice(p,p+n),chunkIndex:Math.floor(p/n)});return m},[d,n]);return f.jsx("div",{className:B.page,style:o,ref:i,children:f.jsx(F.Provider,{value:b,children:g.map(m=>f.jsx(Te,{chunkIndex:m.chunkIndex,children:m.children},m.chunkIndex))})})});ve.displayName="ParavirtualScroll";const Te=C.memo(({children:e,chunkIndex:t})=>{const{dimensionCache:n,updateDimension:a,offsets:r,scrollContainer:l,direction:o,chunkSize:i}=C.useContext(F),u=C.useRef(null),{isIntersecting:s}=me(u,{rootMargin:"100px",threshold:0,root:l}),b=ee(u,{});Q(()=>{if(!b.rect||!s)return;const v=o==="vertical"?b.rect.height:b.rect.width;a(t,v)},[b.rect,s,o,t,a]);const d=C.useMemo(()=>{if(s)return{};const v=n.get(t);return typeof v!="number"?{}:o==="vertical"?{height:v}:{width:v}},[n,s,t,o]),g=n.has(t),m=s||!g,p=C.useMemo(()=>{const v=r[t],y={opacity:g?1:0};return o==="vertical"?(y.top=v,y.width="100%"):(y.left=v,y.height="100%"),y},[g,t,r,o]);return f.jsx("div",{ref:u,style:p,className:B.line,children:m?f.jsx(f.Fragment,{children:i<=1?e[0]:e.map((v,y)=>f.jsx(C.Fragment,{children:v},y))}):f.jsx("div",{className:B.ghost,style:d})})});Te.displayName="ParavirtualScrollChunk";const gt=C.memo(({children:e,index:t})=>{const{dimensionCache:n,updateDimension:a,offsets:r,scrollContainer:l,direction:o}=C.useContext(F),i=C.useRef(null),{isIntersecting:u}=me(i,{rootMargin:"100px",threshold:0,root:l}),s=ee(i,{});Q(()=>{if(!s.rect||!u)return;const p=o==="vertical"?s.rect.height:s.rect.width;a(t,p)},[s.rect,u,o,t,a]);const b=C.useMemo(()=>{if(u)return{};const p=n.get(t);return typeof p!="number"?{}:o==="vertical"?{height:p}:{width:p}},[n,u,t,o]),d=n.has(t),g=u||!d,m=C.useMemo(()=>{const p=r[t],v={opacity:d?1:0};return o==="vertical"?(v.top=p,v.width="100%"):(v.left=p,v.height="100%"),v},[d,t,r,o]);return f.jsx("div",{ref:i,style:m,className:B.line,children:g?f.jsx(f.Fragment,{children:e}):f.jsx("div",{className:B.ghost,style:b})})});gt.displayName="ParavirtualScrollItem";const bt="lytcnt",ht="lytcontrols",mt="lytviewscnt",vt="lytview",V={container:bt,controls:ht,viewsContainer:mt,view:vt},ye=c.memo(({items:e,defaultSelected:t=0,onViewChange:n,header:a,currentIndex:r,controlled:l=!1})=>{const[o,i]=c.useState(t),u=l&&r!==void 0?r:o,s=c.useRef(null),b=c.useRef(null),d=c.useRef(!1),g=c.useRef(null);c.useEffect(()=>{const T=document.body.style.overflowX;return document.body.style.overflowX="hidden",()=>{document.body.style.overflowX=T}},[]);const m=c.useCallback((T,R=!0)=>{if(!b.current||d.current)return;const E=b.current,L=-T*window.innerWidth;R?(d.current=!0,E.style.transition="transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94)",E.style.transform=`translateX(${L}px)`,setTimeout(()=>{d.current=!1,E&&(E.style.transition="")},300)):(E.style.transition="",E.style.transform=`translateX(${L}px)`)},[]);c.useEffect(()=>{m(u,!1)},[m,u]);const p=c.useCallback(T=>{l||i(T)},[l]),v=c.useCallback(T=>{if(d.current)return;const R=T.touches[0];g.current={startX:R.clientX,startY:R.clientY,currentX:R.clientX,isDragging:!1,direction:null}},[]),y=c.useCallback(T=>{if(!g.current||!b.current||d.current)return;const R=T.touches[0],E=R.clientX-g.current.startX,L=R.clientY-g.current.startY;if(g.current.currentX=R.clientX,!g.current.direction&&(Math.abs(E)>8||Math.abs(L)>8)&&(g.current.direction=Math.abs(E)>Math.abs(L)?"horizontal":"vertical",g.current.direction==="horizontal"&&(g.current.isDragging=!0)),g.current.direction==="horizontal"&&g.current.isDragging){T.preventDefault();const P=b.current,H=-u*window.innerWidth;let M=E;(u===0&&E>0||u===e.length-1&&E<0)&&(M=E*.25),P.style.transform=`translateX(${H+M}px)`}},[u,e.length]),h=c.useCallback(()=>{if(!g.current||!g.current.isDragging||d.current){g.current=null;return}const T=g.current.currentX-g.current.startX,R=window.innerWidth*.25;let E=u;Math.abs(T)>R&&(T>0&&u>0?E=u-1:T<0&&u<e.length-1&&(E=u+1)),p(E),m(E,!0),E!==u&&(n==null||n(E)),g.current=null},[u,e.length,m,n,p]);c.useEffect(()=>{const T=s.current;if(T)return T.addEventListener("touchstart",v,{passive:!0}),T.addEventListener("touchmove",y,{passive:!1}),T.addEventListener("touchend",h,{passive:!0}),T.addEventListener("touchcancel",h,{passive:!0}),()=>{T.removeEventListener("touchstart",v),T.removeEventListener("touchmove",y),T.removeEventListener("touchend",h),T.removeEventListener("touchcancel",h)}},[v,y,h]);const S=c.useMemo(()=>e.map((T,R)=>{const E=T.component,L=R===u,P=Math.abs(R-u)<=1;return f.jsx("div",{className:V.view,"aria-hidden":!L,children:P&&E?f.jsx(E,{}):null},T.key||R)}),[e,u]);return f.jsxs("div",{ref:s,className:V.container,children:[a&&f.jsx("div",{className:V.controls,children:a}),f.jsx("div",{ref:b,className:V.viewsContainer,children:S})]})});ye.displayName="ViewSwitcher";var N=(e=>(e.ACTIVATE_TAB="ACTIVATE_TAB",e.CLOSE_TAB="CLOSE_TAB",e.CREATE_TAB="CREATE_TAB",e.MOVE_TAB="MOVE_TAB",e.REORDER_TAB="REORDER_TAB",e.SPLIT_PANEL="SPLIT_PANEL",e.CLOSE_PANEL="CLOSE_PANEL",e.RESIZE_PANEL="RESIZE_PANEL",e.FOCUS_PANEL="FOCUS_PANEL",e.START_DRAG="START_DRAG",e.SET_DROP_TARGET="SET_DROP_TARGET",e.END_DRAG="END_DRAG",e.EXECUTE_DROP="EXECUTE_DROP",e.PRUNE_EMPTY_NODES="PRUNE_EMPTY_NODES",e.RESTORE_TAB="RESTORE_TAB",e.SET_STATE="SET_STATE",e))(N||{});const Se=e=>({activateTab:(t,n)=>{e({type:"ACTIVATE_TAB",payload:{leafId:t,tabId:n}})},closeTab:(t,n)=>{e({type:"CLOSE_TAB",payload:{leafId:t,tabId:n}})},createTab:(t,n)=>{n&&e({type:"CREATE_TAB",payload:{leafId:t,tab:n}})},moveTab:(t,n,a,r)=>{console.log("๐ญ ACTION moveTab dispatching:",{sourceLeafId:t,targetLeafId:n,tabId:a,targetIndex:r}),e({type:"MOVE_TAB",payload:{sourceLeafId:t,targetLeafId:n,tabId:a,targetIndex:r}})},reorderTab:(t,n,a)=>{console.log("๐ญ ACTION reorderTab dispatching:",{leafId:t,tabId:n,newIndex:a}),e({type:"REORDER_TAB",payload:{leafId:t,tabId:n,newIndex:a}})},splitPanel:(t,n,a)=>{e({type:"SPLIT_PANEL",payload:{leafId:t,orientation:n,ratio:a}})},closePanel:t=>{e({type:"CLOSE_PANEL",payload:{panelId:t}})},resizePanel:(t,n)=>{e({type:"RESIZE_PANEL",payload:{panelId:t,sizes:n}})},focusPanel:t=>{e({type:"FOCUS_PANEL",payload:{leafId:t}})},startDrag:(t,n)=>{e({type:"START_DRAG",payload:{tabId:t,sourceLeafId:n}})},setDropTarget:(t,n,a)=>{e({type:"SET_DROP_TARGET",payload:{leafId:t,direction:n,insertIndex:a}})},endDrag:()=>{e({type:"END_DRAG"})},executeDrop:()=>{e({type:"EXECUTE_DROP"})},pruneEmptyNodes:()=>{e({type:"PRUNE_EMPTY_NODES"})},restoreTab:()=>{e({type:"RESTORE_TAB"})}}),J=()=>Math.random().toString(36).substr(2,9),j=(e,t)=>{if(e.id===t)return e;if(e.type==="split")for(const n of e.children){const a=j(n,t);if(a)return a}return null},De=(e,t)=>{if(e.type==="split"){const n=e.children.findIndex(a=>a.id===t);if(n!==-1)return{parent:e,index:n};for(const a of e.children){const r=De(a,t);if(r)return r}}return null},Ee=(e,t)=>{if(e.id===t)return null;if(e.type==="split"){const n=e.children.map(a=>Ee(a,t)).filter(a=>a!==null);return{...e,children:n}}return e},k=e=>{if(e.type==="leaf")return e.tabs.length>0?e:null;const t=e.children.map(a=>k(a)).filter(a=>a!==null);if(t.length===0)return null;if(t.length===1)return t[0];const n=t.map(()=>1/t.length);return{...e,children:t,sizes:n}},Tt=(e,t,n)=>{const a=r=>r.id===t&&r.type==="leaf"?{...r,activeTabId:n}:r.type==="split"?{...r,children:r.children.map(a)}:r;return{...e,root:a(e.root),focusedLeafId:t}},yt=(e,t,n)=>{const a=j(e.root,t);if(!a||a.type!=="leaf")return e;const r=a.tabs.findIndex(g=>g.id===n);if(r===-1)return e;const l=a.tabs[r],o=a.tabs.filter(g=>g.id!==n),i=[...e.recentlyClosedTabs||[],l];let u=a.activeTabId;a.activeTabId===n&&(r<o.length?u=o[r].id:o.length>0?u=o[o.length-1].id:u="");const s=g=>g.id===t&&g.type==="leaf"?{...g,tabs:o,activeTabId:u}:g.type==="split"?{...g,children:g.children.map(s)}:g,b=s(e.root),d=k(b);return{...e,root:d||Z(),recentlyClosedTabs:i.slice(-10)}},Ce=(e,t,n)=>{const a=r=>r.id===t&&r.type==="leaf"?{...r,tabs:[...r.tabs,n],activeTabId:n.id}:r.type==="split"?{...r,children:r.children.map(a)}:r;return{...e,root:a(e.root),focusedLeafId:t}},q=(e,t,n,a,r)=>{const l=j(e.root,t),o=j(e.root,n);if(!l||!o||l.type!=="leaf"||o.type!=="leaf")return e;const i=l.tabs.find(y=>y.id===a);if(!i)return e;const u=l.tabs.filter(y=>y.id!==a);let s=l.activeTabId;if(l.activeTabId===a&&u.length>0){const y=l.tabs.findIndex(h=>h.id===a);y<u.length?s=u[y].id:s=u[u.length-1].id}const b=r??o.tabs.length,d=Math.max(0,Math.min(b,o.tabs.length)),g=[...o.tabs];g.splice(d,0,i),console.log("๐ Move Tab:",{tabId:a,sourceLeafId:t,targetLeafId:n,requestedIndex:r,insertIndex:b,clampedInsertIndex:d,targetTabsLength:o.tabs.length,newTargetTabsLength:g.length});const m=y=>y.id===t&&y.type==="leaf"?{...y,tabs:u,activeTabId:s}:y.id===n&&y.type==="leaf"?{...y,tabs:g,activeTabId:i.id}:y.type==="split"?{...y,children:y.children.map(m)}:y,p=m(e.root),v=k(p);return{...e,root:v||Z(),focusedLeafId:n}},le=(e,t,n,a=.5)=>{const r=j(e.root,t);if(!r||r.type!=="leaf")return e;const o={id:J(),type:"leaf",tabs:[],activeTabId:""},i={id:J(),type:"split",orientation:n,children:[r,o],sizes:[a,1-a]},u=s=>s.id===t?i:s.type==="split"?{...s,children:s.children.map(u)}:s;return e.root.id===t?{...e,root:i}:{...e,root:u(e.root)}},St=(e,t,n)=>{const a=r=>r.id===t&&r.type==="split"?{...r,sizes:n}:r.type==="split"?{...r,children:r.children.map(a)}:r;return{...e,root:a(e.root)}},Dt=(e,t,n,a)=>{const r=l=>{if(l.id===t&&l.type==="leaf"){const o=l.tabs.findIndex(b=>b.id===n);if(o===-1)return l;const i=[...l.tabs],[u]=i.splice(o,1),s=Math.max(0,Math.min(a,i.length));return i.splice(s,0,u),console.log("๐ REORDER:",{tabId:n,from:o,to:s,originalTabs:l.tabs.map(b=>b.id),newTabs:i.map(b=>b.id)}),{...l,tabs:i}}return l.type==="split"?{...l,children:l.children.map(r)}:l};return{...e,root:r(e.root)}},Et=e=>{if(!e.recentlyClosedTabs||e.recentlyClosedTabs.length===0)return e;const t=e.recentlyClosedTabs[e.recentlyClosedTabs.length-1],n=e.recentlyClosedTabs.slice(0,-1),a=e.focusedLeafId||Re(e.root);return a?Ce({...e,recentlyClosedTabs:n},a,t):e},Re=e=>{if(e.type==="leaf")return e.id;if(e.type==="split")for(const t of e.children){const n=Re(t);if(n)return n}return null},Z=()=>({id:J(),type:"leaf",tabs:[],activeTabId:""}),we=(e,t)=>{switch(t.type){case N.ACTIVATE_TAB:return{...e,panelState:Tt(e.panelState,t.payload.leafId,t.payload.tabId)};case N.CLOSE_TAB:return{...e,panelState:yt(e.panelState,t.payload.leafId,t.payload.tabId)};case N.CREATE_TAB:return{...e,panelState:Ce(e.panelState,t.payload.leafId,t.payload.tab)};case N.MOVE_TAB:console.log("๐ข REDUCER MOVE_TAB:",t.payload);const n=q(e.panelState,t.payload.sourceLeafId,t.payload.targetLeafId,t.payload.tabId,t.payload.targetIndex);return console.log("๐ข REDUCER MOVE_TAB result:",{oldState:e.panelState,newState:n,changed:JSON.stringify(e.panelState)!==JSON.stringify(n)}),{...e,panelState:n};case N.REORDER_TAB:console.log("๐ข REDUCER REORDER_TAB:",t.payload);const a=Dt(e.panelState,t.payload.leafId,t.payload.tabId,t.payload.newIndex);return console.log("๐ข REDUCER REORDER_TAB result:",{oldState:e.panelState,newState:a,changed:JSON.stringify(e.panelState)!==JSON.stringify(a)}),{...e,panelState:a};case N.SPLIT_PANEL:return{...e,panelState:le(e.panelState,t.payload.leafId,t.payload.orientation,t.payload.ratio)};case N.CLOSE_PANEL:{const r=Ee(e.panelState.root,t.payload.panelId),l=r?k(r):null;return{...e,panelState:{...e.panelState,root:l||Z()}}}case N.RESIZE_PANEL:return{...e,panelState:St(e.panelState,t.payload.panelId,t.payload.sizes)};case N.FOCUS_PANEL:return{...e,panelState:{...e.panelState,focusedLeafId:t.payload.leafId}};case N.START_DRAG:return{...e,dragState:{isDragging:!0,draggedTabId:t.payload.tabId,sourceLeafId:t.payload.sourceLeafId}};case N.SET_DROP_TARGET:return{...e,dragState:{...e.dragState,dropTargetLeafId:t.payload.leafId,dropDirection:t.payload.direction,insertIndex:t.payload.insertIndex}};case N.END_DRAG:return{...e,dragState:{isDragging:!1}};case N.EXECUTE_DROP:{const{dragState:r}=e;if(!r.isDragging||!r.draggedTabId||!r.sourceLeafId)return{...e,dragState:{isDragging:!1}};let l=e.panelState;if(r.dropTargetLeafId&&r.dropDirection){const o=r.dropDirection==="left"||r.dropDirection==="right"?"horizontal":"vertical",i=le(l,r.dropTargetLeafId,o,.5);if(j(i.root,r.dropTargetLeafId)){const s=De(i.root,r.dropTargetLeafId);if(s&&s.parent.type==="split"){const b=s.parent.children.findIndex(m=>m.id===r.dropTargetLeafId);let d;r.dropDirection==="right"||r.dropDirection==="bottom"?d=b+1:d=b;const g=s.parent.children[d];g&&g.type==="leaf"&&(l=q(i,r.sourceLeafId,g.id,r.draggedTabId))}}}else r.dropTargetLeafId&&(l=q(l,r.sourceLeafId,r.dropTargetLeafId,r.draggedTabId,r.insertIndex));return{...e,panelState:l,dragState:{isDragging:!1}}}case N.PRUNE_EMPTY_NODES:{const r=k(e.panelState.root);return{...e,panelState:{...e.panelState,root:r||Z()}}}case N.RESTORE_TAB:return{...e,panelState:Et(e.panelState)};case N.SET_STATE:return{...e,panelState:t.payload.state};default:return e}},xe=e=>{const t={root:Z(),pruneEmptyPanel:!0,recentlyClosedTabs:[]};return{panelState:e||t,dragState:{isDragging:!1}}},Ne=c.createContext(null),I=()=>{const e=c.useContext(Ne);if(!e)throw new Error("usePanelContext must be used within a PanelProvider");return e},Ct={pruneEmptyGroups:!0,enableTabDrag:!0,enablePanelSplit:!0,enableTabReorder:!0,minPanelSize:100,splitterSize:4,showCloseButton:!0,maxTabWidth:200,minTabWidth:80,enableKeyboardShortcuts:!0,keyBindings:{closeTab:["Ctrl+W","Cmd+W"],newTab:["Ctrl+T","Cmd+T"],nextTab:["Ctrl+Tab","Cmd+Option+ArrowRight"],prevTab:["Ctrl+Shift+Tab","Cmd+Option+ArrowLeft"],splitRight:["Ctrl+\\","Cmd+\\"],splitDown:["Ctrl+K Ctrl+\\","Cmd+K Cmd+\\"],focusGroup:["Ctrl+1","Cmd+1"],moveTabRight:["Ctrl+Alt+ArrowRight","Cmd+Ctrl+ArrowRight"],moveTabLeft:["Ctrl+Alt+ArrowLeft","Cmd+Ctrl+ArrowLeft"]}},Le=({children:e,value:t,defaultValue:n,onChange:a,options:r={}})=>{const l=c.useMemo(()=>({...Ct,...r}),[r]),[o,i]=c.useReducer(we,xe(t||n)),u=t||o.panelState,s=o.dragState,b=c.useRef(o.panelState);c.useEffect(()=>{a&&JSON.stringify(b.current)!==JSON.stringify(o.panelState)&&(b.current=o.panelState,a(o.panelState))},[o.panelState,a]);const d=c.useMemo(()=>Se(i),[i]),g=c.useCallback((w,x)=>{d.activateTab(w,x)},[d]),m=c.useCallback((w,x)=>{d.closeTab(w,x)},[d]),p=c.useCallback((w,x)=>{x&&d.createTab(w,x)},[d]),v=c.useCallback((w,x,A,re)=>{console.log("๐ CONTEXT moveTab called:",{sourceLeafId:w,targetLeafId:x,tabId:A,targetIndex:re}),d.moveTab(w,x,A,re)},[d]),y=c.useCallback((w,x,A)=>{console.log("๐ CONTEXT reorderTab called:",{leafId:w,tabId:x,newIndex:A}),d.reorderTab(w,x,A)},[d]),h=c.useCallback((w,x,A)=>{d.splitPanel(w,x,A)},[d]),S=c.useCallback(w=>{d.closePanel(w)},[d]),T=c.useCallback((w,x)=>{d.resizePanel(w,x)},[d]),R=c.useCallback(w=>{d.focusPanel(w)},[d]),E=c.useCallback((w,x)=>{console.log("๐ CONTEXT startDrag called:",{tabId:w,sourceLeafId:x,enableTabDrag:l.enableTabDrag}),l.enableTabDrag?d.startDrag(w,x):console.log("โ Tab drag disabled in options")},[d,l.enableTabDrag]),L=c.useCallback((w,x,A)=>{d.setDropTarget(w,x,A)},[d]),P=c.useCallback(()=>{d.endDrag()},[d]),H=c.useCallback(()=>{d.executeDrop()},[d]),M=c.useCallback(()=>{l.pruneEmptyGroups&&d.pruneEmptyNodes()},[d,l.pruneEmptyGroups]),te=c.useCallback(()=>{d.restoreTab()},[d]),ne=c.useMemo(()=>({activateTab:g,closeTab:m,createTab:p,moveTab:v,reorderTab:y,splitPanel:h,closePanel:S,resizePanel:T,focusPanel:R,startDrag:E,setDropTarget:L,endDrag:P,executeDrop:H,pruneEmptyNodes:M,restoreTab:te}),[g,m,p,v,y,h,S,T,R,E,L,P,H,M,te]),Ae=c.useMemo(()=>({state:u,dragState:s,actions:ne,options:l}),[u,s,ne,l]);return f.jsx(Ne.Provider,{value:Ae,children:e})},Rt=()=>{const{state:e}=I();return e},X=()=>{const{dragState:e}=I();return e},G=()=>{const{actions:e}=I();return e},wt=()=>{const{options:e}=I();return e},xt=e=>{const{actions:t}=I();return c.useMemo(()=>({activateTab:n=>t.activateTab(e,n),closeTab:n=>t.closeTab(e,n),createTab:n=>t.createTab(e,n),reorderTab:(n,a)=>t.reorderTab(e,n,a)}),[t,e])},Nt=e=>{const{actions:t}=I();return c.useMemo(()=>({splitPanel:(n,a)=>t.splitPanel(e,n,a),closePanel:()=>t.closePanel(e),focusPanel:()=>t.focusPanel(e)}),[t,e])},Lt=()=>{const{actions:e}=I();return c.useMemo(()=>({startDrag:e.startDrag,setDropTarget:e.setDropTarget,endDrag:e.endDrag,executeDrop:e.executeDrop}),[e])},Ot="pnlpnl",At="pnlpnlcnt",It="pnlsplitcnt",Pt="pnlpnlChild",jt="pnlsplitter",Mt="pnlvtspl",_t="pnlhzspl",zt="pnlspl",$t="pnlleafcnt",Bt="pnldrotar",kt="pnltabBar",Zt="pnltabs",Xt="pnltab",Ht="pnlactTab",Ut="pnltabdrg",Vt="pnltabdraove",Ft="pnltabdrozon",Gt="pnltabTitle",Yt="pnltabe5v",Wt="pnlnewtab",Kt="pnltabctn",qt="pnldrozonlay",Jt="pnldragact",Qt="pnldropZone",en="pnlact",tn="pnldrozonlef",nn="pnldrozonrig",rn="pnldrozontop",an="pnldrozonbot",sn="pnldrozoncen",on="pnldrg",ln="pnlresizing",D={panel:Ot,panelContainer:At,splitContainer:It,panelChild:Pt,splitter:jt,verticalSplitter:Mt,horizontalSplitter:_t,splitterDragging:zt,leafContainer:$t,dropTarget:Bt,tabBar:kt,tabs:Zt,tab:Xt,activeTab:Ht,tabDragging:Ut,tabDragOver:Vt,tabDropZone:Ft,tabTitle:Gt,tabCloseButton:Yt,newTabButton:Wt,tabContent:Kt,dropZoneLayer:qt,dragActive:Jt,dropZone:Qt,active:en,dropZoneLeft:tn,dropZoneRight:nn,dropZoneTop:rn,dropZoneBottom:an,dropZoneCenter:sn,dragging:on,resizing:ln},cn=({value:e,defaultValue:t,onChange:n,style:a,className:r,children:l,onRequestTabCreate:o,onTabClose:i,onTabMove:u,onPanelSplit:s,onPanelClose:b,renderTabBar:d,renderSplitter:g,renderDropZone:m,options:p})=>f.jsx(Le,{value:e,defaultValue:t,onChange:n,options:p,children:f.jsx("div",{className:`${D.panel} ${r||""}`,style:a,children:f.jsx(un,{children:l,onRequestTabCreate:o,onTabClose:i,onTabMove:u,onPanelSplit:s,onPanelClose:b,renderTabBar:d,renderSplitter:g,renderDropZone:m})})}),un=e=>{const{state:t}=I(),n=X();return f.jsx("div",{className:`${D.panelContainer} ${n.isDragging?D.dragActive:""}`,children:f.jsx(Oe,{node:t.root,...e})})},Oe=c.memo(({node:e,...t})=>e.type==="split"?f.jsx(dn,{node:e,...t}):f.jsx(pn,{node:e,...t})),dn=c.memo(({node:e,renderSplitter:t,...n})=>{const a=G(),[r,l]=c.useState(!1),o=c.useRef(null),i=c.useCallback((s,b)=>{if(!o.current)return;const d=e.orientation==="horizontal"?o.current.offsetWidth:o.current.offsetHeight,g=[...e.sizes],m=g.reduce((S,T)=>S+T,0),p=g.map(S=>S/m*d);p[s]+=b,p[s+1]-=b;const v=50;if(p[s]<v){const S=v-p[s];p[s]=v,p[s+1]-=S}if(p[s+1]<v){const S=v-p[s+1];p[s+1]=v,p[s]-=S}const y=p.reduce((S,T)=>S+T,0),h=p.map(S=>S/y);a.resizePanel(e.id,h)},[e.id,e.orientation,e.sizes,a]),u={display:"flex",flexDirection:e.orientation==="horizontal"?"row":"column",width:"100%",height:"100%"};return f.jsx("div",{ref:o,className:D.splitContainer,style:u,children:e.children.map((s,b)=>f.jsxs(c.Fragment,{children:[f.jsx("div",{className:D.panelChild,style:{flex:e.sizes[b]||1,minWidth:e.orientation==="horizontal"?"50px":void 0,minHeight:e.orientation==="vertical"?"50px":void 0},children:f.jsx(Oe,{node:s,...n})}),b<e.children.length-1&&f.jsx(gn,{orientation:e.orientation,onResize:d=>i(b,d),onResizeStart:()=>l(!0),onResizeEnd:()=>l(!1),isResizing:r,renderSplitter:t})]},s.id))})}),pn=c.memo(({node:e,children:t,onRequestTabCreate:n,onTabClose:a,onTabMove:r,renderTabBar:l,...o})=>{const i=G(),u=X(),s=e.tabs.find(h=>h.id===e.activeTabId),b=c.useCallback(h=>{i.activateTab(e.id,h)},[i,e.id]),d=c.useCallback(h=>{(a?a(h,e.id):!0)!==!1&&i.closeTab(e.id,h)},[i,e.id,a]),g=c.useCallback(()=>{if(n){const h=n(e.id);h&&i.createTab(e.id,h)}},[i,e.id,n]),m=c.useCallback((h,S)=>{console.log("๐ Tab Drag Start:",{tabId:h,leafId:e.id}),S.dataTransfer.effectAllowed="move",S.dataTransfer.setData("text/tab-id",h),i.startDrag(h,e.id)},[i,e.id]),p=c.useCallback(()=>{console.log("๐ Tab Drag End - Scheduling cleanup"),setTimeout(()=>{console.log("๐งน Executing endDrag cleanup"),i.endDrag()},200)},[i]),v=c.useCallback((h,S)=>{if(console.log("๐ LEAF DROP:",{draggedTabId:h,index:S,sourceLeaf:u.sourceLeafId,targetLeaf:e.id,currentDragState:u}),!h||!u.sourceLeafId){console.log("โ Missing essential data:",{draggedTabId:h,sourceLeafId:u.sourceLeafId});return}console.log("โ
Proceeding with drop execution"),u.sourceLeafId===e.id?(console.log("๐ REORDER in same panel"),i.reorderTab(e.id,h,S)):(console.log("๐ MOVE to different panel"),(r?r(h,u.sourceLeafId,e.id,S):!0)!==!1&&i.moveTab(u.sourceLeafId,e.id,h,S))},[i,e.id,u,r]),y=u.dropTargetLeafId===e.id;return f.jsxs("div",{className:`${D.leafContainer} ${y?D.dropTarget:""} ${u.isDragging?D.dragging:""}`,children:[f.jsx(bn,{leafId:e.id}),l?l({leafId:e.id,tabs:e.tabs,activeTabId:e.activeTabId,onTabClick:b,onTabClose:d,onTabDragStart:m,onTabDragEnd:p,onTabDrop:v,onNewTab:g,isDropTarget:y}):f.jsx(fn,{leafId:e.id,tabs:e.tabs,activeTabId:e.activeTabId,onTabClick:b,onTabClose:d,onTabDragStart:m,onTabDragEnd:p,onTabDrop:v,onNewTab:g,isDropTarget:y}),f.jsx("div",{className:D.tabContent,children:s&&t(s)})]})}),fn=c.memo(({tabs:e,activeTabId:t,onTabClick:n,onTabClose:a,onTabDragStart:r,onTabDragEnd:l,onTabDrop:o,onNewTab:i,isDropTarget:u})=>{const[s,b]=c.useState(null),d=X(),g=c.useCallback((h,S)=>{console.log("๐ฏ START Drag:",{tabId:S}),h.dataTransfer.effectAllowed="move",h.dataTransfer.setData("text/tab-id",S),r(S,h)},[r]),m=c.useCallback(()=>{console.log("๐ DefaultTabBar END Drag - clearing UI state only"),b(null),setTimeout(()=>{console.log("๐ DefaultTabBar calling onTabDragEnd"),l()},50)},[l]),p=c.useCallback((h,S)=>{h.preventDefault(),h.dataTransfer.dropEffect="move",b(S),console.log("๐ฏ OVER:",S)},[]),v=c.useCallback(()=>{b(null)},[]),y=c.useCallback((h,S)=>{h.preventDefault(),h.stopPropagation();const T=h.dataTransfer.getData("text/tab-id");console.log("๐ง TabBar DROP:",{draggedTabId:T,dropIndex:S,isDragging:d.isDragging}),T?(console.log("๐ Executing tab drop immediately"),o(T,S)):console.log("โ No dragged tab ID found"),b(null)},[o,d.isDragging]);return f.jsxs("div",{className:`${D.tabBar} ${u?D.dropTarget:""}`,children:[f.jsxs("div",{className:D.tabs,children:[e.map((h,S)=>{const T=d.isDragging&&d.draggedTabId===h.id,R=s===S;return f.jsxs("div",{className:`${D.tab} ${h.id===t?D.activeTab:""} ${T?D.tabDragging:""} ${R?D.tabDragOver:""}`,draggable:!0,onDragStart:E=>g(E,h.id),onDragEnd:m,onDragOver:E=>p(E,S),onDragLeave:v,onDrop:E=>y(E,S),onClick:()=>n(h.id),children:[f.jsx("span",{className:D.tabTitle,children:h.title}),h.isClosable!==!1&&f.jsx("button",{className:D.tabCloseButton,onClick:E=>{E.stopPropagation(),a(h.id)},children:"ร"})]},h.id)}),f.jsx("div",{className:`${D.tabDropZone} ${s===e.length?D.tabDragOver:""}`,onDragOver:h=>p(h,e.length),onDragLeave:v,onDrop:h=>y(h,e.length)})]}),f.jsx("button",{className:D.newTabButton,onClick:i,children:"+"})]})}),gn=c.memo(({orientation:e,onResize:t,onResizeStart:n,onResizeEnd:a,isResizing:r,renderSplitter:l})=>{const[o,i]=c.useState(!1),[u,s]=c.useState({x:0,y:0}),b=c.useCallback(d=>{i(!0),s({x:d.clientX,y:d.clientY}),n();const g=p=>{const v=e==="horizontal"?p.clientX-u.x:p.clientY-u.y;t(v),s({x:p.clientX,y:p.clientY})},m=()=>{i(!1),a(),document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",m)};document.addEventListener("mousemove",g),document.addEventListener("mouseup",m)},[e,t,n,a,u]);return l?l({orientation:e,onResize:t,onResizeStart:n,onResizeEnd:a,isResizing:r}):f.jsx("div",{className:`${D.splitter} ${e==="horizontal"?D.verticalSplitter:D.horizontalSplitter} ${o?D.splitterDragging:""}`,onMouseDown:b})}),bn=c.memo(({leafId:e})=>{const t=X(),n=G(),[a,r]=c.useState(null),l=c.useCallback(s=>{console.log("๐ง DropZone Drop:",{leafId:e,direction:s,dragState:t}),n.setDropTarget(e,s),n.executeDrop(),r(null)},[n,e,t]),o=c.useCallback(s=>{t.sourceLeafId!==e?(console.log("๐ฅ DropZone activated:",{zone:s,leafId:e,sourceLeafId:t.sourceLeafId}),r(s)):console.log("๐ซ DropZone ignored (same panel):",{zone:s,leafId:e})},[t.sourceLeafId,e]),i=c.useCallback(()=>{r(null)},[]);return t.isDragging?t.sourceLeafId===e?(console.log("๐ซ DropZone hidden for same panel operation"),null):f.jsx("div",{className:D.dropZoneLayer,children:f.jsxs(f.Fragment,{children:[f.jsx("div",{className:`${D.dropZone} ${D.dropZoneLeft} ${a==="left"?D.active:""}`,onDragOver:s=>s.preventDefault(),onDragEnter:()=>o("left"),onDragLeave:i,onDrop:s=>{s.preventDefault(),s.dataTransfer.getData("text/tab-id")&&l("left")}}),f.jsx("div",{className:`${D.dropZone} ${D.dropZoneRight} ${a==="right"?D.active:""}`,onDragOver:s=>s.preventDefault(),onDragEnter:()=>o("right"),onDragLeave:i,onDrop:s=>{s.preventDefault(),s.dataTransfer.getData("text/tab-id")&&l("right")}}),f.jsx("div",{className:`${D.dropZone} ${D.dropZoneTop} ${a==="top"?D.active:""}`,onDragOver:s=>s.preventDefault(),onDragEnter:()=>o("top"),onDragLeave:i,onDrop:s=>{s.preventDefault(),s.dataTransfer.getData("text/tab-id")&&l("top")}}),f.jsx("div",{className:`${D.dropZone} ${D.dropZoneBottom} ${a==="bottom"?D.active:""}`,onDragOver:s=>s.preventDefault(),onDragEnter:()=>o("bottom"),onDragLeave:i,onDrop:s=>{s.preventDefault(),s.dataTransfer.getData("text/tab-id")&&l("bottom")}}),f.jsx("div",{className:`${D.dropZone} ${D.dropZoneCenter} ${a==="center"?D.active:""}`,onDragOver:s=>s.preventDefault(),onDragEnter:()=>o("center"),onDragLeave:i,onDrop:s=>{s.preventDefault(),s.dataTransfer.getData("text/tab-id")&&l()}})]})}):null});exports.AppLayout=be;exports.AutoSizer=ge;exports.HeaderMainLayout=fe;exports.Panel=cn;exports.PanelActionType=N;exports.PanelProvider=Le;exports.ParavirtualScroll=ve;exports.ScrollView=ie;exports.SidebarLayout=pe;exports.StickyHeader=he;exports.ViewSwitcher=ye;exports.createInitialState=xe;exports.createPanelActions=Se;exports.panelReducer=we;exports.useDragOperations=Lt;exports.useDragState=X;exports.usePanelActions=G;exports.usePanelContext=I;exports.usePanelOperations=Nt;exports.usePanelOptions=wt;exports.usePanelState=Rt;exports.useTabOperations=xt;