@dvirus-js/utils 0.0.7 → 0.0.14
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/CHANGELOG.md +54 -0
- package/index.js +666 -534
- package/lib/get-empty-keys.d.ts +29 -0
- package/lib/html-text-parser/api.d.ts +62 -0
- package/lib/html-text-parser/constant.d.ts +0 -1
- package/lib/html-text-parser/dom-renderer.d.ts +17 -0
- package/lib/html-text-parser/grouping.d.ts +2 -0
- package/lib/html-text-parser/index.d.ts +2 -2
- package/lib/html-text-parser/parsing.d.ts +26 -0
- package/lib/html-text-parser/segment.d.ts +2 -0
- package/lib/html-text-parser/stylesheet.d.ts +21 -0
- package/lib/html-text-parser/tag-regex.d.ts +3 -0
- package/lib/html-text-parser/tags.d.ts +43 -0
- package/lib/html-text-parser/types.d.ts +37 -19
- package/lib/http.d.ts +146 -16
- package/package.json +1 -1
- package/lib/html-text-parser/html-text-parser.d.ts +0 -70
- package/lib/html-text-parser/methods.d.ts +0 -51
package/index.js
CHANGED
|
@@ -1,62 +1,130 @@
|
|
|
1
|
-
function
|
|
1
|
+
function V(e) {
|
|
2
2
|
return e.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").toLowerCase().replace(/[_-]+/g, " ").replace(/\s+/g, " ").trim();
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
const
|
|
6
|
-
switch (
|
|
4
|
+
function ue(e, t) {
|
|
5
|
+
const r = V(e);
|
|
6
|
+
switch (t) {
|
|
7
7
|
case "lowercase":
|
|
8
|
-
return
|
|
8
|
+
return r.toLowerCase();
|
|
9
9
|
case "UPPERCASE":
|
|
10
|
-
return
|
|
10
|
+
return r.toUpperCase();
|
|
11
11
|
case "Title Case":
|
|
12
|
-
return
|
|
13
|
-
(
|
|
12
|
+
return r.split(" ").map(
|
|
13
|
+
(n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()
|
|
14
14
|
).join(" ");
|
|
15
15
|
case "kebab-case":
|
|
16
|
-
return
|
|
16
|
+
return r.replace(/\s+/g, "-");
|
|
17
17
|
case "snake_case":
|
|
18
|
-
return
|
|
18
|
+
return r.replace(/\s+/g, "_");
|
|
19
19
|
case "camelCase": {
|
|
20
|
-
const
|
|
21
|
-
return
|
|
20
|
+
const n = r.split(" ");
|
|
21
|
+
return n.length === 0 ? "" : n[0]?.toLowerCase() + n.slice(1).map(
|
|
22
22
|
(o) => o.charAt(0).toUpperCase() + o.slice(1).toLowerCase()
|
|
23
23
|
).join("");
|
|
24
24
|
}
|
|
25
25
|
case "PascalCase":
|
|
26
|
-
return
|
|
27
|
-
(
|
|
26
|
+
return r.split(" ").map(
|
|
27
|
+
(n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()
|
|
28
28
|
).join("");
|
|
29
29
|
case "dot.case":
|
|
30
|
-
return
|
|
30
|
+
return r.replace(/\s+/g, ".");
|
|
31
31
|
case "path/case":
|
|
32
|
-
return
|
|
32
|
+
return r.replace(/\s+/g, "/");
|
|
33
33
|
case "Sentence case":
|
|
34
|
-
return
|
|
34
|
+
return r.replace(/(^\s*\w|[.!?]\s*\w)/g, (n) => n.toUpperCase()).replace(/\bi\b/g, "I");
|
|
35
35
|
case "Header-Case":
|
|
36
|
-
return
|
|
37
|
-
(
|
|
36
|
+
return r.split(" ").map(
|
|
37
|
+
(n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()
|
|
38
38
|
).join("-");
|
|
39
39
|
case "reverse":
|
|
40
|
-
return
|
|
40
|
+
return r.split("").reverse().join("");
|
|
41
41
|
default:
|
|
42
|
-
throw new Error(`Unsupported case type: ${
|
|
42
|
+
throw new Error(`Unsupported case type: ${t}`);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
async function
|
|
45
|
+
async function de(e) {
|
|
46
46
|
try {
|
|
47
47
|
return [await (typeof e == "function" ? e() : e), null];
|
|
48
|
-
} catch (
|
|
49
|
-
return [null,
|
|
48
|
+
} catch (t) {
|
|
49
|
+
return [null, t];
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
function E(e) {
|
|
53
53
|
try {
|
|
54
54
|
return [e(), null];
|
|
55
|
-
} catch (
|
|
56
|
-
return [null,
|
|
55
|
+
} catch (t) {
|
|
56
|
+
return [null, t];
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
let b = "";
|
|
60
|
+
const U = {
|
|
61
|
+
100: "Continue",
|
|
62
|
+
101: "Switching Protocols",
|
|
63
|
+
102: "Processing",
|
|
64
|
+
103: "Early Hints",
|
|
65
|
+
200: "OK",
|
|
66
|
+
201: "Created",
|
|
67
|
+
202: "Accepted",
|
|
68
|
+
203: "Non-Authoritative Information",
|
|
69
|
+
204: "No Content",
|
|
70
|
+
205: "Reset Content",
|
|
71
|
+
206: "Partial Content",
|
|
72
|
+
207: "Multi-Status",
|
|
73
|
+
208: "Already Reported",
|
|
74
|
+
226: "IM Used",
|
|
75
|
+
300: "Multiple Choices",
|
|
76
|
+
301: "Moved Permanently",
|
|
77
|
+
302: "Found",
|
|
78
|
+
303: "See Other",
|
|
79
|
+
304: "Not Modified",
|
|
80
|
+
305: "Use Proxy",
|
|
81
|
+
307: "Temporary Redirect",
|
|
82
|
+
308: "Permanent Redirect",
|
|
83
|
+
400: "Bad Request",
|
|
84
|
+
401: "Unauthorized",
|
|
85
|
+
402: "Payment Required",
|
|
86
|
+
403: "Forbidden",
|
|
87
|
+
404: "Not Found",
|
|
88
|
+
405: "Method Not Allowed",
|
|
89
|
+
406: "Not Acceptable",
|
|
90
|
+
407: "Proxy Authentication Required",
|
|
91
|
+
408: "Request Timeout",
|
|
92
|
+
409: "Conflict",
|
|
93
|
+
410: "Gone",
|
|
94
|
+
411: "Length Required",
|
|
95
|
+
412: "Precondition Failed",
|
|
96
|
+
413: "Payload Too Large",
|
|
97
|
+
414: "URI Too Long",
|
|
98
|
+
415: "Unsupported Media Type",
|
|
99
|
+
416: "Range Not Satisfiable",
|
|
100
|
+
417: "Expectation Failed",
|
|
101
|
+
418: "I'm a teapot",
|
|
102
|
+
421: "Misdirected Request",
|
|
103
|
+
422: "Unprocessable Entity",
|
|
104
|
+
423: "Locked",
|
|
105
|
+
424: "Failed Dependency",
|
|
106
|
+
425: "Too Early",
|
|
107
|
+
426: "Upgrade Required",
|
|
108
|
+
428: "Precondition Required",
|
|
109
|
+
429: "Too Many Requests",
|
|
110
|
+
431: "Request Header Fields Too Large",
|
|
111
|
+
451: "Unavailable For Legal Reasons",
|
|
112
|
+
500: "Internal Server Error",
|
|
113
|
+
501: "Not Implemented",
|
|
114
|
+
502: "Bad Gateway",
|
|
115
|
+
503: "Service Unavailable",
|
|
116
|
+
504: "Gateway Timeout",
|
|
117
|
+
505: "HTTP Version Not Supported",
|
|
118
|
+
506: "Variant Also Negotiates",
|
|
119
|
+
507: "Insufficient Storage",
|
|
120
|
+
508: "Loop Detected",
|
|
121
|
+
510: "Not Extended",
|
|
122
|
+
511: "Network Authentication Required"
|
|
123
|
+
}, fe = {
|
|
124
|
+
setBaseUrl: (e) => {
|
|
125
|
+
b = e;
|
|
126
|
+
},
|
|
127
|
+
CodeNames: U,
|
|
60
128
|
/**
|
|
61
129
|
* Makes a GET request to the specified URL.
|
|
62
130
|
*
|
|
@@ -65,8 +133,11 @@ const oe = {
|
|
|
65
133
|
* @returns {Promise<any>} The response data.
|
|
66
134
|
* @throws {Error} If the response is not ok.
|
|
67
135
|
*/
|
|
68
|
-
get: async function(e,
|
|
69
|
-
return await
|
|
136
|
+
get: async function(e, t) {
|
|
137
|
+
return await w(
|
|
138
|
+
() => fetch(b + e, t),
|
|
139
|
+
t
|
|
140
|
+
);
|
|
70
141
|
},
|
|
71
142
|
/**
|
|
72
143
|
* Makes a POST request to the specified URL with the given data.
|
|
@@ -78,39 +149,37 @@ const oe = {
|
|
|
78
149
|
* @returns {Promise<R>} The response data.
|
|
79
150
|
* @throws {Error} If the response is not ok.
|
|
80
151
|
*/
|
|
81
|
-
post: async function(e,
|
|
82
|
-
return await
|
|
83
|
-
() => fetch(e, {
|
|
152
|
+
post: async function(e, t, r) {
|
|
153
|
+
return await w(
|
|
154
|
+
() => fetch(b + e, {
|
|
84
155
|
method: "POST",
|
|
85
156
|
headers: {
|
|
86
157
|
"Content-Type": "application/json",
|
|
87
|
-
...
|
|
158
|
+
...r?.headers
|
|
88
159
|
},
|
|
89
|
-
body: JSON.stringify(
|
|
90
|
-
...
|
|
160
|
+
body: JSON.stringify(t),
|
|
161
|
+
...r
|
|
91
162
|
}),
|
|
92
|
-
|
|
163
|
+
r
|
|
93
164
|
);
|
|
94
165
|
},
|
|
95
166
|
/**
|
|
96
|
-
* Makes a DELETE request to the specified URL
|
|
167
|
+
* Makes a DELETE request to the specified URL.
|
|
97
168
|
*
|
|
98
169
|
* @template R
|
|
99
170
|
* @param {string} url - The URL to send the DELETE request to.
|
|
100
|
-
* @param {string} id - The ID to send in the request body.
|
|
101
171
|
* @param {RequestInit} [options] - Optional request options.
|
|
102
172
|
* @returns {Promise<R>} The response data.
|
|
103
173
|
* @throws {Error} If the response is not ok.
|
|
104
174
|
*/
|
|
105
|
-
delete: async function(e,
|
|
106
|
-
return await
|
|
107
|
-
() => fetch(e, {
|
|
175
|
+
delete: async function(e, t) {
|
|
176
|
+
return await w(
|
|
177
|
+
() => fetch(b + e, {
|
|
108
178
|
method: "DELETE",
|
|
109
179
|
headers: {
|
|
110
180
|
"Content-Type": "application/json",
|
|
111
181
|
...t?.headers
|
|
112
182
|
},
|
|
113
|
-
body: JSON.stringify({ id: n }),
|
|
114
183
|
...t
|
|
115
184
|
}),
|
|
116
185
|
t
|
|
@@ -126,18 +195,18 @@ const oe = {
|
|
|
126
195
|
* @returns {Promise<R>} The response data.
|
|
127
196
|
* @throws {Error} If the response is not ok.
|
|
128
197
|
*/
|
|
129
|
-
patch: async function(e,
|
|
130
|
-
return await
|
|
131
|
-
() => fetch(e, {
|
|
198
|
+
patch: async function(e, t, r) {
|
|
199
|
+
return await w(
|
|
200
|
+
() => fetch(b + e, {
|
|
132
201
|
method: "PATCH",
|
|
133
202
|
headers: {
|
|
134
203
|
"Content-Type": "application/json",
|
|
135
|
-
...
|
|
204
|
+
...r?.headers
|
|
136
205
|
},
|
|
137
|
-
body: JSON.stringify(
|
|
138
|
-
...
|
|
206
|
+
body: JSON.stringify(t),
|
|
207
|
+
...r
|
|
139
208
|
}),
|
|
140
|
-
|
|
209
|
+
r
|
|
141
210
|
);
|
|
142
211
|
},
|
|
143
212
|
/**
|
|
@@ -150,123 +219,125 @@ const oe = {
|
|
|
150
219
|
* @returns {Promise<R>} The response data.
|
|
151
220
|
* @throws {Error} If the response is not ok.
|
|
152
221
|
*/
|
|
153
|
-
put: async function(e,
|
|
154
|
-
return await
|
|
155
|
-
() => fetch(e, {
|
|
222
|
+
put: async function(e, t, r) {
|
|
223
|
+
return await w(
|
|
224
|
+
() => fetch(b + e, {
|
|
156
225
|
method: "PUT",
|
|
157
226
|
headers: {
|
|
158
227
|
"Content-Type": "application/json",
|
|
159
|
-
...
|
|
228
|
+
...r?.headers
|
|
160
229
|
},
|
|
161
|
-
body: JSON.stringify(
|
|
162
|
-
...
|
|
230
|
+
body: JSON.stringify(t),
|
|
231
|
+
...r
|
|
163
232
|
}),
|
|
164
|
-
|
|
233
|
+
r
|
|
165
234
|
);
|
|
166
235
|
}
|
|
167
236
|
};
|
|
168
|
-
async function
|
|
237
|
+
async function w(e, t) {
|
|
169
238
|
try {
|
|
170
|
-
const
|
|
171
|
-
if (!
|
|
172
|
-
const
|
|
173
|
-
throw Object.assign(
|
|
174
|
-
|
|
175
|
-
{
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
body: r
|
|
179
|
-
}
|
|
180
|
-
);
|
|
239
|
+
const r = await e();
|
|
240
|
+
if (!r.ok) {
|
|
241
|
+
const n = await r.text(), [o, s] = E(() => JSON.parse(n));
|
|
242
|
+
throw Object.assign(r, {
|
|
243
|
+
data: s ? n : o,
|
|
244
|
+
name: `HTTP_${r.status}`,
|
|
245
|
+
message: r.statusText || U[r.status] || `HTTP_${r.status}`
|
|
246
|
+
});
|
|
181
247
|
}
|
|
182
|
-
return
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
248
|
+
return t?.parse === "JSON" ? Object.assign(r, {
|
|
249
|
+
data: await r.json()
|
|
250
|
+
}) : t?.parse === "TEXT" ? Object.assign(r, {
|
|
251
|
+
data: await r.text()
|
|
252
|
+
}) : t?.parse === "BLOB" ? Object.assign(r, {
|
|
253
|
+
data: await r.blob()
|
|
254
|
+
}) : t?.parse === "ARRAYBUFFER" ? Object.assign(r, {
|
|
255
|
+
data: await r.arrayBuffer()
|
|
256
|
+
}) : Object.assign(r, {
|
|
257
|
+
data: await r.json()
|
|
258
|
+
});
|
|
259
|
+
} catch (r) {
|
|
260
|
+
if (J(r)) throw r;
|
|
261
|
+
const n = {
|
|
262
|
+
data: r,
|
|
263
|
+
ok: !1,
|
|
264
|
+
status: 0,
|
|
265
|
+
statusText: "NETWORK_ERROR",
|
|
266
|
+
type: "error",
|
|
267
|
+
name: "NetworkError",
|
|
268
|
+
message: r instanceof Error ? r.message : String(r),
|
|
269
|
+
headers: new Headers(),
|
|
270
|
+
url: "",
|
|
271
|
+
redirected: !1,
|
|
272
|
+
clone: () => n,
|
|
273
|
+
bodyUsed: !1,
|
|
274
|
+
formData: () => Promise.resolve(new FormData())
|
|
275
|
+
};
|
|
276
|
+
throw n;
|
|
196
277
|
}
|
|
197
278
|
}
|
|
198
|
-
function
|
|
199
|
-
|
|
200
|
-
return e.status;
|
|
279
|
+
function J(e) {
|
|
280
|
+
return e !== null && typeof e == "object" && "data" in e && "body" in e;
|
|
201
281
|
}
|
|
202
|
-
function
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
282
|
+
function he(e, t) {
|
|
283
|
+
const r = {};
|
|
284
|
+
return e?.forEach((n, o) => {
|
|
285
|
+
const s = t(n, o, e)?.toString();
|
|
286
|
+
s && (r[s] ??= [], r[s].push(n));
|
|
287
|
+
}), r;
|
|
207
288
|
}
|
|
208
|
-
function
|
|
209
|
-
return
|
|
289
|
+
async function ge(e) {
|
|
290
|
+
return await new Promise((t) => setTimeout(t, e));
|
|
210
291
|
}
|
|
211
|
-
function
|
|
212
|
-
|
|
213
|
-
return e?.forEach((r, o) => {
|
|
214
|
-
const s = n(r, o, e)?.toString();
|
|
215
|
-
s && (t[s] ??= [], t[s].push(r));
|
|
216
|
-
}), t;
|
|
292
|
+
function pe(e, t, r) {
|
|
293
|
+
return t < e ? e : t > r ? r : t;
|
|
217
294
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
function le(e, n, t) {
|
|
225
|
-
let r;
|
|
226
|
-
return t?.isLoadingFn?.(!1), Object.assign((...s) => {
|
|
227
|
-
clearTimeout(r), t?.isLoadingFn?.(!0), r = setTimeout(() => {
|
|
228
|
-
t?.isLoadingFn?.(!1), e(...s);
|
|
229
|
-
}, n);
|
|
295
|
+
function me(e, t, r) {
|
|
296
|
+
let n;
|
|
297
|
+
return r?.isLoadingFn?.(!1), Object.assign((...s) => {
|
|
298
|
+
clearTimeout(n), r?.isLoadingFn?.(!0), n = setTimeout(() => {
|
|
299
|
+
r?.isLoadingFn?.(!1), e(...s);
|
|
300
|
+
}, t);
|
|
230
301
|
}, {
|
|
231
302
|
cancel() {
|
|
232
|
-
clearTimeout(
|
|
303
|
+
clearTimeout(n), r?.isLoadingFn?.(!1);
|
|
233
304
|
}
|
|
234
305
|
});
|
|
235
306
|
}
|
|
236
|
-
function
|
|
237
|
-
if (!
|
|
307
|
+
function Z(e, t) {
|
|
308
|
+
if (!t || typeof t != "string" || typeof e != "object" || e === null)
|
|
238
309
|
return;
|
|
239
|
-
const
|
|
240
|
-
function
|
|
310
|
+
const r = t.split(".");
|
|
311
|
+
function n(o, s) {
|
|
241
312
|
if (!s || typeof s != "object")
|
|
242
313
|
return;
|
|
243
314
|
const a = o[0];
|
|
244
315
|
if (a in s)
|
|
245
|
-
return o.length === 1 ? s[a] :
|
|
316
|
+
return o.length === 1 ? s[a] : n(o.slice(1), s[a]);
|
|
246
317
|
}
|
|
247
|
-
return r
|
|
318
|
+
return n(r, e);
|
|
248
319
|
}
|
|
249
|
-
function
|
|
250
|
-
let
|
|
251
|
-
for (let o = 0; o <
|
|
252
|
-
const s =
|
|
253
|
-
o ===
|
|
320
|
+
function K(e, t, r) {
|
|
321
|
+
let n = e;
|
|
322
|
+
for (let o = 0; o < t.length; o++) {
|
|
323
|
+
const s = t[o] ?? "";
|
|
324
|
+
o === t.length - 1 ? n[s] = r : ((!n[s] || typeof n[s] != "object") && (n[s] = {}), n = n[s]);
|
|
254
325
|
}
|
|
255
326
|
}
|
|
256
|
-
function
|
|
257
|
-
const
|
|
327
|
+
function ye(e, t) {
|
|
328
|
+
const r = {};
|
|
258
329
|
if (!e || typeof e != "object")
|
|
259
|
-
return
|
|
260
|
-
for (const
|
|
261
|
-
const o =
|
|
330
|
+
return r;
|
|
331
|
+
for (const n of t) {
|
|
332
|
+
const o = Z(e, n);
|
|
262
333
|
if (o !== void 0) {
|
|
263
|
-
const s =
|
|
264
|
-
|
|
334
|
+
const s = n.split(".");
|
|
335
|
+
K(r, s, o);
|
|
265
336
|
}
|
|
266
337
|
}
|
|
267
|
-
return
|
|
338
|
+
return r;
|
|
268
339
|
}
|
|
269
|
-
class
|
|
340
|
+
class m {
|
|
270
341
|
#e = null;
|
|
271
342
|
#t = null;
|
|
272
343
|
/**
|
|
@@ -274,24 +345,24 @@ class y {
|
|
|
274
345
|
* @param {T} val - The success value.
|
|
275
346
|
* @returns {Result<T, never>} A Result instance representing a success.
|
|
276
347
|
*/
|
|
277
|
-
static ok(
|
|
278
|
-
return new
|
|
348
|
+
static ok(t) {
|
|
349
|
+
return new m(t, null);
|
|
279
350
|
}
|
|
280
351
|
/**
|
|
281
352
|
* Creates a failed result.
|
|
282
353
|
* @param {E | string} err - The error value or message.
|
|
283
354
|
* @returns {Result<never, E>} A Result instance representing a failure.
|
|
284
355
|
*/
|
|
285
|
-
static err(
|
|
286
|
-
return typeof
|
|
356
|
+
static err(t) {
|
|
357
|
+
return typeof t == "string" ? new m(null, new Error(t)) : new m(null, t);
|
|
287
358
|
}
|
|
288
359
|
/**
|
|
289
360
|
* Wraps a promise in a Result.
|
|
290
361
|
* @param {Promise<T>} promise - The promise to wrap.
|
|
291
362
|
* @returns {Promise<Result<T, E>>} A promise that resolves to a Result.
|
|
292
363
|
*/
|
|
293
|
-
static async promise(
|
|
294
|
-
return
|
|
364
|
+
static async promise(t) {
|
|
365
|
+
return t.then((r) => m.ok(r)).catch((r) => m.err(r));
|
|
295
366
|
}
|
|
296
367
|
/**
|
|
297
368
|
* Wraps a function call in a Result.
|
|
@@ -299,12 +370,12 @@ class y {
|
|
|
299
370
|
* @param {...any[]} args - The arguments to pass to the function.
|
|
300
371
|
* @returns {Result<T, E>} A Result instance representing the function call result.
|
|
301
372
|
*/
|
|
302
|
-
static func(
|
|
373
|
+
static func(t, ...r) {
|
|
303
374
|
try {
|
|
304
|
-
const
|
|
305
|
-
return
|
|
306
|
-
} catch (
|
|
307
|
-
return
|
|
375
|
+
const n = t(...r);
|
|
376
|
+
return m.ok(n);
|
|
377
|
+
} catch (n) {
|
|
378
|
+
return m.err(n);
|
|
308
379
|
}
|
|
309
380
|
}
|
|
310
381
|
/**
|
|
@@ -312,16 +383,16 @@ class y {
|
|
|
312
383
|
* @param {E | null} err - The error value.
|
|
313
384
|
* @throws {Error} If both ok and err are provided or neither is provided.
|
|
314
385
|
*/
|
|
315
|
-
constructor(
|
|
316
|
-
if (
|
|
386
|
+
constructor(t, r) {
|
|
387
|
+
if (t == null && r == null)
|
|
317
388
|
throw new Error(
|
|
318
389
|
"Result must be initialized with either an ok or an err value"
|
|
319
390
|
);
|
|
320
|
-
if (
|
|
391
|
+
if (t != null && r != null)
|
|
321
392
|
throw new Error(
|
|
322
393
|
"Result can't be initialized with both an ok and an err value"
|
|
323
394
|
);
|
|
324
|
-
|
|
395
|
+
t != null ? this.#e = t : this.#t = r;
|
|
325
396
|
}
|
|
326
397
|
/**
|
|
327
398
|
* Gets the success value, throwing an error if the result is a failure.
|
|
@@ -346,8 +417,8 @@ class y {
|
|
|
346
417
|
* @param {T} defaultValue - The default value to return if the result is a failure.
|
|
347
418
|
* @returns {T} The success value or the default value.
|
|
348
419
|
*/
|
|
349
|
-
unwrapOr(
|
|
350
|
-
return this.isOk() ? this.#e :
|
|
420
|
+
unwrapOr(t) {
|
|
421
|
+
return this.isOk() ? this.#e : t;
|
|
351
422
|
}
|
|
352
423
|
/**
|
|
353
424
|
* Gets the success value, throwing a custom error message if the result is a failure.
|
|
@@ -355,15 +426,15 @@ class y {
|
|
|
355
426
|
* @returns {T} The success value.
|
|
356
427
|
* @throws {Error} If the result is a failure.
|
|
357
428
|
*/
|
|
358
|
-
expect(
|
|
429
|
+
expect(t) {
|
|
359
430
|
if (this.isOk())
|
|
360
431
|
return this.#e;
|
|
361
432
|
if (this.isErr()) {
|
|
362
|
-
const
|
|
363
|
-
throw new Error(
|
|
364
|
-
` +
|
|
433
|
+
const r = this.#t;
|
|
434
|
+
throw new Error(t + `:
|
|
435
|
+
` + r.message);
|
|
365
436
|
}
|
|
366
|
-
throw new Error(
|
|
437
|
+
throw new Error(t);
|
|
367
438
|
}
|
|
368
439
|
/**
|
|
369
440
|
* Checks if the result is a success.
|
|
@@ -387,209 +458,209 @@ class y {
|
|
|
387
458
|
return this.#t;
|
|
388
459
|
}
|
|
389
460
|
}
|
|
390
|
-
function
|
|
391
|
-
return e == null ?
|
|
461
|
+
function be(e, t = []) {
|
|
462
|
+
return e == null ? t : Array.isArray(e) ? e : [e];
|
|
392
463
|
}
|
|
393
|
-
const
|
|
394
|
-
const
|
|
464
|
+
const z = /* @__PURE__ */ Symbol("SIGNAL"), we = (e) => typeof e == "function" && z in e, g = [], Se = (e) => {
|
|
465
|
+
const t = g.splice(0, g.length);
|
|
395
466
|
try {
|
|
396
467
|
return e();
|
|
397
468
|
} finally {
|
|
398
|
-
|
|
469
|
+
g.push(...t);
|
|
399
470
|
}
|
|
400
|
-
},
|
|
401
|
-
const
|
|
402
|
-
let
|
|
471
|
+
}, R = (e, t) => {
|
|
472
|
+
const r = /* @__PURE__ */ new Set();
|
|
473
|
+
let n = 0;
|
|
403
474
|
const o = () => {
|
|
404
|
-
const l =
|
|
405
|
-
l && (
|
|
406
|
-
|
|
475
|
+
const l = g[g.length - 1];
|
|
476
|
+
l && (r.add(l.setDirty), l.addSource(() => {
|
|
477
|
+
r.delete(l.setDirty);
|
|
407
478
|
}));
|
|
408
479
|
}, s = (l) => {
|
|
409
|
-
for (const
|
|
410
|
-
}, a = () =>
|
|
480
|
+
for (const h of Array.from(r)) h(l);
|
|
481
|
+
}, a = () => n > 0;
|
|
411
482
|
return { read: Object.assign(() => (o(), e()), {
|
|
412
|
-
[
|
|
413
|
-
subscribe: (l) => (
|
|
414
|
-
|
|
483
|
+
[z]: !0,
|
|
484
|
+
subscribe: (l) => (r.add(l), n++, t?.(), () => {
|
|
485
|
+
r.delete(l), n--;
|
|
415
486
|
})
|
|
416
487
|
}), notify: s, hasSubscribers: a };
|
|
417
488
|
}, S = (e) => {
|
|
418
|
-
let
|
|
419
|
-
const { read:
|
|
420
|
-
return Object.assign(
|
|
489
|
+
let t = e;
|
|
490
|
+
const { read: r, notify: n } = R(() => t);
|
|
491
|
+
return Object.assign(r, {
|
|
421
492
|
set: (o) => {
|
|
422
|
-
|
|
493
|
+
t !== o && (t = o, n(o));
|
|
423
494
|
},
|
|
424
495
|
update: (o) => {
|
|
425
|
-
const s = o(
|
|
426
|
-
|
|
496
|
+
const s = o(t);
|
|
497
|
+
t !== s && (t = s, n(s));
|
|
427
498
|
},
|
|
428
|
-
asReadonly: () =>
|
|
499
|
+
asReadonly: () => r
|
|
429
500
|
});
|
|
430
501
|
}, k = (e) => {
|
|
431
|
-
const
|
|
432
|
-
let
|
|
502
|
+
const t = /* @__PURE__ */ new Set();
|
|
503
|
+
let r = !1, n = null, o = !1;
|
|
433
504
|
const s = () => {
|
|
434
|
-
if (o = !1,
|
|
435
|
-
|
|
505
|
+
if (o = !1, r) return;
|
|
506
|
+
n && (n(), n = null), t.forEach((i) => i()), t.clear();
|
|
436
507
|
const a = (i) => {
|
|
437
|
-
|
|
508
|
+
n = i;
|
|
438
509
|
};
|
|
439
|
-
|
|
510
|
+
g.push({
|
|
440
511
|
setDirty: () => {
|
|
441
|
-
!
|
|
512
|
+
!r && !o && (o = !0, queueMicrotask(s));
|
|
442
513
|
},
|
|
443
|
-
addSource: (i) =>
|
|
444
|
-
}), e(a),
|
|
514
|
+
addSource: (i) => t.add(i)
|
|
515
|
+
}), e(a), g.pop();
|
|
445
516
|
};
|
|
446
517
|
return s(), {
|
|
447
518
|
destroy() {
|
|
448
|
-
|
|
519
|
+
r = !0, n && (n(), n = null), t.forEach((a) => a()), t.clear();
|
|
449
520
|
}
|
|
450
521
|
};
|
|
451
|
-
},
|
|
452
|
-
const
|
|
453
|
-
let
|
|
522
|
+
}, j = (e) => {
|
|
523
|
+
const t = /* @__PURE__ */ new Set();
|
|
524
|
+
let r, n = !0, o = () => {
|
|
454
525
|
};
|
|
455
526
|
const s = () => {
|
|
456
|
-
|
|
527
|
+
t.forEach((c) => c()), t.clear(), g.push({
|
|
457
528
|
setDirty: () => {
|
|
458
|
-
if (
|
|
459
|
-
|
|
460
|
-
const c =
|
|
461
|
-
s(),
|
|
529
|
+
if (n) return;
|
|
530
|
+
n = !0;
|
|
531
|
+
const c = r;
|
|
532
|
+
s(), r !== c && o(r);
|
|
462
533
|
},
|
|
463
|
-
addSource: (c) =>
|
|
464
|
-
}),
|
|
465
|
-
}, { read: a, notify: i } =
|
|
466
|
-
() => (
|
|
534
|
+
addSource: (c) => t.add(c)
|
|
535
|
+
}), r = e(), n = !1, g.pop();
|
|
536
|
+
}, { read: a, notify: i } = R(
|
|
537
|
+
() => (n && s(), r),
|
|
467
538
|
() => {
|
|
468
|
-
|
|
539
|
+
n && s();
|
|
469
540
|
}
|
|
470
541
|
);
|
|
471
542
|
return o = i, a;
|
|
472
543
|
};
|
|
473
|
-
function
|
|
474
|
-
const
|
|
544
|
+
function Te(e) {
|
|
545
|
+
const t = typeof e == "function", r = t ? void 0 : e.source, n = t ? e : e.computation, o = /* @__PURE__ */ new Set();
|
|
475
546
|
let s, a = !0, i = !1, c, l = () => {
|
|
476
547
|
};
|
|
477
|
-
const
|
|
478
|
-
if (o.forEach((u) => u()), o.clear(),
|
|
548
|
+
const h = () => {
|
|
549
|
+
if (o.forEach((u) => u()), o.clear(), g.push({
|
|
479
550
|
setDirty: () => {
|
|
480
551
|
if (a) return;
|
|
481
552
|
a = !0, i = !1;
|
|
482
553
|
const u = s;
|
|
483
|
-
|
|
554
|
+
h(), s !== u && l(s);
|
|
484
555
|
},
|
|
485
556
|
addSource: (u) => o.add(u)
|
|
486
|
-
}),
|
|
487
|
-
s =
|
|
557
|
+
}), t)
|
|
558
|
+
s = n();
|
|
488
559
|
else {
|
|
489
|
-
const u =
|
|
490
|
-
s =
|
|
560
|
+
const u = r?.();
|
|
561
|
+
s = n(u, c), c = { source: u, value: s };
|
|
491
562
|
}
|
|
492
|
-
a = !1,
|
|
493
|
-
}, { read:
|
|
494
|
-
() => (a && !i &&
|
|
563
|
+
a = !1, g.pop();
|
|
564
|
+
}, { read: v, notify: f } = R(
|
|
565
|
+
() => (a && !i && h(), s),
|
|
495
566
|
() => {
|
|
496
|
-
a && !i &&
|
|
567
|
+
a && !i && h();
|
|
497
568
|
}
|
|
498
569
|
);
|
|
499
|
-
l =
|
|
500
|
-
const
|
|
570
|
+
l = f;
|
|
571
|
+
const y = Object.assign(v, {
|
|
501
572
|
set: (u) => {
|
|
502
|
-
s !== u && (s = u, i = !0, a = !1,
|
|
573
|
+
s !== u && (s = u, i = !0, a = !1, f(u));
|
|
503
574
|
},
|
|
504
575
|
update: (u) => {
|
|
505
|
-
a && !i &&
|
|
576
|
+
a && !i && h(), y.set(u(s));
|
|
506
577
|
},
|
|
507
|
-
asReadonly: () =>
|
|
578
|
+
asReadonly: () => v
|
|
508
579
|
});
|
|
509
|
-
return
|
|
510
|
-
}
|
|
511
|
-
class
|
|
512
|
-
constructor(
|
|
513
|
-
const
|
|
514
|
-
${
|
|
515
|
-
super(`Cannot read resource value while in error state${
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
function
|
|
519
|
-
const
|
|
520
|
-
if (
|
|
521
|
-
throw new
|
|
522
|
-
return
|
|
523
|
-
}), i = (
|
|
524
|
-
|
|
525
|
-
}, c = (
|
|
526
|
-
|
|
580
|
+
return y;
|
|
581
|
+
}
|
|
582
|
+
class X extends Error {
|
|
583
|
+
constructor(t) {
|
|
584
|
+
const r = t instanceof Error ? `:
|
|
585
|
+
${t.message}` : "";
|
|
586
|
+
super(`Cannot read resource value while in error state${r}`, { cause: t }), this.name = "ResourceErrorState";
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
function $e(e) {
|
|
590
|
+
const t = S(void 0), r = S("idle"), n = S(void 0), o = j(() => r() === "loading"), s = S(0), a = j(() => {
|
|
591
|
+
if (r() === "error")
|
|
592
|
+
throw new X(n());
|
|
593
|
+
return t();
|
|
594
|
+
}), i = (f) => {
|
|
595
|
+
t.set(f), n.set(void 0), r.set("resolved");
|
|
596
|
+
}, c = (f) => {
|
|
597
|
+
t.update(f), n.set(void 0), r.set("resolved");
|
|
527
598
|
}, l = "params" in e;
|
|
528
599
|
if ("stream" in e) {
|
|
529
|
-
const
|
|
600
|
+
const f = S(void 0), y = k((p) => {
|
|
530
601
|
s();
|
|
531
|
-
const
|
|
532
|
-
|
|
533
|
-
const
|
|
534
|
-
|
|
535
|
-
const
|
|
536
|
-
params:
|
|
537
|
-
abortSignal:
|
|
602
|
+
const d = new AbortController();
|
|
603
|
+
p(() => d.abort());
|
|
604
|
+
const H = l ? e.params() : void 0;
|
|
605
|
+
r.set("loading"), n.set(void 0);
|
|
606
|
+
const P = e.stream, G = P(l ? {
|
|
607
|
+
params: H,
|
|
608
|
+
abortSignal: d.signal
|
|
538
609
|
} : {
|
|
539
|
-
abortSignal:
|
|
610
|
+
abortSignal: d.signal
|
|
540
611
|
});
|
|
541
|
-
|
|
612
|
+
f.set(G);
|
|
542
613
|
}), u = k(() => {
|
|
543
|
-
const
|
|
544
|
-
if (!
|
|
545
|
-
const
|
|
546
|
-
|
|
614
|
+
const p = f();
|
|
615
|
+
if (!p) return;
|
|
616
|
+
const d = p();
|
|
617
|
+
d && ("error" in d && d.error !== void 0 ? (n.set(d.error), r.set("error")) : "value" in d && (t.set(d.value), r.set("resolved")));
|
|
547
618
|
});
|
|
548
619
|
return {
|
|
549
620
|
value: a,
|
|
550
|
-
status:
|
|
551
|
-
error:
|
|
621
|
+
status: r,
|
|
622
|
+
error: n,
|
|
552
623
|
isLoading: o,
|
|
553
624
|
set: i,
|
|
554
625
|
update: c,
|
|
555
626
|
reload: () => {
|
|
556
|
-
s.update((
|
|
627
|
+
s.update((p) => p + 1);
|
|
557
628
|
},
|
|
558
629
|
destroy: () => {
|
|
559
|
-
|
|
630
|
+
y.destroy(), u.destroy();
|
|
560
631
|
}
|
|
561
632
|
};
|
|
562
633
|
}
|
|
563
|
-
const
|
|
634
|
+
const v = k((f) => {
|
|
564
635
|
s();
|
|
565
|
-
const
|
|
566
|
-
|
|
636
|
+
const y = l ? e.params() : void 0;
|
|
637
|
+
r.set("loading"), n.set(void 0);
|
|
567
638
|
const u = new AbortController();
|
|
568
|
-
|
|
569
|
-
const
|
|
570
|
-
e.loader(
|
|
571
|
-
(
|
|
572
|
-
u.signal.aborted || (
|
|
639
|
+
f(() => u.abort());
|
|
640
|
+
const p = l ? { params: y, abortSignal: u.signal } : { abortSignal: u.signal };
|
|
641
|
+
e.loader(p).then(
|
|
642
|
+
(d) => {
|
|
643
|
+
u.signal.aborted || (t.set(d), r.set("resolved"));
|
|
573
644
|
},
|
|
574
|
-
(
|
|
575
|
-
u.signal.aborted || (
|
|
645
|
+
(d) => {
|
|
646
|
+
u.signal.aborted || (n.set(d), r.set("error"));
|
|
576
647
|
}
|
|
577
648
|
);
|
|
578
649
|
});
|
|
579
650
|
return {
|
|
580
651
|
value: a,
|
|
581
|
-
status:
|
|
582
|
-
error:
|
|
652
|
+
status: r,
|
|
653
|
+
error: n,
|
|
583
654
|
isLoading: o,
|
|
584
655
|
set: i,
|
|
585
656
|
update: c,
|
|
586
657
|
reload: () => {
|
|
587
|
-
s.update((
|
|
658
|
+
s.update((f) => f + 1);
|
|
588
659
|
},
|
|
589
|
-
destroy: () =>
|
|
660
|
+
destroy: () => v.destroy()
|
|
590
661
|
};
|
|
591
662
|
}
|
|
592
|
-
const
|
|
663
|
+
const L = /* @__PURE__ */ new Map([
|
|
593
664
|
["b", "b"],
|
|
594
665
|
["i", "i"],
|
|
595
666
|
["u", "u"],
|
|
@@ -613,7 +684,7 @@ const A = /* @__PURE__ */ new Map([
|
|
|
613
684
|
["ul", "ul"],
|
|
614
685
|
["ol", "ol"],
|
|
615
686
|
["li", "li"]
|
|
616
|
-
]),
|
|
687
|
+
]), T = /* @__PURE__ */ new Set([
|
|
617
688
|
"div",
|
|
618
689
|
"p",
|
|
619
690
|
"ul",
|
|
@@ -626,292 +697,355 @@ const A = /* @__PURE__ */ new Map([
|
|
|
626
697
|
"h5",
|
|
627
698
|
"h6"
|
|
628
699
|
]);
|
|
629
|
-
let
|
|
630
|
-
function
|
|
631
|
-
return
|
|
700
|
+
let x = "rtp-";
|
|
701
|
+
function C() {
|
|
702
|
+
return x;
|
|
632
703
|
}
|
|
633
|
-
function
|
|
634
|
-
|
|
704
|
+
function Y(e) {
|
|
705
|
+
x = e;
|
|
635
706
|
}
|
|
636
|
-
const
|
|
707
|
+
const $ = /* @__PURE__ */ new Map([
|
|
637
708
|
["br", "br"],
|
|
638
709
|
["hr", "hr"]
|
|
639
|
-
])
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
[
|
|
656
|
-
"sup",
|
|
657
|
-
/* @__PURE__ */ new Map([
|
|
658
|
-
["vertical-align", "super"],
|
|
659
|
-
["font-size", "smaller"]
|
|
660
|
-
])
|
|
661
|
-
],
|
|
662
|
-
[
|
|
663
|
-
"h1",
|
|
664
|
-
/* @__PURE__ */ new Map([
|
|
665
|
-
["font-size", "2em"],
|
|
666
|
-
["font-weight", "bold"]
|
|
667
|
-
])
|
|
668
|
-
],
|
|
669
|
-
[
|
|
670
|
-
"h2",
|
|
671
|
-
/* @__PURE__ */ new Map([
|
|
672
|
-
["font-size", "1.5em"],
|
|
673
|
-
["font-weight", "bold"]
|
|
674
|
-
])
|
|
675
|
-
],
|
|
676
|
-
[
|
|
677
|
-
"h3",
|
|
678
|
-
/* @__PURE__ */ new Map([
|
|
679
|
-
["font-size", "1.17em"],
|
|
680
|
-
["font-weight", "bold"]
|
|
681
|
-
])
|
|
682
|
-
],
|
|
683
|
-
[
|
|
684
|
-
"h4",
|
|
685
|
-
/* @__PURE__ */ new Map([
|
|
686
|
-
["font-size", "1em"],
|
|
687
|
-
["font-weight", "bold"]
|
|
688
|
-
])
|
|
689
|
-
],
|
|
690
|
-
[
|
|
691
|
-
"h5",
|
|
692
|
-
/* @__PURE__ */ new Map([
|
|
693
|
-
["font-size", "0.83em"],
|
|
694
|
-
["font-weight", "bold"]
|
|
695
|
-
])
|
|
696
|
-
],
|
|
697
|
-
[
|
|
698
|
-
"h6",
|
|
699
|
-
/* @__PURE__ */ new Map([
|
|
700
|
-
["font-size", "0.67em"],
|
|
701
|
-
["font-weight", "bold"]
|
|
702
|
-
])
|
|
703
|
-
],
|
|
704
|
-
["code", /* @__PURE__ */ new Map([["font-family", "monospace"]])],
|
|
705
|
-
["p", /* @__PURE__ */ new Map([["margin-block", "1em"]])],
|
|
706
|
-
["div", /* @__PURE__ */ new Map([["display", "block"]])],
|
|
707
|
-
["ul", /* @__PURE__ */ new Map([["padding-left", "1.5em"]])],
|
|
708
|
-
["ol", /* @__PURE__ */ new Map([["padding-left", "1.5em"]])],
|
|
709
|
-
["li", /* @__PURE__ */ new Map([["margin-block", "0.5em"]])],
|
|
710
|
-
[
|
|
711
|
-
"br",
|
|
712
|
-
/* @__PURE__ */ new Map([
|
|
713
|
-
["display", "block"],
|
|
714
|
-
["height", "1em"]
|
|
715
|
-
])
|
|
716
|
-
],
|
|
717
|
-
[
|
|
718
|
-
"hr",
|
|
719
|
-
/* @__PURE__ */ new Map([
|
|
720
|
-
["display", "block"],
|
|
721
|
-
["border", "0"],
|
|
722
|
-
["border-top", "1px solid #ccc"],
|
|
723
|
-
["border-color", "green"],
|
|
724
|
-
["margin", "1em 0"]
|
|
725
|
-
])
|
|
726
|
-
]
|
|
727
|
-
]), x = (e, n, t, r, o) => {
|
|
728
|
-
const s = e.filter((i) => !v.has(i)), a = e.filter((i) => v.has(i));
|
|
710
|
+
]);
|
|
711
|
+
function W(e) {
|
|
712
|
+
const t = [];
|
|
713
|
+
let r;
|
|
714
|
+
for (const n of e) {
|
|
715
|
+
const o = n.containerTagNames.join(","), s = r?.containerTagNames.join(",");
|
|
716
|
+
o !== s && (r = {
|
|
717
|
+
containerTagNames: n.containerTagNames,
|
|
718
|
+
cssClass: n.containerTagNames.map((a) => `${C()}${a}`).join(" "),
|
|
719
|
+
segments: []
|
|
720
|
+
}, t.push(r)), r.segments.push(n);
|
|
721
|
+
}
|
|
722
|
+
return t;
|
|
723
|
+
}
|
|
724
|
+
const N = (e, t, r, n, o) => {
|
|
725
|
+
const s = e.filter((i) => !T.has(i)), a = e.filter((i) => T.has(i));
|
|
729
726
|
return {
|
|
730
727
|
tagNames: e.join(","),
|
|
731
728
|
tagNamesList: e,
|
|
732
|
-
text: o ??
|
|
733
|
-
style: s.map(
|
|
734
|
-
(i) => [...w.get(i)?.entries() ?? []].map(([c, l]) => `${c}: ${l}`).join("; ")
|
|
735
|
-
).filter(Boolean).join("; "),
|
|
736
|
-
styleObject: Object.fromEntries(
|
|
737
|
-
s.flatMap((i) => Array.from(w.get(i) ?? []))
|
|
738
|
-
),
|
|
729
|
+
text: o ?? t.slice(r, n),
|
|
739
730
|
containerTagNames: a,
|
|
740
|
-
cssClass: s.map((i) => `${
|
|
731
|
+
cssClass: s.map((i) => `${C()}${i}`).join(" ")
|
|
741
732
|
};
|
|
742
|
-
},
|
|
743
|
-
`<\\/?(${
|
|
733
|
+
}, Q = () => [...L.keys()].join("|"), ee = () => [...$.keys()].join("|"), te = () => new RegExp(
|
|
734
|
+
`<\\/?(${Q()})>|<(${ee()})\\s*/?>`,
|
|
744
735
|
"gi"
|
|
745
736
|
);
|
|
746
|
-
function
|
|
747
|
-
const t =
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
if (t.size === 0) continue;
|
|
754
|
-
const r = [...t.entries()].map(([o, s]) => ` ${o}: ${s};`).join(`
|
|
755
|
-
`);
|
|
756
|
-
e.push(`.${M()}${n} {
|
|
757
|
-
${r}
|
|
758
|
-
}`);
|
|
759
|
-
}
|
|
760
|
-
return e.join(`
|
|
761
|
-
`);
|
|
762
|
-
}
|
|
763
|
-
function Q() {
|
|
764
|
-
if ("document" in globalThis) {
|
|
765
|
-
const e = P(), n = globalThis, t = n.document.getElementById(
|
|
766
|
-
"html-text-parser-styles"
|
|
737
|
+
function D(e) {
|
|
738
|
+
const t = [], r = /* @__PURE__ */ new Map();
|
|
739
|
+
let n = 0;
|
|
740
|
+
for (const o of e.matchAll(te())) {
|
|
741
|
+
const s = o.index;
|
|
742
|
+
s > n && t.push(
|
|
743
|
+
N([...r.keys()], e, n, s)
|
|
767
744
|
);
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
745
|
+
const a = o[2]?.toLowerCase();
|
|
746
|
+
if (a && $.has(a)) {
|
|
747
|
+
t.push(
|
|
748
|
+
N(
|
|
749
|
+
[...r.keys(), a],
|
|
750
|
+
e,
|
|
751
|
+
n,
|
|
752
|
+
s,
|
|
753
|
+
""
|
|
754
|
+
)
|
|
755
|
+
), n = s + o[0].length;
|
|
756
|
+
continue;
|
|
771
757
|
}
|
|
772
|
-
const
|
|
773
|
-
|
|
758
|
+
const i = o[0][1] === "/", c = L.get(o[1]?.toLowerCase() ?? "") ?? "";
|
|
759
|
+
if (i) {
|
|
760
|
+
const l = (r.get(c) ?? 1) - 1;
|
|
761
|
+
l <= 0 ? r.delete(c) : r.set(c, l);
|
|
762
|
+
} else
|
|
763
|
+
r.set(c, (r.get(c) ?? 0) + 1);
|
|
764
|
+
n = s + o[0].length;
|
|
765
|
+
}
|
|
766
|
+
return n < e.length && t.push(
|
|
767
|
+
N(
|
|
768
|
+
[...r.keys()],
|
|
769
|
+
e,
|
|
770
|
+
n,
|
|
771
|
+
e.length
|
|
772
|
+
)
|
|
773
|
+
), t;
|
|
774
|
+
}
|
|
775
|
+
function F(e) {
|
|
776
|
+
return W(e);
|
|
777
|
+
}
|
|
778
|
+
function A(e, t) {
|
|
779
|
+
e.className = `${C()}${t}`;
|
|
780
|
+
}
|
|
781
|
+
function re(e, t, r) {
|
|
782
|
+
const n = t.tagNamesList.filter((i) => !T.has(i)), o = n.filter((i) => $.has(i)), s = n.filter((i) => !$.has(i));
|
|
783
|
+
let a = e;
|
|
784
|
+
for (const i of s) {
|
|
785
|
+
const c = r.createElement(i);
|
|
786
|
+
A(c, i), a.appendChild(c), a = c;
|
|
787
|
+
}
|
|
788
|
+
if (t.text) {
|
|
789
|
+
a.appendChild(r.createTextNode(t.text));
|
|
774
790
|
return;
|
|
775
791
|
}
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
792
|
+
for (const i of o) {
|
|
793
|
+
const c = r.createElement(i);
|
|
794
|
+
A(c, i), a.appendChild(c);
|
|
795
|
+
}
|
|
779
796
|
}
|
|
780
|
-
function
|
|
797
|
+
function ne(e, t, r) {
|
|
781
798
|
const n = [];
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
)
|
|
796
|
-
segments: []
|
|
797
|
-
}, n.push(t)), t.segments.push(r);
|
|
799
|
+
for (const o of t) {
|
|
800
|
+
const s = o.containerTagNames;
|
|
801
|
+
let a = 0;
|
|
802
|
+
for (; a < n.length && a < s.length && n[a]?.tag === s[a]; )
|
|
803
|
+
a++;
|
|
804
|
+
n.length = a;
|
|
805
|
+
let i = n[n.length - 1]?.node ?? e;
|
|
806
|
+
for (const l of s.slice(a)) {
|
|
807
|
+
const h = r.createElement(l);
|
|
808
|
+
A(h, l), i.appendChild(h), n.push({ tag: l, node: h }), i = h;
|
|
809
|
+
}
|
|
810
|
+
const c = n[n.length - 1]?.node ?? e;
|
|
811
|
+
for (const l of o.segments)
|
|
812
|
+
re(c, l, r);
|
|
798
813
|
}
|
|
799
|
-
return n;
|
|
800
814
|
}
|
|
801
|
-
function
|
|
815
|
+
function se(e, t) {
|
|
802
816
|
if (!("document" in globalThis)) {
|
|
803
|
-
console.warn(
|
|
804
|
-
"[html-text-parser] Cannot append segments: document is not available."
|
|
805
|
-
);
|
|
817
|
+
console.warn("[html-text-parser] appendToDom: document is not available.");
|
|
806
818
|
return;
|
|
807
819
|
}
|
|
808
820
|
if (!e || !("appendChild" in e)) {
|
|
809
821
|
console.warn(
|
|
810
|
-
"[html-text-parser]
|
|
822
|
+
"[html-text-parser] appendToDom: element does not support appendChild."
|
|
811
823
|
);
|
|
812
824
|
return;
|
|
813
825
|
}
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
826
|
+
const r = globalThis.document, n = F(D(t));
|
|
827
|
+
ne(e, n, r);
|
|
828
|
+
}
|
|
829
|
+
const O = "html-text-parser-styles", I = {};
|
|
830
|
+
function M(e) {
|
|
831
|
+
const t = I;
|
|
832
|
+
return `
|
|
833
|
+
/* rtp = reach text parser */
|
|
834
|
+
|
|
835
|
+
.${e}b {
|
|
836
|
+
font-weight: bold;
|
|
837
|
+
${t.b ?? ""}
|
|
824
838
|
}
|
|
825
|
-
|
|
826
|
-
|
|
839
|
+
|
|
840
|
+
.${e}i {
|
|
841
|
+
font-style: italic;
|
|
842
|
+
${t.i ?? ""}
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
.${e}u {
|
|
846
|
+
text-decoration: underline;
|
|
847
|
+
${t.u ?? ""}
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
.${e}s {
|
|
851
|
+
text-decoration: line-through;
|
|
852
|
+
${t.s ?? ""}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
.${e}mark {
|
|
856
|
+
background-color: yellow;
|
|
857
|
+
${t.mark ?? ""}
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
.${e}small {
|
|
861
|
+
font-size: smaller;
|
|
862
|
+
${t.small ?? ""}
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
.${e}sup {
|
|
866
|
+
vertical-align: super;
|
|
867
|
+
font-size: smaller;
|
|
868
|
+
${t.sup ?? ""}
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
.${e}sub {
|
|
872
|
+
vertical-align: sub;
|
|
873
|
+
font-size: smaller;
|
|
874
|
+
${t.sub ?? ""}
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
.${e}h1 {
|
|
878
|
+
font-size: 2em;
|
|
879
|
+
font-weight: bold;
|
|
880
|
+
display: block;
|
|
881
|
+
${t.h1 ?? ""}
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
.${e}h2 {
|
|
885
|
+
font-size: 1.5em;
|
|
886
|
+
font-weight: bold;
|
|
887
|
+
display: block;
|
|
888
|
+
${t.h2 ?? ""}
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
.${e}h3 {
|
|
892
|
+
font-size: 1.17em;
|
|
893
|
+
font-weight: bold;
|
|
894
|
+
display: block;
|
|
895
|
+
${t.h3 ?? ""}
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
.${e}h4 {
|
|
899
|
+
font-size: 1em;
|
|
900
|
+
font-weight: bold;
|
|
901
|
+
display: block;
|
|
902
|
+
${t.h4 ?? ""}
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
.${e}h5 {
|
|
906
|
+
font-size: 0.83em;
|
|
907
|
+
font-weight: bold;
|
|
908
|
+
display: block;
|
|
909
|
+
${t.h5 ?? ""}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
.${e}h6 {
|
|
913
|
+
font-size: 0.67em;
|
|
914
|
+
font-weight: bold;
|
|
915
|
+
display: block;
|
|
916
|
+
${t.h6 ?? ""}
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
.${e}code {
|
|
920
|
+
font-family: monospace;
|
|
921
|
+
${t.code ?? ""}
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
.${e}span {
|
|
925
|
+
${t.span ?? ""}
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
.${e}p {
|
|
929
|
+
margin-block: 1em;
|
|
930
|
+
display: block;
|
|
931
|
+
${t.p ?? ""}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
.${e}div {
|
|
935
|
+
display: block;
|
|
936
|
+
${t.div ?? ""}
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
.${e}ul {
|
|
940
|
+
padding-left: 1.5em;
|
|
941
|
+
list-style: disc;
|
|
942
|
+
display: block;
|
|
943
|
+
${t.ul ?? ""}
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
.${e}ol {
|
|
947
|
+
padding-left: 1.5em;
|
|
948
|
+
list-style: decimal;
|
|
949
|
+
display: block;
|
|
950
|
+
${t.ol ?? ""}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
.${e}li {
|
|
954
|
+
margin-block: 0.5em;
|
|
955
|
+
display: list-item;
|
|
956
|
+
${t.li ?? ""}
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
.${e}br {
|
|
960
|
+
${t.br ?? ""}
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
.${e}hr {
|
|
964
|
+
${t.hr ?? ""}
|
|
965
|
+
}
|
|
966
|
+
`;
|
|
827
967
|
}
|
|
828
|
-
function
|
|
829
|
-
return
|
|
968
|
+
function oe() {
|
|
969
|
+
return M(C());
|
|
830
970
|
}
|
|
831
|
-
function B(
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
const s = o.index;
|
|
836
|
-
s > r && n.push(
|
|
837
|
-
x([...t.keys()], e, r, s)
|
|
971
|
+
function B() {
|
|
972
|
+
if (!("document" in globalThis)) {
|
|
973
|
+
console.warn(
|
|
974
|
+
"[html-text-parser] Cannot inject stylesheet: document is not available."
|
|
838
975
|
);
|
|
839
|
-
|
|
840
|
-
if (a && N.has(a)) {
|
|
841
|
-
n.push(
|
|
842
|
-
x(
|
|
843
|
-
[...t.keys(), a],
|
|
844
|
-
e,
|
|
845
|
-
r,
|
|
846
|
-
s,
|
|
847
|
-
""
|
|
848
|
-
)
|
|
849
|
-
), r = s + o[0].length;
|
|
850
|
-
continue;
|
|
851
|
-
}
|
|
852
|
-
const i = o[0][1] === "/", c = A.get(o[1]?.toLowerCase() ?? "") ?? "";
|
|
853
|
-
if (i) {
|
|
854
|
-
const l = (t.get(c) ?? 1) - 1;
|
|
855
|
-
l <= 0 ? t.delete(c) : t.set(c, l);
|
|
856
|
-
} else
|
|
857
|
-
t.set(c, (t.get(c) ?? 0) + 1);
|
|
858
|
-
r = s + o[0].length;
|
|
976
|
+
return;
|
|
859
977
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
978
|
+
const e = globalThis, t = e.document.getElementById(O), r = M(C());
|
|
979
|
+
if (t) {
|
|
980
|
+
t.textContent = r;
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
const n = e.document.createElement("style");
|
|
984
|
+
n.setAttribute("id", O), n.textContent = r, e.document.head.appendChild(n);
|
|
985
|
+
}
|
|
986
|
+
function ae(e) {
|
|
987
|
+
Object.assign(
|
|
988
|
+
I,
|
|
989
|
+
Object.fromEntries(
|
|
990
|
+
Object.entries(e).map(([t, r]) => [
|
|
991
|
+
t,
|
|
992
|
+
r.replace(/;/g, " !important;")
|
|
993
|
+
])
|
|
866
994
|
)
|
|
867
|
-
),
|
|
995
|
+
), "document" in globalThis && B();
|
|
868
996
|
}
|
|
869
|
-
function
|
|
997
|
+
function _(e) {
|
|
870
998
|
if (Array.isArray(e)) {
|
|
871
|
-
e.forEach((
|
|
872
|
-
U(t);
|
|
873
|
-
});
|
|
999
|
+
e.forEach((r) => _(r));
|
|
874
1000
|
return;
|
|
875
1001
|
}
|
|
876
|
-
const
|
|
877
|
-
|
|
1002
|
+
const t = e.tagName ?? e.tag;
|
|
1003
|
+
L.set(e.tag, t);
|
|
878
1004
|
}
|
|
879
|
-
function
|
|
1005
|
+
function q(e) {
|
|
880
1006
|
if (Array.isArray(e)) {
|
|
881
|
-
e.forEach((
|
|
882
|
-
D(t);
|
|
883
|
-
});
|
|
1007
|
+
e.forEach((r) => q(r));
|
|
884
1008
|
return;
|
|
885
1009
|
}
|
|
886
|
-
const
|
|
887
|
-
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
1010
|
+
const t = e.tagName ?? e.tag;
|
|
1011
|
+
$.set(e.tag, t);
|
|
1012
|
+
}
|
|
1013
|
+
function ie(e) {
|
|
1014
|
+
T.add(e);
|
|
1015
|
+
}
|
|
1016
|
+
function ce(e) {
|
|
1017
|
+
T.delete(e);
|
|
1018
|
+
}
|
|
1019
|
+
const Ce = {
|
|
1020
|
+
appendToDom: se,
|
|
1021
|
+
parseSegments: D,
|
|
1022
|
+
groupSegments: F,
|
|
1023
|
+
setTag: _,
|
|
1024
|
+
setSelfClosingTag: q,
|
|
1025
|
+
setBlockTag: ie,
|
|
1026
|
+
removeBlockTag: ce,
|
|
1027
|
+
setCssClassPrefix: Y,
|
|
1028
|
+
getStylesheet: oe,
|
|
1029
|
+
generateStylesheet: B,
|
|
1030
|
+
overrideStyles: ae
|
|
1031
|
+
};
|
|
1032
|
+
function le(e, t, r) {
|
|
1033
|
+
function n(o) {
|
|
1034
|
+
const [s, a] = E(() => r ? r(o) : o);
|
|
901
1035
|
if (a) throw new Error(`Error transforming value for ${e}: ${a.message}`);
|
|
902
|
-
if (!
|
|
1036
|
+
if (!t(s)) throw new Error(`"${o}" is not a valid ${e}`);
|
|
903
1037
|
return s;
|
|
904
1038
|
}
|
|
905
|
-
return
|
|
906
|
-
const [s, a] = E(() =>
|
|
1039
|
+
return n.from = (o) => {
|
|
1040
|
+
const [s, a] = E(() => r ? r(o) : o);
|
|
907
1041
|
if (!a)
|
|
908
|
-
return
|
|
909
|
-
},
|
|
910
|
-
const s = E(() =>
|
|
911
|
-
return
|
|
912
|
-
},
|
|
1042
|
+
return t(s) ? s : void 0;
|
|
1043
|
+
}, n.is = (o) => {
|
|
1044
|
+
const s = E(() => r ? r(o) : o)[0] ?? o;
|
|
1045
|
+
return t(s);
|
|
1046
|
+
}, n;
|
|
913
1047
|
}
|
|
914
|
-
const
|
|
1048
|
+
const ve = le(
|
|
915
1049
|
"NumericString",
|
|
916
1050
|
(e) => (
|
|
917
1051
|
// checks that a given value is:
|
|
@@ -921,32 +1055,30 @@ const ye = ne(
|
|
|
921
1055
|
(e) => String(e)
|
|
922
1056
|
);
|
|
923
1057
|
export {
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
1058
|
+
fe as Http,
|
|
1059
|
+
U as HttpCodeNames,
|
|
1060
|
+
ve as NumericString,
|
|
1061
|
+
m as Result,
|
|
1062
|
+
z as SIGNAL,
|
|
1063
|
+
pe as clamp,
|
|
1064
|
+
j as computed,
|
|
1065
|
+
ue as convertCase,
|
|
1066
|
+
le as createBrand,
|
|
1067
|
+
me as debounce,
|
|
1068
|
+
ge as delay,
|
|
933
1069
|
k as effect,
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
ge as resource,
|
|
944
|
-
Z as setDeepValue,
|
|
945
|
-
U as setRichTextTag,
|
|
946
|
-
D as setSelfClosingTag,
|
|
1070
|
+
Z as getProp,
|
|
1071
|
+
he as groupBy,
|
|
1072
|
+
Ce as htmlTextParser,
|
|
1073
|
+
we as isSignal,
|
|
1074
|
+
Te as linkedSignal,
|
|
1075
|
+
V as normalizeString,
|
|
1076
|
+
ye as pickPaths,
|
|
1077
|
+
$e as resource,
|
|
1078
|
+
K as setDeepValue,
|
|
947
1079
|
S as signal,
|
|
948
|
-
|
|
1080
|
+
be as toArray,
|
|
949
1081
|
E as tryCatch,
|
|
950
|
-
|
|
951
|
-
|
|
1082
|
+
de as tryCatchAsync,
|
|
1083
|
+
Se as untracked
|
|
952
1084
|
};
|