@pptx-glimpse/document 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # @pptx-glimpse/document
2
+
3
+ OOXML document foundation for pptx-glimpse.
4
+
5
+ This package reads PowerPoint `.pptx` files into a `PptxSourceModel`, derives a non-mutating computed view, and writes the source model back to PPTX bytes. It does not render SVG or PNG; use `pptx-glimpse` for rendering.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @pptx-glimpse/document
11
+ ```
12
+
13
+ Node.js 22 or later is required.
14
+
15
+ ## Public API
16
+
17
+ Import supported APIs from the package root:
18
+
19
+ ```ts
20
+ import {
21
+ createComputedView,
22
+ readPptx,
23
+ replaceTextRunPlainText,
24
+ writePptx,
25
+ } from "@pptx-glimpse/document";
26
+ ```
27
+
28
+ The stable entry point includes:
29
+
30
+ - `readPptx(input)` for reading PPTX bytes into a `PptxSourceModel`
31
+ - `createComputedView(source, options?)` for deriving slide/layout/master/theme effective values without mutating the source
32
+ - `writePptx(source)` for structural round-trip writing
33
+ - Text editing helpers such as `replaceTextRunPlainText(source, handle, text)` and related source handle lookup types exported from the root entry point
34
+ - Source model, computed view, and unit types needed to consume those APIs
35
+
36
+ Parser helpers, raw replacement internals, writer dirty-scope implementation details, and OOXML implementation modules outside the package root are internal and may change without notice.
37
+
38
+ ## Read and Write Round Trip
39
+
40
+ ```ts
41
+ import { readFile, writeFile } from "node:fs/promises";
42
+ import { createComputedView, readPptx, writePptx } from "@pptx-glimpse/document";
43
+
44
+ const input = await readFile("input.pptx");
45
+ const source = readPptx(input);
46
+ const computed = createComputedView(source);
47
+
48
+ console.log(`slides: ${computed.slides.length}`);
49
+
50
+ const output = writePptx(source);
51
+ await writeFile("round-trip.pptx", output);
52
+ ```
53
+
54
+ `writePptx` targets structural round-trip preservation rather than byte-for-byte equality. Unedited package material is preserved where possible, and supported edits mark dirty PPTX parts for serialization.
55
+
56
+ ## Text-Run Edit
57
+
58
+ ```ts
59
+ import { readFile, writeFile } from "node:fs/promises";
60
+ import {
61
+ readPptx,
62
+ replaceTextRunPlainText,
63
+ writePptx,
64
+ } from "@pptx-glimpse/document";
65
+
66
+ const source = readPptx(await readFile("input.pptx"));
67
+ const firstTextRun = source.slides
68
+ .flatMap((slide) => slide.shapes)
69
+ .flatMap((shape) =>
70
+ shape.kind === "shape" && shape.textBody !== undefined
71
+ ? shape.textBody.paragraphs.flatMap((paragraph) => paragraph.runs)
72
+ : [],
73
+ )
74
+ .find((run) => run.handle !== undefined);
75
+
76
+ if (firstTextRun?.handle === undefined) {
77
+ throw new Error("No editable text run found");
78
+ }
79
+
80
+ const edited = replaceTextRunPlainText(source, firstTextRun.handle, "Edited text");
81
+ await writeFile("edited.pptx", writePptx(edited));
82
+ ```
83
+
84
+ ## Stability
85
+
86
+ `@pptx-glimpse/document` starts as a `0.x` package. APIs exported from the package root are the intended public surface, but the document model is still evolving. Minor releases may refine exported types or behavior while the package remains below `1.0.0`.
87
+
88
+ Do not import from deep internal paths such as `@pptx-glimpse/document/dist/...` or source module paths. Those modules are implementation details.