@betteroffice/pptx 0.0.1 → 0.0.3
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 +21 -4
- package/dist/generated/pptx_wasm_bg.wasm +0 -0
- package/dist/index.d.ts +111 -3
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,10 @@ Framework-free core for the BetterOffice PPTX editor — the Rust parser, yrs de
|
|
|
4
4
|
model, slide layout, and display-list engine compiled to WebAssembly, plus the
|
|
5
5
|
Canvas2D replay host.
|
|
6
6
|
|
|
7
|
-
> **
|
|
7
|
+
> **Early (`0.0.x`).** The core surfaces — opening/saving documents, the editor
|
|
8
|
+
> components, collaboration — are settling and unlikely to change shape. Smaller
|
|
9
|
+
> APIs may still move between releases; breaking changes are always listed in
|
|
10
|
+
> the changelog.
|
|
8
11
|
|
|
9
12
|
```bash
|
|
10
13
|
bun add @betteroffice/pptx
|
|
@@ -14,17 +17,24 @@ Most apps want the turnkey React component in
|
|
|
14
17
|
[`@betteroffice/pptx-react`](https://www.npmjs.com/package/@betteroffice/pptx-react).
|
|
15
18
|
Use this package directly to build custom presentation chrome.
|
|
16
19
|
|
|
17
|
-
##
|
|
20
|
+
## Open and render a slide
|
|
18
21
|
|
|
19
22
|
```ts
|
|
20
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
initWasm,
|
|
25
|
+
openPresentation,
|
|
26
|
+
paintSlide,
|
|
27
|
+
sizeCanvasForSlide,
|
|
28
|
+
} from '@betteroffice/pptx';
|
|
21
29
|
|
|
22
30
|
await initWasm();
|
|
23
31
|
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
24
32
|
const deck = openPresentation(bytes, {
|
|
25
33
|
fonts: [{ family: 'My Sans', bytes: fontBytes }],
|
|
26
34
|
});
|
|
35
|
+
|
|
27
36
|
const frame = deck.layoutSlide(0);
|
|
37
|
+
sizeCanvasForSlide(canvas, frame, devicePixelRatio);
|
|
28
38
|
await paintSlide(canvas.getContext('2d')!, frame, devicePixelRatio);
|
|
29
39
|
```
|
|
30
40
|
|
|
@@ -33,6 +43,11 @@ display-list emission stay in Rust. The package decodes the typed boundary and
|
|
|
33
43
|
replays the resulting primitives on canvas. Font bytes are supplied by the host
|
|
34
44
|
and registered with the Rust shaper through `openPresentation`.
|
|
35
45
|
|
|
46
|
+
Beyond rendering, `PresentationHandle` covers editing: text
|
|
47
|
+
(`insertText` / `deleteText` / `formatText`), slides
|
|
48
|
+
(`insertSlide` / `deleteSlide` / `moveSlide`), shapes
|
|
49
|
+
(`addTextBox` / `moveShape` / `resizeShape`), `hitTest`, and undo/redo.
|
|
50
|
+
|
|
36
51
|
## Collaboration
|
|
37
52
|
|
|
38
53
|
`PresentationHandle` is a collaboration replica. Pair it with
|
|
@@ -44,7 +59,9 @@ and bounds frames and pending backpressure bytes.
|
|
|
44
59
|
```ts
|
|
45
60
|
import { CollaborationProvider } from '@betteroffice/pptx';
|
|
46
61
|
|
|
47
|
-
const provider = new CollaborationProvider(deck, transport
|
|
62
|
+
const provider = new CollaborationProvider(deck, transport, {
|
|
63
|
+
user: { name: "Ada" }, // identity for this peer's presence chip
|
|
64
|
+
});
|
|
48
65
|
deck.onUpdate((_update, origin) => {
|
|
49
66
|
if (origin === 'remote') repaint();
|
|
50
67
|
});
|
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,24 @@ interface StorySnapshot {
|
|
|
32
32
|
paragraphs: ParagraphSnapshot[];
|
|
33
33
|
}
|
|
34
34
|
type ShapeKind = 'shape' | 'picture' | 'graphicFrame' | 'group';
|
|
35
|
+
interface ColorValue {
|
|
36
|
+
rgb?: string;
|
|
37
|
+
themeColor?: string;
|
|
38
|
+
themeTint?: string;
|
|
39
|
+
themeShade?: string;
|
|
40
|
+
auto?: boolean;
|
|
41
|
+
}
|
|
42
|
+
interface ShapeFill {
|
|
43
|
+
type: string;
|
|
44
|
+
color?: ColorValue;
|
|
45
|
+
}
|
|
46
|
+
interface ShapeOutline {
|
|
47
|
+
width?: number;
|
|
48
|
+
color?: ColorValue;
|
|
49
|
+
style?: string;
|
|
50
|
+
cap?: string;
|
|
51
|
+
join?: string;
|
|
52
|
+
}
|
|
35
53
|
interface ShapeSnapshot {
|
|
36
54
|
id: string;
|
|
37
55
|
sourceId: number;
|
|
@@ -45,9 +63,12 @@ interface ShapeSnapshot {
|
|
|
45
63
|
flipH: boolean;
|
|
46
64
|
flipV: boolean;
|
|
47
65
|
geometry: string;
|
|
66
|
+
adjustValues: Record<string, number>;
|
|
48
67
|
placeholder: unknown | null;
|
|
49
|
-
fill:
|
|
50
|
-
|
|
68
|
+
fill: ShapeFill | null;
|
|
69
|
+
resolvedFillColor: string | null;
|
|
70
|
+
outline: ShapeOutline | null;
|
|
71
|
+
resolvedOutlineColor: string | null;
|
|
51
72
|
mediaPartPath: string | null;
|
|
52
73
|
graphic: unknown | null;
|
|
53
74
|
textStories: StorySnapshot[];
|
|
@@ -99,6 +120,34 @@ interface ShapeDraft {
|
|
|
99
120
|
text: string;
|
|
100
121
|
style: TextStyle;
|
|
101
122
|
}
|
|
123
|
+
interface PresetShapeDraft {
|
|
124
|
+
name: string;
|
|
125
|
+
geometry: string;
|
|
126
|
+
rect: ShapeRect;
|
|
127
|
+
fill?: string | null;
|
|
128
|
+
}
|
|
129
|
+
interface ShapeStroke {
|
|
130
|
+
color?: string;
|
|
131
|
+
widthPt?: number;
|
|
132
|
+
}
|
|
133
|
+
interface ShapeFillReceipt {
|
|
134
|
+
slideId: string;
|
|
135
|
+
shapeId: string;
|
|
136
|
+
before: string | null;
|
|
137
|
+
after: string | null;
|
|
138
|
+
}
|
|
139
|
+
interface ShapeStrokeReceipt {
|
|
140
|
+
slideId: string;
|
|
141
|
+
shapeId: string;
|
|
142
|
+
before: ShapeStroke | null;
|
|
143
|
+
after: ShapeStroke | null;
|
|
144
|
+
}
|
|
145
|
+
interface ShapeAdjustReceipt {
|
|
146
|
+
slideId: string;
|
|
147
|
+
shapeId: string;
|
|
148
|
+
before: Record<string, number>;
|
|
149
|
+
after: Record<string, number>;
|
|
150
|
+
}
|
|
102
151
|
interface HistoryResult {
|
|
103
152
|
applied: boolean;
|
|
104
153
|
snapshot: DeckSnapshot;
|
|
@@ -325,9 +374,39 @@ interface CollaborationProviderOptions {
|
|
|
325
374
|
maxFrameBytes?: number;
|
|
326
375
|
maxMessagesPerFrame?: number;
|
|
327
376
|
maxPendingBytes?: number;
|
|
377
|
+
user?: CollaborationUser;
|
|
328
378
|
}
|
|
329
379
|
type CollaborationStatusListener = (change: CollaborationStatusChange) => void;
|
|
330
380
|
type CollaborationErrorListener = (error: CollaborationError) => void;
|
|
381
|
+
interface CollaborationUser {
|
|
382
|
+
name: string;
|
|
383
|
+
color?: string;
|
|
384
|
+
}
|
|
385
|
+
interface PptxPresenceUser {
|
|
386
|
+
name: string;
|
|
387
|
+
color: string;
|
|
388
|
+
}
|
|
389
|
+
interface PptxPresenceCursor {
|
|
390
|
+
slideId: string;
|
|
391
|
+
shapeId?: string;
|
|
392
|
+
}
|
|
393
|
+
interface PptxPresenceState {
|
|
394
|
+
clientId: number;
|
|
395
|
+
clock: number;
|
|
396
|
+
user: PptxPresenceUser;
|
|
397
|
+
cursor: PptxPresenceCursor | null;
|
|
398
|
+
}
|
|
399
|
+
interface PptxPresencePeer {
|
|
400
|
+
state: PptxPresenceState;
|
|
401
|
+
lastSeen: number;
|
|
402
|
+
cursorMovedAt: number;
|
|
403
|
+
}
|
|
404
|
+
type PptxPresenceListener = (peers: readonly PptxPresencePeer[]) => void;
|
|
405
|
+
interface PptxPresence {
|
|
406
|
+
readonly peers: readonly PptxPresencePeer[];
|
|
407
|
+
setCursor(cursor: PptxPresenceCursor | null): void;
|
|
408
|
+
onPresence(listener: PptxPresenceListener): () => void;
|
|
409
|
+
}
|
|
331
410
|
|
|
332
411
|
declare class CollaborationProvider {
|
|
333
412
|
private readonly replica;
|
|
@@ -335,8 +414,12 @@ declare class CollaborationProvider {
|
|
|
335
414
|
private readonly maxFrameBytes;
|
|
336
415
|
private readonly maxMessagesPerFrame;
|
|
337
416
|
private readonly maxPendingBytes;
|
|
417
|
+
private readonly localClientId;
|
|
418
|
+
private readonly localUser;
|
|
419
|
+
private readonly remotePresence;
|
|
338
420
|
private readonly statusListeners;
|
|
339
421
|
private readonly errorListeners;
|
|
422
|
+
private readonly presenceListeners;
|
|
340
423
|
private readonly pendingFrames;
|
|
341
424
|
private unsubscribeReplica;
|
|
342
425
|
private unsubscribeTransport;
|
|
@@ -351,15 +434,25 @@ declare class CollaborationProvider {
|
|
|
351
434
|
private nextListenerId;
|
|
352
435
|
private queuedBytes;
|
|
353
436
|
private isFlushing;
|
|
437
|
+
private localClock;
|
|
438
|
+
private reportedClockExhaustion;
|
|
439
|
+
private localCursor;
|
|
440
|
+
private lastAwarenessSentAt;
|
|
441
|
+
private cursorTimer;
|
|
442
|
+
private heartbeatTimer;
|
|
443
|
+
private expiryTimer;
|
|
354
444
|
constructor(replica: CollaborationReplica, transport: CollaborationTransport, options?: CollaborationProviderOptions);
|
|
355
445
|
get status(): CollaborationStatus;
|
|
356
446
|
get synced(): boolean;
|
|
357
447
|
get pendingBytes(): number;
|
|
448
|
+
get peers(): readonly PptxPresencePeer[];
|
|
449
|
+
setCursor(cursor: PptxPresenceCursor | null): void;
|
|
358
450
|
connect(): void;
|
|
359
451
|
disconnect(): void;
|
|
360
452
|
destroy(): void;
|
|
361
453
|
onStatus(listener: CollaborationStatusListener): () => void;
|
|
362
454
|
onError(listener: CollaborationErrorListener): () => void;
|
|
455
|
+
onPresence(listener: PptxPresenceListener): () => void;
|
|
363
456
|
private isCurrent;
|
|
364
457
|
private failConnection;
|
|
365
458
|
private takeTransportSubscription;
|
|
@@ -370,6 +463,14 @@ declare class CollaborationProvider {
|
|
|
370
463
|
private respondToSyncStep1;
|
|
371
464
|
private applyRemoteUpdate;
|
|
372
465
|
private forwardLocalUpdate;
|
|
466
|
+
private scheduleCursorBroadcast;
|
|
467
|
+
private broadcastLocalPresence;
|
|
468
|
+
private sendLeaveFrameBestEffort;
|
|
469
|
+
private startPresenceTimers;
|
|
470
|
+
private stopPresenceTimers;
|
|
471
|
+
private schedulePresenceExpiry;
|
|
472
|
+
private clearRemotePresence;
|
|
473
|
+
private emitPresence;
|
|
373
474
|
private sendFrame;
|
|
374
475
|
private queueFrame;
|
|
375
476
|
private flushPending;
|
|
@@ -378,6 +479,9 @@ declare class CollaborationProvider {
|
|
|
378
479
|
private report;
|
|
379
480
|
}
|
|
380
481
|
|
|
482
|
+
declare const PRESENCE_LABEL_DURATION_MS = 3000;
|
|
483
|
+
declare function presenceColorForClientId(clientId: number): string;
|
|
484
|
+
|
|
381
485
|
type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
382
486
|
|
|
383
487
|
type WasmInitInput = InitInput | Promise<InitInput>;
|
|
@@ -402,6 +506,10 @@ interface PresentationHandle extends CollaborationReplica {
|
|
|
402
506
|
deleteSlide(slideId: string): SlideReceipt;
|
|
403
507
|
moveSlide(slideId: string, toIndex: number): SlideReceipt;
|
|
404
508
|
addTextBox(slideId: string, draft: ShapeDraft): ShapeReceipt;
|
|
509
|
+
addShape(slideId: string, draft: PresetShapeDraft): ShapeReceipt;
|
|
510
|
+
setShapeFill(slideId: string, shapeId: string, color: string | null): ShapeFillReceipt;
|
|
511
|
+
setShapeStroke(slideId: string, shapeId: string, stroke: ShapeStroke): ShapeStrokeReceipt;
|
|
512
|
+
setShapeAdjust(slideId: string, shapeId: string, adjustments: Record<string, number>): ShapeAdjustReceipt;
|
|
405
513
|
removeShape(slideId: string, shapeId: string): ShapeReceipt;
|
|
406
514
|
moveShape(slideId: string, shapeId: string, x: number, y: number): TransformReceipt;
|
|
407
515
|
resizeShape(slideId: string, shapeId: string, width: number, height: number): TransformReceipt;
|
|
@@ -422,4 +530,4 @@ declare function wasmVersion(): string;
|
|
|
422
530
|
declare function inspectPresentation(bytes: Uint8Array): unknown;
|
|
423
531
|
declare function openPresentation(bytes: Uint8Array, options?: OpenPresentationOptions): PresentationHandle;
|
|
424
532
|
|
|
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 };
|
|
533
|
+
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 CollaborationUser, type ColorValue, type DeckSnapshot, type GeometryPathCommand, type HistoryResult, type HitTestResult, type ImagePrimitive, type OpenPresentationOptions, PRESENCE_LABEL_DURATION_MS, type Paint, type PaintSlideOptions, type ParagraphSnapshot, type PlaceholderPrimitive, type PositionedGlyph, type PositionedTextLine, type PositionedTextRun, type PptxFontFace, type PptxPresence, type PptxPresenceCursor, type PptxPresenceListener, type PptxPresencePeer, type PptxPresenceState, type PptxPresenceUser, type PresentationHandle, type PresetShapeDraft, type PrimitiveTransform, type ShapeAdjustReceipt, type ShapeDraft, type ShapeFill, type ShapeFillReceipt, type ShapeKind, type ShapeOutline, type ShapePrimitive, type ShapeReceipt, type ShapeRect, type ShapeSnapshot, type ShapeStroke, type ShapeStrokeReceipt, 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, presenceColorForClientId, sizeCanvasForSlide, wasmVersion };
|
package/dist/index.js
CHANGED
|
@@ -1 +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};
|
|
1
|
+
var ze=Object.defineProperty;var We=(r,e,t)=>e in r?ze(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t;var u=(r,e,t)=>We(r,typeof e!="symbol"?e+"":e,t);function je(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 $e(r,e,t=1,n=1,s={}){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=le(r,e.background,0,0,e.width,e.height),r.fillRect(0,0,e.width,e.height));for(let i of e.primitives)await qe(r,i,s);}finally{r.restore();}}async function qe(r,e,t){r.save();try{switch(Xe(r,e),e.kind){case "shape":Ge(r,e);break;case "image":await Ye(r,e,t.resolveImage);break;case "textBox":Ke(r,e);break;case "placeholder":et(r,e);break}}finally{r.restore();}}function Xe(r,e){let t=e.transform;if(!t)return;let n=e.x+e.w/2,s=e.y+e.h/2;r.translate(n,s),r.rotate((t.rotationDeg??0)*Math.PI/180),r.scale(t.flipH?-1:1,t.flipV?-1:1),r.translate(-n,-s);}function Ge(r,e){He(r,e.path,e.x,e.y,e.w,e.h),e.fill&&(r.fillStyle=le(r,e.fill,e.x,e.y,e.w,e.h),r.fill()),e.stroke&&ce(r,e.stroke);}function He(r,e,t,n,s,i){r.beginPath();for(let c of e)switch(c.type){case "move":r.moveTo(t+c.x*s,n+c.y*i);break;case "line":r.lineTo(t+c.x*s,n+c.y*i);break;case "quad":r.quadraticCurveTo(t+c.cpx*s,n+c.cpy*i,t+c.x*s,n+c.y*i);break;case "cubic":r.bezierCurveTo(t+c.cp1x*s,n+c.cp1y*i,t+c.cp2x*s,n+c.cp2y*i,t+c.x*s,n+c.y*i);break;case "close":r.closePath();break}}function ce(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 le(r,e,t,n,s,i){if(e.kind==="solid")return e.color;let c=(e.angleDeg??0)*Math.PI/180,l=t+s/2,a=n+i/2,w=Math.hypot(s,i)/2,v=e.gradientType==="linear"?r.createLinearGradient(l-Math.cos(c)*w,a-Math.sin(c)*w,l+Math.cos(c)*w,a+Math.sin(c)*w):r.createRadialGradient(l,a,0,l,a,w);for(let I of e.stops)v.addColorStop(Math.max(0,Math.min(1,I.position)),I.color);return v}async function Ye(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),ce(r,e.stroke));}function Ke(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)Qe(r,n,t.baseline);}function Qe(r,e,t){let n=e.italic?"italic ":"",s=e.bold?"bold ":"";r.font=`${n}${s}${e.fontSizePx}px ${Ze(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 Ze(r){return r.includes(" ")?JSON.stringify(r):r}function et(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 pe=3e3;var de=["#B3261E","#7B1FA2","#3949AB","#00796B","#2E7D32","#A84400","#C2185B","#00695C"],tt=/^#[0-9a-fA-F]+$/;function G(r){return de[Math.abs(r)%de.length]}function H(r,e){return typeof e=="string"&&(e.length===4||e.length===7)&&tt.test(e)?e:G(r)}function ue(r,e){if(e&&(typeof e.name!="string"||e.name.trim().length===0))throw new TypeError("Collaboration user name must be a non-empty string");if(e?.color!==void 0&&typeof e.color!="string")throw new TypeError("Collaboration user color must be a string");let t=e?.name.trim().slice(0,1024)||`Guest ${r.toString(36).toUpperCase()}`,n=H(r,e?.color);return {name:t,color:n}}function Y(r,e){return r?.slideId===e?.slideId&&r?.shapeId===e?.shapeId}var W=class{constructor(e,t={}){u(this,"localClientId",e);u(this,"states",new Map);u(this,"clocks",new Map);u(this,"maxTrackedIds");if(this.maxTrackedIds=t.maxTrackedIds??4096,!Number.isSafeInteger(this.maxTrackedIds)||this.maxTrackedIds<1)throw new RangeError("Presence tracked id limit must be a positive integer")}get peers(){return [...this.states.values()].sort((e,t)=>e.state.clientId-t.state.clientId).map(rt)}get trackedIdCount(){return this.clocks.size}get nextExpiryAt(){let e;for(let t of this.states.values()){let n=t.lastSeen+45e3;e=e===void 0?n:Math.min(e,n);}for(let t of this.clocks.values()){let n=t.updatedAt+3e5;e=e===void 0?n:Math.min(e,n);}return e}apply(e,t){let n=this.expire(t);for(let s of e){if(s.clientId===this.localClientId)continue;let i=this.clocks.get(s.clientId);if(i&&s.clock<=i.clock)continue;if(!i&&this.clocks.size>=this.maxTrackedIds&&(n=this.evictOldest()||n),this.clocks.delete(s.clientId),this.clocks.set(s.clientId,{clock:s.clock,updatedAt:t}),!s.state){n=this.states.delete(s.clientId)||n;continue}let c=this.states.get(s.clientId),l=c&&Y(c.state.cursor,s.state.cursor)?c.cursorMovedAt:t;this.states.set(s.clientId,{state:fe(s.state),lastSeen:t,cursorMovedAt:l}),n=true;}return n}expire(e,t=45e3){let n=false;for(let[s,i]of this.states)e-i.lastSeen<t||(this.states.delete(s),n=true);for(let[s,i]of this.clocks)e-i.updatedAt<3e5||(this.clocks.delete(s),n=this.states.delete(s)||n);return n}clear(){let e=this.states.size>0;return this.states.clear(),this.clocks.clear(),e}evictOldest(){let e=this.clocks.keys().next();return e.done?false:(this.clocks.delete(e.value),this.states.delete(e.value))}};function fe(r){return {clientId:r.clientId,clock:r.clock,user:{...r.user},cursor:r.cursor?{...r.cursor}:null}}function rt(r){return {state:fe(r.state),lastSeen:r.lastSeen,cursorMovedAt:r.cursorMovedAt}}var A=16777216,O=4096,_e=0,ye=1,st=2,be=3,me=0,ge=1,we=2,it=0,ot=Number.MAX_SAFE_INTEGER,f=class extends Error{constructor(e){super(e),this.name="ProtocolError";}},j=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 f("Truncated varUint");let s=this.bytes[this.offset++],i=s&127;if(i>Math.floor((ot-e)/t))throw new f("varUint exceeds Number.MAX_SAFE_INTEGER");if(e+=i*t,n+=1,(s&128)===0){if(n>1&&i===0)throw new f("Non-canonical varUint");return e}if(n>=8)throw new f("varUint exceeds Number.MAX_SAFE_INTEGER");t*=128;}}readVarUint8Array(){let e=this.readVarUint(),t=this.bytes.byteLength-this.offset;if(e>t)throw new f("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 f(`Invalid UTF-8 string${t instanceof Error?`: ${t.message}`:""}`)}}};function T(r){if(!Number.isSafeInteger(r)||r<0)throw new f("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 at(r){let e=new TextEncoder().encode(r);return D([T(e.byteLength),e],A)}function D(r,e){let t=0;for(let i of r)if(t+=i.byteLength,t>e)throw new f(`Frame exceeds ${e} bytes`);let n=new Uint8Array(t),s=0;for(let i of r)n.set(i,s),s+=i.byteLength;return n}function Z(r,e,t){return D([T(_e),T(r),T(e.byteLength),e],t)}function Se(r,e=A){return Z(me,r,e)}function xe(r,e=A){return Z(ge,r,e)}function Pe(r,e=A){return Z(we,r,e)}function ve(r,e=A){if(r.length>O)throw new f(`Awareness update exceeds ${O} entries`);let t=[T(r.length)];for(let s of r){Ue(s);let i=JSON.stringify(s.state);if(i===void 0)throw new f("Awareness state is not JSON serializable");t.push(T(s.clientId),T(s.clock),at(i));}let n=D(t,e);return D([T(ye),T(n.byteLength),n],e)}function Ce(r=A){return D([T(be)],r)}function Te(r,e=O){if(!(r instanceof Uint8Array))throw new f("Awareness update must be a Uint8Array");if(!Number.isSafeInteger(e)||e<1)throw new f("Awareness entry limit must be a positive integer");let t=new j(r),n=t.readVarUint();if(n>e)throw new f(`Awareness update exceeds ${e} entries`);let s=[];for(let i=0;i<n;i+=1){let c=t.readVarUint(),l=t.readVarUint(),a;try{a=JSON.parse(t.readVarString());}catch(v){throw v instanceof f?v:new f(`Invalid awareness JSON${v instanceof Error?`: ${v.message}`:""}`)}let w={clientId:c,clock:l,state:Ee(a,c,l)};Ue(w),s.push(w);}if(!t.done)throw new f("Awareness update has trailing bytes");return s}function Ae(r,e=A,t=O){if(!(r instanceof Uint8Array))throw new f("Frame must be a Uint8Array");if(r.byteLength===0)throw new f("Frame is empty");if(r.byteLength>e)throw new f(`Frame exceeds ${e} bytes`);if(!Number.isSafeInteger(t)||t<1)throw new f("Message limit must be a positive integer");let n=new j(r),s=[];for(;!n.done;){if(s.length>=t)throw new f(`Frame exceeds ${t} messages`);let i=n.readVarUint();switch(i){case _e:{let c=n.readVarUint(),l=n.readVarUint8Array();if(c===me)s.push({type:"sync-step-1",stateVector:l});else if(c===ge)s.push({type:"sync-step-2",update:l});else if(c===we)s.push({type:"update",update:l});else throw new f(`Unknown sync message type ${c}`);break}case ye:s.push({type:"awareness",update:n.readVarUint8Array()});break;case st:{let c=n.readVarUint();if(c!==it)throw new f(`Unknown auth message type ${c}`);s.push({type:"auth",reason:n.readVarString()});break}case be:s.push({type:"query-awareness"});break;default:throw new f(`Unknown top-level message type ${i}`)}}return s}function Ee(r,e,t){if(r===null)return null;if(!Q(r))throw new f("Awareness state must be an object or null");if(r.clientId!==e||r.clock!==t)throw new f("Awareness state identity does not match its entry");if(!Q(r.user))throw new f("Awareness user must be an object");let n=K(r.user.name,"Awareness user name"),s=H(e,r.user.color);return {clientId:e,clock:t,user:{name:n,color:s},cursor:ct(r.cursor)}}function ct(r){if(r==null)return null;if(!Q(r))throw new f("Awareness cursor must be an object or null");let e=K(r.slideId,"Awareness slideId"),t=r.shapeId===void 0?void 0:K(r.shapeId,"Awareness shapeId");return t?{slideId:e,shapeId:t}:{slideId:e}}function Ue(r){he(r.clientId,"Awareness clientId"),he(r.clock,"Awareness clock"),r.state!==null&&Ee(r.state,r.clientId,r.clock);}function he(r,e){if(!Number.isSafeInteger(r)||r<0)throw new f(`${e} must be a non-negative safe integer`)}function K(r,e){if(typeof r!="string"||r.length===0||r.length>1024)throw new f(`${e} must be between 1 and ${1024} characters`);return r}function Q(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}var x=class extends Error{constructor(t,n,s){super(n);u(this,"code");u(this,"cause");this.name="CollaborationError",this.code=t,this.cause=s;}};var pt=16*1024*1024;function ee(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 ut(r){return r instanceof Error&&r.message?r.message:typeof r=="string"&&r?r:"Unknown error"}function m(r,e,t){return t instanceof x?t:new x(r,`${e}: ${ut(t)}`,t)}function te(r,e){if(!(r instanceof Uint8Array))throw new TypeError(`${e} must return a Uint8Array`);return r.slice()}function re(r){typeof r=="object"&&r&&"unref"in r&&r.unref();}function ft(r){if(!Number.isSafeInteger(r)||r<0)throw new RangeError("Replica clientId must be a non-negative safe integer");return r}function ht(r){if(r===null)return null;if(!r||typeof r.slideId!="string"||r.slideId.length===0)throw new TypeError("Presence cursor slideId must be a non-empty string");if(r.shapeId!==void 0&&(typeof r.shapeId!="string"||r.shapeId.length===0))throw new TypeError("Presence cursor shapeId must be a non-empty string");return r.shapeId?{slideId:r.slideId,shapeId:r.shapeId}:{slideId:r.slideId}}function _t(r){return r.slideId.length<=1024&&(r.shapeId===void 0||r.shapeId.length<=1024)}var $=class{constructor(e,t,n={}){u(this,"replica");u(this,"transport");u(this,"maxFrameBytes");u(this,"maxMessagesPerFrame");u(this,"maxPendingBytes");u(this,"localClientId");u(this,"localUser");u(this,"remotePresence");u(this,"statusListeners",new Map);u(this,"errorListeners",new Map);u(this,"presenceListeners",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);u(this,"localClock",0);u(this,"reportedClockExhaustion",false);u(this,"localCursor",null);u(this,"lastAwarenessSentAt",0);u(this,"cursorTimer",null);u(this,"heartbeatTimer",null);u(this,"expiryTimer",null);this.replica=e,this.transport=t,this.localClientId=ft(e.clientId),this.localUser=ue(this.localClientId,n.user),this.remotePresence=new W(this.localClientId),this.maxFrameBytes=ee("maxFrameBytes",n.maxFrameBytes??A,false),this.maxMessagesPerFrame=ee("maxMessagesPerFrame",n.maxMessagesPerFrame??O,false),this.maxPendingBytes=ee("maxPendingBytes",n.maxPendingBytes??pt,true);try{this.unsubscribeReplica=e.onUpdate((s,i)=>{i==="local"&&this.forwardLocalUpdate(s);});}catch(s){throw m("replica","Failed to observe replica updates",s)}}get status(){return this.connectionStatus}get synced(){return this.isSynced}get pendingBytes(){return this.queuedBytes}get peers(){return this.remotePresence.peers}setCursor(e){if(this.isDestroyed)return;let t=ht(e),n=!t||_t(t)?t:null;t&&!n&&this.report(new x("protocol",`Presence cursor identifiers exceed ${1024} characters; cursor dropped`)),!Y(this.localCursor,n)&&(this.localCursor=n,this.isOpen&&this.wantsConnection&&this.scheduleCursorBroadcast());}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(s=>this.handleTransportEvent(e,s)),typeof n!="function")throw new TypeError("Transport event subscription must return a function")}catch(s){this.failConnection(e,m("transport","Failed to subscribe to transport events",s));return}if(!this.isCurrent(e)){try{n();}catch(s){this.isDestroyed||this.report(m("transport","Failed to unsubscribe from stale transport events",s));}return}this.unsubscribeTransport=n,this.hasTransportSubscription=true;}try{let n=this.transport.connect();n&&n.catch(s=>{this.isCurrent(e)&&this.connectAttempt===t&&this.failConnection(e,m("transport","Transport connect failed",s));});}catch(n){this.failConnection(e,m("transport","Transport connect failed",n));}}}disconnect(){if(this.isDestroyed||!(this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus!=="disconnected"))return;if(this.isOpen&&this.wantsConnection){let s=this.epoch;if(this.broadcastLocalPresence(true),!this.isCurrent(s))return}this.stopPresenceTimers(),this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let t=this.takeTransportSubscription();this.clearPending(),this.clearRemotePresence();let n=this.cleanupTransport(t,true);this.setStatus("disconnected",false);for(let s of n)this.report(s);}destroy(){if(this.isDestroyed||(this.isOpen&&this.wantsConnection&&this.broadcastLocalPresence(true),this.isDestroyed))return;let e=this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus==="connecting"||this.connectionStatus==="connected";this.stopPresenceTimers(),this.isDestroyed=true,this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let t=this.takeTransportSubscription();this.clearPending(),this.clearRemotePresence();let n=this.cleanupTransport(t,e);this.setStatus("destroyed",false);for(let s of n)this.report(s);try{this.unsubscribeReplica();}catch(s){this.report(m("replica","Failed to unsubscribe from replica updates",s));}this.unsubscribeReplica=()=>{},this.statusListeners.clear(),this.errorListeners.clear(),this.presenceListeners.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)}onPresence(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("presence listener must be a function");let t=this.nextListenerId++;this.presenceListeners.set(t,e);try{e(this.peers);}catch{}return ()=>this.presenceListeners.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,this.stopPresenceTimers();let n=this.takeTransportSubscription();this.clearPending(),this.clearRemotePresence();let s=this.cleanupTransport(n,true);this.setStatus("disconnected",false),this.report(t);for(let i of s)this.report(i);}takeTransportSubscription(){let e=this.unsubscribeTransport;return this.unsubscribeTransport=()=>{},this.hasTransportSubscription=false,e}cleanupTransport(e,t){let n=[];try{e();}catch(s){n.push(m("transport","Failed to unsubscribe from transport events",s));}if(!t)return n;try{let s=this.transport.disconnect();s&&s.catch(i=>{this.isDestroyed||this.report(m("transport","Transport disconnect failed",i));});}catch(s){n.push(m("transport","Transport disconnect failed",s));}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.stopPresenceTimers(),this.clearPending(),this.clearRemotePresence(),this.setStatus("disconnected",false);break;case "error":this.failConnection(e,m("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=te(this.replica.encodeStateVector(),"encodeStateVector");}catch(n){this.failConnection(e,m("replica","Failed to encode replica state vector",n));return}try{this.sendFrame(Se(t,this.maxFrameBytes));}catch(n){this.failConnection(e,m("protocol","Failed to encode SyncStep1",n));return}if(!(!this.isCurrent(e)||!this.isOpen)&&(this.startPresenceTimers(),this.broadcastLocalPresence(false),!(!this.isCurrent(e)||!this.isOpen)))try{this.sendFrame(Ce(this.maxFrameBytes));}catch(n){this.report(m("protocol","Failed to encode awareness query",n));}}handleMessage(e,t){let n;try{n=Ae(t.slice(),this.maxFrameBytes,this.maxMessagesPerFrame);}catch(s){this.failConnection(e,m("protocol","Invalid collaboration frame",s));return}for(let s of n){if(!this.isCurrent(e)||!this.isOpen)return;switch(s.type){case "sync-step-1":this.respondToSyncStep1(e,s.stateVector);break;case "sync-step-2":this.applyRemoteUpdate(e,s.update)&&this.isCurrent(e)&&this.setStatus("connected",true);break;case "update":this.applyRemoteUpdate(e,s.update);break;case "awareness":{try{let i=Te(s.update,this.maxMessagesPerFrame);this.remotePresence.apply(i,Date.now())&&this.emitPresence(),this.schedulePresenceExpiry();}catch(i){this.report(m("protocol","Invalid awareness update",i));}break}case "auth":this.failConnection(e,new x("protocol",s.reason?`Authentication denied: ${s.reason}`:"Authentication denied"));return;case "query-awareness":this.broadcastLocalPresence(false);break}}}respondToSyncStep1(e,t){let n;try{n=te(this.replica.encodeStateAsUpdate(t.slice()),"encodeStateAsUpdate");}catch(s){this.failConnection(e,m("replica","Failed to encode replica update",s));return}try{this.sendFrame(xe(n,this.maxFrameBytes));}catch(s){this.failConnection(e,m("protocol","Failed to encode SyncStep2",s));}}applyRemoteUpdate(e,t){try{return this.replica.applyUpdate(t.slice()),!0}catch(n){return this.failConnection(e,m("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=te(e,"Replica update");}catch(s){this.failConnection(t,m("replica","Invalid replica update",s));return}try{this.sendFrame(Pe(n,this.maxFrameBytes));}catch(s){this.failConnection(t,m("protocol","Failed to encode update",s));}}scheduleCursorBroadcast(){if(this.cursorTimer)return;let e=Math.max(0,80-(Date.now()-this.lastAwarenessSentAt));if(e===0){this.broadcastLocalPresence(false);return}this.cursorTimer=setTimeout(()=>{this.cursorTimer=null,this.broadcastLocalPresence(false);},e),re(this.cursorTimer);}broadcastLocalPresence(e){if(!this.isOpen||this.isDestroyed||!this.wantsConnection)return;if(this.localClock>=Number.MAX_SAFE_INTEGER){this.reportedClockExhaustion||(this.reportedClockExhaustion=true,this.report(new x("protocol","Awareness clock exceeds Number.MAX_SAFE_INTEGER")));return}this.localClock+=1;let t=this.localClock,n=e?null:{clientId:this.localClientId,clock:t,user:{...this.localUser},cursor:this.localCursor?{...this.localCursor}:null};this.cursorTimer&&clearTimeout(this.cursorTimer),this.cursorTimer=null,this.lastAwarenessSentAt=Date.now();try{let s=ve([{clientId:this.localClientId,clock:t,state:n}],this.maxFrameBytes);e?this.sendLeaveFrameBestEffort(s):this.sendFrame(s);}catch(s){this.report(m("protocol","Failed to encode awareness update",s));}}sendLeaveFrameBestEffort(e){try{this.transport.send(e.slice());}catch{}}startPresenceTimers(){this.stopPresenceTimers(),this.heartbeatTimer=setInterval(()=>{this.broadcastLocalPresence(false);},2e4),re(this.heartbeatTimer),this.schedulePresenceExpiry();}stopPresenceTimers(){this.cursorTimer&&clearTimeout(this.cursorTimer),this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.expiryTimer&&clearTimeout(this.expiryTimer),this.cursorTimer=null,this.heartbeatTimer=null,this.expiryTimer=null;}schedulePresenceExpiry(){if(this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null,!this.isOpen||this.isDestroyed)return;let e=this.remotePresence.nextExpiryAt;e!==void 0&&(this.expiryTimer=setTimeout(()=>{this.expiryTimer=null,this.remotePresence.expire(Date.now())&&this.emitPresence(),this.schedulePresenceExpiry();},Math.max(0,e-Date.now())),re(this.expiryTimer));}clearRemotePresence(){this.remotePresence.clear()&&this.emitPresence();}emitPresence(){let e=this.peers;for(let[t,n]of [...this.presenceListeners])if(this.presenceListeners.get(t)===n)try{n(e);}catch{}}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(s){this.failConnection(t,m("transport","Transport send failed",s));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(s){this.failConnection(e,m("transport","Transport send failed",s));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[s,i]of [...this.statusListeners])if(this.statusListeners.get(s)===i)try{i(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,Re.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,Re.unregister(this),e}free(){let e=this.__destroy_into_raw();o.__wbg_pptxdocument_free(e,0);}addShapeJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_addShapeJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}addTextBoxJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_addTextBoxJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}applyUpdateJson(e){let t,n;try{let c=F(e,o.__wbindgen_malloc),l=_,a=o.pptxdocument_applyUpdateJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}canRedo(){return o.pptxdocument_canRedo(this.__wbg_ptr)!==0}canUndo(){return o.pptxdocument_canUndo(this.__wbg_ptr)!==0}clearUpdateObservation(){o.pptxdocument_clearUpdateObservation(this.__wbg_ptr);}get clientId(){return o.pptxdocument_clientId(this.__wbg_ptr)}deleteSlideJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_deleteSlideJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}deleteTextJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_deleteTextJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}drainUpdateEvent(){let e=o.pptxdocument_drainUpdateEvent(this.__wbg_ptr);var t=E(e[0],e[1]).slice();return o.__wbindgen_free(e[0],e[1]*1,1),t}encodeDiff(e){let t=F(e,o.__wbindgen_malloc),n=_,s=o.pptxdocument_encodeDiff(this.__wbg_ptr,t,n);if(s[3])throw h(s[2]);var i=E(s[0],s[1]).slice();return o.__wbindgen_free(s[0],s[1]*1,1),i}encodeStateAsUpdate(){let e=o.pptxdocument_encodeStateAsUpdate(this.__wbg_ptr);var t=E(e[0],e[1]).slice();return o.__wbindgen_free(e[0],e[1]*1,1),t}encodeStateVector(){let e=o.pptxdocument_encodeStateVector(this.__wbg_ptr);var t=E(e[0],e[1]).slice();return o.__wbindgen_free(e[0],e[1]*1,1),t}formatTextJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_formatTextJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}insertParagraphBreakJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_insertParagraphBreakJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}insertSlideJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_insertSlideJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}insertTextJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_insertTextJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}mediaBytes(e){let t=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),n=_,s=o.pptxdocument_mediaBytes(this.__wbg_ptr,t,n);if(s[3])throw h(s[2]);var i=E(s[0],s[1]).slice();return o.__wbindgen_free(s[0],s[1]*1,1),i}moveShapeJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_moveShapeJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}moveSlideJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_moveSlideJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}static openCollaborative(e,t){let n=F(e,o.__wbindgen_malloc),s=_,i=o.pptxdocument_openCollaborative(n,s,t);if(i[2])throw h(i[1]);return r.__wrap(i[0])}static openCollaborativeFromUpdate(e,t){let n=F(e,o.__wbindgen_malloc),s=_,i=o.pptxdocument_openCollaborativeFromUpdate(n,s,t);if(i[2])throw h(i[1]);return r.__wrap(i[0])}redoJson(){let e,t;try{let i=o.pptxdocument_redoJson(this.__wbg_ptr);var n=i[0],s=i[1];if(i[3])throw n=0,s=0,h(i[2]);return e=n,t=s,y(n,s)}finally{o.__wbindgen_free(e,t,1);}}removeShapeJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_removeShapeJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}resizeShapeJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_resizeShapeJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}setShapeAdjustJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_setShapeAdjustJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}setShapeFillJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_setShapeFillJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}setShapeStrokeJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_setShapeStrokeJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}snapshotJson(){let e,t;try{let i=o.pptxdocument_snapshotJson(this.__wbg_ptr);var n=i[0],s=i[1];if(i[3])throw n=0,s=0,h(i[2]);return e=n,t=s,y(n,s)}finally{o.__wbindgen_free(e,t,1);}}startUpdateObservation(){let e=o.pptxdocument_startUpdateObservation(this.__wbg_ptr);if(e[1])throw h(e[0])}storyJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_storyJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}undoJson(){let e,t;try{let i=o.pptxdocument_undoJson(this.__wbg_ptr);var n=i[0],s=i[1];if(i[3])throw n=0,s=0,h(i[2]);return e=n,t=s,y(n,s)}finally{o.__wbindgen_free(e,t,1);}}static version(){let e,t;try{let n=o.pptxdocument_version();return e=n[0],t=n[1],y(n[0],n[1])}finally{o.__wbindgen_free(e,t,1);}}};Symbol.dispose&&(U.prototype[Symbol.dispose]=U.prototype.free);var M=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,Ie.unregister(this),e}free(){let e=this.__destroy_into_raw();o.__wbg_pptxrenderer_free(e,0);}hitTestJson(e,t){let n,s;try{let l=o.pptxrenderer_hitTestJson(this.__wbg_ptr,e,t);var i=l[0],c=l[1];if(l[3])throw i=0,c=0,h(l[2]);return n=i,s=c,y(i,c)}finally{o.__wbindgen_free(n,s,1);}}layoutSlideJson(e,t){let n,s;try{mt(e,U);let l=o.pptxrenderer_layoutSlideJson(this.__wbg_ptr,e.__wbg_ptr,t);var i=l[0],c=l[1];if(l[3])throw i=0,c=0,h(l[2]);return n=i,s=c,y(i,c)}finally{o.__wbindgen_free(n,s,1);}}constructor(){let e=o.pptxrenderer_new();return this.__wbg_ptr=e,Ie.register(this,this.__wbg_ptr,this),this}registerFont(e,t,n,s){let i=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),c=_,l=F(s,o.__wbindgen_malloc),a=_,w=o.pptxrenderer_registerFont(this.__wbg_ptr,i,c,t,n,l,a);if(w[2])throw h(w[1]);return w[0]>>>0}};Symbol.dispose&&(M.prototype[Symbol.dispose]=M.prototype.free);function Oe(r){let e,t;try{let i=F(r,o.__wbindgen_malloc),c=_,l=o.parsePptxJson(i,c);var n=l[0],s=l[1];if(l[3])throw n=0,s=0,h(l[2]);return e=n,t=s,y(n,s)}finally{o.__wbindgen_free(e,t,1);}}function Fe(){let r,e;try{let t=o.rendererVersion();return r=t[0],e=t[1],y(t[0],t[1])}finally{o.__wbindgen_free(r,e,1);}}function yt(){return {__proto__:null,"./pptx_wasm_bg.js":{__proto__:null,__wbg___wbindgen_string_get_b0ca35b86a603356:function(e,t){let n=t,s=typeof n=="string"?n:void 0;var i=gt(s)?0:S(s,o.__wbindgen_malloc,o.__wbindgen_realloc),c=_;ke().setInt32(e+4,c,true),ke().setInt32(e+0,i,true);},__wbg___wbindgen_throw_344f42d3211c4765:function(e,t){throw new Error(y(e,t))},__wbg_getRandomValues_3f44b700395062e5:function(){return ne(function(e,t){globalThis.crypto.getRandomValues(E(e,t));},arguments)},__wbg_get_78f252d074a84d0b:function(){return ne(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(E(e,t))},__wbg_prototypesetcall_4770620bbe4688a0:function(e,t,n){Uint8Array.prototype.set.call(E(e,t),n);},__wbg_set_8535240470bf2500:function(){return ne(function(e,t,n){return Reflect.set(e,t,n)},arguments)},__wbindgen_cast_0000000000000001:function(e,t){return y(e,t)},__wbindgen_init_externref_table:function(){let e=o.__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 Re=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>o.__wbg_pptxdocument_free(r,1)),Ie=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>o.__wbg_pptxrenderer_free(r,1));function bt(r){let e=o.__externref_table_alloc();return o.__wbindgen_externrefs.set(e,r),e}function mt(r,e){if(!(r instanceof e))throw new Error(`expected instance of ${e.name}`)}function E(r,e){return r=r>>>0,L().subarray(r/1,r/1+e)}var R=null;function ke(){return (R===null||R.buffer.detached===true||R.buffer.detached===void 0&&R.buffer!==o.memory.buffer)&&(R=new DataView(o.memory.buffer)),R}function y(r,e){return St(r>>>0,e)}var J=null;function L(){return (J===null||J.byteLength===0)&&(J=new Uint8Array(o.memory.buffer)),J}function ne(r,e){try{return r.apply(this,e)}catch(t){let n=bt(t);o.__wbindgen_exn_store(n);}}function gt(r){return r==null}function F(r,e){let t=e(r.length*1,1)>>>0;return L().set(r,t/1),_=r.length,t}function S(r,e,t){if(t===void 0){let l=B.encode(r),a=e(l.length,1)>>>0;return L().subarray(a,a+l.length).set(l),_=l.length,a}let n=r.length,s=e(n,1)>>>0,i=L(),c=0;for(;c<n;c++){let l=r.charCodeAt(c);if(l>127)break;i[s+c]=l;}if(c!==n){c!==0&&(r=r.slice(c)),s=t(s,n,n=c+r.length*3,1)>>>0;let l=L().subarray(s+c,s+n),a=B.encodeInto(r,l);c+=a.written,s=t(s,n,c,1)>>>0;}return _=c,s}function h(r){let e=o.__wbindgen_externrefs.get(r);return o.__externref_table_dealloc(r),e}var q=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true});q.decode();var wt=2146435072,se=0;function St(r,e){return se+=e,se>=wt&&(q=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}),q.decode(),se=e),q.decode(L().subarray(r,r+e))}var B=new TextEncoder;"encodeInto"in B||(B.encodeInto=function(r,e){let t=B.encode(r);return e.set(t),{read:r.length,written:t.length}});var _=0,o;function vt(r,e){return o=r.exports,R=null,J=null,o.__wbindgen_start(),o}async function Ct(r,e){if(typeof Response=="function"&&r instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(r,e)}catch(s){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",s);else throw s}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 Le(r){if(o!==void 0)return o;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=yt();(typeof r=="string"||typeof Request=="function"&&r instanceof Request||typeof URL=="function"&&r instanceof URL)&&(r=fetch(r));let{instance:t,module:n}=await Ct(await r,e);return vt(t)}var ie=false,V;function Tt(r=new URL("./generated/pptx_wasm_bg.wasm",import.meta.url)){return ie?Promise.resolve():V||(V=Le({module_or_path:r}).then(()=>{ie=true;},e=>{throw V=void 0,N(e)}),V)}function At(){return typeof WebAssembly=="object"}function Et(){return oe(),Fe()}function Ut(r){return oe(),Ot(()=>Oe(r))}function Rt(r,e={}){oe();let t=e.clientId??It(),n=Ne(()=>e.initialUpdate===void 0?U.openCollaborative(r,t):U.openCollaborativeFromUpdate(e.initialUpdate.slice(),t)),s=Ne(()=>new M);for(let d of e.fonts??[])Me(s,d);let i=new Map,c=[],l=0,a=false,w=false,v=0,I=false,ae=()=>{if(a)throw new Error("presentation handle is disposed")},De=()=>{if(!(a||I||v!==0)){I=true;try{for(;!a&&c.length>0;){let d=c.shift();if(!d)break;for(let[p,b]of [...i]){if(a)return;if(i.get(p)===b)try{b(d.update.slice(),d.origin);}catch{}}}}finally{I=false,a&&(c.length=0);}}},Je=()=>{if(!(!w||a))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}`);c.push({update:d.slice(1),origin:p===0?"local":"remote"});}},C=(d,p=false)=>{ae(),v+=1;try{let b,P,z=!1;try{b=d();}catch(X){P=X,z=!0;}if(p)try{Je();}catch(X){z||(P=X,z=!0);}if(z)throw N(P);return b}finally{v-=1,v===0&&De();}},g=(d,p=false)=>C(()=>JSON.parse(d()),p),Be=()=>{w||(C(()=>n.startUpdateObservation()),w=true);},Ve=()=>{!w||i.size>0||a||(c.length=0,C(()=>n.clearUpdateObservation()),w=false);};return {get clientId(){return C(()=>n.clientId)},snapshot(){return g(()=>n.snapshotJson())},story(d){return g(()=>n.storyJson(JSON.stringify({storyId:d})))},registerFont(d){return C(()=>Me(s,d))},layoutSlide(d){return g(()=>s.layoutSlideJson(n,d))},hitTest(d,p){return g(()=>s.hitTestJson(d,p))},mediaBytes(d){return C(()=>n.mediaBytes(d).slice())},insertText(d,p,b,P={}){return g(()=>n.insertTextJson(JSON.stringify({storyId:d,index:p,text:b,style:P})),true)},deleteText(d,p,b){return g(()=>n.deleteTextJson(JSON.stringify({storyId:d,start:p,end:b})),true)},formatText(d,p,b,P){return g(()=>n.formatTextJson(JSON.stringify({storyId:d,start:p,end:b,patch:P})),true)},insertParagraphBreak(d,p){return g(()=>n.insertParagraphBreakJson(JSON.stringify({storyId:d,index:p})),true)},insertSlide(d,p){return g(()=>n.insertSlideJson(JSON.stringify({index:d,layoutPartPath:p??null})),true)},deleteSlide(d){return g(()=>n.deleteSlideJson(JSON.stringify({slideId:d})),true)},moveSlide(d,p){return g(()=>n.moveSlideJson(JSON.stringify({slideId:d,toIndex:p})),true)},addTextBox(d,p){return g(()=>n.addTextBoxJson(JSON.stringify({slideId:d,draft:p})),true)},addShape(d,p){return g(()=>n.addShapeJson(JSON.stringify({slideId:d,draft:p})),true)},setShapeFill(d,p,b){return g(()=>n.setShapeFillJson(JSON.stringify({slideId:d,shapeId:p,color:b})),true)},setShapeStroke(d,p,b){return g(()=>n.setShapeStrokeJson(JSON.stringify({slideId:d,shapeId:p,stroke:b})),true)},setShapeAdjust(d,p,b){return g(()=>n.setShapeAdjustJson(JSON.stringify({slideId:d,shapeId:p,adjustments:b})),true)},removeShape(d,p){return g(()=>n.removeShapeJson(JSON.stringify({slideId:d,shapeId:p})),true)},moveShape(d,p,b,P){return g(()=>n.moveShapeJson(JSON.stringify({slideId:d,shapeId:p,x:b,y:P})),true)},resizeShape(d,p,b,P){return g(()=>n.resizeShapeJson(JSON.stringify({slideId:d,shapeId:p,width:b,height:P})),true)},canUndo(){return C(()=>n.canUndo())},canRedo(){return C(()=>n.canRedo())},undo(){return g(()=>n.undoJson(),true)},redo(){return g(()=>n.redoJson(),true)},encodeStateVector(){return C(()=>n.encodeStateVector().slice())},encodeStateAsUpdate(d){return C(()=>d===void 0?n.encodeStateAsUpdate().slice():n.encodeDiff(d.slice()).slice())},encodeDiff(d){return C(()=>n.encodeDiff(d.slice()).slice())},applyUpdate(d){return g(()=>n.applyUpdateJson(d.slice()),true)},onUpdate(d){if(ae(),typeof d!="function")throw new TypeError("update listener must be a function");let p=l++;i.set(p,d);try{Be();}catch(P){throw i.delete(p),P}let b=true;return ()=>{b&&(b=false,i.delete(p),Ve());}},dispose(){if(a)return;a=true,i.clear(),c.length=0;let d;if(w){try{n.clearUpdateObservation();}catch(p){d=p;}w=false;}try{s.free();}catch(p){d??(d=p);}try{n.free();}catch(p){d??(d=p);}if(d!==void 0)throw N(d)}}}function Me(r,e){try{return r.registerFont(e.family,e.bold??!1,e.italic??!1,e.bytes)}catch(t){throw N(t)}}function oe(){if(!ie)throw new Error("pptx wasm is not initialized; call initWasm() first")}function It(){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 Ne(r){try{return r()}catch(e){throw N(e)}}function kt(r){try{return JSON.parse(r())}catch(e){throw N(e)}}function Ot(r){return kt(r)}function N(r){return r instanceof Error?r:new Error(typeof r=="string"?r:String(r))}export{x as CollaborationError,$ as CollaborationProvider,pe as PRESENCE_LABEL_DURATION_MS,Tt as initWasm,Ut as inspectPresentation,At as isWasmAvailable,Rt as openPresentation,$e as paintSlide,G as presenceColorForClientId,je as sizeCanvasForSlide,Et as wasmVersion};
|
package/package.json
CHANGED