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