@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,186 +1,183 @@
1
- import { imageCache as f, computedStyleCache as p, bgCache as m } from "../core/cache.js";
2
- async function x(e, t = {}) {
3
- const r = e.startsWith("url("), i = /^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(
4
- e
1
+ import { cache as s } from "../core/cache.js";
2
+ async function R(t, e = {}) {
3
+ const n = p(t), i = /^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(
4
+ t
5
5
  );
6
- if (r) {
7
- const n = I(e);
8
- if (!n) return e;
9
- const a = w(n);
10
- if (m.has(a))
11
- return t.skipInline ? void 0 : `url(${m.get(a)})`;
6
+ if (n) {
7
+ const a = h(n);
8
+ if (s.background.has(a))
9
+ return e.skipInline ? void 0 : `url(${s.background.get(a)})`;
12
10
  {
13
- const s = await y(a, {
14
- useProxy: t.useProxy
11
+ const c = await w(a, {
12
+ useProxy: e.useProxy
15
13
  });
16
- return m.set(a, s), t.skipInline ? void 0 : `url(${s})`;
14
+ return s.background.set(a, c), e.skipInline ? void 0 : `url("${c}")`;
17
15
  }
18
16
  }
19
- return e;
17
+ return t;
20
18
  }
21
- function $(e, { fast: t = !1 } = {}) {
22
- if (t) return e();
23
- "requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 50 }) : setTimeout(e, 1);
19
+ function S(t, { fast: e = !1 } = {}) {
20
+ if (e) return t();
21
+ "requestIdleCallback" in window ? requestIdleCallback(t, { timeout: 50 }) : setTimeout(t, 1);
24
22
  }
25
- function O(e, t = null) {
26
- if (!(e instanceof Element))
27
- return window.getComputedStyle(e, t);
28
- let r = p.get(e);
29
- if (r || (r = /* @__PURE__ */ new Map(), p.set(e, r)), !r.has(t)) {
30
- const i = window.getComputedStyle(e, t);
31
- r.set(t, i);
23
+ function U(t, e = null) {
24
+ if (!(t instanceof Element))
25
+ return window.getComputedStyle(t, e);
26
+ let n = s.computedStyle.get(t);
27
+ if (n || (n = /* @__PURE__ */ new Map(), s.computedStyle.set(t, n)), !n.has(e)) {
28
+ const i = window.getComputedStyle(t, e);
29
+ n.set(e, i);
32
30
  }
33
- return r.get(t);
31
+ return n.get(e);
34
32
  }
35
- function C(e) {
36
- let t = e.replace(/^['"]|['"]$/g, "");
37
- if (t.startsWith("\\"))
33
+ function k(t) {
34
+ let e = t.replace(/^['"]|['"]$/g, "");
35
+ if (e.startsWith("\\"))
38
36
  try {
39
- return String.fromCharCode(parseInt(t.replace("\\", ""), 16));
37
+ return String.fromCharCode(parseInt(e.replace("\\", ""), 16));
40
38
  } catch {
41
- return t;
39
+ return e;
42
40
  }
43
- return t;
41
+ return e;
44
42
  }
45
- function I(e) {
46
- const t = e.indexOf("url(");
47
- if (t === -1) return null;
48
- let r = e.slice(t + 4).trim();
49
- return r.endsWith(")") && (r = r.slice(0, -1).trim()), (r.startsWith('"') && r.endsWith('"') || r.startsWith("'") && r.endsWith("'")) && (r = r.slice(1, -1)), r;
43
+ function p(t) {
44
+ const e = t.match(/url\((['"]?)(.*?)(\1)\)/);
45
+ if (!e) return null;
46
+ const n = e[2].trim();
47
+ return n.startsWith("#") ? null : n;
50
48
  }
51
- function y(e, { timeout: t = 3e3, useProxy: r = "" }) {
52
- function i(a) {
49
+ function w(t, { timeout: e = 3e3, useProxy: n = "" } = {}) {
50
+ function i(l) {
53
51
  try {
54
- return new URL(a, window.location.href).origin === window.location.origin ? "use-credentials" : "anonymous";
52
+ return new URL(l, window.location.href).origin === window.location.origin ? "use-credentials" : "anonymous";
55
53
  } catch {
56
54
  return "anonymous";
57
55
  }
58
56
  }
59
- const n = i(e);
60
- return console.log(
61
- `[SnapDOM - fetchImage] Start loading image: ${e} with crossOrigin=${n}`
62
- ), f.has(e) ? (console.log(`[SnapDOM - fetchImage] Cache hit for: ${e}`), Promise.resolve(f.get(e))) : new Promise((a, s) => {
63
- const h = setTimeout(() => {
64
- console.log(
65
- `[SnapDOM - fetchImage] Timeout after ${t}ms for image: ${e}`
66
- ), s(new Error("Image load timed out"));
67
- }, t), g = () => {
68
- console.warn(`[SnapDOM - fetchImage] Trying fetch fallback for: ${e}`), fetch(e, {
69
- mode: "cors",
70
- credentials: n === "use-credentials" ? "include" : "omit"
71
- }).then((o) => (console.log(
72
- `[SnapDOM - fetchImage] Fetch response received for: ${e}`
73
- ), o.blob())).then((o) => {
74
- const d = new FileReader();
75
- d.onloadend = () => {
76
- const c = d.result;
77
- if (typeof c == "string" && c.startsWith("data:application/octet-stream")) {
78
- s(new Error("Image response was empty or blocked"));
57
+ async function a(l) {
58
+ const u = (d) => fetch(d, {
59
+ mode: "cors",
60
+ credentials: i(d) === "use-credentials" ? "include" : "omit"
61
+ }).then((o) => o.blob()).then(
62
+ (o) => new Promise((r, g) => {
63
+ const m = new FileReader();
64
+ m.onloadend = () => {
65
+ const f = m.result;
66
+ if (typeof f != "string" || !f.startsWith("data:image/")) {
67
+ g(new Error("Invalid image data URL"));
79
68
  return;
80
69
  }
81
- f.set(e, c), a(c);
82
- }, d.readAsDataURL(o);
83
- }).catch(() => {
84
- if (console.warn(
85
- `[SnapDOM - fetchImage] Fetch fallback failed for: ${e}`
86
- ), r !== "") {
87
- const o = typeof r == "string" ? r.replace(/\/$/, "") + w(e) : null;
88
- o ? (console.log(
89
- `[SnapDOM - fetchImage] Trying proxy fallback: ${o}`
90
- ), fetch(o).then((d) => d.blob()).then((d) => {
91
- const c = new FileReader();
92
- c.onloadend = () => {
93
- const u = c.result;
94
- if (typeof u == "string" && u.startsWith("data:application/octet-stream")) {
95
- s(new Error("Image response was empty or blocked"));
96
- return;
97
- }
98
- f.set(e, u), a(u);
99
- }, c.readAsDataURL(d);
100
- }).catch(() => {
101
- console.error(
102
- `[SnapDOM - fetchImage] Proxy fallback failed for: ${e}`
103
- ), s(
104
- new Error(
105
- "CORS restrictions prevented image capture (even via proxy)"
106
- )
107
- );
108
- })) : console.error(
109
- `[SnapDOM - fetchImage] Provide a valid proxy url: ${e}`
110
- );
111
- } else
112
- console.error(
113
- '[SnapDOM - fetchImage] You may try add a proxy "useProxy: url" '
114
- );
115
- });
116
- }, l = new Image();
117
- l.crossOrigin = n, l.onload = async () => {
118
- clearTimeout(h);
119
- try {
120
- await l.decode();
121
- const o = document.createElement("canvas");
122
- o.width = l.width, o.height = l.height, o.getContext("2d").drawImage(l, 0, 0, o.width, o.height);
70
+ r(f);
71
+ }, m.onerror = () => g(new Error("FileReader error")), m.readAsDataURL(o);
72
+ })
73
+ );
74
+ try {
75
+ return await u(l);
76
+ } catch {
77
+ if (n && typeof n == "string") {
78
+ const o = n.replace(/\/$/, "") + h(l);
123
79
  try {
124
- const c = o.toDataURL("image/png");
125
- f.set(e, c), a(c);
80
+ return await u(o);
126
81
  } catch {
127
- g();
82
+ throw new Error(
83
+ "[SnapDOM - fetchImage] CORS restrictions prevented image capture (even via proxy)"
84
+ );
128
85
  }
86
+ } else
87
+ throw new Error(
88
+ "[SnapDOM - fetchImage] Fetch fallback failed and no proxy provided"
89
+ );
90
+ }
91
+ }
92
+ const c = i(t);
93
+ return s.image.has(t) ? Promise.resolve(s.image.get(t)) : t.startsWith("data:image/") ? (s.image.set(t, t), Promise.resolve(t)) : /\.svg(\?.*)?$/i.test(t) ? (async () => {
94
+ try {
95
+ const u = await (await fetch(t, {
96
+ mode: "cors",
97
+ credentials: c === "use-credentials" ? "include" : "omit"
98
+ })).text(), d = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(u)}`;
99
+ return s.image.set(t, d), d;
100
+ } catch {
101
+ return a(t);
102
+ }
103
+ })() : new Promise((l, u) => {
104
+ const d = setTimeout(() => {
105
+ u(new Error("[SnapDOM - fetchImage] Image load timed out"));
106
+ }, e), o = new Image();
107
+ o.crossOrigin = c, o.onload = async () => {
108
+ clearTimeout(d);
109
+ try {
110
+ await o.decode();
111
+ const r = document.createElement("canvas");
112
+ r.width = o.width, r.height = o.height, r.getContext("2d").drawImage(o, 0, 0, r.width, r.height);
113
+ const m = r.toDataURL("image/png");
114
+ s.image.set(t, m), l(m);
129
115
  } catch {
130
- g();
116
+ try {
117
+ const r = await a(t);
118
+ s.image.set(t, r), l(r);
119
+ } catch (r) {
120
+ u(r);
121
+ }
122
+ }
123
+ }, o.onerror = async () => {
124
+ clearTimeout(d), console.error(`[SnapDOM - fetchImage] Image failed to load: ${t}`);
125
+ try {
126
+ const r = await a(t);
127
+ s.image.set(t, r), l(r);
128
+ } catch (r) {
129
+ u(r);
131
130
  }
132
- }, l.onerror = (o) => {
133
- clearTimeout(h), console.error(`[SnapDOM - fetchImage] Image failed to load: ${e}`, o), g();
134
- }, l.src = e;
131
+ }, o.src = t;
135
132
  });
136
133
  }
137
- function D(e) {
138
- const t = {};
139
- for (let r of e)
140
- t[r] = e.getPropertyValue(r);
141
- return t;
134
+ function C(t) {
135
+ const e = {};
136
+ for (let n of t)
137
+ e[n] = t.getPropertyValue(n);
138
+ return e;
142
139
  }
143
- function b() {
140
+ function v() {
144
141
  return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
145
142
  }
146
- function k(e) {
147
- if (!e || e === "none") return "";
148
- let t = e.replace(/translate[XY]?\([^)]*\)/g, "");
149
- return t = t.replace(/matrix\(([^)]+)\)/g, (r, i) => {
150
- const n = i.split(",").map((a) => a.trim());
151
- return n.length !== 6 ? `matrix(${i})` : (n[4] = "0", n[5] = "0", `matrix(${n.join(", ")})`);
152
- }), t = t.replace(/matrix3d\(([^)]+)\)/g, (r, i) => {
153
- const n = i.split(",").map((a) => a.trim());
154
- return n.length !== 16 ? `matrix3d(${i})` : (n[12] = "0", n[13] = "0", `matrix3d(${n.join(", ")})`);
155
- }), t.trim().replace(/\s{2,}/g, " ");
143
+ function D(t) {
144
+ if (!t || t === "none") return "";
145
+ let e = t.replace(/translate[XY]?\([^)]*\)/g, "");
146
+ return e = e.replace(/matrix\(([^)]+)\)/g, (n, i) => {
147
+ const a = i.split(",").map((c) => c.trim());
148
+ return a.length !== 6 ? `matrix(${i})` : (a[4] = "0", a[5] = "0", `matrix(${a.join(", ")})`);
149
+ }), e = e.replace(/matrix3d\(([^)]+)\)/g, (n, i) => {
150
+ const a = i.split(",").map((c) => c.trim());
151
+ return a.length !== 16 ? `matrix3d(${i})` : (a[12] = "0", a[13] = "0", `matrix3d(${a.join(", ")})`);
152
+ }), e.trim().replace(/\s{2,}/g, " ");
156
153
  }
157
- function w(e) {
158
- if (/%[0-9A-Fa-f]{2}/.test(e)) return e;
154
+ function h(t) {
155
+ if (/%[0-9A-Fa-f]{2}/.test(t)) return t;
159
156
  try {
160
- return encodeURI(e);
157
+ return encodeURI(t);
161
158
  } catch {
162
- return e;
159
+ return t;
163
160
  }
164
161
  }
165
- function M(e) {
166
- const t = [];
167
- let r = 0, i = 0;
168
- for (let n = 0; n < e.length; n++) {
169
- const a = e[n];
170
- a === "(" && r++, a === ")" && r--, a === "," && r === 0 && (t.push(e.slice(i, n).trim()), i = n + 1);
162
+ function $(t) {
163
+ const e = [];
164
+ let n = 0, i = 0;
165
+ for (let a = 0; a < t.length; a++) {
166
+ const c = t[a];
167
+ c === "(" && n++, c === ")" && n--, c === "," && n === 0 && (e.push(t.slice(i, a).trim()), i = a + 1);
171
168
  }
172
- return t.push(e.slice(i).trim()), t;
169
+ return e.push(t.slice(i).trim()), e;
173
170
  }
174
171
  export {
175
- I as extractURL,
176
- y as fetchImage,
177
- O as getStyle,
178
- $ as idle,
179
- x as inlineSingleBackgroundEntry,
180
- b as isSafari,
181
- C as parseContent,
182
- w as safeEncodeURI,
183
- D as snapshotComputedStyle,
184
- M as splitBackgroundImage,
185
- k as stripTranslate
172
+ p as extractURL,
173
+ w as fetchImage,
174
+ U as getStyle,
175
+ S as idle,
176
+ R as inlineSingleBackgroundEntry,
177
+ v as isSafari,
178
+ k as parseContent,
179
+ h as safeEncodeURI,
180
+ C as snapshotComputedStyle,
181
+ $ as splitBackgroundImage,
182
+ D as stripTranslate
186
183
  };
package/tree/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { default as I } from "./searchTree.js";
1
+ import { default as I } from "./search/index.js";
2
2
  function a(e, r, f, l = "children") {
3
3
  if (Array.isArray(e) && (e = {
4
4
  [l]: e
@@ -0,0 +1,90 @@
1
+ import "../../is/index.js";
2
+ import A from "lodash/isArray";
3
+ import z from "lodash/isObjectLike";
4
+ import w from "lodash/isString";
5
+ import T from "lodash/isFunction";
6
+ function v(r, l, a, f) {
7
+ return l && r ? { shouldExit: !0, newMatch: !0 } : a && !r ? { shouldExit: !0, newMatch: !1 } : { shouldExit: !1, newMatch: f || r };
8
+ }
9
+ function q(r, l, a = {}) {
10
+ if (!A(r)) throw new TypeError("参数treeData必须是一个数组");
11
+ if (!z(l)) throw new TypeError("参数searchCondition必须是一个对象");
12
+ const f = {
13
+ strategy: "BFS",
14
+ childrenKey: "children",
15
+ strict: !1,
16
+ fuzzyMatch: !1,
17
+ returnAllMatches: !1,
18
+ caseSensitive: !1,
19
+ allowEmptyString: !1,
20
+ matchMode: "AND",
21
+ ...a
22
+ // 用户配置覆盖默认值
23
+ }, {
24
+ strategy: p,
25
+ childrenKey: S,
26
+ strict: x,
27
+ fuzzyMatch: O,
28
+ returnAllMatches: y,
29
+ caseSensitive: m,
30
+ allowEmptyString: B,
31
+ matchMode: E
32
+ } = f, M = E === "OR", g = E === "AND", h = p === "BFS";
33
+ if (!(h || p === "DFS")) throw new Error('配置 strategy 必须是 "BFS" 或 "DFS"');
34
+ if (!(M || g)) throw new Error('配置 matchMode 必须是 "AND" 或 "OR"');
35
+ if (!w(S)) throw new TypeError("配置 childrenKey 必须是字符串");
36
+ const c = [...r], F = [], D = Object.entries(l);
37
+ if (D.length) {
38
+ const N = (s) => {
39
+ let t = !1;
40
+ for (const [n, e] of D) {
41
+ const i = s[n];
42
+ if (e === "" && !B)
43
+ continue;
44
+ let o = !1;
45
+ try {
46
+ if (e instanceof RegExp)
47
+ o = w(i) ? e.test(i) : !1;
48
+ else if (T(e))
49
+ o = !!e(i);
50
+ else if (O && w(e)) {
51
+ const d = String(i), R = m ? e : e.toLowerCase();
52
+ o = (m ? d : d.toLowerCase()).includes(R);
53
+ } else
54
+ o = x ? i === e : i == e;
55
+ } catch {
56
+ o = !1;
57
+ }
58
+ const u = v(o, M, g, t);
59
+ if (u.shouldExit)
60
+ return u.newMatch;
61
+ t = u.newMatch;
62
+ }
63
+ return t;
64
+ };
65
+ for (; c.length > 0; ) {
66
+ const s = h ? c.shift() : c.pop();
67
+ if (!s) continue;
68
+ try {
69
+ if (N(s))
70
+ if (y)
71
+ F.push(s);
72
+ else
73
+ return s;
74
+ } catch {
75
+ continue;
76
+ }
77
+ const t = s[S];
78
+ if (A(t))
79
+ if (h)
80
+ c.push(...t);
81
+ else
82
+ for (let n = t.length - 1; n >= 0; n--)
83
+ c.push(t[n]);
84
+ }
85
+ }
86
+ return y ? F : null;
87
+ }
88
+ export {
89
+ q as default
90
+ };
package/tree.js CHANGED
@@ -1,4 +1,4 @@
1
- import { default as a } from "./tree/searchTree.js";
1
+ import { default as a } from "./tree/search/index.js";
2
2
  import { getItemBy as y, findNodeBy as m, getChildWithParentBy as B, getItemBy as g, getItemBy2 as o, getItemBy3 as I, getItemByID as d, getLabelFromDictionaryByValue as f } from "./tree/index.js";
3
3
  export {
4
4
  y as default,
@@ -1,24 +1,24 @@
1
- export const ARRAY: "array";
1
+ export const INVALID_NUMBER: "Invalid number";
2
+ export const INVALID_ROUND: "Invalid rounding method";
3
+ export const IEC: "iec";
4
+ export const JEDEC: "jedec";
5
+ export const SI: "si";
2
6
  export const BIT: "bit";
3
7
  export const BITS: "bits";
4
8
  export const BYTE: "byte";
5
9
  export const BYTES: "bytes";
6
- export const EMPTY: "";
7
- export const EXPONENT: "exponent";
10
+ export const SI_KBIT: "kbit";
11
+ export const SI_KBYTE: "kB";
12
+ export const ARRAY: "array";
8
13
  export const FUNCTION: "function";
9
- export const IEC: "iec";
10
- export const INVALID_NUMBER: "Invalid number";
11
- export const INVALID_ROUND: "Invalid rounding method";
12
- export const JEDEC: "jedec";
13
14
  export const OBJECT: "object";
14
- export const PERIOD: ".";
15
+ export const STRING: "string";
16
+ export const EXPONENT: "exponent";
15
17
  export const ROUND: "round";
18
+ export const EMPTY: "";
19
+ export const PERIOD: ".";
16
20
  export const S: "s";
17
- export const SI: "si";
18
- export const SI_KBIT: "kbit";
19
- export const SI_KBYTE: "kB";
20
21
  export const SPACE: " ";
21
- export const STRING: "string";
22
22
  export const ZERO: "0";
23
23
  export namespace STRINGS {
24
24
  namespace symbol {
@@ -1,47 +1,88 @@
1
- export function filesize(arg: any, { bits, pad, base, round, locale, localeOptions, separator, spacer, symbols, standard, output, fullform, fullforms, exponent, roundingMethod, precision, }?: {
1
+ /**
2
+ * Converts a file size in bytes to a human-readable string with appropriate units
3
+ * @param {number|string|bigint} arg - The file size in bytes to convert
4
+ * @param {Object} [options={}] - Configuration options for formatting
5
+ * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes
6
+ * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter
7
+ * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)
8
+ * @param {number} [options.round=2] - Number of decimal places to round to
9
+ * @param {string|boolean} [options.locale=""] - Locale for number formatting, true for system locale
10
+ * @param {Object} [options.localeOptions={}] - Additional options for locale formatting
11
+ * @param {string} [options.separator=""] - Custom decimal separator
12
+ * @param {string} [options.spacer=" "] - String to separate value and unit
13
+ * @param {Object} [options.symbols={}] - Custom unit symbols
14
+ * @param {string} [options.standard=""] - Unit standard to use (SI, IEC, JEDEC)
15
+ * @param {string} [options.output="string"] - Output format: "string", "array", "object", or "exponent"
16
+ * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations
17
+ * @param {Array} [options.fullforms=[]] - Custom full unit names
18
+ * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)
19
+ * @param {string} [options.roundingMethod="round"] - Math rounding method to use
20
+ * @param {number} [options.precision=0] - Number of significant digits (0 for auto)
21
+ * @returns {string|Array|Object|number} Formatted file size based on output option
22
+ * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid
23
+ * @example
24
+ * filesize(1024) // "1 KB"
25
+ * filesize(1024, {bits: true}) // "8 Kb"
26
+ * filesize(1024, {output: "object"}) // {value: 1, symbol: "KB", exponent: 1, unit: "KB"}
27
+ */
28
+ export function filesize(arg: number | string | bigint, { bits, pad, base, round, locale, localeOptions, separator, spacer, symbols, standard, output, fullform, fullforms, exponent, roundingMethod, precision, }?: {
2
29
  bits?: boolean | undefined;
3
30
  pad?: boolean | undefined;
4
31
  base?: number | undefined;
5
32
  round?: number | undefined;
6
- locale?: string | undefined;
7
- localeOptions?: {} | undefined;
33
+ locale?: string | boolean | undefined;
34
+ localeOptions?: Object | undefined;
8
35
  separator?: string | undefined;
9
36
  spacer?: string | undefined;
10
- symbols?: {} | undefined;
37
+ symbols?: Object | undefined;
11
38
  standard?: string | undefined;
12
39
  output?: string | undefined;
13
40
  fullform?: boolean | undefined;
14
- fullforms?: never[] | undefined;
41
+ fullforms?: any[] | undefined;
15
42
  exponent?: number | undefined;
16
43
  roundingMethod?: string | undefined;
17
44
  precision?: number | undefined;
18
- }): string | number | any[] | {
19
- value: any;
20
- symbol: any;
21
- exponent: number;
22
- unit: string;
23
- };
45
+ }): string | any[] | Object | number;
46
+ /**
47
+ * Creates a partially applied version of filesize with preset options
48
+ * @param {Object} [options={}] - Default options to apply to the returned function
49
+ * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes
50
+ * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter
51
+ * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)
52
+ * @param {number} [options.round=2] - Number of decimal places to round to
53
+ * @param {string|boolean} [options.locale=""] - Locale for number formatting, true for system locale
54
+ * @param {Object} [options.localeOptions={}] - Additional options for locale formatting
55
+ * @param {string} [options.separator=""] - Custom decimal separator
56
+ * @param {string} [options.spacer=" "] - String to separate value and unit
57
+ * @param {Object} [options.symbols={}] - Custom unit symbols
58
+ * @param {string} [options.standard=""] - Unit standard to use (SI, IEC, JEDEC)
59
+ * @param {string} [options.output="string"] - Output format: "string", "array", "object", or "exponent"
60
+ * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations
61
+ * @param {Array} [options.fullforms=[]] - Custom full unit names
62
+ * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)
63
+ * @param {string} [options.roundingMethod="round"] - Math rounding method to use
64
+ * @param {number} [options.precision=0] - Number of significant digits (0 for auto)
65
+ * @returns {Function} A function that takes a file size and returns formatted output
66
+ * @example
67
+ * const formatBytes = partial({round: 1, standard: "IEC"});
68
+ * formatBytes(1024) // "1.0 KiB"
69
+ * formatBytes(2048) // "2.0 KiB"
70
+ */
24
71
  export function partial({ bits, pad, base, round, locale, localeOptions, separator, spacer, symbols, standard, output, fullform, fullforms, exponent, roundingMethod, precision, }?: {
25
72
  bits?: boolean | undefined;
26
73
  pad?: boolean | undefined;
27
74
  base?: number | undefined;
28
75
  round?: number | undefined;
29
- locale?: string | undefined;
30
- localeOptions?: {} | undefined;
76
+ locale?: string | boolean | undefined;
77
+ localeOptions?: Object | undefined;
31
78
  separator?: string | undefined;
32
79
  spacer?: string | undefined;
33
- symbols?: {} | undefined;
80
+ symbols?: Object | undefined;
34
81
  standard?: string | undefined;
35
82
  output?: string | undefined;
36
83
  fullform?: boolean | undefined;
37
- fullforms?: never[] | undefined;
84
+ fullforms?: any[] | undefined;
38
85
  exponent?: number | undefined;
39
86
  roundingMethod?: string | undefined;
40
87
  precision?: number | undefined;
41
- }): (arg: any) => string | number | any[] | {
42
- value: any;
43
- symbol: any;
44
- exponent: number;
45
- unit: string;
46
- };
47
- export default filesize;
88
+ }): Function;
@@ -1,11 +1,17 @@
1
- /**
2
- * Caches for images, backgrounds, resources, and computed styles used during DOM capture.
3
- * @module cache
4
- */
5
- export const imageCache: Map<any, any>;
6
- export const bgCache: Map<any, any>;
7
- export const resourceCache: Map<any, any>;
8
- export const defaultStylesCache: Map<any, any>;
9
- export const baseCSSCache: Map<any, any>;
10
- export const computedStyleCache: WeakMap<WeakKey, any>;
11
- export const processedFontURLs: Set<any>;
1
+ export namespace cache {
2
+ export let image: Map<any, any>;
3
+ export let background: Map<any, any>;
4
+ export let resource: Map<any, any>;
5
+ export let defaultStyle: Map<any, any>;
6
+ export let baseStyle: Map<any, any>;
7
+ export let computedStyle: WeakMap<WeakKey, any>;
8
+ export let font: Set<any>;
9
+ export let snapshot: WeakMap<WeakKey, any>;
10
+ export let snapshotKey: Map<any, any>;
11
+ export let preStyleMap: Map<any, any>;
12
+ export let preStyle: WeakMap<WeakKey, any>;
13
+ export let preNodeMap: Map<any, any>;
14
+ export { resetCache as reset };
15
+ }
16
+ declare function resetCache(): void;
17
+ export {};
@@ -7,6 +7,8 @@
7
7
  * @param {boolean} [options.embedFonts=false] - Whether to embed custom fonts
8
8
  * @param {boolean} [options.fast=true] - Whether to skip idle delay for faster results
9
9
  * @param {number} [options.scale=1] - Output scale multiplier
10
+ * @param {string[]} [options.exclude] - CSS selectors for elements to exclude
11
+ * @param {Function} [options.filter] - Custom filter function
10
12
  * @returns {Promise<string>} Promise that resolves to an SVG data URL
11
13
  */
12
14
  export function captureDOM(element: Element, options?: {
@@ -14,4 +16,6 @@ export function captureDOM(element: Element, options?: {
14
16
  embedFonts?: boolean | undefined;
15
17
  fast?: boolean | undefined;
16
18
  scale?: number | undefined;
19
+ exclude?: string[] | undefined;
20
+ filter?: Function | undefined;
17
21
  }): Promise<string>;
@@ -2,10 +2,9 @@
2
2
  * Creates a deep clone of a DOM node, including styles, shadow DOM, and special handling for excluded/placeholder/canvas nodes.
3
3
  *
4
4
  * @param {Node} node - Node to clone
5
- * @param {Map} styleMap - Map to store element-to-style-key mappings
6
- * @param {WeakMap} styleCache - Cache of computed styles
7
- * @param {WeakMap} nodeMap - Map to track original-to-clone node relationships
8
5
  * @param {boolean} compress - Whether to compress style keys
9
- * @returns {Node|null} Cloned node with styles and shadow DOM content, or null for empty text nodes
6
+ * @param {Object} [options={}] - Capture options including exclude and filter
7
+ * @param {Node} [originalRoot] - Original root element being captured
8
+ * @returns {Node|null} Cloned node with styles and shadow DOM content, or null for empty text nodes or filtered elements
10
9
  */
11
- export function deepClone(node: Node, styleMap: Map<any, any>, styleCache: WeakMap<any, any>, nodeMap: WeakMap<any, any>, compress: boolean): Node | null;
10
+ export function deepClone(node: Node, compress: boolean, options?: Object, originalRoot?: Node): Node | null;