@betteroffice/pptx 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +95 -10
- package/dist/generated/pptx_wasm_bg.wasm +0 -0
- package/dist/index.d.ts +261 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Elia Hilse, The OpenOOXML Project
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -4,11 +4,6 @@ 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
|
-
> **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.
|
|
11
|
-
|
|
12
7
|
```bash
|
|
13
8
|
bun add @betteroffice/pptx
|
|
14
9
|
```
|
|
@@ -38,17 +33,106 @@ sizeCanvasForSlide(canvas, frame, devicePixelRatio);
|
|
|
38
33
|
await paintSlide(canvas.getContext('2d')!, frame, devicePixelRatio);
|
|
39
34
|
```
|
|
40
35
|
|
|
36
|
+
`initWasm()` with no argument only works where `fetch` of a same-origin URL works (browsers); Node and SSR must pass the wasm bytes.
|
|
37
|
+
|
|
41
38
|
All parsing, edits, collaboration state, text shaping, layout, hit-testing, and
|
|
42
39
|
display-list emission stay in Rust. The package decodes the typed boundary and
|
|
43
40
|
replays the resulting primitives on canvas. Font bytes are supplied by the host
|
|
44
41
|
and registered with the Rust shaper through `openPresentation`.
|
|
45
42
|
|
|
46
43
|
Beyond rendering, `PresentationHandle` covers editing: text
|
|
47
|
-
(`insertText` / `deleteText` / `formatText`), slides
|
|
44
|
+
(`insertText` / `deleteText` / `formatText` / `setParagraphAlignment`), slides
|
|
48
45
|
(`insertSlide` / `deleteSlide` / `moveSlide`), shapes
|
|
49
|
-
(`addTextBox` / `moveShape` / `resizeShape`
|
|
50
|
-
`
|
|
51
|
-
|
|
46
|
+
(`addTextBox` / `moveShape` / `resizeShape` / `setShapeRect`), comments
|
|
47
|
+
(`addComment` / `replyToComment` / `setCommentStatus` / `removeComment`),
|
|
48
|
+
`hitTest`, undo/redo, and `save()`, which serializes the deck back to `.pptx`
|
|
49
|
+
bytes with edits applied — untouched slides keep their exact source part bytes.
|
|
50
|
+
|
|
51
|
+
## Agent proposals
|
|
52
|
+
|
|
53
|
+
Stage a group of edits, inspect it, then accept or reject it:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const slide = deck.snapshot().slides[0];
|
|
57
|
+
const shape = slide.shapes.find((shape) => shape.textStories.length > 0)!;
|
|
58
|
+
const story = shape.textStories[0];
|
|
59
|
+
const proposal = deck.propose('editor-agent', 'Make the title concise', [{
|
|
60
|
+
type: 'replaceText',
|
|
61
|
+
storyId: story.id,
|
|
62
|
+
start: 0,
|
|
63
|
+
end: story.paragraphs[0].runs.reduce((length, run) => length + run.text.length, 0),
|
|
64
|
+
text: 'A clear title',
|
|
65
|
+
}]);
|
|
66
|
+
|
|
67
|
+
const preview = deck.previewProposal(proposal.id);
|
|
68
|
+
const proposedSlide = deck.layoutProposalSlide(proposal.id, 0);
|
|
69
|
+
const diff = deck.layoutProposalDiffSlide(proposal.id, 0);
|
|
70
|
+
await paintSlide(canvas.getContext('2d')!, diff.frame, devicePixelRatio, 1, {
|
|
71
|
+
textChanges: diff.textChanges,
|
|
72
|
+
});
|
|
73
|
+
deck.acceptProposal(proposal.id);
|
|
74
|
+
deck.undo();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`listProposals()` returns agent attribution, notes, edits, before/after targets,
|
|
78
|
+
and current `staleTargets`. `previewProposal()` and `layoutProposalSlide()` replay
|
|
79
|
+
against the current deck without changing it. `rejectProposal(id)` removes a
|
|
80
|
+
pending group. Acceptance applies the whole group in one undo step and emits
|
|
81
|
+
one local update; an invalid edit prevents the entire group from being staged
|
|
82
|
+
or accepted.
|
|
83
|
+
|
|
84
|
+
`layoutProposalDiffSlide()` lays removed and inserted text out together, keeping
|
|
85
|
+
unchanged words as context and retaining fonts and emphasis. Pass its
|
|
86
|
+
`textChanges` to `paintSlide()` for red highlights and strikethrough on deletions,
|
|
87
|
+
and green highlights and underlines on insertions. Its snapshot and UTF-16
|
|
88
|
+
ranges describe a temporary review layout; use the live handle for editing and
|
|
89
|
+
the ordinary proposed layout for the result after acceptance. Review rendering
|
|
90
|
+
does not replace the live hit-test state or add markup to saved presentations.
|
|
91
|
+
|
|
92
|
+
Supported edits replace text within one paragraph, format text, align paragraphs,
|
|
93
|
+
set shape geometry/fill/stroke/adjustments, and replace speaker notes. Text offsets
|
|
94
|
+
use UTF-16 and shape coordinates use EMU. Text replacement inherits the style at
|
|
95
|
+
its start unless `style` is supplied. Edits run in order, so later text offsets
|
|
96
|
+
refer to the result of earlier edits in the group.
|
|
97
|
+
|
|
98
|
+
Changing a targeted shape or its notes makes acceptance throw `StaleProposalError`
|
|
99
|
+
with target IDs. Review a fresh preview before calling
|
|
100
|
+
`acceptProposal(id, { force: true })`; force still validates targets and ranges.
|
|
101
|
+
Unrelated peer edits survive acceptance and Undo. Up to 64 proposals, each with
|
|
102
|
+
1–256 edits, may be pending.
|
|
103
|
+
|
|
104
|
+
Pending proposals belong to this open session: they are excluded from PPTX
|
|
105
|
+
exports and collaboration updates. Accepted edits save and sync normally.
|
|
106
|
+
`isProposalsAvailable()` supports hosts that load an older WASM build.
|
|
107
|
+
|
|
108
|
+
## Comments
|
|
109
|
+
|
|
110
|
+
PowerPoint has two comment systems and a file only ever uses one: `legacy`
|
|
111
|
+
reads in every version of PowerPoint plus LibreOffice and Google Slides, while
|
|
112
|
+
`modern` carries replies and a resolved state but only shows in PowerPoint 365.
|
|
113
|
+
A deck commits to one at its first comment, so `setCommentFlavor` only works
|
|
114
|
+
while `comments()` is empty, and `replyToComment` / `setCommentStatus` throw on
|
|
115
|
+
a legacy deck.
|
|
116
|
+
|
|
117
|
+
Saving patches existing comment XML, preserving identities, formatting, task
|
|
118
|
+
metadata, anchors and unknown fields. Unedited parts remain byte-identical.
|
|
119
|
+
Removing a thread removes its known replies; a concurrent reply survives as a
|
|
120
|
+
new root if its parent was deleted.
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
deck.addComment(deck.snapshot().slides[0].id, {
|
|
124
|
+
author: 'Ada Lovelace',
|
|
125
|
+
initials: 'AL',
|
|
126
|
+
text: 'Tighten this claim.',
|
|
127
|
+
created: new Date().toISOString(),
|
|
128
|
+
xEmu: 1_828_800,
|
|
129
|
+
yEmu: 914_400,
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Positions are EMU, like every other coordinate. `created` is supplied by the
|
|
134
|
+
caller rather than read from a clock, so peers replaying the same edits
|
|
135
|
+
converge.
|
|
52
136
|
|
|
53
137
|
## Collaboration
|
|
54
138
|
|
|
@@ -77,4 +161,5 @@ root, install `wasm-pack` 0.15.0 and `binaryen`, then run
|
|
|
77
161
|
`bun scripts/build-pptx-wasm.ts`.
|
|
78
162
|
Package builds copy the binary into `dist/generated`.
|
|
79
163
|
|
|
80
|
-
|
|
164
|
+
[JavaScript guide](https://docs.betteroffice.dev/docs/javascript) ·
|
|
165
|
+
[Changelog](https://github.com/openooxml/betteroffice/blob/main/packages/pptx/CHANGELOG.md) · Apache-2.0.
|
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ interface TextStyle {
|
|
|
5
5
|
color?: string;
|
|
6
6
|
fontFamily?: string;
|
|
7
7
|
underline?: string;
|
|
8
|
+
spacingPt?: number;
|
|
9
|
+
baselinePct?: number;
|
|
8
10
|
}
|
|
9
11
|
type TextStylePatch = TextStyle;
|
|
10
12
|
interface TextStyleSnapshot {
|
|
@@ -14,11 +16,15 @@ interface TextStyleSnapshot {
|
|
|
14
16
|
color: string | null;
|
|
15
17
|
fontFamily: string | null;
|
|
16
18
|
underline: string | null;
|
|
19
|
+
spacingPt?: number | null;
|
|
20
|
+
baselinePct?: number | null;
|
|
17
21
|
}
|
|
18
22
|
interface TextRunSnapshot {
|
|
19
23
|
text: string;
|
|
20
24
|
style: TextStyleSnapshot;
|
|
21
25
|
}
|
|
26
|
+
/** OOXML `a:pPr@algn` token. */
|
|
27
|
+
type ParagraphAlignment = 'l' | 'ctr' | 'r' | 'just';
|
|
22
28
|
interface ParagraphSnapshot {
|
|
23
29
|
id: string;
|
|
24
30
|
alignment: string | null;
|
|
@@ -50,6 +56,25 @@ interface ShapeOutline {
|
|
|
50
56
|
cap?: string;
|
|
51
57
|
join?: string;
|
|
52
58
|
}
|
|
59
|
+
type BlipEffect = {
|
|
60
|
+
type: 'biLevel';
|
|
61
|
+
threshold: number;
|
|
62
|
+
} | {
|
|
63
|
+
type: 'grayscale';
|
|
64
|
+
} | {
|
|
65
|
+
type: 'luminance';
|
|
66
|
+
brightness: number;
|
|
67
|
+
contrast: number;
|
|
68
|
+
} | {
|
|
69
|
+
type: 'duotone';
|
|
70
|
+
shadow: ColorValue | null;
|
|
71
|
+
highlight: ColorValue | null;
|
|
72
|
+
} | {
|
|
73
|
+
type: 'colorChange';
|
|
74
|
+
from: ColorValue | null;
|
|
75
|
+
to: ColorValue | null;
|
|
76
|
+
useAlpha?: boolean;
|
|
77
|
+
};
|
|
53
78
|
interface ShapeSnapshot {
|
|
54
79
|
id: string;
|
|
55
80
|
sourceId: number;
|
|
@@ -62,6 +87,8 @@ interface ShapeSnapshot {
|
|
|
62
87
|
rotationDeg: number;
|
|
63
88
|
flipH: boolean;
|
|
64
89
|
flipV: boolean;
|
|
90
|
+
/** Hides this shape and its descendants; omitted when false. */
|
|
91
|
+
hidden?: boolean;
|
|
65
92
|
geometry: string;
|
|
66
93
|
adjustValues: Record<string, number>;
|
|
67
94
|
placeholder: unknown | null;
|
|
@@ -70,6 +97,7 @@ interface ShapeSnapshot {
|
|
|
70
97
|
outline: ShapeOutline | null;
|
|
71
98
|
resolvedOutlineColor: string | null;
|
|
72
99
|
mediaPartPath: string | null;
|
|
100
|
+
blipEffects?: BlipEffect[];
|
|
73
101
|
graphic: unknown | null;
|
|
74
102
|
textStories: StorySnapshot[];
|
|
75
103
|
children: ShapeSnapshot[];
|
|
@@ -79,12 +107,37 @@ interface SlideSnapshot {
|
|
|
79
107
|
sourcePartPath: string | null;
|
|
80
108
|
layoutPartPath: string | null;
|
|
81
109
|
name: string | null;
|
|
110
|
+
/** Speaker notes as plain text; absent when the slide has none. */
|
|
111
|
+
notes?: string;
|
|
82
112
|
shapes: ShapeSnapshot[];
|
|
83
113
|
}
|
|
84
114
|
interface DeckSnapshot {
|
|
85
115
|
widthEmu: number;
|
|
86
116
|
heightEmu: number;
|
|
87
117
|
slides: SlideSnapshot[];
|
|
118
|
+
commentFlavor?: CommentFlavor;
|
|
119
|
+
comments?: CommentSnapshot[];
|
|
120
|
+
}
|
|
121
|
+
/** Legacy comments or modern threads. */
|
|
122
|
+
type CommentFlavor = 'legacy' | 'modern';
|
|
123
|
+
interface CommentSnapshot {
|
|
124
|
+
id: string;
|
|
125
|
+
slideId: string;
|
|
126
|
+
author: string;
|
|
127
|
+
initials: string;
|
|
128
|
+
text: string;
|
|
129
|
+
created: string | null;
|
|
130
|
+
xEmu: number;
|
|
131
|
+
yEmu: number;
|
|
132
|
+
/** Set on a reply; names the thread root. Modern decks only. */
|
|
133
|
+
parentId: string | null;
|
|
134
|
+
resolved: boolean;
|
|
135
|
+
}
|
|
136
|
+
interface CommentReceipt {
|
|
137
|
+
commentId: string;
|
|
138
|
+
slideId: string;
|
|
139
|
+
parentId: string | null;
|
|
140
|
+
resolved: boolean;
|
|
88
141
|
}
|
|
89
142
|
interface SlideReceipt {
|
|
90
143
|
slideId: string;
|
|
@@ -195,10 +248,28 @@ type Paint = {
|
|
|
195
248
|
color: string;
|
|
196
249
|
}>;
|
|
197
250
|
};
|
|
251
|
+
interface StrokeEnd {
|
|
252
|
+
kind: string;
|
|
253
|
+
width: number;
|
|
254
|
+
length: number;
|
|
255
|
+
}
|
|
198
256
|
interface Stroke {
|
|
257
|
+
/** Solid colour or first gradient stop. */
|
|
199
258
|
color: string;
|
|
200
259
|
width: number;
|
|
201
260
|
dashed?: boolean;
|
|
261
|
+
paint?: Paint;
|
|
262
|
+
headEnd?: StrokeEnd;
|
|
263
|
+
tailEnd?: StrokeEnd;
|
|
264
|
+
}
|
|
265
|
+
/** An `a:outerShdw`: a blurred copy of the shape's own path, offset and tinted. */
|
|
266
|
+
interface Shadow {
|
|
267
|
+
color: string;
|
|
268
|
+
blur?: number;
|
|
269
|
+
dx?: number;
|
|
270
|
+
dy?: number;
|
|
271
|
+
scaleX?: number;
|
|
272
|
+
scaleY?: number;
|
|
202
273
|
}
|
|
203
274
|
interface PrimitiveTransform {
|
|
204
275
|
rotationDeg?: number;
|
|
@@ -219,15 +290,51 @@ interface ShapePrimitive extends PrimitiveBase {
|
|
|
219
290
|
name: string;
|
|
220
291
|
geometry: string;
|
|
221
292
|
path: GeometryPathCommand[];
|
|
293
|
+
clip?: GeometryPathCommand[];
|
|
294
|
+
evenOdd?: boolean;
|
|
222
295
|
adjustValues?: Record<string, number>;
|
|
223
296
|
fill?: Paint;
|
|
224
297
|
stroke?: Stroke;
|
|
298
|
+
shadow?: Shadow;
|
|
299
|
+
}
|
|
300
|
+
/** An `a:blip` colour transform, colours already resolved to `#rrggbbaa`. */
|
|
301
|
+
type ImageEffect = {
|
|
302
|
+
kind: 'biLevel';
|
|
303
|
+
threshold: number;
|
|
304
|
+
} | {
|
|
305
|
+
kind: 'grayscale';
|
|
306
|
+
} | {
|
|
307
|
+
kind: 'luminance';
|
|
308
|
+
brightness: number;
|
|
309
|
+
contrast: number;
|
|
310
|
+
} | {
|
|
311
|
+
kind: 'duotone';
|
|
312
|
+
shadow: string;
|
|
313
|
+
highlight: string;
|
|
314
|
+
} | {
|
|
315
|
+
kind: 'colorChange';
|
|
316
|
+
from: string;
|
|
317
|
+
to: string;
|
|
318
|
+
useAlpha?: boolean;
|
|
319
|
+
};
|
|
320
|
+
interface ImageCrop {
|
|
321
|
+
left?: number;
|
|
322
|
+
top?: number;
|
|
323
|
+
right?: number;
|
|
324
|
+
bottom?: number;
|
|
225
325
|
}
|
|
226
326
|
interface ImagePrimitive extends PrimitiveBase {
|
|
227
327
|
kind: 'image';
|
|
228
328
|
name: string;
|
|
229
329
|
assetId?: string;
|
|
330
|
+
/** Applied to the bitmap in order before it is drawn. */
|
|
331
|
+
effects?: ImageEffect[];
|
|
332
|
+
/** Fraction of the source discarded per edge, from `a:srcRect`. */
|
|
333
|
+
crop?: ImageCrop;
|
|
334
|
+
/** Outline the picture is masked to, when its `spPr` gives it one. */
|
|
335
|
+
path?: GeometryPathCommand[];
|
|
230
336
|
stroke?: Stroke;
|
|
337
|
+
shadow?: Shadow;
|
|
231
338
|
}
|
|
232
339
|
interface CaretStop {
|
|
233
340
|
position: number;
|
|
@@ -254,6 +361,8 @@ interface PositionedTextRun {
|
|
|
254
361
|
italic: boolean;
|
|
255
362
|
underline: boolean;
|
|
256
363
|
color: string;
|
|
364
|
+
letterSpacingPx?: number;
|
|
365
|
+
baselineOffsetPx?: number;
|
|
257
366
|
glyphs: PositionedGlyph[];
|
|
258
367
|
}
|
|
259
368
|
interface PositionedTextLine {
|
|
@@ -300,7 +409,15 @@ interface ChartPrimitive extends PrimitiveBase {
|
|
|
300
409
|
label: string;
|
|
301
410
|
primitives: SlidePrimitive[];
|
|
302
411
|
}
|
|
303
|
-
|
|
412
|
+
/** A laid-out table. Its cells paint clipped to the table rectangle, and
|
|
413
|
+
* `label` is the screen-reader summary of the whole table. */
|
|
414
|
+
interface TablePrimitive extends PrimitiveBase {
|
|
415
|
+
kind: 'table';
|
|
416
|
+
name: string;
|
|
417
|
+
label: string;
|
|
418
|
+
primitives: SlidePrimitive[];
|
|
419
|
+
}
|
|
420
|
+
type SlidePrimitive = ShapePrimitive | ImagePrimitive | TextBoxPrimitive | PlaceholderPrimitive | ChartPrimitive | TablePrimitive;
|
|
304
421
|
interface SlideDisplayList {
|
|
305
422
|
contractVersion: number;
|
|
306
423
|
width: number;
|
|
@@ -322,9 +439,97 @@ interface UpdateEvent {
|
|
|
322
439
|
update: Uint8Array;
|
|
323
440
|
}
|
|
324
441
|
|
|
442
|
+
type ProposalEdit = {
|
|
443
|
+
type: 'replaceText';
|
|
444
|
+
storyId: string;
|
|
445
|
+
start: number;
|
|
446
|
+
end: number;
|
|
447
|
+
text: string;
|
|
448
|
+
style?: Partial<TextStyleSnapshot> | null;
|
|
449
|
+
} | {
|
|
450
|
+
type: 'formatText';
|
|
451
|
+
storyId: string;
|
|
452
|
+
start: number;
|
|
453
|
+
end: number;
|
|
454
|
+
patch: Partial<TextStyleSnapshot>;
|
|
455
|
+
} | {
|
|
456
|
+
type: 'setParagraphAlignment';
|
|
457
|
+
storyId: string;
|
|
458
|
+
start: number;
|
|
459
|
+
end: number;
|
|
460
|
+
alignment: ParagraphAlignment | 'justLow' | 'dist' | 'thaiDist' | null;
|
|
461
|
+
} | {
|
|
462
|
+
type: 'setShapeRect';
|
|
463
|
+
slideId: string;
|
|
464
|
+
shapeId: string;
|
|
465
|
+
rect: ShapeRect;
|
|
466
|
+
} | {
|
|
467
|
+
type: 'setShapeFill';
|
|
468
|
+
slideId: string;
|
|
469
|
+
shapeId: string;
|
|
470
|
+
color: string | null;
|
|
471
|
+
} | {
|
|
472
|
+
type: 'setShapeStroke';
|
|
473
|
+
slideId: string;
|
|
474
|
+
shapeId: string;
|
|
475
|
+
stroke: {
|
|
476
|
+
[K in keyof ShapeStroke]: ShapeStroke[K] | null;
|
|
477
|
+
};
|
|
478
|
+
} | {
|
|
479
|
+
type: 'setShapeAdjust';
|
|
480
|
+
slideId: string;
|
|
481
|
+
shapeId: string;
|
|
482
|
+
adjustments: Record<string, number>;
|
|
483
|
+
} | {
|
|
484
|
+
type: 'setSlideNotes';
|
|
485
|
+
slideId: string;
|
|
486
|
+
text: string;
|
|
487
|
+
};
|
|
488
|
+
interface ProposalChange {
|
|
489
|
+
slideId: string;
|
|
490
|
+
shapeId: string | null;
|
|
491
|
+
before: ShapeSnapshot | null;
|
|
492
|
+
after: ShapeSnapshot | null;
|
|
493
|
+
oldText: string;
|
|
494
|
+
newText: string;
|
|
495
|
+
}
|
|
496
|
+
interface Proposal {
|
|
497
|
+
id: string;
|
|
498
|
+
agentId: string;
|
|
499
|
+
note: string | null;
|
|
500
|
+
edits: ProposalEdit[];
|
|
501
|
+
changes: ProposalChange[];
|
|
502
|
+
staleTargets: string[];
|
|
503
|
+
}
|
|
504
|
+
interface ProposalPreview {
|
|
505
|
+
proposal: Proposal;
|
|
506
|
+
snapshot: DeckSnapshot;
|
|
507
|
+
}
|
|
508
|
+
interface ProposalTextChange {
|
|
509
|
+
storyId: string;
|
|
510
|
+
start: number;
|
|
511
|
+
end: number;
|
|
512
|
+
kind: 'insertion' | 'deletion';
|
|
513
|
+
}
|
|
514
|
+
interface ProposalDiffSlide extends ProposalPreview {
|
|
515
|
+
frame: SlideDisplayList;
|
|
516
|
+
textChanges: ProposalTextChange[];
|
|
517
|
+
}
|
|
518
|
+
interface ProposalAcceptance {
|
|
519
|
+
proposalId: string;
|
|
520
|
+
applied: boolean;
|
|
521
|
+
snapshot: DeckSnapshot;
|
|
522
|
+
}
|
|
523
|
+
declare class StaleProposalError extends Error {
|
|
524
|
+
readonly targets: string[];
|
|
525
|
+
constructor(targets: string[]);
|
|
526
|
+
}
|
|
527
|
+
|
|
325
528
|
type CanvasImageResolver = (assetId: string) => CanvasImageSource | Promise<CanvasImageSource | null> | null;
|
|
326
529
|
interface PaintSlideOptions {
|
|
327
530
|
resolveImage?: CanvasImageResolver;
|
|
531
|
+
maxShadowPixels?: number;
|
|
532
|
+
textChanges?: readonly ProposalTextChange[];
|
|
328
533
|
}
|
|
329
534
|
interface SlideCanvasLike {
|
|
330
535
|
width: number;
|
|
@@ -337,6 +542,21 @@ interface SlideCanvasLike {
|
|
|
337
542
|
declare function sizeCanvasForSlide(canvas: SlideCanvasLike, list: Pick<SlideDisplayList, 'width' | 'height'>, dpr: number, scale?: number): void;
|
|
338
543
|
declare function paintSlide(ctx: CanvasRenderingContext2D, list: SlideDisplayList, dpr?: number, scale?: number, options?: PaintSlideOptions): Promise<void>;
|
|
339
544
|
|
|
545
|
+
/** Convert presentation image formats that browsers cannot decode. */
|
|
546
|
+
declare function presentationImageBlob(bytes: Uint8Array): Blob;
|
|
547
|
+
|
|
548
|
+
interface SlideToPngOptions {
|
|
549
|
+
/** Output scale, e.g. 2 for hidpi. */
|
|
550
|
+
scale?: number;
|
|
551
|
+
resolveImage?: CanvasImageResolver;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Rasterize one slide to a PNG blob through the same canvas painter the editor
|
|
555
|
+
* draws with, so an export matches what is on screen. The server-side twin is
|
|
556
|
+
* the `betteroffice-pptx-raster` crate.
|
|
557
|
+
*/
|
|
558
|
+
declare function slideToPng(list: SlideDisplayList, options?: SlideToPngOptions): Promise<Blob>;
|
|
559
|
+
|
|
340
560
|
type CollaborationUpdateOrigin = 'local' | 'remote';
|
|
341
561
|
interface CollaborationReplica {
|
|
342
562
|
readonly clientId: number;
|
|
@@ -505,6 +725,16 @@ interface OpenPresentationOptions {
|
|
|
505
725
|
initialUpdate?: Uint8Array;
|
|
506
726
|
}
|
|
507
727
|
interface PresentationHandle extends CollaborationReplica {
|
|
728
|
+
isProposalsAvailable(): boolean;
|
|
729
|
+
propose(agentId: string, note: string | null, edits: readonly ProposalEdit[]): Proposal;
|
|
730
|
+
listProposals(): Proposal[];
|
|
731
|
+
previewProposal(id: string): ProposalPreview;
|
|
732
|
+
layoutProposalSlide(id: string, slideIndex: number): SlideDisplayList;
|
|
733
|
+
layoutProposalDiffSlide(id: string, slideIndex: number): ProposalDiffSlide;
|
|
734
|
+
acceptProposal(id: string, options?: {
|
|
735
|
+
force?: boolean;
|
|
736
|
+
}): ProposalAcceptance;
|
|
737
|
+
rejectProposal(id: string): boolean;
|
|
508
738
|
readonly clientId: number;
|
|
509
739
|
snapshot(): DeckSnapshot;
|
|
510
740
|
story(storyId: string): StorySnapshot;
|
|
@@ -518,17 +748,45 @@ interface PresentationHandle extends CollaborationReplica {
|
|
|
518
748
|
deleteText(storyId: string, start: number, end: number): TextReceipt;
|
|
519
749
|
formatText(storyId: string, start: number, end: number, patch: TextStylePatch): TextReceipt;
|
|
520
750
|
insertParagraphBreak(storyId: string, index: number): TextReceipt;
|
|
751
|
+
/** Sets the alignment of every paragraph the range touches; `null` restores
|
|
752
|
+
* the inherited value. */
|
|
753
|
+
setParagraphAlignment(storyId: string, start: number, end: number, alignment: ParagraphAlignment | null): TextReceipt;
|
|
521
754
|
insertSlide(index: number, layoutPartPath?: string): SlideReceipt;
|
|
522
755
|
deleteSlide(slideId: string): SlideReceipt;
|
|
523
756
|
moveSlide(slideId: string, toIndex: number): SlideReceipt;
|
|
757
|
+
/** Sets a slide's speaker notes; empty text clears them. */
|
|
758
|
+
setSlideNotes(slideId: string, text: string): void;
|
|
524
759
|
addTextBox(slideId: string, draft: ShapeDraft): ShapeReceipt;
|
|
525
760
|
addShape(slideId: string, draft: PresetShapeDraft): ShapeReceipt;
|
|
526
761
|
setShapeFill(slideId: string, shapeId: string, color: string | null): ShapeFillReceipt;
|
|
527
762
|
setShapeStroke(slideId: string, shapeId: string, stroke: ShapeStroke): ShapeStrokeReceipt;
|
|
528
763
|
setShapeAdjust(slideId: string, shapeId: string, adjustments: Record<string, number>): ShapeAdjustReceipt;
|
|
529
764
|
removeShape(slideId: string, shapeId: string): ShapeReceipt;
|
|
765
|
+
/** Adds a slide comment; coordinates are EMU. */
|
|
766
|
+
addComment(slideId: string, comment: {
|
|
767
|
+
author: string;
|
|
768
|
+
initials?: string;
|
|
769
|
+
text: string;
|
|
770
|
+
created: string;
|
|
771
|
+
xEmu?: number;
|
|
772
|
+
yEmu?: number;
|
|
773
|
+
}): CommentReceipt;
|
|
774
|
+
/** Modern decks only; legacy `p:cm` has no reply list. */
|
|
775
|
+
replyToComment(commentId: string, reply: {
|
|
776
|
+
author: string;
|
|
777
|
+
initials?: string;
|
|
778
|
+
text: string;
|
|
779
|
+
created: string;
|
|
780
|
+
}): CommentReceipt;
|
|
781
|
+
/** Resolves or reopens a modern comment. */
|
|
782
|
+
setCommentStatus(commentId: string, resolved: boolean): CommentReceipt;
|
|
783
|
+
removeComment(commentId: string): CommentReceipt;
|
|
784
|
+
/** Only legal while the deck has no comments. */
|
|
785
|
+
setCommentFlavor(flavor: CommentFlavor): CommentFlavor;
|
|
786
|
+
comments(): CommentSnapshot[];
|
|
530
787
|
moveShape(slideId: string, shapeId: string, x: number, y: number): TransformReceipt;
|
|
531
788
|
resizeShape(slideId: string, shapeId: string, width: number, height: number): TransformReceipt;
|
|
789
|
+
setShapeRect(slideId: string, shapeId: string, rect: ShapeRect): TransformReceipt;
|
|
532
790
|
canUndo(): boolean;
|
|
533
791
|
canRedo(): boolean;
|
|
534
792
|
undo(): HistoryResult;
|
|
@@ -540,10 +798,11 @@ interface PresentationHandle extends CollaborationReplica {
|
|
|
540
798
|
onUpdate(listener: (update: Uint8Array, origin: CollaborationUpdateOrigin) => void): () => void;
|
|
541
799
|
dispose(): void;
|
|
542
800
|
}
|
|
801
|
+
declare function isProposalsAvailable(): boolean;
|
|
543
802
|
declare function initWasm(input?: WasmInitInput): Promise<void>;
|
|
544
803
|
declare function isWasmAvailable(): boolean;
|
|
545
804
|
declare function wasmVersion(): string;
|
|
546
805
|
declare function inspectPresentation(bytes: Uint8Array): unknown;
|
|
547
806
|
declare function openPresentation(bytes: Uint8Array, options?: OpenPresentationOptions): PresentationHandle;
|
|
548
807
|
|
|
549
|
-
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 };
|
|
808
|
+
export { type BlipEffect, 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 CommentFlavor, type CommentReceipt, type CommentSnapshot, type DeckSnapshot, type GeometryPathCommand, type HistoryResult, type HitTestResult, type ImageCrop, type ImageEffect, type ImagePrimitive, type OpenPresentationOptions, PRESENCE_LABEL_DURATION_MS, type Paint, type PaintSlideOptions, type ParagraphAlignment, 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 Proposal, type ProposalAcceptance, type ProposalChange, type ProposalDiffSlide, type ProposalEdit, type ProposalPreview, type ProposalTextChange, 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 SlideToPngOptions, StaleProposalError, type StorySnapshot, type Stroke, type StrokeEnd, type TextBoxPrimitive, type TextReceipt, type TextRunSnapshot, type TextStyle, type TextStylePatch, type TextStyleSnapshot, type TransformReceipt, type UpdateEvent, type WasmInitInput, initWasm, inspectPresentation, isProposalsAvailable, isWasmAvailable, openPresentation, paintSlide, presenceColorForClientId, presentationImageBlob, sizeCanvasForSlide, slideToPng, wasmVersion };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var je=Object.defineProperty;var $e=(r,e,t)=>e in r?je(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t;var u=(r,e,t)=>$e(r,typeof e!="symbol"?e+"":e,t);function qe(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 Xe(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=de(r,e.background,0,0,e.width,e.height),r.fillRect(0,0,e.width,e.height));for(let i of e.primitives)await ce(r,i,s);}finally{r.restore();}}async function ce(r,e,t){r.save();try{switch(He(r,e),e.kind){case "shape":Ye(r,e);break;case "image":await Qe(r,e,t.resolveImage);break;case "textBox":Ze(r,e);break;case "placeholder":rt(r,e);break;case "chart":await Ge(r,e,t);break}}finally{r.restore();}}async function Ge(r,e,t){r.beginPath(),r.rect(e.x,e.y,e.w,e.h),r.clip();for(let n of e.primitives)await ce(r,n,t);}function He(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 Ye(r,e){Ke(r,e.path,e.x,e.y,e.w,e.h),e.fill&&(r.fillStyle=de(r,e.fill,e.x,e.y,e.w,e.h),r.fill()),e.stroke&&le(r,e.stroke);}function Ke(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 le(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 de(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 k of e.stops)v.addColorStop(Math.max(0,Math.min(1,k.position)),k.color);return v}async function Qe(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),le(r,e.stroke));}function Ze(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)et(r,n,t.baseline);}function et(r,e,t){let n=e.italic?"italic ":"",s=e.bold?"bold ":"";r.font=`${n}${s}${e.fontSizePx}px ${tt(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 tt(r){return r.includes(" ")?JSON.stringify(r):r}function rt(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 ue=3e3;var pe=["#B3261E","#7B1FA2","#3949AB","#00796B","#2E7D32","#A84400","#C2185B","#00695C"],nt=/^#[0-9a-fA-F]+$/;function G(r){return pe[Math.abs(r)%pe.length]}function H(r,e){return typeof e=="string"&&(e.length===4||e.length===7)&&nt.test(e)?e:G(r)}function fe(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(st)}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:he(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 he(r){return {clientId:r.clientId,clock:r.clock,user:{...r.user},cursor:r.cursor?{...r.cursor}:null}}function st(r){return {state:he(r.state),lastSeen:r.lastSeen,cursorMovedAt:r.cursorMovedAt}}var A=16777216,F=4096,ye=0,be=1,ot=2,me=3,ge=0,we=1,Se=2,at=0,ct=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((ct-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 lt(r){let e=new TextEncoder().encode(r);return N([T(e.byteLength),e],A)}function N(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 N([T(ye),T(r),T(e.byteLength),e],t)}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){return Z(Se,r,e)}function Ce(r,e=A){if(r.length>F)throw new f(`Awareness update exceeds ${F} entries`);let t=[T(r.length)];for(let s of r){Re(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),lt(i));}let n=N(t,e);return N([T(be),T(n.byteLength),n],e)}function Te(r=A){return N([T(me)],r)}function Ae(r,e=F){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:Ue(a,c,l)};Re(w),s.push(w);}if(!t.done)throw new f("Awareness update has trailing bytes");return s}function Ee(r,e=A,t=F){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 ye:{let c=n.readVarUint(),l=n.readVarUint8Array();if(c===ge)s.push({type:"sync-step-1",stateVector:l});else if(c===we)s.push({type:"sync-step-2",update:l});else if(c===Se)s.push({type:"update",update:l});else throw new f(`Unknown sync message type ${c}`);break}case be:s.push({type:"awareness",update:n.readVarUint8Array()});break;case ot:{let c=n.readVarUint();if(c!==at)throw new f(`Unknown auth message type ${c}`);s.push({type:"auth",reason:n.readVarString()});break}case me:s.push({type:"query-awareness"});break;default:throw new f(`Unknown top-level message type ${i}`)}}return s}function Ue(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:dt(r.cursor)}}function dt(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 Re(r){_e(r.clientId,"Awareness clientId"),_e(r.clock,"Awareness clock"),r.state!==null&&Ue(r.state,r.clientId,r.clock);}function _e(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 ft=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 ht(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}: ${ht(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 _t(r){if(!Number.isSafeInteger(r)||r<0)throw new RangeError("Replica clientId must be a non-negative safe integer");return r}function yt(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 bt(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=_t(e.clientId),this.localUser=fe(this.localClientId,n.user),this.remotePresence=new W(this.localClientId),this.maxFrameBytes=ee("maxFrameBytes",n.maxFrameBytes??A,false),this.maxMessagesPerFrame=ee("maxMessagesPerFrame",n.maxMessagesPerFrame??F,false),this.maxPendingBytes=ee("maxPendingBytes",n.maxPendingBytes??ft,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=yt(e),n=!t||bt(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(xe(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(Te(this.maxFrameBytes));}catch(n){this.report(m("protocol","Failed to encode awareness query",n));}}handleMessage(e,t){let n;try{n=Ee(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=Ae(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(Pe(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(ve(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=Ce([{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,Ie.register(t,t.__wbg_ptr,t),t}__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_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=I(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=I(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=I(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,n){let s=I(e,o.__wbindgen_malloc),i=_;var c=Me(n)?0:I(n,o.__wbindgen_malloc),l=_;let a=o.pptxdocument_openCollaborativeFromUpdate(s,i,t,c,l);if(a[2])throw h(a[1]);return r.__wrap(a[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);}}saveBytes(){let e=o.pptxdocument_saveBytes(this.__wbg_ptr);if(e[3])throw h(e[2]);var t=E(e[0],e[1]).slice();return o.__wbindgen_free(e[0],e[1]*1,1),t}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,ke.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{wt(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,ke.register(this,this.__wbg_ptr,this),this}registerFont(e,t,n,s){let i=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),c=_,l=I(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 Fe(r){let e,t;try{let i=I(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 Le(){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 mt(){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=Me(s)?0:S(s,o.__wbindgen_malloc,o.__wbindgen_realloc),c=_;Oe().setInt32(e+4,c,true),Oe().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 Ie=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>o.__wbg_pptxdocument_free(r,1)),ke=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>o.__wbg_pptxrenderer_free(r,1));function gt(r){let e=o.__externref_table_alloc();return o.__wbindgen_externrefs.set(e,r),e}function wt(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 Oe(){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 xt(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=gt(t);o.__wbindgen_exn_store(n);}}function Me(r){return r==null}function I(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 St=2146435072,se=0;function xt(r,e){return se+=e,se>=St&&(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 Ct(r,e){return o=r.exports,R=null,J=null,o.__wbindgen_start(),o}async function Tt(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 De(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=mt();(typeof r=="string"||typeof Request=="function"&&r instanceof Request||typeof URL=="function"&&r instanceof URL)&&(r=fetch(r));let{instance:t,module:n}=await Tt(await r,e);return Ct(t)}var ie=false,V;function At(r=new URL("./generated/pptx_wasm_bg.wasm",import.meta.url)){return ie?Promise.resolve():V||(V=De({module_or_path:r}).then(()=>{ie=true;},e=>{throw V=void 0,D(e)}),V)}function Et(){return typeof WebAssembly=="object"}function Ut(){return oe(),Le()}function Rt(r){return oe(),Ft(()=>Fe(r))}function It(r,e={}){oe();let t=e.clientId??kt(),n=Je(()=>e.initialUpdate===void 0?U.openCollaborative(r,t):U.openCollaborativeFromUpdate(e.initialUpdate.slice(),t,r.slice())),s=Je(()=>new M);for(let d of e.fonts??[])Ne(s,d);let i=new Map,c=[],l=0,a=false,w=false,v=0,k=false,ae=()=>{if(a)throw new Error("presentation handle is disposed")},Be=()=>{if(!(a||k||v!==0)){k=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{k=false,a&&(c.length=0);}}},Ve=()=>{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{Ve();}catch(X){z||(P=X,z=!0);}if(z)throw D(P);return b}finally{v-=1,v===0&&Be();}},g=(d,p=false)=>C(()=>JSON.parse(d()),p),ze=()=>{w||(C(()=>n.startUpdateObservation()),w=true);},We=()=>{!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(()=>Ne(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())},save(){return C(()=>n.saveBytes().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{ze();}catch(P){throw i.delete(p),P}let b=true;return ()=>{b&&(b=false,i.delete(p),We());}},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 D(d)}}}function Ne(r,e){try{return r.registerFont(e.family,e.bold??!1,e.italic??!1,e.bytes)}catch(t){throw D(t)}}function oe(){if(!ie)throw new Error("pptx wasm is not initialized; call initWasm() first")}function kt(){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 Je(r){try{return r()}catch(e){throw D(e)}}function Ot(r){try{return JSON.parse(r())}catch(e){throw D(e)}}function Ft(r){return Ot(r)}function D(r){return r instanceof Error?r:new Error(typeof r=="string"?r:String(r))}export{x as CollaborationError,$ as CollaborationProvider,ue as PRESENCE_LABEL_DURATION_MS,At as initWasm,Rt as inspectPresentation,Et as isWasmAvailable,It as openPresentation,Xe as paintSlide,G as presenceColorForClientId,qe as sizeCanvasForSlide,Ut as wasmVersion};
|
|
1
|
+
var _t=Object.defineProperty;var gt=(t,e,r)=>e in t?_t(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r;var m=(t,e,r)=>gt(t,typeof e!="symbol"?e+"":e,r);function pe(t,e,r,n=1){t.width=Math.round(e.width*n*r),t.height=Math.round(e.height*n*r),t.style.width=`${e.width*n}px`,t.style.height=`${e.height*n}px`;}async function ue(t,e,r=1,n=1,o={}){let i={remaining:o.maxShadowPixels??134217728};if(!Number.isSafeInteger(i.remaining)||i.remaining<0)throw new Error("invalid shadow pixel budget");t.save();try{t.setTransform(r*n,0,0,r*n,0,0),t.clearRect(0,0,e.width,e.height),e.background&&(t.fillStyle=te(t,e.background,0,0,e.width,e.height),t.fillRect(0,0,e.width,e.height));for(let a of e.primitives)await Je(t,a,o,r*n,i);}finally{t.restore();}}async function Je(t,e,r,n,o){t.save();try{switch(yt(t,e),e.kind){case "shape":Le(t,e,n,o);break;case "image":await Et(t,e,r.resolveImage,n,o);break;case "textBox":Nt(t,e,r.textChanges);break;case "placeholder":Xt(t,e);break;case "chart":case "table":await bt(t,e,r,n,o);break}}finally{t.restore();}}async function bt(t,e,r,n,o){t.beginPath(),t.rect(e.x,e.y,e.w,e.h),t.clip();for(let i of e.primitives)await Je(t,i,r,n,o);}function yt(t,e){let r=e.transform;if(!r)return;let n=e.x+e.w/2,o=e.y+e.h/2;t.translate(n,o),t.rotate((r.rotationDeg??0)*Math.PI/180),t.scale(r.flipH?-1:1,r.flipV?-1:1),t.translate(-n,-o);}function Le(t,e,r,n){e.clip&&(ce(t,e.clip,e.x,e.y,e.w,e.h),t.clip()),e.shadow&&(e.fill||e.stroke)&&wt(t,e,r,n),ce(t,e.path,e.x,e.y,e.w,e.h),e.fill&&(t.fillStyle=te(t,e.fill,e.x,e.y,e.w,e.h),t.fill(e.evenOdd?"evenodd":"nonzero")),e.stroke&&(Ne(t,e.stroke,e.x,e.y,e.w,e.h),Pt(t,e));}function wt(t,e,r,n){Fe(t,e.shadow,fe(e.path,e),e.stroke?.width??0,r,n,o=>Le(o,{...e,shadow:void 0},r,n));}function Fe(t,e,r,n,o,i,a){let c=e.scaleX??1,s=e.scaleY??1,u=t.getTransform(),f={a:u.a*c,b:u.b*s,c:u.c*c,d:u.d*s,e:u.e*c,f:u.f*s};if(!r.length)return;let v=1/0,C=1/0,T=-1/0,L=-1/0;for(let[$,Ie]of r){let Re=f.a*$+f.c*Ie+f.e,Ue=f.b*$+f.d*Ie+f.f;v=Math.min(v,Re),C=Math.min(C,Ue),T=Math.max(T,Re),L=Math.max(L,Ue);}let A=Math.min(Math.max(e.blur??0,0)*o/2,128),_=A*3+1,N=n*o*Math.max(Math.abs(c),Math.abs(s))*2,B=(e.dx??0)*o,z=(e.dy??0)*o,d=Math.floor(Math.max(v-N,-_-B)),p=Math.floor(Math.max(C-N,-_-z)),y=Math.ceil(Math.min(T+N,t.canvas.width+_-B)),x=Math.ceil(Math.min(L+N,t.canvas.height+_-z));if(y<=d||x<=p)return;let M=(y-d)*(x-p);if(!Number.isSafeInteger(M)||M>i.remaining)throw new Error("shadows exceed the pixel budget on one slide");i.remaining-=M;let U=typeof OffscreenCanvas<"u"?new OffscreenCanvas(y-d,x-p):Object.assign(document.createElement("canvas"),{width:y-d,height:x-p}),F=U.getContext("2d");if(F){F.setTransform(f.a,f.b,f.c,f.d,f.e-d,f.f-p),a(F),t.save();try{if(t.setTransform(1,0,0,1,0,0),typeof t.filter=="string")F.setTransform(1,0,0,1,0,0),F.globalCompositeOperation="source-in",F.fillStyle=e.color,F.fillRect(0,0,U.width,U.height),t.filter=`blur(${A}px)`,t.drawImage(U,d+B,p+z);else {let $=t.canvas.width+1;t.shadowColor=e.color,t.shadowBlur=A*2,t.shadowOffsetX=d+B-$,t.shadowOffsetY=z,t.drawImage(U,$,p);}}finally{t.restore();}}}function fe(t,e){let r=[];for(let n of t)n.type!=="close"&&(n.type==="quad"?r.push([e.x+n.cpx*e.w,e.y+n.cpy*e.h]):n.type==="cubic"&&(r.push([e.x+n.cp1x*e.w,e.y+n.cp1y*e.h]),r.push([e.x+n.cp2x*e.w,e.y+n.cp2y*e.h])),r.push([e.x+n.x*e.w,e.y+n.y*e.h]));return r.filter((n,o)=>o===0||n[0]!==r[o-1][0]||n[1]!==r[o-1][1])}function St(t){return t.path?fe(t.path,t):[[t.x,t.y],[t.x+t.w,t.y],[t.x+t.w,t.y+t.h],[t.x,t.y+t.h]]}var vt=new Set(["triangle","stealth","arrow","diamond","oval"]);function Pt(t,e){let r=e.stroke;if(!r||!r.headEnd&&!r.tailEnd)return;let n=fe(e.path,e);if(n.length<2)return;let o=[[r.headEnd,n[1],n[0]],[r.tailEnd,n[n.length-2],n[n.length-1]]];t.save(),t.setLineDash([]);let i=r.paint?te(t,r.paint,e.x,e.y,e.w,e.h):r.color;t.fillStyle=i,t.strokeStyle=i,t.lineWidth=r.width,t.lineJoin="miter";for(let[a,c,s]of o){if(!a||!vt.has(a.kind))continue;let[u,f]=[s[0]-c[0],s[1]-c[1]],v=Math.hypot(u,f);v<1e-6||xt(t,a,s,u/v,f/v);}t.restore();}function xt(t,e,[r,n],o,i){let a=e.width/2,[c,s]=[-i*a,o*a],[u,f]=[r-o*e.length,n-i*e.length];switch(t.beginPath(),e.kind){case "triangle":t.moveTo(r,n),t.lineTo(u+c,f+s),t.lineTo(u-c,f-s),t.closePath(),t.fill();break;case "stealth":t.moveTo(r,n),t.lineTo(u+c,f+s),t.lineTo(r-o*e.length*.6,n-i*e.length*.6),t.lineTo(u-c,f-s),t.closePath(),t.fill();break;case "arrow":t.moveTo(u+c,f+s),t.lineTo(r,n),t.lineTo(u-c,f-s),t.stroke();break;case "diamond":{let[v,C]=[o*e.length/2,i*e.length/2];t.moveTo(r+v,n+C),t.lineTo(r+c,n+s),t.lineTo(r-v,n-C),t.lineTo(r-c,n-s),t.closePath(),t.fill();break}case "oval":t.ellipse(r,n,e.length/2,a,Math.atan2(i,o),0,Math.PI*2),t.fill();break}}function Ct(t,e,r){let n=r.crop,o=Z(n?.left),i=Z(n?.top),a=1-o-Z(n?.right),c=1-i-Z(n?.bottom),s=r.path!==void 0||a!==1||c!==1;if(a<=0||c<=0)return;s&&(t.save(),De(t,r),t.clip());let u=Tt(e),f=At(e);u>0&&f>0?t.drawImage(e,o*u,i*f,a*u,c*f,r.x,r.y,r.w,r.h):t.drawImage(e,r.x,r.y,r.w,r.h),s&&t.restore();}function De(t,e){e.path?ce(t,e.path,e.x,e.y,e.w,e.h):(t.beginPath(),t.rect(e.x,e.y,e.w,e.h));}function Z(t){return t===void 0||!Number.isFinite(t)?0:Math.min(Math.max(t,0),1)}function Tt(t){return "naturalWidth"in t&&typeof t.naturalWidth=="number"?t.naturalWidth:"width"in t&&typeof t.width=="number"?t.width:0}function At(t){return "naturalHeight"in t&&typeof t.naturalHeight=="number"?t.naturalHeight:"height"in t&&typeof t.height=="number"?t.height:0}function ce(t,e,r,n,o,i){t.beginPath();for(let a of e)switch(a.type){case "move":t.moveTo(r+a.x*o,n+a.y*i);break;case "line":t.lineTo(r+a.x*o,n+a.y*i);break;case "quad":t.quadraticCurveTo(r+a.cpx*o,n+a.cpy*i,r+a.x*o,n+a.y*i);break;case "cubic":t.bezierCurveTo(r+a.cp1x*o,n+a.cp1y*i,r+a.cp2x*o,n+a.cp2y*i,r+a.x*o,n+a.y*i);break;case "close":t.closePath();break}}function Ne(t,e,r,n,o,i){t.strokeStyle=e.paint?te(t,e.paint,r,n,o,i):e.color,t.lineWidth=e.width,t.setLineDash(e.dashed?[Math.max(3,e.width*2),Math.max(2,e.width)]:[]),t.stroke();}function te(t,e,r,n,o,i){if(e.kind==="solid")return e.color;let a=(e.angleDeg??0)*Math.PI/180,c=r+o/2,s=n+i/2,u=Math.hypot(o,i)/2,f=e.gradientType==="linear"?t.createLinearGradient(c-Math.cos(a)*u,s-Math.sin(a)*u,c+Math.cos(a)*u,s+Math.sin(a)*u):t.createRadialGradient(c,s,0,c,s,u);for(let v of e.stops)f.addColorStop(Math.max(0,Math.min(1,v.position)),v.color);return f}async function Et(t,e,r,n,o){let i;if(e.assetId&&r){let a=await r(e.assetId);a&&(i=e.effects?.length?Lt(a,e.effects):a);}e.shadow&&(i||e.stroke)&&Fe(t,e.shadow,St(e),e.stroke?.width??0,n,o,a=>ke(a,e,i)),ke(t,e,i);}function ke(t,e,r){r&&Ct(t,r,e),e.stroke&&(De(t,e),Ne(t,e.stroke,e.x,e.y,e.w,e.h));}var Me=33554432,It=67108864;function Rt(t){let e=t,r=e.naturalWidth??e.videoWidth??e.displayWidth??(typeof e.width=="number"?e.width:0),n=e.naturalHeight??e.videoHeight??e.displayHeight??(typeof e.height=="number"?e.height:0);return r>0&&n>0?{width:r,height:n}:null}function Ut(t){let e=t.width*t.height;if(e<=Me)return t;let r=Math.sqrt(Me/e);return {width:Math.max(1,Math.floor(t.width*r)),height:Math.max(1,Math.floor(t.height*r))}}var de=new WeakMap,W=[],ae=0;function kt(t){let e=t;return "videoWidth"in e||"displayWidth"in e||typeof e.getContext=="function"}function Mt(t,e){let r=de.get(t),n=r?.get(e);if(!r||!n)return;let o=W.findIndex(i=>i.entries===r&&i.key===e);return o>=0&&W.push(...W.splice(o,1)),n}function Ot(t,e,r,n){let o=de.get(t);for(o||(o=new Map,de.set(t,o)),o.set(e,r),W.push({entries:o,key:e,pixels:n}),ae+=n;ae>It&&W.length>1;){let i=W.shift();if(!i)break;i.entries.delete(i.key),ae-=i.pixels;}}function Jt(t,e){if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(t,e);if(typeof document>"u")return null;let r=document.createElement("canvas");return r.width=t,r.height=e,r}function Lt(t,e){let r=Rt(t);if(!r)return t;let n=JSON.stringify(e),o=!kt(t);if(o){let a=Mt(t,n);if(a)return a}let i=Ut(r);try{let a=Jt(i.width,i.height),c=a?.getContext("2d");if(!a||!c)return t;c.drawImage(t,0,0,i.width,i.height);let s=c.getImageData(0,0,i.width,i.height);Dt(s.data,e),c.putImageData(s,0,0);let u=a;return o&&Ot(t,n,u,i.width*i.height),u}catch{return t}}function le(t,e){return .299*t[e]+.587*t[e+1]+.114*t[e+2]}function Ft(t,e){let r=Math.min(Math.max(e,-1),1),n=r>=0?128/(128-127*r):(128+127*r)/128,o=128-128*n+255*Math.min(Math.max(t,-1),1)*(1+n)/2,i=new Uint8ClampedArray(256);for(let a=0;a<256;a+=1)i[a]=Math.round(n*a+o);return i}function ee(t){let e=t.startsWith("#")?t.slice(1):t,r=e.length===3||e.length===4?[...e].map(i=>i+i).join(""):e;if(r.length!==6&&r.length!==8)return null;let n=i=>Number.parseInt(r.slice(i,i+2),16),o=[n(0),n(2),n(4),r.length===8?n(6):255];return o.some(Number.isNaN)?null:o}function Dt(t,e){for(let r of e)switch(r.kind){case "biLevel":{let n=Math.min(Math.max(r.threshold,0),1)*255;for(let o=0;o<t.length;o+=4){let i=le(t,o)<n?0:255;t[o]=i,t[o+1]=i,t[o+2]=i;}break}case "grayscale":{for(let n=0;n<t.length;n+=4){let o=Math.round(le(t,n));t[n]=o,t[n+1]=o,t[n+2]=o;}break}case "luminance":{let n=Ft(r.brightness,r.contrast);for(let o=0;o<t.length;o+=4)t[o]=n[t[o]],t[o+1]=n[t[o+1]],t[o+2]=n[t[o+2]];break}case "duotone":{let n=ee(r.shadow),o=ee(r.highlight);if(!n||!o)break;for(let i=0;i<t.length;i+=4){let a=le(t,i)/255;for(let s=0;s<3;s+=1)t[i+s]=Math.round(n[s]*(1-a)+o[s]*a);let c=n[3]*(1-a)+o[3]*a;t[i+3]=Math.round(t[i+3]*c/255);}break}case "colorChange":{let n=ee(r.from),o=ee(r.to);if(!n||!o)break;for(let i=0;i<t.length;i+=4)t[i]!==n[0]||t[i+1]!==n[1]||t[i+2]!==n[2]||r.useAlpha!==false&&t[i+3]!==n[3]||(t[i]=o[0],t[i+1]=o[1],t[i+2]=o[2],r.useAlpha!==false&&(t[i+3]=o[3]));break}}}function Nt(t,e,r=[]){e.overflow||(t.beginPath(),t.rect(e.x,e.y,e.w,e.h),t.clip()),t.textAlign="left",t.textBaseline="alphabetic";let n=r.filter(o=>o.storyId===e.storyId);Oe(t,e,n,false);for(let o of e.lines)for(let i of o.runs)Bt(t,i,o.baseline);Oe(t,e,n,true);}function Oe(t,e,r,n){if(r.length!==0)for(let o of e.lines)for(let i of o.runs)for(let a of r){let c=Math.max(i.start,a.start),s=Math.min(i.end,a.end);if(c>=s)continue;let u=o.caretStops.filter(T=>T.position>=c&&T.position<=s),f=u.length>1?Math.max(i.x,Math.min(...u.map(T=>T.x))):i.x,v=u.length>1?Math.min(i.x+i.width,Math.max(...u.map(T=>T.x))):i.x+i.width;if(v<=f)continue;let C=a.kind==="insertion";if(n){t.fillStyle=C?"#166534":"#b91c1c";let L=o.baseline-(i.baselineOffsetPx??0)+i.fontSizePx*(C?.08:-0.3);t.fillRect(f,L,v-f,Math.max(1,i.fontSizePx*.05));}else t.fillStyle=C?"#dcfce7cc":"#fee2e2cc",t.fillRect(f,o.y,v-f,o.height);}}function Bt(t,e,r){let n=e.italic?"italic ":"",o=e.bold?"bold ":"";t.font=`${n}${o}${e.fontSizePx}px ${Vt(e.fontFamily)}`,t.fillStyle=e.color;let i=e.letterSpacingPx??0;t.letterSpacing=i===0?"0px":`${i}px`;let a=r-(e.baselineOffsetPx??0);for(let c of Wt(e))t.fillText(c.text,c.x,a);t.letterSpacing="0px",e.underline&&t.fillRect(e.x,a+e.fontSizePx*.08,e.width,Math.max(1,e.fontSizePx*.05));}function Wt(t){if(t.glyphs.length<2)return [{text:t.text,x:t.x}];let e=[],r=0,n=t.x,o=t.glyphs[0].x;for(let i of t.glyphs){let a=i.cluster-t.start;a>r&&a<t.text.length&&Math.abs(i.x-o)>1e-4&&(e.push({text:t.text.slice(r,a),x:n}),r=a,n=i.x),o=Math.fround(Math.fround(i.x)+Math.fround(i.advance));}return e.push({text:t.text.slice(r),x:n}),e}function Vt(t){return t.includes(" ")?JSON.stringify(t):t}function Xt(t,e){t.strokeStyle="#8a94a6",t.lineWidth=1,t.setLineDash([5,4]),t.strokeRect(e.x,e.y,e.w,e.h),e.label&&(t.setLineDash([]),t.fillStyle="#5d6675",t.font="12px sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText(e.label,e.x+e.w/2,e.y+e.h/2,Math.max(0,e.w-12)));}function Be(t){return t.length>=4&&(t[0]===73&&t[1]===73&&t[2]===42&&t[3]===0||t[0]===77&&t[1]===77&&t[2]===0&&t[3]===42)}var I=class t{static __wrap(e){let r=Object.create(t.prototype);return r.__wbg_ptr=e,We.register(r,r.__wbg_ptr,r),r}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,We.unregister(this),e}free(){let e=this.__destroy_into_raw();l.__wbg_pptxdocument_free(e,0);}acceptProposalJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_acceptProposalJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}addCommentJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_addCommentJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}addShapeJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_addShapeJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}addTextBoxJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_addTextBoxJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}applyUpdateJson(e){let r,n;try{let a=J(e,l.__wbindgen_malloc),c=b,s=l.pptxdocument_applyUpdateJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}canRedo(){return l.pptxdocument_canRedo(this.__wbg_ptr)!==0}canUndo(){return l.pptxdocument_canUndo(this.__wbg_ptr)!==0}clearUpdateObservation(){l.pptxdocument_clearUpdateObservation(this.__wbg_ptr);}get clientId(){return l.pptxdocument_clientId(this.__wbg_ptr)}commentsJson(){let e,r;try{let i=l.pptxdocument_commentsJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{l.__wbindgen_free(e,r,1);}}deleteSlideJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_deleteSlideJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}deleteTextJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_deleteTextJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}drainUpdateEvent(){let e=l.pptxdocument_drainUpdateEvent(this.__wbg_ptr);var r=O(e[0],e[1]).slice();return l.__wbindgen_free(e[0],e[1]*1,1),r}encodeDiff(e){let r=J(e,l.__wbindgen_malloc),n=b,o=l.pptxdocument_encodeDiff(this.__wbg_ptr,r,n);if(o[3])throw h(o[2]);var i=O(o[0],o[1]).slice();return l.__wbindgen_free(o[0],o[1]*1,1),i}encodeStateAsUpdate(){let e=l.pptxdocument_encodeStateAsUpdate(this.__wbg_ptr);var r=O(e[0],e[1]).slice();return l.__wbindgen_free(e[0],e[1]*1,1),r}encodeStateVector(){let e=l.pptxdocument_encodeStateVector(this.__wbg_ptr);var r=O(e[0],e[1]).slice();return l.__wbindgen_free(e[0],e[1]*1,1),r}formatTextJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_formatTextJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}insertParagraphBreakJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_insertParagraphBreakJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}insertSlideJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_insertSlideJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}insertTextJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_insertTextJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}listProposalsJson(){let e,r;try{let i=l.pptxdocument_listProposalsJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{l.__wbindgen_free(e,r,1);}}mediaBytes(e){let r=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),n=b,o=l.pptxdocument_mediaBytes(this.__wbg_ptr,r,n);if(o[3])throw h(o[2]);var i=O(o[0],o[1]).slice();return l.__wbindgen_free(o[0],o[1]*1,1),i}moveShapeJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_moveShapeJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}moveSlideJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_moveSlideJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}static openCollaborative(e,r){let n=J(e,l.__wbindgen_malloc),o=b,i=l.pptxdocument_openCollaborative(n,o,r);if(i[2])throw h(i[1]);return t.__wrap(i[0])}static openCollaborativeFromUpdate(e,r,n){let o=J(e,l.__wbindgen_malloc),i=b;var a=$t(n)?0:J(n,l.__wbindgen_malloc),c=b;let s=l.pptxdocument_openCollaborativeFromUpdate(o,i,r,a,c);if(s[2])throw h(s[1]);return t.__wrap(s[0])}previewProposalJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_previewProposalJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}proposeJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_proposeJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}redoJson(){let e,r;try{let i=l.pptxdocument_redoJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{l.__wbindgen_free(e,r,1);}}rejectProposalJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_rejectProposalJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}removeCommentJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_removeCommentJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}removeShapeJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_removeShapeJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}replyToCommentJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_replyToCommentJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}resizeShapeJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_resizeShapeJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}saveBytes(){let e=l.pptxdocument_saveBytes(this.__wbg_ptr);if(e[3])throw h(e[2]);var r=O(e[0],e[1]).slice();return l.__wbindgen_free(e[0],e[1]*1,1),r}setCommentFlavorJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setCommentFlavorJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}setCommentStatusJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setCommentStatusJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}setParagraphAlignmentJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setParagraphAlignmentJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}setShapeAdjustJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setShapeAdjustJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}setShapeFillJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setShapeFillJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}setShapeRectJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setShapeRectJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}setShapeStrokeJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setShapeStrokeJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}setSlideNotesJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setSlideNotesJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}snapshotJson(){let e,r;try{let i=l.pptxdocument_snapshotJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{l.__wbindgen_free(e,r,1);}}startUpdateObservation(){let e=l.pptxdocument_startUpdateObservation(this.__wbg_ptr);if(e[1])throw h(e[0])}storyJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_storyJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}undoJson(){let e,r;try{let i=l.pptxdocument_undoJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{l.__wbindgen_free(e,r,1);}}static version(){let e,r;try{let n=l.pptxdocument_version();return e=n[0],r=n[1],g(n[0],n[1])}finally{l.__wbindgen_free(e,r,1);}}};Symbol.dispose&&(I.prototype[Symbol.dispose]=I.prototype.free);var D=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,Ve.unregister(this),e}free(){let e=this.__destroy_into_raw();l.__wbg_pptxrenderer_free(e,0);}hitTestJson(e,r){let n,o;try{let c=l.pptxrenderer_hitTestJson(this.__wbg_ptr,e,r);var i=c[0],a=c[1];if(c[3])throw i=0,a=0,h(c[2]);return n=i,o=a,g(i,a)}finally{l.__wbindgen_free(n,o,1);}}layoutProposalDiffSlideJson(e,r,n){let o,i;try{he(e,I);let s=w(r,l.__wbindgen_malloc,l.__wbindgen_realloc),u=b,f=l.pptxrenderer_layoutProposalDiffSlideJson(this.__wbg_ptr,e.__wbg_ptr,s,u,n);var a=f[0],c=f[1];if(f[3])throw a=0,c=0,h(f[2]);return o=a,i=c,g(a,c)}finally{l.__wbindgen_free(o,i,1);}}layoutProposalSlideJson(e,r,n){let o,i;try{he(e,I);let s=w(r,l.__wbindgen_malloc,l.__wbindgen_realloc),u=b,f=l.pptxrenderer_layoutProposalSlideJson(this.__wbg_ptr,e.__wbg_ptr,s,u,n);var a=f[0],c=f[1];if(f[3])throw a=0,c=0,h(f[2]);return o=a,i=c,g(a,c)}finally{l.__wbindgen_free(o,i,1);}}layoutSlideJson(e,r){let n,o;try{he(e,I);let c=l.pptxrenderer_layoutSlideJson(this.__wbg_ptr,e.__wbg_ptr,r);var i=c[0],a=c[1];if(c[3])throw i=0,a=0,h(c[2]);return n=i,o=a,g(i,a)}finally{l.__wbindgen_free(n,o,1);}}constructor(){let e=l.pptxrenderer_new();return this.__wbg_ptr=e,Ve.register(this,this.__wbg_ptr,this),this}registerFont(e,r,n,o){let i=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),a=b,c=J(o,l.__wbindgen_malloc),s=b,u=l.pptxrenderer_registerFont(this.__wbg_ptr,i,a,r,n,c,s);if(u[2])throw h(u[1]);return u[0]>>>0}};Symbol.dispose&&(D.prototype[Symbol.dispose]=D.prototype.free);function Xe(t){let e=J(t,l.__wbindgen_malloc),r=b,n=l.decodeTiffPng(e,r);if(n[3])throw h(n[2]);var o=O(n[0],n[1]).slice();return l.__wbindgen_free(n[0],n[1]*1,1),o}function je(t){let e,r;try{let i=J(t,l.__wbindgen_malloc),a=b,c=l.parsePptxJson(i,a);var n=c[0],o=c[1];if(c[3])throw n=0,o=0,h(c[2]);return e=n,r=o,g(n,o)}finally{l.__wbindgen_free(e,r,1);}}function He(){let t,e;try{let r=l.rendererVersion();return t=r[0],e=r[1],g(r[0],r[1])}finally{l.__wbindgen_free(t,e,1);}}function jt(){return {__proto__:null,"./pptx_wasm_bg.js":{__proto__:null,__wbg___wbindgen_throw_344f42d3211c4765:function(e,r){throw new Error(g(e,r))},__wbg_getRandomValues_3f44b700395062e5:function(){return zt(function(e,r){globalThis.crypto.getRandomValues(O(e,r));},arguments)},__wbindgen_cast_0000000000000001:function(e,r){return g(e,r)},__wbindgen_init_externref_table:function(){let e=l.__wbindgen_externrefs,r=e.grow(4);e.set(0,void 0),e.set(r+0,void 0),e.set(r+1,null),e.set(r+2,true),e.set(r+3,false);}}}}var We=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(t=>l.__wbg_pptxdocument_free(t,1)),Ve=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(t=>l.__wbg_pptxrenderer_free(t,1));function Ht(t){let e=l.__externref_table_alloc();return l.__wbindgen_externrefs.set(e,t),e}function he(t,e){if(!(t instanceof e))throw new Error(`expected instance of ${e.name}`)}function O(t,e){return t=t>>>0,V().subarray(t/1,t/1+e)}function g(t,e){return Gt(t>>>0,e)}var q=null;function V(){return (q===null||q.byteLength===0)&&(q=new Uint8Array(l.memory.buffer)),q}function zt(t,e){try{return t.apply(this,e)}catch(r){let n=Ht(r);l.__wbindgen_exn_store(n);}}function $t(t){return t==null}function J(t,e){let r=e(t.length*1,1)>>>0;return V().set(t,r/1),b=t.length,r}function w(t,e,r){if(r===void 0){let c=G.encode(t),s=e(c.length,1)>>>0;return V().subarray(s,s+c.length).set(c),b=c.length,s}let n=t.length,o=e(n,1)>>>0,i=V(),a=0;for(;a<n;a++){let c=t.charCodeAt(a);if(c>127)break;i[o+a]=c;}if(a!==n){a!==0&&(t=t.slice(a)),o=r(o,n,n=a+t.length*3,1)>>>0;let c=V().subarray(o+a,o+n),s=G.encodeInto(t,c);a+=s.written,o=r(o,n,a,1)>>>0;}return b=a,o}function h(t){let e=l.__wbindgen_externrefs.get(t);return l.__externref_table_dealloc(t),e}var ne=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true});ne.decode();var qt=2146435072,me=0;function Gt(t,e){return me+=e,me>=qt&&(ne=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}),ne.decode(),me=e),ne.decode(V().subarray(t,t+e))}var G=new TextEncoder;"encodeInto"in G||(G.encodeInto=function(t,e){let r=G.encode(t);return e.set(r),{read:t.length,written:r.length}});var b=0,l;function Qt(t,e){return l=t.exports,q=null,l.__wbindgen_start(),l}async function Zt(t,e){if(typeof Response=="function"&&t instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(t,e)}catch(o){if(t.ok&&r(t.type)&&t.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",o);else throw o}let n=await t.arrayBuffer();return await WebAssembly.instantiate(n,e)}else {let n=await WebAssembly.instantiate(t,e);return n instanceof WebAssembly.Instance?{instance:n,module:t}:n}function r(n){switch(n){case "basic":case "cors":case "default":return true}return false}}async function ze(t){if(l!==void 0)return l;if(t!==void 0&&(Object.getPrototypeOf(t)===Object.prototype?{module_or_path:t}=t:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),t===void 0)throw new Error("pptx-wasm requires an explicit module or URL");let e=jt();(typeof t=="string"||typeof Request=="function"&&t instanceof Request||typeof URL=="function"&&t instanceof URL)&&(t=fetch(t));let{instance:r,module:n}=await Zt(await t,e);return Qt(r)}var Y=class extends Error{constructor(r){super(`Proposal targets changed: ${r.join(", ")}`);m(this,"targets");this.name="StaleProposalError",this.targets=r;}};var _e=false;function ge(){return typeof I.prototype.proposeJson=="function"&&typeof D.prototype.layoutProposalSlideJson=="function"}var K;function en(t=new URL("./generated/pptx_wasm_bg.wasm",import.meta.url)){return _e?Promise.resolve():K||(K=ze({module_or_path:t}).then(()=>{_e=true;},e=>{throw K=void 0,X(e)}),K)}function tn(){return typeof WebAssembly=="object"}function nn(){return re(),He()}function rn(t){return re(),ln(()=>je(t))}function qe(t){return re(),be(()=>Xe(t))}function on(t,e={}){re();let r=e.clientId??sn(),n=be(()=>e.initialUpdate===void 0?I.openCollaborative(t,r):I.openCollaborativeFromUpdate(e.initialUpdate.slice(),r,t.slice())),o=be(()=>new D);for(let d of e.fonts??[])$e(o,d);let i=new Map,a=[],c=0,s=false,u=false,f=0,v=false,C=()=>{if(s)throw new Error("presentation handle is disposed")},T=()=>{if(!(s||v||f!==0)){v=true;try{for(;!s&&a.length>0;){let d=a.shift();if(!d)break;for(let[p,y]of [...i]){if(s)return;if(i.get(p)===y)try{y(d.update.slice(),d.origin);}catch{}}}}finally{v=false,s&&(a.length=0);}}},L=()=>{if(!(!u||s))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.subarray(1),origin:p===0?"local":"remote"});}},A=(d,p=false)=>{C(),f+=1;try{let y,x,M=!1;try{y=d();}catch(U){x=U,M=!0;}if(p)try{L();}catch(U){M||(x=U,M=!0);}if(M)throw X(x);return y}finally{f-=1,f===0&&T();}},_=(d,p=false)=>A(()=>JSON.parse(d()),p),N=()=>{u||(A(()=>n.startUpdateObservation()),u=true);},B=()=>{!u||i.size>0||s||(a.length=0,A(()=>n.clearUpdateObservation()),u=false);};return {isProposalsAvailable:ge,propose(d,p,y){return _(()=>n.proposeJson(JSON.stringify({agentId:d,note:p,edits:y})))},listProposals(){return ge()?_(()=>n.listProposalsJson()):[]},previewProposal(d){return _(()=>n.previewProposalJson(JSON.stringify({id:d})))},layoutProposalDiffSlide(d,p){return _(()=>o.layoutProposalDiffSlideJson(n,d,p))},layoutProposalSlide(d,p){return _(()=>o.layoutProposalSlideJson(n,d,p))},acceptProposal(d,p){return _(()=>n.acceptProposalJson(JSON.stringify({id:d,force:p?.force??false})),true)},rejectProposal(d){return _(()=>n.rejectProposalJson(JSON.stringify({id:d})))},get clientId(){return A(()=>n.clientId)},snapshot(){return _(()=>n.snapshotJson())},story(d){return _(()=>n.storyJson(JSON.stringify({storyId:d})))},registerFont(d){return A(()=>$e(o,d))},layoutSlide(d){return _(()=>o.layoutSlideJson(n,d))},hitTest(d,p){return _(()=>o.hitTestJson(d,p))},mediaBytes(d){return A(()=>n.mediaBytes(d))},save(){return A(()=>n.saveBytes())},insertText(d,p,y,x={}){return _(()=>n.insertTextJson(JSON.stringify({storyId:d,index:p,text:y,style:x})),true)},deleteText(d,p,y){return _(()=>n.deleteTextJson(JSON.stringify({storyId:d,start:p,end:y})),true)},formatText(d,p,y,x){return _(()=>n.formatTextJson(JSON.stringify({storyId:d,start:p,end:y,patch:x})),true)},insertParagraphBreak(d,p){return _(()=>n.insertParagraphBreakJson(JSON.stringify({storyId:d,index:p})),true)},setParagraphAlignment(d,p,y,x){return _(()=>n.setParagraphAlignmentJson(JSON.stringify({storyId:d,start:p,end:y,alignment:x})),true)},insertSlide(d,p){return _(()=>n.insertSlideJson(JSON.stringify({index:d,layoutPartPath:p??null})),true)},deleteSlide(d){return _(()=>n.deleteSlideJson(JSON.stringify({slideId:d})),true)},moveSlide(d,p){return _(()=>n.moveSlideJson(JSON.stringify({slideId:d,toIndex:p})),true)},setSlideNotes(d,p){_(()=>n.setSlideNotesJson(JSON.stringify({slideId:d,text:p})),true);},addComment(d,p){return _(()=>n.addCommentJson(JSON.stringify({slideId:d,author:p.author,initials:p.initials??"",text:p.text,created:p.created,xEmu:p.xEmu??0,yEmu:p.yEmu??0})),true)},replyToComment(d,p){return _(()=>n.replyToCommentJson(JSON.stringify({commentId:d,author:p.author,initials:p.initials??"",text:p.text,created:p.created})),true)},setCommentStatus(d,p){return _(()=>n.setCommentStatusJson(JSON.stringify({commentId:d,resolved:p})),true)},removeComment(d){return _(()=>n.removeCommentJson(JSON.stringify({commentId:d})),true)},setCommentFlavor(d){return _(()=>n.setCommentFlavorJson(JSON.stringify({flavor:d})),true)},comments(){return _(()=>n.commentsJson())},addTextBox(d,p){return _(()=>n.addTextBoxJson(JSON.stringify({slideId:d,draft:p})),true)},addShape(d,p){return _(()=>n.addShapeJson(JSON.stringify({slideId:d,draft:p})),true)},setShapeFill(d,p,y){return _(()=>n.setShapeFillJson(JSON.stringify({slideId:d,shapeId:p,color:y})),true)},setShapeStroke(d,p,y){return _(()=>n.setShapeStrokeJson(JSON.stringify({slideId:d,shapeId:p,stroke:y})),true)},setShapeAdjust(d,p,y){return _(()=>n.setShapeAdjustJson(JSON.stringify({slideId:d,shapeId:p,adjustments:y})),true)},removeShape(d,p){return _(()=>n.removeShapeJson(JSON.stringify({slideId:d,shapeId:p})),true)},moveShape(d,p,y,x){return _(()=>n.moveShapeJson(JSON.stringify({slideId:d,shapeId:p,x:y,y:x})),true)},resizeShape(d,p,y,x){return _(()=>n.resizeShapeJson(JSON.stringify({slideId:d,shapeId:p,width:y,height:x})),true)},setShapeRect(d,p,y){return _(()=>n.setShapeRectJson(JSON.stringify({slideId:d,shapeId:p,rect:y})),true)},canUndo(){return A(()=>n.canUndo())},canRedo(){return A(()=>n.canRedo())},undo(){return _(()=>n.undoJson(),true)},redo(){return _(()=>n.redoJson(),true)},encodeStateVector(){return A(()=>n.encodeStateVector())},encodeStateAsUpdate(d){return A(()=>d===void 0?n.encodeStateAsUpdate():n.encodeDiff(d))},encodeDiff(d){return A(()=>n.encodeDiff(d))},applyUpdate(d){return _(()=>n.applyUpdateJson(d),true)},onUpdate(d){if(C(),typeof d!="function")throw new TypeError("update listener must be a function");let p=c++;i.set(p,d);try{N();}catch(x){throw i.delete(p),x}let y=true;return ()=>{y&&(y=false,i.delete(p),B());}},dispose(){if(s)return;s=true,i.clear(),a.length=0;let d;if(u){try{n.clearUpdateObservation();}catch(p){d=p;}u=false;}try{o.free();}catch(p){d??(d=p);}try{n.free();}catch(p){d??(d=p);}if(d!==void 0)throw X(d)}}}function $e(t,e){try{return t.registerFont(e.family,e.bold??!1,e.italic??!1,e.bytes)}catch(r){throw X(r)}}function re(){if(!_e)throw new Error("pptx wasm is not initialized; call initWasm() first")}function sn(){let t=globalThis.crypto;if(!t||typeof t.getRandomValues!="function")throw new Error("crypto.getRandomValues is required to generate a collaboration client ID");let e=new Uint32Array(2),r;do t.getRandomValues(e),r=(e[0]&2097151)*4294967296+e[1];while(r===0);return r}function be(t){try{return t()}catch(e){throw X(e)}}function an(t){try{return JSON.parse(t())}catch(e){throw X(e)}}function ln(t){return an(t)}function X(t){if(t instanceof Error)return t;if(typeof t=="string")try{let e=JSON.parse(t);if(e.code==="staleProposal"&&Array.isArray(e.targets)&&e.targets.every(r=>typeof r=="string"))return new Y(e.targets)}catch{}return new Error(typeof t=="string"?t:String(t))}var dn=33554432;function pn(t){if(Be(t)){if(t.byteLength>33554432)throw new Error("TIFF image exceeds the browser transfer budget");return new Blob([qe(t).slice()],{type:"image/png"})}let e=un(t);return e?new Blob([e],{type:"image/bmp"}):new Blob([t.slice()])}function un(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength);if(e.byteLength<18)return;let r=e.getUint32(0,true)===2596720087?22:0;if(e.byteLength<r+18||![1,2].includes(e.getUint16(r,true))||e.getUint16(r+2,true)!==9||e.getUint16(r+4,true)!==768||e.getUint32(r+6,true)*2!==e.byteLength-r)return;let n=0,o=0,i=0,a=0,c=false,s;for(let u=r+18;u+6<=e.byteLength;){let f=e.getUint32(u,true)*2,v=e.getUint16(u+4,true);if(f<6||f>e.byteLength-u)return;if(v===0)return f===6&&u+f===e.byteLength?s:void 0;if(s)return;if(v===259){if(f<8||e.getUint16(u+6,true)!==8)return;c=true;}else if(v===263){if(f<8||![1,2,3,4].includes(e.getUint16(u+6,true)))return}else if(v===523||v===524){if(f!==10)return;let C=e.getInt16(u+6,true),T=e.getInt16(u+8,true);if(v===523)n=T,o=C;else {if(!c)return;i=T,a=C;}}else if(v===2881){if(f<66||e.getUint32(u+6,true)!==13369376||e.getInt16(u+14,true)!==0||e.getInt16(u+16,true)!==0||e.getInt16(u+18,true)!==a||e.getInt16(u+20,true)!==i||e.getInt16(u+22,true)!==o||e.getInt16(u+24,true)!==n||!i||!a||(s=fn(t.subarray(u+26,u+f),e.getInt16(u+12,true),e.getInt16(u+10,true)),!s))return}else return;u+=f;}}function fn(t,e,r){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),o=n.getInt32(4,true),i=n.getInt32(8,true),a=n.getUint16(14,true);if(n.getUint32(0,true)!==40||o<1||!i||o*Math.abs(i)>dn||e!==o||r!==Math.abs(i)||n.getUint16(12,true)!==1||![24,32].includes(a)||n.getUint32(16,true)!==0||n.getUint32(32,true)!==0)return;let c=Math.ceil(o*a/32)*4*Math.abs(i),s=n.getUint32(20,true);if(40+c!==t.length||s!==0&&s!==c)return;let u=new Uint8Array(14+t.length),f=new DataView(u.buffer);return f.setUint16(0,19778,true),f.setUint32(2,u.length,true),f.setUint32(10,54,true),u.set(t,14),u}async function hn(t,e={}){let{scale:r=1,resolveImage:n}=e;if(!Number.isFinite(r)||r<=0)throw new Error("scale must be finite and positive");let o=mn(t,r),i=o.getContext("2d");if(!i)throw new Error("2d canvas context unavailable");return await ue(i,t,1,r,{resolveImage:n}),_n(o)}function mn(t,e){let r=Math.round(t.width*e),n=Math.round(t.height*e);if(typeof OffscreenCanvas=="function")return new OffscreenCanvas(r,n);if(typeof document>"u")throw new Error("no canvas backend in this environment");let o=document.createElement("canvas");return pe(o,t,1,e),o}function _n(t){return "convertToBlob"in t?t.convertToBlob({type:"image/png"}):new Promise((e,r)=>{t.toBlob(n=>{n?e(n):r(new Error("canvas produced no png"));},"image/png");})}var Ye=3e3;var Ge=["#B3261E","#7B1FA2","#3949AB","#00796B","#2E7D32","#A84400","#C2185B","#00695C"],gn=/^#[0-9a-fA-F]+$/;function ye(t){return Ge[Math.abs(t)%Ge.length]}function we(t,e){return typeof e=="string"&&(e.length===4||e.length===7)&&gn.test(e)?e:ye(t)}function Ke(t,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 r=e?.name.trim().slice(0,1024)||`Guest ${t.toString(36).toUpperCase()}`,n=we(t,e?.color);return {name:r,color:n}}function Se(t,e){return t?.slideId===e?.slideId&&t?.shapeId===e?.shapeId}var oe=class{constructor(e,r={}){m(this,"localClientId",e);m(this,"states",new Map);m(this,"clocks",new Map);m(this,"maxTrackedIds");if(this.maxTrackedIds=r.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,r)=>e.state.clientId-r.state.clientId).map(bn)}get trackedIdCount(){return this.clocks.size}get nextExpiryAt(){let e;for(let r of this.states.values()){let n=r.lastSeen+45e3;e=e===void 0?n:Math.min(e,n);}for(let r of this.clocks.values()){let n=r.updatedAt+3e5;e=e===void 0?n:Math.min(e,n);}return e}apply(e,r){let n=this.expire(r);for(let o of e){if(o.clientId===this.localClientId)continue;let i=this.clocks.get(o.clientId);if(i&&o.clock<=i.clock)continue;if(!i&&this.clocks.size>=this.maxTrackedIds&&(n=this.evictOldest()||n),this.clocks.delete(o.clientId),this.clocks.set(o.clientId,{clock:o.clock,updatedAt:r}),!o.state){n=this.states.delete(o.clientId)||n;continue}let a=this.states.get(o.clientId),c=a&&Se(a.state.cursor,o.state.cursor)?a.cursorMovedAt:r;this.states.set(o.clientId,{state:Qe(o.state),lastSeen:r,cursorMovedAt:c}),n=true;}return n}expire(e,r=45e3){let n=false;for(let[o,i]of this.states)e-i.lastSeen<r||(this.states.delete(o),n=true);for(let[o,i]of this.clocks)e-i.updatedAt<3e5||(this.clocks.delete(o),n=this.states.delete(o)||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 Qe(t){return {clientId:t.clientId,clock:t.clock,user:{...t.user},cursor:t.cursor?{...t.cursor}:null}}function bn(t){return {state:Qe(t.state),lastSeen:t.lastSeen,cursorMovedAt:t.cursorMovedAt}}var k=16777216,H=4096,et=0,tt=1,wn=2,nt=3,rt=0,ot=1,it=2,Sn=0,vn=Number.MAX_SAFE_INTEGER,S=class extends Error{constructor(e){super(e),this.name="ProtocolError";}},ie=class{constructor(e){m(this,"bytes",e);m(this,"offset",0);}get done(){return this.offset===this.bytes.byteLength}readVarUint(){let e=0,r=1,n=0;for(;;){if(this.offset>=this.bytes.byteLength)throw new S("Truncated varUint");let o=this.bytes[this.offset++],i=o&127;if(i>Math.floor((vn-e)/r))throw new S("varUint exceeds Number.MAX_SAFE_INTEGER");if(e+=i*r,n+=1,(o&128)===0){if(n>1&&i===0)throw new S("Non-canonical varUint");return e}if(n>=8)throw new S("varUint exceeds Number.MAX_SAFE_INTEGER");r*=128;}}readVarUint8Array(){let e=this.readVarUint(),r=this.bytes.byteLength-this.offset;if(e>r)throw new S("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(r){throw new S(`Invalid UTF-8 string${r instanceof Error?`: ${r.message}`:""}`)}}};function R(t){if(!Number.isSafeInteger(t)||t<0)throw new S("varUint value must be a non-negative safe integer");let e=[],r=t;for(;r>=128;)e.push(r%128|128),r=Math.floor(r/128);return e.push(r),Uint8Array.from(e)}function Pn(t){let e=new TextEncoder().encode(t);return Q([R(e.byteLength),e],k)}function Q(t,e){let r=0;for(let i of t)if(r+=i.byteLength,r>e)throw new S(`Frame exceeds ${e} bytes`);let n=new Uint8Array(r),o=0;for(let i of t)n.set(i,o),o+=i.byteLength;return n}function xe(t,e,r){return Q([R(et),R(t),R(e.byteLength),e],r)}function st(t,e=k){return xe(rt,t,e)}function at(t,e=k){return xe(ot,t,e)}function lt(t,e=k){return xe(it,t,e)}function ct(t,e=k){if(t.length>H)throw new S(`Awareness update exceeds ${H} entries`);let r=[R(t.length)];for(let o of t){ht(o);let i=JSON.stringify(o.state);if(i===void 0)throw new S("Awareness state is not JSON serializable");r.push(R(o.clientId),R(o.clock),Pn(i));}let n=Q(r,e);return Q([R(tt),R(n.byteLength),n],e)}function dt(t=k){return Q([R(nt)],t)}function pt(t,e=H){if(!(t instanceof Uint8Array))throw new S("Awareness update must be a Uint8Array");if(!Number.isSafeInteger(e)||e<1)throw new S("Awareness entry limit must be a positive integer");let r=new ie(t),n=r.readVarUint();if(n>e)throw new S(`Awareness update exceeds ${e} entries`);let o=[];for(let i=0;i<n;i+=1){let a=r.readVarUint(),c=r.readVarUint(),s;try{s=JSON.parse(r.readVarString());}catch(f){throw f instanceof S?f:new S(`Invalid awareness JSON${f instanceof Error?`: ${f.message}`:""}`)}let u={clientId:a,clock:c,state:ft(s,a,c)};ht(u),o.push(u);}if(!r.done)throw new S("Awareness update has trailing bytes");return o}function ut(t,e=k,r=H){if(!(t instanceof Uint8Array))throw new S("Frame must be a Uint8Array");if(t.byteLength===0)throw new S("Frame is empty");if(t.byteLength>e)throw new S(`Frame exceeds ${e} bytes`);if(!Number.isSafeInteger(r)||r<1)throw new S("Message limit must be a positive integer");let n=new ie(t),o=[];for(;!n.done;){if(o.length>=r)throw new S(`Frame exceeds ${r} messages`);let i=n.readVarUint();switch(i){case et:{let a=n.readVarUint(),c=n.readVarUint8Array();if(a===rt)o.push({type:"sync-step-1",stateVector:c});else if(a===ot)o.push({type:"sync-step-2",update:c});else if(a===it)o.push({type:"update",update:c});else throw new S(`Unknown sync message type ${a}`);break}case tt:o.push({type:"awareness",update:n.readVarUint8Array()});break;case wn:{let a=n.readVarUint();if(a!==Sn)throw new S(`Unknown auth message type ${a}`);o.push({type:"auth",reason:n.readVarString()});break}case nt:o.push({type:"query-awareness"});break;default:throw new S(`Unknown top-level message type ${i}`)}}return o}function ft(t,e,r){if(t===null)return null;if(!Pe(t))throw new S("Awareness state must be an object or null");if(t.clientId!==e||t.clock!==r)throw new S("Awareness state identity does not match its entry");if(!Pe(t.user))throw new S("Awareness user must be an object");let n=ve(t.user.name,"Awareness user name"),o=we(e,t.user.color);return {clientId:e,clock:r,user:{name:n,color:o},cursor:xn(t.cursor)}}function xn(t){if(t==null)return null;if(!Pe(t))throw new S("Awareness cursor must be an object or null");let e=ve(t.slideId,"Awareness slideId"),r=t.shapeId===void 0?void 0:ve(t.shapeId,"Awareness shapeId");return r?{slideId:e,shapeId:r}:{slideId:e}}function ht(t){Ze(t.clientId,"Awareness clientId"),Ze(t.clock,"Awareness clock"),t.state!==null&&ft(t.state,t.clientId,t.clock);}function Ze(t,e){if(!Number.isSafeInteger(t)||t<0)throw new S(`${e} must be a non-negative safe integer`)}function ve(t,e){if(typeof t!="string"||t.length===0||t.length>1024)throw new S(`${e} must be between 1 and ${1024} characters`);return t}function Pe(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}var E=class extends Error{constructor(r,n,o){super(n);m(this,"code");m(this,"cause");this.name="CollaborationError",this.code=r,this.cause=o;}};var An=16*1024*1024,Ce=new TextEncoder().encode("\0betteroffice-document-fingerprint-v1\0");function Te(t,e,r){if(!Number.isSafeInteger(e)||e<(r?0:1))throw new RangeError(`${t} must be ${r?"a non-negative":"a positive"} integer`);return e}function En(t){return t instanceof Error&&t.message?t.message:typeof t=="string"&&t?t:"Unknown error"}function P(t,e,r){return r instanceof E?r:new E(t,`${e}: ${En(r)}`,r)}function Ae(t,e){if(!(t instanceof Uint8Array))throw new TypeError(`${e} must return a Uint8Array`);return t.slice()}function mt(t){let e=Ce.byteLength+32,r=t.byteLength-e;if(r<0)return t;for(let n=0;n<Ce.byteLength;n+=1)if(t[r+n]!==Ce[n])return t;return t.subarray(0,r)}function Ee(t){typeof t=="object"&&t&&"unref"in t&&t.unref();}function In(t){if(!Number.isSafeInteger(t)||t<0)throw new RangeError("Replica clientId must be a non-negative safe integer");return t}function Rn(t){if(t===null)return null;if(!t||typeof t.slideId!="string"||t.slideId.length===0)throw new TypeError("Presence cursor slideId must be a non-empty string");if(t.shapeId!==void 0&&(typeof t.shapeId!="string"||t.shapeId.length===0))throw new TypeError("Presence cursor shapeId must be a non-empty string");return t.shapeId?{slideId:t.slideId,shapeId:t.shapeId}:{slideId:t.slideId}}function Un(t){return t.slideId.length<=1024&&(t.shapeId===void 0||t.shapeId.length<=1024)}var se=class{constructor(e,r,n={}){m(this,"replica");m(this,"transport");m(this,"maxFrameBytes");m(this,"maxMessagesPerFrame");m(this,"maxPendingBytes");m(this,"localClientId");m(this,"localUser");m(this,"remotePresence");m(this,"statusListeners",new Map);m(this,"errorListeners",new Map);m(this,"presenceListeners",new Map);m(this,"pendingFrames",[]);m(this,"unsubscribeReplica");m(this,"unsubscribeTransport",()=>{});m(this,"hasTransportSubscription",false);m(this,"connectionStatus","disconnected");m(this,"isSynced",false);m(this,"wantsConnection",false);m(this,"isOpen",false);m(this,"isDestroyed",false);m(this,"epoch",0);m(this,"connectAttempt",0);m(this,"nextListenerId",0);m(this,"queuedBytes",0);m(this,"isFlushing",false);m(this,"localClock",0);m(this,"reportedClockExhaustion",false);m(this,"localCursor",null);m(this,"lastAwarenessSentAt",0);m(this,"cursorTimer",null);m(this,"heartbeatTimer",null);m(this,"expiryTimer",null);this.replica=e,this.transport=r,this.localClientId=In(e.clientId),this.localUser=Ke(this.localClientId,n.user),this.remotePresence=new oe(this.localClientId),this.maxFrameBytes=Te("maxFrameBytes",n.maxFrameBytes??k,false),this.maxMessagesPerFrame=Te("maxMessagesPerFrame",n.maxMessagesPerFrame??H,false),this.maxPendingBytes=Te("maxPendingBytes",n.maxPendingBytes??An,true);try{this.unsubscribeReplica=e.onUpdate((o,i)=>{i==="local"&&this.forwardLocalUpdate(o);});}catch(o){throw P("replica","Failed to observe replica updates",o)}}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 r=Rn(e),n=!r||Un(r)?r:null;r&&!n&&this.report(new E("protocol",`Presence cursor identifiers exceed ${1024} characters; cursor dropped`)),!Se(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,r=++this.connectAttempt;if(this.setStatus("connecting",false),!!this.isCurrent(e)){if(!this.hasTransportSubscription){let n;try{if(n=this.transport.onEvent(o=>this.handleTransportEvent(e,o)),typeof n!="function")throw new TypeError("Transport event subscription must return a function")}catch(o){this.failConnection(e,P("transport","Failed to subscribe to transport events",o));return}if(!this.isCurrent(e)){try{n();}catch(o){this.isDestroyed||this.report(P("transport","Failed to unsubscribe from stale transport events",o));}return}this.unsubscribeTransport=n,this.hasTransportSubscription=true;}try{let n=this.transport.connect();n&&n.catch(o=>{this.isCurrent(e)&&this.connectAttempt===r&&this.failConnection(e,P("transport","Transport connect failed",o));});}catch(n){this.failConnection(e,P("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 o=this.epoch;if(this.broadcastLocalPresence(true),!this.isCurrent(o))return}this.stopPresenceTimers(),this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let r=this.takeTransportSubscription();this.clearPending(),this.clearRemotePresence();let n=this.cleanupTransport(r,true);this.setStatus("disconnected",false);for(let o of n)this.report(o);}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 r=this.takeTransportSubscription();this.clearPending(),this.clearRemotePresence();let n=this.cleanupTransport(r,e);this.setStatus("destroyed",false);for(let o of n)this.report(o);try{this.unsubscribeReplica();}catch(o){this.report(P("replica","Failed to unsubscribe from replica updates",o));}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 r=this.nextListenerId++;return this.statusListeners.set(r,e),()=>this.statusListeners.delete(r)}onError(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("error listener must be a function");let r=this.nextListenerId++;return this.errorListeners.set(r,e),()=>this.errorListeners.delete(r)}onPresence(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("presence listener must be a function");let r=this.nextListenerId++;this.presenceListeners.set(r,e);try{e(this.peers);}catch{}return ()=>this.presenceListeners.delete(r)}isCurrent(e){return !this.isDestroyed&&this.wantsConnection&&e===this.epoch}failConnection(e,r){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 o=this.cleanupTransport(n,true);this.setStatus("disconnected",false),this.report(r);for(let i of o)this.report(i);}takeTransportSubscription(){let e=this.unsubscribeTransport;return this.unsubscribeTransport=()=>{},this.hasTransportSubscription=false,e}cleanupTransport(e,r){let n=[];try{e();}catch(o){n.push(P("transport","Failed to unsubscribe from transport events",o));}if(!r)return n;try{let o=this.transport.disconnect();o&&o.catch(i=>{this.isDestroyed||this.report(P("transport","Transport disconnect failed",i));});}catch(o){n.push(P("transport","Transport disconnect failed",o));}return n}handleTransportEvent(e,r){if(this.isCurrent(e))switch(r.type){case "open":this.handleOpen(e);break;case "message":this.isOpen&&this.handleMessage(e,r.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,P("transport","Transport error",r.error));break;case "drain":this.isOpen&&this.flushPending();break;default:this.failConnection(e,new E("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 r;try{r=Ae(this.replica.encodeStateVector(),"encodeStateVector");}catch(n){this.failConnection(e,P("replica","Failed to encode replica state vector",n));return}try{this.sendFrame(st(r,this.maxFrameBytes));}catch(n){this.failConnection(e,P("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(dt(this.maxFrameBytes));}catch(n){this.report(P("protocol","Failed to encode awareness query",n));}}handleMessage(e,r){let n;try{n=ut(r.slice(),this.maxFrameBytes,this.maxMessagesPerFrame);}catch(o){this.failConnection(e,P("protocol","Invalid collaboration frame",o));return}for(let o of n){if(!this.isCurrent(e)||!this.isOpen)return;switch(o.type){case "sync-step-1":this.respondToSyncStep1(e,o.stateVector);break;case "sync-step-2":this.applyRemoteUpdate(e,o.update)&&this.isCurrent(e)&&this.setStatus("connected",true);break;case "update":this.applyRemoteUpdate(e,o.update);break;case "awareness":{try{let i=pt(o.update,this.maxMessagesPerFrame);this.remotePresence.apply(i,Date.now())&&this.emitPresence(),this.schedulePresenceExpiry();}catch(i){this.report(P("protocol","Invalid awareness update",i));}break}case "auth":this.failConnection(e,new E("protocol",o.reason?`Authentication denied: ${o.reason}`:"Authentication denied"));return;case "query-awareness":this.broadcastLocalPresence(false);break}}}respondToSyncStep1(e,r){let n;try{n=Ae(this.replica.encodeStateAsUpdate(mt(r).slice()),"encodeStateAsUpdate");}catch(o){this.failConnection(e,P("replica","Failed to encode replica update",o));return}try{this.sendFrame(at(n,this.maxFrameBytes));}catch(o){this.failConnection(e,P("protocol","Failed to encode SyncStep2",o));}}applyRemoteUpdate(e,r){try{return this.replica.applyUpdate(mt(r).slice()),!0}catch(n){return this.failConnection(e,P("replica","Failed to apply remote update",n)),false}}forwardLocalUpdate(e){if(this.isDestroyed||!this.isOpen||!this.wantsConnection)return;let r=this.epoch,n;try{n=Ae(e,"Replica update");}catch(o){this.failConnection(r,P("replica","Invalid replica update",o));return}try{this.sendFrame(lt(n,this.maxFrameBytes));}catch(o){this.failConnection(r,P("protocol","Failed to encode update",o));}}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),Ee(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 E("protocol","Awareness clock exceeds Number.MAX_SAFE_INTEGER")));return}this.localClock+=1;let r=this.localClock,n=e?null:{clientId:this.localClientId,clock:r,user:{...this.localUser},cursor:this.localCursor?{...this.localCursor}:null};this.cursorTimer&&clearTimeout(this.cursorTimer),this.cursorTimer=null,this.lastAwarenessSentAt=Date.now();try{let o=ct([{clientId:this.localClientId,clock:r,state:n}],this.maxFrameBytes);e?this.sendLeaveFrameBestEffort(o):this.sendFrame(o);}catch(o){this.report(P("protocol","Failed to encode awareness update",o));}}sendLeaveFrameBestEffort(e){try{this.transport.send(e.slice());}catch{}}startPresenceTimers(){this.stopPresenceTimers(),this.heartbeatTimer=setInterval(()=>{this.broadcastLocalPresence(false);},2e4),Ee(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())),Ee(this.expiryTimer));}clearRemotePresence(){this.remotePresence.clear()&&this.emitPresence();}emitPresence(){let e=this.peers;for(let[r,n]of [...this.presenceListeners])if(this.presenceListeners.get(r)===n)try{n(e);}catch{}}sendFrame(e){if(!this.isOpen||this.isDestroyed||!this.wantsConnection)return;let r=this.epoch;if(this.pendingFrames.length>0){this.queueFrame(r,e);return}let n;try{n=this.transport.send(e.slice());}catch(o){this.failConnection(r,P("transport","Transport send failed",o));return}if(typeof n!="boolean"){this.failConnection(r,new E("transport","Transport send must return a boolean"));return}!n&&this.isCurrent(r)&&this.isOpen&&this.queueFrame(r,e);}queueFrame(e,r){if(r.byteLength>this.maxPendingBytes-this.queuedBytes){this.failConnection(e,new E("backpressure",`Pending collaboration data exceeds ${this.maxPendingBytes} bytes`));return}let n=r.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,r=this.pendingFrames[0],n;try{n=this.transport.send(r.slice());}catch(o){this.failConnection(e,P("transport","Transport send failed",o));return}if(typeof n!="boolean"){this.failConnection(e,new E("transport","Transport send must return a boolean"));return}if(!n||!this.isOpen||this.pendingFrames[0]!==r)return;this.pendingFrames.shift(),this.queuedBytes-=r.byteLength;}}finally{this.isFlushing=false;}}}clearPending(){this.pendingFrames.length=0,this.queuedBytes=0;}setStatus(e,r){if(this.connectionStatus===e&&this.isSynced===r)return;this.connectionStatus=e,this.isSynced=r;let n={status:e,synced:r};for(let[o,i]of [...this.statusListeners])if(this.statusListeners.get(o)===i)try{i(n);}catch{}}report(e){for(let[r,n]of [...this.errorListeners])if(this.errorListeners.get(r)===n)try{n(e);}catch{}}};export{E as CollaborationError,se as CollaborationProvider,Ye as PRESENCE_LABEL_DURATION_MS,Y as StaleProposalError,en as initWasm,rn as inspectPresentation,ge as isProposalsAvailable,tn as isWasmAvailable,on as openPresentation,ue as paintSlide,ye as presenceColorForClientId,pn as presentationImageBlob,pe as sizeCanvasForSlide,hn as slideToPng,nn as wasmVersion};
|
package/package.json
CHANGED