@unicom-cloud/utils 0.1.5 → 0.1.11

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 (135) hide show
  1. package/caseName.js +11 -0
  2. package/className.js +5 -0
  3. package/clipboardCopy.js +6 -0
  4. package/constant.js +4 -0
  5. package/content-disposition/index.js +56 -0
  6. package/contentDisposition.js +7 -0
  7. package/convert-time/index.js +61 -0
  8. package/convertTime.js +4 -0
  9. package/cookie.js +7 -0
  10. package/dayjs.js +5 -0
  11. package/decimal.js +5 -0
  12. package/eventEmitter.js +4 -0
  13. package/file.js +6 -0
  14. package/filesize.js +8 -0
  15. package/index.js +44 -31
  16. package/invariant.js +4 -0
  17. package/is.js +92 -0
  18. package/lunar-converter/index.js +641 -0
  19. package/lunarConverter.js +4 -0
  20. package/math.js +9 -0
  21. package/md5.js +4 -0
  22. package/mock.js +8 -0
  23. package/normalizeWheel.js +6 -0
  24. package/number-to-chinese/index.js +72 -0
  25. package/numberToChinese.js +4 -0
  26. package/nzh.js +4 -0
  27. package/object-keys-sort/index.js +7 -0
  28. package/objectKeysSort.js +2 -5
  29. package/package.json +1 -1
  30. package/random.js +15 -0
  31. package/screenfull.js +4 -0
  32. package/search-tree/index.js +54 -0
  33. package/searchTree.js +4 -0
  34. package/snapdom/src/api/preCache.js +31 -27
  35. package/snapdom/src/core/capture.js +55 -44
  36. package/snapdom/src/core/clone.js +11 -11
  37. package/snapdom/src/core/prepare.js +38 -31
  38. package/snapdom/src/modules/background.js +18 -43
  39. package/snapdom/src/modules/pseudo.js +66 -67
  40. package/snapdom/src/utils/helpers.js +105 -56
  41. package/snapdom.js +6 -0
  42. package/tree.js +11 -0
  43. package/turboStream.js +6 -0
  44. package/types/case-name/index.d.ts +11 -0
  45. package/types/class-name/index.d.ts +2 -0
  46. package/types/clipboard-copy/index.d.ts +2 -0
  47. package/types/constant/address.d.ts +14 -0
  48. package/types/constant/chineseCharacters.d.ts +2 -0
  49. package/types/constant/constellations.d.ts +2 -0
  50. package/types/constant/domain.d.ts +2 -0
  51. package/types/constant/identity.d.ts +2 -0
  52. package/types/constant/index.d.ts +1 -0
  53. package/types/constant/keyboardCode.d.ts +158 -0
  54. package/types/constant/licensePlate.d.ts +2 -0
  55. package/types/constant/name.d.ts +4 -0
  56. package/types/constant/platform.d.ts +11 -0
  57. package/types/constant/protocol.d.ts +2 -0
  58. package/types/constant/ui.d.ts +14 -0
  59. package/types/content-disposition/index.d.ts +10 -0
  60. package/types/convert-time/index.d.ts +32 -0
  61. package/types/cookie/index.d.ts +4 -0
  62. package/types/cookie/src/index.d.ts +114 -0
  63. package/types/dayjs/index.d.ts +1 -0
  64. package/types/decimal/decimal.d.ts +4 -0
  65. package/types/decimal/index.d.ts +1 -0
  66. package/types/event-emitter/index.d.ts +17 -0
  67. package/types/file/fileToURL.d.ts +2 -0
  68. package/types/file/index.d.ts +3 -0
  69. package/types/file/saveAs.d.ts +2 -0
  70. package/types/filesize/index.d.ts +2 -0
  71. package/types/filesize/src/constants.d.ts +42 -0
  72. package/types/filesize/src/filesize.d.ts +47 -0
  73. package/types/index.d.ts +24 -0
  74. package/types/invariant/index.d.ts +2 -0
  75. package/types/is/index.d.ts +53 -0
  76. package/types/lunar-converter/index.d.ts +113 -0
  77. package/types/math/index.d.ts +11 -0
  78. package/types/md5/index.d.ts +2 -0
  79. package/types/mock/MockWebSocket.d.ts +17 -0
  80. package/types/mock/MockXMLHttpRequest.d.ts +17 -0
  81. package/types/mock/index.d.ts +2 -0
  82. package/types/normalize-wheel/ExecutionEnvironment.d.ts +9 -0
  83. package/types/normalize-wheel/UserAgent_DEPRECATED.d.ts +86 -0
  84. package/types/normalize-wheel/index.d.ts +115 -0
  85. package/types/normalize-wheel/isEventSupported.d.ts +16 -0
  86. package/types/number-to-chinese/index.d.ts +11 -0
  87. package/types/nzh/cn.d.ts +8 -0
  88. package/types/nzh/hk.d.ts +8 -0
  89. package/types/nzh/index.d.ts +1 -0
  90. package/types/nzh/nzh.d.ts +36 -0
  91. package/types/nzh/src/autoGet.d.ts +8 -0
  92. package/types/nzh/src/index.d.ts +34 -0
  93. package/types/nzh/src/langs/cn_b.d.ts +10 -0
  94. package/types/nzh/src/langs/cn_s.d.ts +7 -0
  95. package/types/nzh/src/langs/hk_b.d.ts +10 -0
  96. package/types/nzh/src/langs/hk_s.d.ts +7 -0
  97. package/types/nzh/src/utils.d.ts +65 -0
  98. package/types/object-keys-sort/index.d.ts +4 -0
  99. package/types/random/address.d.ts +8 -0
  100. package/types/random/constellation.d.ts +2 -0
  101. package/types/random/image.d.ts +5 -0
  102. package/types/random/index.d.ts +40 -0
  103. package/types/random/licensePlate.d.ts +2 -0
  104. package/types/random/name.d.ts +9 -0
  105. package/types/random/number.d.ts +6 -0
  106. package/types/random/text.d.ts +13 -0
  107. package/types/random/time.d.ts +2 -0
  108. package/types/random/web.d.ts +11 -0
  109. package/types/screenfull/index.d.ts +10 -0
  110. package/types/search-tree/index.d.ts +20 -0
  111. package/types/snapdom/index.d.ts +1 -0
  112. package/types/snapdom/src/api/preCache.d.ts +8 -0
  113. package/types/snapdom/src/api/snapdom.d.ts +26 -0
  114. package/types/snapdom/src/core/cache.d.ts +11 -0
  115. package/types/snapdom/src/core/capture.d.ts +17 -0
  116. package/types/snapdom/src/core/clone.d.ts +11 -0
  117. package/types/snapdom/src/core/prepare.d.ts +8 -0
  118. package/types/snapdom/src/index.browser.d.ts +1 -0
  119. package/types/snapdom/src/index.d.ts +2 -0
  120. package/types/snapdom/src/modules/background.d.ts +10 -0
  121. package/types/snapdom/src/modules/fonts.d.ts +25 -0
  122. package/types/snapdom/src/modules/images.d.ts +8 -0
  123. package/types/snapdom/src/modules/pseudo.d.ts +12 -0
  124. package/types/snapdom/src/modules/styles.d.ts +10 -0
  125. package/types/snapdom/src/utils/cssTools.d.ts +38 -0
  126. package/types/snapdom/src/utils/helpers.d.ts +71 -0
  127. package/types/tree/index.d.ts +8 -0
  128. package/types/turbo-stream/index.d.ts +1 -0
  129. package/types/turbo-stream/src/decode.d.ts +7 -0
  130. package/types/turbo-stream/src/encode.d.ts +27 -0
  131. package/types/turbo-stream/src/shared.d.ts +107 -0
  132. package/types/turbo-stream/src/turbo-stream.d.ts +4 -0
  133. package/types/url-toolkit/index.d.ts +2 -0
  134. package/types/url-toolkit/src/url-toolkit.d.ts +18 -0
  135. package/urlToolkit.js +8 -0
