@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.
Files changed (35) hide show
  1. package/filesize/src/constants.js +22 -22
  2. package/filesize/src/filesize.js +32 -33
  3. package/package.json +1 -1
  4. package/snapdom/src/api/preCache.js +23 -23
  5. package/snapdom/src/api/snapdom.js +67 -63
  6. package/snapdom/src/core/cache.js +19 -8
  7. package/snapdom/src/core/capture.js +46 -45
  8. package/snapdom/src/core/clone.js +94 -31
  9. package/snapdom/src/core/prepare.js +35 -38
  10. package/snapdom/src/modules/background.js +29 -20
  11. package/snapdom/src/modules/fonts.js +93 -101
  12. package/snapdom/src/modules/pseudo.js +70 -75
  13. package/snapdom/src/modules/styles.js +22 -22
  14. package/snapdom/src/utils/cssTools.js +41 -41
  15. package/snapdom/src/utils/helpers.js +143 -146
  16. package/tree/index.js +1 -1
  17. package/tree/search/index.js +90 -0
  18. package/tree.js +1 -1
  19. package/types/filesize/src/constants.d.ts +12 -12
  20. package/types/filesize/src/filesize.d.ts +63 -22
  21. package/types/snapdom/src/core/cache.d.ts +17 -11
  22. package/types/snapdom/src/core/capture.d.ts +4 -0
  23. package/types/snapdom/src/core/clone.d.ts +4 -5
  24. package/types/snapdom/src/core/prepare.d.ts +8 -1
  25. package/types/snapdom/src/modules/background.d.ts +1 -2
  26. package/types/snapdom/src/modules/pseudo.d.ts +1 -3
  27. package/types/snapdom/src/modules/styles.d.ts +1 -1
  28. package/types/snapdom/src/utils/cssTools.d.ts +1 -2
  29. package/types/tree/index.d.ts +1 -1
  30. package/types/tree/search/index.d.ts +80 -0
  31. package/types/ui-color/index.d.ts +28 -3
  32. package/ui-color/index.js +70 -63
  33. package/uiColor.js +19 -18
  34. package/tree/searchTree.js +0 -54
  35. package/types/tree/searchTree.d.ts +0 -20
@@ -1,4 +1,4 @@
1
- const t = "array", i = "bit", b = "bits", o = "byte", n = "bytes", s = "", c = "exponent", e = "function", B = "iec", E = "Invalid number", I = "Invalid rounding method", T = "jedec", a = "object", N = ".", S = "round", r = "s", R = "si", Y = "kbit", d = "kB", y = " ", P = "string", O = "0", g = {
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
- t as ARRAY,
49
- i as BIT,
50
- b as BITS,
51
- o as BYTE,
52
- n as BYTES,
53
- s as EMPTY,
54
- c as EXPONENT,
55
- e as FUNCTION,
56
- B as IEC,
57
- E as INVALID_NUMBER,
58
- I as INVALID_ROUND,
59
- T as JEDEC,
60
- a as OBJECT,
61
- N as PERIOD,
62
- S as ROUND,
63
- r as S,
64
- R as SI,
65
- Y as SI_KBIT,
66
- d as SI_KBYTE,
67
- y as SPACE,
68
- P as STRING,
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
  };
