@betteroffice/pptx 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -8
- package/dist/generated/pptx_wasm_bg.wasm +0 -0
- package/dist/index.d.ts +762 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -33,20 +33,27 @@ sizeCanvasForSlide(canvas, frame, devicePixelRatio);
|
|
|
33
33
|
await paintSlide(canvas.getContext('2d')!, frame, devicePixelRatio);
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
Browsers can call `initWasm()`; Node and SSR pass wasm bytes to `initWasm(bytes)`.
|
|
37
37
|
|
|
38
38
|
All parsing, edits, collaboration state, text shaping, layout, hit-testing, and
|
|
39
39
|
display-list emission stay in Rust. The package decodes the typed boundary and
|
|
40
40
|
replays the resulting primitives on canvas. Font bytes are supplied by the host
|
|
41
41
|
and registered with the Rust shaper through `openPresentation`.
|
|
42
42
|
|
|
43
|
-
Beyond rendering, `PresentationHandle` covers editing:
|
|
43
|
+
Beyond rendering, `PresentationHandle` covers editing: version-checked batches
|
|
44
|
+
(`readContent` / `findText` / `validateEdits` / `applyEdits`), read-only
|
|
45
|
+
structured export (`exportStructured` / `exportMarkdown`), text
|
|
44
46
|
(`insertText` / `deleteText` / `formatText` / `setParagraphAlignment`), slides
|
|
45
47
|
(`insertSlide` / `deleteSlide` / `moveSlide`), shapes
|
|
46
|
-
(`addTextBox` / `
|
|
48
|
+
(`addTextBox` / `addShape` / `addPicture` / `moveShape` / `resizeShape` /
|
|
49
|
+
`setShapeRect`), paint order (`bringShapeToFront` / `sendShapeToBack` /
|
|
50
|
+
`bringShapeForward` / `sendShapeBackward`), comments
|
|
47
51
|
(`addComment` / `replyToComment` / `setCommentStatus` / `removeComment`),
|
|
48
52
|
`hitTest`, undo/redo, and `save()`, which serializes the deck back to `.pptx`
|
|
49
53
|
bytes with edits applied — untouched slides keep their exact source part bytes.
|
|
54
|
+
`addPicture` accepts common raster/vector MIME types (PNG, JPEG, GIF, BMP,
|
|
55
|
+
TIFF, WebP, SVG) up to 8 MiB, rejecting anything past either limit before it
|
|
56
|
+
reaches the deck.
|
|
50
57
|
|
|
51
58
|
## Agent proposals
|
|
52
59
|
|
|
@@ -86,8 +93,7 @@ unchanged words as context and retaining fonts and emphasis. Pass its
|
|
|
86
93
|
`textChanges` to `paintSlide()` for red highlights and strikethrough on deletions,
|
|
87
94
|
and green highlights and underlines on insertions. Its snapshot and UTF-16
|
|
88
95
|
ranges describe a temporary review layout; use the live handle for editing and
|
|
89
|
-
the ordinary proposed layout for the result after acceptance.
|
|
90
|
-
does not replace the live hit-test state or add markup to saved presentations.
|
|
96
|
+
the ordinary proposed layout for the result after acceptance.
|
|
91
97
|
|
|
92
98
|
Supported edits replace text within one paragraph, format text, align paragraphs,
|
|
93
99
|
set shape geometry/fill/stroke/adjustments, and replace speaker notes. Text offsets
|
|
@@ -101,15 +107,115 @@ with target IDs. Review a fresh preview before calling
|
|
|
101
107
|
Unrelated peer edits survive acceptance and Undo. Up to 64 proposals, each with
|
|
102
108
|
1–256 edits, may be pending.
|
|
103
109
|
|
|
104
|
-
Pending proposals
|
|
105
|
-
exports and collaboration updates. Accepted edits save and sync normally.
|
|
110
|
+
Pending proposals live in the open session; accepted edits save and synchronize.
|
|
106
111
|
`isProposalsAvailable()` supports hosts that load an older WASM build.
|
|
107
112
|
|
|
113
|
+
## Version-checked edit batches
|
|
114
|
+
|
|
115
|
+
Read the deck with its session version, then apply a batch against that
|
|
116
|
+
version: every step commits in one transaction, one update and one undo step,
|
|
117
|
+
or the batch returns a typed refusal and nothing changes.
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
const read = deck.readContent();
|
|
121
|
+
if (!read.ok) throw new Error(read.failure.message);
|
|
122
|
+
const story = read.stories[0];
|
|
123
|
+
const within = { slideId: story.slideId, shapeId: story.shapeId, storyId: story.storyId };
|
|
124
|
+
|
|
125
|
+
const result = deck.applyEdits({
|
|
126
|
+
expectVersion: read.version,
|
|
127
|
+
steps: [
|
|
128
|
+
{ op: 'replaceText', target: { kind: 'search', within, text: 'Q3' }, text: 'Q4' },
|
|
129
|
+
{ op: 'setSlideNotes', target: { slideId: story.slideId }, text: 'Updated for Q4' },
|
|
130
|
+
],
|
|
131
|
+
});
|
|
132
|
+
if (!result.ok) console.warn(result.failure.code, result.failure.stepIndex);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
A story reads as its paragraphs joined by `\n`. Offsets are story-local UTF-16
|
|
136
|
+
positions, and each entry of `paragraphs` gives a paragraph's span, its soft
|
|
137
|
+
line breaks (which also read as `\n`) and its field results. `findText()`
|
|
138
|
+
searches exactly, case-sensitively and within paragraphs; a `search` target
|
|
139
|
+
must match exactly once in its story, overlapping occurrences included. Every
|
|
140
|
+
target and guard resolves against `expectVersion`, so a later step never sees
|
|
141
|
+
an earlier step's offsets.
|
|
142
|
+
|
|
143
|
+
Steps insert, replace and delete text within one paragraph, format text, align
|
|
144
|
+
paragraphs, replace speaker notes, and set the rectangle, fill or outline of a
|
|
145
|
+
shape at the top of a slide (fill and outline on preset shapes). An `expect`
|
|
146
|
+
guard refuses its step unless the target still reads as expected. Receipts
|
|
147
|
+
locate each change in the final state. `validateEdits()` runs every check,
|
|
148
|
+
staging included, without changing anything. `history: 'none'` keeps a batch
|
|
149
|
+
out of undo history and existing undo and redo entries in place;
|
|
150
|
+
`source: 'agent'` records provenance only.
|
|
151
|
+
|
|
152
|
+
Refusals carry a `code` (`stale-version`, `missing-target`, `ambiguous-target`,
|
|
153
|
+
`content-mismatch`, `overlapping-steps`, `unsupported`, `invalid-step`,
|
|
154
|
+
`limit-exceeded`), the failing `stepIndex` and the target; malformed requests
|
|
155
|
+
throw, and so do NaN or infinite numbers. Slide, shape, story and paragraph
|
|
156
|
+
ids and versions are session-scoped.
|
|
157
|
+
|
|
158
|
+
## Structured export
|
|
159
|
+
|
|
160
|
+
`exportStructured()` returns the committed deck as JSON with the version it was
|
|
161
|
+
read at, and `exportMarkdown()` renders that same read as Markdown. Neither
|
|
162
|
+
flushes editor input or changes anything. `exportPptxStructured(bytes)`,
|
|
163
|
+
`exportPptxMarkdown(bytes)` and `renderPptxMarkdown(content)` do the same
|
|
164
|
+
headless, with anchors that address the returned snapshot only.
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
import { exportPptxMarkdown } from '@betteroffice/pptx';
|
|
168
|
+
|
|
169
|
+
const read = deck.exportStructured({ includeNotes: true });
|
|
170
|
+
if (!read.ok) throw new Error(read.failure.message);
|
|
171
|
+
console.log(read.content.slides);
|
|
172
|
+
const { markdown, anchors } = await exportPptxMarkdown(bytes);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Slides come in deck order with their original index; shapes follow the current
|
|
176
|
+
shape tree depth first, a group's descendants at the group's position and table
|
|
177
|
+
cells row by row. This is the authored order, not a reading order inferred from
|
|
178
|
+
geometry. Paragraphs carry their level, effective alignment, authored
|
|
179
|
+
`bulletJson` and the resolved list marker (inherited from the layout, master
|
|
180
|
+
and text styles and numbered as the renderer numbers them); runs carry
|
|
181
|
+
formatting marks, links, soft line breaks, fields with their cached result and
|
|
182
|
+
zero-width placeholders for inline content such as equations. Tables keep their
|
|
183
|
+
grid, spans and merge continuations with each cell's current story. Pictures,
|
|
184
|
+
video, audio, charts, SmartArt, embedded objects and unmodelled shape-tree
|
|
185
|
+
elements become placeholders with their alternative text and relationships.
|
|
186
|
+
Each slide exports its own shapes, with an `inherited-content-omitted`
|
|
187
|
+
diagnostic for layout and master shapes drawn on it.
|
|
188
|
+
|
|
189
|
+
Every record carries an anchor: `range` anchors are batch text targets in the
|
|
190
|
+
story offsets of `readContent()`, so a session export's `range` anchor can be a
|
|
191
|
+
step's `target` at the version it was read at; `notes` and `comment` ranges
|
|
192
|
+
index their plain text, and records seeded from the file carry `provenance`
|
|
193
|
+
(part, SHA-256, element path, `sldId`, `cNvPr` id). Session anchors belong to
|
|
194
|
+
the returned version. A collaboration
|
|
195
|
+
session opened from an update seeded by an older release, without its source
|
|
196
|
+
file, may not know which slides are hidden:
|
|
197
|
+
those slides are exported with `hidden: null` and a `visibility-unknown`
|
|
198
|
+
diagnostic, and reopening the session with its source file restores their
|
|
199
|
+
visibility. Hidden slides and shapes, speaker notes (plain text)
|
|
200
|
+
and comments are excluded unless `includeHiddenSlides`, `includeHiddenShapes`,
|
|
201
|
+
`includeNotes` or `includeComments` asks for them, and `includeFormatting:
|
|
202
|
+
false` drops marks. Everything left out or not represented is listed in
|
|
203
|
+
`diagnostics`. `maxBlocks` (10,000 by default; slides, shapes, paragraphs,
|
|
204
|
+
notes and comments count) and `maxBytes` (8 MiB of compact JSON) stop the
|
|
205
|
+
export at a whole record and set `truncated`. Unusable limits come back as an
|
|
206
|
+
`invalid-options` or `limit-exceeded` refusal (`PptxExportError` for the
|
|
207
|
+
headless functions); malformed options throw.
|
|
208
|
+
|
|
209
|
+
Markdown renders slide headings, title placeholders as headings, paragraphs
|
|
210
|
+
with literal list markers, pipe or entity-escaped HTML tables, object
|
|
211
|
+
placeholders, notes and comments, with a `<!-- pptx-export:N -->` marker before
|
|
212
|
+
each block that `anchors` maps back to its source.
|
|
213
|
+
|
|
108
214
|
## Comments
|
|
109
215
|
|
|
110
216
|
PowerPoint has two comment systems and a file only ever uses one: `legacy`
|
|
111
217
|
reads in every version of PowerPoint plus LibreOffice and Google Slides, while
|
|
112
|
-
`modern` carries replies and
|
|
218
|
+
`modern` carries replies and resolution for PowerPoint 365.
|
|
113
219
|
A deck commits to one at its first comment, so `setCommentFlavor` only works
|
|
114
220
|
while `comments()` is empty, and `replyToComment` / `setCommentStatus` throw on
|
|
115
221
|
a legacy deck.
|
|
@@ -163,3 +269,34 @@ Package builds copy the binary into `dist/generated`.
|
|
|
163
269
|
|
|
164
270
|
[JavaScript guide](https://docs.betteroffice.dev/docs/javascript) ·
|
|
165
271
|
[Changelog](https://github.com/openooxml/betteroffice/blob/main/packages/pptx/CHANGELOG.md) · Apache-2.0.
|
|
272
|
+
|
|
273
|
+
### Operation profiles
|
|
274
|
+
|
|
275
|
+
`layoutSlideProfiled` returns `{ layout, profile }` with scope, layout, and
|
|
276
|
+
serialization durations in milliseconds. Profiled mutation methods such as
|
|
277
|
+
`insertTextProfiled` and `addTextBoxProfiled` return `{ receipt, profile }`;
|
|
278
|
+
`undoProfiled` reports undo, snapshot, and serialization timings. These methods
|
|
279
|
+
share the normal operations and add stage timing. See the
|
|
280
|
+
[corpus and browser tests](../../e2e/README.md) for usage and timing limits.
|
|
281
|
+
|
|
282
|
+
## Host undo and comment controls
|
|
283
|
+
|
|
284
|
+
`handle.setUndoCaptureMode('manual')` groups tracked local edits across pauses
|
|
285
|
+
and operation types until `handle.addUndoBoundary()`. The getter
|
|
286
|
+
`handle.undoCaptureMode()` returns `'auto'` or `'manual'`. Changing modes closes
|
|
287
|
+
the current group and preserves history; setting the same mode is a no-op.
|
|
288
|
+
Auto preserves the existing policy (500 ms capture on native targets, separate
|
|
289
|
+
transactions in the browser). Remote and agent origins remain outside local
|
|
290
|
+
undo. These controls group history; edit batches make edits atomic.
|
|
291
|
+
|
|
292
|
+
`handle.anchorCaret(storyId, index)` returns a caret anchor, plain data that
|
|
293
|
+
later edits, undo, redo and remote updates carry along with the text;
|
|
294
|
+
`handle.resolveCaretAnchor(anchor)` returns its current UTF-16 offset, or `null`
|
|
295
|
+
once the story is gone.
|
|
296
|
+
|
|
297
|
+
`handle.setCommentPosition(commentId, { xEmu, yEmu })` moves an existing root
|
|
298
|
+
comment on its current slide, preserving identity, author, text, replies, and
|
|
299
|
+
resolution state through collaboration, undo/redo, and export. Coordinates must
|
|
300
|
+
be safe integers in EMU. Replies share their root's position. Unknown IDs,
|
|
301
|
+
reply IDs, and invalid coordinates fail before mutation. Legacy PowerPoint
|
|
302
|
+
comments quantize exported positions to master units (1/576 inch).
|
|
Binary file
|