pptxgenjs-plus-jsx 4.3.0 → 4.3.2
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/LICENSE +23 -23
- package/README.md +741 -741
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/markdown/fromMarkdown.d.ts +6 -0
- package/dist/markdown/fromMarkdown.js +104 -10
- package/dist/markdown/fromMarkdown.js.map +1 -1
- package/dist/markdown/index.d.ts +1 -1
- package/dist/markdown/index.js +1 -1
- package/dist/markdown/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,741 +1,741 @@
|
|
|
1
|
-
# pptxgenjs-plus-jsx
|
|
2
|
-
|
|
3
|
-
A JSX runtime for building PowerPoint presentations with [pptxgenjs-plus](https://github.com/lofcz/pptxgenjs-plus). Write your slides as JSX components and render them to `.pptx` files.
|
|
4
|
-
|
|
5
|
-
```tsx
|
|
6
|
-
import { Deck, Slide, Text, TextRun, Rect } from "pptxgenjs-plus-jsx";
|
|
7
|
-
import { renderPptx } from "pptxgenjs-plus-jsx/render";
|
|
8
|
-
|
|
9
|
-
await renderPptx(
|
|
10
|
-
<Deck title="My Deck">
|
|
11
|
-
<Slide>
|
|
12
|
-
<Rect x={0} y={0} w={13.333} h={7.5} fill={{ color: "1E1E2E" }} />
|
|
13
|
-
<Text x={1} y={3} w={11} h={1.5}>
|
|
14
|
-
<TextRun options={{ fontSize: 44, color: "FFFFFF", bold: true }}>
|
|
15
|
-
Hello, PowerPoint!
|
|
16
|
-
</TextRun>
|
|
17
|
-
</Text>
|
|
18
|
-
</Slide>
|
|
19
|
-
</Deck>,
|
|
20
|
-
{ fileName: "output.pptx" },
|
|
21
|
-
);
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Table of Contents
|
|
25
|
-
|
|
26
|
-
- [Installation](#installation)
|
|
27
|
-
- [TypeScript Configuration](#typescript-configuration)
|
|
28
|
-
- [Component Reference](#component-reference)
|
|
29
|
-
- [Deck & Presentation](#deck--presentation)
|
|
30
|
-
- [Slide](#slide)
|
|
31
|
-
- [Text & TextRun](#text--textrun)
|
|
32
|
-
- [FixedBox](#fixedbox)
|
|
33
|
-
- [Shapes](#shapes)
|
|
34
|
-
- [Charts](#charts)
|
|
35
|
-
- [Tables](#tables)
|
|
36
|
-
- [Images & Media](#images--media)
|
|
37
|
-
- [Group](#group)
|
|
38
|
-
- [Raw (escape hatch)](#raw-escape-hatch)
|
|
39
|
-
- [Fragment](#fragment)
|
|
40
|
-
- [Async Components](#async-components)
|
|
41
|
-
- [Context Hooks](#context-hooks)
|
|
42
|
-
- [useSlideContext](#useslidecontext)
|
|
43
|
-
- [useDeckContext](#usedeckcontext)
|
|
44
|
-
- [useGroupContext](#usegroupcontext)
|
|
45
|
-
- [Lazy Slide Loading](#lazy-slide-loading)
|
|
46
|
-
- [Percentage Coordinates](#percentage-coordinates)
|
|
47
|
-
- [Sections & Masters](#sections--masters)
|
|
48
|
-
- [Validation](#validation)
|
|
49
|
-
- [Rendering](#rendering)
|
|
50
|
-
- [License](#license)
|
|
51
|
-
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
## Installation
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
npm install pptxgenjs-plus-jsx
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Peer dependency:
|
|
61
|
-
|
|
62
|
-
- **[pptxgenjs-plus](https://github.com/lofcz/pptxgenjs-plus)** — workspace dependency in this monorepo.
|
|
63
|
-
|
|
64
|
-
## TypeScript Configuration
|
|
65
|
-
|
|
66
|
-
Set `jsx` and `jsxImportSource` in your `tsconfig.json`:
|
|
67
|
-
|
|
68
|
-
```json
|
|
69
|
-
{
|
|
70
|
-
"compilerOptions": {
|
|
71
|
-
"jsx": "react-jsx",
|
|
72
|
-
"jsxImportSource": "pptxgenjs-plus-jsx"
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
> **Note**: This is **not** React — the JSX transform produces `PptxNode` objects, not DOM elements. No React dependency is required.
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
## Component Reference
|
|
82
|
-
|
|
83
|
-
### Deck / Presentation
|
|
84
|
-
|
|
85
|
-
The root element of every presentation. Maps to `new PptxGenJS()`.
|
|
86
|
-
|
|
87
|
-
```tsx
|
|
88
|
-
<Deck>
|
|
89
|
-
<Slide>...</Slide>
|
|
90
|
-
</Deck>
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
`<Presentation>` is an alias for `<Deck>`.
|
|
94
|
-
|
|
95
|
-
#### Layout
|
|
96
|
-
|
|
97
|
-
Use the `layout` prop to control slide dimensions. Two forms are supported:
|
|
98
|
-
|
|
99
|
-
**1. Built-in layout name** (string) — pptxgenjs provides four standard presets:
|
|
100
|
-
|
|
101
|
-
| Name | Dimensions | Aspect Ratio |
|
|
102
|
-
| ---------------- | ------------- | ------------ |
|
|
103
|
-
| `"LAYOUT_4x3"` | 10" × 7.5" | 4:3 |
|
|
104
|
-
| `"LAYOUT_16x9"` | 10" × 5.625" | 16:9 |
|
|
105
|
-
| `"LAYOUT_16x10"` | 10" × 6.25" | 16:10 |
|
|
106
|
-
| `"LAYOUT_WIDE"` | 13.33" × 7.5" | 16:9 (wide) |
|
|
107
|
-
|
|
108
|
-
Default: `"LAYOUT_WIDE"` (13.33" × 7.5").
|
|
109
|
-
|
|
110
|
-
```tsx
|
|
111
|
-
<Deck layout="LAYOUT_16x9">
|
|
112
|
-
<Slide>...</Slide>
|
|
113
|
-
</Deck>
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
**2. Custom layout** (object) — define arbitrary dimensions via a `PresLayout` object with `name`, `width`, and `height` (in inches):
|
|
117
|
-
|
|
118
|
-
```tsx
|
|
119
|
-
<Deck layout={{ name: "A4", width: 10.83, height: 7.82 }}>
|
|
120
|
-
<Slide>...</Slide>
|
|
121
|
-
</Deck>
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
For multiple custom layouts, use the `layouts` prop (array of `PresLayout`):
|
|
125
|
-
|
|
126
|
-
```tsx
|
|
127
|
-
<Deck
|
|
128
|
-
layout="A4"
|
|
129
|
-
layouts={[
|
|
130
|
-
{ name: "A4", width: 10.83, height: 7.82 },
|
|
131
|
-
{ name: "Letter", width: 10, height: 7.5 },
|
|
132
|
-
]}
|
|
133
|
-
>
|
|
134
|
-
<Slide>...</Slide>
|
|
135
|
-
</Deck>
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
The first matching layout name becomes the presentation's active layout.
|
|
139
|
-
|
|
140
|
-
### Slide
|
|
141
|
-
|
|
142
|
-
A single slide. Maps to `pptx.addSlide()`.
|
|
143
|
-
|
|
144
|
-
```tsx
|
|
145
|
-
<Slide>
|
|
146
|
-
<Text>A simple slide</Text>
|
|
147
|
-
</Slide>
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
**Lazy-loaded slide** (see [Lazy Slide Loading](#lazy-slide-loading)):
|
|
151
|
-
|
|
152
|
-
```tsx
|
|
153
|
-
<Slide component={() => import("./slides/chart-slide")} />
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
### Text & TextRun
|
|
157
|
-
|
|
158
|
-
**`<Text>`** — a text box or rich text container. Maps to `slide.addText()`.
|
|
159
|
-
|
|
160
|
-
```tsx
|
|
161
|
-
// Simple text (string from children)
|
|
162
|
-
<Text x={1} y={1} w={8} h={1} fontSize={24} color="333333">
|
|
163
|
-
Hello, World!
|
|
164
|
-
</Text>
|
|
165
|
-
|
|
166
|
-
// Rich text with multiple TextRun elements
|
|
167
|
-
<Text x={1} y={2.5} w={8} h={1.5} valign="middle">
|
|
168
|
-
<TextRun options={{ fontSize: 18, color: "666666" }}>Normal text </TextRun>
|
|
169
|
-
<TextRun options={{ fontSize: 18, color: "0066CC", bold: true }}>
|
|
170
|
-
bold and blue
|
|
171
|
-
</TextRun>
|
|
172
|
-
</Text>
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
**`<TextRun>`** — a single formatted run inside `<Text>`. `options` accepts pptxgenjs `TextProps` (fontSize, color, bold, italic, fontFace, etc.). The run's text comes from its string children (or the `text` prop):
|
|
176
|
-
|
|
177
|
-
```tsx
|
|
178
|
-
<TextRun options={{ fontSize: 18, color: "0066CC", bold: true }}>bold and blue</TextRun>
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
**Text input modes.** A `<Text>` element has four ways to receive content. When more than one is present, this priority applies (higher wins, the rest is ignored):
|
|
182
|
-
|
|
183
|
-
1. child `<TextRun />` nodes — plain string/number children mixed among them are converted to default-style runs (order preserved)
|
|
184
|
-
2. the `runs` prop (rich text array — same shape as pptxgenjs `TextProps[]`)
|
|
185
|
-
3. the `text` prop
|
|
186
|
-
4. plain-string children
|
|
187
|
-
|
|
188
|
-
Plain strings mix freely with `<TextRun />` children — each string segment becomes a default-style run in place:
|
|
189
|
-
|
|
190
|
-
```tsx
|
|
191
|
-
<Text x={1} y={4} w={8} h={1}>
|
|
192
|
-
{"Normal segment "}
|
|
193
|
-
<TextRun options={{ color: "0066CC", bold: true }}>highlighted</TextRun>
|
|
194
|
-
</Text>
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
Whitespace-only text between elements (e.g. from multi-line JSX formatting) is ignored — attach explicit spaces to a run's text (`<TextRun>A </TextRun>`) instead. Mixing the other modes (e.g. `runs` or `text` props alongside children) still drops the lower-priority content.
|
|
198
|
-
|
|
199
|
-
```tsx
|
|
200
|
-
// runs prop (imperative rich text)
|
|
201
|
-
<Text
|
|
202
|
-
x={1}
|
|
203
|
-
y={1}
|
|
204
|
-
w={8}
|
|
205
|
-
h={1}
|
|
206
|
-
runs={[
|
|
207
|
-
{ text: "Normal ", options: { fontSize: 18 } },
|
|
208
|
-
{ text: "bold", options: { fontSize: 18, bold: true } },
|
|
209
|
-
]}
|
|
210
|
-
/>
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
**Text with a shape background.** `shape` is a valid pptxgenjs text option and is forwarded to `slide.addText()`:
|
|
214
|
-
|
|
215
|
-
```tsx
|
|
216
|
-
<Text
|
|
217
|
-
x={1}
|
|
218
|
-
y={1}
|
|
219
|
-
w={4}
|
|
220
|
-
h={2}
|
|
221
|
-
shape="roundRect"
|
|
222
|
-
fill={{ color: "EDE9FE" }}
|
|
223
|
-
margin={18} // text margin uses POINTS (~0.25"), not inches
|
|
224
|
-
valign="middle"
|
|
225
|
-
>
|
|
226
|
-
Shaped text box
|
|
227
|
-
</Text>
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
> Note: pptxgenjs text `margin` values are in **points** (e.g. `18` ≈ 0.25"), not inches.
|
|
231
|
-
|
|
232
|
-
### FixedBox
|
|
233
|
-
|
|
234
|
-
A **fixed-size** text box. Pass CommonMark plus TeX delimiters; the box stays at the authored `x/y/w/h` and PowerPoint shrink-to-fit scales the content (`fit="shrink"`).
|
|
235
|
-
|
|
236
|
-
- Headings, paragraphs, `**bold**` / `*italic*`, and lists become native PPTX runs (real bullets / numbered lists).
|
|
237
|
-
- `$…$` (inline) and `$$…$$` (display) — also `\(…\)`, `\[…\]`, `\begin{env}` — become editable OMML via MathLive + mathml2omml-plus. No extra helper, no image raster.
|
|
238
|
-
|
|
239
|
-
```tsx
|
|
240
|
-
<FixedBox
|
|
241
|
-
x={0.7}
|
|
242
|
-
y={1.5}
|
|
243
|
-
w={6}
|
|
244
|
-
h={4}
|
|
245
|
-
fontSize={18}
|
|
246
|
-
color="0F172A"
|
|
247
|
-
markdown={`
|
|
248
|
-
# Title
|
|
249
|
-
- item one
|
|
250
|
-
- item with $a^2+b^2=c^2$
|
|
251
|
-
|
|
252
|
-
$$\\frac{1}{2}$$
|
|
253
|
-
`}
|
|
254
|
-
/>
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
`fromMarkdown`, `tokenizeMath`, `latexToOmml`, and `mathRun` are also exported from the package root when you need runs without the component.
|
|
258
|
-
|
|
259
|
-
### Shapes
|
|
260
|
-
|
|
261
|
-
All pptxgenjs shapes are available as JSX components. Each supports standard positioning props (`x`, `y`, `w`, `h`) plus shape-specific options via `options` or as top-level props.
|
|
262
|
-
|
|
263
|
-
> **Shapes are leaf elements** — they do not render children. Nested content
|
|
264
|
-
> (e.g. `<RoundRect><Text>…</Text></RoundRect>`) is a compile-time error in TSX
|
|
265
|
-
> and a hard runtime error otherwise; it is never silently dropped.
|
|
266
|
-
>
|
|
267
|
-
> To put text on a shape, use **one** of:
|
|
268
|
-
>
|
|
269
|
-
> 1. A single text box with a shape background: `<Text shape="roundRect" …>` (recommended when the text and shape share one box — see [Text & TextRun](#text--textrun)).
|
|
270
|
-
> 2. A sibling `<Text>` layered over the shape (when text and shape need independent styles/shadows/geometry).
|
|
271
|
-
> 3. A `<Group>` only when you need a relative coordinate system or want to move/scale the pair together.
|
|
272
|
-
|
|
273
|
-
```tsx
|
|
274
|
-
<Rect x={0} y={0} w={13.333} h={7.5} fill={{ color: "1E1E2E" }} />
|
|
275
|
-
<Ellipse x={1} y={1} w={3} h={2} fill={{ color: "FF6B6B" }} />
|
|
276
|
-
<Triangle x={5} y={1} w={2} h={2} fill={{ color: "4ECDC4" }} />
|
|
277
|
-
<RoundRect x={1} y={4} w={4} h={2} fill={{ color: "45B7D1" }} rectRadius={0.3} />
|
|
278
|
-
<Line x={1} y={1} w={5} h={0} line={{ color: "FF0000", width: 2 }} />
|
|
279
|
-
<Cloud x={1} y={1} w={3} h={2} fill={{ color: "E8F4FD" }} />
|
|
280
|
-
<Heart x={5} y={1} w={2} h={2} fill={{ color: "FF4081" }} />
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
**`<LineBetween>`** — a line connecting two absolute coordinates. Supports percentage coordinates.
|
|
284
|
-
|
|
285
|
-
```tsx
|
|
286
|
-
<LineBetween
|
|
287
|
-
x1={0}
|
|
288
|
-
y1={0}
|
|
289
|
-
x2={13.333}
|
|
290
|
-
y2={7.5}
|
|
291
|
-
line={{ color: "999999", width: 1, dashType: "dash" }}
|
|
292
|
-
/>
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
Available shape components:
|
|
296
|
-
|
|
297
|
-
| Component | pptxgenjs shape |
|
|
298
|
-
| -------------------------- | ----------------------------------- |
|
|
299
|
-
| `Rect` | `rect` |
|
|
300
|
-
| `RoundRect` | `roundRect` |
|
|
301
|
-
| `Ellipse` / `Oval` | `ellipse` |
|
|
302
|
-
| `Triangle` | `triangle` |
|
|
303
|
-
| `RightTriangle` | `rtTriangle` |
|
|
304
|
-
| `Diamond` | `diamond` |
|
|
305
|
-
| `Pentagon` | `pentagon` |
|
|
306
|
-
| `Hexagon` | `hexagon` |
|
|
307
|
-
| `Star` / `Star5` | `star5` |
|
|
308
|
-
| `Star4` | `star4` |
|
|
309
|
-
| `Star6` | `star6` |
|
|
310
|
-
| `Star8` | `star8` |
|
|
311
|
-
| `Star10` | `star10` |
|
|
312
|
-
| `Line` | `line` |
|
|
313
|
-
| `LineBetween` | `line` (with computed bounding box) |
|
|
314
|
-
| `Arc` | `arc` |
|
|
315
|
-
| `BlockArc` | `blockArc` |
|
|
316
|
-
| `PieShape` | `pie` |
|
|
317
|
-
| `CustomGeometry` | `custGeom` |
|
|
318
|
-
| `LeftArrow` / `RightArrow` | `leftArrow` / `rightArrow` |
|
|
319
|
-
| `UpArrow` / `DownArrow` | `upArrow` / `downArrow` |
|
|
320
|
-
| `LeftRightArrow` | `leftRightArrow` |
|
|
321
|
-
| `UpDownArrow` | `upDownArrow` |
|
|
322
|
-
| `Chevron` | `chevron` |
|
|
323
|
-
| `Cloud` | `cloud` |
|
|
324
|
-
| `Heart` | `heart` |
|
|
325
|
-
| `Donut` | `donut` |
|
|
326
|
-
| `Plus` | `plus` |
|
|
327
|
-
|
|
328
|
-
### Charts
|
|
329
|
-
|
|
330
|
-
```tsx
|
|
331
|
-
// Generic chart with explicit `type`
|
|
332
|
-
<Chart
|
|
333
|
-
x={1} y={1} w={10} h={5}
|
|
334
|
-
type="bar"
|
|
335
|
-
data={[
|
|
336
|
-
{ name: "Q1", labels: ["Jan", "Feb", "Mar"], values: [100, 150, 200] },
|
|
337
|
-
{ name: "Q2", labels: ["Jan", "Feb", "Mar"], values: [120, 180, 160] },
|
|
338
|
-
]}
|
|
339
|
-
showTitle="Quarterly Sales"
|
|
340
|
-
showLegend={true}
|
|
341
|
-
/>
|
|
342
|
-
|
|
343
|
-
// Or use a typed chart component
|
|
344
|
-
<BarChart x={1} y={1} w={10} h={5} data={[...]} showValue={true} />
|
|
345
|
-
<LineChart x={1} y={1} w={10} h={5} data={[...]} lineSize={3} />
|
|
346
|
-
<PieChart x={1} y={1} w={6} h={5} data={[...]} showPercent={true} />
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
Available chart components: `AreaChart`, `BarChart`, `Bar3DChart`, `BubbleChart`, `DoughnutChart`, `LineChart`, `PieChart`, `RadarChart`, `ScatterChart`.
|
|
350
|
-
|
|
351
|
-
### Tables
|
|
352
|
-
|
|
353
|
-
```tsx
|
|
354
|
-
<Table x={1} y={1} w={10} h={3} fontSize={12} border={{ type: "solid", color: "CCCCCC" }}>
|
|
355
|
-
<TableRow>
|
|
356
|
-
<TableCell options={{ fill: { color: "4472C4" }, color: "FFFFFF", bold: true }}>Name</TableCell>
|
|
357
|
-
<TableCell options={{ fill: { color: "4472C4" }, color: "FFFFFF", bold: true }}>
|
|
358
|
-
Value
|
|
359
|
-
</TableCell>
|
|
360
|
-
</TableRow>
|
|
361
|
-
<TableRow>
|
|
362
|
-
<TableCell>Item A</TableCell>
|
|
363
|
-
<TableCell>100</TableCell>
|
|
364
|
-
</TableRow>
|
|
365
|
-
<TableRow>
|
|
366
|
-
<TableCell>Item B</TableCell>
|
|
367
|
-
<TableCell>200</TableCell>
|
|
368
|
-
</TableRow>
|
|
369
|
-
</Table>
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
`TableToSlides` splits an HTML table across multiple slides (browser runtime only).
|
|
373
|
-
|
|
374
|
-
### Images & Media
|
|
375
|
-
|
|
376
|
-
```tsx
|
|
377
|
-
<Image
|
|
378
|
-
x={1} y={1} w={5} h={3}
|
|
379
|
-
path="https://example.com/image.png"
|
|
380
|
-
sizing={{ type: "contain", w: 5, h: 3 }}
|
|
381
|
-
/>
|
|
382
|
-
|
|
383
|
-
<Media
|
|
384
|
-
x={1} y={1} w={6} h={4}
|
|
385
|
-
path="https://example.com/video.mp4"
|
|
386
|
-
mediaType="video"
|
|
387
|
-
/>
|
|
388
|
-
```
|
|
389
|
-
|
|
390
|
-
### Group
|
|
391
|
-
|
|
392
|
-
A PresentationML group (`p:grpSp`). Child coordinates are relative to the group's origin. Maps to `slide.addGroup()`.
|
|
393
|
-
|
|
394
|
-
```tsx
|
|
395
|
-
<Group x={1} y={1} w={10} h={5}>
|
|
396
|
-
{/* (0, 0) inside group → group-relative; the group itself sits at (1, 1) */}
|
|
397
|
-
<Rect x={0} y={0} w={10} h={5} fill={{ color: "F0F0F0" }} />
|
|
398
|
-
{/* "50%" inside group → 5" from the group origin */}
|
|
399
|
-
<Text x="50%" y="50%" w={4} h={1}>
|
|
400
|
-
<TextRun options={{ fontSize: 18 }}>Centered in group</TextRun>
|
|
401
|
-
</Text>
|
|
402
|
-
</Group>
|
|
403
|
-
```
|
|
404
|
-
|
|
405
|
-
Key features:
|
|
406
|
-
|
|
407
|
-
- **Native group shape**: children move and transform together in PowerPoint.
|
|
408
|
-
- **Coordinate transformation**: Child `x`, `y`, `w`, `h` are relative to the group origin. Percentage strings resolve against the group's `w` (for x/w) or `h` (for y/h).
|
|
409
|
-
- **Nested groups**: Groups can nest via `group.addGroup()`.
|
|
410
|
-
- **Valid children**: shapes, text, images, and nested groups. Tables, charts, media, notes, and WordArt must stay on the slide.
|
|
411
|
-
- **Context-aware**: Children can use `useGroupContext()` for the group's virtual canvas (`width` / `height`) and slide origin (`x` / `y`).
|
|
412
|
-
|
|
413
|
-
### Raw (escape hatch)
|
|
414
|
-
|
|
415
|
-
For pptxgenjs features not covered by a dedicated component.
|
|
416
|
-
|
|
417
|
-
```tsx
|
|
418
|
-
<Raw
|
|
419
|
-
render={({ pptx, slide, node }) => {
|
|
420
|
-
// Direct access to slide.addShape(), slide.addText(), etc.
|
|
421
|
-
slide.addShape("rect", { x: 1, y: 1, w: 5, h: 3, fill: { color: "FF0000" } });
|
|
422
|
-
}}
|
|
423
|
-
/>
|
|
424
|
-
```
|
|
425
|
-
|
|
426
|
-
> Raw children are **not** auto-rendered — they are only accessible via
|
|
427
|
-
> `context.node.children` inside the `render` callback. Use props for
|
|
428
|
-
> configuration; use children only when the callback reads them itself.
|
|
429
|
-
|
|
430
|
-
### Fragment
|
|
431
|
-
|
|
432
|
-
Groups multiple children without producing a wrapper element. Useful when a component needs to return multiple siblings (e.g., in a lazy-loaded slide or inside a map).
|
|
433
|
-
|
|
434
|
-
**Shorthand form `<>...</>`** — for simple grouping without props:
|
|
435
|
-
|
|
436
|
-
```tsx
|
|
437
|
-
// slides/title-slide.tsx
|
|
438
|
-
export default function TitleSlide() {
|
|
439
|
-
return (
|
|
440
|
-
<>
|
|
441
|
-
<Text x={1} y={3} w={10} h={1.5} fontSize={44} bold>
|
|
442
|
-
Welcome
|
|
443
|
-
</Text>
|
|
444
|
-
<Text x={1} y={4.5} w={10} h={1} fontSize={18} color="666666">
|
|
445
|
-
Subtitle text
|
|
446
|
-
</Text>
|
|
447
|
-
</>
|
|
448
|
-
);
|
|
449
|
-
}
|
|
450
|
-
```
|
|
451
|
-
|
|
452
|
-
**Explicit `<Fragment>`** — when you need a `key` prop (e.g., in a `.map()` loop):
|
|
453
|
-
|
|
454
|
-
```tsx
|
|
455
|
-
import { Fragment } from "pptxgenjs-plus-jsx";
|
|
456
|
-
|
|
457
|
-
<Slide>
|
|
458
|
-
{items.map((item) => (
|
|
459
|
-
<Fragment key={item.id}>
|
|
460
|
-
<Text x={1} y={item.y}>
|
|
461
|
-
{item.name}
|
|
462
|
-
</Text>
|
|
463
|
-
<Text x={5} y={item.y}>
|
|
464
|
-
{item.value}
|
|
465
|
-
</Text>
|
|
466
|
-
</Fragment>
|
|
467
|
-
))}
|
|
468
|
-
</Slide>;
|
|
469
|
-
```
|
|
470
|
-
|
|
471
|
-
> **Note**: `<>...</>` is a JSX compile-time syntax — it does not support props like `key`. For dynamic lists, always use `<Fragment key={...}>`.
|
|
472
|
-
|
|
473
|
-
---
|
|
474
|
-
|
|
475
|
-
## Async Components
|
|
476
|
-
|
|
477
|
-
Components can be `async` functions — they are automatically detected and lazily resolved during rendering:
|
|
478
|
-
|
|
479
|
-
```tsx
|
|
480
|
-
// slides/data-slide.tsx
|
|
481
|
-
export default async function DataSlide() {
|
|
482
|
-
const res = await fetch("https://api.example.com/data");
|
|
483
|
-
const data = await res.json();
|
|
484
|
-
|
|
485
|
-
return (
|
|
486
|
-
<Slide>
|
|
487
|
-
<Text x={1} y={1} w={8} h={1} fontSize={32} bold>
|
|
488
|
-
{data.title}
|
|
489
|
-
</Text>
|
|
490
|
-
<Text x={1} y={2.5} w={8} h={4} fontSize={16}>
|
|
491
|
-
{data.description}
|
|
492
|
-
</Text>
|
|
493
|
-
</Slide>
|
|
494
|
-
);
|
|
495
|
-
}
|
|
496
|
-
```
|
|
497
|
-
|
|
498
|
-
```tsx
|
|
499
|
-
// main.tsx
|
|
500
|
-
await renderPptx(
|
|
501
|
-
<Deck>
|
|
502
|
-
<Slide>{/* ... */}</Slide>
|
|
503
|
-
<DataSlide /> {/* async — resolves automatically */}
|
|
504
|
-
</Deck>,
|
|
505
|
-
{ fileName: "output.pptx" },
|
|
506
|
-
);
|
|
507
|
-
```
|
|
508
|
-
|
|
509
|
-
This works because the JSX factory (`jsx`) wraps async component results in a `PptxNodePromise`, and the renderer resolves them during tree traversal.
|
|
510
|
-
|
|
511
|
-
---
|
|
512
|
-
|
|
513
|
-
## Context Hooks
|
|
514
|
-
|
|
515
|
-
Context hooks provide runtime information about the current rendering environment.
|
|
516
|
-
|
|
517
|
-
**How it works**: When TypeScript compiles your JSX, component factories are NOT called during JSX construction. Instead, they are wrapped in a deferred node and executed later during rendering — at which point the renderer has set up the context store via `AsyncLocalStorage`. This is why you can write components that call `useSlideContext()` as direct children of `<Slide>`, even though the JSX appears to be built "eagerly."
|
|
518
|
-
|
|
519
|
-
### useSlideContext
|
|
520
|
-
|
|
521
|
-
Exposes the current slide's index and total.
|
|
522
|
-
|
|
523
|
-
```tsx
|
|
524
|
-
import { useSlideContext } from "pptxgenjs-plus-jsx";
|
|
525
|
-
|
|
526
|
-
function SlideNumber() {
|
|
527
|
-
const { index, total, sectionTitle } = useSlideContext();
|
|
528
|
-
|
|
529
|
-
return (
|
|
530
|
-
<Text x={1} y={6.5} w={10} h={0.5} fontSize={10} color="999999">
|
|
531
|
-
Slide {index} of {total}
|
|
532
|
-
{sectionTitle ? ` · ${sectionTitle}` : ""}
|
|
533
|
-
</Text>
|
|
534
|
-
);
|
|
535
|
-
}
|
|
536
|
-
```
|
|
537
|
-
|
|
538
|
-
```tsx
|
|
539
|
-
// Usage inside a Slide:
|
|
540
|
-
<Slide>
|
|
541
|
-
{/* ... slide content ... */}
|
|
542
|
-
<SlideNumber />
|
|
543
|
-
</Slide>
|
|
544
|
-
```
|
|
545
|
-
|
|
546
|
-
### useDeckContext
|
|
547
|
-
|
|
548
|
-
Exposes the deck's slide dimensions (width, height in inches).
|
|
549
|
-
|
|
550
|
-
```tsx
|
|
551
|
-
import { useDeckContext } from "pptxgenjs-plus-jsx";
|
|
552
|
-
|
|
553
|
-
function FullBleedBackground() {
|
|
554
|
-
const { width, height } = useDeckContext();
|
|
555
|
-
return <Rect x={0} y={0} w={width} h={height} fill={{ color: "1E1E2E" }} />;
|
|
556
|
-
}
|
|
557
|
-
```
|
|
558
|
-
|
|
559
|
-
### useGroupContext
|
|
560
|
-
|
|
561
|
-
Exposes the current group's origin on the slide and its virtual canvas. When called outside a `<Group>`, falls back to deck dimensions with zero offset (`relative: false`). Inside a group, child coordinates are group-relative (`relative: true`).
|
|
562
|
-
|
|
563
|
-
```tsx
|
|
564
|
-
import { useGroupContext } from "pptxgenjs-plus-jsx";
|
|
565
|
-
|
|
566
|
-
function ProgressBar() {
|
|
567
|
-
const { width } = useGroupContext();
|
|
568
|
-
return <Rect x={0} y={0} w={width * 0.7} h={0.4} fill={{ color: "4CAF50" }} />;
|
|
569
|
-
}
|
|
570
|
-
```
|
|
571
|
-
|
|
572
|
-
---
|
|
573
|
-
|
|
574
|
-
## Lazy Slide Loading
|
|
575
|
-
|
|
576
|
-
Use the `component` prop on `<Slide>` to defer loading of slide definitions — analogous to React Router's lazy route loading.
|
|
577
|
-
|
|
578
|
-
```tsx
|
|
579
|
-
// slides/title-slide.tsx
|
|
580
|
-
export default function TitleSlide() {
|
|
581
|
-
return (
|
|
582
|
-
<>
|
|
583
|
-
<Text x={1} y={3} w={10} h={1.5} fontSize={44} bold>
|
|
584
|
-
Welcome
|
|
585
|
-
</Text>
|
|
586
|
-
</>
|
|
587
|
-
);
|
|
588
|
-
}
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
```tsx
|
|
592
|
-
// main.tsx
|
|
593
|
-
<Slide component={() => import("./slides/title-slide")} />
|
|
594
|
-
```
|
|
595
|
-
|
|
596
|
-
The component's return value is rendered **inside** the `<Slide>` that declares `component`, so it should provide slide **content only** — not another `<Slide>` element. Context hooks work inside lazy-loaded components.
|
|
597
|
-
|
|
598
|
-
---
|
|
599
|
-
|
|
600
|
-
## Percentage Coordinates
|
|
601
|
-
|
|
602
|
-
`x`, `y`, `w`, `h` values can be specified as percentage strings (e.g. `"50%"`, `"100%"`), which are resolved relative to the enclosing context:
|
|
603
|
-
|
|
604
|
-
- **Inside a `<Group>`**: resolved against the group's `w` (for x/w) or `h` (for y/h).
|
|
605
|
-
- **Directly inside a `<Slide>`**: resolved against the slide's dimensions from the deck layout.
|
|
606
|
-
|
|
607
|
-
```tsx
|
|
608
|
-
<Group x={1} y={1} w={10} h={5}>
|
|
609
|
-
{/* 50% of group width (5"), 25% of group height (1.25") */}
|
|
610
|
-
<Rect x="25%" y="25%" w="50%" h="50%" fill={{ color: "4ECDC4" }} />
|
|
611
|
-
</Group>
|
|
612
|
-
```
|
|
613
|
-
|
|
614
|
-
This works for all positioning props: `x`, `y`, `w`, `h` on all shape/text/image components, and `x1`, `y1`, `x2`, `y2` on `LineBetween`.
|
|
615
|
-
|
|
616
|
-
---
|
|
617
|
-
|
|
618
|
-
## Sections & Masters
|
|
619
|
-
|
|
620
|
-
### Sections
|
|
621
|
-
|
|
622
|
-
Group slides into named sections in the PowerPoint outline view.
|
|
623
|
-
|
|
624
|
-
```tsx
|
|
625
|
-
<Deck>
|
|
626
|
-
<Slide>...</Slide>
|
|
627
|
-
<Section title="Overview">
|
|
628
|
-
<Slide>...</Slide>
|
|
629
|
-
<Slide>...</Slide>
|
|
630
|
-
</Section>
|
|
631
|
-
<Section title="Details">
|
|
632
|
-
<Slide>...</Slide>
|
|
633
|
-
</Section>
|
|
634
|
-
</Deck>
|
|
635
|
-
```
|
|
636
|
-
|
|
637
|
-
### Masters
|
|
638
|
-
|
|
639
|
-
Define slide masters with reusable layout objects.
|
|
640
|
-
|
|
641
|
-
```tsx
|
|
642
|
-
<Deck>
|
|
643
|
-
<Master name="myMaster" background={{ fill: "F5F5F5" }}>
|
|
644
|
-
<Text x={1} y={0.3} w={10} h={0.5} fontSize={10} color="999999">
|
|
645
|
-
Confidential
|
|
646
|
-
</Text>
|
|
647
|
-
<Rect x={0} y={7} w={13.333} h={0.5} fill={{ color: "4472C4" }} />
|
|
648
|
-
</Master>
|
|
649
|
-
<Slide masterName="myMaster">...</Slide>
|
|
650
|
-
</Deck>
|
|
651
|
-
```
|
|
652
|
-
|
|
653
|
-
You can also use `<Placeholder>` inside masters:
|
|
654
|
-
|
|
655
|
-
```tsx
|
|
656
|
-
<Master name="content">
|
|
657
|
-
<Placeholder options={{ name: "Body", type: "body", x: 1, y: 1, w: 10, h: 5 }} />
|
|
658
|
-
</Master>
|
|
659
|
-
```
|
|
660
|
-
|
|
661
|
-
## Validation
|
|
662
|
-
|
|
663
|
-
The `validateDeck()` function checks your slide tree for common mistakes before rendering. It is **async** — always `await` it:
|
|
664
|
-
|
|
665
|
-
```tsx
|
|
666
|
-
import { validateDeck } from "pptxgenjs-plus-jsx/render";
|
|
667
|
-
|
|
668
|
-
const deck = <Deck>{/* ... */}</Deck>;
|
|
669
|
-
const issues = await validateDeck(deck);
|
|
670
|
-
|
|
671
|
-
if (issues.length > 0) {
|
|
672
|
-
for (const issue of issues) {
|
|
673
|
-
console.error(`[${issue.level}] ${issue.message}`);
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
```
|
|
677
|
-
|
|
678
|
-
Validation catches:
|
|
679
|
-
|
|
680
|
-
- Invalid child types (e.g., a `<Text>` directly inside a `<Deck>`)
|
|
681
|
-
- **Leaf components with children** (`child.leaf`, e.g. `<RoundRect>` containing a `<Text>`)
|
|
682
|
-
- Missing required props (e.g., `CustomGeometry` without `points`)
|
|
683
|
-
- Suspicious prop usage (e.g., `angleRange` on `RoundRect`)
|
|
684
|
-
- Mixed `<Text>` input modes (`text.input.mixed`) — warns whenever a lower-priority source would be ignored and recommends `<TextRun />` children for rich text
|
|
685
|
-
- Invalid `LineBetween` endpoints
|
|
686
|
-
|
|
687
|
-
---
|
|
688
|
-
|
|
689
|
-
## Rendering
|
|
690
|
-
|
|
691
|
-
### To a File
|
|
692
|
-
|
|
693
|
-
```tsx
|
|
694
|
-
import { renderPptx } from "pptxgenjs-plus-jsx/render";
|
|
695
|
-
|
|
696
|
-
await renderPptx(<Deck>{/* ... */}</Deck>, {
|
|
697
|
-
fileName: "output/presentation.pptx",
|
|
698
|
-
});
|
|
699
|
-
```
|
|
700
|
-
|
|
701
|
-
Additional pptxgenjs `writeFile` options are also supported:
|
|
702
|
-
|
|
703
|
-
```tsx
|
|
704
|
-
await renderPptx(<Deck>{/* ... */}</Deck>, {
|
|
705
|
-
fileName: "output.pptx",
|
|
706
|
-
compression: true, // Enable ZIP compression
|
|
707
|
-
zipOptions: { level: 9 }, // Compression level
|
|
708
|
-
});
|
|
709
|
-
```
|
|
710
|
-
|
|
711
|
-
### To a Buffer / Blob
|
|
712
|
-
|
|
713
|
-
```tsx
|
|
714
|
-
import { writePptx } from "pptxgenjs-plus-jsx/render";
|
|
715
|
-
|
|
716
|
-
const buffer = await writePptx(<Deck>{/* ... */}</Deck>, {
|
|
717
|
-
outputType: "arraybuffer", // "arraybuffer" | "blob" | "uint8array" | "base64" | "nodebuffer"
|
|
718
|
-
});
|
|
719
|
-
```
|
|
720
|
-
|
|
721
|
-
### Reuse an Existing PptxGenJS Instance
|
|
722
|
-
|
|
723
|
-
```tsx
|
|
724
|
-
import PptxGenJS from "pptxgenjs-plus";
|
|
725
|
-
|
|
726
|
-
const pptx = new PptxGenJS();
|
|
727
|
-
// ... configure the instance ...
|
|
728
|
-
await renderPptx(<Deck>{/* ... */}</Deck>, { pptx });
|
|
729
|
-
```
|
|
730
|
-
|
|
731
|
-
### Aliases
|
|
732
|
-
|
|
733
|
-
```tsx
|
|
734
|
-
import { render, write } from "pptxgenjs-plus-jsx/render";
|
|
735
|
-
|
|
736
|
-
await render(<Deck>{/* ... */}</Deck>, { fileName: "output.pptx" });
|
|
737
|
-
```
|
|
738
|
-
|
|
739
|
-
## License
|
|
740
|
-
|
|
741
|
-
MIT
|
|
1
|
+
# pptxgenjs-plus-jsx
|
|
2
|
+
|
|
3
|
+
A JSX runtime for building PowerPoint presentations with [pptxgenjs-plus](https://github.com/lofcz/pptxgenjs-plus). Write your slides as JSX components and render them to `.pptx` files.
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import { Deck, Slide, Text, TextRun, Rect } from "pptxgenjs-plus-jsx";
|
|
7
|
+
import { renderPptx } from "pptxgenjs-plus-jsx/render";
|
|
8
|
+
|
|
9
|
+
await renderPptx(
|
|
10
|
+
<Deck title="My Deck">
|
|
11
|
+
<Slide>
|
|
12
|
+
<Rect x={0} y={0} w={13.333} h={7.5} fill={{ color: "1E1E2E" }} />
|
|
13
|
+
<Text x={1} y={3} w={11} h={1.5}>
|
|
14
|
+
<TextRun options={{ fontSize: 44, color: "FFFFFF", bold: true }}>
|
|
15
|
+
Hello, PowerPoint!
|
|
16
|
+
</TextRun>
|
|
17
|
+
</Text>
|
|
18
|
+
</Slide>
|
|
19
|
+
</Deck>,
|
|
20
|
+
{ fileName: "output.pptx" },
|
|
21
|
+
);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Table of Contents
|
|
25
|
+
|
|
26
|
+
- [Installation](#installation)
|
|
27
|
+
- [TypeScript Configuration](#typescript-configuration)
|
|
28
|
+
- [Component Reference](#component-reference)
|
|
29
|
+
- [Deck & Presentation](#deck--presentation)
|
|
30
|
+
- [Slide](#slide)
|
|
31
|
+
- [Text & TextRun](#text--textrun)
|
|
32
|
+
- [FixedBox](#fixedbox)
|
|
33
|
+
- [Shapes](#shapes)
|
|
34
|
+
- [Charts](#charts)
|
|
35
|
+
- [Tables](#tables)
|
|
36
|
+
- [Images & Media](#images--media)
|
|
37
|
+
- [Group](#group)
|
|
38
|
+
- [Raw (escape hatch)](#raw-escape-hatch)
|
|
39
|
+
- [Fragment](#fragment)
|
|
40
|
+
- [Async Components](#async-components)
|
|
41
|
+
- [Context Hooks](#context-hooks)
|
|
42
|
+
- [useSlideContext](#useslidecontext)
|
|
43
|
+
- [useDeckContext](#usedeckcontext)
|
|
44
|
+
- [useGroupContext](#usegroupcontext)
|
|
45
|
+
- [Lazy Slide Loading](#lazy-slide-loading)
|
|
46
|
+
- [Percentage Coordinates](#percentage-coordinates)
|
|
47
|
+
- [Sections & Masters](#sections--masters)
|
|
48
|
+
- [Validation](#validation)
|
|
49
|
+
- [Rendering](#rendering)
|
|
50
|
+
- [License](#license)
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install pptxgenjs-plus-jsx
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Peer dependency:
|
|
61
|
+
|
|
62
|
+
- **[pptxgenjs-plus](https://github.com/lofcz/pptxgenjs-plus)** — workspace dependency in this monorepo.
|
|
63
|
+
|
|
64
|
+
## TypeScript Configuration
|
|
65
|
+
|
|
66
|
+
Set `jsx` and `jsxImportSource` in your `tsconfig.json`:
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"compilerOptions": {
|
|
71
|
+
"jsx": "react-jsx",
|
|
72
|
+
"jsxImportSource": "pptxgenjs-plus-jsx"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
> **Note**: This is **not** React — the JSX transform produces `PptxNode` objects, not DOM elements. No React dependency is required.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Component Reference
|
|
82
|
+
|
|
83
|
+
### Deck / Presentation
|
|
84
|
+
|
|
85
|
+
The root element of every presentation. Maps to `new PptxGenJS()`.
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
<Deck>
|
|
89
|
+
<Slide>...</Slide>
|
|
90
|
+
</Deck>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`<Presentation>` is an alias for `<Deck>`.
|
|
94
|
+
|
|
95
|
+
#### Layout
|
|
96
|
+
|
|
97
|
+
Use the `layout` prop to control slide dimensions. Two forms are supported:
|
|
98
|
+
|
|
99
|
+
**1. Built-in layout name** (string) — pptxgenjs provides four standard presets:
|
|
100
|
+
|
|
101
|
+
| Name | Dimensions | Aspect Ratio |
|
|
102
|
+
| ---------------- | ------------- | ------------ |
|
|
103
|
+
| `"LAYOUT_4x3"` | 10" × 7.5" | 4:3 |
|
|
104
|
+
| `"LAYOUT_16x9"` | 10" × 5.625" | 16:9 |
|
|
105
|
+
| `"LAYOUT_16x10"` | 10" × 6.25" | 16:10 |
|
|
106
|
+
| `"LAYOUT_WIDE"` | 13.33" × 7.5" | 16:9 (wide) |
|
|
107
|
+
|
|
108
|
+
Default: `"LAYOUT_WIDE"` (13.33" × 7.5").
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
<Deck layout="LAYOUT_16x9">
|
|
112
|
+
<Slide>...</Slide>
|
|
113
|
+
</Deck>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**2. Custom layout** (object) — define arbitrary dimensions via a `PresLayout` object with `name`, `width`, and `height` (in inches):
|
|
117
|
+
|
|
118
|
+
```tsx
|
|
119
|
+
<Deck layout={{ name: "A4", width: 10.83, height: 7.82 }}>
|
|
120
|
+
<Slide>...</Slide>
|
|
121
|
+
</Deck>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
For multiple custom layouts, use the `layouts` prop (array of `PresLayout`):
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
<Deck
|
|
128
|
+
layout="A4"
|
|
129
|
+
layouts={[
|
|
130
|
+
{ name: "A4", width: 10.83, height: 7.82 },
|
|
131
|
+
{ name: "Letter", width: 10, height: 7.5 },
|
|
132
|
+
]}
|
|
133
|
+
>
|
|
134
|
+
<Slide>...</Slide>
|
|
135
|
+
</Deck>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The first matching layout name becomes the presentation's active layout.
|
|
139
|
+
|
|
140
|
+
### Slide
|
|
141
|
+
|
|
142
|
+
A single slide. Maps to `pptx.addSlide()`.
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
<Slide>
|
|
146
|
+
<Text>A simple slide</Text>
|
|
147
|
+
</Slide>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Lazy-loaded slide** (see [Lazy Slide Loading](#lazy-slide-loading)):
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
<Slide component={() => import("./slides/chart-slide")} />
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Text & TextRun
|
|
157
|
+
|
|
158
|
+
**`<Text>`** — a text box or rich text container. Maps to `slide.addText()`.
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
// Simple text (string from children)
|
|
162
|
+
<Text x={1} y={1} w={8} h={1} fontSize={24} color="333333">
|
|
163
|
+
Hello, World!
|
|
164
|
+
</Text>
|
|
165
|
+
|
|
166
|
+
// Rich text with multiple TextRun elements
|
|
167
|
+
<Text x={1} y={2.5} w={8} h={1.5} valign="middle">
|
|
168
|
+
<TextRun options={{ fontSize: 18, color: "666666" }}>Normal text </TextRun>
|
|
169
|
+
<TextRun options={{ fontSize: 18, color: "0066CC", bold: true }}>
|
|
170
|
+
bold and blue
|
|
171
|
+
</TextRun>
|
|
172
|
+
</Text>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**`<TextRun>`** — a single formatted run inside `<Text>`. `options` accepts pptxgenjs `TextProps` (fontSize, color, bold, italic, fontFace, etc.). The run's text comes from its string children (or the `text` prop):
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
<TextRun options={{ fontSize: 18, color: "0066CC", bold: true }}>bold and blue</TextRun>
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**Text input modes.** A `<Text>` element has four ways to receive content. When more than one is present, this priority applies (higher wins, the rest is ignored):
|
|
182
|
+
|
|
183
|
+
1. child `<TextRun />` nodes — plain string/number children mixed among them are converted to default-style runs (order preserved)
|
|
184
|
+
2. the `runs` prop (rich text array — same shape as pptxgenjs `TextProps[]`)
|
|
185
|
+
3. the `text` prop
|
|
186
|
+
4. plain-string children
|
|
187
|
+
|
|
188
|
+
Plain strings mix freely with `<TextRun />` children — each string segment becomes a default-style run in place:
|
|
189
|
+
|
|
190
|
+
```tsx
|
|
191
|
+
<Text x={1} y={4} w={8} h={1}>
|
|
192
|
+
{"Normal segment "}
|
|
193
|
+
<TextRun options={{ color: "0066CC", bold: true }}>highlighted</TextRun>
|
|
194
|
+
</Text>
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Whitespace-only text between elements (e.g. from multi-line JSX formatting) is ignored — attach explicit spaces to a run's text (`<TextRun>A </TextRun>`) instead. Mixing the other modes (e.g. `runs` or `text` props alongside children) still drops the lower-priority content.
|
|
198
|
+
|
|
199
|
+
```tsx
|
|
200
|
+
// runs prop (imperative rich text)
|
|
201
|
+
<Text
|
|
202
|
+
x={1}
|
|
203
|
+
y={1}
|
|
204
|
+
w={8}
|
|
205
|
+
h={1}
|
|
206
|
+
runs={[
|
|
207
|
+
{ text: "Normal ", options: { fontSize: 18 } },
|
|
208
|
+
{ text: "bold", options: { fontSize: 18, bold: true } },
|
|
209
|
+
]}
|
|
210
|
+
/>
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**Text with a shape background.** `shape` is a valid pptxgenjs text option and is forwarded to `slide.addText()`:
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
<Text
|
|
217
|
+
x={1}
|
|
218
|
+
y={1}
|
|
219
|
+
w={4}
|
|
220
|
+
h={2}
|
|
221
|
+
shape="roundRect"
|
|
222
|
+
fill={{ color: "EDE9FE" }}
|
|
223
|
+
margin={18} // text margin uses POINTS (~0.25"), not inches
|
|
224
|
+
valign="middle"
|
|
225
|
+
>
|
|
226
|
+
Shaped text box
|
|
227
|
+
</Text>
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
> Note: pptxgenjs text `margin` values are in **points** (e.g. `18` ≈ 0.25"), not inches.
|
|
231
|
+
|
|
232
|
+
### FixedBox
|
|
233
|
+
|
|
234
|
+
A **fixed-size** text box. Pass CommonMark plus TeX delimiters; the box stays at the authored `x/y/w/h` and PowerPoint shrink-to-fit scales the content (`fit="shrink"`).
|
|
235
|
+
|
|
236
|
+
- Headings (`#`–`######` and setext), paragraphs, `**bold**` / `*italic*`, `~~strike~~`, `---` rules, `>` quotes, `[links](url)`, and lists become native PPTX runs (real bullets / numbered lists).
|
|
237
|
+
- `$…$` (inline) and `$$…$$` (display) — also `\(…\)`, `\[…\]`, `\begin{env}` — become editable OMML via MathLive + mathml2omml-plus. No extra helper, no image raster.
|
|
238
|
+
|
|
239
|
+
```tsx
|
|
240
|
+
<FixedBox
|
|
241
|
+
x={0.7}
|
|
242
|
+
y={1.5}
|
|
243
|
+
w={6}
|
|
244
|
+
h={4}
|
|
245
|
+
fontSize={18}
|
|
246
|
+
color="0F172A"
|
|
247
|
+
markdown={`
|
|
248
|
+
# Title
|
|
249
|
+
- item one
|
|
250
|
+
- item with $a^2+b^2=c^2$
|
|
251
|
+
|
|
252
|
+
$$\\frac{1}{2}$$
|
|
253
|
+
`}
|
|
254
|
+
/>
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
`fromMarkdown`, `tokenizeMath`, `latexToOmml`, and `mathRun` are also exported from the package root when you need runs without the component.
|
|
258
|
+
|
|
259
|
+
### Shapes
|
|
260
|
+
|
|
261
|
+
All pptxgenjs shapes are available as JSX components. Each supports standard positioning props (`x`, `y`, `w`, `h`) plus shape-specific options via `options` or as top-level props.
|
|
262
|
+
|
|
263
|
+
> **Shapes are leaf elements** — they do not render children. Nested content
|
|
264
|
+
> (e.g. `<RoundRect><Text>…</Text></RoundRect>`) is a compile-time error in TSX
|
|
265
|
+
> and a hard runtime error otherwise; it is never silently dropped.
|
|
266
|
+
>
|
|
267
|
+
> To put text on a shape, use **one** of:
|
|
268
|
+
>
|
|
269
|
+
> 1. A single text box with a shape background: `<Text shape="roundRect" …>` (recommended when the text and shape share one box — see [Text & TextRun](#text--textrun)).
|
|
270
|
+
> 2. A sibling `<Text>` layered over the shape (when text and shape need independent styles/shadows/geometry).
|
|
271
|
+
> 3. A `<Group>` only when you need a relative coordinate system or want to move/scale the pair together.
|
|
272
|
+
|
|
273
|
+
```tsx
|
|
274
|
+
<Rect x={0} y={0} w={13.333} h={7.5} fill={{ color: "1E1E2E" }} />
|
|
275
|
+
<Ellipse x={1} y={1} w={3} h={2} fill={{ color: "FF6B6B" }} />
|
|
276
|
+
<Triangle x={5} y={1} w={2} h={2} fill={{ color: "4ECDC4" }} />
|
|
277
|
+
<RoundRect x={1} y={4} w={4} h={2} fill={{ color: "45B7D1" }} rectRadius={0.3} />
|
|
278
|
+
<Line x={1} y={1} w={5} h={0} line={{ color: "FF0000", width: 2 }} />
|
|
279
|
+
<Cloud x={1} y={1} w={3} h={2} fill={{ color: "E8F4FD" }} />
|
|
280
|
+
<Heart x={5} y={1} w={2} h={2} fill={{ color: "FF4081" }} />
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
**`<LineBetween>`** — a line connecting two absolute coordinates. Supports percentage coordinates.
|
|
284
|
+
|
|
285
|
+
```tsx
|
|
286
|
+
<LineBetween
|
|
287
|
+
x1={0}
|
|
288
|
+
y1={0}
|
|
289
|
+
x2={13.333}
|
|
290
|
+
y2={7.5}
|
|
291
|
+
line={{ color: "999999", width: 1, dashType: "dash" }}
|
|
292
|
+
/>
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Available shape components:
|
|
296
|
+
|
|
297
|
+
| Component | pptxgenjs shape |
|
|
298
|
+
| -------------------------- | ----------------------------------- |
|
|
299
|
+
| `Rect` | `rect` |
|
|
300
|
+
| `RoundRect` | `roundRect` |
|
|
301
|
+
| `Ellipse` / `Oval` | `ellipse` |
|
|
302
|
+
| `Triangle` | `triangle` |
|
|
303
|
+
| `RightTriangle` | `rtTriangle` |
|
|
304
|
+
| `Diamond` | `diamond` |
|
|
305
|
+
| `Pentagon` | `pentagon` |
|
|
306
|
+
| `Hexagon` | `hexagon` |
|
|
307
|
+
| `Star` / `Star5` | `star5` |
|
|
308
|
+
| `Star4` | `star4` |
|
|
309
|
+
| `Star6` | `star6` |
|
|
310
|
+
| `Star8` | `star8` |
|
|
311
|
+
| `Star10` | `star10` |
|
|
312
|
+
| `Line` | `line` |
|
|
313
|
+
| `LineBetween` | `line` (with computed bounding box) |
|
|
314
|
+
| `Arc` | `arc` |
|
|
315
|
+
| `BlockArc` | `blockArc` |
|
|
316
|
+
| `PieShape` | `pie` |
|
|
317
|
+
| `CustomGeometry` | `custGeom` |
|
|
318
|
+
| `LeftArrow` / `RightArrow` | `leftArrow` / `rightArrow` |
|
|
319
|
+
| `UpArrow` / `DownArrow` | `upArrow` / `downArrow` |
|
|
320
|
+
| `LeftRightArrow` | `leftRightArrow` |
|
|
321
|
+
| `UpDownArrow` | `upDownArrow` |
|
|
322
|
+
| `Chevron` | `chevron` |
|
|
323
|
+
| `Cloud` | `cloud` |
|
|
324
|
+
| `Heart` | `heart` |
|
|
325
|
+
| `Donut` | `donut` |
|
|
326
|
+
| `Plus` | `plus` |
|
|
327
|
+
|
|
328
|
+
### Charts
|
|
329
|
+
|
|
330
|
+
```tsx
|
|
331
|
+
// Generic chart with explicit `type`
|
|
332
|
+
<Chart
|
|
333
|
+
x={1} y={1} w={10} h={5}
|
|
334
|
+
type="bar"
|
|
335
|
+
data={[
|
|
336
|
+
{ name: "Q1", labels: ["Jan", "Feb", "Mar"], values: [100, 150, 200] },
|
|
337
|
+
{ name: "Q2", labels: ["Jan", "Feb", "Mar"], values: [120, 180, 160] },
|
|
338
|
+
]}
|
|
339
|
+
showTitle="Quarterly Sales"
|
|
340
|
+
showLegend={true}
|
|
341
|
+
/>
|
|
342
|
+
|
|
343
|
+
// Or use a typed chart component
|
|
344
|
+
<BarChart x={1} y={1} w={10} h={5} data={[...]} showValue={true} />
|
|
345
|
+
<LineChart x={1} y={1} w={10} h={5} data={[...]} lineSize={3} />
|
|
346
|
+
<PieChart x={1} y={1} w={6} h={5} data={[...]} showPercent={true} />
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
Available chart components: `AreaChart`, `BarChart`, `Bar3DChart`, `BubbleChart`, `DoughnutChart`, `LineChart`, `PieChart`, `RadarChart`, `ScatterChart`.
|
|
350
|
+
|
|
351
|
+
### Tables
|
|
352
|
+
|
|
353
|
+
```tsx
|
|
354
|
+
<Table x={1} y={1} w={10} h={3} fontSize={12} border={{ type: "solid", color: "CCCCCC" }}>
|
|
355
|
+
<TableRow>
|
|
356
|
+
<TableCell options={{ fill: { color: "4472C4" }, color: "FFFFFF", bold: true }}>Name</TableCell>
|
|
357
|
+
<TableCell options={{ fill: { color: "4472C4" }, color: "FFFFFF", bold: true }}>
|
|
358
|
+
Value
|
|
359
|
+
</TableCell>
|
|
360
|
+
</TableRow>
|
|
361
|
+
<TableRow>
|
|
362
|
+
<TableCell>Item A</TableCell>
|
|
363
|
+
<TableCell>100</TableCell>
|
|
364
|
+
</TableRow>
|
|
365
|
+
<TableRow>
|
|
366
|
+
<TableCell>Item B</TableCell>
|
|
367
|
+
<TableCell>200</TableCell>
|
|
368
|
+
</TableRow>
|
|
369
|
+
</Table>
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
`TableToSlides` splits an HTML table across multiple slides (browser runtime only).
|
|
373
|
+
|
|
374
|
+
### Images & Media
|
|
375
|
+
|
|
376
|
+
```tsx
|
|
377
|
+
<Image
|
|
378
|
+
x={1} y={1} w={5} h={3}
|
|
379
|
+
path="https://example.com/image.png"
|
|
380
|
+
sizing={{ type: "contain", w: 5, h: 3 }}
|
|
381
|
+
/>
|
|
382
|
+
|
|
383
|
+
<Media
|
|
384
|
+
x={1} y={1} w={6} h={4}
|
|
385
|
+
path="https://example.com/video.mp4"
|
|
386
|
+
mediaType="video"
|
|
387
|
+
/>
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### Group
|
|
391
|
+
|
|
392
|
+
A PresentationML group (`p:grpSp`). Child coordinates are relative to the group's origin. Maps to `slide.addGroup()`.
|
|
393
|
+
|
|
394
|
+
```tsx
|
|
395
|
+
<Group x={1} y={1} w={10} h={5}>
|
|
396
|
+
{/* (0, 0) inside group → group-relative; the group itself sits at (1, 1) */}
|
|
397
|
+
<Rect x={0} y={0} w={10} h={5} fill={{ color: "F0F0F0" }} />
|
|
398
|
+
{/* "50%" inside group → 5" from the group origin */}
|
|
399
|
+
<Text x="50%" y="50%" w={4} h={1}>
|
|
400
|
+
<TextRun options={{ fontSize: 18 }}>Centered in group</TextRun>
|
|
401
|
+
</Text>
|
|
402
|
+
</Group>
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
Key features:
|
|
406
|
+
|
|
407
|
+
- **Native group shape**: children move and transform together in PowerPoint.
|
|
408
|
+
- **Coordinate transformation**: Child `x`, `y`, `w`, `h` are relative to the group origin. Percentage strings resolve against the group's `w` (for x/w) or `h` (for y/h).
|
|
409
|
+
- **Nested groups**: Groups can nest via `group.addGroup()`.
|
|
410
|
+
- **Valid children**: shapes, text, images, and nested groups. Tables, charts, media, notes, and WordArt must stay on the slide.
|
|
411
|
+
- **Context-aware**: Children can use `useGroupContext()` for the group's virtual canvas (`width` / `height`) and slide origin (`x` / `y`).
|
|
412
|
+
|
|
413
|
+
### Raw (escape hatch)
|
|
414
|
+
|
|
415
|
+
For pptxgenjs features not covered by a dedicated component.
|
|
416
|
+
|
|
417
|
+
```tsx
|
|
418
|
+
<Raw
|
|
419
|
+
render={({ pptx, slide, node }) => {
|
|
420
|
+
// Direct access to slide.addShape(), slide.addText(), etc.
|
|
421
|
+
slide.addShape("rect", { x: 1, y: 1, w: 5, h: 3, fill: { color: "FF0000" } });
|
|
422
|
+
}}
|
|
423
|
+
/>
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
> Raw children are **not** auto-rendered — they are only accessible via
|
|
427
|
+
> `context.node.children` inside the `render` callback. Use props for
|
|
428
|
+
> configuration; use children only when the callback reads them itself.
|
|
429
|
+
|
|
430
|
+
### Fragment
|
|
431
|
+
|
|
432
|
+
Groups multiple children without producing a wrapper element. Useful when a component needs to return multiple siblings (e.g., in a lazy-loaded slide or inside a map).
|
|
433
|
+
|
|
434
|
+
**Shorthand form `<>...</>`** — for simple grouping without props:
|
|
435
|
+
|
|
436
|
+
```tsx
|
|
437
|
+
// slides/title-slide.tsx
|
|
438
|
+
export default function TitleSlide() {
|
|
439
|
+
return (
|
|
440
|
+
<>
|
|
441
|
+
<Text x={1} y={3} w={10} h={1.5} fontSize={44} bold>
|
|
442
|
+
Welcome
|
|
443
|
+
</Text>
|
|
444
|
+
<Text x={1} y={4.5} w={10} h={1} fontSize={18} color="666666">
|
|
445
|
+
Subtitle text
|
|
446
|
+
</Text>
|
|
447
|
+
</>
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
**Explicit `<Fragment>`** — when you need a `key` prop (e.g., in a `.map()` loop):
|
|
453
|
+
|
|
454
|
+
```tsx
|
|
455
|
+
import { Fragment } from "pptxgenjs-plus-jsx";
|
|
456
|
+
|
|
457
|
+
<Slide>
|
|
458
|
+
{items.map((item) => (
|
|
459
|
+
<Fragment key={item.id}>
|
|
460
|
+
<Text x={1} y={item.y}>
|
|
461
|
+
{item.name}
|
|
462
|
+
</Text>
|
|
463
|
+
<Text x={5} y={item.y}>
|
|
464
|
+
{item.value}
|
|
465
|
+
</Text>
|
|
466
|
+
</Fragment>
|
|
467
|
+
))}
|
|
468
|
+
</Slide>;
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
> **Note**: `<>...</>` is a JSX compile-time syntax — it does not support props like `key`. For dynamic lists, always use `<Fragment key={...}>`.
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
475
|
+
## Async Components
|
|
476
|
+
|
|
477
|
+
Components can be `async` functions — they are automatically detected and lazily resolved during rendering:
|
|
478
|
+
|
|
479
|
+
```tsx
|
|
480
|
+
// slides/data-slide.tsx
|
|
481
|
+
export default async function DataSlide() {
|
|
482
|
+
const res = await fetch("https://api.example.com/data");
|
|
483
|
+
const data = await res.json();
|
|
484
|
+
|
|
485
|
+
return (
|
|
486
|
+
<Slide>
|
|
487
|
+
<Text x={1} y={1} w={8} h={1} fontSize={32} bold>
|
|
488
|
+
{data.title}
|
|
489
|
+
</Text>
|
|
490
|
+
<Text x={1} y={2.5} w={8} h={4} fontSize={16}>
|
|
491
|
+
{data.description}
|
|
492
|
+
</Text>
|
|
493
|
+
</Slide>
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
```tsx
|
|
499
|
+
// main.tsx
|
|
500
|
+
await renderPptx(
|
|
501
|
+
<Deck>
|
|
502
|
+
<Slide>{/* ... */}</Slide>
|
|
503
|
+
<DataSlide /> {/* async — resolves automatically */}
|
|
504
|
+
</Deck>,
|
|
505
|
+
{ fileName: "output.pptx" },
|
|
506
|
+
);
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
This works because the JSX factory (`jsx`) wraps async component results in a `PptxNodePromise`, and the renderer resolves them during tree traversal.
|
|
510
|
+
|
|
511
|
+
---
|
|
512
|
+
|
|
513
|
+
## Context Hooks
|
|
514
|
+
|
|
515
|
+
Context hooks provide runtime information about the current rendering environment.
|
|
516
|
+
|
|
517
|
+
**How it works**: When TypeScript compiles your JSX, component factories are NOT called during JSX construction. Instead, they are wrapped in a deferred node and executed later during rendering — at which point the renderer has set up the context store via `AsyncLocalStorage`. This is why you can write components that call `useSlideContext()` as direct children of `<Slide>`, even though the JSX appears to be built "eagerly."
|
|
518
|
+
|
|
519
|
+
### useSlideContext
|
|
520
|
+
|
|
521
|
+
Exposes the current slide's index and total.
|
|
522
|
+
|
|
523
|
+
```tsx
|
|
524
|
+
import { useSlideContext } from "pptxgenjs-plus-jsx";
|
|
525
|
+
|
|
526
|
+
function SlideNumber() {
|
|
527
|
+
const { index, total, sectionTitle } = useSlideContext();
|
|
528
|
+
|
|
529
|
+
return (
|
|
530
|
+
<Text x={1} y={6.5} w={10} h={0.5} fontSize={10} color="999999">
|
|
531
|
+
Slide {index} of {total}
|
|
532
|
+
{sectionTitle ? ` · ${sectionTitle}` : ""}
|
|
533
|
+
</Text>
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
```tsx
|
|
539
|
+
// Usage inside a Slide:
|
|
540
|
+
<Slide>
|
|
541
|
+
{/* ... slide content ... */}
|
|
542
|
+
<SlideNumber />
|
|
543
|
+
</Slide>
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
### useDeckContext
|
|
547
|
+
|
|
548
|
+
Exposes the deck's slide dimensions (width, height in inches).
|
|
549
|
+
|
|
550
|
+
```tsx
|
|
551
|
+
import { useDeckContext } from "pptxgenjs-plus-jsx";
|
|
552
|
+
|
|
553
|
+
function FullBleedBackground() {
|
|
554
|
+
const { width, height } = useDeckContext();
|
|
555
|
+
return <Rect x={0} y={0} w={width} h={height} fill={{ color: "1E1E2E" }} />;
|
|
556
|
+
}
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
### useGroupContext
|
|
560
|
+
|
|
561
|
+
Exposes the current group's origin on the slide and its virtual canvas. When called outside a `<Group>`, falls back to deck dimensions with zero offset (`relative: false`). Inside a group, child coordinates are group-relative (`relative: true`).
|
|
562
|
+
|
|
563
|
+
```tsx
|
|
564
|
+
import { useGroupContext } from "pptxgenjs-plus-jsx";
|
|
565
|
+
|
|
566
|
+
function ProgressBar() {
|
|
567
|
+
const { width } = useGroupContext();
|
|
568
|
+
return <Rect x={0} y={0} w={width * 0.7} h={0.4} fill={{ color: "4CAF50" }} />;
|
|
569
|
+
}
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
---
|
|
573
|
+
|
|
574
|
+
## Lazy Slide Loading
|
|
575
|
+
|
|
576
|
+
Use the `component` prop on `<Slide>` to defer loading of slide definitions — analogous to React Router's lazy route loading.
|
|
577
|
+
|
|
578
|
+
```tsx
|
|
579
|
+
// slides/title-slide.tsx
|
|
580
|
+
export default function TitleSlide() {
|
|
581
|
+
return (
|
|
582
|
+
<>
|
|
583
|
+
<Text x={1} y={3} w={10} h={1.5} fontSize={44} bold>
|
|
584
|
+
Welcome
|
|
585
|
+
</Text>
|
|
586
|
+
</>
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
```tsx
|
|
592
|
+
// main.tsx
|
|
593
|
+
<Slide component={() => import("./slides/title-slide")} />
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
The component's return value is rendered **inside** the `<Slide>` that declares `component`, so it should provide slide **content only** — not another `<Slide>` element. Context hooks work inside lazy-loaded components.
|
|
597
|
+
|
|
598
|
+
---
|
|
599
|
+
|
|
600
|
+
## Percentage Coordinates
|
|
601
|
+
|
|
602
|
+
`x`, `y`, `w`, `h` values can be specified as percentage strings (e.g. `"50%"`, `"100%"`), which are resolved relative to the enclosing context:
|
|
603
|
+
|
|
604
|
+
- **Inside a `<Group>`**: resolved against the group's `w` (for x/w) or `h` (for y/h).
|
|
605
|
+
- **Directly inside a `<Slide>`**: resolved against the slide's dimensions from the deck layout.
|
|
606
|
+
|
|
607
|
+
```tsx
|
|
608
|
+
<Group x={1} y={1} w={10} h={5}>
|
|
609
|
+
{/* 50% of group width (5"), 25% of group height (1.25") */}
|
|
610
|
+
<Rect x="25%" y="25%" w="50%" h="50%" fill={{ color: "4ECDC4" }} />
|
|
611
|
+
</Group>
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
This works for all positioning props: `x`, `y`, `w`, `h` on all shape/text/image components, and `x1`, `y1`, `x2`, `y2` on `LineBetween`.
|
|
615
|
+
|
|
616
|
+
---
|
|
617
|
+
|
|
618
|
+
## Sections & Masters
|
|
619
|
+
|
|
620
|
+
### Sections
|
|
621
|
+
|
|
622
|
+
Group slides into named sections in the PowerPoint outline view.
|
|
623
|
+
|
|
624
|
+
```tsx
|
|
625
|
+
<Deck>
|
|
626
|
+
<Slide>...</Slide>
|
|
627
|
+
<Section title="Overview">
|
|
628
|
+
<Slide>...</Slide>
|
|
629
|
+
<Slide>...</Slide>
|
|
630
|
+
</Section>
|
|
631
|
+
<Section title="Details">
|
|
632
|
+
<Slide>...</Slide>
|
|
633
|
+
</Section>
|
|
634
|
+
</Deck>
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
### Masters
|
|
638
|
+
|
|
639
|
+
Define slide masters with reusable layout objects.
|
|
640
|
+
|
|
641
|
+
```tsx
|
|
642
|
+
<Deck>
|
|
643
|
+
<Master name="myMaster" background={{ fill: "F5F5F5" }}>
|
|
644
|
+
<Text x={1} y={0.3} w={10} h={0.5} fontSize={10} color="999999">
|
|
645
|
+
Confidential
|
|
646
|
+
</Text>
|
|
647
|
+
<Rect x={0} y={7} w={13.333} h={0.5} fill={{ color: "4472C4" }} />
|
|
648
|
+
</Master>
|
|
649
|
+
<Slide masterName="myMaster">...</Slide>
|
|
650
|
+
</Deck>
|
|
651
|
+
```
|
|
652
|
+
|
|
653
|
+
You can also use `<Placeholder>` inside masters:
|
|
654
|
+
|
|
655
|
+
```tsx
|
|
656
|
+
<Master name="content">
|
|
657
|
+
<Placeholder options={{ name: "Body", type: "body", x: 1, y: 1, w: 10, h: 5 }} />
|
|
658
|
+
</Master>
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
## Validation
|
|
662
|
+
|
|
663
|
+
The `validateDeck()` function checks your slide tree for common mistakes before rendering. It is **async** — always `await` it:
|
|
664
|
+
|
|
665
|
+
```tsx
|
|
666
|
+
import { validateDeck } from "pptxgenjs-plus-jsx/render";
|
|
667
|
+
|
|
668
|
+
const deck = <Deck>{/* ... */}</Deck>;
|
|
669
|
+
const issues = await validateDeck(deck);
|
|
670
|
+
|
|
671
|
+
if (issues.length > 0) {
|
|
672
|
+
for (const issue of issues) {
|
|
673
|
+
console.error(`[${issue.level}] ${issue.message}`);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
Validation catches:
|
|
679
|
+
|
|
680
|
+
- Invalid child types (e.g., a `<Text>` directly inside a `<Deck>`)
|
|
681
|
+
- **Leaf components with children** (`child.leaf`, e.g. `<RoundRect>` containing a `<Text>`)
|
|
682
|
+
- Missing required props (e.g., `CustomGeometry` without `points`)
|
|
683
|
+
- Suspicious prop usage (e.g., `angleRange` on `RoundRect`)
|
|
684
|
+
- Mixed `<Text>` input modes (`text.input.mixed`) — warns whenever a lower-priority source would be ignored and recommends `<TextRun />` children for rich text
|
|
685
|
+
- Invalid `LineBetween` endpoints
|
|
686
|
+
|
|
687
|
+
---
|
|
688
|
+
|
|
689
|
+
## Rendering
|
|
690
|
+
|
|
691
|
+
### To a File
|
|
692
|
+
|
|
693
|
+
```tsx
|
|
694
|
+
import { renderPptx } from "pptxgenjs-plus-jsx/render";
|
|
695
|
+
|
|
696
|
+
await renderPptx(<Deck>{/* ... */}</Deck>, {
|
|
697
|
+
fileName: "output/presentation.pptx",
|
|
698
|
+
});
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
Additional pptxgenjs `writeFile` options are also supported:
|
|
702
|
+
|
|
703
|
+
```tsx
|
|
704
|
+
await renderPptx(<Deck>{/* ... */}</Deck>, {
|
|
705
|
+
fileName: "output.pptx",
|
|
706
|
+
compression: true, // Enable ZIP compression
|
|
707
|
+
zipOptions: { level: 9 }, // Compression level
|
|
708
|
+
});
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
### To a Buffer / Blob
|
|
712
|
+
|
|
713
|
+
```tsx
|
|
714
|
+
import { writePptx } from "pptxgenjs-plus-jsx/render";
|
|
715
|
+
|
|
716
|
+
const buffer = await writePptx(<Deck>{/* ... */}</Deck>, {
|
|
717
|
+
outputType: "arraybuffer", // "arraybuffer" | "blob" | "uint8array" | "base64" | "nodebuffer"
|
|
718
|
+
});
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
### Reuse an Existing PptxGenJS Instance
|
|
722
|
+
|
|
723
|
+
```tsx
|
|
724
|
+
import PptxGenJS from "pptxgenjs-plus";
|
|
725
|
+
|
|
726
|
+
const pptx = new PptxGenJS();
|
|
727
|
+
// ... configure the instance ...
|
|
728
|
+
await renderPptx(<Deck>{/* ... */}</Deck>, { pptx });
|
|
729
|
+
```
|
|
730
|
+
|
|
731
|
+
### Aliases
|
|
732
|
+
|
|
733
|
+
```tsx
|
|
734
|
+
import { render, write } from "pptxgenjs-plus-jsx/render";
|
|
735
|
+
|
|
736
|
+
await render(<Deck>{/* ... */}</Deck>, { fileName: "output.pptx" });
|
|
737
|
+
```
|
|
738
|
+
|
|
739
|
+
## License
|
|
740
|
+
|
|
741
|
+
MIT
|