@sqren/docx-editor-react 1.7.0-fork.0 → 1.7.0-fork.1
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/dist/KeyboardShortcutsDialog-B-h3NAat.d.mts +3 -3
- package/dist/KeyboardShortcutsDialog-B-h3NAat.d.ts +3 -3
- package/dist/WatermarkDialog-KRL7WMIS.mjs +1 -1
- package/dist/WatermarkDialog-XGLAH3TK.js +1 -1
- package/dist/chunk-4Y4JFAPY.mjs +1 -1
- package/dist/chunk-74OM4KEH.js +1 -1
- package/dist/chunk-7VWJSV3T.js +1 -1
- package/dist/chunk-BABMU5KA.mjs +1 -1
- package/dist/chunk-BZO4G5M6.js +1 -1
- package/dist/chunk-GNIO6SOS.js +1 -1
- package/dist/chunk-IVFYCMAM.mjs +1 -1
- package/dist/chunk-L4MDZW2J.js +1 -1
- package/dist/chunk-LNONBJQM.js +1 -1
- package/dist/chunk-OHNO4NRQ.mjs +1 -1
- package/dist/chunk-P5ZOUQIK.mjs +1 -1
- package/dist/chunk-P6METJHI.mjs +1 -1
- package/dist/chunk-WFGAQC2B.mjs +1 -1
- package/dist/chunk-WNWY6WX7.js +1 -1
- package/dist/chunk-YY52FSUR.js +1 -1
- package/dist/chunk-ZFZJRL2R.mjs +1 -1
- package/dist/dialogs.d.mts +7 -7
- package/dist/dialogs.d.ts +7 -7
- package/dist/hooks.d.mts +9 -9
- package/dist/hooks.d.ts +9 -9
- package/dist/hooks.js +1 -1
- package/dist/hooks.mjs +1 -1
- package/dist/index.d.mts +27 -27
- package/dist/index.d.ts +27 -27
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/plugin-api.d.mts +8 -8
- package/dist/plugin-api.d.ts +8 -8
- package/dist/plugin-api.js +1 -1
- package/dist/plugin-api.mjs +1 -1
- package/dist/styles.d.mts +2 -2
- package/dist/styles.d.ts +2 -2
- package/dist/types-D35gNE-_.d.mts +1 -1
- package/dist/types-D35gNE-_.d.ts +1 -1
- package/dist/ui.d.mts +12 -12
- package/dist/ui.d.ts +12 -12
- package/dist/ui.js +1 -1
- package/dist/ui.mjs +1 -1
- package/dist/useFindReplace-Bc2ubEeV.d.mts +2 -2
- package/dist/useFindReplace-Bc2ubEeV.d.ts +2 -2
- package/package.json +4 -4
package/dist/chunk-P6METJHI.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {b,c,a}from'./chunk-BABMU5KA.mjs';import {b as b$1}from'./chunk-ZFZJRL2R.mjs';import*as j from'react';import j__default,{createContext,useState,useRef,useCallback,useMemo,useEffect,Children,isValidElement,useContext}from'react';import {clsx}from'clsx';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {halfPointsToPoints}from'@eigenpal/docx-editor-core/utils/units';export{pointsToHalfPoints as d}from'@eigenpal/docx-editor-core/utils/units';import {createDefaultListState}from'@eigenpal/docx-editor-core/utils/listState';export{createDefaultListState as f}from'@eigenpal/docx-editor-core/utils/listState';import {en as en$1}from'@eigenpal/docx-editor-i18n';import*as N from'@radix-ui/react-select';import {generateThemeTintShadeMatrix,resolveColorToHex,twipsToPixels,pixelsToTwips,formatPx,resolveHighlightColor,resolveColor}from'@eigenpal/docx-editor-core/utils';import {resolveParagraphStyleOptions,getStylePreviewProps}from'@eigenpal/docx-editor-core/utils/stylePreview';import {normalizeFontFamilies}from'@eigenpal/docx-editor-core/utils/fontOptions';export{mapHexToHighlightName as g}from'@eigenpal/docx-editor-core/utils/highlightColors';import {openReportIssue}from'@eigenpal/docx-editor-core/utils/reportIssue';var qt=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,Yt=clsx,Xt=(e,t)=>o=>{var r;if(t?.variants==null)return Yt(e,o?.class,o?.className);let{variants:n,defaultVariants:s}=t,i=Object.keys(n).map(a=>{let p=o?.[a],m=s?.[a];if(p===null)return null;let l=qt(p)||qt(m);return n[a][l]}),c=o&&Object.entries(o).reduce((a,p)=>{let[m,l]=p;return l===void 0||(a[m]=l),a},{}),d=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((a,p)=>{let{class:m,className:l,...u}=p;return Object.entries(u).every(f=>{let[g,x]=f;return Array.isArray(x)?x.includes({...s,...c}[g]):{...s,...c}[g]===x})?[...a,m,l]:a},[]);return Yt(e,i,d,o?.class,o?.className)};function P(...e){return clsx(e)}var dr=Xt("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-9 w-9","icon-sm":"h-7 w-7"}},defaultVariants:{variant:"default",size:"default"}}),K=j.forwardRef(({className:e,variant:t,size:o,...r},n)=>jsx("button",{className:P(dr({variant:t,size:o,className:e})),ref:n,...r}));K.displayName="Button";var mr=[8,9,10,11,12,14,16,18,20,24,28,36,48,72],fr=1,gr=400;function Jt(e,t,o){for(let r of t)if(r>e)return r;return Math.min(e+1,o)}function Qt(e,t,o){for(let r=t.length-1;r>=0;r--)if(t[r]<e)return t[r];return Math.max(e-1,o)}function eo({value:e,onChange:t,sizes:o=mr,disabled:r=false,className:n,placeholder:s="11",minSize:i=fr,maxSize:c$1=gr}){let{t:d}=b$1(),[a,p]=useState(false),[m,l]=useState(""),[u,f]=useState(false),g=useRef(null),x=useCallback(()=>{f(false),p(false);},[]),{containerRef:b$2,dropdownRef:h,dropdownStyle:v}=c({isOpen:u,onClose:x}),C=e??(parseInt(s,10)||11),w=e!==void 0?e.toString():s,L=useCallback(M=>{if(M.preventDefault(),r)return;let _=Qt(C,o,i);t?.(_);},[C,o,i,r,t]),J=useCallback(M=>{if(M.preventDefault(),r)return;let _=Jt(C,o,c$1);t?.(_);},[C,o,c$1,r,t]),O=useCallback(M=>{M.preventDefault(),!r&&(p(true),l(w),f(true),requestAnimationFrame(()=>{g.current?.focus(),g.current?.select();}));},[r,w]),Y=useCallback(M=>{l(M.target.value);},[]),de=useCallback(()=>{p(false);let M=parseFloat(m);if(!isNaN(M)&&M>=i&&M<=c$1){let _=Math.round(M*2)/2;t?.(_);}},[m,i,c$1,t]),be=useCallback(M=>{if(M.key==="Enter")M.preventDefault(),de(),f(false);else if(M.key==="Escape")p(false),f(false);else if(M.key==="ArrowUp"){M.preventDefault();let _=Jt(C,o,c$1);l(_.toString()),t?.(_);}else if(M.key==="ArrowDown"){M.preventDefault();let _=Qt(C,o,i);l(_.toString()),t?.(_);}},[de,C,o,c$1,i,t]),G=useCallback(M=>{t?.(M),f(false),p(false);},[t]),R=useCallback(M=>{M.target.tagName!=="INPUT"&&M.preventDefault();},[]);return jsxs("div",{ref:b$2,className:P("flex items-center",n),onMouseDown:R,children:[jsx(K,{variant:"ghost",size:"icon-sm",className:P("h-7 w-7 text-muted-foreground hover:text-foreground hover:bg-muted/80 rounded-r-none",r&&"opacity-30 cursor-not-allowed"),onMouseDown:L,disabled:r||C<=i,"aria-label":d("fontSize.decrease"),"data-testid":"font-size-decrease",children:jsx(b,{name:"remove",size:18})}),jsx("div",{className:"relative",children:a?jsx("input",{ref:g,type:"text",value:m,onChange:Y,onBlur:de,onKeyDown:be,className:P("h-7 w-10 text-center text-sm border border-input bg-doc-bg-input text-doc-text","focus:outline-none focus:ring-1 focus:ring-ring","rounded-none"),"aria-label":d("fontSize.label"),"data-testid":"font-size-input"}):jsx("button",{type:"button",onClick:O,className:P("h-7 w-10 text-center text-sm border border-border bg-doc-bg-input text-doc-text","hover:border-input hover:bg-doc-bg-hover","focus:outline-none focus:ring-1 focus:ring-ring","rounded-none",r&&"opacity-50 cursor-not-allowed"),disabled:r,"aria-label":d("fontSize.label"),"aria-haspopup":"listbox","aria-expanded":u,"data-testid":"font-size-display",children:w})}),u&&jsx("div",{ref:h,style:{...v,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:6,boxShadow:"0 4px 12px var(--doc-shadow)",maxHeight:240,overflowY:"auto",minWidth:60},role:"listbox","aria-label":d("fontSize.listLabel"),children:o.map(M=>jsx("button",{type:"button",onClick:()=>G(M),className:P("w-full px-3 py-1.5 text-sm text-left","hover:bg-muted",M===C&&"bg-muted font-medium"),role:"option","aria-selected":M===C,children:M},M))}),jsx(K,{variant:"ghost",size:"icon-sm",className:P("h-7 w-7 text-muted-foreground hover:text-foreground hover:bg-muted/80 rounded-l-none",r&&"opacity-30 cursor-not-allowed"),onMouseDown:J,disabled:r||C>=c$1,"aria-label":d("fontSize.increase"),"data-testid":"font-size-increase",children:jsx(b,{name:"add",size:18})})]})}var vr={display:"inline-flex",alignItems:"center",gap:"4px"},oo={display:"inline-flex",alignItems:"center",gap:"4px"},st={display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px",padding:"4px",border:"none",borderRadius:"4px",backgroundColor:"transparent",cursor:"pointer",transition:"background-color 0.1s",color:"var(--doc-text-muted)"},yr={...st,backgroundColor:"var(--doc-bg-hover)"},Cr={...st,backgroundColor:"var(--doc-primary-light)",color:"var(--doc-primary)"},Sr={...st,cursor:"default",opacity:.38},wr={width:"28px",height:"28px",padding:"2px"},Tr={width:"1px",height:"20px",backgroundColor:"var(--doc-border)",margin:"0 6px"},at=20;function it({active:e=false,disabled:t=false,title:o,onClick:r,children:n,className:s,style:i}){let[c,d]=useState(false),a={...t?Sr:e?Cr:c?yr:st,...i},p=m=>{m.preventDefault();};return jsx("button",{type:"button",className:`docx-list-button ${e?"docx-list-button-active":""} ${t?"docx-list-button-disabled":""} ${s||""}`,style:a,onMouseDown:p,onClick:t?void 0:r,onMouseEnter:()=>d(true),onMouseLeave:()=>d(false),disabled:t,title:o,"aria-label":o,"aria-pressed":e,role:"button",children:n})}function ro({listState:e,onBulletList:t,onNumberedList:o,onIndent:r,onOutdent:n,disabled:s=false,className:i,style:c,showIndentButtons:d=true,compact:a=false,hasIndent:p=false}){let{t:m}=b$1(),l=useCallback(()=>a?{...wr}:{},[a]),u=e?.type==="bullet",f=e?.type==="numbered",x=(e?.isInList||u||f)&&(e?.level??0)>0||p;return jsxs("div",{className:`docx-list-buttons ${i||""}`,style:{...vr,...c},role:"group","aria-label":m("lists.ariaLabel"),children:[jsxs("div",{style:oo,role:"group","aria-label":m("lists.typeAriaLabel"),children:[jsx(it,{active:u,disabled:s,title:m("lists.bulletList"),onClick:t,style:l(),children:jsx(b,{name:"format_list_bulleted",size:at})}),jsx(it,{active:f,disabled:s,title:m("lists.numberedList"),onClick:o,style:l(),children:jsx(b,{name:"format_list_numbered",size:at})})]}),d&&jsxs(Fragment,{children:[jsx("div",{style:Tr,role:"separator"}),jsxs("div",{style:oo,role:"group","aria-label":m("lists.indentationAriaLabel"),children:[jsx(it,{active:false,disabled:s||!x,title:m("lists.decreaseIndent"),onClick:n,style:l(),children:jsx(b,{name:"format_indent_decrease",size:at})}),jsx(it,{active:false,disabled:s,title:m("lists.increaseIndent"),onClick:r,style:l(),children:jsx(b,{name:"format_indent_increase",size:at})})]})]})]})}var ct={hfInlineEditor:10,ruler:30,outline:40,dropdown:100,toolbar:100,contextMenu:1e4};var io=[{action:"cut",labelKey:"contextMenu.cut",shortcutKey:"contextMenu.cutShortcut"},{action:"copy",labelKey:"contextMenu.copy",shortcutKey:"contextMenu.copyShortcut"},{action:"paste",labelKey:"contextMenu.paste",shortcutKey:"contextMenu.pasteShortcut"},{action:"pasteAsPlainText",labelKey:"contextMenu.pastePlainText",shortcutKey:"contextMenu.pastePlainTextShortcut",dividerAfter:true},{action:"delete",labelKey:"contextMenu.delete",shortcutKey:"contextMenu.deleteShortcut",dividerAfter:true},{action:"selectAll",labelKey:"contextMenu.selectAll",shortcutKey:"contextMenu.selectAllShortcut"}],Ir=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("circle",{cx:"4",cy:"12",r:"2",stroke:"currentColor",strokeWidth:"1.5"}),jsx("circle",{cx:"12",cy:"12",r:"2",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M5.5 10.5L10.5 3M10.5 10.5L5.5 3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),Lr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"5",y:"5",width:"8",height:"9",rx:"1",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M11 5V3a1 1 0 00-1-1H4a1 1 0 00-1 1v8a1 1 0 001 1h2",stroke:"currentColor",strokeWidth:"1.5"})]}),Rr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"3",y:"3",width:"10",height:"11",rx:"1",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M6 3V2a1 1 0 011-1h2a1 1 0 011 1v1",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M6 8h4M6 11h4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),Er=()=>jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{d:"M4 4l8 8M12 4l-8 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})}),Ar=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1",stroke:"currentColor",strokeWidth:"1.5",strokeDasharray:"2 2"}),jsx("rect",{x:"4",y:"4",width:"8",height:"8",fill:"currentColor",opacity:"0.3"})]}),Nr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"6",width:"12",height:"4",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("rect",{x:"2",y:"10",width:"12",height:"4",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M8 1v3M6.5 2.5h3",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]}),Dr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"2",width:"12",height:"4",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("rect",{x:"2",y:"6",width:"12",height:"4",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M8 12v3M6.5 13.5h3",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]}),Br=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"2",width:"12",height:"4",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("rect",{x:"2",y:"6",width:"12",height:"4",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2",opacity:"0.3"}),jsx("rect",{x:"2",y:"10",width:"12",height:"4",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M5 8h6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),_r=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"6",y:"2",width:"4",height:"12",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("rect",{x:"10",y:"2",width:"4",height:"12",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M3 8H0.5M1.75 6.5v3",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]}),Fr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"2",width:"4",height:"12",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("rect",{x:"6",y:"2",width:"4",height:"12",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M13 8h2.5M14.25 6.5v3",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]}),Or=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"2",width:"4",height:"12",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("rect",{x:"6",y:"2",width:"4",height:"12",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2",opacity:"0.3"}),jsx("rect",{x:"10",y:"2",width:"4",height:"12",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M8 5v6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),zr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"4",width:"4",height:"8",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("rect",{x:"10",y:"4",width:"4",height:"8",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M7 8h2",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),jsx("path",{d:"M8 7l1 1-1 1",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]}),Kr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"4",width:"12",height:"8",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M8 4v8",stroke:"currentColor",strokeWidth:"1.2",strokeDasharray:"2 1"}),jsx("path",{d:"M6.5 8h-1M9.5 8h1",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),Hr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M3 3h10a1 1 0 011 1v6a1 1 0 01-1 1H6l-3 2.5V11H3a1 1 0 01-1-1V4a1 1 0 011-1z",stroke:"currentColor",strokeWidth:"1.3"}),jsx("path",{d:"M5 6h6M5 8.5h4",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]});function Wr(e){switch(e){case "cut":return jsx(Ir,{});case "copy":return jsx(Lr,{});case "paste":case "pasteAsPlainText":return jsx(Rr,{});case "delete":return jsx(Er,{});case "selectAll":return jsx(Ar,{});case "addRowAbove":return jsx(Nr,{});case "addRowBelow":return jsx(Dr,{});case "deleteRow":return jsx(Br,{});case "addColumnLeft":return jsx(_r,{});case "addColumnRight":return jsx(Fr,{});case "deleteColumn":return jsx(Or,{});case "mergeCells":return jsx(zr,{});case "splitCell":return jsx(Kr,{});case "addComment":return jsx(Hr,{});default:return null}}var Vr=({item:e,onClick:t,isHighlighted:o,onMouseEnter:r})=>e.action==="separator"?jsx("div",{className:"docx-text-context-menu-separator",style:{height:"1px",backgroundColor:"var(--doc-border)",margin:"4px 12px"}}):jsxs(Fragment,{children:[jsxs("button",{type:"button",className:`docx-text-context-menu-item ${o?"docx-text-context-menu-item-highlighted":""} ${e.disabled?"docx-text-context-menu-item-disabled":""}`,onClick:t,onMouseEnter:r,disabled:e.disabled,role:"menuitem","aria-disabled":e.disabled,style:{display:"flex",alignItems:"center",gap:"10px",width:"100%",padding:"8px 12px",border:"none",background:o&&!e.disabled?"var(--doc-primary-light)":"transparent",cursor:e.disabled?"not-allowed":"pointer",fontSize:"13px",color:e.disabled?"var(--doc-text-subtle)":"var(--doc-text)",textAlign:"left",opacity:e.disabled?.6:1},children:[jsx("span",{style:{display:"flex",color:e.disabled?"var(--doc-border)":"var(--doc-text-muted)"},children:Wr(e.action)}),jsx("span",{style:{flex:1},children:e.label}),e.shortcut&&jsx("span",{style:{fontSize:"11px",color:"var(--doc-text-subtle)",fontFamily:"monospace"},children:e.shortcut})]}),e.dividerAfter&&jsx("div",{className:"docx-text-context-menu-separator",style:{height:"1px",backgroundColor:"var(--doc-border)",margin:"4px 12px"}})]}),ui=({isOpen:e,position:t,hasSelection:o,isEditable:r,hasClipboardContent:n=true,onAction:s,onClose:i,items:c,className:d=""})=>{let a=useRef(null),[p,m]=useState(0),{t:l}=b$1(),u=useMemo(()=>io.map(h=>({action:h.action,label:l(h.labelKey),shortcut:h.shortcutKey?l(h.shortcutKey):void 0,dividerAfter:h.dividerAfter})),[l]),f=(c||u).map(h=>{let v=(()=>{if(h.disabled!==void 0)return h.disabled;switch(h.action){case "cut":case "copy":case "delete":return !o;case "paste":case "pasteAsPlainText":return !r||!n;default:return false}})();return {...h,disabled:v}}),g=f.filter(h=>h.action!=="separator");useEffect(()=>{if(!e)return;let h=C=>{a.current&&!a.current.contains(C.target)&&i();},v=setTimeout(()=>{document.addEventListener("mousedown",h);},0);return ()=>{clearTimeout(v),document.removeEventListener("mousedown",h);}},[e,i]),useEffect(()=>{if(!e)return;let h=v=>{switch(v.key){case "Escape":v.preventDefault(),i();break;case "ArrowDown":v.preventDefault(),m(w=>{let L=(w+1)%g.length;for(;g[L]?.disabled&&L!==w;)L=(L+1)%g.length;return L});break;case "ArrowUp":v.preventDefault(),m(w=>{let L=(w-1+g.length)%g.length;for(;g[L]?.disabled&&L!==w;)L=(L-1+g.length)%g.length;return L});break;case "Enter":v.preventDefault();let C=g[p];C&&!C.disabled&&(s(C.action),i());break}};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[e,p,g,s,i]),useEffect(()=>{e&&m(0);},[e]);let x=useCallback(()=>{let v=f.length*36+16,C=t.x,w=t.y;return typeof window<"u"&&(C+220>window.innerWidth&&(C=window.innerWidth-220-10),w+v>window.innerHeight&&(w=window.innerHeight-v-10),C<10&&(C=10),w<10&&(w=10)),{position:"fixed",top:w,left:C,minWidth:220,background:"var(--doc-surface)",border:"1px solid var(--doc-border-light)",borderRadius:"8px",boxShadow:"0 2px 10px var(--doc-shadow)",zIndex:ct.contextMenu,padding:"4px 0",overflow:"hidden"}},[t,f.length]),b=h=>{h.disabled||(s(h.action),i());};return e?jsx("div",{ref:a,className:`docx-text-context-menu ${d}`,style:x(),role:"menu","aria-label":l("contextMenu.textMenuAriaLabel"),children:f.map((h,v)=>{let C=g.findIndex(w=>w===h);return jsx(Vr,{item:h,onClick:()=>b(h),isHighlighted:C===p,onMouseEnter:()=>{C>=0&&!h.disabled&&m(C);}},`${h.action}-${v}`)})}):null};function pi(e={}){let{enabled:t=true,isEditable:o=true,containerRef:r,onAction:n}=e,[s,i]=useState(false),[c,d]=useState({x:0,y:0}),[a,p]=useState(false),m=useCallback(()=>{let x=window.getSelection(),b=x&&!x.isCollapsed&&x.toString().length>0;return p(!!b),!!b},[]),l=useCallback(x=>{t&&(x.preventDefault(),x.stopPropagation(),m(),d({x:x.clientX,y:x.clientY}),i(true));},[t,m]),u=useCallback(()=>{i(false);},[]),f=useCallback(x=>{switch(u(),x){case "cut":document.execCommand("cut");break;case "copy":document.execCommand("copy");break;case "paste":document.execCommand("paste");break;case "pasteAsPlainText":navigator.clipboard.readText?.().then(b=>{document.execCommand("insertText",false,b);}).catch(()=>{document.execCommand("paste");});break;case "delete":document.execCommand("delete");break;case "selectAll":document.execCommand("selectAll");break}n?.(x);},[u,n]),g=useCallback(x=>{l(x);},[l]);return useEffect(()=>{if(!s)return;let x=b=>{b.key==="Escape"&&u();};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[s,u]),{isOpen:s,position:c,hasSelection:a,openMenu:l,closeMenu:u,handleAction:f,onContextMenu:g}}function mi(e){return {cut:"Cut",copy:"Copy",paste:"Paste",pasteAsPlainText:"Paste as Plain Text",selectAll:"Select All",delete:"Delete",separator:"",addRowAbove:"Insert row above",addRowBelow:"Insert row below",deleteRow:"Delete row",addColumnLeft:"Insert column left",addColumnRight:"Insert column right",deleteColumn:"Delete column",mergeCells:en$1.table.mergeCells,splitCell:en$1.table.splitCell,addComment:"Comment"}[e]}function fi(e){return {cut:"Ctrl+X",copy:"Ctrl+C",paste:"Ctrl+V",pasteAsPlainText:"Ctrl+Shift+V",selectAll:"Ctrl+A",delete:"Del",separator:"",addRowAbove:"",addRowBelow:"",deleteRow:"",addColumnLeft:"",addColumnRight:"",deleteColumn:"",mergeCells:"",splitCell:"",addComment:""}[e]}function gi(){return io.map(e=>({action:e.action,label:e.labelKey,shortcut:e.shortcutKey,dividerAfter:e.dividerAfter}))}function bi(e,t,o){switch(e){case "cut":case "copy":case "delete":return t;case "paste":case "pasteAsPlainText":return o;case "addComment":return t;case "selectAll":return true;default:return true}}var we=N.Root,Be=N.Group,pt=N.Value;function Te({className:e,children:t,onMouseDown:o,...r}){return jsxs(N.Trigger,{className:P("flex h-8 items-center justify-between gap-1 rounded px-2 py-1","text-sm text-foreground bg-transparent","hover:bg-muted/80 focus:outline-none focus:bg-muted/80","disabled:cursor-not-allowed disabled:opacity-50","transition-colors duration-150","[&>span]:truncate",e),onMouseDown:n=>{n.preventDefault(),o?.(n);},...r,children:[t,jsx(N.Icon,{asChild:true,children:jsx(Gr,{className:"h-4 w-4 text-muted-foreground shrink-0"})})]})}function ke({className:e,children:t,position:o="popper",onCloseAutoFocus:r,...n}){let s=typeof document<"u"&&!!document.querySelector(".ep-root.dark");return jsx(N.Portal,{children:jsx("div",{className:P("ep-root",s&&"dark"),children:jsx(N.Content,{className:P("relative z-50 max-h-72 min-w-[8rem] overflow-hidden","rounded-lg border border-border bg-popover text-popover-foreground shadow-lg","data-[state=open]:animate-in data-[state=closed]:animate-out","data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95","data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2",o==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=top]:-translate-y-1",e),position:o,onCloseAutoFocus:i=>{i.preventDefault(),r?.(i);},...n,children:jsx(N.Viewport,{className:P("p-1",o==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),onMouseDown:i=>i.preventDefault(),children:t})})})})}function $e({className:e,...t}){return jsx(N.Label,{className:P("px-2 py-1.5 text-xs font-medium text-muted-foreground",e),...t})}function ie({className:e,children:t,onMouseDown:o,...r}){return jsxs(N.Item,{className:P("relative flex w-full cursor-pointer select-none items-center","rounded px-2 py-1.5 text-sm text-foreground outline-none","hover:bg-muted focus:bg-muted","data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),onMouseDown:n=>{n.preventDefault(),o?.(n);},...r,children:[jsx(N.ItemText,{children:t}),jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:jsx(N.ItemIndicator,{children:jsx(Ur,{className:"h-4 w-4"})})})]})}function Ge({className:e,...t}){return jsx(N.Separator,{className:P("-mx-1 my-1 h-px bg-muted",e),...t})}function Gr({className:e}){return jsx("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",children:jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})}function Ur({className:e}){return jsx("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",children:jsx("path",{fillRule:"evenodd",d:"M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z",clipRule:"evenodd"})})}function kt(e){let t=e.trim();if(!t)return "";let o=null,r="";for(let n of t){if((n==='"'||n==="'")&&o===null){o=n,r+=n;continue}if(n===o){o=null,r+=n;continue}if(n===","&&o===null)break;r+=n;}return r.trim().replace(/^['"]|['"]$/g,"")}var Zr=[{name:"Arial",fontFamily:"Arial, Helvetica, sans-serif",category:"sans-serif"},{name:"Calibri",fontFamily:'"Calibri", Arial, sans-serif',category:"sans-serif"},{name:"Helvetica",fontFamily:"Helvetica, Arial, sans-serif",category:"sans-serif"},{name:"Verdana",fontFamily:"Verdana, Geneva, sans-serif",category:"sans-serif"},{name:"Open Sans",fontFamily:'"Open Sans", sans-serif',category:"sans-serif"},{name:"Roboto",fontFamily:"Roboto, sans-serif",category:"sans-serif"},{name:"Times New Roman",fontFamily:'"Times New Roman", Times, serif',category:"serif"},{name:"Georgia",fontFamily:"Georgia, serif",category:"serif"},{name:"Cambria",fontFamily:"Cambria, Georgia, serif",category:"serif"},{name:"Garamond",fontFamily:"Garamond, serif",category:"serif"},{name:"Courier New",fontFamily:'"Courier New", Courier, monospace',category:"monospace"},{name:"Consolas",fontFamily:"Consolas, monospace",category:"monospace"}];function so({value:e,onChange:t,fonts:o=Zr,disabled:r=false,className:n,placeholder:s="Arial",width:i=120,showPreview:c=true}){let{t:d}=b$1(),a=j.useMemo(()=>e?o.find(u=>u.fontFamily===e||u.name.toLowerCase()===e.toLowerCase()||kt(u.fontFamily).toLowerCase()===e.toLowerCase())?.name||e:s,[e,o,s]),p=j.useCallback(l=>{let u=o.find(f=>f.name===l);u&&t?.(kt(u.fontFamily)||u.name);},[t,o]),m=j.useMemo(()=>{let l={"sans-serif":[],serif:[],monospace:[],other:[]};return o.forEach(u=>{let f=u.category||"other";l[f].push(u);}),l},[o]);return jsxs(we,{value:a,onValueChange:p,disabled:r,children:[jsx(Te,{className:P("h-8 text-sm",n),style:{minWidth:typeof i=="number"?`${i}px`:i},"aria-label":d("font.selectAriaLabel"),children:jsx(pt,{placeholder:s,children:a})}),jsxs(ke,{className:"max-h-[300px]",children:[m["sans-serif"].length>0&&jsxs(Be,{children:[jsx($e,{children:d("font.sansSerif")}),m["sans-serif"].map(l=>jsx(ie,{value:l.name,style:c?{fontFamily:l.fontFamily}:void 0,children:l.name},l.name))]}),m.serif.length>0&&jsxs(Fragment,{children:[jsx(Ge,{}),jsxs(Be,{children:[jsx($e,{children:d("font.serif")}),m.serif.map(l=>jsx(ie,{value:l.name,style:c?{fontFamily:l.fontFamily}:void 0,children:l.name},l.name))]})]}),m.monospace.length>0&&jsxs(Fragment,{children:[jsx(Ge,{}),jsxs(Be,{children:[jsx($e,{children:d("font.monospace")}),m.monospace.map(l=>jsx(ie,{value:l.name,style:c?{fontFamily:l.fontFamily}:void 0,children:l.name},l.name))]})]}),m.other.length>0&&jsxs(Fragment,{children:[jsx(Ge,{}),jsx(Be,{children:m.other.map(l=>jsx(ie,{value:l.name,style:c?{fontFamily:l.fontFamily}:void 0,children:l.name},l.name))})]})]})]})}var Qr=[{name:"Dark Red",nameKey:"colorPicker.colors.darkRed",hex:"C00000"},{name:"Red",nameKey:"colorPicker.colors.red",hex:"FF0000"},{name:"Orange",nameKey:"colorPicker.colors.orange",hex:"FFC000"},{name:"Yellow",nameKey:"colorPicker.colors.yellow",hex:"FFFF00"},{name:"Light Green",nameKey:"colorPicker.colors.lightGreen",hex:"92D050"},{name:"Green",nameKey:"colorPicker.colors.green",hex:"00B050"},{name:"Light Blue",nameKey:"colorPicker.colors.lightBlue",hex:"00B0F0"},{name:"Blue",nameKey:"colorPicker.colors.blue",hex:"0070C0"},{name:"Dark Blue",nameKey:"colorPicker.colors.darkBlue",hex:"002060"},{name:"Purple",nameKey:"colorPicker.colors.purple",hex:"7030A0"}],mt=18,en=2,tn={position:"relative",display:"inline-block"},on={display:"flex",alignItems:"center",justifyContent:"center",width:"40px",height:"32px",padding:"2px 6px",border:"none",borderRadius:"4px",backgroundColor:"transparent",cursor:"pointer",transition:"background-color 0.1s",color:"var(--doc-text-muted)"},rn={padding:"10px",backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border-dark)",borderRadius:"6px",boxShadow:"0 4px 16px var(--doc-shadow)",width:"auto"},It={fontSize:"11px",color:"var(--doc-text-muted)",marginBottom:"4px",fontWeight:500},Lt={height:"1px",backgroundColor:"var(--doc-border)",margin:"8px 0"},po={display:"grid",gap:`${en}px`},ft={width:`${mt}px`,height:`${mt}px`,border:"1px solid var(--doc-border-input)",borderRadius:"2px",cursor:"pointer",padding:0,transition:"transform 0.1s, border-color 0.1s"},mo={...ft,transform:"scale(1.15)",borderColor:"var(--doc-text)",zIndex:1},fo={...ft,borderWidth:"2px",borderColor:"var(--doc-primary)",boxShadow:"0 0 0 1px var(--doc-primary)"},nn={display:"flex",alignItems:"center",gap:"8px",width:"100%",padding:"5px 8px",border:"1px solid var(--doc-border-dark)",borderRadius:"4px",backgroundColor:"var(--doc-surface)",cursor:"pointer",fontSize:"12px",color:"var(--doc-text)"},an={display:"flex",alignItems:"center",gap:"6px"},ln={width:"70px",height:"24px",padding:"2px 6px",border:"1px solid var(--doc-border-input)",borderRadius:"3px",fontSize:"12px"},sn={height:"24px",padding:"0 10px",border:"1px solid var(--doc-border-input)",borderRadius:"3px",backgroundColor:"var(--doc-bg-subtle)",fontSize:"12px",cursor:"pointer"},co={width:"16px",height:"4px",borderRadius:"1px",marginTop:"-2px"},cn={display:"inline-flex",alignItems:"stretch",height:"32px",gap:"2px"},dn={display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:0,width:"28px",padding:"2px 4px",border:"none",borderRadius:"4px",backgroundColor:"transparent",cursor:"pointer",transition:"background-color 0.1s",color:"var(--doc-text-muted)"},un={display:"flex",alignItems:"center",justifyContent:"center",width:"18px",padding:0,border:"none",borderRadius:"4px",backgroundColor:"transparent",cursor:"pointer",transition:"background-color 0.1s",color:"var(--doc-text-muted)"};function Rt(e,t,o){if(!e)return t==="text"||t==="border"?"#000000":"transparent";if(typeof e=="string"){if(t==="highlight"){let r=resolveHighlightColor(e);return r||(e==="none"?"transparent":e.startsWith("#")?e:`#${e}`)}return e.startsWith("#")?e:`#${e}`}return resolveColor(e,o)}function uo(e){let t=e.replace(/^#/,"");if(t.length!==6)return false;let o=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),n=parseInt(t.slice(4,6),16);return (o*299+r*587+n*114)/1e3>230}function go(e,t,o){return e?(typeof e=="string"?e.replace(/^#/,"").toUpperCase():resolveColorToHex(e,o))===t.toUpperCase():false}function pn({matrix:e,selectedColor:t,theme:o,onSelect:r}){let[n,s]=useState(null);return jsx("div",{style:{...po,gridTemplateColumns:`repeat(10, ${mt}px)`},children:e.flatMap((i,c)=>i.map((d,a)=>{let p=`${c}-${a}`,m=n===p,l=go(t,d.hex,o);return jsx("button",{type:"button",style:{...l?fo:m?mo:ft,backgroundColor:`#${d.hex}`},title:d.label,"aria-label":d.label,"aria-selected":l,onClick:()=>r(d),onMouseDown:u=>u.preventDefault(),onMouseEnter:()=>s(p),onMouseLeave:()=>s(null)},p)}))})}function mn({selectedColor:e,theme:t,onSelect:o}){let[r,n]=useState(null),{t:s}=b$1();return jsx("div",{style:{...po,gridTemplateColumns:`repeat(10, ${mt}px)`},children:Qr.map((i,c)=>{let d=r===c,a=go(e,i.hex,t),p=s(i.nameKey);return jsx("button",{type:"button",style:{...a?fo:d?mo:ft,backgroundColor:`#${i.hex}`},title:p,"aria-label":p,"aria-selected":a,onClick:()=>o(i.hex),onMouseDown:m=>m.preventDefault(),onMouseEnter:()=>n(c),onMouseLeave:()=>n(null)},i.hex)})})}function Fe({mode:e,value:t,onChange:o,theme:r,disabled:n=false,className:s,style:i,title:c$1,icon:d,autoLabel:a,splitButton:p=true,defaultColor:m}){let[l,u]=useState(false),[f,g]=useState(false),[x,b$2]=useState(false),[h,v]=useState(false),[C,w]=useState(""),[L,J]=useState(()=>m??(e==="highlight"?"FFFF00":e==="border"?{rgb:"000000"}:{rgb:"FF0000"})),{t:O}=b$1();useEffect(()=>{let T=Rt(t,e,r).replace(/^#/,"");/^[0-9A-Fa-f]{6}$/.test(T)&&w(T.toUpperCase());},[t,e,r]);let Y=useCallback(()=>u(false),[]),{containerRef:de,dropdownRef:be,dropdownStyle:G}=c({isOpen:l,onClose:Y}),R=r?.colorScheme??null,M=useMemo(()=>generateThemeTintShadeMatrix(R),[R]),_=useMemo(()=>Rt(t,e,r),[t,e,r]),ue=useMemo(()=>Rt(L,e,r),[L,e,r]),he=useCallback(()=>{n||u(T=>!T);},[n]),xe=useCallback(T=>{let V;if(e==="highlight")V=T.hex;else {let ye={themeColor:T.themeSlot,rgb:T.hex};T.tint&&(ye.themeTint=T.tint),T.shade&&(ye.themeShade=T.shade),V=ye;}J(V),o?.(V),u(false);},[e,o]),ve=useCallback(T=>{let V=e==="highlight"?T:{rgb:T};J(V),o?.(V),u(false);},[e,o]),oe=useCallback(()=>{o?.(e==="highlight"?"none":{auto:true}),u(false);},[e,o]),Ae=useCallback(()=>{let T=C.replace(/^#/,"").toUpperCase();if(/^[0-9A-F]{6}$/i.test(T)){let V=e==="highlight"?T:{rgb:T};J(V),o?.(V),u(false),w("");}},[e,C,o]),z=useCallback(()=>{n||o?.(L);},[n,L,o]),Xe={...on,...n?{cursor:"default",opacity:.38}:l?{backgroundColor:"var(--doc-primary-light)",color:"var(--doc-primary)"}:f?{backgroundColor:"var(--doc-bg-hover)"}:{}},re=O(e==="text"?"formattingBar.fontColor":e==="highlight"?"formattingBar.highlightColor":"table.borderColor"),We=d??(e==="text"?"format_color_text":e==="highlight"?"ink_highlighter":"border_color");return jsxs("div",{ref:de,className:`docx-color-picker ${s||""}`,style:{...tn,...i},children:[p?jsxs("div",{className:"docx-color-picker-split",style:{...cn,...n?{opacity:.38,cursor:"default"}:null},children:[jsxs("button",{type:"button",className:"docx-color-picker-apply",style:{...dn,...n?{cursor:"default"}:x?{backgroundColor:"var(--doc-bg-hover)"}:null},onClick:z,onMouseDown:T=>T.preventDefault(),onMouseEnter:()=>b$2(true),onMouseLeave:()=>b$2(false),disabled:n,title:c$1||re,"aria-label":c$1||re,children:[jsx(b,{name:We,size:18}),jsx("div",{style:{...co,backgroundColor:ue==="transparent"?"#fff":ue,outline:ue==="transparent"||uo(ue)?"1px solid #bbb":"none"}})]}),jsx("button",{type:"button",className:"docx-color-picker-arrow",style:{...un,...n?{cursor:"default"}:l?{backgroundColor:"var(--doc-primary-light)",color:"var(--doc-primary)"}:h?{backgroundColor:"var(--doc-bg-hover)"}:null},onClick:he,onMouseDown:T=>T.preventDefault(),onMouseEnter:()=>v(true),onMouseLeave:()=>v(false),disabled:n,title:c$1||re,"aria-label":c$1||re,"aria-haspopup":"true","aria-expanded":l,children:jsx(b,{name:"arrow_drop_down",size:18})})]}):jsxs("button",{type:"button",className:"docx-color-picker-button",style:Xe,onClick:he,onMouseDown:T=>T.preventDefault(),onMouseEnter:()=>g(true),onMouseLeave:()=>g(false),disabled:n,title:c$1||re,"aria-label":c$1||re,"aria-haspopup":"true","aria-expanded":l,children:[jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:0},children:[jsx(b,{name:We,size:18}),jsx("div",{style:{...co,backgroundColor:_==="transparent"?"#fff":_,outline:_==="transparent"||uo(_)?"1px solid #bbb":"none"}})]}),jsx(b,{name:"arrow_drop_down",size:14})]}),l&&jsx("div",{ref:be,className:"docx-color-picker-dropdown",style:{...G,...rn},role:"dialog","aria-label":`${re} picker`,onMouseDown:T=>{T.target.tagName!=="INPUT"&&T.preventDefault();},children:jsxs(Fragment,{children:[jsxs("button",{type:"button",style:nn,onClick:oe,onMouseDown:T=>T.preventDefault(),children:[e==="highlight"?jsx("span",{style:{display:"inline-block",width:"16px",height:"16px",border:"1px solid #ccc",borderRadius:"2px",position:"relative",backgroundColor:"#fff"},children:jsx("span",{style:{position:"absolute",top:"50%",left:"-1px",right:"-1px",height:"2px",backgroundColor:"#ff0000",transform:"rotate(-45deg)"}})}):jsx("span",{style:{display:"inline-block",width:"16px",height:"16px",backgroundColor:"#000",borderRadius:"2px"}}),a??O(e==="highlight"?"colorPicker.noColor":"colorPicker.automatic")]}),jsx("div",{style:Lt}),jsx("div",{style:It,children:O("colorPicker.themeColors")}),jsx(pn,{matrix:M,selectedColor:t,theme:r,onSelect:xe}),jsx("div",{style:Lt}),jsx("div",{style:It,children:O("colorPicker.standardColors")}),jsx(mn,{selectedColor:t,theme:r,onSelect:ve}),jsx("div",{style:Lt}),jsx("div",{style:It,children:O("colorPicker.customColor")}),jsxs("div",{style:an,children:[jsx("span",{style:{fontSize:"12px",color:"var(--doc-text-muted)"},children:"#"}),jsx("input",{type:"text",style:ln,value:C,onChange:T=>w(T.target.value.replace(/[^0-9A-Fa-f]/g,"").slice(0,6)),onKeyDown:T=>{T.key==="Enter"&&Ae();},onMouseDown:T=>{T.stopPropagation();},placeholder:"FF0000",maxLength:6,"aria-label":"Custom hex color"}),jsx("button",{type:"button",style:{...sn,opacity:/^[0-9A-Fa-f]{6}$/.test(C)?1:.4,cursor:/^[0-9A-Fa-f]{6}$/.test(C)?"pointer":"default"},onClick:Ae,onMouseDown:T=>T.preventDefault(),disabled:!/^[0-9A-Fa-f]{6}$/.test(C),children:O("common.apply")})]})]})})]})}function ee({content:e,children:t,side:o="bottom",delayMs:r=400}){let[n,s]=j.useState(false),[i,c]=j.useState({x:0,y:0}),d=j.useRef(null),a=j.useRef(null),p=j.useCallback(()=>{a.current=setTimeout(()=>{if(d.current){let f=d.current.getBoundingClientRect(),g=f.left+f.width/2,x=o==="top"?f.top-8:f.bottom+8;c({x:g,y:x});}s(true);},r);},[r,o]),m=j.useCallback(()=>{a.current&&(clearTimeout(a.current),a.current=null),s(false);},[]);j.useEffect(()=>()=>{a.current&&clearTimeout(a.current);},[]);let l=t.props,u=j.cloneElement(t,{ref:d,onMouseEnter:f=>{p(),l.onMouseEnter?.(f);},onMouseLeave:f=>{m(),l.onMouseLeave?.(f);}});return jsxs(Fragment,{children:[u,n&&jsx("div",{className:"fixed z-50 px-2 py-1 text-xs font-medium text-white bg-foreground dark:bg-muted dark:text-foreground rounded-md shadow-lg",style:{left:i.x,top:i.y,transform:o==="top"?"translate(-50%, -100%)":o==="bottom"?"translate(-50%, 0)":void 0},children:e})]})}var Qe=20,Et=[{value:"left",label:"Align Left",labelKey:"alignment.alignLeft",shortcutKey:"alignment.alignLeftShortcut",icon:jsx(b,{name:"format_align_left",size:Qe}),iconName:"format_align_left",shortcut:"Ctrl+L"},{value:"center",label:"Center",labelKey:"alignment.center",shortcutKey:"alignment.centerShortcut",icon:jsx(b,{name:"format_align_center",size:Qe}),iconName:"format_align_center",shortcut:"Ctrl+E"},{value:"right",label:"Align Right",labelKey:"alignment.alignRight",shortcutKey:"alignment.alignRightShortcut",icon:jsx(b,{name:"format_align_right",size:Qe}),iconName:"format_align_right",shortcut:"Ctrl+R"},{value:"both",label:"Justify",labelKey:"alignment.justify",shortcutKey:"alignment.justifyShortcut",icon:jsx(b,{name:"format_align_justify",size:Qe}),iconName:"format_align_justify",shortcut:"Ctrl+J"}];function xo({value:e="left",onChange:t,disabled:o=false}){let{t:r}=b$1(),[n,s]=useState(false),i=useCallback(()=>s(false),[]),{containerRef:c$1,dropdownRef:d,dropdownStyle:a,handleMouseDown:p}=c({isOpen:n,onClose:i}),m=useCallback(b=>{o||t?.(b),s(false);},[o,t]),l=Et.find(b=>b.value===e)||Et[0],u=r(l.labelKey),f=l.shortcutKey?r(l.shortcutKey):void 0,g=`${u}${f?` (${f})`:""}`,x=jsxs(K,{variant:"ghost",size:"icon-sm",className:P("text-muted-foreground hover:text-foreground hover:bg-muted/80",n&&"bg-muted",o&&"opacity-30 cursor-not-allowed"),onMouseDown:p,onClick:()=>!o&&s(b=>!b),disabled:o,"aria-label":g,"aria-expanded":n,"aria-haspopup":"true","data-testid":"toolbar-alignment",children:[jsx(b,{name:l.iconName,size:Qe}),jsx(b,{name:"arrow_drop_down",size:14,className:"-ml-1"})]});return jsxs("div",{ref:c$1,style:{position:"relative",display:"inline-block"},children:[n?x:jsx(ee,{content:g,children:x}),n&&!o&&jsx("div",{ref:d,style:{...a,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:8,boxShadow:"0 4px 16px var(--doc-shadow)",padding:6},onMouseDown:b=>b.stopPropagation(),children:jsx("div",{style:{display:"flex",gap:2},children:Et.map(b$1=>{let h=e===b$1.value,v=r(b$1.labelKey),C=b$1.shortcutKey?r(b$1.shortcutKey):void 0;return jsx("button",{type:"button",title:`${v}${C?` (${C})`:""}`,"data-testid":`alignment-${b$1.value}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,border:"1px solid transparent",borderRadius:4,backgroundColor:h?"var(--doc-primary-light)":"transparent",cursor:"pointer",color:h?"var(--doc-primary)":"var(--doc-text)"},onMouseDown:w=>w.preventDefault(),onMouseEnter:w=>{h||(w.currentTarget.style.backgroundColor="var(--doc-bg-hover)");},onMouseLeave:w=>{w.currentTarget.style.backgroundColor=h?"var(--doc-primary-light)":"transparent";},onClick:()=>m(b$1.value),children:jsx(b,{name:b$1.iconName,size:18})},b$1.value)})})})]})}var vn=[{label:"Single",labelKey:"lineSpacing.single",value:1,twipsValue:240},{label:"1.15",value:1.15,twipsValue:276},{label:"1.5",value:1.5,twipsValue:360},{label:"Double",labelKey:"lineSpacing.double",value:2,twipsValue:480}];function yo({value:e,onChange:t,options:o=vn,disabled:r=false,className:n}){let{t:s}=b$1(),i=j.useMemo(()=>e===void 0?o[0]:o.find(a=>a.twipsValue===e)||o[0],[e,o]),c=j.useCallback(a=>{let p=parseInt(a,10);isNaN(p)||t?.(p);},[t]),d=a=>a.labelKey?s(a.labelKey):a.label;return jsxs(we,{value:i.twipsValue.toString(),onValueChange:c,disabled:r,children:[jsx(Te,{className:P("h-8 text-sm gap-0.5 px-2",n),style:{width:"auto"},title:s("lineSpacing.lineSpacingTitle",{label:d(i)}),children:jsx(a,{className:"h-5 w-5 shrink-0"})}),jsxs(ke,{children:[o.map(a=>jsx(ie,{value:a.twipsValue.toString(),children:d(a)},a.twipsValue)),jsx(Ge,{}),jsx(Be,{children:jsx($e,{children:s("lineSpacing.paragraphSpacing")})})]})]})}var Co=[{styleId:"Normal",name:"Normal text",nameKey:"styles.normalText",type:"paragraph",isDefault:true,priority:0,qFormat:true,fontSize:22},{styleId:"Title",name:"Title",nameKey:"styles.title",type:"paragraph",priority:1,qFormat:true,fontSize:52,bold:true},{styleId:"Subtitle",name:"Subtitle",nameKey:"styles.subtitle",type:"paragraph",priority:2,qFormat:true,fontSize:30,color:"666666"},{styleId:"Heading1",name:"Heading 1",nameKey:"styles.heading1",type:"paragraph",priority:3,qFormat:true,fontSize:40,bold:true},{styleId:"Heading2",name:"Heading 2",nameKey:"styles.heading2",type:"paragraph",priority:4,qFormat:true,fontSize:32,bold:true},{styleId:"Heading3",name:"Heading 3",nameKey:"styles.heading3",type:"paragraph",priority:5,qFormat:true,fontSize:28,bold:true}];function So({value:e,onChange:t,styles:o,disabled:r=false,className:n,width:s=120}){let{t:i}=b$1(),c=j.useMemo(()=>{let u=resolveParagraphStyleOptions(o);return u.length===0?Co:u.map(f=>({...f,type:"paragraph",nameKey:Co.find(g=>g.styleId===f.styleId)?.nameKey}))},[o]),d=j.useCallback(u=>{t?.(u);},[t]),a=u=>u.nameKey?i(u.nameKey):u.name,p=e||"Normal",m=c.find(u=>u.styleId===p),l=m?a(m):p;return jsxs(we,{value:p,onValueChange:d,disabled:r,children:[jsx(Te,{className:P("h-8 text-sm",n),style:{width:typeof s=="number"?`${s}px`:s},"aria-label":i("styles.selectAriaLabel"),children:jsx("span",{className:"truncate",children:l})}),jsx(ke,{className:"min-w-[260px] max-h-[400px]",children:c.map(u=>jsx(ie,{value:u.styleId,className:"py-2.5 px-3",children:jsx("span",{style:getStylePreviewProps(u),children:a(u)})},u.styleId))})]})}var wn=[{value:.5,label:"50%"},{value:.75,label:"75%"},{value:1,label:"100%"},{value:1.25,label:"125%"},{value:1.5,label:"150%"},{value:2,label:"200%"}];function To({value:e=1,onChange:t,levels:o=wn,disabled:r=false,className:n,compact:s=false}){let{t:i}=b$1(),c=j.useMemo(()=>{let u=o.find(f=>Math.abs(f.value-e)<.001);return u?u.label:`${Math.round(e*100)}%`},[o,e]),d=j.useCallback(u=>{let f=parseFloat(u);isNaN(f)||t?.(f);},[t]),a=j.useMemo(()=>[...o].sort((u,f)=>u.value-f.value),[o]),p=j.useMemo(()=>[...a].reverse().find(u=>u.value<e-.001),[a,e]),m=j.useMemo(()=>a.find(u=>u.value>e+.001),[a,e]),l=s?"h-7 w-7":"h-8 w-8";return jsxs("div",{className:"flex items-center",children:[jsx(K,{variant:"ghost",size:"icon-sm",className:P(l,"text-muted-foreground hover:text-foreground hover:bg-muted/80 rounded-r-none",(r||!p)&&"opacity-30 cursor-not-allowed"),onClick:()=>p&&t?.(p.value),disabled:r||!p,"aria-label":i("zoom.zoomOut"),children:jsx(b,{name:"remove",size:18})}),jsxs(we,{value:e.toString(),onValueChange:d,disabled:r,children:[jsx(Te,{className:P(s?"h-7 min-w-[55px] text-xs":"h-8 min-w-[64px] text-sm","rounded-none",n),"aria-label":i("zoom.ariaLabel",{label:c}),children:jsx(pt,{placeholder:"100%",children:c})}),jsx(ke,{children:o.map(u=>jsx(ie,{value:u.value.toString(),children:u.label},u.value))})]}),jsx(K,{variant:"ghost",size:"icon-sm",className:P(l,"text-muted-foreground hover:text-foreground hover:bg-muted/80 rounded-l-none",(r||!m)&&"opacity-30 cursor-not-allowed"),onClick:()=>m&&t?.(m.value),disabled:r||!m,"aria-label":i("zoom.zoomIn"),children:jsx(b,{name:"add",size:18})})]})}var kn=[{action:"borderAll",icon:"border_all",labelKey:"table.borders.all"},{action:"borderOutside",icon:"border_outer",labelKey:"table.borders.outside"},{action:"borderInside",icon:"border_inner",labelKey:"table.borders.inside"},{action:"borderTop",icon:"border_top",labelKey:"table.borders.top"},{action:"borderBottom",icon:"border_bottom",labelKey:"table.borders.bottom"},{action:"borderLeft",icon:"border_left",labelKey:"table.borders.left"},{action:"borderRight",icon:"border_right",labelKey:"table.borders.right"},{action:"borderNone",icon:"border_clear",labelKey:"table.borders.none"}];function Mo({onAction:e,disabled:t=false}){let{t:o}=b$1(),[r,n]=useState(false),s=useCallback(()=>n(false),[]),{containerRef:i,dropdownRef:c$1,dropdownStyle:d,handleMouseDown:a}=c({isOpen:r,onClose:s}),p=useCallback(l=>{e(l),n(false);},[e]),m=jsxs(K,{variant:"ghost",size:"icon-sm",className:P("text-muted-foreground hover:text-foreground hover:bg-muted/80",r&&"bg-muted",t&&"opacity-30 cursor-not-allowed"),onMouseDown:a,onClick:()=>!t&&n(l=>!l),disabled:t,"aria-label":o("table.borders.styleAriaLabel"),"aria-expanded":r,"aria-haspopup":"true","data-testid":"toolbar-table-borders",children:[jsx(b,{name:"border_all",size:20}),jsx(b,{name:"arrow_drop_down",size:14,className:"-ml-1"})]});return jsxs("div",{ref:i,style:{position:"relative",display:"inline-block"},children:[r?m:jsx(ee,{content:o("table.borders.tooltip"),children:m}),r&&!t&&jsx("div",{ref:c$1,style:{...d,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:8,boxShadow:"0 4px 16px var(--doc-shadow)",padding:6},onMouseDown:l=>l.stopPropagation(),children:jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:2},children:kn.map(({action:l,icon:u,labelKey:f})=>jsx("button",{type:"button",title:o(f),style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,border:"1px solid transparent",borderRadius:4,backgroundColor:"transparent",cursor:"pointer",color:"var(--doc-text)"},onMouseDown:g=>g.preventDefault(),onMouseEnter:g=>{g.currentTarget.style.backgroundColor="var(--doc-bg-hover)";},onMouseLeave:g=>{g.currentTarget.style.backgroundColor="transparent";},onClick:()=>p(l),children:jsx(b,{name:u,size:18})},typeof l=="string"?l:l.type))})})]})}function Io({onAction:e,disabled:t=false,theme:o,value:r}){let{t:n}=b$1(),s=useCallback(i=>{typeof i=="string"?e({type:"borderColor",color:i.replace(/^#/,"")}):i.rgb?e({type:"borderColor",color:i.rgb.replace(/^#/,"")}):i.auto&&e({type:"borderColor",color:"000000"});},[e]);return jsx(Fe,{mode:"border",value:r,onChange:s,theme:o,disabled:t,title:n("table.borderColor")})}var Ln=[{size:4,label:"0.5 pt",thickness:.5},{size:8,label:"1 pt",thickness:1},{size:12,label:"1.5 pt",thickness:1.5},{size:16,label:"2 pt",thickness:2},{size:24,label:"3 pt",thickness:3}];function Ro({onAction:e,disabled:t=false}){let[o,r]=useState(false),{t:n}=b$1(),s=useCallback(()=>r(false),[]),{containerRef:i,dropdownRef:c$1,dropdownStyle:d,handleMouseDown:a}=c({isOpen:o,onClose:s}),p=useCallback(l=>{e({type:"borderWidth",size:l}),r(false);},[e]),m=jsxs(K,{variant:"ghost",size:"icon-sm",className:P("text-muted-foreground hover:text-foreground hover:bg-muted/80",o&&"bg-muted",t&&"opacity-30 cursor-not-allowed"),onMouseDown:a,onClick:()=>!t&&r(l=>!l),disabled:t,"aria-label":n("table.borderWidth"),"aria-expanded":o,"aria-haspopup":"true","data-testid":"toolbar-table-border-width",children:[jsx(b,{name:"line_weight",size:20}),jsx(b,{name:"arrow_drop_down",size:14,className:"-ml-1"})]});return jsxs("div",{ref:i,style:{position:"relative",display:"inline-block"},children:[o?m:jsx(ee,{content:n("table.borderWidth"),children:m}),o&&!t&&jsx("div",{ref:c$1,style:{...d,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:8,boxShadow:"0 4px 16px var(--doc-shadow)",padding:"4px 0",minWidth:120},onMouseDown:l=>l.stopPropagation(),children:Ln.map(({size:l,label:u,thickness:f})=>jsxs("button",{type:"button",style:{display:"flex",alignItems:"center",gap:10,padding:"6px 12px",width:"100%",border:"none",backgroundColor:"transparent",cursor:"pointer",fontSize:12,color:"var(--doc-text)"},onMouseDown:g=>g.preventDefault(),onMouseEnter:g=>{g.currentTarget.style.backgroundColor="var(--doc-bg-hover)";},onMouseLeave:g=>{g.currentTarget.style.backgroundColor="transparent";},onClick:()=>p(l),children:[jsx("div",{style:{width:50,height:Math.max(f,1),backgroundColor:"#000",borderRadius:f>2?1:0}}),jsx("span",{children:u})]},l))})]})}function Eo({onAction:e,disabled:t=false,theme:o,value:r}){let{t:n}=b$1(),s=useCallback(i=>{typeof i=="string"&&e(i==="none"?{type:"cellFillColor",color:null}:{type:"cellFillColor",color:i.replace(/^#/,"")});},[e]);return jsx(Fe,{mode:"highlight",value:r,onChange:s,theme:o,disabled:t,title:n("table.cellFillColor"),icon:"format_color_fill",autoLabel:n("colorPicker.noColor")})}var An={display:"flex",alignItems:"center",gap:10,padding:"7px 14px",fontSize:13,color:"var(--doc-text)",cursor:"pointer",border:"none",backgroundColor:"transparent",width:"100%",textAlign:"left"},qe={height:1,backgroundColor:"var(--doc-border)",margin:"4px 0"},Do={padding:"6px 14px 2px",fontSize:11,color:"var(--doc-text-muted)",fontWeight:500};function Bo({onAction:e,disabled:t=false,tableContext:o}){let{t:r}=b$1(),[n,s]=useState(false),[i,c$1]=useState(null),d=useCallback(()=>s(false),[]),{containerRef:a,dropdownRef:p,dropdownStyle:m,handleMouseDown:l}=c({isOpen:n,onClose:d,align:"right"}),u=o?.table?.attrs?.justification??"left",f=useCallback(b=>{e(b),s(false);},[e]),g=(b$1,h,v,C,w)=>{let L=t||w?.itemDisabled;return jsxs("button",{type:"button",role:"menuitem",style:{...An,backgroundColor:i===b$1&&!L?"var(--doc-bg-hover)":"transparent",color:L?"var(--doc-text-muted)":w?.danger?"var(--doc-error)":"var(--doc-text)",cursor:L?"not-allowed":"pointer"},onClick:()=>!L&&f(C),onMouseEnter:()=>c$1(b$1),onMouseLeave:()=>c$1(null),disabled:L,children:[jsx(b,{name:h,size:16,className:w?.danger&&!L?"text-destructive":""}),jsx("span",{style:{flex:1},children:v})]},b$1)},x=jsx(K,{variant:"ghost",size:"icon-sm",className:P("text-muted-foreground hover:text-foreground hover:bg-muted/80",n&&"bg-muted",t&&"opacity-30 cursor-not-allowed"),onMouseDown:l,onClick:()=>!t&&s(b=>!b),disabled:t,"aria-label":r("table.moreOptions"),"aria-expanded":n,"aria-haspopup":"menu","data-testid":"toolbar-table-more",children:jsx(b,{name:"more_vert",size:20})});return jsxs("div",{ref:a,style:{position:"relative",display:"inline-block"},children:[n?x:jsx(ee,{content:r("table.moreOptions"),children:x}),n&&!t&&jsxs("div",{ref:p,style:{...m,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:8,boxShadow:"0 4px 16px var(--doc-shadow)",padding:"4px 0",minWidth:200,maxHeight:"70vh",overflowY:"auto"},role:"menu",onMouseDown:b=>b.stopPropagation(),children:[g("addRowAbove","add",r("table.insertRowAbove"),"addRowAbove"),g("addRowBelow","add",r("table.insertRowBelow"),"addRowBelow"),g("addColumnLeft","add",r("table.insertColumnLeft"),"addColumnLeft"),g("addColumnRight","add",r("table.insertColumnRight"),"addColumnRight"),jsx("div",{style:qe,role:"separator"}),g("mergeCells","call_merge",r("table.mergeCells"),"mergeCells",{itemDisabled:!o?.hasMultiCellSelection}),g("splitCell","call_split",r("table.splitCell"),"splitCell",{itemDisabled:!o?.canSplitCell}),jsx("div",{style:qe,role:"separator"}),g("deleteRow","delete",r("table.deleteRow"),"deleteRow",{danger:true,itemDisabled:(o?.rowCount??0)<=1}),g("deleteColumn","delete",r("table.deleteColumn"),"deleteColumn",{danger:true,itemDisabled:(o?.columnCount??0)<=1}),g("deleteTable","delete",r("table.deleteTable"),"deleteTable",{danger:true}),jsx("div",{style:qe,role:"separator"}),jsx("div",{style:Do,children:r("tableAdvanced.verticalAlignment")}),jsx("div",{style:{display:"flex",gap:4,padding:"4px 14px"},children:["top","center","bottom"].map(b$1=>{let h={top:"vertical_align_top",center:"vertical_align_center",bottom:"vertical_align_bottom"};return jsx("button",{type:"button",title:r({top:"tableAdvanced.top",center:"tableAdvanced.middle",bottom:"tableAdvanced.bottom"}[b$1]),style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,border:"1px solid var(--doc-border)",borderRadius:4,backgroundColor:"transparent",cursor:"pointer"},onMouseDown:C=>C.preventDefault(),onMouseEnter:C=>{C.currentTarget.style.backgroundColor="var(--doc-bg-hover)";},onMouseLeave:C=>{C.currentTarget.style.backgroundColor="transparent";},onClick:()=>f({type:"cellVerticalAlign",align:b$1}),children:jsx(b,{name:h[b$1],size:16})},b$1)})}),jsx("div",{style:qe,role:"separator"}),jsx("div",{style:Do,children:r("tableAdvanced.tableAlignment")}),jsx("div",{style:{display:"flex",gap:4,padding:"4px 14px"},children:["left","center","right"].map(b$1=>{let h={left:"format_align_left",center:"format_align_center",right:"format_align_right"},v=u===b$1;return jsx("button",{type:"button",title:r({left:"tableAdvanced.alignTableLeft",center:"tableAdvanced.alignTableCenter",right:"tableAdvanced.alignTableRight"}[b$1]),style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,border:"1px solid var(--doc-border)",borderRadius:4,backgroundColor:v?"var(--doc-primary-light)":"transparent",borderColor:v?"var(--doc-primary)":"var(--doc-border)",color:v?"var(--doc-primary)":"var(--doc-text)",cursor:"pointer"},onMouseDown:C=>C.preventDefault(),onClick:()=>f({type:"tableProperties",props:{justification:b$1}}),children:jsx(b,{name:h[b$1],size:16})},b$1)})}),jsx("div",{style:qe,role:"separator"}),g("headerRow","table_rows",r("tableAdvanced.toggleHeaderRow"),{type:"toggleHeaderRow"}),g("distribute","view_column",r("tableAdvanced.distributeColumns"),{type:"distributeColumns"}),g("autoFit","fit_width",r("tableAdvanced.autoFit"),{type:"autoFitContents"}),g("noWrap","wrap_text",r("tableAdvanced.toggleNoWrap"),{type:"toggleNoWrap"}),jsx("div",{style:qe,role:"separator"}),g("properties","settings",r("tableAdvanced.tableProperties"),{type:"openTableProperties"})]})]})}var Dn=20;function ht({options:e,activeValue:t,triggerIcon:o,tooltipContent:r,onSelect:n,disabled:s=false,ariaLabel:i,testId:c$1,showLabels:d=false}){let[a,p]=useState(false),m=useCallback(()=>p(false),[]),{containerRef:l,dropdownRef:u,dropdownStyle:f,handleMouseDown:g}=c({isOpen:a,onClose:m}),x=useCallback(h=>{s||n(h),p(false);},[s,n]),b$1=jsxs(K,{variant:"ghost",size:"icon-sm",className:P("text-muted-foreground hover:text-foreground hover:bg-muted/80",a&&"bg-muted",s&&"opacity-30 cursor-not-allowed"),onMouseDown:g,onClick:()=>!s&&p(h=>!h),disabled:s,"aria-label":i??r,"aria-expanded":a,"aria-haspopup":"true","data-testid":c$1,children:[jsx(b,{name:o,size:Dn}),jsx(b,{name:"arrow_drop_down",size:14,className:"-ml-1"})]});return jsxs("div",{ref:l,style:{position:"relative",display:"inline-block"},children:[a?b$1:jsx(ee,{content:r,children:b$1}),a&&!s&&jsx("div",{ref:u,style:{...f,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:8,boxShadow:"0 4px 16px var(--doc-shadow)",padding:6},onMouseDown:h=>h.stopPropagation(),children:jsx("div",{style:{display:"flex",flexDirection:d?"column":"row",gap:d?1:2,minWidth:d?200:void 0},children:e.map(h=>{let v=t===h.value;return jsxs("button",{type:"button",title:h.label,"data-testid":c$1?`${c$1}-${h.value}`:void 0,style:{display:"flex",alignItems:"center",height:32,border:"1px solid transparent",borderRadius:4,backgroundColor:v?"var(--doc-primary-light)":"transparent",cursor:"pointer",color:v?"var(--doc-primary)":"var(--doc-text)",...d?{width:"100%",gap:10,padding:"0 10px",justifyContent:"flex-start",fontSize:13,textAlign:"left"}:{width:32,justifyContent:"center"}},onMouseDown:C=>C.preventDefault(),onMouseEnter:C=>{v||(C.currentTarget.style.backgroundColor="var(--doc-bg-hover)");},onMouseLeave:C=>{C.currentTarget.style.backgroundColor=v?"var(--doc-primary-light)":"transparent";},onClick:()=>x(h.value),children:[jsx(b,{name:h.iconName,size:18}),d&&jsx("span",{style:{flex:1},children:h.label})]},h.value)})})})]})}var Bn=[{value:"inline",labelKey:"imageWrap.inline",iconName:"wrap_text"},{value:"wrapRight",labelKey:"imageWrap.floatLeft",iconName:"format_image_left"},{value:"wrapLeft",labelKey:"imageWrap.floatRight",iconName:"format_image_right"},{value:"behind",labelKey:"imageWrap.behindText",iconName:"flip_to_back"},{value:"inFront",labelKey:"imageWrap.inFrontOfText",iconName:"flip_to_front"}];function _n(e){return e.displayMode==="float"&&e.cssFloat==="left"?"wrapRight":e.displayMode==="float"&&e.cssFloat==="right"?"wrapLeft":e.wrapType}function Oo({imageContext:e,onChange:t,disabled:o=false}){let{t:r}=b$1(),n=Bn.map(c=>({...c,label:r(c.labelKey)})),s=_n(e),i=n.find(c=>c.value===s)||n[0];return jsx(ht,{options:n,activeValue:s,triggerIcon:i.iconName,tooltipContent:`Wrap: ${i.label}`,onSelect:t,disabled:o,testId:"toolbar-image-wrap",showLabels:true})}var On=[{value:"rotateCW",labelKey:"imageTransform.rotateClockwise",iconName:"rotate_right"},{value:"rotateCCW",labelKey:"imageTransform.rotateCounterClockwise",iconName:"rotate_left"},{value:"flipH",labelKey:"imageTransform.flipHorizontal",iconName:"swap_horiz"},{value:"flipV",labelKey:"imageTransform.flipVertical",iconName:"swap_vert"}];function zo({onTransform:e,disabled:t=false}){let{t:o}=b$1(),r=On.map(n=>({...n,label:o(n.labelKey)}));return jsx(ht,{options:r,triggerIcon:"rotate_right",tooltipContent:o("imageTransform.tooltip"),onSelect:e,disabled:t,testId:"toolbar-image-transform"})}var tt=createContext(null);function Ko(){let e=useContext(tt);if(!e)throw new Error("useEditorToolbar must be used within an <EditorToolbar> component");return e}var se=18;function ce({active:e=false,disabled:t=false,title:o,onClick:r,children:n,className:s,ariaLabel:i}){let c=i?.toLowerCase().replace(/\s+/g,"-")||o?.toLowerCase().replace(/\s+/g,"-").replace(/\([^)]*\)/g,"").trim(),d=p=>{p.preventDefault();},a=jsx(K,{variant:"ghost",size:"icon-sm",className:P("text-muted-foreground hover:text-foreground hover:bg-muted",e&&"bg-foreground text-white hover:bg-foreground hover:text-white",e&&"dark:bg-doc-primary-light dark:text-doc-primary dark:hover:bg-doc-primary-light dark:hover:text-doc-primary",t&&"opacity-30 cursor-not-allowed",s),onMouseDown:d,onClick:t?void 0:r,disabled:t,"aria-pressed":e,"aria-label":i||o,"data-testid":c?`toolbar-${c}`:void 0,children:n});return o?jsx(ee,{content:o,children:a}):a}function fe({label:e,children:t,className:o}){return jsx("div",{className:P("flex items-center gap-px px-1.5 border-r border-border/50 last:border-r-0 first:pl-0",o),role:"group","aria-label":e,children:t})}function qs(){return jsx("div",{className:"w-px h-6 bg-border mx-1.5",role:"separator"})}function Gn(e){let t=j__default.useContext(tt);return t?{...t,...Un(e)}:e}function Un(e){let t={};for(let o of Object.keys(e))e[o]!==void 0&&(t[o]=e[o]);return t}function Wo(e){let{t}=b$1(),o=Gn(e),{currentFormatting:r={},onFormat:n,onUndo:s,onRedo:i,canUndo:c=false,canRedo:d=false,disabled:a=false,className:p,style:m,enableShortcuts:l=true,editorRef:u,children:f,showFontPicker:g=true,fontFamilies:x,showFontSizePicker:b$2=true,showTextColorPicker:h=true,showHighlightColorPicker:v=true,showAlignmentButtons:C=true,showListButtons:w=true,showLineSpacingPicker:L=true,showStylePicker:J=true,documentStyles:O,theme:Y,showZoomControl:de=true,zoom:be,onZoomChange:G,onRefocusEditor:R,imageContext:M,onImageWrapType:_,onImageTransform:ue,onOpenImageProperties:he,tableContext:xe,onTableAction:ve,inline:oe=false}=o,Ae=useRef(null),z=useCallback(A=>{!a&&n&&n(A);},[a,n]),Xe=useCallback(()=>{!a&&c&&s&&s();},[a,c,s]),re=useCallback(()=>{!a&&d&&i&&i();},[a,d,i]),We=useCallback(A=>{!a&&n&&(n({type:"fontFamily",value:A}),requestAnimationFrame(()=>R?.()));},[a,n,R]),T=j__default.useMemo(()=>normalizeFontFamilies(x),[x]),V=useCallback(A=>{!a&&n&&(n({type:"fontSize",value:A}),requestAnimationFrame(()=>R?.()));},[a,n,R]),ye=useCallback(A=>{!a&&n&&(n({type:"textColor",value:A}),requestAnimationFrame(()=>R?.()));},[a,n,R]),wt=useCallback(A=>{!a&&n&&(n({type:"highlightColor",value:typeof A=="string"?A:""}),requestAnimationFrame(()=>R?.()));},[a,n,R]),E=useCallback(A=>{!a&&n&&n({type:"alignment",value:A});},[a,n]),Ne=useCallback(()=>{!a&&n&&n("bulletList");},[a,n]),nt=useCallback(()=>{!a&&n&&n("numberedList");},[a,n]),De=useCallback(()=>{!a&&n&&n("indent");},[a,n]),pe=useCallback(()=>{!a&&n&&n("outdent");},[a,n]),Q=useCallback(A=>{!a&&n&&(n({type:"lineSpacing",value:A}),requestAnimationFrame(()=>R?.()));},[a,n,R]),ne=useCallback(A=>{!a&&n&&(n({type:"applyStyle",value:A}),requestAnimationFrame(()=>R?.()));},[a,n,R]),ae=useCallback(A=>{!a&&ve&&(ve(A),requestAnimationFrame(()=>R?.()));},[a,ve,R]);useEffect(()=>{if(!l)return;let A=B=>{let je=B.target,Ut=u?.current,ar=Ae.current,ir=Ut?.contains(je),lr=ar?.contains(je);if(!ir&&!lr)return;if((B.ctrlKey||B.metaKey)&&!B.altKey)switch(B.key.toLowerCase()){case "b":B.preventDefault(),z("bold");break;case "i":B.preventDefault(),z("italic");break;case "u":B.preventDefault(),z("underline");break;case "=":B.shiftKey?(B.preventDefault(),z("superscript")):(B.preventDefault(),z("subscript"));break;case "l":B.preventDefault(),E("left");break;case "e":B.preventDefault(),E("center");break;case "r":B.preventDefault(),E("right");break;case "j":B.preventDefault(),E("both");break;case "k":B.preventDefault(),z("insertLink");break}};return document.addEventListener("keydown",A),()=>{document.removeEventListener("keydown",A);}},[l,z,E,u]);let rr=useCallback(A=>{let B=A.target;B.tagName==="INPUT"||B.tagName==="TEXTAREA"||B.tagName==="SELECT"||B.tagName==="OPTION"||A.preventDefault();},[]),nr=useCallback(A=>{let B=A.target,je=document.activeElement;B.tagName==="SELECT"||B.tagName==="OPTION"||je?.tagName==="SELECT"||requestAnimationFrame(()=>{R?.();});},[R]);return jsxs("div",{ref:Ae,className:P(!oe&&"flex items-center px-2 py-1 bg-muted rounded-full min-h-[36px] overflow-x-auto mx-2 mb-1",p),style:oe?{display:"contents",...m}:m,role:oe?void 0:"toolbar","aria-label":oe?void 0:t("toolbar.ariaLabel"),"data-testid":oe?void 0:"formatting-bar",onMouseDown:oe?void 0:rr,onMouseUp:oe?void 0:nr,children:[jsxs(fe,{label:t("formattingBar.groups.history"),children:[jsx(ce,{onClick:Xe,disabled:a||!c,title:t("formattingBar.undoShortcut"),ariaLabel:t("formattingBar.undo"),children:jsx(b,{name:"undo",size:se})}),jsx(ce,{onClick:re,disabled:a||!d,title:t("formattingBar.redoShortcut"),ariaLabel:t("formattingBar.redo"),children:jsx(b,{name:"redo",size:se})})]}),de&&jsx(fe,{label:t("formattingBar.groups.zoom"),children:jsx(To,{value:be,onChange:G,disabled:a,compact:true})}),J&&jsx(fe,{label:t("formattingBar.groups.styles"),children:jsx(So,{value:r.styleId||"Normal",onChange:ne,styles:O,theme:Y,disabled:a,width:120})}),(g||b$2)&&jsxs(fe,{label:t("formattingBar.groups.font"),children:[g&&jsx(so,{value:r.fontFamily||"Arial",onChange:We,fonts:T,disabled:a,width:60,placeholder:"Arial"}),b$2&&jsx(eo,{value:r.fontSize!==void 0?halfPointsToPoints(r.fontSize):11,onChange:V,disabled:a,width:42,placeholder:"11"})]}),jsxs(fe,{label:t("formattingBar.groups.textFormatting"),children:[jsx(ce,{onClick:()=>z("bold"),active:r.bold,disabled:a,title:t("formattingBar.boldShortcut"),ariaLabel:t("formattingBar.bold"),children:jsx(b,{name:"format_bold",size:se})}),jsx(ce,{onClick:()=>z("italic"),active:r.italic,disabled:a,title:t("formattingBar.italicShortcut"),ariaLabel:t("formattingBar.italic"),children:jsx(b,{name:"format_italic",size:se})}),jsx(ce,{onClick:()=>z("underline"),active:r.underline,disabled:a,title:t("formattingBar.underlineShortcut"),ariaLabel:t("formattingBar.underline"),children:jsx(b,{name:"format_underlined",size:se})}),jsx(ce,{onClick:()=>z("strikethrough"),active:r.strike,disabled:a,title:t("formattingBar.strikethrough"),ariaLabel:t("formattingBar.strikethrough"),children:jsx(b,{name:"strikethrough_s",size:se})}),h&&jsx(Fe,{mode:"text",value:r.color?.replace(/^#/,""),onChange:ye,theme:Y,disabled:a,title:t("formattingBar.fontColor")}),v&&jsx(Fe,{mode:"highlight",value:r.highlight,onChange:wt,theme:Y,disabled:a,title:t("formattingBar.highlightColor")}),jsx(ce,{onClick:()=>z("insertLink"),disabled:a,title:t("formattingBar.insertLinkShortcut"),ariaLabel:t("formattingBar.insertLink"),children:jsx(b,{name:"link",size:se})})]}),jsxs(fe,{label:t("formattingBar.groups.script"),children:[jsx(ce,{onClick:()=>z("superscript"),active:r.superscript,disabled:a,title:t("formattingBar.superscriptShortcut"),ariaLabel:t("formattingBar.superscript"),children:jsx(b,{name:"superscript",size:se})}),jsx(ce,{onClick:()=>z("subscript"),active:r.subscript,disabled:a,title:t("formattingBar.subscriptShortcut"),ariaLabel:t("formattingBar.subscript"),children:jsx(b,{name:"subscript",size:se})})]}),C&&jsx(fe,{label:t("formattingBar.groups.alignment"),children:jsx(xo,{value:r.alignment||"left",onChange:E,disabled:a})}),(w||L)&&jsxs(fe,{label:t("formattingBar.groups.listFormatting"),children:[w&&jsx(ro,{listState:r.listState||createDefaultListState(),onBulletList:Ne,onNumberedList:nt,onIndent:De,onOutdent:pe,disabled:a,showIndentButtons:true,compact:true,hasIndent:(r.indentLeft??0)>0}),L&&jsx(yo,{value:r.lineSpacing,onChange:Q,disabled:a})]}),M&&_&&jsxs(fe,{label:t("formattingBar.groups.image"),children:[jsx(Oo,{imageContext:M,onChange:_,disabled:a}),ue&&jsx(zo,{onTransform:ue,disabled:a}),he&&jsx(ce,{onClick:he,disabled:a,title:t("formattingBar.imagePropertiesShortcut"),ariaLabel:t("formattingBar.imageProperties"),children:jsx(b,{name:"tune",size:se})})]}),xe?.isInTable&&ve&&jsxs(fe,{label:t("formattingBar.groups.table"),children:[jsx(Mo,{onAction:ae,disabled:a}),jsx(Io,{onAction:ae,disabled:a,theme:Y,value:resolveColorToHex(xe?.cellBorderColor,Y)}),jsx(Ro,{onAction:ae,disabled:a}),jsx(Eo,{onAction:ae,disabled:a,theme:Y,value:xe?.cellBackgroundColor}),jsx(Bo,{onAction:ae,disabled:a,tableContext:xe})]}),jsx(ce,{onClick:()=>z("clearFormatting"),disabled:a,title:t("formattingBar.clearFormatting"),ariaLabel:t("formattingBar.clearFormatting"),children:jsx(b,{name:"format_clear",size:se})}),f]})}function qn(e){return "type"in e&&e.type==="separator"}var Go={display:"flex",alignItems:"center",gap:2,padding:"2px 8px",border:"none",background:"transparent",borderRadius:4,cursor:"pointer",fontSize:13,fontWeight:400,color:"var(--doc-text)",whiteSpace:"nowrap",height:28,lineHeight:"28px"},Yn={...Go,background:"var(--doc-bg-hover)"},Uo={display:"flex",alignItems:"center",gap:8,padding:"6px 12px",border:"none",background:"transparent",cursor:"pointer",fontSize:13,color:"var(--doc-text)",width:"100%",textAlign:"left",whiteSpace:"nowrap"},Xn={...Uo,opacity:.4,cursor:"default"},jn={height:1,backgroundColor:"var(--doc-border)",margin:"4px 0"},Jn={marginLeft:"auto",fontSize:12,color:"var(--doc-text-muted)"},Qn={position:"absolute",left:"100%",top:-4,marginLeft:2,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:6,boxShadow:"0 4px 12px var(--doc-shadow)",padding:8,zIndex:1001};function ot({label:e,items:t,disabled:o,showChevron:r=false}){let[n,s]=useState(false),[i,c]=useState(null),d=useRef(null),a=useRef(null),[p,m]=useState({top:0,left:0}),l=useCallback(()=>{s(false),c(null);},[]);useEffect(()=>{if(!n||!d.current)return;let f=d.current.getBoundingClientRect();m({top:f.bottom+2,left:f.left});},[n]),useEffect(()=>{if(!n)return;function f(b){let h=b.target;d.current&&!d.current.contains(h)&&a.current&&!a.current.contains(h)&&l();}function g(b){b.key==="Escape"&&l();}function x(){l();}return document.addEventListener("mousedown",f),document.addEventListener("keydown",g),window.addEventListener("scroll",x,true),()=>{document.removeEventListener("mousedown",f),document.removeEventListener("keydown",g),window.removeEventListener("scroll",x,true);}},[n,l]);let u=f=>{f.disabled||f.submenuContent||f.onClick&&(f.onClick(),l());};return jsxs("div",{style:{position:"relative"},children:[jsxs("button",{ref:d,type:"button",onClick:()=>!o&&s(!n),onMouseDown:f=>f.preventDefault(),disabled:o,style:n?Yn:Go,children:[e,r&&jsx(b,{name:"arrow_drop_down",size:16})]}),n&&jsx("div",{ref:a,style:{position:"fixed",top:p.top,left:p.left,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:6,boxShadow:"0 4px 12px var(--doc-shadow)",padding:"4px 0",zIndex:1e4,minWidth:200},onMouseDown:f=>f.preventDefault(),children:t.map((f,g)=>{if(qn(f))return jsx("div",{style:jn},`sep-${g}`);let x=f;if(x.customContent)return jsx("div",{onMouseDown:v=>v.preventDefault(),children:x.customContent},x.label);let b$1=!!x.submenuContent,h=i===x.label;return jsxs("div",{style:{position:"relative"},onMouseEnter:()=>b$1&&c(x.label),onMouseLeave:()=>b$1&&c(null),children:[jsxs("button",{type:"button",style:x.disabled?Xn:Uo,onClick:()=>u(x),onMouseDown:v=>v.preventDefault(),onMouseOver:v=>{x.disabled||(v.currentTarget.style.backgroundColor="var(--doc-bg-hover)");},onMouseOut:v=>{v.currentTarget.style.backgroundColor="transparent";},disabled:x.disabled,children:[x.icon&&jsx(b,{name:x.icon,size:18}),jsx("span",{children:x.label}),x.shortcut&&jsx("span",{style:Jn,children:x.shortcut}),b$1&&jsx("span",{style:{marginLeft:"auto"},children:jsx(b,{name:"keyboard_arrow_right",size:16})})]}),b$1&&h&&jsx("div",{style:Qn,onMouseDown:v=>v.preventDefault(),children:x.submenuContent(l)})]},x.label)})})]})}var Ft=18,ta=2,qo={width:Ft,height:Ft,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:2,transition:"background-color 0.1s, border-color 0.1s",cursor:"pointer"},oa={...qo,backgroundColor:"var(--doc-primary)",border:"1px solid var(--doc-primary)"},ra={marginTop:6,fontSize:11,fontWeight:500,color:"var(--doc-text)",textAlign:"center"};function Yo({onInsert:e,gridRows:t=6,gridColumns:o=6}){let[r,n]=useState(0),[s,i]=useState(0),c=useCallback(()=>{r>0&&s>0&&e(r,s);},[r,s,e]),d=[];for(let p=1;p<=t;p++)for(let m=1;m<=o;m++){let l=p<=r&&m<=s;d.push(jsx("div",{style:l?oa:qo,onMouseEnter:()=>{n(p),i(m);},onClick:c,role:"gridcell","aria-selected":l},`${p}-${m}`));}let a=r>0&&s>0?`${s} \xD7 ${r}`:"Select size";return jsxs("div",{children:[jsx("div",{style:{display:"grid",gap:ta,gridTemplateColumns:`repeat(${o}, ${Ft}px)`},onMouseLeave:()=>{n(0),i(0);},role:"grid","aria-label":"Table size selector",children:d}),jsx("div",{style:ra,children:a})]})}function la({items:e,closeMenu:t}){return jsx("div",{style:{display:"flex",flexDirection:"column",minWidth:220},children:e.map(o=>{let r=!o.onClick;return jsxs("button",{type:"button",disabled:r,style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",border:"none",background:"transparent",cursor:r?"default":"pointer",fontSize:13,color:"var(--doc-text)",width:"100%",textAlign:"left",whiteSpace:"nowrap",opacity:r?.4:1},onMouseDown:n=>n.preventDefault(),onClick:()=>{r||(o.onClick?.(),t());},onMouseOver:n=>{r||(n.currentTarget.style.backgroundColor="var(--doc-bg-hover)");},onMouseOut:n=>{n.currentTarget.style.backgroundColor="transparent";},children:[jsx(b,{name:o.icon,size:18}),jsx("span",{children:o.label})]},o.label)})})}function sa(){return jsxs("svg",{width:"32",height:"40",viewBox:"0 0 32 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M2 0C0.9 0 0 0.9 0 2V38C0 39.1 0.9 40 2 40H30C31.1 40 32 39.1 32 38V10L22 0H2Z",fill:"#cbd5e1"}),jsx("path",{d:"M22 0L32 10H24C22.9 10 22 9.1 22 8V0Z",fill:"#94a3b8"}),jsx("rect",{x:"7",y:"18",width:"18",height:"2",rx:"1",fill:"#fff"}),jsx("rect",{x:"7",y:"23",width:"18",height:"2",rx:"1",fill:"#fff"}),jsx("rect",{x:"7",y:"28",width:"12",height:"2",rx:"1",fill:"#fff"})]})}function zt({children:e}){return jsx("div",{className:"flex items-center flex-shrink-0",children:e})}function ca(e){return e.replace(/\.docx$/i,"")}function jo({value:e,onChange:t,placeholder:o,editable:r=true}){let{t:n}=b$1(),s=o??n("titleBar.untitled"),i=ca(e)??"";return r?jsx("input",{type:"text",value:i,onChange:c=>{let d=c.target.value;t?.(d.endsWith(".docx")?d:d+".docx");},placeholder:s,className:"text-base font-normal text-foreground bg-transparent border-0 outline-none px-2 py-0 rounded hover:bg-muted focus:bg-doc-bg-input focus:ring-1 focus:ring-ring min-w-[100px] max-w-[300px] truncate leading-tight","aria-label":n("titleBar.documentNameAriaLabel")}):jsx("span",{className:"text-base font-normal text-foreground px-2 py-0 min-w-[100px] max-w-[300px] truncate leading-tight",children:i||s})}function Kt({children:e}){return jsx("div",{className:"flex items-center gap-2 ml-auto flex-shrink-0",children:e})}function Ht(){let{t:e}=b$1(),t=Ko(),{disabled:o=false,onFormat:r,onPrint:n,onOpen:s,onSave:i,onPageSetup:c,onInsertImage:d,onInsertTable:a,showTableInsert:p=true,onInsertPageBreak:m,onInsertSectionBreakNextPage:l,onInsertSectionBreakContinuous:u,onInsertTOC:f,onWatermark:g,onRefocusEditor:x}=t,b=useCallback(w=>{!o&&r&&r(w);},[o,r]),h=useCallback((w,L)=>{!o&&a&&(a(w,L),requestAnimationFrame(()=>x?.()));},[o,a,x]),v=!!n||!!c,C=v||s||i;return jsxs("div",{className:"flex items-center",role:"menubar","aria-label":e("titleBar.menuBarAriaLabel"),children:[C&&jsx(ot,{label:e("toolbar.file"),disabled:o,items:[...s?[{icon:"file_upload",label:e("toolbar.open"),shortcut:e("toolbar.openShortcut"),onClick:s}]:[],...i?[{icon:"file_download",label:e("toolbar.save"),shortcut:e("toolbar.saveShortcut"),onClick:i}]:[],...(s||i)&&v?[{type:"separator"}]:[],...n?[{icon:"print",label:e("toolbar.print"),shortcut:e("toolbar.printShortcut"),onClick:n}]:[],...c?[{icon:"settings",label:e("toolbar.pageSetup"),onClick:c}]:[]]}),jsx(ot,{label:e("toolbar.format"),disabled:o,items:[{icon:"format_textdirection_l_to_r",label:e("toolbar.leftToRight"),onClick:()=>b("setLtr")},{icon:"format_textdirection_r_to_l",label:e("toolbar.rightToLeft"),onClick:()=>b("setRtl")}]}),jsx(ot,{label:e("toolbar.insert"),disabled:o,items:[...d?[{icon:"image",label:e("toolbar.image"),onClick:d}]:[],...p&&a?[{icon:"grid_on",label:e("toolbar.table"),submenuContent:w=>jsx(Yo,{onInsert:(L,J)=>{h(L,J),w();}})}]:[],...d||p&&a?[{type:"separator"}]:[],{icon:"page_break",label:e("toolbar.break"),submenuContent:w=>jsx(la,{closeMenu:w,items:[{icon:"page_break",label:e("toolbar.pageBreak"),onClick:m},{icon:"horizontal_rule",label:e("toolbar.sectionBreakNextPage"),onClick:l},{icon:"border_horizontal",label:e("toolbar.sectionBreakContinuous"),onClick:u}]})},{icon:"format_list_numbered",label:e("toolbar.tableOfContents"),onClick:f,disabled:!f},...g?[{icon:"branding_watermark",label:e("toolbar.watermark"),onClick:g}]:[]]}),jsx(ot,{label:e("toolbar.help"),disabled:o,items:[{label:e("toolbar.reportIssue"),onClick:()=>openReportIssue()}]})]})}function Jo({children:e}){let t=null,o=null,r=[],n=[];Children.forEach(e,i=>{isValidElement(i)&&(i.type===zt?t=i:i.type===Kt?o=i:i.type===Ht?n.push(i):r.push(i));});let s=useCallback(i=>{let c=i.target;c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.tagName==="SELECT"||c.tagName==="OPTION"||i.preventDefault();},[]);return jsxs("div",{className:"flex items-stretch bg-doc-surface pt-2 pb-1",onMouseDown:s,"data-testid":"title-bar",children:[jsx("div",{className:"flex items-center flex-shrink-0 pl-3 pr-1",children:t||jsx(sa,{})}),jsxs("div",{className:"flex flex-col justify-center flex-1 min-w-0 py-1",children:[r.length>0&&jsx("div",{className:"flex items-center gap-2 px-1",children:r}),n.length>0&&jsx("div",{className:"flex items-center px-1",children:n})]}),o&&jsx("div",{className:"flex items-center flex-shrink-0 px-3",children:o})]})}function da({children:e,className:t,style:o,...r}){return jsx(tt.Provider,{value:r,children:jsx("div",{className:P("flex flex-col bg-doc-surface shadow-sm flex-shrink-0",t),style:{position:"relative",zIndex:ct.toolbar,...o},"data-testid":"editor-toolbar",children:e})})}var Ye=da;Ye.TitleBar=Jo;Ye.Logo=zt;Ye.DocumentName=jo;Ye.MenuBar=Ht;Ye.TitleBarRight=Kt;Ye.Toolbar=Wo;var tr=12240,yt=1440,Ct=1440,St=567,Vt=22,ma="var(--doc-text-muted)",fa="var(--doc-text-subtle)",er="var(--doc-shadow-subtle)",ga="var(--doc-primary)",ba="var(--doc-primary-hover)",ha="var(--doc-primary-hover)",He=5;function xa(e,t){return t==="inch"?(e/Ct).toFixed(2)+'"':(e/St).toFixed(1)+" cm"}function Ic({sectionProps:e,zoom:t=1,editable:o=false,onLeftMarginChange:r,onRightMarginChange:n,onFirstLineIndentChange:s,showFirstLineIndent:i=false,firstLineIndent:c=0,hangingIndent:d=false,indentLeft:a=0,indentRight:p=0,onIndentLeftChange:m,onIndentRightChange:l,unit:u="inch",className:f="",style:g,tabStops:x,onTabStopRemove:b}){let{t:h}=b$1(),[v,C]=useState(null),[w,L]=useState(null),[J,O]=useState(null),[Y,de]=useState(null),be=useRef(null),G=e?.pageWidth??tr,R=e?.marginLeft??yt,M=e?.marginRight??yt,_=G-R-M,ue=twipsToPixels(G)*t,he=twipsToPixels(R)*t,xe=twipsToPixels(M)*t,ve=twipsToPixels(a)*t,oe=twipsToPixels(p)*t,Ae=d?-c:c,z=twipsToPixels(Ae)*t,Xe=he+ve,re=ue-xe-oe,We=he+ve+z,T=useCallback((E,Ne)=>{o&&(E.preventDefault(),E.stopPropagation(),C(Ne));},[o]),V=useCallback(E=>{if(!v||!be.current)return;let Ne=be.current.getBoundingClientRect(),nt=E.clientX-Ne.left;de(nt);let De=pixelsToTwips(nt/t);if(v==="leftMargin"){let pe=G-M-720,Q=Math.round(Math.max(0,Math.min(De,pe)));O(Q),r?.(Q);}else if(v==="rightMargin"){let pe=G-De,Q=G-R-720,ne=Math.round(Math.max(0,Math.min(pe,Q)));O(ne),n?.(ne);}else if(v==="firstLineIndent"){let pe=R+a,Q=De-pe,ne=_-a-p-720,ae=Math.round(Math.max(-a,Math.min(Q,ne)));O(ae),s?.(ae);}else if(v==="leftIndent"){let pe=De-R,Q=_-p-720,ne=Math.round(Math.max(0,Math.min(pe,Q)));O(ne),m?.(ne);}else if(v==="rightIndent"){let Q=G-M-De,ne=_-a-720,ae=Math.round(Math.max(0,Math.min(Q,ne)));O(ae),l?.(ae);}},[v,t,G,R,M,_,a,p,r,n,s,m,l]),ye=useCallback(()=>{C(null),O(null),de(null);},[]);useEffect(()=>{if(v)return document.addEventListener("mousemove",V),document.addEventListener("mouseup",ye),()=>{document.removeEventListener("mousemove",V),document.removeEventListener("mouseup",ye);}},[v,V,ye]);let wt=wa(G,t,u);return jsxs("div",{ref:be,className:`docx-horizontal-ruler ${f}`,style:{position:"relative",width:formatPx(ue),height:Vt,backgroundColor:"transparent",overflow:"visible",userSelect:"none",cursor:v?"ew-resize":"default",...g},role:"slider","aria-label":h("ruler.horizontal"),"aria-valuemin":0,"aria-valuemax":G,children:[jsx("div",{style:{position:"absolute",top:0,left:0,width:formatPx(he),height:Vt,backgroundColor:er,borderRight:"1px solid var(--doc-shadow-subtle)",cursor:o?"ew-resize":"default",zIndex:1},onMouseDown:o&&r?E=>T(E,"leftMargin"):void 0}),jsx("div",{style:{position:"absolute",top:0,right:0,width:formatPx(xe),height:Vt,backgroundColor:er,borderLeft:"1px solid var(--doc-shadow-subtle)",cursor:o?"ew-resize":"default",zIndex:1},onMouseDown:o&&n?E=>T(E,"rightMargin"):void 0}),jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none"},children:wt.map((E,Ne)=>jsx(va,{tick:E},Ne))}),i&&jsx($t,{direction:"down",positionPx:We,editable:o,isDragging:v==="firstLineIndent",isHovered:w==="firstLineIndent",onMouseEnter:()=>L("firstLineIndent"),onMouseLeave:()=>L(null),onMouseDown:E=>T(E,"firstLineIndent"),label:h("ruler.firstLineIndent")}),o&&m&&jsx($t,{direction:"up",positionPx:Xe,editable:o,isDragging:v==="leftIndent",isHovered:w==="leftIndent",onMouseEnter:()=>L("leftIndent"),onMouseLeave:()=>L(null),onMouseDown:E=>T(E,"leftIndent"),label:h("ruler.leftIndent")}),o&&l&&jsx($t,{direction:"down",positionPx:re,editable:o,isDragging:v==="rightIndent",isHovered:w==="rightIndent",onMouseEnter:()=>L("rightIndent"),onMouseLeave:()=>L(null),onMouseDown:E=>T(E,"rightIndent"),label:h("ruler.rightIndent")}),x?.map(E=>jsx(Sa,{tabStop:E,positionPx:twipsToPixels(E.position)*t,onDoubleClick:()=>b?.(E.position)},E.position)),v&&J!==null&&Y!==null&&jsx(ya,{value:xa(J,u),positionPx:Y})]})}function va({tick:e}){return jsxs(Fragment,{children:[jsx("div",{style:{position:"absolute",left:formatPx(e.position),bottom:0,width:1,height:e.height,backgroundColor:fa}}),e.label&&jsx("div",{style:{position:"absolute",left:formatPx(e.position),top:3,transform:"translateX(-50%)",fontSize:"9px",color:ma,fontFamily:"sans-serif",whiteSpace:"nowrap"},children:e.label})]})}function $t({direction:e,positionPx:t,editable:o,isDragging:r,isHovered:n,onMouseEnter:s,onMouseLeave:i,onMouseDown:c,label:d}){let a=r?ha:n?ba:ga,p=Math.round(He*1.6),m={position:"absolute",left:formatPx(t-He),width:He*2,height:p+2,cursor:o?"ew-resize":"default",zIndex:r?10:4,...e==="down"?{top:0}:{bottom:0}},l=e==="down"?{position:"absolute",top:1,left:0,width:0,height:0,borderLeft:`${He}px solid transparent`,borderRight:`${He}px solid transparent`,borderTop:`${p}px solid ${a}`,transition:"border-top-color 0.1s"}:{position:"absolute",bottom:1,left:0,width:0,height:0,borderLeft:`${He}px solid transparent`,borderRight:`${He}px solid transparent`,borderBottom:`${p}px solid ${a}`,transition:"border-bottom-color 0.1s"};return jsx("div",{className:"docx-ruler-indent",style:m,onMouseEnter:s,onMouseLeave:i,onMouseDown:c,role:"slider","aria-label":d,"aria-orientation":"horizontal",tabIndex:o?0:-1,children:jsx("div",{style:l})})}function ya({value:e,positionPx:t}){return jsx("div",{style:{position:"absolute",left:formatPx(t),top:-22,transform:"translateX(-50%)",backgroundColor:"var(--doc-text)",color:"var(--doc-on-primary)",fontSize:"10px",fontFamily:"sans-serif",padding:"2px 6px",borderRadius:3,whiteSpace:"nowrap",pointerEvents:"none",zIndex:20},children:e})}var Ca={left:"L",center:"C",right:"R",decimal:"D",bar:"|"};function Sa({tabStop:e,positionPx:t,onDoubleClick:o}){return jsx("div",{style:{position:"absolute",left:formatPx(t-5),bottom:0,width:10,height:12,display:"flex",alignItems:"center",justifyContent:"center",fontSize:8,fontWeight:700,color:"var(--doc-text-muted)",cursor:"pointer",userSelect:"none"},onDoubleClick:r=>{r.stopPropagation(),o();},title:`${e.alignment} tab at ${(e.position/1440).toFixed(2)}"`,children:Ca[e.alignment]||"L"})}function wa(e,t,o){let r=[];if(o==="inch"){let n=Ct/8,s=Math.ceil(e/n);for(let i=0;i<=s;i++){let c=i*n;if(c>e)break;let d=twipsToPixels(c)*t;i%8===0?r.push({position:d,height:10,label:i/8>0?String(i/8):void 0}):i%4===0?r.push({position:d,height:6}):i%2===0?r.push({position:d,height:4}):r.push({position:d,height:2});}}else {let n=St/10,s=Math.ceil(e/n);for(let i=0;i<=s;i++){let c=i*n;if(c>e)break;let d=twipsToPixels(c)*t;i%10===0?r.push({position:d,height:10,label:i/10>0?String(i/10):void 0}):i%5===0?r.push({position:d,height:6}):r.push({position:d,height:3});}}return r}function Lc(e,t,o,r){let n=pixelsToTwips(e/r);return t==="left"?Math.max(0,n):Math.max(0,pixelsToTwips(o/r)-n)}function Rc(e,t=1){let o=e?.pageWidth??tr,r=e?.marginLeft??yt,n=e?.marginRight??yt,s=twipsToPixels(o)*t,i=twipsToPixels(r)*t,c=twipsToPixels(n)*t;return {width:s,leftMargin:i,rightMargin:c,contentWidth:s-i-c}}function Ec(e,t){return t==="inch"?(e/Ct).toFixed(2)+'"':(e/St).toFixed(1)+" cm"}function Ac(e,t){let o=parseFloat(e.replace(/[^\d.]/g,""));return isNaN(o)?null:Math.round(o*(t==="inch"?Ct:St))}
|
|
1
|
+
import {b,c,a}from'./chunk-BABMU5KA.mjs';import {b as b$1}from'./chunk-ZFZJRL2R.mjs';import*as j from'react';import j__default,{createContext,useState,useRef,useCallback,useMemo,useEffect,Children,isValidElement,useContext}from'react';import {clsx}from'clsx';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {halfPointsToPoints}from'@sqren/docx-editor-core/utils/units';export{pointsToHalfPoints as d}from'@sqren/docx-editor-core/utils/units';import {createDefaultListState}from'@sqren/docx-editor-core/utils/listState';export{createDefaultListState as f}from'@sqren/docx-editor-core/utils/listState';import {en as en$1}from'@sqren/docx-editor-i18n';import*as N from'@radix-ui/react-select';import {generateThemeTintShadeMatrix,resolveColorToHex,twipsToPixels,pixelsToTwips,formatPx,resolveHighlightColor,resolveColor}from'@sqren/docx-editor-core/utils';import {resolveParagraphStyleOptions,getStylePreviewProps}from'@sqren/docx-editor-core/utils/stylePreview';import {normalizeFontFamilies}from'@sqren/docx-editor-core/utils/fontOptions';export{mapHexToHighlightName as g}from'@sqren/docx-editor-core/utils/highlightColors';import {openReportIssue}from'@sqren/docx-editor-core/utils/reportIssue';var qt=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,Yt=clsx,Xt=(e,t)=>o=>{var r;if(t?.variants==null)return Yt(e,o?.class,o?.className);let{variants:n,defaultVariants:s}=t,i=Object.keys(n).map(a=>{let p=o?.[a],m=s?.[a];if(p===null)return null;let l=qt(p)||qt(m);return n[a][l]}),c=o&&Object.entries(o).reduce((a,p)=>{let[m,l]=p;return l===void 0||(a[m]=l),a},{}),d=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((a,p)=>{let{class:m,className:l,...u}=p;return Object.entries(u).every(f=>{let[g,x]=f;return Array.isArray(x)?x.includes({...s,...c}[g]):{...s,...c}[g]===x})?[...a,m,l]:a},[]);return Yt(e,i,d,o?.class,o?.className)};function P(...e){return clsx(e)}var dr=Xt("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-9 w-9","icon-sm":"h-7 w-7"}},defaultVariants:{variant:"default",size:"default"}}),K=j.forwardRef(({className:e,variant:t,size:o,...r},n)=>jsx("button",{className:P(dr({variant:t,size:o,className:e})),ref:n,...r}));K.displayName="Button";var mr=[8,9,10,11,12,14,16,18,20,24,28,36,48,72],fr=1,gr=400;function Jt(e,t,o){for(let r of t)if(r>e)return r;return Math.min(e+1,o)}function Qt(e,t,o){for(let r=t.length-1;r>=0;r--)if(t[r]<e)return t[r];return Math.max(e-1,o)}function eo({value:e,onChange:t,sizes:o=mr,disabled:r=false,className:n,placeholder:s="11",minSize:i=fr,maxSize:c$1=gr}){let{t:d}=b$1(),[a,p]=useState(false),[m,l]=useState(""),[u,f]=useState(false),g=useRef(null),x=useCallback(()=>{f(false),p(false);},[]),{containerRef:b$2,dropdownRef:h,dropdownStyle:v}=c({isOpen:u,onClose:x}),C=e??(parseInt(s,10)||11),w=e!==void 0?e.toString():s,L=useCallback(M=>{if(M.preventDefault(),r)return;let _=Qt(C,o,i);t?.(_);},[C,o,i,r,t]),J=useCallback(M=>{if(M.preventDefault(),r)return;let _=Jt(C,o,c$1);t?.(_);},[C,o,c$1,r,t]),O=useCallback(M=>{M.preventDefault(),!r&&(p(true),l(w),f(true),requestAnimationFrame(()=>{g.current?.focus(),g.current?.select();}));},[r,w]),Y=useCallback(M=>{l(M.target.value);},[]),de=useCallback(()=>{p(false);let M=parseFloat(m);if(!isNaN(M)&&M>=i&&M<=c$1){let _=Math.round(M*2)/2;t?.(_);}},[m,i,c$1,t]),be=useCallback(M=>{if(M.key==="Enter")M.preventDefault(),de(),f(false);else if(M.key==="Escape")p(false),f(false);else if(M.key==="ArrowUp"){M.preventDefault();let _=Jt(C,o,c$1);l(_.toString()),t?.(_);}else if(M.key==="ArrowDown"){M.preventDefault();let _=Qt(C,o,i);l(_.toString()),t?.(_);}},[de,C,o,c$1,i,t]),G=useCallback(M=>{t?.(M),f(false),p(false);},[t]),R=useCallback(M=>{M.target.tagName!=="INPUT"&&M.preventDefault();},[]);return jsxs("div",{ref:b$2,className:P("flex items-center",n),onMouseDown:R,children:[jsx(K,{variant:"ghost",size:"icon-sm",className:P("h-7 w-7 text-muted-foreground hover:text-foreground hover:bg-muted/80 rounded-r-none",r&&"opacity-30 cursor-not-allowed"),onMouseDown:L,disabled:r||C<=i,"aria-label":d("fontSize.decrease"),"data-testid":"font-size-decrease",children:jsx(b,{name:"remove",size:18})}),jsx("div",{className:"relative",children:a?jsx("input",{ref:g,type:"text",value:m,onChange:Y,onBlur:de,onKeyDown:be,className:P("h-7 w-10 text-center text-sm border border-input bg-doc-bg-input text-doc-text","focus:outline-none focus:ring-1 focus:ring-ring","rounded-none"),"aria-label":d("fontSize.label"),"data-testid":"font-size-input"}):jsx("button",{type:"button",onClick:O,className:P("h-7 w-10 text-center text-sm border border-border bg-doc-bg-input text-doc-text","hover:border-input hover:bg-doc-bg-hover","focus:outline-none focus:ring-1 focus:ring-ring","rounded-none",r&&"opacity-50 cursor-not-allowed"),disabled:r,"aria-label":d("fontSize.label"),"aria-haspopup":"listbox","aria-expanded":u,"data-testid":"font-size-display",children:w})}),u&&jsx("div",{ref:h,style:{...v,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:6,boxShadow:"0 4px 12px var(--doc-shadow)",maxHeight:240,overflowY:"auto",minWidth:60},role:"listbox","aria-label":d("fontSize.listLabel"),children:o.map(M=>jsx("button",{type:"button",onClick:()=>G(M),className:P("w-full px-3 py-1.5 text-sm text-left","hover:bg-muted",M===C&&"bg-muted font-medium"),role:"option","aria-selected":M===C,children:M},M))}),jsx(K,{variant:"ghost",size:"icon-sm",className:P("h-7 w-7 text-muted-foreground hover:text-foreground hover:bg-muted/80 rounded-l-none",r&&"opacity-30 cursor-not-allowed"),onMouseDown:J,disabled:r||C>=c$1,"aria-label":d("fontSize.increase"),"data-testid":"font-size-increase",children:jsx(b,{name:"add",size:18})})]})}var vr={display:"inline-flex",alignItems:"center",gap:"4px"},oo={display:"inline-flex",alignItems:"center",gap:"4px"},st={display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px",padding:"4px",border:"none",borderRadius:"4px",backgroundColor:"transparent",cursor:"pointer",transition:"background-color 0.1s",color:"var(--doc-text-muted)"},yr={...st,backgroundColor:"var(--doc-bg-hover)"},Cr={...st,backgroundColor:"var(--doc-primary-light)",color:"var(--doc-primary)"},Sr={...st,cursor:"default",opacity:.38},wr={width:"28px",height:"28px",padding:"2px"},Tr={width:"1px",height:"20px",backgroundColor:"var(--doc-border)",margin:"0 6px"},at=20;function it({active:e=false,disabled:t=false,title:o,onClick:r,children:n,className:s,style:i}){let[c,d]=useState(false),a={...t?Sr:e?Cr:c?yr:st,...i},p=m=>{m.preventDefault();};return jsx("button",{type:"button",className:`docx-list-button ${e?"docx-list-button-active":""} ${t?"docx-list-button-disabled":""} ${s||""}`,style:a,onMouseDown:p,onClick:t?void 0:r,onMouseEnter:()=>d(true),onMouseLeave:()=>d(false),disabled:t,title:o,"aria-label":o,"aria-pressed":e,role:"button",children:n})}function ro({listState:e,onBulletList:t,onNumberedList:o,onIndent:r,onOutdent:n,disabled:s=false,className:i,style:c,showIndentButtons:d=true,compact:a=false,hasIndent:p=false}){let{t:m}=b$1(),l=useCallback(()=>a?{...wr}:{},[a]),u=e?.type==="bullet",f=e?.type==="numbered",x=(e?.isInList||u||f)&&(e?.level??0)>0||p;return jsxs("div",{className:`docx-list-buttons ${i||""}`,style:{...vr,...c},role:"group","aria-label":m("lists.ariaLabel"),children:[jsxs("div",{style:oo,role:"group","aria-label":m("lists.typeAriaLabel"),children:[jsx(it,{active:u,disabled:s,title:m("lists.bulletList"),onClick:t,style:l(),children:jsx(b,{name:"format_list_bulleted",size:at})}),jsx(it,{active:f,disabled:s,title:m("lists.numberedList"),onClick:o,style:l(),children:jsx(b,{name:"format_list_numbered",size:at})})]}),d&&jsxs(Fragment,{children:[jsx("div",{style:Tr,role:"separator"}),jsxs("div",{style:oo,role:"group","aria-label":m("lists.indentationAriaLabel"),children:[jsx(it,{active:false,disabled:s||!x,title:m("lists.decreaseIndent"),onClick:n,style:l(),children:jsx(b,{name:"format_indent_decrease",size:at})}),jsx(it,{active:false,disabled:s,title:m("lists.increaseIndent"),onClick:r,style:l(),children:jsx(b,{name:"format_indent_increase",size:at})})]})]})]})}var ct={hfInlineEditor:10,ruler:30,outline:40,dropdown:100,toolbar:100,contextMenu:1e4};var io=[{action:"cut",labelKey:"contextMenu.cut",shortcutKey:"contextMenu.cutShortcut"},{action:"copy",labelKey:"contextMenu.copy",shortcutKey:"contextMenu.copyShortcut"},{action:"paste",labelKey:"contextMenu.paste",shortcutKey:"contextMenu.pasteShortcut"},{action:"pasteAsPlainText",labelKey:"contextMenu.pastePlainText",shortcutKey:"contextMenu.pastePlainTextShortcut",dividerAfter:true},{action:"delete",labelKey:"contextMenu.delete",shortcutKey:"contextMenu.deleteShortcut",dividerAfter:true},{action:"selectAll",labelKey:"contextMenu.selectAll",shortcutKey:"contextMenu.selectAllShortcut"}],Ir=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("circle",{cx:"4",cy:"12",r:"2",stroke:"currentColor",strokeWidth:"1.5"}),jsx("circle",{cx:"12",cy:"12",r:"2",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M5.5 10.5L10.5 3M10.5 10.5L5.5 3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),Lr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"5",y:"5",width:"8",height:"9",rx:"1",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M11 5V3a1 1 0 00-1-1H4a1 1 0 00-1 1v8a1 1 0 001 1h2",stroke:"currentColor",strokeWidth:"1.5"})]}),Rr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"3",y:"3",width:"10",height:"11",rx:"1",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M6 3V2a1 1 0 011-1h2a1 1 0 011 1v1",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M6 8h4M6 11h4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),Er=()=>jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{d:"M4 4l8 8M12 4l-8 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})}),Ar=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1",stroke:"currentColor",strokeWidth:"1.5",strokeDasharray:"2 2"}),jsx("rect",{x:"4",y:"4",width:"8",height:"8",fill:"currentColor",opacity:"0.3"})]}),Nr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"6",width:"12",height:"4",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("rect",{x:"2",y:"10",width:"12",height:"4",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M8 1v3M6.5 2.5h3",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]}),Dr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"2",width:"12",height:"4",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("rect",{x:"2",y:"6",width:"12",height:"4",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M8 12v3M6.5 13.5h3",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]}),Br=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"2",width:"12",height:"4",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("rect",{x:"2",y:"6",width:"12",height:"4",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2",opacity:"0.3"}),jsx("rect",{x:"2",y:"10",width:"12",height:"4",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M5 8h6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),_r=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"6",y:"2",width:"4",height:"12",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("rect",{x:"10",y:"2",width:"4",height:"12",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M3 8H0.5M1.75 6.5v3",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]}),Fr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"2",width:"4",height:"12",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("rect",{x:"6",y:"2",width:"4",height:"12",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M13 8h2.5M14.25 6.5v3",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]}),Or=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"2",width:"4",height:"12",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("rect",{x:"6",y:"2",width:"4",height:"12",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2",opacity:"0.3"}),jsx("rect",{x:"10",y:"2",width:"4",height:"12",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M8 5v6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),zr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"4",width:"4",height:"8",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("rect",{x:"10",y:"4",width:"4",height:"8",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M7 8h2",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),jsx("path",{d:"M8 7l1 1-1 1",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]}),Kr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"2",y:"4",width:"12",height:"8",rx:"0.5",stroke:"currentColor",strokeWidth:"1.2"}),jsx("path",{d:"M8 4v8",stroke:"currentColor",strokeWidth:"1.2",strokeDasharray:"2 1"}),jsx("path",{d:"M6.5 8h-1M9.5 8h1",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),Hr=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M3 3h10a1 1 0 011 1v6a1 1 0 01-1 1H6l-3 2.5V11H3a1 1 0 01-1-1V4a1 1 0 011-1z",stroke:"currentColor",strokeWidth:"1.3"}),jsx("path",{d:"M5 6h6M5 8.5h4",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]});function Wr(e){switch(e){case "cut":return jsx(Ir,{});case "copy":return jsx(Lr,{});case "paste":case "pasteAsPlainText":return jsx(Rr,{});case "delete":return jsx(Er,{});case "selectAll":return jsx(Ar,{});case "addRowAbove":return jsx(Nr,{});case "addRowBelow":return jsx(Dr,{});case "deleteRow":return jsx(Br,{});case "addColumnLeft":return jsx(_r,{});case "addColumnRight":return jsx(Fr,{});case "deleteColumn":return jsx(Or,{});case "mergeCells":return jsx(zr,{});case "splitCell":return jsx(Kr,{});case "addComment":return jsx(Hr,{});default:return null}}var Vr=({item:e,onClick:t,isHighlighted:o,onMouseEnter:r})=>e.action==="separator"?jsx("div",{className:"docx-text-context-menu-separator",style:{height:"1px",backgroundColor:"var(--doc-border)",margin:"4px 12px"}}):jsxs(Fragment,{children:[jsxs("button",{type:"button",className:`docx-text-context-menu-item ${o?"docx-text-context-menu-item-highlighted":""} ${e.disabled?"docx-text-context-menu-item-disabled":""}`,onClick:t,onMouseEnter:r,disabled:e.disabled,role:"menuitem","aria-disabled":e.disabled,style:{display:"flex",alignItems:"center",gap:"10px",width:"100%",padding:"8px 12px",border:"none",background:o&&!e.disabled?"var(--doc-primary-light)":"transparent",cursor:e.disabled?"not-allowed":"pointer",fontSize:"13px",color:e.disabled?"var(--doc-text-subtle)":"var(--doc-text)",textAlign:"left",opacity:e.disabled?.6:1},children:[jsx("span",{style:{display:"flex",color:e.disabled?"var(--doc-border)":"var(--doc-text-muted)"},children:Wr(e.action)}),jsx("span",{style:{flex:1},children:e.label}),e.shortcut&&jsx("span",{style:{fontSize:"11px",color:"var(--doc-text-subtle)",fontFamily:"monospace"},children:e.shortcut})]}),e.dividerAfter&&jsx("div",{className:"docx-text-context-menu-separator",style:{height:"1px",backgroundColor:"var(--doc-border)",margin:"4px 12px"}})]}),ui=({isOpen:e,position:t,hasSelection:o,isEditable:r,hasClipboardContent:n=true,onAction:s,onClose:i,items:c,className:d=""})=>{let a=useRef(null),[p,m]=useState(0),{t:l}=b$1(),u=useMemo(()=>io.map(h=>({action:h.action,label:l(h.labelKey),shortcut:h.shortcutKey?l(h.shortcutKey):void 0,dividerAfter:h.dividerAfter})),[l]),f=(c||u).map(h=>{let v=(()=>{if(h.disabled!==void 0)return h.disabled;switch(h.action){case "cut":case "copy":case "delete":return !o;case "paste":case "pasteAsPlainText":return !r||!n;default:return false}})();return {...h,disabled:v}}),g=f.filter(h=>h.action!=="separator");useEffect(()=>{if(!e)return;let h=C=>{a.current&&!a.current.contains(C.target)&&i();},v=setTimeout(()=>{document.addEventListener("mousedown",h);},0);return ()=>{clearTimeout(v),document.removeEventListener("mousedown",h);}},[e,i]),useEffect(()=>{if(!e)return;let h=v=>{switch(v.key){case "Escape":v.preventDefault(),i();break;case "ArrowDown":v.preventDefault(),m(w=>{let L=(w+1)%g.length;for(;g[L]?.disabled&&L!==w;)L=(L+1)%g.length;return L});break;case "ArrowUp":v.preventDefault(),m(w=>{let L=(w-1+g.length)%g.length;for(;g[L]?.disabled&&L!==w;)L=(L-1+g.length)%g.length;return L});break;case "Enter":v.preventDefault();let C=g[p];C&&!C.disabled&&(s(C.action),i());break}};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[e,p,g,s,i]),useEffect(()=>{e&&m(0);},[e]);let x=useCallback(()=>{let v=f.length*36+16,C=t.x,w=t.y;return typeof window<"u"&&(C+220>window.innerWidth&&(C=window.innerWidth-220-10),w+v>window.innerHeight&&(w=window.innerHeight-v-10),C<10&&(C=10),w<10&&(w=10)),{position:"fixed",top:w,left:C,minWidth:220,background:"var(--doc-surface)",border:"1px solid var(--doc-border-light)",borderRadius:"8px",boxShadow:"0 2px 10px var(--doc-shadow)",zIndex:ct.contextMenu,padding:"4px 0",overflow:"hidden"}},[t,f.length]),b=h=>{h.disabled||(s(h.action),i());};return e?jsx("div",{ref:a,className:`docx-text-context-menu ${d}`,style:x(),role:"menu","aria-label":l("contextMenu.textMenuAriaLabel"),children:f.map((h,v)=>{let C=g.findIndex(w=>w===h);return jsx(Vr,{item:h,onClick:()=>b(h),isHighlighted:C===p,onMouseEnter:()=>{C>=0&&!h.disabled&&m(C);}},`${h.action}-${v}`)})}):null};function pi(e={}){let{enabled:t=true,isEditable:o=true,containerRef:r,onAction:n}=e,[s,i]=useState(false),[c,d]=useState({x:0,y:0}),[a,p]=useState(false),m=useCallback(()=>{let x=window.getSelection(),b=x&&!x.isCollapsed&&x.toString().length>0;return p(!!b),!!b},[]),l=useCallback(x=>{t&&(x.preventDefault(),x.stopPropagation(),m(),d({x:x.clientX,y:x.clientY}),i(true));},[t,m]),u=useCallback(()=>{i(false);},[]),f=useCallback(x=>{switch(u(),x){case "cut":document.execCommand("cut");break;case "copy":document.execCommand("copy");break;case "paste":document.execCommand("paste");break;case "pasteAsPlainText":navigator.clipboard.readText?.().then(b=>{document.execCommand("insertText",false,b);}).catch(()=>{document.execCommand("paste");});break;case "delete":document.execCommand("delete");break;case "selectAll":document.execCommand("selectAll");break}n?.(x);},[u,n]),g=useCallback(x=>{l(x);},[l]);return useEffect(()=>{if(!s)return;let x=b=>{b.key==="Escape"&&u();};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[s,u]),{isOpen:s,position:c,hasSelection:a,openMenu:l,closeMenu:u,handleAction:f,onContextMenu:g}}function mi(e){return {cut:"Cut",copy:"Copy",paste:"Paste",pasteAsPlainText:"Paste as Plain Text",selectAll:"Select All",delete:"Delete",separator:"",addRowAbove:"Insert row above",addRowBelow:"Insert row below",deleteRow:"Delete row",addColumnLeft:"Insert column left",addColumnRight:"Insert column right",deleteColumn:"Delete column",mergeCells:en$1.table.mergeCells,splitCell:en$1.table.splitCell,addComment:"Comment"}[e]}function fi(e){return {cut:"Ctrl+X",copy:"Ctrl+C",paste:"Ctrl+V",pasteAsPlainText:"Ctrl+Shift+V",selectAll:"Ctrl+A",delete:"Del",separator:"",addRowAbove:"",addRowBelow:"",deleteRow:"",addColumnLeft:"",addColumnRight:"",deleteColumn:"",mergeCells:"",splitCell:"",addComment:""}[e]}function gi(){return io.map(e=>({action:e.action,label:e.labelKey,shortcut:e.shortcutKey,dividerAfter:e.dividerAfter}))}function bi(e,t,o){switch(e){case "cut":case "copy":case "delete":return t;case "paste":case "pasteAsPlainText":return o;case "addComment":return t;case "selectAll":return true;default:return true}}var we=N.Root,Be=N.Group,pt=N.Value;function Te({className:e,children:t,onMouseDown:o,...r}){return jsxs(N.Trigger,{className:P("flex h-8 items-center justify-between gap-1 rounded px-2 py-1","text-sm text-foreground bg-transparent","hover:bg-muted/80 focus:outline-none focus:bg-muted/80","disabled:cursor-not-allowed disabled:opacity-50","transition-colors duration-150","[&>span]:truncate",e),onMouseDown:n=>{n.preventDefault(),o?.(n);},...r,children:[t,jsx(N.Icon,{asChild:true,children:jsx(Gr,{className:"h-4 w-4 text-muted-foreground shrink-0"})})]})}function ke({className:e,children:t,position:o="popper",onCloseAutoFocus:r,...n}){let s=typeof document<"u"&&!!document.querySelector(".ep-root.dark");return jsx(N.Portal,{children:jsx("div",{className:P("ep-root",s&&"dark"),children:jsx(N.Content,{className:P("relative z-50 max-h-72 min-w-[8rem] overflow-hidden","rounded-lg border border-border bg-popover text-popover-foreground shadow-lg","data-[state=open]:animate-in data-[state=closed]:animate-out","data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95","data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2",o==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=top]:-translate-y-1",e),position:o,onCloseAutoFocus:i=>{i.preventDefault(),r?.(i);},...n,children:jsx(N.Viewport,{className:P("p-1",o==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),onMouseDown:i=>i.preventDefault(),children:t})})})})}function $e({className:e,...t}){return jsx(N.Label,{className:P("px-2 py-1.5 text-xs font-medium text-muted-foreground",e),...t})}function ie({className:e,children:t,onMouseDown:o,...r}){return jsxs(N.Item,{className:P("relative flex w-full cursor-pointer select-none items-center","rounded px-2 py-1.5 text-sm text-foreground outline-none","hover:bg-muted focus:bg-muted","data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),onMouseDown:n=>{n.preventDefault(),o?.(n);},...r,children:[jsx(N.ItemText,{children:t}),jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:jsx(N.ItemIndicator,{children:jsx(Ur,{className:"h-4 w-4"})})})]})}function Ge({className:e,...t}){return jsx(N.Separator,{className:P("-mx-1 my-1 h-px bg-muted",e),...t})}function Gr({className:e}){return jsx("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",children:jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})}function Ur({className:e}){return jsx("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",children:jsx("path",{fillRule:"evenodd",d:"M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z",clipRule:"evenodd"})})}function kt(e){let t=e.trim();if(!t)return "";let o=null,r="";for(let n of t){if((n==='"'||n==="'")&&o===null){o=n,r+=n;continue}if(n===o){o=null,r+=n;continue}if(n===","&&o===null)break;r+=n;}return r.trim().replace(/^['"]|['"]$/g,"")}var Zr=[{name:"Arial",fontFamily:"Arial, Helvetica, sans-serif",category:"sans-serif"},{name:"Calibri",fontFamily:'"Calibri", Arial, sans-serif',category:"sans-serif"},{name:"Helvetica",fontFamily:"Helvetica, Arial, sans-serif",category:"sans-serif"},{name:"Verdana",fontFamily:"Verdana, Geneva, sans-serif",category:"sans-serif"},{name:"Open Sans",fontFamily:'"Open Sans", sans-serif',category:"sans-serif"},{name:"Roboto",fontFamily:"Roboto, sans-serif",category:"sans-serif"},{name:"Times New Roman",fontFamily:'"Times New Roman", Times, serif',category:"serif"},{name:"Georgia",fontFamily:"Georgia, serif",category:"serif"},{name:"Cambria",fontFamily:"Cambria, Georgia, serif",category:"serif"},{name:"Garamond",fontFamily:"Garamond, serif",category:"serif"},{name:"Courier New",fontFamily:'"Courier New", Courier, monospace',category:"monospace"},{name:"Consolas",fontFamily:"Consolas, monospace",category:"monospace"}];function so({value:e,onChange:t,fonts:o=Zr,disabled:r=false,className:n,placeholder:s="Arial",width:i=120,showPreview:c=true}){let{t:d}=b$1(),a=j.useMemo(()=>e?o.find(u=>u.fontFamily===e||u.name.toLowerCase()===e.toLowerCase()||kt(u.fontFamily).toLowerCase()===e.toLowerCase())?.name||e:s,[e,o,s]),p=j.useCallback(l=>{let u=o.find(f=>f.name===l);u&&t?.(kt(u.fontFamily)||u.name);},[t,o]),m=j.useMemo(()=>{let l={"sans-serif":[],serif:[],monospace:[],other:[]};return o.forEach(u=>{let f=u.category||"other";l[f].push(u);}),l},[o]);return jsxs(we,{value:a,onValueChange:p,disabled:r,children:[jsx(Te,{className:P("h-8 text-sm",n),style:{minWidth:typeof i=="number"?`${i}px`:i},"aria-label":d("font.selectAriaLabel"),children:jsx(pt,{placeholder:s,children:a})}),jsxs(ke,{className:"max-h-[300px]",children:[m["sans-serif"].length>0&&jsxs(Be,{children:[jsx($e,{children:d("font.sansSerif")}),m["sans-serif"].map(l=>jsx(ie,{value:l.name,style:c?{fontFamily:l.fontFamily}:void 0,children:l.name},l.name))]}),m.serif.length>0&&jsxs(Fragment,{children:[jsx(Ge,{}),jsxs(Be,{children:[jsx($e,{children:d("font.serif")}),m.serif.map(l=>jsx(ie,{value:l.name,style:c?{fontFamily:l.fontFamily}:void 0,children:l.name},l.name))]})]}),m.monospace.length>0&&jsxs(Fragment,{children:[jsx(Ge,{}),jsxs(Be,{children:[jsx($e,{children:d("font.monospace")}),m.monospace.map(l=>jsx(ie,{value:l.name,style:c?{fontFamily:l.fontFamily}:void 0,children:l.name},l.name))]})]}),m.other.length>0&&jsxs(Fragment,{children:[jsx(Ge,{}),jsx(Be,{children:m.other.map(l=>jsx(ie,{value:l.name,style:c?{fontFamily:l.fontFamily}:void 0,children:l.name},l.name))})]})]})]})}var Qr=[{name:"Dark Red",nameKey:"colorPicker.colors.darkRed",hex:"C00000"},{name:"Red",nameKey:"colorPicker.colors.red",hex:"FF0000"},{name:"Orange",nameKey:"colorPicker.colors.orange",hex:"FFC000"},{name:"Yellow",nameKey:"colorPicker.colors.yellow",hex:"FFFF00"},{name:"Light Green",nameKey:"colorPicker.colors.lightGreen",hex:"92D050"},{name:"Green",nameKey:"colorPicker.colors.green",hex:"00B050"},{name:"Light Blue",nameKey:"colorPicker.colors.lightBlue",hex:"00B0F0"},{name:"Blue",nameKey:"colorPicker.colors.blue",hex:"0070C0"},{name:"Dark Blue",nameKey:"colorPicker.colors.darkBlue",hex:"002060"},{name:"Purple",nameKey:"colorPicker.colors.purple",hex:"7030A0"}],mt=18,en=2,tn={position:"relative",display:"inline-block"},on={display:"flex",alignItems:"center",justifyContent:"center",width:"40px",height:"32px",padding:"2px 6px",border:"none",borderRadius:"4px",backgroundColor:"transparent",cursor:"pointer",transition:"background-color 0.1s",color:"var(--doc-text-muted)"},rn={padding:"10px",backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border-dark)",borderRadius:"6px",boxShadow:"0 4px 16px var(--doc-shadow)",width:"auto"},It={fontSize:"11px",color:"var(--doc-text-muted)",marginBottom:"4px",fontWeight:500},Lt={height:"1px",backgroundColor:"var(--doc-border)",margin:"8px 0"},po={display:"grid",gap:`${en}px`},ft={width:`${mt}px`,height:`${mt}px`,border:"1px solid var(--doc-border-input)",borderRadius:"2px",cursor:"pointer",padding:0,transition:"transform 0.1s, border-color 0.1s"},mo={...ft,transform:"scale(1.15)",borderColor:"var(--doc-text)",zIndex:1},fo={...ft,borderWidth:"2px",borderColor:"var(--doc-primary)",boxShadow:"0 0 0 1px var(--doc-primary)"},nn={display:"flex",alignItems:"center",gap:"8px",width:"100%",padding:"5px 8px",border:"1px solid var(--doc-border-dark)",borderRadius:"4px",backgroundColor:"var(--doc-surface)",cursor:"pointer",fontSize:"12px",color:"var(--doc-text)"},an={display:"flex",alignItems:"center",gap:"6px"},ln={width:"70px",height:"24px",padding:"2px 6px",border:"1px solid var(--doc-border-input)",borderRadius:"3px",fontSize:"12px"},sn={height:"24px",padding:"0 10px",border:"1px solid var(--doc-border-input)",borderRadius:"3px",backgroundColor:"var(--doc-bg-subtle)",fontSize:"12px",cursor:"pointer"},co={width:"16px",height:"4px",borderRadius:"1px",marginTop:"-2px"},cn={display:"inline-flex",alignItems:"stretch",height:"32px",gap:"2px"},dn={display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:0,width:"28px",padding:"2px 4px",border:"none",borderRadius:"4px",backgroundColor:"transparent",cursor:"pointer",transition:"background-color 0.1s",color:"var(--doc-text-muted)"},un={display:"flex",alignItems:"center",justifyContent:"center",width:"18px",padding:0,border:"none",borderRadius:"4px",backgroundColor:"transparent",cursor:"pointer",transition:"background-color 0.1s",color:"var(--doc-text-muted)"};function Rt(e,t,o){if(!e)return t==="text"||t==="border"?"#000000":"transparent";if(typeof e=="string"){if(t==="highlight"){let r=resolveHighlightColor(e);return r||(e==="none"?"transparent":e.startsWith("#")?e:`#${e}`)}return e.startsWith("#")?e:`#${e}`}return resolveColor(e,o)}function uo(e){let t=e.replace(/^#/,"");if(t.length!==6)return false;let o=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),n=parseInt(t.slice(4,6),16);return (o*299+r*587+n*114)/1e3>230}function go(e,t,o){return e?(typeof e=="string"?e.replace(/^#/,"").toUpperCase():resolveColorToHex(e,o))===t.toUpperCase():false}function pn({matrix:e,selectedColor:t,theme:o,onSelect:r}){let[n,s]=useState(null);return jsx("div",{style:{...po,gridTemplateColumns:`repeat(10, ${mt}px)`},children:e.flatMap((i,c)=>i.map((d,a)=>{let p=`${c}-${a}`,m=n===p,l=go(t,d.hex,o);return jsx("button",{type:"button",style:{...l?fo:m?mo:ft,backgroundColor:`#${d.hex}`},title:d.label,"aria-label":d.label,"aria-selected":l,onClick:()=>r(d),onMouseDown:u=>u.preventDefault(),onMouseEnter:()=>s(p),onMouseLeave:()=>s(null)},p)}))})}function mn({selectedColor:e,theme:t,onSelect:o}){let[r,n]=useState(null),{t:s}=b$1();return jsx("div",{style:{...po,gridTemplateColumns:`repeat(10, ${mt}px)`},children:Qr.map((i,c)=>{let d=r===c,a=go(e,i.hex,t),p=s(i.nameKey);return jsx("button",{type:"button",style:{...a?fo:d?mo:ft,backgroundColor:`#${i.hex}`},title:p,"aria-label":p,"aria-selected":a,onClick:()=>o(i.hex),onMouseDown:m=>m.preventDefault(),onMouseEnter:()=>n(c),onMouseLeave:()=>n(null)},i.hex)})})}function Fe({mode:e,value:t,onChange:o,theme:r,disabled:n=false,className:s,style:i,title:c$1,icon:d,autoLabel:a,splitButton:p=true,defaultColor:m}){let[l,u]=useState(false),[f,g]=useState(false),[x,b$2]=useState(false),[h,v]=useState(false),[C,w]=useState(""),[L,J]=useState(()=>m??(e==="highlight"?"FFFF00":e==="border"?{rgb:"000000"}:{rgb:"FF0000"})),{t:O}=b$1();useEffect(()=>{let T=Rt(t,e,r).replace(/^#/,"");/^[0-9A-Fa-f]{6}$/.test(T)&&w(T.toUpperCase());},[t,e,r]);let Y=useCallback(()=>u(false),[]),{containerRef:de,dropdownRef:be,dropdownStyle:G}=c({isOpen:l,onClose:Y}),R=r?.colorScheme??null,M=useMemo(()=>generateThemeTintShadeMatrix(R),[R]),_=useMemo(()=>Rt(t,e,r),[t,e,r]),ue=useMemo(()=>Rt(L,e,r),[L,e,r]),he=useCallback(()=>{n||u(T=>!T);},[n]),xe=useCallback(T=>{let V;if(e==="highlight")V=T.hex;else {let ye={themeColor:T.themeSlot,rgb:T.hex};T.tint&&(ye.themeTint=T.tint),T.shade&&(ye.themeShade=T.shade),V=ye;}J(V),o?.(V),u(false);},[e,o]),ve=useCallback(T=>{let V=e==="highlight"?T:{rgb:T};J(V),o?.(V),u(false);},[e,o]),oe=useCallback(()=>{o?.(e==="highlight"?"none":{auto:true}),u(false);},[e,o]),Ae=useCallback(()=>{let T=C.replace(/^#/,"").toUpperCase();if(/^[0-9A-F]{6}$/i.test(T)){let V=e==="highlight"?T:{rgb:T};J(V),o?.(V),u(false),w("");}},[e,C,o]),z=useCallback(()=>{n||o?.(L);},[n,L,o]),Xe={...on,...n?{cursor:"default",opacity:.38}:l?{backgroundColor:"var(--doc-primary-light)",color:"var(--doc-primary)"}:f?{backgroundColor:"var(--doc-bg-hover)"}:{}},re=O(e==="text"?"formattingBar.fontColor":e==="highlight"?"formattingBar.highlightColor":"table.borderColor"),We=d??(e==="text"?"format_color_text":e==="highlight"?"ink_highlighter":"border_color");return jsxs("div",{ref:de,className:`docx-color-picker ${s||""}`,style:{...tn,...i},children:[p?jsxs("div",{className:"docx-color-picker-split",style:{...cn,...n?{opacity:.38,cursor:"default"}:null},children:[jsxs("button",{type:"button",className:"docx-color-picker-apply",style:{...dn,...n?{cursor:"default"}:x?{backgroundColor:"var(--doc-bg-hover)"}:null},onClick:z,onMouseDown:T=>T.preventDefault(),onMouseEnter:()=>b$2(true),onMouseLeave:()=>b$2(false),disabled:n,title:c$1||re,"aria-label":c$1||re,children:[jsx(b,{name:We,size:18}),jsx("div",{style:{...co,backgroundColor:ue==="transparent"?"#fff":ue,outline:ue==="transparent"||uo(ue)?"1px solid #bbb":"none"}})]}),jsx("button",{type:"button",className:"docx-color-picker-arrow",style:{...un,...n?{cursor:"default"}:l?{backgroundColor:"var(--doc-primary-light)",color:"var(--doc-primary)"}:h?{backgroundColor:"var(--doc-bg-hover)"}:null},onClick:he,onMouseDown:T=>T.preventDefault(),onMouseEnter:()=>v(true),onMouseLeave:()=>v(false),disabled:n,title:c$1||re,"aria-label":c$1||re,"aria-haspopup":"true","aria-expanded":l,children:jsx(b,{name:"arrow_drop_down",size:18})})]}):jsxs("button",{type:"button",className:"docx-color-picker-button",style:Xe,onClick:he,onMouseDown:T=>T.preventDefault(),onMouseEnter:()=>g(true),onMouseLeave:()=>g(false),disabled:n,title:c$1||re,"aria-label":c$1||re,"aria-haspopup":"true","aria-expanded":l,children:[jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:0},children:[jsx(b,{name:We,size:18}),jsx("div",{style:{...co,backgroundColor:_==="transparent"?"#fff":_,outline:_==="transparent"||uo(_)?"1px solid #bbb":"none"}})]}),jsx(b,{name:"arrow_drop_down",size:14})]}),l&&jsx("div",{ref:be,className:"docx-color-picker-dropdown",style:{...G,...rn},role:"dialog","aria-label":`${re} picker`,onMouseDown:T=>{T.target.tagName!=="INPUT"&&T.preventDefault();},children:jsxs(Fragment,{children:[jsxs("button",{type:"button",style:nn,onClick:oe,onMouseDown:T=>T.preventDefault(),children:[e==="highlight"?jsx("span",{style:{display:"inline-block",width:"16px",height:"16px",border:"1px solid #ccc",borderRadius:"2px",position:"relative",backgroundColor:"#fff"},children:jsx("span",{style:{position:"absolute",top:"50%",left:"-1px",right:"-1px",height:"2px",backgroundColor:"#ff0000",transform:"rotate(-45deg)"}})}):jsx("span",{style:{display:"inline-block",width:"16px",height:"16px",backgroundColor:"#000",borderRadius:"2px"}}),a??O(e==="highlight"?"colorPicker.noColor":"colorPicker.automatic")]}),jsx("div",{style:Lt}),jsx("div",{style:It,children:O("colorPicker.themeColors")}),jsx(pn,{matrix:M,selectedColor:t,theme:r,onSelect:xe}),jsx("div",{style:Lt}),jsx("div",{style:It,children:O("colorPicker.standardColors")}),jsx(mn,{selectedColor:t,theme:r,onSelect:ve}),jsx("div",{style:Lt}),jsx("div",{style:It,children:O("colorPicker.customColor")}),jsxs("div",{style:an,children:[jsx("span",{style:{fontSize:"12px",color:"var(--doc-text-muted)"},children:"#"}),jsx("input",{type:"text",style:ln,value:C,onChange:T=>w(T.target.value.replace(/[^0-9A-Fa-f]/g,"").slice(0,6)),onKeyDown:T=>{T.key==="Enter"&&Ae();},onMouseDown:T=>{T.stopPropagation();},placeholder:"FF0000",maxLength:6,"aria-label":"Custom hex color"}),jsx("button",{type:"button",style:{...sn,opacity:/^[0-9A-Fa-f]{6}$/.test(C)?1:.4,cursor:/^[0-9A-Fa-f]{6}$/.test(C)?"pointer":"default"},onClick:Ae,onMouseDown:T=>T.preventDefault(),disabled:!/^[0-9A-Fa-f]{6}$/.test(C),children:O("common.apply")})]})]})})]})}function ee({content:e,children:t,side:o="bottom",delayMs:r=400}){let[n,s]=j.useState(false),[i,c]=j.useState({x:0,y:0}),d=j.useRef(null),a=j.useRef(null),p=j.useCallback(()=>{a.current=setTimeout(()=>{if(d.current){let f=d.current.getBoundingClientRect(),g=f.left+f.width/2,x=o==="top"?f.top-8:f.bottom+8;c({x:g,y:x});}s(true);},r);},[r,o]),m=j.useCallback(()=>{a.current&&(clearTimeout(a.current),a.current=null),s(false);},[]);j.useEffect(()=>()=>{a.current&&clearTimeout(a.current);},[]);let l=t.props,u=j.cloneElement(t,{ref:d,onMouseEnter:f=>{p(),l.onMouseEnter?.(f);},onMouseLeave:f=>{m(),l.onMouseLeave?.(f);}});return jsxs(Fragment,{children:[u,n&&jsx("div",{className:"fixed z-50 px-2 py-1 text-xs font-medium text-white bg-foreground dark:bg-muted dark:text-foreground rounded-md shadow-lg",style:{left:i.x,top:i.y,transform:o==="top"?"translate(-50%, -100%)":o==="bottom"?"translate(-50%, 0)":void 0},children:e})]})}var Qe=20,Et=[{value:"left",label:"Align Left",labelKey:"alignment.alignLeft",shortcutKey:"alignment.alignLeftShortcut",icon:jsx(b,{name:"format_align_left",size:Qe}),iconName:"format_align_left",shortcut:"Ctrl+L"},{value:"center",label:"Center",labelKey:"alignment.center",shortcutKey:"alignment.centerShortcut",icon:jsx(b,{name:"format_align_center",size:Qe}),iconName:"format_align_center",shortcut:"Ctrl+E"},{value:"right",label:"Align Right",labelKey:"alignment.alignRight",shortcutKey:"alignment.alignRightShortcut",icon:jsx(b,{name:"format_align_right",size:Qe}),iconName:"format_align_right",shortcut:"Ctrl+R"},{value:"both",label:"Justify",labelKey:"alignment.justify",shortcutKey:"alignment.justifyShortcut",icon:jsx(b,{name:"format_align_justify",size:Qe}),iconName:"format_align_justify",shortcut:"Ctrl+J"}];function xo({value:e="left",onChange:t,disabled:o=false}){let{t:r}=b$1(),[n,s]=useState(false),i=useCallback(()=>s(false),[]),{containerRef:c$1,dropdownRef:d,dropdownStyle:a,handleMouseDown:p}=c({isOpen:n,onClose:i}),m=useCallback(b=>{o||t?.(b),s(false);},[o,t]),l=Et.find(b=>b.value===e)||Et[0],u=r(l.labelKey),f=l.shortcutKey?r(l.shortcutKey):void 0,g=`${u}${f?` (${f})`:""}`,x=jsxs(K,{variant:"ghost",size:"icon-sm",className:P("text-muted-foreground hover:text-foreground hover:bg-muted/80",n&&"bg-muted",o&&"opacity-30 cursor-not-allowed"),onMouseDown:p,onClick:()=>!o&&s(b=>!b),disabled:o,"aria-label":g,"aria-expanded":n,"aria-haspopup":"true","data-testid":"toolbar-alignment",children:[jsx(b,{name:l.iconName,size:Qe}),jsx(b,{name:"arrow_drop_down",size:14,className:"-ml-1"})]});return jsxs("div",{ref:c$1,style:{position:"relative",display:"inline-block"},children:[n?x:jsx(ee,{content:g,children:x}),n&&!o&&jsx("div",{ref:d,style:{...a,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:8,boxShadow:"0 4px 16px var(--doc-shadow)",padding:6},onMouseDown:b=>b.stopPropagation(),children:jsx("div",{style:{display:"flex",gap:2},children:Et.map(b$1=>{let h=e===b$1.value,v=r(b$1.labelKey),C=b$1.shortcutKey?r(b$1.shortcutKey):void 0;return jsx("button",{type:"button",title:`${v}${C?` (${C})`:""}`,"data-testid":`alignment-${b$1.value}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,border:"1px solid transparent",borderRadius:4,backgroundColor:h?"var(--doc-primary-light)":"transparent",cursor:"pointer",color:h?"var(--doc-primary)":"var(--doc-text)"},onMouseDown:w=>w.preventDefault(),onMouseEnter:w=>{h||(w.currentTarget.style.backgroundColor="var(--doc-bg-hover)");},onMouseLeave:w=>{w.currentTarget.style.backgroundColor=h?"var(--doc-primary-light)":"transparent";},onClick:()=>m(b$1.value),children:jsx(b,{name:b$1.iconName,size:18})},b$1.value)})})})]})}var vn=[{label:"Single",labelKey:"lineSpacing.single",value:1,twipsValue:240},{label:"1.15",value:1.15,twipsValue:276},{label:"1.5",value:1.5,twipsValue:360},{label:"Double",labelKey:"lineSpacing.double",value:2,twipsValue:480}];function yo({value:e,onChange:t,options:o=vn,disabled:r=false,className:n}){let{t:s}=b$1(),i=j.useMemo(()=>e===void 0?o[0]:o.find(a=>a.twipsValue===e)||o[0],[e,o]),c=j.useCallback(a=>{let p=parseInt(a,10);isNaN(p)||t?.(p);},[t]),d=a=>a.labelKey?s(a.labelKey):a.label;return jsxs(we,{value:i.twipsValue.toString(),onValueChange:c,disabled:r,children:[jsx(Te,{className:P("h-8 text-sm gap-0.5 px-2",n),style:{width:"auto"},title:s("lineSpacing.lineSpacingTitle",{label:d(i)}),children:jsx(a,{className:"h-5 w-5 shrink-0"})}),jsxs(ke,{children:[o.map(a=>jsx(ie,{value:a.twipsValue.toString(),children:d(a)},a.twipsValue)),jsx(Ge,{}),jsx(Be,{children:jsx($e,{children:s("lineSpacing.paragraphSpacing")})})]})]})}var Co=[{styleId:"Normal",name:"Normal text",nameKey:"styles.normalText",type:"paragraph",isDefault:true,priority:0,qFormat:true,fontSize:22},{styleId:"Title",name:"Title",nameKey:"styles.title",type:"paragraph",priority:1,qFormat:true,fontSize:52,bold:true},{styleId:"Subtitle",name:"Subtitle",nameKey:"styles.subtitle",type:"paragraph",priority:2,qFormat:true,fontSize:30,color:"666666"},{styleId:"Heading1",name:"Heading 1",nameKey:"styles.heading1",type:"paragraph",priority:3,qFormat:true,fontSize:40,bold:true},{styleId:"Heading2",name:"Heading 2",nameKey:"styles.heading2",type:"paragraph",priority:4,qFormat:true,fontSize:32,bold:true},{styleId:"Heading3",name:"Heading 3",nameKey:"styles.heading3",type:"paragraph",priority:5,qFormat:true,fontSize:28,bold:true}];function So({value:e,onChange:t,styles:o,disabled:r=false,className:n,width:s=120}){let{t:i}=b$1(),c=j.useMemo(()=>{let u=resolveParagraphStyleOptions(o);return u.length===0?Co:u.map(f=>({...f,type:"paragraph",nameKey:Co.find(g=>g.styleId===f.styleId)?.nameKey}))},[o]),d=j.useCallback(u=>{t?.(u);},[t]),a=u=>u.nameKey?i(u.nameKey):u.name,p=e||"Normal",m=c.find(u=>u.styleId===p),l=m?a(m):p;return jsxs(we,{value:p,onValueChange:d,disabled:r,children:[jsx(Te,{className:P("h-8 text-sm",n),style:{width:typeof s=="number"?`${s}px`:s},"aria-label":i("styles.selectAriaLabel"),children:jsx("span",{className:"truncate",children:l})}),jsx(ke,{className:"min-w-[260px] max-h-[400px]",children:c.map(u=>jsx(ie,{value:u.styleId,className:"py-2.5 px-3",children:jsx("span",{style:getStylePreviewProps(u),children:a(u)})},u.styleId))})]})}var wn=[{value:.5,label:"50%"},{value:.75,label:"75%"},{value:1,label:"100%"},{value:1.25,label:"125%"},{value:1.5,label:"150%"},{value:2,label:"200%"}];function To({value:e=1,onChange:t,levels:o=wn,disabled:r=false,className:n,compact:s=false}){let{t:i}=b$1(),c=j.useMemo(()=>{let u=o.find(f=>Math.abs(f.value-e)<.001);return u?u.label:`${Math.round(e*100)}%`},[o,e]),d=j.useCallback(u=>{let f=parseFloat(u);isNaN(f)||t?.(f);},[t]),a=j.useMemo(()=>[...o].sort((u,f)=>u.value-f.value),[o]),p=j.useMemo(()=>[...a].reverse().find(u=>u.value<e-.001),[a,e]),m=j.useMemo(()=>a.find(u=>u.value>e+.001),[a,e]),l=s?"h-7 w-7":"h-8 w-8";return jsxs("div",{className:"flex items-center",children:[jsx(K,{variant:"ghost",size:"icon-sm",className:P(l,"text-muted-foreground hover:text-foreground hover:bg-muted/80 rounded-r-none",(r||!p)&&"opacity-30 cursor-not-allowed"),onClick:()=>p&&t?.(p.value),disabled:r||!p,"aria-label":i("zoom.zoomOut"),children:jsx(b,{name:"remove",size:18})}),jsxs(we,{value:e.toString(),onValueChange:d,disabled:r,children:[jsx(Te,{className:P(s?"h-7 min-w-[55px] text-xs":"h-8 min-w-[64px] text-sm","rounded-none",n),"aria-label":i("zoom.ariaLabel",{label:c}),children:jsx(pt,{placeholder:"100%",children:c})}),jsx(ke,{children:o.map(u=>jsx(ie,{value:u.value.toString(),children:u.label},u.value))})]}),jsx(K,{variant:"ghost",size:"icon-sm",className:P(l,"text-muted-foreground hover:text-foreground hover:bg-muted/80 rounded-l-none",(r||!m)&&"opacity-30 cursor-not-allowed"),onClick:()=>m&&t?.(m.value),disabled:r||!m,"aria-label":i("zoom.zoomIn"),children:jsx(b,{name:"add",size:18})})]})}var kn=[{action:"borderAll",icon:"border_all",labelKey:"table.borders.all"},{action:"borderOutside",icon:"border_outer",labelKey:"table.borders.outside"},{action:"borderInside",icon:"border_inner",labelKey:"table.borders.inside"},{action:"borderTop",icon:"border_top",labelKey:"table.borders.top"},{action:"borderBottom",icon:"border_bottom",labelKey:"table.borders.bottom"},{action:"borderLeft",icon:"border_left",labelKey:"table.borders.left"},{action:"borderRight",icon:"border_right",labelKey:"table.borders.right"},{action:"borderNone",icon:"border_clear",labelKey:"table.borders.none"}];function Mo({onAction:e,disabled:t=false}){let{t:o}=b$1(),[r,n]=useState(false),s=useCallback(()=>n(false),[]),{containerRef:i,dropdownRef:c$1,dropdownStyle:d,handleMouseDown:a}=c({isOpen:r,onClose:s}),p=useCallback(l=>{e(l),n(false);},[e]),m=jsxs(K,{variant:"ghost",size:"icon-sm",className:P("text-muted-foreground hover:text-foreground hover:bg-muted/80",r&&"bg-muted",t&&"opacity-30 cursor-not-allowed"),onMouseDown:a,onClick:()=>!t&&n(l=>!l),disabled:t,"aria-label":o("table.borders.styleAriaLabel"),"aria-expanded":r,"aria-haspopup":"true","data-testid":"toolbar-table-borders",children:[jsx(b,{name:"border_all",size:20}),jsx(b,{name:"arrow_drop_down",size:14,className:"-ml-1"})]});return jsxs("div",{ref:i,style:{position:"relative",display:"inline-block"},children:[r?m:jsx(ee,{content:o("table.borders.tooltip"),children:m}),r&&!t&&jsx("div",{ref:c$1,style:{...d,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:8,boxShadow:"0 4px 16px var(--doc-shadow)",padding:6},onMouseDown:l=>l.stopPropagation(),children:jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:2},children:kn.map(({action:l,icon:u,labelKey:f})=>jsx("button",{type:"button",title:o(f),style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,border:"1px solid transparent",borderRadius:4,backgroundColor:"transparent",cursor:"pointer",color:"var(--doc-text)"},onMouseDown:g=>g.preventDefault(),onMouseEnter:g=>{g.currentTarget.style.backgroundColor="var(--doc-bg-hover)";},onMouseLeave:g=>{g.currentTarget.style.backgroundColor="transparent";},onClick:()=>p(l),children:jsx(b,{name:u,size:18})},typeof l=="string"?l:l.type))})})]})}function Io({onAction:e,disabled:t=false,theme:o,value:r}){let{t:n}=b$1(),s=useCallback(i=>{typeof i=="string"?e({type:"borderColor",color:i.replace(/^#/,"")}):i.rgb?e({type:"borderColor",color:i.rgb.replace(/^#/,"")}):i.auto&&e({type:"borderColor",color:"000000"});},[e]);return jsx(Fe,{mode:"border",value:r,onChange:s,theme:o,disabled:t,title:n("table.borderColor")})}var Ln=[{size:4,label:"0.5 pt",thickness:.5},{size:8,label:"1 pt",thickness:1},{size:12,label:"1.5 pt",thickness:1.5},{size:16,label:"2 pt",thickness:2},{size:24,label:"3 pt",thickness:3}];function Ro({onAction:e,disabled:t=false}){let[o,r]=useState(false),{t:n}=b$1(),s=useCallback(()=>r(false),[]),{containerRef:i,dropdownRef:c$1,dropdownStyle:d,handleMouseDown:a}=c({isOpen:o,onClose:s}),p=useCallback(l=>{e({type:"borderWidth",size:l}),r(false);},[e]),m=jsxs(K,{variant:"ghost",size:"icon-sm",className:P("text-muted-foreground hover:text-foreground hover:bg-muted/80",o&&"bg-muted",t&&"opacity-30 cursor-not-allowed"),onMouseDown:a,onClick:()=>!t&&r(l=>!l),disabled:t,"aria-label":n("table.borderWidth"),"aria-expanded":o,"aria-haspopup":"true","data-testid":"toolbar-table-border-width",children:[jsx(b,{name:"line_weight",size:20}),jsx(b,{name:"arrow_drop_down",size:14,className:"-ml-1"})]});return jsxs("div",{ref:i,style:{position:"relative",display:"inline-block"},children:[o?m:jsx(ee,{content:n("table.borderWidth"),children:m}),o&&!t&&jsx("div",{ref:c$1,style:{...d,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:8,boxShadow:"0 4px 16px var(--doc-shadow)",padding:"4px 0",minWidth:120},onMouseDown:l=>l.stopPropagation(),children:Ln.map(({size:l,label:u,thickness:f})=>jsxs("button",{type:"button",style:{display:"flex",alignItems:"center",gap:10,padding:"6px 12px",width:"100%",border:"none",backgroundColor:"transparent",cursor:"pointer",fontSize:12,color:"var(--doc-text)"},onMouseDown:g=>g.preventDefault(),onMouseEnter:g=>{g.currentTarget.style.backgroundColor="var(--doc-bg-hover)";},onMouseLeave:g=>{g.currentTarget.style.backgroundColor="transparent";},onClick:()=>p(l),children:[jsx("div",{style:{width:50,height:Math.max(f,1),backgroundColor:"#000",borderRadius:f>2?1:0}}),jsx("span",{children:u})]},l))})]})}function Eo({onAction:e,disabled:t=false,theme:o,value:r}){let{t:n}=b$1(),s=useCallback(i=>{typeof i=="string"&&e(i==="none"?{type:"cellFillColor",color:null}:{type:"cellFillColor",color:i.replace(/^#/,"")});},[e]);return jsx(Fe,{mode:"highlight",value:r,onChange:s,theme:o,disabled:t,title:n("table.cellFillColor"),icon:"format_color_fill",autoLabel:n("colorPicker.noColor")})}var An={display:"flex",alignItems:"center",gap:10,padding:"7px 14px",fontSize:13,color:"var(--doc-text)",cursor:"pointer",border:"none",backgroundColor:"transparent",width:"100%",textAlign:"left"},qe={height:1,backgroundColor:"var(--doc-border)",margin:"4px 0"},Do={padding:"6px 14px 2px",fontSize:11,color:"var(--doc-text-muted)",fontWeight:500};function Bo({onAction:e,disabled:t=false,tableContext:o}){let{t:r}=b$1(),[n,s]=useState(false),[i,c$1]=useState(null),d=useCallback(()=>s(false),[]),{containerRef:a,dropdownRef:p,dropdownStyle:m,handleMouseDown:l}=c({isOpen:n,onClose:d,align:"right"}),u=o?.table?.attrs?.justification??"left",f=useCallback(b=>{e(b),s(false);},[e]),g=(b$1,h,v,C,w)=>{let L=t||w?.itemDisabled;return jsxs("button",{type:"button",role:"menuitem",style:{...An,backgroundColor:i===b$1&&!L?"var(--doc-bg-hover)":"transparent",color:L?"var(--doc-text-muted)":w?.danger?"var(--doc-error)":"var(--doc-text)",cursor:L?"not-allowed":"pointer"},onClick:()=>!L&&f(C),onMouseEnter:()=>c$1(b$1),onMouseLeave:()=>c$1(null),disabled:L,children:[jsx(b,{name:h,size:16,className:w?.danger&&!L?"text-destructive":""}),jsx("span",{style:{flex:1},children:v})]},b$1)},x=jsx(K,{variant:"ghost",size:"icon-sm",className:P("text-muted-foreground hover:text-foreground hover:bg-muted/80",n&&"bg-muted",t&&"opacity-30 cursor-not-allowed"),onMouseDown:l,onClick:()=>!t&&s(b=>!b),disabled:t,"aria-label":r("table.moreOptions"),"aria-expanded":n,"aria-haspopup":"menu","data-testid":"toolbar-table-more",children:jsx(b,{name:"more_vert",size:20})});return jsxs("div",{ref:a,style:{position:"relative",display:"inline-block"},children:[n?x:jsx(ee,{content:r("table.moreOptions"),children:x}),n&&!t&&jsxs("div",{ref:p,style:{...m,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:8,boxShadow:"0 4px 16px var(--doc-shadow)",padding:"4px 0",minWidth:200,maxHeight:"70vh",overflowY:"auto"},role:"menu",onMouseDown:b=>b.stopPropagation(),children:[g("addRowAbove","add",r("table.insertRowAbove"),"addRowAbove"),g("addRowBelow","add",r("table.insertRowBelow"),"addRowBelow"),g("addColumnLeft","add",r("table.insertColumnLeft"),"addColumnLeft"),g("addColumnRight","add",r("table.insertColumnRight"),"addColumnRight"),jsx("div",{style:qe,role:"separator"}),g("mergeCells","call_merge",r("table.mergeCells"),"mergeCells",{itemDisabled:!o?.hasMultiCellSelection}),g("splitCell","call_split",r("table.splitCell"),"splitCell",{itemDisabled:!o?.canSplitCell}),jsx("div",{style:qe,role:"separator"}),g("deleteRow","delete",r("table.deleteRow"),"deleteRow",{danger:true,itemDisabled:(o?.rowCount??0)<=1}),g("deleteColumn","delete",r("table.deleteColumn"),"deleteColumn",{danger:true,itemDisabled:(o?.columnCount??0)<=1}),g("deleteTable","delete",r("table.deleteTable"),"deleteTable",{danger:true}),jsx("div",{style:qe,role:"separator"}),jsx("div",{style:Do,children:r("tableAdvanced.verticalAlignment")}),jsx("div",{style:{display:"flex",gap:4,padding:"4px 14px"},children:["top","center","bottom"].map(b$1=>{let h={top:"vertical_align_top",center:"vertical_align_center",bottom:"vertical_align_bottom"};return jsx("button",{type:"button",title:r({top:"tableAdvanced.top",center:"tableAdvanced.middle",bottom:"tableAdvanced.bottom"}[b$1]),style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,border:"1px solid var(--doc-border)",borderRadius:4,backgroundColor:"transparent",cursor:"pointer"},onMouseDown:C=>C.preventDefault(),onMouseEnter:C=>{C.currentTarget.style.backgroundColor="var(--doc-bg-hover)";},onMouseLeave:C=>{C.currentTarget.style.backgroundColor="transparent";},onClick:()=>f({type:"cellVerticalAlign",align:b$1}),children:jsx(b,{name:h[b$1],size:16})},b$1)})}),jsx("div",{style:qe,role:"separator"}),jsx("div",{style:Do,children:r("tableAdvanced.tableAlignment")}),jsx("div",{style:{display:"flex",gap:4,padding:"4px 14px"},children:["left","center","right"].map(b$1=>{let h={left:"format_align_left",center:"format_align_center",right:"format_align_right"},v=u===b$1;return jsx("button",{type:"button",title:r({left:"tableAdvanced.alignTableLeft",center:"tableAdvanced.alignTableCenter",right:"tableAdvanced.alignTableRight"}[b$1]),style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,border:"1px solid var(--doc-border)",borderRadius:4,backgroundColor:v?"var(--doc-primary-light)":"transparent",borderColor:v?"var(--doc-primary)":"var(--doc-border)",color:v?"var(--doc-primary)":"var(--doc-text)",cursor:"pointer"},onMouseDown:C=>C.preventDefault(),onClick:()=>f({type:"tableProperties",props:{justification:b$1}}),children:jsx(b,{name:h[b$1],size:16})},b$1)})}),jsx("div",{style:qe,role:"separator"}),g("headerRow","table_rows",r("tableAdvanced.toggleHeaderRow"),{type:"toggleHeaderRow"}),g("distribute","view_column",r("tableAdvanced.distributeColumns"),{type:"distributeColumns"}),g("autoFit","fit_width",r("tableAdvanced.autoFit"),{type:"autoFitContents"}),g("noWrap","wrap_text",r("tableAdvanced.toggleNoWrap"),{type:"toggleNoWrap"}),jsx("div",{style:qe,role:"separator"}),g("properties","settings",r("tableAdvanced.tableProperties"),{type:"openTableProperties"})]})]})}var Dn=20;function ht({options:e,activeValue:t,triggerIcon:o,tooltipContent:r,onSelect:n,disabled:s=false,ariaLabel:i,testId:c$1,showLabels:d=false}){let[a,p]=useState(false),m=useCallback(()=>p(false),[]),{containerRef:l,dropdownRef:u,dropdownStyle:f,handleMouseDown:g}=c({isOpen:a,onClose:m}),x=useCallback(h=>{s||n(h),p(false);},[s,n]),b$1=jsxs(K,{variant:"ghost",size:"icon-sm",className:P("text-muted-foreground hover:text-foreground hover:bg-muted/80",a&&"bg-muted",s&&"opacity-30 cursor-not-allowed"),onMouseDown:g,onClick:()=>!s&&p(h=>!h),disabled:s,"aria-label":i??r,"aria-expanded":a,"aria-haspopup":"true","data-testid":c$1,children:[jsx(b,{name:o,size:Dn}),jsx(b,{name:"arrow_drop_down",size:14,className:"-ml-1"})]});return jsxs("div",{ref:l,style:{position:"relative",display:"inline-block"},children:[a?b$1:jsx(ee,{content:r,children:b$1}),a&&!s&&jsx("div",{ref:u,style:{...f,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:8,boxShadow:"0 4px 16px var(--doc-shadow)",padding:6},onMouseDown:h=>h.stopPropagation(),children:jsx("div",{style:{display:"flex",flexDirection:d?"column":"row",gap:d?1:2,minWidth:d?200:void 0},children:e.map(h=>{let v=t===h.value;return jsxs("button",{type:"button",title:h.label,"data-testid":c$1?`${c$1}-${h.value}`:void 0,style:{display:"flex",alignItems:"center",height:32,border:"1px solid transparent",borderRadius:4,backgroundColor:v?"var(--doc-primary-light)":"transparent",cursor:"pointer",color:v?"var(--doc-primary)":"var(--doc-text)",...d?{width:"100%",gap:10,padding:"0 10px",justifyContent:"flex-start",fontSize:13,textAlign:"left"}:{width:32,justifyContent:"center"}},onMouseDown:C=>C.preventDefault(),onMouseEnter:C=>{v||(C.currentTarget.style.backgroundColor="var(--doc-bg-hover)");},onMouseLeave:C=>{C.currentTarget.style.backgroundColor=v?"var(--doc-primary-light)":"transparent";},onClick:()=>x(h.value),children:[jsx(b,{name:h.iconName,size:18}),d&&jsx("span",{style:{flex:1},children:h.label})]},h.value)})})})]})}var Bn=[{value:"inline",labelKey:"imageWrap.inline",iconName:"wrap_text"},{value:"wrapRight",labelKey:"imageWrap.floatLeft",iconName:"format_image_left"},{value:"wrapLeft",labelKey:"imageWrap.floatRight",iconName:"format_image_right"},{value:"behind",labelKey:"imageWrap.behindText",iconName:"flip_to_back"},{value:"inFront",labelKey:"imageWrap.inFrontOfText",iconName:"flip_to_front"}];function _n(e){return e.displayMode==="float"&&e.cssFloat==="left"?"wrapRight":e.displayMode==="float"&&e.cssFloat==="right"?"wrapLeft":e.wrapType}function Oo({imageContext:e,onChange:t,disabled:o=false}){let{t:r}=b$1(),n=Bn.map(c=>({...c,label:r(c.labelKey)})),s=_n(e),i=n.find(c=>c.value===s)||n[0];return jsx(ht,{options:n,activeValue:s,triggerIcon:i.iconName,tooltipContent:`Wrap: ${i.label}`,onSelect:t,disabled:o,testId:"toolbar-image-wrap",showLabels:true})}var On=[{value:"rotateCW",labelKey:"imageTransform.rotateClockwise",iconName:"rotate_right"},{value:"rotateCCW",labelKey:"imageTransform.rotateCounterClockwise",iconName:"rotate_left"},{value:"flipH",labelKey:"imageTransform.flipHorizontal",iconName:"swap_horiz"},{value:"flipV",labelKey:"imageTransform.flipVertical",iconName:"swap_vert"}];function zo({onTransform:e,disabled:t=false}){let{t:o}=b$1(),r=On.map(n=>({...n,label:o(n.labelKey)}));return jsx(ht,{options:r,triggerIcon:"rotate_right",tooltipContent:o("imageTransform.tooltip"),onSelect:e,disabled:t,testId:"toolbar-image-transform"})}var tt=createContext(null);function Ko(){let e=useContext(tt);if(!e)throw new Error("useEditorToolbar must be used within an <EditorToolbar> component");return e}var se=18;function ce({active:e=false,disabled:t=false,title:o,onClick:r,children:n,className:s,ariaLabel:i}){let c=i?.toLowerCase().replace(/\s+/g,"-")||o?.toLowerCase().replace(/\s+/g,"-").replace(/\([^)]*\)/g,"").trim(),d=p=>{p.preventDefault();},a=jsx(K,{variant:"ghost",size:"icon-sm",className:P("text-muted-foreground hover:text-foreground hover:bg-muted",e&&"bg-foreground text-white hover:bg-foreground hover:text-white",e&&"dark:bg-doc-primary-light dark:text-doc-primary dark:hover:bg-doc-primary-light dark:hover:text-doc-primary",t&&"opacity-30 cursor-not-allowed",s),onMouseDown:d,onClick:t?void 0:r,disabled:t,"aria-pressed":e,"aria-label":i||o,"data-testid":c?`toolbar-${c}`:void 0,children:n});return o?jsx(ee,{content:o,children:a}):a}function fe({label:e,children:t,className:o}){return jsx("div",{className:P("flex items-center gap-px px-1.5 border-r border-border/50 last:border-r-0 first:pl-0",o),role:"group","aria-label":e,children:t})}function qs(){return jsx("div",{className:"w-px h-6 bg-border mx-1.5",role:"separator"})}function Gn(e){let t=j__default.useContext(tt);return t?{...t,...Un(e)}:e}function Un(e){let t={};for(let o of Object.keys(e))e[o]!==void 0&&(t[o]=e[o]);return t}function Wo(e){let{t}=b$1(),o=Gn(e),{currentFormatting:r={},onFormat:n,onUndo:s,onRedo:i,canUndo:c=false,canRedo:d=false,disabled:a=false,className:p,style:m,enableShortcuts:l=true,editorRef:u,children:f,showFontPicker:g=true,fontFamilies:x,showFontSizePicker:b$2=true,showTextColorPicker:h=true,showHighlightColorPicker:v=true,showAlignmentButtons:C=true,showListButtons:w=true,showLineSpacingPicker:L=true,showStylePicker:J=true,documentStyles:O,theme:Y,showZoomControl:de=true,zoom:be,onZoomChange:G,onRefocusEditor:R,imageContext:M,onImageWrapType:_,onImageTransform:ue,onOpenImageProperties:he,tableContext:xe,onTableAction:ve,inline:oe=false}=o,Ae=useRef(null),z=useCallback(A=>{!a&&n&&n(A);},[a,n]),Xe=useCallback(()=>{!a&&c&&s&&s();},[a,c,s]),re=useCallback(()=>{!a&&d&&i&&i();},[a,d,i]),We=useCallback(A=>{!a&&n&&(n({type:"fontFamily",value:A}),requestAnimationFrame(()=>R?.()));},[a,n,R]),T=j__default.useMemo(()=>normalizeFontFamilies(x),[x]),V=useCallback(A=>{!a&&n&&(n({type:"fontSize",value:A}),requestAnimationFrame(()=>R?.()));},[a,n,R]),ye=useCallback(A=>{!a&&n&&(n({type:"textColor",value:A}),requestAnimationFrame(()=>R?.()));},[a,n,R]),wt=useCallback(A=>{!a&&n&&(n({type:"highlightColor",value:typeof A=="string"?A:""}),requestAnimationFrame(()=>R?.()));},[a,n,R]),E=useCallback(A=>{!a&&n&&n({type:"alignment",value:A});},[a,n]),Ne=useCallback(()=>{!a&&n&&n("bulletList");},[a,n]),nt=useCallback(()=>{!a&&n&&n("numberedList");},[a,n]),De=useCallback(()=>{!a&&n&&n("indent");},[a,n]),pe=useCallback(()=>{!a&&n&&n("outdent");},[a,n]),Q=useCallback(A=>{!a&&n&&(n({type:"lineSpacing",value:A}),requestAnimationFrame(()=>R?.()));},[a,n,R]),ne=useCallback(A=>{!a&&n&&(n({type:"applyStyle",value:A}),requestAnimationFrame(()=>R?.()));},[a,n,R]),ae=useCallback(A=>{!a&&ve&&(ve(A),requestAnimationFrame(()=>R?.()));},[a,ve,R]);useEffect(()=>{if(!l)return;let A=B=>{let je=B.target,Ut=u?.current,ar=Ae.current,ir=Ut?.contains(je),lr=ar?.contains(je);if(!ir&&!lr)return;if((B.ctrlKey||B.metaKey)&&!B.altKey)switch(B.key.toLowerCase()){case "b":B.preventDefault(),z("bold");break;case "i":B.preventDefault(),z("italic");break;case "u":B.preventDefault(),z("underline");break;case "=":B.shiftKey?(B.preventDefault(),z("superscript")):(B.preventDefault(),z("subscript"));break;case "l":B.preventDefault(),E("left");break;case "e":B.preventDefault(),E("center");break;case "r":B.preventDefault(),E("right");break;case "j":B.preventDefault(),E("both");break;case "k":B.preventDefault(),z("insertLink");break}};return document.addEventListener("keydown",A),()=>{document.removeEventListener("keydown",A);}},[l,z,E,u]);let rr=useCallback(A=>{let B=A.target;B.tagName==="INPUT"||B.tagName==="TEXTAREA"||B.tagName==="SELECT"||B.tagName==="OPTION"||A.preventDefault();},[]),nr=useCallback(A=>{let B=A.target,je=document.activeElement;B.tagName==="SELECT"||B.tagName==="OPTION"||je?.tagName==="SELECT"||requestAnimationFrame(()=>{R?.();});},[R]);return jsxs("div",{ref:Ae,className:P(!oe&&"flex items-center px-2 py-1 bg-muted rounded-full min-h-[36px] overflow-x-auto mx-2 mb-1",p),style:oe?{display:"contents",...m}:m,role:oe?void 0:"toolbar","aria-label":oe?void 0:t("toolbar.ariaLabel"),"data-testid":oe?void 0:"formatting-bar",onMouseDown:oe?void 0:rr,onMouseUp:oe?void 0:nr,children:[jsxs(fe,{label:t("formattingBar.groups.history"),children:[jsx(ce,{onClick:Xe,disabled:a||!c,title:t("formattingBar.undoShortcut"),ariaLabel:t("formattingBar.undo"),children:jsx(b,{name:"undo",size:se})}),jsx(ce,{onClick:re,disabled:a||!d,title:t("formattingBar.redoShortcut"),ariaLabel:t("formattingBar.redo"),children:jsx(b,{name:"redo",size:se})})]}),de&&jsx(fe,{label:t("formattingBar.groups.zoom"),children:jsx(To,{value:be,onChange:G,disabled:a,compact:true})}),J&&jsx(fe,{label:t("formattingBar.groups.styles"),children:jsx(So,{value:r.styleId||"Normal",onChange:ne,styles:O,theme:Y,disabled:a,width:120})}),(g||b$2)&&jsxs(fe,{label:t("formattingBar.groups.font"),children:[g&&jsx(so,{value:r.fontFamily||"Arial",onChange:We,fonts:T,disabled:a,width:60,placeholder:"Arial"}),b$2&&jsx(eo,{value:r.fontSize!==void 0?halfPointsToPoints(r.fontSize):11,onChange:V,disabled:a,width:42,placeholder:"11"})]}),jsxs(fe,{label:t("formattingBar.groups.textFormatting"),children:[jsx(ce,{onClick:()=>z("bold"),active:r.bold,disabled:a,title:t("formattingBar.boldShortcut"),ariaLabel:t("formattingBar.bold"),children:jsx(b,{name:"format_bold",size:se})}),jsx(ce,{onClick:()=>z("italic"),active:r.italic,disabled:a,title:t("formattingBar.italicShortcut"),ariaLabel:t("formattingBar.italic"),children:jsx(b,{name:"format_italic",size:se})}),jsx(ce,{onClick:()=>z("underline"),active:r.underline,disabled:a,title:t("formattingBar.underlineShortcut"),ariaLabel:t("formattingBar.underline"),children:jsx(b,{name:"format_underlined",size:se})}),jsx(ce,{onClick:()=>z("strikethrough"),active:r.strike,disabled:a,title:t("formattingBar.strikethrough"),ariaLabel:t("formattingBar.strikethrough"),children:jsx(b,{name:"strikethrough_s",size:se})}),h&&jsx(Fe,{mode:"text",value:r.color?.replace(/^#/,""),onChange:ye,theme:Y,disabled:a,title:t("formattingBar.fontColor")}),v&&jsx(Fe,{mode:"highlight",value:r.highlight,onChange:wt,theme:Y,disabled:a,title:t("formattingBar.highlightColor")}),jsx(ce,{onClick:()=>z("insertLink"),disabled:a,title:t("formattingBar.insertLinkShortcut"),ariaLabel:t("formattingBar.insertLink"),children:jsx(b,{name:"link",size:se})})]}),jsxs(fe,{label:t("formattingBar.groups.script"),children:[jsx(ce,{onClick:()=>z("superscript"),active:r.superscript,disabled:a,title:t("formattingBar.superscriptShortcut"),ariaLabel:t("formattingBar.superscript"),children:jsx(b,{name:"superscript",size:se})}),jsx(ce,{onClick:()=>z("subscript"),active:r.subscript,disabled:a,title:t("formattingBar.subscriptShortcut"),ariaLabel:t("formattingBar.subscript"),children:jsx(b,{name:"subscript",size:se})})]}),C&&jsx(fe,{label:t("formattingBar.groups.alignment"),children:jsx(xo,{value:r.alignment||"left",onChange:E,disabled:a})}),(w||L)&&jsxs(fe,{label:t("formattingBar.groups.listFormatting"),children:[w&&jsx(ro,{listState:r.listState||createDefaultListState(),onBulletList:Ne,onNumberedList:nt,onIndent:De,onOutdent:pe,disabled:a,showIndentButtons:true,compact:true,hasIndent:(r.indentLeft??0)>0}),L&&jsx(yo,{value:r.lineSpacing,onChange:Q,disabled:a})]}),M&&_&&jsxs(fe,{label:t("formattingBar.groups.image"),children:[jsx(Oo,{imageContext:M,onChange:_,disabled:a}),ue&&jsx(zo,{onTransform:ue,disabled:a}),he&&jsx(ce,{onClick:he,disabled:a,title:t("formattingBar.imagePropertiesShortcut"),ariaLabel:t("formattingBar.imageProperties"),children:jsx(b,{name:"tune",size:se})})]}),xe?.isInTable&&ve&&jsxs(fe,{label:t("formattingBar.groups.table"),children:[jsx(Mo,{onAction:ae,disabled:a}),jsx(Io,{onAction:ae,disabled:a,theme:Y,value:resolveColorToHex(xe?.cellBorderColor,Y)}),jsx(Ro,{onAction:ae,disabled:a}),jsx(Eo,{onAction:ae,disabled:a,theme:Y,value:xe?.cellBackgroundColor}),jsx(Bo,{onAction:ae,disabled:a,tableContext:xe})]}),jsx(ce,{onClick:()=>z("clearFormatting"),disabled:a,title:t("formattingBar.clearFormatting"),ariaLabel:t("formattingBar.clearFormatting"),children:jsx(b,{name:"format_clear",size:se})}),f]})}function qn(e){return "type"in e&&e.type==="separator"}var Go={display:"flex",alignItems:"center",gap:2,padding:"2px 8px",border:"none",background:"transparent",borderRadius:4,cursor:"pointer",fontSize:13,fontWeight:400,color:"var(--doc-text)",whiteSpace:"nowrap",height:28,lineHeight:"28px"},Yn={...Go,background:"var(--doc-bg-hover)"},Uo={display:"flex",alignItems:"center",gap:8,padding:"6px 12px",border:"none",background:"transparent",cursor:"pointer",fontSize:13,color:"var(--doc-text)",width:"100%",textAlign:"left",whiteSpace:"nowrap"},Xn={...Uo,opacity:.4,cursor:"default"},jn={height:1,backgroundColor:"var(--doc-border)",margin:"4px 0"},Jn={marginLeft:"auto",fontSize:12,color:"var(--doc-text-muted)"},Qn={position:"absolute",left:"100%",top:-4,marginLeft:2,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:6,boxShadow:"0 4px 12px var(--doc-shadow)",padding:8,zIndex:1001};function ot({label:e,items:t,disabled:o,showChevron:r=false}){let[n,s]=useState(false),[i,c]=useState(null),d=useRef(null),a=useRef(null),[p,m]=useState({top:0,left:0}),l=useCallback(()=>{s(false),c(null);},[]);useEffect(()=>{if(!n||!d.current)return;let f=d.current.getBoundingClientRect();m({top:f.bottom+2,left:f.left});},[n]),useEffect(()=>{if(!n)return;function f(b){let h=b.target;d.current&&!d.current.contains(h)&&a.current&&!a.current.contains(h)&&l();}function g(b){b.key==="Escape"&&l();}function x(){l();}return document.addEventListener("mousedown",f),document.addEventListener("keydown",g),window.addEventListener("scroll",x,true),()=>{document.removeEventListener("mousedown",f),document.removeEventListener("keydown",g),window.removeEventListener("scroll",x,true);}},[n,l]);let u=f=>{f.disabled||f.submenuContent||f.onClick&&(f.onClick(),l());};return jsxs("div",{style:{position:"relative"},children:[jsxs("button",{ref:d,type:"button",onClick:()=>!o&&s(!n),onMouseDown:f=>f.preventDefault(),disabled:o,style:n?Yn:Go,children:[e,r&&jsx(b,{name:"arrow_drop_down",size:16})]}),n&&jsx("div",{ref:a,style:{position:"fixed",top:p.top,left:p.left,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:6,boxShadow:"0 4px 12px var(--doc-shadow)",padding:"4px 0",zIndex:1e4,minWidth:200},onMouseDown:f=>f.preventDefault(),children:t.map((f,g)=>{if(qn(f))return jsx("div",{style:jn},`sep-${g}`);let x=f;if(x.customContent)return jsx("div",{onMouseDown:v=>v.preventDefault(),children:x.customContent},x.label);let b$1=!!x.submenuContent,h=i===x.label;return jsxs("div",{style:{position:"relative"},onMouseEnter:()=>b$1&&c(x.label),onMouseLeave:()=>b$1&&c(null),children:[jsxs("button",{type:"button",style:x.disabled?Xn:Uo,onClick:()=>u(x),onMouseDown:v=>v.preventDefault(),onMouseOver:v=>{x.disabled||(v.currentTarget.style.backgroundColor="var(--doc-bg-hover)");},onMouseOut:v=>{v.currentTarget.style.backgroundColor="transparent";},disabled:x.disabled,children:[x.icon&&jsx(b,{name:x.icon,size:18}),jsx("span",{children:x.label}),x.shortcut&&jsx("span",{style:Jn,children:x.shortcut}),b$1&&jsx("span",{style:{marginLeft:"auto"},children:jsx(b,{name:"keyboard_arrow_right",size:16})})]}),b$1&&h&&jsx("div",{style:Qn,onMouseDown:v=>v.preventDefault(),children:x.submenuContent(l)})]},x.label)})})]})}var Ft=18,ta=2,qo={width:Ft,height:Ft,backgroundColor:"var(--doc-surface)",border:"1px solid var(--doc-border)",borderRadius:2,transition:"background-color 0.1s, border-color 0.1s",cursor:"pointer"},oa={...qo,backgroundColor:"var(--doc-primary)",border:"1px solid var(--doc-primary)"},ra={marginTop:6,fontSize:11,fontWeight:500,color:"var(--doc-text)",textAlign:"center"};function Yo({onInsert:e,gridRows:t=6,gridColumns:o=6}){let[r,n]=useState(0),[s,i]=useState(0),c=useCallback(()=>{r>0&&s>0&&e(r,s);},[r,s,e]),d=[];for(let p=1;p<=t;p++)for(let m=1;m<=o;m++){let l=p<=r&&m<=s;d.push(jsx("div",{style:l?oa:qo,onMouseEnter:()=>{n(p),i(m);},onClick:c,role:"gridcell","aria-selected":l},`${p}-${m}`));}let a=r>0&&s>0?`${s} \xD7 ${r}`:"Select size";return jsxs("div",{children:[jsx("div",{style:{display:"grid",gap:ta,gridTemplateColumns:`repeat(${o}, ${Ft}px)`},onMouseLeave:()=>{n(0),i(0);},role:"grid","aria-label":"Table size selector",children:d}),jsx("div",{style:ra,children:a})]})}function la({items:e,closeMenu:t}){return jsx("div",{style:{display:"flex",flexDirection:"column",minWidth:220},children:e.map(o=>{let r=!o.onClick;return jsxs("button",{type:"button",disabled:r,style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",border:"none",background:"transparent",cursor:r?"default":"pointer",fontSize:13,color:"var(--doc-text)",width:"100%",textAlign:"left",whiteSpace:"nowrap",opacity:r?.4:1},onMouseDown:n=>n.preventDefault(),onClick:()=>{r||(o.onClick?.(),t());},onMouseOver:n=>{r||(n.currentTarget.style.backgroundColor="var(--doc-bg-hover)");},onMouseOut:n=>{n.currentTarget.style.backgroundColor="transparent";},children:[jsx(b,{name:o.icon,size:18}),jsx("span",{children:o.label})]},o.label)})})}function sa(){return jsxs("svg",{width:"32",height:"40",viewBox:"0 0 32 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M2 0C0.9 0 0 0.9 0 2V38C0 39.1 0.9 40 2 40H30C31.1 40 32 39.1 32 38V10L22 0H2Z",fill:"#cbd5e1"}),jsx("path",{d:"M22 0L32 10H24C22.9 10 22 9.1 22 8V0Z",fill:"#94a3b8"}),jsx("rect",{x:"7",y:"18",width:"18",height:"2",rx:"1",fill:"#fff"}),jsx("rect",{x:"7",y:"23",width:"18",height:"2",rx:"1",fill:"#fff"}),jsx("rect",{x:"7",y:"28",width:"12",height:"2",rx:"1",fill:"#fff"})]})}function zt({children:e}){return jsx("div",{className:"flex items-center flex-shrink-0",children:e})}function ca(e){return e.replace(/\.docx$/i,"")}function jo({value:e,onChange:t,placeholder:o,editable:r=true}){let{t:n}=b$1(),s=o??n("titleBar.untitled"),i=ca(e)??"";return r?jsx("input",{type:"text",value:i,onChange:c=>{let d=c.target.value;t?.(d.endsWith(".docx")?d:d+".docx");},placeholder:s,className:"text-base font-normal text-foreground bg-transparent border-0 outline-none px-2 py-0 rounded hover:bg-muted focus:bg-doc-bg-input focus:ring-1 focus:ring-ring min-w-[100px] max-w-[300px] truncate leading-tight","aria-label":n("titleBar.documentNameAriaLabel")}):jsx("span",{className:"text-base font-normal text-foreground px-2 py-0 min-w-[100px] max-w-[300px] truncate leading-tight",children:i||s})}function Kt({children:e}){return jsx("div",{className:"flex items-center gap-2 ml-auto flex-shrink-0",children:e})}function Ht(){let{t:e}=b$1(),t=Ko(),{disabled:o=false,onFormat:r,onPrint:n,onOpen:s,onSave:i,onPageSetup:c,onInsertImage:d,onInsertTable:a,showTableInsert:p=true,onInsertPageBreak:m,onInsertSectionBreakNextPage:l,onInsertSectionBreakContinuous:u,onInsertTOC:f,onWatermark:g,onRefocusEditor:x}=t,b=useCallback(w=>{!o&&r&&r(w);},[o,r]),h=useCallback((w,L)=>{!o&&a&&(a(w,L),requestAnimationFrame(()=>x?.()));},[o,a,x]),v=!!n||!!c,C=v||s||i;return jsxs("div",{className:"flex items-center",role:"menubar","aria-label":e("titleBar.menuBarAriaLabel"),children:[C&&jsx(ot,{label:e("toolbar.file"),disabled:o,items:[...s?[{icon:"file_upload",label:e("toolbar.open"),shortcut:e("toolbar.openShortcut"),onClick:s}]:[],...i?[{icon:"file_download",label:e("toolbar.save"),shortcut:e("toolbar.saveShortcut"),onClick:i}]:[],...(s||i)&&v?[{type:"separator"}]:[],...n?[{icon:"print",label:e("toolbar.print"),shortcut:e("toolbar.printShortcut"),onClick:n}]:[],...c?[{icon:"settings",label:e("toolbar.pageSetup"),onClick:c}]:[]]}),jsx(ot,{label:e("toolbar.format"),disabled:o,items:[{icon:"format_textdirection_l_to_r",label:e("toolbar.leftToRight"),onClick:()=>b("setLtr")},{icon:"format_textdirection_r_to_l",label:e("toolbar.rightToLeft"),onClick:()=>b("setRtl")}]}),jsx(ot,{label:e("toolbar.insert"),disabled:o,items:[...d?[{icon:"image",label:e("toolbar.image"),onClick:d}]:[],...p&&a?[{icon:"grid_on",label:e("toolbar.table"),submenuContent:w=>jsx(Yo,{onInsert:(L,J)=>{h(L,J),w();}})}]:[],...d||p&&a?[{type:"separator"}]:[],{icon:"page_break",label:e("toolbar.break"),submenuContent:w=>jsx(la,{closeMenu:w,items:[{icon:"page_break",label:e("toolbar.pageBreak"),onClick:m},{icon:"horizontal_rule",label:e("toolbar.sectionBreakNextPage"),onClick:l},{icon:"border_horizontal",label:e("toolbar.sectionBreakContinuous"),onClick:u}]})},{icon:"format_list_numbered",label:e("toolbar.tableOfContents"),onClick:f,disabled:!f},...g?[{icon:"branding_watermark",label:e("toolbar.watermark"),onClick:g}]:[]]}),jsx(ot,{label:e("toolbar.help"),disabled:o,items:[{label:e("toolbar.reportIssue"),onClick:()=>openReportIssue()}]})]})}function Jo({children:e}){let t=null,o=null,r=[],n=[];Children.forEach(e,i=>{isValidElement(i)&&(i.type===zt?t=i:i.type===Kt?o=i:i.type===Ht?n.push(i):r.push(i));});let s=useCallback(i=>{let c=i.target;c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.tagName==="SELECT"||c.tagName==="OPTION"||i.preventDefault();},[]);return jsxs("div",{className:"flex items-stretch bg-doc-surface pt-2 pb-1",onMouseDown:s,"data-testid":"title-bar",children:[jsx("div",{className:"flex items-center flex-shrink-0 pl-3 pr-1",children:t||jsx(sa,{})}),jsxs("div",{className:"flex flex-col justify-center flex-1 min-w-0 py-1",children:[r.length>0&&jsx("div",{className:"flex items-center gap-2 px-1",children:r}),n.length>0&&jsx("div",{className:"flex items-center px-1",children:n})]}),o&&jsx("div",{className:"flex items-center flex-shrink-0 px-3",children:o})]})}function da({children:e,className:t,style:o,...r}){return jsx(tt.Provider,{value:r,children:jsx("div",{className:P("flex flex-col bg-doc-surface shadow-sm flex-shrink-0",t),style:{position:"relative",zIndex:ct.toolbar,...o},"data-testid":"editor-toolbar",children:e})})}var Ye=da;Ye.TitleBar=Jo;Ye.Logo=zt;Ye.DocumentName=jo;Ye.MenuBar=Ht;Ye.TitleBarRight=Kt;Ye.Toolbar=Wo;var tr=12240,yt=1440,Ct=1440,St=567,Vt=22,ma="var(--doc-text-muted)",fa="var(--doc-text-subtle)",er="var(--doc-shadow-subtle)",ga="var(--doc-primary)",ba="var(--doc-primary-hover)",ha="var(--doc-primary-hover)",He=5;function xa(e,t){return t==="inch"?(e/Ct).toFixed(2)+'"':(e/St).toFixed(1)+" cm"}function Ic({sectionProps:e,zoom:t=1,editable:o=false,onLeftMarginChange:r,onRightMarginChange:n,onFirstLineIndentChange:s,showFirstLineIndent:i=false,firstLineIndent:c=0,hangingIndent:d=false,indentLeft:a=0,indentRight:p=0,onIndentLeftChange:m,onIndentRightChange:l,unit:u="inch",className:f="",style:g,tabStops:x,onTabStopRemove:b}){let{t:h}=b$1(),[v,C]=useState(null),[w,L]=useState(null),[J,O]=useState(null),[Y,de]=useState(null),be=useRef(null),G=e?.pageWidth??tr,R=e?.marginLeft??yt,M=e?.marginRight??yt,_=G-R-M,ue=twipsToPixels(G)*t,he=twipsToPixels(R)*t,xe=twipsToPixels(M)*t,ve=twipsToPixels(a)*t,oe=twipsToPixels(p)*t,Ae=d?-c:c,z=twipsToPixels(Ae)*t,Xe=he+ve,re=ue-xe-oe,We=he+ve+z,T=useCallback((E,Ne)=>{o&&(E.preventDefault(),E.stopPropagation(),C(Ne));},[o]),V=useCallback(E=>{if(!v||!be.current)return;let Ne=be.current.getBoundingClientRect(),nt=E.clientX-Ne.left;de(nt);let De=pixelsToTwips(nt/t);if(v==="leftMargin"){let pe=G-M-720,Q=Math.round(Math.max(0,Math.min(De,pe)));O(Q),r?.(Q);}else if(v==="rightMargin"){let pe=G-De,Q=G-R-720,ne=Math.round(Math.max(0,Math.min(pe,Q)));O(ne),n?.(ne);}else if(v==="firstLineIndent"){let pe=R+a,Q=De-pe,ne=_-a-p-720,ae=Math.round(Math.max(-a,Math.min(Q,ne)));O(ae),s?.(ae);}else if(v==="leftIndent"){let pe=De-R,Q=_-p-720,ne=Math.round(Math.max(0,Math.min(pe,Q)));O(ne),m?.(ne);}else if(v==="rightIndent"){let Q=G-M-De,ne=_-a-720,ae=Math.round(Math.max(0,Math.min(Q,ne)));O(ae),l?.(ae);}},[v,t,G,R,M,_,a,p,r,n,s,m,l]),ye=useCallback(()=>{C(null),O(null),de(null);},[]);useEffect(()=>{if(v)return document.addEventListener("mousemove",V),document.addEventListener("mouseup",ye),()=>{document.removeEventListener("mousemove",V),document.removeEventListener("mouseup",ye);}},[v,V,ye]);let wt=wa(G,t,u);return jsxs("div",{ref:be,className:`docx-horizontal-ruler ${f}`,style:{position:"relative",width:formatPx(ue),height:Vt,backgroundColor:"transparent",overflow:"visible",userSelect:"none",cursor:v?"ew-resize":"default",...g},role:"slider","aria-label":h("ruler.horizontal"),"aria-valuemin":0,"aria-valuemax":G,children:[jsx("div",{style:{position:"absolute",top:0,left:0,width:formatPx(he),height:Vt,backgroundColor:er,borderRight:"1px solid var(--doc-shadow-subtle)",cursor:o?"ew-resize":"default",zIndex:1},onMouseDown:o&&r?E=>T(E,"leftMargin"):void 0}),jsx("div",{style:{position:"absolute",top:0,right:0,width:formatPx(xe),height:Vt,backgroundColor:er,borderLeft:"1px solid var(--doc-shadow-subtle)",cursor:o?"ew-resize":"default",zIndex:1},onMouseDown:o&&n?E=>T(E,"rightMargin"):void 0}),jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none"},children:wt.map((E,Ne)=>jsx(va,{tick:E},Ne))}),i&&jsx($t,{direction:"down",positionPx:We,editable:o,isDragging:v==="firstLineIndent",isHovered:w==="firstLineIndent",onMouseEnter:()=>L("firstLineIndent"),onMouseLeave:()=>L(null),onMouseDown:E=>T(E,"firstLineIndent"),label:h("ruler.firstLineIndent")}),o&&m&&jsx($t,{direction:"up",positionPx:Xe,editable:o,isDragging:v==="leftIndent",isHovered:w==="leftIndent",onMouseEnter:()=>L("leftIndent"),onMouseLeave:()=>L(null),onMouseDown:E=>T(E,"leftIndent"),label:h("ruler.leftIndent")}),o&&l&&jsx($t,{direction:"down",positionPx:re,editable:o,isDragging:v==="rightIndent",isHovered:w==="rightIndent",onMouseEnter:()=>L("rightIndent"),onMouseLeave:()=>L(null),onMouseDown:E=>T(E,"rightIndent"),label:h("ruler.rightIndent")}),x?.map(E=>jsx(Sa,{tabStop:E,positionPx:twipsToPixels(E.position)*t,onDoubleClick:()=>b?.(E.position)},E.position)),v&&J!==null&&Y!==null&&jsx(ya,{value:xa(J,u),positionPx:Y})]})}function va({tick:e}){return jsxs(Fragment,{children:[jsx("div",{style:{position:"absolute",left:formatPx(e.position),bottom:0,width:1,height:e.height,backgroundColor:fa}}),e.label&&jsx("div",{style:{position:"absolute",left:formatPx(e.position),top:3,transform:"translateX(-50%)",fontSize:"9px",color:ma,fontFamily:"sans-serif",whiteSpace:"nowrap"},children:e.label})]})}function $t({direction:e,positionPx:t,editable:o,isDragging:r,isHovered:n,onMouseEnter:s,onMouseLeave:i,onMouseDown:c,label:d}){let a=r?ha:n?ba:ga,p=Math.round(He*1.6),m={position:"absolute",left:formatPx(t-He),width:He*2,height:p+2,cursor:o?"ew-resize":"default",zIndex:r?10:4,...e==="down"?{top:0}:{bottom:0}},l=e==="down"?{position:"absolute",top:1,left:0,width:0,height:0,borderLeft:`${He}px solid transparent`,borderRight:`${He}px solid transparent`,borderTop:`${p}px solid ${a}`,transition:"border-top-color 0.1s"}:{position:"absolute",bottom:1,left:0,width:0,height:0,borderLeft:`${He}px solid transparent`,borderRight:`${He}px solid transparent`,borderBottom:`${p}px solid ${a}`,transition:"border-bottom-color 0.1s"};return jsx("div",{className:"docx-ruler-indent",style:m,onMouseEnter:s,onMouseLeave:i,onMouseDown:c,role:"slider","aria-label":d,"aria-orientation":"horizontal",tabIndex:o?0:-1,children:jsx("div",{style:l})})}function ya({value:e,positionPx:t}){return jsx("div",{style:{position:"absolute",left:formatPx(t),top:-22,transform:"translateX(-50%)",backgroundColor:"var(--doc-text)",color:"var(--doc-on-primary)",fontSize:"10px",fontFamily:"sans-serif",padding:"2px 6px",borderRadius:3,whiteSpace:"nowrap",pointerEvents:"none",zIndex:20},children:e})}var Ca={left:"L",center:"C",right:"R",decimal:"D",bar:"|"};function Sa({tabStop:e,positionPx:t,onDoubleClick:o}){return jsx("div",{style:{position:"absolute",left:formatPx(t-5),bottom:0,width:10,height:12,display:"flex",alignItems:"center",justifyContent:"center",fontSize:8,fontWeight:700,color:"var(--doc-text-muted)",cursor:"pointer",userSelect:"none"},onDoubleClick:r=>{r.stopPropagation(),o();},title:`${e.alignment} tab at ${(e.position/1440).toFixed(2)}"`,children:Ca[e.alignment]||"L"})}function wa(e,t,o){let r=[];if(o==="inch"){let n=Ct/8,s=Math.ceil(e/n);for(let i=0;i<=s;i++){let c=i*n;if(c>e)break;let d=twipsToPixels(c)*t;i%8===0?r.push({position:d,height:10,label:i/8>0?String(i/8):void 0}):i%4===0?r.push({position:d,height:6}):i%2===0?r.push({position:d,height:4}):r.push({position:d,height:2});}}else {let n=St/10,s=Math.ceil(e/n);for(let i=0;i<=s;i++){let c=i*n;if(c>e)break;let d=twipsToPixels(c)*t;i%10===0?r.push({position:d,height:10,label:i/10>0?String(i/10):void 0}):i%5===0?r.push({position:d,height:6}):r.push({position:d,height:3});}}return r}function Lc(e,t,o,r){let n=pixelsToTwips(e/r);return t==="left"?Math.max(0,n):Math.max(0,pixelsToTwips(o/r)-n)}function Rc(e,t=1){let o=e?.pageWidth??tr,r=e?.marginLeft??yt,n=e?.marginRight??yt,s=twipsToPixels(o)*t,i=twipsToPixels(r)*t,c=twipsToPixels(n)*t;return {width:s,leftMargin:i,rightMargin:c,contentWidth:s-i-c}}function Ec(e,t){return t==="inch"?(e/Ct).toFixed(2)+'"':(e/St).toFixed(1)+" cm"}function Ac(e,t){let o=parseFloat(e.replace(/[^\d.]/g,""));return isNaN(o)?null:Math.round(o*(t==="inch"?Ct:St))}
|
|
2
2
|
export{ce as A,fe as B,qs as C,Wo as D,Ye as E,Ic as F,Lc as G,Rc as H,Ec as I,Ac as J,P as a,K as b,eo as c,ro as e,ct as h,ui as i,pi as j,mi as k,fi as l,gi as m,bi as n,ee as o,so as p,Fe as q,xo as r,yo as s,So as t,To as u,Mo as v,Io as w,Ro as x,Eo as y,Bo as z};
|
package/dist/chunk-WFGAQC2B.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {d,g,h,m,e,l,j,k,i}from'./chunk-BABMU5KA.mjs';import {b}from'./chunk-BMBP5UFA.mjs';import {useRef,useCallback,useMemo,useState,useEffect}from'react';import {TextSelection}from'prosemirror-state';import {findBodyPmSpans}from'@eigenpal/docx-editor-core/layout-bridge';import {findVerticalScrollParent}from'@eigenpal/docx-editor-core/utils/findVerticalScrollParent';import {computeAutoScrollDelta,AUTO_SCROLL_EDGE_ZONE}from'@eigenpal/docx-editor-core/utils/autoScroll';import {extractTrackedChanges}from'@eigenpal/docx-editor-core/prosemirror/utils/extractTrackedChanges';export{extractTrackedChanges as c}from'@eigenpal/docx-editor-core/prosemirror/utils/extractTrackedChanges';import {TableSelectionManager,getTableFromDocument,updateTableInDocument,deleteTableFromDocument}from'@eigenpal/docx-editor-core';export{TABLE_DATA_ATTRIBUTES as f}from'@eigenpal/docx-editor-core';var $=".layout-page-content .layout-line";function lt(r){let l=findVerticalScrollParent(r);if(!l)return;let s=r.getBoundingClientRect(),m=l.getBoundingClientRect(),t=40;s.bottom>m.bottom-t?l.scrollTop+=s.bottom-m.bottom+t:s.top<m.top+t&&(l.scrollTop-=m.top-s.top+t);}function xt({pagesContainerRef:r}){let l=useRef(null),s=useRef(-1),m=useCallback(b=>{if(!r.current)return null;let u=findBodyPmSpans(r.current);for(let i of u){let o=Number(i.dataset.pmStart),a=Number(i.dataset.pmEnd);if(i.classList.contains("layout-run-tab")){if(b>=o&&b<a)return i.getBoundingClientRect().left;continue}if(b>=o&&b<=a&&i.firstChild?.nodeType===Node.TEXT_NODE){let e=i.firstChild,n=Math.min(b-o,e.length),c=i.ownerDocument;if(!c)continue;let d=c.createRange();return d.setStart(e,n),d.setEnd(e,n),d.getBoundingClientRect().left}}let f=r.current.querySelectorAll(".layout-empty-run");for(let i of Array.from(f)){let o=i.closest(".layout-paragraph");if(!o)continue;let a=Number(o.dataset.pmStart),e=Number(o.dataset.pmEnd);if(b>=a&&b<=e)return i.getBoundingClientRect().left}return null},[r]),t=useCallback(b=>{if(!r.current)return null;let u=r.current.querySelectorAll($);for(let f of Array.from(u)){let i=f,o=i.querySelectorAll("span[data-pm-start][data-pm-end]");for(let a of Array.from(o)){let e=a,n=Number(e.dataset.pmStart),c=Number(e.dataset.pmEnd);if(b>=n&&b<=c)return i}}for(let f of Array.from(u)){let i=f,o=i.closest(".layout-paragraph");if(!o)continue;let a=Number(o.dataset.pmStart),e=Number(o.dataset.pmEnd);if(b>=a&&b<=e&&o.querySelector(".layout-line")===i)return i}return null},[r]),S=useCallback((b,u)=>{let f=b.querySelectorAll("span[data-pm-start][data-pm-end]");if(f.length===0){let e=b.closest(".layout-paragraph");return e?.dataset.pmStart?Number(e.dataset.pmStart)+1:null}for(let e of Array.from(f)){let n=e,c=n.getBoundingClientRect(),d=Number(n.dataset.pmStart),y=Number(n.dataset.pmEnd);if(n.classList.contains("layout-run-tab")){if(u>=c.left&&u<=c.right){let E=(c.left+c.right)/2;return u<E?d:y}continue}if(u>=c.left&&u<=c.right){let E=n.firstChild;if(!E||E.nodeType!==Node.TEXT_NODE)return d;let p=E,R=n.ownerDocument;if(!R)return d;let k=0,H=p.length;for(;k<H;){let w=Math.floor((k+H)/2),L=R.createRange();L.setStart(p,w),L.setEnd(p,w),u<L.getBoundingClientRect().left?H=w:k=w+1;}if(k>0&&k<=p.length){let w=R.createRange();w.setStart(p,k-1),w.setEnd(p,k-1);let L=w.getBoundingClientRect().left;w.setStart(p,Math.min(k,p.length)),w.setEnd(p,Math.min(k,p.length));let h=w.getBoundingClientRect().left;if(Math.abs(u-L)<Math.abs(u-h))return d+(k-1)}return d+Math.min(k,y-d)}}let i=null,o=1/0;for(let e of Array.from(f)){let n=e,c=n.getBoundingClientRect(),d=u<c.left?c.left-u:u-c.right;d<o&&(o=d,i=n);}if(!i)return null;let a=i.getBoundingClientRect();return u<a.left?Number(i.dataset.pmStart):Number(i.dataset.pmEnd)},[]),x=useCallback((b,u)=>{if(u.key!=="ArrowUp"&&u.key!=="ArrowDown")return (["ArrowLeft","ArrowRight","Home","End"].includes(u.key)||u.key.length===1&&!u.ctrlKey&&!u.metaKey)&&(l.current=null,s.current=-1),false;if(u.ctrlKey||u.metaKey)return l.current=null,s.current=-1,false;if(!r.current)return false;let f=Array.from(r.current.querySelectorAll($));if(f.length===0)return false;let{from:i,anchor:o}=b.state.selection;if(l.current===null){let p=m(i);if(p===null)return false;l.current=p;}let a;if(s.current>=0&&s.current<f.length)a=s.current;else {let p=t(i);if(!p||(a=f.indexOf(p),a===-1))return false}let e=u.key==="ArrowUp"?a-1:a+1;if(e<0||e>=f.length)return s.current=-1,false;let n=f[e],c=S(n,l.current);if(c===null)return false;s.current=e;let{state:d,dispatch:y}=b,E=Math.max(0,Math.min(c,d.doc.content.size));try{let p=u.shiftKey?TextSelection.create(d.doc,o,E):TextSelection.create(d.doc,E);y(d.tr.setSelection(p));}catch{let p=d.doc.resolve(E),R=u.shiftKey?TextSelection.between(d.doc.resolve(o),p):TextSelection.near(p);y(d.tr.setSelection(R));}return lt(n),true},[r,m,t,S]);return {stickyXRef:l,lastVisualLineIndexRef:s,getCaretClientX:m,findLineElementAtPosition:t,findPositionOnLineAtClientX:S,handlePMKeyDown:x}}function Ct({pagesContainerRef:r,onScrollExtendSelection:l}){let s=useRef(null),m=useRef({x:0,y:0}),t=useRef(false),S=useRef(null),x=useCallback(()=>{if(S.current)return S.current;let o=r.current;return o?(S.current=findVerticalScrollParent(o),S.current):null},[r]),b=useCallback(()=>{t.current=false,s.current!==null&&(cancelAnimationFrame(s.current),s.current=null);},[]),u=useCallback(()=>{if(!t.current)return;let o=x();if(!o)return;let a=o.getBoundingClientRect(),{x:e,y:n}=m.current,c=computeAutoScrollDelta(a,n);c!==0&&(o.scrollTop+=c,l(e,n)),s.current=requestAnimationFrame(u);},[x,l]),f=useCallback(()=>{t.current||(t.current=true,s.current=requestAnimationFrame(u));},[u]);return {updateMousePosition:useCallback((o,a)=>{if(m.current={x:o,y:a},!t.current){let e=x();if(!e)return;let n=e.getBoundingClientRect();(a<n.top+AUTO_SCROLL_EDGE_ZONE||a>n.bottom-AUTO_SCROLL_EDGE_ZONE)&&f();}},[x,f]),stopAutoScroll:b}}function At(r){return useMemo(()=>extractTrackedChanges(r),[r])}function Ot({document:r,onChange:l$1,onSelectionChange:s}){let m$1=useMemo(()=>new TableSelectionManager,[]),[t,S]=useState({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null}),x=useCallback((a,e,n)=>{if(!r)return;let c=getTableFromDocument(r,a);if(!c){m$1.clearSelection(),S({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null});return}m$1.selectCell({tableIndex:a,rowIndex:e,columnIndex:n});let y=d(c,{tableIndex:a,rowIndex:e,columnIndex:n});S({context:y,table:c,tableIndex:a,rowIndex:e,columnIndex:n}),s?.(y);},[r,m$1,s]),b=useCallback(()=>{m$1.clearSelection(),S({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null}),s?.(null);},[m$1,s]),u=useCallback(()=>!t.table||t.rowIndex===null||t.columnIndex===null?null:g(t.table,t.rowIndex,t.columnIndex),[t.columnIndex,t.rowIndex,t.table]),f=useCallback((a,e)=>{if(!r||!t.table||t.tableIndex===null||t.rowIndex===null||t.columnIndex===null)return;let n=h(t.table,t.rowIndex,t.columnIndex,a,e);if(n===t.table)return;let c=updateTableInDocument(r,t.tableIndex,n);l$1?.(c),c&&x(t.tableIndex,t.rowIndex,t.columnIndex);},[r,x,l$1,t.columnIndex,t.rowIndex,t.table,t.tableIndex]),i$1=useCallback(a=>{if(!r||!t.context||t.tableIndex===null||t.rowIndex===null||t.columnIndex===null)return;let e$1=t.table;if(!e$1)return;let n=null,c=null,d=t.rowIndex,y=t.columnIndex;switch(a){case "addRowAbove":n=i(e$1,t.rowIndex,"before"),d=t.rowIndex+1;break;case "addRowBelow":n=i(e$1,t.rowIndex,"after");break;case "addColumnLeft":n=k(e$1,t.columnIndex,"before"),y=t.columnIndex+1;break;case "addColumnRight":n=k(e$1,t.columnIndex,"after");break;case "deleteRow":e$1.rows.length>1&&(n=j(e$1,t.rowIndex),d>=n.rows.length&&(d=n.rows.length-1));break;case "deleteColumn":{if(e(e$1)>1){n=l(e$1,t.columnIndex);let p=e(n);y>=p&&(y=p-1);}break}case "mergeCells":t.context.selection.selectedCells&&(n=m(e$1,t.context.selection));break;case "splitCell":break;case "deleteTable":c=deleteTableFromDocument(r,t.tableIndex),b(),l$1?.(c);return}n&&(c=updateTableInDocument(r,t.tableIndex,n),l$1?.(c),c&&x(t.tableIndex,d,y));},[r,t,l$1,b,x]),o=useCallback((a,e,n)=>m$1.isCellSelected(a,e,n),[m$1,t]);return {state:t,handleCellClick:x,handleAction:i$1,getSplitCellConfig:u,applySplitCell:f,clearSelection:b,isCellSelected:o,tableContext:t.context}}function et(r,l){return JSON.stringify(r)===JSON.stringify(l)}function nt(r,l={}){let{maxEntries:s=100,groupingInterval:m=500,enableKeyboardShortcuts:t=true,isEqual:S=et,onUndo:x,onRedo:b,containerRef:u}=l,[f,i]=useState(r),[o,a]=useState([]),[e,n]=useState([]),c=useRef(0),d=useRef(false),y=useCallback((h,g)=>{if(S(f,h))return;if(d.current){i(h);return}let T=Date.now();T-c.current<m&&o.length>0?a(K=>{let A=[...K];return A[A.length-1]={state:f,timestamp:T,description:g||A[A.length-1].description},A}):a(K=>{let A={state:f,timestamp:T,description:g},N=[...K,A];return N.length>s?N.slice(N.length-s):N}),n([]),i(h),c.current=T;},[f,S,m,s,o.length]),E=useCallback(()=>{if(o.length===0)return;d.current=true;let h=o[o.length-1];return a(g=>g.slice(0,-1)),n(g=>[...g,{state:f,timestamp:Date.now()}]),i(h.state),setTimeout(()=>{d.current=false;},0),x?.(h.state),h.state},[o,f,x]),p=useCallback(()=>{if(e.length===0)return;d.current=true;let h=e[e.length-1];return n(g=>g.slice(0,-1)),a(g=>[...g,{state:f,timestamp:Date.now()}]),i(h.state),setTimeout(()=>{d.current=false;},0),b?.(h.state),h.state},[e,f,b]),R=useCallback(()=>{a([]),n([]);},[]),k=useCallback(h=>{i(h??r),a([]),n([]),c.current=0;},[r]),H=useCallback(()=>[...o],[o]),w=useCallback(()=>[...e],[e]),L=useCallback(h=>{i(g=>h(g)),a(g=>g.map(T=>({...T,state:h(T.state)}))),n(g=>g.map(T=>({...T,state:h(T.state)})));},[]);return useEffect(()=>{if(!t)return;let h=T=>{if((T.ctrlKey||T.metaKey)&&T.key==="z"&&!T.shiftKey){T.preventDefault(),E();return}if((T.ctrlKey||T.metaKey)&&T.key==="y"||(T.ctrlKey||T.metaKey)&&T.key==="z"&&T.shiftKey){T.preventDefault(),p();return}},g=u?.current||document;return g.addEventListener("keydown",h),()=>{g.removeEventListener("keydown",h);}},[t,E,p,u]),{state:f,canUndo:o.length>0,canRedo:e.length>0,undoCount:o.length,redoCount:e.length,push:y,undo:E,redo:p,clear:R,reset:k,getUndoStack:H,getRedoStack:w,transformAll:L}}function Ft(r,l={}){let s=nt(r,l);return useEffect(()=>{s.push(r);},[r]),s}function Jt(r,l={}){let s=useCallback((m,t)=>!(m?.package?.document!==t?.package?.document&&JSON.stringify(m?.package?.document)!==JSON.stringify(t?.package?.document)||m?.package?.headers!==t?.package?.headers||m?.package?.footers!==t?.package?.footers),[]);return nt(r,{...l,isEqual:s})}var X=class{constructor(l,s={}){b(this,"undoStack",[]);b(this,"redoStack",[]);b(this,"currentState");b(this,"maxEntries");b(this,"groupingInterval");b(this,"lastPushTime",0);b(this,"isEqual");this.currentState=l,this.maxEntries=s.maxEntries??100,this.groupingInterval=s.groupingInterval??500,this.isEqual=s.isEqual??et;}get state(){return this.currentState}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}push(l,s){if(this.isEqual(this.currentState,l))return;let m=Date.now();m-this.lastPushTime<this.groupingInterval&&this.undoStack.length>0?this.undoStack[this.undoStack.length-1].timestamp=m:(this.undoStack.push({state:this.currentState,timestamp:m,description:s}),this.undoStack.length>this.maxEntries&&(this.undoStack=this.undoStack.slice(-this.maxEntries))),this.redoStack=[],this.currentState=l,this.lastPushTime=m;}undo(){if(this.undoStack.length===0)return;let l=this.undoStack.pop();return this.redoStack.push({state:this.currentState,timestamp:Date.now()}),this.currentState=l.state,l.state}redo(){if(this.redoStack.length===0)return;let l=this.redoStack.pop();return this.undoStack.push({state:this.currentState,timestamp:Date.now()}),this.currentState=l.state,l.state}clear(){this.undoStack=[],this.redoStack=[];}reset(l){this.currentState=l??this.currentState,this.undoStack=[],this.redoStack=[],this.lastPushTime=0;}};export{xt as a,Ct as b,At as d,Ot as e,nt as g,Ft as h,Jt as i,X as j};
|
|
1
|
+
import {d,g,h,m,e,l,j,k,i}from'./chunk-BABMU5KA.mjs';import {b}from'./chunk-BMBP5UFA.mjs';import {useRef,useCallback,useMemo,useState,useEffect}from'react';import {TextSelection}from'prosemirror-state';import {findBodyPmSpans}from'@sqren/docx-editor-core/layout-bridge';import {findVerticalScrollParent}from'@sqren/docx-editor-core/utils/findVerticalScrollParent';import {computeAutoScrollDelta,AUTO_SCROLL_EDGE_ZONE}from'@sqren/docx-editor-core/utils/autoScroll';import {extractTrackedChanges}from'@sqren/docx-editor-core/prosemirror/utils/extractTrackedChanges';export{extractTrackedChanges as c}from'@sqren/docx-editor-core/prosemirror/utils/extractTrackedChanges';import {TableSelectionManager,getTableFromDocument,updateTableInDocument,deleteTableFromDocument}from'@sqren/docx-editor-core';export{TABLE_DATA_ATTRIBUTES as f}from'@sqren/docx-editor-core';var $=".layout-page-content .layout-line";function lt(r){let l=findVerticalScrollParent(r);if(!l)return;let s=r.getBoundingClientRect(),m=l.getBoundingClientRect(),t=40;s.bottom>m.bottom-t?l.scrollTop+=s.bottom-m.bottom+t:s.top<m.top+t&&(l.scrollTop-=m.top-s.top+t);}function xt({pagesContainerRef:r}){let l=useRef(null),s=useRef(-1),m=useCallback(b=>{if(!r.current)return null;let u=findBodyPmSpans(r.current);for(let i of u){let o=Number(i.dataset.pmStart),a=Number(i.dataset.pmEnd);if(i.classList.contains("layout-run-tab")){if(b>=o&&b<a)return i.getBoundingClientRect().left;continue}if(b>=o&&b<=a&&i.firstChild?.nodeType===Node.TEXT_NODE){let e=i.firstChild,n=Math.min(b-o,e.length),c=i.ownerDocument;if(!c)continue;let d=c.createRange();return d.setStart(e,n),d.setEnd(e,n),d.getBoundingClientRect().left}}let f=r.current.querySelectorAll(".layout-empty-run");for(let i of Array.from(f)){let o=i.closest(".layout-paragraph");if(!o)continue;let a=Number(o.dataset.pmStart),e=Number(o.dataset.pmEnd);if(b>=a&&b<=e)return i.getBoundingClientRect().left}return null},[r]),t=useCallback(b=>{if(!r.current)return null;let u=r.current.querySelectorAll($);for(let f of Array.from(u)){let i=f,o=i.querySelectorAll("span[data-pm-start][data-pm-end]");for(let a of Array.from(o)){let e=a,n=Number(e.dataset.pmStart),c=Number(e.dataset.pmEnd);if(b>=n&&b<=c)return i}}for(let f of Array.from(u)){let i=f,o=i.closest(".layout-paragraph");if(!o)continue;let a=Number(o.dataset.pmStart),e=Number(o.dataset.pmEnd);if(b>=a&&b<=e&&o.querySelector(".layout-line")===i)return i}return null},[r]),S=useCallback((b,u)=>{let f=b.querySelectorAll("span[data-pm-start][data-pm-end]");if(f.length===0){let e=b.closest(".layout-paragraph");return e?.dataset.pmStart?Number(e.dataset.pmStart)+1:null}for(let e of Array.from(f)){let n=e,c=n.getBoundingClientRect(),d=Number(n.dataset.pmStart),y=Number(n.dataset.pmEnd);if(n.classList.contains("layout-run-tab")){if(u>=c.left&&u<=c.right){let E=(c.left+c.right)/2;return u<E?d:y}continue}if(u>=c.left&&u<=c.right){let E=n.firstChild;if(!E||E.nodeType!==Node.TEXT_NODE)return d;let p=E,R=n.ownerDocument;if(!R)return d;let k=0,H=p.length;for(;k<H;){let w=Math.floor((k+H)/2),L=R.createRange();L.setStart(p,w),L.setEnd(p,w),u<L.getBoundingClientRect().left?H=w:k=w+1;}if(k>0&&k<=p.length){let w=R.createRange();w.setStart(p,k-1),w.setEnd(p,k-1);let L=w.getBoundingClientRect().left;w.setStart(p,Math.min(k,p.length)),w.setEnd(p,Math.min(k,p.length));let h=w.getBoundingClientRect().left;if(Math.abs(u-L)<Math.abs(u-h))return d+(k-1)}return d+Math.min(k,y-d)}}let i=null,o=1/0;for(let e of Array.from(f)){let n=e,c=n.getBoundingClientRect(),d=u<c.left?c.left-u:u-c.right;d<o&&(o=d,i=n);}if(!i)return null;let a=i.getBoundingClientRect();return u<a.left?Number(i.dataset.pmStart):Number(i.dataset.pmEnd)},[]),x=useCallback((b,u)=>{if(u.key!=="ArrowUp"&&u.key!=="ArrowDown")return (["ArrowLeft","ArrowRight","Home","End"].includes(u.key)||u.key.length===1&&!u.ctrlKey&&!u.metaKey)&&(l.current=null,s.current=-1),false;if(u.ctrlKey||u.metaKey)return l.current=null,s.current=-1,false;if(!r.current)return false;let f=Array.from(r.current.querySelectorAll($));if(f.length===0)return false;let{from:i,anchor:o}=b.state.selection;if(l.current===null){let p=m(i);if(p===null)return false;l.current=p;}let a;if(s.current>=0&&s.current<f.length)a=s.current;else {let p=t(i);if(!p||(a=f.indexOf(p),a===-1))return false}let e=u.key==="ArrowUp"?a-1:a+1;if(e<0||e>=f.length)return s.current=-1,false;let n=f[e],c=S(n,l.current);if(c===null)return false;s.current=e;let{state:d,dispatch:y}=b,E=Math.max(0,Math.min(c,d.doc.content.size));try{let p=u.shiftKey?TextSelection.create(d.doc,o,E):TextSelection.create(d.doc,E);y(d.tr.setSelection(p));}catch{let p=d.doc.resolve(E),R=u.shiftKey?TextSelection.between(d.doc.resolve(o),p):TextSelection.near(p);y(d.tr.setSelection(R));}return lt(n),true},[r,m,t,S]);return {stickyXRef:l,lastVisualLineIndexRef:s,getCaretClientX:m,findLineElementAtPosition:t,findPositionOnLineAtClientX:S,handlePMKeyDown:x}}function Ct({pagesContainerRef:r,onScrollExtendSelection:l}){let s=useRef(null),m=useRef({x:0,y:0}),t=useRef(false),S=useRef(null),x=useCallback(()=>{if(S.current)return S.current;let o=r.current;return o?(S.current=findVerticalScrollParent(o),S.current):null},[r]),b=useCallback(()=>{t.current=false,s.current!==null&&(cancelAnimationFrame(s.current),s.current=null);},[]),u=useCallback(()=>{if(!t.current)return;let o=x();if(!o)return;let a=o.getBoundingClientRect(),{x:e,y:n}=m.current,c=computeAutoScrollDelta(a,n);c!==0&&(o.scrollTop+=c,l(e,n)),s.current=requestAnimationFrame(u);},[x,l]),f=useCallback(()=>{t.current||(t.current=true,s.current=requestAnimationFrame(u));},[u]);return {updateMousePosition:useCallback((o,a)=>{if(m.current={x:o,y:a},!t.current){let e=x();if(!e)return;let n=e.getBoundingClientRect();(a<n.top+AUTO_SCROLL_EDGE_ZONE||a>n.bottom-AUTO_SCROLL_EDGE_ZONE)&&f();}},[x,f]),stopAutoScroll:b}}function At(r){return useMemo(()=>extractTrackedChanges(r),[r])}function Ot({document:r,onChange:l$1,onSelectionChange:s}){let m$1=useMemo(()=>new TableSelectionManager,[]),[t,S]=useState({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null}),x=useCallback((a,e,n)=>{if(!r)return;let c=getTableFromDocument(r,a);if(!c){m$1.clearSelection(),S({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null});return}m$1.selectCell({tableIndex:a,rowIndex:e,columnIndex:n});let y=d(c,{tableIndex:a,rowIndex:e,columnIndex:n});S({context:y,table:c,tableIndex:a,rowIndex:e,columnIndex:n}),s?.(y);},[r,m$1,s]),b=useCallback(()=>{m$1.clearSelection(),S({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null}),s?.(null);},[m$1,s]),u=useCallback(()=>!t.table||t.rowIndex===null||t.columnIndex===null?null:g(t.table,t.rowIndex,t.columnIndex),[t.columnIndex,t.rowIndex,t.table]),f=useCallback((a,e)=>{if(!r||!t.table||t.tableIndex===null||t.rowIndex===null||t.columnIndex===null)return;let n=h(t.table,t.rowIndex,t.columnIndex,a,e);if(n===t.table)return;let c=updateTableInDocument(r,t.tableIndex,n);l$1?.(c),c&&x(t.tableIndex,t.rowIndex,t.columnIndex);},[r,x,l$1,t.columnIndex,t.rowIndex,t.table,t.tableIndex]),i$1=useCallback(a=>{if(!r||!t.context||t.tableIndex===null||t.rowIndex===null||t.columnIndex===null)return;let e$1=t.table;if(!e$1)return;let n=null,c=null,d=t.rowIndex,y=t.columnIndex;switch(a){case "addRowAbove":n=i(e$1,t.rowIndex,"before"),d=t.rowIndex+1;break;case "addRowBelow":n=i(e$1,t.rowIndex,"after");break;case "addColumnLeft":n=k(e$1,t.columnIndex,"before"),y=t.columnIndex+1;break;case "addColumnRight":n=k(e$1,t.columnIndex,"after");break;case "deleteRow":e$1.rows.length>1&&(n=j(e$1,t.rowIndex),d>=n.rows.length&&(d=n.rows.length-1));break;case "deleteColumn":{if(e(e$1)>1){n=l(e$1,t.columnIndex);let p=e(n);y>=p&&(y=p-1);}break}case "mergeCells":t.context.selection.selectedCells&&(n=m(e$1,t.context.selection));break;case "splitCell":break;case "deleteTable":c=deleteTableFromDocument(r,t.tableIndex),b(),l$1?.(c);return}n&&(c=updateTableInDocument(r,t.tableIndex,n),l$1?.(c),c&&x(t.tableIndex,d,y));},[r,t,l$1,b,x]),o=useCallback((a,e,n)=>m$1.isCellSelected(a,e,n),[m$1,t]);return {state:t,handleCellClick:x,handleAction:i$1,getSplitCellConfig:u,applySplitCell:f,clearSelection:b,isCellSelected:o,tableContext:t.context}}function et(r,l){return JSON.stringify(r)===JSON.stringify(l)}function nt(r,l={}){let{maxEntries:s=100,groupingInterval:m=500,enableKeyboardShortcuts:t=true,isEqual:S=et,onUndo:x,onRedo:b,containerRef:u}=l,[f,i]=useState(r),[o,a]=useState([]),[e,n]=useState([]),c=useRef(0),d=useRef(false),y=useCallback((h,g)=>{if(S(f,h))return;if(d.current){i(h);return}let T=Date.now();T-c.current<m&&o.length>0?a(K=>{let A=[...K];return A[A.length-1]={state:f,timestamp:T,description:g||A[A.length-1].description},A}):a(K=>{let A={state:f,timestamp:T,description:g},N=[...K,A];return N.length>s?N.slice(N.length-s):N}),n([]),i(h),c.current=T;},[f,S,m,s,o.length]),E=useCallback(()=>{if(o.length===0)return;d.current=true;let h=o[o.length-1];return a(g=>g.slice(0,-1)),n(g=>[...g,{state:f,timestamp:Date.now()}]),i(h.state),setTimeout(()=>{d.current=false;},0),x?.(h.state),h.state},[o,f,x]),p=useCallback(()=>{if(e.length===0)return;d.current=true;let h=e[e.length-1];return n(g=>g.slice(0,-1)),a(g=>[...g,{state:f,timestamp:Date.now()}]),i(h.state),setTimeout(()=>{d.current=false;},0),b?.(h.state),h.state},[e,f,b]),R=useCallback(()=>{a([]),n([]);},[]),k=useCallback(h=>{i(h??r),a([]),n([]),c.current=0;},[r]),H=useCallback(()=>[...o],[o]),w=useCallback(()=>[...e],[e]),L=useCallback(h=>{i(g=>h(g)),a(g=>g.map(T=>({...T,state:h(T.state)}))),n(g=>g.map(T=>({...T,state:h(T.state)})));},[]);return useEffect(()=>{if(!t)return;let h=T=>{if((T.ctrlKey||T.metaKey)&&T.key==="z"&&!T.shiftKey){T.preventDefault(),E();return}if((T.ctrlKey||T.metaKey)&&T.key==="y"||(T.ctrlKey||T.metaKey)&&T.key==="z"&&T.shiftKey){T.preventDefault(),p();return}},g=u?.current||document;return g.addEventListener("keydown",h),()=>{g.removeEventListener("keydown",h);}},[t,E,p,u]),{state:f,canUndo:o.length>0,canRedo:e.length>0,undoCount:o.length,redoCount:e.length,push:y,undo:E,redo:p,clear:R,reset:k,getUndoStack:H,getRedoStack:w,transformAll:L}}function Ft(r,l={}){let s=nt(r,l);return useEffect(()=>{s.push(r);},[r]),s}function Jt(r,l={}){let s=useCallback((m,t)=>!(m?.package?.document!==t?.package?.document&&JSON.stringify(m?.package?.document)!==JSON.stringify(t?.package?.document)||m?.package?.headers!==t?.package?.headers||m?.package?.footers!==t?.package?.footers),[]);return nt(r,{...l,isEqual:s})}var X=class{constructor(l,s={}){b(this,"undoStack",[]);b(this,"redoStack",[]);b(this,"currentState");b(this,"maxEntries");b(this,"groupingInterval");b(this,"lastPushTime",0);b(this,"isEqual");this.currentState=l,this.maxEntries=s.maxEntries??100,this.groupingInterval=s.groupingInterval??500,this.isEqual=s.isEqual??et;}get state(){return this.currentState}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}push(l,s){if(this.isEqual(this.currentState,l))return;let m=Date.now();m-this.lastPushTime<this.groupingInterval&&this.undoStack.length>0?this.undoStack[this.undoStack.length-1].timestamp=m:(this.undoStack.push({state:this.currentState,timestamp:m,description:s}),this.undoStack.length>this.maxEntries&&(this.undoStack=this.undoStack.slice(-this.maxEntries))),this.redoStack=[],this.currentState=l,this.lastPushTime=m;}undo(){if(this.undoStack.length===0)return;let l=this.undoStack.pop();return this.redoStack.push({state:this.currentState,timestamp:Date.now()}),this.currentState=l.state,l.state}redo(){if(this.redoStack.length===0)return;let l=this.redoStack.pop();return this.undoStack.push({state:this.currentState,timestamp:Date.now()}),this.currentState=l.state,l.state}clear(){this.undoStack=[],this.redoStack=[];}reset(l){this.currentState=l??this.currentState,this.undoStack=[],this.redoStack=[],this.lastPushTime=0;}};export{xt as a,Ct as b,At as d,Ot as e,nt as g,Ft as h,Jt as i,X as j};
|