@unicom-cloud/utils 0.1.16 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/class-name/index.js +5 -5
- package/constant/index.js +24 -2
- package/constant/platform.js +13 -12
- package/constant.js +24 -2
- package/content-disposition/index.js +3 -3
- package/date/convertTime.js +4 -4
- package/diff/index.js +7 -0
- package/diff/src/diff.d.ts +21 -0
- package/diff/src/diff.js +381 -0
- package/diff.js +7 -0
- package/filesize/types/constants.d.ts +81 -0
- package/filesize/types/filesize.d.ts +97 -0
- package/index.js +68 -58
- package/js-cookie/index.d.ts +116 -0
- package/js-cookie/index.js +4 -0
- package/js-cookie/src/api.js +56 -0
- package/js-cookie/src/assign.js +11 -0
- package/js-cookie/src/converter.js +14 -0
- package/jsCookie.js +4 -0
- package/lunar/lib/HolidayUtil.js +48 -49
- package/mitt/index.js +4 -0
- package/mitt/src/index.js +37 -0
- package/mitt.js +4 -0
- package/nzh/nzh.d.ts +74 -0
- package/package.json +1 -1
- package/pinyin/index.js +4 -0
- package/pinyin/simplified.js +4 -0
- package/pinyin/src/core.js +143 -0
- package/pinyin/src/simplified.js +8 -0
- package/pinyin/src/simplified_dict.js +410 -0
- package/pinyin/src/traditional.js +8 -0
- package/pinyin/src/traditional_dict.js +403 -0
- package/pinyin/traditional.js +4 -0
- package/pinyin.js +4 -0
- package/query-string/base.d.ts +717 -0
- package/query-string/base.js +268 -0
- package/query-string/index.d.ts +16 -0
- package/query-string/index.js +4 -0
- package/query-string/splitOnFirst.js +14 -0
- package/queryString.js +4 -0
- package/random/index.js +56 -35
- package/snapdom/src/api/preCache.js +51 -28
- package/snapdom/src/core/cache.js +1 -4
- package/snapdom/src/core/capture.js +45 -44
- package/snapdom/src/core/clone.js +82 -66
- package/snapdom/src/core/prepare.js +167 -45
- package/snapdom/src/modules/background.js +29 -19
- package/snapdom/src/modules/fonts.js +158 -111
- package/snapdom/src/modules/images.js +14 -9
- package/snapdom/src/modules/pseudo.js +52 -47
- package/snapdom/src/modules/styles.js +22 -22
- package/snapdom/src/modules/svgDefs.js +39 -20
- package/snapdom/src/utils/cssTools.js +58 -51
- package/snapdom/src/utils/helpers.js +197 -140
- package/snapdom/types/snapdom.d.ts +101 -0
- package/types/constant/index.d.ts +11 -0
- package/types/constant/platform.d.ts +1 -0
- package/types/diff/index.d.ts +2 -0
- package/types/diff/src/diff.d.ts +40 -0
- package/types/index.d.ts +6 -1
- package/types/js-cookie/index.d.ts +1 -0
- package/types/js-cookie/src/api.d.mts +2 -0
- package/types/js-cookie/src/assign.d.mts +1 -0
- package/types/js-cookie/src/converter.d.mts +5 -0
- package/types/mitt/index.d.ts +2 -0
- package/types/mitt/src/index.d.ts +29 -0
- package/types/pinyin/index.d.ts +1 -0
- package/types/pinyin/simplified.d.ts +1 -0
- package/types/pinyin/src/core.d.ts +3 -0
- package/types/pinyin/src/simplified.d.ts +4 -0
- package/types/pinyin/src/simplified_dict.d.ts +408 -0
- package/types/pinyin/src/traditional.d.ts +4 -0
- package/types/pinyin/src/traditional_dict.d.ts +401 -0
- package/types/pinyin/traditional.d.ts +1 -0
- package/types/query-string/base.d.ts +11 -0
- package/types/query-string/index.d.ts +2 -0
- package/types/query-string/splitOnFirst.d.ts +1 -0
- package/types/random/index.d.ts +14 -23
- package/types/snapdom/src/api/preCache.d.ts +2 -5
- package/types/snapdom/src/core/cache.d.ts +0 -3
- package/types/snapdom/src/core/clone.d.ts +1 -1
- package/types/snapdom/src/modules/background.d.ts +16 -6
- package/types/snapdom/src/modules/fonts.d.ts +5 -1
- package/types/snapdom/src/modules/pseudo.d.ts +1 -1
- package/types/snapdom/src/modules/styles.d.ts +1 -1
- package/types/snapdom/src/modules/svgDefs.d.ts +13 -13
- package/types/snapdom/src/utils/cssTools.d.ts +2 -10
- package/types/snapdom/src/utils/helpers.d.ts +13 -7
- package/types/turbo-stream/src/shared.d.ts +3 -3
- package/url-toolkit/src/url-toolkit.d.ts +22 -0
- package/event-emitter/index.js +0 -48
- package/eventEmitter.js +0 -4
- package/types/event-emitter/index.d.ts +0 -17
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import N from "lodash/pick";
|
|
2
|
+
import S from "lodash/pickBy";
|
|
3
|
+
import o from "./splitOnFirst.js";
|
|
4
|
+
const j = (r) => r == null, A = (r) => encodeURIComponent(r).replaceAll(
|
|
5
|
+
/[!'()*]/g,
|
|
6
|
+
(e) => `%${e.charCodeAt(0).toString(16).toUpperCase()}`
|
|
7
|
+
), u = Symbol("encodeFragmentIdentifier");
|
|
8
|
+
function O(r) {
|
|
9
|
+
switch (r.arrayFormat) {
|
|
10
|
+
case "index":
|
|
11
|
+
return (e) => (t, n) => {
|
|
12
|
+
const f = t.length;
|
|
13
|
+
return n === void 0 || r.skipNull && n === null || r.skipEmptyString && n === "" ? t : n === null ? [...t, [c(e, r), "[", f, "]"].join("")] : [
|
|
14
|
+
...t,
|
|
15
|
+
[
|
|
16
|
+
c(e, r),
|
|
17
|
+
"[",
|
|
18
|
+
c(f, r),
|
|
19
|
+
"]=",
|
|
20
|
+
c(n, r)
|
|
21
|
+
].join("")
|
|
22
|
+
];
|
|
23
|
+
};
|
|
24
|
+
case "bracket":
|
|
25
|
+
return (e) => (t, n) => n === void 0 || r.skipNull && n === null || r.skipEmptyString && n === "" ? t : n === null ? [...t, [c(e, r), "[]"].join("")] : [
|
|
26
|
+
...t,
|
|
27
|
+
[c(e, r), "[]=", c(n, r)].join("")
|
|
28
|
+
];
|
|
29
|
+
case "colon-list-separator":
|
|
30
|
+
return (e) => (t, n) => n === void 0 || r.skipNull && n === null || r.skipEmptyString && n === "" ? t : n === null ? [...t, [c(e, r), ":list="].join("")] : [
|
|
31
|
+
...t,
|
|
32
|
+
[c(e, r), ":list=", c(n, r)].join("")
|
|
33
|
+
];
|
|
34
|
+
case "comma":
|
|
35
|
+
case "separator":
|
|
36
|
+
case "bracket-separator": {
|
|
37
|
+
const e = r.arrayFormat === "bracket-separator" ? "[]=" : "=";
|
|
38
|
+
return (t) => (n, f) => f === void 0 || r.skipNull && f === null || r.skipEmptyString && f === "" ? n : (f = f === null ? "" : f, n.length === 0 ? [
|
|
39
|
+
[
|
|
40
|
+
c(t, r),
|
|
41
|
+
e,
|
|
42
|
+
c(f, r)
|
|
43
|
+
].join("")
|
|
44
|
+
] : [
|
|
45
|
+
[n, c(f, r)].join(r.arrayFormatSeparator)
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
default:
|
|
49
|
+
return (e) => (t, n) => n === void 0 || r.skipNull && n === null || r.skipEmptyString && n === "" ? t : n === null ? [...t, c(e, r)] : [
|
|
50
|
+
...t,
|
|
51
|
+
[c(e, r), "=", c(n, r)].join("")
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function w(r) {
|
|
56
|
+
let e;
|
|
57
|
+
switch (r.arrayFormat) {
|
|
58
|
+
case "index":
|
|
59
|
+
return (t, n, f) => {
|
|
60
|
+
if (e = /\[(\d*)]$/.exec(t), t = t.replace(/\[\d*]$/, ""), !e) {
|
|
61
|
+
f[t] = n;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
f[t] === void 0 && (f[t] = {}), f[t][e[1]] = n;
|
|
65
|
+
};
|
|
66
|
+
case "bracket":
|
|
67
|
+
return (t, n, f) => {
|
|
68
|
+
if (e = /(\[])$/.exec(t), t = t.replace(/\[]$/, ""), !e) {
|
|
69
|
+
f[t] = n;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (f[t] === void 0) {
|
|
73
|
+
f[t] = [n];
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
f[t] = [...f[t], n];
|
|
77
|
+
};
|
|
78
|
+
case "colon-list-separator":
|
|
79
|
+
return (t, n, f) => {
|
|
80
|
+
if (e = /(:list)$/.exec(t), t = t.replace(/:list$/, ""), !e) {
|
|
81
|
+
f[t] = n;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (f[t] === void 0) {
|
|
85
|
+
f[t] = [n];
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
f[t] = [...f[t], n];
|
|
89
|
+
};
|
|
90
|
+
case "comma":
|
|
91
|
+
case "separator":
|
|
92
|
+
return (t, n, f) => {
|
|
93
|
+
const i = typeof n == "string" && n.includes(r.arrayFormatSeparator), a = typeof n == "string" && !i && d(n, r).includes(r.arrayFormatSeparator);
|
|
94
|
+
n = a ? d(n, r) : n;
|
|
95
|
+
const s = i || a ? n.split(r.arrayFormatSeparator).map((m) => d(m, r)) : n === null ? n : d(n, r);
|
|
96
|
+
f[t] = s;
|
|
97
|
+
};
|
|
98
|
+
case "bracket-separator":
|
|
99
|
+
return (t, n, f) => {
|
|
100
|
+
const i = /(\[])$/.test(t);
|
|
101
|
+
if (t = t.replace(/\[]$/, ""), !i) {
|
|
102
|
+
f[t] = n && d(n, r);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const a = n === null ? [] : d(n, r).split(r.arrayFormatSeparator);
|
|
106
|
+
if (f[t] === void 0) {
|
|
107
|
+
f[t] = a;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
f[t] = [...f[t], ...a];
|
|
111
|
+
};
|
|
112
|
+
default:
|
|
113
|
+
return (t, n, f) => {
|
|
114
|
+
if (f[t] === void 0) {
|
|
115
|
+
f[t] = n;
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
f[t] = [...[f[t]].flat(), n];
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function l(r) {
|
|
123
|
+
if (typeof r != "string" || r.length !== 1)
|
|
124
|
+
throw new TypeError("arrayFormatSeparator must be single character string");
|
|
125
|
+
}
|
|
126
|
+
function c(r, e) {
|
|
127
|
+
return e.encode ? e.strict ? A(r) : encodeURIComponent(r) : r;
|
|
128
|
+
}
|
|
129
|
+
function d(r, e) {
|
|
130
|
+
return e.decode ? decodeURIComponent(r) : r;
|
|
131
|
+
}
|
|
132
|
+
function y(r) {
|
|
133
|
+
return Array.isArray(r) ? r.sort() : typeof r == "object" ? y(Object.keys(r)).sort((e, t) => Number(e) - Number(t)).map((e) => r[e]) : r;
|
|
134
|
+
}
|
|
135
|
+
function F(r) {
|
|
136
|
+
const e = r.indexOf("#");
|
|
137
|
+
return e !== -1 && (r = r.slice(0, e)), r;
|
|
138
|
+
}
|
|
139
|
+
function C(r) {
|
|
140
|
+
let e = "";
|
|
141
|
+
const t = r.indexOf("#");
|
|
142
|
+
return t !== -1 && (e = r.slice(t)), e;
|
|
143
|
+
}
|
|
144
|
+
function g(r, e, t) {
|
|
145
|
+
return t === "string" && typeof r == "string" ? r : typeof t == "function" && typeof r == "string" ? t(r) : t === "boolean" && r === null ? !0 : t === "boolean" && r !== null && (r.toLowerCase() === "true" || r.toLowerCase() === "false") ? r.toLowerCase() === "true" : t === "boolean" && r !== null && (r.toLowerCase() === "1" || r.toLowerCase() === "0") ? r.toLowerCase() === "1" : t === "string[]" && e.arrayFormat !== "none" && typeof r == "string" ? [r] : t === "number[]" && e.arrayFormat !== "none" && !Number.isNaN(Number(r)) && typeof r == "string" && r.trim() !== "" ? [Number(r)] : t === "number" && !Number.isNaN(Number(r)) && typeof r == "string" && r.trim() !== "" ? Number(r) : e.parseBooleans && r !== null && (r.toLowerCase() === "true" || r.toLowerCase() === "false") ? r.toLowerCase() === "true" : e.parseNumbers && !Number.isNaN(Number(r)) && typeof r == "string" && r.trim() !== "" ? Number(r) : r;
|
|
146
|
+
}
|
|
147
|
+
function b(r) {
|
|
148
|
+
r = F(r);
|
|
149
|
+
const e = r.indexOf("?");
|
|
150
|
+
return e === -1 ? "" : r.slice(e + 1);
|
|
151
|
+
}
|
|
152
|
+
function h(r, e) {
|
|
153
|
+
e = {
|
|
154
|
+
decode: !0,
|
|
155
|
+
sort: !0,
|
|
156
|
+
arrayFormat: "none",
|
|
157
|
+
arrayFormatSeparator: ",",
|
|
158
|
+
parseNumbers: !1,
|
|
159
|
+
parseBooleans: !1,
|
|
160
|
+
types: /* @__PURE__ */ Object.create(null),
|
|
161
|
+
...e
|
|
162
|
+
}, l(e.arrayFormatSeparator);
|
|
163
|
+
const t = w(e), n = /* @__PURE__ */ Object.create(null);
|
|
164
|
+
if (typeof r != "string" || (r = r.trim().replace(/^[?#&]/, ""), !r))
|
|
165
|
+
return n;
|
|
166
|
+
for (const f of r.split("&")) {
|
|
167
|
+
if (f === "")
|
|
168
|
+
continue;
|
|
169
|
+
const i = e.decode ? f.replaceAll("+", " ") : f;
|
|
170
|
+
let [a, s] = o(i, "=");
|
|
171
|
+
a === void 0 && (a = i), s = s === void 0 ? null : ["comma", "separator", "bracket-separator"].includes(
|
|
172
|
+
e.arrayFormat
|
|
173
|
+
) ? s : d(s, e), t(d(a, e), s, n);
|
|
174
|
+
}
|
|
175
|
+
for (const [f, i] of Object.entries(n))
|
|
176
|
+
if (typeof i == "object" && i !== null && e.types[f] !== "string")
|
|
177
|
+
for (const [a, s] of Object.entries(i)) {
|
|
178
|
+
const m = e.types[f] ? e.types[f].replace("[]", "") : void 0;
|
|
179
|
+
i[a] = g(s, e, m);
|
|
180
|
+
}
|
|
181
|
+
else typeof i == "object" && i !== null && e.types[f] === "string" ? n[f] = Object.values(i).join(
|
|
182
|
+
e.arrayFormatSeparator
|
|
183
|
+
) : n[f] = g(i, e, e.types[f]);
|
|
184
|
+
return e.sort === !1 ? n : (e.sort === !0 ? Object.keys(n).sort() : Object.keys(n).sort(e.sort)).reduce((f, i) => {
|
|
185
|
+
const a = n[i];
|
|
186
|
+
return f[i] = a && typeof a == "object" && !Array.isArray(a) ? y(a) : a, f;
|
|
187
|
+
}, /* @__PURE__ */ Object.create(null));
|
|
188
|
+
}
|
|
189
|
+
function $(r, e) {
|
|
190
|
+
if (!r)
|
|
191
|
+
return "";
|
|
192
|
+
e = {
|
|
193
|
+
encode: !0,
|
|
194
|
+
strict: !0,
|
|
195
|
+
arrayFormat: "none",
|
|
196
|
+
arrayFormatSeparator: ",",
|
|
197
|
+
...e
|
|
198
|
+
}, l(e.arrayFormatSeparator);
|
|
199
|
+
const t = (a) => e.skipNull && j(r[a]) || e.skipEmptyString && r[a] === "", n = O(e), f = {};
|
|
200
|
+
for (const [a, s] of Object.entries(r))
|
|
201
|
+
t(a) || (f[a] = s);
|
|
202
|
+
const i = Object.keys(f);
|
|
203
|
+
return e.sort !== !1 && i.sort(e.sort), i.map((a) => {
|
|
204
|
+
const s = r[a];
|
|
205
|
+
return s === void 0 ? "" : s === null ? c(a, e) : Array.isArray(s) ? s.length === 0 && e.arrayFormat === "bracket-separator" ? c(a, e) + "[]" : s.reduce(n(a), []).join("&") : c(a, e) + "=" + c(s, e);
|
|
206
|
+
}).filter((a) => a.length > 0).join("&");
|
|
207
|
+
}
|
|
208
|
+
function x(r, e) {
|
|
209
|
+
e = {
|
|
210
|
+
decode: !0,
|
|
211
|
+
...e
|
|
212
|
+
};
|
|
213
|
+
let [t, n] = o(r, "#");
|
|
214
|
+
return t === void 0 && (t = r), {
|
|
215
|
+
url: t?.split("?")?.[0] ?? "",
|
|
216
|
+
query: h(b(r), e),
|
|
217
|
+
...e && e.parseFragmentIdentifier && n ? { fragmentIdentifier: d(n, e) } : {}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function I(r, e) {
|
|
221
|
+
e = {
|
|
222
|
+
encode: !0,
|
|
223
|
+
strict: !0,
|
|
224
|
+
[u]: !0,
|
|
225
|
+
...e
|
|
226
|
+
};
|
|
227
|
+
const t = F(r.url).split("?")[0] || "", n = b(r.url), f = {
|
|
228
|
+
...h(n, { sort: !1, ...e }),
|
|
229
|
+
...r.query
|
|
230
|
+
};
|
|
231
|
+
let i = $(f, e);
|
|
232
|
+
i &&= `?${i}`;
|
|
233
|
+
let a = C(r.url);
|
|
234
|
+
if (typeof r.fragmentIdentifier == "string") {
|
|
235
|
+
const s = new URL(t);
|
|
236
|
+
s.hash = r.fragmentIdentifier, a = e[u] ? s.hash : `#${r.fragmentIdentifier}`;
|
|
237
|
+
}
|
|
238
|
+
return `${t}${i}${a}`;
|
|
239
|
+
}
|
|
240
|
+
function E(r, e, t) {
|
|
241
|
+
t = {
|
|
242
|
+
parseFragmentIdentifier: !0,
|
|
243
|
+
[u]: !1,
|
|
244
|
+
...t
|
|
245
|
+
};
|
|
246
|
+
const { url: n, query: f, fragmentIdentifier: i } = x(r, t), a = Array.isArray(e) ? N(f, e) : S(f, e);
|
|
247
|
+
return I(
|
|
248
|
+
{
|
|
249
|
+
url: n,
|
|
250
|
+
query: a,
|
|
251
|
+
fragmentIdentifier: i
|
|
252
|
+
},
|
|
253
|
+
t
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
function p(r, e, t) {
|
|
257
|
+
const n = Array.isArray(e) ? (f) => !e.includes(f) : (f, i) => !e(f, i);
|
|
258
|
+
return E(r, n, t);
|
|
259
|
+
}
|
|
260
|
+
export {
|
|
261
|
+
p as exclude,
|
|
262
|
+
b as extract,
|
|
263
|
+
h as parse,
|
|
264
|
+
x as parseUrl,
|
|
265
|
+
E as pick,
|
|
266
|
+
$ as stringify,
|
|
267
|
+
I as stringifyUrl
|
|
268
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// export * as default from './base.js';
|
|
2
|
+
|
|
3
|
+
// Workaround for TS missing feature.
|
|
4
|
+
import * as queryString from './base.js';
|
|
5
|
+
|
|
6
|
+
export default queryString;
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
type ParsedQuery,
|
|
10
|
+
type ParsedUrl,
|
|
11
|
+
type ParseOptions,
|
|
12
|
+
type Stringifiable,
|
|
13
|
+
type StringifiableRecord,
|
|
14
|
+
type StringifyOptions,
|
|
15
|
+
type UrlObject,
|
|
16
|
+
} from './base.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function f(e, t) {
|
|
2
|
+
if (!(typeof e == "string" && typeof t == "string"))
|
|
3
|
+
throw new TypeError("Expected the arguments to be of type `string`");
|
|
4
|
+
if (e === "" || t === "")
|
|
5
|
+
return [];
|
|
6
|
+
const n = e.indexOf(t);
|
|
7
|
+
return n === -1 ? [] : [
|
|
8
|
+
e.slice(0, n),
|
|
9
|
+
e.slice(n + t.length)
|
|
10
|
+
];
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
f as default
|
|
14
|
+
};
|
package/queryString.js
ADDED
package/random/index.js
CHANGED
|
@@ -1,63 +1,84 @@
|
|
|
1
|
-
import
|
|
1
|
+
import e from "lodash/sample";
|
|
2
2
|
import { v4 as p } from "uuid";
|
|
3
|
-
import
|
|
3
|
+
import t from "./address.js";
|
|
4
4
|
import u from "./constellation.js";
|
|
5
|
-
import
|
|
5
|
+
import s from "./image.js";
|
|
6
6
|
import l from "./licensePlate.js";
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
7
|
+
import n from "./name.js";
|
|
8
|
+
import o from "./number.js";
|
|
9
|
+
import i from "./text.js";
|
|
10
|
+
import f from "./time.js";
|
|
11
11
|
import m from "./web.js";
|
|
12
|
-
const
|
|
13
|
-
let
|
|
14
|
-
return () => Date.now() + 19870227 + 19920127 + 202111221054 + 202310310737 +
|
|
15
|
-
})(),
|
|
16
|
-
number: r,
|
|
17
|
-
natural: r.natural.bind(r),
|
|
18
|
-
integer: r.integer.bind(r),
|
|
19
|
-
float: r.float.bind(r),
|
|
12
|
+
const d = /* @__PURE__ */ (() => {
|
|
13
|
+
let r = 0;
|
|
14
|
+
return () => Date.now() + 19870227 + 19920127 + 202111221054 + 202310310737 + r++;
|
|
15
|
+
})(), P = {
|
|
20
16
|
boolean() {
|
|
21
|
-
return
|
|
17
|
+
return e([!0, !1]);
|
|
22
18
|
},
|
|
23
19
|
sex() {
|
|
24
|
-
return
|
|
20
|
+
return e(["男", "女"]);
|
|
25
21
|
},
|
|
26
|
-
pick:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
pick: e,
|
|
23
|
+
number: o,
|
|
24
|
+
...Object.fromEntries(
|
|
25
|
+
["natural", "integer", "float"].map((r) => [r, o[r].bind(o)])
|
|
26
|
+
),
|
|
27
|
+
text: i,
|
|
28
|
+
...Object.fromEntries(
|
|
29
|
+
[
|
|
30
|
+
"paragraph",
|
|
31
|
+
"cparagraph",
|
|
32
|
+
"sentence",
|
|
33
|
+
"csentence",
|
|
34
|
+
"word",
|
|
35
|
+
"cword",
|
|
36
|
+
"title",
|
|
37
|
+
"ctitle",
|
|
38
|
+
"character",
|
|
39
|
+
"string"
|
|
40
|
+
].map((r) => [r, i[r].bind(i)])
|
|
41
|
+
),
|
|
42
|
+
name: n,
|
|
43
|
+
...Object.fromEntries(
|
|
44
|
+
["first", "last", "name", "cfirst", "clast", "cname"].map((r) => [r, n[r].bind(n)])
|
|
45
|
+
),
|
|
34
46
|
web: m,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
47
|
+
...Object.fromEntries(
|
|
48
|
+
["url", "protocol", "domain", "tld", "email", "phone", "ip", "port"].map(
|
|
49
|
+
(r) => [r, m[r].bind(m)]
|
|
50
|
+
)
|
|
51
|
+
),
|
|
52
|
+
address: t,
|
|
53
|
+
...Object.fromEntries(
|
|
54
|
+
["region", "province", "city", "county", "zip"].map((r) => [r, t[r].bind(t)])
|
|
55
|
+
),
|
|
56
|
+
county(r) {
|
|
57
|
+
return t.county(r ?? !0);
|
|
58
|
+
},
|
|
38
59
|
company() {
|
|
39
|
-
return `${
|
|
60
|
+
return `${t.city()}某某某有限公司`;
|
|
40
61
|
},
|
|
41
62
|
project() {
|
|
42
|
-
return `${
|
|
63
|
+
return `${t.city()}某某某项目部`;
|
|
43
64
|
},
|
|
44
|
-
time:
|
|
65
|
+
time: f,
|
|
45
66
|
constellation: u,
|
|
46
67
|
licensePlate: l,
|
|
47
68
|
uuid() {
|
|
48
69
|
return p();
|
|
49
70
|
},
|
|
50
71
|
id() {
|
|
51
|
-
return
|
|
72
|
+
return d();
|
|
52
73
|
},
|
|
53
|
-
increment: /* @__PURE__ */ ((
|
|
74
|
+
increment: /* @__PURE__ */ ((r) => {
|
|
54
75
|
let a = 0;
|
|
55
76
|
return function(c) {
|
|
56
77
|
return a += +c || 1;
|
|
57
78
|
};
|
|
58
79
|
})(),
|
|
59
|
-
image:
|
|
80
|
+
image: s
|
|
60
81
|
};
|
|
61
82
|
export {
|
|
62
|
-
|
|
83
|
+
P as default
|
|
63
84
|
};
|
|
@@ -1,37 +1,60 @@
|
|
|
1
|
-
import { cache as
|
|
2
|
-
import { embedCustomFonts as
|
|
3
|
-
import { precacheCommonTags as
|
|
4
|
-
import { fetchImage as
|
|
5
|
-
async function
|
|
6
|
-
const { embedFonts:
|
|
7
|
-
if (
|
|
8
|
-
|
|
1
|
+
import { cache as r } from "../core/cache.js";
|
|
2
|
+
import { embedCustomFonts as g } from "../modules/fonts.js";
|
|
3
|
+
import { precacheCommonTags as h } from "../utils/cssTools.js";
|
|
4
|
+
import { fetchImage as p, getStyle as d, splitBackgroundImage as S, inlineSingleBackgroundEntry as b } from "../utils/helpers.js";
|
|
5
|
+
async function x(o = document, t = {}) {
|
|
6
|
+
const { embedFonts: f = !0, reset: u = !1, useProxy: n } = t;
|
|
7
|
+
if (u) {
|
|
8
|
+
r.image.clear(), r.background.clear(), r.resource.clear(), r.defaultStyle.clear(), r.baseStyle.clear(), r.font.clear(), r.computedStyle = /* @__PURE__ */ new WeakMap();
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const o = [];
|
|
15
|
-
for (const s of n) {
|
|
16
|
-
const e = s.src;
|
|
17
|
-
a.image.has(e) || o.push(
|
|
18
|
-
h(e, { useProxy: t.useProxy }).then((c) => a.image.set(e, c)).catch(() => {
|
|
19
|
-
})
|
|
20
|
-
);
|
|
11
|
+
try {
|
|
12
|
+
await document.fonts.ready;
|
|
13
|
+
} catch {
|
|
21
14
|
}
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
h();
|
|
16
|
+
let m = [], i = [];
|
|
17
|
+
o?.querySelectorAll && (m = Array.from(o.querySelectorAll("img[src]")), i = Array.from(o.querySelectorAll("*")));
|
|
18
|
+
const a = [];
|
|
19
|
+
for (const l of m) {
|
|
20
|
+
const e = l?.src;
|
|
21
|
+
if (e && !r.image.has(e)) {
|
|
22
|
+
const s = Promise.resolve().then(() => p(e, { useProxy: n })).then((c) => {
|
|
23
|
+
r.image.set(e, c);
|
|
24
|
+
}).catch(() => {
|
|
25
|
+
});
|
|
26
|
+
a.push(s);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
for (const l of i) {
|
|
30
|
+
let e = "";
|
|
31
|
+
try {
|
|
32
|
+
e = d(l).backgroundImage;
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
24
35
|
if (e && e !== "none") {
|
|
25
|
-
const
|
|
26
|
-
for (const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
const s = S(e);
|
|
37
|
+
for (const c of s)
|
|
38
|
+
if (c.startsWith("url(")) {
|
|
39
|
+
const y = Promise.resolve().then(
|
|
40
|
+
() => b(c, { ...t, useProxy: n })
|
|
41
|
+
).catch(() => {
|
|
42
|
+
});
|
|
43
|
+
a.push(y);
|
|
44
|
+
}
|
|
31
45
|
}
|
|
32
46
|
}
|
|
33
|
-
|
|
47
|
+
if (f)
|
|
48
|
+
try {
|
|
49
|
+
await g({
|
|
50
|
+
preCached: !0,
|
|
51
|
+
localFonts: t.localFonts,
|
|
52
|
+
useProxy: t.useProxy
|
|
53
|
+
});
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
await Promise.allSettled(a);
|
|
34
57
|
}
|
|
35
58
|
export {
|
|
36
|
-
|
|
59
|
+
x as preCache
|
|
37
60
|
};
|
|
@@ -8,13 +8,10 @@ const e = {
|
|
|
8
8
|
font: /* @__PURE__ */ new Set(),
|
|
9
9
|
snapshot: /* @__PURE__ */ new WeakMap(),
|
|
10
10
|
snapshotKey: /* @__PURE__ */ new Map(),
|
|
11
|
-
preStyleMap: /* @__PURE__ */ new Map(),
|
|
12
|
-
preStyle: /* @__PURE__ */ new WeakMap(),
|
|
13
|
-
preNodeMap: /* @__PURE__ */ new Map(),
|
|
14
11
|
reset: a
|
|
15
12
|
};
|
|
16
13
|
function a() {
|
|
17
|
-
e.computedStyle = /* @__PURE__ */ new WeakMap()
|
|
14
|
+
e.computedStyle = /* @__PURE__ */ new WeakMap();
|
|
18
15
|
}
|
|
19
16
|
export {
|
|
20
17
|
e as cache
|
|
@@ -1,85 +1,86 @@
|
|
|
1
1
|
import { cache as h } from "./cache.js";
|
|
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 (!
|
|
2
|
+
import { inlineBackgroundImages as A } from "../modules/background.js";
|
|
3
|
+
import { embedCustomFonts as O } from "../modules/fonts.js";
|
|
4
|
+
import { inlineImages as R } from "../modules/images.js";
|
|
5
|
+
import { collectUsedTagNames as U, generateDedupedBaseCSS as j } from "../utils/cssTools.js";
|
|
6
|
+
import { idle as l } from "../utils/helpers.js";
|
|
7
|
+
import { prepareClone as D } from "./prepare.js";
|
|
8
|
+
async function V(c, t = {}) {
|
|
9
|
+
if (!c) throw new Error("Element cannot be null or undefined");
|
|
10
10
|
h.reset();
|
|
11
11
|
const {
|
|
12
12
|
compress: u = !0,
|
|
13
13
|
embedFonts: b = !1,
|
|
14
|
-
fast:
|
|
15
|
-
scale:
|
|
16
|
-
useProxy:
|
|
14
|
+
fast: r = !0,
|
|
15
|
+
scale: y = 1,
|
|
16
|
+
useProxy: T = "",
|
|
17
|
+
localFonts: B = []
|
|
17
18
|
} = t;
|
|
18
|
-
let a,
|
|
19
|
-
if ({ clone: a, classCSS:
|
|
20
|
-
|
|
19
|
+
let a, S, p, v = "", m = "", C, x;
|
|
20
|
+
if ({ clone: a, classCSS: S, styleCache: p } = await D(
|
|
21
|
+
c,
|
|
21
22
|
u,
|
|
22
23
|
b,
|
|
23
24
|
t
|
|
24
25
|
), await new Promise((s) => {
|
|
25
|
-
|
|
26
|
+
l(
|
|
26
27
|
async () => {
|
|
27
|
-
await
|
|
28
|
+
await R(a, t), s();
|
|
28
29
|
},
|
|
29
|
-
{ fast:
|
|
30
|
+
{ fast: r }
|
|
30
31
|
);
|
|
31
32
|
}), await new Promise((s) => {
|
|
32
|
-
|
|
33
|
+
l(
|
|
33
34
|
async () => {
|
|
34
|
-
await
|
|
35
|
+
await A(c, a, p, t), s();
|
|
35
36
|
},
|
|
36
|
-
{ fast:
|
|
37
|
+
{ fast: r }
|
|
37
38
|
);
|
|
38
39
|
}), b && await new Promise((s) => {
|
|
39
|
-
|
|
40
|
+
l(
|
|
40
41
|
async () => {
|
|
41
|
-
|
|
42
|
+
v = await O({ localFonts: B, useProxy: T }), s();
|
|
42
43
|
},
|
|
43
|
-
{ fast:
|
|
44
|
+
{ fast: r }
|
|
44
45
|
);
|
|
45
46
|
}), u) {
|
|
46
|
-
const s =
|
|
47
|
+
const s = U(a).sort(), i = s.join(",");
|
|
47
48
|
h.baseStyle.has(i) ? m = h.baseStyle.get(i) : await new Promise((e) => {
|
|
48
|
-
|
|
49
|
+
l(
|
|
49
50
|
() => {
|
|
50
|
-
m =
|
|
51
|
+
m = j(s), h.baseStyle.set(i, m), e();
|
|
51
52
|
},
|
|
52
|
-
{ fast:
|
|
53
|
+
{ fast: r }
|
|
53
54
|
);
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
await new Promise((s) => {
|
|
57
|
-
|
|
58
|
+
l(
|
|
58
59
|
() => {
|
|
59
|
-
const i =
|
|
60
|
-
let e = i.width,
|
|
61
|
-
const d = Number.isFinite(t.width), f = Number.isFinite(t.height),
|
|
62
|
-
if (
|
|
60
|
+
const i = c.getBoundingClientRect();
|
|
61
|
+
let e = i.width, n = i.height;
|
|
62
|
+
const d = Number.isFinite(t.width), f = Number.isFinite(t.height), $ = typeof y == "number" && y !== 1;
|
|
63
|
+
if (!$) {
|
|
63
64
|
const g = i.width / i.height;
|
|
64
|
-
d && f ? (e = t.width,
|
|
65
|
+
d && f ? (e = t.width, n = t.height) : d ? (e = t.width, n = e / g) : f && (n = t.height, e = n * g);
|
|
65
66
|
}
|
|
66
|
-
if (e = Math.ceil(e),
|
|
67
|
-
const g = i.width,
|
|
68
|
-
a.style.transform = `${
|
|
67
|
+
if (e = Math.ceil(e), n = Math.ceil(n), a.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"), a.style.transformOrigin = "top left", !$ && (d || f)) {
|
|
68
|
+
const g = i.width, N = i.height, z = e / g, H = n / N, I = a.style.transform || "", M = `scale(${z}, ${H})`;
|
|
69
|
+
a.style.transform = `${M} ${I}`.trim();
|
|
69
70
|
}
|
|
70
|
-
const
|
|
71
|
+
const F = "http://www.w3.org/2000/svg", o = document.createElementNS(F, "foreignObject");
|
|
71
72
|
o.setAttribute("width", "100%"), o.setAttribute("height", "100%");
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
x = `<svg xmlns="${
|
|
73
|
+
const P = document.createElement("style");
|
|
74
|
+
P.textContent = m + v + "svg{overflow:visible;}" + S, o.appendChild(P), o.appendChild(a);
|
|
75
|
+
const E = new XMLSerializer().serializeToString(o);
|
|
76
|
+
x = `<svg xmlns="${F}" width="${e}" height="${n}" viewBox="0 0 ${e} ${n}">` + E + "</svg>", C = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(x)}`, s();
|
|
76
77
|
},
|
|
77
|
-
{ fast:
|
|
78
|
+
{ fast: r }
|
|
78
79
|
);
|
|
79
80
|
});
|
|
80
81
|
const w = document.getElementById("snapdom-sandbox");
|
|
81
|
-
return w && w.style.position === "absolute" && w.remove(),
|
|
82
|
+
return w && w.style.position === "absolute" && w.remove(), C;
|
|
82
83
|
}
|
|
83
84
|
export {
|
|
84
|
-
|
|
85
|
+
V as captureDOM
|
|
85
86
|
};
|