@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/index.js CHANGED
@@ -1,62 +1,130 @@
1
- function I(e) {
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 re(e, n) {
5
- const t = I(e);
6
- switch (n) {
4
+ function ue(e, t) {
5
+ const r = V(e);
6
+ switch (t) {
7
7
  case "lowercase":
8
- return t.toLowerCase();
8
+ return r.toLowerCase();
9
9
  case "UPPERCASE":
10
- return t.toUpperCase();
10
+ return r.toUpperCase();
11
11
  case "Title Case":
12
- return t.split(" ").map(
13
- (r) => r.charAt(0).toUpperCase() + r.slice(1).toLowerCase()
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 t.replace(/\s+/g, "-");
16
+ return r.replace(/\s+/g, "-");
17
17
  case "snake_case":
18
- return t.replace(/\s+/g, "_");
18
+ return r.replace(/\s+/g, "_");
19
19
  case "camelCase": {
20
- const r = t.split(" ");
21
- return r.length === 0 ? "" : r[0]?.toLowerCase() + r.slice(1).map(
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 t.split(" ").map(
27
- (r) => r.charAt(0).toUpperCase() + r.slice(1).toLowerCase()
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 t.replace(/\s+/g, ".");
30
+ return r.replace(/\s+/g, ".");
31
31
  case "path/case":
32
- return t.replace(/\s+/g, "/");
32
+ return r.replace(/\s+/g, "/");
33
33
  case "Sentence case":
34
- return t.replace(/(^\s*\w|[.!?]\s*\w)/g, (r) => r.toUpperCase()).replace(/\bi\b/g, "I");
34
+ return r.replace(/(^\s*\w|[.!?]\s*\w)/g, (n) => n.toUpperCase()).replace(/\bi\b/g, "I");
35
35
  case "Header-Case":
36
- return t.split(" ").map(
37
- (r) => r.charAt(0).toUpperCase() + r.slice(1).toLowerCase()
36
+ return r.split(" ").map(
37
+ (n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()
38
38
  ).join("-");
39
39
  case "reverse":
40
- return t.split("").reverse().join("");
40
+ return r.split("").reverse().join("");
41
41
  default:
42
- throw new Error(`Unsupported case type: ${n}`);
42
+ throw new Error(`Unsupported case type: ${t}`);
43
43
  }
44
44
  }
45
- async function se(e) {
45
+ async function de(e) {
46
46
  try {
47
47
  return [await (typeof e == "function" ? e() : e), null];
48
- } catch (n) {
49
- return [null, n];
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 (n) {
56
- return [null, n];
55
+ } catch (t) {
56
+ return [null, t];
57
57
  }
58
58
  }
59
- const oe = {
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, n) {
69
- return await C(() => fetch(e, n), n);
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, n, t) {
82
- return await C(
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
- ...t?.headers
158
+ ...r?.headers
88
159
  },
89
- body: JSON.stringify(n),
90
- ...t
160
+ body: JSON.stringify(t),
161
+ ...r
91
162
  }),
92
- t
163
+ r
93
164
  );
94
165
  },
95
166
  /**
96
- * Makes a DELETE request to the specified URL with the given ID.
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, n, t) {
106
- return await C(
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, n, t) {
130
- return await C(
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
- ...t?.headers
204
+ ...r?.headers
136
205
  },
137
- body: JSON.stringify(n),
138
- ...t
206
+ body: JSON.stringify(t),
207
+ ...r
139
208
  }),
140
- t
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, n, t) {
154
- return await C(
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
- ...t?.headers
228
+ ...r?.headers
160
229
  },
161
- body: JSON.stringify(n),
162
- ...t
230
+ body: JSON.stringify(t),
231
+ ...r
163
232
  }),
164
- t
233
+ r
165
234
  );
166
235
  }
167
236
  };
168
- async function C(e, n) {
237
+ async function w(e, t) {
169
238
  try {
170
- const t = await e();
171
- if (!t.ok) {
172
- const r = await t.text().catch(() => "");
173
- throw Object.assign(
174
- new Error(`HTTP ${t.status} ${t.statusText}`),
175
- {
176
- status: t.status,
177
- statusText: t.statusText,
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 n?.parse === "JSON" ? await t.json() : n?.parse === "TEXT" ? await t.text() : n?.parse === "BLOB" ? await t.blob() : n?.parse === "ARRAYBUFFER" ? await t.arrayBuffer() : await t.json();
183
- } catch (t) {
184
- throw H(t) ? t : Object.assign(
185
- new Error(
186
- t instanceof Error ? t.message : "Network request failed"
187
- ),
188
- {
189
- status: G(t),
190
- statusText: "NETWORK_ERROR",
191
- code: V(t),
192
- isNetworkError: !0,
193
- cause: t
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 G(e) {
199
- if (typeof e == "object" && e !== null && "status" in e && typeof e.status == "number")
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 V(e) {
203
- if (typeof e == "object" && e !== null && "code" in e && typeof e.code == "string")
204
- return e.code;
205
- if (typeof e == "object" && e !== null && "cause" in e && typeof e.cause == "object" && e.cause !== null && "code" in e.cause && typeof e.cause.code == "string")
206
- return e.cause.code;
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 H(e) {
209
- return typeof e == "object" && e !== null && "status" in e && typeof e.status == "number";
289
+ async function ge(e) {
290
+ return await new Promise((t) => setTimeout(t, e));
210
291
  }
211
- function ae(e, n) {
212
- const t = {};
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
- async function ie(e) {
219
- return await new Promise((n) => setTimeout(n, e));
220
- }
221
- function ce(e, n, t) {
222
- return n < e ? e : n > t ? t : n;
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(r), t?.isLoadingFn?.(!1);
303
+ clearTimeout(n), r?.isLoadingFn?.(!1);
233
304
  }
234
305
  });
235
306
  }
236
- function J(e, n) {
237
- if (!n || typeof n != "string" || typeof e != "object" || e === null)
307
+ function Z(e, t) {
308
+ if (!t || typeof t != "string" || typeof e != "object" || e === null)
238
309
  return;
239
- const t = n.split(".");
240
- function r(o, s) {
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] : r(o.slice(1), s[a]);
316
+ return o.length === 1 ? s[a] : n(o.slice(1), s[a]);
246
317
  }
247
- return r(t, e);
318
+ return n(r, e);
248
319
  }
249
- function Z(e, n, t) {
250
- let r = e;
251
- for (let o = 0; o < n.length; o++) {
252
- const s = n[o] ?? "";
253
- o === n.length - 1 ? r[s] = t : ((!r[s] || typeof r[s] != "object") && (r[s] = {}), r = r[s]);
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 ue(e, n) {
257
- const t = {};
327
+ function ye(e, t) {
328
+ const r = {};
258
329
  if (!e || typeof e != "object")
259
- return t;
260
- for (const r of n) {
261
- const o = J(e, r);
330
+ return r;
331
+ for (const n of t) {
332
+ const o = Z(e, n);
262
333
  if (o !== void 0) {
263
- const s = r.split(".");
264
- Z(t, s, o);
334
+ const s = n.split(".");
335
+ K(r, s, o);
265
336
  }
266
337
  }
267
- return t;
338
+ return r;
268
339
  }
269
- class y {
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(n) {
278
- return new y(n, null);
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(n) {
286
- return typeof n == "string" ? new y(null, new Error(n)) : new y(null, n);
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(n) {
294
- return n.then((t) => y.ok(t)).catch((t) => y.err(t));
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(n, ...t) {
373
+ static func(t, ...r) {
303
374
  try {
304
- const r = n(...t);
305
- return y.ok(r);
306
- } catch (r) {
307
- return y.err(r);
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(n, t) {
316
- if (n == null && t == null)
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 (n != null && t != null)
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
- n != null ? this.#e = n : this.#t = t;
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(n) {
350
- return this.isOk() ? this.#e : n;
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(n) {
429
+ expect(t) {
359
430
  if (this.isOk())
360
431
  return this.#e;
361
432
  if (this.isErr()) {
362
- const t = this.#t;
363
- throw new Error(n + `:
364
- ` + t.message);
433
+ const r = this.#t;
434
+ throw new Error(t + `:
435
+ ` + r.message);
365
436
  }
366
- throw new Error(n);
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 fe(e, n = []) {
391
- return e == null ? n : Array.isArray(e) ? e : [e];
461
+ function be(e, t = []) {
462
+ return e == null ? t : Array.isArray(e) ? e : [e];
392
463
  }
393
- const O = /* @__PURE__ */ Symbol("SIGNAL"), de = (e) => typeof e == "function" && O in e, p = [], pe = (e) => {
394
- const n = p.splice(0, p.length);
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
- p.push(...n);
469
+ g.push(...t);
399
470
  }
400
- }, j = (e, n) => {
401
- const t = /* @__PURE__ */ new Set();
402
- let r = 0;
471
+ }, R = (e, t) => {
472
+ const r = /* @__PURE__ */ new Set();
473
+ let n = 0;
403
474
  const o = () => {
404
- const l = p[p.length - 1];
405
- l && (t.add(l.setDirty), l.addSource(() => {
406
- t.delete(l.setDirty);
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 m of Array.from(t)) m(l);
410
- }, a = () => r > 0;
480
+ for (const h of Array.from(r)) h(l);
481
+ }, a = () => n > 0;
411
482
  return { read: Object.assign(() => (o(), e()), {
412
- [O]: !0,
413
- subscribe: (l) => (t.add(l), r++, n?.(), () => {
414
- t.delete(l), r--;
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 n = e;
419
- const { read: t, notify: r } = j(() => n);
420
- return Object.assign(t, {
489
+ let t = e;
490
+ const { read: r, notify: n } = R(() => t);
491
+ return Object.assign(r, {
421
492
  set: (o) => {
422
- n !== o && (n = o, r(o));
493
+ t !== o && (t = o, n(o));
423
494
  },
424
495
  update: (o) => {
425
- const s = o(n);
426
- n !== s && (n = s, r(s));
496
+ const s = o(t);
497
+ t !== s && (t = s, n(s));
427
498
  },
428
- asReadonly: () => t
499
+ asReadonly: () => r
429
500
  });
430
501
  }, k = (e) => {
431
- const n = /* @__PURE__ */ new Set();
432
- let t = !1, r = null, o = !1;
502
+ const t = /* @__PURE__ */ new Set();
503
+ let r = !1, n = null, o = !1;
433
504
  const s = () => {
434
- if (o = !1, t) return;
435
- r && (r(), r = null), n.forEach((i) => i()), n.clear();
505
+ if (o = !1, r) return;
506
+ n && (n(), n = null), t.forEach((i) => i()), t.clear();
436
507
  const a = (i) => {
437
- r = i;
508
+ n = i;
438
509
  };
439
- p.push({
510
+ g.push({
440
511
  setDirty: () => {
441
- !t && !o && (o = !0, queueMicrotask(s));
512
+ !r && !o && (o = !0, queueMicrotask(s));
442
513
  },
443
- addSource: (i) => n.add(i)
444
- }), e(a), p.pop();
514
+ addSource: (i) => t.add(i)
515
+ }), e(a), g.pop();
445
516
  };
446
517
  return s(), {
447
518
  destroy() {
448
- t = !0, r && (r(), r = null), n.forEach((a) => a()), n.clear();
519
+ r = !0, n && (n(), n = null), t.forEach((a) => a()), t.clear();
449
520
  }
450
521
  };
451
- }, L = (e) => {
452
- const n = /* @__PURE__ */ new Set();
453
- let t, r = !0, o = () => {
522
+ }, j = (e) => {
523
+ const t = /* @__PURE__ */ new Set();
524
+ let r, n = !0, o = () => {
454
525
  };
455
526
  const s = () => {
456
- n.forEach((c) => c()), n.clear(), p.push({
527
+ t.forEach((c) => c()), t.clear(), g.push({
457
528
  setDirty: () => {
458
- if (r) return;
459
- r = !0;
460
- const c = t;
461
- s(), t !== c && o(t);
529
+ if (n) return;
530
+ n = !0;
531
+ const c = r;
532
+ s(), r !== c && o(r);
462
533
  },
463
- addSource: (c) => n.add(c)
464
- }), t = e(), r = !1, p.pop();
465
- }, { read: a, notify: i } = j(
466
- () => (r && s(), t),
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
- r && s();
539
+ n && s();
469
540
  }
470
541
  );
471
542
  return o = i, a;
472
543
  };
473
- function he(e) {
474
- const n = typeof e == "function", t = n ? void 0 : e.source, r = n ? e : e.computation, o = /* @__PURE__ */ new Set();
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 m = () => {
478
- if (o.forEach((u) => u()), o.clear(), p.push({
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
- m(), s !== u && l(s);
554
+ h(), s !== u && l(s);
484
555
  },
485
556
  addSource: (u) => o.add(u)
486
- }), n)
487
- s = r();
557
+ }), t)
558
+ s = n();
488
559
  else {
489
- const u = t?.();
490
- s = r(u, c), c = { source: u, value: s };
560
+ const u = r?.();
561
+ s = n(u, c), c = { source: u, value: s };
491
562
  }
492
- a = !1, p.pop();
493
- }, { read: T, notify: d } = j(
494
- () => (a && !i && m(), s),
563
+ a = !1, g.pop();
564
+ }, { read: v, notify: f } = R(
565
+ () => (a && !i && h(), s),
495
566
  () => {
496
- a && !i && m();
567
+ a && !i && h();
497
568
  }
498
569
  );
499
- l = d;
500
- const b = Object.assign(T, {
570
+ l = f;
571
+ const y = Object.assign(v, {
501
572
  set: (u) => {
502
- s !== u && (s = u, i = !0, a = !1, d(u));
573
+ s !== u && (s = u, i = !0, a = !1, f(u));
503
574
  },
504
575
  update: (u) => {
505
- a && !i && m(), b.set(u(s));
576
+ a && !i && h(), y.set(u(s));
506
577
  },
507
- asReadonly: () => T
578
+ asReadonly: () => v
508
579
  });
509
- return b;
510
- }
511
- class q extends Error {
512
- constructor(n) {
513
- const t = n instanceof Error ? `:
514
- ${n.message}` : "";
515
- super(`Cannot read resource value while in error state${t}`, { cause: n }), this.name = "ResourceErrorState";
516
- }
517
- }
518
- function ge(e) {
519
- const n = S(void 0), t = S("idle"), r = S(void 0), o = L(() => t() === "loading"), s = S(0), a = L(() => {
520
- if (t() === "error")
521
- throw new q(r());
522
- return n();
523
- }), i = (d) => {
524
- n.set(d), r.set(void 0), t.set("resolved");
525
- }, c = (d) => {
526
- n.update(d), r.set(void 0), t.set("resolved");
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 d = S(void 0), b = k((g) => {
600
+ const f = S(void 0), y = k((p) => {
530
601
  s();
531
- const f = new AbortController();
532
- g(() => f.abort());
533
- const _ = l ? e.params() : void 0;
534
- t.set("loading"), r.set(void 0);
535
- const $ = e.stream, F = $(l ? {
536
- params: _,
537
- abortSignal: f.signal
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: f.signal
610
+ abortSignal: d.signal
540
611
  });
541
- d.set(F);
612
+ f.set(G);
542
613
  }), u = k(() => {
543
- const g = d();
544
- if (!g) return;
545
- const f = g();
546
- f && ("error" in f && f.error !== void 0 ? (r.set(f.error), t.set("error")) : "value" in f && (n.set(f.value), t.set("resolved")));
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: t,
551
- error: r,
621
+ status: r,
622
+ error: n,
552
623
  isLoading: o,
553
624
  set: i,
554
625
  update: c,
555
626
  reload: () => {
556
- s.update((g) => g + 1);
627
+ s.update((p) => p + 1);
557
628
  },
558
629
  destroy: () => {
559
- b.destroy(), u.destroy();
630
+ y.destroy(), u.destroy();
560
631
  }
561
632
  };
562
633
  }
563
- const T = k((d) => {
634
+ const v = k((f) => {
564
635
  s();
565
- const b = l ? e.params() : void 0;
566
- t.set("loading"), r.set(void 0);
636
+ const y = l ? e.params() : void 0;
637
+ r.set("loading"), n.set(void 0);
567
638
  const u = new AbortController();
568
- d(() => u.abort());
569
- const g = l ? { params: b, abortSignal: u.signal } : { abortSignal: u.signal };
570
- e.loader(g).then(
571
- (f) => {
572
- u.signal.aborted || (n.set(f), t.set("resolved"));
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
- (f) => {
575
- u.signal.aborted || (r.set(f), t.set("error"));
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: t,
582
- error: r,
652
+ status: r,
653
+ error: n,
583
654
  isLoading: o,
584
655
  set: i,
585
656
  update: c,
586
657
  reload: () => {
587
- s.update((d) => d + 1);
658
+ s.update((f) => f + 1);
588
659
  },
589
- destroy: () => T.destroy()
660
+ destroy: () => v.destroy()
590
661
  };
591
662
  }
592
- const A = /* @__PURE__ */ new Map([
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
- ]), v = /* @__PURE__ */ new Set([
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 R = "rtp-";
630
- function M() {
631
- return R;
700
+ let x = "rtp-";
701
+ function C() {
702
+ return x;
632
703
  }
633
- function X(e) {
634
- R = e;
704
+ function Y(e) {
705
+ x = e;
635
706
  }
636
- const N = /* @__PURE__ */ new Map([
707
+ const $ = /* @__PURE__ */ new Map([
637
708
  ["br", "br"],
638
709
  ["hr", "hr"]
639
- ]), w = /* @__PURE__ */ new Map([
640
- ["b", /* @__PURE__ */ new Map([["font-weight", "bold"]])],
641
- ["i", /* @__PURE__ */ new Map([["font-style", "italic"]])],
642
- ["u", /* @__PURE__ */ new Map([["text-decoration", "underline"]])],
643
- ["s", /* @__PURE__ */ new Map([["text-decoration", "line-through"]])],
644
- ["mark", /* @__PURE__ */ new Map([["background-color", "yellow"]])],
645
- ["small", /* @__PURE__ */ new Map([["font-size", "smaller"]])],
646
- ["strong", /* @__PURE__ */ new Map([["font-weight", "bold"]])],
647
- ["em", /* @__PURE__ */ new Map([["font-style", "italic"]])],
648
- [
649
- "sub",
650
- /* @__PURE__ */ new Map([
651
- ["vertical-align", "sub"],
652
- ["font-size", "smaller"]
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 ?? n.slice(t, r),
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) => `${M()}${i}`).join(" ")
731
+ cssClass: s.map((i) => `${C()}${i}`).join(" ")
741
732
  };
742
- }, K = () => [...A.keys()].join("|"), W = () => [...N.keys()].join("|"), Y = () => new RegExp(
743
- `<\\/?(${K()})>|<(${W()})\\s*/?>`,
733
+ }, Q = () => [...L.keys()].join("|"), ee = () => [...$.keys()].join("|"), te = () => new RegExp(
734
+ `<\\/?(${Q()})>|<(${ee()})\\s*/?>`,
744
735
  "gi"
745
736
  );
746
- function z(e, n) {
747
- const t = w.get(e) ?? /* @__PURE__ */ new Map();
748
- Object.entries(n).forEach(([r, o]) => t.set(r, o)), w.set(e, t);
749
- }
750
- function P() {
751
- const e = [];
752
- for (const [n, t] of w) {
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
- if (t) {
769
- t.textContent = e;
770
- return;
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 r = n.document.createElement("style");
773
- r.textContent = e, r.setAttribute("id", "html-text-parser-styles"), n.document.head.appendChild(r);
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
- console.warn(
777
- "[html-text-parser] Cannot inject stylesheet: document is not available."
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 ee(e) {
797
+ function ne(e, t, r) {
781
798
  const n = [];
782
- let t;
783
- for (const r of e) {
784
- const o = r.containerTagNames.join(","), s = t?.containerTagNames.join(",");
785
- o !== s && (t = {
786
- containerTagNames: r.containerTagNames,
787
- cssClass: r.containerTagNames.map((a) => `${M()}${a}`).join(" "),
788
- style: r.containerTagNames.map(
789
- (a) => [...w.get(a)?.entries() ?? []].map(([i, c]) => `${i}: ${c}`).join("; ")
790
- ).filter(Boolean).join("; "),
791
- styleObject: Object.fromEntries(
792
- r.containerTagNames.flatMap(
793
- (a) => Array.from(w.get(a) ?? [])
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 te(e, n, t) {
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] Cannot append segments: provided element does not support appendChild."
822
+ "[html-text-parser] appendToDom: element does not support appendChild."
811
823
  );
812
824
  return;
813
825
  }
814
- t = { useClasses: !0, useStyles: !1, ...t };
815
- const r = e, o = globalThis.document;
816
- for (const s of n) {
817
- const a = o.createElement(
818
- s.containerTagNames[0] || "span"
819
- );
820
- t.useClasses && (a.className = s.cssClass), t.useStyles && a.setAttribute("style", s.style);
821
- for (const i of s.segments) {
822
- const c = o.createElement("span");
823
- c.textContent = i.text, t.useClasses && (c.className = i.cssClass), t.useStyles && c.setAttribute("style", i.style), a.appendChild(c);
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
- r.appendChild(a);
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 h(e) {
829
- return ee(B(e));
968
+ function oe() {
969
+ return M(C());
830
970
  }
831
- function B(e) {
832
- const n = [], t = /* @__PURE__ */ new Map();
833
- let r = 0;
834
- for (const o of e.matchAll(Y())) {
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
- const a = o[2]?.toLowerCase();
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
- return r < e.length && n.push(
861
- x(
862
- [...t.keys()],
863
- e,
864
- r,
865
- e.length
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
- ), n;
995
+ ), "document" in globalThis && B();
868
996
  }
869
- function U(e) {
997
+ function _(e) {
870
998
  if (Array.isArray(e)) {
871
- e.forEach((t) => {
872
- U(t);
873
- });
999
+ e.forEach((r) => _(r));
874
1000
  return;
875
1001
  }
876
- const n = e.tagName ?? e.tag;
877
- A.set(e.tag, n), e.style != null && Object.keys(e.style).length && z(n, e.style);
1002
+ const t = e.tagName ?? e.tag;
1003
+ L.set(e.tag, t);
878
1004
  }
879
- function D(e) {
1005
+ function q(e) {
880
1006
  if (Array.isArray(e)) {
881
- e.forEach((t) => {
882
- D(t);
883
- });
1007
+ e.forEach((r) => q(r));
884
1008
  return;
885
1009
  }
886
- const n = e.tagName ?? e.tag;
887
- N.set(e.tag, n), e.style != null && Object.keys(e.style).length && z(n, e.style);
888
- }
889
- h.setTag = U;
890
- h.setSelfClosingTag = D;
891
- h.setBlockTag = (e) => v.add(e);
892
- h.removeBlockTag = (e) => v.delete(e);
893
- h.setCssClassPrefix = X;
894
- h.getStylesheet = P;
895
- h.flat = B;
896
- h.generateStylesheet = Q;
897
- h.appendToDom = te;
898
- function ne(e, n, t) {
899
- function r(o) {
900
- const [s, a] = E(() => t ? t(o) : o);
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 (!n(s)) throw new Error(`"${o}" is not a valid ${e}`);
1036
+ if (!t(s)) throw new Error(`"${o}" is not a valid ${e}`);
903
1037
  return s;
904
1038
  }
905
- return r.from = (o) => {
906
- const [s, a] = E(() => t ? t(o) : o);
1039
+ return n.from = (o) => {
1040
+ const [s, a] = E(() => r ? r(o) : o);
907
1041
  if (!a)
908
- return n(s) ? s : void 0;
909
- }, r.is = (o) => {
910
- const s = E(() => t ? t(o) : o)[0] ?? o;
911
- return n(s);
912
- }, r;
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 ye = ne(
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
- ye as NumericString,
925
- y as Result,
926
- O as SIGNAL,
927
- ce as clamp,
928
- L as computed,
929
- re as convertCase,
930
- ne as createBrand,
931
- le as debounce,
932
- ie as delay,
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
- J as getProp,
935
- ae as groupBy,
936
- oe as http,
937
- de as isSignal,
938
- he as linkedSignal,
939
- I as normalizeString,
940
- h as parseRichText,
941
- B as parseRichTextFlat,
942
- ue as pickPaths,
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
- fe as toArray,
1080
+ be as toArray,
949
1081
  E as tryCatch,
950
- se as tryCatchAsync,
951
- pe as untracked
1082
+ de as tryCatchAsync,
1083
+ Se as untracked
952
1084
  };