@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.
- package/date/index.js +22 -0
- package/date.js +9 -0
- package/filesize/src/constants.js +22 -22
- package/filesize/src/filesize.js +32 -33
- package/index.js +56 -54
- package/lunar/index.js +36 -0
- package/lunar/lib/Holiday.js +42 -0
- package/lunar/lib/HolidayUtil.js +128 -0
- package/lunar/lib/I18n.js +1005 -0
- package/lunar/lib/JieQi.js +40 -0
- package/lunar/lib/Lunar.js +1035 -0
- package/lunar/lib/LunarMonth.js +150 -0
- package/lunar/lib/LunarTime.js +138 -0
- package/lunar/lib/LunarUtil.js +1752 -0
- package/lunar/lib/LunarYear.js +616 -0
- package/lunar/lib/ShouXingUtil.js +6915 -0
- package/lunar/lib/Solar.js +311 -0
- package/lunar/lib/SolarHalfYear.js +45 -0
- package/lunar/lib/SolarMonth.js +55 -0
- package/lunar/lib/SolarSeason.js +42 -0
- package/lunar/lib/SolarUtil.js +256 -0
- package/lunar/lib/SolarWeek.js +153 -0
- package/lunar/lib/SolarYear.js +35 -0
- package/lunar/lib/index.js +35 -0
- package/lunar.js +36 -0
- package/package.json +1 -1
- package/snapdom/src/api/preCache.js +27 -37
- package/snapdom/src/api/snapdom.js +75 -58
- package/snapdom/src/core/cache.js +19 -8
- package/snapdom/src/core/capture.js +49 -48
- package/snapdom/src/core/clone.js +96 -31
- package/snapdom/src/core/prepare.js +43 -37
- package/snapdom/src/modules/background.js +29 -20
- package/snapdom/src/modules/fonts.js +94 -104
- package/snapdom/src/modules/iconFonts.js +28 -0
- package/snapdom/src/modules/images.js +6 -6
- package/snapdom/src/modules/pseudo.js +52 -50
- package/snapdom/src/modules/styles.js +26 -6
- package/snapdom/src/modules/svgDefs.js +26 -0
- package/snapdom/src/utils/cssTools.js +41 -41
- package/snapdom/src/utils/helpers.js +128 -84
- package/tinycolor/index.js +46 -0
- package/tinycolor/src/conversion.js +143 -0
- package/tinycolor/src/css-color-names.js +153 -0
- package/tinycolor/src/format-input.js +77 -0
- package/tinycolor/src/from-ratio.js +21 -0
- package/tinycolor/src/index.js +404 -0
- package/tinycolor/src/random.js +221 -0
- package/tinycolor/src/readability.js +37 -0
- package/tinycolor/src/to-ms-filter.js +15 -0
- package/tinycolor/src/util.js +32 -0
- package/tinycolor.js +46 -0
- package/tree/index.js +10 -8
- package/tree/search/index.js +90 -0
- package/tree.js +9 -7
- package/types/date/index.d.ts +4 -0
- package/types/filesize/src/constants.d.ts +12 -12
- package/types/filesize/src/filesize.d.ts +63 -22
- package/types/index.d.ts +4 -3
- package/types/lunar/index.d.ts +3 -0
- package/types/lunar/lib/Holiday.d.ts +17 -0
- package/types/lunar/lib/HolidayUtil.d.ts +23 -0
- package/types/lunar/lib/I18n.d.ts +23 -0
- package/types/lunar/lib/JieQi.d.ts +15 -0
- package/types/lunar/lib/Lunar.d.ts +245 -0
- package/types/lunar/lib/LunarMonth.d.ts +35 -0
- package/types/lunar/lib/LunarTime.d.ts +40 -0
- package/types/lunar/lib/LunarUtil.d.ts +128 -0
- package/types/lunar/lib/LunarYear.d.ts +61 -0
- package/types/lunar/lib/ShouXingUtil.d.ts +38 -0
- package/types/lunar/lib/Solar.d.ts +51 -0
- package/types/lunar/lib/SolarHalfYear.d.ts +15 -0
- package/types/lunar/lib/SolarMonth.d.ts +16 -0
- package/types/lunar/lib/SolarSeason.d.ts +15 -0
- package/types/lunar/lib/SolarUtil.d.ts +20 -0
- package/types/lunar/lib/SolarWeek.d.ts +23 -0
- package/types/lunar/lib/SolarYear.d.ts +12 -0
- package/types/lunar/lib/index.d.ts +17 -0
- package/types/snapdom/src/core/cache.d.ts +17 -11
- package/types/snapdom/src/core/capture.d.ts +4 -0
- package/types/snapdom/src/core/clone.d.ts +4 -5
- package/types/snapdom/src/core/prepare.d.ts +8 -1
- package/types/snapdom/src/modules/background.d.ts +1 -2
- package/types/snapdom/src/modules/fonts.d.ts +1 -3
- package/types/snapdom/src/modules/iconFonts.d.ts +2 -0
- package/types/snapdom/src/modules/pseudo.d.ts +1 -3
- package/types/snapdom/src/modules/styles.d.ts +1 -10
- package/types/snapdom/src/modules/svgDefs.d.ts +19 -0
- package/types/snapdom/src/utils/cssTools.d.ts +1 -2
- package/types/snapdom/src/utils/helpers.d.ts +1 -1
- package/types/tinycolor/index.d.ts +2 -0
- package/types/tinycolor/src/conversion.d.ts +79 -0
- package/types/tinycolor/src/css-color-names.d.ts +4 -0
- package/types/tinycolor/src/format-input.d.ts +38 -0
- package/types/tinycolor/src/from-ratio.d.ts +14 -0
- package/types/tinycolor/src/index.d.ts +214 -0
- package/types/tinycolor/src/interfaces.d.ts +57 -0
- package/types/tinycolor/src/public_api.d.ts +10 -0
- package/types/tinycolor/src/random.d.ts +24 -0
- package/types/tinycolor/src/readability.d.ts +46 -0
- package/types/tinycolor/src/to-ms-filter.d.ts +5 -0
- package/types/tinycolor/src/umd_api.d.ts +22 -0
- package/types/tinycolor/src/util.d.ts +36 -0
- package/types/tree/index.d.ts +1 -0
- package/types/tree/search/index.d.ts +80 -0
- package/types/ui-color/compareColorByRange.d.ts +2 -0
- package/types/ui-color/index.d.ts +208 -0
- package/ui-color/compareColorByRange.js +9 -0
- package/ui-color/index.js +162 -0
- package/uiColor.js +29 -0
- package/convertTime.js +0 -4
- package/dayjs/index.js +0 -15
- package/dayjs.js +0 -5
- package/lunar-converter/index.js +0 -641
- package/lunarConverter.js +0 -4
- package/search-tree/index.js +0 -54
- package/searchTree.js +0 -4
- package/types/dayjs/index.d.ts +0 -1
- package/types/lunar-converter/index.d.ts +0 -113
- package/types/search-tree/index.d.ts +0 -20
- /package/{convert-time/index.js → date/convertTime.js} +0 -0
- /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(
|
|
4
|
-
const
|
|
5
|
-
return
|
|
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
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const n = document.createElement("canvas"),
|
|
11
|
-
n.width = Math.ceil(
|
|
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(
|
|
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
|
|
16
|
-
const
|
|
17
|
-
|
|
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
|
|
20
|
-
const n = await
|
|
21
|
-
if (!
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const g =
|
|
25
|
-
return g.fillStyle =
|
|
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
|
|
28
|
-
const g = await
|
|
29
|
-
return
|
|
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
|
|
48
|
+
async function B(a, {
|
|
32
49
|
dpr: t = 1,
|
|
33
|
-
scale:
|
|
34
|
-
backgroundColor:
|
|
50
|
+
scale: o = 1,
|
|
51
|
+
backgroundColor: e = "#fff",
|
|
35
52
|
format: n = "png",
|
|
36
|
-
filename:
|
|
53
|
+
filename: c = "capture"
|
|
37
54
|
} = {}) {
|
|
38
55
|
if (n === "svg") {
|
|
39
|
-
const
|
|
40
|
-
|
|
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,
|
|
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",
|
|
49
|
-
|
|
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(
|
|
52
|
-
if (t = { scale: 1, ...t }, !
|
|
53
|
-
return await i.capture(
|
|
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 (
|
|
56
|
-
const
|
|
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:
|
|
75
|
+
url: o,
|
|
59
76
|
options: t,
|
|
60
|
-
toRaw: () =>
|
|
61
|
-
toImg: () => x(
|
|
62
|
-
toCanvas: () =>
|
|
63
|
-
toBlob: () =>
|
|
64
|
-
toPng: (
|
|
65
|
-
toJpg: (
|
|
66
|
-
toWebp: (
|
|
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:
|
|
85
|
+
format: c = "png",
|
|
69
86
|
filename: g = "capture",
|
|
70
87
|
backgroundColor: s
|
|
71
|
-
} = {}) =>
|
|
88
|
+
} = {}) => B(o, { dpr: e, scale: n, backgroundColor: s, format: c, filename: g })
|
|
72
89
|
};
|
|
73
90
|
};
|
|
74
|
-
i.toRaw = async (
|
|
75
|
-
i.toImg = async (
|
|
76
|
-
i.toCanvas = async (
|
|
77
|
-
i.toBlob = async (
|
|
78
|
-
i.toPng = async (
|
|
79
|
-
i.toJpg = async (
|
|
80
|
-
i.toWebp = async (
|
|
81
|
-
i.download = async (
|
|
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:
|
|
84
|
-
filename:
|
|
100
|
+
format: o = "png",
|
|
101
|
+
filename: e = "capture",
|
|
85
102
|
backgroundColor: n,
|
|
86
|
-
...
|
|
103
|
+
...c
|
|
87
104
|
} = t;
|
|
88
|
-
return await (await i.capture(
|
|
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 =
|
|
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
|
-
|
|
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 {
|
|
2
|
-
import { inlineBackgroundImages as
|
|
3
|
-
import { embedCustomFonts as
|
|
4
|
-
import { inlineImages as
|
|
5
|
-
import { collectUsedTagNames as A, generateDedupedBaseCSS as
|
|
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(
|
|
9
|
-
if (!
|
|
10
|
-
|
|
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:
|
|
15
|
-
fast:
|
|
16
|
-
scale: f = 1
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
23
|
-
|
|
22
|
+
y,
|
|
23
|
+
t
|
|
24
|
+
), await new Promise((i) => {
|
|
24
25
|
l(
|
|
25
26
|
async () => {
|
|
26
|
-
await
|
|
27
|
+
await M(s, t), i();
|
|
27
28
|
},
|
|
28
|
-
{ fast:
|
|
29
|
+
{ fast: n }
|
|
29
30
|
);
|
|
30
|
-
}), await new Promise((
|
|
31
|
+
}), await new Promise((i) => {
|
|
31
32
|
l(
|
|
32
33
|
async () => {
|
|
33
|
-
await
|
|
34
|
+
await H(c, s, t), i();
|
|
34
35
|
},
|
|
35
|
-
{ fast:
|
|
36
|
+
{ fast: n }
|
|
36
37
|
);
|
|
37
|
-
}),
|
|
38
|
+
}), y && await new Promise((i) => {
|
|
38
39
|
l(
|
|
39
40
|
async () => {
|
|
40
|
-
|
|
41
|
+
v = await I(), i();
|
|
41
42
|
},
|
|
42
|
-
{ fast:
|
|
43
|
+
{ fast: n }
|
|
43
44
|
);
|
|
44
45
|
}), b) {
|
|
45
|
-
const
|
|
46
|
-
|
|
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 =
|
|
50
|
+
m = O(i), h.baseStyle.set(a, m), e();
|
|
50
51
|
},
|
|
51
|
-
{ fast:
|
|
52
|
+
{ fast: n }
|
|
52
53
|
);
|
|
53
54
|
});
|
|
54
55
|
}
|
|
55
|
-
await new Promise((
|
|
56
|
+
await new Promise((i) => {
|
|
56
57
|
l(
|
|
57
58
|
() => {
|
|
58
|
-
const
|
|
59
|
-
let e =
|
|
60
|
-
const d = Number.isFinite(
|
|
61
|
-
if (!
|
|
62
|
-
const g =
|
|
63
|
-
d && u ? (e =
|
|
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),
|
|
66
|
-
const g =
|
|
67
|
-
|
|
68
|
-
} else
|
|
69
|
-
const
|
|
70
|
-
|
|
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 +
|
|
73
|
-
const
|
|
74
|
-
|
|
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:
|
|
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 {
|
|
2
|
-
|
|
3
|
-
|
|
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:
|
|
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.
|
|
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.
|
|
36
|
+
if (e.getAttribute("data-capture") === "placeholder") {
|
|
12
37
|
const t = e.cloneNode(!1);
|
|
13
|
-
|
|
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
|
|
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,
|
|
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
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
102
|
+
a,
|
|
103
|
+
o || e
|
|
41
104
|
);
|
|
42
|
-
i &&
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
112
|
+
return c;
|
|
48
113
|
}
|
|
49
114
|
export {
|
|
50
|
-
|
|
115
|
+
u as deepClone
|
|
51
116
|
};
|
|
@@ -1,58 +1,64 @@
|
|
|
1
|
-
import {
|
|
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(
|
|
6
|
-
|
|
7
|
-
let t;
|
|
7
|
+
async function k(l, c = !1, d = !1, f = {}) {
|
|
8
|
+
let o, y = "";
|
|
8
9
|
try {
|
|
9
|
-
|
|
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
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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,
|
|
38
|
-
e.tagName !== "STYLE" && e.setAttribute("style",
|
|
39
|
-
for (const [e,
|
|
40
|
-
const
|
|
41
|
-
if ((
|
|
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
|
|
44
|
-
for (
|
|
45
|
-
|
|
46
|
-
e.appendChild(
|
|
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 (
|
|
50
|
-
const e =
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
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
|
-
|
|
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
|