@unicom-cloud/utils 0.1.15 → 0.1.17

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 (90) hide show
  1. package/class-name/index.js +5 -5
  2. package/constant/index.js +24 -2
  3. package/constant/platform.js +13 -12
  4. package/constant.js +24 -2
  5. package/content-disposition/index.js +3 -3
  6. package/date/convertTime.js +4 -4
  7. package/event-emitter/index.js +2 -4
  8. package/filesize/types/constants.d.ts +81 -0
  9. package/filesize/types/filesize.d.ts +97 -0
  10. package/index.js +66 -60
  11. package/js-cookie/index.d.ts +116 -0
  12. package/js-cookie/index.js +4 -0
  13. package/js-cookie/src/api.js +56 -0
  14. package/js-cookie/src/assign.js +11 -0
  15. package/js-cookie/src/converter.js +14 -0
  16. package/jsCookie.js +4 -0
  17. package/lunar/lib/Holiday.js +2 -6
  18. package/lunar/lib/HolidayUtil.js +113 -100
  19. package/lunar/lib/I18n.js +395 -975
  20. package/lunar/lib/JieQi.js +12 -16
  21. package/lunar/lib/Lunar.js +224 -672
  22. package/lunar/lib/LunarMonth.js +35 -98
  23. package/lunar/lib/LunarTime.js +24 -103
  24. package/lunar/lib/LunarUtil.js +426 -1728
  25. package/lunar/lib/LunarYear.js +473 -566
  26. package/lunar/lib/ShouXingUtil.js +6714 -6690
  27. package/lunar/lib/Solar.js +24 -49
  28. package/lunar/lib/SolarHalfYear.js +0 -2
  29. package/lunar/lib/SolarMonth.js +4 -6
  30. package/lunar/lib/SolarSeason.js +0 -2
  31. package/lunar/lib/SolarUtil.js +238 -226
  32. package/lunar/lib/SolarWeek.js +7 -11
  33. package/lunar/lib/SolarYear.js +0 -1
  34. package/nzh/nzh.d.ts +74 -0
  35. package/package.json +1 -1
  36. package/query-string/base.d.ts +717 -0
  37. package/query-string/base.js +268 -0
  38. package/query-string/index.d.ts +16 -0
  39. package/query-string/index.js +4 -0
  40. package/query-string/splitOnFirst.js +14 -0
  41. package/queryString.js +4 -0
  42. package/random/index.js +56 -35
  43. package/snapdom/src/api/preCache.js +51 -28
  44. package/snapdom/src/core/cache.js +1 -4
  45. package/snapdom/src/core/capture.js +45 -44
  46. package/snapdom/src/core/clone.js +82 -66
  47. package/snapdom/src/core/prepare.js +168 -46
  48. package/snapdom/src/modules/background.js +29 -19
  49. package/snapdom/src/modules/fonts.js +146 -91
  50. package/snapdom/src/modules/images.js +14 -9
  51. package/snapdom/src/modules/pseudo.js +55 -58
  52. package/snapdom/src/modules/styles.js +22 -22
  53. package/snapdom/src/modules/svgDefs.js +39 -20
  54. package/snapdom/src/utils/cssTools.js +58 -51
  55. package/snapdom/src/utils/helpers.js +197 -140
  56. package/snapdom/types/snapdom.d.ts +101 -0
  57. package/tinycolor/src/conversion.js +1 -1
  58. package/tinycolor/src/index.js +2 -19
  59. package/turbo-stream/src/encode.js +5 -8
  60. package/turbo-stream/src/shared.js +117 -119
  61. package/types/constant/index.d.ts +11 -0
  62. package/types/constant/platform.d.ts +1 -0
  63. package/types/index.d.ts +3 -0
  64. package/types/js-cookie/index.d.ts +1 -0
  65. package/types/js-cookie/src/api.d.mts +2 -0
  66. package/types/js-cookie/src/assign.d.mts +1 -0
  67. package/types/js-cookie/src/converter.d.mts +5 -0
  68. package/types/lunar/lib/Lunar.d.ts +0 -98
  69. package/types/lunar/lib/LunarMonth.d.ts +0 -12
  70. package/types/lunar/lib/LunarTime.d.ts +0 -22
  71. package/types/lunar/lib/LunarUtil.d.ts +0 -90
  72. package/types/lunar/lib/LunarYear.d.ts +0 -30
  73. package/types/lunar/lib/Solar.d.ts +0 -5
  74. package/types/query-string/base.d.ts +11 -0
  75. package/types/query-string/index.d.ts +2 -0
  76. package/types/query-string/splitOnFirst.d.ts +1 -0
  77. package/types/random/index.d.ts +14 -23
  78. package/types/snapdom/src/api/preCache.d.ts +2 -5
  79. package/types/snapdom/src/core/cache.d.ts +0 -3
  80. package/types/snapdom/src/core/clone.d.ts +1 -1
  81. package/types/snapdom/src/modules/background.d.ts +16 -6
  82. package/types/snapdom/src/modules/fonts.d.ts +5 -1
  83. package/types/snapdom/src/modules/pseudo.d.ts +1 -1
  84. package/types/snapdom/src/modules/styles.d.ts +1 -1
  85. package/types/snapdom/src/modules/svgDefs.d.ts +13 -13
  86. package/types/snapdom/src/utils/cssTools.d.ts +2 -10
  87. package/types/snapdom/src/utils/helpers.d.ts +13 -7
  88. package/types/tinycolor/src/conversion.d.ts +1 -1
  89. package/types/turbo-stream/src/shared.d.ts +3 -3
  90. package/url-toolkit/src/url-toolkit.d.ts +22 -0
