pptx-viewer-mcp 2.5.9 → 2.6.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/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ A release listed with no entries carried no Conventional Commit in this package'
7
7
  scope: scripts/release-plan.mjs re-releases a package whenever any of its files
8
8
  change, not only on conventional ones.
9
9
 
10
+ ## [2.5.9](https://github.com/ChristopherVR/pptx-viewer/releases/tag/pptx-viewer-mcp@2.5.9) - 2026-10-02
11
+
12
+ ### Build & CI
13
+
14
+ - **core:** Depend on the unscoped ooxml-core package (by @ChristopherVR) ([5ae6159](https://github.com/ChristopherVR/pptx-viewer/commit/5ae615928d76d1328e46719c5b441afb5bfc2f7f))
15
+
10
16
  ## [2.5.8](https://github.com/ChristopherVR/pptx-viewer/releases/tag/pptx-viewer-mcp@2.5.8) - 2026-10-01
11
17
 
12
18
  ### Refactor
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2025-present pptx-viewer contributors
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # pptx-viewer-mcp
2
2
 
3
+ Document operations, load/save execution and the Y.Doc codec are owned by
4
+ `ooxml-core/pptx/automation`. This repository owns MCP schemas, registration and
5
+ the stdio CLI. Compatibility exports retain the existing library API.
6
+ The `/mcp` import exports `createServer({ rootDir })` and `registerTools(server,
7
+ { rootDir })` without starting a transport; the CLI starts stdio separately.
8
+ Release the core automation entry (0.11.0+) before publishing this change.
9
+
3
10
  [![npm](https://img.shields.io/npm/v/pptx-viewer-mcp.svg)](https://www.npmjs.com/package/pptx-viewer-mcp)
4
11
  [![license](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](../../LICENSE)
5
12
 
@@ -167,3 +174,4 @@ bun run test # vitest run
167
174
  ## License
168
175
 
169
176
  Apache-2.0
177
+
@@ -1,58 +1,13 @@
1
- import { Doc } from "yjs";
1
+ import { apiCodecPptxCodec } from "ooxml-core/pptx/automation";
2
2
  //#region src/codec/pptx-codec.d.ts
3
3
  export declare const ORIGIN_FILE_LOAD = "file-load";
4
- /**
5
- * Bidirectional format codec: file bytes <-> Y.Doc shared types.
6
- *
7
- * Y.Doc schema:
8
- * pptx:meta Y.Map - width, height, widthEmu, heightEmu, sourceBytes
9
- * pptx:slides Y.Array<Y.Map> - one map per slide
10
- * Each slide Y.Map: scalar fields + `_`-prefixed JSON blobs + `elements` Y.Array<Y.Map>
11
- * Each element Y.Map: scalar fields + `_`-prefixed JSON blobs + `textBody` Y.Text
12
- * textBody Y.Text: one delta op per TextSegment (see text-body-codec.ts)
13
- *
14
- * NOTE: the viewer bindings' sync schema (pptx-viewer-shared
15
- * collaboration-sync.ts) uses SHORT complex-field key prefixes (`_ts`, `_tr`)
16
- * while this codec uses long ones (`_textStyle`, `_transition`). The two doc
17
- * layouts are similar but NOT interchangeable on the same Y.Doc.
18
- */
19
- interface FormatCodec {
20
- readonly formatId: string;
21
- readonly extensions: string[];
22
- hydrate: (ydoc: Doc, bytes: Uint8Array, origin?: string) => Promise<void>;
23
- dehydrate: (ydoc: Doc, dirtyPaths?: string[]) => Promise<Uint8Array>;
24
- observe: (ydoc: Doc, onChange: () => void) => () => void;
25
- }
26
- /**
27
- * Field coverage is derived from `pptx-viewer-core`'s
28
- * `ELEMENT_FIELD_KIND`/`SLIDE_FIELD_KIND` (the same canonical inventory the
29
- * viewer's `collaboration-sync.ts` allowlists derive from), so this codec
30
- * automatically tracks every field `PptxElement`/`PptxSlide` declares
31
- * instead of drifting out of sync with a hand-maintained list. Wire-format
32
- * prefixes stay long-form (`_textStyle`) here versus the viewer schema's
33
- * short-form (`_ts`) - the two Y.Doc layouts are intentionally NOT
34
- * interchangeable, only the field *coverage* is required to match.
35
- *
36
- * `asset`-kind fields (large binary payloads like `mediaData`) are simply
37
- * embedded as scalars here rather than routed through a separate asset map:
38
- * this codec does one-shot bidirectional file<->Y.Doc conversion, not a
39
- * live P2P transport, so there's no repeated-write cost to avoid.
40
- */
4
+ type FormatCodec = apiCodecPptxCodec.FormatCodec;
41
5
  export declare const SCALAR_ELEMENT_KEYS: Set<string>;
42
6
  export declare const COMPLEX_FIELD_MAP: Record<string, string>;
43
7
  export declare const SCALAR_SLIDE_KEYS: Set<string>;
44
8
  export declare const COMPLEX_SLIDE_FIELD_MAP: Record<string, string>;
45
- export declare class PptxCodec implements FormatCodec {
46
- readonly formatId = "pptx";
47
- readonly extensions: string[];
48
- hydrate(ydoc: Doc, bytes: Uint8Array, origin?: string): Promise<void>;
49
- dehydrate(ydoc: Doc, _dirtyPaths?: string[]): Promise<Uint8Array>;
50
- observe(ydoc: Doc, onChange: () => void): () => void;
51
- private _slideToYMap;
52
- private _yMapToSlide;
53
- private _elementToYMap;
54
- private _yMapToElement;
55
- }
9
+ export declare const PptxCodec: typeof apiCodecPptxCodec.PptxCodec;
10
+ export type PptxCodec = apiCodecPptxCodec.PptxCodec;
56
11
  //#endregion
57
12
  export type { FormatCodec };
58
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/codec/pptx-codec.ts"],"mappings":";;qBAMa;;;;;;;;;;;;;;;;UAiBI;WACP;WACA;EACT,UAAU,MAAM,KAAM,OAAO,YAAY,oBAAoB;EAC7D,YAAY,MAAM,KAAM,0BAA0B,QAAQ;EAC1D,UAAU,MAAM,KAAM;;;;;;;;;;;;;;;;;qBAoBV,qBAAmB;qBAQnB,mBAAmB;qBAWnB,mBAAiB;qBAOjB,yBAAyB;qBAWzB,qBAAqB;WACxB;WACA;EAEH,QAAQ,MAAM,KAAM,OAAO,YAAY,kBAAkB;EA+BzD,UAAU,MAAM,KAAM,yBAAyB,QAAQ;EA2B7D,QAAQ,MAAM,KAAM;UAWZ;UAqBA;UA6BA;UAsBA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/codec/pptx-codec.ts"],"mappings":";;qBAEa;KACD,cAAc,kBAAW;qBACxB,qBAAmB;qBACnB,mBAAiB;qBACjB,mBAAiB;qBACjB,yBAAuB;qBACvB,kBAAS,kBAAA;YACV,YAAY,kBAAW"}
@@ -1,364 +1,14 @@
1
1
  'use strict';
2
2
 
3
- var pptxViewerCore = require('pptx-viewer-core');
4
- var yjs = require('yjs');
3
+ var automation = require('ooxml-core/pptx/automation');
5
4
 
6
5
  // src/codec/pptx-codec.ts
7
-
8
- // src/codec/text-body-codec.ts
9
- var EMPTY_PLACEHOLDER = "\u200B";
10
- function buildAttrs(seg) {
11
- const a = {};
12
- const style = seg.style;
13
- if (style && typeof style === "object" && Object.keys(style).length > 0) {
14
- a.s = JSON.stringify(style);
15
- }
16
- if (seg.isParagraphBreak) {
17
- a.pb = "1";
18
- }
19
- if (seg.isLineBreak) {
20
- a.lb = "1";
21
- }
22
- if (seg.ep === true) {
23
- a.ep = "1";
24
- }
25
- if (seg.bulletInfo) {
26
- a.bi = JSON.stringify(seg.bulletInfo);
27
- }
28
- if (seg.paragraphLevel !== void 0) {
29
- a.pl = String(seg.paragraphLevel);
30
- }
31
- if (seg.endParaRunProperties) {
32
- a.pr = JSON.stringify(seg.endParaRunProperties);
33
- }
34
- if (seg.paragraphProperties) {
35
- a.pp = JSON.stringify(seg.paragraphProperties);
36
- }
37
- if (typeof seg.fieldType === "string") {
38
- a.ft = seg.fieldType;
39
- }
40
- if (typeof seg.fieldGuid === "string") {
41
- a.fg = seg.fieldGuid;
42
- }
43
- if (seg.fieldGuidAttr === "uuid" || seg.fieldGuidAttr === "id") {
44
- a.fga = seg.fieldGuidAttr;
45
- }
46
- if (seg.fieldParagraphPropertiesXml) {
47
- a.fp = JSON.stringify(seg.fieldParagraphPropertiesXml);
48
- }
49
- if (seg.equationXml) {
50
- a.eq = JSON.stringify(seg.equationXml);
51
- }
52
- if (typeof seg.equationNumber === "string") {
53
- a.en = seg.equationNumber;
54
- }
55
- if (seg.breakRunProperties) {
56
- a.br = JSON.stringify(seg.breakRunProperties);
57
- }
58
- if (typeof seg.rubyText === "string") {
59
- a.rt = seg.rubyText;
60
- }
61
- if (typeof seg.rubyAlignment === "string") {
62
- a.ra = seg.rubyAlignment;
63
- }
64
- if (seg.rubyFontSize !== void 0) {
65
- a.rfs = String(seg.rubyFontSize);
66
- }
67
- if (seg.rubyStyle) {
68
- a.rs = JSON.stringify(seg.rubyStyle);
69
- }
70
- return Object.keys(a).length > 0 ? a : void 0;
71
- }
72
- function encodeTextBodyToYText(segments, ytext) {
73
- let offset = 0;
74
- for (const raw of segments) {
75
- const seg = raw;
76
- const attrs = buildAttrs(seg) ?? {};
77
- if (seg.isParagraphBreak === true || seg.isLineBreak === true) {
78
- ytext.insert(offset, "\n", attrs);
79
- offset += 1;
80
- } else if (typeof seg.text === "string" && seg.text.length > 0) {
81
- ytext.insert(offset, seg.text, attrs);
82
- offset += seg.text.length;
83
- } else {
84
- const epAttrs = { ep: "1", ...attrs ?? {} };
85
- ytext.insert(offset, EMPTY_PLACEHOLDER, epAttrs);
86
- offset += 1;
87
- }
88
- }
89
- }
90
- function decodeTextBodyFromYText(ytext) {
91
- const delta = ytext.toDelta();
92
- const segments = [];
93
- for (const op of delta) {
94
- if (typeof op.insert !== "string" || op.insert === "") {
95
- continue;
96
- }
97
- const a = op.attributes ?? {};
98
- const seg = { text: "", style: {} };
99
- if (a.s) {
100
- try {
101
- seg.style = JSON.parse(a.s);
102
- } catch {
103
- seg.style = {};
104
- }
105
- }
106
- if (a.pb === "1") {
107
- seg.isParagraphBreak = true;
108
- }
109
- if (a.lb === "1") {
110
- seg.isLineBreak = true;
111
- }
112
- if (a.bi) {
113
- try {
114
- seg.bulletInfo = JSON.parse(a.bi);
115
- } catch {
116
- }
117
- }
118
- if (a.pl !== void 0) {
119
- seg.paragraphLevel = Number(a.pl);
120
- }
121
- if (a.pr) {
122
- try {
123
- seg.endParaRunProperties = JSON.parse(a.pr);
124
- } catch {
125
- }
126
- }
127
- if (a.pp) {
128
- try {
129
- seg.paragraphProperties = JSON.parse(a.pp);
130
- } catch {
131
- }
132
- }
133
- if (a.ft) {
134
- seg.fieldType = a.ft;
135
- }
136
- if (a.fg) {
137
- seg.fieldGuid = a.fg;
138
- }
139
- if (a.fga === "uuid" || a.fga === "id") {
140
- seg.fieldGuidAttr = a.fga;
141
- }
142
- if (a.fp) {
143
- try {
144
- seg.fieldParagraphPropertiesXml = JSON.parse(a.fp);
145
- } catch {
146
- }
147
- }
148
- if (a.eq) {
149
- try {
150
- seg.equationXml = JSON.parse(a.eq);
151
- } catch {
152
- }
153
- }
154
- if (a.en) {
155
- seg.equationNumber = a.en;
156
- }
157
- if (a.br) {
158
- try {
159
- seg.breakRunProperties = JSON.parse(a.br);
160
- } catch {
161
- }
162
- }
163
- if (a.rt) {
164
- seg.rubyText = a.rt;
165
- }
166
- if (a.ra) {
167
- seg.rubyAlignment = a.ra;
168
- }
169
- if (a.rfs !== void 0) {
170
- seg.rubyFontSize = Number(a.rfs);
171
- }
172
- if (a.rs) {
173
- try {
174
- seg.rubyStyle = JSON.parse(a.rs);
175
- } catch {
176
- }
177
- }
178
- const isBreakMarker = /^\n+$/u.test(op.insert) && (a.pb === "1" || a.lb === "1");
179
- if (isBreakMarker) {
180
- for (let index = 0; index < op.insert.length; index++) {
181
- segments.push(structuredClone(seg));
182
- }
183
- continue;
184
- }
185
- if (op.insert !== EMPTY_PLACEHOLDER) {
186
- seg.text = op.insert;
187
- }
188
- segments.push(seg);
189
- }
190
- return segments;
191
- }
192
-
193
- // src/codec/pptx-codec.ts
194
- var ORIGIN_FILE_LOAD = "file-load";
195
- var SCALAR_ELEMENT_KEYS = new Set(
196
- Object.entries(pptxViewerCore.ELEMENT_FIELD_KIND).filter(([, kind]) => kind === "scalar" || kind === "asset").map(([field]) => field)
197
- );
198
- var COMPLEX_FIELD_MAP = Object.fromEntries(
199
- Object.entries(pptxViewerCore.ELEMENT_FIELD_KIND).filter(([, kind]) => kind === "complex").map(([field]) => [field, `_${field}`])
200
- );
201
- var REVERSE_COMPLEX_MAP = {};
202
- for (const [original, prefixed] of Object.entries(COMPLEX_FIELD_MAP)) {
203
- REVERSE_COMPLEX_MAP[prefixed] = original;
204
- }
205
- var SCALAR_SLIDE_KEYS = new Set(
206
- Object.entries(pptxViewerCore.SLIDE_FIELD_KIND).filter(([, kind]) => kind === "scalar").map(([field]) => field)
207
- );
208
- var COMPLEX_SLIDE_FIELD_MAP = Object.fromEntries(
209
- Object.entries(pptxViewerCore.SLIDE_FIELD_KIND).filter(([, kind]) => kind === "complex").map(([field]) => [field, `_${field}`])
210
- );
211
- var REVERSE_COMPLEX_SLIDE_MAP = {};
212
- for (const [original, prefixed] of Object.entries(COMPLEX_SLIDE_FIELD_MAP)) {
213
- REVERSE_COMPLEX_SLIDE_MAP[prefixed] = original;
214
- }
215
- var PptxCodec = class {
216
- formatId = "pptx";
217
- extensions = [".pptx", ".ppt"];
218
- async hydrate(ydoc, bytes, origin) {
219
- const effectiveOrigin = origin ?? ORIGIN_FILE_LOAD;
220
- const handler = new pptxViewerCore.PptxHandler();
221
- const pptxData = await handler.load(bytes.buffer);
222
- ydoc.transact(() => {
223
- const meta = ydoc.getMap("pptx:meta");
224
- meta.set("width", pptxData.width);
225
- meta.set("height", pptxData.height);
226
- if (pptxData.widthEmu !== void 0) {
227
- meta.set("widthEmu", pptxData.widthEmu);
228
- }
229
- if (pptxData.heightEmu !== void 0) {
230
- meta.set("heightEmu", pptxData.heightEmu);
231
- }
232
- const sourceBytesArr = new yjs.Array();
233
- sourceBytesArr.insert(0, Array.from(bytes));
234
- meta.set("sourceBytes", sourceBytesArr);
235
- const slidesArray = ydoc.getArray("pptx:slides");
236
- if (slidesArray.length > 0) {
237
- slidesArray.delete(0, slidesArray.length);
238
- }
239
- for (const slide of pptxData.slides) {
240
- slidesArray.push([this._slideToYMap(slide)]);
241
- }
242
- }, effectiveOrigin);
243
- }
244
- async dehydrate(ydoc, _dirtyPaths) {
245
- const meta = ydoc.getMap("pptx:meta");
246
- const slidesArray = ydoc.getArray("pptx:slides");
247
- const slides = [];
248
- for (let i = 0; i < slidesArray.length; i++) {
249
- slides.push(this._yMapToSlide(slidesArray.get(i)));
250
- }
251
- const sourceBytesArr = meta.get("sourceBytes");
252
- try {
253
- if (!sourceBytesArr || sourceBytesArr.length === 0) {
254
- throw new Error("No source bytes for PptxHandler");
255
- }
256
- const sourceBytes = new Uint8Array(sourceBytesArr.toArray());
257
- const handler = new pptxViewerCore.PptxHandler();
258
- await handler.load(sourceBytes.buffer);
259
- return await handler.save(slides);
260
- } catch {
261
- if (sourceBytesArr && sourceBytesArr.length > 0) {
262
- return new Uint8Array(sourceBytesArr.toArray());
263
- }
264
- throw new Error("No PPTX bytes available for dehydration");
265
- }
266
- }
267
- observe(ydoc, onChange) {
268
- const slidesArray = ydoc.getArray("pptx:slides");
269
- const meta = ydoc.getMap("pptx:meta");
270
- slidesArray.observeDeep(onChange);
271
- meta.observeDeep(onChange);
272
- return () => {
273
- slidesArray.unobserveDeep(onChange);
274
- meta.unobserveDeep(onChange);
275
- };
276
- }
277
- _slideToYMap(slide) {
278
- const slideMap = new yjs.Map();
279
- const rec = slide;
280
- for (const key of SCALAR_SLIDE_KEYS) {
281
- if (rec[key] !== void 0) {
282
- slideMap.set(key, rec[key]);
283
- }
284
- }
285
- for (const [original, prefixed] of Object.entries(COMPLEX_SLIDE_FIELD_MAP)) {
286
- if (rec[original] !== void 0) {
287
- slideMap.set(prefixed, JSON.stringify(rec[original]));
288
- }
289
- }
290
- const elementsArray = new yjs.Array();
291
- for (const element of slide.elements) {
292
- elementsArray.push([this._elementToYMap(element)]);
293
- }
294
- slideMap.set("elements", elementsArray);
295
- return slideMap;
296
- }
297
- _yMapToSlide(slideMap) {
298
- const slide = {};
299
- for (const key of SCALAR_SLIDE_KEYS) {
300
- const value = slideMap.get(key);
301
- if (value !== void 0) {
302
- slide[key] = value;
303
- }
304
- }
305
- for (const [prefixed, original] of Object.entries(REVERSE_COMPLEX_SLIDE_MAP)) {
306
- const value = slideMap.get(prefixed);
307
- if (value !== void 0) {
308
- try {
309
- slide[original] = JSON.parse(value);
310
- } catch {
311
- }
312
- }
313
- }
314
- const elementsArray = slideMap.get("elements");
315
- const elements = [];
316
- if (elementsArray) {
317
- for (let i = 0; i < elementsArray.length; i++) {
318
- elements.push(this._yMapToElement(elementsArray.get(i)));
319
- }
320
- }
321
- slide.elements = elements;
322
- return slide;
323
- }
324
- _elementToYMap(element) {
325
- const elemMap = new yjs.Map();
326
- const record = element;
327
- for (const [key, value] of Object.entries(record)) {
328
- if (value === void 0) {
329
- continue;
330
- }
331
- if (key === "textSegments") {
332
- if (Array.isArray(value)) {
333
- const ytext = new yjs.Text();
334
- encodeTextBodyToYText(value, ytext);
335
- elemMap.set("textBody", ytext);
336
- }
337
- } else if (SCALAR_ELEMENT_KEYS.has(key)) {
338
- elemMap.set(key, value);
339
- } else if (COMPLEX_FIELD_MAP[key]) {
340
- elemMap.set(COMPLEX_FIELD_MAP[key], JSON.stringify(value));
341
- }
342
- }
343
- return elemMap;
344
- }
345
- _yMapToElement(elemMap) {
346
- const element = {};
347
- elemMap.forEach((value, key) => {
348
- if (key === "textBody" && value instanceof yjs.Text) {
349
- element.textSegments = decodeTextBodyFromYText(value);
350
- } else if (REVERSE_COMPLEX_MAP[key]) {
351
- try {
352
- element[REVERSE_COMPLEX_MAP[key]] = JSON.parse(value);
353
- } catch {
354
- }
355
- } else {
356
- element[key] = value;
357
- }
358
- });
359
- return element;
360
- }
361
- };
6
+ var ORIGIN_FILE_LOAD = automation.apiCodecPptxCodec.ORIGIN_FILE_LOAD;
7
+ var SCALAR_ELEMENT_KEYS = automation.apiCodecPptxCodec.SCALAR_ELEMENT_KEYS;
8
+ var COMPLEX_FIELD_MAP = automation.apiCodecPptxCodec.COMPLEX_FIELD_MAP;
9
+ var SCALAR_SLIDE_KEYS = automation.apiCodecPptxCodec.SCALAR_SLIDE_KEYS;
10
+ var COMPLEX_SLIDE_FIELD_MAP = automation.apiCodecPptxCodec.COMPLEX_SLIDE_FIELD_MAP;
11
+ var PptxCodec = automation.apiCodecPptxCodec.PptxCodec;
362
12
 
363
13
  exports.COMPLEX_FIELD_MAP = COMPLEX_FIELD_MAP;
364
14
  exports.COMPLEX_SLIDE_FIELD_MAP = COMPLEX_SLIDE_FIELD_MAP;