@unicom-cloud/utils 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/filesize/src/constants.js +22 -22
- package/filesize/src/filesize.js +32 -33
- package/package.json +1 -1
- package/snapdom/src/api/preCache.js +23 -23
- package/snapdom/src/api/snapdom.js +67 -63
- package/snapdom/src/core/cache.js +19 -8
- package/snapdom/src/core/capture.js +46 -45
- package/snapdom/src/core/clone.js +94 -31
- package/snapdom/src/core/prepare.js +35 -38
- package/snapdom/src/modules/background.js +29 -20
- package/snapdom/src/modules/fonts.js +93 -101
- package/snapdom/src/modules/pseudo.js +70 -75
- package/snapdom/src/modules/styles.js +22 -22
- package/snapdom/src/utils/cssTools.js +41 -41
- package/snapdom/src/utils/helpers.js +143 -146
- package/tree/index.js +1 -1
- package/tree/search/index.js +90 -0
- package/tree.js +1 -1
- package/types/filesize/src/constants.d.ts +12 -12
- package/types/filesize/src/filesize.d.ts +63 -22
- package/types/snapdom/src/core/cache.d.ts +17 -11
- package/types/snapdom/src/core/capture.d.ts +4 -0
- package/types/snapdom/src/core/clone.d.ts +4 -5
- package/types/snapdom/src/core/prepare.d.ts +8 -1
- package/types/snapdom/src/modules/background.d.ts +1 -2
- package/types/snapdom/src/modules/pseudo.d.ts +1 -3
- package/types/snapdom/src/modules/styles.d.ts +1 -1
- package/types/snapdom/src/utils/cssTools.d.ts +1 -2
- package/types/tree/index.d.ts +1 -1
- package/types/tree/search/index.d.ts +80 -0
- package/types/ui-color/index.d.ts +28 -3
- package/ui-color/index.js +70 -63
- package/uiColor.js +19 -18
- package/tree/searchTree.js +0 -54
- package/types/tree/searchTree.d.ts +0 -20
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const t = "
|
|
1
|
+
const t = "Invalid number", i = "Invalid rounding method", b = "iec", o = "jedec", n = "si", s = "bit", c = "bits", e = "byte", B = "bytes", E = "kbit", I = "kB", T = "array", a = "function", N = "object", S = "string", r = "exponent", R = "round", Y = "", d = ".", y = "s", P = " ", O = "0", g = {
|
|
2
2
|
symbol: {
|
|
3
3
|
iec: {
|
|
4
4
|
bits: [
|
|
@@ -45,27 +45,27 @@ const t = "array", i = "bit", b = "bits", o = "byte", n = "bytes", s = "", c = "
|
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
export {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
48
|
+
T as ARRAY,
|
|
49
|
+
s as BIT,
|
|
50
|
+
c as BITS,
|
|
51
|
+
e as BYTE,
|
|
52
|
+
B as BYTES,
|
|
53
|
+
Y as EMPTY,
|
|
54
|
+
r as EXPONENT,
|
|
55
|
+
a as FUNCTION,
|
|
56
|
+
b as IEC,
|
|
57
|
+
t as INVALID_NUMBER,
|
|
58
|
+
i as INVALID_ROUND,
|
|
59
|
+
o as JEDEC,
|
|
60
|
+
N as OBJECT,
|
|
61
|
+
d as PERIOD,
|
|
62
|
+
R as ROUND,
|
|
63
|
+
y as S,
|
|
64
|
+
n as SI,
|
|
65
|
+
E as SI_KBIT,
|
|
66
|
+
I as SI_KBYTE,
|
|
67
|
+
P as SPACE,
|
|
68
|
+
S as STRING,
|
|
69
69
|
g as STRINGS,
|
|
70
70
|
O as ZERO
|
|
71
71
|
};
|
package/filesize/src/filesize.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { INVALID_NUMBER as
|
|
2
|
-
function
|
|
1
|
+
import { INVALID_NUMBER as s, FUNCTION as z, INVALID_ROUND as X, STRING as G, EXPONENT as Z, STRINGS as O, EMPTY as t, BITS as $, BYTES as v, SI_KBIT as k, SI_KBYTE as q, PERIOD as x, ZERO as H, BIT as Q, BYTE as W, S as b, ARRAY as a, OBJECT as d, SPACE as J, ROUND as K, SI as f0, JEDEC as A, IEC as F } from "./constants.js";
|
|
2
|
+
function i0(I, {
|
|
3
3
|
bits: o = !1,
|
|
4
4
|
pad: M = !1,
|
|
5
5
|
base: l = -1,
|
|
@@ -7,40 +7,40 @@ function e0(I, {
|
|
|
7
7
|
locale: T = t,
|
|
8
8
|
localeOptions: R = {},
|
|
9
9
|
separator: h = t,
|
|
10
|
-
spacer: B =
|
|
10
|
+
spacer: B = J,
|
|
11
11
|
symbols: c = {},
|
|
12
|
-
standard:
|
|
13
|
-
output: g =
|
|
12
|
+
standard: e = t,
|
|
13
|
+
output: g = G,
|
|
14
14
|
fullform: w = !1,
|
|
15
|
-
fullforms:
|
|
16
|
-
exponent:
|
|
17
|
-
roundingMethod: y =
|
|
15
|
+
fullforms: p = [],
|
|
16
|
+
exponent: u = -1,
|
|
17
|
+
roundingMethod: y = K,
|
|
18
18
|
precision: E = 0
|
|
19
19
|
} = {}) {
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
const m = l === 10 ? 1e3 : 1024,
|
|
20
|
+
let i = u, N = Number(I), f = [], n = 0, D = t;
|
|
21
|
+
e === f0 ? (l = 10, e = A) : e === F || e === A ? l = 2 : l === 2 ? e = F : (l = 10, e = A);
|
|
22
|
+
const m = l === 10 ? 1e3 : 1024, V = w === !0, C = N < 0, P = Math[y];
|
|
23
23
|
if (typeof I != "bigint" && isNaN(I))
|
|
24
|
-
throw new TypeError(
|
|
24
|
+
throw new TypeError(s);
|
|
25
25
|
if (typeof P !== z)
|
|
26
26
|
throw new TypeError(X);
|
|
27
|
-
if (C && (N = -N), (
|
|
28
|
-
return
|
|
27
|
+
if (C && (N = -N), (i === -1 || isNaN(i)) && (i = Math.floor(Math.log(N) / Math.log(m)), i < 0 && (i = 0)), i > 8 && (E > 0 && (E += 8 - i), i = 8), g === Z)
|
|
28
|
+
return i;
|
|
29
29
|
if (N === 0)
|
|
30
|
-
f[0] = 0, D = f[1] = O.symbol[
|
|
30
|
+
f[0] = 0, D = f[1] = O.symbol[e][o ? $ : v][i];
|
|
31
31
|
else {
|
|
32
|
-
n = N / (l === 2 ? Math.pow(2,
|
|
33
|
-
const r = Math.pow(10,
|
|
34
|
-
f[0] = P(n * r) / r, f[0] === m &&
|
|
32
|
+
n = N / (l === 2 ? Math.pow(2, i * 10) : Math.pow(1e3, i)), o && (n = n * 8, n >= m && i < 8 && (n = n / m, i++));
|
|
33
|
+
const r = Math.pow(10, i > 0 ? S : 0);
|
|
34
|
+
f[0] = P(n * r) / r, f[0] === m && i < 8 && u === -1 && (f[0] = 1, i++), D = f[1] = l === 10 && i === 1 ? o ? k : q : O.symbol[e][o ? $ : v][i];
|
|
35
35
|
}
|
|
36
|
-
if (C && (f[0] = -f[0]), E > 0 && (f[0] = f[0].toPrecision(E)), f[1] = c[f[1]] || f[1], T === !0 ? f[0] = f[0].toLocaleString() : T.length > 0 ? f[0] = f[0].toLocaleString(T, R) : h.length > 0 && (f[0] = f[0].toString().replace(
|
|
37
|
-
const r = f[0].toString(), Y = h || (r.match(/(\D)/g) || []).pop() ||
|
|
38
|
-
f[0] = `${L[0]}${Y}${U.padEnd(_ +
|
|
36
|
+
if (C && (f[0] = -f[0]), E > 0 && (f[0] = f[0].toPrecision(E)), f[1] = c[f[1]] || f[1], T === !0 ? f[0] = f[0].toLocaleString() : T.length > 0 ? f[0] = f[0].toLocaleString(T, R) : h.length > 0 && (f[0] = f[0].toString().replace(x, h)), M && S > 0) {
|
|
37
|
+
const r = f[0].toString(), Y = h || (r.match(/(\D)/g) || []).pop() || x, L = r.toString().split(Y), U = L[1] || t, _ = U.length, j = S - _;
|
|
38
|
+
f[0] = `${L[0]}${Y}${U.padEnd(_ + j, H)}`;
|
|
39
39
|
}
|
|
40
|
-
return
|
|
40
|
+
return V && (f[1] = p[i] ? p[i] : O.fullform[e][i] + (o ? Q : W) + (f[0] === 1 ? t : b)), g === a ? f : g === d ? {
|
|
41
41
|
value: f[0],
|
|
42
42
|
symbol: f[1],
|
|
43
|
-
exponent:
|
|
43
|
+
exponent: i,
|
|
44
44
|
unit: D
|
|
45
45
|
} : f.join(B);
|
|
46
46
|
}
|
|
@@ -52,17 +52,17 @@ function l0({
|
|
|
52
52
|
locale: S = t,
|
|
53
53
|
localeOptions: T = {},
|
|
54
54
|
separator: R = t,
|
|
55
|
-
spacer: h =
|
|
55
|
+
spacer: h = J,
|
|
56
56
|
symbols: B = {},
|
|
57
57
|
standard: c = t,
|
|
58
|
-
output:
|
|
58
|
+
output: e = G,
|
|
59
59
|
fullform: g = !1,
|
|
60
60
|
fullforms: w = [],
|
|
61
|
-
exponent:
|
|
62
|
-
roundingMethod:
|
|
61
|
+
exponent: p = -1,
|
|
62
|
+
roundingMethod: u = K,
|
|
63
63
|
precision: y = 0
|
|
64
64
|
} = {}) {
|
|
65
|
-
return (E) =>
|
|
65
|
+
return (E) => i0(E, {
|
|
66
66
|
bits: I,
|
|
67
67
|
pad: o,
|
|
68
68
|
base: M,
|
|
@@ -73,16 +73,15 @@ function l0({
|
|
|
73
73
|
spacer: h,
|
|
74
74
|
symbols: B,
|
|
75
75
|
standard: c,
|
|
76
|
-
output:
|
|
76
|
+
output: e,
|
|
77
77
|
fullform: g,
|
|
78
78
|
fullforms: w,
|
|
79
|
-
exponent:
|
|
80
|
-
roundingMethod:
|
|
79
|
+
exponent: p,
|
|
80
|
+
roundingMethod: u,
|
|
81
81
|
precision: y
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
export {
|
|
85
|
-
|
|
86
|
-
e0 as filesize,
|
|
85
|
+
i0 as filesize,
|
|
87
86
|
l0 as partial
|
|
88
87
|
};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@unicom-cloud/utils","version":"0.1.
|
|
1
|
+
{"name":"@unicom-cloud/utils","version":"0.1.14","dependencies":{},"peerDependencies":{"lodash":"^4.17.21"},"main":"./index.js","type":"module","types":"types/index.d.ts","publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"}}
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { embedCustomFonts as
|
|
3
|
-
import { precacheCommonTags as
|
|
4
|
-
import { fetchImage as
|
|
5
|
-
async function
|
|
6
|
-
const { embedFonts:
|
|
1
|
+
import { cache as a } from "../core/cache.js";
|
|
2
|
+
import { embedCustomFonts as u } from "../modules/fonts.js";
|
|
3
|
+
import { precacheCommonTags as g } from "../utils/cssTools.js";
|
|
4
|
+
import { fetchImage as h, getStyle as y, splitBackgroundImage as p, inlineSingleBackgroundEntry as d } from "../utils/helpers.js";
|
|
5
|
+
async function q(r = document, t = {}) {
|
|
6
|
+
const { embedFonts: l = !0, reset: f = !1 } = t;
|
|
7
7
|
if (f) {
|
|
8
|
-
|
|
8
|
+
a.reset();
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
await document.fonts.ready,
|
|
12
|
-
let
|
|
13
|
-
r?.querySelectorAll && (
|
|
14
|
-
const
|
|
15
|
-
for (const
|
|
16
|
-
const e =
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
await document.fonts.ready, g();
|
|
12
|
+
let n = [], i = [];
|
|
13
|
+
r?.querySelectorAll && (n = Array.from(r.querySelectorAll("img[src]")), i = Array.from(r.querySelectorAll("*")));
|
|
14
|
+
const o = [];
|
|
15
|
+
for (const s of n) {
|
|
16
|
+
const e = s.src;
|
|
17
|
+
a.image.has(e) || o.push(
|
|
18
|
+
h(e, { useProxy: t.useProxy }).then((c) => a.image.set(e, c)).catch(() => {
|
|
19
19
|
})
|
|
20
20
|
);
|
|
21
21
|
}
|
|
22
|
-
for (const
|
|
23
|
-
const e =
|
|
22
|
+
for (const s of i) {
|
|
23
|
+
const e = y(s).backgroundImage;
|
|
24
24
|
if (e && e !== "none") {
|
|
25
|
-
const
|
|
26
|
-
for (const
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const c = p(e);
|
|
26
|
+
for (const m of c)
|
|
27
|
+
m.startsWith("url(") && o.push(
|
|
28
|
+
d(m, t).catch(() => {
|
|
29
29
|
})
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
l && await u({ preCached: !0 }), await Promise.all(o);
|
|
34
34
|
}
|
|
35
35
|
export {
|
|
36
|
-
|
|
36
|
+
q as preCache
|
|
37
37
|
};
|
|
@@ -1,109 +1,113 @@
|
|
|
1
1
|
import { captureDOM as v } from "../core/capture.js";
|
|
2
|
-
import { extendIconFonts as
|
|
3
|
-
import { isSafari as
|
|
4
|
-
async function
|
|
2
|
+
import { extendIconFonts as j } from "../modules/iconFonts.js";
|
|
3
|
+
import { isSafari as R } from "../utils/helpers.js";
|
|
4
|
+
async function B(a, { dpr: t = 1, scale: o = 1 }) {
|
|
5
5
|
const e = new Image();
|
|
6
|
-
return e.src = a, await e.decode(),
|
|
6
|
+
return e.src = a, await e.decode(), e.width = e.width * o, e.height = e.height * o, e;
|
|
7
7
|
}
|
|
8
|
-
async function
|
|
8
|
+
async function f(a, { dpr: t = 1, scale: o = 1 } = {}) {
|
|
9
9
|
const e = new Image();
|
|
10
|
-
e.src = a,
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
e.src = a, e.crossOrigin = "anonymous", e.loading = "eager", e.decoding = "sync";
|
|
11
|
+
const c = R();
|
|
12
|
+
let n = !1;
|
|
13
|
+
if (c && (document.body.appendChild(e), n = !0), await e.decode(), c && await new Promise((w) => setTimeout(w, 100)), e.width === 0 || e.height === 0)
|
|
14
|
+
throw n && e.remove(), new Error("Image failed to load or has no dimensions");
|
|
15
|
+
const s = e.width * o, r = e.height * o, g = document.createElement("canvas");
|
|
16
|
+
g.width = Math.ceil(s * t), g.height = Math.ceil(r * t), g.style.width = `${s}px`, g.style.height = `${r}px`;
|
|
17
|
+
const d = g.getContext("2d");
|
|
18
|
+
return d.scale(t, t), d.drawImage(e, 0, 0, s, r), n && e.remove(), g;
|
|
15
19
|
}
|
|
16
|
-
async function
|
|
17
|
-
const
|
|
20
|
+
async function b(a, { type: t = "svg", scale: o = 1, backgroundColor: e = "#fff", quality: c } = {}) {
|
|
21
|
+
const n = {
|
|
18
22
|
jpg: "image/jpeg",
|
|
19
23
|
jpeg: "image/jpeg",
|
|
20
24
|
png: "image/png",
|
|
21
25
|
webp: "image/webp"
|
|
22
26
|
}[t] || "image/png";
|
|
23
27
|
if (t === "svg") {
|
|
24
|
-
const
|
|
25
|
-
return new Blob([
|
|
28
|
+
const r = decodeURIComponent(a.split(",")[1]);
|
|
29
|
+
return new Blob([r], { type: "image/svg+xml" });
|
|
26
30
|
}
|
|
27
|
-
const
|
|
31
|
+
const s = await u(
|
|
28
32
|
a,
|
|
29
33
|
{ dpr: 1, scale: o },
|
|
30
34
|
e
|
|
31
35
|
);
|
|
32
|
-
return new Promise((
|
|
33
|
-
|
|
36
|
+
return new Promise((r) => {
|
|
37
|
+
s.toBlob((g) => r(g), `${n}`, c);
|
|
34
38
|
});
|
|
35
39
|
}
|
|
36
|
-
async function
|
|
37
|
-
const
|
|
38
|
-
if (!e) return
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
return
|
|
40
|
+
async function u(a, { dpr: t = 1, scale: o = 1 }, e) {
|
|
41
|
+
const c = await f(a, { dpr: t, scale: o });
|
|
42
|
+
if (!e) return c;
|
|
43
|
+
const n = document.createElement("canvas");
|
|
44
|
+
n.width = c.width, n.height = c.height;
|
|
45
|
+
const s = n.getContext("2d");
|
|
46
|
+
return s.fillStyle = e, s.fillRect(0, 0, n.width, n.height), s.drawImage(c, 0, 0), n;
|
|
43
47
|
}
|
|
44
|
-
async function
|
|
45
|
-
const
|
|
46
|
-
return
|
|
48
|
+
async function l(a, { dpr: t = 1, scale: o = 1, backgroundColor: e, quality: c }, n = "png") {
|
|
49
|
+
const s = ["jpg", "jpeg", "webp"].includes(n) ? "#fff" : void 0, g = await u(a, { dpr: t, scale: o }, e ?? s), d = new Image();
|
|
50
|
+
return d.src = g.toDataURL(`image/${n}`, c), await d.decode(), d.style.width = `${g.width / t}px`, d.style.height = `${g.height / t}px`, d;
|
|
47
51
|
}
|
|
48
|
-
async function
|
|
52
|
+
async function x(a, {
|
|
49
53
|
dpr: t = 1,
|
|
50
54
|
scale: o = 1,
|
|
51
|
-
backgroundColor: e
|
|
52
|
-
format:
|
|
53
|
-
filename:
|
|
55
|
+
backgroundColor: e,
|
|
56
|
+
format: c = "png",
|
|
57
|
+
filename: n = "snapDOM"
|
|
54
58
|
} = {}) {
|
|
55
|
-
if (
|
|
56
|
-
const y = await
|
|
57
|
-
|
|
59
|
+
if (c === "svg") {
|
|
60
|
+
const y = await b(a), h = URL.createObjectURL(y), m = document.createElement("a");
|
|
61
|
+
m.href = h, m.download = `${n}.svg`, m.click(), URL.revokeObjectURL(h);
|
|
58
62
|
return;
|
|
59
63
|
}
|
|
60
|
-
const
|
|
64
|
+
const s = ["jpg", "jpeg", "webp"].includes(c) ? "#fff" : void 0, g = await u(a, { dpr: t, scale: o }, e ?? s), d = {
|
|
61
65
|
jpg: "image/jpeg",
|
|
62
66
|
jpeg: "image/jpeg",
|
|
63
67
|
png: "image/png",
|
|
64
68
|
webp: "image/webp"
|
|
65
|
-
}[
|
|
66
|
-
|
|
69
|
+
}[c] || "image/png", w = g.toDataURL(d), p = document.createElement("a");
|
|
70
|
+
p.href = w, p.download = `${n}.${c}`, p.click();
|
|
67
71
|
}
|
|
68
|
-
async function
|
|
72
|
+
async function i(a, t = {}) {
|
|
69
73
|
if (t = { scale: 1, ...t }, !a) throw new Error("Element cannot be null or undefined");
|
|
70
|
-
return t.iconFonts &&
|
|
74
|
+
return t.iconFonts && j(t.iconFonts), await i.capture(a, t);
|
|
71
75
|
}
|
|
72
|
-
|
|
73
|
-
const o = await v(a, t), e = window.devicePixelRatio || 1,
|
|
76
|
+
i.capture = async (a, t = {}) => {
|
|
77
|
+
const o = await v(a, t), e = window.devicePixelRatio || 1, c = t.scale || 1;
|
|
74
78
|
return {
|
|
75
79
|
url: o,
|
|
76
80
|
options: t,
|
|
77
81
|
toRaw: () => o,
|
|
78
|
-
toImg: () =>
|
|
79
|
-
toCanvas: () =>
|
|
80
|
-
toBlob: (
|
|
81
|
-
toPng: (
|
|
82
|
-
toJpg: (
|
|
83
|
-
toWebp: (
|
|
82
|
+
toImg: () => B(o, { dpr: e, scale: c }),
|
|
83
|
+
toCanvas: () => f(o, { dpr: e, scale: c }),
|
|
84
|
+
toBlob: (n) => b(o, { scale: c, ...n }),
|
|
85
|
+
toPng: (n) => l(o, { dpr: e, scale: c, ...n }, "png"),
|
|
86
|
+
toJpg: (n) => l(o, { dpr: e, scale: c, ...n }, "jpeg"),
|
|
87
|
+
toWebp: (n) => l(o, { dpr: e, scale: c, ...n }, "webp"),
|
|
84
88
|
download: ({
|
|
85
|
-
format:
|
|
86
|
-
filename:
|
|
87
|
-
backgroundColor:
|
|
88
|
-
} = {}) =>
|
|
89
|
+
format: n = "png",
|
|
90
|
+
filename: s = "capture",
|
|
91
|
+
backgroundColor: r
|
|
92
|
+
} = {}) => x(o, { dpr: e, scale: c, backgroundColor: r, format: n, filename: s })
|
|
89
93
|
};
|
|
90
94
|
};
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
i.toRaw = async (a, t) => (await i.capture(a, t)).toRaw();
|
|
96
|
+
i.toImg = async (a, t) => (await i.capture(a, t)).toImg();
|
|
97
|
+
i.toCanvas = async (a, t) => (await i.capture(a, t)).toCanvas();
|
|
98
|
+
i.toBlob = async (a, t) => (await i.capture(a, t)).toBlob(t);
|
|
99
|
+
i.toPng = async (a, t) => (await i.capture(a, t)).toPng(t);
|
|
100
|
+
i.toJpg = async (a, t) => (await i.capture(a, t)).toJpg(t);
|
|
101
|
+
i.toWebp = async (a, t) => (await i.capture(a, t)).toWebp(t);
|
|
102
|
+
i.download = async (a, t = {}) => {
|
|
99
103
|
const {
|
|
100
104
|
format: o = "png",
|
|
101
105
|
filename: e = "capture",
|
|
102
|
-
backgroundColor:
|
|
103
|
-
...
|
|
106
|
+
backgroundColor: c,
|
|
107
|
+
...n
|
|
104
108
|
} = t;
|
|
105
|
-
return await (await
|
|
109
|
+
return await (await i.capture(a, n)).download({ format: o, filename: e, backgroundColor: c });
|
|
106
110
|
};
|
|
107
111
|
export {
|
|
108
|
-
|
|
112
|
+
i as snapdom
|
|
109
113
|
};
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
const e =
|
|
1
|
+
const e = {
|
|
2
|
+
image: /* @__PURE__ */ new Map(),
|
|
3
|
+
background: /* @__PURE__ */ new Map(),
|
|
4
|
+
resource: /* @__PURE__ */ new Map(),
|
|
5
|
+
defaultStyle: /* @__PURE__ */ new Map(),
|
|
6
|
+
baseStyle: /* @__PURE__ */ new Map(),
|
|
7
|
+
computedStyle: /* @__PURE__ */ new WeakMap(),
|
|
8
|
+
font: /* @__PURE__ */ new Set(),
|
|
9
|
+
snapshot: /* @__PURE__ */ new WeakMap(),
|
|
10
|
+
snapshotKey: /* @__PURE__ */ new Map(),
|
|
11
|
+
preStyleMap: /* @__PURE__ */ new Map(),
|
|
12
|
+
preStyle: /* @__PURE__ */ new WeakMap(),
|
|
13
|
+
preNodeMap: /* @__PURE__ */ new Map(),
|
|
14
|
+
reset: a
|
|
15
|
+
};
|
|
16
|
+
function a() {
|
|
17
|
+
e.computedStyle = /* @__PURE__ */ new WeakMap(), e.snapshot = /* @__PURE__ */ new WeakMap(), e.snapshotKey.clear(), e.preStyleMap.clear(), e.preStyle = /* @__PURE__ */ new WeakMap(), e.preNodeMap.clear();
|
|
18
|
+
}
|
|
2
19
|
export {
|
|
3
|
-
|
|
4
|
-
a as bgCache,
|
|
5
|
-
s as computedStyleCache,
|
|
6
|
-
n as defaultStylesCache,
|
|
7
|
-
e as imageCache,
|
|
8
|
-
o as processedFontURLs,
|
|
9
|
-
c as resourceCache
|
|
20
|
+
e as cache
|
|
10
21
|
};
|
|
@@ -1,54 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { inlineBackgroundImages as
|
|
3
|
-
import { embedCustomFonts as
|
|
4
|
-
import { inlineImages as
|
|
5
|
-
import { collectUsedTagNames as
|
|
6
|
-
import { idle as c
|
|
7
|
-
import { prepareClone as
|
|
8
|
-
async function
|
|
1
|
+
import { cache as h } from "./cache.js";
|
|
2
|
+
import { inlineBackgroundImages as H } from "../modules/background.js";
|
|
3
|
+
import { embedCustomFonts as I } from "../modules/fonts.js";
|
|
4
|
+
import { inlineImages as M } from "../modules/images.js";
|
|
5
|
+
import { collectUsedTagNames as A, generateDedupedBaseCSS as O } from "../utils/cssTools.js";
|
|
6
|
+
import { idle as c } from "../utils/helpers.js";
|
|
7
|
+
import { prepareClone as R } from "./prepare.js";
|
|
8
|
+
async function J(l, t = {}) {
|
|
9
9
|
if (!l) throw new Error("Element cannot be null or undefined");
|
|
10
|
+
h.reset();
|
|
10
11
|
const {
|
|
11
|
-
compress:
|
|
12
|
+
compress: u = !0,
|
|
12
13
|
embedFonts: b = !1,
|
|
13
|
-
fast:
|
|
14
|
-
scale:
|
|
15
|
-
useProxy:
|
|
16
|
-
} =
|
|
17
|
-
let
|
|
18
|
-
if ({ clone:
|
|
14
|
+
fast: n = !0,
|
|
15
|
+
scale: S = 1,
|
|
16
|
+
useProxy: U = ""
|
|
17
|
+
} = t;
|
|
18
|
+
let a, y, p = "", m = "", v, x;
|
|
19
|
+
if ({ clone: a, classCSS: y } = await R(
|
|
19
20
|
l,
|
|
20
|
-
|
|
21
|
+
u,
|
|
21
22
|
b,
|
|
22
|
-
|
|
23
|
+
t
|
|
23
24
|
), await new Promise((s) => {
|
|
24
25
|
c(
|
|
25
26
|
async () => {
|
|
26
|
-
await
|
|
27
|
+
await M(a, t), s();
|
|
27
28
|
},
|
|
28
|
-
{ fast:
|
|
29
|
+
{ fast: n }
|
|
29
30
|
);
|
|
30
31
|
}), await new Promise((s) => {
|
|
31
32
|
c(
|
|
32
33
|
async () => {
|
|
33
|
-
await
|
|
34
|
+
await H(l, a, t), s();
|
|
34
35
|
},
|
|
35
|
-
{ fast:
|
|
36
|
+
{ fast: n }
|
|
36
37
|
);
|
|
37
38
|
}), b && await new Promise((s) => {
|
|
38
39
|
c(
|
|
39
40
|
async () => {
|
|
40
|
-
|
|
41
|
+
p = await I(), s();
|
|
41
42
|
},
|
|
42
|
-
{ fast:
|
|
43
|
+
{ fast: n }
|
|
43
44
|
);
|
|
44
|
-
}),
|
|
45
|
-
const s =
|
|
46
|
-
|
|
45
|
+
}), u) {
|
|
46
|
+
const s = A(a).sort(), i = s.join(",");
|
|
47
|
+
h.baseStyle.has(i) ? m = h.baseStyle.get(i) : await new Promise((e) => {
|
|
47
48
|
c(
|
|
48
49
|
() => {
|
|
49
|
-
m =
|
|
50
|
+
m = O(s), h.baseStyle.set(i, m), e();
|
|
50
51
|
},
|
|
51
|
-
{ fast:
|
|
52
|
+
{ fast: n }
|
|
52
53
|
);
|
|
53
54
|
});
|
|
54
55
|
}
|
|
@@ -56,29 +57,29 @@ async function V(l, a = {}) {
|
|
|
56
57
|
c(
|
|
57
58
|
() => {
|
|
58
59
|
const i = l.getBoundingClientRect();
|
|
59
|
-
let e = i.width,
|
|
60
|
-
const
|
|
61
|
-
if (!
|
|
60
|
+
let e = i.width, r = i.height;
|
|
61
|
+
const d = Number.isFinite(t.width), f = Number.isFinite(t.height), C = typeof S == "number" && S !== 1;
|
|
62
|
+
if (!C) {
|
|
62
63
|
const g = i.width / i.height;
|
|
63
|
-
|
|
64
|
+
d && f ? (e = t.width, r = t.height) : d ? (e = t.width, r = e / g) : f && (r = t.height, e = r * g);
|
|
64
65
|
}
|
|
65
|
-
if (e = Math.ceil(e),
|
|
66
|
-
const g = i.width,
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
const
|
|
66
|
+
if (e = Math.ceil(e), r = Math.ceil(r), a.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"), a.style.transformOrigin = "top left", !C && (d || f)) {
|
|
67
|
+
const g = i.width, T = i.height, B = e / g, E = r / T, N = a.style.transform || "", z = `scale(${B}, ${E})`;
|
|
68
|
+
a.style.transform = `${z} ${N}`.trim();
|
|
69
|
+
}
|
|
70
|
+
const $ = "http://www.w3.org/2000/svg", o = document.createElementNS($, "foreignObject");
|
|
70
71
|
o.setAttribute("width", "100%"), o.setAttribute("height", "100%");
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
72
|
+
const F = document.createElement("style");
|
|
73
|
+
F.textContent = m + p + "svg{overflow:visible;}" + y, o.appendChild(F), o.appendChild(a);
|
|
74
|
+
const P = new XMLSerializer().serializeToString(o);
|
|
75
|
+
x = `<svg xmlns="${$}" width="${e}" height="${r}" viewBox="0 0 ${e} ${r}">` + P + "</svg>", v = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(x)}`, s();
|
|
75
76
|
},
|
|
76
|
-
{ fast:
|
|
77
|
+
{ fast: n }
|
|
77
78
|
);
|
|
78
79
|
});
|
|
79
|
-
const
|
|
80
|
-
return
|
|
80
|
+
const w = document.getElementById("snapdom-sandbox");
|
|
81
|
+
return w && w.style.position === "absolute" && w.remove(), v;
|
|
81
82
|
}
|
|
82
83
|
export {
|
|
83
|
-
|
|
84
|
+
J as captureDOM
|
|
84
85
|
};
|