@@ -1,5 +1,5 @@
1
- import { INVALID_NUMBER as j, FUNCTION as z, INVALID_ROUND as X, STRING as F, EXPONENT as Z, STRINGS as O, EMPTY as t, BITS as $, BYTES as s, SI_KBIT as k, SI_KBYTE as q, PERIOD as v, ZERO as H, BIT as Q, BYTE as W, S as a, ARRAY as b, OBJECT as d, SPACE as G, ROUND as J, SI as f0, JEDEC as A, IEC as x } from "./constants.js";
2
- function e0(I, {
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 = G,
10
+ spacer: B = J,
11
11
  symbols: c = {},
12
- standard: i = t,
13
- output: g = F,
12
+ standard: e = t,
13
+ output: g = G,
14
14
  fullform: w = !1,
15
- fullforms: u = [],
16
- exponent: p = -1,
17
- roundingMethod: y = J,
15
+ fullforms: p = [],
16
+ exponent: u = -1,
17
+ roundingMethod: y = K,
18
18
  precision: E = 0
19
19
  } = {}) {
20
- let e = p, N = Number(I), f = [], n = 0, D = t;
21
- i === f0 ? (l = 10, i = A) : i === x || i === A ? l = 2 : l === 2 ? i = x : (l = 10, i = A);
22
- const m = l === 10 ? 1e3 : 1024, K = w === !0, C = N < 0, P = Math[y];
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(j);
24
+ throw new TypeError(s);
25
25
  if (typeof P !== z)
26
26
  throw new TypeError(X);
27
- if (C && (N = -N), (e === -1 || isNaN(e)) && (e = Math.floor(Math.log(N) / Math.log(m)), e < 0 && (e = 0)), e > 8 && (E > 0 && (E += 8 - e), e = 8), g === Z)
28
- return e;
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[i][o ? $ : s][e];
30
+ f[0] = 0, D = f[1] = O.symbol[e][o ? $ : v][i];
31
31
  else {
32
- n = N / (l === 2 ? Math.pow(2, e * 10) : Math.pow(1e3, e)), o && (n = n * 8, n >= m && e < 8 && (n = n / m, e++));
33
- const r = Math.pow(10, e > 0 ? S : 0);
34
- f[0] = P(n * r) / r, f[0] === m && e < 8 && p === -1 && (f[0] = 1, e++), D = f[1] = l === 10 && e === 1 ? o ? k : q : O.symbol[i][o ? $ : s][e];
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(v, h)), M && S > 0) {
37
- const r = f[0].toString(), Y = h || (r.match(/(\D)/g) || []).pop() || v, L = r.toString().split(Y), U = L[1] || t, _ = U.length, V = S - _;
38
- f[0] = `${L[0]}${Y}${U.padEnd(_ + V, H)}`;
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 K && (f[1] = u[e] ? u[e] : O.fullform[i][e] + (o ? Q : W) + (f[0] === 1 ? t : a)), g === b ? f : g === d ? {
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: e,
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 = G,
55
+ spacer: h = J,
56
56
  symbols: B = {},
57
57
  standard: c = t,
58
- output: i = F,
58
+ output: e = G,
59
59
  fullform: g = !1,
60
60
  fullforms: w = [],
61
- exponent: u = -1,
62
- roundingMethod: p = J,
61
+ exponent: p = -1,
62
+ roundingMethod: u = K,
63
63
  precision: y = 0
64
64
  } = {}) {
65
- return (E) => e0(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: i,
76
+ output: e,
77
77
  fullform: g,
78
78
  fullforms: w,
79
- exponent: u,
80
- roundingMethod: p,
79
+ exponent: p,
80
+ roundingMethod: u,
81
81
  precision: y
82
82
  });
83
83
  }
