@mpen/jsxhtml 0.2.2 → 0.3.0
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/css-escape.d.ts +25 -0
- package/dist/dev.d.ts +1 -0
- package/dist/htmlspec/ButtonElement.d.ts +55 -0
- package/dist/htmlspec/GlobalAttributes.d.ts +75 -5
- package/dist/htmlspec/InputAttributes.d.ts +221 -0
- package/dist/htmlspec/IntrinsicElements.d.ts +663 -84
- package/dist/htmlspec/ScriptElement.d.ts +38 -0
- package/dist/htmlspec/StyleAttributes.d.ts +19 -0
- package/dist/index.cjs +3 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +2 -2
- package/dist/jsx-dev-runtime.cjs +3 -1
- package/dist/jsx-dev-runtime.mjs +2 -2
- package/dist/{jsx-runtime-CsQM2fQb.js → jsx-runtime-Dh9PxNQe.js} +645 -20
- package/dist/{jsx-runtime-DpEMYmD9.js → jsx-runtime-cimCxEOU.js} +648 -19
- package/dist/jsx-runtime.cjs +3 -1
- package/dist/jsx-runtime.mjs +1 -1
- package/dist/jsx-types.d.ts +6 -4
- package/dist/jsx.d.ts +3 -2
- package/dist/jsx.test.d.ts +1 -0
- package/dist/log.d.ts +2 -0
- package/dist/template-strings.d.ts +12 -0
- package/dist/template-strings.test.d.ts +6 -0
- package/package.json +11 -7
|
@@ -1333,12 +1333,12 @@ function cc(names) {
|
|
|
1333
1333
|
return out;
|
|
1334
1334
|
}
|
|
1335
1335
|
|
|
1336
|
-
function isFunction(obj) {
|
|
1336
|
+
function isFunction$1(obj) {
|
|
1337
1337
|
return typeof obj === "function";
|
|
1338
1338
|
}
|
|
1339
1339
|
|
|
1340
1340
|
function isIterable(obj) {
|
|
1341
|
-
return isObjectLike(obj) && isFunction(obj[Symbol.iterator]);
|
|
1341
|
+
return isObjectLike(obj) && isFunction$1(obj[Symbol.iterator]);
|
|
1342
1342
|
}
|
|
1343
1343
|
|
|
1344
1344
|
function isNumber(obj) {
|
|
@@ -1349,7 +1349,7 @@ function isObjectLike(obj) {
|
|
|
1349
1349
|
return typeof obj === "object" && obj !== null;
|
|
1350
1350
|
}
|
|
1351
1351
|
|
|
1352
|
-
function isObject(obj) {
|
|
1352
|
+
function isObject$1(obj) {
|
|
1353
1353
|
return obj != null && (typeof obj === "object" || typeof obj === "function");
|
|
1354
1354
|
}
|
|
1355
1355
|
|
|
@@ -1359,7 +1359,7 @@ function isPlainObject(obj) {
|
|
|
1359
1359
|
return proto === null || proto === Object.prototype;
|
|
1360
1360
|
}
|
|
1361
1361
|
|
|
1362
|
-
function isString(obj) {
|
|
1362
|
+
function isString$1(obj) {
|
|
1363
1363
|
return typeof obj === "string";
|
|
1364
1364
|
}
|
|
1365
1365
|
|
|
@@ -1414,7 +1414,7 @@ function styleObjectToString(styles) {
|
|
|
1414
1414
|
}
|
|
1415
1415
|
|
|
1416
1416
|
function entity(ch) {
|
|
1417
|
-
return Object.
|
|
1417
|
+
return Object.prototype.hasOwnProperty.call(entityMap, ch) ? `&${entityMap[ch]};` : `&#x${ch.codePointAt(0).toString(16)};`;
|
|
1418
1418
|
}
|
|
1419
1419
|
|
|
1420
1420
|
function tagName(string) {
|
|
@@ -1426,15 +1426,15 @@ function attrName(string) {
|
|
|
1426
1426
|
}
|
|
1427
1427
|
|
|
1428
1428
|
function attrValue(value) {
|
|
1429
|
-
if (isFunction(value)) {
|
|
1430
|
-
value = `(${value}).call(this)`;
|
|
1429
|
+
if (isFunction$1(value)) {
|
|
1430
|
+
value = `(${value}).call(this,event)`;
|
|
1431
1431
|
}
|
|
1432
1432
|
return `"${String(value).replace(/"/gu, entity)}"`;
|
|
1433
1433
|
}
|
|
1434
1434
|
|
|
1435
1435
|
function attrKvPair(rawAttr, rawVal) {
|
|
1436
1436
|
let escAttr = attrName(rawAttr);
|
|
1437
|
-
if (/^data-/.test(rawAttr) && !isString(rawVal)) {
|
|
1437
|
+
if (/^data-/.test(rawAttr) && !isString$1(rawVal)) {
|
|
1438
1438
|
rawVal = JSON.stringify(rawVal);
|
|
1439
1439
|
}
|
|
1440
1440
|
if (rawVal === true) {
|
|
@@ -1443,7 +1443,7 @@ function attrKvPair(rawAttr, rawVal) {
|
|
|
1443
1443
|
if (rawVal === false || rawVal == null) {
|
|
1444
1444
|
return null;
|
|
1445
1445
|
}
|
|
1446
|
-
if (rawAttr === "class" && !isString(rawVal)) {
|
|
1446
|
+
if (rawAttr === "class" && !isString$1(rawVal)) {
|
|
1447
1447
|
rawVal = cc(rawVal);
|
|
1448
1448
|
}
|
|
1449
1449
|
if (rawAttr === "style" && isPlainObject(rawVal)) {
|
|
@@ -1454,7 +1454,7 @@ function attrKvPair(rawAttr, rawVal) {
|
|
|
1454
1454
|
|
|
1455
1455
|
function attrs(attributes) {
|
|
1456
1456
|
if (attributes == null) return "";
|
|
1457
|
-
if (isObject(attributes)) {
|
|
1457
|
+
if (isObject$1(attributes)) {
|
|
1458
1458
|
attributes = Object.entries(attributes);
|
|
1459
1459
|
}
|
|
1460
1460
|
return attributes.map((([k, v]) => attrKvPair(k, v))).filter((x => x)).map((x => ` ${x}`)).join("");
|
|
@@ -1482,6 +1482,598 @@ function isJsxNode(x) {
|
|
|
1482
1482
|
return x instanceof JsxNode;
|
|
1483
1483
|
}
|
|
1484
1484
|
|
|
1485
|
+
/*! Adapted from https://github.com/mathiasbynens/CSS.escape/blob/4b25c283eaf4dd443f44a7096463e973d56dd1b2/css.escape.js */ function cssEscape(value) {
|
|
1486
|
+
const string = String(value);
|
|
1487
|
+
const length = string.length;
|
|
1488
|
+
let index = -1;
|
|
1489
|
+
let codeUnit;
|
|
1490
|
+
let result = "";
|
|
1491
|
+
const firstCodeUnit = string.charCodeAt(0);
|
|
1492
|
+
if (length === 1 && firstCodeUnit === 45) {
|
|
1493
|
+
return "\\" + string;
|
|
1494
|
+
}
|
|
1495
|
+
while (++index < length) {
|
|
1496
|
+
codeUnit = string.charCodeAt(index);
|
|
1497
|
+
if (codeUnit === 0) {
|
|
1498
|
+
result += "�";
|
|
1499
|
+
continue;
|
|
1500
|
+
}
|
|
1501
|
+
if (codeUnit >= 1 && codeUnit <= 31 || codeUnit === 127 || index === 0 && codeUnit >= 48 && codeUnit <= 57 || index === 1 && codeUnit >= 48 && codeUnit <= 57 && firstCodeUnit === 45) {
|
|
1502
|
+
result += "\\" + codeUnit.toString(16) + " ";
|
|
1503
|
+
continue;
|
|
1504
|
+
}
|
|
1505
|
+
if (codeUnit >= 128 || codeUnit === 45 || codeUnit === 95 || codeUnit >= 48 && codeUnit <= 57 || codeUnit >= 65 && codeUnit <= 90 || codeUnit >= 97 && codeUnit <= 122) {
|
|
1506
|
+
result += string.charAt(index);
|
|
1507
|
+
continue;
|
|
1508
|
+
}
|
|
1509
|
+
result += "\\" + string.charAt(index);
|
|
1510
|
+
}
|
|
1511
|
+
return result;
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
function isFunction(obj) {
|
|
1515
|
+
return typeof obj === "function";
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
function isString(obj) {
|
|
1519
|
+
return typeof obj === "string";
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
function isStringLike(obj) {
|
|
1523
|
+
return typeof obj === "string" || obj instanceof String;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
function isNumberLike(obj) {
|
|
1527
|
+
return typeof obj === "number" || obj instanceof Number;
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
function isBigInt(obj) {
|
|
1531
|
+
return typeof obj === "bigint";
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
function isBoolean(obj) {
|
|
1535
|
+
return obj === true || obj === false;
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
function isRegExp(obj) {
|
|
1539
|
+
return obj instanceof RegExp;
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
function isArray(obj) {
|
|
1543
|
+
return Array.isArray(obj);
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
function isObject(obj) {
|
|
1547
|
+
return obj !== null && typeof obj === "object";
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
function isSymbol(obj) {
|
|
1551
|
+
return Object.prototype.toString.call(obj) === "[object Symbol]";
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
function findFunction(lib, fn, maxDepth = 3) {
|
|
1555
|
+
let queue = [];
|
|
1556
|
+
let path = [];
|
|
1557
|
+
let seen = new Set;
|
|
1558
|
+
--maxDepth;
|
|
1559
|
+
for (;;) {
|
|
1560
|
+
if (lib[fn.name] === fn) {
|
|
1561
|
+
return [ ...path, fn.name ];
|
|
1562
|
+
}
|
|
1563
|
+
seen.add(lib);
|
|
1564
|
+
if (path.length < maxDepth) {
|
|
1565
|
+
for (let n of Object.getOwnPropertyNames(lib)) {
|
|
1566
|
+
if (n[0] !== "_" && n !== "prototype" && lib[n] && !seen.has(lib[n])) {
|
|
1567
|
+
queue.push([ [ ...path, n ], lib[n] ]);
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
if (!queue.length) {
|
|
1572
|
+
return null;
|
|
1573
|
+
}
|
|
1574
|
+
[path, lib] = queue.shift();
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
var nativeFuncs = new Map;
|
|
1579
|
+
|
|
1580
|
+
var isRaw = Symbol("isRaw");
|
|
1581
|
+
|
|
1582
|
+
var wellKnownSymbols;
|
|
1583
|
+
|
|
1584
|
+
function merge(target, ...sources) {
|
|
1585
|
+
for (let obj of sources) {
|
|
1586
|
+
if (obj) {
|
|
1587
|
+
for (let key of Object.keys(obj)) {
|
|
1588
|
+
if (obj[key] !== undefined) {
|
|
1589
|
+
target[key] = obj[key];
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
return target;
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
function jsSerialize(object, options) {
|
|
1598
|
+
return startSerialize(object, options).replace(/<\/(script)/gi, "<\\/$1");
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
function startSerialize(object, options) {
|
|
1602
|
+
const counts = referenceCount(object);
|
|
1603
|
+
let c = 0;
|
|
1604
|
+
const dupes = [ ...counts ].filter((x => x[1] > 1)).sort(((a, b) => b[1] - a[1])).map((x => [ x[0], `$${c++}` ]));
|
|
1605
|
+
const refs = new Map(dupes);
|
|
1606
|
+
let ctx = {
|
|
1607
|
+
seen: new Set,
|
|
1608
|
+
refs,
|
|
1609
|
+
opts: Object.freeze(merge({
|
|
1610
|
+
compact: false,
|
|
1611
|
+
safe: true
|
|
1612
|
+
}, options))
|
|
1613
|
+
};
|
|
1614
|
+
let js = serializeAny(object, ctx);
|
|
1615
|
+
if (dupes.length) {
|
|
1616
|
+
let varDecl = dupes.map((x => x[1])).join(",");
|
|
1617
|
+
if (dupes.length > 1) {
|
|
1618
|
+
varDecl = `(${varDecl})`;
|
|
1619
|
+
}
|
|
1620
|
+
if (js.startsWith("{")) {
|
|
1621
|
+
js = `(${js})`;
|
|
1622
|
+
}
|
|
1623
|
+
return `(${varDecl}=>${js})()`;
|
|
1624
|
+
}
|
|
1625
|
+
return js;
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
var STRING_REF_MIN_LENGTH = 12;
|
|
1629
|
+
|
|
1630
|
+
function referenceCount(object) {
|
|
1631
|
+
const m = new Map;
|
|
1632
|
+
function r(o) {
|
|
1633
|
+
let c = m.get(o);
|
|
1634
|
+
if (c) {
|
|
1635
|
+
m.set(o, c + 1);
|
|
1636
|
+
return;
|
|
1637
|
+
}
|
|
1638
|
+
if (isArray(o) || o instanceof Set) {
|
|
1639
|
+
m.set(o, 1);
|
|
1640
|
+
for (const v of o) {
|
|
1641
|
+
r(v);
|
|
1642
|
+
}
|
|
1643
|
+
} else if (isString(o)) {
|
|
1644
|
+
if (o.length >= STRING_REF_MIN_LENGTH) {
|
|
1645
|
+
m.set(o, 1);
|
|
1646
|
+
}
|
|
1647
|
+
} else if (o instanceof Map) {
|
|
1648
|
+
m.set(o, 1);
|
|
1649
|
+
for (const v of o.values()) {
|
|
1650
|
+
r(v);
|
|
1651
|
+
}
|
|
1652
|
+
} else if (isRegExp(o) || o instanceof Date || isSymbol(o) || isFunction(o)) {
|
|
1653
|
+
m.set(o, 1);
|
|
1654
|
+
} else if (isObject(o)) {
|
|
1655
|
+
m.set(o, 1);
|
|
1656
|
+
for (const k of Reflect.ownKeys(o)) {
|
|
1657
|
+
r(o[k]);
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
r(object);
|
|
1662
|
+
return m;
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
function isNegativeZero(value) {
|
|
1666
|
+
return 1 / value === -Infinity;
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
function serializeArray(obj, ctx) {
|
|
1670
|
+
const varName = ctx.refs.get(obj);
|
|
1671
|
+
const assign = varName ? `${varName}=` : "";
|
|
1672
|
+
if (obj.length === 0) {
|
|
1673
|
+
return `${assign}[]`;
|
|
1674
|
+
}
|
|
1675
|
+
let sb = [];
|
|
1676
|
+
let hasProp = false;
|
|
1677
|
+
let isSparse = false;
|
|
1678
|
+
for (let i = 0; i < obj.length; ++i) {
|
|
1679
|
+
if (obj.hasOwnProperty(i)) {
|
|
1680
|
+
hasProp = true;
|
|
1681
|
+
sb.push(serializeAny(obj[i], ctx));
|
|
1682
|
+
} else {
|
|
1683
|
+
isSparse = true;
|
|
1684
|
+
sb.push("");
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
if (!hasProp) {
|
|
1688
|
+
return `${assign}new Array(${obj.length})`;
|
|
1689
|
+
}
|
|
1690
|
+
if (sb[sb.length - 1] === "") {
|
|
1691
|
+
sb.push("");
|
|
1692
|
+
}
|
|
1693
|
+
const inner = sb.join(",");
|
|
1694
|
+
if (varName) {
|
|
1695
|
+
if (isSparse) {
|
|
1696
|
+
let sb2 = [ `(${varName}=new Array(${obj.length})` ];
|
|
1697
|
+
for (let i = 0; i < obj.length; ++i) {
|
|
1698
|
+
if (obj.hasOwnProperty(i)) {
|
|
1699
|
+
sb2.push(`${varName}[${i}]=${serializeAny(obj[i], ctx)}`);
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
sb2.push(`${varName})`);
|
|
1703
|
+
return sb2.join(",");
|
|
1704
|
+
}
|
|
1705
|
+
return `(${varName}=[],${varName}.push(${inner}),${varName})`;
|
|
1706
|
+
}
|
|
1707
|
+
return `[${inner}]`;
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
function serializeSet(obj, ctx) {
|
|
1711
|
+
const varName = ctx.refs.get(obj);
|
|
1712
|
+
if (obj.size) {
|
|
1713
|
+
if (varName) {
|
|
1714
|
+
return `(${varName}=new Set,${varName}` + Array.from(obj).map((x => `.add(${serializeAny(x, ctx)})`)).join("") + ")";
|
|
1715
|
+
}
|
|
1716
|
+
return "new Set(" + serializeAny(Array.from(obj), ctx) + ")";
|
|
1717
|
+
}
|
|
1718
|
+
if (varName) {
|
|
1719
|
+
return `${varName}=new Set`;
|
|
1720
|
+
}
|
|
1721
|
+
return "new Set";
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
function serializeMap(obj, ctx) {
|
|
1725
|
+
const varName = ctx.refs.get(obj);
|
|
1726
|
+
if (obj.size) {
|
|
1727
|
+
if (varName) {
|
|
1728
|
+
return `(${varName}=new Map,${varName}` + Array.from(obj).map((([k, v]) => `.set(${serializeAny(k, ctx)},${serializeAny(v, ctx)})`)).join("") + ")";
|
|
1729
|
+
}
|
|
1730
|
+
return "new Map(" + serializeAny(Array.from(obj), ctx) + ")";
|
|
1731
|
+
}
|
|
1732
|
+
if (varName) {
|
|
1733
|
+
return `${varName}=new Map`;
|
|
1734
|
+
}
|
|
1735
|
+
return "new Map";
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
function serializeDate(obj, ctx) {
|
|
1739
|
+
if (ctx.opts.compact) {
|
|
1740
|
+
return `new Date(${obj.valueOf()})`;
|
|
1741
|
+
}
|
|
1742
|
+
const parts = [ obj.getUTCFullYear(), obj.getUTCMonth(), obj.getUTCDate() ];
|
|
1743
|
+
if (+obj % 864e5 !== 0) {
|
|
1744
|
+
parts.push(obj.getUTCHours(), obj.getUTCMinutes(), obj.getUTCSeconds());
|
|
1745
|
+
const ms = obj.getUTCMilliseconds();
|
|
1746
|
+
if (ms) {
|
|
1747
|
+
parts.push(ms);
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
return `new Date(Date.UTC(${parts.join(",")}))`;
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
function wrapSimpleRef(serialize) {
|
|
1754
|
+
return (obj, ctx) => {
|
|
1755
|
+
const js = serialize(obj, ctx);
|
|
1756
|
+
const varName = ctx.refs.get(obj);
|
|
1757
|
+
if (varName) {
|
|
1758
|
+
ctx.seen.add(obj);
|
|
1759
|
+
return `${varName}=${js}`;
|
|
1760
|
+
}
|
|
1761
|
+
return js;
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1765
|
+
function serializeAnySymbol(obj, ctx) {
|
|
1766
|
+
if (!wellKnownSymbols) {
|
|
1767
|
+
wellKnownSymbols = new Map(Object.getOwnPropertyNames(Symbol).filter((k => isSymbol(Symbol[k]))).map((k => [ Symbol[k], k ])));
|
|
1768
|
+
}
|
|
1769
|
+
let symbolName = wellKnownSymbols.get(obj);
|
|
1770
|
+
if (symbolName) {
|
|
1771
|
+
return `Symbol.${symbolName}`;
|
|
1772
|
+
}
|
|
1773
|
+
return serializeSymbol(obj, ctx);
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
function serializeNativeFunction(obj, ctx) {
|
|
1777
|
+
let cachedPath = nativeFuncs.get(obj);
|
|
1778
|
+
if (cachedPath !== undefined) {
|
|
1779
|
+
return cachedPath;
|
|
1780
|
+
}
|
|
1781
|
+
const foundPath = findFunction(global, obj);
|
|
1782
|
+
if (foundPath === null) {
|
|
1783
|
+
throw new Error(`Could not determine fully-qualified name of native function '${obj.name}'`);
|
|
1784
|
+
}
|
|
1785
|
+
const joinedPath = foundPath.join(".");
|
|
1786
|
+
nativeFuncs.set(obj, joinedPath);
|
|
1787
|
+
return joinedPath;
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
function serializeNonNativeFunction(obj, ctx) {
|
|
1791
|
+
return obj.toString();
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
function serializeAnyFunction(obj, ctx) {
|
|
1795
|
+
if (/\{\s*\[native code]\s*}$/.test(obj.toString())) {
|
|
1796
|
+
return serializeNativeFunction(obj);
|
|
1797
|
+
}
|
|
1798
|
+
return serializeNonNativeFunction(obj);
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
function serializeBoolean(obj, ctx) {
|
|
1802
|
+
if (obj) {
|
|
1803
|
+
return ctx.opts.compact ? "!0" : "true";
|
|
1804
|
+
}
|
|
1805
|
+
return ctx.opts.compact ? "!1" : "false";
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
function serializeRegExp(obj, ctx) {
|
|
1809
|
+
return obj.toString();
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
function serializeUndefined(obj, ctx) {
|
|
1813
|
+
return ctx.opts.compact ? "void 0" : "undefined";
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
function serializeNull(obj, ctx) {
|
|
1817
|
+
return "null";
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
function maybeFreeze(obj, js) {
|
|
1821
|
+
if (Object.isFrozen(obj)) {
|
|
1822
|
+
return `Object.freeze(${js})`;
|
|
1823
|
+
}
|
|
1824
|
+
if (Object.isSealed(obj)) {
|
|
1825
|
+
return `Object.seal(${js})`;
|
|
1826
|
+
}
|
|
1827
|
+
if (!Object.isExtensible(obj)) {
|
|
1828
|
+
return `Object.preventExtensions(${js})`;
|
|
1829
|
+
}
|
|
1830
|
+
return js;
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
function serializeAnyObject(obj, ctx) {
|
|
1834
|
+
const tmp = serializeObject(obj, ctx);
|
|
1835
|
+
const name = ctx.refs.get(obj);
|
|
1836
|
+
if (name) {
|
|
1837
|
+
if (Reflect.ownKeys(obj).length) {
|
|
1838
|
+
return `(${name}={},${maybeFreeze(obj, `Object.assign(${name},${tmp})`)})`;
|
|
1839
|
+
}
|
|
1840
|
+
return `${name}=${maybeFreeze(obj, "{}")}`;
|
|
1841
|
+
}
|
|
1842
|
+
return maybeFreeze(obj, tmp);
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
function serializeAny(obj, ctx) {
|
|
1846
|
+
if (ctx.seen.has(obj) && ctx.refs.has(obj)) {
|
|
1847
|
+
return ctx.refs.get(obj);
|
|
1848
|
+
}
|
|
1849
|
+
if (isArray(obj)) {
|
|
1850
|
+
ctx.seen.add(obj);
|
|
1851
|
+
return serializeArray(obj, ctx);
|
|
1852
|
+
}
|
|
1853
|
+
if (obj instanceof Set) {
|
|
1854
|
+
ctx.seen.add(obj);
|
|
1855
|
+
return serializeSet(obj, ctx);
|
|
1856
|
+
}
|
|
1857
|
+
if (obj instanceof Map) {
|
|
1858
|
+
ctx.seen.add(obj);
|
|
1859
|
+
return serializeMap(obj, ctx);
|
|
1860
|
+
}
|
|
1861
|
+
if (obj instanceof Date) {
|
|
1862
|
+
return wrapSimpleRef(serializeDate)(obj, ctx);
|
|
1863
|
+
}
|
|
1864
|
+
if (isSymbol(obj)) {
|
|
1865
|
+
return wrapSimpleRef(serializeAnySymbol)(obj, ctx);
|
|
1866
|
+
}
|
|
1867
|
+
if (isFunction(obj)) {
|
|
1868
|
+
return wrapSimpleRef(serializeAnyFunction)(obj, ctx);
|
|
1869
|
+
}
|
|
1870
|
+
if (isRegExp(obj)) {
|
|
1871
|
+
return wrapSimpleRef(serializeRegExp)(obj, ctx);
|
|
1872
|
+
}
|
|
1873
|
+
if (isNumberLike(obj)) {
|
|
1874
|
+
return serializeNumberLike(obj, ctx);
|
|
1875
|
+
}
|
|
1876
|
+
if (isBigInt(obj)) {
|
|
1877
|
+
return serializeBigInt(obj, ctx);
|
|
1878
|
+
}
|
|
1879
|
+
if (isBoolean(obj)) {
|
|
1880
|
+
return serializeBoolean(obj, ctx);
|
|
1881
|
+
}
|
|
1882
|
+
if (isStringLike(obj)) {
|
|
1883
|
+
return serializeStringLike(obj, ctx);
|
|
1884
|
+
}
|
|
1885
|
+
if (obj === undefined) {
|
|
1886
|
+
return serializeUndefined(obj, ctx);
|
|
1887
|
+
}
|
|
1888
|
+
if (obj === null) {
|
|
1889
|
+
return serializeNull();
|
|
1890
|
+
}
|
|
1891
|
+
if (isObject(obj)) {
|
|
1892
|
+
ctx.seen.add(obj);
|
|
1893
|
+
return serializeAnyObject(obj, ctx);
|
|
1894
|
+
}
|
|
1895
|
+
throw new Error("Could not serialize unknown type");
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
function serializeNumberLike(obj, ctx) {
|
|
1899
|
+
const tmp = serializeNumber(Number(obj), ctx);
|
|
1900
|
+
if (obj instanceof Number) {
|
|
1901
|
+
return `new Number(${tmp})`;
|
|
1902
|
+
}
|
|
1903
|
+
return tmp;
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
function serializeNumber(obj, ctx) {
|
|
1907
|
+
switch (obj) {
|
|
1908
|
+
case Math.E:
|
|
1909
|
+
return "Math.E";
|
|
1910
|
+
|
|
1911
|
+
case Math.LN2:
|
|
1912
|
+
return "Math.LN2";
|
|
1913
|
+
|
|
1914
|
+
case Math.LN10:
|
|
1915
|
+
return "Math.LN10";
|
|
1916
|
+
|
|
1917
|
+
case Math.LOG2E:
|
|
1918
|
+
return "Math.LOG2E";
|
|
1919
|
+
|
|
1920
|
+
case Math.PI:
|
|
1921
|
+
return "Math.PI";
|
|
1922
|
+
|
|
1923
|
+
case Math.SQRT1_2:
|
|
1924
|
+
return "Math.SQRT1_2";
|
|
1925
|
+
|
|
1926
|
+
case Math.SQRT2:
|
|
1927
|
+
return "Math.SQRT2";
|
|
1928
|
+
|
|
1929
|
+
case Number.EPSILON:
|
|
1930
|
+
return "Number.EPSILON";
|
|
1931
|
+
|
|
1932
|
+
case Infinity:
|
|
1933
|
+
return ctx.opts.compact ? "1/0" : "Infinity";
|
|
1934
|
+
|
|
1935
|
+
case -Infinity:
|
|
1936
|
+
return ctx.opts.compact ? "1/-0" : "-Infinity";
|
|
1937
|
+
}
|
|
1938
|
+
if (isNegativeZero(obj)) return "-0";
|
|
1939
|
+
if (ctx.opts.compact && Number.isInteger(obj) && obj >= 1e12) {
|
|
1940
|
+
return "0x" + obj.toString(16);
|
|
1941
|
+
}
|
|
1942
|
+
return String(obj);
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
function serializeBigInt(obj, ctx) {
|
|
1946
|
+
if (ctx.opts.compact && obj >= 1000000000000n) {
|
|
1947
|
+
return "0x" + obj.toString(16) + "n";
|
|
1948
|
+
}
|
|
1949
|
+
return `${obj}n`;
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
function serializeStringLike(obj, ctx) {
|
|
1953
|
+
const js = doSerializeStringLike(obj, ctx);
|
|
1954
|
+
if (obj.length >= STRING_REF_MIN_LENGTH) {
|
|
1955
|
+
const varName = ctx.refs.get(obj);
|
|
1956
|
+
if (varName) {
|
|
1957
|
+
ctx.seen.add(obj);
|
|
1958
|
+
return `${varName}=${js}`;
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
return js;
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
function doSerializeStringLike(obj, ctx) {
|
|
1965
|
+
const tmp = serializeString(String(obj), ctx);
|
|
1966
|
+
if (obj instanceof String) {
|
|
1967
|
+
return `new String(${tmp})`;
|
|
1968
|
+
}
|
|
1969
|
+
return tmp;
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
function serializeString(obj, ctx) {
|
|
1973
|
+
return '"' + Array.from(obj).map((ch => {
|
|
1974
|
+
const cp = ch.codePointAt(0);
|
|
1975
|
+
switch (cp) {
|
|
1976
|
+
case 8:
|
|
1977
|
+
return "\\b";
|
|
1978
|
+
|
|
1979
|
+
case 12:
|
|
1980
|
+
return "\\f";
|
|
1981
|
+
|
|
1982
|
+
case 10:
|
|
1983
|
+
return "\\n";
|
|
1984
|
+
|
|
1985
|
+
case 13:
|
|
1986
|
+
return "\\r";
|
|
1987
|
+
|
|
1988
|
+
case 9:
|
|
1989
|
+
return "\\t";
|
|
1990
|
+
|
|
1991
|
+
case 11:
|
|
1992
|
+
return ctx.opts.safe ? "\\x0B" : "\\v";
|
|
1993
|
+
|
|
1994
|
+
case 34:
|
|
1995
|
+
return '\\"';
|
|
1996
|
+
|
|
1997
|
+
case 92:
|
|
1998
|
+
return "\\\\";
|
|
1999
|
+
}
|
|
2000
|
+
if (cp >= 32 && cp <= 126) {
|
|
2001
|
+
return ch;
|
|
2002
|
+
}
|
|
2003
|
+
if (cp <= 255) {
|
|
2004
|
+
return "\\x" + cp.toString(16).padStart(2, "0");
|
|
2005
|
+
}
|
|
2006
|
+
if (cp <= 65535) {
|
|
2007
|
+
return "\\u" + cp.toString(16).padStart(4, "0");
|
|
2008
|
+
}
|
|
2009
|
+
return "\\u{" + cp.toString(16) + "}";
|
|
2010
|
+
})).join("") + '"';
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
function serializeObject(obj, ctx) {
|
|
2014
|
+
if (obj[isRaw]) {
|
|
2015
|
+
return obj.value;
|
|
2016
|
+
}
|
|
2017
|
+
if (isFunction(obj.toSource)) {
|
|
2018
|
+
return obj.toSource();
|
|
2019
|
+
}
|
|
2020
|
+
if (isFunction(obj.toJSON)) {
|
|
2021
|
+
return serializeAny(obj.toJSON(), ctx);
|
|
2022
|
+
}
|
|
2023
|
+
return serializePlainObject(obj, ctx);
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
function serializePlainObject(obj, ctx) {
|
|
2027
|
+
let tmp = [];
|
|
2028
|
+
for (let key of Reflect.ownKeys(obj)) {
|
|
2029
|
+
tmp.push(serializePropertyName(key, ctx) + ":" + serializeAny(obj[key], ctx));
|
|
2030
|
+
}
|
|
2031
|
+
return "{" + tmp.join(",") + "}";
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
jsSerialize.raw = function raw(jsCode) {
|
|
2035
|
+
return Object.create({
|
|
2036
|
+
[isRaw]: true,
|
|
2037
|
+
value: jsCode
|
|
2038
|
+
});
|
|
2039
|
+
};
|
|
2040
|
+
|
|
2041
|
+
function serializeSymbol(sym, ctx) {
|
|
2042
|
+
let key = Symbol.keyFor(sym);
|
|
2043
|
+
if (key === undefined) {
|
|
2044
|
+
let m = sym.toString().match(/^Symbol\((.+)\)$/);
|
|
2045
|
+
if (m) {
|
|
2046
|
+
return `Symbol(${serializeString(m[1], ctx)})`;
|
|
2047
|
+
}
|
|
2048
|
+
return `Symbol()`;
|
|
2049
|
+
} else {
|
|
2050
|
+
return `Symbol.for(${serializeString(key, ctx)})`;
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
var keywords = new Set([ "do", "if", "in", "for", "let", "new", "try", "var", "case", "else", "enum", "eval", "false", "null", "this", "true", "void", "with", "break", "catch", "class", "const", "super", "throw", "while", "yield", "delete", "export", "import", "public", "return", "static", "switch", "typeof", "default", "extends", "finally", "package", "private", "continue", "debugger", "function", "arguments", "interface", "protected", "implements", "instanceof" ]);
|
|
2055
|
+
|
|
2056
|
+
var propName = /^[$_a-zA-Z][$_a-zA-Z0-9]*$/;
|
|
2057
|
+
|
|
2058
|
+
function isSafePropName(name, ctx) {
|
|
2059
|
+
return (!ctx.opts.safe || !keywords.has(name)) && propName.test(name);
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
function serializePropertyName(name, ctx) {
|
|
2063
|
+
if (isSymbol(name)) {
|
|
2064
|
+
return "[" + serializeSymbol(name, ctx) + "]";
|
|
2065
|
+
}
|
|
2066
|
+
if (isStringLike(name)) {
|
|
2067
|
+
if (isSafePropName(name, ctx)) {
|
|
2068
|
+
return name;
|
|
2069
|
+
}
|
|
2070
|
+
return serializeString(name, ctx);
|
|
2071
|
+
}
|
|
2072
|
+
throw new Error(`Cannot make property name`);
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
var src_default = jsSerialize;
|
|
2076
|
+
|
|
1485
2077
|
function mapIter(iterable, cb) {
|
|
1486
2078
|
const out = [];
|
|
1487
2079
|
let i = 0;
|
|
@@ -1531,7 +2123,7 @@ function scriptChild(el) {
|
|
|
1531
2123
|
if (isJsxNode(el)) {
|
|
1532
2124
|
throw new Error(`<script> cannot contain JSX nodes.`);
|
|
1533
2125
|
}
|
|
1534
|
-
return
|
|
2126
|
+
return src_default(el);
|
|
1535
2127
|
}
|
|
1536
2128
|
|
|
1537
2129
|
function styleChild(el) {
|
|
@@ -1542,19 +2134,19 @@ function styleChild(el) {
|
|
|
1542
2134
|
return "";
|
|
1543
2135
|
}
|
|
1544
2136
|
if (isJsxNode(el)) {
|
|
1545
|
-
throw new Error(`<
|
|
2137
|
+
throw new Error(`<style> cannot contain JSX nodes.`);
|
|
1546
2138
|
}
|
|
1547
|
-
return
|
|
2139
|
+
return cssEscape(String(el));
|
|
1548
2140
|
}
|
|
1549
2141
|
|
|
1550
2142
|
function flattenChildren(children, callback) {
|
|
1551
2143
|
return Array.isArray(children) ? children.map(callback).join("") : callback(children);
|
|
1552
2144
|
}
|
|
1553
2145
|
|
|
1554
|
-
const isJsxComponent = isFunction;
|
|
2146
|
+
const isJsxComponent = isFunction$1;
|
|
1555
2147
|
|
|
1556
2148
|
function isHtmlSafe(x) {
|
|
1557
|
-
return isPlainObject(x) && isString(x.__html);
|
|
2149
|
+
return isPlainObject(x) && isString$1(x.__html);
|
|
1558
2150
|
}
|
|
1559
2151
|
|
|
1560
2152
|
function render(el) {
|
|
@@ -1567,7 +2159,7 @@ function render(el) {
|
|
|
1567
2159
|
if (isHtmlSafe(el)) {
|
|
1568
2160
|
return el.__html;
|
|
1569
2161
|
}
|
|
1570
|
-
if (isString(el)) {
|
|
2162
|
+
if (isString$1(el)) {
|
|
1571
2163
|
return htmlContent(el);
|
|
1572
2164
|
}
|
|
1573
2165
|
if (isNumber(el)) {
|
|
@@ -1576,7 +2168,7 @@ function render(el) {
|
|
|
1576
2168
|
if (Array.isArray(el)) {
|
|
1577
2169
|
return el.map((x => render(x))).join("");
|
|
1578
2170
|
}
|
|
1579
|
-
if (isFunction(el)) {
|
|
2171
|
+
if (isFunction$1(el)) {
|
|
1580
2172
|
return render(el());
|
|
1581
2173
|
}
|
|
1582
2174
|
if (isIterable(el)) {
|
|
@@ -1585,6 +2177,37 @@ function render(el) {
|
|
|
1585
2177
|
throw new Error(`Unsupported type: ${getStringTag(el)}`);
|
|
1586
2178
|
}
|
|
1587
2179
|
|
|
2180
|
+
class JsFrag {
|
|
2181
|
+
str;
|
|
2182
|
+
constructor(str) {
|
|
2183
|
+
this.str = str;
|
|
2184
|
+
}
|
|
2185
|
+
toString() {
|
|
2186
|
+
return this.str;
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
function escapeJs(obj) {
|
|
2191
|
+
if (obj instanceof JsFrag) {
|
|
2192
|
+
return obj;
|
|
2193
|
+
}
|
|
2194
|
+
return src_default(obj);
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
function js(strings, ...values) {
|
|
2198
|
+
return new JsFrag(strings.reduce(((out, str, i) => out + str + (i < values.length ? escapeJs(values[i]) : "")), ""));
|
|
2199
|
+
}
|
|
2200
|
+
|
|
2201
|
+
class CssFrag {
|
|
2202
|
+
str;
|
|
2203
|
+
constructor(str) {
|
|
2204
|
+
this.str = str;
|
|
2205
|
+
}
|
|
2206
|
+
toString() {
|
|
2207
|
+
return this.str;
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
|
|
1588
2211
|
const voidElements = new Set([ "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr" ]);
|
|
1589
2212
|
|
|
1590
2213
|
class JsxElement extends JsxNode {
|
|
@@ -1613,10 +2236,10 @@ class JsxElement extends JsxNode {
|
|
|
1613
2236
|
return `<${tag}${attrs$1}></${tag}>`;
|
|
1614
2237
|
}
|
|
1615
2238
|
if (normalizedTagName === "script") {
|
|
1616
|
-
return `<${tag}${attrs$1}>${escapeScript(flattenChildren(children, scriptChild))}</${tag}>`;
|
|
2239
|
+
return `<${tag}${attrs$1}>${escapeScript(children instanceof JsFrag ? children.toString() : flattenChildren(children, scriptChild))}</${tag}>`;
|
|
1617
2240
|
}
|
|
1618
2241
|
if (normalizedTagName === "style") {
|
|
1619
|
-
return `<${tag}${attrs$1}>${escapeStyle(flattenChildren(children, styleChild))}</${tag}>`;
|
|
2242
|
+
return `<${tag}${attrs$1}>${escapeStyle(children instanceof CssFrag ? children.toString() : flattenChildren(children, styleChild))}</${tag}>`;
|
|
1620
2243
|
}
|
|
1621
2244
|
return `<${tag}${attrs$1}>${flattenChildren(children, render)}</${tag}>`;
|
|
1622
2245
|
}
|
|
@@ -1689,6 +2312,8 @@ class JsxFragment extends JsxNode {
|
|
|
1689
2312
|
}
|
|
1690
2313
|
}
|
|
1691
2314
|
|
|
2315
|
+
const JSX = {};
|
|
2316
|
+
|
|
1692
2317
|
function jsx(tag, props, key, isStaticChildren, source, self) {
|
|
1693
2318
|
if (isJsxComponent(tag)) {
|
|
1694
2319
|
const node = tag(props);
|
|
@@ -1711,4 +2336,4 @@ function Fragment({children}) {
|
|
|
1711
2336
|
return new JsxFragment(children);
|
|
1712
2337
|
}
|
|
1713
2338
|
|
|
1714
|
-
export { EMPTY as E, Fragment as F, JsxRawHtml as J, JsxDocType as a, jsx as b,
|
|
2339
|
+
export { EMPTY as E, Fragment as F, JsxRawHtml as J, JsxDocType as a, jsx as b, js as c, JsxElement as d, JsxComment as e, flattenString as f, JsxEmpty as g, JsxFragment as h, isJsxNode as i, jsxs as j, JsxNode as k, isJsxComponent as l, JSX as m };
|