@unicom-cloud/utils 0.1.16 → 0.1.18

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 (93) hide show
  1. package/class-name/index.js +5 -5
  2. package/constant/index.js +24 -2
  3. package/constant/platform.js +13 -12
  4. package/constant.js +24 -2
  5. package/content-disposition/index.js +3 -3
  6. package/date/convertTime.js +4 -4
  7. package/diff/index.js +7 -0
  8. package/diff/src/diff.d.ts +21 -0
  9. package/diff/src/diff.js +381 -0
  10. package/diff.js +7 -0
  11. package/filesize/types/constants.d.ts +81 -0
  12. package/filesize/types/filesize.d.ts +97 -0
  13. package/index.js +68 -58
  14. package/js-cookie/index.d.ts +116 -0
  15. package/js-cookie/index.js +4 -0
  16. package/js-cookie/src/api.js +56 -0
  17. package/js-cookie/src/assign.js +11 -0
  18. package/js-cookie/src/converter.js +14 -0
  19. package/jsCookie.js +4 -0
  20. package/lunar/lib/HolidayUtil.js +48 -49
  21. package/mitt/index.js +4 -0
  22. package/mitt/src/index.js +37 -0
  23. package/mitt.js +4 -0
  24. package/nzh/nzh.d.ts +74 -0
  25. package/package.json +1 -1
  26. package/pinyin/index.js +4 -0
  27. package/pinyin/simplified.js +4 -0
  28. package/pinyin/src/core.js +143 -0
  29. package/pinyin/src/simplified.js +8 -0
  30. package/pinyin/src/simplified_dict.js +410 -0
  31. package/pinyin/src/traditional.js +8 -0
  32. package/pinyin/src/traditional_dict.js +403 -0
  33. package/pinyin/traditional.js +4 -0
  34. package/pinyin.js +4 -0
  35. package/query-string/base.d.ts +717 -0
  36. package/query-string/base.js +268 -0
  37. package/query-string/index.d.ts +16 -0
  38. package/query-string/index.js +4 -0
  39. package/query-string/splitOnFirst.js +14 -0
  40. package/queryString.js +4 -0
  41. package/random/index.js +56 -35
  42. package/snapdom/src/api/preCache.js +51 -28
  43. package/snapdom/src/core/cache.js +1 -4
  44. package/snapdom/src/core/capture.js +45 -44
  45. package/snapdom/src/core/clone.js +82 -66
  46. package/snapdom/src/core/prepare.js +167 -45
  47. package/snapdom/src/modules/background.js +29 -19
  48. package/snapdom/src/modules/fonts.js +158 -111
  49. package/snapdom/src/modules/images.js +14 -9
  50. package/snapdom/src/modules/pseudo.js +52 -47
  51. package/snapdom/src/modules/styles.js +22 -22
  52. package/snapdom/src/modules/svgDefs.js +39 -20
  53. package/snapdom/src/utils/cssTools.js +58 -51
  54. package/snapdom/src/utils/helpers.js +197 -140
  55. package/snapdom/types/snapdom.d.ts +101 -0
  56. package/types/constant/index.d.ts +11 -0
  57. package/types/constant/platform.d.ts +1 -0
  58. package/types/diff/index.d.ts +2 -0
  59. package/types/diff/src/diff.d.ts +40 -0
  60. package/types/index.d.ts +6 -1
  61. package/types/js-cookie/index.d.ts +1 -0
  62. package/types/js-cookie/src/api.d.mts +2 -0
  63. package/types/js-cookie/src/assign.d.mts +1 -0
  64. package/types/js-cookie/src/converter.d.mts +5 -0
  65. package/types/mitt/index.d.ts +2 -0
  66. package/types/mitt/src/index.d.ts +29 -0
  67. package/types/pinyin/index.d.ts +1 -0
  68. package/types/pinyin/simplified.d.ts +1 -0
  69. package/types/pinyin/src/core.d.ts +3 -0
  70. package/types/pinyin/src/simplified.d.ts +4 -0
  71. package/types/pinyin/src/simplified_dict.d.ts +408 -0
  72. package/types/pinyin/src/traditional.d.ts +4 -0
  73. package/types/pinyin/src/traditional_dict.d.ts +401 -0
  74. package/types/pinyin/traditional.d.ts +1 -0
  75. package/types/query-string/base.d.ts +11 -0
  76. package/types/query-string/index.d.ts +2 -0
  77. package/types/query-string/splitOnFirst.d.ts +1 -0
  78. package/types/random/index.d.ts +14 -23
  79. package/types/snapdom/src/api/preCache.d.ts +2 -5
  80. package/types/snapdom/src/core/cache.d.ts +0 -3
  81. package/types/snapdom/src/core/clone.d.ts +1 -1
  82. package/types/snapdom/src/modules/background.d.ts +16 -6
  83. package/types/snapdom/src/modules/fonts.d.ts +5 -1
  84. package/types/snapdom/src/modules/pseudo.d.ts +1 -1
  85. package/types/snapdom/src/modules/styles.d.ts +1 -1
  86. package/types/snapdom/src/modules/svgDefs.d.ts +13 -13
  87. package/types/snapdom/src/utils/cssTools.d.ts +2 -10
  88. package/types/snapdom/src/utils/helpers.d.ts +13 -7
  89. package/types/turbo-stream/src/shared.d.ts +3 -3
  90. package/url-toolkit/src/url-toolkit.d.ts +22 -0
  91. package/event-emitter/index.js +0 -48
  92. package/eventEmitter.js +0 -4
  93. package/types/event-emitter/index.d.ts +0 -17