84
84
  export {
85
- e0 as default,
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.12","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
+ {"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 { imageCache as s, bgCache as u, resourceCache as g, baseCSSCache as h } from "../core/cache.js";
2
- import { embedCustomFonts as y } from "../modules/fonts.js";
3
- import { precacheCommonTags as p } from "../utils/cssTools.js";
4
- import { fetchImage as d, getStyle as C, splitBackgroundImage as S, inlineSingleBackgroundEntry as b } from "../utils/helpers.js";
5
- async function E(r = document, t = {}) {
6
- const { embedFonts: m = !0, reset: f = !1 } = t;
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
- s.clear(), u.clear(), g.clear(), h.clear();
8
+ a.reset();
9
9
  return;
10
10
  }
11
- await document.fonts.ready, p();
12
- let l = [], n = [];
13
- r?.querySelectorAll && (l = Array.from(r.querySelectorAll("img[src]")), n = Array.from(r.querySelectorAll("*")));
14
- const c = [];
15
- for (const o of l) {
16
- const e = o.src;
17
- s.has(e) || c.push(
18
- d(e, { useProxy: t.useProxy }).then((a) => s.set(e, a)).catch(() => {
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 o of n) {
23
- const e = C(o).backgroundImage;
22
+ for (const s of i) {
23
+ const e = y(s).backgroundImage;
24
24
  if (e && e !== "none") {
25
- const a = S(e);
26
- for (const i of a)
27
- i.startsWith("url(") && c.push(
28
- b(i, t).catch(() => {
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
- m && await y({ preCached: !0 }), await Promise.all(c);
33
+ l && await u({ preCached: !0 }), await Promise.all(o);
34
34
  }
35
35
  export {
36
- E as preCache
36
+ q as preCache
37
37
  };
@@ -1,109 +1,113 @@
1
1
  import { captureDOM as v } from "../core/capture.js";
2
- import { extendIconFonts as R } from "../modules/iconFonts.js";
3
- import { isSafari as j } from "../utils/helpers.js";
4
- async function x(a, { dpr: t = 1, scale: o = 1 }) {
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(), j ? (e.width = e.width * o, e.height = e.height * o) : (e.width = e.width / o, e.height = e.height / o), e;
6
+ return e.src = a, await e.decode(), e.width = e.width * o, e.height = e.height * o, e;
7
7
  }
8
- async function u(a, { dpr: t = 1, scale: o = 1 } = {}) {
8
+ async function f(a, { dpr: t = 1, scale: o = 1 } = {}) {
9
9
  const e = new Image();
10
- e.src = a, await e.decode();
11
- const n = document.createElement("canvas"), c = e.width * o, i = e.height * o;
12
- n.width = Math.ceil(c * t), n.height = Math.ceil(i * t);
13
- const s = n.getContext("2d");
14
- return s.scale(t, t), s.drawImage(e, 0, 0, c, i), n.style.width = `${c}px`, n.style.height = `${i}px`, n;
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 l(a, { type: t = "svg", scale: o = 1, backgroundColor: e = "#fff", quality: n } = {}) {
17
- const c = {
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 s = decodeURIComponent(a.split(",")[1]);
25
- return new Blob([s], { type: "image/svg+xml" });
28
+ const r = decodeURIComponent(a.split(",")[1]);
29
+ return new Blob([r], { type: "image/svg+xml" });
26
30
  }
27
- const i = await m(
31
+ const s = await u(
28
32
  a,
29
33
  { dpr: 1, scale: o },
30
34
  e
31
35
  );
32
- return new Promise((s) => {
33
- i.toBlob((r) => s(r), `${c}`, n);
36
+ return new Promise((r) => {
37
+ s.toBlob((g) => r(g), `${n}`, c);
34
38
  });
35
39
  }
36
- async function m(a, { dpr: t = 1, scale: o = 1 }, e) {
37
- const n = await u(a, { dpr: t, scale: o });
38
- if (!e) return n;
39
- const c = document.createElement("canvas");
40
- c.width = n.width, c.height = n.height;
41
- const i = c.getContext("2d");
42
- return i.fillStyle = e, i.fillRect(0, 0, c.width, c.height), i.drawImage(n, 0, 0), c;
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 p(a, { dpr: t = 1, scale: o = 1, backgroundColor: e = "#fff", quality: n }, c = "png") {
45
- const i = await m(a, { dpr: t, scale: o }, e), s = new Image();
46
- return s.src = i.toDataURL(`image/${c}`, n), await s.decode(), s.style.width = `${i.width / t}px`, s.style.height = `${i.height / t}px`, s;
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 I(a, {
52
+ async function x(a, {
49
53
  dpr: t = 1,
50
54
  scale: o = 1,
51
- backgroundColor: e = "#fff",
52
- format: n = "png",
53
- filename: c = "capture"
55
+ backgroundColor: e,
56
+ format: c = "png",
57
+ filename: n = "snapDOM"
54
58
  } = {}) {
55
- if (n === "svg") {
56
- const y = await l(a), h = URL.createObjectURL(y), d = document.createElement("a");
57
- d.href = h, d.download = `${c}.svg`, d.click(), URL.revokeObjectURL(h);
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 i = ["jpg", "jpeg", "webp"].includes(n) ? "#fff" : void 0, r = await m(a, { dpr: t, scale: o }, e ?? i), f = {
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
- }[n] || "image/png", b = r.toDataURL(f), w = document.createElement("a");
66
- w.href = b, w.download = `${c}.${n}`, w.click();
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 g(a, t = {}) {
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 && R(t.iconFonts), await g.capture(a, t);
74
+ return t.iconFonts && j(t.iconFonts), await i.capture(a, t);
71
75
  }
72
- g.capture = async (a, t = {}) => {
73
- const o = await v(a, t), e = window.devicePixelRatio || 1, n = t.scale || 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: () => x(o, { dpr: e, scale: n }),
79
- toCanvas: () => u(o, { dpr: e, scale: n }),
80
- toBlob: (c) => l(o, { scale: n, ...c }),
81
- toPng: (c) => p(o, { dpr: e, scale: n, ...c }, "png"),
82
- toJpg: (c) => p(o, { dpr: e, scale: n, ...c }, "jpeg"),
83
- toWebp: (c) => p(o, { dpr: e, scale: n, ...c }, "webp"),
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: c = "png",
86
- filename: i = "capture",
87
- backgroundColor: s
88
- } = {}) => I(o, { dpr: e, scale: n, backgroundColor: s, format: c, filename: i })
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
- g.toRaw = async (a, t) => (await g.capture(a, t)).toRaw();
92
- g.toImg = async (a, t) => (await g.capture(a, t)).toImg();
93
- g.toCanvas = async (a, t) => (await g.capture(a, t)).toCanvas();
94
- g.toBlob = async (a, t) => (await g.capture(a, t)).toBlob(t);
95
- g.toPng = async (a, t) => (await g.capture(a, t)).toPng(t);
96
- g.toJpg = async (a, t) => (await g.capture(a, t)).toJpg(t);
97
- g.toWebp = async (a, t) => (await g.capture(a, t)).toWebp(t);
98
- g.download = async (a, t = {}) => {
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: n,
103
- ...c
106
+ backgroundColor: c,
107
+ ...n
104
108
  } = t;
105
- return await (await g.capture(a, c)).download({ format: o, filename: e, backgroundColor: n });
109
+ return await (await i.capture(a, n)).download({ format: o, filename: e, backgroundColor: c });
106
110
  };
107
111
  export {
108
- g as snapdom
112
+ i as snapdom
109
113
  };
@@ -1,10 +1,21 @@
1
- const e = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new Set();
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
- t as baseCSSCache,
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 { baseCSSCache as S } from "./cache.js";
2
- import { inlineBackgroundImages as M } from "../modules/background.js";
3
- import { embedCustomFonts as A } from "../modules/fonts.js";
4
- import { inlineImages as O } from "../modules/images.js";
5
- import { collectUsedTagNames as R, generateDedupedBaseCSS as U } from "../utils/cssTools.js";
6
- import { idle as c, isSafari as j } from "../utils/helpers.js";
7
- import { prepareClone as D } from "./prepare.js";
8
- async function V(l, a = {}) {
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: p = !0,
12
+ compress: u = !0,
12
13
  embedFonts: b = !1,
13
- fast: r = !0,
14
- scale: h = 1,
15
- useProxy: T = ""
16
- } = a;
17
- let t, y, v, C = "", m = "", x, $;
18
- if ({ clone: t, classCSS: y, styleCache: v } = await D(
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
- p,
21
+ u,
21
22
  b,
22
- T
23
+ t
23
24
  ), await new Promise((s) => {
24
25
  c(
25
26
  async () => {
26
- await O(t, a), s();
27
+ await M(a, t), s();
27
28
  },
28
- { fast: r }
29
+ { fast: n }
29
30
  );
30
31
  }), await new Promise((s) => {
31
32
  c(
32
33
  async () => {
33
- await M(l, t, v, a), s();
34
+ await H(l, a, t), s();
34
35
  },
35
- { fast: r }
36
+ { fast: n }
36
37
  );
37
38
  }), b && await new Promise((s) => {
38
39
  c(
39
40
  async () => {
40
- C = await A(), s();
41
+ p = await I(), s();
41
42
  },
42
- { fast: r }
43
+ { fast: n }
43
44
  );
44
- }), p) {
45
- const s = R(t).sort(), i = s.join(",");
46
- S.has(i) ? m = S.get(i) : await new Promise((e) => {
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 = U(s), S.set(i, m), e();
50
+ m = O(s), h.baseStyle.set(i, m), e();
50
51
  },
51
- { fast: r }
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, n = i.height;
60
- const w = Number.isFinite(a.width), d = Number.isFinite(a.height), u = typeof h == "number" && h !== 1;
61
- if (!u) {
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
- w && d ? (e = a.width, n = a.height) : w ? (e = a.width, n = e / g) : d && (n = a.height, e = n * g);
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), n = Math.ceil(n), t.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"), t.style.transformOrigin = "top left", !u && (w || d)) {
66
- const g = i.width, E = i.height, N = e / g, z = n / E, H = t.style.transform || "", I = `scale(${N}, ${z})`;
67
- t.style.transform = `${I} ${H}`.trim();
68
- } else u && j() && (t.style.scale = `${h}`);
69
- const F = "http://www.w3.org/2000/svg", o = document.createElementNS(F, "foreignObject");
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 P = document.createElement("style");
72
- P.textContent = m + C + "svg{overflow:visible;}" + y, o.appendChild(P), o.appendChild(t);
73
- const B = new XMLSerializer().serializeToString(o);
74
- $ = `<svg xmlns="${F}" width="${e}" height="${n}" viewBox="0 0 ${e} ${n}">` + B + "</svg>", x = `data:image/svg+xml;charset=utf-8,${encodeURIComponent($)}`, s();
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: r }
77
+ { fast: n }
77
78
  );
78
79
  });
79
- const f = document.getElementById("snapdom-sandbox");
80
- return f && f.style.position === "absolute" && f.remove(), x;
80
+ const w = document.getElementById("snapdom-sandbox");
81
+ return w && w.style.position === "absolute" && w.remove(), v;
81
82
  }
82
83
  export {
83
- V as captureDOM
84
+ J as captureDOM
84
85
  };