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