@@ -1,4 +1,4 @@
1
- import { cache as r } from "../core/cache.js";
1
+ import { cache as i } from "../core/cache.js";
2
2
  const d = [
3
3
  "div",
4
4
  "span",
@@ -38,74 +38,81 @@ const d = [
38
38
  "td",
39
39
  "th"
40
40
  ];
41
- function u() {
42
- for (let e of d)
43
- c(e);
41
+ function p() {
42
+ for (let t of d)
43
+ r(t);
44
44
  }
45
- function c(e) {
46
- if (r.defaultStyle.has(e))
47
- return r.defaultStyle.get(e);
45
+ function r(t) {
46
+ if (i.defaultStyle.has(t))
47
+ return i.defaultStyle.get(t);
48
48
  if ((/* @__PURE__ */ new Set([
49
49
  "script",
50
50
  "style",
51
51
  "meta",
52
52
  "link",
53
53
  "noscript",
54
- "template"
55
- ])).has(e)) {
54
+ "template",
55
+ "defs",
56
+ "symbol",
57
+ "title",
58
+ "metadata",
59
+ "desc"
60
+ ])).has(t)) {
56
61
  const o = {};
57
- return r.defaultStyle.set(e, o), o;
62
+ return i.defaultStyle.set(t, o), o;
58
63
  }
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;
64
+ let e = document.getElementById("snapdom-sandbox");
65
+ 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));
66
+ const n = document.createElement(t);
67
+ n.style.all = "initial", e.appendChild(n);
68
+ const l = getComputedStyle(n), a = {};
69
+ for (let o of l)
70
+ a[o] = l.getPropertyValue(o);
71
+ return e.removeChild(n), i.defaultStyle.set(t, a), a;
67
72
  }
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
- else {
74
- const i = a[l];
75
- o && o !== i && n.push(`${l}:${o}`);
76
- }
73
+ const f = /* @__PURE__ */ new Set(["-webkit-locale"]);
74
+ function y(t, s, e = !1) {
75
+ const n = [], l = r(s);
76
+ for (let [a, o] of Object.entries(t))
77
+ if (!f.has(a))
78
+ if (!e)
79
+ o && n.push(`${a}:${o}`);
80
+ else {
81
+ const c = l[a];
82
+ o && o !== c && n.push(`${a}:${o}`);
83
+ }
77
84
  return n.sort().join(";");
78
85
  }
