deckjsx 0.1.1 → 0.2.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 CHANGED
@@ -1,6 +1,7 @@
1
1
  # deckjsx
2
2
 
3
- `deckjsx` is a TypeScript library for generating presentation files from JSX through a compiler pipeline.
3
+ `deckjsx` is a TypeScript library for generating presentation files from JSX through a compiler
4
+ pipeline.
4
5
 
5
6
  The intended architecture is:
6
7
 
@@ -13,7 +14,8 @@ JSX
13
14
  ```
14
15
 
15
16
  This project is being designed as a compiler, not as a thin `PptxGenJS` wrapper.
16
- The current API direction is a class-based compiler with callback-based `.add()`, `.render()`, and `.output()`, and JSX authoring centered on a `style` object prop.
17
+ The API uses a class-based compiler with callback-based `.add()`, `.render()`, and `.output()`.
18
+ Authoring uses typed JSX elements with a `style` object prop.
17
19
 
18
20
  The implementation preserves the compiler model with explicit module boundaries for authoring,
19
21
  style normalization, layout, IR, backend emission, and Node runtime output.
@@ -29,7 +31,7 @@ The package currently targets Node.js output and ships a `pptxgenjs` backend.
29
31
  ## Usage
30
32
 
31
33
  ```tsx
32
- import { Deck, Slide, Text, View } from "deckjsx";
34
+ import { Deck, Slide } from "deckjsx";
33
35
 
