@levischuck/tiny-html 0.0.2 → 0.0.4
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/dist/index.d.ts +2 -0
- package/dist/index.js +235 -214
- package/dist/writer.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -13,5 +13,7 @@ export declare function writeHtml(input: HtmlNode | ParseResult, options?: Write
|
|
|
13
13
|
*/
|
|
14
14
|
export declare function awaitHtmlNode(node: HtmlNode | Promise<HtmlNode>): Promise<HtmlNode>;
|
|
15
15
|
export { htmlNodeTo } from './convert.ts';
|
|
16
|
+
export { decodeHtmlEntities, encodeHtmlEntities } from './entities.ts';
|
|
16
17
|
export type { CreateElementFn, CreateElementProps } from './convert.ts';
|
|
18
|
+
export { getTextContent } from './writer.ts';
|
|
17
19
|
export type { WriterOptions, ParseResult, HtmlNode, HtmlElement, HtmlProps, HtmlStyle } from './types.ts';
|
package/dist/index.js
CHANGED
|
@@ -292,38 +292,38 @@ const F = /* @__PURE__ */ new Set([
|
|
|
292
292
|
dArr: "⇓",
|
|
293
293
|
hArr: "⇔"
|
|
294
294
|
}, B = {};
|
|
295
|
-
for (const [e,
|
|
296
|
-
B[
|
|
297
|
-
function
|
|
298
|
-
return !e || typeof e != "string" || !e.includes("&") ? e : e.replace(/&(?:#[xX]([0-9a-fA-F]+)|#(\d+)|([a-zA-Z][a-zA-Z0-9]*));/g, (
|
|
299
|
-
if (
|
|
300
|
-
const
|
|
301
|
-
return String.fromCodePoint(
|
|
302
|
-
} else if (
|
|
303
|
-
const
|
|
304
|
-
return String.fromCodePoint(
|
|
305
|
-
} else if (
|
|
306
|
-
return I[
|
|
307
|
-
return
|
|
295
|
+
for (const [e, n] of Object.entries(I))
|
|
296
|
+
B[n] || (B[n] = e);
|
|
297
|
+
function w(e) {
|
|
298
|
+
return !e || typeof e != "string" || !e.includes("&") ? e : e.replace(/&(?:#[xX]([0-9a-fA-F]+)|#(\d+)|([a-zA-Z][a-zA-Z0-9]*));/g, (n, r, l, a) => {
|
|
299
|
+
if (r) {
|
|
300
|
+
const o = parseInt(r, 16);
|
|
301
|
+
return String.fromCodePoint(o);
|
|
302
|
+
} else if (l) {
|
|
303
|
+
const o = parseInt(l, 10);
|
|
304
|
+
return String.fromCodePoint(o);
|
|
305
|
+
} else if (a && I[a])
|
|
306
|
+
return I[a];
|
|
307
|
+
return n;
|
|
308
308
|
});
|
|
309
309
|
}
|
|
310
|
-
function
|
|
310
|
+
function x(e, n = !1) {
|
|
311
311
|
if (!e || typeof e != "string")
|
|
312
312
|
return e;
|
|
313
|
-
let
|
|
314
|
-
return
|
|
313
|
+
let r = e;
|
|
314
|
+
return r = r.replace(/&/g, "&"), r = r.replace(/</g, "<"), r = r.replace(/>/g, ">"), n && (r = r.replace(/"/g, """)), r;
|
|
315
315
|
}
|
|
316
316
|
function Z(e) {
|
|
317
317
|
return e.replace(/\]\]>/g, "]]]]></g, (
|
|
320
|
+
return e.replace(/[-_]([a-z])/g, (n, r) => r.toUpperCase());
|
|
321
321
|
}
|
|
322
322
|
function $(e) {
|
|
323
|
-
return e.replace(/[A-Z]/g, (
|
|
323
|
+
return e.replace(/[A-Z]/g, (n) => `-${n.toLowerCase()}`);
|
|
324
324
|
}
|
|
325
|
-
function
|
|
326
|
-
return new TextDecoder("utf-8").decode(e.slice(
|
|
325
|
+
function d(e, n, r) {
|
|
326
|
+
return new TextDecoder("utf-8").decode(e.slice(n, r));
|
|
327
327
|
}
|
|
328
328
|
function S(e) {
|
|
329
329
|
return e === 32 || e === 9 || e === 10 || e === 13;
|
|
@@ -337,197 +337,197 @@ function N(e) {
|
|
|
337
337
|
e === 58;
|
|
338
338
|
}
|
|
339
339
|
function K(e) {
|
|
340
|
-
const
|
|
340
|
+
const r = new TextEncoder().encode(e), l = {
|
|
341
341
|
node: []
|
|
342
|
-
},
|
|
343
|
-
let
|
|
342
|
+
}, a = [], o = [];
|
|
343
|
+
let u = "HTML", i = "TEXT", t = 0, c = 0, y = 0, A = 0, b = 0, g = "", P = 0, h = null;
|
|
344
344
|
function M() {
|
|
345
|
-
return
|
|
345
|
+
return o.length > 0 ? o[o.length - 1].children : a;
|
|
346
346
|
}
|
|
347
|
-
function X(s,
|
|
348
|
-
if (s >=
|
|
349
|
-
const
|
|
347
|
+
function X(s, f) {
|
|
348
|
+
if (s >= f) return;
|
|
349
|
+
const p = d(r, s, f), T = w(p);
|
|
350
350
|
T.length > 0 && M().push(T);
|
|
351
351
|
}
|
|
352
|
-
function U(s,
|
|
353
|
-
if (s >=
|
|
354
|
-
const
|
|
355
|
-
|
|
352
|
+
function U(s, f) {
|
|
353
|
+
if (s >= f) return;
|
|
354
|
+
const p = d(r, s, f);
|
|
355
|
+
p.length > 0 && M().push(p);
|
|
356
356
|
}
|
|
357
|
-
function C(s,
|
|
358
|
-
const
|
|
359
|
-
return
|
|
357
|
+
function C(s, f) {
|
|
358
|
+
const p = s.toLowerCase();
|
|
359
|
+
return f === "SVG" && V.has(p) ? V.get(p) : p;
|
|
360
360
|
}
|
|
361
|
-
function _(s,
|
|
362
|
-
const
|
|
363
|
-
if (
|
|
364
|
-
if (
|
|
365
|
-
if (
|
|
366
|
-
return z.has(
|
|
367
|
-
if (
|
|
368
|
-
const T = k(
|
|
369
|
-
return
|
|
361
|
+
function _(s, f) {
|
|
362
|
+
const p = s.toLowerCase();
|
|
363
|
+
if (p === "class") return "className";
|
|
364
|
+
if (p === "for") return "htmlFor";
|
|
365
|
+
if (f === "SVG")
|
|
366
|
+
return z.has(p) ? z.get(p) : s;
|
|
367
|
+
if (f === "HTML") {
|
|
368
|
+
const T = k(p);
|
|
369
|
+
return p === "class" || p === "for" ? p === "class" ? "className" : "htmlFor" : T;
|
|
370
370
|
}
|
|
371
|
-
return
|
|
371
|
+
return p;
|
|
372
372
|
}
|
|
373
373
|
function R(s) {
|
|
374
|
-
const
|
|
375
|
-
for (let
|
|
376
|
-
if (
|
|
377
|
-
for (let T =
|
|
378
|
-
const m =
|
|
374
|
+
const f = C(s, u);
|
|
375
|
+
for (let p = o.length - 1; p >= 0; p--)
|
|
376
|
+
if (o[p].type === f) {
|
|
377
|
+
for (let T = o.length - 1; T >= p; T--) {
|
|
378
|
+
const m = o.pop(), E = {
|
|
379
379
|
type: m.type,
|
|
380
380
|
props: {
|
|
381
381
|
...m.props,
|
|
382
382
|
children: m.children.length === 1 ? m.children[0] : m.children
|
|
383
383
|
}
|
|
384
384
|
};
|
|
385
|
-
|
|
385
|
+
o.length > 0 ? o[o.length - 1].children.push(E) : a.push(E), (m.type === "svg" || m.type === "math") && (u = "HTML");
|
|
386
386
|
}
|
|
387
387
|
return;
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
|
-
function
|
|
391
|
-
const T = C(s,
|
|
392
|
-
if (
|
|
393
|
-
const
|
|
394
|
-
|
|
390
|
+
function v(s, f, p) {
|
|
391
|
+
const T = C(s, u);
|
|
392
|
+
if (o.length > 0 && q.has(T)) {
|
|
393
|
+
const E = q.get(T), j = o[o.length - 1].type;
|
|
394
|
+
E.has(j) && R(j);
|
|
395
395
|
}
|
|
396
|
-
let m =
|
|
397
|
-
if (T === "svg" ? m = "SVG" : T === "math" && (m = "MATHML"), F.has(T) ||
|
|
398
|
-
const
|
|
396
|
+
let m = u;
|
|
397
|
+
if (T === "svg" ? m = "SVG" : T === "math" && (m = "MATHML"), F.has(T) || p) {
|
|
398
|
+
const E = {
|
|
399
399
|
type: T,
|
|
400
|
-
props:
|
|
400
|
+
props: f
|
|
401
401
|
};
|
|
402
|
-
M().push(
|
|
402
|
+
M().push(E);
|
|
403
403
|
} else {
|
|
404
|
-
const
|
|
404
|
+
const E = {
|
|
405
405
|
type: T,
|
|
406
|
-
props:
|
|
406
|
+
props: f,
|
|
407
407
|
children: [],
|
|
408
408
|
namespace: m
|
|
409
409
|
};
|
|
410
|
-
|
|
410
|
+
o.push(E), u = m;
|
|
411
411
|
}
|
|
412
412
|
}
|
|
413
|
-
for (; t <
|
|
414
|
-
const s =
|
|
413
|
+
for (; t < r.length; ) {
|
|
414
|
+
const s = r[t];
|
|
415
415
|
switch (i) {
|
|
416
416
|
case "TEXT":
|
|
417
|
-
s === 60 && (X(
|
|
417
|
+
s === 60 && (X(c, t), i = "TAG_OPEN"), t++;
|
|
418
418
|
break;
|
|
419
419
|
case "TAG_OPEN":
|
|
420
|
-
s === 33 ?
|
|
420
|
+
s === 33 ? r[t + 1] === 45 && r[t + 2] === 45 ? (i = "COMMENT", t += 3) : r[t + 1] === 68 || r[t + 1] === 100 ? d(r, t, Math.min(t + 20, r.length)).toLowerCase().startsWith("!doctype") ? (i = "DOCTYPE", y = t, t++) : (c = t - 1, i = "TEXT") : r[t + 1] === 91 && r[t + 2] === 67 && d(r, t, Math.min(t + 9, r.length)).startsWith("![CDATA[") ? (i = "CDATA", c = t + 8, t += 8) : (c = t - 1, i = "TEXT") : s === 63 ? (i = "PROCESSING_INSTRUCTION", y = t - 1, t++) : s === 47 ? (i = "TAG_CLOSE_START", t++) : N(s) ? (y = t, i = "TAG_NAME", h = null, t++) : (c = t - 1, i = "TEXT");
|
|
421
421
|
break;
|
|
422
422
|
case "TAG_NAME":
|
|
423
423
|
if (S(s)) {
|
|
424
|
-
const
|
|
424
|
+
const f = d(r, y, t), p = f.toLowerCase();
|
|
425
425
|
h = {
|
|
426
|
-
type:
|
|
426
|
+
type: f,
|
|
427
427
|
props: {},
|
|
428
428
|
children: [],
|
|
429
|
-
namespace:
|
|
429
|
+
namespace: p === "svg" ? "SVG" : p === "math" ? "MATHML" : u
|
|
430
430
|
}, i = "ATTRIBUTES", t++;
|
|
431
431
|
} else if (s === 62) {
|
|
432
|
-
const
|
|
433
|
-
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
} else s === 47 ? (i = "TAG_CLOSE_SELF", t++) : N(s) ? t++ : (
|
|
432
|
+
const f = d(r, y, t);
|
|
433
|
+
v(f, {}, !1);
|
|
434
|
+
const p = C(f, u);
|
|
435
|
+
p === "script" ? (i = "SCRIPT_CONTENT", c = t + 1) : p === "style" ? (i = "STYLE_CONTENT", c = t + 1) : (i = "TEXT", c = t + 1), t++;
|
|
436
|
+
} else s === 47 ? (i = "TAG_CLOSE_SELF", t++) : N(s) ? t++ : (c = y - 1, i = "TEXT");
|
|
437
437
|
break;
|
|
438
438
|
case "ATTRIBUTES":
|
|
439
439
|
if (S(s))
|
|
440
440
|
t++;
|
|
441
441
|
else if (s === 62) {
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
} else s === 47 ? (i = "TAG_CLOSE_SELF", t++) : N(s) ? (A = t, i = "ATTRIBUTE_NAME", t++) : (
|
|
442
|
+
const f = h.type;
|
|
443
|
+
v(f, h.props, !1);
|
|
444
|
+
const p = C(f, u);
|
|
445
|
+
p === "script" ? (i = "SCRIPT_CONTENT", c = t + 1) : p === "style" ? (i = "STYLE_CONTENT", c = t + 1) : (i = "TEXT", c = t + 1), t++;
|
|
446
|
+
} else s === 47 ? (i = "TAG_CLOSE_SELF", t++) : N(s) ? (A = t, i = "ATTRIBUTE_NAME", t++) : (c = y - 1, i = "TEXT");
|
|
447
447
|
break;
|
|
448
448
|
case "ATTRIBUTE_NAME":
|
|
449
449
|
if (S(s)) {
|
|
450
|
-
|
|
451
|
-
const
|
|
452
|
-
h.props[
|
|
450
|
+
g = d(r, A, t);
|
|
451
|
+
const f = _(g, h.namespace);
|
|
452
|
+
h.props[f] = !0, g = "", i = "ATTRIBUTES", t++;
|
|
453
453
|
} else if (s === 61)
|
|
454
|
-
|
|
454
|
+
g = d(r, A, t), i = "ATTRIBUTE_VALUE_START", t++;
|
|
455
455
|
else if (s === 62) {
|
|
456
|
-
|
|
457
|
-
const
|
|
458
|
-
h.props[
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
const T = C(
|
|
462
|
-
T === "script" ? (i = "SCRIPT_CONTENT",
|
|
456
|
+
g = d(r, A, t);
|
|
457
|
+
const f = _(g, h.namespace);
|
|
458
|
+
h.props[f] = !0, g = "";
|
|
459
|
+
const p = h.type;
|
|
460
|
+
v(p, h.props, !1);
|
|
461
|
+
const T = C(p, u);
|
|
462
|
+
T === "script" ? (i = "SCRIPT_CONTENT", c = t + 1) : T === "style" ? (i = "STYLE_CONTENT", c = t + 1) : (i = "TEXT", c = t + 1), t++;
|
|
463
463
|
} else if (s === 47) {
|
|
464
|
-
|
|
465
|
-
const
|
|
466
|
-
h.props[
|
|
467
|
-
} else N(s) ? t++ : (
|
|
464
|
+
g = d(r, A, t);
|
|
465
|
+
const f = _(g, h.namespace);
|
|
466
|
+
h.props[f] = !0, g = "", i = "TAG_CLOSE_SELF", t++;
|
|
467
|
+
} else N(s) ? t++ : (c = y - 1, i = "TEXT");
|
|
468
468
|
break;
|
|
469
469
|
case "ATTRIBUTE_VALUE_START":
|
|
470
|
-
S(s) ? t++ : s === 34 || s === 39 ? (P = s,
|
|
470
|
+
S(s) ? t++ : s === 34 || s === 39 ? (P = s, b = t + 1, i = "ATTRIBUTE_VALUE_QUOTED", t++) : (b = t, i = "ATTRIBUTE_VALUE_UNQUOTED");
|
|
471
471
|
break;
|
|
472
472
|
case "ATTRIBUTE_VALUE_QUOTED":
|
|
473
473
|
if (s === P) {
|
|
474
|
-
const
|
|
475
|
-
T === "style" ? h.props[T] = D(
|
|
474
|
+
const f = d(r, b, t), p = w(f), T = _(g, h.namespace);
|
|
475
|
+
T === "style" ? h.props[T] = D(p) : h.props[T] = p, g = "", i = "ATTRIBUTES", t++;
|
|
476
476
|
} else
|
|
477
477
|
t++;
|
|
478
478
|
break;
|
|
479
479
|
case "ATTRIBUTE_VALUE_UNQUOTED":
|
|
480
480
|
if (S(s) || s === 62 || s === 47) {
|
|
481
|
-
const
|
|
482
|
-
T === "style" ? h.props[T] = D(
|
|
481
|
+
const f = d(r, b, t), p = w(f), T = _(g, h.namespace);
|
|
482
|
+
T === "style" ? h.props[T] = D(p) : h.props[T] = p, g = "", i = "ATTRIBUTES";
|
|
483
483
|
} else
|
|
484
484
|
t++;
|
|
485
485
|
break;
|
|
486
486
|
case "TAG_CLOSE_SELF":
|
|
487
487
|
if (s === 62) {
|
|
488
|
-
const
|
|
489
|
-
|
|
488
|
+
const f = h.type;
|
|
489
|
+
v(f, h.props, !0), i = "TEXT", c = t + 1, t++;
|
|
490
490
|
} else
|
|
491
|
-
|
|
491
|
+
c = y - 1, i = "TEXT";
|
|
492
492
|
break;
|
|
493
493
|
case "TAG_CLOSE_START":
|
|
494
|
-
N(s) ? (
|
|
494
|
+
N(s) ? (y = t, i = "TAG_CLOSE_NAME", t++) : (c = t - 2, i = "TEXT");
|
|
495
495
|
break;
|
|
496
496
|
case "TAG_CLOSE_NAME":
|
|
497
497
|
if (s === 62) {
|
|
498
|
-
const
|
|
499
|
-
R(
|
|
500
|
-
} else S(s) || N(s) ? t++ : (
|
|
498
|
+
const f = d(r, y, t);
|
|
499
|
+
R(f), i = "TEXT", c = t + 1, t++;
|
|
500
|
+
} else S(s) || N(s) ? t++ : (c = y - 2, i = "TEXT");
|
|
501
501
|
break;
|
|
502
502
|
case "COMMENT":
|
|
503
|
-
s === 45 &&
|
|
503
|
+
s === 45 && r[t + 1] === 45 && r[t + 2] === 62 ? (i = "TEXT", c = t + 3, t += 3) : t++;
|
|
504
504
|
break;
|
|
505
505
|
case "DOCTYPE":
|
|
506
506
|
if (s === 62) {
|
|
507
|
-
const
|
|
508
|
-
|
|
507
|
+
const f = d(r, y, t + 1);
|
|
508
|
+
l.doctype = "<" + f, i = "TEXT", c = t + 1, t++;
|
|
509
509
|
} else
|
|
510
510
|
t++;
|
|
511
511
|
break;
|
|
512
512
|
case "CDATA":
|
|
513
|
-
s === 93 &&
|
|
513
|
+
s === 93 && r[t + 1] === 93 && r[t + 2] === 62 ? (U(c, t), i = "TEXT", c = t + 3, t += 3) : t++;
|
|
514
514
|
break;
|
|
515
515
|
case "PROCESSING_INSTRUCTION":
|
|
516
|
-
if (s === 63 &&
|
|
517
|
-
const
|
|
518
|
-
|
|
516
|
+
if (s === 63 && r[t + 1] === 62) {
|
|
517
|
+
const f = d(r, y, t + 2);
|
|
518
|
+
l.xml = f, i = "TEXT", c = t + 2, t += 2;
|
|
519
519
|
} else
|
|
520
520
|
t++;
|
|
521
521
|
break;
|
|
522
522
|
case "SCRIPT_CONTENT":
|
|
523
523
|
case "STYLE_CONTENT":
|
|
524
|
-
if (s === 60 &&
|
|
525
|
-
const
|
|
526
|
-
if (T.startsWith(
|
|
527
|
-
U(
|
|
528
|
-
let m = t +
|
|
529
|
-
for (; m <
|
|
530
|
-
R(
|
|
524
|
+
if (s === 60 && r[t + 1] === 47) {
|
|
525
|
+
const f = i === "SCRIPT_CONTENT" ? "script" : "style", p = "</" + f, T = d(r, t, Math.min(t + p.length + 1, r.length)).toLowerCase();
|
|
526
|
+
if (T.startsWith(p) && (T[p.length] === ">" || S(T.charCodeAt(p.length)))) {
|
|
527
|
+
U(c, t);
|
|
528
|
+
let m = t + p.length;
|
|
529
|
+
for (; m < r.length && r[m] !== 62; ) m++;
|
|
530
|
+
R(f), i = "TEXT", c = m + 1, t = m + 1;
|
|
531
531
|
} else
|
|
532
532
|
t++;
|
|
533
533
|
} else
|
|
@@ -537,197 +537,218 @@ function K(e) {
|
|
|
537
537
|
t++;
|
|
538
538
|
}
|
|
539
539
|
}
|
|
540
|
-
for (i === "TEXT" ? X(
|
|
541
|
-
const s =
|
|
540
|
+
for (i === "TEXT" ? X(c, t) : (i === "SCRIPT_CONTENT" || i === "STYLE_CONTENT") && U(c, t); o.length > 0; ) {
|
|
541
|
+
const s = o.pop(), f = {
|
|
542
542
|
type: s.type,
|
|
543
543
|
props: {
|
|
544
544
|
...s.props,
|
|
545
545
|
children: s.children.length === 1 ? s.children[0] : s.children
|
|
546
546
|
}
|
|
547
547
|
};
|
|
548
|
-
|
|
548
|
+
o.length > 0 ? o[o.length - 1].children.push(f) : a.push(f);
|
|
549
549
|
}
|
|
550
|
-
return
|
|
550
|
+
return a.length === 0 ? l.node = null : a.length === 1 ? l.node = a[0] : l.node = a, l;
|
|
551
551
|
}
|
|
552
552
|
function D(e) {
|
|
553
|
-
const
|
|
554
|
-
for (const
|
|
555
|
-
const
|
|
556
|
-
if (
|
|
557
|
-
const
|
|
558
|
-
|
|
553
|
+
const n = {}, l = w(e).split(/;(?![^(]*\))/);
|
|
554
|
+
for (const a of l) {
|
|
555
|
+
const o = a.indexOf(":");
|
|
556
|
+
if (o === -1) continue;
|
|
557
|
+
const u = a.substring(0, o).trim(), i = a.substring(o + 1).trim();
|
|
558
|
+
u && i && (n[k(u)] = i);
|
|
559
559
|
}
|
|
560
|
-
return
|
|
560
|
+
return n;
|
|
561
561
|
}
|
|
562
|
-
function H(e,
|
|
563
|
-
const
|
|
564
|
-
let
|
|
562
|
+
function H(e, n = {}) {
|
|
563
|
+
const r = [];
|
|
564
|
+
let l, a, o;
|
|
565
565
|
if (e && typeof e == "object" && "node" in e) {
|
|
566
|
-
const
|
|
567
|
-
|
|
566
|
+
const c = e;
|
|
567
|
+
l = c.node, a = c.xml ?? n.xml, o = c.doctype ?? n.doctype;
|
|
568
568
|
} else
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
`) ||
|
|
572
|
-
`)),
|
|
573
|
-
`) ||
|
|
569
|
+
l = e, a = n.xml, o = n.doctype;
|
|
570
|
+
a && (r.push(a), a.endsWith(`
|
|
571
|
+
`) || r.push(`
|
|
572
|
+
`)), o && (r.push(o), o.endsWith(`
|
|
573
|
+
`) || r.push(`
|
|
574
574
|
`));
|
|
575
|
-
const
|
|
576
|
-
return O(
|
|
575
|
+
const u = n.useCDataForScripts ?? !1, i = n.useCDataForStyles ?? !1, t = n.voidTrailingSlash ?? !0;
|
|
576
|
+
return O(l, r, "HTML", u, i, t), r.join("");
|
|
577
577
|
}
|
|
578
|
-
function O(e,
|
|
578
|
+
function O(e, n, r, l, a, o) {
|
|
579
579
|
if (e != null) {
|
|
580
580
|
if (typeof e == "string") {
|
|
581
|
-
|
|
581
|
+
n.push(x(e, !1));
|
|
582
582
|
return;
|
|
583
583
|
}
|
|
584
584
|
if (typeof e == "number" || typeof e == "bigint") {
|
|
585
|
-
|
|
585
|
+
n.push(String(e));
|
|
586
586
|
return;
|
|
587
587
|
}
|
|
588
588
|
if (typeof e == "boolean") {
|
|
589
|
-
|
|
589
|
+
n.push(String(e));
|
|
590
590
|
return;
|
|
591
591
|
}
|
|
592
592
|
if (Array.isArray(e)) {
|
|
593
|
-
for (const
|
|
594
|
-
O(
|
|
593
|
+
for (const u of e)
|
|
594
|
+
O(u, n, r, l, a, o);
|
|
595
595
|
return;
|
|
596
596
|
}
|
|
597
597
|
if (typeof e != "function" && typeof e != "symbol" && !(e && typeof e == "object" && "then" in e && typeof e.then == "function") && e && typeof e == "object" && "type" in e && "props" in e) {
|
|
598
|
-
J(e,
|
|
598
|
+
J(e, n, r, l, a, o);
|
|
599
599
|
return;
|
|
600
600
|
}
|
|
601
601
|
}
|
|
602
602
|
}
|
|
603
|
-
function J(e,
|
|
604
|
-
var
|
|
605
|
-
const
|
|
606
|
-
let i =
|
|
607
|
-
if (
|
|
608
|
-
for (const [A,
|
|
609
|
-
if (A !== "children" && !(
|
|
610
|
-
if (
|
|
611
|
-
|
|
612
|
-
else if (A === "style" && typeof
|
|
613
|
-
const
|
|
614
|
-
|
|
603
|
+
function J(e, n, r, l, a, o) {
|
|
604
|
+
var y;
|
|
605
|
+
const u = e.type;
|
|
606
|
+
let i = r;
|
|
607
|
+
if (u === "svg" ? i = "SVG" : u === "math" && (i = "MATHML"), n.push("<"), n.push(u), e.props) {
|
|
608
|
+
for (const [A, b] of Object.entries(e.props))
|
|
609
|
+
if (A !== "children" && !(b === !1 || b === null || b === void 0))
|
|
610
|
+
if (b === !0)
|
|
611
|
+
n.push(" "), n.push(A);
|
|
612
|
+
else if (A === "style" && typeof b == "object") {
|
|
613
|
+
const g = ee(b);
|
|
614
|
+
g && (n.push(' style="'), n.push(x(g, !0)), n.push('"'));
|
|
615
615
|
} else
|
|
616
|
-
|
|
616
|
+
n.push(" "), n.push(A), n.push('="'), n.push(x(String(b), !0)), n.push('"');
|
|
617
617
|
}
|
|
618
|
-
const t = (
|
|
619
|
-
let
|
|
620
|
-
if (t && typeof t == "object" && "then" in t && typeof t.then == "function" ?
|
|
621
|
-
|
|
622
|
-
else if (
|
|
623
|
-
|
|
618
|
+
const t = (y = e.props) == null ? void 0 : y.children;
|
|
619
|
+
let c;
|
|
620
|
+
if (t && typeof t == "object" && "then" in t && typeof t.then == "function" ? c = !1 : c = t != null && (Array.isArray(t) && t.length > 0 || !Array.isArray(t) && t !== !1), F.has(u))
|
|
621
|
+
o ? n.push(" />") : n.push(">");
|
|
622
|
+
else if (c) {
|
|
623
|
+
n.push(">");
|
|
624
624
|
const A = t;
|
|
625
|
-
|
|
626
|
-
} else Q.has(
|
|
625
|
+
u === "script" && l || u === "style" && a ? (n.push("<![CDATA["), G(A, n, i, l, a, o), n.push("]]>")) : u === "script" || u === "style" ? W(A, n) : O(A, n, i, l, a, o), n.push("</"), n.push(u), n.push(">");
|
|
626
|
+
} else Q.has(u), n.push("></"), n.push(u), n.push(">");
|
|
627
627
|
}
|
|
628
|
-
function
|
|
628
|
+
function G(e, n, r, l, a, o, u) {
|
|
629
629
|
if (e != null) {
|
|
630
630
|
if (typeof e == "string") {
|
|
631
|
-
|
|
631
|
+
n.push(Z(e));
|
|
632
632
|
return;
|
|
633
633
|
}
|
|
634
634
|
if (typeof e == "number" || typeof e == "bigint" || typeof e == "boolean") {
|
|
635
|
-
|
|
635
|
+
n.push(String(e));
|
|
636
636
|
return;
|
|
637
637
|
}
|
|
638
638
|
if (Array.isArray(e)) {
|
|
639
639
|
for (const i of e)
|
|
640
|
-
|
|
640
|
+
G(i, n, r, l, a, o);
|
|
641
641
|
return;
|
|
642
642
|
}
|
|
643
|
-
O(e,
|
|
643
|
+
O(e, n, r, l, a, o);
|
|
644
644
|
}
|
|
645
645
|
}
|
|
646
|
-
function W(e,
|
|
646
|
+
function W(e, n) {
|
|
647
647
|
if (e != null) {
|
|
648
648
|
if (typeof e == "string") {
|
|
649
|
-
|
|
649
|
+
n.push(e);
|
|
650
650
|
return;
|
|
651
651
|
}
|
|
652
652
|
if (typeof e == "number" || typeof e == "bigint" || typeof e == "boolean") {
|
|
653
|
-
|
|
653
|
+
n.push(String(e));
|
|
654
654
|
return;
|
|
655
655
|
}
|
|
656
656
|
if (Array.isArray(e)) {
|
|
657
|
-
for (const
|
|
658
|
-
W(
|
|
657
|
+
for (const r of e)
|
|
658
|
+
W(r, n);
|
|
659
659
|
return;
|
|
660
660
|
}
|
|
661
661
|
}
|
|
662
662
|
}
|
|
663
663
|
function ee(e) {
|
|
664
|
-
const
|
|
665
|
-
for (const [
|
|
666
|
-
if (
|
|
667
|
-
const
|
|
668
|
-
|
|
664
|
+
const n = [];
|
|
665
|
+
for (const [r, l] of Object.entries(e))
|
|
666
|
+
if (l) {
|
|
667
|
+
const a = $(r);
|
|
668
|
+
n.push(`${a}: ${l}`);
|
|
669
669
|
}
|
|
670
|
-
return
|
|
670
|
+
return n.join("; ");
|
|
671
|
+
}
|
|
672
|
+
function te(e) {
|
|
673
|
+
const n = [];
|
|
674
|
+
function r(l) {
|
|
675
|
+
if (typeof l == "string" && n.push(l), (typeof l == "number" || typeof l == "bigint" || typeof l == "boolean") && n.push(`${l}`), typeof l == "object" && l !== null && "type" in l && l.props && "children" in l.props) {
|
|
676
|
+
const a = l.props.children;
|
|
677
|
+
if (l.type === "script" || l.type === "style" || l.type === "template" || a && typeof a == "object" && "then" in a && typeof a.then == "function")
|
|
678
|
+
return;
|
|
679
|
+
if (Array.isArray(a))
|
|
680
|
+
for (const o of a)
|
|
681
|
+
r(o);
|
|
682
|
+
else a != null && r(a);
|
|
683
|
+
}
|
|
684
|
+
if (Array.isArray(l))
|
|
685
|
+
for (const a of l)
|
|
686
|
+
r(a);
|
|
687
|
+
}
|
|
688
|
+
return r(e), n.join("");
|
|
671
689
|
}
|
|
672
690
|
async function L(e) {
|
|
673
691
|
if (e == null)
|
|
674
692
|
return e;
|
|
675
693
|
if (e && typeof e == "object" && "then" in e && typeof e.then == "function") {
|
|
676
|
-
const
|
|
677
|
-
return L(
|
|
694
|
+
const n = await e;
|
|
695
|
+
return L(n);
|
|
678
696
|
}
|
|
679
697
|
if (typeof e == "string" || typeof e == "number" || typeof e == "boolean" || typeof e == "bigint")
|
|
680
698
|
return e;
|
|
681
699
|
if (typeof e != "function" && typeof e != "symbol") {
|
|
682
700
|
if (Array.isArray(e))
|
|
683
701
|
return await Promise.all(
|
|
684
|
-
e.filter((
|
|
702
|
+
e.filter((r) => !(r == null || typeof r == "function" || typeof r == "symbol")).map((r) => L(r))
|
|
685
703
|
);
|
|
686
704
|
if (e && typeof e == "object" && "type" in e && "props" in e) {
|
|
687
|
-
const
|
|
688
|
-
for (const [
|
|
689
|
-
if (
|
|
690
|
-
const
|
|
691
|
-
|
|
705
|
+
const n = e, r = {};
|
|
706
|
+
for (const [l, a] of Object.entries(n.props))
|
|
707
|
+
if (l === "children") {
|
|
708
|
+
const o = await L(a);
|
|
709
|
+
o != null && (r.children = o);
|
|
692
710
|
} else {
|
|
693
|
-
if (typeof
|
|
711
|
+
if (typeof a == "function" || typeof a == "symbol")
|
|
694
712
|
continue;
|
|
695
|
-
|
|
713
|
+
a != null && (r[l] = a);
|
|
696
714
|
}
|
|
697
715
|
return {
|
|
698
|
-
type:
|
|
699
|
-
props:
|
|
716
|
+
type: n.type,
|
|
717
|
+
props: r
|
|
700
718
|
};
|
|
701
719
|
}
|
|
702
720
|
}
|
|
703
721
|
}
|
|
704
|
-
function Y(e,
|
|
722
|
+
function Y(e, n) {
|
|
705
723
|
if (e == null || typeof e == "string" || typeof e == "number" || typeof e == "boolean" || typeof e == "bigint")
|
|
706
724
|
return e;
|
|
707
725
|
if (Array.isArray(e))
|
|
708
|
-
return e.map((
|
|
726
|
+
return e.map((r) => Y(r, n));
|
|
709
727
|
if (typeof e == "object" && "type" in e && "props" in e) {
|
|
710
|
-
const { type:
|
|
711
|
-
if (
|
|
712
|
-
const
|
|
713
|
-
return
|
|
728
|
+
const { type: r, props: l } = e, { children: a, ...o } = l;
|
|
729
|
+
if (a !== void 0) {
|
|
730
|
+
const u = Y(a, n);
|
|
731
|
+
return u === null ? n(r, o) : Array.isArray(u) ? n(r, o, ...u) : n(r, o, u);
|
|
714
732
|
}
|
|
715
|
-
return r
|
|
733
|
+
return n(r, o);
|
|
716
734
|
}
|
|
717
735
|
return null;
|
|
718
736
|
}
|
|
719
|
-
function
|
|
737
|
+
function re(e) {
|
|
720
738
|
return K(e);
|
|
721
739
|
}
|
|
722
|
-
function
|
|
723
|
-
return e && typeof e == "object" && "node" in e ? H(e,
|
|
740
|
+
function ne(e, n = {}) {
|
|
741
|
+
return e && typeof e == "object" && "node" in e ? H(e, n) : e === void 0 ? "" : H(e, n);
|
|
724
742
|
}
|
|
725
|
-
async function
|
|
743
|
+
async function ie(e) {
|
|
726
744
|
return await L(e);
|
|
727
745
|
}
|
|
728
746
|
export {
|
|
729
|
-
|
|
747
|
+
ie as awaitHtmlNode,
|
|
748
|
+
w as decodeHtmlEntities,
|
|
749
|
+
x as encodeHtmlEntities,
|
|
750
|
+
te as getTextContent,
|
|
730
751
|
Y as htmlNodeTo,
|
|
731
|
-
|
|
732
|
-
|
|
752
|
+
re as readHtml,
|
|
753
|
+
ne as writeHtml
|
|
733
754
|
};
|
package/dist/writer.d.ts
CHANGED