marquee-selection 0.0.11
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/README.html +442 -0
- package/README.md +204 -0
- package/dist/index.d.ts +215 -0
- package/dist/infinite-canvas.es.js +475 -0
- package/dist/infinite-canvas.es.js.map +1 -0
- package/dist/infinite-canvas.umd.js +2 -0
- package/dist/infinite-canvas.umd.js.map +1 -0
- package/dist/marquee-selection.es.js +672 -0
- package/dist/marquee-selection.es.js.map +1 -0
- package/dist/marquee-selection.umd.js +2 -0
- package/dist/marquee-selection.umd.js.map +1 -0
- package/index.html +740 -0
- package/package.json +49 -0
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
function ce(jt) {
|
|
2
|
+
const {
|
|
3
|
+
container: O,
|
|
4
|
+
selectable: at = "img",
|
|
5
|
+
exclude: Q,
|
|
6
|
+
selectionMode: ft = "intersects",
|
|
7
|
+
minOverlapRatio: Vt = 0,
|
|
8
|
+
overlapMetric: Wt = "element",
|
|
9
|
+
selectedClass: Z = "selected",
|
|
10
|
+
onChange: pt,
|
|
11
|
+
preventAncestorSelection: Kt = !0,
|
|
12
|
+
conflictStrategy: _t,
|
|
13
|
+
groupMode: B = !1,
|
|
14
|
+
groupOverlayClass: Mt,
|
|
15
|
+
groupColor: ut,
|
|
16
|
+
groupRandomColor: Jt = !1,
|
|
17
|
+
groupColorPalette: tt,
|
|
18
|
+
multi: kt = !1,
|
|
19
|
+
combineMode: ht,
|
|
20
|
+
hoverHighlight: et = !1,
|
|
21
|
+
hoverClass: Rt = "hovered",
|
|
22
|
+
onSelectionEnd: It,
|
|
23
|
+
quickGroupOnDblClick: dt = !1,
|
|
24
|
+
quickGroupSelector: At,
|
|
25
|
+
allowIntersectionSelection: X = !0,
|
|
26
|
+
allowUnionSelection: H = !0,
|
|
27
|
+
allowContainmentSelection: T = !0,
|
|
28
|
+
toolbarButtons: yt
|
|
29
|
+
} = jt, Lt = Array.isArray(Q) ? Q.filter(Boolean) : Q ? [Q] : [], gt = (t) => {
|
|
30
|
+
if (!t || !Lt.length) return !1;
|
|
31
|
+
for (const e of Lt)
|
|
32
|
+
try {
|
|
33
|
+
if (t instanceof Element && t.matches(e)) return !0;
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
return !1;
|
|
37
|
+
};
|
|
38
|
+
if (!O) throw new Error("container is required");
|
|
39
|
+
let mt = 0, bt = 0, j = !1, z = null, xt = !1, F = /* @__PURE__ */ new Set(), U = null, vt = "replace", a = [], nt = [], I = [], Y = [];
|
|
40
|
+
const Qt = () => `hsl(${Math.floor(Math.random() * 360)}, 70%, 55%)`, wt = () => {
|
|
41
|
+
if (ut && typeof ut == "string")
|
|
42
|
+
return ut;
|
|
43
|
+
if (Jt) {
|
|
44
|
+
if (Array.isArray(tt) && tt.length > 0) {
|
|
45
|
+
const t = Math.floor(Math.random() * tt.length);
|
|
46
|
+
return tt[t];
|
|
47
|
+
}
|
|
48
|
+
return Qt();
|
|
49
|
+
}
|
|
50
|
+
return "rgba(255, 165, 0, 0.9)";
|
|
51
|
+
};
|
|
52
|
+
let k = null;
|
|
53
|
+
const V = [], Et = [];
|
|
54
|
+
let D = null;
|
|
55
|
+
const St = (t) => {
|
|
56
|
+
if (!t.length) return null;
|
|
57
|
+
const e = new Set(t);
|
|
58
|
+
for (let r = 0; r < a.length; r++) {
|
|
59
|
+
const i = a[r] || [];
|
|
60
|
+
if (i.length !== e.size) continue;
|
|
61
|
+
let c = !0;
|
|
62
|
+
const o = new Set(i);
|
|
63
|
+
if (o.size !== e.size && (c = !1), c) {
|
|
64
|
+
for (const n of e)
|
|
65
|
+
if (!o.has(n)) {
|
|
66
|
+
c = !1;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (c) return r;
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
};
|
|
74
|
+
let Nt = null;
|
|
75
|
+
const Ot = (t) => {
|
|
76
|
+
const e = !!I[t], r = a[t] || [];
|
|
77
|
+
for (const i of r)
|
|
78
|
+
i.style.visibility = e ? "hidden" : "";
|
|
79
|
+
}, ot = (t, e) => t < 0 || t >= a.length ? !1 : (I[t] = e, Ot(t), !0);
|
|
80
|
+
let W = null;
|
|
81
|
+
const st = (t) => {
|
|
82
|
+
et && (W && W !== t && W.classList.remove(Rt), t && W !== t && t.classList.add(Rt), W = t);
|
|
83
|
+
}, Zt = () => {
|
|
84
|
+
const t = document.createElement("div");
|
|
85
|
+
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;
|
|
86
|
+
}, lt = (t, e) => t.left < e.right && t.right > e.left && t.top < e.bottom && t.bottom > e.top, te = (t, e) => t.left <= e.left && t.right >= e.right && t.top <= e.top && t.bottom >= e.bottom, ee = (t, e) => {
|
|
87
|
+
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, h = Math.max(1, e.width * e.height);
|
|
88
|
+
return y / h;
|
|
89
|
+
}, ne = (t, e) => {
|
|
90
|
+
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, h = Math.max(1, t.width * t.height), p = Math.max(1, e.width * e.height), d = h + p - y;
|
|
91
|
+
return y / d;
|
|
92
|
+
}, Gt = (t, e) => Wt === "iou" ? ne(t, e) : ee(t, e), Bt = (t, e, r, i) => {
|
|
93
|
+
const c = Math.min(t, r), o = Math.min(e, i), n = Math.abs(r - t), s = Math.abs(i - e);
|
|
94
|
+
return { left: c, top: o, width: n, height: s };
|
|
95
|
+
}, Ct = (t) => {
|
|
96
|
+
const e = t.map((n) => n.getBoundingClientRect()).filter((n) => n.width > 0 && n.height > 0);
|
|
97
|
+
if (!e.length) return null;
|
|
98
|
+
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));
|
|
99
|
+
return { left: r, top: i, width: c - r, height: o - i };
|
|
100
|
+
}, K = () => {
|
|
101
|
+
nt.forEach((t) => t.remove()), nt = [];
|
|
102
|
+
}, L = () => {
|
|
103
|
+
if (K(), !B) return;
|
|
104
|
+
const t = [], e = (r, i) => r.left < i.right && r.right > i.left && r.top < i.bottom && r.bottom > i.top;
|
|
105
|
+
a.forEach((r, i) => {
|
|
106
|
+
const c = Ct(r);
|
|
107
|
+
if (!c) return;
|
|
108
|
+
const o = Y[i] || "rgba(255, 165, 0, 0.9)", n = document.createElement("div");
|
|
109
|
+
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);
|
|
110
|
+
const s = document.createElement("div");
|
|
111
|
+
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";
|
|
112
|
+
const y = document.createElement("span");
|
|
113
|
+
y.textContent = `组 ${i + 1}`;
|
|
114
|
+
const h = document.createElement("button");
|
|
115
|
+
h.textContent = I[i] ? "显示" : "隐藏", h.style.background = "rgba(0,0,0,0.15)", h.style.border = "none", h.style.color = "#fff", h.style.padding = "2px 6px", h.style.borderRadius = "3px", h.style.cursor = "pointer", h.onclick = (b) => {
|
|
116
|
+
b.stopPropagation(), ot(i, !I[i]), L(), N();
|
|
117
|
+
};
|
|
118
|
+
const p = document.createElement("button");
|
|
119
|
+
p.textContent = "取消组", 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 = (b) => {
|
|
120
|
+
b.stopPropagation(), ot(i, !1), Ft(i);
|
|
121
|
+
}, s.appendChild(y), s.appendChild(h), s.appendChild(p);
|
|
122
|
+
const d = (b) => {
|
|
123
|
+
const l = c ? new DOMRect(c.left, c.top, c.width, c.height) : null;
|
|
124
|
+
if (!l) return [];
|
|
125
|
+
const f = [];
|
|
126
|
+
return a.forEach((w, u) => {
|
|
127
|
+
if (u === b) return;
|
|
128
|
+
const v = Ct(w);
|
|
129
|
+
if (!v) return;
|
|
130
|
+
const S = new DOMRect(v.left, v.top, v.width, v.height);
|
|
131
|
+
lt(l, S) && f.push(u);
|
|
132
|
+
}), f;
|
|
133
|
+
};
|
|
134
|
+
if ((() => {
|
|
135
|
+
if (k !== i) return;
|
|
136
|
+
const b = d(i);
|
|
137
|
+
if (b.length === 0) return;
|
|
138
|
+
const l = document.createElement("button");
|
|
139
|
+
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";
|
|
140
|
+
const f = () => {
|
|
141
|
+
const w = s.querySelector(".merge-panel");
|
|
142
|
+
w && w.remove();
|
|
143
|
+
const u = document.createElement("div");
|
|
144
|
+
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";
|
|
145
|
+
const v = document.createElement("div");
|
|
146
|
+
v.textContent = "选择要合并的组", v.style.fontSize = "12px", v.style.marginBottom = "6px", u.appendChild(v);
|
|
147
|
+
const S = document.createElement("div");
|
|
148
|
+
S.style.maxHeight = "200px", S.style.overflow = "auto";
|
|
149
|
+
const q = [];
|
|
150
|
+
b.forEach(($) => {
|
|
151
|
+
const R = document.createElement("label");
|
|
152
|
+
R.style.display = "flex", R.style.alignItems = "center", R.style.gap = "6px", R.style.fontSize = "12px", R.style.margin = "4px 0";
|
|
153
|
+
const G = document.createElement("input");
|
|
154
|
+
G.type = "checkbox", G.checked = !0, G.value = String($);
|
|
155
|
+
const J = document.createElement("span");
|
|
156
|
+
J.textContent = `组 ${$ + 1}`, R.appendChild(G), R.appendChild(J), S.appendChild(R), q.push(G);
|
|
157
|
+
}), u.appendChild(S);
|
|
158
|
+
const P = document.createElement("div");
|
|
159
|
+
P.style.display = "flex", P.style.gap = "8px", P.style.marginTop = "8px";
|
|
160
|
+
const C = document.createElement("button");
|
|
161
|
+
C.textContent = "确认", C.style.padding = "2px 8px", C.style.cursor = "pointer";
|
|
162
|
+
const M = document.createElement("button");
|
|
163
|
+
M.textContent = "取消", M.style.padding = "2px 8px", M.style.cursor = "pointer", P.appendChild(C), P.appendChild(M), u.appendChild(P), M.onclick = ($) => {
|
|
164
|
+
$.stopPropagation(), u.remove();
|
|
165
|
+
}, C.onclick = ($) => {
|
|
166
|
+
$.stopPropagation();
|
|
167
|
+
const R = q.filter((E) => E.checked).map((E) => parseInt(E.value, 10)).filter((E) => !Number.isNaN(E));
|
|
168
|
+
if (R.length === 0) {
|
|
169
|
+
u.remove();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const G = /* @__PURE__ */ new Set();
|
|
173
|
+
(a[i] || []).forEach((E) => G.add(E)), R.forEach((E) => {
|
|
174
|
+
(a[E] || []).forEach((ie) => G.add(ie));
|
|
175
|
+
}), a[i] = Array.from(G);
|
|
176
|
+
const re = [...R].sort((E, ct) => ct - E);
|
|
177
|
+
let $t = i;
|
|
178
|
+
re.forEach((E) => {
|
|
179
|
+
E < 0 || E >= a.length || E === i || (ot(E, !1), a.splice(E, 1), I.splice(E, 1), Y.splice(E, 1), k !== null && (k === E ? k = null : k > E && k--), E < $t && $t--);
|
|
180
|
+
}), k = $t;
|
|
181
|
+
const Ut = /* @__PURE__ */ new Set();
|
|
182
|
+
a.forEach((E) => E.forEach((ct) => Ut.add(ct))), A(Ut), L(), u.remove(), N();
|
|
183
|
+
}, s.appendChild(u);
|
|
184
|
+
};
|
|
185
|
+
l.onclick = (w) => {
|
|
186
|
+
w.stopPropagation(), f();
|
|
187
|
+
}, s.appendChild(l);
|
|
188
|
+
})(), n.appendChild(s), yt && yt.length) {
|
|
189
|
+
const b = (l) => {
|
|
190
|
+
const f = document.createElement("button");
|
|
191
|
+
f.textContent = l.label || "按钮", f.title = l.title || "", f.style.background = "rgba(0,0,0,0.15)", f.style.border = "none", f.style.color = "#fff", f.style.padding = "2px 6px", f.style.borderRadius = "3px", f.style.cursor = "pointer", l.className && (f.className += (f.className ? " " : "") + l.className), f.onclick = (w) => {
|
|
192
|
+
var u;
|
|
193
|
+
w.stopPropagation();
|
|
194
|
+
try {
|
|
195
|
+
(u = l.onClick) == null || u.call(l, {
|
|
196
|
+
index: i,
|
|
197
|
+
group: a[i] || [],
|
|
198
|
+
controller: Nt,
|
|
199
|
+
getSnapshot: () => it(),
|
|
200
|
+
refresh: () => {
|
|
201
|
+
L(), N();
|
|
202
|
+
},
|
|
203
|
+
mouseX: w.clientX,
|
|
204
|
+
mouseY: w.clientY,
|
|
205
|
+
anchorRect: s.getBoundingClientRect(),
|
|
206
|
+
anchorEl: s,
|
|
207
|
+
overlayEl: n
|
|
208
|
+
});
|
|
209
|
+
} catch {
|
|
210
|
+
}
|
|
211
|
+
}, s.appendChild(f);
|
|
212
|
+
};
|
|
213
|
+
yt.forEach(b);
|
|
214
|
+
}
|
|
215
|
+
(() => {
|
|
216
|
+
const b = [
|
|
217
|
+
"tl",
|
|
218
|
+
"tr",
|
|
219
|
+
"bl",
|
|
220
|
+
"br"
|
|
221
|
+
], l = s.style.visibility;
|
|
222
|
+
s.style.visibility = "hidden";
|
|
223
|
+
const f = 28, w = 6;
|
|
224
|
+
t: for (let u = 0; u < b.length; u++)
|
|
225
|
+
for (let v = 0; v < 6; v++) {
|
|
226
|
+
s.style.left = "", s.style.right = "", s.style.top = "", s.style.bottom = "";
|
|
227
|
+
const S = s.offsetHeight || 22;
|
|
228
|
+
b[u] === "tl" ? (s.style.left = "0", s.style.top = `${-S - w + v * f}px`) : b[u] === "tr" ? (s.style.right = "0", s.style.top = `${-S - w + v * f}px`) : b[u] === "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`);
|
|
229
|
+
const q = s.getBoundingClientRect(), P = {
|
|
230
|
+
left: q.left,
|
|
231
|
+
top: q.top,
|
|
232
|
+
right: q.right,
|
|
233
|
+
bottom: q.bottom
|
|
234
|
+
};
|
|
235
|
+
let C = !1;
|
|
236
|
+
for (const M of t)
|
|
237
|
+
if (e(P, M)) {
|
|
238
|
+
C = !0;
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
if (!C) {
|
|
242
|
+
t.push(P);
|
|
243
|
+
break t;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
s.style.visibility = l;
|
|
247
|
+
})(), s.addEventListener("mouseenter", () => {
|
|
248
|
+
try {
|
|
249
|
+
nt.forEach((b) => b.style.zIndex = "2147483646"), n.style.zIndex = "2147483647";
|
|
250
|
+
} catch {
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
const x = (b) => {
|
|
254
|
+
const l = document.createElement("div");
|
|
255
|
+
l.style.position = "absolute", l.style.pointerEvents = "auto", l.style.background = "transparent", l.style.zIndex = "2147483647";
|
|
256
|
+
const f = 8;
|
|
257
|
+
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) => {
|
|
258
|
+
w.preventDefault(), w.stopPropagation();
|
|
259
|
+
const u = {
|
|
260
|
+
left: parseFloat(n.style.left || "0"),
|
|
261
|
+
top: parseFloat(n.style.top || "0"),
|
|
262
|
+
width: parseFloat(n.style.width || "0"),
|
|
263
|
+
height: parseFloat(n.style.height || "0")
|
|
264
|
+
};
|
|
265
|
+
D = {
|
|
266
|
+
idx: i,
|
|
267
|
+
side: b,
|
|
268
|
+
startX: w.clientX,
|
|
269
|
+
startY: w.clientY,
|
|
270
|
+
startRect: u,
|
|
271
|
+
overlay: n
|
|
272
|
+
}, document.addEventListener("mousemove", zt), document.addEventListener("mouseup", oe, { once: !0 });
|
|
273
|
+
}, n.appendChild(l);
|
|
274
|
+
};
|
|
275
|
+
x("top"), x("right"), x("bottom"), x("left"), x("nw"), x("ne"), x("sw"), x("se"), Mt && n.classList.add(Mt), nt.push(n);
|
|
276
|
+
});
|
|
277
|
+
}, zt = (t) => {
|
|
278
|
+
if (!D) return;
|
|
279
|
+
const { idx: e, side: r, startX: i, startY: c, startRect: o, overlay: n } = D, s = t.clientX - i, y = t.clientY - c;
|
|
280
|
+
let h = o.left, p = o.top, d = o.width, g = o.height;
|
|
281
|
+
const m = 4;
|
|
282
|
+
r === "left" || r === "nw" || r === "sw" ? (h = o.left + s, d = o.width - s, d < m && (h = o.left + (o.width - m), d = m)) : (r === "right" || r === "ne" || r === "se") && (d = o.width + s, d < m && (d = m)), r === "top" || r === "nw" || r === "ne" ? (p = o.top + y, g = o.height - y, g < m && (p = o.top + (o.height - m), g = m)) : (r === "bottom" || r === "sw" || r === "se") && (g = o.height + y, g < m && (g = m)), n.style.left = `${h}px`, n.style.top = `${p}px`, n.style.width = `${d}px`, n.style.height = `${g}px`;
|
|
283
|
+
const x = _(h, p, d, g), b = new Set(a[e] || []), l = /* @__PURE__ */ new Set();
|
|
284
|
+
a.forEach((C, M) => {
|
|
285
|
+
M !== e && C.forEach(($) => l.add($));
|
|
286
|
+
});
|
|
287
|
+
const f = new Set(x);
|
|
288
|
+
let w = !1, u = !1;
|
|
289
|
+
for (let C = 0; C < a.length; C++) {
|
|
290
|
+
if (C === e) continue;
|
|
291
|
+
const M = new Set(a[C] || []);
|
|
292
|
+
let $ = 0;
|
|
293
|
+
for (const R of f) M.has(R) && $++;
|
|
294
|
+
if ($ !== 0 && !($ === M.size && $ === f.size))
|
|
295
|
+
if ($ === M.size)
|
|
296
|
+
u = !0;
|
|
297
|
+
else if ($ === f.size)
|
|
298
|
+
u = !0;
|
|
299
|
+
else {
|
|
300
|
+
w = !0;
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const v = x.filter((C) => !b.has(C)).length, S = !X && (w || !T && u), q = !H && v > 0;
|
|
305
|
+
if (S || q) {
|
|
306
|
+
n.style.outline = "1px dashed #ff4d4f", n.style.background = "rgba(255,77,79,0.06)";
|
|
307
|
+
const C = /* @__PURE__ */ new Set();
|
|
308
|
+
a.forEach((M, $) => {
|
|
309
|
+
($ === e ? a[e] || [] : M).forEach((G) => C.add(G));
|
|
310
|
+
}), A(C);
|
|
311
|
+
} else {
|
|
312
|
+
const C = Y[e] || "rgba(255, 165, 0, 0.9)";
|
|
313
|
+
n.style.outline = `1px solid ${C}`, n.style.background = "transparent";
|
|
314
|
+
const M = /* @__PURE__ */ new Set();
|
|
315
|
+
a.forEach(($, R) => {
|
|
316
|
+
(R === e ? x : $).forEach((J) => M.add(J));
|
|
317
|
+
}), A(M);
|
|
318
|
+
}
|
|
319
|
+
}, oe = (t) => {
|
|
320
|
+
if (!D) return;
|
|
321
|
+
const { idx: e, overlay: r, startRect: i } = D, 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 = _(c, o, n, s), h = new Set(a[e] || []), p = /* @__PURE__ */ new Set();
|
|
322
|
+
a.forEach((u, v) => {
|
|
323
|
+
v !== e && u.forEach((S) => p.add(S));
|
|
324
|
+
});
|
|
325
|
+
const d = new Set(y);
|
|
326
|
+
let g = !1, m = !1;
|
|
327
|
+
for (let u = 0; u < a.length; u++) {
|
|
328
|
+
if (u === e) continue;
|
|
329
|
+
const v = new Set(a[u] || []);
|
|
330
|
+
let S = 0;
|
|
331
|
+
for (const q of d) v.has(q) && S++;
|
|
332
|
+
if (S !== 0 && !(S === v.size && S === d.size))
|
|
333
|
+
if (S === v.size || S === d.size)
|
|
334
|
+
m = !0;
|
|
335
|
+
else {
|
|
336
|
+
g = !0;
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
const x = y.filter((u) => !h.has(u)).length, b = !X && (g || !T && m), l = !H && x > 0;
|
|
341
|
+
if (b || l) {
|
|
342
|
+
const u = /* @__PURE__ */ new Set();
|
|
343
|
+
a.forEach((v) => v.forEach((S) => u.add(S))), A(u), L(), D = null, document.removeEventListener("mousemove", zt), N();
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
a[e] = y;
|
|
347
|
+
const w = /* @__PURE__ */ new Set();
|
|
348
|
+
a.forEach((u) => u.forEach((v) => w.add(v))), A(w), L(), D = null, document.removeEventListener("mousemove", zt), N();
|
|
349
|
+
}, Ft = (t) => {
|
|
350
|
+
if (t < 0 || t >= a.length) return !1;
|
|
351
|
+
const e = a[t];
|
|
352
|
+
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--), K(), L();
|
|
353
|
+
const r = /* @__PURE__ */ new Set();
|
|
354
|
+
return a.forEach((i) => i.forEach((c) => r.add(c))), A(r), N(), !0;
|
|
355
|
+
}, se = (t) => {
|
|
356
|
+
if (!B || !Array.isArray(t) || t.length === 0) return !1;
|
|
357
|
+
const e = Array.from(new Set(t)).filter((p) => {
|
|
358
|
+
var d;
|
|
359
|
+
try {
|
|
360
|
+
return !!p && O.contains(p) && !gt(p) && ((d = p.matches) == null ? void 0 : d.call(p, at));
|
|
361
|
+
} catch {
|
|
362
|
+
return !1;
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
if (e.length === 0 || St(e) !== null) return !1;
|
|
366
|
+
const i = new Set(e);
|
|
367
|
+
let c = !1, o = !1;
|
|
368
|
+
for (const p of a) {
|
|
369
|
+
const d = new Set(p);
|
|
370
|
+
let g = 0;
|
|
371
|
+
for (const m of i) d.has(m) && g++;
|
|
372
|
+
if (g !== 0 && !(g === d.size && g === i.size))
|
|
373
|
+
if (g === d.size || g === i.size)
|
|
374
|
+
o = !0;
|
|
375
|
+
else {
|
|
376
|
+
c = !0;
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
const n = new Set(F), s = !X && (c || !T && o), y = !H && n.size > 0 && e.length > 0;
|
|
381
|
+
if (s || y) return !1;
|
|
382
|
+
a.push(e), I.push(!1), Y.push(wt()), k = a.length - 1;
|
|
383
|
+
const h = /* @__PURE__ */ new Set();
|
|
384
|
+
return a.forEach((p) => p.forEach((d) => h.add(d))), A(h), L(), N(), !0;
|
|
385
|
+
}, le = (t) => {
|
|
386
|
+
if (B) return "add";
|
|
387
|
+
const e = kt ? ht ?? "add" : "replace";
|
|
388
|
+
return kt ? ht === "auto" ? t.shiftKey ? "add" : t.altKey ? "subtract" : t.metaKey || t.ctrlKey ? "toggle" : "add" : ht ?? e : "replace";
|
|
389
|
+
}, A = (t) => {
|
|
390
|
+
for (const e of Array.from(F))
|
|
391
|
+
t.has(e) || e.classList.remove(Z);
|
|
392
|
+
for (const e of Array.from(t))
|
|
393
|
+
F.has(e) || e.classList.add(Z);
|
|
394
|
+
F = t, pt && pt(B ? {
|
|
395
|
+
type: "groups",
|
|
396
|
+
groups: a.slice(),
|
|
397
|
+
flat: Array.from(F)
|
|
398
|
+
} : { type: "single", selected: Array.from(F) });
|
|
399
|
+
}, qt = (t, e, r) => {
|
|
400
|
+
if (r === "replace") return new Set(e);
|
|
401
|
+
const i = new Set(t);
|
|
402
|
+
if (r === "add")
|
|
403
|
+
for (const c of e) i.add(c);
|
|
404
|
+
else if (r === "subtract")
|
|
405
|
+
for (const c of e) i.delete(c);
|
|
406
|
+
else if (r === "toggle")
|
|
407
|
+
for (const c of e)
|
|
408
|
+
i.has(c) ? i.delete(c) : i.add(c);
|
|
409
|
+
return i;
|
|
410
|
+
}, Pt = (t) => {
|
|
411
|
+
if (t.button !== 0) return;
|
|
412
|
+
const e = t.target;
|
|
413
|
+
!O.contains(e) && e !== document.body || (mt = t.clientX, bt = t.clientY, j = !0, z = Zt(), vt = le(t), U = new Set(F), t.preventDefault());
|
|
414
|
+
}, Yt = (t) => {
|
|
415
|
+
var g;
|
|
416
|
+
if (!j && et) {
|
|
417
|
+
const m = t.target, x = (g = m == null ? void 0 : m.closest) == null ? void 0 : g.call(m, at);
|
|
418
|
+
x && O.contains(x) && !gt(x) ? st(x) : st(null);
|
|
419
|
+
}
|
|
420
|
+
if (!j || !z) return;
|
|
421
|
+
const { left: e, top: r, width: i, height: c } = Bt(
|
|
422
|
+
mt,
|
|
423
|
+
bt,
|
|
424
|
+
t.clientX,
|
|
425
|
+
t.clientY
|
|
426
|
+
);
|
|
427
|
+
z.style.left = `${e}px`, z.style.top = `${r}px`, z.style.width = `${i}px`, z.style.height = `${c}px`;
|
|
428
|
+
const o = _(e, r, i, c), n = U ?? /* @__PURE__ */ new Set(), s = new Set(o);
|
|
429
|
+
let y = 0;
|
|
430
|
+
for (const m of s) n.has(m) && y++;
|
|
431
|
+
let h = "disjoint";
|
|
432
|
+
y === 0 ? h = "disjoint" : y === s.size && y === n.size ? h = "equal" : y === s.size || y === n.size ? h = "containment" : h = "partial";
|
|
433
|
+
const p = !X && (h === "partial" || !T && h === "containment"), d = !H && n.size > 0 && o.length > 0;
|
|
434
|
+
if (xt = p || d, z && (xt ? (z.style.outline = "1px dashed #ff4d4f", z.style.background = "rgba(255,77,79,0.12)") : (z.style.outline = "1px dashed #268aff", z.style.background = "rgba(38,138,255,0.12)")), xt)
|
|
435
|
+
A(n);
|
|
436
|
+
else {
|
|
437
|
+
const m = qt(n, o, vt);
|
|
438
|
+
A(m);
|
|
439
|
+
}
|
|
440
|
+
}, Dt = (t) => {
|
|
441
|
+
if (!j) return;
|
|
442
|
+
j = !1, z && z.parentNode && z.parentNode.removeChild(z), z = null;
|
|
443
|
+
const { left: e, top: r, width: i, height: c } = Bt(
|
|
444
|
+
mt,
|
|
445
|
+
bt,
|
|
446
|
+
t.clientX,
|
|
447
|
+
t.clientY
|
|
448
|
+
), o = _(e, r, i, c), n = U ?? /* @__PURE__ */ new Set(), s = new Set(o);
|
|
449
|
+
let y = 0;
|
|
450
|
+
for (const x of s) n.has(x) && y++;
|
|
451
|
+
let h = "disjoint";
|
|
452
|
+
y === 0 ? h = "disjoint" : y === s.size && y === n.size ? h = "equal" : y === s.size || y === n.size ? h = "containment" : h = "partial";
|
|
453
|
+
const p = !X && (h === "partial" || !T && h === "containment"), d = !H && n.size > 0 && o.length > 0;
|
|
454
|
+
if (p || d) {
|
|
455
|
+
A(n), U = null, N();
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
const m = qt(n, o, vt);
|
|
459
|
+
if (A(m), B && o.length > 0) {
|
|
460
|
+
const x = St(o);
|
|
461
|
+
if (x !== null) {
|
|
462
|
+
try {
|
|
463
|
+
console.warn(`重复编组被阻止:与已存在的第${x + 1}组元素完全一致`);
|
|
464
|
+
} catch {
|
|
465
|
+
}
|
|
466
|
+
U = null, N();
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
a.push(o), k = a.length - 1, I.push(!1), Y.push(wt());
|
|
470
|
+
const b = /* @__PURE__ */ new Set();
|
|
471
|
+
a.forEach((l) => l.forEach((f) => b.add(f))), A(b), L();
|
|
472
|
+
}
|
|
473
|
+
U = null, N();
|
|
474
|
+
}, Xt = (t) => {
|
|
475
|
+
var m;
|
|
476
|
+
if (!dt || !B) return;
|
|
477
|
+
const e = t.target;
|
|
478
|
+
if (!e) return;
|
|
479
|
+
let r = e;
|
|
480
|
+
if (At && (r = ((m = e.closest) == null ? void 0 : m.call(e, At)) || null), !r || !O.contains(r)) return;
|
|
481
|
+
const i = r.getBoundingClientRect(), c = _(i.left, i.top, i.width, i.height), o = new Set(F), n = new Set(c);
|
|
482
|
+
let s = 0;
|
|
483
|
+
for (const x of n) o.has(x) && s++;
|
|
484
|
+
let y = "disjoint";
|
|
485
|
+
s === 0 ? y = "disjoint" : s === n.size && s === o.size ? y = "equal" : s === n.size || s === o.size ? y = "containment" : y = "partial";
|
|
486
|
+
const h = !X && (y === "partial" || !T && y === "containment"), p = !H && o.size > 0 && c.length > 0;
|
|
487
|
+
if (c.length === 0 || h || p) {
|
|
488
|
+
N();
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
const d = St(c);
|
|
492
|
+
if (d !== null) {
|
|
493
|
+
try {
|
|
494
|
+
console.warn(`重复编组被阻止:与已存在的第${d + 1}组元素完全一致`);
|
|
495
|
+
} catch {
|
|
496
|
+
}
|
|
497
|
+
N();
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
a.push(c), k = a.length - 1, I.push(!1), Y.push(wt());
|
|
501
|
+
const g = /* @__PURE__ */ new Set();
|
|
502
|
+
a.forEach((x) => x.forEach((b) => g.add(b))), A(g), L(), N();
|
|
503
|
+
}, Ht = () => st(null);
|
|
504
|
+
function _(t, e, r, i) {
|
|
505
|
+
if (r === 0 || i === 0) return [];
|
|
506
|
+
const c = O.getBoundingClientRect(), o = new DOMRect(t, e, r, i);
|
|
507
|
+
if (!lt(o, c)) return [];
|
|
508
|
+
const n = Array.from(O.querySelectorAll(at));
|
|
509
|
+
let s = [];
|
|
510
|
+
const y = /* @__PURE__ */ new Map();
|
|
511
|
+
for (const p of n) {
|
|
512
|
+
if (gt(p)) continue;
|
|
513
|
+
const d = p.getBoundingClientRect();
|
|
514
|
+
if (!lt(d, c)) continue;
|
|
515
|
+
let g = !1;
|
|
516
|
+
if (ft === "contains")
|
|
517
|
+
g = te(o, d);
|
|
518
|
+
else if (ft === "center") {
|
|
519
|
+
const m = d.left + d.width / 2, x = d.top + d.height / 2;
|
|
520
|
+
g = m >= o.left && m <= o.right && x >= o.top && x <= o.bottom;
|
|
521
|
+
} else
|
|
522
|
+
lt(o, d) && (g = Gt(o, d) >= Math.max(0, Math.min(1, Vt)));
|
|
523
|
+
if (g) {
|
|
524
|
+
const m = ft === "contains" ? 1 : Gt(o, d);
|
|
525
|
+
y.set(p, m), s.push(p);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
const h = _t ?? (Kt ? "leaf" : "none");
|
|
529
|
+
if (h !== "none" && s.length > 1) {
|
|
530
|
+
if (h === "leaf")
|
|
531
|
+
s = s.filter(
|
|
532
|
+
(p) => !s.some(
|
|
533
|
+
(d) => d !== p && p.contains(d)
|
|
534
|
+
)
|
|
535
|
+
);
|
|
536
|
+
else if (h === "best") {
|
|
537
|
+
const p = [...s].sort(
|
|
538
|
+
(g, m) => (y.get(m) || 0) - (y.get(g) || 0)
|
|
539
|
+
), d = [];
|
|
540
|
+
for (const g of p)
|
|
541
|
+
d.find(
|
|
542
|
+
(x) => x.contains(g) || g.contains(x)
|
|
543
|
+
) || d.push(g);
|
|
544
|
+
s = d;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
return s;
|
|
548
|
+
}
|
|
549
|
+
document.addEventListener("mousedown", Pt, !0), document.addEventListener("mousemove", Yt), document.addEventListener("mouseup", Dt), et && O.addEventListener("mouseleave", Ht), B && dt && O.addEventListener("dblclick", Xt);
|
|
550
|
+
const rt = () => L();
|
|
551
|
+
B && (window.addEventListener("scroll", rt, !0), window.addEventListener("resize", rt));
|
|
552
|
+
const it = () => {
|
|
553
|
+
if (B) {
|
|
554
|
+
const t = a.map((o) => Ct(o)), e = Array(a.length).fill(null), r = t.map(
|
|
555
|
+
(o) => o ? Math.max(0, o.width * o.height) : Number.POSITIVE_INFINITY
|
|
556
|
+
);
|
|
557
|
+
for (let o = 0; o < a.length; o++) {
|
|
558
|
+
const n = t[o];
|
|
559
|
+
if (!n) continue;
|
|
560
|
+
let s = null, y = Number.POSITIVE_INFINITY;
|
|
561
|
+
for (let h = 0; h < a.length; h++) {
|
|
562
|
+
if (o === h) continue;
|
|
563
|
+
const p = t[h];
|
|
564
|
+
if (!p) continue;
|
|
565
|
+
if (p.left <= n.left && p.top <= n.top && p.left + p.width >= n.left + n.width && p.top + p.height >= n.top + n.height) {
|
|
566
|
+
const g = Number(r[h]);
|
|
567
|
+
g < y && (y = g, s = h);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
e[o] = s;
|
|
571
|
+
}
|
|
572
|
+
const i = Array.from(
|
|
573
|
+
{ length: a.length },
|
|
574
|
+
() => []
|
|
575
|
+
);
|
|
576
|
+
for (let o = 0; o < a.length; o++) {
|
|
577
|
+
const n = e[o];
|
|
578
|
+
n != null && i[n] && i[n].push(o);
|
|
579
|
+
}
|
|
580
|
+
const c = [];
|
|
581
|
+
for (let o = 0; o < a.length; o++)
|
|
582
|
+
(e[o] === null || e[o] === void 0) && c.push(o);
|
|
583
|
+
return {
|
|
584
|
+
type: "groups",
|
|
585
|
+
groups: a.map((o) => o.slice()),
|
|
586
|
+
flat: Array.from(F),
|
|
587
|
+
hidden: I.slice(),
|
|
588
|
+
groupRects: t,
|
|
589
|
+
groupNesting: { parents: e, children: i, roots: c }
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
return { type: "single", selected: Array.from(F) };
|
|
593
|
+
}, N = () => {
|
|
594
|
+
const t = it();
|
|
595
|
+
if (It)
|
|
596
|
+
try {
|
|
597
|
+
It(t);
|
|
598
|
+
} catch {
|
|
599
|
+
}
|
|
600
|
+
for (const r of V)
|
|
601
|
+
try {
|
|
602
|
+
r(t);
|
|
603
|
+
} catch {
|
|
604
|
+
}
|
|
605
|
+
const e = Et.splice(0);
|
|
606
|
+
for (const r of e)
|
|
607
|
+
try {
|
|
608
|
+
r(t);
|
|
609
|
+
} catch {
|
|
610
|
+
}
|
|
611
|
+
}, Tt = {
|
|
612
|
+
destroy() {
|
|
613
|
+
document.removeEventListener("mousedown", Pt), document.removeEventListener("mousemove", Yt), document.removeEventListener("mouseup", Dt), z && z.parentNode && z.parentNode.removeChild(z), z = null, O.querySelectorAll(`.${Z}`).forEach((e) => e.classList.remove(Z)), et && (O.removeEventListener("mouseleave", Ht), st(null)), B && (window.removeEventListener("scroll", rt, !0), window.removeEventListener("resize", rt)), B && dt && O.removeEventListener("dblclick", Xt), K(), a.forEach(
|
|
614
|
+
(e) => e.forEach((r) => r.style.visibility = "")
|
|
615
|
+
), a = [], I = [], Y = [], k = null, F.clear(), V.splice(0), Et.splice(0);
|
|
616
|
+
},
|
|
617
|
+
getGroups() {
|
|
618
|
+
return a.slice();
|
|
619
|
+
},
|
|
620
|
+
clearGroups() {
|
|
621
|
+
a.forEach(
|
|
622
|
+
(e) => e.forEach((r) => r.style.visibility = "")
|
|
623
|
+
), a = [], I = [], Y = [], k = null, K(), A(/* @__PURE__ */ new Set());
|
|
624
|
+
},
|
|
625
|
+
removeGroup(t) {
|
|
626
|
+
return Ft(t);
|
|
627
|
+
},
|
|
628
|
+
addGroup(t) {
|
|
629
|
+
return se(t);
|
|
630
|
+
},
|
|
631
|
+
setGroupVisibility(t, e) {
|
|
632
|
+
return ot(t, e);
|
|
633
|
+
},
|
|
634
|
+
toggleGroupVisibility(t) {
|
|
635
|
+
return t < 0 || t >= a.length ? !1 : (I[t] = !I[t], Ot(t), L(), !0);
|
|
636
|
+
},
|
|
637
|
+
getSelectionResult() {
|
|
638
|
+
return it();
|
|
639
|
+
},
|
|
640
|
+
refresh() {
|
|
641
|
+
L();
|
|
642
|
+
},
|
|
643
|
+
hideOverlays() {
|
|
644
|
+
K();
|
|
645
|
+
},
|
|
646
|
+
showAndRefreshOverlays() {
|
|
647
|
+
L();
|
|
648
|
+
},
|
|
649
|
+
// 获取当前组级嵌套信息
|
|
650
|
+
getGroupNesting() {
|
|
651
|
+
const t = it();
|
|
652
|
+
return t.type === "groups" ? t.groupNesting : null;
|
|
653
|
+
},
|
|
654
|
+
onSelectionEnd(t) {
|
|
655
|
+
return V.push(t), () => {
|
|
656
|
+
const e = V.indexOf(t);
|
|
657
|
+
e >= 0 && V.splice(e, 1);
|
|
658
|
+
};
|
|
659
|
+
},
|
|
660
|
+
waitForSelectionEnd() {
|
|
661
|
+
return new Promise((t) => {
|
|
662
|
+
Et.push(t);
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
return Nt = Tt, Tt;
|
|
667
|
+
}
|
|
668
|
+
export {
|
|
669
|
+
ce as default,
|
|
670
|
+
ce as marqueeSelection
|
|
671
|
+
};
|
|
672
|
+
//# sourceMappingURL=marquee-selection.es.js.map
|