marquee-selection 0.0.12 → 0.0.14

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