@betteroffice/pptx-react 0.0.2 → 0.0.4
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 +45 -12
- package/dist/index.d.ts +187 -4
- package/dist/index.js +4 -2
- package/package.json +12 -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,38 @@ 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/fonts`](https://www.npmjs.com/package/@betteroffice/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`, `fileName`,
|
|
50
|
+
`onReady` (exposes the core `PresentationHandle`, a `refresh` callback for
|
|
51
|
+
host-driven edits, and `save`), `onChange` (deck snapshots), `onError`, and
|
|
52
|
+
`onSave` (receives the saved bytes; without it, saving downloads the file).
|
|
53
|
+
|
|
54
|
+
## What works today
|
|
55
|
+
|
|
56
|
+
- Slide rendering with Rust layout and text shaping, painted onto canvas
|
|
57
|
+
- Canvas interactions: shape selection, drag, and resize
|
|
58
|
+
- Text editing with caret and selection computed by the engine
|
|
59
|
+
- Slide management (add, delete), text boxes, undo/redo
|
|
60
|
+
- Saving the deck back to `.pptx` — toolbar button, Ctrl/Cmd+S, or `api.save()`
|
|
61
|
+
- Localized UI via the `i18n` prop
|
|
62
|
+
([`@betteroffice/pptx-i18n`](https://www.npmjs.com/package/@betteroffice/pptx-i18n))
|
|
63
|
+
- Real-time collaboration with people or agents; the deck is a CRDT
|
|
64
|
+
- Live collaborator shape selections and presence chips, shown in each peer's color
|
|
40
65
|
|
|
41
66
|
## Collaboration
|
|
42
67
|
|
|
@@ -45,20 +70,28 @@ session; drive it with a `CollaborationProvider` over any transport. Every peer
|
|
|
45
70
|
must boot from the same `initialUpdate` seed.
|
|
46
71
|
|
|
47
72
|
```tsx
|
|
48
|
-
import { CollaborationProvider } from '@betteroffice/pptx
|
|
73
|
+
import { CollaborationProvider } from '@betteroffice/pptx';
|
|
49
74
|
|
|
50
75
|
<PptxEditor
|
|
51
76
|
file={file}
|
|
77
|
+
fonts={fonts}
|
|
52
78
|
collaboration={{
|
|
53
79
|
clientId,
|
|
54
80
|
initialUpdate: sharedSeed,
|
|
55
81
|
onReplica: (replica) => {
|
|
56
82
|
if (!replica) return;
|
|
57
|
-
const provider = new CollaborationProvider(replica, transport
|
|
83
|
+
const provider = new CollaborationProvider(replica, transport, {
|
|
84
|
+
user: { name: "Ada" }, // shown on this peer's presence chip
|
|
85
|
+
});
|
|
58
86
|
provider.connect();
|
|
59
87
|
},
|
|
60
88
|
}}
|
|
61
89
|
/>;
|
|
62
90
|
```
|
|
63
91
|
|
|
92
|
+
## Framework notes
|
|
93
|
+
|
|
94
|
+
The editor is browser-only (canvas, wasm); under Next.js load it with
|
|
95
|
+
`next/dynamic` and `ssr: false`.
|
|
96
|
+
|
|
64
97
|
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 {
|
|
@@ -13,11 +12,14 @@ interface PptxTextSelection {
|
|
|
13
12
|
interface PptxEditorApi {
|
|
14
13
|
handle: PresentationHandle;
|
|
15
14
|
refresh: () => void;
|
|
15
|
+
/** Serialize the presentation back to .pptx bytes, edits included. */
|
|
16
|
+
save: () => Uint8Array;
|
|
16
17
|
}
|
|
17
18
|
interface PptxEditorCollaborationOptions {
|
|
18
19
|
clientId: number;
|
|
19
20
|
initialUpdate?: Uint8Array;
|
|
20
21
|
onReplica?: (replica: CollaborationReplica | null) => void;
|
|
22
|
+
presence?: PptxPresence;
|
|
21
23
|
}
|
|
22
24
|
interface PptxEditorProps {
|
|
23
25
|
file?: Uint8Array;
|
|
@@ -27,12 +29,193 @@ interface PptxEditorProps {
|
|
|
27
29
|
collaboration?: PptxEditorCollaborationOptions;
|
|
28
30
|
i18n?: Translations;
|
|
29
31
|
className?: string;
|
|
32
|
+
/** Download name for the save button; falls back to `presentation.pptx`. */
|
|
33
|
+
fileName?: string;
|
|
30
34
|
onReady?: (api: PptxEditorApi) => void;
|
|
31
35
|
onChange?: (snapshot: DeckSnapshot) => void;
|
|
32
36
|
onError?: (error: Error) => void;
|
|
37
|
+
/** Receives the saved bytes; without it, saving downloads the file. */
|
|
38
|
+
onSave?: (bytes: Uint8Array) => void;
|
|
33
39
|
}
|
|
34
40
|
declare function PptxEditor({ i18n, ...props }: PptxEditorProps): react.JSX.Element;
|
|
35
41
|
|
|
42
|
+
declare const SHAPE_PRESETS: readonly [{
|
|
43
|
+
readonly geometry: "rect";
|
|
44
|
+
readonly labelKey: "toolbar.shapes.rect";
|
|
45
|
+
}, {
|
|
46
|
+
readonly geometry: "roundRect";
|
|
47
|
+
readonly labelKey: "toolbar.shapes.roundRect";
|
|
48
|
+
}, {
|
|
49
|
+
readonly geometry: "ellipse";
|
|
50
|
+
readonly labelKey: "toolbar.shapes.ellipse";
|
|
51
|
+
}, {
|
|
52
|
+
readonly geometry: "triangle";
|
|
53
|
+
readonly labelKey: "toolbar.shapes.triangle";
|
|
54
|
+
}, {
|
|
55
|
+
readonly geometry: "rtTriangle";
|
|
56
|
+
readonly labelKey: "toolbar.shapes.rtTriangle";
|
|
57
|
+
}, {
|
|
58
|
+
readonly geometry: "diamond";
|
|
59
|
+
readonly labelKey: "toolbar.shapes.diamond";
|
|
60
|
+
}, {
|
|
61
|
+
readonly geometry: "parallelogram";
|
|
62
|
+
readonly labelKey: "toolbar.shapes.parallelogram";
|
|
63
|
+
}, {
|
|
64
|
+
readonly geometry: "trapezoid";
|
|
65
|
+
readonly labelKey: "toolbar.shapes.trapezoid";
|
|
66
|
+
}, {
|
|
67
|
+
readonly geometry: "pentagon";
|
|
68
|
+
readonly labelKey: "toolbar.shapes.pentagon";
|
|
69
|
+
}, {
|
|
70
|
+
readonly geometry: "hexagon";
|
|
71
|
+
readonly labelKey: "toolbar.shapes.hexagon";
|
|
72
|
+
}, {
|
|
73
|
+
readonly geometry: "octagon";
|
|
74
|
+
readonly labelKey: "toolbar.shapes.octagon";
|
|
75
|
+
}, {
|
|
76
|
+
readonly geometry: "star5";
|
|
77
|
+
readonly labelKey: "toolbar.shapes.star5";
|
|
78
|
+
}, {
|
|
79
|
+
readonly geometry: "rightArrow";
|
|
80
|
+
readonly labelKey: "toolbar.shapes.rightArrow";
|
|
81
|
+
}, {
|
|
82
|
+
readonly geometry: "leftArrow";
|
|
83
|
+
readonly labelKey: "toolbar.shapes.leftArrow";
|
|
84
|
+
}, {
|
|
85
|
+
readonly geometry: "upArrow";
|
|
86
|
+
readonly labelKey: "toolbar.shapes.upArrow";
|
|
87
|
+
}, {
|
|
88
|
+
readonly geometry: "downArrow";
|
|
89
|
+
readonly labelKey: "toolbar.shapes.downArrow";
|
|
90
|
+
}, {
|
|
91
|
+
readonly geometry: "chevron";
|
|
92
|
+
readonly labelKey: "toolbar.shapes.chevron";
|
|
93
|
+
}];
|
|
94
|
+
type PptxShapePreset = (typeof SHAPE_PRESETS)[number]['geometry'];
|
|
95
|
+
type PptxEditorTool = 'select' | 'textBox' | `shape:${PptxShapePreset}`;
|
|
96
|
+
type PptxZoom = number | 'fit';
|
|
97
|
+
interface SelectionFormatting {
|
|
98
|
+
fontFamily?: string;
|
|
99
|
+
fontSize?: number;
|
|
100
|
+
bold?: boolean;
|
|
101
|
+
italic?: boolean;
|
|
102
|
+
underline?: boolean;
|
|
103
|
+
textColor?: string;
|
|
104
|
+
}
|
|
105
|
+
type FormattingAction = 'bold' | 'italic' | 'underline' | {
|
|
106
|
+
type: 'fontFamily';
|
|
107
|
+
value: string;
|
|
108
|
+
} | {
|
|
109
|
+
type: 'fontSize';
|
|
110
|
+
value: number;
|
|
111
|
+
} | {
|
|
112
|
+
type: 'textColor';
|
|
113
|
+
value: string;
|
|
114
|
+
};
|
|
115
|
+
interface ShapeFormatting {
|
|
116
|
+
geometry?: string;
|
|
117
|
+
fillColor?: string | null;
|
|
118
|
+
strokeColor?: string | null;
|
|
119
|
+
strokeWidthPt?: number | null;
|
|
120
|
+
adjustments?: Record<string, number>;
|
|
121
|
+
}
|
|
122
|
+
type ShapeFormattingAction = {
|
|
123
|
+
type: 'fillColor';
|
|
124
|
+
value: string | null;
|
|
125
|
+
} | {
|
|
126
|
+
type: 'strokeColor';
|
|
127
|
+
value: string | null;
|
|
128
|
+
} | {
|
|
129
|
+
type: 'strokeWidth';
|
|
130
|
+
value: number | null;
|
|
131
|
+
} | {
|
|
132
|
+
type: 'adjust';
|
|
133
|
+
name: string;
|
|
134
|
+
value: number;
|
|
135
|
+
};
|
|
136
|
+
interface SlideLayoutOption {
|
|
137
|
+
partPath: string | null;
|
|
138
|
+
label?: string;
|
|
139
|
+
}
|
|
140
|
+
interface ToolbarProps {
|
|
141
|
+
currentFormatting?: SelectionFormatting;
|
|
142
|
+
textSelectionActive?: boolean;
|
|
143
|
+
onFormat?: (action: FormattingAction) => void;
|
|
144
|
+
currentShapeFormatting?: ShapeFormatting;
|
|
145
|
+
shapeSelectionActive?: boolean;
|
|
146
|
+
onShapeFormat?: (action: ShapeFormattingAction) => void;
|
|
147
|
+
onInsertSlide?: (layoutPartPath?: string | null) => void;
|
|
148
|
+
slideLayouts?: readonly SlideLayoutOption[];
|
|
149
|
+
currentLayoutPartPath?: string | null;
|
|
150
|
+
onSave?: () => void;
|
|
151
|
+
onUndo?: () => void;
|
|
152
|
+
onRedo?: () => void;
|
|
153
|
+
canUndo?: boolean;
|
|
154
|
+
canRedo?: boolean;
|
|
155
|
+
zoom?: PptxZoom;
|
|
156
|
+
onZoomChange?: (zoom: PptxZoom) => void;
|
|
157
|
+
activeTool?: PptxEditorTool;
|
|
158
|
+
onToolChange?: (tool: PptxEditorTool) => void;
|
|
159
|
+
fontFamilies?: readonly string[];
|
|
160
|
+
fontSizes?: readonly number[];
|
|
161
|
+
disabled?: boolean;
|
|
162
|
+
className?: string;
|
|
163
|
+
style?: CSSProperties;
|
|
164
|
+
children?: ReactNode;
|
|
165
|
+
}
|
|
166
|
+
declare function Toolbar(explicitProps: ToolbarProps): react.JSX.Element;
|
|
167
|
+
|
|
168
|
+
type EditorToolbarProps = ToolbarProps;
|
|
169
|
+
declare const EditorToolbarContext: react.Context<ToolbarProps | null>;
|
|
170
|
+
declare function useEditorToolbar(): ToolbarProps;
|
|
171
|
+
|
|
172
|
+
interface EditorToolbarComponent {
|
|
173
|
+
(props: EditorToolbarProps & {
|
|
174
|
+
children: ReactNode;
|
|
175
|
+
}): React.JSX.Element;
|
|
176
|
+
Toolbar: typeof Toolbar;
|
|
177
|
+
}
|
|
178
|
+
declare const EditorToolbar: EditorToolbarComponent;
|
|
179
|
+
|
|
180
|
+
interface ToolbarButtonProps {
|
|
181
|
+
active?: boolean;
|
|
182
|
+
disabled?: boolean;
|
|
183
|
+
title: string;
|
|
184
|
+
onClick?: () => void;
|
|
185
|
+
children: ReactNode;
|
|
186
|
+
style?: CSSProperties;
|
|
187
|
+
testId?: string;
|
|
188
|
+
ariaExpanded?: boolean;
|
|
189
|
+
}
|
|
190
|
+
declare function ToolbarButton({ active, disabled, title, onClick, children, style, testId, ariaExpanded, }: ToolbarButtonProps): react.JSX.Element;
|
|
191
|
+
declare function ToolbarGroup({ label, children, style, }: {
|
|
192
|
+
label: string;
|
|
193
|
+
children: ReactNode;
|
|
194
|
+
style?: CSSProperties;
|
|
195
|
+
}): react.JSX.Element;
|
|
196
|
+
declare function ToolbarSeparator(): react.JSX.Element;
|
|
197
|
+
interface ToolbarDropdownProps {
|
|
198
|
+
title: string;
|
|
199
|
+
trigger: ReactNode;
|
|
200
|
+
children: (close: () => void) => ReactNode;
|
|
201
|
+
disabled?: boolean;
|
|
202
|
+
active?: boolean;
|
|
203
|
+
menuWidth?: number;
|
|
204
|
+
style?: CSSProperties;
|
|
205
|
+
testId?: string;
|
|
206
|
+
}
|
|
207
|
+
declare function ToolbarDropdown({ title, trigger, children, disabled, active, menuWidth, style, testId, }: ToolbarDropdownProps): react.JSX.Element;
|
|
208
|
+
interface ToolbarMenuItemProps {
|
|
209
|
+
label: string;
|
|
210
|
+
icon?: ReactNode;
|
|
211
|
+
selected?: boolean;
|
|
212
|
+
disabled?: boolean;
|
|
213
|
+
onClick?: () => void;
|
|
214
|
+
close?: () => void;
|
|
215
|
+
}
|
|
216
|
+
declare function ToolbarMenuItem({ label, icon, selected, disabled, onClick, close, }: ToolbarMenuItemProps): react.JSX.Element;
|
|
217
|
+
declare function ToolbarMenuSeparator(): react.JSX.Element;
|
|
218
|
+
|
|
36
219
|
interface LocaleProviderProps {
|
|
37
220
|
i18n?: Translations;
|
|
38
221
|
children: ReactNode;
|
|
@@ -42,4 +225,4 @@ declare function useTranslation(): {
|
|
|
42
225
|
t: TFunction;
|
|
43
226
|
};
|
|
44
227
|
|
|
45
|
-
export { LocaleProvider, type LocaleProviderProps, PptxEditor, type PptxEditorApi, type PptxEditorCollaborationOptions, type PptxEditorProps, type PptxTextSelection, useTranslation };
|
|
228
|
+
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 as en$1,deepMerge,createT}from'@betteroffice/pptx-i18n';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Ut=createContext(en$1),_t=createContext("en");function nt({i18n:e,children:t}){let n=typeof e?._lang=="string"?e._lang:"en",i=useMemo(()=>deepMerge(en$1,e),[e]);return jsx(_t.Provider,{value:n,children:jsx(Ut.Provider,{value:i,children:t})})}function Be(){let e=useContext(Ut),t=useContext(_t);return {t:useMemo(()=>createT(e,t),[e,t])}}var ze=createContext(null);function _o(){let e=useContext(ze);if(!e)throw new Error("useEditorToolbar must be used within an <EditorToolbar> component");return e}function D({name:e,size:t=20,style:n}){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,...n},children:[e==="save"&&jsx("path",{d:"M12 3v11m0 0 4-4m-4 4-4-4M5 19h14"}),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 w={text:"#3c4043",muted:"#5f6368",disabled:"#9aa0a6",hover:"#e2e7ef",active:"#d3e3fd",border:"#c7cacf",surface:"#ffffff",rail:"#edf2fa"},Xo={appearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:2,minWidth:28,height:28,padding:"0 5px",border:0,borderRadius:4,color:w.text,font:"500 13px ui-sans-serif, system-ui, sans-serif",lineHeight:1,whiteSpace:"nowrap",boxSizing:"border-box"};function Zt(e,t,n,i){return {...Xo,background:t?w.active:n&&!e?w.hover:"transparent",color:e?w.disabled:w.text,cursor:e?"default":"pointer",opacity:e?.48:1,...i}}function ae({active:e=false,disabled:t=false,title:n,onClick:i,children:a,style:l,testId:h,ariaExpanded:y}){let[b,x]=useState(false);return jsx("button",{type:"button","data-testid":h,disabled:t,"aria-label":n,"aria-pressed":e||void 0,"aria-expanded":y,title:n,onMouseDown:u=>u.preventDefault(),onMouseEnter:()=>x(true),onMouseLeave:()=>x(false),onClick:t?void 0:i,style:Zt(t,e,b,l),children:a})}function fe({label:e,children:t,style:n}){return jsx("div",{role:"group","aria-label":e,style:{display:"inline-flex",alignItems:"center",gap:1,flex:"0 0 auto",...n},children:t})}function Fe(){return jsx("div",{role:"separator",style:{width:1,height:24,margin:"0 5px",background:w.border,flex:"0 0 auto"}})}function Le({title:e,trigger:t,children:n,disabled:i=false,active:a=false,menuWidth:l=220,style:h,testId:y}){let[b,x]=useState(false),[u,T]=useState(false),[A,le]=useState({top:0,left:0}),Y=useRef(null),K=useRef(null),M=useCallback(()=>x(false),[]);return useEffect(()=>{if(!b||!Y.current)return;let C=Y.current.getBoundingClientRect(),q=Math.min(C.left,Math.max(8,window.innerWidth-l-8));le({top:C.bottom+4,left:q});},[b,l]),useEffect(()=>{if(!b)return;let C=ie=>{let U=ie.target;!Y.current?.contains(U)&&!K.current?.contains(U)&&M();},q=ie=>{ie.key==="Escape"&&M();},I=()=>M();return document.addEventListener("mousedown",C),document.addEventListener("keydown",q),window.addEventListener("scroll",I,true),()=>{document.removeEventListener("mousedown",C),document.removeEventListener("keydown",q),window.removeEventListener("scroll",I,true);}},[b,M]),jsxs("div",{style:{position:"relative",display:"inline-flex",flex:"0 0 auto"},children:[jsx("button",{ref:Y,type:"button","data-testid":y,disabled:i,"aria-label":e,"aria-haspopup":"menu","aria-expanded":b,title:e,onMouseDown:C=>C.preventDefault(),onMouseEnter:()=>T(true),onMouseLeave:()=>T(false),onClick:()=>!i&&x(C=>!C),style:Zt(i,a||b,u,h),children:t}),b&&jsx("div",{ref:K,role:"menu","aria-label":e,onMouseDown:C=>C.preventDefault(),style:{position:"fixed",top:A.top,left:A.left,zIndex:1e4,width:l,maxHeight:"min(440px, calc(100vh - 16px))",overflowY:"auto",padding:6,border:`1px solid ${w.border}`,borderRadius:8,background:w.surface,boxShadow:"0 4px 16px rgba(60, 64, 67, 0.24)",boxSizing:"border-box"},children:n(M)})]})}function He({label:e,icon:t,selected:n=false,disabled:i=false,onClick:a,close:l}){let[h,y]=useState(false);return jsxs("button",{type:"button",role:"menuitem",disabled:i,"aria-label":e,onMouseEnter:()=>y(true),onMouseLeave:()=>y(false),onClick:()=>{i||(a?.(),l?.());},style:{appearance:"none",display:"flex",alignItems:"center",gap:10,width:"100%",minHeight:32,padding:"5px 9px",border:0,borderRadius:4,background:h&&!i?w.hover:"transparent",color:i?w.disabled:w.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}),n&&jsx("span",{"aria-hidden":"true",children:"\u2713"})]})}function Zo(){return jsx("div",{role:"separator",style:{height:1,margin:"5px 2px",background:w.border}})}function rt({value:e,label:t,onChange:n,onClear:i,icon:a="textColor",none:l=false,clearLabel:h,disabled:y=false,testId:b}){let[x,u]=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:x&&!y?w.hover:"transparent",color:y?w.disabled:w.text,cursor:y?"default":"pointer",opacity:y?.48:1,boxSizing:"border-box",position:"relative"},onMouseEnter:()=>u(true),onMouseLeave:()=>u(false),children:[jsx(D,{name:a,size:20}),jsx("span",{"aria-hidden":"true",style:{position:"absolute",left:5,right:5,bottom:2,height:3,borderRadius:2,background:l?"transparent":e,border:l?`1px solid ${w.disabled}`:0,boxSizing:"border-box"}}),l?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":b,type:"color",value:e,disabled:y,"aria-label":t,onChange:T=>n?.(T.target.value),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0}})]}),i?jsx("button",{type:"button",disabled:y,"aria-label":h??t,title:h??t,onMouseDown:T=>T.preventDefault(),onClick:i,style:{appearance:"none",width:15,height:28,padding:0,border:0,borderRadius:3,background:"transparent",color:y?w.disabled:w.muted,cursor:y?"default":"pointer",opacity:y?.48:1,font:"500 14px ui-sans-serif, system-ui, sans-serif"},children:"\xD7"}):null]})}function it({value:e,options:t,label:n,onCommit:i,disabled:a=false,width:l=72,inputStyle:h,testId:y}){let[b,x]=useState(e),[u,T]=useState(false),[A,le]=useState({top:0,left:0,width:l}),Y=useRef(null),K=useRef(null),M=useRef(null);useEffect(()=>x(e),[e]);let C=useCallback(()=>T(false),[]);useEffect(()=>{if(!u||!Y.current)return;let I=Y.current.getBoundingClientRect();le({top:I.bottom+4,left:I.left,width:Math.max(I.width,l)});},[u,l]),useEffect(()=>{if(!u)return;let I=U=>{let ee=U.target;!Y.current?.contains(ee)&&!K.current?.contains(ee)&&C();},ie=U=>{U.key==="Escape"&&(x(e),C());};return document.addEventListener("mousedown",I),document.addEventListener("keydown",ie),()=>{document.removeEventListener("mousedown",I),document.removeEventListener("keydown",ie);}},[u,C,e]);let q=useCallback(()=>{!a&&i&&b.trim()&&i(b.trim()),x(e);},[a,i,b,e]);return jsxs("div",{ref:Y,style:{display:"inline-flex",alignItems:"center",width:l,height:28,border:`1px solid ${w.border}`,borderRadius:4,background:a?"rgba(255,255,255,0.5)":w.surface,opacity:a?.48:1,boxSizing:"border-box",flex:"0 0 auto"},children:[jsx("input",{ref:M,"data-testid":y,role:"combobox","aria-label":n,"aria-autocomplete":"list","aria-expanded":u,disabled:a,value:b,onFocus:I=>{a||(T(true),I.currentTarget.select());},onChange:I=>x(I.target.value),onKeyDown:I=>{I.key==="Enter"?(q(),C(),I.currentTarget.blur()):I.key==="ArrowDown"&&(T(true),I.preventDefault());},onBlur:()=>{requestAnimationFrame(()=>{K.current?.contains(document.activeElement)||q();});},style:{appearance:"none",width:"calc(100% - 22px)",height:26,padding:"0 2px 0 7px",border:0,outline:0,background:"transparent",color:w.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":n,title:n,onMouseDown:I=>I.preventDefault(),onClick:()=>{a||(T(I=>!I),M.current?.focus());},style:{appearance:"none",display:"grid",placeItems:"center",width:21,height:26,padding:0,border:0,background:"transparent",color:w.muted,cursor:a?"default":"pointer"},children:jsx(D,{name:"chevronDown",size:14})}),u&&!a&&jsx("div",{ref:K,role:"listbox","aria-label":n,style:{position:"fixed",top:A.top,left:A.left,zIndex:1e4,width:A.width,maxHeight:260,overflowY:"auto",padding:4,border:`1px solid ${w.border}`,borderRadius:6,background:w.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:ie=>ie.preventDefault(),onClick:()=>{x(I.label),i?.(I.value),C();},style:{appearance:"none",display:"block",width:"100%",minHeight:28,padding:"4px 7px",border:0,borderRadius:3,background:I.value===e?w.active:"transparent",color:w.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"}],Jo=[.5,.75,1,1.25,1.5,2],Qo=["Arial","Calibri","Cambria","Georgia","Roboto","Times New Roman","Verdana"],en=[8,9,10,11,12,14,16,18,20,24,28,36,48,72],tn=[1,2,3,4,8],on=[0,10,17,25,33,50],nn=[0,10,20,30,40,50,60,70,80,90,100];function rn(e){let t={};for(let n of Object.keys(e))e[n]!==void 0&&(t[n]=e[n]);return t}function an(e){let t=useContext(ze);return t?{...t,...rn(e)}:e}function $t(e,t,n){return n>0?t.find(i=>i>e)??e+1:[...t].reverse().find(i=>i<e)??Math.max(1,e-1)}function ln(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}=Be(),{currentFormatting:n={},textSelectionActive:i=false,onFormat:a,currentShapeFormatting:l={},shapeSelectionActive:h=false,onShapeFormat:y,onInsertSlide:b,slideLayouts:x=[],currentLayoutPartPath:u,onSave:T,onUndo:A,onRedo:le,canUndo:Y=false,canRedo:K=false,zoom:M="fit",onZoomChange:C,activeTool:q="select",onToolChange:I,fontFamilies:ie=Qo,fontSizes:U=en,disabled:ee=false,className:Qe,style:et,children:k}=an(e),O=useRef(null),[Oe,We]=useState(Number.POSITIVE_INFINITY),P=!ee&&i&&!!a,Te=!ee&&h&&!!y,f=!ee&&!!b,B=!ee&&!!I,z=n.fontSize??24,H=t("toolbar.fit"),Ae=M==="fit"?H:`${Math.round(M*100)}%`,N=ln(l.adjustments),te=l.geometry==="roundRect"&&N?.[0]==="adj";useEffect(()=>{let g=O.current;if(!g)return;let v=()=>We(g.clientWidth);v();let Se=new ResizeObserver(v);return Se.observe(g),()=>Se.disconnect()},[]);let j=useMemo(()=>[{value:H,label:H},...Jo.map(g=>({value:`${g*100}%`,label:`${g*100}%`}))],[H]),se=useMemo(()=>U.map(g=>({value:String(g),label:String(g)})),[U]),ue=g=>{P&&a?.(g);},he=g=>{Te&&y?.(g);},ge=[{key:"file",width:40,node:jsx(fe,{label:t("toolbar.groups.file"),children:jsx(ae,{title:t("toolbar.save"),disabled:ee||!T,onClick:T,testId:"pptx-save",children:jsx(D,{name:"save",size:18})})})},{key:"new-slide",width:59,node:jsxs(fe,{label:t("toolbar.groups.slides"),children:[jsx(ae,{title:t("toolbar.newSlide"),disabled:!f,onClick:()=>b?.(),style:{borderRadius:"4px 0 0 4px"},testId:"pptx-new-slide",children:jsx(D,{name:"newSlide"})}),jsx(Le,{title:t("toolbar.newSlideWithLayout"),disabled:!f||x.length===0,menuWidth:230,testId:"pptx-new-slide-layout",style:{minWidth:20,width:20,padding:0,borderRadius:"0 4px 4px 0"},trigger:jsx(D,{name:"chevronDown",size:13}),children:g=>jsx(Fragment,{children:x.map((v,Se)=>jsx(He,{label:v.label??t("toolbar.layoutOption",{number:Se+1}),selected:(v.partPath??null)===(u??null),onClick:()=>b?.(v.partPath),close:g},v.partPath??`default-${Se}`))})})]})},{key:"history",width:75,node:jsxs(Fragment,{children:[jsx(Fe,{}),jsxs(fe,{label:t("toolbar.groups.history"),children:[jsx(ae,{title:t("toolbar.undoShortcut"),disabled:ee||!Y||!A,onClick:A,testId:"pptx-undo",children:jsx(D,{name:"undo"})}),jsx(ae,{title:t("toolbar.redoShortcut"),disabled:ee||!K||!le,onClick:le,testId:"pptx-redo",children:jsx(D,{name:"redo"})})]})]})},{key:"zoom",width:82,node:jsx(fe,{label:t("toolbar.groups.zoom"),children:jsx(it,{value:Ae,options:j,label:t("toolbar.zoomValue",{value:Ae}),disabled:ee||!C,onCommit:g=>{if(g===H){C?.("fit");return}let v=Number.parseFloat(g.replace("%",""));Number.isFinite(v)&&v>=25&&v<=400&&C?.(v/100);},width:76,testId:"pptx-zoom"})})},{key:"tools",width:127,node:jsxs(Fragment,{children:[jsx(Fe,{}),jsxs(fe,{label:t("toolbar.groups.tools"),children:[jsx(ae,{title:t("toolbar.selectToolShortcut"),active:q==="select",disabled:!B,onClick:()=>I?.("select"),testId:"pptx-tool-select",children:jsx(D,{name:"select"})}),jsx(ae,{title:t("toolbar.textBoxTool"),active:q==="textBox",disabled:!B,onClick:()=>I?.("textBox"),testId:"pptx-tool-text-box",children:jsx(D,{name:"textBox"})}),jsx(Le,{title:t("toolbar.shapeTool"),active:q.startsWith("shape:"),disabled:!B,menuWidth:264,testId:"pptx-tool-shape",style:{minWidth:46,padding:"0 4px"},trigger:jsxs(Fragment,{children:[jsx(D,{name:"shape"}),jsx(D,{name:"chevronDown",size:11})]}),children:g=>jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(5, 44px)",gap:4,padding:2},children:$e.map(v=>jsx("button",{type:"button",role:"menuitem","data-testid":`pptx-shape-${v.geometry}`,"aria-label":t(v.labelKey),title:t(v.labelKey),onClick:()=>{I?.(`shape:${v.geometry}`),g();},style:{appearance:"none",display:"grid",placeItems:"center",width:44,height:38,padding:5,border:`1px solid ${w.border}`,borderRadius:4,background:q===`shape:${v.geometry}`?w.active:w.surface,color:w.text,cursor:"pointer"},children:jsx(sn,{geometry:v.geometry})},v.geometry))})})]})]})},{key:"font-family",width:137,node:jsxs(Fragment,{children:[jsx(Fe,{}),jsx(fe,{label:t("toolbar.groups.font"),children:jsx(Le,{title:t("toolbar.fontFamily"),disabled:!P,menuWidth:210,testId:"pptx-font-family",style:{width:120,justifyContent:"space-between"},trigger:jsxs(Fragment,{children:[jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:n.fontFamily??t("toolbar.mixed")}),jsx(D,{name:"chevronDown",size:13})]}),children:g=>jsx(Fragment,{children:ie.map(v=>jsx(He,{label:v,selected:n.fontFamily===v,onClick:()=>ue({type:"fontFamily",value:v}),close:g},v))})})})]})},{key:"font-size",width:116,node:jsxs(fe,{label:t("toolbar.groups.font"),children:[jsx(ae,{title:t("toolbar.decreaseFontSize"),disabled:!P,onClick:()=>ue({type:"fontSize",value:$t(z,U,-1)}),children:jsx(D,{name:"remove"})}),jsx(it,{value:n.fontSize===void 0?"":String(z),options:se,label:t("toolbar.fontSize"),disabled:!P,onCommit:g=>{let v=Number.parseFloat(g);Number.isFinite(v)&&v>=1&&v<=400&&ue({type:"fontSize",value:v});},width:50,inputStyle:{textAlign:"center"},testId:"pptx-font-size"}),jsx(ae,{title:t("toolbar.increaseFontSize"),disabled:!P,onClick:()=>ue({type:"fontSize",value:$t(z,U,1)}),children:jsx(D,{name:"add"})})]})},{key:"text",width:133,node:jsxs(Fragment,{children:[jsx(Fe,{}),jsxs(fe,{label:t("toolbar.groups.text"),children:[jsx(ae,{title:t("toolbar.boldShortcut"),active:n.bold,disabled:!P,onClick:()=>ue("bold"),testId:"pptx-bold",children:jsx(D,{name:"bold"})}),jsx(ae,{title:t("toolbar.italicShortcut"),active:n.italic,disabled:!P,onClick:()=>ue("italic"),testId:"pptx-italic",children:jsx(D,{name:"italic"})}),jsx(ae,{title:t("toolbar.underlineShortcut"),active:n.underline,disabled:!P,onClick:()=>ue("underline"),testId:"pptx-underline",children:jsx(D,{name:"underline"})}),jsx(rt,{value:n.textColor??"#000000",label:t("toolbar.textColor"),disabled:!P,onChange:g=>ue({type:"textColor",value:g}),testId:"pptx-text-color"})]})]})},{key:"shape-formatting",width:N?244:172,node:jsxs(Fragment,{children:[jsx(Fe,{}),jsxs(fe,{label:t("toolbar.groups.shape"),children:[jsx(rt,{value:l.fillColor??"#d9eaf7",label:t("toolbar.fillColor"),clearLabel:t("toolbar.noFill"),icon:"fillColor",none:!l.fillColor,disabled:!Te,onChange:g=>he({type:"fillColor",value:g}),onClear:()=>he({type:"fillColor",value:null}),testId:"pptx-shape-fill"}),jsx(rt,{value:l.strokeColor??"#202124",label:t("toolbar.borderColor"),clearLabel:t("toolbar.noBorder"),icon:"borderColor",none:!l.strokeColor,disabled:!Te,onChange:g=>he({type:"strokeColor",value:g}),onClear:()=>he({type:"strokeColor",value:null}),testId:"pptx-shape-border-color"}),jsx(Le,{title:t("toolbar.borderWidth"),disabled:!Te,menuWidth:170,testId:"pptx-shape-border-width",trigger:jsx(D,{name:"borderWidth"}),children:g=>jsxs(Fragment,{children:[jsx(He,{label:t("toolbar.noBorder"),selected:l.strokeWidthPt===null,onClick:()=>he({type:"strokeWidth",value:null}),close:g}),tn.map(v=>jsx(He,{label:t("toolbar.borderWidthValue",{width:v}),selected:l.strokeWidthPt===v,icon:jsx("span",{"aria-hidden":"true",style:{width:18,borderTop:`${Math.min(v,5)}px solid currentColor`}}),onClick:()=>he({type:"strokeWidth",value:v}),close:g},v))]})}),N?jsx(it,{value:`${Math.round(N[1]*100)}%`,options:(te?on:nn).map(g=>({value:String(g),label:`${g}%`})),label:t(te?"toolbar.cornerRadius":"toolbar.shapeAdjustment"),disabled:!Te,onCommit:g=>{let v=Number.parseFloat(g.replace("%",""));if(Number.isFinite(v)){let Se=te?50:100;he({type:"adjust",name:N[0],value:Math.max(0,Math.min(Se,v))/100});}},width:68,inputStyle:{textAlign:"center"},testId:te?"pptx-shape-corner-radius":"pptx-shape-adjustment"}):null]})]})}];k&&ge.push({key:"custom",width:40,node:k});let Ue=Math.max(0,Oe-48),tt=0,me=ge.length;for(let g=0;g<ge.length;g++)if(tt+=ge[g].width,tt>Ue){me=g;break}let ye=ge.slice(0,me),_e=ge.slice(me);return jsxs("div",{ref:O,className:Qe,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:w.rail,color:w.text,overflow:"hidden",boxSizing:"border-box",...et},children:[ye.map(g=>jsx("span",{style:{display:"contents"},children:g.node},g.key)),jsx("span",{style:{marginLeft:"auto",flex:"0 0 auto"},children:jsx(Le,{title:t("toolbar.more"),disabled:_e.length===0,menuWidth:390,testId:"pptx-toolbar-more",trigger:jsx(D,{name:"more"}),children:()=>jsx("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:2},children:_e.map(g=>jsx("span",{style:{display:"contents"},children:g.node},g.key))})})})]})}function sn({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 dn({children:e,className:t,style:n,...i}){return jsx(ze.Provider,{value:i,children:jsx("div",{className:t,"data-testid":"pptx-editor-toolbar",style:{display:"flex",flexDirection:"column",flex:"0 0 auto",...n},children:e})})}var qe=dn;qe.Toolbar=at;var cn=Math.fround(Math.fround(Math.PI)/180);function st(e,t,n,i){if(!Number.isFinite(e.width)||!Number.isFinite(e.height)||e.width<=0||e.height<=0)return null;let a=(n-e.left)*t.width/e.width,l=(i-e.top)*t.height/e.height;return Number.isFinite(a)&&Number.isFinite(l)?{x:a,y:l}:null}function Me(e,t){for(let n of e){if(n.id===t)return n;let i=Me(n.children,t);if(i)return i}return null}function Qt(e){let t=new Map,n=[...e];for(;n.length>0;){let i=n.pop();t.set(i.id,i),n.push(...i.children);}return t}function vt(e,t){for(let n of e.shapes)if(n.id===t||Me(n.children,t))return n;return null}function eo(e){return e.width>0&&e.height>0}function It(e,t,n){let i=new Set;io(n,i);let a=t.primitives.filter(u=>u.shapeId&&i.has(u.shapeId));if(a.length===0)return n.width<=0||n.height<=0||e.widthEmu<=0||e.heightEmu<=0?null:{x:n.x*t.width/e.widthEmu,y:n.y*t.height/e.heightEmu,width:n.width*t.width/e.widthEmu,height:n.height*t.height/e.heightEmu};let l=a.map(u=>{let T=(u.transform?.rotationDeg??0)*Math.PI/180,A=Math.abs(u.w*Math.cos(T))+Math.abs(u.h*Math.sin(T)),le=Math.abs(u.w*Math.sin(T))+Math.abs(u.h*Math.cos(T));return {x:u.x+(u.w-A)/2,y:u.y+(u.h-le)/2,width:A,height:le}}),h=Math.min(...l.map(u=>u.x)),y=Math.min(...l.map(u=>u.y)),b=Math.max(...l.map(u=>u.x+u.width)),x=Math.max(...l.map(u=>u.y+u.height));return {x:h,y,width:b-h,height:x-y}}function to(e,t,n,i){let a=e.primitives.find(x=>x.kind==="textBox"&&x.shapeId===t&&x.storyId===n);if(!a||a.lines.length===0)return null;let l=no(a,i),h=a.lines.reduce((x,u)=>lt(u.y,u.height,l.y)<lt(x.y,x.height,l.y)?u:x),y=h.caretStops[0];return y?h.caretStops.reduce((x,u)=>Math.abs(u.x-l.x)<Math.abs(x.x-l.x)?u:x,y).position:h.start}function oo(e,t){let n={x:Math.fround(t.x),y:Math.fround(t.y)};for(let i=e.primitives.length-1;i>=0;i-=1){let a=e.primitives[i];if(!a.shapeId)continue;let l=un(a,n);if(l)return a.kind==="textBox"&&a.storyId&&pn(a,l.y)?"text":"shape"}return null}function no(e,t){let n=e.transform;if(!n||!n.rotationDeg&&!n.flipH&&!n.flipV)return t;let i=Math.fround,a=i(i(e.x)+i(i(e.w)/2)),l=i(i(e.y)+i(i(e.h)/2)),h=i(i(n.rotationDeg??0)*cn),y=i(Math.cos(h)),b=i(Math.sin(h)),x=i(t.x-a),u=i(t.y-l),T=i(i(x*y)+i(u*b)),A=i(i(u*y)-i(x*b));return n.flipH&&(T=-T),n.flipV&&(A=-A),{x:i(a+T),y:i(l+A)}}function Jt(e,t){return Math.fround(Math.fround(e)+Math.fround(t))}function un(e,t){let n=no(e,t);return n.x>=Math.fround(e.x)&&n.x<=Jt(e.x,e.w)&&n.y>=Math.fround(e.y)&&n.y<=Jt(e.y,e.h)?n:null}function pn(e,t){return e.lines.length===0?false:e.lines.reduce((i,a)=>lt(a.y,a.height,t)<lt(i.y,i.height,t)?a:i).caretStops.length>0}function ro(e,t,n,i){return {x:n.x+Math.round(i.x*e.widthEmu/t.width),y:n.y+Math.round(i.y*e.heightEmu/t.height)}}function Tt(e,t,n,i,a=4){return Math.hypot(n-e,i-t)>=a}function io(e,t){t.add(e.id);for(let n of e.children)io(n,t);}function lt(e,t,n){return n<e?e-n:n>e+t?n-e-t:0}function ao(e,t=12){return {visible:e.slice(0,t),overflow:Math.max(0,e.length-t)}}function lo(e,t,n=4){let i=new Map;for(let a of e){let l=a.state.cursor?.slideId;if(!l||!t.has(l))continue;let h=i.get(l)??{visible:[],overflow:0};h.visible.length<n?h.visible.push(a):h.overflow+=1,i.set(l,h);}return i}function so(e,t,n,i=24){let a=new Map,l=0;for(let h of e){let y=h.state.cursor;if(y?.slideId!==t||!y.shapeId||!n.has(y.shapeId))continue;let b=a.get(y.shapeId);b?(b.count+=1,h.cursorMovedAt>b.peer.cursorMovedAt&&(b.peer=h)):a.size<i?a.set(y.shapeId,{shapeId:y.shapeId,peer:h,count:1}):l+=1;}return {visible:[...a.values()],overflow:l}}function dt(e,t,n,i){let a=fn(e,t,n,i),l=Ne(a,"underline");return {bold:Ne(a,"bold"),italic:Ne(a,"italic"),underline:l===void 0?void 0:l!=="none",fontSize:Ne(a,"fontSizePt"),textColor:Ne(a,"color"),fontFamily:Ne(a,"fontFamily")}}function co(e,t){return dt(e,0,e.length,t)}function uo(e,t,n,i){let a=dt(e,t,n,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 fn(e,t,n,i){let a=hn(e,i);if(a.length===0)return [i];let l=Math.min(t,n),h=Math.max(t,n);if(l===h){let x=a.find(T=>l>=T.start&&l<T.end);return x?[x.style]:[[...a].reverse().find(T=>T.end<=l)?.style??a[0].style]}let y=a.filter(x=>x.end>l&&x.start<h).map(x=>x.style);return y.length>0?y:[[...a].reverse().find(x=>x.end<=l)?.style??a[0].style]}function hn(e,t){let n=[],i=0;return e.paragraphs.forEach((a,l)=>{for(let h of a.runs){let y=i;i+=h.text.length,i>y&&n.push({start:y,end:i,style:mn(h.style,t)});}l<e.paragraphs.length-1&&(i+=1);}),n}function mn(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 Ne(e,t){let n=e[0]?.[t];return e.every(i=>i[t]===n)?n:void 0}function fo(e){let t=e?.fill?.type==="none"?null:po(e?.resolvedFillColor),n=po(e?.resolvedOutlineColor);return {geometry:e?.geometry,fillColor:t,strokeColor:n,strokeWidthPt:n&&e?.outline?.width!==void 0?e.outline.width/12700:n?1:null,adjustments:e?.adjustValues??{}}}function po(e){if(!e)return null;let t=e.replace(/^#/,"");return /^[0-9a-f]{6}$/i.test(t)?`#${t}`:null}var bn=new Intl.Segmenter(void 0,{granularity:"word"});function wt(e,t,n){return n==="word"?xn(e,t):gn(e,t)}function xn(e,t){let n=mo(e,t),i=[...bn.segment(e)],a=i.find(l=>n>=l.index&&n<l.index+l.segment.length)??i[i.length-1];return a?{start:a.index,end:a.index+a.segment.length}:{start:n,end:n}}function gn(e,t){let n=mo(e,t),i=e.lastIndexOf(`
|
|
2
|
+
`,Math.max(0,n-1))+1,a=e.indexOf(`
|
|
3
|
+
`,n);return {start:i,end:a===-1?e.length:a}}function ho(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 mo(e,t){return Number.isFinite(t)?Math.max(0,Math.min(e.length,Math.trunc(t))):0}var Pn="application/vnd.openxmlformats-officedocument.presentationml.presentation";function vn(e,t,n){let i=new Blob([new Uint8Array(e)],{type:n}),a=URL.createObjectURL(i),l=document.createElement("a");l.href=a,l.download=t,document.body.appendChild(l),l.click(),l.remove(),URL.revokeObjectURL(a);}var ct={bold:false,italic:false,underline:"none",fontSizePt:24,color:"#111827",fontFamily:"Arial"};function In({i18n:e,...t}){return jsx(nt,{i18n:e,children:jsx(Tn,{...t})})}function Tn({file:e,fonts:t,clientId:n,collaboration:i,className:a,fileName:l,onReady:h,onChange:y,onError:b,onSave:x}){let{t:u}=Be(),T=u("errors.decodeSlideImage"),A=i?.clientId??n,le=i?.initialUpdate,Y=i?.onReplica,K=i?.presence,M=useRef(null),C=useRef(null),q=useRef(h),I=useRef(y),ie=useRef(b),U=useRef(null),ee=useRef(null),Qe=useRef(null),et=useRef(null),k=useRef(null),O=useRef(null),Oe=useRef(new Map),We=kn(t),[P,Te]=useState(null),[f,B]=useState(null),[z,H]=useState(null),[Ae,N]=useState(null),[te,j]=useState(null),[se,ue]=useState(ct),[he,ge]=useState({canUndo:false,canRedo:false}),[Ue,tt]=useState("fit"),[me,ye]=useState("select"),[_e,g]=useState(null),[v,Se]=useState({width:0,height:0}),[kt,pt]=useState(null),[Po,ot]=useState(false),[ft,Rt]=useState(null),[Ee,ht]=useState([]);q.current=h,I.current=y,ie.current=b,C.current=P;let _=useCallback(o=>{let r=o instanceof Error?o:new Error(String(o));pt(r.message),ie.current?.(r);},[]),oe=useCallback((o,r=false,c=false)=>{let s=M.current;if(!s)return null;try{let d=s.snapshot(),m=Mn(o??C.current?.slideIndex??0,d.slides.length),S=new Map;for(let L=0;L<d.slides.length;L+=1){let J=d.slides[L],de=C.current?.thumbnails.get(J.id);L!==m&&de&&!c?S.set(J.id,de):L!==m&&S.set(J.id,s.layoutSlide(L));}let R=d.slides.length>0?s.layoutSlide(m):null;R&&S.set(d.slides[m].id,R);let Z={snapshot:d,slideIndex:m,frame:R,thumbnails:S},V=d.slides[m];B(L=>L&&V&&Me(V.shapes,L.shapeId)?L:null),H(L=>L&&V?.id===L.slideId&&Me(V.shapes,L.shapeId)?L:null);let G=k.current;return G&&(!V||V.id!==G.slideId||G.kind!=="textBox"&&G.kind!=="shapeInsert"&&!Me(V.shapes,G.shapeId))&&(k.current=null,O.current=null,N(null),j(null)),C.current=Z,Te(Z),ge({canUndo:s.canUndo(),canRedo:s.canRedo()}),pt(null),r&&I.current?.(d),Z}catch(d){return _(d),null}},[_]),Ft=useCallback(()=>{oe(void 0,false,true);},[oe]);useEffect(()=>{let o=false,r=null,c=[],s=()=>{};if(M.current?.dispose(),M.current=null,Rt(null),C.current=null,Te(null),B(null),H(null),N(null),j(null),ge({canUndo:false,canRedo:false}),ye("select"),k.current=null,O.current=null,pt(null),Oe.current.clear(),!!e)return ot(true),Promise.all([initWasm(),zn(We)]).then(([,d])=>{if(c=d,o){xo(c);return}try{r=openPresentation(e,{clientId:A,fonts:We,initialUpdate:le}),M.current=r,s=r.onUpdate((S,R)=>{R==="remote"&&oe(void 0,!0,!0);}),oe(0),ot(!1),Rt(r);let m=r;q.current?.({handle:m,refresh:Ft,save:()=>m.save()});}catch(m){ot(false),_(m);}},d=>{o||(ot(false),_(d));}),()=>{o=true,s(),r?.dispose(),M.current===r&&(M.current=null),xo(c);}},[A,le,e,We,Ft,oe,_]),useEffect(()=>{if(!(!Y||!ft))return Y(ft),()=>Y(null)},[Y,ft]),useEffect(()=>g(null),[me]),useEffect(()=>{if(!K){ht([]);return}return ht(K.peers),K.onPresence(ht)},[K]),useEffect(()=>{let o=ee.current;if(!o)return;let r=()=>Se({width:o.clientWidth,height:o.clientHeight});r();let c=new ResizeObserver(r);return c.observe(o),()=>c.disconnect()},[]);let vo=useMemo(()=>!P?.frame||v.width<=0||v.height<=0?1:Math.min((v.width-40)/P.frame.width,(v.height-40)/P.frame.height,1),[P?.frame,v]),X=Ue==="fit"?vo:Ue;useEffect(()=>{let o=Qe.current,r=P?.frame;if(!o||!r)return;let c=o.getContext("2d");if(!c)return;let s=window.devicePixelRatio||1;sizeCanvasForSlide(o,r,s,X);let d=false;return paintSlide(c,r,s,X,{resolveImage:m=>go(m,M,Oe,T)}).catch(m=>{d||_(m);}),()=>{d=true;}},[T,P?.frame,_,X]),useEffect(()=>{let o=et.current,r=P?.frame;if(!o||!r)return;let c=o.getContext("2d");if(!c)return;let s=window.devicePixelRatio||1;sizeCanvasForSlide(o,r,s,X),Nn(c,r,f,s,X);},[P?.frame,X,f]);let pe=useMemo(()=>{if(!P?.frame||!z)return null;let o=P.snapshot.slides[P.slideIndex];return !o||o.id!==z.slideId?null:Me(o.shapes,z.shapeId)},[P,z]),ke=pe?.textStories[0]?.id??null,Io=useMemo(()=>fo(pe),[pe]),Ke=useMemo(()=>P?.frame&&pe?It(P.snapshot,P.frame,pe):null,[P,pe]),Pe=P?.snapshot.slides[P.slideIndex],Xe=Pe?.id,mt=useMemo(()=>{if(Pe){if(z?.slideId===Pe.id)return z.shapeId;if(f)return vt(Pe,f.shapeId)?.id}},[Pe,f,z]);useEffect(()=>{K&&K.setCursor(Xe?{slideId:Xe,...mt?{shapeId:mt}:{}}:null);},[K,Xe,mt]),useEffect(()=>()=>{K?.setCursor(null);},[K]);let Ze=useMemo(()=>ao(Ee),[Ee]),bt=useMemo(()=>{if(!P?.frame||!Pe)return {visible:[],overflow:0};let o=Qt(Pe.shapes),r=so(Ee,Pe.id,o),c=[],s=r.overflow;for(let d of r.visible){let m=o.get(d.shapeId);if(!m)continue;let S=It(P.snapshot,P.frame,m);S?c.push({peer:d.peer,peerCount:d.count,shapeId:d.shapeId,bounds:S}):s+=d.count;}return {visible:c,overflow:s}},[Pe,P,Ee]),To=useMemo(()=>{let o=new Set(P?.snapshot.slides.map(r=>r.id));return lo(Ee,o)},[P,Ee]);useEffect(()=>{let o=M.current;if(!(!o||!f))try{let r=o.story(f.storyId);ue(uo(r,f.anchor,f.focus,ct));}catch(r){_(r);}},[P,_,f]);let Re=useMemo(()=>{if(f&&f.anchor===f.focus)return ut(se);let o=M.current;if(!o)return ut(se);try{return f?dt(o.story(f.storyId),f.anchor,f.focus,ct):ke?co(o.story(ke),ct):ut(se)}catch{return ut(se)}},[P,ke,f,se]),wo=useMemo(()=>{let o=new Set;for(let r of P?.snapshot.slides??[])o.add(r.layoutPartPath);return [...o].map(r=>({partPath:r}))},[P?.snapshot]),Co=o=>{B(null),H(null),N(null),j(null),k.current=null,O.current=null,oe(o),U.current?.focus();},Mo=(o,r)=>{let c=M.current,s=C.current;if(!c||!s?.frame)return;let d=s.snapshot.slides[s.slideIndex];if(!d)return;let m=Math.abs(r.x-o.x)>=6||Math.abs(r.y-o.y)>=6,S=m?Math.abs(r.x-o.x):s.frame.width*.36,R=m?Math.abs(r.y-o.y):s.frame.height*.12,Z=Math.max(0,Math.min(m?Math.min(o.x,r.x):o.x,s.frame.width-S)),V=Math.max(0,Math.min(m?Math.min(o.y,r.y):o.y,s.frame.height-R));try{let G=c.addTextBox(d.id,{name:u("objects.defaultTextBoxName"),rect:{x:Math.round(Z*s.snapshot.widthEmu/s.frame.width),y:Math.round(V*s.snapshot.heightEmu/s.frame.height),width:Math.round(Math.max(12,S)*s.snapshot.widthEmu/s.frame.width),height:Math.round(Math.max(12,R)*s.snapshot.heightEmu/s.frame.height)},text:"",style:se}),L=oe(void 0,!0);ye("select"),H(null),N(null),j(null),k.current=null,O.current=null;let J=L?.snapshot.slides[L.slideIndex]?.shapes.find(Ho=>Ho.id===G.shapeId),de=J?.textStories[0];de&&(B({shapeId:J.id,storyId:de.id,anchor:0,focus:0}),U.current?.focus());}catch(G){_(G);}},Eo=(o,r,c)=>{let s=M.current,d=C.current;if(!s||!d?.frame)return;let m=d.snapshot.slides[d.slideIndex],S=$e.find(J=>J.geometry===o);if(!m||!S)return;let R=Math.abs(c.x-r.x)>=6||Math.abs(c.y-r.y)>=6,Z=R?Math.abs(c.x-r.x):d.frame.width*.22,V=R?Math.abs(c.y-r.y):d.frame.height*.18,G=Math.max(0,Math.min(R?Math.min(r.x,c.x):r.x-Z/2,d.frame.width-Z)),L=Math.max(0,Math.min(R?Math.min(r.y,c.y):r.y-V/2,d.frame.height-V));try{let J=s.addShape(m.id,{name:u(S.labelKey),geometry:o,rect:{x:Math.round(G*d.snapshot.widthEmu/d.frame.width),y:Math.round(L*d.snapshot.heightEmu/d.frame.height),width:Math.round(Math.max(12,Z)*d.snapshot.widthEmu/d.frame.width),height:Math.round(Math.max(12,V)*d.snapshot.heightEmu/d.frame.height)},fill:"#d9eaf7"}),de=oe(void 0,!0);ye("select"),B(null),H({slideId:m.id,shapeId:J.shapeId}),N(null),j(null),k.current=null,O.current=null,de&&U.current?.focus();}catch(J){_(J);}},ko=o=>{if(!o.isPrimary||o.button!==0)return;let r=M.current,c=C.current;if(!r||!c?.frame)return;let s=st(o.currentTarget.getBoundingClientRect(),c.frame,o.clientX,o.clientY);if(!s)return;let d=c.snapshot.slides[c.slideIndex],m=En(me);if((me==="textBox"||m)&&d){B(null),H(null),N(null),j({start:s,end:s}),O.current=null,k.current=m?{kind:"shapeInsert",pointerId:o.pointerId,slideId:d.id,geometry:m,start:s,last:s}:{kind:"textBox",pointerId:o.pointerId,slideId:d.id,start:s,last:s},o.currentTarget.setPointerCapture(o.pointerId),U.current?.focus(),o.preventDefault();return}try{r.layoutSlide(c.slideIndex);let S=r.hitTest(s.x,s.y),R=d&&S?vt(d,S.shapeId):null,Z=O.current,V=!!(d&&R&&Z?.slideId===d.id&&Z.shapeId===R.id&&o.timeStamp-Z.timeStamp<=600&&Math.hypot(o.clientX-Z.clientX,o.clientY-Z.clientY)<=6),G=V&&Z?Math.min(Z.count+1,3):1;if(O.current=null,d&&S?.kind==="text"&&R&&G>=2){let L=r.story(S.storyId),J=G>=3?"paragraph":"word",de=wt(Je(L),S.position,J);B({shapeId:S.shapeId,storyId:S.storyId,anchor:de.start,focus:de.end}),H(null),N(null),k.current={kind:"text",pointerId:o.pointerId,slideId:d.id,shapeId:S.shapeId,storyId:S.storyId,anchor:de.start,focus:de.end,granularity:J,clickCount:G,clickShapeId:R.id,startClientX:o.clientX,startClientY:o.clientY,dragging:!1},o.currentTarget.setPointerCapture(o.pointerId);}else if(d&&f&&S?.kind==="text"&&S.shapeId===f.shapeId&&S.storyId===f.storyId){r.story(S.storyId);let L=o.shiftKey?f.anchor:S.position;B({shapeId:S.shapeId,storyId:S.storyId,anchor:L,focus:S.position}),H(null),N(null),k.current={kind:"text",pointerId:o.pointerId,slideId:d.id,shapeId:S.shapeId,storyId:S.storyId,anchor:L,focus:S.position,granularity:"character",clickCount:G,clickShapeId:R?.id??S.shapeId,startClientX:o.clientX,startClientY:o.clientY,dragging:!1},o.currentTarget.setPointerCapture(o.pointerId);}else d&&S?R?(B(null),H({slideId:d.id,shapeId:R.id}),N(null),eo(R)?(k.current={kind:"shape",pointerId:o.pointerId,slideId:d.id,shapeId:R.id,startClientX:o.clientX,startClientY:o.clientY,start:s,last:s,dragThreshold:V?8:4,clickCount:G,dragging:!1},o.currentTarget.setPointerCapture(o.pointerId)):k.current=null):(B(null),H(null),O.current=null,k.current=null):(B(null),H(null),N(null),O.current=null,k.current=null);U.current?.focus(),o.preventDefault();}catch(S){_(S);}},Lt=o=>{let r=k.current,c=M.current,s=C.current;if(!r||r.pointerId!==o.pointerId||!c||!s?.frame)return false;let d=st(o.currentTarget.getBoundingClientRect(),s.frame,o.clientX,o.clientY);if(!d||s.snapshot.slides[s.slideIndex]?.id!==r.slideId)return false;if(r.kind==="text"){!r.dragging&&Tt(r.startClientX,r.startClientY,o.clientX,o.clientY)&&(r.dragging=true);let m=to(s.frame,r.shapeId,r.storyId,d);if(m!==null){let S=r.granularity==="character"?{anchor:r.anchor,focus:m}:ho({start:r.anchor,end:r.focus},wt(Je(c.story(r.storyId)),m,r.granularity));B({shapeId:r.shapeId,storyId:r.storyId,...S});}}else r.kind==="shape"?(r.last=d,!r.dragging&&Tt(r.startClientX,r.startClientY,o.clientX,o.clientY,r.dragThreshold)&&(r.dragging=true),r.dragging&&N({shapeId:r.shapeId,delta:{x:d.x-r.start.x,y:d.y-r.start.y}})):(r.last=d,j({start:r.start,end:d}));return true},Ro=o=>{if(Lt(o)){o.preventDefault();return}if(k.current||me!=="select")return;let r=C.current;if(!r?.frame)return;let c=st(o.currentTarget.getBoundingClientRect(),r.frame,o.clientX,o.clientY);g(c?oo(r.frame,c):null);},Fo=()=>{k.current||g(null);},Lo=o=>{Lt(o);let r=k.current;if(!r||r.pointerId!==o.pointerId)return;if(k.current=null,N(null),o.currentTarget.hasPointerCapture(o.pointerId)&&o.currentTarget.releasePointerCapture(o.pointerId),r.kind==="textBox"){j(null),Mo(r.start,r.last),o.preventDefault();return}if(r.kind==="shapeInsert"){j(null),Eo(r.geometry,r.start,r.last),o.preventDefault();return}if(r.kind==="text"){O.current=r.dragging?null:{slideId:r.slideId,shapeId:r.clickShapeId,clientX:o.clientX,clientY:o.clientY,timeStamp:o.timeStamp,count:r.clickCount};return}if(r.kind!=="shape")return;if(!r.dragging){O.current={slideId:r.slideId,shapeId:r.shapeId,clientX:o.clientX,clientY:o.clientY,timeStamp:o.timeStamp,count:r.clickCount};return}O.current=null;let c=M.current,s=C.current,d=s?.snapshot.slides[s.slideIndex];if(!c||!s?.frame||d?.id!==r.slideId)return;let m=Me(d.shapes,r.shapeId);if(m)try{let S=ro(s.snapshot,s.frame,m,{x:r.last.x-r.start.x,y:r.last.y-r.start.y});(S.x!==m.x||S.y!==m.y)&&(c.moveShape(d.id,m.id,S.x,S.y),oe(void 0,!0)),H({slideId:d.id,shapeId:m.id}),o.preventDefault();}catch(S){_(S);}},At=o=>{k.current?.pointerId===o.pointerId&&(k.current=null,N(null),j(null),O.current=null);},De=o=>{B(o),H(null),O.current=null,oe(void 0,true);},Ao=o=>{let r=M.current;if(!r)return;let c=o.metaKey||o.ctrlKey;if(o.key==="Escape"){ye("select"),j(null),k.current=null,o.preventDefault();return}if(c&&(o.key==="z"||o.key==="Z")){o.preventDefault(),xt(o.shiftKey?"redo":"undo");return}if(c&&(o.key==="s"||o.key==="S")){o.preventDefault(),Dt();return}if(!f&&!ke)return;if(c&&(o.key==="b"||o.key==="B")){o.preventDefault(),ve({bold:f?!se.bold:!Re.bold});return}if(c&&(o.key==="i"||o.key==="I")){o.preventDefault(),ve({italic:f?!se.italic:!Re.italic});return}if(c&&(o.key==="u"||o.key==="U")){o.preventDefault(),ve({underline:f?se.underline==="none"?"sng":"none":Re.underline?"none":"sng"});return}if(!f)return;let s=Math.min(f.anchor,f.focus),d=Math.max(f.anchor,f.focus);try{if(o.key==="ArrowLeft"||o.key==="ArrowRight"){o.preventDefault();let m=r.story(f.storyId),S=o.key==="ArrowLeft"?-1:1,R=Math.max(0,Math.min(m.length,f.focus+S));B({...f,anchor:o.shiftKey?f.anchor:R,focus:R});return}if(o.key==="Backspace"){if(o.preventDefault(),s!==d){r.deleteText(f.storyId,s,d),De({...f,anchor:s,focus:s});return}let m=Dn(r.story(f.storyId),s);m<s&&(r.deleteText(f.storyId,m,s),De({...f,anchor:m,focus:m}));return}if(o.key==="Delete"){if(o.preventDefault(),s!==d){r.deleteText(f.storyId,s,d),De({...f,anchor:s,focus:s});return}let m=Bn(r.story(f.storyId),d);m>d&&(r.deleteText(f.storyId,d,m),De({...f,anchor:d,focus:d}));return}if(o.key==="Enter"){o.preventDefault(),s!==d&&r.deleteText(f.storyId,s,d),r.insertParagraphBreak(f.storyId,s),De({...f,anchor:s+1,focus:s+1});return}if(o.key.length>0&&!o.metaKey&&!o.ctrlKey&&!o.altKey&&Array.from(o.key).length===1){o.preventDefault(),s!==d&&r.deleteText(f.storyId,s,d),r.insertText(f.storyId,s,o.key,se);let m=s+o.key.length;De({...f,anchor:m,focus:m});}}catch(m){_(m);}},ve=o=>{ue(c=>({...c,...o}));let r=M.current;if(r)try{if(f){if(f.anchor===f.focus)return;r.formatText(f.storyId,Math.min(f.anchor,f.focus),Math.max(f.anchor,f.focus),o);}else if(ke){let c=r.story(ke);An(r,c,o);}else return;oe(void 0,!0);}catch(c){_(c);}},Do=o=>{o==="bold"?ve({bold:!Re.bold}):o==="italic"?ve({italic:!Re.italic}):o==="underline"?ve({underline:Re.underline?"none":"sng"}):o.type==="fontFamily"?ve({fontFamily:o.value}):o.type==="fontSize"?ve({fontSizePt:o.value}):o.type==="textColor"&&ve({color:o.value});},Bo=o=>{let r=M.current;if(!(!r||!z||!pe))try{o.type==="fillColor"?r.setShapeFill(z.slideId,z.shapeId,o.value):o.type==="strokeColor"?r.setShapeStroke(z.slideId,z.shapeId,o.value?{color:o.value}:{}):o.type==="strokeWidth"?r.setShapeStroke(z.slideId,z.shapeId,o.value===null?{}:{widthPt:o.value}):r.setShapeAdjust(z.slideId,z.shapeId,{...pe.adjustValues,[o.name]:o.value}),oe(void 0,!0);}catch(c){_(c);}},zo=o=>{let r=M.current,c=C.current;if(!(!r||!c))try{let s=c.slideIndex+1,d=o===void 0?c.snapshot.slides[c.slideIndex]?.layoutPartPath??void 0:o??void 0;r.insertSlide(s,d),B(null),H(null),N(null),j(null),ye("select"),k.current=null,O.current=null,oe(s,!0,!0);}catch(s){_(s);}},xt=o=>{let r=M.current;if(r)try{o==="undo"?r.undo():r.redo(),B(null),N(null),j(null),ye("select"),k.current=null,O.current=null,oe(void 0,!0);}catch(c){_(c);}},Dt=()=>{let o=M.current;if(o)try{let r=o.save();x?x(r):vn(r,l??"presentation.pptx",Pn);}catch(r){_(r);}},gt=P?.snapshot.slides.length??0,Ge=P?.slideIndex??0,Bt=Ae&&Ae.shapeId===z?.shapeId?Ae.delta:null;return jsxs("div",{className:a,style:F.root,children:[jsxs("div",{style:F.toolbarShell,children:[jsx(qe,{currentFormatting:Re,textSelectionActive:f!==null||ke!==null,onFormat:Do,currentShapeFormatting:Io,shapeSelectionActive:pe?.kind==="shape",onShapeFormat:Bo,onInsertSlide:zo,slideLayouts:wo,currentLayoutPartPath:P?.snapshot.slides[Ge]?.layoutPartPath,onSave:Dt,onUndo:()=>xt("undo"),onRedo:()=>xt("redo"),canUndo:he.canUndo,canRedo:he.canRedo,zoom:Ue,onZoomChange:tt,activeTool:me,onToolChange:o=>{ye(o),o!=="select"&&(B(null),H(null)),j(null),k.current=null,U.current?.focus();},disabled:!P||gt===0,style:F.toolbar,children:jsx(qe.Toolbar,{})}),Ee.length>0?jsxs("div",{style:F.presenceStrip,role:"list","aria-label":"Collaborators",children:[Ze.visible.map(o=>{let r=o.state.cursor?.slideId===Xe;return jsx("span",{role:"listitem",style:yo(o.state.user.color,r),title:o.state.user.name,"aria-label":o.state.user.name,children:Wn(o.state.user.name)},o.state.clientId)}),Ze.overflow>0?jsxs("span",{role:"listitem",style:yo("#64748b",true),title:`${Ze.overflow} more collaborators`,"aria-label":`${Ze.overflow} more collaborators`,children:["+",Ze.overflow]}):null]}):null]}),jsxs("div",{style:F.workspace,children:[jsx("aside",{style:F.slideStrip,"aria-label":u("slides.panelLabel"),children:P?.snapshot.slides.map((o,r)=>{let c=To.get(o.id);return jsxs("button",{type:"button","aria-current":r===Ge?"page":void 0,style:Un(r===Ge),onClick:()=>Co(r),children:[jsx("span",{style:F.slideNumber,children:r+1}),jsxs("span",{style:F.slidePreview,children:[P.thumbnails.get(o.id)?jsx(Cn,{frame:P.thumbnails.get(o.id),resolveImage:s=>go(s,M,Oe,T)}):jsx("span",{style:F.slideTitle,children:On(o.shapes)||u("slides.fallbackTitle",{number:r+1})}),o.id!==Xe&&c&&(c.visible.length>0||c.overflow>0)?jsxs("span",{style:F.thumbnailPresence,"aria-hidden":"true",children:[c.visible.map(s=>jsx("span",{style:{...F.thumbnailPresenceDot,backgroundColor:s.state.user.color}},s.state.clientId)),c.overflow>0?jsxs("span",{style:F.thumbnailPresenceOverflow,children:["+",c.overflow]}):null]}):null]})]},o.id)})}),jsxs("div",{ref:U,style:F.stage,tabIndex:0,role:"application","aria-label":u("editor.appLabel"),onKeyDown:Ao,children:[jsx("div",{ref:ee,style:F.canvasHost,children:P?.frame?jsxs("div",{style:{...F.canvasFrame,width:P.frame.width*X,height:P.frame.height*X},children:[jsx("canvas",{ref:Qe,"data-testid":"pptx-slide-canvas",style:{...F.canvas,cursor:me!=="select"?"crosshair":_e==="text"?"text":_e==="shape"?"move":"default"},onPointerDown:ko,onPointerMove:Ro,onPointerUp:Lo,onPointerLeave:Fo,onPointerCancel:At,onLostPointerCapture:At,"aria-label":pe?u("slides.canvasLabelWithSelection",{current:Ge+1,total:gt,name:pe.name}):u("slides.canvasLabel",{current:Ge+1,total:gt})}),jsx("canvas",{ref:et,style:F.canvasOverlay,"aria-hidden":"true"}),bt.visible.map(({peer:o,peerCount:r,shapeId:c,bounds:s},d)=>jsx(wn,{peer:o,peerCount:r,bounds:s,scale:X,labelOffset:d},c)),bt.overflow>0?jsxs("span",{style:F.remoteShapeOverflow,"aria-hidden":"true",children:["+",bt.overflow," selections"]}):null,Ke?jsx("span",{style:{...F.shapeSelection,left:(Ke.x+(Bt?.x??0))*X,top:(Ke.y+(Bt?.y??0))*X,width:Math.max(1,Ke.width*X),height:Math.max(1,Ke.height*X)},"aria-hidden":"true"}):null,te?jsx("span",{style:{...F.textBoxPreview,left:Math.min(te.start.x,te.end.x)*X,top:Math.min(te.start.y,te.end.y)*X,width:Math.max(1,Math.abs(te.end.x-te.start.x))*X,height:Math.max(1,Math.abs(te.end.y-te.start.y))*X},"aria-hidden":"true"}):null]}):jsx("div",{style:F.empty,children:u(Po?"editor.opening":e?"editor.noSlides":"editor.openPrompt")})}),kt?jsx("div",{style:F.error,children:kt}):null]})]})]})}function wn({peer:e,peerCount:t,bounds:n,scale:i,labelOffset:a}){let[l,h]=useState(()=>Date.now()-e.cursorMovedAt<PRESENCE_LABEL_DURATION_MS);return useEffect(()=>{let y=PRESENCE_LABEL_DURATION_MS-(Date.now()-e.cursorMovedAt);if(y<=0){h(false);return}h(true);let b=setTimeout(()=>h(false),y);return ()=>clearTimeout(b)},[e.cursorMovedAt]),jsxs("span",{style:{...F.remoteShapeSelection,left:n.x*i,top:n.y*i,width:Math.max(1,n.width*i),height:Math.max(1,n.height*i),borderColor:e.state.user.color},"aria-hidden":"true",children:[jsx("span",{style:{...F.remoteShapeWash,backgroundColor:e.state.user.color}}),l?jsxs("span",{style:{...F.remoteShapeLabel,top:-4-a%3*20,backgroundColor:e.state.user.color},children:[e.state.user.name,t>1?` +${t-1}`:""]}):null]})}function Cn({frame:e,resolveImage:t}){let n=useRef(null);return useEffect(()=>{let i=n.current;if(!i)return;let a=i.getContext("2d");if(!a)return;let l=128/e.width,h=window.devicePixelRatio||1;sizeCanvasForSlide(i,e,h,l),paintSlide(a,e,h,l,{resolveImage:t}).catch(()=>{});},[e,t]),jsx("canvas",{ref:n,style:F.thumbnailCanvas,"aria-hidden":"true"})}function Mn(e,t){return t===0?0:Math.max(0,Math.min(t-1,e))}function En(e){if(!e.startsWith("shape:"))return null;let t=e.slice(6);return $e.some(n=>n.geometry===t)?t:null}function kn(e){let t=useRef(e);return Rn(t.current,e)||(t.current=e),t.current}function Rn(e,t){return e===t?true:e.length!==t.length?false:e.every((n,i)=>Fn(n,t[i]))}function Fn(e,t){return e.family===t.family&&(e.bold??false)===(t.bold??false)&&(e.italic??false)===(t.italic??false)&&Ln(e.bytes,t.bytes)}function Ln(e,t){return e===t?true:e.byteLength!==t.byteLength?false:e.every((n,i)=>n===t[i])}function Je(e){return e.paragraphs.map(t=>t.runs.map(n=>n.text).join("")).join(`
|
|
4
|
+
`)}function An(e,t,n){e.formatText(t.id,0,t.length,n);}function Dn(e,t){let n=Je(e).slice(0,t),i=Array.from(n),a=i[i.length-1];return a?t-a.length:t}function Bn(e,t){let n=Array.from(Je(e).slice(t))[0];return n?t+n.length:t}function ut(e){return {bold:e.bold,italic:e.italic,underline:e.underline!=="none",fontSize:e.fontSizePt,textColor:e.color,fontFamily:e.fontFamily}}async function zn(e){return typeof FontFace>"u"||typeof document>"u"?[]:await Promise.all(e.map(async n=>{let i=n.bytes.slice().buffer,l=await new FontFace(n.family,i,{style:n.italic?"italic":"normal",weight:n.bold?"700":"400"}).load();return document.fonts.add(l),l}))}function xo(e){if(!(typeof document>"u"))for(let t of e)document.fonts.delete(t);}function go(e,t,n,i){let a=n.current.get(e);if(a)return a;let l=Hn(t.current?.mediaBytes(e),i);return n.current.set(e,l),l}async function Hn(e,t){if(!e)return null;let n=new Blob([e.slice()]);if(typeof createImageBitmap=="function")return createImageBitmap(n);let i=URL.createObjectURL(n);try{return await new Promise((a,l)=>{let h=new Image;h.onload=()=>a(h),h.onerror=()=>l(new Error(t)),h.src=i;})}finally{URL.revokeObjectURL(i);}}function Nn(e,t,n,i,a){if(!n)return;let l=t.primitives.find(b=>b.kind==="textBox"&&b.storyId===n.storyId&&b.shapeId===n.shapeId);if(!l)return;let h=Math.min(n.anchor,n.focus),y=Math.max(n.anchor,n.focus);if(e.save(),e.setTransform(i*a,0,0,i*a,0,0),h!==y){e.fillStyle="rgba(59, 130, 246, 0.26)";for(let b of l.lines){let x=Math.max(h,b.start),u=Math.min(y,b.end);if(x>=u)continue;let T=Mt(b,x),A=Mt(b,u);e.fillRect(Math.min(T,A),b.y,Math.max(1,Math.abs(A-T)),b.height);}}else {let b=l.lines.find(x=>h>=x.start&&h<=x.end)??l.lines[l.lines.length-1];if(b){let x=Mt(b,h);e.fillStyle="#1d4ed8",e.fillRect(x,b.y,1.5,b.height);}}e.restore();}function Mt(e,t){let n=e.caretStops[0];return n?e.caretStops.reduce((i,a)=>Math.abs(a.position-t)<Math.abs(i.position-t)?a:i,n).x:e.x}function On(e){for(let t of e)for(let n of t.textStories){let i=Je(n).trim();if(i)return i.slice(0,40)}return ""}var F={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 Wn(e){let t=e.trim().split(/\s+/).filter(Boolean);return t.length===0?"?":t.slice(0,2).map(n=>n[0]).join("").toUpperCase()}function yo(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 Un(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{qe as EditorToolbar,ze as EditorToolbarContext,nt as LocaleProvider,In as PptxEditor,at as PptxToolbar,$e as SHAPE_PRESETS,at as Toolbar,ae as ToolbarButton,Le as ToolbarDropdown,fe as ToolbarGroup,He as ToolbarMenuItem,Zo as ToolbarMenuSeparator,Fe as ToolbarSeparator,_o as useEditorToolbar,Be 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.4",
|
|
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,14 +40,17 @@
|
|
|
34
40
|
"typecheck": "tsc --noEmit -p ."
|
|
35
41
|
},
|
|
36
42
|
"dependencies": {
|
|
37
|
-
"@betteroffice/pptx": "0.0.
|
|
38
|
-
"@betteroffice/pptx-i18n": "0.0.
|
|
43
|
+
"@betteroffice/pptx": "0.0.4",
|
|
44
|
+
"@betteroffice/pptx-i18n": "0.0.4"
|
|
39
45
|
},
|
|
40
46
|
"peerDependencies": {
|
|
41
47
|
"react": "^18.0.0 || ^19.0.0",
|
|
42
48
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
43
49
|
},
|
|
44
50
|
"devDependencies": {
|
|
51
|
+
"@happy-dom/global-registrator": "^20.8.3",
|
|
52
|
+
"@testing-library/react": "^16.0.0",
|
|
53
|
+
"@types/bun": "^1.3.14",
|
|
45
54
|
"@types/react": "^19.2.17",
|
|
46
55
|
"@types/react-dom": "^19.2.3",
|
|
47
56
|
"react": "^19.2.7",
|