deckjsx 0.2.0 → 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.
@@ -0,0 +1,290 @@
1
+ //#region src/authoring/tree.ts
2
+ function isRecord$1(value) {
3
+ return typeof value === "object" && value !== null;
4
+ }
5
+ function createAuthorText(value, sourceSpan) {
6
+ return {
7
+ $$typeof: "deckjsx.author-tree",
8
+ kind: "text",
9
+ value,
10
+ ...sourceSpan ? { sourceSpan } : {}
11
+ };
12
+ }
13
+ function createAuthorElement(input) {
14
+ return {
15
+ $$typeof: "deckjsx.author-tree",
16
+ kind: "element",
17
+ source: input.source,
18
+ ...input.key !== void 0 ? { key: input.key } : {},
19
+ props: input.props ?? {},
20
+ children: normalizeAuthorChildren(input.children ?? []),
21
+ ...input.sourceSpan ? { sourceSpan: input.sourceSpan } : {}
22
+ };
23
+ }
24
+ function createAuthorFragment(input) {
25
+ return {
26
+ $$typeof: "deckjsx.author-tree",
27
+ kind: "fragment",
28
+ ...input.key !== void 0 ? { key: input.key } : {},
29
+ children: normalizeAuthorChildren(input.children ?? []),
30
+ ...input.sourceSpan ? { sourceSpan: input.sourceSpan } : {}
31
+ };
32
+ }
33
+ function isAuthorTreeNode(value) {
34
+ return isRecord$1(value) && value.$$typeof === "deckjsx.author-tree";
35
+ }
36
+ function normalizeAuthorChildren(children) {
37
+ return children.flatMap((child) => {
38
+ if (child === null || child === void 0 || typeof child === "boolean") return [];
39
+ if (typeof child === "string" || typeof child === "number") return [createAuthorText(child)];
40
+ if (Array.isArray(child)) return normalizeAuthorChildren(child);
41
+ if (isAuthorTreeNode(child)) return [child];
42
+ throw new Error("JSX children must be deckjsx author tree nodes or primitive text values.");
43
+ });
44
+ }
45
+ function collectChildren(propsObject, children) {
46
+ if (children.length === 0) return propsObject.children;
47
+ if (children.length === 1) return children[0];
48
+ return children;
49
+ }
50
+ //#endregion
51
+ //#region src/authoring/components.ts
52
+ function splitChildren(props) {
53
+ const { children, ...nodeProps } = props;
54
+ return {
55
+ props: nodeProps,
56
+ children: children === void 0 ? [] : [children]
57
+ };
58
+ }
59
+ function leafProps(props) {
60
+ const { children: _children, ...nodeProps } = props;
61
+ return nodeProps;
62
+ }
63
+ function Slide(props) {
64
+ const authored = splitChildren(props);
65
+ return createAuthorElement({
66
+ source: {
67
+ kind: "component",
68
+ component: "Slide"
69
+ },
70
+ props: authored.props,
71
+ children: authored.children
72
+ });
73
+ }
74
+ function View(props) {
75
+ const authored = splitChildren(props);
76
+ return createAuthorElement({
77
+ source: {
78
+ kind: "component",
79
+ component: "View"
80
+ },
81
+ props: authored.props,
82
+ children: authored.children
83
+ });
84
+ }
85
+ function Text(props) {
86
+ const authored = splitChildren(props);
87
+ return createAuthorElement({
88
+ source: {
89
+ kind: "component",
90
+ component: "Text"
91
+ },
92
+ props: authored.props,
93
+ children: authored.children
94
+ });
95
+ }
96
+ function Image(props) {
97
+ return createAuthorElement({
98
+ source: {
99
+ kind: "component",
100
+ component: "Image"
101
+ },
102
+ props: leafProps(props)
103
+ });
104
+ }
105
+ function Shape(props) {
106
+ return createAuthorElement({
107
+ source: {
108
+ kind: "component",
109
+ component: "Shape"
110
+ },
111
+ props: leafProps(props)
112
+ });
113
+ }
114
+ //#endregion
115
+ //#region src/authoring/tags.ts
116
+ const INTRINSIC_VIEW_TAGS = new Set([
117
+ "article",
118
+ "aside",
119
+ "div",
120
+ "figure",
121
+ "footer",
122
+ "header",
123
+ "main",
124
+ "nav",
125
+ "section"
126
+ ]);
127
+ const INTRINSIC_TEXT_TAGS = new Set([
128
+ "h1",
129
+ "h2",
130
+ "h3",
131
+ "h4",
132
+ "h5",
133
+ "h6",
134
+ "p"
135
+ ]);
136
+ function isIntrinsicViewTag(value) {
137
+ return INTRINSIC_VIEW_TAGS.has(value);
138
+ }
139
+ function isIntrinsicTextTag(value) {
140
+ return INTRINSIC_TEXT_TAGS.has(value);
141
+ }
142
+ function isAuthoredTag(value) {
143
+ return isIntrinsicViewTag(value) || isIntrinsicTextTag(value) || value === "img" || value === "span";
144
+ }
145
+ //#endregion
146
+ //#region src/authoring/legacy.ts
147
+ function textFromPrimitive(value) {
148
+ if (typeof value === "string" && value.trim().length === 0) return null;
149
+ const text = typeof value === "string" && /[\n\r\t]/.test(value) ? value.trim() : String(value);
150
+ if (text.length === 0) return null;
151
+ return legacyNode("text", {}, [text]);
152
+ }
153
+ function legacyNode(kind, props, children) {
154
+ return {
155
+ $$typeof: "deckjsx.author-node",
156
+ kind,
157
+ props,
158
+ children
159
+ };
160
+ }
161
+ function elementKind(node) {
162
+ if (node.source.kind === "component") switch (node.source.component) {
163
+ case "Slide": return "slide";
164
+ case "View": return "view";
165
+ case "Text": return "text";
166
+ case "Image": return "image";
167
+ case "Shape": return "shape";
168
+ }
169
+ if (isIntrinsicViewTag(node.source.tag)) return "view";
170
+ if (isIntrinsicTextTag(node.source.tag) || node.source.tag === "span") return "text";
171
+ return "image";
172
+ }
173
+ function convertChildrenFor(kind, children) {
174
+ const converted = [];
175
+ for (const child of children) {
176
+ if (child.kind === "fragment") {
177
+ converted.push(...convertChildrenFor(kind, child.children));
178
+ continue;
179
+ }
180
+ if (child.kind === "text") {
181
+ if (kind === "view" || kind === "slide") {
182
+ const textNode = textFromPrimitive(child.value);
183
+ if (textNode) converted.push(textNode);
184
+ continue;
185
+ }
186
+ converted.push(child.value);
187
+ continue;
188
+ }
189
+ converted.push(toLegacyAuthorNode(child));
190
+ }
191
+ return converted;
192
+ }
193
+ function toLegacyAuthorNode(node) {
194
+ const kind = elementKind(node);
195
+ const props = node.props;
196
+ switch (kind) {
197
+ case "slide": return legacyNode("slide", props, convertChildrenFor(kind, node.children));
198
+ case "view": return legacyNode("view", props, convertChildrenFor(kind, node.children));
199
+ case "text": return legacyNode("text", props, convertChildrenFor(kind, node.children));
200
+ case "image": return legacyNode("image", props, []);
201
+ case "shape": return legacyNode("shape", props, []);
202
+ }
203
+ }
204
+ function toLegacyJsxNode(value) {
205
+ if (isLegacyAuthorNode(value)) return value;
206
+ if (Array.isArray(value)) return value.map((item) => toLegacyJsxNode(item));
207
+ if (!isAuthorTreeNode(value)) return value;
208
+ if (value.kind === "fragment") return value.children.map((child) => toLegacyJsxNode(child));
209
+ if (value.kind === "text") return value.value;
210
+ return toLegacyAuthorNode(value);
211
+ }
212
+ function isLegacyAuthorNode(value) {
213
+ return typeof value === "object" && value !== null && "$$typeof" in value && value.$$typeof === "deckjsx.author-node";
214
+ }
215
+ //#endregion
216
+ //#region src/jsx.ts
217
+ function isRecord(value) {
218
+ return typeof value === "object" && value !== null;
219
+ }
220
+ function splitProps(props, children) {
221
+ const rawChildren = collectChildren(props, children);
222
+ const { children: _children, ...nodeProps } = props;
223
+ return {
224
+ props: nodeProps,
225
+ children: rawChildren === void 0 ? [] : [rawChildren]
226
+ };
227
+ }
228
+ function intrinsicElement(type, propsObject, children, key, sourceSpan) {
229
+ const authored = splitProps(propsObject, children);
230
+ return createAuthorElement({
231
+ source: {
232
+ kind: "tag",
233
+ tag: type
234
+ },
235
+ props: authored.props,
236
+ children: authored.children,
237
+ ...key !== void 0 ? { key } : {},
238
+ ...sourceSpan ? { sourceSpan } : {}
239
+ });
240
+ }
241
+ function createElement(type, props, ...children) {
242
+ return createElementWithMetadata(type, props, void 0, void 0, children);
243
+ }
244
+ function createElementWithMetadata(type, props, key, sourceSpan, children = []) {
245
+ if (typeof type === "string") {
246
+ if (isIntrinsicViewTag(type) || isIntrinsicTextTag(type) || type === "img" || type === "span") return intrinsicElement(type, isRecord(props) ? props : {}, children, key, sourceSpan);
247
+ if (!isAuthoredTag(type)) throw new Error(`Intrinsic element is not supported: <${type}>.`);
248
+ }
249
+ if (typeof type !== "function") throw new Error("JSX element type must be a function component.");
250
+ if (type === Fragment) {
251
+ const rawChildren = collectChildren(isRecord(props) ? props : {}, children);
252
+ return createAuthorFragment({
253
+ children: rawChildren === void 0 ? [] : [rawChildren],
254
+ ...key !== void 0 ? { key } : {},
255
+ ...sourceSpan ? { sourceSpan } : {}
256
+ });
257
+ }
258
+ const propsObject = isRecord(props) ? props : {};
259
+ const rawChildren = collectChildren(propsObject, children);
260
+ const result = type({
261
+ ...propsObject,
262
+ children: rawChildren
263
+ });
264
+ if (!isAuthorTreeNode(result)) throw new Error("Function components must return a deckjsx author tree node.");
265
+ if (key === void 0 && sourceSpan === void 0) return result;
266
+ if (result.kind === "element") return {
267
+ ...result,
268
+ ...key !== void 0 ? { key } : {},
269
+ ...sourceSpan ? { sourceSpan } : {}
270
+ };
271
+ return result;
272
+ }
273
+ function Fragment(props) {
274
+ return createAuthorFragment({ children: props.children === void 0 ? [] : [props.children] });
275
+ }
276
+ function isAuthorNodeKind(value) {
277
+ return value === "slide" || value === "view" || value === "text" || value === "image" || value === "shape";
278
+ }
279
+ function isAuthorNode(value) {
280
+ if (!isLegacyAuthorNode(value)) return false;
281
+ return isAuthorNodeKind(value.kind);
282
+ }
283
+ function isSlideNode(value) {
284
+ return isAuthorNode(value) && value.kind === "slide";
285
+ }
286
+ function isContentNode(value) {
287
+ return isAuthorNode(value) && value.kind !== "slide";
288
+ }
289
+ //#endregion
290
+ export { isContentNode as a, toLegacyJsxNode as c, Slide as d, Text as f, isAuthorNode as i, Image as l, isAuthorTreeNode as m, createElement as n, isSlideNode as o, View as p, createElementWithMetadata as r, isLegacyAuthorNode as s, Fragment as t, Shape as u };
@@ -1,2 +1,6 @@
1
- import { a as Fragment, i as jsxs, r as jsx, t as JSX } from "./jsx-runtime-BWV9tOov.mjs";
2
- export { Fragment, type JSX, jsx, jsx as jsxDEV, jsxs };
1
+ import { fn as AuthorTreeNode, i as Fragment, n as jsx, pn as JsxKey, r as jsxs, t as JSX } from "./jsx-runtime-DauuRkY2.mjs";
2
+
3
+ //#region src/jsx-dev-runtime.d.ts
4
+ declare function jsxDEV(type: unknown, props: unknown, key?: JsxKey, _isStaticChildren?: boolean, source?: unknown): AuthorTreeNode;
5
+ //#endregion
6
+ export { Fragment, type JSX, jsx, jsxDEV, jsxs };
@@ -1,3 +1,18 @@
1
- import { t as Fragment } from "./jsx-lqMAdW2X.mjs";
1
+ import { r as createElementWithMetadata, t as Fragment } from "./jsx-Crlbye9V.mjs";
2
2
  import { jsx, jsxs } from "./jsx-runtime.mjs";
3
- export { Fragment, jsx, jsx as jsxDEV, jsxs };
3
+ //#region src/jsx-dev-runtime.ts
4
+ function sourceSpanFromDevSource(source) {
5
+ if (typeof source !== "object" || source === null) return;
6
+ const devSource = source;
7
+ if (devSource.fileName === void 0 && devSource.lineNumber === void 0 && devSource.columnNumber === void 0) return;
8
+ return {
9
+ file: devSource.fileName,
10
+ line: devSource.lineNumber,
11
+ column: devSource.columnNumber
12
+ };
13
+ }
14
+ function jsxDEV(type, props, key, _isStaticChildren, source) {
15
+ return createElementWithMetadata(type, props, key, sourceSpanFromDevSource(source));
16
+ }
17
+ //#endregion
18
+ export { Fragment, jsx, jsxDEV, jsxs };