@unicom-cloud/utils 0.1.11 → 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 (122) hide show
  1. package/date/index.js +22 -0
  2. package/date.js +9 -0
  3. package/filesize/src/constants.js +22 -22
  4. package/filesize/src/filesize.js +32 -33
  5. package/index.js +56 -54
  6. package/lunar/index.js +36 -0
  7. package/lunar/lib/Holiday.js +42 -0
  8. package/lunar/lib/HolidayUtil.js +128 -0
  9. package/lunar/lib/I18n.js +1005 -0
  10. package/lunar/lib/JieQi.js +40 -0
  11. package/lunar/lib/Lunar.js +1035 -0
  12. package/lunar/lib/LunarMonth.js +150 -0
  13. package/lunar/lib/LunarTime.js +138 -0
  14. package/lunar/lib/LunarUtil.js +1752 -0
  15. package/lunar/lib/LunarYear.js +616 -0
  16. package/lunar/lib/ShouXingUtil.js +6915 -0
  17. package/lunar/lib/Solar.js +311 -0
  18. package/lunar/lib/SolarHalfYear.js +45 -0
  19. package/lunar/lib/SolarMonth.js +55 -0
  20. package/lunar/lib/SolarSeason.js +42 -0
  21. package/lunar/lib/SolarUtil.js +256 -0
  22. package/lunar/lib/SolarWeek.js +153 -0
  23. package/lunar/lib/SolarYear.js +35 -0
  24. package/lunar/lib/index.js +35 -0
  25. package/lunar.js +36 -0
  26. package/package.json +1 -1
  27. package/snapdom/src/api/preCache.js +27 -37
  28. package/snapdom/src/api/snapdom.js +75 -58
  29. package/snapdom/src/core/cache.js +19 -8
  30. package/snapdom/src/core/capture.js +49 -48
  31. package/snapdom/src/core/clone.js +96 -31
  32. package/snapdom/src/core/prepare.js +43 -37
  33. package/snapdom/src/modules/background.js +29 -20
  34. package/snapdom/src/modules/fonts.js +94 -104
  35. package/snapdom/src/modules/iconFonts.js +28 -0
  36. package/snapdom/src/modules/images.js +6 -6
  37. package/snapdom/src/modules/pseudo.js +52 -50
  38. package/snapdom/src/modules/styles.js +26 -6
  39. package/snapdom/src/modules/svgDefs.js +26 -0
  40. package/snapdom/src/utils/cssTools.js +41 -41
  41. package/snapdom/src/utils/helpers.js +128 -84
  42. package/tinycolor/index.js +46 -0
  43. package/tinycolor/src/conversion.js +143 -0
  44. package/tinycolor/src/css-color-names.js +153 -0
  45. package/tinycolor/src/format-input.js +77 -0
  46. package/tinycolor/src/from-ratio.js +21 -0
  47. package/tinycolor/src/index.js +404 -0
  48. package/tinycolor/src/random.js +221 -0
  49. package/tinycolor/src/readability.js +37 -0
  50. package/tinycolor/src/to-ms-filter.js +15 -0
  51. package/tinycolor/src/util.js +32 -0
  52. package/tinycolor.js +46 -0
  53. package/tree/index.js +10 -8
  54. package/tree/search/index.js +90 -0
  55. package/tree.js +9 -7
  56. package/types/date/index.d.ts +4 -0
  57. package/types/filesize/src/constants.d.ts +12 -12
  58. package/types/filesize/src/filesize.d.ts +63 -22
  59. package/types/index.d.ts +4 -3
  60. package/types/lunar/index.d.ts +3 -0
  61. package/types/lunar/lib/Holiday.d.ts +17 -0
  62. package/types/lunar/lib/HolidayUtil.d.ts +23 -0
  63. package/types/lunar/lib/I18n.d.ts +23 -0
  64. package/types/lunar/lib/JieQi.d.ts +15 -0
  65. package/types/lunar/lib/Lunar.d.ts +245 -0
  66. package/types/lunar/lib/LunarMonth.d.ts +35 -0
  67. package/types/lunar/lib/LunarTime.d.ts +40 -0
  68. package/types/lunar/lib/LunarUtil.d.ts +128 -0
  69. package/types/lunar/lib/LunarYear.d.ts +61 -0
  70. package/types/lunar/lib/ShouXingUtil.d.ts +38 -0
  71. package/types/lunar/lib/Solar.d.ts +51 -0
  72. package/types/lunar/lib/SolarHalfYear.d.ts +15 -0
  73. package/types/lunar/lib/SolarMonth.d.ts +16 -0
  74. package/types/lunar/lib/SolarSeason.d.ts +15 -0
  75. package/types/lunar/lib/SolarUtil.d.ts +20 -0
  76. package/types/lunar/lib/SolarWeek.d.ts +23 -0
  77. package/types/lunar/lib/SolarYear.d.ts +12 -0
  78. package/types/lunar/lib/index.d.ts +17 -0
  79. package/types/snapdom/src/core/cache.d.ts +17 -11
  80. package/types/snapdom/src/core/capture.d.ts +4 -0
  81. package/types/snapdom/src/core/clone.d.ts +4 -5
  82. package/types/snapdom/src/core/prepare.d.ts +8 -1
  83. package/types/snapdom/src/modules/background.d.ts +1 -2
  84. package/types/snapdom/src/modules/fonts.d.ts +1 -3
  85. package/types/snapdom/src/modules/iconFonts.d.ts +2 -0
  86. package/types/snapdom/src/modules/pseudo.d.ts +1 -3
  87. package/types/snapdom/src/modules/styles.d.ts +1 -10
  88. package/types/snapdom/src/modules/svgDefs.d.ts +19 -0
  89. package/types/snapdom/src/utils/cssTools.d.ts +1 -2
  90. package/types/snapdom/src/utils/helpers.d.ts +1 -1
  91. package/types/tinycolor/index.d.ts +2 -0
  92. package/types/tinycolor/src/conversion.d.ts +79 -0
  93. package/types/tinycolor/src/css-color-names.d.ts +4 -0
  94. package/types/tinycolor/src/format-input.d.ts +38 -0
  95. package/types/tinycolor/src/from-ratio.d.ts +14 -0
  96. package/types/tinycolor/src/index.d.ts +214 -0
  97. package/types/tinycolor/src/interfaces.d.ts +57 -0
  98. package/types/tinycolor/src/public_api.d.ts +10 -0
  99. package/types/tinycolor/src/random.d.ts +24 -0
  100. package/types/tinycolor/src/readability.d.ts +46 -0
  101. package/types/tinycolor/src/to-ms-filter.d.ts +5 -0
  102. package/types/tinycolor/src/umd_api.d.ts +22 -0
  103. package/types/tinycolor/src/util.d.ts +36 -0
  104. package/types/tree/index.d.ts +1 -0
  105. package/types/tree/search/index.d.ts +80 -0
  106. package/types/ui-color/compareColorByRange.d.ts +2 -0
  107. package/types/ui-color/index.d.ts +208 -0
  108. package/ui-color/compareColorByRange.js +9 -0
  109. package/ui-color/index.js +162 -0
  110. package/uiColor.js +29 -0
  111. package/convertTime.js +0 -4
  112. package/dayjs/index.js +0 -15
  113. package/dayjs.js +0 -5
  114. package/lunar-converter/index.js +0 -641
  115. package/lunarConverter.js +0 -4
  116. package/search-tree/index.js +0 -54
  117. package/searchTree.js +0 -4
  118. package/types/dayjs/index.d.ts +0 -1
  119. package/types/lunar-converter/index.d.ts +0 -113
  120. package/types/search-tree/index.d.ts +0 -20
  121. /package/{convert-time/index.js → date/convertTime.js} +0 -0
  122. /package/types/{convert-time/index.d.ts → date/convertTime.d.ts} +0 -0
