@unicom-cloud/utils 0.1.12 → 0.1.13

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 +42 -42
  6. package/snapdom/src/core/cache.js +19 -8
  7. package/snapdom/src/core/capture.js +60 -59
  8. package/snapdom/src/core/clone.js +96 -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 +97 -105
  12. package/snapdom/src/modules/pseudo.js +32 -32
  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,12 +1,13 @@
1
- import { iconToImage as z } from "./fonts.js";
2
- import { isIconFont as U } from "./iconFonts.js";
1
+ import { cache as I } from "../core/cache.js";
2
+ import { iconToImage as T } from "./fonts.js";
3
+ import { isIconFont as $ } from "./iconFonts.js";
3
4
  import { getStyleKey as N } from "../utils/cssTools.js";
4
- import { getStyle as W, snapshotComputedStyle as V, parseContent as j, extractURL as A, fetchImage as D, safeEncodeURI as L, splitBackgroundImage as R, inlineSingleBackgroundEntry as K } from "../utils/helpers.js";
5
- async function M(c, r, h, F, u, T = !1, w) {
5
+ import { getStyle as z, snapshotComputedStyle as V, parseContent as U, extractURL as W, fetchImage as j, safeEncodeURI as A, splitBackgroundImage as D, inlineSingleBackgroundEntry as L } from "../utils/helpers.js";
6
+ async function R(c, r, h, F = !1, S) {
6
7
  if (!(c instanceof Element) || !(r instanceof Element)) return;
7
8
  for (const n of ["::before", "::after", "::first-letter"])
8
9
  try {
9
- const t = W(c, n);
10
+ const t = z(c, n);
10
11
  if (!t || typeof t[Symbol.iterator] != "function") continue;
11
12
  if (n === "::first-letter") {
12
13
  const l = getComputedStyle(c);
@@ -19,36 +20,37 @@ async function M(c, r, h, F, u, T = !1, w) {
19
20
  if (!f || /[\uD800-\uDFFF]/.test(f)) continue;
20
21
  const a = document.createElement("span");
21
22
  a.textContent = f, a.dataset.snapdomPseudo = "::first-letter";
22
- const s = V(t), I = N(s, "span", u);
23
- h.set(a, I);
23
+ const s = V(t), B = N(s, "span", h);
24
+ I.preStyleMap.set(a, B);
24
25
  const E = document.createTextNode(x);
25
26
  r.replaceChild(E, d), r.insertBefore(a, E);
26
27
  continue;
27
28
  }
28
- const B = t.getPropertyValue("content"), y = t.getPropertyValue("background-image"), m = t.getPropertyValue("background-color"), $ = B !== "none", C = y && y !== "none", b = m && m !== "transparent" && m !== "rgba(0, 0, 0, 0)";
29
- if ($ || C || b) {
30
- const l = t.getPropertyValue("font-family"), p = parseInt(t.getPropertyValue("font-size")) || 32, d = parseInt(t.getPropertyValue("font-weight")) || !1, g = t.getPropertyValue("color") || "#000", o = document.createElement("span");
29
+ const u = t.getPropertyValue("content"), y = t.getPropertyValue("background-image"), p = t.getPropertyValue("background-color"), M = u !== "none", C = y && y !== "none", b = p && p !== "transparent" && p !== "rgba(0, 0, 0, 0)";
30
+ if (M || C || b) {
31
+ const l = t.getPropertyValue("font-family"), m = parseInt(t.getPropertyValue("font-size")) || 32, d = parseInt(t.getPropertyValue("font-weight")) || !1, g = t.getPropertyValue("color") || "#000", o = document.createElement("span");
31
32
  o.dataset.snapdomPseudo = n;
32
- const f = V(t), x = N(f, "span", u);
33
- h.set(o, x);
34
- const a = U(l), s = j(B);
35
- if (a && s.length === 1) {
33
+ const f = V(t), x = N(f, "span", h);
34
+ I.preStyleMap.set(o, x);
35
+ const a = $(l);
36
+ let s;
37
+ if (/counter\s*\(|counters\s*\(/.test(u) ? s = "- " : s = U(u), a && s.length === 1) {
36
38
  const e = document.createElement("img");
37
- e.src = await z(
39
+ e.src = await T(
38
40
  s,
39
41
  l,
40
42
  d,
41
- p,
43
+ m,
42
44
  g
43
- ), e.style = `width:${p}px;height:auto;object-fit:contain;`, o.appendChild(e);
45
+ ), e.style = `width:${m}px;height:auto;object-fit:contain;`, o.appendChild(e);
44
46
  } else if (s.startsWith("url(")) {
45
- const e = A(s);
47
+ const e = W(s);
46
48
  if (e && e.trim() !== "")
47
49
  try {
48
- const i = document.createElement("img"), P = await D(
49
- L(e, { useProxy: w })
50
+ const i = document.createElement("img"), P = await j(
51
+ A(e, { useProxy: S })
50
52
  );
51
- i.src = P, i.style = `width:${p}px;height:auto;object-fit:contain;`, o.appendChild(i);
53
+ i.src = P, i.style = `width:${m}px;height:auto;object-fit:contain;`, o.appendChild(i);
52
54
  } catch (i) {
53
55
  console.error(
54
56
  `[snapdom] Error in pseudo ${n} for`,
@@ -59,8 +61,8 @@ async function M(c, r, h, F, u, T = !1, w) {
59
61
  } else !a && s && s !== "none" && (o.textContent = s);
60
62
  if (C)
61
63
  try {
62
- const e = R(y), i = await Promise.all(
63
- e.map((P) => K(P))
64
+ const e = D(y), i = await Promise.all(
65
+ e.map((P) => L(P))
64
66
  );
65
67
  o.style.backgroundImage = i.join(", ");
66
68
  } catch (e) {
@@ -69,26 +71,24 @@ async function M(c, r, h, F, u, T = !1, w) {
69
71
  e
70
72
  );
71
73
  }
72
- if (b && (o.style.backgroundColor = m), !(o.childNodes.length > 0 || o.textContent && o.textContent.trim() !== "" || C || b)) continue;
74
+ if (b && (o.style.backgroundColor = p), !(o.childNodes.length > 0 || o.textContent && o.textContent.trim() !== "" || C || b)) continue;
73
75
  n === "::before" ? r.insertBefore(o, r.firstChild) : r.appendChild(o);
74
76
  }
75
77
  } catch (t) {
76
78
  console.warn(`[snapdom] Failed to capture ${n} for`, c, t);
77
79
  }
78
- const S = Array.from(c.children), k = Array.from(r.children).filter(
80
+ const w = Array.from(c.children), k = Array.from(r.children).filter(
79
81
  (n) => !n.dataset.snapdomPseudo
80
82
  );
81
- for (let n = 0; n < Math.min(S.length, k.length); n++)
82
- await M(
83
- S[n],
83
+ for (let n = 0; n < Math.min(w.length, k.length); n++)
84
+ await R(
85
+ w[n],
84
86
  k[n],
85
87
  h,
86
88
  F,
87
- u,
88
- T,
89
- w
89
+ S
90
90
  );
91
91
  }
92
92
  export {
93
- M as inlinePseudoElements
93
+ R as inlinePseudoElements
94
94
  };
@@ -1,31 +1,31 @@
1
- import { getStyleKey as c } from "../utils/cssTools.js";
2
- import { getStyle as d } from "../utils/helpers.js";
3
- const p = /* @__PURE__ */ new WeakMap(), r = /* @__PURE__ */ new Map();
4
- function y(t) {
5
- const o = {};
6
- for (let n = 0; n < t.length; n++) {
7
- const e = t[n];
8
- let a = t.getPropertyValue(e);
9
- (e === "background-image" || e === "content") && a.includes("url(") && !a.includes("data:") && (a = "none"), o[e] = a;
1
+ import { cache as e } from "../core/cache.js";
2
+ import { getStyleKey as y } from "../utils/cssTools.js";
3
+ import { getStyle as m } from "../utils/helpers.js";
4
+ function g(t) {
5
+ const a = {};
6
+ for (let o = 0; o < t.length; o++) {
7
+ const s = t[o];
8
+ let n = t.getPropertyValue(s);
9
+ (s === "background-image" || s === "content") && n.includes("url(") && !n.includes("data:") && (n = "none"), a[s] = n;
10
10
  }
11
- return o;
11
+ return a;
12
12
  }
13
- function S(t, o, n, e, a) {
13
+ function d(t, a, o) {
14
14
  if (t.tagName === "STYLE") return;
15
- e.has(t) || e.set(t, d(t));
16
- const m = e.get(t);
17
- if (!p.has(t)) {
18
- const s = y(m);
19
- p.set(t, s);
15
+ e.preStyle.has(t) || e.preStyle.set(t, m(t));
16
+ const s = e.preStyle.get(t);
17
+ if (!e.snapshot.has(t)) {
18
+ const p = g(s);
19
+ e.snapshot.set(t, p);
20
20
  }
21
- const g = p.get(t), i = Object.entries(g).sort(([s], [l]) => s.localeCompare(l)).map(([s, l]) => `${s}:${l}`).join(";");
22
- if (r.has(i)) {
23
- n.set(o, r.get(i));
21
+ const n = e.snapshot.get(t), l = Object.entries(n).sort(([p], [r]) => p.localeCompare(r)).map(([p, r]) => `${p}:${r}`).join(";");
22
+ if (e.snapshotKey.has(l)) {
23
+ e.preStyleMap.set(a, e.snapshotKey.get(l));
24
24
  return;
25
25
  }
26
- const f = t.tagName?.toLowerCase() || "div", h = c(g, f, a);
27
- r.set(i, h), n.set(o, h);
26
+ const h = t.tagName?.toLowerCase() || "div", i = y(n, h, o);
27
+ e.snapshotKey.set(l, i), e.preStyleMap.set(a, i);
28
28
  }
29
29
  export {
30
- S as inlineAllStyles
30
+ d as inlineAllStyles
31
31
  };
@@ -1,4 +1,4 @@
1
- import { defaultStylesCache as r } from "../core/cache.js";
1
+ import { cache as r } from "../core/cache.js";
2
2
  const d = [
3
3
  "div",
4
4
  "span",
@@ -39,12 +39,12 @@ const d = [
39
39
  "th"
40
40
  ];
41
41
  function u() {
42
- for (let t of d)
43
- c(t);
42
+ for (let e of d)
43
+ c(e);
44
44
  }
45
- function c(t) {
46
- if (r.has(t))
47
- return r.get(t);
45
+ function c(e) {
46
+ if (r.defaultStyle.has(e))
47
+ return r.defaultStyle.get(e);
48
48
  if ((/* @__PURE__ */ new Set([
49
49
  "script",
50
50
  "style",
@@ -52,54 +52,54 @@ function c(t) {
52
52
  "link",
53
53
  "noscript",
54
54
  "template"
55
- ])).has(t)) {
55
+ ])).has(e)) {
56
56
  const o = {};
57
- return r.set(t, o), o;
57
+ return r.defaultStyle.set(e, o), o;
58
58
  }
59
- let e = document.getElementById("snapdom-sandbox");
60
- e || (e = document.createElement("div"), e.id = "snapdom-sandbox", e.style.position = "absolute", e.style.left = "-9999px", e.style.top = "-9999px", e.style.width = "0", e.style.height = "0", e.style.overflow = "hidden", document.body.appendChild(e));
61
- const n = document.createElement(t);
62
- n.style.all = "initial", e.appendChild(n);
63
- const l = getComputedStyle(n), a = {};
64
- for (let o of l)
65
- a[o] = l.getPropertyValue(o);
66
- return e.removeChild(n), r.set(t, a), a;
59
+ let t = document.getElementById("snapdom-sandbox");
60
+ t || (t = document.createElement("div"), t.id = "snapdom-sandbox", t.style.position = "absolute", t.style.left = "-9999px", t.style.top = "-9999px", t.style.width = "0", t.style.height = "0", t.style.overflow = "hidden", document.body.appendChild(t));
61
+ const n = document.createElement(e);
62
+ n.style.all = "initial", t.appendChild(n);
63
+ const a = getComputedStyle(n), l = {};
64
+ for (let o of a)
65
+ l[o] = a.getPropertyValue(o);
66
+ return t.removeChild(n), r.defaultStyle.set(e, l), l;
67
67
  }
68
- function p(t, s, e = !1) {
69
- const n = [], l = c(s);
70
- for (let [a, o] of Object.entries(t))
71
- if (!e)
72
- o && n.push(`${a}:${o}`);
68
+ function p(e, s, t = !1) {
69
+ const n = [], a = c(s);
70
+ for (let [l, o] of Object.entries(e))
71
+ if (!t)
72
+ o && n.push(`${l}:${o}`);
73
73
  else {
74
- const i = l[a];
75
- o && o !== i && n.push(`${a}:${o}`);
74
+ const i = a[l];
75
+ o && o !== i && n.push(`${l}:${o}`);
76
76
  }
77
77
  return n.sort().join(";");
78
78
  }
79
- function y(t) {
79
+ function y(e) {
80
80
  const s = /* @__PURE__ */ new Set();
81
- return t.nodeType !== Node.ELEMENT_NODE && t.nodeType !== Node.DOCUMENT_FRAGMENT_NODE ? [] : (t.tagName && s.add(t.tagName.toLowerCase()), typeof t.querySelectorAll == "function" && t.querySelectorAll("*").forEach((e) => s.add(e.tagName.toLowerCase())), Array.from(s));
81
+ return e.nodeType !== Node.ELEMENT_NODE && e.nodeType !== Node.DOCUMENT_FRAGMENT_NODE ? [] : (e.tagName && s.add(e.tagName.toLowerCase()), typeof e.querySelectorAll == "function" && e.querySelectorAll("*").forEach((t) => s.add(t.tagName.toLowerCase())), Array.from(s));
82
82
  }
83
- function h(t) {
83
+ function h(e) {
84
84
  const s = /* @__PURE__ */ new Map();
85
- for (let n of t) {
86
- const l = r.get(n);
87
- if (!l) continue;
88
- const a = Object.entries(l).map(([o, i]) => `${o}:${i};`).sort().join("");
89
- s.has(a) || s.set(a, []), s.get(a).push(n);
85
+ for (let n of e) {
86
+ const a = r.defaultStyle.get(n);
87
+ if (!a) continue;
88
+ const l = Object.entries(a).map(([o, i]) => `${o}:${i};`).sort().join("");
89
+ s.has(l) || s.set(l, []), s.get(l).push(n);
90
90
  }
91
- let e = "";
92
- for (let [n, l] of s.entries())
93
- e += `${l.join(",")} { ${n} }
91
+ let t = "";
92
+ for (let [n, a] of s.entries())
93
+ t += `${a.join(",")} { ${n} }
94
94
  `;
95
- return e;
95
+ return t;
96
96
  }
97
- function m(t) {
98
- const s = new Set(t.values()), e = /* @__PURE__ */ new Map();
99
- let n = 1;
100
- for (const l of s)
101
- e.set(l, `c${n++}`);
102
- return e;
97
+ function m() {
98
+ const e = new Set(r.preStyleMap.values()), s = /* @__PURE__ */ new Map();
99
+ let t = 1;
100
+ for (const n of e)
101
+ s.set(n, `c${t++}`);
102
+ return s;
103
103
  }
104
104
  export {
105
105
  y as collectUsedTagNames,
@@ -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