@pptx-editor.dev/pro 0.0.0-stage → 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.md ADDED
@@ -0,0 +1,84 @@
1
+ # EigenPal Pro Evaluation License 1.0
2
+
3
+ Copyright (c) 2026 EigenPal, Inc. All rights reserved.
4
+
5
+ By copying, modifying, or using the Software, you agree to these terms.
6
+
7
+ ## 1. Covered Software
8
+
9
+ “Software” means all source code, object code, documentation, assets, and other materials contained in the “packages/pro/” directory of the EigenPal PPTX Editor repository, except for any material that expressly states that it is subject to a different license.
10
+
11
+ ## 2. Evaluation Permission; Modifications
12
+
13
+ Subject to these terms, EigenPal, Inc. grants you a limited, non-exclusive, non-transferable, non-sublicensable, royalty-free license to:
14
+
15
+ 1. view, clone, and copy the Software;
16
+ 2. run the Software internally in a non-production environment solely to    evaluate its suitability for your intended application; and
17
+ 3. modify the Software solely as reasonably necessary for that internal,    non-production evaluation.
18
+
19
+ For any such modification, the following applies:
20
+
21
+ You may keep any modification to yourself. If you do not disclose it to EigenPal, Inc. or to anyone else, it remains yours If you disclose a modification to EigenPal, Inc. or to any third party, in any form, you assign all right, title, and interest in it to EigenPal, Inc. at the moment of disclosure. The same applies to any feedback you give EigenPal, Inc. You will promptly send EigenPal, Inc. the source code of any modification you disclose, and will sign any document needed to record the assignment. Disclosing a modification to a third party grants that third party no rights in it or in the Software. You will not license or purport to license any modification to anyone. You may continue using an assigned modification for the internal, non-production evaluation permitted by Section 2 for as long as this license is in effect. EigenPal, Inc. is not obliged to use or support any modification or feedback, and owes you nothing for it. You confirm that any modification or feedback you disclose is yours to assign and is not subject to any license that would impose obligations on EigenPal, Inc. or grant rights to any third party.
22
+
23
+ No other rights are granted.
24
+
25
+ ## 3. No Production Use
26
+
27
+ You may not use the Software for Production Use.
28
+
29
+ “Production Use” means any use of the Software:
30
+
31
+ 1. in a live, operational, or customer-facing environment;
32
+ 2. to provide, operate, support, or enhance a product or service for another    person or organization;
33
+ 3. to process live, customer, or business-operational data; or
34
+ 4. as part of your ordinary internal business operations, other than evaluation    and testing.
35
+
36
+ For the avoidance of doubt, Production Use includes embedding the Software in a product made available to others, offering the Software through a hosted or managed service, and using it in a customer pilot or paid proof of concept.
37
+
38
+ ## 4. No Distribution or Sublicensing
39
+
40
+ You may not sell, sublicense, distribute, publish, transfer, or otherwise make the Software or modifications to the Software available to any third party.
41
+
42
+ You may allow your employees and contractors to access the Software solely for your evaluation, provided they are bound by restrictions at least as protective as these terms. You are responsible for their compliance.
43
+
44
+ ## 5. Commercial Rights
45
+
46
+ Production Use and any rights not expressly granted by this license require a separate written commercial agreement signed by EigenPal, Inc.
47
+
48
+ Commercial licenses are available by contacting licensing@eigenpal.com.
49
+
50
+ Access to the Software, correspondence with EigenPal, Inc., or payment of an invoice does not by itself grant production or commercial rights unless those rights are set out in a written agreement signed by EigenPal, Inc.
51
+
52
+ ## 6. Ownership
53
+
54
+ EigenPal, Inc. and its licensors retain all rights, title, and interest in the Software. This license does not transfer ownership or grant any rights by implication.
55
+
56
+ Modifying the Software does not grant you the right to use the Software or those modifications in production.
57
+
58
+ ## 7. Termination
59
+
60
+ Your rights under this license terminate automatically if you breach these terms or if EigenPal terminates this license.
61
+
62
+ Following termination, you must stop using the Software and delete your copies and modifications, except for copies that you are legally required to retain. EigenPal, Inc. may reinstate your rights in writing.
63
+
64
+ ## 8. No Warranty
65
+
66
+ TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED “AS IS” AND WITHOUT WARRANTIES OF ANY KIND, WHETHER EXPRESS, IMPLIED, OR STATUTORY, INCLUDING WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT.
67
+
68
+ ## 9. Limitation of Liability
69
+
70
+ TO THE MAXIMUM EXTENT PERMITTED BY LAW, EIGENPAL, INC. AND ITS LICENSORS WILL NOT BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL, EXEMPLARY, OR PUNITIVE DAMAGES, OR FOR ANY LOSS OF DATA, REVENUE, PROFITS, OR BUSINESS, ARISING FROM OR RELATING TO THE SOFTWARE OR THIS LICENSE. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE TOTAL AGGREGATE LIABILITY OF EIGENPAL, INC. AND ITS LICENSORS FOR ALL CLAIMS ARISING FROM OR RELATING TO THE SOFTWARE OR THIS LICENSE, WHETHER IN CONTRACT, TORT, STRICT LIABILITY, OR ANY OTHER THEORY, WILL NOT EXCEED TEN UNITED STATES DOLLARS (US$10). THE FOREGOING LIMITATIONS APPLY EVEN IF EIGENPAL, INC. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND EVEN IF ANY LIMITED REMEDY IS FOUND TO HAVE FAILED OF ITS ESSENTIAL PURPOSE.
71
+
72
+ ## 10. Trademarks
73
+
74
+ This license does not grant permission to use the names, trademarks, service marks, or logos of EigenPal, Inc., except to identify the origin of an unmodified copy of the Software.
75
+
76
+ ## 11. Governing Law and Jurisdiction
77
+
78
+ This license is governed by the laws of the State of California, without regard to its conflict-of-laws rules.
79
+
80
+ Any dispute arising from or relating to this license will be subject to the exclusive jurisdiction of the state and federal courts located in California, and you consent to their jurisdiction.
81
+
82
+ ## 12. Separate Commercial Agreements
83
+
84
+ If EigenPal, Inc. and you enter into a separate written commercial agreement, that agreement controls to the extent it grants additional rights or conflicts with this license.
package/README.md CHANGED
@@ -1,3 +1,129 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <a href="https://pptx-editor.dev/">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/eigenpal/pptx-editor/main/.github/assets/readme-logo-dark.svg" />
5
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/eigenpal/pptx-editor/main/.github/assets/readme-logo-light.svg" />
6
+ <img src="https://raw.githubusercontent.com/eigenpal/pptx-editor/main/.github/assets/readme-logo-light.svg" alt="PPTX Editor by EigenPal" width="320" height="90" />
7
+ </picture>
8
+ </a>
9
+ </p>
2
10
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/@pptx-editor.dev/pro"><img src="https://img.shields.io/npm/v/@pptx-editor.dev/pro.svg?style=flat-square&color=C43E1C" alt="npm version" /></a>
13
+ <a href="https://www.npmjs.com/package/@pptx-editor.dev/pro"><img src="https://img.shields.io/npm/dm/@pptx-editor.dev/pro.svg?style=flat-square&color=C43E1C" alt="npm downloads" /></a>
14
+ <a href="https://github.com/eigenpal/pptx-editor/blob/main/packages/pro/LICENSE.md"><img src="https://img.shields.io/badge/license-EigenPal_Pro_License-blue.svg?style=flat-square&color=C43E1C" alt="EigenPal Pro License" /></a>
15
+ </p>
16
+
17
+ # @pptx-editor.dev/pro
18
+
19
+ Commercial capabilities for PPTX Editor, delivered as `EditorModule`s, in the same shape as DOCX Editor's `@docx-editor.dev/pro`:
20
+
21
+ - `reviewModule()`: the review queue. It reads legacy comments (`p:cmLst`, ECMA-376 Part 1, 19.4) and their replies today.
22
+ - `collaborationModule({ session })`: attaches a host-created collaboration session to each opened deck.
23
+ - `createYjsCollaborationSession({ doc, documentId, identity, awareness })`: a session over a Y.Doc. It mirrors the deck into Yjs, as DOCX Editor does, so concurrent edits merge without a server sequencer.
24
+ - **History:** while the session is attached, the editor's undo and redo revert only your own changes (`Y.UndoManager`), never a peer's, and return to the slide and selection of the undone change.
25
+ - **Status:** `statusSnapshot()` and `subscribeStatus()` report the state and a typed `CollaborationFailureCode`, as in DOCX Editor. Call `setConnected()` from your provider's status event.
26
+ - **Concurrent edits:** two peers that add or replace an element that a slide, shape, or paragraph holds once end with one element, and the other peer's copy stays hidden in the room until the winner undoes. Property elements merge. Concurrent splits of one run keep its text once, and a node moved into content that a peer removes at once goes back. The `collaboration.realtime` row in `docs/site/data/pptx-features.ts` states what is supported and its limits. A room from a pre-release build (room format 1) refuses to attach.
27
+ - **Presence:** with a Yjs `awareness` (`y-protocols/awareness`), the editor publishes its selection, and the canvas shows each peer's selected shapes and text caret, with the peer's name and color. Your caret stays on its character while peers type before it.
28
+
29
+ This package uses the EigenPal Pro License (`LICENSE.md`): you may evaluate it freely, and production use requires a commercial agreement.
30
+
31
+ ## Use
32
+
33
+ ```ts
34
+ import { createPptxEditor } from '@pptx-editor.dev/core';
35
+ import { collaborationModule, reviewModule } from '@pptx-editor.dev/pro';
36
+
37
+ const editor = createPptxEditor({
38
+ document: bytes,
39
+ modules: [reviewModule(), collaborationModule({ session })],
40
+ });
41
+ ```
42
+
43
+ In the React or Vue adapter, pass the same list in the `modules` prop of `PptxEditor` or its root. The editor reads it once, when it is created. Keep the list stable, for example in `useMemo` or a `const` in `setup`:
44
+
45
+ ```tsx
46
+ <PptxEditor document={bytes} modules={modules} />
47
+ ```
48
+
49
+ To collaborate over Yjs, create one session per editor from a Y.Doc and an awareness that your provider connects. This example links two editors in one page; in an app, each editor runs in its own browser with a provider such as Hocuspocus.
50
+
51
+ ```ts
52
+ import * as Y from 'yjs';
53
+ import { Awareness, applyAwarenessUpdate, encodeAwarenessUpdate } from 'y-protocols/awareness';
54
+ import { createPptxEditor } from '@pptx-editor.dev/core';
55
+ import { collaborationModule, createYjsCollaborationSession } from '@pptx-editor.dev/pro';
56
+
57
+ // The deck to open, for example from a file input.
58
+ const bytes = new Uint8Array(await file.arrayBuffer());
59
+
60
+ function openReplica(doc: Y.Doc, awareness: Awareness, actorId: string, name: string) {
61
+ const session = createYjsCollaborationSession({
62
+ doc,
63
+ awareness,
64
+ documentId: 'quarterly-review',
65
+ identity: { actorId, name, color: '#2563eb' },
66
+ });
67
+ const editor = createPptxEditor({ document: bytes, modules: [collaborationModule({ session })] });
68
+ return { editor, session };
69
+ }
70
+
71
+ const docA = new Y.Doc();
72
+ const docB = new Y.Doc();
73
+ const awarenessA = new Awareness(docA);
74
+ const awarenessB = new Awareness(docB);
75
+ // A provider does this over the network. Here, two docs in one page.
76
+ docA.on('update', (update, origin) => origin !== 'peer' && Y.applyUpdate(docB, update, 'peer'));
77
+ docB.on('update', (update, origin) => origin !== 'peer' && Y.applyUpdate(docA, update, 'peer'));
78
+ for (const [from, to] of [
79
+ [awarenessA, awarenessB],
80
+ [awarenessB, awarenessA],
81
+ ] as const)
82
+ from.on('update', ({ added, updated, removed }, origin) => {
83
+ if (origin === 'peer') return;
84
+ const changed = [...added, ...updated, ...removed];
85
+ applyAwarenessUpdate(to, encodeAwarenessUpdate(from, changed), 'peer');
86
+ });
87
+
88
+ const a = openReplica(docA, awarenessA, 'user-1', 'Ada');
89
+ const b = openReplica(docB, awarenessB, 'user-2', 'Grace');
90
+ a.editor.attach(document.getElementById('editor-a')!);
91
+ b.editor.attach(document.getElementById('editor-b')!);
92
+
93
+ // When a person leaves: destroy the editor, then the session. Peers stop showing them.
94
+ a.editor.destroy();
95
+ a.session.destroy();
96
+ ```
97
+
98
+ The first replica in an empty room seeds it from its deck. Later replicas adopt the room.
99
+
100
+ Your host must authenticate participants and authorize access to each document before connecting its provider. A `documentId` identifies a document; it does not grant access. Enforce read and write permissions in your provider or server, including update and awareness messages. Disconnect participants when their access ends. Use an encrypted connection for network transport.
101
+
102
+ Registering a module is the whole enablement story. Without modules, the free engine works the same: decks round-trip, comments are kept, and no replica attaches.
103
+
104
+ ## How it connects to the engine
105
+
106
+ ```mermaid
107
+ flowchart LR
108
+ A["host: collaboration session"] --> B["collaborationModule()"]
109
+ C["reviewModule()"] --> D["createPptxEditor({ modules })"]
110
+ B --> D
111
+ D --> E["resolveEditorModules: closed registry"]
112
+ E --> F["CollaborationDocumentPort over PptxDocumentStore"]
113
+ F -- "local ops" --> A
114
+ A -- "remote ops: applyRemote" --> F
115
+ ```
116
+
117
+ The seam is in `packages/core/src/editor/modules.ts`. It is closed, as in DOCX Editor: every contribution point is named there, and core never imports this package.
118
+
119
+ ## Tracked changes in PPTX
120
+
121
+ PresentationML has no tracked-change markup: there is no equivalent of WordprocessingML `w:ins` and `w:del`. Review in a PPTX file is comments only. So a PPTX Editor suggestion cannot live in the deck the way a `w:ins` or `w:del` revision lives in a DOCX file.
122
+
123
+ ## License
124
+
125
+ The EigenPal Pro License permits evaluation. Production use requires a commercial agreement. The package makes no network requests for licensing.
126
+
127
+ ## Room access
128
+
129
+ Your host must authenticate participants and authorize document access before connecting the provider. A `documentId` identifies a document; it does not grant access. Enforce read and write permissions in your provider or server, including update and awareness messages. Disconnect participants when their access ends. Use an encrypted connection for network transport.
@@ -0,0 +1,3 @@
1
+ # Third-party notices for @pptx-editor.dev/pro
2
+
3
+ This package bundles no third-party code.
@@ -0,0 +1,106 @@
1
+ import { ReviewDisplayMode, EditorModule, ReviewItem, EditorCollaborationSession, CollaborationIdentity, CollaborationFailureCode } from '@pptx-editor.dev/core/editor';
2
+ import { PptxPackage } from '@pptx-editor.dev/core/store';
3
+ import * as Y from 'yjs';
4
+
5
+ /** Accepted by every pro entry point. @public */
6
+ interface ProLicenseOptions {
7
+ /**
8
+ * Your license key. Optional: evaluation use is permitted, production use requires a
9
+ * commercial agreement under the EigenPal Pro License (see LICENSE.md).
10
+ */
11
+ readonly licenseKey?: string;
12
+ }
13
+
14
+ /** Options of `reviewModule`. @public */
15
+ interface ReviewModuleOptions extends ProLicenseOptions {
16
+ /** Display modes to unlock. Default: `final` and `markup`. */
17
+ readonly displayModes?: readonly ReviewDisplayMode[];
18
+ }
19
+ /**
20
+ * The review module. Register it with `createPptxEditor({ modules: [reviewModule()] })`.
21
+ *
22
+ * @public
23
+ */
24
+ declare function reviewModule(options?: ReviewModuleOptions): EditorModule;
25
+
26
+ /** Every legacy comment of every slide, in slide order and then file order. */
27
+ declare function legacyComments(pkg: PptxPackage): ReviewItem[];
28
+
29
+ /** Options of `collaborationModule`. @public */
30
+ interface CollaborationModuleOptions extends ProLicenseOptions {
31
+ /** A ready session, for example from `createYjsCollaborationSession`. */
32
+ readonly session: EditorCollaborationSession;
33
+ }
34
+ /**
35
+ * The collaboration module. Register it with
36
+ * `createPptxEditor({ modules: [collaborationModule({ session })] })`.
37
+ *
38
+ * @public
39
+ */
40
+ declare function collaborationModule(options: CollaborationModuleOptions): EditorModule;
41
+
42
+ /** The minimal awareness surface the session uses (`y-protocols/awareness`'s `Awareness`). */
43
+ interface AwarenessLike {
44
+ /** This replica's awareness client id. */
45
+ readonly clientID: number;
46
+ /** Every connected client's state, by client id. */
47
+ getStates(): Map<number, Record<string, unknown>>;
48
+ /** Set one field of this replica's state; peers see it on their next update. */
49
+ setLocalStateField(field: string, value: unknown): void;
50
+ /** Listen to changes of any client's state. */
51
+ on(event: 'change', handler: () => void): void;
52
+ /** Stop listening to state changes. */
53
+ off(event: 'change', handler: () => void): void;
54
+ }
55
+
56
+ /** Options of `createYjsCollaborationSession`. @public */
57
+ interface YjsCollaborationSessionOptions {
58
+ /** The shared document. The host connects it to a provider. */
59
+ readonly doc: Y.Doc;
60
+ /** The room's document identity. */
61
+ readonly documentId: string;
62
+ /** The local author. */
63
+ readonly identity: CollaborationIdentity;
64
+ /**
65
+ * Yjs awareness for presence (`new Awareness(doc)` from `y-protocols/awareness`), usually
66
+ * the provider's. Absent, the session lists only the local participant.
67
+ */
68
+ readonly awareness?: AwarenessLike;
69
+ }
70
+ /** A session over a Y.Doc. @public */
71
+ interface YjsCollaborationSession extends EditorCollaborationSession {
72
+ /**
73
+ * Report the provider's connection. `false` sets `disconnected` with
74
+ * `transport-disconnected`; edits continue and merge on reconnect. `true` returns to `ready`.
75
+ * Call it from the provider's status event.
76
+ */
77
+ setConnected(connected: boolean): void;
78
+ }
79
+ /**
80
+ * Create a session over a Y.Doc. Register it with `collaborationModule({ session })`. Throws
81
+ * `CollaborationSchemaError` for an invalid document id or identity.
82
+ *
83
+ * @public
84
+ */
85
+ declare function createYjsCollaborationSession(options: YjsCollaborationSessionOptions): YjsCollaborationSession;
86
+
87
+ /**
88
+ * Typed collaboration schema or trust-boundary failure, thrown for invalid factory input.
89
+ * Use `code` for application logic; `detail` is diagnostic information.
90
+ *
91
+ * @public
92
+ */
93
+ declare class CollaborationSchemaError extends Error {
94
+ /** Stable failure code. Branch on it. */
95
+ readonly code: CollaborationFailureCode;
96
+ /** Bounded diagnostic text for logs. Not a parsing contract. */
97
+ readonly detail?: string | undefined;
98
+ constructor(
99
+ /** Stable failure code. Branch on it. */
100
+ code: CollaborationFailureCode,
101
+ /** Bounded diagnostic text for logs. Not a parsing contract. */
102
+ detail?: string | undefined);
103
+ }
104
+
105
+ export { CollaborationSchemaError, collaborationModule, createYjsCollaborationSession, legacyComments, reviewModule };
106
+ export type { AwarenessLike, CollaborationModuleOptions, ProLicenseOptions, ReviewModuleOptions, YjsCollaborationSession, YjsCollaborationSessionOptions };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ var Ks;function mt(t){t!==void 0&&(Ks=t)}import{attr as Oe,binaryPartOf as $s,elements as Ut,parseXmlPart as Ws,mainPresentationPart as Gs,presentationInfo as Xs,relTargetByType as Fn,textOf as Bs,xmlPartOf as Us}from"@pptx-editor.dev/core/store";var zn="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Hs=`${zn}/comments`,Vs=`${zn}/commentAuthors`;function jn(t,e){let n=Us(t,e);if(n||!e)return n;let o=$s(t,e);if(!o)return;let s=Ws(e,new TextDecoder().decode(o));return s.ok?s.part:void 0}function qs(t){let e=Object.create(null),n=Gs(t);if(!n)return e;let o=jn(t,Fn(t,n,Vs));for(let s of Ut(o?.root)){if(s.local!=="cmAuthor")continue;let i=Oe(s,"id"),r=Oe(s,"name");i!==void 0&&r!==void 0&&(e[i]=r)}return e}function Bt(t,e){for(let n of Ut(t)){if(n.local===e)return n;let o=Bt(n,e);if(o)return o}}var _n=(t,e,n)=>`${t}#cm-${e}-${n}`;function Ht(t){let e=qs(t),n=[];for(let o of Xs(t).slides){let s=jn(t,Fn(t,o.partName,Hs));for(let i of Ut(s?.root)){if(i.local!=="cm")continue;let r=Oe(i,"authorId")??"",u=Oe(i,"idx")??"",l=Bt(i,"parentCm"),f=e[r],d=Oe(i,"dt");n.push({id:_n(o.partName,r,u),kind:"comment",slidePart:o.partName,text:Bs(Bt(i,"text")),...f!==void 0?{author:f}:{},...d!==void 0?{date:d}:{},...l?{parentId:_n(o.partName,Oe(l,"authorId")??"",Oe(l,"idx")??"")}:{}})}}return n}function Js(t={}){return mt(t.licenseKey),{id:"review",review:{displayModes:t.displayModes??["final","markup"],collectReviewItems:({package:e})=>Ht(e)}}}function Qs(t){return mt(t.licenseKey),{id:"collaboration",collaboration:{session:t.session}}}import*as me from"yjs";import{createCollaborationStatusTracker as wi}from"@pptx-editor.dev/core/editor";var Ke=class extends Error{constructor(n,o){let s=o?`${n}: ${o}`:n;super(n==="schema-version-mismatch"?`${s}
2
+ Collaboration upgrade required. Save local changes and use a compatible app version.`:s);this.code=n;this.detail=o;this.name="CollaborationSchemaError"}code;detail};import*as B from"yjs";import{buildReplicaPart as Wr}from"@pptx-editor.dev/core/store";import"yjs";var Vt=5,Zs="pptx-meta-v1",er="pptx-parts-v1",tr="pptx-binaries-v1",nr="pptx-nodes-v1",N=Object.freeze({part:"p",key:"k",shell:"s",attrs:"a",children:"c",text:"x"}),yt="",Kn=2**40,kt=Object.freeze({kind:"pptx-local"}),qt=Object.freeze({kind:"pptx-undo-repair"}),Jt=Object.freeze({kind:"pptx-redo-repair"}),Qt=Object.freeze({kind:"pptx-text-repair"}),Zt=Object.freeze({kind:"pptx-tidy"}),Ze=Object.freeze({kind:"pptx-undone-listing"}),en=Object.freeze({kind:"pptx-seed"}),et=Object.freeze({maxBinaryBytes:256*1024*1024,maxReadDepth:300,maxCopiesPerGroup:256});function $n(t){return{doc:t,meta:t.getMap(Zs),parts:t.getMap(er),binaries:t.getMap(tr),nodes:t.getMap(nr)}}function $e(t){if(typeof t!="object"||t===null)return null;let e=t;return e.kind==="binary"?{kind:"binary"}:e.kind==="xml"&&typeof e.root=="string"?{kind:"xml",root:e.root}:null}import{asciiFold as or}from"@pptx-editor.dev/core/store";var nn="http://schemas.openxmlformats.org/drawingml/2006/main",Un="http://schemas.openxmlformats.org/presentationml/2006/main",Y=t=>[t,[t]],ne=(t,e)=>[t,e],nt=["*",[]],ot=ne("fill",["noFill","solidFill","gradFill","blipFill","pattFill","grpFill"]),sr=ne("fill",["noFill","solidFill","gradFill","pattFill"]),xt=ne("effect",["effectLst","effectDag"]),rr=[ne("color",["scrgbClr","srgbClr","hslClr","sysClr","schemeClr","prstClr"])],Wn=[Y("xfrm"),ne("geometry",["custGeom","prstGeom"]),ot,Y("ln"),xt,Y("scene3d"),Y("sp3d"),Y("extLst")],Gn=[sr,ne("dash",["prstDash","custDash"]),ne("join",["round","bevel","miter"]),Y("headEnd"),Y("tailEnd"),Y("extLst")],tn=[Y("ln"),ot,xt,Y("highlight"),ne("uLn",["uLnTx","uLn"]),ne("uFill",["uFillTx","uFill"]),Y("latin"),Y("ea"),Y("cs"),Y("sym"),Y("hlinkClick"),Y("hlinkMouseOver"),Y("rtl"),Y("extLst")],tt=t=>[Y("cNvPr"),Y(t),Y("nvPr")],wt=t=>[Y(t),Y("extLst")],on=["lnL","lnR","lnT","lnB","lnTlToBr","lnBlToTr"],ir=Object.assign(Object.create(null),{sld:[Y("cSld"),Y("clrMapOvr"),Y("transition"),Y("timing"),Y("extLst")],cSld:[Y("bg"),Y("spTree"),Y("custDataLst"),Y("controls"),Y("extLst")],bg:[ne("background",["bgPr","bgRef"])],bgPr:[ot,xt,Y("extLst")],spPr:Wn,grpSpPr:Wn,ln:Gn,...Object.fromEntries(on.map(t=>[t,Gn])),effectLst:[Y("blur"),Y("fillOverlay"),Y("glow"),Y("innerShdw"),Y("outerShdw"),Y("prstShdw"),Y("reflection"),Y("softEdge")],...Object.fromEntries(["solidFill","outerShdw","innerShdw","prstShdw","glow","highlight","buClr","lnRef","fillRef","effectRef","fontRef"].map(t=>[t,rr])),style:[Y("lnRef"),Y("fillRef"),Y("effectRef"),Y("fontRef")],sp:[Y("nvSpPr"),Y("spPr"),Y("style"),Y("txBody"),Y("extLst")],pic:[Y("nvPicPr"),Y("blipFill"),Y("spPr"),Y("style"),Y("extLst")],cxnSp:[Y("nvCxnSpPr"),Y("spPr"),Y("style"),Y("extLst")],grpSp:[Y("nvGrpSpPr"),Y("grpSpPr"),nt,Y("extLst")],graphicFrame:[Y("nvGraphicFramePr"),Y("xfrm"),Y("graphic"),Y("extLst")],nvSpPr:tt("cNvSpPr"),nvPicPr:tt("cNvPicPr"),nvCxnSpPr:tt("cNvCxnSpPr"),nvGrpSpPr:tt("cNvGrpSpPr"),nvGraphicFramePr:tt("cNvGraphicFramePr"),cNvPr:[Y("hlinkClick"),Y("hlinkHover"),Y("extLst")],nvPr:[Y("ph"),ne("media",["audioCd","wavAudioFile","audioFile","videoFile","quickTimeFile"]),Y("custDataLst"),Y("extLst")],cNvSpPr:wt("spLocks"),cNvPicPr:wt("picLocks"),cNvGrpSpPr:wt("grpSpLocks"),cNvGraphicFramePr:wt("graphicFrameLocks"),cNvCxnSpPr:[Y("cxnSpLocks"),Y("stCxn"),Y("endCxn"),Y("extLst")],xfrm:[Y("off"),Y("ext"),Y("chOff"),Y("chExt")],blipFill:[Y("blip"),Y("srcRect"),ne("fillMode",["tile","stretch"])],txBody:[Y("bodyPr"),Y("lstStyle"),nt],bodyPr:[Y("prstTxWarp"),ne("autofit",["noAutofit","normAutofit","spAutoFit"]),Y("scene3d"),ne("text3d",["sp3d","flatTx"]),Y("extLst")],p:[Y("pPr"),nt,Y("endParaRPr")],r:[Y("rPr"),Y("t")],fld:[Y("rPr"),Y("pPr"),Y("t")],br:[Y("rPr")],pPr:[Y("lnSpc"),Y("spcBef"),Y("spcAft"),ne("buClr",["buClrTx","buClr"]),ne("buSz",["buSzTx","buSzPct","buSzPts"]),ne("buFont",["buFontTx","buFont"]),ne("bullet",["buNone","buAutoNum","buChar","buBlip"]),Y("tabLst"),Y("defRPr"),Y("extLst")],rPr:tn,defRPr:tn,endParaRPr:tn,tbl:[Y("tblPr"),Y("tblGrid"),nt],tblPr:[ot,xt,ne("tableStyle",["tableStyle","tableStyleId"]),Y("extLst")],tc:[Y("txBody"),Y("tcPr"),Y("extLst")],tcPr:[...on.map(Y),Y("cell3D"),ot,Y("headers"),Y("extLst")]}),rn=t=>t.ns===nn||t.ns===Un,cr=new Set(["sld","cSld","bg","bgPr","sp","pic","cxnSp","grpSp","graphicFrame","nvSpPr","nvPicPr","nvCxnSpPr","nvGrpSpPr","nvGraphicFramePr","nvPr","style"]);function Hn(t){if(!(!rn(t)||cr.has(t.local)&&t.ns!==Un))return ir[t.local]}function Vn(t,e){return rn(e)?t.findIndex(([,n])=>n.includes(e.local)):-1}var ar=new Set(["pPr","rPr","defRPr","endParaRPr","bodyPr","tblPr","tcPr","ln",...on]);function qn(t){return rn(t)&&ar.has(t.local)}function lr(t,e){let n=Hn(t),o=n?Vn(n,e):-1;return o<0?void 0:n[o][0]}var dr=(t,e)=>t.ns===nn&&t.local==="tc"&&e.ns===nn&&e.local==="txBody",fr="http://schemas.openxmlformats.org/package/2006/content-types",ur="http://schemas.openxmlformats.org/package/2006/relationships",pr=Object.assign(Object.create(null),{[`${fr}|Types`]:{Default:{attr:"Extension",caseless:!0},Override:{attr:"PartName",caseless:!0}},[`${ur}|Relationships`]:{Relationship:{attr:"Id",caseless:!1}}});function We(t,e,n){let o=pr[`${t.ns}|${t.local}`];if(o&&Object.prototype.hasOwnProperty.call(o,e.local)){let{attr:i,caseless:r}=o[e.local],u=n(i);return u===void 0?void 0:{slot:`${e.local}:${r?or(u):u}`,rule:"key"}}let s=lr(t,e);if(!(s===void 0||dr(t,e)))return{slot:s,rule:qn(e)?"merge":"first"}}function Ge(t,e,n){let o=Hn(t);if(!o)return e;let s=o.indexOf(nt),i=-1,r=!0,u=e.map((l,f)=>{let d=n(l),c=d?Vn(o,d):-1,g=c>=0?c:s>=0?s:i;return g<i&&(r=!1),i=g,{c:l,rank:g,i:f}});return r?e:u.sort((l,f)=>l.rank-f.rank||l.i-f.i).map(l=>l.c)}var Xn=t=>`${t.ns}${yt}${t.local}`,ge=t=>t.slice(0,Math.max(0,t.indexOf("."))),St="_",Bn=t=>t.slice(t.indexOf(".")+1).startsWith(St);function Jn(t,e){let n=t.get(e);return n||(n={merge:!1,companions:[],attrFrom:new Map,childFrom:new Map,shadowed:new Map},t.set(e,n)),n}var sn=(t,e)=>t.attrs?.find(n=>n.ns===""&&n.local===e)?.value;function gr(t,e,n){let o=Jn(n,t.key);o.merge=!0;let s=new Map;for(let a of t.attrs??[])s.set(Xn(a),a);let i=a=>"text"in a?void 0:We(t,a,h=>sn(a,h))?.slot,r=t.children??[],u=new Set(r.map(i)),l=[...r],f=new Map;for(let a of e){o.companions.push(a.key);for(let h of a.attrs??[]){let p=Xn(h);s.has(p)||(s.set(p,h),o.attrFrom.set(p,a.key))}for(let h of a.children??[]){if("text"in h)continue;let p=i(h);if(p===void 0){l.push(h),f.set(h.key,a.key);continue}if(u.has(p)&&!qn(h)){o.shadowed.set(h.key,p);continue}u.add(p),l.push(h),f.set(h.key,a.key)}}let d=cn(t,l,n);if(!d)return null;for(let a of d){let h="text"in a?void 0:f.get(a.key);h!==void 0&&o.childFrom.set(a.key,h)}let c=Ge(t,d,a=>"text"in a?void 0:a),g=[...s.entries()].sort(([a],[h])=>a<h?-1:a>h?1:0);return{...t,attrs:g.map(([,a])=>a),children:[...c]}}function cn(t,e,n){let o=new Map,s=[],i=new Map;for(let r of e){let u="text"in r?void 0:We(t,r,g=>sn(r,g)),l=u?o.get(u.slot):void 0,f=l===void 0?void 0:s[l],d=f!==void 0&&!(Bn(f.key)&&Bn(r.key));if(u&&l===void 0&&o.set(u.slot,s.length),!d){s.push(r);continue}let c=i.get(l);if(c||i.set(l,c=[]),c.length>=et.maxCopiesPerGroup)return null;c.push(r)}for(let[r,u]of i){let l=s[r];if(We(t,l,f=>sn(l,f))?.rule==="merge"){let f=gr(l,u,n);if(!f)return null;s[r]=f}else{let f=Jn(n,l.key);for(let d of u)f.companions.push(d.key)}}return s}import*as fe from"yjs";var z=Object.freeze({splitFrom:"sf",splitBaseText:"sb",splitAt:"sa",splitLength:"sl",splitGeneration:"sg",splitEdited:"se",splitBreak:"sk",movedFrom:"mf",movedIndex:"mi",movedClock:"mq",movedTo:"mt",movedEarlier:"mo",removedWith:"rw"}),Ne="pptx-pieces-v1",at="pptx-moves-v1",bt="pptx-splits-v1",it=2e4,no=64,oo=`${z.removedWith}.`,un=2**31,pn=300,gn=8,Xe=4096,Ae=t=>Number.isSafeInteger(t)&&t>=0,hr=t=>Number.isSafeInteger(t)&&t>=1&&t<un,so="http://schemas.openxmlformats.org/drawingml/2006/main",ct=new Set,xe=t=>t?.type==="element",hn=t=>t===z.removedWith||t.startsWith(oo);function he(t){for(let e of t.keys())if(hn(e))return!0;return!1}function Qn(t,e,n){t.set(`${oo}${e}`,n)}var ln=t=>t.children.filter(xe);function st(t){let n=ln(t).find(o=>o.local==="t")?.children.find(o=>o.type==="text");return n?.type==="text"?n.value:""}function ro(t){if(!t||"text"in t)return"";let e=t.children?.find(o=>!("text"in o)&&o.local==="t"),n=e&&!("text"in e)?e.children?.find(o=>"text"in o):void 0;return n&&"text"in n?n.text:""}function io(t){let e=2166136261;for(let n=0;n<t.length;n+=1)e^=t.charCodeAt(n),e=Math.imul(e,16777619)>>>0;return e.toString(36)}function dn(t,e,n,o){let s=`${t}\0${io(e)}\0${n}`;return o===void 0?s:`${s}\0${o}`}var Zn=t=>{let e=Number.parseInt(t,36);return Number.isFinite(e)?e:Number.MAX_SAFE_INTEGER};function co(t,e,n,o,s){if(o.size===0)return;let i=m=>{let k=s.get(m),S=k===void 0?void 0:t.nodes.get(k);return S instanceof fe.Map?S:void 0},r=t.doc.clientID.toString(36),u=new Map,l=[],f=new Set,d=new Set,c=m=>{for(let k of ln(m)){if(k.local!=="r"||d.has(k.id))continue;let S=o.get(k.id);if(!xe(S)||S===k||st(S)===st(k))continue;let w=i(k.id);w&&typeof w.get(z.splitFrom)=="string"&&w.get(z.splitEdited)!==!0&&w.set(z.splitEdited,!0)}},g=m=>{let k=ln(m);k.forEach((S,w)=>{if(S.local!=="r"||!o.has(S.id))return;let A=o.get(S.id);if(!xe(A)||A===S)return;let R=st(A),P=st(S);if(R.length<=P.length||!R.startsWith(P))return;let b=R.slice(P.length),I=[],C="",j=[];for(let D=w+1;D<k.length&&C.length<b.length;D+=1){let K=k[D];if(K.local==="br"&&!o.has(K.id)){j.push({el:K,at:P.length+C.length});continue}if(K.local!=="r"||o.has(K.id))break;let T=st(K);I.push({el:K,at:P.length+C.length,length:T.length}),C+=T}let _=s.get(S.id);if(C!==b||_===void 0||I.length===0)return;d.add(S.id);let E=`${_}\0${io(R)}`,O=Math.min((ao(t).latest.get(E)??0)+1,un-1);for(let{el:D,at:K,length:T}of I){let F=i(D.id);if(!F||F.has(z.splitFrom))continue;F.set(z.splitFrom,_),F.set(z.splitBaseText,R),F.set(z.splitAt,K),F.set(z.splitLength,T),F.set(z.splitGeneration,O);let M=s.get(D.id);M!==void 0&&t.doc.getMap(Ne).set(M,e)}for(let{el:D,at:K}of j){let T=i(D.id);!T||T.has(z.splitBreak)||(T.set(z.splitBreak,dn(_,R,O)),T.set(z.splitAt,K))}t.doc.getMap(bt).set(dn(_,R,O,r),P.length)})},a=(m,k)=>{let S=o.get(m.id);if(S===m)return;let w=s.get(m.id),A=w===void 0?k:[w,...k].slice(0,pn),R=xe(S)?new Set(S.children.map(P=>P.id)):new Set;for(let P of m.children)f.add(P.id),!R.has(P.id)&&o.has(P.id)&&l.push({node:P,path:A});if(xe(S)){let P=new Set(m.children.map(b=>b.id));for(let b of S.children)P.has(b.id)||u.set(b.id,b)}m.ns===so&&m.local==="p"&&xe(S)&&(g(m),c(m));for(let P of m.children)xe(P)&&a(P,A)};if(a(n,[]),l.length>0){let m=new Map;for(let w of o.values())xe(w)&&w.children.forEach((A,R)=>m.set(A.id,{parent:w.id,index:R}));let k=t.doc.getMap(at),S=fe.getState(t.doc.store,t.doc.clientID);for(let{node:w,path:A}of l){let R=m.get(w.id),P=R===void 0?void 0:s.get(R.parent),b=s.get(w.id),I=i(w.id);if(!I||!R||P===void 0||b===void 0)continue;let C=I.get(z.movedFrom);if(typeof C=="string"&&C!==P){let j=I.get(z.movedEarlier),_=Array.isArray(j)?j.filter(E=>typeof E=="string"&&E!==C):[];I.set(z.movedEarlier,[C,..._].slice(0,gn))}I.set(z.movedFrom,P),I.set(z.movedIndex,R.index),I.set(z.movedClock,S),I.set(z.movedTo,A),k.set(b,e)}}let h=t.doc.getMap(Ne),p,y,x=m=>(p??=eo(n,s)).has(m);for(let[m,k]of u){if(f.has(m))continue;let S=new Set,w=[k];for(;w.length>0&&S.size<=it;){let b=w.pop(),I=s.get(b.id);if(I!==void 0&&S.add(I),xe(b))for(let C of b.children)f.has(C.id)||w.push(C)}let A=s.get(m);A!==void 0&&yr(t,A,S,x);let R=i(m);if(!R||S.size>it)continue;let P=[...S];Qn(R,r,P);for(let b of S){if(b===A||!h.has(b)||(p??=eo(n,s)).has(b))continue;let I=t.nodes.get(b);!(I instanceof fe.Map)||he(I)||(y??=new Set([...o.keys()].flatMap(C=>s.get(C)??[])),!(!y.has(b)&&mr(t,e,I,p))&&Qn(I,r,[b]))}}}function eo(t,e){let n=new Set,o=[t];for(;o.length>0;){let s=o.pop(),i=e.get(s.id);if(i!==void 0&&n.add(i),xe(s))for(let r of s.children)o.push(r)}return n}function mr(t,e,n,o){let s=Te(n),i=s?Be(t)(s.group):void 0;if(!s||i===void 0)return!1;let r=0;for(let[u,l]of t.doc.getMap(Ne).entries())if(!(l!==e||ge(u)!==i||!o.has(u))&&((r+=1)>Xe||Te(t.nodes.get(u))?.group===s.group))return!0;return!1}function yr(t,e,n,o){let s=[e],i=new Set;for(;s.length>0&&n.size<=it;){let r=s.pop();if(i.has(r))continue;i.add(r),n.add(r);let u=t.nodes.get(r),l=u instanceof fe.Map?u.get(N.children):void 0;if(l instanceof fe.Array)for(let f of l.toArray())typeof f=="string"&&!i.has(f)&&!o(f)&&s.push(f)}}var an=new WeakMap,to=new WeakSet;function ao(t){let e=t.doc.getMap(bt),n=an.get(e);if(n)return n;let o={groups:new Map,latest:new Map};for(let[s,i]of e.entries()){let r=s.split("\0");if(!Ae(i)||r.length!==4)continue;let[u,l,f,d]=r,c=Number(f);if(!Number.isSafeInteger(c)||c<1||c>=un)continue;let g=`${u}\0${l}`,a=`${g}\0${c}`,h=o.groups.get(a);h||o.groups.set(a,h=new Map),h.set(d,i),o.latest.set(g,Math.max(o.latest.get(g)??0,c))}return an.set(e,o),to.has(e)||(to.add(e),e.observe(()=>an.delete(e))),o}function Te(t){if(!(t instanceof fe.Map))return null;let e=t.get(z.splitFrom),n=t.get(z.splitBaseText),o=t.get(z.splitAt),s=t.get(z.splitLength),i=t.get(z.splitGeneration);return typeof e!="string"||typeof n!="string"||!Ae(o)||!Ae(s)||!hr(i)?null:{from:e,group:dn(e,n,i),original:n.slice(o,o+s),at:o,edited:t.get(z.splitEdited)===!0}}function Be(t){let{groups:e}=ao(t),n=new Map;return o=>{if(n.has(o))return n.get(o);let s=e.get(o),i;if(s&&s.size>=2){let r;for(let[u,l]of s)(!r||l<r[1]||l===r[1]&&Zn(u)<Zn(r[0]))&&(r=[u,l]);i=r?.[0]}return n.set(o,i),i}}function lo(t,e,n){let o=new Map,s=new Set,i=r=>{let u=o.get(r);if(u!==void 0||o.has(r))return u??null;let l=e(r);if(!l||l.edited||s.has(r)||s.size>Xe)return null;s.add(r);let f=n(r);for(let d of t.get(r)??[]){let c=i(d);if(c===null){f=null;break}f+=c}return s.delete(r),o.set(r,f),f};return i}function fn(t){let e=new Map;for(let[o,s]of t){let i=e.get(s.from);i?i.push([o,s.at]):e.set(s.from,[[o,s.at]])}let n=new Map;for(let[o,s]of e)n.set(o,s.sort((i,r)=>i[1]-r[1]||(i[0]<r[0]?-1:i[0]>r[0]?1:0)).map(([i])=>i));return n}function fo(t,e){let n=0;for(let o=0;o<e.length&&n<t.length;o+=1)e[o]===t[n]&&(n+=1);return n===t.length}function uo(t,e,n,o,s=ct){if(e.ns!==so||e.local!=="p")return n;let i=new Map,r=new Map;for(let a of n){if("text"in a)continue;let h=Te(t.nodes.get(a.key));if(h){if(i.size>=Xe)return n;i.set(a.key,h),r.set(a.key,ro(a))}}if(i.size===0)return n;let u=fn(i),l=lo(u,a=>i.get(a),a=>r.get(a)??""),f=Be(t),d=new Set;for(let[a,h]of i){let p=f(h.group);if(p===void 0||ge(a)===p||s.has(h.group))continue;let y=l(a);y!==null&&fo(y,h.original)&&d.add(a)}if(d.size===0)return n;let c=[...d];for(;c.length>0;)for(let a of u.get(c.pop())??[])d.has(a)||(d.add(a),c.push(a));for(let a of d)o.add(a);let g=n.filter(a=>"text"in a||!d.has(a.key));return kr(t,g,d,i,f)}function kr(t,e,n,o,s){let i=new Set;for(let f of n){let d=o.get(f);d&&i.add(`${d.group}\0${ge(f)}`)}let r=new Map;for(let f of e){if("text"in f||f.local!=="br")continue;let d=t.nodes.get(f.key);if(!(d instanceof fe.Map))continue;let c=d.get(z.splitBreak),g=d.get(z.splitAt);if(typeof c!="string"||!Ae(g)||!i.has(`${c}\0${ge(f.key)}`))continue;let a;for(let h of e){let p="text"in h?void 0:o.get(h.key);!p||p.group!==c||ge(h.key)!==s(c)||p.at<g||(!a||p.at<a[1])&&(a=[h.key,p.at])}a&&r.set(f.key,a[0])}if(r.size===0)return e;let u=new Map;for(let f of e){let d=r.get(f.key);if(d===void 0)continue;let c=u.get(d);c?c.push(f):u.set(d,[f])}let l=[];for(let f of e)if(!r.has(f.key)){for(let d of u.get(f.key)??[])l.push(d);l.push(f)}return l}function po(t,e,n){if(!n||n.size===0)return e;let o=new Set(e),s=[...e],i=-1;for(let r of t){let u=s.indexOf(r);if(u>=0&&o.has(r)){i=u;continue}!n.has(r)||o.has(r)||(s.splice(i+1,0,r),i+=1)}return s}function go(t,e,n,o,s=ct){let i=t.doc.getMap(Ne);if(i.size===0)return n;let r=new Map,u=E=>{(E.children??[]).forEach((O,D)=>{r.set(O.key,{parent:E,at:D,order:r.size}),"text"in O||u(O)})};u(n);let l=new Map;for(let[E,O]of i.entries()){if(O!==e)continue;let D=t.nodes.get(E);if(!(D instanceof fe.Map)||he(D))continue;let K=Te(D);K&&(l.size>=Xe&&(r.has(E)||l.size>=2*Xe)||l.set(E,K))}let f=Be(t),d=new Map,c=E=>{let O=d.get(E);if(O===void 0){let D=r.get(E);O=ro(D?D.parent.children[D.at]:o(E,new Set,1)??void 0),d.set(E,O)}return O},g=lo(fn(l),E=>l.get(E),c),a=new Map;for(let[E,O]of l){if(ge(E)!==f(O.group))continue;let D=r.get(E)?.order;if(D===void 0)continue;let K=a.get(O.group);(!K||D>K.order)&&a.set(O.group,{key:E,order:D})}let h=new Map,p=E=>{let O=l.get(E).from;O!==E&&h.set(E,O)},y=[];for(let E of[...l.keys()].sort()){let O=l.get(E),D=f(O.group);if(D===void 0||ge(E)===D){s.has(E)&&!r.has(E)&&y.push(E);continue}let K=g(E);if(K!==null&&fo(K,O.original))continue;let T=a.get(O.group)?.key??(r.has(O.from)?O.from:void 0);T!==void 0&&T!==E&&h.set(E,T)}let x=new Set(y);for(let E of y){let O=l.get(E).from;(r.has(O)||x.has(O))&&p(E)}let m=fn(l),k=[...h.keys()];for(;k.length>0;)for(let E of m.get(k.pop())??[])!h.has(E)&&r.has(E)&&(p(E),k.push(E));if(h.size===0)return n;let S=new Map,w=new Set(r.keys());for(let E of h.keys()){let O=r.get(E),D=O?O.parent.children[O.at]:o(E,w,1);D&&S.set(E,D)}let A=new Map,R=E=>{let O=A.get(E);if(O!==void 0)return O;let D=h.get(E);A.set(E,!1);let K=D===void 0?r.has(E):S.has(E)&&R(D);return A.set(E,K),K},P=new Map,b=new Set;for(let[E,O]of h){let D=S.get(E);if(!D||!R(E))continue;b.add(E);let K=P.get(O);K?K.push(D):P.set(O,[D])}if(b.size===0)return n;let I=(E,O)=>{let D=l.get(O);return D?.from===E?D.at:1/0};for(let[E,O]of P)O.sort((D,K)=>I(E,D.key)-I(E,K.key)||(D.key<K.key?-1:D.key>K.key?1:0));let C=new Set,j=(E,O)=>{for(let D of P.get(E)??[])C.has(D.key)||(C.add(D.key),O.push(D),j(D.key,O))},_=E=>{let O=[];for(let D of E.children??[])b.has(D.key)||(O.push("text"in D?D:_(D)),j(D.key,O));return{...E,children:O}};return _(n)}var rt=Object.freeze({unseenWinners:ct,lost:ct});function lt(t,e,n,o=ct){let s=t.doc.getMap(Ne);if(s.size===0)return rt;let i=Be(t),r=new Set,u=new Map,l=0;for(let[y,x]of s.entries()){if(x!==e)continue;let m=t.nodes.get(y);if(!(m instanceof fe.Map)||m.get(N.part)!==e)continue;let k=Te(m);if(k){if(he(m)){ge(y)===i(k.group)&&r.add(k.group);continue}if((l+=1)>Xe)return rt;u.set(y,k)}}if(u.size===0)return rt;let f=new Set,d=[n];for(;d.length>0;){let y=d.pop();if(f.has(y))continue;f.add(y);let x=t.nodes.get(y);if(!(x instanceof fe.Map)||x.get(N.part)!==e)continue;let m=x.get(N.children);if(m instanceof fe.Array)for(let k of m.toArray())typeof k=="string"&&!f.has(k)&&d.push(k)}let c=new Set,g=new Map;for(let[y,x]of u){let m=ge(y)===i(x.group);if(f.has(y)||o.has(y)){m&&r.add(x.group);continue}if(c.add(y),!m)continue;let k=g.get(x.group);k?k.push(y):g.set(x.group,[y])}let a=new Map,h=y=>{let x=a.get(y);if(x!==void 0)return x;a.set(y,!1);let m=u.get(y)?.from,k=m!==void 0&&(f.has(m)||o.has(m)||c.has(m)&&h(m));return a.set(y,k),k},p=new Set;for(let[y,x]of g)!r.has(y)&&!x.some(h)&&p.add(y);return{unseenWinners:p,lost:c}}import*as Mt from"yjs";var wr=1024;function xr(t){if(!(t instanceof Mt.Map))return null;let e=null,n=0;for(let[o,s]of t.entries())if(!(!hn(o)||!Array.isArray(s))){if(s.length>it+1||(n+=1)>no)return"all";e??=new Set;for(let i of s)typeof i=="string"&&e.add(i)}return e}function Sr(t,e,n,o,s){if(n.length>pn)return null;for(let i of n){if(typeof i!="string"||o.has(i))return null;let r=s.get(i);if(r===void 0&&(r=xr(t.nodes.get(i)),s.set(i,r)),r==="all")return null;if(r)return r.has(e)?null:i}return null}var mn=(t,e)=>t<e?-1:t>e?1:0,yn=class extends Set{#e;constructor(e){super(),this.#e=e}has(e){return this.#e.has(e)||super.has(e)}};function mo(t,e,n,o,s){let i=t.doc.getMap(at);if(i.size===0)return n;let r=new Map,u=new Map,l=new Map,f=(R,P,b)=>{if(r.set(R.key,P),l.set(R.key,l.size),b!==null&&u.set(R.key,b),!("text"in R))for(let I of R.children??[])f(I,P+1,R.key)};f(n,0,null);let d=[],c=[],g=new Map,a,h=R=>{if(!a){a=new Map;for(let P of i.keys()){if(!u.has(P))continue;let b=t.nodes.get(P),I=b instanceof Mt.Map?b.get(z.movedFrom):void 0;if(typeof I!="string")continue;let C=a.get(I);(C===void 0||l.get(P)>l.get(C))&&a.set(I,P)}}return a.get(R)};for(let[R,P]of i.entries()){if(P!==e||r.has(R))continue;let b=t.nodes.get(R);if(!(b instanceof Mt.Map)||b.get(N.part)!==e||he(b))continue;let I=b.get(z.movedFrom),C=b.get(z.movedTo);if(typeof I!="string"||!Array.isArray(C))continue;let j=b.get(z.movedEarlier),_=r.has(I)?I:(Array.isArray(j)?j.slice(0,gn):[]).find(T=>typeof T=="string"&&r.has(T)),E=b.get(z.movedIndex),O=b.get(z.movedClock),D=typeof O=="number"&&Number.isFinite(O)?O:0,K=Sr(t,R,C,r,g);if(K!==null){if(d.length+c.length>=wr)return n;if(_!==void 0){let T=_===I&&Ae(E)?E:1/0;d.push({key:R,from:_,index:T,clock:D,to:C})}else c.push({key:R,last:I,removed:K,index:Ae(E)?E:1/0,clock:D,to:C})}}let p=new Map,y=c,x=0;for(;y.length>0;){let R=[],P=[];for(let b of y){let I=p.get(b.removed),C=I?void 0:h(b.removed),j=I?I.into:C===void 0?void 0:u.get(C),_=I?I.key:C;_===void 0||j===void 0?P.push(b):R.push({...b,after:_,into:j})}if(R.length===0)break;R.sort((b,I)=>b.clock-I.clock||b.index-I.index||mn(b.key,I.key));for(let b of R)d.push({...b,from:b.into,seq:x++}),p.set(b.last,{key:b.key,into:b.into});y=P}if(d.length===0)return n;let m=new Set(d.map(R=>R.key)),k=new Map(d.map(R=>[R.key,R.to.filter(P=>typeof P=="string"&&m.has(P)).length]));d.sort((R,P)=>k.get(R.key)-k.get(P.key)||mn(R.key,P.key));let S=new yn(new Set(r.keys())),w=new Map;for(let R of d){let P=o(R.key,S,r.get(R.from)+1);if(!P)continue;s?.add(P.key);let b={node:P,index:R.index,clock:R.clock,after:R.after,seq:R.seq??0},I=w.get(R.from);I?I.push(b):w.set(R.from,[b])}if(w.size===0)return n;let A=R=>{let P=w.get(R.key),b=(R.children??[]).map(O=>"text"in O?O:A(O));if(!P)return{...R,children:b};let I=[...b],C=P.filter(O=>O.after===void 0).sort((O,D)=>D.clock-O.clock||O.index-D.index||mn(O.node.key,D.node.key));for(let{node:O,index:D}of C)I.splice(Math.min(D,I.length),0,O);let j=P.filter(O=>O.after!==void 0).sort((O,D)=>O.seq-D.seq),_=new Map;for(let{node:O,after:D}of j){let K=_.get(D)??D,T=I.findIndex(F=>F.key===K);I.splice(T<0?I.length:T+1,0,O),_.set(D,O.key)}let E={ns:R.ns,local:R.local};return{...R,children:[...Ge(E,I,O=>"text"in O?void 0:O)]}};return A(n)}function Rt(t){let e=new Set,n=[t];for(;n.length>0;){let o=n.pop();if(e.add(o.key),!("text"in o))for(let s of o.children??[])n.push(s)}return e}var ho=(t,e)=>t.size===e.size&&[...t].every(n=>e.has(n));function yo(t,e){return ho(t.lost,e.lost)&&ho(t.unseenWinners,e.unseenWinners)}import*as ft from"yjs";import{children as kn,elements as Ue,isStructureEdited as br,path as ko,TABLE_MAX_COLUMNS as Mr,TABLE_MAX_ROWS as Rr,tableGridOf as Yr}from"@pptx-editor.dev/core/store";var Yt=Object.freeze({holder:"mh",cover:"cv."}),xn="http://schemas.openxmlformats.org/drawingml/2006/main",Er="http://schemas.openxmlformats.org/presentationml/2006/main",It=256,wo=4096,dt=t=>t?.type==="element",Et=(t,e)=>!!t&&!("text"in t)&&t.ns===xn&&t.local===e;function Ir(t){return(Ue(t).find(n=>n.local==="t")?.children??[]).map(n=>n.type==="text"?n.value:"").join("")}function Sn(t){return Ue(t).some(e=>e.local==="br"||(e.local==="r"||e.local==="fld")&&Ir(e).length>0)}function xo(t){return"text"in t?!1:(t.children??[]).some(e=>{if("text"in e||!(e.local==="br"||e.local==="r"||e.local==="fld"))return!1;if(e.local==="br")return!0;let n=e.children?.find(o=>!("text"in o)&&o.local==="t");return!!n&&!("text"in n)&&(n.children??[]).some(o=>"text"in o&&o.text!=="")})}function So(t,e){let n=[],o=(s,i)=>{if(s.ns===Er&&s.local==="graphicFrame"){n.push(s);return}if(i<It)for(let r of e(s))o(r,i+1)};return o(t,0),n}function bo(t){let e=ko(t,"a:graphic","a:graphicData","a:tbl"),n=Math.min(kn(ko(e,"a:tblGrid"),"a:gridCol").length,Mr),o=kn(e,"a:tr").slice(0,Rr).map(r=>kn(r,"a:tc"));if(n===0||o.length===0)return[];let s=Yr(t,o,n),i=[];return o.forEach((r,u)=>r.slice(0,n).forEach((l,f)=>{let d=s.blocks[s.owner[u*n+f]],c=d&&o[d.row][d.col];c&&(d.row!==u||d.col!==f)&&i.push({tc:l,over:c})})),i}var wn=t=>Ue(t).filter(e=>e.ns===xn&&e.local==="txBody");function Mo(t){let e=new Set;if(!(t instanceof ft.Map))return e;for(let[n,o]of t.entries())if(!(!n.startsWith(Yt.cover)||!Array.isArray(o))){if(o.length>wo)return"all";for(let s of o)typeof s=="string"&&e.add(s)}return e}function Ro(t,e,n,o){if(n.size===0)return;let s=d=>{let c=o.get(d),g=c===void 0?void 0:t.nodes.get(c);return g instanceof ft.Map?g:void 0},i=new Set,r=[],u=(d,c)=>{let g=n.get(d.id);if(g!==d){for(let a of d.children)i.add(a.id);if(d.ns===xn&&d.local==="txBody"&&dt(g)){let a=new Set(d.children.map(p=>p.id)),h=g.children.filter(p=>dt(p)&&p.local==="p");h.length>0&&h.every(p=>!a.has(p.id))&&r.push({body:d,old:g})}if(c<It)for(let a of d.children)dt(a)&&u(a,c+1)}};u(e,0);for(let{body:d,old:c}of r)if(c.children.filter(a=>dt(a)&&a.local==="p").every(a=>i.has(a.id)))for(let a of d.children)dt(a)&&a.local==="p"&&!n.has(a.id)&&!Sn(a)&&s(a.id)?.set(Yt.holder,!0);let l=`${Yt.cover}${t.doc.clientID.toString(36)}`,f=d=>Ue(d).filter(c=>n.get(c.id)!==c);for(let d of So(e,f))for(let{tc:c}of bo(d)){let g=s(c.id),a=wn(c);if(!g||a.length===0)continue;let h=Mo(g);if(h==="all")continue;let p=a.flatMap(m=>Ue(m).filter(k=>k.local==="p")).map(m=>o.get(m.id)).filter(m=>m!==void 0&&!h.has(m));if(p.length===0)continue;let y=g.get(l),x=Array.isArray(y)?y.filter(m=>typeof m=="string"):[];g.set(l,[...x,...p].slice(0,wo+1))}}function Yo(t,e){let n=new Map(t);return n.delete(e),n}function Eo(t,e,n){let o=[];if(!e||e.size===0)return o;let s=(i,r)=>{let u=n.get(i.id);if(u!==void 0&&e.has(u)&&o.push(i),r<It)for(let l of Ue(i))s(l,r+1)};return s(t,0),o}function Io(t,e){e.set(t.key,t);let n=(t.children??[]).map(o=>"text"in o?{type:"text",id:o.key,value:o.text}:Io(o,e));return{type:"element",id:t.key,kind:"generic",ns:t.ns,local:t.local,...t.prefix?{prefix:t.prefix}:{},nsDecls:[],attrs:t.attrs??[],children:n}}function vr(t,e,n,o,s){let i=new Map,r=Io(n,i),u=br(r);for(let{tc:l,over:f}of bo(r)){let d=wn(f)[0],c=d&&i.get(d.id);if(!c)continue;let g=Mo(t.nodes.get(l.id)),a=x=>{if(g==="all"||g.has(x))return!1;let m=t.nodes.get(x);return m instanceof ft.Map?u?!0:typeof m.get(z.movedFrom)=="string"||he(m):!1},h=wn(l).flatMap(x=>{let m=i.get(x.id);if(!m)return[];let k=m.children??[],S=k.filter(w=>Et(w,"p")&&(e.has(w.key)||xo(w)&&a(w.key)));return[{from:m,kids:k,going:S,paragraphs:k.filter(w=>Et(w,"p")).length}]});h.every(x=>x.going.length===x.paragraphs)&&[...h].reverse().find(x=>x.going.length>0)?.going.pop();let p=new Set(h.filter(x=>x.going.length===x.paragraphs).map(x=>x.from)),y=i.get(l.id);y&&p.size>0&&p.size<h.length&&s.set(y.key,(y.children??[]).filter(x=>!p.has(x)));for(let{from:x,kids:m,going:k}of h){if(k.length===0)continue;let S=new Set(k);s.set(x.key,m.filter(A=>!S.has(A)));let w=o.get(c.key);if(w)for(let A of k)w.push(A);else o.set(c.key,k)}}}function vo(t,e,n,o){let s=new Map,i=new Map,r=So(e,f=>(f.children??[]).filter(d=>!("text"in d)));for(let f of r)vr(t,n,f,s,i);if(s.size===0&&n.size===0)return e;let u=f=>{if(!Et(f,"p")||xo(f))return!1;let d=t.nodes.get(f.key);return d instanceof ft.Map&&d.get(Yt.holder)===!0},l=(f,d)=>{let c=i.get(f.key)??f.children??[],g=s.get(f.key);g&&(c=[...c,...g]),f.local==="txBody"&&c.some(p=>Et(p,"p")&&n.has(p.key))&&(c=c.filter(p=>!u(p)));let a=d<It?c.map(p=>"text"in p?p:l(p,d+1)):c,h=a.length===(f.children??[]).length&&a.every((p,y)=>p===f.children[y]);return!h&&f.local==="txBody"&&o?.add(f.key),h?f:{...f,children:a}};return l(e,0)}import*as U from"yjs";var ee=Object.freeze({copyOf:"ci",newParagraph:"cp",seen:"cs",followed:"cf.",removedRun:"rr."}),De="pptx-copies-v1",Po=1<<20,Co=4096,Pr=1024,Mn=32,bn=1024,vt=1024,Nt="http://schemas.openxmlformats.org/drawingml/2006/main",H=(t,e)=>`${t}:${e}`,Ye=t=>Number.isSafeInteger(t)&&t>=0,Oo=new WeakMap;function Ee(t){if(!(t instanceof U.Map))return null;let e=t.get(ee.copyOf),n=Oo.get(t);if(n&&n.value===e)return n.copy;let o=Do(e,t.get(ee.newParagraph)===!0);return Oo.set(t,{value:e,copy:o}),o}function Do(t,e){if(!Array.isArray(t)||t.length<5||(t.length-2)%3!==0||t.length>2+3*Po)return null;let[n,o]=t;if(!Ye(n)||!Ye(o))return null;let s=[],i=0;for(let u=2;u<t.length;u+=3){let l=t[u],f=t[u+1],d=t[u+2];if(!Ye(l)||!Ye(f)||!Ye(d)||d===0||(s.push(i),i+=d,i>Po))return null}let r=t;return{client:n,clock:o,length:i,newParagraph:e,source(u){let l=0,f=s.length-1;for(;l<f;){let c=l+f+1>>1;s[c]<=u?l=c:f=c-1}let d=2+3*l;return U.createID(r[d],r[d+1]+(u-s[l]))}}}var No=new WeakMap;function At(t){let e=[];if(!(t instanceof U.Map))return e;let n=0;for(let[o,s]of t.entries()){if(++n>Pr)break;if(!o.startsWith(ee.followed)||!Array.isArray(s))continue;let i=No.get(s);i===void 0&&No.set(s,i=Do(s,!1)),i&&e.push(i)}return e}function Or(t,e){let n=s=>s!==null&&s.client===e.client&&e.clock>=s.clock&&e.clock<s.clock+s.length,o=Ee(t);return n(o)?o:At(t).find(n)??null}function Lo(t,e,n,o){t.set(`${ee.followed}${H(e,n)}`,[e,n,...Fo(o)])}function _o(t,e){let n=new Set,o=t.nodes;for(let[s,i]of e.changed){if(s===o){for(let u of i)u!==null&&At(o.get(u)).length>0&&n.add(u);continue}if(!(s instanceof U.Map)||s.parent!==o)continue;let r=s.get(N.key);if(typeof r=="string")for(let u of i)u?.startsWith(ee.followed)&&n.add(r)}return n}var Ie="pptx-restored-v1",Le=65536,Nr=/^(\d{1,16}):(\d{1,16})$/,Pt=new WeakMap,Ao=new WeakSet;function Ar(t){let e=Pt.get(t);if(e)return e;Ao.has(t)||(Ao.add(t),t.observe(()=>Pt.delete(t))),e=new Map;for(let[n,o]of t.entries()){let s=Nr.exec(n);if(!s||!Array.isArray(o)||o.length!==3||!o.every(Ye))continue;let[i,r,u]=o;if(u===0||u>Le)continue;let l=Number(s[1]),f=Number(s[2]);if(!Number.isSafeInteger(l)||!Number.isSafeInteger(f))continue;let d=e.get(l),c=[f,i,r,u];d?d.push(c):e.set(l,[c])}for(let n of e.values())n.sort((o,s)=>o[0]-s[0]);return Pt.set(t,e),e}function He(t,e){let n=t.getMap(Ie);if(n.size===0)return null;let o=Ar(n).get(e.client);if(!o)return null;let s=0,i=o.length-1;for(;s<i;){let u=s+i+1>>1;o[u][0]<=e.clock?s=u:i=u-1}let r=o[s];return!r||e.clock<r[0]||e.clock>=r[0]+r[3]?null:U.createID(r[1],r[2]+(e.clock-r[0]))}function pt(t,e){if(e.length===0)return;let n=t.getMap(Ie);for(let o=0;o+3<e.length;o+=4)n.set(H(t.clientID,e[o]),[e[o+1],e[o+2],e[o+3]]);Pt.delete(n)}function Fo(t){let e=[];for(let n of t){let o=e.length;o>0&&e[o-3]===n.client&&e[o-2]+e[o-1]===n.clock?e[o-1]+=1:e.push(n.client,n.clock,1)}return e}function Tr(t,e){let n=new Set;for(let s=e._start;s!==null;s=s.right)if(n.add(s.id.client),n.size>Co)return null;let o=[];for(let s of[...n].sort((i,r)=>i-r))o.push(s,U.getState(t.store,s));return o}var To=new WeakMap;function zo(t){if(!(t instanceof U.Map))return null;let e=t.get(ee.seen),n=To.get(t);(!n||n.value!==e)&&(n={value:e,seen:Cr(e)},To.set(t,n));let o=n.seen;return o?s=>s.clock<(o.get(s.client)??0):null}function Cr(t){if(!Array.isArray(t)||t.length%2!==0||t.length>2*Co)return null;let e=new Map;for(let n=0;n<t.length;n+=2){let o=t[n],s=t[n+1];if(!Ye(o)||!Ye(s)||e.has(o))return null;e.set(o,s)}return e}function Tt(t,e,n){let o=[],s=0;for(let i=t._start;i!==null&&o.length<n;i=i.right)if(!(i.deleted||!i.countable))for(let r=0;r<i.length&&o.length<n;r+=1,s+=1)s>=e&&o.push(U.createID(i.id.client,i.id.clock+r));return o}function ye(t,e){if(U.getState(t.store,e.client)<=e.clock)return null;let n=U.getItem(t.store,e);return n instanceof U.Item?n:null}function Rn(t){let e=t.parent,n=e instanceof U.Text?e.parent:null;return n instanceof U.Map?n:null}function Ct(t,e){let n=ye(t,e);return!n||n.deleted}function ue(t,e,n,o=!0){let s=H(e.client,e.clock),i=n?.get(s);if(i)return i;let r=e;for(let u=0;u<Mn;u+=1){let l=ye(t,r),f=l?Or(Rn(l),r):null;if(f){r=f.source(r.clock-f.clock);continue}let d=o?He(t,r):null;if(!d)break;r=d}return n?.set(s,r),r}var Ce=t=>t?.type==="element",Ot=t=>t.children.filter(Ce),le=(t,e)=>t.ns===Nt&&t.local===e;function jo(t){return Ot(t).find(n=>le(n,"t"))?.children.find(n=>n.type==="text")}var ut=t=>{let e=jo(t);return e?.type==="text"?e.value:""};function Ko(t,e,n,o,s,i){let r=new Set;if(o.size===0||i.size===0)return r;let u=t.doc.getMap(De),l=c=>{let g=jo(c);return g?s.get(g.id):void 0},f=(c,g,a)=>{let h=Ot(c);h.forEach((p,y)=>{if(!le(p,"r"))return;let x=o.get(p.id);if(!Ce(x)||x===p)return;let m=ut(x),k=ut(p);if(m.length<=k.length||!m.startsWith(k))return;let S=l(p),w=S===void 0?void 0:i.get(S),A=m.length-k.length;if(!w||w.deleted.length!==A)return;let R=[],P=0,b=(F,M,L)=>{for(let v=M;v<F.length&&P<A;v+=1){let $=F[v];if(!(!o.has($.id)&&le($,"br"))&&!le($,"pPr")){if(le($,"endParaRPr"))return!0;if(!le($,"r")||o.has($.id))return!1;R.push({run:$,newParagraph:L}),P+=ut($).length}}return!0},I=b(h,y+1,!1),C=g[a+1],j=h.slice(y+1).every(F=>o.has(F.id)||le(F,"endParaRPr"));P<A&&I&&j&&C&&le(C,"p")&&!o.has(C.id)&&b(Ot(C),0,!0);let _=R.length>0&&R.every(F=>F.newParagraph),E=R.map(F=>ut(F.run)).join("");if(P>A||P<A&&!(_&&m.endsWith(E)))return;let O=S===void 0?void 0:t.nodes.get(S),D=O instanceof U.Map?O.get(N.text):void 0,K=D instanceof U.Text?Tr(t.doc,D):null,T=A-P;for(let F of R){let M=l(F.run),L=ut(F.run).length,v=M===void 0?void 0:i.get(M),$=M===void 0?void 0:t.nodes.get(M),G=w.deleted.slice(T,T+L);if(T+=L,!(L===0||!v?.created||v.inserted?.length!==L)&&!(!($ instanceof U.Map)||M===void 0)){$.set(ee.copyOf,[v.inserted.client,v.inserted.clock,...Fo(G)]),F.newParagraph&&$.set(ee.newParagraph,!0),K&&$.set(ee.seen,K),u.set(M,e);for(let oe of G)r.add(H(oe.client,oe.clock))}}})},d=c=>{if(o.get(c.id)===c)return;let g=Ot(c);g.forEach((a,h)=>{le(a,"p")&&Ce(o.get(a.id))&&f(a,g,h)});for(let a of g)d(a)};return d(n),r}function $o(t,e,n,o){let s=[];if(n.size===0)return s;let i=new Set,r=[],u=l=>{let f=n.get(l.id);if(f!==l){for(let d of l.children)i.add(d.id);if(Ce(f)){let d=new Set(l.children.map(g=>g.id)),c="";for(let g of f.children)!d.has(g.id)&&Ce(g)&&(le(g,"r")||le(g,"p"))&&r.push({node:g,from:l,prev:c}),c=o.get(g.id)??c}for(let d of l.children)Ce(d)&&u(d)}};u(e);for(let{node:l,from:f,prev:d}of r){if(i.has(l.id))continue;let c=o.get(l.id),g=o.get(f.id),a=g===void 0?void 0:t.nodes.get(g);(le(l,"r")&&le(f,"p")||le(l,"p")&&le(f,"txBody")&&!Sn(l))&&c!==void 0&&a instanceof U.Map&&a.set(`${ee.removedRun}${c}`,d);let p=[l];for(;p.length>0;){let y=p.pop();if(y!==l&&i.has(y.id))continue;if(Ce(y)){for(let S of y.children)p.push(S);continue}let x=o.get(y.id),m=x===void 0?void 0:t.nodes.get(x),k=m instanceof U.Map?m.get(N.text):void 0;if(!(!(k instanceof U.Text)||y.type!=="text"||y.value.length===0)&&k.toString()===y.value){for(let S of Tt(k,0,k.length))s.push(S);k.delete(0,k.length)}}}return s}function Wo(t,e){let n=o=>{let s=o.get(N.children);return s instanceof U.Array?s.toArray().filter(i=>typeof i=="string"):[]};for(let o of n(e).slice(0,bn)){let s=t.nodes.get(o);if(!(s instanceof U.Map))continue;let i=s.get(N.shell);if(!(i?.ns!==Nt||i.local!=="t"))for(let r of n(s).slice(0,bn)){let u=t.nodes.get(r),l=u instanceof U.Map?u.get(N.text):void 0;if(l instanceof U.Text&&l.length>0)return!0}}return!1}var Dr=t=>(t.children??[]).some(e=>!("text"in e)&&e.local==="t"&&(e.children??[]).some(n=>"text"in n&&n.text.length>0));function Lr(t,e){let n=e.get(N.children);if(!(n instanceof U.Array))return!1;let o=e.get(N.key),s=new Set;for(let r of e.keys())r.startsWith(ee.removedRun)&&s.size<vt&&s.add(r.slice(ee.removedRun.length));let i=n.toArray().slice(0,bn);for(let r of[...i,...s]){let u=typeof r=="string"?t.nodes.get(r):void 0;if(!(u instanceof U.Map))continue;let l=u.get(N.shell);if(l?.ns!==Nt)continue;if(l.local==="br")return!0;if(l.local!=="r"&&l.local!=="fld")continue;if(!(s.has(r)&&(!he(u)||u.get(z.movedFrom)===o))&&Wo(t,u))return!0}return!1}function Go(t,e,n,o,s){let i=new Map;for(let m of n.keys()){if(!m.startsWith(ee.removedRun))continue;let k=n.get(m);if(typeof k=="string"&&(i.set(m.slice(ee.removedRun.length),k),i.size>=vt))break}if(i.size===0)return o;let r=new Set(o.map(m=>m.key)),u=n.get(N.key),l=n.get(N.shell)?.local==="txBody",f=l?"p":"r",d=l?["bodyPr","lstStyle"]:["pPr"],c=new Map;for(let m of[...i.keys()].sort()){if(r.has(m))continue;let k=t.nodes.get(m);if(!(k instanceof U.Map)||k.get(N.part)!==e)continue;let S=k.get(N.shell);if(S?.ns!==Nt||S.local!==f||!he(k)||k.get(z.movedFrom)===u)continue;let A=(l?Lr:Wo)(t,k),R=s(m);R&&(A||Dr(R))&&c.set(m,R)}if(c.size===0)return o;let g=m=>{let k=i.get(m)??"";for(let S=0;S<vt&&k!==""&&!r.has(k)&&!c.has(k);S+=1)k=i.get(k)??"";return r.has(k)||c.has(k)?k:""},a=new Map;for(let[m,k]of c){let S=g(m),w=a.get(S);w?w.push(k):a.set(S,[k])}let h=[],p=new Set,y=(m,k)=>{if(!(k>vt))for(let S of a.get(m)??[])p.has(S.key)||(p.add(S.key),h.push(S),y(S.key,k+1))},x=!1;for(let m of o)!x&&("text"in m||!d.includes(m.local))&&(x=!0,y("",0)),h.push(m),y(m.key,0);x||y("",0);for(let m of c.values())p.has(m.key)||h.push(m);return h}import*as q from"yjs";import*as ke from"yjs";function be(t){if(!(t instanceof ke.AbstractType))return null;let e=t._item;return e instanceof ke.Item?e:null}function pe(t,e,n){for(let[o,s]of e.clients){let i=t.store.clients.get(o);if(!(!i||i.length===0))for(let{clock:r,len:u}of s){let l=i[i.length-1];if(!(r>=l.id.clock+l.length))for(let f=ke.findIndexSS(i,r);f<i.length;f+=1){let d=i[f];if(d.id.clock>=r+u)break;d instanceof ke.Item&&n(d)}}}}function Dt(t,e,n){let o=ke.createDeleteSet();for(let[s,i]of e.clients){let r=t.store.clients.get(s),u=[];for(let{clock:l,len:f}of i){if(!r||r.length===0){u.push({clock:l,len:f});continue}let d=l+f,c=l,g=r[r.length-1];if(l<g.id.clock+g.length)for(let a=ke.findIndexSS(r,l);a<r.length;a+=1){let h=r[a];if(h.id.clock>=d)break;if(!(h instanceof ke.Item)||!n(h))continue;let p=Math.max(l,h.id.clock);p>c&&u.push({clock:c,len:p-c}),c=Math.min(d,h.id.clock+h.length)}d>c&&u.push({clock:c,len:d-c})}u.length>0&&o.clients.set(s,u)}return o}function*Yn(t){for(let e=t._start;e;e=e.right)e.deleted||(yield e)}function*Xo(t){for(let e of t._map.values())e.deleted||(yield e)}function Lt(t,e){let n=0;for(let o=t._start;o!==null;o=o.right)if(!(o.deleted||!o.countable)){if(o.id.client===e.client&&e.clock>=o.id.clock&&e.clock<o.id.clock+o.length)return n+(e.clock-o.id.clock);n+=o.length}return-1}function _e(t,e){let n=[],o=0;for(let s=t._start;s!==null&&n.length<e.size;s=s.right)if(!(s.deleted||!s.countable)){for(let i=0;i<s.length;i+=1)e.has(`${s.id.client}:${s.id.clock+i}`)&&n.push(o+i);o+=s.length}for(let s=n.length-1;s>=0;){let i=s;for(;i>0&&n[i-1]===n[i]-1;)i-=1;t.delete(n[i],n[s]-n[i]+1),s=i-1}}var Bo=t=>t.left===null;var ve="pptx-undone-v1",_r=64,Uo=1024,Fr=1<<18,zr=(t,e)=>t.id.client!==e.client||t.id.clock>=e.clock;function jr(t,e,n){if(typeof e!="object"||e===null)return null;let o=e;if(typeof o.p!="string"||n!==void 0&&o.p!==n||typeof o.u!="string"||typeof o.a!="string"||!Number.isSafeInteger(o.c)||o.c<0)return null;let s=Number.isSafeInteger(o.q)&&o.q>=0?o.q:1/0,i=typeof o.n=="string"?o.n:"",r=typeof o.s=="string"?o.s:null;return{key:t,parent:o.u,after:o.a,before:i,client:o.c,clock:s,shownIn:r}}function qo(t,e,n){let o=t.nodes,s=new Map,i=new Set;if(pe(t.doc,e.insertions,d=>{d.parent===t.parts&&d.parentSub!==null&&!d.deleted&&i.add(d.parentSub)}),pe(t.doc,e.insertions,d=>{let c=d.parent;if(d.deleted||!(c instanceof q.Array))return;let g=c.parent;if(!(g instanceof q.Map)||be(g)?.parent!==o||g.get(N.children)!==c||d.parentSub!==null||!(d.content instanceof q.ContentAny))return;let a=s.get(c);a||s.set(c,a=new Set);for(let h of d.content.getContent())typeof h=="string"&&a.add(h)}),s.size===0)return;let r=t.doc.getMap(ve),u=t.doc.clientID,l=q.getState(t.doc.store,u),f=[];for(let[d,c]of s){let g=d.parent;if(!(g instanceof q.Map)||g.get(N.children)!==d)continue;let a=g.get(N.key),h=g.get(N.part);if(typeof a!="string"||typeof h!="string"||i.has(h))continue;let p=d.toArray().filter(y=>typeof y=="string");p.forEach((y,x)=>{if(!c.has(y))return;let m=p[x+1]??"",k={p:h,u:a,a:p[x-1]??"",n:m,c:u,q:l};JSON.stringify(r.get(y))!==JSON.stringify(k)&&f.push([y,k])})}f.length>0&&n(()=>{for(let[d,c]of f)r.set(d,c)})}function Jo(t,e,n,o,s,i){let r=t.doc.getMap(ve),u=t.doc.clientID,l=new Set;for(let f of s){let d=o[f],c=typeof d=="string"?i(d):void 0;if(typeof d!="string"||c===void 0||l.has(d))continue;l.add(d);let g="";for(let p=f-1;p>=0&&g==="";p-=1)o[p]!==d&&typeof o[p]=="string"&&(g=o[p]);let a="";for(let p=f+1;p<o.length&&a==="";p+=1)o[p]!==d&&typeof o[p]=="string"&&(a=o[p]);let h={p:e,u:n,a:g,n:a,c:u,q:0,s:c};JSON.stringify(r.get(d))!==JSON.stringify(h)&&r.set(d,h)}}function Qo(t,e,n){let o=t.doc.getMap(ve);if(o.size===0)return;let s=new Set;pe(t.doc,e.deletions,i=>{if(!(!(i.parent instanceof q.Array)||!(i.content instanceof q.ContentAny)))for(let u of i.content.getContent())typeof u=="string"&&o.has(u)&&s.add(u)}),s.size>0&&n(()=>{for(let i of s)o.delete(i)})}function Zo(t,e,n){let o=new Map;if(pe(t.doc,e.insertions,r=>{if(r.parent!==t.nodes||r.parentSub===null||!(r.content instanceof q.ContentType)||!(r.content.type instanceof q.Map))return;let u=r.content.type;if(t.nodes.get(r.parentSub)!==u)return;let l=u.get(N.part),f=u.get(N.attrs),d=u.get(N.children);if(typeof l!="string"||!(f instanceof q.Map)||!(d instanceof q.Array)||f.size>0||d.length>0||!n(l,r.parentSub))return;let c=o.get(l);c||o.set(l,c=new Set),c.add(r.parentSub)}),o.size===0)return!1;let s=!1,i=0;for(let r of t.nodes.values()){if((i+=1)>Fr)break;if(!(r instanceof q.Map))continue;let u=r.get(N.part),l=typeof u=="string"?o.get(u):void 0,f=r.get(N.children);if(!l||!(f instanceof q.Array))continue;let d=f.toArray();for(let c=d.length-1;c>=0;c-=1){let g=d[c];typeof g=="string"&&l.has(g)&&(f.delete(c,1),s=!0)}}return s}var Ho=new WeakMap;function Vo(t,e,n){let o=t.placeOf.get(e);if(o){let l=t.byPart.get(o.part),f=l?.get(o.parent);f?.delete(e),f?.size===0&&l.delete(o.parent),t.placeOf.delete(e)}let s=n===void 0?null:jr(e,n),i=s?n.p:null;if(!s||i===null)return;let r=t.byPart.get(i);r||t.byPart.set(i,r=new Map);let u=r.get(s.parent);u||r.set(s.parent,u=new Map),u.set(e,s),t.placeOf.set(e,{part:i,parent:s.parent})}function Kr(t,e){let n=t.doc.getMap(ve),o=Ho.get(n);if(!o){let s={byPart:new Map,placeOf:new Map};o=s;for(let[i,r]of n.entries())Vo(s,i,r);Ho.set(n,s),n.observe(i=>{for(let r of i.keysChanged)Vo(s,r,n.get(r))})}return o.byPart.get(e)??new Map}var En="http://schemas.openxmlformats.org/drawingml/2006/main",es=new Set(["p","pPr","rPr","endParaRPr","ln","bodyPr","tcPr"]);function ts(t){if("text"in t)return t.text.length>0;if(t.ns!==En)return!1;let e=t.children??[];return t.local==="r"?e.some(n=>!("text"in n)&&n.ns===En&&n.local==="t"&&ts(n)):t.local==="t"?e.some(n=>"text"in n&&n.text.length>0):es.has(t.local)&&(e.length>0||(t.attrs??[]).length>0)}var _t=class t{#e;#t;#n;#i=new Map;shown=new Set;constructor(e,n,o){this.#e=e,this.#t=n,this.#n=o}static of(e,n,o){if(e.doc.getMap(ve).size===0)return null;let s=Kr(e,n);if(s.size===0)return null;let i=new Set,r=[o];for(;r.length>0;){let u=r.pop();if(i.has(u))continue;i.add(u);let l=e.nodes.get(u);if(!(l instanceof q.Map)||l.get(N.part)!==n)continue;let f=l.get(N.children);if(f instanceof q.Array)for(let d of f.toArray())typeof d=="string"&&!i.has(d)&&r.push(d)}return new t(e,s,i)}#s(e,n,o){let s=`${e}\0${n.client}\0${n.clock}`,i=this.#i.get(s);if(i!==void 0)return i;this.#i.set(s,!1);let r=o<=_r&&this.#l(e,n,o);return this.#i.set(s,r),r}#l(e,n,o){let s=this.#e.nodes.get(e);if(!(s instanceof q.Map))return!1;let i=d=>zr(d,n),r=s.get(N.text);if(r instanceof q.Text){for(let d of Yn(r))if(d.countable&&i(d))return!0}let u=s.get(N.attrs);if(u instanceof q.Map){for(let d of Xo(u))if(i(d))return!0}let l=s.get(N.children);if(l instanceof q.Array){for(let d of Yn(l))if(i(d))return!0}let f=0;for(let d of s.keys())if(d.startsWith(ee.removedRun)){if((f+=1)>Uo)break;if(this.#s(d.slice(ee.removedRun.length),n,o+1))return!0}return this.#r(e).some(d=>this.#s(d.key,d,o+1))}#r(e){return[...this.#t.get(e)?.values()??[]].filter(n=>{if(this.#n.has(n.key)||n.shownIn!==null&&!this.#n.has(n.shownIn))return!1;let o=this.#e.nodes.get(n.key);return o instanceof q.Map&&!he(o)})}withUndone(e,n,o,s,i){let r=this.#r(e).filter(g=>!s.has(g.key)&&this.#s(g.key,g,0)).sort((g,a)=>g.key<a.key?-1:g.key>a.key?1:0).slice(0,Uo);if(r.length===0)return o;let u=[...o],l=new Set(u.map(g=>g.key)),f=new Map([...this.#t.get(e)?.values()??[]].map(g=>[g.key,g.after])),d=new Set(r.map(g=>g.key)),c="\0";for(let g=!1;d.size>0;){let a=!1;for(let h of r){if(!d.has(h.key))continue;let p=h.after,y=p!==""&&!l.has(p)&&!d.has(p)&&l.has(h.before)?h.before:null;y!==null&&(p=c);let x=new Set([h.key]),m=!1;for(;p!==""&&p!==c&&!l.has(p);){if(d.has(p)&&!g){m=!0;break}x.has(p)?p=c:(x.add(p),p=f.get(p)??c)}if(m)continue;d.delete(h.key),a=!0;let k=this.#c(h.key,n,s,i);if(!k||!ts(k))continue;let S=y!==null?u.findIndex(w=>w.key===y):p===""?0:p===c?u.length:u.findIndex(w=>w.key===p)+1;u.splice(S,0,k),l.add(h.key),this.shown.add(h.key)}a||(g=!0)}return u}#c(e,n,o,s){let i=this.#e.nodes.get(e);if(!(i instanceof q.Map)||i.get(N.part)!==n)return null;let r=i.get(N.text);if(r instanceof q.Text)return o.add(e),{key:e,text:r.toString()};let u=i.get(N.shell),{ns:l,local:f}=typeof u=="object"&&u!==null?u:{};return l!==En||typeof f!="string"||!es.has(f)&&f!=="r"&&f!=="t"?null:s(e)}};function os(t){let e=new Map;if(!t)return e;let n=[t];for(;n.length>0;){let o=n.pop();if(e.set(o.id,o),o.type==="element")for(let s of o.children)n.push(s)}return e}function $r(t,e){let n=t.length,o=e.length,s=new Uint32Array((n+1)*(o+1));for(let f=n-1;f>=0;f--)for(let d=o-1;d>=0;d--)s[f*(o+1)+d]=t[f]===e[d]?s[(f+1)*(o+1)+d+1]+1:Math.max(s[(f+1)*(o+1)+d],s[f*(o+1)+d+1]);let i=new Set,r=new Set,u=0,l=0;for(;u<n&&l<o;)t[u]===e[l]?(i.add(u++),r.add(l++)):s[(u+1)*(o+1)+l]>=s[u*(o+1)+l+1]?u++:l++;return{keepA:i,keepB:r}}function In(t,e){let n=t.toArray();if(n.length===e.length&&n.every((r,u)=>r===e[u]))return;if(n.length*e.length>25e4){t.delete(0,n.length),t.insert(0,[...e]);return}let{keepA:o,keepB:s}=$r(n,e);for(let r=n.length-1;r>=0;r--)o.has(r)||t.delete(r,1);let i=0;e.forEach((r,u)=>{s.has(u)||t.insert(i,[r]),i+=1})}function ss(t,e){if(t.size===0)return t;let n=Rt(e);return new Map([...t].filter(([o])=>n.has(o)))}function ns(t){let e=new Map;if(t?.kind!=="xml")return e;let n=[[t.xml.root,""]];for(;n.length>0;){let[o,s]=n.pop();if(e.set(o.id,s),o.type==="element")for(let i of o.children)n.push([i,`${o.id}/${s}`])}return e}function rs(t,e,n){let o,s;return i=>{let r=t?.get(i);if(r===void 0)return!1;o??=ns(e),s??=ns(n);let u=o.get(r);return u!==void 0&&u===s.get(r)}}function is(t,e,n){let o;return s=>{let i=t?.get(s);if(i===void 0||n?.kind!=="xml")return;if(!o){let u=new Map,l=[n.xml.root];for(;l.length>0;){let f=l.pop();if(f.type==="element")for(let d of f.children)u.set(d.id,f.id),l.push(d)}o=u}let r=o.get(i);return r===void 0?void 0:e?.get(r)}}var Gr="http://schemas.openxmlformats.org/drawingml/2006/main",Xr=1<<20;function Br(t,e,n){let o=t.toString();if(o===e)return;let s=0;for(;s<o.length&&s<e.length&&o[s]===e[s];)s++;let i=0;for(;i<o.length-s&&i<e.length-s&&o[o.length-1-i]===e[e.length-1-i];)i++;let r=a=>a>=55296&&a<=56319,u=a=>a>=56320&&a<=57343;s>0&&r(o.charCodeAt(s-1))&&s--,i>0&&u(o.charCodeAt(o.length-i))&&i--;let l=o.length-s-i,f=e.length-s-i;if(l===f&&!/[\uD800-\uDFFF]/.test(o.slice(s,s+l)+e.slice(s,s+f))){let a=Tt(t,s,l),h=[];for(let p=s;p<s+l;p++){if(o[p]===e[p])continue;let y=a[p-s];y&&h.push(y),t.insert(p,e[p]),t.delete(p+1,1)}return{created:n,deleted:h}}let d=l>0?Tt(t,s,l):[];l>0&&t.delete(s,l);let c=t.doc,g=c?B.getState(c.store,c.clientID):0;return f>0&&t.insert(s,e.slice(s,e.length-i)),{created:n,deleted:d,...f>0&&c?{inserted:{client:c.clientID,clock:g,length:f}}:{}}}var cs=(t,e)=>t.attrs.find(n=>n.ns===""&&n.local===e)?.value,Ur=t=>({ns:t.ns,local:t.local,...t.prefix?{prefix:t.prefix}:{},nsDecls:t.nsDecls.map(e=>({prefix:e.prefix,uri:e.uri}))}),Ft=class{#e;#t=new Map;#n=new Map;#i=new Map;#s=new Set;#l=new Map;#r=new Map;#c=new Map;#g=new Set;#a=new Map;#d=new Map;#f=rt;#u=null;#w=new Map;#h=new Map;#x;#m=new Set;constructor(e,n={value:0}){this.#e=e,this.#x=n;let o=`${e.doc.clientID.toString(36)}.`;for(let s of e.nodes.keys()){if(!s.startsWith(o))continue;let i=Number.parseInt(s.slice(o.length).replace(St,""),36);Number.isSafeInteger(i)&&i<=Kn&&i>n.value&&(n.value=i)}}get seeded(){return this.#e.parts.size>0}#M(e,n){for(let o of this.#i.get(e)??[])this.#n.delete(o);for(let[o,s]of n)this.#n.set(o,s);this.#i.set(e,new Set(n.keys())),this.#s.clear(),this.#w.clear();for(let[o,s]of this.#n)for(let i of s.companions)this.#s.add(i),this.#w.set(i,o)}#S(e,n){for(let o of this.#t.get(e)?.idOf.keys()??[])this.#h.delete(o);if(!n){this.#t.delete(e);return}this.#t.set(e,n);for(let o of n.idOf.keys())this.#h.set(o,e)}#E(e){let n=this.#t.get(e);return n||(n={keyOf:new Map,idOf:new Map},this.#t.set(e,n)),n}#y=!1;#I(){let e=this.#e.doc.clientID.toString(36),n=this.#y?St:"",o;do this.#x.value+=1,o=`${e}.${n}${this.#x.value.toString(36)}`;while(this.#e.nodes.has(o));return o}seed(e){this.#y=!0;try{for(let n of e.parts.values())this.#R(n,void 0)}finally{this.#y=!1}}hasHiddenListings(e){return e.some(n=>this.#a.has(n))}dropHiddenListings(e,n,o){for(let s of e){let i=this.#a.get(s);if(!i)continue;let r=rs(this.#t.get(s)?.idOf,n.parts.get(s),o.parts.get(s)),u=this.#t.get(s),l=is(u?.idOf,u?.keyOf,n.parts.get(s));this.#a.delete(s);for(let[f,d]of i){let c=this.#Y(f);if(!c||c.length!==d.length)continue;let g=[...d.at.keys()].sort((h,p)=>p-h);if(g.some(h=>c.get(h)!==d.at.get(h)))continue;let a=g.filter(h=>r(d.at.get(h)));a.length>0&&Jo(this.#e,s,f,c.toArray(),a,l);for(let h=0;h<g.length;){let p=h+1;for(;p<g.length&&g[p]===g[p-1]-1;)p++;c.delete(g[p-1],p-h),h=p}}}}writeChange(e,n,o){for(let s of o){let i=n.parts.get(s);if(!i){this.#e.parts.delete(s),this.#e.binaries.delete(s),this.#S(s,void 0);continue}this.#R(i,e.parts.get(s))}}#R(e,n){if(e.kind==="binary"){(n?.kind!=="binary"||n.bytes!==e.bytes)&&this.#e.binaries.set(e.partName,e.bytes),$e(this.#e.parts.get(e.partName))?.kind!=="binary"&&this.#e.parts.set(e.partName,{kind:"binary"});return}n?.kind==="binary"&&this.#e.binaries.delete(e.partName);let o={partName:e.partName,ids:this.#E(e.partName),before:os(n?.kind==="xml"?n.xml.root:void 0),texts:new Map},s=this.#b(e.xml.root,o),i=this.#r.get(e.partName);this.#r.delete(e.partName);for(let u of Eo(e.xml.root,i,o.ids.keyOf))this.#b(u,{...o,before:Yo(o.before,u.id)});co(this.#e,e.partName,e.xml.root,o.before,o.ids.keyOf),Ro(this.#e,e.xml.root,o.before,o.ids.keyOf),this.#v(e.partName,e.xml.root,o);let r=$e(this.#e.parts.get(e.partName));(r?.kind!=="xml"||r.root!==s)&&this.#e.parts.set(e.partName,{kind:"xml",root:s})}#v(e,n,o){if(this.#y)return;let s=Ko(this.#e,e,n,o.before,o.ids.keyOf,o.texts),i=$o(this.#e,n,o.before,o.ids.keyOf),r=this.#e.doc,u=new Map,l=f=>{if(this.#m.size>=Xr||s.has(H(f.client,f.clock)))return;let d=ue(r,f,u,!1);this.#m.add(H(d.client,d.clock))};for(let f of o.texts.values())for(let d of f.deleted)l(d);for(let f of i)l(f)}get deletedText(){return this.#m}showingUnlisted(e){return e.filter(n=>(this.#c.get(n)?.size??0)>0)}forgetDeleted(e){for(let n of e)this.#m.delete(n)}newCopies(e){let n=new Map,o=e.changed.get(this.#e.nodes);if(!o)return n;let s=this.#e.doc.getMap(De);for(let i of o){if(i===null)continue;let r=s.get(i),u=this.#e.nodes.get(i),l=Ee(u);if(typeof r!="string"||!l||l.client===this.#e.doc.clientID||u.get(N.part)!==r)continue;let f=n.get(r);f?f.push(i):n.set(r,[i])}return n}#b(e,n){let{partName:o,ids:s,before:i}=n,r=s.keyOf.get(e.id),u=r===void 0?void 0:this.#e.nodes.get(r);if(r!==void 0&&u instanceof B.Map&&i.get(e.id)===e)return r;let l=r===void 0||!(u instanceof B.Map);if(r===void 0||!(u instanceof B.Map)){r=this.#I();let b=new B.Map;this.#e.nodes.set(r,b),b.set(N.part,o),b.set(N.key,r),e.type==="text"?b.set(N.text,new B.Text):(b.set(N.attrs,new B.Map),b.set(N.children,new B.Array)),u=b,s.keyOf.set(e.id,r),s.idOf.set(r,e.id),this.#h.set(r,o)}let f=u;if(e.type==="text"){let b=f.get(N.text),I=b instanceof B.Text?Br(b,e.value,l):void 0;return I&&n.texts.set(r,I),r}let d=Ur(e);JSON.stringify(f.get(N.shell))!==JSON.stringify(d)&&f.set(N.shell,d);let c=this.#n.get(r),g=this.#e.doc.clientID.toString(36),a=c?.merge?[r,...c.companions].find(b=>ge(b)===g)??r:r,h=f.get(N.attrs);if(h instanceof B.Map){let b=new Map;for(let C of e.attrs)b.set(`${C.ns}${yt}${C.local}`,{ns:C.ns,local:C.local,value:C.value,...C.prefix?{prefix:C.prefix}:{}});let I=c?.merge?c.companions.map(C=>this.#k(C)):[];for(let C of[...h.keys()])b.has(C)||h.delete(C);for(let C of I)for(let j of[...C?.keys()??[]])b.has(j)||C.delete(j);for(let[C,j]of b){let _=c?.attrFrom.get(C)??(h.has(C)?r:void 0),E=_===void 0?void 0:this.#k(_);if(E&&JSON.stringify(E.get(C))===JSON.stringify(j))continue;if((this.#k(a)??h).set(C,j),c?.merge)for(let D of[r,...c.companions])D!==a&&this.#k(D)?.delete(C)}}let p=e.children.map(b=>this.#b(b,n)),y=new Set(p),x=f.get(N.children),m=(b,I)=>{let C=[],j=new Set,_=E=>{j.has(E)||(j.add(E),C.push(E))};for(let E of b){_(E);for(let O of this.#n.get(E)?.companions??[])I.has(O)&&_(O)}return C},k=new Set(x instanceof B.Array?x.toArray():[]),S=this.#c.get(o),w=c?p.filter(b=>!c.childFrom.has(b)&&!k.has(b)&&!S?.has(b)):[],A=(c?p.filter(b=>!c.childFrom.has(b)&&(k.has(b)||a===r)):p).filter(b=>!S?.has(b)||k.has(b));if(x instanceof B.Array){let b=x,I=b.toArray();In(b,po(I,this.#P(e,I,m(A,new Set(I))),this.#l.get(o)))}let R=new Set;if(c?.merge)for(let b of e.children)b.type==="element"&&R.add(We(e,b,I=>cs(b,I))?.slot);let P=new Set(w);c?.merge&&e.children.forEach((b,I)=>{b.type==="element"&&P.has(p[I])&&R.delete(We(e,b,C=>cs(b,C))?.slot)});for(let b of c?.merge?c.companions:[]){let I=this.#Y(b);if(!I)continue;let C=I.toArray(),j=C.filter(_=>{if(this.#s.has(_))return y.has(this.#w.get(_));if(c.childFrom.get(_)===b)return y.has(_);let E=c.shadowed.get(_);return E!==void 0&&R.has(E)});In(I,m([...j,...b===a?w:[]],new Set(C)))}return r}#P(e,n,o){let s=new Set(o),i=new Set(n),r=n.filter(a=>s.has(a)),u=o.filter(a=>i.has(a)),l=(a,h)=>a.length===h.length&&a.every((p,y)=>p===h[y]);if(l(r,u)||!l(Ge(e,r,a=>this.#O(a)),u))return o;let f=new Map,d=[],c;for(let a=o.length-1;a>=0;a--){let h=o[a];if(i.has(h))c=h;else if(c===void 0)d.unshift(h);else{let p=f.get(c);p||f.set(c,p=[]),p.unshift(h)}}let g=[];for(let a of r){for(let h of f.get(a)??[])g.push(h);g.push(a)}for(let a of d)g.push(a);return g}#O(e){let n=this.#e.nodes.get(e),o=n instanceof B.Map?n.get(N.shell):void 0;if(typeof o!="object"||o===null)return;let{ns:s,local:i}=o;return typeof s=="string"&&typeof i=="string"?{ns:s,local:i}:void 0}#k(e){let n=this.#e.nodes.get(e),o=n instanceof B.Map?n.get(N.attrs):void 0;return o instanceof B.Map?o:void 0}#Y(e){let n=this.#e.nodes.get(e),o=n instanceof B.Map?n.get(N.children):void 0;return o instanceof B.Array?o:void 0}keyOf(e,n){return this.#t.get(e)?.keyOf.get(n)}idOf(e,n){return this.#t.get(e)?.idOf.get(n)}textOf(e){let n=this.#e.nodes.get(e),o=n instanceof B.Map?n.get(N.text):void 0;return o instanceof B.Text?o:void 0}partOf(e){let n=this.#e.nodes.get(e),o=n instanceof B.Map?n.get(N.part):void 0;return typeof o=="string"?o:void 0}recordOfText(e){let n=e.parent,o=n instanceof B.Map?n.get(N.key):void 0;if(typeof o!="string"||this.#e.nodes.get(o)!==n)return;let s=n.get(N.part);return typeof s=="string"?{key:o,part:s}:void 0}touchedParts(e){let n=new Set,o=this.#e.parts,s=this.#e.binaries,i=this.#e.nodes,r=this.#e.doc,u=[r.getMap(Ne),r.getMap(at)],l=r.getMap(bt),f=r.getMap(ve);for(let[d,c]of e.changed){let g=d;if(g===o||g===s){for(let p of c)p!==null&&n.add(p);continue}if(u.includes(g)){for(let p of c){let y=p===null?void 0:d.get(p);typeof y=="string"&&n.add(y)}continue}if(g===f){for(let p of c){if(p===null)continue;let y=this.#e.doc.getMap(ve).get(p),x=typeof y=="object"&&y!==null?y.p:void 0,m=this.#e.nodes.get(p),k=typeof x=="string"?x:m instanceof B.Map?m.get(N.part):void 0;typeof k=="string"&&n.add(k)}continue}if(g===l){for(let p of c){let y=p===null?void 0:this.#e.nodes.get(p.split("\0")[0]),x=y instanceof B.Map?y.get(N.part):void 0;typeof x=="string"&&n.add(x)}continue}if(g===i){for(let p of c){if(p===null)continue;let y=this.#e.nodes.get(p),x=y instanceof B.Map?y.get(N.part):void 0;if(typeof x=="string"){n.add(x);continue}let m=this.#h.get(p);m!==void 0&&n.add(m)}continue}let a=g;for(;a instanceof B.AbstractType&&a.parent!==i;)a=a.parent;let h=a instanceof B.Map?a.get(N.part):void 0;typeof h=="string"&&n.add(h)}return n}allParts(e){let n=new Set(this.#e.parts.keys());for(let o of e.parts.keys())n.add(o);return n}rebuild(e,n,o=!1){let s=[],i=[],r=new Map,u=new Map,l=new Map,f=new Map,d=new Map,c=[...e];for(let a of c)[this.#a,this.#r].forEach(h=>h.delete(a));let g=new Map;for(let a of c){let h=$e(this.#e.parts.get(a));if(!h){if(this.#e.parts.has(a))return{ok:!1,reason:`invalid part entry ${a}`};n.parts.has(a)&&i.push(a);continue}if(h.kind==="binary"){let _=this.#e.binaries.get(a);if(!(_ instanceof Uint8Array)||_.length>et.maxBinaryBytes)return{ok:!1,reason:`invalid binary part ${a}`};s.push({kind:"binary",partName:a,bytes:_});continue}let p=new Map;this.#g=new Set,this.#o=void 0,this.#f=lt(this.#e,a,h.root),this.#d=new Map,this.#u=_t.of(this.#e,a,h.root);let y=(_,E,O)=>this.#p(_,a,E,O,p),x=new Set,m=()=>{x=new Set;let _=this.#p(h.root,a,new Set,0,p);return _&&mo(this.#e,a,_,y,x)},k=m(),S=this.#f;if(k&&(S.lost.size>0||S.unseenWinners.size>0)){let _=lt(this.#e,a,h.root,Rt(k));yo(_,S)||(this.#f=_,this.#g=new Set,this.#d=new Map,p.clear(),k=m())}if(!k)return{ok:!1,reason:`${this.#o??"invalid node records"} in ${a}`};let w=go(this.#e,a,k,y,this.#f.lost);if(this.#o)return{ok:!1,reason:`${this.#o} in ${a}`};let A=new Set,R=vo(this.#e,w,x,A);d.set(a,A);let P=o?void 0:this.#t.get(a),b=n.parts.get(a),I=b?.kind==="xml"?b.xml.nextId:1,C=Wr(a,R,{idOf:_=>P?.idOf.get(_),nextId:I});if(!C.ok)return{ok:!1,reason:`${a}: ${C.reason}`};let j={keyOf:new Map,idOf:new Map};for(let[_,E]of C.ids)j.idOf.set(_,E),j.keyOf.set(E,_);r.set(a,j),u.set(a,p),l.set(a,this.#g),f.set(a,ss(this.#d,R)),g.set(a,this.#u?.shown??new Set),s.push({kind:"xml",partName:a,xml:C.part})}for(let[a,h]of r)this.#S(a,h);for(let a of i)this.#S(a,void 0);for(let[a,h]of u)this.#M(a,h);for(let a of i)this.#M(a,new Map);for(let[a,h]of l)this.#l.set(a,h);for(let a of i)this.#l.delete(a);for(let[a,h]of f)h.size>0&&this.#a.set(a,h);for(let a of i)this.#a.delete(a);for(let[a,h]of g)this.#c.set(a,h);for(let a of i)this.#c.delete(a);for(let[a,h]of d)this.#r.set(a,h);return this.#u=null,{ok:!0,parts:s,removed:i}}#o;#p(e,n,o,s,i){if(s>et.maxReadDepth||o.has(e))return null;o.add(e);let r=this.#e.nodes.get(e);if(!(r instanceof B.Map)||r.get(N.part)!==n)return null;let u=r.get(N.shell),l=r.get(N.attrs),f=r.get(N.children);if(typeof u!="object"||u===null||!(l instanceof B.Map)||!(f instanceof B.Array))return null;let d=u,c=[],g=f.toArray();for(let[S,w]of g.entries()){if(typeof w!="string")continue;if(o.has(w)){let P=this.#d.get(e);P||this.#d.set(e,P={length:g.length,at:new Map}),P.at.set(S,w);continue}let A=this.#e.nodes.get(w);if(A instanceof B.Map&&A.get(N.text)instanceof B.Text){if(A.get(N.part)!==n)continue;o.add(w),c.push({key:w,text:A.get(N.text).toString()});continue}let R=this.#p(w,n,o,s+1,i);if(R)c.push(R);else if(this.#o)return null}let a=[...l.entries()].sort(([S],[w])=>S<w?-1:S>w?1:0).map(([,S])=>S),h=d.ns,p=d.local,y=(p==="p"||p==="txBody")&&h===Gr?Go(this.#e,n,r,c,S=>{let w=this.#p(S,n,o,s+1,i);return this.#o?null:w}):c,x=this.#u?this.#u.withUndone(e,n,y,o,S=>this.#p(S,n,o,s+1,i)):y;if(this.#o)return null;let m=uo(this.#e,{ns:h,local:p},x,this.#g,this.#f.unseenWinners),k=cn({ns:h,local:p},m,i);return k?{key:e,ns:h,local:p,...typeof d.prefix=="string"?{prefix:d.prefix}:{},nsDecls:Array.isArray(d.nsDecls)?d.nsDecls:[],attrs:a,children:[...Ge({ns:h,local:p},k,S=>"text"in S?void 0:S)]}:(this.#o="too many concurrent copies of one element",null)}};import*as Se from"yjs";var zt="pptxEditor",Hr=256,ls=256,ds=512,fs=256,us=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,Fe=(t,e=Hr)=>typeof t=="string"&&t.trim().length>0&&t.length<=e;function ps(t){return!Fe(t.actorId)||!Fe(t.name)||t.role!==void 0&&t.role!=="human"&&t.role!=="agent"?"invalid-identity":t.color!==void 0&&!us.test(t.color)?"invalid-identity-color":null}function gs(t){let{actorId:e,name:n,color:o,role:s}=t;return!Fe(e)||!Fe(n)?null:{actorId:e,name:n,...typeof o=="string"&&us.test(o)?{color:o}:{},...s==="human"||s==="agent"?{role:s}:{}}}function hs(t){let e=t?.[zt];return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:null}function ms(t,e){if(t.kind==="shapes"){let i=t.shapes.slice(0,ds).map(r=>e.keyOf(t.part,r)).filter(r=>r!==void 0);return i.length>0?{kind:"shapes",part:t.part,keys:i}:void 0}let n=i=>{let r=e.keyOf(t.part,i.node);if(r===void 0)return;let u=e.textOf(r);if(!u)return{key:r};let l=Math.max(0,Math.min(Math.trunc(i.offset)||0,u.length));return{rel:Se.relativePositionToJSON(Se.createRelativePositionFromTypeIndex(u,l))}},o=n(t.anchor),s=n(t.head);return o&&s?{kind:"text",anchor:o,head:s}:void 0}function ys(t,e){return{actorId:t.actorId,name:t.name,...t.color?{color:t.color}:{},...t.role?{role:t.role}:{},...e?{selection:e}:{}}}function ks(t){let e=[];for(let[n,o]of t.getStates()){if(e.length>=ls)break;let s=hs(o),i=s?gs(s):null;i&&e.push({...i,isLocal:n===t.clientID})}return e}function as(t,e,n){if(typeof t!="object"||t===null)return null;let o=t;if(Fe(o.key,fs)){let l=n.partOf(o.key),f=l?n.idOf(l,o.key):void 0;return l&&f?{part:l,node:f,offset:0}:null}let s=o.rel;if(typeof s!="object"||s===null)return null;let i;try{i=Se.createAbsolutePositionFromRelativePosition(Se.createRelativePositionFromJSON(s),e)}catch{return null}if(!i||!(i.type instanceof Se.Text))return null;let r=n.recordOfText(i.type),u=r?n.idOf(r.part,r.key):void 0;return r&&u?{part:r.part,node:u,offset:i.index}:null}function jt(t,e,n){if(typeof t!="object"||t===null)return null;let o=t;if(o.kind==="shapes"&&Fe(o.part,1024)&&Array.isArray(o.keys)){let s=o.part,i=o.keys.slice(0,ds).filter(r=>Fe(r,fs)).map(r=>n.idOf(s,r)).filter(r=>r!==void 0);return i.length>0?{kind:"shapes",part:s,shapes:i}:null}if(o.kind==="text"){let s=as(o.anchor,e,n),i=as(o.head,e,n);return!s||!i||s.part!==i.part?null:{kind:"text",part:s.part,anchor:{node:s.node,offset:s.offset},head:{node:i.node,offset:i.offset}}}return null}function ws(t,e,n){let o=[],s=0;for(let[i,r]of t.getStates()){if(++s>ls)break;if(i===t.clientID)continue;let u=hs(r),l=u?gs(u):null;if(!u||!l)continue;let f=jt(u.selection,e,n);f&&o.push({actorId:l.actorId,name:l.name,...l.color?{color:l.color}:{},selection:f})}return o}import*as J from"yjs";var Vr=4096,Ss=1<<20,qr=65536,Jr=1<<20,xs="http://schemas.openxmlformats.org/drawingml/2006/main",Qr=t=>t.type==="element";function Zr(t,e){let n=ye(t,e);if(!n)return null;let o=0;for(let s=n.parent instanceof J.Text?n.parent._start:null;s;s=s.right){if(s===n)return{text:n.parent,at:o+(e.clock-n.id.clock)};o+=s.length}return null}function ei(t,e){let n=new Map,o=t.package.parts.get(e);if(o?.kind!=="xml")return n;let s=(i,r,u)=>{let l=t.keyOf(e,i.id),f=i.ns===xs&&i.local==="p"&&l&&u?{p:{key:l,parent:u}}:i.ns===xs&&i.local==="r"&&l?{...r,run:l}:r;for(let d of i.children)if(Qr(d))s(d,f,l);else{let c=t.keyOf(e,d.id);c!==void 0&&n.set(c,{order:n.size,...f})}};return s(o.xml.root,{},void 0),n}function bs(t,e,n,o,s,i){let r=t.doc,u=r.clientID,l=M=>{let L=t.nodes.get(M),v=Ee(L),$=L instanceof J.Map?L.get(N.text):void 0;return!v||!($ instanceof J.Text)||L.get(N.part)!==e?null:{key:M,copy:v,text:$}},f=new Set(n.filter(M=>{let L=l(M);return L!==null&&L.copy.client!==u}));if(f.size===0)return;let d=ei(s,e),c=[],g=0;for(let[M,L]of t.doc.getMap(De).entries()){if(L!==e)continue;let v=l(M);if(!(!v||v.text.length===0&&!d.has(M))){if(c.length>=Vr||(g+=v.copy.length)>Ss)return;c.push(v)}}let a=c.filter(M=>f.has(M.key));if(a.length===0)return;let h=new Map,p=M=>ue(r,M,h),y=new Map,x=new Map,m=M=>(x.has(M.key)||x.set(M.key,Zr(r,p(M.copy.source(0)))),x.get(M.key)),k=(M,L)=>{let v=m(M),$=m(L);return v&&$&&v.text===$.text?v.at-$.at:0},S=M=>d.get(M.key)?.order??-1,w=(M,L)=>(k(M,L)||S(M)-S(L))>=0?M:L,A=(M,L)=>J.createID(M.copy.client,M.copy.clock+L),R=M=>{if(M.copy.newParagraph)return!0;let L=M.copy.source(0);for(let v=0;v<Mn;v+=1){let $=ye(r,L),G=$?Ee(Rn($)):null,oe=G?L.clock-G.clock:-1;if(!G||L.client!==G.client||oe<0||oe>=G.length)return!1;if(G.newParagraph)return!0;L=G.source(oe)}return!1},P=new Map;for(let M of c)if(d.has(M.key))for(let L=0;L<M.copy.length;L+=1){let v=A(M,L);if(Ct(r,v))continue;let $=p(M.copy.source(L)),G=H($.client,$.clock),oe=P.get(G);oe?oe.push({copy:M,id:v}):P.set(G,[{copy:M,id:v}])}let b=M=>P.get(H(M.client,M.clock))?.reduce((L,v)=>w(L.copy,v.copy)===L.copy?L:v);for(let M of a)ni(t,M,zo(t.nodes.get(M.key)),L=>b(p(L)),i);let I=new Map,C=(M,L)=>{let v=I.get(M);v?v.push(L):I.set(M,[L])};if(o.size>0)for(let M of a)for(let L=0;L<M.copy.length;L+=1){let v=ue(r,M.copy.source(L),y,!1);o.has(H(v.client,v.clock))&&!Ct(r,A(M,L))&&C(M.text,A(M,L))}let j=new Map,_=M=>{let L=j.get(M.key);return L===void 0&&j.set(M.key,L=R(M)),L};for(let M of P.values()){if(M.length<2||!M.some(v=>f.has(v.copy.key))||!M.some(v=>_(v.copy))||new Set(M.map(v=>v.copy.key)).size<2)continue;let L=M.reduce((v,$)=>w(v.copy,$.copy)===v.copy?v:$);for(let v of M)v!==L&&C(v.copy.text,v.id)}for(let[M,L]of I)_e(M,new Set(L.map(v=>H(v.client,v.clock))));let E=new Map,O=M=>{let L=E.get(M.key);if(!L){L=new Set;for(let v=0;v<M.copy.length;v+=1){let $=p(M.copy.source(v));L.add(H($.client,$.clock))}E.set(M.key,L)}return L},D=Jr,K=(M=1)=>(D-=M)>=0,F={room:t,me:u,incoming:a,all:c,placed:d,share:(M,L)=>{let[v,$]=[O(M),O(L)].sort((G,oe)=>G.size-oe.size);if(!K(v.size))return!1;for(let G of v)if($.has(G))return!0;return!1},laterStart:k,step:K};oi(F),ti(F)}function Kt(t,e){let n=t.nodes.get(e),o=n instanceof J.Map?n.get(N.children):void 0;return o instanceof J.Array?o:void 0}function ti({room:t,me:e,incoming:n,all:o,placed:s,share:i,step:r}){let u=new Map,l=(f,d)=>{let c=u.get(f);if(!c){u.set(f,c=new Map);let g=qr,a=h=>{let p=Kt(t,h)?.toArray()??[];return g-=p.length,g<0?[]:p};for(let h of a(f))for(let p of a(h))for(let y of a(p))for(let x of a(y))c.set(x,{p:h,run:p})}return c.get(d)};for(let f of n){let d=s.get(f.key);if(!(!d?.p||!d.run))for(let c of o){if(!r())return;if(c.copy.client!==e||c.key===f.key||!i(f,c))continue;let g=l(d.p.parent,c.key),a=g?t.nodes.get(g.run):void 0;if(!g||g.p===d.p.key||!(a instanceof J.Map)||a.get(z.movedFrom)!==d.p.key)continue;let h=Kt(t,d.p.key),p=Kt(t,g.p),y=h?.toArray().indexOf(d.run)??-1;if(!(!h||!p||y<0)){h.delete(y,1),p.insert(p.toArray().indexOf(g.run),[d.run]);break}}}}function ni(t,e,n,o,s){let i=t.doc,r=i.clientID,l=ye(i,e.copy.source(0))?.parent;if(!(l instanceof J.Text))return;let f=new Set;for(let a=0;a<e.copy.length;a+=1){let h=e.copy.source(a);f.add(H(h.client,h.clock))}let d=new Map,c=[],g=null;for(let a=l._start;a!==null;a=a.right){if(a.deleted||!(a.content instanceof J.ContentString))continue;let h=a.content.str;for(let p=0;p<h.length;p+=1){let y=J.createID(a.id.client,a.id.clock+p),x=p===0?a.origin:J.createID(a.id.client,a.id.clock+p-1),m=x?H(x.client,x.clock):"",k=a.id.client!==r||!x?void 0:f.has(m)?x:d.get(m);if(!k){g=null;continue}if(d.set(H(y.client,y.clock),k),n?.(y))continue;(!g||!J.compareIDs(g.anchor,k))&&(g={anchor:k,ids:[],written:[],text:"",marks:[]},c.push(g)),g.ids.push(y);let S=He(i,y);S&&o(y)||(S&&g.marks.push([g.text.length,S]),g.written.push(y),g.text+=h[p])}}for(let a of c){let h=o(a.anchor),p=h?Lt(h.copy.text,h.id):-1;if(!h||p<0||(_e(l,new Set(a.ids.map(m=>H(m.client,m.clock)))),a.text.length===0))continue;let y=J.getState(i.store,r);h.copy.text.insert(p+1,a.text);let x=t.nodes.get(h.copy.key);x instanceof J.Map&&Lo(x,r,y,a.written),pt(i,a.marks.flatMap(([m,k])=>[y+m,k.client,k.clock,1])),s(a.ids[0],J.createID(r,y),a.text.length)}}function Ms(t,e,n){if(n.size===0)return;let o=t.doc,s=new Map,i=0;for(let r of e){let u=t.nodes.get(r),l=u instanceof J.Map?u.get(N.text):void 0;if(!(l instanceof J.Text))continue;let f=[];for(let d of At(u))if(!(d.client===o.clientID||(i+=d.length)>Ss))for(let c=0;c<d.length;c+=1){let g=J.createID(d.client,d.clock+c),a=ue(o,d.source(c),s,!1);n.has(H(a.client,a.clock))&&!Ct(o,g)&&f.push(g)}f.length>0&&_e(l,new Set(f.map(d=>H(d.client,d.clock))))}}function oi({room:t,me:e,incoming:n,all:o,placed:s,share:i,laterStart:r,step:u}){for(let l of o){if(l.copy.client!==e||!l.copy.newParagraph)continue;let f=s.get(l.key)?.p,d=f?Kt(t,f.parent):void 0;if(!f||!d)continue;let c=d.toArray();if(!u(c.length))return;let g=new Map(c.map((p,y)=>[p,y])),a=g.get(f.key)??-1;if(a<0)continue;let h;for(let p of n){if(!u())return;if(p.key===l.key||r(l,p)<=0)continue;let y=s.get(p.key)?.p;if(!y||y.parent!==f.parent||y.key===f.key)continue;let x=g.get(y.key)??-1;x<=a||h&&x<=h.at||!i(p,l)||(h={key:y.key,at:x})}h&&(d.delete(a,1),d.insert(d.toArray().indexOf(h.key)+1,[f.key]))}}import*as Rs from"yjs";var si=new Set([N.part,N.key,N.shell,ee.copyOf,ee.newParagraph]);function Ys(t){return e=>{let n=e.parent;if(n===t)return!1;let o=be(n);return o===null||o.parent!==t?!0:e.content instanceof Rs.ContentType?!1:!(e.parentSub!==null&&si.has(e.parentSub)&&Bo(e))}}import*as re from"yjs";var ri=4096,ii=4096,ci=32;function ai(t,e,n,o,s=new Set){let i=t.doc,r=new Map,u=0;for(let[l,f]of i.getMap(De).entries()){if(typeof f!="string"||!e.has(f)||!n(f,l))continue;if((u+=1)>ri)return null;let d=t.nodes.get(l),c=d instanceof re.Map?d.get(N.text):void 0;if(!(!Ee(d)||!(c instanceof re.Text))){for(let g=c._start;g!==null;g=g.right)if(!(g.deleted||!g.countable))for(let a=0;a<g.length;a+=1){let h=H(g.id.client,g.id.clock+a);if(s.has(h))continue;let p=ue(i,re.createID(g.id.client,g.id.clock+a),o),y=H(p.client,p.clock);y!==h&&!r.has(y)&&r.set(y,{text:c,item:g,j:a})}}}return r}function ze(t,e){let n=e.parent;if(!(n instanceof re.Map)||be(n)?.parent!==t.nodes)return null;let o=n.get(N.part);return typeof o=="string"?o:null}function Es(t,e){let n=t.content.getContent();return n.length>0&&typeof n[0]=="string"?String(n.join("")).charAt(e):""}var li=t=>re.createID(t.item.id.client,t.item.id.clock+t.j);function Is(t,e,n){let o=t.doc,s=[],i=new Map,r=!1;return pe(o,e,u=>{if(r||!u.countable||!(u.parent instanceof re.Text)||u.redone===null)return;let l=u.parent,f=ye(o,u.redone);if(!ze(t,l)||!f||f.deleted||f.parent!==l)return;let d=Math.min(u.length,f.length);for(let c=0;c<d;c+=1){if(s.length>=Le){r=!0;return}let g=ue(o,re.createID(u.id.client,u.id.clock+c),i);s.push({text:l,item:f,j:c,root:g,char:Es(f,c)})}}),!r&&vs(t,s,n,i,()=>!0)}function vs(t,e,n,o,s){let i=t.doc;if(e.length===0)return!1;let r=new Set;for(let p of e)r.add(ze(t,p.text));let u=p=>H(p.item.id.client,p.item.id.clock+p.j),l=new Set(e.map(u)),f=ai(t,r,n,o,l);if(!f||f.size===0)return!1;let d=p=>{let y=0,x=p.item,m=p.j-1;for(;x!==null&&y<ii;){for(;m>=0&&x.countable;m-=1,y+=1){let k=re.createID(x.id.client,x.id.clock+m);if(l.has(H(k.client,k.clock)))continue;let S=ue(i,k,o),w=f.get(H(S.client,S.clock));if(w&&w.text!==p.text)return w;if(!x.deleted)return null}x=x.left,m=x?x.length-1:-1}return null},c=[],g=[];for(let p of e){let y=f.get(H(p.root.client,p.root.clock));if(y&&y.text!==p.text){c.push(p);continue}let x=s(p)?d(p):null;if(!x)continue;let m=g[g.length-1];m&&m.to.item===x.item&&m.to.j===x.j?m.chars.push(p):g.push({to:x,chars:[p]})}if(c.length===0&&g.length===0)return!1;let a=[];for(let{to:p,chars:y}of g){let x=Lt(p.text,li(p));if(x<0)continue;let m=y.map(S=>S.char).join("");if(m.length===0)continue;let k=re.getState(i.store,i.clientID);p.text.insert(x+1,m),y.forEach((S,w)=>a.push(k+w,S.root.client,S.root.clock,1)),c.push(...y)}pt(i,a);let h=new Map;for(let p of c){let y=h.get(p.text);y?y.add(u(p)):h.set(p.text,new Set([u(p)]))}for(let[p,y]of h)_e(p,y);return!0}function vn(t,e){let n=t.doc,o=[],s=new Set,i=new Set,r=new Map,u=0;return pe(n,e,l=>{if(!l.countable||!(l.parent instanceof re.Text)||l.redone===null)return;let f=l.parent,d=l.redone;if(d.client!==n.clientID||ze(t,f)===null)return;let c=ye(n,d);if(!(!c||c.parent!==f)){i.add(f);for(let g=0;g<l.length;g+=1){if((u+=1)>Le)return;let a=re.createID(l.id.client,l.id.clock+g);for(let m=0;m<ci;m+=1){let k=He(n,a);if(!k)break;a=k}let h=ue(n,a,r,!1);s.add(H(h.client,h.clock));let p=d.clock+g,y=o.length;y>0&&o[y-4]+o[y-1]===p&&o[y-3]===a.client&&o[y-2]+o[y-1]===a.clock?o[y-1]+=1:o.push(p,a.client,a.clock,1)}}}),pt(n,o),{roots:s,texts:i}}function Pn(t,e){let n=t.doc,o=n.getMap(Ie),s=new Set;for(let i of e){let r=i===null?null:/^(\d{1,16}):(\d{1,16})$/.exec(i),u=i===null?void 0:o.get(i);if(!r||!Array.isArray(u))continue;let l=Math.min(Number(u[2])||0,Le),f=Number(r[1]);for(let d=Number(r[2]),c=d+l;d<c;){let g=ye(n,re.createID(f,d));if(!g)break;if(!g.deleted&&g.parent instanceof re.Text&&ze(t,g.parent)){s.add(g.parent);break}d=g.id.clock+g.length}}return s}function On(t,e){let n=new Set,o=0;for(let s of t.doc.getMap(Ie).keys()){if((o+=1)>Le)break;for(let i of Pn(t,[s])){let r=ze(t,i);r!==null&&e.has(r)&&n.add(i)}}return n}function di(t,e){let n=be(e.parent);return n&&n.parent===t.nodes&&typeof n.parentSub=="string"?n.parentSub:null}var fi=(t,e)=>t.client<e.client||t.client===e.client&&t.clock>e.clock;function Nn(t,e,n){let o=t.doc,s=new Map,i=[...e],r=new Set;for(let p of i){let y=ze(t,p);y!==null&&r.add(y)}if(r.size===0)return!1;let u=new Set(On(t,r));for(let p of i)u.add(p);let l=new Map,f=new Map,d=(p,y)=>{let x=f.get(p);x?x.add(H(y.client,y.clock)):f.set(p,new Set([H(y.client,y.clock)]))},c=0;for(let p of u){let y=ze(t,p),x=di(t,p);if(y===null||x===null)continue;let m=n(y,x)?"":`${x}\0`;for(let k=p._start;k!==null&&c<Le;k=k.right)if(!(k.deleted||!k.countable))for(let S=0;S<k.length;S+=1,c+=1){let w=re.createID(k.id.client,k.id.clock+S);if(!He(o,w))continue;let A=ue(o,w,s),R=m+H(A.client,A.clock),P=l.get(R);P?fi(w,P.id)?(d(P.text,P.id),l.set(R,{id:w,text:p})):d(p,w):l.set(R,{id:w,text:p})}}for(let[p,y]of f)_e(p,y);let g=[];for(let{id:p,text:y}of l.values()){let x=ye(o,p);if(!x||x.deleted||x.parent!==y)continue;let m=p.clock-x.id.clock;g.push({text:y,item:x,j:m,root:ue(o,p,s),char:Es(x,m)})}let a=o.clientID;return vs(t,g,n,s,p=>p.item.id.client===a)||f.size>0}import*as ie from"yjs";function Ps(t,e,n){let o=s=>{let i=t.nodes.get(s),r=i instanceof ie.Map?i.get(N.children):void 0;return r instanceof ie.Array?r.toArray():[]};for(let s of o(e))if(!(typeof s!="string"||t.nodes.get(s)?.get?.(N.shell)?.local!=="t"))for(let r of o(s)){let u=typeof r=="string"?t.nodes.get(r):void 0,l=u instanceof ie.Map?u.get(N.text):void 0;l instanceof ie.Text&&n.add(l)}}var Ve=(t,e)=>be(e)?.parent===t.nodes&&e instanceof ie.Map?e:null;function Os(t,e){let n=t.doc.clientID.toString(36),o=Be(t),s=new Set,i=new Map,r=l=>{if(typeof l!="string")return new Set;let f=i.get(l);if(!f){let d=$e(t.parts.get(l));f=d?.kind==="xml"?lt(t,l,d.root).unseenWinners:new Set,i.set(l,f)}return f};if(pe(t.doc,e.insertions,l=>{if(l.parent!==t.nodes||l.deleted||!(l.content instanceof ie.ContentType))return;let f=l.content.type,d=Te(f),c=d?o(d.group):void 0;!d||c===void 0||c===n||r(f.get(N.part)).has(d.group)||s.add(d.from)}),s.size===0)return e.deletions;let u=new Set;for(let l of s)Ps(t,l,u);return u.size===0?e.deletions:Dt(t.doc,e.deletions,l=>u.has(l.parent))}function Ns(t,e){let n=new Map;if(pe(t.doc,e.insertions,c=>{let g=c.parent;!(g instanceof ie.Text)||!c.countable||Ve(t,g.parent)&&n.set(g,(n.get(g)??!1)||c.deleted)}),![...n.values()].some(Boolean))return e;let o=new Map,s=new Set;if(pe(t.doc,e.deletions,c=>{let g=Ve(t,c.parent);if(!g||c.parentSub!==z.splitFrom||!(c.content instanceof ie.ContentAny))return;let a=c.content.getContent()[0];if(typeof a!="string")return;let h=new Set;Ps(t,a,h);let p=[...h].filter(x=>n.get(x)===!0);if(p.length===0)return;for(let x of p)s.add(x);let y=g.get(N.key);typeof y=="string"&&o.set(g,y)}),o.size===0)return e;let i=new Map;pe(t.doc,e.deletions,c=>{let g=c.parent,h=(g instanceof ie.Array?Ve(t,g.parent):null)?.get(N.key);if(typeof h!="string"||!(c.content instanceof ie.ContentAny))return;let p=i.get(h);p||i.set(h,p=[]);for(let y of c.content.getContent())typeof y=="string"&&p.push(y)});let r=new Set(o.values()),u=new Set,l=[...r];for(;l.length>0;){let c=l.pop(),g=t.nodes.get(c);if(!(u.has(g)||!(g instanceof ie.Map))){u.add(g);for(let a of i.get(c)??[])l.push(a)}}let f=c=>Ve(t,c.parent)??Ve(t,c.parent?.parent),d=c=>c.parent instanceof ie.Array&&Ve(t,c.parent.parent)!==null&&c.content instanceof ie.ContentAny&&c.content.getContent().some(g=>typeof g=="string"&&r.has(g));return{insertions:Dt(t.doc,e.insertions,c=>s.has(c.parent)),deletions:Dt(t.doc,e.deletions,c=>u.has(f(c))||d(c))}}import*as Ds from"yjs";import{CONTENT_TYPES_PART as $t,asciiFold as je,NS as ae,attr as we,children as Gt,materialize as ui,relationshipsOf as gt,relsPartName as Wt,specOf as pi}from"@pptx-editor.dev/core/store";var Tn=Symbol("absent");function Ls(t,e,n){let o=gi(n);for(let s of t){let i=s.target;if(!(i instanceof Ds.Map)||!e(i))continue;let r=o.get(i);r||o.set(i,r=new Map);for(let[u,l]of s.changes.keys){let f=i.get(u),d=r.get(u);if(d)d[3]=f;else{let c=[i,u,l.action==="add"?Tn:l.oldValue,f];n.push(c),r.set(u,c)}}}}var As=new WeakMap;function gi(t){let e=As.get(t);if(e)return e;e=new Map;for(let n of t){let o=e.get(n[0]);o||e.set(n[0],o=new Map),o.has(n[1])||o.set(n[1],n)}return As.set(t,e),e}var _s=t=>t._item?.deleted!==!0;function Fs(t){return t.filter(([e,n,o])=>o!==Tn&&_s(e)&&!e.has(n)).map(([e,n,o])=>[e,n,o])}function Cn(t){let e=(n,o)=>JSON.stringify(n)===JSON.stringify(o);return t.filter(([n,o,s,i])=>_s(n)&&i!==void 0&&s!==Tn&&e(n.get(o),s)&&!e(s,i)).map(([n,o,,s])=>[n,o,s])}function hi(t){let e=new Set,n=[t];for(;n.length>0;){let o=n.pop();if(!(o.type!=="element"||zs(o))){for(let s of o.attrs)s.ns===ae.r&&e.add(s.value);for(let s of o.children)n.push(s)}}return e}function Ts(t,e){let n={next:t.nextId},o=e.map(s=>ui(pi(s),t.root.kind,n));return{partName:t.partName,root:{...t.root,children:[...t.root.children,...o]},nextId:n.next}}var zs=t=>t.ns===ae.p&&t.local==="sldId";function mi(t,e){for(let n of t.parts.values()){if(n.kind!=="xml")continue;let o=n.xml.root;if(o.ns!==ae.p||o.local!=="presentation")continue;let s=o.children.find(m=>m.type==="element"&&m.ns===ae.p&&m.local==="sldIdLst");if(!s)return;let i=[],r=new Set;for(let m of s.children){if(m.type!=="element"||!zs(m))continue;let k=m.attrs.find(S=>S.ns===ae.r&&S.local==="id")?.value;k===void 0||!e.has(k)?r.add(m):i.push(we(m,"id")??"")}let u=[],l=m=>{for(let k of m.children)k.type==="element"&&(k.ns===ae.p14&&k.local==="section"?u.push(k):l(k))};l(o);let f=new Map(u.map((m,k)=>[m,k])),d=new Map;u.forEach((m,k)=>{let S=m.children.find(w=>w.type==="element"&&w.ns===ae.p14&&w.local==="sldIdLst");if(S)for(let w of Gt(S,{ns:ae.p14,local:"sldId"})){let A=we(w,"id")??"",R=d.get(A);R?R[R.length-1]!==k&&R.push(k):d.set(A,[k])}});let c=new Map,g=0;for(let m of i){let k=d.get(m);if(!k)continue;let S=k.find(w=>w>=g)??k[0];c.set(m,S),g=Math.max(g,S)}let a=new Map(i.map((m,k)=>[m,k])),h=r.size>0,p=(m,k)=>{let S=m.children.map(w=>{if(w.type!=="element"||w.ns!==ae.p14||w.local!=="sldIdLst")return w;let A=new Set,P=[...w.children.filter(b=>{if(b.type!=="element"||b.ns!==ae.p14||b.local!=="sldId")return!0;let I=we(b,"id")??"";return c.get(I)!==k||A.has(I)?!1:(A.add(I),!0)})].sort((b,I)=>{let C=b.type==="element"?a.get(we(b,"id")??"")??0:0,j=I.type==="element"?a.get(we(I,"id")??"")??0:0;return C-j});return P.length===w.children.length&&P.every((b,I)=>b===w.children[I])?w:(h=!0,{...w,children:P})});return S.every((w,A)=>w===m.children[A])?m:{...m,children:S}},y=m=>{let k=m.children.filter(w=>w.type!=="element"||!r.has(w)).map(w=>{if(w.type!=="element")return w;let A=f.get(w)??-1;return A>=0?p(w,A):y(w)});return k.length===m.children.length&&k.every((w,A)=>w===m.children[A])?m:{...m,children:k}},x=y(o);return h?{...n.xml,root:x}:void 0}}var yi=new Set(["hlinkClick","hlinkHover","hlinkMouseOver"]),An=t=>t.endsWith("/relationships/slide");function Cs(t,e){let n=!1,o=i=>{let r=!1,u=[];for(let l of i.children){if(l.type!=="element"){u.push(l);continue}let f=l.attrs.some(c=>c.ns===ae.r&&c.value===e);if(f&&l.ns===ae.a&&yi.has(l.local)){r=!0;continue}f&&(n=!0);let d=o(l);d!==l&&(r=!0),u.push(d)}return r?{...i,children:u}:i},s=o(t);return n?void 0:s}function ki(t,e){return{...t,root:{...t.root,children:t.root.children.filter(n=>n.type!=="element"||n.local!=="Relationship"||we(n,"Id")!==e)}}}var qe=(t,e)=>{let n=t.parts.get(e);return n?.kind==="xml"?n.xml:void 0};function Dn(t,e){let n=new Map,o=new Set;for(let c of e.parts.keys())o.add(je(c));let s=c=>e.parts.has(c)||o.has(je(c)),i=[],r=new Set,u=c=>{!c||r.has(c.partName)||(r.add(c.partName),i.push(c))},l=!1;for(let c of t.parts.keys())e.parts.has(c)||(l=!0);for(let[c,g]of e.parts){if(g.kind!=="xml")continue;let a=Wt(c);if(!l&&t.parts.get(c)===g&&t.parts.get(a)===e.parts.get(a))continue;let h=w=>{let A=Cs((n.get(c)??g.xml).root,w);if(!A)return!1;n.set(c,{...n.get(c)??g.xml,root:A});let R=n.get(a)??qe(e,a);return R&&n.set(a,ki(R,w)),!0};for(let w of gt(e,c))!w.external&&w.target&&!s(w.target)&&An(w.type)&&h(w.id);let p=hi((n.get(c)??g.xml).root);if(p.size===0)continue;for(let w of gt(e,c))!p.has(w.id)||w.external||!w.target||s(w.target)||An(w.type)||u(t.parts.get(w.target));let y=new Set(gt(e,c).map(w=>w.id)),x=qe(t,a);if(!x)continue;let m=Gt(x.root,{ns:ae.rel,local:"Relationship"}).filter(w=>{let A=we(w,"Id");return A!==void 0&&p.has(A)&&!y.has(A)});for(let w of gt(t,c)){let A=m.findIndex(P=>we(P,"Id")===w.id);if(A<0||w.external||!w.target||s(w.target)||!An(w.type))continue;let R=Cs((n.get(c)??g.xml).root,w.id);R&&(n.set(c,{...n.get(c)??g.xml,root:R}),m.splice(A,1))}if(m.length===0)continue;let k=n.get(a)??qe(e,a)??{partName:a,root:{...x.root,children:[]},nextId:x.nextId};n.set(a,Ts(k,m));let S=new Set(m.map(w=>we(w,"Id")));for(let w of gt(t,c))!S.has(w.id)||w.external||!w.target||s(w.target)||u(t.parts.get(w.target))}{let c=[...e.parts.values()].find(p=>p.kind==="xml"&&p.xml.root.ns===ae.p&&p.xml.root.local==="presentation"),g=c&&(n.get(Wt(c.partName))??qe(e,Wt(c.partName))),a=c&&Wt(c.partName),h=c&&(t.parts.get(c.partName)!==c||t.parts.get(a)!==e.parts.get(a)||n.has(a));if(g&&h&&a&&e.parts.has(a)){let p=new Set(Gt(g.root,{ns:ae.rel,local:"Relationship"}).map(x=>we(x,"Id")??"")),y=mi(e,p);y&&n.set(y.partName,y)}}let f=qe(e,$t),d=qe(t,$t);if(f&&d){let c=(m,k,S)=>{let w=new Map;for(let A of Gt(m,{ns:ae.ct,local:k})){let R=we(A,S);R!==void 0&&!w.has(je(R))&&w.set(je(R),A)}return w},g=c(f.root,"Override","PartName"),a=c(f.root,"Default","Extension"),h=c(d.root,"Override","PartName"),p=c(d.root,"Default","Extension"),y=new Set,x=new Set(e.parts.keys());for(let m of i)x.add(m.partName);for(let m of x){if(m===$t)continue;let k=je(m.slice(m.lastIndexOf(".")+1));if(g.has(je(m))||a.has(k))continue;let S=h.get(je(m))??p.get(k);S&&y.add(S)}y.size>0&&n.set($t,Ts(f,[...y]))}return[...[...n.values()].map(c=>({kind:"xml",partName:c.partName,xml:c})),...i]}var js=0;function Ln(t,...e){for(let n of[...t])try{n(...e)}catch(o){console.warn("[pptx-editor] collaboration listener failed",o)}}function xi(t){let{doc:e,documentId:n,identity:o,awareness:s}=t;if(typeof n!="string"||n.trim()===""||n.length>256)throw new Ke("invalid-document-id");let i=ps(o);if(i)throw new Ke(i);let r=$n(e),u=wi("initializing"),l=new Set,f=new Set,d=new Set,c=null,g=null,a={value:0},h=null,p=null,y=null,x=!1,m=!0,k=[{...o,isLocal:!0}],S=[],w=null,A=null,R=null,P=!1;js+=1;let b=`${e.clientID.toString(36)}-${js}`,I=(T,F,M,L=!1)=>{if(!u.set(T,F,M,L))return;let v=u.snapshot().reason;Ln(l,T,v?.code,v?.detail)},C=()=>m?I("ready"):I("disconnected","transport-disconnected"),j=T=>{s&&!x&&s.setLocalStateField(zt,ys(o,T))},_=()=>{if(!s)return;let T=ks(s);JSON.stringify(T)!==JSON.stringify(k)&&(k=T,Ln(f,k));let F=g?ws(s,e,g):[];JSON.stringify(F)!==JSON.stringify(S)&&(S=F,Ln(d,S))};j(void 0),s?.on("change",_),_();let E=(T,F,M,L=!0)=>{let v=F?T.redoStack:T.undoStack,$=v.length;F?T.undoing=!0:T.redoing=!0;try{e.transact(M,Jt)}finally{T.undoing=!1,T.redoing=!1}if(v.length!==$+1)return!1;let G=v[v.length-2];if(!L||!G)return!0;let oe=v.pop();return G.deletions=me.mergeDeleteSets([G.deletions,oe.deletions]),G.insertions=me.mergeDeleteSets([G.insertions,oe.insertions]),!0},O=(T,F,M)=>F.length>0&&E(T,!1,()=>{for(let[L,v,$]of F)L.set(v,$)},M),D=(T,F)=>{let M=F?T?.undoStack:T?.redoStack;if(!T||!M||M.length===0)return!1;P=!1;let L=p?.package(),v=M[M.length-1];if(F)qo(r,v,X=>e.transact(X,Ze)),v.deletions=Os(r,v);else{let X=Ns(r,v);v.insertions=X.insertions,v.deletions=X.deletions}let $=[...M];y=null,F?T.undo():T.redo(),!F&&y===v&&Qo(r,v,X=>e.transact(X,Ze));let G=y,oe=new Set(M),Xt=$.reverse().filter(X=>!oe.has(X)&&X!==G),Je=X=>X.meta.get("attrs")??[],Qe=!1,Me=!1,Re=null;if(F&&G&&G!==v)y=null,T.redo(),Re=y,Me=!0;else if(!F&&G===v)Qe=O(T,Cn(Je(v)),!0);else if(!F){G&&(y=null,T.undo(),Re=y);for(let X of Xt.slice(1).reverse())T.redoStack.push(X);Qe=O(T,Cn(Je(v)),!1)}if(Re){let X=Re;e.transact(()=>vn(r,X.deletions),Ze)}let W=G&&!Me&&(F||G===v)?G:null;if(W&&g){let X=g,te=W,Q=(ce,Pe)=>X.idOf(ce,Pe)!==void 0,de=new Set;E(T,F,()=>{let ce=vn(r,te.deletions);de=ce.roots,F&&Zo(r,te,Q),Is(r,te.deletions,Q),Nn(r,ce.texts,Q)}),X.forgetDeleted(de)}let V=p?.package(),se=F&&G&&!Me?Fs(Je(G)):[],Z=L&&V&&!Me?Dn(L,V):[];if((se.length>0||Z.length>0)&&V&&g){let X=g;e.transact(()=>{for(let[Q,de,ce]of se)Q.set(de,ce);if(Z.length===0)return;let te=new Map(V.parts);for(let Q of Z)te.set(Q.partName,Q);X.writeChange(V,{parts:te},Z.map(Q=>Q.partName))},qt)}return!P&&(F?G!==null&&!Me:G===v||Qe)};return{documentId:n,sessionId:b,identity:o,get attached(){return c!==null},status:()=>u.status(),statusSnapshot:()=>u.snapshot(),subscribeStatus(T){return l.add(T),()=>l.delete(T)},setConnected(T){if(x||T===m)return;m=T;let F=u.snapshot();(F.status==="ready"||F.status==="disconnected")&&C()},participants:()=>k,subscribeParticipants(T){return f.add(T),()=>f.delete(T)},remoteSelections:()=>S,subscribeRemoteSelections(T){return d.add(T),()=>d.delete(T)},setLocalSelection(T){let F=T&&g?ms(T,g):void 0;w=T&&F?{selection:T,encoded:F}:null,j(F)},remoteSelectionMove:()=>A,historySelection:()=>R&&g?jt(R,e,g):null,canUndo:()=>h?h.undoStack.length>0:!1,canRedo:()=>h?h.redoStack.length>0:!1,undo:()=>D(h,!0),redo:()=>D(h,!1),attach(T){if(x)return()=>{};c?.(),I("initializing");let F=r.meta.get("schema");if(F!==void 0&&F!==Vt)return I("error","schema-version-mismatch",`room schema ${String(F)}`),()=>{};let M=new Ft(r,a);p=T,g=M;let L=(W,V,se=!1)=>{let Z=T.package(),X=M.rebuild(W,Z,V);if(!X.ok)return P=!0,I("error","remote-apply-failed",X.reason,!0);let te=w?jt(w.encoded,e,M):null;if(A=w&&te&&JSON.stringify(te)!==JSON.stringify(w.selection)?{from:w.selection,to:te}:null,A&&w&&(w={selection:A.to,encoded:w.encoded}),X.parts.length>0||X.removed.length>0){let de=T.applyRemoteParts(X.parts,X.removed,"collaboration");if(A=null,!de.ok){P=!0;let ce=de.rejection.code;return ce==="unsafe-part-name"?I("error","unsafe-part-name",ce):I("error","remote-apply-failed",ce,!0)}}A=null,se&&Xt(Z,T.package());let Q=u.snapshot();Q.status==="error"&&Q.recovering&&C(),_()};M.seeded?L(M.allParts(T.package()),!0):e.transact(()=>{r.meta.set("schema",Vt),r.meta.set("documentId",n),M.seed(T.package())},en);let v=new me.UndoManager([r.parts,r.binaries,r.nodes],{trackedOrigins:new Set([kt,Jt]),captureTimeout:Number.POSITIVE_INFINITY,deleteFilter:Ys(r.nodes)}),$=W=>{let V=W.parent;return V instanceof me.Map&&V.get(N.attrs)===W},G=W=>{let V=v.currStackItem;if((v.undoing||v.redoing)&&V){W.stackItem.meta.set("attrs",V.meta.get("attrs")??[]);return}let se=W.stackItem.meta.get("attrs")??[],Z=new Set;for(let X of W.changedParentTypes?.values()??[])for(let te of X)Z.add(te);Ls(Z,$,se),W.stackItem.meta.set("attrs",se)};v.on("stack-item-added",W=>{w&&W.stackItem.meta.set("selection",w.encoded),G(W)}),v.on("stack-item-updated",G),v.on("stack-item-popped",W=>{R=W.stackItem.meta.get("selection")??null,y=W.stackItem}),h=v;let oe=T.subscribeLocal(W=>{W.merged||v.stopCapturing(),M.hasHiddenListings(W.parts)&&e.transact(()=>M.dropHiddenListings(W.parts,W.before,W.after),Zt),e.transact(()=>M.writeChange(W.before,W.after,W.parts),kt);let V=M.showingUnlisted(W.parts);V.length>0&&L(V,!1),_()}),Xt=(W,V)=>{let se=Dn(W,V);if(se.length===0)return;let Z=new Map(V.parts);for(let X of se)Z.set(X.partName,X);e.transact(()=>M.writeChange(V,{parts:Z},se.map(X=>X.partName)),qt)},Je=(W,V)=>{let se=M.deletedText,Z=se.size>0?_o(r,W):new Set;if(V.size===0&&Z.size===0)return;let X={keyOf:M.keyOf.bind(M),package:T.package()},te=[];e.transact(()=>{for(let[Q,de]of V)bs(r,Q,de,se,X,(ce,Pe,ht)=>te.push([ce,Pe,ht]));Ms(r,Z,se)},Qt);for(let[Q,de,ce]of te)for(let Pe of[...v.undoStack,...v.redoStack]){if(!me.isDeleted(Pe.insertions,Q))continue;let ht=me.createDeleteSet();ht.clients.set(de.client,[{clock:de.clock,len:ce}]),Pe.insertions=me.mergeDeleteSets([Pe.insertions,ht])}},Qe=e.getMap(Ie),Me=W=>{let V=W.origin;if(V===kt||V===en||V===Ze||V===Zt)return;let se=M.touchedParts(W);if(se.size>0&&L(se,!1,!W.local),W.local)return;let Z=M.newCopies(W);Je(W,Z);let X=W.changed.get(Qe),te=X?Pn(r,X):new Set;if(Z.size>0&&r.doc.getMap(Ie).size>0)for(let Q of On(r,new Set(Z.keys())))te.add(Q);if(te.size>0){let Q=(de,ce)=>M.idOf(de,ce)!==void 0;e.transact(()=>Nn(r,te,Q),Qt)}};e.on("afterTransaction",Me),u.status()==="initializing"&&C(),_();let Re=()=>{oe(),e.off("afterTransaction",Me),v.destroy(),h===v&&(h=null),g===M&&(g=null),p===T&&(p=null),w=null,R=null,j(void 0),_(),c===Re&&(c=null)};return c=Re,Re},destroy(){x||(c?.(),s?.off("change",_),s?.setLocalStateField(zt,null),x=!0,I("destroyed","collaboration-session-destroyed"),l.clear(),f.clear(),d.clear())}}}export{Ke as CollaborationSchemaError,Qs as collaborationModule,xi as createYjsCollaborationSession,Ht as legacyComments,Js as reviewModule};
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@pptx-editor.dev/pro",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Commercial capabilities for PPTX Editor, as EditorModules: the review module (comments and suggestions) and realtime collaboration.",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ },
12
+ "./package.json": "./package.json"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md",
17
+ "LICENSE.md",
18
+ "THIRD_PARTY_NOTICES.md",
19
+ "!dist/metafile-*.json"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsup",
23
+ "typecheck": "bun check",
24
+ "api:extract": "node ../../scripts/api-extractor.mjs --package @pptx-editor.dev/pro --local",
25
+ "api:check": "node ../../scripts/api-extractor.mjs --package @pptx-editor.dev/pro"
26
+ },
27
+ "peerDependencies": {
28
+ "@pptx-editor.dev/core": "0.x"
29
+ },
30
+ "devDependencies": {
31
+ "@pptx-editor.dev/core": "workspace:*"
32
+ },
33
+ "license": "LicenseRef-EigenPal-Pro-Evaluation-1.0",
34
+ "dependencies": {
35
+ "y-protocols": "^1.0.7",
36
+ "yjs": "^13.6.32"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/eigenpal/pptx-editor.git",
41
+ "directory": "packages/pro"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ }
46
+ }