pixelagent 0.1.25 → 0.1.27

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.
@@ -0,0 +1,970 @@
1
+ const Q = "[modern-screenshot]", T = typeof window < "u", de = T && "Worker" in window;
2
+ var Y;
3
+ const O = T ? (Y = window.navigator) == null ? void 0 : Y.userAgent : "", J = O.includes("Chrome"), M = O.includes("AppleWebKit") && !J, q = O.includes("Firefox"), me = (e) => e && "__CONTEXT__" in e, ge = (e) => e.constructor.name === "CSSFontFaceRule", he = (e) => e.constructor.name === "CSSImportRule", pe = (e) => e.constructor.name === "CSSLayerBlockRule", v = (e) => e.nodeType === 1, _ = (e) => typeof e.className == "object", Z = (e) => e.tagName === "image", we = (e) => e.tagName === "use", A = (e) => v(e) && typeof e.style < "u" && !_(e), ye = (e) => e.nodeType === 8, Se = (e) => e.nodeType === 3, R = (e) => e.tagName === "IMG", $ = (e) => e.tagName === "VIDEO", be = (e) => e.tagName === "CANVAS", Ee = (e) => e.tagName === "TEXTAREA", Ce = (e) => e.tagName === "INPUT", ve = (e) => e.tagName === "STYLE", Ne = (e) => e.tagName === "SCRIPT", Te = (e) => e.tagName === "SELECT", Re = (e) => e.tagName === "SLOT", Ae = (e) => e.tagName === "IFRAME", ke = (...e) => console.warn(Q, ...e);
4
+ function Ie(e) {
5
+ var r;
6
+ const t = (r = e == null ? void 0 : e.createElement) == null ? void 0 : r.call(e, "canvas");
7
+ return t && (t.height = t.width = 1), !!t && "toDataURL" in t && !!t.toDataURL("image/webp").includes("image/webp");
8
+ }
9
+ const U = (e) => e.startsWith("data:");
10
+ function ee(e, t) {
11
+ if (e.match(/^[a-z]+:\/\//i))
12
+ return e;
13
+ if (T && e.match(/^\/\//))
14
+ return window.location.protocol + e;
15
+ if (e.match(/^[a-z]+:/i) || !T)
16
+ return e;
17
+ const r = P().implementation.createHTMLDocument(), n = r.createElement("base"), i = r.createElement("a");
18
+ return r.head.appendChild(n), r.body.appendChild(i), t && (n.href = t), i.href = e, i.href;
19
+ }
20
+ function P(e) {
21
+ return (e && v(e) ? e == null ? void 0 : e.ownerDocument : e) ?? window.document;
22
+ }
23
+ const x = "http://www.w3.org/2000/svg";
24
+ function _e(e, t, r) {
25
+ const n = P(r).createElementNS(x, "svg");
26
+ return n.setAttributeNS(null, "width", e.toString()), n.setAttributeNS(null, "height", t.toString()), n.setAttributeNS(null, "viewBox", `0 0 ${e} ${t}`), n;
27
+ }
28
+ function Fe(e, t) {
29
+ let r = new XMLSerializer().serializeToString(e);
30
+ return t && (r = r.replace(/[\u0000-\u0008\v\f\u000E-\u001F\uD800-\uDFFF\uFFFE\uFFFF]/gu, "")), `data:image/svg+xml;charset=utf-8,${encodeURIComponent(r)}`;
31
+ }
32
+ function De(e, t) {
33
+ return new Promise((r, n) => {
34
+ const i = new FileReader();
35
+ i.onload = () => r(i.result), i.onerror = () => n(i.error), i.onabort = () => n(new Error(`Failed read blob to ${t}`)), i.readAsDataURL(e);
36
+ });
37
+ }
38
+ const Me = (e) => De(e, "dataUrl");
39
+ function N(e, t) {
40
+ const r = P(t).createElement("img");
41
+ return r.decoding = "sync", r.loading = "eager", r.src = e, r;
42
+ }
43
+ function k(e, t) {
44
+ return new Promise((r) => {
45
+ const { timeout: n, ownerDocument: i, onError: o, onWarn: a } = t ?? {}, s = typeof e == "string" ? N(e, P(i)) : e;
46
+ let c = null, u = null;
47
+ function l() {
48
+ r(s), c && clearTimeout(c), u == null || u();
49
+ }
50
+ if (n && (c = setTimeout(l, n)), $(s)) {
51
+ const h = s.currentSrc || s.src;
52
+ if (!h)
53
+ return s.poster ? k(s.poster, t).then(r) : l();
54
+ if (s.readyState >= 2)
55
+ return l();
56
+ const m = l, f = (g) => {
57
+ a == null || a(
58
+ "Failed video load",
59
+ h,
60
+ g
61
+ ), o == null || o(g), l();
62
+ };
63
+ u = () => {
64
+ s.removeEventListener("loadeddata", m), s.removeEventListener("error", f);
65
+ }, s.addEventListener("loadeddata", m, { once: !0 }), s.addEventListener("error", f, { once: !0 });
66
+ } else {
67
+ const h = Z(s) ? s.href.baseVal : s.currentSrc || s.src;
68
+ if (!h)
69
+ return l();
70
+ const m = async () => {
71
+ if (R(s) && "decode" in s)
72
+ try {
73
+ await s.decode();
74
+ } catch (g) {
75
+ a == null || a(
76
+ "Failed to decode image, trying to render anyway",
77
+ s.dataset.originalSrc || h,
78
+ g
79
+ );
80
+ }
81
+ l();
82
+ }, f = (g) => {
83
+ a == null || a(
84
+ "Failed image load",
85
+ s.dataset.originalSrc || h,
86
+ g
87
+ ), l();
88
+ };
89
+ if (R(s) && s.complete)
90
+ return m();
91
+ u = () => {
92
+ s.removeEventListener("load", m), s.removeEventListener("error", f);
93
+ }, s.addEventListener("load", m, { once: !0 }), s.addEventListener("error", f, { once: !0 });
94
+ }
95
+ });
96
+ }
97
+ async function $e(e, t) {
98
+ A(e) && (R(e) || $(e) ? await k(e, t) : await Promise.all(
99
+ ["img", "video"].flatMap((r) => Array.from(e.querySelectorAll(r)).map((n) => k(n, t)))
100
+ ));
101
+ }
102
+ const te = /* @__PURE__ */ (function() {
103
+ let t = 0;
104
+ const r = () => `0000${(Math.random() * 36 ** 4 << 0).toString(36)}`.slice(-4);
105
+ return () => (t += 1, `u${r()}${t}`);
106
+ })();
107
+ function re(e) {
108
+ return e == null ? void 0 : e.split(",").map((t) => t.trim().replace(/"|'/g, "").toLowerCase()).filter(Boolean);
109
+ }
110
+ let j = 0;
111
+ function Pe(e) {
112
+ const t = `${Q}[#${j}]`;
113
+ return j++, {
114
+ // eslint-disable-next-line no-console
115
+ time: (r) => e && console.time(`${t} ${r}`),
116
+ // eslint-disable-next-line no-console
117
+ timeEnd: (r) => e && console.timeEnd(`${t} ${r}`),
118
+ warn: (...r) => e && ke(...r)
119
+ };
120
+ }
121
+ function xe(e) {
122
+ return {
123
+ cache: e ? "no-cache" : "force-cache"
124
+ };
125
+ }
126
+ async function ne(e, t) {
127
+ return me(e) ? e : Ue(e, { ...t, autoDestruct: !0 });
128
+ }
129
+ async function Ue(e, t) {
130
+ var f, g;
131
+ const { scale: r = 1, workerUrl: n, workerNumber: i = 1 } = t || {}, o = !!(t != null && t.debug), a = (t == null ? void 0 : t.features) ?? !0, s = e.ownerDocument ?? (T ? window.document : void 0), c = ((f = e.ownerDocument) == null ? void 0 : f.defaultView) ?? (T ? window : void 0), u = /* @__PURE__ */ new Map(), l = {
132
+ // Options
133
+ width: 0,
134
+ height: 0,
135
+ quality: 1,
136
+ type: "image/png",
137
+ scale: r,
138
+ backgroundColor: null,
139
+ style: null,
140
+ filter: null,
141
+ maximumCanvasSize: 0,
142
+ timeout: 3e4,
143
+ progress: null,
144
+ debug: o,
145
+ fetch: {
146
+ requestInit: xe((g = t == null ? void 0 : t.fetch) == null ? void 0 : g.bypassingCache),
147
+ placeholderImage: "data:image/png;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
148
+ bypassingCache: !1,
149
+ ...t == null ? void 0 : t.fetch
150
+ },
151
+ fetchFn: null,
152
+ font: {},
153
+ drawImageInterval: 100,
154
+ workerUrl: null,
155
+ workerNumber: i,
156
+ onCloneEachNode: null,
157
+ onCloneNode: null,
158
+ onEmbedNode: null,
159
+ onCreateForeignObjectSvg: null,
160
+ includeStyleProperties: null,
161
+ autoDestruct: !1,
162
+ ...t,
163
+ // InternalContext
164
+ __CONTEXT__: !0,
165
+ log: Pe(o),
166
+ node: e,
167
+ ownerDocument: s,
168
+ ownerWindow: c,
169
+ dpi: r === 1 ? null : 96 * r,
170
+ svgStyleElement: se(s),
171
+ svgDefsElement: s == null ? void 0 : s.createElementNS(x, "defs"),
172
+ svgStyles: /* @__PURE__ */ new Map(),
173
+ defaultComputedStyles: /* @__PURE__ */ new Map(),
174
+ workers: [
175
+ ...Array.from({
176
+ length: de && n && i ? i : 0
177
+ })
178
+ ].map(() => {
179
+ try {
180
+ const d = new Worker(n);
181
+ return d.onmessage = async (p) => {
182
+ var w, b, E, C;
183
+ const { url: y, result: S } = p.data;
184
+ S ? (b = (w = u.get(y)) == null ? void 0 : w.resolve) == null || b.call(w, S) : (C = (E = u.get(y)) == null ? void 0 : E.reject) == null || C.call(E, new Error(`Error receiving message from worker: ${y}`));
185
+ }, d.onmessageerror = (p) => {
186
+ var S, w;
187
+ const { url: y } = p.data;
188
+ (w = (S = u.get(y)) == null ? void 0 : S.reject) == null || w.call(S, new Error(`Error receiving message from worker: ${y}`));
189
+ }, d;
190
+ } catch (d) {
191
+ return l.log.warn("Failed to new Worker", d), null;
192
+ }
193
+ }).filter(Boolean),
194
+ fontFamilies: /* @__PURE__ */ new Map(),
195
+ fontCssTexts: /* @__PURE__ */ new Map(),
196
+ acceptOfImage: `${[
197
+ Ie(s) && "image/webp",
198
+ "image/svg+xml",
199
+ "image/*",
200
+ "*/*"
201
+ ].filter(Boolean).join(",")};q=0.8`,
202
+ requests: u,
203
+ drawImageCount: 0,
204
+ tasks: [],
205
+ features: a,
206
+ isEnable: (d) => d === "restoreScrollPosition" ? typeof a == "boolean" ? !1 : a[d] ?? !1 : typeof a == "boolean" ? a : a[d] ?? !0,
207
+ shadowRoots: []
208
+ };
209
+ l.log.time("wait until load"), await $e(e, { timeout: l.timeout, onWarn: l.log.warn }), l.log.timeEnd("wait until load");
210
+ const { width: h, height: m } = Le(e, l);
211
+ return l.width = h, l.height = m, l;
212
+ }
213
+ function se(e) {
214
+ if (!e)
215
+ return;
216
+ const t = e.createElement("style"), r = t.ownerDocument.createTextNode(`
217
+ .______background-clip--text {
218
+ background-clip: text;
219
+ -webkit-background-clip: text;
220
+ }
221
+ `);
222
+ return t.appendChild(r), t;
223
+ }
224
+ function Le(e, t) {
225
+ let { width: r, height: n } = t;
226
+ if (v(e) && (!r || !n)) {
227
+ const i = e.getBoundingClientRect();
228
+ r = r || i.width || Number(e.getAttribute("width")) || 0, n = n || i.height || Number(e.getAttribute("height")) || 0;
229
+ }
230
+ return { width: r, height: n };
231
+ }
232
+ async function Be(e, t) {
233
+ const {
234
+ log: r,
235
+ timeout: n,
236
+ drawImageCount: i,
237
+ drawImageInterval: o
238
+ } = t;
239
+ r.time("image to canvas");
240
+ const a = await k(e, { timeout: n, onWarn: t.log.warn }), { canvas: s, context2d: c } = Oe(e.ownerDocument, t), u = () => {
241
+ try {
242
+ c == null || c.drawImage(a, 0, 0, s.width, s.height);
243
+ } catch (l) {
244
+ t.log.warn("Failed to drawImage", l);
245
+ }
246
+ };
247
+ if (u(), t.isEnable("fixSvgXmlDecode"))
248
+ for (let l = 0; l < i; l++)
249
+ await new Promise((h) => {
250
+ setTimeout(() => {
251
+ c == null || c.clearRect(0, 0, s.width, s.height), u(), h();
252
+ }, l + o);
253
+ });
254
+ return t.drawImageCount = 0, r.timeEnd("image to canvas"), s;
255
+ }
256
+ function Oe(e, t) {
257
+ const { width: r, height: n, scale: i, backgroundColor: o, maximumCanvasSize: a } = t, s = e.createElement("canvas");
258
+ s.width = Math.floor(r * i), s.height = Math.floor(n * i), s.style.width = `${r}px`, s.style.height = `${n}px`, a && (s.width > a || s.height > a) && (s.width > a && s.height > a ? s.width > s.height ? (s.height *= a / s.width, s.width = a) : (s.width *= a / s.height, s.height = a) : s.width > a ? (s.height *= a / s.width, s.width = a) : (s.width *= a / s.height, s.height = a));
259
+ const c = s.getContext("2d");
260
+ return c && o && (c.fillStyle = o, c.fillRect(0, 0, s.width, s.height)), { canvas: s, context2d: c };
261
+ }
262
+ function oe(e, t) {
263
+ if (e.ownerDocument)
264
+ try {
265
+ const o = e.toDataURL();
266
+ if (o !== "data:,")
267
+ return N(o, e.ownerDocument);
268
+ } catch (o) {
269
+ t.log.warn("Failed to clone canvas", o);
270
+ }
271
+ const r = e.cloneNode(!1), n = e.getContext("2d"), i = r.getContext("2d");
272
+ try {
273
+ return n && i && i.putImageData(
274
+ n.getImageData(0, 0, e.width, e.height),
275
+ 0,
276
+ 0
277
+ ), r;
278
+ } catch (o) {
279
+ t.log.warn("Failed to clone canvas", o);
280
+ }
281
+ return r;
282
+ }
283
+ function qe(e, t) {
284
+ var r;
285
+ try {
286
+ if ((r = e == null ? void 0 : e.contentDocument) != null && r.documentElement)
287
+ return W(e.contentDocument.documentElement, t);
288
+ } catch (n) {
289
+ t.log.warn("Failed to clone iframe", n);
290
+ }
291
+ return e.cloneNode(!1);
292
+ }
293
+ function We(e) {
294
+ const t = e.cloneNode(!1);
295
+ return e.currentSrc && e.currentSrc !== e.src && (t.src = e.currentSrc, t.srcset = ""), t.loading === "lazy" && (t.loading = "eager"), t;
296
+ }
297
+ async function Ve(e, t) {
298
+ if (e.ownerDocument && !e.currentSrc && e.poster)
299
+ return N(e.poster, e.ownerDocument);
300
+ const r = e.cloneNode(!1);
301
+ r.crossOrigin = "anonymous", e.currentSrc && e.currentSrc !== e.src && (r.src = e.currentSrc);
302
+ const n = r.ownerDocument;
303
+ if (n) {
304
+ let i = !0;
305
+ if (await k(r, { onError: () => i = !1, onWarn: t.log.warn }), !i)
306
+ return e.poster ? N(e.poster, e.ownerDocument) : r;
307
+ r.currentTime = e.currentTime, await new Promise((a) => {
308
+ r.addEventListener("seeked", a, { once: !0 });
309
+ });
310
+ const o = n.createElement("canvas");
311
+ o.width = e.offsetWidth, o.height = e.offsetHeight;
312
+ try {
313
+ const a = o.getContext("2d");
314
+ a && a.drawImage(r, 0, 0, o.width, o.height);
315
+ } catch (a) {
316
+ return t.log.warn("Failed to clone video", a), e.poster ? N(e.poster, e.ownerDocument) : r;
317
+ }
318
+ return oe(o, t);
319
+ }
320
+ return r;
321
+ }
322
+ function je(e, t) {
323
+ return be(e) ? oe(e, t) : Ae(e) ? qe(e, t) : R(e) ? We(e) : $(e) ? Ve(e, t) : e.cloneNode(!1);
324
+ }
325
+ function He(e) {
326
+ let t = e.sandbox;
327
+ if (!t) {
328
+ const { ownerDocument: r } = e;
329
+ try {
330
+ r && (t = r.createElement("iframe"), t.id = `__SANDBOX__${te()}`, t.width = "0", t.height = "0", t.style.visibility = "hidden", t.style.position = "fixed", r.body.appendChild(t), t.srcdoc = '<!DOCTYPE html><meta charset="UTF-8"><title></title><body>', e.sandbox = t);
331
+ } catch (n) {
332
+ e.log.warn("Failed to getSandBox", n);
333
+ }
334
+ }
335
+ return t;
336
+ }
337
+ const ze = [
338
+ "width",
339
+ "height",
340
+ "-webkit-text-fill-color"
341
+ ], Xe = [
342
+ "stroke",
343
+ "fill"
344
+ ];
345
+ function ae(e, t, r) {
346
+ const { defaultComputedStyles: n } = r, i = e.nodeName.toLowerCase(), o = _(e) && i !== "svg", a = o ? Xe.map((d) => [d, e.getAttribute(d)]).filter(([, d]) => d !== null) : [], s = [
347
+ o && "svg",
348
+ i,
349
+ a.map((d, p) => `${d}=${p}`).join(","),
350
+ t
351
+ ].filter(Boolean).join(":");
352
+ if (n.has(s))
353
+ return n.get(s);
354
+ const c = He(r), u = c == null ? void 0 : c.contentWindow;
355
+ if (!u)
356
+ return /* @__PURE__ */ new Map();
357
+ const l = u == null ? void 0 : u.document;
358
+ let h, m;
359
+ o ? (h = l.createElementNS(x, "svg"), m = h.ownerDocument.createElementNS(h.namespaceURI, i), a.forEach(([d, p]) => {
360
+ m.setAttributeNS(null, d, p);
361
+ }), h.appendChild(m)) : h = m = l.createElement(i), m.textContent = " ", l.body.appendChild(h);
362
+ const f = u.getComputedStyle(m, t), g = /* @__PURE__ */ new Map();
363
+ for (let d = f.length, p = 0; p < d; p++) {
364
+ const y = f.item(p);
365
+ ze.includes(y) || g.set(y, f.getPropertyValue(y));
366
+ }
367
+ return l.body.removeChild(h), n.set(s, g), g;
368
+ }
369
+ function ie(e, t, r) {
370
+ var s;
371
+ const n = /* @__PURE__ */ new Map(), i = [], o = /* @__PURE__ */ new Map();
372
+ if (r)
373
+ for (const c of r)
374
+ a(c);
375
+ else
376
+ for (let c = e.length, u = 0; u < c; u++) {
377
+ const l = e.item(u);
378
+ a(l);
379
+ }
380
+ for (let c = i.length, u = 0; u < c; u++)
381
+ (s = o.get(i[u])) == null || s.forEach((l, h) => n.set(h, l));
382
+ function a(c) {
383
+ const u = e.getPropertyValue(c), l = e.getPropertyPriority(c), h = c.lastIndexOf("-"), m = h > -1 ? c.substring(0, h) : void 0;
384
+ if (m) {
385
+ let f = o.get(m);
386
+ f || (f = /* @__PURE__ */ new Map(), o.set(m, f)), f.set(c, [u, l]);
387
+ }
388
+ t.get(c) === u && !l || (m ? i.push(m) : n.set(c, [u, l]));
389
+ }
390
+ return n;
391
+ }
392
+ function Ge(e, t, r, n) {
393
+ var h, m, f, g;
394
+ const { ownerWindow: i, includeStyleProperties: o, currentParentNodeStyle: a } = n, s = t.style, c = i.getComputedStyle(e), u = ae(e, null, n);
395
+ a == null || a.forEach((d, p) => {
396
+ u.delete(p);
397
+ });
398
+ const l = ie(c, u, o);
399
+ l.delete("transition-property"), l.delete("all"), l.delete("d"), l.delete("content"), r && (l.delete("position"), l.delete("margin-top"), l.delete("margin-right"), l.delete("margin-bottom"), l.delete("margin-left"), l.delete("margin-block-start"), l.delete("margin-block-end"), l.delete("margin-inline-start"), l.delete("margin-inline-end"), l.set("box-sizing", ["border-box", ""])), ((h = l.get("background-clip")) == null ? void 0 : h[0]) === "text" && t.classList.add("______background-clip--text"), J && (l.has("font-kerning") || l.set("font-kerning", ["normal", ""]), (((m = l.get("overflow-x")) == null ? void 0 : m[0]) === "hidden" || ((f = l.get("overflow-y")) == null ? void 0 : f[0]) === "hidden") && ((g = l.get("text-overflow")) == null ? void 0 : g[0]) === "ellipsis" && e.scrollWidth === e.clientWidth && l.set("text-overflow", ["clip", ""]));
400
+ for (let d = s.length, p = 0; p < d; p++)
401
+ s.removeProperty(s.item(p));
402
+ return l.forEach(([d, p], y) => {
403
+ s.setProperty(y, d, p);
404
+ }), l;
405
+ }
406
+ function Ke(e, t) {
407
+ (Ee(e) || Ce(e) || Te(e)) && t.setAttribute("value", e.value);
408
+ }
409
+ const Ye = [
410
+ "::before",
411
+ "::after"
412
+ // '::placeholder', TODO
413
+ ], Qe = [
414
+ "::-webkit-scrollbar",
415
+ "::-webkit-scrollbar-button",
416
+ // '::-webkit-scrollbar:horizontal', TODO
417
+ "::-webkit-scrollbar-thumb",
418
+ "::-webkit-scrollbar-track",
419
+ "::-webkit-scrollbar-track-piece",
420
+ // '::-webkit-scrollbar:vertical', TODO
421
+ "::-webkit-scrollbar-corner",
422
+ "::-webkit-resizer"
423
+ ];
424
+ function Je(e, t, r, n, i) {
425
+ const { ownerWindow: o, svgStyleElement: a, svgStyles: s, currentNodeStyle: c } = n;
426
+ if (!a || !o)
427
+ return;
428
+ function u(l) {
429
+ var w;
430
+ const h = o.getComputedStyle(e, l);
431
+ let m = h.getPropertyValue("content");
432
+ if (!m || m === "none")
433
+ return;
434
+ i == null || i(m), m = m.replace(/(')|(")|(counter\(.+\))/g, "");
435
+ const f = [te()], g = ae(e, l, n);
436
+ c == null || c.forEach((b, E) => {
437
+ g.delete(E);
438
+ });
439
+ const d = ie(h, g, n.includeStyleProperties);
440
+ d.delete("content"), d.delete("-webkit-locale"), ((w = d.get("background-clip")) == null ? void 0 : w[0]) === "text" && t.classList.add("______background-clip--text");
441
+ const p = [
442
+ `content: '${m}';`
443
+ ];
444
+ if (d.forEach(([b, E], C) => {
445
+ p.push(`${C}: ${b}${E ? " !important" : ""};`);
446
+ }), p.length === 1)
447
+ return;
448
+ try {
449
+ t.className = [t.className, ...f].join(" ");
450
+ } catch (b) {
451
+ n.log.warn("Failed to copyPseudoClass", b);
452
+ return;
453
+ }
454
+ const y = p.join(`
455
+ `);
456
+ let S = s.get(y);
457
+ S || (S = [], s.set(y, S)), S.push(`.${f[0]}${l}`);
458
+ }
459
+ Ye.forEach(u), r && Qe.forEach(u);
460
+ }
461
+ const H = /* @__PURE__ */ new Set([
462
+ "symbol"
463
+ // test/fixtures/svg.symbol.html
464
+ ]);
465
+ async function z(e, t, r, n, i) {
466
+ if (v(r) && (ve(r) || Ne(r)) || n.filter && !n.filter(r))
467
+ return;
468
+ H.has(t.nodeName) || H.has(r.nodeName) ? n.currentParentNodeStyle = void 0 : n.currentParentNodeStyle = n.currentNodeStyle;
469
+ const o = await W(r, n, !1, i);
470
+ n.isEnable("restoreScrollPosition") && Ze(e, o), t.appendChild(o);
471
+ }
472
+ async function X(e, t, r, n) {
473
+ var o;
474
+ let i = e.firstChild;
475
+ v(e) && e.shadowRoot && (i = (o = e.shadowRoot) == null ? void 0 : o.firstChild, r.shadowRoots.push(e.shadowRoot));
476
+ for (let a = i; a; a = a.nextSibling)
477
+ if (!ye(a))
478
+ if (v(a) && Re(a) && typeof a.assignedNodes == "function") {
479
+ const s = a.assignedNodes();
480
+ for (let c = 0; c < s.length; c++)
481
+ await z(e, t, s[c], r, n);
482
+ } else
483
+ await z(e, t, a, r, n);
484
+ }
485
+ function Ze(e, t) {
486
+ if (!A(e) || !A(t))
487
+ return;
488
+ const { scrollTop: r, scrollLeft: n } = e;
489
+ if (!r && !n)
490
+ return;
491
+ const { transform: i } = t.style, o = new DOMMatrix(i), { a, b: s, c, d: u } = o;
492
+ o.a = 1, o.b = 0, o.c = 0, o.d = 1, o.translateSelf(-n, -r), o.a = a, o.b = s, o.c = c, o.d = u, t.style.transform = o.toString();
493
+ }
494
+ function et(e, t) {
495
+ const { backgroundColor: r, width: n, height: i, style: o } = t, a = e.style;
496
+ if (r && a.setProperty("background-color", r, "important"), n && a.setProperty("width", `${n}px`, "important"), i && a.setProperty("height", `${i}px`, "important"), o)
497
+ for (const s in o) a[s] = o[s];
498
+ }
499
+ const tt = /^[\w-:]+$/;
500
+ async function W(e, t, r = !1, n) {
501
+ var u, l, h, m;
502
+ const { ownerDocument: i, ownerWindow: o, fontFamilies: a, onCloneEachNode: s } = t;
503
+ if (i && Se(e))
504
+ return n && /\S/.test(e.data) && n(e.data), i.createTextNode(e.data);
505
+ if (i && o && v(e) && (A(e) || _(e))) {
506
+ const f = await je(e, t);
507
+ if (t.isEnable("removeAbnormalAttributes")) {
508
+ const w = f.getAttributeNames();
509
+ for (let b = w.length, E = 0; E < b; E++) {
510
+ const C = w[E];
511
+ tt.test(C) || f.removeAttribute(C);
512
+ }
513
+ }
514
+ const g = t.currentNodeStyle = Ge(e, f, r, t);
515
+ r && et(f, t);
516
+ let d = !1;
517
+ if (t.isEnable("copyScrollbar")) {
518
+ const w = [
519
+ (u = g.get("overflow-x")) == null ? void 0 : u[0],
520
+ (l = g.get("overflow-y")) == null ? void 0 : l[0]
521
+ ];
522
+ d = w.includes("scroll") || (w.includes("auto") || w.includes("overlay")) && (e.scrollHeight > e.clientHeight || e.scrollWidth > e.clientWidth);
523
+ }
524
+ const p = (h = g.get("text-transform")) == null ? void 0 : h[0], y = re((m = g.get("font-family")) == null ? void 0 : m[0]), S = y ? (w) => {
525
+ p === "uppercase" ? w = w.toUpperCase() : p === "lowercase" ? w = w.toLowerCase() : p === "capitalize" && (w = w[0].toUpperCase() + w.substring(1)), y.forEach((b) => {
526
+ let E = a.get(b);
527
+ E || a.set(b, E = /* @__PURE__ */ new Set()), w.split("").forEach((C) => E.add(C));
528
+ });
529
+ } : void 0;
530
+ return Je(
531
+ e,
532
+ f,
533
+ d,
534
+ t,
535
+ S
536
+ ), Ke(e, f), $(e) || await X(
537
+ e,
538
+ f,
539
+ t,
540
+ S
541
+ ), await (s == null ? void 0 : s(f)), f;
542
+ }
543
+ const c = e.cloneNode(!1);
544
+ return await X(e, c, t), await (s == null ? void 0 : s(c)), c;
545
+ }
546
+ function rt(e) {
547
+ if (e.ownerDocument = void 0, e.ownerWindow = void 0, e.svgStyleElement = void 0, e.svgDefsElement = void 0, e.svgStyles.clear(), e.defaultComputedStyles.clear(), e.sandbox) {
548
+ try {
549
+ e.sandbox.remove();
550
+ } catch (t) {
551
+ e.log.warn("Failed to destroyContext", t);
552
+ }
553
+ e.sandbox = void 0;
554
+ }
555
+ e.workers = [], e.fontFamilies.clear(), e.fontCssTexts.clear(), e.requests.clear(), e.tasks = [], e.shadowRoots = [];
556
+ }
557
+ function nt(e) {
558
+ const { url: t, timeout: r, responseType: n, ...i } = e, o = new AbortController(), a = r ? setTimeout(() => o.abort(), r) : void 0;
559
+ return fetch(t, { signal: o.signal, ...i }).then((s) => {
560
+ if (!s.ok)
561
+ throw new Error("Failed fetch, not 2xx response", { cause: s });
562
+ switch (n) {
563
+ case "arrayBuffer":
564
+ return s.arrayBuffer();
565
+ case "dataUrl":
566
+ return s.blob().then(Me);
567
+ case "text":
568
+ default:
569
+ return s.text();
570
+ }
571
+ }).finally(() => clearTimeout(a));
572
+ }
573
+ function I(e, t) {
574
+ const { url: r, requestType: n = "text", responseType: i = "text", imageDom: o } = t;
575
+ let a = r;
576
+ const {
577
+ timeout: s,
578
+ acceptOfImage: c,
579
+ requests: u,
580
+ fetchFn: l,
581
+ fetch: {
582
+ requestInit: h,
583
+ bypassingCache: m,
584
+ placeholderImage: f
585
+ },
586
+ font: g,
587
+ workers: d,
588
+ fontFamilies: p
589
+ } = e;
590
+ n === "image" && (M || q) && e.drawImageCount++;
591
+ let y = u.get(r);
592
+ if (!y) {
593
+ m && m instanceof RegExp && m.test(a) && (a += (/\?/.test(a) ? "&" : "?") + (/* @__PURE__ */ new Date()).getTime());
594
+ const S = n.startsWith("font") && g && g.minify, w = /* @__PURE__ */ new Set();
595
+ S && n.split(";")[1].split(",").forEach((F) => {
596
+ p.has(F) && p.get(F).forEach((V) => w.add(V));
597
+ });
598
+ const b = S && w.size, E = {
599
+ url: a,
600
+ timeout: s,
601
+ responseType: b ? "arrayBuffer" : i,
602
+ headers: n === "image" ? { accept: c } : void 0,
603
+ ...h
604
+ };
605
+ y = {
606
+ type: n,
607
+ resolve: void 0,
608
+ reject: void 0,
609
+ response: null
610
+ }, y.response = (async () => {
611
+ if (l && n === "image") {
612
+ const C = await l(r);
613
+ if (C)
614
+ return C;
615
+ }
616
+ return !M && r.startsWith("http") && d.length ? new Promise((C, F) => {
617
+ d[u.size & d.length - 1].postMessage({ rawUrl: r, ...E }), y.resolve = C, y.reject = F;
618
+ }) : nt(E);
619
+ })().catch((C) => {
620
+ if (u.delete(r), n === "image" && f)
621
+ return e.log.warn("Failed to fetch image base64, trying to use placeholder image", a), typeof f == "string" ? f : f(o);
622
+ throw C;
623
+ }), u.set(r, y);
624
+ }
625
+ return y.response;
626
+ }
627
+ async function le(e, t, r, n) {
628
+ if (!ce(e))
629
+ return e;
630
+ for (const [i, o] of st(e, t))
631
+ try {
632
+ const a = await I(
633
+ r,
634
+ {
635
+ url: o,
636
+ requestType: n ? "image" : "text",
637
+ responseType: "dataUrl"
638
+ }
639
+ );
640
+ e = e.replace(ot(i), `$1${a}$3`);
641
+ } catch (a) {
642
+ r.log.warn("Failed to fetch css data url", i, a);
643
+ }
644
+ return e;
645
+ }
646
+ function ce(e) {
647
+ return /url\((['"]?)([^'"]+?)\1\)/.test(e);
648
+ }
649
+ const ue = /url\((['"]?)([^'"]+?)\1\)/g;
650
+ function st(e, t) {
651
+ const r = [];
652
+ return e.replace(ue, (n, i, o) => (r.push([o, ee(o, t)]), n)), r.filter(([n]) => !U(n));
653
+ }
654
+ function ot(e) {
655
+ const t = e.replace(/([.*+?^${}()|\[\]\/\\])/g, "\\$1");
656
+ return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`, "g");
657
+ }
658
+ const at = [
659
+ "background-image",
660
+ "border-image-source",
661
+ "-webkit-border-image",
662
+ "-webkit-mask-image",
663
+ "list-style-image"
664
+ ];
665
+ function it(e, t) {
666
+ return at.map((r) => {
667
+ const n = e.getPropertyValue(r);
668
+ return !n || n === "none" ? null : ((M || q) && t.drawImageCount++, le(n, null, t, !0).then((i) => {
669
+ !i || n === i || e.setProperty(
670
+ r,
671
+ i,
672
+ e.getPropertyPriority(r)
673
+ );
674
+ }));
675
+ }).filter(Boolean);
676
+ }
677
+ function lt(e, t) {
678
+ if (R(e)) {
679
+ const r = e.currentSrc || e.src;
680
+ if (!U(r))
681
+ return [
682
+ I(t, {
683
+ url: r,
684
+ imageDom: e,
685
+ requestType: "image",
686
+ responseType: "dataUrl"
687
+ }).then((n) => {
688
+ n && (e.srcset = "", e.dataset.originalSrc = r, e.src = n || "");
689
+ })
690
+ ];
691
+ (M || q) && t.drawImageCount++;
692
+ } else if (_(e) && !U(e.href.baseVal)) {
693
+ const r = e.href.baseVal;
694
+ return [
695
+ I(t, {
696
+ url: r,
697
+ imageDom: e,
698
+ requestType: "image",
699
+ responseType: "dataUrl"
700
+ }).then((n) => {
701
+ n && (e.dataset.originalSrc = r, e.href.baseVal = n || "");
702
+ })
703
+ ];
704
+ }
705
+ return [];
706
+ }
707
+ function ct(e, t) {
708
+ const { ownerDocument: r, svgDefsElement: n } = t, i = e.getAttribute("href") ?? e.getAttribute("xlink:href");
709
+ if (!i)
710
+ return [];
711
+ const [o, a] = i.split("#");
712
+ if (a) {
713
+ const s = `#${a}`, c = t.shadowRoots.reduce(
714
+ (u, l) => u ?? l.querySelector(`svg ${s}`),
715
+ r == null ? void 0 : r.querySelector(`svg ${s}`)
716
+ );
717
+ if (o && e.setAttribute("href", s), n != null && n.querySelector(s))
718
+ return [];
719
+ if (c)
720
+ return n == null || n.appendChild(c.cloneNode(!0)), [];
721
+ if (o)
722
+ return [
723
+ I(t, {
724
+ url: o,
725
+ responseType: "text"
726
+ }).then((u) => {
727
+ n == null || n.insertAdjacentHTML("beforeend", u);
728
+ })
729
+ ];
730
+ }
731
+ return [];
732
+ }
733
+ function fe(e, t) {
734
+ const { tasks: r } = t;
735
+ v(e) && ((R(e) || Z(e)) && r.push(...lt(e, t)), we(e) && r.push(...ct(e, t))), A(e) && r.push(...it(e.style, t)), e.childNodes.forEach((n) => {
736
+ fe(n, t);
737
+ });
738
+ }
739
+ async function ut(e, t) {
740
+ const {
741
+ ownerDocument: r,
742
+ svgStyleElement: n,
743
+ fontFamilies: i,
744
+ fontCssTexts: o,
745
+ tasks: a,
746
+ font: s
747
+ } = t;
748
+ if (!(!r || !n || !i.size))
749
+ if (s && s.cssText) {
750
+ const c = K(s.cssText, t);
751
+ n.appendChild(r.createTextNode(`${c}
752
+ `));
753
+ } else {
754
+ const c = Array.from(r.styleSheets).filter((f) => {
755
+ try {
756
+ return "cssRules" in f && !!f.cssRules.length;
757
+ } catch (g) {
758
+ return t.log.warn(`Error while reading CSS rules from ${f.href}`, g), !1;
759
+ }
760
+ }), u = r.implementation.createHTMLDocument(""), l = u.createElement("style");
761
+ u.head.appendChild(l);
762
+ const h = l.sheet;
763
+ await Promise.all(
764
+ c.flatMap((f) => Array.from(f.cssRules).map(async (g) => {
765
+ if (he(g)) {
766
+ const d = g.href;
767
+ let p = "";
768
+ try {
769
+ p = await I(t, {
770
+ url: d,
771
+ requestType: "text",
772
+ responseType: "text"
773
+ });
774
+ } catch (S) {
775
+ t.log.warn(`Error fetch remote css import from ${d}`, S);
776
+ }
777
+ const y = p.replace(
778
+ ue,
779
+ (S, w, b) => S.replace(b, ee(b, d))
780
+ );
781
+ for (const S of dt(y))
782
+ try {
783
+ h.insertRule(S, h.cssRules.length);
784
+ } catch (w) {
785
+ t.log.warn("Error inserting rule from remote css import", { rule: S, error: w });
786
+ }
787
+ }
788
+ }))
789
+ ), h.cssRules.length && c.push(h);
790
+ const m = [];
791
+ c.forEach((f) => {
792
+ L(f.cssRules, m);
793
+ }), m.filter((f) => {
794
+ var g;
795
+ return ge(f) && ce(f.style.getPropertyValue("src")) && ((g = re(f.style.getPropertyValue("font-family"))) == null ? void 0 : g.some((d) => i.has(d)));
796
+ }).forEach((f) => {
797
+ const g = f, d = o.get(g.cssText);
798
+ d ? n.appendChild(r.createTextNode(`${d}
799
+ `)) : a.push(
800
+ le(
801
+ g.cssText,
802
+ g.parentStyleSheet ? g.parentStyleSheet.href : null,
803
+ t
804
+ ).then((p) => {
805
+ p = K(p, t), o.set(g.cssText, p), n.appendChild(r.createTextNode(`${p}
806
+ `));
807
+ })
808
+ );
809
+ });
810
+ }
811
+ }
812
+ const ft = /(\/\*[\s\S]*?\*\/)/g, G = /((@.*?keyframes [\s\S]*?){([\s\S]*?}\s*?)})/gi;
813
+ function dt(e) {
814
+ if (e == null)
815
+ return [];
816
+ const t = [];
817
+ let r = e.replace(ft, "");
818
+ for (; ; ) {
819
+ const o = G.exec(r);
820
+ if (!o)
821
+ break;
822
+ t.push(o[0]);
823
+ }
824
+ r = r.replace(G, "");
825
+ const n = /@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi, i = new RegExp(
826
+ // eslint-disable-next-line
827
+ "((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",
828
+ "gi"
829
+ );
830
+ for (; ; ) {
831
+ let o = n.exec(r);
832
+ if (o)
833
+ i.lastIndex = n.lastIndex;
834
+ else if (o = i.exec(r), o)
835
+ n.lastIndex = i.lastIndex;
836
+ else
837
+ break;
838
+ t.push(o[0]);
839
+ }
840
+ return t;
841
+ }
842
+ const mt = /url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g, gt = /src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;
843
+ function K(e, t) {
844
+ const { font: r } = t, n = r ? r == null ? void 0 : r.preferredFormat : void 0;
845
+ return n ? e.replace(gt, (i) => {
846
+ for (; ; ) {
847
+ const [o, , a] = mt.exec(i) || [];
848
+ if (!a)
849
+ return "";
850
+ if (a === n)
851
+ return `src: ${o};`;
852
+ }
853
+ }) : e;
854
+ }
855
+ function L(e, t = []) {
856
+ for (const r of Array.from(e))
857
+ pe(r) ? t.push(...L(r.cssRules)) : "cssRules" in r ? L(r.cssRules, t) : t.push(r);
858
+ return t;
859
+ }
860
+ const ht = /\bx?link:?href\s*=\s*["'](?!data:)[^"']+["']/i;
861
+ function pt(e) {
862
+ return ht.test(e.innerHTML);
863
+ }
864
+ async function wt(e, t) {
865
+ const r = await ne(e, t);
866
+ if (v(r.node) && _(r.node) && !pt(r.node))
867
+ return r.node;
868
+ const {
869
+ ownerDocument: n,
870
+ log: i,
871
+ tasks: o,
872
+ svgStyleElement: a,
873
+ svgDefsElement: s,
874
+ svgStyles: c,
875
+ font: u,
876
+ progress: l,
877
+ autoDestruct: h,
878
+ onCloneNode: m,
879
+ onEmbedNode: f,
880
+ onCreateForeignObjectSvg: g
881
+ } = r;
882
+ i.time("clone node");
883
+ const d = await W(r.node, r, !0);
884
+ if (a && n) {
885
+ let b = "";
886
+ c.forEach((E, C) => {
887
+ b += `${E.join(`,
888
+ `)} {
889
+ ${C}
890
+ }
891
+ `;
892
+ }), a.appendChild(n.createTextNode(b));
893
+ }
894
+ i.timeEnd("clone node"), await (m == null ? void 0 : m(d)), u !== !1 && v(d) && (i.time("embed web font"), await ut(d, r), i.timeEnd("embed web font")), i.time("embed node"), fe(d, r);
895
+ const p = o.length;
896
+ let y = 0;
897
+ const S = async () => {
898
+ for (; ; ) {
899
+ const b = o.pop();
900
+ if (!b)
901
+ break;
902
+ try {
903
+ await b;
904
+ } catch (E) {
905
+ r.log.warn("Failed to run task", E);
906
+ }
907
+ l == null || l(++y, p);
908
+ }
909
+ };
910
+ l == null || l(y, p), await Promise.all([...Array.from({ length: 4 })].map(S)), i.timeEnd("embed node"), await (f == null ? void 0 : f(d));
911
+ const w = yt(d, r);
912
+ return s && w.insertBefore(s, w.children[0]), a && w.insertBefore(a, w.children[0]), h && rt(r), await (g == null ? void 0 : g(w)), w;
913
+ }
914
+ function yt(e, t) {
915
+ const { width: r, height: n } = t, i = _e(r, n, e.ownerDocument), o = i.ownerDocument.createElementNS(i.namespaceURI, "foreignObject");
916
+ return o.setAttributeNS(null, "x", "0%"), o.setAttributeNS(null, "y", "0%"), o.setAttributeNS(null, "width", "100%"), o.setAttributeNS(null, "height", "100%"), o.append(e), i.appendChild(o), i;
917
+ }
918
+ async function St(e, t) {
919
+ var a;
920
+ const r = await ne(e, t), n = await wt(r), i = Fe(n, r.isEnable("removeControlCharacter"));
921
+ r.autoDestruct || (r.svgStyleElement = se(r.ownerDocument), r.svgDefsElement = (a = r.ownerDocument) == null ? void 0 : a.createElementNS(x, "defs"), r.svgStyles.clear());
922
+ const o = N(i, n.ownerDocument);
923
+ return await Be(o, r);
924
+ }
925
+ const B = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new WeakMap();
926
+ function Et(e = document.body) {
927
+ B.delete(e), D.delete(e);
928
+ }
929
+ async function bt(e, t, r) {
930
+ const n = B.get(e);
931
+ if (n && n.scale === t) return n.full;
932
+ let i = D.get(e);
933
+ return i || (i = (async () => {
934
+ try {
935
+ const o = await St(e, {
936
+ scale: t,
937
+ backgroundColor: null,
938
+ filter: (a) => !(a === r || a instanceof Element && r.contains(a))
939
+ });
940
+ return B.set(e, { full: o, scale: t }), o;
941
+ } catch {
942
+ return null;
943
+ } finally {
944
+ D.delete(e);
945
+ }
946
+ })(), D.set(e, i)), i;
947
+ }
948
+ async function Ct(e) {
949
+ const { surface: t, host: r = document.body, scale: n = window.devicePixelRatio || 1 } = e, i = await bt(r, n, t);
950
+ if (!i) return null;
951
+ const o = t.getBoundingClientRect(), a = Math.max(1, Math.round(o.width)), s = Math.max(1, Math.round(o.height)), c = document.createElement("canvas");
952
+ c.width = a, c.height = s;
953
+ const u = c.getContext("2d");
954
+ return u ? (u.filter = "blur(4px) saturate(1.3)", u.drawImage(
955
+ i,
956
+ Math.round(o.left * n),
957
+ Math.round(o.top * n),
958
+ Math.round(a * n),
959
+ Math.round(s * n),
960
+ 0,
961
+ 0,
962
+ a,
963
+ s
964
+ ), u.filter = "none", { canvas: c, width: a, height: s }) : null;
965
+ }
966
+ export {
967
+ Ct as captureBehind,
968
+ Et as invalidateCaptureCache
969
+ };
970
+ //# sourceMappingURL=captureBehind-DUL_bR7u.js.map