@@ -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,4 @@
1
+ import * as r from "./base.js";
2
+ export {
3
+ r as default
4
+ };
@@ -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
@@ -0,0 +1,4 @@
1
+ import * as r from "./query-string/base.js";
2
+ export {
3
+ r as default
4
+ };
package/random/index.js CHANGED
@@ -1,63 +1,84 @@
1
- import o from "lodash/sample";
1
+ import e from "lodash/sample";
2
2
  import { v4 as p } from "uuid";
3
- import n from "./address.js";
3
+ import t from "./address.js";
4
4
  import u from "./constellation.js";
5
- import d from "./image.js";
5
+ import s from "./image.js";
6
6
  import l from "./licensePlate.js";
7
- import i from "./name.js";
8
- import r from "./number.js";
9
- import e from "./text.js";
10
- import s from "./time.js";
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 f = /* @__PURE__ */ (() => {
13
- let t = 0;
14
- return () => Date.now() + 19870227 + 19920127 + 202111221054 + 202310310737 + t++;
15
- })(), v = {
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 o([!0, !1]);
17
+ return e([!0, !1]);
22
18
  },
23
19
  sex() {
24
- return o(["男", "女"]);
20
+ return e(["男", "女"]);
25
21
  },
26
- pick: o,
27
- text: e,
28
- ctitle: e.ctitle.bind(e),
29
- cparagraph: e.cparagraph.bind(e),
30
- csentence: e.csentence.bind(e),
31
- cword: e.cword.bind(e),
32
- name: i,
33
- cname: i.cname.bind(i),
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
- phone: m.phone.bind(m),
36
- address: n,
37
- county: (t) => n.county(t ?? !0),
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 `${n.city()}某某某有限公司`;
60
+ return `${t.city()}某某某有限公司`;
40
61
  },
41
62
  project() {
42
- return `${n.city()}某某某项目部`;
63
+ return `${t.city()}某某某项目部`;
43
64
  },
44
- time: s,
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 f();
72
+ return d();
52
73
  },
