ilha 0.13.0 → 0.14.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/README.md +97 -285
- package/dist/define.d.ts +5 -0
- package/dist/define.js +18 -0
- package/dist/index.d.ts +35 -2
- package/dist/index.js +51 -3209
- package/dist/jsx-dev-runtime.d.ts +4 -2
- package/dist/jsx-dev-runtime.js +3 -2
- package/dist/jsx-runtime.d.ts +8 -2
- package/dist/jsx-runtime.js +11 -2
- package/dist/mount-Dcy4teaf.js +992 -0
- package/dist/types-DU46exHq.d.ts +33 -0
- package/dist/vnode-BZLcG8lC.d.ts +20 -0
- package/dist/vnode-DHN2EFHi.js +37 -0
- package/package.json +19 -15
- package/dist/index-CVOjC94p.d.ts +0 -395
- package/dist/internal.d.ts +0 -77
- package/dist/internal.js +0 -62
- package/dist/jsx-runtime-CzU-60tX.d.ts +0 -631
- package/dist/jsx-runtime-DreKruAt.js +0 -124
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { __ilhaJsxSlot, __ilhaRenderTemplate } from "./internal.js";
|
|
2
|
-
import { raw } from "./index.js";
|
|
3
|
-
|
|
4
|
-
//#region src/template.ts
|
|
5
|
-
function elementTemplate(tag, props, children) {
|
|
6
|
-
const attrs = { ...props };
|
|
7
|
-
delete attrs.children;
|
|
8
|
-
return {
|
|
9
|
-
kind: "element",
|
|
10
|
-
tag,
|
|
11
|
-
props: attrs,
|
|
12
|
-
children: children.flat(Infinity).map((value) => ({
|
|
13
|
-
kind: "dynamic",
|
|
14
|
-
value
|
|
15
|
-
}))
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function fragmentTemplate(children) {
|
|
19
|
-
return {
|
|
20
|
-
kind: "fragment",
|
|
21
|
-
children: children.flat(Infinity).map((value) => ({
|
|
22
|
-
kind: "dynamic",
|
|
23
|
-
value
|
|
24
|
-
}))
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region src/jsx-runtime.ts
|
|
30
|
-
const RAW = Symbol.for("ilha.raw");
|
|
31
|
-
const ISLAND = Symbol.for("ilha.island");
|
|
32
|
-
const ISLAND_CALL = Symbol.for("ilha.islandCall");
|
|
33
|
-
const RENDER_PART = Symbol.for("ilha.renderPart");
|
|
34
|
-
function isRawHtml(v) {
|
|
35
|
-
return !!(v && typeof v === "object" && RAW in v);
|
|
36
|
-
}
|
|
37
|
-
function isIsland(v) {
|
|
38
|
-
return typeof v === "function" && ISLAND in v;
|
|
39
|
-
}
|
|
40
|
-
function isIslandCall(v) {
|
|
41
|
-
if (v == null || typeof v !== "object" && typeof v !== "function") return false;
|
|
42
|
-
if (ISLAND_CALL in v) return true;
|
|
43
|
-
return typeof v === "object" && "island" in v && isIsland(v.island);
|
|
44
|
-
}
|
|
45
|
-
function normalizeJsxChildren(props, children) {
|
|
46
|
-
const propChildren = props && "children" in props ? props.children : void 0;
|
|
47
|
-
return (children.length > 0 ? children : propChildren === void 0 ? [] : [propChildren]).flat(1);
|
|
48
|
-
}
|
|
49
|
-
function normalizeJsxSlotKey(rawKey) {
|
|
50
|
-
const key = String(rawKey);
|
|
51
|
-
if (key.trim().length === 0) throw new Error("jsx key requires a non-empty string.");
|
|
52
|
-
if (key.includes(":")) throw new Error(`jsx key cannot contain the slot separator ":" (got "${key}").`);
|
|
53
|
-
return key;
|
|
54
|
-
}
|
|
55
|
-
function extractJsxSlotKey(props, keyArg) {
|
|
56
|
-
const fromProps = props?.key;
|
|
57
|
-
const rawKey = keyArg ?? (typeof fromProps === "string" || typeof fromProps === "number" ? fromProps : void 0);
|
|
58
|
-
if (rawKey == null) return void 0;
|
|
59
|
-
return normalizeJsxSlotKey(rawKey);
|
|
60
|
-
}
|
|
61
|
-
function escapeAttrValue(value) {
|
|
62
|
-
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
63
|
-
}
|
|
64
|
-
function injectDataKey(out, key) {
|
|
65
|
-
const m = /^\s*<([a-zA-Z][a-zA-Z0-9:._-]*)/.exec(out.value);
|
|
66
|
-
if (!m) return out;
|
|
67
|
-
const openEnd = out.value.indexOf(">", m.index);
|
|
68
|
-
const openTag = out.value.slice(m.index, openEnd === -1 ? void 0 : openEnd);
|
|
69
|
-
if (/\sdata-key\s*=/.test(openTag)) return out;
|
|
70
|
-
const insertAt = m.index + m[0].length;
|
|
71
|
-
return raw(`${out.value.slice(0, insertAt)} data-key="${escapeAttrValue(key)}"${out.value.slice(insertAt)}`);
|
|
72
|
-
}
|
|
73
|
-
function renderJsxValue(value) {
|
|
74
|
-
return __ilhaRenderTemplate(fragmentTemplate([value]));
|
|
75
|
-
}
|
|
76
|
-
function renderJsxElement({ type, props, children, slotKey }) {
|
|
77
|
-
const attrs = { ...props ?? {} };
|
|
78
|
-
delete attrs.children;
|
|
79
|
-
if (slotKey !== void 0) attrs.key = slotKey;
|
|
80
|
-
return __ilhaRenderTemplate(elementTemplate(type, attrs, children));
|
|
81
|
-
}
|
|
82
|
-
function jsx(type, props, maybeKey, ...restChildren) {
|
|
83
|
-
const hasKeyArg = typeof maybeKey === "string" || typeof maybeKey === "number";
|
|
84
|
-
const keyFromArg = hasKeyArg ? maybeKey : void 0;
|
|
85
|
-
const normalizedChildren = normalizeJsxChildren(props, hasKeyArg || maybeKey === void 0 ? restChildren : [maybeKey, ...restChildren]);
|
|
86
|
-
const slotKey = extractJsxSlotKey(props, typeof keyFromArg === "string" || typeof keyFromArg === "number" ? keyFromArg : void 0);
|
|
87
|
-
if (typeof type === "function") {
|
|
88
|
-
const componentProps = {
|
|
89
|
-
...props,
|
|
90
|
-
...normalizedChildren.length > 0 ? { children: normalizedChildren } : {}
|
|
91
|
-
};
|
|
92
|
-
delete componentProps.key;
|
|
93
|
-
const out = type(Object.keys(componentProps).length ? componentProps : {});
|
|
94
|
-
if (isIslandCall(out)) {
|
|
95
|
-
if (slotKey !== void 0) out.key = slotKey;
|
|
96
|
-
return renderJsxValue(out);
|
|
97
|
-
}
|
|
98
|
-
if (isRawHtml(out)) return slotKey !== void 0 ? injectDataKey(out, slotKey) : out;
|
|
99
|
-
if (typeof out === "string" && isIsland(type)) return __ilhaJsxSlot({
|
|
100
|
-
island: type,
|
|
101
|
-
props: componentProps,
|
|
102
|
-
key: slotKey
|
|
103
|
-
});
|
|
104
|
-
if (typeof out === "string") return renderJsxValue(out);
|
|
105
|
-
if (typeof out === "object" && out !== null && Object.getPrototypeOf(out) === Object.prototype && out[RENDER_PART] === true && typeof out.toString === "function") return raw(String(out));
|
|
106
|
-
return renderJsxValue(out);
|
|
107
|
-
}
|
|
108
|
-
return renderJsxElement({
|
|
109
|
-
type,
|
|
110
|
-
props,
|
|
111
|
-
children: normalizedChildren,
|
|
112
|
-
slotKey
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
const jsxs = jsx;
|
|
116
|
-
function Fragment(props, ...children) {
|
|
117
|
-
return __ilhaRenderTemplate(fragmentTemplate(normalizeJsxChildren(props, children)));
|
|
118
|
-
}
|
|
119
|
-
function jsxDEV(type, props, maybeKey, _source, _self) {
|
|
120
|
-
return jsx(type, props, maybeKey);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
//#endregion
|
|
124
|
-
export { jsxs as i, jsx as n, jsxDEV as r, Fragment as t };
|