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