@betteroffice/pptx-react 0.0.3 → 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 +6 -4
- package/dist/index.d.ts +7 -0
- package/dist/index.js +4 -4
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ export function Presentation({ file, fontBytes }: {
|
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
Font bytes are supplied by the host and registered with the Rust shaper; pair
|
|
40
|
-
with [`@betteroffice/
|
|
40
|
+
with [`@betteroffice/fonts`](https://www.npmjs.com/package/@betteroffice/fonts)
|
|
41
41
|
for metric-compatible open faces.
|
|
42
42
|
|
|
43
43
|
## Edit
|
|
@@ -46,9 +46,10 @@ Click text to place the Rust-computed caret, type to edit the yrs story and
|
|
|
46
46
|
trigger Rust reflow, drag or resize shapes on the canvas, or use the toolbar
|
|
47
47
|
for bold, italic, size, color, slides, and text boxes.
|
|
48
48
|
|
|
49
|
-
Props: `file`, `fonts`, `collaboration`, `i18n`, `className`, `
|
|
50
|
-
(exposes the core `PresentationHandle
|
|
51
|
-
edits), `onChange` (deck snapshots), `onError
|
|
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).
|
|
52
53
|
|
|
53
54
|
## What works today
|
|
54
55
|
|
|
@@ -56,6 +57,7 @@ edits), `onChange` (deck snapshots), `onError`.
|
|
|
56
57
|
- Canvas interactions: shape selection, drag, and resize
|
|
57
58
|
- Text editing with caret and selection computed by the engine
|
|
58
59
|
- Slide management (add, delete), text boxes, undo/redo
|
|
60
|
+
- Saving the deck back to `.pptx` — toolbar button, Ctrl/Cmd+S, or `api.save()`
|
|
59
61
|
- Localized UI via the `i18n` prop
|
|
60
62
|
([`@betteroffice/pptx-i18n`](https://www.npmjs.com/package/@betteroffice/pptx-i18n))
|
|
61
63
|
- Real-time collaboration with people or agents; the deck is a CRDT
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ interface PptxTextSelection {
|
|
|
12
12
|
interface PptxEditorApi {
|
|
13
13
|
handle: PresentationHandle;
|
|
14
14
|
refresh: () => void;
|
|
15
|
+
/** Serialize the presentation back to .pptx bytes, edits included. */
|
|
16
|
+
save: () => Uint8Array;
|
|
15
17
|
}
|
|
16
18
|
interface PptxEditorCollaborationOptions {
|
|
17
19
|
clientId: number;
|
|
@@ -27,9 +29,13 @@ 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
|
|
|
@@ -141,6 +147,7 @@ interface ToolbarProps {
|
|
|
141
147
|
onInsertSlide?: (layoutPartPath?: string | null) => void;
|
|
142
148
|
slideLayouts?: readonly SlideLayoutOption[];
|
|
143
149
|
currentLayoutPartPath?: string | null;
|
|
150
|
+
onSave?: () => void;
|
|
144
151
|
onUndo?: () => void;
|
|
145
152
|
onRedo?: () => void;
|
|
146
153
|
canUndo?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {initWasm,openPresentation,sizeCanvasForSlide,paintSlide,PRESENCE_LABEL_DURATION_MS}from'@betteroffice/pptx';import {createContext,useMemo,useContext,useState,useRef,useCallback,useEffect}from'react';import {en,deepMerge,createT}from'@betteroffice/pptx-i18n';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Ht=createContext(en),Nt=createContext("en");function tt({i18n:e,children:t}){let r=typeof e?._lang=="string"?e._lang:"en",i=useMemo(()=>deepMerge(en,e),[e]);return jsx(Nt.Provider,{value:r,children:jsx(Ht.Provider,{value:i,children:t})})}function He(){let e=useContext(Ht),t=useContext(Nt);return {t:useMemo(()=>createT(e,t),[e,t])}}var Ne=createContext(null);function Ao(){let e=useContext(Ne);if(!e)throw new Error("useEditorToolbar must be used within an <EditorToolbar> component");return e}function B({name:e,size:t=20,style:r}){return jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",style:{display:"inline-flex",flexShrink:0,...r},children:[e==="undo"&&jsx("path",{d:"m9 7-5 5 5 5M5 12h9a6 6 0 0 1 6 6"}),e==="redo"&&jsx("path",{d:"m15 7 5 5-5 5m4-5h-9a6 6 0 0 0-6 6"}),e==="newSlide"&&jsxs(Fragment,{children:[jsx("rect",{x:"3",y:"5",width:"15",height:"14",rx:"1.5"}),jsx("path",{d:"M7 9h7M7 13h5M20 9v6m-3-3h6"})]}),e==="select"&&jsx("path",{d:"m6 3 12 9-6 1.5L9 19Z"}),e==="textBox"&&jsxs(Fragment,{children:[jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"1.5"}),jsx("path",{d:"M8 8h8m-4 0v8m-3 0h6"})]}),e==="shape"&&jsx("rect",{x:"4",y:"6",width:"16",height:"12",rx:"3"}),e==="fillColor"&&jsxs(Fragment,{children:[jsx("path",{d:"m7 4 10 10-5 5-7-7Z"}),jsx("path",{d:"m5 12 7-7m6 12h2"})]}),e==="borderColor"&&jsx(Fragment,{children:jsx("path",{d:"M5 18h14M8 15l8-8 2 2-8 8H8Z"})}),e==="borderWidth"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 7h14",strokeWidth:"1"}),jsx("path",{d:"M5 12h14",strokeWidth:"2"}),jsx("path",{d:"M5 18h14",strokeWidth:"3"})]}),e==="bold"&&jsx("path",{d:"M7 4h6a4 4 0 0 1 0 8H7zm0 8h7a4 4 0 0 1 0 8H7z"}),e==="italic"&&jsx("path",{d:"M10 4h8M6 20h8M14 4 10 20"}),e==="underline"&&jsxs(Fragment,{children:[jsx("path",{d:"M7 4v7a5 5 0 0 0 10 0V4"}),jsx("path",{d:"M5 20h14"})]}),e==="textColor"&&jsxs(Fragment,{children:[jsx("path",{d:"m7 16 5-12 5 12M9 11h6"}),jsx("path",{d:"M5 20h14",strokeWidth:"3"})]}),e==="more"&&jsxs(Fragment,{children:[jsx("circle",{cx:"5",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),jsx("circle",{cx:"12",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),jsx("circle",{cx:"19",cy:"12",r:"1",fill:"currentColor",stroke:"none"})]}),e==="chevronDown"&&jsx("path",{d:"m7 10 5 5 5-5"}),e==="remove"&&jsx("path",{d:"M5 12h14"}),e==="add"&&jsx("path",{d:"M12 5v14M5 12h14"})]})}var T={text:"#3c4043",muted:"#5f6368",disabled:"#9aa0a6",hover:"#e2e7ef",active:"#d3e3fd",border:"#c7cacf",surface:"#ffffff",rail:"#edf2fa"},zo={appearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:2,minWidth:28,height:28,padding:"0 5px",border:0,borderRadius:4,color:T.text,font:"500 13px ui-sans-serif, system-ui, sans-serif",lineHeight:1,whiteSpace:"nowrap",boxSizing:"border-box"};function Kt(e,t,r,i){return {...zo,background:t?T.active:r&&!e?T.hover:"transparent",color:e?T.disabled:T.text,cursor:e?"default":"pointer",opacity:e?.48:1,...i}}function ce({active:e=false,disabled:t=false,title:r,onClick:i,children:a,style:d,testId:h,ariaExpanded:g}){let[c,y]=useState(false);return jsx("button",{type:"button","data-testid":h,disabled:t,"aria-label":r,"aria-pressed":e||void 0,"aria-expanded":g,title:r,onMouseDown:S=>S.preventDefault(),onMouseEnter:()=>y(true),onMouseLeave:()=>y(false),onClick:t?void 0:i,style:Kt(t,e,c,d),children:a})}function be({label:e,children:t,style:r}){return jsx("div",{role:"group","aria-label":e,style:{display:"inline-flex",alignItems:"center",gap:1,flex:"0 0 auto",...r},children:t})}function De(){return jsx("div",{role:"separator",style:{width:1,height:24,margin:"0 5px",background:T.border,flex:"0 0 auto"}})}function Ae({title:e,trigger:t,children:r,disabled:i=false,active:a=false,menuWidth:d=220,style:h,testId:g}){let[c,y]=useState(false),[S,C]=useState(false),[z,U]=useState({top:0,left:0}),w=useRef(null),D=useRef(null),q=useCallback(()=>y(false),[]);return useEffect(()=>{if(!c||!w.current)return;let k=w.current.getBoundingClientRect(),J=Math.min(k.left,Math.max(8,window.innerWidth-d-8));U({top:k.bottom+4,left:J});},[c,d]),useEffect(()=>{if(!c)return;let k=$=>{let X=$.target;!w.current?.contains(X)&&!D.current?.contains(X)&&q();},J=$=>{$.key==="Escape"&&q();},I=()=>q();return document.addEventListener("mousedown",k),document.addEventListener("keydown",J),window.addEventListener("scroll",I,true),()=>{document.removeEventListener("mousedown",k),document.removeEventListener("keydown",J),window.removeEventListener("scroll",I,true);}},[c,q]),jsxs("div",{style:{position:"relative",display:"inline-flex",flex:"0 0 auto"},children:[jsx("button",{ref:w,type:"button","data-testid":g,disabled:i,"aria-label":e,"aria-haspopup":"menu","aria-expanded":c,title:e,onMouseDown:k=>k.preventDefault(),onMouseEnter:()=>C(true),onMouseLeave:()=>C(false),onClick:()=>!i&&y(k=>!k),style:Kt(i,a||c,S,h),children:t}),c&&jsx("div",{ref:D,role:"menu","aria-label":e,onMouseDown:k=>k.preventDefault(),style:{position:"fixed",top:z.top,left:z.left,zIndex:1e4,width:d,maxHeight:"min(440px, calc(100vh - 16px))",overflowY:"auto",padding:6,border:`1px solid ${T.border}`,borderRadius:8,background:T.surface,boxShadow:"0 4px 16px rgba(60, 64, 67, 0.24)",boxSizing:"border-box"},children:r(q)})]})}function Oe({label:e,icon:t,selected:r=false,disabled:i=false,onClick:a,close:d}){let[h,g]=useState(false);return jsxs("button",{type:"button",role:"menuitem",disabled:i,"aria-label":e,onMouseEnter:()=>g(true),onMouseLeave:()=>g(false),onClick:()=>{i||(a?.(),d?.());},style:{appearance:"none",display:"flex",alignItems:"center",gap:10,width:"100%",minHeight:32,padding:"5px 9px",border:0,borderRadius:4,background:h&&!i?T.hover:"transparent",color:i?T.disabled:T.text,cursor:i?"default":"pointer",opacity:i?.48:1,font:"400 13px ui-sans-serif, system-ui, sans-serif",textAlign:"left",boxSizing:"border-box"},children:[jsx("span",{style:{display:"inline-grid",placeItems:"center",width:20,flex:"0 0 auto"},children:t}),jsx("span",{style:{flex:1},children:e}),r&&jsx("span",{"aria-hidden":"true",children:"\u2713"})]})}function Ho(){return jsx("div",{role:"separator",style:{height:1,margin:"5px 2px",background:T.border}})}function ot({value:e,label:t,onChange:r,onClear:i,icon:a="textColor",none:d=false,clearLabel:h,disabled:g=false,testId:c}){let[y,S]=useState(false);return jsxs("span",{style:{display:"inline-flex",alignItems:"center",height:28},children:[jsxs("label",{title:t,"aria-label":t,style:{display:"inline-grid",placeItems:"center",width:28,height:28,borderRadius:4,background:y&&!g?T.hover:"transparent",color:g?T.disabled:T.text,cursor:g?"default":"pointer",opacity:g?.48:1,boxSizing:"border-box",position:"relative"},onMouseEnter:()=>S(true),onMouseLeave:()=>S(false),children:[jsx(B,{name:a,size:20}),jsx("span",{"aria-hidden":"true",style:{position:"absolute",left:5,right:5,bottom:2,height:3,borderRadius:2,background:d?"transparent":e,border:d?`1px solid ${T.disabled}`:0,boxSizing:"border-box"}}),d?jsx("span",{"aria-hidden":"true",style:{position:"absolute",left:5,bottom:3,width:18,height:1,background:"#d93025",transform:"rotate(-18deg)"}}):null,jsx("input",{"data-testid":c,type:"color",value:e,disabled:g,"aria-label":t,onChange:C=>r?.(C.target.value),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0}})]}),i?jsx("button",{type:"button",disabled:g,"aria-label":h??t,title:h??t,onMouseDown:C=>C.preventDefault(),onClick:i,style:{appearance:"none",width:15,height:28,padding:0,border:0,borderRadius:3,background:"transparent",color:g?T.disabled:T.muted,cursor:g?"default":"pointer",opacity:g?.48:1,font:"500 14px ui-sans-serif, system-ui, sans-serif"},children:"\xD7"}):null]})}function rt({value:e,options:t,label:r,onCommit:i,disabled:a=false,width:d=72,inputStyle:h,testId:g}){let[c,y]=useState(e),[S,C]=useState(false),[z,U]=useState({top:0,left:0,width:d}),w=useRef(null),D=useRef(null),q=useRef(null);useEffect(()=>y(e),[e]);let k=useCallback(()=>C(false),[]);useEffect(()=>{if(!S||!w.current)return;let I=w.current.getBoundingClientRect();U({top:I.bottom+4,left:I.left,width:Math.max(I.width,d)});},[S,d]),useEffect(()=>{if(!S)return;let I=X=>{let Ee=X.target;!w.current?.contains(Ee)&&!D.current?.contains(Ee)&&k();},$=X=>{X.key==="Escape"&&(y(e),k());};return document.addEventListener("mousedown",I),document.addEventListener("keydown",$),()=>{document.removeEventListener("mousedown",I),document.removeEventListener("keydown",$);}},[S,k,e]);let J=useCallback(()=>{!a&&i&&c.trim()&&i(c.trim()),y(e);},[a,i,c,e]);return jsxs("div",{ref:w,style:{display:"inline-flex",alignItems:"center",width:d,height:28,border:`1px solid ${T.border}`,borderRadius:4,background:a?"rgba(255,255,255,0.5)":T.surface,opacity:a?.48:1,boxSizing:"border-box",flex:"0 0 auto"},children:[jsx("input",{ref:q,"data-testid":g,role:"combobox","aria-label":r,"aria-autocomplete":"list","aria-expanded":S,disabled:a,value:c,onFocus:I=>{a||(C(true),I.currentTarget.select());},onChange:I=>y(I.target.value),onKeyDown:I=>{I.key==="Enter"?(J(),k(),I.currentTarget.blur()):I.key==="ArrowDown"&&(C(true),I.preventDefault());},onBlur:()=>{requestAnimationFrame(()=>{D.current?.contains(document.activeElement)||J();});},style:{appearance:"none",width:"calc(100% - 22px)",height:26,padding:"0 2px 0 7px",border:0,outline:0,background:"transparent",color:T.text,font:"500 13px ui-sans-serif, system-ui, sans-serif",boxSizing:"border-box",...h}}),jsx("button",{type:"button",disabled:a,tabIndex:-1,"aria-label":r,title:r,onMouseDown:I=>I.preventDefault(),onClick:()=>{a||(C(I=>!I),q.current?.focus());},style:{appearance:"none",display:"grid",placeItems:"center",width:21,height:26,padding:0,border:0,background:"transparent",color:T.muted,cursor:a?"default":"pointer"},children:jsx(B,{name:"chevronDown",size:14})}),S&&!a&&jsx("div",{ref:D,role:"listbox","aria-label":r,style:{position:"fixed",top:z.top,left:z.left,zIndex:1e4,width:z.width,maxHeight:260,overflowY:"auto",padding:4,border:`1px solid ${T.border}`,borderRadius:6,background:T.surface,boxShadow:"0 4px 16px rgba(60, 64, 67, 0.24)",boxSizing:"border-box"},children:t.map(I=>jsx("button",{type:"button",role:"option","aria-selected":I.value===e,onMouseDown:$=>$.preventDefault(),onClick:()=>{y(I.label),i?.(I.value),k();},style:{appearance:"none",display:"block",width:"100%",minHeight:28,padding:"4px 7px",border:0,borderRadius:3,background:I.value===e?T.active:"transparent",color:T.text,cursor:"pointer",font:"400 13px ui-sans-serif, system-ui, sans-serif",textAlign:"left"},children:I.label},I.value))})]})}var $e=[{geometry:"rect",labelKey:"toolbar.shapes.rect"},{geometry:"roundRect",labelKey:"toolbar.shapes.roundRect"},{geometry:"ellipse",labelKey:"toolbar.shapes.ellipse"},{geometry:"triangle",labelKey:"toolbar.shapes.triangle"},{geometry:"rtTriangle",labelKey:"toolbar.shapes.rtTriangle"},{geometry:"diamond",labelKey:"toolbar.shapes.diamond"},{geometry:"parallelogram",labelKey:"toolbar.shapes.parallelogram"},{geometry:"trapezoid",labelKey:"toolbar.shapes.trapezoid"},{geometry:"pentagon",labelKey:"toolbar.shapes.pentagon"},{geometry:"hexagon",labelKey:"toolbar.shapes.hexagon"},{geometry:"octagon",labelKey:"toolbar.shapes.octagon"},{geometry:"star5",labelKey:"toolbar.shapes.star5"},{geometry:"rightArrow",labelKey:"toolbar.shapes.rightArrow"},{geometry:"leftArrow",labelKey:"toolbar.shapes.leftArrow"},{geometry:"upArrow",labelKey:"toolbar.shapes.upArrow"},{geometry:"downArrow",labelKey:"toolbar.shapes.downArrow"},{geometry:"chevron",labelKey:"toolbar.shapes.chevron"}],Zo=[.5,.75,1,1.25,1.5,2],Xo=["Arial","Calibri","Cambria","Georgia","Roboto","Times New Roman","Verdana"],Go=[8,9,10,11,12,14,16,18,20,24,28,36,48,72],Yo=[1,2,3,4,8],jo=[0,10,17,25,33,50],$o=[0,10,20,30,40,50,60,70,80,90,100];function Vo(e){let t={};for(let r of Object.keys(e))e[r]!==void 0&&(t[r]=e[r]);return t}function qo(e){let t=useContext(Ne);return t?{...t,...Vo(e)}:e}function Gt(e,t,r){return r>0?t.find(i=>i>e)??e+1:[...t].reverse().find(i=>i<e)??Math.max(1,e-1)}function Jo(e){if(!e)return null;if(e.adj!==void 0)return ["adj",e.adj];if(e.adj1!==void 0)return ["adj1",e.adj1];let t=Object.keys(e).sort()[0];return t?[t,e[t]]:null}function nt(e){let{t}=He(),{currentFormatting:r={},textSelectionActive:i=false,onFormat:a,currentShapeFormatting:d={},shapeSelectionActive:h=false,onShapeFormat:g,onInsertSlide:c,slideLayouts:y=[],currentLayoutPartPath:S,onUndo:C,onRedo:z,canUndo:U=false,canRedo:w=false,zoom:D="fit",onZoomChange:q,activeTool:k="select",onToolChange:J,fontFamilies:I=Xo,fontSizes:$=Go,disabled:X=false,className:Ee,style:F,children:H}=qo(e),Be=useRef(null),[Ke,v]=useState(Number.POSITIVE_INFINITY),le=!X&&i&&!!a,p=!X&&h&&!!g,N=!X&&!!c,A=!X&&!!J,W=r.fontSize??24,ye=t("toolbar.fit"),_=D==="fit"?ye:`${Math.round(D*100)}%`,Q=Jo(d.adjustments),K=d.geometry==="roundRect"&&Q?.[0]==="adj";useEffect(()=>{let b=Be.current;if(!b)return;let P=()=>v(b.clientWidth);P();let Se=new ResizeObserver(P);return Se.observe(b),()=>Se.disconnect()},[]);let se=useMemo(()=>[{value:ye,label:ye},...Zo.map(b=>({value:`${b*100}%`,label:`${b*100}%`}))],[ye]),Je=useMemo(()=>$.map(b=>({value:String(b),label:String(b)})),[$]),ue=b=>{le&&a?.(b);},he=b=>{p&&g?.(b);},me=[{key:"new-slide",width:59,node:jsxs(be,{label:t("toolbar.groups.slides"),children:[jsx(ce,{title:t("toolbar.newSlide"),disabled:!N,onClick:()=>c?.(),style:{borderRadius:"4px 0 0 4px"},testId:"pptx-new-slide",children:jsx(B,{name:"newSlide"})}),jsx(Ae,{title:t("toolbar.newSlideWithLayout"),disabled:!N||y.length===0,menuWidth:230,testId:"pptx-new-slide-layout",style:{minWidth:20,width:20,padding:0,borderRadius:"0 4px 4px 0"},trigger:jsx(B,{name:"chevronDown",size:13}),children:b=>jsx(Fragment,{children:y.map((P,Se)=>jsx(Oe,{label:P.label??t("toolbar.layoutOption",{number:Se+1}),selected:(P.partPath??null)===(S??null),onClick:()=>c?.(P.partPath),close:b},P.partPath??`default-${Se}`))})})]})},{key:"history",width:75,node:jsxs(Fragment,{children:[jsx(De,{}),jsxs(be,{label:t("toolbar.groups.history"),children:[jsx(ce,{title:t("toolbar.undoShortcut"),disabled:X||!U||!C,onClick:C,testId:"pptx-undo",children:jsx(B,{name:"undo"})}),jsx(ce,{title:t("toolbar.redoShortcut"),disabled:X||!w||!z,onClick:z,testId:"pptx-redo",children:jsx(B,{name:"redo"})})]})]})},{key:"zoom",width:82,node:jsx(be,{label:t("toolbar.groups.zoom"),children:jsx(rt,{value:_,options:se,label:t("toolbar.zoomValue",{value:_}),disabled:X||!q,onCommit:b=>{if(b===ye){q?.("fit");return}let P=Number.parseFloat(b.replace("%",""));Number.isFinite(P)&&P>=25&&P<=400&&q?.(P/100);},width:76,testId:"pptx-zoom"})})},{key:"tools",width:127,node:jsxs(Fragment,{children:[jsx(De,{}),jsxs(be,{label:t("toolbar.groups.tools"),children:[jsx(ce,{title:t("toolbar.selectToolShortcut"),active:k==="select",disabled:!A,onClick:()=>J?.("select"),testId:"pptx-tool-select",children:jsx(B,{name:"select"})}),jsx(ce,{title:t("toolbar.textBoxTool"),active:k==="textBox",disabled:!A,onClick:()=>J?.("textBox"),testId:"pptx-tool-text-box",children:jsx(B,{name:"textBox"})}),jsx(Ae,{title:t("toolbar.shapeTool"),active:k.startsWith("shape:"),disabled:!A,menuWidth:264,testId:"pptx-tool-shape",style:{minWidth:46,padding:"0 4px"},trigger:jsxs(Fragment,{children:[jsx(B,{name:"shape"}),jsx(B,{name:"chevronDown",size:11})]}),children:b=>jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(5, 44px)",gap:4,padding:2},children:$e.map(P=>jsx("button",{type:"button",role:"menuitem","data-testid":`pptx-shape-${P.geometry}`,"aria-label":t(P.labelKey),title:t(P.labelKey),onClick:()=>{J?.(`shape:${P.geometry}`),b();},style:{appearance:"none",display:"grid",placeItems:"center",width:44,height:38,padding:5,border:`1px solid ${T.border}`,borderRadius:4,background:k===`shape:${P.geometry}`?T.active:T.surface,color:T.text,cursor:"pointer"},children:jsx(Qo,{geometry:P.geometry})},P.geometry))})})]})]})},{key:"font-family",width:137,node:jsxs(Fragment,{children:[jsx(De,{}),jsx(be,{label:t("toolbar.groups.font"),children:jsx(Ae,{title:t("toolbar.fontFamily"),disabled:!le,menuWidth:210,testId:"pptx-font-family",style:{width:120,justifyContent:"space-between"},trigger:jsxs(Fragment,{children:[jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:r.fontFamily??t("toolbar.mixed")}),jsx(B,{name:"chevronDown",size:13})]}),children:b=>jsx(Fragment,{children:I.map(P=>jsx(Oe,{label:P,selected:r.fontFamily===P,onClick:()=>ue({type:"fontFamily",value:P}),close:b},P))})})})]})},{key:"font-size",width:116,node:jsxs(be,{label:t("toolbar.groups.font"),children:[jsx(ce,{title:t("toolbar.decreaseFontSize"),disabled:!le,onClick:()=>ue({type:"fontSize",value:Gt(W,$,-1)}),children:jsx(B,{name:"remove"})}),jsx(rt,{value:r.fontSize===void 0?"":String(W),options:Je,label:t("toolbar.fontSize"),disabled:!le,onCommit:b=>{let P=Number.parseFloat(b);Number.isFinite(P)&&P>=1&&P<=400&&ue({type:"fontSize",value:P});},width:50,inputStyle:{textAlign:"center"},testId:"pptx-font-size"}),jsx(ce,{title:t("toolbar.increaseFontSize"),disabled:!le,onClick:()=>ue({type:"fontSize",value:Gt(W,$,1)}),children:jsx(B,{name:"add"})})]})},{key:"text",width:133,node:jsxs(Fragment,{children:[jsx(De,{}),jsxs(be,{label:t("toolbar.groups.text"),children:[jsx(ce,{title:t("toolbar.boldShortcut"),active:r.bold,disabled:!le,onClick:()=>ue("bold"),testId:"pptx-bold",children:jsx(B,{name:"bold"})}),jsx(ce,{title:t("toolbar.italicShortcut"),active:r.italic,disabled:!le,onClick:()=>ue("italic"),testId:"pptx-italic",children:jsx(B,{name:"italic"})}),jsx(ce,{title:t("toolbar.underlineShortcut"),active:r.underline,disabled:!le,onClick:()=>ue("underline"),testId:"pptx-underline",children:jsx(B,{name:"underline"})}),jsx(ot,{value:r.textColor??"#000000",label:t("toolbar.textColor"),disabled:!le,onChange:b=>ue({type:"textColor",value:b}),testId:"pptx-text-color"})]})]})},{key:"shape-formatting",width:Q?244:172,node:jsxs(Fragment,{children:[jsx(De,{}),jsxs(be,{label:t("toolbar.groups.shape"),children:[jsx(ot,{value:d.fillColor??"#d9eaf7",label:t("toolbar.fillColor"),clearLabel:t("toolbar.noFill"),icon:"fillColor",none:!d.fillColor,disabled:!p,onChange:b=>he({type:"fillColor",value:b}),onClear:()=>he({type:"fillColor",value:null}),testId:"pptx-shape-fill"}),jsx(ot,{value:d.strokeColor??"#202124",label:t("toolbar.borderColor"),clearLabel:t("toolbar.noBorder"),icon:"borderColor",none:!d.strokeColor,disabled:!p,onChange:b=>he({type:"strokeColor",value:b}),onClear:()=>he({type:"strokeColor",value:null}),testId:"pptx-shape-border-color"}),jsx(Ae,{title:t("toolbar.borderWidth"),disabled:!p,menuWidth:170,testId:"pptx-shape-border-width",trigger:jsx(B,{name:"borderWidth"}),children:b=>jsxs(Fragment,{children:[jsx(Oe,{label:t("toolbar.noBorder"),selected:d.strokeWidthPt===null,onClick:()=>he({type:"strokeWidth",value:null}),close:b}),Yo.map(P=>jsx(Oe,{label:t("toolbar.borderWidthValue",{width:P}),selected:d.strokeWidthPt===P,icon:jsx("span",{"aria-hidden":"true",style:{width:18,borderTop:`${Math.min(P,5)}px solid currentColor`}}),onClick:()=>he({type:"strokeWidth",value:P}),close:b},P))]})}),Q?jsx(rt,{value:`${Math.round(Q[1]*100)}%`,options:(K?jo:$o).map(b=>({value:String(b),label:`${b}%`})),label:t(K?"toolbar.cornerRadius":"toolbar.shapeAdjustment"),disabled:!p,onCommit:b=>{let P=Number.parseFloat(b.replace("%",""));if(Number.isFinite(P)){let Se=K?50:100;he({type:"adjust",name:Q[0],value:Math.max(0,Math.min(Se,P))/100});}},width:68,inputStyle:{textAlign:"center"},testId:K?"pptx-shape-corner-radius":"pptx-shape-adjustment"}):null]})]})}];H&&me.push({key:"custom",width:40,node:H});let st=Math.max(0,Ke-48),Me=0,pe=me.length;for(let b=0;b<me.length;b++)if(Me+=me[b].width,Me>st){pe=b;break}let ke=me.slice(0,pe),Qe=me.slice(pe);return jsxs("div",{ref:Be,className:Ee,role:"toolbar","aria-label":t("toolbar.label"),"data-testid":"pptx-formatting-toolbar",style:{display:"flex",alignItems:"center",minWidth:0,minHeight:36,margin:"0 8px 5px",padding:"4px 7px",borderRadius:18,background:T.rail,color:T.text,overflow:"hidden",boxSizing:"border-box",...F},children:[ke.map(b=>jsx("span",{style:{display:"contents"},children:b.node},b.key)),jsx("span",{style:{marginLeft:"auto",flex:"0 0 auto"},children:jsx(Ae,{title:t("toolbar.more"),disabled:Qe.length===0,menuWidth:390,testId:"pptx-toolbar-more",trigger:jsx(B,{name:"more"}),children:()=>jsx("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:2},children:Qe.map(b=>jsx("span",{style:{display:"contents"},children:b.node},b.key))})})})]})}function Qo({geometry:e}){let t={rect:"M3 5h18v14H3Z",roundRect:"M7 5h10a4 4 0 0 1 4 4v6a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4V9a4 4 0 0 1 4-4Z",ellipse:"M3 12a9 7 0 1 0 18 0 9 7 0 1 0-18 0",triangle:"m12 4 9 16H3Z",rtTriangle:"M4 4v16h16Z",diamond:"m12 3 9 9-9 9-9-9Z",parallelogram:"M7 5h14l-4 14H3Z",trapezoid:"M7 5h10l4 14H3Z",pentagon:"m12 3 9 7-4 11H7L3 10Z",hexagon:"m7 4 10 0 5 8-5 8H7l-5-8Z",octagon:"m7 3 10 0 4 4v10l-4 4H7l-4-4V7Z",star5:"m12 2.5 2.8 6 6.5.6-5 4.3 1.6 6.4-5.7-3.4-5.7 3.4 1.6-6.4-5-4.3 6.5-.6Z",rightArrow:"M3 8h11V4l7 8-7 8v-4H3Z",leftArrow:"m21 8H10V4l-7 8 7 8v-4h11Z",upArrow:"M8 21V10H4l8-7 8 7h-4v11Z",downArrow:"M8 3v11H4l8 7 8-7h-4V3Z",chevron:"M4 4h9l7 8-7 8H4l7-8Z"}[e];return jsx("svg",{width:"30",height:"24",viewBox:"0 0 24 24",fill:"rgba(60, 64, 67, 0.08)",stroke:"currentColor",strokeWidth:"1.4",strokeLinejoin:"round","aria-hidden":"true",children:jsx("path",{d:t})})}function er({children:e,className:t,style:r,...i}){return jsx(Ne.Provider,{value:i,children:jsx("div",{className:t,"data-testid":"pptx-editor-toolbar",style:{display:"flex",flexDirection:"column",flex:"0 0 auto",...r},children:e})})}var Ve=er;Ve.Toolbar=nt;function gt(e,t,r,i){if(!Number.isFinite(e.width)||!Number.isFinite(e.height)||e.width<=0||e.height<=0)return null;let a=(r-e.left)*t.width/e.width,d=(i-e.top)*t.height/e.height;return Number.isFinite(a)&&Number.isFinite(d)?{x:a,y:d}:null}function Ce(e,t){for(let r of e){if(r.id===t)return r;let i=Ce(r.children,t);if(i)return i}return null}function $t(e){let t=new Map,r=[...e];for(;r.length>0;){let i=r.pop();t.set(i.id,i),r.push(...i.children);}return t}function yt(e,t){for(let r of e.shapes)if(r.id===t||Ce(r.children,t))return r;return null}function St(e){return e.width>0&&e.height>0}function Pt(e,t,r){let i=new Set;Jt(r,i);let a=t.primitives.filter(S=>S.shapeId&&i.has(S.shapeId));if(a.length===0)return r.width<=0||r.height<=0||e.widthEmu<=0||e.heightEmu<=0?null:{x:r.x*t.width/e.widthEmu,y:r.y*t.height/e.heightEmu,width:r.width*t.width/e.widthEmu,height:r.height*t.height/e.heightEmu};let d=a.map(S=>{let C=(S.transform?.rotationDeg??0)*Math.PI/180,z=Math.abs(S.w*Math.cos(C))+Math.abs(S.h*Math.sin(C)),U=Math.abs(S.w*Math.sin(C))+Math.abs(S.h*Math.cos(C));return {x:S.x+(S.w-z)/2,y:S.y+(S.h-U)/2,width:z,height:U}}),h=Math.min(...d.map(S=>S.x)),g=Math.min(...d.map(S=>S.y)),c=Math.max(...d.map(S=>S.x+S.width)),y=Math.max(...d.map(S=>S.y+S.height));return {x:h,y:g,width:c-h,height:y-g}}function Vt(e,t,r,i){let a=e.primitives.find(c=>c.kind==="textBox"&&c.shapeId===t&&c.storyId===r);if(!a||a.lines.length===0)return null;let d=a.lines.reduce((c,y)=>jt(y.y,y.height,i.y)<jt(c.y,c.height,i.y)?y:c),h=d.caretStops[0];return h?d.caretStops.reduce((c,y)=>Math.abs(y.x-i.x)<Math.abs(c.x-i.x)?y:c,h).position:d.start}function qt(e,t,r,i){return {x:r.x+Math.round(i.x*e.widthEmu/t.width),y:r.y+Math.round(i.y*e.heightEmu/t.height)}}function vt(e,t,r,i,a=4){return Math.hypot(r-e,i-t)>=a}function Jt(e,t){t.add(e.id);for(let r of e.children)Jt(r,t);}function jt(e,t,r){return r<e?e-r:r>e+t?r-e-t:0}function Qt(e,t=12){return {visible:e.slice(0,t),overflow:Math.max(0,e.length-t)}}function eo(e,t,r=4){let i=new Map;for(let a of e){let d=a.state.cursor?.slideId;if(!d||!t.has(d))continue;let h=i.get(d)??{visible:[],overflow:0};h.visible.length<r?h.visible.push(a):h.overflow+=1,i.set(d,h);}return i}function to(e,t,r,i=24){let a=new Map,d=0;for(let h of e){let g=h.state.cursor;if(g?.slideId!==t||!g.shapeId||!r.has(g.shapeId))continue;let c=a.get(g.shapeId);c?(c.count+=1,h.cursorMovedAt>c.peer.cursorMovedAt&&(c.peer=h)):a.size<i?a.set(g.shapeId,{shapeId:g.shapeId,peer:h,count:1}):d+=1;}return {visible:[...a.values()],overflow:d}}function it(e,t,r,i){let a=tr(e,t,r,i),d=We(a,"underline");return {bold:We(a,"bold"),italic:We(a,"italic"),underline:d===void 0?void 0:d!=="none",fontSize:We(a,"fontSizePt"),textColor:We(a,"color"),fontFamily:We(a,"fontFamily")}}function oo(e,t){return it(e,0,e.length,t)}function ro(e,t,r,i){let a=it(e,t,r,i);return {bold:a.bold??i.bold,italic:a.italic??i.italic,underline:a.underline===void 0?i.underline:a.underline?"sng":"none",fontSizePt:a.fontSize??i.fontSizePt,color:a.textColor??i.color,fontFamily:a.fontFamily??i.fontFamily}}function tr(e,t,r,i){let a=or(e,i);if(a.length===0)return [i];let d=Math.min(t,r),h=Math.max(t,r);if(d===h){let y=a.find(C=>d>=C.start&&d<C.end);return y?[y.style]:[[...a].reverse().find(C=>C.end<=d)?.style??a[0].style]}let g=a.filter(y=>y.end>d&&y.start<h).map(y=>y.style);return g.length>0?g:[[...a].reverse().find(y=>y.end<=d)?.style??a[0].style]}function or(e,t){let r=[],i=0;return e.paragraphs.forEach((a,d)=>{for(let h of a.runs){let g=i;i+=h.text.length,i>g&&r.push({start:g,end:i,style:rr(h.style,t)});}d<e.paragraphs.length-1&&(i+=1);}),r}function rr(e,t){return {bold:e.bold??t.bold,italic:e.italic??t.italic,underline:e.underline??t.underline,fontSizePt:e.fontSizePt??t.fontSizePt,color:e.color??t.color,fontFamily:e.fontFamily??t.fontFamily}}function We(e,t){let r=e[0]?.[t];return e.every(i=>i[t]===r)?r:void 0}function io(e){let t=e?.fill?.type==="none"?null:no(e?.resolvedFillColor),r=no(e?.resolvedOutlineColor);return {geometry:e?.geometry,fillColor:t,strokeColor:r,strokeWidthPt:r&&e?.outline?.width!==void 0?e.outline.width/12700:r?1:null,adjustments:e?.adjustValues??{}}}function no(e){if(!e)return null;let t=e.replace(/^#/,"");return /^[0-9a-f]{6}$/i.test(t)?`#${t}`:null}var nr=new Intl.Segmenter(void 0,{granularity:"word"});function It(e,t,r){return r==="word"?ir(e,t):ar(e,t)}function ir(e,t){let r=lo(e,t),i=[...nr.segment(e)],a=i.find(d=>r>=d.index&&r<d.index+d.segment.length)??i[i.length-1];return a?{start:a.index,end:a.index+a.segment.length}:{start:r,end:r}}function ar(e,t){let r=lo(e,t),i=e.lastIndexOf(`
|
|
2
|
-
`,Math.max(0,
|
|
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
|
|
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,8 +40,8 @@
|
|
|
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",
|