Files
small-packages/luci-app-honk/root/etc/honk/doona/assets/Virtualizer-BH6NJSXn.js
T
2026-10-31 01:37:59 +08:00

2 lines
31 KiB
JavaScript

import{el as t,bt as e,cZ as i,er as n,f0 as s,f1 as o,ey as r,eH as l,eS as a,eU as h,f2 as d,ea as u,f3 as c}from"./index-DFPUSiWe.js";import{r as y,$ as g,a as f}from"./vendor-react-64fcanlc.js";class p{constructor(t=0,e=0){this.x=t,this.y=e}copy(){return new p(this.x,this.y)}equals(t){return this.x===t.x&&this.y===t.y}isOrigin(){return 0===this.x&&0===this.y}}class w{constructor(t=0,e=0,i=0,n=0){this.x=t,this.y=e,this.width=i,this.height=n}get maxX(){return this.x+this.width}get maxY(){return this.y+this.height}get area(){return this.width*this.height}get topLeft(){return new p(this.x,this.y)}get topRight(){return new p(this.maxX,this.y)}get bottomLeft(){return new p(this.x,this.maxY)}get bottomRight(){return new p(this.maxX,this.maxY)}intersects(t){return this.area>0&&t.area>0&&this.x<=t.x+t.width&&t.x<=this.x+this.width&&this.y<=t.y+t.height&&t.y<=this.y+this.height}containsRect(t){return this.x<=t.x&&this.y<=t.y&&this.maxX>=t.maxX&&this.maxY>=t.maxY}containsPoint(t){return this.x<=t.x&&this.y<=t.y&&this.maxX>=t.x&&this.maxY>=t.y}getCornerInRect(t){for(let e of["topLeft","topRight","bottomLeft","bottomRight"])if(t.containsPoint(this[e]))return e;return null}equals(t){return t.x===this.x&&t.y===this.y&&t.width===this.width&&t.height===this.height}pointEquals(t){return this.x===t.x&&this.y===t.y}sizeEquals(t){return this.width===t.width&&this.height===t.height}union(t){let e=Math.min(this.x,t.x),i=Math.min(this.y,t.y),n=Math.max(this.maxX,t.maxX)-e,s=Math.max(this.maxY,t.maxY)-i;return new w(e,i,n,s)}intersection(t){if(!this.intersects(t))return new w(0,0,0,0);let e=Math.max(this.x,t.x),i=Math.max(this.y,t.y);return new w(e,i,Math.min(this.maxX,t.maxX)-e,Math.min(this.maxY,t.maxY)-i)}copy(){return new w(this.x,this.y,this.width,this.height)}}class z{constructor(t=0,e=0){this.width=Math.max(t,0),this.height=Math.max(e,0)}copy(){return new z(this.width,this.height)}equals(t){return this.width===t.width&&this.height===t.height}get area(){return this.width*this.height}}let v=0;class m{constructor(t,e){this.virtualizer=t,this.key=++v,this.viewType=e,this.children=new Set,this.reusableViews=new Map,this.layoutInfo=null,this.content=null,this.rendered=null}prepareForReuse(){this.content=null,this.rendered=null,this.layoutInfo=null}getReusableView(t){let e=this.reusableViews.get(t);return e&&e.length>0?e.shift():new b(this.virtualizer,this,t)}reuseChild(t){t.prepareForReuse();let e=this.reusableViews.get(t.viewType);e||(e=[],this.reusableViews.set(t.viewType,e)),e.push(t)}}class S extends m{constructor(t){super(t,"root")}}class b extends m{constructor(t,e,i){super(t,i),this.parent=e}}class x{setVisibleRect(t){let e=performance.now()-this.startTime;e<500&&(t.x!==this.visibleRect.x&&e>0&&(this.velocity.x=(t.x-this.visibleRect.x)/e),t.y!==this.visibleRect.y&&e>0&&(this.velocity.y=(t.y-this.visibleRect.y)/e)),this.startTime=performance.now(),this.visibleRect=t}getOverscannedRect(){let t=this.visibleRect.copy(),e=this.visibleRect.height/3;t.height+=e,this.velocity.y<0&&(t.y-=e);let i=this.visibleRect.width/3;return t.width+=i,this.velocity.x<0&&(t.x-=i),t}constructor(){this.startTime=0,this.velocity=new p(0,0),this.visibleRect=new w}}function I(t){return"x"===t?"width":"height"}function R(t,e,i,n,s){if("start"===i)return t[n]<=s;let o=I(n);return e[o]-(t[n]+t[o])<=s}function C(t,e,i,n,s,o,r,l,a,h){let d=t=>"x"===e?new w(t,a.y,a.width,a.height):new w(a.x,t,a.width,a.height);if(i){let t=function(t,e,i,n,s){let o=i(t.key);if(!o)return null;let r=o.rect[t.corner][e]-n[e]-t.offset;if(0===r)return null;let l=n[e]+r,a=I(e),h=Math.max(0,s[a]-n[a]),d=Math.max(0,Math.min(h,l));return d!==n[e]?d:null}(i,e,l,a,h);if(null!=t)return d(t)}if(n&&!s&&(!o||r>0)){let i=d(function(t,e,i,n){if("start"===t)return 0;let s=I(e);return Math.max(0,i[s]-n[s])}(t,e,h,a));return i.equals(a)?null:i}return null}class k{reset(){this.hasSnappedToEdge=!1,this.hadEstimatedVisibleItems=!1,this.wasNearAnchorEdge=!1}captureBeforeLayout(t,e,i){return t?function(t,e,i,n,s=()=>!0){let o=I(e),r=null;for(let[l,a]of n){if(!a||!s(a))continue;let n=a.rect.intersection(i)[o];if(a.rect.area>0&&n>=4){let n=a.rect.getCornerInRect(i)??"topLeft",s=a.rect[n][e]-i[e];(!r||("end"===t?s<r.offset:s>r.offset))&&(r={key:l,corner:n,offset:s})}}return r}(t.edge,t.axis,i,e,t.isAnchorable):null}resolveAfterLayout(t){let{anchorInfo:e,anchor:i,postLayoutInfos:n,previousVisibleRect:s,previousContentSize:o,contentSize:r,itemSizeChanged:l,isScrolling:a,getLayoutInfo:h}=t;if(!e)return null;let d=this.hadEstimatedVisibleItems,u=this.wasNearAnchorEdge,c=!1;for(let z of n.values())if(z.estimatedSize){c=!0;break}if(this.hadEstimatedVisibleItems=c,d||(this.wasNearAnchorEdge=R(s,o,e.edge,e.axis,e.threshold)),0===s.area)return null;let y="x"===e.axis?"width":"height",g=r[y]-o[y],f=!this.hasSnappedToEdge;if(this.hasSnappedToEdge=!0,!f&&0===g&&!l)return null;let p=f||d&&u||R(s,o,e.edge,e.axis,e.threshold);d||(this.wasNearAnchorEdge=p);let w=f||d&&u?null:i;return C(e.edge,e.axis,w,p,a,l,g,h,s,r)}constructor(){this.hasSnappedToEdge=!1,this.hadEstimatedVisibleItems=!1,this.wasNearAnchorEdge=!1}}class V{constructor(t){this.delegate=t.delegate,this.collection=t.collection,this.layout=t.layout,this.contentSize=new z,this.visibleRect=new w,this.size=new z,this.persistedKeys=new Set,this._visibleViews=new Map,this._renderedContent=new WeakMap,this._rootView=new S(this),this._isScrolling=!1,this._invalidationContext={},this._overscanManager=new x,this._scrollAnchor=new k}isPersistedKey(t){if(this.persistedKeys.has(t))return!0;for(let e of this.persistedKeys)for(;null!=e;){let i=this.layout.getLayoutInfo(e);if(!i||null==i.parentKey)break;if(e=i.parentKey,e===t)return!0}return!1}getParentView(t){return null!=t.parentKey?this._visibleViews.get(t.parentKey):this._rootView}getReusableView(t){let e=this.getParentView(t).getReusableView(t.type);return e.layoutInfo=t,this._renderView(e),e}_renderView(t){if(t.layoutInfo){let{type:e,key:i,content:n}=t.layoutInfo;t.content=n||this.collection.getItem(i),t.rendered=this._renderContent(e,t.content)}}_renderContent(t,e){let i=null!=e?this._renderedContent.get(e):null;if(null!=i)return i;let n=this.delegate.renderView(t,e);return e&&this._renderedContent.set(e,n),n}keyAtPoint(t){let e=new w(t.x,t.y,1,1),i=0===e.area?[]:this.layout.getVisibleLayoutInfos(e);for(let n of i)if(n.rect.intersects(e))return n.key;return null}relayout(t={}){let e=this.layout.UNSTABLE_getScrollAnchorInfo?.(t.layoutOptions)??null,i=null;if(e){let t=[];for(let[e,i]of this._visibleViews){let n=this.layout.getLayoutInfo(e)??i.layoutInfo;n&&t.push([e,n])}i=this._scrollAnchor.captureBeforeLayout(e,t,this.visibleRect)}let n=this.contentSize,s=this.visibleRect;this.layout.update(t);let o=this.layout.getContentSize();this.contentSize=new z(o.width,o.height);let r=this._scrollAnchor.resolveAfterLayout({anchorInfo:e,anchor:i,postLayoutInfos:e?this.getVisibleLayoutInfos():new Map,previousVisibleRect:s,previousContentSize:n,contentSize:this.contentSize,itemSizeChanged:t.itemSizeChanged??!1,isScrolling:this._isScrolling,getLayoutInfo:t=>this.layout.getLayoutInfo(t)});if(r)return void this.delegate.setVisibleRect(r);let l=this.visibleRect,a=t.contentChanged?0:l.x,h=t.contentChanged?0:l.y;if(a=Math.max(0,Math.min(this.contentSize.width-l.width,a)),h=Math.max(0,Math.min(this.contentSize.height-l.height,h)),a!==l.x||h!==l.y){let t=new w(a,h,l.width,l.height);this.delegate.setVisibleRect(t)}else this.updateSubviews()}getVisibleLayoutInfos(){let t;t=this._overscanManager.getOverscannedRect();let e=this.layout.getVisibleLayoutInfos(t),i=new Map;for(let n of e)i.set(n.key,n);return i}updateSubviews(){let t=this.getVisibleLayoutInfos(),e=new Set;for(let[i,n]of this._visibleViews){let s=t.get(i);s&&n.parent===this.getParentView(s)||(this._visibleViews.delete(i),n.parent.reuseChild(n),e.add(n))}for(let[i,n]of t){let t=this._visibleViews.get(i);if(t){t.layoutInfo=n;let e=this.collection.getItem(n.key);t.content!==e&&(null!=t.content&&this._renderedContent.delete(t.content),this._renderView(t))}else t=this.getReusableView(n),t.parent.children.add(t),this._visibleViews.set(i,t),e.delete(t)}for(let i of e)i.parent.children.delete(i),i.parent.reusableViews.clear();if(!this._isScrolling)for(let i of t.keys()){let t=this._visibleViews.get(i);t.parent.children.delete(t),t.parent.children.add(t)}}render(t){let e=this,i=!1,n=!1,s=!1,o=!1,r=!1,l=!1,a=!1,h=!1;if(t.collection!==this.collection&&(e.collection=t.collection,i=!0),t.layout===this.layout&&this.layout.virtualizer===this||(this.layout&&(this.layout.virtualizer=null),t.layout.virtualizer=this,e.layout=t.layout,this._scrollAnchor.reset(),i=!0),t.persistedKeys&&!function(t,e){if(t===e)return!0;if(t.size!==e.size)return!1;for(let i of t)if(!e.has(i))return!1;return!0}(t.persistedKeys,this.persistedKeys)&&(e.persistedKeys=t.persistedKeys,h=!0),!this.visibleRect.equals(t.visibleRect)||!this.size.equals(t.size)){this._overscanManager.setVisibleRect(t.visibleRect);let l=new w(this.visibleRect.x,this.visibleRect.y,this.size.width,this.size.height),a=new w(t.visibleRect.x,t.visibleRect.y,t.size.width,t.size.height);this.layout.shouldInvalidate(a,l)?(n=!t.visibleRect.pointEquals(this.visibleRect),s=!this.size.equals(t.size),o=this.size.width!==t.size.width,r=this.size.height!==t.size.height,i=!0):h=!0,e.visibleRect=t.visibleRect,e.size=t.size}return t.invalidationContext!==this._invalidationContext&&(t.invalidationContext&&(s||=t.invalidationContext.sizeChanged||!1,o||=t.invalidationContext.widthChanged||!1,r||=t.invalidationContext.heightChanged||!1,n||=t.invalidationContext.offsetChanged||!1,l||=t.invalidationContext.itemSizeChanged||!1,a||=null!=t.invalidationContext.layoutOptions&&null!=this._invalidationContext.layoutOptions&&t.invalidationContext.layoutOptions!==this._invalidationContext.layoutOptions&&this.layout.shouldInvalidateLayoutOptions(t.invalidationContext.layoutOptions,this._invalidationContext.layoutOptions),i||=l||s||n||a),this._invalidationContext=t.invalidationContext),t.isScrolling!==this._isScrolling&&(this._isScrolling=t.isScrolling,t.isScrolling||(h=!0)),i?this.relayout({offsetChanged:n,sizeChanged:s,widthChanged:o,heightChanged:r,itemSizeChanged:l,layoutOptionsChanged:a,layoutOptions:this._invalidationContext.layoutOptions}):h&&this.updateSubviews(),Array.from(this._rootView.children)}getVisibleView(t){return this._visibleViews.get(t)}invalidate(t){this.delegate.invalidate(t)}updateItemSize(t,e){if(!this.layout.updateItemSize)return;this.layout.updateItemSize(t,e)&&this.invalidate({itemSizeChanged:!0})}}const O="undefined"!=typeof document?g.useLayoutEffect:()=>{};class E{shouldInvalidate(t,e){return t.width!==e.width||t.height!==e.height}shouldInvalidateLayoutOptions(t,e){return t!==e}update(t){}getItemRect(t){return this.getLayoutInfo(t)?.rect??null}getVisibleRect(){return this.virtualizer.visibleRect}constructor(){this.virtualizer=null}}class M{constructor(t,e,i){this.type=t,this.key=e,this.parentKey=null,this.content=null,this.rect=i,this.estimatedSize=!1,this.isSticky=!1,this.opacity=1,this.transform=null,this.zIndex=0,this.allowOverflow=!1}copy(){let t=new M(this.type,this.key,this.rect.copy());return t.estimatedSize=this.estimatedSize,t.opacity=this.opacity,t.transform=this.transform,t.parentKey=this.parentKey,t.content=this.content,t.isSticky=this.isSticky,t.zIndex=this.zIndex,t.allowOverflow=this.allowOverflow,t}}const L=48;class T extends E{constructor(t={}){super(),this.rowSize=t?.rowSize??t?.rowHeight??null,this.orientation=t.orientation??"vertical",this.estimatedRowSize=t?.estimatedRowSize??t?.estimatedRowHeight??null,this.headingSize=t?.headingSize??t?.headingHeight??null,this.estimatedHeadingSize=t?.estimatedHeadingSize??t?.estimatedHeadingHeight??null,this.loaderSize=t?.loaderSize??t?.loaderHeight??null,this.dropIndicatorThickness=t.dropIndicatorThickness||2,this.gap=t.gap||0,this.padding=t.padding||0,this.layoutNodes=new Map,this.rootNodes=[],this.lastCollection=null,this.invalidateEverything=!1,this.validRect=new w,this.requestedRect=new w,this.contentSize=new z}get collection(){return this.virtualizer.collection}get rowHeight(){return this.rowSize}get estimatedRowHeight(){return this.estimatedRowSize}get headingHeight(){return this.headingSize}get estimatedHeadingHeight(){return this.estimatedHeadingSize}get loaderHeight(){return this.loaderSize}getLayoutInfo(t){return this.ensureLayoutInfo(t),this.layoutNodes.get(t)?.layoutInfo||null}getVisibleLayoutInfos(t){let e="horizontal"===this.orientation?"x":"y",i="horizontal"===this.orientation?"width":"height";if(t[i]>1){let n=(this.rowSize??this.estimatedRowSize??L)+this.gap;t=t.copy();let s=Math.floor(t[e]/n)*n,o=t[i]+t[e]-s;t[e]=s,t[i]=Math.ceil(o/n)*n}this.layoutIfNeeded(t);let n=[],s=e=>{for(let i of e)this.isVisible(i,t)&&(n.push(i.layoutInfo),i.children&&s(i.children))};return s(this.rootNodes),n}layoutIfNeeded(t){if(this.lastCollection){this.requestedRect.containsRect(t)||(this.requestedRect=this.requestedRect.union(t),this.rootNodes=this.buildCollection());for(let t of this.virtualizer.persistedKeys)if(this.ensureLayoutInfo(t))return}}ensureLayoutInfo(t){return!!(!this.layoutNodes.has(t)&&this.requestedRect.area<this.contentSize.area&&this.lastCollection)&&(this.requestedRect=new w(0,0,1/0,1/0),this.rootNodes=this.buildCollection(),this.requestedRect=new w(0,0,this.contentSize.width,this.contentSize.height),!0)}isVisible(t,e){return t.layoutInfo.rect.intersects(e)||t.layoutInfo.isSticky||"header"===t.layoutInfo.type||"loader"===t.layoutInfo.type||this.virtualizer.isPersistedKey(t.layoutInfo.key)}shouldInvalidateEverything(t){let e=t.layoutOptions;return t.sizeChanged||this.rowSize!==(e?.rowSize??e?.rowHeight??this.rowSize)||this.orientation!==(e?.orientation??this.orientation)||this.headingSize!==(e?.headingSize??e?.headingHeight??this.headingSize)||this.loaderSize!==(e?.loaderSize??e?.loaderHeight??this.loaderSize)||this.gap!==(e?.gap??this.gap)||this.padding!==(e?.padding??this.padding)}shouldInvalidateLayoutOptions(t,e){return(t?.rowSize??t?.rowHeight)!==(e?.rowSize??e?.rowHeight)||t.orientation!==e.orientation||(t?.estimatedRowSize??t?.estimatedRowHeight)!==(e?.estimatedRowSize??e?.estimatedRowHeight)||(t?.headingSize??t?.headingHeight)!==(e?.headingSize??e?.headingHeight)||(t?.estimatedHeadingSize??t?.estimatedHeadingHeight)!==(e?.estimatedHeadingSize??e?.estimatedHeadingHeight)||(t?.loaderSize??t?.loaderHeight)!==(e?.loaderSize??e?.loaderHeight)||t.dropIndicatorThickness!==e.dropIndicatorThickness||t.gap!==e.gap||t.padding!==e.padding}update(t){let e=this.virtualizer.collection;this.invalidateEverything=this.shouldInvalidateEverything(t),this.invalidateEverything&&(this.requestedRect=this.virtualizer.visibleRect.copy(),this.layoutNodes.clear());let i=t.layoutOptions;if(this.rowSize=i?.rowSize??i?.rowHeight??this.rowSize,this.orientation=i?.orientation??this.orientation,this.estimatedRowSize=i?.estimatedRowSize??i?.estimatedRowHeight??this.estimatedRowSize,this.headingSize=i?.headingSize??i?.headingHeight??this.headingSize,this.estimatedHeadingSize=i?.estimatedHeadingSize??i?.estimatedHeadingHeight??this.estimatedHeadingSize,this.loaderSize=i?.loaderSize??i?.loaderHeight??this.loaderSize,this.dropIndicatorThickness=i?.dropIndicatorThickness??this.dropIndicatorThickness,this.gap=i?.gap??this.gap,this.padding=i?.padding??this.padding,this.rootNodes=this.buildCollection(),this.lastCollection&&e!==this.lastCollection)for(let n of this.lastCollection.getKeys())if(!e.getItem(n)){this.layoutNodes.get(n)&&this.layoutNodes.delete(n)}this.lastCollection=e,this.invalidateEverything=!1,this.validRect=this.requestedRect.copy()}buildCollection(t=this.padding){let e=this.virtualizer.collection,i="horizontal"===this.orientation?"x":"y",n="horizontal"===this.orientation?"maxX":"maxY",s=function(t,e){const i=[];for(const n of t)e(n)&&i.push(n);return i}(e,t=>"content"!==t.type),o=s.filter(t=>"loader"===t.type),r=[],l=0===e?.size;l&&(t=0);for(let a of s){let e=(this.rowSize??this.estimatedRowSize??L)+this.gap;if("item"===a.type&&t+e<this.requestedRect[i]&&!this.isValid(a,t)){t+=e;continue}let l="horizontal"===this.orientation?this.buildChild(a,t,this.padding,null):this.buildChild(a,this.padding,t,null);if(t=l.layoutInfo.rect[n]+this.gap,r.push(l),"loader"===a.type){let t=o.indexOf(a);o.splice(t,1)}if(("item"===a.type||"loader"===a.type)&&t>this.requestedRect[n]){let i=s.indexOf(a);for(let l of o){let o=s.indexOf(l);t+=(o-i-1)*e;let a="horizontal"===this.orientation?this.buildChild(l,t,this.padding,null):this.buildChild(l,this.padding,t,null);r.push(a),t=a.layoutInfo.rect[n],i=o}t+=(s.length-i-1)*e;break}}return t=Math.max(t-this.gap,0),t+=l?0:this.padding,this.contentSize="horizontal"===this.orientation?new z(t,this.virtualizer.size.height):new z(this.virtualizer.size.width,t),r}isValid(t,e){let i=this.layoutNodes.get(t.key),n="horizontal"===this.orientation?"x":"y";return!this.invalidateEverything&&!!i&&i.node===t&&e===i.layoutInfo.rect[n]&&i.layoutInfo.rect.intersects(this.validRect)&&i.validRect.containsRect(i.layoutInfo.rect.intersection(this.requestedRect))}buildChild(t,e,i,n){if(this.isValid(t,"horizontal"===this.orientation?e:i))return this.layoutNodes.get(t.key);let s=this.buildNode(t,e,i);return s.layoutInfo.parentKey=n??null,s.layoutInfo.allowOverflow=!0,this.layoutNodes.set(t.key,s),s}buildNode(t,e,i){switch(t.type){case"section":return this.buildSection(t,e,i);case"item":case"separator":return this.buildItem(t,e,i);case"header":return this.buildSectionHeader(t,e,i);case"loader":return this.buildLoader(t,e,i);default:throw new Error("Unsupported node type: "+t.type)}}buildLoader(t,e,i){let n=new w(e,i,this.padding,0),s=new M(t.type,t.key,n);return"horizontal"===this.orientation?(n.height=this.virtualizer.contentSize.height-this.padding-i,n.width=t.props.isLoading?this.loaderSize??this.rowSize??this.estimatedRowSize??L:0):(n.width=this.virtualizer.contentSize.width-this.padding-e,n.height=t.props.isLoading?this.loaderSize??this.rowSize??this.estimatedRowSize??L:0),{layoutInfo:s,validRect:n.intersection(this.requestedRect)}}buildSection(e,i,n){let s=this.virtualizer.collection,o=this.virtualizer.size.width-this.padding-i,r=this.virtualizer.size.height-this.padding-n,l="horizontal"===this.orientation?new w(i,n,0,r):new w(i,n,o,0),a=new M(e.type,e.key,l),h="horizontal"===this.orientation?i:n,d="horizontal"===this.orientation?"x":"y",u="horizontal"===this.orientation?"maxX":"maxY",c="horizontal"===this.orientation?"width":"height",y=0,g=[];for(let f of t(e,s)){if("content"===f.type)continue;let o=(this.rowSize??this.estimatedRowSize??L)+this.gap;if(h+o<this.requestedRect[d]&&!this.isValid(e,h)){h+=o,y++;continue}let r="horizontal"===this.orientation?this.buildChild(f,h,n,a.key):this.buildChild(f,i,h,a.key);if(h=r.layoutInfo.rect[u]+this.gap,g.push(r),h>this.requestedRect[u]){h+=([...t(e,s)].length-(g.length+y))*o;break}}return h-=this.gap,l[c]=h-("horizontal"===this.orientation?i:n),{layoutInfo:a,children:g,validRect:a.rect.intersection(this.requestedRect),node:e}}buildSectionHeader(t,e,i){let n="horizontal"===this.orientation?"height":"width",s="horizontal"===this.orientation?"width":"height",o=this.virtualizer.size[n]-this.padding-("horizontal"===this.orientation?i:e),r=this.headingSize,l=!1;if(null==r){let e=this.layoutNodes.get(t.key),i=e?.layoutInfo;if(i){let a=this.virtualizer.collection.getItem(t.key),h=this.lastCollection?this.lastCollection.getItem(t.key):null;r=e.layoutInfo.rect[s],l=o!==i.rect[n]||a!==h||i.estimatedSize}else r=t.rendered?this.estimatedHeadingSize:0,l=!0}null==r&&(r=L);let a="horizontal"===this.orientation?new w(e,i,r,o-i):new w(e,i,o-e,r),h=new M("header",t.key,a);return h.estimatedSize=l,{layoutInfo:h,children:[],validRect:h.rect.intersection(this.requestedRect),node:t}}buildItem(t,e,i){let n="horizontal"===this.orientation?"height":"width",s="horizontal"===this.orientation?"width":"height",o=this.virtualizer.size[n]-this.padding-("horizontal"===this.orientation?i:e),r=this.rowSize,l=!1;if(null==r){let e=this.layoutNodes.get(t.key);e?(r=e.layoutInfo.rect[s],l=o!==e.layoutInfo.rect[n]||t!==e.node||e.layoutInfo.estimatedSize):(r=this.estimatedRowSize,l=!0)}null==r&&(r=L);let a="horizontal"===this.orientation?new w(e,i,r,o):new w(e,i,o,r),h=new M(t.type,t.key,a);return h.estimatedSize=l,{layoutInfo:h,children:[],validRect:h.rect.intersection(this.requestedRect),node:t}}updateItemSize(t,e){let i=this.layoutNodes.get(t);if(!i)return!1;let n=this.virtualizer.collection,s=i.layoutInfo,o="horizontal"===this.orientation?"x":"y",r="horizontal"===this.orientation?"width":"height";if(s.estimatedSize=!1,s.rect[r]!==e[r]){let l=s.copy();l.rect[r]=e[r],i.layoutInfo=l,this.validRect[r]=Math.min(this.validRect[r],s.rect[o]-this.validRect[o]),"item"===i.node?.type&&(this.requestedRect[r]+=l.rect[r]-s.rect[r]),this.updateLayoutNode(t,s,l);let a=null!=s.parentKey?n.getItem(s.parentKey):null;for(;a;)this.updateLayoutNode(a.key,s,l),a=null!=a.parentKey?n.getItem(a.parentKey):null;return!0}return!1}updateLayoutNode(t,e,i){let n=this.layoutNodes.get(t);n&&(n.validRect=n.validRect.intersection(this.validRect),n.layoutInfo===e&&(n.layoutInfo=i))}getContentSize(){return this.contentSize}getDropTargetFromPoint(t,e,i){t+=this.virtualizer.visibleRect.x,e+=this.virtualizer.visibleRect.y;let n=new w(t,Math.max(0,e-this.gap),1,Math.max(1,2*this.gap)),s=this.getVisibleLayoutInfos(n),o=null,r=1/0;for(let d of s){if(!d.rect.intersects(n))continue;let t=Math.abs(d.rect.y-e),i=Math.abs(d.rect.maxY-e),s=Math.min(t,i);s<r&&(r=s,o=d.key)}if(null==o||0===this.virtualizer.collection.size)return{type:"root"};let l=this.getLayoutInfo(o);if(!l)return null;let a=l.rect,h={type:"item",key:l.key,dropPosition:"on"};return i(h)?e<=a.y+10&&i({...h,dropPosition:"before"})?h.dropPosition="before":e>=a.maxY-10&&i({...h,dropPosition:"after"})&&(h.dropPosition="after"):e<=a.y+a.height/2&&i({...h,dropPosition:"before"})?h.dropPosition="before":i({...h,dropPosition:"after"})&&(h.dropPosition="after"),h}getDropTargetLayoutInfo(t){let e,i=this.getLayoutInfo(t.key);if("before"===t.dropPosition)e="horizontal"===this.orientation?new w(Math.max(0,i.rect.x-this.dropIndicatorThickness/2),i.rect.y,this.dropIndicatorThickness,i.rect.height):new w(i.rect.x,Math.max(0,i.rect.y-this.dropIndicatorThickness/2),i.rect.width,this.dropIndicatorThickness);else if("after"===t.dropPosition){let n=this.collection.getItem(t.key);if(n){let e=n.level??0,s=this.collection.getKeyAfter(t.key);for(;null!=s;){let t=this.collection.getItem(s);if(!t||t.level<=e)break;i=this.getLayoutInfo(s)||i,s=this.collection.getKeyAfter(s)}}e="horizontal"===this.orientation?new w(i.rect.maxX-this.dropIndicatorThickness/2,i.rect.y,this.dropIndicatorThickness,i.rect.height):new w(i.rect.x,i.rect.maxY-this.dropIndicatorThickness/2,i.rect.width,this.dropIndicatorThickness)}else e=i.rect;return new M("dropIndicator",t.key+":"+t.dropPosition,e)}}let H=null;function _(t,e){let{scrollLeft:i}=t;if("rtl"===e){let{scrollWidth:e,clientWidth:n}=t;switch(function(t=!1){if(null===H||t){const t=document.createElement("div"),e=t.style;e.width="50px",e.height="50px",e.overflow="scroll",e.direction="rtl";const i=document.createElement("div"),n=i.style;return n.width="100px",n.height="100px",t.appendChild(i),document.body.appendChild(t),t.scrollLeft>0?H="positive-descending":(t.scrollLeft=1,H=0===t.scrollLeft?"negative":"positive-ascending"),document.body.removeChild(t),H}return H}()){case"negative":i=-i;break;case"positive-descending":i=e-n-i}}return i}function N(t){let{layoutInfo:e,virtualizer:i,ref:n,shouldObserveItemSize:s}=t,o=e?.key,r=y.useCallback(()=>{if(null!=o&&n.current){if(!d(n.current))return;let t=function(t){let e=t.style.height;t.style.height="";let i=new z(t.scrollWidth,t.scrollHeight);return t.style.height=e,i}(n.current);i.updateItemSize(o,t)}},[i,o,n]),h=l(r);return a(()=>{e?.estimatedSize&&h()}),y.useEffect(()=>{if(!s)return;let t=n.current;if(!t||"undefined"==typeof ResizeObserver)return;let e=new ResizeObserver(t=>{t.length&&h()});for(let i of t.children)e.observe(i);return()=>{e.disconnect()}},[s,n,o]),{updateSize:r}}function P(t){let{style:i,className:n,layoutInfo:s,virtualizer:o,parent:r,children:l,shouldObserveItemSize:a}=t,{direction:h}=e(),d=y.useRef(null);return N({layoutInfo:s,virtualizer:o,ref:d,shouldObserveItemSize:a}),g.createElement("div",{role:"presentation",ref:d,className:n,style:{...K(s,h,r),...i}},l)}let q=new WeakMap;function K(t,e,i){let n="rtl"===e?"right":"left",s=q.get(t);if(s&&null!=s[n]){if(!i)return s;let e=t.rect.y-i.rect.y,o=t.rect.x-i.rect.x;if(s.top===e&&s[n]===o)return s}let o={top:t.rect.y-(!i||i.allowOverflow&&t.isSticky?0:i.rect.y),[n]:t.rect.x-(!i||i.allowOverflow&&t.isSticky?0:i.rect.x),width:t.rect.width,height:t.rect.height};Object.entries(o).forEach(([t,e])=>{Number.isFinite(e)||(o[t]=void 0)});let r={position:t.isSticky?"sticky":"absolute",display:t.isSticky?"inline-block":void 0,overflow:t.allowOverflow?"visible":"hidden",opacity:t.opacity,zIndex:t.zIndex,transform:t.transform??void 0,contain:"size layout style",...o};return q.set(t,r),r}const A=y.createContext(null),Y=y.createContext(null);function W(t){let{children:e,layout:i,layoutOptions:n,shouldObserveItemSize:s}=t,o=y.useMemo(()=>"function"==typeof i?new i:i,[i]),r=y.useMemo(()=>({isVirtualized:!0,layoutDelegate:o,dropTargetDelegate:o.getDropTargetFromPoint?o:void 0,CollectionRoot:X,CollectionBranch:D}),[o]);return g.createElement(u.Provider,{value:r},g.createElement(Y.Provider,{value:{layout:o,layoutOptions:n,shouldObserveItemSize:s}},e))}function X({collection:t,persistedKeys:d,scrollRef:u,renderDropIndicator:c}){let{layout:v,layoutOptions:m,shouldObserveItemSize:S}=y.useContext(Y),b=v.useLayoutOptions?.(),x=function(t){let[e,i]=y.useState(new w(0,0,0,0)),[n,s]=y.useState(new z),[o,r]=y.useState(!1),[l,a]=y.useState({}),h=y.useRef(!1),[d]=y.useState(()=>new V({collection:t.collection,layout:t.layout,delegate:{setVisibleRect(t){i(t),h.current=!0},renderView:t.renderView,invalidate:a}}));O(()=>{h.current&&(h.current=!1,t.onVisibleRectChange(e))});let u=y.useMemo(()=>null!=t.layoutOptions?{...l,layoutOptions:t.layoutOptions}:l,[l,t.layoutOptions]),c=d.render({layout:t.layout,collection:t.collection,persistedKeys:t.persistedKeys,layoutOptions:t.layoutOptions,visibleRect:e,size:t.allowsWindowScrolling?n:e,invalidationContext:u,isScrolling:o}),g=d.contentSize,f=y.useCallback(()=>{r(!0)},[]),p=y.useCallback(()=>{r(!1)},[]);return y.useMemo(()=>({virtualizer:d,visibleViews:c,setVisibleRect:i,size:n,setSize:s,contentSize:g,isScrolling:o,startScrolling:f,endScrolling:p}),[d,c,i,n,s,g,o,f,p])}({allowsWindowScrolling:!0,layout:v,collection:t,renderView:(t,e)=>e?.render?.(e),onVisibleRectChange(t){let e=u?.current;e&&(e.scrollLeft=t.x,e.scrollTop=t.y)},persistedKeys:d,layoutOptions:y.useMemo(()=>m&&b?{...m,...b}:m||b,[m,b])}),{contentProps:I}=function(t,d){let{contentSize:u,onVisibleRectChange:c,onSizeChange:g,innerStyle:v,onScrollStart:m,onScrollEnd:S,scrollDirection:b="both",onScroll:x,allowsWindowScrolling:I,...R}=t,C=y.useRef({scrollPosition:new p,size:new z,viewportOffset:new p,viewportSize:new z,scrollEndTime:0,scrollTimeout:null,isScrolling:!1,lastVisibleRect:new w}).current,{direction:k}=e(),V=y.useCallback(()=>{let t=I?new w(C.viewportOffset.x+C.scrollPosition.x,C.viewportOffset.y+C.scrollPosition.y,Math.max(0,Math.min(C.size.width-C.viewportOffset.x,C.viewportSize.width)),Math.max(0,Math.min(C.size.height-C.viewportOffset.y,C.viewportSize.height))):new w(C.scrollPosition.x,C.scrollPosition.y,C.size.width,C.size.height);(t.area>0||C.lastVisibleRect.area>0)&&(c(t),C.lastVisibleRect=t)},[C,I,c]),[O,E]=y.useState(!1),M=y.useCallback(t=>{let e=i(t);if(n(e,d.current)){if(x&&e===d.current&&x(t),e!==d.current){let t=d.current.getBoundingClientRect(),e=t.x<0?-t.x:0,i=t.y<0?-t.y:0;if(e===C.viewportOffset.x&&i===C.viewportOffset.y)return;C.viewportOffset=new p(e,i)}else{let t=e.scrollTop,i=_(e,k);C.scrollPosition=new p(Math.max(0,Math.min(i,u.width-C.size.width)),Math.max(0,Math.min(t,u.height-C.size.height)))}f.flushSync(()=>{V(),C.isScrolling||(C.isScrolling=!0,E(!0),window.dispatchEvent(new Event("tk.disconnect-observer")),m&&m());let t=Date.now();C.scrollEndTime<=t+50&&(C.scrollEndTime=t+300,null!=C.scrollTimeout&&clearTimeout(C.scrollTimeout),C.scrollTimeout=setTimeout(()=>{C.isScrolling=!1,E(!1),C.scrollTimeout=null,window.dispatchEvent(new Event("tk.connect-observer")),S&&S()},300))})}},[x,d,k,C,u,V,m,S]);y.useEffect(()=>s(o(d.current,r(d.current)),"scroll",M,!0),[M,d]),y.useEffect(()=>()=>{null!=C.scrollTimeout&&clearTimeout(C.scrollTimeout),C.isScrolling&&window.dispatchEvent(new Event("tk.connect-observer"))},[]);let L=y.useRef(!1),T=y.useCallback(t=>{let e=d.current;if(!e||L.current)return;L.current=!0,Object.getOwnPropertyNames(window.HTMLElement.prototype).includes("clientWidth"),Object.getOwnPropertyNames(window.HTMLElement.prototype).includes("clientHeight");let i=e.clientWidth,n=e.clientHeight,s=i,o=n,r=window.innerWidth,l=window.innerHeight,a=C.viewportSize.width!==r||C.viewportSize.height!==l;a&&(C.viewportSize=new z(r,l)),(C.size.width!==s||C.size.height!==o||a)&&(C.size=new z(s,o),t(()=>{V(),g?.(C.size)}),i===e.clientWidth&&n===e.clientHeight||(C.size=new z(e.clientWidth,e.clientHeight),t(()=>{V(),g?.(C.size)}))),L.current=!1},[d,C,V,g]),H=l(T);a(()=>{C.viewportSize=new z(window.innerWidth,window.innerHeight);let t=()=>{H(f.flushSync)};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[C]);let N=y.useRef(null),[P,q]=y.useState({});a(()=>{if(!(L.current||null!=N.current&&u.equals(N.current))){if("boolean"==typeof IS_REACT_ACT_ENVIRONMENT?IS_REACT_ACT_ENVIRONMENT:"undefined"!=typeof jest)return q({}),void(N.current=u);queueMicrotask(()=>H(f.flushSync))}N.current=u}),a(()=>{H(t=>t())},[P]);let K=y.useCallback(()=>{T(f.flushSync)},[T]);h({ref:d,box:"border-box",onResize:K});let A={padding:0,...R.style};return"horizontal"===b?(A.overflowX="auto",A.overflowY="hidden"):"vertical"===b||u.width===C.size.width?(A.overflowY="auto",A.overflowX="hidden"):A.overflow="auto",v={width:Number.isFinite(u.width)?u.width:void 0,height:Number.isFinite(u.height)?u.height:void 0,pointerEvents:O?"none":"auto",position:"relative",...v},{isScrolling:O,scrollViewProps:{...R,style:A},contentProps:{role:"presentation",style:v}}}({onVisibleRectChange:x.setVisibleRect,onSizeChange:x.setSize,contentSize:x.contentSize,onScrollStart:x.startScrolling,onScrollEnd:x.endScrolling,allowsWindowScrolling:!0},u);return g.createElement("div",I,g.createElement(A.Provider,{value:x},F(null,x.visibleViews,c,S)))}function D({parent:t,renderDropIndicator:e}){let i=y.useContext(A).virtualizer.getVisibleView(t.key),{shouldObserveItemSize:n}=y.useContext(Y);return F(i,Array.from(i.children),e,n)}function F(t,e,i,n){return e.map(e=>function(t,e,i,n){let s=g.createElement(P,{key:e.key,layoutInfo:e.layoutInfo,virtualizer:e.virtualizer,parent:t?.layoutInfo,shouldObserveItemSize:n},e.rendered),{collection:o,layout:r}=e.virtualizer,l=e.content;"item"===l?.type&&i&&r.getDropTargetLayoutInfo&&(s=g.createElement(g.Fragment,{key:e.key},j(t,e,{type:"item",key:e.content.key,dropPosition:"before"},i),s,c(o,l,n=>j(t,e,n,i))));return s}(t,e,i,n))}function j(t,e,i,n){let s=n(i);if(s){let n=e.virtualizer.layout.getDropTargetLayoutInfo(i);s=g.createElement(P,{layoutInfo:n,virtualizer:e.virtualizer,parent:t?.layoutInfo},s)}return s}export{W as $,T as a,E as b,z as c,M as d,w as e};