@betteroffice/pptx-react 0.0.3 → 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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Elia Hilse, The OpenOOXML Project
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -8,11 +8,6 @@ slides are painted onto canvas.
8
8
 
9
9
  <!-- TODO(author): add a screenshot/GIF here once hosted; an <img> with an unresolvable src renders broken on npm -->
10
10
 
11
- > **Early (`0.0.x`).** The core surfaces — opening/saving documents, the editor
12
- > components, collaboration — are settling and unlikely to change shape. Smaller
13
- > APIs may still move between releases; breaking changes are always listed in
14
- > the changelog.
15
-
16
11
  ```bash
17
12
  bun add @betteroffice/pptx-react @betteroffice/pptx react react-dom
18
13
  ```
@@ -37,7 +32,7 @@ export function Presentation({ file, fontBytes }: {
37
32
  ```
38
33
 
39
34
  Font bytes are supplied by the host and registered with the Rust shaper; pair
40
- with [`@betteroffice/docx-fonts`](https://www.npmjs.com/package/@betteroffice/docx-fonts)
35
+ with [`@betteroffice/fonts`](https://www.npmjs.com/package/@betteroffice/fonts)
41
36
  for metric-compatible open faces.
42
37
 
43
38
  ## Edit
@@ -46,9 +41,10 @@ Click text to place the Rust-computed caret, type to edit the yrs story and
46
41
  trigger Rust reflow, drag or resize shapes on the canvas, or use the toolbar
47
42
  for bold, italic, size, color, slides, and text boxes.
48
43
 
49
- Props: `file`, `fonts`, `collaboration`, `i18n`, `className`, `onReady`
50
- (exposes the core `PresentationHandle` and a `refresh` callback for host-driven
51
- edits), `onChange` (deck snapshots), `onError`.
44
+ Props: `file`, `fonts`, `collaboration`, `i18n`, `className`, `fileName`,
45
+ `onReady` (exposes the core `PresentationHandle`, a `refresh` callback for
46
+ host-driven edits, `refreshProposals`, and `save`), `onChange` (deck snapshots), `onError`, and
47
+ `onSave` (receives the saved bytes; without it, saving downloads the file).
52
48
 
53
49
  ## What works today
54
50
 
@@ -56,10 +52,55 @@ edits), `onChange` (deck snapshots), `onError`.
56
52
  - Canvas interactions: shape selection, drag, and resize
57
53
  - Text editing with caret and selection computed by the engine
58
54
  - Slide management (add, delete), text boxes, undo/redo
55
+ - Saving the deck back to `.pptx` — toolbar button, Ctrl/Cmd+S, or `api.save()`
59
56
  - Localized UI via the `i18n` prop
60
57
  ([`@betteroffice/pptx-i18n`](https://www.npmjs.com/package/@betteroffice/pptx-i18n))
61
58
  - Real-time collaboration with people or agents; the deck is a CRDT
62
59
  - Live collaborator shape selections and presence chips, shown in each peer's color
60
+ - Agent proposal review directly on the slide canvas, with inline text diffs,
61
+ old/new shape bounds, before/after previews, acceptance, rejection, and Undo
62
+
63
+ ## Review agent proposals
64
+
65
+ Use the editor API supplied to `onReady` to stage edits from your agent, then
66
+ refresh the pending list:
67
+
68
+ ```ts
69
+ api.handle.propose('editor-agent', 'Clarify the speaker notes', [{
70
+ type: 'setSlideNotes',
71
+ slideId: api.handle.snapshot().slides[0].id,
72
+ text: 'Explain the customer outcome before the implementation details.',
73
+ }]);
74
+ api.refreshProposals();
75
+ ```
76
+
77
+ Pending edits appear directly on the slide canvas: deleted text is red and
78
+ struck through, inserted text is green and underlined, and moved/resized shapes
79
+ show their previous and proposed bounds. Speaker notes have their own inline
80
+ text diff. The canvas toolbar selects a proposal when several affect the slide
81
+ and provides acceptance, rejection, and access to review details. Acceptance is
82
+ available after the current diff has painted successfully.
83
+
84
+ The canvas is in review mode while showing a diff. **Edit slide** (or Escape)
85
+ returns to normal editing; **Show changes** restores the diff. This keeps
86
+ temporary review offsets separate from editable text. Saving, PNG export, and
87
+ presentation mode use the actual document. Changes from other users refresh the
88
+ review, and stale targets require the explicit review described below.
89
+
90
+ The **Agent proposals** button shows the pending count. Each group shows its
91
+ author, rationale, targets, and text changes. **Preview** opens current and
92
+ proposed slide renderings, with a target selector for groups spanning multiple
93
+ shapes or slides. Notes changes also appear as text because notes are outside
94
+ the slide canvas.
95
+
96
+ Accepting a group updates the editor, calls `onChange`, and creates one Undo
97
+ step. Rejecting it leaves the deck untouched. If a target changed, preview its
98
+ current state before choosing **Apply updated proposal**. A further target
99
+ change detected at that click refreshes the preview for another review.
100
+
101
+ Pending proposals are session-local and disappear when the deck closes. Only
102
+ accepted edits are saved and synchronized. Existing host-driven edits may keep
103
+ using `api.refresh()`, which also refreshes the proposal list.
63
104
 
64
105
  ## Collaboration
65
106
 
@@ -92,4 +133,5 @@ import { CollaborationProvider } from '@betteroffice/pptx';
92
133
  The editor is browser-only (canvas, wasm); under Next.js load it with
93
134
  `next/dynamic` and `ssr: false`.
94
135
 
95
- Docs: https://betteroffice.dev · Apache-2.0.
136
+ [JavaScript guide](https://docs.betteroffice.dev/docs/javascript) ·
137
+ [Changelog](https://github.com/openooxml/betteroffice/blob/main/packages/pptx-react/CHANGELOG.md) · Apache-2.0.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { CSSProperties, ReactNode } from 'react';
3
- import { PptxFontFace, CollaborationReplica, PptxPresence, PresentationHandle, DeckSnapshot } from '@betteroffice/pptx';
3
+ import { PptxFontFace, CollaborationReplica, PptxPresence, PresentationHandle, DeckSnapshot, ParagraphAlignment } from '@betteroffice/pptx';
4
4
  import { Translations, TFunction } from '@betteroffice/pptx-i18n';
5
5
 
6
6
  interface PptxTextSelection {
@@ -8,10 +8,15 @@ interface PptxTextSelection {
8
8
  storyId: string;
9
9
  anchor: number;
10
10
  focus: number;
11
+ focusLine?: number;
11
12
  }
12
13
  interface PptxEditorApi {
14
+ focus: () => void;
13
15
  handle: PresentationHandle;
14
16
  refresh: () => void;
17
+ refreshProposals: () => void;
18
+ /** Serialize the presentation back to .pptx bytes, edits included. */
19
+ save: () => Uint8Array;
15
20
  }
16
21
  interface PptxEditorCollaborationOptions {
17
22
  clientId: number;
@@ -27,9 +32,13 @@ interface PptxEditorProps {
27
32
  collaboration?: PptxEditorCollaborationOptions;
28
33
  i18n?: Translations;
29
34
  className?: string;
35
+ /** Download name for the save button; falls back to `presentation.pptx`. */
36
+ fileName?: string;
30
37
  onReady?: (api: PptxEditorApi) => void;
31
38
  onChange?: (snapshot: DeckSnapshot) => void;
32
39
  onError?: (error: Error) => void;
40
+ /** Receives the saved bytes; without it, saving downloads the file. */
41
+ onSave?: (bytes: Uint8Array) => void;
33
42
  }
34
43
  declare function PptxEditor({ i18n, ...props }: PptxEditorProps): react.JSX.Element;
35
44
 
@@ -95,6 +104,7 @@ interface SelectionFormatting {
95
104
  italic?: boolean;
96
105
  underline?: boolean;
97
106
  textColor?: string;
107
+ align?: ParagraphAlignment;
98
108
  }
99
109
  type FormattingAction = 'bold' | 'italic' | 'underline' | {
100
110
  type: 'fontFamily';
@@ -105,6 +115,9 @@ type FormattingAction = 'bold' | 'italic' | 'underline' | {
105
115
  } | {
106
116
  type: 'textColor';
107
117
  value: string;
118
+ } | {
119
+ type: 'align';
120
+ value: ParagraphAlignment;
108
121
  };
109
122
  interface ShapeFormatting {
110
123
  geometry?: string;
@@ -141,6 +154,8 @@ interface ToolbarProps {
141
154
  onInsertSlide?: (layoutPartPath?: string | null) => void;
142
155
  slideLayouts?: readonly SlideLayoutOption[];
143
156
  currentLayoutPartPath?: string | null;
157
+ onSave?: () => void;
158
+ onExportPng?: () => void;
144
159
  onUndo?: () => void;
145
160
  onRedo?: () => void;
146
161
  canUndo?: boolean;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import {initWasm,openPresentation,sizeCanvasForSlide,paintSlide,PRESENCE_LABEL_DURATION_MS}from'@betteroffice/pptx';import {createContext,useMemo,useContext,useState,useRef,useCallback,useEffect}from'react';import {en,deepMerge,createT}from'@betteroffice/pptx-i18n';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Ht=createContext(en),Nt=createContext("en");function tt({i18n:e,children:t}){let r=typeof e?._lang=="string"?e._lang:"en",i=useMemo(()=>deepMerge(en,e),[e]);return jsx(Nt.Provider,{value:r,children:jsx(Ht.Provider,{value:i,children:t})})}function He(){let e=useContext(Ht),t=useContext(Nt);return {t:useMemo(()=>createT(e,t),[e,t])}}var Ne=createContext(null);function Ao(){let e=useContext(Ne);if(!e)throw new Error("useEditorToolbar must be used within an <EditorToolbar> component");return e}function B({name:e,size:t=20,style:r}){return jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",style:{display:"inline-flex",flexShrink:0,...r},children:[e==="undo"&&jsx("path",{d:"m9 7-5 5 5 5M5 12h9a6 6 0 0 1 6 6"}),e==="redo"&&jsx("path",{d:"m15 7 5 5-5 5m4-5h-9a6 6 0 0 0-6 6"}),e==="newSlide"&&jsxs(Fragment,{children:[jsx("rect",{x:"3",y:"5",width:"15",height:"14",rx:"1.5"}),jsx("path",{d:"M7 9h7M7 13h5M20 9v6m-3-3h6"})]}),e==="select"&&jsx("path",{d:"m6 3 12 9-6 1.5L9 19Z"}),e==="textBox"&&jsxs(Fragment,{children:[jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"1.5"}),jsx("path",{d:"M8 8h8m-4 0v8m-3 0h6"})]}),e==="shape"&&jsx("rect",{x:"4",y:"6",width:"16",height:"12",rx:"3"}),e==="fillColor"&&jsxs(Fragment,{children:[jsx("path",{d:"m7 4 10 10-5 5-7-7Z"}),jsx("path",{d:"m5 12 7-7m6 12h2"})]}),e==="borderColor"&&jsx(Fragment,{children:jsx("path",{d:"M5 18h14M8 15l8-8 2 2-8 8H8Z"})}),e==="borderWidth"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 7h14",strokeWidth:"1"}),jsx("path",{d:"M5 12h14",strokeWidth:"2"}),jsx("path",{d:"M5 18h14",strokeWidth:"3"})]}),e==="bold"&&jsx("path",{d:"M7 4h6a4 4 0 0 1 0 8H7zm0 8h7a4 4 0 0 1 0 8H7z"}),e==="italic"&&jsx("path",{d:"M10 4h8M6 20h8M14 4 10 20"}),e==="underline"&&jsxs(Fragment,{children:[jsx("path",{d:"M7 4v7a5 5 0 0 0 10 0V4"}),jsx("path",{d:"M5 20h14"})]}),e==="textColor"&&jsxs(Fragment,{children:[jsx("path",{d:"m7 16 5-12 5 12M9 11h6"}),jsx("path",{d:"M5 20h14",strokeWidth:"3"})]}),e==="more"&&jsxs(Fragment,{children:[jsx("circle",{cx:"5",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),jsx("circle",{cx:"12",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),jsx("circle",{cx:"19",cy:"12",r:"1",fill:"currentColor",stroke:"none"})]}),e==="chevronDown"&&jsx("path",{d:"m7 10 5 5 5-5"}),e==="remove"&&jsx("path",{d:"M5 12h14"}),e==="add"&&jsx("path",{d:"M12 5v14M5 12h14"})]})}var T={text:"#3c4043",muted:"#5f6368",disabled:"#9aa0a6",hover:"#e2e7ef",active:"#d3e3fd",border:"#c7cacf",surface:"#ffffff",rail:"#edf2fa"},zo={appearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:2,minWidth:28,height:28,padding:"0 5px",border:0,borderRadius:4,color:T.text,font:"500 13px ui-sans-serif, system-ui, sans-serif",lineHeight:1,whiteSpace:"nowrap",boxSizing:"border-box"};function Kt(e,t,r,i){return {...zo,background:t?T.active:r&&!e?T.hover:"transparent",color:e?T.disabled:T.text,cursor:e?"default":"pointer",opacity:e?.48:1,...i}}function ce({active:e=false,disabled:t=false,title:r,onClick:i,children:a,style:d,testId:h,ariaExpanded:g}){let[c,y]=useState(false);return jsx("button",{type:"button","data-testid":h,disabled:t,"aria-label":r,"aria-pressed":e||void 0,"aria-expanded":g,title:r,onMouseDown:S=>S.preventDefault(),onMouseEnter:()=>y(true),onMouseLeave:()=>y(false),onClick:t?void 0:i,style:Kt(t,e,c,d),children:a})}function be({label:e,children:t,style:r}){return jsx("div",{role:"group","aria-label":e,style:{display:"inline-flex",alignItems:"center",gap:1,flex:"0 0 auto",...r},children:t})}function De(){return jsx("div",{role:"separator",style:{width:1,height:24,margin:"0 5px",background:T.border,flex:"0 0 auto"}})}function Ae({title:e,trigger:t,children:r,disabled:i=false,active:a=false,menuWidth:d=220,style:h,testId:g}){let[c,y]=useState(false),[S,C]=useState(false),[z,U]=useState({top:0,left:0}),w=useRef(null),D=useRef(null),q=useCallback(()=>y(false),[]);return useEffect(()=>{if(!c||!w.current)return;let k=w.current.getBoundingClientRect(),J=Math.min(k.left,Math.max(8,window.innerWidth-d-8));U({top:k.bottom+4,left:J});},[c,d]),useEffect(()=>{if(!c)return;let k=$=>{let X=$.target;!w.current?.contains(X)&&!D.current?.contains(X)&&q();},J=$=>{$.key==="Escape"&&q();},I=()=>q();return document.addEventListener("mousedown",k),document.addEventListener("keydown",J),window.addEventListener("scroll",I,true),()=>{document.removeEventListener("mousedown",k),document.removeEventListener("keydown",J),window.removeEventListener("scroll",I,true);}},[c,q]),jsxs("div",{style:{position:"relative",display:"inline-flex",flex:"0 0 auto"},children:[jsx("button",{ref:w,type:"button","data-testid":g,disabled:i,"aria-label":e,"aria-haspopup":"menu","aria-expanded":c,title:e,onMouseDown:k=>k.preventDefault(),onMouseEnter:()=>C(true),onMouseLeave:()=>C(false),onClick:()=>!i&&y(k=>!k),style:Kt(i,a||c,S,h),children:t}),c&&jsx("div",{ref:D,role:"menu","aria-label":e,onMouseDown:k=>k.preventDefault(),style:{position:"fixed",top:z.top,left:z.left,zIndex:1e4,width:d,maxHeight:"min(440px, calc(100vh - 16px))",overflowY:"auto",padding:6,border:`1px solid ${T.border}`,borderRadius:8,background:T.surface,boxShadow:"0 4px 16px rgba(60, 64, 67, 0.24)",boxSizing:"border-box"},children:r(q)})]})}function Oe({label:e,icon:t,selected:r=false,disabled:i=false,onClick:a,close:d}){let[h,g]=useState(false);return jsxs("button",{type:"button",role:"menuitem",disabled:i,"aria-label":e,onMouseEnter:()=>g(true),onMouseLeave:()=>g(false),onClick:()=>{i||(a?.(),d?.());},style:{appearance:"none",display:"flex",alignItems:"center",gap:10,width:"100%",minHeight:32,padding:"5px 9px",border:0,borderRadius:4,background:h&&!i?T.hover:"transparent",color:i?T.disabled:T.text,cursor:i?"default":"pointer",opacity:i?.48:1,font:"400 13px ui-sans-serif, system-ui, sans-serif",textAlign:"left",boxSizing:"border-box"},children:[jsx("span",{style:{display:"inline-grid",placeItems:"center",width:20,flex:"0 0 auto"},children:t}),jsx("span",{style:{flex:1},children:e}),r&&jsx("span",{"aria-hidden":"true",children:"\u2713"})]})}function Ho(){return jsx("div",{role:"separator",style:{height:1,margin:"5px 2px",background:T.border}})}function ot({value:e,label:t,onChange:r,onClear:i,icon:a="textColor",none:d=false,clearLabel:h,disabled:g=false,testId:c}){let[y,S]=useState(false);return jsxs("span",{style:{display:"inline-flex",alignItems:"center",height:28},children:[jsxs("label",{title:t,"aria-label":t,style:{display:"inline-grid",placeItems:"center",width:28,height:28,borderRadius:4,background:y&&!g?T.hover:"transparent",color:g?T.disabled:T.text,cursor:g?"default":"pointer",opacity:g?.48:1,boxSizing:"border-box",position:"relative"},onMouseEnter:()=>S(true),onMouseLeave:()=>S(false),children:[jsx(B,{name:a,size:20}),jsx("span",{"aria-hidden":"true",style:{position:"absolute",left:5,right:5,bottom:2,height:3,borderRadius:2,background:d?"transparent":e,border:d?`1px solid ${T.disabled}`:0,boxSizing:"border-box"}}),d?jsx("span",{"aria-hidden":"true",style:{position:"absolute",left:5,bottom:3,width:18,height:1,background:"#d93025",transform:"rotate(-18deg)"}}):null,jsx("input",{"data-testid":c,type:"color",value:e,disabled:g,"aria-label":t,onChange:C=>r?.(C.target.value),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0}})]}),i?jsx("button",{type:"button",disabled:g,"aria-label":h??t,title:h??t,onMouseDown:C=>C.preventDefault(),onClick:i,style:{appearance:"none",width:15,height:28,padding:0,border:0,borderRadius:3,background:"transparent",color:g?T.disabled:T.muted,cursor:g?"default":"pointer",opacity:g?.48:1,font:"500 14px ui-sans-serif, system-ui, sans-serif"},children:"\xD7"}):null]})}function rt({value:e,options:t,label:r,onCommit:i,disabled:a=false,width:d=72,inputStyle:h,testId:g}){let[c,y]=useState(e),[S,C]=useState(false),[z,U]=useState({top:0,left:0,width:d}),w=useRef(null),D=useRef(null),q=useRef(null);useEffect(()=>y(e),[e]);let k=useCallback(()=>C(false),[]);useEffect(()=>{if(!S||!w.current)return;let I=w.current.getBoundingClientRect();U({top:I.bottom+4,left:I.left,width:Math.max(I.width,d)});},[S,d]),useEffect(()=>{if(!S)return;let I=X=>{let Ee=X.target;!w.current?.contains(Ee)&&!D.current?.contains(Ee)&&k();},$=X=>{X.key==="Escape"&&(y(e),k());};return document.addEventListener("mousedown",I),document.addEventListener("keydown",$),()=>{document.removeEventListener("mousedown",I),document.removeEventListener("keydown",$);}},[S,k,e]);let J=useCallback(()=>{!a&&i&&c.trim()&&i(c.trim()),y(e);},[a,i,c,e]);return jsxs("div",{ref:w,style:{display:"inline-flex",alignItems:"center",width:d,height:28,border:`1px solid ${T.border}`,borderRadius:4,background:a?"rgba(255,255,255,0.5)":T.surface,opacity:a?.48:1,boxSizing:"border-box",flex:"0 0 auto"},children:[jsx("input",{ref:q,"data-testid":g,role:"combobox","aria-label":r,"aria-autocomplete":"list","aria-expanded":S,disabled:a,value:c,onFocus:I=>{a||(C(true),I.currentTarget.select());},onChange:I=>y(I.target.value),onKeyDown:I=>{I.key==="Enter"?(J(),k(),I.currentTarget.blur()):I.key==="ArrowDown"&&(C(true),I.preventDefault());},onBlur:()=>{requestAnimationFrame(()=>{D.current?.contains(document.activeElement)||J();});},style:{appearance:"none",width:"calc(100% - 22px)",height:26,padding:"0 2px 0 7px",border:0,outline:0,background:"transparent",color:T.text,font:"500 13px ui-sans-serif, system-ui, sans-serif",boxSizing:"border-box",...h}}),jsx("button",{type:"button",disabled:a,tabIndex:-1,"aria-label":r,title:r,onMouseDown:I=>I.preventDefault(),onClick:()=>{a||(C(I=>!I),q.current?.focus());},style:{appearance:"none",display:"grid",placeItems:"center",width:21,height:26,padding:0,border:0,background:"transparent",color:T.muted,cursor:a?"default":"pointer"},children:jsx(B,{name:"chevronDown",size:14})}),S&&!a&&jsx("div",{ref:D,role:"listbox","aria-label":r,style:{position:"fixed",top:z.top,left:z.left,zIndex:1e4,width:z.width,maxHeight:260,overflowY:"auto",padding:4,border:`1px solid ${T.border}`,borderRadius:6,background:T.surface,boxShadow:"0 4px 16px rgba(60, 64, 67, 0.24)",boxSizing:"border-box"},children:t.map(I=>jsx("button",{type:"button",role:"option","aria-selected":I.value===e,onMouseDown:$=>$.preventDefault(),onClick:()=>{y(I.label),i?.(I.value),k();},style:{appearance:"none",display:"block",width:"100%",minHeight:28,padding:"4px 7px",border:0,borderRadius:3,background:I.value===e?T.active:"transparent",color:T.text,cursor:"pointer",font:"400 13px ui-sans-serif, system-ui, sans-serif",textAlign:"left"},children:I.label},I.value))})]})}var $e=[{geometry:"rect",labelKey:"toolbar.shapes.rect"},{geometry:"roundRect",labelKey:"toolbar.shapes.roundRect"},{geometry:"ellipse",labelKey:"toolbar.shapes.ellipse"},{geometry:"triangle",labelKey:"toolbar.shapes.triangle"},{geometry:"rtTriangle",labelKey:"toolbar.shapes.rtTriangle"},{geometry:"diamond",labelKey:"toolbar.shapes.diamond"},{geometry:"parallelogram",labelKey:"toolbar.shapes.parallelogram"},{geometry:"trapezoid",labelKey:"toolbar.shapes.trapezoid"},{geometry:"pentagon",labelKey:"toolbar.shapes.pentagon"},{geometry:"hexagon",labelKey:"toolbar.shapes.hexagon"},{geometry:"octagon",labelKey:"toolbar.shapes.octagon"},{geometry:"star5",labelKey:"toolbar.shapes.star5"},{geometry:"rightArrow",labelKey:"toolbar.shapes.rightArrow"},{geometry:"leftArrow",labelKey:"toolbar.shapes.leftArrow"},{geometry:"upArrow",labelKey:"toolbar.shapes.upArrow"},{geometry:"downArrow",labelKey:"toolbar.shapes.downArrow"},{geometry:"chevron",labelKey:"toolbar.shapes.chevron"}],Zo=[.5,.75,1,1.25,1.5,2],Xo=["Arial","Calibri","Cambria","Georgia","Roboto","Times New Roman","Verdana"],Go=[8,9,10,11,12,14,16,18,20,24,28,36,48,72],Yo=[1,2,3,4,8],jo=[0,10,17,25,33,50],$o=[0,10,20,30,40,50,60,70,80,90,100];function Vo(e){let t={};for(let r of Object.keys(e))e[r]!==void 0&&(t[r]=e[r]);return t}function qo(e){let t=useContext(Ne);return t?{...t,...Vo(e)}:e}function Gt(e,t,r){return r>0?t.find(i=>i>e)??e+1:[...t].reverse().find(i=>i<e)??Math.max(1,e-1)}function Jo(e){if(!e)return null;if(e.adj!==void 0)return ["adj",e.adj];if(e.adj1!==void 0)return ["adj1",e.adj1];let t=Object.keys(e).sort()[0];return t?[t,e[t]]:null}function nt(e){let{t}=He(),{currentFormatting:r={},textSelectionActive:i=false,onFormat:a,currentShapeFormatting:d={},shapeSelectionActive:h=false,onShapeFormat:g,onInsertSlide:c,slideLayouts:y=[],currentLayoutPartPath:S,onUndo:C,onRedo:z,canUndo:U=false,canRedo:w=false,zoom:D="fit",onZoomChange:q,activeTool:k="select",onToolChange:J,fontFamilies:I=Xo,fontSizes:$=Go,disabled:X=false,className:Ee,style:F,children:H}=qo(e),Be=useRef(null),[Ke,v]=useState(Number.POSITIVE_INFINITY),le=!X&&i&&!!a,p=!X&&h&&!!g,N=!X&&!!c,A=!X&&!!J,W=r.fontSize??24,ye=t("toolbar.fit"),_=D==="fit"?ye:`${Math.round(D*100)}%`,Q=Jo(d.adjustments),K=d.geometry==="roundRect"&&Q?.[0]==="adj";useEffect(()=>{let b=Be.current;if(!b)return;let P=()=>v(b.clientWidth);P();let Se=new ResizeObserver(P);return Se.observe(b),()=>Se.disconnect()},[]);let se=useMemo(()=>[{value:ye,label:ye},...Zo.map(b=>({value:`${b*100}%`,label:`${b*100}%`}))],[ye]),Je=useMemo(()=>$.map(b=>({value:String(b),label:String(b)})),[$]),ue=b=>{le&&a?.(b);},he=b=>{p&&g?.(b);},me=[{key:"new-slide",width:59,node:jsxs(be,{label:t("toolbar.groups.slides"),children:[jsx(ce,{title:t("toolbar.newSlide"),disabled:!N,onClick:()=>c?.(),style:{borderRadius:"4px 0 0 4px"},testId:"pptx-new-slide",children:jsx(B,{name:"newSlide"})}),jsx(Ae,{title:t("toolbar.newSlideWithLayout"),disabled:!N||y.length===0,menuWidth:230,testId:"pptx-new-slide-layout",style:{minWidth:20,width:20,padding:0,borderRadius:"0 4px 4px 0"},trigger:jsx(B,{name:"chevronDown",size:13}),children:b=>jsx(Fragment,{children:y.map((P,Se)=>jsx(Oe,{label:P.label??t("toolbar.layoutOption",{number:Se+1}),selected:(P.partPath??null)===(S??null),onClick:()=>c?.(P.partPath),close:b},P.partPath??`default-${Se}`))})})]})},{key:"history",width:75,node:jsxs(Fragment,{children:[jsx(De,{}),jsxs(be,{label:t("toolbar.groups.history"),children:[jsx(ce,{title:t("toolbar.undoShortcut"),disabled:X||!U||!C,onClick:C,testId:"pptx-undo",children:jsx(B,{name:"undo"})}),jsx(ce,{title:t("toolbar.redoShortcut"),disabled:X||!w||!z,onClick:z,testId:"pptx-redo",children:jsx(B,{name:"redo"})})]})]})},{key:"zoom",width:82,node:jsx(be,{label:t("toolbar.groups.zoom"),children:jsx(rt,{value:_,options:se,label:t("toolbar.zoomValue",{value:_}),disabled:X||!q,onCommit:b=>{if(b===ye){q?.("fit");return}let P=Number.parseFloat(b.replace("%",""));Number.isFinite(P)&&P>=25&&P<=400&&q?.(P/100);},width:76,testId:"pptx-zoom"})})},{key:"tools",width:127,node:jsxs(Fragment,{children:[jsx(De,{}),jsxs(be,{label:t("toolbar.groups.tools"),children:[jsx(ce,{title:t("toolbar.selectToolShortcut"),active:k==="select",disabled:!A,onClick:()=>J?.("select"),testId:"pptx-tool-select",children:jsx(B,{name:"select"})}),jsx(ce,{title:t("toolbar.textBoxTool"),active:k==="textBox",disabled:!A,onClick:()=>J?.("textBox"),testId:"pptx-tool-text-box",children:jsx(B,{name:"textBox"})}),jsx(Ae,{title:t("toolbar.shapeTool"),active:k.startsWith("shape:"),disabled:!A,menuWidth:264,testId:"pptx-tool-shape",style:{minWidth:46,padding:"0 4px"},trigger:jsxs(Fragment,{children:[jsx(B,{name:"shape"}),jsx(B,{name:"chevronDown",size:11})]}),children:b=>jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(5, 44px)",gap:4,padding:2},children:$e.map(P=>jsx("button",{type:"button",role:"menuitem","data-testid":`pptx-shape-${P.geometry}`,"aria-label":t(P.labelKey),title:t(P.labelKey),onClick:()=>{J?.(`shape:${P.geometry}`),b();},style:{appearance:"none",display:"grid",placeItems:"center",width:44,height:38,padding:5,border:`1px solid ${T.border}`,borderRadius:4,background:k===`shape:${P.geometry}`?T.active:T.surface,color:T.text,cursor:"pointer"},children:jsx(Qo,{geometry:P.geometry})},P.geometry))})})]})]})},{key:"font-family",width:137,node:jsxs(Fragment,{children:[jsx(De,{}),jsx(be,{label:t("toolbar.groups.font"),children:jsx(Ae,{title:t("toolbar.fontFamily"),disabled:!le,menuWidth:210,testId:"pptx-font-family",style:{width:120,justifyContent:"space-between"},trigger:jsxs(Fragment,{children:[jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:r.fontFamily??t("toolbar.mixed")}),jsx(B,{name:"chevronDown",size:13})]}),children:b=>jsx(Fragment,{children:I.map(P=>jsx(Oe,{label:P,selected:r.fontFamily===P,onClick:()=>ue({type:"fontFamily",value:P}),close:b},P))})})})]})},{key:"font-size",width:116,node:jsxs(be,{label:t("toolbar.groups.font"),children:[jsx(ce,{title:t("toolbar.decreaseFontSize"),disabled:!le,onClick:()=>ue({type:"fontSize",value:Gt(W,$,-1)}),children:jsx(B,{name:"remove"})}),jsx(rt,{value:r.fontSize===void 0?"":String(W),options:Je,label:t("toolbar.fontSize"),disabled:!le,onCommit:b=>{let P=Number.parseFloat(b);Number.isFinite(P)&&P>=1&&P<=400&&ue({type:"fontSize",value:P});},width:50,inputStyle:{textAlign:"center"},testId:"pptx-font-size"}),jsx(ce,{title:t("toolbar.increaseFontSize"),disabled:!le,onClick:()=>ue({type:"fontSize",value:Gt(W,$,1)}),children:jsx(B,{name:"add"})})]})},{key:"text",width:133,node:jsxs(Fragment,{children:[jsx(De,{}),jsxs(be,{label:t("toolbar.groups.text"),children:[jsx(ce,{title:t("toolbar.boldShortcut"),active:r.bold,disabled:!le,onClick:()=>ue("bold"),testId:"pptx-bold",children:jsx(B,{name:"bold"})}),jsx(ce,{title:t("toolbar.italicShortcut"),active:r.italic,disabled:!le,onClick:()=>ue("italic"),testId:"pptx-italic",children:jsx(B,{name:"italic"})}),jsx(ce,{title:t("toolbar.underlineShortcut"),active:r.underline,disabled:!le,onClick:()=>ue("underline"),testId:"pptx-underline",children:jsx(B,{name:"underline"})}),jsx(ot,{value:r.textColor??"#000000",label:t("toolbar.textColor"),disabled:!le,onChange:b=>ue({type:"textColor",value:b}),testId:"pptx-text-color"})]})]})},{key:"shape-formatting",width:Q?244:172,node:jsxs(Fragment,{children:[jsx(De,{}),jsxs(be,{label:t("toolbar.groups.shape"),children:[jsx(ot,{value:d.fillColor??"#d9eaf7",label:t("toolbar.fillColor"),clearLabel:t("toolbar.noFill"),icon:"fillColor",none:!d.fillColor,disabled:!p,onChange:b=>he({type:"fillColor",value:b}),onClear:()=>he({type:"fillColor",value:null}),testId:"pptx-shape-fill"}),jsx(ot,{value:d.strokeColor??"#202124",label:t("toolbar.borderColor"),clearLabel:t("toolbar.noBorder"),icon:"borderColor",none:!d.strokeColor,disabled:!p,onChange:b=>he({type:"strokeColor",value:b}),onClear:()=>he({type:"strokeColor",value:null}),testId:"pptx-shape-border-color"}),jsx(Ae,{title:t("toolbar.borderWidth"),disabled:!p,menuWidth:170,testId:"pptx-shape-border-width",trigger:jsx(B,{name:"borderWidth"}),children:b=>jsxs(Fragment,{children:[jsx(Oe,{label:t("toolbar.noBorder"),selected:d.strokeWidthPt===null,onClick:()=>he({type:"strokeWidth",value:null}),close:b}),Yo.map(P=>jsx(Oe,{label:t("toolbar.borderWidthValue",{width:P}),selected:d.strokeWidthPt===P,icon:jsx("span",{"aria-hidden":"true",style:{width:18,borderTop:`${Math.min(P,5)}px solid currentColor`}}),onClick:()=>he({type:"strokeWidth",value:P}),close:b},P))]})}),Q?jsx(rt,{value:`${Math.round(Q[1]*100)}%`,options:(K?jo:$o).map(b=>({value:String(b),label:`${b}%`})),label:t(K?"toolbar.cornerRadius":"toolbar.shapeAdjustment"),disabled:!p,onCommit:b=>{let P=Number.parseFloat(b.replace("%",""));if(Number.isFinite(P)){let Se=K?50:100;he({type:"adjust",name:Q[0],value:Math.max(0,Math.min(Se,P))/100});}},width:68,inputStyle:{textAlign:"center"},testId:K?"pptx-shape-corner-radius":"pptx-shape-adjustment"}):null]})]})}];H&&me.push({key:"custom",width:40,node:H});let st=Math.max(0,Ke-48),Me=0,pe=me.length;for(let b=0;b<me.length;b++)if(Me+=me[b].width,Me>st){pe=b;break}let ke=me.slice(0,pe),Qe=me.slice(pe);return jsxs("div",{ref:Be,className:Ee,role:"toolbar","aria-label":t("toolbar.label"),"data-testid":"pptx-formatting-toolbar",style:{display:"flex",alignItems:"center",minWidth:0,minHeight:36,margin:"0 8px 5px",padding:"4px 7px",borderRadius:18,background:T.rail,color:T.text,overflow:"hidden",boxSizing:"border-box",...F},children:[ke.map(b=>jsx("span",{style:{display:"contents"},children:b.node},b.key)),jsx("span",{style:{marginLeft:"auto",flex:"0 0 auto"},children:jsx(Ae,{title:t("toolbar.more"),disabled:Qe.length===0,menuWidth:390,testId:"pptx-toolbar-more",trigger:jsx(B,{name:"more"}),children:()=>jsx("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:2},children:Qe.map(b=>jsx("span",{style:{display:"contents"},children:b.node},b.key))})})})]})}function Qo({geometry:e}){let t={rect:"M3 5h18v14H3Z",roundRect:"M7 5h10a4 4 0 0 1 4 4v6a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4V9a4 4 0 0 1 4-4Z",ellipse:"M3 12a9 7 0 1 0 18 0 9 7 0 1 0-18 0",triangle:"m12 4 9 16H3Z",rtTriangle:"M4 4v16h16Z",diamond:"m12 3 9 9-9 9-9-9Z",parallelogram:"M7 5h14l-4 14H3Z",trapezoid:"M7 5h10l4 14H3Z",pentagon:"m12 3 9 7-4 11H7L3 10Z",hexagon:"m7 4 10 0 5 8-5 8H7l-5-8Z",octagon:"m7 3 10 0 4 4v10l-4 4H7l-4-4V7Z",star5:"m12 2.5 2.8 6 6.5.6-5 4.3 1.6 6.4-5.7-3.4-5.7 3.4 1.6-6.4-5-4.3 6.5-.6Z",rightArrow:"M3 8h11V4l7 8-7 8v-4H3Z",leftArrow:"m21 8H10V4l-7 8 7 8v-4h11Z",upArrow:"M8 21V10H4l8-7 8 7h-4v11Z",downArrow:"M8 3v11H4l8 7 8-7h-4V3Z",chevron:"M4 4h9l7 8-7 8H4l7-8Z"}[e];return jsx("svg",{width:"30",height:"24",viewBox:"0 0 24 24",fill:"rgba(60, 64, 67, 0.08)",stroke:"currentColor",strokeWidth:"1.4",strokeLinejoin:"round","aria-hidden":"true",children:jsx("path",{d:t})})}function er({children:e,className:t,style:r,...i}){return jsx(Ne.Provider,{value:i,children:jsx("div",{className:t,"data-testid":"pptx-editor-toolbar",style:{display:"flex",flexDirection:"column",flex:"0 0 auto",...r},children:e})})}var Ve=er;Ve.Toolbar=nt;function gt(e,t,r,i){if(!Number.isFinite(e.width)||!Number.isFinite(e.height)||e.width<=0||e.height<=0)return null;let a=(r-e.left)*t.width/e.width,d=(i-e.top)*t.height/e.height;return Number.isFinite(a)&&Number.isFinite(d)?{x:a,y:d}:null}function Ce(e,t){for(let r of e){if(r.id===t)return r;let i=Ce(r.children,t);if(i)return i}return null}function $t(e){let t=new Map,r=[...e];for(;r.length>0;){let i=r.pop();t.set(i.id,i),r.push(...i.children);}return t}function yt(e,t){for(let r of e.shapes)if(r.id===t||Ce(r.children,t))return r;return null}function St(e){return e.width>0&&e.height>0}function Pt(e,t,r){let i=new Set;Jt(r,i);let a=t.primitives.filter(S=>S.shapeId&&i.has(S.shapeId));if(a.length===0)return r.width<=0||r.height<=0||e.widthEmu<=0||e.heightEmu<=0?null:{x:r.x*t.width/e.widthEmu,y:r.y*t.height/e.heightEmu,width:r.width*t.width/e.widthEmu,height:r.height*t.height/e.heightEmu};let d=a.map(S=>{let C=(S.transform?.rotationDeg??0)*Math.PI/180,z=Math.abs(S.w*Math.cos(C))+Math.abs(S.h*Math.sin(C)),U=Math.abs(S.w*Math.sin(C))+Math.abs(S.h*Math.cos(C));return {x:S.x+(S.w-z)/2,y:S.y+(S.h-U)/2,width:z,height:U}}),h=Math.min(...d.map(S=>S.x)),g=Math.min(...d.map(S=>S.y)),c=Math.max(...d.map(S=>S.x+S.width)),y=Math.max(...d.map(S=>S.y+S.height));return {x:h,y:g,width:c-h,height:y-g}}function Vt(e,t,r,i){let a=e.primitives.find(c=>c.kind==="textBox"&&c.shapeId===t&&c.storyId===r);if(!a||a.lines.length===0)return null;let d=a.lines.reduce((c,y)=>jt(y.y,y.height,i.y)<jt(c.y,c.height,i.y)?y:c),h=d.caretStops[0];return h?d.caretStops.reduce((c,y)=>Math.abs(y.x-i.x)<Math.abs(c.x-i.x)?y:c,h).position:d.start}function qt(e,t,r,i){return {x:r.x+Math.round(i.x*e.widthEmu/t.width),y:r.y+Math.round(i.y*e.heightEmu/t.height)}}function vt(e,t,r,i,a=4){return Math.hypot(r-e,i-t)>=a}function Jt(e,t){t.add(e.id);for(let r of e.children)Jt(r,t);}function jt(e,t,r){return r<e?e-r:r>e+t?r-e-t:0}function Qt(e,t=12){return {visible:e.slice(0,t),overflow:Math.max(0,e.length-t)}}function eo(e,t,r=4){let i=new Map;for(let a of e){let d=a.state.cursor?.slideId;if(!d||!t.has(d))continue;let h=i.get(d)??{visible:[],overflow:0};h.visible.length<r?h.visible.push(a):h.overflow+=1,i.set(d,h);}return i}function to(e,t,r,i=24){let a=new Map,d=0;for(let h of e){let g=h.state.cursor;if(g?.slideId!==t||!g.shapeId||!r.has(g.shapeId))continue;let c=a.get(g.shapeId);c?(c.count+=1,h.cursorMovedAt>c.peer.cursorMovedAt&&(c.peer=h)):a.size<i?a.set(g.shapeId,{shapeId:g.shapeId,peer:h,count:1}):d+=1;}return {visible:[...a.values()],overflow:d}}function it(e,t,r,i){let a=tr(e,t,r,i),d=We(a,"underline");return {bold:We(a,"bold"),italic:We(a,"italic"),underline:d===void 0?void 0:d!=="none",fontSize:We(a,"fontSizePt"),textColor:We(a,"color"),fontFamily:We(a,"fontFamily")}}function oo(e,t){return it(e,0,e.length,t)}function ro(e,t,r,i){let a=it(e,t,r,i);return {bold:a.bold??i.bold,italic:a.italic??i.italic,underline:a.underline===void 0?i.underline:a.underline?"sng":"none",fontSizePt:a.fontSize??i.fontSizePt,color:a.textColor??i.color,fontFamily:a.fontFamily??i.fontFamily}}function tr(e,t,r,i){let a=or(e,i);if(a.length===0)return [i];let d=Math.min(t,r),h=Math.max(t,r);if(d===h){let y=a.find(C=>d>=C.start&&d<C.end);return y?[y.style]:[[...a].reverse().find(C=>C.end<=d)?.style??a[0].style]}let g=a.filter(y=>y.end>d&&y.start<h).map(y=>y.style);return g.length>0?g:[[...a].reverse().find(y=>y.end<=d)?.style??a[0].style]}function or(e,t){let r=[],i=0;return e.paragraphs.forEach((a,d)=>{for(let h of a.runs){let g=i;i+=h.text.length,i>g&&r.push({start:g,end:i,style:rr(h.style,t)});}d<e.paragraphs.length-1&&(i+=1);}),r}function rr(e,t){return {bold:e.bold??t.bold,italic:e.italic??t.italic,underline:e.underline??t.underline,fontSizePt:e.fontSizePt??t.fontSizePt,color:e.color??t.color,fontFamily:e.fontFamily??t.fontFamily}}function We(e,t){let r=e[0]?.[t];return e.every(i=>i[t]===r)?r:void 0}function io(e){let t=e?.fill?.type==="none"?null:no(e?.resolvedFillColor),r=no(e?.resolvedOutlineColor);return {geometry:e?.geometry,fillColor:t,strokeColor:r,strokeWidthPt:r&&e?.outline?.width!==void 0?e.outline.width/12700:r?1:null,adjustments:e?.adjustValues??{}}}function no(e){if(!e)return null;let t=e.replace(/^#/,"");return /^[0-9a-f]{6}$/i.test(t)?`#${t}`:null}var nr=new Intl.Segmenter(void 0,{granularity:"word"});function It(e,t,r){return r==="word"?ir(e,t):ar(e,t)}function ir(e,t){let r=lo(e,t),i=[...nr.segment(e)],a=i.find(d=>r>=d.index&&r<d.index+d.segment.length)??i[i.length-1];return a?{start:a.index,end:a.index+a.segment.length}:{start:r,end:r}}function ar(e,t){let r=lo(e,t),i=e.lastIndexOf(`
2
- `,Math.max(0,r-1))+1,a=e.indexOf(`
3
- `,r);return {start:i,end:a===-1?e.length:a}}function ao(e,t){return t.start<e.start?{anchor:e.end,focus:t.start}:t.end>e.end?{anchor:e.start,focus:t.end}:{anchor:e.start,focus:e.end}}function lo(e,t){return Number.isFinite(t)?Math.max(0,Math.min(e.length,Math.trunc(t))):0}var at={bold:false,italic:false,underline:"none",fontSizePt:24,color:"#111827",fontFamily:"Arial"};function dr({i18n:e,...t}){return jsx(tt,{i18n:e,children:jsx(cr,{...t})})}function cr({file:e,fonts:t,clientId:r,collaboration:i,className:a,onReady:d,onChange:h,onError:g}){let{t:c}=He(),y=c("errors.decodeSlideImage"),S=i?.clientId??r,C=i?.initialUpdate,z=i?.onReplica,U=i?.presence,w=useRef(null),D=useRef(null),q=useRef(d),k=useRef(h),J=useRef(g),I=useRef(null),$=useRef(null),X=useRef(null),Ee=useRef(null),F=useRef(null),H=useRef(null),Be=useRef(new Map),Ke=mr(t),[v,le]=useState(null),[p,N]=useState(null),[A,W]=useState(null),[ye,_]=useState(null),[Q,K]=useState(null),[se,Je]=useState(at),[ue,he]=useState({canUndo:false,canRedo:false}),[me,st]=useState("fit"),[Me,pe]=useState("select"),[ke,Qe]=useState({width:0,height:0}),[b,P]=useState(null),[Se,et]=useState(false),[dt,Et]=useState(null),[Re,ct]=useState([]);q.current=d,k.current=h,J.current=g,D.current=v;let Z=useCallback(o=>{let n=o instanceof Error?o:new Error(String(o));P(n.message),J.current?.(n);},[]),re=useCallback((o,n=false,u=false)=>{let l=w.current;if(!l)return null;try{let s=l.snapshot(),m=fr(o??D.current?.slideIndex??0,s.slides.length),x=new Map;for(let R=0;R<s.slides.length;R+=1){let ee=s.slides[R],de=D.current?.thumbnails.get(ee.id);R!==m&&de&&!u?x.set(ee.id,de):R!==m&&x.set(ee.id,l.layoutSlide(R));}let L=s.slides.length>0?l.layoutSlide(m):null;L&&x.set(s.slides[m].id,L);let Y={snapshot:s,slideIndex:m,frame:L,thumbnails:x},V=s.slides[m];N(R=>R&&V&&Ce(V.shapes,R.shapeId)?R:null),W(R=>R&&V?.id===R.slideId&&Ce(V.shapes,R.shapeId)?R:null);let j=F.current;return j&&(!V||V.id!==j.slideId||j.kind!=="textBox"&&j.kind!=="shapeInsert"&&!Ce(V.shapes,j.shapeId))&&(F.current=null,H.current=null,_(null),K(null)),D.current=Y,le(Y),he({canUndo:l.canUndo(),canRedo:l.canRedo()}),P(null),n&&k.current?.(s),Y}catch(s){return Z(s),null}},[Z]),Mt=useCallback(()=>{re(void 0,false,true);},[re]);useEffect(()=>{let o=false,n=null,u=[],l=()=>{};if(w.current?.dispose(),w.current=null,Et(null),D.current=null,le(null),N(null),W(null),_(null),K(null),he({canUndo:false,canRedo:false}),pe("select"),F.current=null,H.current=null,P(null),Be.current.clear(),!!e)return et(true),Promise.all([initWasm(),vr(Ke)]).then(([,s])=>{if(u=s,o){co(u);return}try{n=openPresentation(e,{clientId:S,fonts:Ke,initialUpdate:C}),w.current=n,l=n.onUpdate((m,x)=>{x==="remote"&&re(void 0,!0,!0);}),re(0),et(!1),Et(n),q.current?.({handle:n,refresh:Mt});}catch(m){et(false),Z(m);}},s=>{o||(et(false),Z(s));}),()=>{o=true,l(),n?.dispose(),w.current===n&&(w.current=null),co(u);}},[S,C,e,Ke,Mt,re,Z]),useEffect(()=>{if(!(!z||!dt))return z(dt),()=>z(null)},[z,dt]),useEffect(()=>{if(!U){ct([]);return}return ct(U.peers),U.onPresence(ct)},[U]),useEffect(()=>{let o=$.current;if(!o)return;let n=()=>Qe({width:o.clientWidth,height:o.clientHeight});n();let u=new ResizeObserver(n);return u.observe(o),()=>u.disconnect()},[]);let ho=useMemo(()=>!v?.frame||ke.width<=0||ke.height<=0?1:Math.min((ke.width-40)/v.frame.width,(ke.height-40)/v.frame.height,1),[v?.frame,ke]),G=me==="fit"?ho:me;useEffect(()=>{let o=X.current,n=v?.frame;if(!o||!n)return;let u=o.getContext("2d");if(!u)return;let l=window.devicePixelRatio||1;sizeCanvasForSlide(o,n,l,G);let s=false;return paintSlide(u,n,l,G,{resolveImage:m=>uo(m,w,Be,y)}).catch(m=>{s||Z(m);}),()=>{s=true;}},[y,v?.frame,Z,G]),useEffect(()=>{let o=Ee.current,n=v?.frame;if(!o||!n)return;let u=o.getContext("2d");if(!u)return;let l=window.devicePixelRatio||1;sizeCanvasForSlide(o,n,l,G),Tr(u,n,p,l,G);},[v?.frame,G,p]);let ae=useMemo(()=>{if(!v?.frame||!A)return null;let o=v.snapshot.slides[v.slideIndex];return !o||o.id!==A.slideId?null:Ce(o.shapes,A.shapeId)},[v,A]),Fe=ae?.textStories[0]?.id??null,mo=useMemo(()=>io(ae),[ae]),Ue=useMemo(()=>v?.frame&&ae?Pt(v.snapshot,v.frame,ae):null,[v,ae]),Pe=v?.snapshot.slides[v.slideIndex],_e=Pe?.id,ut=useMemo(()=>{if(Pe){if(A?.slideId===Pe.id)return A.shapeId;if(p)return yt(Pe,p.shapeId)?.id}},[Pe,p,A]);useEffect(()=>{U&&U.setCursor(_e?{slideId:_e,...ut?{shapeId:ut}:{}}:null);},[U,_e,ut]),useEffect(()=>()=>{U?.setCursor(null);},[U]);let Ze=useMemo(()=>Qt(Re),[Re]),pt=useMemo(()=>{if(!v?.frame||!Pe)return {visible:[],overflow:0};let o=$t(Pe.shapes),n=to(Re,Pe.id,o),u=[],l=n.overflow;for(let s of n.visible){let m=o.get(s.shapeId);if(!m)continue;let x=Pt(v.snapshot,v.frame,m);x?u.push({peer:s.peer,peerCount:s.count,shapeId:s.shapeId,bounds:x}):l+=s.count;}return {visible:u,overflow:l}},[Pe,v,Re]),bo=useMemo(()=>{let o=new Set(v?.snapshot.slides.map(n=>n.id));return eo(Re,o)},[v,Re]);useEffect(()=>{let o=w.current;if(!(!o||!p))try{let n=o.story(p.storyId);Je(ro(n,p.anchor,p.focus,at));}catch(n){Z(n);}},[v,Z,p]);let Le=useMemo(()=>{if(p&&p.anchor===p.focus)return lt(se);let o=w.current;if(!o)return lt(se);try{return p?it(o.story(p.storyId),p.anchor,p.focus,at):Fe?oo(o.story(Fe),at):lt(se)}catch{return lt(se)}},[v,Fe,p,se]),xo=useMemo(()=>{let o=new Set;for(let n of v?.snapshot.slides??[])o.add(n.layoutPartPath);return [...o].map(n=>({partPath:n}))},[v?.snapshot]),go=o=>{N(null),W(null),_(null),K(null),F.current=null,H.current=null,re(o),I.current?.focus();},yo=(o,n)=>{let u=w.current,l=D.current;if(!u||!l?.frame)return;let s=l.snapshot.slides[l.slideIndex];if(!s)return;let m=Math.abs(n.x-o.x)>=6||Math.abs(n.y-o.y)>=6,x=m?Math.abs(n.x-o.x):l.frame.width*.36,L=m?Math.abs(n.y-o.y):l.frame.height*.12,Y=Math.max(0,Math.min(m?Math.min(o.x,n.x):o.x,l.frame.width-x)),V=Math.max(0,Math.min(m?Math.min(o.y,n.y):o.y,l.frame.height-L));try{let j=u.addTextBox(s.id,{name:c("objects.defaultTextBoxName"),rect:{x:Math.round(Y*l.snapshot.widthEmu/l.frame.width),y:Math.round(V*l.snapshot.heightEmu/l.frame.height),width:Math.round(Math.max(12,x)*l.snapshot.widthEmu/l.frame.width),height:Math.round(Math.max(12,L)*l.snapshot.heightEmu/l.frame.height)},text:"",style:se}),R=re(void 0,!0);pe("select"),W(null),_(null),K(null),F.current=null,H.current=null;let ee=R?.snapshot.slides[R.slideIndex]?.shapes.find(ko=>ko.id===j.shapeId),de=ee?.textStories[0];de&&(N({shapeId:ee.id,storyId:de.id,anchor:0,focus:0}),I.current?.focus());}catch(j){Z(j);}},So=(o,n,u)=>{let l=w.current,s=D.current;if(!l||!s?.frame)return;let m=s.snapshot.slides[s.slideIndex],x=$e.find(ee=>ee.geometry===o);if(!m||!x)return;let L=Math.abs(u.x-n.x)>=6||Math.abs(u.y-n.y)>=6,Y=L?Math.abs(u.x-n.x):s.frame.width*.22,V=L?Math.abs(u.y-n.y):s.frame.height*.18,j=Math.max(0,Math.min(L?Math.min(n.x,u.x):n.x-Y/2,s.frame.width-Y)),R=Math.max(0,Math.min(L?Math.min(n.y,u.y):n.y-V/2,s.frame.height-V));try{let ee=l.addShape(m.id,{name:c(x.labelKey),geometry:o,rect:{x:Math.round(j*s.snapshot.widthEmu/s.frame.width),y:Math.round(R*s.snapshot.heightEmu/s.frame.height),width:Math.round(Math.max(12,Y)*s.snapshot.widthEmu/s.frame.width),height:Math.round(Math.max(12,V)*s.snapshot.heightEmu/s.frame.height)},fill:"#d9eaf7"}),de=re(void 0,!0);pe("select"),N(null),W({slideId:m.id,shapeId:ee.shapeId}),_(null),K(null),F.current=null,H.current=null,de&&I.current?.focus();}catch(ee){Z(ee);}},Po=o=>{if(!o.isPrimary||o.button!==0)return;let n=w.current,u=D.current;if(!n||!u?.frame)return;let l=gt(o.currentTarget.getBoundingClientRect(),u.frame,o.clientX,o.clientY);if(!l)return;let s=u.snapshot.slides[u.slideIndex],m=hr(Me);if((Me==="textBox"||m)&&s){N(null),W(null),_(null),K({start:l,end:l}),H.current=null,F.current=m?{kind:"shapeInsert",pointerId:o.pointerId,slideId:s.id,geometry:m,start:l,last:l}:{kind:"textBox",pointerId:o.pointerId,slideId:s.id,start:l,last:l},o.currentTarget.setPointerCapture(o.pointerId),I.current?.focus(),o.preventDefault();return}try{n.layoutSlide(u.slideIndex);let x=n.hitTest(l.x,l.y),L=s&&x?yt(s,x.shapeId):null,Y=H.current,V=!!(s&&L&&Y?.slideId===s.id&&Y.shapeId===L.id&&o.timeStamp-Y.timeStamp<=600&&Math.hypot(o.clientX-Y.clientX,o.clientY-Y.clientY)<=6),j=V&&Y?Math.min(Y.count+1,3):1;if(H.current=null,s&&x?.kind==="text"&&L&&j>=2){let R=n.story(x.storyId),ee=j>=3?"paragraph":"word",de=It(qe(R),x.position,ee);N({shapeId:x.shapeId,storyId:x.storyId,anchor:de.start,focus:de.end}),W(null),_(null),F.current={kind:"text",pointerId:o.pointerId,slideId:s.id,shapeId:x.shapeId,storyId:x.storyId,anchor:de.start,focus:de.end,granularity:ee,clickCount:j,clickShapeId:L.id,startClientX:o.clientX,startClientY:o.clientY,dragging:!1},o.currentTarget.setPointerCapture(o.pointerId);}else if(s&&p&&x?.kind==="text"&&x.shapeId===p.shapeId&&x.storyId===p.storyId){n.story(x.storyId);let R=o.shiftKey?p.anchor:x.position;N({shapeId:x.shapeId,storyId:x.storyId,anchor:R,focus:x.position}),W(null),_(null),F.current={kind:"text",pointerId:o.pointerId,slideId:s.id,shapeId:x.shapeId,storyId:x.storyId,anchor:R,focus:x.position,granularity:"character",clickCount:j,clickShapeId:L?.id??x.shapeId,startClientX:o.clientX,startClientY:o.clientY,dragging:!1},o.currentTarget.setPointerCapture(o.pointerId);}else s&&x?L?(N(null),W({slideId:s.id,shapeId:L.id}),_(null),St(L)?(F.current={kind:"shape",pointerId:o.pointerId,slideId:s.id,shapeId:L.id,startClientX:o.clientX,startClientY:o.clientY,start:l,last:l,dragThreshold:V?8:4,clickCount:j,dragging:!1},o.currentTarget.setPointerCapture(o.pointerId)):F.current=null):(N(null),W(null),H.current=null,F.current=null):(N(null),W(null),_(null),H.current=null,F.current=null);I.current?.focus(),o.preventDefault();}catch(x){Z(x);}},kt=o=>{let n=F.current,u=w.current,l=D.current;if(!n||n.pointerId!==o.pointerId||!u||!l?.frame)return false;let s=gt(o.currentTarget.getBoundingClientRect(),l.frame,o.clientX,o.clientY);if(!s||l.snapshot.slides[l.slideIndex]?.id!==n.slideId)return false;if(n.kind==="text"){!n.dragging&&vt(n.startClientX,n.startClientY,o.clientX,o.clientY)&&(n.dragging=true);let m=Vt(l.frame,n.shapeId,n.storyId,s);if(m!==null){let x=n.granularity==="character"?{anchor:n.anchor,focus:m}:ao({start:n.anchor,end:n.focus},It(qe(u.story(n.storyId)),m,n.granularity));N({shapeId:n.shapeId,storyId:n.storyId,...x});}}else n.kind==="shape"?(n.last=s,!n.dragging&&vt(n.startClientX,n.startClientY,o.clientX,o.clientY,n.dragThreshold)&&(n.dragging=true),n.dragging&&_({shapeId:n.shapeId,delta:{x:s.x-n.start.x,y:s.y-n.start.y}})):(n.last=s,K({start:n.start,end:s}));return true},vo=o=>{kt(o)&&o.preventDefault();},Io=o=>{kt(o);let n=F.current;if(!n||n.pointerId!==o.pointerId)return;if(F.current=null,_(null),o.currentTarget.hasPointerCapture(o.pointerId)&&o.currentTarget.releasePointerCapture(o.pointerId),n.kind==="textBox"){K(null),yo(n.start,n.last),o.preventDefault();return}if(n.kind==="shapeInsert"){K(null),So(n.geometry,n.start,n.last),o.preventDefault();return}if(n.kind==="text"){H.current=n.dragging?null:{slideId:n.slideId,shapeId:n.clickShapeId,clientX:o.clientX,clientY:o.clientY,timeStamp:o.timeStamp,count:n.clickCount};return}if(n.kind!=="shape")return;if(!n.dragging){H.current={slideId:n.slideId,shapeId:n.shapeId,clientX:o.clientX,clientY:o.clientY,timeStamp:o.timeStamp,count:n.clickCount};return}H.current=null;let u=w.current,l=D.current,s=l?.snapshot.slides[l.slideIndex];if(!u||!l?.frame||s?.id!==n.slideId)return;let m=Ce(s.shapes,n.shapeId);if(m)try{let x=qt(l.snapshot,l.frame,m,{x:n.last.x-n.start.x,y:n.last.y-n.start.y});(x.x!==m.x||x.y!==m.y)&&(u.moveShape(s.id,m.id,x.x,x.y),re(void 0,!0)),W({slideId:s.id,shapeId:m.id}),o.preventDefault();}catch(x){Z(x);}},Rt=o=>{F.current?.pointerId===o.pointerId&&(F.current=null,_(null),K(null),H.current=null);},ze=o=>{N(o),W(null),H.current=null,re(void 0,true);},To=o=>{let n=w.current;if(!n)return;let u=o.metaKey||o.ctrlKey;if(o.key==="Escape"){pe("select"),K(null),F.current=null,o.preventDefault();return}if(u&&(o.key==="z"||o.key==="Z")){o.preventDefault(),ft(o.shiftKey?"redo":"undo");return}if(!p&&!Fe)return;if(u&&(o.key==="b"||o.key==="B")){o.preventDefault(),ve({bold:p?!se.bold:!Le.bold});return}if(u&&(o.key==="i"||o.key==="I")){o.preventDefault(),ve({italic:p?!se.italic:!Le.italic});return}if(u&&(o.key==="u"||o.key==="U")){o.preventDefault(),ve({underline:p?se.underline==="none"?"sng":"none":Le.underline?"none":"sng"});return}if(!p)return;let l=Math.min(p.anchor,p.focus),s=Math.max(p.anchor,p.focus);try{if(o.key==="ArrowLeft"||o.key==="ArrowRight"){o.preventDefault();let m=n.story(p.storyId),x=o.key==="ArrowLeft"?-1:1,L=Math.max(0,Math.min(m.length,p.focus+x));N({...p,anchor:o.shiftKey?p.anchor:L,focus:L});return}if(o.key==="Backspace"){if(o.preventDefault(),l!==s){n.deleteText(p.storyId,l,s),ze({...p,anchor:l,focus:l});return}let m=Sr(n.story(p.storyId),l);m<l&&(n.deleteText(p.storyId,m,l),ze({...p,anchor:m,focus:m}));return}if(o.key==="Delete"){if(o.preventDefault(),l!==s){n.deleteText(p.storyId,l,s),ze({...p,anchor:l,focus:l});return}let m=Pr(n.story(p.storyId),s);m>s&&(n.deleteText(p.storyId,s,m),ze({...p,anchor:s,focus:s}));return}if(o.key==="Enter"){o.preventDefault(),l!==s&&n.deleteText(p.storyId,l,s),n.insertParagraphBreak(p.storyId,l),ze({...p,anchor:l+1,focus:l+1});return}if(o.key.length>0&&!o.metaKey&&!o.ctrlKey&&!o.altKey&&Array.from(o.key).length===1){o.preventDefault(),l!==s&&n.deleteText(p.storyId,l,s),n.insertText(p.storyId,l,o.key,se);let m=l+o.key.length;ze({...p,anchor:m,focus:m});}}catch(m){Z(m);}},ve=o=>{Je(u=>({...u,...o}));let n=w.current;if(n)try{if(p){if(p.anchor===p.focus)return;n.formatText(p.storyId,Math.min(p.anchor,p.focus),Math.max(p.anchor,p.focus),o);}else if(Fe){let u=n.story(Fe);yr(n,u,o);}else return;re(void 0,!0);}catch(u){Z(u);}},wo=o=>{o==="bold"?ve({bold:!Le.bold}):o==="italic"?ve({italic:!Le.italic}):o==="underline"?ve({underline:Le.underline?"none":"sng"}):o.type==="fontFamily"?ve({fontFamily:o.value}):o.type==="fontSize"?ve({fontSizePt:o.value}):o.type==="textColor"&&ve({color:o.value});},Co=o=>{let n=w.current;if(!(!n||!A||!ae))try{o.type==="fillColor"?n.setShapeFill(A.slideId,A.shapeId,o.value):o.type==="strokeColor"?n.setShapeStroke(A.slideId,A.shapeId,o.value?{color:o.value}:{}):o.type==="strokeWidth"?n.setShapeStroke(A.slideId,A.shapeId,o.value===null?{}:{widthPt:o.value}):n.setShapeAdjust(A.slideId,A.shapeId,{...ae.adjustValues,[o.name]:o.value}),re(void 0,!0);}catch(u){Z(u);}},Eo=o=>{let n=w.current,u=D.current;if(!(!n||!u))try{let l=u.slideIndex+1,s=o===void 0?u.snapshot.slides[u.slideIndex]?.layoutPartPath??void 0:o??void 0;n.insertSlide(l,s),N(null),W(null),_(null),K(null),pe("select"),F.current=null,H.current=null,re(l,!0,!0);}catch(l){Z(l);}},ft=o=>{let n=w.current;if(n)try{o==="undo"?n.undo():n.redo(),N(null),_(null),K(null),pe("select"),F.current=null,H.current=null,re(void 0,!0);}catch(u){Z(u);}},ht=v?.snapshot.slides.length??0,Xe=v?.slideIndex??0,Ft=ye&&ye.shapeId===A?.shapeId?ye.delta:null,Mo=ae?St(ae):false;return jsxs("div",{className:a,style:M.root,children:[jsxs("div",{style:M.toolbarShell,children:[jsx(Ve,{currentFormatting:Le,textSelectionActive:p!==null||Fe!==null,onFormat:wo,currentShapeFormatting:mo,shapeSelectionActive:ae?.kind==="shape",onShapeFormat:Co,onInsertSlide:Eo,slideLayouts:xo,currentLayoutPartPath:v?.snapshot.slides[Xe]?.layoutPartPath,onUndo:()=>ft("undo"),onRedo:()=>ft("redo"),canUndo:ue.canUndo,canRedo:ue.canRedo,zoom:me,onZoomChange:st,activeTool:Me,onToolChange:o=>{pe(o),o!=="select"&&(N(null),W(null)),K(null),F.current=null,I.current?.focus();},disabled:!v||ht===0,style:M.toolbar,children:jsx(Ve.Toolbar,{})}),Re.length>0?jsxs("div",{style:M.presenceStrip,role:"list","aria-label":"Collaborators",children:[Ze.visible.map(o=>{let n=o.state.cursor?.slideId===_e;return jsx("span",{role:"listitem",style:po(o.state.user.color,n),title:o.state.user.name,"aria-label":o.state.user.name,children:Cr(o.state.user.name)},o.state.clientId)}),Ze.overflow>0?jsxs("span",{role:"listitem",style:po("#64748b",true),title:`${Ze.overflow} more collaborators`,"aria-label":`${Ze.overflow} more collaborators`,children:["+",Ze.overflow]}):null]}):null]}),jsxs("div",{style:M.workspace,children:[jsx("aside",{style:M.slideStrip,"aria-label":c("slides.panelLabel"),children:v?.snapshot.slides.map((o,n)=>{let u=bo.get(o.id);return jsxs("button",{type:"button","aria-current":n===Xe?"page":void 0,style:Er(n===Xe),onClick:()=>go(n),children:[jsx("span",{style:M.slideNumber,children:n+1}),jsxs("span",{style:M.slidePreview,children:[v.thumbnails.get(o.id)?jsx(pr,{frame:v.thumbnails.get(o.id),resolveImage:l=>uo(l,w,Be,y)}):jsx("span",{style:M.slideTitle,children:wr(o.shapes)||c("slides.fallbackTitle",{number:n+1})}),o.id!==_e&&u&&(u.visible.length>0||u.overflow>0)?jsxs("span",{style:M.thumbnailPresence,"aria-hidden":"true",children:[u.visible.map(l=>jsx("span",{style:{...M.thumbnailPresenceDot,backgroundColor:l.state.user.color}},l.state.clientId)),u.overflow>0?jsxs("span",{style:M.thumbnailPresenceOverflow,children:["+",u.overflow]}):null]}):null]})]},o.id)})}),jsxs("div",{ref:I,style:M.stage,tabIndex:0,role:"application","aria-label":c("editor.appLabel"),onKeyDown:To,children:[jsx("div",{ref:$,style:M.canvasHost,children:v?.frame?jsxs("div",{style:{...M.canvasFrame,width:v.frame.width*G,height:v.frame.height*G},children:[jsx("canvas",{ref:X,"data-testid":"pptx-slide-canvas",style:{...M.canvas,cursor:Me!=="select"?"crosshair":p?"text":Mo?"move":"default"},onPointerDown:Po,onPointerMove:vo,onPointerUp:Io,onPointerCancel:Rt,onLostPointerCapture:Rt,"aria-label":ae?c("slides.canvasLabelWithSelection",{current:Xe+1,total:ht,name:ae.name}):c("slides.canvasLabel",{current:Xe+1,total:ht})}),jsx("canvas",{ref:Ee,style:M.canvasOverlay,"aria-hidden":"true"}),pt.visible.map(({peer:o,peerCount:n,shapeId:u,bounds:l},s)=>jsx(ur,{peer:o,peerCount:n,bounds:l,scale:G,labelOffset:s},u)),pt.overflow>0?jsxs("span",{style:M.remoteShapeOverflow,"aria-hidden":"true",children:["+",pt.overflow," selections"]}):null,Ue?jsx("span",{style:{...M.shapeSelection,left:(Ue.x+(Ft?.x??0))*G,top:(Ue.y+(Ft?.y??0))*G,width:Math.max(1,Ue.width*G),height:Math.max(1,Ue.height*G)},"aria-hidden":"true"}):null,Q?jsx("span",{style:{...M.textBoxPreview,left:Math.min(Q.start.x,Q.end.x)*G,top:Math.min(Q.start.y,Q.end.y)*G,width:Math.max(1,Math.abs(Q.end.x-Q.start.x))*G,height:Math.max(1,Math.abs(Q.end.y-Q.start.y))*G},"aria-hidden":"true"}):null]}):jsx("div",{style:M.empty,children:c(Se?"editor.opening":e?"editor.noSlides":"editor.openPrompt")})}),b?jsx("div",{style:M.error,children:b}):null]})]})]})}function ur({peer:e,peerCount:t,bounds:r,scale:i,labelOffset:a}){let[d,h]=useState(()=>Date.now()-e.cursorMovedAt<PRESENCE_LABEL_DURATION_MS);return useEffect(()=>{let g=PRESENCE_LABEL_DURATION_MS-(Date.now()-e.cursorMovedAt);if(g<=0){h(false);return}h(true);let c=setTimeout(()=>h(false),g);return ()=>clearTimeout(c)},[e.cursorMovedAt]),jsxs("span",{style:{...M.remoteShapeSelection,left:r.x*i,top:r.y*i,width:Math.max(1,r.width*i),height:Math.max(1,r.height*i),borderColor:e.state.user.color},"aria-hidden":"true",children:[jsx("span",{style:{...M.remoteShapeWash,backgroundColor:e.state.user.color}}),d?jsxs("span",{style:{...M.remoteShapeLabel,top:-4-a%3*20,backgroundColor:e.state.user.color},children:[e.state.user.name,t>1?` +${t-1}`:""]}):null]})}function pr({frame:e,resolveImage:t}){let r=useRef(null);return useEffect(()=>{let i=r.current;if(!i)return;let a=i.getContext("2d");if(!a)return;let d=128/e.width,h=window.devicePixelRatio||1;sizeCanvasForSlide(i,e,h,d),paintSlide(a,e,h,d,{resolveImage:t}).catch(()=>{});},[e,t]),jsx("canvas",{ref:r,style:M.thumbnailCanvas,"aria-hidden":"true"})}function fr(e,t){return t===0?0:Math.max(0,Math.min(t-1,e))}function hr(e){if(!e.startsWith("shape:"))return null;let t=e.slice(6);return $e.some(r=>r.geometry===t)?t:null}function mr(e){let t=useRef(e);return br(t.current,e)||(t.current=e),t.current}function br(e,t){return e===t?true:e.length!==t.length?false:e.every((r,i)=>xr(r,t[i]))}function xr(e,t){return e.family===t.family&&(e.bold??false)===(t.bold??false)&&(e.italic??false)===(t.italic??false)&&gr(e.bytes,t.bytes)}function gr(e,t){return e===t?true:e.byteLength!==t.byteLength?false:e.every((r,i)=>r===t[i])}function qe(e){return e.paragraphs.map(t=>t.runs.map(r=>r.text).join("")).join(`
4
- `)}function yr(e,t,r){e.formatText(t.id,0,t.length,r);}function Sr(e,t){let r=qe(e).slice(0,t),i=Array.from(r),a=i[i.length-1];return a?t-a.length:t}function Pr(e,t){let r=Array.from(qe(e).slice(t))[0];return r?t+r.length:t}function lt(e){return {bold:e.bold,italic:e.italic,underline:e.underline!=="none",fontSize:e.fontSizePt,textColor:e.color,fontFamily:e.fontFamily}}async function vr(e){return typeof FontFace>"u"||typeof document>"u"?[]:await Promise.all(e.map(async r=>{let i=r.bytes.slice().buffer,d=await new FontFace(r.family,i,{style:r.italic?"italic":"normal",weight:r.bold?"700":"400"}).load();return document.fonts.add(d),d}))}function co(e){if(!(typeof document>"u"))for(let t of e)document.fonts.delete(t);}function uo(e,t,r,i){let a=r.current.get(e);if(a)return a;let d=Ir(t.current?.mediaBytes(e),i);return r.current.set(e,d),d}async function Ir(e,t){if(!e)return null;let r=new Blob([e.slice()]);if(typeof createImageBitmap=="function")return createImageBitmap(r);let i=URL.createObjectURL(r);try{return await new Promise((a,d)=>{let h=new Image;h.onload=()=>a(h),h.onerror=()=>d(new Error(t)),h.src=i;})}finally{URL.revokeObjectURL(i);}}function Tr(e,t,r,i,a){if(!r)return;let d=t.primitives.find(c=>c.kind==="textBox"&&c.storyId===r.storyId&&c.shapeId===r.shapeId);if(!d)return;let h=Math.min(r.anchor,r.focus),g=Math.max(r.anchor,r.focus);if(e.save(),e.setTransform(i*a,0,0,i*a,0,0),h!==g){e.fillStyle="rgba(59, 130, 246, 0.26)";for(let c of d.lines){let y=Math.max(h,c.start),S=Math.min(g,c.end);if(y>=S)continue;let C=wt(c,y),z=wt(c,S);e.fillRect(Math.min(C,z),c.y,Math.max(1,Math.abs(z-C)),c.height);}}else {let c=d.lines.find(y=>h>=y.start&&h<=y.end)??d.lines[d.lines.length-1];if(c){let y=wt(c,h);e.fillStyle="#1d4ed8",e.fillRect(y,c.y,1.5,c.height);}}e.restore();}function wt(e,t){let r=e.caretStops[0];return r?e.caretStops.reduce((i,a)=>Math.abs(a.position-t)<Math.abs(i.position-t)?a:i,r).x:e.x}function wr(e){for(let t of e)for(let r of t.textStories){let i=qe(r).trim();if(i)return i.slice(0,40)}return ""}var M={root:{display:"flex",flexDirection:"column",width:"100%",height:"100%",minHeight:480,overflow:"hidden",color:"#172033",background:"#f3f5f8",fontFamily:"ui-sans-serif, system-ui, sans-serif"},toolbarShell:{display:"flex",alignItems:"center",flex:"0 0 auto",padding:"4px 0 5px",background:"#ffffff",borderBottom:"1px solid #e2e8f0"},toolbar:{flex:"1 1 auto",minWidth:0},presenceStrip:{display:"flex",alignItems:"center",gap:4,flex:"0 0 auto",maxWidth:"35%",padding:"0 10px 0 2px",overflowX:"auto"},workspace:{display:"flex",flex:1,minHeight:0},slideStrip:{width:184,padding:"14px 10px",overflowY:"auto",background:"#eef1f5",borderRight:"1px solid #d8dee9",boxSizing:"border-box"},slideNumber:{width:18,flex:"0 0 auto",paddingTop:3,fontSize:11,color:"#647087",textAlign:"right"},slidePreview:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center",width:132,aspectRatio:"16 / 9",padding:8,overflow:"hidden",background:"#ffffff",boxSizing:"border-box",boxShadow:"0 1px 4px rgba(20, 31, 50, 0.16)"},slideTitle:{fontSize:9,lineHeight:1.25,color:"#39445a",textAlign:"center"},thumbnailCanvas:{display:"block",maxWidth:"100%",height:"auto"},thumbnailPresence:{position:"absolute",top:4,right:4,display:"flex",gap:3,padding:2,borderRadius:999,background:"rgba(255, 255, 255, 0.88)",boxShadow:"0 1px 3px rgba(15, 23, 42, 0.2)"},thumbnailPresenceDot:{width:7,height:7,borderRadius:999,boxShadow:"0 0 0 1px rgba(255, 255, 255, 0.9)"},thumbnailPresenceOverflow:{color:"#475569",fontSize:8,fontWeight:700,lineHeight:"8px"},stage:{position:"relative",flex:1,minWidth:0,outline:"none",overflow:"hidden"},canvasHost:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",overflow:"auto"},canvasFrame:{position:"relative",flex:"0 0 auto"},canvas:{display:"block",flex:"0 0 auto",background:"#fff",boxShadow:"0 8px 32px rgba(27, 39, 61, 0.2)",touchAction:"none"},canvasOverlay:{position:"absolute",inset:0,display:"block",pointerEvents:"none"},shapeSelection:{position:"absolute",zIndex:3,border:"2px solid #2563eb",boxSizing:"border-box",boxShadow:"0 0 0 1px rgba(255, 255, 255, 0.9)",pointerEvents:"none"},remoteShapeSelection:{position:"absolute",zIndex:2,border:"2px solid",borderRadius:2,boxSizing:"border-box",boxShadow:"0 0 0 1px rgba(255, 255, 255, 0.88)",pointerEvents:"none"},remoteShapeWash:{position:"absolute",inset:0,opacity:.12},remoteShapeLabel:{position:"absolute",left:-2,maxWidth:180,overflow:"hidden",padding:"3px 6px",borderRadius:"4px 4px 4px 0",color:"#ffffff",fontSize:11,fontWeight:650,lineHeight:"14px",textOverflow:"ellipsis",whiteSpace:"nowrap",transform:"translateY(-100%)",boxShadow:"0 1px 3px rgba(15, 23, 42, 0.25)"},remoteShapeOverflow:{position:"absolute",top:8,right:8,zIndex:3,padding:"3px 6px",borderRadius:999,backgroundColor:"#475569",color:"#ffffff",fontSize:10,fontWeight:700,pointerEvents:"none"},textBoxPreview:{position:"absolute",border:"1.5px dashed #1a73e8",background:"rgba(26, 115, 232, 0.08)",boxSizing:"border-box",pointerEvents:"none"},empty:{margin:"auto",color:"#6b7587",fontSize:14},error:{position:"absolute",left:16,right:16,bottom:14,padding:"9px 12px",color:"#8b1e2d",background:"#fff0f2",border:"1px solid #efb8c0",borderRadius:6,fontSize:12}};function Cr(e){let t=e.trim().split(/\s+/).filter(Boolean);return t.length===0?"?":t.slice(0,2).map(r=>r[0]).join("").toUpperCase()}function po(e,t){return {display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,flex:"0 0 auto",border:"2px solid #ffffff",borderRadius:999,backgroundColor:e,boxShadow:"0 0 0 1px rgba(15, 23, 42, 0.14)",color:"#ffffff",fontSize:10,fontWeight:700,letterSpacing:"-0.02em",opacity:t?1:.38}}function Er(e){return {display:"flex",alignItems:"flex-start",gap:7,width:"100%",marginBottom:12,padding:4,border:e?"2px solid #325ee6":"2px solid transparent",borderRadius:5,background:"transparent",cursor:"pointer"}}export{Ve as EditorToolbar,Ne as EditorToolbarContext,tt as LocaleProvider,dr as PptxEditor,nt as PptxToolbar,$e as SHAPE_PRESETS,nt as Toolbar,ce as ToolbarButton,Ae as ToolbarDropdown,be as ToolbarGroup,Oe as ToolbarMenuItem,Ho as ToolbarMenuSeparator,De as ToolbarSeparator,Ao as useEditorToolbar,He as useTranslation};
1
+ import {StaleProposalError,initWasm,openPresentation,sizeCanvasForSlide,paintSlide,PRESENCE_LABEL_DURATION_MS,presentationImageBlob,slideToPng}from'@betteroffice/pptx';import {createContext,useMemo,useContext,useState,useRef,useCallback,useEffect,useId}from'react';import {en,deepMerge,createT}from'@betteroffice/pptx-i18n';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Wn=createContext(en),Kn=createContext("en");function Ct({i18n:e,children:t}){let o=typeof e?._lang=="string"?e._lang:"en",r=useMemo(()=>deepMerge(en,e),[e]);return jsx(Kn.Provider,{value:o,children:jsx(Wn.Provider,{value:r,children:t})})}function Te(){let e=useContext(Wn),t=useContext(Kn);return {t:useMemo(()=>createT(e,t),[e,t])}}function jn({handle:e,proposals:t,snapshot:o,resolveImage:r,onAccept:a,onReject:s,onNavigate:d,onClose:m}){let{t:f}=Te(),g=useId(),[l,y]=useState(null),[I,K]=useState(null),[X,j]=useState(null),b=useRef(null),w=useRef(null);useEffect(()=>{if(l){if(!t.some(h=>h.id===l.id)){y(null);return}try{let h=e.previewProposal(l.id),T=h.proposal.changes[l.index],O=h.snapshot.slides.findIndex(se=>se.id===T?.slideId);if(O<0)throw new Error(f("proposals.targetMissing"));let Z=e.layoutSlide(O),Se=e.layoutProposalSlide(l.id,O);K({data:h,before:Z,after:Se}),j(null);}catch(h){K(null),j(h instanceof Error?h.message:String(h));}}},[e,t,o,l,f]),useEffect(()=>{let h=b.current;l&&h&&!h.open&&h.showModal(),!l&&h?.open&&h.close();},[l]);let B=h=>{let T=o.slides.findIndex(Z=>Z.id===h.slideId),O=h.before?.name||f("notes.panelLabel");return T<0?f("proposals.targetMissing"):f("proposals.target",{slide:T+1,name:O})},k=(h,T,O)=>{w.current=O;let Z=h.changes[T];d(Z.slideId,Z.shapeId,h.id),K(null),j(null),y({id:h.id,index:T});},N=h=>{if(!(!l||!I))try{let T=e.previewProposal(l.id);if(JSON.stringify(T.proposal.changes)!==JSON.stringify(I.data.proposal.changes)){let O=T.proposal.changes[l.index],Z=T.snapshot.slides.findIndex(Se=>Se.id===O.slideId);K({data:T,before:e.layoutSlide(Z),after:e.layoutProposalSlide(l.id,Z)}),j(f("proposals.changedAgain"));return}a(l.id,h);}catch(T){K(null),j(T instanceof Error?T.message:String(T));}};return jsxs("aside",{"data-testid":"pptx-proposals-panel","aria-label":f("proposals.title"),style:D.panel,children:[jsxs("header",{style:D.header,children:[jsxs("strong",{children:[f("proposals.title")," ",jsx("span",{style:D.count,children:t.length})]}),jsx("button",{type:"button",onClick:m,"aria-label":f("proposals.close"),style:D.button,children:"\xD7"})]}),t.length===0&&jsx("p",{style:D.muted,children:f("proposals.empty")}),t.map(h=>jsxs("section",{"data-testid":"pptx-proposal","data-proposal-id":h.id,style:D.card,children:[jsx("strong",{style:D.author,children:h.agentId}),h.note&&jsx("p",{style:D.note,children:h.note}),h.changes.map((T,O)=>jsxs("div",{style:D.change,children:[jsx("button",{type:"button",onClick:()=>d(T.slideId,T.shapeId,h.id),style:D.link,children:B(T)}),T.oldText!==T.newText?jsxs("div",{style:D.textDiff,children:[jsx("del",{style:D.deleted,children:T.oldText||f("proposals.blank")}),jsx("ins",{style:D.inserted,children:T.newText||f("proposals.blank")})]}):null,T.before&&T.after&&jsx(Pr,{change:T}),jsx("button",{type:"button","data-testid":"pptx-proposal-preview",style:D.button,onClick:Z=>k(h,O,Z.currentTarget),children:f("proposals.preview")})]},`${T.slideId}:${T.shapeId??"notes"}`)),h.staleTargets.length>0&&jsx("p",{role:"alert","data-testid":"pptx-proposal-stale",style:D.warning,children:f("proposals.stale")}),jsxs("div",{style:D.actions,children:[jsx("button",{type:"button","data-testid":"pptx-proposal-accept",style:D.primary,onClick:()=>a(h.id),children:f("proposals.accept")}),jsx("button",{type:"button","data-testid":"pptx-proposal-reject",style:D.button,onClick:()=>s(h.id),children:f("proposals.reject")})]})]},h.id)),jsxs("dialog",{ref:b,"data-testid":"pptx-proposal-preview-dialog","aria-labelledby":g,style:D.dialog,onCancel:()=>y(null),onClose:()=>{y(null),w.current?.focus();},children:[jsxs("header",{style:D.header,children:[jsx("strong",{id:g,children:f("proposals.previewTitle")}),jsx("button",{type:"button",style:D.button,onClick:()=>y(null),children:f("proposals.close")})]}),X&&jsx("p",{role:"alert",style:D.warning,children:X}),I&&l&&jsxs(Fragment,{children:[jsxs("p",{children:[jsx("strong",{children:I.data.proposal.agentId}),I.data.proposal.note&&jsxs(Fragment,{children:[" \xB7 ",I.data.proposal.note]})]}),jsxs("label",{children:[f("proposals.targetLabel")," ",jsx("select",{"aria-label":f("proposals.targetLabel"),value:l.index,onChange:h=>{let T=Number(h.target.value),O=I.data.proposal.changes[T];d(O.slideId,O.shapeId,l.id),y({id:l.id,index:T});},children:I.data.proposal.changes.map((h,T)=>jsx("option",{value:T,children:B(h)},T))})]}),I.data.proposal.changes[l.index].oldText!==I.data.proposal.changes[l.index].newText&&jsxs("div",{style:D.textDiff,children:[jsx("del",{style:D.deleted,children:I.data.proposal.changes[l.index].oldText||f("proposals.blank")}),jsx("ins",{style:D.inserted,children:I.data.proposal.changes[l.index].newText||f("proposals.blank")})]}),jsxs("div",{style:D.previews,children:[jsx(Un,{label:f("proposals.before"),frame:I.before,resolveImage:r}),jsx(Un,{label:f("proposals.after"),frame:I.after,resolveImage:r})]}),I.data.proposal.staleTargets.length>0&&jsx("p",{role:"alert",style:D.warning,children:f("proposals.stalePreview")}),jsxs("div",{style:D.actions,children:[I.data.proposal.staleTargets.length>0?jsx("button",{type:"button","data-testid":"pptx-proposal-force",style:D.primary,onClick:()=>N(true),children:f("proposals.force")}):jsx("button",{type:"button",style:D.primary,onClick:()=>N(false),children:f("proposals.accept")}),jsx("button",{type:"button",style:D.button,onClick:()=>s(l.id),children:f("proposals.reject")})]})]})]})]})}function Pr({change:e}){let{t}=Te(),o=e.before,r=e.after,a=o.x!==r.x||o.y!==r.y||o.width!==r.width||o.height!==r.height,s=d=>[d.x,d.y,d.width,d.height].map(m=>(m/12700).toFixed(1)).join(", ");return jsxs(Fragment,{children:[a&&jsxs("p",{style:D.detail,children:[t("proposals.geometry"),jsx("br",{}),s(o)," \u2192 ",s(r)," pt"]}),JSON.stringify({...o,x:0,y:0,width:0,height:0})!==JSON.stringify({...r,x:0,y:0,width:0,height:0})&&e.oldText===e.newText&&jsx("p",{style:D.detail,children:t("proposals.appearance")})]})}function Un({label:e,frame:t,resolveImage:o}){let r=useRef(null),[a,s]=useState(null);return useEffect(()=>{let d=false,m=r.current;if(!m)return;let f=document.createElement("canvas"),g=f.getContext("2d"),l=m.getContext("2d");if(!g||!l)return;let y=Math.min(1,560/t.width),I=window.devicePixelRatio||1;return sizeCanvasForSlide(f,t,I,y),s(null),paintSlide(g,t,I,y,{resolveImage:o}).then(()=>{d||(sizeCanvasForSlide(m,t,I,y),l.setTransform(1,0,0,1,0,0),l.drawImage(f,0,0));}).catch(K=>{d||s(K instanceof Error?K.message:String(K));}),()=>{d=true;}},[t,o]),jsxs("figure",{style:D.figure,children:[jsx("figcaption",{style:D.caption,children:e}),jsx("canvas",{ref:r,role:"img","aria-label":e,style:{maxWidth:"100%",height:"auto",display:"block",background:"#fff"}}),a&&jsx("p",{role:"alert",children:a})]})}var D={panel:{width:340,maxWidth:"45%",flex:"0 0 auto",overflowY:"auto",background:"#fff",borderLeft:"1px solid #dbe3ee",padding:16,fontSize:13},header:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},count:{color:"#64748b",marginLeft:6},card:{border:"1px solid #dbe3ee",borderLeft:"3px solid #6366f1",borderRadius:8,padding:12,marginTop:16},author:{color:"#4338ca"},note:{margin:"6px 0 12px",lineHeight:1.5},change:{borderTop:"1px solid #eef2f7",padding:"10px 0"},textDiff:{display:"grid",gap:6,margin:"8px 0",whiteSpace:"pre-wrap",overflowWrap:"anywhere",maxHeight:200,overflowY:"auto"},deleted:{color:"#9f1239",background:"#fff1f2",padding:"4px 6px"},inserted:{color:"#166534",background:"#f0fdf4",padding:"4px 6px",textDecoration:"none"},actions:{display:"flex",flexWrap:"wrap",gap:8,marginTop:12},button:{border:"1px solid #cbd5e1",borderRadius:5,background:"#fff",color:"#334155",padding:"6px 10px",cursor:"pointer",font:"inherit"},primary:{border:"1px solid #4338ca",borderRadius:5,background:"#4338ca",color:"#fff",padding:"6px 10px",cursor:"pointer",font:"inherit"},link:{background:"none",border:0,padding:0,color:"#4338ca",textAlign:"left",cursor:"pointer",font:"inherit",fontWeight:600},warning:{padding:10,borderRadius:5,background:"#fffbeb",color:"#92400e",lineHeight:1.5},detail:{color:"#64748b",lineHeight:1.5},muted:{color:"#64748b",marginTop:24},dialog:{width:"min(1200px, 92vw)",maxHeight:"90vh",overflow:"auto",padding:24,border:"1px solid #cbd5e1",borderRadius:12,color:"#172033",background:"#f8fafc"},previews:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(360px, 100%), 1fr))",gap:16,margin:"20px 0"},figure:{margin:0,minWidth:0},caption:{fontWeight:600,marginBottom:8}};var Gn=["nw","n","ne","e","se","s","sw","w"];var Ir=Math.fround(Math.fround(Math.PI)/180);function gt(e,t,o,r){if(!Number.isFinite(e.width)||!Number.isFinite(e.height)||e.width<=0||e.height<=0)return null;let a=(o-e.left)*t.width/e.width,s=(r-e.top)*t.height/e.height;return Number.isFinite(a)&&Number.isFinite(s)?{x:a,y:s}:null}function Ee(e,t){for(let o of e){if(o.id===t)return o;let r=Ee(o.children,t);if(r)return r}return null}function Zn(e){let t=new Map,o=[...e];for(;o.length>0;){let r=o.pop();t.set(r.id,r),o.push(...r.children);}return t}function tn(e,t){for(let o of e.shapes)if(o.id===t||Ee(o.children,t))return o;return null}function $n(e,t){return !!(e&&e.id===t.slideId&&Ee(e.shapes,t.shapeId))}function kt(e,t){return e?.pointerId===t}function nn(e){return e.width>0&&e.height>0}function Rt(e){let t=(e.rotationDeg%360+360)%360;return nn(e)&&t===0&&!e.flipH&&!e.flipV}function Ve(e,t,o){let r=new Set;Jn(o,r);let a=t.primitives.filter(l=>l.shapeId&&r.has(l.shapeId));if(a.length===0)return o.width<=0||o.height<=0||e.widthEmu<=0||e.heightEmu<=0?null:{x:o.x*t.width/e.widthEmu,y:o.y*t.height/e.heightEmu,width:o.width*t.width/e.widthEmu,height:o.height*t.height/e.heightEmu};let s=a.map(l=>{let y=(l.transform?.rotationDeg??0)*Math.PI/180,I=Math.abs(l.w*Math.cos(y))+Math.abs(l.h*Math.sin(y)),K=Math.abs(l.w*Math.sin(y))+Math.abs(l.h*Math.cos(y));return {x:l.x+(l.w-I)/2,y:l.y+(l.h-K)/2,width:I,height:K}}),d=Math.min(...s.map(l=>l.x)),m=Math.min(...s.map(l=>l.y)),f=Math.max(...s.map(l=>l.x+l.width)),g=Math.max(...s.map(l=>l.y+l.height));return {x:d,y:m,width:f-d,height:g-m}}function on(e,t,o,r){let a=e.primitives.find(l=>l.kind==="textBox"&&l.shapeId===t&&l.storyId===o);if(!a||a.lines.length===0)return null;let s=Yn(a,r),d=0;for(let l=1;l<a.lines.length;l+=1){let y=a.lines[l],I=a.lines[d];Mt(y.y,y.height,s.y)<Mt(I.y,I.height,s.y)&&(d=l);}let m=a.lines[d],f=m.caretStops[0];return f?{position:m.caretStops.reduce((l,y)=>Math.abs(y.x-s.x)<Math.abs(l.x-s.x)?y:l,f).position,lineIndex:d}:{position:m.start,lineIndex:d}}function wr(e,t){let o={x:Math.fround(t.x),y:Math.fround(t.y)};for(let r=e.primitives.length-1;r>=0;r-=1){let a=e.primitives[r];if(!a.shapeId)continue;let s=Vn(a,o);if(s)return a.kind==="textBox"&&a.storyId&&Tr(a,s.y)?"text":"shape"}return null}function Yn(e,t){let o=e.transform;if(!o||!o.rotationDeg&&!o.flipH&&!o.flipV)return t;let r=Math.fround,a=r(r(e.x)+r(r(e.w)/2)),s=r(r(e.y)+r(r(e.h)/2)),d=r(r(o.rotationDeg??0)*Ir),m=r(Math.cos(d)),f=r(Math.sin(d)),g=r(t.x-a),l=r(t.y-s),y=r(r(g*m)+r(l*f)),I=r(r(l*m)-r(g*f));return o.flipH&&(y=-y),o.flipV&&(I=-I),{x:r(a+y),y:r(s+I)}}function Xn(e,t){return Math.fround(Math.fround(e)+Math.fround(t))}function Vn(e,t){let o=Yn(e,t);return o.x>=Math.fround(e.x)&&o.x<=Xn(e.x,e.w)&&o.y>=Math.fround(e.y)&&o.y<=Xn(e.y,e.h)?o:null}function Tr(e,t){return e.lines.length===0?false:e.lines.reduce((r,a)=>Mt(a.y,a.height,t)<Mt(r.y,r.height,t)?a:r).caretStops.length>0}function qn(e,t,o,r){return {x:o.x+Math.round(r.x*e.widthEmu/t.width),y:o.y+Math.round(r.y*e.heightEmu/t.height)}}function rn(e,t,o,r,a=4){return Math.hypot(o-e,r-t)>=a}function Jn(e,t){t.add(e.id);for(let o of e.children)Jn(o,t);}function Mt(e,t,o){return o<e?e-o:o>e+t?o-e-t:0}function Qn(e,t){let o=t.includes("w")?e.x:t.includes("e")?e.x+e.width:e.x+e.width/2,r=t.startsWith("n")?e.y:t.startsWith("s")?e.y+e.height:e.y+e.height/2;return {x:o,y:r}}function eo(e){return e==="nw"||e==="se"?"nwse-resize":e==="ne"||e==="sw"?"nesw-resize":e==="n"||e==="s"?"ns-resize":"ew-resize"}function Cr(e,t,o,r){let{x:a,y:s,width:d,height:m}=e;if(t.includes("w")){let f=Math.min(o.x,d-r);a+=f,d-=f;}else t.includes("e")&&(d=Math.max(r,d+o.x));if(t.startsWith("n")){let f=Math.min(o.y,m-r);s+=f,m-=f;}else t.startsWith("s")&&(m=Math.max(r,m+o.y));return {x:a,y:s,width:d,height:m}}function to(e,t,o){return o?{x:o.x-e.x,y:o.y-e.y}:t}function an(e,t,o,r,a){if(!Rt(o))return null;let s={x:Math.round(a.x*e.widthEmu/t.width),y:Math.round(a.y*e.heightEmu/t.height)},d=Cr({x:o.x,y:o.y,width:o.width,height:o.height},r,s,76200);return {x:d.x,y:d.y,width:d.width,height:d.height}}function no(e,t,o,r,a){let s=an(e,t,o,r,a);return !s||e.widthEmu<=0||e.heightEmu<=0?null:{x:s.x*t.width/e.widthEmu,y:s.y*t.height/e.heightEmu,width:s.width*t.width/e.widthEmu,height:s.height*t.height/e.heightEmu}}function sn(e,t,o=1){let r=wr(e,t);if(r!=="text")return r;let a={x:Math.fround(t.x),y:Math.fround(t.y)};for(let s=e.primitives.length-1;s>=0;s-=1){let d=e.primitives[s];if(!d.shapeId)continue;let m=Vn(d,a);if(m)return Er(d,m,o)?"shape":"text"}return r}function Er(e,t,o){let r=Number.isFinite(o)&&o>0?o:1,a=Math.min(6/r,e.w/3,e.h/3);return t.x-e.x<=a||e.x+e.w-t.x<=a||t.y-e.y<=a||e.y+e.h-t.y<=a}function ao(e,t,o,r){let[a,s]=useState(true),[d,m]=useState(null),f=o?.slides[r]?.id,g=useMemo(()=>t.filter(I=>I.changes.some(K=>K.slideId===f)),[t,f]),l=g.find(I=>I.id===d)??g[0]??null,y=useMemo(()=>{if(!a||!e||!l)return {diff:null,error:null};try{return {diff:e.layoutProposalDiffSlide(l.id,r),error:null}}catch(I){return {diff:null,error:I instanceof Error?I.message:String(I)}}},[a,e,l,r,o]);return useEffect(()=>{s(true),m(null);},[e]),{...y,available:g,selected:l,enabled:a,setEnabled:s,select:m,reviewing:a&&l!==null}}function so({review:e,ready:t,onAccept:o,onReject:r,onDetails:a}){let{t:s}=Te();if(!e.selected)return null;let d=e.selected.staleTargets.length>0,m=d||!!e.error||e.enabled&&!t;return jsxs("div",{style:J.toolbar,"data-testid":"pptx-canvas-review-toolbar",children:[jsxs("div",{style:J.row,children:[jsxs("label",{style:J.label,children:[s("proposals.canvasTitle"),jsx("select",{"aria-label":s("proposals.canvasTitle"),value:e.selected.id,onChange:f=>{e.select(f.target.value),e.setEnabled(true);},style:J.select,children:e.available.map((f,g)=>jsxs("option",{value:f.id,children:[g+1,". ",f.agentId,f.note?` \xB7 ${f.note}`:""]},f.id))})]}),jsx("button",{type:"button",style:J.button,"data-testid":"pptx-canvas-review-toggle","aria-pressed":e.enabled,onClick:()=>e.setEnabled(!e.enabled),children:s(e.enabled?"proposals.editSlide":"proposals.showDiff")}),jsx("button",{type:"button",style:J.button,onClick:a,children:s("proposals.details")}),jsx("button",{type:"button",style:{...J.primary,opacity:m?.45:1,cursor:m?"default":"pointer"},disabled:m,"data-testid":"pptx-canvas-proposal-accept",onClick:()=>o(e.selected.id),children:s("proposals.accept")}),jsx("button",{type:"button",style:J.button,"data-testid":"pptx-canvas-proposal-reject",onClick:()=>r(e.selected.id),children:s("proposals.reject")})]}),e.enabled&&jsxs("div",{style:J.legend,children:[jsx("span",{style:J.removed,children:s("proposals.removed")}),jsx("span",{style:J.added,children:s("proposals.added")}),jsx("span",{children:s("proposals.reviewHint")})]}),d&&jsx("p",{role:"status",style:J.warning,children:s("proposals.canvasStale")}),e.error&&jsx("p",{role:"alert",style:J.warning,children:e.error})]})}function lo({diff:e,current:t,frame:o,slideIndex:r,scale:a,resolveImage:s,onTarget:d,onPainted:m}){let{t:f}=Te(),g=useRef(null),[l,y]=useState(null),[I,K]=useState(null),X=t.slides[r]?.id,j=e.proposal.changes.filter(b=>b.slideId===X&&b.shapeId&&b.before&&b.after);return useEffect(()=>{let b=false,w=g.current;if(!w)return;let B=document.createElement("canvas"),k=B.getContext("2d"),N=w.getContext("2d");if(!k||!N)return;let h=window.devicePixelRatio||1;return sizeCanvasForSlide(B,e.frame,h,a),w.dataset.ready="false",y(null),paintSlide(k,e.frame,h,a,{resolveImage:s,textChanges:e.textChanges}).then(()=>{b||(sizeCanvasForSlide(w,e.frame,h,a),N.setTransform(1,0,0,1,0,0),N.drawImage(B,0,0),w.dataset.ready="true",K(e),m(e));}).catch(T=>{b||y(T instanceof Error?T.message:String(T));}),()=>{b=true;}},[e,a,s,m]),jsxs("div",{style:J.overlay,"data-testid":"pptx-canvas-proposal-diff",children:[jsx("canvas",{ref:g,role:"img","aria-label":f("proposals.canvasTitle"),style:{...J.canvas,visibility:I===e?"visible":"hidden"}}),I!==e&&!l&&jsx("p",{role:"status",style:J.paintError,children:f("proposals.loadingDiff")}),j.map(b=>{let w=Ve(t,o,b.before),B=Ve(e.snapshot,e.frame,b.after);if(!B)return null;let k=w&&(w.x!==B.x||w.y!==B.y||w.width!==B.width||w.height!==B.height),N=h=>({left:h.x*a,top:h.y*a,width:Math.max(1,h.width*a),height:Math.max(1,h.height*a)});return jsxs("div",{children:[k&&jsx("span",{"data-testid":"pptx-proposal-old-bounds",style:{...J.outline,...N(w),borderColor:"#b91c1c",borderStyle:"dashed",pointerEvents:"none"},"aria-hidden":"true",children:jsx("span",{style:{...J.tag,color:"#b91c1c",background:"#fee2e2"},children:f("proposals.previousPosition")})}),jsx("button",{type:"button","data-testid":"pptx-proposal-canvas-target","aria-label":`${e.proposal.agentId}: ${b.after.name}`,onClick:()=>d(b.slideId,b.shapeId),style:{...J.outline,...N(B),borderColor:"#16a34a",cursor:"pointer"},children:k&&jsx("span",{style:{...J.tag,left:"auto",right:-1,color:"#166534",background:"#dcfce7"},children:f("proposals.proposedPosition")})})]},b.shapeId)}),jsx("div",{style:J.srOnly,children:j.map(b=>jsxs("p",{children:[b.after.name,": ",jsx("del",{children:b.oldText})," ",jsx("ins",{children:b.newText})]},b.shapeId))}),l&&jsx("p",{role:"alert",style:J.paintError,children:l})]})}function co({diff:e,slideId:t}){let{t:o}=Te(),r=e?.proposal.changes.find(a=>a.slideId===t&&!a.shapeId&&a.oldText!==a.newText);return r?jsxs("section",{"aria-label":o("notes.panelLabel"),style:J.notes,"data-testid":"pptx-proposal-notes-diff",children:[jsx("strong",{children:o("notes.panelLabel")}),jsx("del",{style:J.removed,children:r.oldText||o("proposals.blank")}),jsx("ins",{style:J.added,children:r.newText||o("proposals.blank")})]}):null}var J={toolbar:{flex:"0 0 auto",padding:"10px 14px",background:"#fff",borderBottom:"1px solid #dbe3ee",fontSize:12},row:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:8},label:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:8,minWidth:0,fontWeight:600},select:{maxWidth:260,minWidth:80,padding:5,border:"1px solid #cbd5e1",borderRadius:4,font:"inherit"},legend:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:12,marginTop:8,color:"#64748b"},removed:{color:"#b91c1c",background:"#fee2e2",textDecoration:"line-through",padding:"2px 5px"},added:{color:"#166534",background:"#dcfce7",textDecoration:"underline",padding:"2px 5px"},button:{padding:"5px 9px",border:"1px solid #cbd5e1",borderRadius:5,background:"#fff",color:"#334155",cursor:"pointer",font:"inherit"},primary:{padding:"5px 9px",border:"1px solid #4338ca",borderRadius:5,background:"#4338ca",color:"#fff",cursor:"pointer",font:"inherit"},warning:{margin:"8px 0 0",color:"#92400e"},overlay:{position:"absolute",inset:0,overflow:"hidden",background:"#fff"},canvas:{position:"absolute",inset:0,display:"block",pointerEvents:"none"},outline:{position:"absolute",border:"1px solid",background:"transparent",padding:0},tag:{position:"absolute",left:-1,top:-18,fontSize:11,lineHeight:"16px",padding:"0 4px",whiteSpace:"nowrap"},srOnly:{position:"absolute",width:1,height:1,padding:0,margin:-1,overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"},notes:{display:"grid",gap:6,padding:"10px 14px",maxHeight:160,overflow:"auto",background:"#fff",fontSize:12,whiteSpace:"pre-wrap"},paintError:{position:"absolute",top:8,left:8,right:8,padding:8,background:"#fff1f2",color:"#b91c1c"}};var rt=createContext(null);function Dr(){let e=useContext(rt);if(!e)throw new Error("useEditorToolbar must be used within an <EditorToolbar> component");return e}function ee({name:e,size:t=20,style:o}){return jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",style:{display:"inline-flex",flexShrink:0,...o},children:[e==="save"&&jsx("path",{d:"M12 3v11m0 0 4-4m-4 4-4-4M5 19h14"}),e==="image"&&jsxs(Fragment,{children:[jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),jsx("circle",{cx:"8.5",cy:"9.5",r:"1.25"}),jsx("path",{d:"m6 17 4.5-4.5 3.25 3.25L16 13.5l2 2"})]}),e==="undo"&&jsx("path",{d:"m9 7-5 5 5 5M5 12h9a6 6 0 0 1 6 6"}),e==="redo"&&jsx("path",{d:"m15 7 5 5-5 5m4-5h-9a6 6 0 0 0-6 6"}),e==="newSlide"&&jsxs(Fragment,{children:[jsx("rect",{x:"3",y:"5",width:"15",height:"14",rx:"1.5"}),jsx("path",{d:"M7 9h7M7 13h5M20 9v6m-3-3h6"})]}),e==="select"&&jsx("path",{d:"m6 3 12 9-6 1.5L9 19Z"}),e==="textBox"&&jsxs(Fragment,{children:[jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"1.5"}),jsx("path",{d:"M8 8h8m-4 0v8m-3 0h6"})]}),e==="shape"&&jsx("rect",{x:"4",y:"6",width:"16",height:"12",rx:"3"}),e==="fillColor"&&jsxs(Fragment,{children:[jsx("path",{d:"m7 4 10 10-5 5-7-7Z"}),jsx("path",{d:"m5 12 7-7m6 12h2"})]}),e==="borderColor"&&jsx(Fragment,{children:jsx("path",{d:"M5 18h14M8 15l8-8 2 2-8 8H8Z"})}),e==="borderWidth"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 7h14",strokeWidth:"1"}),jsx("path",{d:"M5 12h14",strokeWidth:"2"}),jsx("path",{d:"M5 18h14",strokeWidth:"3"})]}),e==="bold"&&jsx("path",{d:"M7 4h6a4 4 0 0 1 0 8H7zm0 8h7a4 4 0 0 1 0 8H7z"}),e==="italic"&&jsx("path",{d:"M10 4h8M6 20h8M14 4 10 20"}),e==="underline"&&jsxs(Fragment,{children:[jsx("path",{d:"M7 4v7a5 5 0 0 0 10 0V4"}),jsx("path",{d:"M5 20h14"})]}),e==="textColor"&&jsxs(Fragment,{children:[jsx("path",{d:"m7 16 5-12 5 12M9 11h6"}),jsx("path",{d:"M5 20h14",strokeWidth:"3"})]}),e==="alignLeft"&&jsx("path",{d:"M4 6h16M4 10h10M4 14h16M4 18h10"}),e==="alignCenter"&&jsx("path",{d:"M4 6h16M7 10h10M4 14h16M7 18h10"}),e==="alignRight"&&jsx("path",{d:"M4 6h16M10 10h10M4 14h16M10 18h10"}),e==="alignJustify"&&jsx("path",{d:"M4 6h16M4 10h16M4 14h16M4 18h16"}),e==="more"&&jsxs(Fragment,{children:[jsx("circle",{cx:"5",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),jsx("circle",{cx:"12",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),jsx("circle",{cx:"19",cy:"12",r:"1",fill:"currentColor",stroke:"none"})]}),e==="chevronDown"&&jsx("path",{d:"m7 10 5 5 5-5"}),e==="remove"&&jsx("path",{d:"M5 12h14"}),e==="add"&&jsx("path",{d:"M12 5v14M5 12h14"})]})}var A={text:"#3c4043",muted:"#5f6368",disabled:"#9aa0a6",hover:"#e2e7ef",active:"#d3e3fd",border:"#c7cacf",surface:"#ffffff",rail:"#edf2fa"},Ar={appearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:2,minWidth:28,height:28,padding:"0 5px",border:0,borderRadius:4,color:A.text,font:"500 13px ui-sans-serif, system-ui, sans-serif",lineHeight:1,whiteSpace:"nowrap",boxSizing:"border-box"};function fo(e,t,o,r){return {...Ar,background:t?A.active:o&&!e?A.hover:"transparent",color:e?A.disabled:A.text,cursor:e?"default":"pointer",opacity:e?.48:1,...r}}function Pe({active:e=false,disabled:t=false,title:o,onClick:r,children:a,style:s,testId:d,ariaExpanded:m}){let[f,g]=useState(false);return jsx("button",{type:"button","data-testid":d,disabled:t,"aria-label":o,"aria-pressed":e||void 0,"aria-expanded":m,title:o,onMouseDown:l=>l.preventDefault(),onMouseEnter:()=>g(true),onMouseLeave:()=>g(false),onClick:t?void 0:r,style:fo(t,e,f,s),children:a})}function Me({label:e,children:t,style:o}){return jsx("div",{role:"group","aria-label":e,style:{display:"inline-flex",alignItems:"center",gap:1,flex:"0 0 auto",...o},children:t})}function _e(){return jsx("div",{role:"separator",style:{width:1,height:24,margin:"0 5px",background:A.border,flex:"0 0 auto"}})}function qe({title:e,trigger:t,children:o,disabled:r=false,active:a=false,menuWidth:s=220,style:d,testId:m}){let[f,g]=useState(false),[l,y]=useState(false),[I,K]=useState({top:0,left:0}),X=useRef(null),j=useRef(null),b=useCallback(()=>g(false),[]);return useEffect(()=>{if(!f||!X.current)return;let w=X.current.getBoundingClientRect(),B=Math.min(w.left,Math.max(8,window.innerWidth-s-8));K({top:w.bottom+4,left:B});},[f,s]),useEffect(()=>{if(!f)return;let w=N=>{let h=N.target;!X.current?.contains(h)&&!j.current?.contains(h)&&b();},B=N=>{N.key==="Escape"&&b();},k=()=>b();return document.addEventListener("mousedown",w),document.addEventListener("keydown",B),window.addEventListener("scroll",k,true),()=>{document.removeEventListener("mousedown",w),document.removeEventListener("keydown",B),window.removeEventListener("scroll",k,true);}},[f,b]),jsxs("div",{style:{position:"relative",display:"inline-flex",flex:"0 0 auto"},children:[jsx("button",{ref:X,type:"button","data-testid":m,disabled:r,"aria-label":e,"aria-haspopup":"menu","aria-expanded":f,title:e,onMouseDown:w=>w.preventDefault(),onMouseEnter:()=>y(true),onMouseLeave:()=>y(false),onClick:()=>!r&&g(w=>!w),style:fo(r,a||f,l,d),children:t}),f&&jsx("div",{ref:j,role:"menu","aria-label":e,onMouseDown:w=>w.preventDefault(),style:{position:"fixed",top:I.top,left:I.left,zIndex:1e4,width:s,maxHeight:"min(440px, calc(100vh - 16px))",overflowY:"auto",padding:6,border:`1px solid ${A.border}`,borderRadius:8,background:A.surface,boxShadow:"0 4px 16px rgba(60, 64, 67, 0.24)",boxSizing:"border-box"},children:o(b)})]})}function it({label:e,icon:t,selected:o=false,disabled:r=false,onClick:a,close:s}){let[d,m]=useState(false);return jsxs("button",{type:"button",role:"menuitem",disabled:r,"aria-label":e,onMouseEnter:()=>m(true),onMouseLeave:()=>m(false),onClick:()=>{r||(a?.(),s?.());},style:{appearance:"none",display:"flex",alignItems:"center",gap:10,width:"100%",minHeight:32,padding:"5px 9px",border:0,borderRadius:4,background:d&&!r?A.hover:"transparent",color:r?A.disabled:A.text,cursor:r?"default":"pointer",opacity:r?.48:1,font:"400 13px ui-sans-serif, system-ui, sans-serif",textAlign:"left",boxSizing:"border-box"},children:[jsx("span",{style:{display:"inline-grid",placeItems:"center",width:20,flex:"0 0 auto"},children:t}),jsx("span",{style:{flex:1},children:e}),o&&jsx("span",{"aria-hidden":"true",children:"\u2713"})]})}function Br(){return jsx("div",{role:"separator",style:{height:1,margin:"5px 2px",background:A.border}})}function Dt({value:e,label:t,onChange:o,onClear:r,icon:a="textColor",none:s=false,clearLabel:d,disabled:m=false,testId:f}){let[g,l]=useState(false);return jsxs("span",{style:{display:"inline-flex",alignItems:"center",height:28},children:[jsxs("label",{title:t,"aria-label":t,style:{display:"inline-grid",placeItems:"center",width:28,height:28,borderRadius:4,background:g&&!m?A.hover:"transparent",color:m?A.disabled:A.text,cursor:m?"default":"pointer",opacity:m?.48:1,boxSizing:"border-box",position:"relative"},onMouseEnter:()=>l(true),onMouseLeave:()=>l(false),children:[jsx(ee,{name:a,size:20}),jsx("span",{"aria-hidden":"true",style:{position:"absolute",left:5,right:5,bottom:2,height:3,borderRadius:2,background:s?"transparent":e,border:s?`1px solid ${A.disabled}`:0,boxSizing:"border-box"}}),s?jsx("span",{"aria-hidden":"true",style:{position:"absolute",left:5,bottom:3,width:18,height:1,background:"#d93025",transform:"rotate(-18deg)"}}):null,jsx("input",{"data-testid":f,type:"color",value:e,disabled:m,"aria-label":t,onChange:y=>o?.(y.target.value),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0}})]}),r?jsx("button",{type:"button",disabled:m,"aria-label":d??t,title:d??t,onMouseDown:y=>y.preventDefault(),onClick:r,style:{appearance:"none",width:15,height:28,padding:0,border:0,borderRadius:3,background:"transparent",color:m?A.disabled:A.muted,cursor:m?"default":"pointer",opacity:m?.48:1,font:"500 14px ui-sans-serif, system-ui, sans-serif"},children:"\xD7"}):null]})}function Ft({value:e,options:t,label:o,onCommit:r,disabled:a=false,width:s=72,inputStyle:d,testId:m}){let[f,g]=useState(e),[l,y]=useState(false),[I,K]=useState({top:0,left:0,width:s}),X=useRef(null),j=useRef(null),b=useRef(null);useEffect(()=>g(e),[e]);let w=useCallback(()=>y(false),[]);useEffect(()=>{if(!l||!X.current)return;let k=X.current.getBoundingClientRect();K({top:k.bottom+4,left:k.left,width:Math.max(k.width,s)});},[l,s]),useEffect(()=>{if(!l)return;let k=h=>{let T=h.target;!X.current?.contains(T)&&!j.current?.contains(T)&&w();},N=h=>{h.key==="Escape"&&(g(e),w());};return document.addEventListener("mousedown",k),document.addEventListener("keydown",N),()=>{document.removeEventListener("mousedown",k),document.removeEventListener("keydown",N);}},[l,w,e]);let B=useCallback(()=>{!a&&r&&f.trim()&&r(f.trim()),g(e);},[a,r,f,e]);return jsxs("div",{ref:X,style:{display:"inline-flex",alignItems:"center",width:s,height:28,border:`1px solid ${A.border}`,borderRadius:4,background:a?"rgba(255,255,255,0.5)":A.surface,opacity:a?.48:1,boxSizing:"border-box",flex:"0 0 auto"},children:[jsx("input",{ref:b,"data-testid":m,role:"combobox","aria-label":o,"aria-autocomplete":"list","aria-expanded":l,disabled:a,value:f,onFocus:k=>{a||(y(true),k.currentTarget.select());},onChange:k=>g(k.target.value),onKeyDown:k=>{k.key==="Enter"?(B(),w(),k.currentTarget.blur()):k.key==="ArrowDown"&&(y(true),k.preventDefault());},onBlur:()=>{requestAnimationFrame(()=>{j.current?.contains(document.activeElement)||B();});},style:{appearance:"none",width:"calc(100% - 22px)",height:26,padding:"0 2px 0 7px",border:0,outline:0,background:"transparent",color:A.text,font:"500 13px ui-sans-serif, system-ui, sans-serif",boxSizing:"border-box",...d}}),jsx("button",{type:"button",disabled:a,tabIndex:-1,"aria-label":o,title:o,onMouseDown:k=>k.preventDefault(),onClick:()=>{a||(y(k=>!k),b.current?.focus());},style:{appearance:"none",display:"grid",placeItems:"center",width:21,height:26,padding:0,border:0,background:"transparent",color:A.muted,cursor:a?"default":"pointer"},children:jsx(ee,{name:"chevronDown",size:14})}),l&&!a&&jsx("div",{ref:j,role:"listbox","aria-label":o,style:{position:"fixed",top:I.top,left:I.left,zIndex:1e4,width:I.width,maxHeight:260,overflowY:"auto",padding:4,border:`1px solid ${A.border}`,borderRadius:6,background:A.surface,boxShadow:"0 4px 16px rgba(60, 64, 67, 0.24)",boxSizing:"border-box"},children:t.map(k=>jsx("button",{type:"button",role:"option","aria-selected":k.value===e,onMouseDown:N=>N.preventDefault(),onClick:()=>{g(k.label),r?.(k.value),w();},style:{appearance:"none",display:"block",width:"100%",minHeight:28,padding:"4px 7px",border:0,borderRadius:3,background:k.value===e?A.active:"transparent",color:A.text,cursor:"pointer",font:"400 13px ui-sans-serif, system-ui, sans-serif",textAlign:"left"},children:k.label},k.value))})]})}var St=[{geometry:"rect",labelKey:"toolbar.shapes.rect"},{geometry:"roundRect",labelKey:"toolbar.shapes.roundRect"},{geometry:"ellipse",labelKey:"toolbar.shapes.ellipse"},{geometry:"triangle",labelKey:"toolbar.shapes.triangle"},{geometry:"rtTriangle",labelKey:"toolbar.shapes.rtTriangle"},{geometry:"diamond",labelKey:"toolbar.shapes.diamond"},{geometry:"parallelogram",labelKey:"toolbar.shapes.parallelogram"},{geometry:"trapezoid",labelKey:"toolbar.shapes.trapezoid"},{geometry:"pentagon",labelKey:"toolbar.shapes.pentagon"},{geometry:"hexagon",labelKey:"toolbar.shapes.hexagon"},{geometry:"octagon",labelKey:"toolbar.shapes.octagon"},{geometry:"star5",labelKey:"toolbar.shapes.star5"},{geometry:"rightArrow",labelKey:"toolbar.shapes.rightArrow"},{geometry:"leftArrow",labelKey:"toolbar.shapes.leftArrow"},{geometry:"upArrow",labelKey:"toolbar.shapes.upArrow"},{geometry:"downArrow",labelKey:"toolbar.shapes.downArrow"},{geometry:"chevron",labelKey:"toolbar.shapes.chevron"}],_r=[.5,.75,1,1.25,1.5,2],Ur=["Arial","Calibri","Cambria","Georgia","Roboto","Times New Roman","Verdana"],jr=[8,9,10,11,12,14,16,18,20,24,28,36,48,72],Xr=[{value:"l",icon:"alignLeft",labelKey:"toolbar.align.left",testId:"left"},{value:"ctr",icon:"alignCenter",labelKey:"toolbar.align.center",testId:"center"},{value:"r",icon:"alignRight",labelKey:"toolbar.align.right",testId:"right"},{value:"just",icon:"alignJustify",labelKey:"toolbar.align.justify",testId:"justify"}],Gr=[1,2,3,4,8],Zr=[0,10,17,25,33,50],$r=[0,10,20,30,40,50,60,70,80,90,100];function Yr(e){let t={};for(let o of Object.keys(e))e[o]!==void 0&&(t[o]=e[o]);return t}function Vr(e){let t=useContext(rt);return t?{...t,...Yr(e)}:e}function xo(e,t,o){return o>0?t.find(r=>r>e)??e+1:[...t].reverse().find(r=>r<e)??Math.max(1,e-1)}function qr(e){if(!e)return null;if(e.adj!==void 0)return ["adj",e.adj];if(e.adj1!==void 0)return ["adj1",e.adj1];let t=Object.keys(e).sort()[0];return t?[t,e[t]]:null}function At(e){let{t}=Te(),{currentFormatting:o={},textSelectionActive:r=false,onFormat:a,currentShapeFormatting:s={},shapeSelectionActive:d=false,onShapeFormat:m,onInsertSlide:f,slideLayouts:g=[],currentLayoutPartPath:l,onSave:y,onExportPng:I,onUndo:K,onRedo:X,canUndo:j=false,canRedo:b=false,zoom:w="fit",onZoomChange:B,activeTool:k="select",onToolChange:N,fontFamilies:h=Ur,fontSizes:T=jr,disabled:O=false,className:Z,style:Se,children:se}=Vr(e),ne=useRef(null),[Ae,we]=useState(Number.POSITIVE_INFINITY),L=!O&&r&&!!a,oe=!O&&d&&!!m,Be=!O&&!!f,je=!O&&!!N,v=o.fontSize??24,Ke=t("toolbar.fit"),x=w==="fit"?Ke:`${Math.round(w*100)}%`,V=qr(s.adjustments),q=s.geometry==="roundRect"&&V?.[0]==="adj";useEffect(()=>{let C=ne.current;if(!C)return;let R=()=>we(C.clientWidth);R();let ve=new ResizeObserver(R);return ve.observe(C),()=>ve.disconnect()},[]);let ce=useMemo(()=>[{value:Ke,label:Ke},..._r.map(C=>({value:`${C*100}%`,label:`${C*100}%`}))],[Ke]),dt=useMemo(()=>T.map(C=>({value:String(C),label:String(C)})),[T]),$=C=>{L&&a?.(C);},he=C=>{oe&&m?.(C);},ae=[{key:"file",width:72,node:jsxs(Me,{label:t("toolbar.groups.file"),children:[jsx(Pe,{title:t("toolbar.save"),disabled:O||!y,onClick:y,testId:"pptx-save",children:jsx(ee,{name:"save",size:18})}),jsx(Pe,{title:t("toolbar.exportPng"),disabled:O||!I,onClick:I,testId:"pptx-export-png",children:jsx(ee,{name:"image",size:18})})]})},{key:"new-slide",width:59,node:jsxs(Me,{label:t("toolbar.groups.slides"),children:[jsx(Pe,{title:t("toolbar.newSlide"),disabled:!Be,onClick:()=>f?.(),style:{borderRadius:"4px 0 0 4px"},testId:"pptx-new-slide",children:jsx(ee,{name:"newSlide"})}),jsx(qe,{title:t("toolbar.newSlideWithLayout"),disabled:!Be||g.length===0,menuWidth:230,testId:"pptx-new-slide-layout",style:{minWidth:20,width:20,padding:0,borderRadius:"0 4px 4px 0"},trigger:jsx(ee,{name:"chevronDown",size:13}),children:C=>jsx(Fragment,{children:g.map((R,ve)=>jsx(it,{label:R.label??t("toolbar.layoutOption",{number:ve+1}),selected:(R.partPath??null)===(l??null),onClick:()=>f?.(R.partPath),close:C},R.partPath??`default-${ve}`))})})]})},{key:"history",width:75,node:jsxs(Fragment,{children:[jsx(_e,{}),jsxs(Me,{label:t("toolbar.groups.history"),children:[jsx(Pe,{title:t("toolbar.undoShortcut"),disabled:O||!j||!K,onClick:K,testId:"pptx-undo",children:jsx(ee,{name:"undo"})}),jsx(Pe,{title:t("toolbar.redoShortcut"),disabled:O||!b||!X,onClick:X,testId:"pptx-redo",children:jsx(ee,{name:"redo"})})]})]})},{key:"zoom",width:82,node:jsx(Me,{label:t("toolbar.groups.zoom"),children:jsx(Ft,{value:x,options:ce,label:t("toolbar.zoomValue",{value:x}),disabled:O||!B,onCommit:C=>{if(C===Ke){B?.("fit");return}let R=Number.parseFloat(C.replace("%",""));Number.isFinite(R)&&R>=25&&R<=400&&B?.(R/100);},width:76,testId:"pptx-zoom"})})},{key:"tools",width:127,node:jsxs(Fragment,{children:[jsx(_e,{}),jsxs(Me,{label:t("toolbar.groups.tools"),children:[jsx(Pe,{title:t("toolbar.selectToolShortcut"),active:k==="select",disabled:!je,onClick:()=>N?.("select"),testId:"pptx-tool-select",children:jsx(ee,{name:"select"})}),jsx(Pe,{title:t("toolbar.textBoxTool"),active:k==="textBox",disabled:!je,onClick:()=>N?.("textBox"),testId:"pptx-tool-text-box",children:jsx(ee,{name:"textBox"})}),jsx(qe,{title:t("toolbar.shapeTool"),active:k.startsWith("shape:"),disabled:!je,menuWidth:264,testId:"pptx-tool-shape",style:{minWidth:46,padding:"0 4px"},trigger:jsxs(Fragment,{children:[jsx(ee,{name:"shape"}),jsx(ee,{name:"chevronDown",size:11})]}),children:C=>jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(5, 44px)",gap:4,padding:2},children:St.map(R=>jsx("button",{type:"button",role:"menuitem","data-testid":`pptx-shape-${R.geometry}`,"aria-label":t(R.labelKey),title:t(R.labelKey),onClick:()=>{N?.(`shape:${R.geometry}`),C();},style:{appearance:"none",display:"grid",placeItems:"center",width:44,height:38,padding:5,border:`1px solid ${A.border}`,borderRadius:4,background:k===`shape:${R.geometry}`?A.active:A.surface,color:A.text,cursor:"pointer"},children:jsx(Jr,{geometry:R.geometry})},R.geometry))})})]})]})},{key:"font-family",width:137,node:jsxs(Fragment,{children:[jsx(_e,{}),jsx(Me,{label:t("toolbar.groups.font"),children:jsx(qe,{title:t("toolbar.fontFamily"),disabled:!L,menuWidth:210,testId:"pptx-font-family",style:{width:120,justifyContent:"space-between"},trigger:jsxs(Fragment,{children:[jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:o.fontFamily??t("toolbar.mixed")}),jsx(ee,{name:"chevronDown",size:13})]}),children:C=>jsx(Fragment,{children:h.map(R=>jsx(it,{label:R,selected:o.fontFamily===R,onClick:()=>$({type:"fontFamily",value:R}),close:C},R))})})})]})},{key:"font-size",width:116,node:jsxs(Me,{label:t("toolbar.groups.font"),children:[jsx(Pe,{title:t("toolbar.decreaseFontSize"),disabled:!L,onClick:()=>$({type:"fontSize",value:xo(v,T,-1)}),children:jsx(ee,{name:"remove"})}),jsx(Ft,{value:o.fontSize===void 0?"":String(v),options:dt,label:t("toolbar.fontSize"),disabled:!L,onCommit:C=>{let R=Number.parseFloat(C);Number.isFinite(R)&&R>=1&&R<=400&&$({type:"fontSize",value:R});},width:50,inputStyle:{textAlign:"center"},testId:"pptx-font-size"}),jsx(Pe,{title:t("toolbar.increaseFontSize"),disabled:!L,onClick:()=>$({type:"fontSize",value:xo(v,T,1)}),children:jsx(ee,{name:"add"})})]})},{key:"text",width:133,node:jsxs(Fragment,{children:[jsx(_e,{}),jsxs(Me,{label:t("toolbar.groups.text"),children:[jsx(Pe,{title:t("toolbar.boldShortcut"),active:o.bold,disabled:!L,onClick:()=>$("bold"),testId:"pptx-bold",children:jsx(ee,{name:"bold"})}),jsx(Pe,{title:t("toolbar.italicShortcut"),active:o.italic,disabled:!L,onClick:()=>$("italic"),testId:"pptx-italic",children:jsx(ee,{name:"italic"})}),jsx(Pe,{title:t("toolbar.underlineShortcut"),active:o.underline,disabled:!L,onClick:()=>$("underline"),testId:"pptx-underline",children:jsx(ee,{name:"underline"})}),jsx(Dt,{value:o.textColor??"#000000",label:t("toolbar.textColor"),disabled:!L,onChange:C=>$({type:"textColor",value:C}),testId:"pptx-text-color"})]})]})},{key:"align",width:126,node:jsxs(Fragment,{children:[jsx(_e,{}),jsx(Me,{label:t("toolbar.groups.alignment"),children:Xr.map(C=>jsx(Pe,{title:t(C.labelKey),active:o.align===C.value,disabled:!L,onClick:()=>$({type:"align",value:C.value}),testId:`pptx-align-${C.testId}`,children:jsx(ee,{name:C.icon})},C.value))})]})},{key:"shape-formatting",width:V?244:172,node:jsxs(Fragment,{children:[jsx(_e,{}),jsxs(Me,{label:t("toolbar.groups.shape"),children:[jsx(Dt,{value:s.fillColor??"#d9eaf7",label:t("toolbar.fillColor"),clearLabel:t("toolbar.noFill"),icon:"fillColor",none:!s.fillColor,disabled:!oe,onChange:C=>he({type:"fillColor",value:C}),onClear:()=>he({type:"fillColor",value:null}),testId:"pptx-shape-fill"}),jsx(Dt,{value:s.strokeColor??"#202124",label:t("toolbar.borderColor"),clearLabel:t("toolbar.noBorder"),icon:"borderColor",none:!s.strokeColor,disabled:!oe,onChange:C=>he({type:"strokeColor",value:C}),onClear:()=>he({type:"strokeColor",value:null}),testId:"pptx-shape-border-color"}),jsx(qe,{title:t("toolbar.borderWidth"),disabled:!oe,menuWidth:170,testId:"pptx-shape-border-width",trigger:jsx(ee,{name:"borderWidth"}),children:C=>jsxs(Fragment,{children:[jsx(it,{label:t("toolbar.noBorder"),selected:s.strokeWidthPt===null,onClick:()=>he({type:"strokeWidth",value:null}),close:C}),Gr.map(R=>jsx(it,{label:t("toolbar.borderWidthValue",{width:R}),selected:s.strokeWidthPt===R,icon:jsx("span",{"aria-hidden":"true",style:{width:18,borderTop:`${Math.min(R,5)}px solid currentColor`}}),onClick:()=>he({type:"strokeWidth",value:R}),close:C},R))]})}),V?jsx(Ft,{value:`${Math.round(V[1]*100)}%`,options:(q?Zr:$r).map(C=>({value:String(C),label:`${C}%`})),label:t(q?"toolbar.cornerRadius":"toolbar.shapeAdjustment"),disabled:!oe,onCommit:C=>{let R=Number.parseFloat(C.replace("%",""));if(Number.isFinite(R)){let ve=q?50:100;he({type:"adjust",name:V[0],value:Math.max(0,Math.min(ve,R))/100});}},width:68,inputStyle:{textAlign:"center"},testId:q?"pptx-shape-corner-radius":"pptx-shape-adjustment"}):null]})]})}];se&&ae.push({key:"custom",width:40,node:se});let Ce=Math.max(0,Ae-48),ct=0,Qe=ae.length;for(let C=0;C<ae.length;C++)if(ct+=ae[C].width,ct>Ce){Qe=C;break}let It=ae.slice(0,Qe),et=ae.slice(Qe);return jsxs("div",{ref:ne,className:Z,role:"toolbar","aria-label":t("toolbar.label"),"data-testid":"pptx-formatting-toolbar",style:{display:"flex",alignItems:"center",minWidth:0,minHeight:36,margin:"0 8px 5px",padding:"4px 7px",borderRadius:18,background:A.rail,color:A.text,overflow:"hidden",boxSizing:"border-box",...Se},children:[It.map(C=>jsx("span",{style:{display:"contents"},children:C.node},C.key)),jsx("span",{style:{marginLeft:"auto",flex:"0 0 auto"},children:jsx(qe,{title:t("toolbar.more"),disabled:et.length===0,menuWidth:390,testId:"pptx-toolbar-more",trigger:jsx(ee,{name:"more"}),children:()=>jsx("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:2},children:et.map(C=>jsx("span",{style:{display:"contents"},children:C.node},C.key))})})})]})}function Jr({geometry:e}){let t={rect:"M3 5h18v14H3Z",roundRect:"M7 5h10a4 4 0 0 1 4 4v6a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4V9a4 4 0 0 1 4-4Z",ellipse:"M3 12a9 7 0 1 0 18 0 9 7 0 1 0-18 0",triangle:"m12 4 9 16H3Z",rtTriangle:"M4 4v16h16Z",diamond:"m12 3 9 9-9 9-9-9Z",parallelogram:"M7 5h14l-4 14H3Z",trapezoid:"M7 5h10l4 14H3Z",pentagon:"m12 3 9 7-4 11H7L3 10Z",hexagon:"m7 4 10 0 5 8-5 8H7l-5-8Z",octagon:"m7 3 10 0 4 4v10l-4 4H7l-4-4V7Z",star5:"m12 2.5 2.8 6 6.5.6-5 4.3 1.6 6.4-5.7-3.4-5.7 3.4 1.6-6.4-5-4.3 6.5-.6Z",rightArrow:"M3 8h11V4l7 8-7 8v-4H3Z",leftArrow:"m21 8H10V4l-7 8 7 8v-4h11Z",upArrow:"M8 21V10H4l8-7 8 7h-4v11Z",downArrow:"M8 3v11H4l8 7 8-7h-4V3Z",chevron:"M4 4h9l7 8-7 8H4l7-8Z"}[e];return jsx("svg",{width:"30",height:"24",viewBox:"0 0 24 24",fill:"rgba(60, 64, 67, 0.08)",stroke:"currentColor",strokeWidth:"1.4",strokeLinejoin:"round","aria-hidden":"true",children:jsx("path",{d:t})})}function Qr({children:e,className:t,style:o,...r}){return jsx(rt.Provider,{value:r,children:jsx("div",{className:t,"data-testid":"pptx-editor-toolbar",style:{display:"flex",flexDirection:"column",flex:"0 0 auto",...o},children:e})})}var vt=Qr;vt.Toolbar=At;function Io({handle:e,slideCount:t,startIndex:o,resolveImage:r,label:a,counterLabel:s,exitLabel:d,previousLabel:m,nextLabel:f,onExit:g,onError:l}){let y=useRef(null),I=useRef(null),K=useRef(null),X=useRef({onExit:g,onError:l});X.current={onExit:g,onError:l};let[j,b]=useState(o),w=Math.max(0,Math.min(j,t-1)),[B,k]=useState({width:0,height:0}),N=h=>b(Math.max(0,Math.min(w+h,t-1)));return useEffect(()=>{b(h=>Math.max(0,Math.min(h,t-1))),t===0&&X.current.onExit();},[t]),useEffect(()=>{let h=I.current,T=y.current,O=document.activeElement,Z=true;h.showModal(),h.focus(),T.requestFullscreen?.().then(()=>{Z?(h.close(),h.showModal(),h.focus()):document.fullscreenElement===T&&document.exitFullscreen().catch(()=>{});}).catch(()=>{});let Se=()=>{document.fullscreenElement||X.current.onExit();},se=()=>k({width:window.innerWidth,height:window.innerHeight});return se(),window.addEventListener("resize",se),document.addEventListener("fullscreenchange",Se),()=>{Z=false,window.removeEventListener("resize",se),document.removeEventListener("fullscreenchange",Se),document.fullscreenElement===T&&document.exitFullscreen().catch(()=>{}),h.close(),O instanceof HTMLElement&&O.isConnected&&O.focus();}},[]),useEffect(()=>{let h=K.current;if(!h||t===0||B.width<=0||B.height<=0)return;let T=false;return (async()=>{let Z=e.layoutSlide(w),Se=document.createElement("canvas"),se=Se.getContext("2d");if(!se)return;let ne=Math.min(B.width/Z.width,B.height/Z.height),Ae=window.devicePixelRatio||1;sizeCanvasForSlide(Se,Z,Ae,ne),await paintSlide(se,Z,Ae,ne,{resolveImage:r}),!T&&(sizeCanvasForSlide(h,Z,Ae,ne),h.getContext("2d")?.drawImage(Se,0,0));})().catch(Z=>{T||(X.current.onError(Z),X.current.onExit());}),()=>{T=true;}},[e,w,t,r,B]),jsx("div",{ref:y,children:jsxs("dialog",{ref:I,"aria-label":a,tabIndex:-1,style:Je.presentationOverlay,onCancel:h=>{h.preventDefault(),g();},onClick:h=>{h.target===I.current&&N(1);},onKeyDown:h=>{if(!(h.altKey||h.ctrlKey||h.metaKey)){switch(h.key){case " ":if(h.target instanceof HTMLElement&&h.target.closest("button"))return;N(1);break;case "ArrowRight":case "ArrowDown":case "PageDown":N(1);break;case "ArrowLeft":case "ArrowUp":case "PageUp":N(-1);break;case "Home":b(0);break;case "End":b(Math.max(0,t-1));break;case "Escape":g();break;default:return}h.preventDefault(),h.stopPropagation();}},children:[jsx("canvas",{ref:K,style:Je.presentationCanvas}),jsx("button",{type:"button",onClick:g,"aria-label":d,title:d,style:Je.presentationExit,children:jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":"true",children:jsx("path",{d:"M6 6 18 18M18 6 6 18"})})}),jsxs("div",{style:Je.presentationControls,children:[jsx("button",{type:"button",onClick:()=>N(-1),disabled:w===0,"aria-label":m,style:Je.presentationNavButton,children:jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4","aria-hidden":"true",children:jsx("path",{d:"m15 6-6 6 6 6"})})}),jsx("span",{style:Je.presentationCounter,"aria-live":"polite",children:s(w+1,t)}),jsx("button",{type:"button",onClick:()=>N(1),disabled:w>=t-1,"aria-label":f,style:Je.presentationNavButton,children:jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4","aria-hidden":"true",children:jsx("path",{d:"m9 6 6 6-6 6"})})})]})]})})}var Je={presentationOverlay:{position:"fixed",margin:0,padding:0,border:0,width:"100vw",height:"100vh",maxWidth:"none",maxHeight:"none",inset:0,zIndex:2147483e3,display:"flex",alignItems:"center",justifyContent:"center",background:"#000000",cursor:"pointer"},presentationCanvas:{display:"block",pointerEvents:"none"},presentationExit:{position:"absolute",top:16,right:16,display:"inline-flex",alignItems:"center",justifyContent:"center",width:36,height:36,border:0,borderRadius:999,background:"rgba(255, 255, 255, 0.14)",color:"#ffffff",cursor:"pointer"},presentationControls:{position:"absolute",bottom:20,left:"50%",transform:"translateX(-50%)",display:"flex",alignItems:"center",gap:12,padding:"6px 14px",borderRadius:999,background:"rgba(255, 255, 255, 0.12)"},presentationNavButton:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,border:0,borderRadius:999,background:"rgba(255, 255, 255, 0.14)",color:"#ffffff",cursor:"pointer"},presentationCounter:{minWidth:64,color:"#ffffff",fontSize:12,fontWeight:600,textAlign:"center"}};function wo(e,t=12){return {visible:e.slice(0,t),overflow:Math.max(0,e.length-t)}}function To(e,t,o=4){let r=new Map;for(let a of e){let s=a.state.cursor?.slideId;if(!s||!t.has(s))continue;let d=r.get(s)??{visible:[],overflow:0};d.visible.length<o?d.visible.push(a):d.overflow+=1,r.set(s,d);}return r}function Co(e,t,o,r=24){let a=new Map,s=0;for(let d of e){let m=d.state.cursor;if(m?.slideId!==t||!m.shapeId||!o.has(m.shapeId))continue;let f=a.get(m.shapeId);f?(f.count+=1,d.cursorMovedAt>f.peer.cursorMovedAt&&(f.peer=d)):a.size<r?a.set(m.shapeId,{shapeId:m.shapeId,peer:d,count:1}):s+=1;}return {visible:[...a.values()],overflow:s}}function zt(e,t,o,r){let a=ii(e,t,o,r),s=at(a,"underline");return {bold:at(a,"bold"),italic:at(a,"italic"),underline:s===void 0?void 0:s!=="none",fontSize:at(a,"fontSizePt"),textColor:at(a,"color"),fontFamily:at(a,"fontFamily")}}function Eo(e,t){return zt(e,0,e.length,t)}var ti={left:"l",center:"ctr",right:"r",justify:"just"},ni={l:"l",ctr:"ctr",r:"r",just:"just",justLow:"just",dist:"just",thaiDist:"just"};function pn(e,t,o,r){let a=ri(e),s=a[a.length-1]?.end??0,d=Math.min(Math.min(o,r),s),m=Math.max(o,r),f=a.map((l,y)=>({range:l,index:y})).filter(({range:l})=>d===m?d>=l.start&&d<=l.end:d<=l.end&&m>l.start).map(({index:l})=>oi(e,t,l));if(f.length===0)return;let g=f[0];return f.every(l=>l===g)?g:void 0}function oi(e,t,o){let r=e.paragraphs[o]?.alignment;if(r)return ni[r]??"l";let a=t?.paragraphs[o]?.align;return a?ti[a]??"l":"l"}function ri(e){let t=0;return e.paragraphs.map(o=>{let r=t+o.runs.reduce((s,d)=>s+d.text.length,0),a={start:t,end:r};return t=r+1,a})}function Mo(e,t,o,r){let a=zt(e,t,o,r);return {bold:a.bold??r.bold,italic:a.italic??r.italic,underline:a.underline===void 0?r.underline:a.underline?"sng":"none",fontSizePt:a.fontSize??r.fontSizePt,color:a.textColor??r.color,fontFamily:a.fontFamily??r.fontFamily}}function ii(e,t,o,r){let a=ai(e,r);if(a.length===0)return [r];let s=Math.min(t,o),d=Math.max(t,o);if(s===d){let g=a.find(y=>s>=y.start&&s<y.end);return g?[g.style]:[[...a].reverse().find(y=>y.end<=s)?.style??a[0].style]}let m=a.filter(g=>g.end>s&&g.start<d).map(g=>g.style);return m.length>0?m:[[...a].reverse().find(g=>g.end<=s)?.style??a[0].style]}function ai(e,t){let o=[],r=0;return e.paragraphs.forEach((a,s)=>{for(let d of a.runs){let m=r;r+=d.text.length,r>m&&o.push({start:m,end:r,style:si(d.style,t)});}s<e.paragraphs.length-1&&(r+=1);}),o}function si(e,t){return {bold:e.bold??t.bold,italic:e.italic??t.italic,underline:e.underline??t.underline,fontSizePt:e.fontSizePt??t.fontSizePt,color:e.color??t.color,fontFamily:e.fontFamily??t.fontFamily}}function at(e,t){let o=e[0]?.[t];return e.every(r=>r[t]===o)?o:void 0}function Ro(e){let t=e?.fill?.type==="none"?null:ko(e?.resolvedFillColor),o=ko(e?.resolvedOutlineColor);return {geometry:e?.geometry,fillColor:t,strokeColor:o,strokeWidthPt:o&&e?.outline?.width!==void 0?e.outline.width/12700:o?1:null,adjustments:e?.adjustValues??{}}}function ko(e){if(!e)return null;let t=e.replace(/^#/,"");return /^[0-9a-f]{6}$/i.test(t)?`#${t}`:null}var Lo=new Intl.Segmenter(void 0,{granularity:"word"});function fn(e,t,o){return o==="word"?li(e,t):di(e,t)}function li(e,t){let o=hn(e,t),r=[...Lo.segment(e)],a=r.find(s=>o>=s.index&&o<s.index+s.segment.length)??r[r.length-1];return a?{start:a.index,end:a.index+a.segment.length}:{start:o,end:o}}function di(e,t){let o=hn(e,t),r=e.lastIndexOf(`
2
+ `,Math.max(0,o-1))+1,a=e.indexOf(`
3
+ `,o);return {start:r,end:a===-1?e.length:a}}function Do(e,t){return t.start<e.start?{anchor:e.end,focus:t.start}:t.end>e.end?{anchor:e.start,focus:t.end}:{anchor:e.start,focus:e.end}}function hn(e,t){return Number.isFinite(t)?Math.max(0,Math.min(e.length,Math.trunc(t))):0}function Fo(e,t){return e.shapeId===t.shapeId&&e.position===t.position&&e.lineIndex===t.lineIndex}function mn(e,t){return e[Pt(e,t)]?.caretStops.find(r=>r.position===t.position)?.x}function Ao(e,t,o,r){if(e.length===0)return {position:t.position,lineIndex:0};let a=Pt(e,t),s=a+(o==="up"?-1:1),d=e[s];if(!d)return {position:t.position,lineIndex:a};let m=r??mn(e,t);return m===void 0?{position:d.start,lineIndex:s}:{position:d.caretStops.reduce((g,l)=>g===null||Math.abs(l.x-m)<Math.abs(g.x-m)?l:g,null)?.position??d.start,lineIndex:s}}function Ht(e,t,o){let r=Pt(e,t),a=e[r];return a?{position:o==="start"?a.start:a.end,lineIndex:r}:{position:t.position,lineIndex:r}}function Bo(e,t,o){let r=hn(e,t),a=[...Lo.segment(e)].filter(d=>d.isWordLike).flatMap(d=>[d.index,d.index+d.segment.length]),s=o<0?a.filter(d=>d<r):a.filter(d=>d>r);return s.length===0?o<0?0:e.length:o<0?Math.max(...s):Math.min(...s)}function Pt(e,t){let o=t.lineIndex;if(o!==void 0&&o>=0&&o<e.length&&t.position>=e[o].start&&t.position<=e[o].end)return o;let r=-1;for(let a=0;a<e.length;a+=1){let s=e[a];t.position>=s.start&&t.position<=s.end&&(r=a);}return r===-1?Math.max(0,e.length-1):r}var mi="application/vnd.openxmlformats-officedocument.presentationml.presentation";function gi(e,t){return `${(e??"presentation.pptx").replace(/\.pptx$/i,"")}-slide-${t+1}.png`}function Ho(e,t,o){let r=new Blob([new Uint8Array(e)],{type:o}),a=URL.createObjectURL(r),s=document.createElement("a");s.href=a,s.download=t,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(a);}var bi=530,Wt=9,Nt={bold:false,italic:false,underline:"none",fontSizePt:24,color:"#111827",fontFamily:"Arial"};function xi({i18n:e,...t}){return jsx(Ct,{i18n:e,children:jsx(yi,{...t})})}function yi({file:e,fonts:t,clientId:o,collaboration:r,className:a,fileName:s,onReady:d,onChange:m,onError:f,onSave:g}){let{t:l}=Te(),y=l("errors.decodeSlideImage"),I=r?.clientId??o,K=r?.initialUpdate,X=r?.onReplica,j=r?.presence,b=useRef(null),w=useRef(null),B=useRef(d),k=useRef(m),N=useRef(f),h=useRef(null),T=useRef(null),O=useRef(null),[Z,Se]=useState(false),se=useRef(null),ne=useRef(null),[Ae,we]=useState(null),L=useRef(null),oe=useRef(null),Be=useRef(new Map),je=Ci(t),[v,Ke]=useState(null),[x,V]=useState(null),[q,ce]=useState(null),[dt,$]=useState(null),[he,ae]=useState(null),[Ce,ct]=useState(Nt),[Qe,It]=useState({canUndo:false,canRedo:false}),[et,C]=useState("fit"),[R,ve]=useState("select"),[xn,Kt]=useState(null),[ut,_o]=useState({width:0,height:0}),[yn,_t]=useState(null),[Uo,wt]=useState(false),[Ut,Sn]=useState(null),[Xe,jt]=useState([]),[jo,Xt]=useState(false),[Gt,Zt]=useState([]),[vn,pt]=useState(false),Pn=useRef(null),re=ao(b.current,Gt,v?.snapshot,v?.slideIndex??0),[Xo,Go]=useState(null),Zo=useCallback(n=>st(n,b,Be,y),[y]);useEffect(()=>{re.reviewing&&(V(null),ce(null),L.current=null,ne.current=null,we(null),$(null),ae(null));},[re.reviewing]),B.current=d,k.current=m,N.current=f,w.current=v;let U=useCallback(n=>{let i=n instanceof Error?n:new Error(String(n));_t(i.message),N.current?.(i);},[]),le=useCallback((n,i=false,u=false)=>{let c=b.current;if(!c)return null;try{se.current=null;let p=c.snapshot(),P=wi(n??w.current?.slideIndex??0,p.slides.length),E=new Map;for(let z=0;z<p.slides.length;z+=1){let ye=p.slides[z],Le=w.current?.thumbnails.get(ye.id);z!==P&&Le&&!u?E.set(ye.id,Le):z!==P&&E.set(ye.id,c.layoutSlide(z));}let M=p.slides.length>0?c.layoutSlide(P):null;M&&E.set(p.slides[P].id,M);let de={snapshot:p,slideIndex:P,frame:M,thumbnails:E},Y=p.slides[P];V(z=>z&&Y&&Ee(Y.shapes,z.shapeId)?z:null),ce(z=>z&&Y?.id===z.slideId&&Ee(Y.shapes,z.shapeId)?z:null);let G=L.current;G&&(!Y||Y.id!==G.slideId||G.kind!=="textBox"&&G.kind!=="shapeInsert"&&!Ee(Y.shapes,G.shapeId))&&(L.current=null,oe.current=null,$(null),ae(null));let ue=ne.current;return ue&&!$n(Y,ue)&&(ne.current=null,we(null)),w.current=de,Ke(de),It({canUndo:c.canUndo(),canRedo:c.canRedo()}),Zt(c.listProposals()),_t(null),i&&k.current?.(p),de}catch(p){return U(p),null}},[U]),In=useCallback(()=>{le(void 0,false,true);},[le]),wn=useCallback((n,i,u)=>{let c=w.current?.snapshot.slides.findIndex(E=>E.id===n)??-1;if(c<0)return;let p=le(c),P=p?.snapshot.slides[p.slideIndex];V(null),ce(i&&P&&Ee(P.shapes,i)?{slideId:n,shapeId:i}:null),u&&re.select(u),re.setEnabled(true);},[le,re.select,re.setEnabled]),tt=useCallback(()=>{try{Zt(b.current?.listProposals()??[]);}catch(n){U(n);}},[U]),Tn=useCallback((n,i=false)=>{try{b.current?.acceptProposal(n,{force:i}),le(void 0,!0,!0);}catch(u){tt(),u instanceof StaleProposalError||U(u);}},[le,tt,U]),Cn=useCallback(n=>{try{b.current?.rejectProposal(n),tt();}catch(i){U(i);}},[tt,U]);useEffect(()=>{let n=false,i=null,u=[],c=()=>{};if(b.current?.dispose(),b.current=null,Sn(null),w.current=null,Ke(null),V(null),ce(null),$(null),ae(null),we(null),It({canUndo:false,canRedo:false}),ve("select"),Xt(false),Zt([]),pt(false),L.current=null,ne.current=null,se.current=null,oe.current=null,_t(null),Be.current.clear(),!!e)return wt(true),Promise.all([initWasm(),Fi(je)]).then(([,p])=>{if(u=p,n){No(u);return}try{i=openPresentation(e,{clientId:I,fonts:je,initialUpdate:K}),b.current=i,c=i.onUpdate((E,M)=>{M==="remote"&&le(void 0,!0,!0);}),le(0),wt(!1),Sn(i);let P=i;B.current?.({handle:P,refresh:In,refreshProposals:tt,save:()=>P.save(),focus:()=>h.current?.focus()});}catch(P){wt(false),U(P);}},p=>{n||(wt(false),U(p));}),()=>{n=true,c(),i?.dispose(),b.current===i&&(b.current=null),No(u);}},[I,K,e,je,In,le,U]),useEffect(()=>{if(!(!X||!Ut))return X(Ut),()=>X(null)},[X,Ut]),useEffect(()=>Kt(null),[R]),useEffect(()=>{if(!j){jt([]);return}return jt(j.peers),j.onPresence(jt)},[j]),useEffect(()=>{let n=T.current;if(!n)return;let i=()=>_o({width:n.clientWidth,height:n.clientHeight});i();let u=new ResizeObserver(i);return u.observe(n),()=>u.disconnect()},[]);let $o=useMemo(()=>!v?.frame||ut.width<=0||ut.height<=0?1:Math.min((ut.width-40)/v.frame.width,(ut.height-40)/v.frame.height,1),[v?.frame,ut]),Q=et==="fit"?$o:et;useEffect(()=>{let n=O.current,i=v?.frame;if(!n||!i)return;let u=n.getContext("2d");if(!u)return;let c=window.devicePixelRatio||1;sizeCanvasForSlide(n,i,c,Q);let p=false;return paintSlide(u,i,c,Q,{resolveImage:P=>st(P,b,Be,y)}).catch(P=>{p||U(P);}),()=>{p=true;}},[y,v?.frame,U,Q]);let me=useMemo(()=>{if(!v?.frame||!q)return null;let n=v.snapshot.slides[v.slideIndex];return !n||n.id!==q.slideId?null:Ee(n.shapes,q.shapeId)},[v,q]),Fe=me?.textStories[0]?.id??null,Yo=useMemo(()=>Ro(me),[me]),Ge=useMemo(()=>v?.frame&&me?Ve(v.snapshot,v.frame,me):null,[v,me]),ft=useMemo(()=>{if(!v?.frame||!x||Ge)return null;let n=v.snapshot.slides[v.slideIndex],i=n?Ee(n.shapes,x.shapeId):null;return i?Ve(v.snapshot,v.frame,i):null},[v,Ge,x]),xe=v?.snapshot.slides[v.slideIndex],ht=xe?.id,$t=useMemo(()=>{if(xe){if(q?.slideId===xe.id)return q.shapeId;if(x)return tn(xe,x.shapeId)?.id}},[xe,x,q]);useEffect(()=>{j&&j.setCursor(ht?{slideId:ht,...$t?{shapeId:$t}:{}}:null);},[j,ht,$t]),useEffect(()=>()=>{j?.setCursor(null);},[j]);let mt=useMemo(()=>wo(Xe),[Xe]),Yt=useMemo(()=>{if(!v?.frame||!xe)return {visible:[],overflow:0};let n=Zn(xe.shapes),i=Co(Xe,xe.id,n),u=[],c=i.overflow;for(let p of i.visible){let P=n.get(p.shapeId);if(!P)continue;let E=Ve(v.snapshot,v.frame,P);E?u.push({peer:p.peer,peerCount:p.count,shapeId:p.shapeId,bounds:E}):c+=p.count;}return {visible:u,overflow:c}},[xe,v,Xe]),Vo=useMemo(()=>{let n=new Set(v?.snapshot.slides.map(i=>i.id));return To(Xe,n)},[v,Xe]);useEffect(()=>{let n=b.current;if(!(!n||!x))try{let i=n.story(x.storyId);ct(Mo(i,x.anchor,x.focus,Nt));}catch(i){U(i);}},[v,U,x]);let Ze=useMemo(()=>{if(x&&x.anchor===x.focus)return Ot(Ce);let n=b.current;if(!n)return Ot(Ce);try{return x?zt(n.story(x.storyId),x.anchor,x.focus,Nt):Fe?Eo(n.story(Fe),Nt):Ot(Ce)}catch{return Ot(Ce)}},[v,Fe,x,Ce]),qo=useMemo(()=>{let n=b.current,i=x?.storyId??Fe;if(!(!n||!i))try{let u=n.story(i),c=v?.frame?.primitives.find(p=>p.kind==="textBox"&&p.storyId===i);return x?pn(u,c,x.anchor,x.focus):pn(u,c,0,u.length)}catch{return}},[v,Fe,x]),Jo=useMemo(()=>{let n=new Set;for(let i of v?.snapshot.slides??[])n.add(i.layoutPartPath);return [...n].map(i=>({partPath:i}))},[v?.snapshot]),Qo=n=>{se.current=null,ne.current=null,we(null),V(null),ce(null),$(null),ae(null),L.current=null,oe.current=null,le(n),h.current?.focus();},er=(n,i)=>{let u=b.current,c=w.current;if(!u||!c?.frame)return;let p=c.snapshot.slides[c.slideIndex];if(!p)return;let P=Math.abs(i.x-n.x)>=6||Math.abs(i.y-n.y)>=6,E=P?Math.abs(i.x-n.x):c.frame.width*.36,M=P?Math.abs(i.y-n.y):c.frame.height*.12,de=Math.max(0,Math.min(P?Math.min(n.x,i.x):n.x,c.frame.width-E)),Y=Math.max(0,Math.min(P?Math.min(n.y,i.y):n.y,c.frame.height-M));try{let G=u.addTextBox(p.id,{name:l("objects.defaultTextBoxName"),rect:{x:Math.round(de*c.snapshot.widthEmu/c.frame.width),y:Math.round(Y*c.snapshot.heightEmu/c.frame.height),width:Math.round(Math.max(12,E)*c.snapshot.widthEmu/c.frame.width),height:Math.round(Math.max(12,M)*c.snapshot.heightEmu/c.frame.height)},text:"",style:Ce}),ue=le(void 0,!0);ve("select"),ce(null),$(null),ae(null),L.current=null,oe.current=null;let z=ue?.snapshot.slides[ue.slideIndex]?.shapes.find(Le=>Le.id===G.shapeId),ye=z?.textStories[0];ye&&(V({shapeId:z.id,storyId:ye.id,anchor:0,focus:0,focusLine:0}),h.current?.focus());}catch(G){U(G);}},tr=(n,i,u)=>{let c=b.current,p=w.current;if(!c||!p?.frame)return;let P=p.snapshot.slides[p.slideIndex],E=St.find(z=>z.geometry===n);if(!P||!E)return;let M=Math.abs(u.x-i.x)>=6||Math.abs(u.y-i.y)>=6,de=M?Math.abs(u.x-i.x):p.frame.width*.22,Y=M?Math.abs(u.y-i.y):p.frame.height*.18,G=Math.max(0,Math.min(M?Math.min(i.x,u.x):i.x-de/2,p.frame.width-de)),ue=Math.max(0,Math.min(M?Math.min(i.y,u.y):i.y-Y/2,p.frame.height-Y));try{let z=c.addShape(P.id,{name:l(E.labelKey),geometry:n,rect:{x:Math.round(G*p.snapshot.widthEmu/p.frame.width),y:Math.round(ue*p.snapshot.heightEmu/p.frame.height),width:Math.round(Math.max(12,de)*p.snapshot.widthEmu/p.frame.width),height:Math.round(Math.max(12,Y)*p.snapshot.heightEmu/p.frame.height)},fill:"#d9eaf7"}),ye=le(void 0,!0);ve("select"),V(null),ce({slideId:P.id,shapeId:z.shapeId}),$(null),ae(null),L.current=null,oe.current=null,ye&&h.current?.focus();}catch(z){U(z);}},nr=n=>{if(!n.isPrimary||n.button!==0)return;let i=b.current,u=w.current;if(!i||!u?.frame)return;let c=gt(n.currentTarget.getBoundingClientRect(),u.frame,n.clientX,n.clientY);if(!c)return;se.current=null,ne.current=null,we(null);let p=u.snapshot.slides[u.slideIndex],P=Ti(R);if((R==="textBox"||P)&&p){V(null),ce(null),$(null),ae({start:c,end:c}),oe.current=null,L.current=P?{kind:"shapeInsert",pointerId:n.pointerId,slideId:p.id,geometry:P,start:c,last:c}:{kind:"textBox",pointerId:n.pointerId,slideId:p.id,start:c,last:c},n.currentTarget.setPointerCapture(n.pointerId),h.current?.focus(),n.preventDefault();return}try{i.layoutSlide(u.slideIndex);let E=i.hitTest(c.x,c.y),M=E?.kind==="text"&&sn(u.frame,c,Q)==="shape"?{kind:"shape",shapeId:E.shapeId}:E,de=p&&M?tn(p,M.shapeId):null,Y=oe.current,G=!!(p&&de&&Y?.slideId===p.id&&Y.shapeId===de.id&&n.timeStamp-Y.timeStamp<=600&&Math.hypot(n.clientX-Y.clientX,n.clientY-Y.clientY)<=6),ue=G&&Y?Math.min(Y.count+1,3):1,z=M?.kind==="text"?on(u.frame,M.shapeId,M.storyId,c):null;if(oe.current=null,p&&M?.kind==="text"&&de&&ue>=2){let ye=i.story(M.storyId),Le=ue>=3?"paragraph":"word",Tt=fn(lt(ye),M.position,Le);V({shapeId:M.shapeId,storyId:M.storyId,anchor:Tt.start,focus:Tt.end,focusLine:z?.lineIndex}),ce(null),$(null),L.current={kind:"text",pointerId:n.pointerId,slideId:p.id,shapeId:M.shapeId,storyId:M.storyId,anchor:Tt.start,focus:Tt.end,focusLine:z?.lineIndex,granularity:Le,clickCount:ue,clickShapeId:de.id,startClientX:n.clientX,startClientY:n.clientY,dragging:!1},n.currentTarget.setPointerCapture(n.pointerId);}else if(p&&x&&M?.kind==="text"&&M.shapeId===x.shapeId&&M.storyId===x.storyId){i.story(M.storyId);let ye=n.shiftKey?x.anchor:M.position;V({shapeId:M.shapeId,storyId:M.storyId,anchor:ye,focus:M.position,focusLine:z?.lineIndex}),ce(null),$(null),L.current={kind:"text",pointerId:n.pointerId,slideId:p.id,shapeId:M.shapeId,storyId:M.storyId,anchor:ye,focus:M.position,focusLine:z?.lineIndex,granularity:"character",clickCount:ue,clickShapeId:de?.id??M.shapeId,startClientX:n.clientX,startClientY:n.clientY,dragging:!1},n.currentTarget.setPointerCapture(n.pointerId);}else p&&M?de?(V(null),ce({slideId:p.id,shapeId:de.id}),$(null),nn(de)?(L.current={kind:"shape",pointerId:n.pointerId,slideId:p.id,shapeId:de.id,startClientX:n.clientX,startClientY:n.clientY,start:c,last:c,dragThreshold:G?8:4,clickCount:ue,dragging:!1},n.currentTarget.setPointerCapture(n.pointerId)):L.current=null):(V(null),ce(null),oe.current=null,L.current=null):(V(null),ce(null),$(null),oe.current=null,L.current=null);h.current?.focus(),n.preventDefault();}catch(E){U(E);}},En=n=>{let i=L.current,u=b.current,c=w.current;if(!i||i.pointerId!==n.pointerId||!u||!c?.frame)return false;let p=gt(n.currentTarget.getBoundingClientRect(),c.frame,n.clientX,n.clientY);if(!p||c.snapshot.slides[c.slideIndex]?.id!==i.slideId)return false;if(i.kind==="text"){!i.dragging&&rn(i.startClientX,i.startClientY,n.clientX,n.clientY)&&(i.dragging=true);let P=on(c.frame,i.shapeId,i.storyId,p);if(P){let E=i.granularity==="character"?{anchor:i.anchor,focus:P.position}:Do({start:i.anchor,end:i.focus},fn(lt(u.story(i.storyId)),P.position,i.granularity));V({shapeId:i.shapeId,storyId:i.storyId,...E,focusLine:P.lineIndex});}}else i.kind==="shape"?(i.last=p,!i.dragging&&rn(i.startClientX,i.startClientY,n.clientX,n.clientY,i.dragThreshold)&&(i.dragging=true),i.dragging&&$({shapeId:i.shapeId,delta:{x:p.x-i.start.x,y:p.y-i.start.y}})):(i.last=p,ae({start:i.start,end:p}));return true},or=n=>{if(En(n)){n.preventDefault();return}if(L.current||R!=="select")return;let i=w.current;if(!i?.frame)return;let u=gt(n.currentTarget.getBoundingClientRect(),i.frame,n.clientX,n.clientY);Kt(u?sn(i.frame,u,Q):null);},rr=()=>{L.current||Kt(null);},ir=n=>{En(n);let i=L.current;if(!i||i.pointerId!==n.pointerId)return;if(L.current=null,$(null),n.currentTarget.hasPointerCapture(n.pointerId)&&n.currentTarget.releasePointerCapture(n.pointerId),i.kind==="textBox"){ae(null),er(i.start,i.last),n.preventDefault();return}if(i.kind==="shapeInsert"){ae(null),tr(i.geometry,i.start,i.last),n.preventDefault();return}if(i.kind==="text"){oe.current=i.dragging?null:{slideId:i.slideId,shapeId:i.clickShapeId,clientX:n.clientX,clientY:n.clientY,timeStamp:n.timeStamp,count:i.clickCount};return}if(i.kind!=="shape")return;if(!i.dragging){oe.current={slideId:i.slideId,shapeId:i.shapeId,clientX:n.clientX,clientY:n.clientY,timeStamp:n.timeStamp,count:i.clickCount};return}oe.current=null;let u=b.current,c=w.current,p=c?.snapshot.slides[c.slideIndex];if(!u||!c?.frame||p?.id!==i.slideId)return;let P=Ee(p.shapes,i.shapeId);if(P)try{let E=qn(c.snapshot,c.frame,P,{x:i.last.x-i.start.x,y:i.last.y-i.start.y});(E.x!==P.x||E.y!==P.y)&&(u.moveShape(p.id,P.id,E.x,E.y),le(void 0,!0)),ce({slideId:p.id,shapeId:P.id}),n.preventDefault();}catch(E){U(E);}},Mn=n=>{L.current?.pointerId===n.pointerId&&(L.current=null,$(null),ae(null),oe.current=null);},nt=n=>{V(n?{...n,focusLine:void 0}:null),ce(null),oe.current=null,le(void 0,true);},ar=n=>{let i=b.current;if(!i)return;let u=n.metaKey||n.ctrlKey;if(n.key==="Escape"){re.setEnabled(false),ve("select"),ae(null),L.current=null,ne.current=null,we(null),n.preventDefault();return}if(u&&(n.key==="z"||n.key==="Z")){n.preventDefault(),Vt(n.shiftKey?"redo":"undo");return}if(u&&(n.key==="s"||n.key==="S")){n.preventDefault(),kn();return}if(re.reviewing||!x&&!Fe)return;if(u&&(n.key==="b"||n.key==="B")){n.preventDefault(),ze({bold:x?!Ce.bold:!Ze.bold});return}if(u&&(n.key==="i"||n.key==="I")){n.preventDefault(),ze({italic:x?!Ce.italic:!Ze.italic});return}if(u&&(n.key==="u"||n.key==="U")){n.preventDefault(),ze({underline:x?Ce.underline==="none"?"sng":"none":Ze.underline?"none":"sng"});return}if(!x)return;let c=Math.min(x.anchor,x.focus),p=Math.max(x.anchor,x.focus);try{let P=sr(n,x);if(P!==null){n.preventDefault(),V({...x,anchor:n.shiftKey?x.anchor:P.position,focus:P.position,focusLine:P.lineIndex});return}if(n.key==="Backspace"){if(n.preventDefault(),c!==p){i.deleteText(x.storyId,c,p),nt({...x,anchor:c,focus:c});return}let E=Li(i.story(x.storyId),c);E<c&&(i.deleteText(x.storyId,E,c),nt({...x,anchor:E,focus:E}));return}if(n.key==="Delete"){if(n.preventDefault(),c!==p){i.deleteText(x.storyId,c,p),nt({...x,anchor:c,focus:c});return}let E=Di(i.story(x.storyId),p);E>p&&(i.deleteText(x.storyId,p,E),nt({...x,anchor:p,focus:p}));return}if(n.key==="Enter"){n.preventDefault(),c!==p&&i.deleteText(x.storyId,c,p),i.insertParagraphBreak(x.storyId,c),nt({...x,anchor:c+1,focus:c+1});return}if(n.key.length>0&&!n.metaKey&&!n.ctrlKey&&!n.altKey&&Array.from(n.key).length===1){n.preventDefault(),c!==p&&i.deleteText(x.storyId,c,p),i.insertText(x.storyId,c,n.key,Ce);let E=c+n.key.length;nt({...x,anchor:E,focus:E});}}catch(P){U(P);}},ze=n=>{ct(u=>({...u,...n}));let i=b.current;if(i)try{if(x){if(x.anchor===x.focus)return;i.formatText(x.storyId,Math.min(x.anchor,x.focus),Math.max(x.anchor,x.focus),n);}else if(Fe){let u=i.story(Fe);Ri(i,u,n);}else return;le(void 0,!0);}catch(u){U(u);}},sr=(n,i)=>{let u=b.current;if(!u)return null;let c=u.story(i.storyId),p=Math.max(0,c.length-1),P=G=>Math.max(0,Math.min(p,G)),E=Bi(v?.frame,i),M={position:i.focus,lineIndex:i.focusLine},de=n.altKey||n.ctrlKey&&!n.metaKey,Y=n.metaKey;if(n.key==="ArrowUp"||n.key==="ArrowDown"){let G={shapeId:i.shapeId,...M},ue=se.current&&Fo(se.current,G)?se.current.goalX:mn(E,M),z=n.key==="ArrowUp"?"up":"down",ye=Ao(E,M,z,ue),Le={...ye,position:P(ye.position)};return se.current=ue===void 0?null:{shapeId:i.shapeId,goalX:ue,position:Le.position,lineIndex:Le.lineIndex},Le}if(se.current=null,n.key==="ArrowLeft"||n.key==="ArrowRight"){let G=n.key==="ArrowLeft"?-1:1;if(Y){let z=Ht(E,M,G<0?"start":"end");return {...z,position:P(z.position)}}let ue=de?Bo(lt(c),i.focus,G):i.focus+G;return {position:P(ue),lineIndex:i.focusLine}}if(n.key==="Home"){if(Y||n.ctrlKey)return {position:0,lineIndex:0};let G=Ht(E,M,"start");return {...G,position:P(G.position)}}if(n.key==="End"){if(Y||n.ctrlKey)return {position:p,lineIndex:Math.max(0,E.length-1)};let G=Ht(E,M,"end");return {...G,position:P(G.position)}}return null},lr=n=>{let i=b.current,u=x?.storyId??Fe;if(!(!i||!u))try{x?i.setParagraphAlignment(u,Math.min(x.anchor,x.focus),Math.max(x.anchor,x.focus),n):i.setParagraphAlignment(u,0,i.story(u).length,n),le(void 0,!0);}catch(c){U(c);}},dr=n=>{n==="bold"?ze({bold:!Ze.bold}):n==="italic"?ze({italic:!Ze.italic}):n==="underline"?ze({underline:Ze.underline?"none":"sng"}):n.type==="fontFamily"?ze({fontFamily:n.value}):n.type==="fontSize"?ze({fontSizePt:n.value}):n.type==="textColor"?ze({color:n.value}):n.type==="align"&&lr(n.value);},cr=n=>{let i=b.current;if(!(!i||!q||!me))try{n.type==="fillColor"?i.setShapeFill(q.slideId,q.shapeId,n.value):n.type==="strokeColor"?i.setShapeStroke(q.slideId,q.shapeId,n.value?{color:n.value}:{}):n.type==="strokeWidth"?i.setShapeStroke(q.slideId,q.shapeId,n.value===null?{}:{widthPt:n.value}):i.setShapeAdjust(q.slideId,q.shapeId,{...me.adjustValues,[n.name]:n.value}),le(void 0,!0);}catch(u){U(u);}},ur=n=>{let i=b.current,u=w.current;if(!(!i||!u))try{let c=u.slideIndex+1,p=n===void 0?u.snapshot.slides[u.slideIndex]?.layoutPartPath??void 0:n??void 0;i.insertSlide(c,p),V(null),ce(null),$(null),ae(null),ve("select"),L.current=null,oe.current=null,ne.current=null,we(null),le(c,!0,!0);}catch(c){U(c);}},Vt=n=>{let i=b.current;if(i)try{n==="undo"?i.undo():i.redo(),V(null),$(null),ae(null),ve("select"),L.current=null,oe.current=null,ne.current=null,we(null),le(void 0,!0);}catch(u){U(u);}},kn=()=>{let n=b.current;if(n)try{let i=n.save();g?g(i):Ho(i,s??"presentation.pptx",mi);}catch(i){U(i);}},Rn=(n,i)=>{let u=O.current,c=v?.frame;return !u||!c?null:gt(u.getBoundingClientRect(),c,n,i)},pr=n=>i=>{if(!q||!me||!Rt(me))return;let u=Rn(i.clientX,i.clientY);u&&(i.preventDefault(),i.stopPropagation(),ne.current={pointerId:i.pointerId,handle:n,start:u,slideId:q.slideId,shapeId:q.shapeId,delta:{x:0,y:0}},we({x:0,y:0}),i.currentTarget.setPointerCapture(i.pointerId));},Ln=n=>{let i=ne.current;return kt(i,n.pointerId)?to(i.start,i.delta,Rn(n.clientX,n.clientY)):null},fr=n=>{let i=ne.current,u=Ln(n);!kt(i,n.pointerId)||!u||(i.delta=u,we(u));},Dn=n=>{let i=ne.current;return kt(i,n.pointerId)?(ne.current=null,we(null),n.currentTarget.hasPointerCapture(n.pointerId)&&n.currentTarget.releasePointerCapture(n.pointerId),i):null},Fn=n=>{Dn(n);},hr=n=>{let i=Ln(n),u=Dn(n),c=b.current,p=w.current,P=p?.snapshot.slides[p.slideIndex],E=P&&u?Ee(P.shapes,u.shapeId):null;if(!(!u||!i||!c||!p?.frame||P?.id!==u.slideId||!E)&&!(i.x===0&&i.y===0))try{let M=an(p.snapshot,p.frame,E,u.handle,i);M&&(M.x!==E.x||M.y!==E.y||M.width!==E.width||M.height!==E.height)&&(c.setShapeRect(u.slideId,u.shapeId,M),le(void 0,!0));}catch(M){U(M);}},$e=v?.snapshot.slides.length??0,Ye=v?.slideIndex??0,mr=()=>{$e!==0&&Xt(true);},gr=()=>{let n=v?.frame,i=b.current;if(!n||!i)return;let u={current:i},c={current:new Map};slideToPng(n,{scale:window.devicePixelRatio||1,resolveImage:p=>st(p,u,c,y)}).then(async p=>{let P=new Uint8Array(await p.arrayBuffer());b.current===i&&Ho(P,gi(s,Ye),"image/png");}).catch(p=>{b.current===i&&U(p);});},An=dt&&dt.shapeId===q?.shapeId?dt.delta:null,qt=ne.current?.handle,br=v?.frame&&me&&Ae&&qt?no(v.snapshot,v.frame,me,qt,Ae):null,ot=Ge?Ae&&qt?br??Ge:{...Ge,x:Ge.x+(An?.x??0),y:Ge.y+(An?.y??0)}:null;return jsxs("div",{className:a,style:W.root,children:[jsxs("div",{style:W.toolbarShell,children:[jsx(vt,{currentFormatting:{...Ze,align:qo},textSelectionActive:!re.reviewing&&(x!==null||Fe!==null),onFormat:dr,currentShapeFormatting:Yo,shapeSelectionActive:!re.reviewing&&me?.kind==="shape",onShapeFormat:cr,onInsertSlide:ur,slideLayouts:Jo,currentLayoutPartPath:v?.snapshot.slides[Ye]?.layoutPartPath,onSave:kn,onExportPng:gr,onUndo:()=>Vt("undo"),onRedo:()=>Vt("redo"),canUndo:Qe.canUndo,canRedo:Qe.canRedo,zoom:et,onZoomChange:C,activeTool:R,onToolChange:n=>{re.setEnabled(false),ve(n),n!=="select"&&(V(null),ce(null)),ae(null),L.current=null,ne.current=null,we(null),h.current?.focus();},disabled:!v||$e===0,style:W.toolbar,children:jsx(vt.Toolbar,{})}),b.current?.isProposalsAvailable()&&jsxs("button",{ref:Pn,type:"button","data-testid":"pptx-proposals-button","aria-expanded":vn,style:W.presentButton,onClick:()=>{tt(),pt(n=>!n);},children:[l("proposals.title")," ",jsx("span",{"data-testid":"pptx-proposals-count",children:Gt.length})]}),Xe.length>0?jsxs("div",{style:W.presenceStrip,role:"list","aria-label":"Collaborators",children:[mt.visible.map(n=>{let i=n.state.cursor?.slideId===ht;return jsx("span",{role:"listitem",style:Oo(n.state.user.color,i),title:n.state.user.name,"aria-label":n.state.user.name,children:Ni(n.state.user.name)},n.state.clientId)}),mt.overflow>0?jsxs("span",{role:"listitem",style:Oo("#64748b",true),title:`${mt.overflow} more collaborators`,"aria-label":`${mt.overflow} more collaborators`,children:["+",mt.overflow]}):null]}):null,jsxs("button",{type:"button",onClick:mr,disabled:$e===0,"data-testid":"pptx-present",style:W.presentButton,children:[jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:jsx("path",{d:"M6 4.5v15l13-7.5Z"})}),l("toolbar.present")]})]}),jsxs("div",{style:W.workspace,children:[jsx("aside",{style:W.slideStrip,"aria-label":l("slides.panelLabel"),children:v?.snapshot.slides.map((n,i)=>{let u=Vo.get(n.id);return jsxs("button",{type:"button","aria-current":i===Ye?"page":void 0,style:Oi(i===Ye),onClick:()=>Qo(i),children:[jsx("span",{style:W.slideNumber,children:i+1}),jsxs("span",{style:W.slidePreview,children:[v.thumbnails.get(n.id)?jsx(Pi,{frame:v.thumbnails.get(n.id),resolveImage:c=>st(c,b,Be,y)}):jsx("span",{style:W.slideTitle,children:Hi(n.shapes)||l("slides.fallbackTitle",{number:i+1})}),n.id!==ht&&u&&(u.visible.length>0||u.overflow>0)?jsxs("span",{style:W.thumbnailPresence,"aria-hidden":"true",children:[u.visible.map(c=>jsx("span",{style:{...W.thumbnailPresenceDot,backgroundColor:c.state.user.color}},c.state.clientId)),u.overflow>0?jsxs("span",{style:W.thumbnailPresenceOverflow,children:["+",u.overflow]}):null]}):null]})]},n.id)})}),jsxs("div",{ref:h,style:W.stage,tabIndex:0,role:"application","aria-label":l("editor.appLabel"),onKeyDown:ar,onFocus:()=>Se(true),onBlur:()=>Se(false),children:[jsx(so,{review:re,ready:Xo===re.diff,onAccept:Tn,onReject:Cn,onDetails:()=>pt(true)}),jsx("div",{ref:T,style:W.canvasHost,children:v?.frame?jsxs("div",{style:{...W.canvasFrame,width:v.frame.width*Q,height:v.frame.height*Q},children:[jsx("canvas",{ref:O,"data-testid":"pptx-slide-canvas","aria-hidden":re.reviewing,style:{...W.canvas,cursor:R!=="select"?"crosshair":xn==="text"?"text":xn==="shape"?"move":"default"},onPointerDown:re.reviewing?void 0:nr,onPointerMove:or,onPointerUp:ir,onPointerLeave:rr,onPointerCancel:Mn,onLostPointerCapture:Mn,"aria-label":me?l("slides.canvasLabelWithSelection",{current:Ye+1,total:$e,name:me.name}):l("slides.canvasLabel",{current:Ye+1,total:$e})}),!re.reviewing&&jsxs(Fragment,{children:[jsx(Ii,{frame:v.frame,selection:x,scale:Q,focused:Z}),Yt.visible.map(({peer:n,peerCount:i,shapeId:u,bounds:c},p)=>jsx(Si,{peer:n,peerCount:i,bounds:c,scale:Q,labelOffset:p},u)),Yt.overflow>0?jsxs("span",{style:W.remoteShapeOverflow,"aria-hidden":"true",children:["+",Yt.overflow," selections"]}):null,ot?jsxs(Fragment,{children:[jsx("span",{style:{...W.shapeSelection,left:ot.x*Q,top:ot.y*Q,width:Math.max(1,ot.width*Q),height:Math.max(1,ot.height*Q)},"aria-hidden":"true"}),me&&Rt(me)?Gn.map(n=>{let i=Qn(ot,n);return jsx("span",{"data-testid":`pptx-resize-${n}`,onPointerDown:pr(n),onPointerMove:fr,onPointerUp:hr,onPointerCancel:Fn,onLostPointerCapture:Fn,style:{...W.resizeHandle,left:i.x*Q-Wt/2,top:i.y*Q-Wt/2,cursor:eo(n)}},n)}):null]}):null,ft?jsx("span",{style:{...W.textEditOutline,left:ft.x*Q,top:ft.y*Q,width:Math.max(1,ft.width*Q),height:Math.max(1,ft.height*Q)},"aria-hidden":"true"}):null,he?jsx("span",{style:{...W.textBoxPreview,left:Math.min(he.start.x,he.end.x)*Q,top:Math.min(he.start.y,he.end.y)*Q,width:Math.max(1,Math.abs(he.end.x-he.start.x))*Q,height:Math.max(1,Math.abs(he.end.y-he.start.y))*Q},"aria-hidden":"true"}):null]}),re.diff&&jsx(lo,{diff:re.diff,current:v.snapshot,frame:v.frame,slideIndex:v.slideIndex,scale:Q,resolveImage:Zo,onPainted:Go,onTarget:(n,i)=>{wn(n,i,re.selected?.id),pt(true);}},`${re.diff.proposal.id}:${v.slideIndex}`)]}):jsx("div",{style:W.empty,children:l(Uo?"editor.opening":e?"editor.noSlides":"editor.openPrompt")})}),yn?jsx("div",{style:W.error,children:yn}):null]}),vn&&v&&b.current&&jsx(jn,{handle:b.current,proposals:Gt,snapshot:v.snapshot,resolveImage:n=>st(n,b,Be,y),onAccept:Tn,onReject:Cn,onNavigate:wn,onClose:()=>{pt(false),Pn.current?.focus();}})]}),xe&&re.diff?.proposal.changes.some(n=>n.slideId===xe.id&&!n.shapeId&&n.oldText!==n.newText)?jsx(co,{diff:re.diff,slideId:xe.id}):xe?jsx(vi,{value:xe.notes??"",disabled:!v||re.reviewing,label:l("notes.panelLabel"),placeholder:l("notes.placeholder"),onCommit:n=>{let i=b.current;if(i)try{i.setSlideNotes(xe.id,n),le(void 0,!0);}catch(u){U(u);}}},xe.id):null,jo&&$e>0&&b.current?jsx(Io,{handle:b.current,slideCount:$e,startIndex:Ye,resolveImage:n=>st(n,b,Be,y),counterLabel:(n,i)=>l("presentation.slideCounter",{current:n,total:i}),label:l("presentation.label"),exitLabel:l("presentation.exit"),previousLabel:l("presentation.previousSlide"),nextLabel:l("presentation.nextSlide"),onExit:()=>Xt(false),onError:U}):null]})}function Si({peer:e,peerCount:t,bounds:o,scale:r,labelOffset:a}){let[s,d]=useState(()=>Date.now()-e.cursorMovedAt<PRESENCE_LABEL_DURATION_MS);return useEffect(()=>{let m=PRESENCE_LABEL_DURATION_MS-(Date.now()-e.cursorMovedAt);if(m<=0){d(false);return}d(true);let f=setTimeout(()=>d(false),m);return ()=>clearTimeout(f)},[e.cursorMovedAt]),jsxs("span",{style:{...W.remoteShapeSelection,left:o.x*r,top:o.y*r,width:Math.max(1,o.width*r),height:Math.max(1,o.height*r),borderColor:e.state.user.color},"aria-hidden":"true",children:[jsx("span",{style:{...W.remoteShapeWash,backgroundColor:e.state.user.color}}),s?jsxs("span",{style:{...W.remoteShapeLabel,top:-4-a%3*20,backgroundColor:e.state.user.color},children:[e.state.user.name,t>1?` +${t-1}`:""]}):null]})}function vi({value:e,disabled:t,label:o,placeholder:r,onCommit:a}){return jsxs("div",{style:W.notesPanel,children:[jsx("span",{style:W.notesLabel,children:o}),jsx("textarea",{"aria-label":o,style:W.notesTextarea,value:e,disabled:t,placeholder:r,"data-testid":"pptx-notes-textarea",onChange:s=>a(s.target.value)})]})}function Pi({frame:e,resolveImage:t}){let o=useRef(null);return useEffect(()=>{let r=o.current;if(!r)return;let a=r.getContext("2d");if(!a)return;let s=128/e.width,d=window.devicePixelRatio||1;sizeCanvasForSlide(r,e,d,s),paintSlide(a,e,d,s,{resolveImage:t}).catch(()=>{});},[e,t]),jsx("canvas",{ref:o,style:W.thumbnailCanvas,"aria-hidden":"true"})}function Ii({frame:e,selection:t,scale:o,focused:r}){let a=useRef(null),[s,d]=useState(()=>typeof document>"u"||document.visibilityState==="visible"),[m,f]=useState(false);return useEffect(()=>{if(typeof document>"u")return;let g=()=>d(document.visibilityState==="visible");return document.addEventListener("visibilitychange",g),()=>document.removeEventListener("visibilitychange",g)},[]),useEffect(()=>{let g=r&&s&&t!==null&&t.anchor===t.focus;if(f(g),!g)return;let l=window.setInterval(()=>f(y=>!y),bi);return ()=>window.clearInterval(l)},[r,s,t]),useEffect(()=>{let g=a.current;if(!g)return;let l=g.getContext("2d");if(!l)return;let y=window.devicePixelRatio||1;sizeCanvasForSlide(g,e,y,o),zi(l,e,t,y,o,m);},[m,e,o,t]),jsx("canvas",{ref:a,style:W.canvasOverlay,"aria-hidden":"true"})}function wi(e,t){return t===0?0:Math.max(0,Math.min(t-1,e))}function Ti(e){if(!e.startsWith("shape:"))return null;let t=e.slice(6);return St.some(o=>o.geometry===t)?t:null}function Ci(e){let t=useRef(e);return Ei(t.current,e)||(t.current=e),t.current}function Ei(e,t){return e===t?true:e.length!==t.length?false:e.every((o,r)=>Mi(o,t[r]))}function Mi(e,t){return e.family===t.family&&(e.bold??false)===(t.bold??false)&&(e.italic??false)===(t.italic??false)&&ki(e.bytes,t.bytes)}function ki(e,t){return e===t?true:e.byteLength!==t.byteLength?false:e.every((o,r)=>o===t[r])}function lt(e){return e.paragraphs.map(t=>t.runs.map(o=>o.text).join("")).join(`
4
+ `)}function Ri(e,t,o){e.formatText(t.id,0,t.length,o);}function Li(e,t){let o=lt(e).slice(0,t),r=Array.from(o),a=r[r.length-1];return a?t-a.length:t}function Di(e,t){let o=Array.from(lt(e).slice(t))[0];return o?t+o.length:t}function Ot(e){return {bold:e.bold,italic:e.italic,underline:e.underline!=="none",fontSize:e.fontSizePt,textColor:e.color,fontFamily:e.fontFamily}}async function Fi(e){return typeof FontFace>"u"||typeof document>"u"?[]:await Promise.all(e.map(async o=>{let r=o.bytes.slice().buffer,s=await new FontFace(o.family,r,{style:o.italic?"italic":"normal",weight:o.bold?"700":"400"}).load();return document.fonts.add(s),s}))}function No(e){if(!(typeof document>"u"))for(let t of e)document.fonts.delete(t);}function st(e,t,o,r){let a=o.current.get(e);if(a)return a;let s=Ai(t.current?.mediaBytes(e),r);return o.current.set(e,s),s}async function Ai(e,t){if(!e)return null;let o=presentationImageBlob(e);if(typeof createImageBitmap=="function")return createImageBitmap(o);let r=URL.createObjectURL(o);try{return await new Promise((a,s)=>{let d=new Image;d.onload=()=>a(d),d.onerror=()=>s(new Error(t)),d.src=r;})}finally{URL.revokeObjectURL(r);}}function Bi(e,t){return e?.primitives.find(r=>r.kind==="textBox"&&r.storyId===t.storyId&&r.shapeId===t.shapeId)?.lines??[]}function zi(e,t,o,r,a,s=true){if(!o)return;let d=t.primitives.find(g=>g.kind==="textBox"&&g.storyId===o.storyId&&g.shapeId===o.shapeId);if(!d)return;let m=Math.min(o.anchor,o.focus),f=Math.max(o.anchor,o.focus);if(e.save(),e.setTransform(r*a,0,0,r*a,0,0),m!==f){e.fillStyle="rgba(59, 130, 246, 0.26)";for(let g of d.lines){let l=Math.max(m,g.start),y=Math.min(f,g.end);if(l>=y)continue;let I=gn(g,l),K=gn(g,y);e.fillRect(Math.min(I,K),g.y,Math.max(1,Math.abs(K-I)),g.height);}}else if(s){let g=d.lines[Pt(d.lines,{position:m,lineIndex:o.focusLine})];if(g){let l=gn(g,m);e.fillStyle="#1d4ed8",e.fillRect(l,g.y,1.5,g.height);}}e.restore();}function gn(e,t){let o=e.caretStops[0];return o?e.caretStops.reduce((r,a)=>Math.abs(a.position-t)<Math.abs(r.position-t)?a:r,o).x:e.x}function Hi(e){for(let t of e)for(let o of t.textStories){let r=lt(o).trim();if(r)return r.slice(0,40)}return ""}var W={root:{display:"flex",flexDirection:"column",width:"100%",height:"100%",minHeight:480,overflow:"hidden",color:"#172033",background:"#f3f5f8",fontFamily:"ui-sans-serif, system-ui, sans-serif"},toolbarShell:{display:"flex",alignItems:"center",flex:"0 0 auto",padding:"4px 0 5px",background:"#ffffff",borderBottom:"1px solid #e2e8f0"},toolbar:{flex:"1 1 auto",minWidth:0},presenceStrip:{display:"flex",alignItems:"center",gap:4,flex:"0 0 auto",maxWidth:"35%",padding:"0 10px 0 2px",overflowX:"auto"},workspace:{display:"flex",flex:1,minHeight:0},slideStrip:{width:184,padding:"14px 10px",overflowY:"auto",background:"#eef1f5",borderRight:"1px solid #d8dee9",boxSizing:"border-box"},slideNumber:{width:18,flex:"0 0 auto",paddingTop:3,fontSize:11,color:"#647087",textAlign:"right"},slidePreview:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center",width:132,aspectRatio:"16 / 9",padding:8,overflow:"hidden",background:"#ffffff",boxSizing:"border-box",boxShadow:"0 1px 4px rgba(20, 31, 50, 0.16)"},slideTitle:{fontSize:9,lineHeight:1.25,color:"#39445a",textAlign:"center"},thumbnailCanvas:{display:"block",maxWidth:"100%",height:"auto"},thumbnailPresence:{position:"absolute",top:4,right:4,display:"flex",gap:3,padding:2,borderRadius:999,background:"rgba(255, 255, 255, 0.88)",boxShadow:"0 1px 3px rgba(15, 23, 42, 0.2)"},thumbnailPresenceDot:{width:7,height:7,borderRadius:999,boxShadow:"0 0 0 1px rgba(255, 255, 255, 0.9)"},thumbnailPresenceOverflow:{color:"#475569",fontSize:8,fontWeight:700,lineHeight:"8px"},stage:{position:"relative",display:"flex",flexDirection:"column",flex:1,minWidth:0,outline:"none",overflow:"hidden"},canvasHost:{display:"flex",flex:1,minHeight:0,alignItems:"center",justifyContent:"center",width:"100%",overflow:"auto"},canvasFrame:{position:"relative",flex:"0 0 auto"},canvas:{display:"block",flex:"0 0 auto",background:"#fff",boxShadow:"0 8px 32px rgba(27, 39, 61, 0.2)",touchAction:"none"},canvasOverlay:{position:"absolute",inset:0,display:"block",pointerEvents:"none"},textEditOutline:{position:"absolute",zIndex:3,border:"2px dashed #6b7280",boxSizing:"border-box",boxShadow:"0 0 0 1px rgba(255, 255, 255, 0.9)",pointerEvents:"none"},resizeHandle:{position:"absolute",zIndex:4,width:Wt,height:Wt,borderRadius:"50%",border:"1px solid #2563eb",background:"#ffffff",boxShadow:"0 1px 2px rgba(15, 23, 42, 0.35)",boxSizing:"border-box",touchAction:"none"},shapeSelection:{position:"absolute",zIndex:3,border:"2px solid #2563eb",boxSizing:"border-box",boxShadow:"0 0 0 1px rgba(255, 255, 255, 0.9)",pointerEvents:"none"},remoteShapeSelection:{position:"absolute",zIndex:2,border:"2px solid",borderRadius:2,boxSizing:"border-box",boxShadow:"0 0 0 1px rgba(255, 255, 255, 0.88)",pointerEvents:"none"},remoteShapeWash:{position:"absolute",inset:0,opacity:.12},remoteShapeLabel:{position:"absolute",left:-2,maxWidth:180,overflow:"hidden",padding:"3px 6px",borderRadius:"4px 4px 4px 0",color:"#ffffff",fontSize:11,fontWeight:650,lineHeight:"14px",textOverflow:"ellipsis",whiteSpace:"nowrap",transform:"translateY(-100%)",boxShadow:"0 1px 3px rgba(15, 23, 42, 0.25)"},remoteShapeOverflow:{position:"absolute",top:8,right:8,zIndex:3,padding:"3px 6px",borderRadius:999,backgroundColor:"#475569",color:"#ffffff",fontSize:10,fontWeight:700,pointerEvents:"none"},textBoxPreview:{position:"absolute",border:"1.5px dashed #1a73e8",background:"rgba(26, 115, 232, 0.08)",boxSizing:"border-box",pointerEvents:"none"},notesPanel:{flex:"0 0 auto",display:"flex",flexDirection:"column",gap:4,padding:"8px 14px 10px",background:"#ffffff",borderTop:"1px solid #e2e8f0"},notesLabel:{fontSize:11,fontWeight:650,color:"#647087",textTransform:"uppercase",letterSpacing:"0.02em"},notesTextarea:{width:"100%",height:64,resize:"vertical",border:"1px solid #d8dee9",borderRadius:6,padding:"6px 8px",font:"13px ui-sans-serif, system-ui, sans-serif",color:"#172033",boxSizing:"border-box",outline:"none"},empty:{margin:"auto",color:"#6b7587",fontSize:14},error:{position:"absolute",left:16,right:16,bottom:14,padding:"9px 12px",color:"#8b1e2d",background:"#fff0f2",border:"1px solid #efb8c0",borderRadius:6,fontSize:12},presentButton:{display:"inline-flex",alignItems:"center",gap:6,flex:"0 0 auto",margin:"0 12px 0 4px",padding:"0 14px",height:30,border:0,borderRadius:15,background:"#1a73e8",color:"#ffffff",font:"600 13px ui-sans-serif, system-ui, sans-serif",cursor:"pointer"}};function Ni(e){let t=e.trim().split(/\s+/).filter(Boolean);return t.length===0?"?":t.slice(0,2).map(o=>o[0]).join("").toUpperCase()}function Oo(e,t){return {display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,flex:"0 0 auto",border:"2px solid #ffffff",borderRadius:999,backgroundColor:e,boxShadow:"0 0 0 1px rgba(15, 23, 42, 0.14)",color:"#ffffff",fontSize:10,fontWeight:700,letterSpacing:"-0.02em",opacity:t?1:.38}}function Oi(e){return {display:"flex",alignItems:"flex-start",gap:7,width:"100%",marginBottom:12,padding:4,border:e?"2px solid #325ee6":"2px solid transparent",borderRadius:5,background:"transparent",cursor:"pointer"}}export{vt as EditorToolbar,rt as EditorToolbarContext,Ct as LocaleProvider,xi as PptxEditor,At as PptxToolbar,St as SHAPE_PRESETS,At as Toolbar,Pe as ToolbarButton,qe as ToolbarDropdown,Me as ToolbarGroup,it as ToolbarMenuItem,Br as ToolbarMenuSeparator,_e as ToolbarSeparator,Dr as useEditorToolbar,Te as useTranslation};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betteroffice/pptx-react",
3
- "version": "0.0.3",
3
+ "version": "0.1.0",
4
4
  "description": "PowerPoint-faithful React PPTX editor and viewer — full OOXML fidelity, real-time human + AI agent collaboration.",
5
5
  "keywords": [
6
6
  "pptx",
@@ -11,8 +11,14 @@
11
11
  "editor",
12
12
  "viewer",
13
13
  "react",
14
+ "react-pptx",
15
+ "pptx-editor",
16
+ "pptx-viewer",
17
+ "slides-editor",
14
18
  "collaborative",
15
19
  "real-time",
20
+ "crdt",
21
+ "yjs",
16
22
  "ai-agent"
17
23
  ],
18
24
  "type": "module",
@@ -34,8 +40,8 @@
34
40
  "typecheck": "tsc --noEmit -p ."
35
41
  },
36
42
  "dependencies": {
37
- "@betteroffice/pptx": "0.0.3",
38
- "@betteroffice/pptx-i18n": "0.0.3"
43
+ "@betteroffice/pptx": "0.1.0",
44
+ "@betteroffice/pptx-i18n": "0.1.0"
39
45
  },
40
46
  "peerDependencies": {
41
47
  "react": "^18.0.0 || ^19.0.0",