react-resizable-panels 4.0.7 → 4.0.8-alpha.0

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.
@@ -1,2 +1,2 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("react/jsx-runtime"),S=require("react");function b(e,t="Assertion error"){if(!e)throw Error(t)}function se(e,t){return t.sort(e==="horizontal"?Oe:Te)}function Oe(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function Te(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function ee({group:e}){const{orientation:t,panels:n}=e;return n.reduce((o,a)=>(o+=t==="horizontal"?a.element.offsetWidth:a.element.offsetHeight,o),0)}function ye(e){const{element:t,orientation:n,panels:o,separators:a}=e,s=se(n,Array.from(t.children).filter(l=>l instanceof HTMLElement).map(l=>({element:l}))).map(({element:l})=>l),u=[];let i,r;for(const l of s){const f=o.find(c=>c.element===l);if(f){if(i){const c=i.element.getBoundingClientRect(),m=l.getBoundingClientRect();u.push({group:e,groupSize:ee({group:e}),panels:[i,f],separator:r,rect:n==="horizontal"?new DOMRect(c.right,m.top,m.left-c.right,m.height):new DOMRect(m.left,c.bottom,m.width,m.top-c.bottom)})}i=f,r=void 0}else{const c=a.find(m=>m.element===l);c?r=c:(i=void 0,r=void 0)}}return u}function De(e,t){const n=getComputedStyle(e),o=parseFloat(n.fontSize);return t*o}function Ae(e,t){const n=getComputedStyle(e.ownerDocument.body),o=parseFloat(n.fontSize);return t*o}function $e(e){return e/100*window.innerHeight}function Ne(e){return e/100*window.innerWidth}function _e(e){switch(typeof e){case"number":return[e,"px"];case"string":{const t=parseFloat(e);return e.endsWith("%")?[t,"%"]:e.endsWith("px")?[t,"px"]:e.endsWith("rem")?[t,"rem"]:e.endsWith("em")?[t,"em"]:e.endsWith("vh")?[t,"vh"]:e.endsWith("vw")?[t,"vw"]:[t,"%"]}}}function Z({groupSize:e,panelElement:t,styleProp:n}){let o;const[a,s]=_e(n);switch(s){case"%":{o=a/100*e;break}case"px":{o=a;break}case"rem":{o=Ae(t,a);break}case"em":{o=De(t,a);break}case"vh":{o=$e(a);break}case"vw":{o=Ne(a);break}}return o}function I(e){return parseFloat(e.toFixed(3))}function de(e){const{panels:t}=e,n=ee({group:e});return t.map(o=>{const{element:a,panelConstraints:s}=o;let u=0;if(s.collapsedSize){const f=Z({groupSize:n,panelElement:a,styleProp:s.collapsedSize});u=I(f/n*100)}let i;if(s.defaultSize){const f=Z({groupSize:n,panelElement:a,styleProp:s.defaultSize});i=I(f/n*100)}let r=0;if(s.minSize){const f=Z({groupSize:n,panelElement:a,styleProp:s.minSize});r=I(f/n*100)}let l=100;if(s.maxSize){const f=Z({groupSize:n,panelElement:a,styleProp:s.maxSize});l=I(f/n*100)}return{collapsedSize:u,collapsible:s.collapsible===!0,defaultSize:i,minSize:r,maxSize:l,panelId:o.id}})}class je{#e={};addListener(t,n){const o=this.#e[t];return o===void 0?this.#e[t]=[n]:o.includes(n)||o.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const o=this.#e[t];if(o!==void 0)if(o.length===1)o[0].call(null,n);else{let a=!1,s=null;const u=Array.from(o);for(let i=0;i<u.length;i++){const r=u[i];try{r.call(null,n)}catch(l){s===null&&(a=!0,s=l)}}if(a)throw s}}removeAllListeners(){this.#e={}}removeListener(t,n){const o=this.#e[t];if(o!==void 0){const a=o.indexOf(n);a>=0&&o.splice(a,1)}}}function P(e,t,n=0){return Math.abs(I(e)-I(t))<=n}let C={cursorFlags:0,interactionState:{state:"inactive"},mountedGroups:new Map};const D=new je;function O(){return C}function M(e){const t=typeof e=="function"?e(C):e;if(C===t)return C;const n=C;return C={...C,...t},t.cursorFlags!==void 0&&D.emit("cursorFlagsChange",C.cursorFlags),t.interactionState!==void 0&&D.emit("interactionStateChange",C.interactionState),t.mountedGroups!==void 0&&(C.mountedGroups.forEach((o,a)=>{o.derivedPanelConstraints.forEach(s=>{if(s.collapsible){const{layout:u}=n.mountedGroups.get(a)??{};if(u){const i=P(s.collapsedSize,o.layout[s.panelId]),r=P(s.collapsedSize,u[s.panelId]);i&&!r&&(a.inMemoryLastExpandedPanelSizes[s.panelId]=u[s.panelId])}}})}),D.emit("mountedGroupsChange",C.mountedGroups)),C}const Fe=e=>e,oe=()=>{},xe=1,ze=2,be=4,we=8,pe={coarse:10,precise:5};function He({cursorFlags:e,groups:t,state:n}){let o=0,a=0;switch(n){case"active":case"hover":t.forEach(s=>{if(!s.disableCursor)switch(s.orientation){case"horizontal":{o++;break}case"vertical":{a++;break}}})}if(o===0&&a===0)return null;switch(n){case"active":{const s=(e&xe)!==0,u=(e&ze)!==0,i=(e&be)!==0,r=(e&we)!==0;if(e){if(s)return i?"se-resize":r?"ne-resize":"e-resize";if(u)return i?"sw-resize":r?"nw-resize":"w-resize";if(i)return"s-resize";if(r)return"n-resize"}break}}return o>0&&a>0?"move":o>0?"ew-resize":"ns-resize"}let ie,k;function re(){k===void 0&&(k=new CSSStyleSheet,document.adoptedStyleSheets=[k]);const{cursorFlags:e,interactionState:t}=O();switch(t.state){case"active":case"hover":{const n=He({cursorFlags:e,groups:t.hitRegions.map(a=>a.group),state:t.state}),o=`*{cursor: ${n} !important; ${t.state==="active"?"touch-action: none;":""} }`;if(ie===o)return;ie=o,n?k.cssRules.length===0?k.insertRule(o):k.replaceSync(o):k.cssRules.length===1&&k.deleteRule(0);break}case"inactive":{ie=void 0,k.cssRules.length===1&&k.deleteRule(0);break}}}function We(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function H(e,t){return P(e,t)?0:e>t?1:-1}function _({panelConstraints:e,size:t}){const{collapsedSize:n=0,collapsible:o,maxSize:a=100,minSize:s=0}=e;if(H(t,s)<0)if(o){const u=(n+s)/2;H(t,u)<0?t=n:t=s}else t=s;return t=Math.min(a,t),t=I(t),t}function W({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:o,prevLayout:a,trigger:s}){if(P(e,0))return t;const u=Object.values(t),i=Object.values(a),r=[...u],[l,f]=o;b(l!=null,"Invalid first pivot index"),b(f!=null,"Invalid second pivot index");let c=0;if(s==="keyboard"){{const d=e<0?f:l,p=n[d];b(p,`Panel constraints not found for index ${d}`);const{collapsedSize:h=0,collapsible:v,minSize:z=0}=p;if(v){const x=u[d];if(b(x!=null,`Previous layout not found for panel index ${d}`),P(x,h)){const y=z-x;H(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}{const d=e<0?l:f,p=n[d];b(p,`No panel constraints found for index ${d}`);const{collapsedSize:h=0,collapsible:v,minSize:z=0}=p;if(v){const x=u[d];if(b(x!=null,`Previous layout not found for panel index ${d}`),P(x,z)){const y=x-h;H(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}}{const d=e<0?1:-1;let p=e<0?f:l,h=0;for(;;){const z=u[p];b(z!=null,`Previous layout not found for panel index ${p}`);const y=_({panelConstraints:n[p],size:100})-z;if(h+=y,p+=d,p<0||p>=n.length)break}const v=Math.min(Math.abs(e),Math.abs(h));e=e<0?0-v:v}{let p=e<0?l:f;for(;p>=0&&p<n.length;){const h=Math.abs(e)-Math.abs(c),v=u[p];b(v!=null,`Previous layout not found for panel index ${p}`);const z=v-h,x=_({panelConstraints:n[p],size:z});if(!P(v,x)&&(c+=v-x,r[p]=x,c.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?p--:p++}}if(We(i,r))return a;{const d=e<0?f:l,p=u[d];b(p!=null,`Previous layout not found for panel index ${d}`);const h=p+c,v=_({panelConstraints:n[d],size:h});if(r[d]=v,!P(v,h)){let z=h-v,y=e<0?f:l;for(;y>=0&&y<n.length;){const L=r[y];b(L!=null,`Previous layout not found for panel index ${y}`);const R=L+z,E=_({panelConstraints:n[y],size:R});if(P(L,E)||(z-=E-L,r[y]=E),P(z,0))break;e>0?y--:y++}}}const m=Object.values(r).reduce((d,p)=>p+d,0);if(!P(m,100,.1))return a;const g=Object.keys(a);return r.reduce((d,p,h)=>(d[g[h]]=p,d),{})}function B(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(H(e[n],t[n])!==0)return!1;return!0}function Pe({event:e,hitRegions:t,initialLayoutMap:n,mountedGroups:o,pointerDownAtPoint:a}){let s=0;const u=new Map(o);t.forEach(i=>{const{group:r,groupSize:l}=i,{disableCursor:f,orientation:c,panels:m}=r;let g=0;a?c==="horizontal"?g=(e.clientX-a.x)/l*100:g=(e.clientY-a.y)/l*100:c==="horizontal"?g=e.clientX<0?-100:100:g=e.clientY<0?-100:100;const d=n.get(r),{derivedPanelConstraints:p,layout:h,separatorToPanels:v}=o.get(r)??{};if(p&&d&&h&&v){const z=W({delta:g,initialLayout:d,panelConstraints:p,pivotIndices:i.panels.map(x=>m.indexOf(x)),prevLayout:h,trigger:"mouse-or-touch"});if(B(z,h)){if(g!==0&&!f)switch(c){case"horizontal":{s|=g<0?xe:ze;break}case"vertical":{s|=g<0?be:we;break}}}else{u.set(i.group,{derivedPanelConstraints:p,layout:z,separatorToPanels:v});const x=i.group.panels.map(({id:y})=>y).join(",");i.group.inMemoryLayouts[x]=z}}}),M({cursorFlags:s,mountedGroups:u}),re()}function me(e){if(e.defaultPrevented)return;if(e.relatedTarget!==null)return;if(e.clientX===0&&e.clientY===0)return;const{interactionState:t,mountedGroups:n}=O();switch(t.state){case"active":t.hitRegions.forEach(o=>{e.currentTarget===o.group.element&&Pe({event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n})})}}function Q(e){const t=e.parentElement;b(t,"Parent group element not found");const{mountedGroups:n}=O();for(const[o]of n)if(o.element===t)return o;throw Error("Could not find parent Group for separator element")}function A({layout:e,panelConstraints:t}){const o=[...Object.values(e)],a=o.reduce((i,r)=>i+r,0);if(o.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${o.map(i=>`${i}%`).join(", ")}`);if(!P(a,100)&&o.length>0)for(let i=0;i<t.length;i++){const r=o[i];b(r!=null,`No layout data found for index ${i}`);const l=100/a*r;o[i]=l}let s=0;for(let i=0;i<t.length;i++){const r=o[i];b(r!=null,`No layout data found for index ${i}`);const l=_({panelConstraints:t[i],size:r});r!=l&&(s+=r-l,o[i]=l)}if(!P(s,0))for(let i=0;i<t.length;i++){const r=o[i];b(r!=null,`No layout data found for index ${i}`);const l=r+s,f=_({panelConstraints:t[i],size:l});if(r!==f&&(s-=f-r,o[i]=f,P(s,0)))break}const u=Object.keys(e);return o.reduce((i,r,l)=>(i[u[l]]=r,i),{})}function Le({groupId:e}){const t=()=>{const{mountedGroups:n}=O();for(const[o,a]of n)if(o.id===e)return{group:o,...a};throw Error(`Group ${e} not found`)};return{getLayout(){const{layout:n}=t();return n},setLayout(n){const{derivedPanelConstraints:o,group:a,layout:s,separatorToPanels:u}=t(),i=A({layout:n,panelConstraints:o});return B(s,i)||M(r=>({mountedGroups:new Map(r.mountedGroups).set(a,{derivedPanelConstraints:o,layout:i,separatorToPanels:u})})),i}}}function Re(e){const{mountedGroups:t}=O(),n=t.get(e);return b(n,`Mounted Group ${e.id} not found`),n}function T(e,t){const n=Q(e),o=Re(n),a=n.separators.find(c=>c.element===e);b(a,"Matching separator not found");const s=o.separatorToPanels.get(a);b(s,"Matching panels not found");const u=s.map(c=>n.panels.indexOf(c)),r=Le({groupId:n.id}).getLayout(),l=W({delta:t,initialLayout:r,panelConstraints:o.derivedPanelConstraints,pivotIndices:u,prevLayout:r,trigger:"keyboard"}),f=A({layout:l,panelConstraints:o.derivedPanelConstraints});B(r,f)||M(c=>({mountedGroups:new Map(c.mountedGroups).set(n,{derivedPanelConstraints:o.derivedPanelConstraints,layout:f,separatorToPanels:o.separatorToPanels})}))}function he(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=Q(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&T(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&T(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&T(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&T(t,-5);break}case"End":{e.preventDefault(),T(t,100);break}case"Enter":{e.preventDefault();const o=Q(t),{derivedPanelConstraints:a,layout:s,separatorToPanels:u}=Re(o),i=o.separators.find(c=>c.element===t);b(i,"Matching separator not found");const r=u.get(i);b(r,"Matching panels not found");const l=r[0],f=a.find(c=>c.panelId===l.id);if(b(f,"Panel metadata not found"),f.collapsible){const c=s[l.id],m=f.collapsedSize===c?o.inMemoryLastExpandedPanelSizes[l.id]??f.minSize:f.collapsedSize;T(t,m-c)}break}case"F6":{e.preventDefault();const a=Q(t).separators.map(r=>r.element),s=Array.from(a).findIndex(r=>r===e.currentTarget);b(s!==null,"Index not found");const u=e.shiftKey?s>0?s-1:a.length-1:s+1<a.length?s+1:0;a[u].focus();break}case"Home":{e.preventDefault(),T(t,-100);break}}}function Be(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function Ue(e,t,n){let o,a={x:1/0,y:1/0};for(const s of t){const u=Be(n,s.rect);switch(e){case"horizontal":{u.x<=a.x&&(o=s,a=u);break}case"vertical":{u.y<=a.y&&(o=s,a=u);break}}}return o?{distance:a,hitRegion:o}:void 0}let J;function Ke(){return J===void 0&&(typeof matchMedia=="function"?J=!!matchMedia("(pointer:coarse)").matches:J=!1),J}function Ee(e,t){const n=[];return t.forEach((o,a)=>{if(a.disabled)return;const s=Ke()?pe.coarse:pe.precise,u=ye(a),i=Ue(a.orientation,u,{x:e.clientX,y:e.clientY});i&&i.distance.x<=s&&i.distance.y<=s&&n.push(i.hitRegion)}),n}function ve(e){if(e.defaultPrevented)return;const{mountedGroups:t}=O(),n=Ee(e,t),o=new Set,a=new Set,s=new Set,u=new Map;let i=!1;n.forEach(r=>{o.add(r.group),r.panels.forEach(f=>{a.add(f)}),r.separator&&(s.add(r.separator),i||(i=!0,r.separator.element.focus()));const l=t.get(r.group);l&&u.set(r.group,l.layout)}),M({interactionState:{hitRegions:n,initialLayoutMap:u,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}}),n.length&&e.preventDefault()}function ge(e){if(e.defaultPrevented)return;const{interactionState:t,mountedGroups:n}=O();switch(t.state){case"active":{if(e.type!=="pointerleave"&&e.buttons===0){M(o=>o.interactionState.state==="inactive"?o:{cursorFlags:0,interactionState:{state:"inactive"}});return}Pe({event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint});break}default:{const o=Ee(e,n);o.length===0?t.state!=="inactive"&&M({interactionState:{state:"inactive"}}):M({interactionState:{hitRegions:o,state:"hover"}}),re();break}}}function Se(e){if(e.defaultPrevented)return;e.preventDefault();const{interactionState:t}=O();switch(t.state){case"active":M({cursorFlags:0,interactionState:{state:"inactive"}}),re()}}function Ve(e){let t=0,n=0;const o={};for(const s of e)if(s.defaultSize!==void 0){t++;const u=I(s.defaultSize);n+=u,o[s.panelId]=u}else o[s.panelId]=void 0;const a=e.length-t;if(a!==0){const s=I((100-n)/a);for(const u of e)u.defaultSize===void 0&&(o[u.panelId]=s)}return o}function qe(e,t,n){const o=n[0];if(!o)return;const a=e.panels.find(u=>u.element===t);if(!a||!a.onResize)return;const s=ee({group:e});a.onResize({asPercentage:I(o.inlineSize/s*100),inPixels:o.inlineSize},a.id)}function Xe(e){let t=!0;b(e.separators.length===0||e.separators.length<e.panels.length,"Invalid Group configuration; too many Separator components");const n=new Set,o=new Set,a=new ResizeObserver(c=>{for(const m of c){const{borderBoxSize:g,target:d}=m;d===e.element?t&&M(p=>{const h=p.mountedGroups.get(e);if(h){const v=de(e),z=h.layout,x=A({layout:z,panelConstraints:v});return{mountedGroups:new Map(p.mountedGroups).set(e,{derivedPanelConstraints:v,layout:x,separatorToPanels:h.separatorToPanels})}}return p}):qe(e,d,g)}});a.observe(e.element),e.panels.forEach(c=>{b(!n.has(c.id),`Panel ids must be unique; id "${c.id}" was used more than once`),n.add(c.id),c.onResize&&a.observe(c.element)});const s=de(e),u=e.panels.map(({id:c})=>c).join(","),i=e.inMemoryLayouts[u]??e.defaultLayout??Ve(s),r=A({layout:i,panelConstraints:s}),l=ye(e),f=M(c=>({mountedGroups:new Map(c.mountedGroups).set(e,{derivedPanelConstraints:s,layout:r,separatorToPanels:new Map(l.filter(m=>m.separator).map(m=>[m.separator,m.panels]))})}));return e.element.addEventListener("pointerleave",me),e.separators.forEach(c=>{b(!o.has(c.id),`Separator ids must be unique; id "${c.id}" was used more than once`),o.add(c.id),c.element.addEventListener("keydown",he)}),f.mountedGroups.size===1&&(window.addEventListener("pointerdown",ve),window.addEventListener("pointermove",ge),window.addEventListener("pointerup",Se)),function(){t=!1;const m=M(g=>{const d=new Map(g.mountedGroups);return d.delete(e),{mountedGroups:d}});e.element.removeEventListener("pointerleave",me),e.separators.forEach(g=>{g.element.removeEventListener("keydown",he)}),m.mountedGroups.size===0&&(window.removeEventListener("pointerdown",ve),window.removeEventListener("pointermove",ge),window.removeEventListener("pointerup",Se)),a.disconnect()}}function le(e){const t=S.useId();return`${e??t}`}const j=typeof window<"u"?S.useLayoutEffect:S.useEffect;function ue(e){const t=S.useRef(e);return j(()=>{t.current=e},[e]),S.useCallback(n=>t.current?.(n),[t])}function ce(...e){return ue(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}const Ce="--react-resizable-panels--panel--pointer-events";function Me(e,t){const n=e.replace(/[^a-zA-Z0-9\-_]/g,""),o=t.replace(/[^a-zA-Z0-9\-_]/g,"");return`--react-resizable-panels--${n}--${o}`}const Ge=S.createContext(null);function Ye(e,t){const n=S.useRef({getLayout:()=>({}),setLayout:Fe});S.useImperativeHandle(t,()=>n.current,[]),j(()=>{Object.assign(n.current,Le({groupId:e}))})}function Ze({children:e,className:t,defaultLayout:n,disableCursor:o,disabled:a,elementRef:s,groupRef:u,id:i,onLayoutChange:r,orientation:l="horizontal",style:f,...c}){const m=S.useRef({}),g=ue(w=>{B(m.current,w)||(m.current=w,r?.(w))}),d=le(i),[p,h]=S.useState(!1),[v,z]=S.useState(null),[x,y]=S.useState(n??{}),[L,R]=S.useState([]),[E,U]=S.useState([]),te=S.useRef({}),K=S.useRef({}),V=ce(z,s);Ye(d,u);const q=S.useMemo(()=>({id:d,orientation:l,registerPanel:w=>(R(G=>se(l,[...G,w])),()=>{R(G=>G.filter($=>$!==w))}),registerSeparator:w=>(U(G=>se(l,[...G,w])),()=>{U(G=>G.filter($=>$!==w))})}),[d,l]);j(()=>{if(v!==null&&L.length>0){const w={defaultLayout:n,disableCursor:!!o,disabled:!!a,element:v,id:d,inMemoryLastExpandedPanelSizes:te.current,inMemoryLayouts:K.current,orientation:l,panels:L,separators:E},G=Xe(w),ne=O().mountedGroups.get(w);ne&&(y(ne.layout),g?.(ne.layout));const Ie=D.addListener("interactionStateChange",Y=>{switch(Y.state){case"active":{h(Y.hitRegions.some(N=>N.group===w));break}default:{h(!1);break}}}),ke=D.addListener("mountedGroupsChange",Y=>{const N=Y.get(w);N&&N.derivedPanelConstraints.length>0&&(y(N.layout),g?.(N.layout))});return()=>{G(),Ie(),ke()}}},[n,o,a,v,d,g,l,L,E]);const X={[Ce]:p?"none":void 0};for(const w in x){const G=Me(d,w),$=x[w];X[G]=$}return F.jsx(Ge.Provider,{value:q,children:F.jsx("div",{...c,"aria-orientation":l,className:t,"data-group":!0,"data-testid":d,id:d,ref:V,style:{...f,...X,display:"flex",flexDirection:l==="horizontal"?"row":"column",flexWrap:"nowrap"},children:e})})}function ae(e){return`react-resizable-panels:${e}`}function Je({id:e,layout:t,storage:n}){try{const o=ae(e);n.setItem(o,JSON.stringify(t))}catch(o){console.error(o)}}function Qe({groupId:e,storage:t}){const n=S.useSyncExternalStore(et,()=>t.getItem(ae(e)),()=>t.getItem(ae(e))),o=S.useMemo(()=>n?JSON.parse(n):void 0,[n]),a=S.useCallback(s=>Je({id:e,layout:s,storage:t}),[e,t]);return{defaultLayout:o,onLayoutChange:a}}function et(){return function(){}}function tt(){return S.useState(null)}function nt(){return S.useRef(null)}function fe(){const e=S.useContext(Ge);return b(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function ot({groupId:e,panelId:t}){const n=()=>{const{mountedGroups:i}=O();for(const[r,{derivedPanelConstraints:l,layout:f,separatorToPanels:c}]of i)if(r.id===e)return{derivedPanelConstraints:l,group:r,layout:f,separatorToPanels:c};throw Error(`Group ${e} not found`)},o=()=>{const i=n().derivedPanelConstraints.find(r=>r.panelId===t);if(i!==void 0)return i;throw Error(`Panel constraints not found for Panel ${t}`)},a=()=>{const i=n().group.panels.find(r=>r.id===t);if(i!==void 0)return i;throw Error(`Layout not found for Panel ${t}`)},s=()=>{const i=n().layout[t];if(i!==void 0)return i;throw Error(`Layout not found for Panel ${t}`)},u=i=>{const r=s();if(i===r)return;const{derivedPanelConstraints:l,group:f,layout:c,separatorToPanels:m}=n(),g=f.panels.findIndex(v=>v.id===t),d=g===f.panels.length-1,p=W({delta:d?r-i:i-r,initialLayout:c,panelConstraints:l,pivotIndices:d?[g-1,g]:[g,g+1],prevLayout:c,trigger:"imperative-api"}),h=A({layout:p,panelConstraints:l});B(c,h)||M(v=>({mountedGroups:new Map(v.mountedGroups).set(f,{derivedPanelConstraints:l,layout:h,separatorToPanels:m})}))};return{collapse:()=>{const{collapsible:i,collapsedSize:r}=o(),l=s();i&&l!==r&&u(r)},expand:()=>{const{collapsible:i,collapsedSize:r,minSize:l}=o(),f=s();i&&f===r&&u(l)},getSize:()=>{const{group:i}=n(),r=s(),{element:l}=a(),f=i.orientation==="horizontal"?l.offsetWidth:l.offsetHeight;return{asPercentage:r,inPixels:f}},isCollapsed:()=>{const{collapsible:i,collapsedSize:r}=o(),l=s();return i&&P(r,l)},resize:i=>{if(s()!==i){let l;switch(typeof i){case"number":{const{group:f}=n(),c=ee({group:f});l=I(i/c*100);break}case"string":{l=parseFloat(i);break}}u(l)}}}}function it(e,t){const{id:n}=fe(),o=S.useRef({collapse:oe,expand:oe,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:oe});S.useImperativeHandle(t,()=>o.current,[]),j(()=>{Object.assign(o.current,ot({groupId:n,panelId:e}))})}function st({children:e,className:t,collapsedSize:n="0%",collapsible:o=!1,defaultSize:a,elementRef:s,id:u,maxSize:i="100%",minSize:r="0%",onResize:l,panelRef:f,style:c,...m}){const g=!!u,d=le(u),[p,h]=S.useState(null),v=ce(h,s),{id:z,registerPanel:x}=fe(),y=l!==null,L=ue(E=>{l?.(E,u)});j(()=>{if(p!==null)return x({element:p,id:d,idIsStable:g,onResize:y?L:void 0,panelConstraints:{collapsedSize:n,collapsible:o,defaultSize:a,maxSize:i,minSize:r}})},[n,o,a,p,y,d,g,i,r,L,x]),it(d,f);const R=Me(z,d);return F.jsx("div",{...m,"data-panel":!0,"data-testid":d,id:d,ref:v,style:{...at,flexBasis:0,flexGrow:`var(${R}, 1)`,flexShrink:1,overflow:"hidden",pointerEvents:`var(${Ce})`},children:F.jsx("div",{className:t,style:{width:"100%",height:"100%",...c},children:e})})}const at={minHeight:"unset",maxHeight:"unset",height:"unset",minWidth:"unset",maxWidth:"unset",width:"unset",flex:"unset",flexBasis:"unset",flexShrink:"unset",flexGrow:"unset",border:"unset",borderWidth:"unset",padding:"unset",margin:"unset"};function rt(){return S.useState(null)}function lt(){return S.useRef(null)}function ut({layout:e,panelConstraints:t,panelId:n,panelIndex:o}){let a,s;const u=e[n],i=t.find(r=>r.panelId===n);if(i){const r=i.maxSize,l=s=i.collapsible?i.collapsedSize:i.minSize,f=[o,o+1];s=A({layout:W({delta:l-u,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e,trigger:"keyboard"}),panelConstraints:t})[n],a=A({layout:W({delta:r-u,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e,trigger:"keyboard"}),panelConstraints:t})[n]}return{valueControls:n,valueMax:a,valueMin:s,valueNow:u}}function ct({children:e,className:t,elementRef:n,id:o,style:a,...s}){const u=le(o),[i,r]=S.useState({}),[l,f]=S.useState("inactive"),[c,m]=S.useState(null),g=ce(m,n),{id:d,orientation:p,registerSeparator:h}=fe(),v=p==="horizontal"?"vertical":"horizontal";return j(()=>{if(c!==null){const z={element:c,id:u},x=h(z),y=D.addListener("interactionStateChange",R=>{f(R.state!=="inactive"&&R.hitRegions.some(E=>E.separator===z)?R.state:"inactive")}),L=D.addListener("mountedGroupsChange",R=>{R.forEach(({derivedPanelConstraints:E,layout:U,separatorToPanels:te},K)=>{if(K.id===d){const V=te.get(z);if(V){const q=V[0],X=K.panels.indexOf(q);r(ut({layout:U,panelConstraints:E,panelId:q.id,panelIndex:X}))}}})});return()=>{y(),L(),x()}}},[c,d,u,h]),F.jsx("div",{...s,"aria-controls":i.valueControls,"aria-orientation":v,"aria-valuemax":i.valueMax,"aria-valuemin":i.valueMin,"aria-valuenow":i.valueNow,children:e,className:t,"data-separator":l,"data-testid":u,id:u,ref:g,role:"separator",style:{flexBasis:"auto",...a,flexGrow:0,flexShrink:0},tabIndex:0})}exports.Group=Ze;exports.Panel=st;exports.Separator=ct;exports.useDefaultLayout=Qe;exports.useGroupCallbackRef=tt;exports.useGroupRef=nt;exports.usePanelCallbackRef=rt;exports.usePanelRef=lt;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("react/jsx-runtime"),y=require("react");function z(e,t="Assertion error"){if(!e)throw Error(t)}function se(e,t){return t.sort(e==="horizontal"?Te:De)}function Te(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function De(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function Q({group:e}){const{orientation:t,panels:n}=e;return n.reduce((o,s)=>(o+=t==="horizontal"?s.element.offsetWidth:s.element.offsetHeight,o),0)}function xe(e){const{element:t,orientation:n,panels:o,separators:s}=e,a=se(n,Array.from(t.children).filter(u=>u instanceof HTMLElement).map(u=>({element:u}))).map(({element:u})=>u),l=[];let i,r;for(const u of a){const d=o.find(c=>c.element===u);if(d){if(i){const c=i.element.getBoundingClientRect(),h=u.getBoundingClientRect();l.push({group:e,groupSize:Q({group:e}),panels:[i,d],separator:r,rect:n==="horizontal"?new DOMRect(c.right,h.top,h.left-c.right,h.height):new DOMRect(h.left,c.bottom,h.width,h.top-c.bottom)})}i=d,r=void 0}else{const c=s.find(h=>h.element===u);c?r=c:(i=void 0,r=void 0)}}return l}function Ae(e,t){const n=getComputedStyle(e),o=parseFloat(n.fontSize);return t*o}function $e(e,t){const n=getComputedStyle(e.ownerDocument.body),o=parseFloat(n.fontSize);return t*o}function Ne(e){return e/100*window.innerHeight}function _e(e){return e/100*window.innerWidth}function je(e){switch(typeof e){case"number":return[e,"px"];case"string":{const t=parseFloat(e);return e.endsWith("%")?[t,"%"]:e.endsWith("px")?[t,"px"]:e.endsWith("rem")?[t,"rem"]:e.endsWith("em")?[t,"em"]:e.endsWith("vh")?[t,"vh"]:e.endsWith("vw")?[t,"vw"]:[t,"%"]}}}function Y({groupSize:e,panelElement:t,styleProp:n}){let o;const[s,a]=je(n);switch(a){case"%":{o=s/100*e;break}case"px":{o=s;break}case"rem":{o=$e(t,s);break}case"em":{o=Ae(t,s);break}case"vh":{o=Ne(s);break}case"vw":{o=_e(s);break}}return o}function I(e){return parseFloat(e.toFixed(3))}function pe(e){const{element:t,panels:n}=e;if(typeof t.checkVisibility=="function"&&!t.checkVisibility())return n.map(s=>({collapsedSize:0,collapsible:s.panelConstraints.collapsible===!0,defaultSize:void 0,minSize:0,maxSize:100,panelId:s.id}));const o=Q({group:e});return n.map(s=>{const{element:a,panelConstraints:l}=s;let i=0;if(l.collapsedSize){const c=Y({groupSize:o,panelElement:a,styleProp:l.collapsedSize});i=I(c/o*100)}let r;if(l.defaultSize){const c=Y({groupSize:o,panelElement:a,styleProp:l.defaultSize});r=I(c/o*100)}let u=0;if(l.minSize){const c=Y({groupSize:o,panelElement:a,styleProp:l.minSize});u=I(c/o*100)}let d=100;if(l.maxSize){const c=Y({groupSize:o,panelElement:a,styleProp:l.maxSize});d=I(c/o*100)}return{collapsedSize:i,collapsible:l.collapsible===!0,defaultSize:r,minSize:u,maxSize:d,panelId:s.id}})}class Fe{#e={};addListener(t,n){const o=this.#e[t];return o===void 0?this.#e[t]=[n]:o.includes(n)||o.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const o=this.#e[t];if(o!==void 0)if(o.length===1)o[0].call(null,n);else{let s=!1,a=null;const l=Array.from(o);for(let i=0;i<l.length;i++){const r=l[i];try{r.call(null,n)}catch(u){a===null&&(s=!0,a=u)}}if(s)throw a}}removeAllListeners(){this.#e={}}removeListener(t,n){const o=this.#e[t];if(o!==void 0){const s=o.indexOf(n);s>=0&&o.splice(s,1)}}}function L(e,t,n=0){return Math.abs(I(e)-I(t))<=n}let C={cursorFlags:0,interactionState:{state:"inactive"},mountedGroups:new Map};const D=new Fe;function O(){return C}function M(e){const t=typeof e=="function"?e(C):e;if(C===t)return C;const n=C;return C={...C,...t},t.cursorFlags!==void 0&&D.emit("cursorFlagsChange",C.cursorFlags),t.interactionState!==void 0&&D.emit("interactionStateChange",C.interactionState),t.mountedGroups!==void 0&&(C.mountedGroups.forEach((o,s)=>{o.derivedPanelConstraints.forEach(a=>{if(a.collapsible){const{layout:l}=n.mountedGroups.get(s)??{};if(l){const i=L(a.collapsedSize,o.layout[a.panelId]),r=L(a.collapsedSize,l[a.panelId]);i&&!r&&(s.inMemoryLastExpandedPanelSizes[a.panelId]=l[a.panelId])}}})}),D.emit("mountedGroupsChange",C.mountedGroups)),C}const He=e=>e,oe=()=>{},be=1,ze=2,we=4,Le=8,me={coarse:10,precise:5};function Ve({cursorFlags:e,groups:t,state:n}){let o=0,s=0;switch(n){case"active":case"hover":t.forEach(a=>{if(!a.disableCursor)switch(a.orientation){case"horizontal":{o++;break}case"vertical":{s++;break}}})}if(o===0&&s===0)return null;switch(n){case"active":{const a=(e&be)!==0,l=(e&ze)!==0,i=(e&we)!==0,r=(e&Le)!==0;if(e){if(a)return i?"se-resize":r?"ne-resize":"e-resize";if(l)return i?"sw-resize":r?"nw-resize":"w-resize";if(i)return"s-resize";if(r)return"n-resize"}break}}return o>0&&s>0?"move":o>0?"ew-resize":"ns-resize"}let ie,k;function ae(){k===void 0&&(k=new CSSStyleSheet,document.adoptedStyleSheets=[k]);const{cursorFlags:e,interactionState:t}=O();switch(t.state){case"active":case"hover":{const n=Ve({cursorFlags:e,groups:t.hitRegions.map(s=>s.group),state:t.state}),o=`*{cursor: ${n} !important; ${t.state==="active"?"touch-action: none;":""} }`;if(ie===o)return;ie=o,n?k.cssRules.length===0?k.insertRule(o):k.replaceSync(o):k.cssRules.length===1&&k.deleteRule(0);break}case"inactive":{ie=void 0,k.cssRules.length===1&&k.deleteRule(0);break}}}function We(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function H(e,t){return L(e,t)?0:e>t?1:-1}function _({panelConstraints:e,size:t}){const{collapsedSize:n=0,collapsible:o,maxSize:s=100,minSize:a=0}=e;if(H(t,a)<0)if(o){const l=(n+a)/2;H(t,l)<0?t=n:t=a}else t=a;return t=Math.min(s,t),t=I(t),t}function V({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:o,prevLayout:s,trigger:a}){if(L(e,0))return t;const l=Object.values(t),i=Object.values(s),r=[...l],[u,d]=o;z(u!=null,"Invalid first pivot index"),z(d!=null,"Invalid second pivot index");let c=0;if(a==="keyboard"){{const f=e<0?d:u,p=n[f];z(p,`Panel constraints not found for index ${f}`);const{collapsedSize:v=0,collapsible:m,minSize:b=0}=p;if(m){const x=l[f];if(z(x!=null,`Previous layout not found for panel index ${f}`),L(x,v)){const g=b-x;H(g,Math.abs(e))>0&&(e=e<0?0-g:g)}}}{const f=e<0?u:d,p=n[f];z(p,`No panel constraints found for index ${f}`);const{collapsedSize:v=0,collapsible:m,minSize:b=0}=p;if(m){const x=l[f];if(z(x!=null,`Previous layout not found for panel index ${f}`),L(x,b)){const g=x-v;H(g,Math.abs(e))>0&&(e=e<0?0-g:g)}}}}{const f=e<0?1:-1;let p=e<0?d:u,v=0;for(;;){const b=l[p];z(b!=null,`Previous layout not found for panel index ${p}`);const g=_({panelConstraints:n[p],size:100})-b;if(v+=g,p+=f,p<0||p>=n.length)break}const m=Math.min(Math.abs(e),Math.abs(v));e=e<0?0-m:m}{let p=e<0?u:d;for(;p>=0&&p<n.length;){const v=Math.abs(e)-Math.abs(c),m=l[p];z(m!=null,`Previous layout not found for panel index ${p}`);const b=m-v,x=_({panelConstraints:n[p],size:b});if(!L(m,x)&&(c+=m-x,r[p]=x,c.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?p--:p++}}if(We(i,r))return s;{const f=e<0?d:u,p=l[f];z(p!=null,`Previous layout not found for panel index ${f}`);const v=p+c,m=_({panelConstraints:n[f],size:v});if(r[f]=m,!L(m,v)){let b=v-m,g=e<0?d:u;for(;g>=0&&g<n.length;){const P=r[g];z(P!=null,`Previous layout not found for panel index ${g}`);const R=P+b,E=_({panelConstraints:n[g],size:R});if(L(P,E)||(b-=E-P,r[g]=E),L(b,0))break;e>0?g--:g++}}}const h=Object.values(r).reduce((f,p)=>p+f,0);if(!L(h,100,.1))return s;const S=Object.keys(s);return r.reduce((f,p,v)=>(f[S[v]]=p,f),{})}function W(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(H(e[n],t[n])!==0)return!1;return!0}function Pe({event:e,hitRegions:t,initialLayoutMap:n,mountedGroups:o,pointerDownAtPoint:s}){let a=0;const l=new Map(o);t.forEach(i=>{const{group:r,groupSize:u}=i,{disableCursor:d,orientation:c,panels:h}=r;let S=0;s?c==="horizontal"?S=(e.clientX-s.x)/u*100:S=(e.clientY-s.y)/u*100:c==="horizontal"?S=e.clientX<0?-100:100:S=e.clientY<0?-100:100;const f=n.get(r),{derivedPanelConstraints:p,layout:v,separatorToPanels:m}=o.get(r)??{};if(p&&f&&v&&m){const b=V({delta:S,initialLayout:f,panelConstraints:p,pivotIndices:i.panels.map(x=>h.indexOf(x)),prevLayout:v,trigger:"mouse-or-touch"});if(W(b,v)){if(S!==0&&!d)switch(c){case"horizontal":{a|=S<0?be:ze;break}case"vertical":{a|=S<0?we:Le;break}}}else{l.set(i.group,{derivedPanelConstraints:p,layout:b,separatorToPanels:m});const x=i.group.panels.map(({id:g})=>g).join(",");i.group.inMemoryLayouts[x]=b}}}),M({cursorFlags:a,mountedGroups:l}),ae()}function he(e){if(e.defaultPrevented)return;if(e.relatedTarget!==null)return;if(e.clientX===0&&e.clientY===0)return;const{interactionState:t,mountedGroups:n}=O();switch(t.state){case"active":t.hitRegions.forEach(o=>{e.currentTarget===o.group.element&&Pe({event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n})})}}function J(e){const t=e.parentElement;z(t,"Parent group element not found");const{mountedGroups:n}=O();for(const[o]of n)if(o.element===t)return o;throw Error("Could not find parent Group for separator element")}function A({layout:e,panelConstraints:t}){const o=[...Object.values(e)],s=o.reduce((i,r)=>i+r,0);if(o.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${o.map(i=>`${i}%`).join(", ")}`);if(!L(s,100)&&o.length>0)for(let i=0;i<t.length;i++){const r=o[i];z(r!=null,`No layout data found for index ${i}`);const u=100/s*r;o[i]=u}let a=0;for(let i=0;i<t.length;i++){const r=o[i];z(r!=null,`No layout data found for index ${i}`);const u=_({panelConstraints:t[i],size:r});r!=u&&(a+=r-u,o[i]=u)}if(!L(a,0))for(let i=0;i<t.length;i++){const r=o[i];z(r!=null,`No layout data found for index ${i}`);const u=r+a,d=_({panelConstraints:t[i],size:u});if(r!==d&&(a-=d-r,o[i]=d,L(a,0)))break}const l=Object.keys(e);return o.reduce((i,r,u)=>(i[l[u]]=r,i),{})}function Re({groupId:e}){const t=()=>{const{mountedGroups:n}=O();for(const[o,s]of n)if(o.id===e)return{group:o,...s};throw Error(`Group ${e} not found`)};return{getLayout(){const{layout:n}=t();return n},setLayout(n){const{derivedPanelConstraints:o,group:s,layout:a,separatorToPanels:l}=t(),i=A({layout:n,panelConstraints:o});return W(a,i)||M(r=>({mountedGroups:new Map(r.mountedGroups).set(s,{derivedPanelConstraints:o,layout:i,separatorToPanels:l})})),i}}}function Ee(e){const{mountedGroups:t}=O(),n=t.get(e);return z(n,`Mounted Group ${e.id} not found`),n}function T(e,t){const n=J(e),o=Ee(n),s=n.separators.find(c=>c.element===e);z(s,"Matching separator not found");const a=o.separatorToPanels.get(s);z(a,"Matching panels not found");const l=a.map(c=>n.panels.indexOf(c)),r=Re({groupId:n.id}).getLayout(),u=V({delta:t,initialLayout:r,panelConstraints:o.derivedPanelConstraints,pivotIndices:l,prevLayout:r,trigger:"keyboard"}),d=A({layout:u,panelConstraints:o.derivedPanelConstraints});W(r,d)||M(c=>({mountedGroups:new Map(c.mountedGroups).set(n,{derivedPanelConstraints:o.derivedPanelConstraints,layout:d,separatorToPanels:o.separatorToPanels})}))}function ve(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=J(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&T(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&T(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&T(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&T(t,-5);break}case"End":{e.preventDefault(),T(t,100);break}case"Enter":{e.preventDefault();const o=J(t),{derivedPanelConstraints:s,layout:a,separatorToPanels:l}=Ee(o),i=o.separators.find(c=>c.element===t);z(i,"Matching separator not found");const r=l.get(i);z(r,"Matching panels not found");const u=r[0],d=s.find(c=>c.panelId===u.id);if(z(d,"Panel metadata not found"),d.collapsible){const c=a[u.id],h=d.collapsedSize===c?o.inMemoryLastExpandedPanelSizes[u.id]??d.minSize:d.collapsedSize;T(t,h-c)}break}case"F6":{e.preventDefault();const s=J(t).separators.map(r=>r.element),a=Array.from(s).findIndex(r=>r===e.currentTarget);z(a!==null,"Index not found");const l=e.shiftKey?a>0?a-1:s.length-1:a+1<s.length?a+1:0;s[l].focus();break}case"Home":{e.preventDefault(),T(t,-100);break}}}function Be(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function Ue(e,t,n){let o,s={x:1/0,y:1/0};for(const a of t){const l=Be(n,a.rect);switch(e){case"horizontal":{l.x<=s.x&&(o=a,s=l);break}case"vertical":{l.y<=s.y&&(o=a,s=l);break}}}return o?{distance:s,hitRegion:o}:void 0}let Z;function Ke(){return Z===void 0&&(typeof matchMedia=="function"?Z=!!matchMedia("(pointer:coarse)").matches:Z=!1),Z}function Ce(e,t){const n=[];return t.forEach((o,s)=>{if(s.disabled)return;const a=Ke()?me.coarse:me.precise,l=xe(s),i=Ue(s.orientation,l,{x:e.clientX,y:e.clientY});i&&i.distance.x<=a&&i.distance.y<=a&&n.push(i.hitRegion)}),n}function ye(e){if(e.defaultPrevented)return;const{mountedGroups:t}=O(),n=Ce(e,t),o=new Set,s=new Set,a=new Set,l=new Map;let i=!1;n.forEach(r=>{o.add(r.group),r.panels.forEach(d=>{s.add(d)}),r.separator&&(a.add(r.separator),i||(i=!0,r.separator.element.focus()));const u=t.get(r.group);u&&l.set(r.group,u.layout)}),M({interactionState:{hitRegions:n,initialLayoutMap:l,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}}),n.length&&e.preventDefault()}function Se(e){if(e.defaultPrevented)return;const{interactionState:t,mountedGroups:n}=O();switch(t.state){case"active":{if(e.type!=="pointerleave"&&e.buttons===0){M(o=>o.interactionState.state==="inactive"?o:{cursorFlags:0,interactionState:{state:"inactive"}});return}Pe({event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint});break}default:{const o=Ce(e,n);o.length===0?t.state!=="inactive"&&M({interactionState:{state:"inactive"}}):M({interactionState:{hitRegions:o,state:"hover"}}),ae();break}}}function ge(e){if(e.defaultPrevented)return;e.preventDefault();const{interactionState:t}=O();switch(t.state){case"active":M({cursorFlags:0,interactionState:{state:"inactive"}}),ae()}}function qe(e){let t=0,n=0;const o={};for(const a of e)if(a.defaultSize!==void 0){t++;const l=I(a.defaultSize);n+=l,o[a.panelId]=l}else o[a.panelId]=void 0;const s=e.length-t;if(s!==0){const a=I((100-n)/s);for(const l of e)l.defaultSize===void 0&&(o[l.panelId]=a)}return o}function Xe(e,t,n){const o=n[0];if(!o)return;const s=e.panels.find(l=>l.element===t);if(!s||!s.onResize)return;const a=Q({group:e});s.onResize({asPercentage:I(o.inlineSize/a*100),inPixels:o.inlineSize},s.id)}function Ye(e){let t=!0;z(e.separators.length===0||e.separators.length<e.panels.length,"Invalid Group configuration; too many Separator components");const n=new Set,o=new Set,s=new ResizeObserver(c=>{for(const h of c){const{borderBoxSize:S,target:f}=h;if(f===e.element){if(typeof f.checkVisibility=="function"&&!f.checkVisibility())return;t&&M(p=>{const v=p.mountedGroups.get(e);if(v){const m=pe(e),b=v.layout,x=A({layout:b,panelConstraints:m});return{mountedGroups:new Map(p.mountedGroups).set(e,{derivedPanelConstraints:m,layout:x,separatorToPanels:v.separatorToPanels})}}return p})}else Xe(e,f,S)}});s.observe(e.element),e.panels.forEach(c=>{z(!n.has(c.id),`Panel ids must be unique; id "${c.id}" was used more than once`),n.add(c.id),c.onResize&&s.observe(c.element)});const a=pe(e),l=e.panels.map(({id:c})=>c).join(","),i=e.inMemoryLayouts[l]??e.defaultLayout??qe(a),r=A({layout:i,panelConstraints:a}),u=xe(e),d=M(c=>({mountedGroups:new Map(c.mountedGroups).set(e,{derivedPanelConstraints:a,layout:r,separatorToPanels:new Map(u.filter(h=>h.separator).map(h=>[h.separator,h.panels]))})}));return e.element.addEventListener("pointerleave",he),e.separators.forEach(c=>{z(!o.has(c.id),`Separator ids must be unique; id "${c.id}" was used more than once`),o.add(c.id),c.element.addEventListener("keydown",ve)}),d.mountedGroups.size===1&&(window.addEventListener("pointerdown",ye),window.addEventListener("pointermove",Se),window.addEventListener("pointerup",ge)),function(){t=!1;const h=M(S=>{const f=new Map(S.mountedGroups);return f.delete(e),{mountedGroups:f}});e.element.removeEventListener("pointerleave",he),e.separators.forEach(S=>{S.element.removeEventListener("keydown",ve)}),h.mountedGroups.size===0&&(window.removeEventListener("pointerdown",ye),window.removeEventListener("pointermove",Se),window.removeEventListener("pointerup",ge)),s.disconnect()}}function le(e){const t=y.useId();return`${e??t}`}const j=typeof window<"u"?y.useLayoutEffect:y.useEffect;function ue(e){const t=y.useRef(e);return j(()=>{t.current=e},[e]),y.useCallback(n=>t.current?.(n),[t])}function ce(...e){return ue(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}const Me="--react-resizable-panels--panel--pointer-events";function Ge(e,t){const n=e.replace(/[^a-zA-Z0-9\-_]/g,""),o=t.replace(/[^a-zA-Z0-9\-_]/g,"");return`--react-resizable-panels--${n}--${o}`}const Ie=y.createContext(null);function Ze(e,t){const n=y.useRef({getLayout:()=>({}),setLayout:He});y.useImperativeHandle(t,()=>n.current,[]),j(()=>{Object.assign(n.current,Re({groupId:e}))})}function Je(e){return y.useSyncExternalStore(t=>(e?.addEventListener("contentvisibilityautostatechange",t),()=>{e?.removeEventListener("contentvisibilityautostatechange",t)}),()=>typeof e?.checkVisibility=="function"?e.checkVisibility():!0,()=>!0)}function Qe({children:e,className:t,defaultLayout:n,disableCursor:o,disabled:s,elementRef:a,groupRef:l,id:i,onLayoutChange:r,orientation:u="horizontal",style:d,...c}){const h=y.useRef({}),S=ue(w=>{W(h.current,w)||(h.current=w,r?.(w))}),f=le(i),[p,v]=y.useState(!1),[m,b]=y.useState(null),[x,g]=y.useState(n??{}),[P,R]=y.useState([]),[E,B]=y.useState([]),ee=Je(m),U=y.useRef({}),K=y.useRef({}),q=ce(b,a);Ze(f,l);const te=y.useMemo(()=>({id:f,orientation:u,registerPanel:w=>(R(G=>se(u,[...G,w])),()=>{R(G=>G.filter($=>$!==w))}),registerSeparator:w=>(B(G=>se(u,[...G,w])),()=>{B(G=>G.filter($=>$!==w))})}),[f,u]);j(()=>{if(m===null||P.length===0||typeof m.checkVisibility=="function"&&!m.checkVisibility())return;const w={defaultLayout:n,disableCursor:!!o,disabled:!!s,element:m,id:f,inMemoryLastExpandedPanelSizes:U.current,inMemoryLayouts:K.current,orientation:u,panels:P,separators:E},G=Ye(w),ne=O().mountedGroups.get(w);ne&&(g(ne.layout),S?.(ne.layout));const ke=D.addListener("interactionStateChange",X=>{switch(X.state){case"active":{v(X.hitRegions.some(N=>N.group===w));break}default:{v(!1);break}}}),Oe=D.addListener("mountedGroupsChange",X=>{const N=X.get(w);N&&N.derivedPanelConstraints.length>0&&(g(N.layout),S?.(N.layout))});return()=>{G(),ke(),Oe()}},[n,o,s,m,f,ee,S,u,P,E]);const de={[Me]:p?"none":void 0};for(const w in x){const G=Ge(f,w),$=x[w];de[G]=$}return F.jsx(Ie.Provider,{value:te,children:F.jsx("div",{...c,"aria-orientation":u,className:t,"data-group":!0,"data-testid":f,id:f,ref:q,style:{...d,...de,contentVisibility:"auto",display:"flex",flexDirection:u==="horizontal"?"row":"column",flexWrap:"nowrap"},children:e})})}function re(e){return`react-resizable-panels:${e}`}function et({id:e,layout:t,storage:n}){try{const o=re(e);n.setItem(o,JSON.stringify(t))}catch(o){console.error(o)}}function tt({groupId:e,storage:t}){const n=y.useSyncExternalStore(nt,()=>t.getItem(re(e)),()=>t.getItem(re(e))),o=y.useMemo(()=>n?JSON.parse(n):void 0,[n]),s=y.useCallback(a=>et({id:e,layout:a,storage:t}),[e,t]);return{defaultLayout:o,onLayoutChange:s}}function nt(){return function(){}}function ot(){return y.useState(null)}function it(){return y.useRef(null)}function fe(){const e=y.useContext(Ie);return z(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function st({groupId:e,panelId:t}){const n=()=>{const{mountedGroups:i}=O();for(const[r,{derivedPanelConstraints:u,layout:d,separatorToPanels:c}]of i)if(r.id===e)return{derivedPanelConstraints:u,group:r,layout:d,separatorToPanels:c};throw Error(`Group ${e} not found`)},o=()=>{const i=n().derivedPanelConstraints.find(r=>r.panelId===t);if(i!==void 0)return i;throw Error(`Panel constraints not found for Panel ${t}`)},s=()=>{const i=n().group.panels.find(r=>r.id===t);if(i!==void 0)return i;throw Error(`Layout not found for Panel ${t}`)},a=()=>{const i=n().layout[t];if(i!==void 0)return i;throw Error(`Layout not found for Panel ${t}`)},l=i=>{const r=a();if(i===r)return;const{derivedPanelConstraints:u,group:d,layout:c,separatorToPanels:h}=n(),S=d.panels.findIndex(m=>m.id===t),f=S===d.panels.length-1,p=V({delta:f?r-i:i-r,initialLayout:c,panelConstraints:u,pivotIndices:f?[S-1,S]:[S,S+1],prevLayout:c,trigger:"imperative-api"}),v=A({layout:p,panelConstraints:u});W(c,v)||M(m=>({mountedGroups:new Map(m.mountedGroups).set(d,{derivedPanelConstraints:u,layout:v,separatorToPanels:h})}))};return{collapse:()=>{const{collapsible:i,collapsedSize:r}=o(),u=a();i&&u!==r&&l(r)},expand:()=>{const{collapsible:i,collapsedSize:r,minSize:u}=o(),d=a();i&&d===r&&l(u)},getSize:()=>{const{group:i}=n(),r=a(),{element:u}=s(),d=i.orientation==="horizontal"?u.offsetWidth:u.offsetHeight;return{asPercentage:r,inPixels:d}},isCollapsed:()=>{const{collapsible:i,collapsedSize:r}=o(),u=a();return i&&L(r,u)},resize:i=>{if(a()!==i){let u;switch(typeof i){case"number":{const{group:d}=n(),c=Q({group:d});u=I(i/c*100);break}case"string":{u=parseFloat(i);break}}l(u)}}}}function rt(e,t){const{id:n}=fe(),o=y.useRef({collapse:oe,expand:oe,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:oe});y.useImperativeHandle(t,()=>o.current,[]),j(()=>{Object.assign(o.current,st({groupId:n,panelId:e}))})}function at({children:e,className:t,collapsedSize:n="0%",collapsible:o=!1,defaultSize:s,elementRef:a,id:l,maxSize:i="100%",minSize:r="0%",onResize:u,panelRef:d,style:c,...h}){const S=!!l,f=le(l),[p,v]=y.useState(null),m=ce(v,a),{id:b,registerPanel:x}=fe(),g=u!==null,P=ue(E=>{u?.(E,l)});j(()=>{if(p!==null)return x({element:p,id:f,idIsStable:S,onResize:g?P:void 0,panelConstraints:{collapsedSize:n,collapsible:o,defaultSize:s,maxSize:i,minSize:r}})},[n,o,s,p,g,f,S,i,r,P,x]),rt(f,d);const R=Ge(b,f);return F.jsx("div",{...h,"data-panel":!0,"data-testid":f,id:f,ref:m,style:{...lt,flexBasis:0,flexGrow:`var(${R}, 1)`,flexShrink:1,overflow:"hidden",pointerEvents:`var(${Me})`},children:F.jsx("div",{className:t,style:{width:"100%",height:"100%",...c},children:e})})}const lt={minHeight:"unset",maxHeight:"unset",height:"unset",minWidth:"unset",maxWidth:"unset",width:"unset",flex:"unset",flexBasis:"unset",flexShrink:"unset",flexGrow:"unset",border:"unset",borderWidth:"unset",padding:"unset",margin:"unset"};function ut(){return y.useState(null)}function ct(){return y.useRef(null)}function ft({layout:e,panelConstraints:t,panelId:n,panelIndex:o}){let s,a;const l=e[n],i=t.find(r=>r.panelId===n);if(i){const r=i.maxSize,u=a=i.collapsible?i.collapsedSize:i.minSize,d=[o,o+1];a=A({layout:V({delta:u-l,initialLayout:e,panelConstraints:t,pivotIndices:d,prevLayout:e,trigger:"keyboard"}),panelConstraints:t})[n],s=A({layout:V({delta:r-l,initialLayout:e,panelConstraints:t,pivotIndices:d,prevLayout:e,trigger:"keyboard"}),panelConstraints:t})[n]}return{valueControls:n,valueMax:s,valueMin:a,valueNow:l}}function dt({children:e,className:t,elementRef:n,id:o,style:s,...a}){const l=le(o),[i,r]=y.useState({}),[u,d]=y.useState("inactive"),[c,h]=y.useState(null),S=ce(h,n),{id:f,orientation:p,registerSeparator:v}=fe(),m=p==="horizontal"?"vertical":"horizontal";return j(()=>{if(c!==null){const b={element:c,id:l},x=v(b),g=D.addListener("interactionStateChange",R=>{d(R.state!=="inactive"&&R.hitRegions.some(E=>E.separator===b)?R.state:"inactive")}),P=D.addListener("mountedGroupsChange",R=>{R.forEach(({derivedPanelConstraints:E,layout:B,separatorToPanels:ee},U)=>{if(U.id===f){const K=ee.get(b);if(K){const q=K[0],te=U.panels.indexOf(q);r(ft({layout:B,panelConstraints:E,panelId:q.id,panelIndex:te}))}}})});return()=>{g(),P(),x()}}},[c,f,l,v]),F.jsx("div",{...a,"aria-controls":i.valueControls,"aria-orientation":m,"aria-valuemax":i.valueMax,"aria-valuemin":i.valueMin,"aria-valuenow":i.valueNow,children:e,className:t,"data-separator":u,"data-testid":l,id:l,ref:S,role:"separator",style:{flexBasis:"auto",...s,flexGrow:0,flexShrink:0},tabIndex:0})}exports.Group=Qe;exports.Panel=at;exports.Separator=dt;exports.useDefaultLayout=tt;exports.useGroupCallbackRef=ot;exports.useGroupRef=it;exports.usePanelCallbackRef=ut;exports.usePanelRef=ct;
2
2
  //# sourceMappingURL=react-resizable-panels.cjs.map