53
- increment: /* @__PURE__ */ ((t) => {
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: d
80
+ image: s
60
81
  };
61
82
  export {
62
- v as default
83
+ P as default
63
84
  };
@@ -1,37 +1,60 @@
1
- import { cache as a } from "../core/cache.js";
2
- import { embedCustomFonts as u } from "../modules/fonts.js";
3
- import { precacheCommonTags as g } from "../utils/cssTools.js";
4
- import { fetchImage as h, getStyle as y, splitBackgroundImage as p, inlineSingleBackgroundEntry as d } from "../utils/helpers.js";
5
- async function q(r = document, t = {}) {
6
- const { embedFonts: l = !0, reset: f = !1 } = t;
7
- if (f) {
8
- a.reset();
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
- await document.fonts.ready, g();
12
- let n = [], i = [];
13
- r?.querySelectorAll && (n = Array.from(r.querySelectorAll("img[src]")), i = Array.from(r.querySelectorAll("*")));
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
- for (const s of i) {
23
- const e = y(s).backgroundImage;
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 c = p(e);
26
- for (const m of c)
27
- m.startsWith("url(") && o.push(
28
- d(m, t).catch(() => {
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
- l && await u({ preCached: !0 }), await Promise.all(o);
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
- q as preCache
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(), e.snapshot = /* @__PURE__ */ new WeakMap(), e.snapshotKey.clear(), e.preStyleMap.clear(), e.preStyle = /* @__PURE__ */ new WeakMap(), e.preNodeMap.clear();
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 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
- import { idle as c } from "../utils/helpers.js";
7
- import { prepareClone as R } from "./prepare.js";
8
- async function J(l, t = {}) {
9
- if (!l) throw new Error("Element cannot be null or undefined");
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: n = !0,
15
- scale: S = 1,
16
- useProxy: U = ""
14
+ fast: r = !0,
15
+ scale: y = 1,
16
+ useProxy: T = "",
17
+ localFonts: B = []
17
18
  } = t;
18
- let a, y, p = "", m = "", v, x;
19
- if ({ clone: a, classCSS: y } = await R(
20
- l,
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
- c(
26
+ l(
26
27
  async () => {
27
- await M(a, t), s();
28
+ await R(a, t), s();
28
29
  },
29
- { fast: n }
30
+ { fast: r }
30
31
  );
31
32
  }), await new Promise((s) => {
32
- c(
33
+ l(
33
34
  async () => {
34
- await H(l, a, t), s();
35
+ await A(c, a, p, t), s();
35
36
  },
36
- { fast: n }
37
+ { fast: r }
37
38
  );
38
39
  }), b && await new Promise((s) => {
39
- c(
40
+ l(
40
41
  async () => {
41
- p = await I(), s();
42
+ v = await O({ localFonts: B, useProxy: T }), s();
42
43
  },
43
- { fast: n }
44
+ { fast: r }
44
45
  );
45
46
  }), u) {
46
- const s = A(a).sort(), i = s.join(",");
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
- c(
49
+ l(
49
50
  () => {
50
- m = O(s), h.baseStyle.set(i, m), e();
51
+ m = j(s), h.baseStyle.set(i, m), e();
51
52
  },
52
- { fast: n }
53
+ { fast: r }
53
54
  );
54
55
  });
55
56
  }
56
57
  await new Promise((s) => {
57
- c(
58
+ l(
58
59
  () => {
59
- const i = l.getBoundingClientRect();
60
- let e = i.width, r = i.height;
61
- const d = Number.isFinite(t.width), f = Number.isFinite(t.height), C = typeof S == "number" && S !== 1;
62
- if (!C) {
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, r = t.height) : d ? (e = t.width, r = e / g) : f && (r = t.height, e = r * g);
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), r = Math.ceil(r), a.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"), a.style.transformOrigin = "top left", !C && (d || f)) {
67
- const g = i.width, T = i.height, B = e / g, E = r / T, N = a.style.transform || "", z = `scale(${B}, ${E})`;
68
- a.style.transform = `${z} ${N}`.trim();
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 $ = "http://www.w3.org/2000/svg", o = document.createElementNS($, "foreignObject");
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 F = document.createElement("style");
73
- F.textContent = m + p + "svg{overflow:visible;}" + y, o.appendChild(F), o.appendChild(a);
74
- const P = new XMLSerializer().serializeToString(o);
75
- x = `<svg xmlns="${$}" width="${e}" height="${r}" viewBox="0 0 ${e} ${r}">` + P + "</svg>", v = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(x)}`, s();
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: n }
78
+ { fast: r }
78
79
  );
79
80
  });
80
81
  const w = document.getElementById("snapdom-sandbox");
81
- return w && w.style.position === "absolute" && w.remove(), v;
82
+ return w && w.style.position === "absolute" && w.remove(), C;
82
83
  }
83
84
  export {
84
- J as captureDOM
85
+ V as captureDOM
85
86
  };