marquee-selection 0.0.14 → 0.0.16

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(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"}})});
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="999999",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="999990",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",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="999999";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"};l.addEventListener("mouseenter",()=>{x();try{at.forEach(v=>v.style.zIndex="999990"),n.style.zIndex="999999"}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="999999";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