@betteroffice/pptx-react 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -12
- package/dist/index.d.ts +180 -4
- package/dist/index.js +4 -2
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -3,8 +3,15 @@
|
|
|
3
3
|
React chrome for the BetterOffice PPTX editor — wraps
|
|
4
4
|
[`@betteroffice/pptx`](https://www.npmjs.com/package/@betteroffice/pptx) in a
|
|
5
5
|
slide canvas, slide strip, formatting toolbar, and keyboard editing surface.
|
|
6
|
+
Parsing, layout, and text shaping run in the core's Rust/WebAssembly engine;
|
|
7
|
+
slides are painted onto canvas.
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
<!-- TODO(author): add a screenshot/GIF here once hosted; an <img> with an unresolvable src renders broken on npm -->
|
|
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.
|
|
8
15
|
|
|
9
16
|
```bash
|
|
10
17
|
bun add @betteroffice/pptx-react @betteroffice/pptx react react-dom
|
|
@@ -12,7 +19,7 @@ bun add @betteroffice/pptx-react @betteroffice/pptx react react-dom
|
|
|
12
19
|
|
|
13
20
|
`react` and `react-dom` (18 or 19) are peer dependencies.
|
|
14
21
|
|
|
15
|
-
##
|
|
22
|
+
## Render a presentation
|
|
16
23
|
|
|
17
24
|
```tsx
|
|
18
25
|
import { PptxEditor } from '@betteroffice/pptx-react';
|
|
@@ -23,20 +30,36 @@ export function Presentation({ file, fontBytes }: {
|
|
|
23
30
|
}) {
|
|
24
31
|
return (
|
|
25
32
|
<div style={{ height: 720 }}>
|
|
26
|
-
<PptxEditor
|
|
27
|
-
file={file}
|
|
28
|
-
fonts={[{ family: 'My Sans', bytes: fontBytes }]}
|
|
29
|
-
onChange={(deck) => console.log(deck.slides.length)}
|
|
30
|
-
/>
|
|
33
|
+
<PptxEditor file={file} fonts={[{ family: 'My Sans', bytes: fontBytes }]} />
|
|
31
34
|
</div>
|
|
32
35
|
);
|
|
33
36
|
}
|
|
34
37
|
```
|
|
35
38
|
|
|
39
|
+
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)
|
|
41
|
+
for metric-compatible open faces.
|
|
42
|
+
|
|
43
|
+
## Edit
|
|
44
|
+
|
|
36
45
|
Click text to place the Rust-computed caret, type to edit the yrs story and
|
|
37
|
-
trigger Rust reflow, or
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
trigger Rust reflow, drag or resize shapes on the canvas, or use the toolbar
|
|
47
|
+
for bold, italic, size, color, slides, and text boxes.
|
|
48
|
+
|
|
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`.
|
|
52
|
+
|
|
53
|
+
## What works today
|
|
54
|
+
|
|
55
|
+
- Slide rendering with Rust layout and text shaping, painted onto canvas
|
|
56
|
+
- Canvas interactions: shape selection, drag, and resize
|
|
57
|
+
- Text editing with caret and selection computed by the engine
|
|
58
|
+
- Slide management (add, delete), text boxes, undo/redo
|
|
59
|
+
- Localized UI via the `i18n` prop
|
|
60
|
+
([`@betteroffice/pptx-i18n`](https://www.npmjs.com/package/@betteroffice/pptx-i18n))
|
|
61
|
+
- Real-time collaboration with people or agents; the deck is a CRDT
|
|
62
|
+
- Live collaborator shape selections and presence chips, shown in each peer's color
|
|
40
63
|
|
|
41
64
|
## Collaboration
|
|
42
65
|
|
|
@@ -45,20 +68,28 @@ session; drive it with a `CollaborationProvider` over any transport. Every peer
|
|
|
45
68
|
must boot from the same `initialUpdate` seed.
|
|
46
69
|
|
|
47
70
|
```tsx
|
|
48
|
-
import { CollaborationProvider } from '@betteroffice/pptx
|
|
71
|
+
import { CollaborationProvider } from '@betteroffice/pptx';
|
|
49
72
|
|
|
50
73
|
<PptxEditor
|
|
51
74
|
file={file}
|
|
75
|
+
fonts={fonts}
|
|
52
76
|
collaboration={{
|
|
53
77
|
clientId,
|
|
54
78
|
initialUpdate: sharedSeed,
|
|
55
79
|
onReplica: (replica) => {
|
|
56
80
|
if (!replica) return;
|
|
57
|
-
const provider = new CollaborationProvider(replica, transport
|
|
81
|
+
const provider = new CollaborationProvider(replica, transport, {
|
|
82
|
+
user: { name: "Ada" }, // shown on this peer's presence chip
|
|
83
|
+
});
|
|
58
84
|
provider.connect();
|
|
59
85
|
},
|
|
60
86
|
}}
|
|
61
87
|
/>;
|
|
62
88
|
```
|
|
63
89
|
|
|
90
|
+
## Framework notes
|
|
91
|
+
|
|
92
|
+
The editor is browser-only (canvas, wasm); under Next.js load it with
|
|
93
|
+
`next/dynamic` and `ssr: false`.
|
|
94
|
+
|
|
64
95
|
Docs: https://betteroffice.dev · Apache-2.0.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
import { PptxFontFace, PresentationHandle, DeckSnapshot } from '@betteroffice/pptx';
|
|
4
|
-
import { CollaborationReplica } from '@betteroffice/pptx/collaboration';
|
|
2
|
+
import { CSSProperties, ReactNode } from 'react';
|
|
3
|
+
import { PptxFontFace, CollaborationReplica, PptxPresence, PresentationHandle, DeckSnapshot } from '@betteroffice/pptx';
|
|
5
4
|
import { Translations, TFunction } from '@betteroffice/pptx-i18n';
|
|
6
5
|
|
|
7
6
|
interface PptxTextSelection {
|
|
@@ -18,6 +17,7 @@ interface PptxEditorCollaborationOptions {
|
|
|
18
17
|
clientId: number;
|
|
19
18
|
initialUpdate?: Uint8Array;
|
|
20
19
|
onReplica?: (replica: CollaborationReplica | null) => void;
|
|
20
|
+
presence?: PptxPresence;
|
|
21
21
|
}
|
|
22
22
|
interface PptxEditorProps {
|
|
23
23
|
file?: Uint8Array;
|
|
@@ -33,6 +33,182 @@ interface PptxEditorProps {
|
|
|
33
33
|
}
|
|
34
34
|
declare function PptxEditor({ i18n, ...props }: PptxEditorProps): react.JSX.Element;
|
|
35
35
|
|
|
36
|
+
declare const SHAPE_PRESETS: readonly [{
|
|
37
|
+
readonly geometry: "rect";
|
|
38
|
+
readonly labelKey: "toolbar.shapes.rect";
|
|
39
|
+
}, {
|
|
40
|
+
readonly geometry: "roundRect";
|
|
41
|
+
readonly labelKey: "toolbar.shapes.roundRect";
|
|
42
|
+
}, {
|
|
43
|
+
readonly geometry: "ellipse";
|
|
44
|
+
readonly labelKey: "toolbar.shapes.ellipse";
|
|
45
|
+
}, {
|
|
46
|
+
readonly geometry: "triangle";
|
|
47
|
+
readonly labelKey: "toolbar.shapes.triangle";
|
|
48
|
+
}, {
|
|
49
|
+
readonly geometry: "rtTriangle";
|
|
50
|
+
readonly labelKey: "toolbar.shapes.rtTriangle";
|
|
51
|
+
}, {
|
|
52
|
+
readonly geometry: "diamond";
|
|
53
|
+
readonly labelKey: "toolbar.shapes.diamond";
|
|
54
|
+
}, {
|
|
55
|
+
readonly geometry: "parallelogram";
|
|
56
|
+
readonly labelKey: "toolbar.shapes.parallelogram";
|
|
57
|
+
}, {
|
|
58
|
+
readonly geometry: "trapezoid";
|
|
59
|
+
readonly labelKey: "toolbar.shapes.trapezoid";
|
|
60
|
+
}, {
|
|
61
|
+
readonly geometry: "pentagon";
|
|
62
|
+
readonly labelKey: "toolbar.shapes.pentagon";
|
|
63
|
+
}, {
|
|
64
|
+
readonly geometry: "hexagon";
|
|
65
|
+
readonly labelKey: "toolbar.shapes.hexagon";
|
|
66
|
+
}, {
|
|
67
|
+
readonly geometry: "octagon";
|
|
68
|
+
readonly labelKey: "toolbar.shapes.octagon";
|
|
69
|
+
}, {
|
|
70
|
+
readonly geometry: "star5";
|
|
71
|
+
readonly labelKey: "toolbar.shapes.star5";
|
|
72
|
+
}, {
|
|
73
|
+
readonly geometry: "rightArrow";
|
|
74
|
+
readonly labelKey: "toolbar.shapes.rightArrow";
|
|
75
|
+
}, {
|
|
76
|
+
readonly geometry: "leftArrow";
|
|
77
|
+
readonly labelKey: "toolbar.shapes.leftArrow";
|
|
78
|
+
}, {
|
|
79
|
+
readonly geometry: "upArrow";
|
|
80
|
+
readonly labelKey: "toolbar.shapes.upArrow";
|
|
81
|
+
}, {
|
|
82
|
+
readonly geometry: "downArrow";
|
|
83
|
+
readonly labelKey: "toolbar.shapes.downArrow";
|
|
84
|
+
}, {
|
|
85
|
+
readonly geometry: "chevron";
|
|
86
|
+
readonly labelKey: "toolbar.shapes.chevron";
|
|
87
|
+
}];
|
|
88
|
+
type PptxShapePreset = (typeof SHAPE_PRESETS)[number]['geometry'];
|
|
89
|
+
type PptxEditorTool = 'select' | 'textBox' | `shape:${PptxShapePreset}`;
|
|
90
|
+
type PptxZoom = number | 'fit';
|
|
91
|
+
interface SelectionFormatting {
|
|
92
|
+
fontFamily?: string;
|
|
93
|
+
fontSize?: number;
|
|
94
|
+
bold?: boolean;
|
|
95
|
+
italic?: boolean;
|
|
96
|
+
underline?: boolean;
|
|
97
|
+
textColor?: string;
|
|
98
|
+
}
|
|
99
|
+
type FormattingAction = 'bold' | 'italic' | 'underline' | {
|
|
100
|
+
type: 'fontFamily';
|
|
101
|
+
value: string;
|
|
102
|
+
} | {
|
|
103
|
+
type: 'fontSize';
|
|
104
|
+
value: number;
|
|
105
|
+
} | {
|
|
106
|
+
type: 'textColor';
|
|
107
|
+
value: string;
|
|
108
|
+
};
|
|
109
|
+
interface ShapeFormatting {
|
|
110
|
+
geometry?: string;
|
|
111
|
+
fillColor?: string | null;
|
|
112
|
+
strokeColor?: string | null;
|
|
113
|
+
strokeWidthPt?: number | null;
|
|
114
|
+
adjustments?: Record<string, number>;
|
|
115
|
+
}
|
|
116
|
+
type ShapeFormattingAction = {
|
|
117
|
+
type: 'fillColor';
|
|
118
|
+
value: string | null;
|
|
119
|
+
} | {
|
|
120
|
+
type: 'strokeColor';
|
|
121
|
+
value: string | null;
|
|
122
|
+
} | {
|
|
123
|
+
type: 'strokeWidth';
|
|
124
|
+
value: number | null;
|
|
125
|
+
} | {
|
|
126
|
+
type: 'adjust';
|
|
127
|
+
name: string;
|
|
128
|
+
value: number;
|
|
129
|
+
};
|
|
130
|
+
interface SlideLayoutOption {
|
|
131
|
+
partPath: string | null;
|
|
132
|
+
label?: string;
|
|
133
|
+
}
|
|
134
|
+
interface ToolbarProps {
|
|
135
|
+
currentFormatting?: SelectionFormatting;
|
|
136
|
+
textSelectionActive?: boolean;
|
|
137
|
+
onFormat?: (action: FormattingAction) => void;
|
|
138
|
+
currentShapeFormatting?: ShapeFormatting;
|
|
139
|
+
shapeSelectionActive?: boolean;
|
|
140
|
+
onShapeFormat?: (action: ShapeFormattingAction) => void;
|
|
141
|
+
onInsertSlide?: (layoutPartPath?: string | null) => void;
|
|
142
|
+
slideLayouts?: readonly SlideLayoutOption[];
|
|
143
|
+
currentLayoutPartPath?: string | null;
|
|
144
|
+
onUndo?: () => void;
|
|
145
|
+
onRedo?: () => void;
|
|
146
|
+
canUndo?: boolean;
|
|
147
|
+
canRedo?: boolean;
|
|
148
|
+
zoom?: PptxZoom;
|
|
149
|
+
onZoomChange?: (zoom: PptxZoom) => void;
|
|
150
|
+
activeTool?: PptxEditorTool;
|
|
151
|
+
onToolChange?: (tool: PptxEditorTool) => void;
|
|
152
|
+
fontFamilies?: readonly string[];
|
|
153
|
+
fontSizes?: readonly number[];
|
|
154
|
+
disabled?: boolean;
|
|
155
|
+
className?: string;
|
|
156
|
+
style?: CSSProperties;
|
|
157
|
+
children?: ReactNode;
|
|
158
|
+
}
|
|
159
|
+
declare function Toolbar(explicitProps: ToolbarProps): react.JSX.Element;
|
|
160
|
+
|
|
161
|
+
type EditorToolbarProps = ToolbarProps;
|
|
162
|
+
declare const EditorToolbarContext: react.Context<ToolbarProps | null>;
|
|
163
|
+
declare function useEditorToolbar(): ToolbarProps;
|
|
164
|
+
|
|
165
|
+
interface EditorToolbarComponent {
|
|
166
|
+
(props: EditorToolbarProps & {
|
|
167
|
+
children: ReactNode;
|
|
168
|
+
}): React.JSX.Element;
|
|
169
|
+
Toolbar: typeof Toolbar;
|
|
170
|
+
}
|
|
171
|
+
declare const EditorToolbar: EditorToolbarComponent;
|
|
172
|
+
|
|
173
|
+
interface ToolbarButtonProps {
|
|
174
|
+
active?: boolean;
|
|
175
|
+
disabled?: boolean;
|
|
176
|
+
title: string;
|
|
177
|
+
onClick?: () => void;
|
|
178
|
+
children: ReactNode;
|
|
179
|
+
style?: CSSProperties;
|
|
180
|
+
testId?: string;
|
|
181
|
+
ariaExpanded?: boolean;
|
|
182
|
+
}
|
|
183
|
+
declare function ToolbarButton({ active, disabled, title, onClick, children, style, testId, ariaExpanded, }: ToolbarButtonProps): react.JSX.Element;
|
|
184
|
+
declare function ToolbarGroup({ label, children, style, }: {
|
|
185
|
+
label: string;
|
|
186
|
+
children: ReactNode;
|
|
187
|
+
style?: CSSProperties;
|
|
188
|
+
}): react.JSX.Element;
|
|
189
|
+
declare function ToolbarSeparator(): react.JSX.Element;
|
|
190
|
+
interface ToolbarDropdownProps {
|
|
191
|
+
title: string;
|
|
192
|
+
trigger: ReactNode;
|
|
193
|
+
children: (close: () => void) => ReactNode;
|
|
194
|
+
disabled?: boolean;
|
|
195
|
+
active?: boolean;
|
|
196
|
+
menuWidth?: number;
|
|
197
|
+
style?: CSSProperties;
|
|
198
|
+
testId?: string;
|
|
199
|
+
}
|
|
200
|
+
declare function ToolbarDropdown({ title, trigger, children, disabled, active, menuWidth, style, testId, }: ToolbarDropdownProps): react.JSX.Element;
|
|
201
|
+
interface ToolbarMenuItemProps {
|
|
202
|
+
label: string;
|
|
203
|
+
icon?: ReactNode;
|
|
204
|
+
selected?: boolean;
|
|
205
|
+
disabled?: boolean;
|
|
206
|
+
onClick?: () => void;
|
|
207
|
+
close?: () => void;
|
|
208
|
+
}
|
|
209
|
+
declare function ToolbarMenuItem({ label, icon, selected, disabled, onClick, close, }: ToolbarMenuItemProps): react.JSX.Element;
|
|
210
|
+
declare function ToolbarMenuSeparator(): react.JSX.Element;
|
|
211
|
+
|
|
36
212
|
interface LocaleProviderProps {
|
|
37
213
|
i18n?: Translations;
|
|
38
214
|
children: ReactNode;
|
|
@@ -42,4 +218,4 @@ declare function useTranslation(): {
|
|
|
42
218
|
t: TFunction;
|
|
43
219
|
};
|
|
44
220
|
|
|
45
|
-
export { LocaleProvider, type LocaleProviderProps, PptxEditor, type PptxEditorApi, type PptxEditorCollaborationOptions, type PptxEditorProps, type PptxTextSelection, useTranslation };
|
|
221
|
+
export { EditorToolbar, EditorToolbarContext, type EditorToolbarProps, type FormattingAction, LocaleProvider, type LocaleProviderProps, PptxEditor, type PptxEditorApi, type PptxEditorCollaborationOptions, type PptxEditorProps, type PptxEditorTool, type PptxShapePreset, type PptxTextSelection, Toolbar as PptxToolbar, type PptxZoom, SHAPE_PRESETS, type SelectionFormatting, type ShapeFormatting, type ShapeFormattingAction, type SlideLayoutOption, Toolbar, ToolbarButton, ToolbarDropdown, ToolbarGroup, ToolbarMenuItem, ToolbarMenuSeparator, type ToolbarProps, ToolbarSeparator, useEditorToolbar, useTranslation };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import {initWasm,openPresentation,sizeCanvasForSlide,paintSlide}from'@betteroffice/pptx';import {createContext,useMemo,useContext,useRef,useState,useCallback,useEffect}from'react';import {en,deepMerge,createT}from'@betteroffice/pptx-i18n';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Ne=createContext(en),Xe=createContext("en");function ne({i18n:t,children:r}){let o=typeof t?._lang=="string"?t._lang:"en",d=useMemo(()=>deepMerge(en,t),[t]);return jsx(Xe.Provider,{value:o,children:jsx(Ne.Provider,{value:d,children:r})})}function re(){let t=useContext(Ne),r=useContext(Xe);return {t:useMemo(()=>createT(t,r),[t,r])}}function oe(t,r,o,d){if(!Number.isFinite(t.width)||!Number.isFinite(t.height)||t.width<=0||t.height<=0)return null;let h=(o-t.left)*r.width/t.width,f=(d-t.top)*r.height/t.height;return Number.isFinite(h)&&Number.isFinite(f)?{x:h,y:f}:null}function X(t,r){for(let o of t){if(o.id===r)return o;let d=X(o.children,r);if(d)return d}return null}function Ye(t,r){for(let o of t.shapes)if(o.id===r||X(o.children,r))return o;return null}function pe(t){return t.width>0&&t.height>0}function Ge(t,r,o){let d=new Set;qe(o,d);let h=r.primitives.filter(m=>m.shapeId&&d.has(m.shapeId));if(h.length===0)return o.width<=0||o.height<=0||t.widthEmu<=0||t.heightEmu<=0?null:{x:o.x*r.width/t.widthEmu,y:o.y*r.height/t.heightEmu,width:o.width*r.width/t.widthEmu,height:o.height*r.height/t.heightEmu};let f=h.map(m=>{let A=(m.transform?.rotationDeg??0)*Math.PI/180,U=Math.abs(m.w*Math.cos(A))+Math.abs(m.h*Math.sin(A)),g=Math.abs(m.w*Math.sin(A))+Math.abs(m.h*Math.cos(A));return {x:m.x+(m.w-U)/2,y:m.y+(m.h-g)/2,width:U,height:g}}),S=Math.min(...f.map(m=>m.x)),z=Math.min(...f.map(m=>m.y)),l=Math.max(...f.map(m=>m.x+m.width)),I=Math.max(...f.map(m=>m.y+m.height));return {x:S,y:z,width:l-S,height:I-z}}function Oe(t,r,o,d){let h=t.primitives.find(l=>l.kind==="textBox"&&l.shapeId===r&&l.storyId===o);if(!h||h.lines.length===0)return null;let f=h.lines.reduce((l,I)=>Ke(I.y,I.height,d.y)<Ke(l.y,l.height,d.y)?I:l),S=f.caretStops[0];return S?f.caretStops.reduce((l,I)=>Math.abs(I.x-d.x)<Math.abs(l.x-d.x)?I:l,S).position:f.start}function je(t,r,o,d){return {x:o.x+Math.round(d.x*t.widthEmu/r.width),y:o.y+Math.round(d.y*t.heightEmu/r.height)}}function We(t,r,o,d,h=4){return Math.hypot(o-t,d-r)>=h}function qe(t,r){r.add(t.id);for(let o of t.children)qe(o,r);}function Ke(t,r,o){return o<t?t-o:o>t+r?o-t-r:0}var mt={bold:false,italic:false,fontSizePt:24,color:"#111827"};function $({name:t}){return jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",style:{flex:"0 0 auto"},children:[t==="undo"&&jsx("path",{d:"m9 7-5 5 5 5M5 12h9a6 6 0 0 1 6 6"}),t==="redo"&&jsx("path",{d:"m15 7 5 5-5 5m4-5h-9a6 6 0 0 0-6 6"}),t==="addSlide"&&jsxs(Fragment,{children:[jsx("rect",{x:"3",y:"5",width:"14",height:"14",rx:"2"}),jsx("path",{d:"M7 9h6M7 13h4M20 10v6m-3-3h6"})]}),t==="deleteSlide"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 7h14M9 7V4h6v3m2 0-1 13H8L7 7"}),jsx("path",{d:"M10 11v5m4-5v5"})]}),t==="textBox"&&jsxs(Fragment,{children:[jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),jsx("path",{d:"M8 8h8m-4 0v8m-3 0h6"})]})]})}function bt({i18n:t,...r}){return jsx(ne,{i18n:t,children:jsx(xt,{...r})})}function xt({file:t,fonts:r,clientId:o,collaboration:d,className:h,onReady:f,onChange:S,onError:z}){let{t:l}=re(),I=l("errors.decodeSlideImage"),m=d?.clientId??o,A=d?.initialUpdate,U=d?.onReplica,g=useRef(null),F=useRef(null),ge=useRef(f),Se=useRef(S),Ie=useRef(z),V=useRef(null),Pe=useRef(null),ve=useRef(null),we=useRef(null),P=useRef(null),v=useRef(null),ie=useRef(new Map),ae=St(r),[y,Ce]=useState(null),[c,C]=useState(null),[J,T]=useState(null),[le,k]=useState(null),[D,Ze]=useState(mt),[Q,$e]=useState({width:0,height:0}),[Me,se]=useState(null),[et,ee]=useState(false),[de,Te]=useState(null);ge.current=f,Se.current=S,Ie.current=z,F.current=y;let w=useCallback(e=>{let n=e instanceof Error?e:new Error(String(e));se(n.message),Ie.current?.(n);},[]),L=useCallback((e,n=false,i=false)=>{let s=g.current;if(!s)return null;try{let a=s.snapshot(),p=gt(e??F.current?.slideIndex??0,a.slides.length),b=new Map;for(let M=0;M<a.slides.length;M+=1){let ce=a.slides[M],De=F.current?.thumbnails.get(ce.id);M!==p&&De&&!i?b.set(ce.id,De):M!==p&&b.set(ce.id,s.layoutSlide(M));}let H=a.slides.length>0?s.layoutSlide(p):null;H&&b.set(a.slides[p].id,H);let W={snapshot:a,slideIndex:p,frame:H,thumbnails:b},Y=a.slides[p];C(M=>M&&Y&&X(Y.shapes,M.shapeId)?M:null),T(M=>M&&Y?.id===M.slideId&&X(Y.shapes,M.shapeId)?M:null);let ue=P.current;return ue&&(!Y||Y.id!==ue.slideId||!X(Y.shapes,ue.shapeId))&&(P.current=null,v.current=null,k(null)),F.current=W,Ce(W),se(null),n&&Se.current?.(a),W}catch(a){return w(a),null}},[w]),ke=useCallback(()=>{L(void 0,false,true);},[L]);useEffect(()=>{let e=false,n=null,i=[],s=()=>{};if(g.current?.dispose(),g.current=null,Te(null),F.current=null,Ce(null),C(null),T(null),k(null),P.current=null,v.current=null,se(null),ie.current.clear(),!!t)return ee(true),Promise.all([initWasm(),Mt(ae)]).then(([,a])=>{if(i=a,e){_e(i);return}try{n=openPresentation(t,{clientId:m,fonts:ae,initialUpdate:A}),g.current=n,s=n.onUpdate((p,b)=>{b==="remote"&&L(void 0,!0,!0);}),L(0),ee(!1),Te(n),ge.current?.({handle:n,refresh:ke});}catch(p){ee(false),w(p);}},a=>{e||(ee(false),w(a));}),()=>{e=true,s(),n?.dispose(),g.current===n&&(g.current=null),_e(i);}},[m,A,t,ae,ke,L,w]),useEffect(()=>{if(!(!U||!de))return U(de),()=>U(null)},[U,de]),useEffect(()=>{let e=Pe.current;if(!e)return;let n=()=>$e({width:e.clientWidth,height:e.clientHeight});n();let i=new ResizeObserver(n);return i.observe(e),()=>i.disconnect()},[]);let B=useMemo(()=>!y?.frame||Q.width<=0||Q.height<=0?1:Math.min((Q.width-40)/y.frame.width,(Q.height-40)/y.frame.height,1),[y?.frame,Q]);useEffect(()=>{let e=ve.current,n=y?.frame;if(!e||!n)return;let i=e.getContext("2d");if(!i)return;let s=window.devicePixelRatio||1;sizeCanvasForSlide(e,n,s,B);let a=false;return paintSlide(i,n,s,B,{resolveImage:p=>Ve(p,g,ie,I)}).catch(p=>{a||w(p);}),()=>{a=true;}},[I,y?.frame,w,B]),useEffect(()=>{let e=we.current,n=y?.frame;if(!e||!n)return;let i=e.getContext("2d");if(!i)return;let s=window.devicePixelRatio||1;sizeCanvasForSlide(e,n,s,B),kt(i,n,c,s,B);},[y?.frame,B,c]);let K=useMemo(()=>{if(!y?.frame||!J)return null;let e=y.snapshot.slides[y.slideIndex];return !e||e.id!==J.slideId?null:X(e.shapes,J.shapeId)},[y,J]),Z=useMemo(()=>y?.frame&&K?Ge(y.snapshot,y.frame,K):null,[y,K]),tt=e=>{C(null),T(null),k(null),P.current=null,v.current=null,L(e),V.current?.focus();},nt=e=>{if(!e.isPrimary||e.button!==0)return;let n=g.current,i=F.current;if(!n||!i?.frame)return;let s=oe(e.currentTarget.getBoundingClientRect(),i.frame,e.clientX,e.clientY);if(s)try{n.layoutSlide(i.slideIndex);let a=n.hitTest(s.x,s.y),p=i.snapshot.slides[i.slideIndex];if(p&&c&&a?.kind==="text"&&a.shapeId===c.shapeId&&a.storyId===c.storyId){n.story(a.storyId);let b=e.shiftKey?c.anchor:a.position;C({shapeId:a.shapeId,storyId:a.storyId,anchor:b,focus:a.position}),T(null),k(null),v.current=null,P.current={kind:"text",pointerId:e.pointerId,slideId:p.id,shapeId:a.shapeId,storyId:a.storyId,anchor:b},e.currentTarget.setPointerCapture(e.pointerId);}else if(p&&a){let b=Ye(p,a.shapeId);if(b){C(null),T({slideId:p.id,shapeId:b.id}),k(null);let H=v.current,W=H?.slideId===p.id&&H.shapeId===b.id&&e.timeStamp-H.timeStamp<=600&&Math.hypot(e.clientX-H.clientX,e.clientY-H.clientY)<=6;v.current=null,pe(b)?(P.current={kind:"shape",pointerId:e.pointerId,slideId:p.id,shapeId:b.id,startClientX:e.clientX,startClientY:e.clientY,start:s,last:s,dragThreshold:W?8:4,repeatedClick:W,dragging:!1},e.currentTarget.setPointerCapture(e.pointerId)):P.current=null;}else C(null),T(null),v.current=null,P.current=null;}else C(null),T(null),k(null),v.current=null,P.current=null;V.current?.focus(),e.preventDefault();}catch(a){w(a);}},rt=e=>{if(e.button!==0)return;let n=g.current,i=F.current;if(!n||!i?.frame)return;let s=oe(e.currentTarget.getBoundingClientRect(),i.frame,e.clientX,e.clientY);if(s)try{n.layoutSlide(i.slideIndex);let a=n.hitTest(s.x,s.y);a?.kind==="text"&&(n.story(a.storyId),C({shapeId:a.shapeId,storyId:a.storyId,anchor:a.position,focus:a.position}),T(null),k(null),P.current=null,v.current=null,V.current?.focus(),e.preventDefault());}catch(a){w(a);}},Ee=e=>{let n=P.current,i=F.current;if(!n||n.pointerId!==e.pointerId||!i?.frame)return false;let s=oe(e.currentTarget.getBoundingClientRect(),i.frame,e.clientX,e.clientY);if(!s||i.snapshot.slides[i.slideIndex]?.id!==n.slideId)return false;if(n.kind==="text"){let a=Oe(i.frame,n.shapeId,n.storyId,s);a!==null&&C({shapeId:n.shapeId,storyId:n.storyId,anchor:n.anchor,focus:a});}else n.last=s,!n.dragging&&We(n.startClientX,n.startClientY,e.clientX,e.clientY,n.dragThreshold)&&(n.dragging=true),n.dragging&&k({shapeId:n.shapeId,delta:{x:s.x-n.start.x,y:s.y-n.start.y}});return true},ot=e=>{Ee(e)&&e.preventDefault();},it=e=>{Ee(e);let n=P.current;if(!n||n.pointerId!==e.pointerId||(P.current=null,k(null),e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),n.kind!=="shape"))return;if(!n.dragging){v.current=n.repeatedClick?null:{slideId:n.slideId,shapeId:n.shapeId,clientX:e.clientX,clientY:e.clientY,timeStamp:e.timeStamp};return}v.current=null;let i=g.current,s=F.current,a=s?.snapshot.slides[s.slideIndex];if(!i||!s?.frame||a?.id!==n.slideId)return;let p=X(a.shapes,n.shapeId);if(p)try{let b=je(s.snapshot,s.frame,p,{x:n.last.x-n.start.x,y:n.last.y-n.start.y});(b.x!==p.x||b.y!==p.y)&&(i.moveShape(a.id,p.id,b.x,b.y),L(void 0,!0)),T({slideId:a.id,shapeId:p.id}),e.preventDefault();}catch(b){w(b);}},Le=e=>{P.current?.pointerId===e.pointerId&&(P.current=null,k(null),v.current=null);},G=e=>{C(e),T(null),v.current=null,L(void 0,true);},at=e=>{let n=g.current;if(!n||!c)return;if((e.metaKey||e.ctrlKey)&&(e.key==="b"||e.key==="B")){e.preventDefault(),O({bold:!D.bold});return}if((e.metaKey||e.ctrlKey)&&(e.key==="i"||e.key==="I")){e.preventDefault(),O({italic:!D.italic});return}let i=Math.min(c.anchor,c.focus),s=Math.max(c.anchor,c.focus);try{if(e.key==="ArrowLeft"||e.key==="ArrowRight"){e.preventDefault();let a=n.story(c.storyId),p=e.key==="ArrowLeft"?-1:1,b=Math.max(0,Math.min(a.length,c.focus+p));C({...c,anchor:e.shiftKey?c.anchor:b,focus:b});return}if(e.key==="Backspace"){if(e.preventDefault(),i!==s){n.deleteText(c.storyId,i,s),G({...c,anchor:i,focus:i});return}let a=wt(n.story(c.storyId),i);a<i&&(n.deleteText(c.storyId,a,i),G({...c,anchor:a,focus:a}));return}if(e.key==="Delete"){if(e.preventDefault(),i!==s){n.deleteText(c.storyId,i,s),G({...c,anchor:i,focus:i});return}let a=Ct(n.story(c.storyId),s);a>s&&(n.deleteText(c.storyId,s,a),G({...c,anchor:s,focus:s}));return}if(e.key==="Enter"){e.preventDefault(),i!==s&&n.deleteText(c.storyId,i,s),n.insertParagraphBreak(c.storyId,i),G({...c,anchor:i+1,focus:i+1});return}if(e.key.length>0&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&Array.from(e.key).length===1){e.preventDefault(),i!==s&&n.deleteText(c.storyId,i,s),n.insertText(c.storyId,i,e.key,D);let a=i+e.key.length;G({...c,anchor:a,focus:a});}}catch(a){w(a);}},O=e=>{Ze(i=>({...i,...e}));let n=g.current;if(!(!n||!c||c.anchor===c.focus))try{n.formatText(c.storyId,Math.min(c.anchor,c.focus),Math.max(c.anchor,c.focus),e),L(void 0,!0);}catch(i){w(i);}},lt=()=>{let e=g.current,n=F.current;if(!(!e||!n))try{let i=n.slideIndex+1,s=n.snapshot.slides[n.slideIndex]?.layoutPartPath??void 0;e.insertSlide(i,s),C(null),T(null),k(null),P.current=null,v.current=null,L(i,!0,!0);}catch(i){w(i);}},st=()=>{let e=g.current,n=F.current;if(!(!e||!n||n.snapshot.slides.length<=1))try{e.deleteSlide(n.snapshot.slides[n.slideIndex].id),C(null),T(null),k(null),P.current=null,v.current=null,L(Math.max(0,n.slideIndex-1),!0,!0);}catch(i){w(i);}},dt=()=>{let e=g.current,n=F.current;if(!e||!n)return;let i=n.snapshot.slides[n.slideIndex];if(i)try{let s=e.addTextBox(i.id,{name:l("objects.defaultTextBoxName"),rect:{x:Math.round(n.snapshot.widthEmu*.15),y:Math.round(n.snapshot.heightEmu*.25),width:Math.round(n.snapshot.widthEmu*.7),height:Math.round(n.snapshot.heightEmu*.3)},text:"",style:D}),a=L(void 0,!0);T(null),k(null),P.current=null,v.current=null;let p=a?.snapshot.slides[a.slideIndex]?.shapes.find(H=>H.id===s.shapeId),b=p?.textStories[0];b&&(C({shapeId:p.id,storyId:b.id,anchor:0,focus:0}),V.current?.focus());}catch(s){w(s);}},Re=e=>{let n=g.current;if(n)try{e==="undo"?n.undo():n.redo(),C(null),T(null),k(null),P.current=null,v.current=null,L(void 0,!0);}catch(i){w(i);}},j=y?.snapshot.slides.length??0,te=y?.slideIndex??0,Fe=le&&le.shapeId===J?.shapeId?le.delta:null,ut=K?pe(K):false;return jsxs("div",{className:h,style:x.root,children:[jsx("div",{style:x.toolbarShell,children:jsxs("div",{style:x.toolbar,role:"group","aria-label":l("toolbar.label"),children:[jsxs("div",{style:x.toolbarGroup,role:"group","aria-label":l("toolbar.historyLabel"),children:[jsx("button",{type:"button",style:_(g.current?.canUndo()??false),disabled:!g.current?.canUndo(),"aria-label":l("toolbar.undo"),title:l("toolbar.undo"),onClick:()=>Re("undo"),children:jsx($,{name:"undo"})}),jsx("button",{type:"button",style:_(g.current?.canRedo()??false),disabled:!g.current?.canRedo(),"aria-label":l("toolbar.redo"),title:l("toolbar.redo"),onClick:()=>Re("redo"),children:jsx($,{name:"redo"})})]}),jsx("span",{style:x.divider,"aria-hidden":"true"}),jsxs("div",{style:x.toolbarGroup,role:"group","aria-label":l("toolbar.textFormattingLabel"),children:[jsx("button",{type:"button","aria-pressed":D.bold,"aria-label":l("toolbar.bold"),title:l("toolbar.bold"),style:Je(D.bold),onClick:()=>O({bold:!D.bold}),children:"B"}),jsx("button",{type:"button","aria-pressed":D.italic,"aria-label":l("toolbar.italic"),title:l("toolbar.italic"),style:{...Je(D.italic),fontStyle:"italic"},onClick:()=>O({italic:!D.italic}),children:"I"}),jsx("input",{"aria-label":l("toolbar.fontSize"),title:l("toolbar.fontSize"),type:"number",min:6,max:400,value:D.fontSizePt,style:x.numberInput,onChange:e=>{let n=Number(e.target.value);Number.isFinite(n)&&O({fontSizePt:n});}}),jsx("input",{"aria-label":l("toolbar.textColor"),title:l("toolbar.textColor"),type:"color",value:D.color,style:x.colorInput,onChange:e=>O({color:e.target.value})})]}),jsx("span",{style:x.divider,"aria-hidden":"true"}),jsxs("div",{style:x.toolbarGroup,role:"group","aria-label":l("toolbar.slidesLabel"),children:[jsx("button",{type:"button",style:_(true),"aria-label":l("toolbar.addSlide"),title:l("toolbar.addSlide"),onClick:lt,children:jsx($,{name:"addSlide"})}),jsx("button",{type:"button",style:_(j>1),disabled:j<=1,"aria-label":l("toolbar.deleteSlide"),title:l("toolbar.deleteSlide"),onClick:st,children:jsx($,{name:"deleteSlide"})})]}),jsx("span",{style:x.divider,"aria-hidden":"true"}),jsx("div",{style:x.toolbarGroup,role:"group","aria-label":l("toolbar.objectsLabel"),children:jsx("button",{type:"button",style:_(j>0),disabled:j===0,"aria-label":l("toolbar.addTextBox"),title:l("toolbar.addTextBox"),onClick:dt,children:jsx($,{name:"textBox"})})})]})}),jsxs("div",{style:x.workspace,children:[jsx("aside",{style:x.slideStrip,"aria-label":l("slides.panelLabel"),children:y?.snapshot.slides.map((e,n)=>jsxs("button",{type:"button","aria-current":n===te?"page":void 0,style:Lt(n===te),onClick:()=>tt(n),children:[jsx("span",{style:x.slideNumber,children:n+1}),jsx("span",{style:x.slidePreview,children:y.thumbnails.get(e.id)?jsx(yt,{frame:y.thumbnails.get(e.id),resolveImage:i=>Ve(i,g,ie,I)}):jsx("span",{style:x.slideTitle,children:Et(e.shapes)||l("slides.fallbackTitle",{number:n+1})})})]},e.id))}),jsxs("div",{ref:V,style:x.stage,tabIndex:0,role:"application","aria-label":l("editor.appLabel"),onKeyDown:at,children:[jsx("div",{ref:Pe,style:x.canvasHost,children:y?.frame?jsxs("div",{style:{...x.canvasFrame,width:y.frame.width*B,height:y.frame.height*B},children:[jsx("canvas",{ref:ve,style:{...x.canvas,cursor:c?"text":ut?"move":"default"},onPointerDown:nt,onPointerMove:ot,onPointerUp:it,onPointerCancel:Le,onLostPointerCapture:Le,onDoubleClick:rt,"aria-label":K?l("slides.canvasLabelWithSelection",{current:te+1,total:j,name:K.name}):l("slides.canvasLabel",{current:te+1,total:j})}),jsx("canvas",{ref:we,style:x.canvasOverlay,"aria-hidden":"true"}),Z?jsx("span",{style:{...x.shapeSelection,left:(Z.x+(Fe?.x??0))*B,top:(Z.y+(Fe?.y??0))*B,width:Math.max(1,Z.width*B),height:Math.max(1,Z.height*B)},"aria-hidden":"true"}):null]}):jsx("div",{style:x.empty,children:l(et?"editor.opening":t?"editor.noSlides":"editor.openPrompt")})}),Me?jsx("div",{style:x.error,children:Me}):null]})]})]})}function yt({frame:t,resolveImage:r}){let o=useRef(null);return useEffect(()=>{let d=o.current;if(!d)return;let h=d.getContext("2d");if(!h)return;let f=128/t.width,S=window.devicePixelRatio||1;sizeCanvasForSlide(d,t,S,f),paintSlide(h,t,S,f,{resolveImage:r}).catch(()=>{});},[t,r]),jsx("canvas",{ref:o,style:x.thumbnailCanvas,"aria-hidden":"true"})}function gt(t,r){return r===0?0:Math.max(0,Math.min(r-1,t))}function St(t){let r=useRef(t);return It(r.current,t)||(r.current=t),r.current}function It(t,r){return t===r?true:t.length!==r.length?false:t.every((o,d)=>Pt(o,r[d]))}function Pt(t,r){return t.family===r.family&&(t.bold??false)===(r.bold??false)&&(t.italic??false)===(r.italic??false)&&vt(t.bytes,r.bytes)}function vt(t,r){return t===r?true:t.byteLength!==r.byteLength?false:t.every((o,d)=>o===r[d])}function ye(t){return t.paragraphs.map(r=>r.runs.map(o=>o.text).join("")).join(`
|
|
2
|
-
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betteroffice/pptx-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
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",
|
|
@@ -34,14 +34,17 @@
|
|
|
34
34
|
"typecheck": "tsc --noEmit -p ."
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@betteroffice/pptx": "0.0.
|
|
38
|
-
"@betteroffice/pptx-i18n": "0.0.
|
|
37
|
+
"@betteroffice/pptx": "0.0.3",
|
|
38
|
+
"@betteroffice/pptx-i18n": "0.0.3"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": "^18.0.0 || ^19.0.0",
|
|
42
42
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
+
"@happy-dom/global-registrator": "^20.8.3",
|
|
46
|
+
"@testing-library/react": "^16.0.0",
|
|
47
|
+
"@types/bun": "^1.3.14",
|
|
45
48
|
"@types/react": "^19.2.17",
|
|
46
49
|
"@types/react-dom": "^19.2.3",
|
|
47
50
|
"react": "^19.2.7",
|