@dvirus-js/utils 0.0.1
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 +69 -0
- package/README.md +237 -0
- package/index.d.ts +11 -0
- package/index.js +837 -0
- package/lib/Result.d.ts +79 -0
- package/lib/brand-type/brand-factory.d.ts +39 -0
- package/lib/brand-type/index.d.ts +2 -0
- package/lib/brand-type/numeric-string.d.ts +15 -0
- package/lib/convert-cases.d.ts +15 -0
- package/lib/delay.d.ts +21 -0
- package/lib/getProp.d.ts +17 -0
- package/lib/group-by.d.ts +13 -0
- package/lib/html-text-parser/constant.d.ts +19 -0
- package/lib/html-text-parser/html-text-parser.d.ts +51 -0
- package/lib/html-text-parser/index.d.ts +2 -0
- package/lib/html-text-parser/methods.d.ts +28 -0
- package/lib/html-text-parser/types.d.ts +35 -0
- package/lib/html-text-parser___.d.ts +59 -0
- package/lib/http.d.ts +58 -0
- package/lib/signals.d.ts +72 -0
- package/lib/to-array.d.ts +1 -0
- package/lib/tryCatch.d.ts +22 -0
- package/package.json +11 -0
package/index.js
ADDED
|
@@ -0,0 +1,837 @@
|
|
|
1
|
+
function D(t) {
|
|
2
|
+
return t.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
|
+
}
|
|
4
|
+
function W(t, r) {
|
|
5
|
+
const e = D(t);
|
|
6
|
+
switch (r) {
|
|
7
|
+
case "lowercase":
|
|
8
|
+
return e.toLowerCase();
|
|
9
|
+
case "UPPERCASE":
|
|
10
|
+
return e.toUpperCase();
|
|
11
|
+
case "Title Case":
|
|
12
|
+
return e.split(" ").map(
|
|
13
|
+
(n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()
|
|
14
|
+
).join(" ");
|
|
15
|
+
case "kebab-case":
|
|
16
|
+
return e.replace(/\s+/g, "-");
|
|
17
|
+
case "snake_case":
|
|
18
|
+
return e.replace(/\s+/g, "_");
|
|
19
|
+
case "camelCase": {
|
|
20
|
+
const n = e.split(" ");
|
|
21
|
+
return n.length === 0 ? "" : n[0]?.toLowerCase() + n.slice(1).map(
|
|
22
|
+
(o) => o.charAt(0).toUpperCase() + o.slice(1).toLowerCase()
|
|
23
|
+
).join("");
|
|
24
|
+
}
|
|
25
|
+
case "PascalCase":
|
|
26
|
+
return e.split(" ").map(
|
|
27
|
+
(n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()
|
|
28
|
+
).join("");
|
|
29
|
+
case "dot.case":
|
|
30
|
+
return e.replace(/\s+/g, ".");
|
|
31
|
+
case "path/case":
|
|
32
|
+
return e.replace(/\s+/g, "/");
|
|
33
|
+
case "Sentence case":
|
|
34
|
+
return e.replace(/(^\s*\w|[.!?]\s*\w)/g, (n) => n.toUpperCase()).replace(/\bi\b/g, "I");
|
|
35
|
+
case "Header-Case":
|
|
36
|
+
return e.split(" ").map(
|
|
37
|
+
(n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()
|
|
38
|
+
).join("-");
|
|
39
|
+
case "reverse":
|
|
40
|
+
return e.split("").reverse().join("");
|
|
41
|
+
default:
|
|
42
|
+
throw new Error(`Unsupported case type: ${r}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function Y(t) {
|
|
46
|
+
try {
|
|
47
|
+
return [await t, null];
|
|
48
|
+
} catch (r) {
|
|
49
|
+
return [null, r];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function E(t) {
|
|
53
|
+
try {
|
|
54
|
+
return [t(), null];
|
|
55
|
+
} catch (r) {
|
|
56
|
+
return [null, r];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const F = {
|
|
60
|
+
/**
|
|
61
|
+
* Makes a GET request to the specified URL.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} url - The URL to send the GET request to.
|
|
64
|
+
* @param {RequestInit} [options] - Optional request options.
|
|
65
|
+
* @returns {Promise<any>} The response data.
|
|
66
|
+
* @throws {Error} If the response is not ok.
|
|
67
|
+
*/
|
|
68
|
+
get: async function(t, r) {
|
|
69
|
+
const e = await fetch(t, r);
|
|
70
|
+
return await S(e);
|
|
71
|
+
},
|
|
72
|
+
/**
|
|
73
|
+
* Makes a POST request to the specified URL with the given data.
|
|
74
|
+
*
|
|
75
|
+
* @template R
|
|
76
|
+
* @param {string} url - The URL to send the POST request to.
|
|
77
|
+
* @param {unknown} data - The data to send in the request body.
|
|
78
|
+
* @param {RequestInit} [options] - Optional request options.
|
|
79
|
+
* @returns {Promise<R>} The response data.
|
|
80
|
+
* @throws {Error} If the response is not ok.
|
|
81
|
+
*/
|
|
82
|
+
post: async function(t, r, e) {
|
|
83
|
+
const n = await fetch(t, {
|
|
84
|
+
method: "POST",
|
|
85
|
+
headers: {
|
|
86
|
+
"Content-Type": "application/json",
|
|
87
|
+
...e?.headers
|
|
88
|
+
},
|
|
89
|
+
body: JSON.stringify(r),
|
|
90
|
+
...e
|
|
91
|
+
});
|
|
92
|
+
return await S(n);
|
|
93
|
+
},
|
|
94
|
+
/**
|
|
95
|
+
* Makes a DELETE request to the specified URL with the given ID.
|
|
96
|
+
*
|
|
97
|
+
* @template R
|
|
98
|
+
* @param {string} url - The URL to send the DELETE request to.
|
|
99
|
+
* @param {string} id - The ID to send in the request body.
|
|
100
|
+
* @param {RequestInit} [options] - Optional request options.
|
|
101
|
+
* @returns {Promise<R>} The response data.
|
|
102
|
+
* @throws {Error} If the response is not ok.
|
|
103
|
+
*/
|
|
104
|
+
delete: async function(t, r, e) {
|
|
105
|
+
const n = await fetch(t, {
|
|
106
|
+
method: "DELETE",
|
|
107
|
+
headers: {
|
|
108
|
+
"Content-Type": "application/json",
|
|
109
|
+
...e?.headers
|
|
110
|
+
},
|
|
111
|
+
body: JSON.stringify({ id: r }),
|
|
112
|
+
...e
|
|
113
|
+
});
|
|
114
|
+
return await S(n);
|
|
115
|
+
},
|
|
116
|
+
/**
|
|
117
|
+
* Makes a PATCH request to the specified URL with the given data.
|
|
118
|
+
*
|
|
119
|
+
* @template R
|
|
120
|
+
* @param {string} url - The URL to send the PATCH request to.
|
|
121
|
+
* @param {unknown} data - The data to send in the request body.
|
|
122
|
+
* @param {RequestInit} [options] - Optional request options.
|
|
123
|
+
* @returns {Promise<R>} The response data.
|
|
124
|
+
* @throws {Error} If the response is not ok.
|
|
125
|
+
*/
|
|
126
|
+
patch: async function(t, r, e) {
|
|
127
|
+
const n = await fetch(t, {
|
|
128
|
+
method: "PATCH",
|
|
129
|
+
headers: {
|
|
130
|
+
"Content-Type": "application/json",
|
|
131
|
+
...e?.headers
|
|
132
|
+
},
|
|
133
|
+
body: JSON.stringify(r),
|
|
134
|
+
...e
|
|
135
|
+
});
|
|
136
|
+
return await S(n);
|
|
137
|
+
},
|
|
138
|
+
/**
|
|
139
|
+
* Makes a PUT request to the specified URL with the given data.
|
|
140
|
+
*
|
|
141
|
+
* @template R
|
|
142
|
+
* @param {string} url - The URL to send the PUT request to.
|
|
143
|
+
* @param {unknown} data - The data to send in the request body.
|
|
144
|
+
* @param {RequestInit} [options] - Optional request options.
|
|
145
|
+
* @returns {Promise<R>} The response data.
|
|
146
|
+
* @throws {Error} If the response is not ok.
|
|
147
|
+
*/
|
|
148
|
+
put: async function(t, r, e) {
|
|
149
|
+
const n = await fetch(t, {
|
|
150
|
+
method: "PUT",
|
|
151
|
+
headers: {
|
|
152
|
+
"Content-Type": "application/json",
|
|
153
|
+
...e?.headers
|
|
154
|
+
},
|
|
155
|
+
body: JSON.stringify(r),
|
|
156
|
+
...e
|
|
157
|
+
});
|
|
158
|
+
return await S(n);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
async function S(t) {
|
|
162
|
+
if (!t.ok) throw new Error(`Error: ${t.statusText}`);
|
|
163
|
+
return await t.json();
|
|
164
|
+
}
|
|
165
|
+
function ee(t, r) {
|
|
166
|
+
const e = {};
|
|
167
|
+
return t?.forEach((n, o) => {
|
|
168
|
+
const s = r(n, o, t)?.toString();
|
|
169
|
+
s && (e[s] ??= [], e[s].push(n));
|
|
170
|
+
}), e;
|
|
171
|
+
}
|
|
172
|
+
async function te(t) {
|
|
173
|
+
return await new Promise((r) => setTimeout(r, t));
|
|
174
|
+
}
|
|
175
|
+
function re(t, r, e) {
|
|
176
|
+
return r < t ? t : r > e ? e : r;
|
|
177
|
+
}
|
|
178
|
+
function ne(t, r) {
|
|
179
|
+
let e;
|
|
180
|
+
return (...n) => {
|
|
181
|
+
clearTimeout(e), e = setTimeout(() => t(...n), r);
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function se(t, r) {
|
|
185
|
+
if (!r || typeof r != "string" || typeof t != "object" || t === null)
|
|
186
|
+
return;
|
|
187
|
+
const e = r.split(".");
|
|
188
|
+
function n(o, s) {
|
|
189
|
+
if (!s || typeof s != "object")
|
|
190
|
+
return;
|
|
191
|
+
const a = o[0];
|
|
192
|
+
if (a in s)
|
|
193
|
+
return o.length === 1 ? s[a] : n(o.slice(1), s[a]);
|
|
194
|
+
}
|
|
195
|
+
return n(e, t);
|
|
196
|
+
}
|
|
197
|
+
class g {
|
|
198
|
+
#e = null;
|
|
199
|
+
#t = null;
|
|
200
|
+
/**
|
|
201
|
+
* Creates a successful result.
|
|
202
|
+
* @param {T} val - The success value.
|
|
203
|
+
* @returns {Result<T, never>} A Result instance representing a success.
|
|
204
|
+
*/
|
|
205
|
+
static ok(r) {
|
|
206
|
+
return new g(r, null);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Creates a failed result.
|
|
210
|
+
* @param {E | string} err - The error value or message.
|
|
211
|
+
* @returns {Result<never, E>} A Result instance representing a failure.
|
|
212
|
+
*/
|
|
213
|
+
static err(r) {
|
|
214
|
+
return typeof r == "string" ? new g(null, new Error(r)) : new g(null, r);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Wraps a promise in a Result.
|
|
218
|
+
* @param {Promise<T>} promise - The promise to wrap.
|
|
219
|
+
* @returns {Promise<Result<T, E>>} A promise that resolves to a Result.
|
|
220
|
+
*/
|
|
221
|
+
static async promise(r) {
|
|
222
|
+
return r.then((e) => g.ok(e ?? "void")).catch((e) => g.err(e));
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Wraps a function call in a Result.
|
|
226
|
+
* @param {(...args: any[]) => T} func - The function to call.
|
|
227
|
+
* @param {...any[]} args - The arguments to pass to the function.
|
|
228
|
+
* @returns {Result<T, E>} A Result instance representing the function call result.
|
|
229
|
+
*/
|
|
230
|
+
static func(r, ...e) {
|
|
231
|
+
try {
|
|
232
|
+
const n = r(...e);
|
|
233
|
+
return g.ok(n);
|
|
234
|
+
} catch (n) {
|
|
235
|
+
return g.err(n);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* @param {T | null} ok - The success value.
|
|
240
|
+
* @param {E | null} err - The error value.
|
|
241
|
+
* @throws {Error} If both ok and err are provided or neither is provided.
|
|
242
|
+
*/
|
|
243
|
+
constructor(r, e) {
|
|
244
|
+
if (!r && !e)
|
|
245
|
+
throw new Error("Result must be initialized with either an ok or an err value");
|
|
246
|
+
if (r && e)
|
|
247
|
+
throw new Error("Result can't be initialized with both an ok and an err value");
|
|
248
|
+
r != null ? this.#e = r : this.#t = e;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Gets the success value, throwing an error if the result is a failure.
|
|
252
|
+
* @returns {T} The success value.
|
|
253
|
+
* @throws {Error} If the result is a failure.
|
|
254
|
+
*/
|
|
255
|
+
get value() {
|
|
256
|
+
return this.expect("add error handling");
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Unwraps the result, returning the success value or throwing the error.
|
|
260
|
+
* @returns {T} The success value.
|
|
261
|
+
* @throws {E} If the result is a failure.
|
|
262
|
+
*/
|
|
263
|
+
unwrap() {
|
|
264
|
+
if (this.isOk())
|
|
265
|
+
return this.#e;
|
|
266
|
+
throw this.isErr() ? this.#t : new Error("Unknown error");
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Unwraps the result, returning the success value or a default value if the result is a failure.
|
|
270
|
+
* @param {T} defaultValue - The default value to return if the result is a failure.
|
|
271
|
+
* @returns {T} The success value or the default value.
|
|
272
|
+
*/
|
|
273
|
+
unwrapOr(r) {
|
|
274
|
+
return this.isOk() ? this.#e : r;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Gets the success value, throwing a custom error message if the result is a failure.
|
|
278
|
+
* @param {string} msg - The custom error message.
|
|
279
|
+
* @returns {T} The success value.
|
|
280
|
+
* @throws {Error} If the result is a failure.
|
|
281
|
+
*/
|
|
282
|
+
expect(r) {
|
|
283
|
+
if (this.isOk())
|
|
284
|
+
return this.#e;
|
|
285
|
+
if (this.isErr()) {
|
|
286
|
+
const e = this.#t;
|
|
287
|
+
throw new Error(r + `:
|
|
288
|
+
` + e.message);
|
|
289
|
+
}
|
|
290
|
+
throw new Error(r);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Checks if the result is a success.
|
|
294
|
+
* @returns {boolean} True if the result is a success, false otherwise.
|
|
295
|
+
*/
|
|
296
|
+
isOk() {
|
|
297
|
+
return this.#e != null;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Checks if the result is a failure.
|
|
301
|
+
* @returns {boolean} True if the result is a failure, false otherwise.
|
|
302
|
+
*/
|
|
303
|
+
isErr() {
|
|
304
|
+
return this.#t != null;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Gets the error value.
|
|
308
|
+
* @returns {E | null} The error value, or null if the result is a success.
|
|
309
|
+
*/
|
|
310
|
+
get error() {
|
|
311
|
+
return this.#t;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function oe(t, r = []) {
|
|
315
|
+
return t == null ? r : Array.isArray(t) ? t : [t];
|
|
316
|
+
}
|
|
317
|
+
const z = /* @__PURE__ */ Symbol("SIGNAL"), ae = (t) => typeof t == "function" && z in t, h = [], ie = (t) => {
|
|
318
|
+
const r = h.splice(0, h.length);
|
|
319
|
+
try {
|
|
320
|
+
return t();
|
|
321
|
+
} finally {
|
|
322
|
+
h.push(...r);
|
|
323
|
+
}
|
|
324
|
+
}, A = (t, r) => {
|
|
325
|
+
const e = /* @__PURE__ */ new Set();
|
|
326
|
+
let n = 0;
|
|
327
|
+
const o = () => {
|
|
328
|
+
const l = h[h.length - 1];
|
|
329
|
+
l && (e.add(l.setDirty), l.addSource(() => {
|
|
330
|
+
e.delete(l.setDirty);
|
|
331
|
+
}));
|
|
332
|
+
}, s = (l) => {
|
|
333
|
+
for (const y of Array.from(e)) y(l);
|
|
334
|
+
}, a = () => n > 0;
|
|
335
|
+
return { read: Object.assign(() => (o(), t()), {
|
|
336
|
+
[z]: !0,
|
|
337
|
+
subscribe: (l) => (e.add(l), n++, r?.(), () => {
|
|
338
|
+
e.delete(l), n--;
|
|
339
|
+
})
|
|
340
|
+
}), notify: s, hasSubscribers: a };
|
|
341
|
+
}, C = (t) => {
|
|
342
|
+
let r = t;
|
|
343
|
+
const { read: e, notify: n } = A(() => r);
|
|
344
|
+
return Object.assign(e, {
|
|
345
|
+
set: (o) => {
|
|
346
|
+
r !== o && (r = o, n(o));
|
|
347
|
+
},
|
|
348
|
+
update: (o) => {
|
|
349
|
+
const s = o(r);
|
|
350
|
+
r !== s && (r = s, n(s));
|
|
351
|
+
},
|
|
352
|
+
asReadonly: () => e
|
|
353
|
+
});
|
|
354
|
+
}, k = (t) => {
|
|
355
|
+
const r = /* @__PURE__ */ new Set();
|
|
356
|
+
let e = !1, n = null, o = !1;
|
|
357
|
+
const s = () => {
|
|
358
|
+
if (o = !1, e) return;
|
|
359
|
+
n && (n(), n = null), r.forEach((i) => i()), r.clear();
|
|
360
|
+
const a = (i) => {
|
|
361
|
+
n = i;
|
|
362
|
+
};
|
|
363
|
+
h.push({
|
|
364
|
+
setDirty: () => {
|
|
365
|
+
!e && !o && (o = !0, queueMicrotask(s));
|
|
366
|
+
},
|
|
367
|
+
addSource: (i) => r.add(i)
|
|
368
|
+
}), t(a), h.pop();
|
|
369
|
+
};
|
|
370
|
+
return s(), {
|
|
371
|
+
destroy() {
|
|
372
|
+
e = !0, n && (n(), n = null), r.forEach((a) => a()), r.clear();
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
}, L = (t) => {
|
|
376
|
+
const r = /* @__PURE__ */ new Set();
|
|
377
|
+
let e, n = !0, o = () => {
|
|
378
|
+
};
|
|
379
|
+
const s = () => {
|
|
380
|
+
r.forEach((c) => c()), r.clear(), h.push({
|
|
381
|
+
setDirty: () => {
|
|
382
|
+
if (n) return;
|
|
383
|
+
n = !0;
|
|
384
|
+
const c = e;
|
|
385
|
+
s(), e !== c && o(e);
|
|
386
|
+
},
|
|
387
|
+
addSource: (c) => r.add(c)
|
|
388
|
+
}), e = t(), n = !1, h.pop();
|
|
389
|
+
}, { read: a, notify: i } = A(
|
|
390
|
+
() => (n && s(), e),
|
|
391
|
+
() => {
|
|
392
|
+
n && s();
|
|
393
|
+
}
|
|
394
|
+
);
|
|
395
|
+
return o = i, a;
|
|
396
|
+
};
|
|
397
|
+
function ce(t) {
|
|
398
|
+
const r = typeof t == "function", e = r ? void 0 : t.source, n = r ? t : t.computation, o = /* @__PURE__ */ new Set();
|
|
399
|
+
let s, a = !0, i = !1, c, l = () => {
|
|
400
|
+
};
|
|
401
|
+
const y = () => {
|
|
402
|
+
if (o.forEach((u) => u()), o.clear(), h.push({
|
|
403
|
+
setDirty: () => {
|
|
404
|
+
if (a) return;
|
|
405
|
+
a = !0, i = !1;
|
|
406
|
+
const u = s;
|
|
407
|
+
y(), s !== u && l(s);
|
|
408
|
+
},
|
|
409
|
+
addSource: (u) => o.add(u)
|
|
410
|
+
}), r)
|
|
411
|
+
s = n();
|
|
412
|
+
else {
|
|
413
|
+
const u = e?.();
|
|
414
|
+
s = n(u, c), c = { source: u, value: s };
|
|
415
|
+
}
|
|
416
|
+
a = !1, h.pop();
|
|
417
|
+
}, { read: v, notify: d } = A(
|
|
418
|
+
() => (a && !i && y(), s),
|
|
419
|
+
() => {
|
|
420
|
+
a && !i && y();
|
|
421
|
+
}
|
|
422
|
+
);
|
|
423
|
+
l = d;
|
|
424
|
+
const b = Object.assign(v, {
|
|
425
|
+
set: (u) => {
|
|
426
|
+
s !== u && (s = u, i = !0, a = !1, d(u));
|
|
427
|
+
},
|
|
428
|
+
update: (u) => {
|
|
429
|
+
a && !i && y(), b.set(u(s));
|
|
430
|
+
},
|
|
431
|
+
asReadonly: () => v
|
|
432
|
+
});
|
|
433
|
+
return b;
|
|
434
|
+
}
|
|
435
|
+
class G extends Error {
|
|
436
|
+
constructor(r) {
|
|
437
|
+
const e = r instanceof Error ? `:
|
|
438
|
+
${r.message}` : "";
|
|
439
|
+
super(`Cannot read resource value while in error state${e}`, { cause: r }), this.name = "ResourceErrorState";
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
function le(t) {
|
|
443
|
+
const r = C(void 0), e = C("idle"), n = C(void 0), o = L(() => e() === "loading"), s = C(0), a = L(() => {
|
|
444
|
+
if (e() === "error")
|
|
445
|
+
throw new G(n());
|
|
446
|
+
return r();
|
|
447
|
+
}), i = (d) => {
|
|
448
|
+
r.set(d), n.set(void 0), e.set("resolved");
|
|
449
|
+
}, c = (d) => {
|
|
450
|
+
r.update(d), n.set(void 0), e.set("resolved");
|
|
451
|
+
}, l = "params" in t;
|
|
452
|
+
if ("stream" in t) {
|
|
453
|
+
const d = C(void 0), b = k((p) => {
|
|
454
|
+
s();
|
|
455
|
+
const f = new AbortController();
|
|
456
|
+
p(() => f.abort());
|
|
457
|
+
const I = l ? t.params() : void 0;
|
|
458
|
+
e.set("loading"), n.set(void 0);
|
|
459
|
+
const N = t.stream, _ = N(l ? {
|
|
460
|
+
params: I,
|
|
461
|
+
abortSignal: f.signal
|
|
462
|
+
} : {
|
|
463
|
+
abortSignal: f.signal
|
|
464
|
+
});
|
|
465
|
+
d.set(_);
|
|
466
|
+
}), u = k(() => {
|
|
467
|
+
const p = d();
|
|
468
|
+
if (!p) return;
|
|
469
|
+
const f = p();
|
|
470
|
+
f && ("error" in f && f.error !== void 0 ? (n.set(f.error), e.set("error")) : "value" in f && (r.set(f.value), e.set("resolved")));
|
|
471
|
+
});
|
|
472
|
+
return {
|
|
473
|
+
value: a,
|
|
474
|
+
status: e,
|
|
475
|
+
error: n,
|
|
476
|
+
isLoading: o,
|
|
477
|
+
set: i,
|
|
478
|
+
update: c,
|
|
479
|
+
reload: () => {
|
|
480
|
+
s.update((p) => p + 1);
|
|
481
|
+
},
|
|
482
|
+
destroy: () => {
|
|
483
|
+
b.destroy(), u.destroy();
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
const v = k((d) => {
|
|
488
|
+
s();
|
|
489
|
+
const b = l ? t.params() : void 0;
|
|
490
|
+
e.set("loading"), n.set(void 0);
|
|
491
|
+
const u = new AbortController();
|
|
492
|
+
d(() => u.abort());
|
|
493
|
+
const p = l ? { params: b, abortSignal: u.signal } : { abortSignal: u.signal };
|
|
494
|
+
t.loader(p).then(
|
|
495
|
+
(f) => {
|
|
496
|
+
u.signal.aborted || (r.set(f), e.set("resolved"));
|
|
497
|
+
},
|
|
498
|
+
(f) => {
|
|
499
|
+
u.signal.aborted || (n.set(f), e.set("error"));
|
|
500
|
+
}
|
|
501
|
+
);
|
|
502
|
+
});
|
|
503
|
+
return {
|
|
504
|
+
value: a,
|
|
505
|
+
status: e,
|
|
506
|
+
error: n,
|
|
507
|
+
isLoading: o,
|
|
508
|
+
set: i,
|
|
509
|
+
update: c,
|
|
510
|
+
reload: () => {
|
|
511
|
+
s.update((d) => d + 1);
|
|
512
|
+
},
|
|
513
|
+
destroy: () => v.destroy()
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
const $ = /* @__PURE__ */ new Map([
|
|
517
|
+
["b", "b"],
|
|
518
|
+
["i", "i"],
|
|
519
|
+
["u", "u"],
|
|
520
|
+
["s", "s"],
|
|
521
|
+
["mark", "mark"],
|
|
522
|
+
["small", "small"],
|
|
523
|
+
["strong", "b"],
|
|
524
|
+
["em", "i"],
|
|
525
|
+
["sup", "sup"],
|
|
526
|
+
["sub", "sub"],
|
|
527
|
+
["h1", "h1"],
|
|
528
|
+
["h2", "h2"],
|
|
529
|
+
["h3", "h3"],
|
|
530
|
+
["h4", "h4"],
|
|
531
|
+
["h5", "h5"],
|
|
532
|
+
["h6", "h6"],
|
|
533
|
+
["code", "code"],
|
|
534
|
+
["p", "p"],
|
|
535
|
+
["div", "div"],
|
|
536
|
+
["ul", "ul"],
|
|
537
|
+
["ol", "ol"],
|
|
538
|
+
["li", "li"]
|
|
539
|
+
]), T = /* @__PURE__ */ new Set([
|
|
540
|
+
"div",
|
|
541
|
+
"p",
|
|
542
|
+
"ul",
|
|
543
|
+
"ol",
|
|
544
|
+
"li",
|
|
545
|
+
"h1",
|
|
546
|
+
"h2",
|
|
547
|
+
"h3",
|
|
548
|
+
"h4",
|
|
549
|
+
"h5",
|
|
550
|
+
"h6"
|
|
551
|
+
]);
|
|
552
|
+
let O = "rtp-";
|
|
553
|
+
function x() {
|
|
554
|
+
return O;
|
|
555
|
+
}
|
|
556
|
+
function V(t) {
|
|
557
|
+
O = t;
|
|
558
|
+
}
|
|
559
|
+
const j = /* @__PURE__ */ new Map([
|
|
560
|
+
["br", "br"],
|
|
561
|
+
["hr", "hr"]
|
|
562
|
+
]), w = /* @__PURE__ */ new Map([
|
|
563
|
+
["b", /* @__PURE__ */ new Map([["font-weight", "bold"]])],
|
|
564
|
+
["i", /* @__PURE__ */ new Map([["font-style", "italic"]])],
|
|
565
|
+
["u", /* @__PURE__ */ new Map([["text-decoration", "underline"]])],
|
|
566
|
+
["s", /* @__PURE__ */ new Map([["text-decoration", "line-through"]])],
|
|
567
|
+
["mark", /* @__PURE__ */ new Map([["background-color", "yellow"]])],
|
|
568
|
+
["small", /* @__PURE__ */ new Map([["font-size", "smaller"]])],
|
|
569
|
+
["strong", /* @__PURE__ */ new Map([["font-weight", "bold"]])],
|
|
570
|
+
["em", /* @__PURE__ */ new Map([["font-style", "italic"]])],
|
|
571
|
+
[
|
|
572
|
+
"sub",
|
|
573
|
+
/* @__PURE__ */ new Map([
|
|
574
|
+
["vertical-align", "sub"],
|
|
575
|
+
["font-size", "smaller"]
|
|
576
|
+
])
|
|
577
|
+
],
|
|
578
|
+
[
|
|
579
|
+
"sup",
|
|
580
|
+
/* @__PURE__ */ new Map([
|
|
581
|
+
["vertical-align", "super"],
|
|
582
|
+
["font-size", "smaller"]
|
|
583
|
+
])
|
|
584
|
+
],
|
|
585
|
+
[
|
|
586
|
+
"h1",
|
|
587
|
+
/* @__PURE__ */ new Map([
|
|
588
|
+
["font-size", "2em"],
|
|
589
|
+
["font-weight", "bold"]
|
|
590
|
+
])
|
|
591
|
+
],
|
|
592
|
+
[
|
|
593
|
+
"h2",
|
|
594
|
+
/* @__PURE__ */ new Map([
|
|
595
|
+
["font-size", "1.5em"],
|
|
596
|
+
["font-weight", "bold"]
|
|
597
|
+
])
|
|
598
|
+
],
|
|
599
|
+
[
|
|
600
|
+
"h3",
|
|
601
|
+
/* @__PURE__ */ new Map([
|
|
602
|
+
["font-size", "1.17em"],
|
|
603
|
+
["font-weight", "bold"]
|
|
604
|
+
])
|
|
605
|
+
],
|
|
606
|
+
[
|
|
607
|
+
"h4",
|
|
608
|
+
/* @__PURE__ */ new Map([
|
|
609
|
+
["font-size", "1em"],
|
|
610
|
+
["font-weight", "bold"]
|
|
611
|
+
])
|
|
612
|
+
],
|
|
613
|
+
[
|
|
614
|
+
"h5",
|
|
615
|
+
/* @__PURE__ */ new Map([
|
|
616
|
+
["font-size", "0.83em"],
|
|
617
|
+
["font-weight", "bold"]
|
|
618
|
+
])
|
|
619
|
+
],
|
|
620
|
+
[
|
|
621
|
+
"h6",
|
|
622
|
+
/* @__PURE__ */ new Map([
|
|
623
|
+
["font-size", "0.67em"],
|
|
624
|
+
["font-weight", "bold"]
|
|
625
|
+
])
|
|
626
|
+
],
|
|
627
|
+
["code", /* @__PURE__ */ new Map([["font-family", "monospace"]])],
|
|
628
|
+
["p", /* @__PURE__ */ new Map([["margin-block", "1em"]])],
|
|
629
|
+
["div", /* @__PURE__ */ new Map([["display", "block"]])],
|
|
630
|
+
["ul", /* @__PURE__ */ new Map([["padding-left", "1.5em"]])],
|
|
631
|
+
["ol", /* @__PURE__ */ new Map([["padding-left", "1.5em"]])],
|
|
632
|
+
["li", /* @__PURE__ */ new Map([["margin-block", "0.5em"]])],
|
|
633
|
+
[
|
|
634
|
+
"br",
|
|
635
|
+
/* @__PURE__ */ new Map([
|
|
636
|
+
["display", "block"],
|
|
637
|
+
["height", "1em"]
|
|
638
|
+
])
|
|
639
|
+
],
|
|
640
|
+
[
|
|
641
|
+
"hr",
|
|
642
|
+
/* @__PURE__ */ new Map([
|
|
643
|
+
["display", "block"],
|
|
644
|
+
["border", "0"],
|
|
645
|
+
["border-top", "1px solid #ccc"],
|
|
646
|
+
["border-color", "green"],
|
|
647
|
+
["margin", "1em 0"]
|
|
648
|
+
])
|
|
649
|
+
]
|
|
650
|
+
]), M = (t, r, e, n, o) => {
|
|
651
|
+
const s = t.filter((i) => !T.has(i)), a = t.filter((i) => T.has(i));
|
|
652
|
+
return {
|
|
653
|
+
tagNames: t.join(","),
|
|
654
|
+
tagNamesList: t,
|
|
655
|
+
text: o ?? r.slice(e, n),
|
|
656
|
+
style: s.map(
|
|
657
|
+
(i) => [...w.get(i)?.entries() ?? []].map(([c, l]) => `${c}: ${l}`).join("; ")
|
|
658
|
+
).filter(Boolean).join("; "),
|
|
659
|
+
styleObject: Object.fromEntries(
|
|
660
|
+
s.flatMap((i) => Array.from(w.get(i) ?? []))
|
|
661
|
+
),
|
|
662
|
+
containerTagNames: a,
|
|
663
|
+
cssClass: s.map((i) => `${x()}${i}`).join(" ")
|
|
664
|
+
};
|
|
665
|
+
}, J = () => [...$.keys()].join("|"), H = () => [...j.keys()].join("|"), Z = () => new RegExp(
|
|
666
|
+
`<\\/?(${J()})>|<(${H()})\\s*/?>`,
|
|
667
|
+
"gi"
|
|
668
|
+
);
|
|
669
|
+
function P(t, r) {
|
|
670
|
+
const e = w.get(t) ?? /* @__PURE__ */ new Map();
|
|
671
|
+
Object.entries(r).forEach(([n, o]) => e.set(n, o)), w.set(t, e);
|
|
672
|
+
}
|
|
673
|
+
function B() {
|
|
674
|
+
const t = [];
|
|
675
|
+
for (const [r, e] of w) {
|
|
676
|
+
if (e.size === 0) continue;
|
|
677
|
+
const n = [...e.entries()].map(([o, s]) => ` ${o}: ${s};`).join(`
|
|
678
|
+
`);
|
|
679
|
+
t.push(`.${x()}${r} {
|
|
680
|
+
${n}
|
|
681
|
+
}`);
|
|
682
|
+
}
|
|
683
|
+
return t.join(`
|
|
684
|
+
`);
|
|
685
|
+
}
|
|
686
|
+
function q() {
|
|
687
|
+
if ("document" in globalThis) {
|
|
688
|
+
const t = B(), r = globalThis, e = r.document.getElementById(
|
|
689
|
+
"html-text-parser-styles"
|
|
690
|
+
);
|
|
691
|
+
if (e) {
|
|
692
|
+
e.textContent = t;
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
const n = r.document.createElement("style");
|
|
696
|
+
n.textContent = t, n.setAttribute("id", "html-text-parser-styles"), r.document.head.appendChild(n);
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
console.warn(
|
|
700
|
+
"[html-text-parser] Cannot inject stylesheet: document is not available."
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
function X(t) {
|
|
704
|
+
const r = [];
|
|
705
|
+
let e;
|
|
706
|
+
for (const n of t) {
|
|
707
|
+
const o = n.containerTagNames.join(","), s = e?.containerTagNames.join(",");
|
|
708
|
+
o !== s && (e = {
|
|
709
|
+
containerTagNames: n.containerTagNames,
|
|
710
|
+
cssClass: n.containerTagNames.map((a) => `${x()}${a}`).join(" "),
|
|
711
|
+
style: n.containerTagNames.map(
|
|
712
|
+
(a) => [...w.get(a)?.entries() ?? []].map(([i, c]) => `${i}: ${c}`).join("; ")
|
|
713
|
+
).filter(Boolean).join("; "),
|
|
714
|
+
styleObject: Object.fromEntries(
|
|
715
|
+
n.containerTagNames.flatMap(
|
|
716
|
+
(a) => Array.from(w.get(a) ?? [])
|
|
717
|
+
)
|
|
718
|
+
),
|
|
719
|
+
segments: []
|
|
720
|
+
}, r.push(e)), e.segments.push(n);
|
|
721
|
+
}
|
|
722
|
+
return r;
|
|
723
|
+
}
|
|
724
|
+
function m(t) {
|
|
725
|
+
const r = [], e = /* @__PURE__ */ new Map();
|
|
726
|
+
let n = 0;
|
|
727
|
+
for (const o of t.matchAll(Z())) {
|
|
728
|
+
const s = o.index;
|
|
729
|
+
s > n && r.push(
|
|
730
|
+
M([...e.keys()], t, n, s)
|
|
731
|
+
);
|
|
732
|
+
const a = o[2]?.toLowerCase();
|
|
733
|
+
if (a && j.has(a)) {
|
|
734
|
+
r.push(
|
|
735
|
+
M(
|
|
736
|
+
[...e.keys(), a],
|
|
737
|
+
t,
|
|
738
|
+
n,
|
|
739
|
+
s,
|
|
740
|
+
""
|
|
741
|
+
)
|
|
742
|
+
), n = s + o[0].length;
|
|
743
|
+
continue;
|
|
744
|
+
}
|
|
745
|
+
const i = o[0][1] === "/", c = $.get(o[1]?.toLowerCase() ?? "") ?? "";
|
|
746
|
+
if (i) {
|
|
747
|
+
const l = (e.get(c) ?? 1) - 1;
|
|
748
|
+
l <= 0 ? e.delete(c) : e.set(c, l);
|
|
749
|
+
} else
|
|
750
|
+
e.set(c, (e.get(c) ?? 0) + 1);
|
|
751
|
+
n = s + o[0].length;
|
|
752
|
+
}
|
|
753
|
+
return n < t.length && r.push(
|
|
754
|
+
M(
|
|
755
|
+
[...e.keys()],
|
|
756
|
+
t,
|
|
757
|
+
n,
|
|
758
|
+
t.length
|
|
759
|
+
)
|
|
760
|
+
), r;
|
|
761
|
+
}
|
|
762
|
+
function R(t) {
|
|
763
|
+
if (Array.isArray(t)) {
|
|
764
|
+
t.forEach((e) => {
|
|
765
|
+
R(e);
|
|
766
|
+
});
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
const r = t.tagName ?? t.tag;
|
|
770
|
+
$.set(t.tag, r), t.style != null && Object.keys(t.style).length && P(r, t.style);
|
|
771
|
+
}
|
|
772
|
+
function U(t) {
|
|
773
|
+
if (Array.isArray(t)) {
|
|
774
|
+
t.forEach((e) => {
|
|
775
|
+
U(e);
|
|
776
|
+
});
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
const r = t.tagName ?? t.tag;
|
|
780
|
+
j.set(t.tag, r), t.style != null && Object.keys(t.style).length && P(r, t.style);
|
|
781
|
+
}
|
|
782
|
+
m.setTag = R;
|
|
783
|
+
m.setSelfClosingTag = U;
|
|
784
|
+
m.setBlockTag = (t) => T.add(t);
|
|
785
|
+
m.removeBlockTag = (t) => T.delete(t);
|
|
786
|
+
m.setCssClassPrefix = V;
|
|
787
|
+
"document" in globalThis && (m.generateStylesheet = q);
|
|
788
|
+
m.getStylesheet = B;
|
|
789
|
+
m.groupByBlocks = X;
|
|
790
|
+
function K(t, r, e) {
|
|
791
|
+
function n(o) {
|
|
792
|
+
const [s, a] = E(() => e ? e(o) : o);
|
|
793
|
+
if (a) throw new Error(`Error transforming value for ${t}: ${a.message}`);
|
|
794
|
+
if (!r(s)) throw new Error(`"${o}" is not a valid ${t}`);
|
|
795
|
+
return s;
|
|
796
|
+
}
|
|
797
|
+
return n.from = (o) => {
|
|
798
|
+
const [s, a] = E(() => e ? e(o) : o);
|
|
799
|
+
if (!a)
|
|
800
|
+
return r(s) ? s : void 0;
|
|
801
|
+
}, n.is = (o) => {
|
|
802
|
+
const s = E(() => e ? e(o) : o)[0] ?? o;
|
|
803
|
+
return r(s);
|
|
804
|
+
}, n;
|
|
805
|
+
}
|
|
806
|
+
const Q = /^\d+$/, ue = K(
|
|
807
|
+
"NumericString",
|
|
808
|
+
(t) => Q.test(String(t)),
|
|
809
|
+
(t) => String(t)
|
|
810
|
+
);
|
|
811
|
+
export {
|
|
812
|
+
ue as NumericString,
|
|
813
|
+
g as Result,
|
|
814
|
+
z as SIGNAL,
|
|
815
|
+
re as clamp,
|
|
816
|
+
L as computed,
|
|
817
|
+
W as convertCase,
|
|
818
|
+
K as createBrand,
|
|
819
|
+
ne as debounce,
|
|
820
|
+
te as delay,
|
|
821
|
+
k as effect,
|
|
822
|
+
se as getProp,
|
|
823
|
+
ee as groupBy,
|
|
824
|
+
F as http,
|
|
825
|
+
ae as isSignal,
|
|
826
|
+
ce as linkedSignal,
|
|
827
|
+
D as normalizeString,
|
|
828
|
+
m as parseRichText,
|
|
829
|
+
le as resource,
|
|
830
|
+
R as setRichTextTag,
|
|
831
|
+
U as setSelfClosingTag,
|
|
832
|
+
C as signal,
|
|
833
|
+
oe as toArray,
|
|
834
|
+
E as tryCatch,
|
|
835
|
+
Y as tryCatchAsync,
|
|
836
|
+
ie as untracked
|
|
837
|
+
};
|