marquee-selection 0.0.11 → 0.0.12

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
- (function(D,X){typeof exports=="object"&&typeof module<"u"?X(exports):typeof define=="function"&&define.amd?define(["exports"],X):(D=typeof globalThis<"u"?globalThis:D||self,X(D.marqueeSelection={}))})(this,function(D){"use strict";function X(Wt){const{container:O,selectable:ut="img",exclude:tt,selectionMode:pt="intersects",minOverlapRatio:Kt=0,overlapMetric:_t="element",selectedClass:et="selected",onChange:dt,preventAncestorSelection:Jt=!0,conflictStrategy:Qt,groupMode:B=!1,groupOverlayClass:Rt,groupColor:ht,groupRandomColor:Zt=!1,groupColorPalette:nt,multi:It=!1,combineMode:yt,hoverHighlight:ot=!1,hoverClass:At="hovered",onSelectionEnd:Lt,quickGroupOnDblClick:gt=!1,quickGroupSelector:Nt,allowIntersectionSelection:j=!0,allowUnionSelection:H=!0,allowContainmentSelection:U=!0,toolbarButtons:mt}=Wt,Ot=Array.isArray(tt)?tt.filter(Boolean):tt?[tt]:[],bt=t=>{if(!t||!Ot.length)return!1;for(const e of Ot)try{if(t instanceof Element&&t.matches(e))return!0}catch{}return!1};if(!O)throw new Error("container is required");let vt=0,xt=0,W=!1,z=null,wt=!1,F=new Set,V=null,Et="replace",a=[],st=[],I=[],Y=[];const te=()=>`hsl(${Math.floor(Math.random()*360)}, 70%, 55%)`,St=()=>{if(ht&&typeof ht=="string")return ht;if(Zt){if(Array.isArray(nt)&&nt.length>0){const t=Math.floor(Math.random()*nt.length);return nt[t]}return te()}return"rgba(255, 165, 0, 0.9)"};let k=null;const K=[],Ct=[];let T=null;const zt=t=>{if(!t.length)return null;const e=new Set(t);for(let r=0;r<a.length;r++){const i=a[r]||[];if(i.length!==e.size)continue;let c=!0;const o=new Set(i);if(o.size!==e.size&&(c=!1),c){for(const n of e)if(!o.has(n)){c=!1;break}}if(c)return r}return null};let Gt=null;const Bt=t=>{const e=!!I[t],r=a[t]||[];for(const i of r)i.style.visibility=e?"hidden":""},lt=(t,e)=>t<0||t>=a.length?!1:(I[t]=e,Bt(t),!0);let _=null;const rt=t=>{ot&&(_&&_!==t&&_.classList.remove(At),t&&_!==t&&t.classList.add(At),_=t)},ee=()=>{const t=document.createElement("div");return t.style.position="fixed",t.style.left="0px",t.style.top="0px",t.style.width="0px",t.style.height="0px",t.style.outline="1px dashed #268aff",t.style.background="rgba(38,138,255,0.12)",t.style.pointerEvents="none",t.style.zIndex="2147483647",t.style.boxSizing="border-box",document.body.appendChild(t),t},it=(t,e)=>t.left<e.right&&t.right>e.left&&t.top<e.bottom&&t.bottom>e.top,ne=(t,e)=>t.left<=e.left&&t.right>=e.right&&t.top<=e.top&&t.bottom>=e.bottom,oe=(t,e)=>{const r=Math.max(t.left,e.left),i=Math.min(t.right,e.right),c=Math.max(t.top,e.top),o=Math.min(t.bottom,e.bottom),n=Math.max(0,i-r),s=Math.max(0,o-c),y=n*s,d=Math.max(1,e.width*e.height);return y/d},se=(t,e)=>{const r=Math.max(t.left,e.left),i=Math.min(t.right,e.right),c=Math.max(t.top,e.top),o=Math.min(t.bottom,e.bottom),n=Math.max(0,i-r),s=Math.max(0,o-c),y=n*s,d=Math.max(1,t.width*t.height),u=Math.max(1,e.width*e.height),h=d+u-y;return y/h},Ft=(t,e)=>_t==="iou"?se(t,e):oe(t,e),qt=(t,e,r,i)=>{const c=Math.min(t,r),o=Math.min(e,i),n=Math.abs(r-t),s=Math.abs(i-e);return{left:c,top:o,width:n,height:s}},Mt=t=>{const e=t.map(n=>n.getBoundingClientRect()).filter(n=>n.width>0&&n.height>0);if(!e.length)return null;const r=Math.min(...e.map(n=>n.left)),i=Math.min(...e.map(n=>n.top)),c=Math.max(...e.map(n=>n.right)),o=Math.max(...e.map(n=>n.bottom));return{left:r,top:i,width:c-r,height:o-i}},J=()=>{st.forEach(t=>t.remove()),st=[]},L=()=>{if(J(),!B)return;const t=[],e=(r,i)=>r.left<i.right&&r.right>i.left&&r.top<i.bottom&&r.bottom>i.top;a.forEach((r,i)=>{const c=Mt(r);if(!c)return;const o=Y[i]||"rgba(255, 165, 0, 0.9)",n=document.createElement("div");n.style.position="fixed",n.style.pointerEvents="none",n.style.zIndex="2147483646",n.style.left=`${c.left}px`,n.style.top=`${c.top}px`,n.style.width=`${c.width}px`,n.style.height=`${c.height}px`,n.style.boxSizing="border-box",n.style.outline=`1px solid ${o}`,n.style.background="transparent",document.body.appendChild(n);const s=document.createElement("div");s.style.position="absolute",s.style.display="inline-flex",s.style.alignItems="center",s.style.gap="6px",s.style.minWidth="max-content",s.style.padding="2px 6px",s.style.fontSize="12px",s.style.lineHeight="16px",s.style.color="#fff",s.style.background=o,s.style.borderRadius="4px",s.style.pointerEvents="auto";const y=document.createElement("span");y.textContent=`组 ${i+1}`;const d=document.createElement("button");d.textContent=I[i]?"显示":"隐藏",d.style.background="rgba(0,0,0,0.15)",d.style.border="none",d.style.color="#fff",d.style.padding="2px 6px",d.style.borderRadius="3px",d.style.cursor="pointer",d.onclick=b=>{b.stopPropagation(),lt(i,!I[i]),L(),N()};const u=document.createElement("button");u.textContent="取消组",u.style.background="rgba(0,0,0,0.15)",u.style.border="none",u.style.color="#fff",u.style.padding="2px 6px",u.style.borderRadius="3px",u.style.cursor="pointer",u.onclick=b=>{b.stopPropagation(),lt(i,!1),Pt(i)},s.appendChild(y),s.appendChild(d),s.appendChild(u);const h=b=>{const l=c?new DOMRect(c.left,c.top,c.width,c.height):null;if(!l)return[];const f=[];return a.forEach((w,p)=>{if(p===b)return;const x=Mt(w);if(!x)return;const S=new DOMRect(x.left,x.top,x.width,x.height);it(l,S)&&f.push(p)}),f};if((()=>{if(k!==i)return;const b=h(i);if(b.length===0)return;const l=document.createElement("button");l.textContent="合并",l.style.background="rgba(0,0,0,0.15)",l.style.border="none",l.style.color="#fff",l.style.padding="2px 6px",l.style.borderRadius="3px",l.style.cursor="pointer";const f=()=>{const w=s.querySelector(".merge-panel");w&&w.remove();const p=document.createElement("div");p.className="merge-panel",p.style.position="absolute",p.style.left="0",p.style.top="22px",p.style.minWidth="160px",p.style.padding="8px",p.style.background="#fff",p.style.color="#333",p.style.border="1px solid rgba(0,0,0,0.15)",p.style.borderRadius="6px",p.style.boxShadow="0 4px 12px rgba(0,0,0,0.15)",p.style.pointerEvents="auto",p.style.zIndex="2147483647";const x=document.createElement("div");x.textContent="选择要合并的组",x.style.fontSize="12px",x.style.marginBottom="6px",p.appendChild(x);const S=document.createElement("div");S.style.maxHeight="200px",S.style.overflow="auto";const q=[];b.forEach(M=>{const R=document.createElement("label");R.style.display="flex",R.style.alignItems="center",R.style.gap="6px",R.style.fontSize="12px",R.style.margin="4px 0";const G=document.createElement("input");G.type="checkbox",G.checked=!0,G.value=String(M);const Z=document.createElement("span");Z.textContent=`组 ${M+1}`,R.appendChild(G),R.appendChild(Z),S.appendChild(R),q.push(G)}),p.appendChild(S);const P=document.createElement("div");P.style.display="flex",P.style.gap="8px",P.style.marginTop="8px";const C=document.createElement("button");C.textContent="确认",C.style.padding="2px 8px",C.style.cursor="pointer";const $=document.createElement("button");$.textContent="取消",$.style.padding="2px 8px",$.style.cursor="pointer",P.appendChild(C),P.appendChild($),p.appendChild(P),$.onclick=M=>{M.stopPropagation(),p.remove()},C.onclick=M=>{M.stopPropagation();const R=q.filter(E=>E.checked).map(E=>parseInt(E.value,10)).filter(E=>!Number.isNaN(E));if(R.length===0){p.remove();return}const G=new Set;(a[i]||[]).forEach(E=>G.add(E)),R.forEach(E=>{(a[E]||[]).forEach(ae=>G.add(ae))}),a[i]=Array.from(G);const ce=[...R].sort((E,ft)=>ft-E);let kt=i;ce.forEach(E=>{E<0||E>=a.length||E===i||(lt(E,!1),a.splice(E,1),I.splice(E,1),Y.splice(E,1),k!==null&&(k===E?k=null:k>E&&k--),E<kt&&kt--)}),k=kt;const Vt=new Set;a.forEach(E=>E.forEach(ft=>Vt.add(ft))),A(Vt),L(),p.remove(),N()},s.appendChild(p)};l.onclick=w=>{w.stopPropagation(),f()},s.appendChild(l)})(),n.appendChild(s),mt&&mt.length){const b=l=>{const f=document.createElement("button");f.textContent=l.label||"按钮",f.title=l.title||"",f.style.background="rgba(0,0,0,0.15)",f.style.border="none",f.style.color="#fff",f.style.padding="2px 6px",f.style.borderRadius="3px",f.style.cursor="pointer",l.className&&(f.className+=(f.className?" ":"")+l.className),f.onclick=w=>{var p;w.stopPropagation();try{(p=l.onClick)==null||p.call(l,{index:i,group:a[i]||[],controller:Gt,getSnapshot:()=>at(),refresh:()=>{L(),N()},mouseX:w.clientX,mouseY:w.clientY,anchorRect:s.getBoundingClientRect(),anchorEl:s,overlayEl:n})}catch{}},s.appendChild(f)};mt.forEach(b)}(()=>{const b=["tl","tr","bl","br"],l=s.style.visibility;s.style.visibility="hidden";const f=28,w=6;t:for(let p=0;p<b.length;p++)for(let x=0;x<6;x++){s.style.left="",s.style.right="",s.style.top="",s.style.bottom="";const S=s.offsetHeight||22;b[p]==="tl"?(s.style.left="0",s.style.top=`${-S-w+x*f}px`):b[p]==="tr"?(s.style.right="0",s.style.top=`${-S-w+x*f}px`):b[p]==="bl"?(s.style.left="0",s.style.top=`${c.height+w+x*f}px`):(s.style.right="0",s.style.top=`${c.height+w+x*f}px`);const q=s.getBoundingClientRect(),P={left:q.left,top:q.top,right:q.right,bottom:q.bottom};let C=!1;for(const $ of t)if(e(P,$)){C=!0;break}if(!C){t.push(P);break t}}s.style.visibility=l})(),s.addEventListener("mouseenter",()=>{try{st.forEach(b=>b.style.zIndex="2147483646"),n.style.zIndex="2147483647"}catch{}});const v=b=>{const l=document.createElement("div");l.style.position="absolute",l.style.pointerEvents="auto",l.style.background="transparent",l.style.zIndex="2147483647";const f=8;b==="top"?(l.style.cursor="ns-resize",l.style.left="-4px",l.style.right="-4px",l.style.top=`-${f/2|0}px`,l.style.height=`${f}px`):b==="bottom"?(l.style.cursor="ns-resize",l.style.left="-4px",l.style.right="-4px",l.style.bottom=`-${f/2|0}px`,l.style.height=`${f}px`):b==="left"?(l.style.cursor="ew-resize",l.style.top="-4px",l.style.bottom="-4px",l.style.left=`-${f/2|0}px`,l.style.width=`${f}px`):b==="right"?(l.style.cursor="ew-resize",l.style.top="-4px",l.style.bottom="-4px",l.style.right=`-${f/2|0}px`,l.style.width=`${f}px`):b==="nw"?(l.style.cursor="nwse-resize",l.style.left=`-${f/2|0}px`,l.style.top=`-${f/2|0}px`,l.style.width=`${f}px`,l.style.height=`${f}px`):b==="ne"?(l.style.cursor="nesw-resize",l.style.right=`-${f/2|0}px`,l.style.top=`-${f/2|0}px`,l.style.width=`${f}px`,l.style.height=`${f}px`):b==="sw"?(l.style.cursor="nesw-resize",l.style.left=`-${f/2|0}px`,l.style.bottom=`-${f/2|0}px`,l.style.width=`${f}px`,l.style.height=`${f}px`):b==="se"&&(l.style.cursor="nwse-resize",l.style.right=`-${f/2|0}px`,l.style.bottom=`-${f/2|0}px`,l.style.width=`${f}px`,l.style.height=`${f}px`),l.onmousedown=w=>{w.preventDefault(),w.stopPropagation();const p={left:parseFloat(n.style.left||"0"),top:parseFloat(n.style.top||"0"),width:parseFloat(n.style.width||"0"),height:parseFloat(n.style.height||"0")};T={idx:i,side:b,startX:w.clientX,startY:w.clientY,startRect:p,overlay:n},document.addEventListener("mousemove",$t),document.addEventListener("mouseup",le,{once:!0})},n.appendChild(l)};v("top"),v("right"),v("bottom"),v("left"),v("nw"),v("ne"),v("sw"),v("se"),Rt&&n.classList.add(Rt),st.push(n)})},$t=t=>{if(!T)return;const{idx:e,side:r,startX:i,startY:c,startRect:o,overlay:n}=T,s=t.clientX-i,y=t.clientY-c;let d=o.left,u=o.top,h=o.width,g=o.height;const m=4;r==="left"||r==="nw"||r==="sw"?(d=o.left+s,h=o.width-s,h<m&&(d=o.left+(o.width-m),h=m)):(r==="right"||r==="ne"||r==="se")&&(h=o.width+s,h<m&&(h=m)),r==="top"||r==="nw"||r==="ne"?(u=o.top+y,g=o.height-y,g<m&&(u=o.top+(o.height-m),g=m)):(r==="bottom"||r==="sw"||r==="se")&&(g=o.height+y,g<m&&(g=m)),n.style.left=`${d}px`,n.style.top=`${u}px`,n.style.width=`${h}px`,n.style.height=`${g}px`;const v=Q(d,u,h,g),b=new Set(a[e]||[]),l=new Set;a.forEach((C,$)=>{$!==e&&C.forEach(M=>l.add(M))});const f=new Set(v);let w=!1,p=!1;for(let C=0;C<a.length;C++){if(C===e)continue;const $=new Set(a[C]||[]);let M=0;for(const R of f)$.has(R)&&M++;if(M!==0&&!(M===$.size&&M===f.size))if(M===$.size)p=!0;else if(M===f.size)p=!0;else{w=!0;break}}const x=v.filter(C=>!b.has(C)).length,S=!j&&(w||!U&&p),q=!H&&x>0;if(S||q){n.style.outline="1px dashed #ff4d4f",n.style.background="rgba(255,77,79,0.06)";const C=new Set;a.forEach(($,M)=>{(M===e?a[e]||[]:$).forEach(G=>C.add(G))}),A(C)}else{const C=Y[e]||"rgba(255, 165, 0, 0.9)";n.style.outline=`1px solid ${C}`,n.style.background="transparent";const $=new Set;a.forEach((M,R)=>{(R===e?v:M).forEach(Z=>$.add(Z))}),A($)}},le=t=>{if(!T)return;const{idx:e,overlay:r,startRect:i}=T,c=parseFloat(r.style.left||"0"),o=parseFloat(r.style.top||"0"),n=parseFloat(r.style.width||"0"),s=parseFloat(r.style.height||"0"),y=Q(c,o,n,s),d=new Set(a[e]||[]),u=new Set;a.forEach((p,x)=>{x!==e&&p.forEach(S=>u.add(S))});const h=new Set(y);let g=!1,m=!1;for(let p=0;p<a.length;p++){if(p===e)continue;const x=new Set(a[p]||[]);let S=0;for(const q of h)x.has(q)&&S++;if(S!==0&&!(S===x.size&&S===h.size))if(S===x.size||S===h.size)m=!0;else{g=!0;break}}const v=y.filter(p=>!d.has(p)).length,b=!j&&(g||!U&&m),l=!H&&v>0;if(b||l){const p=new Set;a.forEach(x=>x.forEach(S=>p.add(S))),A(p),L(),T=null,document.removeEventListener("mousemove",$t),N();return}a[e]=y;const w=new Set;a.forEach(p=>p.forEach(x=>w.add(x))),A(w),L(),T=null,document.removeEventListener("mousemove",$t),N()},Pt=t=>{if(t<0||t>=a.length)return!1;const e=a[t];e&&e.forEach(i=>i.style.visibility=""),a.splice(t,1),I.splice(t,1),Y.splice(t,1),k!==null&&(k===t?k=null:k>t&&k--),J(),L();const r=new Set;return a.forEach(i=>i.forEach(c=>r.add(c))),A(r),N(),!0},re=t=>{if(!B||!Array.isArray(t)||t.length===0)return!1;const e=Array.from(new Set(t)).filter(u=>{var h;try{return!!u&&O.contains(u)&&!bt(u)&&((h=u.matches)==null?void 0:h.call(u,ut))}catch{return!1}});if(e.length===0||zt(e)!==null)return!1;const i=new Set(e);let c=!1,o=!1;for(const u of a){const h=new Set(u);let g=0;for(const m of i)h.has(m)&&g++;if(g!==0&&!(g===h.size&&g===i.size))if(g===h.size||g===i.size)o=!0;else{c=!0;break}}const n=new Set(F),s=!j&&(c||!U&&o),y=!H&&n.size>0&&e.length>0;if(s||y)return!1;a.push(e),I.push(!1),Y.push(St()),k=a.length-1;const d=new Set;return a.forEach(u=>u.forEach(h=>d.add(h))),A(d),L(),N(),!0},ie=t=>{if(B)return"add";const e=It?yt??"add":"replace";return It?yt==="auto"?t.shiftKey?"add":t.altKey?"subtract":t.metaKey||t.ctrlKey?"toggle":"add":yt??e:"replace"},A=t=>{for(const e of Array.from(F))t.has(e)||e.classList.remove(et);for(const e of Array.from(t))F.has(e)||e.classList.add(et);F=t,dt&&dt(B?{type:"groups",groups:a.slice(),flat:Array.from(F)}:{type:"single",selected:Array.from(F)})},Yt=(t,e,r)=>{if(r==="replace")return new Set(e);const i=new Set(t);if(r==="add")for(const c of e)i.add(c);else if(r==="subtract")for(const c of e)i.delete(c);else if(r==="toggle")for(const c of e)i.has(c)?i.delete(c):i.add(c);return i},Dt=t=>{if(t.button!==0)return;const e=t.target;!O.contains(e)&&e!==document.body||(vt=t.clientX,xt=t.clientY,W=!0,z=ee(),Et=ie(t),V=new Set(F),t.preventDefault())},Tt=t=>{var g;if(!W&&ot){const m=t.target,v=(g=m==null?void 0:m.closest)==null?void 0:g.call(m,ut);v&&O.contains(v)&&!bt(v)?rt(v):rt(null)}if(!W||!z)return;const{left:e,top:r,width:i,height:c}=qt(vt,xt,t.clientX,t.clientY);z.style.left=`${e}px`,z.style.top=`${r}px`,z.style.width=`${i}px`,z.style.height=`${c}px`;const o=Q(e,r,i,c),n=V??new Set,s=new Set(o);let y=0;for(const m of s)n.has(m)&&y++;let d="disjoint";y===0?d="disjoint":y===s.size&&y===n.size?d="equal":y===s.size||y===n.size?d="containment":d="partial";const u=!j&&(d==="partial"||!U&&d==="containment"),h=!H&&n.size>0&&o.length>0;if(wt=u||h,z&&(wt?(z.style.outline="1px dashed #ff4d4f",z.style.background="rgba(255,77,79,0.12)"):(z.style.outline="1px dashed #268aff",z.style.background="rgba(38,138,255,0.12)")),wt)A(n);else{const m=Yt(n,o,Et);A(m)}},Xt=t=>{if(!W)return;W=!1,z&&z.parentNode&&z.parentNode.removeChild(z),z=null;const{left:e,top:r,width:i,height:c}=qt(vt,xt,t.clientX,t.clientY),o=Q(e,r,i,c),n=V??new Set,s=new Set(o);let y=0;for(const v of s)n.has(v)&&y++;let d="disjoint";y===0?d="disjoint":y===s.size&&y===n.size?d="equal":y===s.size||y===n.size?d="containment":d="partial";const u=!j&&(d==="partial"||!U&&d==="containment"),h=!H&&n.size>0&&o.length>0;if(u||h){A(n),V=null,N();return}const m=Yt(n,o,Et);if(A(m),B&&o.length>0){const v=zt(o);if(v!==null){try{console.warn(`重复编组被阻止:与已存在的第${v+1}组元素完全一致`)}catch{}V=null,N();return}a.push(o),k=a.length-1,I.push(!1),Y.push(St());const b=new Set;a.forEach(l=>l.forEach(f=>b.add(f))),A(b),L()}V=null,N()},jt=t=>{var m;if(!gt||!B)return;const e=t.target;if(!e)return;let r=e;if(Nt&&(r=((m=e.closest)==null?void 0:m.call(e,Nt))||null),!r||!O.contains(r))return;const i=r.getBoundingClientRect(),c=Q(i.left,i.top,i.width,i.height),o=new Set(F),n=new Set(c);let s=0;for(const v of n)o.has(v)&&s++;let y="disjoint";s===0?y="disjoint":s===n.size&&s===o.size?y="equal":s===n.size||s===o.size?y="containment":y="partial";const d=!j&&(y==="partial"||!U&&y==="containment"),u=!H&&o.size>0&&c.length>0;if(c.length===0||d||u){N();return}const h=zt(c);if(h!==null){try{console.warn(`重复编组被阻止:与已存在的第${h+1}组元素完全一致`)}catch{}N();return}a.push(c),k=a.length-1,I.push(!1),Y.push(St());const g=new Set;a.forEach(v=>v.forEach(b=>g.add(b))),A(g),L(),N()},Ht=()=>rt(null);function Q(t,e,r,i){if(r===0||i===0)return[];const c=O.getBoundingClientRect(),o=new DOMRect(t,e,r,i);if(!it(o,c))return[];const n=Array.from(O.querySelectorAll(ut));let s=[];const y=new Map;for(const u of n){if(bt(u))continue;const h=u.getBoundingClientRect();if(!it(h,c))continue;let g=!1;if(pt==="contains")g=ne(o,h);else if(pt==="center"){const m=h.left+h.width/2,v=h.top+h.height/2;g=m>=o.left&&m<=o.right&&v>=o.top&&v<=o.bottom}else it(o,h)&&(g=Ft(o,h)>=Math.max(0,Math.min(1,Kt)));if(g){const m=pt==="contains"?1:Ft(o,h);y.set(u,m),s.push(u)}}const d=Qt??(Jt?"leaf":"none");if(d!=="none"&&s.length>1){if(d==="leaf")s=s.filter(u=>!s.some(h=>h!==u&&u.contains(h)));else if(d==="best"){const u=[...s].sort((g,m)=>(y.get(m)||0)-(y.get(g)||0)),h=[];for(const g of u)h.find(v=>v.contains(g)||g.contains(v))||h.push(g);s=h}}return s}document.addEventListener("mousedown",Dt,!0),document.addEventListener("mousemove",Tt),document.addEventListener("mouseup",Xt),ot&&O.addEventListener("mouseleave",Ht),B&&gt&&O.addEventListener("dblclick",jt);const ct=()=>L();B&&(window.addEventListener("scroll",ct,!0),window.addEventListener("resize",ct));const at=()=>{if(B){const t=a.map(o=>Mt(o)),e=Array(a.length).fill(null),r=t.map(o=>o?Math.max(0,o.width*o.height):Number.POSITIVE_INFINITY);for(let o=0;o<a.length;o++){const n=t[o];if(!n)continue;let s=null,y=Number.POSITIVE_INFINITY;for(let d=0;d<a.length;d++){if(o===d)continue;const u=t[d];if(!u)continue;if(u.left<=n.left&&u.top<=n.top&&u.left+u.width>=n.left+n.width&&u.top+u.height>=n.top+n.height){const g=Number(r[d]);g<y&&(y=g,s=d)}}e[o]=s}const i=Array.from({length:a.length},()=>[]);for(let o=0;o<a.length;o++){const n=e[o];n!=null&&i[n]&&i[n].push(o)}const c=[];for(let o=0;o<a.length;o++)(e[o]===null||e[o]===void 0)&&c.push(o);return{type:"groups",groups:a.map(o=>o.slice()),flat:Array.from(F),hidden:I.slice(),groupRects:t,groupNesting:{parents:e,children:i,roots:c}}}return{type:"single",selected:Array.from(F)}},N=()=>{const t=at();if(Lt)try{Lt(t)}catch{}for(const r of K)try{r(t)}catch{}const e=Ct.splice(0);for(const r of e)try{r(t)}catch{}},Ut={destroy(){document.removeEventListener("mousedown",Dt),document.removeEventListener("mousemove",Tt),document.removeEventListener("mouseup",Xt),z&&z.parentNode&&z.parentNode.removeChild(z),z=null,O.querySelectorAll(`.${et}`).forEach(e=>e.classList.remove(et)),ot&&(O.removeEventListener("mouseleave",Ht),rt(null)),B&&(window.removeEventListener("scroll",ct,!0),window.removeEventListener("resize",ct)),B&&gt&&O.removeEventListener("dblclick",jt),J(),a.forEach(e=>e.forEach(r=>r.style.visibility="")),a=[],I=[],Y=[],k=null,F.clear(),K.splice(0),Ct.splice(0)},getGroups(){return a.slice()},clearGroups(){a.forEach(e=>e.forEach(r=>r.style.visibility="")),a=[],I=[],Y=[],k=null,J(),A(new Set)},removeGroup(t){return Pt(t)},addGroup(t){return re(t)},setGroupVisibility(t,e){return lt(t,e)},toggleGroupVisibility(t){return t<0||t>=a.length?!1:(I[t]=!I[t],Bt(t),L(),!0)},getSelectionResult(){return at()},refresh(){L()},hideOverlays(){J()},showAndRefreshOverlays(){L()},getGroupNesting(){const t=at();return t.type==="groups"?t.groupNesting:null},onSelectionEnd(t){return K.push(t),()=>{const e=K.indexOf(t);e>=0&&K.splice(e,1)}},waitForSelectionEnd(){return new Promise(t=>{Ct.push(t)})}};return Gt=Ut,Ut}D.default=X,D.marqueeSelection=X,Object.defineProperties(D,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(D,X){typeof exports=="object"&&typeof module<"u"?X(exports):typeof define=="function"&&define.amd?define(["exports"],X):(D=typeof globalThis<"u"?globalThis:D||self,X(D.marqueeSelection={}))})(this,function(D){"use strict";function X(Wt){const{container:B,selectable:ut="img",exclude:tt,selectionMode:pt="intersects",minOverlapRatio:Kt=0,overlapMetric:_t="element",selectedClass:et="selected",onChange:dt,preventAncestorSelection:Jt=!0,conflictStrategy:Qt,groupMode:q=!1,groupOverlayClass:Rt,groupColor:ht,groupRandomColor:Zt=!1,groupColorPalette:nt,multi:It=!1,combineMode:yt,hoverHighlight:ot=!1,hoverClass:At="hovered",onSelectionEnd:Lt,quickGroupOnDblClick:gt=!1,quickGroupSelector:Nt,allowIntersectionSelection:j=!0,allowUnionSelection:H=!0,allowContainmentSelection:U=!0,toolbarButtons:mt}=Wt,Ot=Array.isArray(tt)?tt.filter(Boolean):tt?[tt]:[],bt=t=>{if(!t||!Ot.length)return!1;for(const e of Ot)try{if(t instanceof Element&&t.matches(e))return!0}catch{}return!1};if(!B)throw new Error("container is required");let xt=0,vt=0,W=!1,M=null,wt=!1,P=new Set,V=null,Et="replace",a=[],st=[],I=[],Y=[];const te=()=>`hsl(${Math.floor(Math.random()*360)}, 70%, 55%)`,St=()=>{if(ht&&typeof ht=="string")return ht;if(Zt){if(Array.isArray(nt)&&nt.length>0){const t=Math.floor(Math.random()*nt.length);return nt[t]}return te()}return"rgba(255, 165, 0, 0.9)"};let k=null;const K=[],Ct=[];let T=null;const zt=t=>{if(!t.length)return null;const e=new Set(t);for(let r=0;r<a.length;r++){const i=a[r]||[];if(i.length!==e.size)continue;let c=!0;const o=new Set(i);if(o.size!==e.size&&(c=!1),c){for(const n of e)if(!o.has(n)){c=!1;break}}if(c)return r}return null};let Gt=null;const Bt=t=>{const e=!!I[t],r=a[t]||[];for(const i of r)i.style.visibility=e?"hidden":""},lt=(t,e)=>t<0||t>=a.length?!1:(I[t]=e,Bt(t),!0);let _=null;const rt=t=>{ot&&(_&&_!==t&&_.classList.remove(At),t&&_!==t&&t.classList.add(At),_=t)},ee=()=>{const t=document.createElement("div");return t.style.position="fixed",t.style.left="0px",t.style.top="0px",t.style.width="0px",t.style.height="0px",t.style.outline="1px dashed #268aff",t.style.background="rgba(38,138,255,0.12)",t.style.pointerEvents="none",t.style.zIndex="2147483647",t.style.boxSizing="border-box",document.body.appendChild(t),t},it=(t,e)=>t.left<e.right&&t.right>e.left&&t.top<e.bottom&&t.bottom>e.top,ne=(t,e)=>t.left<=e.left&&t.right>=e.right&&t.top<=e.top&&t.bottom>=e.bottom,oe=(t,e)=>{const r=Math.max(t.left,e.left),i=Math.min(t.right,e.right),c=Math.max(t.top,e.top),o=Math.min(t.bottom,e.bottom),n=Math.max(0,i-r),s=Math.max(0,o-c),y=n*s,d=Math.max(1,e.width*e.height);return y/d},se=(t,e)=>{const r=Math.max(t.left,e.left),i=Math.min(t.right,e.right),c=Math.max(t.top,e.top),o=Math.min(t.bottom,e.bottom),n=Math.max(0,i-r),s=Math.max(0,o-c),y=n*s,d=Math.max(1,t.width*t.height),u=Math.max(1,e.width*e.height),h=d+u-y;return y/h},Ft=(t,e)=>_t==="iou"?se(t,e):oe(t,e),qt=(t,e,r,i)=>{const c=Math.min(t,r),o=Math.min(e,i),n=Math.abs(r-t),s=Math.abs(i-e);return{left:c,top:o,width:n,height:s}},Mt=t=>{const e=t.map(n=>n.getBoundingClientRect()).filter(n=>n.width>0&&n.height>0);if(!e.length)return null;const r=Math.min(...e.map(n=>n.left)),i=Math.min(...e.map(n=>n.top)),c=Math.max(...e.map(n=>n.right)),o=Math.max(...e.map(n=>n.bottom));return{left:r,top:i,width:c-r,height:o-i}},J=()=>{st.forEach(t=>t.remove()),st=[]},N=()=>{if(J(),!q)return;const t=[],e=(r,i)=>r.left<i.right&&r.right>i.left&&r.top<i.bottom&&r.bottom>i.top;a.forEach((r,i)=>{const c=Mt(r);if(!c)return;const o=Y[i]||"rgba(255, 165, 0, 0.9)",n=document.createElement("div");n.style.position="fixed",n.style.pointerEvents="none",n.style.zIndex="2147483646",n.style.left=`${c.left}px`,n.style.top=`${c.top}px`,n.style.width=`${c.width}px`,n.style.height=`${c.height}px`,n.style.boxSizing="border-box",n.style.outline=`1px solid ${o}`,n.style.background="transparent",document.body.appendChild(n);const s=document.createElement("div");s.style.position="absolute",s.style.display="inline-flex",s.style.alignItems="center",s.style.gap="6px",s.style.minWidth="max-content",s.style.padding="2px 6px",s.style.fontSize="12px",s.style.lineHeight="16px",s.style.color="#fff",s.style.background=o,s.style.borderRadius="4px",s.style.pointerEvents="auto";const y=document.createElement("span");y.textContent=`组 ${i+1}`;const d=document.createElement("button");d.textContent=I[i]?"显示":"隐藏",d.style.background="rgba(0,0,0,0.15)",d.style.border="none",d.style.color="#fff",d.style.padding="2px 6px",d.style.borderRadius="3px",d.style.cursor="pointer",d.onclick=b=>{b.stopPropagation(),lt(i,!I[i]),N(),O()};const u=document.createElement("button");u.textContent="取消组",u.style.background="rgba(0,0,0,0.15)",u.style.border="none",u.style.color="#fff",u.style.padding="2px 6px",u.style.borderRadius="3px",u.style.cursor="pointer",u.onclick=b=>{b.stopPropagation(),lt(i,!1),Pt(i)},s.appendChild(y),s.appendChild(d),s.appendChild(u);const h=b=>{const l=c?new DOMRect(c.left,c.top,c.width,c.height):null;if(!l)return[];const f=[];return a.forEach((w,p)=>{if(p===b)return;const v=Mt(w);if(!v)return;const S=new DOMRect(v.left,v.top,v.width,v.height);it(l,S)&&f.push(p)}),f};if((()=>{if(k!==i)return;const b=h(i);if(b.length===0)return;const l=document.createElement("button");l.textContent="合并",l.style.background="rgba(0,0,0,0.15)",l.style.border="none",l.style.color="#fff",l.style.padding="2px 6px",l.style.borderRadius="3px",l.style.cursor="pointer";const f=()=>{const w=s.querySelector(".merge-panel");w&&w.remove();const p=document.createElement("div");p.className="merge-panel",p.style.position="absolute",p.style.left="0",p.style.top="22px",p.style.minWidth="160px",p.style.padding="8px",p.style.background="#fff",p.style.color="#333",p.style.border="1px solid rgba(0,0,0,0.15)",p.style.borderRadius="6px",p.style.boxShadow="0 4px 12px rgba(0,0,0,0.15)",p.style.pointerEvents="auto",p.style.zIndex="2147483647";const v=document.createElement("div");v.textContent="选择要合并的组",v.style.fontSize="12px",v.style.marginBottom="6px",p.appendChild(v);const S=document.createElement("div");S.style.maxHeight="200px",S.style.overflow="auto";const L=[];b.forEach(z=>{const R=document.createElement("label");R.style.display="flex",R.style.alignItems="center",R.style.gap="6px",R.style.fontSize="12px",R.style.margin="4px 0";const F=document.createElement("input");F.type="checkbox",F.checked=!0,F.value=String(z);const Z=document.createElement("span");Z.textContent=`组 ${z+1}`,R.appendChild(F),R.appendChild(Z),S.appendChild(R),L.push(F)}),p.appendChild(S);const G=document.createElement("div");G.style.display="flex",G.style.gap="8px",G.style.marginTop="8px";const E=document.createElement("button");E.textContent="确认",E.style.padding="2px 8px",E.style.cursor="pointer";const $=document.createElement("button");$.textContent="取消",$.style.padding="2px 8px",$.style.cursor="pointer",G.appendChild(E),G.appendChild($),p.appendChild(G),$.onclick=z=>{z.stopPropagation(),p.remove()},E.onclick=z=>{z.stopPropagation();const R=L.filter(C=>C.checked).map(C=>parseInt(C.value,10)).filter(C=>!Number.isNaN(C));if(R.length===0){p.remove();return}const F=new Set;(a[i]||[]).forEach(C=>F.add(C)),R.forEach(C=>{(a[C]||[]).forEach(ae=>F.add(ae))}),a[i]=Array.from(F);const ce=[...R].sort((C,ft)=>ft-C);let kt=i;ce.forEach(C=>{C<0||C>=a.length||C===i||(lt(C,!1),a.splice(C,1),I.splice(C,1),Y.splice(C,1),k!==null&&(k===C?k=null:k>C&&k--),C<kt&&kt--)}),k=kt;const Vt=new Set;a.forEach(C=>C.forEach(ft=>Vt.add(ft))),A(Vt),N(),p.remove(),O()},s.appendChild(p)};l.onclick=w=>{w.stopPropagation(),f()},s.appendChild(l)})(),n.appendChild(s),mt&&mt.length){const b=l=>{const f=document.createElement("button"),w={label:l.label||"按钮",title:l.title||""},p=()=>{f.textContent=w.label||"",f.title=w.title||""};p(),f.style.background="rgba(0,0,0,0.15)",f.style.border="none",f.style.color="#fff",f.style.padding="2px 6px",f.style.borderRadius="3px",f.style.cursor="pointer",l.className&&(f.className+=(f.className?" ":"")+l.className),f.onclick=v=>{var G;v.stopPropagation();const S={index:i,group:a[i]||[],controller:Gt,getSnapshot:()=>at(),refresh:()=>{N(),O()},mouseX:v.clientX,mouseY:v.clientY,anchorRect:s.getBoundingClientRect(),anchorEl:s,overlayEl:n,label:w.label,title:w.title,buttonEl:f},L=E=>{Object.defineProperty(S,E,{configurable:!0,get:()=>w[E],set:$=>{const z=$??"";w[E]!==z&&(w[E]=z,p())}})};L("label"),L("title");try{(G=l.onClick)==null||G.call(l,S)}catch{}},s.appendChild(f)};mt.forEach(b)}(()=>{const b=["tl","tr","bl","br"],l=s.style.visibility;s.style.visibility="hidden";const f=28,w=6;t:for(let p=0;p<b.length;p++)for(let v=0;v<6;v++){s.style.left="",s.style.right="",s.style.top="",s.style.bottom="";const S=s.offsetHeight||22;b[p]==="tl"?(s.style.left="0",s.style.top=`${-S-w+v*f}px`):b[p]==="tr"?(s.style.right="0",s.style.top=`${-S-w+v*f}px`):b[p]==="bl"?(s.style.left="0",s.style.top=`${c.height+w+v*f}px`):(s.style.right="0",s.style.top=`${c.height+w+v*f}px`);const L=s.getBoundingClientRect(),G={left:L.left,top:L.top,right:L.right,bottom:L.bottom};let E=!1;for(const $ of t)if(e(G,$)){E=!0;break}if(!E){t.push(G);break t}}s.style.visibility=l})(),s.addEventListener("mouseenter",()=>{try{st.forEach(b=>b.style.zIndex="2147483646"),n.style.zIndex="2147483647"}catch{}});const x=b=>{const l=document.createElement("div");l.style.position="absolute",l.style.pointerEvents="auto",l.style.background="transparent",l.style.zIndex="2147483647";const f=8;b==="top"?(l.style.cursor="ns-resize",l.style.left="-4px",l.style.right="-4px",l.style.top=`-${f/2|0}px`,l.style.height=`${f}px`):b==="bottom"?(l.style.cursor="ns-resize",l.style.left="-4px",l.style.right="-4px",l.style.bottom=`-${f/2|0}px`,l.style.height=`${f}px`):b==="left"?(l.style.cursor="ew-resize",l.style.top="-4px",l.style.bottom="-4px",l.style.left=`-${f/2|0}px`,l.style.width=`${f}px`):b==="right"?(l.style.cursor="ew-resize",l.style.top="-4px",l.style.bottom="-4px",l.style.right=`-${f/2|0}px`,l.style.width=`${f}px`):b==="nw"?(l.style.cursor="nwse-resize",l.style.left=`-${f/2|0}px`,l.style.top=`-${f/2|0}px`,l.style.width=`${f}px`,l.style.height=`${f}px`):b==="ne"?(l.style.cursor="nesw-resize",l.style.right=`-${f/2|0}px`,l.style.top=`-${f/2|0}px`,l.style.width=`${f}px`,l.style.height=`${f}px`):b==="sw"?(l.style.cursor="nesw-resize",l.style.left=`-${f/2|0}px`,l.style.bottom=`-${f/2|0}px`,l.style.width=`${f}px`,l.style.height=`${f}px`):b==="se"&&(l.style.cursor="nwse-resize",l.style.right=`-${f/2|0}px`,l.style.bottom=`-${f/2|0}px`,l.style.width=`${f}px`,l.style.height=`${f}px`),l.onmousedown=w=>{w.preventDefault(),w.stopPropagation();const p={left:parseFloat(n.style.left||"0"),top:parseFloat(n.style.top||"0"),width:parseFloat(n.style.width||"0"),height:parseFloat(n.style.height||"0")};T={idx:i,side:b,startX:w.clientX,startY:w.clientY,startRect:p,overlay:n},document.addEventListener("mousemove",$t),document.addEventListener("mouseup",le,{once:!0})},n.appendChild(l)};x("top"),x("right"),x("bottom"),x("left"),x("nw"),x("ne"),x("sw"),x("se"),Rt&&n.classList.add(Rt),st.push(n)})},$t=t=>{if(!T)return;const{idx:e,side:r,startX:i,startY:c,startRect:o,overlay:n}=T,s=t.clientX-i,y=t.clientY-c;let d=o.left,u=o.top,h=o.width,g=o.height;const m=4;r==="left"||r==="nw"||r==="sw"?(d=o.left+s,h=o.width-s,h<m&&(d=o.left+(o.width-m),h=m)):(r==="right"||r==="ne"||r==="se")&&(h=o.width+s,h<m&&(h=m)),r==="top"||r==="nw"||r==="ne"?(u=o.top+y,g=o.height-y,g<m&&(u=o.top+(o.height-m),g=m)):(r==="bottom"||r==="sw"||r==="se")&&(g=o.height+y,g<m&&(g=m)),n.style.left=`${d}px`,n.style.top=`${u}px`,n.style.width=`${h}px`,n.style.height=`${g}px`;const x=Q(d,u,h,g),b=new Set(a[e]||[]),l=new Set;a.forEach((E,$)=>{$!==e&&E.forEach(z=>l.add(z))});const f=new Set(x);let w=!1,p=!1;for(let E=0;E<a.length;E++){if(E===e)continue;const $=new Set(a[E]||[]);let z=0;for(const R of f)$.has(R)&&z++;if(z!==0&&!(z===$.size&&z===f.size))if(z===$.size)p=!0;else if(z===f.size)p=!0;else{w=!0;break}}const v=x.filter(E=>!b.has(E)).length,S=!j&&(w||!U&&p),L=!H&&v>0;if(S||L){n.style.outline="1px dashed #ff4d4f",n.style.background="rgba(255,77,79,0.06)";const E=new Set;a.forEach(($,z)=>{(z===e?a[e]||[]:$).forEach(F=>E.add(F))}),A(E)}else{const E=Y[e]||"rgba(255, 165, 0, 0.9)";n.style.outline=`1px solid ${E}`,n.style.background="transparent";const $=new Set;a.forEach((z,R)=>{(R===e?x:z).forEach(Z=>$.add(Z))}),A($)}},le=t=>{if(!T)return;const{idx:e,overlay:r,startRect:i}=T,c=parseFloat(r.style.left||"0"),o=parseFloat(r.style.top||"0"),n=parseFloat(r.style.width||"0"),s=parseFloat(r.style.height||"0"),y=Q(c,o,n,s),d=new Set(a[e]||[]),u=new Set;a.forEach((p,v)=>{v!==e&&p.forEach(S=>u.add(S))});const h=new Set(y);let g=!1,m=!1;for(let p=0;p<a.length;p++){if(p===e)continue;const v=new Set(a[p]||[]);let S=0;for(const L of h)v.has(L)&&S++;if(S!==0&&!(S===v.size&&S===h.size))if(S===v.size||S===h.size)m=!0;else{g=!0;break}}const x=y.filter(p=>!d.has(p)).length,b=!j&&(g||!U&&m),l=!H&&x>0;if(b||l){const p=new Set;a.forEach(v=>v.forEach(S=>p.add(S))),A(p),N(),T=null,document.removeEventListener("mousemove",$t),O();return}a[e]=y;const w=new Set;a.forEach(p=>p.forEach(v=>w.add(v))),A(w),N(),T=null,document.removeEventListener("mousemove",$t),O()},Pt=t=>{if(t<0||t>=a.length)return!1;const e=a[t];e&&e.forEach(i=>i.style.visibility=""),a.splice(t,1),I.splice(t,1),Y.splice(t,1),k!==null&&(k===t?k=null:k>t&&k--),J(),N();const r=new Set;return a.forEach(i=>i.forEach(c=>r.add(c))),A(r),O(),!0},re=t=>{if(!q||!Array.isArray(t)||t.length===0)return!1;const e=Array.from(new Set(t)).filter(u=>{var h;try{return!!u&&B.contains(u)&&!bt(u)&&((h=u.matches)==null?void 0:h.call(u,ut))}catch{return!1}});if(e.length===0||zt(e)!==null)return!1;const i=new Set(e);let c=!1,o=!1;for(const u of a){const h=new Set(u);let g=0;for(const m of i)h.has(m)&&g++;if(g!==0&&!(g===h.size&&g===i.size))if(g===h.size||g===i.size)o=!0;else{c=!0;break}}const n=new Set(P),s=!j&&(c||!U&&o),y=!H&&n.size>0&&e.length>0;if(s||y)return!1;a.push(e),I.push(!1),Y.push(St()),k=a.length-1;const d=new Set;return a.forEach(u=>u.forEach(h=>d.add(h))),A(d),N(),O(),!0},ie=t=>{if(q)return"add";const e=It?yt??"add":"replace";return It?yt==="auto"?t.shiftKey?"add":t.altKey?"subtract":t.metaKey||t.ctrlKey?"toggle":"add":yt??e:"replace"},A=t=>{for(const e of Array.from(P))t.has(e)||e.classList.remove(et);for(const e of Array.from(t))P.has(e)||e.classList.add(et);P=t,dt&&dt(q?{type:"groups",groups:a.slice(),flat:Array.from(P)}:{type:"single",selected:Array.from(P)})},Yt=(t,e,r)=>{if(r==="replace")return new Set(e);const i=new Set(t);if(r==="add")for(const c of e)i.add(c);else if(r==="subtract")for(const c of e)i.delete(c);else if(r==="toggle")for(const c of e)i.has(c)?i.delete(c):i.add(c);return i},Dt=t=>{if(t.button!==0)return;const e=t.target;!B.contains(e)&&e!==document.body||(xt=t.clientX,vt=t.clientY,W=!0,M=ee(),Et=ie(t),V=new Set(P),t.preventDefault())},Tt=t=>{var g;if(!W&&ot){const m=t.target,x=(g=m==null?void 0:m.closest)==null?void 0:g.call(m,ut);x&&B.contains(x)&&!bt(x)?rt(x):rt(null)}if(!W||!M)return;const{left:e,top:r,width:i,height:c}=qt(xt,vt,t.clientX,t.clientY);M.style.left=`${e}px`,M.style.top=`${r}px`,M.style.width=`${i}px`,M.style.height=`${c}px`;const o=Q(e,r,i,c),n=V??new Set,s=new Set(o);let y=0;for(const m of s)n.has(m)&&y++;let d="disjoint";y===0?d="disjoint":y===s.size&&y===n.size?d="equal":y===s.size||y===n.size?d="containment":d="partial";const u=!j&&(d==="partial"||!U&&d==="containment"),h=!H&&n.size>0&&o.length>0;if(wt=u||h,M&&(wt?(M.style.outline="1px dashed #ff4d4f",M.style.background="rgba(255,77,79,0.12)"):(M.style.outline="1px dashed #268aff",M.style.background="rgba(38,138,255,0.12)")),wt)A(n);else{const m=Yt(n,o,Et);A(m)}},Xt=t=>{if(!W)return;W=!1,M&&M.parentNode&&M.parentNode.removeChild(M),M=null;const{left:e,top:r,width:i,height:c}=qt(xt,vt,t.clientX,t.clientY),o=Q(e,r,i,c),n=V??new Set,s=new Set(o);let y=0;for(const x of s)n.has(x)&&y++;let d="disjoint";y===0?d="disjoint":y===s.size&&y===n.size?d="equal":y===s.size||y===n.size?d="containment":d="partial";const u=!j&&(d==="partial"||!U&&d==="containment"),h=!H&&n.size>0&&o.length>0;if(u||h){A(n),V=null,O();return}const m=Yt(n,o,Et);if(A(m),q&&o.length>0){const x=zt(o);if(x!==null){try{console.warn(`重复编组被阻止:与已存在的第${x+1}组元素完全一致`)}catch{}V=null,O();return}a.push(o),k=a.length-1,I.push(!1),Y.push(St());const b=new Set;a.forEach(l=>l.forEach(f=>b.add(f))),A(b),N()}V=null,O()},jt=t=>{var m;if(!gt||!q)return;const e=t.target;if(!e)return;let r=e;if(Nt&&(r=((m=e.closest)==null?void 0:m.call(e,Nt))||null),!r||!B.contains(r))return;const i=r.getBoundingClientRect(),c=Q(i.left,i.top,i.width,i.height),o=new Set(P),n=new Set(c);let s=0;for(const x of n)o.has(x)&&s++;let y="disjoint";s===0?y="disjoint":s===n.size&&s===o.size?y="equal":s===n.size||s===o.size?y="containment":y="partial";const d=!j&&(y==="partial"||!U&&y==="containment"),u=!H&&o.size>0&&c.length>0;if(c.length===0||d||u){O();return}const h=zt(c);if(h!==null){try{console.warn(`重复编组被阻止:与已存在的第${h+1}组元素完全一致`)}catch{}O();return}a.push(c),k=a.length-1,I.push(!1),Y.push(St());const g=new Set;a.forEach(x=>x.forEach(b=>g.add(b))),A(g),N(),O()},Ht=()=>rt(null);function Q(t,e,r,i){if(r===0||i===0)return[];const c=B.getBoundingClientRect(),o=new DOMRect(t,e,r,i);if(!it(o,c))return[];const n=Array.from(B.querySelectorAll(ut));let s=[];const y=new Map;for(const u of n){if(bt(u))continue;const h=u.getBoundingClientRect();if(!it(h,c))continue;let g=!1;if(pt==="contains")g=ne(o,h);else if(pt==="center"){const m=h.left+h.width/2,x=h.top+h.height/2;g=m>=o.left&&m<=o.right&&x>=o.top&&x<=o.bottom}else it(o,h)&&(g=Ft(o,h)>=Math.max(0,Math.min(1,Kt)));if(g){const m=pt==="contains"?1:Ft(o,h);y.set(u,m),s.push(u)}}const d=Qt??(Jt?"leaf":"none");if(d!=="none"&&s.length>1){if(d==="leaf")s=s.filter(u=>!s.some(h=>h!==u&&u.contains(h)));else if(d==="best"){const u=[...s].sort((g,m)=>(y.get(m)||0)-(y.get(g)||0)),h=[];for(const g of u)h.find(x=>x.contains(g)||g.contains(x))||h.push(g);s=h}}return s}document.addEventListener("mousedown",Dt,!0),document.addEventListener("mousemove",Tt),document.addEventListener("mouseup",Xt),ot&&B.addEventListener("mouseleave",Ht),q&&gt&&B.addEventListener("dblclick",jt);const ct=()=>N();q&&(window.addEventListener("scroll",ct,!0),window.addEventListener("resize",ct));const at=()=>{if(q){const t=a.map(o=>Mt(o)),e=Array(a.length).fill(null),r=t.map(o=>o?Math.max(0,o.width*o.height):Number.POSITIVE_INFINITY);for(let o=0;o<a.length;o++){const n=t[o];if(!n)continue;let s=null,y=Number.POSITIVE_INFINITY;for(let d=0;d<a.length;d++){if(o===d)continue;const u=t[d];if(!u)continue;if(u.left<=n.left&&u.top<=n.top&&u.left+u.width>=n.left+n.width&&u.top+u.height>=n.top+n.height){const g=Number(r[d]);g<y&&(y=g,s=d)}}e[o]=s}const i=Array.from({length:a.length},()=>[]);for(let o=0;o<a.length;o++){const n=e[o];n!=null&&i[n]&&i[n].push(o)}const c=[];for(let o=0;o<a.length;o++)(e[o]===null||e[o]===void 0)&&c.push(o);return{type:"groups",groups:a.map(o=>o.slice()),flat:Array.from(P),hidden:I.slice(),groupRects:t,groupNesting:{parents:e,children:i,roots:c}}}return{type:"single",selected:Array.from(P)}},O=()=>{const t=at();if(Lt)try{Lt(t)}catch{}for(const r of K)try{r(t)}catch{}const e=Ct.splice(0);for(const r of e)try{r(t)}catch{}},Ut={destroy(){document.removeEventListener("mousedown",Dt),document.removeEventListener("mousemove",Tt),document.removeEventListener("mouseup",Xt),M&&M.parentNode&&M.parentNode.removeChild(M),M=null,B.querySelectorAll(`.${et}`).forEach(e=>e.classList.remove(et)),ot&&(B.removeEventListener("mouseleave",Ht),rt(null)),q&&(window.removeEventListener("scroll",ct,!0),window.removeEventListener("resize",ct)),q&&gt&&B.removeEventListener("dblclick",jt),J(),a.forEach(e=>e.forEach(r=>r.style.visibility="")),a=[],I=[],Y=[],k=null,P.clear(),K.splice(0),Ct.splice(0)},getGroups(){return a.slice()},clearGroups(){a.forEach(e=>e.forEach(r=>r.style.visibility="")),a=[],I=[],Y=[],k=null,J(),A(new Set)},removeGroup(t){return Pt(t)},addGroup(t){return re(t)},setGroupVisibility(t,e){return lt(t,e)},toggleGroupVisibility(t){return t<0||t>=a.length?!1:(I[t]=!I[t],Bt(t),N(),!0)},getSelectionResult(){return at()},refresh(){N()},hideOverlays(){J()},showAndRefreshOverlays(){N()},getGroupNesting(){const t=at();return t.type==="groups"?t.groupNesting:null},onSelectionEnd(t){return K.push(t),()=>{const e=K.indexOf(t);e>=0&&K.splice(e,1)}},waitForSelectionEnd(){return new Promise(t=>{Ct.push(t)})}};return Gt=Ut,Ut}D.default=X,D.marqueeSelection=X,Object.defineProperties(D,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
2
2
  //# sourceMappingURL=marquee-selection.umd.js.map