34
36
  const deck = new Deck({
35
37
  layout: { width: 13.333, height: 7.5, unit: "in" },
@@ -38,38 +40,41 @@ const deck = new Deck({
38
40
 
39
41
  deck.add(({ slideIndex, totalSlides }) => (
40
42
  <Slide name={`Slide ${slideIndex + 1}`} style={{ backgroundColor: "#F8FAFC" }}>
41
- <Text
43
+ <main
42
44
  style={{
43
45
  x: 0.7,
44
46
  y: 0.5,
45
- width: 8.5,
46
- height: 0.6,
47
- fontSize: 28,
48
- fontWeight: 700,
49
- color: "#0F172A",
50
- }}
51
- >
52
- Quarterly Review
53
- </Text>
54
- <View
55
- style={{
56
- x: 0.7,
57
- y: 1.4,
58
47
  width: 11.9,
59
- height: 4.8,
48
+ height: 6.3,
60
49
  display: "grid",
61
- gridTemplateColumns: "1fr 1fr",
62
- columnGap: 0.35,
50
+ gridTemplateRows: ["0.9in", "1fr", "0.4in"],
51
+ rowGap: 0.25,
63
52
  }}
64
53
  >
65
- <Text style={{ fontSize: 18, color: "#334155", fit: "shrink" }}>
66
- Author slides with TSX primitives, inspect the generated IR, and emit PPTX files through the
67
- backend boundary.
68
- </Text>
69
- <Text style={{ fontSize: 18, color: "#334155", fit: "shrink" }}>
70
- {slideIndex + 1} / {totalSlides}
71
- </Text>
72
- </View>
54
+ <header>
55
+ <h1 style={{ width: "100%", height: 0.6, fontSize: 28, fontWeight: 700, color: "#0F172A" }}>
56
+ Quarterly Review
57
+ </h1>
58
+ </header>
59
+
60
+ <section style={{ display: "grid", gridTemplateColumns: "1fr 1fr", columnGap: 0.35 }}>
61
+ <p style={{ fontSize: 18, color: "#334155", fit: "shrink" }}>
62
+ Author slides with typed JSX, inspect the generated IR, and emit PPTX files through the
63
+ backend boundary.
64
+ </p>
65
+ <figure style={{ backgroundColor: "#E0F2FE", borderRadius: 0.15, padding: 0.25 }}>
66
+ <img src="chart.png" style={{ width: "100%", height: "100%", fit: "contain" }} />
67
+ </figure>
68
+ </section>
69
+
70
+ <footer>
71
+ <p
72
+ style={{ width: "100%", height: 0.3, fontSize: 11, color: "#64748B", textAlign: "right" }}
73
+ >
74
+ {slideIndex + 1} / {totalSlides}
75
+ </p>
76
+ </footer>
77
+ </main>
73
78
  </Slide>
74
79
  ));
75
80
 
@@ -80,6 +85,64 @@ await deck.output({ backend: "pptxgenjs", output: "quarterly-review.pptx" });
80
85
  Use `deck.render()` for tests, snapshots, and backend-independent inspection. Use
81
86
  `deck.output({ backend: "pptxgenjs", output })` when writing a PowerPoint file.
82
87
 
88
+ ## JSX elements
89
+
90
+ `deckjsx` supports both the original capitalized components and a typed HTML-like JSX surface.
91
+
92
+ View-like elements compile to grouped layout containers:
93
+
94
+ ```tsx
95
+ <main>
96
+ <header />
97
+ <section />
98
+ <article />
99
+ <aside />
100
+ <nav />
101
+ <footer />
102
+ <figure />
103
+ </main>
104
+ ```
105
+
106
+ Text-like elements compile to text boxes:
107
+
108
+ ```tsx
109
+ <h1>Title</h1>
110
+ <h2>Section</h2>
111
+ <p>Body copy</p>
112
+ ```
113
+
114
+ Image elements compile to images and require either `src` or `data`:
115
+
116
+ ```tsx
117
+ <img src="diagram.png" style={{ width: 4, height: 2.5, fit: "contain" }} />
118
+ ```
119
+
120
+ Primitive string and number children inside view-like elements are normalized to implicit text
121
+ nodes. Inline rich text with `span` is intentionally reserved for a later release.
122
+
123
+ ## View Layout Semantics
124
+
125
+ `View` is a containing block for its children. Child `x`, `y`, `left`, `top`, `right`,
126
+ `bottom`, `width`, and `height` values are resolved relative to the parent `View`, not
127
+ the slide, so authors can build panels with local coordinates. Percentage lengths use
128
+ the parent frame as their reference.
129
+
130
+ ```tsx
131
+ <View style={{ x: 1, y: 1, width: 6, height: 3 }}>
132
+ <Text style={{ x: "10%", y: "20%", width: "50%", height: "25%" }}>local percent frame</Text>
133
+ <Text style={{ left: "55%", top: "10%", right: "10%", bottom: "60%" }}>inset frame</Text>
134
+ </View>
135
+ ```
136
+
137
+ For `display: "flex"` and `display: "grid"`, normal-flow children are laid out inside
138
+ the content frame after padding. `gap`, `flexGrow`, percentage widths, `fr` grid tracks,
139
+ and simple `gridColumn` / `gridRow` spans resolve to concrete slide coordinates during
140
+ rendering. Absolutely positioned children inside flex or grid containers also use the
141
+ container content frame, including padding, as their containing block.
142
+
143
+ Use direct slide children when you want slide-global absolute placement. Use children
144
+ inside a `View` when you want a local, web-like layout region.
145
+
83
146
  ## Development
84
147
 
85
148
  ```bash
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as OutputConfig, A as CssGridLine, B as CssOverflow, C as CssAspectRatio, D as CssFlexDirection, E as CssFlexBasis, F as CssGridTemplateShorthand, G as DeckPointLength, H as CssVisibility, I as CssGridTrack, J as ImageProps, K as ImageCropAuthoring, L as CssJustifyContent, M as CssGridShorthand, N as CssGridTemplate, O as CssFlexWrap, P as CssGridTemplateAreas, Q as LayoutMode, R as CssJustifySelf, S as CssAlignSelf, T as CssDisplay, U as DeckLength, V as CssPosition, W as DeckOptions, X as ImplementedBackendName, Y as ImageStyle, Z as JsxNode, _ as BorderStyle, _t as TextTabStopAuthoring, a as Text, at as SlideStyle, b as CssAlignContent, bt as ViewProps, c as isAuthorNode, ct as StackAxis, d as AuthorNode, dt as StrokeLineJoin, et as ShapeProps, f as AuthorNodeKind, ft as TextFit, g as BackendName, gt as TextTabStopAlignment, h as AuthorNodePropsMap, ht as TextStyle, i as Slide, it as SlideProps, j as CssGridPlacement, k as CssGridAutoFlow, l as isContentNode, lt as StrokeDashType, m as AuthorNodeProps, mt as TextProps, n as Image, nt as SlideContext, o as View, ot as Spacing, p as AuthorNodeMap, pt as TextJsxChild, q as ImageCropValue, r as Shape, rt as SlideFactory, s as createElement, st as StackAlignment, t as Fragment, tt as ShapeStyle, u as isSlideNode, ut as StrokeLineCap, v as ContentAuthorNode, vt as TextTabStopLength, w as CssBoxSizing, x as CssAlignItems, xt as ViewStyle, y as ContentJsxChild, yt as VerticalAlign, z as CssObjectPosition } from "./jsx-CrQPDEqU.mjs";
1
+ import { $ as ImageProps, A as CssFlexBasis, At as ViewProps, B as CssGridTrack, C as ContentJsxChild, Ct as TextJsxChild, D as CssAspectRatio, Dt as TextTabStopAuthoring, E as CssAlignSelf, Et as TextTabStopAlignment, F as CssGridPlacement, G as CssPosition, H as CssJustifySelf, I as CssGridShorthand, J as DeckLength, K as CssVisibility, L as CssGridTemplate, M as CssFlexWrap, N as CssGridAutoFlow, O as CssBoxSizing, Ot as TextTabStopLength, P as CssGridLine, Q as ImageCropValue, R as CssGridTemplateAreas, S as ContentAuthorNode, St as TextFit, T as CssAlignItems, Tt as TextStyle, U as CssObjectPosition, V as CssJustifyContent, W as CssOverflow, X as DeckPointLength, Y as DeckOptions, Z as ImageCropAuthoring, _ as AuthorNodeMap, _t as StackAlignment, a as Fragment, at as IntrinsicTextTag, b as BackendName, bt as StrokeLineCap, c as Slide, ct as LayoutMode, d as createElement, dt as ShapeStyle, et as ImageStyle, f as isAuthorNode, ft as SlideContext, g as AuthorNodeKind, gt as Spacing, h as AuthorNode, ht as SlideStyle, it as IntrinsicPProps, j as CssFlexDirection, jt as ViewStyle, k as CssDisplay, kt as VerticalAlign, l as Text, lt as OutputConfig, m as isSlideNode, mt as SlideProps, n as JsxKey, nt as IntrinsicDivProps, o as Image, ot as IntrinsicViewTag, p as isContentNode, pt as SlideFactory, q as DeckJsxIntrinsicElements, rt as IntrinsicImgProps, s as Shape, st as JsxNode, tt as ImplementedBackendName, u as View, ut as ShapeProps, v as AuthorNodeProps, vt as StackAxis, w as CssAlignContent, wt as TextProps, x as BorderStyle, xt as StrokeLineJoin, y as AuthorNodePropsMap, yt as StrokeDashType, z as CssGridTemplateShorthand } from "./jsx-runtime-BWV9tOov.mjs";
2
2
 
3
3
  //#region src/ir/index.d.ts
4
4
  type PresentationIR = {
@@ -260,8 +260,11 @@ declare global {
260
260
  interface ElementChildrenAttribute {
261
261
  children: {};
262
262
  }
263
- interface IntrinsicElements {}
263
+ interface IntrinsicAttributes {
264
+ key?: JsxKey;
265
+ }
266
+ interface IntrinsicElements extends DeckJsxIntrinsicElements {}
264
267
  }
265
268
  }
266
269
  //#endregion
267
- export { type AuthorNode, type AuthorNodeKind, type AuthorNodeMap, type AuthorNodeProps, type AuthorNodePropsMap, type BackendArtifact, type BackendName, type BackgroundImageLayerIR, type BackgroundLayerIR, type BaseNodeIR, type BorderStyle, type CompileBackend, type ContentAuthorNode, type ContentJsxChild, type CssAlignContent, type CssAlignItems, type CssAlignSelf, type CssAspectRatio, type CssBoxSizing, type CssDisplay, type CssFlexBasis, type CssFlexDirection, type CssFlexWrap, type CssGridAutoFlow, type CssGridLine, type CssGridPlacement, type CssGridShorthand, type CssGridTemplate, type CssGridTemplateAreas, type CssGridTemplateShorthand, type CssGridTrack, type CssJustifyContent, type CssJustifySelf, type CssObjectPosition, type CssOverflow, type CssPosition, type CssVisibility, Deck, type DeckLength, type DeckOptions, type DeckPointLength, EMU_PER_INCH, type EdgeStrokeIR, type FillIR, Fragment, type FrameIR, type GroupIR, type HyperlinkIR, Image, type ImageCropAuthoring, type ImageCropIR, type ImageCropValue, type ImageIR, type ImageProps, type ImageSourceIR, type ImageStyle, type ImplementedBackendName, type JsxNode, type LayoutMode, type LinearGradientFillIR, type LinearGradientStopIR, type NodeIR, type ObjectPositionIR, type OutputConfig, POINTS_PER_INCH, type PresentationIR, type RadialGradientFillIR, type ShadowIR, Shape, type ShapeIR, type ShapeProps, type ShapeStyle, type SizeIR, Slide, type SlideContext, type SlideFactory, type SlideIR, type SlideProps, type SlideStyle, type SolidFillIR, type Spacing, type StackAlignment, type StackAxis, type StrokeDashType, type StrokeIR, type StrokeLineCap, type StrokeLineJoin, Text, type TextBulletListIR, type TextContentIR, type TextFit, type TextIR, type TextJsxChild, type TextListIR, type TextNoListIR, type TextNumberListIR, type TextProps, type TextStyle, type TextStyleIR, type TextTabStopAlignment, type TextTabStopAuthoring, type TextTabStopIR, type TextTabStopLength, type VerticalAlign, View, type ViewProps, type ViewStyle, createElement, isAuthorNode, isContentNode, isSlideNode, pptxgenjsBackend };
270
+ export { type AuthorNode, type AuthorNodeKind, type AuthorNodeMap, type AuthorNodeProps, type AuthorNodePropsMap, type BackendArtifact, type BackendName, type BackgroundImageLayerIR, type BackgroundLayerIR, type BaseNodeIR, type BorderStyle, type CompileBackend, type ContentAuthorNode, type ContentJsxChild, type CssAlignContent, type CssAlignItems, type CssAlignSelf, type CssAspectRatio, type CssBoxSizing, type CssDisplay, type CssFlexBasis, type CssFlexDirection, type CssFlexWrap, type CssGridAutoFlow, type CssGridLine, type CssGridPlacement, type CssGridShorthand, type CssGridTemplate, type CssGridTemplateAreas, type CssGridTemplateShorthand, type CssGridTrack, type CssJustifyContent, type CssJustifySelf, type CssObjectPosition, type CssOverflow, type CssPosition, type CssVisibility, Deck, type DeckJsxIntrinsicElements, type DeckLength, type DeckOptions, type DeckPointLength, EMU_PER_INCH, type EdgeStrokeIR, type FillIR, Fragment, type FrameIR, type GroupIR, type HyperlinkIR, Image, type ImageCropAuthoring, type ImageCropIR, type ImageCropValue, type ImageIR, type ImageProps, type ImageSourceIR, type ImageStyle, type ImplementedBackendName, type IntrinsicDivProps, type IntrinsicImgProps, type IntrinsicPProps, type IntrinsicTextTag, type IntrinsicViewTag, type JsxKey, type JsxNode, type LayoutMode, type LinearGradientFillIR, type LinearGradientStopIR, type NodeIR, type ObjectPositionIR, type OutputConfig, POINTS_PER_INCH, type PresentationIR, type RadialGradientFillIR, type ShadowIR, Shape, type ShapeIR, type ShapeProps, type ShapeStyle, type SizeIR, Slide, type SlideContext, type SlideFactory, type SlideIR, type SlideProps, type SlideStyle, type SolidFillIR, type Spacing, type StackAlignment, type StackAxis, type StrokeDashType, type StrokeIR, type StrokeLineCap, type StrokeLineJoin, Text, type TextBulletListIR, type TextContentIR, type TextFit, type TextIR, type TextJsxChild, type TextListIR, type TextNoListIR, type TextNumberListIR, type TextProps, type TextStyle, type TextStyleIR, type TextTabStopAlignment, type TextTabStopAuthoring, type TextTabStopIR, type TextTabStopLength, type VerticalAlign, View, type ViewProps, type ViewStyle, createElement, isAuthorNode, isContentNode, isSlideNode, pptxgenjsBackend };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as Text, c as isAuthorNode, i as Slide, l as isContentNode, n as Image, o as View, r as Shape, s as createElement, t as Fragment, u as isSlideNode } from "./jsx-5H4Zgl79.mjs";
1
+ import { a as Text, c as isAuthorNode, i as Slide, l as isContentNode, n as Image, o as View, r as Shape, s as createElement, t as Fragment, u as isSlideNode } from "./jsx-lqMAdW2X.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import { mkdir, writeFile } from "node:fs/promises";
4
4
  import { dirname } from "node:path";
@@ -1,3 +1,2 @@
1
- import { t as Fragment } from "./jsx-CrQPDEqU.mjs";
2
- import { JSX, jsx, jsxs } from "./jsx-runtime.mjs";
1
+ import { a as Fragment, i as jsxs, r as jsx, t as JSX } from "./jsx-runtime-BWV9tOov.mjs";
3
2
  export { Fragment, type JSX, jsx, jsx as jsxDEV, jsxs };
@@ -1,3 +1,3 @@
1
- import { t as Fragment } from "./jsx-5H4Zgl79.mjs";
1
+ import { t as Fragment } from "./jsx-lqMAdW2X.mjs";
2
2
  import { jsx, jsxs } from "./jsx-runtime.mjs";
3
3
  export { Fragment, jsx, jsx as jsxDEV, jsxs };
@@ -0,0 +1,175 @@
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 };
@@ -54,6 +54,8 @@ type TextJsxChild = string | number | boolean | null | undefined | TextJsxChildA
54
54
  type ContentAuthorNode = AuthorNode<"view" | "text" | "image" | "shape">;
55
55
  interface ContentJsxChildArray extends ReadonlyArray<ContentJsxChild> {}
56
56
  type ContentJsxChild = AuthorNode | boolean | null | undefined | ContentJsxChildArray;
57
+ interface ViewIntrinsicJsxChildArray extends ReadonlyArray<ViewIntrinsicJsxChild> {}
58
+ type ViewIntrinsicJsxChild = ContentJsxChild | string | number | ViewIntrinsicJsxChildArray;
57
59
  interface JsxNodeArray extends ReadonlyArray<JsxNode> {}
58
60
  type JsxNode = AuthorNode | string | number | boolean | null | undefined | JsxNodeArray;
59
61
  type BaseAuthorProps = {
@@ -310,9 +312,13 @@ type TextProps = TextNodeProps & {
310
312
  };
311
313
  type ImageNodeProps = {
312
314
  style?: ImageStyle;
313
- src?: string;
315
+ } & ImageStyle & ({
316
+ src: string;
314
317
  data?: string;
315
- } & ImageStyle;
318
+ } | {
319
+ src?: string;
320
+ data: string;
321
+ });
316
322
  type ImageProps = ImageNodeProps & {
317
323
  children?: never;
318
324
  };
@@ -339,12 +345,37 @@ type AuthorNodePropsMap = {
339
345
  shape: ShapeNodeProps;
340
346
  };
341
347
  type AuthorNodeProps<K extends AuthorNodeKind> = AuthorNodePropsMap[K];
342
- type AuthorNode<K extends AuthorNodeKind = AuthorNodeKind> = { [NodeKind in K]: {
348
+ type BaseAuthorNode<K extends AuthorNodeKind, P, C> = {
343
349
  readonly $$typeof: "deckjsx.author-node";
344
- readonly kind: NodeKind;
345
- readonly props: AuthorNodeProps<NodeKind>;
346
- readonly children: ReadonlyArray<JsxNode>;
347
- } }[K];
350
+ readonly kind: K;
351
+ readonly props: P;
352
+ readonly children: ReadonlyArray<C>;
353
+ };
354
+ interface SlideAuthorNode extends BaseAuthorNode<"slide", SlideNodeProps, ContentJsxChild> {}
355
+ interface ViewAuthorNode extends BaseAuthorNode<"view", ViewNodeProps, ContentJsxChild> {}
356
+ interface TextAuthorNode extends BaseAuthorNode<"text", TextNodeProps, TextJsxChild> {}
357
+ interface ImageAuthorNode extends BaseAuthorNode<"image", ImageNodeProps, never> {}
358
+ interface ShapeAuthorNode extends BaseAuthorNode<"shape", ShapeNodeProps, never> {}
359
+ type AuthorNodeByKind = {
360
+ slide: SlideAuthorNode;
361
+ view: ViewAuthorNode;
362
+ text: TextAuthorNode;
363
+ image: ImageAuthorNode;
364
+ shape: ShapeAuthorNode;
365
+ };
366
+ type AuthorNode<K extends AuthorNodeKind = AuthorNodeKind> = AuthorNodeByKind[K];
367
+ type IntrinsicDivProps = ViewNodeProps & {
368
+ children?: ViewIntrinsicJsxChild;
369
+ };
370
+ type IntrinsicPProps = TextNodeProps & {
371
+ children?: TextJsxChild;
372
+ };
373
+ type IntrinsicImgProps = ImageProps;
374
+ type IntrinsicViewTag = "article" | "aside" | "div" | "figure" | "footer" | "header" | "main" | "nav" | "section";
375
+ type IntrinsicTextTag = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p";
376
+ type DeckJsxIntrinsicElements = {
377
+ img: IntrinsicImgProps;
378
+ } & { [Tag in IntrinsicViewTag]: IntrinsicDivProps } & { [Tag in IntrinsicTextTag]: IntrinsicPProps };
348
379
  //#endregion
349
380
  //#region src/jsx.d.ts
350
381
  type ComponentProps = {
@@ -359,6 +390,9 @@ type ElementChildArgs<P> = P extends {
359
390
  declare function createElement<P extends {
360
391
  children?: unknown;
361
392
  }, R extends JsxNode>(type: (props: P) => R, props: (Omit<P, "children"> & Partial<Pick<P, "children">>) | null, ...children: ElementChildArgs<P>): R;
393
+ declare function createElement(type: IntrinsicViewTag, props: (Omit<IntrinsicDivProps, "children"> & Partial<Pick<IntrinsicDivProps, "children">>) | null, ...children: ElementChildArgs<IntrinsicDivProps>): AuthorNode<"view">;
394
+ declare function createElement(type: IntrinsicTextTag, props: (Omit<IntrinsicPProps, "children"> & Partial<Pick<IntrinsicPProps, "children">>) | null, ...children: ElementChildArgs<IntrinsicPProps>): AuthorNode<"text">;
395
+ declare function createElement(type: "img", props: IntrinsicImgProps): AuthorNode<"image">;
362
396
  declare function createElement(type: string, props: ComponentProps | null): never;
363
397
  declare function Fragment(props: {
364
398
  children?: ContentJsxChild;
@@ -372,4 +406,27 @@ declare function isAuthorNode(value: unknown): value is AuthorNode;
372
406
  declare function isSlideNode(value: unknown): value is AuthorNode<"slide">;
373
407
  declare function isContentNode(value: unknown): value is ContentAuthorNode;
374
408
  //#endregion
375
- export { OutputConfig as $, CssGridLine as A, CssOverflow as B, CssAspectRatio as C, CssFlexDirection as D, CssFlexBasis as E, CssGridTemplateShorthand as F, DeckPointLength as G, CssVisibility as H, CssGridTrack as I, ImageProps as J, ImageCropAuthoring as K, CssJustifyContent as L, CssGridShorthand as M, CssGridTemplate as N, CssFlexWrap as O, CssGridTemplateAreas as P, LayoutMode as Q, CssJustifySelf as R, CssAlignSelf as S, CssDisplay as T, DeckLength as U, CssPosition as V, DeckOptions as W, ImplementedBackendName as X, ImageStyle as Y, JsxNode as Z, BorderStyle as _, TextTabStopAuthoring as _t, Text as a, SlideStyle as at, CssAlignContent as b, ViewProps as bt, isAuthorNode as c, StackAxis as ct, AuthorNode as d, StrokeLineJoin as dt, ShapeProps as et, AuthorNodeKind as f, TextFit as ft, BackendName as g, TextTabStopAlignment as gt, AuthorNodePropsMap as h, TextStyle as ht, Slide as i, SlideProps as it, CssGridPlacement as j, CssGridAutoFlow as k, isContentNode as l, StrokeDashType as lt, AuthorNodeProps as m, TextProps as mt, Image as n, SlideContext as nt, View as o, Spacing as ot, AuthorNodeMap as p, TextJsxChild as pt, ImageCropValue as q, Shape as r, SlideFactory as rt, createElement as s, StackAlignment as st, Fragment as t, ShapeStyle as tt, isSlideNode as u, StrokeLineCap as ut, ContentAuthorNode as v, TextTabStopLength as vt, CssBoxSizing as w, CssAlignItems as x, ViewStyle as xt, ContentJsxChild as y, VerticalAlign as yt, CssObjectPosition as z };
409
+ //#region src/jsx-runtime.d.ts
410
+ type JsxKey = string | number | bigint;
411
+ type JsxComponent<P, R extends JsxNode> = (props: P) => R;
412
+ type JsxProps<P> = P extends {
413
+ children?: unknown;
414
+ } ? Omit<P, "children"> & Partial<Pick<P, "children">> : P;
415
+ declare function jsx<P, R extends JsxNode>(type: JsxComponent<P, R>, props: JsxProps<P> | null, key?: JsxKey): R;
416
+ declare function jsx(type: IntrinsicViewTag, props: JsxProps<IntrinsicDivProps> | null, key?: JsxKey): JsxNode;
417
+ declare function jsx(type: IntrinsicTextTag, props: JsxProps<IntrinsicPProps> | null, key?: JsxKey): JsxNode;
418
+ declare function jsx(type: "img", props: IntrinsicImgProps, key?: JsxKey): JsxNode;
419
+ declare function jsx(type: string, props: Record<string, unknown> | null, key?: JsxKey): never;
420
+ declare const jsxs: typeof jsx;
421
+ declare namespace JSX {
422
+ type Element = ContentJsxChild;
423
+ interface ElementChildrenAttribute {
424
+ children: {};
425
+ }
426
+ interface IntrinsicAttributes {
427
+ key?: JsxKey;
428
+ }
429
+ interface IntrinsicElements extends DeckJsxIntrinsicElements {}
430
+ }
431
+ //#endregion
432
+ export { ImageProps as $, CssFlexBasis as A, ViewProps as At, CssGridTrack as B, ContentJsxChild as C, TextJsxChild as Ct, CssAspectRatio as D, TextTabStopAuthoring as Dt, CssAlignSelf as E, TextTabStopAlignment as Et, CssGridPlacement as F, CssPosition as G, CssJustifySelf as H, CssGridShorthand as I, DeckLength as J, CssVisibility as K, CssGridTemplate as L, CssFlexWrap as M, CssGridAutoFlow as N, CssBoxSizing as O, TextTabStopLength as Ot, CssGridLine as P, ImageCropValue as Q, CssGridTemplateAreas as R, ContentAuthorNode as S, TextFit as St, CssAlignItems as T, TextStyle as Tt, CssObjectPosition as U, CssJustifyContent as V, CssOverflow as W, DeckPointLength as X, DeckOptions as Y, ImageCropAuthoring as Z, AuthorNodeMap as _, StackAlignment as _t, Fragment as a, IntrinsicTextTag as at, BackendName as b, StrokeLineCap as bt, Slide as c, LayoutMode as ct, createElement as d, ShapeStyle as dt, ImageStyle as et, isAuthorNode as f, SlideContext as ft, AuthorNodeKind as g, Spacing as gt, AuthorNode as h, SlideStyle as ht, jsxs as i, IntrinsicPProps as it, CssFlexDirection as j, ViewStyle as jt, CssDisplay as k, VerticalAlign as kt, Text as l, OutputConfig as lt, isSlideNode as m, SlideProps as mt, JsxKey as n, IntrinsicDivProps as nt, Image as o, IntrinsicViewTag as ot, isContentNode as p, SlideFactory as pt, DeckJsxIntrinsicElements as q, jsx as r, IntrinsicImgProps as rt, Shape as s, JsxNode as st, JSX as t, ImplementedBackendName as tt, View as u, ShapeProps as ut, AuthorNodeProps as v, StackAxis as vt, CssAlignContent as w, TextProps as wt, BorderStyle as x, StrokeLineJoin as xt, AuthorNodePropsMap as y, StrokeDashType as yt, CssGridTemplateShorthand as z };
@@ -1,19 +1,2 @@
1
- import { Z as JsxNode, t as Fragment, y as ContentJsxChild } from "./jsx-CrQPDEqU.mjs";
2
-
3
- //#region src/jsx-runtime.d.ts
4
- type JsxComponent<P, R extends JsxNode> = (props: P) => R;
5
- type JsxProps<P> = P extends {
6
- children?: unknown;
7
- } ? Omit<P, "children"> & Partial<Pick<P, "children">> : P;
8
- declare function jsx<P, R extends JsxNode>(type: JsxComponent<P, R>, props: JsxProps<P> | null, key?: string): R;
9
- declare function jsx(type: string, props: Record<string, unknown> | null, key?: string): never;
10
- declare const jsxs: typeof jsx;
11
- declare namespace JSX {
12
- type Element = ContentJsxChild;
13
- interface ElementChildrenAttribute {
14
- children: {};
15
- }
16
- interface IntrinsicElements {}
17
- }
18
- //#endregion
19
- export { Fragment, JSX, jsx, jsxs };
1
+ import { a as Fragment, i as jsxs, n as JsxKey, r as jsx, t as JSX } from "./jsx-runtime-BWV9tOov.mjs";
2
+ export { Fragment, JSX, JsxKey, jsx, jsxs };
@@ -1,4 +1,4 @@
1
- import { s as createElement, t as Fragment } from "./jsx-5H4Zgl79.mjs";
1
+ import { s as createElement, t as Fragment } from "./jsx-lqMAdW2X.mjs";
2
2
  //#region src/jsx-runtime.ts
3
3
  function jsx(type, props, _key) {
4
4
  return createElement(type, props);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deckjsx",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Generate PowerPoint presentations from TSX/JSX through a compiler pipeline.",
5
5
  "license": "MIT",
6
6
  "author": "deckjsx contributors",
@@ -27,6 +27,7 @@
27
27
  "dev": "vp pack --watch",
28
28
  "test": "vp test",
29
29
  "check": "vp check",
30
+ "verify:render": "bun run scripts/verify-render.ts",
30
31
  "prepublishOnly": "vp run build"
31
32
  },
32
33
  "dependencies": {
@@ -1,66 +0,0 @@
1
- //#region src/jsx.ts
2
- function isRecord(value) {
3
- return typeof value === "object" && value !== null;
4
- }
5
- function isJsxNode(value) {
6
- 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));
7
- }
8
- function requireJsxNode(value) {
9
- if (isJsxNode(value)) return value;
10
- throw new Error("JSX children must be deckjsx nodes or primitive text values.");
11
- }
12
- function flattenChildren(input) {
13
- if (Array.isArray(input)) return input.flatMap((item) => flattenChildren(item));
14
- return [input];
15
- }
16
- function authorNode(kind, props) {
17
- const { children: rawChildren, ...nodeProps } = props;
18
- return {
19
- $$typeof: "deckjsx.author-node",
20
- kind,
21
- props: nodeProps,
22
- children: rawChildren === void 0 ? [] : flattenChildren(rawChildren)
23
- };
24
- }
25
- function createElement(type, props, ...children) {
26
- if (typeof type === "string") throw new Error(`Intrinsic elements are not supported: <${type}>.`);
27
- if (typeof type !== "function") throw new Error("JSX element type must be a function component.");
28
- const propsObject = isRecord(props) ? props : {};
29
- return type({
30
- ...propsObject,
31
- children: children.length === 0 ? requireJsxNode(propsObject.children) : children.length === 1 ? requireJsxNode(children[0]) : children.map((child) => requireJsxNode(child))
32
- });
33
- }
34
- function Fragment(props) {
35
- return props.children ?? null;
36
- }
37
- function Slide(props) {
38
- return authorNode("slide", props);
39
- }
40
- function View(props) {
41
- return authorNode("view", props);
42
- }
43
- function Text(props) {
44
- return authorNode("text", props);
45
- }
46
- function Image(props) {
47
- return authorNode("image", props);
48
- }
49
- function Shape(props) {
50
- return authorNode("shape", props);
51
- }
52
- function isAuthorNodeKind(value) {
53
- return value === "slide" || value === "view" || value === "text" || value === "image" || value === "shape";
54
- }
55
- function isAuthorNode(value) {
56
- if (!isRecord(value)) return false;
57
- return value.$$typeof === "deckjsx.author-node" && isAuthorNodeKind(value.kind) && isRecord(value.props) && Array.isArray(value.children);
58
- }
59
- function isSlideNode(value) {
60
- return isAuthorNode(value) && value.kind === "slide";
61
- }
62
- function isContentNode(value) {
63
- return isAuthorNode(value) && value.kind !== "slide";
64
- }
65
- //#endregion
66
- 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 };