@betteroffice/pptx 0.0.1

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,60 @@
1
+ # @betteroffice/pptx
2
+
3
+ Framework-free core for the BetterOffice PPTX editor — the Rust parser, yrs deck
4
+ model, slide layout, and display-list engine compiled to WebAssembly, plus the
5
+ Canvas2D replay host.
6
+
7
+ > **Experimental (`0.0.x`).** The API is unstable and may change in any release.
8
+
9
+ ```bash
10
+ bun add @betteroffice/pptx
11
+ ```
12
+
13
+ Most apps want the turnkey React component in
14
+ [`@betteroffice/pptx-react`](https://www.npmjs.com/package/@betteroffice/pptx-react).
15
+ Use this package directly to build custom presentation chrome.
16
+
17
+ ## Usage
18
+
19
+ ```ts
20
+ import { initWasm, openPresentation, paintSlide } from '@betteroffice/pptx';
21
+
22
+ await initWasm();
23
+ const bytes = new Uint8Array(await file.arrayBuffer());
24
+ const deck = openPresentation(bytes, {
25
+ fonts: [{ family: 'My Sans', bytes: fontBytes }],
26
+ });
27
+ const frame = deck.layoutSlide(0);
28
+ await paintSlide(canvas.getContext('2d')!, frame, devicePixelRatio);
29
+ ```
30
+
31
+ All parsing, edits, collaboration state, text shaping, layout, hit-testing, and
32
+ display-list emission stay in Rust. The package decodes the typed boundary and
33
+ replays the resulting primitives on canvas. Font bytes are supplied by the host
34
+ and registered with the Rust shaper through `openPresentation`.
35
+
36
+ ## Collaboration
37
+
38
+ `PresentationHandle` is a collaboration replica. Pair it with
39
+ `CollaborationProvider` and a transport implementing the small
40
+ `CollaborationTransport` interface. The provider speaks the standard Yjs sync-v1
41
+ wire protocol, performs state-vector handshakes, forwards only local updates,
42
+ and bounds frames and pending backpressure bytes.
43
+
44
+ ```ts
45
+ import { CollaborationProvider } from '@betteroffice/pptx';
46
+
47
+ const provider = new CollaborationProvider(deck, transport);
48
+ deck.onUpdate((_update, origin) => {
49
+ if (origin === 'remote') repaint();
50
+ });
51
+ provider.connect();
52
+ ```
53
+
54
+ ## Development
55
+
56
+ The generated `.wasm` binary is intentionally not committed. From the repository
57
+ root, install `wasm-pack` 0.15.0 and run `bun scripts/build-pptx-wasm.ts`.
58
+ Package builds copy the binary into `dist/generated`.
59
+
60
+ Docs: https://betteroffice.dev · Apache-2.0.
Binary file
@@ -0,0 +1,425 @@
1
+ interface TextStyle {
2
+ bold?: boolean;
3
+ italic?: boolean;
4
+ fontSizePt?: number;
5
+ color?: string;
6
+ fontFamily?: string;
7
+ underline?: string;
8
+ }
9
+ type TextStylePatch = TextStyle;
10
+ interface TextStyleSnapshot {
11
+ bold: boolean | null;
12
+ italic: boolean | null;
13
+ fontSizePt: number | null;
14
+ color: string | null;
15
+ fontFamily: string | null;
16
+ underline: string | null;
17
+ }
18
+ interface TextRunSnapshot {
19
+ text: string;
20
+ style: TextStyleSnapshot;
21
+ }
22
+ interface ParagraphSnapshot {
23
+ id: string;
24
+ alignment: string | null;
25
+ level: number;
26
+ bulletJson: string | null;
27
+ runs: TextRunSnapshot[];
28
+ }
29
+ interface StorySnapshot {
30
+ id: string;
31
+ length: number;
32
+ paragraphs: ParagraphSnapshot[];
33
+ }
34
+ type ShapeKind = 'shape' | 'picture' | 'graphicFrame' | 'group';
35
+ interface ShapeSnapshot {
36
+ id: string;
37
+ sourceId: number;
38
+ kind: ShapeKind;
39
+ name: string;
40
+ x: number;
41
+ y: number;
42
+ width: number;
43
+ height: number;
44
+ rotationDeg: number;
45
+ flipH: boolean;
46
+ flipV: boolean;
47
+ geometry: string;
48
+ placeholder: unknown | null;
49
+ fill: unknown | null;
50
+ outline: unknown | null;
51
+ mediaPartPath: string | null;
52
+ graphic: unknown | null;
53
+ textStories: StorySnapshot[];
54
+ children: ShapeSnapshot[];
55
+ }
56
+ interface SlideSnapshot {
57
+ id: string;
58
+ sourcePartPath: string | null;
59
+ layoutPartPath: string | null;
60
+ name: string | null;
61
+ shapes: ShapeSnapshot[];
62
+ }
63
+ interface DeckSnapshot {
64
+ widthEmu: number;
65
+ heightEmu: number;
66
+ slides: SlideSnapshot[];
67
+ }
68
+ interface SlideReceipt {
69
+ slideId: string;
70
+ fromIndex: number | null;
71
+ toIndex: number | null;
72
+ }
73
+ interface ShapeReceipt {
74
+ slideId: string;
75
+ shapeId: string;
76
+ index: number;
77
+ }
78
+ interface ShapeRect {
79
+ x: number;
80
+ y: number;
81
+ width: number;
82
+ height: number;
83
+ }
84
+ interface TransformReceipt {
85
+ slideId: string;
86
+ shapeId: string;
87
+ before: ShapeRect;
88
+ after: ShapeRect;
89
+ }
90
+ interface TextReceipt {
91
+ storyId: string;
92
+ start: number;
93
+ end: number;
94
+ text: string;
95
+ }
96
+ interface ShapeDraft {
97
+ name: string;
98
+ rect: ShapeRect;
99
+ text: string;
100
+ style: TextStyle;
101
+ }
102
+ interface HistoryResult {
103
+ applied: boolean;
104
+ snapshot: DeckSnapshot;
105
+ }
106
+ interface PptxFontFace {
107
+ family: string;
108
+ bold?: boolean;
109
+ italic?: boolean;
110
+ bytes: Uint8Array;
111
+ }
112
+ type GeometryPathCommand = {
113
+ type: 'move';
114
+ x: number;
115
+ y: number;
116
+ } | {
117
+ type: 'line';
118
+ x: number;
119
+ y: number;
120
+ } | {
121
+ type: 'quad';
122
+ cpx: number;
123
+ cpy: number;
124
+ x: number;
125
+ y: number;
126
+ } | {
127
+ type: 'cubic';
128
+ cp1x: number;
129
+ cp1y: number;
130
+ cp2x: number;
131
+ cp2y: number;
132
+ x: number;
133
+ y: number;
134
+ } | {
135
+ type: 'close';
136
+ };
137
+ type Paint = {
138
+ kind: 'solid';
139
+ color: string;
140
+ } | {
141
+ kind: 'gradient';
142
+ gradientType: 'linear' | 'radial' | 'rectangular' | 'path';
143
+ angleDeg?: number;
144
+ stops: Array<{
145
+ position: number;
146
+ color: string;
147
+ }>;
148
+ };
149
+ interface Stroke {
150
+ color: string;
151
+ width: number;
152
+ dashed?: boolean;
153
+ }
154
+ interface PrimitiveTransform {
155
+ rotationDeg?: number;
156
+ flipH?: boolean;
157
+ flipV?: boolean;
158
+ }
159
+ interface PrimitiveBase {
160
+ objectId: number;
161
+ shapeId?: string;
162
+ x: number;
163
+ y: number;
164
+ w: number;
165
+ h: number;
166
+ transform?: PrimitiveTransform;
167
+ }
168
+ interface ShapePrimitive extends PrimitiveBase {
169
+ kind: 'shape';
170
+ name: string;
171
+ geometry: string;
172
+ path: GeometryPathCommand[];
173
+ adjustValues?: Record<string, number>;
174
+ fill?: Paint;
175
+ stroke?: Stroke;
176
+ }
177
+ interface ImagePrimitive extends PrimitiveBase {
178
+ kind: 'image';
179
+ name: string;
180
+ assetId?: string;
181
+ stroke?: Stroke;
182
+ }
183
+ interface CaretStop {
184
+ position: number;
185
+ x: number;
186
+ }
187
+ interface PositionedGlyph {
188
+ glyphId: number;
189
+ cluster: number;
190
+ x: number;
191
+ advance: number;
192
+ xOffset: number;
193
+ yOffset: number;
194
+ }
195
+ interface PositionedTextRun {
196
+ text: string;
197
+ start: number;
198
+ end: number;
199
+ x: number;
200
+ width: number;
201
+ fontId: number;
202
+ fontFamily: string;
203
+ fontSizePx: number;
204
+ bold: boolean;
205
+ italic: boolean;
206
+ underline: boolean;
207
+ color: string;
208
+ glyphs: PositionedGlyph[];
209
+ }
210
+ interface PositionedTextLine {
211
+ x: number;
212
+ y: number;
213
+ width: number;
214
+ height: number;
215
+ baseline: number;
216
+ start: number;
217
+ end: number;
218
+ runs: PositionedTextRun[];
219
+ caretStops: CaretStop[];
220
+ }
221
+ interface TextBoxPrimitive extends PrimitiveBase {
222
+ kind: 'textBox';
223
+ storyId?: string;
224
+ anchor: 'top' | 'center' | 'bottom';
225
+ paragraphs: Array<{
226
+ align?: 'left' | 'center' | 'right' | 'justify';
227
+ level: number;
228
+ runs: Array<{
229
+ text: string;
230
+ fontFamily: string;
231
+ fontSizePt: number;
232
+ bold?: boolean;
233
+ italic?: boolean;
234
+ underline?: boolean;
235
+ color: string;
236
+ }>;
237
+ }>;
238
+ lines: PositionedTextLine[];
239
+ overflow?: boolean;
240
+ }
241
+ interface PlaceholderPrimitive extends PrimitiveBase {
242
+ kind: 'placeholder';
243
+ name: string;
244
+ label?: string;
245
+ }
246
+ type SlidePrimitive = ShapePrimitive | ImagePrimitive | TextBoxPrimitive | PlaceholderPrimitive;
247
+ interface SlideDisplayList {
248
+ contractVersion: number;
249
+ width: number;
250
+ height: number;
251
+ background?: Paint;
252
+ primitives: SlidePrimitive[];
253
+ }
254
+ type HitTestResult = {
255
+ kind: 'shape';
256
+ shapeId: string;
257
+ } | {
258
+ kind: 'text';
259
+ shapeId: string;
260
+ storyId: string;
261
+ position: number;
262
+ };
263
+ interface UpdateEvent {
264
+ origin: 'local' | 'remote';
265
+ update: Uint8Array;
266
+ }
267
+
268
+ type CanvasImageResolver = (assetId: string) => CanvasImageSource | Promise<CanvasImageSource | null> | null;
269
+ interface PaintSlideOptions {
270
+ resolveImage?: CanvasImageResolver;
271
+ }
272
+ interface SlideCanvasLike {
273
+ width: number;
274
+ height: number;
275
+ style: {
276
+ width: string;
277
+ height: string;
278
+ };
279
+ }
280
+ declare function sizeCanvasForSlide(canvas: SlideCanvasLike, list: Pick<SlideDisplayList, 'width' | 'height'>, dpr: number, scale?: number): void;
281
+ declare function paintSlide(ctx: CanvasRenderingContext2D, list: SlideDisplayList, dpr?: number, scale?: number, options?: PaintSlideOptions): Promise<void>;
282
+
283
+ type CollaborationUpdateOrigin = 'local' | 'remote';
284
+ interface CollaborationReplica {
285
+ readonly clientId: number;
286
+ encodeStateVector(): Uint8Array;
287
+ encodeStateAsUpdate(remoteStateVector?: Uint8Array): Uint8Array;
288
+ applyUpdate(update: Uint8Array): unknown;
289
+ onUpdate(listener: (update: Uint8Array, origin: CollaborationUpdateOrigin) => void): () => void;
290
+ }
291
+ type CollaborationTransportEvent = {
292
+ type: 'open';
293
+ } | {
294
+ type: 'message';
295
+ data: Uint8Array;
296
+ } | {
297
+ type: 'close';
298
+ reason?: string;
299
+ } | {
300
+ type: 'error';
301
+ error: unknown;
302
+ } | {
303
+ type: 'drain';
304
+ };
305
+ interface CollaborationTransport {
306
+ /** Starts one connection attempt; transports may also reopen while still subscribed. */
307
+ connect(): void | Promise<void>;
308
+ disconnect(): void | Promise<void>;
309
+ /** Returns true only when the owned frame was accepted; false requires a later drain event. */
310
+ send(data: Uint8Array): boolean;
311
+ onEvent(listener: (event: CollaborationTransportEvent) => void): () => void;
312
+ }
313
+ type CollaborationStatus = 'disconnected' | 'connecting' | 'connected' | 'destroyed';
314
+ interface CollaborationStatusChange {
315
+ status: CollaborationStatus;
316
+ synced: boolean;
317
+ }
318
+ type CollaborationErrorCode = 'backpressure' | 'protocol' | 'replica' | 'transport';
319
+ declare class CollaborationError extends Error {
320
+ readonly code: CollaborationErrorCode;
321
+ readonly cause: unknown;
322
+ constructor(code: CollaborationErrorCode, message: string, cause?: unknown);
323
+ }
324
+ interface CollaborationProviderOptions {
325
+ maxFrameBytes?: number;
326
+ maxMessagesPerFrame?: number;
327
+ maxPendingBytes?: number;
328
+ }
329
+ type CollaborationStatusListener = (change: CollaborationStatusChange) => void;
330
+ type CollaborationErrorListener = (error: CollaborationError) => void;
331
+
332
+ declare class CollaborationProvider {
333
+ private readonly replica;
334
+ private readonly transport;
335
+ private readonly maxFrameBytes;
336
+ private readonly maxMessagesPerFrame;
337
+ private readonly maxPendingBytes;
338
+ private readonly statusListeners;
339
+ private readonly errorListeners;
340
+ private readonly pendingFrames;
341
+ private unsubscribeReplica;
342
+ private unsubscribeTransport;
343
+ private hasTransportSubscription;
344
+ private connectionStatus;
345
+ private isSynced;
346
+ private wantsConnection;
347
+ private isOpen;
348
+ private isDestroyed;
349
+ private epoch;
350
+ private connectAttempt;
351
+ private nextListenerId;
352
+ private queuedBytes;
353
+ private isFlushing;
354
+ constructor(replica: CollaborationReplica, transport: CollaborationTransport, options?: CollaborationProviderOptions);
355
+ get status(): CollaborationStatus;
356
+ get synced(): boolean;
357
+ get pendingBytes(): number;
358
+ connect(): void;
359
+ disconnect(): void;
360
+ destroy(): void;
361
+ onStatus(listener: CollaborationStatusListener): () => void;
362
+ onError(listener: CollaborationErrorListener): () => void;
363
+ private isCurrent;
364
+ private failConnection;
365
+ private takeTransportSubscription;
366
+ private cleanupTransport;
367
+ private handleTransportEvent;
368
+ private handleOpen;
369
+ private handleMessage;
370
+ private respondToSyncStep1;
371
+ private applyRemoteUpdate;
372
+ private forwardLocalUpdate;
373
+ private sendFrame;
374
+ private queueFrame;
375
+ private flushPending;
376
+ private clearPending;
377
+ private setStatus;
378
+ private report;
379
+ }
380
+
381
+ type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
382
+
383
+ type WasmInitInput = InitInput | Promise<InitInput>;
384
+ interface OpenPresentationOptions {
385
+ clientId?: number;
386
+ fonts?: ReadonlyArray<PptxFontFace>;
387
+ initialUpdate?: Uint8Array;
388
+ }
389
+ interface PresentationHandle extends CollaborationReplica {
390
+ readonly clientId: number;
391
+ snapshot(): DeckSnapshot;
392
+ story(storyId: string): StorySnapshot;
393
+ registerFont(face: PptxFontFace): number;
394
+ layoutSlide(slideIndex: number): SlideDisplayList;
395
+ hitTest(x: number, y: number): HitTestResult | null;
396
+ mediaBytes(partPath: string): Uint8Array;
397
+ insertText(storyId: string, index: number, text: string, style?: TextStyle): TextReceipt;
398
+ deleteText(storyId: string, start: number, end: number): TextReceipt;
399
+ formatText(storyId: string, start: number, end: number, patch: TextStylePatch): TextReceipt;
400
+ insertParagraphBreak(storyId: string, index: number): TextReceipt;
401
+ insertSlide(index: number, layoutPartPath?: string): SlideReceipt;
402
+ deleteSlide(slideId: string): SlideReceipt;
403
+ moveSlide(slideId: string, toIndex: number): SlideReceipt;
404
+ addTextBox(slideId: string, draft: ShapeDraft): ShapeReceipt;
405
+ removeShape(slideId: string, shapeId: string): ShapeReceipt;
406
+ moveShape(slideId: string, shapeId: string, x: number, y: number): TransformReceipt;
407
+ resizeShape(slideId: string, shapeId: string, width: number, height: number): TransformReceipt;
408
+ canUndo(): boolean;
409
+ canRedo(): boolean;
410
+ undo(): HistoryResult;
411
+ redo(): HistoryResult;
412
+ encodeStateVector(): Uint8Array;
413
+ encodeStateAsUpdate(remoteStateVector?: Uint8Array): Uint8Array;
414
+ encodeDiff(remoteStateVector: Uint8Array): Uint8Array;
415
+ applyUpdate(update: Uint8Array): DeckSnapshot;
416
+ onUpdate(listener: (update: Uint8Array, origin: CollaborationUpdateOrigin) => void): () => void;
417
+ dispose(): void;
418
+ }
419
+ declare function initWasm(input?: WasmInitInput): Promise<void>;
420
+ declare function isWasmAvailable(): boolean;
421
+ declare function wasmVersion(): string;
422
+ declare function inspectPresentation(bytes: Uint8Array): unknown;
423
+ declare function openPresentation(bytes: Uint8Array, options?: OpenPresentationOptions): PresentationHandle;
424
+
425
+ export { type CanvasImageResolver, type CaretStop, CollaborationError, type CollaborationErrorCode, type CollaborationErrorListener, CollaborationProvider, type CollaborationProviderOptions, type CollaborationReplica, type CollaborationStatus, type CollaborationStatusChange, type CollaborationStatusListener, type CollaborationTransport, type CollaborationTransportEvent, type CollaborationUpdateOrigin, type DeckSnapshot, type GeometryPathCommand, type HistoryResult, type HitTestResult, type ImagePrimitive, type OpenPresentationOptions, type Paint, type PaintSlideOptions, type ParagraphSnapshot, type PlaceholderPrimitive, type PositionedGlyph, type PositionedTextLine, type PositionedTextRun, type PptxFontFace, type PresentationHandle, type PrimitiveTransform, type ShapeDraft, type ShapeKind, type ShapePrimitive, type ShapeReceipt, type ShapeRect, type ShapeSnapshot, type SlideCanvasLike, type SlideDisplayList, type SlidePrimitive, type SlideReceipt, type SlideSnapshot, type StorySnapshot, type Stroke, type TextBoxPrimitive, type TextReceipt, type TextRunSnapshot, type TextStyle, type TextStylePatch, type TextStyleSnapshot, type TransformReceipt, type UpdateEvent, type WasmInitInput, initWasm, inspectPresentation, isWasmAvailable, openPresentation, paintSlide, sizeCanvasForSlide, wasmVersion };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ var ye=Object.defineProperty;var ge=(r,e,t)=>e in r?ye(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t;var u=(r,e,t)=>ge(r,typeof e!="symbol"?e+"":e,t);function me(r,e,t,n=1){r.width=Math.round(e.width*n*t),r.height=Math.round(e.height*n*t),r.style.width=`${e.width*n}px`,r.style.height=`${e.height*n}px`;}async function we(r,e,t=1,n=1,i={}){r.save();try{r.setTransform(t*n,0,0,t*n,0,0),r.clearRect(0,0,e.width,e.height),e.background&&(r.fillStyle=K(r,e.background,0,0,e.width,e.height),r.fillRect(0,0,e.width,e.height));for(let o of e.primitives)await Se(r,o,i);}finally{r.restore();}}async function Se(r,e,t){r.save();try{switch(ve(r,e),e.kind){case "shape":xe(r,e);break;case "image":await Ce(r,e,t.resolveImage);break;case "textBox":Ue(r,e);break;case "placeholder":Pe(r,e);break}}finally{r.restore();}}function ve(r,e){let t=e.transform;if(!t)return;let n=e.x+e.w/2,i=e.y+e.h/2;r.translate(n,i),r.rotate((t.rotationDeg??0)*Math.PI/180),r.scale(t.flipH?-1:1,t.flipV?-1:1),r.translate(-n,-i);}function xe(r,e){Te(r,e.path,e.x,e.y,e.w,e.h),e.fill&&(r.fillStyle=K(r,e.fill,e.x,e.y,e.w,e.h),r.fill()),e.stroke&&Q(r,e.stroke);}function Te(r,e,t,n,i,o){r.beginPath();for(let a of e)switch(a.type){case "move":r.moveTo(t+a.x*i,n+a.y*o);break;case "line":r.lineTo(t+a.x*i,n+a.y*o);break;case "quad":r.quadraticCurveTo(t+a.cpx*i,n+a.cpy*o,t+a.x*i,n+a.y*o);break;case "cubic":r.bezierCurveTo(t+a.cp1x*i,n+a.cp1y*o,t+a.cp2x*i,n+a.cp2y*o,t+a.x*i,n+a.y*o);break;case "close":r.closePath();break}}function Q(r,e){r.strokeStyle=e.color,r.lineWidth=e.width,r.setLineDash(e.dashed?[Math.max(3,e.width*2),Math.max(2,e.width)]:[]),r.stroke();}function K(r,e,t,n,i,o){if(e.kind==="solid")return e.color;let a=(e.angleDeg??0)*Math.PI/180,l=t+i/2,c=n+o/2,w=Math.hypot(i,o)/2,A=e.gradientType==="linear"?r.createLinearGradient(l-Math.cos(a)*w,c-Math.sin(a)*w,l+Math.cos(a)*w,c+Math.sin(a)*w):r.createRadialGradient(l,c,0,l,c,w);for(let P of e.stops)A.addColorStop(Math.max(0,Math.min(1,P.position)),P.color);return A}async function Ce(r,e,t){if(e.assetId&&t){let n=await t(e.assetId);n&&r.drawImage(n,e.x,e.y,e.w,e.h);}e.stroke&&(r.beginPath(),r.rect(e.x,e.y,e.w,e.h),Q(r,e.stroke));}function Ue(r,e){r.beginPath(),r.rect(e.x,e.y,e.w,e.h),r.clip(),r.textAlign="left",r.textBaseline="alphabetic";for(let t of e.lines)for(let n of t.runs)Ae(r,n,t.baseline);}function Ae(r,e,t){let n=e.italic?"italic ":"",i=e.bold?"bold ":"";r.font=`${n}${i}${e.fontSizePx}px ${Ee(e.fontFamily)}`,r.fillStyle=e.color,r.fillText(e.text,e.x,t),e.underline&&r.fillRect(e.x,t+e.fontSizePx*.08,e.width,Math.max(1,e.fontSizePx*.05));}function Ee(r){return r.includes(" ")?JSON.stringify(r):r}function Pe(r,e){r.strokeStyle="#8a94a6",r.lineWidth=1,r.setLineDash([5,4]),r.strokeRect(e.x,e.y,e.w,e.h),e.label&&(r.setLineDash([]),r.fillStyle="#5d6675",r.font="12px sans-serif",r.textAlign="center",r.textBaseline="middle",r.fillText(e.label,e.x+e.w/2,e.y+e.h/2,Math.max(0,e.w-12)));}var Re=Number.MAX_SAFE_INTEGER,m=class extends Error{constructor(e){super(e),this.name="ProtocolError";}},W=class{constructor(e){u(this,"bytes",e);u(this,"offset",0);}get done(){return this.offset===this.bytes.byteLength}readVarUint(){let e=0,t=1,n=0;for(;;){if(this.offset>=this.bytes.byteLength)throw new m("Truncated varUint");let i=this.bytes[this.offset++],o=i&127;if(o>Math.floor((Re-e)/t))throw new m("varUint exceeds Number.MAX_SAFE_INTEGER");if(e+=o*t,n+=1,(i&128)===0){if(n>1&&o===0)throw new m("Non-canonical varUint");return e}if(n>=8)throw new m("varUint exceeds Number.MAX_SAFE_INTEGER");t*=128;}}readVarUint8Array(){let e=this.readVarUint(),t=this.bytes.byteLength-this.offset;if(e>t)throw new m("Truncated varUint8Array");let n=this.bytes.slice(this.offset,this.offset+e);return this.offset+=e,n}readVarString(){let e=this.readVarUint8Array();try{return new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch(t){throw new m(`Invalid UTF-8 string${t instanceof Error?`: ${t.message}`:""}`)}}};function I(r){if(!Number.isSafeInteger(r)||r<0)throw new m("varUint value must be a non-negative safe integer");let e=[],t=r;for(;t>=128;)e.push(t%128|128),t=Math.floor(t/128);return e.push(t),Uint8Array.from(e)}function Z(r,e){let t=0;for(let o of r)if(t+=o.byteLength,t>e)throw new m(`Frame exceeds ${e} bytes`);let n=new Uint8Array(t),i=0;for(let o of r)n.set(o,i),i+=o.byteLength;return n}function z(r,e,t){return Z([I(0),I(r),I(e.byteLength),e],t)}function ee(r,e=16777216){return z(0,r,e)}function te(r,e=16777216){return z(1,r,e)}function ne(r,e=16777216){return z(2,r,e)}function re(r=16777216){let e=Uint8Array.of(0);return Z([I(1),I(e.byteLength),e],r)}function ie(r,e=16777216,t=4096){if(!(r instanceof Uint8Array))throw new m("Frame must be a Uint8Array");if(r.byteLength===0)throw new m("Frame is empty");if(r.byteLength>e)throw new m(`Frame exceeds ${e} bytes`);if(!Number.isSafeInteger(t)||t<1)throw new m("Message limit must be a positive integer");let n=new W(r),i=[];for(;!n.done;){if(i.length>=t)throw new m(`Frame exceeds ${t} messages`);let o=n.readVarUint();switch(o){case 0:{let a=n.readVarUint(),l=n.readVarUint8Array();if(a===0)i.push({type:"sync-step-1",stateVector:l});else if(a===1)i.push({type:"sync-step-2",update:l});else if(a===2)i.push({type:"update",update:l});else throw new m(`Unknown sync message type ${a}`);break}case 1:i.push({type:"awareness",update:n.readVarUint8Array()});break;case 2:{let a=n.readVarUint();if(a!==0)throw new m(`Unknown auth message type ${a}`);i.push({type:"auth",reason:n.readVarString()});break}case 3:i.push({type:"query-awareness"});break;default:throw new m(`Unknown top-level message type ${o}`)}}return i}var x=class extends Error{constructor(t,n,i){super(n);u(this,"code");u(this,"cause");this.name="CollaborationError",this.code=t,this.cause=i;}};var Le=16*1024*1024;function Y(r,e,t){if(!Number.isSafeInteger(e)||e<(t?0:1))throw new RangeError(`${r} must be ${t?"a non-negative":"a positive"} integer`);return e}function Ie(r){return r instanceof Error&&r.message?r.message:typeof r=="string"&&r?r:"Unknown error"}function b(r,e,t){return t instanceof x?t:new x(r,`${e}: ${Ie(t)}`,t)}function $(r,e){if(!(r instanceof Uint8Array))throw new TypeError(`${e} must return a Uint8Array`);return r.slice()}var B=class{constructor(e,t,n={}){u(this,"replica");u(this,"transport");u(this,"maxFrameBytes");u(this,"maxMessagesPerFrame");u(this,"maxPendingBytes");u(this,"statusListeners",new Map);u(this,"errorListeners",new Map);u(this,"pendingFrames",[]);u(this,"unsubscribeReplica");u(this,"unsubscribeTransport",()=>{});u(this,"hasTransportSubscription",false);u(this,"connectionStatus","disconnected");u(this,"isSynced",false);u(this,"wantsConnection",false);u(this,"isOpen",false);u(this,"isDestroyed",false);u(this,"epoch",0);u(this,"connectAttempt",0);u(this,"nextListenerId",0);u(this,"queuedBytes",0);u(this,"isFlushing",false);this.replica=e,this.transport=t,this.maxFrameBytes=Y("maxFrameBytes",n.maxFrameBytes??16777216,false),this.maxMessagesPerFrame=Y("maxMessagesPerFrame",n.maxMessagesPerFrame??4096,false),this.maxPendingBytes=Y("maxPendingBytes",n.maxPendingBytes??Le,true);try{this.unsubscribeReplica=e.onUpdate((i,o)=>{o==="local"&&this.forwardLocalUpdate(i);});}catch(i){throw b("replica","Failed to observe replica updates",i)}}get status(){return this.connectionStatus}get synced(){return this.isSynced}get pendingBytes(){return this.queuedBytes}connect(){if(this.isDestroyed||this.isOpen||this.connectionStatus==="connecting")return;this.wantsConnection=true;let e=this.hasTransportSubscription?this.epoch:++this.epoch,t=++this.connectAttempt;if(this.setStatus("connecting",false),!!this.isCurrent(e)){if(!this.hasTransportSubscription){let n;try{if(n=this.transport.onEvent(i=>this.handleTransportEvent(e,i)),typeof n!="function")throw new TypeError("Transport event subscription must return a function")}catch(i){this.failConnection(e,b("transport","Failed to subscribe to transport events",i));return}if(!this.isCurrent(e)){try{n();}catch(i){this.isDestroyed||this.report(b("transport","Failed to unsubscribe from stale transport events",i));}return}this.unsubscribeTransport=n,this.hasTransportSubscription=true;}try{let n=this.transport.connect();n&&n.catch(i=>{this.isCurrent(e)&&this.connectAttempt===t&&this.failConnection(e,b("transport","Transport connect failed",i));});}catch(n){this.failConnection(e,b("transport","Transport connect failed",n));}}}disconnect(){if(this.isDestroyed||!(this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus!=="disconnected"))return;this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let t=this.takeTransportSubscription();this.clearPending();let n=this.cleanupTransport(t,true);this.setStatus("disconnected",false);for(let i of n)this.report(i);}destroy(){if(this.isDestroyed)return;let e=this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus==="connecting"||this.connectionStatus==="connected";this.isDestroyed=true,this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let t=this.takeTransportSubscription();this.clearPending();let n=this.cleanupTransport(t,e);this.setStatus("destroyed",false);for(let i of n)this.report(i);try{this.unsubscribeReplica();}catch(i){this.report(b("replica","Failed to unsubscribe from replica updates",i));}this.unsubscribeReplica=()=>{},this.statusListeners.clear(),this.errorListeners.clear();}onStatus(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("status listener must be a function");let t=this.nextListenerId++;return this.statusListeners.set(t,e),()=>this.statusListeners.delete(t)}onError(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("error listener must be a function");let t=this.nextListenerId++;return this.errorListeners.set(t,e),()=>this.errorListeners.delete(t)}isCurrent(e){return !this.isDestroyed&&this.wantsConnection&&e===this.epoch}failConnection(e,t){if(!this.isCurrent(e))return;this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let n=this.takeTransportSubscription();this.clearPending();let i=this.cleanupTransport(n,true);this.setStatus("disconnected",false),this.report(t);for(let o of i)this.report(o);}takeTransportSubscription(){let e=this.unsubscribeTransport;return this.unsubscribeTransport=()=>{},this.hasTransportSubscription=false,e}cleanupTransport(e,t){let n=[];try{e();}catch(i){n.push(b("transport","Failed to unsubscribe from transport events",i));}if(!t)return n;try{let i=this.transport.disconnect();i&&i.catch(o=>{this.isDestroyed||this.report(b("transport","Transport disconnect failed",o));});}catch(i){n.push(b("transport","Transport disconnect failed",i));}return n}handleTransportEvent(e,t){if(this.isCurrent(e))switch(t.type){case "open":this.handleOpen(e);break;case "message":this.isOpen&&this.handleMessage(e,t.data);break;case "close":this.isOpen=false,this.connectAttempt+=1,this.clearPending(),this.setStatus("disconnected",false);break;case "error":this.failConnection(e,b("transport","Transport error",t.error));break;case "drain":this.isOpen&&this.flushPending();break;default:this.failConnection(e,new x("transport","Unknown transport event"));}}handleOpen(e){if(this.isOpen||(this.isOpen=true,this.clearPending(),this.setStatus("connected",false),!this.isCurrent(e)||!this.isOpen))return;let t;try{t=$(this.replica.encodeStateVector(),"encodeStateVector");}catch(n){this.failConnection(e,b("replica","Failed to encode replica state vector",n));return}try{this.sendFrame(ee(t,this.maxFrameBytes));}catch(n){this.failConnection(e,b("protocol","Failed to encode SyncStep1",n));}}handleMessage(e,t){let n;try{n=ie(t.slice(),this.maxFrameBytes,this.maxMessagesPerFrame);}catch(i){this.failConnection(e,b("protocol","Invalid collaboration frame",i));return}for(let i of n){if(!this.isCurrent(e)||!this.isOpen)return;switch(i.type){case "sync-step-1":this.respondToSyncStep1(e,i.stateVector);break;case "sync-step-2":this.applyRemoteUpdate(e,i.update)&&this.isCurrent(e)&&this.setStatus("connected",true);break;case "update":this.applyRemoteUpdate(e,i.update);break;case "awareness":break;case "auth":this.failConnection(e,new x("protocol",i.reason?`Authentication denied: ${i.reason}`:"Authentication denied"));return;case "query-awareness":try{this.sendFrame(re(this.maxFrameBytes));}catch(o){this.failConnection(e,b("protocol","Failed to encode awareness response",o));return}break}}}respondToSyncStep1(e,t){let n;try{n=$(this.replica.encodeStateAsUpdate(t.slice()),"encodeStateAsUpdate");}catch(i){this.failConnection(e,b("replica","Failed to encode replica update",i));return}try{this.sendFrame(te(n,this.maxFrameBytes));}catch(i){this.failConnection(e,b("protocol","Failed to encode SyncStep2",i));}}applyRemoteUpdate(e,t){try{return this.replica.applyUpdate(t.slice()),!0}catch(n){return this.failConnection(e,b("replica","Failed to apply remote update",n)),false}}forwardLocalUpdate(e){if(this.isDestroyed||!this.isOpen||!this.wantsConnection)return;let t=this.epoch,n;try{n=$(e,"Replica update");}catch(i){this.failConnection(t,b("replica","Invalid replica update",i));return}try{this.sendFrame(ne(n,this.maxFrameBytes));}catch(i){this.failConnection(t,b("protocol","Failed to encode update",i));}}sendFrame(e){if(!this.isOpen||this.isDestroyed||!this.wantsConnection)return;let t=this.epoch;if(this.pendingFrames.length>0){this.queueFrame(t,e);return}let n;try{n=this.transport.send(e.slice());}catch(i){this.failConnection(t,b("transport","Transport send failed",i));return}if(typeof n!="boolean"){this.failConnection(t,new x("transport","Transport send must return a boolean"));return}!n&&this.isCurrent(t)&&this.isOpen&&this.queueFrame(t,e);}queueFrame(e,t){if(t.byteLength>this.maxPendingBytes-this.queuedBytes){this.failConnection(e,new x("backpressure",`Pending collaboration data exceeds ${this.maxPendingBytes} bytes`));return}let n=t.slice();this.pendingFrames.push(n),this.queuedBytes+=n.byteLength;}flushPending(){if(!this.isFlushing){this.isFlushing=true;try{for(;this.isOpen&&!this.isDestroyed&&this.pendingFrames.length>0;){let e=this.epoch,t=this.pendingFrames[0],n;try{n=this.transport.send(t.slice());}catch(i){this.failConnection(e,b("transport","Transport send failed",i));return}if(typeof n!="boolean"){this.failConnection(e,new x("transport","Transport send must return a boolean"));return}if(!n||!this.isOpen||this.pendingFrames[0]!==t)return;this.pendingFrames.shift(),this.queuedBytes-=t.byteLength;}}finally{this.isFlushing=false;}}}clearPending(){this.pendingFrames.length=0,this.queuedBytes=0;}setStatus(e,t){if(this.connectionStatus===e&&this.isSynced===t)return;this.connectionStatus=e,this.isSynced=t;let n={status:e,synced:t};for(let[i,o]of [...this.statusListeners])if(this.statusListeners.get(i)===o)try{o(n);}catch{}}report(e){for(let[t,n]of [...this.errorListeners])if(this.errorListeners.get(t)===n)try{n(e);}catch{}}};var U=class r{static __wrap(e){let t=Object.create(r.prototype);return t.__wbg_ptr=e,oe.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,oe.unregister(this),e}free(){let e=this.__destroy_into_raw();s.__wbg_pptxdocument_free(e,0);}addTextBoxJson(e){let t,n;try{let a=S(e,s.__wbindgen_malloc,s.__wbindgen_realloc),l=_,c=s.pptxdocument_addTextBoxJson(this.__wbg_ptr,a,l);var i=c[0],o=c[1];if(c[3])throw i=0,o=0,f(c[2]);return t=i,n=o,h(i,o)}finally{s.__wbindgen_free(t,n,1);}}applyUpdateJson(e){let t,n;try{let a=R(e,s.__wbindgen_malloc),l=_,c=s.pptxdocument_applyUpdateJson(this.__wbg_ptr,a,l);var i=c[0],o=c[1];if(c[3])throw i=0,o=0,f(c[2]);return t=i,n=o,h(i,o)}finally{s.__wbindgen_free(t,n,1);}}canRedo(){return s.pptxdocument_canRedo(this.__wbg_ptr)!==0}canUndo(){return s.pptxdocument_canUndo(this.__wbg_ptr)!==0}clearUpdateObservation(){s.pptxdocument_clearUpdateObservation(this.__wbg_ptr);}get clientId(){return s.pptxdocument_clientId(this.__wbg_ptr)}deleteSlideJson(e){let t,n;try{let a=S(e,s.__wbindgen_malloc,s.__wbindgen_realloc),l=_,c=s.pptxdocument_deleteSlideJson(this.__wbg_ptr,a,l);var i=c[0],o=c[1];if(c[3])throw i=0,o=0,f(c[2]);return t=i,n=o,h(i,o)}finally{s.__wbindgen_free(t,n,1);}}deleteTextJson(e){let t,n;try{let a=S(e,s.__wbindgen_malloc,s.__wbindgen_realloc),l=_,c=s.pptxdocument_deleteTextJson(this.__wbg_ptr,a,l);var i=c[0],o=c[1];if(c[3])throw i=0,o=0,f(c[2]);return t=i,n=o,h(i,o)}finally{s.__wbindgen_free(t,n,1);}}drainUpdateEvent(){let e=s.pptxdocument_drainUpdateEvent(this.__wbg_ptr);var t=C(e[0],e[1]).slice();return s.__wbindgen_free(e[0],e[1]*1,1),t}encodeDiff(e){let t=R(e,s.__wbindgen_malloc),n=_,i=s.pptxdocument_encodeDiff(this.__wbg_ptr,t,n);if(i[3])throw f(i[2]);var o=C(i[0],i[1]).slice();return s.__wbindgen_free(i[0],i[1]*1,1),o}encodeStateAsUpdate(){let e=s.pptxdocument_encodeStateAsUpdate(this.__wbg_ptr);var t=C(e[0],e[1]).slice();return s.__wbindgen_free(e[0],e[1]*1,1),t}encodeStateVector(){let e=s.pptxdocument_encodeStateVector(this.__wbg_ptr);var t=C(e[0],e[1]).slice();return s.__wbindgen_free(e[0],e[1]*1,1),t}formatTextJson(e){let t,n;try{let a=S(e,s.__wbindgen_malloc,s.__wbindgen_realloc),l=_,c=s.pptxdocument_formatTextJson(this.__wbg_ptr,a,l);var i=c[0],o=c[1];if(c[3])throw i=0,o=0,f(c[2]);return t=i,n=o,h(i,o)}finally{s.__wbindgen_free(t,n,1);}}insertParagraphBreakJson(e){let t,n;try{let a=S(e,s.__wbindgen_malloc,s.__wbindgen_realloc),l=_,c=s.pptxdocument_insertParagraphBreakJson(this.__wbg_ptr,a,l);var i=c[0],o=c[1];if(c[3])throw i=0,o=0,f(c[2]);return t=i,n=o,h(i,o)}finally{s.__wbindgen_free(t,n,1);}}insertSlideJson(e){let t,n;try{let a=S(e,s.__wbindgen_malloc,s.__wbindgen_realloc),l=_,c=s.pptxdocument_insertSlideJson(this.__wbg_ptr,a,l);var i=c[0],o=c[1];if(c[3])throw i=0,o=0,f(c[2]);return t=i,n=o,h(i,o)}finally{s.__wbindgen_free(t,n,1);}}insertTextJson(e){let t,n;try{let a=S(e,s.__wbindgen_malloc,s.__wbindgen_realloc),l=_,c=s.pptxdocument_insertTextJson(this.__wbg_ptr,a,l);var i=c[0],o=c[1];if(c[3])throw i=0,o=0,f(c[2]);return t=i,n=o,h(i,o)}finally{s.__wbindgen_free(t,n,1);}}mediaBytes(e){let t=S(e,s.__wbindgen_malloc,s.__wbindgen_realloc),n=_,i=s.pptxdocument_mediaBytes(this.__wbg_ptr,t,n);if(i[3])throw f(i[2]);var o=C(i[0],i[1]).slice();return s.__wbindgen_free(i[0],i[1]*1,1),o}moveShapeJson(e){let t,n;try{let a=S(e,s.__wbindgen_malloc,s.__wbindgen_realloc),l=_,c=s.pptxdocument_moveShapeJson(this.__wbg_ptr,a,l);var i=c[0],o=c[1];if(c[3])throw i=0,o=0,f(c[2]);return t=i,n=o,h(i,o)}finally{s.__wbindgen_free(t,n,1);}}moveSlideJson(e){let t,n;try{let a=S(e,s.__wbindgen_malloc,s.__wbindgen_realloc),l=_,c=s.pptxdocument_moveSlideJson(this.__wbg_ptr,a,l);var i=c[0],o=c[1];if(c[3])throw i=0,o=0,f(c[2]);return t=i,n=o,h(i,o)}finally{s.__wbindgen_free(t,n,1);}}static openCollaborative(e,t){let n=R(e,s.__wbindgen_malloc),i=_,o=s.pptxdocument_openCollaborative(n,i,t);if(o[2])throw f(o[1]);return r.__wrap(o[0])}static openCollaborativeFromUpdate(e,t){let n=R(e,s.__wbindgen_malloc),i=_,o=s.pptxdocument_openCollaborativeFromUpdate(n,i,t);if(o[2])throw f(o[1]);return r.__wrap(o[0])}redoJson(){let e,t;try{let o=s.pptxdocument_redoJson(this.__wbg_ptr);var n=o[0],i=o[1];if(o[3])throw n=0,i=0,f(o[2]);return e=n,t=i,h(n,i)}finally{s.__wbindgen_free(e,t,1);}}removeShapeJson(e){let t,n;try{let a=S(e,s.__wbindgen_malloc,s.__wbindgen_realloc),l=_,c=s.pptxdocument_removeShapeJson(this.__wbg_ptr,a,l);var i=c[0],o=c[1];if(c[3])throw i=0,o=0,f(c[2]);return t=i,n=o,h(i,o)}finally{s.__wbindgen_free(t,n,1);}}resizeShapeJson(e){let t,n;try{let a=S(e,s.__wbindgen_malloc,s.__wbindgen_realloc),l=_,c=s.pptxdocument_resizeShapeJson(this.__wbg_ptr,a,l);var i=c[0],o=c[1];if(c[3])throw i=0,o=0,f(c[2]);return t=i,n=o,h(i,o)}finally{s.__wbindgen_free(t,n,1);}}snapshotJson(){let e,t;try{let o=s.pptxdocument_snapshotJson(this.__wbg_ptr);var n=o[0],i=o[1];if(o[3])throw n=0,i=0,f(o[2]);return e=n,t=i,h(n,i)}finally{s.__wbindgen_free(e,t,1);}}startUpdateObservation(){let e=s.pptxdocument_startUpdateObservation(this.__wbg_ptr);if(e[1])throw f(e[0])}storyJson(e){let t,n;try{let a=S(e,s.__wbindgen_malloc,s.__wbindgen_realloc),l=_,c=s.pptxdocument_storyJson(this.__wbg_ptr,a,l);var i=c[0],o=c[1];if(c[3])throw i=0,o=0,f(c[2]);return t=i,n=o,h(i,o)}finally{s.__wbindgen_free(t,n,1);}}undoJson(){let e,t;try{let o=s.pptxdocument_undoJson(this.__wbg_ptr);var n=o[0],i=o[1];if(o[3])throw n=0,i=0,f(o[2]);return e=n,t=i,h(n,i)}finally{s.__wbindgen_free(e,t,1);}}static version(){let e,t;try{let n=s.pptxdocument_version();return e=n[0],t=n[1],h(n[0],n[1])}finally{s.__wbindgen_free(e,t,1);}}};Symbol.dispose&&(U.prototype[Symbol.dispose]=U.prototype.free);var O=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,se.unregister(this),e}free(){let e=this.__destroy_into_raw();s.__wbg_pptxrenderer_free(e,0);}hitTestJson(e,t){let n,i;try{let l=s.pptxrenderer_hitTestJson(this.__wbg_ptr,e,t);var o=l[0],a=l[1];if(l[3])throw o=0,a=0,f(l[2]);return n=o,i=a,h(o,a)}finally{s.__wbindgen_free(n,i,1);}}layoutSlideJson(e,t){let n,i;try{Je(e,U);let l=s.pptxrenderer_layoutSlideJson(this.__wbg_ptr,e.__wbg_ptr,t);var o=l[0],a=l[1];if(l[3])throw o=0,a=0,f(l[2]);return n=o,i=a,h(o,a)}finally{s.__wbindgen_free(n,i,1);}}constructor(){let e=s.pptxrenderer_new();return this.__wbg_ptr=e,se.register(this,this.__wbg_ptr,this),this}registerFont(e,t,n,i){let o=S(e,s.__wbindgen_malloc,s.__wbindgen_realloc),a=_,l=R(i,s.__wbindgen_malloc),c=_,w=s.pptxrenderer_registerFont(this.__wbg_ptr,o,a,t,n,l,c);if(w[2])throw f(w[1]);return w[0]>>>0}};Symbol.dispose&&(O.prototype[Symbol.dispose]=O.prototype.free);function ce(r){let e,t;try{let o=R(r,s.__wbindgen_malloc),a=_,l=s.parsePptxJson(o,a);var n=l[0],i=l[1];if(l[3])throw n=0,i=0,f(l[2]);return e=n,t=i,h(n,i)}finally{s.__wbindgen_free(e,t,1);}}function le(){let r,e;try{let t=s.rendererVersion();return r=t[0],e=t[1],h(t[0],t[1])}finally{s.__wbindgen_free(r,e,1);}}function De(){return {__proto__:null,"./pptx_wasm_bg.js":{__proto__:null,__wbg___wbindgen_string_get_b0ca35b86a603356:function(e,t){let n=t,i=typeof n=="string"?n:void 0;var o=ke(i)?0:S(i,s.__wbindgen_malloc,s.__wbindgen_realloc),a=_;ae().setInt32(e+4,a,true),ae().setInt32(e+0,o,true);},__wbg___wbindgen_throw_344f42d3211c4765:function(e,t){throw new Error(h(e,t))},__wbg_getRandomValues_3f44b700395062e5:function(){return q(function(e,t){globalThis.crypto.getRandomValues(C(e,t));},arguments)},__wbg_get_78f252d074a84d0b:function(){return q(function(e,t){return Reflect.get(e,t)},arguments)},__wbg_get_unchecked_6e0ad6d2a41b06f6:function(e,t){return e[t>>>0]},__wbg_instanceof_Object_33f20e6f12439f3e:function(e){let t;try{t=e instanceof Object;}catch{t=false;}return t},__wbg_keys_58421f8f96795607:function(e){return Object.keys(e)},__wbg_length_1f0964f4a5e2c6d8:function(e){return e.length},__wbg_length_370319915dc99107:function(e){return e.length},__wbg_new_cd45aabdf6073e84:function(e){return new Uint8Array(e)},__wbg_new_da52cf8fe3429cb2:function(){return new Object},__wbg_new_from_slice_77cdfb7977362f3c:function(e,t){return new Uint8Array(C(e,t))},__wbg_prototypesetcall_4770620bbe4688a0:function(e,t,n){Uint8Array.prototype.set.call(C(e,t),n);},__wbg_set_8535240470bf2500:function(){return q(function(e,t,n){return Reflect.set(e,t,n)},arguments)},__wbindgen_cast_0000000000000001:function(e,t){return h(e,t)},__wbindgen_init_externref_table:function(){let e=s.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,true),e.set(t+3,false);}}}}var oe=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>s.__wbg_pptxdocument_free(r,1)),se=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>s.__wbg_pptxrenderer_free(r,1));function Me(r){let e=s.__externref_table_alloc();return s.__wbindgen_externrefs.set(e,r),e}function Je(r,e){if(!(r instanceof e))throw new Error(`expected instance of ${e.name}`)}function C(r,e){return r=r>>>0,F().subarray(r/1,r/1+e)}var E=null;function ae(){return (E===null||E.buffer.detached===true||E.buffer.detached===void 0&&E.buffer!==s.memory.buffer)&&(E=new DataView(s.memory.buffer)),E}function h(r,e){return Ve(r>>>0,e)}var D=null;function F(){return (D===null||D.byteLength===0)&&(D=new Uint8Array(s.memory.buffer)),D}function q(r,e){try{return r.apply(this,e)}catch(t){let n=Me(t);s.__wbindgen_exn_store(n);}}function ke(r){return r==null}function R(r,e){let t=e(r.length*1,1)>>>0;return F().set(r,t/1),_=r.length,t}function S(r,e,t){if(t===void 0){let l=M.encode(r),c=e(l.length,1)>>>0;return F().subarray(c,c+l.length).set(l),_=l.length,c}let n=r.length,i=e(n,1)>>>0,o=F(),a=0;for(;a<n;a++){let l=r.charCodeAt(a);if(l>127)break;o[i+a]=l;}if(a!==n){a!==0&&(r=r.slice(a)),i=t(i,n,n=a+r.length*3,1)>>>0;let l=F().subarray(i+a,i+n),c=M.encodeInto(r,l);a+=c.written,i=t(i,n,a,1)>>>0;}return _=a,i}function f(r){let e=s.__wbindgen_externrefs.get(r);return s.__externref_table_dealloc(r),e}var V=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true});V.decode();var Be=2146435072,H=0;function Ve(r,e){return H+=e,H>=Be&&(V=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}),V.decode(),H=e),V.decode(F().subarray(r,r+e))}var M=new TextEncoder;"encodeInto"in M||(M.encodeInto=function(r,e){let t=M.encode(r);return e.set(t),{read:r.length,written:t.length}});var _=0,s;function ze(r,e){return s=r.exports,E=null,D=null,s.__wbindgen_start(),s}async function Ye(r,e){if(typeof Response=="function"&&r instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(r,e)}catch(i){if(r.ok&&t(r.type)&&r.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",i);else throw i}let n=await r.arrayBuffer();return await WebAssembly.instantiate(n,e)}else {let n=await WebAssembly.instantiate(r,e);return n instanceof WebAssembly.Instance?{instance:n,module:r}:n}function t(n){switch(n){case "basic":case "cors":case "default":return true}return false}}async function de(r){if(s!==void 0)return s;if(r!==void 0&&(Object.getPrototypeOf(r)===Object.prototype?{module_or_path:r}=r:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),r===void 0)throw new Error("pptx-wasm requires an explicit module or URL");let e=De();(typeof r=="string"||typeof Request=="function"&&r instanceof Request||typeof URL=="function"&&r instanceof URL)&&(r=fetch(r));let{instance:t,module:n}=await Ye(await r,e);return ze(t)}var j=false,J;function $e(r=new URL("./generated/pptx_wasm_bg.wasm",import.meta.url)){return j?Promise.resolve():J||(J=de({module_or_path:r}).then(()=>{j=true;},e=>{throw J=void 0,L(e)}),J)}function qe(){return typeof WebAssembly=="object"}function He(){return X(),le()}function je(r){return X(),Ke(()=>ce(r))}function Xe(r,e={}){X();let t=e.clientId??Ge(),n=ue(()=>e.initialUpdate===void 0?U.openCollaborative(r,t):U.openCollaborativeFromUpdate(e.initialUpdate.slice(),t)),i=ue(()=>new O);for(let d of e.fonts??[])pe(i,d);let o=new Map,a=[],l=0,c=false,w=false,A=0,P=false,G=()=>{if(c)throw new Error("presentation handle is disposed")},fe=()=>{if(!(c||P||A!==0)){P=true;try{for(;!c&&a.length>0;){let d=a.shift();if(!d)break;for(let[p,g]of [...o]){if(c)return;if(o.get(p)===g)try{g(d.update.slice(),d.origin);}catch{}}}}finally{P=false,c&&(a.length=0);}}},_e=()=>{if(!(!w||c))for(;;){let d=n.drainUpdateEvent();if(d.byteLength===0)return;let p=d[0];if(p!==0&&p!==1)throw new Error(`pptx wasm returned unknown update origin ${p}`);a.push({update:d.slice(1),origin:p===0?"local":"remote"});}},T=(d,p=false)=>{G(),A+=1;try{let g,v,k=!1;try{g=d();}catch(N){v=N,k=!0;}if(p)try{_e();}catch(N){k||(v=N,k=!0);}if(k)throw L(v);return g}finally{A-=1,A===0&&fe();}},y=(d,p=false)=>T(()=>JSON.parse(d()),p),he=()=>{w||(T(()=>n.startUpdateObservation()),w=true);},be=()=>{!w||o.size>0||c||(a.length=0,T(()=>n.clearUpdateObservation()),w=false);};return {get clientId(){return T(()=>n.clientId)},snapshot(){return y(()=>n.snapshotJson())},story(d){return y(()=>n.storyJson(JSON.stringify({storyId:d})))},registerFont(d){return T(()=>pe(i,d))},layoutSlide(d){return y(()=>i.layoutSlideJson(n,d))},hitTest(d,p){return y(()=>i.hitTestJson(d,p))},mediaBytes(d){return T(()=>n.mediaBytes(d).slice())},insertText(d,p,g,v={}){return y(()=>n.insertTextJson(JSON.stringify({storyId:d,index:p,text:g,style:v})),true)},deleteText(d,p,g){return y(()=>n.deleteTextJson(JSON.stringify({storyId:d,start:p,end:g})),true)},formatText(d,p,g,v){return y(()=>n.formatTextJson(JSON.stringify({storyId:d,start:p,end:g,patch:v})),true)},insertParagraphBreak(d,p){return y(()=>n.insertParagraphBreakJson(JSON.stringify({storyId:d,index:p})),true)},insertSlide(d,p){return y(()=>n.insertSlideJson(JSON.stringify({index:d,layoutPartPath:p??null})),true)},deleteSlide(d){return y(()=>n.deleteSlideJson(JSON.stringify({slideId:d})),true)},moveSlide(d,p){return y(()=>n.moveSlideJson(JSON.stringify({slideId:d,toIndex:p})),true)},addTextBox(d,p){return y(()=>n.addTextBoxJson(JSON.stringify({slideId:d,draft:p})),true)},removeShape(d,p){return y(()=>n.removeShapeJson(JSON.stringify({slideId:d,shapeId:p})),true)},moveShape(d,p,g,v){return y(()=>n.moveShapeJson(JSON.stringify({slideId:d,shapeId:p,x:g,y:v})),true)},resizeShape(d,p,g,v){return y(()=>n.resizeShapeJson(JSON.stringify({slideId:d,shapeId:p,width:g,height:v})),true)},canUndo(){return T(()=>n.canUndo())},canRedo(){return T(()=>n.canRedo())},undo(){return y(()=>n.undoJson(),true)},redo(){return y(()=>n.redoJson(),true)},encodeStateVector(){return T(()=>n.encodeStateVector().slice())},encodeStateAsUpdate(d){return T(()=>d===void 0?n.encodeStateAsUpdate().slice():n.encodeDiff(d.slice()).slice())},encodeDiff(d){return T(()=>n.encodeDiff(d.slice()).slice())},applyUpdate(d){return y(()=>n.applyUpdateJson(d.slice()),true)},onUpdate(d){if(G(),typeof d!="function")throw new TypeError("update listener must be a function");let p=l++;o.set(p,d);try{he();}catch(v){throw o.delete(p),v}let g=true;return ()=>{g&&(g=false,o.delete(p),be());}},dispose(){if(c)return;c=true,o.clear(),a.length=0;let d;if(w){try{n.clearUpdateObservation();}catch(p){d=p;}w=false;}try{i.free();}catch(p){d??(d=p);}try{n.free();}catch(p){d??(d=p);}if(d!==void 0)throw L(d)}}}function pe(r,e){try{return r.registerFont(e.family,e.bold??!1,e.italic??!1,e.bytes)}catch(t){throw L(t)}}function X(){if(!j)throw new Error("pptx wasm is not initialized; call initWasm() first")}function Ge(){let r=globalThis.crypto;if(!r||typeof r.getRandomValues!="function")throw new Error("crypto.getRandomValues is required to generate a collaboration client ID");let e=new Uint32Array(2),t;do r.getRandomValues(e),t=(e[0]&2097151)*4294967296+e[1];while(t===0);return t}function ue(r){try{return r()}catch(e){throw L(e)}}function Qe(r){try{return JSON.parse(r())}catch(e){throw L(e)}}function Ke(r){return Qe(r)}function L(r){return r instanceof Error?r:new Error(typeof r=="string"?r:String(r))}export{x as CollaborationError,B as CollaborationProvider,$e as initWasm,je as inspectPresentation,qe as isWasmAvailable,Xe as openPresentation,we as paintSlide,me as sizeCanvasForSlide,He as wasmVersion};
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@betteroffice/pptx",
3
+ "version": "0.0.1",
4
+ "description": "PowerPoint-faithful PPTX editor and viewer core — full OOXML fidelity, real-time human + AI agent collaboration. Framework-free (Rust/Wasm).",
5
+ "keywords": [
6
+ "pptx",
7
+ "powerpoint",
8
+ "presentation",
9
+ "slides",
10
+ "ooxml",
11
+ "office",
12
+ "editor",
13
+ "viewer",
14
+ "collaborative",
15
+ "real-time",
16
+ "ai-agent",
17
+ "wasm"
18
+ ],
19
+ "type": "module",
20
+ "sideEffects": false,
21
+ "main": "./dist/index.js",
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "scripts": {
34
+ "build": "bun run build:wasm && tsup",
35
+ "build:wasm": "bun ../../scripts/build-pptx-wasm.ts",
36
+ "typecheck": "tsc --noEmit -p ."
37
+ },
38
+ "devDependencies": {
39
+ "@types/bun": "^1.3.14",
40
+ "@types/node": "^26.0.0",
41
+ "tsup": "^8.5.1",
42
+ "typescript": "^6.0.3"
43
+ },
44
+ "license": "Apache-2.0",
45
+ "homepage": "https://betteroffice.dev/",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/openooxml/betteroffice.git",
49
+ "directory": "packages/pptx"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ }
54
+ }