pptxgenjs-plus-jsx 4.1.17
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 -0
- package/README.md +713 -0
- package/dist/components.d.ts +565 -0
- package/dist/components.js +228 -0
- package/dist/components.js.map +1 -0
- package/dist/context.d.ts +147 -0
- package/dist/context.js +167 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +1 -0
- package/dist/jsx-dev-runtime.js +2 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.d.ts +63 -0
- package/dist/jsx-runtime.js +85 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/node.d.ts +129 -0
- package/dist/node.js +188 -0
- package/dist/node.js.map +1 -0
- package/dist/render.d.ts +61 -0
- package/dist/render.js +1125 -0
- package/dist/render.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSX runtime for pptxgenjsx.
|
|
3
|
+
*
|
|
4
|
+
* Provides jsx/jsxs/jsxDEV for TypeScript's `react-jsx` transform, plus
|
|
5
|
+
* Fragment (re-exported from node.js — the core model — so both this
|
|
6
|
+
* subpath and the package entry expose the same value).
|
|
7
|
+
* Async component factories are wrapped in PptxNodePromise for lazy resolution
|
|
8
|
+
* during tree traversal (in render.ts).
|
|
9
|
+
*/
|
|
10
|
+
import { type ComponentFactory, type ComponentProps, type PptxChild, type PptxNode, type PptxElement } from "./node.js";
|
|
11
|
+
export type Key = string | number | bigint;
|
|
12
|
+
/**
|
|
13
|
+
* JSX factory — called by TypeScript's `react-jsx` transform.
|
|
14
|
+
*
|
|
15
|
+
* If the Component returns a Promise (async component), it is wrapped in
|
|
16
|
+
* a PptxNodePromise and resolved lazily during `createPptx` traversal.
|
|
17
|
+
*
|
|
18
|
+
* Note on the props type: the public signature intentionally does NOT add
|
|
19
|
+
* `children` unconditionally. Whether an element accepts children is
|
|
20
|
+
* decided by the component's own props type (container props declare
|
|
21
|
+
* `children`, leaf props use `children?: never`). The runtime still
|
|
22
|
+
* destructures whatever `children` the JSX transform passes in.
|
|
23
|
+
*/
|
|
24
|
+
export declare function jsx<P extends ComponentProps>(Component: ComponentFactory<P> | string, props: P & {
|
|
25
|
+
key?: Key;
|
|
26
|
+
}, _key?: Key | null): PptxElement;
|
|
27
|
+
/** Alias for jsx (used when there are multiple children). */
|
|
28
|
+
export declare const jsxs: typeof jsx;
|
|
29
|
+
/** Alias for dev-mode (same as jsx in this runtime). */
|
|
30
|
+
export declare const jsxDEV: typeof jsx;
|
|
31
|
+
export { Fragment } from "./node.js";
|
|
32
|
+
export declare namespace JSX {
|
|
33
|
+
/**
|
|
34
|
+
* Accept both sync (PptxNode) and async (Promise<PptxNode>) component results.
|
|
35
|
+
* TypeScript checks the component factory's declared return type against JSX.Element.
|
|
36
|
+
* Async results are wrapped in PptxNodePromise by the jsx() factory at runtime.
|
|
37
|
+
*/
|
|
38
|
+
type Element = PptxNode | Promise<PptxNode>;
|
|
39
|
+
interface ElementChildrenAttribute {
|
|
40
|
+
children: unknown;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* React compatibility: allow `key` on every JSX element so that
|
|
44
|
+
* React-style code (e.g. `key` inside `.map()` loops) type-checks.
|
|
45
|
+
* The key is stripped at runtime and has no effect on rendering.
|
|
46
|
+
*/
|
|
47
|
+
interface IntrinsicAttributes {
|
|
48
|
+
key?: Key | null;
|
|
49
|
+
}
|
|
50
|
+
interface IntrinsicElements {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Hyperscript-style factory.
|
|
55
|
+
* Prefer `pptxElement` to avoid shadowing PptxGenJS height props.
|
|
56
|
+
*/
|
|
57
|
+
export declare function h<P extends ComponentProps>(Component: ComponentFactory<P>, props: (P & {
|
|
58
|
+
key?: Key | null;
|
|
59
|
+
}) | null, ...children: PptxChild[]): PptxElement;
|
|
60
|
+
/** Alias that avoids shadowing the `h` (height) prop. */
|
|
61
|
+
export declare const pptxElement: typeof h;
|
|
62
|
+
/** React-compatible alias. */
|
|
63
|
+
export declare const createElement: typeof h;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSX runtime for pptxgenjsx.
|
|
3
|
+
*
|
|
4
|
+
* Provides jsx/jsxs/jsxDEV for TypeScript's `react-jsx` transform, plus
|
|
5
|
+
* Fragment (re-exported from node.js — the core model — so both this
|
|
6
|
+
* subpath and the package entry expose the same value).
|
|
7
|
+
* Async component factories are wrapped in PptxNodePromise for lazy resolution
|
|
8
|
+
* during tree traversal (in render.ts).
|
|
9
|
+
*/
|
|
10
|
+
import { createNode, flattenChildren, createPptxNodePromise, } from "./node.js";
|
|
11
|
+
// ── JSX factory ───────────────────────────────────────────────────
|
|
12
|
+
/**
|
|
13
|
+
* JSX factory — called by TypeScript's `react-jsx` transform.
|
|
14
|
+
*
|
|
15
|
+
* If the Component returns a Promise (async component), it is wrapped in
|
|
16
|
+
* a PptxNodePromise and resolved lazily during `createPptx` traversal.
|
|
17
|
+
*
|
|
18
|
+
* Note on the props type: the public signature intentionally does NOT add
|
|
19
|
+
* `children` unconditionally. Whether an element accepts children is
|
|
20
|
+
* decided by the component's own props type (container props declare
|
|
21
|
+
* `children`, leaf props use `children?: never`). The runtime still
|
|
22
|
+
* destructures whatever `children` the JSX transform passes in.
|
|
23
|
+
*/
|
|
24
|
+
export function jsx(Component, props, _key) {
|
|
25
|
+
// Cast to any: the JSX transform may pass `children` even when the
|
|
26
|
+
// component's public props type does not declare it (leaf components).
|
|
27
|
+
const { children, key: _unusedKey, ...rest } = (props ?? {});
|
|
28
|
+
const flatChildren = flattenChildren(children);
|
|
29
|
+
if (typeof Component === "string") {
|
|
30
|
+
// Intrinsic element (not used in this runtime, but kept for completeness)
|
|
31
|
+
return createNode(Component, {
|
|
32
|
+
...rest,
|
|
33
|
+
children: flatChildren,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
// ── Deferred execution via synchronous thunk ──────────────────────────
|
|
37
|
+
//
|
|
38
|
+
// Defer ALL non-string component factory calls so they execute during
|
|
39
|
+
// tree traversal (in render.ts) rather than during JSX construction.
|
|
40
|
+
//
|
|
41
|
+
// Why? Components like <Slide><Title /></Slide> evaluate children first
|
|
42
|
+
// (jsx(Title, {}) runs before jsx(Slide, ...)). If Title's factory calls
|
|
43
|
+
// useSlideContext(), useDeckContext(), or useGroupContext(), those contexts
|
|
44
|
+
// DON'T exist yet during JSX construction — they are set up in render.ts
|
|
45
|
+
// inside withSlideContext() / withDeckContext() / withGroupContext().
|
|
46
|
+
//
|
|
47
|
+
// By wrapping every factory call in a PptxNodePromise **thunk** (a zero-arg
|
|
48
|
+
// function), the factory is executed lazily when resolveChild() processes
|
|
49
|
+
// the promise. The thunk is called **synchronously** from resolveChild(),
|
|
50
|
+
// so the factory inherits whatever rendering context (slide / deck / group)
|
|
51
|
+
// is active at the call site.
|
|
52
|
+
//
|
|
53
|
+
// This is critical: using Promise.resolve().then() would break
|
|
54
|
+
// AsyncLocalStorage propagation because the promise chain is created
|
|
55
|
+
// during JSX construction (outside any rendering context). The thunk
|
|
56
|
+
// approach keeps the factory call synchronous from the perspective of
|
|
57
|
+
// the rendering engine's event loop.
|
|
58
|
+
// ───────────────────────────────────────────────────────────────────────
|
|
59
|
+
return createPptxNodePromise(() => Component({
|
|
60
|
+
...rest,
|
|
61
|
+
children: flatChildren,
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
/** Alias for jsx (used when there are multiple children). */
|
|
65
|
+
export const jsxs = jsx;
|
|
66
|
+
/** Alias for dev-mode (same as jsx in this runtime). */
|
|
67
|
+
export const jsxDEV = jsx;
|
|
68
|
+
// ── Fragment ──────────────────────────────────────────────────────
|
|
69
|
+
// Re-export from the core model (node.ts) so both the JSX runtime subpath
|
|
70
|
+
// and the package entry expose the same Fragment value. TypeScript's
|
|
71
|
+
// `jsxImportSource` transform imports Fragment from this subpath for `<>`.
|
|
72
|
+
export { Fragment } from "./node.js";
|
|
73
|
+
// ── Additional factory aliases (h / pptxElement / createElement) ──
|
|
74
|
+
/**
|
|
75
|
+
* Hyperscript-style factory.
|
|
76
|
+
* Prefer `pptxElement` to avoid shadowing PptxGenJS height props.
|
|
77
|
+
*/
|
|
78
|
+
export function h(Component, props, ...children) {
|
|
79
|
+
return jsx(Component, { ...props, children }, props?.key);
|
|
80
|
+
}
|
|
81
|
+
/** Alias that avoids shadowing the `h` (height) prop. */
|
|
82
|
+
export const pptxElement = h;
|
|
83
|
+
/** React-compatible alias. */
|
|
84
|
+
export const createElement = h;
|
|
85
|
+
//# sourceMappingURL=jsx-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-runtime.js","sourceRoot":"","sources":["../src/jsx-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAOL,UAAU,EACV,eAAe,EACf,qBAAqB,GACtB,MAAM,WAAW,CAAC;AAMnB,qEAAqE;AAErE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,GAAG,CACjB,SAAuC,EACvC,KAAwB,EACxB,IAAiB;IAEjB,mEAAmE;IACnE,uEAAuE;IACvE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE,CAAQ,CAAC;IACpE,MAAM,YAAY,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAE/C,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAClC,0EAA0E;QAC1E,OAAO,UAAU,CAAC,SAAS,EAAE;YAC3B,GAAG,IAAI;YACP,QAAQ,EAAE,YAAY;SAChB,CAAC,CAAC;IACZ,CAAC;IAED,yEAAyE;IACzE,EAAE;IACF,sEAAsE;IACtE,qEAAqE;IACrE,EAAE;IACF,yEAAyE;IACzE,0EAA0E;IAC1E,4EAA4E;IAC5E,yEAAyE;IACzE,sEAAsE;IACtE,EAAE;IACF,4EAA4E;IAC5E,0EAA0E;IAC1E,2EAA2E;IAC3E,4EAA4E;IAC5E,8BAA8B;IAC9B,EAAE;IACF,+DAA+D;IAC/D,qEAAqE;IACrE,sEAAsE;IACtE,sEAAsE;IACtE,qCAAqC;IACrC,0EAA0E;IAC1E,OAAO,qBAAqB,CAAC,GAAG,EAAE,CAChC,SAAS,CAAC;QACR,GAAG,IAAI;QACP,QAAQ,EAAE,YAAY;KACY,CAAC,CACtC,CAAC;AACJ,CAAC;AAED,6DAA6D;AAC7D,MAAM,CAAC,MAAM,IAAI,GAAe,GAAG,CAAC;AAEpC,wDAAwD;AACxD,MAAM,CAAC,MAAM,MAAM,GAAe,GAAG,CAAC;AAEtC,qEAAqE;AAErE,0EAA0E;AAC1E,sEAAsE;AACtE,2EAA2E;AAC3E,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAyBrC,qEAAqE;AAErE;;;GAGG;AACH,MAAM,UAAU,CAAC,CACf,SAA8B,EAC9B,KAAwC,EACxC,GAAG,QAAqB;IAExB,OAAO,GAAG,CAAC,SAAS,EAAE,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAS,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AACnE,CAAC;AAED,yDAAyD;AACzD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAE7B,8BAA8B;AAC9B,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC"}
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core node types for pptxgenjsx.
|
|
3
|
+
*
|
|
4
|
+
* Provides PptxNode, PptxNodePromise (async component support),
|
|
5
|
+
* and type definitions used by the JSX runtime and rendering engine.
|
|
6
|
+
*/
|
|
7
|
+
import type PptxGenJS from "pptxgenjs-plus";
|
|
8
|
+
export type PrimitiveChild = string | number | boolean | null | undefined;
|
|
9
|
+
export type ComponentProps = object;
|
|
10
|
+
/**
|
|
11
|
+
* Props for container components — components that legitimately render
|
|
12
|
+
* their children (Deck, Slide, Section, Master, Placeholder, Text,
|
|
13
|
+
* TextRun, Notes, Table, TableRow, TableCell, Group, ...).
|
|
14
|
+
*/
|
|
15
|
+
export type ContainerProps = {
|
|
16
|
+
children?: PptxChildren;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Props for leaf components — components that must NOT render children
|
|
20
|
+
* (shapes, lines, images, media, charts, ...). Declaring
|
|
21
|
+
* `children?: never` makes the intent explicit and turns any accidental
|
|
22
|
+
* JSX children into a compile-time error.
|
|
23
|
+
*/
|
|
24
|
+
export type LeafProps = {
|
|
25
|
+
children?: never;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A deferred component factory wrapper.
|
|
29
|
+
*
|
|
30
|
+
* Unlike the original design (which stored a pre-resolved Promise), this
|
|
31
|
+
* stores a **thunk** — a zero-argument factory function. The thunk is
|
|
32
|
+
* called **synchronously** when `resolveChild()` processes the promise,
|
|
33
|
+
* which means the factory executes inside whatever rendering context
|
|
34
|
+
* (slide / deck / group) is active at that point.
|
|
35
|
+
*
|
|
36
|
+
* This is critical for `AsyncLocalStorage`-based contexts
|
|
37
|
+
* (`useSlideContext`, `useDeckContext`, `useGroupContext`): if the
|
|
38
|
+
* factory were scheduled via `Promise.resolve().then()`, the promise
|
|
39
|
+
* chain would be created outside the rendering context (during JSX
|
|
40
|
+
* construction), and `AsyncLocalStorage` context would NOT propagate
|
|
41
|
+
* into the `.then()` callback. By calling the thunk synchronously
|
|
42
|
+
* from `resolveChild()`, the factory inherits the caller's rendering
|
|
43
|
+
* context naturally.
|
|
44
|
+
*/
|
|
45
|
+
export interface PptxNodePromise {
|
|
46
|
+
readonly $pptxPromise: true;
|
|
47
|
+
/** Factory thunk — called synchronously by resolveChild(). */
|
|
48
|
+
readonly thunk: () => PptxNode | Promise<PptxNode>;
|
|
49
|
+
}
|
|
50
|
+
export declare function createPptxNodePromise(thunk: () => PptxNode | Promise<PptxNode>): PptxNodePromise;
|
|
51
|
+
export declare function isPptxNodePromise(value: unknown): value is PptxNodePromise;
|
|
52
|
+
/**
|
|
53
|
+
* Resolve a PptxNodePromise or plain Promise recursively until a concrete
|
|
54
|
+
* PptxNode (or primitive) is obtained.
|
|
55
|
+
*
|
|
56
|
+
* Resolution strategy:
|
|
57
|
+
* 1. PptxNodePromise → call `.thunk()` synchronously, then re-check
|
|
58
|
+
* 2. Promise (async component) → `await` it, then re-check
|
|
59
|
+
* 3. PptxNode or primitive → return as-is
|
|
60
|
+
*
|
|
61
|
+
* Why recursive? With deferred component factories (jsx-runtime wraps ALL
|
|
62
|
+
* non-string component calls in PptxNodePromise), an async component like:
|
|
63
|
+
*
|
|
64
|
+
* async function TitleSlide() {
|
|
65
|
+
* return (<>...</>); // jsx(Fragment, ...) returns PptxNodePromise
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* produces Promise<PptxNodePromise> — the outer Promise from the `async`
|
|
69
|
+
* keyword, the inner PptxNodePromise from the JSX factory. We need to
|
|
70
|
+
* unwrap both layers before we get a usable PptxNode.
|
|
71
|
+
*/
|
|
72
|
+
export declare function resolveChild<T>(child: T): Promise<T extends PptxNodePromise ? PptxNode : T>;
|
|
73
|
+
export type PptxChild = PptxNode | PptxNodePromise | Promise<PptxNode> | PrimitiveChild;
|
|
74
|
+
export type PptxChildren = PptxChild | PptxChildren[];
|
|
75
|
+
/**
|
|
76
|
+
* Node types that are terminal rendering operations and therefore cannot
|
|
77
|
+
* contain children. This is the shared source of truth for construction,
|
|
78
|
+
* rendering, and validation.
|
|
79
|
+
*/
|
|
80
|
+
export declare const LEAF_NODE_TYPES: ReadonlySet<string>;
|
|
81
|
+
/** Whether a node type is a leaf component. */
|
|
82
|
+
export declare function isLeafNodeType(type: string): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Fail when a leaf component receives children. This protects JavaScript,
|
|
85
|
+
* `any`, and hand-built node trees that bypass the TSX `children?: never`
|
|
86
|
+
* constraint.
|
|
87
|
+
*/
|
|
88
|
+
export declare function assertLeafHasNoChildren(type: string, children: readonly PptxChild[]): void;
|
|
89
|
+
/** A component factory can return a PptxNode synchronously OR a Promise.
|
|
90
|
+
*
|
|
91
|
+
* Children support is **not** added unconditionally anymore: whether a
|
|
92
|
+
* component accepts children is decided by its own props type. Container
|
|
93
|
+
* components declare `children?: PptxChildren` (or use {@link ContainerProps});
|
|
94
|
+
* leaf components omit it or use {@link LeafProps} (`children?: never`).
|
|
95
|
+
* User-defined components only accept children if their props declare them.
|
|
96
|
+
*/
|
|
97
|
+
export type ComponentFactory<P extends ComponentProps = ComponentProps> = (props: P) => PptxNode<string, P> | Promise<PptxNode<string, P>>;
|
|
98
|
+
/** Union type for JSX element — accepts both sync and async component results. */
|
|
99
|
+
export type PptxElement = PptxNode | PptxNodePromise;
|
|
100
|
+
export declare class PptxNode<TType extends string = string, TProps extends ComponentProps = ComponentProps> {
|
|
101
|
+
readonly $$pptxNode = true;
|
|
102
|
+
readonly type: TType;
|
|
103
|
+
readonly props: Readonly<TProps>;
|
|
104
|
+
readonly children: readonly PptxChild[];
|
|
105
|
+
constructor(type: TType, props: TProps & {
|
|
106
|
+
children?: PptxChildren;
|
|
107
|
+
});
|
|
108
|
+
toJSON(): Record<string, unknown>;
|
|
109
|
+
}
|
|
110
|
+
export declare function createNode<TType extends string, TProps extends ComponentProps>(type: TType, props: TProps & {
|
|
111
|
+
children?: PptxChildren;
|
|
112
|
+
}): PptxNode<TType, TProps>;
|
|
113
|
+
export declare function isPptxNode(value: unknown): value is PptxNode;
|
|
114
|
+
export declare function isValidChild(value: unknown): value is PptxNode | PptxNodePromise | string | number | boolean;
|
|
115
|
+
export declare function flattenChildren(children: PptxChildren | undefined): PptxChild[];
|
|
116
|
+
/**
|
|
117
|
+
* Structural fragment — renders its children in place without producing
|
|
118
|
+
* a wrapper element.
|
|
119
|
+
*
|
|
120
|
+
* Defined in the core model (not in the JSX runtime) so the public entry
|
|
121
|
+
* point can re-export it as a **value** (`export { Fragment }`). The JSX
|
|
122
|
+
* runtime re-exports the same function for TypeScript's `jsxImportSource`
|
|
123
|
+
* automatic import on `<>...</>`.
|
|
124
|
+
*/
|
|
125
|
+
export declare function Fragment(props: {
|
|
126
|
+
children?: PptxChildren;
|
|
127
|
+
}): PptxNode<"Fragment", {}>;
|
|
128
|
+
export type PptxPresentation = PptxGenJS;
|
|
129
|
+
export type PptxSlide = PptxGenJS.PresSlide;
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
export function createPptxNodePromise(thunk) {
|
|
2
|
+
return { $pptxPromise: true, thunk };
|
|
3
|
+
}
|
|
4
|
+
export function isPptxNodePromise(value) {
|
|
5
|
+
return value != null && typeof value === "object" && value.$pptxPromise === true;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Resolve a PptxNodePromise or plain Promise recursively until a concrete
|
|
9
|
+
* PptxNode (or primitive) is obtained.
|
|
10
|
+
*
|
|
11
|
+
* Resolution strategy:
|
|
12
|
+
* 1. PptxNodePromise → call `.thunk()` synchronously, then re-check
|
|
13
|
+
* 2. Promise (async component) → `await` it, then re-check
|
|
14
|
+
* 3. PptxNode or primitive → return as-is
|
|
15
|
+
*
|
|
16
|
+
* Why recursive? With deferred component factories (jsx-runtime wraps ALL
|
|
17
|
+
* non-string component calls in PptxNodePromise), an async component like:
|
|
18
|
+
*
|
|
19
|
+
* async function TitleSlide() {
|
|
20
|
+
* return (<>...</>); // jsx(Fragment, ...) returns PptxNodePromise
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* produces Promise<PptxNodePromise> — the outer Promise from the `async`
|
|
24
|
+
* keyword, the inner PptxNodePromise from the JSX factory. We need to
|
|
25
|
+
* unwrap both layers before we get a usable PptxNode.
|
|
26
|
+
*/
|
|
27
|
+
export async function resolveChild(child) {
|
|
28
|
+
// eslint-disable-next-line no-constant-condition
|
|
29
|
+
while (true) {
|
|
30
|
+
if (isPptxNodePromise(child)) {
|
|
31
|
+
// Call thunk synchronously — the factory needs to run inside
|
|
32
|
+
// whatever AsyncLocalStorage context (slide / deck / group) the
|
|
33
|
+
// caller has set up.
|
|
34
|
+
child = child.thunk();
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (child instanceof Promise) {
|
|
38
|
+
child = (await child);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
return child;
|
|
44
|
+
}
|
|
45
|
+
// ── Leaf components ───────────────────────────────────────────────
|
|
46
|
+
/**
|
|
47
|
+
* Node types that are terminal rendering operations and therefore cannot
|
|
48
|
+
* contain children. This is the shared source of truth for construction,
|
|
49
|
+
* rendering, and validation.
|
|
50
|
+
*/
|
|
51
|
+
export const LEAF_NODE_TYPES = new Set([
|
|
52
|
+
"Shape",
|
|
53
|
+
"Rect",
|
|
54
|
+
"RoundRect",
|
|
55
|
+
"Ellipse",
|
|
56
|
+
"Oval",
|
|
57
|
+
"Triangle",
|
|
58
|
+
"RightTriangle",
|
|
59
|
+
"Diamond",
|
|
60
|
+
"Pentagon",
|
|
61
|
+
"Hexagon",
|
|
62
|
+
"Star",
|
|
63
|
+
"Star4",
|
|
64
|
+
"Star5",
|
|
65
|
+
"Star6",
|
|
66
|
+
"Star8",
|
|
67
|
+
"Star10",
|
|
68
|
+
"Arc",
|
|
69
|
+
"BlockArc",
|
|
70
|
+
"PieShape",
|
|
71
|
+
"CustomGeometry",
|
|
72
|
+
"LeftArrow",
|
|
73
|
+
"RightArrow",
|
|
74
|
+
"UpArrow",
|
|
75
|
+
"DownArrow",
|
|
76
|
+
"LeftRightArrow",
|
|
77
|
+
"UpDownArrow",
|
|
78
|
+
"Chevron",
|
|
79
|
+
"Cloud",
|
|
80
|
+
"Heart",
|
|
81
|
+
"Donut",
|
|
82
|
+
"Plus",
|
|
83
|
+
"Line",
|
|
84
|
+
"LineBetween",
|
|
85
|
+
"Image",
|
|
86
|
+
"Media",
|
|
87
|
+
"Chart",
|
|
88
|
+
"AreaChart",
|
|
89
|
+
"BarChart",
|
|
90
|
+
"Bar3DChart",
|
|
91
|
+
"BubbleChart",
|
|
92
|
+
"DoughnutChart",
|
|
93
|
+
"LineChart",
|
|
94
|
+
"PieChart",
|
|
95
|
+
"RadarChart",
|
|
96
|
+
"ScatterChart",
|
|
97
|
+
"Layout",
|
|
98
|
+
"TableToSlides",
|
|
99
|
+
]);
|
|
100
|
+
/** Whether a node type is a leaf component. */
|
|
101
|
+
export function isLeafNodeType(type) {
|
|
102
|
+
return LEAF_NODE_TYPES.has(type);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Fail when a leaf component receives children. This protects JavaScript,
|
|
106
|
+
* `any`, and hand-built node trees that bypass the TSX `children?: never`
|
|
107
|
+
* constraint.
|
|
108
|
+
*/
|
|
109
|
+
export function assertLeafHasNoChildren(type, children) {
|
|
110
|
+
if (!isLeafNodeType(type) || children.length === 0)
|
|
111
|
+
return;
|
|
112
|
+
throw new Error(`${type} is a leaf component and cannot contain children. ` +
|
|
113
|
+
`Render <${type} /> and <Text> as siblings. Wrap them in <Group> only when ` +
|
|
114
|
+
`relative positioning is needed, or use <Text shape="..."> for a single text box ` +
|
|
115
|
+
`with a shape background.`);
|
|
116
|
+
}
|
|
117
|
+
// ── PptxNode class ────────────────────────────────────────────────
|
|
118
|
+
export class PptxNode {
|
|
119
|
+
$$pptxNode = true;
|
|
120
|
+
type;
|
|
121
|
+
props;
|
|
122
|
+
children;
|
|
123
|
+
constructor(type, props) {
|
|
124
|
+
const { children, ...rest } = props;
|
|
125
|
+
const flatChildren = flattenChildren(children);
|
|
126
|
+
assertLeafHasNoChildren(type, flatChildren);
|
|
127
|
+
this.type = type;
|
|
128
|
+
this.props = Object.freeze(rest);
|
|
129
|
+
this.children = Object.freeze(flatChildren);
|
|
130
|
+
}
|
|
131
|
+
toJSON() {
|
|
132
|
+
return {
|
|
133
|
+
type: this.type,
|
|
134
|
+
props: this.props,
|
|
135
|
+
children: this.children
|
|
136
|
+
.filter((c) => isValidChild(c))
|
|
137
|
+
.map((c) => (isPptxNode(c) ? c.toJSON() : c)),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// ── Factory helpers ───────────────────────────────────────────────
|
|
142
|
+
export function createNode(type, props) {
|
|
143
|
+
return new PptxNode(type, props);
|
|
144
|
+
}
|
|
145
|
+
export function isPptxNode(value) {
|
|
146
|
+
return (value instanceof PptxNode || !!(value && typeof value === "object" && value.$$pptxNode));
|
|
147
|
+
}
|
|
148
|
+
export function isValidChild(value) {
|
|
149
|
+
return (isPptxNode(value) ||
|
|
150
|
+
isPptxNodePromise(value) ||
|
|
151
|
+
typeof value === "string" ||
|
|
152
|
+
typeof value === "number" ||
|
|
153
|
+
typeof value === "boolean");
|
|
154
|
+
}
|
|
155
|
+
export function flattenChildren(children) {
|
|
156
|
+
if (children == null || children === false)
|
|
157
|
+
return [];
|
|
158
|
+
const result = [];
|
|
159
|
+
flatten(children, result);
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
function flatten(input, output) {
|
|
163
|
+
if (Array.isArray(input)) {
|
|
164
|
+
for (const item of input) {
|
|
165
|
+
flatten(item, output);
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (input != null && input !== false) {
|
|
170
|
+
output.push(input);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// ── Fragment ──────────────────────────────────────────────────────
|
|
174
|
+
/**
|
|
175
|
+
* Structural fragment — renders its children in place without producing
|
|
176
|
+
* a wrapper element.
|
|
177
|
+
*
|
|
178
|
+
* Defined in the core model (not in the JSX runtime) so the public entry
|
|
179
|
+
* point can re-export it as a **value** (`export { Fragment }`). The JSX
|
|
180
|
+
* runtime re-exports the same function for TypeScript's `jsxImportSource`
|
|
181
|
+
* automatic import on `<>...</>`.
|
|
182
|
+
*/
|
|
183
|
+
export function Fragment(props) {
|
|
184
|
+
return createNode("Fragment", {
|
|
185
|
+
children: flattenChildren(props.children),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AA2DA,MAAM,UAAU,qBAAqB,CAAC,KAAyC;IAC7E,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAK,KAAa,CAAC,YAAY,KAAK,IAAI,CAAC;AAC5F,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAI,KAAQ;IAC5C,iDAAiD;IACjD,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,6DAA6D;YAC7D,gEAAgE;YAChE,qBAAqB;YACrB,KAAK,GAAG,KAAK,CAAC,KAAK,EAAS,CAAC;YAC7B,SAAS;QACX,CAAC;QACD,IAAI,KAAK,YAAY,OAAO,EAAE,CAAC;YAC7B,KAAK,GAAG,CAAC,MAAM,KAAK,CAAQ,CAAC;YAC7B,SAAS;QACX,CAAC;QACD,MAAM;IACR,CAAC;IACD,OAAO,KAAY,CAAC;AACtB,CAAC;AAQD,qEAAqE;AAErE;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IAC1D,OAAO;IACP,MAAM;IACN,WAAW;IACX,SAAS;IACT,MAAM;IACN,UAAU;IACV,eAAe;IACf,SAAS;IACT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tD,MAAM,MAAM,GAAgB,EAAE,CAAC;IAC/B,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC1B,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,OAAO,CAAC,KAAmB,EAAE,MAAmB;IACvD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACxB,CAAC;QACD,OAAO;IACT,CAAC;IACD,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;QACrC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC;AAED,qEAAqE;AAErE;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAkC;IACzD,OAAO,UAAU,CAAC,UAAU,EAAE;QAC5B,QAAQ,EAAE,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC;KAC1C,CAAC,CAAC;AACL,CAAC"}
|
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendering engine for pptxgenjsx.
|
|
3
|
+
*
|
|
4
|
+
* All tree-traversal functions are async to support PptxNodePromise resolution.
|
|
5
|
+
* Component factories and type definitions are in `./components.ts`.
|
|
6
|
+
*/
|
|
7
|
+
import type PptxGenJSType from "pptxgenjs-plus";
|
|
8
|
+
import { type PptxElement } from "./node.js";
|
|
9
|
+
export interface CreatePptxOptions {
|
|
10
|
+
/** Reuse an existing PptxGenJS instance instead of creating a new one. */
|
|
11
|
+
pptx?: PptxGenJSType;
|
|
12
|
+
}
|
|
13
|
+
export type RenderPptxOptions = PptxGenJSType.WriteFileProps & CreatePptxOptions;
|
|
14
|
+
export type WritePptxOptions = PptxGenJSType.WriteProps & CreatePptxOptions;
|
|
15
|
+
/**
|
|
16
|
+
* Create a PptxGenJS instance from a Deck or Slide node tree.
|
|
17
|
+
* Resolves any PptxNodePromise wrappers during traversal.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createPptx(root: PptxElement, options?: CreatePptxOptions): Promise<PptxGenJSType>;
|
|
20
|
+
/**
|
|
21
|
+
* Render to a .pptx file.
|
|
22
|
+
* Returns the file name (as per PptxGenJS.writeFile).
|
|
23
|
+
*/
|
|
24
|
+
export declare function renderPptx(root: PptxElement, options?: RenderPptxOptions): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Write to a buffer / ArrayBuffer / Blob.
|
|
27
|
+
*/
|
|
28
|
+
export declare function writePptx(root: PptxElement, options?: WritePptxOptions): Promise<string | ArrayBuffer | Blob | Uint8Array>;
|
|
29
|
+
/** Alias for renderPptx. */
|
|
30
|
+
export declare const render: typeof renderPptx;
|
|
31
|
+
/** Alias for writePptx. */
|
|
32
|
+
export declare const write: typeof writePptx;
|
|
33
|
+
export interface ValidationIssue {
|
|
34
|
+
code: string;
|
|
35
|
+
level: "error" | "warning";
|
|
36
|
+
path: string;
|
|
37
|
+
message: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Validate a Deck or Slide tree for common mistakes.
|
|
41
|
+
* Returns a list of issues (errors and warnings).
|
|
42
|
+
*
|
|
43
|
+
* Accepts both resolved PptxNode and deferred PptxNodePromise (which is
|
|
44
|
+
* resolved first). Only resolves **already-resolved** children during
|
|
45
|
+
* traversal — PptxNodePromise (deferred component thunks) are skipped
|
|
46
|
+
* because their factories may require rendering context (slide / deck /
|
|
47
|
+
* group) that is NOT available during validation.
|
|
48
|
+
*
|
|
49
|
+
* This means validation only checks the structural skeleton (Deck → Slide
|
|
50
|
+
* → intrinsic elements like Text, Rect, etc.) and skips any user-defined
|
|
51
|
+
* component boundaries until rendering.
|
|
52
|
+
*
|
|
53
|
+
* Leaf components (shapes, images, charts, ...) are reported as
|
|
54
|
+
* `child.leaf` errors when they carry already-resolved children. The
|
|
55
|
+
* render pipeline enforces the same rule authoritatively via
|
|
56
|
+
* `assertLeafHasNoChildren()`, so an empty issues array never means the
|
|
57
|
+
* whole tree was fully validated.
|
|
58
|
+
*/
|
|
59
|
+
export declare function validateDeck(root: PptxElement): Promise<ValidationIssue[]>;
|
|
60
|
+
/** Alias for backward compatibility. */
|
|
61
|
+
export declare const validatePptxTree: typeof validateDeck;
|