@@ -0,0 +1,72 @@
1
+ const h = (i) => {
2
+ const t = {
3
+ normal: {
4
+ digits: ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"],
5
+ units: ["", "十", "百", "千"],
6
+ bigUnits: ["", "万", "亿", "万亿"],
7
+ decimalUnits: ["点"]
8
+ // 普通模式小数单位
9
+ },
10
+ money: {
11
+ digits: ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"],
12
+ units: ["", "拾", "佰", "仟"],
13
+ bigUnits: ["", "万", "亿", "万亿"],
14
+ decimalUnits: ["元", "角", "分", "厘"],
15
+ // 金额模式小数单位
16
+ suffix: "整"
17
+ // 金额后缀
18
+ }
19
+ }[i.mode], d = (r) => {
20
+ let s = "";
21
+ const l = Math.floor(r).toString(), n = [];
22
+ for (let e = l.length; e > 0; e -= 4)
23
+ n.push(l.slice(Math.max(0, e - 4), e));
24
+ return n.forEach((e, c) => {
25
+ let a = "", o = !1;
26
+ for (let g = 0; g < e.length; g++) {
27
+ const m = parseInt(e[g]), u = e.length - 1 - g;
28
+ m === 0 ? o = !0 : (o && (a += t.digits[0], o = !1), a += t.digits[m] + t.units[u]);
29
+ }
30
+ a !== "" && (a += t.bigUnits[c], s = a + s);
31
+ }), i.mode === "money" && s && (s += t.decimalUnits[0]), s;
32
+ }, f = (r) => {
33
+ if (r <= 0) return "";
34
+ let s = r.toString().padStart(i.decimalDigits, "0").substring(0, i.decimalDigits);
35
+ i.trailingZeros || (s = s.replace(/0+$/, ""));
36
+ let l = "";
37
+ for (let n = 0; n < s.length; n++) {
38
+ const e = parseInt(s[n]);
39
+ e !== 0 && (l += t.digits[e] + (t.decimalUnits[n + 1] || ""));
40
+ }
41
+ return l;
42
+ };
43
+ return (r) => {
44
+ if (isNaN(r)) return "无效数字";
45
+ if (r === 0)
46
+ return i.mode === "money" ? t.digits[0] + t.decimalUnits[0] + t.suffix : t.digits[0];
47
+ let s = "";
48
+ r < 0 && (s = i.negativeSymbol, r = Math.abs(r));
49
+ const l = Math.floor(r), n = Math.round(
50
+ (r - l) * Math.pow(10, i.decimalDigits)
51
+ );
52
+ let e = s;
53
+ const c = d(l), a = f(n);
54
+ return e += c, c === "" && i.mode === "money" && (e += t.digits[0] + t.decimalUnits[0]), e += a, i.mode === "money" && a === "" && c && (e += t.suffix), i.mode === "normal" ? e.startsWith(t.digits[1] + t.units[1]) && (e = e.substring(1)) : e = e.replace(/(零[仟佰拾])+/g, "零").replace(/零+/g, "零").replace(
55
+ new RegExp(`${t.digits[0]}${t.decimalUnits[0]}`),
56
+ t.decimalUnits[0]
57
+ ), e || t.digits[0];
58
+ };
59
+ };
60
+ function U(i, t = {}) {
61
+ const d = {
62
+ mode: "normal",
63
+ negativeSymbol: "负",
64
+ decimalDigits: 4,
65
+ trailingZeros: !1,
66
+ ...t
67
+ };
68
+ return h(d)(i);
69
+ }
70
+ export {
71
+ U as default
72
+ };
@@ -0,0 +1,4 @@
1
+ import { default as o } from "./number-to-chinese/index.js";
2
+ export {
3
+ o as default
4
+ };
package/nzh.js ADDED
@@ -0,0 +1,4 @@
1
+ import { default as o } from "./nzh/nzh.js";
2
+ export {
3
+ o as default
4
+ };
@@ -0,0 +1,7 @@
1
+ function s(r) {
2
+ const o = Object.entries(r).sort((t, e) => t[0] === e[0] ? 0 : t[0] > e[0] ? 1 : -1);
3
+ return Object.fromEntries(o);
4
+ }
5
+ export {
6
+ s as default
7
+ };
package/objectKeysSort.js CHANGED
@@ -1,7 +1,4 @@
1
- function s(r) {
2
- const o = Object.entries(r).sort((t, e) => t[0] === e[0] ? 0 : t[0] > e[0] ? 1 : -1);
3
- return Object.fromEntries(o);
4
- }
1
+ import { default as o } from "./object-keys-sort/index.js";
5
2
  export {
6
- s as default
3
+ o as default
7
4
  };
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@unicom-cloud/utils","version":"0.1.5","dependencies":{},"peerDependencies":{"lodash":"^4.17.21"},"main":"./index.js","type":"module","types":"types/*","publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"}}
1
+ {"name":"@unicom-cloud/utils","version":"0.1.11","dependencies":{},"peerDependencies":{"lodash":"^4.17.21"},"main":"./index.js","type":"module","types":"types/index.d.ts","publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"}}
package/random.js ADDED
@@ -0,0 +1,15 @@
1
+ import "lodash/sample";
2
+ import "uuid";
3
+ import "./random/address.js";
4
+ import "./random/constellation.js";
5
+ import "./random/image.js";
6
+ import "./random/licensePlate.js";
7
+ import "./random/name.js";
8
+ import "./random/number.js";
9
+ import "./random/text.js";
10
+ import "./random/time.js";
11
+ import "./random/web.js";
12
+ import { default as b } from "./random/index.js";
13
+ export {
14
+ b as default
15
+ };
package/screenfull.js ADDED
@@ -0,0 +1,4 @@
1
+ import { default as o } from "./screenfull/index.js";
2
+ export {
3
+ o as default
4
+ };
@@ -0,0 +1,54 @@
1
+ function p(o, i, a = {}) {
2
+ const {
3
+ strategy: f = "BFS",
4
+ childrenKey: c = "children",
5
+ strict: u = !1
6
+ } = a;
7
+ if (!Array.isArray(o))
8
+ throw new TypeError("treeData must be an array");
9
+ if (typeof i != "object" || i === null)
10
+ throw new TypeError("searchCondition must be an object");
11
+ const t = [...o], l = (e) => {
12
+ for (const r in i) {
13
+ if (!Object.prototype.hasOwnProperty.call(e, r))
14
+ return !1;
15
+ const n = i[r], s = e[r];
16
+ if (u) {
17
+ if (s !== n)
18
+ return !1;
19
+ } else if (n instanceof RegExp) {
20
+ if (typeof s != "string" || !n.test(s))
21
+ return !1;
22
+ } else if (typeof n == "function") {
23
+ if (!n(s))
24
+ return !1;
25
+ } else if (s != n)
26
+ return !1;
27
+ }
28
+ return !0;
29
+ };
30
+ if (f === "BFS")
31
+ for (; t.length > 0; ) {
32
+ const e = t.shift();
33
+ if (!e) continue;
34
+ if (l(e))
35
+ return e;
36
+ const r = e[c];
37
+ Array.isArray(r) && t.push(...r);
38
+ }
39
+ else if (f === "DFS")
40
+ for (; t.length > 0; ) {
41
+ const e = t.pop();
42
+ if (!e) continue;
43
+ if (l(e))
44
+ return e;
45
+ const r = e[c];
46
+ Array.isArray(r) && t.push(...r.slice().reverse());
47
+ }
48
+ else
49
+ throw new Error('Invalid strategy. Use "BFS" or "DFS"');
50
+ return null;
51
+ }
52
+ export {
53
+ p as default
54
+ };
package/searchTree.js ADDED
@@ -0,0 +1,4 @@
1
+ import { default as o } from "./search-tree/index.js";
2
+ export {
3
+ o as default
4
+ };
@@ -1,43 +1,47 @@
1
- import { imageCache as n, bgCache as m, resourceCache as y, baseCSSCache as C, computedStyleCache as d } from "../core/cache.js";
2
- import { embedCustomFonts as S } from "../modules/fonts.js";
3
- import { precacheCommonTags as b } from "../utils/cssTools.js";
4
- import { fetchImage as u, extractURL as A } from "../utils/helpers.js";
5
- async function I(c = document, h = {}) {
1
+ import { imageCache as i, bgCache as u, resourceCache as h, baseCSSCache as p } from "../core/cache.js";
2
+ import { embedCustomFonts as y } from "../modules/fonts.js";
3
+ import { precacheCommonTags as d } from "../utils/cssTools.js";
4
+ import { fetchImage as C, getStyle as S, splitBackgroundImage as b, inlineSingleBackgroundEntry as A } from "../utils/helpers.js";
5
+ async function w(o = document, f = {}) {
6
6
  const {
7
- embedFonts: i = !0,
7
+ embedFonts: a = !0,
8
8
  reset: g = !1,
9
- crossOrigin: o
10
- } = h;
9
+ crossOrigin: s
10
+ } = f;
11
11
  if (g) {
12
- n.clear(), m.clear(), y.clear(), C.clear(), d.clear();
12
+ i.clear(), u.clear(), h.clear(), p.clear();
13
13
  return;
14
14
  }
15
- await document.fonts.ready, b();
16
- let l = [], f = [];
17
- c?.querySelectorAll && (l = Array.from(c.querySelectorAll("img[src]")), f = Array.from(c.querySelectorAll("*")));
15
+ await document.fonts.ready, d();
16
+ let l = [], m = [];
17
+ o?.querySelectorAll && (l = Array.from(o.querySelectorAll("img[src]")), m = Array.from(o.querySelectorAll("*")));
18
18
  const t = [];
19
- for (const s of l) {
20
- const r = s.src;
21
- if (!n.has(r)) {
22
- const e = o ? o(r) : "anonymous";
19
+ for (const c of l) {
20
+ const r = c.src;
21
+ if (!i.has(r)) {
22
+ const n = s ? s(r) : "anonymous";
23
23
  t.push(
24
- u(r, 3e3, e).then((a) => n.set(r, a)).catch(() => {
24
+ C(r, 3e3, n).then((e) => i.set(r, e)).catch(() => {
25
25
  })
26
26
  );
27
27
  }
28
28
  }
29
- for (const s of f) {
30
- const r = getComputedStyle(s).backgroundImage, e = A(r);
31
- if (e && !m.has(e)) {
32
- const a = o ? o(e) : "anonymous";
33
- t.push(
34
- u(e, 3e3, a).then((p) => m.set(e, p)).catch(() => {
35
- })
36
- );
29
+ for (const c of m) {
30
+ const r = S(c).backgroundImage;
31
+ if (r && r !== "none") {
32
+ const n = b(r);
33
+ for (const e of n)
34
+ e.startsWith("url(") && t.push(
35
+ A(e, {
36
+ crossOrigin: s,
37
+ skipInline: !0
38
+ }).catch(() => {
39
+ })
40
+ );
37
41
  }
38
42
  }
39
- i && await S({ ignoreIconFonts: !i, preCached: !0 }), await Promise.all(t);
43
+ a && await y({ ignoreIconFonts: !a, preCached: !0 }), await Promise.all(t);
40
44
  }
41
45
  export {
42
- I as preCache
46
+ w as preCache
43
47
  };
@@ -1,73 +1,84 @@
1
- import { baseCSSCache as w } from "./cache.js";
2
- import { inlineBackgroundImages as $ } from "../modules/background.js";
3
- import { embedCustomFonts as B } from "../modules/fonts.js";
4
- import { inlineImages as E } from "../modules/images.js";
5
- import { collectUsedTagNames as F, generateDedupedBaseCSS as I } from "../utils/cssTools.js";
6
- import { idle as i, isSafari as P } from "../utils/helpers.js";
7
- import { prepareClone as z } from "./prepare.js";
8
- async function L(a, l = {}) {
9
- if (!a) throw new Error("Element cannot be null or undefined");
1
+ import { baseCSSCache as S } from "./cache.js";
2
+ import { inlineBackgroundImages as P } from "../modules/background.js";
3
+ import { embedCustomFonts as z } from "../modules/fonts.js";
4
+ import { inlineImages as H } from "../modules/images.js";
5
+ import { collectUsedTagNames as A, generateDedupedBaseCSS as D } from "../utils/cssTools.js";
6
+ import { idle as l, isSafari as R } from "../utils/helpers.js";
7
+ import { prepareClone as U } from "./prepare.js";
8
+ async function Q(r, n = {}) {
9
+ if (!r) throw new Error("Element cannot be null or undefined");
10
+ if (!(r instanceof Element))
11
+ throw new Error("captureDOM: Only Element nodes are supported");
10
12
  const {
11
- compress: d = !0,
12
- embedFonts: m = !1,
13
+ compress: b = !0,
14
+ embedFonts: h = !1,
13
15
  fast: o = !0,
14
16
  scale: f = 1
15
- } = l;
16
- let t, h, p, u = "", r = "", S, v;
17
- if ({ clone: t, classCSS: h, styleCache: p } = await z(
18
- a,
19
- d,
20
- m
21
- ), await new Promise((e) => {
22
- i(
17
+ } = n;
18
+ let t, y, v, C = "", m = "", $, x;
19
+ if ({ clone: t, classCSS: y, styleCache: v } = await U(
20
+ r,
21
+ b,
22
+ h
23
+ ), await new Promise((s) => {
24
+ l(
23
25
  async () => {
24
- await E(t, l), e();
26
+ await H(t, n), s();
25
27
  },
26
28
  { fast: o }
27
29
  );
28
- }), await new Promise((e) => {
29
- i(
30
+ }), await new Promise((s) => {
31
+ l(
30
32
  async () => {
31
- await $(a, t, p, l), e();
33
+ await P(r, t, v, n), s();
32
34
  },
33
35
  { fast: o }
34
36
  );
35
- }), m && await new Promise((e) => {
36
- i(
37
+ }), h && await new Promise((s) => {
38
+ l(
37
39
  async () => {
38
- u = await B({ ignoreIconFonts: !m }), e();
40
+ C = await z({ ignoreIconFonts: !h }), s();
39
41
  },
40
42
  { fast: o }
41
43
  );
42
- }), d) {
43
- const e = F(t).sort(), s = e.join(",");
44
- w.has(s) ? r = w.get(s) : await new Promise((c) => {
45
- i(
44
+ }), b) {
45
+ const s = A(t).sort(), i = s.join(",");
46
+ S.has(i) ? m = S.get(i) : await new Promise((e) => {
47
+ l(
46
48
  () => {
47
- r = I(e), w.set(s, r), c();
49
+ m = D(s), S.set(i, m), e();
48
50
  },
49
51
  { fast: o }
50
52
  );
51
53
  });
52
54
  }
53
- await new Promise((e) => {
54
- i(
55
+ await new Promise((s) => {
56
+ l(
55
57
  () => {
56
- const s = a.getBoundingClientRect(), c = Math.ceil(s.width), C = Math.ceil(s.height);
57
- t.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"), t.style.transformOrigin = "top left", f !== 1 && P() && (t.style.scale = `${f}`);
58
- const b = "http://www.w3.org/2000/svg", n = document.createElementNS(b, "foreignObject");
59
- n.setAttribute("width", "100%"), n.setAttribute("height", "100%");
60
- const y = document.createElement("style");
61
- y.textContent = r + u + "svg{overflow:visible;}" + h, n.appendChild(y), n.appendChild(t);
62
- const x = new XMLSerializer().serializeToString(n);
63
- v = `<svg xmlns="${b}" width="${c}" height="${C}" viewBox="0 0 ${c} ${C}">` + x + "</svg>", S = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(v)}`, e();
58
+ const i = r.getBoundingClientRect();
59
+ let e = i.width, a = i.height;
60
+ const d = Number.isFinite(n.width), u = Number.isFinite(n.height), p = typeof f == "number" && f !== 1;
61
+ if (!p) {
62
+ const g = i.width / i.height;
63
+ d && u ? (e = n.width, a = n.height) : d ? (e = n.width, a = e / g) : u && (a = n.height, e = a * g);
64
+ }
65
+ if (e = Math.ceil(e), a = Math.ceil(a), t.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"), t.style.transformOrigin = "top left", !p && (d || u)) {
66
+ const g = i.width, B = i.height, I = e / g, M = a / B, N = t.style.transform || "", O = `scale(${I}, ${M})`;
67
+ t.style.transform = `${O} ${N}`.trim();
68
+ } else p && R() && (t.style.scale = `${f}`);
69
+ const E = "http://www.w3.org/2000/svg", c = document.createElementNS(E, "foreignObject");
70
+ c.setAttribute("width", "100%"), c.setAttribute("height", "100%");
71
+ const F = document.createElement("style");
72
+ F.textContent = m + C + "svg{overflow:visible;}" + y, c.appendChild(F), c.appendChild(t);
73
+ const T = new XMLSerializer().serializeToString(c);
74
+ x = `<svg xmlns="${E}" width="${e}" height="${a}" viewBox="0 0 ${e} ${a}">` + T + "</svg>", $ = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(x)}`, s();
64
75
  },
65
76
  { fast: o }
66
77
  );
67
78
  });
68
- const g = document.getElementById("snapdom-sandbox");
69
- return g && g.style.position === "absolute" && g.remove(), S;
79
+ const w = document.getElementById("snapdom-sandbox");
80
+ return w && w.style.position === "absolute" && w.remove(), $;
70
81
  }
71
82
  export {
72
- L as captureDOM
83
+ Q as captureDOM
73
84
  };
@@ -1,5 +1,5 @@
1
- import { inlineAllStyles as f } from "../modules/styles.js";
2
- function h(e, c, r, n, s) {
1
+ import { inlineAllStyles as o } from "../modules/styles.js";
2
+ function f(e, c, r, n, s) {
3
3
  if (e.nodeType === Node.ELEMENT_NODE && e.getAttribute("data-capture") === "exclude") {
4
4
  const t = document.createElement("div"), i = e.getBoundingClientRect();
5
5
  return t.style.cssText = `display: inline-block; width: ${i.width}px; height: ${i.height}px; visibility: hidden;`, t;
@@ -10,13 +10,13 @@ function h(e, c, r, n, s) {
10
10
  }
11
11
  if (e.nodeType === Node.ELEMENT_NODE && e.getAttribute("data-capture") === "placeholder") {
12
12
  const t = e.cloneNode(!1);
13
- n.set(t, e), f(e, t, c, r, s);
13
+ n.set(t, e), o(e, t, c, r, s);
14
14
  const i = document.createElement("div");
15
15
  return i.textContent = e.getAttribute("data-placeholder-text") || "", i.style.cssText = "color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;", t.appendChild(i), t;
16
16
  }
17
17
  if (e.tagName === "CANVAS") {
18
18
  const t = e.toDataURL(), i = document.createElement("img");
19
- return i.src = t, i.width = e.width, i.height = e.height, i.style.display = "inline-block", i.style.width = `${e.width}px`, i.style.height = `${e.height}px`, i;
19
+ return i.src = t, i.width = e.width, i.height = e.height, i.style.display = "inline-block", i.style.width = e.style.width || `${e.width}px`, i.style.height = e.style.height || `${e.height}px`, i;
20
20
  }
21
21
  if (e.nodeType === Node.TEXT_NODE) {
22
22
  if (e.parentElement?.shadowRoot) {
@@ -29,23 +29,23 @@ function h(e, c, r, n, s) {
29
29
  const l = e.cloneNode(!1);
30
30
  n.set(l, e), e instanceof HTMLInputElement ? (l.value = e.value, l.setAttribute("value", e.value), e.checked !== void 0 && (l.checked = e.checked, e.checked && l.setAttribute("checked", ""))) : e instanceof HTMLTextAreaElement ? (l.value = e.value, l.textContent = e.value) : e instanceof HTMLSelectElement && (l.value = e.value, Array.from(l.options).forEach((t) => {
31
31
  t.value === e.value ? t.setAttribute("selected", "") : t.removeAttribute("selected");
32
- })), f(e, l, c, r, s);
33
- const o = document.createDocumentFragment();
32
+ })), o(e, l, c, r, s);
33
+ const h = document.createDocumentFragment();
34
34
  if (e.childNodes.forEach((t) => {
35
- const i = h(
35
+ const i = f(
36
36
  t,
37
37
  c,
38
38
  r,
39
39
  n,
40
40
  s
41
41
  );
42
- i && o.appendChild(i);
43
- }), l.appendChild(o), e.shadowRoot) {
44
- const t = Array.from(e.shadowRoot.children).filter((a) => a.tagName !== "STYLE").map((a) => h(a, c, r, n)).filter(Boolean), i = document.createDocumentFragment();
42
+ i && h.appendChild(i);
43
+ }), l.appendChild(h), e.shadowRoot) {
44
+ const t = Array.from(e.shadowRoot.children).filter((a) => a.tagName !== "STYLE").map((a) => f(a, c, r, n)).filter(Boolean), i = document.createDocumentFragment();
45
45
  t.forEach((a) => i.appendChild(a)), l.appendChild(i);
46
46
  }
47
47
  return l;
48
48
  }
49
49
  export {
50
- h as deepClone
50
+ f as deepClone
51
51
  };
@@ -1,52 +1,59 @@
1
1
  import { inlinePseudoElements as m } from "../modules/pseudo.js";
2
- import { generateCSSClasses as h } from "../utils/cssTools.js";
3
- import { deepClone as g } from "./clone.js";
4
- async function S(f, r = !1, p = !1) {
5
- const l = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new Map();
6
- let c;
2
+ import { generateCSSClasses as g } from "../utils/cssTools.js";
3
+ import { stripTranslate as u } from "../utils/helpers.js";
4
+ import { deepClone as h } from "./clone.js";
5
+ async function k(s, f = !1, p = !1) {
6
+ const a = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new Map();
7
+ let t;
7
8
  try {
8
- c = g(f, l, i, d, r);
9
+ t = h(s, a, r, y, f);
9
10
  } catch (e) {
10
11
  throw console.warn("deepClone failed:", e), e;
11
12
  }
12
13
  try {
13
14
  await m(
14
- f,
15
- c,
16
- l,
17
- i,
15
+ s,
16
+ t,
17
+ a,
18
18
  r,
19
+ f,
19
20
  p
20
21
  );
21
22
  } catch (e) {
22
23
  console.warn("inlinePseudoElements failed:", e);
23
24
  }
24
- let y = "";
25
- if (r) {
26
- const e = h(l);
27
- y = Array.from(e.entries()).map(([t, n]) => `.${n}{${t}}`).join("");
28
- for (const [t, n] of l.entries()) {
29
- if (t.tagName === "STYLE") continue;
30
- const s = e.get(n);
31
- s && t.classList.add(s);
32
- const a = t.style?.backgroundImage;
33
- t.removeAttribute("style"), a && a !== "none" && (t.style.backgroundImage = a);
25
+ let d = "";
26
+ if (f) {
27
+ const e = g(a);
28
+ d = Array.from(e.entries()).map(([o, n]) => `.${n}{${o}}`).join("");
29
+ for (const [o, n] of a.entries()) {
30
+ if (o.tagName === "STYLE") continue;
31
+ const i = e.get(n);
32
+ i && o.classList.add(i);
33
+ const c = o.style?.backgroundImage;
34
+ o.removeAttribute("style"), c && c !== "none" && (o.style.backgroundImage = c);
34
35
  }
35
36
  } else
36
- for (const [e, t] of l.entries())
37
- e.tagName !== "STYLE" && e.setAttribute("style", t.replace(/;/g, "; "));
38
- for (const [e, t] of d.entries()) {
39
- const n = t.scrollLeft, s = t.scrollTop;
40
- if ((n || s) && e instanceof HTMLElement) {
37
+ for (const [e, o] of a.entries())
38
+ e.tagName !== "STYLE" && e.setAttribute("style", o.replace(/;/g, "; "));
39
+ for (const [e, o] of y.entries()) {
40
+ const n = o.scrollLeft, i = o.scrollTop;
41
+ if ((n || i) && e instanceof HTMLElement) {
41
42
  e.style.overflow = "hidden", e.style.scrollbarWidth = "none", e.style.msOverflowStyle = "none";
42
- const o = document.createElement("div");
43
- for (o.style.transform = `translate(${-n}px, ${-s}px)`, o.style.willChange = "transform", o.style.display = "inline-block", o.style.width = "100%"; e.firstChild; )
44
- o.appendChild(e.firstChild);
45
- e.appendChild(o);
43
+ const l = document.createElement("div");
44
+ for (l.style.transform = `translate(${-n}px, ${-i}px)`, l.style.willChange = "transform", l.style.display = "inline-block", l.style.width = "100%"; e.firstChild; )
45
+ l.appendChild(e.firstChild);
46
+ e.appendChild(l);
46
47
  }
47
48
  }
48
- return { clone: c, classCSS: y, styleCache: i };
49
+ if (s === y.get(t)) {
50
+ const e = r.get(s) || window.getComputedStyle(s);
51
+ r.set(s, e);
52
+ const o = u(e.transform);
53
+ t.style.margin = "0", t.style.position = "static", t.style.top = "auto", t.style.left = "auto", t.style.right = "auto", t.style.bottom = "auto", t.style.zIndex = "auto", t.style.float = "none", t.style.clear = "none", t.style.transform = o || "";
54
+ }
55
+ return { clone: t, classCSS: d, styleCache: r };
49
56
  }
50
57
  export {
51
- S as prepareClone
58
+ k as prepareClone
52
59
  };
@@ -1,50 +1,25 @@
1
- import { bgCache as u } from "../core/cache.js";
2
- import { getStyle as C, extractURL as A, fetchImage as B } from "../utils/helpers.js";
3
- async function O(k, w, c, h = {}) {
4
- const o = [[k, w]];
5
- for (; o.length; ) {
6
- const [e, i] = o.shift(), l = c.get(e) || C(e);
7
- c.has(e) || c.set(e, l);
8
- const g = l.getPropertyValue("background-image"), s = l.getPropertyValue("background-color");
9
- if (!g || g === "none") {
10
- const r = Array.from(e.children), a = Array.from(i.children);
11
- for (let t = 0; t < Math.min(r.length, a.length); t++)
12
- o.push([r[t], a[t]]);
1
+ import { getStyle as b, splitBackgroundImage as p, inlineSingleBackgroundEntry as k } from "../utils/helpers.js";
2
+ async function B(u, m, l, f = {}) {
3
+ const r = [[u, m]];
4
+ for (; r.length; ) {
5
+ const [e, o] = r.shift(), s = l.get(e) || b(e);
6
+ l.has(e) || l.set(e, s);
7
+ const c = s.getPropertyValue("background-image"), t = s.getPropertyValue("background-color");
8
+ if (!c || c === "none") {
9
+ const n = Array.from(e.children), h = Array.from(o.children);
10
+ for (let i = 0; i < Math.min(n.length, h.length); i++)
11
+ r.push([n[i], h[i]]);
13
12
  continue;
14
13
  }
15
- const U = g.split(/,(?=(?:[^()]*\([^()]*\))*[^()]*$)/).map((r) => r.trim()), m = await Promise.all(
16
- U.map(async (r) => {
17
- const a = r.startsWith("url("), t = /^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(r);
18
- if (a) {
19
- const d = A(r);
20
- if (!d) return r;
21
- try {
22
- const n = encodeURI(d);
23
- if (u.has(n))
24
- return `url(${u.get(n)})`;
25
- {
26
- const y = h.crossOrigin ? h.crossOrigin(n) : "anonymous", b = await B(n, 3e3, y);
27
- return u.set(n, b), `url(${b})`;
28
- }
29
- } catch (n) {
30
- return console.warn(
31
- "[snapdom] Failed to inline background-image:",
32
- d,
33
- n
34
- ), r;
35
- }
36
- }
37
- return r;
38
- })
14
+ const y = p(c), a = await Promise.all(
15
+ y.map((n) => k(n, f))
39
16
  );
40
- m.some(
41
- (r) => r && r !== "none" && !/^url\(undefined\)/.test(r)
42
- ) && (i.style.backgroundImage = m.join(", ")), s && s !== "transparent" && s !== "rgba(0, 0, 0, 0)" && (i.style.backgroundColor = s);
43
- const f = Array.from(e.children), p = Array.from(i.children);
44
- for (let r = 0; r < Math.min(f.length, p.length); r++)
45
- o.push([f[r], p[r]]);
17
+ a.some((n) => n && n !== "none" && !/^url\(undefined\)/.test(n)) && (o.style.backgroundImage = a.join(", ")), t && t !== "transparent" && t !== "rgba(0, 0, 0, 0)" && (o.style.backgroundColor = t);
18
+ const g = Array.from(e.children), d = Array.from(o.children);
19
+ for (let n = 0; n < Math.min(g.length, d.length); n++)
20
+ r.push([g[n], d[n]]);
46
21
  }
47
22
  }
48
23
  export {
49
- O as inlineBackgroundImages
24
+ B as inlineBackgroundImages
50
25
  };