@mpen/jsxhtml 0.1.23 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -0
- package/{custom-components.d.ts → dist/custom-components.d.ts} +3 -2
- package/dist/elysia-plugin.d.ts +27 -0
- package/{entityMap.d.ts → dist/entityMap.d.ts} +0 -0
- package/{escape.d.ts → dist/escape.d.ts} +2 -1
- package/{htmlspec → dist/htmlspec}/AnchorElement.d.ts +0 -0
- package/{htmlspec → dist/htmlspec}/GlobalAttributes.d.ts +0 -1
- package/{htmlspec → dist/htmlspec}/IntrinsicElements.d.ts +2 -2
- package/{index.cjs → dist/index.cjs} +4 -2
- package/{index.d.ts → dist/index.d.ts} +1 -1
- package/{index.mjs → dist/index.mjs} +3 -3
- package/{jsx-dev-runtime.cjs → dist/jsx-dev-runtime.cjs} +1 -1
- package/{jsx-dev-runtime.d.ts → dist/jsx-dev-runtime.d.ts} +1 -1
- package/{jsx-dev-runtime.mjs → dist/jsx-dev-runtime.mjs} +2 -2
- package/{jsx-elements.d.ts → dist/jsx-elements.d.ts} +1 -1
- package/{jsx-node.d.ts → dist/jsx-node.d.ts} +0 -0
- package/{jsx-runtime-6Dbtz0G4.js → dist/jsx-runtime-CsQM2fQb.js} +56 -31
- package/{jsx-runtime-zSLyeHpr.js → dist/jsx-runtime-DpEMYmD9.js} +57 -30
- package/{jsx-runtime.cjs → dist/jsx-runtime.cjs} +1 -1
- package/{jsx-runtime.d.ts → dist/jsx-runtime.d.ts} +2 -2
- package/dist/jsx-runtime.mjs +1 -0
- package/{jsx-types.d.ts → dist/jsx-types.d.ts} +3 -3
- package/{jsx.d.ts → dist/jsx.d.ts} +0 -0
- package/dist/render.d.ts +3 -0
- package/{styleObjectToString.d.ts → dist/styleObjectToString.d.ts} +0 -0
- package/{util-types.d.ts → dist/util-types.d.ts} +0 -0
- package/{util.d.ts → dist/util.d.ts} +5 -2
- package/package.json +64 -10
- package/dev.d.ts +0 -2
- package/elysia-plugin.d.ts +0 -7
- package/jsx-runtime.mjs +0 -1
- package/jsx.cjs +0 -1
- package/jsx.mjs +0 -1
- package/render.d.ts +0 -2
package/README.md
CHANGED
|
File without changes
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { DocTypeProps
|
|
2
|
-
import {
|
|
1
|
+
import type { DocTypeProps } from './jsx-elements';
|
|
2
|
+
import { JsxComment, JsxDocType, JsxRawHtml } from './jsx-elements';
|
|
3
|
+
import type { AnyAttributes, StringChildren } from './jsx-types';
|
|
3
4
|
/**
|
|
4
5
|
* Unescaped HTML.
|
|
5
6
|
*/
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Doesn't seem to work in newer versions of Elysia.
|
|
3
|
+
* Just add `.onAfterHandle` directly to your app.
|
|
4
|
+
* @see https://elysiajs.com/essential/life-cycle#interceptor-hook
|
|
5
|
+
*/
|
|
6
|
+
export declare function elysiaJsx(): import("elysia").default<"", {
|
|
7
|
+
decorator: {};
|
|
8
|
+
store: {};
|
|
9
|
+
derive: {};
|
|
10
|
+
resolve: {};
|
|
11
|
+
}, {
|
|
12
|
+
typebox: import("@sinclair/typebox").TModule<{}>;
|
|
13
|
+
error: {};
|
|
14
|
+
}, {
|
|
15
|
+
schema: {};
|
|
16
|
+
macro: {};
|
|
17
|
+
macroFn: {};
|
|
18
|
+
parser: {};
|
|
19
|
+
}, {}, {
|
|
20
|
+
derive: {};
|
|
21
|
+
resolve: {};
|
|
22
|
+
schema: {};
|
|
23
|
+
}, {
|
|
24
|
+
derive: {};
|
|
25
|
+
resolve: {};
|
|
26
|
+
schema: {};
|
|
27
|
+
}>;
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Attributes, AttributeValue, Stringable } from './jsx-types';
|
|
1
|
+
import type { Attributes, AttributeValue, Stringable } from './jsx-types';
|
|
2
2
|
export declare function tagName(string: Stringable): string;
|
|
3
3
|
export declare function attrName(string: Stringable): string;
|
|
4
4
|
export declare function attrValue(value: Stringable): string;
|
|
@@ -7,6 +7,7 @@ export declare function attrs(attributes: Attributes): string;
|
|
|
7
7
|
export declare function htmlContent(string: Stringable): string;
|
|
8
8
|
export declare function htmlComment(string: Stringable): string;
|
|
9
9
|
export declare function escapeScript(string: Stringable): string;
|
|
10
|
+
export declare function escapeStyle(string: Stringable): string;
|
|
10
11
|
/**
|
|
11
12
|
* Generic HTML escape. Works for both attribute values and HTML content.
|
|
12
13
|
*
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnyAttributes, CommonProps } from '../jsx-types';
|
|
2
|
-
import { AnchorElement } from './AnchorElement';
|
|
1
|
+
import type { AnyAttributes, CommonProps } from '../jsx-types';
|
|
2
|
+
import type { AnchorElement } from './AnchorElement';
|
|
3
3
|
export type IntrinsicElements = {
|
|
4
4
|
/**
|
|
5
5
|
* The <a> HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files,
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
var jsxRuntime = require("./jsx-runtime-
|
|
7
|
+
var jsxRuntime = require("./jsx-runtime-DpEMYmD9.js");
|
|
8
8
|
|
|
9
9
|
function RawHtml({children}) {
|
|
10
10
|
return new jsxRuntime.JsxRawHtml(jsxRuntime.flattenString(children));
|
|
@@ -41,7 +41,7 @@ function elysiaJsx() {
|
|
|
41
41
|
if (jsxRuntime.isJsxNode(response)) {
|
|
42
42
|
return new Response(String(response), {
|
|
43
43
|
headers: {
|
|
44
|
-
"content-type": "text/html; charset=
|
|
44
|
+
"content-type": "text/html; charset=utf-8"
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
}
|
|
@@ -75,6 +75,8 @@ exports.JsxEmpty = jsxRuntime.JsxEmpty;
|
|
|
75
75
|
|
|
76
76
|
exports.JsxFragment = jsxRuntime.JsxFragment;
|
|
77
77
|
|
|
78
|
+
exports.JsxNode = jsxRuntime.JsxNode;
|
|
79
|
+
|
|
78
80
|
exports.JsxRawHtml = jsxRuntime.JsxRawHtml;
|
|
79
81
|
|
|
80
82
|
exports.isJsxNode = jsxRuntime.isJsxNode;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './jsx-elements';
|
|
2
2
|
export * from './custom-components';
|
|
3
3
|
export * from './elysia-plugin';
|
|
4
|
-
export
|
|
4
|
+
export * from './jsx-node';
|
|
5
5
|
import type { AnyAttributes, JsxComponent, JsxRenderable } from './jsx-types';
|
|
6
6
|
import { Fragment as _Fragment } from './jsx-runtime';
|
|
7
7
|
declare namespace React {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { J as JsxRawHtml, f as flattenString, E as EMPTY, a as JsxDocType, j as jsxs, b as jsx, F as Fragment, i as isJsxNode } from "./jsx-runtime-CsQM2fQb.js";
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { d as JsxComment, c as JsxElement, e as JsxEmpty, g as JsxFragment, h as JsxNode } from "./jsx-runtime-CsQM2fQb.js";
|
|
4
4
|
|
|
5
5
|
function RawHtml({children}) {
|
|
6
6
|
return new JsxRawHtml(flattenString(children));
|
|
@@ -37,7 +37,7 @@ function elysiaJsx() {
|
|
|
37
37
|
if (isJsxNode(response)) {
|
|
38
38
|
return new Response(String(response), {
|
|
39
39
|
headers: {
|
|
40
|
-
"content-type": "text/html; charset=
|
|
40
|
+
"content-type": "text/html; charset=utf-8"
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
43
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { AnyAttributes, JsxComponent } from './jsx-types';
|
|
2
|
-
import { JsxNode } from './jsx-node';
|
|
2
|
+
import type { JsxNode } from './jsx-node';
|
|
3
3
|
export { jsx, Fragment } from './jsx-runtime';
|
|
4
4
|
export declare function jsxDEV(tag: string | JsxComponent, props: AnyAttributes, key: unknown, isStaticChildren: unknown, source: unknown, self: unknown): JsxNode;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as jsx, k as isJsxComponent, d as JsxComment, g as JsxFragment } from "./jsx-runtime-CsQM2fQb.js";
|
|
2
2
|
|
|
3
|
-
export { F as Fragment } from "./jsx-runtime-
|
|
3
|
+
export { F as Fragment } from "./jsx-runtime-CsQM2fQb.js";
|
|
4
4
|
|
|
5
5
|
function jsxDEV(tag, props, key, isStaticChildren, source, self) {
|
|
6
6
|
let node = jsx(...arguments);
|
|
File without changes
|
|
@@ -1363,18 +1363,6 @@ function isString(obj) {
|
|
|
1363
1363
|
return typeof obj === "string";
|
|
1364
1364
|
}
|
|
1365
1365
|
|
|
1366
|
-
var isFunction_1 = isFunction;
|
|
1367
|
-
|
|
1368
|
-
var isIterable_1 = isIterable;
|
|
1369
|
-
|
|
1370
|
-
var isNumber_1 = isNumber;
|
|
1371
|
-
|
|
1372
|
-
var isObject_1 = isObject;
|
|
1373
|
-
|
|
1374
|
-
var isPlainObject_1 = isPlainObject;
|
|
1375
|
-
|
|
1376
|
-
var isString_1 = isString;
|
|
1377
|
-
|
|
1378
1366
|
const uppercasePattern = /([A-Z])/g;
|
|
1379
1367
|
|
|
1380
1368
|
const msPattern = /^ms-/;
|
|
@@ -1438,7 +1426,7 @@ function attrName(string) {
|
|
|
1438
1426
|
}
|
|
1439
1427
|
|
|
1440
1428
|
function attrValue(value) {
|
|
1441
|
-
if (
|
|
1429
|
+
if (isFunction(value)) {
|
|
1442
1430
|
value = `(${value}).call(this)`;
|
|
1443
1431
|
}
|
|
1444
1432
|
return `"${String(value).replace(/"/gu, entity)}"`;
|
|
@@ -1446,7 +1434,7 @@ function attrValue(value) {
|
|
|
1446
1434
|
|
|
1447
1435
|
function attrKvPair(rawAttr, rawVal) {
|
|
1448
1436
|
let escAttr = attrName(rawAttr);
|
|
1449
|
-
if (/^data-/.test(rawAttr) && !
|
|
1437
|
+
if (/^data-/.test(rawAttr) && !isString(rawVal)) {
|
|
1450
1438
|
rawVal = JSON.stringify(rawVal);
|
|
1451
1439
|
}
|
|
1452
1440
|
if (rawVal === true) {
|
|
@@ -1455,10 +1443,10 @@ function attrKvPair(rawAttr, rawVal) {
|
|
|
1455
1443
|
if (rawVal === false || rawVal == null) {
|
|
1456
1444
|
return null;
|
|
1457
1445
|
}
|
|
1458
|
-
if (rawAttr === "class" && !
|
|
1446
|
+
if (rawAttr === "class" && !isString(rawVal)) {
|
|
1459
1447
|
rawVal = cc(rawVal);
|
|
1460
1448
|
}
|
|
1461
|
-
if (rawAttr === "style" &&
|
|
1449
|
+
if (rawAttr === "style" && isPlainObject(rawVal)) {
|
|
1462
1450
|
rawVal = styleObjectToString(rawVal);
|
|
1463
1451
|
}
|
|
1464
1452
|
return `${escAttr}=${attrValue(rawVal)}`;
|
|
@@ -1466,7 +1454,7 @@ function attrKvPair(rawAttr, rawVal) {
|
|
|
1466
1454
|
|
|
1467
1455
|
function attrs(attributes) {
|
|
1468
1456
|
if (attributes == null) return "";
|
|
1469
|
-
if (
|
|
1457
|
+
if (isObject(attributes)) {
|
|
1470
1458
|
attributes = Object.entries(attributes);
|
|
1471
1459
|
}
|
|
1472
1460
|
return attributes.map((([k, v]) => attrKvPair(k, v))).filter((x => x)).map((x => ` ${x}`)).join("");
|
|
@@ -1484,6 +1472,16 @@ function escapeScript(string) {
|
|
|
1484
1472
|
return String(string).replace(/<\/(script)/giu, "<\\/$1");
|
|
1485
1473
|
}
|
|
1486
1474
|
|
|
1475
|
+
function escapeStyle(string) {
|
|
1476
|
+
return String(string).replace(/<\/(style)/giu, "<\\/$1");
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
class JsxNode {}
|
|
1480
|
+
|
|
1481
|
+
function isJsxNode(x) {
|
|
1482
|
+
return x instanceof JsxNode;
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1487
1485
|
function mapIter(iterable, cb) {
|
|
1488
1486
|
const out = [];
|
|
1489
1487
|
let i = 0;
|
|
@@ -1505,7 +1503,7 @@ function isEmptyChildren(children) {
|
|
|
1505
1503
|
}
|
|
1506
1504
|
|
|
1507
1505
|
function isEmptyRender(el) {
|
|
1508
|
-
return el
|
|
1506
|
+
return el == null || el === false;
|
|
1509
1507
|
}
|
|
1510
1508
|
|
|
1511
1509
|
function fullWide(n) {
|
|
@@ -1520,19 +1518,43 @@ function fullWide(n) {
|
|
|
1520
1518
|
}
|
|
1521
1519
|
|
|
1522
1520
|
function flattenString(content, sep = "") {
|
|
1523
|
-
return
|
|
1521
|
+
return isIterable(content) ? Array.from(content).join(sep) : String(content);
|
|
1524
1522
|
}
|
|
1525
1523
|
|
|
1526
|
-
|
|
1524
|
+
function scriptChild(el) {
|
|
1525
|
+
if (typeof el === "string") {
|
|
1526
|
+
return el;
|
|
1527
|
+
}
|
|
1528
|
+
if (isEmptyRender(el)) {
|
|
1529
|
+
return "";
|
|
1530
|
+
}
|
|
1531
|
+
if (isJsxNode(el)) {
|
|
1532
|
+
throw new Error(`<script> cannot contain JSX nodes.`);
|
|
1533
|
+
}
|
|
1534
|
+
return JSON.stringify(el);
|
|
1535
|
+
}
|
|
1527
1536
|
|
|
1528
|
-
|
|
1537
|
+
function styleChild(el) {
|
|
1538
|
+
if (typeof el === "string") {
|
|
1539
|
+
return el;
|
|
1540
|
+
}
|
|
1541
|
+
if (isEmptyRender(el)) {
|
|
1542
|
+
return "";
|
|
1543
|
+
}
|
|
1544
|
+
if (isJsxNode(el)) {
|
|
1545
|
+
throw new Error(`<sty;e> cannot contain JSX nodes.`);
|
|
1546
|
+
}
|
|
1547
|
+
return CSS.escape(String(el));
|
|
1548
|
+
}
|
|
1529
1549
|
|
|
1530
|
-
function
|
|
1531
|
-
return
|
|
1550
|
+
function flattenChildren(children, callback) {
|
|
1551
|
+
return Array.isArray(children) ? children.map(callback).join("") : callback(children);
|
|
1532
1552
|
}
|
|
1533
1553
|
|
|
1554
|
+
const isJsxComponent = isFunction;
|
|
1555
|
+
|
|
1534
1556
|
function isHtmlSafe(x) {
|
|
1535
|
-
return
|
|
1557
|
+
return isPlainObject(x) && isString(x.__html);
|
|
1536
1558
|
}
|
|
1537
1559
|
|
|
1538
1560
|
function render(el) {
|
|
@@ -1545,19 +1567,19 @@ function render(el) {
|
|
|
1545
1567
|
if (isHtmlSafe(el)) {
|
|
1546
1568
|
return el.__html;
|
|
1547
1569
|
}
|
|
1548
|
-
if (
|
|
1570
|
+
if (isString(el)) {
|
|
1549
1571
|
return htmlContent(el);
|
|
1550
1572
|
}
|
|
1551
|
-
if (
|
|
1573
|
+
if (isNumber(el)) {
|
|
1552
1574
|
return fullWide(el);
|
|
1553
1575
|
}
|
|
1554
1576
|
if (Array.isArray(el)) {
|
|
1555
1577
|
return el.map((x => render(x))).join("");
|
|
1556
1578
|
}
|
|
1557
|
-
if (
|
|
1579
|
+
if (isFunction(el)) {
|
|
1558
1580
|
return render(el());
|
|
1559
1581
|
}
|
|
1560
|
-
if (
|
|
1582
|
+
if (isIterable(el)) {
|
|
1561
1583
|
return mapIter(el, (x => render(x))).join("");
|
|
1562
1584
|
}
|
|
1563
1585
|
throw new Error(`Unsupported type: ${getStringTag(el)}`);
|
|
@@ -1591,9 +1613,12 @@ class JsxElement extends JsxNode {
|
|
|
1591
1613
|
return `<${tag}${attrs$1}></${tag}>`;
|
|
1592
1614
|
}
|
|
1593
1615
|
if (normalizedTagName === "script") {
|
|
1594
|
-
return `<${tag}${attrs$1}>${escapeScript(
|
|
1616
|
+
return `<${tag}${attrs$1}>${escapeScript(flattenChildren(children, scriptChild))}</${tag}>`;
|
|
1617
|
+
}
|
|
1618
|
+
if (normalizedTagName === "style") {
|
|
1619
|
+
return `<${tag}${attrs$1}>${escapeStyle(flattenChildren(children, styleChild))}</${tag}>`;
|
|
1595
1620
|
}
|
|
1596
|
-
return `<${tag}${attrs$1}>${
|
|
1621
|
+
return `<${tag}${attrs$1}>${flattenChildren(children, render)}</${tag}>`;
|
|
1597
1622
|
}
|
|
1598
1623
|
}
|
|
1599
1624
|
|
|
@@ -1686,4 +1711,4 @@ function Fragment({children}) {
|
|
|
1686
1711
|
return new JsxFragment(children);
|
|
1687
1712
|
}
|
|
1688
1713
|
|
|
1689
|
-
export { EMPTY as E, Fragment as F,
|
|
1714
|
+
export { EMPTY as E, Fragment as F, JsxRawHtml as J, JsxDocType as a, jsx as b, JsxElement as c, JsxComment as d, JsxEmpty as e, flattenString as f, JsxFragment as g, JsxNode as h, isJsxNode as i, jsxs as j, isJsxComponent as k };
|
|
@@ -1365,18 +1365,6 @@ function isString(obj) {
|
|
|
1365
1365
|
return typeof obj === "string";
|
|
1366
1366
|
}
|
|
1367
1367
|
|
|
1368
|
-
var isFunction_1 = isFunction;
|
|
1369
|
-
|
|
1370
|
-
var isIterable_1 = isIterable;
|
|
1371
|
-
|
|
1372
|
-
var isNumber_1 = isNumber;
|
|
1373
|
-
|
|
1374
|
-
var isObject_1 = isObject;
|
|
1375
|
-
|
|
1376
|
-
var isPlainObject_1 = isPlainObject;
|
|
1377
|
-
|
|
1378
|
-
var isString_1 = isString;
|
|
1379
|
-
|
|
1380
1368
|
const uppercasePattern = /([A-Z])/g;
|
|
1381
1369
|
|
|
1382
1370
|
const msPattern = /^ms-/;
|
|
@@ -1440,7 +1428,7 @@ function attrName(string) {
|
|
|
1440
1428
|
}
|
|
1441
1429
|
|
|
1442
1430
|
function attrValue(value) {
|
|
1443
|
-
if (
|
|
1431
|
+
if (isFunction(value)) {
|
|
1444
1432
|
value = `(${value}).call(this)`;
|
|
1445
1433
|
}
|
|
1446
1434
|
return `"${String(value).replace(/"/gu, entity)}"`;
|
|
@@ -1448,7 +1436,7 @@ function attrValue(value) {
|
|
|
1448
1436
|
|
|
1449
1437
|
function attrKvPair(rawAttr, rawVal) {
|
|
1450
1438
|
let escAttr = attrName(rawAttr);
|
|
1451
|
-
if (/^data-/.test(rawAttr) && !
|
|
1439
|
+
if (/^data-/.test(rawAttr) && !isString(rawVal)) {
|
|
1452
1440
|
rawVal = JSON.stringify(rawVal);
|
|
1453
1441
|
}
|
|
1454
1442
|
if (rawVal === true) {
|
|
@@ -1457,10 +1445,10 @@ function attrKvPair(rawAttr, rawVal) {
|
|
|
1457
1445
|
if (rawVal === false || rawVal == null) {
|
|
1458
1446
|
return null;
|
|
1459
1447
|
}
|
|
1460
|
-
if (rawAttr === "class" && !
|
|
1448
|
+
if (rawAttr === "class" && !isString(rawVal)) {
|
|
1461
1449
|
rawVal = cc(rawVal);
|
|
1462
1450
|
}
|
|
1463
|
-
if (rawAttr === "style" &&
|
|
1451
|
+
if (rawAttr === "style" && isPlainObject(rawVal)) {
|
|
1464
1452
|
rawVal = styleObjectToString(rawVal);
|
|
1465
1453
|
}
|
|
1466
1454
|
return `${escAttr}=${attrValue(rawVal)}`;
|
|
@@ -1468,7 +1456,7 @@ function attrKvPair(rawAttr, rawVal) {
|
|
|
1468
1456
|
|
|
1469
1457
|
function attrs(attributes) {
|
|
1470
1458
|
if (attributes == null) return "";
|
|
1471
|
-
if (
|
|
1459
|
+
if (isObject(attributes)) {
|
|
1472
1460
|
attributes = Object.entries(attributes);
|
|
1473
1461
|
}
|
|
1474
1462
|
return attributes.map((([k, v]) => attrKvPair(k, v))).filter((x => x)).map((x => ` ${x}`)).join("");
|
|
@@ -1486,6 +1474,16 @@ function escapeScript(string) {
|
|
|
1486
1474
|
return String(string).replace(/<\/(script)/giu, "<\\/$1");
|
|
1487
1475
|
}
|
|
1488
1476
|
|
|
1477
|
+
function escapeStyle(string) {
|
|
1478
|
+
return String(string).replace(/<\/(style)/giu, "<\\/$1");
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
class JsxNode {}
|
|
1482
|
+
|
|
1483
|
+
function isJsxNode(x) {
|
|
1484
|
+
return x instanceof JsxNode;
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1489
1487
|
function mapIter(iterable, cb) {
|
|
1490
1488
|
const out = [];
|
|
1491
1489
|
let i = 0;
|
|
@@ -1507,7 +1505,7 @@ function isEmptyChildren(children) {
|
|
|
1507
1505
|
}
|
|
1508
1506
|
|
|
1509
1507
|
function isEmptyRender(el) {
|
|
1510
|
-
return el
|
|
1508
|
+
return el == null || el === false;
|
|
1511
1509
|
}
|
|
1512
1510
|
|
|
1513
1511
|
function fullWide(n) {
|
|
@@ -1522,19 +1520,43 @@ function fullWide(n) {
|
|
|
1522
1520
|
}
|
|
1523
1521
|
|
|
1524
1522
|
function flattenString(content, sep = "") {
|
|
1525
|
-
return
|
|
1523
|
+
return isIterable(content) ? Array.from(content).join(sep) : String(content);
|
|
1526
1524
|
}
|
|
1527
1525
|
|
|
1528
|
-
|
|
1526
|
+
function scriptChild(el) {
|
|
1527
|
+
if (typeof el === "string") {
|
|
1528
|
+
return el;
|
|
1529
|
+
}
|
|
1530
|
+
if (isEmptyRender(el)) {
|
|
1531
|
+
return "";
|
|
1532
|
+
}
|
|
1533
|
+
if (isJsxNode(el)) {
|
|
1534
|
+
throw new Error(`<script> cannot contain JSX nodes.`);
|
|
1535
|
+
}
|
|
1536
|
+
return JSON.stringify(el);
|
|
1537
|
+
}
|
|
1529
1538
|
|
|
1530
|
-
|
|
1539
|
+
function styleChild(el) {
|
|
1540
|
+
if (typeof el === "string") {
|
|
1541
|
+
return el;
|
|
1542
|
+
}
|
|
1543
|
+
if (isEmptyRender(el)) {
|
|
1544
|
+
return "";
|
|
1545
|
+
}
|
|
1546
|
+
if (isJsxNode(el)) {
|
|
1547
|
+
throw new Error(`<sty;e> cannot contain JSX nodes.`);
|
|
1548
|
+
}
|
|
1549
|
+
return CSS.escape(String(el));
|
|
1550
|
+
}
|
|
1531
1551
|
|
|
1532
|
-
function
|
|
1533
|
-
return
|
|
1552
|
+
function flattenChildren(children, callback) {
|
|
1553
|
+
return Array.isArray(children) ? children.map(callback).join("") : callback(children);
|
|
1534
1554
|
}
|
|
1535
1555
|
|
|
1556
|
+
const isJsxComponent = isFunction;
|
|
1557
|
+
|
|
1536
1558
|
function isHtmlSafe(x) {
|
|
1537
|
-
return
|
|
1559
|
+
return isPlainObject(x) && isString(x.__html);
|
|
1538
1560
|
}
|
|
1539
1561
|
|
|
1540
1562
|
function render(el) {
|
|
@@ -1547,19 +1569,19 @@ function render(el) {
|
|
|
1547
1569
|
if (isHtmlSafe(el)) {
|
|
1548
1570
|
return el.__html;
|
|
1549
1571
|
}
|
|
1550
|
-
if (
|
|
1572
|
+
if (isString(el)) {
|
|
1551
1573
|
return htmlContent(el);
|
|
1552
1574
|
}
|
|
1553
|
-
if (
|
|
1575
|
+
if (isNumber(el)) {
|
|
1554
1576
|
return fullWide(el);
|
|
1555
1577
|
}
|
|
1556
1578
|
if (Array.isArray(el)) {
|
|
1557
1579
|
return el.map((x => render(x))).join("");
|
|
1558
1580
|
}
|
|
1559
|
-
if (
|
|
1581
|
+
if (isFunction(el)) {
|
|
1560
1582
|
return render(el());
|
|
1561
1583
|
}
|
|
1562
|
-
if (
|
|
1584
|
+
if (isIterable(el)) {
|
|
1563
1585
|
return mapIter(el, (x => render(x))).join("");
|
|
1564
1586
|
}
|
|
1565
1587
|
throw new Error(`Unsupported type: ${getStringTag(el)}`);
|
|
@@ -1593,9 +1615,12 @@ class JsxElement extends JsxNode {
|
|
|
1593
1615
|
return `<${tag}${attrs$1}></${tag}>`;
|
|
1594
1616
|
}
|
|
1595
1617
|
if (normalizedTagName === "script") {
|
|
1596
|
-
return `<${tag}${attrs$1}>${escapeScript(
|
|
1618
|
+
return `<${tag}${attrs$1}>${escapeScript(flattenChildren(children, scriptChild))}</${tag}>`;
|
|
1597
1619
|
}
|
|
1598
|
-
|
|
1620
|
+
if (normalizedTagName === "style") {
|
|
1621
|
+
return `<${tag}${attrs$1}>${escapeStyle(flattenChildren(children, styleChild))}</${tag}>`;
|
|
1622
|
+
}
|
|
1623
|
+
return `<${tag}${attrs$1}>${flattenChildren(children, render)}</${tag}>`;
|
|
1599
1624
|
}
|
|
1600
1625
|
}
|
|
1601
1626
|
|
|
@@ -1702,6 +1727,8 @@ exports.JsxEmpty = JsxEmpty;
|
|
|
1702
1727
|
|
|
1703
1728
|
exports.JsxFragment = JsxFragment;
|
|
1704
1729
|
|
|
1730
|
+
exports.JsxNode = JsxNode;
|
|
1731
|
+
|
|
1705
1732
|
exports.JsxRawHtml = JsxRawHtml;
|
|
1706
1733
|
|
|
1707
1734
|
exports.flattenString = flattenString;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { JsxComponent, AnyAttributes, ChildrenOnly } from './jsx-types';
|
|
1
|
+
import type { JsxComponent, AnyAttributes, ChildrenOnly } from './jsx-types';
|
|
2
2
|
import { JsxFragment } from './jsx-elements';
|
|
3
|
-
import { JsxNode } from './jsx-node';
|
|
3
|
+
import type { JsxNode } from './jsx-node';
|
|
4
4
|
export declare function jsx(tag: string | JsxComponent, props: AnyAttributes, key?: unknown, isStaticChildren?: unknown, source?: unknown, self?: unknown): JsxNode;
|
|
5
5
|
export declare function jsxs(...args: Parameters<typeof jsx>): JsxNode;
|
|
6
6
|
export declare function Fragment({ children }: ChildrenOnly): JsxFragment;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { F as Fragment, b as jsx, j as jsxs } from "./jsx-runtime-CsQM2fQb.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { JsxNode } from './jsx-node';
|
|
2
|
-
import { AllGlobalAttributes } from './htmlspec/GlobalAttributes';
|
|
3
|
-
import { Override } from './util-types';
|
|
1
|
+
import type { JsxNode } from './jsx-node';
|
|
2
|
+
import type { AllGlobalAttributes } from './htmlspec/GlobalAttributes';
|
|
3
|
+
import type { Override } from './util-types';
|
|
4
4
|
export interface Stringable {
|
|
5
5
|
toString(): string;
|
|
6
6
|
}
|
|
File without changes
|
package/dist/render.d.ts
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { FlatString, JsxChildren, JsxComponent } from './jsx-types';
|
|
1
|
+
import type { FlatString, JsxChildren, JsxComponent } from './jsx-types';
|
|
2
2
|
export declare function mapIter<In, Out>(iterable: Iterable<In>, cb: (el: In, i: number) => Out): Out[];
|
|
3
3
|
export declare function getStringTag(value: any): string;
|
|
4
4
|
export declare function isEmptyChildren(children: JsxChildren): boolean;
|
|
5
5
|
export declare function isEmptyRender(el: any): boolean;
|
|
6
6
|
export declare function fullWide(n: number): string;
|
|
7
7
|
export declare function flattenString(content: FlatString, sep?: string): string;
|
|
8
|
-
export declare
|
|
8
|
+
export declare function scriptChild(el: any): string;
|
|
9
|
+
export declare function styleChild(el: any): string;
|
|
10
|
+
export declare function flattenChildren(children: any | any[], callback: (el: any) => string): string;
|
|
11
|
+
export declare const isJsxComponent: ((x: any) => x is JsxComponent);
|
package/package.json
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpen/jsxhtml",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"packageManager": "bun@1.
|
|
5
|
-
"main": "./index.cjs",
|
|
6
|
-
"module": "./index.mjs",
|
|
7
|
-
"types": "./index.d.ts",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"packageManager": "bun@1.2.9",
|
|
8
5
|
"exports": {
|
|
9
|
-
".":
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
".": {
|
|
7
|
+
"import": "./dist/index.mjs",
|
|
8
|
+
"require": "./dist/index.cjs",
|
|
9
|
+
"types": "./dist/index.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"./jsx-runtime": {
|
|
12
|
+
"import": "./dist/jsx-runtime.mjs",
|
|
13
|
+
"require": "./dist/jsx-runtime.cjs",
|
|
14
|
+
"types": "./dist/jsx-runtime.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./jsx-dev-runtime": {
|
|
17
|
+
"import": "./dist/jsx-dev-runtime.mjs",
|
|
18
|
+
"require": "./dist/jsx-dev-runtime.cjs",
|
|
19
|
+
"types": "./dist/jsx-dev-runtime.d.ts"
|
|
20
|
+
}
|
|
12
21
|
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"private": false,
|
|
13
27
|
"sideEffects": false,
|
|
14
28
|
"author": {
|
|
15
29
|
"name": "Mark Penner",
|
|
@@ -23,10 +37,50 @@
|
|
|
23
37
|
"server-side",
|
|
24
38
|
"elysia"
|
|
25
39
|
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"dev:build": "rollup -cw",
|
|
42
|
+
"_dev:serve": "serve -l tcp://0.0.0.0:8080",
|
|
43
|
+
"dev": "run-p \"dev:**\"",
|
|
44
|
+
"dev:serve": "bun run --hot src/dev.tsx",
|
|
45
|
+
"test": "bun test",
|
|
46
|
+
"bundle:clean": "rm -rf dist/",
|
|
47
|
+
"bundle:build": "NODE_ENV=production rollup -c",
|
|
48
|
+
"bundle": "run-s bundle:clean bundle:build",
|
|
49
|
+
"commit": "VER=$(jq -r '.version' package.json) && hg ci -m \"Commit v$VER\" && hg tag \"v$VER\"",
|
|
50
|
+
"bumpver": "npm version patch",
|
|
51
|
+
"release": "run-s test bundle bumpver commit && npm publish --access=public && hg pushall",
|
|
52
|
+
"lint": "sh -c 'eslint --quiet --fix --fix-type problem,suggestion,layout,directive -- \"${@:-.}\"' --"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@mpen/is-type": "^0.1.15",
|
|
56
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
57
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
58
|
+
"@rollup/plugin-replace": "^5.0.7",
|
|
59
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
60
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
61
|
+
"@types/eslint": "^8.56.12",
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^8.29.1",
|
|
63
|
+
"@typescript-eslint/parser": "^8.29.1",
|
|
64
|
+
"bun-types": "^1.2.9",
|
|
65
|
+
"classnames": "^2.5.1",
|
|
66
|
+
"csstype": "^3.1.3",
|
|
67
|
+
"elysia": ">=1.2.25",
|
|
68
|
+
"eslint": "^8.57.1",
|
|
69
|
+
"eslint-plugin-react-compiler": "^19.0.0-beta-e993439-20250405",
|
|
70
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
71
|
+
"eslint-plugin-react-refresh": "^0.4.19",
|
|
72
|
+
"eslint-plugin-unused-imports": "^4.1.4",
|
|
73
|
+
"npm-run-all": "^4.1.5",
|
|
74
|
+
"rimraf": "^5.0.10",
|
|
75
|
+
"rollup": "^4.40.0",
|
|
76
|
+
"serve": "^14.2.4",
|
|
77
|
+
"tslib": "^2.8.1",
|
|
78
|
+
"typescript": "^5.8.3"
|
|
79
|
+
},
|
|
26
80
|
"optionalDependencies": {
|
|
27
|
-
"elysia": ">=
|
|
81
|
+
"elysia": ">=1.2.25"
|
|
28
82
|
},
|
|
29
83
|
"dependencies": {
|
|
30
|
-
"classcat": "^5.0.
|
|
84
|
+
"classcat": "^5.0.5"
|
|
31
85
|
}
|
|
32
86
|
}
|
package/dev.d.ts
DELETED
package/elysia-plugin.d.ts
DELETED
package/jsx-runtime.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { F as Fragment, j as jsx, d as jsxs } from "./jsx-runtime-6Dbtz0G4.js";
|
package/jsx.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/jsx.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/render.d.ts
DELETED