How hectordev2/js-ppt-generate works
1. What this repo is
- js-ppt-generate is a browser-only presentation generator. It has no backend and runs entirely in the client.
- The core architectural split is between two entry points: JSON mode (index.html → src/main.ts) and JS mode (js.html → src/main-js.ts).
2. Two independent inputs, one shared output system
- JSON mode accepts a declarative presentation schema.
- JS mode executes user-authored pptxgenjs code in the browser.
- Both modes converge on the same downstream capabilities: generate PPTX, generate PDF, and render a visual preview.
3. Shared internal representation
- JSON mode does not render directly from the input schema. It first normalizes and validates into a Document Node Tree (DNT).
- The DNT is the main architectural boundary: everything after it is format-specific rendering, not input-specific parsing.
4. JSON mode pipeline
- src/parser.ts handles parse → normalize → validate → compile.
- src/schema/types.ts defines the presentation schema and element types.
- src/schema/validator.ts enforces structure and type guards.
- src/engine/runtime.ts turns schema elements into positioned, styled document nodes using layout rules and theme defaults.
5. JS mode pipeline
- src/modes/library.ts provides the browser execution environment for pptxgenjs, including a require("pptxgenjs") polyfill and interception of writeFile().
- Instead of downloading immediately, the created presentation instance is captured so the app can reuse it for export and preview.
- This mode bypasses the DNT compiler and works from the pptxgenjs object model directly.
6. Rendering outputs are separate adapters
- src/renderers/pptx.ts converts DNT into PPTX using PptxGenJS.
- src/renderers/pdf.ts converts DNT into PDF using jsPDF.
- src/renderers/html.ts converts DNT into HTML for the JSON-mode preview.
- In JS mode, src/lib/pptx-to-pdf.ts handles PDF creation from the captured pptxgenjs instance.
7. Preview is a shared UI concern, but with two data sources
- JSON mode preview is generated from the DNT via HTML rendering.
- JS mode preview is generated by src/modes/js-preview.ts, which inspects internal pptxgenjs slide objects and turns them into HTML.
- The preview subsystem is intentionally decoupled from export generation so the same slide content can be shown without requiring file output.
8. Layout, theming, and styling
- src/engine/theme.ts defines the built-in themes and color/style resolution.
- src/engine/runtime.ts applies layout behavior such as placement, grid positioning, and default sizing.
- Style resolution is hierarchical: element styles override theme defaults, and tokens like accent or background are resolved centrally.
9. Editor and runtime ergonomics
- src/editor/setup.ts wires up Monaco Editor and its workers, which suggests the app includes in-browser code editing for both JSON and JS modes.
- src/state.ts and src/types.ts hold shared app state, logs, and processing status that support compile/execute feedback in the UI.
10. Sample content and app bootstrap
- src/lib/samples.ts provides example presentations, likely used to seed the editor or demonstrate the pipeline in both modes.
- src/main.ts and src/main-js.ts are the two bootstraps that connect editor input, compilation/execution, rendering, export, and preview.
- index.html and js.html are the mode-specific shells that select which pipeline is active.
11. Technology boundaries that matter
- The app is TypeScript-first, built with Vite, and uses vanilla HTML/CSS for the UI.
- Presentation generation depends on PptxGenJS; PDF export uses jsPDF.
- Because everything runs in the browser, the key architecture constraint is managing execution safely and converting internal structures into preview/export artifacts without server-side services.
12. How to diagram it
- A good architecture diagram should show:
- two entry points feeding two input pipelines,
- a shared presentation runtime/preview layer,
- separate adapters for PPTX, PDF, and HTML output,
- and a clear boundary between input parsing/execution and output rendering.
- The main “join point” is the captured document model: DNT for JSON mode, captured pptxgenjs state for JS mode.
Main entry points: main.ts Main boot · runtime.ts Layout runtime · main-js.ts JS boot · parser.ts Parser
Components 18
Entry shells
Mode-specific HTML entry points and bootstraps.
- index.html · JSON-mode browser entry shell.
index.html - js.html · JS-mode browser entry shell.
js.html - Main boot · Wires JSON mode UI, parsing, preview, and export.
src/main.ts - JS boot · Wires JS mode UI, execution capture, preview, and export.
src/main-js.ts
JSON mode
Declarative presentation pipeline.
- Parser · Parse, normalize, validate, and compile JSON input.
src/parser.ts - Schema types · Presentation schema and element type definitions.
src/schema/types.ts - Validator · Structural validation and type guards for JSON presentations.
src/schema/validator.ts
JS mode
Browser-executed pptxgenjs pipeline.
- Pptx library · Browser execution environment for pptxgenjs with require polyfill and write interception.
src/modes/library.ts - JS preview · Turns captured pptxgenjs slide objects into HTML preview output.
src/modes/js-preview.ts
Shared core
Runtime, state, editor, and sample data shared across modes.
- Layout runtime · Builds positioned document nodes from schema elements using layout and theme rules.
src/engine/runtime.ts - Theme system · Built-in themes and centralized style/token resolution.
src/engine/theme.ts - Samples · Example presentations used to seed or demonstrate the editor.
src/lib/samples.ts - App state · Shared processing status, logs, and UI state.
src/state.ts - Editor setup · Monaco editor and worker setup for browser editing.
src/editor/setup.ts
Output adapters
Format-specific export and preview renderers.
- PPTX renderer · Converts the document node tree into PptxGenJS output.
src/renderers/pptx.ts - PDF renderer · Converts the document node tree into PDF output via jsPDF.
src/renderers/pdf.ts - HTML renderer · Renders the document node tree as HTML for JSON-mode preview.
src/renderers/html.ts - PPTX to PDF · Creates PDF from captured pptxgenjs presentation in JS mode.
src/lib/pptx-to-pdf.ts
Connections 20
- index.html → Main boot: loads · JSON mode shell loads the JSON-mode bootstrap.
- js.html → JS boot: loads · JS mode shell loads the JS-mode bootstrap.
- Main boot → Editor setup: uses · Bootstraps browser editing in JSON mode.
- Main boot → Samples: seeds · Sample presentations can initialize the JSON editor.
- Main boot → Parser: parses · JSON mode compiles user schema into the document node tree.
- Parser → Schema types: reads · Parser relies on the presentation schema definitions.
- Parser → Validator: validates · Parser delegates structural checks and guards.
- Parser → Layout runtime: compiles · Normalization feeds the layout/runtime compiler.
- Layout runtime → Theme system: resolves · Runtime applies theme defaults and token resolution.
- Layout runtime → HTML renderer: previews · JSON-mode preview is rendered from the DNT as HTML.
- Layout runtime → PPTX renderer: exports · The shared DNT is exported to PPTX.
- Layout runtime → PDF renderer: exports · The shared DNT is exported to PDF.
- JS boot → Editor setup: uses · Bootstraps browser editing in JS mode.
- JS boot → Pptx library: executes · JS mode runs user code inside the browser library environment.
- Pptx library → PPTX to PDF: captures · Intercepted presentation instance is reused for PDF creation.
- Pptx library → JS preview: inspects · Captured pptxgenjs slide objects drive JS-mode preview.
- Main boot → App state: updates · JSON-mode processing status and logs are stored in shared app state.
- JS boot → App state: updates · JS-mode processing status and logs are stored in shared app state.
- Editor setup → App state: reports · Editor/runtime feedback flows through shared state.
- Samples → JS boot: demonstrates · Sample content can seed JS mode as well as JSON mode.