deckjsx 0.2.0 → 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/dist/index.d.mts +165 -2
- package/dist/index.mjs +568 -22
- package/dist/jsx-Crlbye9V.mjs +290 -0
- package/dist/jsx-dev-runtime.d.mts +6 -2
- package/dist/jsx-dev-runtime.mjs +17 -2
- package/dist/{jsx-runtime-BWV9tOov.d.mts → jsx-runtime-ru5t8S3z.d.mts} +80 -24
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/jsx-runtime.mjs +3 -3
- package/package.json +1 -1
- package/dist/jsx-lqMAdW2X.mjs +0 -175
package/dist/jsx-lqMAdW2X.mjs
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
//#region src/jsx.ts
|
|
2
|
-
const VIEW_INTRINSIC_TAGS = new Set([
|
|
3
|
-
"article",
|
|
4
|
-
"aside",
|
|
5
|
-
"div",
|
|
6
|
-
"figure",
|
|
7
|
-
"footer",
|
|
8
|
-
"header",
|
|
9
|
-
"main",
|
|
10
|
-
"nav",
|
|
11
|
-
"section"
|
|
12
|
-
]);
|
|
13
|
-
const TEXT_INTRINSIC_TAGS = new Set([
|
|
14
|
-
"h1",
|
|
15
|
-
"h2",
|
|
16
|
-
"h3",
|
|
17
|
-
"h4",
|
|
18
|
-
"h5",
|
|
19
|
-
"h6",
|
|
20
|
-
"p"
|
|
21
|
-
]);
|
|
22
|
-
function isRecord(value) {
|
|
23
|
-
return typeof value === "object" && value !== null;
|
|
24
|
-
}
|
|
25
|
-
function isViewIntrinsicTag(value) {
|
|
26
|
-
return VIEW_INTRINSIC_TAGS.has(value);
|
|
27
|
-
}
|
|
28
|
-
function isTextIntrinsicTag(value) {
|
|
29
|
-
return TEXT_INTRINSIC_TAGS.has(value);
|
|
30
|
-
}
|
|
31
|
-
function isJsxNode(value) {
|
|
32
|
-
return value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || isAuthorNode(value) || Array.isArray(value) && value.every((item) => isJsxNode(item));
|
|
33
|
-
}
|
|
34
|
-
function isTextJsxNode(value) {
|
|
35
|
-
return value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || Array.isArray(value) && value.every((item) => isTextJsxNode(item));
|
|
36
|
-
}
|
|
37
|
-
function requireJsxNode(value) {
|
|
38
|
-
if (isJsxNode(value)) return value;
|
|
39
|
-
throw new Error("JSX children must be deckjsx nodes or primitive text values.");
|
|
40
|
-
}
|
|
41
|
-
function requireTextJsxNode(value) {
|
|
42
|
-
if (isTextJsxNode(value)) return value;
|
|
43
|
-
throw new Error("Text-like intrinsic children must be primitive text values.");
|
|
44
|
-
}
|
|
45
|
-
function flattenChildren(input) {
|
|
46
|
-
if (Array.isArray(input)) return input.flatMap((item) => flattenChildren(item));
|
|
47
|
-
return [input];
|
|
48
|
-
}
|
|
49
|
-
function splitContentProps(props) {
|
|
50
|
-
const { children: rawChildren, ...nodeProps } = props;
|
|
51
|
-
return {
|
|
52
|
-
props: nodeProps,
|
|
53
|
-
children: rawChildren === void 0 ? [] : flattenChildren(rawChildren)
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
function splitTextProps(props) {
|
|
57
|
-
const { children: rawChildren, ...nodeProps } = props;
|
|
58
|
-
return {
|
|
59
|
-
props: nodeProps,
|
|
60
|
-
children: rawChildren === void 0 ? [] : flattenChildren(rawChildren)
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function splitLeafProps(props) {
|
|
64
|
-
const { children: _rawChildren, ...nodeProps } = props;
|
|
65
|
-
return nodeProps;
|
|
66
|
-
}
|
|
67
|
-
function collectRawChildren(propsObject, children) {
|
|
68
|
-
if (children.length === 0) return propsObject.children;
|
|
69
|
-
if (children.length === 1) return children[0];
|
|
70
|
-
return children;
|
|
71
|
-
}
|
|
72
|
-
function implicitTextNode(value) {
|
|
73
|
-
if (typeof value === "string" && value.trim().length === 0) return null;
|
|
74
|
-
const text = typeof value === "string" && /[\n\r\t]/.test(value) ? value.trim() : String(value);
|
|
75
|
-
if (text.length === 0) return null;
|
|
76
|
-
return Text({ children: text });
|
|
77
|
-
}
|
|
78
|
-
function normalizeViewIntrinsicChildren(value) {
|
|
79
|
-
if (value === void 0) return;
|
|
80
|
-
return flattenChildren(value).map((child) => {
|
|
81
|
-
if (typeof child === "string" || typeof child === "number") return implicitTextNode(child);
|
|
82
|
-
return child;
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
function intrinsicElement(type, propsObject, children) {
|
|
86
|
-
const rawChildren = collectRawChildren(propsObject, children);
|
|
87
|
-
const { children: _children, ...nodeProps } = propsObject;
|
|
88
|
-
if (isViewIntrinsicTag(type)) {
|
|
89
|
-
const viewChildren = requireJsxNode(rawChildren);
|
|
90
|
-
return View({
|
|
91
|
-
...nodeProps,
|
|
92
|
-
children: normalizeViewIntrinsicChildren(viewChildren)
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
if (isTextIntrinsicTag(type)) return Text({
|
|
96
|
-
...nodeProps,
|
|
97
|
-
children: requireTextJsxNode(rawChildren)
|
|
98
|
-
});
|
|
99
|
-
if (rawChildren !== void 0) throw new Error("<img> is a leaf element and does not accept children.");
|
|
100
|
-
if (typeof propsObject.src !== "string" && typeof propsObject.data !== "string") throw new Error("<img> requires either src or data.");
|
|
101
|
-
return Image(nodeProps);
|
|
102
|
-
}
|
|
103
|
-
function createElement(type, props, ...children) {
|
|
104
|
-
if (typeof type === "string") {
|
|
105
|
-
if (isViewIntrinsicTag(type) || isTextIntrinsicTag(type) || type === "img") return intrinsicElement(type, isRecord(props) ? props : {}, children);
|
|
106
|
-
throw new Error(`Intrinsic element is not supported: <${type}>.`);
|
|
107
|
-
}
|
|
108
|
-
if (typeof type !== "function") throw new Error("JSX element type must be a function component.");
|
|
109
|
-
const propsObject = isRecord(props) ? props : {};
|
|
110
|
-
return type({
|
|
111
|
-
...propsObject,
|
|
112
|
-
children: children.length === 0 ? requireJsxNode(propsObject.children) : children.length === 1 ? requireJsxNode(children[0]) : children.map((child) => requireJsxNode(child))
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
function Fragment(props) {
|
|
116
|
-
return props.children ?? null;
|
|
117
|
-
}
|
|
118
|
-
function Slide(props) {
|
|
119
|
-
const authored = splitContentProps(props);
|
|
120
|
-
return {
|
|
121
|
-
$$typeof: "deckjsx.author-node",
|
|
122
|
-
kind: "slide",
|
|
123
|
-
props: authored.props,
|
|
124
|
-
children: authored.children
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function View(props) {
|
|
128
|
-
const authored = splitContentProps(props);
|
|
129
|
-
return {
|
|
130
|
-
$$typeof: "deckjsx.author-node",
|
|
131
|
-
kind: "view",
|
|
132
|
-
props: authored.props,
|
|
133
|
-
children: authored.children
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function Text(props) {
|
|
137
|
-
const authored = splitTextProps(props);
|
|
138
|
-
return {
|
|
139
|
-
$$typeof: "deckjsx.author-node",
|
|
140
|
-
kind: "text",
|
|
141
|
-
props: authored.props,
|
|
142
|
-
children: authored.children
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
function Image(props) {
|
|
146
|
-
return {
|
|
147
|
-
$$typeof: "deckjsx.author-node",
|
|
148
|
-
kind: "image",
|
|
149
|
-
props: splitLeafProps(props),
|
|
150
|
-
children: []
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
function Shape(props) {
|
|
154
|
-
return {
|
|
155
|
-
$$typeof: "deckjsx.author-node",
|
|
156
|
-
kind: "shape",
|
|
157
|
-
props: splitLeafProps(props),
|
|
158
|
-
children: []
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
function isAuthorNodeKind(value) {
|
|
162
|
-
return value === "slide" || value === "view" || value === "text" || value === "image" || value === "shape";
|
|
163
|
-
}
|
|
164
|
-
function isAuthorNode(value) {
|
|
165
|
-
if (!isRecord(value)) return false;
|
|
166
|
-
return value.$$typeof === "deckjsx.author-node" && isAuthorNodeKind(value.kind) && isRecord(value.props) && Array.isArray(value.children);
|
|
167
|
-
}
|
|
168
|
-
function isSlideNode(value) {
|
|
169
|
-
return isAuthorNode(value) && value.kind === "slide";
|
|
170
|
-
}
|
|
171
|
-
function isContentNode(value) {
|
|
172
|
-
return isAuthorNode(value) && value.kind !== "slide";
|
|
173
|
-
}
|
|
174
|
-
//#endregion
|
|
175
|
-
export { Text as a, isAuthorNode as c, Slide as i, isContentNode as l, Image as n, View as o, Shape as r, createElement as s, Fragment as t, isSlideNode as u };
|