@@ -1,91 +1,108 @@
1
1
  import { captureDOM as v } from "../core/capture.js";
2
+ import { extendIconFonts as j } from "../modules/iconFonts.js";
2
3
  import { isSafari as R } from "../utils/helpers.js";
3
- async function x(e, { dpr: t = 1, scale: c = 1 }) {
4
- const a = new Image();
5
- return a.src = e, await a.decode(), R ? (a.width = a.width * c, a.height = a.height * c) : (a.width = a.width / c, a.height = a.height / c), a;
4
+ async function x(a, { dpr: t = 1, scale: o = 1 }) {
5
+ const e = new Image();
6
+ return e.src = a, await e.decode(), R ? (e.width = e.width * o, e.height = e.height * o) : (e.width = e.width / o, e.height = e.height / o), e;
6
7
  }
7
- async function p(e, { dpr: t = 1, scale: c = 1 } = {}) {
8
- const a = new Image();
9
- a.src = e, await a.decode();
10
- const n = document.createElement("canvas"), o = a.width * c, g = a.height * c;
11
- n.width = Math.ceil(o * t), n.height = Math.ceil(g * t);
8
+ async function l(a, { dpr: t = 1, scale: o = 1 } = {}) {
9
+ const e = new Image();
10
+ e.src = a, await e.decode();
11
+ const n = document.createElement("canvas"), c = e.width * o, g = e.height * o;
12
+ n.width = Math.ceil(c * t), n.height = Math.ceil(g * t);
12
13
  const s = n.getContext("2d");
13
- return s.scale(t, t), s.drawImage(a, 0, 0, o, g), n.style.width = `${o}px`, n.style.height = `${g}px`, n;
14
+ return s.scale(t, t), s.drawImage(e, 0, 0, c, g), n.style.width = `${c}px`, n.style.height = `${g}px`, n;
14
15
  }
15
- async function u(e) {
16
- const t = decodeURIComponent(e.split(",")[1]);
17
- return new Blob([t], { type: "image/svg+xml" });
16
+ async function f(a, { type: t = "svg", scale: o = 1, backgroundColor: e = "#fff", quality: n } = {}) {
17
+ const c = {
18
+ jpg: "image/jpeg",
19
+ jpeg: "image/jpeg",
20
+ png: "image/png",
21
+ webp: "image/webp"
22
+ }[t] || "image/png";
23
+ if (t === "svg") {
24
+ const s = decodeURIComponent(a.split(",")[1]);
25
+ return new Blob([s], { type: "image/svg+xml" });
26
+ }
27
+ const g = await m(
28
+ a,
29
+ { dpr: 1, scale: o },
30
+ e
31
+ );
32
+ return new Promise((s) => {
33
+ g.toBlob((r) => s(r), `${c}`, n);
34
+ });
18
35
  }
19
- async function l(e, { dpr: t = 1, scale: c = 1 }, a) {
20
- const n = await p(e, { dpr: t, scale: c });
21
- if (!a) return n;
22
- const o = document.createElement("canvas");
23
- o.width = n.width, o.height = n.height;
24
- const g = o.getContext("2d");
25
- return g.fillStyle = a, g.fillRect(0, 0, o.width, o.height), g.drawImage(n, 0, 0), o;
36
+ async function m(a, { dpr: t = 1, scale: o = 1 }, e) {
37
+ const n = await l(a, { dpr: t, scale: o });
38
+ if (!e) return n;
39
+ const c = document.createElement("canvas");
40
+ c.width = n.width, c.height = n.height;
41
+ const g = c.getContext("2d");
42
+ return g.fillStyle = e, g.fillRect(0, 0, c.width, c.height), g.drawImage(n, 0, 0), c;
26
43
  }
27
- async function d(e, { dpr: t = 1, scale: c = 1, backgroundColor: a = "#fff", quality: n }, o = "png") {
28
- const g = await l(e, { dpr: t, scale: c }, a), s = new Image();
29
- return s.src = g.toDataURL(`image/${o}`, n), await s.decode(), s.style.width = `${g.width / t}px`, s.style.height = `${g.height / t}px`, s;
44
+ async function u(a, { dpr: t = 1, scale: o = 1, backgroundColor: e, quality: n }, c = "png") {
45
+ const g = ["jpg", "jpeg", "webp"].includes(c) ? "#fff" : void 0, r = await m(a, { dpr: t, scale: o }, e ?? g), w = new Image();
46
+ return w.src = r.toDataURL(`image/${c}`, n), await w.decode(), w.style.width = `${r.width / t}px`, w.style.height = `${r.height / t}px`, w;
30
47
  }
31
- async function I(e, {
48
+ async function B(a, {
32
49
  dpr: t = 1,
33
- scale: c = 1,
34
- backgroundColor: a = "#fff",
50
+ scale: o = 1,
51
+ backgroundColor: e = "#fff",
35
52
  format: n = "png",
36
- filename: o = "capture"
53
+ filename: c = "capture"
37
54
  } = {}) {
38
55
  if (n === "svg") {
39
- const b = await u(e), h = URL.createObjectURL(b), w = document.createElement("a");
40
- w.href = h, w.download = `${o}.svg`, w.click(), URL.revokeObjectURL(h);
56
+ const y = await f(a), h = URL.createObjectURL(y), p = document.createElement("a");
57
+ p.href = h, p.download = `${c}.svg`, p.click(), URL.revokeObjectURL(h);
41
58
  return;
42
59
  }
43
- const g = ["jpg", "jpeg", "webp"].includes(n) ? "#fff" : void 0, m = await l(e, { dpr: t, scale: c }, a ?? g), f = {
60
+ const g = ["jpg", "jpeg", "webp"].includes(n) ? "#fff" : void 0, r = await m(a, { dpr: t, scale: o }, e ?? g), w = {
44
61
  jpg: "image/jpeg",
45
62
  jpeg: "image/jpeg",
46
63
  png: "image/png",
47
64
  webp: "image/webp"
48
- }[n] || "image/png", y = m.toDataURL(f), r = document.createElement("a");
49
- r.href = y, r.download = `${o}.${n}`, r.click();
65
+ }[n] || "image/png", b = r.toDataURL(w), d = document.createElement("a");
66
+ d.href = b, d.download = `${c}.${n}`, d.click();
50
67
  }
51
- async function i(e, t = {}) {
52
- if (t = { scale: 1, ...t }, !e) throw new Error("Element cannot be null or undefined");
53
- return await i.capture(e, t);
68
+ async function i(a, t = {}) {
69
+ if (t = { scale: 1, ...t }, !a) throw new Error("Element cannot be null or undefined");
70
+ return t.iconFonts && j(t.iconFonts), await i.capture(a, t);
54
71
  }
55
- i.capture = async (e, t = {}) => {
56
- const c = await v(e, t), a = window.devicePixelRatio || 1, n = t.scale || 1;
72
+ i.capture = async (a, t = {}) => {
73
+ const o = await v(a, t), e = window.devicePixelRatio || 1, n = t.scale || 1;
57
74
  return {
58
- url: c,
75
+ url: o,
59
76
  options: t,
60
- toRaw: () => c,
61
- toImg: () => x(c, { dpr: a, scale: n }),
62
- toCanvas: () => p(c, { dpr: a, scale: n }),
63
- toBlob: () => u(c),
64
- toPng: (o) => d(c, { dpr: a, scale: n, ...o }, "png"),
65
- toJpg: (o) => d(c, { dpr: a, scale: n, ...o }, "jpeg"),
66
- toWebp: (o) => d(c, { dpr: a, scale: n, ...o }, "webp"),
77
+ toRaw: () => o,
78
+ toImg: () => x(o, { dpr: e, scale: n }),
79
+ toCanvas: () => l(o, { dpr: e, scale: n }),
80
+ toBlob: (c) => f(o, { scale: n, ...c }),
81
+ toPng: (c) => u(o, { dpr: e, scale: n, ...c }, "png"),
82
+ toJpg: (c) => u(o, { dpr: e, scale: n, ...c }, "jpeg"),
83
+ toWebp: (c) => u(o, { dpr: e, scale: n, ...c }, "webp"),
67
84
  download: ({
68
- format: o = "png",
85
+ format: c = "png",
69
86
  filename: g = "capture",
70
87
  backgroundColor: s
71
- } = {}) => I(c, { dpr: a, scale: n, backgroundColor: s, format: o, filename: g })
88
+ } = {}) => B(o, { dpr: e, scale: n, backgroundColor: s, format: c, filename: g })
72
89
  };
73
90
  };
74
- i.toRaw = async (e, t) => (await i.capture(e, t)).toRaw();
75
- i.toImg = async (e, t) => (await i.capture(e, t)).toImg();
76
- i.toCanvas = async (e, t) => (await i.capture(e, t)).toCanvas();
77
- i.toBlob = async (e, t) => (await i.capture(e, t)).toBlob();
78
- i.toPng = async (e, t) => (await i.capture(e, t)).toPng(t);
79
- i.toJpg = async (e, t) => (await i.capture(e, t)).toJpg(t);
80
- i.toWebp = async (e, t) => (await i.capture(e, t)).toWebp(t);
81
- i.download = async (e, t = {}) => {
91
+ i.toRaw = async (a, t) => (await i.capture(a, t)).toRaw();
92
+ i.toImg = async (a, t) => (await i.capture(a, t)).toImg();
93
+ i.toCanvas = async (a, t) => (await i.capture(a, t)).toCanvas();
94
+ i.toBlob = async (a, t) => (await i.capture(a, t)).toBlob(t);
95
+ i.toPng = async (a, t) => (await i.capture(a, t)).toPng(t);
96
+ i.toJpg = async (a, t) => (await i.capture(a, t)).toJpg(t);
97
+ i.toWebp = async (a, t) => (await i.capture(a, t)).toWebp(t);
98
+ i.download = async (a, t = {}) => {
82
99
  const {
83
- format: c = "png",
84
- filename: a = "capture",
100
+ format: o = "png",
101
+ filename: e = "capture",
85
102
  backgroundColor: n,
86
- ...o
103
+ ...c
87
104
  } = t;
88
- return await (await i.capture(e, o)).download({ format: c, filename: a, backgroundColor: n });
105
+ return await (await i.capture(a, c)).download({ format: o, filename: e, backgroundColor: n });
89
106
  };
90
107
  export {
91
108
  i as snapdom
@@ -1,10 +1,21 @@
1
- const e = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new Set();
1
+ const e = {
2
+ image: /* @__PURE__ */ new Map(),
3
+ background: /* @__PURE__ */ new Map(),
4
+ resource: /* @__PURE__ */ new Map(),
5
+ defaultStyle: /* @__PURE__ */ new Map(),
6
+ baseStyle: /* @__PURE__ */ new Map(),
7
+ computedStyle: /* @__PURE__ */ new WeakMap(),
8
+ font: /* @__PURE__ */ new Set(),
9
+ snapshot: /* @__PURE__ */ new WeakMap(),
10
+ snapshotKey: /* @__PURE__ */ new Map(),
11
+ preStyleMap: /* @__PURE__ */ new Map(),
12
+ preStyle: /* @__PURE__ */ new WeakMap(),
13
+ preNodeMap: /* @__PURE__ */ new Map(),
14
+ reset: a
15
+ };
16
+ function a() {
17
+ e.computedStyle = /* @__PURE__ */ new WeakMap(), e.snapshot = /* @__PURE__ */ new WeakMap(), e.snapshotKey.clear(), e.preStyleMap.clear(), e.preStyle = /* @__PURE__ */ new WeakMap(), e.preNodeMap.clear();
18
+ }
2
19
  export {
3
- t as baseCSSCache,
4
- a as bgCache,
5
- s as computedStyleCache,
6
- n as defaultStylesCache,
7
- e as imageCache,
8
- o as processedFontURLs,
9
- c as resourceCache
20
+ e as cache
10
21
  };
@@ -1,83 +1,84 @@
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";
1
+ import { cache as h } from "./cache.js";
2
+ import { inlineBackgroundImages as H } from "../modules/background.js";
3
+ import { embedCustomFonts as I } from "../modules/fonts.js";
4
+ import { inlineImages as M } from "../modules/images.js";
5
+ import { collectUsedTagNames as A, generateDedupedBaseCSS as O } from "../utils/cssTools.js";
6
6
  import { idle as l, isSafari as R } from "../utils/helpers.js";
7
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");
8
+ async function Q(c, t = {}) {
9
+ if (!c) throw new Error("Element cannot be null or undefined");
10
+ h.reset();
12
11
  const {
13
12
  compress: b = !0,
14
- embedFonts: h = !1,
15
- fast: o = !0,
16
- scale: f = 1
17
- } = n;
18
- let t, y, v, C = "", m = "", $, x;
19
- if ({ clone: t, classCSS: y, styleCache: v } = await U(
20
- r,
13
+ embedFonts: y = !1,
14
+ fast: n = !0,
15
+ scale: f = 1,
16
+ useProxy: j = ""
17
+ } = t;
18
+ let s, p, v = "", m = "", x, C;
19
+ if ({ clone: s, classCSS: p } = await U(
20
+ c,
21
21
  b,
22
- h
23
- ), await new Promise((s) => {
22
+ y,
23
+ t
24
+ ), await new Promise((i) => {
24
25
  l(
25
26
  async () => {
26
- await H(t, n), s();
27
+ await M(s, t), i();
27
28
  },
28
- { fast: o }
29
+ { fast: n }
29
30
  );
30
- }), await new Promise((s) => {
31
+ }), await new Promise((i) => {
31
32
  l(
32
33
  async () => {
33
- await P(r, t, v, n), s();
34
+ await H(c, s, t), i();
34
35
  },
35
- { fast: o }
36
+ { fast: n }
36
37
  );
37
- }), h && await new Promise((s) => {
38
+ }), y && await new Promise((i) => {
38
39
  l(
39
40
  async () => {
40
- C = await z({ ignoreIconFonts: !h }), s();
41
+ v = await I(), i();
41
42
  },
42
- { fast: o }
43
+ { fast: n }
43
44
  );
44
45
  }), b) {
45
- const s = A(t).sort(), i = s.join(",");
46
- S.has(i) ? m = S.get(i) : await new Promise((e) => {
46
+ const i = A(s).sort(), a = i.join(",");
47
+ h.baseStyle.has(a) ? m = h.baseStyle.get(a) : await new Promise((e) => {
47
48
  l(
48
49
  () => {
49
- m = D(s), S.set(i, m), e();
50
+ m = O(i), h.baseStyle.set(a, m), e();
50
51
  },
51
- { fast: o }
52
+ { fast: n }
52
53
  );
53
54
  });
54
55
  }
55
- await new Promise((s) => {
56
+ await new Promise((i) => {
56
57
  l(
57
58
  () => {
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);
59
+ const a = c.getBoundingClientRect();
60
+ let e = a.width, r = a.height;
61
+ const d = Number.isFinite(t.width), u = Number.isFinite(t.height), S = typeof f == "number" && f !== 1;
62
+ if (!S) {
63
+ const g = a.width / a.height;
64
+ d && u ? (e = t.width, r = t.height) : d ? (e = t.width, r = e / g) : u && (r = t.height, e = r * g);
64
65
  }
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%");
66
+ if (e = Math.ceil(e), r = Math.ceil(r), s.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"), s.style.transformOrigin = "top left", !S && (d || u)) {
67
+ const g = a.width, T = a.height, B = e / g, E = r / T, N = s.style.transform || "", z = `scale(${B}, ${E})`;
68
+ s.style.transform = `${z} ${N}`.trim();
69
+ } else S && R() && (s.style.scale = `${f}`);
70
+ const $ = "http://www.w3.org/2000/svg", o = document.createElementNS($, "foreignObject");
71
+ o.setAttribute("width", "100%"), o.setAttribute("height", "100%");
71
72
  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();
73
+ F.textContent = m + v + "svg{overflow:visible;}" + p, o.appendChild(F), o.appendChild(s);
74
+ const P = new XMLSerializer().serializeToString(o);
75
+ C = `<svg xmlns="${$}" width="${e}" height="${r}" viewBox="0 0 ${e} ${r}">` + P + "</svg>", x = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(C)}`, i();
75
76
  },
76
- { fast: o }
77
+ { fast: n }
77
78
  );
78
79
  });
79
80
  const w = document.getElementById("snapdom-sandbox");
80
- return w && w.style.position === "absolute" && w.remove(), $;
81
+ return w && w.style.position === "absolute" && w.remove(), x;
81
82
  }
82
83
  export {
83
84
  Q as captureDOM
@@ -1,51 +1,116 @@
1
- import { inlineAllStyles as o } from "../modules/styles.js";
2
- function f(e, c, r, n, s) {
3
- if (e.nodeType === Node.ELEMENT_NODE && e.getAttribute("data-capture") === "exclude") {
1
+ import { cache as r } from "./cache.js";
2
+ import { inlineAllStyles as f } from "../modules/styles.js";
3
+ function u(e, n, a = {}, o) {
4
+ if (!e) throw new Error("Invalid node");
5
+ const p = /* @__PURE__ */ new Set();
6
+ let d = null;
7
+ if (e.nodeType === Node.TEXT_NODE || e.nodeType !== Node.ELEMENT_NODE)
8
+ return e.cloneNode(!0);
9
+ if (e.getAttribute("data-capture") === "exclude") {
4
10
  const t = document.createElement("div"), i = e.getBoundingClientRect();
5
- return t.style.cssText = `display: inline-block; width: ${i.width}px; height: ${i.height}px; visibility: hidden;`, t;
11
+ return t.style.cssText = `display:inline-block;width:${i.width}px;height:${i.height}px;visibility:hidden;`, t;
6
12
  }
13
+ if (a.exclude && Array.isArray(a.exclude))
14
+ for (const t of a.exclude)
15
+ try {
16
+ if (e.matches?.(t)) {
17
+ const i = document.createElement("div"), l = e.getBoundingClientRect();
18
+ return i.style.cssText = `display:inline-block;width:${l.width}px;height:${l.height}px;visibility:hidden;`, i;
19
+ }
20
+ } catch (i) {
21
+ console.warn(`Invalid selector in exclude option: ${t}`, i);
22
+ }
23
+ if (typeof a.filter == "function")
24
+ try {
25
+ if (!a.filter(e, o || e)) {
26
+ const t = document.createElement("div"), i = e.getBoundingClientRect();
27
+ return t.style.cssText = `display:inline-block;width:${i.width}px;height:${i.height}px;visibility:hidden;`, t;
28
+ }
29
+ } catch (t) {
30
+ console.warn("Error in filter function:", t);
31
+ }
7
32
  if (e.tagName === "IFRAME") {
8
33
  const t = document.createElement("div");
9
- return t.textContent = "", t.style.cssText = `width: ${e.offsetWidth}px; height: ${e.offsetHeight}px; background-image: repeating-linear-gradient(45deg, #ddd, #ddd 5px, #f9f9f9 5px, #f9f9f9 10px);display: flex;align-items: center;justify-content: center;font-size: 12px;color: #555; border: 1px solid #aaa;`, t;
34
+ return t.style.cssText = `width:${e.offsetWidth}px;height:${e.offsetHeight}px;background-image:repeating-linear-gradient(45deg,#ddd,#ddd 5px,#f9f9f9 5px,#f9f9f9 10px);display:flex;align-items:center;justify-content:center;font-size:12px;color:#555;border:1px solid #aaa;`, t;
10
35
  }
11
- if (e.nodeType === Node.ELEMENT_NODE && e.getAttribute("data-capture") === "placeholder") {
36
+ if (e.getAttribute("data-capture") === "placeholder") {
12
37
  const t = e.cloneNode(!1);
13
- n.set(t, e), o(e, t, c, r, s);
38
+ r.preNodeMap.set(t, e), f(e, t, n);
14
39
  const i = document.createElement("div");
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;
40
+ 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
41
  }
17
42
  if (e.tagName === "CANVAS") {
18
43
  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.style.width || `${e.width}px`, i.style.height = e.style.height || `${e.height}px`, i;
44
+ return i.src = t, i.width = e.width, i.height = e.height, r.preNodeMap.set(i, e), f(e, i, n), i;
45
+ }
46
+ let c;
47
+ try {
48
+ c = e.cloneNode(!1), r.preNodeMap.set(c, e);
49
+ } catch (t) {
50
+ throw console.error("[Snapdom] Failed to clone node:", e, t), t;
51
+ }
52
+ if (e instanceof HTMLTextAreaElement) {
53
+ c.textContent = e.value, c.value = e.value;
54
+ const t = e.getBoundingClientRect();
55
+ return c.style.width = `${t.width}px`, c.style.height = `${t.height}px`, c;
20
56
  }
21
- if (e.nodeType === Node.TEXT_NODE) {
22
- if (e.parentElement?.shadowRoot) {
23
- const t = e.parentElement.tagName.toLowerCase();
24
- if (customElements.get(t)) return null;
57
+ if (e instanceof HTMLInputElement)
58
+ return c.value = e.value, c.setAttribute("value", e.value), e.checked !== void 0 && (c.checked = e.checked, e.checked && c.setAttribute("checked", ""), e.indeterminate && (c.indeterminate = e.indeterminate)), c;
59
+ if (e instanceof HTMLSelectElement && (d = e.value), f(e, c, n), e.shadowRoot)
60
+ if (Array.from(e.shadowRoot.querySelectorAll("slot")).length > 0) {
61
+ for (const i of e.shadowRoot.childNodes)
62
+ if (i.nodeType === Node.ELEMENT_NODE && i.tagName === "STYLE") {
63
+ const l = i.textContent || "";
64
+ l.trim() && n && (r.preStyle || (r.preStyle = /* @__PURE__ */ new WeakMap()), r.preStyle.set(i, l));
65
+ }
66
+ } else {
67
+ const i = document.createDocumentFragment();
68
+ for (const l of e.shadowRoot.childNodes) {
69
+ if (l.nodeType === Node.ELEMENT_NODE && l.tagName === "STYLE") {
70
+ const s = l.textContent || "";
71
+ s.trim() && n && (r.preStyle || (r.preStyle = /* @__PURE__ */ new WeakMap()), r.preStyle.set(l, s));
72
+ continue;
73
+ }
74
+ const h = u(
75
+ l,
76
+ n,
77
+ a,
78
+ o || e
79
+ );
80
+ h && i.appendChild(h);
81
+ }
82
+ c.appendChild(i);
25
83
  }
26
- return e.cloneNode(!0);
84
+ if (e.tagName === "SLOT") {
85
+ const t = e.assignedNodes?.({ flatten: !0 }) || [], i = t.length > 0 ? t : Array.from(e.childNodes), l = document.createDocumentFragment();
86
+ for (const h of i) {
87
+ const s = u(
88
+ h,
89
+ n,
90
+ a,
91
+ o || e
92
+ );
93
+ s && l.appendChild(s);
94
+ }
95
+ return l;
27
96
  }
28
- if (e.nodeType !== Node.ELEMENT_NODE) return e.cloneNode(!0);
29
- const l = e.cloneNode(!1);
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
- t.value === e.value ? t.setAttribute("selected", "") : t.removeAttribute("selected");
32
- })), o(e, l, c, r, s);
33
- const h = document.createDocumentFragment();
34
- if (e.childNodes.forEach((t) => {
35
- const i = f(
97
+ for (const t of e.childNodes) {
98
+ if (p.has(t)) continue;
99
+ const i = u(
36
100
  t,
37
- c,
38
- r,
39
101
  n,
40
- s
102
+ a,
103
+ o || e
41
104
  );
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
- t.forEach((a) => i.appendChild(a)), l.appendChild(i);
105
+ i && c.appendChild(i);
106
+ }
107
+ if (d !== null && c instanceof HTMLSelectElement) {
108
+ c.value = d;
109
+ for (const t of c.options)
110
+ t.value === d ? t.setAttribute("selected", "") : t.removeAttribute("selected");
46
111
  }
47
- return l;
112
+ return c;
48
113
  }
49
114
  export {
50
- f as deepClone
115
+ u as deepClone
51
116
  };
@@ -1,58 +1,64 @@
1
- import { inlinePseudoElements as m } from "../modules/pseudo.js";
1
+ import { cache as n } from "./cache.js";
2
+ import { inlinePseudoElements as p } from "../modules/pseudo.js";
3
+ import { inlineExternalDef as m } from "../modules/svgDefs.js";
2
4
  import { generateCSSClasses as g } from "../utils/cssTools.js";
3
5
  import { stripTranslate as u } from "../utils/helpers.js";
4
6
  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
+ async function k(l, c = !1, d = !1, f = {}) {
8
+ let o, y = "";
8
9
  try {
9
- t = h(s, a, r, y, f);
10
+ o = h(l, c, f, l);
10
11
  } catch (e) {
11
12
  throw console.warn("deepClone failed:", e), e;
12
13
  }
13
14
  try {
14
- await m(
15
- s,
16
- t,
17
- a,
18
- r,
19
- f,
20
- p
15
+ await p(
16
+ l,
17
+ o,
18
+ c,
19
+ d,
20
+ f.useProxy
21
21
  );
22
22
  } catch (e) {
23
23
  console.warn("inlinePseudoElements failed:", e);
24
24
  }
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);
25
+ try {
26
+ m(o);
27
+ } catch (e) {
28
+ console.warn("inlineExternalDef failed:", e);
29
+ }
30
+ if (c) {
31
+ const e = g();
32
+ y = Array.from(e.entries()).map(([t, r]) => `.${r}{${t}}`).join("");
33
+ for (const [t, r] of n.preStyleMap.entries()) {
34
+ if (t.tagName === "STYLE") continue;
35
+ const a = e.get(r);
36
+ a && t.classList.add(a);
37
+ const i = t.style?.backgroundImage;
38
+ t.removeAttribute("style"), i && i !== "none" && (t.style.backgroundImage = i);
35
39
  }
36
40
  } else
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
+ for (const [e, t] of n.preStyleMap.entries())
42
+ e.tagName !== "STYLE" && e.setAttribute("style", t.replace(/;/g, "; "));
43
+ for (const [e, t] of n.preNodeMap.entries()) {
44
+ const r = t.scrollLeft, a = t.scrollTop;
45
+ if ((r || a) && e instanceof HTMLElement) {
42
46
  e.style.overflow = "hidden", e.style.scrollbarWidth = "none", e.style.msOverflowStyle = "none";
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);
47
+ const s = document.createElement("div");
48
+ for (s.style.transform = `translate(${-r}px, ${-a}px)`, s.style.willChange = "transform", s.style.display = "inline-block", s.style.width = "100%"; e.firstChild; )
49
+ s.appendChild(e.firstChild);
50
+ e.appendChild(s);
47
51
  }
48
52
  }
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 || "";
53
+ if (l === n.preNodeMap.get(o)) {
54
+ const e = n.preStyle.get(l) || window.getComputedStyle(l);
55
+ n.preStyle.set(l, e);
56
+ const t = u(e.transform);
57
+ o.style.margin = "0", o.style.position = "static", o.style.top = "auto", o.style.left = "auto", o.style.right = "auto", o.style.bottom = "auto", o.style.zIndex = "auto", o.style.float = "none", o.style.clear = "none", o.style.transform = t || "";
54
58
  }
55
- return { clone: t, classCSS: d, styleCache: r };
59
+ for (const [e, t] of n.preNodeMap.entries())
60
+ t.tagName === "PRE" && (e.style.marginTop = "0", e.style.marginBlockStart = "0");
61
+ return { clone: o, classCSS: y };
56
62
  }
57
63
  export {
58
64
  k as prepareClone