deckjsx 0.6.0 → 0.8.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.
@@ -1,22 +0,0 @@
1
- import { Yt as Diagnostics } from "./index-C5l8PX5V.mjs";
2
- import { F as OutputFormat, L as ProjectionFormat, s as PptxPackageModel, z as RenderedArtifact } from "./pptx-PzEK54aA.mjs";
3
-
4
- //#region src/adapter.d.ts
5
- type RenderOptions = {
6
- readonly output?: string;
7
- };
8
- type WriterAdapterResult<TFormat extends OutputFormat = OutputFormat> = {
9
- readonly diagnostics: Diagnostics;
10
- readonly artifact?: RenderedArtifact<TFormat>;
11
- };
12
- type WriterAdapter<TProjection = unknown, TFormat extends OutputFormat = OutputFormat> = {
13
- readonly kind: "deckjsx.writerAdapter";
14
- readonly name: string;
15
- readonly projectionFormat: ProjectionFormat;
16
- readonly format: TFormat;
17
- readonly options: RenderOptions;
18
- render(projection: TProjection): Promise<WriterAdapterResult<TFormat>>;
19
- };
20
- declare function pptxgenjs(options?: RenderOptions): WriterAdapter<PptxPackageModel, "pptx">;
21
- //#endregion
22
- export { pptxgenjs as i, WriterAdapter as n, WriterAdapterResult as r, RenderOptions as t };
@@ -1,290 +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 Slide(props) {
165
- const authored = splitChildren(props);
166
- return createAuthorElement({
167
- source: {
168
- kind: "component",
169
- component: "Slide"
170
- },
171
- props: authored.props,
172
- children: authored.children
173
- });
174
- }
175
- function View(props) {
176
- const authored = splitChildren(props);
177
- return createAuthorElement({
178
- source: {
179
- kind: "component",
180
- component: "View"
181
- },
182
- props: authored.props,
183
- children: authored.children
184
- });
185
- }
186
- function Text(props) {
187
- const authored = splitChildren(props);
188
- return createAuthorElement({
189
- source: {
190
- kind: "component",
191
- component: "Text"
192
- },
193
- props: authored.props,
194
- children: authored.children
195
- });
196
- }
197
- function Image(props) {
198
- return createAuthorElement({
199
- source: {
200
- kind: "component",
201
- component: "Image"
202
- },
203
- props: leafProps(props)
204
- });
205
- }
206
- function Shape(props) {
207
- return createAuthorElement({
208
- source: {
209
- kind: "component",
210
- component: "Shape"
211
- },
212
- props: leafProps(props)
213
- });
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 (!isAuthorNodeValue(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, Shape as c, View as d, isAuthorNodeValue as f, isAuthoredTag as h, isAuthorNode as i, Slide as l, isAuthorTreeNode as m, createElement as n, isSlideNode as o, toAuthorJsxNode as p, createElementWithMetadata as r, Image as s, Fragment as t, Text as u };
@@ -1,57 +0,0 @@
1
- import { _ as TextProps, a as DeckJsxIntrinsicElements, an as JsxKey, c as IntrinsicDivProps, cn as IntrinsicViewTag, d as IntrinsicTextTag$1, f as IntrinsicViewTag$1, h as SlideProps, in as AuthorTreeNode, l as IntrinsicImgProps, nn as AuthorElementNode, p as ShapeProps, rn as AuthorTreeChild, s as ImageProps, sn as IntrinsicTextTag, u as IntrinsicPProps, y as ViewProps } from "./index-C5l8PX5V.mjs";
2
-
3
- //#region src/authoring/components.d.ts
4
- declare function Slide(props: SlideProps): AuthorElementNode;
5
- declare function View(props: ViewProps): AuthorElementNode;
6
- declare function Text(props: TextProps): AuthorElementNode;
7
- declare function Image(props: ImageProps): AuthorElementNode;
8
- declare function Shape(props: ShapeProps): AuthorElementNode;
9
- //#endregion
10
- //#region src/jsx.d.ts
11
- type ComponentProps = {
12
- children?: AuthorTreeChild;
13
- };
14
- type ElementChildren<P> = P extends {
15
- children?: infer Child;
16
- } ? Child : never;
17
- type ElementChildArgs<P> = P extends {
18
- children?: never;
19
- } ? [] : ElementChildren<P>[];
20
- declare function createElement<P extends {
21
- children?: unknown;
22
- }, R extends AuthorTreeNode>(type: (props: P) => R, props: (Omit<P, "children"> & Partial<Pick<P, "children">>) | null, ...children: ElementChildArgs<P>): R;
23
- declare function createElement(type: IntrinsicViewTag, props: (Omit<IntrinsicDivProps, "children"> & Partial<Pick<IntrinsicDivProps, "children">>) | null, ...children: ElementChildArgs<IntrinsicDivProps>): AuthorTreeNode;
24
- declare function createElement(type: IntrinsicTextTag, props: (Omit<IntrinsicPProps, "children"> & Partial<Pick<IntrinsicPProps, "children">>) | null, ...children: ElementChildArgs<IntrinsicPProps>): AuthorTreeNode;
25
- declare function createElement(type: "span", props: IntrinsicPProps | null): AuthorTreeNode;
26
- declare function createElement(type: "img", props: IntrinsicImgProps): AuthorTreeNode;
27
- declare function createElement(type: string, props: ComponentProps | null): never;
28
- declare function Fragment(props: {
29
- children?: AuthorTreeChild;
30
- }): AuthorTreeNode;
31
- //#endregion
32
- //#region src/jsx-runtime.d.ts
33
- type JsxComponent<P, R extends AuthorTreeNode> = (props: P) => R;
34
- type JsxProps<P> = P extends {
35
- children?: unknown;
36
- } ? Omit<P, "children"> & Partial<Pick<P, "children">> : P;
37
- declare function jsx<P, R extends AuthorTreeNode>(type: JsxComponent<P, R>, props: JsxProps<P> | null, key?: JsxKey): R;
38
- declare function jsx(type: IntrinsicViewTag$1, props: JsxProps<IntrinsicDivProps> | null, key?: JsxKey): AuthorTreeNode;
39
- declare function jsx(type: IntrinsicTextTag$1, props: JsxProps<IntrinsicPProps> | null, key?: JsxKey): AuthorTreeNode;
40
- declare function jsx(type: "span", props: JsxProps<IntrinsicPProps> | null, key?: JsxKey): AuthorTreeNode;
41
- declare function jsx(type: "img", props: IntrinsicImgProps, key?: JsxKey): AuthorTreeNode;
42
- declare function jsx(type: string, props: Record<string, unknown> | null, key?: JsxKey): never;
43
- declare const jsxs: typeof jsx;
44
- declare namespace JSX {
45
- type Element = AuthorTreeNode;
46
- interface ElementChildrenAttribute {
47
- children: {};
48
- }
49
- interface IntrinsicAttributes {
50
- key?: JsxKey;
51
- }
52
- interface IntrinsicElements extends DeckJsxIntrinsicElements {
53
- span: IntrinsicPProps;
54
- }
55
- }
56
- //#endregion
57
- export { createElement as a, Slide as c, Fragment as i, Text as l, jsx as n, Image as o, jsxs as r, Shape as s, JSX as t, View as u };