@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.
- package/caseName.js +11 -0
- package/className.js +5 -0
- package/clipboardCopy.js +6 -0
- package/constant.js +4 -0
- package/content-disposition/index.js +56 -0
- package/contentDisposition.js +7 -0
- package/convert-time/index.js +61 -0
- package/convertTime.js +4 -0
- package/cookie.js +7 -0
- package/dayjs.js +5 -0
- package/decimal.js +5 -0
- package/eventEmitter.js +4 -0
- package/file.js +6 -0
- package/filesize.js +8 -0
- package/index.js +44 -31
- package/invariant.js +4 -0
- package/is.js +92 -0
- package/lunar-converter/index.js +641 -0
- package/lunarConverter.js +4 -0
- package/math.js +9 -0
- package/md5.js +4 -0
- package/mock.js +8 -0
- package/normalizeWheel.js +6 -0
- package/number-to-chinese/index.js +72 -0
- package/numberToChinese.js +4 -0
- package/nzh.js +4 -0
- package/object-keys-sort/index.js +7 -0
- package/objectKeysSort.js +2 -5
- package/package.json +1 -1
- package/random.js +15 -0
- package/screenfull.js +4 -0
- package/search-tree/index.js +54 -0
- package/searchTree.js +4 -0
- package/snapdom/src/api/preCache.js +31 -27
- package/snapdom/src/core/capture.js +55 -44
- package/snapdom/src/core/clone.js +11 -11
- package/snapdom/src/core/prepare.js +38 -31
- package/snapdom/src/modules/background.js +18 -43
- package/snapdom/src/modules/pseudo.js +66 -67
- package/snapdom/src/utils/helpers.js +105 -56
- package/snapdom.js +6 -0
- package/tree.js +11 -0
- package/turboStream.js +6 -0
- package/types/case-name/index.d.ts +11 -0
- package/types/class-name/index.d.ts +2 -0
- package/types/clipboard-copy/index.d.ts +2 -0
- package/types/constant/address.d.ts +14 -0
- package/types/constant/chineseCharacters.d.ts +2 -0
- package/types/constant/constellations.d.ts +2 -0
- package/types/constant/domain.d.ts +2 -0
- package/types/constant/identity.d.ts +2 -0
- package/types/constant/index.d.ts +1 -0
- package/types/constant/keyboardCode.d.ts +158 -0
- package/types/constant/licensePlate.d.ts +2 -0
- package/types/constant/name.d.ts +4 -0
- package/types/constant/platform.d.ts +11 -0
- package/types/constant/protocol.d.ts +2 -0
- package/types/constant/ui.d.ts +14 -0
- package/types/content-disposition/index.d.ts +10 -0
- package/types/convert-time/index.d.ts +32 -0
- package/types/cookie/index.d.ts +4 -0
- package/types/cookie/src/index.d.ts +114 -0
- package/types/dayjs/index.d.ts +1 -0
- package/types/decimal/decimal.d.ts +4 -0
- package/types/decimal/index.d.ts +1 -0
- package/types/event-emitter/index.d.ts +17 -0
- package/types/file/fileToURL.d.ts +2 -0
- package/types/file/index.d.ts +3 -0
- package/types/file/saveAs.d.ts +2 -0
- package/types/filesize/index.d.ts +2 -0
- package/types/filesize/src/constants.d.ts +42 -0
- package/types/filesize/src/filesize.d.ts +47 -0
- package/types/index.d.ts +24 -0
- package/types/invariant/index.d.ts +2 -0
- package/types/is/index.d.ts +53 -0
- package/types/lunar-converter/index.d.ts +113 -0
- package/types/math/index.d.ts +11 -0
- package/types/md5/index.d.ts +2 -0
- package/types/mock/MockWebSocket.d.ts +17 -0
- package/types/mock/MockXMLHttpRequest.d.ts +17 -0
- package/types/mock/index.d.ts +2 -0
- package/types/normalize-wheel/ExecutionEnvironment.d.ts +9 -0
- package/types/normalize-wheel/UserAgent_DEPRECATED.d.ts +86 -0
- package/types/normalize-wheel/index.d.ts +115 -0
- package/types/normalize-wheel/isEventSupported.d.ts +16 -0
- package/types/number-to-chinese/index.d.ts +11 -0
- package/types/nzh/cn.d.ts +8 -0
- package/types/nzh/hk.d.ts +8 -0
- package/types/nzh/index.d.ts +1 -0
- package/types/nzh/nzh.d.ts +36 -0
- package/types/nzh/src/autoGet.d.ts +8 -0
- package/types/nzh/src/index.d.ts +34 -0
- package/types/nzh/src/langs/cn_b.d.ts +10 -0
- package/types/nzh/src/langs/cn_s.d.ts +7 -0
- package/types/nzh/src/langs/hk_b.d.ts +10 -0
- package/types/nzh/src/langs/hk_s.d.ts +7 -0
- package/types/nzh/src/utils.d.ts +65 -0
- package/types/object-keys-sort/index.d.ts +4 -0
- package/types/random/address.d.ts +8 -0
- package/types/random/constellation.d.ts +2 -0
- package/types/random/image.d.ts +5 -0
- package/types/random/index.d.ts +40 -0
- package/types/random/licensePlate.d.ts +2 -0
- package/types/random/name.d.ts +9 -0
- package/types/random/number.d.ts +6 -0
- package/types/random/text.d.ts +13 -0
- package/types/random/time.d.ts +2 -0
- package/types/random/web.d.ts +11 -0
- package/types/screenfull/index.d.ts +10 -0
- package/types/search-tree/index.d.ts +20 -0
- package/types/snapdom/index.d.ts +1 -0
- package/types/snapdom/src/api/preCache.d.ts +8 -0
- package/types/snapdom/src/api/snapdom.d.ts +26 -0
- package/types/snapdom/src/core/cache.d.ts +11 -0
- package/types/snapdom/src/core/capture.d.ts +17 -0
- package/types/snapdom/src/core/clone.d.ts +11 -0
- package/types/snapdom/src/core/prepare.d.ts +8 -0
- package/types/snapdom/src/index.browser.d.ts +1 -0
- package/types/snapdom/src/index.d.ts +2 -0
- package/types/snapdom/src/modules/background.d.ts +10 -0
- package/types/snapdom/src/modules/fonts.d.ts +25 -0
- package/types/snapdom/src/modules/images.d.ts +8 -0
- package/types/snapdom/src/modules/pseudo.d.ts +12 -0
- package/types/snapdom/src/modules/styles.d.ts +10 -0
- package/types/snapdom/src/utils/cssTools.d.ts +38 -0
- package/types/snapdom/src/utils/helpers.d.ts +71 -0
- package/types/tree/index.d.ts +8 -0
- package/types/turbo-stream/index.d.ts +1 -0
- package/types/turbo-stream/src/decode.d.ts +7 -0
- package/types/turbo-stream/src/encode.d.ts +27 -0
- package/types/turbo-stream/src/shared.d.ts +107 -0
- package/types/turbo-stream/src/turbo-stream.d.ts +4 -0
- package/types/url-toolkit/index.d.ts +2 -0
- package/types/url-toolkit/src/url-toolkit.d.ts +18 -0
- 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
|
+
};
|
package/nzh.js
ADDED
package/objectKeysSort.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@unicom-cloud/utils","version":"0.1.
|
|
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,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
|
@@ -1,43 +1,47 @@
|
|
|
1
|
-
import { imageCache as
|
|
2
|
-
import { embedCustomFonts as
|
|
3
|
-
import { precacheCommonTags as
|
|
4
|
-
import { fetchImage as
|
|
5
|
-
async function
|
|
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:
|
|
7
|
+
embedFonts: a = !0,
|
|
8
8
|
reset: g = !1,
|
|
9
|
-
crossOrigin:
|
|
10
|
-
} =
|
|
9
|
+
crossOrigin: s
|
|
10
|
+
} = f;
|
|
11
11
|
if (g) {
|
|
12
|
-
|
|
12
|
+
i.clear(), u.clear(), h.clear(), p.clear();
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
-
await document.fonts.ready,
|
|
16
|
-
let l = [],
|
|
17
|
-
|
|
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
|
|
20
|
-
const r =
|
|
21
|
-
if (!
|
|
22
|
-
const
|
|
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
|
-
|
|
24
|
+
C(r, 3e3, n).then((e) => i.set(r, e)).catch(() => {
|
|
25
25
|
})
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
for (const
|
|
30
|
-
const r =
|
|
31
|
-
if (
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
43
|
+
a && await y({ ignoreIconFonts: !a, preCached: !0 }), await Promise.all(t);
|
|
40
44
|
}
|
|
41
45
|
export {
|
|
42
|
-
|
|
46
|
+
w as preCache
|
|
43
47
|
};
|
|
@@ -1,73 +1,84 @@
|
|
|
1
|
-
import { baseCSSCache as
|
|
2
|
-
import { inlineBackgroundImages as
|
|
3
|
-
import { embedCustomFonts as
|
|
4
|
-
import { inlineImages as
|
|
5
|
-
import { collectUsedTagNames as
|
|
6
|
-
import { idle as
|
|
7
|
-
import { prepareClone as
|
|
8
|
-
async function
|
|
9
|
-
if (!
|
|
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:
|
|
12
|
-
embedFonts:
|
|
13
|
+
compress: b = !0,
|
|
14
|
+
embedFonts: h = !1,
|
|
13
15
|
fast: o = !0,
|
|
14
16
|
scale: f = 1
|
|
15
|
-
} =
|
|
16
|
-
let t,
|
|
17
|
-
if ({ clone: t, classCSS:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
), await new Promise((
|
|
22
|
-
|
|
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
|
|
26
|
+
await H(t, n), s();
|
|
25
27
|
},
|
|
26
28
|
{ fast: o }
|
|
27
29
|
);
|
|
28
|
-
}), await new Promise((
|
|
29
|
-
|
|
30
|
+
}), await new Promise((s) => {
|
|
31
|
+
l(
|
|
30
32
|
async () => {
|
|
31
|
-
await
|
|
33
|
+
await P(r, t, v, n), s();
|
|
32
34
|
},
|
|
33
35
|
{ fast: o }
|
|
34
36
|
);
|
|
35
|
-
}),
|
|
36
|
-
|
|
37
|
+
}), h && await new Promise((s) => {
|
|
38
|
+
l(
|
|
37
39
|
async () => {
|
|
38
|
-
|
|
40
|
+
C = await z({ ignoreIconFonts: !h }), s();
|
|
39
41
|
},
|
|
40
42
|
{ fast: o }
|
|
41
43
|
);
|
|
42
|
-
}),
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
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((
|
|
54
|
-
|
|
55
|
+
await new Promise((s) => {
|
|
56
|
+
l(
|
|
55
57
|
() => {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
|
69
|
-
return
|
|
79
|
+
const w = document.getElementById("snapdom-sandbox");
|
|
80
|
+
return w && w.style.position === "absolute" && w.remove(), $;
|
|
70
81
|
}
|
|
71
82
|
export {
|
|
72
|
-
|
|
83
|
+
Q as captureDOM
|
|
73
84
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { inlineAllStyles as
|
|
2
|
-
function
|
|
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),
|
|
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
|
-
})),
|
|
33
|
-
const
|
|
32
|
+
})), o(e, l, c, r, s);
|
|
33
|
+
const h = document.createDocumentFragment();
|
|
34
34
|
if (e.childNodes.forEach((t) => {
|
|
35
|
-
const i =
|
|
35
|
+
const i = f(
|
|
36
36
|
t,
|
|
37
37
|
c,
|
|
38
38
|
r,
|
|
39
39
|
n,
|
|
40
40
|
s
|
|
41
41
|
);
|
|
42
|
-
i &&
|
|
43
|
-
}), l.appendChild(
|
|
44
|
-
const t = Array.from(e.shadowRoot.children).filter((a) => a.tagName !== "STYLE").map((a) =>
|
|
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
|
-
|
|
50
|
+
f as deepClone
|
|
51
51
|
};
|
|
@@ -1,52 +1,59 @@
|
|
|
1
1
|
import { inlinePseudoElements as m } from "../modules/pseudo.js";
|
|
2
|
-
import { generateCSSClasses as
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
25
|
-
if (
|
|
26
|
-
const e =
|
|
27
|
-
|
|
28
|
-
for (const [
|
|
29
|
-
if (
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
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,
|
|
37
|
-
e.tagName !== "STYLE" && e.setAttribute("style",
|
|
38
|
-
for (const [e,
|
|
39
|
-
const n =
|
|
40
|
-
if ((n ||
|
|
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
|
|
43
|
-
for (
|
|
44
|
-
|
|
45
|
-
e.appendChild(
|
|
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
|
-
|
|
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
|
-
|
|
58
|
+
k as prepareClone
|
|
52
59
|
};
|
|
@@ -1,50 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
c.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
16
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
24
|
+
B as inlineBackgroundImages
|
|
50
25
|
};
|