oasis-editor 0.0.417 → 0.0.418
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/OasisEditorApp-DAqRW7aB.js +1 -0
- package/dist/assets/{importDocxWorker-ChuR4jqX.js → importDocxWorker-FgGrfnHp.js} +3800 -2669
- package/dist/core/commands/builtinCommands.d.ts +1 -1
- package/dist/core/commands/publicCommandTypes.d.ts +13 -0
- package/dist/core/commands/text.d.ts +1 -1
- package/dist/core/document/contentControlTransactions.d.ts +20 -0
- package/dist/core/document/contentControlTraversal.d.ts +9 -0
- package/dist/core/document/contentControlValues.d.ts +8 -0
- package/dist/core/document/documentProtection.d.ts +3 -0
- package/dist/core/document/inlineContentControlEdit.d.ts +8 -0
- package/dist/core/document/repeatingSectionRows.d.ts +4 -0
- package/dist/core/model/types/document.d.ts +6 -0
- package/dist/core/model/types/docxSourcePackage.d.ts +4 -0
- package/dist/core/model/types/nodes.d.ts +4 -0
- package/dist/defaultToolbar-Ux_dvdoA.js +1 -0
- package/dist/export/docx/docxPackageXml.d.ts +1 -1
- package/dist/export/docx/synchronizeBoundContentControls.d.ts +7 -1
- package/dist/export/docx/text/sdtSubtypeSource.d.ts +2 -0
- package/dist/import/docx/opc/sourcePackage.d.ts +1 -0
- package/dist/import/docx/settings.d.ts +5 -0
- package/dist/oasis-editor.js +1 -1
- package/dist/oasis-editor.umd.cjs +1 -1
- package/dist/ooxml/word/customXmlBinding.d.ts +5 -0
- package/dist/plugins/internal/essentialsCapabilities.d.ts +3 -0
- package/dist/sourcePackage-GLrWYLnd.js +1 -0
- package/dist/ui/app/useEditorTransactions.d.ts +2 -0
- package/package.json +1 -1
- package/dist/OasisEditorApp-Dis4OFNS.js +0 -1
- package/dist/defaultToolbar-y3saZHkk.js +0 -1
- package/dist/sourcePackage-BhGtQ-1k.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e}from"./rolldown-runtime-CjpNFd0O.js";import{$ as t,$i as n,$n as r,$r as o,$t as a,A as i,Ai as s,An as l,Ar as c,At as d,B as u,Bi as p,Bn as f,Bt as g,C as m,Ci as h,Cn as b,Cr as y,Ct as v,D as x,Di as w,Dn as I,Dr as S,Dt as C,E as k,Ei as T,En as P,Er as R,Et as A,F as M,Fn as O,Fr as B,Ft as F,G as E,Gi as D,Gn as L,H as N,Hi as z,Hn as $,I as H,In as W,It as j,J as U,Ji as V,Jn as K,Jr as _,Jt as X,K as q,Ki as G,Kn as Y,Kt as Z,L as J,Ln as Q,Lt as ee,M as te,Mn as ne,Mr as re,Mt as oe,N as ae,Nn as ie,Nr as se,O as le,Oi as ce,On as de,Or as ue,Ot as pe,P as fe,Pn as ge,Pt as me,Q as he,Qn as be,Qr as ye,Qt as ve,R as xe,Rn as we,Rt as Ie,S as Se,Si as Ce,Sn as ke,Sr as Te,St as Pe,T as Re,Ti as Ae,Tn as Me,Tr as Oe,Tt as Be,U as Fe,Ui as Ee,Un as De,V as Le,Vi as Ne,Vn as ze,W as $e,Wi as He,Wn as We,X as je,Xi as Ue,Xn as Ve,Xr as Ke,Xt as _e,Y as Xe,Yi as qe,Yn as Ge,Yr as Ye,Yt as Ze,Z as Je,Zi as Qe,Zn as et,Zr as tt,Zt as nt,_ as rt,_a as ot,_i as at,_n as it,_r as st,_t as lt,a as ct,aa as dt,ai as ut,an as pt,ar as ft,at as gt,b as mt,bi as ht,bn as bt,br as yt,bt as vt,c as xt,ca as wt,ci as It,cn as St,cr as Ct,ct as kt,d as Tt,da as Pt,dn as Rt,dr as At,dt as Mt,ea as Ot,ei as Bt,en as Ft,er as Et,et as Dt,f as Lt,fa as Nt,fi as zt,fn as $t,fr as Ht,ft as Wt,g as jt,ga as Ut,gn as Vt,gr as Kt,gt as _t,h as Xt,ha as qt,hi as Gt,hn as Yt,hr as Zt,i as Jt,ia as Qt,ii as en,in as tn,ir as nn,it as rn,j as on,jn as an,jr as sn,jt as ln,k as cn,ki as dn,kn as un,kr as pn,kt as fn,l as gn,la as mn,li as hn,ln as bn,lr as yn,lt as vn,m as xn,mi as wn,mn as In,mr as Sn,mt as Cn,n as kn,na as Tn,ni as Pn,nn as Rn,nr as An,nt as Mn,o as On,oa as Bn,oi as Fn,on as En,or as Dn,ot as Ln,p as Nn,pa as zn,pi as $n,pn as Hn,pr as Wn,pt as jn,q as Un,qi as Vn,qn as Kn,qt as _n,r as Xn,ra as qn,ri as Gn,rn as Yn,rr as Zn,rt as Jn,s as Qn,sa as er,si as tr,sn as nr,sr as rr,st as or,t as ar,ti as ir,tn as sr,tr as lr,tt as cr,u as dr,ua as ur,un as pr,ur as fr,ut as gr,v as mr,vi as hr,vn as br,vr as yr,vt as vr,w as xr,wi as wr,wn as Ir,wr as Sr,wt as Cr,x as kr,xi as Tr,xn as Pr,xr as Rr,xt as Ar,y as Mr,yi as Or,yn as Br,yr as Fr,yt as Er,z as Dr,zi as Lr,zn as Nr,zt as zr}from"./defaultToolbar-Ux_dvdoA.js";import{$ as $r,$n as Hr,A as Wr,An as jr,Ar as Ur,At as Vr,B as Kr,Br as _r,C as Xr,Cr as qr,Ct as Gr,D as Yr,Dn as Zr,Dr as Jr,Dt as Qr,E as eo,En as to,Et as no,F as ro,Ft as oo,G as ao,Gn as io,Gr as so,H as lo,Hn as co,Hr as uo,I as po,In as fo,Ir as go,It as mo,J as ho,Jn as bo,Jr as yo,K as vo,Kn as xo,Kr as wo,Ln as Io,Lr as So,Lt as Co,Mn as ko,Mt as To,N as Po,Nn as Ro,Nr as Ao,Nt as Mo,O as Oo,Ot as Bo,P as Fo,Pn as Eo,Q as Do,Qn as Lo,Qr as No,R as zo,Rn as $o,Rr as Ho,S as Wo,Sn as jo,St as Uo,T as Vo,Tt as Ko,Ur as _o,V as Xo,Wn as qo,Wr as Go,X as Yo,Xn as Zo,Xr as Jo,Y as Qo,Yn as ea,Yr as ta,Z as na,Zn as ra,Zr as oa,_ as aa,_n as ia,_r as sa,_t as la,a as ca,an as da,ar as ua,at as pa,b as fa,bn as ga,c as ma,cn as ha,cr as ba,ct as ya,d as va,dn as xa,dr as wa,er as Ia,f as Sa,fn as Ca,fr as ka,ft as Ta,g as Pa,gn as Ra,gr as Aa,gt as Ma,h as Oa,hn as Ba,hr as Fa,ht as Ea,i as Da,in as La,it as Na,j as za,jn as $a,jr as Ha,jt as Wa,k as ja,kn as Ua,kr as Va,kt as Ka,l as _a,ln as Xa,lr as qa,lt as Ga,m as Ya,mn as Za,mt as Ja,n as Qa,nn as ei,nr as ti,o as ni,on as ri,or as oi,p as ai,pn as ii,pr as si,pt as li,qn as ci,qr as di,rn as ui,rr as pi,rt as fi,s as gi,sr as mi,st as hi,tr as bi,tt as yi,u as vi,ur as xi,v as wi,vn as Ii,vr as Si,w as Ci,wr as ki,wt as Ti,x as Pi,xn as Ri,xt as Ai,y as Mi,yn as Oi,yr as Bi,yt as Fi,z as Ei,zn as Di,zr as Li}from"./sourcePackage-GLrWYLnd.js";function Ni(e,t){return{document:e.document,selection:t}}function zi(e,t){if(!ga(e.selection))return on(e,t<0?"start":"end");const{paragraphs:n,index:r,offset:o}=ae(e),a=r+t;if(a<0||a>=n.length)return e;const i=n[a];return Ni(e,J(xi(i,Math.min(o,oi(i)))))}function $i(e,t){const{paragraphs:n,paragraph:r,index:o,offset:a}=ae(e),i=oi(r);if(t<0&&a>0)return Ni(e,{anchor:e.selection.anchor,focus:xi(r,a-1)});if(t>0&&a<i)return Ni(e,{anchor:e.selection.anchor,focus:xi(r,a+1)});if(t<0&&o>0){const t=n[o-1];return Ni(e,{anchor:e.selection.anchor,focus:xi(t,oi(t))})}if(t>0&&o<n.length-1){const t=n[o+1];return Ni(e,{anchor:e.selection.anchor,focus:xi(t,0)})}return e}function Hi(e,t){const{paragraphs:n,index:r,offset:o}=ae(e),a=r+t;if(a<0||a>=n.length)return e;const i=n[a];return Ni(e,{anchor:e.selection.anchor,focus:xi(i,Math.min(o,oi(i)))})}function Wi(e){const t=Ri(e);if(t.isCollapsed)return"";const n=ko(e);if(t.startIndex===t.endIndex){const e=n[t.startIndex];return mi(e).slice(t.startParagraphOffset,t.endParagraphOffset)}const r=[],o=n[t.startIndex],a=n[t.endIndex];r.push(mi(o).slice(t.startParagraphOffset));for(let i=t.startIndex+1;i<t.endIndex;i+=1)r.push(mi(n[i]));return r.push(mi(a).slice(0,t.endParagraphOffset)),r.join("\n")}function ji(e,t){return{...e,selection:{anchor:Ra(e,t.anchor),focus:Ra(e,t.focus)}}}function Ui(e){if(!ga(e.selection))return on(e,"start");const{paragraph:t,index:n,offset:r}=ae(e),o=ko(e);if(ba(t,r)&&"before-markers"!==e.selection.focus.fieldBoundaryAffinity)return{...e,selection:J(qa(t,r,"before-markers"))};if(r>0)return{...e,selection:J(qa(t,r-1,"after-markers"))};if(0===n)return e;const a=o[n-1];return{...e,selection:J(qa(a,oi(a),"after-markers"))}}function Vi(e){if(!ga(e.selection))return on(e,"end");const{paragraph:t,index:n,offset:r}=ae(e),o=ko(e),a=oi(t);if(ba(t,r)&&"after-markers"!==e.selection.focus.fieldBoundaryAffinity)return{...e,selection:J(qa(t,r,"after-markers"))};if(r<a)return{...e,selection:J(qa(t,r+1,"before-markers"))};if(n>=o.length-1)return e;const i=o[n+1];return{...e,selection:J(qa(i,0,"before-markers"))}}function Ki(e,t){const n=Ri(e);if(n.isCollapsed||n.startIndex!==n.endIndex||n.endParagraphOffset-n.startParagraphOffset!==1)return null;const r=ko(e)[n.startIndex];if(!r)return null;let o=0;for(let a=0;a<r.runs.length;a+=1){const e=r.runs[a],i=o;if(o+=e.text.length,t(e)&&1===e.text.length&&i===n.startParagraphOffset)return{paragraph:r,paragraphIndex:n.startIndex,run:e,runIndex:a,offset:i}}return null}var _i=ei(),Xi="http://schemas.openxmlformats.org/officeDocument/2006/relationships",qi="http://schemas.microsoft.com/office/2011/relationships",Gi="application/vnd.openxmlformats-officedocument.",Yi=16777216,Zi=4096,Ji=/* @__PURE__ */new Map([[Xi+"/chart",/* @__PURE__ */new Set([Gi+"drawingml.chart+xml"])],[qi+"/chartStyle",/* @__PURE__ */new Set(["application/vnd.ms-office.chartstyle+xml"])],[qi+"/chartColorStyle",/* @__PURE__ */new Set(["application/vnd.ms-office.chartcolorstyle+xml"])],[Xi+"/image",/* @__PURE__ */new Set(["image/png","image/jpeg","image/gif","image/bmp","image/tiff"])],[Xi+"/package",/* @__PURE__ */new Set([Gi+"spreadsheetml.sheet"])]]),Qi="oasis.opc-chart-transfer.v1",es=e=>{throw Error("Opaque transfer rejected: "+e)};function ts(e){if(!e||"object"!=typeof e||Array.isArray(e))return es("expected record");const t=Object.getPrototypeOf(e);return t!==Object.prototype&&null!==t?es("unexpected record prototype"):e}function ns(e,t=Yi){return"string"!=typeof e||!e.length||e.length>t?es("invalid string or size"):e}function rs(e,t){return!Array.isArray(e)||e.length>t?es("invalid array or count"):e}function os(e){const t=ns(e,512);return!/^[A-Za-z0-9_.\-/]+$/.test(t)||t.split("/").some(e=>!e||"."===e||".."===e||"_rels"===e)||t.endsWith(".rels")||"__proto__"===t||"constructor"===t||"prototype"===t?es("unsafe part path"):t}function as(e){if(/<!\s*(?:DOCTYPE|ENTITY)\b/i.test(e))return es("unsafe XML declaration");const t=new _i.DOMParser({onError:()=>es("malformed XML")}).parseFromString(e,"application/xml").documentElement;return t||es("missing XML root")}function is(e,t){const n=rs(e,Zi).map(e=>function(e,t){const n=ts(e),r=ns(n.id,256),o=ns(n.type,512),a=ns(n.target,512);if(!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(r)||!Ji.has(o))return es("unsupported relationship");if(void 0!==n.targetMode&&"Internal"!==n.targetMode)return es("external relationship");if(!/^[A-Za-z0-9_.\-/]+$/.test(a))return es("unsafe relationship URI");const i=os(n.resolvedTarget);return Ka(t,a)!==i?es("inconsistent relationship target"):{id:r,type:o,target:a,targetMode:"Internal",resolvedTarget:i}}(e,t));return new Set(n.map(e=>e.id)).size!==n.length?es("duplicate relationship ID"):n}function ss(e){const t=ts(e),n=os(t.path),r=ns(t.contentType,256),o=ns(t.data),a=r.endsWith("+xml");return[...Ji.values()].some(e=>e.has(r))?t.kind!==(a?"xml":"binary")||t.encoding!==(a?"utf8":"base64")?es("inconsistent part encoding"):a||/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(o)?(a&&as(o),{path:n,contentType:r,kind:a?"xml":"binary",encoding:a?"utf8":"base64",data:o,relationships:is(t.relationships,n)}):es("invalid base64"):es("unsupported content type")}function ls(e){const t=ts(e);if("oasis.opc-chart-transfer.v1"!==t.format)return es("unsupported format");const n=os(t.ownerPath),r=ns(t.fragmentXml,1048576),o=ns(t.signature,2097152),a=is(t.relationships,n),i=rs(t.parts,128).map(ts);let s=r.length+o.length,l=a.length;for(const m of i){if(s+=ns(m.data).length,l+=rs(m.relationships,Zi).length,3*s>Yi)return es("aggregate size limit");if(l>Zi)return es("aggregate relationship limit")}const c=i.map(ss),d=as(r),u=Xo(d);if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==d.namespaceURI||"drawing"!==d.localName||!u||"chart"!==u.objectKind||"inline"!==u.placement||u.signature!==o)return es("unsupported or changed chart fragment");if(1!==a.filter(e=>e.type===Xi+"/chart").length||a.some(e=>e.type!==Xi+"/chart")||JSON.stringify([...u.relationshipIds].sort())!==JSON.stringify(a.map(e=>e.id).sort()))return es("chart relationship mismatch");const p=new Map(c.map(e=>[e.path,e]));if(p.size!==c.length||p.has(n))return es("duplicate or story-dependent part");if(new Set([n,...p.keys()].map(e=>e.toLowerCase())).size!==c.length+1)return es("aliased part path");const f=[...a],g=/* @__PURE__ */new Set;for(let m=0;m<f.length;m++){const e=f[m],t=p.get(e.resolvedTarget);if(!t||!Ji.get(e.type)?.has(t.contentType))return es("missing dependency or incompatible relationship type");if(!g.has(t.path)){if(g.add(t.path),t.contentType!==Gi+"drawingml.chart+xml"&&t.relationships.length)return es("unsupported nested dependency owner");if(t.relationships.some(e=>e.type===Xi+"/chart"))return es("nested chart dependency");f.push(...t.relationships)}}return g.size!==c.length?es("unreachable payload part"):{format:Qi,ownerPath:n,fragmentXml:r,signature:o,relationships:a,parts:c.sort((e,t)=>e.path<t.path?-1:e.path>t.path?1:0)}}var cs=/* @__PURE__ */e(Mo(),1);var ds=new Set(["chart","diagramData","diagramLayout","diagramQuickStyle","diagramColors","oleObject","package","image"].map(e=>"http://schemas.openxmlformats.org/officeDocument/2006/relationships/"+e)),us=(e,t)=>Object.hasOwn(e.parts,t),ps=e=>Array.from(e.childNodes).filter(e=>1===e.nodeType);function fs(e){if(/<!\s*(?:DOCTYPE|ENTITY)\b/i.test(e))throw Error("Unsupported XML declarations");const t=new _i.DOMParser({onError:()=>{throw Error("Invalid XML")}}).parseFromString(e,"application/xml");if(!t.documentElement)throw Error("Missing XML root");return t}function gs(e){return/^[A-Za-z0-9_.\-/]+$/.test(e)&&!e.startsWith("/")&&!e.split("/").some(e=>""===e||"."===e||".."===e)}function ms(e,t,n){const r=t.parts[e],o=n.parts[e];if(!r||!o||!gs(e)||r.kind!==o.kind||r.data!==o.data||r.contentType!==o.contentType||r.encoding!==o.encoding)return!1;const a=r.contentType??"";return/^word\/charts\//.test(e)&&/^application\/vnd\.(?:openxmlformats-officedocument\.drawingml\.chart|ms-office\.chart(?:style|colorstyle))\+xml$/i.test(a)||/^word\/diagrams\//.test(e)&&/^application\/vnd\.openxmlformats-officedocument\.drawingml\.diagram(?:Data|Layout|Style|Colors)\+xml$/i.test(a)||/^word\/embeddings\//.test(e)&&/^(?:application\/vnd\.openxmlformats-officedocument\.(?:spreadsheetml\.sheet|wordprocessingml\.document|presentationml\.presentation|oleObject)|application\/vnd\.ms-excel)$/i.test(a)||/^word\/media\//.test(e)&&/^image\//.test(a)}function hs(e,t){if(e.includes(t))return!0;const n=[fs(e).documentElement];for(;n.length;){const e=n.pop();if(Array.from(e.attributes).some(e=>e.value.includes(t)))return!0;for(const r of Array.from(e.childNodes))if(1===r.nodeType)n.push(r);else if(r.nodeValue?.includes(t))return!0}return!1}function bs(e,t){return e.id===t.id&&e.type===t.type&&e.mode===(t.targetMode??"Internal")&&e.resolved===t.resolvedTarget}function ys(e,t,n){const r=e=>({removeEdges:[],removeParts:[],...e?{skippedReason:e}:{}});if(!n.length)return r();try{if(e.mainDocumentPart!==t.mainDocumentPart)return r("Main part changed");if(Object.keys(t.parts).some(e=>e.startsWith("_xmlsignatures/")))return r("Signed package");const o=Kr(e),a=/* @__PURE__ */new Set,i=/* @__PURE__ */new Set;for(const b of n){const n=o.objects.filter(e=>e.signature===b.signature),s=1===n.length?n[0]:void 0;if(!s||s.ownerPath!==e.mainDocumentPart||s.ownerPath!==b.ownerPath||s.ordinal!==b.ordinal||s.issues.length)return r("Ambiguous deletion intent");for(const r of s.partPaths)ms(r,e,t)&&a.add(r);for(const e of s.relationshipIds)i.add(e)}if(!a.size)return r();const s=function(e){const t=[];for(const[n,r]of Object.entries(e.parts)){const o=Ko(n);if(void 0===o)continue;if(null!==o&&!us(e,o))throw Error("Relationship without owner");if("xml"!==r.kind)throw Error("Non-XML relationship part");const a=fs(r.data).documentElement;if("http://schemas.openxmlformats.org/package/2006/relationships"!==a.namespaceURI||"Relationships"!==a.localName)throw Error("Invalid relationship root");const i=/* @__PURE__ */new Set;for(const r of ps(a)){if("http://schemas.openxmlformats.org/package/2006/relationships"!==r.namespaceURI||"Relationship"!==r.localName)throw Error("Unknown relationship element");const a=r.getAttribute("Id"),s=r.getAttribute("Type"),l=r.getAttribute("Target"),c=r.getAttribute("TargetMode")||"Internal";if(!a||!s||!l||i.has(a)||"Internal"!==c&&"External"!==c)throw Error("Invalid or duplicate relationship");i.add(a);const d={owner:o,relPath:n,id:a,type:s,target:l,mode:c};if("Internal"===c){if(!/^[A-Za-z0-9_.\-/]+$/.test(l))throw Error("Ambiguous internal relationship URI");const t=Ka(o,l);if(!t||!gs(t)||!us(e,t)||void 0!==Ko(t)||"[Content_Types].xml"===t)throw Error("Unresolved internal relationship");d.resolved=t}t.push(d)}}return t}(t),l=t.parts[t.mainDocumentPart];if(!l||"xml"!==l.kind)return r("Missing main story XML");const c=/* @__PURE__ */new Set;for(const n of s)n.owner===t.mainDocumentPart&&"Internal"===n.mode&&n.resolved&&a.has(n.resolved)&&i.has(n.id)&&ds.has(n.type)&&e.parts[e.mainDocumentPart]?.relationships?.find(e=>bs(n,e))&&!hs(l.data,n.id)&&c.add(n);if(!c.size)return r();const d=/* @__PURE__ */new Map;for(const e of s)if(!c.has(e)){const t=d.get(e.owner)??[];t.push(e),d.set(e.owner,t)}const u=/* @__PURE__ */new Set,p=[null,...Object.keys(t.parts).filter(e=>!a.has(e)&&"[Content_Types].xml"!==e&&void 0===Ko(e))];for(let e=0;e<p.length;e++){const t=p[e];if(null!==t){if(u.has(t))continue;u.add(t)}for(const e of d.get(t)??[])e.resolved&&!u.has(e.resolved)&&p.push(e.resolved)}const f=/* @__PURE__ */new Set,g=[...c].flatMap(e=>e.resolved?[e.resolved]:[]);for(let e=0;e<g.length;e++){const t=g[e];if(a.has(t)&&!f.has(t)){f.add(t);for(const e of d.get(t)??[])e.resolved&&g.push(e.resolved)}}const m=[...f].filter(e=>!u.has(e)).sort(),h=new Set(m);for(const e of s)if(e.resolved&&h.has(e.resolved)&&!c.has(e)&&(null===e.owner||!h.has(e.owner)))return r("Retained incoming edge");return{removeEdges:[...c],removeParts:m}}catch(o){return r(o instanceof Error?o.message:String(o))}}var vs="word/comments.xml";function xs(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const r=e.childNodes[n];r?.nodeType===r.ELEMENT_NODE&&t.push(r)}return t}function ws(e){return e.localName??e.tagName}function Is(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(r?.localName===t)return r.value}}function Ss(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(!r)continue;const o=r.localName??r.name;(r.namespaceURI?t.hasAttributeNS(r.namespaceURI,o):t.hasAttribute(r.name))||(r.namespaceURI?t.setAttributeNS(r.namespaceURI,r.name,r.value):t.setAttribute(r.name,r.value))}}function Cs(e){let t="";for(const n of xs(e)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"===n.namespaceURI){if("t"===ws(n)){t+=n.textContent??"";continue}if("tab"===ws(n)){t+="\t";continue}if("br"===ws(n)||"cr"===ws(n)){t+="\n";continue}}t+=Cs(n)}return t}function ks(e){return xs(e).filter(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&"p"===ws(e))}function Ts(e){return ks(e).map(Cs).join("\n").trim()}function Ps(e){const t=(new _i.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"comments"===ws(t)?t:void 0}function Rs(e,t){const n=Is(ks(t)[0]??t,"paraId");for(;t.firstChild;)t.removeChild(t.firstChild);for(let o=0;o<e.childNodes.length;o+=1){const n=e.childNodes[o];n&&t.appendChild(n.cloneNode(!0))}const r=ks(t)[0];n&&r&&r.setAttributeNS(mo,"w14:paraId",n)}function As(e,t){const n=ks(e),r=ks(t);n[0]&&r[0]&&Vo(n[0],r[0]);const o=new Set(xs(t).filter(e=>e.namespaceURI!==Co).map(e=>`${e.namespaceURI??""}\0${ws(e)}`));for(const a of xs(e)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"===a.namespaceURI)continue;const e=`${a.namespaceURI??""}\0${ws(a)}`;o.has(e)||(t.appendChild(a.cloneNode(!0)),o.add(e))}}async function Ms(e,t){const n=function(e){const t=e.parts[e.mainDocumentPart]?.relationships?.find(e=>"External"!==e.targetMode&&e.type.endsWith("/comments")&&Boolean(e.resolvedTarget)),n=t?.resolvedTarget?e.parts[t.resolvedTarget]:void 0;return"xml"===n?.kind?n.data:void 0}(e),r=t.file(vs);if(!n||!r)return!1;const o=await r.async("string"),a=function(e,t){const n=Ps(e),r=Ps(t);if(!n||!r)return t;const o=/* @__PURE__ */new Map;for(const i of xs(r)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==i.namespaceURI||"comment"!==ws(i))continue;const e=Is(i,"id");void 0!==e&&o.set(e,i)}let a=!1;for(const i of xs(n)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==i.namespaceURI||"comment"!==ws(i))continue;const e=Is(i,"id"),t=void 0!==e?o.get(e):void 0;if(!t)continue;const n=(new _i.XMLSerializer).serializeToString(t);Ss(i,t),Ts(i)===Ts(t)?Rs(i,t):As(i,t),(new _i.XMLSerializer).serializeToString(t)!==n&&(a=!0)}return a?(new _i.XMLSerializer).serializeToString(r.ownerDocument):t}(n,o);return a!==o&&(t.file(vs,a),!0)}var Os="http://schemas.microsoft.com/office/word/2012/wordml",Bs="word/commentsExtended.xml";function Fs(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const r=e.childNodes[n];r?.nodeType===r.ELEMENT_NODE&&t.push(r)}return t}function Es(e){return e.localName??e.tagName}function Ds(e){return`${e.namespaceURI??""}\0${Es(e)}`}function Ls(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(r?.localName===t)return r.value}}function Ns(e,t,n){t.namespaceURI?e.setAttributeNS(t.namespaceURI,t.name,n):e.setAttribute(t.name,n)}function zs(e,t){const n=e.parts[e.mainDocumentPart]?.relationships?.find(e=>"External"!==e.targetMode&&e.type.endsWith(t)&&Boolean(e.resolvedTarget)),r=n?.resolvedTarget?e.parts[n.resolvedTarget]:void 0;return"xml"===r?.kind?r.data:void 0}function $s(e){const t=/* @__PURE__ */new Map,n=(new _i.DOMParser).parseFromString(e,"application/xml").documentElement;if(!n)return t;for(const r of Array.from(n.getElementsByTagNameNS(Co,"comment"))){const e=Ls(r,"id"),n=r.getElementsByTagNameNS(Co,"p").item(0),o=n?Ls(n,"paraId"):void 0;void 0!==e&&o&&t.set(e,o)}return t}function Hs(e){const t=(new _i.DOMParser).parseFromString(e,"application/xml").documentElement;return t?.namespaceURI===Os&&"commentsEx"===Es(t)?t:void 0}function Ws(e,t,n){for(let o=0;o<e.attributes.length;o+=1){const r=e.attributes.item(o);if(!r)continue;const a=r.localName??r.name;"paraId"!==a&&((r.namespaceURI?t.hasAttributeNS(r.namespaceURI,a):t.hasAttribute(r.name))||Ns(t,r,"paraIdParent"===a?n.get(r.value)??r.value:r.value))}const r=new Set(Fs(t).map(Ds));for(const o of Fs(e))r.has(Ds(o))||t.appendChild(o.cloneNode(!0))}function js(e,t,n,r){const o=Hs(t),a=Hs(r);if(!o||!a)return r;!function(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(!r)continue;const o=r.localName??r.name;(r.namespaceURI?t.hasAttributeNS(r.namespaceURI,o):t.hasAttribute(r.name))||Ns(t,r,r.value)}}(o,a);const i=$s(e),s=$s(n),l=/* @__PURE__ */new Map;for(const[p,f]of i){const e=s.get(p);e&&l.set(f,e)}const c=function(e){const t=/* @__PURE__ */new Map;for(const n of Fs(e)){if(n.namespaceURI!==Os||"commentEx"!==Es(n))continue;const e=Ls(n,"paraId");e&&t.set(e,n)}return t}(a),d=Fs(o),u=new Set(Fs(a).filter(e=>!(e.namespaceURI===Os&&"commentEx"===Es(e))).map(Ds));for(const p of d){if(p.namespaceURI===Os&&"commentEx"===Es(p)){const e=Ls(p,"paraId"),t=e?l.get(e):void 0,n=t?c.get(t):void 0;n&&Ws(p,n,l);continue}u.has(Ds(p))||(a.appendChild(p.cloneNode(!0)),u.add(Ds(p)))}return(new _i.XMLSerializer).serializeToString(a.ownerDocument)}var Us="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function Vs(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const r=e.childNodes[n];r?.nodeType===r.ELEMENT_NODE&&t.push(r)}return t}function Ks(e){return e.localName??e.tagName}function _s(e){return`${e.namespaceURI??""}\0${Ks(e)}`}function Xs(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(r?.localName===t)return r.value}}function qs(e,t){return Vs(e).find(e=>e.namespaceURI===Us&&Ks(e)===t)}function Gs(e,t){return e.filter(e=>e.namespaceURI===Us&&t.has(Ks(e)))}function Ys(e){if(e.namespaceURI!==Us)return;const t=Ks(e);if("p"===t){const t=Xs(e,"paraId");return t?`p:${t}`:void 0}if("sdt"===t){const t=qs(e,"sdtPr"),n=t?qs(t,"id"):void 0,r=n?Xs(n,"val"):void 0;return r?`sdt:${r}`:void 0}}function Zs(e,t,n){const r=(new _i.DOMParser).parseFromString(e,"application/xml"),o=(new _i.DOMParser).parseFromString(t,"application/xml"),a=r.documentElement,i=o.documentElement;if(!a||!i||a.namespaceURI!==Us||i.namespaceURI!==Us||Ks(a)!==n||Ks(i)!==n)return t;!function(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(!r)continue;const o=r.localName??r.name;(r.namespaceURI?t.hasAttributeNS(r.namespaceURI,o):t.hasAttribute(r.name))||(r.namespaceURI?t.setAttributeNS(r.namespaceURI,r.name,r.value):t.setAttribute(r.name,r.value))}}(a,i);const s=Vs(a),l=Vs(i),c=new Set(l.map(_s));return s.forEach((e,t)=>{if(e.namespaceURI===Us||c.has(_s(e)))return;const n=s.slice(t+1).map(e=>l.find(t=>_s(t)===_s(e))).find(e=>Boolean(e));i.insertBefore(e.cloneNode(!0),n??null)}),(new _i.XMLSerializer).serializeToString(o)}function Js(e,t,n,r=/* @__PURE__ */new Set(["p","tbl","sdt"])){const o=Zs(e,t,n),a=(new _i.DOMParser).parseFromString(e,"application/xml"),i=(new _i.DOMParser).parseFromString(o,"application/xml"),s=a.documentElement,l=i.documentElement;if(!s||!l||s.namespaceURI!==Us||l.namespaceURI!==Us||Ks(s)!==n||Ks(l)!==n)return o;const c=Vs(s),d=Vs(l),u=function(e,t,n){const r=Gs(e,n),o=Gs(t,n);return r.length===o.length&&r.every((e,t)=>Ks(e)===Ks(o[t]))}(c,d,r),p=/* @__PURE__ */new Map;return c.forEach((e,t)=>{if(e.namespaceURI!==Us||r.has(Ks(e)))return;const n=_s(e),o=p.get(n)??0;if(p.set(n,o+1),Vs(l).filter(e=>_s(e)===n)[o])return;const a=function(e,t,n,r,o){const a=e.slice(t+1).find(e=>e.namespaceURI===Us&&r.has(Ks(e)));if(!a)return;const i=Ys(a);if(i){const e=Gs(n,r).find(e=>Ys(e)===i);if(e)return e}if(!o)return;const s=Gs(e,r),l=Gs(n,r),c=s.indexOf(a);return c>=0?l[c]:void 0}(c,t,d,r,u);(a||u)&&l.insertBefore(e.cloneNode(!0),a??null)}),(new _i.XMLSerializer).serializeToString(i)}var Qs="word/document.xml",el=/* @__PURE__ */new Set(["p","tbl","sdt","sectPr"]);function tl(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const r=e.childNodes[n];r?.nodeType===r.ELEMENT_NODE&&t.push(r)}return t}function nl(e){return e.localName??e.tagName}function rl(e){return`${e.namespaceURI??""}\0${nl(e)}`}function ol(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(r?.localName===t)return r.value}}function al(e,t){return tl(e).find(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&nl(e)===t)}function il(e){return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&el.has(nl(e))}function sl(e){return e.filter(il)}function ll(e){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==e.namespaceURI)return;const t=nl(e);if("p"===t){const t=ol(e,"paraId");return t?`p:${t}`:void 0}if("sdt"===t){const t=al(e,"sdtPr"),n=t?ol(al(t,"id")??t,"val"):void 0;return n?`sdt:${n}`:void 0}return"sectPr"===t?"sectPr:final":void 0}function cl(e,t){const n=(new _i.DOMParser).parseFromString(e,"application/xml"),r=(new _i.DOMParser).parseFromString(t,"application/xml"),o=n.documentElement,a=r.documentElement;if(!o||!a||"http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==o.namespaceURI||"http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==a.namespaceURI||"document"!==nl(o)||"document"!==nl(a))return t;!function(e,t){const n=tl(e),r=al(t,"body");if(!r)return;let o=r;const a=n.filter(e=>!("http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&"body"===nl(e))),i=/* @__PURE__ */new Set;for(let s=a.length-1;s>=0;s-=1){const e=a[s],n=tl(t).find(t=>!i.has(t)&&rl(t)===rl(e)),r=n??e.cloneNode(!0);n&&i.add(n),t.insertBefore(r,o),o=r}}(o,a);const i=al(o,"body"),s=al(a,"body");if(!i||!s)return t;!function(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(!r)continue;const o=r.localName??r.name;(r.namespaceURI?t.hasAttributeNS(r.namespaceURI,o):t.hasAttribute(r.name))||(r.namespaceURI?t.setAttributeNS(r.namespaceURI,r.name,r.value):t.setAttribute(r.name,r.value))}}(i,s);const l=tl(i),c=tl(s),d=function(e,t){const n=sl(e),r=sl(t);return n.length===r.length&&n.every((e,t)=>nl(e)===nl(r[t]))}(l,c),u=/* @__PURE__ */new Map;return l.forEach((e,t)=>{if(il(e))return;const n=rl(e),r=u.get(n)??0;if(u.set(n,r+1),tl(s).filter(e=>rl(e)===n)[r])return;const o=function(e,t,n){const r=e.slice(t+1).find(il);if(!r)return;const o=ll(r);return o?sl(n).find(e=>ll(e)===o):void 0}(l,t,c),a=d?function(e,t,n){const r=sl(e),o=sl(n),a=e.slice(t+1).find(il);if(a){const e=r.indexOf(a);if(e>=0)return o[e]}}(l,t,c):void 0,i=o??a;("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==e.namespaceURI||i)&&s.insertBefore(e.cloneNode(!0),i??function(e){return[...e].reverse().find(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&"sectPr"===nl(e))}(c)??null)}),(new _i.XMLSerializer).serializeToString(r)}async function dl(e,t){const n=e.parts[e.mainDocumentPart],r=t.file(Qs);if("xml"!==n?.kind||!r)return!1;const o=await r.async("string"),a=function(e,t){return cl(e,Zs(e,t,"document"))}(n.data,o);return a!==o&&(t.file(Qs,a),!0)}function ul(e){return e.getAttributeNS("http://schemas.openxmlformats.org/officeDocument/2006/relationships","id")||void 0}function pl(e){return e.getAttributeNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","type")||"default"}function fl(e,t){const n=e.getAttributeNodeNS(oo,"id");return!(!n||n.value===t)&&(e.setAttributeNS(oo,n.name,t),!0)}var gl="word/document.xml",ml="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function hl(e){const t=(new _i.DOMParser).parseFromString(e,"application/xml");return Array.from(t.getElementsByTagNameNS(ml,"sectPr")).filter(e=>Boolean(e)&&"sectPrChange"!==e.parentNode?.localName)}function bl(e){const t=[];return hl(e).forEach((e,n)=>{const r=/* @__PURE__ */new Map;for(const o of function(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const r=e.childNodes[n];r?.nodeType===r.ELEMENT_NODE&&t.push(r)}return t}(e)){const e=o.namespaceURI===ml&&"headerReference"===o.localName?"header":o.namespaceURI===ml&&"footerReference"===o.localName?"footer":void 0;if(!e)continue;const a=ul(o);if(!a)continue;const i=pl(o),s=`${e}:${i}`,l=r.get(s)??0;r.set(s,l+1),t.push({key:`${n}:${e}:${i}:${l}`,kind:e,relationshipId:a})}}),t}function yl(e){return new Map(e.map(e=>[e.id,e]))}async function vl(e,t){const n=e.parts[e.mainDocumentPart],r=await(t.file(gl)?.async("string"));if("xml"!==n?.kind||!r)return!1;const o=hl(n.data),a=hl(r);if(o.length!==a.length)return!1;const i=bl(n.data),s=bl(r),l=new Map(i.map(e=>[e.key,e])),c=yl(n.relationships??[]),d=yl(await async function(e){const t=await(e.file(function(e){const t=e.lastIndexOf("/"),n=t>=0?e.slice(0,t):"",r=t>=0?e.slice(t+1):e;return n?`${n}/_rels/${r}.rels`:`_rels/${r}.rels`}(gl))?.async("string"));return Vr(gl,Bo(t))}(t));let u=!1;for(const p of s){const n=l.get(p.key);if(!n||n.kind!==p.kind)continue;const r=c.get(n.relationshipId),o=d.get(p.relationshipId);if("External"===r?.targetMode||"External"===o?.targetMode||!r?.resolvedTarget||!o?.resolvedTarget)continue;const a=e.parts[r.resolvedTarget];if("xml"!==a?.kind)continue;const i=o.resolvedTarget,s=await(t.file(i)?.async("string"));if(!s)continue;const f="header"===p.kind?"hdr":"ftr",g=Js(a.data,s,f);g!==s&&(t.file(i,g),u=!0)}return u}var xl="word/document.xml",wl={"/styles":"word/styles.xml","/numbering":"word/numbering.xml","/settings":"word/settings.xml","/fontTable":"word/fontTable.xml","/theme":"word/theme/theme1.xml","/footnotes":"word/footnotes.xml","/endnotes":"word/endnotes.xml","/comments":"word/comments.xml","/commentsExtended":"word/commentsExtended.xml"},Il=["/officeDocument",...Object.keys(wl)];function Sl(e){return[e.type,e.target,e.targetMode??"Internal"].join("\0")}function Cl(e){const t=e.lastIndexOf("/"),n=t>=0?e.slice(0,t):"",r=t>=0?e.slice(t+1):e;return n?`${n}/_rels/${r}.rels`:`_rels/${r}.rels`}function kl(e){for(const[t,n]of Object.entries(wl))if(e.type.endsWith(t))return n}function Tl(e,t){if("[Content_Types].xml"===e||"_rels/.rels"===e)return e;const n=Ko(e);return void 0===n?t.get(e)??e:null===n?e:Cl(t.get(n)??n)}function Pl(e,t){for(const[n,r]of t)if(r===e)return n;return e}function Rl(e,t){if(null===e)return t;const n=function(e){const t=e.lastIndexOf("/");return t<0?[]:e.slice(0,t).split("/")}(e),r=t.split("/");let o=0;for(;o<n.length&&o<r.length&&n[o]===r[o];)o+=1;return[...Array.from({length:n.length-o},()=>".."),...r.slice(o)].join("/")}function Al(e,t){const n=e.parts[t];return"xml"===n?.kind?Bo(n.data):[]}function Ml(e,t){const n=null===t?e.rootRelationships.length>0?e.rootRelationships:Al(e,Ti):e.parts[t]?.relationships??Al(e,Cl(t));return Vr(t,n)}function Ol(e,t,n){return Ml(e,t).filter(e=>"External"===e.targetMode||!e.resolvedTarget||!n.has(e.resolvedTarget))}function Bl(e,t,n,r,o){return e.map(e=>{if("External"===e.targetMode)return e;const a=(i=e.type,Il.find(e=>i.endsWith(e)));var i;const s=a?t.find(e=>"External"!==e.targetMode&&e.type.endsWith(a)):void 0,l=Vr(n,[e])[0]?.resolvedTarget,c=s?.resolvedTarget??(l?o.get(l)??l:void 0);return c?{...e,...s?{id:s.id,type:s.type}:{},target:Rl(r,c),targetMode:"Internal",resolvedTarget:c}:e})}function Fl(e,t,n){const r=[...t],o=new Map(t.map(e=>[e.id,e]));for(const a of e){const e=o.get(a.id);if(e){if(Sl(e)===Sl(a))continue;throw new Error(`Cannot safely preserve ${n}: relationship id ${a.id} is used by both the source package and rebuilt document for different targets.`)}r.push(a)}return r}function El(e,t,n){const r=t.parts[n];r&&("base64"===r.encoding?e.file(n,r.data,{base64:!0}):e.file(n,r.data))}function Dl(e,t,n,r){const o=e.rebuiltPartHashes?.[t];return Boolean(o&&e.parts[n]&&o===ca(r))}async function Ll(e,t){const n=e.sourcePackage;if(!n)return t;const r=await cs.default.loadAsync(t),o=new Set(Object.entries(r.files).filter(([,e])=>!e.dir).map(([e])=>no(e))),a=function(e){const t=/* @__PURE__ */new Map;t.set(xl,e.mainDocumentPart);const n=e.parts[e.mainDocumentPart];for(const r of n?.relationships??[]){if("External"===r.targetMode||!r.resolvedTarget)continue;const e=kl(r);e&&t.set(e,r.resolvedTarget)}return t}(n),i=function(e,t,n){const r=/* @__PURE__ */new Set;for(const[o,a]of t)o!==xl&&e.rebuiltPartHashes?.[o]&&!n.has(o)&&e.parts[a]&&r.add(a);return r}(n,a,o),s=new cs.default;for(const c of Object.keys(n.parts))El(s,n,c);for(const c of i)s.remove(c),s.remove(Cl(c));!function(e,t,n,r,o){if(0!==o.size)for(const a of Object.keys(t.parts)){const i=Ko(a);if(null==i)continue;const s=Ml(t,i),l=s.filter(e=>"External"===e.targetMode||!e.resolvedTarget||!o.has(e.resolvedTarget));if(l.length===s.length)continue;const c=Pl(i,n);r.has(Cl(c))||(0===l.length?e.remove(a):e.file(a,To(l)))}}(s,n,a,o,i);let l=null;for(const[c,d]of Object.entries(r.files)){if(d.dir)continue;const e=no(c);if("[Content_Types].xml"===e){l=await d.async("string");continue}const t=Tl(e,a),r=Ko(e);if(void 0!==r){const e=r,o=null===e?null:a.get(e)??e,l=Ol(n,o,i),c=Fl(l,Bl(Bo(await d.async("string")),l,e,o,a),t);s.file(t,To(c));continue}const o=await d.async("uint8array");Dl(n,e,t,o)||s.file(t,o)}return l&&s.file(Uo,function(e,t,n,r){const o=Qr(t),a={};for(const[s,l]of Object.entries(o.overrides))a[n.get(s)??s]=l;const i=Object.fromEntries(Object.entries(e.overrides).filter(([e])=>!r.has(e)));return Wa({defaults:{...e.defaults,...o.defaults},overrides:{...i,...a}})}(n.contentTypes,l,a,i)),s.generateAsync({type:"arraybuffer"})}var Nl="word/document.xml",zl=["first","even","default"];function $l(e){const t=e.lastIndexOf("/"),n=t>=0?e.slice(0,t):"",r=t>=0?e.slice(t+1):e;return n?`${n}/_rels/${r}.rels`:`_rels/${r}.rels`}function Hl(e,t){const n=function(e){const t=e.lastIndexOf("/");return t<0?[]:e.slice(0,t).split("/")}(e),r=t.split("/");let o=0;for(;o<n.length&&o<r.length&&n[o]===r[o];)o+=1;return[...Array.from({length:n.length-o},()=>".."),...r.slice(o)].join("/")}function Wl(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const r=e.childNodes[n];r?.nodeType===r.ELEMENT_NODE&&t.push(r)}return t}function jl(e,t){const n=[],r=e=>{for(const o of Wl(e))"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===o.namespaceURI&&o.localName===t&&n.push(o),r(o)};return r(e),n}function Ul(e){const t=(new _i.DOMParser).parseFromString(e,"application/xml"),n=[],r=jl(t,"sectPr").filter(e=>"sectPrChange"!==e.parentNode?.localName);return r.forEach((e,t)=>{const r=/* @__PURE__ */new Map;for(const o of Wl(e)){const e="http://schemas.openxmlformats.org/wordprocessingml/2006/main"===o.namespaceURI&&"headerReference"===o.localName?"header":"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===o.namespaceURI&&"footerReference"===o.localName?"footer":void 0;if(!e)continue;const a=ul(o);if(!a)continue;const i=pl(o),s=`${e}:${i}`,l=r.get(s)??0;r.set(s,l+1),n.push({key:`${t}:${e}:${i}:${l}`,sectionIndex:t,kind:e,type:i,occurrence:l,relationshipId:a})}}),{references:n,sectionCount:r.length}}function Vl(e,t){const n=e.parts[t];return"xml"===n?.kind?n.data:void 0}function Kl(e,t){const n=e.parts[t]?.relationships??Bo(Vl(e,$l(t)));return Vr(t,n)}function _l(e,t){const n=new Map(t.map(e=>[e.id,e]));return e.flatMap(e=>{const t=n.get(e.relationshipId);if(!t||"External"===t.targetMode||!t.resolvedTarget)return[];const r="header"===e.kind?"/header":"/footer";return t.type.endsWith(r)?[{...e,relationship:t,partPath:t.resolvedTarget}]:[]})}async function Xl(e,t){const n=Vl(e,e.mainDocumentPart),r=await(t.file(Nl)?.async("string"));if(!n||!r)return{matches:[],deletedSourcePartPaths:/* @__PURE__ */new Set,sourceRelationshipByCurrentId:/* @__PURE__ */new Map};const o=Ul(n),a=Ul(r),i=_l(o.references,Kl(e,e.mainDocumentPart));!function(e){const t=[...e].sort((e,t)=>{if(e.sectionIndex!==t.sectionIndex)return e.sectionIndex-t.sectionIndex;if(e.kind!==t.kind)return"header"===e.kind?-1:1;const n=zl.indexOf(e.type),r=zl.indexOf(t.type),o=n<0?99:n,a=r<0?99:r;return o!==a?o-a:e.type!==t.type?e.type.localeCompare(t.type):e.occurrence-t.occurrence});let n=1,r=1;for(const o of t)"header"===o.kind?(o.baselinePath=`word/header${n}.xml`,n+=1):(o.baselinePath=`word/footer${r}.xml`,r+=1)}(i);const s=_l(a.references,await async function(e,t){const n=await(e.file($l(t))?.async("string"));return Vr(t,Bo(n))}(t,Nl)),l=new Map(i.map(e=>[e.key,e])),c=[],d=/* @__PURE__ */new Set,u=/* @__PURE__ */new Map;for(const p of s){const e=l.get(p.key);e&&(c.push({current:p,source:e}),d.add(e.partPath),u.set(p.relationshipId,e.relationship))}return{matches:c,deletedSourcePartPaths:o.sectionCount===a.sectionCount?new Set(i.map(e=>e.partPath).filter(e=>!d.has(e))):/* @__PURE__ */new Set,sourceRelationshipByCurrentId:u}}function ql(e){return[e.type,e.target,e.targetMode??"Internal"].join("\0")}async function Gl(e,t,n,r){if(!r)return!1;const o=t.rebuiltPartHashes?.[r],a=e.file(n);return a?!!o&&o===ca(await a.async("uint8array")):void 0===o}async function Yl(e,t,n,r){for(const o of n)if(!(await Gl(e,t,r?$l(o.current.partPath):o.current.partPath,o.source.baselinePath?r?$l(o.source.baselinePath):o.source.baselinePath:void 0)))return!1;return!0}async function Zl(e,t,n){if(t.length<2)return;const r=/* @__PURE__ */new Set;for(const o of t){const t=n?$l(o.current.partPath):o.current.partPath,a=await(e.file(t)?.async("uint8array"));r.add(a?ca(a):"<missing>")}if(r.size>1)throw new Error(`Cannot safely preserve shared header/footer part ${t[0].source.partPath}: its section projections diverged after editing.`)}async function Jl(e,t,n){const r=await(e.file(Nl)?.async("string"));if(r){const o=t.rebuiltPartHashes?.[Nl],a=ca((new TextEncoder).encode(r));if(!o||o!==a){const t=function(e,t){const n=(new _i.DOMParser).parseFromString(e,"application/xml");let r=!1;for(const o of["headerReference","footerReference"])for(const e of jl(n,o)){const n=ul(e),o=n?t.get(n):void 0;o&&(r=fl(e,o.id)||r)}return r?(new _i.XMLSerializer).serializeToString(n):void 0}(r,n.sourceRelationshipByCurrentId);t&&e.file(Nl,t)}}const o=$l(Nl),a=Bo(await(e.file(o)?.async("string"))).map(e=>{const t=n.sourceRelationshipByCurrentId.get(e.id);return t?.resolvedTarget?{...t,target:Hl(Nl,t.resolvedTarget),targetMode:"Internal"}:e});e.file(o,To(function(e,t){const n=[],r=/* @__PURE__ */new Map;for(const o of e){const e=r.get(o.id);if(e){if(ql(e)===ql(o))continue;throw new Error(`Cannot safely preserve ${t}: relationship id ${o.id} is used for different targets.`)}r.set(o.id,o),n.push(o)}return n}(a,o)))}async function Ql(e,t,n){const r=n[0],o=r.source.partPath;if(!(await Yl(e,t,n,!1))){await Zl(e,n,!1);const t=await(e.file(r.current.partPath)?.async("uint8array"));if(!t)throw new Error(`Cannot preserve ${o}: rebuilt header/footer part is missing.`);e.file(o,t)}for(const i of n)i.current.partPath!==o&&e.remove(i.current.partPath);const a=$l(o);if(!(await Yl(e,t,n,!0))){await Zl(e,n,!0);const t=$l(r.current.partPath),i=await(e.file(t)?.async("string"));i&&e.file(a,To(function(e,t,n){return e.map(e=>{if("External"===e.targetMode)return e;const r=Vr(t,[e])[0]?.resolvedTarget;return r?{...e,target:Hl(n,r),targetMode:"Internal",resolvedTarget:r}:e})}(Bo(i),r.current.partPath,o)))}for(const i of n){const t=$l(i.current.partPath);t!==a&&e.remove(t)}}async function ec(e,t,n){for(const r of function(e){const t=/* @__PURE__ */new Map;for(const n of e){const e=t.get(n.source.partPath)??[];e.push(n),t.set(n.source.partPath,e)}return t}(n.matches).values())await Ql(e,t,r)}async function tc(e,t){const n=e.sourcePackage;if(!n)return t;const r=await cs.default.loadAsync(t),o=await Xl(n,r);o.matches.length>0&&(await Jl(r,n,o),await ec(r,n,o),await async function(e,t){const n=await(e.file(Uo)?.async("string"));if(!n)return;const r=Qr(n);for(const o of t.matches){const e=r.overrides[o.current.partPath];e&&(r.overrides[o.source.partPath]=e),o.current.partPath!==o.source.partPath&&delete r.overrides[o.current.partPath]}e.file(Uo,Wa(r))}(r,o));const a=o.matches.length>0?await r.generateAsync({type:"arraybuffer"}):t;return Ll(function(e,t){const n=e.sourcePackage;if(!n||0===t.size)return e;const r={defaults:{...n.contentTypes.defaults},overrides:Object.fromEntries(Object.entries(n.contentTypes.overrides).filter(([e])=>!t.has(e)))},o={...n.parts};for(const d of t)delete o[d],delete o[$l(d)];const a=o[n.mainDocumentPart],i=Kl(n,n.mainDocumentPart).filter(e=>"External"===e.targetMode||!e.resolvedTarget||!t.has(e.resolvedTarget));a&&(o[n.mainDocumentPart]={...a,relationships:i});const s=$l(n.mainDocumentPart),l=o[s];l&&(o[s]={...l,data:To(i)});const c=o[Uo];return c&&(o[Uo]={...c,data:Wa(r)}),{...e,sourcePackage:{...n,contentTypes:r,parts:o}}}(e,o.deletedSourcePartPaths),a)}var nc=[{kind:"footnote",relationshipSuffix:"/footnotes",rebuiltPath:"word/footnotes.xml",rootName:"footnotes",entryName:"footnote"},{kind:"endnote",relationshipSuffix:"/endnotes",rebuiltPath:"word/endnotes.xml",rootName:"endnotes",entryName:"endnote"}],rc=/* @__PURE__ */new Set(["p","tbl"]),oc=/* @__PURE__ */new Set(["separator","continuationSeparator","continuationNotice"]);function ac(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const r=e.childNodes[n];r?.nodeType===r.ELEMENT_NODE&&t.push(r)}return t}function ic(e){return e.localName??e.tagName}function sc(e){return`${e.namespaceURI??""}\0${ic(e)}`}function lc(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(r?.localName===t)return r.value}}function cc(e,t){const n=e.parts[e.mainDocumentPart]?.relationships?.find(e=>"External"!==e.targetMode&&e.type.endsWith(t)&&Boolean(e.resolvedTarget)),r=n?.resolvedTarget?e.parts[n.resolvedTarget]:void 0;return"xml"===r?.kind?r.data:void 0}function dc(e,t){const n=(new _i.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===n?.namespaceURI&&ic(n)===t?n:void 0}function uc(e){const t=lc(e,"type");if(t&&oc.has(t))return`type:${t}`;const n=lc(e,"id");return n?`id:${n}`:void 0}function pc(e){return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&rc.has(ic(e))}function fc(e){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==e.namespaceURI||"p"!==ic(e))return;const t=lc(e,"paraId");return t?`p:${t}`:void 0}function gc(e,t){!function(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(!r)continue;const o=r.localName??r.name;(r.namespaceURI?t.hasAttributeNS(r.namespaceURI,o):t.hasAttribute(r.name))||(r.namespaceURI?t.setAttributeNS(r.namespaceURI,r.name,r.value):t.setAttribute(r.name,r.value))}}(e,t);const n=ac(e),r=ac(t),o=function(e,t){const n=e.filter(pc),r=t.filter(pc);return n.length===r.length&&n.every((e,t)=>ic(e)===ic(r[t]))}(n,r),a=/* @__PURE__ */new Map;n.forEach((e,i)=>{if(pc(e))return;const s=sc(e),l=a.get(s)??0;if(a.set(s,l+1),ac(t).filter(e=>sc(e)===s)[l])return;const c=function(e,t,n,r){const o=e.slice(t+1).find(pc);if(!o)return;const a=fc(o);if(a){const e=n.filter(pc).find(e=>fc(e)===a);if(e)return e}if(!r)return;const i=e.filter(pc),s=n.filter(pc),l=i.indexOf(o);return l>=0?s[l]:void 0}(n,i,r,o);("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==e.namespaceURI||c||o)&&t.insertBefore(e.cloneNode(!0),c??null)})}function mc(e,t,n,r){const o=dc(t,r.rootName),a=dc(n,r.rootName);if(!o||!a)return n;const i=ac(o).filter(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&ic(e)===r.entryName),s=/* @__PURE__ */new Map;for(const c of ac(a)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==c.namespaceURI||ic(c)!==r.entryName)continue;const e=uc(c);e&&s.set(e,c)}const l=function(e,t){const n="footnote"===t?e.footnotes?.items:e.endnotes?.items,r=/* @__PURE__ */new Set;for(const o of Object.values(n??{}))void 0!==o.docxId&&Number.isSafeInteger(o.docxId)&&o.docxId>=1&&r.add(String(o.docxId));return r}(e,r.kind);for(const c of i){const e=uc(c);if(!e)continue;const t=s.get(e),n=lc(c,"type");if(t){n&&oc.has(n)?a.replaceChild(c.cloneNode(!0),t):gc(c,t);continue}if("continuationNotice"===n){a.appendChild(c.cloneNode(!0));continue}const r=lc(c,"id");r&&l.has(r)&&a.appendChild(c.cloneNode(!0))}return(new _i.XMLSerializer).serializeToString(a.ownerDocument)}var hc="http://schemas.openxmlformats.org/wordprocessingml/2006/main",bc="word/numbering.xml";function yc(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const r=e.childNodes[n];r?.nodeType===r.ELEMENT_NODE&&t.push(r)}return t}function vc(e){return e.localName??e.tagName}function xc(e){return`${e.namespaceURI??""}\0${vc(e)}`}function wc(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(r?.localName===t)return r.value}}function Ic(e,t,n){for(let r=0;r<e.attributes.length;r+=1){const o=e.attributes.item(r);if(o?.localName===t)return void e.setAttribute(o.name,n)}e.setAttributeNS(hc,`w:${t}`,n)}function Sc(e,t){return yc(e).find(e=>e.namespaceURI===hc&&vc(e)===t)}function Cc(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(!r)continue;const o=r.localName??r.name;(r.namespaceURI?t.hasAttributeNS(r.namespaceURI,o):t.hasAttribute(r.name))||(r.namespaceURI?t.setAttributeNS(r.namespaceURI,r.name,r.value):t.setAttribute(r.name,r.value))}}function kc(e,t){const n=new Set(yc(t).map(xc));for(const r of yc(e))r.namespaceURI===hc||n.has(xc(r))||t.appendChild(r.cloneNode(!0))}function Tc(e,t,n,r,o){const a=e.slice(t+1).map(o).find(e=>Boolean(e));r.insertBefore(n.cloneNode(!0),a??null)}var Pc=/* @__PURE__ */new Set(["start","numFmt","lvlRestart","pStyle","lvlText","lvlJc","suff","isLgl"]);function Rc(e,t){Cc(e,t);const n=yc(e),r=new Map(yc(t).map(e=>[xc(e),e]));n.forEach((e,o)=>{const a=xc(e),i=r.get(a),s=vc(e);if(i)return Cc(e,i),void(e.namespaceURI===hc&&"rPr"===s?function(e,t){Cc(e,t);const n=yc(e),r=new Map(yc(t).map(e=>[xc(e),e]));n.forEach((e,o)=>{const a=xc(e),i=r.get(a);if(i)return Cc(e,i),void kc(e,i);e.namespaceURI===hc&&"rFonts"===vc(e)||Tc(n,o,e,t,e=>r.get(xc(e)))})}(e,i):kc(e,i));if(e.namespaceURI!==hc||!Pc.has(s)){if(e.namespaceURI===hc&&"rPr"===s){const n=function(e){const t=e.cloneNode(!1);let n=!1;for(const r of yc(e))r.namespaceURI===hc&&"rFonts"===vc(r)||(t.appendChild(r.cloneNode(!0)),n=!0);return n?t:void 0}(e);return void(n&&t.appendChild(n))}Tc(n,o,e,t,e=>r.get(xc(e)))}})}function Ac(e){return function(e){return e.namespaceURI===hc&&"lvl"===vc(e)?`${xc(e)}\0${wc(e,"ilvl")??"0"}`:xc(e)}(e)}function Mc(e,t,n){const r=Sc(t,"abstractNumId"),o=r?wc(r,"val"):void 0;if(!o)return;const a=yc(e).find(e=>e.namespaceURI===hc&&"abstractNum"===vc(e)&&wc(e,"abstractNumId")===o);return a?yc(a).find(e=>e.namespaceURI===hc&&"lvl"===vc(e)&&(wc(e,"ilvl")??"0")===n):void 0}function Oc(e,t){const n=t.cloneNode(!0);Rc(e,n);const r=Sc(e,"pPr"),o=Sc(n,"pPr");return r?o?n.replaceChild(r.cloneNode(!0),o):n.appendChild(r.cloneNode(!0)):o&&n.removeChild(o),n}function Bc(e,t){if(!t)return e.cloneNode(!0);const n=e.cloneNode(!1),r=wc(Sc(t,"start")??t,"val")??"1";for(const o of yc(e)){const e=vc(o);if(o.namespaceURI===hc&&"startOverride"===e){const e=o.cloneNode(!0);Ic(e,"val",r),n.appendChild(e);continue}o.namespaceURI!==hc||"lvl"!==e?n.appendChild(o.cloneNode(!0)):n.appendChild(Oc(o,t))}return n}function Fc(e){if(e.namespaceURI!==hc)return xc(e);const t=vc(e);return"abstractNum"===t?`${xc(e)}\0${wc(e,"abstractNumId")??""}`:"num"===t?`${xc(e)}\0${wc(e,"numId")??""}`:xc(e)}function Ec(e,t){const n=function(e,t){const n=(new _i.DOMParser).parseFromString(e,"application/xml").documentElement,r=(new _i.DOMParser).parseFromString(t,"application/xml").documentElement;if(n&&r&&n.namespaceURI===hc&&r.namespaceURI===hc&&"numbering"===vc(n)&&"numbering"===vc(r))return{sourceRoot:n,rebuiltRoot:r}}(e,t);if(!n)return t;const{sourceRoot:r,rebuiltRoot:o}=n;Cc(r,o);const a=yc(r),i=new Map(yc(o).map(e=>[Fc(e),e]));return a.forEach((e,t)=>{const n=Fc(e),r=i.get(n),s=vc(e);if(r)return Cc(e,r),void(e.namespaceURI===hc&&"abstractNum"===s?function(e,t){Cc(e,t);const n=yc(e),r=new Map(yc(t).map(e=>[Ac(e),e]));n.forEach((e,o)=>{const a=Ac(e),i=r.get(a);if(i)return Cc(e,i),void(e.namespaceURI===hc&&"lvl"===vc(e)?Rc(e,i):kc(e,i));Tc(n,o,e,t,e=>r.get(Ac(e)))})}(e,r):e.namespaceURI===hc&&"num"===s?function(e,t,n){Cc(e,t);const r=Sc(t,"abstractNumId"),o=/* @__PURE__ */new Map;for(const a of yc(t))a.namespaceURI===hc&&"lvlOverride"===vc(a)&&o.set(wc(a,"ilvl")??"0",a);for(const a of yc(e)){const e=vc(a);if(a.namespaceURI!==hc||"abstractNumId"!==e){if(a.namespaceURI===hc&&"lvlOverride"===e){const e=wc(a,"ilvl")??"0",r=Bc(a,Mc(n,t,e)),i=o.get(e);i?t.replaceChild(r,i):t.appendChild(r),o.set(e,r);continue}a.namespaceURI===hc||yc(t).some(e=>xc(e)===xc(a))||t.appendChild(a.cloneNode(!0))}else r&&(Cc(a,r),kc(a,r))}}(e,r,o):kc(e,r));Tc(a,t,e,o,e=>i.get(Fc(e)))}),(new _i.XMLSerializer).serializeToString(o.ownerDocument)}async function Dc(e,t){const n=function(e){const t=e.parts[e.mainDocumentPart]?.relationships?.find(e=>"External"!==e.targetMode&&e.type.endsWith("/numbering")&&Boolean(e.resolvedTarget)),n=t?.resolvedTarget?e.parts[t.resolvedTarget]:void 0;return"xml"===n?.kind?n.data:void 0}(e),r=t.file(bc);if(!n||!r)return!1;const o=await r.async("string"),a=Ec(n,o);return a!==o&&(t.file(bc,a),!0)}var Lc=[{relationshipSuffix:"/footnotes",rebuiltPath:"word/footnotes.xml",rootLocalName:"footnotes"},{relationshipSuffix:"/endnotes",rebuiltPath:"word/endnotes.xml",rootLocalName:"endnotes"},{relationshipSuffix:"/comments",rebuiltPath:"word/comments.xml",rootLocalName:"comments"}];function Nc(e,t){const n=e.parts[e.mainDocumentPart]?.relationships?.find(e=>"External"!==e.targetMode&&e.type.endsWith(t)&&Boolean(e.resolvedTarget)),r=n?.resolvedTarget?e.parts[n.resolvedTarget]:void 0;return"xml"===r?.kind?r.data:void 0}var zc="http://schemas.openxmlformats.org/wordprocessingml/2006/main",$c=/* @__PURE__ */new Set(["headerReference","footerReference","type","pgSz","pgMar","pgNumType","cols","vAlign","bidi"]);function Hc(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const r=e.childNodes[n];r?.nodeType===r.ELEMENT_NODE&&t.push(r)}return t}function Wc(e){return e.localName??e.tagName}function jc(e){return`${e.namespaceURI??""}\0${Wc(e)}`}function Uc(e){const t=[],n=e=>{for(const r of Hc(e))r.namespaceURI===zc&&"sectPr"===Wc(r)&&"sectPrChange"!==r.parentNode?.localName&&t.push(r),n(r)};return n(e),t}function Vc(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(!r)continue;const o=r.localName??r.name;(r.namespaceURI?t.hasAttributeNS(r.namespaceURI,o):t.hasAttribute(r.name))||(r.namespaceURI?t.setAttributeNS(r.namespaceURI,r.name,r.value):t.setAttribute(r.name,r.value))}}function Kc(e){return e.namespaceURI===zc&&$c.has(Wc(e))}function _c(e,t){const n=(new _i.DOMParser).parseFromString(e,"application/xml"),r=(new _i.DOMParser).parseFromString(t,"application/xml"),o=n.documentElement,a=r.documentElement;if(!o||!a)return t;const i=Uc(n),s=Uc(r);return 0===i.length||i.length!==s.length?t:(Vc(o,a),i.forEach((e,t)=>{!function(e,t){Vc(e,t);const n=Hc(e),r=Hc(t),o=/* @__PURE__ */new Map;for(const i of r){const e=jc(i),t=o.get(e);t?t.push(i):o.set(e,[i])}const a=/* @__PURE__ */new Map;for(let i=0;i<n.length;i+=1){const e=n[i],r=jc(e),s=a.get(r)??0;a.set(r,s+1);const l=o.get(r)?.[s];if(l){Vc(e,l);continue}if(Kc(e))continue;const c=n.slice(i+1).map(e=>o.get(jc(e))?.[0]).find(e=>Boolean(e));t.insertBefore(e.cloneNode(!0),c??null)}}(e,s[t])}),(new _i.XMLSerializer).serializeToString(r))}var Xc="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function qc(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const r=e.childNodes[n];r?.nodeType===r.ELEMENT_NODE&&t.push(r)}return t}function Gc(e){return e.localName??e.tagName}function Yc(e,t){const n=(new _i.DOMParser).parseFromString(e,"application/xml").documentElement;return n?.namespaceURI===Xc&&Gc(n)===t?n:void 0}function Zc(e){return qc(e).length>0?(new _i.XMLSerializer).serializeToString(e.ownerDocument):void 0}var Jc=/* @__PURE__ */new Set(["documentProtection","defaultTabStop","autoHyphenation","consecutiveHyphenLimit","hyphenationZone","doNotHyphenateCaps","evenAndOddHeaders"]),Qc=/* @__PURE__ */new Map([["compat",/* @__PURE__ */new Set(["allowSpaceOfSameStyleInTable"])],["footnotePr",/* @__PURE__ */new Set(["numFmt","numStart","numRestart"])],["endnotePr",/* @__PURE__ */new Set(["numFmt","numStart","numRestart"])]]);function ed(e){const t=Yc(e,"settings");if(!t)return e;for(const n of[...qc(t)]){if(n.namespaceURI!==Xc)continue;const e=Gc(n);if(Jc.has(e)){t.removeChild(n);continue}const r=Qc.get(e);if(r){for(const e of[...qc(n)])e.namespaceURI===Xc&&r.has(Gc(e))&&n.removeChild(e);0===qc(n).length&&t.removeChild(n)}}return Zc(t)}function td(e){const t=Yc(e,"styles");if(!t)return e;for(const n of[...qc(t)])n.namespaceURI===Xc&&"style"===Gc(n)&&t.removeChild(n);return Zc(t)}function nd(e){const t=Yc(e,"fonts");if(!t)return e;for(const n of[...qc(t)])n.namespaceURI===Xc&&"font"===Gc(n)&&t.removeChild(n);return Zc(t)}async function rd(e,t,n){const r=e.file(t);if(!r)return!1;const o=await r.async("string"),a=n(o);return a!==o&&(void 0===a?e.remove(t):e.file(t,a),!0)}var od="word/styles.xml";function ad(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const r=e.childNodes[n];r?.nodeType===r.ELEMENT_NODE&&t.push(r)}return t}function id(e){return e.localName??e.tagName}function sd(e){return`${e.namespaceURI??""}\0${id(e)}`}function ld(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(r?.localName===t)return r.value}}function cd(e,t){return ad(e).find(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&id(e)===t)}function dd(e){return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&"tblStylePr"===id(e)?`${sd(e)}\0${ld(e,"type")??""}`:sd(e)}function ud(e){const t=(new _i.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"styles"===id(t)?t:void 0}function pd(e,t){const n=cd(e,"pPr");if(!n)return!1;const r=cd(t,"pPr"),o=new _i.XMLSerializer,a=o.serializeToString(n),i=r?o.serializeToString(r):"",s=fa(a,i);if(s===i)return!1;if(!s)return!!r&&(t.removeChild(r),!0);const l=function(e){if(!e)return;const t=(new _i.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"pPr"===id(t)?t:void 0}(s);if(!l)return!1;const c=l.cloneNode(!0);return r?t.replaceChild(c,r):function(e,t,n,r){const o=ad(e),a=o.indexOf(n),i=ad(t),s=new Map(i.map(e=>[dd(e),e])),l=o.slice(a+1).map(e=>s.get(dd(e))).find(e=>Boolean(e));t.insertBefore(r,l??null)}(e,t,n,c),!0}async function fd(e,t){const n=function(e){const t=e.parts[e.mainDocumentPart]?.relationships?.find(e=>"External"!==e.targetMode&&e.type.endsWith("/styles")&&Boolean(e.resolvedTarget)),n=t?.resolvedTarget?e.parts[t.resolvedTarget]:void 0;return"xml"===n?.kind?n.data:void 0}(e),r=t.file(od);if(!n||!r)return!1;const o=await r.async("string"),a=function(e,t){const n=ud(e),r=ud(t);if(!n||!r)return t;const o=/* @__PURE__ */new Map;for(const i of ad(r)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==i.namespaceURI||"style"!==id(i))continue;const e=ld(i,"styleId");e&&o.set(e,i)}let a=!1;for(const i of ad(n)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==i.namespaceURI||"style"!==id(i))continue;const e=ld(i,"styleId"),t=e?o.get(e):void 0;t&&(a=pd(i,t)||a)}return a?(new _i.XMLSerializer).serializeToString(r.ownerDocument):t}(n,o);return a!==o&&(t.file(od,a),!0)}function gd(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const r=e.childNodes[n];r?.nodeType===r.ELEMENT_NODE&&t.push(r)}return t}function md(e){return e.localName??e.tagName}function hd(e){for(let t=0;t<e.attributes.length;t+=1){const n=e.attributes[t];if(n&&"http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==n.namespaceURI&&"http://www.w3.org/2000/xmlns/"!==n.namespaceURI&&"xmlns"!==n.prefix&&"xmlns"!==n.name)return!0}return!1}function bd(e,t){const n=function(e){if(!e)return;const t=(new _i.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"rPr"===md(t)?t:void 0}(e);if(!n)return t;const r=`<w:r xmlns:w="${Co}" xmlns:w14="${mo}">${t}<w:t/></w:r>`,o={id:"ooxml-style-rpr-source",kind:"text",text:""};yi(o,`<w:r xmlns:w="${Co}" xmlns:w14="${mo}">${e}<w:t/></w:r>`);const a=function(e){const t=(new _i.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"r"===md(t)?t:void 0}(Pi(o,r));if(!a)return t;let i=gd(a).find(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&"rPr"===md(e));return!i&&hd(n)&&(i=a.ownerDocument.createElementNS(Co,"w:rPr"),a.insertBefore(i,a.firstChild)),i?(Vo(n,i),0!==gd(i).length||hd(i)?(new _i.XMLSerializer).serializeToString(i):""):""}var yd="word/styles.xml";function vd(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const r=e.childNodes[n];r?.nodeType===r.ELEMENT_NODE&&t.push(r)}return t}function xd(e){return e.localName??e.tagName}function wd(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(r?.localName===t)return r.value}}function Id(e,t){return vd(e).find(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&xd(e)===t)}function Sd(e){const t=(new _i.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"styles"===xd(t)?t:void 0}function Cd(e,t){const n=Id(e,"rPr");if(!n)return!1;const r=Id(t,"rPr"),o=new _i.XMLSerializer,a=o.serializeToString(n),i=r?o.serializeToString(r):"",s=bd(a,i);if(s===i)return!1;if(!s)return!!r&&(t.removeChild(r),!0);const l=function(e){if(!e)return;const t=(new _i.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"rPr"===xd(t)?t:void 0}(s);if(!l)return!1;const c=l.cloneNode(!0);return r?t.replaceChild(c,r):function(e,t,n,r){const o=vd(e),a=o.indexOf(n),i=vd(t),s=o.slice(a+1).map(e=>i.find(t=>t.namespaceURI===e.namespaceURI&&xd(t)===xd(e))).find(e=>Boolean(e));t.insertBefore(r,s??null)}(e,t,n,c),!0}async function kd(e,t){const n=function(e){const t=e.parts[e.mainDocumentPart]?.relationships?.find(e=>"External"!==e.targetMode&&e.type.endsWith("/styles")&&Boolean(e.resolvedTarget)),n=t?.resolvedTarget?e.parts[t.resolvedTarget]:void 0;return"xml"===n?.kind?n.data:void 0}(e),r=t.file(yd);if(!n||!r)return!1;const o=await r.async("string"),a=function(e,t){const n=Sd(e),r=Sd(t);if(!n||!r)return t;const o=/* @__PURE__ */new Map;for(const i of vd(r)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==i.namespaceURI||"style"!==xd(i))continue;const e=wd(i,"styleId");e&&o.set(e,i)}let a=!1;for(const i of vd(n)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==i.namespaceURI||"style"!==xd(i))continue;const e=wd(i,"styleId"),t=e?o.get(e):void 0;t&&(a=Cd(i,t)||a)}return a?(new _i.XMLSerializer).serializeToString(r.ownerDocument):t}(n,o);return a!==o&&(t.file(yd,a),!0)}var Td="word/styles.xml",Pd=/* @__PURE__ */new Set(["pPr","rPr","tblPr","trPr","tcPr"]);function Rd(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const r=e.childNodes[n];r?.nodeType===r.ELEMENT_NODE&&t.push(r)}return t}function Ad(e){return e.localName??e.tagName}function Md(e){return`${e.namespaceURI??""}\0${Ad(e)}`}function Od(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(r?.localName===t)return r.value}}function Bd(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(!r)continue;const o=r.localName??r.name;(r.namespaceURI?t.hasAttributeNS(r.namespaceURI,o):t.hasAttribute(r.name))||(r.namespaceURI?t.setAttributeNS(r.namespaceURI,r.name,r.value):t.setAttribute(r.name,r.value))}}function Fd(e,t){return Rd(e).find(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&Ad(e)===t)}function Ed(e){return e?(new _i.XMLSerializer).serializeToString(e):""}function Dd(e,t){if(!e)return;const n=(new _i.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===n?.namespaceURI&&Ad(n)===t?n:void 0}function Ld(e,t,n){switch(e){case"pPr":return fa(t,n);case"rPr":return bd(t,n);case"tblPr":return Xr(t,n);case"trPr":return Ci(t,n);case"tcPr":return Wo(t,n);default:return n}}function Nd(e,t,n,r){const o=Rd(e),a=o.indexOf(n),i=o.slice(a+1).find(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&Pd.has(Ad(e)));return i?Fd(t,Ad(i))??null:"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&"style"===Ad(e)&&Pd.has(r)?Rd(t).find(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&"tblStylePr"===Ad(e))??null:null}function zd(e,t,n){const r=Fd(e,n);if(!r)return!1;const o=Fd(t,n),a=Ed(o),i=Ld(n,Ed(r),a);if(i===a)return!1;if(!i)return!!o&&(t.removeChild(o),!0);const s=Dd(i,n);if(!s)return!1;const l=s.cloneNode(!0);return o?(t.replaceChild(l,o),!0):(t.insertBefore(l,Nd(e,t,r,n)),!0)}function $d(e,t){Bd(e,t);let n=!1;for(const o of Pd)n=zd(e,t,o)||n;const r=new Set(Rd(t).map(Md));for(const o of Rd(e))"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===o.namespaceURI&&Pd.has(Ad(o))||r.has(Md(o))||(t.appendChild(o.cloneNode(!0)),r.add(Md(o)),n=!0);return n}function Hd(e){const t=e.ownerDocument;if(!t)return;const n=t.createElementNS(Co,"w:tblStylePr");Bd(e,n);let r=!1;for(const o of Rd(e)){const e=Ad(o);if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"===o.namespaceURI&&Pd.has(e)){const t=Dd(Ld(e,Ed(o),""),e);t&&(n.appendChild(t.cloneNode(!0)),r=!0);continue}n.appendChild(o.cloneNode(!0)),r=!0}return r?n:void 0}function Wd(e){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==e.namespaceURI||"tblStylePr"!==Ad(e))return;const t=Od(e,"type");return t?`tblStylePr:${t}`:void 0}function jd(e,t){let n=!1;n=zd(e,t,"tblPr")||n;const r=Rd(e).filter(e=>void 0!==Wd(e)),o=/* @__PURE__ */new Map;for(const a of Rd(t)){const e=Wd(a);e&&o.set(e,a)}for(const a of r){const r=Wd(a),i=o.get(r);if(i){n=$d(a,i)||n;continue}const s=Hd(a);if(!s)continue;const l=Rd(e),c=l.indexOf(a),d=l.slice(c+1).find(e=>void 0!==Wd(e)),u=d?o.get(Wd(d))??null:null;t.insertBefore(s.cloneNode(!0),u),n=!0}return n}function Ud(e){const t=(new _i.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"styles"===Ad(t)?t:void 0}async function Vd(e,t){const n=function(e){const t=e.parts[e.mainDocumentPart]?.relationships?.find(e=>"External"!==e.targetMode&&e.type.endsWith("/styles")&&Boolean(e.resolvedTarget)),n=t?.resolvedTarget?e.parts[t.resolvedTarget]:void 0;return"xml"===n?.kind?n.data:void 0}(e),r=t.file(Td);if(!n||!r)return!1;const o=await r.async("string"),a=function(e,t){const n=Ud(e),r=Ud(t);if(!n||!r)return t;const o=/* @__PURE__ */new Map;for(const i of Rd(r))if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"===i.namespaceURI&&"style"===Ad(i)){const e=Od(i,"styleId");e&&o.set(e,i)}let a=!1;for(const i of Rd(n)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==i.namespaceURI||"style"!==Ad(i))continue;if("table"!==Od(i,"type"))continue;const e=Od(i,"styleId"),t=e?o.get(e):void 0;t&&(a=jd(i,t)||a)}return a?(new _i.XMLSerializer).serializeToString(r.ownerDocument):t}(n,o);return a!==o&&(t.file(Td,a),!0)}var Kd="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function _d(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const r=e.childNodes[n];r?.nodeType===r.ELEMENT_NODE&&t.push(r)}return t}function Xd(e){return e.localName??e.tagName}function qd(e){return`${e.namespaceURI??""}\0${Xd(e)}`}function Gd(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(r?.localName===t)return r.value}}function Yd(e,t){for(let n=0;n<e.attributes.length;n+=1){const r=e.attributes.item(n);if(!r)continue;const o=r.localName??r.name;(r.namespaceURI?t.hasAttributeNS(r.namespaceURI,o):t.hasAttribute(r.name))||(r.namespaceURI?t.setAttributeNS(r.namespaceURI,r.name,r.value):t.setAttribute(r.name,r.value))}}function Zd(e,t,n){const r=(new _i.DOMParser).parseFromString(e,"application/xml"),o=(new _i.DOMParser).parseFromString(t,"application/xml"),a=r.documentElement,i=o.documentElement;if(a&&i&&a.namespaceURI===Kd&&i.namespaceURI===Kd&&Xd(a)===n&&Xd(i)===n)return{sourceRoot:a,rebuiltRoot:i}}function Jd(e,t,n,r,o){const a=e.slice(t+1).map(o).find(e=>Boolean(e));r.insertBefore(n.cloneNode(!0),a??null)}function Qd(e,t){const n=new Set(_d(t).map(qd));for(const r of _d(e))r.namespaceURI===Kd||n.has(qd(r))||t.appendChild(r.cloneNode(!0))}var eu=/* @__PURE__ */new Set(["documentProtection","defaultTabStop","autoHyphenation","consecutiveHyphenLimit","hyphenationZone","doNotHyphenateCaps","evenAndOddHeaders"]);var tu=/* @__PURE__ */new Set(["name","basedOn","next","uiPriority","qFormat","semiHidden","unhideWhenUsed","pPr","rPr","tblPr","tblStylePr"]);function nu(e){return e.namespaceURI===Kd&&"tblStylePr"===Xd(e)?`${qd(e)}\0${Gd(e,"type")??""}`:qd(e)}function ru(e){return e.namespaceURI===Kd&&"style"===Xd(e)?`${qd(e)}\0${Gd(e,"styleId")??""}`:qd(e)}var ou=/* @__PURE__ */new Set(["altName","panose1","charset","family","pitch","sig"]);function au(e){return e.namespaceURI===Kd&&"font"===Xd(e)?`${qd(e)}\0${Gd(e,"name")??""}`:qd(e)}var iu=[{relationshipSuffix:"/settings",rebuiltPath:"word/settings.xml",merge:function(e,t){const n=Zd(e,t,"settings");if(!n)return t;const{sourceRoot:r,rebuiltRoot:o}=n;Yd(r,o);const a=/* @__PURE__ */new Map([["compat",/* @__PURE__ */new Set(["allowSpaceOfSameStyleInTable"])],["footnotePr",/* @__PURE__ */new Set(["numFmt","numStart","numRestart"])],["endnotePr",/* @__PURE__ */new Set(["numFmt","numStart","numRestart"])]]),i=_d(r),s=new Map(_d(o).map(e=>[qd(e),e]));return i.forEach((e,t)=>{const n=qd(e),r=s.get(n),l=Xd(e),c=e.namespaceURI===Kd?a.get(l):void 0;if(r)return Yd(e,r),void(c?function(e,t,n){Yd(e,t);const r=_d(t),o=new Map(r.map(e=>[qd(e),e])),a=_d(e);a.forEach((e,r)=>{const i=qd(e),s=o.get(i);if(s)return Yd(e,s),void Qd(e,s);e.namespaceURI===Kd&&n.has(Xd(e))||Jd(a,r,e,t,e=>o.get(qd(e)))})}(e,r,c):Qd(e,r));if(c){const n=function(e,t){const n=e.cloneNode(!1);let r=!1;for(const o of _d(e))o.namespaceURI===Kd&&t.has(Xd(o))||(n.appendChild(o.cloneNode(!0)),r=!0);return r?n:void 0}(e,c);if(n){const e=i.slice(t+1).map(e=>s.get(qd(e))).find(e=>Boolean(e));o.insertBefore(n,e??null)}return}e.namespaceURI===Kd&&eu.has(l)||Jd(i,t,e,o,e=>s.get(qd(e)))}),(new _i.XMLSerializer).serializeToString(o.ownerDocument)}},{relationshipSuffix:"/styles",rebuiltPath:"word/styles.xml",merge:function(e,t){const n=Zd(e,t,"styles");if(!n)return t;const{sourceRoot:r,rebuiltRoot:o}=n;Yd(r,o);const a=_d(r),i=new Map(_d(o).map(e=>[ru(e),e]));return a.forEach((e,t)=>{const n=ru(e),r=i.get(n);if(r)return Yd(e,r),void(e.namespaceURI===Kd&&"style"===Xd(e)?function(e,t){Yd(e,t);const n=_d(e),r=new Map(_d(t).map(e=>[nu(e),e]));n.forEach((e,o)=>{const a=nu(e),i=r.get(a);if(i)return Yd(e,i),void Qd(e,i);e.namespaceURI===Kd&&tu.has(Xd(e))||Jd(n,o,e,t,e=>r.get(nu(e)))})}(e,r):Qd(e,r));Jd(a,t,e,o,e=>i.get(ru(e)))}),(new _i.XMLSerializer).serializeToString(o.ownerDocument)}},{relationshipSuffix:"/numbering",rebuiltPath:"word/numbering.xml"},{relationshipSuffix:"/fontTable",rebuiltPath:"word/fontTable.xml",merge:function(e,t){const n=Zd(e,t,"fonts");if(!n)return t;const{sourceRoot:r,rebuiltRoot:o}=n;Yd(r,o);const a=_d(r),i=new Map(_d(o).map(e=>[au(e),e]));return a.forEach((e,t)=>{const n=au(e),r=i.get(n);if(r)return Yd(e,r),void(e.namespaceURI===Kd&&"font"===Xd(e)&&function(e,t){Yd(e,t);const n=_d(e),r=new Map(_d(t).map(e=>[qd(e),e]));n.forEach((e,o)=>{const a=qd(e),i=r.get(a);i?Yd(e,i):e.namespaceURI===Kd&&ou.has(Xd(e))||Jd(n,o,e,t,e=>r.get(qd(e)))})}(e,r));Jd(a,t,e,o,e=>i.get(au(e)))}),(new _i.XMLSerializer).serializeToString(o.ownerDocument)}}];function su(e,t){const n=e.parts[e.mainDocumentPart]?.relationships?.find(e=>"External"!==e.targetMode&&e.type.endsWith(t)&&Boolean(e.resolvedTarget)),r=n?.resolvedTarget?e.parts[n.resolvedTarget]:void 0;return"xml"===r?.kind?r.data:void 0}var lu="word/document.xml";function cu(e){const t=(new _i.DOMParser).parseFromString(e,"application/xml").getElementsByTagNameNS(Co,"sectPr");let n=0;for(let r=0;r<t.length;r+=1){const e=t.item(r),o=e?.parentNode;e&&"sectPrChange"!==o?.localName&&(n+=1)}return n}async function du(e,t){const n=e.sourcePackage;if(!n)return t;const r=n.parts[n.mainDocumentPart];if("xml"!==r?.kind)return Ll(e,t);const o=await cs.default.loadAsync(t),a=Boolean(o.file("word/numbering.xml")),i={settings:Boolean(o.file("word/settings.xml")),styles:Boolean(o.file("word/styles.xml")),fontTable:Boolean(o.file("word/fontTable.xml"))};let s=await async function(e,t){let n=!1;for(const r of iu){const o=su(e,r.relationshipSuffix);if(!o)continue;const a=t.file(r.rebuiltPath);if(!a){t.file(r.rebuiltPath,o),n=!0;continue}if(!r.merge)continue;const i=await a.async("string"),s=r.merge(o,i);s!==i&&(t.file(r.rebuiltPath,s),n=!0)}return n}(n,o);a&&(s=await Dc(n,o)||s),i.styles&&(s=await fd(n,o)||s,s=await kd(n,o)||s,s=await Vd(n,o)||s),s=await async function(e,t){let n=!1;return t.settings||(n=await rd(e,"word/settings.xml",ed)||n),t.styles||(n=await rd(e,"word/styles.xml",td)||n),t.fontTable||(n=await rd(e,"word/fontTable.xml",nd)||n),n}(o,i)||s,s=await async function(e,t){let n=!1;for(const r of Lc){const o=Nc(e,r.relationshipSuffix),a=t.file(r.rebuiltPath);if(!o||!a)continue;const i=await a.async("string"),s=Zs(o,i,r.rootLocalName);s!==i&&(t.file(r.rebuiltPath,s),n=!0)}return n}(n,o)||s,s=await async function(e,t,n){let r=!1;for(const o of nc){const a=cc(t,o.relationshipSuffix),i=n.file(o.rebuiltPath);if(!a||!i)continue;const s=await i.async("string"),l=mc(e,a,s,o);l!==s&&(n.file(o.rebuiltPath,l),r=!0)}return r}(e,n,o)||s,s=await Ms(n,o)||s,s=await async function(e,t){const n=zs(e,"/comments"),r=zs(e,"/commentsExtended"),o=t.file("word/comments.xml"),a=t.file(Bs);if(!(n&&r&&o&&a))return!1;const i=await o.async("string"),s=await a.async("string"),l=js(n,r,i,s);return l!==s&&(t.file(Bs,l),!0)}(n,o)||s,s=await vl(n,o)||s,s=await dl(n,o)||s;const l=await(o.file(lu)?.async("string"));if(!l||cu(r.data)!==cu(l)){return Ll(e,s?await o.generateAsync({type:"arraybuffer"}):t)}const c=_c(r.data,l);c!==l&&(o.file(lu,c),s=!0);return tc(e,s?await o.generateAsync({type:"arraybuffer"}):t)}async function uu(e,t={}){if(!e.sourcePackage)return ni(e);const n=(r=e.sourcePackage,{...r,contentTypes:{defaults:{...r.contentTypes.defaults},overrides:{...r.contentTypes.overrides}},rootRelationships:r.rootRelationships.map(e=>({...e})),parts:Object.fromEntries(Object.entries(r.parts).map(([e,t])=>[e,{...t,...t.relationships?{relationships:t.relationships.map(e=>({...e}))}:{}}])),...r.diagnostics?{diagnostics:r.diagnostics.map(e=>({...e}))}:{},...r.rebuiltPartHashes?{rebuiltPartHashes:{...r.rebuiltPartHashes}}:{}});var r;const o=Kr(n),a=o.diagnostics.filter(e=>"error"===e.level);if(a.length)throw new zo(a);n.opaqueObjects=o.objects;const i={...e,sourcePackage:n};Fo(i);const s=o.objects.length>0,l=e.opaqueRelocationIntent,c=l?_a(n,l,l.destinationOwner):void 0,d=await ma(i,n);let u=await du(i,d);if(c){if(e.opaqueDeletionIntents?.length)throw new Error("Cannot combine opaque deletion and relocation");u=await async function(e,t){const n=await cs.default.loadAsync(e);if(!n.file(t.destinationOwner))throw Error("Original destination story was not retained");const r=t.destinationOwner.lastIndexOf("/"),o=(r>=0?t.destinationOwner.slice(0,r+1):"")+"_rels/"+t.destinationOwner.slice(r+1)+".rels",a=await(n.file(o)?.async("string"))??'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"/>';if(/<!\s*(?:DOCTYPE|ENTITY)\b/i.test(a))throw Error("Unsafe relationship XML");const i=new _i.DOMParser({onError:()=>{throw Error("Malformed relationships")}}).parseFromString(a,"application/xml"),s=i.documentElement;if(!s||"http://schemas.openxmlformats.org/package/2006/relationships"!==s.namespaceURI||"Relationships"!==s.localName)throw Error("Invalid destination relationships");const l=/* @__PURE__ */new Set;for(const c of Array.from(s.getElementsByTagNameNS(Gr,"Relationship"))){const e=c.getAttribute("Id");if(!e||l.has(e))throw Error("Duplicate destination relationship");l.add(e)}for(const c of t.addedRelationships){if(l.has(c.id)||!c.resolvedTarget||!n.file(c.resolvedTarget))throw Error("Relocation relationship collision or missing target");l.add(c.id);const e=i.createElementNS(Gr,s.prefix?s.prefix+":Relationship":"Relationship");e.setAttribute("Id",c.id),e.setAttribute("Type",c.type),e.setAttribute("Target",c.target),s.appendChild(e)}return n.file(o,(new _i.XMLSerializer).serializeToString(i)),n.generateAsync({type:"arraybuffer"})}(u,c)}if(s||t.requireOpaquePreservation||c||e.opaqueDeletionIntents?.length){const{captureDocxSourcePackage:r}=await import("./sourcePackage-GLrWYLnd.js").then(e=>e.r),o=await r(u),a=Ei(n,o,e.opaqueDeletionIntents,c?function(e,t){const n=e.opaqueObjects?.find(e=>e.ownerPath===t.sourceOwner&&e.ordinal===t.sourceOrdinal&&e.signature===t.sourceSignature),r=e.parts[t.destinationOwner];if(!n||!r)throw Error("Relocation source missing");const o={...e,parts:{...e.parts,[t.destinationOwner]:{...r,relationships:[...r.relationships??[],...t.addedRelationships]}}},a=lo(o,t.destinationOwner,t.destinationRun.relationshipIds);if(a.issues.length)throw Error("Invalid relocation closure");return{original:n,expected:{...n,ownerPath:t.destinationOwner,signature:t.destinationRun.signature,fragmentXml:t.destinationRun.fragmentXml,relationshipIds:t.destinationRun.relationshipIds,...a}}}(n,c):void 0);if(a.length)throw new zo(a);const i=e.opaqueDeletionIntents??[];if(i.length&&!1!==t.pruneDeletedOpaqueDependencies){const t=ys(n,o,i);if(t.removeEdges.length||t.removeParts.length){const o=await async function(e,t){if(!t.removeParts.length&&!t.removeEdges.length)return e;const n=await cs.default.loadAsync(e),r=new _i.XMLSerializer,o=async e=>{const t=n.file(e);if(!t)throw Error("Missing planned OPC part "+e);return fs(await t.async("string"))};for(const l of new Set(t.removeEdges.map(e=>e.relPath))){const e=await o(l),a=e.documentElement,i=new Set(t.removeEdges.filter(e=>e.relPath===l).map(e=>e.id));for(const t of ps(a))i.has(t.getAttribute("Id")??"")&&(i.delete(t.getAttribute("Id")),a.removeChild(t));if(i.size)throw Error("OPC relationship plan became stale");ps(a).length?n.file(l,r.serializeToString(e)):n.remove(l)}const a=new Set(t.removeParts);for(const[l,c]of Object.entries(n.files)){if(c.dir)continue;const e=Ko(l);(a.has(l)||"string"==typeof e&&a.has(e))&&n.remove(l)}const i=await o(Uo),s=i.documentElement;if("http://schemas.openxmlformats.org/package/2006/content-types"!==s.namespaceURI||"Types"!==s.localName)throw Error("Invalid OPC content types");for(const l of ps(s))"http://schemas.openxmlformats.org/package/2006/content-types"===l.namespaceURI&&"Override"===l.localName&&a.has((l.getAttribute("PartName")??"").replace(/^\//,""))&&s.removeChild(l);return n.file(Uo,r.serializeToString(i)),n.generateAsync({type:"arraybuffer"})}(u,t),a=await r(o),s=Ei(n,a,i);if(s.length)throw new zo(s);return Fi(o,e)}}}return Fi(u,e)}async function pu(e,t={}){if(!e.sourcePackage)return gi(e);const n=await uu(e,t);return new Blob([n],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}var fu="http://schemas.openxmlformats.org/wordprocessingml/2006/main",gu="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",mu="http://schemas.openxmlformats.org/officeDocument/2006/relationships",hu=e=>{throw Error("Opaque insertion rejected: "+e)};function bu(e){if(/<!\s*(?:DOCTYPE|ENTITY)\b/i.test(e))return hu("unsafe XML declaration");const t=new _i.DOMParser({onError:()=>hu("malformed XML")}).parseFromString(e,"application/xml").documentElement;return t||hu("missing XML root")}function yu(e){const t=[],n=[e];for(let r=0;r<n.length;r++){const e=n[r];t.push(e);for(const t of Array.from(e.childNodes))1===t.nodeType&&n.push(t)}return t}function vu(e){const t=e.lastIndexOf("/");return e.slice(0,t+1)+"_rels/"+e.slice(t+1)+".rels"}function xu(e,t){const n=e.split("/").slice(0,-1),r=t.split("/");for(;n.length&&r.length&&n[0]===r[0];)n.shift(),r.shift();const o="../".repeat(n.length)+r.join("/");return Ka(e,o)!==t?hu("unrepresentable relative target"):o}function wu(e){return/^[A-Za-z0-9_.\-/]+$/.test(e)&&!e.split("/").some(e=>!e||"."===e||".."===e)}var Iu={"application/vnd.openxmlformats-officedocument.drawingml.chart+xml":"xml","application/vnd.ms-office.chartstyle+xml":"xml","application/vnd.ms-office.chartcolorstyle+xml":"xml","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/bmp":"bmp","image/tiff":"tiff"};var Su="http://schemas.openxmlformats.org/wordprocessingml/2006/main",Cu="[Content_Types].xml",ku="application/vnd.openxmlformats-package.relationships+xml",Tu=e=>{throw Error("Opaque transfer application rejected: "+e)};function Pu(e,t,n){if(/<!\s*(?:DOCTYPE|ENTITY)\b/i.test(e))return Tu("unsafe XML declaration");const r=new _i.DOMParser({onError:()=>Tu("malformed XML")}).parseFromString(e,"application/xml");return r.documentElement?.namespaceURI!==t||r.documentElement.localName!==n?Tu("unexpected XML root"):r}function Ru(e){return Array.from(e.childNodes).filter(e=>1===e.nodeType)}function Au(e){const t=e.lastIndexOf("/");return e.slice(0,t+1)+"_rels/"+e.slice(t+1)+".rels"}function Mu(e){return(new _i.XMLSerializer).serializeToString(e)}function Ou(e,t){return e.byteLength===t.byteLength&&e.every((e,n)=>e===t[n])}function Bu(e){const t=/* @__PURE__ */new Set;for(const[n,r]of Object.entries(e.files)){if(r.dir)continue;const e=n.toLowerCase();if(t.has(e)||void 0!==r.unsafeOriginalName&&r.unsafeOriginalName!==n)return Tu("ambiguous ZIP entry");if(t.add(e),e.startsWith("_xmlsignatures/"))return Tu("signed package")}}async function Fu(e,t,n){const r=await cs.default.loadAsync(e);Bu(r);const o=await Qa(e);!function(e){if([...e.rootRelationships,...Object.values(e.parts).flatMap(e=>e.relationships??[])].some(e=>e.type.includes("digital-signature"))||[...Object.values(e.contentTypes.defaults),...Object.values(e.contentTypes.overrides)].some(e=>e.includes("digital-signature")))Tu("signed package")}(o);const a=function(e,t){const n=ls(e),r=t.mainDocumentPart,o=Object.hasOwn(t.parts,r)?t.parts[r]:void 0;if(!wu(r)||!o||"xml"!==o.kind)return hu("missing destination main story");const a=bu(o.data);if(a.namespaceURI!==fu||"document"!==a.localName)return hu("only Transitional main story is supported");if(Kr(t).diagnostics.some(e=>"error"===e.level))return hu("destination opaque inspection errors");const i=/* @__PURE__ */new Set,s=e=>{if("[Content_Types].xml"!==e&&!wu(e))return hu("ambiguous destination OPC path");i.add(e.toLowerCase())};for(const[T,P]of Object.entries(t.parts)){if(P.path!==T)return hu("inconsistent destination part path");s(T),"[Content_Types].xml"===T||T.endsWith(".rels")||s(vu(T));for(const e of P.relationships??[])if("External"!==e.targetMode){if(!e.resolvedTarget||Ka(T,e.target)!==e.resolvedTarget)return hu("unresolved destination relationship");s(e.resolvedTarget)}}for(const T of Object.keys(t.contentTypes.overrides))s(T);for(const T of t.rootRelationships)if("External"!==T.targetMode){if(!T.resolvedTarget||Ka(null,T.target)!==T.resolvedTarget)return hu("unresolved root relationship");s(T.resolvedTarget)}if(new Set(Object.keys(t.parts).map(e=>e.toLowerCase())).size!==Object.keys(t.parts).length)return hu("aliased destination parts");let l="";for(let T=1;T<=1e5;T++){const e="word/oasis-transfer-"+T;if(![...i].some(t=>t===e||t.startsWith(e+"/")||e.startsWith(t+"/"))){l=e;break}}if(!l)return hu("part namespace exhausted");const c=new Map(n.parts.map((e,t)=>[e.path,l+"/part-"+(t+1)+"."+Iu[e.contentType]])),d=(e,t,n=e.id)=>{const r=c.get(e.resolvedTarget);return r?{...e,id:n,target:xu(t,r),resolvedTarget:r,targetMode:"Internal"}:hu("unmapped dependency")},u=n.parts.map(e=>{const t=c.get(e.path);return{...e,path:t,relationships:e.relationships.map(e=>d(e,t))}}),p=new Set((o.relationships??[]).map(e=>e.id));if(p.size!==(o.relationships??[]).length)return hu("duplicate destination relationship ID");const f=yu(a).flatMap(e=>Array.from(e.attributes).map(e=>e.value));let g=1;const m=n.relationships.map(e=>{let t;do{t="rIdOasisTransfer"+g++}while(p.has(t)||o.data.includes(t)||f.some(e=>e.includes(t)));return p.add(t),{from:e.id,to:t}}),h=new Map(m.map(e=>[e.from,e.to])),b=n.relationships.map(e=>d(e,r,h.get(e.id))),y=bu(n.fragmentXml),v=yu(y),x=v.filter(e=>e.namespaceURI===gu&&"docPr"===e.localName),w=v.filter(e=>"http://schemas.openxmlformats.org/drawingml/2006/chart"===e.namespaceURI&&"chart"===e.localName);if(1!==x.length||1!==w.length||!h.has(w[0].getAttributeNS(mu,"id")??""))return hu("ambiguous chart or drawing identity");for(const T of v){if(T!==y&&T.namespaceURI===fu)return hu("nested WordprocessingML in chart drawing");for(const e of Array.from(T.attributes)){if("http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"===e.namespaceURI)return hu("unsupported extended drawing identity");if(e.namespaceURI===mu||"http://purl.oclc.org/ooxml/officeDocument/relationships"===e.namespaceURI||"urn:schemas-microsoft-com:office:office"===e.namespaceURI&&"relid"===e.localName){if(T!==w[0]||e.namespaceURI!==mu||"id"!==e.localName||!h.has(e.value))return hu("unknown chart relationship reference");T.setAttributeNS(mu,e.name,h.get(e.value))}else if("http://www.w3.org/2000/xmlns/"!==e.namespaceURI&&h.has(e.value))return hu("unknown attribute may reference a relationship")}}const I=/* @__PURE__ */new Set;for(const T of Object.values(t.parts)){if("xml"!==T.kind||!T.data.includes("docPr"))continue;const e=T.path===r?a:bu(T.data);for(const t of yu(e)){if(t.namespaceURI!==gu||"docPr"!==t.localName)continue;const e=t.getAttribute("id")??"";if(!/^\d+$/.test(e)||Number(e)>4294967295)return hu("invalid destination drawing ID");I.add(Number(e))}}let S=1879048192;for(;I.has(S)&&S<2147483647;)S++;if(I.has(S))return hu("drawing identity exhausted");x[0].setAttribute("id",String(S));const C=Xo(y);if(!C)return hu("chart projection lost");const k=ls({...n,ownerPath:r,fragmentXml:C.fragmentXml,signature:C.signature,relationships:b,parts:u});return{destinationOwner:r,destinationRun:C,addedRelationships:k.relationships,addedParts:k.parts,contentTypeOverrides:Object.fromEntries(k.parts.map(e=>[e.path,e.contentType])),pathMapping:[...c].map(([e,t])=>({from:e,to:t})),relationshipMapping:m,drawingId:S}}(t,o),i=a.destinationOwner,s=o.parts[i],l=Pu(s.data,Su,"document"),c=l.documentElement,d=Ru(c).filter(e=>e.namespaceURI===Su&&"body"===e.localName);if(1!==d.length)return Tu("ambiguous document body");const u=Ru(d[0]).filter(e=>e.namespaceURI===Su&&"p"===e.localName);if(!Number.isSafeInteger(n)||n<0||n>=u.length)return Tu("invalid paragraph index");const p=u[n],f=Pu(a.destinationRun.fragmentXml,Su,"drawing"),g=l.createElementNS(Su,c.prefix?c.prefix+":r":"r");g.appendChild(l.importNode(f.documentElement,!0)),p.appendChild(g);const m=Mu(l),h=Au(i),b=function(e,t){const n=Pu(e,Gr,"Relationships"),r=n.documentElement,o=/* @__PURE__ */new Set;for(const a of Ru(r)){const e=a.getAttribute("Id")??"";if("http://schemas.openxmlformats.org/package/2006/relationships"!==a.namespaceURI||"Relationship"!==a.localName||!e||o.has(e)||!a.getAttribute("Type")||!a.getAttribute("Target"))return Tu("ambiguous existing relationships");const t=a.getAttribute("TargetMode");if(t&&"Internal"!==t&&"External"!==t)return Tu("unknown relationship mode");o.add(e)}for(const a of t){if(o.has(a.id))return Tu("relationship collision");o.add(a.id);const e=n.createElementNS(Gr,r.prefix?r.prefix+":Relationship":"Relationship");e.setAttribute("Id",a.id),e.setAttribute("Type",a.type),e.setAttribute("Target",a.target),r.appendChild(e)}return Mu(n)}(await(r.file(h)?.async("string"))??'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"/>',a.addedRelationships),y=await(r.file(Cu)?.async("string"));if(!y)return Tu("missing content types");const v=function(e,t){const n=Pu(e,Ai,"Types"),r=n.documentElement,o=/* @__PURE__ */new Set,a=/* @__PURE__ */new Set;let i;for(const s of Ru(r)){if("http://schemas.openxmlformats.org/package/2006/content-types"!==s.namespaceURI)return Tu("unexpected content type element");const e=s.getAttribute("ContentType")??"";if(!e)return Tu("missing content type");if("Default"===s.localName){const t=(s.getAttribute("Extension")??"").toLowerCase();if(!t||a.has(t))return Tu("duplicate or invalid content type default");a.add(t),"rels"===t&&(i=e)}else{if("Override"!==s.localName)return Tu("unknown content type element");{const e=(s.getAttribute("PartName")??"").toLowerCase();if(!e.startsWith("/")||o.has(e))return Tu("duplicate or invalid content type override");o.add(e)}}}if(i&&i!==ku)return Tu("inconsistent relationship content type");if(!i){const e=n.createElementNS(Ai,r.prefix?r.prefix+":Default":"Default");e.setAttribute("Extension","rels"),e.setAttribute("ContentType",ku),r.insertBefore(e,Ru(r).find(e=>"Override"===e.localName)??null)}for(const[s,l]of Object.entries(t.contentTypeOverrides)){const e="/"+s;if(o.has(e.toLowerCase()))return Tu("content type override collision");o.add(e.toLowerCase());const t=n.createElementNS(Ai,r.prefix?r.prefix+":Override":"Override");t.setAttribute("PartName",e),t.setAttribute("ContentType",l),r.appendChild(t)}return Mu(n)}(y,a),x={...o,parts:{...o.parts,[i]:{...s,data:m,relationships:[...s.relationships??[],...a.addedRelationships]}},contentTypes:{defaults:{...o.contentTypes.defaults,rels:ku},overrides:{...o.contentTypes.overrides,...a.contentTypeOverrides}}};for(const N of a.addedParts)x.parts[N.path]={...N,originalHash:""};const w=Kr(o),I=Kr(x);if(I.diagnostics.some(e=>"error"===e.level)||I.objects.length!==w.objects.length+1)return Tu("unexpected predicted inventory");const S=I.objects.filter(e=>e.ownerPath===i&&e.signature===a.destinationRun.signature);if(1!==S.length||JSON.stringify(S[0].partPaths)!==JSON.stringify(a.addedParts.map(e=>e.path).sort()))return Tu("predicted inserted closure mismatch");const C=I.objects.filter(e=>e!==S[0]),k=e=>JSON.stringify([e.ownerPath,e.kind,e.signature,e.edges,e.partPaths]);if(JSON.stringify(C.map(k).sort())!==JSON.stringify(w.objects.map(k).sort()))return Tu("predicted loss of original objects");if(1!==Array.from(c.getElementsByTagNameNS("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing","docPr")).filter(e=>Number(e.getAttribute("id"))===a.drawingId).length)return Tu("drawing ID collision");const T=await cs.default.loadAsync(e),P=/* @__PURE__ */new Set,R=new Set(Object.keys(T.files).map(e=>e.toLowerCase())),A=(e,t,n=!1)=>{const r=e.toLowerCase();if(R.has(r)||P.has(r))return Tu("part collision");P.add(r),T.file(e,t,{base64:n})};for(const N of a.addedParts)A(N.path,N.data,"base64"===N.encoding),N.relationships.length&&A(Au(N.path),To(N.relationships));r.file(h)||P.add(h.toLowerCase()),T.file(i,m),T.file(h,b),T.file(Cu,v);const M=await T.generateAsync({type:"arraybuffer",compression:"DEFLATE"}),O=await cs.default.loadAsync(M);Bu(O);const B=await Qa(M),F=Ei(x,B);if(F.length)throw new zo(F);const E=/* @__PURE__ */new Set([i,h,Cu]);for(const[N,z]of Object.entries(r.files)){if(z.dir||E.has(N))continue;const e=O.file(N);if(!e||!Ou(await z.async("uint8array"),await e.async("uint8array")))return Tu("existing part changed: "+N)}for(const[N,z]of Object.entries(O.files))if(!z.dir&&!r.file(N)&&!P.has(N.toLowerCase()))return Tu("unexpected added part: "+N);for(const N of a.addedParts){const e=B.parts[N.path];if(!e||e.contentType!==N.contentType||e.kind!==N.kind||e.encoding!==N.encoding||e.data!==N.data)return Tu("copied payload mismatch")}for(const[N,z]of Object.entries(o.parts))if(B.parts[N]?.contentType!==z.contentType)return Tu("existing part content type changed");for(const[N,z]of Object.entries(o.contentTypes.defaults))if(B.contentTypes.defaults[N]!==z)return Tu("existing default changed");for(const[N,z]of Object.entries(o.contentTypes.overrides))if(B.contentTypes.overrides[N]!==z)return Tu("existing override changed");const D=B.parts[i]?.relationships??[],L=x.parts[i].relationships??[];return JSON.stringify(D)!==JSON.stringify(L)?Tu("owner relationships changed"):{buffer:M,plan:a}}var Eu=e=>{throw Error("Opaque editor transfer rejected: "+e)};function Du(e){return 1!==e.sections?.length?Eu("only one section is supported"):e.sections[0].blocks.filter(e=>"paragraph"===e.type)}function Lu(e){if(!e.document.sourcePackage||"main"!==jr(e)||1!==e.document.sections?.length||e.trackChangesEnabled||e.document.opaqueDeletionIntents?.length||e.document.opaqueRelocationIntent||e.document.bookmarks?.order.length||e.document.comments?.order.length)return Eu("unsupported state or pending opaque edit")}function Nu(e){Lu(e);const t=Ki(e,e=>"opaque"===e.kind);if(!t||"opaque"!==t.run.kind||t.run.revision||t.run.sdtWrappers?.length||!Du(e.document).some(e=>e.id===t.paragraph.id))return Eu("select one unwrapped chart in the main story");const n=e.document.sourcePackage,r=t.run.opaque,o=Kr(n).objects.filter(e=>e.ownerPath===n.mainDocumentPart&&e.signature===r.signature),a=1===o.length?o[0]:void 0;return a&&a.fragmentXml===r.fragmentXml&&JSON.stringify(a.relationshipIds)===JSON.stringify(r.relationshipIds)?function(e,t){const n=Kr(e);if(n.diagnostics.some(e=>"error"===e.level))return es("source inspection errors");const r=n.objects.filter(e=>e.signature===t.signature),o=1===r.length?r[0]:void 0;if(!o||o.ownerPath!==t.ownerPath||o.ordinal!==t.ordinal)return es("ambiguous original identity");if("chart"!==o.kind||"inline"!==o.geometry?.placement)return es("only inline charts are supported");const a=lo(e,o.ownerPath,o.relationshipIds);if(a.issues.length)return es("unresolved source closure");const i=e.parts[o.ownerPath],s=a.partPaths.map(t=>{const n=Object.hasOwn(e.parts,t)?e.parts[t]:void 0;return n?{path:n.path,contentType:n.contentType,kind:n.kind,encoding:n.encoding,data:n.data,relationships:n.relationships??[]}:es("missing source part")});return ls({format:Qi,ownerPath:o.ownerPath,fragmentXml:o.fragmentXml,signature:o.signature,relationships:(i.relationships??[]).filter(e=>o.relationshipIds.includes(e.id)),parts:s})}(n,a):Eu("selection is not an unchanged original")}function zu(e){return JSON.stringify(Du(e).map(e=>{const t=[];let n=0;for(const r of e.runs)"opaque"===r.kind&&t.push([n,r.kind,r.opaque.signature]),n+=r.text.length;return[e.runs.map(e=>e.text).join(""),t]}))}function $u(e,t,n,r){const o=u(t,n,[r]),a=xi(o,n+1);return Vt(e,ko(e).map(e=>e.id===t.id?o:e),{anchor:a,focus:a})}async function Hu(e,t){Lu(e);const n=Ri(e);if(!n.isCollapsed)return Eu("paste requires a collapsed caret");const r=ko(e)[n.startIndex],o=Du(e.document).findIndex(e=>e.id===r?.id);if(!r||o<0)return Eu("caret must be in a direct body paragraph");const a=n.startParagraphOffset;if(!Number.isSafeInteger(a)||a<0||a>oi(r))return Eu("invalid caret");if(r.runs.some(e=>"text"!==e.kind&&"opaque"!==e.kind||e.revision||e.sdtWrappers?.length||e.styles?.link))return Eu("unsupported destination runs");const i=await uu(e.document);if(zu(await Ft(i.slice(0)))!==zu(e.document))return Eu("destination body projection mismatch");const s=await Fu(i,t,o),l=await Qa(s.buffer),c=l.opaqueObjects?.filter(e=>e.signature===s.plan.destinationRun.signature&&e.ownerPath===l.mainDocumentPart);if(1!==c?.length)return Eu("staged chart identity mismatch");const d={...s.plan.destinationRun,fragmentXml:c[0].fragmentXml,relationshipIds:[...c[0].relationshipIds]},u={id:_o("run"),kind:"opaque",text:"",opaque:d,styles:{}},p=function(e,t){const n=e.document.sourcePackage,r=Kr(n).objects,o=Kr(t).objects,a=/* @__PURE__ */new Set,i=ko(e).map(e=>{let i=!1;const s=e.runs.map(e=>{if("opaque"!==e.kind)return e;const s=e.opaque,l=r.filter(e=>e.signature===s.signature),c=o.filter(e=>e.signature===s.signature),d=l[0],u=c[0];return 1!==l.length||1!==c.length||!d||!u||d.ownerPath!==n.mainDocumentPart||u.ownerPath!==t.mainDocumentPart||d.kind!==s.objectKind||d.fragmentXml!==s.fragmentXml||JSON.stringify(d.relationshipIds)!==JSON.stringify(s.relationshipIds)||JSON.stringify(d.edges)!==JSON.stringify(u.edges)||JSON.stringify(d.partPaths)!==JSON.stringify(u.partPaths)||d.partPaths.some(e=>{const r=n.parts[e],o=t.parts[e];return!r||!o||r.kind!==o.kind||r.contentType!==o.contentType||r.encoding!==o.encoding||r.data!==o.data})||a.has(d.signature)?Eu("cannot rebind original chart provenance"):(a.add(d.signature),u.fragmentXml===s.fragmentXml?e:(i=!0,{...e,opaque:{...s,fragmentXml:u.fragmentXml,relationshipIds:[...u.relationshipIds]}}))});return i?{...e,runs:s}:e});return Vt(e,i,e.selection)}(e,l),f=ko(p).find(e=>e.id===r.id);if(!f)return Eu("target paragraph lost during rebind");const g={...$u(p,f,oi(f),u).document,sourcePackage:l};if(zu(await Ft(s.buffer))!==zu(g))return Eu("staged body projection mismatch");l.rebuiltPartHashes=await Da(g,l);const m=$u(p,f,a,u),h={...m,document:{...m.document,sourcePackage:l}},b=await uu(h.document);return zu(await Ft(b))!==zu(h.document)?Eu("exported caret position mismatch"):h}var Wu="application/x-oasis-chart-token",ju="web "+Wu;function Uu(e){return"application/x-oasis-chart-token"===e||"web application/x-oasis-chart-token"===e}var Vu,Ku=0;function _u(e){const t=++Ku;Vu=void 0;const n=Nu(e),r=globalThis.crypto.randomUUID();let o=!1;return{token:r,confirm:()=>!o&&t===Ku&&(o=!0,Vu={token:r,manifest:n,expires:Date.now()+3e5},!0)}}function Xu(e){return Vu&&Date.now()>=Vu.expires&&(Vu=void 0),Vu&&Vu.token===e?structuredClone(Vu.manifest):void 0}function qu(e){return e.map(na)}function Gu(e){return e.reduce((e,t)=>e+t.text.length,0)}function Yu(e,t,n){if(0===n.length)return e;const r=ko(e),o=r.findIndex(e=>e.id===t.paragraphId);if(-1===o)return e;const a=r[o],i=wa(a,t),s=qu(n[0].runs);if(1===n.length){const t=u(a,i,s),n=r.map((e,n)=>n===o?t:e),l=Gu(s),c=xi(t,i),d=xi(t,i+l);return Vt(e,n,{anchor:c,focus:d})}const l=Ln(a,0,i),c=Ln(a,i,oi(a)),d=n[n.length-1],p=n.slice(1,-1),f=N(ho(n[0].paragraphTemplate),[...l,...s],gt(a,i)),g=p.map(e=>N(ho(e.paragraphTemplate),qu(e.runs))),m=N(ho(d.paragraphTemplate),[...qu(d.runs),...c],gt(a,i)),h=[...r.slice(0,o),f,...g,m,...r.slice(o+1)],b=xi(f,Gu(l)),y=xi(m,Gu(d.runs));return Vt(e,h,{anchor:b,focus:y})}function Zu(e,n,r={}){if(Po(e))return e;const o=Ri(e);if(o.isCollapsed)return e;if(function(e,t){const n=Ri(e);if(n.isCollapsed)return!1;const r=ko(e),o=r.findIndex(e=>e.id===t.paragraphId);if(-1===o)return!1;if(o<n.startIndex||o>n.endIndex)return!1;const a=r[o],i=wa(a,t);return!(o===n.startIndex&&i<n.startParagraphOffset||o===n.endIndex&&i>n.endParagraphOffset)}(e,n))return e;if(Dt(e))return e;const a=ko(e).find(e=>e.id===n.paragraphId);if(a&&(cr(a)||t(a,wa(a,n),wa(a,n))))return e;const i=function(e){const t=Ri(e);if(t.isCollapsed)return[];const n=ko(e),r=[];for(let o=t.startIndex;o<=t.endIndex;o+=1){const e=n[o],a=o===t.startIndex?t.startParagraphOffset:0,i=o===t.endIndex?t.endParagraphOffset:oi(e),s=Ln(e,a,i);r.push({paragraphTemplate:ho(e),runs:s})}return r}(e);if(0===i.length)return e;const s=i.flatMap(e=>e.runs);if(s.some(e=>"opaque"===e.kind)){if(r.copy||e.trackChangesEnabled||1!==s.length||"opaque"!==s[0].kind||s[0].revision||s[0].sdtWrappers?.length||1!==i.length)return e;const t=ko(e),a=t.findIndex(e=>e.id===n.paragraphId);if(a<0)return e;const l=t[a],c=wa(l,n),d=o.endParagraphOffset-o.startParagraphOffset,u=a===o.startIndex&&c>o.endParagraphOffset?c-d:c,p=te(e),f=ko(p).find(e=>e.id===l.id);return f?Yu(p,xi(f,u),i):e}if(r.copy)return Yu(e,n,i);const l=function(e,t){const n=Ri(e),r=ko(e),o=r.findIndex(e=>e.id===t.paragraphId);if(-1===o)return t;const a=r[o],i=wa(a,t);if(n.startIndex===n.endIndex){if(o!==n.startIndex||i<=n.endParagraphOffset)return t;const e=r[n.startIndex];return xi(e,i-(n.endParagraphOffset-n.startParagraphOffset))}return t}(e,n);return Yu(te(e),l,i)}function Ju(e,t,n){return Yr(e,function(e,t,n){if(Po(e))return e;if(0===t.length)return e;if(ga(e.selection)&&!e.trackChangesEnabled?Xe(e):Dt(e))return e;const r=Dr(e,t,{styles:n});if(r)return r;const o=ga(e.selection)?e:te(e);if(!ga(e.selection)&&o===e)return e;const{paragraph:a,index:i,offset:s}=ae(o),l=n?{...n}:gt(a,s),c={id:`run:${Math.random().toString(36).slice(2,9)}`,text:t,styles:l,kind:"text"};o.trackChangesEnabled&&(c.revision={id:`rev:${Math.random().toString(36).slice(2,9)}`,type:"insert",author:"User",date:Date.now()});const d=!e.trackChangesEnabled&&ga(e.selection)?e.selection.focus.fieldBoundaryAffinity:void 0,p=u(a,s,[c],d),f=ko(o).map((e,t)=>t===i?p:e);return Vt(o,f,J(qa(p,s+t.length,d)))}(e,t,n))}function Qu(e){return Ju(e,"\v")}function ep(e,t,n){return Yr(e,function(e,t,n){if(Po(e))return e;if(0===t.length)return e;const r=t.replace(/\r\n/g,"\n").replace(/\r/g,"\n");if(!r.includes("\n"))return Ju(e,r,n);if(xe(e))return Ju(e,r,n);const o=Dr(e,void 0);if(o)return o;if(he(e))return e;const a=ga(e.selection)?e:te(e);if(!ga(e.selection)&&a===e)return e;const{paragraph:i,index:s,offset:l}=ae(a);if(he(a))return e;const c=r.split("\n"),d=n?{...n}:gt(i,l),{beforeRuns:u,afterRuns:p}=Le(i,l,a.selection.focus.fieldBoundaryAffinity),f=N(i,[...u,di(c[0],d)],d),g=c.slice(1,-1).map(e=>E([{text:e,styles:d}])),m=N(cr(i)?q(i,[]):E([]),[di(c[c.length-1],d),...p],d),h=ko(a),b=[...h.slice(0,s),f,...g,m,...h.slice(s+1)];return Vt(a,b,J(qa(m,c[c.length-1].length,"before-markers")))}(e,t,n))}function tp(e){const t=ko(e),n=Ri(e,t);if(n.isCollapsed)return!1;for(let r=n.startIndex;r<=n.endIndex;r++){const e=t[r];if(!e)continue;const o=r===n.startIndex?n.startParagraphOffset:0,a=r===n.endIndex?n.endParagraphOffset:oi(e);let i=0;for(const t of e.runs){const e=i+t.text.length;if("opaque"===t.kind&&i<a&&e>o)return!0;i=e}}return!1}function np(e){const t=Ri(e);if(t.isCollapsed)return"";const n=ko(e),r=[];let o=null;const a=()=>{o&&(r.push("bullet"===o?"</ul>":"</ol>"),o=null)};for(let i=t.startIndex;i<=t.endIndex;i+=1){const s=n[i];if(!s)continue;const l=i===t.startIndex?t.startParagraphOffset:0,c=i===t.endIndex?t.endParagraphOffset:oi(s),d=Ln(s,l,c),u=ht(s,e.document,d.map(e=>e.text).join("")),p=at(d,e.document);if(s.list?.kind){const e="bullet"===s.list.kind?"ul":"ol";o!==s.list.kind&&(a(),r.push(`<${e}>`),o=s.list.kind),r.push(`<li${u}>${p}</li>`);continue}a(),r.push(`<p${u}>${p}</p>`)}return a(),r.join("")}function rp(e,t){return Yr(e,function(e,t){if(Po(e))return e;if(0===t.length||Dt(e))return e;const n=t.every(e=>e.runs.every(e=>!e.image))?t.map(e=>e.runs.map(e=>e.text).join("")).join("\n"):void 0;if(n?.includes("\n")&&xe(e))return Ju(e,n);const r=Dr(e,n);if(r)return r;const o=ga(e.selection)?e:te(e);if(!ga(e.selection)&&o===e)return e;const{paragraph:a,index:i,offset:s}=ae(o),l=ko(o),c=0===oi(a);if(Dt(o))return e;const{beforeRuns:d,afterRuns:u}=Le(a,s),p=t.map(e=>{const t=so(e.runs.map(e=>({text:e.text,styles:Na(e.styles),image:e.image?{...e.image}:void 0})));return t.style=e.style?{...e.style}:void 0,t.list=e.list?{...e.list}:void 0,t});let f,g=J(xi(a,s));if(1===p.length){const e=p[0],t=e.runs.reduce((e,t)=>e+t.text.length,0),n=N(a,[...d,...e.runs.map(na),...u],gt(a,s));n.style=c&&void 0!==e.style?.tabs?{...a.style,tabs:e.style.tabs}:a.style?{...a.style}:e.style?{...e.style}:void 0,n.list=a.list?{...a.list}:e.list?{...e.list}:void 0,f=[...Yo(l.slice(0,i)),n,...Yo(l.slice(i+1))],g=J(xi(n,d.reduce((e,t)=>e+t.text.length,0)+t))}else{const e=p[0],t=p[p.length-1],n=t.runs.reduce((e,t)=>e+t.text.length,0),r=N(a,[...d,...e.runs.map(na)],gt(a,s));r.style=c&&void 0!==e.style?.tabs?{...a.style,tabs:e.style.tabs}:a.style?{...a.style}:e.style?{...e.style}:void 0,r.list=a.list?{...a.list}:e.list?{...e.list}:void 0;const o=p.slice(1,-1).map(ho),m=N(t,[...t.runs.map(na),...u],void 0);m.list=t.list?{...t.list}:void 0,f=[...Yo(l.slice(0,i)),r,...o,m,...Yo(l.slice(i+1))],g=J(xi(m,n))}return Vt(o,f,g)}(e,t))}function op(e,t){const n=ko(e),r=Ri(e,n);if(r.startIndex!==r.endIndex)return;const o=n[r.startIndex];if(!o)return;let a=r.startParagraphOffset,i=r.endParagraphOffset;if(r.isCollapsed&&("backward"===t?a-=1:i+=1),a<0||i>oi(o)||i-a!==1)return;let s,l=0;for(const h of o.runs){if(l===a&&"opaque"===h.kind&&""===h.text){s=h;break}l+=h.text.length}if(!s)return;if(e.trackChangesEnabled||s.revision||"main"!==jr(e))return e;const c=e.document.sourcePackage;if(!c)return e;const d=s.opaque.signature,u=(c.opaqueObjects??[]).filter(e=>e.signature===d);if(1!==u.length||u[0].ownerPath!==c.mainDocumentPart||u[0].issues.length)return e;const p=u[0],f=e.document.opaqueDeletionIntents??[];if(f.some(e=>e.ownerPath===p.ownerPath&&e.ordinal===p.ordinal))return e;const g=te({...e,selection:{anchor:xi(o,a),focus:xi(o,i)}}),m={ownerPath:p.ownerPath,ordinal:p.ordinal,signature:p.signature};return{...g,document:{...g.document,opaqueDeletionIntents:[...f,m]}}}function ap(e){return Yr(e,function(e){if(Po(e))return e;const t=op(e,"backward");if(void 0!==t)return t;if(!ga(e.selection))return te(e);const{paragraph:n,index:r,offset:o}=ae(e),a=ko(e);if(o>0){if(e.trackChangesEnabled&&Mn(e)||Un(e,n,o-1,o))return e;const t=Dr(e,"",{range:[o-1,o]});if(t)return t;if(cr(n)){const t={...e,selection:{anchor:xi(n,o-1),focus:xi(n,o)}};return te(t)}if(e.trackChangesEnabled){const t=n.runs;let i=0,s=-1,l=-1;for(let e=0;e<t.length;e+=1){const n=i+t[e].text.length;if(o<=n){s=e,l=o-i;break}i=n}if(-1!==s){const i=t[s];if("insert"===i.revision?.type){const t=[...Ln(n,0,o-1),...Ln(n,o,oi(n))],i=N(n,t),s=a.map((e,t)=>t===r?i:e);return Vt(e,s,J(xi(i,o-1)))}const c=i.text[l-1],d={id:`run:${Math.random().toString(36).slice(2,9)}`,text:c,kind:"text",styles:{...i.styles},revision:{id:`rev:${Math.random().toString(36).slice(2,9)}`,type:"delete",author:"User",date:Date.now()}},u=[...Ln(n,0,o-1),d,...Ln(n,o,oi(n))],p=N(n,u),f=a.map((e,t)=>t===r?p:e);return Vt(e,f,J(xi(p,o-1)))}}const i=N(n,[...Ln(n,0,o-1),...Ln(n,o,oi(n))],gt(n,o-1)),s=a.map((e,t)=>t===r?i:e);return Vt(e,s,J(xi(i,o-1)))}if(0===r)return e;const i=a[r-1];if(Je(e,i,n))return e;const s=N(i,[...i.runs.map(na),...n.runs.map(na)]),l=[...a.slice(0,r-1),s,...a.slice(r+1)];return Vt(e,l,J(qa(s,oi(i),je(i,n))))}(e))}function ip(e){return Yr(e,function(e){if(Po(e))return e;const t=op(e,"forward");if(void 0!==t)return t;if(!ga(e.selection))return te(e);const{paragraph:n,index:r,offset:o}=ae(e),a=ko(e);if(o<oi(n)){if(e.trackChangesEnabled&&Mn(e)||Un(e,n,o,o+1))return e;const t=Dr(e,"",{range:[o,o+1]});if(t)return t;if(cr(n)){const t={...e,selection:{anchor:xi(n,o),focus:xi(n,o+1)}};return te(t)}if(e.trackChangesEnabled){const t=n.runs;let i=0,s=-1,l=-1;for(let e=0;e<t.length;e+=1){const n=i+t[e].text.length;if(o<n){s=e,l=o-i;break}i=n}if(-1!==s){const i=t[s];if("insert"===i.revision?.type){const t=[...Ln(n,0,o),...Ln(n,o+1,oi(n))],i=N(n,t),s=a.map((e,t)=>t===r?i:e);return Vt(e,s,J(xi(i,o)))}const c=i.text[l],d={id:`run:${Math.random().toString(36).slice(2,9)}`,text:c,kind:"text",styles:{...i.styles},revision:{id:`rev:${Math.random().toString(36).slice(2,9)}`,type:"delete",author:"User",date:Date.now()}},u=[...Ln(n,0,o),d,...Ln(n,o+1,oi(n))],p=N(n,u),f=a.map((e,t)=>t===r?p:e);return Vt(e,f,J(xi(p,o)))}}const i=N(n,[...Ln(n,0,o),...Ln(n,o+1,oi(n))],gt(n,o)),s=a.map((e,t)=>t===r?i:e);return Vt(e,s,J(xi(i,o)))}if(r>=a.length-1)return e;const i=a[r+1];if(Je(e,n,i))return e;const s=N(n,[...n.runs.map(na),...i.runs.map(na)]),l=[...a.slice(0,r),s,...a.slice(r+2)];return Vt(e,l,J(qa(s,o,je(n,i))))}(e))}function sp(e,t,n,r,o){let a=pa(n,r,o);const i=pi(a,t.style?.styleId,e.document.styles);return!o&&i[r]&&(a={...a,[r]:!1}),!o||"superscript"!==r&&"subscript"!==r||(a=sp(e,t,a,"superscript"===r?"subscript":"superscript",!1)),a}function lp(e,t){return Yr(e,function(e,t){if(Po(e))return e;const n=Ri(e);if(n.isCollapsed||U(e))return e;const r=ko(e),o=r.slice(n.startIndex,n.endIndex+1).flatMap((t,r)=>{const o=n.startIndex+r,a=o===n.startIndex?n.startParagraphOffset:0,i=o===n.endIndex?n.endParagraphOffset:oi(t);return Ln(t,a,i).map(n=>({...n,styles:pi(n.styles,t.style?.styleId,e.document.styles)}))}).filter(e=>e.text.length>0);if(0===o.length)return e;const a=!o.every(e=>Boolean(e.styles?.[t])),i=r.map((r,o)=>{if(o<n.startIndex||o>n.endIndex)return r;const i=o===n.startIndex?n.startParagraphOffset:0,s=o===n.endIndex?n.endParagraphOffset:oi(r);return M(e,r,i,s,n=>({...n,styles:sp(e,r,n.styles,t,a)}))});return Vt(e,i,H(i,n))}(e,t))}function cp(e){return Yr(e,function(e){if(Po(e))return e;const t=Ri(e);if(t.isCollapsed||U(e))return e;const n=ko(e).map((n,r)=>{if(r<t.startIndex||r>t.endIndex)return n;const o=r===t.startIndex?t.startParagraphOffset:0,a=r===t.endIndex?t.endParagraphOffset:oi(n);return M(e,n,o,a,e=>{const t=e.styles?.link,n=null!=t&&""!==t?{link:t}:{};return{...e,styles:n}})});return Vt(e,n,H(n,t))}(e))}function dp(e,t){return Yr(e,function(e,t){if(Po(e))return e;const n=Ri(e);if(n.isCollapsed||U(e))return e;const r=ko(e).map((r,o)=>{if(o<n.startIndex||o>n.endIndex)return r;const a=o===n.startIndex?n.startParagraphOffset:0,i=o===n.endIndex?n.endParagraphOffset:oi(r);return M(e,r,a,i,n=>{let o=hi(sp(e,r,n.styles,"underline",null!==t),"underlineStyle","single"===t?null:t);return"single"!==t&&null!==t||!pi(o,r.style?.styleId,e.document.styles).underlineStyle||(o={...o,underlineStyle:t}),{...n,styles:o}})});return Vt(e,r,H(r,n))}(e,t))}function up(e,t,n){return Yr(e,function(e,t,n){if(Po(e))return e;const r=Ri(e);if(r.isCollapsed||U(e))return e;const o=ko(e).map((o,a)=>{if(a<r.startIndex||a>r.endIndex)return o;const i=a===r.startIndex?r.startParagraphOffset:0,s=a===r.endIndex?r.endParagraphOffset:oi(o);return M(e,o,i,s,e=>({...e,styles:hi(e.styles,t,n)}))});return Vt(e,o,H(o,r))}(e,t,n))}function pp(e,t){return Yr(e,function(e,t){if(Po(e))return e;const n=Ri(e);if(n.isCollapsed||U(e))return e;const r=ko(e),o=e.document.styles,a=r.map((r,a)=>{if(a<n.startIndex||a>n.endIndex)return r;const i=a===n.startIndex?n.startParagraphOffset:0,s=a===n.endIndex?n.endParagraphOffset:oi(r);return M(e,r,i,s,e=>{const n=(pi(e.styles,r.style?.styleId,o).fontSize??14.6667)*go,a=Math.max(1,Math.min(1638,n+t));return{...e,styles:hi(e.styles,"fontSize",a/go)}})});return Vt(e,a,H(a,n))}(e,t))}function fp(e){return Yr(e,function(e){if(Po(e))return e;const t=Ri(e);if(t.isCollapsed||U(e))return e;const n=ko(e),r=n.slice(t.startIndex,t.endIndex+1).flatMap((e,n)=>{const r=t.startIndex+n,o=r===t.startIndex?t.startParagraphOffset:0,a=r===t.endIndex?t.endParagraphOffset:oi(e);return Ln(e,o,a)}).filter(e=>e.text.length>0);if(0===r.length)return e;const o=!r.every(e=>Boolean(e.styles?.textBorder)),a=n.map((n,r)=>{if(r<t.startIndex||r>t.endIndex)return n;const a=r===t.startIndex?t.startParagraphOffset:0,i=r===t.endIndex?t.endParagraphOffset:oi(n);return M(e,n,a,i,e=>({...e,styles:mp(e.styles,o)}))});return Vt(e,a,H(a,t))}(e))}var gp={width:.5,type:"solid",color:"#000000"};function mp(e,t){const n={...e??{}};return t?n.textBorder=gp:delete n.textBorder,Object.keys(n).length>0?n:void 0}function hp(e){return/\p{L}/u.test(e)}function bp(e,t){switch(t){case"lower":return e.toLowerCase();case"upper":return e.toUpperCase();case"capitalize":return function(e){let t="",n=!1;for(const r of e){const e=hp(r);t+=e&&!n?r.toUpperCase():r,n=e}return t}(e);case"toggle":return function(e){let t="";for(const n of e){const e=n.toUpperCase(),r=n.toLowerCase();t+=n===r&&n!==e?e:n===e&&n!==r?r:n}return t}(e);default:return function(e){let t="",n=!0;for(const r of e.toLowerCase())n&&hp(r)?(t+=r.toUpperCase(),n=!1):(t+=r,"."!==r&&"!"!==r&&"?"!==r||(n=!0));return t}(e)}}function yp(e,t){return function(e,t){const n=Ri(e);if(n.isCollapsed)return e;const r=ko(e).map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const o=r===n.startIndex?n.startParagraphOffset:0,a=r===n.endIndex?n.endParagraphOffset:oi(e),i=t(Ln(e,o,a).map(e=>e.text).join(""));let s=0;return fe(e,o,a,e=>{const t=e.text.length,n=i.slice(s,s+t);return s+=t,{...e,text:n}})});return Vt(e,r,H(r,n))}(e,e=>bp(e,t))}var vp=["bold","italic","underline","underlineStyle","underlineColor","strike","doubleStrike","smallCaps","allCaps","superscript","subscript","link"];function xp(e,t){const n=Na(e)??{};delete n.link;for(const r of vp)void 0!==t?.[r]&&Object.assign(n,{[r]:t[r]});return Object.keys(n).length>0?n:void 0}function wp(e,t){if(0===t.length)return[];const n=Ri(e),r=ko(e)[n.startIndex];if(!r)return t;const o=gt(r,n.startParagraphOffset);return t.map(e=>({runs:e.runs.map(e=>({...e,styles:xp(o,e.styles)})),style:fi(r.style),list:r.list?{...r.list}:void 0}))}function Ip(e){if("undefined"==typeof document||0===e.trim().length)return[];const t=document.createElement("template");t.innerHTML=e;const n=[],r=Array.from(t.content.childNodes),o=(e,t,r)=>{const o=t.length>0?t:[di("")];n.push({runs:o.map(e=>{const t=ki(e);return{text:e.text,styles:Na(e.styles),image:t?{...t}:void 0}}),style:e?Or(e):void 0,list:r})},a=(e,t)=>{for(const n of Array.from(e.children))"LI"===n.tagName&&o(n,ce(n,void 0),{kind:t,level:0})};for(const i of r){if(i.nodeType===Node.TEXT_NODE){const e=i.textContent??"";e.trim().length>0&&o(null,[di(e)]);continue}if(i.nodeType!==Node.ELEMENT_NODE)continue;const e=i,t=s(e.tagName);if(t){a(e,t);continue}if(dn(e.tagName)){o(e,ce(e,void 0),"LI"===e.tagName?{kind:"bullet",level:0}:void 0);continue}const n=ce(e,void 0);n.length>0&&o(null,n)}return n}async function Sp(e,t){if(e.isReadOnly())return!1;if("undefined"==typeof navigator||!Boolean(navigator.clipboard?.read||navigator.clipboard?.readText))return e.onIssue?.("access-denied"),!1;const n=e.stateSnapshot?.()??e.state(),r={anchor:{...n.selection.anchor},focus:{...n.selection.focus}};let o;try{o=await async function(e){const t=navigator.clipboard;let n=/* @__PURE__ */new Error("Clipboard access unavailable"),r=!1,o=!1;const a="text"===e&&Boolean(t?.readText);if(a)try{const e=await t.readText();return e?{kind:"content",text:e,html:""}:{kind:"empty"}}catch(i){n=i}if(t?.read)try{const n=await t.read(),a=n.flatMap(e=>e.types.filter(Uu).map(t=>({item:e,type:t})));if(a.length){if(1!==a.length||"rich"!==e)return{kind:"unsupported"};try{const e=await a[0].item.getType(a[0].type);if(e.size>128)return{kind:"unsupported"};const t=await e.text();return t.length<=128?{kind:"chart",token:t}:{kind:"unsupported"}}catch{return{kind:"unsupported"}}}let i="",s="";for(const t of n)"text"!==e&&t.types.includes("text/html")&&(i=await(await t.getType("text/html")).text()),t.types.includes("text/plain")&&(s=await(await t.getType("text/plain")).text());if(i||s)return{kind:"content",html:i,text:s};r=!0,o=n.length>0}catch(i){n=i}if(!a&&t?.readText)try{const e=await t.readText();if(e)return{kind:"content",text:e,html:""};r=!0}catch(i){n=i}if(r)return{kind:o?"unsupported":"empty"};throw n}(t)}catch(l){return e.onError?.(l),e.onIssue?.("access-denied"),!1}if(e.isReadOnly())return!1;if(e.state().document!==n.document)return e.onIssue?.("document-changed"),!1;if("chart"===o.kind){if("rich"!==t||!e.stateSnapshot)return e.onIssue?.("unsupported"),!1;const r=Xu(o.token);if(!r)return e.onIssue?.("unsupported"),!1;if(e.stateSnapshot()!==n)return e.onIssue?.("document-changed"),!1;let a;try{a=await Hu(n,r)}catch(l){return e.isReadOnly()||(e.onError?.(l),e.onIssue?.("unsupported")),!1}if(e.isReadOnly())return!1;if(e.stateSnapshot()!==n)return e.onIssue?.("document-changed"),!1;let i=!1;return e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(t=>e.isReadOnly()||t!==n?t:(i=!0,a)),i?e.focusInput():e.isReadOnly()||e.onIssue?.("document-changed"),i}if("content"!==o.kind)return e.onIssue?.(o.kind),!1;const a="text"!==t?Ip(o.html):[],i="merge"===t?wp({...n,selection:r},a):a;if(0===i.length&&0===o.text.length)return e.onIssue?.("unsupported"),!1;e.clearPreferredColumn(),e.resetTransactionGrouping();let s=!1;return e.applyTransactionalState(t=>{if(t.document!==n.document||e.isReadOnly())return t;const a={...t,selection:r},l=e.applyTableAwareParagraphEdit(a,e=>i.length>0?rp(e,i):ep(e,o.text));return s=l.document!==t.document,l}),s&&e.focusInput(),s}function Cp(e){if("undefined"==typeof document||"function"!=typeof document.execCommand)return!1;const t=document.activeElement,n=document.createElement("textarea");n.value=e,n.readOnly=!0,n.setAttribute("aria-hidden","true"),n.style.cssText="position:fixed;opacity:0;left:-9999px;top:0",document.body.appendChild(n);try{return n.focus({preventScroll:!0}),n.select(),document.execCommand("copy")}catch{return!1}finally{n.remove(),t instanceof HTMLElement&&t.focus({preventScroll:!0})}}function kp(e){const t="undefined"!=typeof navigator?navigator.clipboard:void 0;if(t?.writeText)try{return t.writeText(e).then(()=>!0,()=>Cp(e))}catch{}return Promise.resolve(Cp(e))}async function Tp(e,t){if(tp(e)){let n;try{n=_u(e)}catch{return t?.("unsupported"),!1}const r="undefined"!=typeof navigator?navigator.clipboard:void 0;if(!r?.write||"undefined"==typeof ClipboardItem)return t?.("unsupported"),!1;try{const e=new ClipboardItem({[ju]:new Blob([n.token],{type:ju.slice(4)})});return await r.write([e]),n.confirm()}catch{return t?.("access-denied"),!1}}const n=await function(e){const t=Wi(e);if(!t)return Promise.resolve(!1);const n="undefined"!=typeof navigator?navigator.clipboard:void 0;if(n?.write&&"undefined"!=typeof ClipboardItem)try{const r=np(e),o=new ClipboardItem({"text/plain":new Blob([t],{type:"text/plain"}),"text/html":new Blob([r],{type:"text/html"})});return n.write([o]).then(()=>!0,()=>kp(t))}catch{}return kp(t)}(e);return!n&&Wi(e)&&t?.("access-denied"),n}function Pp(e){return function(e){const[t,n]=Nt();let r,o=0;zn()&&Ut(()=>{o++});const a=()=>{n(void 0),r=void 0},i=()=>{o++,a()},s=async(t,i="rich")=>{const s=++o;a();const l=e.stateSnapshot?.()??e.state(),c=a=>{s===o&&(n({action:t,issue:a,..."paste"===t?{mode:i}:{}}),"access-denied"!==a&&"unsupported"!==a||("paste"!==t||"unsupported"===a&&"rich"!==i||(r={document:l.document,mode:i}),e.focusInput()),e.onIssue?.(a))};if("copy"===t)return Tp(l,c);const d={...e,onIssue:c,isReadOnly:()=>s!==o||e.isReadOnly()};return"cut"===t?async function(e){if(e.isReadOnly())return!1;const t=e.stateSnapshot?.()??e.state();if(tp(t))return e.onIssue?.("unsupported"),!1;if(!Wi(t))return!1;if(!(await Tp(t,e.onIssue))||e.isReadOnly())return!1;if(e.state().document!==t.document)return e.onIssue?.("document-changed"),!1;const n={anchor:{...t.selection.anchor},focus:{...t.selection.focus}};let r=!1;return e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(o=>{if(e.isReadOnly()||o.document!==t.document)return o;const a={...o,selection:n},i=e.applyTableAwareParagraphEdit(a,e=>ap(e));return r=i.document!==o.document,i}),r&&e.focusInput(),r}(d):Sp(d,i)},l=()=>{const t=r;return i(),t?.document===e.state().document?t.mode:void 0},c=(t,r)=>{o++,a(),n({action:t,issue:r,..."paste"===t?{mode:"rich"}:{}}),e.onIssue?.(r)};return{notice:t,dismiss:i,reportNativeIssue:c,requestGeneration:()=>o,consumePasteMode:l,copy:()=>s("copy"),cut:()=>s("cut"),paste:(e="rich")=>s("paste",e),hasSelection:()=>Wi(e.state()).length>0}}(e)}var Rp=/*#__PURE__*/qn("<div class=oasis-editor-clipboard-feedback role=status aria-live=polite aria-atomic=true>"),Ap=/*#__PURE__*/qn("<div class=oasis-editor-clipboard-feedback-message data-testid=editor-clipboard-feedback>");function Mp(e){const t=D();let n;const[r,o]=Nt(12);mn(()=>{if(!e.notice())return;const t=n?.parentElement;if(!t)return;const r=()=>{const e=t.getBoundingClientRect(),r=t.querySelector(".oasis-editor-toolbar"),a=r?r.getBoundingClientRect().bottom-e.top+8:12,i=Math.max(12,12-e.top),s=window.innerHeight-e.top-(n?.offsetHeight??0)-12;o(Math.max(i,Math.min(a,s)))};queueMicrotask(r);const a=new ResizeObserver(r);a.observe(t),n&&a.observe(n);const i=t.querySelector(".oasis-editor-toolbar");i&&a.observe(i),window.addEventListener("resize",r),window.addEventListener("scroll",r,!0),Ut(()=>{a.disconnect(),window.removeEventListener("resize",r),window.removeEventListener("scroll",r,!0)})});return a=Rp(),"function"==typeof n?Qt(n,a):n=a,Ue(a,wt(Bn,{get when(){return e.notice()},children:n=>{return r=Ap(),Ue(r,wt(ut,{name:"clipboard"}),null),Ue(r,wt(Pn,{get children(){return(e=>{const n=`${/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl+"}${"copy"===e.action?"C":"cut"===e.action?"X":"V"}`,r="access-denied"===e.issue?`clipboard.${e.action}Denied`:"empty"===e.issue?"clipboard.empty":"document-changed"===e.issue?"clipboard.documentChanged":e.mode&&"rich"!==e.mode?"clipboard.unsupportedOption":"clipboard.unsupported";return t(r,[n])})(n())}}),null),Ue(r,wt(g,{variant:"ghost",size:"sm",icon:"x",get label(){return t("generic.close")},get onClick(){return e.onDismiss},"data-testid":"editor-clipboard-feedback-close"}),null),r;var r}})),Pt(e=>Ot(a,"top",`${r()}px`)),a;var a}var Op=/[\s\-–—/_([{]/;function Bp(e,t){const n=e.trim().toLowerCase();if(0===n.length)return 0;const r=t.toLowerCase();if(r===n)return 1e3;const o=r.indexOf(n);if(o>=0){let e=400;return 0===o?e+=400:!function(e,t){return 0===t||Op.test(e[t-1]??"")}(r,o)?e+=100:e+=200,e+=Math.round(n.length/r.length*50),e}let a=0,i=-1,s=-1,l=0;for(const d of n){const e=r.indexOf(d,a);if(-1===e)return null;-1===i&&(i=e),l+=e-a,a=e+1,s=e}const c=s-i+1;return Math.max(1,120-l-4*Math.abs(c-n.length))}function Fp(e,t){const n=e.trim().toLowerCase();if(0===n.length)return 0;const r=Bp(n,t.label),o=Bp(n,t.command),a=Math.max(r??Number.NEGATIVE_INFINITY,(o??Number.NEGATIVE_INFINITY)-50);return Number.isFinite(a)?a:null}var Ep=/*#__PURE__*/qn("<ul id=editor-command-search-listbox class=oasis-command-search-list role=listbox data-testid=editor-command-search-listbox>"),Dp=/*#__PURE__*/qn("<div class=oasis-command-search-overlay role=presentation data-testid=editor-command-search-overlay><div class=oasis-command-search role=dialog aria-modal=true data-testid=editor-command-search>"),Lp=/*#__PURE__*/qn("<kbd class=oasis-command-search-shortcut>"),Np=/*#__PURE__*/qn("<li role=option class=oasis-command-search-option data-testid=editor-command-search-item>");function zp(e){const t=D(),[r,o]=Nt(""),[a,i]=Nt(0);let s;mn(()=>{e.isOpen&&(o(""),i(0),queueMicrotask(()=>{s?.focus()}))});const l=ur(()=>function(e,t,n=24){const r=e.trim().toLowerCase();if(0===r.length)return t.map(e=>({...e,score:0})).sort((e,t)=>e.label.localeCompare(t.label)).slice(0,n);const o=[];for(const a of t){const e=Fp(r,a);null!==e&&o.push({...a,score:e})}return o.sort((e,t)=>t.score-e.score||e.label.length-t.label.length),o.slice(0,n)}(r(),e.entries,12));mn(()=>{l(),i(e=>Math.min(e,Math.max(0,l().length-1)))});const c=t=>e.isEnabled(t.command,t.payload),d=t=>{c(t)&&e.onExecute(t)},u=e=>{const t=l().length;0!==t&&i(n=>(n+e+t)%t)},p=t=>{switch(t.key){case"ArrowDown":t.preventDefault(),u(1);break;case"ArrowUp":t.preventDefault(),u(-1);break;case"Enter":{t.preventDefault();const e=l()[a()];e&&d(e);break}case"Escape":t.preventDefault(),e.onClose()}};return wt(Bn,{get when(){return e.isOpen},get children(){var u=Dp(),f=u.firstChild;return Vn(u,"click",e.onClose,!0),f.$$keydown=p,f.$$click=e=>e.stopPropagation(),Ue(f,wt(pe,{id:"editor-command-search-input",get placeholder(){return t("commandSearch.placeholder")},get value(){return r()},onChange:e=>{o(e)},ref(e){"function"==typeof s?s(e):s=e},role:"combobox","aria-autocomplete":"list","aria-expanded":"true","aria-controls":"editor-command-search-listbox",get"aria-activedescendant"(){return Qe(()=>!!l()[a()])()?`editor-command-search-option-${a()}`:void 0},"data-testid":"editor-command-search-input",autocomplete:"off",spellcheck:!1}),null),Ue(f,wt(Pn,{class:"oasis-command-search-hint",get children(){return t("commandSearch.hint")}}),null),Ue(f,wt(Bn,{get when(){return l().length>0},get fallback(){return wt(Pn,{as:"p",class:"oasis-command-search-empty","data-testid":"editor-command-search-empty",get children(){return t("commandSearch.noResults")}})},get children(){var e=Ep();return Ue(e,wt(dt,{get each(){return l()},children:(e,t)=>{const r=()=>t()===a(),o=()=>c(e);return(s=Np()).$$click=()=>d(e),s.addEventListener("mouseenter",()=>{i(t())}),Ue(s,wt(Pn,{as:"span",get children(){return e.label}}),null),Ue(s,wt(Bn,{get when(){return e.shortcut},get children(){var t=Lp();return Ue(t,()=>e.shortcut),t}}),null),Pt(a=>{var i=`editor-command-search-option-${t()}`,l=r(),c=!o()||void 0,d=!!r(),u=!o(),p=e.command;return i!==a.e&&n(s,"id",a.e=i),l!==a.t&&n(s,"aria-selected",a.t=l),c!==a.a&&n(s,"aria-disabled",a.a=c),d!==a.o&&s.classList.toggle("oasis-command-search-option-active",a.o=d),u!==a.i&&s.classList.toggle("oasis-command-search-option-disabled",a.i=u),p!==a.n&&n(s,"data-command",a.n=p),a},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),s;var s}})),e}}),null),Ue(f,wt(Gn,{size:"sm",variant:"ghost",class:"oasis-command-search-close",get onClick(){return e.onClose},"data-testid":"editor-command-search-close",get"aria-label"(){return t("generic.close")},children:"✕"}),null),Pt(()=>n(f,"aria-label",t("commandSearch.title"))),u}})}function $p(e){return e?"string"==typeof e?{command:e}:"object"==typeof e&&"string"==typeof e.name?{command:e.name,payload:e.payload}:null:null}function Hp(e){return $p(e.command)}qe(["click","keydown"]);var Wp=!1,jp=null,Up=null,Vp=null,Kp=[];function _p(){"undefined"!=typeof window&&(!function(){const e={BASE_URL:"./",DEV:!1,MODE:"lib",PROD:!0,SSR:!1},t=globalThis.process?.env??{};return!0===e.DEV||"test"===e.MODE||"test"===t.NODE_ENV||"1"===e.VITE_OASIS_CANVAS_DEBUG}()?Wp&&(delete window.__oasisCanvasDebug,Wp=!1):Wp||(window.__oasisCanvasDebug={getLastHit:()=>jp?{...jp}:null,getLayoutSnapshot:()=>Up?{...Up,surfaceRect:{...Up.surfaceRect},pages:Up.pages.map(e=>({...e})),paragraphs:Up.paragraphs.map(e=>({...e,lines:e.lines.map(e=>({...e,slots:e.slots.map(e=>({...e}))})),tableCell:e.tableCell?{...e.tableCell}:void 0})),inlineImages:Up.inlineImages.map(e=>({...e})),inlineTextBoxes:Up.inlineTextBoxes.map(e=>({...e})),unsupportedRegions:Up.unsupportedRegions.map(e=>({...e}))}:null,getSelection:()=>Vp?{anchor:{...Vp.anchor},focus:{...Vp.focus},activeZone:Vp.activeZone,activeSectionIndex:Vp.activeSectionIndex}:null,getMissEvents:()=>Kp.map(e=>({...e})),clearMissEvents:()=>{Kp=[]}},Wp=!0))}function Xp(e){Wp&&e&&(jp={timestamp:Date.now(),zone:e.zone,paragraphId:e.paragraphId,paragraphOffset:e.paragraphOffset,source:e.source,missReason:e.missReason,resolvedFromParagraph:e.resolvedFromParagraph})}var qp=["Aptos, sans-serif","Aptos Display, sans-serif","Arial","Arial Black","Bahnschrift, sans-serif","Book Antiqua, serif","Calibri, sans-serif","Calibri Light, sans-serif","Cambria, serif","Candara, sans-serif","Century Gothic, sans-serif","Comic Sans MS","Consolas, monospace","Constantia, serif","Corbel, sans-serif","Courier New","Franklin Gothic Medium, sans-serif","Garamond, serif","Georgia","Gill Sans, sans-serif","Helvetica, sans-serif","Impact","Inter","Lucida Console, monospace","Lucida Sans Unicode, sans-serif","Open Sans, sans-serif","Palatino Linotype, serif","Segoe UI, sans-serif","Tahoma, sans-serif","Times New Roman","Trebuchet MS, sans-serif","Verdana, sans-serif","Wingdings"];function Gp(e,t,n){const r=n?.trim();if(!r)return;const o=r.toLowerCase();t.has(o)||(t.add(o),e.push(r))}function Yp(e){return function(e){const[t,n]=Nt([]),r=()=>function(e,t,n=[]){const r=/* @__PURE__ */new Set,o=[],a=[];for(const i of Object.values(e?.styles??{}))Gp(o,r,i.textStyle?.fontFamily);Gp(o,r,t.fontFamily);for(const i of n)Gp(a,r,i);for(const i of qp)Gp(a,r,i);return[...o.sort((e,t)=>e.localeCompare(t)),...a.sort((e,t)=>e.localeCompare(t))]}(e.state().document,e.toolbarStyleState(),t()),o=()=>function(e,t){const n=new Set(kn);for(const o of Object.values(e?.styles??{})){const e=o.textStyle?.fontSize;"number"==typeof e&&Number.isFinite(e)&&n.add(Jt(e))}const r=Jt(Number(t.fontSize));return Number.isFinite(r)&&r>0&&n.add(r),Array.from(n).sort((e,t)=>e-t)}(e.state().document,e.toolbarStyleState());return{computeFontFamilyOptions:r,computeFontSizeOptions:o,loadLocalFontFamilyOptions:async()=>{if(t().length>0)return;const e=await b();e.length>0&&n(e)}}}(e)}var Zp="insertText",Jp="composition",Qp="insertImage",ef="insertTable",tf="moveImage",nf="splitListItem",rf="link",of="imageAlt",af="imageCaption",sf="imageResize",lf="imageCrop",cf="imageFlip",df="imageRotate",uf="imageTransparency",pf="imageReset",ff="layoutWrapPolygon",gf="specialIndent",mf="paraBorders",hf="paragraphMoveUp",bf="paragraphMoveDown",yf="findReplace",vf="findReplaceAll",xf="tableProperties",wf="paragraph-dialog",If="font-dialog",Sf="copyTextByDrag",Cf="moveTextByDrag",kf="mergeTable",Tf="splitTable",Pf="insertTableColumn",Rf="deleteTableColumn",Af="insertTableRow",Mf="deleteTableRow",Of="tableShading",Bf="tableBorders",Ff="tableWidth",Ef="tableAlign",Df="tableCellAlignment",Lf="tableCellVerticalAlign",Nf="tableCellTextDirection",zf="tableCellWidth",$f="tableColumnWidth",Hf="tableToText",Wf="textToTable",jf="tableSplitAtRow",Uf="tableSortAscending",Vf="tableSortDescending",Kf="tableDelete",_f="deleteTableCell",Xf="tableAutoFit",qf="tableRepeatHeaderRows",Gf="tableCellMargins",Yf="tableFormula",Zf="tableRowHeight",Jf="tableStyleOptions",Qf="tableStyleGallery",eg="tableDistribute",tg="layoutWrapPreset",ng="layoutFixedPosition",rg="shapeFill",og="shapeOutline",ag="shapeOutlineWidth",ig="floatingAlign",sg="floatingReorder",lg="floatingNudge",cg="floatingFixedPosition",dg="floatingRotation",ug="floatingWrap",pg="floatingWrapText",fg="floatingPositionPreset",gg="shapePreset",mg="textBoxTextDirection",hg="textBoxVerticalAlign",bg="textBoxAlt",yg="textBoxRotate",vg="textBoxWidthCm",xg="textBoxHeightCm";function wg(e,t){const n={...e},r=(e,t)=>{null==t?delete n[e]:n[e]=t};return r("align",t.align),r("indentLeft",t.indentLeft),r("indentRight",t.indentRight),r("indentFirstLine",t.indentFirstLine),r("indentHanging",t.indentHanging),n.mirrorIndents=t.mirrorIndents,r("spacingBefore",t.spacingBefore),r("spacingAfter",t.spacingAfter),r("lineHeight",t.lineHeight),r("lineRule",t.lineRule),n.contextualSpacing=t.contextualSpacing,r("outlineLevel",t.outlineLevel),r("shading",t.shading),r("borderTop",t.borders.top),r("borderRight",t.borders.right),r("borderBottom",t.borders.bottom),r("borderLeft",t.borders.left),n.pageBreakBefore=t.pageBreakBefore,n.keepWithNext=t.keepWithNext,n.keepLinesTogether=t.keepLinesTogether,n.widowControl=t.widowControl,r("tabs",t.tabs.length>0?t.tabs:null),n}function Ig(){return{id:`rev:${Math.random().toString(36).slice(2,9)}`,author:"User",date:Date.now()}}function Sg(e,t,n){const r={...e??{}};return null===n?delete r[t]:r[t]=n,Object.keys(r).length>0?r:void 0}function Cg(e,t){const n=Lo(e.document).map(e=>({...e,blocks:t(e.blocks),header:e.header?t(e.header):void 0,firstPageHeader:e.firstPageHeader?t(e.firstPageHeader):void 0,evenPageHeader:e.evenPageHeader?t(e.evenPageHeader):void 0,footer:e.footer?t(e.footer):void 0,firstPageFooter:e.firstPageFooter?t(e.firstPageFooter):void 0,evenPageFooter:e.evenPageFooter?t(e.evenPageFooter):void 0})),r=e.document.footnotes?{...e.document.footnotes,items:Object.fromEntries(Object.entries(e.document.footnotes.items).map(([e,n])=>[e,{...n,blocks:t(n.blocks)}]))}:void 0,o=e.document.endnotes?{...e.document.endnotes,items:Object.fromEntries(Object.entries(e.document.endnotes.items).map(([e,n])=>[e,{...n,blocks:t(n.blocks)}]))}:void 0;return{...e,document:{...e.document,sections:n,footnotes:r,endnotes:o}}}function kg(e,t){return e.map(e=>{if("paragraph"===e.type)return e;const n=t(e);return{...n,rows:n.rows.map(e=>({...e,cells:e.cells.map(e=>({...e,blocks:kg(e.blocks,t)}))}))}})}function Tg(e,t,n){const r=Lo(e)[t];if(r)return"header"===n?r.header:"footer"===n?r.footer:r.blocks}function Pg(e){const t=e.tablePath[e.tablePath.length-1];return t?{...e,rowIndex:t.rowIndex,cellIndex:t.cellIndex}:e}function Rg(e){const t=Ua(e),n=xo(e.document,e.selection.focus.paragraphId,t);return n?{activeSectionIndex:t,loc:Pg(n)}:null}function Ag(e,t,n){const r=t[0];if(!r)return e;const o=e[r.tableBlockIndex];if(!o||"table"!==o.type)return e;if(1===t.length){const t=n(o);if(t===o)return e;const a=[...e];return a[r.tableBlockIndex]=t,a}const a=o.rows[r.rowIndex],i=a?.cells[r.cellIndex];if(!a||!i)return e;const s=Ag(i.blocks,t.slice(1),n);if(s===i.blocks)return e;const l=[...a.cells];l[r.cellIndex]={...i,blocks:s};const c=[...o.rows];c[r.rowIndex]={...a,cells:l};const d=[...e];return d[r.tableBlockIndex]={...o,rows:c},d}function Mg(e,t){return Boolean(e?.some(e=>ra(e).some(e=>e.id===t)))}function Og(e,t,n){if("main"===t)return e.blocks;if("header"===t||"footer"===t){const r=function(e,t,n){return"header"===t?Mg(e.firstPageHeader,n)?"firstPage":Mg(e.evenPageHeader,n)?"evenPage":"default":Mg(e.firstPageFooter,n)?"firstPage":Mg(e.evenPageFooter,n)?"evenPage":"default"}(e,t,n);return e[Eo(t,r)]??null}return null}function Bg(e,t,n,r){return"main"===t?{...e,blocks:r(e.blocks)}:"header"===t?Mg(e.firstPageHeader,n)?{...e,firstPageHeader:r(e.firstPageHeader)}:Mg(e.evenPageHeader,n)?{...e,evenPageHeader:r(e.evenPageHeader)}:{...e,header:e.header?r(e.header):e.header}:"footer"===t?Mg(e.firstPageFooter,n)?{...e,firstPageFooter:r(e.firstPageFooter)}:Mg(e.evenPageFooter,n)?{...e,evenPageFooter:r(e.evenPageFooter)}:{...e,footer:e.footer?r(e.footer):e.footer}:e}function Fg(e,t){const n=t[0];if(!n||!e)return null;const r=e[n.tableBlockIndex];if(!r||"table"!==r.type)return null;if(1===t.length)return r;const o=r.rows[n.rowIndex],a=o?.cells[n.cellIndex];return o&&a?Fg(a.blocks,t.slice(1)):null}function Eg(e,t,n){const r=t[0];if(!r)return null;const o=e[r.tableBlockIndex];if(!o||"table"!==o.type)return null;if(1===t.length)return[...e.slice(0,r.tableBlockIndex),...n,...e.slice(r.tableBlockIndex+1)];const a=o.rows[r.rowIndex],i=a?.cells[r.cellIndex];if(!a||!i)return null;const s=Eg(i.blocks,t.slice(1),n);if(!s)return null;const l=[...a.cells];l[r.cellIndex]={...i,blocks:s};const c=[...o.rows];c[r.rowIndex]={...a,cells:l};const d=[...e];return d[r.tableBlockIndex]={...o,rows:c},d}function Dg(e){const t=Rg(e);if(!t)return null;const{activeSectionIndex:n,loc:r}=t,o=e.selection.focus.paragraphId;if("footnote"===r.zone)return Ng(e,o);const a=Lo(e.document)[n];return a?Og(a,r.zone,o):null}function Lg(e){const t=e.selection.focus.paragraphId,n=jr(e);if("footnote"===n)return Ng(e,t);const r=Ua(e),o=Lo(e.document)[r];return o?Og(o,n,t):null}function Ng(e,t){const n=qo(e.document,t)?.footnoteId??e.activeFootnoteId,r=e.document.footnotes;return(n?r?.items[n]:void 0)?.blocks??null}function zg(e,t){const n=Rg(e);if(!n)return e;const{activeSectionIndex:r,loc:o}=n,a=e.selection.focus.paragraphId,i=e=>Eg(e,o.tablePath,t)??e;if("footnote"===o.zone){const t=qo(e.document,a)?.footnoteId??e.activeFootnoteId,n=e.document.footnotes,r=t?n?.items[t]:void 0;return t&&n&&r?{...e,document:{...e.document,footnotes:{...n,items:{...n.items,[t]:{...r,blocks:i(r.blocks)}}}}}:e}const s=Lo(e.document).map((e,t)=>t===r?Bg(e,o.zone,a,i):e);return{...e,document:{...e.document,sections:s}}}function $g(e,t){const n=Rg(e);if(!n)return e;const{activeSectionIndex:r,loc:o}=n,a=e.selection.focus.paragraphId,i=e=>Ag(e,o.tablePath,t);if("footnote"===o.zone){const t=qo(e.document,a)?.footnoteId??e.activeFootnoteId,n=e.document.footnotes,r=t?n?.items[t]:void 0;return t&&n&&r?{...e,document:{...e.document,footnotes:{...n,items:{...n.items,[t]:{...r,blocks:i(r.blocks)}}}}}:e}const s=Lo(e.document).map((e,t)=>t===r?Bg(e,o.zone,a,i):e);return{...e,document:{...e.document,sections:s}}}var Hg={width:.5,type:"solid",color:"#000000"},Wg={width:0,type:"none",color:"transparent"};function jg(e){const t=Ua(e),n=xo(e.document,e.selection.anchor.paragraphId,t),r=xo(e.document,e.selection.focus.paragraphId,t);if(!n||!r||n.zone!==r.zone||!function(e,t){if(0===e.length||e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){const r=e[n],o=t[n];if(r.tableBlockIndex!==o.tableBlockIndex)return!1;if(n<e.length-1&&(r.rowIndex!==o.rowIndex||r.cellIndex!==o.cellIndex))return!1}return!0}(n.tablePath,r.tablePath))return null;const o=Tg(e.document,t,n.zone);if(!o)return null;const a=Zo(o,n.tablePath),i=Zo(o,r.tablePath),s=a?.[a.length-1],l=i?.[i.length-1];if(!s||!l||s.table!==l.table)return null;const c=n.tablePath[n.tablePath.length-1],d=r.tablePath[r.tablePath.length-1];if(!c||!d)return null;const u=Xa(s.table),p=u.find(e=>e.rowIndex===c.rowIndex&&e.cellIndex===c.cellIndex),f=u.find(e=>e.rowIndex===d.rowIndex&&e.cellIndex===d.cellIndex);if(!p||!f)return null;const g=Math.min(p.visualRowIndex,f.visualRowIndex),m=Math.max(p.visualRowIndex+p.rowSpan-1,f.visualRowIndex+f.rowSpan-1),h=Math.min(p.visualColumnIndex,f.visualColumnIndex),b=Math.max(p.visualColumnIndex+p.colSpan-1,f.visualColumnIndex+f.colSpan-1);return{entries:u,selectedEntries:u.filter(e=>e.visualRowIndex<=m&&e.visualRowIndex+e.rowSpan-1>=g&&e.visualColumnIndex<=b&&e.visualColumnIndex+e.colSpan-1>=h),startRow:g,endRow:m,startCol:h,endCol:b}}function Ug(e,t,n){const r=function(e){const t=/* @__PURE__ */new Set,n=jg(e);if(!n)return t;for(const r of n.selectedEntries)for(const e of r.cell.blocks)for(const n of ra(e))t.add(n.id);return t}(e);if(0===r.size)for(const i of function(e){const t=/* @__PURE__ */new Set,n=Ri(e),r=ko(e);for(let o=n.startIndex;o<=n.endIndex;o+=1)t.add(r[o].id);return t}(e))r.add(i);const o=r=>{let o=r.style;return e.trackChangesEnabled&&"revision"!==t&&"propertyRevision"!==t&&!o?.propertyRevision&&(o={...o??{},propertyRevision:{...Ig(),type:"property",previous:{...o??{}}}}),{...r,style:Sg(o,t,n)}},a=Lo(e.document).map(e=>({...e,blocks:br(e.blocks,r,o),header:e.header?br(e.header,r,o):void 0,footer:e.footer?br(e.footer,r,o):void 0}));return{...e,document:{...e.document,sections:a}}}function Vg(e,t){let n=Ug(e,"borderTop",t);return n=Ug(n,"borderRight",t),n=Ug(n,"borderBottom",t),n=Ug(n,"borderLeft",t),n}function Kg(e,t,n){const r=function(e){const t=Ri(e),n=ko(e),r=/* @__PURE__ */new Set;for(let o=t.startIndex;o<=t.endIndex;o+=1)r.add(n[o].id);return r}(e),o=a=>a.map(a=>{if("paragraph"===a.type)return a;const i=a.rows.map(e=>({...e,cells:e.cells.map(e=>({...e,blocks:o(e.blocks)}))})),s={...a,rows:i};return function(e,t){return e.rows.some(e=>e.cells.some(e=>e.blocks.some(e=>"paragraph"===e.type&&t.has(e.id))))}(a,r)?(r=>{let o=r.style;return e.trackChangesEnabled&&"revision"!==t&&!o?.revision&&(o={...o??{},revision:{...Ig(),type:"property",previous:{...o??{}}}}),{...r,style:Sg(o,t,n)}})(s):s});return Cg(e,o)}function _g(e,t,n,r){const o=o=>{if(o.id!==t)return o;let a=o.style;return e.trackChangesEnabled&&"revision"!==n&&!a?.revision&&(a={...a??{},revision:{...Ig(),type:"property",previous:{...a??{}}}}),{...o,style:Sg(a,n,r)}};return Cg(e,e=>kg(e,o))}function Xg(e,t,n){const r=Rg(e);if(!r)return e;return $g(e,o=>{const a=o.rows.map((o,a)=>a===r.loc.rowIndex?(()=>{let r=o.style;return e.trackChangesEnabled&&"revision"!==t&&"propertyRevision"!==t&&!r?.propertyRevision&&(r={...r??{},propertyRevision:{...Ig(),type:"property",previous:{...r??{}}}}),{...o,style:Sg(r,t,n)}})():o);return{...o,rows:a}})}function qg(e,t){const n=Rg(e);if(!n)return e;return $g(e,r=>({...r,rows:r.rows.map((r,o)=>{if(o!==n.loc.rowIndex)return r;let a=r.style;e.trackChangesEnabled&&!a?.propertyRevision&&(a={...a??{},propertyRevision:{...Ig(),type:"property",previous:{...a??{},isHeader:r.isHeader}}});const i=null===t?void 0:t;return{...r,isHeader:i,style:Sg(a,"isHeader",i??null)}})}))}function Gg(e,t,n){const r=r=>{if(r.id!==t)return r;const o=r.rows.map((t,r)=>{if(!Object.prototype.hasOwnProperty.call(n,r))return t;let o=t.style;return e.trackChangesEnabled&&!o?.propertyRevision&&(o={...o??{},propertyRevision:{...Ig(),type:"property",previous:{...o??{}}}}),{...t,style:Sg(o,"height",n[r])}});return{...r,rows:o}};return Cg(e,e=>kg(e,r))}function Yg(e){if("number"==typeof e&&Number.isFinite(e))return e;if("string"!=typeof e)return null;const t=e.trim().toLowerCase();if(!t||t.includes("%"))return null;if(t.endsWith("pt")){const e=Number.parseFloat(t.slice(0,-2));return Number.isFinite(e)?e:null}if(t.endsWith("px")){const e=Number.parseFloat(t.slice(0,-2));return Number.isFinite(e)?e*go:null}if(!/^[+-]?\d+(\.\d+)?$/.test(t))return null;const n=Number.parseFloat(t);return Number.isFinite(n)?n:null}function Zg(e,t,n,r,o){const a=a=>{if(a.id!==t)return a;const i=Xa(a),s=new Map(i.map(e=>[`${e.rowIndex}:${e.cellIndex}`,e])),l=Math.max(1,...i.map(e=>e.visualColumnIndex+Math.max(1,e.colSpan))),c=Array(l);let d=!1,u=!0;for(let e=0;e<l;e+=1){const t=Yg(n[e]);if(null!==t){c[e]=Math.max(1,t),d=!0;continue}const r=a.gridCols?.[e];if(!("number"==typeof r&&Number.isFinite(r)&&r>0)){u=!1;break}c[e]=r}const p=a.rows.map((t,r)=>{const o=t.cells.map((t,o)=>{const a=s.get(`${r}:${o}`);if(!a)return t;const i=n[a.visualColumnIndex+a.colSpan-1];if(void 0!==i&&1===a.colSpan){const n=e.trackChangesEnabled&&!t.style?.propertyRevision?{...Ig(),type:"property",previous:{...t.style??{}}}:t.style?.propertyRevision;return{...t,style:{...t.style??{},width:i,...n?{propertyRevision:n}:{}}}}return t});return{...t,cells:o}}),f={...a.style??{}};return!e.trackChangesEnabled||f.revision||void 0===r&&void 0===o||(f.revision={...Ig(),type:"property",previous:{...a.style??{}}}),void 0!==r&&(f.width=r),void 0!==o&&(f.indentLeft="number"==typeof o?o:Number(o)),{...a,rows:p,gridCols:d&&u?c:a.gridCols,gridRevision:e.trackChangesEnabled&&d&&u&&!a.gridRevision?{...Ig(),type:"grid",previous:[...a.gridCols??[]]}:a.gridRevision,style:Object.keys(f).length>0?f:void 0}};return Cg(e,e=>kg(e,a))}function Jg(e){const t=Rg(e);if(!t)return e;const n=Dg(e);if(!n)return e;const r=Fg(n,t.loc.tablePath);if(!r)return e;const o=function(e){const t=[];for(const n of e.rows)for(const e of n.cells)for(const n of e.blocks)"paragraph"===n.type&&t.push(ho(n));return t}(r);if(0===o.length)return e;const a=zg(e,o);if(a===e)return e;const i=o[0];return{...a,selection:J(xi(i,0))}}function Qg(e){if(Rg(e))return e;if(!Lg(e))return e;const t=ko(e);if(0===t.length)return e;const n=Ri(e,t),r=t.slice(n.startIndex,n.endIndex+1);if(0===r.length)return e;const o=function(e){const t=e.map(em),n=Math.max(1,...t.map(e=>e.length)),r=t.map(e=>Jo(Array.from({length:n},(t,n)=>{const r=e[n]??[],o={id:_o("paragraph"),type:"paragraph",runs:r.length>0?r:[wo("")]};return ta([o])})));return yo(r)}(r),a=r[0].id,i=r[r.length-1].id;let s=null,l=!1;const c=function(e,t){const n=e.selection.focus.paragraphId,r=jr(e),o=Ua(e);if("footnote"===r){const r=qo(e.document,n)?.footnoteId??e.activeFootnoteId,o=e.document.footnotes,a=r?o?.items[r]:void 0;return r&&o&&a?{...e,document:{...e.document,footnotes:{...o,items:{...o.items,[r]:{...a,blocks:t(a.blocks)}}}}}:e}const a=Lo(e.document).map((e,a)=>a===o?Bg(e,r,n,t):e);return{...e,document:{...e.document,sections:a}}}(e,e=>{const{nextBlocks:t,cell:n}=function(e,t,n,r){let o=-1,a=-1;for(let s=0;s<e.length;s+=1){const r=e[s];"paragraph"===r.type&&(r.id===t&&(o=s),r.id===n&&(a=s))}if(-1===o||-1===a||o>a)return{nextBlocks:null,cell:null};for(let s=o;s<=a;s+=1)if("paragraph"!==e[s].type)return{nextBlocks:null,cell:null};const i=r.rows[0]?.cells[0]?.blocks.find(e=>"paragraph"===e.type);return{nextBlocks:[...e.slice(0,o),r,...e.slice(a+1)],cell:i??null}}(e,a,i,o);return t&&n?(s=n,l=!0,t):e});return l&&s?{...c,selection:J(xi(s,0))}:e}function em(e){const t=[];let n=[];const r=()=>{n.length>0&&t.push(n),n=[]};for(const o of e.runs){const e=o.text.split("\t");for(let t=0;t<e.length;t+=1){t>0&&r();const a=e[t];if(a.length>0){const e=na(o);e.id=`run:${Math.random().toString(36).slice(2,9)}`,e.text=a,n.push(e)}}}return n.length>0&&t.push(n),t}function tm(e,t){const n=Rg(e);if(!n)return e;const r=n.loc.cellIndex;return $g(e,e=>{const n=function(e,t,n){const r=[],o=[];for(const l of e.rows)l.isHeader?r.push(l):o.push(l);if(o.length<2)return e.rows;const a="ascending"===n?1:-1,i=[...o].sort((e,n)=>{const r=nm(e.cells[t]),o=nm(n.cells[t]);return r.localeCompare(o,void 0,{numeric:!0})*a}),s=[...r,...i];return s.length===e.rows.length&&s.every((t,n)=>t===e.rows[n])?e.rows:s}(e,r,t);return n===e.rows?e:{...e,rows:n}})}function nm(e){return e?e.blocks.flatMap(e=>"paragraph"===e.type?[e]:ra(e)).map(e=>e.runs.map(e=>e.text).join("")).join("\n"):""}function rm(e){return!0===e.isHeader}function om(e){return null!==Rg(e)}function am(e){return null!==Rg(e)}var im=/* @__PURE__ */new Set(["left","center","right"]);function sm(e,t){const n=Rg(e);if(!n)return e;if(null!==t&&!im.has(t))return e;const r=function(e,t){const n=Rg(e);if(!n)return null;const r=Zo(t,n.loc.tablePath);return(r?.[r.length-1])?.table??null}(e,Tg(e.document,n.activeSectionIndex,n.loc.zone)??[]);if(!r)return e;const o=r.style?.align,a=null===t?void 0:t;return o===a?e:Kg(e,"align",a)}function lm(e){return null!==Rg(e)}var cm=["SUM","AVERAGE","COUNT","MIN","MAX"];function dm(e,t){const n=function(e){const t=/^\s*=\s*([A-Z]+)\s*\(\s*([A-Z]+)\s*\)\s*$/i.exec(e);if(!t)return null;const n=t[1].toUpperCase(),r=t[2].toUpperCase();return cm.includes(n)&&["ABOVE","BELOW","LEFT","RIGHT"].includes(r)?{function:n,direction:r}:null}(t);if(!n)return e;const r=Rg(e);if(!r)return e;const o=Dg(e);if(!o)return e;const a=Fg(o,r.loc.tablePath);if(!a)return e;const i=function(e,t,n){const r=Xa(e),o=r.find(e=>e.rowIndex===n.rowIndex&&e.cellIndex===n.cellIndex);if(!o)return[];const a=[];for(const i of r){if(i.rowIndex===n.rowIndex&&i.cellIndex===n.cellIndex)continue;if(!pm(o,i,t))continue;if(!fm(o,i,t))continue;const e=gm(um(i.cell));null!==e&&a.push(e)}return a}(a,n.direction,r.loc);if(0===i.length)return e;const s=function(e){if(Number.isInteger(e)||!Number.isFinite(e))return String(e);const t=Math.round(1e6*e)/1e6;return String(t)}(function(e,t){switch(e){case"SUM":return t.reduce((e,t)=>e+t,0);case"AVERAGE":return t.length>0?t.reduce((e,t)=>e+t,0)/t.length:0;case"COUNT":return t.length;case"MIN":return t.length>0?Math.min(...t):0;case"MAX":return t.length>0?Math.max(...t):0}}(n.function,i)),l=r.loc.rowIndex,c=r.loc.cellIndex,d=$g(e,e=>({...e,rows:e.rows.map((e,t)=>t!==l?e:{...e,cells:e.cells.map((e,t)=>t!==c?e:{...e,blocks:[Go(s)]})})}));if(d===e)return e;const u=Go(s);return{...d,selection:J(xi(u,s.length))}}function um(e){return e?e.blocks.flatMap(e=>"paragraph"===e.type?[e]:ra(e)).map(e=>e.runs.map(e=>e.text).join("")).join("\n"):""}function pm(e,t,n){if("LEFT"===n||"RIGHT"===n){const n=e.visualRowIndex+e.rowSpan,r=t.visualRowIndex+t.rowSpan;return e.visualRowIndex<r&&t.visualRowIndex<n}const r=e.visualColumnIndex+e.colSpan,o=t.visualColumnIndex+t.colSpan;return e.visualColumnIndex<o&&t.visualColumnIndex<r}function fm(e,t,n){switch(n){case"ABOVE":return t.visualRowIndex+t.rowSpan<=e.visualRowIndex;case"BELOW":return t.visualRowIndex>=e.visualRowIndex+e.rowSpan;case"LEFT":return t.visualColumnIndex+t.colSpan<=e.visualColumnIndex;case"RIGHT":return t.visualColumnIndex>=e.visualColumnIndex+e.colSpan}}function gm(e){const t=/\d+(?:[.,]\d+)?/.exec(e);if(!t)return null;const n=t[0].replace(",","."),r=Number(n);return Number.isFinite(r)?r:null}function mm(e,t){const n=function(e){const t=Rg(e);if(!t)return null;const n=Dg(e);if(!n)return null;const r=Fg(n,t.loc.tablePath);if(!r)return null;const o=Xa(r),a=o.find(e=>e.rowIndex===t.loc.rowIndex&&e.cellIndex===t.loc.cellIndex);return a?{table:r,entries:o,active:a}:null}(e);if(!n)return e;const{table:r,entries:o,active:a}=n,i=function(e,t,n,r){switch(r){case"cell":return[n];case"row":{const e=n.visualRowIndex,r=n.visualRowIndex+n.rowSpan;return t.filter(t=>{const n=t.visualRowIndex,o=t.visualRowIndex+t.rowSpan;return n<r&&e<o})}case"column":{const e=n.visualColumnIndex,r=n.visualColumnIndex+n.colSpan;return t.filter(t=>{const n=t.visualColumnIndex,o=t.visualColumnIndex+t.colSpan;return n<r&&e<o})}case"table":return[...t]}}(0,o,a,t);if(0===i.length)return e;const s=function(e){return[...e].sort((e,t)=>e.visualRowIndex!==t.visualRowIndex?e.visualRowIndex-t.visualRowIndex:e.visualColumnIndex-t.visualColumnIndex)}(i),l=s[0].cell,c=s[s.length-1].cell,d=hm(l),u=hm(c),p=d[0],f=u[u.length-1];return p&&f?{...e,selection:{anchor:xi(p,0),focus:xi(f,mi(f).length)}}:e}function hm(e){return e.blocks.flatMap(ra)}function bm(e){const t=function(e){const t=Rg(e);if(!t)return null;const n=Dg(e);if(!n)return null;const r=Fg(n,t.loc.tablePath);return r?r.rows[t.loc.rowIndex]??null:null}(e);return Boolean(t&&t.cells.length>1)}function ym(e){const t=Rg(e);if(!t)return e;const n=Dg(e);if(!n)return e;const r=Fg(n,t.loc.tablePath);if(!r)return e;const o=t.loc.rowIndex,a=t.loc.cellIndex,i=r.rows[o];if(!i||i.cells.length<=1||a>=i.cells.length)return e;const s=$g(e,e=>{const t=e.rows.map((e,t)=>{if(t!==o)return e;const n=e.cells.filter((e,t)=>t!==a);return{...e,cells:n}});return{...e,rows:t}});if(s===e)return e;const l=i.cells[Math.min(a,i.cells.length-2)],c=l?l.blocks.flatMap(ra)[0]??null:null;return c?{...s,selection:J(xi(c,0))}:s}var vm={activeTab:"table",tableWidth:"",tableWidthUnit:"points",tableAlign:"",tableIndentLeft:"",tableWrapping:"none",floatingSummary:"",floatingHorizontalAnchor:"margin",floatingVerticalAnchor:"text",floatingX:"0",floatingY:"0",floatingXAlign:"",floatingYAlign:"",floatingDistanceTop:"0",floatingDistanceRight:"0",floatingDistanceBottom:"0",floatingDistanceLeft:"0",floatingOverlap:"overlap",rowHeight:"",rowHeightRule:"",repeatHeader:!1,allowBreakAcrossPages:!0,hiddenRow:!1,columnWidth:"",cellWidth:"",cellVerticalAlign:"",cellTextDirection:"",cellNoWrap:!1,cellFitText:!1,cellHideMark:!1,marginTop:"",marginRight:"",marginBottom:"",marginLeft:"",borderStyle:"none",borderWidth:"",borderColor:"",borderTop:!1,borderRight:!1,borderBottom:!1,borderLeft:!1,borderStart:!1,borderEnd:!1,borderTopLeftToBottomRight:!1,borderTopRightToBottomLeft:!1,shading:"",altTitle:"",altDescription:""};function xm(e){const t=Ua(e),n=xo(e.document,e.selection.focus.paragraphId,t),r=n?.tablePath[n.tablePath.length-1];if(!n||!r)return null;const o=Zo(function(e,t){const n=Lo(e.document)[Ua(e)];return n?"header"===t?n.header??[]:"footer"===t?n.footer??[]:n.blocks:[]}(e,n.zone),n.tablePath),a=o?.[o.length-1]?.table;if(!a)return null;const i=Xa(a).find(e=>e.rowIndex===r.rowIndex&&e.cellIndex===r.cellIndex);return{table:a,tableId:a.id,rowIndex:r.rowIndex,cellIndex:r.cellIndex,visualColumnIndex:i?.visualColumnIndex??r.cellIndex}}function wm(e){if("number"==typeof e&&Number.isFinite(e))return{value:String(e),unit:"points"};if("string"==typeof e){const t=e.trim();if(t.endsWith("%"))return{value:t.slice(0,-1),unit:"percent"};const n=t.match(/^([0-9.]+)(pt)?$/i);if(n?.[1])return{value:n[1],unit:"points"}}return{value:"",unit:"points"}}function Im(e){return!!e&&"none"!==e.type&&e.width>0}function Sm(e,t="table"){const n=wm(e.table.style?.width),r=e.table.rows[e.rowIndex],o=r?.cells[e.cellIndex],a=wm(r?.style?.height),i=wm(o?.style?.width),s=e.table.gridCols?.[e.visualColumnIndex],l=wm(s),c=o?.style??{},d=[c.borderTop,c.borderRight,c.borderBottom,c.borderLeft,c.borderStart,c.borderEnd,c.borderTopLeftToBottomRight,c.borderTopRightToBottomLeft].filter(Im)[0],u=function(e){const t=e.style?.floating;return t&&0!==Object.keys(t).length?Object.entries(t).map(([e,t])=>`${e}=${t}`).join(", "):""}(e.table);return{...vm,activeTab:t,tableWidth:n.value,tableWidthUnit:n.unit,tableAlign:e.table.style?.align??"",tableIndentLeft:wm(e.table.style?.indentLeft).value,tableWrapping:u?"around":"none",floatingSummary:u,floatingHorizontalAnchor:e.table.style?.floating?.horizontalAnchor??"margin",floatingVerticalAnchor:e.table.style?.floating?.verticalAnchor??"text",floatingX:null!=e.table.style?.floating?.x?String(e.table.style.floating.x):"0",floatingY:null!=e.table.style?.floating?.y?String(e.table.style.floating.y):"0",floatingXAlign:e.table.style?.floating?.xAlign??"",floatingYAlign:e.table.style?.floating?.yAlign??"",floatingDistanceTop:String(e.table.style?.floating?.distanceTop??0),floatingDistanceRight:String(e.table.style?.floating?.distanceRight??0),floatingDistanceBottom:String(e.table.style?.floating?.distanceBottom??0),floatingDistanceLeft:String(e.table.style?.floating?.distanceLeft??0),floatingOverlap:e.table.style?.tblOverlap??"overlap",rowHeight:a.value,rowHeightRule:r?.style?.heightRule??"",repeatHeader:Boolean(r?.isHeader),allowBreakAcrossPages:!0!==r?.style?.cantSplit,hiddenRow:!0===r?.style?.hidden,columnWidth:l.value,cellWidth:i.value,cellVerticalAlign:c.verticalAlign??"",cellTextDirection:c.textDirection??"",cellNoWrap:!0===c.noWrap,cellFitText:!0===c.fitText,cellHideMark:!0===c.hideMark,marginTop:null!=c.paddingTop?String(c.paddingTop):"",marginRight:null!=c.paddingRight?String(c.paddingRight):"",marginBottom:null!=c.paddingBottom?String(c.paddingBottom):"",marginLeft:null!=c.paddingLeft?String(c.paddingLeft):"",borderStyle:d?.type??"none",borderWidth:d?String(d.width):"",borderColor:d?.color??"",borderTop:Im(c.borderTop),borderRight:Im(c.borderRight),borderBottom:Im(c.borderBottom),borderLeft:Im(c.borderLeft),borderStart:Im(c.borderStart),borderEnd:Im(c.borderEnd),borderTopLeftToBottomRight:Im(c.borderTopLeftToBottomRight),borderTopRightToBottomLeft:Im(c.borderTopRightToBottomLeft),shading:c.shading??"",altTitle:e.table.style?.altTitle??"",altDescription:e.table.style?.altDescription??""}}function Cm(e,t,n){return Ug(e,t,n)}function km(e){return Boolean(xm(e))}function Tm(e,t="table"){const n=xm(e);return n?Sm(n,t):null}function Pm(e){const t=()=>km(e.state());return{isInsideTable:t,openTablePropertiesDialog:(t="table")=>{const n=Tm(e.state(),t);n&&(e.setContextMenu({isOpen:!1,x:0,y:0}),e.setTablePropertiesDialog({isOpen:!0,initial:n}))},applyTablePropertiesDialogValues:n=>{e.isReadOnly()||t()&&(e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(e=>function(e,t){const n=xm(e);if(!n)return e;let r=e;return r=_g(r,n.tableId,"width",t.tableWidth),r=_g(r,n.tableId,"align",t.tableAlign),r=_g(r,n.tableId,"indentLeft",t.tableIndentLeft),r=_g(r,n.tableId,"floating",t.tableFloating),r=_g(r,n.tableId,"tblOverlap",t.tableOverlap),r=_g(r,n.tableId,"altTitle",t.altTitle),r=_g(r,n.tableId,"altDescription",t.altDescription),r=qg(r,t.repeatHeader),r=Xg(r,"height",t.rowHeight),r=Xg(r,"heightRule",t.rowHeightRule),r=Xg(r,"cantSplit",t.cantSplit),r=Xg(r,"hidden",t.hiddenRow),null!==t.columnWidth&&(r=Zg(r,n.tableId,{[n.visualColumnIndex]:t.columnWidth})),r=Cm(r,"width",t.cellWidth),r=Cm(r,"verticalAlign",t.cellVerticalAlign),r=Cm(r,"textDirection",t.cellTextDirection),r=Cm(r,"noWrap",t.cellNoWrap),r=Cm(r,"fitText",t.cellFitText),r=Cm(r,"hideMark",t.cellHideMark),r=Cm(r,"paddingTop",t.margins.top),r=Cm(r,"paddingRight",t.margins.right),r=Cm(r,"paddingBottom",t.margins.bottom),r=Cm(r,"paddingLeft",t.margins.left),r=Cm(r,"borderTop",t.borders.top),r=Cm(r,"borderRight",t.borders.right),r=Cm(r,"borderBottom",t.borders.bottom),r=Cm(r,"borderLeft",t.borders.left),r=Cm(r,"borderStart",t.borders.start),r=Cm(r,"borderEnd",t.borders.end),r=Cm(r,"borderTopLeftToBottomRight",t.borders.topLeftToBottomRight),r=Cm(r,"borderTopRightToBottomLeft",t.borders.topRightToBottomLeft),r=Cm(r,"shading",t.shading),r}(e,n),{mergeKey:xf}),e.focusInput())}}}function Rm(e){return function(e){const t=e.t,n=e.clipboardActions??Pp({...e,onIssue:t=>e.logger.warn("contextMenu:clipboard:not-completed",{issue:t})}),r=n.copy,o=n.cut,a=()=>n.paste("rich"),i=()=>{const n=!ga(e.state().selection),i=e.isReadOnly(),s=[{id:"cut",label:t("contextmenu.cut"),icon:"scissors",shortcut:"Ctrl+X",disabled:i||!n,testId:"editor-context-menu-cut",onSelect:()=>{o()}},{id:"copy",label:t("contextmenu.copy"),icon:"copy",shortcut:"Ctrl+C",disabled:!n,testId:"editor-context-menu-copy",onSelect:()=>{r()}},{id:"paste",label:t("contextmenu.paste"),icon:"clipboard",shortcut:"Ctrl+V",disabled:i,testId:"editor-context-menu-paste",onSelect:()=>{a()}},{id:"sep1",type:"separator"},{id:"link",label:t("contextmenu.link"),icon:"link",disabled:i||!n,testId:"editor-context-menu-link",onSelect:e.promptForLink},{id:"font",label:t("contextmenu.font"),icon:"type",disabled:i||!n,testId:"editor-context-menu-font",onSelect:e.openFontDialog},{id:"paragraph",label:t("contextmenu.paragraph"),icon:"pilcrow",disabled:i,testId:"editor-context-menu-paragraph",onSelect:e.openParagraphDialog}],l=e.table;return l?.isInsideTable()&&s.push({id:"sep-table",type:"separator"},{id:"table-properties",label:t("contextmenu.tableProperties"),icon:"table-properties",disabled:i,testId:"editor-context-menu-table-properties",onSelect:l.openProperties},{id:"table-insert-row-above",label:t("table.insertRowAbove"),icon:"rows-3",disabled:i||!l.canEditRow(),testId:"editor-context-menu-table-insert-row-above",onSelect:l.insertRowBefore},{id:"table-insert-row-below",label:t("table.insertRowBelow"),icon:"rows-3",disabled:i||!l.canEditRow(),testId:"editor-context-menu-table-insert-row-below",onSelect:l.insertRowAfter},{id:"table-insert-column-left",label:t("table.insertColumnLeft"),icon:"columns-3",disabled:i||!l.canEditColumn(),testId:"editor-context-menu-table-insert-column-left",onSelect:l.insertColumnBefore},{id:"table-insert-column-right",label:t("table.insertColumnRight"),icon:"columns-3",disabled:i||!l.canEditColumn(),testId:"editor-context-menu-table-insert-column-right",onSelect:l.insertColumnAfter},{id:"table-delete-row",label:t("table.deleteRow"),icon:"trash-2",disabled:i||!l.canEditRow(),testId:"editor-context-menu-table-delete-row",onSelect:l.deleteRow},{id:"table-delete-column",label:t("table.deleteColumn"),icon:"trash-2",disabled:i||!l.canEditColumn(),testId:"editor-context-menu-table-delete-column",onSelect:l.deleteColumn},{id:"table-merge",label:t("table.mergeTooltip"),icon:"combine",disabled:i||!l.canMerge(),testId:"editor-context-menu-table-merge",onSelect:l.merge},{id:"table-split",label:t("table.splitTooltip"),icon:"split",disabled:i||!l.canSplit(),testId:"editor-context-menu-table-split",onSelect:l.split},{id:"table-borders-shading",label:t("contextmenu.bordersAndShading"),icon:"frame",disabled:i,testId:"editor-context-menu-table-borders-shading",onSelect:l.openBordersAndShading}),s},s=t=>{t.preventDefault(),e.setContextMenu({isOpen:!0,x:t.clientX,y:t.clientY})},l=()=>{e.setContextMenu({isOpen:!1,x:0,y:0})};return{buildContextMenuItems:i,closeContextMenu:l,handleEditorContextMenu:s,programmaticCopy:r,programmaticCut:o,programmaticPaste:a}}(e)}function Am(e){const{state:t,tableOps:n,applyTableContextCommand:r}=e;return{isInsideTable:e.isInsideTable,canMerge:()=>n.canMergeSelectedTable(t()),canSplit:()=>n.canSplitSelectedTable(t()),canEditColumn:()=>n.canEditSelectedTableColumn(t()),canEditRow:()=>n.canEditSelectedTableRow(t()),openProperties:()=>e.openTablePropertiesDialog("table"),openBordersAndShading:()=>e.openTablePropertiesDialog("cell"),merge:()=>r(e=>n.mergeSelectedTable(e),kf),split:()=>r(e=>n.splitSelectedTable(e),Tf),insertColumnBefore:()=>r(e=>n.insertSelectedTableColumn(e,-1),Pf),insertColumnAfter:()=>r(e=>n.insertSelectedTableColumn(e,1),Pf),deleteColumn:()=>r(e=>n.deleteSelectedTableColumn(e),Rf),insertRowBefore:()=>r(e=>n.insertSelectedTableRow(e,-1),Af),insertRowAfter:()=>r(e=>n.insertSelectedTableRow(e,1),Af),deleteRow:()=>r(e=>n.deleteSelectedTableRow(e),Mf)}}function Mm(e){return function(e){const{computeFontFamilyOptions:t,computeFontSizeOptions:n,loadLocalFontFamilyOptions:r}=Yp({state:e.state,toolbarStyleState:e.toolbarStyleState}),o=function(e){return{openFontDialog:()=>{var t;e.loadLocalFontFamilyOptions(),e.setFontDialog({isOpen:!0,initial:(t=e.toolbarStyleState(),{fontFamily:t.fontFamily??"",fontSize:ct(t.fontSize),color:t.color??"",colorMode:t.color?"custom":"automatic",highlight:t.highlight??"",shading:t.textShading??"",bold:Boolean(t.bold),italic:Boolean(t.italic),underline:Boolean(t.underline),underlineStyle:t.underlineStyle?t.underlineStyle:null,underlineColor:t.underlineColor??"",strike:Boolean(t.strike),doubleStrike:Boolean(t.doubleStrike),superscript:Boolean(t.superscript),subscript:Boolean(t.subscript),smallCaps:Boolean(t.smallCaps),allCaps:Boolean(t.allCaps),hidden:Boolean(t.hidden),characterScale:t.characterScale??"",characterSpacing:t.characterSpacing??"",baselineShift:t.baselineShift??"",kerningThreshold:t.kerningThreshold??"",ligatures:t.ligatures??"",numberSpacing:t.numberSpacing??"",numberForm:t.numberForm??"",stylisticSet:t.stylisticSet??"",contextualAlternates:Boolean(t.contextualAlternates)})}),e.setContextMenu({isOpen:!1,x:0,y:0})},applyFontDialogValues:(t,n)=>{e.isReadOnly()||(ga(e.selection())||(e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(e=>{let r=e;t.fontFamily!==(n.fontFamily||null)&&(r=up(r,"fontFamily",t.fontFamily)),t.fontSize!==(n.fontSize?Number(n.fontSize):null)&&(r=up(r,"fontSize",Qn(t.fontSize)));const o="automatic"===n.colorMode?null:n.color||null;t.color!==o&&(r=up(r,"color",t.color)),(t.highlight??"")!==(n.highlight??"")&&(r=up(r,"highlight",t.highlight)),(t.shading??"")!==(n.shading??"")&&(r=up(r,"shading",t.shading)),t.bold!==Boolean(n.bold)&&(r=lp(r,"bold")),t.italic!==Boolean(n.italic)&&(r=lp(r,"italic"));const a=n.underline?n.underlineStyle??"single":null;(t.underlineStyle??null)!==(a??null)&&(r=up(r,"underlineStyle",t.underlineStyle));const i=n.underline&&n.underlineColor||null;(t.underlineColor??null)!==(i??null)&&(r=up(r,"underlineColor",t.underlineColor)),t.underline!==Boolean(n.underline)&&(r=lp(r,"underline")),t.strike!==Boolean(n.strike)&&(r=lp(r,"strike")),t.doubleStrike!==Boolean(n.doubleStrike)&&(r=lp(r,"doubleStrike")),t.superscript!==Boolean(n.superscript)&&(r=lp(r,"superscript")),t.subscript!==Boolean(n.subscript)&&(r=lp(r,"subscript")),t.superscript&&t.subscript&&(r=lp(r,"subscript")),t.strike&&t.doubleStrike&&(r=lp(r,"doubleStrike")),t.smallCaps!==Boolean(n.smallCaps)&&(r=lp(r,"smallCaps")),t.allCaps!==Boolean(n.allCaps)&&(r=lp(r,"allCaps")),t.hidden!==Boolean(n.hidden)&&(r=lp(r,"hidden"));const s=n.characterScale?Number(n.characterScale):null;(t.characterScale??null)!==(s??null)&&(r=up(r,"characterScale",t.characterScale));const l=n.characterSpacing?Number(n.characterSpacing):null;(t.characterSpacing??null)!==(l??null)&&(r=up(r,"characterSpacing",t.characterSpacing));const c=n.baselineShift?Number(n.baselineShift):null;(t.baselineShift??null)!==(c??null)&&(r=up(r,"baselineShift",t.baselineShift));const d=n.kerningThreshold?Number(n.kerningThreshold):null;(t.kerningThreshold??null)!==(d??null)&&(r=up(r,"kerningThreshold",t.kerningThreshold)),(t.ligatures??null)!==(n.ligatures||null)&&(r=up(r,"ligatures",t.ligatures)),(t.numberSpacing??null)!==(n.numberSpacing||null)&&(r=up(r,"numberSpacing",t.numberSpacing)),(t.numberForm??null)!==(n.numberForm||null)&&(r=up(r,"numberForm",t.numberForm));const u=n.stylisticSet?Number(n.stylisticSet):null;return(t.stylisticSet??null)!==(u??null)&&(r=up(r,"stylisticSet",t.stylisticSet)),t.contextualAlternates!==Boolean(n.contextualAlternates)&&(r=lp(r,"contextualAlternates")),r},{mergeKey:If})),e.focusInput())}}}({toolbarStyleState:e.toolbarStyleState,selection:e.selection,isReadOnly:e.isReadOnly,loadLocalFontFamilyOptions:r,setFontDialog:e.setFontDialog,setContextMenu:e.setContextMenu,clearPreferredColumn:e.clearPreferredColumn,resetTransactionGrouping:e.resetTransactionGrouping,applyTransactionalState:e.applyTransactionalState,focusInput:e.focusInput}),a=o.openFontDialog,i=function(e){return{openParagraphDialog:()=>{var t;e.setParagraphDialog({isOpen:!0,initial:(t=e.toolbarStyleState(),{align:t.align??"",indentLeft:t.indentLeft??"",indentRight:t.indentRight??"",indentFirstLine:t.indentFirstLine??"",indentHanging:t.indentHanging??"",mirrorIndents:t.mirrorIndents??!1,spacingBefore:t.spacingBefore??"",spacingAfter:t.spacingAfter??"",lineHeight:t.lineHeight??"",lineRule:t.lineRule??"",contextualSpacing:t.contextualSpacing??!1,outlineLevel:t.outlineLevel??"",shading:t.shading??"",borderStyle:t.borderStyle??"",borderWidth:t.borderWidth??"",borderColor:t.borderColor??"",borderSideTop:t.borderSideTop??!1,borderSideRight:t.borderSideRight??!1,borderSideBottom:t.borderSideBottom??!1,borderSideLeft:t.borderSideLeft??!1,pageBreakBefore:t.pageBreakBefore??!1,keepWithNext:t.keepWithNext??!1,keepLinesTogether:t.keepLinesTogether??!1,widowControl:t.widowControl??!0,tabs:t.tabs??[]})}),e.setContextMenu({isOpen:!1,x:0,y:0})},applyParagraphDialogValues:(t,n)=>{if(e.isReadOnly())return;if(e.clearPreferredColumn(),e.resetTransactionGrouping(),n.tabsOnly)return e.applyTransactionalState(e=>(t.tabChanges??[]).reduce(Yt,e)),void e.focusInput();const r=e=>{if(""===e.trim())return null;const t=Number(e);return Number.isFinite(t)?t:null};e.applyTransactionalState(e=>{let o=e;t.align!==(n.align||null)&&(o=le(o,"align",t.align)),t.indentLeft!==r(n.indentLeft)&&(o=le(o,"indentLeft",t.indentLeft)),t.indentRight!==r(n.indentRight)&&(o=le(o,"indentRight",t.indentRight)),t.indentFirstLine!==r(n.indentFirstLine)&&(o=le(o,"indentFirstLine",t.indentFirstLine)),t.indentHanging!==r(n.indentHanging)&&(o=le(o,"indentHanging",t.indentHanging)),t.spacingBefore!==r(n.spacingBefore)&&(o=le(o,"spacingBefore",t.spacingBefore)),t.spacingAfter!==r(n.spacingAfter)&&(o=le(o,"spacingAfter",t.spacingAfter)),t.lineHeight!==r(n.lineHeight)&&(o=le(o,"lineHeight",t.lineHeight));const a=n.lineRule||null;t.lineRule!==a&&(o=le(o,"lineRule",t.lineRule)),t.shading!==(n.shading||null)&&(o=le(o,"shading",t.shading)),t.mirrorIndents!==(n.mirrorIndents??!1)&&(o=le(o,"mirrorIndents",t.mirrorIndents)),t.contextualSpacing!==(n.contextualSpacing??!1)&&(o=le(o,"contextualSpacing",t.contextualSpacing));const i=""===n.outlineLevel.trim()?null:Number(n.outlineLevel);t.outlineLevel!==i&&(o=le(o,"outlineLevel",t.outlineLevel)),t.pageBreakBefore!==(n.pageBreakBefore??!1)&&(o=le(o,"pageBreakBefore",t.pageBreakBefore)),t.keepWithNext!==(n.keepWithNext??!1)&&(o=le(o,"keepWithNext",t.keepWithNext)),t.keepLinesTogether!==(n.keepLinesTogether??!1)&&(o=le(o,"keepLinesTogether",t.keepLinesTogether)),t.widowControl!==(n.widowControl??!0)&&(o=le(o,"widowControl",t.widowControl)),t.tabChanges?.length?o=t.tabChanges.reduce(Yt,o):JSON.stringify(t.tabs)!==JSON.stringify(n.tabs??[])&&(o=le(o,"tabs",t.tabs.length>0?t.tabs:null));const s="solid"===n.borderStyle||"dashed"===n.borderStyle||"dotted"===n.borderStyle?{type:n.borderStyle,width:Number(n.borderWidth)||0,color:n.borderColor||"#000000"}:null,l={borderTop:n.borderSideTop?s:null,borderRight:n.borderSideRight?s:null,borderBottom:n.borderSideBottom?s:null,borderLeft:n.borderSideLeft?s:null},c={borderTop:t.borders.top,borderRight:t.borders.right,borderBottom:t.borders.bottom,borderLeft:t.borders.left};for(const t of["borderTop","borderRight","borderBottom","borderLeft"])JSON.stringify(c[t])!==JSON.stringify(l[t])&&(o=le(o,t,c[t]));return o},{mergeKey:wf}),e.focusInput()},setParagraphDialogDefault:t=>{e.isReadOnly()||(e.resetTransactionGrouping(),e.applyTransactionalState(e=>{const n=e.document.styles,r=bi(n);if(!r||!n?.[r])return e;const o=n[r];return{...e,document:{...e.document,styles:{...n,[r]:{...o,paragraphStyle:wg(o.paragraphStyle??{},t)}}}}}),e.focusInput())}}}({toolbarStyleState:e.toolbarStyleState,isReadOnly:e.isReadOnly,setParagraphDialog:e.setParagraphDialog,setContextMenu:e.setContextMenu,clearPreferredColumn:e.clearPreferredColumn,resetTransactionGrouping:e.resetTransactionGrouping,applyTransactionalState:e.applyTransactionalState,focusInput:e.focusInput}),s=i.openParagraphDialog,l=Pm({state:e.state,isReadOnly:e.isReadOnly,setTablePropertiesDialog:e.setTablePropertiesDialog,setContextMenu:e.setContextMenu,clearPreferredColumn:e.clearPreferredColumn,resetTransactionGrouping:e.resetTransactionGrouping,applyTransactionalState:e.applyTransactionalState,focusInput:e.focusInput}),c=l.openTablePropertiesDialog,d=(t,n)=>{e.applyTransactionalState(t,{mergeKey:n}),e.focusInput()},u=Rm({clipboardActions:e.clipboardActions,state:e.state,isReadOnly:e.isReadOnly,t:e.t,logger:e.logger,setContextMenu:e.setContextMenu,clearPreferredColumn:e.clearPreferredColumn,resetTransactionGrouping:e.resetTransactionGrouping,applyTransactionalState:e.applyTransactionalState,applyTableAwareParagraphEdit:e.applyTableAwareParagraphEdit,focusInput:e.focusInput,promptForLink:e.promptForLink,openFontDialog:a,openParagraphDialog:s,table:Am({state:e.state,tableOps:e.tableOps,isInsideTable:l.isInsideTable,openTablePropertiesDialog:c,applyTableContextCommand:d})});return{computeFontFamilyOptions:t,computeFontSizeOptions:n,applyFontDialogValues:o.applyFontDialogValues,applyParagraphDialogValues:i.applyParagraphDialogValues,setParagraphDialogDefault:i.setParagraphDialogDefault,applyTablePropertiesDialogValues:l.applyTablePropertiesDialogValues,buildContextMenuItems:u.buildContextMenuItems,handleEditorContextMenu:u.handleEditorContextMenu,closeContextMenu:u.closeContextMenu}}(e)}function Om(e){const t=ur(()=>{const t=e.targetPos(),n=e.surfaceRef;if(!n)return null;const r=e.snapshotProvider.getCanvasLayoutSnapshot({surface:n,state:e.state,documentLayout:e.documentLayout(),zoomFactor:e.zoomFactor?.()});let o=0,a=0,i=28;if(r){const n=ko(e.state).find(e=>e.id===t.paragraphId),o=n?wa(n,t):0,a=Ye(r,t,o);if(a)return{viewportLeft:a.left,viewportTop:a.top,height:Math.min(a.height||28,32)};const i=tt(r,t.paragraphId,"end");if(i)return{viewportLeft:i.left,viewportTop:i.top,height:i.height||28}}const s=e.caretViewport?.()??null;if(s)return o=s.left,a=s.top,i=Math.max(12,Math.min(36,s.height)),{viewportLeft:o,viewportTop:a,height:i};const l=e.pointerPos?.()??null;return l?(o=l.x,a=l.y-12,i=24,{viewportLeft:o,viewportTop:a,height:i}):{viewportLeft:o,viewportTop:a,height:i}});return wt(Bn,{get when(){return t()},children:e=>wt(pr,{active:!0,fixed:!0,get left(){return e().viewportLeft},get top(){return e().viewportTop},get height(){return e().height}})})}var Bm=/*#__PURE__*/qn("<div class=oasis-editor-table-resize-guide>"),Fm=/*#__PURE__*/qn("<div class=oasis-editor-table-resize-outline>"),Em=/*#__PURE__*/qn("<img class=oasis-editor-image-ghost>"),Dm=/*#__PURE__*/qn("<div class=oasis-editor-table-ghost>");function Lm(e){return[wt(Bn,{get when(){return e.tableResize.resizing()},children:e=>{return t=Bm(),Pt(n=>{var r=!("column"!==e().type),o=!("row"!==e().type),a={..."column"===e().type?{left:`${e().currentPos}px`,top:`${e().guideBounds.top}px`,width:"0px",height:`${e().guideBounds.height}px`}:{left:`${e().guideBounds.left}px`,top:`${e().currentPos}px`,width:`${e().guideBounds.width}px`,height:"0px"}};return r!==n.e&&t.classList.toggle("oasis-editor-table-resize-guide-column",n.e=r),o!==n.t&&t.classList.toggle("oasis-editor-table-resize-guide-row",n.t=o),n.a=Tn(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t;var t}}),wt(Bn,{get when(){return e.tableCornerResize.previewRect()},children:e=>{return t=Fm(),Pt(n=>{var r=`${e().left}px`,o=`${e().top}px`,a=`${e().width}px`,i=`${e().height}px`;return r!==n.e&&Ot(t,"left",n.e=r),o!==n.t&&Ot(t,"top",n.t=o),a!==n.a&&Ot(t,"width",n.a=a),i!==n.o&&Ot(t,"height",n.o=i),n},{e:void 0,t:void 0,a:void 0,o:void 0}),t;var t}}),wt(Bn,{get when(){return Qe(()=>!!e.imageOps.dragging())()&&e.imageOps.draggedImageInfo()},children:t=>{return r=Em(),Pt(o=>{var a=t().src,i=`${t().width}px`,s=`${t().height}px`,l=e.imageOps.mousePos().x-t().offsetX+"px",c=e.imageOps.mousePos().y-t().offsetY+"px";return a!==o.e&&n(r,"src",o.e=a),i!==o.t&&Ot(r,"width",o.t=i),s!==o.a&&Ot(r,"height",o.a=s),l!==o.o&&Ot(r,"left",o.o=l),c!==o.i&&Ot(r,"top",o.i=c),o},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),r;var r}}),wt(Bn,{get when(){return Qe(()=>!!e.tableDrag.dragging())()&&e.tableDrag.draggedTableInfo()},children:t=>{return n=Dm(),Pt(r=>{var o=`${t().width}px`,a=`${t().height}px`,i=e.tableDrag.mousePos().x-t().offsetX+"px",s=e.tableDrag.mousePos().y-t().offsetY+"px";return o!==r.e&&Ot(n,"width",r.e=o),a!==r.t&&Ot(n,"height",r.t=a),i!==r.a&&Ot(n,"left",r.a=i),s!==r.o&&Ot(n,"top",r.o=s),r},{e:void 0,t:void 0,a:void 0,o:void 0}),n;var n}}),wt(Bn,{get when(){return Qe(()=>!!e.tableDrag.dragging())()&&e.tableDrag.dropTargetPos()},children:t=>wt(Om,{get surfaceRef(){return e.surfaceRef},get state(){return e.state},get documentLayout(){return e.documentLayout},get snapshotProvider(){return e.snapshotProvider},get zoomFactor(){return e.zoomFactor},targetPos:t})}),wt(Bn,{get when(){return Qe(()=>!!e.imageOps.dragging())()&&e.imageOps.dropTargetPos()},children:t=>wt(Om,{get surfaceRef(){return e.surfaceRef},get state(){return e.state},get documentLayout(){return e.documentLayout},get snapshotProvider(){return e.snapshotProvider},get zoomFactor(){return e.zoomFactor},targetPos:t})}),wt(Bn,{get when(){return Qe(()=>!!e.textDrag.dragging())()&&e.textDrag.dropTargetPos()},children:t=>wt(Om,{get surfaceRef(){return e.surfaceRef},get state(){return e.state},get documentLayout(){return e.documentLayout},get snapshotProvider(){return e.snapshotProvider},get zoomFactor(){return e.zoomFactor},targetPos:t,get pointerPos(){return e.textDrag.pointerPos},get caretViewport(){return e.textDrag.caretViewport}})})]}function Nm(e){return[wt(bn,{variant:"secondary",get onClick(){return e.onCancel},get"data-testid"(){return e.cancelTestId},get children(){return e.cancelLabel}}),wt(bn,{variant:"primary",get onClick(){return e.onConfirm},get"data-testid"(){return e.confirmTestId},get children(){return e.confirmLabel}})]}function zm(e){const t=D(),[n,r]=Nt(e.initialValue);let o;mn(()=>{e.isOpen&&(r(e.initialValue),setTimeout(()=>o?.focus(),50))});const a=()=>{e.onConfirm(n()),e.onClose()};return wt(F,{get isOpen(){return e.isOpen},get title(){return e.title},get onClose(){return e.onClose},get footer(){return wt(Nm,{get onCancel(){return e.onClose},onConfirm:a,get cancelLabel(){return t("generic.cancel")},get confirmLabel(){return e.confirmLabel},get cancelTestId(){return e.testIds?.cancel},get confirmTestId(){return e.testIds?.confirm}})},get children(){return wt(pe,{ref(e){"function"==typeof o?o(e):o=e},get label(){return e.label},get value(){return n()},onChange:r,onKeyDown:e=>"Enter"===e.key&&a(),get placeholder(){return e.placeholder},get"data-testid"(){return e.testIds?.input}})}})}function $m(e){const t=D();return wt(zm,{get isOpen(){return e.isOpen},get title(){return t("dialog.link.title")},get label(){return t("dialog.link.label")},get placeholder(){return t("dialog.link.placeholder")},get initialValue(){return e.initialHref},get confirmLabel(){return t("generic.apply")},get onClose(){return e.onClose},get onConfirm(){return e.onConfirm},testIds:{input:"editor-link-dialog-input",cancel:"editor-link-dialog-cancel",confirm:"editor-link-dialog-apply"}})}function Hm(e){const t=D();return wt(zm,{get isOpen(){return e.isOpen},get title(){return t("dialog.imageAlt.title")},get label(){return t("dialog.imageAlt.label")},get placeholder(){return t("dialog.imageAlt.placeholder")},get initialValue(){return e.initialAlt},get confirmLabel(){return t("generic.save")},get onClose(){return e.onClose},get onConfirm(){return e.onConfirm}})}function Wm(e){const t=D();return wt(zm,{get isOpen(){return e.isOpen},get title(){return t("dialog.imageCaption.title")},get label(){return t("dialog.imageCaption.label")},get placeholder(){return t("dialog.imageCaption.placeholder")},get initialValue(){return e.initialCaption},get confirmLabel(){return t("generic.save")},get onClose(){return e.onClose},get onConfirm(){return e.onConfirm}})}var jm=/*#__PURE__*/qn("<div class=oasis-editor-comment-composer-parent data-testid=comment-reply-context>"),Um=/*#__PURE__*/qn("<div class=oasis-editor-comment-composer>");function Vm(e){const t=D(),[n,r]=Nt(""),[o,a]=Nt("");let i;const s=e.composer.draft,l=()=>("edit"===s()?.mode||n().trim().length>0)&&o().trim().length>0,c=()=>{l()&&e.composer.submit(n(),o())};return mn(()=>{s()&&(r("edit"===s()?.mode?s()?.commentAuthor??"":e.composer.authorName()),a("edit"===s()?.mode?s()?.commentText??"":""),queueMicrotask(()=>i?.focus()))}),wt(F,{get isOpen(){return null!==s()},get title(){return t("edit"===s()?.mode?"toolbar.editComment":"reply"===s()?.mode?"toolbar.replyComment":"toolbar.newComment")},get onClose(){return e.composer.close},get footer(){return[wt(bn,{get onClick(){return e.composer.close},"data-testid":"comment-composer-cancel",get children(){return t("generic.cancel")}}),wt(bn,{variant:"primary",get disabled(){return!l()},onClick:c,"data-testid":"comment-composer-submit",get children(){return t("generic.save")}})]},get children(){var l=Um();return Ue(l,wt(Bn,{get when(){return"reply"===s()?.mode},get children(){var e=jm();return Ue(e,wt(Pn,{as:"strong",get children(){return[Qe(()=>t("comment.replyTo"))," ",Qe(()=>s()?.parentAuthor)]}}),null),Ue(e,wt(Pn,{as:"p",get children(){return s()?.parentText}}),null),e}}),null),Ue(l,wt(pe,{get label(){return t("comment.author")},get value(){return n()},onChange:r,maxLength:150,required:!0,get disabled(){return"edit"===s()?.mode||e.composer.authorLocked()},"data-testid":"comment-composer-author"}),null),Ue(l,wt(C,{ref(e){"function"==typeof i?i(e):i=e},get label(){return t("comment.body")},controlClass:"oasis-editor-comment-composer-textarea",get value(){return o()},onChange:a,onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&(e.preventDefault(),c())},rows:5,maxLength:2e4,get placeholder(){return t("comment.placeholder")},"data-testid":"comment-composer-body"}),null),l}})}var Km=[8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72],_m=[33,50,66,75,90,100,105,110,115,120,150,200];function Xm(e){const t=Number(e.trim());return Number.isFinite(t)&&t>0?t:null}function qm(e){const t=Number(e.trim());return Number.isFinite(t)&&t>=0?t:null}function Gm(e){return null==e||""===e?"":String(e)}function Ym(e){const t=Number(e);return Number.isFinite(t)&&0!==t?t>0?"expanded":"condensed":"normal"}function Zm(e){const t=Number(e);return Number.isFinite(t)&&0!==t?t>0?"raised":"lowered":"normal"}function Jm(e){if(!e.trim())return null;const t=Number(e);return Number.isInteger(t)&&t>=1&&t<=20?t:null}function Qm(e){switch(e){case"none":return"none";case"standard":return"common-ligatures";case"contextual":return"contextual";case"historical":return"historical-ligatures";case"standardContextual":return"common-ligatures contextual";default:return}}function eh(e,t){const n=[];return"proportional"===e&&n.push("proportional-nums"),"tabular"===e&&n.push("tabular-nums"),"lining"===t&&n.push("lining-nums"),"oldStyle"===t&&n.push("oldstyle-nums"),n.join(" ")||void 0}function th(e,t){const n=[],r=Jm(e);return null!==r&&n.push(`"ss${String(r).padStart(2,"0")}" 1`),t&&n.push('"calt" 1'),n.join(", ")||void 0}function nh(e){return{familyFilter:"",fontFamily:e.fontFamily??"",fontSize:e.fontSize??"",colorMode:e.colorMode,color:e.color||"#111827",highlight:e.highlight||"",shading:e.shading||"",bold:Boolean(e.bold),italic:Boolean(e.italic),underline:Boolean(e.underline),underlineStyle:e.underline?e.underlineStyle??"single":"none",underlineColor:e.underlineColor||"#111827",strike:Boolean(e.strike),doubleStrike:Boolean(e.doubleStrike),superscript:Boolean(e.superscript),subscript:Boolean(e.subscript),smallCaps:Boolean(e.smallCaps),allCaps:Boolean(e.allCaps),hidden:Boolean(e.hidden)}}function rh(e){return{characterScale:Gm(e.characterScale),spacingMode:Ym(e.characterSpacing),spacingAmount:e.characterSpacing?String(Math.abs(Number(e.characterSpacing))):"",positionMode:Zm(e.baselineShift),positionAmount:e.baselineShift?String(Math.abs(Number(e.baselineShift))):"",kerningEnabled:""!==e.kerningThreshold,kerningThreshold:Gm(e.kerningThreshold),ligatures:e.ligatures,numberSpacing:e.numberSpacing,numberForm:e.numberForm,stylisticSet:Gm(e.stylisticSet),contextualAlternates:Boolean(e.contextualAlternates)}}function oh(e){const t=D(),[n,r]=Nt("font"),[o,a]=Nt(nh(e.initial)),[i,s]=Nt(rh(e.initial));mn(()=>{e.isOpen&&(r("font"),a(nh(e.initial)),s(rh(e.initial)))});const l=ur(()=>{return e=o().bold,t=o().italic,e&&t?"boldItalic":e?"bold":t?"italic":"regular";var e,t}),c=ur(()=>{const t=o().familyFilter.trim().toLowerCase();return t?e.familyOptions.filter(e=>e.toLowerCase().includes(t)):e.familyOptions}),d=ur(()=>{const t=new Set(Km);for(const r of e.sizeOptions)t.add(r);const n=Number(o().fontSize);return Number.isFinite(n)&&n>0&&t.add(n),Array.from(t).sort((e,t)=>e-t)}),u=ur(()=>{const e=o().fontSize.trim();if(!e)return"";const n=Number(e);return Number.isFinite(n)&&n>0?"":t("dialog.font.sizeInvalid")}),p=ur(()=>{const e=i();return e.characterScale.trim()&&null===Xm(e.characterScale)?t("dialog.font.advancedScaleInvalid"):"normal"!==e.spacingMode&&null===qm(e.spacingAmount)||"normal"!==e.positionMode&&null===qm(e.positionAmount)?t("dialog.font.advancedAmountInvalid"):e.kerningThreshold.trim()&&null===qm(e.kerningThreshold)?t("dialog.font.advancedKerningInvalid"):e.stylisticSet.trim()&&null===Jm(e.stylisticSet)?t("dialog.font.advancedStylisticSetInvalid"):""}),f=ur(()=>function(e,t){const n=Number(e.fontSize),r=Xm(t.characterScale)??100,o="normal"===t.spacingMode?null:qm(t.spacingAmount),a="normal"===t.positionMode?null:qm(t.positionAmount),i=null===o?void 0:"condensed"===t.spacingMode?`-${o}pt`:`${o}pt`,s=null===a?void 0:"lowered"===t.positionMode?`-${a}pt`:`${a}pt`,l=[];return e.underline&&"none"!==e.underlineStyle&&l.push("underline"),e.strike&&l.push("line-through"),e.doubleStrike&&l.push("line-through"),{"font-family":e.fontFamily||"inherit","font-size":Number.isFinite(n)&&n>0?`${n}pt`:void 0,"font-weight":e.bold?700:400,"font-style":e.italic?"italic":"normal","text-decoration":l.join(" ")||"none",color:"automatic"===e.colorMode?"inherit":e.color,"background-color":e.highlight||e.shading||void 0,"vertical-align":s??(e.superscript?"super":e.subscript?"sub":"baseline"),"font-stretch":`${r}%`,"letter-spacing":i,"font-variant-ligatures":Qm(t.ligatures),"font-variant-numeric":eh(t.numberSpacing,t.numberForm),"font-feature-settings":th(t.stylisticSet,t.contextualAlternates)}}(o(),i()));return{activeTab:n,setActiveTab:e=>r(e),fontTabValues:o,setFontTabValues:a,advancedTabValues:i,setAdvancedTabValues:s,updateFontTab:(e,t)=>{a(n=>({...n,[e]:t}))},updateAdvancedTab:(e,t)=>{s(n=>({...n,[e]:t}))},selectedFontStyle:l,visibleFamilyOptions:c,effectiveSizeOptions:d,customSizeError:u,advancedValidationError:p,previewStyle:f,applyFontStylePreset:e=>{a(t=>({...t,bold:"bold"===e||"boldItalic"===e,italic:"italic"===e||"boldItalic"===e}))},handleApply:()=>{if(p())return;const t=function(e,t){const n=Number(e.fontSize),r=Number.isFinite(n)&&n>0,o="none"===e.underlineStyle?null:e.underlineStyle,a=null!==o,i=t.characterScale.trim()?Xm(t.characterScale):null,s="normal"===t.spacingMode?null:qm(t.spacingAmount),l="normal"===t.positionMode?null:qm(t.positionAmount),c=t.kerningEnabled&&t.kerningThreshold.trim()?qm(t.kerningThreshold):null,d=Jm(t.stylisticSet);return{fontFamily:e.fontFamily.trim()?e.fontFamily.trim():null,fontSize:r?n:null,colorMode:e.colorMode,color:"automatic"===e.colorMode?null:e.color||null,highlight:e.highlight||null,shading:e.shading||null,bold:e.bold,italic:e.italic,underline:a,underlineStyle:o,underlineColor:a&&e.underlineColor||null,strike:e.strike,doubleStrike:e.doubleStrike,superscript:e.superscript,subscript:e.subscript,smallCaps:e.smallCaps,allCaps:e.allCaps,hidden:e.hidden,characterScale:i,characterSpacing:null===s?null:"condensed"===t.spacingMode?-s:s,baselineShift:null===l?null:"lowered"===t.positionMode?-l:l,kerningThreshold:c,ligatures:t.ligatures||null,numberSpacing:t.numberSpacing||null,numberForm:t.numberForm||null,stylisticSet:d,contextualAlternates:t.contextualAlternates}}(o(),i());e.onApply(t,e.initial),e.onClose()}}}var ah=/*#__PURE__*/qn("<div>");function ih(e){const t=D();return r=ah(),Ue(r,()=>t("dialog.font.previewText")),Pt(t=>{var o=e.class??"oasis-editor-dialog-preview",a=e.testId,i=e.style;return o!==t.e&&V(r,t.e=o),a!==t.t&&n(r,"data-testid",t.t=a),t.a=Tn(r,i,t.a),t},{e:void 0,t:void 0,a:void 0}),r;var r}var sh=/*#__PURE__*/qn('<div class="oasis-editor-font-dialog-panel oasis-editor-font-dialog-font-panel">');function lh(e){const t=D(),{ctrl:n}=e;return r=sh(),Ue(r,wt(d,{container:!0,spacing:1.5,get children(){return[wt(d,{size:12,get children(){return wt(pe,{get label(){return t("dialog.font.familyFilter")},get value(){return n.fontTabValues().familyFilter},onChange:e=>n.updateFontTab("familyFilter",e),"data-testid":"editor-font-dialog-family-filter"})}}),wt(d,{size:{xs:12,md:8},get children(){return wt(Cr,{get label(){return t("dialog.font.family")},get value(){return n.fontTabValues().fontFamily},onChange:e=>n.updateFontTab("fontFamily",e),"data-testid":"editor-font-dialog-family",get options(){return[{value:"",label:"—"},...n.visibleFamilyOptions().map(e=>({value:e,label:e}))]}})}}),wt(d,{size:{xs:12,md:4},get children(){return wt(Cr,{get label(){return t("dialog.font.size")},get value(){return n.fontTabValues().fontSize},onChange:e=>n.updateFontTab("fontSize",e),"data-testid":"editor-font-dialog-size",get options(){return[{value:"",label:"—"},...n.effectiveSizeOptions().map(e=>({value:String(e),label:String(e)}))]}})}}),wt(d,{size:{xs:12,md:4},get children(){return[wt(pe,{get label(){return t("dialog.font.customSize")},get value(){return n.fontTabValues().fontSize},onChange:e=>n.updateFontTab("fontSize",e),"data-testid":"editor-font-dialog-custom-size"}),wt(oe,{class:"oasis-editor-dialog-help-text",get children(){return n.customSizeError()}})]}}),wt(d,{size:{xs:12,md:8},get children(){return wt(Cr,{get label(){return t("dialog.font.styleList")},get value(){return n.selectedFontStyle()},onChange:e=>n.applyFontStylePreset(e),"data-testid":"editor-font-dialog-style-list",get options(){return[{value:"regular",label:t("dialog.font.styleRegular")},{value:"italic",label:t("dialog.font.styleItalic")},{value:"bold",label:t("dialog.font.styleBold")},{value:"boldItalic",label:t("dialog.font.styleBoldItalic")}]}})}})]}}),null),Ue(r,wt(d,{container:!0,spacing:1.5,class:"oasis-editor-font-dialog-color-row",get children(){return[wt(d,{size:{xs:12,md:4},get children(){return wt(Cr,{get label(){return t("dialog.font.color")},get value(){return n.fontTabValues().colorMode},onChange:e=>n.updateFontTab("colorMode",e),"data-testid":"editor-font-dialog-color-mode",get options(){return[{value:"automatic",label:t("toolbar.colorAutomatic")},{value:"custom",label:t("dialog.font.customColor")}]}})}}),wt(d,{size:{xs:12,md:4},get children(){return wt(A,{get label(){return t("dialog.font.color")},get value(){return n.fontTabValues().color},get disabled(){return"automatic"===n.fontTabValues().colorMode},onChange:e=>n.setFontTabValues(t=>({...t,color:e,colorMode:"custom"})),"data-testid":"editor-font-dialog-color"})}}),wt(d,{size:{xs:12,md:2},get children(){return wt(A,{get label(){return t("dialog.font.highlight")},get value(){return n.fontTabValues().highlight||"#fef08a"},onChange:e=>n.updateFontTab("highlight",e),"data-testid":"editor-font-dialog-highlight"})}}),wt(d,{size:{xs:12,md:2},get children(){return wt(A,{get label(){return t("dialog.font.shading")},get value(){return n.fontTabValues().shading||"#fef3c7"},onChange:e=>n.updateFontTab("shading",e),"data-testid":"editor-font-dialog-shading"})}})]}}),null),Ue(r,wt(d,{container:!0,spacing:1.5,get children(){return[wt(d,{size:{xs:12,md:8},get children(){return wt(Cr,{get label(){return t("dialog.font.underlineStyle")},get value(){return n.fontTabValues().underlineStyle},onChange:e=>n.setFontTabValues(t=>({...t,underlineStyle:e,underline:"none"!==e})),"data-testid":"editor-font-dialog-underline-style",get options(){return[{value:"none",label:t("toolbar.underlineRemove")},...gr.map(e=>({value:e.value,label:t(e.labelKey)}))]}})}}),wt(d,{size:{xs:12,md:4},get children(){return wt(A,{get label(){return t("dialog.font.underlineColor")},get value(){return n.fontTabValues().underlineColor||"#111827"},get disabled(){return"none"===n.fontTabValues().underlineStyle},onChange:e=>n.setFontTabValues(t=>({...t,underlineColor:e,underline:"none"!==t.underlineStyle})),"data-testid":"editor-font-dialog-underline-color"})}})]}}),null),Ue(r,wt(fn,{class:"oasis-editor-dialog-input-group-grow",get label(){return t("dialog.font.style")},get children(){return wt(ln,{class:"oasis-editor-dialog-style-row",direction:"row",spacing:1,get children(){return wt(dt,{get each(){return[{testId:"editor-font-dialog-bold",label:t("dialog.font.bold"),labelStyle:{"font-weight":700},checked:()=>n.fontTabValues().bold,onChange:e=>n.updateFontTab("bold",e)},{testId:"editor-font-dialog-italic",label:t("dialog.font.italic"),labelStyle:{"font-style":"italic"},checked:()=>n.fontTabValues().italic,onChange:e=>n.updateFontTab("italic",e)},{testId:"editor-font-dialog-underline",label:t("dialog.font.underline"),labelStyle:{"text-decoration":"underline"},checked:()=>n.fontTabValues().underline,onChange:e=>n.setFontTabValues(t=>({...t,underline:e,underlineStyle:e?"none"===t.underlineStyle?"single":t.underlineStyle:"none"}))},{testId:"editor-font-dialog-strike",label:t("dialog.font.strike"),labelStyle:{"text-decoration":"line-through"},checked:()=>n.fontTabValues().strike,onChange:e=>n.setFontTabValues(t=>({...t,strike:e,doubleStrike:!e&&t.doubleStrike}))},{testId:"editor-font-dialog-double-strike",label:t("dialog.font.doubleStrike"),checked:()=>n.fontTabValues().doubleStrike,onChange:e=>n.setFontTabValues(t=>({...t,doubleStrike:e,strike:!e&&t.strike}))},{testId:"editor-font-dialog-superscript",label:t("toolbar.superscript"),checked:()=>n.fontTabValues().superscript,onChange:e=>n.setFontTabValues(t=>({...t,superscript:e,subscript:!e&&t.subscript}))},{testId:"editor-font-dialog-subscript",label:t("toolbar.subscript"),checked:()=>n.fontTabValues().subscript,onChange:e=>n.setFontTabValues(t=>({...t,subscript:e,superscript:!e&&t.superscript}))},{testId:"editor-font-dialog-small-caps",label:t("dialog.font.smallCaps"),checked:()=>n.fontTabValues().smallCaps,onChange:e=>n.updateFontTab("smallCaps",e)},{testId:"editor-font-dialog-all-caps",label:t("dialog.font.allCaps"),checked:()=>n.fontTabValues().allCaps,onChange:e=>n.updateFontTab("allCaps",e)},{testId:"editor-font-dialog-hidden",label:t("dialog.font.hidden"),checked:()=>n.fontTabValues().hidden,onChange:e=>n.updateFontTab("hidden",e)}]},children:e=>wt(Er,{get label(){return e.label},get labelStyle(){return e.labelStyle},get checked(){return e.checked()},get onChange(){return e.onChange},get"data-testid"(){return e.testId}})})}})}}),null),Ue(r,wt(fn,{get label(){return t("dialog.font.preview")},get children(){return wt(ih,{testId:"editor-font-dialog-preview",get style(){return n.previewStyle()}})}}),null),r;var r}var ch=/*#__PURE__*/qn("<div class=oasis-editor-font-dialog-kerning-line>"),dh=/*#__PURE__*/qn('<div class="oasis-editor-font-dialog-panel oasis-editor-font-dialog-advanced-panel">');function uh(e){const t=D(),{ctrl:n}=e;return r=dh(),Ue(r,wt(vt,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("dialog.font.advancedCharacterSpacingGroup")},get children(){return wt(d,{container:!0,spacing:1.5,get children(){return[wt(d,{size:{xs:12,md:4},get children(){return wt(Cr,{get label(){return t("dialog.font.advancedScale")},get value(){return n.advancedTabValues().characterScale||"100"},onChange:e=>n.updateAdvancedTab("characterScale",e),"data-testid":"editor-font-dialog-advanced-scale",get options(){return _m.map(e=>({value:String(e),label:`${e}%`}))}})}}),wt(d,{size:{xs:12,md:8},get children(){return wt(d,{container:!0,spacing:1.5,get children(){return[wt(d,{size:{xs:12,md:8},get children(){return wt(Cr,{get label(){return t("dialog.font.advancedSpacing")},get value(){return n.advancedTabValues().spacingMode},onChange:e=>n.updateAdvancedTab("spacingMode",e),"data-testid":"editor-font-dialog-advanced-spacing-mode",get options(){return[{value:"normal",label:t("dialog.font.advancedNormal")},{value:"expanded",label:t("dialog.font.advancedExpanded")},{value:"condensed",label:t("dialog.font.advancedCondensed")}]}})}}),wt(d,{size:{xs:12,md:4},get children(){return wt(pe,{class:"oasis-editor-font-dialog-small-input",get label(){return t("dialog.font.advancedBy")},get value(){return n.advancedTabValues().spacingAmount},get disabled(){return"normal"===n.advancedTabValues().spacingMode},onChange:e=>n.updateAdvancedTab("spacingAmount",e),"data-testid":"editor-font-dialog-advanced-spacing-amount"})}})]}})}}),wt(d,{size:{xs:12,md:8},get children(){return wt(Cr,{get label(){return t("dialog.font.advancedPosition")},get value(){return n.advancedTabValues().positionMode},onChange:e=>n.updateAdvancedTab("positionMode",e),"data-testid":"editor-font-dialog-advanced-position-mode",get options(){return[{value:"normal",label:t("dialog.font.advancedNormal")},{value:"raised",label:t("dialog.font.advancedRaised")},{value:"lowered",label:t("dialog.font.advancedLowered")}]}})}}),wt(d,{size:{xs:12,md:4},get children(){return wt(pe,{class:"oasis-editor-font-dialog-small-input",get label(){return t("dialog.font.advancedBy")},get value(){return n.advancedTabValues().positionAmount},get disabled(){return"normal"===n.advancedTabValues().positionMode},onChange:e=>n.updateAdvancedTab("positionAmount",e),"data-testid":"editor-font-dialog-advanced-position-amount"})}}),wt(d,{size:12,get children(){var e=ch();return Ue(e,wt(Be,{class:"oasis-editor-font-dialog-kerning-toggle",get label(){return t("dialog.font.advancedKerning")},get checked(){return n.advancedTabValues().kerningEnabled},onChange:e=>n.setAdvancedTabValues(t=>({...t,kerningEnabled:e,kerningThreshold:e?t.kerningThreshold||"1":t.kerningThreshold})),"data-testid":"editor-font-dialog-advanced-kerning-enabled"}),null),Ue(e,wt(pe,{class:"oasis-editor-font-dialog-kerning-input",get value(){return n.advancedTabValues().kerningThreshold},get disabled(){return!n.advancedTabValues().kerningEnabled},onChange:e=>n.updateAdvancedTab("kerningThreshold",e),"data-testid":"editor-font-dialog-advanced-kerning"}),null),Ue(e,wt(oe,{class:"oasis-editor-dialog-help-text oasis-editor-font-dialog-kerning-suffix",get children(){return t("dialog.font.advancedKerningAbove")}}),null),e}})]}})}}),null),Ue(r,wt(vt,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("dialog.font.advancedOpenTypeGroup")},get children(){return[wt(d,{container:!0,spacing:1.5,get children(){return[wt(d,{size:{xs:12,md:6},get children(){return wt(Cr,{get label(){return t("dialog.font.advancedLigatures")},get value(){return n.advancedTabValues().ligatures},onChange:e=>n.updateAdvancedTab("ligatures",e),"data-testid":"editor-font-dialog-advanced-ligatures",get options(){return[{value:"",label:t("dialog.font.advancedDefault")},{value:"none",label:t("dialog.font.advancedLigaturesNone")},{value:"standard",label:t("dialog.font.advancedLigaturesStandard")},{value:"contextual",label:t("dialog.font.advancedLigaturesContextual")},{value:"historical",label:t("dialog.font.advancedLigaturesHistorical")},{value:"standardContextual",label:t("dialog.font.advancedLigaturesStandardContextual")}]}})}}),wt(d,{size:{xs:12,md:6},get children(){return wt(Cr,{get label(){return t("dialog.font.advancedNumberSpacing")},get value(){return n.advancedTabValues().numberSpacing},onChange:e=>n.updateAdvancedTab("numberSpacing",e),"data-testid":"editor-font-dialog-advanced-number-spacing",get options(){return[{value:"",label:t("dialog.font.advancedDefault")},{value:"proportional",label:t("dialog.font.advancedNumberSpacingProportional")},{value:"tabular",label:t("dialog.font.advancedNumberSpacingTabular")}]}})}}),wt(d,{size:{xs:12,md:6},get children(){return wt(Cr,{get label(){return t("dialog.font.advancedNumberForm")},get value(){return n.advancedTabValues().numberForm},onChange:e=>n.updateAdvancedTab("numberForm",e),"data-testid":"editor-font-dialog-advanced-number-form",get options(){return[{value:"",label:t("dialog.font.advancedDefault")},{value:"lining",label:t("dialog.font.advancedNumberFormLining")},{value:"oldStyle",label:t("dialog.font.advancedNumberFormOldStyle")}]}})}}),wt(d,{size:{xs:12,md:6},get children(){return wt(Cr,{get label(){return t("dialog.font.advancedStylisticSet")},get value(){return n.advancedTabValues().stylisticSet},onChange:e=>n.updateAdvancedTab("stylisticSet",e),"data-testid":"editor-font-dialog-advanced-stylistic-set",get options(){return[{value:"",label:t("dialog.font.advancedDefault")},...Array.from({length:20},(e,t)=>t+1).map(e=>({value:String(e),label:String(e)}))]}})}})]}}),wt(Be,{class:"oasis-editor-font-dialog-contextual-toggle",get label(){return t("dialog.font.advancedContextualAlternates")},get checked(){return n.advancedTabValues().contextualAlternates},onChange:e=>n.updateAdvancedTab("contextualAlternates",e),"data-testid":"editor-font-dialog-advanced-contextual-alternates"})]}}),null),Ue(r,wt(vt,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("dialog.font.advancedPreviewGroup")},get children(){return wt(ih,{class:"oasis-editor-dialog-preview oasis-editor-font-dialog-advanced-preview",testId:"editor-font-dialog-advanced-preview",get style(){return n.previewStyle()}})}}),null),Ue(r,wt(oe,{as:"p",class:"oasis-editor-dialog-help-text","data-testid":"editor-font-dialog-advanced-placeholder",get children(){return n.advancedValidationError()||t("dialog.font.advancedPlaceholder")}}),null),r;var r}function ph(e){const t=D(),n=oh(e);return wt(F,{get isOpen(){return e.isOpen},get title(){return t("dialog.font.title")},get onClose(){return e.onClose},class:"oasis-editor-font-dialog",bodyClass:"oasis-editor-font-dialog-body",size:"font",get footer(){return wt(Nm,{get onCancel(){return e.onClose},get onConfirm(){return n.handleApply},get cancelLabel(){return t("generic.cancel")},get confirmLabel(){return t("generic.ok")},cancelTestId:"editor-font-dialog-cancel",confirmTestId:"editor-font-dialog-apply"})},get children(){return wt(me,{class:"oasis-editor-font-dialog-tabs",get ariaLabel(){return t("dialog.font.title")},get value(){return n.activeTab()},onChange:e=>n.setActiveTab(e),get items(){return[{id:"font",label:t("dialog.font.tabFont"),testId:"editor-font-dialog-tab-font",panel:wt(lh,{ctrl:n})},{id:"advanced",label:t("dialog.font.tabAdvanced"),testId:"editor-font-dialog-tab-advanced",panel:wt(uh,{ctrl:n})}]}})}})}var fh=/*#__PURE__*/qn("<div class=oasis-editor-word-tabs-fields><div><div class=oasis-editor-word-tabs-list role=group>"),gh=/*#__PURE__*/qn("<div class=oasis-editor-word-tabs-fields>"),mh=/*#__PURE__*/qn("<div class=oasis-editor-word-tabs-actions>"),hh=(e,t)=>Math.abs(e-t)<In,bh=e=>null!==e&&Number.isFinite(e)&&Math.abs(e)<=1584;function yh(e){const t=D(),[r,o]=Nt([]),[a,i]=Nt([]),[s,l]=Nt(null),[c,d]=Nt("left"),[u,p]=Nt("none"),[f,g]=Nt(36),[m,h]=Nt(36),b=e=>{l(e.position),"clear"!==e.type&&d(e.type),p(e.leader??"none")};mn(()=>{if(!e.isOpen)return;const t=e.initial.filter(e=>"clear"!==e.type).map(e=>({...e})).sort((e,t)=>e.position-t.position);o(t),i([]);const n=e.initialDefault??36;g(n),h(n),l(null),d("left"),p("none");const r=t.find(t=>void 0!==e.selectedPosition&&hh(t.position,e.selectedPosition));r&&b(r)});const y=()=>r().find(e=>null!==s()&&hh(e.position,s())),x=()=>{const e=f();return null!==e&&Number.isFinite(e)&&e>=1&&e<=1584},w=()=>bh(s())&&(Boolean(y())||r().length<64),I=()=>{const e=s();if(!bh(e)||!w())return;const t={position:e,type:c(),..."bar"!==c()&&"none"!==u()?{leader:u()}:{}};o(n=>[...n.filter(t=>!hh(t.position,e)),t].sort((e,t)=>e.position-t.position)),i(e=>[...e,{set:[t]}])},S=()=>{const e=s();bh(e)&&y()&&(o(t=>t.filter(t=>!hh(t.position,e))),i(t=>[...t,{clear:[e]}]),l(null))},C=()=>{o([]),l(null),i(e=>[...e,{clearAll:!0}])},k=()=>{if(!x())return;const t=[...a()];f()!==m()&&t.push({default:f()}),e.onApply(r().map(e=>({...e})),t),e.onClose()};return wt(F,{get isOpen(){return e.isOpen},get title(){return t("paragraph.tabsTitle")},get onClose(){return e.onClose},testId:"editor-tab-stops-dialog",class:"oasis-editor-word-tabs-dialog",initialFocusTestId:"editor-tab-stops-position",get footer(){return[wt(bn,{variant:"secondary",get onClick(){return e.onClose},"data-testid":"editor-tab-stops-cancel",get children(){return t("generic.cancel")}}),wt(bn,{variant:"primary",get disabled(){return!x()},onClick:k,"data-testid":"editor-tab-stops-apply",get children(){return t("generic.apply")}})]},get children(){return[(a=fh(),i=a.firstChild,m=i.firstChild,Ue(i,wt(v,{get label(){return t("paragraph.tabsPosition")},step:"0.05",min:-Hn,max:Hn,get value(){return s()??""},onChange:l,"data-testid":"editor-tab-stops-position",get error(){return Qe(()=>!(null===s()||bh(s())))()?t("paragraph.tabsInvalidPosition"):void 0}}),m),Ue(m,wt(dt,{get each(){return r()},get fallback(){return wt(oe,{as:"p",get children(){return t("paragraph.tabsEmpty")}})},children:e=>wt(bn,{variant:"ghost",class:"oasis-editor-word-tabs-option",get"aria-pressed"(){return Qe(()=>null!==s())()&&hh(s(),e.position)},onClick:()=>b(e),"data-testid":"editor-tab-stops-option",get children(){return[Qe(()=>Number(e.position.toFixed(2)))," pt"]}})})),Ue(a,wt(v,{get label(){return t("paragraph.tabsDefaultInterval")},step:"0.05",min:"1",max:Hn,get value(){return f()??""},onChange:g,"data-testid":"editor-tab-stops-default",get error(){return Qe(()=>!x())()?t("paragraph.tabsInvalidInterval"):void 0}}),null),Pt(()=>n(m,"aria-label",t("paragraph.tabsDefined"))),a),(o=gh(),Ue(o,wt(Pe,{get label(){return t("paragraph.tabsAlignment")},get value(){return c()},get options(){return[{value:"left",label:t("paragraph.tabAlignLeft")},{value:"center",label:t("paragraph.tabAlignCenter")},{value:"right",label:t("paragraph.tabAlignRight")},{value:"decimal",label:t("paragraph.tabAlignDecimal")},{value:"bar",label:t("paragraph.tabAlignBar")}]},onChange:e=>d(e)}),null),Ue(o,wt(Pe,{get label(){return t("paragraph.tabsLeader")},get value(){return Qe(()=>"bar"===c())()?"none":u()},get options(){return[{value:"none",label:t("paragraph.tabLeaderNone")},{value:"dot",label:"2 ............"},{value:"hyphen",label:"3 ----------"},{value:"underscore",label:"4 ________"},{value:"heavy",label:"5 ━━━━━━"},{value:"middleDot",label:"6 ············"}]},get disabled(){return"bar"===c()},onChange:e=>p(e)}),null),o),(e=mh(),Ue(e,wt(bn,{get disabled(){return!w()},onClick:I,"data-testid":"editor-tab-stops-set",get children(){return t("paragraph.tabsSet")}}),null),Ue(e,wt(bn,{get disabled(){return!y()},onClick:S,"data-testid":"editor-tab-stops-remove",get children(){return t("paragraph.tabsClear")}}),null),Ue(e,wt(bn,{onClick:C,"data-testid":"editor-tab-stops-clear",get children(){return t("paragraph.tabsClearAll")}}),null),e),wt(oe,{as:"p",get children(){return t("paragraph.tabsDraftHelp")}})];var e,o,a,i,m}})}var vh=96/72;function xh(e){const[t,n]=Nt(""),[r,o]=Nt(""),[a,i]=Nt(null),[s,l]=Nt(null),[c,d]=Nt("none"),[u,p]=Nt(null),[f,g]=Nt(!1),[m,h]=Nt(null),[b,y]=Nt(null),[v,x]=Nt("multiple"),[w,I]=Nt(null),[S,C]=Nt(!1),[k,T]=Nt(""),[P,R]=Nt("none"),[A,M]=Nt(null),[O,B]=Nt(""),[F,E]=Nt(!1),[D,L]=Nt(!1),[N,z]=Nt(!1),[$,H]=Nt(!1),[W,j]=Nt(!1),[U,V]=Nt(!1),[K,_]=Nt(!1),[X,q]=Nt(!0),[G,Y]=Nt([]),[Z,J]=Nt([]),[Q,ee]=Nt(36);mn(()=>{if(e.isOpen){n(e.initial.align??""),o(e.initial.outlineLevel??""),i(vn(e.initial.indentLeft??"")),l(vn(e.initial.indentRight??"")),g(e.initial.mirrorIndents??!1),h(vn(e.initial.spacingBefore??"")),y(vn(e.initial.spacingAfter??"")),C(e.initial.contextualSpacing??!1),T(e.initial.shading??"");const{mode:a,at:s}=(t=e.initial.lineRule??"",r=vn(e.initial.lineHeight??""),"exact"===t||"atLeast"===t?{mode:t,at:null!==r?Math.round(r/vh):null}:null===r?{mode:"multiple",at:null}:1===r?{mode:"single",at:null}:1.5===r?{mode:"onePointFive",at:null}:2===r?{mode:"double",at:null}:{mode:"multiple",at:r});x(a),I(s);const c=e.initial.borderStyle;R("solid"===c||"dashed"===c||"dotted"===c?c:"none"),M(vn(e.initial.borderWidth??"")),B(e.initial.borderColor??""),E(e.initial.borderSideTop??!1),L(e.initial.borderSideRight??!1),z(e.initial.borderSideBottom??!1),H(e.initial.borderSideLeft??!1),j(e.initial.pageBreakBefore??!1),V(e.initial.keepWithNext??!1),_(e.initial.keepLinesTogether??!1),q(e.initial.widowControl??!0),Y(e.initial.tabs??[]),J([]),ee(e.initial.defaultTabStop??36);const u=vn(e.initial.indentFirstLine??""),f=vn(e.initial.indentHanging??"");null!==f&&f>0?(d("hanging"),p(f)):null!==u&&u>0?(d("firstLine"),p(u)):(d("none"),p(null))}var t,r});const te=()=>{switch(v()){case"single":return{lineHeight:1,lineRule:null};case"onePointFive":return{lineHeight:1.5,lineRule:null};case"double":return{lineHeight:2,lineRule:null};case"multiple":return{lineHeight:w(),lineRule:null};case"atLeast":return{lineHeight:null!==w()?w()*vh:null,lineRule:"atLeast"};case"exact":return{lineHeight:null!==w()?w()*vh:null,lineRule:"exact"}}},ne=ur(()=>{const e=a(),n=s(),r="firstLine"===c()?u():null,o="hanging"===c()?u():null,i=null!==r?r:null!==o?-o:null,l="none"!==P()?`${A()??.5}pt ${P()} ${O().trim()||"#000000"}`:void 0,{lineHeight:d,lineRule:p}=te(),f=null===d?void 0:"exact"===p||"atLeast"===p?`${d}px`:String(d);return{"text-align":t()||void 0,"line-height":f,"padding-left":null!==e?`${e+(o??0)}pt`:void 0,"padding-right":null!==n?`${n}pt`:void 0,"text-indent":null!==i?`${i}pt`:void 0,"background-color":k().trim()||void 0,"border-top":l&&F()?l:void 0,"border-right":l&&D()?l:void 0,"border-bottom":l&&N()?l:void 0,"border-left":l&&$()?l:void 0}}),re=()=>{const e=P();if("none"===e)return{top:null,right:null,bottom:null,left:null};const t=A(),n={type:e,width:null!==t&&t>0?t:.5,color:O().trim()||"#000000"};return{top:F()?n:null,right:D()?n:null,bottom:N()?n:null,left:$()?n:null}},oe=()=>{const e=u(),{lineHeight:n,lineRule:o}=te(),i=r();return{align:t()||null,indentLeft:a(),indentRight:s(),indentFirstLine:"firstLine"===c()?e:null,indentHanging:"hanging"===c()?e:null,mirrorIndents:f(),spacingBefore:m(),spacingAfter:b(),lineHeight:n,lineRule:o,contextualSpacing:S(),outlineLevel:""===i?null:Number(i),shading:k().trim()||null,borders:re(),pageBreakBefore:W(),keepWithNext:U(),keepLinesTogether:K(),widowControl:X(),tabs:G(),...Z().length?{tabChanges:Z()}:{}}};return{align:t,setAlign:n,outlineLevel:r,setOutlineLevel:o,indentLeft:a,setIndentLeft:i,indentRight:s,setIndentRight:l,special:c,setSpecial:d,specialBy:u,setSpecialBy:p,mirrorIndents:f,setMirrorIndents:g,spacingBefore:m,setSpacingBefore:h,spacingAfter:b,setSpacingAfter:y,lineMode:v,setLineMode:x,lineAt:w,setLineAt:I,contextualSpacing:S,setContextualSpacing:C,shading:k,setShading:T,borderStyle:P,setBorderStyle:R,borderWidth:A,setBorderWidth:M,borderColor:O,setBorderColor:B,sideTop:F,setSideTop:E,sideRight:D,setSideRight:L,sideBottom:N,setSideBottom:z,sideLeft:$,setSideLeft:H,pageBreakBefore:W,setPageBreakBefore:j,keepWithNext:U,setKeepWithNext:V,keepLinesTogether:K,setKeepLinesTogether:_,widowControl:X,setWidowControl:q,tabs:G,setTabs:Y,defaultTabStop:Q,setDefaultTabStop:ee,setTabChanges:J,atEnabled:()=>"multiple"===v()||"atLeast"===v()||"exact"===v(),previewStyle:ne,handleApply:()=>{e.onApply(oe(),e.initial),e.onClose()},handleSetDefault:()=>{e.onSetDefault?.(oe()),e.onClose()}}}var wh=/*#__PURE__*/qn("<div class=oasis-editor-paragraph-dialog-panel>"),Ih=/*#__PURE__*/qn("<div class=oasis-editor-dialog-preview data-testid=editor-paragraph-dialog-preview>"),Sh=/*#__PURE__*/qn("<div>"),Ch=/*#__PURE__*/qn("<div class=oasis-editor-dialog-footer-split><div class=oasis-editor-dialog-footer-start></div><div class=oasis-editor-dialog-footer-end>");function kh(e){const t=D(),[n,r]=Nt(!1),{align:o,setAlign:a,outlineLevel:i,setOutlineLevel:s,indentLeft:l,setIndentLeft:c,indentRight:u,setIndentRight:p,special:f,setSpecial:g,specialBy:m,setSpecialBy:h,mirrorIndents:b,setMirrorIndents:y,spacingBefore:x,setSpacingBefore:w,spacingAfter:I,setSpacingAfter:S,lineMode:C,setLineMode:k,lineAt:T,setLineAt:P,contextualSpacing:R,setContextualSpacing:M,shading:O,setShading:B,borderStyle:E,setBorderStyle:L,borderWidth:N,setBorderWidth:z,borderColor:$,setBorderColor:H,sideTop:W,setSideTop:j,sideRight:U,setSideRight:V,sideBottom:K,setSideBottom:_,sideLeft:X,setSideLeft:q,pageBreakBefore:G,setPageBreakBefore:Y,keepWithNext:Z,setKeepWithNext:J,keepLinesTogether:Q,setKeepLinesTogether:ee,widowControl:te,setWidowControl:ne,tabs:re,setTabs:oe,defaultTabStop:ae,setDefaultTabStop:ie,setTabChanges:se,atEnabled:le,previewStyle:ce,handleApply:de,handleSetDefault:ue}=xh(e),pe=wt(Cr,{get label(){return t("paragraph.alignLabel")},get value(){return o()},onChange:a,"data-testid":"editor-paragraph-dialog-align",get options(){return[{value:"left",label:t("paragraph.alignLeft")},{value:"center",label:t("paragraph.alignCenter")},{value:"right",label:t("paragraph.alignRight")},{value:"justify",label:t("paragraph.alignJustify")}]}}),fe=wt(Cr,{get label(){return t("paragraph.outlineLevelLabel")},get value(){return i()},onChange:s,"data-testid":"editor-paragraph-dialog-outline-level",get options(){return[{value:"",label:t("paragraph.outlineBodyText")},...Array.from({length:9},(e,n)=>({value:String(n),label:t("paragraph.outlineLevelN",[n+1])}))]}}),ge=(he=wh(),Ue(he,wt(vt,{class:"oasis-editor-dialog-fieldset",get legend(){return t("paragraph.groupGeneral")},get children(){return wt(d,{container:!0,spacing:1.5,get children(){return[wt(d,{size:{xs:12,md:6},children:pe}),wt(d,{size:{xs:12,md:6},children:fe})]}})}}),null),Ue(he,wt(vt,{class:"oasis-editor-dialog-fieldset",get legend(){return t("paragraph.groupIndent")},get children(){return wt(d,{container:!0,spacing:1.5,get children(){return[wt(d,{size:{xs:12,md:6},get children(){return wt(v,{get label(){return t("paragraph.indentLeftLabel")},step:"1",get value(){return l()??""},onChange:c,"data-testid":"editor-paragraph-dialog-indent-left"})}}),wt(d,{size:{xs:12,md:6},get children(){return wt(v,{get label(){return t("paragraph.indentRightLabel")},step:"1",get value(){return u()??""},onChange:p,"data-testid":"editor-paragraph-dialog-indent-right"})}}),wt(d,{size:{xs:12,md:6},get children(){return wt(Cr,{get label(){return t("paragraph.specialLabel")},get value(){return f()},onChange:e=>{const t=e;g(t),"none"===t&&h(null)},"data-testid":"editor-paragraph-dialog-special",get options(){return[{value:"none",label:t("paragraph.specialNone")},{value:"firstLine",label:t("paragraph.specialFirstLine")},{value:"hanging",label:t("paragraph.specialHanging")}]}})}}),wt(d,{size:{xs:12,md:6},get children(){return wt(v,{get label(){return t("paragraph.specialByLabel")},min:"0",step:"1",get disabled(){return"none"===f()},get value(){return m()??""},onChange:h,"data-testid":"editor-paragraph-dialog-special-by"})}}),wt(d,{size:12,get children(){return wt(Be,{get label(){return t("paragraph.mirrorIndentsLabel")},get checked(){return b()},onChange:y,"data-testid":"editor-paragraph-dialog-mirror-indents"})}})]}})}}),null),Ue(he,wt(vt,{class:"oasis-editor-dialog-fieldset",get legend(){return t("paragraph.groupSpacing")},get children(){return wt(d,{container:!0,spacing:1.5,get children(){return[wt(d,{size:{xs:12,md:4},get children(){return wt(v,{get label(){return t("paragraph.spacingBeforeLabel")},min:"0",step:"1",get value(){return x()??""},onChange:w,"data-testid":"editor-paragraph-dialog-spacing-before"})}}),wt(d,{size:{xs:12,md:4},get children(){return wt(v,{get label(){return t("paragraph.spacingAfterLabel")},min:"0",step:"1",get value(){return I()??""},onChange:S,"data-testid":"editor-paragraph-dialog-spacing-after"})}}),wt(d,{size:{xs:12,md:4}}),wt(d,{size:{xs:12,md:8},get children(){return wt(Cr,{get label(){return t("paragraph.lineSpacingLabel")},get value(){return C()},onChange:e=>{k(e)},"data-testid":"editor-paragraph-dialog-line-mode",get options(){return[{value:"single",label:t("paragraph.lineSpacingSingle")},{value:"onePointFive",label:t("paragraph.lineSpacingOnePointFive")},{value:"double",label:t("paragraph.lineSpacingDouble")},{value:"atLeast",label:t("paragraph.lineSpacingAtLeast")},{value:"exact",label:t("paragraph.lineSpacingExact")},{value:"multiple",label:t("paragraph.lineSpacingMultiple")}]}})}}),wt(d,{size:{xs:12,md:4},get children(){return wt(v,{get label(){return t("paragraph.lineSpacingAt")},min:"0",get step(){return"multiple"===C()?"0.05":"1"},get disabled(){return!le()},get value(){return T()??""},onChange:P,"data-testid":"editor-paragraph-dialog-line-at"})}}),wt(d,{size:12,get children(){return wt(Be,{get label(){return t("paragraph.contextualSpacingLabel")},get checked(){return R()},onChange:M,"data-testid":"editor-paragraph-dialog-contextual-spacing"})}})]}})}}),null),Ue(he,wt(vt,{class:"oasis-editor-dialog-fieldset",get legend(){return t("paragraph.groupBorders")},get children(){return[wt(d,{container:!0,spacing:1.5,get children(){return[wt(d,{size:{xs:12,md:3},get children(){return wt(Cr,{get label(){return t("paragraph.borderStyleLabel")},get value(){return E()},onChange:e=>{const t=e;L(t),"none"===t?(j(!1),V(!1),_(!1),q(!1)):W()||U()||K()||X()||(j(!0),V(!0),_(!0),q(!0))},"data-testid":"editor-paragraph-dialog-border-style",get options(){return[{value:"none",label:t("paragraph.borderNone")},{value:"solid",label:t("paragraph.borderSolid")},{value:"dashed",label:t("paragraph.borderDashed")},{value:"dotted",label:t("paragraph.borderDotted")}]}})}}),wt(d,{size:{xs:12,md:3},get children(){return wt(v,{get label(){return t("paragraph.borderWidthLabel")},min:"0",step:"0.25",get disabled(){return"none"===E()},get value(){return N()??""},onChange:z,"data-testid":"editor-paragraph-dialog-border-width"})}}),wt(d,{size:{xs:12,md:3},get children(){return wt(A,{get label(){return t("paragraph.borderColorLabel")},get disabled(){return"none"===E()},get value(){return $()||"#000000"},onChange:H,"data-testid":"editor-paragraph-dialog-border-color"})}}),wt(d,{size:{xs:12,md:3},get children(){return wt(A,{get label(){return t("paragraph.shadingLabel")},get value(){return O()||"#ffffff"},onChange:B,"data-testid":"editor-paragraph-dialog-shading"})}})]}}),wt(fn,{class:"oasis-editor-dialog-input-group-grow",get label(){return t("paragraph.borderSidesLabel")},get children(){return wt(ln,{class:"oasis-editor-dialog-style-row",direction:"row",spacing:1,get children(){return[wt(Be,{get label(){return t("paragraph.borderSideTop")},get disabled(){return"none"===E()},get checked(){return W()},onChange:j,"data-testid":"editor-paragraph-dialog-border-side-top"}),wt(Be,{get label(){return t("paragraph.borderSideRight")},get disabled(){return"none"===E()},get checked(){return U()},onChange:V,"data-testid":"editor-paragraph-dialog-border-side-right"}),wt(Be,{get label(){return t("paragraph.borderSideBottom")},get disabled(){return"none"===E()},get checked(){return K()},onChange:_,"data-testid":"editor-paragraph-dialog-border-side-bottom"}),wt(Be,{get label(){return t("paragraph.borderSideLeft")},get disabled(){return"none"===E()},get checked(){return X()},onChange:q,"data-testid":"editor-paragraph-dialog-border-side-left"})]}})}})]}}),null),he);var he;const be=(ye=wh(),Ue(ye,wt(vt,{class:"oasis-editor-dialog-fieldset",get legend(){return t("paragraph.groupPagination")},get children(){return wt(ln,{direction:"column",spacing:1,get children(){return[wt(Be,{get label(){return t("paragraph.widowControlLabel")},get checked(){return te()},onChange:ne,"data-testid":"editor-paragraph-dialog-widow-control"}),wt(Be,{get label(){return t("paragraph.keepWithNextLabel")},get checked(){return Z()},onChange:J,"data-testid":"editor-paragraph-dialog-keep-with-next"}),wt(Be,{get label(){return t("paragraph.keepLinesTogetherLabel")},get checked(){return Q()},onChange:ee,"data-testid":"editor-paragraph-dialog-keep-lines-together"}),wt(Be,{get label(){return t("paragraph.pageBreakBeforeLabel")},get checked(){return G()},onChange:Y,"data-testid":"editor-paragraph-dialog-page-break-before"})]}})}})),ye);var ye,ve;return ve=Sh(),Ue(ve,wt(F,{get isOpen(){return Qe(()=>!(!e.isOpen||n()))()&&!e.initial.tabsOnly},get title(){return t("paragraph.title")},get onClose(){return e.onClose},size:"lg",testId:"editor-paragraph-dialog",get footer(){return n=Ch(),o=n.firstChild,a=o.nextSibling,Ue(o,wt(bn,{variant:"secondary",onClick:()=>{r(!0)},"data-testid":"editor-paragraph-dialog-tabs",get children(){return t("paragraph.tabsButton")}}),null),Ue(o,wt(bn,{variant:"secondary",onClick:ue,"data-testid":"editor-paragraph-dialog-set-default",get children(){return t("paragraph.setAsDefault")}}),null),Ue(a,wt(bn,{variant:"secondary",get onClick(){return e.onClose},"data-testid":"editor-paragraph-dialog-cancel",get children(){return t("generic.cancel")}}),null),Ue(a,wt(bn,{variant:"primary",onClick:de,"data-testid":"editor-paragraph-dialog-apply",get children(){return t("generic.apply")}}),null),n;var n,o,a},get children(){return[wt(me,{get ariaLabel(){return t("paragraph.title")},get items(){return[{id:"indents",label:t("paragraph.tabIndentsSpacing"),panel:ge,testId:"editor-paragraph-dialog-tab-indents"},{id:"breaks",label:t("paragraph.tabLineBreaks"),panel:be,testId:"editor-paragraph-dialog-tab-breaks"}]}}),wt(fn,{get label(){return t("paragraph.preview")},get children(){var e=Ih();return Ue(e,()=>t("paragraph.previewText")),Pt(t=>Tn(e,ce(),t)),e}})]}}),null),Ue(ve,wt(yh,{get isOpen(){return Qe(()=>!!e.isOpen)()&&(n()||!!e.initial.tabsOnly)},get initial(){return re()},get initialDefault(){return ae()},get selectedPosition(){return e.initial.selectedTabPosition},onClose:()=>{r(!1),e.initial.tabsOnly&&e.onClose()},onApply:(t,n)=>{oe(t),se(e=>[...e,...n]);for(const e of n)"number"==typeof e.default&&ie(e.default);e.initial.tabsOnly&&de()}}),null),ve}function Th(e,t){const n=vn(e);return null===n?null:"percent"===t?`${n}%`:n}function Ph(e,t,n){if("none"===e)return null;const r=vn(t);return{type:e,width:null!==r&&r>0?r:.5,color:n.trim()||"#000000"}}function Rh(e){const[t,n]=zt({activeTab:"table",tableWidth:"",tableWidthUnit:"points",tableAlign:"",tableIndentLeft:"",tableWrapping:"none",floatingHorizontalAnchor:"margin",floatingVerticalAnchor:"text",floatingX:"",floatingY:"",floatingXAlign:"",floatingYAlign:"",floatingDistanceTop:"",floatingDistanceRight:"",floatingDistanceBottom:"",floatingDistanceLeft:"",floatingOverlap:"overlap",rowHeight:"",rowHeightRule:"",repeatHeader:!1,allowBreakAcrossPages:!0,hiddenRow:!1,columnWidth:"",cellWidth:"",cellVerticalAlign:"",cellTextDirection:"",cellNoWrap:!1,cellFitText:!1,cellHideMark:!1,marginTop:"",marginRight:"",marginBottom:"",marginLeft:"",borderStyle:"none",borderWidth:"",borderColor:"",borderTop:!1,borderRight:!1,borderBottom:!1,borderLeft:!1,borderStart:!1,borderEnd:!1,borderTlBr:!1,borderTrBl:!1,shading:"",altTitle:"",altDescription:""});mn(()=>{var t;e.isOpen&&n($n({activeTab:(t=e.initial).activeTab??"table",tableWidth:t.tableWidth,tableWidthUnit:t.tableWidthUnit,tableAlign:t.tableAlign,tableIndentLeft:t.tableIndentLeft,tableWrapping:t.tableWrapping,floatingHorizontalAnchor:t.floatingHorizontalAnchor,floatingVerticalAnchor:t.floatingVerticalAnchor,floatingX:t.floatingX,floatingY:t.floatingY,floatingXAlign:t.floatingXAlign,floatingYAlign:t.floatingYAlign,floatingDistanceTop:t.floatingDistanceTop,floatingDistanceRight:t.floatingDistanceRight,floatingDistanceBottom:t.floatingDistanceBottom,floatingDistanceLeft:t.floatingDistanceLeft,floatingOverlap:t.floatingOverlap,rowHeight:t.rowHeight,rowHeightRule:t.rowHeightRule,repeatHeader:t.repeatHeader,allowBreakAcrossPages:t.allowBreakAcrossPages,hiddenRow:t.hiddenRow,columnWidth:t.columnWidth,cellWidth:t.cellWidth,cellVerticalAlign:t.cellVerticalAlign,cellTextDirection:t.cellTextDirection,cellNoWrap:t.cellNoWrap,cellFitText:t.cellFitText,cellHideMark:t.cellHideMark,marginTop:t.marginTop,marginRight:t.marginRight,marginBottom:t.marginBottom,marginLeft:t.marginLeft,borderStyle:t.borderStyle,borderWidth:t.borderWidth,borderColor:t.borderColor,borderTop:t.borderTop,borderRight:t.borderRight,borderBottom:t.borderBottom,borderLeft:t.borderLeft,borderStart:t.borderStart,borderEnd:t.borderEnd,borderTlBr:t.borderTopLeftToBottomRight,borderTrBl:t.borderTopRightToBottomLeft,shading:t.shading,altTitle:t.altTitle,altDescription:t.altDescription}))});return{form:t,set:n,handleApply:()=>{e.onApply(function(e){const t=Ph(e.borderStyle,e.borderWidth,e.borderColor);return{tableWidth:Th(e.tableWidth,e.tableWidthUnit),tableAlign:e.tableAlign||null,tableIndentLeft:Th(e.tableIndentLeft,"points"),tableFloating:"around"===e.tableWrapping?{horizontalAnchor:e.floatingHorizontalAnchor,verticalAnchor:e.floatingVerticalAnchor,...e.floatingXAlign?{xAlign:e.floatingXAlign}:{x:vn(e.floatingX)??0},...e.floatingYAlign?{yAlign:e.floatingYAlign}:{y:vn(e.floatingY)??0},distanceTop:vn(e.floatingDistanceTop)??0,distanceRight:vn(e.floatingDistanceRight)??0,distanceBottom:vn(e.floatingDistanceBottom)??0,distanceLeft:vn(e.floatingDistanceLeft)??0}:null,tableOverlap:"around"===e.tableWrapping?e.floatingOverlap:null,rowHeight:Th(e.rowHeight,"points"),rowHeightRule:e.rowHeightRule||null,repeatHeader:e.repeatHeader,cantSplit:!e.allowBreakAcrossPages,hiddenRow:e.hiddenRow,columnWidth:Th(e.columnWidth,"points"),cellWidth:Th(e.cellWidth,"points"),cellVerticalAlign:e.cellVerticalAlign||null,cellTextDirection:e.cellTextDirection||null,cellNoWrap:e.cellNoWrap,cellFitText:e.cellFitText,cellHideMark:e.cellHideMark,margins:{top:vn(e.marginTop),right:vn(e.marginRight),bottom:vn(e.marginBottom),left:vn(e.marginLeft)},borders:{top:e.borderTop?t:null,right:e.borderRight?t:null,bottom:e.borderBottom?t:null,left:e.borderLeft?t:null,start:e.borderStart?t:null,end:e.borderEnd?t:null,topLeftToBottomRight:e.borderTlBr?t:null,topRightToBottomLeft:e.borderTrBl?t:null},shading:e.shading.trim()||null,altTitle:e.altTitle.trim()||null,altDescription:e.altDescription.trim()||null}}(t),e.initial),e.onClose()}}}function Ah(e,t,n,r,o=!1,a=!1){return wt(pe,{class:"oasis-editor-dialog-input-group-grow",type:"number",label:e,min:a?void 0:"0",step:"1",get value(){return t()},disabled:o,onChange:n,"data-testid":r})}var Mh=/*#__PURE__*/qn("<div class=oasis-editor-table-properties-panel>");function Oh(e){const t=D(),n=()=>e.ctrl.form,r=e.ctrl.set;return o=Mh(),Ue(o,wt(vt,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("table.sizeSection")},get children(){return wt(d,{container:!0,spacing:1.5,get children(){return[wt(d,{size:{xs:12,md:6},get children(){return Ah(t("table.preferredWidth"),()=>n().tableWidth,e=>r("tableWidth",e),"editor-table-properties-table-width")}}),wt(d,{size:{xs:12,md:6},get children(){return wt(Cr,{get label(){return t("table.measureIn")},get value(){return n().tableWidthUnit},onChange:e=>r("tableWidthUnit",e),"data-testid":"editor-table-properties-table-width-unit",get options(){return[{value:"points",label:t("table.points")},{value:"percent",label:t("table.percent")}]}})}})]}})}}),null),Ue(o,wt(vt,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("table.alignmentSection")},get children(){return[wt(Pe,{class:"oasis-editor-dialog-style-row",name:"table-align",get value(){return n().tableAlign},onChange:e=>r("tableAlign",e),get children(){return["left","center","right"].map(e=>wt(Ar,{value:e,get label(){return t(`table.align${e[0].toUpperCase()}${e.slice(1)}`)},"data-testid":`editor-table-properties-align-${e}`}))}}),wt(d,{container:!0,spacing:1.5,get children(){return wt(d,{size:{xs:12,md:6},get children(){return Ah(t("table.indentFromLeft"),()=>n().tableIndentLeft,e=>r("tableIndentLeft",e),"editor-table-properties-indent-left")}})}})]}}),null),Ue(o,wt(vt,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("table.textWrappingSection")},get children(){return[wt(ln,{class:"oasis-editor-dialog-style-row",direction:"row",spacing:1,get children(){return[wt(Be,{get label(){return t("table.wrapNone")},get checked(){return"none"===n().tableWrapping},onChange:()=>r("tableWrapping","none"),"data-testid":"editor-table-properties-wrap-none"}),wt(Be,{get label(){return t("table.wrapAround")},get checked(){return"around"===n().tableWrapping},onChange:()=>r("tableWrapping","around"),"data-testid":"editor-table-properties-wrap-around"})]}}),wt(Bn,{get when(){return"around"===n().tableWrapping},get children(){return[wt(d,{container:!0,spacing:1.5,get children(){return[wt(d,{size:{xs:12,md:6},get children(){return wt(Cr,{get label(){return t("table.horizontalAnchor")},get value(){return n().floatingHorizontalAnchor},onChange:e=>r("floatingHorizontalAnchor",e),"data-testid":"editor-table-properties-floating-h-anchor",get options(){return[{value:"margin",label:t("table.anchorMargin")},{value:"page",label:t("table.anchorPage")},{value:"text",label:t("table.anchorText")}]}})}}),wt(d,{size:{xs:12,md:6},get children(){return wt(Cr,{get label(){return t("table.verticalAnchor")},get value(){return n().floatingVerticalAnchor},onChange:e=>r("floatingVerticalAnchor",e),"data-testid":"editor-table-properties-floating-v-anchor",get options(){return[{value:"margin",label:t("table.anchorMargin")},{value:"page",label:t("table.anchorPage")},{value:"text",label:t("table.anchorText")}]}})}}),wt(d,{size:{xs:12,md:3},get children(){return Ah(t("table.positionX"),()=>n().floatingX,e=>r("floatingX",e),"editor-table-properties-floating-x",Boolean(n().floatingXAlign),!0)}}),wt(d,{size:{xs:12,md:3},get children(){return Ah(t("table.positionY"),()=>n().floatingY,e=>r("floatingY",e),"editor-table-properties-floating-y",Boolean(n().floatingYAlign),!0)}}),wt(d,{size:{xs:12,md:3},get children(){return wt(Cr,{get label(){return t("table.horizontalAlignment")},get value(){return n().floatingXAlign},onChange:e=>r("floatingXAlign",e),"data-testid":"editor-table-properties-floating-x-align",get options(){return[{value:"",label:t("table.explicitOffset")},...["left","center","right","inside","outside"].map(e=>({value:e,label:e}))]}})}}),wt(d,{size:{xs:12,md:3},get children(){return wt(Cr,{get label(){return t("table.verticalAlignment")},get value(){return n().floatingYAlign},onChange:e=>r("floatingYAlign",e),"data-testid":"editor-table-properties-floating-y-align",get options(){return[{value:"",label:t("table.explicitOffset")},...["top","center","bottom","inside","outside"].map(e=>({value:e,label:e}))]}})}}),wt(d,{size:{xs:12,md:3},get children(){return Ah(t("table.distanceTop"),()=>n().floatingDistanceTop,e=>r("floatingDistanceTop",e),"editor-table-properties-floating-distance-top")}}),wt(d,{size:{xs:12,md:3},get children(){return Ah(t("table.distanceRight"),()=>n().floatingDistanceRight,e=>r("floatingDistanceRight",e),"editor-table-properties-floating-distance-right")}}),wt(d,{size:{xs:12,md:3},get children(){return Ah(t("table.distanceBottom"),()=>n().floatingDistanceBottom,e=>r("floatingDistanceBottom",e),"editor-table-properties-floating-distance-bottom")}}),wt(d,{size:{xs:12,md:3},get children(){return Ah(t("table.distanceLeft"),()=>n().floatingDistanceLeft,e=>r("floatingDistanceLeft",e),"editor-table-properties-floating-distance-left")}})]}}),wt(Be,{get label(){return t("table.allowOverlap")},get checked(){return"overlap"===n().floatingOverlap},onChange:e=>r("floatingOverlap",e?"overlap":"never"),"data-testid":"editor-table-properties-floating-overlap"})]}})]}}),null),o;var o}var Bh=/*#__PURE__*/qn("<div class=oasis-editor-table-properties-panel>");function Fh(e){const t=D(),n=()=>e.ctrl.form,r=e.ctrl.set;return o=Bh(),Ue(o,wt(d,{container:!0,spacing:1.5,get children(){return[wt(d,{size:{xs:12,md:6},get children(){return Ah(t("table.rowHeight"),()=>n().rowHeight,e=>r("rowHeight",e),"editor-table-properties-row-height")}}),wt(d,{size:{xs:12,md:6},get children(){return wt(Cr,{get label(){return t("table.rowHeightRule")},get value(){return n().rowHeightRule},onChange:e=>r("rowHeightRule",e),"data-testid":"editor-table-properties-row-height-rule",get options(){return[{value:"",label:t("table.rowAuto")},{value:"atLeast",label:t("table.rowAtLeast")},{value:"exact",label:t("table.rowExactly")}]}})}})]}}),null),Ue(o,wt(ln,{class:"oasis-editor-dialog-style-row",direction:"row",spacing:1,get children(){return[wt(Be,{get label(){return t("table.repeatHeader")},get checked(){return n().repeatHeader},onChange:e=>r("repeatHeader",e),"data-testid":"editor-table-properties-repeat-header"}),wt(Be,{get label(){return t("table.allowBreakAcrossPages")},get checked(){return n().allowBreakAcrossPages},onChange:e=>r("allowBreakAcrossPages",e),"data-testid":"editor-table-properties-allow-break"}),wt(Be,{get label(){return t("table.hiddenRow")},get checked(){return n().hiddenRow},onChange:e=>r("hiddenRow",e),"data-testid":"editor-table-properties-hidden-row"})]}}),null),o;var o}var Eh=/*#__PURE__*/qn("<div class=oasis-editor-table-properties-panel>");function Dh(e){const t=D(),n=e.ctrl.set;return r=Eh(),Ue(r,wt(d,{container:!0,spacing:1.5,get children(){return wt(d,{size:{xs:12,md:6},get children(){return Ah(t("table.columnWidth"),()=>e.ctrl.form.columnWidth,e=>n("columnWidth",e),"editor-table-properties-column-width")}})}})),r;var r}var Lh=/*#__PURE__*/qn("<div class=oasis-editor-table-properties-cell-preview data-testid=editor-table-properties-cell-preview>"),Nh=/*#__PURE__*/qn("<div class=oasis-editor-table-properties-panel>");function zh(e){const t=D(),n=()=>e.ctrl.form,r=e.ctrl.set,o=ur(()=>{const e=Ph(n().borderStyle,n().borderWidth,n().borderColor),t=e?`${e.width}pt ${e.type} ${e.color}`:void 0;return{"background-color":n().shading.trim()||void 0,"border-top":t&&n().borderTop?t:"1px solid #dadce0","border-right":t&&n().borderRight?t:"1px solid #dadce0","border-bottom":t&&n().borderBottom?t:"1px solid #dadce0","border-left":t&&n().borderLeft?t:"1px solid #dadce0"}}),a=()=>"none"===n().borderStyle;return i=Nh(),Ue(i,wt(d,{container:!0,spacing:1.5,get children(){return[wt(d,{size:{xs:12,md:4},get children(){return Ah(t("table.cellWidth"),()=>n().cellWidth,e=>r("cellWidth",e),"editor-table-properties-cell-width")}}),wt(d,{size:{xs:12,md:4},get children(){return wt(Cr,{get label(){return t("table.verticalAlignment")},get value(){return n().cellVerticalAlign},onChange:e=>r("cellVerticalAlign",e),"data-testid":"editor-table-properties-cell-valign",get options(){return[{value:"",label:t("table.inherit")},{value:"top",label:t("table.valignTop")},{value:"middle",label:t("table.valignMiddle")},{value:"bottom",label:t("table.valignBottom")}]}})}}),wt(d,{size:{xs:12,md:4},get children(){return wt(Cr,{get label(){return t("table.textDirection")},get value(){return n().cellTextDirection},onChange:e=>r("cellTextDirection",e),"data-testid":"editor-table-properties-cell-direction",get options(){return[{value:"",label:t("table.inherit")},{value:"lrTb",label:"lrTb"},{value:"tbRl",label:"tbRl"},{value:"btLr",label:"btLr"},{value:"lrTbV",label:"lrTbV"},{value:"tbRlV",label:"tbRlV"}]}})}})]}}),null),Ue(i,wt(vt,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("table.options")},get children(){return wt(ln,{class:"oasis-editor-dialog-style-row",direction:"row",spacing:1,get children(){return[wt(Be,{get label(){return t("table.noWrap")},get checked(){return n().cellNoWrap},onChange:e=>r("cellNoWrap",e),"data-testid":"editor-table-properties-cell-nowrap"}),wt(Be,{get label(){return t("table.fitText")},get checked(){return n().cellFitText},onChange:e=>r("cellFitText",e),"data-testid":"editor-table-properties-cell-fit-text"}),wt(Be,{get label(){return t("table.hideMark")},get checked(){return n().cellHideMark},onChange:e=>r("cellHideMark",e),"data-testid":"editor-table-properties-cell-hide-mark"})]}})}}),null),Ue(i,wt(vt,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("table.cellMargins")},get children(){return wt(d,{container:!0,spacing:1.5,get children(){return[wt(d,{size:{xs:12,md:3},get children(){return Ah(t("paragraph.borderSideTop"),()=>n().marginTop,e=>r("marginTop",e),"editor-table-properties-margin-top")}}),wt(d,{size:{xs:12,md:3},get children(){return Ah(t("paragraph.borderSideRight"),()=>n().marginRight,e=>r("marginRight",e),"editor-table-properties-margin-right")}}),wt(d,{size:{xs:12,md:3},get children(){return Ah(t("paragraph.borderSideBottom"),()=>n().marginBottom,e=>r("marginBottom",e),"editor-table-properties-margin-bottom")}}),wt(d,{size:{xs:12,md:3},get children(){return Ah(t("paragraph.borderSideLeft"),()=>n().marginLeft,e=>r("marginLeft",e),"editor-table-properties-margin-left")}})]}})}}),null),Ue(i,wt(vt,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("paragraph.bordersSection")},get children(){return[wt(d,{container:!0,spacing:1.5,get children(){return[wt(d,{size:{xs:12,md:3},get children(){return wt(Cr,{get label(){return t("paragraph.borderStyleLabel")},get value(){return n().borderStyle},onChange:e=>{const t=e;r("borderStyle",t),"none"===t?(r("borderTop",!1),r("borderRight",!1),r("borderBottom",!1),r("borderLeft",!1),r("borderStart",!1),r("borderEnd",!1),r("borderTlBr",!1),r("borderTrBl",!1)):n().borderTop||n().borderRight||n().borderBottom||n().borderLeft||(r("borderTop",!0),r("borderRight",!0),r("borderBottom",!0),r("borderLeft",!0))},"data-testid":"editor-table-properties-border-style",get options(){return[{value:"none",label:t("paragraph.borderNone")},{value:"solid",label:t("paragraph.borderSolid")},{value:"dashed",label:t("paragraph.borderDashed")},{value:"dotted",label:t("paragraph.borderDotted")}]}})}}),wt(d,{size:{xs:12,md:3},get children(){return Ah(t("paragraph.borderWidthLabel"),()=>n().borderWidth,e=>r("borderWidth",e),"editor-table-properties-border-width",a())}}),wt(d,{size:{xs:12,md:3},get children(){return wt(A,{get label(){return t("paragraph.borderColorLabel")},get value(){return n().borderColor||"#000000"},get disabled(){return a()},onChange:e=>r("borderColor",e),"data-testid":"editor-table-properties-border-color"})}}),wt(d,{size:{xs:12,md:3},get children(){return wt(A,{get label(){return t("paragraph.shadingLabel")},get value(){return n().shading||"#ffffff"},onChange:e=>r("shading",e),"data-testid":"editor-table-properties-shading"})}})]}}),wt(ln,{class:"oasis-editor-dialog-style-row",direction:"row",spacing:1,get children(){return[wt(Be,{get label(){return t("paragraph.borderSideTop")},get checked(){return n().borderTop},get disabled(){return a()},onChange:e=>r("borderTop",e),"data-testid":"editor-table-properties-border-top"}),wt(Be,{get label(){return t("paragraph.borderSideRight")},get checked(){return n().borderRight},get disabled(){return a()},onChange:e=>r("borderRight",e),"data-testid":"editor-table-properties-border-right"}),wt(Be,{get label(){return t("paragraph.borderSideBottom")},get checked(){return n().borderBottom},get disabled(){return a()},onChange:e=>r("borderBottom",e),"data-testid":"editor-table-properties-border-bottom"}),wt(Be,{get label(){return t("paragraph.borderSideLeft")},get checked(){return n().borderLeft},get disabled(){return a()},onChange:e=>r("borderLeft",e),"data-testid":"editor-table-properties-border-left"}),wt(Be,{get label(){return t("table.borderStart")},get checked(){return n().borderStart},get disabled(){return a()},onChange:e=>r("borderStart",e),"data-testid":"editor-table-properties-border-start"}),wt(Be,{get label(){return t("table.borderEnd")},get checked(){return n().borderEnd},get disabled(){return a()},onChange:e=>r("borderEnd",e),"data-testid":"editor-table-properties-border-end"}),wt(Be,{get label(){return t("table.borderTlBr")},get checked(){return n().borderTlBr},get disabled(){return a()},onChange:e=>r("borderTlBr",e),"data-testid":"editor-table-properties-border-tlbr"}),wt(Be,{get label(){return t("table.borderTrBl")},get checked(){return n().borderTrBl},get disabled(){return a()},onChange:e=>r("borderTrBl",e),"data-testid":"editor-table-properties-border-trbl"})]}}),(e=Lh(),Pt(t=>Tn(e,o(),t)),e)];var e}}),null),i;var i}var $h=/*#__PURE__*/qn("<div class=oasis-editor-table-properties-panel>");function Hh(e){const t=D(),n=()=>e.ctrl.form,r=e.ctrl.set;return o=$h(),Ue(o,wt(pe,{get label(){return t("table.altTitle")},get value(){return n().altTitle},onChange:e=>r("altTitle",e),"data-testid":"editor-table-properties-alt-title"}),null),Ue(o,wt(C,{class:"oasis-editor-dialog-input-group",get label(){return t("table.altDescription")},controlClass:"oasis-editor-table-properties-textarea",get value(){return n().altDescription},onChange:e=>r("altDescription",e),"data-testid":"editor-table-properties-alt-description"}),null),o;var o}function Wh(e){const t=D(),n=Rh(e);return wt(F,{get isOpen(){return e.isOpen},get title(){return t("table.propertiesTitle")},get onClose(){return e.onClose},size:"lg",class:"oasis-editor-table-properties-dialog",bodyClass:"oasis-editor-table-properties-body",get footer(){return wt(Nm,{get onCancel(){return e.onClose},get onConfirm(){return n.handleApply},get cancelLabel(){return t("generic.cancel")},get confirmLabel(){return t("generic.ok")},cancelTestId:"editor-table-properties-cancel",confirmTestId:"editor-table-properties-apply"})},get children(){return wt(me,{get value(){return n.form.activeTab},onChange:e=>n.set("activeTab",e),get ariaLabel(){return t("table.propertiesTitle")},class:"oasis-editor-table-properties-tabs",get items(){return[{id:"table",label:t("table.tabTable"),testId:"editor-table-properties-tab-table",panel:wt(Oh,{ctrl:n})},{id:"row",label:t("table.tabRow"),testId:"editor-table-properties-tab-row",panel:wt(Fh,{ctrl:n})},{id:"column",label:t("table.tabColumn"),testId:"editor-table-properties-tab-column",panel:wt(Dh,{ctrl:n})},{id:"cell",label:t("table.tabCell"),testId:"editor-table-properties-tab-cell",panel:wt(zh,{ctrl:n})},{id:"altText",label:t("table.tabAltText"),testId:"editor-table-properties-tab-alt-text",panel:wt(Hh,{ctrl:n})}]}})}})}var jh=/*#__PURE__*/qn("<p data-testid=editor-new-document-message>");function Uh(e){const t=D();return wt(F,{get isOpen(){return e.isOpen},get title(){return t("dialog.newDocument.title")},get onClose(){return e.onClose},closeOnOverlayClick:!1,size:"sm",get footer(){return wt(Nm,{get onCancel(){return e.onClose},get onConfirm(){return e.onConfirm},get cancelLabel(){return t("generic.cancel")},get confirmLabel(){return t("dialog.newDocument.discard")},cancelTestId:"editor-new-document-cancel",confirmTestId:"editor-new-document-discard"})},get children(){var e=jh();return Ue(e,()=>t("dialog.newDocument.message")),e}})}function Vh(e){const t=D(),n=()=>"accept"===e.action;return wt(F,{get isOpen(){return e.isOpen},get title(){return t(n()?"review.bulkAcceptTitle":"review.bulkRejectTitle")},get onClose(){return e.onClose},closeOnOverlayClick:!1,size:"sm",testId:"editor-revision-bulk-dialog",get footer(){return wt(Nm,{get onCancel(){return e.onClose},get onConfirm(){return e.onConfirm},get cancelLabel(){return t("generic.cancel")},get confirmLabel(){return t(n()?"toolbar.acceptAll":"toolbar.rejectAll")},cancelTestId:"editor-revision-bulk-cancel",confirmTestId:"editor-revision-bulk-confirm"})},get children(){return wt(Pn,{as:"p","data-testid":"editor-revision-bulk-message",get children(){return t(n()?"review.bulkAcceptMessage":"review.bulkRejectMessage",[e.count])}})}})}var Kh=/*#__PURE__*/qn("<div class=oasis-editor-symbol-dialog-controls><label class=oasis-editor-symbol-dialog-field><span></span><select data-testid=editor-symbol-dialog-font></select></label><label class=oasis-editor-symbol-dialog-field><span></span><select data-testid=editor-symbol-dialog-category><option value=all>"),_h=/*#__PURE__*/qn("<div class=oasis-editor-symbol-dialog-recent><span></span><div class=oasis-editor-symbol-dialog-recent-list>"),Xh=/*#__PURE__*/qn("<div class=oasis-editor-symbol-dialog-layout><div class=oasis-editor-symbol-dialog-grid role=grid></div><aside class=oasis-editor-symbol-dialog-preview><span class=oasis-editor-symbol-dialog-preview-label></span><span class=oasis-editor-symbol-dialog-preview-character data-testid=editor-symbol-dialog-preview></span><label class=oasis-editor-symbol-dialog-field><span></span><input data-testid=editor-symbol-dialog-code></label><p class=oasis-editor-symbol-dialog-help>"),qh=/*#__PURE__*/qn("<option>"),Gh=/*#__PURE__*/qn("<button type=button class=oasis-editor-symbol-dialog-tile>"),Yh=/*#__PURE__*/qn("<button type=button class=oasis-editor-symbol-dialog-tile role=gridcell>"),Zh=["Segoe UI Symbol","Arial Unicode MS","Cambria Math","Times New Roman"];function Jh(e){const t=D(),[r,o]=Nt("common"),[a,i]=Nt(Tt[0]),[s,l]=Nt(Zh[0]),[c,d]=Nt(Tt[0].codePoint),u=ur(()=>(e.isOpen,gn())),p=ur(()=>"all"===r()?Lt.flatMap(e=>e.entries):Lt.find(e=>e.id===r())?.entries??Tt),f=e=>{i(e),d(e.codePoint)},g=()=>{const t=a().character;t&&(dr(t),e.onInsert(t,s()),e.onClose())};return wt(F,{get isOpen(){return e.isOpen},get title(){return t("dialog.symbol.title")},get onClose(){return e.onClose},class:"oasis-editor-symbol-dialog",bodyClass:"oasis-editor-symbol-dialog-body",size:"lg",closeOnOverlayClick:!1,get footer(){return[wt(bn,{variant:"secondary",get onClick(){return e.onClose},"data-testid":"editor-symbol-dialog-cancel",get children(){return t("generic.cancel")}}),wt(bn,{variant:"primary",onClick:g,"data-testid":"editor-symbol-dialog-insert",get children(){return t("dialog.symbol.insert")}})]},get children(){return[(I=Kh(),S=I.firstChild,C=S.firstChild,k=C.nextSibling,T=S.nextSibling.firstChild,P=T.nextSibling,R=P.firstChild,Ue(C,()=>t("dialog.symbol.font")),k.addEventListener("change",e=>{l(e.currentTarget.value)}),Ue(k,wt(dt,{each:Zh,children:e=>{return(t=qh()).value=e,Ue(t,e),t;var t}})),Ue(T,()=>t("dialog.symbol.subset")),P.addEventListener("change",e=>{o(e.currentTarget.value)}),Ue(R,()=>t("symbols.category.all")),Ue(P,wt(dt,{each:Lt,children:e=>{return n=qh(),Ue(n,()=>t(e.labelKey)),Pt(()=>n.value=e.id),n;var n}}),null),Pt(()=>k.value=s()),Pt(()=>P.value=r()),I),(e=Xh(),m=e.firstChild,h=m.nextSibling.firstChild,b=h.nextSibling,y=b.nextSibling,v=y.firstChild,x=v.nextSibling,w=y.nextSibling,Ue(m,wt(Bn,{get when(){return u().length>0},get children(){var e=_h(),r=e.firstChild,o=r.nextSibling;return Ue(r,()=>t("dialog.symbol.recent")),Ue(o,wt(dt,{get each(){return u()},children:e=>{return(t=Gh()).$$click=()=>f(e),Ue(t,()=>e.character),Pt(r=>{var o=`${e.character} (${e.codePoint})`,a=`${e.character} (${e.codePoint})`;return o!==r.e&&n(t,"title",r.e=o),a!==r.t&&n(t,"aria-label",r.t=a),r},{e:void 0,t:void 0}),t;var t}})),e}}),null),Ue(m,wt(dt,{get each(){return p()},children:e=>{return(t=Yh()).$$dblclick=g,t.$$click=()=>f(e),Ue(t,()=>e.character),Pt(r=>{var o=!(a().character!==e.character),i=`${e.character} (${e.codePoint})`,s=`${e.character} (${e.codePoint})`,l=`editor-symbol-dialog-${e.codePoint.replace(/[^A-Z0-9]/g,"-")}`;return o!==r.e&&t.classList.toggle("oasis-editor-symbol-dialog-tile-active",r.e=o),i!==r.t&&n(t,"title",r.t=i),s!==r.a&&n(t,"aria-label",r.a=s),l!==r.o&&n(t,"data-testid",r.o=l),r},{e:void 0,t:void 0,a:void 0,o:void 0}),t;var t}}),null),Ue(h,()=>t("dialog.symbol.preview")),Ue(b,()=>a().character),Ue(v,()=>t("dialog.symbol.code")),x.$$input=e=>(e=>{d(e);const t=e.trim().toUpperCase().replace(/^U\+/,""),n=Number.parseInt(t,16);!Number.isFinite(n)||n<0||n>1114111||i({character:String.fromCodePoint(n),codePoint:`U+${n.toString(16).toUpperCase().padStart(4,"0")}`})})(e.currentTarget.value),n(x,"spellcheck",!1),Ue(w,()=>t("dialog.symbol.doubleClickHelp")),Pt(e=>{var r=t("dialog.symbol.title"),o=s();return r!==e.e&&n(m,"aria-label",e.e=r),o!==e.t&&Ot(b,"font-family",e.t=o),e},{e:void 0,t:void 0}),Pt(()=>x.value=c()),e)];var e,m,h,b,y,v,x,w,I,S,C,k,T,P,R}})}qe(["input","click","dblclick"]);var Qh=/*#__PURE__*/qn("<div class=oasis-editor-equation-editor><div class=oasis-editor-equation-palette></div><label class=oasis-editor-equation-linear><span></span><textarea data-testid=editor-equation-linear></textarea></label><div class=oasis-editor-equation-preview aria-live=polite data-testid=editor-equation-preview>"),eb=/*#__PURE__*/qn("<button type=button data-testid=editor-equation-template>"),tb=[["\\frac{□}{□}","\\frac{a}{b}"],["\\sqrt{□}","\\sqrt{x}"],["x^□","x^{2}"],["x_□","x_{i}"],["∑","\\sum_{i=1}^{n} i"],["∫","∫ f(x) dx"],["[ ]","(a+b)"],["[a b]","\\matrix{a & b \\ c & d}"]];function nb(e){const t=D(),[r,o]=Nt(""),[a,i]=Nt(Lr);mn(()=>{if(!e.isOpen)return;const t=e.initial??Lr;i(t),o(At(t))});const s=e=>{o(e),i(fr(e))};return wt(F,{get isOpen(){return e.isOpen},get title(){return t("dialog.equation.title")},get onClose(){return e.onClose},size:"lg",closeOnOverlayClick:!1,class:"oasis-editor-equation-dialog",get footer(){return[wt(bn,{variant:"secondary",get onClick(){return e.onClose},get children(){return t("generic.cancel")}}),wt(bn,{variant:"primary",onClick:()=>e.onApply(a()),"data-testid":"editor-equation-apply",get children(){return t("dialog.equation.insert")}})]},get children(){var e=Qh(),o=e.firstChild,i=o.nextSibling,l=i.firstChild,c=l.nextSibling,d=i.nextSibling;return Ue(o,wt(dt,{each:tb,children:([e,t])=>{return(n=eb()).$$click=()=>s(t),Ue(n,e),n;var n}})),Ue(l,()=>t("dialog.equation.linear")),c.$$input=e=>s(e.currentTarget.value),n(c,"spellcheck",!1),Ue(d,()=>At(a())||t("dialog.equation.empty")),Pt(()=>n(o,"aria-label",t("dialog.equation.structures"))),Pt(()=>c.value=r()),e}})}qe(["input","click"]);var rb=/*#__PURE__*/qn("<div class=oasis-editor-find-replace-dialog><div class=oasis-editor-fr-header></div><div class=oasis-editor-fr-body><div class=oasis-editor-fr-input-group><div class=oasis-editor-fr-input-wrapper></div></div><div class=oasis-editor-fr-input-group>");function ob(e){const t=D(),{fr:n}=e,r=e=>{n.isOpen()&&"Escape"===e.key&&n.setIsOpen(!1)},o=e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?n.findPrevious():n.findNext())};return ot(()=>{window.addEventListener("keydown",r,!0)}),Ut(()=>{window.removeEventListener("keydown",r,!0)}),wt(Bn,{get when(){return n.isOpen()},get children(){var e=rb(),r=e.firstChild,a=r.nextSibling,i=a.firstChild,s=i.firstChild,l=i.nextSibling;return e.$$keydown=o,Ue(r,wt(Pn,{get children(){return t("find.title")}}),null),Ue(r,wt(Gn,{class:"oasis-editor-fr-close",icon:"x",onClick:()=>n.setIsOpen(!1),get label(){return t("generic.close")}}),null),Ue(s,wt(pe,{type:"text",get placeholder(){return t("find.placeholder")},get value(){return n.searchTerm()},onChange:e=>n.setSearchTerm(e),autofocus:!0,controlClass:"oasis-editor-fr-input"}),null),Ue(s,wt(oe,{class:"oasis-editor-fr-counter",get children(){return Qe(()=>n.matches().length>0)()?`${n.currentIndex()+1} / ${n.matches().length}`:t("find.noMatches")}}),null),Ue(i,wt(ln,{class:"oasis-editor-fr-actions",direction:"row",spacing:1,get children(){return[wt(Gn,{get onClick(){return n.findPrevious},get disabled(){return 0===n.matches().length},icon:"chevron-up",get label(){return t("find.prevTooltip")}}),wt(Gn,{get onClick(){return n.findNext},get disabled(){return 0===n.matches().length},icon:"chevron-down",get label(){return t("find.nextTooltip")}})]}}),null),Ue(l,wt(pe,{type:"text",get placeholder(){return t("replace.placeholder")},get value(){return n.replaceTerm()},onChange:e=>n.setReplaceTerm(e),controlClass:"oasis-editor-fr-input"}),null),Ue(l,wt(ln,{class:"oasis-editor-fr-actions",direction:"row",spacing:1,get children(){return[wt(Gn,{class:"oasis-editor-fr-btn-text",get onClick(){return n.replace},get disabled(){return 0===n.matches().length},get children(){return t("replace.one")}}),wt(Gn,{class:"oasis-editor-fr-btn-text",get onClick(){return n.replaceAll},get disabled(){return 0===n.matches().length},get children(){return t("replace.allBtn")}})]}}),null),Ue(a,wt(ln,{class:"oasis-editor-fr-options",direction:"row",spacing:1,get children(){return[wt(Be,{class:"oasis-editor-fr-checkbox",get label(){return t("find.matchCase")},get checked(){return n.findOptions().matchCase},onChange:e=>n.setFindOptions({...n.findOptions(),matchCase:e})}),wt(Be,{class:"oasis-editor-fr-checkbox",get label(){return t("find.wholeWord")},get checked(){return n.findOptions().wholeWord},onChange:e=>n.setFindOptions({...n.findOptions(),wholeWord:e})})]}}),null),e}})}qe(["keydown"]);var ab=/*#__PURE__*/qn("<div class=oasis-editor-context-menu role=menu data-testid=editor-context-menu>"),ib=/*#__PURE__*/qn("<i>"),sb=/*#__PURE__*/qn("<span class=oasis-editor-context-menu-shortcut>"),lb=/*#__PURE__*/qn("<button type=button class=oasis-editor-context-menu-item role=menuitem><span class=oasis-editor-context-menu-label>"),cb=/*#__PURE__*/qn("<div class=oasis-editor-context-menu-separator>"),db=/*#__PURE__*/qn("<span aria-hidden=true style=visibility:hidden;flex-shrink:0>");function ub(e){let t;ir({refs:()=>[t],open:()=>e.isOpen,onDismiss:()=>e.onClose()});const r=n=>{e.isOpen&&(t&&n.target instanceof Node&&t.contains(n.target)||e.onClose())},o=()=>{e.isOpen&&e.onClose()};return ot(()=>{window.addEventListener("contextmenu",r,!0),window.addEventListener("scroll",o,!0),window.addEventListener("resize",o,!0)}),Ut(()=>{window.removeEventListener("contextmenu",r,!0),window.removeEventListener("scroll",o,!0),window.removeEventListener("resize",o,!0)}),mn(()=>{if(!e.isOpen||!t)return;const n=t.getBoundingClientRect(),r=Math.max(4,window.innerWidth-n.width-4),o=Math.max(4,window.innerHeight-n.height-4),a=Math.min(e.x,r),i=Math.min(e.y,o);t.style.left=`${a}px`,t.style.top=`${i}px`}),wt(Bn,{get when(){return e.isOpen},get children(){var r=ab();r.$$contextmenu=e=>e.preventDefault();return"function"==typeof t?Qt(t,r):t=r,Ue(r,wt(dt,{get each(){return e.items},children:t=>wt(Bn,{get when(){return"separator"!==t.type},get fallback(){return cb()},get children(){var r=lb(),o=r.firstChild;return r.$$click=()=>{t.disabled||(t.onSelect?.(),e.onClose())},Ue(r,wt(Bn,{get when(){return t.icon},get fallback(){return e=db(),Ue(e,wt(en,{size:16})),e;var e},get children(){var e=ib();return Pt(()=>n(e,"data-lucide",t.icon)),e}}),o),Ue(o,()=>t.label),Ue(r,wt(Bn,{get when(){return t.shortcut},get children(){var e=sb();return Ue(e,()=>t.shortcut),e}}),null),Pt(e=>{var o=t.disabled,a=t.testId;return o!==e.e&&(r.disabled=e.e=o),a!==e.t&&n(r,"data-testid",e.t=a),e},{e:void 0,t:void 0}),r}})})),Pt(t=>{var n=`${e.x}px`,o=`${e.y}px`;return n!==t.e&&Ot(r,"left",t.e=n),o!==t.t&&Ot(r,"top",t.t=o),t},{e:void 0,t:void 0}),r}})}function pb(e){const{linkDialog:t,setLinkDialog:n,imageAltDialog:r,setImageAltDialog:o,imageCaptionDialog:a,setImageCaptionDialog:i,contextMenu:s,fontDialog:l,setFontDialog:c,paragraphDialog:d,setParagraphDialog:u,tablePropertiesDialog:p,setTablePropertiesDialog:f,newDocumentDialog:g,setNewDocumentDialog:m,revisionBulkDialog:h,setRevisionBulkDialog:b,symbolDialog:y,setSymbolDialog:v,equationDialog:x,setEquationDialog:w}=e.dialogs;return[wt(Uh,{get isOpen(){return g().isOpen},onClose:()=>{m({isOpen:!1}),e.focusInput()},onConfirm:()=>{m({isOpen:!1}),e.confirmNewDocument()}}),wt(Vh,{get isOpen(){return h().isOpen},get action(){return h().action},get count(){return h().count},onClose:()=>{b({...h(),isOpen:!1}),e.focusInput()},onConfirm:()=>{const t=h().action;b({...h(),isOpen:!1}),e.applyBulkRevisions(t)}}),wt(Jh,{get isOpen(){return y().isOpen},onClose:()=>{v({isOpen:!1}),e.focusInput()},onInsert:(t,n)=>{v({isOpen:!1}),e.insertSymbol(t,n)}}),wt(nb,{get isOpen(){return x().isOpen},get initial(){return x().initial},onClose:()=>{w({isOpen:!1}),e.focusInput()},onApply:t=>{w({isOpen:!1}),e.applyEquation(t,x().targetRunId)}}),wt($m,{get isOpen(){return t().isOpen},get initialHref(){return t().initialHref},onClose:()=>{n({...t(),isOpen:!1}),e.focusInput()},onConfirm:t=>e.applyLinkCommand(t.trim()||null)}),wt(Hm,{get isOpen(){return r().isOpen},get initialAlt(){return r().initialAlt},onClose:()=>{o({...r(),isOpen:!1}),e.focusInput()},onConfirm:t=>e.applyImageAltCommand(t.trim())}),wt(Wm,{get isOpen(){return a().isOpen},get initialCaption(){return a().initialCaption},onClose:()=>{i({...a(),isOpen:!1}),e.focusInput()},onConfirm:t=>e.applyImageCaptionCommand(t.trim())}),wt(Vm,{get composer(){return e.commentComposer}}),wt(ob,{get fr(){return e.findReplace}}),wt(ph,{get isOpen(){return l().isOpen},get initial(){return l().initial},get familyOptions(){return e.fontFamilyOptions()},get sizeOptions(){return e.fontSizeOptions()},onClose:()=>{c({...l(),isOpen:!1}),e.focusInput()},get onApply(){return e.applyFontDialogValues}}),wt(kh,{get isOpen(){return d().isOpen},get initial(){return d().initial},onClose:()=>{u({...d(),isOpen:!1}),e.focusInput()},get onApply(){return e.applyParagraphDialogValues},get onSetDefault(){return e.setParagraphDialogDefault}}),wt(Wh,{get isOpen(){return p().isOpen},get initial(){return p().initial},onClose:()=>{f({...p(),isOpen:!1}),e.focusInput()},get onApply(){return e.applyTablePropertiesDialogValues}}),wt(ub,{get isOpen(){return s().isOpen},get x(){return s().x},get y(){return s().y},get items(){return e.contextMenuItems()},get onClose(){return e.closeContextMenu}})]}qe(["contextmenu","click"]);var fb=/*#__PURE__*/qn("<div class=oasis-editor-main-container><section class=oasis-editor-stage>");function gb(e){let t,n;const r=_n(),o=n=>{t=n,e.view.refs.onSurfaceRef?.(n)},a=t=>{n=t,e.view.refs.onViewportRef?.(t)},i=Z({state:e.runtime.state,documentLayout:e.view.documentLayout,surfaceRef:()=>t,viewportRef:()=>n,zoomFactor:e.view.layout.zoomFactor,snapshotProvider:r});return[wt(Bn,{get when(){return e.useComposedShell()},get children(){return(()=>{const t=e.shellComponent(),{runtime:n,chrome:r,view:o}=e;return wt(t,{get state(){return n.state()},get toolbarHost(){return n.toolbarHost},get runtimeEditor(){return n.runtimeEditor},get persistenceStatus(){return n.persistenceStatus},get toolbarRegistry(){return n.toolbarRegistry},get menuRegistry(){return n.menuRegistry},get showChrome(){return r.showChrome()},get showTitleBar(){return r.showTitleBar()},get showMenubar(){return r.showMenubar()},get showToolbar(){return r.showToolbar()},get showOutline(){return r.showOutline},get showRuler(){return r.showRuler()},get toolbarView(){return r.toolbarView()},get toolbarLayout(){return r.toolbarLayout()},get isReadOnly(){return o.isReadOnly()},get measuredBlockHeights(){return o.measuredBlockHeights},get measuredParagraphLayouts(){return o.measuredParagraphLayouts},get documentLayout(){return o.documentLayout},get viewportHeight(){return o.viewportHeight},get layout(){return o.layout},get overlays(){return o.overlays},get refs(){return o.refs},get surfaceHandlers(){return o.surfaceHandlers},get inputHandlers(){return o.inputHandlers},get fileHandlers(){return o.fileHandlers}})})()}}),wt(Bn,{get when(){return!e.useComposedShell()},get children(){return wt(zr,{get editor(){return e.runtime.runtimeEditor},get children(){var s=fb(),l=s.firstChild;return Ue(s,wt(Bn,{get when(){return e.chrome.showOutline()},get children(){return wt(_,{get state(){return e.runtime.state()},onNavigate:i,surfaceRef:()=>t,viewportRef:()=>n,get documentLayout(){return e.view.documentLayout},get zoomFactor(){return e.view.layout.zoomFactor},snapshotProvider:r})}}),l),Ue(l,wt(X,{get state(){return e.runtime.state},get layout(){return{...e.view.layout,documentLayout:e.view.documentLayout,measuredBlockHeights:e.view.measuredBlockHeights,measuredParagraphLayouts:e.view.measuredParagraphLayouts,readOnly:e.view.isReadOnly()}},get overlays(){return{...e.view.overlays,toolbarHost:e.runtime.toolbarHost,persistenceStatus:e.runtime.persistenceStatus}},get refs(){return{...e.view.refs,onSurfaceRef:o,onViewportRef:a}},get surfaceHandlers(){return e.view.surfaceHandlers},get inputHandlers(){return e.view.inputHandlers},get fileHandlers(){return e.view.fileHandlers}})),s}})}})]}var mb=/*#__PURE__*/qn("<div class=oasis-editor-welcome-overlay role=dialog aria-modal=true aria-labelledby=oasis-editor-welcome-title><div class=oasis-editor-welcome-card><h2 id=oasis-editor-welcome-title class=oasis-editor-welcome-title></h2><p class=oasis-editor-welcome-body></p><p class=oasis-editor-welcome-note></p><div class=oasis-editor-welcome-actions>");function hb(e){const t=D(),n=()=>{Pr(),de(),e.onClose()},r=()=>{I(!1),de(),e.onClose()};return wt(Bn,{get when(){return e.isOpen},get children(){var e=mb(),o=e.firstChild,a=o.firstChild,i=a.nextSibling,s=i.nextSibling,l=s.nextSibling;return Ue(o,wt(Ee,{height:72,class:"oasis-editor-welcome-mark"}),a),Ue(a,()=>t("welcome.title")),Ue(i,()=>t("welcome.body")),Ue(s,()=>t("welcome.note")),Ue(l,wt(bn,{variant:"secondary",onClick:r,"data-testid":"editor-welcome-skip",get children(){return t("welcome.skip")}}),null),Ue(l,wt(bn,{variant:"primary",onClick:n,"data-testid":"editor-welcome-enable",get children(){return t("welcome.enable")}}),null),e}})}function bb(e){switch(e){case"dashed":return[or(5),or(3)];case"dotted":return[or(1),or(3)];default:return}}async function yb(e,t,n,r,o,a,i,s){const l=t.rotation;l&&(e.saveGraphicsState(n.pageIndex),e.rotateAbout(n.pageIndex,or(r+a/2),or(o+i/2),l)),function(e,t,n,r,o,a,i){const s=O(n.shape?.preset,or(r),or(o),or(a),or(i)),l=n.shape?.fill,c=n.shape?.borderColor,d=n.shape?.borderWidthPt??(c?.75:0);e.drawPath(t,{segments:s,fill:l,stroke:c&&d>0?c:void 0,lineWidth:d})}(e,n.pageIndex,t,r,o,a,i),await async function(e,t,n,r,o,a,i,s){if(0===t.blocks.length)return;const l=function(e){return{left:e.body?.paddingLeft??0,top:e.body?.paddingTop??0,right:e.body?.paddingRight??0,bottom:e.body?.paddingBottom??0}}(t),c=r+l.left,d=o+l.top,u=Math.max(1,a-l.left-l.right),p=Math.max(1,i-l.top-l.bottom),f=Kn({blocks:t.blocks,pageSettings:{width:u,height:p,orientation:"portrait",margins:{top:0,right:0,bottom:0,left:0,header:0,footer:0,gutter:0}},maxPageHeight:p,styles:n.document.styles,pageOffset:n.pageIndex})[0]?.blocks??[];if(0===f.length)return;const g=Io(n.document);e.saveGraphicsState(n.pageIndex),e.clipRect(n.pageIndex,or(c),or(d),or(u),or(p));let m=d;for(const h of f){switch(h.sourceBlock.type){case"paragraph":h.layout&&await s.drawParagraph(e,n.pageIndex,h.sourceBlock,h.layout.lines,n.document,c,m,n.fontRegistry,g,s);break;case"table":await s.drawTableBlock(e,n.pageIndex,h,n.document,c,m,u,n.fontRegistry,g,s);break;default:Va(h.sourceBlock,"block")}m+=Math.max(0,h.estimatedHeight)}e.restoreGraphicsState(n.pageIndex)}(e,t,n,r,o,a,i,s),l&&e.restoreGraphicsState(n.pageIndex)}async function vb(e){const{writer:t,document:n,fontRegistry:r,pageIndex:o,lines:a,pageSettings:i,contentLeft:s,contentTop:l,contentWidth:c,paragraphTop:d,drawers:u}=e;for(const p of a){const a=new Map(p.slots.map(e=>[e.offset,e]));for(const f of p.fragments){const g=f.textBox;if(!g?.floating)continue;const m=Boolean(g.floating.behindDoc);if(e.layer&&"behind"===e.layer!==m)continue;const h=s+(a.get(f.startOffset)?.left??0),b=d+p.top,y=et({object:Ve(g),pageSettings:i,contentLeft:s,contentTop:l,contentWidth:c,paragraphTop:d,lineTop:b,anchorLeft:h});await yb(t,g,{document:n,fontRegistry:r,pageIndex:o},y.x,y.y,y.width,y.height,u)}}}var xb=/* @__PURE__ */new WeakMap;function wb(e){const t=/^data:([^;,]+)(;base64)?,(.*)$/i.exec(e);if(!t)return null;const n=t[1].toLowerCase(),r=Boolean(t[2]),o=t[3]??"";if(!r)return{mediaType:n,data:(new TextEncoder).encode(decodeURIComponent(o))};const a="function"==typeof atob?atob(o):Buffer.from(o,"base64").toString("binary");return{mediaType:n,data:Uint8Array.from(a,e=>e.charCodeAt(0))}}async function Ib(e,t,n){let r=e;r.startsWith("data:")||(r=await async function(e){if("function"!=typeof fetch)return null;const t=await fetch(e);if(!t.ok)return null;const n=await t.blob(),r=new Uint8Array(await n.arrayBuffer()),o=Array.from(r,e=>String.fromCharCode(e)).join(""),a="function"==typeof btoa?btoa(o):Buffer.from(r).toString("base64");return`data:${n.type||"application/octet-stream"};base64,${a}`}(r)??r);let o=wb(r);if(!o)return null;const a="undefined"!=typeof Image?await async function(e){return"undefined"==typeof Image?null:await new Promise(t=>{const n=new Image;n.crossOrigin="anonymous",n.onload=()=>t(n),n.onerror=()=>t(null),n.src=e})}(r):null,i=null!=a&&a.naturalWidth>0&&a.naturalHeight>0;if("image/jpeg"!==o.mediaType&&"image/jpg"!==o.mediaType){if(!i)return null;const e=function(e){if("undefined"==typeof document)return null;const t=document.createElement("canvas");t.width=e.naturalWidth,t.height=e.naturalHeight;const n=t.getContext("2d");return n?(n.fillStyle="#ffffff",n.fillRect(0,0,t.width,t.height),n.drawImage(e,0,0),t.toDataURL("image/jpeg",.92)):null}(a);if(o=e?wb(e):null,!o)return null}const s=i?a.naturalWidth:t,l=i?a.naturalHeight:n;return{width:Math.max(1,Math.round(s)),height:Math.max(1,Math.round(l)),data:o.data}}async function Sb(e,t,n){const r=Ia(t,n.src);if(!r)return null;let o=xb.get(e);o||(o=/* @__PURE__ */new Map,xb.set(e,o));const a=o.get(r);if(a)return a;const i=Ib(r,n.width,n.height).then(t=>t?e.registerImageResource({width:t.width,height:t.height,data:t.data,filter:"DCTDecode"}):null);return o.set(r,i),i}async function Cb(e,t,n,r,o,a,i,s){const l=await Sb(e,n,r);if(!l)return;const c=r.intrinsicWidth??r.width,d=r.intrinsicHeight??r.height,u=c/Math.max(1,d),p=i/Math.max(1,s);let f=o,g=a,m=i,h=s;"fit"===r.cropFit&&u>0&&(u>p?(h=i/u,g+=(s-h)/2):(m=s*u,f+=(i-m)/2));const b="fill"!==r.cropFit||r.crop?r.crop:(()=>{if(u>p){const e=p/u,t=Math.max(0,(1-e)/2);return{left:t,right:t}}if(u<p){const e=u/p,t=Math.max(0,(1-e)/2);return{top:t,bottom:t}}})(),y=r.cropShape?.preset,v=y?function(e,t,n,r,o,a){if(!a)return e;const i=t+r/2,s=n+o/2,l=a*Math.PI/180,c=(e,t)=>({x:i+(e-i)*Math.cos(l)-(t-s)*Math.sin(l),y:s+(e-i)*Math.sin(l)+(t-s)*Math.cos(l)});return e.map(e=>{if("close"===e.type)return e;if("cubic"===e.type){const t=c(e.x1,e.y1),n=c(e.x2,e.y2),r=c(e.x,e.y);return{type:"cubic",x1:t.x,y1:t.y,x2:n.x,y2:n.y,x:r.x,y:r.y}}const t=c(e.x,e.y);return{type:e.type,x:t.x,y:t.y}})}(O(y,o,a,i,s),o,a,i,s,r.rotation??0):null,x=r.transparency??0,w="fit"===r.cropFit&&Boolean(r.rotation);v&&(e.saveGraphicsState(t),e.clipPath(t,v)),w&&(e.saveGraphicsState(t),e.rotateAbout(t,o+i/2,a+s/2,r.rotation??0)),x>0&&e.saveGraphicsState(t),x>0&&e.setOpacity(t,1-Math.min(1,x)),e.drawImage(t,{resourceName:l,x:f,y:g,width:m,height:h,rotation:w?void 0:r.rotation,crop:b}),x>0&&e.restoreGraphicsState(t),w&&e.restoreGraphicsState(t),v&&e.restoreGraphicsState(t);const I=r.border;if(!I)return;const S=r.rotation;S&&!v&&(e.saveGraphicsState(t),e.rotateAbout(t,o+i/2,a+s/2,S));const C=B(I.dash);v?e.drawPath(t,{segments:v,stroke:I.color,lineWidth:I.widthPt??1}):e.drawRect(t,{x:o,y:a,width:i,height:s,stroke:I.color,lineWidth:I.widthPt??1,...C.length>0?{dashArray:C}:{}}),S&&!v&&e.restoreGraphicsState(t)}function kb(e,t){const n=new Map(e.slots.map(e=>[e.offset,e])),r=[];for(const o of t.chars){if("\n"===o.char||"\t"===o.char)continue;const e=n.get(o.paragraphOffset);e&&r.push({char:o.char,left:e.left,offset:o.paragraphOffset})}return r}function Tb(e,t,n){const r=kb(e,t);if(0===r.length)return null;const o=new Map(e.slots.map(e=>[e.offset,e])),a=r[0],i=r[r.length-1],s=o.get(i.offset+1);return{left:a.left,right:s?.left??i.left+.55*n}}function Pb(e,t,n,r,o,a,i){const s=Tb(e,t,n.fontSize??14.6667);return s?{x:or(r+s.left),y:or(o+e.top+a),width:or(Math.max(0,s.right-s.left)),height:or(Math.max(2,e.height-i))}:null}function Rb(e,t,n,r,o,a,i){const s=i.textFill;if(!s||"gradient"!==s.type||s.stops.length<2)return;const l=Tb(n,r,i.fontSize??14.6667);if(!l)return;const c=o+l.left,d=o+l.right,u=a+n.top,p=a+n.top+n.height,f=ne(c,u,d,p,s.angle??0);return e.registerAxialGradient(t,{x0:or(f.x0),y0:or(f.y0),x1:or(f.x1),y1:or(f.y1),stops:s.stops.map(e=>({offset:e.position,color:e.color}))})??void 0}function Ab(e,t,n,r,o,a,i){const s=w(i),c=(o,i)=>{e.drawLine(t,{x1:or(n),y1:or(o),x2:or(r),y2:or(o),stroke:a,lineWidth:or(s),dashArray:i})};if(h(i))return c(o-l),void c(o+l);wr(i)?function(e,t,n,r,o,a,i){let s=n,l=o;for(let c=n;c<=r;c+=1){const r=o+Math.sin((c-n)/4*Math.PI)*Ce;e.drawLine(t,{x1:or(s),y1:or(l),x2:or(c),y2:or(r),stroke:a,lineWidth:or(i)}),s=c,l=r}}(e,t,n,r,o,a,s):c(o,T(i))}function Mb(e,t,n,r,o,a,i){const s=new Map(n.slots.map(e=>[e.offset,e]));for(const l of r.chars){if("\t"!==l.char)continue;const r=s.get(l.paragraphOffset),c=s.get(l.paragraphOffset+1);if(!r||!c)continue;const d=n.resolvedTabs?.[l.paragraphOffset]?.leader;if(!d||c.left<=r.left+2)continue;const u="underscore"===d?a+2:a;e.drawLine(t,{x1:or(o+r.left),y1:or(u),x2:or(o+c.left),y2:or(u),stroke:i,lineWidth:or("heavy"===d?1.5:1),dashArray:"dot"===d||"middleDot"===d?[1,3]:"hyphen"===d?[5,3]:void 0})}}function Ob(e,t){const n=Ca(xa(e));if(!n)return e;const r=Math.max(0,Math.min(1,t));return ii(255+(n[0]-255)*r,255+(n[1]-255)*r,255+(n[2]-255)*r)}function Bb(e,t,n){const{writer:r,pageIndex:o,baselineY:a,fontSizePt:i,mainColor:s,gradientShadingName:l,styles:c,baseTextOptions:d}=e,u=or(1);if(c.emboss||c.imprint){const e=c.imprint?1:-1;r.drawText(o,{...d,x:or(t)+u*e,y:or(a)+u*e,text:n,color:"#BFBFBF"})}if(c.glow){const e=c.glow,i=.5*or(e.radiusPt*Ho),s=Ob(e.color,.4*(e.alpha??.5)),l=[[i,0],[-i,0],[0,i],[0,-i],[.7*i,.7*i],[.7*-i,.7*i],[.7*i,.7*-i],[.7*-i,.7*-i]];for(const[c,u]of l)r.drawText(o,{...d,x:or(t)+c,y:or(a)+u,text:n,color:s})}if(c.textShadow){const e=c.textShadow,i=e.dirDeg*Math.PI/180,s=or(e.distPt*Ho);r.drawText(o,{...d,x:or(t)+Math.cos(i)*s,y:or(a)+Math.sin(i)*s,text:n,color:e.color})}else c.shadow&&r.drawText(o,{...d,x:or(t)+u,y:or(a)+u,text:n,color:"#808080"});if(c.reflection){const e=c.reflection,l=Ob(s,.6*((e.startAlpha+e.endAlpha)/2));r.drawText(o,{...d,x:or(t),y:or(a)+or(e.distPt*Ho)+i,text:n,color:l})}const p=c.textOutline;r.drawText(o,{...d,x:or(t),y:or(a),text:n,color:s,...l?{gradientShadingName:l}:p?{renderMode:2,strokeColor:p.color??s,strokeWidth:p.widthPt}:{renderMode:c.outline?1:0}})}async function Fb(e){for(const t of e.lines){const n=new Map(t.slots.map(e=>[e.offset,e]));for(const r of t.fragments){const o=r.image;if(!o?.floating)continue;const a=Boolean(o.floating.behindDoc);if("behind"===e.layer!==a)continue;const i=n.get(r.startOffset),s=et({object:Ge(o),pageSettings:e.pageSettings,contentLeft:e.contentLeft,contentTop:e.contentTop,contentWidth:e.contentWidth,paragraphTop:e.paragraphTop,lineTop:e.paragraphTop+t.top,anchorLeft:e.contentLeft+(i?.left??0)});await Cb(e.writer,e.pageIndex,e.document,o,or(s.x),or(s.y),or(s.width),or(s.height))}}}function Eb(e,t,n,r,o,a,i,s){const l=Tb(n,r,i.fontSize??14.6667);if(!l)return;const c=a+an(s,n.top,n.height),d=o+l.left,u=o+l.right,p="underline"===s?i.underlineColor??i.color??"#000000":i.color??"#000000";if("strike"!==s)return"doubleStrike"===s?(e.drawLine(t,{x1:or(d),y1:or(c-un),x2:or(u),y2:or(c-un),stroke:p,lineWidth:or(1)}),void e.drawLine(t,{x1:or(d),y1:or(c+un),x2:or(u),y2:or(c+un),stroke:p,lineWidth:or(1)})):void Ab(e,t,d,u,c,p,i.underlineStyle);e.drawLine(t,{x1:or(d),y1:or(c),x2:or(u),y2:or(c),stroke:p,lineWidth:or(1)})}async function Db(e,t,n,r,o,a,i,s,l,c){if(o.opaque){const n=r.slots.find(e=>e.offset===o.startOffset);if(!n)return;const a=i+n.left,l=s+r.top+r.height-o.opaque.height,c=o.opaque.width,d=o.opaque.height;for(const[r,o,i,s]of[[a,l,a+c,l],[a+c,l,a+c,l+d],[a+c,l+d,a,l+d],[a,l+d,a,l],[a,l,a+c,l+d]])e.drawLine(t,{x1:or(r),y1:or(o),x2:or(i),y2:or(s),stroke:"#64748b",lineWidth:.75});return}if(o.image){if(o.image.floating)return;const n=r.slots.find(e=>e.offset===o.startOffset)??r.slots.find(e=>e.offset>=o.startOffset);if(!n)return;return void(await Cb(e,t,a,o.image,or(i+n.left),or(s+r.top+r.height-o.image.height),or(o.image.width),or(o.image.height)))}if(o.textBox){if(o.textBox.floating)return;const n=r.slots.find(e=>e.offset===o.startOffset)??r.slots.find(e=>e.offset>=o.startOffset);if(!n)return;return void(await yb(e,o.textBox,{document:a,fontRegistry:l,pageIndex:t},i+n.left,s+r.top+r.height-o.textBox.height,o.textBox.width,o.textBox.height,c))}if(o.math){const c=r.slots.find(e=>e.offset===o.startOffset)??r.slots.find(e=>e.offset>=o.startOffset);if(!c)return;const d=pi(o.styles,n.style?.styleId,a.styles),u=l.resolveFontFace({fontFamily:"Cambria Math",bold:!1,italic:!1});return void e.drawText(t,{x:or(i+c.left),y:or(s+r.top+r.height*yr),text:yn(o.math),fontSize:kt(d),color:d.color??"#000000",fontResourceName:u.writerResourceName})}const d=pi(o.styles,n.style?.styleId,a.styles);if(d.hidden)return;const u=l.resolveFontFace({fontFamily:d.fontFamily,bold:d.bold,italic:d.italic}),p=kt(d),f=(d.baselineShift??0)*Ho,g=ti(n.style,a.styles),m=yt(g.textAlignment,d.fontSize??14.6667,r.height),h=s+r.top+r.height*yr-f+m,b=kb(r,o),y=b.map(e=>Wn(e.char,d)).join("");if(0===b.length||0===y.length)return void Mb(e,t,r,o,i,h,d.color??"#000000");!function(e,t,n,r,o,a,i){if(!i.link)return;const s=Tb(n,r,i.fontSize??14.6667);if(!s||s.right<=s.left)return;const l=i.link.startsWith("#");e.addLinkAnnotation(t,{x:or(o+s.left),y:or(a+n.top),width:or(s.right-s.left),height:or(n.height),...l?{destName:i.link.slice(1)}:{uri:i.link}})}(e,t,r,o,i,s,d),function(e,t,n,r,o,a,i){if(!i.shading)return;const s=Pb(n,r,i,o,a,2,4);s&&e.drawRect(t,{...s,fill:i.shading})}(e,t,r,o,i,s,d),function(e,t,n,r,o,a,i){if(!i.highlight)return;const s=Pb(n,r,i,o,a,2,4);s&&e.drawRect(t,{...s,fill:i.highlight})}(e,t,r,o,i,s,d),function(e,t,n,r,o,a,i){const s=i.textBorder;if(!s||"none"===s.type||s.width<=0)return;const l=Pb(n,r,i,o,a,1,2);l&&e.drawRect(t,{...l,stroke:s.color,lineWidth:or(Math.max(.5,s.width*Ho))})}(e,t,r,o,i,s,d),Mb(e,t,r,o,i,h,d.color??"#000000");const v=ti(n.style,a.styles).align??"left",x=Ae(d,kt(d)),w={fontSize:p,bold:d.bold,italic:d.italic,fontResourceName:u.writerResourceName,characterSpacing:d.characterSpacing??0,horizontalScale:d.characterScale??100,fontFeatures:x};!function(e,t,n,r,o,a,i){const s="justify"===i?function(e){const t=[];let n=[];for(const r of e){const e=n[n.length-1];e&&r.offset>e.offset+1&&(t.push(n),n=[])," "!==r.char?n.push(r):n.length>0&&(t.push(n),n=[])}return n.length>0&&t.push(n),t}(t):function(e){const t=[];let n=[];for(const r of e){const e=n[n.length-1];e&&r.offset>e.offset+1&&(t.push(n),n=[]),n.push(r)}return n.length>0&&t.push(n),t}(t);for(const l of s){let t=[],o=!1;const a=()=>{if(0===t.length)return;const a=t.map(e=>Wn(e.char,r)).join("");if(a.length>0){const r=o?.8*e.fontSizePt:e.fontSizePt;Bb({...e,fontSizePt:r,baseTextOptions:{...e.baseTextOptions,fontSize:r}},n+t[0].left,a)}t=[]};for(const e of l){const n=Boolean(r.smallCaps&&Ht(e.char));t.length>0&&n!==o&&a(),o=n,t.push(e)}a()}if(o.trailingHyphen&&a.endOffset>=o.endOffset){const t=o.slots.find(e=>e.offset===o.endOffset)??o.slots[o.slots.length-1];t&&Bb(e,n+t.left,"-")}}({writer:e,pageIndex:t,baselineY:h,fontSizePt:p,mainColor:"solid"===d.textFill?.type?d.textFill.color:"gradient"===d.textFill?.type&&d.textFill.stops[0]?d.textFill.stops[0].color:d.color??"#000000",gradientShadingName:Rb(e,t,r,o,i,s,d),styles:d,baseTextOptions:w},b,i,d,r,o,v),d.underline&&Eb(e,t,r,o,i,s,d,"underline"),d.strike&&Eb(e,t,r,o,i,s,d,"strike"),d.doubleStrike&&Eb(e,t,r,o,i,s,d,"doubleStrike"),d.emphasisMark&&function(e,t,n,r,o,a,i){const s=i.emphasisMark;if(!s||"none"===s)return;const l=Tr[s];if(!l)return;const c=kb(n,r),d="underDot"===s,u=Math.max(4,.35*n.height),p=d?a+n.top+n.height+u:a+n.top+u;for(let f=0;f<c.length;f+=1){const r=c[f];if(" "===r.char||"\t"===r.char||"\n"===r.char)continue;const a=c[f+1],s=a?(r.left+a.left)/2:r.left+.25*n.height;e.drawText(t,{x:or(o+s-.25*u),y:or(p),text:l,fontSize:or(u),color:i.color??"#000000"})}}(e,t,r,o,i,s,d)}async function Lb(e,t,n,r,o,a,i,s,l){if(0!==r.index)return;const c=$o(n,l),d=r.slots[0];if(!d)return;const u=Di(n,o.styles),p="bullet"===u?.kind,f=p?u?.bulletFont:void 0,g=p?u.bulletPicture:void 0;if(g){const s=g.widthPx??16,l=g.heightPx??s,c=await Sb(e,o,{src:g.src,width:s,height:l,...g.altText?{alt:g.altText}:{}});if(c)return void e.drawImage(t,{resourceName:c,x:or(a+Math.max(0,Ct(n,o.styles))),y:or(i+r.top+r.height*yr-l),width:or(s),height:or(l)})}if(!c)return;const m=pi(void 0,n.style?.styleId,o.styles),h=s.resolveFontFace({fontFamily:f??m.fontFamily,bold:m.bold,italic:m.italic}),b=Ct(n,o.styles),y=kt(m),v=c.length*y*.62*Ho,x=rr(n,o.styles,d.left,v);e.drawText(t,{x:or(a+Math.max(0,x||b)),y:or(i+r.top+r.height*yr),text:c,fontSize:y,color:m.color??"#000000",bold:m.bold,italic:m.italic,fontResourceName:h.writerResourceName})}function Nb(e,t,n,r,o,a,i){const s=[[n.borderTop,"top"],[n.borderRight,"right"],[n.borderBottom,"bottom"],[n.borderLeft,"left"]],l=s.some(([e])=>e&&"none"!==e.type&&e.width>0)||null!=n.borderBar&&"none"!==n.borderBar.type&&n.borderBar.width>0;if(!n.shading&&!l)return;let c=0;for(const h of r)c=Math.max(c,h.top+h.height);if(c<=0)return;const d=Rr(n),u=d.top+c+d.bottom,p=o+(n.indentLeft??0),f=o+i-(n.indentRight??0),g=a+u;n.shading&&e.drawRect(t,{x:or(p),y:or(a),width:or(Math.max(0,f-p)),height:or(u),fill:n.shading});for(const[h,b]of s){if(!h||"none"===h.type||h.width<=0)continue;const[n,r,o,i]="top"===b?[p,a,f,a]:"bottom"===b?[p,g,f,g]:"left"===b?[p,a,p,g]:[f,a,f,g];e.drawLine(t,{x1:or(n),y1:or(r),x2:or(o),y2:or(i),stroke:h.color,lineWidth:h.width,dashArray:bb(h.type)})}const m=n.borderBar;m&&"none"!==m.type&&m.width>0&&e.drawLine(t,{x1:or(p),y1:or(a),x2:or(p),y2:or(g),stroke:m.color,lineWidth:m.width,dashArray:bb(m.type)})}async function zb(e,t,n,r,o,a,i,s,l,c){for(const d of r){for(const n of d.barTabPositionsPx??[])e.drawLine(t,{x1:or(a+n),y1:or(i+d.top),x2:or(a+n),y2:or(i+d.top+d.height),stroke:"#000000",lineWidth:or(1)});await Lb(e,t,n,d,o,a,i,s,l);for(const r of d.fragments)await Db(e,t,n,d,r,o,a,i,s,c)}}function $b(e,t,n,r,o,a,i){"none"===n.type||n.width<=0||e.drawLine(t,{x1:or(r),y1:or(o),x2:or(a),y2:or(i),stroke:n.color,lineWidth:or(n.width),dashArray:bb(n.type)})}function Hb(e,t,n,r,o){const a=r+n.left,i=o+n.top,s=a+n.width,l=i+n.height;$b(e,t,n.borders.top,a,i,s,i),$b(e,t,n.borders.right,s,i,s,l),$b(e,t,n.borders.bottom,a,l,s,l),$b(e,t,n.borders.left,a,i,a,l),n.borders.topLeftToBottomRight&&$b(e,t,n.borders.topLeftToBottomRight,a,i,s,l),n.borders.topRightToBottomLeft&&$b(e,t,n.borders.topRightToBottomLeft,s,i,a,l)}async function Wb(e,t,n,r,o,a,i,s,l,c){if("table"!==n.sourceBlock.type)return;const d=n.sourceBlock,u=n.tableSegment?ha(d,n.tableSegment):d;if(0===u.rows.length)return;const p=W({table:u,state:{document:r},pageIndex:0,originX:0,originY:0,contentWidth:i,estimatedHeight:n.estimatedHeight});for(const f of p.cells)f.shading&&e.drawRect(t,{x:or(o+f.left),y:or(a+f.top),width:or(f.width),height:or(f.height),fill:f.shading});for(const f of p.cells)if(Hb(e,t,f,o,a),f.revision){const n="insert"===f.revision.type?"#059669":"delete"===f.revision.type?"#dc2626":"#d97706";e.drawRect(t,{x:or(o+f.left+1),y:or(a+f.top+1),width:or(Math.max(0,f.width-2)),height:or(Math.max(0,f.height-2)),stroke:n,lineWidth:or(2)})}for(const f of p.cells)for(const n of f.paragraphs)await zb(e,t,n.paragraph,n.lines,r,o+n.originX,a+n.originY,s,l,c)}var jb={drawParagraph:zb,drawTableBlock:Wb};async function Ub(e,t,n,r,o,a,i,s,l,c,d){if(!n||0===n.length)return;const u=a;let p=a;for(let f=0;f<n.length;f+=1){const g=n[f];switch(g.sourceBlock.type){case"paragraph":{if(!g.layout)break;const n=ti(g.sourceBlock.style,r.styles),f=p+(0===g.layout.startOffset&&p>a?n.spacingBefore??0:0);d?.(g.sourceBlock.id,f);const m=f+Rr(n).top;Nb(e,t,n,g.layout.lines,o,f,i),c&&(await Fb({writer:e,pageIndex:t,lines:g.layout.lines,document:r,pageSettings:c,contentLeft:o,contentTop:u,contentWidth:i,paragraphTop:m,layer:"behind"}),await vb({writer:e,document:r,fontRegistry:s,pageIndex:t,lines:g.layout.lines,pageSettings:c,contentLeft:o,contentTop:u,contentWidth:i,paragraphTop:f,drawers:jb,layer:"behind"})),await zb(e,t,g.sourceBlock,g.layout.lines,r,o,m,s,l,jb),c&&(await Fb({writer:e,pageIndex:t,lines:g.layout.lines,document:r,pageSettings:c,contentLeft:o,contentTop:u,contentWidth:i,paragraphTop:m,layer:"front"}),await vb({writer:e,document:r,fontRegistry:s,pageIndex:t,lines:g.layout.lines,pageSettings:c,contentLeft:o,contentTop:u,contentWidth:i,paragraphTop:f,drawers:jb,layer:"front"}));break}case"table":if(g.sourceBlock.style?.floating&&c){const n=Q(g.sourceBlock,i),a=be({floating:g.sourceBlock.style.floating,pageSettings:c,contentLeft:o,contentTop:u,contentWidth:i,anchorTop:p,width:n,height:g.floatingTableHeight??1,pageIndex:t});a.y+=g.floatingTableOffsetY??0,await Wb(e,t,{...g,estimatedHeight:a.height},r,a.x,a.y,i,s,l,jb);break}await Wb(e,t,g,r,o,p,i,s,l,jb);break;default:Va(g.sourceBlock,"block")}if("paragraph"===g.sourceBlock.type&&g.layout){const s=n[f+1];if("paragraph"===s?.sourceBlock.type&&s.layout&&s.sourceBlock.id!==g.sourceBlock.id){const n=ti(g.sourceBlock.style,r.styles),l=ti(s.sourceBlock.style,r.styles);if(Te(n,l)){const r=p+(0===g.layout.startOffset&&p>a?n.spacingBefore??0:0)+Rr(n).top;let s=0;for(const e of g.layout.lines)s=Math.max(s,e.top+e.height);const l=r+s,c=o+(n.indentLeft??0),d=o+i-(n.indentRight??0),u=n.borderBetween;e.drawLine(t,{x1:or(c),y1:or(l),x2:or(d),y2:or(l),stroke:u.color,lineWidth:u.width,dashArray:bb(u.type)})}}}p+=Math.max(0,g.estimatedHeight)}}async function Vb(e,t,n,r,o,a,i){if(e.drawRect(t,{x:0,y:0,width:n,height:r,fill:o?.pageColor||"#ffffff"}),a){const o=a.distance??12,i="dashed"===a.style?[6,4]:"dotted"===a.style?[1,3]:void 0;if(e.drawRect(t,{x:o,y:o,width:n-2*o,height:r-2*o,fill:void 0,stroke:a.color,lineWidth:a.width,...i?{dashArray:i}:{}}),"double"===a.style){const i=o+2*a.width;e.drawRect(t,{x:i,y:i,width:n-2*i,height:r-2*i,stroke:a.color,lineWidth:a.width})}}const s=o?.watermark;if("text"===s?.kind&&s.text)e.saveGraphicsState(t),e.rotateAbout(t,n/2,r/2,s.rotation??-45),e.setOpacity(t,s.opacity??.25),e.drawText(t,{x:n/2,y:r/2,text:s.text,fontSize:s.fontSize??48,color:s.color??"#94a3b8"}),e.restoreGraphicsState(t);else if("image"===s?.kind&&s.src&&i){const o={src:s.src,width:360,height:180},a=await Sb(e,i,o);if(a){const i=s.scale??1,l=o.width*i,c=o.height*i;e.saveGraphicsState(t),e.rotateAbout(t,n/2,r/2,s.rotation??-45),e.setOpacity(t,s.opacity??.25),e.drawImage(t,{resourceName:a,x:(n-l)/2,y:(r-c)/2,width:l,height:c}),e.restoreGraphicsState(t)}}}var Kb=[{key:"helvetica:regular",family:"Helvetica",bold:!1,italic:!1,writerResourceName:"F1",pdfResource:{kind:"base14",resourceName:"F1",baseFont:"Helvetica"}},{key:"helvetica:bold",family:"Helvetica",bold:!0,italic:!1,writerResourceName:"F2",pdfResource:{kind:"base14",resourceName:"F2",baseFont:"Helvetica-Bold"}},{key:"helvetica:italic",family:"Helvetica",bold:!1,italic:!0,writerResourceName:"F3",pdfResource:{kind:"base14",resourceName:"F3",baseFont:"Helvetica-Oblique"}},{key:"helvetica:bolditalic",family:"Helvetica",bold:!0,italic:!0,writerResourceName:"F4",pdfResource:{kind:"base14",resourceName:"F4",baseFont:"Helvetica-BoldOblique"}}];function _b(e,t,n){return`${e.toLowerCase()}:${t?"bold":"regular"}${n?"italic":""}`}function Xb(e){return e.replace(/[^A-Za-z0-9_]/g,"")}var qb=class{faces=/* @__PURE__ */new Map;fallbackFamily="Helvetica";constructor(){for(const e of Kb)this.registerFontFace(e)}registerFontFace(e){this.faces.set(_b(e.family,e.bold,e.italic),e)}resolveFontFace(e){const t=pn(e.fontFamily),n=Boolean(e.bold),r=Boolean(e.italic);return this.faces.get(_b(t,n,r))??this.faces.get(_b(this.fallbackFamily,n,r))??this.faces.get(_b(this.fallbackFamily,!1,!1))}getPdfFontResources(){const e=/* @__PURE__ */new Map;for(const t of this.faces.values())e.set(t.pdfResource.resourceName,t.pdfResource);return Array.from(e.values())}async loadBundledUnicodeFaces(e={}){const t=e.families?new Set(Array.from(e.families).map(pn).map(e=>e.toLowerCase())):null,n=await this.registerOfficeCompatibleFaces(t);if(!t||t.has("roboto")||Array.from(t).some(e=>"helvetica"!==e&&!n.has(e)))for(const[r,o]of Object.entries(S)){const e=await ue(o);if(!e)continue;const t="bold"===r||"bolditalic"===r,n="italic"===r||"bolditalic"===r,a=`Roboto${r[0].toUpperCase()}${r.slice(1)}`;this.registerFontFace({key:`roboto:${r}`,family:"Roboto",bold:t,italic:n,writerResourceName:a,pdfResource:{kind:"unicode",resourceName:a,family:"Roboto",fontData:e}}),this.fallbackFamily="Roboto"}}async loadRemoteWebFontFaces(e={}){if(!e.families)return;const t=await Sn(e.families);for(const n of t){const e=`Remote${Xb(n.postscriptName||n.family)}`;this.registerFontFace({key:_b(n.family,n.bold,n.italic),family:n.family,bold:n.bold,italic:n.italic,writerResourceName:e,pdfResource:{kind:"unicode",resourceName:e,family:n.family,fontData:n.fontData,postscriptName:n.postscriptName}})}}async registerOfficeCompatibleFaces(e){const t=/* @__PURE__ */new Set;for(const n of R){const r=[n.family,...n.aliases].map(e=>e.toLowerCase());if(e&&!r.some(t=>e.has(t)))continue;for(const e of r)t.add(e);const o=[];for(const[e,t]of Object.entries(n.files)){const r=await ue(t);if(!r)continue;const a="bold"===e||"bolditalic"===e,i="italic"===e||"bolditalic"===e,s=`${Xb(n.family)}${e[0].toUpperCase()}${e.slice(1)}`,l={key:`${n.family.toLowerCase()}:${e}`,family:n.family,bold:a,italic:i,writerResourceName:s,pdfResource:{kind:"unicode",resourceName:s,family:n.family,fontData:r}};this.registerFontFace(l),o.push(l)}for(const e of n.aliases)for(const t of o)this.registerFontFace({...t,key:`${e.toLowerCase()}:${t.key.split(":")[1]}`,family:e})}return t}},Gb="%PDF-1.4\n% Oasis PDF\n",Yb=[{kind:"base14",resourceName:"F1",baseFont:"Helvetica"},{kind:"base14",resourceName:"F2",baseFont:"Helvetica-Bold"},{kind:"base14",resourceName:"F3",baseFont:"Helvetica-Oblique"},{kind:"base14",resourceName:"F4",baseFont:"Helvetica-BoldOblique"}];function Zb(e){return Number.isFinite(e)?Number(e.toFixed(3)).toString():"0"}function Jb(e){return Math.max(0,e).toString(16).padStart(4,"0").slice(-4).toUpperCase()}function Qb(e,t){if(!e)return t;const n=Ca(xa(e));return n?[n[0]/255,n[1]/255,n[2]/255]:t}function ey(e,t,n){const[r,o,a]=Qb(e,n);return`${Zb(r)} ${Zb(o)} ${Zb(a)} ${t}`}function ty(e,t){return(e&&e.trim().length>0?e:t).replaceAll(" ","_").replace(/[^A-Za-z0-9_.+-]/g,"")}var ny=/* @__PURE__ */new Map([[8364,128],[8218,130],[402,131],[8222,132],[8230,133],[8224,134],[8225,135],[710,136],[8240,137],[352,138],[8249,139],[338,140],[381,142],[8216,145],[8217,146],[8220,147],[8221,148],[8226,149],[8211,150],[8212,151],[732,152],[8482,153],[353,154],[8250,155],[339,156],[382,158],[376,159]]);function ry(e){return Array.from(e).map(e=>function(e){const t=e.codePointAt(0)??63;return t>=32&&t<=126||t>=160&&t<=255?t:ny.get(t)??63}(e).toString(16).padStart(2,"0").toUpperCase()).join("")}function oy(e){const t=[];for(let n of e)n>65535?(n-=65536,t.push(n>>>10&1023|55296),t.push(1023&n|56320)):t.push(n);return t.map(Jb).join("")}function ay(e,t=[]){const n=new TextEncoder,r=n.encode(["<< /Length "+e.byteLength,...t,">>"].join(" ")+"\nstream\n"),o=n.encode("\nendstream"),a=new Uint8Array(r.length+e.length+o.length);return a.set(r),a.set(e,r.length),a.set(o,r.length+e.length),a}function iy(e,t=[]){return ay(re(e,{level:9}),["/Filter /FlateDecode",...t])}function sy(e,t){const n=[...new Set(t)].sort((e,t)=>e-t),r=[];let o=-1,a=-2,i=[];const s=()=>{i.length&&r.push(o+" ["+i.join(" ")+"]")};for(const l of n)(l!==a+1||o<0)&&(s(),o=l,i=[]),i.push(Zb(e[l]??0)),a=l;return s(),r.join(" ")}function ly(e){return Jb(e)}function cy(e){return`% OasisText ${oy(Array.from(e).map(e=>e.codePointAt(0)??65533))}`}function dy(e){return e&&0!==e.length?`[${e.map(e=>Zb(e)).join(" ")}] 0 d`:null}var uy=class{page;fonts;images;shadings;constructor(e,t,n,r){this.page=e,this.fonts=t,this.images=n,this.shadings=r}registerAxialGradient(e){const t=this.shadings.register({x0:e.x0,y0:this.page.height-e.y0,x1:e.x1,y1:this.page.height-e.y1,stops:e.stops});return this.page.shadingResourceNames.add(t),t}drawRect(e){const t=this.page;if(e.width<=0||e.height<=0)return;const n=["q"];if(e.fill&&n.push(ey(e.fill,"rg",[1,1,1])),e.stroke){n.push(ey(e.stroke,"RG",[0,0,0])),n.push(`${Zb(e.lineWidth??1)} w`);const t=dy(e.dashArray);t&&n.push(t)}n.push([Zb(e.x),Zb(t.height-e.y-e.height),Zb(e.width),Zb(e.height),"re"].join(" ")),e.fill&&e.stroke?n.push("B"):e.fill?n.push("f"):e.stroke&&n.push("S"),n.push("Q"),t.commands.push(n.join("\n"))}drawLine(e){const t=this.page,n=dy(e.dashArray),r=["q",ey(e.stroke,"RG",[0,0,0])];n&&r.push(n),r.push(`${Zb(e.lineWidth??1)} w`,`${Zb(e.x1)} ${Zb(t.height-e.y1)} m`,`${Zb(e.x2)} ${Zb(t.height-e.y2)} l`,"S","Q"),t.commands.push(r.join("\n"))}drawPath(e){const t=this.page;if(0===e.segments.length)return;if(!e.fill&&!e.stroke)return;const n=e=>t.height-e,r=["q"];e.fill&&r.push(ey(e.fill,"rg",[1,1,1])),e.stroke&&(r.push(ey(e.stroke,"RG",[0,0,0])),r.push(`${Zb(e.lineWidth??1)} w`));for(const o of e.segments)switch(o.type){case"move":r.push(`${Zb(o.x)} ${Zb(n(o.y))} m`);break;case"line":r.push(`${Zb(o.x)} ${Zb(n(o.y))} l`);break;case"cubic":r.push(`${Zb(o.x1)} ${Zb(n(o.y1))} ${Zb(o.x2)} ${Zb(n(o.y2))} ${Zb(o.x)} ${Zb(n(o.y))} c`);break;case"close":r.push("h")}e.fill&&e.stroke?r.push("B"):e.fill?r.push("f"):r.push("S"),r.push("Q"),t.commands.push(r.join("\n"))}saveGraphicsState(){this.page.commands.push("q")}restoreGraphicsState(){this.page.commands.push("Q")}setOpacity(e){const t=Math.max(0,Math.min(1,e)),n=`GSOpacity${Math.round(100*t)}`;(this.page.graphicsStateOpacities??=/* @__PURE__ */new Map).set(n,t),this.page.commands.push(`/${n} gs`)}rotateAbout(e,t,n){const r=this.page;if(!n)return;const o=r.height-t,a=-n*Math.PI/180,i=Math.cos(a),s=Math.sin(a),l=e-e*i+o*s,c=o-e*s-o*i;r.commands.push(`${Zb(i)} ${Zb(s)} ${Zb(-s)} ${Zb(i)} ${Zb(l)} ${Zb(c)} cm`)}clipRect(e,t,n,r){const o=this.page;n<=0||r<=0||o.commands.push(`${Zb(e)} ${Zb(o.height-t-r)} ${Zb(n)} ${Zb(r)} re`,"W","n")}clipPath(e){const t=this.page;if(0===e.length)return;const n=e=>t.height-e,r=[];for(const o of e)switch(o.type){case"move":r.push(`${Zb(o.x)} ${Zb(n(o.y))} m`);break;case"line":r.push(`${Zb(o.x)} ${Zb(n(o.y))} l`);break;case"cubic":r.push(`${Zb(o.x1)} ${Zb(n(o.y1))} ${Zb(o.x2)} ${Zb(n(o.y2))} ${Zb(o.x)} ${Zb(n(o.y))} c`);break;case"close":r.push("h")}r.push("W","n"),t.commands.push(r.join("\n"))}drawText(e){if(0===e.text.length)return;const t=this.fonts.resolveAndMarkFontName(e),n=this.fonts.getUnicodeState(t),r=n?this.fonts.buildUnicodeShowCommand(n,e.text,e.fontFeatures):`<${ry(e.text)}> Tj`;null!==r&&(e.gradientShadingName?this.emitGradientTextBlock(t,r,e,e.gradientShadingName):this.emitTextBlock(t,r,e))}textSetupCommands(e,t){return[`/${e} ${Zb(t.fontSize??12)} Tf`,...t.horizontalScale&&t.horizontalScale>0&&100!==t.horizontalScale?[`${Zb(t.horizontalScale)} Tz`]:[],...t.characterSpacing&&0!==t.characterSpacing?[`${Zb(t.characterSpacing)} Tc`]:[]]}emitTextBlock(e,t,n){const r=this.page;r.commands.push([cy(n.text),"BT",ey(n.color,"rg",[0,0,0]),...n.renderMode&&0!==n.renderMode?[ey(n.strokeColor??n.color,"RG",[0,0,0]),`${Zb(n.strokeWidth??Math.max(.3,.03*(n.fontSize??12)))} w`,`${n.renderMode} Tr`]:[],...this.textSetupCommands(e,n),`${Zb(n.x)} ${Zb(r.height-n.y)} Td`,t,"ET"].join("\n"))}emitGradientTextBlock(e,t,n,r){const o=this.page;o.commands.push([cy(n.text),"q","BT",...this.textSetupCommands(e,n),"7 Tr",`${Zb(n.x)} ${Zb(o.height-n.y)} Td`,t,"ET",`/${r} sh`,"Q"].join("\n"))}drawImage(e){const t=this.page;if(e.width<=0||e.height<=0||!this.images.has(e.resourceName))return;t.imageResourceNames.add(e.resourceName);const n=t.height-e.y-e.height,r=Number.isFinite(e.rotation)?e.rotation??0:0,o=e.crop,a=o?.left??0,i=o?.top??0,s=o?.right??0,l=o?.bottom??0;if(o&&(a>0||i>0||s>0||l>0))return void this.drawCroppedImage(e,n,r,{left:a,top:i,right:s,bottom:l});if(0===r)return void t.commands.push(["q",[Zb(e.width),"0","0",Zb(e.height),Zb(e.x),Zb(n),"cm"].join(" "),`/${e.resourceName} Do`,"Q"].join("\n"));const c=-r*Math.PI/180,d=Math.cos(c),u=Math.sin(c),p=e.width*d,f=e.width*u,g=-e.height*u,m=e.height*d,h=e.x+e.width/2-.5*p-.5*g,b=n+e.height/2-.5*f-.5*m;t.commands.push(["q",[Zb(p),Zb(f),Zb(g),Zb(m),Zb(h),Zb(b),"cm"].join(" "),`/${e.resourceName} Do`,"Q"].join("\n"))}drawCroppedImage(e,t,n,r){const o=this.page,{width:a,height:i}=e,s=a/Math.max(1e-4,1-r.left-r.right),l=i/Math.max(1e-4,1-r.top-r.bottom),c=-r.left*s,d=-r.bottom*l,u=-n*Math.PI/180,p=Math.cos(u),f=Math.sin(u),g=a/2,m=i/2,h=p,b=f,y=-f,v=p,x=e.x+a/2-(h*g+y*m),w=t+i/2-(b*g+v*m);o.commands.push(["q",[Zb(h),Zb(b),Zb(y),Zb(v),Zb(x),Zb(w),"cm"].join(" "),`0 0 ${Zb(a)} ${Zb(i)} re W n`,[Zb(s),"0","0",Zb(l),Zb(c),Zb(d),"cm"].join(" "),`/${e.resourceName} Do`,"Q"].join("\n"))}};function py(e,t,n){if(e.seek(t),1!==e.u16())return null;const r=e.u16();return n(e,t+e.u32(),r)}function fy(e,t){const n=new Array(t);for(let r=0;r<t;r+=1)n[r]=e.u16();return n}function gy(e,t,n){const r=new Array(t);for(let o=0;o<t;o+=1)r[o]=n+e.u16();return r}function my(e,t){e.seek(t);const n=e.u16();if(1===n){const t=e.u16(),n=/* @__PURE__ */new Map;for(let r=0;r<t;r+=1)n.set(e.u16(),r);return e=>n.get(e)??-1}if(2===n){const t=e.u16(),n=[];for(let r=0;r<t;r+=1){const t=e.u16(),r=e.u16(),o=e.u16();n.push({start:t,end:r,startIndex:o})}return e=>{for(const t of n)if(e>=t.start&&e<=t.end)return t.startIndex+(e-t.start);return-1}}return()=>-1}function hy(e,t){e.seek(t);const n=e.u16();if(1===n){const t=e.u16(),n=e.u16(),r=fy(e,n);return e=>{const o=e-t;return o>=0&&o<n?r[o]:0}}if(2===n){const t=e.u16(),n=[];for(let r=0;r<t;r+=1){const t=e.u16(),r=e.u16(),o=e.u16();n.push({start:t,end:r,classValue:o})}return e=>{for(const t of n)if(e>=t.start&&e<=t.end)return t.classValue;return 0}}return()=>0}function by(e){e.seek(0),e.skip(2),e.skip(2);const t=e.u16(),n=e.u16(),r=e.u16(),o=function(e,t){e.seek(t);const n=e.u16(),r=[];for(let o=0;o<n;o+=1){const n=e.tag(),o=t+e.u16();r.push({tag:n,offset:o})}return r.map(({tag:t,offset:n})=>(e.seek(n),e.skip(2),{tag:t,lookupIndices:fy(e,e.u16())}))}(e,n),a=function(e,t){e.seek(t);const n=e.u16(),r=[];for(let c=0;c<n;c+=1){const n=e.tag(),o=t+e.u16();r.push({tag:n,offset:o})}if(0===r.length)return[];const o=r.find(e=>"latn"===e.tag)??r.find(e=>"DFLT"===e.tag)??r[0];e.seek(o.offset);const a=e.u16();if(0===a)return[];e.seek(o.offset+a),e.skip(2);const i=e.u16(),s=e.u16(),l=[];65535!==i&&l.push(i);for(let c=0;c<s;c+=1)l.push(e.u16());return l}(e,t),i=/* @__PURE__ */new Map;for(const s of a){const e=o[s];if(!e)continue;const t=i.get(e.tag)??[];for(const n of e.lookupIndices)t.includes(n)||t.push(n);i.set(e.tag,t)}return{featureToLookups:i,lookupListOffset:r}}function yy(e,t,n){return e.seek(t),gy(e,e.u16(),t).map(t=>{e.seek(t);const r=e.u16();e.skip(2);const o=gy(e,e.u16(),t),a=[];for(const i of o)try{const t=n(e,i,r);t&&a.push(t)}catch{}return{lookupType:r,subtables:a}})}function vy(e,t){const n=/* @__PURE__ */new Set;for(const r of t)for(const t of e.get(r)??[])n.add(t);return Array.from(n).sort((e,t)=>e-t)}function xy(e,t){if(e.seek(t),1!==e.u16())return null;const n=t+e.u16(),r=e.u16(),o=gy(e,r,t).map(t=>(e.seek(t),fy(e,e.u16())));return{coverage:my(e,n),sets:o}}function wy(e,t){const n=new Array(t);for(let r=0;r<t;r+=1){const t=e.u16(),o=e.u16();n[r]={sequenceIndex:t,lookupListIndex:o}}return n}function Iy(e,t,n,r){for(const o of n)r.applyLookupIndexAt(o.lookupListIndex,e,t+o.sequenceIndex)}function Sy(e,t){e.seek(t);const n=e.u16();return gy(e,n,t).map(t=>(e.seek(t),{backtrack:fy(e,e.u16()),input:fy(e,Math.max(0,e.u16()-1)),lookahead:fy(e,e.u16()),records:wy(e,e.u16())}))}function Cy(e,t,n,r,o){const a=(e,n)=>{const r=t[e];return r?o?"b"===n?o.backtrack(r.id):"l"===n?o.lookahead(r.id):o.input(r.id):r.id:null};for(const i of e){const e=i.input.length+1;if(n+e>t.length)continue;let o=!0;for(let t=0;t<i.input.length;t+=1)if(a(n+1+t,"i")!==i.input[t]){o=!1;break}if(o){for(let e=0;e<i.backtrack.length;e+=1)if(a(n-1-e,"b")!==i.backtrack[e]){o=!1;break}if(o){for(let t=0;t<i.lookahead.length;t+=1)if(a(n+e+t,"l")!==i.lookahead[t]){o=!1;break}if(o)return Iy(t,n,i.records,r),e}}}return null}function ky(e,t,n){switch(n){case 1:return function(e,t){e.seek(t);const n=e.u16(),r=t+e.u16();if(1===n){const t=e.i16(),n=my(e,r);return{apply(e,r){const o=e[r];return!o||n(o.id)<0?null:(o.id=o.id+t&65535,1)}}}if(2===n){const t=e.u16(),n=fy(e,t),o=my(e,r);return{apply(e,r){const a=e[r];if(!a)return null;const i=o(a.id);return i<0||i>=t?null:(a.id=n[i],1)}}}return null}(e,t);case 2:return function(e,t){const n=xy(e,t);if(!n)return null;const{coverage:r,sets:o}=n;return{apply(e,t){const n=e[t];if(!n)return null;const a=r(n.id);if(a<0||a>=o.length)return null;const i=o[a];if(0===i.length)return null;const s=n.codePoints,l=i.map((e,t)=>({id:e,codePoints:0===t?s:[]}));return e.splice(t,1,...l),i.length}}}(e,t);case 3:return function(e,t){const n=xy(e,t);if(!n)return null;const{coverage:r,sets:o}=n;return{apply(e,t){const n=e[t];if(!n)return null;const a=r(n.id);if(a<0||a>=o.length)return null;const i=o[a];return 0===i.length?null:(n.id=i[0],1)}}}(e,t);case 4:return function(e,t){if(e.seek(t),1!==e.u16())return null;const n=t+e.u16(),r=e.u16(),o=gy(e,r,t).map(t=>(e.seek(t),gy(e,e.u16(),t).map(t=>{e.seek(t);const n=e.u16(),r=e.u16();return{ligatureGlyph:n,components:fy(e,Math.max(0,r-1))}}))),a=my(e,n);return{apply(e,t){const n=e[t];if(!n)return null;const r=a(n.id);if(r<0||r>=o.length)return null;for(const a of o[r]){const{components:n}=a;if(t+n.length>e.length-1)continue;let r=!0;for(let a=0;a<n.length;a+=1)if(e[t+1+a].id!==n[a]){r=!1;break}if(!r)continue;const o=n.length+1,i=[];for(let a=0;a<o;a+=1)i.push(...e[t+a].codePoints);return e.splice(t,o,{id:a.ligatureGlyph,codePoints:i}),1}return null}}}(e,t);case 6:return function(e,t){e.seek(t);const n=e.u16();if(3===n){const n=gy(e,e.u16(),t),r=gy(e,e.u16(),t),o=gy(e,e.u16(),t),a=wy(e,e.u16()),i=n.map(t=>my(e,t)),s=r.map(t=>my(e,t)),l=o.map(t=>my(e,t));return{apply(e,t,n){if(0===s.length)return null;if(t+s.length>e.length)return null;for(let r=0;r<s.length;r+=1)if(s[r](e[t+r].id)<0)return null;for(let r=0;r<i.length;r+=1){const n=e[t-1-r];if(!n||i[r](n.id)<0)return null}for(let r=0;r<l.length;r+=1){const n=e[t+s.length+r];if(!n||l[r](n.id)<0)return null}return Iy(e,t,a,n),s.length}}}if(1===n){const n=t+e.u16(),r=e.u16(),o=gy(e,r,t),a=my(e,n),i=o.map(t=>Sy(e,t));return{apply(e,t,n){const r=e[t];if(!r)return null;const o=a(r.id);return o<0||o>=i.length?null:Cy(i[o],e,t,n,null)}}}if(2===n){const n=t+e.u16(),r=t+e.u16(),o=t+e.u16(),a=t+e.u16(),i=e.u16(),s=new Array(i);for(let f=0;f<i;f+=1){const n=e.u16();s[f]=0===n?0:t+n}const l=my(e,n),c=hy(e,r),d=hy(e,o),u=hy(e,a),p=s.map(t=>0===t?[]:Sy(e,t));return{apply(e,t,n){const r=e[t];if(!r)return null;if(l(r.id)<0)return null;const o=d(r.id),a=p[o];return a?Cy(a,e,t,n,{backtrack:c,input:d,lookahead:u}):null}}}return null}(e,t);case 7:return py(e,t,ky);default:return null}}var Ty=class e{lookups;featureToLookups;constructor(e,t){this.lookups=e,this.featureToLookups=t}static parse(t){try{const n=new st(t),{featureToLookups:r,lookupListOffset:o}=by(n),a=yy(n,o,ky);return new e(a,r)}catch{return null}}hasAnyFeature(e){return e.some(e=>this.featureToLookups.has(e))}collectLookupIndices(e){return vy(this.featureToLookups,e)}applyLookupIndexAt(e,t,n){const r=this.lookups[e];if(!r||n<0||n>=t.length)return null;for(const o of r.subtables){const e=o.apply(t,n,this);if(null!==e)return e}return null}shape(e,t){const n=this.collectLookupIndices(t);for(const r of n){let t=0;for(;t<e.length;){const n=this.applyLookupIndexAt(r,e,t);t+=n&&n>0?n:1}}}};function Py(e,t){let n=0;return 1&t&&e.i16(),2&t&&e.i16(),4&t&&(n=e.i16()),8&t&&e.i16(),16&t&&e.u16(),32&t&&e.u16(),64&t&&e.u16(),128&t&&e.u16(),n}function Ry(e){let t=0;for(let n=0;n<8;n+=1)e&1<<n&&(t+=1);return 2*t}function Ay(e,t,n){switch(n){case 1:return function(e,t){e.seek(t);const n=e.u16(),r=t+e.u16();if(1===n){const t=Py(e,e.u16()),n=my(e,r);return 0===t?null:{apply:(e,r,o)=>n(e[o])<0?null:(r[o]+=t,1)}}if(2===n){const t=e.u16(),n=e.u16(),o=Ry(t),a=e.tell(),i=new Array(n);for(let r=0;r<n;r+=1)e.seek(a+r*o),i[r]=Py(e,t);const s=my(e,r);return{apply(e,t,r){const o=s(e[r]);if(o<0||o>=n)return null;const a=i[o];return 0===a?null:(t[r]+=a,1)}}}return null}(e,t);case 2:return function(e,t){e.seek(t);const n=e.u16(),r=t+e.u16(),o=e.u16(),a=e.u16(),i=!!(4&a);if(1===n){const n=e.u16(),s=gy(e,n,t).map(t=>{e.seek(t);const n=e.u16(),r=/* @__PURE__ */new Map;for(let i=0;i<n;i+=1){const t=e.u16(),n=Py(e,o),i=Py(e,a);r.set(t,{secondGlyph:t,value1XAdvance:n,value2XAdvance:i})}return r}),l=my(e,r);return{apply(e,t,n){const r=e[n+1];if(void 0===r)return null;const o=l(e[n]);if(o<0||o>=s.length)return null;const a=s[o].get(r);return a?(t[n]+=a.value1XAdvance,t[n+1]+=a.value2XAdvance,i?2:1):null}}}if(2===n){const n=t+e.u16(),s=t+e.u16(),l=e.u16(),c=e.u16(),d=Ry(o),u=d+Ry(a),p=e.tell(),f=new Array(l*c),g=new Array(l*c);for(let t=0;t<l;t+=1)for(let n=0;n<c;n+=1){const r=(t*c+n)*u;e.seek(p+r),f[t*c+n]=Py(e,o),e.seek(p+r+d),g[t*c+n]=Py(e,a)}const m=my(e,r),h=hy(e,n),b=hy(e,s);return{apply(e,t,n){const r=e[n],o=e[n+1];if(void 0===o)return null;if(m(r)<0)return null;const a=h(r),s=b(o);if(a>=l||s>=c)return null;const d=a*c+s,u=f[d],p=g[d];return 0===u&&0===p?null:(t[n]+=u,t[n+1]+=p,i?2:1)}}}return null}(e,t);case 9:return py(e,t,Ay);default:return null}}var My=class e{lookups;featureToLookups;constructor(e,t){this.lookups=e,this.featureToLookups=t}static parse(t){try{const n=new st(t),{featureToLookups:r,lookupListOffset:o}=by(n),a=yy(n,o,Ay);return new e(a,r)}catch{return null}}hasAnyFeature(e){return e.some(e=>this.featureToLookups.has(e))}position(e,t,n){const r=vy(this.featureToLookups,n);for(const o of r){const n=this.lookups[o];if(!n)continue;let r=0;for(;r<e.length;){let o=null;for(const a of n.subtables)if(o=a.apply(e,t,r),null!==o)break;r+=o&&o>0?o:1}}}},Oy=/* @__PURE__ */new Set(["kern"]),By=class{font;gsub;gpos;constructor(e){this.font=e;const t=e.getRawTableData("GSUB");this.gsub=t?Ty.parse(t):null;const n=e.getRawTableData("GPOS");this.gpos=n?My.parse(n):null}get hasGsub(){return null!==this.gsub}get hasGpos(){return null!==this.gpos}get hasShaping(){return null!==this.gsub||null!==this.gpos}layout(e,t){const n=[];for(const c of e){const e=c.codePointAt(0)??65533,t=this.font.glyphForCodePoint(e);n.push({id:t,codePoints:0===t?[65533]:[e]})}const r=t?.filter(e=>!Oy.has(e))??[],o=t?.filter(e=>Oy.has(e))??[];this.gsub&&r.length>0&&this.gsub.shape(n,r);const a=n.map(e=>this.font.advanceWidthForGlyph(e.id));this.gpos&&o.length>0&&this.gpos.position(n.map(e=>e.id),a,o);const i=[],s=[];let l=0;for(let c=0;c<n.length;c+=1){const e=n[c],t=this.font.advanceWidthForGlyph(e.id),r=a[c];i.push({id:e.id,codePoints:e.codePoints,advanceWidth:t}),s.push({xAdvance:r}),l+=r}return{glyphs:i,positions:s,advanceWidth:l}}},Fy=class{font;constructor(e){this.font=e}layout(e){const t=[],n=[];let r=0;for(const o of e){const e=o.codePointAt(0)??65533,a=this.font.glyphForCodePoint(e),i=this.font.advanceWidthForGlyph(a);t.push({id:a,codePoints:0===a?[65533]:[e],advanceWidth:i}),n.push({xAdvance:i}),r+=i}return{glyphs:t,positions:n,advanceWidth:r}}};function Ey(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Dy(e,t){return Ey(e).getUint16(t)}function Ly(e,t){return Ey(e).getInt16(t)}function Ny(e,t,n){Ey(e).setUint16(t,n,!1)}function zy(e,t,n){Ey(e).setUint32(t,n,!1)}function $y(e){return e+3&-4}function Hy(e){const t=e.reduce((e,t)=>e+$y(t.byteLength),0),n=new Uint8Array(t);let r=0;for(const o of e)n.set(o,r),r+=$y(o.byteLength);return n}function Wy(e,t){const n=[],r=Ey(e);if(0===t)for(let o=0;o+1<e.byteLength;o+=2)n.push(2*r.getUint16(o));else for(let o=0;o+3<e.byteLength;o+=4)n.push(r.getUint32(o));return n}function jy(e,t){const n=e[t],r=e[t+1];return void 0===n||void 0===r?null:{start:n,end:r}}function Uy(e,t){if(e.byteLength<10||Ly(e,0)>=0)return;let n=10,r=0;do{if(n+4>e.byteLength)throw new Error("Truncated composite glyph");r=Dy(e,n),t(Dy(e,n+2),n+2),n+=4,n+=1&r?4:2,8&r?n+=2:64&r?n+=4:128&r&&(n+=8)}while(32&r)}function Vy(e,t,n){const r=/* @__PURE__ */new Map;for(const h of t.values())for(const t of h){if(!Number.isInteger(t)||t<=0||t>1114111||t>=55296&&t<=57343)continue;const o=n.get(e.glyphForCodePoint(t));o&&r.set(t,o)}const o=[...r].sort(([e],[t])=>e-t),a=[];for(const[h,b]of o){const e=a[a.length-1];e&&h===e.end+1&&b===e.gid+h-e.start?e.end=h:a.push({start:h,end:h,gid:b})}const i=new Uint8Array(16+12*a.length);Ny(i,0,12),zy(i,4,i.length),zy(i,12,a.length),a.forEach((e,t)=>{const n=16+12*t;zy(i,n,e.start),zy(i,n+4,e.end),zy(i,n+8,e.gid)});const s=a.filter(e=>e.start<65535).map(e=>({...e,end:Math.min(e.end,65534)}));s.push({start:65535,end:65535,gid:0});const l=s.length,c=16+8*l,d=c<=65535?new Uint8Array(c):null;if(d){const e=2**Math.floor(Math.log2(l));Ny(d,0,4),Ny(d,2,c),Ny(d,6,2*l),Ny(d,8,2*e),Ny(d,10,Math.log2(e)),Ny(d,12,2*l-2*e),s.forEach((e,t)=>{Ny(d,14+2*t,e.end),Ny(d,16+2*l+2*t,e.start),Ny(d,16+4*l+2*t,e.gid-e.start&65535)})}if(d&&o.every(([e])=>e<65535)){const e=new Uint8Array(12+d.length);return Ny(e,2,1),Ny(e,4,3),Ny(e,6,1),zy(e,8,12),e.set(d,12),e}const u=d?2:1,p=4+8*u,f=new Uint8Array(p+(d?.length??0)+i.length);Ny(f,2,u),d&&(Ny(f,4,3),Ny(f,6,1),zy(f,8,p),f.set(d,p));const g=d?12:4,m=p+(d?.length??0);return Ny(f,g,3),Ny(f,g+2,10),zy(f,g+4,m),f.set(i,m),f}function Ky(e,t,n,r){const o=e.getRawTableData("glyf"),a=e.getRawTableData("loca"),i=e.getRawTableData("head"),s=e.getRawTableData("hhea"),l=e.getRawTableData("maxp");if(!(o&&a&&i&&s&&l))throw new Error("Missing required TrueType tables for subsetting");const c=Wy(a,Dy(i,50)),d=[],u=[];let p=0;for(const x of t){d.push(p);const e=jy(c,x);if(!e||e.end<e.start||e.end>o.length)throw new Error("Invalid glyph range");if(e.end===e.start)continue;const t=o.slice(e.start,e.end);Uy(t,(e,r)=>{const o=n.get(e);if(void 0===o)throw new Error("Missing composite dependency");Ny(t,r,o)}),u.push(t),p+=$y(t.length)}d.push(p);const f=function(e){const t=e.every(e=>e%2==0&&e<=131070),n=new Uint8Array(e.length*(t?2:4));return e.forEach((e,r)=>{t?Ny(n,2*r,e/2):zy(n,4*r,e)}),{data:n,format:t?0:1}}(d),g=function(e,t,n){const r=e.getRawTableData("hmtx"),o=Dy(n,34);if(!r||o<1||o>e.glyphCount)throw new Error("Invalid source hmtx");const a=t.map(t=>e.advanceWidthForGlyph(t));let i=a.length;for(;i>1&&a[i-1]===a[i-2];)i--;const s=new Uint8Array(4*i+2*(t.length-i));return t.forEach((e,t)=>{const n=e<o?4*e+2:4*o+2*(e-o),l=t<i?4*t+2:4*i+2*(t-i);t<i&&Ny(s,4*t,a[t]),Ey(s).setInt16(l,Ly(r,n))}),{data:s,longCount:i}}(e,t,s),m=i.slice();zy(m,8,0),Ny(m,50,f.format);const h=s.slice();Ny(h,34,g.longCount);const b=l.slice();Ny(b,4,t.length);const y={cmap:Vy(e,r,n),head:m,hhea:h,maxp:b,hmtx:g.data,loca:f.data,glyf:Hy(u)};for(const x of["OS/2","name","cvt ","fpgm","prep","gasp"]){const t=e.getRawTableData(x);t&&(y[x]=t)}const v=e.getRawTableData("post");return v&&v.length>=32&&(y.post=v.slice(0,32),zy(y.post,0,196608)),y}var _y=class{createSubset(e,t){const n=/* @__PURE__ */new Map,r=[];for(const d of t)r.push(d.id),n.has(d.id)||n.set(d.id,d.codePoints);const o=function(e,t){const n=e.getRawTableData("glyf"),r=e.getRawTableData("loca"),o=e.getRawTableData("head");if(!n||!r||!o)return Array.from(/* @__PURE__ */new Set([0,...t])).sort((e,t)=>e-t);const a=Wy(r,Dy(o,50)),i=/* @__PURE__ */new Set([0,...t]),s=Array.from(i);for(;s.length>0;){const t=s.pop(),r=jy(a,t);if(!r||t>=e.glyphCount||r.end<r.start||r.end>n.byteLength)throw new Error("Invalid subset glyph range");r.end!==r.start&&Uy(n.slice(r.start,r.end),e=>{i.has(e)||(i.add(e),s.push(e))})}return Array.from(i).sort((e,t)=>e-t)}(e,r),a=new Map(o.map((e,t)=>[e,t])),i=Ky(e,o,a,n),s=sn(65536,new Map(Object.entries(i).map(([e,t])=>[e.charCodeAt(0)<<24|e.charCodeAt(1)<<16|e.charCodeAt(2)<<8|e.charCodeAt(3),t]))).ttf,l=[],c=[];for(const d of o)l[d]=e.advanceWidthForGlyph(d)/e.unitsPerEm*1e3,c[d]=n.get(d)??[0];return{fontFile:s,widths:l,unicode:c,encodeGlyph:e=>a.get(e)??0}}};var Xy=class{fontResources=/* @__PURE__ */new Map;unicodeFontStates=/* @__PURE__ */new Map;usedFontResourceNames=/* @__PURE__ */new Set;constructor(e){for(const t of e)this.registerFontResource(t)}registerFontResource(e){if(this.fontResources.set(e.resourceName,e),"unicode"===e.kind&&!this.unicodeFontStates.has(e.resourceName)){const t=function(e){const t=new By(e);return{program:e,layouter:t.hasShaping?t:new Fy(e),subsetter:new _y}}(function(e){const t=c.decodeSync(e);return Kt.parse(t)}(e.fontData)),n=1e3/t.program.unitsPerEm,r={id:0,codePoints:[0],advanceWidth:t.program.advanceWidthForGlyph(0)};this.unicodeFontStates.set(e.resourceName,{resource:e,font:t,usedGlyphs:/* @__PURE__ */new Map([[0,r]]),scale:n,layoutCache:/* @__PURE__ */new Map})}}resolveAndMarkFontName(e){const t=function(e){return e.fontResourceName?e.fontResourceName:e.bold&&e.italic?"F4":e.bold?"F2":e.italic?"F3":"F1"}(e);return this.usedFontResourceNames.add(t),t}getUnicodeState(e){return this.unicodeFontStates.get(e)}buildUnicodeShowCommand(e,t,n){const r=this.layoutUnicodeText(e,t,n),o=this.encodeUnicodeGlyphRun(e,r);return 0===o.length?null:o.some(e=>Math.abs(e.nominalWidth-e.desiredAdvance)>.01)?`[${o.map(e=>{const t=e.nominalWidth-e.desiredAdvance;return 0===t?`<${ly(e.glyphId)}>`:`<${ly(e.glyphId)}> ${Zb(t)}`}).join(" ")}] TJ`:`<${o.map(e=>ly(e.glyphId)).join("")}> Tj`}buildFontObjects(e){const t=Array.from(this.fontResources.values()).filter(e=>this.usedFontResourceNames.has(e.resourceName)),n=t.map(t=>{if("unicode"===t.kind){const n=this.unicodeFontStates.get(t.resourceName);if(n)return this.addUnicodeFontObjects(n,e)}return e(function(e){switch(e.kind){case"base14":return`<< /Type /Font /Subtype /Type1 /BaseFont /${e.baseFont} /Encoding /WinAnsiEncoding >>`;case"unicode":return"<< /Type /Font /Subtype /Type0 /BaseFont /OasisPending /Encoding /Identity-H >>"}}(t))});return{resourceXml:t.map((e,t)=>`/${e.resourceName} ${n[t]} 0 R`).join(" ")}}layoutUnicodeText(e,t,n){const r=`${n?.join(",")??""}\0${t}`,o=e.layoutCache.get(r);if(o)return o;const a=e.font.layouter.layout(t,n);return e.layoutCache.set(r,a),a}encodeUnicodeGlyphRun(e,t){return t.glyphs.map((n,r)=>{e.usedGlyphs.has(n.id)||e.usedGlyphs.set(n.id,n);const o=t.positions[r],a=n.advanceWidth*e.scale,i=(o?.xAdvance??n.advanceWidth)*e.scale;return{glyphId:n.id,nominalWidth:a,desiredAdvance:i}})}addUnicodeFontObjects(e,t){const n=e.font.subsetter.createSubset(e.font.program,e.usedGlyphs.values()),r=n.fontFile,o=t(iy(r,[`/Length1 ${r.byteLength}`])),a=e.font.program.metadata,i=a.familyClass>>8||0;let s=4;a.isFixedPitch&&(s|=1),i>=1&&i<=7&&(s|=2),10===i&&(s|=8),a.macStyleItalic&&(s|=64);const l=`${ty(`${e.resource.resourceName}AAAAAA`,"OASISF").slice(0,6).padEnd(6,"A")}+${ty(a.postscriptName,e.resource.family)}`,c=a.bbox,d=t(["<< /Type /FontDescriptor",`/FontName /${l}`,`/Flags ${s}`,`/FontBBox [${[c.minX*e.scale,c.minY*e.scale,c.maxX*e.scale,c.maxY*e.scale].map(Zb).join(" ")}]`,`/ItalicAngle ${Zb(a.italicAngle)}`,`/Ascent ${Zb(a.ascent*e.scale)}`,`/Descent ${Zb(a.descent*e.scale)}`,`/CapHeight ${Zb(a.capHeight*e.scale)}`,`/XHeight ${Zb(a.xHeight*e.scale)}`,"/StemV 0",`/FontFile2 ${o} 0 R`,">>"].join("\n")),u=[...e.usedGlyphs.keys()],p=Math.max(0,...u),f=new Uint8Array(2*(p+1)),g=new DataView(f.buffer);for(const v of u)g.setUint16(2*v,n.encodeGlyph(v));const m=u.every(e=>n.encodeGlyph(e)===e)?"/Identity":t(iy(f))+" 0 R",h=t(["<< /Type /Font","/Subtype /CIDFontType2",`/BaseFont /${l}`,"/CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >>",`/FontDescriptor ${d} 0 R`,`/W [${sy(n.widths,e.usedGlyphs.keys())}]`,`/CIDToGIDMap ${m}`,">>"].filter(Boolean).join("\n")),b=function(e){const t=[...e].filter(([e,t])=>e>=0&&e<=65535&&t.length>0).sort(([e],[t])=>e-t).map(([e,t])=>"<"+Jb(e)+"> <"+oy([...t])+">"),n=[];for(let r=0;r<t.length;r+=100){const e=t.slice(r,r+100);n.push(e.length+" beginbfchar",...e,"endbfchar")}return["/CIDInit /ProcSet findresource begin","12 dict begin","begincmap","/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def","/CMapName /Adobe-Identity-UCS def","/CMapType 2 def","1 begincodespacerange","<0000><ffff>","endcodespacerange",...n,"endcmap","CMapName currentdict /CMap defineresource pop","end","end",""].join("\n")}(new Map([...e.usedGlyphs].map(([e,t])=>[e,t.codePoints]))),y=t(iy((new TextEncoder).encode(b)));return t(["<< /Type /Font","/Subtype /Type0",`/BaseFont /${l}`,"/Encoding /Identity-H",`/DescendantFonts [${h} 0 R]`,`/ToUnicode ${y} 0 R`,">>"].join("\n"))}},qy=class{imageResources=/* @__PURE__ */new Map;registerImageResource(e){const t=e.resourceName??`Im${this.imageResources.size+1}`;return this.imageResources.has(t)||this.imageResources.set(t,{resourceName:t,width:Math.max(1,Math.round(e.width)),height:Math.max(1,Math.round(e.height)),data:e.data,filter:e.filter}),t}has(e){return this.imageResources.has(e)}buildImageObjects(e){const t=/* @__PURE__ */new Map;for(const n of this.imageResources.values())t.set(n.resourceName,this.addImageObject(n,e));return t}addImageObject(e,t){return t(ay(e.data,["/Filter /DCTDecode","/Type /XObject","/Subtype /Image",`/Width ${e.width}`,`/Height ${e.height}`,"/ColorSpace /DeviceRGB","/BitsPerComponent 8"]))}},Gy=class{shadings=[];register(e){const t=`Sh${this.shadings.length+1}`;return this.shadings.push({name:t,spec:e}),t}buildShadingObjects(e){const t=/* @__PURE__ */new Map;for(const{name:n,spec:r}of this.shadings)t.set(n,this.addShadingObject(r,e));return t}addShadingObject(e,t){const n=t(function(e){if(2===e.length)return Yy(e[0].rgb,e[1].rgb);const t=[];for(let o=0;o<e.length-1;o+=1)t.push(Yy(e[o].rgb,e[o+1].rgb));const n=e.slice(1,-1).map(e=>Zb(e.offset)),r=e.slice(0,-1).map(()=>"0 1").join(" ");return["<< /FunctionType 3","/Domain [0 1]",`/Functions [${t.join(" ")}]`,`/Bounds [${n.join(" ")}]`,`/Encode [${r}]`,">>"].join("\n")}(function(e){const t=e.map(e=>({offset:Math.min(1,Math.max(0,e.offset)),rgb:Qb(e.color,[0,0,0])})).sort((e,t)=>e.offset-t.offset);if(0===t.length)return[{offset:0,rgb:[0,0,0]},{offset:1,rgb:[0,0,0]}];if(1===t.length)return[{offset:0,rgb:t[0].rgb},{offset:1,rgb:t[0].rgb}];t[0].offset=0,t[t.length-1].offset=1;for(let n=1;n<t.length-1;n+=1){const e=t[n-1].offset+1e-4;t[n].offset<=e&&(t[n].offset=Math.min(.9999,e))}return t}(e.stops)));return t(["<< /ShadingType 2","/ColorSpace /DeviceRGB",`/Coords [${[e.x0,e.y0,e.x1,e.y1].map(Zb).join(" ")}]`,"/Domain [0 1]",`/Function ${n} 0 R`,"/Extend [true true]",">>"].join("\n"))}};function Yy(e,t){return["<< /FunctionType 2","/Domain [0 1]",`/C0 [${e.map(Zb).join(" ")}]`,`/C1 [${t.map(Zb).join(" ")}]`,"/N 1",">>"].join("\n")}var Zy=new TextEncoder;function Jy(e){return"string"==typeof e?(t=e,(new TextEncoder).encode(t).byteLength):e.length;var t}function Qy(e){return iy(Zy.encode(e))}function ev(e){return e.replace(/[\\()]/g,e=>`\\${e}`)}function tv(e){return`<FEFF${oy(Array.from(e).map(e=>e.codePointAt(0)??63))}>`}function nv(e){const t=[];if(e.title&&t.push(`/Title ${tv(e.title)}`),e.author&&t.push(`/Author ${tv(e.author)}`),e.subject&&t.push(`/Subject ${tv(e.subject)}`),e.keywords&&t.push(`/Keywords ${tv(e.keywords)}`),e.producer&&t.push(`/Producer (${ev(e.producer)})`),e.creationDate&&t.push(`/CreationDate (${function(e){const t=(e,t=2)=>String(e).padStart(t,"0");return`D:${e.getUTCFullYear()}${t(e.getUTCMonth()+1)}${t(e.getUTCDate())}${t(e.getUTCHours())}${t(e.getUTCMinutes())}${t(e.getUTCSeconds())}+00'00'`}(e.creationDate)})`),0!==t.length)return`<< ${t.join(" ")} >>`}function rv(e){return e.children.reduce((e,t)=>e+1+rv(t),0)}function ov(e,t,n,r,o=[],a=[],i){const s=[],l=e=>{const t=s.length+1;return s.push({id:t,body:e}),t},c=l(""),d=l(""),{resourceXml:u}=t.buildFontObjects(l),p=n.buildImageObjects(l),f=r.buildShadingObjects(l),g=/* @__PURE__ */new Map;for(const A of e)for(const[e,t]of A.graphicsStateOpacities??[])g.has(e)||g.set(e,l(`<< /Type /ExtGState /ca ${Zb(t)} /CA ${Zb(t)} >>`));const m=[];for(const A of e){const e=l(Qy(`${A.commands.join("\n")}\n`)),t=Array.from(A.imageResourceNames).map(e=>{const t=p.get(e);return t?`/${e} ${t} 0 R`:""}).filter(Boolean).join(" "),n=t?` /XObject << ${t} >>`:"",r=Array.from(A.shadingResourceNames).map(e=>{const t=f.get(e);return t?`/${e} ${t} 0 R`:""}).filter(Boolean).join(" "),o=r?` /Shading << ${r} >>`:"",a=Array.from(A.graphicsStateOpacities?.keys()??[]).map(e=>`/${e} ${g.get(e)} 0 R`).join(" "),i=a?` /ExtGState << ${a} >>`:"",s=A.annotations.map(e=>{const t=e.x,n=e.x+e.width,r=A.height-e.y-e.height,o=A.height-e.y,a=void 0!==e.destName?`/A << /Type /Action /S /GoTo /D (${ev(e.destName)}) >>`:`/A << /Type /Action /S /URI /URI (${ev(e.uri??"")}) >>`;return l(["<< /Type /Annot /Subtype /Link",`/Rect [${Zb(t)} ${Zb(r)} ${Zb(n)} ${Zb(o)}]`,"/Border [0 0 0]",a,">>"].join("\n"))}),c=s.length>0?`\n/Annots [${s.map(e=>`${e} 0 R`).join(" ")}]`:"",h=l(["<< /Type /Page",`/Parent ${d} 0 R`,`/MediaBox [0 0 ${Zb(A.width)} ${Zb(A.height)}]`,`/Resources << /Font << ${u} >>${n}${o}${i} >>`,`/Contents ${e} 0 R${c}`,">>"].join("\n"));m.push(h)}let h;const b=o.filter(e=>void 0!==m[e.pageIndex]).sort((e,t)=>e.name<t.name?-1:e.name>t.name?1:0);let y;b.length>0&&(h=l(`<< /Dests ${l(`<< /Names [${b.map(t=>{const n=m[t.pageIndex],r=e[t.pageIndex].height-t.y;return`(${ev(t.name)}) [${n} 0 R /XYZ ${Zb(t.x)} ${Zb(r)} null]`}).join(" ")}] >>`)} 0 R >>`));const v=new Set(b.map(e=>e.name)),x=function(e){const t=[],n=[];for(const r of e){const e={title:r.title,destName:r.destName,children:[]};for(;n.length>0&&n[n.length-1].level>=r.level;)n.pop();0===n.length?t.push(e):n[n.length-1].node.children.push(e),n.push({node:e,level:r.level})}return t}(a.filter(e=>v.has(e.destName)));if(x.length>0){y=l("");const e=t=>t.map(t=>{const n=l("");return t.id=n,t.childIds=e(t.children),n}),t=e(x),n=(e,t)=>{e.forEach((r,o)=>{const a=r,i=o>0?e[o-1]:void 0,l=o<e.length-1?e[o+1]:void 0,c=["<< /Title "+tv(r.title),`/Parent ${t} 0 R`,i?`/Prev ${i.id} 0 R`:"",l?`/Next ${l.id} 0 R`:"",`/Dest (${ev(r.destName)})`];a.childIds.length>0&&(c.push(`/First ${a.childIds[0]} 0 R`),c.push(`/Last ${a.childIds[a.childIds.length-1]} 0 R`),c.push(`/Count ${rv(r)}`)),c.push(">>"),s[a.id-1].body=c.filter(Boolean).join("\n"),n(r.children,a.id)})};n(x,y);const r=a.filter(e=>v.has(e.destName)).length;s[y-1].body=["<< /Type /Outlines",`/First ${t[0]} 0 R`,`/Last ${t[t.length-1]} 0 R`,`/Count ${r}`,">>"].join("\n")}let w;if(s[c-1].body=["<< /Type /Catalog",`/Pages ${d} 0 R`,void 0!==h?`/Names ${h} 0 R`:"",void 0!==y?`/Outlines ${y} 0 R`:"",void 0!==y?"/PageMode /UseOutlines":"",">>"].filter(Boolean).join("\n"),s[d-1].body=["<< /Type /Pages",`/Kids [${m.map(e=>`${e} 0 R`).join(" ")}]`,`/Count ${m.length}`,">>"].join("\n"),i){const e=nv(i);e&&(w=l(e))}const I=[Gb];let S=Jy(Gb);const C=[0],k=e=>{I.push(e),S+=Jy(e)};for(const A of s)C[A.id]=S,k(`${A.id} 0 obj\n`),k(A.body),k("\nendobj\n");const T=S;let P=`xref\n0 ${s.length+1}\n`;P+="0000000000 65535 f \n";for(const A of s)P+=`${String(C[A.id]??0).padStart(10,"0")} 00000 n \n`;k(P);const R=void 0!==w?` /Info ${w} 0 R`:"";return k(["trailer",`<< /Size ${s.length+1} /Root ${c} 0 R${R} >>`,"startxref",String(T),"%%EOF",""].join("\n")),function(e){const t=e.reduce((e,t)=>e+Jy(t),0),n=new Uint8Array(t);let r=0;for(const o of e){const e="string"==typeof o?Zy.encode(o):o;n.set(e,r),r+=e.length}return n}(I)}var av=class{pages=[];streams=[];fonts;images=new qy;shadings=new Gy;namedDestinations=[];outlineItems=[];documentInfo;constructor(e=Yb){this.fonts=new Xy(e)}registerFontResource(e){this.fonts.registerFontResource(e)}addPage(e){const t={width:Math.max(1,e.width),height:Math.max(1,e.height),commands:[],imageResourceNames:/* @__PURE__ */new Set,shadingResourceNames:/* @__PURE__ */new Set,annotations:[],graphicsStateOpacities:/* @__PURE__ */new Map};return this.pages.push(t),this.streams.push(new uy(t,this.fonts,this.images,this.shadings)),this.pages.length-1}getPageCount(){return this.pages.length}drawRect(e,t){this.streams[e]?.drawRect(t)}drawLine(e,t){this.streams[e]?.drawLine(t)}drawPath(e,t){this.streams[e]?.drawPath(t)}saveGraphicsState(e){this.streams[e]?.saveGraphicsState()}restoreGraphicsState(e){this.streams[e]?.restoreGraphicsState()}setOpacity(e,t){this.streams[e]?.setOpacity(t)}rotateAbout(e,t,n,r){this.streams[e]?.rotateAbout(t,n,r)}clipRect(e,t,n,r,o){this.streams[e]?.clipRect(t,n,r,o)}clipPath(e,t){this.streams[e]?.clipPath(t)}drawText(e,t){this.streams[e]?.drawText(t)}registerAxialGradient(e,t){return this.streams[e]?.registerAxialGradient(t)??null}registerImageResource(e){return this.images.registerImageResource(e)}drawImage(e,t){this.streams[e]?.drawImage(t)}addLinkAnnotation(e,t){this.pages[e]?.annotations.push(t)}addNamedDestination(e){this.namedDestinations.some(t=>t.name===e.name)||this.namedDestinations.push(e)}addOutlineItem(e){this.outlineItems.push(e)}setDocumentInfo(e){this.documentInfo=e}toArrayBuffer(){const e=this.toUint8Array();return Uint8Array.from(e).buffer}toBlob(){return new Blob([this.toArrayBuffer()],{type:"application/pdf"})}toUint8Array(){return 0===this.pages.length&&this.addPage({width:612,height:792}),ov(this.pages,this.fonts,this.images,this.shadings,this.namedDestinations,this.outlineItems,this.documentInfo)}};function iv(e,t,n,r,o){if(0!==r.size||0!==o.size)return(a,i)=>{const s=or(i),l=or(n);for(const n of r.get(a)??[])e.addNamedDestination({name:n,pageIndex:t,x:l,y:s});const c=o.get(a);if(c){const n=`__oasis_heading_${a}`;e.addNamedDestination({name:n,pageIndex:t,x:l,y:s}),e.addOutlineItem({title:c.title,level:c.level,destName:n})}}}async function sv(e){e=Pa(e);const t=new qb,n=y(e);await t.loadBundledUnicodeFaces({families:n}),await t.loadRemoteWebFontFaces({families:n});const r=new av(t.getPdfFontResources());r.setDocumentInfo(function(e){const t=e.metadata??{},n=e=>"string"==typeof e&&""!==e.trim()?e:void 0;return{title:n(t.title),author:n(t.author),subject:n(t.subject),keywords:n(t.keywords),producer:"Oasis Editor",creationDate:/* @__PURE__ */new Date}}(e));const o=f(e),a=function(e){return Io(e)}(e),i=function(e){const t=/* @__PURE__ */new Map,n=e.bookmarks;if(!n)return t;for(const r of n.order){const e=n.items[r],o=e?.start?.paragraphId;if(!e||!o)continue;const a=t.get(o)??[];a.push(e.name),t.set(o,a)}return t}(e),s=new Map(Bt(e).map(e=>[e.id,{level:e.level,title:e.text}]));for(const l of o.pages){const n=Math.max(1,or(l.pageSettings.width)),o=Math.max(1,or(l.pageSettings.height)),c=r.addPage({width:n,height:o});await Vb(r,c,n,o,e.design,e.sections?.[l.sectionIndex??0]?.pageBorder,e);const d=l.pageSettings.margins.left+l.pageSettings.margins.gutter,u=sa(l.pageSettings);await Ub(r,c,l.headerBlocks,e,d,l.headerTop??Si(l.pageSettings),u,t,a,l.pageSettings);const p=l.bodyTop??Fa(l.pageSettings);if(l.blocks.some(e=>void 0!==e.columnIndex)){const n=Aa(l.pageSettings),o=/* @__PURE__ */new Map;for(const e of l.blocks){const t=e.columnIndex??0,n=o.get(t)??[];n.push(e),o.set(t,n)}for(const[d,u]of o){const o=n[d]??n[0];await Ub(r,c,u,e,o.left,p,o.width,t,a,l.pageSettings,iv(r,c,o.left,i,s))}}else await Ub(r,c,l.blocks,e,d,p,u,t,a,l.pageSettings,iv(r,c,d,i,s));await Ub(r,c,l.footerBlocks,e,d,l.footerTop??l.bodyBottom??l.pageSettings.height,u,t,a,l.pageSettings),l.footnoteBlocks&&l.footnoteBlocks.length>0&&void 0!==l.footnoteTop&&(void 0!==l.footnoteSeparatorTop&&r.drawLine(c,{x1:or(d),y1:or(l.footnoteSeparatorTop+.5),x2:or(d+Math.min(180,.35*u)),y2:or(l.footnoteSeparatorTop+.5),stroke:"#64748b",lineWidth:or(1)}),await cv(r,c,l.footnoteBlocks,l.footnoteReferenceIds??[],e,d,l.footnoteTop,u,t,a))}if(0===r.getPageCount()){const t=r.addPage({width:612,height:792});await Vb(r,t,612,792,e.design,void 0,e)}return r.toArrayBuffer()}async function lv(e){const t=await sv(e);return new Blob([t],{type:"application/pdf"})}async function cv(e,t,n,r,o,a,i,s,l,c){let d=i;const u=/* @__PURE__ */new Set,p=new Map(r.map(e=>[e,Ta(o,e)?.run.text??""]));for(const f of n){const n=r.find(e=>f.blockId.startsWith(`${e}:`));if(n&&!u.has(n)){const r=p.get(n);if(r){const n="paragraph"===f.sourceBlock.type?f.sourceBlock:void 0,i=pi(void 0,n?.style?.styleId,o.styles),s=l.resolveFontFace({fontFamily:i.fontFamily,bold:i.bold,italic:i.italic});e.drawText(t,{x:or(a),y:or(d+12),text:r,fontSize:kt(i),color:i.color??"#000000",bold:i.bold,italic:i.italic,fontResourceName:s.writerResourceName})}u.add(n)}await Ub(e,t,[f],o,a+24,d,Math.max(24,s-24),l,c),d+=Math.max(0,f.estimatedHeight)+2}}function dv(e,t){const n=URL.createObjectURL(e),r=document.createElement("a");r.href=n,r.download=t,r.click(),URL.revokeObjectURL(n)}function uv(e){return new Promise(t=>{const n=URL.createObjectURL(e),r=document.createElement("iframe");r.setAttribute("aria-hidden","true"),r.style.position="fixed",r.style.right="0",r.style.bottom="0",r.style.width="0",r.style.height="0",r.style.border="0";let o=!1;const a=()=>{o||(o=!0,r.remove(),URL.revokeObjectURL(n),t())},i=()=>{if(!o){if(!window.open(n,"_blank")){const e=document.createElement("a");e.href=n,e.download="oasis-editor.pdf",e.click()}a()}};r.addEventListener("load",()=>{try{const e=r.contentWindow;if(!e)return void i();e.addEventListener("afterprint",a),globalThis.setTimeout(a,6e4),e.focus(),e.print()}catch{i()}}),r.src=n,document.body.appendChild(r)})}async function pv(e){return"function"==typeof e.arrayBuffer?e.arrayBuffer():new Promise((t,n)=>{const r=new FileReader;r.onerror=()=>n(r.error??/* @__PURE__ */new Error("Failed to read file.")),r.onload=()=>{const e=r.result;e instanceof ArrayBuffer?t(e):n(/* @__PURE__ */new Error("Failed to read file as ArrayBuffer."))},r.readAsArrayBuffer(e)})}function fv(e){if(!e)return null;for(const t of Array.from(e.items??[])){if("file"!==t.kind)continue;const e=t.getAsFile();if(e&&e.type.startsWith("image/"))return e}for(const t of Array.from(e.files??[]))if(t.type.startsWith("image/"))return t;return null}function gv(e){return function(e){const t=ci(e),n=/* @__PURE__ */new Map,r=/* @__PURE__ */new Map;let o=0,a=0;for(const i of t){const t=ti(i.style,e.styles);r.set(t.align,(r.get(t.align)??0)+1);for(const r of i.runs){const t=pi(r.styles,i.style?.styleId,e.styles),s=t.fontFamily??"<null>";n.set(s,(n.get(s)??0)+1),null!==t.characterSpacing&&(o+=1),null!==t.characterScale&&(a+=1)}}return{paragraphCount:t.length,alignCounts:Array.from(r.entries()),fontCounts:Array.from(n.entries()),characterSpacingRuns:o,characterScaleRuns:a,firstParagraphs:t.slice(0,30).map((t,n)=>{const r=ti(t.style,e.styles),o=t.runs[0],a=pi(o?.styles,t.style?.styleId,e.styles);return{index:n,textLength:mi(t).length,runCount:t.runs.length,rawParagraphStyle:t.style,align:r.align,indentFirstLine:r.indentFirstLine,lineGridPitch:r.lineGridPitch,lineGridType:r.lineGridType,fontFamily:a.fontFamily,fontSize:a.fontSize,characterSpacing:a.characterSpacing,characterScale:a.characterScale,firstRunStyle:o?.styles}})}}(e)}function mv(e,t){if("inline"===t)return;const n={...e??{type:"floating",allowOverlap:!0,positionH:{relativeFrom:"column",offset:0},positionV:{relativeFrom:"paragraph",offset:0}},type:"floating"};switch(t){case"square":case"tight":case"through":case"topAndBottom":return{...n,wrap:t,behindDoc:!1};case"behind":return{...n,wrap:"none",behindDoc:!0};case"front":return{...n,wrap:"none",behindDoc:!1}}}function hv(e){return e?e.behindDoc?"behind":e.wrap&&"none"!==e.wrap?e.wrap:"front":"inline"}function bv(e,t){return{...e,positionV:{...e.positionV??{},relativeFrom:t?"page":"paragraph"}}}function yv(e){return"page"===e?.positionV?.relativeFrom}function vv(e){return Ki(e,e=>"image"===e.kind)}function xv(e,t,n){return Av(e,e=>({...e,width:Math.max(24,Math.round(t)),height:Math.max(24,Math.round(n))}))}function wv(e){return!e||!Number.isFinite(e)||e<0?0:Math.min(e,.99)}function Iv(e,t){return Av(e,e=>{const n={...e},r=function(e){if(!e)return;const t=wv(e.left),n=wv(e.top),r=wv(e.right),o=wv(e.bottom),a=Math.min(r,Math.max(0,.99-t)),i=Math.min(o,Math.max(0,.99-n));return 0!==t||0!==n||0!==a||0!==i?{left:t,top:n,right:a,bottom:i}:void 0}(t.crop);return r?n.crop=r:delete n.crop,void 0!==t.width&&(n.width=Math.max(24,Math.round(t.width))),void 0!==t.height&&(n.height=Math.max(24,Math.round(t.height))),n})}function Sv(e,t){const n=vv(e),r=n&&ki(n.run);return r?Iv(e,function(e,t){if("reset"===t)return{crop:null};const n=t,{width:r,height:o}=e;if(!Number.isFinite(n)||n<=0||r<=0||o<=0)return{crop:e.crop??null};const a=e.crop??{},i=wv(a.left),s=wv(a.top),l=wv(a.right),c=wv(a.bottom),d=r/o;if(d>n){const e=o*n,t=(r-e)/r*Math.max(0,1-i-l);return{crop:{...a,left:i+t/2,right:l+t/2},width:e}}if(d<n){const e=r/n,t=(o-e)/o*Math.max(0,1-s-c);return{crop:{...a,top:s+t/2,bottom:c+t/2},height:e}}return{crop:e.crop??null}}(r,t)):e}function Cv(e){const t=e.intrinsicWidth??e.width,n=e.intrinsicHeight??e.height,r=t>0&&n>0?t/n:e.width/Math.max(1,e.height),o=e.width/Math.max(1,e.height);if(!Number.isFinite(r)||!Number.isFinite(o))return{};if(r>o){const e=o/r,t=Math.max(0,(1-e)/2);return{left:t,right:t}}if(r<o){const e=r/o,t=Math.max(0,(1-e)/2);return{top:t,bottom:t}}return{}}function kv(e){return Av(e,e=>{const t={...e};return delete t.crop,delete t.cropFit,delete t.cropShape,t})}function Tv(e){if(!Number.isFinite(e))return;const t=(Math.round(e)%360+360)%360;return 0===t?void 0:t}function Pv(e,t,n=90){const r=vv(e);if(!r||!ki(r.run))return e;const o="right"===t?-n:n,a=Tv(function(e){const t=vv(e);return(t&&ki(t.run))?.rotation??0}(e)+o);return Av(e,e=>({...e,rotation:a}))}function Rv(e,t){const n=function(e){const t=vv(e),n=t&&ki(t.run);return n?{flipH:Boolean(n.flipH),flipV:Boolean(n.flipV)}:null}(e);return n?Av(e,"horizontal"===t?e=>({...e,flipH:!n.flipH}):e=>({...e,flipV:!n.flipV})):e}function Av(e,t){const n=vv(e);if(!n||!ki(n.run))return e;const r=ko(e),{paragraphIndex:o,run:a}=n,i=r.map((e,n)=>n!==o?ho(e):{...ho(e),runs:e.runs.map(e=>e.id===a.id&&"image"===e.kind?{...e,image:t(e.image)}:na(e))});return Vt(e,i,H(i,Ri(e)))}function Mv(e,t){return Av(e,e=>{const n=t(e.floating);if(n)return{...e,floating:n};const{floating:r,...o}=e;return o})}function Ov(e,t){const n=vv(e);if(!n)return e;const r=ko(e),{paragraphIndex:o,offset:a,run:i}=n,s=Oi(r,t.paragraphId);if(s<0)return e;const l=r[s],c=wa(l,t),d=s===o&&c>a?c-1:c;if(s===o&&d===a)return e;const p=e=>N(e,[...Ln(e,0,a),...Ln(e,a+1,oi(e))]),f=(e,t)=>u(e,Math.max(0,Math.min(t,oi(e))),[di("",gt(e,t),ki(i))]),g=r.map((e,t)=>t===o&&t===s?f(p(e),d):t===o?p(e):t===s?f(e,d):Yo([e])[0]),m=g[s],h=Math.max(0,Math.min(d+1,oi(m)));return Vt(e,g,J(xi(m,h)))}function Bv(e,t,n,r=0){const o=sa(si(t));if(!n)return o;const a=K(t,n,r);return null!==a&&Number.isFinite(a)&&a>0?Math.min(o,a):o}function Fv(e){return{insertImageFromFile:async(t,n)=>{e.logger.info(`image insert:start name="${t.name}" type=${t.type} size=${t.size}`);const r=await pv(t),o=`data:${t.type};base64,${function(e){return btoa(new Uint8Array(e).reduce((e,t)=>e+String.fromCharCode(t),""))}(r)}`,a=new Image;a.src=o,await new Promise(e=>{a.onload=e,a.onerror=e});const i=a.naturalWidth||300,s=a.naturalHeight||300,l=e.state(),c=n?.paragraphId??l.selection.focus.paragraphId,d=Bv(e.surfaceRef(),l.document,c,l.activeSectionIndex??0),p=i>d?d/i:1,f=Math.max(24,Math.round(i*p)),g=Math.max(24,Math.round(s*p));e.logger.info(`image insert:decoded natural=${i}x${s} fitted=${f}x${g} maxWidth=${d}`),e.applyTransactionalState(e=>function(e,t){const n=ga(e.selection)?e:te(e),{paragraph:r,index:o,offset:a}=ae(n),i=di("",gt(r,a),t),s=u(r,a,[i]),l=ko(n).map((e,t)=>t===o?s:ho(e));return Vt(n,l,J(xi(s,a+1)))}(n?ji(e,{anchor:n,focus:n}):e,{src:o,width:f,height:g,intrinsicWidth:i,intrinsicHeight:s}),{mergeKey:Qp})}}}var Ev={"reading-file":[0,8],opening:[8,20],parsing:[20,72],finishing:[72,78],"preparing-fonts":[78,90],"applying-editor-state":[90,94],"stabilizing-layout":[94,99],done:[100,100],error:[100,100]};function Dv(e){return function(e){const[t,n]=Nt(null),r=(e,t)=>{const[n,r]=Ev[e];return void 0!==t&&Number.isFinite(t)?Math.round(10*(n+(r-n)*Math.min(1,Math.max(0,t))))/10:r},o=(e,t)=>{n({phase:e,progress:r(e,t),subProgress:t})},i=()=>{globalThis.setTimeout(()=>{n(e=>"done"===e?.phase||"error"===e?.phase?null:e)},1200)},s=function(e){return{handleImportFile:async t=>{if(!t)return;const n=a(t);if(!n)return e.setImportPhase("error"),e.logger.error("import:unsupported-format",{name:t.name,type:t.type}),void e.clearImportProgressSoon();const r=e.now();e.logger.info("import:start",{format:n.id,name:t.name,size:t.size}),e.setImportPhase("reading-file");const o="docx"===n.id?e.requestLocalFontAccess().catch(()=>!1):Promise.resolve(!1);try{const a=e.now(),i=await pv(t);e.logger.info("import:phase",{phase:"reading-file",durationMs:Zt(e.now()-a,2)});let s=null,l=-1,c=0;const d=await n.import(i,(t,n)=>{const r=e.now(),o=void 0!==n&&Number.isFinite(n)?Math.floor(100*n):void 0,a=t!==s;if(!(a||void 0!==o&&(l<0||o-l>=1)||r-c>=40))return;s=t,l=o??l,c=r,e.setImportPhase(t,n);const i={phase:t,subProgress:n};a||void 0===n||1===n?e.logger.info("import:phase",i):e.logger.debug("import:phase",i)});e.logger.debug("import:document-diagnostics",gv(d));const u=e.now();e.setImportPhase("preparing-fonts"),await o,await e.prepareDocumentFonts(d),e.logger.info("import:phase",{phase:"preparing-fonts",durationMs:Zt(e.now()-u,2)}),e.setImportPhase("applying-editor-state"),e.resetEditorChromeState(),e.applyState(Za(d));const p=e.now();e.setImportPhase("stabilizing-layout"),await e.stabilizeLayoutAfterImport(),e.logger.info("import:phase",{phase:"stabilizing-layout",durationMs:Zt(e.now()-p,2)});const f=Hr(d).reduce((e,t)=>e+(t.header?.length??0)+t.blocks.length+(t.footer?.length??0),0),g=bo(d).length;e.setImportPhase("done"),e.logger.info("import:done",{format:n.id,blocks:f,paragraphs:g,durationMs:Zt(e.now()-r,2)}),e.focusInput()}catch(i){e.setImportPhase("error"),e.logger.error("import:error",i)}finally{e.clearImportProgressSoon()}}}}({applyState:e.applyState,stabilizeLayoutAfterImport:e.stabilizeLayoutAfterImport,resetEditorChromeState:e.resetEditorChromeState,focusInput:e.focusInput,requestLocalFontAccess:e.requestLocalFontAccess,prepareDocumentFonts:e.prepareDocumentFonts,setImportPhase:o,clearImportProgressSoon:i,now:()=>performance.now(),logger:e.logger}),l=Fv({state:e.state,applyTransactionalState:e.applyTransactionalState,surfaceRef:e.surfaceRef,logger:e.logger}),c=function(e){const t=e.download??dv,n=e.print??uv;let r=!1;return{handleExportDocx:async()=>{const n=await pu(e.document());return t(n,"oasis-editor.docx"),e.focusInput(),n},handleExportPdf:async()=>{const n=await lv(e.document());return t(n,"oasis-editor.pdf"),e.focusInput(),n},handlePrint:async()=>{const t=await lv(e.document());if(!r){r=!0;try{await n(t)}finally{r=!1}}return e.focusInput(),t},exportDocxBlob:()=>pu(e.document()),exportPdfBlob:()=>lv(e.document())}}({document:()=>e.state().document,focusInput:e.focusInput}),d=async t=>{e.isReadOnly()||await s.handleImportFile(t)},u=async(e,t)=>{await l.insertImageFromFile(e,t)},p=async t=>{e.isReadOnly()||t&&(await u(t),e.focusInput())};return{importProgress:t,handleImportFile:d,handleExportDocx:async()=>c.handleExportDocx(),handleExportPdf:async()=>c.handleExportPdf(),handlePrint:async()=>c.handlePrint(),exportDocxBlob:c.exportDocxBlob,exportPdfBlob:c.exportPdfBlob,insertImageFromFile:u,handleInsertImage:p}}(e)}function Lv(e,t){return e.paragraph.runs.map(e=>e.text).join("")[t]??""}function Nv(e){return" "===e||"\t"===e||"\n"===e}function zv(e,t,n){if(n.isCollapsed)return null;const r=t.get(e);return void 0===r||r<n.startIndex||r>n.endIndex?null:n.startIndex===n.endIndex?{start:n.startParagraphOffset,end:n.endParagraphOffset}:e===n.start.paragraphId?{start:n.startParagraphOffset,end:Number.POSITIVE_INFINITY}:e===n.end.paragraphId?{start:0,end:n.endParagraphOffset}:{start:0,end:Number.POSITIVE_INFINITY}}function $v(e,t){if(!e)return null;for(const n of e)if("table"===n.type){if(n.id===t)return n;for(const e of n.rows)for(const n of e.cells){const e=$v(n.blocks,t);if(e)return e}}return null}function Hv(e,t){const n=Ri(t),r=[],o=e.surfaceRect,a=new Map(ko(t).map((e,t)=>[e.id,t]));let i=null,s=null;if(!n.isCollapsed&&n.startIndex===n.endIndex&&n.endParagraphOffset-n.startParagraphOffset===1){const t=e=>e.paragraphId===n.start.paragraphId&&e.startOffset===n.startParagraphOffset&&e.endOffset===n.endParagraphOffset,r=e.inlineImages.find(t)??e.floatingImages.find(t);if(r&&(i={paragraphId:r.paragraphId,startOffset:r.startOffset,endOffset:r.endOffset,left:r.left-o.left,top:r.top-o.top,width:r.width,height:r.height,rotation:r.rotation??0}),!i){const t=e=>e.paragraphId===n.start.paragraphId&&e.startOffset===n.startParagraphOffset&&e.endOffset===n.endParagraphOffset,r=e.floatingTextBoxes.find(t),a=r?void 0:e.inlineTextBoxes.find(t),i=r??a;i&&(s={paragraphId:i.paragraphId,startOffset:i.startOffset,endOffset:i.endOffset,left:i.left-o.left,top:i.top-o.top,width:i.width,height:i.height,rotation:i.rotation??0,floating:Boolean(r)})}}const l=(e.paragraphsById.get(t.selection.anchor.paragraphId)??[]).find(e=>e.tableCell)?.tableCell,c=(e.paragraphsById.get(t.selection.focus.paragraphId)??[]).find(e=>e.tableCell)?.tableCell;let d=!1;if(l&&c&&l.tableId===c.tableId&&(l.rowIndex!==c.rowIndex||l.cellIndex!==c.cellIndex)){const n=function(e,t){for(const n of Lo(e))for(const e of[n.blocks,n.header,n.firstPageHeader,n.evenPageHeader,n.footer,n.firstPageFooter,n.evenPageFooter]){const n=$v(e,t);if(n)return n}for(const n of Object.values(e.footnotes?.items??{})){const e=$v(n.blocks,t);if(e)return e}return null}(t.document,l.tableId);if(n){const t=Xa(n),a=t.find(e=>e.rowIndex===l.rowIndex&&e.cellIndex===l.cellIndex),i=t.find(e=>e.rowIndex===c.rowIndex&&e.cellIndex===c.cellIndex);if(a&&i){d=!0;const s=Math.min(a.visualRowIndex,i.visualRowIndex),l=Math.max(a.visualRowIndex+a.rowSpan-1,i.visualRowIndex+i.rowSpan-1),c=Math.min(a.visualColumnIndex,i.visualColumnIndex),u=Math.max(a.visualColumnIndex+a.colSpan-1,i.visualColumnIndex+i.colSpan-1),p=/* @__PURE__ */new Set;for(const a of e.paragraphs)if(a.tableCell&&a.tableCell.tableId===n.id){const e=t.find(e=>e.rowIndex===a.tableCell.rowIndex&&e.cellIndex===a.tableCell.cellIndex);if(e){const t=e.visualRowIndex<=l&&e.visualRowIndex+e.rowSpan-1>=s,n=e.visualColumnIndex<=u&&e.visualColumnIndex+e.colSpan-1>=c;if(t&&n){const t=`${e.rowIndex}:${e.cellIndex}`;p.has(t)||(p.add(t),r.push({left:a.tableCell.left-o.left,top:a.tableCell.top-o.top,width:a.tableCell.width,height:a.tableCell.height}))}}}}}}if(!(d||n.isCollapsed||i||s))for(const w of e.paragraphs){const e=zv(w.paragraphId,a,n);if(!e)continue;const t=Math.max(e.start,w.startOffset),i=Math.min(e.end,w.endOffset);if(!(t>=i))for(const n of w.lines){let e=Math.max(t,n.startOffset),a=Math.min(i,n.endOffset);for(;e<a&&Nv(Lv(w,e));)e+=1;for(;a>e&&Nv(Lv(w,a-1));)a-=1;if(e>=a)continue;const s=n.slots.find(t=>t.offset===e),l=n.slots.find(e=>e.offset===a)??n.slots[n.slots.length-1];if(!s||!l)continue;const c=0===w.startOffset&&n.startOffset===w.startOffset&&n.top>w.top,d=c?w.top:n.top,u=c?n.top+n.height-w.top:n.height;r.push({left:s.left-o.left+1,top:d-o.top,width:Math.max(1,l.left-s.left+1-1),height:u})}}const u=t.selection.focus.paragraphId,p=e.paragraphsById.get(u)??[],f=p[0]?.paragraph,g=function(e,t){if(0===e.length)return null;const n=e.find(e=>t>=e.startOffset&&t<=e.endOffset)??e[e.length-1],r=n.lines.flatMap(e=>e.slots);if(0===r.length)return{left:n.left,top:n.top,height:Math.max(18,n.height)};let o=r[0],a=Math.abs(t-o.offset);for(const s of r){const e=Math.abs(t-s.offset);e<a&&(o=s,a=e)}const i=n.lines[0];return 0===n.startOffset&&void 0!==i&&t>=i.startOffset&&t<=i.endOffset&&o.top>n.top?{left:o.left,top:n.top,height:o.top+o.height-n.top}:{left:o.left,top:o.top,height:o.height}}(p,f?wa(f,t.selection.focus):t.selection.focus.offset),m=(g?.left??o.left)-o.left,h=(g?.top??o.top)-o.top,b=Math.max(18,g?.height??28),y={left:m,top:h,height:b,visible:p.length>0&&!d&&!i&&!s};let v=null;const x=(e.paragraphsById.get(u)??[])[0]?.tableCell?.tableId??null;if(x){let t=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(const o of e.paragraphs){const e=o.tableCell;e&&e.tableId===x&&(t=Math.min(t,e.left),n=Math.min(n,e.top),r=Math.max(r,e.left+e.width),a=Math.max(a,e.top+e.height))}Number.isFinite(t)&&r>t&&a>n&&(v={tableId:x,left:t-o.left,top:n-o.top,width:r-t,height:a-n})}return{selectionBoxes:r,inputBox:{left:m,top:h,height:b},caretBox:y,selectedImageBox:i,selectedTextBoxBox:s,selectedTableBox:v}}function Wv(e,t){if(e)for(const n of e)if("paragraph"!==n.type)for(const e of n.rows)for(const n of e.cells)Wv(n.blocks,t);else t.push(n.id)}function jv(e){const t=[],n=e=>{if(e)for(const r of e)if("paragraph"!==r.type)for(const e of r.rows)for(const t of e.cells)n(t.blocks);else for(const e of r.runs)t.push(e.text)};return n(e),t.join("").trim()}function Uv(e){return e.cells.flatMap(e=>e.blocks)}function Vv(e){return e.rows.flatMap(Uv)}function Kv(e){return{id:e.id,type:e.type,author:e.author,date:e.date}}function _v(e){return{id:e.id,type:"property",author:e.author,date:e.date}}function Xv(e){const t=[];return e.style?.revision&&t.push(Kv(e.style.revision)),e.style?.propertyRevision&&t.push(_v(e.style.propertyRevision)),t}function qv(e){const t=[];return e.style?.revision&&t.push(Kv(e.style.revision)),e.style?.propertyRevision&&t.push(_v(e.style.propertyRevision)),e.propertyExceptionsRevision&&t.push(_v(e.propertyExceptionsRevision)),t}function Gv(e){const t=[];return e.style?.revision&&t.push(_v(e.style.revision)),e.gridRevision&&t.push({id:e.gridRevision.id,type:"grid",author:e.gridRevision.author,date:e.gridRevision.date}),t}function Yv(e){const t=[],n=/* @__PURE__ */new Set,r=(e,r,o,a,i,s)=>{if(n.has(e.id))return;n.add(e.id);const l=[];Wv(s,l),t.push({...e,scope:r,tableId:o,rowIndex:a,cellIndex:i,paragraphIds:l,snippet:jv(s)})},o=e=>{if(e)for(const t of e)if("paragraph"!==t.type){for(const e of Gv(t))r(e,"table",t.id,void 0,void 0,Vv(t));t.rows.forEach((e,n)=>{for(const o of qv(e))r(o,"row",t.id,n,void 0,Uv(e));e.cells.forEach((e,a)=>{for(const o of Xv(e))r(o,"cell",t.id,n,a,e.blocks);o(e.blocks)})})}};for(const a of Lo(e.document))for(const e of[a.blocks,a.header,a.firstPageHeader,a.evenPageHeader,a.footer,a.firstPageFooter,a.evenPageFooter])o(e);for(const a of Object.values(e.document.footnotes?.items??{}))o(a.blocks);for(const a of Object.values(e.document.endnotes?.items??{}))o(a.blocks);return t}function Zv(e){const t=[],n=/* @__PURE__ */new Set;return Lo(e.document).forEach((e,r)=>{const o=e.propertyRevision;if(!o||n.has(o.id))return;n.add(o.id);const a=[];Wv(e.blocks,a);const i=jv(e.blocks);t.push({id:o.id,type:"property",author:o.author,date:o.date,sectionId:e.id,sectionIndex:r,paragraphIds:a,snippet:i.length>96?`${i.slice(0,93)}…`:i})}),t}var Jv={insertions:"showMarkupInsertions",deletions:"showMarkupDeletions",comments:"showMarkupComments",formatting:"showMarkupFormatting"};function Qv(e,t){return e[Jv[t]]??!0}function ex(e,t){return"boolean"==typeof t.allAuthors?ox(e,t.allAuthors?void 0:[]):"string"==typeof t.author?function(e,t,n){const r=e.markupAuthors??[...n],o=ax(r.includes(t)?r.filter(e=>e!==t):[...r,t]),a=ax(n);return ox(e,o.length===a.length&&o.every((e,t)=>e===a[t])?void 0:o)}(e,t.author,sx(e)):t.section?function(e,t){const n=Jv[t],r=!(e[n]??!0);return e[n]===r?e:{...e,[n]:r}}(e,t.section):e}function tx(e,t){return e.markupAuthors?.includes(t)??!0}function nx(e,t,n){return!("insert"===t&&!Qv(e,"insertions"))&&(!("delete"===t&&!Qv(e,"deletions"))&&(!("property"===t&&!Qv(e,"formatting"))&&tx(e,n)))}function rx(e){const t=/* @__PURE__ */new Map;for(const n of Yv(e))if(nx(e,n.type,n.author))for(const e of n.paragraphIds)t.has(e)||t.set(e,null);for(const n of function(e){const t=[];for(const n of Zv(e))nx(e,n.type,n.author)&&t.push(...n.paragraphIds);return t}(e))t.has(n)||t.set(n,null);for(const n of ci(e.document)){const r=[];let o=0;for(const t of n.runs){const n=t.text.length,a=t.revision,i="delete"===a?.type,s=t.styles?.propertyRevision;let l=!1;!a||"insert"!==a.type&&"delete"!==a.type?s&&(l=nx(e,"property",s.author)):l=nx(e,a.type,a.author),l&&(i?r.push({start:Math.max(0,o-1),end:o+1}):n>0&&r.push({start:o,end:o+n})),i||(o+=n)}if(0===r.length)continue;const a=t.get(n.id);void 0===a?t.set(n.id,r):null!==a&&t.set(n.id,[...a,...r])}return t}function ox(e,t){return void 0===e.markupAuthors&&void 0===t||void 0!==e.markupAuthors&&void 0!==t&&e.markupAuthors.length===t.length&&e.markupAuthors.every((e,n)=>e===t[n])?e:{...e,markupAuthors:t}}function ax(e){return[...new Set(e)].sort()}function ix(e,t){for(const n of e.runs){const e=n.revision?.author??n.revisionRangeMarker?.author??n.styles?.propertyRevision?.author;e&&t.add(e)}}function sx(e){const t=/* @__PURE__ */new Set,n=e=>{e&&t.add(e)},r=e=>{if(e)for(const o of e)if("paragraph"!==o.type){n(o.style?.revision?.author),n(o.gridRevision?.author);for(const e of o.rows){n(e.style?.revision?.author),n(e.style?.propertyRevision?.author);for(const t of e.cells)n(t.style?.revision?.author),n(t.style?.propertyRevision?.author),r(t.blocks)}}else ix(o,t)},o=ci(e.document);for(const l of o)ix(l,t);for(const l of Lo(e.document)){for(const e of[l.blocks,l.header,l.firstPageHeader,l.evenPageHeader,l.footer,l.firstPageFooter,l.evenPageFooter])r(e);n(l.propertyRevision?.author)}const a=e.document.footnotes?.items??{};for(const l of Object.values(a))r(l.blocks);const i=e.document.endnotes?.items??{};for(const l of Object.values(i))r(l.blocks);const s=e.document.comments?.items??{};for(const l of Object.values(s)){const e=l.author??l.authorId;e&&t.add(e)}return[...t].sort((e,t)=>e.localeCompare(t))}function lx(e,t){const n=[];let r=0;for(const o of e.runs){const e=r,a=r+o.text.length;r=a;const i=o.revision,s=o.styles?.propertyRevision;let l,c,d;if(!i||"insert"!==i.type&&"delete"!==i.type?s&&(l=s.id,c="property",d=s.author):(l=i.id,c=i.type,d=i.author),void 0!==l&&void 0!==c&&void 0!==d&&nx(t,c,d)&&a>e){const t=n.at(-1);t&&t.revisionId===l&&t.type===c&&t.end===e?t.end=a:n.push({start:e,end:a,revisionId:l,type:c})}}return n}function cx(e,t){const n=e.surfaceRect,r=[];for(const o of e.paragraphs){const e=lx(o.paragraph,t);if(0!==e.length)for(const t of o.lines)for(const o of e){const e=Math.max(o.start,t.startOffset),a=Math.min(o.end,t.endOffset);if(e>=a)continue;const i=t.slots.find(t=>t.offset===e),s=t.slots.find(e=>e.offset===a)??t.slots[t.slots.length-1];i&&s&&r.push({revisionId:o.revisionId,type:o.type,left:i.left-n.left,top:t.top-n.top,width:Math.max(1,s.left-i.left),height:t.height})}}return r.push(...function(e,t){const{surfaceRect:n}=e,r=[],o=/* @__PURE__ */new Set;for(const i of e.paragraphs){const e=i.tableCell;if(!e)continue;const t=`${e.tableId}:${e.rowIndex}:${e.cellIndex}`;o.has(t)||(o.add(t),r.push({tableId:e.tableId,rowIndex:e.rowIndex,cellIndex:e.cellIndex,left:e.left,top:e.top,width:e.width,height:e.height}))}const a=[];for(const i of Yv(t)){if(!nx(t,i.type,i.author))continue;const e=r.filter(e=>e.tableId===i.tableId&&("table"===i.scope||e.rowIndex===i.rowIndex&&("row"===i.scope||e.cellIndex===i.cellIndex)));if(0===e.length)continue;const o=Math.min(...e.map(e=>e.left)),s=Math.min(...e.map(e=>e.top)),l=Math.max(...e.map(e=>e.left+e.width)),c=Math.max(...e.map(e=>e.top+e.height));a.push({revisionId:i.id,type:i.type,variant:"cell",left:o-n.left,top:s-n.top,width:l-o,height:c-s})}return a}(e,t)),r.push(...function(e,t){const{surfaceRect:n}=e,r=[];for(const o of Zv(t)){if(!nx(t,o.type,o.author))continue;const a=new Set(o.paragraphIds),i=/* @__PURE__ */new Map;for(const t of e.paragraphs){if(!a.has(t.paragraphId))continue;const e=i.get(t.pageIndex)??[];e.push(t),i.set(t.pageIndex,e)}for(const e of i.values()){const t=Math.min(...e.map(e=>e.left)),a=Math.min(...e.map(e=>e.top)),i=Math.max(...e.map(e=>e.left+e.width)),s=Math.max(...e.map(e=>e.top+e.height));r.push({revisionId:o.id,type:o.type,variant:"section",left:t-n.left,top:a-n.top,width:i-t,height:s-a})}}return r}(e,t)),r}var dx=e=>e.length>96?`${e.slice(0,93)}…`:e;function ux(e,t){const{surfaceRect:n}=e,r=e.paragraphs,o=/* @__PURE__ */new Map;for(const c of r){const e=c.left+c.width,t=o.get(c.pageIndex);(void 0===t||e>t)&&o.set(c.pageIndex,e)}const a=/* @__PURE__ */new Map;for(const c of e.pages??[]){const e=c.left+c.width,t=o.get(c.index)??e-Math.min(96,c.width),r=Math.max(0,e-t),i=Math.min(168,Math.max(84,r-16));a.set(c.index,{left:e-8-i-n.left,width:i})}const i=[];for(const c of function(e){const t=/* @__PURE__ */new Map,n=(e,n,r)=>{const o=t.get(e.id);if(o)return o.paragraphIds.push(...n),void(r&&o.snippetParts.push(r));t.set(e.id,{...e,paragraphIds:[...n],snippetParts:r?[r]:[]})};for(const r of ci(e.document))for(const e of r.runs){const t=e.revision,o=e.styles?.propertyRevision,a=!t||"insert"!==t.type&&"delete"!==t.type?o?{id:o.id,type:"property",author:o.author,date:o.date,scope:"run"}:void 0:{id:t.id,type:t.type,author:t.author,date:t.date,scope:"run"};a&&n(a,[r.id],e.text)}for(const r of Yv(e))n({id:r.id,type:r.type,author:r.author,date:r.date,scope:r.scope},r.paragraphIds,r.snippet);for(const r of Zv(e))n({id:r.id,type:r.type,author:r.author,date:r.date,scope:"section"},r.paragraphIds,r.snippet);return[...t.values()].map(e=>({id:e.id,type:e.type,author:e.author,date:e.date,scope:e.scope,snippet:dx(e.snippetParts.join("").trim()),paragraphIds:[...new Set(e.paragraphIds)]}))}(t)){if(!nx(t,c.type,c.author))continue;const e=new Set(c.paragraphIds);let o;for(const t of r)e.has(t.paragraphId)&&(!o||t.top<o.top)&&(o=t);if(!o||!a.has(o.pageIndex))continue;const s=o.lines[0];i.push({descriptor:c,pageIndex:o.pageIndex,top:(s?s.top:o.top)-n.top})}i.sort((e,t)=>e.pageIndex-t.pageIndex||e.top-t.top);const s=/* @__PURE__ */new Map,l=[];for(const c of i){const e=s.get(c.pageIndex)??-1/0,t=Math.max(c.top,e+6);s.set(c.pageIndex,t+58);const n=a.get(c.pageIndex),r=c.descriptor;l.push({revisionId:r.id,type:r.type,variant:"balloon",left:n.left,top:t,width:n.width,height:58,author:r.author,date:r.date,snippet:r.snippet})}return l}var px={composeMeasuredParagraphLines:e=>ft.composeMeasuredParagraphLines(e),resolveRenderedLineHeightPx:(e,t)=>ft.resolveRenderedLineHeightPx(e,t)};function fx(e,t){return(e?.length??0)===(t?.length??0)&&(t??[]).every((t,n)=>e?.[n]===t)}function gx(e,t){return(e?.length??0)===(t?.length??0)&&(t??[]).every((t,n)=>{const r=e?.[n];return r?.blockIndex===t.blockIndex&&r?.offset===t.offset})}function mx(){let e=/* @__PURE__ */new Map,t=/* @__PURE__ */new Map;return function(n){const r=/* @__PURE__ */new Map,o=t=>t?.map(t=>{const n=e.get(t.blockId),o=function(e,t){return Boolean(e&&e.blockId===t.blockId&&e.sourceBlock===t.sourceBlock&&e.estimatedHeight===t.estimatedHeight&&e.tableSegment?.startRowIndex===t.tableSegment?.startRowIndex&&e.tableSegment?.endRowIndex===t.tableSegment?.endRowIndex&&e.tableSegment?.repeatedHeaderRowCount===t.tableSegment?.repeatedHeaderRowCount&&fx(e.tableSegment?.startRowCellBlockStarts,t.tableSegment?.startRowCellBlockStarts)&&fx(e.tableSegment?.endRowCellBlockEnds,t.tableSegment?.endRowCellBlockEnds)&&gx(e.tableSegment?.startRowCellBlockPositions,t.tableSegment?.startRowCellBlockPositions)&&gx(e.tableSegment?.endRowCellBlockPositions,t.tableSegment?.endRowCellBlockPositions)&&function(e,t){return e===t||!(!e||!t)&&e.text===t.text&&e.startOffset===t.startOffset&&e.endOffset===t.endOffset&&e.lines.length===t.lines.length&&t.lines.every((t,n)=>{const r=e.lines[n];return void 0!==r&&r.startOffset===t.startOffset&&r.endOffset===t.endOffset&&r.top===t.top&&r.height===t.height})}(e.layout,t.layout))}(n,t)?n:t;return r.set(o.blockId,o),o}),a=n.pages.map(e=>{const n={...e,blocks:o(e.blocks)??[],headerBlocks:o(e.headerBlocks),footerBlocks:o(e.footerBlocks),footnoteBlocks:o(e.footnoteBlocks)},r=t.get(n.id);return function(e,t){const n=Boolean(e&&e.pageSettings.width===t.pageSettings.width&&e.pageSettings.height===t.pageSettings.height&&e.pageSettings.orientation===t.pageSettings.orientation&&e.pageSettings.margins.top===t.pageSettings.margins.top&&e.pageSettings.margins.right===t.pageSettings.margins.right&&e.pageSettings.margins.bottom===t.pageSettings.margins.bottom&&e.pageSettings.margins.left===t.pageSettings.margins.left&&e.pageSettings.margins.header===t.pageSettings.margins.header&&e.pageSettings.margins.footer===t.pageSettings.margins.footer&&e.pageSettings.margins.gutter===t.pageSettings.margins.gutter);if(!e||e.id!==t.id||e.index!==t.index||e.height!==t.height||e.maxHeight!==t.maxHeight||!n||e.bodyTop!==t.bodyTop||e.bodyBottom!==t.bodyBottom||e.headerTop!==t.headerTop||e.footerTop!==t.footerTop||e.footnoteTop!==t.footnoteTop||e.footnoteSeparatorTop!==t.footnoteSeparatorTop)return!1;const r=(e,t)=>(e?.length??0)===(t?.length??0)&&(t??[]).every((t,n)=>e?.[n]===t);return r(e.blocks,t.blocks)&&r(e.headerBlocks,t.headerBlocks)&&r(e.footerBlocks,t.footerBlocks)&&r(e.footnoteBlocks,t.footnoteBlocks)&&(o=e.footnoteReferenceIds,a=t.footnoteReferenceIds,(o?.length??0)===(a?.length??0)&&(a??[]).every((e,t)=>o?.[t]===e));var o,a}(r,n)?r:n});return e=r,t=new Map(a.map(e=>[e.id,e])),{pages:a}}}function hx(e,t){if(0===t.length)return e;let n;for(const r of t)Object.prototype.hasOwnProperty.call(e,r)&&(n??={...e},delete n[r]);return n??e}function bx(e){return function(e){const[t,n]=Nt({}),[r,o]=Nt({}),[a,i]=Nt({left:0,top:0,height:28}),[s,l]=Nt([]),[c,d]=Nt([]),[u,p]=Nt([]),[g,m]=Nt([]),[h,b]=Nt(null),[y,v]=Nt(null),[x,w]=Nt(null),[I,S]=Nt({left:0,top:0,height:28,visible:!1}),[C,k]=Nt(null),T=mx(),P=ur(()=>{Nr();const t=void 0===(n=e.state.reviewDisplayMode)||"all"===n?null:"original"===n?"original":"final";var n;return null===t?e.state.document:jn(e.state.document,t).document}),R=ur(()=>(Nr(),T(f(P(),void 0,t(),r(),{measurer:px})))),A=_n();let M=0;const O=(t="selection")=>{const n=e.surfaceRef();if(!n)return l([]),d([]),p([]),m([]),b(null),v(null),w(null),void S(e=>({...e,visible:!1}));const r=A.getCanvasLayoutSnapshot({surface:n,state:e.state,documentLayout:R(),zoomFactor:e.zoomFactor?.()});if(!r)return l([]),d([]),p([]),m([]),b(null),v(null),w(null),void S(e=>({...e,visible:!1}));const o=e.state.reviewDisplayMode??"all";if("all"!==o)return l([]),b(null),v(null),w(null),S({left:0,top:0,height:28,visible:!1}),i({left:0,top:0,height:28}),d([]),p([]),void m("simple"===o&&!1!==e.state.showRevisionMarkup?function(e,t){const n=rx(t);if(0===n.size)return[];const r=e.surfaceRect,o=/* @__PURE__ */new Map;for(const s of e.paragraphs){const e=o.get(s.pageIndex);(void 0===e||s.left<e)&&o.set(s.pageIndex,s.left)}const a=/* @__PURE__ */new Map;for(const s of e.pages??[]){const e=o.get(s.index),t=void 0===e?0:e-s.left;a.set(s.index,s.left+(t>0?.5*t:12)-r.left)}const i=[];for(const s of e.paragraphs){const e=n.get(s.paragraphId);if(void 0===e)continue;const t=a.get(s.pageIndex)??s.left-r.left-12,o=s.lines;if(0===o.length){i.push({paragraphId:s.paragraphId,left:t,top:s.top-r.top,height:Math.max(1,s.height)});continue}const l=null===e?o:o.filter(t=>e.some(e=>e.start<t.endOffset&&e.end>t.startOffset)),c=l.length>0?l:[o[0]];for(const n of c)i.push({paragraphId:s.paragraphId,left:t,top:n.top-r.top,height:Math.max(1,n.height)})}return i}(r,e.state):[]);const a=Hv(r,e.state);m([]),l(a.selectionBoxes),p(!1===e.state.showRevisionMarkup?[]:[...cx(r,e.state),...ux(r,e.state)]),d(function(e,t){const n=t.document.comments;if(!n||0===n.order.length||!Qv(t,"comments"))return[];const r=e.surfaceRect,o=new Map(ko(t).map((e,t)=>[e.id,t])),a=[];for(const i of n.order){const s=n.items[i];if(!s?.start||!s?.end||!tx(t,s.author))continue;const l=o.get(s.start.paragraphId),c=o.get(s.end.paragraphId);if(void 0!==l&&void 0!==c)for(const t of e.paragraphs){const e=o.get(t.paragraphId);if(void 0===e||e<l||e>c)continue;const n=e===l?s.start.offset:0,d=e===c?s.end.offset:Number.POSITIVE_INFINITY,u=Math.max(n,t.startOffset),p=Math.min(d,t.endOffset);if(!(u>=p))for(const o of t.lines){const e=Math.max(u,o.startOffset),t=Math.min(p,o.endOffset);if(e>=t)continue;const n=o.slots.find(t=>t.offset===e),s=o.slots.find(e=>e.offset===t)??o.slots[o.slots.length-1];n&&s&&a.push({commentId:i,left:n.left-r.left,top:o.top-r.top,width:Math.max(1,s.left-n.left),height:o.height})}}}return a}(r,e.state)),b(a.selectedImageBox),v(a.selectedTextBoxBox),w(a.selectedTableBox),i(a.inputBox),S(a.caretBox)},B=(e="selection")=>{const t=++M;queueMicrotask(()=>{t===M&&O(e)})},F=(e="content-change")=>(B(e),!1),E=(e,t={})=>(t.paragraphIds&&t.paragraphIds.length>0&&(o(e=>hx(e,t.paragraphIds??[])),we()),B(e),t.resolveWhenDone?Promise.resolve():null),D=t=>{if(!e.isImporting?.()){if(t.dirtyAll||t.structureChanged)n({}),o({}),we();else if((t.dirtyParagraphIds?.length??0)>0){const e=t.dirtyParagraphIds??[];o(t=>hx(t,e)),we()}B("content-change")}},L=async()=>{n({}),o({}),we(),await new Promise(e=>{var t;t=()=>e(),"undefined"!=typeof window&&"function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(()=>t()):globalThis.setTimeout(t,16)}),B("import")};mn(()=>{e.state.selection.anchor.paragraphId,e.state.selection.anchor.runId,e.state.selection.anchor.offset,e.state.selection.focus.paragraphId,e.state.selection.focus.runId,e.state.selection.focus.offset,B("selection")}),mn(()=>{e.state.document,e.state.activeSectionIndex,e.state.activeZone,e.isImporting?.()||B("content-change")}),mn(()=>{e.state.showRevisionMarkup,e.state.showMarkupInsertions,e.state.showMarkupDeletions,e.state.showMarkupComments,e.state.showMarkupFormatting,e.state.markupAuthors,B("content-change")}),mn(()=>{e.state.reviewDisplayMode,B("content-change")}),mn(()=>{const t=e.viewportRef();if(!t)return;const n=()=>{B("scroll")},r=()=>{B("resize")};t.addEventListener("scroll",n,{passive:!0}),window.addEventListener("resize",r),Ut(()=>{t.removeEventListener("scroll",n),window.removeEventListener("resize",r)})});const N=()=>k(null),z=()=>{M+=1,A.clear()};return{measuredBlockHeights:t,measuredParagraphLayouts:r,documentLayout:R,canvasSnapshotProvider:A,inputBox:a,selectionBoxes:s,commentHighlights:c,revisionMarkupBoxes:u,changeBarBoxes:g,selectedImageBox:h,selectedTextBoxBox:y,selectedTableBox:x,caretBox:I,preferredColumnX:C,setPreferredColumnX:k,clearPreferredColumn:N,requestInputBoxSync:B,scheduleDeferredLayoutMeasurement:E,stabilizeLayoutAfterImport:L,syncMeasuredLayoutMetrics:F,syncInputBox:O,setMeasuredBlockHeights:n,setMeasuredParagraphLayouts:o,applyInvalidation:D,onCleanupHook:z}}(e)}function yx(e){return Array.isArray(e)?e.map(yx):e&&"object"==typeof e?Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,yx(t)])):e}function vx(e){const{builtinStyle:t,customStyle:n,...r}=e;return JSON.stringify(yx(r))}var xx=new Map(Object.values(Ur).flatMap(e=>{const t=L(e);return t?[[e.id,{key:t,signature:vx(e)}]]:[]}));function wx(e){if(!0===e.customStyle||void 0!==e.builtinStyle)return;const t=xx.get(e.id);return t?.signature===vx(e)?t.key:void 0}function Ix(e,t,n){const[r,o]=Nt("Initial"),[a,i]=Nt(!1),s=()=>n.enabled??!1,l=n.persistence,c=ye(async e=>{if(s()&&a()){o("Saving...");try{const t=JSON.parse(JSON.stringify(wn(e)));await l.saveDocument(t),o("Saved")}catch(t){n.logger?.error("persistence:autosave failed",t),o("Error")}}},1e3);return mn(qt(()=>e.document,e=>{s()&&a()&&c(e)},{defer:!0})),ot(async()=>{if(!s())return i(!0),void o("Saved");try{const e=await l.loadDocument();e&&t(function(e){if(e.sourcePackage||!e.styles)return e;let t;for(const[n,r]of Object.entries(e.styles)){const o=wx(r);o&&(t??={...e.styles},t[n]={...r,builtinStyle:o})}return t?{...e,styles:t}:e}(e))}catch(e){n.logger?.error("persistence:load failed",e)}finally{i(!0),o("Saved")}}),{status:r}}function Sx(e,t){const n=Math.max(0,249),r=Math.max(0,e.length-n);return[...e.slice(r),t]}function Cx(e){return function(e){const t=(e,t)=>{const n=Hr(e.document),r=Math.max(0,Math.min(Ua(e),n.length-1)),o=jr(e),a=n[r];if(!a)return e;const i=[...n],s={...a},l=Go("");if("header"===o){const e=[...a.header??[]];t<0?e.unshift(l):e.push(l),s.header=e}else if("footer"===o){const e=[...a.footer??[]];t<0?e.unshift(l):e.push(l),s.footer=e}else{const e=[...a.blocks];t<0?e.unshift(l):e.push(l),s.blocks=e}return i[r]=s,{...e,document:{...e.document,sections:i}}},n=()=>{const t=(n=e.getHistoryState(),r=e.stateSnapshot(),0===n.undoStack.length?null:{history:{undoStack:n.undoStack.slice(0,-1),redoStack:Sx(n.redoStack,r),lastTransactionMeta:null},nextState:n.undoStack[n.undoStack.length-1]});var n,r;t&&(e.updateHistoryState(()=>t.history),e.clearPreferredColumn(),e.applyHistoryState(t.nextState),e.focusInput())},r=()=>{const t=(n=e.getHistoryState(),r=e.stateSnapshot(),0===n.redoStack.length?null:{history:{undoStack:Sx(n.undoStack,r),redoStack:n.redoStack.slice(0,-1),lastTransactionMeta:null},nextState:n.redoStack[n.redoStack.length-1]});var n,r;t&&(e.updateHistoryState(()=>t.history),e.clearPreferredColumn(),e.applyHistoryState(t.nextState),e.focusInput())},o=n=>{const r=e.imageOps().getSelectedImageInfo(e.state());if(!r)return!1;const o=ko(e.state()),a=o.findIndex(e=>e.id===r.paragraph.id);if(a<0)return!1;const i=a+n;if(i<0||i>=o.length){const r=e.state(),o=t(r,n),a=ko(o),i=n<0?a[0]:a[a.length-1];if(!i)return!1;const s=xi(i,n<0?oi(i):0);return e.applyTransactionalState(()=>Ov(o,s),{mergeKey:tf}),e.focusInput(),!0}const s=o[i],l=n<0?oi(s):0;return e.applyTransactionalState(e=>Ov(e,xi(s,l)),{mergeKey:tf}),e.focusInput(),!0},a=t=>{const n=e.stateSnapshot();e.applyHistoryState({...n,document:{...n.document,sections:n.document.sections?.map(vr)},selection:{anchor:{...t.anchor},focus:{...t.focus}}})};return{performUndo:n,performRedo:r,moveSelectedImageByParagraph:o,applySelectionPreservingStructure:a}}(e)}function kx(e={}){const t=e.dbName??"oasis-editor-db",n=e.storeName??"documents",r=e.key??"current-document";let o=null;async function a(){return o||(o=await function(e){return new Promise((t,n)=>{const r=indexedDB.open(e.name,e.version);r.onerror=()=>{n(/* @__PURE__ */new Error(`Failed to open IndexedDB: ${r.error?.message}`))},r.onsuccess=()=>{t(r.result)},r.onupgradeneeded=t=>{const n=r.result;e.onUpgrade(n,t.oldVersion,t.newVersion)}})}({name:t,version:1,onUpgrade:e=>{e.objectStoreNames.contains(n)||e.createObjectStore(n)}}),o)}return{async saveDocument(e){await function(e,t,n,r){return new Promise((o,a)=>{try{const i=e.transaction([t],"readwrite"),s=i.objectStore(t).put(r,n);s.onerror=()=>{a(/* @__PURE__ */new Error(`Failed to put item in ${t}: ${s.error?.message}`))},i.oncomplete=()=>{o()},i.onabort=i.onerror=()=>{a(/* @__PURE__ */new Error(`Transaction failed putting item in ${t}: ${i.error?.message}`))}}catch(i){a(i)}})}(await a(),n,r,e)},loadDocument:async()=>function(e,t,n){return new Promise((r,o)=>{try{const a=e.transaction([t],"readonly").objectStore(t).get(n);a.onerror=()=>{o(/* @__PURE__ */new Error(`Failed to get item from ${t}: ${a.error?.message}`))},a.onsuccess=()=>{r(a.result??null)}}catch(a){o(a)}})}(await a(),n,r),async clearDocument(){await function(e,t,n){return new Promise((r,o)=>{try{const a=e.transaction([t],"readwrite"),i=a.objectStore(t).delete(n);i.onerror=()=>{o(/* @__PURE__ */new Error(`Failed to delete item from ${t}: ${i.error?.message}`))},a.oncomplete=()=>{r()},a.onabort=a.onerror=()=>{o(/* @__PURE__ */new Error(`Transaction failed deleting item from ${t}: ${a.error?.message}`))}}catch(a){o(a)}})}(await a(),n,r)},close(){o&&(o.close(),o=null)}}}function Tx(e){return function(e){const[t,n]=Nt([]),[r,o]=Nt([]);let a={undoStack:[],redoStack:[],lastTransactionMeta:null};const i=()=>{n(a.undoStack),o(a.redoStack)},s=t=>{e.commitState(e.cloneState(t))},l=(t,n)=>{const r=e.stateSnapshot(),o=An("txn:produce",()=>eo(r,t(r),t=>{e.reportContentControlDiagnostic?.(t)}),0);if(o===r)return;a=function(e,t,n,r,o=Date.now()){return{undoStack:void 0!==r?.mergeKey&&e.lastTransactionMeta?.mergeKey===r.mergeKey&&o-e.lastTransactionMeta.timestamp<1e3?e.undoStack:Sx(e.undoStack,t),redoStack:[],lastTransactionMeta:r?.mergeKey?{mergeKey:r.mergeKey,timestamp:o}:null}}(a,r,0,n),i();const s=An("txn:invalidate",()=>function(e,t){if(e===t||e.document===t.document)return{};const n=e=>Hr(e.document).map(e=>[...(e.header??[]).map(e=>e.id),...e.blocks.map(e=>e.id),...(e.footer??[]).map(e=>e.id)].join("|")).join("||");if(n(e)!==n(t))return{dirtyAll:!0,structureChanged:!0};const r=ko(e),o=ko(t),a=/* @__PURE__ */new Map;for(const s of r)a.set(s.id,s);const i=[];for(const s of o){const e=a.get(s.id);if(!e){i.push(s.id);continue}if(e===s)continue;if(e.runs.length!==s.runs.length){i.push(s.id);continue}let t=!1;for(let n=0;n<e.runs.length;n+=1){const r=e.runs[n],o=s.runs[n];if(r===o)continue;if(r.id!==o.id||r.text!==o.text){t=!0;break}const a=ki(r),i=ki(o);if(Boolean(a)!==Boolean(i)||(a?.width??-1)!==(i?.width??-1)||(a?.height??-1)!==(i?.height??-1)||(a?.floating?.wrap??"")!==(i?.floating?.wrap??"")||Boolean(a?.floating?.behindDoc)!==Boolean(i?.floating?.behindDoc)||(a?.wrapPolygon?.length??-1)!==(i?.wrapPolygon?.length??-1)){t=!0;break}}t&&i.push(s.id)}return{dirtyParagraphIds:i}}(r,o),0);e.applyLayoutInvalidation(s),An("txn:setState",()=>e.commitState(o),0)};return{undoStack:t,redoStack:r,applyTransactionalState:l,applyHistoryState:s,resetTransactionGrouping:()=>{var e;e=a,a={...e,lastTransactionMeta:null}},updateHistoryState:e=>{a=e(a),i()},getHistoryState:()=>a,clearHistory:()=>{a={undoStack:[],redoStack:[],lastTransactionMeta:null},i()}}}(e)}function Px(e){let t=e.state.document,n=e.state.selection;mn(()=>{const r=e.state.document,o=e.state.selection,a=r!==t,i=o!==n;var s;if(t=r,n=o,e.state.activeSectionIndex,e.state.activeZone,s=e.state,Wp&&(Vp={anchor:{paragraphId:s.selection.anchor.paragraphId,runId:s.selection.anchor.runId,offset:s.selection.anchor.offset},focus:{paragraphId:s.selection.focus.paragraphId,runId:s.selection.focus.runId,offset:s.selection.focus.offset},activeZone:s.activeZone??"main",activeSectionIndex:s.activeSectionIndex??0}),e.isImportInProgress())return;const l=e.cloneState(e.getStateSnapshot());e.getOnStateChange()?.(l),a&&(e.emit("change",l),e.emit("documentChange",l.document)),i&&e.emit("selectionChange",l.selection)})}function Rx(e){return function(e){const{documentOptions:t,logger:n,runtimeClient:r,state:o,commitState:a,getStateSnapshot:i,applyState:s,cloneState:l,isReadOnly:c,focusInput:d,surfaceRef:u,viewportRef:p,zoomFactor:f,getImageOps:g}=e,m=Dv({state:()=>o,applyState:s,applyTransactionalState:(e,t)=>j(e,t),isReadOnly:c,surfaceRef:()=>u()??null,stabilizeLayoutAfterImport:async()=>{await F()},resetEditorChromeState:()=>G(),focusInput:d,requestLocalFontAccess:Pr,prepareDocumentFonts:async e=>{await Br(e,{remoteWebFonts:t().remoteWebFonts})},logger:n}),h=()=>"done"!==m.importProgress()?.phase&&"error"!==m.importProgress()?.phase&&null!==m.importProgress(),{measuredBlockHeights:b,measuredParagraphLayouts:y,documentLayout:v,canvasSnapshotProvider:x,inputBox:w,selectionBoxes:I,commentHighlights:S,revisionMarkupBoxes:C,changeBarBoxes:k,selectedImageBox:T,selectedTextBoxBox:P,selectedTableBox:R,caretBox:A,preferredColumnX:M,setPreferredColumnX:O,clearPreferredColumn:B,stabilizeLayoutAfterImport:F,setMeasuredBlockHeights:E,setMeasuredParagraphLayouts:D,applyInvalidation:L,onCleanupHook:N}=bx({state:o,surfaceRef:u,viewportRef:p,isImporting:h,zoomFactor:f}),z=kx({key:t().persistenceKey}),{status:$}=Ix(o,e=>{n.info("persistence:loaded",{docId:e.id});const t=Za(e);a(t),G()},{enabled:t().persistenceEnabled??!1,persistence:t().persistence??z,logger:n}),{undoStack:H,redoStack:W,applyTransactionalState:j,applyHistoryState:U,resetTransactionGrouping:V,updateHistoryState:K,getHistoryState:_,clearHistory:X}=Tx({reportContentControlDiagnostic:e=>n.warn(e.code,e),stateSnapshot:i,commitState:a,cloneState:l,applyLayoutInvalidation:L}),q=Cx({state:()=>o,stateSnapshot:i,applyHistoryState:U,applyTransactionalState:j,focusInput:d,clearPreferredColumn:B,imageOps:g,updateHistoryState:K,getHistoryState:_}),G=()=>{B(),E({}),D({}),we(),x.clear(),X()};return Px({state:o,isImportInProgress:h,cloneState:l,getStateSnapshot:i,getOnStateChange:()=>t().onStateChange,emit:r.emit}),{docIO:m,isImportInProgress:h,measuredBlockHeights:b,measuredParagraphLayouts:y,documentLayout:v,canvasSnapshotProvider:x,inputBox:w,selectionBoxes:I,commentHighlights:S,revisionMarkupBoxes:C,changeBarBoxes:k,selectedImageBox:T,selectedTextBoxBox:P,selectedTableBox:R,caretBox:A,preferredColumnX:M,setPreferredColumnX:O,clearPreferredColumn:B,stabilizeLayoutAfterImport:F,setMeasuredBlockHeights:E,setMeasuredParagraphLayouts:D,applyLayoutInvalidation:L,onCleanupHook:N,fallbackPersistence:z,persistenceStatus:$,undoStack:H,redoStack:W,applyTransactionalState:j,applyHistoryState:U,resetTransactionGrouping:V,updateHistoryState:K,getHistoryState:_,clearHistory:X,historyActions:q,resetEditorChromeState:G}}(e)}function Ax(e){return Ki(e,e=>"textBox"===e.kind)}function Mx(e,t){const n=Ax(e);if(!n||!Jr(n.run))return e;const r=function(e){if(!Number.isFinite(e))return;const t=(Math.round(e)%360+360)%360;return 0===t?void 0:t}(t),{paragraphIndex:o,run:a}=n,i=ko(e).map((e,t)=>t!==o?ho(e):{...ho(e),runs:e.runs.map(e=>e.id===a.id&&"textBox"===e.kind?{...e,textBox:{...e.textBox,rotation:r}}:na(e))});return Vt(e,i,H(i,Ri(e)))}function Ox(e,t){const n=Ax(e);if(!n||!Jr(n.run))return e;const{paragraphIndex:r,run:o}=n,a=ko(e).map((e,n)=>n!==r?ho(e):{...ho(e),runs:e.runs.map(e=>{if(e.id!==o.id||"textBox"!==e.kind)return na(e);const n=t(e.textBox.floating),r={...e.textBox};return n?r.floating=n:delete r.floating,{...e,textBox:r}})});return Vt(e,a,H(a,Ri(e)))}function Bx(e,t,n,r={}){const o=Ax(e),a=o&&Jr(o.run);if(!o||!a)return e;const i=r.handleDirection??"se",s=i.includes("n")||i.includes("s"),l=i.includes("w"),c=i.includes("n"),d=Math.max(24,Math.round(t)),u=Math.max(24,Math.round(n)),{paragraphIndex:p,run:f}=o,g=d-a.width,m=u-a.height,h=ko(e).map((e,t)=>t!==p?ho(e):{...ho(e),runs:e.runs.map(e=>{if(e.id!==f.id||"textBox"!==e.kind)return na(e);const t=e.textBox,n={...t,width:d,height:u};return s&&t.body?.autoFit&&(n.body={...t.body,autoFit:!1}),t.floating&&(n.floating=function(e,t,n,r,o){let a=e;if(r&&0!==t){const n=e.positionH;n?.align||(a={...a,positionH:{...n??{},offset:(n?.offset??0)-t*Ao}})}if(o&&0!==n){const e=a.positionV;e?.align||(a={...a,positionV:{...e??{},offset:(e?.offset??0)-n*Ao}})}return a}(t.floating,g,m,l,c)),{...e,textBox:n}})});return Vt(e,h,H(h,Ri(e)))}var Fx=e=>e.cells.reduce((e,t)=>e+Math.max(1,t.colSpan??1),0),Ex=e=>e.rows.reduce((e,t)=>Math.max(e,Fx(t)),0),Dx=(e,t)=>{let n=0;for(const r of e.cells){const e=Math.max(1,r.colSpan??1);if(t>=n&&t<n+e)return r;n+=e}return null};function Lx(e){if(!e)return null;for(const t of e.blocks){const e=ra(t)[0];if(e)return e}return null}var Nx=e=>{for(const t of e.rows)for(const e of t.cells){if("continue"===e.vMerge)continue;const t=Lx(e);if(t)return t}return null};function zx(e,t){return e.some(e=>ra(e).some(e=>e.id===t))}var $x=(e,t,n)=>{const r=qo(e,t);if(!r)return{kind:"outside"};const o=xo(e,t,r.sectionIndex);if(!o)return{kind:"outside"};const a=function(e,t,n){for(const r of e){if(!zx(r,n))continue;const e=Zo(r,t),o=e?.[e.length-1]?.table;if(o)return o}return null}(function(e,t){const n=qo(e,t);if(!n)return[];if("footnote"===n.zone){const t=n.footnoteId?e.footnotes?.items[n.footnoteId]:void 0;return t?[t.blocks]:[]}const r=Lo(e)[n.sectionIndex];return r?"main"===n.zone?[r.blocks]:"header"===n.zone?[r.header,r.firstPageHeader,r.evenPageHeader].filter(e=>Boolean(e)):[r.footer,r.firstPageFooter,r.evenPageFooter].filter(e=>Boolean(e)):[]}(e,t),o.tablePath,t);if(!a)return{kind:"blocked"};const i=a.rows.filter(e=>!e.style?.hidden).flatMap(e=>e.cells.filter(e=>"continue"!==e.vMerge&&e.blocks.length>0)),s=i.findIndex(e=>function(e,t){return e.blocks.some(e=>ra(e).some(e=>e.id===t))}(e,t));if(-1===s)return{kind:"blocked"};const l=s+n;if(l<0)return{kind:"beforeFirst"};if(l>=i.length)return{kind:"afterLast"};const c=i[l],d=c.blocks.every(e=>"paragraph"===e.type),u=c.blocks.flatMap(ra),p=d?u[0]:c.blocks.find(e=>"paragraph"===e.type)??u[0];if(!p)return{kind:"blocked"};const f=d?u[u.length-1]:p;return{kind:"adjacent",selection:{anchor:xi(p,0),focus:xi(f,oi(f))}}},Hx=(e,t,n)=>{const r=$x(e,t,n);return"adjacent"===r.kind?r.selection.anchor:null};function Wx(e,t){return Boolean(e?.some(e=>ra(e).some(e=>e.id===t)))}function jx(e,t,n){if("main"===n)return"blocks";const r=e.selection.focus.paragraphId;return"header"===n?[["header",t.header],["firstPageHeader",t.firstPageHeader],["evenPageHeader",t.evenPageHeader]].find(([,e])=>Wx(e,r))?.[0]??"header":"footer"===n?[["footer",t.footer],["firstPageFooter",t.firstPageFooter],["evenPageFooter",t.evenPageFooter]].find(([,e])=>Wx(e,r))?.[0]??"footer":"blocks"}function Ux(e){const t=qo(e.document,e.selection.focus.paragraphId);return"footnote"===t?.zone?t.footnoteId:e.activeFootnoteId}function Vx(e,t){if("footnote"===t){const t=Ux(e);return t?e.document.footnotes?.items[t]?.blocks??[]:[]}const n=Hr(e.document),r=Ua(e),o=n[Math.max(0,Math.min(r,n.length-1))];if(!o)return[];const a=jx(e,o,t);return"blocks"===a?o.blocks:o[a]??[]}var Kx=(e,t,n="main")=>{if("footnote"===n){const n=Ux(e),r=e.document.footnotes,o=n?r?.items[n]:void 0;return n&&r&&o?{...e,document:{...e.document,footnotes:{...r,items:{...r.items,[n]:{...o,blocks:t}}}}}:e}const r=Ua(e),o=Hr(e.document),a=Math.max(0,Math.min(r,o.length-1)),i=o[a];if(!i)return e;const s=jx(e,i,n),l=[...o];return l[a]="blocks"===s?{...i,blocks:t}:{...i,[s]:t},{...e,document:{...e.document,sections:l}}};function _x(e){const t=e.tablePath[e.tablePath.length-1];return t?{...e,rowIndex:t.rowIndex,cellIndex:t.cellIndex}:e}function Xx(e,t){const n=Zo(e,t.tablePath),r=n?.[n.length-1];return r?{tableBlock:r.table,targetCell:r.cell,location:_x(t),targetBlocks:e}:null}function qx(e,t,n){const r=n.tablePath[0];if(!r)return null;const o=t(e,n.zone),a=o[r.tableBlockIndex];if(!a||"table"!==a.type)return null;const i=[...o];return i[r.tableBlockIndex]=_t(a),Xx(i,n)}var Gx=(e,t,n)=>{const r=qo(e.document,e.selection.focus.paragraphId),o=qo(e.document,e.selection.anchor.paragraphId);if(!r||!o)return n(e);if(r.zone!==o.zone||r.sectionIndex!==o.sectionIndex||r.footnoteId!==o.footnoteId)return e;const a=xo(e.document,e.selection.focus.paragraphId,Ua(e)),i=r.zone;let s,l;if(a){const n=function(e,t,n){const r=n.tablePath[0];if(!r)return null;const o=t(e,n.zone),a=o[r.tableBlockIndex];return a&&"table"===a.type?Xx(function(e,t){const n=[...e];let r=n;for(let o=0;o<t.length;o+=1){const e=t[o];if(!e)break;const n=r[e.tableBlockIndex];if(!n||"table"!==n.type)break;const a={...n,rows:[...n.rows]};r[e.tableBlockIndex]=a;const i=a.rows[e.rowIndex];if(!i)break;const s={...i,cells:[...i.cells]};a.rows[e.rowIndex]=s;const l=s.cells[e.cellIndex];if(!l)break;const c={...l,blocks:[...l.blocks]};s.cells[e.cellIndex]=c,r=c.blocks}return n}(o,n.tablePath),n):null}(e,t,a);if(!n)return e;s=n.targetBlocks,l=n.targetCell.blocks}else{const r=t(e,i);if(r.length&&r.every(e=>"paragraph"===e.type)&&r.some(t=>t.id===e.selection.anchor.paragraphId)&&r.some(t=>t.id===e.selection.focus.paragraphId))return n(e);s=[...r],l=s}const c=function(e,t){const n=e.findIndex(e=>"paragraph"===e.type&&e.id===t.anchor.paragraphId),r=e.findIndex(e=>"paragraph"===e.type&&e.id===t.focus.paragraphId);if(n<0||r<0)return null;let o=Math.min(n,r),a=Math.max(n,r)+1;if(e.slice(o,a).some(e=>"paragraph"!==e.type))return null;for(;o>0&&"paragraph"===e[o-1]?.type;)o--;for(;a<e.length&&"paragraph"===e[a]?.type;)a++;return{start:o,end:a}}(l,e.selection);if(!c)return e;const d=jo(l.slice(c.start,c.end).map(e=>"paragraph"===e.type?ho(e):e),e.document.pageSettings,void 0,e.document.styles,void 0,e.document.assets),u={...e,activeSectionIndex:0,activeZone:"main",document:{...d,settings:e.document.settings},selection:{anchor:{...e.selection.anchor},focus:{...e.selection.focus}}};Wr(u.document);const p=n(u),f=Hr(p.document)[0]?.blocks??[];if(p===u&&JSON.stringify(f)===JSON.stringify(l.slice(c.start,c.end))&&JSON.stringify(p.selection)===JSON.stringify(e.selection))return e;l.splice(c.start,c.end-c.start,...f);const g=Kx(e,s,i),m=ko(e),h=ko(g),b=e.document.bookmarks,y=e.document.comments;return{...g,document:{...g.document,...b?{bookmarks:vo(b,m,h)}:{},...y?{comments:ao(y,m,h)}:{}},selection:p.selection}};function Yx(e,t){const n=xo(e.document,e.selection.focus.paragraphId,Ua(e));return n?qx(e,t,n):null}function Zx(e,t,n,r){const o=Kx(e,t,n);return r?{...o,selection:{anchor:xi(r,0),focus:xi(r,0)}}:o}function Jx(e,t,n,r){const o=t.getTargetBlocks(e,n),a=Zo(o,r);return a?.[a.length-1]?.table??null}function Qx(e,t){const n=xo(e.document,e.selection.focus.paragraphId,Ua(e)),r=n?.tablePath[n.tablePath.length-1];if(!n||!r)return null;const o=Jx(e,t,n.zone,n.tablePath);return o?{table:o,rowIndex:r.rowIndex,cellIndex:r.cellIndex}:null}function ew(e){return function(e){const t=t=>{const n=e.resolveHorizontalTableCellRange(t);return Boolean(n&&n.endCellIndex>n.startCellIndex)},n=t=>{const n=Qx(t,e);if(!n)return!1;const r=n.table.rows[n.rowIndex]?.cells[n.cellIndex];return Boolean((r?.colSpan??1)>1)},r=t=>{const n=e.resolveVerticalTableCellRange(t);if(!n)return!1;const r=Jx(t,e,n.zone,n.tablePath);if(!r)return!1;for(let e=n.startRowIndex;e<=n.endRowIndex;e+=1){const t=r.rows[e]?.cells[n.cellIndex];if(!t||"continue"===t.vMerge||1!==t.blocks.length||"paragraph"!==t.blocks[0]?.type)return!1}return!0},o=e=>t(e)||r(e),a=t=>{const n=Qx(t,e);if(!n)return!1;const r=n.table.rows[n.rowIndex]?.cells[n.cellIndex];return Boolean((r?.rowSpan??1)>1&&"restart"===r?.vMerge)},i=e=>n(e)||a(e),s=t=>null!==Qx(t,e),l=t=>{const n=Qx(t,e);return Boolean(n&&Ex(n.table)>1)};return{canMergeSelectedTableCells:t,canSplitSelectedTableCell:n,canMergeSelectedTableRows:r,canMergeSelectedTable:o,canSplitSelectedTableCellVertically:a,canSplitSelectedTable:i,canEditSelectedTableRow:s,canEditSelectedTableColumn:l}}(e)}function tw(e,t){return e.visualRowIndex!==t.visualRowIndex?e.visualRowIndex-t.visualRowIndex:e.visualColumnIndex!==t.visualColumnIndex?e.visualColumnIndex-t.visualColumnIndex:0}function nw(e){return e.blocks.flatMap(ra)}function rw(e){const t=e.tablePath[e.tablePath.length-1];return t?{...e,rowIndex:t.rowIndex,cellIndex:t.cellIndex}:e}function ow(e,t){return function(e,t){const n=e.selection,r=Ua(e),o=xo(e.document,n.anchor.paragraphId,r),a=xo(e.document,n.focus.paragraphId,r);if(!o||!a||o.zone!==a.zone||!function(e,t){if(0===e.length||e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){const r=e[n],o=t[n];if(r.tableBlockIndex!==o.tableBlockIndex)return!1;if(n<e.length-1&&(r.rowIndex!==o.rowIndex||r.cellIndex!==o.cellIndex))return!1}return!0}(o.tablePath,a.tablePath))return null;const i=t.getTargetBlocks(e,o.zone),s=Zo(i,o.tablePath),l=Zo(i,a.tablePath),c=s?.[s.length-1],d=l?.[l.length-1];if(!c||!d||c.table!==d.table)return null;const u=rw(o),p=rw(a),f=c.table,g=Xa(f),m=g.find(e=>e.rowIndex===u.rowIndex&&e.cellIndex===u.cellIndex),h=g.find(e=>e.rowIndex===p.rowIndex&&e.cellIndex===p.cellIndex);return m&&h?{anchorLocation:u,focusLocation:p,anchorCell:m,focusCell:h,tableBlock:f,tableLayout:g}:null}(e,t)}function aw(e){return function(e){const t=t=>{const n=t.selection,r=ow(t,e);if(!r||r.anchorLocation.rowIndex===r.focusLocation.rowIndex&&r.anchorLocation.cellIndex===r.focusLocation.cellIndex)return e.logger?.debug(`resolveTableCellRangeSelection: no expansion (anchor=${n.anchor.paragraphId} focus=${n.focus.paragraphId})`),null;const o=Math.min(r.anchorLocation.rowIndex,r.focusLocation.rowIndex),a=Math.max(r.anchorLocation.rowIndex,r.focusLocation.rowIndex),i=Math.min(r.anchorLocation.cellIndex,r.focusLocation.cellIndex),s=Math.max(r.anchorLocation.cellIndex,r.focusLocation.cellIndex);e.logger?.info(`resolveTableCellRangeSelection: expanding r${r.anchorLocation.rowIndex}:c${r.anchorLocation.cellIndex}->r${r.focusLocation.rowIndex}:c${r.focusLocation.cellIndex} (anchor=${n.anchor.paragraphId} focus=${n.focus.paragraphId}) range=[rows ${o}..${a}, cells ${i}..${s}]`);const l=tw(r.anchorCell,r.focusCell)<=0?r.anchorLocation:r.focusLocation,c=tw(r.anchorCell,r.focusCell)<=0?r.focusLocation:r.anchorLocation,d=r.tableBlock.rows[l.rowIndex]?.cells[l.cellIndex],u=r.tableBlock.rows[c.rowIndex]?.cells[c.cellIndex],p=d?nw(d)[0]:void 0,f=u?nw(u):[],g=f[f.length-1];return p&&g?{anchor:xi(p,0),focus:xi(g,oi(g))}:null},n=t=>{const n=ow(t,e);if(!n)return null;const r=Math.min(n.anchorCell.visualRowIndex,n.focusCell.visualRowIndex),o=Math.max(n.anchorCell.visualRowIndex+n.anchorCell.rowSpan-1,n.focusCell.visualRowIndex+n.focusCell.rowSpan-1),a=Math.min(n.anchorCell.visualColumnIndex,n.focusCell.visualColumnIndex),i=Math.max(n.anchorCell.visualColumnIndex+n.anchorCell.colSpan-1,n.focusCell.visualColumnIndex+n.focusCell.colSpan-1),s=n.tableLayout.filter(e=>e.visualRowIndex<=o&&e.visualRowIndex+e.rowSpan-1>=r&&e.visualColumnIndex<=i&&e.visualColumnIndex+e.colSpan-1>=a);return{blockIndex:n.anchorLocation.blockIndex,tablePath:n.anchorLocation.tablePath.map(e=>({...e})),cells:s,zone:n.anchorLocation.zone}},r=t=>{const n=ow(t,e);if(!n||n.anchorCell.visualRowIndex!==n.focusCell.visualRowIndex)return null;const r=tw(n.anchorCell,n.focusCell);if(0===r)return null;const o=r<=0?n.anchorLocation:n.focusLocation,a=r<=0?n.focusLocation:n.anchorLocation;return{blockIndex:n.anchorLocation.blockIndex,tablePath:n.anchorLocation.tablePath.map(e=>({...e})),rowIndex:o.rowIndex,startCellIndex:o.cellIndex,endCellIndex:a.cellIndex,zone:n.anchorLocation.zone}},o=t=>{const n=ow(t,e);if(!n||n.anchorLocation.cellIndex!==n.focusLocation.cellIndex)return null;const r=Math.min(n.anchorCell.visualRowIndex,n.focusCell.visualRowIndex),o=Math.max(n.anchorCell.visualRowIndex,n.focusCell.visualRowIndex);return r===o?null:{blockIndex:n.anchorLocation.blockIndex,tablePath:n.anchorLocation.tablePath.map(e=>({...e})),startRowIndex:r,endRowIndex:o,cellIndex:n.anchorLocation.cellIndex,zone:n.anchorLocation.zone}};return{resolveTableCellRangeSelection:t,resolveSelectedTableCells:n,resolveHorizontalTableCellRange:r,resolveVerticalTableCellRange:o}}(e)}function iw(e){if(e)for(const t of e.blocks){const e=ra(t)[0];if(e)return e}}function sw(e,t,n){const r=n.tablePath[n.tablePath.length-1];return r?qx(e,t.getTargetBlocks,{blockIndex:n.blockIndex,rowIndex:r.rowIndex,cellIndex:r.cellIndex,paragraphIndex:0,tablePath:n.tablePath,zone:n.zone}):null}function lw(e){return function(e){const t=e=>({...e,style:e.style?{...e.style}:void 0,conditionalStyle:e.conditionalStyle?{...e.conditionalStyle}:void 0,mergeRevisionState:void 0,blocks:e.blocks.map(e=>_t(e))}),n=n=>{const r=e.resolveHorizontalTableCellRange(n);if(!r)return n;const o=sw(n,e,r);if(!o)return n;const{tableBlock:a,targetBlocks:i}=o,s=a.rows[r.rowIndex];if(!s)return n;const l=s.cells.slice(r.startCellIndex,r.endCellIndex+1);if(l.length<2)return n;const c=n.trackChangesEnabled?Ig():void 0,d={...l[0],colSpan:l.reduce((e,t)=>e+Math.max(1,t.colSpan??1),0),blocks:l.flatMap(e=>e.blocks.map(e=>_t(e))),...c?{style:{...l[0].style??{},revision:{...c,type:"merge",previous:{colSpan:l[0].colSpan,rowSpan:l[0].rowSpan,vMerge:l[0].vMerge}}},mergeRevisionState:{revisionId:c.id,orientation:"horizontal",currentCellCount:1,previousCells:l.map(t)}}:{}};s.cells.splice(r.startCellIndex,l.length,d);const u=iw(d);return u?Zx(n,i,r.zone,u):n},r=n=>{const r=e.resolveVerticalTableCellRange(n);if(!r)return n;const o=sw(n,e,r);if(!o)return n;const{tableBlock:a,targetBlocks:i}=o,s=[];for(let e=r.startRowIndex;e<=r.endRowIndex;e+=1){const t=a.rows[e],o=t?.cells[r.cellIndex];if(!t||!o||"continue"===o.vMerge||1!==o.blocks.length||"paragraph"!==o.blocks[0]?.type)return n;s.push(o)}if(s.length<2)return n;const l=Math.max(1,s[0].colSpan??1);if(!s.every(e=>Math.max(1,e.colSpan??1)===l))return n;const c=n.trackChangesEnabled?Ig():void 0,d={...s[0],rowSpan:s.length,vMerge:"restart",blocks:s.flatMap(e=>e.blocks.map(e=>_t(e))),...c?{style:{...s[0].style??{},revision:{...c,type:"merge",previous:{colSpan:s[0].colSpan,rowSpan:s[0].rowSpan,vMerge:s[0].vMerge}}},mergeRevisionState:{revisionId:c.id,orientation:"vertical",currentCellCount:1,previousCells:s.map(t)}}:{}};a.rows[r.startRowIndex].cells[r.cellIndex]=d;for(let e=r.startRowIndex+1;e<=r.endRowIndex;e+=1){const t=ta([Go("")],l);t.blocks=[],t.vMerge="continue",a.rows[e].cells[r.cellIndex]=t}const u=iw(d);return u?Zx(n,i,r.zone,u):n},o=t=>e.canMergeSelectedTableCells(t)?n(t):e.canMergeSelectedTableRows(t)?r(t):t,a=n=>{const r=Yx(n,e.getTargetBlocks);if(!r)return n;const{tableBlock:o,location:a,targetBlocks:i}=r,s=o.rows[a.rowIndex]?.cells[a.cellIndex],l=Math.max(1,s?.rowSpan??1);if(!s||l<=1||"restart"!==s.vMerge)return n;const c=t(s),d=n.trackChangesEnabled?Ig():void 0,u=Math.max(1,s.colSpan??1);s.rowSpan=void 0,s.vMerge=void 0,d&&(s.style={...s.style??{},revision:{...d,type:"merge",previous:{colSpan:c.colSpan,rowSpan:c.rowSpan,vMerge:c.vMerge}}},s.mergeRevisionState={revisionId:d.id,orientation:"vertical",currentCellCount:1,previousCells:[c,...Array.from({length:l-1},(e,n)=>{const r=o.rows[a.rowIndex+n+1]?.cells[a.cellIndex];return r?t(r):ta([],u)})]});for(let e=1;e<l;e+=1){const t=o.rows[a.rowIndex+e];if(!t)break;const n=ta([Go("")],u);t.cells[a.cellIndex]=n}const p=iw(s);return p?Zx(n,i,a.zone,p):n},i=n=>{const r=Yx(n,e.getTargetBlocks);if(!r)return n;const{tableBlock:o,location:a,targetBlocks:i}=r,s=o.rows[a.rowIndex],l=s?.cells[a.cellIndex],c=Math.max(1,l?.colSpan??1);if(!s||!l||c<=1)return n;const d=t(l),u=n.trackChangesEnabled?Ig():void 0,p=[{...l,colSpan:void 0,blocks:l.blocks.map(e=>_t(e)),...u?{style:{...l.style??{},revision:{...u,type:"merge",previous:{colSpan:d.colSpan,rowSpan:d.rowSpan,vMerge:d.vMerge}}},mergeRevisionState:{revisionId:u.id,orientation:"horizontal",currentCellCount:c,previousCells:[d]}}:{}},...Array.from({length:c-1},()=>ta([Go("")]))];s.cells.splice(a.cellIndex,1,...p);const f=iw(p[0]);return f?Zx(n,i,a.zone,f):n},s=t=>e.canSplitSelectedTableCellVertically(t)?a(t):e.canSplitSelectedTableCell(t)?i(t):t;return{mergeSelectedTableCells:n,mergeSelectedTableRows:r,mergeSelectedTable:o,splitSelectedTableCellVertically:a,splitSelectedTableCell:i,splitSelectedTable:s}}(e)}function cw(e,t){e.style={...e.style??{},revision:{...Ig(),type:t}}}function dw(e){if(!e)return null;for(const t of e.blocks){const e=ra(t)[0];if(e)return e}return null}function uw(e,t,n){const r=dw(t);if(r)return r;if(n)for(const o of n.cells){if("continue"===o.vMerge)continue;const e=dw(o);if(e)return e}return Nx(e)}function pw(e){return function(e){const t=(t,n)=>{const r=Yx(t,e.getTargetBlocks);if(!r)return t;const{tableBlock:o,location:a,targetBlocks:i}=r,s=o.rows[a.rowIndex];if(!s)return t;const l=Math.max(0,Math.min(o.rows.length,a.rowIndex+(n>0?1:0)));let c;if(o.rows.some(e=>e.cells.some(e=>Math.max(1,e.rowSpan??1)>1||void 0!==e.vMerge))){const e=Xa(o),n=e.find(e=>e.rowIndex===a.rowIndex&&e.cellIndex===a.cellIndex),r=e.filter(e=>e.rowIndex===a.rowIndex),s=r.length>0?r:e.filter(e=>e.rowIndex===Math.max(0,a.rowIndex-1));c=Jo(s.map(t=>{const n=e.find(e=>e.visualColumnIndex===t.visualColumnIndex&&e.visualRowIndex<l&&e.visualRowIndex+e.rowSpan>l);if(n){n.cell.rowSpan=Math.max(1,n.cell.rowSpan??1)+1,n.cell.vMerge="restart";const e=ta([Go("")],t.colSpan);return e.blocks=[],e.vMerge="continue",e}return ta([Go("")],t.colSpan)})),t.trackChangesEnabled&&cw(c,"insert"),o.rows.splice(l,0,c);const d=n?.visualColumnIndex??a.cellIndex,u=uw(o,Dx(c,d),c);return Zx(t,i,a.zone,u)}c=Jo(s.cells.map(e=>ta([Go("")],Math.max(1,e.colSpan??1)))),t.trackChangesEnabled&&cw(c,"insert"),o.rows.splice(l,0,c);const d=uw(o,c.cells[Math.min(a.cellIndex,c.cells.length-1)],c);return Zx(t,i,a.zone,d)},n=t=>{const n=Yx(t,e.getTargetBlocks);if(!n)return t;const{tableBlock:r,targetBlocks:o,location:a}=n,i=r.rows[r.rows.length-1];if(!i||!i.cells.length)return t;const s=i.cells.map(e=>{const t=ta([Go("")],Math.max(1,e.colSpan??1));if(e.style){const{revision:n,...r}=e.style;t.style=r}return t}),l=Math.max(r.gridCols?.length??0,Ex(r));for(let e=s.reduce((e,t)=>e+Math.max(1,t.colSpan??1),0);e<l;e++)s.push(ta([Go("")]));const c=Jo(s);return t.trackChangesEnabled&&cw(c,"insert"),r.rows.push(c),Zx(t,o,a.zone,dw(s[0]))},r=t=>{const n=Yx(t,e.getTargetBlocks);if(!n)return t;const{tableBlock:r,location:o,targetBlocks:a}=n;if(r.rows.length<=1&&!t.trackChangesEnabled)return t;const i=r.rows[o.rowIndex];if(!i)return t;if(t.trackChangesEnabled)return cw(i,"delete"),Zx(t,a,o.zone,null);if(i.cells.some(e=>"continue"!==e.vMerge&&Math.max(1,e.rowSpan??1)>1))return t;const s=r.rows.some(e=>e.cells.some(e=>Math.max(1,e.rowSpan??1)>1||void 0!==e.vMerge)),l=s?Xa(r).find(e=>e.rowIndex===o.rowIndex&&e.cellIndex===o.cellIndex):null;if(s){const e=Xa(r);for(const t of e)t.visualRowIndex<o.rowIndex&&t.visualRowIndex+t.rowSpan>o.rowIndex&&(t.cell.rowSpan=Math.max(1,t.cell.rowSpan??1)-1,t.cell.rowSpan<=1?(t.cell.rowSpan=void 0,t.cell.vMerge=void 0):t.cell.vMerge="restart")}r.rows.splice(o.rowIndex,1);const c=r.rows[Math.min(o.rowIndex,r.rows.length-1)],d=uw(r,c?Dx(c,Math.min(l?.visualColumnIndex??o.cellIndex,Math.max(0,Fx(c)-1))):null);return Zx(t,a,o.zone,d)},o=(t,n)=>{const r=Yx(t,e.getTargetBlocks);if(!r)return t;const{tableBlock:o,location:a,targetBlocks:i}=r;if(o.rows.some(e=>e.cells.some(e=>Math.max(1,e.colSpan??1)>1))){const e=Xa(o).find(e=>e.rowIndex===a.rowIndex&&e.cellIndex===a.cellIndex),r=(e?.visualColumnIndex??a.cellIndex)+(n>0?Math.max(1,e?.colSpan??1):0);for(const n of o.rows){const e=[];let o=0,a=!1;for(const i of n.cells){const n=Math.max(1,i.colSpan??1);if(!a&&r<=o){const n=ta([Go("")]);t.trackChangesEnabled&&cw(n,"insert"),e.push(n),a=!0}!a&&o<r&&r<o+n?(e.push({...i,colSpan:n+1,...t.trackChangesEnabled?{style:{...i.style??{},revision:{...Ig(),type:"merge",previous:{colSpan:i.colSpan}}}}:{}}),a=!0):e.push(i),o+=n}if(!a){const n=ta([Go("")]);t.trackChangesEnabled&&cw(n,"insert"),e.push(n)}n.cells=e}const s=o.rows[a.rowIndex],l=uw(o,s?Dx(s,r):null);return Zx(t,i,a.zone,l)}const s=Math.max(0,Math.min(o.rows[0]?.cells.length??0,a.cellIndex+(n>0?1:0)));for(const e of o.rows){const n=ta([Go("")]);t.trackChangesEnabled&&cw(n,"insert"),e.cells.splice(s,0,n)}const l=o.rows[a.rowIndex]?.cells[s],c=uw(o,l);return Zx(t,i,a.zone,c)},a=t=>{const n=Yx(t,e.getTargetBlocks);if(!n)return t;const{tableBlock:r,location:o,targetBlocks:a}=n;if(Ex(r)<=1)return t;if(t.trackChangesEnabled){const e=Xa(r).find(e=>e.rowIndex===o.rowIndex&&e.cellIndex===o.cellIndex)?.visualColumnIndex??o.cellIndex;for(const t of r.rows){const n=Dx(t,e);n&&cw(n,"delete")}return Zx(t,a,o.zone,null)}if(r.rows.some(e=>e.cells.some(e=>Math.max(1,e.colSpan??1)>1))){const e=Xa(r).find(e=>e.rowIndex===o.rowIndex&&e.cellIndex===o.cellIndex)?.visualColumnIndex??o.cellIndex;for(const t of r.rows){const n=[];let r=0;for(const o of t.cells){const t=Math.max(1,o.colSpan??1);e>=r&&e<r+t?t>1&&n.push({...o,colSpan:t-1>1?t-1:void 0}):n.push(o),r+=t}t.cells=n}const n=r.rows[o.rowIndex],i=uw(r,n&&Dx(n,Math.min(e,Math.max(0,Fx(n)-1))));return Zx(t,a,o.zone,i)}if(r.rows[0]?.cells.length<=1)return t;for(const e of r.rows)e.cells.splice(o.cellIndex,1);const i=r.rows[o.rowIndex],s=i?.cells[Math.min(o.cellIndex,i.cells.length-1)],l=uw(r,s);return Zx(t,a,o.zone,l)};return{insertSelectedTableRow:t,appendTableRowForTab:n,deleteSelectedTableRow:r,insertSelectedTableColumn:o,deleteSelectedTableColumn:a}}(e)}function fw(e){return function(e){const t=t=>{const n=e.resolveTableCellRangeSelection(t);return n?e.applySelectionToStatePreservingStructure(t,n):t},n=(n,r)=>{e.applyTransactionalState(o=>{const a=e.resolveSelectedTableCells(o);if(!a||a.cells.length<=1){const a=t(o);return a!==o&&e.logger?.info(`${r}: expanded selection to ${a.selection.anchor.paragraphId}[${a.selection.anchor.offset}]..${a.selection.focus.paragraphId}[${a.selection.focus.offset}]`),n(a)}const{blockIndex:i,tablePath:s,cells:l,zone:c}=a;e.logger?.info(`${r}: multi-cell selection in table block ${i} at depth ${s.length} (${l.length} cells) in zone ${c}`);const d=[],u=[];for(const e of l){const t=e.cell.blocks.flatMap(ra);d.push(...t),u.push(t.length)}if(0===d.length)return o;const p={...o,activeSectionIndex:0,activeZone:"main",document:{...jo(d,o.document.pageSettings,void 0,o.document.styles,void 0,o.document.assets),settings:o.document.settings},selection:{anchor:xi(d[0],0),focus:xi(d[d.length-1],oi(d[d.length-1]))}},f=n(p);if(f===p)return o;const g=ko(f);if(g.length!==d.length)return o;const m=s[s.length-1];if(!m)return o;const h=qx(o,e.getTargetBlocks,{blockIndex:i,rowIndex:m.rowIndex,cellIndex:m.cellIndex,paragraphIndex:0,tablePath:s,zone:c});if(!h)return o;let b=0;for(let e=0;e<l.length;e+=1){const t=l[e],n=u[e]??0,r=g.slice(b,b+n);b+=n;const o=h.tableBlock.rows[t.rowIndex]?.cells[t.cellIndex];o&&(o.blocks=it(o.blocks,r))}return Kx(o,h.targetBlocks,c)})};return{withExpandedTableCellSelection:t,applySelectionAwareTextCommand:e=>{n(e,"applySelectionAwareTextCommand")},applySelectionAwareParagraphCommand:e=>{n(e,"applySelectionAwareParagraphCommand")}}}(e)}function gw(e){return function(e){const t=Vx,{resolveTableCellRangeSelection:n,resolveSelectedTableCells:r,resolveHorizontalTableCellRange:o,resolveVerticalTableCellRange:a}=aw({getTargetBlocks:t,logger:e.logger}),{canMergeSelectedTableCells:i,canSplitSelectedTableCell:s,canMergeSelectedTableRows:l,canMergeSelectedTable:c,canSplitSelectedTableCellVertically:d,canSplitSelectedTable:u,canEditSelectedTableRow:p,canEditSelectedTableColumn:f}=ew({getTargetBlocks:t,resolveHorizontalTableCellRange:o,resolveVerticalTableCellRange:a}),{mergeSelectedTableCells:g,mergeSelectedTableRows:m,mergeSelectedTable:h,splitSelectedTableCellVertically:b,splitSelectedTableCell:y,splitSelectedTable:v}=lw({getTargetBlocks:t,resolveHorizontalTableCellRange:o,resolveVerticalTableCellRange:a,canMergeSelectedTableCells:i,canMergeSelectedTableRows:l,canSplitSelectedTableCell:s,canSplitSelectedTableCellVertically:d}),{insertSelectedTableRow:x,appendTableRowForTab:w,deleteSelectedTableRow:I,insertSelectedTableColumn:S,deleteSelectedTableColumn:C}=pw({getTargetBlocks:t}),k=(e,n)=>Gx(e,t,n),{withExpandedTableCellSelection:T,applySelectionAwareTextCommand:P,applySelectionAwareParagraphCommand:R}=fw({applyTransactionalState:e.applyTransactionalState,applySelectionToStatePreservingStructure:e.applySelectionToStatePreservingStructure,getTargetBlocks:t,resolveTableCellRangeSelection:n,resolveSelectedTableCells:r,logger:e.logger}),A=(t,n)=>{e.logger?.info(`insertTableCommand: ${t}x${n}`),e.applyTransactionalState(e=>function(e,t,n){const r=100/Math.max(1,n)+"%",o=e.trackChangesEnabled?Ig():void 0,a=[];for(let b=0;b<t;b+=1){const e=[];for(let o=0;o<n;o+=1)e.push({...ta([Go("")]),style:{width:r}});const t=Jo(e);o&&(t.style={revision:{...o,type:"insert"}}),a.push(t)}const i={...yo(a),style:{width:"100%"}},s=Ra(e,e.selection.focus),l=Lo(e.document),c=Ua(e),d=jr(e),u=e=>{const t=e.findIndex(e=>e.id===s.paragraphId||"paragraph"!==e.type&&ra(e).some(e=>e.id===s.paragraphId));return-1===t?{nextBlocks:e,found:!1}:{nextBlocks:[...e.slice(0,t+1),i,...e.slice(t+1)],found:!0}},p=l[c];if(!p)return e;const f={...p};let g=!1;if("header"===d){const e=u(p.header??[]);f.header=e.nextBlocks,g=e.found}else if("footer"===d){const e=u(p.footer??[]);f.footer=e.nextBlocks,g=e.found}else{const e=u(p.blocks);f.blocks=e.nextBlocks,g=e.found}if(!g)return e;const m=[...l];m[c]=f;const h=i.rows[0].cells[0].blocks[0];return"paragraph"!==h.type?e:{...e,document:{...e.document,sections:m},selection:J(xi(h,0))}}(e,t,n),{mergeKey:ef}),e.focusInput()};return{resolveTableCellRangeSelection:n,resolveHorizontalTableCellRange:o,resolveVerticalTableCellRange:a,canMergeSelectedTableCells:i,canSplitSelectedTableCell:s,canMergeSelectedTableRows:l,canMergeSelectedTable:c,canSplitSelectedTableCellVertically:d,canSplitSelectedTable:u,canEditSelectedTableRow:p,canEditSelectedTableColumn:f,mergeSelectedTableCells:g,mergeSelectedTableRows:m,mergeSelectedTable:h,splitSelectedTableCellVertically:b,splitSelectedTableCell:y,splitSelectedTable:v,insertSelectedTableRow:x,appendTableRowForTab:w,deleteSelectedTableRow:I,insertSelectedTableColumn:S,deleteSelectedTableColumn:C,getRowVisualWidth:Fx,getTableVisualWidth:Ex,findCellAtVisualColumn:Dx,findFirstNavigableParagraphInTable:Nx,updateBlocksInCurrentSection:Kx,resolveAdjacentTableCellPosition:Hx,resolveTableTabTarget:$x,applyTableAwareParagraphEdit:k,withExpandedTableCellSelection:T,applySelectionAwareTextCommand:P,applySelectionAwareParagraphCommand:R,insertTableCommand:A}}(e)}function mw(){let e=null;return{claim:t=>{e=t.pointerId??null},owns:t=>null===e||t.pointerId===e,release:()=>{e=null}}}function hw(e,t){let n=null;const r=(e,t,n)=>{const r=ko(e).find(e=>e.id===t);return r?{anchor:xi(r,n),focus:xi(r,n+1)}:null},o=(e,t)=>({...e,selection:{anchor:{...t.anchor},focus:{...t.focus}}}),a=mw(),i=i=>{if(!a.owns(i))return;const s=n;if(!s)return;const l=t.zoomFactor?.()??1,c=(i.clientX-s.startClientX)/l,d=(i.clientY-s.startClientY)/l,u=e.getMaxWidth(t.state,s.paragraphId),{width:p,height:f}=ve(s,c,d,i.shiftKey,u),g=r(t.state,s.paragraphId,s.paragraphOffset);g?t.applyState(e.applyResize(o(t.state,g),p,f,s.handleDirection)):t.logger.warn(`${e.label} resize:missing paragraph`,s)},s=()=>{const e=n;e&&t.updateHistoryState(n=>({...n,undoStack:Sx(n.undoStack,t.cloneState(e.initialState)),redoStack:[]})),l(),t.focusInput()},l=()=>{n=null,a.release(),window.removeEventListener("pointermove",i),window.removeEventListener("pointerup",s),window.removeEventListener("pointercancel",s)};return{start:(l,c,d,u,p)=>{const f=r(p,l,c);if(!f)return;const g=e.getSelected(o(p,f));g&&(n={paragraphId:l,paragraphOffset:c,handleDirection:d,startClientX:u.clientX,startClientY:u.clientY,startWidth:g.width,startHeight:g.height,aspectRatio:g.width/g.height,initialState:t.cloneState(p)},a.claim(u),window.addEventListener("pointermove",i),window.addEventListener("pointerup",s),window.addEventListener("pointercancel",s))},stop:l}}function bw(e,t){let n=null;const r=mw(),o=o=>{if(!r.owns(o))return;const a=n;if(!a)return;let i=((180*Math.atan2(o.clientY-a.centerY,o.clientX-a.centerX)/Math.PI+90)%360+360)%360;o.shiftKey&&(i=15*Math.round(i/15)%360);const s=((e,t,n)=>{const r=ko(e).find(e=>e.id===t);return r?{anchor:xi(r,n),focus:xi(r,n+1)}:null})(t.state,a.paragraphId,a.paragraphOffset);s?t.applyState(e.applyRotate(((e,t)=>({...e,selection:{anchor:{...t.anchor},focus:{...t.focus}}}))(t.state,s),i)):t.logger.warn(`${e.label} rotate:missing paragraph`,a)},a=()=>{const e=n;e&&t.updateHistoryState(n=>({...n,undoStack:Sx(n.undoStack,t.cloneState(e.initialState)),redoStack:[]})),i(),t.focusInput()},i=()=>{n=null,r.release(),window.removeEventListener("pointermove",o),window.removeEventListener("pointerup",a),window.removeEventListener("pointercancel",a)};return{start:(e,i,s,l)=>{const c=s.currentTarget.closest(".oasis-editor-selection-overlay");if(!c)return;const d=c.getBoundingClientRect();n={paragraphId:e,paragraphOffset:i,centerX:d.left+d.width/2,centerY:d.top+d.height/2,initialState:t.cloneState(l)},r.claim(s),window.addEventListener("pointermove",o),window.addEventListener("pointerup",a),window.addEventListener("pointercancel",a)},stop:i}}function yw(e,t){return Math.max(1e-4,1-e-t)}function vw(e,t,n,r){const o=Math.max(.01,1-e-t),a=Math.max(0,Math.min(n,.99-t)),i=Math.max(0,Math.min(r,.99-a));return a+i>=.99?{near:Math.max(0,.99-o-t),far:t}:{near:a,far:i}}function xw(e){let t=null;const n=(e,t,n)=>{const r=ko(e).find(e=>e.id===t);return r?{anchor:xi(r,n),focus:xi(r,n+1)}:null},r=(e,t)=>({...e,selection:{anchor:{...t.anchor},focus:{...t.focus}}}),o=mw(),a=a=>{if(!o.owns(a))return;const i=t;if(!i)return;const s=e.zoomFactor?.()??1,l=(a.clientX-i.startClientX)/s,c=(a.clientY-i.startClientY)/s,d="move"===i.mode?function(e,t,n){const{startWidth:r,startHeight:o}=e,a=e.startCrop.left??0,i=e.startCrop.top??0,s=e.startCrop.right??0,l=e.startCrop.bottom??0,c=yw(a,s)/r,d=yw(i,l)/o,u=1-a-s,p=1-i-l,f=Math.max(0,Math.min(1-u,a-t*c)),g=Math.max(0,Math.min(1-p,i-n*d));return{crop:{left:f,right:Math.max(0,1-u-f),top:g,bottom:Math.max(0,1-p-g)},width:Math.round(r),height:Math.round(o)}}(i,l,c):function(e,t,n){const{startWidth:r,startHeight:o}=e,a=e.startCrop.left??0,i=e.startCrop.top??0,s=e.startCrop.right??0,l=e.startCrop.bottom??0,c=yw(a,s)/r,d=yw(i,l)/o,u=_e(e.handleDirection,"x"),p=_e(e.handleDirection,"y");let f=a,g=s,m=r;if(0!==u)if(u<0){m=nt(r-t,24,r+a/c);const e=vw(a,s,a-(m-r)*c,s);f=e.near,g=e.far}else{m=nt(r+t,24,r+s/c);const e=vw(a,s,a,s-(m-r)*c);f=e.near,g=e.far}let h=i,b=l,y=o;if(0!==p)if(p<0){y=nt(o-n,24,o+i/d);const e=vw(i,l,i-(y-o)*d,l);h=e.near,b=e.far}else{y=nt(o+n,24,o+l/d);const e=vw(i,l,i,l-(y-o)*d);h=e.near,b=e.far}return{crop:{left:f,top:h,right:g,bottom:b},width:Math.round(m),height:Math.round(y)}}(i,l,c),u=n(e.state,i.paragraphId,i.paragraphOffset);u?e.applyState(Iv(r(e.state,u),{crop:d.crop,width:d.width,height:d.height})):e.logger.warn("image crop:missing paragraph",i)},i=()=>{const n=t;n&&e.updateHistoryState(t=>({...t,undoStack:Sx(t.undoStack,e.cloneState(n.initialState)),redoStack:[]})),s(),e.focusInput()},s=()=>{t=null,o.release(),window.removeEventListener("pointermove",a),window.removeEventListener("pointerup",i),window.removeEventListener("pointercancel",i)},l=(s,l,c,d,u,p)=>{const f=n(u,s,l);if(!f)return;const g=vv(r(u,f)),m=g&&ki(g.run);if(!m)return;const h={...m.crop??{}};t={paragraphId:s,paragraphOffset:l,handleDirection:c,startClientX:d.clientX,startClientY:d.clientY,startWidth:m.width,startHeight:m.height,startCrop:h,initialState:e.cloneState(u),mode:p},o.claim(d),window.addEventListener("pointermove",a),window.addEventListener("pointerup",i),window.addEventListener("pointercancel",i)};return{start:(e,t,n,r,o)=>l(e,t,n,r,o,"handle"),startMove:(e,t,n,r)=>l(e,t,"se",n,r,"move"),stop:s}}function ww(e){return function(e){const[t,n]=Nt(!1),[r,o]=Nt(!1),[a,i]=Nt(null);mn(()=>{r()&&!m(e.state)&&o(!1)});const s=()=>{m(e.state)?o(e=>!e):o(!1)},[l,c]=Nt({x:0,y:0}),[d,u]=Nt(null);let p=null,f=null,g=null;const m=e=>{const t=Ri(e);if(t.isCollapsed||t.startIndex!==t.endIndex||t.endParagraphOffset-t.startParagraphOffset!==1)return null;const n=ko(e)[t.startIndex];if(!n)return null;let r=0;for(const o of n.runs){const a=r;if(r+=o.text.length,"image"===o.kind&&1===o.text.length&&a===t.startParagraphOffset)return{paragraph:n,run:o,startOffset:a,width:o.image.width,height:o.image.height,src:Ia(e.document,o.image.src)}}return null},h=(t,n)=>e.resolvePositionAtSurfacePoint(t,n),b=()=>{g||(g=document.createElement("style"),g.setAttribute("data-oasis-image-drag-cursor",""),g.textContent="*, *::before, *::after { cursor: grabbing !important; }",document.head.appendChild(g))},y=()=>{g&&(g.remove(),g=null),document.body.style.cursor=""},v=mw(),x=()=>{y(),f=null,p=null,n(!1),i(null),u(null),v.release(),window.removeEventListener("pointermove",k),window.removeEventListener("pointerup",T),window.removeEventListener("pointercancel",T)},w=()=>{x()},I=hw({label:"image",getSelected:e=>m(e),applyResize:(e,t,n)=>xv(e,t,n),getMaxWidth:(t,n)=>Bv(e.surfaceRef(),t.document,n,t.activeSectionIndex??0)},{state:e.state,applyState:e.applyState,updateHistoryState:e.updateHistoryState,cloneState:e.cloneState,focusInput:e.focusInput,logger:e.logger,zoomFactor:e.zoomFactor}),S=bw({label:"image",applyRotate:(e,t)=>function(e,t){const n=Tv(t);return Av(e,e=>({...e,rotation:n}))}(e,t)},{state:e.state,applyState:e.applyState,updateHistoryState:e.updateHistoryState,cloneState:e.cloneState,focusInput:e.focusInput,logger:e.logger}),C=xw({state:e.state,applyState:e.applyState,updateHistoryState:e.updateHistoryState,cloneState:e.cloneState,focusInput:e.focusInput,logger:e.logger,zoomFactor:e.zoomFactor}),k=t=>{if(!v.owns(t))return;let r=p;if(!r){const o=f;if(!o)return;if(Math.abs(t.clientX-o.startClientX)+Math.abs(t.clientY-o.startClientY)<4)return;r={paragraphId:o.paragraphId,paragraphOffset:o.paragraphOffset,src:o.src,width:o.width,height:o.height,offsetX:o.offsetX,offsetY:o.offsetY},p=r,f=null,n(!0),b(),e.logger.info(`image drag:start ${r.paragraphId}@${r.paragraphOffset} client=(${t.clientX},${t.clientY})`)}c({x:t.clientX,y:t.clientY}),i({...r}),u(h(t.clientX,t.clientY))},T=t=>{if(!v.owns(t))return;const n=p;if(n||f){if(n){const r=h(t.clientX,t.clientY);r?(e.logger.info(`image drag:done ${n.paragraphId} -> ${r.paragraphId}:${r.runId}[${r.offset}]`),e.applyTransactionalState(e=>Ov(e,r),{mergeKey:tf})):e.logger.warn(`image drag:cancel ${n.paragraphId} no target at (${t.clientX},${t.clientY})`)}x(),e.focusInput()}else e.focusInput()},P=(t,r,o,a)=>{const s=o.currentTarget,l=a?{left:a.left,top:a.top,width:a.width,height:a.height}:s?.getBoundingClientRect();if(!l)return;const d=m(e.state);f={paragraphId:t,paragraphOffset:r,startClientX:o.clientX,startClientY:o.clientY,src:d?.src??"",width:d?.width??l.width,height:d?.height??l.height,offsetX:o.clientX-l.left,offsetY:o.clientY-l.top},p=null,c({x:o.clientX,y:o.clientY}),n(!1),i(null),u(null),v.claim(o),window.addEventListener("pointermove",k),window.addEventListener("pointerup",T),window.addEventListener("pointercancel",T)},R=(t,n,r)=>{r.preventDefault(),r.stopPropagation();const o=ci(e.state.document).find(e=>e.id===t);o&&e.applyState(ji(e.state,{anchor:xi(o,n),focus:xi(o,n+1)})),P(t,n,r),e.focusInputAfterPointerSelection()},A=(t,n,r,o)=>{o.preventDefault(),o.stopPropagation(),I.start(t,n,r,o,e.state)},M=(t,n,r)=>{r.preventDefault(),r.stopPropagation(),S.start(t,n,r,e.state)},O=(t,n,r,o)=>{o.preventDefault(),o.stopPropagation(),C.start(t,n,r,o,e.state)},B=(t,n,r)=>{r.preventDefault(),r.stopPropagation(),C.startMove(t,n,r,e.state)};return{dragging:t,cropMode:r,setCropMode:o,toggleCropMode:s,draggedImageInfo:a,mousePos:l,dropTargetPos:d,getSelectedImageInfo:m,startImageDrag:P,stopImageDrag:w,stopImageResize:I.stop,stopImageRotate:S.stop,stopImageCrop:C.stop,handleImagePointerDown:R,handleImageResizeHandlePointerDown:A,handleImageRotateHandlePointerDown:M,handleImageCropHandlePointerDown:O,handleImageCropBodyPointerDown:B}}(e)}function Iw(e){return function(e){const t=e=>{const t=Ax(e),n=t&&Jr(t.run);return n?{width:n.width,height:ge(n,e,0)}:null},n=hw({label:"text box",getSelected:t,applyResize:(e,t,n,r)=>Bx(e,t,n,{handleDirection:r}),getMaxWidth:(n,r)=>{const o=Bv(e.surfaceRef(),n.document,r,n.activeSectionIndex??0),a=t(n);return a?Math.max(o,a.width):o}},{state:e.state,applyState:e.applyState,updateHistoryState:e.updateHistoryState,cloneState:e.cloneState,focusInput:e.focusInput,logger:e.logger,zoomFactor:e.zoomFactor}),r=bw({label:"text box",applyRotate:(e,t)=>Mx(e,t)},{state:e.state,applyState:e.applyState,updateHistoryState:e.updateHistoryState,cloneState:e.cloneState,focusInput:e.focusInput,logger:e.logger}),o=(t,r,o,a)=>{a.preventDefault(),a.stopPropagation(),n.start(t,r,o,a,e.state)},a=(t,n,o)=>{o.preventDefault(),o.stopPropagation(),r.start(t,n,o,e.state)};return{handleTextBoxResizeHandlePointerDown:o,handleTextBoxRotateHandlePointerDown:a,stopTextBoxResize:n.stop,stopTextBoxRotate:r.stop}}(e)}function Sw(e){return function(e){const[t,n]=Nt(void 0),r=()=>{n(void 0)};mn(()=>{ga(e.state().selection)||r()});const o=(e,t)=>{n(n=>{const r={...n??{}};return null==t||""===t?delete r[e]:r[e]=t,Object.keys(r).length>0?r:void 0})},a=(e,t)=>{n(n=>{const r={...n??{}};return r[e]=t,"superscript"===e&&t&&(r.subscript=!1),"subscript"===e&&t&&(r.superscript=!1),r})},i=()=>{const n=$t(e.state()),r=t();return ga(e.state().selection)&&r?{...n,bold:r.bold??n.bold,italic:r.italic??n.italic,underline:r.underline??n.underline,underlineStyle:void 0!==r.underlineStyle?String(r.underlineStyle??""):n.underlineStyle,strike:r.strike??n.strike,superscript:r.superscript??n.superscript,subscript:r.subscript??n.subscript,fontFamily:r.fontFamily??n.fontFamily,fontSize:void 0!==r.fontSize&&null!==r.fontSize?String(r.fontSize):n.fontSize,color:r.color??n.color,highlight:r.highlight??n.highlight,textShading:r.shading??n.textShading,link:r.link??n.link,characterStyleId:void 0!==r.styleId&&null!==r.styleId?String(r.styleId):n.characterStyleId}:n},s=(t,n)=>{if(ga(e.state().selection))return e.logger.info(`setPendingStyle:${t}=${JSON.stringify(n)}`),e.clearPreferredColumn(),e.resetTransactionGrouping(),o(t,n),void e.focusInput();e.commandsController().applyValueStyleCommand(t,n)},l=t=>{if(ga(e.state().selection)){const n=!i()[t];return e.logger.info(`setPendingStyle:${t}=${JSON.stringify(n)}`),e.clearPreferredColumn(),e.resetTransactionGrouping(),a(t,n),void e.focusInput()}e.commandsController().applyBooleanStyleCommand(t)},c=t=>{if(ga(e.state().selection))return e.clearPreferredColumn(),e.resetTransactionGrouping(),n(e=>({...e,underline:null!==t,underlineStyle:"single"===t?null:t})),void e.focusInput();e.commandsController().applyUnderlineStyleCommand(t)};return{pendingCaretTextStyle:t,clearPendingCaretTextStyle:r,toolbarStyleState:i,applyToolbarValueStyleCommand:s,applyToolbarUnderlineStyleCommand:c,applyToolbarBooleanStyleCommand:l}}(e)}function Cw(e,t,n={}){if(!t)return[];const r=[],o=ci(e),{matchCase:a=!1,wholeWord:i=!1}=n,s=a?"g":"gi";let l=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");i&&(l=`\\b${l}\\b`);const c=new RegExp(l,s);return o.forEach((e,t)=>{const n=mi(e);let o;for(c.lastIndex=0;null!==(o=c.exec(n));){const n=o.index,a=o.index+o[0].length;r.push({anchor:xi(e,n),focus:xi(e,a),paragraphIndex:t}),o.index===c.lastIndex&&c.lastIndex++}}),r}function kw(e,t,n,r={}){const o=Cw(e.document,t,r);if(0===o.length)return e;let a=e;for(let i=o.length-1;i>=0;i-=1){const e=o[i];a=ji(a,{anchor:e.anchor,focus:e.focus}),a=Ju(a,n)}return a}function Tw(e,t,n,r,o,a){const i=e+n,s=t+r;return(a<t?t-a:a>s?a-s:0)*Fr+(o<e?e-o:o>i?o-i:0)}function Pw(e,t,n){if(0===e.slots.length)return{offset:e.startOffset,score:Number.POSITIVE_INFINITY};let r=e.slots[0].offset,o=Number.POSITIVE_INFINITY,a=e.slots[0].left,i=e.slots[0].top,s=e.slots[0].height;for(const l of e.slots){const e=n<l.top?l.top-n:n>l.top+l.height?n-(l.top+l.height):0,c=Math.abs(t-l.left),d=e*Fr+c;d<o&&(o=d,r=l.offset,a=l.left,i=l.top,s=l.height)}return{offset:r,score:o,slotLeft:a,slotTop:i,slotHeight:s}}function Rw(e,t,n){let r=e.startOffset,o=Number.POSITIVE_INFINITY;for(const a of e.lines){const{offset:e,score:i}=Pw(a,t,n);i<o&&(o=i,r=e)}return Math.max(e.startOffset,Math.min(r,e.endOffset))}function Aw(e,t,n){return e>=n.left&&e<=n.left+n.width&&t>=n.top&&t<=n.top+n.height}function Mw(e){const{snapshot:t,state:n}=e,r=e.pierce??!1,o=e.zoomFactor&&e.zoomFactor>0?e.zoomFactor:1,a=t.surfaceRect,i=a.left+(e.clientX-a.left)/o,s=a.top+(e.clientY-a.top)/o,l=function(e,t,n){if(0===e.length)return null;let r=e[0],o=Number.POSITIVE_INFINITY;for(const a of e){const e=Tw(a.left,a.top,a.width,a.height,t,n);e<o&&(o=e,r=a)}return r}(t.pages,i,s);if(!l)return null;const c=function(e,t){const n=t-e.top;return n<e.bodyTop?"header":void 0!==e.footnoteSeparatorTop&&n>=e.footnoteSeparatorTop&&n<(e.footerTop??e.height)?"footnote":n>=e.bodyBottom?"footer":"main"}(l,s),d=function(e,t,n,r,o,a){for(let i=e.floatingTextBoxes.length-1;i>=0;i-=1){const s=e.floatingTextBoxes[i];if(s.pageIndex===t&&s.zone===n&&(!s.behindDoc||a)&&r>=s.left&&r<=s.left+s.width&&o>=s.top&&o<=s.top+s.height)return s}return null}(t,l.index,c,i,s,r);if(d){const e=t.paragraphsById.get(d.paragraphId)??[],n=e.find(e=>e.pageIndex===l.index&&e.zone===c&&d.startOffset>=e.startOffset&&d.startOffset<=e.endOffset)??e[0];if(n){const e=Math.max(n.startOffset,Math.min(d.startOffset,n.endOffset)),t=xi(n.paragraph,e);return{zone:c,footnoteId:n.footnoteId,paragraphId:d.paragraphId,paragraphOffset:e,position:t,source:"canvas-layout",resolvedFromParagraph:!0,tableCellAnchorPosition:n.tableCell?.anchorPosition,caretViewport:{left:d.left,top:d.top,height:d.height},textBox:{paragraphId:d.paragraphId,paragraphOffset:e,startOffset:d.startOffset,endOffset:d.endOffset,left:d.left,top:d.top,width:d.width,height:d.height}}}}const u=function(e,t,n,r,o,a){for(let i=e.floatingImages.length-1;i>=0;i-=1){const s=e.floatingImages[i];if(s.pageIndex===t&&s.zone===n&&(!s.behindDoc||a)&&Aw(r,o,s))return s}for(const i of e.inlineImages)if(i.pageIndex===t&&i.zone===n&&Aw(r,o,i))return i;return null}(t,l.index,c,i,s,r);if(u){const e=t.paragraphsById.get(u.paragraphId)??[],n=e.find(e=>e.pageIndex===l.index&&e.zone===c&&u.startOffset>=e.startOffset&&u.startOffset<=e.endOffset)??e[0];if(n){const e=Math.max(n.startOffset,Math.min(u.startOffset,n.endOffset)),t=xi(n.paragraph,e);return{zone:c,footnoteId:n.footnoteId,paragraphId:u.paragraphId,paragraphOffset:e,position:t,source:"canvas-layout",resolvedFromParagraph:!0,tableCellAnchorPosition:n.tableCell?.anchorPosition,caretViewport:{left:u.left,top:u.top,height:u.height},image:{paragraphId:u.paragraphId,paragraphOffset:e,startOffset:u.startOffset,endOffset:u.endOffset,left:u.left,top:u.top,width:u.width,height:u.height}}}}const p=function(e,t,n){if(0===e.length)return null;let r=null;for(const i of e)for(const e of i.lines){const o=e.top-2,a=e.top+e.height+2;if(n<o||n>a)continue;const{offset:s,score:l,slotLeft:c,slotTop:d,slotHeight:u}=Pw(e,t,n);(!r||l<r.score)&&(r={paragraph:i,offset:s,score:l,caretViewport:void 0!==c&&void 0!==d&&void 0!==u?{left:c,top:d,height:u}:void 0})}if(r)return{paragraph:r.paragraph,offset:r.offset,caretViewport:r.caretViewport};let o=null,a=Number.POSITIVE_INFINITY;for(const i of e){const e=Tw(i.left,i.top,Math.max(1,i.width),Math.max(1,i.height),t,n);e<a&&(a=e,o=i)}return o?{paragraph:o,offset:Rw(o,t,n),caretViewport:{left:o.left,top:o.top,height:Math.max(16,Math.min(32,o.height||24))}}:null}(t.paragraphs.filter(e=>e.pageIndex===l.index&&e.zone===c),i,s);if(!p){const e=n.selection.focus.paragraphId,r=n.selection.focus.offset,o=function(e,t,n,r,o){return e.unsupportedRegions.find(e=>e.pageIndex===t&&e.zone===n&&r>=e.left&&r<=e.left+e.width&&o>=e.top&&o<=e.top+e.height)?.reason??null}(t,l.index,c,i,s);return{zone:c,paragraphId:e,paragraphOffset:r,position:{...n.selection.focus},source:"canvas-layout",resolvedFromParagraph:!1,missReason:o??"zone-without-paragraph"}}const f=p.paragraph,g=Math.max(0,Math.min(p.offset,f.textLength)),m=p.caretViewport;let h;if(m&&i!==m.left){const e=f.lines.filter(e=>s>=e.top&&s<=e.top+e.height&&e.slots.some(e=>e.offset===g&&e.left===m.left&&e.top===m.top));if(1===e.length){const t=e[0].slots,n=t.filter(e=>e.offset===g),r=t.find(e=>e.offset===g-1),o=t.find(e=>e.offset===g+1);1===n.length&&r&&o&&r.left<m.left&&m.left<o.left&&(h=i<m.left?"before-markers":"after-markers")}}const b=qa(f.paragraph,g,h);return{zone:c,footnoteId:f.footnoteId,paragraphId:f.paragraphId,paragraphOffset:g,position:b,source:"canvas-layout",resolvedFromParagraph:!0,tableCellAnchorPosition:f.tableCell?.anchorPosition,caretViewport:p.caretViewport,insideTextLine:f.lines.some(e=>{if(s<e.top||s>e.top+e.height||e.slots.length<2)return!1;const t=e.slots.map(e=>e.left);return i>=Math.min(...t)&&i<=Math.max(...t)})}}function Ow(e){return function(e){const t=(t,n,r={})=>{const o=e.surfaceRef();if(!o)return null;const a=e.state(),i=e.zoomFactor(),s=e.canvasSnapshotProvider.getCanvasLayoutSnapshot({surface:o,state:a,documentLayout:e.documentLayout(),zoomFactor:i});if(function(e){Wp&&(Up=e?function(e){return{surfaceRect:{left:e.surfaceRect.left,top:e.surfaceRect.top,width:e.surfaceRect.width,height:e.surfaceRect.height},pages:(t=e.pages,t.map(e=>({index:e.index,left:e.left,top:e.top,width:e.width,height:e.height,bodyTop:e.bodyTop,bodyBottom:e.bodyBottom}))),paragraphs:e.paragraphs.map(e=>{return{paragraphId:e.paragraphId,paragraphIndex:e.paragraphIndex,zone:e.zone,pageIndex:e.pageIndex,startOffset:e.startOffset,endOffset:e.endOffset,textLength:e.textLength,left:e.left,top:e.top,width:e.width,height:e.height,lines:(t=e.lines,t.map(e=>{return{startOffset:e.startOffset,endOffset:e.endOffset,top:e.top,height:e.height,slots:(t=e.slots,t.map(e=>({offset:e.offset,left:e.left,top:e.top,height:e.height})))};var t})),tableCell:e.tableCell?{tableId:e.tableCell.tableId,rowIndex:e.tableCell.rowIndex,cellIndex:e.tableCell.cellIndex,left:e.tableCell.left,top:e.tableCell.top,width:e.tableCell.width,height:e.tableCell.height}:void 0,verticalMode:e.verticalMode};var t}),inlineImages:e.inlineImages.map(e=>({paragraphId:e.paragraphId,paragraphIndex:e.paragraphIndex,zone:e.zone,pageIndex:e.pageIndex,startOffset:e.startOffset,endOffset:e.endOffset,left:e.left,top:e.top,width:e.width,height:e.height})),inlineTextBoxes:e.inlineTextBoxes.map(e=>({paragraphId:e.paragraphId,paragraphIndex:e.paragraphIndex,zone:e.zone,pageIndex:e.pageIndex,startOffset:e.startOffset,endOffset:e.endOffset,left:e.left,top:e.top,width:e.width,height:e.height,rotation:e.rotation})),unsupportedRegions:e.unsupportedRegions.map(e=>({...e}))};var t}(e):null)}(s),!s)return Xp(null),null;const l=Mw({snapshot:s,state:a,clientX:t,clientY:n,pierce:r.pierce??!1,zoomFactor:i});return Xp(l),l};return{resolveSurfaceHitAtPoint:t}}(e)}var Bw=[{x:0,y:0},{x:1,y:0},{x:1,y:1},{x:0,y:1}],Fw=/* @__PURE__ */new Map;function Ew(){return Bw.map(e=>({...e}))}var Dw=[[0,-1],[1,-1],[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1]];function Lw(e,t,n){const[r,o]=e,[a,i]=t,[s,l]=n,c=s-a,d=l-i,u=c*c+d*d;return 0===u?Math.hypot(r-a,o-i):Math.abs(c*(i-o)-d*(a-r))/Math.sqrt(u)}function Nw(e,t){if(e.length<3)return e.slice();let n=0,r=0;const o=e[0],a=e[e.length-1];for(let l=1;l<e.length-1;l+=1){const t=Lw(e[l],o,a);t>n&&(n=t,r=l)}if(n<=t)return[o,a];const i=Nw(e.slice(0,r+1),t),s=Nw(e.slice(r),t);return[...i.slice(0,-1),...s]}function zw(e,t,n){let r=0;for(let l=0;l<e.length;l+=1)1===e[l]&&(r+=1);if(t<=0||n<=0||0===r||r/(t*n)>=.985)return Ew();const o=function(e,t,n){const r=(r,o)=>r>=0&&r<t&&o>=0&&o<n&&1===e[o*t+r];let o=-1,a=-1;for(let u=0;u<n&&a<0;u+=1)for(let n=0;n<t;n+=1)if(1===e[u*t+n]){o=n,a=u;break}if(o<0)return[];const i=[];let s=o,l=a,c=6;const d=t*n*4;for(let u=0;u<d;u+=1){let e=!1;for(let t=1;t<=8;t+=1){const n=(c+t)%8,[o,a]=Dw[n],d=s+o,u=l+a;if(r(d,u)){i.push([s,l]),c=(n+4)%8,s=d,l=u,e=!0;break}}if(!e){i.push([s,l]);break}if(s===o&&l===a&&i.length>1)break}return i}(e,t,n);if(o.length<3)return Ew();const a=.012*Math.max(t,n);let i=Nw(o,a),s=a;for(;i.length>40;)s*=1.6,i=Nw(o,s);return i.length<3?Ew():i.map(([e,r])=>({x:Math.min(1,Math.max(0,e/t)),y:Math.min(1,Math.max(0,r/n))}))}function $w(e){const t=e.src,n=Fw.get(t);if(n)return n.map(e=>({...e}));const r=function(e){const t=e.naturalWidth||e.width,n=e.naturalHeight||e.height;if(!t||!n)return null;const r=Math.min(1,256/Math.max(t,n)),o=Math.max(1,Math.round(t*r)),a=Math.max(1,Math.round(n*r)),i=document.createElement("canvas");i.width=o,i.height=a;const s=i.getContext("2d",{willReadFrequently:!0});if(!s)return null;let l;s.drawImage(e,0,0,o,a);try{l=s.getImageData(0,0,o,a).data}catch{return null}const c=new Uint8Array(o*a);let d=0;for(let u=0;u<c.length;u+=1)l[4*u+3]>=128&&(c[u]=1,d+=1);return{mask:c,width:o,height:a,foreground:d}}(e);if(!r)return Ew();const o=zw(r.mask,r.width,r.height);return Fw.set(t,o),o.map(e=>({...e}))}function Hw(e){const{state:t,resetTransactionGrouping:n,applyTransactionalState:r,focusInput:o}=e,a=()=>vv(t())?"image":Ax(t())?"textBox":null,i=(e,t)=>{const i=a();i&&(n(),r(e=>t(e,i),{mergeKey:e}),o())},s=(e,n)=>{const o=Ia(t().document,n),a=t=>{const n=$w(t);r(t=>function(e,t,n){const r=ko(e);let o=!1;const a=r.map(e=>e.runs.some(e=>e.id===t&&"image"===e.kind)?{...ho(e),runs:e.runs.map(e=>{if(e.id!==t||"image"!==e.kind)return na(e);o=!0;const r={...e.image};return n&&n.length>0?r.wrapPolygon=n:delete r.wrapPolygon,{...e,image:r}})}:ho(e));return o?Vt(e,a,H(a,Ri(e))):e}(t,e,n),{mergeKey:ff})},i=ie(o,()=>{i.naturalWidth>0&&a(i)});i.complete&&i.naturalWidth>0&&a(i)};return{target:a,preset:()=>{const e=a();return"image"===e?function(e){const t=vv(e),n=t&&ki(t.run);return n?hv(n.floating):null}(t()):"textBox"===e?function(e){const t=Ax(e),n=t&&Jr(t.run);return n?hv(n.floating):null}(t()):null},fixedPosition:()=>{const e=a();return"image"===e?function(e){const t=vv(e),n=t&&ki(t.run);return yv(n?.floating)}(t()):"textBox"===e&&function(e){const t=Ax(e),n=t&&Jr(t.run);return yv(n?.floating)}(t())},setPreset:e=>{if(i(tg,(t,n)=>"image"===n?function(e,t){return Mv(e,e=>mv(e,t))}(t,e):function(e,t){return Ox(e,e=>mv(e,t))}(t,e)),"tight"===e||"through"===e){const e=vv(t()),n=e&&ki(e.run);n&&!n.wrapPolygon&&s(e.run.id,n.src)}},setFixedPosition:e=>i(ng,(t,n)=>"image"===n?function(e,t){return Mv(e,e=>e?bv(e,t):e)}(t,e):function(e,t){return Ox(e,e=>e?bv(e,t):e)}(t,e))}}function Ww(e){return function(e){let t=0;zn()&&Ut(()=>{t++});const n=n=>{if(t++,e.onNativeClipboardStart?.(),tp(e.state()))return n.preventDefault(),void(n.clipboardData&&function(e,t){try{const n=_u(e);return t.setData(Wu,n.token),!!Array.from(t.types).includes("application/x-oasis-chart-token")&&n.confirm()}catch{return!1}}(e.stateSnapshot?.()??e.state(),n.clipboardData)?e.onNativeClipboardSuccess?.():e.onNativeClipboardIssue?.("copy","unsupported"));const r=Wi(e.state());if(0!==r.length&&(n.preventDefault(),n.clipboardData)){try{n.clipboardData.setData("text/plain",r),n.clipboardData.setData("text/html",np(e.state()))}catch{return}e.onNativeClipboardSuccess?.()}},r=n=>{if(t++,e.onNativeClipboardStart?.(),e.isReadOnly())return void n.preventDefault();if(tp(e.state()))return n.preventDefault(),void e.onNativeClipboardIssue?.("cut","unsupported");const r=Wi(e.state());if(0!==r.length&&(n.preventDefault(),n.clipboardData)){try{n.clipboardData.setData("text/plain",r),n.clipboardData.setData("text/html",np(e.state()))}catch{return}e.onNativeClipboardSuccess?.(),e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>ap(e))),e.focusInput()}},o=n=>{const r=++t;if(e.isReadOnly())return void n.preventDefault();const o=e.consumePasteMode?.(),a=e.clipboardRequestGeneration?.(),i=()=>r!==t||e.clipboardRequestGeneration?.()!==a,s=Array.from(n.clipboardData?.types??[]).filter(Uu);if(n.clipboardData&&s.length){n.preventDefault();const t=e.forcePlainTextPaste();e.setForcePlainTextPaste(!1);const r=1===s.length?Xu(n.clipboardData.getData(s[0])):void 0,a=e.stateSnapshot?.();return t||o&&"rich"!==o||!r||!a?void e.onNativeClipboardIssue?.("paste","unsupported"):(n.currentTarget.value="",(async()=>{let t;try{t=await Hu(a,r)}catch{return void(i()||e.isReadOnly()||e.onNativeClipboardIssue?.("paste","unsupported"))}if(i()||e.isReadOnly())return;if(e.stateSnapshot?.()!==a)return void e.onNativeClipboardIssue?.("paste","document-changed");let n=!1;e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(r=>i()||e.isReadOnly()||r!==a?r:(n=!0,t)),n?(e.onNativeClipboardSuccess?.(),e.focusInput()):e.onNativeClipboardIssue?.("paste","document-changed")})())}if(e.forcePlainTextPaste()||"text"===o){e.setForcePlainTextPaste(!1);const t=n.clipboardData?.getData("text/plain")??"";return 0===t.length?void n.preventDefault():(n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(n=>e.applyTableAwareParagraphEdit(n,e=>ep(e,t))),n.currentTarget.value="",void e.focusInput())}const l="merge"!==o?fv(n.clipboardData):null;if(l)return n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping(),e.insertImageFromFile(l),n.currentTarget.value="",void e.focusInput();const c=Ip(n.clipboardData?.getData("text/html")??""),d="merge"===o?wp(e.state(),c):c;if(d.length>0)return n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>rp(e,d))),n.currentTarget.value="",void e.focusInput();const u=n.clipboardData?.getData("text/plain")??"";0!==u.length&&(n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>ep(e,u))),n.currentTarget.value="",e.focusInput())},a=n=>{if(t++,e.onNativeClipboardStart?.(),e.isReadOnly())return void n.preventDefault();const r=fv(n.dataTransfer);if(!r)return;n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping();const o=e.resolvePositionAtSurfacePoint(n.clientX,n.clientY)??e.state().selection.focus;e.insertImageFromFile(r,o),e.focusInput()};return{handleCopy:n,handleCut:r,handlePaste:o,handleDrop:a}}(e)}var jw=/* @__PURE__ */new WeakMap;function Uw(e,t){return function(e){return Hr(e.document).flatMap(e=>[...e.header??[],...e.blocks,...e.footer??[]])}(e).find(e=>"table"===e.type&&e.id===t)??null}function Vw(e,t,n,r,o){const a=r.getCanvasLayoutSnapshot({surface:e,state:t,documentLayout:n,zoomFactor:o});if(!a)return[];const i=jw.get(a);if(i)return i;const s=/* @__PURE__ */new Map,l=/* @__PURE__ */new Map;for(const d of a.paragraphs){const e=d.tableCell;if(!e)continue;const t=`${d.pageIndex}:${e.rowIndex}:${e.cellIndex}`,n=s.get(e.tableId)??/* @__PURE__ */new Map;let r=n.get(t);r||(r={tableId:e.tableId,rowIndex:e.rowIndex,cellIndex:e.cellIndex,pageIndex:d.pageIndex,left:e.left,top:e.top,right:e.left+e.width,bottom:e.top+e.height,width:e.width,height:e.height,contentMinWidth:0,contentMinHeight:0},n.set(t,r),s.set(e.tableId,n));const o=d.lines.flatMap(e=>e.slots.map(e=>e.left)),a=d.lines.map(e=>e.top+e.height),i=o.length>0?Math.min(...o):d.left,c=o.length>0?Math.max(...o):d.left,u=d.lines.length>0?d.lines[0].top:d.top,p=a.length>0?Math.max(...a):d.top+d.height,f=`${e.tableId}:${d.pageIndex}:${e.rowIndex}:${e.cellIndex}`,g=l.get(f);g?(g.left=Math.min(g.left,i),g.top=Math.min(g.top,u),g.right=Math.max(g.right,c),g.bottom=Math.max(g.bottom,p)):l.set(f,{left:i,top:u,right:c,bottom:p})}for(const[d,u]of s.entries())for(const e of u.values()){const t=l.get(`${d}:${e.pageIndex}:${e.rowIndex}:${e.cellIndex}`);t&&(e.contentMinWidth=Math.max(0,t.right-t.left),e.contentMinHeight=Math.max(0,t.bottom-t.top))}const c=[];for(const[d,u]of s.entries()){const e=Array.from(u.values());if(0===e.length)continue;const t=Math.min(...e.map(e=>e.left)),n=Math.min(...e.map(e=>e.top)),r=Math.max(...e.map(e=>e.right)),o=Math.max(...e.map(e=>e.bottom));c.push({tableId:d,cells:e,bounds:{left:t,top:n,right:r,bottom:o,width:Math.max(1,r-t),height:Math.max(1,o-n)}})}return jw.set(a,c),c}function Kw(e,t,n,r,o,a){const i=Vw(t,n,r,o,a);if(0===i.length)return null;let s=null;for(const d of i)if(!(e.clientX<d.bounds.left-4||e.clientX>d.bounds.right+4||e.clientY<d.bounds.top-4||e.clientY>d.bounds.bottom+4))for(const t of d.cells){const n=e.clientY>=t.top-4&&e.clientY<=t.bottom+4,r=e.clientX>=t.left-4&&e.clientX<=t.right+4;if(n){const n=Math.abs(e.clientX-t.left);n<=4&&(!s||n<s.distance)&&(s={geometry:d,cell:t,side:"left",distance:n});const r=Math.abs(e.clientX-t.right);r<=4&&(!s||r<s.distance)&&(s={geometry:d,cell:t,side:"right",distance:r})}if(r){const n=Math.abs(e.clientY-t.top);n<=4&&(!s||n<s.distance)&&(s={geometry:d,cell:t,side:"top",distance:n});const r=Math.abs(e.clientY-t.bottom);r<=4&&(!s||r<s.distance)&&(s={geometry:d,cell:t,side:"bottom",distance:r})}}if(!s)return null;const l=Uw(n,s.geometry.tableId);if(!l)return null;const c=Xa(l).find(e=>e.rowIndex===s.cell.rowIndex&&e.cellIndex===s.cell.cellIndex);return c?{tableId:s.geometry.tableId,rowIndex:s.cell.rowIndex,cellIndex:s.cell.cellIndex,side:s.side,rect:s.cell,tableNode:l,layoutEntry:c,tableGeometry:s.geometry}:null}var _w=1/.75;function Xw(e){return.75*e}function qw(e){return e*_w}var Gw=Yg;function Yw(e){return("number"==typeof e.style?.padding&&Number.isFinite(e.style.padding)?2*Math.max(0,qw(e.style.padding)):Math.max(0,(void 0!==e.style?.paddingLeft?qw(e.style.paddingLeft):7.2)+(void 0!==e.style?.paddingRight?qw(e.style.paddingRight):7.2)))+(e.style?.borderLeft?Math.max(0,qw(e.style.borderLeft.width)):1)+(e.style?.borderRight?Math.max(0,qw(e.style.borderRight.width)):1)}function Zw(e,t,n){const r=Math.max(1,e.rows.length),o=n.bounds.height/r,a=Array(r).fill(o),i=new Map(n.cells.map(e=>[`${e.rowIndex}:${e.cellIndex}`,e]));for(let s=0;s<r;s+=1){const n=Gw(e.rows[s]?.style?.height);if(null!==n){a[s]=Math.max(1,qw(n));continue}const r=t.find(e=>e.rowIndex===s&&1===e.rowSpan);if(r){const e=i.get(`${r.rowIndex}:${r.cellIndex}`);e&&(a[s]=Math.max(1,e.height))}}return a}function Jw(e,t,n){const r=Math.max(1,...t.map(e=>e.visualColumnIndex+Math.max(1,e.colSpan))),o=r-1,a=Array(r).fill(n.bounds.width/r),i=new Map(n.cells.map(e=>[`${e.rowIndex}:${e.cellIndex}`,e]));if(e.gridCols&&e.gridCols.length>=r)for(let l=0;l<r;l+=1)a[l]=Math.max(1,qw(e.gridCols[l]));else for(const l of t){if(1!==l.colSpan)continue;const e=i.get(`${l.rowIndex}:${l.cellIndex}`);e&&(a[l.visualColumnIndex]=Math.max(1,e.width))}const s={};for(let l=0;l<r;l+=1)s[l]=Math.max(10,Xw(a[l]));return{widthsPt:s,maxColumnIndex:o}}function Qw(e,t,n){if("row"!==t.type)return e;const r=t.initialRowHeightPx??qw(10),o=Math.max(qw(10),t.minRowHeightPx??qw(10)),a=Math.max(10,Xw(Math.max(o,r+n)));return function(e,t,n,r){return Gg(e,t,{[n]:r})}(e,t.tableId,t.index,a)}function eI(e){const t=e();if(!t)return{left:0,top:0,width:window.innerWidth,height:window.innerHeight};const n=t.getBoundingClientRect();return{left:n.left,top:n.top,width:Math.max(0,n.width),height:Math.max(0,n.height)}}var tI=null;function nI(e,t){tI=t,e?(document.body.classList.add("oasis-editor-hover-col-resize"),document.body.classList.remove("oasis-editor-hover-row-resize")):(document.body.classList.add("oasis-editor-hover-row-resize"),document.body.classList.remove("oasis-editor-hover-col-resize"))}function rI(e){e&&tI!==e||(tI=null,document.body.classList.remove("oasis-editor-hover-col-resize"),document.body.classList.remove("oasis-editor-hover-row-resize"))}function oI(e,t){nI(e,t)}function aI(e){return"undefined"!=typeof window&&"function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(e):globalThis.setTimeout(e,16)}function iI(e){"undefined"==typeof window||"function"!=typeof window.cancelAnimationFrame?globalThis.clearTimeout(e):window.cancelAnimationFrame(e)}function sI(e){const[t,n]=Nt(null);let r=null,o=null,a=null,i=null;const s={},l=()=>{r=null;const n=o;if(o=null,!n||t())return;const a=e.surfaceRef();if(!a)return void rI();const i=Kw(n,a,e.state(),e.documentLayout(),e.canvasSnapshotProvider,e.zoomFactor?.());i?nI("left"===i.side||"right"===i.side,s):rI()},c=mw(),d=e=>{c.owns(e)&&t()&&(i={clientX:e.clientX,clientY:e.clientY},null===a&&(a=aI(u)))},u=()=>{a=null;const r=i;i=null;const o=t();r&&o&&n({...o,currentPos:"column"===o.type?r.clientX:r.clientY,guideBounds:eI(e.viewportRef)})},p=()=>{o=null,i=null,null!==r&&(iI(r),r=null),null!==a&&(iI(a),a=null),n(null),rI(s),c.release(),window.removeEventListener("pointermove",d),window.removeEventListener("pointerup",f),window.removeEventListener("pointercancel",f)},f=n=>{if(!c.owns(n))return;const r=t();if(!r)return;const o=e.zoomFactor?.()??1,a=(("column"===r.type?n.clientX:n.clientY)-r.initialPos)/o;Math.abs(a)>=2&&e.applyTransactionalState(e=>"row"===r.type?Qw(e,r,a):function(e,t,n){if("column"!==t.type)return e;const r=Xw(n),o=t.maxColumnIndex??t.index,a={...t.columnWidthsPt??{}};for(let m=0;m<=o;m+=1)void 0===a[m]&&(a[m]=10);const i=t.minColumnWidthsPx??{},s=a[t.index]??10,l=Math.max(10,Xw(i[t.index]??qw(10)));if(t.resizeFromLeftEdge){const n=Math.max(0,t.initialTableIndentLeftPt??0);let o=Math.max(l,s-r),i=s-o;n+i<0&&(i=-n,o=s-i),a[t.index]=o;const c=Object.values(a).reduce((e,t)=>e+t,0),d=Math.max(0,n+i);return Zg(e,t.tableId,a,c,d)}let c=Math.max(l,s+r);const d=t.index===o;if(d)a[t.index]=c;else{const e=t.index+1,n=a[e]??10,r=Math.max(10,Xw(i[e]??qw(10)));let o=n-(c-s);o<r&&(o=r,c=s+(n-r),c=Math.max(l,c)),a[t.index]=c,a[e]=o}const u=Object.values(a).reduce((e,t)=>e+t,0),p=Uw(e,t.tableId),f=Gw(p?.style?.width),g=d?u:null!==f?f:void 0;return Zg(e,t.tableId,a,g)}(e,r,a)),p()};return{resizing:t,handlePointerMove:e=>{c.owns(e)&&(t()||(o={clientX:e.clientX,clientY:e.clientY},null===r&&(r=aI(l))))},handlePointerDown:t=>{o=null,null!==r&&(iI(r),r=null),rI();const a=e.surfaceRef();if(!a)return!1;const i=Kw(t,a,e.state(),e.documentLayout(),e.canvasSnapshotProvider,e.zoomFactor?.());if(!i)return!1;const l=e.state(),u=Xa(i.tableNode);if("left"===i.side||"right"===i.side){const r="left"===i.side&&0===i.layoutEntry.visualColumnIndex,o=r?0:"left"===i.side?i.layoutEntry.visualColumnIndex-1:i.layoutEntry.visualColumnIndex+i.layoutEntry.colSpan-1;if(o<0)return!1;const a="left"===i.side?i.rect.left:i.rect.right,{widthsPt:p,maxColumnIndex:g}=Jw(i.tableNode,u,i.tableGeometry),m=function(e,t,n,r){const o=qw(10),a={},i=new Map(r.cells.map(e=>[`${e.rowIndex}:${e.cellIndex}`,e]));for(const s of n){if(1!==s.colSpan)continue;if(!i.get(`${s.rowIndex}:${s.cellIndex}`))continue;const n=t.rows[s.rowIndex]?.cells[s.cellIndex];if(!n)continue;const r=s.visualColumnIndex,l=a[r]??o,c=n.blocks.reduce((t,n)=>"paragraph"!==n.type?t:Math.max(t,Dn(n,e.document.styles)),1);a[r]=Math.max(l,c+Yw(n)+12,o)}return a}(l,i.tableNode,u,i.tableGeometry);return n({type:"column",tableId:i.tableId,index:o,initialPos:a,currentPos:a,columnWidthsPt:p,maxColumnIndex:g,minColumnWidthsPx:m,resizeFromLeftEdge:r,initialTableIndentLeftPt:Gw(i.tableNode.style?.indentLeft)??0,guideBounds:eI(e.viewportRef)}),oI(!0,s),c.claim(t),window.addEventListener("pointermove",d),window.addEventListener("pointerup",f),window.addEventListener("pointercancel",f),t.preventDefault(),t.stopPropagation(),!0}const p=Zw(i.tableNode,u,i.tableGeometry),g="top"===i.side?i.layoutEntry.visualRowIndex-1:i.layoutEntry.visualRowIndex+i.layoutEntry.rowSpan-1;if(g<0||g>=p.length)return!1;const m="top"===i.side?i.rect.top:i.rect.bottom,h=function(e,t,n,r){const o=e.rows[r];if(!o)return qw(10);const a=qw(10);let i=a;for(let s=0;s<o.cells.length;s+=1){if(!o.cells[s])continue;const e=t.find(e=>e.rowIndex===r&&e.cellIndex===s);if(!e||1!==e.rowSpan)continue;const a=n.cells.find(e=>e.rowIndex===r&&e.cellIndex===s);a&&(i=Math.max(i,a.contentMinHeight+4))}return Math.max(a,i)}(i.tableNode,u,i.tableGeometry,g);return n({type:"row",tableId:i.tableId,index:g,initialPos:m,currentPos:m,initialRowHeightPx:p[g],minRowHeightPx:h,guideBounds:eI(e.viewportRef)}),oI(!1,s),c.claim(t),window.addEventListener("pointermove",d),window.addEventListener("pointerup",f),window.addEventListener("pointercancel",f),t.preventDefault(),t.stopPropagation(),!0},stop:p}}var lI=null;function cI(e){const t=(e.bounds.width+(e.currentClientX-e.startClientX))/e.bounds.width,n=(e.bounds.height+(e.currentClientY-e.startClientY))/e.bounds.height,r=Object.values(e.widthsPt),o=r.length>0?Math.min(...r):1,a=o>0?10/o:0,i=qw(10),s=e.rowHeightsPx.length>0?Math.min(...e.rowHeightsPx):i,l=s>0?i/s:0;return{scaleX:Math.max(a,t),scaleY:Math.max(l,n)}}function dI(e){const[t,n]=Nt(null);let r=null,o=null;const a={},i=mw(),s=e=>{i.owns(e)&&t()&&(o={clientX:e.clientX,clientY:e.clientY},null===r&&(r=aI(l)))},l=()=>{r=null;const e=o;o=null,e&&n(t=>t?{...t,currentClientX:e.clientX,currentClientY:e.clientY}:null)},c=()=>{o=null,null!==r&&(iI(r),r=null),n(null),i.release(),window.removeEventListener("pointermove",s),window.removeEventListener("pointerup",d),window.removeEventListener("pointercancel",d),lI===a&&(lI=null,"nwse-resize"===document.body.style.cursor&&(document.body.style.cursor=""))},d=n=>{if(!i.owns(n))return;const r=t();if(r){const t=Math.abs(n.clientX-r.startClientX),o=Math.abs(n.clientY-r.startClientY);if(t>=2||o>=2){const t={...r,currentClientX:n.clientX,currentClientY:n.clientY},{scaleX:o,scaleY:a}=cI(t);e.applyTransactionalState(e=>function(e,t,n,r){const o={};for(const l of Object.keys(t.widthsPt)){const e=Number(l);o[e]=Math.max(10,t.widthsPt[e]*n)}const a=Object.values(o).reduce((e,t)=>e+t,0),i=Zg(e,t.tableId,o,a),s={};return t.rowHeightsPx.forEach((e,t)=>{s[t]=Math.max(10,Xw(e*r))}),Gg(i,t.tableId,s)}(e,t,o,a))}}c()};return{resizing:t,previewRect:()=>{const e=t();if(!e)return null;const{scaleX:n,scaleY:r}=cI(e);return{left:e.bounds.left,top:e.bounds.top,width:e.bounds.width*n,height:e.bounds.height*r}},handlePointerDown:(t,r)=>{const o=e.surfaceRef();if(!o)return;const l=Vw(o,e.state(),e.documentLayout(),e.canvasSnapshotProvider,e.zoomFactor?.()).find(e=>e.tableId===t),c=Uw(e.state(),t);if(!l||!c)return;const u=Xa(c),{widthsPt:p}=Jw(c,u,l),f=Zw(c,u,l),g=Object.values(p).reduce((e,t)=>e+t,0);n({tableId:t,bounds:{left:l.bounds.left,top:l.bounds.top,width:Math.max(1,l.bounds.width),height:Math.max(1,l.bounds.height)},startClientX:r.clientX,startClientY:r.clientY,currentClientX:r.clientX,currentClientY:r.clientY,widthsPt:p,totalWidthPt:g,rowHeightsPx:f}),lI=a,document.body.style.cursor="nwse-resize",i.claim(r),window.addEventListener("pointermove",s),window.addEventListener("pointerup",d),window.addEventListener("pointercancel",d),r.preventDefault(),r.stopPropagation()},stop:c}}var uI=null;function pI(e,t,n,r){if(!e)return null;for(const o of e)if("table"===o.type){if(o.id===t)return{table:o,nested:n,movableTopLevelStory:r};for(const e of o.rows)for(const n of e.cells){const e=pI(n.blocks,t,!0,!1);if(e)return e}}return null}function fI(e,t){for(const n of Lo(e)){for(const e of[n.blocks,n.header,n.footer]){const n=pI(e,t,!1,!0);if(n)return n}for(const e of[n.firstPageHeader,n.evenPageHeader,n.firstPageFooter,n.evenPageFooter]){const n=pI(e,t,!1,!1);if(n)return n}}for(const n of Object.values(e.footnotes?.items??{})){const e=pI(n.blocks,t,!1,!1);if(e)return e}for(const n of Object.values(e.endnotes?.items??{})){const e=pI(n.blocks,t,!1,!1);if(e)return e}return null}function gI(e){return function(e){const[t,n]=Nt(!1),[r,o]=Nt(null),[a,i]=Nt(null),[s,l]=Nt(0),[c,d]=Nt(0),[u,p]=Nt({x:0,y:0});let f=null,g=null;const m={},h=(e,t)=>e===t||null!==e&&null!==t&&e.paragraphId===t.paragraphId&&e.runId===t.runId&&e.offset===t.offset,b=e=>{i(t=>h(t,e)?t:e)},y=mw(),v=()=>{g=null,null!==f&&(iI(f),f=null),n(!1),o(null),i(null),y.release(),window.removeEventListener("pointermove",w),window.removeEventListener("pointerup",I),window.removeEventListener("pointercancel",I),uI===m&&(uI=null,"grabbing"===document.body.style.cursor&&(document.body.style.cursor=""))},x=()=>{f=null;const n=g;if(g=null,!n||!t())return;p({x:n.clientX,y:n.clientY});const o=e.resolvePositionAtSurfacePoint(n.clientX,n.clientY),a=r()?.tableId;o&&a&&function(e,t,n){const r=fI(e,n);return Boolean(r?.table&&ra(r.table).some(e=>e.id===t))}(e.state().document,o.paragraphId,a)?b(null):b(o)},w=e=>{if(y.owns(e)){if(!t()){if(Math.abs(e.clientY-s())<=4)return;n(!0),uI=m,document.body.style.cursor="grabbing"}g={clientX:e.clientX,clientY:e.clientY},null===f&&(f=aI(x))}},I=n=>{if(!y.owns(n))return;const o=r();if(t()){const t=e.resolvePositionAtSurfacePoint(n.clientX,n.clientY),r=o?.tableId;r&&e.applyTransactionalState(e=>{const o=fI(e.document,r),a=o?.table;if(a?.style?.floating){const t=a.style.floating;return _g(e,r,"floating",{...t,x:(t.x??0)+(n.clientX-c())*go,y:(t.y??0)+(n.clientY-s())*go,xAlign:void 0,yAlign:void 0})}return o&&!o.nested&&o.movableTopLevelStory&&t?k(e,r,t):e})}v(),e.focusInput()};return{dragging:t,draggedTableInfo:r,mousePos:u,dropTargetPos:a,handlePointerDown:(e,t)=>{t.preventDefault(),t.stopPropagation();const r=t.currentTarget.getBoundingClientRect(),a=r;o({tableId:e,width:a.width,height:a.height,offsetX:t.clientX-r.left,offsetY:t.clientY-r.top}),l(t.clientY),d(t.clientX),p({x:t.clientX,y:t.clientY}),n(!1),i(null),y.claim(t),window.addEventListener("pointermove",w),window.addEventListener("pointerup",I),window.addEventListener("pointercancel",I)},stop:v}}(e)}function mI(e){const t=La(e);if(t.error||"TC"!==t.command)return;const[n,...r]=t.tokens.slice(1);if(!n||"quoted"!==n.kind||!n.value.trim()||n.value.length>4096||/[\u0000-\u001f\u007f]/.test(n.value))return;let o,a=1,i=!1;const s=/* @__PURE__ */new Set;for(let l=0;l<r.length;l++){const e=r[l];if("switch"!==e.kind)return;const t=e.value.toLowerCase();if(s.has(t))return;if(s.add(t),"n"===t){i=!0;continue}if("f"!==t&&"l"!==t)return;const n=r[++l];if(!n||"switch"===n.kind)return;if("l"===t){if(!/^[1-9]$/.test(n.value))return;a=Number(n.value)}else{if(!/^[A-Za-z]$/.test(n.value))return;o=n.value}}return{text:n.value,level:a,...void 0===o?{}:{identifier:o},omitPageNumber:i}}function hI(e){const t=La(e);if(t.error||"TOC"!==t.command)return;const n=t.tokens.slice(1);let r,o,a,i,s,l,c,d,u,p,f,g,m,h,b=!1,y=!1,v=!1;const x=/* @__PURE__ */new Set;for(let I=0;I<n.length;I++){const e=n[I];if("switch"!==e.kind)return;const t=e.value.toLowerCase();if(x.has(t))return;if(x.add(t),"f"===t){const e=n[++I];if(!e||"switch"===e.kind||!/^[A-Za-z]$/.test(e.value))return;i=e.value.toUpperCase()}else if("l"===t){const e=n[++I];if(!e||"switch"===e.kind)return;const t=/^([1-9])-([1-9])$/.exec(e.value);if(!t||Number(t[1])>Number(t[2]))return;s=[Number(t[1]),Number(t[2])]}else if("o"===t){const e=n[++I];if("quoted"!==e?.kind)return;const t=/^([1-9])-([1-9])$/.exec(e.value);if(!t)return;if(r=Number(t[1]),o=Number(t[2]),r>o)return}else if("t"===t){const e=n[++I];if("quoted"!==e?.kind||e.value.length>4096||/[\r\n\t\\]/.test(e.value))return;const t=e.value.split(",").map(e=>e.trim());if(t.length<2||t.length%2||t.length>128)return;const r=/* @__PURE__ */new Set,o=[];for(let n=0;n<t.length;n+=2){const e=t[n],a=t[n+1],i=e.toLowerCase();if(!e||e.length>256||!/^[1-9]$/.test(a)||r.has(i))return;r.add(i),o.push({name:e,level:Number(a)})}a=o}else if("h"===t)b=!0;else if("z"===t)y=!0;else if("u"===t)v=!0;else if("c"===t||"a"===t||"b"===t||"s"===t){const e=n[++I];if(!e||"switch"===e.kind||!e.value||e.value.length>64||!/^[A-Za-z_][A-Za-z0-9_ ]*$/.test(e.value))return;if("c"===t){if(void 0!==l||void 0!==c)return;l=e.value}else if("a"===t){if(void 0!==l||void 0!==c)return;c=e.value}else if("b"===t){if(void 0!==d)return;d=e.value}else{if(void 0!==u)return;u=e.value}}else if("d"===t||"p"===t){const e=n[++I];if("quoted"!==e?.kind||!e.value||e.value.length>15||[...e.value.replace(/^\t$/,"")].some(e=>e.charCodeAt(0)<32||127===e.charCodeAt(0)))return;if("d"===t){if(void 0!==p)return;p=e.value}else{if(void 0!==f)return;f=e.value}}else if("n"===t){const e=n[++I];if(!e||"switch"===e.kind)return;const t=/^([1-9])-([1-9])$/.exec(e.value);if(!t||Number(t[1])>Number(t[2])||g)return;g=[Number(t[1]),Number(t[2])]}else if("w"===t)m=!0;else{if("x"!==t)return;h=!0}}if(void 0!==l||void 0!==c){if(void 0!==r||a||v||void 0!==i||s)return;return{startLevel:1,endLevel:9,hyperlinks:b,hideWebNumbers:y,useOutline:!1,...l?{captionIdentifier:l}:{},...c?{unlabeledIdentifier:c}:{},...d?{scopeBookmark:d}:{},...u?{chapterIdentifier:u}:{},...p?{chapterSeparator:p}:{},...f?{entryPageSeparator:f}:{},...g?{omitPages:g}:{},...m?{preserveTabs:m}:{},...h?{preserveLineBreaks:h}:{}}}if(void 0!==i&&void 0===r&&!a&&!v)return{startLevel:s?.[0]??1,endLevel:s?.[1]??9,hyperlinks:b,hideWebNumbers:y,useOutline:v,tcIdentifier:i};if(s&&void 0===i)return;const w=void 0===i?{}:{tcIdentifier:i,tcMixedRange:s??[1,9]};if(void 0===r||void 0===o){if(v&&!a)return{startLevel:1,endLevel:9,hyperlinks:b,hideWebNumbers:y,useOutline:v,...w};if(!a||v)return;return{startLevel:1,endLevel:Math.max(...a.map(e=>e.level)),hyperlinks:b,hideWebNumbers:y,useOutline:v,styleMappings:a,customOnly:!0,...w}}return{startLevel:r,endLevel:o,hyperlinks:b,hideWebNumbers:y,useOutline:v,...a?{styleMappings:a}:{},...w}}function bI(e){return!e.sdtWrappers?.length&&!e.numberingRevision&&!e.dropCap&&e.runs.every(e=>!(e.revision||e.revisionRangeMarker||e.sdtWrappers?.length||e.styles?.hidden||e.styles?.rtl))}function yI(e,t=!1){if(!bI(e)||e.list||e.dropCap||1!==e.runs.length)return!1;const n=e.runs[0];return"text"===n.kind&&n.text.length<=8192&&(n.text.includes("\t")||t&&n.text.length>0)&&!/[\r\n]/.test(n.text)}function vI(e){const t=[];for(let n=0;n<e.length;){if("paragraph"!==e[n]?.type){n++;continue}const r=n,o=[];for(;n<e.length&&"paragraph"===e[n]?.type;)o.push(e[n]),n++;const a=Ga(o);if(!a.diagnostics.length)for(const e of a.spans){if(null!==e.parentIndex||!e.separator||!e.end||e.beginMarker.fieldLock||e.beginMarker.dirty||e.code.some(e=>"instruction"!==e.kind)||e.begin.paragraphIndex!==e.separator.paragraphIndex||e.begin.paragraphIndex>=e.end.paragraphIndex)continue;const n=o[e.begin.paragraphIndex],a=o[e.end.paragraphIndex];if(!bI(n)||!bI(a)||0!==e.begin.runIndex||e.separator.runIndex!==n.runs.length-1||0!==e.end.runIndex||1!==a.runs.length||"fieldChar"!==n.runs[0]?.kind||"fieldChar"!==n.runs.at(-1)?.kind||"fieldChar"!==a.runs[0]?.kind)continue;const i=hI(e.code.map(e=>"instruction"===e.kind?e.raw:"").join(""));if(!i)continue;const s=e.begin.paragraphIndex,l=e.end.paragraphIndex;o.slice(s+1,l).every(e=>yI(e,void 0!==i.tcIdentifier))&&(e.result.length!==l-s-1||e.result.some((e,t)=>"run"!==e.kind||e.point.paragraphIndex!==s+t+1)||t.push({...i,startBlockIndex:r+s,endBlockIndex:r+l}))}}return 1===t.length?t[0]:void 0}function xI(e,t){const n=Y(e,t),r=Lo(e),o=/* @__PURE__ */new Map;return r.forEach((e,t)=>{for(const n of e.blocks)"paragraph"===n.type&&o.set(n.id,o.has(n.id)?null:t)}),(a,i)=>{if(i)return i.paragraphId===a?function(e,t,n,r=Y(e,t)){if(n.omitPageNumber)return"";const o=r.pageIndexAt(n.paragraphId,n.offset);if(void 0===o)return;const a=r.forPage(o);if(a.sectionNumber!==n.sectionIndex+1||void 0===a.pageNumber)return;const i=Lo(e)[n.sectionIndex];if(!i)return;const s=da(a.pageNumber,i.pageNumbering?.format);return void 0===s?void 0:String(s)}(e,t,i,n):void 0;const s=o.get(a);if(null==s)return;const l=r[s],c=n.pageIndexAt(a,0);if(void 0===c)return;const d=n.forPage(c);return d.sectionNumber===s+1&&void 0!==d.pageNumber?da(d.pageNumber,l.pageNumbering?.format):void 0}}var wI=e=>` TOC \\o "1-${e}" \\h \\z \\u `,II=e=>Math.round(e/Li*96);function SI(e,t,n=9){if(n<t.endLevel||t.styleMappings?.some(e=>e.level>n))return;if(void 0!==t.tcIdentifier){const r=Lo(e.document);if(r.some(e=>e.blocks.some(e=>"paragraph"!==e.type||e.runs.some(e=>"textBox"===e.kind||"opaque"===e.kind))))return;const o=function(e){const t=[],n=Lo(e),r=/* @__PURE__ */new Set;for(const[o,a]of n.entries()){for(const e of a.blocks){if(r.has(e.id))return;r.add(e.id)}for(let e=0;e<a.blocks.length;){if("paragraph"!==a.blocks[e]?.type){e++;continue}const n=[];for(;"paragraph"===a.blocks[e]?.type;)n.push(a.blocks[e++]);const r=Ga(n);if(r.diagnostics.length)return;for(const e of r.spans){const r=e.code.map(e=>"instruction"===e.kind?e.raw:"").join("");if("TC"!==La(r).command)continue;const a=mI(r);if(!a||null!==e.parentIndex||!e.end||e.separator||e.begin.paragraphIndex!==e.end.paragraphIndex||e.beginMarker.fieldLock||e.beginMarker.dirty||e.code.some(e=>"instruction"!==e.kind)||e.result.length)return;const i=n[e.begin.paragraphIndex],s=i.runs.slice(e.begin.runIndex,e.end.runIndex+1);if(i.sdtWrappers?.length||i.numberingRevision||i.dropCap||new Set(i.runs.map(e=>e.id)).size!==i.runs.length||s.some(e=>e.text.length||e.revision||e.revisionRangeMarker||e.sdtWrappers?.length||e.styles?.link||"fieldChar"!==e.kind&&"fieldInstruction"!==e.kind))return;if(t.push({...a,sectionIndex:o,paragraphId:i.id,runId:e.begin.runId,offset:e.begin.offset,raw:r}),t.length>2048)return}}}return t}(e.document);if(!o)return;if("C"===t.tcIdentifier&&o.some(e=>void 0===e.identifier))return;const[a,i]=t.tcMixedRange??[t.startLevel,t.endLevel];if(i>n)return;const s=o.filter(e=>e.identifier?.toUpperCase()===t.tcIdentifier&&e.level>=a&&e.level<=i).map(e=>({id:e.paragraphId,level:e.level,text:e.text,tc:e}));if(!t.tcMixedRange)return s;const{tcIdentifier:l,tcMixedRange:c,...d}=t,u=SI(e,d,n);if(!u)return;const p=/* @__PURE__ */new Map,f=/* @__PURE__ */new Set;for(const e of r){const t=vI(e.blocks);if(t)for(const n of e.blocks.slice(t.startBlockIndex,t.endBlockIndex+1))f.add(n.id);for(const n of e.blocks)p.set(n.id,p.size)}const g=new Set(o.map(e=>e.paragraphId));if(u.some(e=>g.has(e.id)||f.has(e.id)||!p.has(e.id))||s.some(e=>f.has(e.id)||!p.has(e.id)))return;return[...u,...s].sort((e,t)=>p.get(e.id)-p.get(t.id)||(e.tc?.offset??0)-(t.tc?.offset??0))}if(!t.styleMappings&&!t.useOutline)return function(e,t=3){const n=[];for(const r of ci(e.document)){const e=o(r.style?.styleId);if(null===e||e>t)continue;const a=mi(r).trim();a&&n.push({id:r.id,level:e,text:a})}return n}(e,t.endLevel).filter(e=>e.level>=t.startLevel);const r=t.useOutline?function(e){const t=e.styles,n=/* @__PURE__ */new Map;for(const o of Object.values(t??{}))n.set(o.id,n.has(o.id)?null:o);const r=e=>null===e||9===e?null:Number.isInteger(e)&&e>=0&&e<9?e+1:void 0,a=[...n.values()].filter(e=>"paragraph"===e?.type&&e.isDefault),i=1===a.length?a[0].id:bi(t);return e=>{if(void 0!==e.style?.outlineLevel)return r(e.style.outlineLevel);if(!e.style?.styleId&&a.length>1)return;let t=e.style?.styleId??i;const s=/* @__PURE__ */new Set;for(;t;){if(s.has(t)||s.size>=128)return;s.add(t);const e=n.get(t);if(null===e)return;if(!e){const e=o(t);return null!==e?e:/^(normal|caption)$/i.test(t)?null:void 0}if("paragraph"!==e.type)return;if(void 0!==e.paragraphStyle?.outlineLevel)return r(e.paragraphStyle.outlineLevel);const a=L(e)??We(e),i=o(a);if(null!==i)return i;t=e.basedOn}return null}}(e.document):void 0,a=Object.values(e.document.styles??{}),i=e=>e.trim().toLowerCase(),s=/* @__PURE__ */new Map;for(const{name:o,level:d}of t.styleMappings??[]){const e=i(o),t=a.filter(t=>i(t.id)===e||i(t.name)===e);if(1!==t.length||"paragraph"!==t[0].type)return;const n=t[0].id;if(s.has(n))return;s.set(n,d)}const l=/* @__PURE__ */new Set;for(const o of Lo(e.document)){const e=vI(o.blocks);if(e)for(const t of o.blocks.slice(e.startBlockIndex,e.endBlockIndex+1))l.add(t.id)}const c=[];for(const d of ci(e.document)){const e=d.style?.styleId,n=void 0===e?void 0:s.get(e),a=r?r(d):t.customOnly?null:o(e);if(void 0===a)return;const i=null!==a&&a>=t.startLevel&&a<=t.endLevel?a:void 0;if(void 0!==n&&void 0!==i&&n!==i)return;const u=n??i;if(void 0===u)continue;if(l.has(d.id))return;const p=mi(d).trim();p&&c.push({id:d.id,level:u,text:p})}return c}function CI(e){const t=wo(e.text).id;return e.fieldChar?{id:t,text:e.text,kind:"fieldChar",fieldChar:e.fieldChar}:void 0!==e.fieldInstruction?{id:t,text:e.text,kind:"fieldInstruction",fieldInstruction:e.fieldInstruction}:{id:t,text:e.text,kind:"text"}}function kI(e,t){const n=Go("");return n.runs=e,t&&(n.style=t),n}function TI(e,t){return e.tc?.omitPageNumber?e.text:e.text+"\t"+(t??"")}function PI(e,t,n){return kI([CI({text:TI(e,t)})],{...e.tc?.omitPageNumber?{}:{tabs:[{position:n,type:"right",leader:"dot"}]},spacingAfter:II(40),indentLeft:II(397*(e.level-1))})}function RI(e){const{width:t,margins:n}=e.pageSettings,r=Math.max(0,t-n.left-n.right);return Zt(r*go,2)}function AI(e){return kI([CI({text:"",fieldChar:{kind:"begin"}}),CI({text:"",fieldInstruction:wI(e)}),CI({text:"",fieldChar:{kind:"separate"}})])}function MI(e,t,n,r){const o=Lo(e.document),a=o[t];if(!a)return e;const i=[...o];return i[t]={...a,blocks:n},{...e,document:{...e.document,sections:i},selection:J(xi(r,0))}}function OI(e,t=()=>{},n=3){if("main"!==jr(e)||!Number.isInteger(n)||n<1||n>9)return e;const r=Ua(e),o=Lo(e.document)[r];if(!o)return e;const a=SI(e,{startLevel:1,endLevel:n,hyperlinks:!0,hideWebNumbers:!0,useOutline:!0},n);if(!a)return e;const i=function(e,t,n,r){const o=e.map(e=>{const r=t(e.id);return PI(e,void 0!==r&&ri(r)?r:void 0,n)});return[AI(r),...o,kI([CI({text:"",fieldChar:{kind:"end"}})])]}(a,t,RI(o),n),s=Ra(e,e.selection.focus),l=o.blocks.findIndex(e=>e.id===s.paragraphId||"paragraph"!==e.type&&ra(e).some(e=>e.id===s.paragraphId)),c=-1===l?o.blocks.length:l+1;return MI(e,r,[...o.blocks.slice(0,c),...i,...o.blocks.slice(c)],i[0])}var BI=vI;function FI(e,t=()=>{},n=9){if("main"!==jr(e)||!Number.isInteger(n)||n<1||n>9)return e;const r=Ua(e),o=Lo(e.document)[r];if(!o)return e;const a=BI(o.blocks);if(!a||n<a.endLevel)return e;const i=SI(e,a,n);if(!i)return e;const s=new Map(ci(e.document).map(e=>[e.id,e]));if(i.some(e=>{const t=s.get(e.id);return e.tc?!t:!t||t.sdtWrappers?.length||t.numberingRevision||t.dropCap||t.runs.some(e=>"text"!==e.kind||e.revision||e.revisionRangeMarker||e.sdtWrappers?.length||e.styles?.hidden||e.styles?.rtl)||e.text.length>4096||/[\r\n\t]/.test(e.text)}))return e;const l=o.blocks.slice(a.startBlockIndex+1,a.endBlockIndex),c=i.map(e=>e.tc?.omitPageNumber?"":t(e.id,e.tc));if(c.some((e,t)=>!i[t].tc?.omitPageNumber&&(void 0!==e&&!ri(e)||void 0===e&&(!!i[t].tc||!!a.tcMixedRange))))return e;if(c.some(e=>void 0===e)&&l.some(e=>"paragraph"===e.type&&/\t\S/.test(mi(e))))return e;const d=i.map((e,t)=>PI(e,c[t],RI(o)));if(l.length===d.length&&l.every((e,t)=>"paragraph"===e.type&&mi(e)===mi(d[t])))return e;if(l.some(e=>"paragraph"===e.type&&e.runs.some(e=>e.styles?.link)))return e;if(void 0!==a.tcIdentifier){const t=new Set(l.map(e=>e.id));if(e.trackChangesEnabled||t.has(e.selection.anchor.paragraphId)||t.has(e.selection.focus.paragraphId)||[...Object.values(e.document.bookmarks?.items??{}),...Object.values(e.document.comments?.items??{})].some(e=>[e.start,e.end].some(e=>e&&t.has(e.paragraphId))))return e}return MI(e,r,[...o.blocks.slice(0,a.startBlockIndex+1),...d,...o.blocks.slice(a.endBlockIndex)],d[0]??o.blocks[a.startBlockIndex])}var EI=e=>e.map(e=>"instruction"===e.kind?e.raw??"":"").join(""),DI=e=>["text","fieldChar","fieldInstruction"].includes(e.kind)&&!e.revision&&!e.revisionRangeMarker&&!e.sdtWrappers?.length&&!e.styles?.hidden&&!e.styles?.rtl,LI=e=>!e.numberingRevision&&!e.dropCap&&!e.list&&!e.style?.bidi&&(!e.style?.textDirection||"lrTb"===e.style.textDirection)&&e.runs.every(DI)&&new Set(e.runs.map(e=>e.id)).size===e.runs.length,NI="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function zI(e){const t=e.sdtPr;return!!e.groupId&&(!t.lock||"unlocked"===t.lock||"sdtLocked"===t.lock)&&!t.dataBinding&&!t.temporary&&!t.showingPlcHdr&&!t.repeatingSectionProperties&&!t.subtype&&function(e){if(!e||e.length>8192||/<!|<\?/.test(e))return!1;try{const t=(new _i.DOMParser).parseFromString('<root xmlns:w="'+NI+'">'+e+"</root>","application/xml").documentElement;if(!t||"root"!==t.localName)return!1;const n=e=>{const t=[];for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes.item(n);if(1===r?.nodeType)t.push(r);else if(3!==r?.nodeType||r.nodeValue?.trim())return}return t},r=n(t);if(1!==r?.length||r[0].namespaceURI!==NI||"docPartObj"!==r[0].localName)return!1;const o=n(r[0]);if(!o||o.length<1||o.length>3)return!1;const a=/* @__PURE__ */new Set;for(const e of o){const t=e.localName;if(e.namespaceURI!==NI||!t||a.has(t)||!["docPartGallery","docPartCategory","docPartUnique"].includes(t)||0!==n(e)?.length)return!1;a.add(t);const r=e.getAttributeNS(NI,"val");if("docPartGallery"===t&&"Table of Contents"!==r)return!1;if("docPartCategory"===t&&!r)return!1;if("docPartUnique"===t&&r&&!["1","0","true","false","on","off"].includes(r))return!1}return a.has("docPartGallery")}catch{return!1}}(t.unknownXml??"")}function $I(e){const t=e[0]?.sdtWrappers??[];if(!t.length)return e.every(e=>!e.sdtWrappers?.length);if(1!==t.length||!zI(t[0]))return!1;const n=JSON.stringify(t);return e.every(e=>JSON.stringify(e.sdtWrappers??[])===n)}function HI(e,t=Ua(e),n=!1){if(!n&&("main"!==jr(e)||e.trackChangesEnabled))return;const r=Lo(e.document)[t];if(!r)return;const o=[];let a=0;for(let i=0;i<r.blocks.length;){if("paragraph"!==r.blocks[i]?.type){i++;continue}const e=[];for(;"paragraph"===r.blocks[i]?.type;)e.push(r.blocks[i++]);const t=Ga(e);if(t.diagnostics.length)return;for(const n of t.spans){const r=EI(n.code);if("TOC"!==La(r).command)continue;a++;const i=hI(r);if(!i||void 0!==i.tcIdentifier||null!==n.parentIndex||!n.separator||!n.end||n.beginMarker.fieldLock||n.beginMarker.dirty||n.code.some(e=>"instruction"!==e.kind)||n.begin.paragraphIndex!==n.separator.paragraphIndex||0!==n.begin.runIndex||n.end.runIndex!==e[n.end.paragraphIndex].runs.length-1)continue;const s=n.begin.paragraphIndex,l=n.end.paragraphIndex,c=e.slice(s,l+1);if(c.length>2050||!c.every(LI)||!$I(c)||new Set(c.map(e=>e.id)).size!==c.length)continue;const d=[],u=/* @__PURE__ */new Set;let p=!0;for(let o=s;o<=l;o++){const r=e[o],a=o===s?n.separator.runIndex+1:0,i=o===l?n.end.runIndex:r.runs.length;if(a===i&&(o===s||o===l))continue;const c=t.spans.filter(e=>e.parentIndex===n.index&&e.begin.paragraphIndex===o);if(1!==c.length){p=!1;break}const f=c[0];if(!f.separator||!f.end||f.beginMarker.fieldLock||f.beginMarker.dirty||f.end.paragraphIndex!==o||f.separator.paragraphIndex!==o||f.begin.runIndex<=a||f.end.runIndex!==i-1||f.code.some(e=>"instruction"!==e.kind)||!f.result.length||f.result.length>128||f.result.some(e=>"run"!==e.kind)){p=!1;break}const g=Ma(EI(f.code));if("PAGEREF"!==g?.type){p=!1;break}const m=r.runs.slice(a,f.begin.runIndex),h=m.map(e=>e.text).join(""),b=r.runs.slice(f.separator.runIndex+1,f.end.runIndex),y=b.map(e=>e.text).join("");if(b.length!==f.result.length||b.some((e,t)=>{const n=f.result[t];return"text"!==e.kind||!e.text.length||"run"!==n?.kind||n.point.paragraphIndex!==o||n.point.runIndex!==f.separator.runIndex+1+t})||!y.length||y.length>128||/[\r\n\t]/.test(y)||b.length>1&&!/^(?:[0-9]+|[A-Za-z]+)$/.test(y)||h.length>8192||!h.endsWith("\t")||!h.slice(0,-1).trim()||/[\r\n]/.test(h)||!m.every(e=>"text"===e.kind)||[...m,...b].some(e=>e.styles?.link&&e.styles.link!=="#"+g.bookmark)){p=!1;break}u.add(f.index),d.push({paragraphId:r.id,runIds:b.map(e=>e.id),bookmark:g.bookmark})}!p||!d.length||d.length>2048||n.result.some(e=>"nested"===e.kind&&!u.has(e.fieldIndex))||t.spans.some(e=>e.parentIndex===n.index&&!u.has(e.index))||o.push({entries:d,paragraphIds:new Set(c.map(e=>e.id)),hyperlinks:i.hyperlinks})}}return 1===a&&1===o.length?o[0]:void 0}function WI(e){return!!HI(e)}function jI(e,t,n){const r=Lo(e),o=/* @__PURE__ */new Map;r.forEach((e,t)=>e.blocks.forEach(e=>{"paragraph"===e.type&&o.set(e.id,o.has(e.id)?null:{p:e,section:t})}));const a=e.bookmarks,i=/* @__PURE__ */new Map;for(const l of Object.values(a?.items??{})){const e=l.name.toLowerCase();i.set(e,i.has(e)?null:l)}const s=Y(e,t);return n.entries.map(e=>{const t=i.get(e.bookmark.toLowerCase());if(!t||t.name!==e.bookmark||!a?.order.includes(t.id)||!t.start||!t.end||void 0!==t.colFirst||void 0!==t.colLast||t.start.paragraphId!==t.end.paragraphId||n.paragraphIds.has(t.start.paragraphId))return;const l=o.get(t.start.paragraphId);if(!l||!Number.isInteger(t.start.offset)||!Number.isInteger(t.end.offset)||t.start.offset<0||t.end.offset<t.start.offset||t.end.offset>oi(l.p))return;const c=s.pageIndexAt(l.p.id,t.start.offset);if(void 0===c)return;const d=s.forPage(c);if(d.sectionNumber!==l.section+1||void 0===d.pageNumber)return;const u=da(d.pageNumber,r[l.section].pageNumbering?.format);return void 0===u?void 0:String(u)})}function UI(e,t){if(e.length<t.length)return;let n=0;return t.map((r,o)=>{const a=o===t.length-1?e.length-n:Math.min(r,e.length-n-(t.length-o-1)),i=e.slice(n,n+a);return n+=a,i})}function VI(e,t,n){if(!Number.isInteger(n)||n<0)return;const r=Lo(e.document),o=r.flatMap((e,n)=>e.blocks.filter(e=>e.id===t&&"paragraph"===e.type).map(e=>({p:e,i:n})));if(1!==o.length)return;const{p:a,i:i}=o[0];if("paragraph"!==a.type||n>oi(a))return;const s=r[i].blocks,l=vI(s);let c,d,u;if(l?.hyperlinks&&s.slice(l.startBlockIndex+1,l.endBlockIndex).some(e=>e.id===t)){const n=a.runs[0]?.styles?.link;if(!n?.startsWith("#")||n.length<2)return;if(c=n.slice(1),void 0!==l.tcIdentifier){const n=SI(e,l),r=s.slice(l.startBlockIndex+1,l.endBlockIndex),o=n?.[r.findIndex(e=>e.id===t)];if(!o||n?.length!==r.length)return;const i=mi(a);if(o.tc?.omitPageNumber?i!==o.text:!i.startsWith(o.text+"\t"))return;u=o}d=new Set(s.slice(l.startBlockIndex,l.endBlockIndex+1).map(e=>e.id))}else{const r=function(e,t,n,r){const o=HI(e,t,!0);if(!o?.hyperlinks)return;const a=o.entries.find(e=>e.paragraphId===n),i=Lo(e.document)[t]?.blocks.find(e=>e.id===n);if(!a||!i||"paragraph"!==i.type||!Number.isInteger(r)||r<0||r>oi(i))return;const s=a.bookmark;let l=0;for(const c of i.runs){const e=l+c.text.length;if(c.text.length>0&&r>=l&&(r<e||r===e&&e===oi(i)))return"text"===c.kind&&c.styles?.link==="#"+s?{name:s,excluded:o.paragraphIds}:void 0;l=e}}(e,i,t,n);if(!r)return;({name:c,excluded:d}=r)}const p=e.document.bookmarks;if(!p)return;const f=Object.values(p.items).filter(e=>e.name.toLowerCase()===c.toLowerCase());if(1!==f.length)return;const g=f[0];if(g.name!==c||!g.start||!g.end||!p.order.includes(g.id)||g.start.paragraphId!==g.end.paragraphId||d.has(g.start.paragraphId)||void 0!==g.colFirst||void 0!==g.colLast)return;if(u&&(!g.hidden||g.start.paragraphId!==u.id||g.start.offset!==(u.tc?.offset??0)))return;if(u?.tc&&g.end.offset!==u.tc.offset)return;const m=r.flatMap((e,t)=>e.blocks.filter(e=>e.id===g.start.paragraphId&&"paragraph"===e.type).map(e=>({p:e,i:t})));if(1!==m.length)return;const{p:h,i:b}=m[0];if("paragraph"!==h.type||!Number.isInteger(g.start.offset)||!Number.isInteger(g.end.offset)||g.start.offset<0||g.end.offset<g.start.offset||g.end.offset>oi(h))return;if(u&&!u.tc&&g.end.offset!==oi(h))return;const y=xi(h,g.start.offset);return{...e,activeZone:"main",activeFootnoteId:void 0,activeSectionIndex:b,selection:{anchor:y,focus:y}}}var KI=e=>"touch"===e.pointerType;function _I(e,t){if(!e||0===e.length){const e=No(t);return{paragraph:e,blocks:[e]}}const n=e[0];return{paragraph:"paragraph"===n.type?n:ra(n)[0]??null,blocks:e}}function XI(e,t,n){const r=ci(e.document).filter(t=>{const r=qo(e.document,t.id);return null!==r&&r.zone===n}),o=r.findIndex(e=>e.id===t.id),a=o>=0?r[o+1]:void 0;return{start:xi(t,0),end:a?xi(a,0):xi(t,mi(t).length)}}function qI(e){return function(e){let t=null,n=null,r=null,o=0,a=0,i=0,s=0,l=0,c=null,d=0,u=0,p=0,f=null,g=null;const m=e=>"undefined"!=typeof window&&"function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(()=>e()):globalThis.setTimeout(e,16),h=e=>{"undefined"==typeof window||"function"!=typeof window.cancelAnimationFrame?globalThis.clearTimeout(e):window.cancelAnimationFrame(e)},b=(t,n,r,o)=>{const a=n!==(t.activeZone??"main"),i="footnote"===n&&o?qo(r.document,o.paragraphId)?.footnoteId:void 0,s="footnote"===n&&i!==t.activeFootnoteId;if(!a&&!s)return void e.applyState(r);let l=r.document,c=t.activeSectionIndex??0;if(!l.sections||0===l.sections.length){const e=No("header"),t=No("footer");l={...l,sections:[{id:"section:1",blocks:[],pageSettings:Bi(l.pageSettings??ka),header:[e],footer:[t]}]},c=0}const d=l.sections,u=d[c];let p=u.header,f=u.footer,g=null;if("header"===n){const e=_I(p,"header");g=e.paragraph,p=e.blocks}else if("footer"===n){const e=_I(f,"footer");g=e.paragraph,f=e.blocks}if(p!==u.header||f!==u.footer){const e=[...d];e[c]={...u,header:p,footer:f},l={...l,sections:e}}const m=o||(g?xi(g,0):r.selection.anchor);e.applyState({...r,document:l,selection:{anchor:m,focus:m},activeSectionIndex:c,activeZone:n,activeFootnoteId:"footnote"===n?i:void 0})},y=t=>{const n=e.state(),r=n.selection,o=Ua(n),a=io(n.document,r.anchor.paragraphId,o),i=io(n.document,r.focus.paragraphId,o),s=a?`b${a.blockIndex}r${a.rowIndex}c${a.cellIndex}`:"",l=i?`b${i.blockIndex}r${i.rowIndex}c${i.cellIndex}`:"";e.logger.debug(`${t} ${r.anchor.paragraphId}[${r.anchor.offset}]→${r.focus.paragraphId}[${r.focus.offset}] [${s}→${l}]`)},v=()=>{g?.longPressHandle&&clearTimeout(g.longPressHandle),g=null},x=()=>{t=null,r=null,f=null,v(),null!==n&&(h(n),n=null),window.removeEventListener("pointermove",C),window.removeEventListener("pointerup",k),window.removeEventListener("pointercancel",T)},w=e=>{f=e,window.addEventListener("pointermove",C),window.addEventListener("pointerup",k),window.addEventListener("pointercancel",T)},I=()=>{if(n=null,!t)return;const o=r;if(r=null,!o)return;const a=e.resolveSurfaceHitAtPoint(o.clientX,o.clientY,{forDrag:!0});if(!a?.resolvedFromParagraph)return;const i=e.state();if(qo(i.document,t.paragraphId)?.sectionIndex!==qo(i.document,a.paragraphId)?.sectionIndex)return;const s=ji(i,{anchor:t,focus:a.position});b(i,a.zone,s,a.position),y("selection:drag")},S=()=>{r&&(null!==n&&(h(n),n=null),I())},C=e=>{null!==f&&e.pointerId!==f||(!g||g.longPressFired?t&&(r={clientX:e.clientX,clientY:e.clientY},null===n&&(n=m(I))):Math.hypot(e.clientX-g.clientX,e.clientY-g.clientY)>20&&x())},k=t=>{if(null===f||t.pointerId===f){if(g&&!g.longPressFired){const n=g,r=Math.hypot(t.clientX-n.clientX,t.clientY-n.clientY)<=20&&Date.now()-n.startedAt<=500;return v(),x(),void(r&&(E(n.hit,n.clickDetail,t),e.onSelectionFinalized?.()))}S(),y("selection:end"),x(),e.onSelectionFinalized?.(),e.focusInputAfterPointerSelection()}},T=e=>{null!==f&&e.pointerId!==f||x()},P=(n,r,o)=>{if(o<2)return t=null,x(),void e.focusInputAfterPointerSelection();t=null,r.resolvedFromParagraph?b(n,r.zone,{...n,selection:{anchor:{...r.position},focus:{...r.position}}},r.position):b(n,r.zone,n),x(),e.focusInputAfterPointerSelection()},R=(n,r)=>{const o=e.getParagraphById(n.document,r.textBox.paragraphId);if(!o)return void e.focusInputAfterPointerSelection();t=null;const a=xi(o,r.textBox.startOffset),i=xi(o,r.textBox.endOffset);b(n,r.zone,ji(n,{anchor:a,focus:i}),a),x(),e.focusInputAfterPointerSelection()},A=(n,r,o)=>{const a=e.getParagraphById(n.document,r.image.paragraphId);if(!a)return void e.focusInputAfterPointerSelection();t=null;const i=xi(a,r.image.startOffset),s=xi(a,r.image.endOffset);b(n,r.zone,ji(n,{anchor:i,focus:s}),i),x(),KI(o)||e.imageOps.startImageDrag(r.image.paragraphId,r.image.startOffset,o,{left:r.image.left,top:r.image.top,width:r.image.width,height:r.image.height}),e.focusInputAfterPointerSelection()},M=(n,r,o)=>{t=n.selection.anchor,b(n,r.zone,ji(n,{anchor:n.selection.anchor,focus:r.position}),r.position),w(o),e.focusInputAfterPointerSelection()},O=(n,r,o)=>{t=null;const a=XI(n,o,r.zone);b(n,r.zone,ji(n,{anchor:a.start,focus:a.end}),a.start),x(),e.focusInputAfterPointerSelection()},B=(n,r,o)=>{t=null;let a=0;const i=o.runs.find(e=>{const t="math"===e.kind&&r.paragraphOffset>=a&&r.paragraphOffset<=a+e.text.length;return a+=e.text.length,t});if("math"===i?.kind){const t=xi(o,r.paragraphOffset);return b(n,r.zone,ji(n,{anchor:t,focus:t}),t),x(),void e.openEquationDialog(i.math,i.id)}const s=St(mi(o),r.paragraphOffset),l=xi(o,s.start),c=xi(o,s.end);b(n,r.zone,ji(n,{anchor:l,focus:c}),l),x(),e.focusInputAfterPointerSelection()},F=(n,r,a,i)=>{if(e.imageOps.stopImageDrag(),e.imageOps.stopImageResize(),e.clearPreferredColumn(),e.resetTransactionGrouping(),!r)return void e.focusInputAfterPointerSelection();if(!KI(i)&&(i.ctrlKey||i.metaKey)&&!i.altKey&&!i.shiftKey&&"main"===r.zone&&r.resolvedFromParagraph&&r.insideTextLine&&!r.image&&!r.textBox){const t=VI(n,r.paragraphId,r.paragraphOffset);if(t)return x(),o=0,e.applyState(t),e.focusInputAfterPointerSelection(),void e.scrollToLinkedParagraph?.(t.selection.focus.paragraphId)}if(!KI(i)&&e.textDrag?.tryStartTextDrag(i,r))return t=null,x(),void e.focusInputAfterPointerSelection();const s=e.getParagraphById(n.document,r.paragraphId);r.zone===(n.activeZone??"main")?r.textBox?R(n,r):r.image?A(n,r,i):i.shiftKey&&r.resolvedFromParagraph?M(n,r,i.pointerId):a>=3&&s?O(n,r,s):2===a&&s?B(n,r,s):r.resolvedFromParagraph?(t=r.position,b(n,r.zone,{...n,selection:{anchor:{...r.position},focus:{...r.position}}},r.position),KI(i)||w(i.pointerId),e.focusInputAfterPointerSelection()):e.focusInputAfterPointerSelection():P(n,r,a)},E=(t,n,r)=>{F(e.state(),t,n,r),e.focusInputSync()},D=()=>{const n=g;if(!n)return;n.longPressHandle=null,n.longPressFired=!0;const r=n.hit;if(!r?.resolvedFromParagraph)return;const o=e.state(),a=e.getParagraphById(o.document,r.paragraphId);if(!a)return;const i=St(mi(a),r.paragraphOffset),s=xi(a,i.start),l=xi(a,i.end);b(o,r.zone,ji(o,{anchor:s,focus:l}),s),t=s,e.focusInputSync()},L=t=>{if(0!==t.button)return;const n=Date.now(),r=Math.hypot(t.clientX-i,t.clientY-s);o=n-a<=450&&r<=((e,t)=>KI(e)?20:t)(t,6)&&t.button===l?o+1:1,a=n,i=t.clientX,s=t.clientY,l=t.button;const f=Math.max(t.detail,o),m=e.state();if(e.clearPendingCaretTextStyle(),e.tableResize.handlePointerDown(t))return void t.preventDefault();const h=e.resolveSurfaceHitAtPoint(t.clientX,t.clientY,{pierce:t.altKey});if(c=h,d=n,u=t.clientX,p=t.clientY,KI(t))return v(),g={pointerId:t.pointerId,clientX:t.clientX,clientY:t.clientY,startedAt:n,hit:h,clickDetail:f,longPressHandle:setTimeout(D,500),longPressFired:!1},void w(t.pointerId);t.preventDefault(),F(m,h,f,t)},N=n=>{if(n.ctrlKey||n.metaKey||n.detail<3)return;n.preventDefault();const r=e.state(),o=Math.hypot(n.clientX-u,n.clientY-p),a=Date.now()-d<=600&&o<=8?c:e.resolveSurfaceHitAtPoint(n.clientX,n.clientY);if(!a?.resolvedFromParagraph)return void e.focusInputAfterPointerSelection();const i=e.getParagraphById(r.document,a.paragraphId);if(!i)return void e.focusInputAfterPointerSelection();t=null;const s=XI(r,i,a.zone);b(r,a.zone,ji(r,{anchor:s.start,focus:s.end}),s.start),x(),e.focusInputAfterPointerSelection()},z=(e,t)=>{0===t.button&&(KI(t)||t.preventDefault(),L(t))};return{handleSurfacePointerDown:L,handleSurfaceClick:N,handleSurfaceDblClick:e=>{e.preventDefault()},handleParagraphPointerDown:z,stopDragging:x}}(e)}function GI(e){return function(e){const[t,n]=Nt(!1);let r,o=0,a="",i=null;const s=()=>{o=0,a="",r=void 0},l=(t,n)=>{if(!n&&t===a)return;if(0===o&&0===t.length)return void(n&&s());const l=o,c=Na(r);e.clearPreferredColumn(),e.applyTransactionalState(n=>e.applyTableAwareParagraphEdit(n,e=>{const n=function(e,t){if(Po(e))return e;if(t<=0)return e;const{paragraph:n,index:r,offset:o}=ae(e);if(o<t)return e;const a=ko(e),i=o-t;if(Un(e,n,i,o))return e;const s=Dr(e,"",{range:[i,o]});if(s)return s;const l=N(n,cr(n)?Jn(n,i,o,()=>null):[...Ln(n,0,i),...Ln(n,o,oi(n))],gt(n,i)),c=a.map((e,t)=>t===r?l:e);return Vt(e,c,J(xi(l,i)))}(e,l);return t.length>0?Ju(n,t,c):n}),{mergeKey:Jp}),n?(s(),i=t.length>0?t:null):(o=t.length,a=t)},c=n=>{if(lr("input:text"),e.isReadOnly())return e.logger.debug(`input:readonly ignored value=${JSON.stringify(n.currentTarget.value)}`),n.currentTarget.value="",void s();const r=n.currentTarget.value;if(0===r.length)return;if(t())return e.logger.debug(`input:composing buffer=${JSON.stringify(r)}`),void l(r,!1);if(null!==i){const t=r===i;if(i=null,t)return e.logger.debug(`input:suppressed text=${JSON.stringify(r)}`),void(n.currentTarget.value="")}const o=e.state(),a=o.selection,c=ko(o).find(e=>e.id===a.anchor.paragraphId)?.runs.find(e=>e.id===a.anchor.runId),d=c?{bold:c.styles?.bold,italic:c.styles?.italic,underline:c.styles?.underline}:null;e.logger.info(`input:text ${JSON.stringify(r)} (len=${r.length}) at ${a.anchor.paragraphId}:${a.anchor.runId}[${a.anchor.offset}] run:${JSON.stringify(d)}`),e.clearPreferredColumn();const u=Na(e.pendingCaretTextStyle());e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>Ju(e,r,u)),{mergeKey:Zp}),n.currentTarget.value="",e.focusInput(),Et("input:text")},d=()=>{e.logger.debug("input:composition start"),s(),i=null,r=Na(e.pendingCaretTextStyle()),n(!0)},u=t=>{e.isReadOnly()||l(t.data??"",!1)},p=t=>{if(n(!1),e.isReadOnly())return t.currentTarget.value="",void s();const r=t.data??t.currentTarget.value,o=e.state().selection;e.logger.info(`input:composition end ${JSON.stringify(r)} (len=${r.length}) at ${o.anchor.paragraphId}:${o.anchor.runId}[${o.anchor.offset}]`),l(r,!0),t.currentTarget.value="",e.focusInput()};return{handleTextInput:c,handleCompositionStart:d,handleCompositionUpdate:u,handleCompositionEnd:p,composing:t}}(e)}var YI="url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cg fill='none' stroke-linejoin='round' stroke-linecap='round'%3E%3Cpath d='M6 3.5 6 22.5 10.7 17.9 14.1 26.6 17.2 25.4 13.8 16.9 20.4 16.9Z' fill='white' stroke='white' stroke-width='4'/%3E%3Cpath d='M6 3.5 6 22.5 10.7 17.9 14.1 26.6 17.2 25.4 13.8 16.9 20.4 16.9Z' fill='white' stroke='black' stroke-width='1.4'/%3E%3Cpath d='M7.5 7.1 7.5 19.1 10.9 15.8 14.7 24.4' stroke='white' stroke-width='1.15' opacity='.95'/%3E%3Crect x='22' y='23' width='8.5' height='6.5' rx='.5' fill='white' stroke='white' stroke-width='3'/%3E%3Crect x='22' y='23' width='8.5' height='6.5' rx='.5' stroke='black' stroke-width='1.25' stroke-dasharray='2 2'/%3E%3C/g%3E%3C/svg%3E\") 6 4, auto";function ZI(e,t){const n=Ri(e);if(n.isCollapsed)return!1;const r=ko(e),o=r.findIndex(e=>e.id===t.paragraphId);if(o<n.startIndex||o>n.endIndex)return!1;const a=r[o];if(!a)return!1;const i=wa(a,t);return!(o===n.startIndex&&i<n.startParagraphOffset)&&!(o===n.endIndex&&i>n.endParagraphOffset)}function JI(e,t,n,r,o,a){if(n.zone===jr(e))return o(e,e=>Zu(e,t,{copy:r}));if(r||n.tableCellAnchorPosition||!["main","header","footer"].includes(n.zone))return e;if("main"!==n.zone&&"header"!==n.zone&&"footer"!==n.zone)return e;try{return function(e,t){const n=e.document.sourcePackage,r=jr(e);if(!n||1!==e.document.sections?.length||e.trackChangesEnabled||e.document.opaqueRelocationIntent||e.document.opaqueDeletionIntents?.length)throw Error("Relocation requires a single-section source-backed document without pending opaque edits or tracked changes");if("main"!==r&&"header"!==r&&"footer"!==r)throw Error("Unsupported source zone");if(r===t.zone||"main"!==r&&e.activeHeaderFooterStory&&"default"!==e.activeHeaderFooterStory)throw Error("Only distinct default stories are supported");if(e.document.bookmarks?.order.length||e.document.comments?.order.length)throw Error("Cross-story anchors are not supported");const o=Ki(e,e=>"opaque"===e.kind);if(!o||"opaque"!==o.run.kind||"inline"!==o.run.opaque.placement||o.run.revision||o.run.sdtWrappers?.length)throw Error("Select exactly one unwrapped inline opaque object");const a=vi(n,r),i=vi(n,t.zone),s=o.run.opaque.signature,l=(n.opaqueObjects??[]).filter(e=>e.signature===s),c=1===l.length?l[0]:void 0;if(!c||c.ownerPath!==a)throw Error("Ambiguous source identity");const d=_a(n,c,i),p=e.document.sections[0],f="main"===r?p.blocks:p[r],g="main"===t.zone?p.blocks:p[t.zone];if(!f?.some(e=>"paragraph"===e.type&&e.id===o.paragraph.id)||!g?.some(e=>"paragraph"===e.type&&e.id===t.paragraphId))throw Error("Only top-level paragraphs of existing stories are supported");const m={...e,activeSectionIndex:0,activeZone:t.zone,activeHeaderFooterStory:"default"},h=ko(m).find(e=>e.id===t.paragraphId);if(!h||!Number.isInteger(t.offset)||t.offset<0||t.offset>oi(h))throw Error("Invalid destination offset");const b={...te(e),activeZone:t.zone,activeSectionIndex:0,activeHeaderFooterStory:"default"},y=ko(b),v=y.find(e=>e.id===t.paragraphId);if(!v)throw Error("Destination unavailable after deletion");const x=na(o.run);if("opaque"!==x.kind)throw Error("Invalid cloned object");const w=u(v,t.offset,[{...x,opaque:d.destinationRun}]),I=Vt(b,y.map(e=>e.id===w.id?w:e),{anchor:xi(w,t.offset),focus:xi(w,t.offset+1)});return{...I,document:{...I.document,opaqueRelocationIntent:{ownerPath:c.ownerPath,ordinal:c.ordinal,signature:c.signature,destinationOwner:i}}}}(e,{zone:n.zone,paragraphId:n.paragraphId,offset:n.paragraphOffset})}catch(i){return a?.(i),e}}function QI(e){return function(e){const[t,n]=Nt(!1),[r,o]=Nt(null),[a,i]=Nt(!1),[s,l]=Nt(null),[c,d]=Nt(null);let u=null,p=null,f=null,g=null;const m=()=>{p&&(p.remove(),p=null)},h=()=>{p||(p=document.createElement("style"),p.setAttribute("data-oasis-text-drag-cursor",""),p.textContent=`*, *::before, *::after { cursor: ${YI} !important; }`,document.head.appendChild(p))},b=mw(),y=()=>{e.logger?.info("text-drag:stop",{dragging:t(),dropTarget:r()?`${r().paragraphId}:${r().runId}[${r().offset}]`:null,copyMode:a()}),u=null,f=null,g=null,n(!1),o(null),i(!1),l(null),d(null),m(),b.release(),window.removeEventListener("pointermove",v),window.removeEventListener("pointerup",x),window.removeEventListener("pointercancel",x)},v=r=>{if(!b.owns(r))return;if(!u)return;const a=r.ctrlKey||r.metaKey;if(i(a),!t()){const t=Math.abs(r.clientX-u.x),o=Math.abs(r.clientY-u.y);if(t+o<4)return;e.logger?.info("text-drag:activate",{start:u,at:{x:r.clientX,y:r.clientY},deltaX:t,deltaY:o}),n(!0),h()}l({x:r.clientX,y:r.clientY});const s=e.resolveSurfaceHitAtPoint(r.clientX,r.clientY,{forDrag:!0});if(g=s?.resolvedFromParagraph?s:null,!s?.resolvedFromParagraph)return e.logger?.debug("text-drag:hit-miss",{x:r.clientX,y:r.clientY}),o(null),void d(null);const c=s.tableCellAnchorPosition??s.position,p=`${c.paragraphId}:${c.runId}[${c.offset}]|${s.zone}|src=${s.tableCellAnchorPosition?"cell-anchor":"hit"}`;p!==f&&(e.logger?.info("text-drag:target",{x:r.clientX,y:r.clientY,zone:s.zone,resolvedFromParagraph:s.resolvedFromParagraph,paragraphId:s.paragraphId,paragraphOffset:s.paragraphOffset,hitPosition:`${s.position.paragraphId}:${s.position.runId}[${s.position.offset}]`,target:`${c.paragraphId}:${c.runId}[${c.offset}]`,source:s.tableCellAnchorPosition?"tableCellAnchorPosition":"position"}),f=p),o(c),d(s.caretViewport??null)},x=n=>{if(b.owns(n))if(e.logger?.info("text-drag:mouseup",{x:n.clientX,y:n.clientY,dragging:t(),copyMode:a(),dropTarget:r()?`${r().paragraphId}:${r().runId}[${r().offset}]`:null}),"pointercancel"!==n.type){if(t()&&r()&&g){const t=r(),o=n.ctrlKey||n.metaKey,a=g;e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(n=>JI(n,t,a,o,e.applyTableAwareParagraphEdit,t=>e.logger?.warn?.("text-drag:relocation-rejected",t)),{mergeKey:o?Sf:Cf}),e.logger?.info("text-drag:apply",{mode:o?"copy":"move",destination:`${t.paragraphId}:${t.runId}[${t.offset}]`})}else if(u){const t=u.position,n=e.state(),r=ZI(o=n,i=t)?ji(o,{anchor:i,focus:i}):o;r!==n&&e.applyState(r),e.logger?.info("text-drag:collapse",{at:`${t.paragraphId}:${t.runId}[${t.offset}]`})}var o,i;y(),e.focusInputAfterPointerSelection()}else y()},w=(t,r)=>e.isReadOnly()||!r?.resolvedFromParagraph?(e.logger?.debug("text-drag:skip-start",{reason:e.isReadOnly()?"readonly":"no-hit",x:t.clientX,y:t.clientY}),!1):ZI(e.state(),r.position)?(e.logger?.info("text-drag:start-pending",{x:t.clientX,y:t.clientY,hit:`${r.position.paragraphId}:${r.position.runId}[${r.position.offset}]`,zone:r.zone}),u={x:t.clientX,y:t.clientY,position:r.position},l({x:t.clientX,y:t.clientY}),i(t.ctrlKey||t.metaKey),o(null),g=null,d(r.caretViewport??null),n(!1),b.claim(t),window.addEventListener("pointermove",v),window.addEventListener("pointerup",x),window.addEventListener("pointercancel",x),!0):(e.logger?.debug("text-drag:skip-start",{reason:"outside-selection",x:t.clientX,y:t.clientY,hit:`${r.position.paragraphId}:${r.position.runId}[${r.position.offset}]`}),!1);return{dragging:t,dropTargetPos:r,copyMode:a,pointerPos:s,caretViewport:c,tryStartTextDrag:w,stopDrag:y}}(e)}function eS(e){return e.blocks.flatMap(ra)}function tS(e,t){if(!e)return;const n=eS(e);return"start"===t?n[0]:n[n.length-1]}function nS(e){return function(e){const t=(t,n)=>{const r=e.state(),o=ko(r).find(e=>e.id===r.selection.focus.paragraphId);if(!o)return!1;const a="start"===t?0:mi(o).length,i=xi(o,a);return e.clearPreferredColumn(),e.applyState(ji(r,{anchor:n?r.selection.anchor:i,focus:i})),!0},n=(t,n)=>{const r=e.state(),o=ko(r);if(0===o.length)return!1;const a="start"===t?o[0]:o[o.length-1],i="start"===t?0:mi(a).length,s=xi(a,i);return e.clearPreferredColumn(),e.applyState(ji(r,{anchor:n?r.selection.anchor:s,focus:s})),!0},r=(t,n)=>{const r=e.state(),o=ko(r),a=o.findIndex(e=>e.id===r.selection.focus.paragraphId),i=o[a];if(!i)return!1;const s=mi(i),l=wa(i,r.selection.focus),c=s.length;if(!n&&!ga(r.selection))return e.clearPreferredColumn(),e.applyState("left"===t?Ui(r):Vi(r)),!0;let d=i,u=l;"left"===t?0===l&&a>0?(d=o[a-1],u=mi(d).length):u=nr(s,l):l===c&&a<o.length-1?(d=o[a+1],u=0):u=En(s,l);const p=xi(d,u);return e.clearPreferredColumn(),e.applyState(ji(r,{anchor:n?r.selection.anchor:p,focus:p})),!0},o=e=>a(e,!1),a=(t,n)=>{const r=e.state(),o=ko(r),a=o.findIndex(e=>e.id===r.selection.focus.paragraphId);if(-1===a)return!1;const i=e.surfaceRef(),s=i?.getBoundingClientRect()??null,l=e.preferredColumnX(),c=null===l?e.caretBox().left+(s?.left??0):l,d=i?e.canvasSnapshotProvider.getCanvasLayoutSnapshot({surface:i,state:r,documentLayout:e.documentLayout(),zoomFactor:e.zoomFactor?.()}):null;let u=a+t;const p=xo(r.document,r.selection.focus.paragraphId,Ua(r)),f=p?.tablePath[p.tablePath.length-1];if(p&&f){const e=Vx(r,p.zone),n=Zo(e,p.tablePath),a=n?.[n.length-1]?.table;if(a){const e=Xa(a),n=e.find(e=>e.rowIndex===f.rowIndex&&e.cellIndex===f.cellIndex);if(n){const r=[];for(let e=n.visualRowIndex+t;e>=0&&e<a.rows.length;e+=t)r.push(e);for(const n of r){const r=e.filter(e=>e.visualRowIndex===n&&eS(e.cell).length>0&&"continue"!==e.cell.vMerge);if(0===r.length)continue;const i=r.map(e=>{const t=tS(e.cell,"start")?.id,n=t?d?.paragraphs.find(e=>e.paragraphId===t&&e.tableCell&&e.tableCell.tableId===a.id)?.tableCell:null,r=n?.left??c,o=n?n.left+n.width:c;return{entry:e,distance:c<r?r-c:c>o?c-o:0}}).sort((e,t)=>e.distance-t.distance)[0]?.entry;if(!i)continue;const s=tS(i.cell,t<0?"end":"start");u=s?o.findIndex(e=>e.id===s.id):-1;break}}else if(t<0){const e=tS(a.rows[0]?.cells[0],"start");e&&(u=o.findIndex(t=>t.id===e.id)-1)}else{const e=a.rows[a.rows.length-1],t=e?.cells[e.cells.length-1],n=tS(t,"end");n&&(u=o.findIndex(e=>e.id===n.id)+1)}}}if(u<0||u>=o.length)return!1;const g=o[u];let m=0;const h=d?Ke(d,g.id):[],b=t<0?h[h.length-1]:h[0];if(b&&b.lines.length>0){const e=b.lines,n=t<0?e[e.length-1]:e[0];m=n.slots.length?n.slots.reduce((e,t)=>Math.abs(c-t.left)<Math.abs(c-e.left)?t:e,n.slots[0]).offset:0}else m=Math.min(wa(g,r.selection.focus),mi(g).length);return e.setPreferredColumnX(c),e.resetTransactionGrouping(),e.applyTransactionalState(e=>ji(e,{anchor:n?e.selection.anchor:xi(g,m),focus:xi(g,m)})),e.focusInput(),!0},i=()=>{const t=e.state();if(!ga(t.selection))return!1;const n=e.surfaceRef(),r=e.caretBox();if(!n||!r.visible)return!1;const o=ko(t).find(e=>e.id===t.selection.focus.paragraphId);if(!o)return!1;const a=wa(o,t.selection.focus);if(a<=0)return!1;const i=e.canvasSnapshotProvider.getCanvasLayoutSnapshot({surface:n,state:t,documentLayout:e.documentLayout(),zoomFactor:e.zoomFactor?.()});return!!i&&function(e,t,n){if(t<=0||!Number.isFinite(n))return!1;const r=e.filter(e=>e.startOffset<=t&&e.endOffset>=t&&n>=e.top-.5&&n<e.top+e.height-.5);return 1===r.length&&r[0].startOffset===t}(Ke(i,o.id).flatMap(e=>e.lines),a,r.top+i.surfaceRect.top+Math.min(1,r.height/2))};return{isCaretAtWrappedLineStart:i,moveSelectionToParagraphBoundary:t,moveSelectionToDocumentBoundary:n,moveSelectionByWord:r,moveVerticalByBlock:o,moveVerticalSelection:a}}(e)}function rS(e){return function(e){const[t,n]=Nt(null),r=(t,r)=>{const o=ko(e.state());let a;for(const e of o){for(const n of e.runs)if(n.revision?.id===t){a=n.revision;break}if(a)break}const i=e=>{for(const n of e)if("paragraph"!==n.type){if(n.style?.revision?.id===t)return n.style.revision;if(n.gridRevision?.id===t)return n.gridRevision;for(const e of n.rows){if(e.style?.revision?.id===t)return e.style.revision;if(e.style?.propertyRevision?.id===t)return e.style.propertyRevision;for(const n of e.cells){if(n.style?.revision?.id===t)return n.style.revision;if(n.style?.propertyRevision?.id===t)return n.style.propertyRevision;const e=i(n.blocks);if(e)return e}}}};if(!a)for(const n of Lo(e.state().document)){for(const e of[n.blocks,n.header,n.firstPageHeader,n.evenPageHeader,n.footer,n.firstPageFooter,n.evenPageFooter])if(e&&(a=i(e),a))break;if(a)break}if(!a)return;const s=r.currentTarget.getBoundingClientRect(),l=e.surfaceRef()?.getBoundingClientRect();if(!l)return;const c=e.zoomFactor?.()??1;n({revisionId:a.id,author:a.author,date:a.date,type:a.type,left:(s.left-l.left)/c,top:(s.top-l.top)/c})};return{hoveredRevision:t,handleRevisionMouseEnter:r,handleRevisionMouseLeave:()=>{n(null)}}}(e)}function oS(e){const t=ko(e);if(!t.length)return null;const n=Ri(e,t),r=t[n.startIndex];if(!r)return null;const o=(n.isCollapsed?[]:Ln(r,n.startParagraphOffset,n.startIndex===n.endIndex?n.endParagraphOffset:oi(r))).find(e=>"text"===e.kind&&e.text.length>0),a=function(e){const t=Na(e);if(t)return delete t.link,delete t.propertyRevision,Object.keys(t).length>0?t:void 0}(pi(o?o.styles:gt(r,n.startParagraphOffset),r.style?.styleId,e.document.styles)),i=n.isCollapsed||0===n.startParagraphOffset&&(n.endIndex>n.startIndex||n.endParagraphOffset===oi(r));return{text:a,paragraph:i?fi(r.style):void 0,list:i&&r.list?{...r.list}:void 0,copyParagraph:i}}function aS(e,t){const n=ko(e);if(!n.length)return e;const r=Ri(e,n);if(r.isCollapsed)return e;let o=!1;const a=n.map((e,n)=>{if(n<r.startIndex||n>r.endIndex)return e;const a=n===r.startIndex?r.startParagraphOffset:0,i=n===r.endIndex?r.endParagraphOffset:oi(e),s=t.copyParagraph&&function(e,t,n){return(t>n.startIndex||0===n.startParagraphOffset)&&(t<n.endIndex||n.endParagraphOffset===oi(e))}(e,n,r),l=s?fi(t.paragraph):e.style,c=s?t.list?{...t.list}:void 0:e.list,d=s&&(JSON.stringify(l)!==JSON.stringify(e.style)||JSON.stringify(c)!==JSON.stringify(e.list)),u=a<i&&Ln(e,a,i).some(e=>{if("text"!==e.kind||0===e.text.length)return!1;const n=Na(t.text)??{};void 0!==e.styles?.link&&(n.link=e.styles.link),void 0!==e.styles?.propertyRevision&&(n.propertyRevision=e.styles.propertyRevision);const r=Object.keys(n).length?n:void 0;return!ya(e.styles,r)});if(!d&&!u)return e;o=!0;let p=u?fe(e,a,i,e=>{if("text"!==e.kind)return e;const n=Na(t.text)??{};return void 0!==e.styles?.link&&(n.link=e.styles.link),void 0!==e.styles?.propertyRevision&&(n.propertyRevision=e.styles.propertyRevision),{...e,styles:Object.keys(n).length?n:void 0}}):e;return s&&(p={...p,style:l,list:c}),p});return o?Vt(e,a,H(a,r)):e}function iS(e){const t=ko(e);if(!t.length)return"";const n=Ri(e,t);return[e.activeSectionIndex??0,e.activeZone??"main",n.start.paragraphId,n.startParagraphOffset,n.end.paragraphId,n.endParagraphOffset].join(":")}function sS(e){const[t,n]=Nt(null);let r=null,o=null,a="";const i=()=>{r=null,o=null,a="",n(null)};zn()&&(mn(()=>{t()&&(e.isReadOnly()||e.state().document!==o)&&i()}),Ut(i));const s=()=>!e.isReadOnly()&&ko(e.state()).length>0,l=t=>{if(!s())return!1;const i=e.state(),l=oS(i);return!!l&&(r=l,o=i.document,a=iS(i),n(t),e.focusInput(),!0)};return{mode:t,canCapture:s,armOnce:()=>l("once"),armContinuous:()=>l("continuous"),cancel:i,applyToSelection:n=>{if(!r||!t())return!1;if(e.isReadOnly()||e.state().document!==o)return i(),!1;const s=e.state();if(iS(s)===a)return!1;const l=function(e,t){const n=ko(e);if(0===n.length)return null;const r=Ri(e,n);if(!r.isCollapsed)return e;if(!t)return null;const o=n[r.startIndex];if(!o)return null;const a=St(mi(o),r.startParagraphOffset);return a.end<=a.start?null:{...e,selection:{anchor:xi(o,a.start),focus:xi(o,a.end)}}}(s,"pointer"===n);if(!l)return!1;e.clearPreferredColumn(),e.resetTransactionGrouping();let c=!1;return er(()=>{e.applyTransactionalState(t=>{if(e.isReadOnly()||t.document!==o)return t;const n=e.applyTableAwareParagraphEdit({...t,selection:l.selection},e=>aS(e,r));return c=n.document!==t.document,n}),"once"===t()?i():c&&(o=e.state().document)}),c&&e.focusInput(),c}}}function lS(e){return function(e){const{state:t,logger:n,isReadOnly:r,applyState:o,cloneState:a,focusInput:i,focusInputAfterPointerSelection:s,focusInputSync:l,surfaceRef:c,viewportRef:d,zoomFactor:u,insertImageFromFile:p,getForcePlainTextPaste:f,setForcePlainTextPaste:g,getCommandsController:m,applyTransactionalState:h,clearPreferredColumn:b,resetTransactionGrouping:y,updateHistoryState:v,caretBox:x,preferredColumnX:w,setPreferredColumnX:I,documentLayout:S,canvasSnapshotProvider:C}=e,k=()=>vv(t),T=()=>Ax(t),P=Hw({state:()=>t,resetTransactionGrouping:y,applyTransactionalState:h,focusInput:i}),R=Ow({state:()=>t,surfaceRef:()=>c()??null,viewportRef:()=>d()??null,documentLayout:S,canvasSnapshotProvider:C,zoomFactor:u}).resolveSurfaceHitAtPoint,A=function(e){const[t,n]=Nt(""),[r,o]=Nt(""),[a,i]=Nt({matchCase:!1,wholeWord:!1}),[s,l]=Nt([]),[c,d]=Nt(-1),[u,p]=Nt(!1);mn(qt([()=>e.state.document,t,a],([e,t,n])=>{const r=Cw(e,t,n);l(r),0===r.length?d(-1):(c()>=r.length||-1===c())&&d(0)}));const f=t=>{const n=s()[t];n&&e.applyState(ji(e.state,{anchor:n.anchor,focus:n.focus}))};return{searchTerm:t,setSearchTerm:n,replaceTerm:r,setReplaceTerm:o,findOptions:a,setFindOptions:i,matches:s,currentIndex:c,findNext:()=>{const e=s().length;if(0===e)return;const t=(c()+1)%e;d(t),f(t)},findPrevious:()=>{const e=s().length;if(0===e)return;const t=(c()-1+e)%e;d(t),f(t)},replace:()=>{if(0===s().length||-1===c())return;const t=s()[c()];e.applyTransactionalState(e=>Ju(ji(e,{anchor:t.anchor,focus:t.focus}),r()),{mergeKey:yf})},replaceAll:()=>{const n=t();0!==n.length&&(e.applyTransactionalState(e=>kw(e,n,r(),a()),{mergeKey:vf}),p(!1),e.focusInput())},isOpen:u,setIsOpen:p}}({state:t,applyState:o,applyTransactionalState:h,focusInput:i}),M=gw({applyTransactionalState:h,applySelectionToStatePreservingStructure:(e,t)=>({...e,document:lt(e).document,selection:t}),focusInput:i,logger:n}),O=sS({state:()=>t,isReadOnly:r,applyTransactionalState:h,applyTableAwareParagraphEdit:M.applyTableAwareParagraphEdit,clearPreferredColumn:b,resetTransactionGrouping:y,focusInput:i}),B=(e,t)=>R(e,t)?.position??null,F=ww({state:t,surfaceRef:c,resolvePositionAtSurfacePoint:B,applyState:o,applyTransactionalState:h,updateHistoryState:v,focusInput:i,focusInputAfterPointerSelection:s,cloneState:a,logger:n,zoomFactor:u}),E=Iw({state:t,surfaceRef:c,applyState:o,updateHistoryState:v,focusInput:i,cloneState:a,logger:n,zoomFactor:u}),D=Sw({state:()=>t,commandsController:m,clearPreferredColumn:b,resetTransactionGrouping:y,focusInput:i,logger:n}),L=function(e){const t=()=>e.state,n=sI({state:t,applyTransactionalState:e.applyTransactionalState,surfaceRef:e.surfaceRef,viewportRef:e.viewportRef,zoomFactor:e.zoomFactor,documentLayout:e.documentLayout,canvasSnapshotProvider:e.canvasSnapshotProvider}),r=dI({state:t,applyTransactionalState:e.applyTransactionalState,surfaceRef:e.surfaceRef,zoomFactor:e.zoomFactor,documentLayout:e.documentLayout,canvasSnapshotProvider:e.canvasSnapshotProvider}),o=gI({state:t,applyTransactionalState:e.applyTransactionalState,resolvePositionAtSurfacePoint:e.resolvePositionAtSurfacePoint,focusInput:e.focusInput}),a=rS({state:t,surfaceRef:()=>e.surfaceRef()??null,zoomFactor:e.zoomFactor}),i=QI({state:t,isReadOnly:e.isReadOnly,resolveSurfaceHitAtPoint:e.resolveSurfaceHitAtPoint,applyTransactionalState:e.applyTransactionalState,applyState:e.applyState,applyTableAwareParagraphEdit:e.tableOps.applyTableAwareParagraphEdit,clearPreferredColumn:e.clearPreferredColumn,resetTransactionGrouping:e.resetTransactionGrouping,focusInputAfterPointerSelection:e.focusInputAfterPointerSelection,logger:e.logger}),s=qI({state:t,applyState:e.applyState,tableResize:n,imageOps:e.imageOps,clearPendingCaretTextStyle:e.styleController.clearPendingCaretTextStyle,onSelectionFinalized:()=>{e.formatPainter.applyToSelection("pointer")},clearPreferredColumn:e.clearPreferredColumn,resetTransactionGrouping:e.resetTransactionGrouping,focusInputAfterPointerSelection:e.focusInputAfterPointerSelection,focusInputSync:e.focusInputSync,scrollToLinkedParagraph:Z({state:t,documentLayout:e.documentLayout,surfaceRef:e.surfaceRef,viewportRef:e.viewportRef,zoomFactor:e.zoomFactor,snapshotProvider:e.canvasSnapshotProvider}),resolveSurfaceHitAtPoint:e.resolveSurfaceHitAtPoint,getParagraphById:ea,textDrag:{tryStartTextDrag:i.tryStartTextDrag},logger:e.logger,openEquationDialog:e.openEquationDialog}),l=GI({state:t,isReadOnly:e.isReadOnly,logger:e.logger,clearPreferredColumn:e.clearPreferredColumn,pendingCaretTextStyle:e.styleController.pendingCaretTextStyle,applyTransactionalState:e.applyTransactionalState,applyTableAwareParagraphEdit:e.tableOps.applyTableAwareParagraphEdit,focusInput:e.focusInput}),c=nS({state:t,applyState:e.applyState,applyTransactionalState:e.applyTransactionalState,surfaceRef:()=>e.surfaceRef()??null,caretBox:e.caretBox,preferredColumnX:e.preferredColumnX,setPreferredColumnX:e.setPreferredColumnX,clearPreferredColumn:e.clearPreferredColumn,resetTransactionGrouping:e.resetTransactionGrouping,focusInput:e.focusInput,zoomFactor:e.zoomFactor,documentLayout:e.documentLayout,canvasSnapshotProvider:e.canvasSnapshotProvider}),{handleCopy:d,handleCut:u,handlePaste:p,handleDrop:f}=Ww({state:t,stateSnapshot:e.getStateSnapshot,onNativeClipboardIssue:e.clipboardActions?.reportNativeIssue,isReadOnly:e.isReadOnly,forcePlainTextPaste:e.getForcePlainTextPaste,consumePasteMode:e.clipboardActions?.consumePasteMode,onNativeClipboardSuccess:e.clipboardActions?.dismiss,onNativeClipboardStart:e.clipboardActions?.dismiss,clipboardRequestGeneration:e.clipboardActions?.requestGeneration,setForcePlainTextPaste:e.setForcePlainTextPaste,clearPreferredColumn:e.clearPreferredColumn,resetTransactionGrouping:e.resetTransactionGrouping,applyTransactionalState:e.applyTransactionalState,applyTableAwareParagraphEdit:e.tableOps.applyTableAwareParagraphEdit,focusInput:e.focusInput,insertImageFromFile:e.insertImageFromFile,resolvePositionAtSurfacePoint:e.resolvePositionAtSurfacePoint});return{tableResize:n,tableCornerResize:r,tableDrag:o,revisionController:a,textDrag:i,surfaceEvents:s,textInput:l,navigation:c,handleCopy:d,handleCut:u,handlePaste:p,handleDrop:f}}({state:t,getStateSnapshot:e.getStateSnapshot,applyState:o,applyTransactionalState:h,isReadOnly:r,logger:n,focusInput:i,focusInputAfterPointerSelection:s,focusInputSync:l,clearPreferredColumn:b,resetTransactionGrouping:y,surfaceRef:c,viewportRef:d,caretBox:()=>x(),preferredColumnX:()=>w(),setPreferredColumnX:I,zoomFactor:u,documentLayout:S,canvasSnapshotProvider:C,resolveSurfaceHitAtPoint:R,resolvePositionAtSurfacePoint:B,tableOps:M,imageOps:F,styleController:D,formatPainter:O,getForcePlainTextPaste:f,setForcePlainTextPaste:g,clipboardActions:e.clipboardActions,insertImageFromFile:p,openEquationDialog:e.openEquationDialog}),N=e=>{0===e.button&&(D.clearPendingCaretTextStyle(),e.preventDefault(),i())};return{selectedImageRun:k,selectedTextBoxRun:T,layoutOptionsOverlay:P,fr:A,resolveSurfaceHitAtPoint:R,resolvePositionAtSurfacePoint:B,tableOps:M,imageOps:F,textBoxOps:E,styleController:D,formatPainter:O,onEditorPointerDown:N,tableResize:L.tableResize,tableCornerResize:L.tableCornerResize,tableDrag:L.tableDrag,revisionController:L.revisionController,textDrag:L.textDrag,surfaceEventsWithTextDrag:L.surfaceEvents,textInput:L.textInput,navigation:L.navigation,handleCopy:L.handleCopy,handleCut:L.handleCut,handlePaste:L.handlePaste,handleDrop:L.handleDrop}}(e)}function cS(e){if("main"!==(e.activeZone??"main"))return e;const t=ga(e.selection)?e:te(e),{paragraph:n,index:r,offset:o}=ae(t),a=uo(),i=function(e){const t=e.footnotes,n=t?.settings?.numberFormat??"decimal";let r=(t?.settings?.startAt??1)-1;const o=/* @__PURE__ */new Set;for(const{run:a}of Ja(e)){const e=qr(a);e&&!e.customMark&&(o.has(e.footnoteId)||(o.add(e.footnoteId),r+=1))}return li(r+1,n)}(t.document),s=oa(a.id,i),l=u(n,o,[s]),c=ko(t).map((e,t)=>t===r?l:e),d=xi(l,o+i.length),p=Vt(t,c,Ii(d)),f=function(e){return e||{items:{}}}(p.document.footnotes),g={...p.document,footnotes:{...f,items:{...f.items,[a.id]:a}}},m=Ea(g),h=a.blocks.flatMap(ra).find(Boolean);return h?{...p,document:m,selection:Ii(xi(h,0)),activeZone:"footnote",activeFootnoteId:a.id}:{...p,document:m}}function dS(e){if(!e)return;const{propertyRevision:t,...n}=e;return Object.keys(n).length>0?n:void 0}function uS(e,t,n){return e.flatMap(e=>{if("paragraph"===e.type)return[e];let r=e.style;if(r?.revision?.id===t)if(n){const{revision:e,...t}=r;r=t}else r={...r.revision.previous};let o=e.gridCols,a=e.gridRevision;a?.id===t&&(o=n?o:[...a.previous],a=void 0);const i=e.rows.map(e=>({...e,cells:[...e.cells]}));for(let l=0;l<i.length;l+=1){const e=i[l];for(let r=0;r<e.cells.length;r+=1){const o=e.cells[r],a=o.mergeRevisionState;if(a&&a.revisionId===t){if(n){const{mergeRevisionState:t,...n}=o;e.cells[r]=n;continue}"horizontal"===a.orientation?e.cells.splice(r,a.currentCellCount,...a.previousCells):a.previousCells.forEach((e,t)=>{const n=i[l+t];n&&(n.cells[r]=e)})}}}const s=i.flatMap(e=>{if(e.style?.revision?.id===t&&(n&&"delete"===e.style.revision.type||!n&&"insert"===e.style.revision.type))return[];let r=e.style;if(r?.propertyRevision?.id===t)if(n){const{propertyRevision:e,...t}=r;r=t}else r={...r.propertyRevision.previous,revision:r.revision};if(r?.revision?.id===t){const{revision:e,...t}=r;r=t}const o=e.cells.flatMap(e=>{if(e.style?.revision?.id===t&&(n&&"delete"===e.style.revision.type||!n&&"insert"===e.style.revision.type))return[];let r=e.style;if(r?.propertyRevision?.id===t)if(n){const{propertyRevision:e,...t}=r;r=t}else r={...r.propertyRevision.previous,revision:r.revision};let o={...e,style:r,blocks:uS(e.blocks,t,n)};if(r?.revision?.id===t&&e.mergeRevisionState?.revisionId!==t){const e=r.revision,{revision:t,...a}=r;o={...o,...n||"merge"!==e.type?{}:e.previous,style:a}}return[o]});return[{...e,isHeader:r&&"isHeader"in r?r.isHeader:e.isHeader,style:r,cells:o}]});return 0===s.length?[]:[{...e,style:r,gridCols:o,gridRevision:a,rows:s}]})}function pS(e,t,n){const r=Lo(e.document).map(e=>({...e,blocks:uS(e.blocks,t,n),header:e.header?uS(e.header,t,n):void 0,firstPageHeader:e.firstPageHeader?uS(e.firstPageHeader,t,n):void 0,evenPageHeader:e.evenPageHeader?uS(e.evenPageHeader,t,n):void 0,footer:e.footer?uS(e.footer,t,n):void 0,firstPageFooter:e.firstPageFooter?uS(e.firstPageFooter,t,n):void 0,evenPageFooter:e.evenPageFooter?uS(e.evenPageFooter,t,n):void 0}));return{...e,document:{...e.document,sections:r}}}function fS(e,t,n){const r=Lo(e.document),o=r.findIndex(e=>e.propertyRevision?.id===t);if(-1===o)return e;const a=r[o],i=a.propertyRevision,s=[...r];if(n)s[o]={...a,propertyRevision:void 0};else{const e=structuredClone(i.previous);s[o]={...a,pageSettings:e.pageSettings,pageBorder:e.pageBorder,pageNumbering:e.pageNumbering,verticalAlignment:e.verticalAlignment,bidi:e.bidi,propertyRevision:void 0};const t=s[o+1];t&&(s[o+1]={...t,breakType:e.nextBreakType})}return{...e,document:{...e.document,sections:s}}}function gS(e,t){const n=ko(e).map(e=>{const n=e.runs.filter(e=>!(e.revision?.id===t&&"delete"===e.revision.type)).map(e=>{if(e.revision?.id===t&&"insert"===e.revision.type){const t={...e};return delete t.revision,t}return e.styles?.propertyRevision?.id===t?{...e,styles:dS(e.styles)}:e});return n.length===e.runs.length&&n.every((t,n)=>t===e.runs[n])?e:N(e,n)});return fS(pS(Vt(e,n,H(n,Ri(e))),t,!0),t,!0)}function mS(e,t){const n=ko(e).map(e=>{const n=e.runs.filter(e=>!(e.revision?.id===t&&"insert"===e.revision.type)).map(e=>{if(e.revision?.id===t&&"delete"===e.revision.type){const t={...e};return delete t.revision,t}const n=e.styles?.propertyRevision;return n?.id===t?{...e,styles:dS(n.previous)}:e});return n.length===e.runs.length&&n.every((t,n)=>t===e.runs[n])?e:N(e,n)});return fS(pS(Vt(e,n,H(n,Ri(e))),t,!1),t,!1)}function hS(e,t){return"paragraph"===e.type?t.has(e.id):e.rows.some(e=>e.cells.some(e=>e.blocks.some(e=>hS(e,t))))}function bS(e,t,n){for(const r of e)if("paragraph"!==r.type){hS(r,t)&&(r.style?.revision&&n.add(r.style.revision.id),r.gridRevision&&n.add(r.gridRevision.id));for(const e of r.rows){const r=e.cells.filter(e=>e.blocks.some(e=>hS(e,t)));r.length>0&&(e.style?.revision&&n.add(e.style.revision.id),e.style?.propertyRevision&&n.add(e.style.propertyRevision.id));for(const e of r)e.style?.revision&&n.add(e.style.revision.id),e.style?.propertyRevision&&n.add(e.style.propertyRevision.id),bS(e.blocks,t,n)}}}function yS(e){const t=Ri(e),n=ko(e),r=/* @__PURE__ */new Set;for(let a=t.startIndex;a<=t.endIndex;a+=1){const e=n[a],o=a===t.startIndex?t.startParagraphOffset:0,i=a===t.endIndex?t.endParagraphOffset:oi(e),s=Ln(e,o,i);for(const t of s)t.revision?.id&&r.add(t.revision.id),t.styles?.propertyRevision?.id&&r.add(t.styles.propertyRevision.id)}const o=new Set(n.slice(t.startIndex,t.endIndex+1).map(e=>e.id));for(const a of Lo(e.document))for(const e of[a.blocks,a.header,a.firstPageHeader,a.evenPageHeader,a.footer,a.firstPageFooter,a.evenPageFooter])e&&bS(e,o,r);for(const a of Zv(e))a.paragraphIds.some(e=>o.has(e))&&r.add(a.id);return r}function vS(e){const t=/* @__PURE__ */new Set,n=e=>{for(const n of e)n.revision?.id&&t.add(n.revision.id),n.revisionRangeMarker?.id&&t.add(n.revisionRangeMarker.id),n.styles?.propertyRevision?.id&&t.add(n.styles.propertyRevision.id)},r=e=>{if(e)for(const o of e)if("paragraph"!==o.type){o.style?.revision&&t.add(o.style.revision.id),o.gridRevision&&t.add(o.gridRevision.id);for(const e of o.rows){e.style?.revision&&t.add(e.style.revision.id),e.style?.propertyRevision&&t.add(e.style.propertyRevision.id);for(const n of e.cells)n.style?.revision&&t.add(n.style.revision.id),n.style?.propertyRevision&&t.add(n.style.propertyRevision.id),n.mergeRevisionState?.revisionId&&t.add(n.mergeRevisionState.revisionId),r(n.blocks)}}else n(o.runs)};for(const i of Lo(e.document))i.propertyRevision&&t.add(i.propertyRevision.id),r(i.blocks),r(i.header),r(i.firstPageHeader),r(i.evenPageHeader),r(i.footer),r(i.firstPageFooter),r(i.evenPageFooter);const o=e.document.footnotes?.items??{};for(const i of Object.values(o))r(i.blocks);const a=e.document.endnotes?.items??{};for(const i of Object.values(a))r(i.blocks);return t}function xS(e){return vS(e).size>0}function wS(e,t){if(!xS(e))return e;const n=Cn(e.document,t);if(!n.changed)return e;const r=ko({...e,document:n.document}),o=H(r,Ri(e));return{...e,document:n.document,selection:o}}function IS(e){const t=Ri(e),n=ko(e);if(t.isCollapsed){const e=n[t.startIndex];return e?rn(e,t.startParagraphOffset)?.href??null:null}const r=n.slice(t.startIndex,t.endIndex+1).flatMap((e,n)=>{const r=t.startIndex+n,o=r===t.startIndex?t.startParagraphOffset:0,a=r===t.endIndex?t.endParagraphOffset:oi(e);return Ln(e,o,a)}).filter(e=>e.text.length>0&&"image"!==e.kind);if(0===r.length)return null;const o=r[0]?.styles?.link;return o&&r.every(e=>e.styles?.link===o)?o:null}function SS(e){const t=Ri(e),n=ko(e).map((e,n)=>{if(n<t.startIndex||n>t.endIndex)return ho(e);if(!e.list)return ho(e);const r=e.list.level??0;return r<=0?Fe(e):$e(e,r-1)});return Vt(e,n,H(n,t))}function CS(e){return kS(e,null)}function kS(e,t){const n=Ri(e),r=ko(e).map((e,r)=>r<n.startIndex||r>n.endIndex?ho(e):e.list?{...ho(e),list:{...e.list,startAt:null!==t?t:void 0}}:ho(e));return Vt(e,r,H(r,n))}function TS(e){return function(e){const{state:t,logger:n,applyState:r,applyTransactionalState:o,applySelectionAwareTextCommand:a,applySelectionAwareParagraphCommand:s,applyTableAwareParagraphEdit:l,focusInput:c,clearPreferredColumn:d,resetTransactionGrouping:u,toolbarStyleState:p,selectionCollapsed:f,selectedImageRun:g}=e,m=e=>{d(),u(),r(e),c()},h=e=>{d(),u(),a(e),c()},b=e=>{d(),u(),s(e),c()},y=(e,t)=>{d(),u(),o(e,t),c()},v=()=>{const e=Ri(t);return ko(t).slice(e.startIndex,e.endIndex+1)},w=()=>v().some(e=>Boolean(e.list)),I=()=>{const e=t.selection.focus.paragraphId;return ko(t).find(t=>t.id===e)??null},S=()=>{const e=I();return!!e?.list&&(d(),u(),f()&&0===mi(e).length?s(e=>function(e){const t=Ri(e),n=ko(e).map((e,n)=>n<t.startIndex||n>t.endIndex?ho(e):Fe(e));return Vt(e,n,H(n,t))}(e)):o(e=>l(e,e=>function(e){if(Dt(e))return e;const t=ga(e.selection)?e:te(e),{paragraph:n,index:r,offset:o}=ae(t);if(Dt(t))return e;const{beforeRuns:a,afterRuns:i}=Le(n,o),s=N(n,a,gt(n,o)),l=i.length>0?N(q(n,[]),i):(()=>{const e=Go("");return e.style=n.style?{...n.style}:void 0,e.list=Qo(n.list),e})(),c=ko(t),d=[...Yo(c.slice(0,r)),s,l,...Yo(c.slice(r+1))];return Vt(t,d,J(xi(l,0)))}(e)),{mergeKey:nf}),c(),!0)},C=()=>{const e=t.selection,n=Ua(t),r=io(t.document,e.anchor.paragraphId,n),o=io(t.document,e.focus.paragraphId,n);return r&&o&&r.blockIndex===o.blockIndex?` [table b${r.blockIndex} r${r.rowIndex}:c${r.cellIndex}→r${o.rowIndex}:c${o.cellIndex}]`:""},k=e=>{if(f())return;const r=t.selection;n.info(`toggleStyle:${e} at ${r.anchor.paragraphId}:${r.anchor.runId}[${r.anchor.offset}..${r.focus.offset}]${C()}`),h(t=>lp(t,e))},T=e=>{f()||h(t=>dp(t,e))},P=(e,r)=>{if(f())return;const o=t.selection;n.info(`setStyle:${e}=${JSON.stringify(r)} at ${o.anchor.paragraphId}:${o.anchor.runId}[${o.anchor.offset}..${o.focus.offset}]${C()}`),h(t=>up(t,e,r))},R=(e,t)=>{b(n=>le(n,e,t))},A=e=>{const t=!p()[e];R(e,"widowControl"===e?t:!!t||null)},M=()=>{y(e=>l(e,e=>xr(e)))},O=()=>"main"===(t.activeZone??"main"),B=()=>{O()&&y(e=>cS(e))},F=e=>{const n=IS(t);f()&&!n||y(t=>function(e,t){const n=Ri(e);if(!n.isCollapsed)return up(e,"link",t);const r=ko(e)[n.startIndex];if(!r)return e;const o=rn(r,n.startParagraphOffset);if(!o)return e;const a=up(ji(e,{anchor:xi(r,o.startOffset),focus:xi(r,o.endOffset)}),"link",t),i=ko(a)[n.startIndex];return i?{...a,selection:{anchor:xi(i,o.startOffset),focus:xi(i,o.endOffset)}}:a}(t,e),{mergeKey:rf})},E=()=>{const n=IS(t)??"";f()&&!n||e.openLinkDialog(n)},D=()=>e.openFontDialog(),L=t=>e.openParagraphDialog(t),z=()=>{F(null)},$=()=>{const t=g();if(!t)return;const n=ki(t.run)?.alt??"";e.openImageAltDialog(n)},W=t=>{g()&&y(n=>function(e,t,n){const r=vv(e);if(!r||!ki(r.run))return e;const o=ko(e),a=r.paragraphIndex+1,i=a<o.length&&Ya(o[a]),s=i?aa(o[a],t,n):va(t,n,1);if(i&&s===o[a])return e;const l=a<o.length&&Ya(o[a])?[...Yo(o.slice(0,a)),s,...Yo(o.slice(a+1))]:[...Yo(o.slice(0,a)),s,...Yo(o.slice(a))],c=Oa(l,e.document.styles),d=c[a]??s;return Vt(e,c,J(xi(d,Sa(d))))}(n,t,e.imageCaptionLabel()),{mergeKey:af})},j=()=>{g()&&e.openImageCaptionDialog(function(e){const t=vv(e);if(!t||!ki(t.run))return null;const n=ko(e);return ai(n[t.paragraphIndex+1])}(t)??"")};return{applyBooleanStyleCommand:k,applyToggleCharacterBorderCommand:()=>{f()||h(e=>fp(e))},applyValueStyleCommand:P,applyUnderlineStyleCommand:T,applyChangeTextCaseCommand:e=>{f()||h(t=>yp(t,e))},applyClearFormattingCommand:()=>{f()||h(e=>cp(e))},applyParagraphStyleCommand:R,toggleParagraphFlagCommand:A,applyParagraphListCommand:e=>{b(t=>function(e,t){const n=Ri(e),r=ko(e),o=n.startIndex,a=n.endIndex,i=r.slice(o,a+1),s=i.length>0&&i.every(e=>e.list?.kind===t),l=r.map((e,n)=>{if(n<o||n>a)return ho(e);const r=ho(e);return s?(delete r.list,r):(r.list={kind:t,level:e.list?.level??0,format:e.list?.format,startAt:e.list?.startAt},r)});return Vt(e,l,H(l,n))}(t,e))},handleListFormatChange:e=>{b(t=>function(e,t){if(null!==t&&!co(t))return e;const n=Ri(e),r=ko(e).map((e,r)=>r<n.startIndex||r>n.endIndex?ho(e):e.list?{...ho(e),list:{...e.list,format:t||void 0}}:ho(e));return Vt(e,r,H(r,n))}(t,e))},handleListStartAtChange:e=>{b(t=>kS(t,e))},applyInsertSectionBreakCommand:e=>{m(Re(t,e))},applyInsertPageBreakCommand:M,canInsertFootnoteCommand:O,applyInsertFootnoteCommand:B,handleStyleChange:e=>{b(t=>x(t,e||null))},applyUpdateSectionSettingsCommand:(e,n)=>{m(i(t,e,n))},applyToggleTrackChangesCommand:()=>{m(function(e){return{...e,trackChangesEnabled:!e.trackChangesEnabled}}(t))},applyToggleRevisionMarkupCommand:()=>{m(function(e){return{...e,showRevisionMarkup:!(e.showRevisionMarkup??!0)}}(t))},applySetReviewDisplayModeCommand:e=>{m(function(e,t){return(e.reviewDisplayMode??"all")===(t??"all")?e:{...e,reviewDisplayMode:t}}(t,e))},applyShowMarkupCommand:e=>{m(ex(t,e))},applyToggleShowMarginsCommand:()=>{r({...t,showMargins:!t.showMargins}),c()},applyToggleShowParagraphMarksCommand:()=>{r({...t,showParagraphMarks:!t.showParagraphMarks}),c()},applyAcceptRevisionsCommand:()=>{y(e=>function(e){let t=e;for(const n of yS(e))t=gS(t,n);return t}(e))},applyRejectRevisionsCommand:()=>{y(e=>function(e){let t=e;for(const n of yS(e))t=mS(t,n);return t}(e))},applyAcceptAllRevisionsCommand:()=>{y(e=>function(e){return wS(e,"accept")}(e))},applyRejectAllRevisionsCommand:()=>{y(e=>function(e){return wS(e,"reject")}(e))},applyLinkCommand:F,promptForLink:E,openFontDialog:D,openParagraphDialog:L,openStylesDialog:()=>{n.warn("stylesDialog not yet implemented")},openPageSetupDialog:()=>{n.warn("pageSetupDialog not yet implemented")},removeLinkCommand:z,applyImageAltCommand:e=>{g()&&y(t=>function(e,t){return Av(e,e=>({...e,alt:t??void 0}))}(t,e),{mergeKey:of})},promptForImageAlt:$,applyImageCaptionCommand:W,promptForImageCaption:j,applyImageWidthCmCommand:e=>{!g()||!Number.isFinite(e)||e<=0||y(t=>function(e,t){const n=vv(e),r=n&&ki(n.run);if(!r||!Number.isFinite(t)||t<=0)return e;const o=Math.max(24,Math.round(t*So));return xv(e,o,o*(r.height/r.width))}(t,e),{mergeKey:sf})},applyImageHeightCmCommand:e=>{!g()||!Number.isFinite(e)||e<=0||y(t=>function(e,t){const n=vv(e),r=n&&ki(n.run);if(!r||!Number.isFinite(t)||t<=0)return e;const o=Math.max(24,Math.round(t*So));return xv(e,o*(r.width/r.height),o)}(t,e),{mergeKey:sf})},applyImageCropAspectCommand:e=>{if(!g())return;const t=function(e){const t=e.trim().toLowerCase();if("reset"===t||"fit"===t||"fill"===t)return"reset";const n=t.split(/[:/]/);if(2!==n.length)return null;const r=Number(n[0]),o=Number(n[1]);return!Number.isFinite(r)||!Number.isFinite(o)||r<=0||o<=0?null:r/o}(e);null!==t&&y(e=>"reset"===t?kv(e):Sv(e,t),{mergeKey:lf})},applyImageCropShapeCommand:e=>{g()&&y(t=>function(e,t){const n=t?.trim();return Av(e,e=>{const t={...e};return n&&"rect"!==n?(t.cropShape={preset:n},t.cropFit||(t.cropFit="fill")):delete t.cropShape,t})}(t,e),{mergeKey:lf})},applyImageCropFillCommand:()=>{g()&&y(e=>function(e){const t=vv(e),n=t&&ki(t.run);return n?Av(Iv(e,{crop:Cv(n)}),e=>({...e,cropFit:"fill"})):e}(e),{mergeKey:lf})},applyImageCropFitCommand:()=>{g()&&y(e=>function(e){return Av(e,e=>{const t={...e,cropFit:"fit"};return delete t.crop,t})}(e),{mergeKey:lf})},resetImageCropCommand:()=>{g()&&y(e=>kv(e),{mergeKey:lf})},applyImageBorderCommand:e=>{g()&&y(t=>function(e,t){return Av(e,e=>{if(null===t.color){const{border:t,...n}=e;return n}const n={...e.border??{color:"#000000"}};return void 0!==t.color&&(n.color=t.color),void 0!==t.widthPt&&(n.widthPt=t.widthPt),void 0!==t.dash&&(n.dash=t.dash),{...e,border:n}})}(t,e))},flipImageCommand:e=>{g()&&y(t=>Rv(t,e),{mergeKey:cf})},rotateImageCommand:e=>{g()&&y(t=>Pv(t,e),{mergeKey:df})},applyImageTransparencyCommand:e=>{g()&&y(t=>function(e,t){return null===vv(e)?e:Av(e,e=>{if(!Number.isFinite(t)||t<=0){const{transparency:t,...n}=e;return n}const n=Math.min(1,t);return{...e,transparency:Math.round(1e3*n)/1e3}})}(t,e??0),{mergeKey:uf})},resetImageCommand:()=>{g()&&y(e=>function(e){return null===vv(e)?e:Av(e,e=>{const t={...e};return delete t.crop,delete t.cropFit,delete t.cropShape,delete t.transparency,delete t.border,delete t.rotation,delete t.flipH,delete t.flipV,delete t.fillMode,t})}(e),{mergeKey:pf})},handleListTab:e=>!io(t.document,t.selection.focus.paragraphId,Ua(t))&&(!!w()&&(b(t=>"indent"===e?function(e){const t=Ri(e),n=ko(e).map((e,n)=>n<t.startIndex||n>t.endIndex?ho(e):e.list?$e(e,(e.list.level??0)+1):ho(e));return Vt(e,n,H(n,t))}(t):SS(t)),!0)),handleListEnter:S,handleListBoundaryBackspace:e=>{const n=I();return!(!n?.list||!f())&&(0===wa(n,t.selection.focus)&&(d(),u(),s(e=>SS(e)),e.currentTarget.value="",c(),!0))}}}(e)}function PS(e){return{fontFamily:e.fontFamily??"",fontSize:ct(e.fontSize),color:e.color??"",colorMode:e.color?"custom":"automatic",highlight:e.highlight??"",shading:e.textShading??"",bold:Boolean(e.bold),italic:Boolean(e.italic),underline:Boolean(e.underline),underlineStyle:e.underlineStyle?e.underlineStyle:null,underlineColor:e.underlineColor??"",strike:Boolean(e.strike),doubleStrike:Boolean(e.doubleStrike),superscript:Boolean(e.superscript),subscript:Boolean(e.subscript),smallCaps:Boolean(e.smallCaps),allCaps:Boolean(e.allCaps),hidden:Boolean(e.hidden),characterScale:e.characterScale??"",characterSpacing:e.characterSpacing??"",baselineShift:e.baselineShift??"",kerningThreshold:e.kerningThreshold??"",ligatures:e.ligatures??"",numberSpacing:e.numberSpacing??"",numberForm:e.numberForm??"",stylisticSet:e.stylisticSet??"",contextualAlternates:Boolean(e.contextualAlternates)}}function RS(e){return{align:e.align??"",indentLeft:e.indentLeft??"",indentRight:e.indentRight??"",indentFirstLine:e.indentFirstLine??"",indentHanging:e.indentHanging??"",mirrorIndents:e.mirrorIndents??!1,spacingBefore:e.spacingBefore??"",spacingAfter:e.spacingAfter??"",lineHeight:e.lineHeight??"",lineRule:e.lineRule??"",contextualSpacing:e.contextualSpacing??!1,outlineLevel:e.outlineLevel??"",shading:e.shading??"",borderStyle:e.borderStyle??"",borderWidth:e.borderWidth??"",borderColor:e.borderColor??"",borderSideTop:e.borderSideTop??!1,borderSideRight:e.borderSideRight??!1,borderSideBottom:e.borderSideBottom??!1,borderSideLeft:e.borderSideLeft??!1,pageBreakBefore:e.pageBreakBefore??!1,keepWithNext:e.keepWithNext??!1,keepLinesTogether:e.keepLinesTogether??!1,widowControl:e.widowControl??!0,tabs:e.tabs??[]}}function AS(e){return function(e){const t=TS({state:e.state,logger:e.logger,applyState:e.applyState,applyTransactionalState:e.applyTransactionalState,applySelectionAwareTextCommand:e.tableOps.applySelectionAwareTextCommand,applySelectionAwareParagraphCommand:e.tableOps.applySelectionAwareParagraphCommand,applyTableAwareParagraphEdit:e.tableOps.applyTableAwareParagraphEdit,focusInput:e.focusInput,clearPreferredColumn:e.clearPreferredColumn,resetTransactionGrouping:e.resetTransactionGrouping,toolbarStyleState:e.toolbarStyleState,selectionCollapsed:()=>ga(e.state.selection),selectedImageRun:e.selectedImageRun,openLinkDialog:t=>e.setLinkDialog({isOpen:!0,initialHref:t}),openImageAltDialog:t=>e.setImageAltDialog({isOpen:!0,initialAlt:t}),openImageCaptionDialog:t=>e.setImageCaptionDialog({isOpen:!0,initialCaption:t}),openFontDialog:()=>{e.setFontDialog({isOpen:!0,initial:PS(e.toolbarStyleState())})},openParagraphDialog:t=>{e.setParagraphDialog({isOpen:!0,initial:{...RS(e.toolbarStyleState()),defaultTabStop:e.state.document.settings?.defaultTabStop??36,...void 0!==t?{tabsOnly:!0,selectedTabPosition:t}:{}}})},imageCaptionLabel:()=>e.locale().startsWith("en")?"Figure":"Figura"});return{commandsController:t,keyboardCommandsController:{...t,applyBooleanStyleCommand:t=>e.applyBooleanStyleCommand(t)}}}(e)}function MS(e){return()=>{e.isDirty()?e.requestConfirmation():e.resetDocument()}}function OS(e){const t=e.document.settings?.defaultTabStop;return("number"==typeof t&&Number.isFinite(t)&&t>0?t:36)*Ho}function BS(e,t){const n=ko(e);if(!n.length)return e;const r=Ri(e,n),o=OS(e);let a=!1;const i=n.map((n,i)=>{if(i<r.startIndex||i>r.endIndex)return n;if(n.list){const e=n.list.level??0,r=Math.max(0,Math.min(8,e+t));return r===e?n:(a=!0,$e(n,r))}const s=ti(n.style,e.document.styles).indentLeft??0;if(t<0&&s<=0)return n;const l=t<0?Math.max(0,s-o):s+o;return l!==s&&Number.isFinite(l)?(a=!0,{...n,style:{...n.style,indentLeft:l}}):n});return a?Vt(e,i,e.selection):e}function FS(e,t){const n=ko(e);if(!n.length)return e;const r=Ri(e,n);if(!r.isCollapsed||0!==r.startParagraphOffset)return e;const o=n[r.startIndex];if(!o||o.list)return e;const a=ti(o.style,e.document.styles),i=a.indentFirstLine??0,s=a.indentHanging??0;if(t>0&&(0!==i||0!==s))return BS(e,1);if(t<0&&i<=0)return e;const l=t>0?OS(e):Math.max(0,i-OS(e)),c=n.map((e,t)=>t===r.startIndex?{...e,style:{...e.style,indentFirstLine:l,indentHanging:0}}:e);return Vt(e,c,e.selection)}function ES(e){const t=ko(e);if(!t.length)return null;const n=Ri(e,t);if(!n.isCollapsed||0!==n.startParagraphOffset)return null;const r=t[n.startIndex];if(!r||r.list)return null;const o=ti(r.style,e.document.styles);return(o.indentLeft??0)>0?"paragraph":(o.indentFirstLine??0)>0&&(o.indentHanging??0)<=0?"firstLine":null}function DS(e){const t=ES(e);return"paragraph"===t?BS(e,-1):"firstLine"===t?FS(e,-1):e}var LS=class{bindings=/* @__PURE__ */new Map;register(e){this.bindings.set(e.id,e)}unregister(e){this.bindings.delete(e)}getBindings(){return Array.from(this.bindings.values())}execute(e,t,n){const r=e.ctrlKey||e.metaKey,o=e.key.toLowerCase();for(const a of this.bindings.values())if(a.key.toLowerCase()===o&&Boolean(a.ctrlOrMeta)===r&&Boolean(a.shift)===e.shiftKey&&Boolean(a.alt)===e.altKey){if(a.command&&n)return n.canExecuteCommand?.(a.command)??!0?(n.executeCommand(a.command),e.preventDefault(),!0):(e.preventDefault(),!0);if(!1!==a.execute(t,e))return e.preventDefault(),!0}return!1}},NS=[{id:"newDocument",command:"newDocument",key:"n",ctrlOrMeta:!0,execute:()=>!0},{id:"print",command:"print",key:"p",ctrlOrMeta:!0,execute:()=>!0},{id:"selectAll",command:"selectAll",key:"a",ctrlOrMeta:!0,execute:e=>{const t=e.state(),n=ko(t);if(0===n.length)return!1;const r=n[0],o=n[n.length-1];return e.clearPreferredColumn(),e.applyState(ji(t,{anchor:xi(r,0),focus:xi(o,mi(o).length)})),e.focusInput(),!0}},{id:"editImageAlt",command:"editImageAlt",key:"a",ctrlOrMeta:!0,alt:!0,execute:e=>!!e.selectedImageRun()&&(e.commandsController.promptForImageAlt(),!0)},{id:"insertFootnote",command:"insertFootnote",key:"f",ctrlOrMeta:!0,alt:!0,execute:e=>(e.commandsController.applyInsertFootnoteCommand(),!0)},{id:"pastePlainText",command:"pastePlainText",key:"v",ctrlOrMeta:!0,shift:!0,execute:e=>(e.setForcePlainTextPaste(!0),e.focusInput(),!0)},{id:"bold",command:"bold",key:"b",ctrlOrMeta:!0,execute:e=>(e.commandsController.applyBooleanStyleCommand("bold"),!0)},{id:"italic",command:"italic",key:"i",ctrlOrMeta:!0,execute:e=>(e.commandsController.applyBooleanStyleCommand("italic"),!0)},{id:"underline",command:"underline",key:"u",ctrlOrMeta:!0,execute:e=>(e.commandsController.applyBooleanStyleCommand("underline"),!0)},{id:"link",command:"link",key:"k",ctrlOrMeta:!0,execute:e=>(e.commandsController.promptForLink(),!0)},{id:"orderedList",command:"orderedList",key:"7",ctrlOrMeta:!0,shift:!0,execute:e=>(e.commandsController.applyParagraphListCommand("ordered"),!0)},{id:"bulletList",command:"bulletList",key:"8",ctrlOrMeta:!0,shift:!0,execute:e=>(e.commandsController.applyParagraphListCommand("bullet"),!0)},{id:"updateSelectedFields",command:"updateSelectedFields",key:"F9",execute:e=>!!e.executeCommand&&(!1!==e.canExecuteCommand?.("updateSelectedFields")&&e.executeCommand("updateSelectedFields"),!0)},{id:"repeatLastAction",command:"repeatLastAction",key:"F4",ctrlOrMeta:!1,execute:e=>(e.executeCommand?.("repeatLastAction"),!0)},{id:"find",command:"find",key:"f",ctrlOrMeta:!0,execute:e=>(e.toggleFindReplace(!0),!0)},{id:"commandSearch",command:"openCommandSearch",key:"q",alt:!0,execute:e=>(e.toggleCommandSearch(!0),!0)},{id:"replace",command:"replace",key:"h",ctrlOrMeta:!0,execute:e=>(e.toggleReplace(!0),!0)},{id:"undo",command:"undo",key:"z",ctrlOrMeta:!0,execute:e=>(e.performUndo(),!0)},{id:"redo",command:"redo",key:"z",ctrlOrMeta:!0,shift:!0,execute:e=>(e.performRedo(),!0)},{id:"redoAlternative",command:"redo",key:"y",ctrlOrMeta:!0,execute:e=>(e.performRedo(),!0)},{id:"pageBreak",command:"pageBreak",key:"Enter",ctrlOrMeta:!0,execute:e=>(e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>xr(e))),e.focusInput(),!0)},{id:"lineBreak",command:"lineBreak",key:"Enter",shift:!0,execute:e=>(e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>Ju(e,"\n"))),e.focusInput(),!0)},{id:"columnBreak",command:"columnBreak",key:"Enter",ctrlOrMeta:!0,shift:!0,execute:e=>(e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>Qu(e))),e.focusInput(),!0)},{id:"splitBlock",command:"splitBlock",key:"Enter",execute:e=>(e.commandsController.handleListEnter()||(e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>cn(e))),e.focusInput()),!0)}];function zS(e){return function(e){const t=new LS;NS.forEach(e=>t.register(e));const n=n=>{if(n.defaultPrevented)return;const r=e.state();if(e.isReadOnly()){const e=n.key,t=e.toLowerCase(),r="Tab"===e||"ArrowLeft"===e||"ArrowRight"===e||"ArrowUp"===e||"ArrowDown"===e||"Home"===e||"End"===e||"PageUp"===e||"PageDown"===e,o="Shift"===e||"Control"===e||"Meta"===e||"Alt"===e,a=(n.ctrlKey||n.metaKey)&&("a"===t||"c"===t);return void(r||o||a||n.preventDefault())}if(n.isComposing||229===n.keyCode)return;if((" "===n.key||"ArrowUp"===n.key||"ArrowDown"===n.key)&&!n.ctrlKey&&!n.metaKey&&!n.altKey&&!n.shiftKey&&ga(r.selection)){const t=r.selection.focus,o=ko(r).find(e=>e.id===t.paragraphId),a=o?.runs.find(e=>e.id===t.runId),i=[...o?.sdtWrappers??[],...a?.sdtWrappers??[]].at(-1),s=i?.sdtPr.subtype;let l;if(" "===n.key&&"checkbox"===s?.kind)l=s.checked?"0":"1";else if("ArrowUp"!==n.key&&"ArrowDown"!==n.key||"dropDownList"!==s?.kind)l=void 0;else{const e=s.listItems??[],t=o?.runs.filter(e=>!a?.sdtWrappers?.some(e=>e.groupId===i?.groupId)||e.sdtWrappers?.some(e=>e.groupId===i?.groupId)).map(e=>e.text).join(""),r=void 0!==s.lastSelectedValue?e.findIndex(e=>(e.value??e.displayText??"")===s.lastSelectedValue):e.findIndex(e=>(e.displayText??e.value??"")===t),c=e[r<0?"ArrowDown"===n.key?0:e.length-1:r+("ArrowDown"===n.key?1:-1)];l=c?.value??c?.displayText}const c=" "===n.key&&"checkbox"===s?.kind||("ArrowUp"===n.key||"ArrowDown"===n.key)&&"dropDownList"===s?.kind;if(i&&c)return n.preventDefault(),void(r.trackChangesEnabled||void 0===l||(e.resetTransactionGrouping(),e.applyTransactionalState(e=>za(e,i.groupId,l)),e.clearPreferredColumn(),e.focusInput()))}const o=e.executeCommand?{executeCommand:(t,n)=>e.executeCommand?.(t,n),canExecuteCommand:(t,n)=>e.canExecuteCommand?.(t,n)}:void 0;if(!t.execute(n,e,o)){if((n.ctrlKey||n.metaKey)&&!n.altKey){if(("ArrowLeft"===n.key||"ArrowRight"===n.key)&&(n.preventDefault(),e.resetTransactionGrouping(),e.moveSelectionByWord("ArrowLeft"===n.key?"left":"right",n.shiftKey)))return void e.focusInput();if("Backspace"===n.key||"Delete"===n.key){if(n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping(),!ga(r.selection))return e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>ap(e))),n.currentTarget.value="",void e.focusInput();const t=ko(r),o=t[t.findIndex(e=>e.id===r.selection.focus.paragraphId)];if(!o)return n.currentTarget.value="",void e.focusInput();if("Backspace"===n.key&&o.list&&0===wa(o,r.selection.focus))return e.applySelectionAwareParagraphCommand(e=>SS(e)),n.currentTarget.value="",void e.focusInput();const a=wa(o,r.selection.focus),i=mi(o),s="Backspace"===n.key?nr(i,a):En(i,a);return"Backspace"===n.key?0===a||s===a?e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>ap(e))):e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(ji(t,{anchor:xi(o,s),focus:xi(o,a)}),e=>ap(e))):a>=i.length?e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>ip(e))):s>a?e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(ji(t,{anchor:xi(o,a),focus:xi(o,s)}),e=>ap(e))):e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>ip(e))),n.currentTarget.value="",void e.focusInput()}}if("Home"===n.key||"End"===n.key){n.preventDefault(),e.resetTransactionGrouping();const t="Home"===n.key?"start":"end";return n.ctrlKey||n.metaKey?e.moveSelectionToDocumentBoundary(t,n.shiftKey):e.moveSelectionToParagraphBoundary(t,n.shiftKey),void e.focusInput()}if(!n.altKey||n.ctrlKey||n.metaKey||"ArrowUp"!==n.key&&"ArrowDown"!==n.key||(n.preventDefault(),e.resetTransactionGrouping(),e.clearPreferredColumn(),!e.moveSelectedImageByParagraph("ArrowUp"===n.key?-1:1)))switch(n.key){case"Backspace":return e.commandsController.handleListBoundaryBackspace(n)?void n.preventDefault():n.altKey||n.ctrlKey||n.metaKey||!ES(r)?(n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>ap(e))),n.currentTarget.value="",void e.focusInput()):(n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping(),!1!==e.canExecuteCommand?.("outdent")&&e.applySelectionAwareParagraphCommand(DS),n.currentTarget.value="",void e.focusInput());case"Delete":return n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>ip(e))),n.currentTarget.value="",void e.focusInput();case"Tab":return void function(e,t,n){const r=t.selection.focus.paragraphId,o=qo(t.document,r),a=!!o&&Boolean(xo(t.document,r,o.sectionIndex)),i=ko(t);if(!i.length)return;const s=Ri(t,i),l=i[s.startIndex];if(!l)return;const c=!s.isCollapsed&&(s.startIndex!==s.endIndex||0===s.startParagraphOffset&&s.endParagraphOffset===oi(l)),d=ti(l.style,t.document.styles),u=s.isCollapsed&&0===s.startParagraphOffset&&!l.list,p=e.autoTabIndentEnabled?.()??!0,f=function(e){if(e.alt||e.ctrl||e.meta){const t=!e.meta&&!e.shift&&(e.ctrl&&!e.alt||e.isMac&&e.alt&&!e.ctrl);return e.inTable&&t?"insertLiteralTab":"passThrough"}return e.inTable?"navigateCell":e.reverseFirstLineIndent||!e.shift&&e.autoIndentAtStart?"changeFirstLineIndent":e.shift||e.wholeParagraphs||e.atListStart||e.atWrappedLineStart?"changeParagraphIndent":"insertLiteralTab"}({inTable:a,shift:n.shiftKey,ctrl:n.ctrlKey,meta:n.metaKey,alt:n.altKey,isMac:e.isMacPlatform?.()??!1,atWrappedLineStart:p&&s.isCollapsed&&s.startParagraphOffset>0&&!a&&!n.shiftKey&&!n.ctrlKey&&!n.metaKey&&!n.altKey&&(e.isCaretAtWrappedLineStart?.()??!1),wholeParagraphs:c,atListStart:Boolean(l.list)&&s.isCollapsed&&0===s.startParagraphOffset,autoIndentAtStart:p&&u&&mi(l).length>0,reverseFirstLineIndent:n.shiftKey&&p&&u&&(d.indentLeft??0)<=0&&(d.indentFirstLine??0)>0});if("passThrough"!==f){switch(n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping(),f){case"insertLiteralTab":{const t=Na(e.pendingCaretTextStyle?.());e.applyTransactionalState(n=>e.applyTableAwareParagraphEdit(n,e=>Ju(e,"\t",t)));break}case"navigateCell":{const o=n.shiftKey?-1:1,a=e.resolveTableTabTarget?.(t.document,r,o);if("adjacent"===a?.kind)e.applySelectionPreservingStructure(a.selection);else if("afterLast"===a?.kind&&1===o&&e.appendTableRowForTab&&!1!==e.canExecuteCommand?.("tableInsertRowAfter"))e.applyTransactionalState(e.appendTableRowForTab);else if(!a){const n=e.resolveAdjacentTableCellPosition(t.document,r,o);n&&e.applySelectionPreservingStructure({anchor:n,focus:n})}break}case"changeFirstLineIndent":case"changeParagraphIndent":{const t=n.shiftKey?"outdent":"indent";if(!1===e.canExecuteCommand?.(t))break;e.applySelectionAwareParagraphCommand(e=>"changeFirstLineIndent"===f?FS(e,n.shiftKey?-1:1):BS(e,n.shiftKey?-1:1));break}}n.currentTarget.value="",e.focusInput()}}(e,r,n);case"ArrowLeft":return n.preventDefault(),e.resetTransactionGrouping(),n.shiftKey?(e.clearPreferredColumn(),e.applyState($i(r,-1))):(e.clearPreferredColumn(),e.applyState(Ui(r))),void e.focusInput();case"ArrowRight":return n.preventDefault(),e.resetTransactionGrouping(),n.shiftKey?(e.clearPreferredColumn(),e.applyState(function(e){return $i(e,1)}(r))):(e.clearPreferredColumn(),e.applyState(Vi(r))),void e.focusInput();case"ArrowUp":return n.preventDefault(),e.resetTransactionGrouping(),void(n.shiftKey?e.moveVerticalSelection(-1,!0)||(e.applyState(function(e){return Hi(e,-1)}(r)),e.focusInput()):e.moveVerticalByBlock(-1)||(e.applyState(function(e){return zi(e,-1)}(r)),e.focusInput()));case"ArrowDown":return n.preventDefault(),e.resetTransactionGrouping(),void(n.shiftKey?e.moveVerticalSelection(1,!0)||(e.applyState(function(e){return Hi(e,1)}(r)),e.focusInput()):e.moveVerticalByBlock(1)||(e.applyState(function(e){return zi(e,1)}(r)),e.focusInput()));default:return}}};return{handleKeyDown:n,registry:t}}(e)}var $S=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown","Escape"];var HS={oasis:{color:"#0f766e",heading:"#115e59",body:"#1f2937"},office:{color:"#4472c4",heading:"#2f5597",body:"#1f2937"},facet:{color:"#8064a2",heading:"#604a7b",body:"#262626"},integral:{color:"#70ad47",heading:"#548235",body:"#1f2937"},ion:{color:"#ed7d31",heading:"#c55a11",body:"#262626"},retrospect:{color:"#5b9bd5",heading:"#2f75b5",body:"#1f2937"}},WS={oasis:{color:"#0f766e",heading:"#115e59"},office:{color:"#4472c4",heading:"#2f5597"},monochrome:{color:"#374151",heading:"#111827"},warm:{color:"#c2410c",heading:"#9a3412"}},jS={aptos:["Aptos, sans-serif","Aptos Display, sans-serif"],calibri:["Calibri, sans-serif","Calibri Light, sans-serif"],georgia:["Georgia, serif","Georgia, serif"],garamond:["Garamond, serif","Garamond, serif"]};function US(e,t){const n={...e.document.design??{},...t};return{...e,document:{...e.document,design:n}}}function VS(e,t){return function(e,t){const n=HS[t],r=e.document.styles??{},o=Object.fromEntries(Object.entries(r).map(([e,t])=>{if(!/^(normal|title|subtitle|heading[1-9]|quote|intensequote)$/i.test(e))return[e,t];const r=/^heading[1-9]$/i.test(e)||/title|quote/i.test(e);return[e,{...t,textStyle:{...t.textStyle??{},color:r?n.heading:n.body,...r?{fontFamily:"Aptos Display, sans-serif"}:{fontFamily:"Aptos, sans-serif"}}}]}));return{...e,document:{...e.document,design:{...e.document.design??{},themeId:t,colorSchemeId:t,themeData:{...e.document.design?.themeData??{},sourceXml:void 0,colors:{...e.document.design?.themeData?.colors??{},accent1:n.color,accent2:n.heading,dk2:n.body},fonts:{...e.document.design?.themeData?.fonts??{},major:{...e.document.design?.themeData?.fonts?.major??{},majorHAnsi:"Aptos Display"},minor:{...e.document.design?.themeData?.fonts?.minor??{},minorHAnsi:"Aptos"}}}},styles:o}}}(e,t)}function KS(e){return null==e||""===e?null:!0===e||"true"===e||1===e}function _S(e){return null==e||""===e?null:"string"==typeof e?e:String(e)}function XS(e){return null!=e&&""!==e?Number(e):null}function qS({gate:e,style:t,selection:n,history:r,formatting:o,dialog:a,link:i,command:s,valueCommand:l,actionCommand:c}){const d=t.state;return{selectAll:s("selectAll",o.selectAll),selectWord:s("selectWord",o.selectWord),selectSentence:s("selectSentence",o.selectSentence),selectParagraph:s("selectParagraph",o.selectParagraph),selectCollapse:c("selectCollapse",e=>{const t=e??{};o.selectCollapse(Boolean(t.end))}),selectText:l("selectText",e=>{const t=e??{};return o.selectText(t.text??"",null==t.occurrence?1:Number(t.occurrence))},()=>""),selectRange:c("selectRange",e=>{const t=e??{};t.anchor&&t.focus&&o.selectRange(t.anchor,t.focus)}),insertFootnote:s("insertFootnote",o.insertFootnote),setNoteOptions:c("setNoteOptions",e=>{const t=e??{},n="endnote"===t.kind?"endnote":"footnote";o.setNoteOptions({kind:n,...void 0!==t.numberFormat?{numberFormat:t.numberFormat}:{},...void 0!==t.startAt?{startAt:XS(t.startAt)}:{},...void 0!==t.restart?{restart:t.restart}:{}})},()=>({value:o.getNoteOptions("footnote")})),insertTableOfContents:s("insertTableOfContents",o.insertTableOfContents),updateTableOfContents:s("updateTableOfContents",o.updateTableOfContents,()=>({isEnabled:e.isCommandEnabled("updateTableOfContents")&&o.hasTableOfContents()})),insertText:c("insertText",e=>{const t="object"==typeof e&&null!==e&&"text"in e?e:{text:e};o.insertText(String(t.text??""),"string"==typeof t.fontFamily?t.fontFamily:null)}),insertEquation:c("insertEquation",e=>{o.insertEquation(e)}),updateEquation:c("updateEquation",e=>{const t=e;o.updateEquation(t.runId,t.expression)}),pastePlainText:s("pastePlainText",o.pastePlainText),formatPainter:s("formatPainter",o.formatPainterOnce,()=>({isEnabled:e.isCommandEnabled("formatPainter")&&o.canCaptureFormatPainter(),isActive:null!==o.formatPainterMode()})),formatPainterContinuous:s("formatPainterContinuous",o.formatPainterContinuous,()=>({isEnabled:e.isCommandEnabled("formatPainterContinuous")&&o.canCaptureFormatPainter(),isActive:"continuous"===o.formatPainterMode()})),cancelFormatPainter:s("cancelFormatPainter",o.cancelFormatPainter,()=>({isEnabled:null!==o.formatPainterMode()})),bold:s("bold",o.bold,()=>({isActive:Boolean(d().bold)})),italic:s("italic",o.italic,()=>({isActive:Boolean(d().italic)})),underline:s("underline",o.underline,()=>({isActive:Boolean(d().underline)})),doubleUnderline:s("doubleUnderline",o.doubleUnderline,()=>({isActive:"double"===d().underlineStyle})),wordUnderline:s("wordUnderline",o.wordUnderline,()=>({isActive:"words"===d().underlineStyle})),strike:s("strike",o.strike,()=>({isActive:Boolean(d().strike)})),doubleStrike:s("doubleStrike",o.doubleStrike,()=>({isActive:Boolean(d().doubleStrike)})),smallCaps:s("smallCaps",o.smallCaps,()=>({isActive:Boolean(d().smallCaps)})),allCaps:s("allCaps",o.allCaps,()=>({isActive:Boolean(d().allCaps)})),hidden:s("hidden",o.hidden,()=>({isActive:Boolean(d().hidden)})),noProof:s("noProof",o.noProof,()=>({isActive:Boolean(d().noProof)})),webHidden:s("webHidden",o.webHidden,()=>({isActive:Boolean(d().webHidden)})),specVanish:s("specVanish",o.specVanish,()=>({isActive:Boolean(d().specVanish)})),contextualAlternates:s("contextualAlternates",o.contextualAlternates,()=>({isActive:Boolean(d().contextualAlternates)})),characterBorder:s("characterBorder",o.toggleCharacterBorder,()=>({isActive:Boolean(d().characterBorder)})),shadow:s("shadow",o.shadow,()=>({isActive:Boolean(d().shadow)})),emboss:s("emboss",o.emboss,()=>({isActive:Boolean(d().emboss)})),engrave:s("engrave",o.engrave,()=>({isActive:Boolean(d().imprint)})),outline:s("outline",o.outline,()=>({isActive:Boolean(d().outline)})),superscript:s("superscript",o.superscript,()=>({isActive:Boolean(d().superscript)})),subscript:s("subscript",o.subscript,()=>({isActive:Boolean(d().subscript)})),link:s("link",()=>(i.prompt(),!0),()=>({isEnabled:e.isCommandEnabled("link")&&i.canPrompt(),isActive:Boolean(d().link)})),alignLeft:s("alignLeft",o.alignLeft,()=>({isActive:"left"===d().align})),alignCenter:s("alignCenter",o.alignCenter,()=>({isActive:"center"===d().align})),alignRight:s("alignRight",o.alignRight,()=>({isActive:"right"===d().align})),alignJustify:s("alignJustify",o.alignJustify,()=>({isActive:"justify"===d().align})),orderedList:s("orderedList",o.orderedList,()=>({isActive:"ordered"===d().listKind})),bulletList:s("bulletList",o.bulletList,()=>({isActive:"bullet"===d().listKind})),find:s("find",o.find),replace:s("replace",o.replace),replaceAll:c("replaceAll",e=>{const t=e??{};"string"==typeof t.search&&t.search.length>0&&o.replaceAll(t)}),setReviewDisplayMode:l("setReviewDisplayMode",e=>{const t="string"==typeof e?e:e?.mode;return("all"===t||"final"===t||"original"===t||"simple"===t)&&o.setReviewDisplayMode(t)},()=>o.reviewDisplayMode()),toggleTrackChanges:s("toggleTrackChanges",o.toggleTrackChanges,()=>({isActive:o.isTrackChangesEnabled()})),toggleRevisionMarkup:s("toggleRevisionMarkup",o.toggleRevisionMarkup,()=>({isActive:o.areRevisionMarkupVisible()})),showMarkupOptions:l("showMarkupOptions",()=>!1,()=>o.showMarkupOptions()),applyShowMarkup:c("applyShowMarkup",e=>{o.applyShowMarkup(e??{})}),toggleOutlinePanel:s("toggleOutlinePanel",o.toggleOutlinePanel,()=>({isActive:o.areOutlineVisible()})),toggleRevisionsPanel:s("toggleRevisionsPanel",o.toggleRevisionsPanel,()=>({isActive:o.areRevisionsPanelVisible()})),acceptRevisions:s("acceptRevisions",o.acceptRevisions,()=>({isEnabled:e.isCommandEnabled("acceptRevisions")&&o.hasRevisionsInSelection()})),rejectRevisions:s("rejectRevisions",o.rejectRevisions,()=>({isEnabled:e.isCommandEnabled("rejectRevisions")&&o.hasRevisionsInSelection()})),acceptAllRevisions:s("acceptAllRevisions",o.acceptAllRevisions,()=>({isEnabled:e.isCommandEnabled("acceptAllRevisions")&&o.hasRevisionsInDocument()})),rejectAllRevisions:s("rejectAllRevisions",o.rejectAllRevisions,()=>({isEnabled:e.isCommandEnabled("rejectAllRevisions")&&o.hasRevisionsInDocument()})),requestAcceptAllRevisions:s("requestAcceptAllRevisions",()=>(a.requestAcceptAllRevisions(),!0),()=>({isEnabled:e.isCommandEnabled("requestAcceptAllRevisions")&&o.hasRevisionsInDocument()})),requestRejectAllRevisions:s("requestRejectAllRevisions",()=>(a.requestRejectAllRevisions(),!0),()=>({isEnabled:e.isCommandEnabled("requestRejectAllRevisions")&&o.hasRevisionsInDocument()})),nextRevision:s("nextRevision",o.navigateRevisionNext,()=>({isEnabled:e.isCommandEnabled("nextRevision")&&o.hasNavigableRevisions()})),previousRevision:s("previousRevision",o.navigateRevisionPrevious,()=>({isEnabled:e.isCommandEnabled("previousRevision")&&o.hasNavigableRevisions()})),newComment:s("newComment",o.newComment,()=>({isEnabled:e.isCommandEnabled("newComment")&&o.canCreateComment()})),replyComment:s("replyComment",o.replyComment,()=>({isEnabled:e.isCommandEnabled("replyComment")&&o.canReplyToComment()})),toggleCommentsPanel:s("toggleCommentsPanel",o.toggleCommentsPanel,()=>({isEnabled:e.isCommandEnabled("toggleCommentsPanel"),isActive:o.isCommentsPanelOpen()})),editComment:s("editComment",o.editComment,()=>({isEnabled:e.isCommandEnabled("editComment")&&o.canEditComment()})),nextComment:s("nextComment",o.navigateCommentNext,()=>({isEnabled:e.isCommandEnabled("nextComment")&&o.hasNavigableComments()})),previousComment:s("previousComment",o.navigateCommentPrevious,()=>({isEnabled:e.isCommandEnabled("previousComment")&&o.hasNavigableComments()})),resolveComment:s("resolveComment",o.resolveSelectedComment,()=>({isEnabled:e.isCommandEnabled("resolveComment")&&o.canManageSelectedComment()&&!o.isSelectedCommentResolved()})),reopenComment:s("reopenComment",o.reopenSelectedComment,()=>({isEnabled:e.isCommandEnabled("reopenComment")&&o.canManageSelectedComment()&&o.isSelectedCommentResolved()})),deleteComment:s("deleteComment",o.deleteSelectedComment,()=>({isEnabled:e.isCommandEnabled("deleteComment")&&o.canDeleteSelectedComment()})),toggleShowMargins:s("toggleShowMargins",o.toggleShowMargins,()=>({isActive:o.areMarginsVisible()})),toggleShowParagraphMarks:s("toggleShowParagraphMarks",o.toggleShowParagraphMarks,()=>({isActive:o.areParagraphMarksVisible()})),togglePreciseFonts:s("togglePreciseFonts",o.togglePreciseFonts,()=>(Oe(),{isActive:Sr()})),undo:s("undo",r.undo,()=>({isEnabled:e.isCommandEnabled("undo")&&r.canUndo()})),redo:s("redo",r.redo,()=>({isEnabled:e.isCommandEnabled("redo")&&r.canRedo()})),pageBreak:s("pageBreak",o.pageBreak),lineBreak:s("lineBreak",o.lineBreak),columnBreak:s("columnBreak",o.columnBreak),splitBlock:s("splitBlock",o.splitBlock),insertNonBreakingSpace:s("insertNonBreakingSpace",()=>o.insertSpecialChar("nbsp")),insertNonBreakingHyphen:s("insertNonBreakingHyphen",()=>o.insertSpecialChar("nbHyphen")),insertOptionalHyphen:s("insertOptionalHyphen",()=>o.insertSpecialChar("optionalHyphen")),insertEmDash:s("insertEmDash",()=>o.insertSpecialChar("emDash")),insertEllipsis:s("insertEllipsis",()=>o.insertSpecialChar("ellipsis")),insertCopyright:s("insertCopyright",()=>o.insertSpecialChar("copyright")),insertRegistered:s("insertRegistered",()=>o.insertSpecialChar("registered")),insertTrademark:s("insertTrademark",()=>o.insertSpecialChar("trademark")),setFontFamily:l("setFontFamily",e=>o.setFontFamily(e||null),()=>d().fontFamily),setFontSize:l("setFontSize",e=>{const t=e&&"object"==typeof e&&"size"in e?e.size:e;if(null==t||""===t)return o.setFontSize(null);if("string"!=typeof t&&"number"!=typeof t)return!1;const n=Qn(t);return null!==n&&o.setFontSize(n)},()=>ct(d().fontSize)),increaseFontSize:s("increaseFontSize",o.increaseFontSize),decreaseFontSize:s("decreaseFontSize",o.decreaseFontSize),growFont1:s("growFont1",o.growFont1),shrinkFont1:s("shrinkFont1",o.shrinkFont1),changeTextCase:c("changeTextCase",e=>{o.changeTextCase(e??"sentence")},()=>({isEnabled:e.isCommandEnabled("changeTextCase")&&!n.isCollapsed()})),clearFormatting:s("clearFormatting",o.clearFormatting),setColor:l("setColor",e=>o.setColor(e??null),()=>d().color||null),setHighlight:l("setHighlight",e=>o.setHighlight(e??null),()=>d().highlight||null),setTextShading:l("setTextShading",e=>o.setTextShading(e??null),()=>d().textShading||null),setStyleId:l("setStyleId",e=>o.setStyleId(String(e)),()=>{const e=d();return e.mixedParagraphStyles?"":e.styleId||"normal"}),setCharacterStyleId:l("setCharacterStyleId",e=>o.setCharacterStyleId(String(e)),()=>d().characterStyleId||""),applyUnderlineStyle:l("applyUnderlineStyle",e=>(o.applyUnderlineStyle(e),!0),()=>d().underlineStyle),setUnderlineStyle:l("setUnderlineStyle",e=>(o.setUnderlineStyle(e||null),!0),()=>d().underlineStyle),setUnderlineColor:l("setUnderlineColor",e=>o.setUnderlineColor(e||null),()=>d().underlineColor),setCharacterScale:l("setCharacterScale",e=>o.setCharacterScale(XS(e)),()=>d().characterScale),setCharacterSpacing:l("setCharacterSpacing",e=>o.setCharacterSpacing(XS(e)),()=>d().characterSpacing),setRunSnapToGrid:l("setRunSnapToGrid",e=>o.setRunSnapToGrid(KS(e)),()=>d().snapToGrid),setFitText:l("setFitText",e=>o.setFitText(XS(e)),()=>d().fitText),setBaselineShift:l("setBaselineShift",e=>o.setBaselineShift(XS(e)),()=>d().baselineShift),setEmphasisMark:l("setEmphasisMark",e=>o.setEmphasisMark(e||null),()=>d().emphasisMark),setTextEffect:l("setTextEffect",e=>o.setTextEffect(e||null),()=>d().textEffect),setKerning:l("setKerning",e=>o.setKerning(XS(e)),()=>d().kerningThreshold),setLigatures:l("setLigatures",e=>o.setLigatures(e||null),()=>d().ligatures),setNumberSpacing:l("setNumberSpacing",e=>o.setNumberSpacing(e||null),()=>d().numberSpacing),setNumberForm:l("setNumberForm",e=>o.setNumberForm(e||null),()=>d().numberForm),setStylisticSet:l("setStylisticSet",e=>o.setStylisticSet(XS(e)),()=>d().stylisticSet)}}function GS({gate:e,style:t,document:n,link:r,image:o,browser:a,actionCommand:i}){const s=t.state;return{documentStyles:i("documentStyles",()=>{},()=>({isEnabled:!0,value:n.documentStyles()})),print:i("print",()=>n.printDocument(),()=>({isEnabled:!0})),paste:i("paste",()=>a.paste(),()=>({isEnabled:e.isCommandEnabled("paste")&&a.canPaste()})),pasteAsPlainText:i("pasteAsPlainText",()=>a.pasteAsPlainText(),()=>({isEnabled:e.isCommandEnabled("pasteAsPlainText")&&a.canPaste()})),cut:i("cut",()=>a.cut(),()=>({isEnabled:e.isCommandEnabled("cut")&&a.hasSelection()&&a.canCut()})),pasteMergeFormatting:i("pasteMergeFormatting",()=>a.pasteMergeFormatting(),()=>({isEnabled:e.isCommandEnabled("pasteMergeFormatting")&&a.canPaste()})),copy:i("copy",()=>a.copy(),()=>({isEnabled:e.isCommandEnabled("copy")&&a.hasSelection()})),newDocument:i("newDocument",()=>n.newDocument()),saveDocument:i("saveDocument",()=>n.saveDocument()),exportDocx:i("exportDocx",()=>n.exportDocx()),exportPdf:i("exportPdf",()=>n.exportPdf()),importDocument:i("importDocument",()=>n.importDocument()),insertHtml:i("insertHtml",e=>{if(!e||"object"!=typeof e||"string"!=typeof e.html)throw new TypeError("insertHtml requires a payload with a string html property.");n.insertHtml(e.html)}),insertImage:i("insertImage",()=>n.insertImage()),insertShape:i("insertShape",e=>n.insertShape(String(e))),setShapeFill:i("setShapeFill",e=>n.setShapeFill(null==e?null:String(e))),setShapeOutline:i("setShapeOutline",e=>n.setShapeOutline(null==e?null:String(e))),setShapeOutlineWidth:i("setShapeOutlineWidth",e=>n.setShapeOutlineWidth(Number(e))),alignFloatingObject:i("alignFloatingObject",e=>n.alignFloatingObject(e??"center")),reorderFloatingObject:i("reorderFloatingObject",e=>n.reorderFloatingObject(e??"front")),nudgeFloatingObject:i("nudgeFloatingObject",e=>{const t=e??{};n.nudgeFloatingObject(Number(t.dx)||0,Number(t.dy)||0)}),setFloatingFixedPosition:i("setFloatingFixedPosition",e=>n.setFloatingFixedPosition(Boolean(e))),setFloatingRotation:i("setFloatingRotation",e=>n.setFloatingRotation(Number(e))),setFloatingWrapPreset:i("setFloatingWrapPreset",e=>n.setFloatingWrapPreset(e??"square")),setFloatingWrapText:i("setFloatingWrapText",e=>n.setFloatingWrapText(e??"bothSides")),setFloatingPositionPreset:i("setFloatingPositionPreset",e=>n.setFloatingPositionPreset(e??"middleCenter")),setShapePreset:i("setShapePreset",e=>n.setShapePreset(null==e?"rect":String(e))),setTextBoxTextDirection:i("setTextBoxTextDirection",e=>n.setTextBoxTextDirection(e??"horz")),setTextBoxVerticalAlign:i("setTextBoxVerticalAlign",e=>n.setTextBoxVerticalAlign(e??"t")),editTextBoxAlt:i("editTextBoxAlt",e=>n.setTextBoxAlt(null==e?null:String(e))),rotateTextBox:i("rotateTextBox",e=>n.rotateTextBox(e??"left")),textBoxWidthCm:i("textBoxWidthCm",e=>n.setTextBoxWidthCm(Number(e)),()=>({isEnabled:n.isTextBoxSelected(),value:n.getTextBoxSizeCm()?.width??null})),textBoxHeightCm:i("textBoxHeightCm",e=>n.setTextBoxHeightCm(Number(e)),()=>({isEnabled:n.isTextBoxSelected(),value:n.getTextBoxSizeCm()?.height??null})),openSymbolDialog:i("openSymbolDialog",()=>n.openSymbolDialog()),openCommandSearch:i("openCommandSearch",()=>n.openCommandSearch()),repeatLastAction:i("repeatLastAction",()=>n.repeatLastAction()),openEquationDialog:i("openEquationDialog",()=>n.openEquationDialog()),tableProperties:i("tableProperties",e=>n.openTableProperties(e?.activeTab??"table"),()=>({isEnabled:n.hasActiveTable()})),unlink:i("unlink",()=>r.remove(),()=>({isEnabled:e.isCommandEnabled("unlink")&&Boolean(s().link),isActive:Boolean(s().link)})),editImageAlt:i("editImageAlt",()=>o.promptAlt(),()=>({isEnabled:o.isSelected(),isActive:o.isSelected()})),insertImageCaption:i("insertImageCaption",()=>o.promptCaption(),()=>({isEnabled:o.isSelected(),isActive:o.isSelected()})),imageContext:i("imageContext",()=>{},()=>({isEnabled:o.isSelected(),isActive:o.isSelected(),value:null})),imageWidthCm:i("imageWidthCm",e=>o.setWidthCm(Number(e)),()=>({isEnabled:o.isSelected(),value:o.getSizeCm()?.width??null})),imageHeightCm:i("imageHeightCm",e=>o.setHeightCm(Number(e)),()=>({isEnabled:o.isSelected(),value:o.getSizeCm()?.height??null})),imageCrop:i("imageCrop",()=>o.toggleCrop(),()=>({isEnabled:o.isSelected(),isActive:o.isCropActive()})),imageCropAspect:i("imageCropAspect",e=>o.applyCropAspect(String(e)),()=>({isEnabled:o.isSelected()})),imageCropShape:i("imageCropShape",e=>o.applyCropShape(String(e)),()=>({isEnabled:o.isSelected(),value:o.getCropShape()})),imageCropFill:i("imageCropFill",()=>o.applyCropFill(),()=>({isEnabled:o.isSelected()})),imageCropFit:i("imageCropFit",()=>o.applyCropFit(),()=>({isEnabled:o.isSelected()})),imageCropReset:i("imageCropReset",()=>o.resetCrop(),()=>({isEnabled:o.isSelected()})),imageFlip:i("imageFlip",e=>o.flip(e??"horizontal"),()=>({isEnabled:o.isSelected()})),imageRotate:i("imageRotate",e=>o.rotate(e??"left"),()=>({isEnabled:o.isSelected()})),imageBorder:i("imageBorder",e=>o.setBorder(e),()=>({isEnabled:o.isSelected(),value:o.getBorder()})),imageTransparency:i("imageTransparency",e=>o.setTransparency("number"==typeof e?e:null==e?0:Number(e)),()=>({isEnabled:o.isSelected(),value:o.getTransparency()})),resetImage:i("resetImage",()=>o.reset(),()=>({isEnabled:o.canReset()}))}}function YS({style:e,paragraph:t,section:n,valueCommand:r,actionCommand:o}){const a=e.state;return{outdent:o("outdent",()=>t.outdent()),indent:o("indent",()=>t.indent()),moveParagraphsUp:o("moveParagraphsUp",()=>t.moveParagraphsUp(),()=>({isEnabled:t.canMoveParagraphsUp()})),moveParagraphsDown:o("moveParagraphsDown",()=>t.moveParagraphsDown(),()=>({isEnabled:t.canMoveParagraphsDown()})),togglePageBreakBefore:o("togglePageBreakBefore",()=>t.togglePageBreakBefore(),()=>({isActive:Boolean(a().pageBreakBefore)})),toggleKeepWithNext:o("toggleKeepWithNext",()=>t.toggleKeepWithNext(),()=>({isActive:Boolean(a().keepWithNext)})),toggleKeepLinesTogether:o("toggleKeepLinesTogether",()=>t.toggleKeepLinesTogether(),()=>({isActive:Boolean(a().keepLinesTogether)})),toggleWidowControl:o("toggleWidowControl",()=>t.toggleWidowControl(),()=>({isActive:Boolean(a().widowControl)})),toggleParagraphBidi:o("toggleParagraphBidi",()=>t.setBidi(!a().bidi||null),()=>({isActive:Boolean(a().bidi)})),setParagraphBidi:r("setParagraphBidi",e=>(t.setBidi(KS(e)),!0),()=>a().bidi),setParagraphAlign:r("setParagraphAlign",e=>(t.setParagraphAlign(e),!0),()=>a().align),sortParagraphs:o("sortParagraphs",e=>t.sortParagraphs(!0===e||"true"===e||Boolean(e?.descending))),promote:o("promote",()=>t.promote()),demote:o("demote",()=>t.demote()),resetParagraphFormatting:o("resetParagraphFormatting",()=>t.resetParagraphFormatting()),setOutlineLevel:o("setOutlineLevel",e=>{const n=e??void 0,r=null==n||"body"===n||""===n?null:Number(n);t.setOutlineLevel(null===r||Number.isNaN(r)?null:r)},()=>({value:Number(e.state().outlineLevel)||null})),setParagraphTabStops:o("setParagraphTabStops",e=>{const n=e??{};t.setTabStops({...void 0!==n.tabs?{tabs:n.tabs}:{},...void 0!==n.set?{set:n.set}:{},...void 0!==n.clear?{clear:n.clear}:{},...void 0!==n.clearAll?{clearAll:n.clearAll}:{},...void 0!==n.default?{default:n.default}:{}})}),setSpacingAfter:r("setSpacingAfter",e=>(t.setSpacingAfter(XS(e)),!0),()=>a().spacingAfter),setSpacingBefore:r("setSpacingBefore",e=>(t.setSpacingBefore(XS(e)),!0),()=>a().spacingBefore),setContextualSpacing:r("setContextualSpacing",e=>(t.setContextualSpacing(KS(e)),!0),()=>a().contextualSpacing),setLineRule:r("setLineRule",e=>(t.setLineRule(_S(e)),!0),()=>a().lineRule),setTextDirection:r("setTextDirection",e=>(t.setTextDirection(_S(e)),!0),()=>a().textDirection),setSuppressAutoHyphens:r("setSuppressAutoHyphens",e=>(t.setSuppressAutoHyphens(KS(e)),!0),()=>a().suppressAutoHyphens),setSuppressLineNumbers:r("setSuppressLineNumbers",e=>(t.setSuppressLineNumbers(KS(e)),!0),()=>a().suppressLineNumbers),setKinsoku:r("setKinsoku",e=>(t.setKinsoku(KS(e)),!0),()=>a().kinsoku),setOverflowPunct:r("setOverflowPunct",e=>(t.setOverflowPunct(KS(e)),!0),()=>a().overflowPunct),setWordWrap:r("setWordWrap",e=>(t.setWordWrap(KS(e)),!0),()=>a().wordWrap),setAutoSpaceDE:r("setAutoSpaceDE",e=>(t.setAutoSpaceDE(KS(e)),!0),()=>a().autoSpaceDE),setAutoSpaceDN:r("setAutoSpaceDN",e=>(t.setAutoSpaceDN(KS(e)),!0),()=>a().autoSpaceDN),setAdjustRightInd:r("setAdjustRightInd",e=>(t.setAdjustRightInd(KS(e)),!0),()=>a().adjustRightInd),setTopLinePunct:r("setTopLinePunct",e=>(t.setTopLinePunct(KS(e)),!0),()=>a().topLinePunct),setPageBreakBefore:r("setPageBreakBefore",e=>(t.setPageBreakBefore(KS(e)),!0),()=>a().pageBreakBefore),setKeepWithNext:r("setKeepWithNext",e=>(t.setKeepWithNext(KS(e)),!0),()=>a().keepWithNext),setKeepLinesTogether:r("setKeepLinesTogether",e=>(t.setKeepLinesTogether(KS(e)),!0),()=>a().keepLinesTogether),setWidowControl:r("setWidowControl",e=>(t.setWidowControl(KS(e)),!0),()=>a().widowControl),setMirrorIndents:r("setMirrorIndents",e=>(t.setMirrorIndents(KS(e)),!0),()=>a().mirrorIndents),setIndentLeft:r("setIndentLeft",e=>(t.setIndentLeft(XS(e)),!0),()=>a().indentLeft),setIndentRight:r("setIndentRight",e=>(t.setIndentRight(XS(e)),!0),()=>a().indentRight),setIndentFirstLine:r("setIndentFirstLine",e=>(t.setIndentFirstLine(XS(e)),!0),()=>a().indentFirstLine),setIndentHanging:r("setIndentHanging",e=>(t.setIndentHanging(XS(e)),!0),()=>a().indentHanging),setSpecialIndent:o("setSpecialIndent",e=>{const n=e??{};t.setSpecialIndent(n.kind??"none",XS(n.value))},()=>{const e=Number(a().indentFirstLine),t=Number(a().indentHanging),n=Number.isFinite(t)&&t>0?"hanging":Number.isFinite(e)&&e>0?"firstLine":"none";return{isActive:"none"!==n,value:n}}),setParagraphShading:r("setParagraphShading",e=>(t.setShading(e??null),!0),()=>a().shading||"#ffffff"),applyParagraphBorders:o("applyParagraphBorders",()=>t.applyBorders()),applyHorizontalLine:o("applyHorizontalLine",()=>t.addHorizontalLine()),setDropCap:o("setDropCap",e=>{const n=e??{};t.setDropCap(n)},()=>({value:t.hasDropCap()})),setLineHeight:r("setLineHeight",e=>(t.setLineHeight(XS(e)),!0),()=>a().lineHeight),setListFormat:o("setListFormat",e=>t.setListFormat(String(e))),setListStartAt:o("setListStartAt",e=>t.setListStartAt(XS(e))),restartList:o("restartList",e=>{const n=e;t.restartList("number"==typeof n&&Number.isFinite(n)?Math.max(0,Math.floor(n)):void 0)}),continueList:o("continueList",()=>t.continueList()),setListLevel:o("setListLevel",e=>t.setListLevel(XS(e)??0)),toggleOrientation:o("toggleOrientation",()=>n.toggleOrientation(),()=>({isActive:n.isLandscape()})),setOrientation:o("setOrientation",e=>n.setOrientation(e)),sectionBreakNextPage:o("sectionBreakNextPage",()=>n.breakNextPage()),sectionBreakContinuous:o("sectionBreakContinuous",()=>n.breakContinuous()),sectionBreakEvenPage:o("sectionBreakEvenPage",()=>n.breakEvenPage()),sectionBreakOddPage:o("sectionBreakOddPage",()=>n.breakOddPage()),sectionBreakNextColumn:o("sectionBreakNextColumn",()=>n.breakNextColumn()),setPageMargins:o("setPageMargins",e=>{n.setPageMargins(e??{})},()=>({value:n.getMargins()})),setMarginsPreset:o("setMarginsPreset",e=>{"string"==typeof e&&e.length>0&&n.setMarginsPreset(e)}),setSectionPageNumbering:o("setSectionPageNumbering",e=>{const t=e??{};n.setPageNumbering({...void 0!==t.start?{start:Number(t.start)}:{},..."string"==typeof t.format?{format:t.format}:{}})},()=>({value:n.getPageNumbering()})),setPaperSize:o("setPaperSize",e=>{const t=e??{};void 0!==t.widthPt&&void 0!==t.heightPt&&n.setPaperSize({widthPt:Number(t.widthPt),heightPt:Number(t.heightPt)})},()=>({value:n.getPaperSize()})),setPaperSizePreset:o("setPaperSizePreset",e=>{"string"==typeof e&&e.length>0&&n.setPaperSizePreset(e)}),setColumns:o("setColumns",e=>{const t=e??{};void 0!==t.count&&n.setColumns({count:Number(t.count),...void 0!==t.space?{space:Number(t.space)}:{},...void 0!==t.separator?{separator:Boolean(t.separator)}:{}})}),setColumnsPreset:o("setColumnsPreset",e=>{if("string"==typeof e&&e.length>0){const t=Xt(e);if(!t)return;n.setColumns({count:t.count})}}),setSectionVerticalAlign:o("setSectionVerticalAlign",e=>{const t=e??void 0;void 0!==t&&"top"!==t&&"center"!==t&&"both"!==t&&"bottom"!==t||n.setVerticalAlign(t??"top")},()=>({value:n.getVerticalAlign()})),setSectionStart:o("setSectionStart",e=>{const t=e??void 0;void 0!==t&&"nextPage"!==t&&"continuous"!==t&&"evenPage"!==t&&"oddPage"!==t&&"nextColumn"!==t||n.setSectionStart(t??"nextPage")},()=>({value:n.getSectionStart()})),setSectionBidi:o("setSectionBidi",e=>{const t=e??void 0;n.setBidi(t??!0)},()=>({value:n.getBidi()})),setHyphenation:o("setHyphenation",e=>{const t=e??{};n.setHyphenation(t)},()=>({value:n.getHyphenation().value}))}}function ZS({gate:e,headerFooter:t,command:n,actionCommand:r}){return{editHeader:n("editHeader",()=>(t.editHeader(),!0)),editFooter:n("editFooter",()=>(t.editFooter(),!0)),editFirstPageHeader:n("editFirstPageHeader",()=>(t.editFirstPageHeader(),!0)),editEvenPageHeader:n("editEvenPageHeader",()=>(t.editEvenPageHeader(),!0)),editFirstPageFooter:n("editFirstPageFooter",()=>(t.editFirstPageFooter(),!0)),editEvenPageFooter:n("editEvenPageFooter",()=>(t.editEvenPageFooter(),!0)),insertPageNumber:n("insertPageNumber",()=>(t.insertPageNumber(),!0)),insertPageNumberXOfY:n("insertPageNumberXOfY",()=>(t.insertPageNumberXOfY(),!0)),placePageNumberTop:n("placePageNumberTop",()=>(t.placePageNumberTop(),!0)),placePageNumberBottom:n("placePageNumberBottom",()=>(t.placePageNumberBottom(),!0)),exitHeaderFooter:r("exitHeaderFooter",()=>t.exit(),()=>({isEnabled:e.isCommandEnabled("exitHeaderFooter")&&t.isInHeaderFooter()})),setDifferentFirstPage:r("setDifferentFirstPage",e=>{const n=e??void 0;t.setDifferentFirstPage(n??!0)},()=>({value:t.getDifferentFirstPage()})),setDifferentOddEven:r("setDifferentOddEven",e=>{const n=e??void 0;t.setDifferentOddEven(n??!0)},()=>({value:t.getDifferentOddEven()}))}}function JS({bookmark:e,actionCommand:t}){return{insertBookmark:t("insertBookmark",t=>{e.insert("string"==typeof t&&t.trim().length>0?t:void 0)}),removeBookmark:t("removeBookmark",t=>{"string"==typeof t&&e.remove(t)})}}function QS({fields:e,actionCommand:t}){const n=(e,n,r)=>{const o=t(e,()=>{},()=>({isEnabled:n()}));return{...o,execute:e=>!1!==o.refresh?.().isEnabled&&r(e)}};return{markIndexEntry:n("markIndexEntry",()=>!!e.markIndexEntry&&!!e.canMarkIndexEntry?.(),t=>{if(!t||"object"!=typeof t)return!1;const n=t;return!(!Array.isArray(n.path)||!n.path.every(e=>"string"==typeof e)||void 0!==n.identifier&&"string"!=typeof n.identifier||void 0!==n.boldPage&&"boolean"!=typeof n.boldPage||void 0!==n.italicPage&&"boolean"!=typeof n.italicPage)&&(e.markIndexEntry?.(n)??!1)}),insertIndex:n("insertIndex",()=>!!e.insertIndex&&!!e.canInsertIndex?.(),t=>{if(!t||"object"!=typeof t)return!1;const n=t;return"string"==typeof n.locale&&(void 0===n.identifier||"string"==typeof n.identifier)&&(e.insertIndex?.(n)??!1)}),updateIndex:n("updateIndex",()=>!!e.updateIndex&&!!e.canUpdateIndex?.(),t=>{if(void 0!==t&&(!t||"object"!=typeof t||Array.isArray(t)))return!1;const n=t?.locale;return(void 0===n||"string"==typeof n)&&(e.updateIndex?.(n)??!1)}),updateBodyFields:t("updateBodyFields",()=>{e.updateBodyFields?.()},()=>({isEnabled:!!e.updateBodyFields&&(e.canUpdateBodyFields?.()??!0)})),updateSelectedFields:t("updateSelectedFields",()=>{e.updateSelectedFields?.()},()=>({isEnabled:!!e.updateSelectedFields&&(e.canUpdateBodyFields?.()??!0)})),insertFieldCode:n("insertFieldCode",()=>!!e.insertFieldCode,t=>!("string"!=typeof t||!t)&&(e.insertFieldCode?.(t)??!1)),editFieldCode:n("editFieldCode",()=>!!e.editFieldCode,t=>{if(!t||"object"!=typeof t)return!1;const n=t;return"string"==typeof n.instructionRunId&&"string"==typeof n.code&&(e.editFieldCode?.(n.instructionRunId,n.code)??!1)}),editFieldCodeAtSelection:n("editFieldCodeAtSelection",()=>!!e.editFieldCodeAtSelection,t=>!("string"!=typeof t||!t)&&(e.editFieldCodeAtSelection?.(t)??!1)),toggleFieldLock:n("toggleFieldLock",()=>!!e.toggleFieldLock,t=>"string"==typeof t&&(e.toggleFieldLock?.(t)??!1)),toggleFieldCodes:t("toggleFieldCodes",t=>{const n="boolean"==typeof t?t:void 0;e.toggleFieldCodes?.(n??!0)}),nextField:t("nextField",()=>{e.navigateField?.("next")}),previousField:t("previousField",()=>{e.navigateField?.("previous")}),markAuthorityEntry:n("markAuthorityEntry",()=>!!e.markAuthorityEntry,t=>{if(!t||"object"!=typeof t)return!1;const n=t;return!("string"!=typeof n.long||void 0!==n.short&&"string"!=typeof n.short||void 0!==n.category&&"string"!=typeof n.category)&&(e.markAuthorityEntry?.(n)??!1)}),insertTableOfAuthorities:n("insertTableOfAuthorities",()=>!!e.insertTableOfAuthorities,t=>{if(!t||"object"!=typeof t)return!1;const n=t;return"string"==typeof n.locale&&"string"==typeof n.category&&(e.insertTableOfAuthorities?.(n)??!1)}),updateTableOfAuthorities:n("updateTableOfAuthorities",()=>!!e.updateTableOfAuthorities,t=>{if(void 0!==t&&("object"!=typeof t||null===t))return!1;const n=t?.locale;return(void 0===n||"string"==typeof n)&&(e.updateTableOfAuthorities?.(n)??!1)}),insertTableOfFigures:n("insertTableOfFigures",()=>!!e.insertTableOfFigures,t=>{if(!t||"object"!=typeof t)return!1;const n=t;return"string"==typeof n.identifier&&(void 0===n.unlabeled||"boolean"==typeof n.unlabeled)&&(e.insertTableOfFigures?.(n)??!1)}),updateTableOfFigures:n("updateTableOfFigures",()=>!!e.updateTableOfFigures,()=>e.updateTableOfFigures?.()??!1),previewMergeRecord:n("previewMergeRecord",()=>!!e.previewMergeRecord,t=>{if(!t||"object"!=typeof t)return!1;const n=t;return!(!Array.isArray(n.records)||!Number.isInteger(n.index))&&(e.previewMergeRecord?.(n.records,n.index)??!1)}),mergeToNewDocuments:t("mergeToNewDocuments",t=>{const n=t??{};Array.isArray(n.records)&&e.mergeToNewDocuments?.(n.records)}),updateVariableFields:n("updateVariableFields",()=>!!e.updateVariableFields,()=>e.updateVariableFields?.()??!1),setFormFieldValue:n("setFormFieldValue",()=>!!e.setFormFieldValue,t=>{if(!t||"object"!=typeof t)return!1;const n=t;return"string"==typeof n.name&&"string"==typeof n.value&&(e.setFormFieldValue?.(n.name,n.value)??!1)}),setContentControlValue:n("setContentControlValue",()=>!!e.setContentControlValue,t=>{if(!t||"object"!=typeof t)return!1;const n=t;return"string"==typeof n.groupId&&"string"==typeof n.value&&(e.setContentControlValue?.(n.groupId,n.value)??!1)}),mutateRepeatingSectionRow:n("mutateRepeatingSectionRow",()=>!!e.mutateRepeatingSectionRow,t=>{if(!t||"object"!=typeof t)return!1;const n=t;return"string"==typeof n.sectionId&&"string"==typeof n.itemId&&("insertAfter"===n.operation||"remove"===n.operation||"moveUp"===n.operation||"moveDown"===n.operation)&&(e.mutateRepeatingSectionRow?.(n.sectionId,n.itemId,n.operation)??!1)}),toggleFormCheckbox:n("toggleFormCheckbox",()=>!!e.toggleFormCheckbox,t=>"string"==typeof t&&(e.toggleFormCheckbox?.(t)??!1)),insertDateField:t("insertDateField",()=>{e.insertDate()}),insertDateTime:t("insertDateTime",t=>{const n=t??{};e.insertDateTime(n.dateFormat)}),insertCrossReference:t("insertCrossReference",t=>{const n=t??{};if("string"!=typeof n.bookmark||0===n.bookmark.length)return;const r="PAGEREF"===n.type?"PAGEREF":"REF";e.insertCrossReference({type:r,bookmark:n.bookmark})})}}function eC({gate:e,table:t,actionCommand:n,valueCommand:r}){return{tableContext:n("tableContext",()=>{},()=>({isEnabled:t.insideTable(),isActive:t.insideTable(),value:t.selectionLabel()})),tableMerge:n("tableMerge",()=>t.merge(),()=>({isEnabled:e.isCommandEnabled("tableMerge")&&t.canMerge()})),tableSplit:n("tableSplit",()=>t.split(),()=>({isEnabled:e.isCommandEnabled("tableSplit")&&t.canSplit()})),tableToText:n("tableToText",()=>t.convertToText(),()=>({isEnabled:e.isCommandEnabled("tableToText")&&t.canConvertToText()})),textToTable:n("textToTable",()=>t.convertToTable(),()=>({isEnabled:e.isCommandEnabled("textToTable")&&t.canConvertToTable()})),tableSplitAtRow:n("tableSplitAtRow",()=>t.splitTableAtRow(),()=>({isEnabled:e.isCommandEnabled("tableSplitAtRow")&&t.canSplitTableAtRow()})),tableSortAscending:n("tableSortAscending",()=>t.sortTable("ascending"),()=>({isEnabled:e.isCommandEnabled("tableSortAscending")&&t.canSortTable()})),tableSortDescending:n("tableSortDescending",()=>t.sortTable("descending"),()=>({isEnabled:e.isCommandEnabled("tableSortDescending")&&t.canSortTable()})),tableDelete:n("tableDelete",()=>t.deleteTable(),()=>({isEnabled:e.isCommandEnabled("tableDelete")&&t.canDeleteTable()})),tableRepeatHeaderRows:n("tableRepeatHeaderRows",()=>t.toggleRepeatHeaderRows(),()=>({isEnabled:e.isCommandEnabled("tableRepeatHeaderRows")&&t.canToggleRepeatHeaderRows(),isActive:t.isRepeatHeaderRowsActive()})),tableInsertColumnBefore:n("tableInsertColumnBefore",()=>t.insertColumnBefore(),()=>({isEnabled:e.isCommandEnabled("tableInsertColumnBefore")&&t.canEditColumn()})),tableInsertColumnAfter:n("tableInsertColumnAfter",()=>t.insertColumnAfter(),()=>({isEnabled:e.isCommandEnabled("tableInsertColumnAfter")&&t.canEditColumn()})),tableDeleteColumn:n("tableDeleteColumn",()=>t.deleteColumn(),()=>({isEnabled:e.isCommandEnabled("tableDeleteColumn")&&t.canEditColumn()})),tableInsertRowBefore:n("tableInsertRowBefore",()=>t.insertRowBefore(),()=>({isEnabled:e.isCommandEnabled("tableInsertRowBefore")&&t.canEditRow()})),tableInsertRowAfter:n("tableInsertRowAfter",()=>t.insertRowAfter(),()=>({isEnabled:e.isCommandEnabled("tableInsertRowAfter")&&t.canEditRow()})),tableDeleteRow:n("tableDeleteRow",()=>t.deleteRow(),()=>({isEnabled:e.isCommandEnabled("tableDeleteRow")&&t.canEditRow()})),tableDeleteCells:n("tableDeleteCells",()=>t.deleteCell(),()=>({isEnabled:e.isCommandEnabled("tableDeleteCells")&&t.canDeleteCell()})),tableCellShading:n("tableCellShading",e=>t.cellShading(e??null)),tableCellBorders:n("tableCellBorders",()=>t.cellBorders()),tableCellNoBorders:n("tableCellNoBorders",()=>t.cellNoBorders()),tableApplyBorderPreset:n("tableApplyBorderPreset",e=>t.applyBorderPreset(e)),toggleTableDrawBorders:n("toggleTableDrawBorders",()=>t.toggleDrawingBorders(),()=>({isEnabled:t.insideTable(),isActive:t.isDrawingBorders()})),toggleTableGridlines:n("toggleTableGridlines",()=>t.toggleGridlines(),()=>({isEnabled:t.insideTable(),isActive:t.isShowingGridlines()})),tableWidth100:n("tableWidth100",()=>t.width100()),tableAlignLeft:n("tableAlignLeft",()=>t.alignLeft()),tableAlignCenter:n("tableAlignCenter",()=>t.alignCenter()),tableAlignRight:n("tableAlignRight",()=>t.alignRight()),tableSetCellAlignment:n("tableSetCellAlignment",e=>t.setCellAlignment(e),()=>({value:t.getCellAlignmentState()})),tableSetCellVerticalAlign:n("tableSetCellVerticalAlign",e=>t.setCellVerticalAlign(e)),tableSetCellTextDirection:n("tableSetCellTextDirection",e=>t.setCellTextDirection(e)),tableSetCellWidth:n("tableSetCellWidth",e=>t.setCellWidth(String(e))),tableSetCellNoWrap:n("tableSetCellNoWrap",e=>t.setCellNoWrap(KS(e))),tableSetCellFitText:n("tableSetCellFitText",e=>t.setCellFitText(KS(e))),tableSetRowHeight:n("tableSetRowHeight",e=>t.setActiveTableRowHeight(e??{height:null}),()=>({isEnabled:e.isCommandEnabled("tableSetRowHeight")&&t.canSetActiveTableRowHeight()})),tableSetBreakAcrossPages:r("tableSetBreakAcrossPages",e=>(t.setActiveTableRowBreakAcrossPages(KS(e)),!0),()=>({isEnabled:e.isCommandEnabled("tableSetBreakAcrossPages")&&t.canSetActiveTableRowBreakAcrossPages()})),tableSetHeaderRow:r("tableSetHeaderRow",e=>(t.setActiveTableRowHeader(KS(e)),!0),()=>({isEnabled:e.isCommandEnabled("tableSetHeaderRow")&&t.canSetActiveTableRowHeader()})),tableSetColumnWidth:r("tableSetColumnWidth",e=>(t.setActiveTableColumnWidth(e),!0),()=>({isEnabled:e.isCommandEnabled("tableSetColumnWidth")&&t.canSetActiveTableColumnWidth()})),tableSetTableWidth:r("tableSetTableWidth",e=>(t.setActiveTableWidth(e),!0),()=>({isEnabled:e.isCommandEnabled("tableSetTableWidth")&&t.canSetActiveTableWidth()})),tableSetCellMargins:n("tableSetCellMargins",e=>t.setCellMargins(e??{}),()=>({isEnabled:e.isCommandEnabled("tableSetCellMargins")&&t.canSetCellMargins()})),tableSetCellSpacing:n("tableSetCellSpacing",e=>t.setCellSpacing(XS(e)),()=>({isEnabled:e.isCommandEnabled("tableSetCellSpacing")&&t.canSetCellSpacing()})),tableSetTableIndent:n("tableSetTableIndent",e=>t.setTableIndent(XS(e)),()=>({isEnabled:e.isCommandEnabled("tableSetTableIndent")&&t.canSetTableIndent()})),tableSetAlignment:n("tableSetAlignment",e=>t.setTableAlignment(_S(e)),()=>({isEnabled:e.isCommandEnabled("tableSetAlignment")&&t.canSetTableAlignment()})),tableFormula:n("tableFormula",e=>t.evaluateTableFormula(String(e)),()=>({isEnabled:e.isCommandEnabled("tableFormula")&&t.canEvaluateTableFormula()})),tableSelectCell:n("tableSelectCell",()=>t.selectTablePart("cell"),()=>({isEnabled:e.isCommandEnabled("tableSelectCell")&&t.canSelectTable()})),tableSelectRow:n("tableSelectRow",()=>t.selectTablePart("row"),()=>({isEnabled:e.isCommandEnabled("tableSelectRow")&&t.canSelectTable()})),tableSelectColumn:n("tableSelectColumn",()=>t.selectTablePart("column"),()=>({isEnabled:e.isCommandEnabled("tableSelectColumn")&&t.canSelectTable()})),tableSelectTable:n("tableSelectTable",()=>t.selectTablePart("table"),()=>({isEnabled:e.isCommandEnabled("tableSelectTable")&&t.canSelectTable()})),tableToggleHeaderRow:n("tableToggleHeaderRow",()=>t.toggleTblLook("firstRow"),()=>({isEnabled:t.insideTable(),isActive:t.getTblLook()?.firstRow??!1})),tableToggleTotalRow:n("tableToggleTotalRow",()=>t.toggleTblLook("lastRow"),()=>({isEnabled:t.insideTable(),isActive:t.getTblLook()?.lastRow??!1})),tableToggleBandedRows:n("tableToggleBandedRows",()=>t.toggleTblLook("bandedRows"),()=>({isEnabled:t.insideTable(),isActive:t.getTblLook()?.bandedRows??!1})),tableToggleFirstColumn:n("tableToggleFirstColumn",()=>t.toggleTblLook("firstCol"),()=>({isEnabled:t.insideTable(),isActive:t.getTblLook()?.firstCol??!1})),tableToggleLastColumn:n("tableToggleLastColumn",()=>t.toggleTblLook("lastCol"),()=>({isEnabled:t.insideTable(),isActive:t.getTblLook()?.lastCol??!1})),tableToggleBandedColumns:n("tableToggleBandedColumns",()=>t.toggleTblLook("bandedCols"),()=>({isEnabled:t.insideTable(),isActive:t.getTblLook()?.bandedCols??!1})),setTableStyle:n("setTableStyle",e=>t.setStyleId(String(e??"")),()=>({isEnabled:t.insideTable(),value:t.getStyleId()})),tableToggleAutoFit:n("tableToggleAutoFit",()=>t.toggleAutoFit(),()=>({isEnabled:t.insideTable(),isActive:"autofit"===t.getLayout()})),tableAutoFit:n("tableAutoFit",e=>t.setAutoFit(e??"contents"),()=>({isEnabled:t.canSetAutoFit()})),tableDistributeColumns:n("tableDistributeColumns",()=>t.distributeColumns(),()=>({isEnabled:e.isCommandEnabled("tableDistributeColumns")&&t.canEditColumn()})),tableDistributeRows:n("tableDistributeRows",()=>t.distributeRows(),()=>({isEnabled:e.isCommandEnabled("tableDistributeRows")&&t.canEditRow()})),insertTable:n("insertTable",e=>{const{rows:n,cols:r,columns:o}=e??{},a=r??o;n&&a&&t.insert(n,a)})}}function tC({design:e,actionCommand:t}){return{applyDocumentTheme:t("applyDocumentTheme",t=>e.applyTheme(String(t)),()=>({value:e.getDesign()?.themeId})),setDocumentColorScheme:t("setDocumentColorScheme",t=>e.setColorScheme(String(t)),()=>({value:e.getDesign()?.colorSchemeId})),setDocumentFontScheme:t("setDocumentFontScheme",t=>e.setFontScheme(String(t)),()=>({value:e.getDesign()?.fontSchemeId})),setDocumentParagraphSpacing:t("setDocumentParagraphSpacing",t=>e.setParagraphSpacing(String(t)),()=>({value:e.getDesign()?.paragraphSpacingId})),setDocumentEffects:t("setDocumentEffects",t=>e.setEffects(String(t)),()=>({value:e.getDesign()?.effectsId})),setDocumentPageColor:t("setDocumentPageColor",t=>e.setPageColor(t??null),()=>({value:e.getDesign()?.pageColor})),setDocumentWatermark:t("setDocumentWatermark",t=>e.setWatermark(t??null),()=>({value:e.getDesign()?.watermark})),setDocumentPageBorder:t("setDocumentPageBorder",t=>e.setPageBorder(t??null),()=>({value:e.getPageBorder()})),setDocumentDesignDefault:t("setDocumentDesignDefault",()=>e.setDefault())}}function nC({dialog:e,actionCommand:t}){return{openFontDialog:t("openFontDialog",()=>{e.openFontDialog()}),openParagraphDialog:t("openParagraphDialog",t=>{const n="number"==typeof t&&Number.isFinite(t)?t:void 0;e.openParagraphDialog(n)})}}var rC=/* @__PURE__ */new Set(["copy","selectAll","selectWord","selectSentence","selectParagraph","selectCollapse","nextRevision","previousRevision","nextComment","previousComment","toggleCommentsPanel","find","replace","print","exportDocx","exportPdf","toggleShowMargins","toggleShowParagraphMarks","togglePreciseFonts","toggleRevisionMarkup","showMarkupOptions","applyShowMarkup","toggleRevisionsPanel","toggleOutlinePanel","setReviewDisplayMode","imageContext","tableContext","toggleTableGridlines","documentStyles"]),oC=/* @__PURE__ */new Set(["bold","italic","underline","doubleUnderline","wordUnderline","strike","doubleStrike","smallCaps","allCaps","hidden","noProof","webHidden","specVanish","contextualAlternates","characterBorder","shadow","emboss","engrave","outline","superscript","subscript","setFontFamily","setFontSize","increaseFontSize","decreaseFontSize","growFont1","shrinkFont1","changeTextCase","clearFormatting","setColor","setHighlight","setTextShading","setCharacterStyleId","setUnderlineStyle","applyUnderlineStyle","setUnderlineColor","setCharacterScale","setCharacterSpacing","setRunSnapToGrid","setFitText","setBaselineShift","setEmphasisMark","setTextEffect","setKerning","setLigatures","setNumberSpacing","setNumberForm","setStylisticSet"]),aC=/* @__PURE__ */new WeakMap;function iC(e){return{isCommandEnabled:t=>"openSymbolDialog"===t||("openEquationDialog"===t||("repeatLastAction"===t?!e.isReadOnly()&&e.canRepeatLastAction():(!oC.has(t)||!function(e){const t=e.state?.();if(!t)return!1;const n=t.document,r=t.selection;if(!n||!r)return!1;let o=aC.get(n);o||(o=/* @__PURE__ */new WeakMap,aC.set(n,o));const a=o.get(r);if(void 0!==a)return a;const i=null!==Ki(t,e=>"image"===e.kind||"textBox"===e.kind);return o.set(r,i),i}(e))&&((rC.has(t)||!e.isReadOnly())&&("insertFootnote"!==t||e.commandsController.canInsertFootnoteCommand()))))}}function sC(e){return{state:()=>e.styleController.toolbarStyleState()}}function lC(e){return{isCollapsed:()=>ga(e.state().selection)}}function cC(e){return{canUndo:()=>e.undoStack().length>0,canRedo:()=>e.redoStack().length>0,undo:()=>(e.historyActions.performUndo(),!0),redo:()=>(e.historyActions.performRedo(),!0)}}var dC={nbsp:" ",nbHyphen:"‑",optionalHyphen:"",emDash:"—",ellipsis:"…",copyright:"©",registered:"®",trademark:"™"};function uC(e){return/\p{L}|\p{N}/u.test(e)}function pC(e){return"."===e||"!"===e||"?"===e}function fC(e,t){return xi(e,t)}function gC(e,t,n,r){return e-n||t-r}function mC(e,t){const n=ko(e),r=n[t.startIndex],o=n[t.endIndex];return r&&o?{...e,selection:{anchor:fC(r,t.startOffset),focus:fC(o,t.endOffset)}}:e}function hC(e,t,n){if(!t.length)return null;const r=ko(e),o=new Map(r.map((e,t)=>[e.id,t])),a="next"===n?Ri(e,r).end:Ri(e,r).start,i=o.get(a.paragraphId);if(void 0===i)return null;const s=r[i],l=wa(s,a);return("next"===n?t.find(e=>gC(e.startIndex,e.startOffset,i,l)>0):[...t].reverse().find(e=>gC(e.startIndex,e.startOffset,i,l)<0))??("next"===n?t[0]:t[t.length-1])}function bC(e){const t=ko(e),n=[],r=/* @__PURE__ */new Set,o=/* @__PURE__ */new Map;for(const a of[...Yv(e),...Zv(e)]){const e=a.paragraphIds[0];if(!e)continue;const t=o.get(e)??[];t.push(a.id),o.set(e,t)}return t.forEach((e,t)=>{for(const i of o.get(e.id)??[])r.has(i)||(r.add(i),n.push({id:i,startIndex:t,startOffset:0,endIndex:t,endOffset:e.runs.reduce((e,t)=>e+t.text.length,0)}));let a=0;for(const o of e.runs){const e=[o.revision?.id,o.styles?.propertyRevision?.id].filter(e=>"string"==typeof e);for(const i of e)r.has(i)||(r.add(i),n.push({id:i,startIndex:t,startOffset:a,endIndex:t,endOffset:a+o.text.length}));a+=o.text.length}}),n}function yC(e,t){const n=hC(e,bC(e),t);return n?mC(e,n):e}function vC(e){const t=ko(e),n=new Map(t.map((e,t)=>[e.id,t])),r=e.document.comments;if(!r)return[];const o=[];for(const a of r.order){const e=r.items[a];if(!e?.start||!e.end)continue;const i=n.get(e.start.paragraphId),s=n.get(e.end.paragraphId);if(void 0===i||void 0===s)continue;const l=t[i],c=t[s],d=Math.max(0,Math.min(e.start.offset,l.runs.reduce((e,t)=>e+t.text.length,0))),u=Math.max(0,Math.min(e.end.offset,c.runs.reduce((e,t)=>e+t.text.length,0)));gC(i,d,s,u)>0||o.push({id:a,startIndex:i,startOffset:d,endIndex:s,endOffset:u})}return o.sort((e,t)=>gC(e.startIndex,e.startOffset,t.startIndex,t.startOffset))}function xC(e,t){const n=hC(e,vC(e),t);return n?mC(e,n):e}function wC(e){const t=vC(e);if(!t.length)return null;const n=Ri(e),r=t.find(e=>0===gC(e.startIndex,e.startOffset,n.startIndex,n.startParagraphOffset)&&0===gC(e.endIndex,e.endOffset,n.endIndex,n.endParagraphOffset))??t.find(e=>gC(e.startIndex,e.startOffset,n.startIndex,n.startParagraphOffset)<=0&&gC(e.endIndex,e.endOffset,n.endIndex,n.endParagraphOffset)>=0);return r?e.document.comments?.items[r.id]??null:null}function IC(e,t){const n=bC(e).find(e=>e.id===t);return n?mC(e,n):e}function SC(e,t=f,n=6,r=9){const o=(t,n,r)=>({state:e,layout:r,status:t,passes:n,updatedEntries:0});if("main"!==jr(e)||e.trackChangesEnabled||!Number.isSafeInteger(n)||n<1||!Number.isSafeInteger(r)||r<1||r>9)return o("unsupported",0);const a=Math.min(n,6),i=Ua(e),s=Lo(e.document)[i];if(!s)return o("unsupported",0);const l=vI(s.blocks);if(!l||r<l.endLevel)return o("unsupported",0);const c=s.blocks[l.startBlockIndex].id,d=s.blocks[l.endBlockIndex].id,u=new Set(s.blocks.slice(l.startBlockIndex+1,l.endBlockIndex).map(e=>e.id)),p=SI(e,l,r);if(!p||p.length>2048)return o("unsupported",0);const g=JSON.stringify(p.map(e=>[e.id,e.level,e.text,e.tc])),m=/* @__PURE__ */new Set;let h,b=e;for(let f=1;f<=a;f++){let n;try{n=t(b.document)}catch{return o("unsupported",f,h)}h??=n;const a=Lo(b.document)[i]?.blocks,s=a&&vI(a);if(!a||!s||a[s.startBlockIndex]?.id!==c||a[s.endBlockIndex]?.id!==d)return o("unsupported",f,h);const l=SI(b,s,r);if(!l||JSON.stringify(l.map(e=>[e.id,e.level,e.text,e.tc]))!==g)return o("unsupported",f,h);const p=xI(b.document,n),y=l.map(e=>p(e.id,e.tc));if(y.some(e=>void 0===e))return o("unresolved",f,h);const v=FI(b,p,r);if(v===b){const t=a.slice(s.startBlockIndex+1,s.endBlockIndex);return t.length!==l.length||t.some((e,t)=>"paragraph"!==e.type||mi(e)!==TI(l[t],y[t]))?o("unsupported",f,h):{state:b===e?e:{...b,selection:e.selection},layout:n,status:b===e?"unchanged":"updated",passes:f,updatedEntries:b===e?0:l.length}}if(u.has(e.selection.anchor.paragraphId)||u.has(e.selection.focus.paragraphId))return o("unsupported",f,h);const x=JSON.stringify([l.map((e,t)=>[e.id,e.tc?.runId,e.text,y[t]]),n.pages.map(e=>[e.index,e.sectionIndex])]);if(m.has(x))return o("nonconvergent",f,h);m.add(x),b={...v,selection:e.selection}}return o("nonconvergent",a,h)}var CC=e=>/^_TocOasis(?:[0-9a-f]{30}|[0-9a-f]{32})$/.test(e);function kC(e,t=f){const n=(t,n)=>({state:e,status:t,layout:n});if("main"!==jr(e)||e.trackChangesEnabled)return n("unsupported");const r=Ua(e),o=Lo(e.document),a=o[r];if(!a)return n("unsupported");const i=vI(a.blocks);if(!i?.hyperlinks)return n("unsupported");const s=SI(e,i),l=a.blocks.slice(i.startBlockIndex+1,i.endBlockIndex);if(!s||s.length>2048||l.length!==s.length)return n("unsupported");const c=/* @__PURE__ */new Map;for(const f of o)for(const e of f.blocks)if("paragraph"===e.type){if(c.has(e.id))return n("unsupported");c.set(e.id,e)}const d=e.document.bookmarks,u={...d?.items},p=[...d?.order??[]];if(new Set(p).size!==p.length||p.length!==Object.keys(u).length||p.some(e=>!Object.hasOwn(u,e)||u[e]?.id!==e))return n("unsupported");const g=/* @__PURE__ */new Map;for(const f of Object.values(u)){const e=f.name.toLowerCase();g.set(e,g.has(e)?null:f)}let m;try{m=t(e.document)}catch{return n("unsupported")}const h=xI(e.document,m),b=s.map(e=>h(e.id,e.tc));if(b.some(e=>void 0===e))return n("unresolved",m);const y=void 0!==i.tcIdentifier?Y(e.document,m):void 0,v=(e,t,n)=>!!e&&!0===e.hidden&&void 0===e.colFirst&&void 0===e.colLast&&e.start?.paragraphId===t.id&&e.start.offset===(n.tc?.offset??0)&&e.end?.paragraphId===t.id&&e.end.offset===(n.tc?.offset??oi(t));let x=!1;const w=/* @__PURE__ */new Map;for(const[f,T]of s.entries()){const e=l[f],t=c.get(T.id);if(!e||"paragraph"!==e.type||!t||t===e||t.sdtWrappers?.length||t.numberingRevision||t.dropCap||t.runs.some(e=>e.revision||e.revisionRangeMarker||e.sdtWrappers?.length||e.styles?.rtl||("text"===e.kind?!!e.styles?.hidden:!T.tc||0!==e.text.length||"fieldChar"!==e.kind&&"fieldInstruction"!==e.kind))||/[\r\n\t]/.test(T.text)||mi(e)!==TI(T,b[f]))return n("unsupported",m);if(T.tc){const e=T.tc.offset;if(!Number.isSafeInteger(e)||e<0||e>oi(t))return n("unsupported",m);const r=y?.pageIndexAt(t.id,e);if(void 0===r||y?.forPage(r).sectionNumber!==T.tc.sectionIndex+1)return n("unresolved",m)}const r=e.runs[0],o=r.styles?.link;if(o){if(!o.startsWith("#")||!v(g.get(o.slice(1).toLowerCase()),t,T)||g.get(o.slice(1).toLowerCase())?.name!==o.slice(1))return n("unsupported",m);continue}let a=Object.values(u).find(e=>CC(e.name)&&g.get(e.name.toLowerCase())===e&&v(e,t,T));if(!a){const e=_r(),r="_TocOasis"+e.replace(/^bookmark:/,"").replace(/-/g,"").slice(0,30);if(!CC(r)||Object.hasOwn(u,e)||g.has(r.toLowerCase()))return n("unsupported",m);a={id:e,name:r,hidden:!0,start:{paragraphId:t.id,offset:T.tc?.offset??0},end:{paragraphId:t.id,offset:T.tc?.offset??oi(t)}},u[e]=a,p.push(e),g.set(r.toLowerCase(),a)}w.set(e.id,{...e,runs:[{...r,styles:{...r.styles,link:"#"+a.name}}]}),x=!0}if(!x)return n("unchanged",m);const I=o.map((e,t)=>t!==r?e:{...e,blocks:e.blocks.map(e=>w.get(e.id)??e)}),S={...e.document,sections:I,bookmarks:{items:u,order:p}};let C;try{C=t(S)}catch{return n("unsupported",m)}const k=xI(S,C);if(s.some((e,t)=>k(e.id,e.tc)!==b[t]))return n("unresolved",m);if(void 0!==i.tcIdentifier){const e=Y(S,C);if(s.some(t=>{if(!t.tc)return!1;const n=e.pageIndexAt(t.id,t.tc.offset);return void 0===n||e.forPage(n).sectionNumber!==t.tc.sectionIndex+1}))return n("unresolved",m)}return{state:{...e,document:S},status:"updated",layout:C}}function TC(e){const t=Lo(e.document)[Ua(e)],n=t&&vI(t.blocks);return!n&&WI(e)?function(e,t=e=>f(e,void 0,void 0,void 0,{cachedBodyPageFields:!0})){let n;const r=(t,r)=>({state:e,status:t,passes:r,layout:n,updatedEntries:0}),o=HI(e);if(!o)return r("unsupported",0);const a=Lo(e.document).flatMap(e=>e.blocks);if(new Set(a.map(e=>e.id)).size!==a.length)return r("unsupported",0);const i=/* @__PURE__ */new Set;for(const u of[e.document.bookmarks,e.document.comments])for(const e of Object.values(u?.items??{}))for(const t of[e.start,e.end])t&&i.add(t.paragraphId);i.add(e.selection.anchor.paragraphId),i.add(e.selection.focus.paragraphId);const s=JSON.stringify(o.entries),l=/* @__PURE__ */new Set,c=/* @__PURE__ */new Set;let d=e;for(let u=1;u<=6;u++){let o;try{o=t(d.document)}catch{return r("unsupported",u)}n??=o;const a=HI(d);if(!a||JSON.stringify(a.entries)!==s)return r("unsupported",u);const p=jI(d.document,o,a);if(p.some(e=>void 0===e))return r("unresolved",u);const f=Lo(d.document).flatMap(e=>e.blocks),g=/* @__PURE__ */new Map,m=[];for(const[e,t]of a.entries.entries()){const n=f.find(e=>e.id===t.paragraphId);if(!n||"paragraph"!==n.type)return r("unsupported",u);const o=t.runIds.map(e=>n.runs.find(t=>t.id===e));if(o.some(e=>!e||"text"!==e.kind))return r("unsupported",u);const a=o.map(e=>e.text.length),s=o.map(e=>e.text).join("");m.push(s);const l=p[e];if(s===l)continue;const d=UI(l,a);if(!d)return r("unsupported",u);if(d.some((e,t)=>e.length!==a[t])&&i.has(t.paragraphId))return r("unsupported",u);g.set(t.paragraphId,new Map(t.runIds.map((e,t)=>[e,d[t]]))),c.add(t.paragraphId)}if(!g.size)return{state:d,layout:o,status:d===e?"unchanged":"updated",passes:u,updatedEntries:c.size};const h=JSON.stringify([m,p]);if(l.has(h))return r("nonconvergent",u);l.add(h),d={...d,document:{...d.document,sections:Lo(d.document).map(e=>({...e,blocks:e.blocks.map(e=>{const t=g.get(e.id);return t&&"paragraph"===e.type?{...e,runs:e.runs.map(e=>t.has(e.id)&&t.get(e.id)!==e.text?{...e,text:t.get(e.id)}:e)}:e})}))}}}return r("nonconvergent",6)}(e):n?.hyperlinks?function(e,t=f){let n=0;const r=e=>(n++,t(e)),o=t=>({state:e,status:t,passes:n,updatedEntries:0});if("main"!==jr(e)||e.trackChangesEnabled)return o("unsupported");const a=Ua(e),i=Lo(e.document),s=i[a],l=s&&vI(s.blocks);if(!s||!l?.hyperlinks)return o("unsupported");const c=s.blocks.slice(l.startBlockIndex+1,l.endBlockIndex),d=kC(e,r);if("unchanged"===d.status)return{...d,passes:n,updatedEntries:0};if("updated"===d.status)return{...d,passes:n,updatedEntries:c.length};if("unresolved"===d.status)return o("unresolved");const u=Object.values(e.document.bookmarks?.items??{}),p=/* @__PURE__ */new Map;for(const f of c){if("paragraph"!==f.type)return o("unsupported");const e=f.runs[0],t=e.styles?.link;if(!t)continue;if(!t.startsWith("#")||!CC(t.slice(1)))return o("unsupported");const n=u.filter(e=>e.name.toLowerCase()===t.slice(1).toLowerCase());if(n.length>1||n.some(e=>e.name!==t.slice(1)||!e.hidden||void 0!==e.colFirst||void 0!==e.colLast))return o("unsupported");const{link:r,...a}=e.styles;p.set(f.id,{...f,runs:[{...e,styles:a}]})}const g=new Set(c.map(e=>e.id));if(u.some(e=>[e.start,e.end].some(e=>e&&g.has(e.paragraphId))))return o("unsupported");const m=SC(p.size?{...e,document:{...e.document,sections:i.map((e,t)=>t===a?{...e,blocks:e.blocks.map(e=>p.get(e.id)??e)}:e)}}:e,r);if("updated"!==m.status&&"unchanged"!==m.status)return o(m.status);const h=kC(m.state,r);if("updated"!==h.status&&"unchanged"!==h.status)return o(h.status);const b=SI(h.state,l);return b?{state:h.state,layout:h.layout,status:"updated",passes:n,updatedEntries:b.length}:o("unsupported")}(e):SC(e)}function PC(e){const t=t=>{const n=Number(e.styleController.toolbarStyleState().fontSize),r=Number.isFinite(n)&&n>0?Jt(n):11,o="increase"===t?On(r):xt(r);return e.styleController.applyToolbarValueStyleCommand("fontSize",Xn(o)),!0};return{formatPainterOnce:e.formatPainter.armOnce,formatPainterContinuous:e.formatPainter.armContinuous,cancelFormatPainter:()=>(e.formatPainter.cancel(),!0),formatPainterMode:e.formatPainter.mode,canCaptureFormatPainter:e.formatPainter.canCapture,selectAll:()=>{const t=ci(e.state().document);if(0===t.length)return!1;const n=t[0],r=t[t.length-1];return e.applyState({...e.state(),selection:{anchor:xi(n,0),focus:xi(r,mi(r).length)}}),e.focusInput(),!0},selectWord:()=>!e.isReadOnly()&&(e.applyState(function(e){const{paragraph:t,offset:n}=ae(e),r=mi(t);let o=n,a=n;for(;o>0&&uC(r[o-1]);)o-=1;for(;a<r.length&&uC(r[a]);)a+=1;return ji(e,{anchor:xi(t,o),focus:xi(t,a)})}(e.state())),e.focusInput(),!0),selectSentence:()=>!e.isReadOnly()&&(e.applyState(function(e){const{paragraph:t,offset:n}=ae(e),r=mi(t);let o=n;for(;o>0&&!pC(r[o-1]);)o-=1;for(;o<r.length&&/\s/u.test(r[o]);)o+=1;let a=n;for(;a<r.length&&!pC(r[a]);)a+=1;return a<r.length&&(a+=1),ji(e,{anchor:xi(t,o),focus:xi(t,Math.min(a,r.length))})}(e.state())),e.focusInput(),!0),selectParagraph:()=>!e.isReadOnly()&&(e.applyState(function(e){const t=ko(e),n=Ri(e),r=t[n.startIndex],o=t[n.endIndex];return r&&o?ji(e,{anchor:xi(r,0),focus:xi(o,oi(o))}):e}(e.state())),e.focusInput(),!0),selectCollapse:(t=!1)=>!e.isReadOnly()&&(e.applyState(function(e,t=!1){const n=e.selection.anchor,r=e.selection.focus,o=ko(e),a=ia(o,n,r),i=t?a<=0?r:n:a<=0?n:r;return ji(e,{anchor:i,focus:i})}(e.state(),t)),e.focusInput(),!0),selectText:(t,n=1)=>0!==t.length&&(e.applyState(function(e,t,n=1){const r=Cw(e.document,t)[Math.max(1,n)-1];return r?ji(e,{anchor:r.anchor,focus:r.focus}):e}(e.state(),t,n)),e.focusInput(),!0),selectRange:(t,n)=>(e.applyState(function(e,t,n){return ji(e,{anchor:t,focus:n})}(e.state(),t,n)),e.focusInput(),!0),insertFootnote:()=>(e.commandsController.applyInsertFootnoteCommand(),!0),setNoteOptions:t=>{e.applyTransactionalState(e=>function(e,t){const n=t.kind,r={...("endnote"===n?e.document.endnotes?.settings:e.document.footnotes?.settings)??{}};let o=!1;if(void 0!==t.numberFormat){const e=null===t.numberFormat?void 0:t.numberFormat;r.numberFormat!==e&&(r.numberFormat=e,o=!0)}if(void 0!==t.startAt){const e=null===t.startAt?void 0:Math.max(1,Math.round(t.startAt));r.startAt!==e&&(r.startAt=e,o=!0)}if(void 0!==t.restart){const e=null===t.restart?void 0:t.restart;r.restart!==e&&(r.restart=e,o=!0)}if(!o)return e;const a=Object.keys(r).length>0?{...r}:void 0;if("endnote"===n){const t=e.document.endnotes??{items:{}};return{...e,document:{...e.document,endnotes:{...t,settings:a}}}}const i=e.document.footnotes??{items:{}};return{...e,document:{...e.document,footnotes:{...i,settings:a}}}}(e,{kind:t.kind,...void 0!==t.numberFormat?{numberFormat:null===t.numberFormat?null:t.numberFormat}:{},...void 0!==t.startAt?{startAt:t.startAt}:{},...void 0!==t.restart?{restart:null===t.restart?null:t.restart}:{}})),e.focusInput()},getNoteOptions:t=>function(e,t){return"endnote"===t?{...e.document.endnotes?.settings??{}}:{...e.document.footnotes?.settings??{}}}(e.state(),t),insertText:(t,n)=>{if(0===t.length)return!1;const r=n?{fontFamily:n}:void 0;return e.applyTransactionalState(n=>e.tableOps.applyTableAwareParagraphEdit(n,e=>Ju(e,t,r))),e.focusInput(),!0},insertEquation:t=>(e.applyTransactionalState(n=>e.tableOps.applyTableAwareParagraphEdit(n,e=>function(e,t){if(Po(e))return e;if(Dt(e))return e;const n=ga(e.selection)?e:te(e);if(!ga(e.selection)&&n===e)return e;const{paragraph:r,index:o,offset:a}=ae(n),i=gt(r,a),s={id:`run:${Math.random().toString(36).slice(2,9)}`,text:"",styles:i,kind:"math",math:t},l=u(r,a,[s]),c=ko(n).map((e,t)=>t===o?l:e);return Vt(n,c,J(xi(l,a+1)))}(e,t))),e.focusInput(),!0),updateEquation:(t,n)=>(e.applyTransactionalState(e=>function(e,t,n){if(Po(e))return e;let r=!1;const o=ko(e).map(e=>{let o=!1;const a=e.runs.map(e=>e.id!==t||"math"!==e.kind?e:(r=!0,o=!0,{...e,math:n,text:""}));return o?{...e,runs:a}:e});return r?Vt(e,o,e.selection):e}(e,t,n)),e.focusInput(),!0),hasTableOfContents:()=>function(e){if("main"!==jr(e))return!1;const t=Lo(e.document)[Ua(e)];return!!t&&void 0!==BI(t.blocks)}(e.state())||WI(e.state()),hasRevisionsInSelection:()=>yS(e.state()).size>0,hasRevisionsInDocument:()=>xS(e.state()),hasNavigableRevisions:()=>bC(e.state()).length>0,hasNavigableComments:()=>{return(t=e.state(),vC(t).map(e=>e.id)).length>0;var t},canCreateComment:e.commentComposer.canCreate,canReplyToComment:e.commentComposer.canReply,newComment:e.commentComposer.openNew,replyComment:e.commentComposer.openReply,editComment:e.commentComposer.openEdit,toggleCommentsPanel:e.commentComposer.togglePanel,isCommentsPanelOpen:e.commentComposer.panelOpen,canEditComment:e.commentComposer.canEdit,navigateRevisionNext:()=>{const t=e.state(),n=yC(t,"next");return n!==t&&(e.applyState(n),e.focusInput(),!0)},navigateRevisionPrevious:()=>{const t=e.state(),n=yC(t,"previous");return n!==t&&(e.applyState(n),e.focusInput(),!0)},navigateCommentNext:()=>{const t=e.state(),n=xC(t,"next");return n!==t&&(e.applyState(n),e.focusInput(),!0)},navigateCommentPrevious:()=>{const t=e.state(),n=xC(t,"previous");return n!==t&&(e.applyState(n),e.focusInput(),!0)},hasSelectedComment:()=>null!==wC(e.state()),isSelectedCommentResolved:()=>Boolean(wC(e.state())?.resolved),canManageSelectedComment:e.commentComposer.canResolveSelected,resolveSelectedComment:()=>e.commentComposer.resolveSelected(!0),reopenSelectedComment:()=>e.commentComposer.resolveSelected(!1),deleteSelectedComment:e.commentComposer.deleteSelected,canDeleteSelectedComment:e.commentComposer.canDeleteSelected,insertTableOfContents:()=>(e.applyTransactionalState(e=>{const t=OI(e);if(t===e)return e;const n=TC(t);return"updated"===n.status||"unchanged"===n.status?n.state:t}),e.focusInput(),!0),updateTableOfContents:()=>(e.applyTransactionalState(e=>TC(e).state),e.focusInput(),!0),pastePlainText:()=>(e.forcePlainTextPaste.set(!0),e.focusInput(),!0),bold:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("bold"),!0),italic:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("italic"),!0),underline:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("underline"),!0),doubleUnderline:()=>(e.styleController.applyToolbarUnderlineStyleCommand(e.styleController.toolbarStyleState().underline&&"double"===e.styleController.toolbarStyleState().underlineStyle?null:"double"),!0),wordUnderline:()=>(e.styleController.applyToolbarUnderlineStyleCommand(e.styleController.toolbarStyleState().underline&&"words"===e.styleController.toolbarStyleState().underlineStyle?null:"words"),!0),strike:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("strike"),!0),doubleStrike:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("doubleStrike"),!0),smallCaps:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("smallCaps"),!0),allCaps:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("allCaps"),!0),hidden:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("hidden"),!0),noProof:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("noProof"),!0),webHidden:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("webHidden"),!0),specVanish:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("specVanish"),!0),contextualAlternates:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("contextualAlternates"),!0),toggleCharacterBorder:()=>(e.keyboardCommandsController.applyToggleCharacterBorderCommand(),!0),shadow:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("shadow"),!0),emboss:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("emboss"),!0),engrave:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("imprint"),!0),outline:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("outline"),!0),superscript:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("superscript"),!0),subscript:()=>(e.keyboardCommandsController.applyBooleanStyleCommand("subscript"),!0),alignLeft:()=>(e.commandsController.applyParagraphStyleCommand("align","left"),!0),alignCenter:()=>(e.commandsController.applyParagraphStyleCommand("align","center"),!0),alignRight:()=>(e.commandsController.applyParagraphStyleCommand("align","right"),!0),alignJustify:()=>(e.commandsController.applyParagraphStyleCommand("align","justify"),!0),orderedList:()=>(e.commandsController.applyParagraphListCommand("ordered"),!0),bulletList:()=>(e.commandsController.applyParagraphListCommand("bullet"),!0),find:()=>(e.findReplace.setIsOpen(!0),!0),replace:()=>(e.findReplace.setIsOpen(!0),!0),replaceAll:t=>(e.isReadOnly()||(e.applyTransactionalState(e=>kw(e,t.search,t.replace,{matchCase:t.matchCase,wholeWord:t.wholeWord}),{mergeKey:vf}),e.focusInput()),!0),isTrackChangesEnabled:()=>Boolean(e.state().trackChangesEnabled),areMarginsVisible:()=>Boolean(e.state().showMargins),areParagraphMarksVisible:()=>Boolean(e.state().showParagraphMarks),areRevisionMarkupVisible:()=>Boolean(e.state().showRevisionMarkup??!0),areOutlineVisible:()=>e.isOutlineVisible(),toggleRevisionsPanel:()=>(e.toggleRevisionsPanel(),!0),areRevisionsPanelVisible:()=>e.revisionsPanelVisible(),reviewDisplayMode:()=>e.state().reviewDisplayMode??"all",setReviewDisplayMode:t=>(e.commandsController.applySetReviewDisplayModeCommand(t),!0),showMarkupOptions:()=>function(e){const t=void 0===e.markupAuthors;return{insertions:Qv(e,"insertions"),deletions:Qv(e,"deletions"),comments:Qv(e,"comments"),formatting:Qv(e,"formatting"),allAuthors:t,visibleAuthors:e.markupAuthors??[],knownAuthors:sx(e)}}(e.state()),applyShowMarkup:t=>(e.commandsController.applyShowMarkupCommand(t),!0),toggleTrackChanges:()=>(e.commandsController.applyToggleTrackChangesCommand(),!0),toggleRevisionMarkup:()=>(e.commandsController.applyToggleRevisionMarkupCommand(),!0),toggleOutlinePanel:()=>(e.toggleOutlinePanel(),!0),acceptRevisions:()=>(e.commandsController.applyAcceptRevisionsCommand(),!0),rejectRevisions:()=>(e.commandsController.applyRejectRevisionsCommand(),!0),acceptAllRevisions:()=>(e.commandsController.applyAcceptAllRevisionsCommand(),!0),rejectAllRevisions:()=>(e.commandsController.applyRejectAllRevisionsCommand(),!0),toggleShowMargins:()=>(e.commandsController.applyToggleShowMarginsCommand(),!0),toggleShowParagraphMarks:()=>(e.commandsController.applyToggleShowParagraphMarksCommand(),!0),togglePreciseFonts:()=>(Ir(),!0),pageBreak:()=>(e.applyTransactionalState(t=>e.tableOps.applyTableAwareParagraphEdit(t,e=>xr(e))),e.focusInput(),!0),lineBreak:()=>(e.applyTransactionalState(t=>e.tableOps.applyTableAwareParagraphEdit(t,e=>Ju(e,"\n"))),e.focusInput(),!0),columnBreak:()=>(e.applyTransactionalState(t=>e.tableOps.applyTableAwareParagraphEdit(t,e=>Qu(e))),e.focusInput(),!0),splitBlock:()=>(e.commandsController.handleListEnter()||(e.applyTransactionalState(t=>e.tableOps.applyTableAwareParagraphEdit(t,e=>cn(e))),e.focusInput()),!0),insertSpecialChar:t=>(e.applyTransactionalState(n=>e.tableOps.applyTableAwareParagraphEdit(n,e=>function(e,t){return Ju(e,dC[t])}(e,t))),e.focusInput(),!0),setFontFamily:t=>(e.styleController.applyToolbarValueStyleCommand("fontFamily",t),!0),setFontSize:t=>(e.styleController.applyToolbarValueStyleCommand("fontSize",t),!0),increaseFontSize:()=>t("increase"),decreaseFontSize:()=>t("decrease"),growFont1:()=>(e.applyTransactionalState(e=>pp(e,1)),e.focusInput(),!0),shrinkFont1:()=>(e.applyTransactionalState(e=>pp(e,-1)),e.focusInput(),!0),changeTextCase:t=>(e.commandsController.applyChangeTextCaseCommand(t),!0),clearFormatting:()=>ga(e.state().selection)?(e.styleController.clearPendingCaretTextStyle(),e.focusInput(),!0):(e.commandsController.applyClearFormattingCommand(),!0),setColor:t=>(e.styleController.applyToolbarValueStyleCommand("color",t),!0),setHighlight:t=>(e.styleController.applyToolbarValueStyleCommand("highlight",t),!0),setTextShading:t=>(e.styleController.applyToolbarValueStyleCommand("shading",t),!0),setStyleId:t=>(e.commandsController.handleStyleChange(t),!0),setCharacterStyleId:t=>(e.styleController.applyToolbarValueStyleCommand("styleId",t||null),!0),applyUnderlineStyle:e.styleController.applyToolbarUnderlineStyleCommand,setUnderlineStyle:t=>e.styleController.applyToolbarValueStyleCommand("underlineStyle",t),setUnderlineColor:t=>(e.styleController.applyToolbarValueStyleCommand("underlineColor",t),!0),setCharacterScale:t=>(e.styleController.applyToolbarValueStyleCommand("characterScale",t),!0),setCharacterSpacing:t=>(e.styleController.applyToolbarValueStyleCommand("characterSpacing",t),!0),setRunSnapToGrid:t=>(e.styleController.applyToolbarValueStyleCommand("snapToGrid",t),!0),setFitText:t=>(e.styleController.applyToolbarValueStyleCommand("fitText",t),!0),setBaselineShift:t=>(e.styleController.applyToolbarValueStyleCommand("baselineShift",t),!0),setEmphasisMark:t=>(e.styleController.applyToolbarValueStyleCommand("emphasisMark",t),!0),setTextEffect:t=>(e.styleController.applyToolbarValueStyleCommand("textEffect",t),!0),setKerning:t=>(e.styleController.applyToolbarValueStyleCommand("kerningThreshold",t),!0),setLigatures:t=>(e.styleController.applyToolbarValueStyleCommand("ligatures",t||null),!0),setNumberSpacing:t=>(e.styleController.applyToolbarValueStyleCommand("numberSpacing",t||null),!0),setNumberForm:t=>(e.styleController.applyToolbarValueStyleCommand("numberForm",t||null),!0),setStylisticSet:t=>(e.styleController.applyToolbarValueStyleCommand("stylisticSet",t),!0)}}function RC(e,t){const n=Ax(e),r=n&&Jr(n.run);if(!n||!r)return e;const{paragraphIndex:o,run:a}=n,i=ko(e).map((e,n)=>n!==o?ho(e):{...ho(e),runs:e.runs.map(e=>e.id===a.id&&"textBox"===e.kind?{...e,textBox:{...e.textBox,shape:t(e.textBox.shape??{})}}:na(e))});return Vt(e,i,H(i,Ri(e)))}function AC(e,t){return{...e??{type:"floating",allowOverlap:!0,positionV:{relativeFrom:"paragraph",offset:0}},type:"floating",wrap:"none"===e?.wrap?e.wrap:e?.wrap??"square",behindDoc:e?.behindDoc,positionH:{relativeFrom:"margin",align:t,offset:0}}}function MC(e,t,n){const r={...e??{type:"floating",allowOverlap:!0,positionH:{relativeFrom:"column",offset:0},positionV:{relativeFrom:"paragraph",offset:0}},type:"floating"},o=r.positionH??{},a=r.positionV??{};return{...r,wrap:"none"===r.wrap?r.wrap:r.wrap??"square",positionH:{...o,offset:(o.offset??0)+Math.round(t*Ao),align:void 0},positionV:{...a,offset:(a.offset??0)+Math.round(n*Ao)}}}function OC(e,t){const n=Ki(e,e=>"image"===e.kind||"textBox"===e.kind);if(!n)return e;const r=function(e){if(!Number.isFinite(e))return;const t=(Math.round(e)%360+360)%360;return 0===t?void 0:t}(t),{paragraphIndex:o,run:a}=n,i=ko(e).map((e,t)=>t!==o?ho(e):{...ho(e),runs:e.runs.map(e=>e.id!==a.id?na(e):"image"===e.kind?{...e,image:{...e.image,rotation:r}}:"textBox"===e.kind?{...e,textBox:{...e.textBox,rotation:r}}:na(e))});return Vt(e,i,H(i,Ri(e)))}function BC(e,t,n=90){return FC(e,e=>{const r="right"===t?-n:n,o=function(e){if(!Number.isFinite(e))return;const t=(Math.round(e)%360+360)%360;return 0===t?void 0:t}((e.rotation??0)+r);return{...e,rotation:o}})}function FC(e,t){const n=Ax(e);if(!n||!Jr(n.run))return e;const{paragraphIndex:r,run:o}=n,a=ko(e).map((e,n)=>n!==r?ho(e):{...ho(e),runs:e.runs.map(e=>e.id===o.id&&"textBox"===e.kind?{...e,textBox:t(e.textBox)}:na(e))});return Vt(e,a,H(a,Ri(e)))}function EC(e,t){return FC(e,e=>({...e,body:t(e.body??{})}))}var DC={normal:"toolbar.style.builtin.normal",heading1:"toolbar.style.builtin.heading1",heading2:"toolbar.style.builtin.heading2",heading3:"toolbar.style.builtin.heading3",heading4:"toolbar.style.builtin.heading4",heading5:"toolbar.style.builtin.heading5",heading6:"toolbar.style.builtin.heading6",heading7:"toolbar.style.builtin.heading7",heading8:"toolbar.style.builtin.heading8",heading9:"toolbar.style.builtin.heading9",title:"toolbar.style.builtin.title",subtitle:"toolbar.style.builtin.subtitle",caption:"toolbar.style.builtin.caption",quote:"toolbar.style.builtin.quote",emphasis:"toolbar.style.builtin.emphasis",strong:"toolbar.style.builtin.strong",header:"toolbar.style.builtin.header",footer:"toolbar.style.builtin.footer",footnoteText:"toolbar.style.builtin.footnoteText",footnoteReference:"toolbar.style.builtin.footnoteReference"};function LC(e,t=!0){const n=L(e)??(t?wx(e):void 0);return n?DC[n]:void 0}function NC(e){return{documentStyles:()=>{const t=e.state().document,n=t?.styles??{},r=/* @__PURE__ */new Set;for(const e of ci(t)){e.style?.styleId&&r.add(e.style.styleId);for(const t of e.runs)t.styles?.styleId&&r.add(t.styles.styleId)}return Object.values(n).map(e=>{const o=ua(e.id,n),a="table"===e.type?Zr(e.id,n).tableStyle:void 0,i=a?.conditionalFormats?.wholeTable,s=a?.conditionalFormats?.firstRow,l=a?.conditionalFormats?.band1Horz,c=i?.borders?.borderBottom??a?.borders?.borderBottom;return{id:e.id,name:e.name,labelKey:LC(e,!t.sourcePackage),type:e.type,qFormat:e.qFormat,uiPriority:e.uiPriority,semiHidden:e.semiHidden,unhideWhenUsed:e.unhideWhenUsed,isUsed:r.has(e.id),fontFamily:o.fontFamily?.trim()||void 0,fontSize:"number"==typeof o.fontSize?o.fontSize:void 0,color:o.color??void 0,bold:o.bold??void 0,italic:o.italic??void 0,tablePreview:a?{wholeFill:i?.shading,headerFill:s?.shading,bandFill:l?.shading,borderColor:c?.color,headerColor:s?.textStyle?.color??void 0}:void 0}})},newDocument:()=>e.newDocument(),saveDocument:()=>e.saveDocument(),openSymbolDialog:()=>e.openSymbolDialog(),openCommandSearch:()=>e.openCommandSearch(),repeatLastAction:()=>e.repeatLastAction(),openEquationDialog:()=>e.openEquationDialog(),hasActiveTable:()=>km(e.state()),openTableProperties:t=>e.openTablePropertiesDialog(t??"table"),exportDocx:()=>{e.docIO.handleExportDocx()},exportPdf:()=>{e.docIO.handleExportPdf()},printDocument:()=>{e.docIO.handlePrint()},importDocument:()=>e.importInputRef()?.click(),insertImage:()=>e.imageInputRef()?.click(),insertHtml:t=>e.applyTransactionalState(e=>function(e,t){if(!t.trim())return e;const n=hr(t),r=Hr(n)[0]?.blocks??[];if(0===r.length)return e;if(r.every(e=>"paragraph"===e.type))return rp(e,r.map(e=>({runs:e.runs.map(e=>({text:e.text,styles:e.styles,..."image"===e.kind?{image:e.image}:{}})),style:e.style,list:e.list})));const o=ga(e.selection)?e:te(e),{paragraph:a,offset:i}=ae(o),s=Ln(a,0,i),l=Ln(a,i,oi(a)),c=Go(""),d={...a,runs:s.length?s:Go("").runs},u={...a,id:c.id,runs:l.length?l:c.runs},p=[...i>0?[d]:[],...r,...l.length||"table"===r[r.length-1]?.type?[u]:[]];let f=!1;const g=e=>{let t=!1;const n=e.flatMap(e=>{if("paragraph"===e.type&&e.id===a.id)return f=!0,t=!0,p;if("table"!==e.type)return[e];let n=!1;const r=e.rows.map(e=>{let t=!1;const r=e.cells.map(e=>{const n=g(e.blocks);return n===e.blocks?e:(t=!0,{...e,blocks:n})});return t?(n=!0,{...e,cells:r}):e});return n?(t=!0,[{...e,rows:r}]):[e]});return t?n:e},m=o.activeZone??"main";let h=o.document;if("footnote"===m&&o.activeFootnoteId&&o.document.footnotes?.items[o.activeFootnoteId]){const e=o.document.footnotes,t=e.items[o.activeFootnoteId],n=g(t.blocks);f&&(h={...o.document,footnotes:{...e,items:{...e.items,[o.activeFootnoteId]:{...t,blocks:n}}}})}else{const t=Hr(o.document),n=Math.max(0,Math.min(o.activeSectionIndex??0,t.length-1)),r=t[n];if(!r)return e;const a="header"===m?"header":"footer"===m?"footer":"blocks",i=g(r[a]??[]);if(f){const e=[...t];e[n]={...r,[a]:i},h={...o.document,sections:e}}}if(!f)return e;const b=r[r.length-1],y="paragraph"!==b.type||l.length?xi(u,0):xi(b,oi(b));return{...o,document:h,selection:J(y)}}(e,t)),insertShape:t=>e.applyTransactionalState(e=>function(e,t){const n=ga(e.selection)?e:te(e),{paragraph:r,index:o,offset:a}=ae(n),i=function(e){switch(e.document.design?.effectsId){case"flat":return{fill:"#e2e8f0",border:"#64748b"};case"intense":return{fill:"#0f766e",border:"#115e59"};case"moderate":return{fill:"#5b9bd5",border:"#2f75b5"};default:return{fill:"#4472C4",border:"#2F528F"}}}(n),s={width:150,height:100,blocks:[Go("")],shape:{preset:t,fill:i.fill,borderColor:i.border,borderWidthPt:1},floating:mv(void 0,"front")},l=di("",gt(r,a),void 0,s),c=u(r,a,[l]),d=ko(n).map((e,t)=>t===o?c:ho(e));return Vt(n,d,J(xi(c,a+1)))}(e,t)),setShapeFill:t=>e.applyTransactionalState(e=>function(e,t){return RC(e,e=>({...e,fill:t??void 0}))}(e,t),{mergeKey:rg}),setShapeOutline:t=>e.applyTransactionalState(e=>{return n=t,RC(e,e=>({...e,borderColor:n??void 0}));var n},{mergeKey:og}),setShapeOutlineWidth:t=>e.applyTransactionalState(e=>function(e,t){return RC(e,e=>({...e,borderWidthPt:Math.max(0,t)}))}(e,t),{mergeKey:ag}),alignFloatingObject:t=>e.applyTransactionalState(e=>function(e,t){const n=Ki(e,e=>"image"===e.kind||"textBox"===e.kind);if(!n)return e;const{paragraphIndex:r,run:o}=n,a=ko(e).map((e,n)=>n!==r?ho(e):{...ho(e),runs:e.runs.map(e=>e.id!==o.id?na(e):"image"===e.kind?{...e,image:{...e.image,floating:AC(e.image.floating,t)}}:"textBox"===e.kind?{...e,textBox:{...e.textBox,floating:AC(e.textBox.floating,t)}}:na(e))});return Vt(e,a,H(a,Ri(e)))}(e,t),{mergeKey:ig}),reorderFloatingObject:t=>e.applyTransactionalState(e=>function(e,t){const n=Ki(e,e=>"image"===e.kind||"textBox"===e.kind);if(!n)return e;const{paragraphIndex:r,run:o}=n,a=e=>({...e??{type:"floating",allowOverlap:!0,positionH:{relativeFrom:"column",offset:0},positionV:{relativeFrom:"paragraph",offset:0}},type:"floating",wrap:"none",behindDoc:"back"===t}),i=ko(e).map((e,t)=>t!==r?ho(e):{...ho(e),runs:e.runs.map(e=>e.id!==o.id?na(e):"image"===e.kind?{...e,image:{...e.image,floating:a(e.image.floating)}}:"textBox"===e.kind?{...e,textBox:{...e.textBox,floating:a(e.textBox.floating)}}:na(e))});return Vt(e,i,H(i,Ri(e)))}(e,t),{mergeKey:sg}),nudgeFloatingObject:(t,n)=>e.applyTransactionalState(e=>function(e,t,n){const r=Ki(e,e=>"image"===e.kind||"textBox"===e.kind);if(!r)return e;const{paragraphIndex:o,run:a}=r,i=ko(e).map((e,r)=>r!==o?ho(e):{...ho(e),runs:e.runs.map(e=>e.id!==a.id?na(e):"image"===e.kind?{...e,image:{...e.image,floating:MC(e.image.floating,t,n)}}:"textBox"===e.kind?{...e,textBox:{...e.textBox,floating:MC(e.textBox.floating,t,n)}}:na(e))});return Vt(e,i,H(i,Ri(e)))}(e,t,n),{mergeKey:lg}),setFloatingFixedPosition:t=>e.applyTransactionalState(e=>function(e,t){const n=Ki(e,e=>"image"===e.kind||"textBox"===e.kind);if(!n)return e;const{paragraphIndex:r,run:o}=n,a=ko(e).map((e,n)=>n!==r?ho(e):{...ho(e),runs:e.runs.map(e=>{if(e.id!==o.id)return na(e);if("image"===e.kind){const n=e.image.floating;return{...e,image:{...e.image,floating:n?bv(n,t):n}}}if("textBox"===e.kind){const n=e.textBox.floating;return{...e,textBox:{...e.textBox,floating:n?bv(n,t):n}}}return na(e)})});return Vt(e,a,H(a,Ri(e)))}(e,t),{mergeKey:cg}),setFloatingRotation:t=>e.applyTransactionalState(e=>OC(e,t),{mergeKey:dg}),setFloatingWrapPreset:t=>e.applyTransactionalState(e=>function(e,t){const n=Ki(e,e=>"image"===e.kind||"textBox"===e.kind);if(!n)return e;const r=e=>mv(e,t),{paragraphIndex:o,run:a}=n,i=ko(e).map((e,t)=>t!==o?ho(e):{...ho(e),runs:e.runs.map(e=>{if(e.id!==a.id)return na(e);if("image"===e.kind){const t=r(e.image.floating),n=t?{...e.image,floating:t}:(()=>{const{floating:t,...n}=e.image;return n})();return{...e,image:n}}if("textBox"===e.kind){const t=r(e.textBox.floating),n=t?{...e.textBox,floating:t}:(()=>{const{floating:t,...n}=e.textBox;return n})();return{...e,textBox:n}}return na(e)})});return Vt(e,i,H(i,Ri(e)))}(e,t),{mergeKey:ug}),setFloatingWrapText:t=>e.applyTransactionalState(e=>function(e,t){const n=Ki(e,e=>"image"===e.kind||"textBox"===e.kind);if(!n)return e;const r=e=>{if(!e)return e;if("bothSides"===t){const{wrapText:t,...n}=e;return n}return{...e,wrapText:t}},{paragraphIndex:o,run:a}=n,i=ko(e).map((e,t)=>t!==o?ho(e):{...ho(e),runs:e.runs.map(e=>e.id!==a.id?na(e):"image"===e.kind?{...e,image:{...e.image,floating:r(e.image.floating)}}:"textBox"===e.kind?{...e,textBox:{...e.textBox,floating:r(e.textBox.floating)}}:na(e))});return Vt(e,i,H(i,Ri(e)))}(e,t),{mergeKey:pg}),setFloatingPositionPreset:t=>e.applyTransactionalState(e=>function(e,t){const n=Ki(e,e=>"image"===e.kind||"textBox"===e.kind);if(!n)return e;const{h:r,v:o}=function(e){return{h:e.endsWith("Left")?"left":e.endsWith("Right")?"right":"center",v:e.startsWith("top")?"top":e.startsWith("bottom")?"bottom":"ctr"}}(t),a={relativeFrom:"margin",align:r,offset:0},i={relativeFrom:"margin",align:o,offset:0},{paragraphIndex:s,run:l}=n,c=ko(e).map((e,t)=>t!==s?ho(e):{...ho(e),runs:e.runs.map(e=>{if(e.id!==l.id)return na(e);if("image"===e.kind){const t={...e.image.floating??{type:"floating",allowOverlap:!0},type:"floating",wrap:"none"===e.image.floating?.wrap?e.image.floating.wrap:e.image.floating?.wrap??"square",behindDoc:e.image.floating?.behindDoc,positionH:a,positionV:i};return{...e,image:{...e.image,floating:t}}}if("textBox"===e.kind){const t={...e.textBox.floating??{type:"floating",allowOverlap:!0},type:"floating",wrap:"none"===e.textBox.floating?.wrap?e.textBox.floating.wrap:e.textBox.floating?.wrap??"square",behindDoc:e.textBox.floating?.behindDoc,positionH:a,positionV:i};return{...e,textBox:{...e.textBox,floating:t}}}return na(e)})});return Vt(e,c,H(c,Ri(e)))}(e,t),{mergeKey:fg}),setShapePreset:t=>e.applyTransactionalState(e=>function(e,t){return RC(e,e=>({...e,preset:t}))}(e,t),{mergeKey:gg}),setTextBoxTextDirection:t=>e.applyTransactionalState(e=>function(e,t){const n="horz"===t?"horz":"vert"===t?"vert":"vert270"===t?"vert270":"wordArtVert";return EC(e,e=>({...e,vert:n}))}(e,t),{mergeKey:mg}),setTextBoxVerticalAlign:t=>e.applyTransactionalState(e=>function(e,t){const n="b"===t?"b":"ctr"===t?"ctr":"t";return EC(e,e=>({...e,anchor:n}))}(e,t),{mergeKey:hg}),setTextBoxAlt:t=>e.applyTransactionalState(e=>function(e,t){return FC(e,e=>({...e,alt:t??void 0}))}(e,t),{mergeKey:bg}),rotateTextBox:t=>e.applyTransactionalState(e=>BC(e,t),{mergeKey:yg}),getTextBoxSizeCm:()=>function(e){const t=Ax(e),n=t&&Jr(t.run);return n?{width:n.width/So,height:n.height/So}:null}(e.state()),isTextBoxSelected:()=>null!==Ax(e.state()),setTextBoxWidthCm:t=>e.applyTransactionalState(e=>function(e,t){return FC(e,e=>({...e,width:Math.max(24,Math.round(t*So))}))}(e,t),{mergeKey:vg}),setTextBoxHeightCm:t=>e.applyTransactionalState(e=>function(e,t){return FC(e,e=>({...e,height:Math.max(24,Math.round(t*So))}))}(e,t),{mergeKey:xg})}}function zC(e){return{prompt:()=>e.commandsController.promptForLink(),remove:()=>e.commandsController.removeLinkCommand(),canPrompt:()=>!ga(e.state().selection)||Boolean(e.styleController.toolbarStyleState().link)}}function $C(e){return{promptAlt:()=>e.commandsController.promptForImageAlt(),promptCaption:()=>e.commandsController.promptForImageCaption(),isSelected:()=>Boolean(e.selectedImageRun()),getSizeCm:()=>function(e){const t=vv(e),n=t&&ki(t.run);return n?{width:n.width/So,height:n.height/So}:null}(e.state()),setWidthCm:t=>e.commandsController.applyImageWidthCmCommand(t),setHeightCm:t=>e.commandsController.applyImageHeightCmCommand(t),isCropActive:()=>e.imageCropMode.isActive(),toggleCrop:()=>e.imageCropMode.toggle(),applyCropAspect:t=>e.commandsController.applyImageCropAspectCommand(t),getCropShape:()=>function(e){const t=vv(e);return(t&&ki(t.run))?.cropShape??null}(e.state())?.preset??null,applyCropShape:t=>e.commandsController.applyImageCropShapeCommand(t),applyCropFill:()=>e.commandsController.applyImageCropFillCommand(),applyCropFit:()=>e.commandsController.applyImageCropFitCommand(),resetCrop:()=>e.commandsController.resetImageCropCommand(),getBorder:()=>function(e){const t=vv(e);return(t&&ki(t.run))?.border??null}(e.state()),setBorder:t=>e.commandsController.applyImageBorderCommand(t),flip:t=>e.commandsController.flipImageCommand(t),rotate:t=>e.commandsController.rotateImageCommand(t),getTransparency:()=>function(e){const t=vv(e),n=t&&ki(t.run);return n?n.transparency??0:null}(e.state()),setTransparency:t=>e.commandsController.applyImageTransparencyCommand(t),reset:()=>e.commandsController.resetImageCommand(),canReset:()=>null!==vv(e.state())}}function HC(e){const t=e.clipboardActions??Pp({state:e.state,isReadOnly:e.isReadOnly,applyTransactionalState:e.applyTransactionalState,applyTableAwareParagraphEdit:e.tableOps.applyTableAwareParagraphEdit,clearPreferredColumn:e.clearPreferredColumn,resetTransactionGrouping:e.resetTransactionGrouping,focusInput:e.focusInput});return{canCut:()=>!0,canPaste:()=>!0,hasSelection:t.hasSelection,copy:()=>{t.copy()},cut:()=>{t.cut()},paste:()=>{t.paste("rich")},pasteAsPlainText:()=>{t.paste("text")},pasteMergeFormatting:()=>{t.paste("merge")}}}function WC(e,t){const n=jr(e),r=Lo(e.document);if("header"===n||"footer"===n){const o=Ua(e),a=r[o];if(!a)return e;const i=e.activeHeaderFooterStory??"default",s=fo(a,n,i,t),l=[...r];return l[o]=s,{...e,document:{...e.document,sections:l}}}if("main"===n){const n=Ua(e),o=r[n];if(!o)return e;const a=[...r];return a[n]={...o,blocks:t},{...e,document:{...e.document,sections:a}}}return e}function jC(e,t){return null!==VC(e,t)}function UC(e,t){const n=VC(e,t);if(!n)return e;const{nextBlocks:r}=n,o=WC(e,r),a=r.flatMap(ra);return{...o,selection:KC(e.selection,a)}}function VC(e,t){const n=jr(e);if("footnote"===n)return null;const r=$a(e,n);if(0===r.length)return null;const o=Ri(e),a=function(e,t,n,r){const o=/* @__PURE__ */new Set;for(let s=n;s<=r;s+=1){const e=t[s];if(void 0===e)return null;o.add(e)}if(0===o.size)return null;const a=Math.min(...o),i=Math.max(...o);for(let s=a;s<=i;s+=1)if("paragraph"!==e[s].type)return null;return{lo:a,hi:i}}(r,function(e){const t=[];return e.forEach((e,n)=>{ra(e).forEach(()=>{t.push(n)})}),t}(r),o.startIndex,o.endIndex);if(!a)return null;const{lo:i,hi:s}=a,l=r.slice(i,s+1);let c;if("up"===t){if(0===i)return null;const e=r[i-1];if("paragraph"!==e.type)return null;c=[...r.slice(0,i-1),...l,e,...r.slice(s+1)]}else{if(s===r.length-1)return null;const e=r[s+1];if("paragraph"!==e.type)return null;c=[...r.slice(0,i),e,...l,...r.slice(s+2)]}return{nextBlocks:c}}function KC(e,t){const n=new Map(t.map((e,t)=>[e.id,t])),r=e=>{const r=n.get(e.paragraphId);if(void 0===r)return e;const o=t[r];return xi(o,Math.min(e.offset,oi(o)))};return{anchor:r(e.anchor),focus:r(e.focus)}}function _C(e,t){const n=function(e){const t=jr(e);if("footnote"===t)return null;const n=$a(e,t);if(0===n.length)return null;const r=Ri(e),o=/* @__PURE__ */new Set;for(let s=r.startIndex;s<=r.endIndex;s+=1){let e=0,t=-1;for(let r=0;r<n.length;r+=1){const o=ra(n[r]).length;if(s<e+o){t=r;break}e+=o}if(t<0)return null;o.add(t)}if(0===o.size)return null;const a=Math.min(...o),i=Math.max(...o);for(let s=a;s<=i;s+=1)if("paragraph"!==n[s].type)return null;return{blocks:n,lo:a,hi:i}}(e);if(!n)return e;if(n.hi-n.lo<1)return e;const{lo:r,hi:o,blocks:a}=n,i=a.slice(r,o+1).map((e,t)=>({block:e,index:t,key:XC(mi(e))}));i.sort((e,n)=>{const r=function(e,t){const n=function(e,t){return void 0!==e&&void 0!==t?e===t?0:e<t?-1:1:void 0!==e?-1:void 0!==t?1:0}(e.num,t.num);return 0!==n?n:e.text.localeCompare(t.text,void 0,{sensitivity:"base"})}(e.key,n.key);return 0!==r?t?-r:r:e.index-n.index});const s=[...a.slice(0,r),...i.map(e=>e.block),...a.slice(o+1)],l=WC(e,s),c=s.flatMap(ra);return{...l,selection:qC(e.selection,c)}}function XC(e){const t=e.trim(),n=/^(\d+(?:\.\d+)?)/.exec(t)?.[1];return{num:void 0===n?void 0:Number(n),text:e}}function qC(e,t){const n=new Map(t.map((e,t)=>[e.id,t])),r=e=>{const r=n.get(e.paragraphId);if(void 0===r)return e;const o=t[r];return xi(o,Math.min(e.offset,oi(o)))};return{anchor:r(e.anchor),focus:r(e.focus)}}function GC(e,t){const n=Ri(e),r=ko(e);let a=1;for(let l=0;l<n.startIndex;l+=1){const e=o(r[l]?.style?.styleId);null!==e&&(a=e)}let i=!1;const s=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return ho(e);const s=o(e.style?.styleId);if(e.list&&e.list.kind){const n=e.list.level??0,r=t?Math.max(0,n-1):Math.min(8,n+1);return r===n?ho(e):(i=!0,$e(e,r))}if(null!==s){const n=t?Math.max(1,s-1):Math.min(9,s+1);if(n===s)return ho(e);i=!0;const r=ho(e);return r.style={...e.style??{},styleId:`heading${n}`,outlineLevel:void 0},r}if(!t)return ho(e);i=!0;const l=ho(e);return l.style={...e.style??{},styleId:`heading${a}`,outlineLevel:void 0},l});return i?Vt(e,s,H(s,n)):e}var YC=["align","spacingBefore","spacingAfter","lineHeight","lineRule","indentLeft","indentRight","indentFirstLine","indentHanging","mirrorIndents","contextualSpacing","outlineLevel","shading","borderTop","borderRight","borderBottom","borderLeft","tabs","pageBreakBefore","keepWithNext","keepLinesTogether","widowControl","bidi"];var ZC=/* @__PURE__ */new Set(["auto","exact","atLeast"]);var JC=/* @__PURE__ */new Set(["lrTb","tbRl","btLr","lrTbV","tbRlV"]);var QC={width:1.5,type:"solid",color:"#000000"};function ek(e,t){const n=t.text??mi(e).slice(0,1),r=Math.max(1,Math.min(10,Math.round(t.lines??3))),o=e.runs[0]?.styles,a=t.font;return{text:n,lines:r,type:"margin"===t.type?"margin":"drop",style:void 0!==a?{...o??{},fontFamily:a}:o}}function tk(e){return{togglePageBreakBefore:()=>e.commandsController.toggleParagraphFlagCommand("pageBreakBefore"),toggleKeepWithNext:()=>e.commandsController.toggleParagraphFlagCommand("keepWithNext"),toggleKeepLinesTogether:()=>e.commandsController.toggleParagraphFlagCommand("keepLinesTogether"),toggleWidowControl:()=>e.commandsController.toggleParagraphFlagCommand("widowControl"),setSpacingAfter:t=>e.commandsController.applyParagraphStyleCommand("spacingAfter",t),setSpacingBefore:t=>e.commandsController.applyParagraphStyleCommand("spacingBefore",t),setLineRule:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.lineRule,i=(()=>{if(null!==t&&"auto"!==t)return ZC.has(t)?t:a})();if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{lineRule:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},lineRule:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setTextDirection:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.textDirection,i=null===t||"lrTb"===t?void 0:JC.has(t)?t:a;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{textDirection:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},textDirection:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setSuppressAutoHyphens:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.suppressAutoHyphens,i=null===t?void 0:t;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{suppressAutoHyphens:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},suppressAutoHyphens:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setSuppressLineNumbers:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.suppressLineNumbers,i=null===t?void 0:t;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{suppressLineNumbers:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},suppressLineNumbers:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setKinsoku:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.kinsoku,i=null===t?void 0:t;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{kinsoku:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},kinsoku:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setOverflowPunct:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.overflowPunct,i=null===t?void 0:t;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{overflowPunct:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},overflowPunct:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setWordWrap:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.wordWrap,i=null===t?void 0:t;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{wordWrap:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},wordWrap:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setAutoSpaceDE:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.autoSpaceDE,i=null===t?void 0:t;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{autoSpaceDE:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},autoSpaceDE:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setAutoSpaceDN:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.autoSpaceDN,i=null===t?void 0:t;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{autoSpaceDN:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},autoSpaceDN:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setAdjustRightInd:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.adjustRightInd,i=null===t?void 0:t;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{adjustRightInd:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},adjustRightInd:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setTopLinePunct:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.topLinePunct,i=null===t?void 0:t;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{topLinePunct:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},topLinePunct:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setPageBreakBefore:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.pageBreakBefore,i=null===t?void 0:t;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{pageBreakBefore:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},pageBreakBefore:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setKeepWithNext:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.keepWithNext,i=null===t?void 0:t;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{keepWithNext:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},keepWithNext:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setKeepLinesTogether:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.keepLinesTogether,i=null===t?void 0:t;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{keepLinesTogether:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},keepLinesTogether:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setWidowControl:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.widowControl,i=null===t?void 0:t;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{widowControl:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},widowControl:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setContextualSpacing:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.contextualSpacing,i=null===t?void 0:t;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{contextualSpacing:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},contextualSpacing:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setMirrorIndents:t=>e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e);let o=!1;const a=r.map((e,r)=>{if(r<n.startIndex||r>n.endIndex)return e;const a=e.style?.mirrorIndents,i=null===t?void 0:t;if(a===i)return e;o=!0;const s=void 0===i?(()=>{const{mirrorIndents:t,...n}=e.style??{};return Object.keys(n).length>0?n:void 0})():{...e.style??{},mirrorIndents:i};return{...ho(e),style:s}});return o?Vt(e,a,H(a,n)):e}(e,t)),setIndentLeft:t=>e.commandsController.applyParagraphStyleCommand("indentLeft",t),setIndentRight:t=>e.commandsController.applyParagraphStyleCommand("indentRight",t),setIndentFirstLine:t=>e.commandsController.applyParagraphStyleCommand("indentFirstLine",t),setIndentHanging:t=>e.commandsController.applyParagraphStyleCommand("indentHanging",t),setSpecialIndent:(t,n)=>{const r=n??48;e.applyTransactionalState(e=>{let n=le(e,"indentFirstLine",null);return n=le(n,"indentHanging",null),"firstLine"===t?n=le(n,"indentFirstLine",r):"hanging"===t&&(n=le(n,"indentHanging",r)),n},{mergeKey:gf}),e.focusInput()},setShading:t=>e.commandsController.applyParagraphStyleCommand("shading",t),applyBorders:()=>{const t={width:1,type:"solid",color:"#000000"};e.applyTransactionalState(e=>{let n=le(e,"borderTop",t);return n=le(n,"borderRight",t),n=le(n,"borderBottom",t),n=le(n,"borderLeft",t),n},{mergeKey:mf}),e.focusInput()},addHorizontalLine:()=>{e.applyTransactionalState(e=>le(e,"borderBottom",QC),{mergeKey:mf}),e.focusInput()},setLineHeight:t=>e.commandsController.applyParagraphStyleCommand("lineHeight",t),setListFormat:t=>e.commandsController.handleListFormatChange(t),setListStartAt:t=>e.commandsController.handleListStartAtChange(t),restartList:t=>{e.applyTransactionalState(e=>function(e,t=1){return kS(e,t)}(e,t)),e.focusInput()},continueList:()=>{e.applyTransactionalState(CS),e.focusInput()},setListLevel:t=>{e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=Math.min(8,Math.max(0,Math.round(t))),o=ko(e);let a=!1;const i=o.map((e,t)=>t<n.startIndex||t>n.endIndex?e:e.list?(e.list.level??0)===r?e:(a=!0,$e(e,r)):e);return a?Vt(e,i,H(i,n)):e}(e,t)),e.focusInput()},outdent:()=>{e.clearPreferredColumn(),e.resetTransactionGrouping(),e.tableOps.applySelectionAwareParagraphCommand(e=>BS(e,-1)),e.focusInput()},indent:()=>{e.clearPreferredColumn(),e.resetTransactionGrouping(),e.tableOps.applySelectionAwareParagraphCommand(e=>BS(e,1)),e.focusInput()},moveParagraphsUp:()=>{jC(e.state(),"up")?(e.applyTransactionalState(e=>UC(e,"up"),{mergeKey:hf}),e.focusInput()):e.focusInput()},moveParagraphsDown:()=>{jC(e.state(),"down")?(e.applyTransactionalState(e=>UC(e,"down"),{mergeKey:bf}),e.focusInput()):e.focusInput()},canMoveParagraphsUp:()=>jC(e.state(),"up"),canMoveParagraphsDown:()=>jC(e.state(),"down"),promote:()=>{e.applyTransactionalState(e=>GC(e,!0)),e.focusInput()},demote:()=>{e.applyTransactionalState(e=>GC(e,!1)),e.focusInput()},resetParagraphFormatting:()=>{e.applyTransactionalState(e=>function(e){const t=Ri(e),n=ko(e);let r=!1;const o=n.map((e,n)=>{if(n<t.startIndex||n>t.endIndex)return e;const o=e.style;if(!o||YC.every(e=>!(e in o)))return e;r=!0;const a=ho(e),i=o.styleId?{styleId:o.styleId}:{};return a.style=Object.keys(i).length>0?i:void 0,a});return r?Vt(e,o,H(o,t)):e}(e)),e.focusInput()},setTabStops:t=>{e.resetTransactionGrouping(),e.applyTransactionalState(e=>Yt(e,t),{mergeKey:wf}),e.focusInput()},setOutlineLevel:t=>{e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e),o=null==t?null:Math.min(8,Math.max(0,Math.round(t)));let a=!1;const i=r.map((e,t)=>{if(t<n.startIndex||t>n.endIndex)return e;if((e.style?.outlineLevel??null)===o)return e;a=!0;const r={...e.style??{}};null===o?delete r.outlineLevel:r.outlineLevel=o;const i=ho(e);return i.style=Object.keys(r).length>0?r:void 0,i});return a?Vt(e,i,H(i,n)):e}(e,t)),e.focusInput()},setBidi:t=>e.commandsController.applyParagraphStyleCommand("bidi",t),setParagraphAlign:t=>{e.applyTransactionalState(e=>function(e,t){return le(e,"align",t)}(e,t))},sortParagraphs:(t=!1)=>e.applyTransactionalState(e=>_C(e,t)),hasDropCap:()=>function(e){const t=Ri(e);return ko(e).slice(t.startIndex,t.endIndex+1).some(e=>void 0!==e.dropCap)}(e.state()),setDropCap:t=>{e.applyTransactionalState(e=>function(e,t){const n=Ri(e),r=ko(e),o=n.startIndex,a=n.endIndex,i="none"===t.type||0===t.lines||void 0!==t.text&&0===t.text.length,s=r.map((e,n)=>n<o||n>a?ho(e):i?{...ho(e),dropCap:void 0}:{...ho(e),dropCap:ek(e,{...t,type:"margin"===t.type?"margin":"drop"})});return Vt(e,s,H(s,n))}(e,t)),e.focusInput()}}}function nk(e){const t=Lo(e.document);return{sections:t,sectionIndex:Math.max(0,Math.min(Ua(e),t.length-1))}}function rk(e,t){const{sections:n,sectionIndex:r}=nk(e);if(0===n.length)return e;const o=t(n[r]);if(o===n[r])return e;const a=[...n];return a[r]=o,{...e,document:{...e.document,sections:a}}}function ok(e,t,n="default"){const r=Eo(t,n);return rk(e,e=>e[r]?e:{...e,[r]:[No(t)]})}function ak(e,t,n="default"){const r=Eo(t,n),o=rk(e,e=>e[r]?{...e,[r]:void 0}:e);return o===e?e:jr(o)===t?ck(o):o}function ik(e,t,n="default"){const r=ok(e,t,n),{sections:o,sectionIndex:a}=nk(r),i=(o[a][Eo(t,n)]??[]).flatMap(ra).find(Boolean);return i?{...r,selection:Ii(xi(i,0)),activeSectionIndex:a,activeZone:t,activeHeaderFooterStory:n}:r}function sk(e){const{sections:t,sectionIndex:n}=nk(e),r=t[n];return Boolean(r&&(r.firstPageHeader||r.firstPageFooter))}function lk(e){const{sections:t,sectionIndex:n}=nk(e),r=t[n];return Boolean(r&&(r.evenPageHeader||r.evenPageFooter))}function ck(e){const{sections:t,sectionIndex:n}=nk(e),r=(t[n]?.blocks??[]).flatMap(ra).find(Boolean);return r?{...e,selection:Ii(xi(r,0)),activeSectionIndex:n,activeZone:"main",activeHeaderFooterStory:void 0}:{...e,activeZone:"main",activeHeaderFooterStory:void 0}}function dk(e){return function(e,t){const n=ga(e.selection)?e:te(e),{paragraph:r,index:o,offset:a}=ae(n),i=Ln(r,0,a),s=Ln(r,a,oi(r)),l={id:`run:field:${Math.random().toString(36).slice(2,9)}`,text:"1",kind:"field",field:{type:t},styles:gt(r,a)},c=N(r,[...i,l,...s]),d=ko(n),u=[...Yo(d.slice(0,o)),c,...Yo(d.slice(o+1))];return Vt(n,u,J(xi(c,a+l.text.length)))}(e,"PAGE")}function uk(e,t,n,r){return{id:n,text:"1",kind:"field",field:r&&"decimal"!==r?{type:e,format:r}:{type:e},styles:t}}function pk(e,t){const n=Math.random().toString(36).slice(2,9);return"xOfY"===e?[{id:`run:page-of-prefix:${n}`,text:"Page ",kind:"text"},uk("PAGE",void 0,`run:page-field:${n}`,t),{id:`run:page-of-separator:${n}`,text:" of ",kind:"text"},uk("NUMPAGES",void 0,`run:numpages-field:${n}`,t)]:[uk("PAGE",void 0,`run:page-field:${n}`,t)]}function fk(e,t="page",n){return function(e,t){const n=ga(e.selection)?e:te(e),{paragraph:r,index:o,offset:a}=ae(n),i=gt(r,a),s=t.map((e,t)=>e.styles?e:{...e,styles:i,id:`${e.id}:${t}`}),l=N(r,[...Ln(r,0,a),...s,...Ln(r,a,oi(r))]),c=ko(n),d=[...Yo(c.slice(0,o)),l,...Yo(c.slice(o+1))],u=s.reduce((e,t)=>e+t.text.length,0);return Vt(n,d,J(xi(l,a+u)))}(e,pk(t,n))}function gk(e){const t=Lo(e.document);return{sections:t,sectionIndex:Math.max(0,Math.min(Ua(e),t.length-1))}}function mk(e,t,n={}){const{kind:r="page",format:o,align:a="center"}=n;if("current"===t)return fk(e,r,o);const i="top"===t?"header":"footer",s=Eo(i,"default"),{sections:l,sectionIndex:c}=gk(e);if(0===l.length)return e;const d={id:_o("paragraph"),type:"paragraph",runs:pk(r,o),style:{styleId:i,align:a}},u={...l[c],[s]:[d]},p=[...l];return p[c]=u,{...e,document:{...e.document,sections:p},selection:Ii(xi(d,0)),activeSectionIndex:c,activeZone:i}}function hk(e){const t={isLandscape:()=>{const t=Ua(e.state());return"landscape"===(e.state().document.sections?.[t]??e.state().document)?.pageSettings?.orientation},setOrientation:t=>{const n=Ua(e.state()),r=e.state().document.sections?.[n]??e.state().document;r&&e.commandsController.applyUpdateSectionSettingsCommand(n,{pageSettings:{...r.pageSettings,orientation:t}})},toggleOrientation:()=>{const n=Ua(e.state()),r=e.state().document.sections?.[n]??e.state().document;if(!r)return;const o=r.pageSettings?.orientation??"portrait";t.setOrientation("portrait"===o?"landscape":"portrait")},breakNextPage:()=>e.commandsController.applyInsertSectionBreakCommand("nextPage"),breakContinuous:()=>e.commandsController.applyInsertSectionBreakCommand("continuous"),breakEvenPage:()=>e.commandsController.applyInsertSectionBreakCommand("evenPage"),breakOddPage:()=>e.commandsController.applyInsertSectionBreakCommand("oddPage"),breakNextColumn:()=>e.commandsController.applyInsertSectionBreakCommand("nextColumn"),getMargins:()=>{const t=Ua(e.state());return(e.state().document.sections?.[t]??e.state().document)?.pageSettings?.margins},setPageMargins:t=>{const n=Ua(e.state()),r=e.state().document.sections?.[n]??e.state().document;r?.pageSettings&&e.commandsController.applyUpdateSectionSettingsCommand(n,{pageSettings:{...r.pageSettings,margins:{...r.pageSettings.margins,...t}}})},setMarginsPreset:t=>{e.applyTransactionalState(e=>mt(e,t)),e.focusInput()},getPageNumbering:()=>{const t=Ua(e.state());return e.state().document.sections?.[t]?.pageNumbering},setPageNumbering:t=>{e.applyTransactionalState(e=>function(e,t){const{sections:n,sectionIndex:r}=gk(e);if(0===n.length)return e;const o={...n[r].pageNumbering,...void 0!==t.start?{start:t.start}:{},...void 0!==t.format?{format:t.format}:{}};return i(e,r,{pageNumbering:o})}(e,t)),e.focusInput()},getPaperSize:()=>xn(e.state()),setPaperSize:t=>{e.applyTransactionalState(e=>kr(e,t)),e.focusInput()},setPaperSizePreset:t=>{e.applyTransactionalState(e=>Se(e,t)),e.focusInput()},getColumns:()=>Nn(e.state()),setColumns:t=>{e.applyTransactionalState(e=>Mr(e,t)),e.focusInput()},getVerticalAlign:()=>rt(e.state()),setVerticalAlign:t=>{e.applyTransactionalState(e=>m(e,t)),e.focusInput()},getSectionStart:()=>{const t=Ua(e.state());return e.state().document.sections?.[t]?.breakType},setSectionStart:t=>{const n=Ua(e.state());(e.state().document.sections?.[n]??e.state().document)&&e.commandsController.applyUpdateSectionSettingsCommand(n,{breakType:t})},getBidi:()=>jt(e.state()),setBidi:t=>{e.applyTransactionalState(e=>mr(e,t)),e.focusInput()},getHyphenation:()=>function(e){const t=e.document.settings;return{value:!0===t?.autoHyphenation,zone:t?.hyphenationZone,caps:t?.doNotHyphenateCaps,limit:t?.consecutiveHyphenLimit}}(e.state()),setHyphenation:t=>{e.applyTransactionalState(e=>function(e,t){const n=e.document.settings,r={...n??{},...void 0!==t.value?{autoHyphenation:t.value}:void 0!==n?.autoHyphenation?{autoHyphenation:n.autoHyphenation}:{},...void 0!==t.zone?{hyphenationZone:t.zone}:void 0!==n?.hyphenationZone?{hyphenationZone:n.hyphenationZone}:{},...void 0!==t.caps?{doNotHyphenateCaps:t.caps}:void 0!==n?.doNotHyphenateCaps?{doNotHyphenateCaps:n.doNotHyphenateCaps}:{},...void 0!==t.limit?{consecutiveHyphenLimit:t.limit}:void 0!==n?.consecutiveHyphenLimit?{consecutiveHyphenLimit:n.consecutiveHyphenLimit}:{}};return{...e,document:{...e.document,settings:r}}}(e,t)),e.focusInput()}};return t}function bk(e){const t=t=>{e.applyTransactionalState(t),e.focusInput()};return{editHeader:()=>t(e=>ik(e,"header")),editFooter:()=>t(e=>ik(e,"footer")),editFirstPageHeader:()=>t(e=>ik(e,"header","firstPage")),editEvenPageHeader:()=>t(e=>ik(e,"header","evenPage")),editFirstPageFooter:()=>t(e=>ik(e,"footer","firstPage")),editEvenPageFooter:()=>t(e=>ik(e,"footer","evenPage")),insertPageNumber:()=>t(e=>dk(e)),insertPageNumberXOfY:()=>t(e=>fk(e,"xOfY")),placePageNumberTop:()=>t(e=>mk(e,"top")),placePageNumberBottom:()=>t(e=>mk(e,"bottom")),exit:()=>t(e=>function(e){return ck(e)}(e)),isInHeaderFooter:()=>{const t=e.state().activeZone;return"header"===t||"footer"===t},getDifferentFirstPage:()=>sk(e.state()),setDifferentFirstPage:e=>t(t=>function(e,t){if(sk(e)===t)return e;let n=e;return t?(n=ok(n,"header","firstPage"),n=ok(n,"footer","firstPage"),n):(n=ak(n,"header","firstPage"),ak(n,"footer","firstPage"))}(t,e)),getDifferentOddEven:()=>lk(e.state()),setDifferentOddEven:e=>t(t=>function(e,t){if(lk(e)===t)return e;let n=e;return t?(n=ok(n,"header","evenPage"),n=ok(n,"footer","evenPage"),n):(n=ak(n,"header","evenPage"),ak(n,"footer","evenPage"))}(t,e))}}function yk(e){const t=e.document.bookmarks;return t?t.order.map(e=>t.items[e]).filter(e=>Boolean(e)):[]}function vk(e){return{insert:t=>{e.applyTransactionalState(e=>function(e,t){const{start:n,end:r,isCollapsed:o}=Ri(e),a=e.document.bookmarks,i=a?.order??[],s=t&&t.trim().length>0?t.trim():`Bookmark${i.length+1}`,l={id:_r(),name:s,start:{paragraphId:n.paragraphId,offset:n.offset},...o?{}:{end:{paragraphId:r.paragraphId,offset:r.offset}}},c={items:{...a?.items??{},[l.id]:l},order:[...i,l.id]},d={...e.document,bookmarks:c};return{...e,document:d}}(e,t)),e.focusInput()},remove:t=>{e.applyTransactionalState(e=>function(e,t){const n=e.document.bookmarks;if(!n||!n.items[t])return e;const r={...n.items};delete r[t];const o={items:r,order:n.order.filter(e=>e!==t)};return{...e,document:{...e.document,bookmarks:o}}}(e,t)),e.focusInput()},list:()=>yk(e.state()).map(e=>({id:e.id,name:e.name}))}}var xk=["January","February","March","April","May","June","July","August","September","October","November","December"],wk=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function Ik(e,t){let n="";const r=e=>String(e).padStart(2,"0");let o=0;const a=t;for(;o<a.length;){const t=a[o];let i=t;for(;o+i.length<a.length&&a[o+i.length]===t;)i+=t;const s=e.getHours();switch(t){case"d":n+=i.length>=4?wk[e.getDay()]:3===i.length?wk[e.getDay()].slice(0,3):2===i.length?r(e.getDate()):String(e.getDate());break;case"M":n+=i.length>=4?xk[e.getMonth()]:3===i.length?xk[e.getMonth()].slice(0,3):2===i.length?r(e.getMonth()+1):String(e.getMonth()+1);break;case"y":n+=i.length>=3?String(e.getFullYear()):String(e.getFullYear()).slice(-2);break;case"H":n+=r(s);break;case"h":n+=i.length>=2?r(s%12==0?12:s%12):String(s%12==0?12:s%12);break;case"m":n+=i.length>=2?r(e.getMinutes()):String(e.getMinutes());break;case"s":n+=i.length>=2?r(e.getSeconds()):String(e.getSeconds());break;default:if(a.slice(o).toLowerCase().startsWith("am/pm")){n+=s<12?"am":"pm",o+=5;continue}n+=t}o+=i.length}return n}var Sk=e=>f(e,void 0,void 0,void 0,{cachedBodyPageFields:!0});function Ck(e,t){const n=t.get(e.paragraphId);if(!n)return e;let r=0;for(const o of n.edits){if(e.offset<=o.start)break;if(e.offset<o.end)throw Error("interior anchor must be rejected before mapping");r+=o.text.length-(o.end-o.start)}return r?{...e,offset:e.offset+r}:e}function kk(e,t){if(!e)return e;let n=!1;const r={...e.items};for(const[o,a]of Object.entries(r)){const e=a.start?Ck(a.start,t):void 0,i=a.end?Ck(a.end,t):void 0;e===a.start&&i===a.end||(r[o]={...a,start:e,end:i},n=!0)}return n?{...e,items:r}:e}function Tk(e,t,n){const r=t.get(e.paragraphId)?.edits.find(t=>t.runId===e.runId);if(!r)return e;const o=e.offset===r.end-r.start?r.text.length:"selection"===n?Math.min(e.offset,r.text.length):e.offset;return o===e.offset?e:{...e,offset:o}}function Pk(e){return!e.list&&!e.dropCap&&!e.sdtWrappers?.length&&!e.numberingRevision&&!e.style?.bidi&&(!e.style?.textDirection||"lrTb"===e.style.textDirection)&&e.runs.every($)&&new Set(e.runs.map(e=>e.id)).size===e.runs.length}function Rk(e){const t=/* @__PURE__ */new Map;for(const n of[e.document.bookmarks,e.document.comments])for(const e of Object.values(n?.items??{}))for(const n of[e.start,e.end]){if(!n)continue;const e=t.get(n.paragraphId)??[];e.push(n.offset),t.set(n.paragraphId,e)}return t}function Ak(e,t=Sk,n="all",r){const o=r||e.document.coreTimestamps?{...e.document.coreTimestamps,...r}:void 0,a=t(e.document),i=(t,n)=>({state:e,layout:a,status:t,passes:n,updatedFields:0}),s=Lo(e.document),l=s.flatMap(e=>e.blocks);if(e.trackChangesEnabled||"main"!==jr(e)||Object.keys(e.document.footnotes?.items??{}).length||Object.keys(e.document.endnotes?.items??{}).length||s.some((e,t)=>t>0&&e.breakType&&"nextPage"!==e.breakType)||l.some(e=>"paragraph"!==e.type)||new Set(l.map(e=>e.id)).size!==l.length)return i("unsupported",0);let c=/* @__PURE__ */new Map;if(ze(l,c),"selection"===n&&(c=function(e,t,n){const r=e=>{const n=t.findIndex(t=>t.id===e.paragraphId);if(n<0)return;const r=t[n],o=r.runs.findIndex(t=>t.id===e.runId);return o<0||!Number.isInteger(e.offset)||e.offset<0||e.offset>r.runs[o].text.length?void 0:{index:n,runIndex:o,offset:r.runs.slice(0,o).reduce((e,t)=>e+t.text.length,0)+e.offset,affinity:e.fieldBoundaryAffinity}},o=r(e.selection.anchor),a=r(e.selection.focus),i=/* @__PURE__ */new Map;if(!o||!a)return i;const[s,l]=o.index<a.index||o.index===a.index&&o.offset<=a.offset?[o,a]:[a,o],c=s.index===l.index&&s.offset===l.offset;if(c&&(o.runIndex!==a.runIndex||o.affinity!==a.affinity))return i;for(let d=s.index;d<=l.index;d++){const e=t[d],r=n.get(e.id);if(!r)continue;let o=0;const a=e.runs.map(e=>{const t=o;return o+=e.text.length,t}),u=r.filter(t=>{const n=a[t.runIndex],r=n+e.runs[t.runIndex].text.length;return n!==r&&(c?!("before-markers"===s.affinity&&s.offset===n||"after-markers"===s.affinity&&s.offset===r)&&(s.offset>n&&s.offset<r||s.runIndex===t.runIndex&&s.offset>=n&&s.offset<=r):n<(d===l.index?l.offset:o)&&r>(d===s.index?s.offset:0))});u.length&&i.set(e.id,u)}return i}(e,l,c)),!c.size)return i("unchanged",0);const d=wi(e.document);let u=e,p=a;const f=/* @__PURE__ */new Set,g=/* @__PURE__ */new Set;for(let m=1;m<=6;m++){const r=Y(u.document,p),a=De(u.document,p),s=Lo(u.document),l=Rk(u),h=/* @__PURE__ */new Map,b=/* @__PURE__ */new Map;for(const e of p.pages)for(const t of e.blocks){if("paragraph"!==t.sourceBlock.type||!t.layout)continue;const n=t.sourceBlock.id,r=t.layout.startOffset??0,o=t.layout.endOffset??r+t.layout.text.length;r!==(b.get(n)??0)||o<r||o-r!==t.layout.text.length||o>oi(t.sourceBlock)?h.set(n,null):(b.set(n,o),h.has(n)?h.get(n)!==e.index&&h.set(n,null):h.set(n,e.index))}const y=/* @__PURE__ */new Map,v=/* @__PURE__ */new Set,x=[];for(const e of s)for(const t of e.blocks){if("paragraph"!==t.type||!Pk(t))continue;const i=c.get(t.id),p=h.get(t.id);if(!i||null==p||b.get(t.id)!==oi(t))continue;const g=r.forPage(p),m=[];let w=0;for(const e of t.runs)m.push(w),w+=e.text.length;for(const{runIndex:r,field:c}of i){const i=t.runs[r],h=JSON.stringify([t.id,r]);if(x.push(JSON.stringify([h,i.text,p])),"PAGE"===c.type&&!c.format&&e.pageNumbering?.format&&"decimal"!==e.pageNumbering.format)continue;if("PAGEREF"===c.type&&s.some(e=>e.pageNumbering?.format&&"decimal"!==e.pageNumbering.format))continue;const b=i.styles?.language?.value?.toLowerCase(),I="pt-br"===b?"pt-BR":b?.startsWith("en")?"en-US":o?.locale,S=la(c,{...g,styleRefText:(e,n,o)=>a.forBody(t.id,e,n,{output:o,offset:m[r],locale:"pt-BR"===I?"pt-BR":"en-US"}),sequenceValue:d.get(Mi(t.id,r)),documentVariables:u.document.documentVariables,documentProperties:u.document.documentProperties,temporal:o?{...o,locale:I}:void 0},i.text),C=m[r],k=C+i.text.length;if("resolved"!==S.status||!S.text.length||S.text.length>65536||!i.text.length||/[\r\n\t]/.test(S.text)||Array.from(S.text).length!==S.text.length)continue;if(S.text!==i.text&&((l.get(t.id)??[]).some(e=>!Number.isInteger(e)||e<0||e>w||e>C&&e<k)||"all"===n&&[u.selection.anchor,u.selection.focus].some(e=>e.paragraphId===t.id&&e.runId===i.id&&0!==e.offset&&e.offset!==i.text.length)))continue;if(v.add(h),S.text===i.text)continue;const T=y.get(t.id)??{paragraph:t,edits:[]};T.edits.push({runIndex:r,runId:i.id,start:C,end:k,text:S.text}),y.set(t.id,T),f.add(h)}}if([...f].some(e=>!v.has(e)))return i("nonconvergent",m);if(!y.size)return{state:u,layout:p,status:u===e?"unchanged":"updated",passes:m,updatedFields:f.size};const w=JSON.stringify([p.pages.length,x]);if(g.has(w))return i("nonconvergent",m);g.add(w);for(const e of y.values())e.edits.sort((e,t)=>e.start-t.start);const I={...u.document,sections:s.map(e=>({...e,blocks:e.blocks.map(e=>{const t=y.get(e.id);if("paragraph"!==e.type||!t)return e;const n=new Map(t.edits.map(e=>[e.runIndex,e.text]));return{...e,runs:e.runs.map((e,t)=>n.has(t)?{...e,text:n.get(t)}:e)}})})),bookmarks:kk(u.document.bookmarks,y),comments:kk(u.document.comments,y)};u={...u,document:I,selection:{anchor:Tk(u.selection.anchor,y,n),focus:Tk(u.selection.focus,y,n)}},p=t(I)}return i("nonconvergent",6)}var Mk=(e,t)=>e.length<=t&&!!e.trim()&&!/[\u0000-\u001f\u007f]/.test(e);function Ok(e){const t=La(e);if(t.error||"XE"!==t.command)return;const[n,...r]=t.tokens.slice(1);if("quoted"!==n?.kind||!Mk(n.value,4096)||n.value.includes("\\"))return;const o=n.value.split(":");if(o.length>9||o.some(e=>!Mk(e,1024)))return;let a,i=!1,s=!1,l={kind:"page"};const c=/* @__PURE__ */new Set;for(let d=0;d<r.length;d++){const e=r[d];if("switch"!==e.kind)return;const t=e.value.toLowerCase();if(c.has(t))return;if(c.add(t),"b"===t){i=!0;continue}if("i"===t){s=!0;continue}if("f"!==t&&"r"!==t&&"t"!==t)return;const n=r[++d];if(!n||"switch"===n.kind)return;if("f"!==t){if("page"!==l.kind)return;if("r"===t){if(!/^[A-Za-z_][A-Za-z0-9_]{0,39}$/.test(n.value))return;l={kind:"bookmarkRange",bookmark:n.value}}else{if("quoted"!==n.kind||!Mk(n.value,4096))return;l={kind:"crossReference",text:n.value}}}else{if(!/^[A-Za-z]$/.test(n.value))return;a=n.value}}return"crossReference"!==l.kind||!i&&!s?{path:o,...void 0===a?{}:{identifier:a},boldPage:i,italicPage:s,reference:l}:void 0}function Bk(e){const t=[],n=/* @__PURE__ */new Set;for(const[r,o]of Lo(e).entries()){const e=[];for(const t of o.blocks){if("paragraph"!==t.type||n.has(t.id)||t.runs.some(e=>"textBox"===e.kind||"opaque"===e.kind))return;n.add(t.id),e.push(t)}const a=Ga(e);if(a.diagnostics.length)return;for(const n of a.spans){const o=n.code.map(e=>"instruction"===e.kind?e.raw:"").join("");if("XE"!==La(o).command&&!/^\s*XE(?=\s|\\|"|$)/i.test(o))continue;const a=Ok(o);if(!a||null!==n.parentIndex||!n.end||n.separator||n.begin.paragraphIndex!==n.end.paragraphIndex||n.beginMarker.fieldLock||n.beginMarker.dirty||n.code.some(e=>"instruction"!==e.kind)||n.result.length)return;const i=e[n.begin.paragraphIndex];if(i.sdtWrappers?.length||i.numberingRevision||i.dropCap||new Set(i.runs.map(e=>e.id)).size!==i.runs.length||i.runs.slice(n.begin.runIndex,n.end.runIndex+1).some(e=>e.text.length||e.revision||e.revisionRangeMarker||e.sdtWrappers?.length||e.styles?.link||"fieldChar"!==e.kind&&"fieldInstruction"!==e.kind))return;if(t.push({...a,sectionIndex:r,paragraphId:i.id,runId:n.begin.runId,offset:n.begin.offset,raw:o}),t.length>4096)return}}return t}function Fk(e,t,n,r=Y(e,t)){if("page"!==n.reference.kind)return;const o=r.pageIndexAt(n.paragraphId,n.offset);if(void 0===o)return;const a=r.forPage(o);if(a.sectionNumber!==n.sectionIndex+1||void 0===a.pageNumber)return;const i=Lo(e)[n.sectionIndex];if(!i)return;const s=da(a.pageNumber,i.pageNumbering?.format);return void 0===s?void 0:{physicalPageIndex:o,label:String(s)}}function Ek(e,t,n,r=Y(e,t)){const o=e.bookmarks;if(!o||new Set(o.order).size!==o.order.length||o.order.length!==Object.keys(o.items).length||o.order.some(e=>o.items[e]?.id!==e))return;const a=Object.values(o.items).filter(e=>e.name.toLowerCase()===n.toLowerCase()),i=a[0];if(1!==a.length||!i||i.name!==n||!i.start||!i.end||void 0!==i.colFirst||void 0!==i.colLast)return;const s=Lo(e),l=[],c=/* @__PURE__ */new Map;for(const[h,b]of s.entries())for(const e of b.blocks){if("paragraph"!==e.type||c.has(e.id))return;c.set(e.id,l.length),l.push({p:e,sectionIndex:h})}const d=c.get(i.start.paragraphId),u=c.get(i.end.paragraphId);if(void 0===d||void 0===u||d>u)return;const p=(e,t)=>Number.isSafeInteger(t)&&t>=0&&t<=oi(l[e].p);if(!p(d,i.start.offset)||!p(u,i.end.offset)||d===u&&i.start.offset>=i.end.offset)return;let f,g;for(let h=d;h<=u;h++){const{p:e,sectionIndex:t}=l[h],n=h===d?i.start.offset:0,o=h===u?i.end.offset:oi(e);if(o<=n)continue;if(e.sdtWrappers?.length||e.numberingRevision||e.dropCap||e.runs.some(e=>e.revision||e.revisionRangeMarker||e.sdtWrappers?.length||e.text.length>0&&("text"!==e.kind||e.styles?.hidden)))return;const a=r.pageIndexAt(e.id,n),s=r.pageIndexAt(e.id,o-1);if(void 0===a||void 0===s||a>s||r.forPage(a).sectionNumber!==t+1||r.forPage(s).sectionNumber!==t+1||void 0!==g&&a<g)return;f??=a,g=s}if(void 0===f||void 0===g||g-f>=4096)return;const m=[];for(let h=f;h<=g;h++){const e=r.forPage(h);if(void 0===e.sectionNumber||void 0===e.pageNumber)return;const t=e.sectionNumber-1,n=s[t];if(!n)return;const o=da(e.pageNumber,n.pageNumbering?.format);if(void 0===o)return;m.push({physicalPageIndex:h,sectionIndex:t,label:String(o)})}return m}function Dk(e,t,n,r){const o=function(e,t){const n=e.bookmarks;if(!n)return;const r=Object.values(n.items).filter(e=>e.name===t);return 1===r.length?r[0]:void 0}(e,t);if(!o?.start||!o.end||void 0!==o.colFirst||void 0!==o.colLast)return;const a=Lo(e),i=/* @__PURE__ */new Map;let s=0;for(const m of a)for(const e of m.blocks){if("paragraph"!==e.type)return;i.set(e.id,s++)}const l=i.get(o.start.paragraphId),c=i.get(o.end.paragraphId),d=i.get(n);if(void 0===l||void 0===c||void 0===d||l>c)return;const u=a.flatMap(e=>e.blocks),p=u.find(e=>e.id===o.start.paragraphId),f=u.find(e=>e.id===o.end.paragraphId),g=u.find(e=>e.id===n);return"paragraph"!==p?.type||"paragraph"!==f?.type||"paragraph"!==g?.type||!Number.isSafeInteger(o.start.offset)||o.start.offset<0||o.start.offset>oi(p)||!Number.isSafeInteger(o.end.offset)||o.end.offset<0||o.end.offset>oi(f)||l===c&&o.start.offset>=o.end.offset?void 0:!(d<l||d>c)&&(!(d===l&&r<o.start.offset)&&(!(d===c&&r>=o.end.offset)&&!(d!==c&&r>oi(g))))}var Lk={1033:"en-US",2057:"en-GB",1046:"pt-BR",2070:"pt-PT",1034:"es-ES",1036:"fr-FR",1031:"de-DE"};function Nk(e){if(/^[A-Za-z]{2,3}(?:-[A-Za-z]{2})?$/.test(e))try{const t=Intl.getCanonicalLocales(e)[0];return t&&Intl.Collator.supportedLocalesOf([t]).length?t:void 0}catch{return}}function zk(e){const t=La(e);if(t.error||"INDEX"!==t.command)return;const n={entrySeparator:", ",pageSeparator:", ",crossReferenceSeparator:". "},r=t.tokens.slice(1),o=/* @__PURE__ */new Set;for(let a=0;a<r.length;a++){const e=r[a];if("switch"!==e.kind)return;const t=e.value.toLowerCase();if(o.has(t))return;if(o.add(t),"r"===t||"y"===t){"r"===t?n.runIn=!0:n.yomi=!0;continue}const i=r[++a];if(!i||"switch"===i.kind)return;if("f"===t){if(!/^[A-Za-z]$/.test(i.value))return;n.identifier=i.value}else if("z"===t){const e=Nk(Lk[i.value]??i.value);if(!e)return;n.locale=e}else if("c"===t){const e=Number(i.value);if(!Number.isInteger(e)||e<1||e>4)return;1!==e&&(n.columns=e)}else if("b"===t||"s"===t){if(!/^[A-Za-z_][A-Za-z0-9_]{0,39}$/.test(i.value))return;"s"===t?n.seqIdentifier=i.value:n.bookmark=i.value}else if("h"===t){if("quoted"!==i.kind||!i.value||i.value.length>128||[...i.value].some(e=>e.charCodeAt(0)<32||127===e.charCodeAt(0)))return;n.heading=i.value}else if("p"===t){if("!"!==i.value&&!/^[A-Za-z]-[A-Za-z]$/.test(i.value))return;if("!"!==i.value&&i.value.charCodeAt(0)>i.value.charCodeAt(2))return;n.letterRange=i.value.toLowerCase()}else{if("e"!==t&&"l"!==t&&"k"!==t&&"g"!==t&&"d"!==t)return;if("quoted"!==i.kind||i.value.length>15||[...i.value].some(e=>e.charCodeAt(0)<32||127===e.charCodeAt(0)))return;"e"===t?n.entrySeparator=i.value:"l"===t?n.pageSeparator=i.value:"g"===t?n.rangeSeparator=i.value:"d"===t?n.seqSeparator=i.value:n.crossReferenceSeparator=i.value}}return n}function $k(e,t,n,r){const o=zk(n);if(!o)return;const a=o.locale??(r?Nk(r):void 0);if(!a)return;const i=Bk(e);if(!i)return;let s=i;if(o.bookmark){s=[];for(const t of i){const n=Dk(e,o.bookmark,t.paragraphId,t.offset);if(void 0===n)return;n&&s.push(t)}if(!s.length)return}const l=Y(e,t),c=new Intl.Collator(a,{usage:"sort",sensitivity:"accent",numeric:!1,ignorePunctuation:!1}),d=o.seqIdentifier?function(e,t){let n;for(const r of Lo(e)){const e=r.blocks.filter(e=>"paragraph"===e.type);if(e.length!==r.blocks.length)return;const o=Ga(e);if(o.diagnostics.length)return;for(const r of o.spans){const o=r.code.map(e=>"instruction"===e.kind?e.raw:"").join(""),a=Ma(o);if("SEQ"!==a?.type||a.identifier!==t.toLowerCase())continue;if(!r.separator||!r.end||r.result.some(e=>"run"!==e.kind))return;const i=e[r.begin.paragraphIndex],s=r.result.map(e=>"run"===e.kind?i.runs.find(t=>t.id===e.point.runId)?.text??"":"").join("").trim();if(!s||s.length>64||!/^[A-Za-z0-9.-]+$/.test(s))return;n=s}}return n}(e,o.seqIdentifier):void 0;if(o.seqIdentifier&&void 0===d)return;const u=/* @__PURE__ */new Map;let p=0,f=0;for(const m of s){if(m.identifier!==o.identifier){if(void 0!==m.identifier&&void 0!==o.identifier&&m.identifier.toUpperCase()===o.identifier.toUpperCase())return;continue}if(m.path.some(e=>e.includes(";")||e!==e.trim()))return;let n,r=u;const a=[];for(const e of m.path){if(a.push(e),n=r.get(e),!n){if(++p>8192)return;n={label:e,path:[...a],children:/* @__PURE__ */new Map,pages:/* @__PURE__ */new Map,ranges:/* @__PURE__ */new Map,crossReferences:/* @__PURE__ */new Set},r.set(e,n)}r=n.children}if(!n)return;if("crossReference"===m.reference.kind){n.crossReferences.add(m.reference.text);continue}if("bookmarkRange"===m.reference.kind){const r=Ek(e,t,m.reference.bookmark,l);if(!r)return;const o=r[0].physicalPageIndex+":"+r.at(-1).physicalPageIndex,a=n.ranges.get(o);if(a&&(a.bold!==m.boldPage||a.italic!==m.italicPage||JSON.stringify(a.pages)!==JSON.stringify(r)))return;if(!a){if(f+=r.length,f>32768)return;n.ranges.set(o,{pages:r,bold:m.boldPage,italic:m.italicPage})}continue}const i=Fk(e,t,m,l);if(!i)return;const s={...i,bold:m.boldPage,italic:m.italicPage},c=n.pages.get(i.physicalPageIndex);if(c&&(c.label!==s.label||c.bold!==s.bold||c.italic!==s.italic))return;n.pages.set(i.physicalPageIndex,s)}const g=[];return function e(t){const n=[...t.values()].sort((e,t)=>c.compare(e.label,t.label));for(let r=1;r<n.length;r++)if(0===c.compare(n[r-1].label,n[r].label))return!1;for(const r of n){if(r.crossReferences.size>1||r.crossReferences.size&&(r.pages.size||r.ranges.size))return!1;const t=[...r.ranges.values()].sort((e,t)=>e.pages[0].physicalPageIndex-t.pages[0].physicalPageIndex);let n=-1;for(const e of t){if(e.pages[0].physicalPageIndex<=n||e.pages.some(e=>r.pages.has(e.physicalPageIndex)))return!1;n=e.pages.at(-1).physicalPageIndex}if(g.push({path:r.path,pages:[...r.pages.values()].sort((e,t)=>e.physicalPageIndex-t.physicalPageIndex),...t.length?{ranges:t}:{},crossReferences:[...r.crossReferences]}),!e(r.children))return!1}return!0}(u)?{settings:void 0===d?o:{...o,seqPrefix:`${d}${o.seqSeparator??"-"}`},locale:a,entries:g}:void 0}var Hk=e=>!e.sdtWrappers?.length&&!e.list&&!e.numberingRevision&&!e.dropCap&&!e.style?.propertyRevision&&e.runs.every(e=>!(e.revision||e.revisionRangeMarker||e.sdtWrappers?.length||e.styles?.propertyRevision||e.styles?.hidden||e.styles?.rtl||e.styles?.link)),Wk="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function jk(e){if(!e)return!0;if(e.length>262144||/<!|<\?/.test(e))return!1;try{const t=(new _i.DOMParser).parseFromString('<root xmlns:w="'+Wk+'">'+e+"</root>","application/xml").documentElement;if(!t||"root"!==t.localName)return!1;const n={root:["p","pPr","r"],p:["pPr","r"],pPr:["ind"],r:["rPr","t"],rPr:["b","i"],ind:[],b:[],i:[],t:[]},r={p:[],pPr:[],r:[],rPr:[],ind:["left"],b:["val"],i:["val"],t:[]};function o(e,t){for(let n=0;n<e.attributes.length;n++){const o=e.attributes.item(n);if("http://www.w3.org/2000/xmlns/"!==o.namespaceURI&&("t"!==t||"http://www.w3.org/XML/1998/namespace"!==o.namespaceURI||"space"!==o.localName||"preserve"!==o.value&&"default"!==o.value)){if(o.namespaceURI!==Wk||!o.localName||!r[t]?.includes(o.localName))return!1;if("ind"===t&&!/^\d+$/.test(o.value))return!1;if(("b"===t||"i"===t)&&!/^(?:0|1|true|false|on|off)$/.test(o.value))return!1}}for(let r=0;r<e.childNodes.length;r++){const a=e.childNodes.item(r);if(1===a.nodeType){const e=a;if(e.namespaceURI!==Wk||!e.localName||!n[t]?.includes(e.localName)||!o(e,e.localName))return!1}else if(3!==a.nodeType||"t"!==t&&a.nodeValue?.trim())return!1}return!0}return o(t,"root")}catch{return!1}}function Uk(e,t){return Object.entries(e??{}).every(([e,n])=>void 0===n||t.includes(e))}function Vk(e){if(!Hk(e)||!Uk(e.style,["indentLeft","styleId"])||void 0!==e.style?.styleId&&"IndexHeading"!==e.style.styleId||!Number.isFinite(e.style?.indentLeft??0)||!e.runs.length||mi(e).length>32768)return!1;const t=Do(e);return!(t?.attributes?.trim()||!jk(t?.xml)||!jk(t?.paragraphProperties?.xml))&&e.runs.every(e=>"text"===e.kind&&!/[\r\n]/.test(e.text)&&("\t"!==e.text||1===e.text.length)&&Uk(e.styles,["bold","italic"])&&jk($r(e)?.xml))}function Kk(e){if(e.some(e=>"paragraph"!==e.type))return;const t=e,n=Ga(t);if(n.diagnostics.length)return;const r=n.spans.filter(e=>{const t=e.code.map(e=>"instruction"===e.kind?e.raw:"").join("");return"INDEX"===La(t).command||/^\s*INDEX(?=\s|\\|"|$)/i.test(t)});if(1!==r.length)return;const o=r[0],a=o.code.map(e=>"instruction"===e.kind?e.raw:"").join("");if(!zk(a)||null!==o.parentIndex||!o.separator||!o.end||o.beginMarker.fieldLock||o.beginMarker.dirty||o.code.some(e=>"instruction"!==e.kind)||o.begin.paragraphIndex!==o.separator.paragraphIndex||o.begin.paragraphIndex>=o.end.paragraphIndex)return;const i=o.begin.paragraphIndex,s=o.end.paragraphIndex,l=t[i],c=t[s];if(!Hk(l)||!Hk(c)||0!==o.begin.runIndex||o.separator.runIndex!==l.runs.length-1||0!==o.end.runIndex||1!==c.runs.length||l.runs.some(e=>e.text.length||"fieldChar"!==e.kind&&"fieldInstruction"!==e.kind)||0!==c.runs[0]?.text.length)return;const d=t.slice(i+1,s);return d.every(Vk)&&!o.result.some(e=>"run"!==e.kind||e.point.paragraphIndex<=i||e.point.paragraphIndex>=s)&&o.result.length===d.reduce((e,t)=>e+t.runs.length,0)?{start:i,end:s,raw:a}:void 0}function _k(e,t="tabs"){if(!e.entries.length||e.entries.length>2048)return;const n=e.settings.letterRange,r=n&&"!"!==n?e.entries.filter(e=>{const t=(e.path.at(-1)?.[0]??"").normalize("NFD").replace(/\p{M}/gu,"").toLowerCase();return t>=n[0]&&t<=n[2]}):e.entries;if(!r.length)return;const o=[],a=[];e.settings.heading&&o.push({indent:0,fragments:[{text:e.settings.heading}],styleId:"IndexHeading"});for(const l of r){const t=e.settings.runIn?l.path.join(":"):l.path.at(-1);if(!t)return;const n=[];e.settings.seqPrefix&&n.push({text:e.settings.seqPrefix}),n.push({text:t});const r=l.pages.map(e=>({index:e.physicalPageIndex,fragment:{text:e.label,bold:e.bold,italic:e.italic}}));for(const o of l.ranges??[]){const t=o.pages[0],n=o.pages.at(-1);if(!t||!n||o.pages.some(e=>e.sectionIndex!==t.sectionIndex)||t!==n&&t.label===n.label)return;r.push({index:t.physicalPageIndex,fragment:{text:t===n?t.label:t.label+(e.settings.rangeSeparator??"–")+n.label,bold:o.bold,italic:o.italic}})}if(r.sort((e,t)=>e.index-t.index),r.length){if(l.crossReferences.length)return;n.push({text:e.settings.entrySeparator}),r.forEach((t,r)=>{r&&n.push({text:e.settings.pageSeparator}),n.push(t.fragment)})}else if(l.crossReferences.length){if(1!==l.crossReferences.length)return;n.push({text:e.settings.crossReferenceSeparator},{text:l.crossReferences[0]})}if(n.some(e=>/[\r\n\t]/.test(e.text))||n.reduce((e,t)=>e+t.text.length,0)>32768)return;a.push({indent:e.settings.runIn?0:24*(l.path.length-1),fragments:n})}const i=Math.min(4,Math.max(1,e.settings.columns??1));if(1===i||"section"===t)return[...o,...a];const s=Math.ceil(a.length/i);for(let l=0;l<i;l++){const e=a.slice(l*s,(l+1)*s);if(!e.length)break;l&&o.push({indent:0,fragments:[{text:"\t"}]}),o.push(...e)}return o}function Xk(e){const t=[];for(const n of e){if(!n.text)continue;const e=!!n.bold,r=!!n.italic,o=t.at(-1);o&&o.bold===e&&o.italic===r?o.text+=n.text:t.push({text:n.text,bold:e,italic:r})}return t}function qk(e,t){return"paragraph"===e.type&&(e.style?.indentLeft??0)===t.indent&&(e.style?.styleId??void 0)===t.styleId&&JSON.stringify(Xk(e.runs.map(e=>({text:e.text,bold:e.styles?.bold,italic:e.styles?.italic}))))===JSON.stringify(Xk(t.fragments))}function Gk(e){const t=so(Xk(e.fragments).map(e=>({text:e.text,...e.bold||e.italic?{styles:{...e.bold?{bold:!0}:{},...e.italic?{italic:!0}:{}}}:{}})));return(e.indent||e.styleId)&&(t.style={...e.indent?{indentLeft:e.indent}:{},...e.styleId?{styleId:e.styleId}:{}}),t}function Yk(e,t,n,r){const o=/* @__PURE__ */new Map;for(const s of Lo(e.document))for(const e of s.blocks)o.set(e.id,o.size);if(t.has(e.selection.anchor.paragraphId)||t.has(e.selection.focus.paragraphId))return!0;const a=o.get(n),i=o.get(r);if(void 0===a||void 0===i)return!0;for(const s of[...Object.values(e.document.bookmarks?.items??{}),...Object.values(e.document.comments?.items??{})]){const e=s.start?o.get(s.start.paragraphId):void 0,t=s.end?o.get(s.end.paragraphId):void 0;if(void 0===e||void 0===t||e>t||e<=i&&t>=a)return!0}return!1}function Zk(e,t,n=f,r=6){let o;const a=e,i=(e,t)=>({state:a,status:e,passes:t,updatedEntries:0,layout:o});if("main"!==jr(e)||e.trackChangesEnabled||!Number.isSafeInteger(r)||r<1)return i("unsupported",0);let s=Ua(e);const l=Lo(e.document),c=l[s];if(!c||(c.pageSettings.columns?.count??1)>1&&("continuous"!==c.breakType||!Kk(c.blocks)))return i("unsupported",0);const d=Kk(c.blocks);if(!d)return i("unsupported",0);const u=Math.min(4,Math.max(1,zk(d.raw)?.columns??1)),p=c.blocks[d.start].id,g=c.blocks[d.end].id,m=new Set(c.blocks.slice(d.start+1,d.end).map(e=>e.id));u>1&&c.pageSettings.columns?.count!==u&&(e={...e,document:{...e.document,sections:l.map((e,t)=>t===s?{...e,pageSettings:{...e.pageSettings,columns:{count:u,space:24}},breakType:"continuous"}:e)}});const h=Bk(e.document);if(!h)return i("unsupported",0);const b=JSON.stringify(h);let y=e;const v=/* @__PURE__ */new Set,x=Math.min(r,6);for(let f=1;f<=x;f++){let r;try{r=n(y.document)}catch{return i("unsupported",f)}o??=r;const a=Lo(y.document);let l=s;if(u>1&&(l=a.findIndex(e=>"continuous"===e.breakType&&e.pageSettings.columns?.count===u&&Kk(e.blocks)?.raw===d.raw),l<0))return i("unsupported",f);const c=a[l],h=c&&Kk(c.blocks);if(!c||!h||h.raw!==d.raw||c.blocks[h.start].id!==p||c.blocks[h.end].id!==g||JSON.stringify(Bk(y.document))!==b)return i("unsupported",f);const x=$k(y.document,r,h.raw,t);if(!x)return i("unresolved",f);const w=_k(x,u>1?"section":"tabs");if(!w)return i("unsupported",f);const I=c.blocks.slice(h.start+1,h.end);if(I.length===w.length&&I.every((e,t)=>qk(e,w[t])))return{state:y,status:y===e?"unchanged":"updated",passes:f,updatedEntries:y===e?0:w.length,layout:r};if(Yk(e,m,p,g))return i("unsupported",f);const S=JSON.stringify([w,r.pages.map(e=>[e.index,e.sectionIndex])]);if(v.has(S))return i("nonconvergent",f);v.add(S);const C=[...c.blocks.slice(0,h.start+1),...w.map(Gk),...c.blocks.slice(h.end)];y={...y,document:{...y.document,sections:a.map((e,t)=>t===l?{...e,blocks:C}:e)},selection:e.selection}}return i("nonconvergent",x)}function Jk(e,t=!1){return{...wo(""),kind:"fieldInstruction",fieldInstruction:e,...t?{styles:{hidden:!0}}:{}}}function Qk(e,t=!1){return{...wo(""),kind:"fieldChar",fieldChar:{kind:e},...t?{styles:{hidden:!0}}:{}}}function eT(e){if("main"!==jr(e)||e.trackChangesEnabled||!ga(e.selection))return;const t=Lo(e.document),n=Ua(e),r=t[n];if(!r||r.blocks.some(e=>"paragraph"!==e.type))return;const o=r.blocks,a=o.findIndex(t=>t.id===e.selection.focus.paragraphId),i=o[a];if(!i||wa(i,e.selection.focus)!==oi(i)||i.sdtWrappers?.length||i.list||i.numberingRevision||i.dropCap||i.style?.propertyRevision||i.runs.some(e=>e.revision||e.revisionRangeMarker||e.sdtWrappers?.length||e.styles?.propertyRevision))return;const s=Ga(o);return s.diagnostics.length?void 0:{sections:t,index:n,section:r,paragraphs:o,at:a,p:i,graph:s}}function tT(e,t,n){return{...e,document:{...e.document,sections:t.sections.map((e,r)=>r===t.index?{...e,blocks:n}:e)}}}function nT(e){return void 0===e||/^[A-Za-z]$/.test(e)}function rT(e){const t=eT(e);return!!t&&(!(Do(t.p)||t.p.runs.some(e=>"text"!==e.kind||e.styles?.hidden||e.styles?.rtl)||t.graph.spans.some(e=>e.begin.paragraphIndex<=t.at&&(e.end?.paragraphIndex??1/0)>=t.at))&&(![...Object.values(e.document.bookmarks?.items??{}),...Object.values(e.document.comments?.items??{})].some(e=>e.start?.paragraphId===t.p.id||e.end?.paragraphId===t.p.id)&&void 0!==Bk(e.document)))}function oT(e){const t=eT(e);if(!t||Object.keys(e.document.bookmarks?.items??{}).length||Object.keys(e.document.comments?.items??{}).length||(t.section.pageSettings.columns?.count??1)>1)return!1;if(t.graph.spans.some(e=>e.begin.paragraphIndex<=t.at&&(e.end?.paragraphIndex??1/0)>t.at))return!1;for(const n of t.sections){if(n.blocks.some(e=>"paragraph"!==e.type))return!1;const e=Ga(n.blocks);if(e.diagnostics.length||e.spans.some(e=>{const t=e.code.map(e=>"instruction"===e.kind?e.raw:"").join("");return"INDEX"===La(t).command||/^\s*INDEX(?=\s|\\|"|$)/i.test(t)}))return!1}return!!Bk(e.document)?.length}function aT(e){if("main"!==jr(e)||e.trackChangesEnabled)return!1;const t=Lo(e.document);return t.some(e=>1===(e.pageSettings.columns?.count??1)&&!!Kk(e.blocks))||t.some(e=>"continuous"===e.breakType&&(e.pageSettings.columns?.count??1)>1&&!!Kk(e.blocks))}var iT=e=>`${e}:${Math.random().toString(36).slice(2,11)}`;function sT(e,t){return{id:iT("run:fld"),kind:"fieldChar",text:"",fieldChar:{kind:e},styles:t?{...t}:void 0}}function lT(e,t,n){const r=ko(e),o=r[t],a={...o,runs:o.runs.map(e=>n.get(e.id)??na(e))};return Vt(e,[...Yo(r.slice(0,t)),a,...Yo(r.slice(t+1))],e.selection)}function cT(e,t,n){if("string"!=typeof n||La(n).error)return e;const r=function(e,t){const n=ko(e),r=Ga(n);if(!r.diagnostics.length)return r.spans.find(e=>null===e.parentIndex&&(e.begin.runId===t||e.code.some(e=>"instruction"===e.kind&&e.point.runId===t))&&e.code.every(e=>"instruction"===e.kind)&&!!e.separator&&!!e.end&&e.begin.paragraphIndex===e.end.paragraphIndex)}(e,t);if(!r||r.beginMarker.fieldLock)return e;const o=r.code.filter(e=>"instruction"===e.kind).map(e=>e.point.runId);if(!o.includes(t))return e;const a=/* @__PURE__ */new Map,i=ko(e)[r.begin.paragraphIndex];if(o.forEach((e,t)=>{const r=i.runs.find(t=>t.id===e);r&&"fieldInstruction"===r.kind&&a.set(e,{...r,fieldInstruction:0===t?n:""})}),a.size!==o.length)return e;const s=i.runs.find(e=>e.id===r.begin.runId);return s&&"fieldChar"===s.kind?(a.set(r.begin.runId,{...s,fieldChar:{...s.fieldChar,dirty:!0}}),lT(e,r.begin.paragraphIndex,a)):e}var dT=(e,t)=>e.length>0&&e.length<=t&&!!e.trim()&&![...e].some(e=>e.charCodeAt(0)<32||127===e.charCodeAt(0));function uT(e){const t=La(e);if(t.error||"TA"!==t.command)return;const n=t.tokens.slice(1);if(!n.length)return;let r,o,a,i="1",s=!1,l=!1;const c=/* @__PURE__ */new Set;for(let d=0;d<n.length;d++){const e=n[d];if("switch"!==e.kind)return;const t=e.value.toLowerCase();if(c.has(t))return;if(c.add(t),"b"===t){s=!0;continue}if("i"===t){l=!0;continue}if("l"!==t&&"s"!==t&&"c"!==t&&"r"!==t)return;const u=n[++d];if(!u||"switch"===u.kind)return;if("l"===t||"s"===t){if("quoted"!==u.kind||!dT(u.value,4096))return;"l"===t?r=u.value:o=u.value}else if("c"===t){if(!dT(u.value,32)||/\s/.test(u.value))return;i=u.value}else{if(!/^[A-Za-z_][A-Za-z0-9_]{0,39}$/.test(u.value))return;a=u.value}}return r?{long:r,...o?{short:o}:{},category:i,boldPage:s,italicPage:l,...a?{bookmark:a}:{}}:void 0}function pT(e){const t=[],n=/* @__PURE__ */new Set;for(const[r,o]of Lo(e).entries()){const e=[];for(const t of o.blocks){if("paragraph"!==t.type||n.has(t.id)||t.runs.some(e=>"textBox"===e.kind||"opaque"===e.kind))return;n.add(t.id),e.push(t)}const a=Ga(e);if(a.diagnostics.length)return;for(const n of a.spans){const o=n.code.map(e=>"instruction"===e.kind?e.raw:"").join("");if("TA"!==La(o).command&&!/^\s*TA(?=\s|\\|"|$)/i.test(o))continue;const a=uT(o);if(!a||null!==n.parentIndex||!n.end||n.separator||n.begin.paragraphIndex!==n.end.paragraphIndex||n.beginMarker.fieldLock||n.beginMarker.dirty||n.code.some(e=>"instruction"!==e.kind)||n.result.length)return;const i=e[n.begin.paragraphIndex];if(i.sdtWrappers?.length||i.numberingRevision||i.dropCap||new Set(i.runs.map(e=>e.id)).size!==i.runs.length||i.runs.slice(n.begin.runIndex,n.end.runIndex+1).some(e=>e.text.length||e.revision||e.revisionRangeMarker||e.sdtWrappers?.length||e.styles?.link||"fieldChar"!==e.kind&&"fieldInstruction"!==e.kind))return;if(t.push({...a,sectionIndex:r,paragraphId:i.id,runId:n.begin.runId,offset:n.begin.offset,raw:o}),t.length>4096)return}}return t}function fT(e,t,n,r=Y(e,t)){if(n.bookmark)return;const o=r.pageIndexAt(n.paragraphId,n.offset);if(void 0===o)return;const a=r.forPage(o);if(a.sectionNumber!==n.sectionIndex+1||void 0===a.pageNumber)return;const i=Lo(e)[n.sectionIndex];if(!i)return;const s=da(a.pageNumber,i.pageNumbering?.format);return void 0===s?void 0:{physicalPageIndex:o,label:String(s)}}var gT=e=>e.length>0&&e.length<=15&&![...e.replace(/^\t$/,"")].some(e=>e.charCodeAt(0)<32||127===e.charCodeAt(0));function mT(e){const t=La(e);if(t.error||"TOA"!==t.command)return;const n=t.tokens.slice(1);let r,o,a;const i={category:"1",entrySeparator:"\t",pageSeparator:", ",rangeSeparator:"–",seqSeparator:"-",passim:!1,includeHeading:!1,stripSourceFormatting:!1},s=/* @__PURE__ */new Set;for(let l=0;l<n.length;l++){const e=n[l];if("switch"!==e.kind)return;const t=e.value.toLowerCase();if(s.has(t))return;if(s.add(t),"p"===t){i.passim=!0;continue}if("h"===t){i.includeHeading=!0;continue}if("f"===t){i.stripSourceFormatting=!0;continue}if(!["c","b","e","g","l","s","d"].includes(t))return;const c=n[++l];if(!c||"switch"===c.kind)return;if("c"===t){if(!c.value||c.value.length>32||/\s|["\\]/.test(c.value))return;r=c.value}else if("b"===t||"s"===t){if(!/^[A-Za-z_][A-Za-z0-9_]{0,39}$/.test(c.value))return;"b"===t?o=c.value:a=c.value}else{if(!gT(c.value)||"quoted"!==c.kind&&"\t"!==c.value)return;"e"===t?i.entrySeparator=c.value:"l"===t?i.pageSeparator=c.value:"g"===t?i.rangeSeparator=c.value:i.seqSeparator=c.value}}return r?{...i,category:r,...o?{bookmark:o}:{},...a?{seqIdentifier:a}:{}}:void 0}function hT(e,t,n,r){const o=mT(n);if(!o)return;if(!r||!/^[A-Za-z]{2,3}(?:-[A-Za-z]{2})?$/.test(r))return;let a;try{a=new Intl.Collator(r)}catch{return}const i=pT(e);if(!i)return;let s=i;if(o.bookmark){s=[];for(const t of i){const n=Dk(e,o.bookmark,t.paragraphId,t.offset);if(void 0===n)return;n&&s.push(t)}if(!s.length)return}const l=Y(e,t),c=o.seqIdentifier?wi(e).get(o.seqIdentifier.toLowerCase()):void 0;if(o.seqIdentifier&&(void 0===c||!Number.isSafeInteger(c)))return;const d=/* @__PURE__ */new Map;for(const p of s){if(p.category.toLowerCase()!==o.category.toLowerCase())continue;const n=p.short??p.long;if(n.length>4096||/[\r\n\t]/.test(n))return;let r=d.get(n);if(r||(r={label:n,pages:[],bold:p.boldPage,italic:p.italicPage},d.set(n,r)),r.bold!==p.boldPage||r.italic!==p.italicPage)return;if(p.bookmark){const n=Ek(e,t,p.bookmark,l);if(!n)return;r.ranges??=[];const o=n[0].physicalPageIndex,a=n.at(-1).physicalPageIndex;r.ranges.some(e=>e[0].physicalPageIndex===o&&e.at(-1).physicalPageIndex===a)||r.ranges.push(n);continue}const a=fT(e,t,p,l);if(!a)return;r.pages.some(e=>e.physicalPageIndex===a.physicalPageIndex)||r.pages.push(a)}const u=[...d.values()];if(u.sort((e,t)=>a.compare(e.label,t.label)),!(u.length>2048)){for(const e of u)e.pages.sort((e,t)=>e.physicalPageIndex-t.physicalPageIndex),void 0!==c&&(e.prefix=`${c}${o.seqSeparator}`);return{settings:o,locale:r,category:o.category,entries:u}}}var bT=e=>!e.sdtWrappers?.length&&!e.list&&!e.numberingRevision&&!e.dropCap&&!e.style?.propertyRevision&&e.runs.every(e=>!(e.revision||e.revisionRangeMarker||e.sdtWrappers?.length||e.styles?.propertyRevision||e.styles?.hidden||e.styles?.rtl||e.styles?.link));function yT(e){if(e.some(e=>"paragraph"!==e.type))return;const t=e,n=Ga(t);if(n.diagnostics.length)return;const r=n.spans.filter(e=>{const t=e.code.map(e=>"instruction"===e.kind?e.raw:"").join("");return"TOA"===La(t).command||/^\s*TOA(?=\s|\\|"|$)/i.test(t)});if(1!==r.length)return;const o=r[0],a=o.code.map(e=>"instruction"===e.kind?e.raw:"").join("");if(!mT(a)||null!==o.parentIndex||!o.separator||!o.end||o.beginMarker.fieldLock||o.beginMarker.dirty||o.code.some(e=>"instruction"!==e.kind)||o.begin.paragraphIndex!==o.separator.paragraphIndex||o.begin.paragraphIndex>=o.end.paragraphIndex)return;const i=o.begin.paragraphIndex,s=o.end.paragraphIndex,l=t[i],c=t[s];if(!bT(l)||!bT(c)||0!==o.begin.runIndex||o.separator.runIndex!==l.runs.length-1||0!==o.end.runIndex||1!==c.runs.length||l.runs.some(e=>e.text.length||"fieldChar"!==e.kind&&"fieldInstruction"!==e.kind)||0!==c.runs[0]?.text.length)return;const d=t.slice(i+1,s);return d.every(e=>bT(e)&&e.runs.every(e=>"text"===e.kind&&e.text.length<=32768))&&!o.result.some(e=>"run"!==e.kind||e.point.paragraphIndex<=i||e.point.paragraphIndex>=s)&&o.result.length===d.reduce((e,t)=>e+t.runs.length,0)?{start:i,end:s,raw:a}:void 0}function vT(e){if(e.entries.length>2048)return;const{settings:t}=e,n=[];t.includeHeading&&n.push({fragments:[{text:e.category}]});for(const r of e.entries){const e=[];r.prefix&&e.push({text:r.prefix}),e.push({text:r.label});const o=t.passim&&r.pages.length>=5?[{text:"passim"}]:r.pages.map((e,n)=>({text:`${n?t.pageSeparator:""}${e.label}`,bold:r.bold,italic:r.italic}));for(const n of r.ranges??[]){const e=n[0],a=n.at(-1);if(!e||!a||n.some(t=>t.sectionIndex!==e.sectionIndex)||e!==a&&e.label===a.label)return;o.push({text:t.pageSeparator,bold:r.bold,italic:r.italic}),o.push({text:e===a?e.label:`${e.label}${t.rangeSeparator}${a.label}`,bold:r.bold,italic:r.italic})}if(o.length&&e.push({text:t.entrySeparator},...o),e.some(e=>!e.text||e.text.length>4e4))return;n.push({fragments:e})}return n.length?n:void 0}function xT(e){const t=[];for(const n of e){if(!n.text)continue;const e=t.at(-1);e&&e.bold===!!n.bold&&e.italic===!!n.italic?e.text+=n.text:t.push({text:n.text,bold:!!n.bold,italic:!!n.italic})}return t}var wT=(e,t)=>"paragraph"===e.type&&JSON.stringify(xT(e.runs.map(e=>({text:e.text,bold:e.styles?.bold,italic:e.styles?.italic}))))===JSON.stringify(xT(t.fragments)),IT=e=>so(xT(e.fragments).map(e=>({text:e.text,...e.bold||e.italic?{styles:{...e.bold?{bold:!0}:{},...e.italic?{italic:!0}:{}}}:{}})));function ST(e,t,n=f,r=6){let o;const a=(t,n)=>({state:e,status:t,passes:n,updatedEntries:0,layout:o});if("main"!==jr(e)||e.trackChangesEnabled||!Number.isSafeInteger(r)||r<1||r>6)return a("unsupported",0);const i=Ua(e),s=Lo(e.document)[i];if(!s)return a("unsupported",0);const l=yT(s.blocks);if(!l)return a("unsupported",0);const c=s.blocks[l.start].id,d=s.blocks[l.end].id;let u=e;const p=/* @__PURE__ */new Set;for(let f=1;f<=r;f++){let r;try{r=n(u.document)}catch{return a("unsupported",f)}o??=r;const s=Lo(u.document),g=s[i],m=g&&yT(g.blocks);if(!g||!m||m.raw!==l.raw||g.blocks[m.start].id!==c||g.blocks[m.end].id!==d)return a("unsupported",f);const h=hT(u.document,r,m.raw,t);if(!h)return a("unresolved",f);const b=vT(h);if(!b)return a("unsupported",f);const y=g.blocks.slice(m.start+1,m.end);if(y.length===b.length&&y.every((e,t)=>wT(e,b[t])))return{state:u,status:u===e?"unchanged":"updated",passes:f,updatedEntries:u===e?0:b.length,layout:r};const v=JSON.stringify([b,r.pages.map(e=>[e.index,e.sectionIndex])]);if(p.has(v))return a("nonconvergent",f);p.add(v);const x=[...g.blocks.slice(0,m.start+1),...b.map(IT),...g.blocks.slice(m.end)];u={...u,document:{...u.document,sections:s.map((e,t)=>t===i?{...e,blocks:x}:e)},selection:e.selection}}return a("nonconvergent",r)}var CT=(e,t=!1)=>({...wo(""),kind:"fieldInstruction",fieldInstruction:e,...t?{styles:{hidden:!0}}:{}}),kT=(e,t=!1)=>({...wo(""),kind:"fieldChar",fieldChar:{kind:e},...t?{styles:{hidden:!0}}:{}});function TT(e){if("main"!==jr(e)||e.trackChangesEnabled||!ga(e.selection))return;const t=Lo(e.document),n=Ua(e),r=t[n];if(!r||r.blocks.some(e=>"paragraph"!==e.type))return;const o=r.blocks,a=o.findIndex(t=>t.id===e.selection.focus.paragraphId),i=o[a];if(!i||wa(i,e.selection.focus)!==oi(i)||i.sdtWrappers?.length||i.list||i.numberingRevision||i.dropCap||i.style?.propertyRevision||i.runs.some(e=>e.revision||e.revisionRangeMarker||e.sdtWrappers?.length||e.styles?.propertyRevision))return;const s=Ga(o);return s.diagnostics.length?void 0:{sections:t,index:n,section:r,paragraphs:o,at:a,p:i,graph:s}}function PT(e,t,n){return{...e,document:{...e.document,sections:t.sections.map((e,r)=>r===t.index?{...e,blocks:n}:e)}}}var RT=e=>"string"==typeof e&&!!e.trim()&&e.length<=4096&&!/[\r\n\t\\;"]/.test(e),AT=e=>"string"==typeof e&&!!e&&e.length<=32&&!/\s|["\\]/.test(e);function MT(e,t){const n=TT(e);if(!n||!function(e){const t=TT(e);return!(!t||Do(t.p)||t.p.runs.some(e=>"text"!==e.kind||e.styles?.hidden||e.styles?.rtl)||t.graph.spans.some(e=>e.begin.paragraphIndex<=t.at&&(e.end?.paragraphIndex??1/0)>=t.at)||[...Object.values(e.document.bookmarks?.items??{}),...Object.values(e.document.comments?.items??{})].some(e=>e.start?.paragraphId===t.p.id||e.end?.paragraphId===t.p.id)||void 0===pT(e.document))}(e)||!RT(t.long)||void 0!==t.short&&!RT(t.short)||void 0!==t.category&&!AT(t.category))return e;const r=t.category??"1",o=` TA \\l "${t.long}"`+(t.short?` \\s "${t.short}"`:"")+` \\c ${r}`+(t.boldPage?" \\b":"")+(t.italicPage?" \\i":"")+" ";if(!uT(o))return e;const a={...n.p,runs:[...n.p.runs,kT("begin",!0),CT(o,!0),kT("end",!0)]},i=PT(e,n,n.paragraphs.map((e,t)=>t===n.at?a:e));return pT(i.document)?i:e}function OT(e,t,n=f){const r=TT(e);if(!(r&&function(e){const t=TT(e);if(!t||Object.keys(e.document.bookmarks?.items??{}).length||Object.keys(e.document.comments?.items??{}).length||(t.section.pageSettings.columns?.count??1)>1)return!1;if(t.graph.spans.some(e=>{const t=e.code.map(e=>"instruction"===e.kind?e.raw:"").join("");return"TOA"===La(t).command||/^\s*TOA(?=\s|\\|"|$)/i.test(t)}))return!1;for(const n of t.sections){if(n.blocks.some(e=>"paragraph"!==e.type))return!1;const e=Ga(n.blocks);if(e.diagnostics.length||e.spans.some(e=>{const t=e.code.map(e=>"instruction"===e.kind?e.raw:"").join("");return"TOA"===La(t).command||/^\s*TOA(?=\s|\\|"|$)/i.test(t)}))return!1}return!!pT(e.document)?.length}(e)&&AT(t.category)&&/^[A-Za-z]{2,3}(?:-[A-Za-z]{2})?$/.test(t.locale)))return e;const o=` TOA \\c "${t.category}"`+(t.heading?" \\h":"")+(t.passim?" \\p":"")+" ";if(!mT(o))return e;const a=Go("");a.runs=[kT("begin"),CT(o),kT("separate")];const i=Go("");i.runs=[kT("end")];const s=ST(PT(e,r,[...r.paragraphs.slice(0,r.at+1),a,i,...r.paragraphs.slice(r.at+1)]),t.locale,n);return"updated"===s.status?s.state:e}function BT(e,t,n,r=Y(e,t)){const o=r.pageIndexAt(n.paragraphId,n.offset);if(void 0===o)return;const a=r.forPage(o);if(a.sectionNumber!==n.sectionIndex+1||void 0===a.pageNumber)return;const i=Lo(e)[n.sectionIndex];if(!i)return;const s=da(a.pageNumber,i.pageNumbering?.format);return void 0===s?void 0:{physicalPageIndex:o,label:String(s)}}var FT=e=>!e.sdtWrappers?.length&&!e.list&&!e.numberingRevision&&!e.dropCap&&!e.style?.propertyRevision&&e.runs.every(e=>!(e.revision||e.revisionRangeMarker||e.sdtWrappers?.length||e.styles?.propertyRevision||e.styles?.hidden||e.styles?.rtl||e.styles?.link));function ET(e){if(e.some(e=>"paragraph"!==e.type))return;const t=e,n=Ga(t);if(n.diagnostics.length)return;const r=n.spans.filter(e=>{const t=hI(e.code.map(e=>"instruction"===e.kind?e.raw:"").join(""));return void 0!==t?.captionIdentifier||void 0!==t?.unlabeledIdentifier});if(1!==r.length)return;const o=r[0],a=o.code.map(e=>"instruction"===e.kind?e.raw:"").join(""),i=hI(a);if(null!==o.parentIndex||!o.separator||!o.end||o.beginMarker.fieldLock||o.beginMarker.dirty||o.code.some(e=>"instruction"!==e.kind)||o.begin.paragraphIndex!==o.separator.paragraphIndex||o.begin.paragraphIndex>=o.end.paragraphIndex)return;const s=o.begin.paragraphIndex,l=o.end.paragraphIndex,c=t[s],d=t[l];if(!FT(c)||!FT(d)||0!==o.begin.runIndex||o.separator.runIndex!==c.runs.length-1||0!==o.end.runIndex||1!==d.runs.length||c.runs.some(e=>e.text.length||"fieldChar"!==e.kind&&"fieldInstruction"!==e.kind)||0!==d.runs[0]?.text.length)return;const u=t.slice(s+1,l);return u.every(e=>FT(e)&&e.runs.every(e=>"text"===e.kind&&e.text.length<=32768))&&!o.result.some(e=>"run"!==e.kind||e.point.paragraphIndex<=s||e.point.paragraphIndex>=l)&&o.result.length===u.reduce((e,t)=>e+t.runs.length,0)?{start:s,end:l,raw:a,settings:i}:void 0}function DT(e,t,n){const r=hI(n);if(!r||void 0===r.captionIdentifier&&void 0===r.unlabeledIdentifier)return;const o=function(e,t,n=!1){if(!t||t.length>64||!/^[A-Za-z_][A-Za-z0-9_ ]*$/.test(t))return;const r=wi(e),o=[];for(const[a,i]of Lo(e).entries()){const e=[];for(const t of i.blocks){if("paragraph"!==t.type)return;e.push(t)}const s=Ga(e);if(s.diagnostics.length)return;for(const i of s.spans){const s=i.code.map(e=>"instruction"===e.kind?e.raw:"").join(""),l=Ma(s);if("SEQ"!==l?.type||l.identifier!==t.toLowerCase())continue;if(null!==i.parentIndex||!i.end||!i.separator||i.code.some(e=>"instruction"!==e.kind)||1!==i.result.length||"run"!==i.result[0]?.kind||i.beginMarker.fieldLock)return;const c=e[i.begin.paragraphIndex];if(i.begin.paragraphIndex!==i.end.paragraphIndex||c.sdtWrappers?.length||c.numberingRevision||c.dropCap||c.runs.some(e=>e.revision||e.revisionRangeMarker||e.sdtWrappers?.length||e.styles?.link))return;const d=i.result[0].point.runIndex,u=r.get(Mi(c.id,d));if(void 0===u)return;const p=c.runs.slice(0,i.begin.runIndex).map(e=>e.text).join("").replace(/^\s+/,""),f=c.runs.slice(i.end.runIndex+1).map(e=>e.text).join("").trim();if(p.length>256||f.length>4096||/[\r\n]/.test(p+f))return;const g=f.replace(/^[:;\-\s]+/,""),m=n?g:`${p}${u}${f?`: ${g}`:""}`;if(!m||m.length>4096)return;o.push({identifier:t,number:u,display:m,paragraphId:c.id,offset:i.begin.offset,sectionIndex:a})}}return o.sort((e,t)=>e.sectionIndex-t.sectionIndex||e.offset-t.offset)}(e,r.captionIdentifier??r.unlabeledIdentifier,!!r.unlabeledIdentifier);if(!o||o.length>2048)return;const a=r.chapterIdentifier?wi(e).get(r.chapterIdentifier.toLowerCase()):void 0;if(r.chapterIdentifier&&void 0===a)return;const i=Y(e,t),s=[];for(const l of o){const n=r.scopeBookmark?void 0:BT(e,t,l,i);if(!r.scopeBookmark&&!n)return;const o=void 0===a?l.display:`${a}${r.chapterSeparator??"-"}${l.display}`;if(o.length>4096)return;s.push({display:o,page:n})}return{settings:r,entries:s}}function LT(e){if(!e.entries.length)return;const t=[],n=e.settings.entryPageSeparator??"\t";for(const r of e.entries){const o=[{text:r.display}],a=e.settings.omitPages,i=Number(r.display.match(/\d+/)?.[0]??0),s=a&&i>=a[0]&&i<=a[1];if(r.page&&!s&&o.push({text:n},{text:r.page.label}),o.some(e=>!e.text||e.text.length>4e4))return;t.push({fragments:o})}return t}function NT(e){const t=[];for(const n of e){if(!n.text)continue;const e=t.at(-1);e&&e.bold===!!n.bold&&e.italic===!!n.italic?e.text+=n.text:t.push({text:n.text,bold:!!n.bold,italic:!!n.italic})}return t}var zT=(e,t)=>"paragraph"===e.type&&JSON.stringify(NT(e.runs.map(e=>({text:e.text,bold:e.styles?.bold,italic:e.styles?.italic}))))===JSON.stringify(NT(t.fragments)),$T=e=>so(NT(e.fragments).map(e=>({text:e.text})));function HT(e,t=f,n=6){let r;const o=(t,n)=>({state:e,status:t,passes:n,updatedEntries:0,layout:r});if("main"!==jr(e)||e.trackChangesEnabled||!Number.isSafeInteger(n)||n<1||n>6)return o("unsupported",0);const a=Ua(e),i=Lo(e.document)[a];if(!i)return o("unsupported",0);const s=ET(i.blocks);if(!s)return o("unsupported",0);const l=i.blocks[s.start].id,c=i.blocks[s.end].id;let d=e;const u=/* @__PURE__ */new Set;for(let p=1;p<=n;p++){let n;try{n=t(d.document)}catch{return o("unsupported",p)}r??=n;const i=Lo(d.document),f=i[a],g=f&&ET(f.blocks);if(!f||!g||g.raw!==s.raw||f.blocks[g.start].id!==l||f.blocks[g.end].id!==c)return o("unsupported",p);const m=DT(d.document,n,g.raw);if(!m)return o("unresolved",p);const h=LT(m);if(!h)return o("unsupported",p);const b=f.blocks.slice(g.start+1,g.end);if(b.length===h.length&&b.every((e,t)=>zT(e,h[t])))return{state:d,status:d===e?"unchanged":"updated",passes:p,updatedEntries:d===e?0:h.length,layout:n};const y=JSON.stringify([h,n.pages.map(e=>[e.index,e.sectionIndex])]);if(u.has(y))return o("nonconvergent",p);u.add(y);const v=[...f.blocks.slice(0,g.start+1),...h.map($T),...f.blocks.slice(g.end)];d={...d,document:{...d.document,sections:i.map((e,t)=>t===a?{...e,blocks:v}:e)},selection:e.selection}}return o("nonconvergent",n)}var WT=e=>({...wo(""),kind:"fieldInstruction",fieldInstruction:e}),jT=e=>({...wo(""),kind:"fieldChar",fieldChar:{kind:e}});function UT(e){if("main"!==jr(e)||e.trackChangesEnabled||!ga(e.selection))return;const t=Lo(e.document),n=Ua(e),r=t[n];if(!r||r.blocks.some(e=>"paragraph"!==e.type))return;const o=r.blocks,a=o.findIndex(t=>t.id===e.selection.focus.paragraphId),i=o[a];if(!i||wa(i,e.selection.focus)!==oi(i)||i.sdtWrappers?.length||i.list||i.numberingRevision||i.dropCap||i.style?.propertyRevision||i.runs.some(e=>e.revision||e.revisionRangeMarker||e.sdtWrappers?.length||e.styles?.propertyRevision))return;const s=Ga(o);return s.diagnostics.length?void 0:{sections:t,index:n,section:r,paragraphs:o,at:a,graph:s}}function VT(e,t,n=f){const r=UT(e);if(!(r&&function(e){const t=UT(e);if(!t||Object.keys(e.document.bookmarks?.items??{}).length||Object.keys(e.document.comments?.items??{}).length||(t.section.pageSettings.columns?.count??1)>1)return!1;if(t.graph.spans.some(e=>{const t=hI(e.code.map(e=>"instruction"===e.kind?e.raw:"").join(""));return void 0!==t?.captionIdentifier||void 0!==t?.unlabeledIdentifier}))return!1;for(const n of t.sections){if(n.blocks.some(e=>"paragraph"!==e.type))return!1;const e=Ga(n.blocks);if(e.diagnostics.length||e.spans.some(e=>{const t=hI(e.code.map(e=>"instruction"===e.kind?e.raw:"").join(""));return void 0!==t?.captionIdentifier||void 0!==t?.unlabeledIdentifier}))return!1}return!0}(e)&&t.identifier&&/^[A-Za-z_][A-Za-z0-9_ ]{0,63}$/.test(t.identifier)))return e;const o=t.unlabeled?` TOC \\a ${t.identifier} `:` TOC \\c "${t.identifier}" `;if(!hI(o))return e;const a=Go("");a.runs=[jT("begin"),WT(o),jT("separate")];const i=Go("");i.runs=[jT("end")];const s=function(e,t,n){return{...e,document:{...e.document,sections:t.sections.map((e,r)=>r===t.index?{...e,blocks:n}:e)}}}(e,r,[...r.paragraphs.slice(0,r.at+1),a,i,...r.paragraphs.slice(r.at+1)]),l=HT(s,n);return"updated"===l.status?l.state:e}function KT(e){const t=[];let n="",r=!1;for(let o=0;o<e.length;o++){const a=e[o];if("'"!==a)if(";"!==a||r)n+=a;else{if(!n)return;t.push(n),n=""}else r=!r,n+=a}if(!r&&n)return t.push(n),t.length<=3?t:void 0}function _T(e){let t="",n="",r="",o=!1,a=!1,i=!1;for(let s=0;s<e.length;s++){const l=e[s];if("'"===l){const r=e.indexOf("'",s+1);if(r<0)return;const a=e.slice(s+1,r);o?n+=a:t+=a,s=r;continue}if("0"!==l&&"#"!==l&&"x"!==l)if(!o||"."!==l&&","!==l)if("%"!==l){if(!/[\s+\-$€£¥()]/.test(l))return;o?n+=l:t+=l}else i=!0,o?n+=l:t+=l;else","===l&&(a=!0),r+=l;else r+=l,o=!0}return{prefix:t,suffix:n,mask:r,grouping:a,percent:i}}function XT(e){if(!e||e.length>256||[...e].some(e=>e.charCodeAt(0)<32||127===e.charCodeAt(0)))return!1;const t=KT(e);if(!t)return!1;const n=t.map(e=>_T(e));return n.every(e=>!!e)&&n.some(e=>/[0#x]/.test(e.mask))}function qT(e,t){if(!Number.isFinite(e)||!XT(t))return;const n=KT(t).map(e=>_T(e));let r,o=!1;1===n.length?(r=n[0],o=e<0&&!r.prefix.includes("-")):r=2===n.length?e<0?n[1]:n[0]:0===e?n[2]:e<0?n[1]:n[0];const a=function(e,t){if(!/[0#x]/.test(t.mask))return t.prefix+t.suffix;const n=t.mask.indexOf(".");if(n>=0&&t.mask.indexOf(".",n+1)>=0)return;const r=n<0?t.mask:t.mask.slice(0,n),o=n<0?"":t.mask.slice(n+1),a=(r.match(/0/g)??[]).length,i=(o.match(/0/g)??[]).length,s=(o.match(/x/g)??[]).length,l=(o.match(/[0#x]/g)??[]).length;if(a>21||l>20||l<i+s)return;let c,d=Math.abs(e);if(t.percent&&(d*=100),s>0){const e=10**s;d=Math.floor(d*e)/e}try{c=new Intl.NumberFormat("en-US",{useGrouping:t.grouping,minimumIntegerDigits:a||1,minimumFractionDigits:i,maximumFractionDigits:l}).format(d)}catch{return}return t.prefix+c+t.suffix}(e,r);return void 0===a?void 0:o?`-${a}`:a}var GT=/* @__PURE__ */new Set(["MERGEFORMAT","CHARFORMAT","Caps","FirstCap","Upper","Lower"]),YT=/* @__PURE__ */new Set(["alphabetic","ALPHABETIC","Arabic","CardText","DollarText","Hex","OrdText","Ordinal","roman","ROMAN"]);function ZT(e,t){if(!e||"quoted"!==e.kind&&"word"!==e.kind)return;const n=e.value;return!n||n.length>256||[...n].some(e=>e.charCodeAt(0)<32||127===e.charCodeAt(0))?void 0:t(n)?n:void 0}var JT=/* @__PURE__ */new Set(["=","<>",">","<",">=","<="]),QT=/^-?(?:0|[1-9]\d*)(?:\.\d+)?$/;function eP(e,t,n){if(r=n,!JT.has(r)||e.length>4096||t.length>4096||[...e+t].some(e=>e.charCodeAt(0)<32))return;var r;if(QT.test(e)&&QT.test(t)){const r=Number(e),o=Number(t);if(!Number.isFinite(r)||!Number.isFinite(o))return;switch(n){case"=":return r===o;case"<>":return r!==o;case">":return r>o;case"<":return r<o;case">=":return r>=o;case"<=":return r<=o}}if("="!==n&&"<>"!==n)return;if(!(e.includes("*")||e.includes("?")||t.includes("*")||t.includes("?")))return"="===n?e===t:e!==t;if(e.length+t.length>128)return;const o=(e=>e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\?/g,".").replace(/\*/g,".*"))(t.includes("*")||t.includes("?")?t:e),a=t.includes("*")||t.includes("?")?e:t;let i;try{i=new RegExp(`^${o}$`,"u").test(a)}catch{return}return"="===n?i:!i}var tP=e=>!!e&&e.length<=128&&/^[\p{L}_][\p{L}\p{N}_ .-]*$/u.test(e);function nP(e,t){const n=e[t];if(n&&"switch"!==n.kind){if("MERGEFIELD"===n.value){const n=e[t+1];if(!n||"switch"===n.kind||!tP(n.value))return;return{value:{kind:"mergeField",name:n.value},next:t+2}}if(!(n.value.length>4096||/[\r\n\t]/.test(n.value)))return{value:{kind:"literal",value:n.value,quoted:"quoted"===n.kind},next:t+1}}}function rP(e){const t=La(e);if(t.error||!t.command)return;const n=t.tokens.slice(1);if("NEXT"===t.command)return n.length?void 0:{type:"NEXT"};if("NEXTIF"===t.command||"SKIPIF"===t.command){const e=nP(n,0),r=e&&n[e.next];if(!e||!r||"word"!==r.kind)return;const o=nP(n,e.next+1);if(!o||o.next!==n.length)return;return{type:t.command,left:e.value,operator:r.value,right:o.value}}if("MERGEFIELD"!==t.command)return;const r=n[0];if(!r||"switch"===r.kind||!tP(r.value))return;const o=function(e,t){const n={},r=[],o=/* @__PURE__ */new Set;for(let a=0;a<e.length;a++){const i=e[a];if("switch"!==i.kind){r.push(i);continue}const s=i.value;if("*"===s){if(!t.text&&!t.number){r.push(i);continue}const s=e[++a];if(!s||"word"!==s.kind)return;const l=s.value;if(GT.has(l)){if(!t.text||o.has("text"))return;o.add("text"),"MERGEFORMAT"===l?n.mergeFormat=!0:"CHARFORMAT"===l?n.charFormat=!0:n.capitalization=l}else if(YT.has(l)){if(!t.number||o.has("number"))return;o.add("number"),n.capitalization=l}else{if("ArabicDash"!==l)return;if(!t.arabicDash||o.has("number"))return;o.add("number"),n.capitalization="ArabicDash"}}else if("#"===s){if(!t.numericPicture){r.push(i);continue}if(o.has("numeric"))return;const s=ZT(e[++a],XT);if(void 0===s)return;o.add("numeric"),n.numericPicture=s}else if("@"===s){if(!t.datePicture){r.push(i);continue}if(o.has("date"))return;const s=ZT(e[++a],ui);if(void 0===s)return;o.add("date"),n.datePicture=s}else r.push(i)}return{switches:n,remaining:r}}(n.slice(1),{text:!0});if(!o)return;const a={type:"MERGEFIELD",name:r.value};for(let i=0;i<o.remaining.length;i++){const e=o.remaining[i];if("switch"!==e.kind)return;const t=e.value.toLowerCase();if("m"===t){if(a.mapped)return;a.mapped=!0;continue}if("v"===t){if(a.vertical)return;a.vertical=!0;continue}if("b"!==t&&"f"!==t)return;const n=o.remaining[++i];if(!n||"quoted"!==n.kind||n.value.length>4096)return;if("b"===t){if(void 0!==a.before)return;a.before=n.value}else{if(void 0!==a.after)return;a.after=n.value}}return Object.keys(o.switches).length&&(a.format=o.switches),a}function oP(e,t){return"mergeField"===e.kind?t[e.name]:e.quoted?e.value:t[e.value]??e.value}function aP(e,t){const n=t[e.name];if(void 0!==n)return n?`${e.before??""}${n}${e.after??""}`:""}function iP(e,t){if("NEXT"===e.type)return{advanceInPlace:!0,skipDocument:!1};if(!e.left||!e.right||!e.operator)return;const n=oP(e.left,t),r=oP(e.right,t);if(void 0===n||void 0===r)return;const o=eP(n,r,e.operator);return void 0!==o?"NEXTIF"===e.type?{advanceInPlace:o,skipDocument:!1}:{advanceInPlace:!1,skipDocument:o}:void 0}function sP(e){const t=[],n=/* @__PURE__ */new Set;for(const r of Lo(e)){const e=[];for(const t of r.blocks){if("paragraph"!==t.type||n.has(t.id))return;n.add(t.id),e.push(t)}const o=Ga(e);if(o.diagnostics.length)return;for(const n of o.spans){const r=n.code.map(e=>"instruction"===e.kind?e.raw:"").join(""),o=La(r);if("MERGEFIELD"!==o.command&&"NEXT"!==o.command&&"NEXTIF"!==o.command&&"SKIPIF"!==o.command)continue;const a=rP(r);if(!a||null!==n.parentIndex)return;t.push({span:n,paragraph:e[n.begin.paragraphIndex],instruction:a})}}return t}function lP(e){if("MERGEFIELD"===e.instruction.type)return!0;if(e.span.begin.paragraphIndex!==(e.span.end?.paragraphIndex??-1))return!1;const t=e.span.code.map(e=>"instruction"===e.kind?e.raw:"").join("");return!/NEXTIF|SKIPIF|\bNEXT\b/i.test(t.replace(/^\s*(?:NEXT|NEXTIF|SKIPIF)\b/i,""))}function cP(e,t){const n=sP(e);if(!n||!n.every(lP))return;const r=/* @__PURE__ */new Map,o=e=>{let t=r.get(e.id);return t||(t={...e,runs:e.runs.map(e=>({...e}))},r.set(e.id,t)),t};let a=null;for(const{span:s,paragraph:l,instruction:c}of n){const e=o(l);if("MERGEFIELD"===c.type){const n=aP(c,t);if(void 0===n)return;for(const t of s.result){if("run"!==t.kind)return;const r=e.runs[t.point.runIndex];if(!r)return;r.text=n}}else{const n=iP(c,t);if(!n)return;a??=n;for(const t of s.result){if("run"!==t.kind)return;e.runs[t.point.runIndex].text=""}}}const i=Lo(e).map(e=>({...e,blocks:e.blocks.map(e=>"paragraph"===e.type?r.get(e.id)??e:e)}));return{document:{...e,sections:i},decision:a}}function dP(e,t,n=!1){return"paragraph"!==e.type?e:{...e,id:`${e.id}${t}`,...n?{style:{...e.style,pageBreakBefore:!0}}:{},runs:e.runs.map(e=>({...e,id:`${e.id}${t}`}))}}function uP(e,t,n){const r=/* @__PURE__ */new Map;for(const[o,a]of t.entries())for(const e of Lo(a))for(const t of e.blocks)if("paragraph"===t.type&&n.has(t.id)){const e=r.get(t.id)??[];e.push(dP(t,`:merge:${o}`,o>0)),r.set(t.id,e)}return{...e,sections:Lo(e).map(e=>({...e,blocks:e.blocks.flatMap(e=>"paragraph"===e.type&&n.has(e.id)?r.get(e.id)??[e]:[e])}))}}function pP(e,t){if(e)return function(e,t){if(!Array.isArray(e)||e.length>1e3)return;const n=sP(t);if(!n||!n.every(lP))return;const r=new Set(n.map(e=>e.paragraph.id)),o=[];let a=[];for(const i of e){const e=cP(t,i);if(!e)return;e.decision?.skipDocument?a=[]:(a.push(e.document),e.decision?.advanceInPlace||(o.push(uP(t,a,r)),a=[]))}return a.length&&o.push(uP(t,a,r)),o}(t,e.document)}var fP={ABS:1,INT:1,ROUND:2,SIGN:1,MOD:2,MIN:-1,MAX:-1,SUM:-1,PRODUCT:-1,AVERAGE:-1,COUNT:-1,AND:-1,OR:-1,NOT:1,TRUE:0,FALSE:0,DEFINED:1},gP=e=>"number"==typeof e&&Number.isFinite(e)&&Math.abs(e)<=1e12;function mP(e,t={},n=0){if(n>32||"string"!=typeof e)return;const r=function(e){const t=[];let n=0;for(;n<e.length;){const r=e[n];if(/\s/.test(r)){n++;continue}if(t.length>=256)return;if(/[0-9.]/.test(r)){let r=n;for(;r<e.length&&/[0-9.]/.test(e[r]);)r++;const o=e.slice(n,r);if(!/^(?:\d+(?:\.\d*)?|\.\d+)$/.test(o))return;t.push({kind:"number",value:o}),n=r;continue}if(/[\p{L}_]/u.test(r)){let r=n;for(;r<e.length&&/[\p{L}\p{N}_.]/u.test(e[r]);)r++;t.push({kind:"identifier",value:e.slice(n,r)}),n=r;continue}if("()".includes(r)){t.push({kind:"paren",value:r}),n++;continue}if(","===r||";"===r){t.push({kind:"comma",value:r}),n++;continue}const o=e.slice(n,n+2);if(["<=",">=","<>"].includes(o))t.push({kind:"operator",value:o}),n+=2;else{if(!["+","-","*","/","%","^","=","<",">"].includes(r))return;t.push({kind:"operator",value:r}),n++}}return t.length?t:void 0}(e);if(!r)return;let o=0;const a=()=>r[o],i=()=>r[o++],s=e=>"boolean"==typeof e?e?1:0:gP(e)?e:void 0,l=()=>{const e=i();if(!e)return;if("number"===e.kind)return Number(e.value);if("paren"===e.kind){const e=f();return"paren"===a()?.kind&&")"===a()?.value?(i(),e):void 0}if("identifier"!==e.kind)return;const n=e.value.toUpperCase();if("paren"!==a()?.kind||"("!==a()?.value)return(e=>{const n=e.toLowerCase(),r=t.variables?.[n]??t.variables?.[e]??t.record?.[e];if(void 0!==r)return"TRUE"===r||"true"===r||"FALSE"!==r&&"false"!==r&&(gP(Number(r))?Number(r):void 0)})(e.value);if(!(n in fP))return;i();const r=a()?.value,o=[];if(")"===a()?.value)i();else for(;;){const e=f();if(void 0===e)return;o.push(e);const t=a();if("comma"!==t?.kind){if("paren"===t?.kind&&")"===t.value){i();break}return}i()}const l=fP[n];if(l>=0&&o.length!==l)return;const c=o.map(s);switch(n){case"TRUE":return!0;case"FALSE":return!1;case"DEFINED":{const e=r??"";return void 0!==t.variables?.[e.toLowerCase()]||void 0!==t.variables?.[e]||void 0!==t.record?.[e]}case"NOT":return!s(c[0]);case"AND":return o.every(e=>!!s(e));case"OR":return o.some(e=>!!s(e));case"ABS":return Math.abs(c[0]);case"INT":return Math.trunc(c[0]);case"SIGN":return Math.sign(c[0]);case"MOD":return c[0]%c[1];case"ROUND":{const e=c[1]??0;if(!Number.isSafeInteger(e)||e<0||e>10)return;const t=10**e;return Math.round(c[0]*t)/t}case"MIN":return Math.min(...c);case"MAX":return Math.max(...c);case"SUM":return c.reduce((e,t)=>e+t,0);case"PRODUCT":return c.reduce((e,t)=>e*t,1);case"AVERAGE":return c.reduce((e,t)=>e+t,0)/c.length;case"COUNT":return c.length;default:return}},c=()=>{const e=a();if("operator"===e?.kind&&("+"===e.value||"-"===e.value)){i();const t=s(c());return void 0===t?void 0:"-"===e.value?-t:t}return l()},d=()=>{const e=s(c());if(void 0!==e){if("operator"===a()?.kind&&"^"===a()?.value){i();const t=s(c());if(void 0===t||!Number.isSafeInteger(t)||Math.abs(t)>64)return;return e**t}return e}},u=()=>{let e=s(d());if(void 0!==e){for(;;){const t=a();if("operator"!==t?.kind||!["*","/","%"].includes(t.value))break;i();const n=s(d());if(void 0===n)return;if(e="*"===t.value?e*n:"/"===t.value?0===n?void 0:e/n:e%n,void 0===e||!gP(e))return}return e}},p=()=>{let e=s(u());if(void 0!==e){for(;;){const t=a();if("operator"!==t?.kind||!["+","-"].includes(t.value))break;i();const n=s(u());if(void 0===n)return;if(e="+"===t.value?e+n:e-n,!gP(e))return}return e}},f=()=>{let e=p();if(void 0!==e){for(;;){const t=a();if(!t)break;if("identifier"===t.kind&&["AND","OR"].includes(t.value.toUpperCase())){i();const n=p();if(void 0===n)return;e="AND"===t.value.toUpperCase()?!!s(e)&&!!s(n):!!s(e)||!!s(n);continue}if("operator"!==t.kind||!["=","<>","<","<=",">",">="].includes(t.value))break;i();const n=p();if(void 0===n)return;switch(t.value){case"=":e=e===n;break;case"<>":e=e!==n;break;case"<":e=s(e)<s(n);break;case"<=":e=s(e)<=s(n);break;case">":e=s(e)>s(n);break;case">=":e=s(e)>=s(n);break;default:return}}return e}},g=f();return o===r.length?g:void 0}var hP=e=>!!e&&e.length<=128&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(e),bP=(e,t=4096)=>e&&("quoted"===e.kind||"word"===e.kind)&&e.value.length<=t&&![...e.value].some(e=>e.charCodeAt(0)<32)?e.value:void 0;function yP(e){const t=La(e);if(t.error||!t.command)return;const n=t.tokens.slice(1);if("SET"===t.command){const e=n[0],t=n[1];if(!e||!hP(e.value)||2!==n.length||"quoted"!==t?.kind&&"word"!==t?.kind)return;const r=bP(t);return void 0===r?void 0:{type:"SET",name:e.value,value:r}}if("ASK"===t.command||"FILLIN"===t.command){const e="ASK"===t.command,r=n[0],o=e?bP(n[1]):void 0===r?"":bP(r);if(void 0===o)return;let a,i,s=!1,l=e?2:1;if(e){if(!r||!hP(r.value))return;a=r.value}const c=/* @__PURE__ */new Set;for(;l<n.length;l++){const e=n[l];if("switch"!==e.kind)return;const t=e.value.toLowerCase();if(c.has(t))return;if(c.add(t),"o"===t){if(s)return;s=!0;continue}if("d"!==t)return;const r=n[++l],o="quoted"===r?.kind?bP(r):void 0;if(void 0===o||void 0!==i)return;i=o}return e?{type:"ASK",name:a,prompt:o,...void 0!==i?{defaultValue:i}:{},once:s}:{type:"FILLIN",prompt:o,...void 0!==i?{defaultValue:i}:{},once:s}}if("COMPARE"===t.command){const e=n[0],t=n[1],r=n[2];if(!e||!t||!r||3!==n.length||"word"!==t.kind||"switch"===e.kind||"switch"===r.kind)return;const o=bP(e),a=bP(r);if(void 0===o||void 0===a)return;return{type:"COMPARE",left:o,right:a,operator:t.value,quoted:["quoted"===e.kind,"quoted"===r.kind]}}if("="===t.command){const e=n.findIndex(e=>"switch"===e.kind&&"#"===e.value),t=e<0?n:n.slice(0,e);if(!t.length||t.some(e=>"switch"===e.kind))return;const r=t.map(e=>e.raw).join(" ");if(r.length>4096)return;let o;if(e>=0){if(e!==n.length-2||"quoted"!==n[e+1]?.kind)return;if(o=bP(n[e+1],256),!o||!XT(o))return}return{type:"FORMULA",expression:r,...o?{picture:o}:{}}}}function vP(e,t,n){const r=e.toLowerCase();return n[r]??t.variables?.[r]??t.record?.[e]}function xP(e,t,n,r){const o=()=>({text:r,variables:n,status:"preserved"});if("SET"===e.type){const r=vP(e.value,t,n)??e.value;return{text:"",variables:{...n,[e.name.toLowerCase()]:r},status:"resolved"}}if("ASK"===e.type){if(!t.prompt)return o();const r=t.prompt(e.prompt,e.defaultValue);return void 0===r||r.length>4096||/[\r\n\t]/.test(r)?o():{text:"",variables:{...n,[e.name.toLowerCase()]:r},status:"resolved"}}if("FILLIN"===e.type){if(!t.prompt)return o();const r=t.prompt(e.prompt,e.defaultValue);return void 0===r||r.length>4096||/[\r\n\t]/.test(r)?o():{text:r,variables:n,status:"resolved"}}if("COMPARE"===e.type){const r=eP(e.quoted[0]?e.left:vP(e.left,t,n)??e.left,e.quoted[1]?e.right:vP(e.right,t,n)??e.right,e.operator);return void 0===r?o():{text:r?"1":"0",variables:n,status:"resolved"}}const a={...t.variables,...n,...t.record},i=mP(e.expression,{variables:a});if(void 0===i)return o();const s="boolean"==typeof i?i?1:0:i,l=e.picture?qT(s,e.picture):String(s);return void 0===l?o():{text:l,variables:n,status:"resolved"}}function wP(e,t,n,r){if(e.trackChangesEnabled)return e;let o,a=!1;if(po(e.document,{block:e=>("table"===e.type&&e.rows.some(e=>e.sdtWrappers?.some(e=>e.groupId===t))&&(o&&(a=!0),o=e),e)}),!o||a)return e;const i=o,s=i.rows,l=s.findIndex(e=>e.sdtWrappers?.some(e=>e.groupId===n&&"repeatingSectionItem"===e.sdtPr.subtype?.kind));if(l<0)return e;const c=s[l].sdtWrappers?.find(e=>e.groupId===t&&"repeatingSection"===e.sdtPr.subtype?.kind);if(!c||c.sdtPr.repeatingSectionProperties?.doNotAllowInsertDeleteSection&&("insertAfter"===r||"remove"===r)||c.sdtPr.lock&&"unlocked"!==c.sdtPr.lock)return e;const d=s.map((e,t)=>({row:e,rowIndex:t})).filter(({row:e})=>e.sdtWrappers?.some(e=>e.groupId===t));if(!d.length||d.some(({row:e,rowIndex:t},n)=>t!==d[0].rowIndex+n||1!==e.sdtWrappers?.filter(e=>"repeatingSectionItem"===e.sdtPr.subtype?.kind).length))return e;const u=d.map(({row:e})=>e.sdtWrappers.find(e=>"repeatingSectionItem"===e.sdtPr.subtype?.kind).groupId);if(new Set(u).size!==u.length)return e;const p=c.sdtPr.dataBinding,f=/* @__PURE__ */new Set,g=/* @__PURE__ */new Map,m=e=>[...e.sdtWrappers??[],...e.cells.flatMap(e=>[...e.sdtWrappers??[],...e.blocks.flatMap(e=>[...e.sdtWrappers??[],..."paragraph"===e.type?e.runs.flatMap(e=>e.sdtWrappers??[]):[]])])];for(const[S,{row:C}]of d.entries())for(const n of m(C)){const r=n.sdtPr.dataBinding;if(!r||n.groupId===t)continue;if(!p?.xpath||!p.storeItemID||!r.xpath||r.storeItemID?.replace(/[{}]/g,"").toLowerCase()!==p.storeItemID.replace(/[{}]/g,"").toLowerCase()||(r.prefixMappings??"")!==(p.prefixMappings??""))return e;const o=`${p.xpath}[${S+1}]`;if(!r.xpath.startsWith(`${o}/`))return e;const a=g.get(n.groupId);if(void 0!==a&&a!==S)return e;g.set(n.groupId,S),f.add(n.groupId)}const h=e=>(e??[]).every(e=>(!e.sdtPr.dataBinding||e.groupId===t||f.has(e.groupId))&&!e.sdtPr.unknownXml&&!e.sdtEndPrXml&&(!e.sdtPr.lock||"unlocked"===e.sdtPr.lock));if(c.sdtPr.dataBinding){let n=!1;const r=e=>{e?.some(e=>e.groupId!==t&&!f.has(e.groupId)&&e.sdtPr.dataBinding)&&(n=!0)};if(po(e.document,{block:e=>(r(e.sdtWrappers),"paragraph"===e.type&&e.runs.forEach(e=>r(e.sdtWrappers)),e),row:e=>r(e.sdtWrappers),cell:e=>r(e.sdtWrappers)}),n)return e}const b=e=>h(e.sdtWrappers)&&!e.style?.revision&&!e.extAttributes&&e.cells.every(e=>!e.vMerge&&!e.rowSpan&&!e.extAttributes&&h(e.sdtWrappers)&&e.blocks.every(e=>"paragraph"===e.type&&h(e.sdtWrappers)&&e.runs.every(e=>"text"===e.kind&&!e.revision&&!e.revisionRangeMarker&&h(e.sdtWrappers))));if(d.some(({row:e})=>!b(e)))return e;const y=[...s],v=new Map(d.map(({row:e},t)=>[e.id,t+1]));if("insertAfter"===r){const e=/* @__PURE__ */new Map,n=n=>n?.map(n=>{if(n.groupId===t)return n;let r=e.get(n.groupId);r||(r=_o("sdt"),e.set(n.groupId,r));const{id:o,...a}=n.sdtPr;return{...n,groupId:r,sdtPr:a}}),r=s[l],o={...r,id:_o("table-row"),sdtWrappers:n(r.sdtWrappers),cells:r.cells.map(e=>({...e,id:_o("table-cell"),sdtWrappers:n(e.sdtWrappers),blocks:e.blocks.map(e=>"paragraph"!==e.type?e:{...e,id:_o("paragraph"),sdtWrappers:n(e.sdtWrappers),runs:e.runs.map(e=>({...e,id:_o("run"),sdtWrappers:n(e.sdtWrappers)}))})}))};v.set(o.id,l-d[0].rowIndex+1),y.splice(l+1,0,o)}else if("remove"===r){if(d.length<2||e.document.bookmarks||e.document.comments)return e;const t=s[l],n=new Set(t.cells.flatMap(e=>e.blocks.map(e=>e.id)));if(n.has(e.selection.anchor.paragraphId)||n.has(e.selection.focus.paragraphId))return e;y.splice(l,1)}else{const t=l+("moveUp"===r?-1:1);if(!d.some(({rowIndex:e})=>e===t))return e;[y[l],y[t]]=[y[t],y[l]]}const x=c.sdtPr.dataBinding?ro(e.document.sourcePackage,c.sdtPr.dataBinding,d.length,l-d[0].rowIndex,r):e.document.sourcePackage;if(c.sdtPr.dataBinding&&!x)return e;if(p?.xpath&&f.size){const e=p.xpath,n=(n,r,o)=>n?.map(n=>{const a=n.sdtPr.dataBinding;if(!a||n.groupId===t)return n;const i=`${e}[${r}]`;return{...n,sdtPr:{...n.sdtPr,dataBinding:{...a,xpath:`${e}[${o}]${a.xpath.slice(i.length)}`}}}});for(let t=d[0].rowIndex;t<d[0].rowIndex+d.length+("insertAfter"===r?1:"remove"===r?-1:0);t+=1){const e=y[t],r=v.get(e.id),o=t-d[0].rowIndex+1;y[t]={...e,sdtWrappers:n(e.sdtWrappers,r,o),cells:e.cells.map(e=>({...e,sdtWrappers:n(e.sdtWrappers,r,o),blocks:e.blocks.map(e=>"paragraph"!==e.type?e:{...e,sdtWrappers:n(e.sdtWrappers,r,o),runs:e.runs.map(e=>({...e,sdtWrappers:n(e.sdtWrappers,r,o)}))})}))}}}const w=po(e.document,{block:e=>e===i?{...i,rows:y}:e}),I={...e,document:{...w,sourcePackage:x??void 0}};if("remove"===r&&f.size){const t=new Set(m(s[l]).filter(e=>f.has(e.groupId)).map(e=>e.groupId));return ja(e,I,t)}return eo(e,I,()=>{})}function IP(e,t){if("main"===jr(e)&&!e.trackChangesEnabled&&t)for(const n of Lo(e.document)){const e=[];for(const t of n.blocks){if("paragraph"!==t.type)return;e.push(t)}const r=Ga(e);if(r.diagnostics.length)return;for(const n of r.spans){const r=e[n.begin.paragraphIndex],o=r.runs.find(e=>e.id===n.begin.runId);if("fieldChar"!==o?.kind||o.fieldChar.formField?.name!==t)continue;if(null!==n.parentIndex||!n.separator||!n.end||n.code.some(e=>"instruction"!==e.kind)||n.result.some(e=>"run"!==e.kind))return;const a=o.fieldChar.formField;return{name:t,control:a.control,value:a.value,enabled:a.enabled,paragraphId:r.id,beginRunId:o.id,resultRunIds:n.result.map(e=>"run"===e.kind?e.point.runId:"")}}}}function SP(e,t){if("string"!=typeof t||t.length>4096||[...t].some(e=>e.charCodeAt(0)<32))return!1;if("text"===e.control){const n=e.textInput?.maxLength;return!(void 0!==n&&t.length>n)&&!("number"===e.textInput?.type&&t&&!/^-?(?:\d+)(?:\.\d+)?$/.test(t))}return"checkBox"===e.control?""===t||"x"===t:(e.ddList?.listEntries??[]).includes(t)}function CP(e,t,n){const r=IP(e,t);if(!r||!r.enabled)return e;const o=Lo(e.document);for(const[a,i]of o.entries()){const t=i.blocks.findIndex(e=>e.id===r.paragraphId);if(t<0)continue;const s=i.blocks[t],l=s.runs.find(e=>e.id===r.beginRunId);if("fieldChar"!==l?.kind||!l.fieldChar.formField||!SP(l.fieldChar.formField,n))return e;const c=s.runs.map(e=>{if(e.id===r.beginRunId&&"fieldChar"===e.kind){const t=e.fieldChar.formField;return{...e,fieldChar:{...e.fieldChar,formField:{...t,value:n,..."checkBox"===t.control?{checkBox:{...t.checkBox,checked:"x"===n}}:{}}}}}return r.resultRunIds.includes(e.id)?{...e,text:e.id===r.resultRunIds[0]?n:""}:e}),d={...s,runs:c},u=[...i.blocks];u[t]=d;const p={...e,document:{...e.document,sections:o.map((e,t)=>t===a?{...e,blocks:u}:e)}};return Oo(e,p)}return e}function kP(e,t){const n=t.type??"REF",r=function(e,t){return yk(e).find(e=>e.name===t)}(e,t.bookmark);if(!r)return e;const o=ga(e.selection)?e:te(e),{paragraph:a,index:i,offset:s}=ae(o),l=gt(a,s),c={type:n,bookmark:t.bookmark},d="REF"===n?Y(e.document).bookmarkText(r.name):void 0,u={id:`run:${n.toLowerCase()}:${Math.random().toString(36).slice(2,9)}`,text:d&&!/[\r\n]/.test(d)?d:"1",kind:"field",field:c,styles:l},p=N(a,[...Ln(a,0,s),u,...Ln(a,s,oi(a))]),f=ko(o),g=[...Yo(f.slice(0,i)),p,...Yo(f.slice(i+1))];return Vt(o,g,J(xi(p,s+u.text.length)))}function TP(e){const t=()=>!e.isReadOnly()&&"main"===jr(e.state())&&!e.state().trackChangesEnabled,n=n=>{if(!t())return;e.resetTransactionGrouping();const r={now:Date.now(),timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone};e.applyTransactionalState(e=>Ak(e,void 0,n,r).state),e.clearPreferredColumn(),e.focusInput()},r=(t,n)=>{if(e.isReadOnly()||!t(e.state()))return!1;let r=!1;return e.resetTransactionGrouping(),e.applyTransactionalState(o=>{if(e.isReadOnly()||!t(o))return o;const a=n(o);return r=a!==o,a}),r&&(e.clearPreferredColumn(),e.focusInput()),r},o=t=>{if(e.isReadOnly())return!1;let n=!1;return e.resetTransactionGrouping(),e.applyTransactionalState(e=>{const r=t(e);return n=r!==e,r}),n&&(e.clearPreferredColumn(),e.focusInput()),n};return{canMarkIndexEntry:()=>!e.isReadOnly()&&rT(e.state()),canInsertIndex:()=>!e.isReadOnly()&&oT(e.state()),canUpdateIndex:()=>!e.isReadOnly()&&aT(e.state()),markIndexEntry:e=>r(rT,t=>function(e,t){const n=eT(e);if(!n||!nT(t.identifier)||!Array.isArray(t.path)||!t.path.length||t.path.some(e=>"string"!=typeof e||e.trim()!==e||!e||/[:;\\]/.test(e)||[...e].some(e=>e.charCodeAt(0)<32||127===e.charCodeAt(0))))return e;if(!rT(e))return e;const r=' XE "'+t.path.join(":").replace(/"/g,'\\"')+'"'+(t.identifier?" \\f "+t.identifier:"")+(t.boldPage?" \\b":"")+(t.italicPage?" \\i":"")+" ";if(!Ok(r))return e;const o={...n.p,runs:[...n.p.runs,Qk("begin",!0),Jk(r,!0),Qk("end",!0)]},a=tT(e,n,n.paragraphs.map((e,t)=>t===n.at?o:e));return Bk(a.document)?a:e}(t,e)),insertIndex:e=>r(oT,t=>function(e,t,n=f){const r=eT(e);if(!r||!nT(t.identifier)||"string"!=typeof t.locale||!/^[A-Za-z]{2,3}(?:-[A-Za-z]{2})?$/.test(t.locale)||Object.keys(e.document.bookmarks?.items??{}).length||Object.keys(e.document.comments?.items??{}).length)return e;if(!oT(e))return e;const o=' INDEX \\z "'+t.locale+'"'+(t.identifier?" \\f "+t.identifier:"")+" ";if(!zk(o))return e;const a=Go("");a.runs=[Qk("begin"),Jk(o),Qk("separate")];const i=Go("");i.runs=[Qk("end")];const s=Zk(tT(e,r,[...r.paragraphs.slice(0,r.at+1),a,i,...r.paragraphs.slice(r.at+1)]),void 0,n);return"updated"===s.status?s.state:e}(t,e)),updateIndex:e=>r(aT,t=>function(e,t){const n=Zk(e,t);return"updated"===n.status?n.state:e}(t,e)),canUpdateBodyFields:t,updateBodyFields:()=>n("all"),updateSelectedFields:()=>n("selection"),insertFieldCode:e=>o(t=>function(e,t){if("string"!=typeof t||La(t).error||Xe(e))return e;const n=ga(e.selection)?e:te(e),{paragraph:r,index:o,offset:a}=ae(n),i=gt(r,a),s={id:iT("run:instr"),kind:"fieldInstruction",text:"",fieldInstruction:t,styles:i?{...i}:void 0},l={id:iT("run:fld"),kind:"fieldChar",text:"",fieldChar:{kind:"begin",dirty:!0},styles:i?{...i}:void 0},c=sT("separate",i),d=sT("end",i),u={id:iT("run:result"),kind:"text",text:"",styles:i?{...i}:void 0},p={...r,runs:[...Ln(r,0,a),l,s,c,u,d,...Ln(r,a,oi(r))]},f=ko(n);return Vt(n,[...Yo(f.slice(0,o)),p,...Yo(f.slice(o+1))],J(xi(p,a)))}(t,e)),editFieldCode:(e,t)=>o(n=>cT(n,e,t)),editFieldCodeAtSelection:e=>o(t=>{const n=function(e){const t=ko(e),n=Ga(t);if(n.diagnostics.length)return;const{anchor:r}=e.selection,o=n.spans.find(e=>null===e.parentIndex&&e.begin.paragraphId===r.paragraphId&&e.end&&e.begin.offset<=r.offset&&e.end.offset>=r.offset);return o&&!o.code.some(e=>"instruction"!==e.kind)?o.code.find(e=>"instruction"===e.kind)?.point.runId:void 0}(t);return n?cT(t,n,e):t}),toggleFieldLock:e=>o(t=>function(e,t){const n=ko(e),r=Ga(n);if(r.diagnostics.length)return e;const o=r.spans.find(e=>null===e.parentIndex&&e.begin.runId===t&&!!e.separator&&!!e.end&&e.begin.paragraphIndex===e.end.paragraphIndex);if(!o)return e;const a=n[o.begin.paragraphIndex].runs.find(e=>e.id===o.begin.runId);return a&&"fieldChar"===a.kind?lT(e,o.begin.paragraphIndex,/* @__PURE__ */new Map([[a.id,{...a,fieldChar:{...a.fieldChar,fieldLock:!a.fieldChar.fieldLock||void 0}}]])):e}(t,e)),toggleFieldCodes:t=>e.applyState(function(e,t){return e.showFieldCodes===t?e:{...e,showFieldCodes:t}}(e.state(),t)),navigateField:t=>e.applyState(function(e,t){const n=ko(e),r=Ga(n);if(r.diagnostics.length)return e;const o=r.spans.filter(e=>null===e.parentIndex&&!!e.separator&&!!e.end);if(o.length<2)return e;const{anchor:a}=e.selection,i=o.findIndex(e=>n[e.begin.paragraphIndex]?.id===a.paragraphId&&e.begin.offset<=a.offset&&(e.end?.offset??0)>=a.offset),s="next"===t?o[i<0?0:(i+1)%o.length]:o[i<0?o.length-1:(i-1+o.length)%o.length],l=n[s.begin.paragraphIndex];return{...e,selection:J(xi(l,s.begin.offset))}}(e.state(),t)),markAuthorityEntry:e=>o(t=>MT(t,e)),insertTableOfAuthorities:e=>o(t=>OT(t,e)),updateTableOfAuthorities:e=>o(t=>function(e,t){const n=ST(e,t);return"updated"===n.status?n.state:e}(t,e)),insertTableOfFigures:e=>o(t=>VT(t,e)),updateTableOfFigures:()=>o(e=>function(e){const t=HT(e);return"updated"===t.status?t.state:e}(e)),previewMergeRecord:(e,t)=>o(n=>function(e,t,n){if(!e||!Array.isArray(t)||!Number.isSafeInteger(n)||n<0||n>=t.length||t.length>1e3)return e;const r=cP(e.document,t[n]);return r?{...e,document:r.document}:e}(n,e,t)),mergeToNewDocuments:t=>pP(e.state(),t)?.length??0,updateVariableFields:()=>{let t=!1;return e.applyTransactionalState(e=>{const n=function(e,t={}){if("main"!==jr(e)||e.trackChangesEnabled)return{state:e,updated:0,variables:{}};let n={...t.variables},r=0;const o=/* @__PURE__ */new Map,a=Lo(e.document),i=[];for(const[l,c]of a.entries()){const t=[];for(const o of c.blocks){if("paragraph"!==o.type)return{state:e,updated:0,variables:n};t.push(o)}const r=Ga(t);if(r.diagnostics.length)return{state:e,updated:0,variables:n};for(const e of r.spans){const n=e.code.map(e=>"instruction"===e.kind?e.raw:"").join("");if(!yP(n)||null!==e.parentIndex||!e.separator||!e.end||e.code.some(e=>"instruction"!==e.kind)||e.beginMarker.fieldLock)continue;const r=t[e.begin.paragraphIndex];i.push({sectionIndex:l,paragraph:r,raw:n,runIds:e.result.flatMap(e=>"run"===e.kind?[e.point.runId]:[]),locked:!!e.beginMarker.fieldLock})}}for(const l of i){const e=xP(yP(l.raw),t,n,l.paragraph.runs.filter(e=>l.runIds.includes(e.id)).map(e=>e.text).join(""));if(n=e.variables,"preserved"===e.status)continue;let a=o.get(l.paragraph.id);a||(a={...l.paragraph,runs:l.paragraph.runs.map(e=>({...e}))},o.set(a.id,a));for(const t of l.runIds){const n=a.runs.find(e=>e.id===t);n&&(n.text=t===l.runIds[0]?e.text:"")}r++}const s=a.map(e=>({...e,blocks:e.blocks.map(e=>"paragraph"===e.type?o.get(e.id)??e:e)}));return{state:{...e,document:{...e.document,sections:s}},updated:r,variables:n}}(e,{prompt:(e,t)=>"undefined"==typeof window?void 0:window.prompt(e,t??"")??void 0});return t=n.updated>0,n.state}),t},setFormFieldValue:(e,t)=>o(n=>CP(n,e,t)),setContentControlValue:(e,t)=>o(n=>za(n,e,t)),mutateRepeatingSectionRow:(e,t,n)=>o(r=>wP(r,e,t,n)),toggleFormCheckbox:e=>o(t=>function(e,t){const n=IP(e,t);return n&&"checkBox"===n.control?CP(e,t,"x"===n.value?"":"x"):e}(t,e)),insertDate:()=>{e.applyTransactionalState(e=>function(e,t={}){const n=(t.dateFormat??"M/d/yyyy").trim(),r=t.value??/* @__PURE__ */new Date,o=ga(e.selection)?e:te(e),{paragraph:a,index:i,offset:s}=ae(o),l=gt(a,s),c=n.length>0&&"M/d/yyyy"!==n?{type:"DATE",dateFormat:n}:{type:"DATE"},d={id:`run:date:${Math.random().toString(36).slice(2,9)}`,text:Ik(r,n),kind:"field",field:c,styles:l},u=N(a,[...Ln(a,0,s),d,...Ln(a,s,oi(a))]),p=ko(o),f=[...Yo(p.slice(0,i)),u,...Yo(p.slice(i+1))],g=d.text.length;return Vt(o,f,J(xi(u,s+g)))}(e)),e.focusInput()},insertDateTime:t=>{e.applyTransactionalState(e=>function(e,t="M/d/yyyy",n=/* @__PURE__ */new Date){const r=Ik(n,t);return 0===r.length?e:Ju(e,r)}(e,t)),e.focusInput()},insertCrossReference:t=>{e.applyTransactionalState(e=>kP(e,t)),e.focusInput()}}}function PP(e){let t=!1,n=!1;const r=(t,n)=>{e.applyTransactionalState(t,{mergeKey:n}),e.focusInput()},o={firstRow:!1,lastRow:!1,firstCol:!1,lastCol:!1,noHBand:!1,noVBand:!1},a=e=>{const t=Ua(e),n=xo(e.document,e.selection.focus.paragraphId,t);if(!n)return null;const r=function(e,t,n){if("footnote"===n){const t=e.activeFootnoteId;return t?e.document.footnotes?.items[t]?.blocks??null:null}const r=Lo(e.document)[t];return r?"header"===n?r.header??[]:"footer"===n?r.footer??[]:r.blocks:null}(e,t,n.zone);if(!r)return null;const o=Zo(r,n.tablePath);return o?.[o.length-1]?.table??null},i=e=>{const t=a(e);if(!t)return null;const n=to(t,e.document.styles);return{...o,...n.tblLook??{}}};return{insideTable:()=>Boolean(xo(e.state().document,e.state().selection.focus.paragraphId,Ua(e.state()))),selectionLabel:()=>{const t=e.state();if(Ri(t).isCollapsed)return null;const n=Ua(t),r=xo(t.document,t.selection.anchor.paragraphId,n),o=xo(t.document,t.selection.focus.paragraphId,n),a=r?.tablePath[r.tablePath.length-1],i=o?.tablePath[o.tablePath.length-1];if(!r||!o||!a||!i||r.zone!==o.zone||!function(e,t){if(0===e.length||e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){const r=e[n],o=t[n];if(r.tableBlockIndex!==o.tableBlockIndex)return!1;if(n<e.length-1&&(r.rowIndex!==o.rowIndex||r.cellIndex!==o.cellIndex))return!1}return!0}(r.tablePath,o.tablePath)||a.rowIndex===i.rowIndex&&a.cellIndex===i.cellIndex)return null;const s=e.selectionBoxes().length;return 0===s?null:`Table selection: ${s} cell${1===s?"":"s"}`},getTblLook:()=>{const t=i(e.state());return t?{firstRow:t.firstRow,lastRow:t.lastRow,firstCol:t.firstCol,lastCol:t.lastCol,bandedRows:!t.noHBand,bandedCols:!t.noVBand}:null},toggleTblLook:e=>r(t=>{const n=i(t);if(!n)return t;const r={...n};switch(e){case"firstRow":r.firstRow=!n.firstRow;break;case"lastRow":r.lastRow=!n.lastRow;break;case"firstCol":r.firstCol=!n.firstCol;break;case"lastCol":r.lastCol=!n.lastCol;break;case"bandedRows":r.noHBand=!n.noHBand;break;case"bandedCols":r.noVBand=!n.noVBand}return Kg(t,"tblLook",r)},Jf),getStyleId:()=>a(e.state())?.style?.styleId??null,setStyleId:e=>r(t=>Kg(t,"styleId",e||null),Qf),getLayout:()=>a(e.state())?.style?.layout??null,toggleAutoFit:()=>r(e=>Kg(e,"layout","autofit"===a(e)?.style?.layout?"fixed":"autofit"),eg),canSetAutoFit:()=>null!==Rg(e.state()),setAutoFit:e=>r(t=>function(e,t){const n="fixed"===t?"fixed":"autofit";return $g(e,r=>{let o=r.style;e.trackChangesEnabled&&!o?.revision&&(o={...o??{},revision:{...Ig(),type:"property",previous:{...o??{}}}});let a=Sg(o,"layout",n);return"window"===t?a=Sg(a,"width","100%"):"contents"===t&&(a=Sg(a,"width",null)),{...r,style:a}})}(t,e),Xf),distributeColumns:()=>r(e=>$g(e,e=>{const t=Xa(e),n=Math.max(1,...t.map(e=>e.visualColumnIndex+Math.max(1,e.colSpan))),r=(e.gridCols??[]).reduce((e,t)=>e+("number"==typeof t&&t>0?t:0),0),o=r>0?r:120*n,a=o/n,i=Array.from({length:n},()=>a),s=e.rows.map((e,n)=>({...e,cells:e.cells.map((e,r)=>{const o=t.find(e=>e.rowIndex===n&&e.cellIndex===r);return o?{...e,style:{...e.style??{},width:a*Math.max(1,o.colSpan)}}:e})}));return{...e,gridCols:i,rows:s,style:{...e.style??{},width:o}}}),eg),distributeRows:()=>r(e=>$g(e,e=>{let t=0;for(const r of e.rows){const e=r.style?.height,n="number"==typeof e?e:"string"==typeof e?Number.parseFloat(e):0;Number.isFinite(n)&&n>t&&(t=n)}t<=0&&(t=24);const n=e.rows.map(e=>({...e,style:{...e.style??{},height:t,heightRule:"atLeast"}}));return{...e,rows:n}}),eg),canMerge:()=>e.tableOps.canMergeSelectedTable(e.state()),canSplit:()=>e.tableOps.canSplitSelectedTable(e.state()),canEditColumn:()=>e.tableOps.canEditSelectedTableColumn(e.state()),canEditRow:()=>e.tableOps.canEditSelectedTableRow(e.state()),canConvertToText:()=>null!==Rg(e.state()),convertToText:()=>r(e=>Jg(e),Hf),canConvertToTable:()=>{return!Rg(t=e.state())&&null!==Lg(t);var t},convertToTable:()=>r(e=>Qg(e),Wf),canSplitTableAtRow:()=>function(e){const t=Rg(e);if(!t)return!1;const n=Dg(e);if(!n)return!1;const r=Fg(n,t.loc.tablePath);if(!r)return!1;const o=t.loc.rowIndex;return o>0&&o<r.rows.length}(e.state()),splitTableAtRow:()=>r(e=>function(e){const t=Rg(e);if(!t)return e;const n=Dg(e);if(!n)return e;const r=Fg(n,t.loc.tablePath);if(!r)return e;const o=t.loc.rowIndex;if(o<=0||o>=r.rows.length)return e;const a=r.rows.slice(0,o),i=r.rows.slice(o),s={...r,rows:a},l=yo(i),c=zg(e,[s,Go(""),l]);if(c===e)return e;const d=l.rows[0]?.cells[0]?.blocks.find(e=>"paragraph"===e.type);return d?{...c,selection:J(xi(d,0))}:e}(e),jf),canSortTable:()=>function(e){const t=Rg(e);if(!t)return!1;const n=Dg(e);if(!n)return!1;const r=Fg(n,t.loc.tablePath);return!!r&&function(e){let t=0;for(const n of e)n.isHeader||(t+=1);return t}(r.rows)>=2}(e.state()),sortTable:e=>r(t=>tm(t,e),"ascending"===e?Uf:Vf),canDeleteTable:()=>null!==Rg(e.state()),deleteTable:()=>r(e=>function(e){const t=Rg(e);if(!t)return e;const n=Dg(e);if(!n)return e;const r=t.loc.tablePath[0]?.tableBlockIndex;if(void 0===r||"table"!==n[r]?.type)return e;if(1===n.length){const t=Go(""),n=zg(e,[t]);return n===e?e:{...n,selection:J(xi(t,0))}}const o=function(e,t){for(let n=t+1;n<e.length;n+=1){const t=e[n];if("paragraph"===t?.type)return t.id}for(let n=t-1;n>=0;n-=1){const t=e[n];if("paragraph"===t?.type)return t.id}return null}(n,r),a=zg(e,[]);if(a===e)return e;if(o){const e=ko(a).find(e=>e.id===o);if(e)return{...a,selection:J(xi(e,0))}}return a}(e),Kf),canToggleRepeatHeaderRows:()=>function(e){const t=Rg(e);if(!t)return!1;const n=Dg(e);if(!n)return!1;const r=Fg(n,t.loc.tablePath);return null!==r&&r.rows.length>0}(e.state()),isRepeatHeaderRowsActive:()=>function(e){const t=Rg(e);if(!t)return!1;const n=Dg(e);if(!n)return!1;const r=Fg(n,t.loc.tablePath);return!(!r||0===r.rows.length)&&rm(r.rows[0])}(e.state()),toggleRepeatHeaderRows:()=>r(e=>function(e){const t=Rg(e);if(!t)return e;const n=Dg(e);if(!n)return e;const r=Fg(n,t.loc.tablePath);if(!r||0===r.rows.length)return e;const o=rm(r.rows[0]);return $g(e,e=>({...e,rows:e.rows.map((e,t)=>0!==t?e:o?{...e,isHeader:void 0}:{...e,isHeader:!0})}))}(e),qf),merge:()=>r(t=>e.tableOps.mergeSelectedTable(t),kf),split:()=>r(t=>e.tableOps.splitSelectedTable(t),Tf),insertColumnBefore:()=>r(t=>e.tableOps.insertSelectedTableColumn(t,-1),Pf),insertColumnAfter:()=>r(t=>e.tableOps.insertSelectedTableColumn(t,1),Pf),deleteColumn:()=>r(t=>e.tableOps.deleteSelectedTableColumn(t),Rf),insertRowBefore:()=>r(t=>e.tableOps.insertSelectedTableRow(t,-1),Af),insertRowAfter:()=>r(t=>e.tableOps.insertSelectedTableRow(t,1),Af),deleteRow:()=>r(t=>e.tableOps.deleteSelectedTableRow(t),Mf),canDeleteCell:()=>bm(e.state()),deleteCell:()=>r(e=>ym(e),_f),cellShading:e=>r(t=>Ug(t,"shading",e||null),Of),cellBorders:()=>r(e=>Vg(e,{width:1,type:"solid",color:"#64748b"}),Bf),cellNoBorders:()=>r(e=>Vg(e,{width:0,type:"none",color:"transparent"}),Bf),applyBorderPreset:e=>r(t=>function(e,t,n=Hg){const r=jg(e);if(!r)return e;const o=/* @__PURE__ */new Map,a=new Set(r.selectedEntries.map(e=>e.cell.id)),i=/* @__PURE__ */new Map;for(const m of r.entries)for(let e=m.visualRowIndex;e<m.visualRowIndex+m.rowSpan;e+=1)for(let t=m.visualColumnIndex;t<m.visualColumnIndex+m.colSpan;t+=1)i.set(`${e}:${t}`,m);const s=(e,t,r=n)=>{if(!e)return;const a=o.get(e.cell.id)??{};a[t]=r,o.set(e.cell.id,a)},l=(e,t,r,o,a=n)=>{s(e,t,a),r&&r.cell.id!==e?.cell.id&&s(r,o,a)},c=(e,t=n)=>{if("top"===e||"bottom"===e){const n="top"===e?r.startRow:r.endRow,o=n+("top"===e?-1:1);for(let s=r.startCol;s<=r.endCol;s+=1){const r=i.get(`${n}:${s}`);r&&a.has(r.cell.id)&&l(r,"top"===e?"borderTop":"borderBottom",i.get(`${o}:${s}`),"top"===e?"borderBottom":"borderTop",t)}return}const o="left"===e?r.startCol:r.endCol,s=o+("left"===e?-1:1);for(let n=r.startRow;n<=r.endRow;n+=1){const r=i.get(`${n}:${o}`);r&&a.has(r.cell.id)&&l(r,"left"===e?"borderLeft":"borderRight",i.get(`${n}:${s}`),"left"===e?"borderRight":"borderLeft",t)}},d=()=>{for(let e=r.startRow+1;e<=r.endRow;e+=1)for(let t=r.startCol;t<=r.endCol;t+=1){const n=i.get(`${e-1}:${t}`),r=i.get(`${e}:${t}`);n&&r&&n.cell.id!==r.cell.id&&a.has(n.cell.id)&&a.has(r.cell.id)&&l(n,"borderBottom",r,"borderTop")}},u=()=>{for(let e=r.startCol+1;e<=r.endCol;e+=1)for(let t=r.startRow;t<=r.endRow;t+=1){const n=i.get(`${t}:${e-1}`),r=i.get(`${t}:${e}`);n&&r&&n.cell.id!==r.cell.id&&a.has(n.cell.id)&&a.has(r.cell.id)&&l(n,"borderRight",r,"borderLeft")}};switch(t){case"none":for(const e of r.selectedEntries)for(const t of["borderTop","borderRight","borderBottom","borderLeft","borderStart","borderEnd","borderTopLeftToBottomRight","borderTopRightToBottomLeft"])s(e,t,Wg);c("top",Wg),c("right",Wg),c("bottom",Wg),c("left",Wg);break;case"top":c("top");break;case"right":c("right");break;case"bottom":c("bottom");break;case"left":c("left");break;case"outside":c("top"),c("right"),c("bottom"),c("left");break;case"insideHorizontal":d();break;case"insideVertical":u();break;case"inside":d(),u();break;case"all":c("top"),c("right"),c("bottom"),c("left"),d(),u();break;case"diagonalDown":for(const e of r.selectedEntries)s(e,"borderTopLeftToBottomRight");break;case"diagonalUp":for(const e of r.selectedEntries)s(e,"borderTopRightToBottomLeft")}if(0===o.size)return e;const p=/* @__PURE__ */new Set;for(const m of r.entries)if(o.has(m.cell.id))for(const e of m.cell.blocks)for(const t of ra(e))p.add(t.id);const f=t=>{const n=o.get(t.id);if(!n)return t;let r=t.style;e.trackChangesEnabled&&!r?.propertyRevision&&(r={...r??{},propertyRevision:{...Ig(),type:"property",previous:{...r??{}}}});for(const[e,o]of Object.entries(n))r=Sg(r,e,o);return{...t,style:r}},g=Lo(e.document).map(e=>({...e,blocks:br(e.blocks,p,f),header:e.header?br(e.header,p,f):void 0,footer:e.footer?br(e.footer,p,f):void 0}));return{...e,document:{...e.document,sections:g}}}(t,e),Bf),isDrawingBorders:()=>t,toggleDrawingBorders:()=>{t=!t,e.applyState({...e.state()})},isShowingGridlines:()=>n,toggleGridlines:()=>{n=!n,e.applyState({...e.state()})},width100:()=>r(e=>Kg(e,"width","100%"),Ff),alignLeft:()=>r(e=>Ug(e,"horizontalAlign","left"),Ef),alignCenter:()=>r(e=>Ug(e,"horizontalAlign","center"),Ef),alignRight:()=>r(e=>Ug(e,"horizontalAlign","right"),Ef),setCellAlignment:e=>r(t=>{return n=t,r=e.horizontal,o=e.vertical,Ug(Ug(n,"horizontalAlign",r),"verticalAlign",o);var n,r,o},Df),getCellAlignmentState:()=>function(e){const t=jg(e);if(!t||0===t.selectedEntries.length)return null;const n=t.selectedEntries.map(({cell:e})=>e.style?.horizontalAlign??"left"),r=t.selectedEntries.map(({cell:e})=>e.style?.verticalAlign??"top"),o=(e,t)=>{const n=e[0];return n?e.some(e=>!t.includes(e))?null:e.some(e=>e!==n)?"mixed":n:null};return{horizontal:o(n,["left","center","right"]),vertical:o(r,["top","middle","bottom"])}}(e.state()),setCellVerticalAlign:e=>r(t=>Ug(t,"verticalAlign",e),Lf),setCellTextDirection:e=>r(t=>Ug(t,"textDirection",e),Nf),setCellWidth:e=>r(t=>function(e,t){return Ug(e,"width",t)}(t,e),zf),setCellNoWrap:e=>r(t=>function(e,t){return Ug(e,"noWrap",t)}(t,e),zf),setCellFitText:e=>r(t=>function(e,t){return Ug(e,"fitText",t)}(t,e),zf),canSetCellMargins:()=>null!==Rg(e.state()),setCellMargins:e=>r(t=>function(e,t){let n=e;return void 0!==t.top&&(n=Ug(n,"paddingTop",t.top)),void 0!==t.right&&(n=Ug(n,"paddingRight",t.right)),void 0!==t.bottom&&(n=Ug(n,"paddingBottom",t.bottom)),void 0!==t.left&&(n=Ug(n,"paddingLeft",t.left)),n}(t,e),Gf),canSetCellSpacing:()=>om(e.state()),setCellSpacing:e=>r(t=>function(e,t){return om(e)?Kg(e,"cellSpacing",null===t||t<0?null===t?null:0:Math.round(2*t)/2):e}(t,e),Gf),canSetTableIndent:()=>am(e.state()),setTableIndent:e=>r(t=>function(e,t){return am(e)?null===t||t<0||Number.isNaN(t)||!Number.isFinite(t)?Kg(e,"indentLeft",null):Kg(e,"indentLeft",Math.round(2*t)/2):e}(t,e),Gf),canSetTableAlignment:()=>null!==Rg(e.state()),setTableAlignment:e=>r(t=>sm(t,e),Gf),canEvaluateTableFormula:()=>null!==Rg(e.state()),evaluateTableFormula:e=>r(t=>dm(t,e),Yf),canSelectTable:()=>null!==Rg(e.state()),selectTablePart:t=>e.applyState(mm(e.state(),t)),canSetActiveTableRowHeight:()=>null!==Rg(e.state()),setActiveTableRowHeight:e=>r(t=>function(e,t){let n=e;return n=Xg(n,"height",t.height),void 0!==t.heightRule&&(n=Xg(n,"heightRule",t.heightRule)),n}(t,e),Zf),canSetActiveTableRowBreakAcrossPages:()=>lm(e.state()),setActiveTableRowBreakAcrossPages:e=>r(t=>function(e,t){return lm(e)?Xg(e,"cantSplit",null===t?null:!t):e}(t,e),Zf),canSetActiveTableRowHeader:()=>null!==Rg(e.state()),setActiveTableRowHeader:e=>r(t=>qg(t,e),qf),canSetActiveTableColumnWidth:()=>null!==Rg(e.state()),setActiveTableColumnWidth:e=>r(t=>function(e,t){const n=Rg(e);if(!n)return e;const{activeSectionIndex:r,loc:o}=n,a=Fg(Tg(e.document,r,o.zone),o.tablePath);if(!a)return e;const i=Xa(a).find(e=>e.rowIndex===o.rowIndex&&e.cellIndex===o.cellIndex);if(!i)return e;const s=i.visualColumnIndex;return null===t?e:Zg(e,a.id,{[s]:t})}(t,e),$f),canSetActiveTableWidth:()=>null!==Rg(e.state()),setActiveTableWidth:e=>r(t=>function(e,t){const n=Rg(e);if(!n)return e;const{activeSectionIndex:r,loc:o}=n,a=Fg(Tg(e.document,r,o.zone),o.tablePath);return a?_g(e,a.id,"width",t):e}(t,e),Ff),insert:(t,n)=>e.tableOps.insertTableCommand(t,n)}}function RP(e){const t=t=>e.applyTransactionalState(t);return{applyTheme:e=>t(t=>VS(t,e)),setColorScheme:e=>t(t=>function(e,t){const n=WS[t]??WS.oasis,r=Object.fromEntries(Object.entries(e.document.styles??{}).map(([e,t])=>{if(!/^(normal|title|subtitle|heading[1-9]|quote|intensequote)$/i.test(e))return[e,t];const r=/^heading[1-9]$/i.test(e)||/title|quote/i.test(e);return[e,{...t,textStyle:{...t.textStyle??{},color:r?n.heading:n.color}}]}));return{...e,document:{...e.document,styles:r,design:{...e.document.design??{},colorSchemeId:t,themeData:{...e.document.design?.themeData??{},sourceXml:void 0,colors:{...e.document.design?.themeData?.colors??{},accent1:n.color,accent2:n.heading}}}}}}(t,e)),setFontScheme:e=>t(t=>function(e,t){const[n,r]=jS[t]??jS.aptos,o=Object.fromEntries(Object.entries(e.document.styles??{}).map(([e,t])=>/^(normal|title|subtitle|heading[1-9]|quote|intensequote)$/i.test(e)?[e,{...t,textStyle:{...t.textStyle??{},fontFamily:/^heading|title|quote/i.test(e)?r:n}}]:[e,t]));return{...e,document:{...e.document,design:{...e.document.design??{},fontSchemeId:t,themeData:{...e.document.design?.themeData??{},sourceXml:void 0,fonts:{...e.document.design?.themeData?.fonts??{},major:{...e.document.design?.themeData?.fonts?.major??{},majorHAnsi:r.split(",")[0].trim()},minor:{...e.document.design?.themeData?.fonts?.minor??{},minorHAnsi:n.split(",")[0].trim()}}}},styles:o}}}(t,e)),setParagraphSpacing:e=>t(t=>function(e,t){const n={compact:[0,4],tight:[0,6],open:[0,10],relaxed:[4,12]},[r,o]=n[t]??n.open,a=Object.fromEntries(Object.entries(e.document.styles??{}).map(([e,t])=>/^(normal|title|subtitle|heading[1-9]|quote|intensequote)$/i.test(e)?[e,{...t,paragraphStyle:{...t.paragraphStyle??{},spacingBefore:r,spacingAfter:o}}]:[e,t]));return{...e,document:{...e.document,design:{...e.document.design??{},paragraphSpacingId:t},styles:a}}}(t,e)),setEffects:e=>t(t=>US(t,{effectsId:e,themeData:{...t.document.design?.themeData??{},sourceXml:void 0,effectsXml:void 0}})),setPageColor:e=>t(t=>function(e,t){return US(e,{pageColor:t})}(t,e)),setWatermark:e=>t(t=>function(e,t){return US(e,{watermark:t})}(t,e)),setPageBorder:e=>t(t=>function(e,t){const n=(e.document.sections??[]).map(e=>({...e,pageBorder:t}));return{...e,document:{...e.document,sections:n,design:{...e.document.design??{}}}}}(t,e)),setDefault:()=>{const t=e.state().document.design;t&&globalThis.localStorage?.setItem("oasis-design-default",JSON.stringify(t))},getDesign:()=>e.state().document.design,getPageBorder:()=>e.state().document.sections?.find(e=>e.pageBorder)?.pageBorder}}function AP(e){return function(e){const t=(n=e.gate.isCommandEnabled,(e,t,r)=>({execute:t,refresh:()=>{const t=r?.()??{};return{...t,isEnabled:n(e)&&(t.isEnabled??!0)}}}));var n;const r=function(e){return(t,n,r)=>({execute:n,refresh:()=>({isEnabled:e(t),value:r()})})}(e.gate.isCommandEnabled),o=function(e){return(t,n,r)=>({execute:e=>(n(e),!0),refresh:()=>{const n=r?.()??{};return{...n,isEnabled:e(t)&&(n.isEnabled??!0)}}})}(e.gate.isCommandEnabled);return{name:"Essentials",commands:{...qS({gate:e.gate,style:e.style,selection:e.selection,history:e.history,formatting:e.formatting,dialog:e.dialog,link:e.link,command:t,valueCommand:r,actionCommand:o}),...GS({gate:e.gate,style:e.style,document:e.document,link:e.link,image:e.image,browser:e.browser,actionCommand:o}),...YS({style:e.style,paragraph:e.paragraph,section:e.section,valueCommand:r,actionCommand:o}),...nC({dialog:e.dialog,actionCommand:o}),...ZS({gate:e.gate,headerFooter:e.headerFooter,command:t,actionCommand:o}),...eC({gate:e.gate,table:e.table,actionCommand:o,valueCommand:r}),...tC({design:e.design,actionCommand:o}),...JS({bookmark:e.bookmark,actionCommand:o}),...QS({fields:e.fields,actionCommand:o})}}}({gate:iC(e),style:sC(e),selection:lC(e),history:cC(e),formatting:PC(e),document:NC(e),link:zC(e),image:$C(e),browser:HC(e),paragraph:tk(e),section:hk(e),headerFooter:bk(e),table:PP(e),design:RP(e),bookmark:vk(e),fields:TP(e),dialog:{openFontDialog:e.openFontDialog,openParagraphDialog:e.openParagraphDialog,requestAcceptAllRevisions:e.requestAcceptAllRevisions,requestRejectAllRevisions:e.requestRejectAllRevisions}})}var MP=[{id:"file_new",path:"File/New",labelKey:"menu.file.new",shortcut:"Ctrl+N",command:"newDocument",icon:"file-plus"},{id:"file_import",path:"File/Import",labelKey:"toolbar.importDocx",shortcut:"Ctrl+O",command:"importDocument",icon:"upload"},{id:"file_save",path:"File/Save",labelKey:"generic.save",shortcut:"Ctrl+S",command:"saveDocument",icon:"save"},{id:"file_export",path:"File/Export",labelKey:"menu.file.export",icon:"download"},{id:"file_export_pdf",path:"File/Export/PDF",command:"exportPdf",icon:"file-down"},{id:"file_export_docx",path:"File/Export/DOCX",command:"exportDocx",icon:"file-text"},{id:"file_export_html",path:"File/Export/HTML",hidden:!0},{id:"file_export_md",path:"File/Export/MD",hidden:!0},{id:"file_print",path:"File/Print",labelKey:"menu.file.print",shortcut:"Ctrl+P",command:"print",icon:"printer"},{id:"edit_undo",path:"Edit/Undo",labelKey:"toolbar.undo",shortcut:"Ctrl+Z",command:"undo",icon:"undo-2"},{id:"edit_redo",path:"Edit/Redo",labelKey:"toolbar.redo",shortcut:"Ctrl+Y",command:"redo",icon:"redo-2"},{id:"edit_repeat",path:"Edit/Repeat",labelKey:"quickAccess.repeat",shortcut:"F4",command:"repeatLastAction",icon:"repeat"},{id:"edit_cut",path:"Edit/Cut",labelKey:"menu.edit.cut",shortcut:"Ctrl+X",command:"cut",icon:"scissors"},{id:"edit_copy",path:"Edit/Copy",labelKey:"menu.edit.copy",shortcut:"Ctrl+C",command:"copy",icon:"copy"},{id:"edit_paste",path:"Edit/Paste",labelKey:"menu.edit.paste",shortcut:"Ctrl+V",command:"paste",icon:"clipboard-paste"},{id:"edit_paste_merge",path:"Edit/Paste Merge Formatting",labelKey:"toolbar.pasteMergeFormatting",command:"pasteMergeFormatting",icon:"paintbrush"},{id:"edit_paste_plain",path:"Edit/Paste as Plain Text",labelKey:"toolbar.pastePlainText",command:"pasteAsPlainText",icon:"clipboard"},{id:"edit_format_painter",path:"Edit/Format Painter",labelKey:"toolbar.formatPainter",command:"formatPainter",icon:"paintbrush"},{id:"edit_format_painter_continuous",path:"Edit/Format Painter Continuous",labelKey:"toolbar.formatPainterContinuous",command:"formatPainterContinuous",icon:"paintbrush"},{id:"edit_cancel_format_painter",path:"Edit/Cancel Format Painter",labelKey:"toolbar.formatPainterCancel",command:"cancelFormatPainter",icon:"x"},{id:"edit_find",path:"Edit/Find & Replace",labelKey:"find.title",shortcut:"Ctrl+F",command:"find",icon:"search"},{id:"edit_selectAll",path:"Edit/Select All",labelKey:"menu.edit.selectAll",shortcut:"Ctrl+A",hidden:!0},{id:"review_previous_revision",path:"Review/Previous Change",labelKey:"toolbar.previousRevision",command:"previousRevision",icon:"chevron-up"},{id:"review_next_revision",path:"Review/Next Change",labelKey:"toolbar.nextRevision",command:"nextRevision",icon:"chevron-down"},{id:"review_revision_markup",path:"Review/Show Markup",labelKey:"toolbar.revisionMarkup",command:"toggleRevisionMarkup",icon:"highlighter"},{id:"review_accept_all_revisions",path:"Review/Accept All Changes",labelKey:"toolbar.acceptAll",command:"requestAcceptAllRevisions",icon:"check-check"},{id:"review_reject_all_revisions",path:"Review/Reject All Changes",labelKey:"toolbar.rejectAll",command:"requestRejectAllRevisions",icon:"undo-2"},{id:"review_comments_panel",path:"Review/Comments Panel",labelKey:"review.commentsPanel",command:"toggleCommentsPanel",icon:"list-filter"},{id:"review_revisions_panel",path:"Review/Reviewing Pane",labelKey:"review.reviewingPane",command:"toggleRevisionsPanel",icon:"list-checks"},{id:"review_new_comment",path:"Review/New Comment",labelKey:"toolbar.newComment",command:"newComment",icon:"message-square-plus"},{id:"review_reply_comment",path:"Review/Reply to Comment",labelKey:"toolbar.replyComment",command:"replyComment",icon:"reply"},{id:"review_edit_comment",path:"Review/Edit Comment",labelKey:"toolbar.editComment",command:"editComment",icon:"pencil"},{id:"review_previous_comment",path:"Review/Previous Comment",labelKey:"toolbar.previousComment",command:"previousComment",icon:"message-square"},{id:"review_next_comment",path:"Review/Next Comment",labelKey:"toolbar.nextComment",command:"nextComment",icon:"messages-square"},{id:"review_resolve_comment",path:"Review/Resolve Comment",labelKey:"toolbar.resolveComment",command:"resolveComment",icon:"message-square-check"},{id:"review_reopen_comment",path:"Review/Reopen Comment",labelKey:"toolbar.reopenComment",command:"reopenComment",icon:"message-square-more"},{id:"review_delete_comment",path:"Review/Delete Comment",labelKey:"toolbar.deleteComment",command:"deleteComment",icon:"message-square-x"},{id:"view_outline",path:"View/Show Outline",labelKey:"menu.view.outline",command:"toggleOutlinePanel",icon:"list"},{id:"view_ruler",path:"View/Show Ruler",hidden:!0},{id:"view_margins",path:"View/Show Margins",labelKey:"menu.view.margins",command:"toggleShowMargins",icon:e=>e.commands.state("toggleShowMargins").isActive?"check-square":"square"},{id:"view_paragraph_marks",path:"View/Show Paragraph Marks",labelKey:"menu.view.paragraphMarks",command:"toggleShowParagraphMarks",icon:e=>e.commands.state("toggleShowParagraphMarks").isActive?"check-square":"square"},{id:"view_precise_fonts",path:"View/Precise Fonts",labelKey:"menu.view.preciseFonts",command:"togglePreciseFonts",icon:e=>e.commands.state("togglePreciseFonts").isActive?"check-square":"square"},{id:"view_fullscreen",path:"View/Full Screen",labelKey:"menu.view.fullscreen",hidden:!0},{id:"view_zoom",path:"View/Zoom",labelKey:"status.zoom",hidden:!0},{id:"view_zoom_50",path:"View/Zoom/50%",hidden:!0},{id:"view_zoom_75",path:"View/Zoom/75%",hidden:!0},{id:"view_zoom_100",path:"View/Zoom/100%",hidden:!0},{id:"view_zoom_125",path:"View/Zoom/125%",hidden:!0},{id:"view_zoom_150",path:"View/Zoom/150%",hidden:!0},{id:"view_zoom_200",path:"View/Zoom/200%",hidden:!0},{id:"insert_image",path:"Insert/Image",labelKey:"toolbar.image",command:"insertImage",icon:"image"},{id:"insert_image_caption",path:"Insert/Image Caption",labelKey:"toolbar.imageCaption",command:"insertImageCaption",icon:"subtitles"},{id:"insert_table",path:"Insert/Table",labelKey:"toolbar.table",command:{name:"insertTable",payload:{rows:3,cols:3}},icon:"table"},{id:"insert_link",path:"Insert/Link",labelKey:"toolbar.link",command:"link",icon:"link"},{id:"insert_footnote",path:"Insert/Footnote",labelKey:"toolbar.footnote",shortcut:"Ctrl+Alt+F",command:"insertFootnote",icon:"footnote"},{id:"insert_toc",path:"Insert/Table of Contents",labelKey:"menu.insert.toc",command:"insertTableOfContents",icon:"tableOfContents"},{id:"insert_toc_update",path:"Insert/Update Table of Contents",labelKey:"menu.insert.updateToc",command:"updateTableOfContents",icon:"updateTableOfContents"},{id:"insert_hr",path:"Insert/Horizontal Rule",hidden:!0},{id:"insert_pageBreak",path:"Insert/Page Break",labelKey:"metric.pageBreak",command:"pageBreak",icon:"file-minus"},{id:"insert_header",path:"Insert/Header",labelKey:"headerFooter.header",command:"editHeader",icon:"panel-top"},{id:"insert_footer",path:"Insert/Footer",labelKey:"headerFooter.footer",command:"editFooter",icon:"panel-bottom"},{id:"insert_page_number",path:"Insert/Page Number",labelKey:"headerFooter.pageNumber",icon:"hash"},{id:"insert_page_number_current",path:"Insert/Page Number/Current Position",labelKey:"headerFooter.pageNumberCurrent",command:"insertPageNumber"},{id:"insert_page_number_xofy",path:"Insert/Page Number/Page X of Y",labelKey:"headerFooter.pageNumberXOfY",command:"insertPageNumberXOfY"},{id:"insert_page_number_top",path:"Insert/Page Number/Top of Page",labelKey:"headerFooter.pageNumberTop",command:"placePageNumberTop"},{id:"insert_page_number_bottom",path:"Insert/Page Number/Bottom of Page",labelKey:"headerFooter.pageNumberBottom",command:"placePageNumberBottom"},{id:"insert_bookmark",path:"Insert/Bookmark",labelKey:"toolbar.bookmark",command:"insertBookmark",icon:"bookmark"},{id:"insert_date",path:"Insert/Date",labelKey:"toolbar.date",command:"insertDateField",icon:"calendar"},{id:"insert_specialChar",path:"Insert/Special Character",hidden:!0},{id:"insert_comment",path:"Insert/Comment",hidden:!0},{id:"format_text",path:"Format/Text",labelKey:"menu.format.text",icon:"type"},{id:"format_text_bold",path:"Format/Text/Bold",labelKey:"toolbar.bold",shortcut:"Ctrl+B",command:"bold",icon:"bold"},{id:"format_text_italic",path:"Format/Text/Italic",labelKey:"toolbar.italic",shortcut:"Ctrl+I",command:"italic",icon:"italic"},{id:"format_text_underline",path:"Format/Text/Underline",labelKey:"toolbar.underline",shortcut:"Ctrl+U",command:"underline",icon:"underline"},{id:"format_text_strike",path:"Format/Text/Strikethrough",labelKey:"toolbar.strike",command:"strike",icon:"strikethrough"},{id:"format_paragraphStyles",path:"Format/Paragraph styles",labelKey:"toolbar.style",hidden:!0},{id:"format_align",path:"Format/Align",labelKey:"menu.format.align",icon:"align-left"},{id:"format_align_left",path:"Format/Align/Left",labelKey:"toolbar.alignLeft",command:"alignLeft",icon:"align-left"},{id:"format_align_center",path:"Format/Align/Center",labelKey:"toolbar.alignCenter",command:"alignCenter",icon:"align-center"},{id:"format_align_right",path:"Format/Align/Right",labelKey:"toolbar.alignRight",command:"alignRight",icon:"align-right"},{id:"format_align_justify",path:"Format/Align/Justify",labelKey:"toolbar.justify",command:"alignJustify",icon:"align-justify"},{id:"format_lineSpacing",path:"Format/Line spacing",hidden:!0},{id:"format_lists",path:"Format/Lists",labelKey:"menu.format.lists",icon:"list"},{id:"format_lists_bullet",path:"Format/Lists/Bullet List",labelKey:"toolbar.bulletList",command:"bulletList",icon:"list"},{id:"format_lists_numbered",path:"Format/Lists/Numbered List",labelKey:"toolbar.numberedList",command:"orderedList",icon:"list-ordered"},{id:"format_clear",path:"Format/Clear formatting",hidden:!0},{id:"layout_orientation",path:"Layout/Orientation",labelKey:"section.orientation",icon:"layout"},{id:"layout_orientation_portrait",path:"Layout/Orientation/Portrait",labelKey:"section.portrait",command:{name:"setOrientation",payload:"portrait"},icon:e=>e.commands.state("toggleOrientation").isActive?"":"check"},{id:"layout_orientation_landscape",path:"Layout/Orientation/Landscape",labelKey:"section.landscape",command:{name:"setOrientation",payload:"landscape"},icon:e=>e.commands.state("toggleOrientation").isActive?"check":""},{id:"tools_update_selected_fields",path:"Tools/Update Selected Fields",labelKey:"menu.tools.updateSelectedFields",command:"updateSelectedFields",icon:"refresh-cw",shortcut:"F9"},{id:"tools_update_body_fields",path:"Tools/Update All Body Fields",labelKey:"menu.tools.updateBodyFields",command:"updateBodyFields",icon:"refresh-cw"},{id:"tools_wordcount",path:"Tools/Word count",labelKey:"menu.tools.wordcount",hidden:!0},{id:"tools_command_search",path:"Tools/Command Search",labelKey:"menu.tools.commandSearch",command:"openCommandSearch",icon:"search",shortcut:"Ctrl+K"},{id:"tools_spelling",hidden:!0,path:"Tools/Spelling"},{id:"tools_preferences",path:"Tools/Preferences",hidden:!0},{id:"help_shortcuts",path:"Help/Keyboard shortcuts",labelKey:"menu.help.shortcuts",hidden:!0},{id:"help_about",path:"Help/About",labelKey:"menu.help.about",hidden:!0}];function OP(e){const t=AP(e.essentials),{runtimePlugins:n,toolbarRegistry:r,menuRegistry:o,dispose:a}=function(e){const t=[e.essentialsPlugin,...e.externalPlugins??[]],n=[],r=[],o=Wt(),a=new Mt;for(const i of ar(e.t))o.register(i);for(const i of MP)a.register(i);for(const i of t){for(const e of i.toolbar??[]){const t={type:"button",id:e.id,testId:e.id,command:e.command,iconName:e.icon,tab:e.tab??"plugins",group:e.group??"general",groupLabel:e.groupLabel,row:e.row??1,ribbonSize:e.ribbonSize,ribbonGroupResize:e.ribbonGroupResize,ribbonGroupLayout:e.ribbonGroupLayout,ribbonGroupGrid:e.ribbonGroupGrid,order:e.order};o.register(t),n.push(e.id)}for(const e of i.menubar??[])a.register({id:e.id,path:e.path,command:e.command,icon:e.icon,shortcut:e.shortcut}),r.push(e.id)}return e.customizeToolbar?.(o),e.customizeMenubar?.(a),{runtimePlugins:t,toolbarRegistry:o,menuRegistry:a,dispose:()=>{for(const e of n)o.remove(e);for(const e of r)a.unregister(e)}}}({essentialsPlugin:t,externalPlugins:e.externalPlugins,t:e.t,customizeToolbar:e.customizeToolbar,customizeMenubar:e.customizeMenubar}),i=function(e){const[t,n]=Nt(!1),[r,o]=Nt(new hn({doc:e.initialDocument}));let a=!1;const i=e=>{const t=p(e),n=r().commands.get(t);if(!n)return{isEnabled:!1,isActive:!1,value:void 0};const o=n.refresh?.()??{isEnabled:!0};return{isEnabled:!1!==o.isEnabled,isActive:Boolean(o.isActive),value:o.value}};return{runtimeReady:t,runtimeEditor:r,commandStateOf:i,toolbarHost:()=>({commands:{execute:(e,t)=>{const n=Ne(e,t);return r().commands.execute(n.name,n.payload)},canExecute:(e,t)=>{const n=Ne(e,t);return r().commands.canExecute(n.name,n.payload)},state:i},focusEditor:e.focusEditor}),initialize:async()=>{try{const t=await hn.create({doc:e.initialDocument,plugins:e.runtimePlugins});if(e.onExecuted&&(t.commands.onExecuted=e.onExecuted),a)return void(await t.destroy());const i=r();o(t),await i.destroy(),n(!0),requestAnimationFrame(()=>{e.onSettled?.(),e.onReady?.(t)})}catch(t){e.logger.error("runtime:init failed",t),e.onError?.(t),e.onSettled?.()}},dispose:async()=>{a=!0,await r().destroy()}}}({initialDocument:e.initialDocument,runtimePlugins:n,focusEditor:e.focusEditor,logger:e.logger,onExecuted:e.onExecuted,onReady:e.onReady,onSettled:e.onSettled,onError:e.onError});return ot(()=>{i.initialize()}),Ut(()=>{i.dispose(),a()}),{toolbarRegistry:r,menuRegistry:o,runtimeReady:i.runtimeReady,runtimeEditor:i.runtimeEditor,commandStateOf:i.commandStateOf,toolbarHost:i.toolbarHost}}var BP=/* @__PURE__ */new Set(["undo","redo","repeatLastAction","find","replace","replaceAll","print","newDocument","saveDocument","insertHtml","insertImageFromFile","openSymbolDialog","openEquationDialog","openCommandSearch","importDocument","exportDocx","exportPdf"]);function FP(e,t){let n=null;return{lastCommand:()=>n?.command??null,record:(e,t)=>{(function(e){return!BP.has(e)})(e)&&(n={command:e,payload:t})},canExecute:()=>null!==n&&function(e){try{return e()}catch{return!1}}(()=>t(n.command,n.payload)),execute:()=>{n&&e(n.command,n.payload)}}}function EP(e){return function(e){const{document:t,interaction:n,runtimeClient:r}=e,{commandsController:o,keyboardCommandsController:a}=AS({state:e.state,logger:e.logger,applyState:e.applyState,applyTransactionalState:t.applyTransactionalState,clearPreferredColumn:t.clearPreferredColumn,resetTransactionGrouping:t.resetTransactionGrouping,focusInput:e.focusInput,selectedImageRun:n.selectedImageRun,tableOps:n.tableOps,toolbarStyleState:n.styleController.toolbarStyleState,applyBooleanStyleCommand:e=>n.styleController.applyToolbarBooleanStyleCommand(e),locale:e.locale,setLinkDialog:e.setLinkDialog,setImageAltDialog:e.setImageAltDialog,setImageCaptionDialog:e.setImageCaptionDialog,setFontDialog:e.setFontDialog,setParagraphDialog:e.setParagraphDialog});let i;const s=FP((e,t)=>{if(!i)throw new Error("repeat tracking used before ready");return i().commands.execute(e,t)},(e,t)=>!!i&&i().commands.canExecute(e,t)),l=()=>{s.execute()},c=()=>s.canExecute(),{runtimeReady:d,runtimeEditor:u,commandStateOf:p,toolbarHost:f,toolbarRegistry:g,menuRegistry:m}=OP({essentials:{clipboardActions:e.clipboardActions,state:()=>e.state,isReadOnly:e.isReadOnly,forcePlainTextPaste:{get:e.getForcePlainTextPaste,set:e.setForcePlainTextPaste},undoStack:t.undoStack,redoStack:t.redoStack,commandsController:o,keyboardCommandsController:a,historyActions:t.historyActions,styleController:n.styleController,formatPainter:n.formatPainter,commentComposer:e.commentComposer,tableOps:n.tableOps,docIO:t.docIO,importInputRef:e.importInputRef,imageInputRef:e.imageInputRef,selectedImageRun:n.selectedImageRun,imageCropMode:{isActive:n.imageOps.cropMode,toggle:n.imageOps.toggleCropMode},selectionBoxes:t.selectionBoxes,focusInput:e.focusInput,clearPreferredColumn:t.clearPreferredColumn,resetTransactionGrouping:t.resetTransactionGrouping,applyState:e.applyState,applyTransactionalState:t.applyTransactionalState,findReplace:{setIsOpen:n.fr.setIsOpen},newDocument:MS({isDirty:()=>r.isDirty(),resetDocument:()=>r.resetDocument(),requestConfirmation:()=>e.setNewDocumentDialog({isOpen:!0})}),saveDocument:()=>{r.save().catch(t=>e.logger.error("document:save failed",t))},openSymbolDialog:()=>e.setSymbolDialog({isOpen:!0}),openCommandSearch:()=>e.setCommandSearchOpen(!0),repeatLastAction:l,canRepeatLastAction:c,openTablePropertiesDialog:t=>{const n=Tm(e.state,t??"table");n&&e.setTablePropertiesDialog({isOpen:!0,initial:n})},openEquationDialog:()=>{const t=e.state.selection.focus,n=ci(e.state.document).find(e=>e.id===t.paragraphId);if("paragraph"===n?.type){let r=0;for(const o of n.runs){if("math"===o.kind&&t.offset>=r&&t.offset<=r+o.text.length)return void e.setEquationDialog({isOpen:!0,initial:o.math,targetRunId:o.id});r+=o.text.length}}e.setEquationDialog({isOpen:!0})},openFontDialog:o.openFontDialog,openParagraphDialog:o.openParagraphDialog,requestAcceptAllRevisions:()=>{e.setRevisionBulkDialog({isOpen:!0,action:"accept",count:vS(e.state).size})},requestRejectAllRevisions:()=>{e.setRevisionBulkDialog({isOpen:!0,action:"reject",count:vS(e.state).size})},toggleOutlinePanel:e.toggleOutline,isOutlineVisible:e.isOutlineVisible,toggleRevisionsPanel:e.toggleRevisionsPanel,revisionsPanelVisible:e.revisionsPanelVisible},externalPlugins:e.runtimeOptions().plugins,t:e.translator,customizeToolbar:e.runtimeOptions().customizeToolbar,customizeMenubar:e.runtimeOptions().customizeMenubar,initialDocument:e.getStateSnapshot().document,focusEditor:e.focusInput,logger:e.logger,onExecuted:(t,n)=>{s.record(t,n),e.onExecutedTap?.()},onReady:t=>{i=()=>t,r.resolveReady(t),e.runtimeOptions().onReady?.(r)},onSettled:()=>{e.setInitialLoading(!1)},onError:e=>r.rejectReady(e)});(function(e,t){const n=()=>t.cloneState(t.getStateSnapshot());e.connectHost({getRuntimeEditor:()=>t.runtimeReady()?t.runtimeEditor():null,getState:()=>n(),getDocument:()=>n().document,setDocument:e=>{t.applyState(Za(e)),t.resetEditorChromeState(),t.focusInput()},applyTransactionalState:t.applyTransactionalState,resetDocument:()=>{let e=Ba();try{const t=globalThis.localStorage?.getItem("oasis-design-default");if(t){const n=JSON.parse(t);n.themeId&&(e=VS(e,n.themeId)),e=US(e,n)}}catch{}t.applyState(e),t.resetEditorChromeState(),t.focusInput()},saveDocument:async()=>{await t.getPersistence().saveDocument(n().document)},getSelection:()=>n().selection,setSelection:e=>{t.applyState({...t.getStateSnapshot(),selection:{anchor:{...e.anchor},focus:{...e.focus}}}),t.focusInput()},focus:()=>t.focusInput(),blur:()=>{document.activeElement instanceof HTMLElement&&document.activeElement.blur(),t.setFocused(!1)},clearHistory:()=>t.clearHistory(),importDocx:e=>t.docIO.handleImportFile(e),exportDocx:()=>Promise.resolve(t.docIO.handleExportDocx()),exportPdf:()=>Promise.resolve(t.docIO.handleExportPdf()),exportDocxBlob:()=>t.docIO.exportDocxBlob(),exportPdfBlob:()=>t.docIO.exportPdfBlob(),getUiState:t.getUiState,updateUiState:t.updateUiState,getZoom:t.getZoom,setZoom:t.setZoom,adjustZoom:t.adjustZoom,toolbarRegistry:t.toolbarRegistry,menuRegistry:t.menuRegistry})})(r,{runtimeReady:d,runtimeEditor:u,getStateSnapshot:e.getStateSnapshot,cloneState:e.cloneState,applyState:e.applyState,applyTransactionalState:t.applyTransactionalState,resetEditorChromeState:t.resetEditorChromeState,focusInput:e.focusInput,setFocused:e.setFocused,clearHistory:t.clearHistory,getPersistence:()=>e.documentOptions().persistence??t.fallbackPersistence,docIO:t.docIO,getUiState:e.getUiState,updateUiState:e.updateUiState,getZoom:e.zoom.zoomPercent,setZoom:e.zoom.setZoomPercent,adjustZoom:e.zoom.adjustZoom,toolbarRegistry:g,menuRegistry:m}),mn(()=>{if(!d())return;e.state.document,e.state.selection,e.state.activeSectionIndex,e.state.activeZone;const t=e.cloneState(e.getStateSnapshot());u().dispatch(()=>t)});const{handleKeyDown:h}=function(e){const{state:t,isReadOnly:n,logger:r,focusInput:o,clearPreferredColumn:a,resetTransactionGrouping:i,applyState:s,applyTransactionalState:l,setForcePlainTextPaste:c,selectedImageRun:d,commandsController:u,tableOps:p,navigation:f,historyActions:g,styleController:m,findReplace:h,commandSearch:b,runtimeEditor:y}=e,{handleKeyDown:v}=zS({state:t,isReadOnly:n,clearPreferredColumn:a,resetTransactionGrouping:i,applyState:s,applyTransactionalState:l,applyTableAwareParagraphEdit:p.applyTableAwareParagraphEdit,applySelectionAwareParagraphCommand:p.applySelectionAwareParagraphCommand,focusInput:o,commandsController:u,pendingCaretTextStyle:m.pendingCaretTextStyle,autoTabIndentEnabled:Me,isMacPlatform:()=>"undefined"!=typeof navigator&&/Mac|iPhone|iPad/.test(navigator.platform),isCaretAtWrappedLineStart:f.isCaretAtWrappedLineStart,selectedImageRun:d,setForcePlainTextPaste:c,moveSelectionByWord:f.moveSelectionByWord,moveSelectionToDocumentBoundary:f.moveSelectionToDocumentBoundary,moveSelectionToParagraphBoundary:f.moveSelectionToParagraphBoundary,moveSelectedImageByParagraph:g.moveSelectedImageByParagraph,performUndo:g.performUndo,performRedo:g.performRedo,moveVerticalSelection:f.moveVerticalSelection,moveVerticalByBlock:f.moveVerticalByBlock,resolveAdjacentTableCellPosition:p.resolveAdjacentTableCellPosition,resolveTableTabTarget:p.resolveTableTabTarget,appendTableRowForTab:p.appendTableRowForTab,applySelectionPreservingStructure:g.applySelectionPreservingStructure,toggleFindReplace:e=>{h.setIsOpen(e??!h.isOpen())},toggleReplace:e=>{h.setIsOpen(e??!h.isOpen())},toggleCommandSearch:e=>{b.setIsOpen(e??!b.isOpen())},executeCommand:(e,t)=>y().commands.execute(e,t),canExecuteCommand:e=>y().commands.canExecute(e)});return{handleKeyDown:e=>{$S.includes(e.key)&&m.clearPendingCaretTextStyle();const n=[e.ctrlKey?"Ctrl":null,e.metaKey?"Meta":null,e.altKey?"Alt":null,e.shiftKey?"Shift":null].filter(Boolean).join("+"),o=n?`${n}+${e.key}`:e.key,a=t().selection;r.debug(`key:down ${o} at ${a.anchor.paragraphId}:${a.anchor.runId}[${a.anchor.offset}]`),lr("input-to-layout"),v(e),Et("input-to-layout")}}}({state:()=>e.state,isReadOnly:e.isReadOnly,logger:e.logger,focusInput:e.focusInput,clearPreferredColumn:t.clearPreferredColumn,resetTransactionGrouping:t.resetTransactionGrouping,applyState:e.applyState,applyTransactionalState:t.applyTransactionalState,setForcePlainTextPaste:e.setForcePlainTextPaste,selectedImageRun:n.selectedImageRun,commandsController:a,tableOps:n.tableOps,navigation:n.navigation,historyActions:t.historyActions,styleController:n.styleController,findReplace:n.fr,commandSearch:e.commandSearch,runtimeEditor:u});return{commandsController:o,runtimeReady:d,runtimeEditor:u,commandStateOf:p,toolbarHost:f,toolbarRegistry:g,menuRegistry:m,handleKeyDown:h}}(e)}function DP(e,t){const n=e.document.comments?.items;if(!n?.[t])return null;const r=/* @__PURE__ */new Set;let o=t;for(;n[o]?.parentId&&!r.has(o);){r.add(o);const e=n[o].parentId;if(!n[e])break;o=e}return o}function LP(e,t,n){if(t.document===e.document)return e;const r=e.document.comments?.items[n.commentId]??t.document.comments?.items[n.commentId];if(!r)return t;const o=DP(e,n.commentId)??DP(t,n.commentId)??n.commentId,a=e.document.comments?.order.length??0,i=t.document.comments?.order.length??0;return function(e,t){if(!(t.id.trim()&&t.commentId.trim()&&t.threadId.trim()&&t.actorName.trim()&&Number.isFinite(t.timestamp)))return e;const n=e.document.reviewActivity??[];return n.some(e=>e.id===t.id)?e:{...e,document:{...e.document,reviewActivity:[...n,{...t}]}}}(t,{id:n.id,kind:n.kind,commentId:n.commentId,threadId:o,...n.parentId?{parentId:n.parentId}:{},actorName:n.actorName,...n.actorId?{actorId:n.actorId}:{},targetAuthor:r.author,timestamp:n.timestamp,..."comment-deleted"===n.kind?{affectedCount:Math.max(1,a-i)}:{}})}function NP(e,t){if(!t)return!1;if(!e)return!0;if(e.canModerate)return!0;const n=e.identity?.id.trim();return Boolean(n&&t.authorId&&n===t.authorId)}function zP(e,t,n){if(!t?.items[n])return!1;if(!e||e.canModerate)return!0;if(!NP(e,t.items[n]))return!1;const r=/* @__PURE__ */new Set([n]),o=[n],a=/* @__PURE__ */new Map;for(const i of Object.values(t.items)){if(!i.parentId)continue;const e=a.get(i.parentId)??[];e.push(i.id),a.set(i.parentId,e)}for(;o.length;){const n=o.pop();for(const i of a.get(n)??[])if(!r.has(i)){if(r.add(i),!NP(e,t.items[i]))return!1;o.push(i)}}return!0}function $P(e){const[t,n]=Nt(null),[r,o]=Nt(""),[a,i]=Nt(!1),s=()=>e.access?.(),l=()=>{const e=s()?.identity;return e?.id.trim()&&e.displayName.trim()?{id:e.id.trim(),displayName:e.displayName.trim()}:null},c=()=>!(e.isReadOnly()||s()&&null===l()),d=()=>c()&&null!==Yn(e.state()),u=t=>c()&&Boolean(e.state().document.comments?.items[t]),p=()=>c()&&null!==wC(e.state()),f=t=>!e.isReadOnly()&&NP(s(),e.state().document.comments?.items[t]),g=()=>{const t=wC(e.state());return null!==t&&f(t.id)},m=t=>!e.isReadOnly()&&zP(s(),e.state().document.comments,t),h=f,b=(e="Local editor")=>{const t=l();return t?{actorName:t.displayName,actorId:t.id}:{actorName:e}},y=(e,t,n,r,o,a)=>LP(e,t,{id:_o("review-activity"),kind:n,commentId:r,...b(o),timestamp:Date.now(),...a?{parentId:a}:{}}),v=t=>{if(!u(t))return!1;const r=e.state(),o=r.document.comments?.items[t];return!!o&&(n({mode:"reply",snapshot:r,parentId:o.id,parentAuthor:o.author,parentText:o.text}),!0)},x=t=>{if(!f(t))return!1;const r=e.state(),o=r.document.comments?.items[t];return!!o&&(n({mode:"edit",snapshot:r,commentId:t,commentAuthor:o.author,commentText:o.text}),!0)},w=()=>{n(null),e.focusInput()},I=t=>{if(!m(t))return!1;const n=e.state();let r=!1;return e.applyTransactionalState(o=>{if(e.isReadOnly()||o.document!==n.document||!zP(s(),o.document.comments,t))return o;const a=function(e,t){const n=e.document.comments;if(!n?.items[t])return e;const r=/* @__PURE__ */new Set([t]),o=[t],a=/* @__PURE__ */new Map;for(const s of Object.values(n.items)){if(!s.parentId)continue;const e=a.get(s.parentId)??[];e.push(s.id),a.set(s.parentId,e)}for(;o.length>0;){const e=o.pop();for(const t of a.get(e)??[])r.has(t)||(r.add(t),o.push(t))}const i=Object.fromEntries(Object.entries(n.items).filter(([e])=>!r.has(e)));return{...e,document:{...e.document,comments:{...n,items:i,order:n.order.filter(e=>!r.has(e))}}}}(o,t);return r=a.document!==o.document,r?y(o,a,"comment-deleted",t):a}),r},S=(t,n)=>{if(!h(t))return!1;const r=e.state();let o=!1;return e.applyTransactionalState(a=>{if(e.isReadOnly()||a.document!==r.document||!NP(s(),a.document.comments?.items[t]))return a;const i=function(e,t,n){const r=e.document.comments,o=r?.items[t];return r&&o&&Boolean(o.resolved)!==n?{...e,document:{...e.document,comments:{...r,items:{...r.items,[t]:{...o,resolved:n}}}}}:e}(a,t,n);return o=i.document!==a.document,o?y(a,i,n?"comment-resolved":"comment-reopened",t):i}),o};return{draft:t,lastAuthor:r,panelOpen:a,togglePanel:()=>(i(!a()),!0),closePanel:()=>{i(!1)},canCreate:d,canReply:p,canReplyId:u,canEdit:g,canEditId:f,canDeleteId:m,canDeleteSelected:()=>{const t=wC(e.state());return null!==t&&m(t.id)},deleteSelected:()=>{const t=wC(e.state());return!!t&&I(t.id)},deleteById:I,canResolveId:h,canResolveSelected:()=>{const t=wC(e.state());return null!==t&&h(t.id)},resolveSelected:t=>{const n=wC(e.state());return!!n&&S(n.id,t)},resolveById:S,authorName:()=>l()?.displayName??r(),authorLocked:()=>void 0!==s(),openNew:()=>!!d()&&(n({mode:"new",snapshot:e.state()}),!0),openReply:()=>{if(!p())return!1;const t=wC(e.state());return!!t&&v(t.id)},openReplyToId:v,openEdit:()=>{if(!g())return!1;const t=wC(e.state());return!!t&&x(t.id)},openEditToId:x,close:w,submit:(n,r)=>{const a=t();if(!a||e.isReadOnly())return!1;if("edit"===a.mode&&!f(a.commentId))return!1;if("edit"!==a.mode&&!c())return!1;const i="edit"===a.mode?a.commentAuthor?.trim()??"":l()?.displayName??n.trim(),d=r.trim();if(!i||!d||e.state().document!==a.snapshot.document)return!1;if("edit"===a.mode&&a.commentText===d)return w(),!0;const u="edit"===a.mode?null:{id:_o("comment"),author:i,...l()?{authorId:l().id}:{},text:d,date:Date.now()};let p=!1;return e.applyTransactionalState(t=>{if(e.isReadOnly()||t.document!==a.snapshot.document)return t;if("edit"===a.mode&&!NP(s(),t.document.comments?.items[a.commentId]))return t;if("edit"!==a.mode&&!c())return t;const n="edit"===a.mode?Rn(t,a.commentId,d):"reply"===a.mode?pt(t,a.parentId,u):tn({...t,selection:a.snapshot.selection,activeSectionIndex:a.snapshot.activeSectionIndex,activeZone:a.snapshot.activeZone,activeFootnoteId:a.snapshot.activeFootnoteId},u);return p=n.document!==t.document,p?y(t,n,"new"===a.mode?"comment-created":"reply"===a.mode?"comment-replied":"comment-edited","edit"===a.mode?a.commentId:u.id,i,"reply"===a.mode?a.parentId:void 0):n}),p&&("edit"!==a.mode&&o(i),w()),p}}}var HP=/*#__PURE__*/qn("<div class=oasis-review-comments-filters role=group>"),WP=/*#__PURE__*/qn("<div class=oasis-review-comments-list>"),jP=/*#__PURE__*/qn("<div class=oasis-review-activity-list data-testid=review-activity-list role=list>"),UP=/*#__PURE__*/qn("<div role=region class=oasis-review-comments-panel data-testid=review-comments-panel><div class=oasis-review-comments-heading></div><div class=oasis-review-mode-switch role=group>"),VP=/*#__PURE__*/qn("<div class=oasis-review-thread-replies>"),KP=/*#__PURE__*/qn("<div class=oasis-review-thread><div class=oasis-review-thread-header></div><div class=oasis-review-thread-actions>"),_P=/*#__PURE__*/qn("<div class=oasis-review-reply><div class=oasis-review-thread-actions>"),XP=/*#__PURE__*/qn("<div class=oasis-review-activity-entry role=listitem data-testid=review-activity-entry><div class=oasis-review-activity-heading>");function qP(e){const t=D(),[r,o]=Nt("all"),[a,i]=Nt(!1),[s,l]=Nt(""),[c,d]=Nt(null),[u,p]=Nt(null),f=()=>e.state().document.comments,g=ur(()=>{const e=f();if(!e)return[];const t=s().trim().toLocaleLowerCase();return e.order.map(t=>e.items[t]).filter(t=>Boolean(t&&(!t.parentId||!e.items[t.parentId]))).filter(n=>("open"!==r()||!n.resolved)&&(!("resolved"===r()&&!n.resolved)&&(!t||[n,...sr(e.items,n.id)].some(e=>(e.text+" "+e.author).toLocaleLowerCase().includes(t)))))}),m=e=>sr(f()?.items??{},e),h=ur(()=>{const t=s().trim().toLocaleLowerCase();return[...e.state().document.reviewActivity??[]].filter(e=>!t||(e.actorName+" "+e.targetAuthor+" "+e.kind).toLocaleLowerCase().includes(t)).reverse()}),b=t=>Number.isFinite(t)?new Date(t).toLocaleString(e.locale?.()??"pt-BR"):"",y=t=>{u()===t?e.composer.deleteById(t)&&(p(null),c()===t&&d(null)):p(t)};return v=UP(),x=v.firstChild,w=x.nextSibling,Ue(x,wt(Pn,{as:"strong",get children(){return t("review.commentsPanel")}}),null),Ue(x,wt(bn,{size:"sm",variant:"ghost",get onClick(){return e.onClose},"data-testid":"review-comments-close",get"aria-label"(){return t("generic.close")},children:"✕"}),null),Ue(w,wt(bn,{size:"sm",variant:"ghost",get"aria-pressed"(){return!a()},onClick:()=>{i(!1)},"data-testid":"review-show-discussions",get children(){return t("review.commentsPanel")}}),null),Ue(w,wt(bn,{size:"sm",variant:"ghost",get"aria-pressed"(){return a()},onClick:()=>{i(!0)},"data-testid":"review-show-activity",get children(){return t("review.activity.title")}}),null),Ue(v,wt(Pn,{as:"p",get children(){return Qe(()=>!!a())()?`${t("review.activity.title")}: ${e.state().document.reviewActivity?.length??0}`:`${t("review.discussionCount")}: ${f()?.order.length??0}`}}),null),Ue(v,wt(pe,{get label(){return Qe(()=>!!a())()?t("review.activity.search"):t("review.searchComments")},get value(){return s()},onChange:l,"data-testid":"review-comments-search"}),null),Ue(v,wt(Bn,{get when(){return!a()},get children(){return[(i=HP(),Ue(i,wt(bn,{size:"sm",variant:"ghost",get"aria-pressed"(){return"all"===r()},onClick:()=>{o("all")},get children(){return t("review.filterAll")}}),null),Ue(i,wt(bn,{size:"sm",variant:"ghost",get"aria-pressed"(){return"open"===r()},onClick:()=>{o("open")},get children(){return t("review.filterOpen")}}),null),Ue(i,wt(bn,{size:"sm",variant:"ghost",get"aria-pressed"(){return"resolved"===r()},onClick:()=>{o("resolved")},get children(){return t("review.filterResolved")}}),null),Pt(()=>n(i,"aria-label",t("review.filterComments"))),i),(a=WP(),Ue(a,wt(Bn,{get when(){return 0===g().length},get children(){return wt(Pn,{as:"p",get children(){return t("review.noComments")}})}}),null),Ue(a,wt(dt,{get each(){return g()},children:r=>{return o=KP(),a=o.firstChild,i=a.nextSibling,Ue(a,wt(Pn,{as:"strong",get children(){return r.author||"—"}}),null),Ue(a,wt(Pn,{as:"span",get children(){return Qe(()=>!!r.resolved)()?t("review.filterResolved"):t("review.filterOpen")}}),null),Ue(o,wt(Pn,{as:"p",get children(){return r.text}}),i),Ue(i,wt(bn,{size:"sm",variant:"ghost",onClick:()=>e.onNavigate(r.id),"data-testid":"review-comment-navigate",get children(){return t("review.goToComment")}}),null),Ue(i,wt(Bn,{get when(){return e.composer.canEditId(r.id)},get children(){return wt(bn,{size:"sm",variant:"ghost",onClick:()=>{e.composer.openEditToId(r.id)},"data-testid":"review-comment-edit",get children(){return t("toolbar.editComment")}})}}),null),Ue(i,wt(Bn,{get when(){return e.composer.canResolveId(r.id)},get children(){return wt(bn,{size:"sm",variant:"ghost",onClick:()=>{e.composer.resolveById(r.id,!r.resolved)},"data-testid":"review-comment-resolve",get children(){return Qe(()=>!!r.resolved)()?t("toolbar.reopenComment"):t("toolbar.resolveComment")}})}}),null),Ue(i,wt(Bn,{get when(){return e.composer.canReplyId(r.id)},get children(){return wt(bn,{size:"sm",variant:"ghost",onClick:()=>{e.composer.openReplyToId(r.id)},"data-testid":"review-comment-reply",get children(){return t("toolbar.replyComment")}})}}),null),Ue(i,wt(Bn,{get when(){return e.composer.canDeleteId(r.id)},get children(){return[wt(bn,{size:"sm",variant:"ghost",onClick:()=>y(r.id),"data-testid":"review-comment-delete",get children(){return Qe(()=>u()===r.id)()?t("review.confirmDelete"):t("toolbar.deleteComment")}}),wt(Bn,{get when(){return u()===r.id},get children(){return wt(bn,{size:"sm",variant:"ghost",onClick:()=>{p(null)},get children(){return t("generic.cancel")}})}})]}}),null),Ue(o,wt(Bn,{get when(){return m(r.id).length>0},get children(){return wt(bn,{size:"sm",variant:"ghost",get"aria-expanded"(){return c()===r.id},"data-testid":"review-toggle-replies",onClick:()=>{d(c()===r.id?null:r.id)},get children(){return Qe(()=>c()===r.id)()?t("comment.showFewerReplies"):`${t("comment.showAllReplies")} (${m(r.id).length})`}})}}),null),Ue(o,wt(Bn,{get when(){return c()===r.id},get children(){var o=VP();return Ue(o,wt(dt,{get each(){return m(r.id)},children:r=>{return o=_P(),a=o.firstChild,Ue(o,wt(Pn,{as:"strong",get children(){return r.author||"—"}}),a),Ue(o,wt(Pn,{as:"p",get children(){return r.text}}),a),Ue(a,wt(Bn,{get when(){return e.composer.canEditId(r.id)},get children(){return wt(bn,{size:"sm",variant:"ghost",onClick:()=>{e.composer.openEditToId(r.id)},"data-testid":"review-reply-edit",get children(){return t("toolbar.editComment")}})}}),null),Ue(a,wt(Bn,{get when(){return e.composer.canReplyId(r.id)},get children(){return wt(bn,{size:"sm",variant:"ghost",onClick:()=>{e.composer.openReplyToId(r.id)},get children(){return t("toolbar.replyComment")}})}}),null),Ue(a,wt(Bn,{get when(){return e.composer.canDeleteId(r.id)},get children(){return[wt(bn,{size:"sm",variant:"ghost",onClick:()=>y(r.id),"data-testid":"review-reply-delete",get children(){return Qe(()=>u()===r.id)()?t("review.confirmDelete"):t("toolbar.deleteComment")}}),wt(Bn,{get when(){return u()===r.id},get children(){return wt(bn,{size:"sm",variant:"ghost",onClick:()=>{p(null)},get children(){return t("generic.cancel")}})}})]}}),null),Pt(()=>n(o,"data-comment-id",r.id)),o;var o,a}})),o}}),null),Pt(()=>n(o,"data-comment-id",r.id)),o;var o,a,i}}),null),a)];var a,i}}),null),Ue(v,wt(Bn,{get when(){return a()},get children(){var r=jP();return Ue(r,wt(Bn,{get when(){return 0===h().length},get children(){return wt(Pn,{as:"p",get children(){return t("review.activity.empty")}})}}),null),Ue(r,wt(dt,{get each(){return h()},children:r=>{return o=XP(),a=o.firstChild,Ue(a,wt(Pn,{as:"strong",get children(){return r.actorName}}),null),Ue(a,wt(Pn,{as:"span",get children(){return b(r.timestamp)}}),null),Ue(o,wt(Pn,{as:"p",get children(){return[Qe(()=>(e=>{switch(e){case"comment-created":return t("review.activity.created");case"comment-replied":return t("review.activity.replied");case"comment-edited":return t("review.activity.edited");case"comment-resolved":return t("review.activity.resolved");case"comment-reopened":return t("review.activity.reopened");case"comment-deleted":return t("review.activity.deleted")}})(r.kind))," — ",Qe(()=>r.targetAuthor),Qe(()=>Qe(()=>!!(r.affectedCount&&r.affectedCount>1))()?` (${r.affectedCount})`:"")]}}),null),Ue(o,wt(Bn,{get when(){return Boolean(f()?.items[r.commentId])},get children(){return wt(bn,{size:"sm",variant:"ghost","data-testid":"review-activity-navigate",onClick:()=>e.onNavigate(r.commentId),get children(){return t("review.goToComment")}})}}),null),Pt(()=>n(o,"data-activity-kind",r.kind)),o;var o,a}}),null),Pt(()=>n(r,"aria-label",t("review.activity.title"))),r}}),null),Pt(e=>{var r=t("review.commentsPanel"),o=t("review.displayMode");return r!==e.e&&n(v,"aria-label",e.e=r),o!==e.t&&n(w,"aria-label",e.t=o),e},{e:void 0,t:void 0}),v;var v,x,w}var GP="oasis-reviewing-pane-v1",YP={open:!1,scrollTop:0};function ZP(e){return"number"==typeof e&&Number.isFinite(e)&&e>=0?e:0}function JP(){const e=function(){try{const e=globalThis.localStorage?.getItem(GP);if(!e)return YP;if("true"===e)return{open:!0,scrollTop:0};if("false"===e)return{open:!1,scrollTop:0};const t=JSON.parse(e);if(!t||"object"!=typeof t||Array.isArray(t))return YP;const n=t;return{open:!0===n.open,scrollTop:ZP(n.scrollTop)}}catch{return YP}}(),[t,n]=Nt(e.open),[r,o]=Nt(e.scrollTop),a=()=>{!function(e){try{globalThis.localStorage?.setItem(GP,JSON.stringify(e))}catch{}}({open:t(),scrollTop:r()})},i=e=>{n(e),a()};return{open:()=>t(),toggle:()=>(i(!t()),!0),close:()=>{i(!1)},scrollTop:()=>r(),setScrollTop:e=>{const t=ZP(e);t!==r()&&(o(t),a())}}}var QP=/*#__PURE__*/qn("<ul class=oasis-review-revisions-list data-testid=review-revisions-list>"),eR=/*#__PURE__*/qn("<div class=oasis-review-revision-footer>"),tR=/*#__PURE__*/qn('<div role=region class="oasis-review-comments-panel oasis-review-revisions-panel"data-testid=review-revisions-panel><div class=oasis-review-comments-heading>'),nR=/*#__PURE__*/qn("<li class=oasis-review-revision-item><div class=oasis-review-revision-body></div><div class=oasis-review-revision-actions>");function rR(e,t){const n=ko(e),r=[];for(const a of n)for(const e of a.runs)e.revision?.id!==t&&e.styles?.propertyRevision?.id!==t||r.push(e.text);const o=r.join("").trim();return o.length>96?`${o.slice(0,93)}…`:o}function oR(e){const t=D(),r=ur(()=>{const t=e.state(),n=ko(t),r=/* @__PURE__ */new Map,o=/* @__PURE__ */new Map;for(const e of n)for(const t of e.runs){const e=t.revision;e&&(r.has(e.id)||r.set(e.id,e.author),o.has(e.id)||o.set(e.id,{date:e.date,type:e.type}));const n=t.styles?.propertyRevision;n&&(r.has(n.id)||r.set(n.id,n.author),o.has(n.id)||o.set(n.id,{date:n.date,type:"property"}))}const a=new Map(Yv(t).map(e=>[e.id,e])),i=new Map(Zv(t).map(e=>[e.id,e]));return bC(t).map(e=>{const n=o.get(e.id),s=a.get(e.id),l=i.get(e.id);return{id:e.id,type:n?.type??s?.type??l?.type??"insert",author:r.get(e.id)??s?.author??l?.author??"—",date:n?.date??s?.date??l?.date,snippet:rR(t,e.id)||s?.snippet||l?.snippet||"",section:void 0!==l}})}),o=ur(()=>{const t=e.state();return r().filter(e=>nx(t,e.type,e.author))});let a,i=!1;const s=()=>{const t=a,n=e.scrollTop;!t||"number"!=typeof n||n<=0||t.scrollHeight<=t.clientHeight||(t.scrollTop=n,i=!0,t.scrollTop!==n&&e.onScroll?.(t.scrollTop))};mn(()=>{o().length,i||queueMicrotask(s)});return l=tR(),c=l.firstChild,Ue(c,wt(Pn,{as:"strong",get children(){return t("review.reviewingPane")}}),null),Ue(c,wt(bn,{size:"sm",variant:"ghost",get onClick(){return e.onClose},"data-testid":"review-revisions-close",get"aria-label"(){return t("generic.close")},children:"✕"}),null),Ue(l,wt(Pn,{as:"p",get children(){return[Qe(()=>t("review.revisionCount")),": ",Qe(()=>o().length)]}}),null),Ue(l,wt(Bn,{get when(){return r().length-o().length>0},get children(){return wt(Pn,{as:"p",class:"oasis-review-revisions-filtered","data-testid":"review-revisions-filtered",get children(){return t("review.revisionsHiddenByShowMarkup")}})}}),null),Ue(l,wt(Bn,{get when(){return o().length>0},get fallback(){return wt(Pn,{as:"p",get children(){return t("review.noRevisions")}})},get children(){var r=QP();return r.addEventListener("scroll",t=>{e.onScroll?.(t.currentTarget.scrollTop)}),Qt(e=>{a=e,queueMicrotask(s)},r),Ue(r,wt(dt,{get each(){return o()},children:r=>{return o=nR(),a=o.firstChild,i=a.nextSibling,Ue(a,wt(Pn,{as:"span",get class(){return"oasis-review-revision-type "+(e=r.type,r.section?"review-revisions-icon-section":"delete"===e?"review-revisions-icon-delete":"property"===e?"review-revisions-icon-property":"grid"===e?"review-revisions-icon-grid":"review-revisions-icon-insert");var e},get"data-revision-type"(){return r.type},get children(){return[wt(ut,{get name(){return"delete"===(e=r.type)?"minus":"insert"===e?"plus":"pencil";var e}}),wt(Pn,{as:"span",get children(){return e=r.type,n=r.section,t(n?"review.revisionSection":"insert"===e||"delete"===e?"insert"===e?"review.revisionInsert":"review.revisionDelete":"grid"===e?"review.revisionGrid":"review.revisionProperty");var e,n}})]}}),null),Ue(a,wt(Pn,{as:"p",get children(){return r.snippet||"—"}}),null),Ue(a,wt(Pn,{as:"span",get children(){return r.author}}),null),Ue(i,wt(bn,{size:"sm",variant:"ghost",onClick:()=>e.onNavigate(r.id),"data-testid":"review-revision-navigate",get children(){return t("review.goToComment")}}),null),Ue(i,wt(bn,{size:"sm",variant:"ghost",onClick:()=>e.onAccept(r.id),"data-testid":"review-revision-accept",get children(){return t("toolbar.accept")}}),null),Ue(i,wt(bn,{size:"sm",variant:"ghost",onClick:()=>e.onReject(r.id),"data-testid":"review-revision-reject",get children(){return t("toolbar.reject")}}),null),Pt(e=>{var t=r.id,a=r.section?"true":void 0;return t!==e.e&&n(o,"data-comment-id",e.e=t),a!==e.t&&n(o,"data-revision-section",e.t=a),e},{e:void 0,t:void 0}),o;var o,a,i}})),r}}),null),Ue(l,wt(Bn,{get when(){return o().length>0},get children(){var n=eR();return Ue(n,wt(bn,{size:"sm",variant:"ghost",get onClick(){return e.onRejectAll},"data-testid":"review-revisions-reject-all",get children(){return t("toolbar.rejectAll")}}),null),Ue(n,wt(bn,{size:"sm",variant:"primary",get onClick(){return e.onAcceptAll},"data-testid":"review-revisions-accept-all",get children(){return t("toolbar.acceptAll")}}),null),n}}),null),Pt(()=>n(l,"aria-label",t("review.reviewingPane"))),l;var l,c}var aR=/*#__PURE__*/qn('<div class="oasis-editor-shell oasis-editor-app">');function iR(e={}){const t=e.runtime?.client??Gt(),[o,a]=Nt({}),i=()=>({...e.ui??{},...o(),toolbar:{...e.ui?.toolbar??{},...o().toolbar??{}}}),s=()=>({...e.document??{},...void 0===o().readOnly?{}:{readOnly:o().readOnly}}),l=()=>({...i(),readOnly:s().readOnly}),c=e=>(a(t=>({...t,...e,toolbar:{...t.toolbar??{},...e.toolbar??{}}})),{...l(),...e}),d=()=>e.runtime??{};_p();const u=G(()=>i().locale??"pt-BR"),p=It("app"),{state:f,commitState:g,getStateSnapshot:m}=function(e){const t=e.initialState?lt(e.initialState):e.initialDocument?Za(e.initialDocument):Ba();let n=t;const[r,o]=Nt(t),a=new Proxy({},{get(e,t){const n=r();if(null!==n&&("object"==typeof n||"function"==typeof n))return Reflect.get(n,t)},has(e,t){const n=r();return null!==n&&("object"==typeof n||"function"==typeof n)&&Reflect.has(n,t)},ownKeys(e){const t=r();return null===t||"object"!=typeof t&&"function"!=typeof t?[]:Reflect.ownKeys(t)},getOwnPropertyDescriptor(e,t){const n=r();return null===n||"object"!=typeof n&&"function"!=typeof n?{configurable:!0,enumerable:!0}:{...Reflect.getOwnPropertyDescriptor(n,t),configurable:!0,enumerable:!0}}});return{state:a,setStateSignal:o,commitState:e=>{const t=Ro(e===a?n:e);n=t,o(t)},getStateSnapshot:()=>n}}({initialDocument:s().initialDocument,initialState:s().initialState}),h=e=>{g(e)},b=lt;let y=!1;const{showChrome:v,showTitleBar:x,showMenubar:w,showToolbar:I,showOutline:S,showRuler:C,toggleOutline:k,toolbarView:T,toolbarLayout:R,isReadOnly:A,useComposedShell:M,loadingOptions:O,loadingLabel:B,shellComponent:F}=function(e){const{ui:t,documentOptions:n,updateUiState:r,state:o}=e,a=()=>{const e=t().loading;return"object"==typeof e&&null!==e?e:void 0};return{showChrome:()=>t().showChrome??!0,showTitleBar:()=>t().showTitleBar??!0,showMenubar:()=>t().showMenubar??!0,showToolbar:()=>t().showToolbar??!0,showRuler:()=>t().showRuler??t().showChrome??!0,showOutline:()=>t().showOutline??!0,toggleOutline:()=>{r({showOutline:!(t().showOutline??!0)})},toolbarView:()=>t().toolbar?.view??"ribbon",toolbarLayout:()=>t().toolbar?.layout??"overflow",isReadOnly:()=>(n().readOnly??!1)||"all"!==(o().reviewDisplayMode??"all"),useComposedShell:()=>"docs"===t().uiVariant||"document"!==(t().shell??"document"),loadingOptions:a,loadingLabel:()=>a()?.label??"Loading oasis-editor...",shellComponent:()=>{const e=t().shell??"document";return"inline"===e?ee:"balloon"===e?j:Ie}}}({ui:i,documentOptions:s,updateUiState:c,state:()=>f}),E=function(){const[e,t]=Nt(!1);let n,r,o,a,i;return{focused:e,setFocused:t,focusInput:()=>{t(!0),queueMicrotask(()=>{o?.focus({preventScroll:!0}),o&&(o.selectionStart=o.value.length,o.selectionEnd=o.value.length)})},focusInputAfterPointerSelection:()=>{t(!0),queueMicrotask(()=>{requestAnimationFrame(()=>{o?.focus({preventScroll:!0}),o&&(o.selectionStart=o.value.length,o.selectionEnd=o.value.length)})})},focusInputSync:()=>{t(!0),o?.focus({preventScroll:!0}),o&&(o.selectionStart=o.value.length,o.selectionEnd=o.value.length)},get viewportRef(){return n},set viewportRef(e){n=e},get surfaceRef(){return r},set surfaceRef(e){r=e},get textareaRef(){return o},set textareaRef(e){o=e},get importInputRef(){return a},set importInputRef(e){a=e},get imageInputRef(){return i},set imageInputRef(e){i=e}}}(),D=E.focused,L=E.setFocused,N=E.focusInput,$=E.focusInputAfterPointerSelection,H=E.focusInputSync,[W,U]=Nt(!1!==i().loading),V=Ze(),{linkDialog:K,setLinkDialog:_,imageAltDialog:X,setImageAltDialog:q,imageCaptionDialog:Y,setImageCaptionDialog:Z,contextMenu:J,setContextMenu:Q,fontDialog:te,setFontDialog:ne,paragraphDialog:re,setParagraphDialog:oe,tablePropertiesDialog:ae,setTablePropertiesDialog:ie,revisionBulkDialog:le,setRevisionBulkDialog:ce,newDocumentDialog:de,setNewDocumentDialog:ue,symbolDialog:pe,setSymbolDialog:fe,equationDialog:ge,setEquationDialog:me}=function(){const[e,t]=Nt({isOpen:!1}),[n,r]=Nt({isOpen:!1}),[o,a]=Nt({isOpen:!1}),[i,s]=Nt({isOpen:!1,initialHref:""}),[l,c]=Nt({isOpen:!1,initialAlt:""}),[d,u]=Nt({isOpen:!1,initialCaption:""}),[p,f]=Nt({isOpen:!1,x:0,y:0}),[g,m]=Nt({isOpen:!1,initial:{fontFamily:"",fontSize:"",color:"",colorMode:"automatic",highlight:"",shading:"",bold:!1,italic:!1,underline:!1,underlineStyle:null,underlineColor:"",strike:!1,doubleStrike:!1,superscript:!1,subscript:!1,smallCaps:!1,allCaps:!1,hidden:!1,characterScale:"",characterSpacing:"",baselineShift:"",kerningThreshold:"",ligatures:"",numberSpacing:"",numberForm:"",stylisticSet:"",contextualAlternates:!1}}),[h,b]=Nt({isOpen:!1,initial:{align:"",indentLeft:"",indentRight:"",indentFirstLine:"",indentHanging:"",mirrorIndents:!1,spacingBefore:"",spacingAfter:"",lineHeight:"",lineRule:"",contextualSpacing:!1,outlineLevel:"",shading:"",borderStyle:"",borderWidth:"",borderColor:"",borderSideTop:!1,borderSideRight:!1,borderSideBottom:!1,borderSideLeft:!1,pageBreakBefore:!1,keepWithNext:!1,keepLinesTogether:!1,widowControl:!0,tabs:[]}}),[y,v]=Nt({isOpen:!1,action:"accept",count:0}),[x,w]=Nt({isOpen:!1,initial:{activeTab:"table",tableWidth:"",tableWidthUnit:"points",tableAlign:"",tableIndentLeft:"",tableWrapping:"none",floatingSummary:"",floatingHorizontalAnchor:"margin",floatingVerticalAnchor:"text",floatingX:"0",floatingY:"0",floatingXAlign:"",floatingYAlign:"",floatingDistanceTop:"0",floatingDistanceRight:"0",floatingDistanceBottom:"0",floatingDistanceLeft:"0",floatingOverlap:"overlap",rowHeight:"",rowHeightRule:"",repeatHeader:!1,allowBreakAcrossPages:!0,hiddenRow:!1,columnWidth:"",cellWidth:"",cellVerticalAlign:"",cellTextDirection:"",cellNoWrap:!1,cellFitText:!1,cellHideMark:!1,marginTop:"",marginRight:"",marginBottom:"",marginLeft:"",borderStyle:"none",borderWidth:"",borderColor:"",borderTop:!1,borderRight:!1,borderBottom:!1,borderLeft:!1,borderStart:!1,borderEnd:!1,borderTopLeftToBottomRight:!1,borderTopRightToBottomLeft:!1,shading:"",altTitle:"",altDescription:""}});return{newDocumentDialog:e,setNewDocumentDialog:t,symbolDialog:n,setSymbolDialog:r,equationDialog:o,setEquationDialog:a,linkDialog:i,setLinkDialog:s,imageAltDialog:l,setImageAltDialog:c,imageCaptionDialog:d,setImageCaptionDialog:u,contextMenu:p,setContextMenu:f,fontDialog:g,setFontDialog:m,paragraphDialog:h,setParagraphDialog:b,tablePropertiesDialog:x,setTablePropertiesDialog:w,revisionBulkDialog:y,setRevisionBulkDialog:v}}(),[he,be]=Nt(!1),ye=()=>E.viewportRef,ve=()=>E.surfaceRef,xe=Rx({documentOptions:s,logger:p,runtimeClient:t,state:f,commitState:g,getStateSnapshot:m,applyState:h,cloneState:b,isReadOnly:A,focusInput:N,surfaceRef:ve,viewportRef:ye,zoomFactor:V.zoomFactor,getImageOps:()=>qe.imageOps}),{docIO:we,measuredBlockHeights:Se,measuredParagraphLayouts:Ce,documentLayout:Te,canvasSnapshotProvider:Pe,inputBox:Re,selectionBoxes:Ae,commentHighlights:Me,revisionMarkupBoxes:Oe,changeBarBoxes:Be,selectedImageBox:Fe,selectedTextBoxBox:Ee,selectedTableBox:De,caretBox:Le,preferredColumnX:Ne,setPreferredColumnX:ze,clearPreferredColumn:$e,onCleanupHook:We,persistenceStatus:je,applyTransactionalState:Ve,resetTransactionGrouping:Ke,updateHistoryState:_e}=xe,Xe=Pp({state:()=>f,stateSnapshot:m,isReadOnly:A,applyTransactionalState:Ve,applyTableAwareParagraphEdit:(e,t)=>qe.tableOps.applyTableAwareParagraphEdit(e,t),clearPreferredColumn:$e,resetTransactionGrouping:Ke,focusInput:N}),qe=lS({clipboardActions:Xe,state:f,getStateSnapshot:m,logger:p,isReadOnly:A,applyState:h,cloneState:b,focusInput:N,focusInputAfterPointerSelection:$,focusInputSync:H,surfaceRef:ve,viewportRef:ye,zoomFactor:V.zoomFactor,insertImageFromFile:we.insertImageFromFile,getForcePlainTextPaste:()=>y,setForcePlainTextPaste:e=>{y=e},getCommandsController:()=>Ct.commandsController,applyTransactionalState:Ve,clearPreferredColumn:$e,resetTransactionGrouping:Ke,updateHistoryState:_e,caretBox:Le,preferredColumnX:Ne,setPreferredColumnX:ze,measuredBlockHeights:Se,measuredParagraphLayouts:Ce,documentLayout:Te,canvasSnapshotProvider:Pe,openEquationDialog:(e,t)=>{me({isOpen:!0,initial:e,targetRunId:t})}}),{layoutOptionsOverlay:Ge,fr:Ye,tableOps:Je,imageOps:et,textBoxOps:tt,styleController:nt,onEditorPointerDown:rt,tableResize:at,tableCornerResize:it,tableDrag:st,revisionController:ct,textDrag:dt,surfaceEventsWithTextDrag:ut,textInput:pt,handleCopy:ft,handleCut:gt,handlePaste:mt,handleDrop:ht}=qe,[yt,vt]=Nt(!1),xt=JP(),St=$P({state:()=>f,isReadOnly:A,applyTransactionalState:Ve,focusInput:N,access:()=>d().review}),Ct=EP({commandSearch:{isOpen:yt,setIsOpen:e=>{vt(e)}},setCommandSearchOpen:vt,clipboardActions:Xe,document:xe,interaction:qe,commentComposer:St,state:f,logger:p,isReadOnly:A,focusInput:N,applyState:h,getStateSnapshot:m,cloneState:b,setFocused:L,setInitialLoading:U,getForcePlainTextPaste:()=>y,setForcePlainTextPaste:e=>{y=e},locale:()=>i().locale??"pt-BR",translator:u,runtimeClient:t,runtimeOptions:d,documentOptions:s,getUiState:l,updateUiState:c,zoom:V,importInputRef:()=>E.importInputRef,imageInputRef:()=>E.imageInputRef,setLinkDialog:_,setImageAltDialog:q,setImageCaptionDialog:Z,setNewDocumentDialog:ue,setSymbolDialog:fe,setEquationDialog:me,setTablePropertiesDialog:ie,setFontDialog:ne,setParagraphDialog:oe,setRevisionBulkDialog:ce,toggleOutline:k,isOutlineVisible:S,toggleRevisionsPanel:()=>{xt.toggle()},revisionsPanelVisible:xt.open}),{commandsController:kt,runtimeReady:Tt,runtimeEditor:At,toolbarHost:Mt,toolbarRegistry:Ot,menuRegistry:Bt,handleKeyDown:Ft}=Ct,Et=()=>function(e,t,n){const r=[],o=/* @__PURE__ */new Set;for(const a of e){if("hidden"in a&&!0===a.hidden)continue;const e=Hp(a);if(!e)continue;const t=a.label;if("string"!=typeof t||!t.trim())continue;if(o.has(e.command))continue;o.add(e.command);const n={id:a.id,label:t,command:e.command,...void 0===e.payload?{}:{payload:e.payload},source:"ribbon"};r.push(n)}for(const a of t){if(!0===a.hidden)continue;const e=$p(a.command);if(!e)continue;if(o.has(e.command))continue;o.add(e.command);const t=a.labelKey?n(a.labelKey):a.id;r.push({id:a.id,label:String(t),command:e.command,...void 0===e.payload?{}:{payload:e.payload},source:"menubar",...a.shortcut?{shortcut:a.shortcut}:{}})}return r}(Ot.getOrdered(),Bt.getItems(),u),Dt=e=>{try{return!1!==At().commands.canExecute(e)}catch{return!1}},{computeFontFamilyOptions:Lt,computeFontSizeOptions:zt,applyFontDialogValues:$t,applyParagraphDialogValues:Ht,setParagraphDialogDefault:Wt,applyTablePropertiesDialogValues:jt,buildContextMenuItems:Vt,handleEditorContextMenu:Kt,closeContextMenu:_t}=Mm({clipboardActions:Xe,state:()=>f,selection:()=>f.selection,toolbarStyleState:nt.toolbarStyleState,isReadOnly:A,t:u,logger:p,setFontDialog:ne,setParagraphDialog:oe,setTablePropertiesDialog:ie,setContextMenu:Q,clearPreferredColumn:$e,resetTransactionGrouping:Ke,applyTransactionalState:Ve,applyTableAwareParagraphEdit:Je.applyTableAwareParagraphEdit,focusInput:N,promptForLink:kt.promptForLink,tableOps:Je}),{layout:Xt,overlays:qt,refs:Yt,surfaceHandlers:Zt,inputHandlers:Jt,fileHandlers:Qt}=function(e){const{layout:t,overlays:n,refs:r,surface:o,input:a,files:i}=e;return{layout:{documentLayout:t.documentLayout,remoteWebFonts:t.remoteWebFonts,pageGutter:t.pageGutter,initialZoomMode:t.initialZoomMode,viewportHeight:t.viewportHeight,class:t.className,style:t.style,zoomPercent:t.zoomPercent,setZoomPercent:t.setZoomPercent,zoomFactor:t.zoomFactor},overlays:{selectionBoxes:n.selectionBoxes,commentHighlights:n.commentHighlights,revisionMarkupBoxes:n.revisionMarkupBoxes,changeBarBoxes:n.changeBarBoxes,onReplyToComment:n.onReplyToComment,onEditComment:n.onEditComment,canEditComment:n.canEditComment,canReplyComment:n.canReplyComment,selectedImageBox:n.selectedImageBox,selectedTextBoxBox:n.selectedTextBoxBox,selectedTableBox:n.selectedTableBox,layoutOptions:n.layoutOptions,caretBox:n.caretBox,inputBox:n.inputBox,hoveredRevision:n.hoveredRevision,focused:n.focused,showCaret:n.showCaret,importProgress:n.importProgress,imageCropMode:n.imageCropMode},refs:{onViewportRef:e=>{r.focusController.viewportRef=e},onSurfaceRef:e=>{r.focusController.surfaceRef=e},onTextareaRef:e=>{r.focusController.textareaRef=e},onImportInputRef:e=>{r.focusController.importInputRef=e},onImageInputRef:e=>{r.focusController.imageInputRef=e}},surfaceHandlers:{onDragOver:e=>e.preventDefault(),onDrop:o.handleDrop,onEditorPointerDown:o.onEditorPointerDown,onSurfacePointerDown:o.surfaceEvents.handleSurfacePointerDown,onSurfaceClick:o.surfaceEvents.handleSurfaceClick,onSurfacePointerMove:o.tableResize.handlePointerMove,onSurfaceDblClick:o.surfaceEvents.handleSurfaceDblClick,onParagraphPointerDown:o.surfaceEvents.handleParagraphPointerDown,onImagePointerDown:o.handleImagePointerDown,onImageResizeHandlePointerDown:o.handleImageResizeHandlePointerDown,onTextBoxResizeHandlePointerDown:o.handleTextBoxResizeHandlePointerDown,onImageRotateHandlePointerDown:o.handleImageRotateHandlePointerDown,onImageCropHandlePointerDown:o.handleImageCropHandlePointerDown,onImageCropBodyPointerDown:o.handleImageCropBodyPointerDown,onTextBoxRotateHandlePointerDown:o.handleTextBoxRotateHandlePointerDown,onTableDragHandlePointerDown:o.tableDrag.handlePointerDown,onTableCornerResizeHandlePointerDown:o.tableCornerResize.handlePointerDown,onRevisionMouseEnter:o.revisionController.handleRevisionMouseEnter,onRevisionMouseLeave:o.revisionController.handleRevisionMouseLeave,onEditorContextMenu:e=>o.handleEditorContextMenu(e)},inputHandlers:{onInputBlur:()=>a.setFocused(!1),onInputFocus:()=>a.setFocused(!0),onCompositionEnd:a.textInput.handleCompositionEnd,onCompositionStart:a.textInput.handleCompositionStart,onCompositionUpdate:a.textInput.handleCompositionUpdate,onCopy:a.handleCopy,onCut:a.handleCut,onInput:a.textInput.handleTextInput,onKeyDown:a.handleKeyDown,onKeyUp:a.handleKeyUp,onPaste:a.handlePaste},fileHandlers:{onImportInputChange:e=>i.handleImportFile(e.currentTarget.files?.[0]??null),onImageInputChange:e=>i.handleInsertImage(e.currentTarget.files?.[0]??null)}}}({layout:{documentLayout:Te,remoteWebFonts:s().remoteWebFonts,pageGutter:i().pageGutter,initialZoomMode:i().zoom?.initialMode,viewportHeight:i().viewportHeight,className:i().class,style:i().style,zoomPercent:V.zoomPercent,setZoomPercent:V.setZoomPercent,zoomFactor:V.zoomFactor},overlays:{selectionBoxes:Ae,commentHighlights:Me,revisionMarkupBoxes:Oe,changeBarBoxes:Be,onReplyToComment:e=>{St.openReplyToId(e)},onEditComment:e=>{St.openEditToId(e)},canEditComment:St.canEditId,canReplyComment:St.canReplyId,selectedImageBox:Fe,selectedTextBoxBox:Ee,selectedTableBox:De,layoutOptions:Ge,caretBox:Le,inputBox:Re,hoveredRevision:ct.hoveredRevision,focused:D,showCaret:()=>function(e,t){if(!t.visible||!ga(e.selection))return!1;const n=Ua(e),r=io(e.document,e.selection.anchor.paragraphId,n),o=io(e.document,e.selection.focus.paragraphId,n);return!(r&&o&&r.blockIndex===o.blockIndex&&(r.rowIndex!==o.rowIndex||r.cellIndex!==o.cellIndex))}(f,Le()),importProgress:we.importProgress,imageCropMode:et.cropMode},refs:{focusController:E},files:{handleImportFile:we.handleImportFile,handleInsertImage:we.handleInsertImage},surface:{surfaceEvents:ut,tableResize:at,tableCornerResize:it,tableDrag:st,revisionController:ct,handleDrop:ht,onEditorPointerDown:rt,handleImagePointerDown:et.handleImagePointerDown,handleImageResizeHandlePointerDown:et.handleImageResizeHandlePointerDown,handleTextBoxResizeHandlePointerDown:tt.handleTextBoxResizeHandlePointerDown,handleImageRotateHandlePointerDown:et.handleImageRotateHandlePointerDown,handleImageCropHandlePointerDown:et.handleImageCropHandlePointerDown,handleImageCropBodyPointerDown:et.handleImageCropBodyPointerDown,handleTextBoxRotateHandlePointerDown:tt.handleTextBoxRotateHandlePointerDown,handleEditorContextMenu:Kt},input:{textInput:pt,setFocused:L,handleCopy:ft,handleCut:gt,handlePaste:mt,handleKeyDown:e=>{if("Escape"===e.key&&qe.formatPainter.mode())return qe.formatPainter.cancel(),void e.preventDefault();Ft(e)},handleKeyUp:e=>{qe.formatPainter.mode()&&(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown","Shift"].includes(e.key)||(e.ctrlKey||e.metaKey)&&"a"===e.key.toLowerCase())&&qe.formatPainter.applyToSelection("keyboard")}}});return ot(()=>{Fn(),nn(),r(),Zn(()=>ve()??null),bt(),(i().showWelcome??!0)&&!P()&&ke()&&be(!0)}),Ut(()=>{We(),ut.stopDragging(),dt.stopDrag(),at.stop(),it.stop(),st.stop(),et.stopImageDrag(),et.stopImageResize(),et.stopImageCrop(),tt.stopTextBoxResize(),tr()}),wt(He,{translator:u,get children(){var e=aR();return Ue(e,wt(Bn,{get when(){return Qe(()=>!(M()||!v()))()&&I()},get children(){return wt(se,{host:Mt,registry:Ot,get showFileGroup(){return!!Qe(()=>"ribbon"===T())()||!w()},get view(){return T()},get layout(){return R()}})}}),null),Ue(e,wt(Mp,{get notice(){return Xe.notice},onDismiss:()=>{Xe.dismiss(),N()}}),null),Ue(e,wt(Bn,{get when(){return St.panelOpen()},get children(){return wt(qP,{state:()=>f,composer:St,locale:()=>i().locale??"pt-BR",get onClose(){return St.closePanel},onNavigate:e=>{const t=function(e,t){const n=e.document.comments?.items;if(!n?.[t])return e;let r=n[t];const o=/* @__PURE__ */new Set;for(;r&&!r.start&&r.parentId&&!o.has(r.id);)o.add(r.id),r=n[r.parentId];const a=r?.start,i=r?.end;if(!a||!i)return e;const s=ko(e),l=s.find(e=>e.id===a.paragraphId),c=s.find(e=>e.id===i.paragraphId);return l&&c?{...e,selection:{anchor:xi(l,a.offset),focus:xi(c,i.offset)}}:e}(f,e);t!==f&&(h(t),N())}})}}),null),Ue(e,wt(Bn,{get when(){return xt.open()},get children(){return wt(oR,{state:()=>f,get onClose(){return xt.close},get scrollTop(){return xt.scrollTop()},get onScroll(){return xt.setScrollTop},onNavigate:e=>{const t=IC(f,e);t!==f&&(h(t),N())},onAccept:e=>{const t=IC(f,e);t!==f&&(h(t),kt.applyAcceptRevisionsCommand(),N())},onReject:e=>{const t=IC(f,e);t!==f&&(h(t),kt.applyRejectRevisionsCommand(),N())},onAcceptAll:()=>At().commands.execute("requestAcceptAllRevisions"),onRejectAll:()=>At().commands.execute("requestRejectAllRevisions")})}}),null),Ue(e,wt(zp,{get isOpen(){return yt()},get entries(){return Et()},isEnabled:Dt,onExecute:e=>{At().commands.execute(e.command,e.payload),vt(!1),N()},onClose:()=>{vt(!1),N()}}),null),Ue(e,wt(pb,{commentComposer:St,dialogs:{linkDialog:K,setLinkDialog:_,imageAltDialog:X,setImageAltDialog:q,imageCaptionDialog:Y,setImageCaptionDialog:Z,contextMenu:J,setContextMenu:Q,fontDialog:te,setFontDialog:ne,paragraphDialog:re,setParagraphDialog:oe,tablePropertiesDialog:ae,setTablePropertiesDialog:ie,revisionBulkDialog:le,setRevisionBulkDialog:ce,newDocumentDialog:de,setNewDocumentDialog:ue,symbolDialog:pe,setSymbolDialog:fe,equationDialog:ge,setEquationDialog:me},findReplace:Ye,fontFamilyOptions:Lt,fontSizeOptions:zt,contextMenuItems:Vt,focusInput:N,get applyLinkCommand(){return kt.applyLinkCommand},get applyImageAltCommand(){return kt.applyImageAltCommand},get applyImageCaptionCommand(){return kt.applyImageCaptionCommand},applyFontDialogValues:$t,applyParagraphDialogValues:Ht,setParagraphDialogDefault:Wt,applyTablePropertiesDialogValues:jt,confirmNewDocument:()=>t.resetDocument(),applyBulkRevisions:e=>{At().commands.execute("accept"===e?"acceptAllRevisions":"rejectAllRevisions"),N()},insertSymbol:(e,t)=>{At().commands.execute("insertText",{text:e,fontFamily:t}),N()},applyEquation:(e,t)=>{t?At().commands.execute("updateEquation",{runId:t,expression:e}):At().commands.execute("insertEquation",e),N()},closeContextMenu:_t}),null),Ue(e,wt(gb,{useComposedShell:M,shellComponent:F,runtime:{state:()=>f,toolbarHost:Mt,runtimeEditor:At,persistenceStatus:je,toolbarRegistry:Ot,menuRegistry:Bt},chrome:{showChrome:v,showTitleBar:x,showMenubar:w,showToolbar:I,showOutline:S,showRuler:C,toolbarView:T,toolbarLayout:R},view:{isReadOnly:A,viewportHeight:()=>i().viewportHeight,measuredBlockHeights:Se,measuredParagraphLayouts:Ce,documentLayout:Te,layout:Xt,overlays:qt,refs:Yt,surfaceHandlers:Zt,inputHandlers:Jt,fileHandlers:Qt}}),null),Ue(e,wt(Lm,{state:f,get surfaceRef(){return ve()},documentLayout:Te,snapshotProvider:Pe,get zoomFactor(){return V.zoomFactor},tableResize:at,tableCornerResize:it,imageOps:et,tableDrag:st,textDrag:dt}),null),Ue(e,wt(Bn,{get when(){return W()||!Tt()},get children(){return wt(z,{get label(){return B()},get class(){return O()?.class},get style(){return O()?.style}})}}),null),Ue(e,wt(hb,{get isOpen(){return Qe(()=>!(!he()||W()))()&&Tt()},onClose:()=>be(!1)}),null),Pt(t=>{var r=i().theme??"light",o=!!M(),a=!!A(),s=!("two-line"!==i().toolbar?.ribbonStyle),l=!("simplified"!==i().toolbar?.ribbonStyle),c=!(null===qe.formatPainter.mode()),d={"--oasis-editor-gutter-x":`${Rt(i().pageGutter)}px`,...void 0!==i().pageGutter?{"--oasis-editor-gutter-top":`${Rt(i().pageGutter)}px`,"--oasis-editor-gutter-bottom":`${Rt(i().pageGutter)}px`}:{}};return r!==t.e&&n(e,"data-theme",t.e=r),o!==t.t&&e.classList.toggle("oasis-editor-docs",t.t=o),a!==t.a&&e.classList.toggle("oasis-editor-read-only",t.a=a),s!==t.o&&e.classList.toggle("oasis-editor-ribbon-two-line",t.o=s),l!==t.i&&e.classList.toggle("oasis-editor-ribbon-simplified",t.i=l),c!==t.n&&e.classList.toggle("oasis-editor-format-painter-active",t.n=c),t.s=Tn(e,d,t.s),t},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),e}})}export{iR as OasisEditorApp};
|