79
- function y(e) {
86
+ function h(t) {
80
87
  const s = /* @__PURE__ */ new Set();
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));
88
+ 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));
82
89
  }
83
- function h(e) {
90
+ function m(t) {
84
91
  const s = /* @__PURE__ */ new Map();
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);
92
+ for (let n of t) {
93
+ const l = i.defaultStyle.get(n);
94
+ if (!l) continue;
95
+ const a = Object.entries(l).map(([o, c]) => `${o}:${c};`).sort().join("");
96
+ s.has(a) || s.set(a, []), s.get(a).push(n);
90
97
  }
91
- let t = "";
92
- for (let [n, a] of s.entries())
93
- t += `${a.join(",")} { ${n} }
98
+ let e = "";
99
+ for (let [n, l] of s.entries())
100
+ e += `${l.join(",")} { ${n} }
94
101
  `;
95
- return t;
102
+ return e;
96
103
  }
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;
104
+ function g(t) {
105
+ const s = new Set(t.values()), e = /* @__PURE__ */ new Map();
106
+ let n = 1;
107
+ for (const l of s)
108
+ l.trim() && e.set(l, `c${n++}`);
109
+ return e;
103
110
  }
104
111
  export {
105
- y as collectUsedTagNames,
106
- m as generateCSSClasses,
107
- h as generateDedupedBaseCSS,
108
- c as getDefaultStyleForTag,
109
- p as getStyleKey,
110
- u as precacheCommonTags
112
+ h as collectUsedTagNames,
113
+ g as generateCSSClasses,
114
+ m as generateDedupedBaseCSS,
115
+ r as getDefaultStyleForTag,
116
+ y as getStyleKey,
117
+ p as precacheCommonTags
111
118
  };
@@ -1,183 +1,240 @@
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
1
+ import { cache as d } from "../core/cache.js";
2
+ async function P(e, t = {}) {
3
+ const n = $(e), c = /^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(
4
+ e
5
5
  );
6
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)})`;
7
+ const r = I(n);
8
+ if (d.background.has(r))
9
+ return t.skipInline ? void 0 : `url(${d.background.get(r)})`;
10
10
  {
11
- const c = await w(a, {
12
- useProxy: e.useProxy
11
+ const l = await U(r, {
12
+ useProxy: t.useProxy
13
13
  });
14
- return s.background.set(a, c), e.skipInline ? void 0 : `url("${c}")`;
14
+ return d.background.set(r, l), t.skipInline ? void 0 : `url("${l}")`;
15
15
  }
16
16
  }
17
- return t;
17
+ return e;
18
18
  }
19
- function S(t, { fast: e = !1 } = {}) {
20
- if (e) return t();
21
- "requestIdleCallback" in window ? requestIdleCallback(t, { timeout: 50 }) : setTimeout(t, 1);
19
+ function D(e, { fast: t = !1 } = {}) {
20
+ if (t) return e();
21
+ "requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 50 }) : setTimeout(e, 1);
22
22
  }
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);
23
+ function b(e, t = null) {
24
+ if (!(e instanceof Element))
25
+ return window.getComputedStyle(e, t);
26
+ let n = d.computedStyle.get(e);
27
+ if (n || (n = /* @__PURE__ */ new Map(), d.computedStyle.set(e, n)), !n.has(t)) {
28
+ const c = window.getComputedStyle(e, t);
29
+ n.set(t, c);
30
30
  }
31
- return n.get(e);
31
+ return n.get(t);
32
32
  }
33
- function k(t) {
34
- let e = t.replace(/^['"]|['"]$/g, "");
35
- if (e.startsWith("\\"))
33
+ function M(e) {
34
+ let t = e.replace(/^['"]|['"]$/g, "");
35
+ if (t.startsWith("\\"))
36
36
  try {
37
- return String.fromCharCode(parseInt(e.replace("\\", ""), 16));
37
+ return String.fromCharCode(parseInt(t.replace("\\", ""), 16));
38
38
  } catch {
39
- return e;
39
+ return t;
40
40
  }
41
- return e;
41
+ return t;
42
42
  }
43
- function p(t) {
44
- const e = t.match(/url\((['"]?)(.*?)(\1)\)/);
45
- if (!e) return null;
46
- const n = e[2].trim();
43
+ function $(e) {
44
+ const t = e.match(/url\((['"]?)(.*?)(\1)\)/);
45
+ if (!t) return null;
46
+ const n = t[2].trim();
47
47
  return n.startsWith("#") ? null : n;
48
48
  }
49
- function w(t, { timeout: e = 3e3, useProxy: n = "" } = {}) {
50
- function i(l) {
49
+ async function O(e, { useProxy: t = "" } = {}) {
50
+ async function n(c) {
51
+ const r = await fetch(c);
52
+ if (!r.ok) throw new Error(`[snapdom] Failed to fetch resource: ${c}`);
53
+ return r;
54
+ }
55
+ try {
56
+ return await n(e);
57
+ } catch (c) {
58
+ if (t && typeof t == "string") {
59
+ const r = t.replace(/\/$/, "") + I(e);
60
+ return n(r);
61
+ }
62
+ throw c;
63
+ }
64
+ }
65
+ var g = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map();
66
+ function U(e, { timeout: t = 3e3, useProxy: n = "", errorTTL: c = 8e3 } = {}) {
67
+ function r(o) {
51
68
  try {
52
- return new URL(l, window.location.href).origin === window.location.origin ? "use-credentials" : "anonymous";
69
+ return new URL(o, window.location.href).origin === window.location.origin ? "use-credentials" : "anonymous";
53
70
  } catch {
54
71
  return "anonymous";
55
72
  }
56
73
  }
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"));
68
- return;
69
- }
70
- r(f);
71
- }, m.onerror = () => g(new Error("FileReader error")), m.readAsDataURL(o);
72
- })
73
- );
74
+ const l = (o) => ({ ok: !0, data: o }), h = (o) => ({
75
+ ok: !1,
76
+ error: o instanceof Error ? o : new Error(String(o))
77
+ });
78
+ function x(o) {
74
79
  try {
75
- return await u(l);
76
- } catch {
80
+ return fetch(o, {
81
+ mode: "cors",
82
+ credentials: r(o) === "use-credentials" ? "include" : "omit"
83
+ }).then((s) => s.ok ? s.blob().then(
84
+ (u) => new Promise((i) => {
85
+ const f = new FileReader();
86
+ f.onloadend = () => {
87
+ const m = f.result;
88
+ typeof m != "string" || !m.startsWith("data:image/") ? i(h(new Error("Invalid image data URL"))) : i(l(m));
89
+ }, f.onerror = () => i(h(new Error("FileReader error"))), f.readAsDataURL(u);
90
+ })
91
+ ) : h(new Error("HTTP " + s.status))).catch((s) => h(s));
92
+ } catch (s) {
93
+ return Promise.resolve(h(s));
94
+ }
95
+ }
96
+ function p(o) {
97
+ return x(o).then((s) => {
98
+ if (s.ok) return s;
77
99
  if (n && typeof n == "string") {
78
- const o = n.replace(/\/$/, "") + h(l);
100
+ const u = n.replace(/\/$/, "") + I(o);
101
+ return x(u).then((i) => i.ok ? i : h(
102
+ new Error(
103
+ "[SnapDOM - fetchImage] Fetch failed and no proxy provided"
104
+ )
105
+ ));
106
+ }
107
+ return h(
108
+ new Error("[SnapDOM - fetchImage] Fetch failed and no proxy provided")
109
+ );
110
+ });
111
+ }
112
+ const E = Date.now(), S = y.get(e);
113
+ if (S && S > E) {
114
+ const o = Promise.reject(
115
+ new Error("[SnapDOM - fetchImage] Recently failed (cooldown).")
116
+ );
117
+ return o.catch(() => {
118
+ }), o;
119
+ }
120
+ if (g.has(e)) return g.get(e);
121
+ const v = r(e);
122
+ if (d.image.has(e)) return Promise.resolve(d.image.get(e));
123
+ if (e.startsWith("data:image/"))
124
+ return d.image.set(e, e), Promise.resolve(e);
125
+ if (/\.svg(\?.*)?$/i.test(e)) {
126
+ const o = (async () => {
127
+ const s = await (async () => {
79
128
  try {
80
- return await u(o);
81
- } catch {
82
- throw new Error(
83
- "[SnapDOM - fetchImage] CORS restrictions prevented image capture (even via proxy)"
129
+ const i = await fetch(e, {
130
+ mode: "cors",
131
+ credentials: v === "use-credentials" ? "include" : "omit"
132
+ });
133
+ if (!i.ok) return h(new Error("HTTP " + i.status));
134
+ const f = await i.text();
135
+ return l(
136
+ `data:image/svg+xml;charset=utf-8,${encodeURIComponent(f)}`
84
137
  );
138
+ } catch (i) {
139
+ return h(i);
85
140
  }
86
- } else
87
- throw new Error(
88
- "[SnapDOM - fetchImage] Fetch fallback failed and no proxy provided"
89
- );
90
- }
141
+ })();
142
+ if (s.ok)
143
+ return d.image.set(e, s.data), s.data;
144
+ const u = await p(e);
145
+ return u.ok ? (d.image.set(e, u.data), u.data) : (y.set(e, E + c), Promise.reject(u.error));
146
+ })();
147
+ return g.set(e, o), o.finally(() => g.delete(e)), o.catch(() => {
148
+ }), o;
91
149
  }
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);
115
- } catch {
150
+ const w = new Promise((o, s) => {
151
+ let u = !1;
152
+ const i = new Image(), f = (a) => (R) => {
153
+ u || (u = !0, clearTimeout(C), i.onload = i.onerror = null, a(R));
154
+ }, m = (a) => {
155
+ d.image.set(e, a), o(a);
156
+ }, k = (a) => {
157
+ y.set(e, Date.now() + c), s(a);
158
+ }, C = setTimeout(
159
+ f(() => {
160
+ p(e).then((a) => {
161
+ a.ok ? m(a.data) : k(new Error("Image load timed out"));
162
+ });
163
+ }),
164
+ t
165
+ );
166
+ i.crossOrigin = v, i.onload = f(() => {
167
+ Promise.resolve(i.decode()).then(() => {
116
168
  try {
117
- const r = await a(t);
118
- s.image.set(t, r), l(r);
119
- } catch (r) {
120
- u(r);
169
+ const a = document.createElement("canvas");
170
+ a.width = i.naturalWidth || i.width, a.height = i.naturalHeight || i.height, a.getContext("2d").drawImage(i, 0, 0, a.width, a.height), m(a.toDataURL("image/png"));
171
+ } catch {
172
+ p(e).then((a) => {
173
+ a.ok ? m(a.data) : k(a.error);
174
+ });
121
175
  }
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);
130
- }
131
- }, o.src = t;
176
+ }).catch(() => {
177
+ p(e).then((a) => {
178
+ a.ok ? m(a.data) : k(a.error);
179
+ });
180
+ });
181
+ }), i.onerror = f(() => {
182
+ p(e).then((a) => {
183
+ a.ok ? m(a.data) : k(a.error);
184
+ });
185
+ }), i.src = e;
132
186
  });
187
+ return g.set(e, w), w.finally(() => g.delete(e)), w.catch(() => {
188
+ }), w;
133
189
  }
134
- function C(t) {
135
- const e = {};
136
- for (let n of t)
137
- e[n] = t.getPropertyValue(n);
138
- return e;
190
+ function T(e) {
191
+ const t = {};
192
+ for (let n of e)
193
+ t[n] = e.getPropertyValue(n);
194
+ return t;
139
195
  }
140
- function v() {
196
+ function W() {
141
197
  return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
142
198
  }
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, " ");
199
+ function L(e) {
200
+ if (!e || e === "none") return "";
201
+ let t = e.replace(/translate[XY]?\([^)]*\)/g, "");
202
+ return t = t.replace(/matrix\(([^)]+)\)/g, (n, c) => {
203
+ const r = c.split(",").map((l) => l.trim());
204
+ return r.length !== 6 ? `matrix(${c})` : (r[4] = "0", r[5] = "0", `matrix(${r.join(", ")})`);
205
+ }), t = t.replace(/matrix3d\(([^)]+)\)/g, (n, c) => {
206
+ const r = c.split(",").map((l) => l.trim());
207
+ return r.length !== 16 ? `matrix3d(${c})` : (r[12] = "0", r[13] = "0", `matrix3d(${r.join(", ")})`);
208
+ }), t.trim().replace(/\s{2,}/g, " ");
153
209
  }
154
- function h(t) {
155
- if (/%[0-9A-Fa-f]{2}/.test(t)) return t;
210
+ function I(e) {
211
+ if (/%[0-9A-Fa-f]{2}/.test(e)) return e;
156
212
  try {
157
- return encodeURI(t);
213
+ return encodeURI(e);
158
214
  } catch {
159
- return t;
215
+ return e;
160
216
  }
161
217
  }
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);
218
+ function j(e) {
219
+ const t = [];
220
+ let n = 0, c = 0;
221
+ for (let r = 0; r < e.length; r++) {
222
+ const l = e[r];
223
+ l === "(" && n++, l === ")" && n--, l === "," && n === 0 && (t.push(e.slice(c, r).trim()), c = r + 1);
168
224
  }
169
- return e.push(t.slice(i).trim()), e;
225
+ return t.push(e.slice(c).trim()), t;
170
226
  }
171
227
  export {
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
228
+ $ as extractURL,
229
+ U as fetchImage,
230
+ O as fetchResource,
231
+ b as getStyle,
232
+ D as idle,
233
+ P as inlineSingleBackgroundEntry,
234
+ W as isSafari,
235
+ M as parseContent,
236
+ I as safeEncodeURI,
237
+ T as snapshotComputedStyle,
238
+ j as splitBackgroundImage,
239
+ L as stripTranslate
183
240
  };
@@ -0,0 +1,101 @@
1
+ declare module '@zumer/snapdom' {
2
+ export interface SnapOptions {
3
+ compress?: boolean;
4
+ embedFonts?: boolean;
5
+ localFonts?: Array<{
6
+ family: string;
7
+ src: string;
8
+ weight?: string;
9
+ style?: string;
10
+ }>;
11
+ iconFonts?: string | RegExp | Array<string | RegExp>;
12
+ fast?: boolean;
13
+ scale?: number;
14
+ width?: number;
15
+ height?: number;
16
+ backgroundColor?: string;
17
+ format?: 'png' | 'jpeg' | 'jpg' | 'webp' | 'svg';
18
+ type?: 'png' | 'jpeg' | 'jpg' | 'webp' | 'svg';
19
+ filename?: string;
20
+ dpr?: number;
21
+ quality?: number;
22
+ useProxy?: string;
23
+ exclude?: string[];
24
+ filter?: (element: Element, originalElement: Element) => boolean;
25
+ }
26
+
27
+ export interface SnapResult {
28
+ url: string;
29
+ options: SnapOptions;
30
+ toRaw(): string;
31
+ toImg(): Promise<HTMLImageElement>;
32
+ toCanvas(): Promise<HTMLCanvasElement>;
33
+ toBlob(options?: SnapOptions): Promise<Blob>;
34
+ toPng(options?: SnapOptions): Promise<HTMLImageElement>;
35
+ toJpg(options?: SnapOptions): Promise<HTMLImageElement>;
36
+ toWebp(options?: SnapOptions): Promise<HTMLImageElement>;
37
+ download(options?: SnapOptions): Promise<void>;
38
+ }
39
+
40
+ /**
41
+ * Captura un elemento del DOM como imagen SVG + métodos de exportación.
42
+ */
43
+ export function snapdom(
44
+ element: HTMLElement,
45
+ options?: SnapOptions,
46
+ ): Promise<SnapResult>;
47
+
48
+ export namespace snapdom {
49
+ function capture(
50
+ element: HTMLElement,
51
+ options?: SnapOptions,
52
+ ): Promise<SnapResult>;
53
+ function toRaw(
54
+ element: HTMLElement,
55
+ options?: SnapOptions,
56
+ ): Promise<string>;
57
+ function toImg(
58
+ element: HTMLElement,
59
+ options?: SnapOptions,
60
+ ): Promise<HTMLImageElement>;
61
+ function toCanvas(
62
+ element: HTMLElement,
63
+ options?: SnapOptions,
64
+ ): Promise<HTMLCanvasElement>;
65
+ function toBlob(element: HTMLElement, options?: SnapOptions): Promise<Blob>;
66
+ function toPng(
67
+ element: HTMLElement,
68
+ options?: SnapOptions,
69
+ ): Promise<HTMLImageElement>;
70
+ function toJpg(
71
+ element: HTMLElement,
72
+ options?: SnapOptions,
73
+ ): Promise<HTMLImageElement>;
74
+ function toWebp(
75
+ element: HTMLElement,
76
+ options?: SnapOptions,
77
+ ): Promise<HTMLImageElement>;
78
+ function download(
79
+ element: HTMLElement,
80
+ options?: SnapOptions,
81
+ ): Promise<void>;
82
+ }
83
+
84
+ /**
85
+ * Precarga imágenes, fondos y fuentes para acelerar capturas posteriores.
86
+ */
87
+ export function preCache(
88
+ root?: Document | HTMLElement,
89
+ options?: {
90
+ embedFonts?: boolean;
91
+ useProxy?: string;
92
+ reset?: boolean;
93
+ localFonts?: Array<{
94
+ family: string;
95
+ src: string;
96
+ weight?: string;
97
+ style?: string;
98
+ }>;
99
+ },
100
+ ): Promise<void>;
101
+ }
@@ -1 +1,12 @@
1
+ export * as date from "./address";
2
+ export * as chineseCharacters from "./chineseCharacters";
3
+ export * as constellations from "./constellations";
4
+ export * as domain from "./domain";
5
+ export * as identity from "./identity";
6
+ export * as keyboardCode from "./keyboardCode";
7
+ export * as licensePlate from "./licensePlate";
8
+ export * as name from "./name";
9
+ export * as platform from "./platform";
10
+ export * as protocol from "./protocol";
11
+ export * as ui from "./ui";
1
12
  export const MATCH_MEDIA_PREFERS_COLOR_SCHEME_DARK: MediaQueryList;
@@ -6,6 +6,7 @@ export const isIOS_OS: boolean;
6
6
  export const isAndroidOS: boolean;
7
7
  export const isHarmony: boolean;
8
8
  export const isMacOS: boolean;
9
+ export const isAppleDevice: boolean;
9
10
  export const isWindowsOS: boolean;
10
11
  export const isMobileDevice: boolean;
11
12
  export const isPWA: boolean;
@@ -0,0 +1,2 @@
1
+ export * from "./src/diff";
2
+ export { default } from "./src/diff";