oasis-editor 0.0.393 → 0.0.394

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.
@@ -1 +0,0 @@
1
- import{i as e}from"./rolldown-runtime-CjpNFd0O.js";import{$ as t,$n as n,$r as o,$t as r,A as a,An as i,Ar as s,At as l,B as c,Bi as d,Bn as u,C as p,Ci as g,Cn as f,Cr as m,Ct as h,D as b,Di as y,Dn as v,Dr as x,Dt as w,E as S,Ei as I,En as C,Er as T,Et as k,F as P,Fn as R,Ft as B,G as M,Gi as O,Gn as A,Gt as F,H as D,Hi as E,Hn as L,I as N,In as z,It as $,J as H,Ji as W,Jn as U,Jr as j,Jt as V,K,Ki as _,Kn as X,Kr as G,Kt as q,L as Y,Li as Z,Ln as J,Lt as Q,M as ee,Mn as te,Mt as ne,N as oe,Nn as re,Nr as ae,Nt as ie,O as se,Oi as le,On as ce,Or as de,Ot as ue,P as pe,Pn as ge,Pt as fe,Q as me,Qi as he,Qn as be,Qr as ye,Qt as ve,R as xe,Ri as we,Rn as Se,Rt as Ie,S as Ce,Si as Te,Sn as ke,Sr as Pe,St as Re,T as Be,Ti as Me,Tn as Oe,Tr as Ae,Tt as Fe,U as De,Ui as Ee,Un as Le,V as Ne,Vi as ze,Vn as $e,W as He,Wi as We,Wn as Ue,Wt as je,X as Ve,Xn as Ke,Xr as _e,Xt as Xe,Y as Ge,Yi as qe,Yn as Ye,Yr as Ze,Yt as Je,Z as Qe,Zi as et,Zn as tt,Zr as nt,Zt as ot,_ as rt,_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 gt,at as ft,b as mt,bi as ht,bn as bt,br as yt,bt as vt,c as xt,ca as wt,cn as St,cr as It,ct as Ct,d as Tt,da as kt,di as Pt,dn as Rt,dr as Bt,dt as Mt,ea as Ot,ei as At,en as Ft,er as Dt,et as Et,f as Lt,fi as Nt,fn as zt,fr as $t,ft as Ht,g as Wt,gi as Ut,gn as jt,gr as Vt,gt as Kt,h as _t,ha as Xt,hi as Gt,hn as qt,hr as Yt,ht as Zt,i as Jt,ia as Qt,ii as en,in as tn,ir as nn,it as on,j as rn,jn as an,jr as sn,k as ln,kn as cn,kr as dn,kt as un,l as pn,la as gn,ln as fn,lr as mn,lt as hn,m as bn,ma as yn,mn as vn,mr as xn,mt as wn,n as Sn,na as In,ni as Cn,nn as Tn,nr as kn,nt as Pn,o as Rn,oa as Bn,oi as Mn,on as On,or as An,ot as Fn,p as Dn,pa as En,pi as Ln,pn as Nn,pr as zn,q as $n,qi as Hn,qn as Wn,qr as Un,qt as jn,r as Vn,ra as Kn,ri as _n,rn as Xn,rr as Gn,rt as qn,s as Yn,sa as Zn,si as Jn,sn as Qn,sr as eo,st as to,t as no,ta as oo,ti as ro,tn as ao,tr as io,tt as so,u as lo,ua as co,ui as uo,un as po,ur as go,ut as fo,v as mo,vi as ho,vn as bo,vr as yo,vt as vo,w as xo,wi as wo,wn as So,wr as Io,wt as Co,x as To,xi as ko,xn as Po,xr as Ro,xt as Bo,y as Mo,yi as Oo,yn as Ao,yr as Fo,yt as Do,z as Eo,zi as Lo,zn as No}from"./defaultToolbar-WpWm9GL2.js";import{$ as zo,$n as $o,$t as Ho,A as Wo,An as Uo,At as jo,B as Vo,Bn as Ko,C as _o,Cn as Xo,D as Go,Dn as qo,Dt as Yo,E as Zo,En as Jo,Fn as Qo,Ft as er,G as tr,Gt as nr,H as or,Hn as rr,Ht as ar,In as ir,It as sr,J as lr,Jt as cr,K as dr,Kn as ur,Kt as pr,L as gr,Ln as fr,Lt as mr,M as hr,Mt as br,N as yr,Nt as vr,O as xr,On as wr,Ot as Sr,Pn as Ir,Pt as Cr,Qn as Tr,Qt as kr,Rt as Pr,S as Rr,Sn as Br,T as Mr,Tt as Or,U as Ar,Un as Fr,Ut as Dr,V as Er,W as Lr,Wn as Nr,X as zr,Xn as $r,Xt as Hr,Y as Wr,Yn as Ur,Yt as jr,Z as Vr,Zn as Kr,_ as _r,_n as Xr,_t as Gr,a as qr,an as Yr,ar as Zr,b as Jr,bn as Qr,c as ea,cn as ta,cr as na,ct as oa,d as ra,dn as aa,dr as ia,dt as sa,en as la,et as ca,f as da,fn as ua,ft as pa,g as ga,gn as fa,gt as ma,h as ha,i as ba,in as ya,ir as va,it as xa,j as wa,jt as Sa,k as Ia,kn as Ca,kt as Ta,l as ka,ln as Pa,lr as Ra,lt as Ba,m as Ma,mn as Oa,n as Aa,nn as Fa,nr as Da,nt as Ea,o as La,on as Na,or as za,ot as $a,p as Ha,pn as Wa,q as Ua,qt as ja,rn as Va,rr as Ka,s as _a,sn as Xa,sr as Ga,st as qa,tn as Ya,tr as Za,tt as Ja,u as Qa,un as ei,ur as ti,v as ni,vn as oi,vt as ri,w as ai,wn as ii,wt as si,x as li,xn as ci,xt as di,y as ui,yn as pi,yt as gi,z as fi}from"./sourcePackage-BbPv-emQ.js";function mi(e,t){return{document:e.document,selection:t}}function hi(e,t){if(!sr(e.selection))return rn(e,t<0?"start":"end");const{paragraphs:n,index:o,offset:r}=oe(e),a=o+t;if(a<0||a>=n.length)return e;const i=n[a];return mi(e,Y(ci(i,Math.min(r,Xr(i)))))}function bi(e,t){const{paragraphs:n,paragraph:o,index:r,offset:a}=oe(e),i=Xr(o);if(t<0&&a>0)return mi(e,{anchor:e.selection.anchor,focus:ci(o,a-1)});if(t>0&&a<i)return mi(e,{anchor:e.selection.anchor,focus:ci(o,a+1)});if(t<0&&r>0){const t=n[r-1];return mi(e,{anchor:e.selection.anchor,focus:ci(t,Xr(t))})}if(t>0&&r<n.length-1){const t=n[r+1];return mi(e,{anchor:e.selection.anchor,focus:ci(t,0)})}return e}function yi(e,t){const{paragraphs:n,index:o,offset:r}=oe(e),a=o+t;if(a<0||a>=n.length)return e;const i=n[a];return mi(e,{anchor:e.selection.anchor,focus:ci(i,Math.min(r,Xr(i)))})}function vi(e){const t=mr(e);if(t.isCollapsed)return"";const n=cr(e);if(t.startIndex===t.endIndex){const e=n[t.startIndex];return oi(e).slice(t.startParagraphOffset,t.endParagraphOffset)}const o=[],r=n[t.startIndex],a=n[t.endIndex];o.push(oi(r).slice(t.startParagraphOffset));for(let i=t.startIndex+1;i<t.endIndex;i+=1)o.push(oi(n[i]));return o.push(oi(a).slice(0,t.endParagraphOffset)),o.join("\n")}function xi(e,t){return{...e,selection:{anchor:br(e,t.anchor),focus:br(e,t.focus)}}}function wi(e){if(!sr(e.selection))return rn(e,"start");const{paragraph:t,index:n,offset:o}=oe(e),r=cr(e);if(pi(t,o)&&"before-markers"!==e.selection.focus.fieldBoundaryAffinity)return{...e,selection:Y(Qr(t,o,"before-markers"))};if(o>0)return{...e,selection:Y(Qr(t,o-1,"after-markers"))};if(0===n)return e;const a=r[n-1];return{...e,selection:Y(Qr(a,Xr(a),"after-markers"))}}function Si(e){if(!sr(e.selection))return rn(e,"end");const{paragraph:t,index:n,offset:o}=oe(e),r=cr(e),a=Xr(t);if(pi(t,o)&&"after-markers"!==e.selection.focus.fieldBoundaryAffinity)return{...e,selection:Y(Qr(t,o,"after-markers"))};if(o<a)return{...e,selection:Y(Qr(t,o+1,"before-markers"))};if(n>=r.length-1)return e;const i=r[n+1];return{...e,selection:Y(Qr(i,0,"before-markers"))}}function Ii(e,t){const n=mr(e);if(n.isCollapsed||n.startIndex!==n.endIndex||n.endParagraphOffset-n.startParagraphOffset!==1)return null;const o=cr(e)[n.startIndex];if(!o)return null;let r=0;for(let a=0;a<o.runs.length;a+=1){const e=o.runs[a],i=r;if(r+=e.text.length,t(e)&&1===e.text.length&&i===n.startParagraphOffset)return{paragraph:o,paragraphIndex:n.startIndex,run:e,runIndex:a,offset:i}}return null}var Ci=$a(),Ti="http://schemas.openxmlformats.org/officeDocument/2006/relationships",ki="http://schemas.microsoft.com/office/2011/relationships",Pi="application/vnd.openxmlformats-officedocument.",Ri=16777216,Bi=4096,Mi=/* @__PURE__ */new Map([[Ti+"/chart",/* @__PURE__ */new Set([Pi+"drawingml.chart+xml"])],[ki+"/chartStyle",/* @__PURE__ */new Set(["application/vnd.ms-office.chartstyle+xml"])],[ki+"/chartColorStyle",/* @__PURE__ */new Set(["application/vnd.ms-office.chartcolorstyle+xml"])],[Ti+"/image",/* @__PURE__ */new Set(["image/png","image/jpeg","image/gif","image/bmp","image/tiff"])],[Ti+"/package",/* @__PURE__ */new Set([Pi+"spreadsheetml.sheet"])]]),Oi="oasis.opc-chart-transfer.v1",Ai=e=>{throw Error("Opaque transfer rejected: "+e)};function Fi(e){if(!e||"object"!=typeof e||Array.isArray(e))return Ai("expected record");const t=Object.getPrototypeOf(e);return t!==Object.prototype&&null!==t?Ai("unexpected record prototype"):e}function Di(e,t=Ri){return"string"!=typeof e||!e.length||e.length>t?Ai("invalid string or size"):e}function Ei(e,t){return!Array.isArray(e)||e.length>t?Ai("invalid array or count"):e}function Li(e){const t=Di(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?Ai("unsafe part path"):t}function Ni(e){if(/<!\s*(?:DOCTYPE|ENTITY)\b/i.test(e))return Ai("unsafe XML declaration");const t=new Ci.DOMParser({onError:()=>Ai("malformed XML")}).parseFromString(e,"application/xml").documentElement;return t||Ai("missing XML root")}function zi(e,t){const n=Ei(e,Bi).map(e=>function(e,t){const n=Fi(e),o=Di(n.id,256),r=Di(n.type,512),a=Di(n.target,512);if(!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(o)||!Mi.has(r))return Ai("unsupported relationship");if(void 0!==n.targetMode&&"Internal"!==n.targetMode)return Ai("external relationship");if(!/^[A-Za-z0-9_.\-/]+$/.test(a))return Ai("unsafe relationship URI");const i=Li(n.resolvedTarget);return Ua(t,a)!==i?Ai("inconsistent relationship target"):{id:o,type:r,target:a,targetMode:"Internal",resolvedTarget:i}}(e,t));return new Set(n.map(e=>e.id)).size!==n.length?Ai("duplicate relationship ID"):n}function $i(e){const t=Fi(e),n=Li(t.path),o=Di(t.contentType,256),r=Di(t.data),a=o.endsWith("+xml");return[...Mi.values()].some(e=>e.has(o))?t.kind!==(a?"xml":"binary")||t.encoding!==(a?"utf8":"base64")?Ai("inconsistent part encoding"):a||/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(r)?(a&&Ni(r),{path:n,contentType:o,kind:a?"xml":"binary",encoding:a?"utf8":"base64",data:r,relationships:zi(t.relationships,n)}):Ai("invalid base64"):Ai("unsupported content type")}function Hi(e){const t=Fi(e);if("oasis.opc-chart-transfer.v1"!==t.format)return Ai("unsupported format");const n=Li(t.ownerPath),o=Di(t.fragmentXml,1048576),r=Di(t.signature,2097152),a=zi(t.relationships,n),i=Ei(t.parts,128).map(Fi);let s=o.length+r.length,l=a.length;for(const m of i){if(s+=Di(m.data).length,l+=Ei(m.relationships,Bi).length,3*s>Ri)return Ai("aggregate size limit");if(l>Bi)return Ai("aggregate relationship limit")}const c=i.map($i),d=Ni(o),u=hr(d);if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==d.namespaceURI||"drawing"!==d.localName||!u||"chart"!==u.objectKind||"inline"!==u.placement||u.signature!==r)return Ai("unsupported or changed chart fragment");if(1!==a.filter(e=>e.type===Ti+"/chart").length||a.some(e=>e.type!==Ti+"/chart")||JSON.stringify([...u.relationshipIds].sort())!==JSON.stringify(a.map(e=>e.id).sort()))return Ai("chart relationship mismatch");const p=new Map(c.map(e=>[e.path,e]));if(p.size!==c.length||p.has(n))return Ai("duplicate or story-dependent part");if(new Set([n,...p.keys()].map(e=>e.toLowerCase())).size!==c.length+1)return Ai("aliased part path");const g=[...a],f=/* @__PURE__ */new Set;for(let m=0;m<g.length;m++){const e=g[m],t=p.get(e.resolvedTarget);if(!t||!Mi.get(e.type)?.has(t.contentType))return Ai("missing dependency or incompatible relationship type");if(!f.has(t.path)){if(f.add(t.path),t.contentType!==Pi+"drawingml.chart+xml"&&t.relationships.length)return Ai("unsupported nested dependency owner");if(t.relationships.some(e=>e.type===Ti+"/chart"))return Ai("nested chart dependency");g.push(...t.relationships)}}return f.size!==c.length?Ai("unreachable payload part"):{format:Oi,ownerPath:n,fragmentXml:o,signature:r,relationships:a,parts:c.sort((e,t)=>e.path<t.path?-1:e.path>t.path?1:0)}}var Wi=/* @__PURE__ */e(Vr(),1);var Ui=new Set(["chart","diagramData","diagramLayout","diagramQuickStyle","diagramColors","oleObject","package","image"].map(e=>"http://schemas.openxmlformats.org/officeDocument/2006/relationships/"+e)),ji=(e,t)=>Object.hasOwn(e.parts,t),Vi=e=>Array.from(e.childNodes).filter(e=>1===e.nodeType);function Ki(e){if(/<!\s*(?:DOCTYPE|ENTITY)\b/i.test(e))throw Error("Unsupported XML declarations");const t=new Ci.DOMParser({onError:()=>{throw Error("Invalid XML")}}).parseFromString(e,"application/xml");if(!t.documentElement)throw Error("Missing XML root");return t}function _i(e){return/^[A-Za-z0-9_.\-/]+$/.test(e)&&!e.startsWith("/")&&!e.split("/").some(e=>""===e||"."===e||".."===e)}function Xi(e,t,n){const o=t.parts[e],r=n.parts[e];if(!o||!r||!_i(e)||o.kind!==r.kind||o.data!==r.data||o.contentType!==r.contentType||o.encoding!==r.encoding)return!1;const a=o.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 Gi(e,t){if(e.includes(t))return!0;const n=[Ki(e).documentElement];for(;n.length;){const e=n.pop();if(Array.from(e.attributes).some(e=>e.value.includes(t)))return!0;for(const o of Array.from(e.childNodes))if(1===o.nodeType)n.push(o);else if(o.nodeValue?.includes(t))return!0}return!1}function qi(e,t){return e.id===t.id&&e.type===t.type&&e.mode===(t.targetMode??"Internal")&&e.resolved===t.resolvedTarget}function Yi(e,t,n){const o=e=>({removeEdges:[],removeParts:[],...e?{skippedReason:e}:{}});if(!n.length)return o();try{if(e.mainDocumentPart!==t.mainDocumentPart)return o("Main part changed");if(Object.keys(t.parts).some(e=>e.startsWith("_xmlsignatures/")))return o("Signed package");const r=wa(e),a=/* @__PURE__ */new Set,i=/* @__PURE__ */new Set;for(const b of n){const n=r.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 o("Ambiguous deletion intent");for(const o of s.partPaths)Xi(o,e,t)&&a.add(o);for(const e of s.relationshipIds)i.add(e)}if(!a.size)return o();const s=function(e){const t=[];for(const[n,o]of Object.entries(e.parts)){const r=Ar(n);if(void 0===r)continue;if(null!==r&&!ji(e,r))throw Error("Relationship without owner");if("xml"!==o.kind)throw Error("Non-XML relationship part");const a=Ki(o.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 o of Vi(a)){if("http://schemas.openxmlformats.org/package/2006/relationships"!==o.namespaceURI||"Relationship"!==o.localName)throw Error("Unknown relationship element");const a=o.getAttribute("Id"),s=o.getAttribute("Type"),l=o.getAttribute("Target"),c=o.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:r,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=Ua(r,l);if(!t||!_i(t)||!ji(e,t)||void 0!==Ar(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 o("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)&&Ui.has(n.type)&&e.parts[e.mainDocumentPart]?.relationships?.find(e=>qi(n,e))&&!Gi(l.data,n.id)&&c.add(n);if(!c.size)return o();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===Ar(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 g=/* @__PURE__ */new Set,f=[...c].flatMap(e=>e.resolved?[e.resolved]:[]);for(let e=0;e<f.length;e++){const t=f[e];if(a.has(t)&&!g.has(t)){g.add(t);for(const e of d.get(t)??[])e.resolved&&f.push(e.resolved)}}const m=[...g].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 o("Retained incoming edge");return{removeEdges:[...c],removeParts:m}}catch(r){return o(r instanceof Error?r.message:String(r))}}var Zi="word/comments.xml";function Ji(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}function Qi(e){return e.localName??e.tagName}function es(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(o?.localName===t)return o.value}}function ts(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(!o)continue;const r=o.localName??o.name;(o.namespaceURI?t.hasAttributeNS(o.namespaceURI,r):t.hasAttribute(o.name))||(o.namespaceURI?t.setAttributeNS(o.namespaceURI,o.name,o.value):t.setAttribute(o.name,o.value))}}function ns(e){let t="";for(const n of Ji(e)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"===n.namespaceURI){if("t"===Qi(n)){t+=n.textContent??"";continue}if("tab"===Qi(n)){t+="\t";continue}if("br"===Qi(n)||"cr"===Qi(n)){t+="\n";continue}}t+=ns(n)}return t}function os(e){return Ji(e).filter(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&"p"===Qi(e))}function rs(e){return os(e).map(ns).join("\n").trim()}function as(e){const t=(new Ci.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"comments"===Qi(t)?t:void 0}function is(e,t){const n=es(os(t)[0]??t,"paraId");for(;t.firstChild;)t.removeChild(t.firstChild);for(let r=0;r<e.childNodes.length;r+=1){const n=e.childNodes[r];n&&t.appendChild(n.cloneNode(!0))}const o=os(t)[0];n&&o&&o.setAttributeNS(Go,"w14:paraId",n)}function ss(e,t){const n=os(e),o=os(t);n[0]&&o[0]&&Mr(n[0],o[0]);const r=new Set(Ji(t).filter(e=>e.namespaceURI!==xr).map(e=>`${e.namespaceURI??""}\0${Qi(e)}`));for(const a of Ji(e)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"===a.namespaceURI)continue;const e=`${a.namespaceURI??""}\0${Qi(a)}`;r.has(e)||(t.appendChild(a.cloneNode(!0)),r.add(e))}}async function ls(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),o=t.file(Zi);if(!n||!o)return!1;const r=await o.async("string"),a=function(e,t){const n=as(e),o=as(t);if(!n||!o)return t;const r=/* @__PURE__ */new Map;for(const i of Ji(o)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==i.namespaceURI||"comment"!==Qi(i))continue;const e=es(i,"id");void 0!==e&&r.set(e,i)}let a=!1;for(const i of Ji(n)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==i.namespaceURI||"comment"!==Qi(i))continue;const e=es(i,"id"),t=void 0!==e?r.get(e):void 0;if(!t)continue;const n=(new Ci.XMLSerializer).serializeToString(t);ts(i,t),rs(i)===rs(t)?is(i,t):ss(i,t),(new Ci.XMLSerializer).serializeToString(t)!==n&&(a=!0)}return a?(new Ci.XMLSerializer).serializeToString(o.ownerDocument):t}(n,r);return a!==r&&(t.file(Zi,a),!0)}var cs="http://schemas.microsoft.com/office/word/2012/wordml",ds="word/commentsExtended.xml";function us(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}function ps(e){return e.localName??e.tagName}function gs(e){return`${e.namespaceURI??""}\0${ps(e)}`}function fs(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(o?.localName===t)return o.value}}function ms(e,t,n){t.namespaceURI?e.setAttributeNS(t.namespaceURI,t.name,n):e.setAttribute(t.name,n)}function hs(e,t){const n=e.parts[e.mainDocumentPart]?.relationships?.find(e=>"External"!==e.targetMode&&e.type.endsWith(t)&&Boolean(e.resolvedTarget)),o=n?.resolvedTarget?e.parts[n.resolvedTarget]:void 0;return"xml"===o?.kind?o.data:void 0}function bs(e){const t=/* @__PURE__ */new Map,n=(new Ci.DOMParser).parseFromString(e,"application/xml").documentElement;if(!n)return t;for(const o of Array.from(n.getElementsByTagNameNS(xr,"comment"))){const e=fs(o,"id"),n=o.getElementsByTagNameNS(xr,"p").item(0),r=n?fs(n,"paraId"):void 0;void 0!==e&&r&&t.set(e,r)}return t}function ys(e){const t=(new Ci.DOMParser).parseFromString(e,"application/xml").documentElement;return t?.namespaceURI===cs&&"commentsEx"===ps(t)?t:void 0}function vs(e,t,n){for(let r=0;r<e.attributes.length;r+=1){const o=e.attributes.item(r);if(!o)continue;const a=o.localName??o.name;"paraId"!==a&&((o.namespaceURI?t.hasAttributeNS(o.namespaceURI,a):t.hasAttribute(o.name))||ms(t,o,"paraIdParent"===a?n.get(o.value)??o.value:o.value))}const o=new Set(us(t).map(gs));for(const r of us(e))o.has(gs(r))||t.appendChild(r.cloneNode(!0))}function xs(e,t,n,o){const r=ys(t),a=ys(o);if(!r||!a)return o;!function(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(!o)continue;const r=o.localName??o.name;(o.namespaceURI?t.hasAttributeNS(o.namespaceURI,r):t.hasAttribute(o.name))||ms(t,o,o.value)}}(r,a);const i=bs(e),s=bs(n),l=/* @__PURE__ */new Map;for(const[p,g]of i){const e=s.get(p);e&&l.set(g,e)}const c=function(e){const t=/* @__PURE__ */new Map;for(const n of us(e)){if(n.namespaceURI!==cs||"commentEx"!==ps(n))continue;const e=fs(n,"paraId");e&&t.set(e,n)}return t}(a),d=us(r),u=new Set(us(a).filter(e=>!(e.namespaceURI===cs&&"commentEx"===ps(e))).map(gs));for(const p of d){if(p.namespaceURI===cs&&"commentEx"===ps(p)){const e=fs(p,"paraId"),t=e?l.get(e):void 0,n=t?c.get(t):void 0;n&&vs(p,n,l);continue}u.has(gs(p))||(a.appendChild(p.cloneNode(!0)),u.add(gs(p)))}return(new Ci.XMLSerializer).serializeToString(a.ownerDocument)}var ws="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function Ss(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}function Is(e){return e.localName??e.tagName}function Cs(e){return`${e.namespaceURI??""}\0${Is(e)}`}function Ts(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(o?.localName===t)return o.value}}function ks(e,t){return Ss(e).find(e=>e.namespaceURI===ws&&Is(e)===t)}function Ps(e,t){return e.filter(e=>e.namespaceURI===ws&&t.has(Is(e)))}function Rs(e){if(e.namespaceURI!==ws)return;const t=Is(e);if("p"===t){const t=Ts(e,"paraId");return t?`p:${t}`:void 0}if("sdt"===t){const t=ks(e,"sdtPr"),n=t?ks(t,"id"):void 0,o=n?Ts(n,"val"):void 0;return o?`sdt:${o}`:void 0}}function Bs(e,t,n){const o=(new Ci.DOMParser).parseFromString(e,"application/xml"),r=(new Ci.DOMParser).parseFromString(t,"application/xml"),a=o.documentElement,i=r.documentElement;if(!a||!i||a.namespaceURI!==ws||i.namespaceURI!==ws||Is(a)!==n||Is(i)!==n)return t;!function(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(!o)continue;const r=o.localName??o.name;(o.namespaceURI?t.hasAttributeNS(o.namespaceURI,r):t.hasAttribute(o.name))||(o.namespaceURI?t.setAttributeNS(o.namespaceURI,o.name,o.value):t.setAttribute(o.name,o.value))}}(a,i);const s=Ss(a),l=Ss(i),c=new Set(l.map(Cs));return s.forEach((e,t)=>{if(e.namespaceURI===ws||c.has(Cs(e)))return;const n=s.slice(t+1).map(e=>l.find(t=>Cs(t)===Cs(e))).find(e=>Boolean(e));i.insertBefore(e.cloneNode(!0),n??null)}),(new Ci.XMLSerializer).serializeToString(r)}function Ms(e,t,n,o=/* @__PURE__ */new Set(["p","tbl","sdt"])){const r=Bs(e,t,n),a=(new Ci.DOMParser).parseFromString(e,"application/xml"),i=(new Ci.DOMParser).parseFromString(r,"application/xml"),s=a.documentElement,l=i.documentElement;if(!s||!l||s.namespaceURI!==ws||l.namespaceURI!==ws||Is(s)!==n||Is(l)!==n)return r;const c=Ss(s),d=Ss(l),u=function(e,t,n){const o=Ps(e,n),r=Ps(t,n);return o.length===r.length&&o.every((e,t)=>Is(e)===Is(r[t]))}(c,d,o),p=/* @__PURE__ */new Map;return c.forEach((e,t)=>{if(e.namespaceURI!==ws||o.has(Is(e)))return;const n=Cs(e),r=p.get(n)??0;if(p.set(n,r+1),Ss(l).filter(e=>Cs(e)===n)[r])return;const a=function(e,t,n,o,r){const a=e.slice(t+1).find(e=>e.namespaceURI===ws&&o.has(Is(e)));if(!a)return;const i=Rs(a);if(i){const e=Ps(n,o).find(e=>Rs(e)===i);if(e)return e}if(!r)return;const s=Ps(e,o),l=Ps(n,o),c=s.indexOf(a);return c>=0?l[c]:void 0}(c,t,d,o,u);(a||u)&&l.insertBefore(e.cloneNode(!0),a??null)}),(new Ci.XMLSerializer).serializeToString(i)}var Os="word/document.xml",As=/* @__PURE__ */new Set(["p","tbl","sdt","sectPr"]);function Fs(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}function Ds(e){return e.localName??e.tagName}function Es(e){return`${e.namespaceURI??""}\0${Ds(e)}`}function Ls(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(o?.localName===t)return o.value}}function Ns(e,t){return Fs(e).find(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&Ds(e)===t)}function zs(e){return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&As.has(Ds(e))}function $s(e){return e.filter(zs)}function Hs(e){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==e.namespaceURI)return;const t=Ds(e);if("p"===t){const t=Ls(e,"paraId");return t?`p:${t}`:void 0}if("sdt"===t){const t=Ns(e,"sdtPr"),n=t?Ls(Ns(t,"id")??t,"val"):void 0;return n?`sdt:${n}`:void 0}return"sectPr"===t?"sectPr:final":void 0}function Ws(e,t){const n=(new Ci.DOMParser).parseFromString(e,"application/xml"),o=(new Ci.DOMParser).parseFromString(t,"application/xml"),r=n.documentElement,a=o.documentElement;if(!r||!a||"http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==r.namespaceURI||"http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==a.namespaceURI||"document"!==Ds(r)||"document"!==Ds(a))return t;!function(e,t){const n=Fs(e),o=Ns(t,"body");if(!o)return;let r=o;const a=n.filter(e=>!("http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&"body"===Ds(e))),i=/* @__PURE__ */new Set;for(let s=a.length-1;s>=0;s-=1){const e=a[s],n=Fs(t).find(t=>!i.has(t)&&Es(t)===Es(e)),o=n??e.cloneNode(!0);n&&i.add(n),t.insertBefore(o,r),r=o}}(r,a);const i=Ns(r,"body"),s=Ns(a,"body");if(!i||!s)return t;!function(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(!o)continue;const r=o.localName??o.name;(o.namespaceURI?t.hasAttributeNS(o.namespaceURI,r):t.hasAttribute(o.name))||(o.namespaceURI?t.setAttributeNS(o.namespaceURI,o.name,o.value):t.setAttribute(o.name,o.value))}}(i,s);const l=Fs(i),c=Fs(s),d=function(e,t){const n=$s(e),o=$s(t);return n.length===o.length&&n.every((e,t)=>Ds(e)===Ds(o[t]))}(l,c),u=/* @__PURE__ */new Map;return l.forEach((e,t)=>{if(zs(e))return;const n=Es(e),o=u.get(n)??0;if(u.set(n,o+1),Fs(s).filter(e=>Es(e)===n)[o])return;const r=function(e,t,n){const o=e.slice(t+1).find(zs);if(!o)return;const r=Hs(o);return r?$s(n).find(e=>Hs(e)===r):void 0}(l,t,c),a=d?function(e,t,n){const o=$s(e),r=$s(n),a=e.slice(t+1).find(zs);if(a){const e=o.indexOf(a);if(e>=0)return r[e]}}(l,t,c):void 0,i=r??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"===Ds(e))}(c)??null)}),(new Ci.XMLSerializer).serializeToString(o)}async function Us(e,t){const n=e.parts[e.mainDocumentPart],o=t.file(Os);if("xml"!==n?.kind||!o)return!1;const r=await o.async("string"),a=function(e,t){return Ws(e,Bs(e,t,"document"))}(n.data,r);return a!==r&&(t.file(Os,a),!0)}function js(e){return e.getAttributeNS("http://schemas.openxmlformats.org/officeDocument/2006/relationships","id")||void 0}function Vs(e){return e.getAttributeNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","type")||"default"}function Ks(e,t){const n=e.getAttributeNodeNS(Zo,"id");return!(!n||n.value===t)&&(e.setAttributeNS(Zo,n.name,t),!0)}var _s="word/document.xml",Xs="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function Gs(e){const t=(new Ci.DOMParser).parseFromString(e,"application/xml");return Array.from(t.getElementsByTagNameNS(Xs,"sectPr")).filter(e=>Boolean(e)&&"sectPrChange"!==e.parentNode?.localName)}function qs(e){const t=[];return Gs(e).forEach((e,n)=>{const o=/* @__PURE__ */new Map;for(const r of function(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}(e)){const e=r.namespaceURI===Xs&&"headerReference"===r.localName?"header":r.namespaceURI===Xs&&"footerReference"===r.localName?"footer":void 0;if(!e)continue;const a=js(r);if(!a)continue;const i=Vs(r),s=`${e}:${i}`,l=o.get(s)??0;o.set(s,l+1),t.push({key:`${n}:${e}:${i}:${l}`,kind:e,relationshipId:a})}}),t}function Ys(e){return new Map(e.map(e=>[e.id,e]))}async function Zs(e,t){const n=e.parts[e.mainDocumentPart],o=await(t.file(_s)?.async("string"));if("xml"!==n?.kind||!o)return!1;const r=Gs(n.data),a=Gs(o);if(r.length!==a.length)return!1;const i=qs(n.data),s=qs(o),l=new Map(i.map(e=>[e.key,e])),c=Ys(n.relationships??[]),d=Ys(await async function(e){const t=await(e.file(function(e){const t=e.lastIndexOf("/"),n=t>=0?e.slice(0,t):"",o=t>=0?e.slice(t+1):e;return n?`${n}/_rels/${o}.rels`:`_rels/${o}.rels`}(_s))?.async("string"));return lr(_s,dr(t))}(t));let u=!1;for(const p of s){const n=l.get(p.key);if(!n||n.kind!==p.kind)continue;const o=c.get(n.relationshipId),r=d.get(p.relationshipId);if("External"===o?.targetMode||"External"===r?.targetMode||!o?.resolvedTarget||!r?.resolvedTarget)continue;const a=e.parts[o.resolvedTarget];if("xml"!==a?.kind)continue;const i=r.resolvedTarget,s=await(t.file(i)?.async("string"));if(!s)continue;const g="header"===p.kind?"hdr":"ftr",f=Ms(a.data,s,g);f!==s&&(t.file(i,f),u=!0)}return u}var Js="word/document.xml",Qs={"/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"},el=["/officeDocument",...Object.keys(Qs)];function tl(e){return[e.type,e.target,e.targetMode??"Internal"].join("\0")}function nl(e){const t=e.lastIndexOf("/"),n=t>=0?e.slice(0,t):"",o=t>=0?e.slice(t+1):e;return n?`${n}/_rels/${o}.rels`:`_rels/${o}.rels`}function ol(e){for(const[t,n]of Object.entries(Qs))if(e.type.endsWith(t))return n}function rl(e,t){if("[Content_Types].xml"===e||"_rels/.rels"===e)return e;const n=Ar(e);return void 0===n?t.get(e)??e:null===n?e:nl(t.get(n)??n)}function al(e,t){for(const[n,o]of t)if(o===e)return n;return e}function il(e,t){if(null===e)return t;const n=function(e){const t=e.lastIndexOf("/");return t<0?[]:e.slice(0,t).split("/")}(e),o=t.split("/");let r=0;for(;r<n.length&&r<o.length&&n[r]===o[r];)r+=1;return[...Array.from({length:n.length-r},()=>".."),...o.slice(r)].join("/")}function sl(e,t){const n=e.parts[t];return"xml"===n?.kind?dr(n.data):[]}function ll(e,t){const n=null===t?e.rootRelationships.length>0?e.rootRelationships:sl(e,or):e.parts[t]?.relationships??sl(e,nl(t));return lr(t,n)}function cl(e,t,n){return ll(e,t).filter(e=>"External"===e.targetMode||!e.resolvedTarget||!n.has(e.resolvedTarget))}function dl(e,t,n,o,r){return e.map(e=>{if("External"===e.targetMode)return e;const a=(i=e.type,el.find(e=>i.endsWith(e)));var i;const s=a?t.find(e=>"External"!==e.targetMode&&e.type.endsWith(a)):void 0,l=lr(n,[e])[0]?.resolvedTarget,c=s?.resolvedTarget??(l?r.get(l)??l:void 0);return c?{...e,...s?{id:s.id,type:s.type}:{},target:il(o,c),targetMode:"Internal",resolvedTarget:c}:e})}function ul(e,t,n){const o=[...t],r=new Map(t.map(e=>[e.id,e]));for(const a of e){const e=r.get(a.id);if(e){if(tl(e)===tl(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.`)}o.push(a)}return o}function pl(e,t,n){const o=t.parts[n];o&&("base64"===o.encoding?e.file(n,o.data,{base64:!0}):e.file(n,o.data))}function gl(e,t,n,o){const r=e.rebuiltPartHashes?.[t];return Boolean(r&&e.parts[n]&&r===qr(o))}async function fl(e,t){const n=e.sourcePackage;if(!n)return t;const o=await Wi.default.loadAsync(t),r=new Set(Object.entries(o.files).filter(([,e])=>!e.dir).map(([e])=>Lr(e))),a=function(e){const t=/* @__PURE__ */new Map;t.set(Js,e.mainDocumentPart);const n=e.parts[e.mainDocumentPart];for(const o of n?.relationships??[]){if("External"===o.targetMode||!o.resolvedTarget)continue;const e=ol(o);e&&t.set(e,o.resolvedTarget)}return t}(n),i=function(e,t,n){const o=/* @__PURE__ */new Set;for(const[r,a]of t)r!==Js&&e.rebuiltPartHashes?.[r]&&!n.has(r)&&e.parts[a]&&o.add(a);return o}(n,a,r),s=new Wi.default;for(const c of Object.keys(n.parts))pl(s,n,c);for(const c of i)s.remove(c),s.remove(nl(c));!function(e,t,n,o,r){if(0!==r.size)for(const a of Object.keys(t.parts)){const i=Ar(a);if(null==i)continue;const s=ll(t,i),l=s.filter(e=>"External"===e.targetMode||!e.resolvedTarget||!r.has(e.resolvedTarget));if(l.length===s.length)continue;const c=al(i,n);o.has(nl(c))||(0===l.length?e.remove(a):e.file(a,zr(l)))}}(s,n,a,r,i);let l=null;for(const[c,d]of Object.entries(o.files)){if(d.dir)continue;const e=Lr(c);if("[Content_Types].xml"===e){l=await d.async("string");continue}const t=rl(e,a),o=Ar(e);if(void 0!==o){const e=o,r=null===e?null:a.get(e)??e,l=cl(n,r,i),c=ul(l,dl(dr(await d.async("string")),l,e,r,a),t);s.file(t,zr(c));continue}const r=await d.async("uint8array");gl(n,e,t,r)||s.file(t,r)}return l&&s.file(Vo,function(e,t,n,o){const r=tr(t),a={};for(const[s,l]of Object.entries(r.overrides))a[n.get(s)??s]=l;const i=Object.fromEntries(Object.entries(e.overrides).filter(([e])=>!o.has(e)));return Wr({defaults:{...e.defaults,...r.defaults},overrides:{...i,...a}})}(n.contentTypes,l,a,i)),s.generateAsync({type:"arraybuffer"})}var ml="word/document.xml",hl=["first","even","default"];function bl(e){const t=e.lastIndexOf("/"),n=t>=0?e.slice(0,t):"",o=t>=0?e.slice(t+1):e;return n?`${n}/_rels/${o}.rels`:`_rels/${o}.rels`}function yl(e,t){const n=function(e){const t=e.lastIndexOf("/");return t<0?[]:e.slice(0,t).split("/")}(e),o=t.split("/");let r=0;for(;r<n.length&&r<o.length&&n[r]===o[r];)r+=1;return[...Array.from({length:n.length-r},()=>".."),...o.slice(r)].join("/")}function vl(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}function xl(e,t){const n=[],o=e=>{for(const r of vl(e))"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===r.namespaceURI&&r.localName===t&&n.push(r),o(r)};return o(e),n}function wl(e){const t=(new Ci.DOMParser).parseFromString(e,"application/xml"),n=[],o=xl(t,"sectPr").filter(e=>"sectPrChange"!==e.parentNode?.localName);return o.forEach((e,t)=>{const o=/* @__PURE__ */new Map;for(const r of vl(e)){const e="http://schemas.openxmlformats.org/wordprocessingml/2006/main"===r.namespaceURI&&"headerReference"===r.localName?"header":"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===r.namespaceURI&&"footerReference"===r.localName?"footer":void 0;if(!e)continue;const a=js(r);if(!a)continue;const i=Vs(r),s=`${e}:${i}`,l=o.get(s)??0;o.set(s,l+1),n.push({key:`${t}:${e}:${i}:${l}`,sectionIndex:t,kind:e,type:i,occurrence:l,relationshipId:a})}}),{references:n,sectionCount:o.length}}function Sl(e,t){const n=e.parts[t];return"xml"===n?.kind?n.data:void 0}function Il(e,t){const n=e.parts[t]?.relationships??dr(Sl(e,bl(t)));return lr(t,n)}function Cl(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 o="header"===e.kind?"/header":"/footer";return t.type.endsWith(o)?[{...e,relationship:t,partPath:t.resolvedTarget}]:[]})}async function Tl(e,t){const n=Sl(e,e.mainDocumentPart),o=await(t.file(ml)?.async("string"));if(!n||!o)return{matches:[],deletedSourcePartPaths:/* @__PURE__ */new Set,sourceRelationshipByCurrentId:/* @__PURE__ */new Map};const r=wl(n),a=wl(o),i=Cl(r.references,Il(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=hl.indexOf(e.type),o=hl.indexOf(t.type),r=n<0?99:n,a=o<0?99:o;return r!==a?r-a:e.type!==t.type?e.type.localeCompare(t.type):e.occurrence-t.occurrence});let n=1,o=1;for(const r of t)"header"===r.kind?(r.baselinePath=`word/header${n}.xml`,n+=1):(r.baselinePath=`word/footer${o}.xml`,o+=1)}(i);const s=Cl(a.references,await async function(e,t){const n=await(e.file(bl(t))?.async("string"));return lr(t,dr(n))}(t,ml)),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:r.sectionCount===a.sectionCount?new Set(i.map(e=>e.partPath).filter(e=>!d.has(e))):/* @__PURE__ */new Set,sourceRelationshipByCurrentId:u}}function kl(e){return[e.type,e.target,e.targetMode??"Internal"].join("\0")}async function Pl(e,t,n,o){if(!o)return!1;const r=t.rebuiltPartHashes?.[o],a=e.file(n);return a?!!r&&r===qr(await a.async("uint8array")):void 0===r}async function Rl(e,t,n,o){for(const r of n)if(!(await Pl(e,t,o?bl(r.current.partPath):r.current.partPath,r.source.baselinePath?o?bl(r.source.baselinePath):r.source.baselinePath:void 0)))return!1;return!0}async function Bl(e,t,n){if(t.length<2)return;const o=/* @__PURE__ */new Set;for(const r of t){const t=n?bl(r.current.partPath):r.current.partPath,a=await(e.file(t)?.async("uint8array"));o.add(a?qr(a):"<missing>")}if(o.size>1)throw new Error(`Cannot safely preserve shared header/footer part ${t[0].source.partPath}: its section projections diverged after editing.`)}async function Ml(e,t,n){const o=await(e.file(ml)?.async("string"));if(o){const r=t.rebuiltPartHashes?.[ml],a=qr((new TextEncoder).encode(o));if(!r||r!==a){const t=function(e,t){const n=(new Ci.DOMParser).parseFromString(e,"application/xml");let o=!1;for(const r of["headerReference","footerReference"])for(const e of xl(n,r)){const n=js(e),r=n?t.get(n):void 0;r&&(o=Ks(e,r.id)||o)}return o?(new Ci.XMLSerializer).serializeToString(n):void 0}(o,n.sourceRelationshipByCurrentId);t&&e.file(ml,t)}}const r=bl(ml),a=dr(await(e.file(r)?.async("string"))).map(e=>{const t=n.sourceRelationshipByCurrentId.get(e.id);return t?.resolvedTarget?{...t,target:yl(ml,t.resolvedTarget),targetMode:"Internal"}:e});e.file(r,zr(function(e,t){const n=[],o=/* @__PURE__ */new Map;for(const r of e){const e=o.get(r.id);if(e){if(kl(e)===kl(r))continue;throw new Error(`Cannot safely preserve ${t}: relationship id ${r.id} is used for different targets.`)}o.set(r.id,r),n.push(r)}return n}(a,r)))}async function Ol(e,t,n){const o=n[0],r=o.source.partPath;if(!(await Rl(e,t,n,!1))){await Bl(e,n,!1);const t=await(e.file(o.current.partPath)?.async("uint8array"));if(!t)throw new Error(`Cannot preserve ${r}: rebuilt header/footer part is missing.`);e.file(r,t)}for(const i of n)i.current.partPath!==r&&e.remove(i.current.partPath);const a=bl(r);if(!(await Rl(e,t,n,!0))){await Bl(e,n,!0);const t=bl(o.current.partPath),i=await(e.file(t)?.async("string"));i&&e.file(a,zr(function(e,t,n){return e.map(e=>{if("External"===e.targetMode)return e;const o=lr(t,[e])[0]?.resolvedTarget;return o?{...e,target:yl(n,o),targetMode:"Internal",resolvedTarget:o}:e})}(dr(i),o.current.partPath,r)))}for(const i of n){const t=bl(i.current.partPath);t!==a&&e.remove(t)}}async function Al(e,t,n){for(const o 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 Ol(e,t,o)}async function Fl(e,t){const n=e.sourcePackage;if(!n)return t;const o=await Wi.default.loadAsync(t),r=await Tl(n,o);r.matches.length>0&&(await Ml(o,n,r),await Al(o,n,r),await async function(e,t){const n=await(e.file(Vo)?.async("string"));if(!n)return;const o=tr(n);for(const r of t.matches){const e=o.overrides[r.current.partPath];e&&(o.overrides[r.source.partPath]=e),r.current.partPath!==r.source.partPath&&delete o.overrides[r.current.partPath]}e.file(Vo,Wr(o))}(o,r));const a=r.matches.length>0?await o.generateAsync({type:"arraybuffer"}):t;return fl(function(e,t){const n=e.sourcePackage;if(!n||0===t.size)return e;const o={defaults:{...n.contentTypes.defaults},overrides:Object.fromEntries(Object.entries(n.contentTypes.overrides).filter(([e])=>!t.has(e)))},r={...n.parts};for(const d of t)delete r[d],delete r[bl(d)];const a=r[n.mainDocumentPart],i=Il(n,n.mainDocumentPart).filter(e=>"External"===e.targetMode||!e.resolvedTarget||!t.has(e.resolvedTarget));a&&(r[n.mainDocumentPart]={...a,relationships:i});const s=bl(n.mainDocumentPart),l=r[s];l&&(r[s]={...l,data:zr(i)});const c=r[Vo];return c&&(r[Vo]={...c,data:Wr(o)}),{...e,sourcePackage:{...n,contentTypes:o,parts:r}}}(e,r.deletedSourcePartPaths),a)}var Dl=[{kind:"footnote",relationshipSuffix:"/footnotes",rebuiltPath:"word/footnotes.xml",rootName:"footnotes",entryName:"footnote"},{kind:"endnote",relationshipSuffix:"/endnotes",rebuiltPath:"word/endnotes.xml",rootName:"endnotes",entryName:"endnote"}],El=/* @__PURE__ */new Set(["p","tbl"]),Ll=/* @__PURE__ */new Set(["separator","continuationSeparator","continuationNotice"]);function Nl(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}function zl(e){return e.localName??e.tagName}function $l(e){return`${e.namespaceURI??""}\0${zl(e)}`}function Hl(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(o?.localName===t)return o.value}}function Wl(e,t){const n=e.parts[e.mainDocumentPart]?.relationships?.find(e=>"External"!==e.targetMode&&e.type.endsWith(t)&&Boolean(e.resolvedTarget)),o=n?.resolvedTarget?e.parts[n.resolvedTarget]:void 0;return"xml"===o?.kind?o.data:void 0}function Ul(e,t){const n=(new Ci.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===n?.namespaceURI&&zl(n)===t?n:void 0}function jl(e){const t=Hl(e,"type");if(t&&Ll.has(t))return`type:${t}`;const n=Hl(e,"id");return n?`id:${n}`:void 0}function Vl(e){return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&El.has(zl(e))}function Kl(e){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==e.namespaceURI||"p"!==zl(e))return;const t=Hl(e,"paraId");return t?`p:${t}`:void 0}function _l(e,t){!function(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(!o)continue;const r=o.localName??o.name;(o.namespaceURI?t.hasAttributeNS(o.namespaceURI,r):t.hasAttribute(o.name))||(o.namespaceURI?t.setAttributeNS(o.namespaceURI,o.name,o.value):t.setAttribute(o.name,o.value))}}(e,t);const n=Nl(e),o=Nl(t),r=function(e,t){const n=e.filter(Vl),o=t.filter(Vl);return n.length===o.length&&n.every((e,t)=>zl(e)===zl(o[t]))}(n,o),a=/* @__PURE__ */new Map;n.forEach((e,i)=>{if(Vl(e))return;const s=$l(e),l=a.get(s)??0;if(a.set(s,l+1),Nl(t).filter(e=>$l(e)===s)[l])return;const c=function(e,t,n,o){const r=e.slice(t+1).find(Vl);if(!r)return;const a=Kl(r);if(a){const e=n.filter(Vl).find(e=>Kl(e)===a);if(e)return e}if(!o)return;const i=e.filter(Vl),s=n.filter(Vl),l=i.indexOf(r);return l>=0?s[l]:void 0}(n,i,o,r);("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==e.namespaceURI||c||r)&&t.insertBefore(e.cloneNode(!0),c??null)})}function Xl(e,t,n,o){const r=Ul(t,o.rootName),a=Ul(n,o.rootName);if(!r||!a)return n;const i=Nl(r).filter(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&zl(e)===o.entryName),s=/* @__PURE__ */new Map;for(const c of Nl(a)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==c.namespaceURI||zl(c)!==o.entryName)continue;const e=jl(c);e&&s.set(e,c)}const l=function(e,t){const n="footnote"===t?e.footnotes?.items:e.endnotes?.items,o=/* @__PURE__ */new Set;for(const r of Object.values(n??{}))void 0!==r.docxId&&Number.isSafeInteger(r.docxId)&&r.docxId>=1&&o.add(String(r.docxId));return o}(e,o.kind);for(const c of i){const e=jl(c);if(!e)continue;const t=s.get(e),n=Hl(c,"type");if(t){n&&Ll.has(n)?a.replaceChild(c.cloneNode(!0),t):_l(c,t);continue}if("continuationNotice"===n){a.appendChild(c.cloneNode(!0));continue}const o=Hl(c,"id");o&&l.has(o)&&a.appendChild(c.cloneNode(!0))}return(new Ci.XMLSerializer).serializeToString(a.ownerDocument)}var Gl="http://schemas.openxmlformats.org/wordprocessingml/2006/main",ql="word/numbering.xml";function Yl(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}function Zl(e){return e.localName??e.tagName}function Jl(e){return`${e.namespaceURI??""}\0${Zl(e)}`}function Ql(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(o?.localName===t)return o.value}}function ec(e,t,n){for(let o=0;o<e.attributes.length;o+=1){const r=e.attributes.item(o);if(r?.localName===t)return void e.setAttribute(r.name,n)}e.setAttributeNS(Gl,`w:${t}`,n)}function tc(e,t){return Yl(e).find(e=>e.namespaceURI===Gl&&Zl(e)===t)}function nc(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(!o)continue;const r=o.localName??o.name;(o.namespaceURI?t.hasAttributeNS(o.namespaceURI,r):t.hasAttribute(o.name))||(o.namespaceURI?t.setAttributeNS(o.namespaceURI,o.name,o.value):t.setAttribute(o.name,o.value))}}function oc(e,t){const n=new Set(Yl(t).map(Jl));for(const o of Yl(e))o.namespaceURI===Gl||n.has(Jl(o))||t.appendChild(o.cloneNode(!0))}function rc(e,t,n,o,r){const a=e.slice(t+1).map(r).find(e=>Boolean(e));o.insertBefore(n.cloneNode(!0),a??null)}var ac=/* @__PURE__ */new Set(["start","numFmt","lvlRestart","pStyle","lvlText","lvlJc","suff","isLgl"]);function ic(e,t){nc(e,t);const n=Yl(e),o=new Map(Yl(t).map(e=>[Jl(e),e]));n.forEach((e,r)=>{const a=Jl(e),i=o.get(a),s=Zl(e);if(i)return nc(e,i),void(e.namespaceURI===Gl&&"rPr"===s?function(e,t){nc(e,t);const n=Yl(e),o=new Map(Yl(t).map(e=>[Jl(e),e]));n.forEach((e,r)=>{const a=Jl(e),i=o.get(a);if(i)return nc(e,i),void oc(e,i);e.namespaceURI===Gl&&"rFonts"===Zl(e)||rc(n,r,e,t,e=>o.get(Jl(e)))})}(e,i):oc(e,i));if(e.namespaceURI!==Gl||!ac.has(s)){if(e.namespaceURI===Gl&&"rPr"===s){const n=function(e){const t=e.cloneNode(!1);let n=!1;for(const o of Yl(e))o.namespaceURI===Gl&&"rFonts"===Zl(o)||(t.appendChild(o.cloneNode(!0)),n=!0);return n?t:void 0}(e);return void(n&&t.appendChild(n))}rc(n,r,e,t,e=>o.get(Jl(e)))}})}function sc(e){return function(e){return e.namespaceURI===Gl&&"lvl"===Zl(e)?`${Jl(e)}\0${Ql(e,"ilvl")??"0"}`:Jl(e)}(e)}function lc(e,t,n){const o=tc(t,"abstractNumId"),r=o?Ql(o,"val"):void 0;if(!r)return;const a=Yl(e).find(e=>e.namespaceURI===Gl&&"abstractNum"===Zl(e)&&Ql(e,"abstractNumId")===r);return a?Yl(a).find(e=>e.namespaceURI===Gl&&"lvl"===Zl(e)&&(Ql(e,"ilvl")??"0")===n):void 0}function cc(e,t){const n=t.cloneNode(!0);ic(e,n);const o=tc(e,"pPr"),r=tc(n,"pPr");return o?r?n.replaceChild(o.cloneNode(!0),r):n.appendChild(o.cloneNode(!0)):r&&n.removeChild(r),n}function dc(e,t){if(!t)return e.cloneNode(!0);const n=e.cloneNode(!1),o=Ql(tc(t,"start")??t,"val")??"1";for(const r of Yl(e)){const e=Zl(r);if(r.namespaceURI===Gl&&"startOverride"===e){const e=r.cloneNode(!0);ec(e,"val",o),n.appendChild(e);continue}r.namespaceURI!==Gl||"lvl"!==e?n.appendChild(r.cloneNode(!0)):n.appendChild(cc(r,t))}return n}function uc(e){if(e.namespaceURI!==Gl)return Jl(e);const t=Zl(e);return"abstractNum"===t?`${Jl(e)}\0${Ql(e,"abstractNumId")??""}`:"num"===t?`${Jl(e)}\0${Ql(e,"numId")??""}`:Jl(e)}function pc(e,t){const n=function(e,t){const n=(new Ci.DOMParser).parseFromString(e,"application/xml").documentElement,o=(new Ci.DOMParser).parseFromString(t,"application/xml").documentElement;if(n&&o&&n.namespaceURI===Gl&&o.namespaceURI===Gl&&"numbering"===Zl(n)&&"numbering"===Zl(o))return{sourceRoot:n,rebuiltRoot:o}}(e,t);if(!n)return t;const{sourceRoot:o,rebuiltRoot:r}=n;nc(o,r);const a=Yl(o),i=new Map(Yl(r).map(e=>[uc(e),e]));return a.forEach((e,t)=>{const n=uc(e),o=i.get(n),s=Zl(e);if(o)return nc(e,o),void(e.namespaceURI===Gl&&"abstractNum"===s?function(e,t){nc(e,t);const n=Yl(e),o=new Map(Yl(t).map(e=>[sc(e),e]));n.forEach((e,r)=>{const a=sc(e),i=o.get(a);if(i)return nc(e,i),void(e.namespaceURI===Gl&&"lvl"===Zl(e)?ic(e,i):oc(e,i));rc(n,r,e,t,e=>o.get(sc(e)))})}(e,o):e.namespaceURI===Gl&&"num"===s?function(e,t,n){nc(e,t);const o=tc(t,"abstractNumId"),r=/* @__PURE__ */new Map;for(const a of Yl(t))a.namespaceURI===Gl&&"lvlOverride"===Zl(a)&&r.set(Ql(a,"ilvl")??"0",a);for(const a of Yl(e)){const e=Zl(a);if(a.namespaceURI!==Gl||"abstractNumId"!==e){if(a.namespaceURI===Gl&&"lvlOverride"===e){const e=Ql(a,"ilvl")??"0",o=dc(a,lc(n,t,e)),i=r.get(e);i?t.replaceChild(o,i):t.appendChild(o),r.set(e,o);continue}a.namespaceURI===Gl||Yl(t).some(e=>Jl(e)===Jl(a))||t.appendChild(a.cloneNode(!0))}else o&&(nc(a,o),oc(a,o))}}(e,o,r):oc(e,o));rc(a,t,e,r,e=>i.get(uc(e)))}),(new Ci.XMLSerializer).serializeToString(r.ownerDocument)}async function gc(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),o=t.file(ql);if(!n||!o)return!1;const r=await o.async("string"),a=pc(n,r);return a!==r&&(t.file(ql,a),!0)}var fc=[{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 mc(e,t){const n=e.parts[e.mainDocumentPart]?.relationships?.find(e=>"External"!==e.targetMode&&e.type.endsWith(t)&&Boolean(e.resolvedTarget)),o=n?.resolvedTarget?e.parts[n.resolvedTarget]:void 0;return"xml"===o?.kind?o.data:void 0}var hc="http://schemas.openxmlformats.org/wordprocessingml/2006/main",bc=/* @__PURE__ */new Set(["headerReference","footerReference","type","pgSz","pgMar","pgNumType","cols","vAlign","bidi"]);function yc(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}function vc(e){return e.localName??e.tagName}function xc(e){return`${e.namespaceURI??""}\0${vc(e)}`}function wc(e){const t=[],n=e=>{for(const o of yc(e))o.namespaceURI===hc&&"sectPr"===vc(o)&&"sectPrChange"!==o.parentNode?.localName&&t.push(o),n(o)};return n(e),t}function Sc(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(!o)continue;const r=o.localName??o.name;(o.namespaceURI?t.hasAttributeNS(o.namespaceURI,r):t.hasAttribute(o.name))||(o.namespaceURI?t.setAttributeNS(o.namespaceURI,o.name,o.value):t.setAttribute(o.name,o.value))}}function Ic(e){return e.namespaceURI===hc&&bc.has(vc(e))}function Cc(e,t){const n=(new Ci.DOMParser).parseFromString(e,"application/xml"),o=(new Ci.DOMParser).parseFromString(t,"application/xml"),r=n.documentElement,a=o.documentElement;if(!r||!a)return t;const i=wc(n),s=wc(o);return 0===i.length||i.length!==s.length?t:(Sc(r,a),i.forEach((e,t)=>{!function(e,t){Sc(e,t);const n=yc(e),o=yc(t),r=/* @__PURE__ */new Map;for(const i of o){const e=xc(i),t=r.get(e);t?t.push(i):r.set(e,[i])}const a=/* @__PURE__ */new Map;for(let i=0;i<n.length;i+=1){const e=n[i],o=xc(e),s=a.get(o)??0;a.set(o,s+1);const l=r.get(o)?.[s];if(l){Sc(e,l);continue}if(Ic(e))continue;const c=n.slice(i+1).map(e=>r.get(xc(e))?.[0]).find(e=>Boolean(e));t.insertBefore(e.cloneNode(!0),c??null)}}(e,s[t])}),(new Ci.XMLSerializer).serializeToString(o))}var Tc="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function kc(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}function Pc(e){return e.localName??e.tagName}function Rc(e,t){const n=(new Ci.DOMParser).parseFromString(e,"application/xml").documentElement;return n?.namespaceURI===Tc&&Pc(n)===t?n:void 0}function Bc(e){return kc(e).length>0?(new Ci.XMLSerializer).serializeToString(e.ownerDocument):void 0}var Mc=/* @__PURE__ */new Set(["defaultTabStop","autoHyphenation","consecutiveHyphenLimit","hyphenationZone","doNotHyphenateCaps","evenAndOddHeaders"]),Oc=/* @__PURE__ */new Map([["compat",/* @__PURE__ */new Set(["allowSpaceOfSameStyleInTable"])],["footnotePr",/* @__PURE__ */new Set(["numFmt","numStart","numRestart"])],["endnotePr",/* @__PURE__ */new Set(["numFmt","numStart","numRestart"])]]);function Ac(e){const t=Rc(e,"settings");if(!t)return e;for(const n of[...kc(t)]){if(n.namespaceURI!==Tc)continue;const e=Pc(n);if(Mc.has(e)){t.removeChild(n);continue}const o=Oc.get(e);if(o){for(const e of[...kc(n)])e.namespaceURI===Tc&&o.has(Pc(e))&&n.removeChild(e);0===kc(n).length&&t.removeChild(n)}}return Bc(t)}function Fc(e){const t=Rc(e,"styles");if(!t)return e;for(const n of[...kc(t)])n.namespaceURI===Tc&&"style"===Pc(n)&&t.removeChild(n);return Bc(t)}function Dc(e){const t=Rc(e,"fonts");if(!t)return e;for(const n of[...kc(t)])n.namespaceURI===Tc&&"font"===Pc(n)&&t.removeChild(n);return Bc(t)}async function Ec(e,t,n){const o=e.file(t);if(!o)return!1;const r=await o.async("string"),a=n(r);return a!==r&&(void 0===a?e.remove(t):e.file(t,a),!0)}var Lc="word/styles.xml";function Nc(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}function zc(e){return e.localName??e.tagName}function $c(e){return`${e.namespaceURI??""}\0${zc(e)}`}function Hc(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(o?.localName===t)return o.value}}function Wc(e,t){return Nc(e).find(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&zc(e)===t)}function Uc(e){return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&"tblStylePr"===zc(e)?`${$c(e)}\0${Hc(e,"type")??""}`:$c(e)}function jc(e){const t=(new Ci.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"styles"===zc(t)?t:void 0}function Vc(e,t){const n=Wc(e,"pPr");if(!n)return!1;const o=Wc(t,"pPr"),r=new Ci.XMLSerializer,a=r.serializeToString(n),i=o?r.serializeToString(o):"",s=Jr(a,i);if(s===i)return!1;if(!s)return!!o&&(t.removeChild(o),!0);const l=function(e){if(!e)return;const t=(new Ci.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"pPr"===zc(t)?t:void 0}(s);if(!l)return!1;const c=l.cloneNode(!0);return o?t.replaceChild(c,o):function(e,t,n,o){const r=Nc(e),a=r.indexOf(n),i=Nc(t),s=new Map(i.map(e=>[Uc(e),e])),l=r.slice(a+1).map(e=>s.get(Uc(e))).find(e=>Boolean(e));t.insertBefore(o,l??null)}(e,t,n,c),!0}async function Kc(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),o=t.file(Lc);if(!n||!o)return!1;const r=await o.async("string"),a=function(e,t){const n=jc(e),o=jc(t);if(!n||!o)return t;const r=/* @__PURE__ */new Map;for(const i of Nc(o)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==i.namespaceURI||"style"!==zc(i))continue;const e=Hc(i,"styleId");e&&r.set(e,i)}let a=!1;for(const i of Nc(n)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==i.namespaceURI||"style"!==zc(i))continue;const e=Hc(i,"styleId"),t=e?r.get(e):void 0;t&&(a=Vc(i,t)||a)}return a?(new Ci.XMLSerializer).serializeToString(o.ownerDocument):t}(n,r);return a!==r&&(t.file(Lc,a),!0)}function _c(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}function Xc(e){return e.localName??e.tagName}function Gc(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 qc(e,t){const n=function(e){if(!e)return;const t=(new Ci.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"rPr"===Xc(t)?t:void 0}(e);if(!n)return t;const o=`<w:r xmlns:w="${xr}" xmlns:w14="${Go}">${t}<w:t/></w:r>`,r={id:"ooxml-style-rpr-source",kind:"text",text:""};xa(r,`<w:r xmlns:w="${xr}" xmlns:w14="${Go}">${e}<w:t/></w:r>`);const a=function(e){const t=(new Ci.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"r"===Xc(t)?t:void 0}(li(r,o));if(!a)return t;let i=_c(a).find(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&"rPr"===Xc(e));return!i&&Gc(n)&&(i=a.ownerDocument.createElementNS(xr,"w:rPr"),a.insertBefore(i,a.firstChild)),i?(Mr(n,i),0!==_c(i).length||Gc(i)?(new Ci.XMLSerializer).serializeToString(i):""):""}var Yc="word/styles.xml";function Zc(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}function Jc(e){return e.localName??e.tagName}function Qc(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(o?.localName===t)return o.value}}function ed(e,t){return Zc(e).find(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&Jc(e)===t)}function td(e){const t=(new Ci.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"styles"===Jc(t)?t:void 0}function nd(e,t){const n=ed(e,"rPr");if(!n)return!1;const o=ed(t,"rPr"),r=new Ci.XMLSerializer,a=r.serializeToString(n),i=o?r.serializeToString(o):"",s=qc(a,i);if(s===i)return!1;if(!s)return!!o&&(t.removeChild(o),!0);const l=function(e){if(!e)return;const t=(new Ci.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"rPr"===Jc(t)?t:void 0}(s);if(!l)return!1;const c=l.cloneNode(!0);return o?t.replaceChild(c,o):function(e,t,n,o){const r=Zc(e),a=r.indexOf(n),i=Zc(t),s=r.slice(a+1).map(e=>i.find(t=>t.namespaceURI===e.namespaceURI&&Jc(t)===Jc(e))).find(e=>Boolean(e));t.insertBefore(o,s??null)}(e,t,n,c),!0}async function od(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),o=t.file(Yc);if(!n||!o)return!1;const r=await o.async("string"),a=function(e,t){const n=td(e),o=td(t);if(!n||!o)return t;const r=/* @__PURE__ */new Map;for(const i of Zc(o)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==i.namespaceURI||"style"!==Jc(i))continue;const e=Qc(i,"styleId");e&&r.set(e,i)}let a=!1;for(const i of Zc(n)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==i.namespaceURI||"style"!==Jc(i))continue;const e=Qc(i,"styleId"),t=e?r.get(e):void 0;t&&(a=nd(i,t)||a)}return a?(new Ci.XMLSerializer).serializeToString(o.ownerDocument):t}(n,r);return a!==r&&(t.file(Yc,a),!0)}var rd="word/styles.xml",ad=/* @__PURE__ */new Set(["pPr","rPr","tblPr","trPr","tcPr"]);function id(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}function sd(e){return e.localName??e.tagName}function ld(e){return`${e.namespaceURI??""}\0${sd(e)}`}function cd(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(o?.localName===t)return o.value}}function dd(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(!o)continue;const r=o.localName??o.name;(o.namespaceURI?t.hasAttributeNS(o.namespaceURI,r):t.hasAttribute(o.name))||(o.namespaceURI?t.setAttributeNS(o.namespaceURI,o.name,o.value):t.setAttribute(o.name,o.value))}}function ud(e,t){return id(e).find(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&sd(e)===t)}function pd(e){return e?(new Ci.XMLSerializer).serializeToString(e):""}function gd(e,t){if(!e)return;const n=(new Ci.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===n?.namespaceURI&&sd(n)===t?n:void 0}function fd(e,t,n){switch(e){case"pPr":return Jr(t,n);case"rPr":return qc(t,n);case"tblPr":return _o(t,n);case"trPr":return ai(t,n);case"tcPr":return Rr(t,n);default:return n}}function md(e,t,n,o){const r=id(e),a=r.indexOf(n),i=r.slice(a+1).find(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&ad.has(sd(e)));return i?ud(t,sd(i))??null:"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&"style"===sd(e)&&ad.has(o)?id(t).find(e=>"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===e.namespaceURI&&"tblStylePr"===sd(e))??null:null}function hd(e,t,n){const o=ud(e,n);if(!o)return!1;const r=ud(t,n),a=pd(r),i=fd(n,pd(o),a);if(i===a)return!1;if(!i)return!!r&&(t.removeChild(r),!0);const s=gd(i,n);if(!s)return!1;const l=s.cloneNode(!0);return r?(t.replaceChild(l,r),!0):(t.insertBefore(l,md(e,t,o,n)),!0)}function bd(e,t){dd(e,t);let n=!1;for(const r of ad)n=hd(e,t,r)||n;const o=new Set(id(t).map(ld));for(const r of id(e))"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===r.namespaceURI&&ad.has(sd(r))||o.has(ld(r))||(t.appendChild(r.cloneNode(!0)),o.add(ld(r)),n=!0);return n}function yd(e){const t=e.ownerDocument;if(!t)return;const n=t.createElementNS(xr,"w:tblStylePr");dd(e,n);let o=!1;for(const r of id(e)){const e=sd(r);if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"===r.namespaceURI&&ad.has(e)){const t=gd(fd(e,pd(r),""),e);t&&(n.appendChild(t.cloneNode(!0)),o=!0);continue}n.appendChild(r.cloneNode(!0)),o=!0}return o?n:void 0}function vd(e){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==e.namespaceURI||"tblStylePr"!==sd(e))return;const t=cd(e,"type");return t?`tblStylePr:${t}`:void 0}function xd(e,t){let n=!1;n=hd(e,t,"tblPr")||n;const o=id(e).filter(e=>void 0!==vd(e)),r=/* @__PURE__ */new Map;for(const a of id(t)){const e=vd(a);e&&r.set(e,a)}for(const a of o){const o=vd(a),i=r.get(o);if(i){n=bd(a,i)||n;continue}const s=yd(a);if(!s)continue;const l=id(e),c=l.indexOf(a),d=l.slice(c+1).find(e=>void 0!==vd(e)),u=d?r.get(vd(d))??null:null;t.insertBefore(s.cloneNode(!0),u),n=!0}return n}function wd(e){const t=(new Ci.DOMParser).parseFromString(e,"application/xml").documentElement;return"http://schemas.openxmlformats.org/wordprocessingml/2006/main"===t?.namespaceURI&&"styles"===sd(t)?t:void 0}async function Sd(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),o=t.file(rd);if(!n||!o)return!1;const r=await o.async("string"),a=function(e,t){const n=wd(e),o=wd(t);if(!n||!o)return t;const r=/* @__PURE__ */new Map;for(const i of id(o))if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"===i.namespaceURI&&"style"===sd(i)){const e=cd(i,"styleId");e&&r.set(e,i)}let a=!1;for(const i of id(n)){if("http://schemas.openxmlformats.org/wordprocessingml/2006/main"!==i.namespaceURI||"style"!==sd(i))continue;if("table"!==cd(i,"type"))continue;const e=cd(i,"styleId"),t=e?r.get(e):void 0;t&&(a=xd(i,t)||a)}return a?(new Ci.XMLSerializer).serializeToString(o.ownerDocument):t}(n,r);return a!==r&&(t.file(rd,a),!0)}var Id="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function Cd(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}function Td(e){return e.localName??e.tagName}function kd(e){return`${e.namespaceURI??""}\0${Td(e)}`}function Pd(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(o?.localName===t)return o.value}}function Rd(e,t){for(let n=0;n<e.attributes.length;n+=1){const o=e.attributes.item(n);if(!o)continue;const r=o.localName??o.name;(o.namespaceURI?t.hasAttributeNS(o.namespaceURI,r):t.hasAttribute(o.name))||(o.namespaceURI?t.setAttributeNS(o.namespaceURI,o.name,o.value):t.setAttribute(o.name,o.value))}}function Bd(e,t,n){const o=(new Ci.DOMParser).parseFromString(e,"application/xml"),r=(new Ci.DOMParser).parseFromString(t,"application/xml"),a=o.documentElement,i=r.documentElement;if(a&&i&&a.namespaceURI===Id&&i.namespaceURI===Id&&Td(a)===n&&Td(i)===n)return{sourceRoot:a,rebuiltRoot:i}}function Md(e,t,n,o,r){const a=e.slice(t+1).map(r).find(e=>Boolean(e));o.insertBefore(n.cloneNode(!0),a??null)}function Od(e,t){const n=new Set(Cd(t).map(kd));for(const o of Cd(e))o.namespaceURI===Id||n.has(kd(o))||t.appendChild(o.cloneNode(!0))}var Ad=/* @__PURE__ */new Set(["defaultTabStop","autoHyphenation","consecutiveHyphenLimit","hyphenationZone","doNotHyphenateCaps","evenAndOddHeaders"]);var Fd=/* @__PURE__ */new Set(["name","basedOn","next","uiPriority","qFormat","semiHidden","unhideWhenUsed","pPr","rPr","tblPr","tblStylePr"]);function Dd(e){return e.namespaceURI===Id&&"tblStylePr"===Td(e)?`${kd(e)}\0${Pd(e,"type")??""}`:kd(e)}function Ed(e){return e.namespaceURI===Id&&"style"===Td(e)?`${kd(e)}\0${Pd(e,"styleId")??""}`:kd(e)}var Ld=/* @__PURE__ */new Set(["altName","panose1","charset","family","pitch","sig"]);function Nd(e){return e.namespaceURI===Id&&"font"===Td(e)?`${kd(e)}\0${Pd(e,"name")??""}`:kd(e)}var zd=[{relationshipSuffix:"/settings",rebuiltPath:"word/settings.xml",merge:function(e,t){const n=Bd(e,t,"settings");if(!n)return t;const{sourceRoot:o,rebuiltRoot:r}=n;Rd(o,r);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=Cd(o),s=new Map(Cd(r).map(e=>[kd(e),e]));return i.forEach((e,t)=>{const n=kd(e),o=s.get(n),l=Td(e),c=e.namespaceURI===Id?a.get(l):void 0;if(o)return Rd(e,o),void(c?function(e,t,n){Rd(e,t);const o=Cd(t),r=new Map(o.map(e=>[kd(e),e])),a=Cd(e);a.forEach((e,o)=>{const i=kd(e),s=r.get(i);if(s)return Rd(e,s),void Od(e,s);e.namespaceURI===Id&&n.has(Td(e))||Md(a,o,e,t,e=>r.get(kd(e)))})}(e,o,c):Od(e,o));if(c){const n=function(e,t){const n=e.cloneNode(!1);let o=!1;for(const r of Cd(e))r.namespaceURI===Id&&t.has(Td(r))||(n.appendChild(r.cloneNode(!0)),o=!0);return o?n:void 0}(e,c);if(n){const e=i.slice(t+1).map(e=>s.get(kd(e))).find(e=>Boolean(e));r.insertBefore(n,e??null)}return}e.namespaceURI===Id&&Ad.has(l)||Md(i,t,e,r,e=>s.get(kd(e)))}),(new Ci.XMLSerializer).serializeToString(r.ownerDocument)}},{relationshipSuffix:"/styles",rebuiltPath:"word/styles.xml",merge:function(e,t){const n=Bd(e,t,"styles");if(!n)return t;const{sourceRoot:o,rebuiltRoot:r}=n;Rd(o,r);const a=Cd(o),i=new Map(Cd(r).map(e=>[Ed(e),e]));return a.forEach((e,t)=>{const n=Ed(e),o=i.get(n);if(o)return Rd(e,o),void(e.namespaceURI===Id&&"style"===Td(e)?function(e,t){Rd(e,t);const n=Cd(e),o=new Map(Cd(t).map(e=>[Dd(e),e]));n.forEach((e,r)=>{const a=Dd(e),i=o.get(a);if(i)return Rd(e,i),void Od(e,i);e.namespaceURI===Id&&Fd.has(Td(e))||Md(n,r,e,t,e=>o.get(Dd(e)))})}(e,o):Od(e,o));Md(a,t,e,r,e=>i.get(Ed(e)))}),(new Ci.XMLSerializer).serializeToString(r.ownerDocument)}},{relationshipSuffix:"/numbering",rebuiltPath:"word/numbering.xml"},{relationshipSuffix:"/fontTable",rebuiltPath:"word/fontTable.xml",merge:function(e,t){const n=Bd(e,t,"fonts");if(!n)return t;const{sourceRoot:o,rebuiltRoot:r}=n;Rd(o,r);const a=Cd(o),i=new Map(Cd(r).map(e=>[Nd(e),e]));return a.forEach((e,t)=>{const n=Nd(e),o=i.get(n);if(o)return Rd(e,o),void(e.namespaceURI===Id&&"font"===Td(e)&&function(e,t){Rd(e,t);const n=Cd(e),o=new Map(Cd(t).map(e=>[kd(e),e]));n.forEach((e,r)=>{const a=kd(e),i=o.get(a);i?Rd(e,i):e.namespaceURI===Id&&Ld.has(Td(e))||Md(n,r,e,t,e=>o.get(kd(e)))})}(e,o));Md(a,t,e,r,e=>i.get(Nd(e)))}),(new Ci.XMLSerializer).serializeToString(r.ownerDocument)}}];function $d(e,t){const n=e.parts[e.mainDocumentPart]?.relationships?.find(e=>"External"!==e.targetMode&&e.type.endsWith(t)&&Boolean(e.resolvedTarget)),o=n?.resolvedTarget?e.parts[n.resolvedTarget]:void 0;return"xml"===o?.kind?o.data:void 0}var Hd="word/document.xml";function Wd(e){const t=(new Ci.DOMParser).parseFromString(e,"application/xml").getElementsByTagNameNS(xr,"sectPr");let n=0;for(let o=0;o<t.length;o+=1){const e=t.item(o),r=e?.parentNode;e&&"sectPrChange"!==r?.localName&&(n+=1)}return n}async function Ud(e,t){const n=e.sourcePackage;if(!n)return t;const o=n.parts[n.mainDocumentPart];if("xml"!==o?.kind)return fl(e,t);const r=await Wi.default.loadAsync(t),a=Boolean(r.file("word/numbering.xml")),i={settings:Boolean(r.file("word/settings.xml")),styles:Boolean(r.file("word/styles.xml")),fontTable:Boolean(r.file("word/fontTable.xml"))};let s=await async function(e,t){let n=!1;for(const o of zd){const r=$d(e,o.relationshipSuffix);if(!r)continue;const a=t.file(o.rebuiltPath);if(!a){t.file(o.rebuiltPath,r),n=!0;continue}if(!o.merge)continue;const i=await a.async("string"),s=o.merge(r,i);s!==i&&(t.file(o.rebuiltPath,s),n=!0)}return n}(n,r);a&&(s=await gc(n,r)||s),i.styles&&(s=await Kc(n,r)||s,s=await od(n,r)||s,s=await Sd(n,r)||s),s=await async function(e,t){let n=!1;return t.settings||(n=await Ec(e,"word/settings.xml",Ac)||n),t.styles||(n=await Ec(e,"word/styles.xml",Fc)||n),t.fontTable||(n=await Ec(e,"word/fontTable.xml",Dc)||n),n}(r,i)||s,s=await async function(e,t){let n=!1;for(const o of fc){const r=mc(e,o.relationshipSuffix),a=t.file(o.rebuiltPath);if(!r||!a)continue;const i=await a.async("string"),s=Bs(r,i,o.rootLocalName);s!==i&&(t.file(o.rebuiltPath,s),n=!0)}return n}(n,r)||s,s=await async function(e,t,n){let o=!1;for(const r of Dl){const a=Wl(t,r.relationshipSuffix),i=n.file(r.rebuiltPath);if(!a||!i)continue;const s=await i.async("string"),l=Xl(e,a,s,r);l!==s&&(n.file(r.rebuiltPath,l),o=!0)}return o}(e,n,r)||s,s=await ls(n,r)||s,s=await async function(e,t){const n=hs(e,"/comments"),o=hs(e,"/commentsExtended"),r=t.file("word/comments.xml"),a=t.file(ds);if(!(n&&o&&r&&a))return!1;const i=await r.async("string"),s=await a.async("string"),l=xs(n,o,i,s);return l!==s&&(t.file(ds,l),!0)}(n,r)||s,s=await Zs(n,r)||s,s=await Us(n,r)||s;const l=await(r.file(Hd)?.async("string"));if(!l||Wd(o.data)!==Wd(l)){return fl(e,s?await r.generateAsync({type:"arraybuffer"}):t)}const c=Cc(o.data,l);c!==l&&(r.file(Hd,c),s=!0);return Fl(e,s?await r.generateAsync({type:"arraybuffer"}):t)}function jd(e){return e.trim().replace(/[{}]/g,"").toLowerCase()}function Vd(e){const t=(new Ci.DOMParser).parseFromString(e,"application/xml").documentElement;return t&&(t.getAttributeNS("http://schemas.openxmlformats.org/officeDocument/2006/customXml","itemID")??t.getAttribute("ds:itemID")??t.getAttribute("itemID"))?.trim()||null}function Kd(e){const t=/^(([^:[]+):)?([^[]+?)(?:\[(\d+)\])?$/.exec(e);if(!t)return null;const n=t[4]?Number.parseInt(t[4],10):1;return!Number.isFinite(n)||n<1?null:{...t[2]?{prefix:t[2]}:{},localName:t[3],index:n}}function _d(e,t,n,o){if(e.localName!==n)return!1;if(!t)return!e.namespaceURI;const r=o.get(t);return void 0!==r&&e.namespaceURI===r}function Xd(e){const t=[];for(let n=0;n<e.childNodes.length;n+=1){const o=e.childNodes[n];o?.nodeType===o.ELEMENT_NODE&&t.push(o)}return t}function Gd(e,t,n){if(!e||!t?.storeItemID||!t.xpath)return!1;const o=function(e,t){const n=jd(t);for(const o of Object.values(e.parts)){if("xml"!==o.kind||!/^customXml\/item\d+\.xml$/i.test(o.path))continue;const t=(o.relationships?.find(e=>"External"!==e.targetMode&&e.type.endsWith("/customXmlProps")&&e.resolvedTarget))?.resolvedTarget;if(!t)continue;const r=e.parts[t];if(!r||"xml"!==r.kind)continue;const a=Vd(r.data);if(a&&jd(a)===n)return{storeItemId:a,itemPartPath:o.path,itemPropsPartPath:t,xml:o.data}}return null}(e,t.storeItemID);if(!o)return!1;const r=function(e,t,n){const o=(new Ci.DOMParser).parseFromString(e,"application/xml"),r=o.documentElement;if(!r)return null;const a=t.trim().replace(/\/text\(\)$/,"");if(!a.startsWith("/")||a.startsWith("//"))return null;const i=a.split("/").filter(Boolean);if(0===i.length)return null;const s=i.at(-1)?.startsWith("@")?i.pop():null,l=Kd(i[0]);if(!l||1!==l.index)return null;if(!_d(r,l.prefix,l.localName,n))return null;let c=r;for(let m=1;m<i.length;m+=1){const e=Kd(i[m]);if(!e)return null;const t=Xd(c).filter(t=>_d(t,e.prefix,e.localName,n))[e.index-1];if(!t)return null;c=t}if(!s)return{document:o,element:c};const d=s.slice(1),u=d.indexOf(":");if(u<0)return{document:o,element:c,attribute:{localName:d,qualifiedName:d}};const p=d.slice(0,u),g=d.slice(u+1),f=n.get(p);return f?{document:o,element:c,attribute:{namespaceUri:f,localName:g,qualifiedName:`${p}:${g}`}}:null}(o.xml,t.xpath,function(e){const t=/* @__PURE__ */new Map;if(!e)return t;for(const n of e.matchAll(/xmlns:([A-Za-z_][\w.-]*)\s*=\s*(["'])(.*?)\2/g))t.set(n[1],n[3]);return t}(t.prefixMappings));if(!r)return!1;if(r.attribute)r.attribute.namespaceUri?r.element.setAttributeNS(r.attribute.namespaceUri,r.attribute.qualifiedName,n):r.element.setAttribute(r.attribute.localName,n);else{if(Xd(r.element).length>0)return!1;for(;r.element.firstChild;)r.element.removeChild(r.element.firstChild);r.element.appendChild(r.document.createTextNode(n))}const a=e.parts[o.itemPartPath];return!!a&&(a.data=(new Ci.XMLSerializer).serializeToString(r.document),!0)}function qd(e,t,n,o){if(!t.sdtPr.dataBinding)return;const r=e.get(t.groupId);r?r.value+=`${o}${n}`:e.set(t.groupId,{wrapper:t,value:n})}function Yd(e){return e.blocks.map(Jd).filter(Boolean).join("\n")}function Zd(e){return e.cells.map(Yd).filter(Boolean).join("\t")}function Jd(e){return"paragraph"===e.type?oi(e):e.rows.map(Zd).filter(Boolean).join("\n")}function Qd(e,t){for(const n of e.runs){for(const e of n.sdtWrappers??[])qd(t,e,n.text,"");"textBox"===n.kind&&tu(n.textBox.blocks,t)}}function eu(e,t){for(const n of e.rows){const e=Zd(n);for(const o of n.sdtWrappers??[])qd(t,o,e,"\n");for(const o of n.cells){const e=Yd(o);for(const n of o.sdtWrappers??[])qd(t,n,e,"\n");tu(o.blocks,t)}}}function tu(e,t){if(e)for(const n of e){const e=Jd(n);for(const o of n.sdtWrappers??[])qd(t,o,e,"\n");"paragraph"===n.type?Qd(n,t):eu(n,t)}}async function nu(e,t={}){if(!e.sourcePackage)return La(e);const n=(o=e.sourcePackage,{...o,contentTypes:{defaults:{...o.contentTypes.defaults},overrides:{...o.contentTypes.overrides}},rootRelationships:o.rootRelationships.map(e=>({...e})),parts:Object.fromEntries(Object.entries(o.parts).map(([e,t])=>[e,{...t,...t.relationships?{relationships:t.relationships.map(e=>({...e}))}:{}}])),...o.diagnostics?{diagnostics:o.diagnostics.map(e=>({...e}))}:{},...o.rebuiltPartHashes?{rebuiltPartHashes:{...o.rebuiltPartHashes}}:{}});var o;const r=wa(n),a=r.diagnostics.filter(e=>"error"===e.level);if(a.length)throw new Ia(a);n.opaqueObjects=r.objects;const i={...e,sourcePackage:n};!function(e){if(!e.sourcePackage)return 0;const t=/* @__PURE__ */new Map;for(const o of ei(e))tu(o.blocks,t),tu(o.header,t),tu(o.firstPageHeader,t),tu(o.evenPageHeader,t),tu(o.footer,t),tu(o.firstPageFooter,t),tu(o.evenPageFooter,t);let n=0;for(const{wrapper:o,value:r}of t.values()){const t=o.sdtPr.dataBinding;t&&Gd(e.sourcePackage,t,r)&&(n+=1)}}(i);const s=r.objects.length>0,l=e.opaqueRelocationIntent,c=l?ka(n,l,l.destinationOwner):void 0,d=await ea(i,n);let u=await Ud(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 Wi.default.loadAsync(e);if(!n.file(t.destinationOwner))throw Error("Original destination story was not retained");const o=t.destinationOwner.lastIndexOf("/"),r=(o>=0?t.destinationOwner.slice(0,o+1):"")+"_rels/"+t.destinationOwner.slice(o+1)+".rels",a=await(n.file(r)?.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 Ci.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(Er,"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(Er,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(r,(new Ci.XMLSerializer).serializeToString(i)),n.generateAsync({type:"arraybuffer"})}(u,c)}if(s||t.requireOpaquePreservation||c||e.opaqueDeletionIntents?.length){const{captureDocxSourcePackage:o}=await import("./sourcePackage-BbPv-emQ.js").then(e=>e.r),r=await o(u),a=Wo(n,r,e.opaqueDeletionIntents,c?function(e,t){const n=e.opaqueObjects?.find(e=>e.ownerPath===t.sourceOwner&&e.ordinal===t.sourceOrdinal&&e.signature===t.sourceSignature),o=e.parts[t.destinationOwner];if(!n||!o)throw Error("Relocation source missing");const r={...e,parts:{...e.parts,[t.destinationOwner]:{...o,relationships:[...o.relationships??[],...t.addedRelationships]}}},a=yr(r,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 Ia(a);const i=e.opaqueDeletionIntents??[];if(i.length&&!1!==t.pruneDeletedOpaqueDependencies){const t=Yi(n,r,i);if(t.removeEdges.length||t.removeParts.length){const r=await async function(e,t){if(!t.removeParts.length&&!t.removeEdges.length)return e;const n=await Wi.default.loadAsync(e),o=new Ci.XMLSerializer,r=async e=>{const t=n.file(e);if(!t)throw Error("Missing planned OPC part "+e);return Ki(await t.async("string"))};for(const l of new Set(t.removeEdges.map(e=>e.relPath))){const e=await r(l),a=e.documentElement,i=new Set(t.removeEdges.filter(e=>e.relPath===l).map(e=>e.id));for(const t of Vi(a))i.has(t.getAttribute("Id")??"")&&(i.delete(t.getAttribute("Id")),a.removeChild(t));if(i.size)throw Error("OPC relationship plan became stale");Vi(a).length?n.file(l,o.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=Ar(l);(a.has(l)||"string"==typeof e&&a.has(e))&&n.remove(l)}const i=await r(Vo),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 Vi(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(Vo,o.serializeToString(i)),n.generateAsync({type:"arraybuffer"})}(u,t),a=await o(r),s=Wo(n,a,i);if(s.length)throw new Ia(s);return gr(r,e)}}}return gr(u,e)}async function ou(e,t={}){if(!e.sourcePackage)return _a(e);const n=await nu(e,t);return new Blob([n],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}var ru="http://schemas.openxmlformats.org/wordprocessingml/2006/main",au="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",iu="http://schemas.openxmlformats.org/officeDocument/2006/relationships",su=e=>{throw Error("Opaque insertion rejected: "+e)};function lu(e){if(/<!\s*(?:DOCTYPE|ENTITY)\b/i.test(e))return su("unsafe XML declaration");const t=new Ci.DOMParser({onError:()=>su("malformed XML")}).parseFromString(e,"application/xml").documentElement;return t||su("missing XML root")}function cu(e){const t=[],n=[e];for(let o=0;o<n.length;o++){const e=n[o];t.push(e);for(const t of Array.from(e.childNodes))1===t.nodeType&&n.push(t)}return t}function du(e){const t=e.lastIndexOf("/");return e.slice(0,t+1)+"_rels/"+e.slice(t+1)+".rels"}function uu(e,t){const n=e.split("/").slice(0,-1),o=t.split("/");for(;n.length&&o.length&&n[0]===o[0];)n.shift(),o.shift();const r="../".repeat(n.length)+o.join("/");return Ua(e,r)!==t?su("unrepresentable relative target"):r}function pu(e){return/^[A-Za-z0-9_.\-/]+$/.test(e)&&!e.split("/").some(e=>!e||"."===e||".."===e)}var gu={"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 fu="http://schemas.openxmlformats.org/wordprocessingml/2006/main",mu="[Content_Types].xml",hu="application/vnd.openxmlformats-package.relationships+xml",bu=e=>{throw Error("Opaque transfer application rejected: "+e)};function yu(e,t,n){if(/<!\s*(?:DOCTYPE|ENTITY)\b/i.test(e))return bu("unsafe XML declaration");const o=new Ci.DOMParser({onError:()=>bu("malformed XML")}).parseFromString(e,"application/xml");return o.documentElement?.namespaceURI!==t||o.documentElement.localName!==n?bu("unexpected XML root"):o}function vu(e){return Array.from(e.childNodes).filter(e=>1===e.nodeType)}function xu(e){const t=e.lastIndexOf("/");return e.slice(0,t+1)+"_rels/"+e.slice(t+1)+".rels"}function wu(e){return(new Ci.XMLSerializer).serializeToString(e)}function Su(e,t){return e.byteLength===t.byteLength&&e.every((e,n)=>e===t[n])}function Iu(e){const t=/* @__PURE__ */new Set;for(const[n,o]of Object.entries(e.files)){if(o.dir)continue;const e=n.toLowerCase();if(t.has(e)||void 0!==o.unsafeOriginalName&&o.unsafeOriginalName!==n)return bu("ambiguous ZIP entry");if(t.add(e),e.startsWith("_xmlsignatures/"))return bu("signed package")}}async function Cu(e,t,n){const o=await Wi.default.loadAsync(e);Iu(o);const r=await Aa(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")))bu("signed package")}(r);const a=function(e,t){const n=Hi(e),o=t.mainDocumentPart,r=Object.hasOwn(t.parts,o)?t.parts[o]:void 0;if(!pu(o)||!r||"xml"!==r.kind)return su("missing destination main story");const a=lu(r.data);if(a.namespaceURI!==ru||"document"!==a.localName)return su("only Transitional main story is supported");if(wa(t).diagnostics.some(e=>"error"===e.level))return su("destination opaque inspection errors");const i=/* @__PURE__ */new Set,s=e=>{if("[Content_Types].xml"!==e&&!pu(e))return su("ambiguous destination OPC path");i.add(e.toLowerCase())};for(const[k,P]of Object.entries(t.parts)){if(P.path!==k)return su("inconsistent destination part path");s(k),"[Content_Types].xml"===k||k.endsWith(".rels")||s(du(k));for(const e of P.relationships??[])if("External"!==e.targetMode){if(!e.resolvedTarget||Ua(k,e.target)!==e.resolvedTarget)return su("unresolved destination relationship");s(e.resolvedTarget)}}for(const k of Object.keys(t.contentTypes.overrides))s(k);for(const k of t.rootRelationships)if("External"!==k.targetMode){if(!k.resolvedTarget||Ua(null,k.target)!==k.resolvedTarget)return su("unresolved root relationship");s(k.resolvedTarget)}if(new Set(Object.keys(t.parts).map(e=>e.toLowerCase())).size!==Object.keys(t.parts).length)return su("aliased destination parts");let l="";for(let k=1;k<=1e5;k++){const e="word/oasis-transfer-"+k;if(![...i].some(t=>t===e||t.startsWith(e+"/")||e.startsWith(t+"/"))){l=e;break}}if(!l)return su("part namespace exhausted");const c=new Map(n.parts.map((e,t)=>[e.path,l+"/part-"+(t+1)+"."+gu[e.contentType]])),d=(e,t,n=e.id)=>{const o=c.get(e.resolvedTarget);return o?{...e,id:n,target:uu(t,o),resolvedTarget:o,targetMode:"Internal"}:su("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((r.relationships??[]).map(e=>e.id));if(p.size!==(r.relationships??[]).length)return su("duplicate destination relationship ID");const g=cu(a).flatMap(e=>Array.from(e.attributes).map(e=>e.value));let f=1;const m=n.relationships.map(e=>{let t;do{t="rIdOasisTransfer"+f++}while(p.has(t)||r.data.includes(t)||g.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,o,h.get(e.id))),y=lu(n.fragmentXml),v=cu(y),x=v.filter(e=>e.namespaceURI===au&&"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(iu,"id")??""))return su("ambiguous chart or drawing identity");for(const k of v){if(k!==y&&k.namespaceURI===ru)return su("nested WordprocessingML in chart drawing");for(const e of Array.from(k.attributes)){if("http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"===e.namespaceURI)return su("unsupported extended drawing identity");if(e.namespaceURI===iu||"http://purl.oclc.org/ooxml/officeDocument/relationships"===e.namespaceURI||"urn:schemas-microsoft-com:office:office"===e.namespaceURI&&"relid"===e.localName){if(k!==w[0]||e.namespaceURI!==iu||"id"!==e.localName||!h.has(e.value))return su("unknown chart relationship reference");k.setAttributeNS(iu,e.name,h.get(e.value))}else if("http://www.w3.org/2000/xmlns/"!==e.namespaceURI&&h.has(e.value))return su("unknown attribute may reference a relationship")}}const S=/* @__PURE__ */new Set;for(const k of Object.values(t.parts)){if("xml"!==k.kind||!k.data.includes("docPr"))continue;const e=k.path===o?a:lu(k.data);for(const t of cu(e)){if(t.namespaceURI!==au||"docPr"!==t.localName)continue;const e=t.getAttribute("id")??"";if(!/^\d+$/.test(e)||Number(e)>4294967295)return su("invalid destination drawing ID");S.add(Number(e))}}let I=1879048192;for(;S.has(I)&&I<2147483647;)I++;if(S.has(I))return su("drawing identity exhausted");x[0].setAttribute("id",String(I));const C=hr(y);if(!C)return su("chart projection lost");const T=Hi({...n,ownerPath:o,fragmentXml:C.fragmentXml,signature:C.signature,relationships:b,parts:u});return{destinationOwner:o,destinationRun:C,addedRelationships:T.relationships,addedParts:T.parts,contentTypeOverrides:Object.fromEntries(T.parts.map(e=>[e.path,e.contentType])),pathMapping:[...c].map(([e,t])=>({from:e,to:t})),relationshipMapping:m,drawingId:I}}(t,r),i=a.destinationOwner,s=r.parts[i],l=yu(s.data,fu,"document"),c=l.documentElement,d=vu(c).filter(e=>e.namespaceURI===fu&&"body"===e.localName);if(1!==d.length)return bu("ambiguous document body");const u=vu(d[0]).filter(e=>e.namespaceURI===fu&&"p"===e.localName);if(!Number.isSafeInteger(n)||n<0||n>=u.length)return bu("invalid paragraph index");const p=u[n],g=yu(a.destinationRun.fragmentXml,fu,"drawing"),f=l.createElementNS(fu,c.prefix?c.prefix+":r":"r");f.appendChild(l.importNode(g.documentElement,!0)),p.appendChild(f);const m=wu(l),h=xu(i),b=function(e,t){const n=yu(e,Er,"Relationships"),o=n.documentElement,r=/* @__PURE__ */new Set;for(const a of vu(o)){const e=a.getAttribute("Id")??"";if("http://schemas.openxmlformats.org/package/2006/relationships"!==a.namespaceURI||"Relationship"!==a.localName||!e||r.has(e)||!a.getAttribute("Type")||!a.getAttribute("Target"))return bu("ambiguous existing relationships");const t=a.getAttribute("TargetMode");if(t&&"Internal"!==t&&"External"!==t)return bu("unknown relationship mode");r.add(e)}for(const a of t){if(r.has(a.id))return bu("relationship collision");r.add(a.id);const e=n.createElementNS(Er,o.prefix?o.prefix+":Relationship":"Relationship");e.setAttribute("Id",a.id),e.setAttribute("Type",a.type),e.setAttribute("Target",a.target),o.appendChild(e)}return wu(n)}(await(o.file(h)?.async("string"))??'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"/>',a.addedRelationships),y=await(o.file(mu)?.async("string"));if(!y)return bu("missing content types");const v=function(e,t){const n=yu(e,fi,"Types"),o=n.documentElement,r=/* @__PURE__ */new Set,a=/* @__PURE__ */new Set;let i;for(const s of vu(o)){if("http://schemas.openxmlformats.org/package/2006/content-types"!==s.namespaceURI)return bu("unexpected content type element");const e=s.getAttribute("ContentType")??"";if(!e)return bu("missing content type");if("Default"===s.localName){const t=(s.getAttribute("Extension")??"").toLowerCase();if(!t||a.has(t))return bu("duplicate or invalid content type default");a.add(t),"rels"===t&&(i=e)}else{if("Override"!==s.localName)return bu("unknown content type element");{const e=(s.getAttribute("PartName")??"").toLowerCase();if(!e.startsWith("/")||r.has(e))return bu("duplicate or invalid content type override");r.add(e)}}}if(i&&i!==hu)return bu("inconsistent relationship content type");if(!i){const e=n.createElementNS(fi,o.prefix?o.prefix+":Default":"Default");e.setAttribute("Extension","rels"),e.setAttribute("ContentType",hu),o.insertBefore(e,vu(o).find(e=>"Override"===e.localName)??null)}for(const[s,l]of Object.entries(t.contentTypeOverrides)){const e="/"+s;if(r.has(e.toLowerCase()))return bu("content type override collision");r.add(e.toLowerCase());const t=n.createElementNS(fi,o.prefix?o.prefix+":Override":"Override");t.setAttribute("PartName",e),t.setAttribute("ContentType",l),o.appendChild(t)}return wu(n)}(y,a),x={...r,parts:{...r.parts,[i]:{...s,data:m,relationships:[...s.relationships??[],...a.addedRelationships]}},contentTypes:{defaults:{...r.contentTypes.defaults,rels:hu},overrides:{...r.contentTypes.overrides,...a.contentTypeOverrides}}};for(const N of a.addedParts)x.parts[N.path]={...N,originalHash:""};const w=wa(r),S=wa(x);if(S.diagnostics.some(e=>"error"===e.level)||S.objects.length!==w.objects.length+1)return bu("unexpected predicted inventory");const I=S.objects.filter(e=>e.ownerPath===i&&e.signature===a.destinationRun.signature);if(1!==I.length||JSON.stringify(I[0].partPaths)!==JSON.stringify(a.addedParts.map(e=>e.path).sort()))return bu("predicted inserted closure mismatch");const C=S.objects.filter(e=>e!==I[0]),T=e=>JSON.stringify([e.ownerPath,e.kind,e.signature,e.edges,e.partPaths]);if(JSON.stringify(C.map(T).sort())!==JSON.stringify(w.objects.map(T).sort()))return bu("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 bu("drawing ID collision");const k=await Wi.default.loadAsync(e),P=/* @__PURE__ */new Set,R=new Set(Object.keys(k.files).map(e=>e.toLowerCase())),B=(e,t,n=!1)=>{const o=e.toLowerCase();if(R.has(o)||P.has(o))return bu("part collision");P.add(o),k.file(e,t,{base64:n})};for(const N of a.addedParts)B(N.path,N.data,"base64"===N.encoding),N.relationships.length&&B(xu(N.path),zr(N.relationships));o.file(h)||P.add(h.toLowerCase()),k.file(i,m),k.file(h,b),k.file(mu,v);const M=await k.generateAsync({type:"arraybuffer",compression:"DEFLATE"}),O=await Wi.default.loadAsync(M);Iu(O);const A=await Aa(M),F=Wo(x,A);if(F.length)throw new Ia(F);const D=/* @__PURE__ */new Set([i,h,mu]);for(const[N,z]of Object.entries(o.files)){if(z.dir||D.has(N))continue;const e=O.file(N);if(!e||!Su(await z.async("uint8array"),await e.async("uint8array")))return bu("existing part changed: "+N)}for(const[N,z]of Object.entries(O.files))if(!z.dir&&!o.file(N)&&!P.has(N.toLowerCase()))return bu("unexpected added part: "+N);for(const N of a.addedParts){const e=A.parts[N.path];if(!e||e.contentType!==N.contentType||e.kind!==N.kind||e.encoding!==N.encoding||e.data!==N.data)return bu("copied payload mismatch")}for(const[N,z]of Object.entries(r.parts))if(A.parts[N]?.contentType!==z.contentType)return bu("existing part content type changed");for(const[N,z]of Object.entries(r.contentTypes.defaults))if(A.contentTypes.defaults[N]!==z)return bu("existing default changed");for(const[N,z]of Object.entries(r.contentTypes.overrides))if(A.contentTypes.overrides[N]!==z)return bu("existing override changed");const E=A.parts[i]?.relationships??[],L=x.parts[i].relationships??[];return JSON.stringify(E)!==JSON.stringify(L)?bu("owner relationships changed"):{buffer:M,plan:a}}var Tu=e=>{throw Error("Opaque editor transfer rejected: "+e)};function ku(e){return 1!==e.sections?.length?Tu("only one section is supported"):e.sections[0].blocks.filter(e=>"paragraph"===e.type)}function Pu(e){if(!e.document.sourcePackage||"main"!==pr(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 Tu("unsupported state or pending opaque edit")}function Ru(e){Pu(e);const t=Ii(e,e=>"opaque"===e.kind);if(!t||"opaque"!==t.run.kind||t.run.revision||t.run.sdtWrappers?.length||!ku(e.document).some(e=>e.id===t.paragraph.id))return Tu("select one unwrapped chart in the main story");const n=e.document.sourcePackage,o=t.run.opaque,r=wa(n).objects.filter(e=>e.ownerPath===n.mainDocumentPart&&e.signature===o.signature),a=1===r.length?r[0]:void 0;return a&&a.fragmentXml===o.fragmentXml&&JSON.stringify(a.relationshipIds)===JSON.stringify(o.relationshipIds)?function(e,t){const n=wa(e);if(n.diagnostics.some(e=>"error"===e.level))return Ai("source inspection errors");const o=n.objects.filter(e=>e.signature===t.signature),r=1===o.length?o[0]:void 0;if(!r||r.ownerPath!==t.ownerPath||r.ordinal!==t.ordinal)return Ai("ambiguous original identity");if("chart"!==r.kind||"inline"!==r.geometry?.placement)return Ai("only inline charts are supported");const a=yr(e,r.ownerPath,r.relationshipIds);if(a.issues.length)return Ai("unresolved source closure");const i=e.parts[r.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??[]}:Ai("missing source part")});return Hi({format:Oi,ownerPath:r.ownerPath,fragmentXml:r.fragmentXml,signature:r.signature,relationships:(i.relationships??[]).filter(e=>r.relationshipIds.includes(e.id)),parts:s})}(n,a):Tu("selection is not an unchanged original")}function Bu(e){return JSON.stringify(ku(e).map(e=>{const t=[];let n=0;for(const o of e.runs)"opaque"===o.kind&&t.push([n,o.kind,o.opaque.signature]),n+=o.text.length;return[e.runs.map(e=>e.text).join(""),t]}))}function Mu(e,t,n,o){const r=xe(t,n,[o]),a=ci(r,n+1);return qt(e,cr(e).map(e=>e.id===t.id?r:e),{anchor:a,focus:a})}async function Ou(e,t){Pu(e);const n=mr(e);if(!n.isCollapsed)return Tu("paste requires a collapsed caret");const o=cr(e)[n.startIndex],r=ku(e.document).findIndex(e=>e.id===o?.id);if(!o||r<0)return Tu("caret must be in a direct body paragraph");const a=n.startParagraphOffset;if(!Number.isSafeInteger(a)||a<0||a>Xr(o))return Tu("invalid caret");if(o.runs.some(e=>"text"!==e.kind&&"opaque"!==e.kind||e.revision||e.sdtWrappers?.length||e.styles?.link))return Tu("unsupported destination runs");const i=await nu(e.document);if(Bu(await ve(i.slice(0)))!==Bu(e.document))return Tu("destination body projection mismatch");const s=await Cu(i,t,r),l=await Aa(s.buffer),c=l.opaqueObjects?.filter(e=>e.signature===s.plan.destinationRun.signature&&e.ownerPath===l.mainDocumentPart);if(1!==c?.length)return Tu("staged chart identity mismatch");const d={...s.plan.destinationRun,fragmentXml:c[0].fragmentXml,relationshipIds:[...c[0].relationshipIds]},u={id:Da("run"),kind:"opaque",text:"",opaque:d,styles:{}},p=function(e,t){const n=e.document.sourcePackage,o=wa(n).objects,r=wa(t).objects,a=/* @__PURE__ */new Set,i=cr(e).map(e=>{let i=!1;const s=e.runs.map(e=>{if("opaque"!==e.kind)return e;const s=e.opaque,l=o.filter(e=>e.signature===s.signature),c=r.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 o=n.parts[e],r=t.parts[e];return!o||!r||o.kind!==r.kind||o.contentType!==r.contentType||o.encoding!==r.encoding||o.data!==r.data})||a.has(d.signature)?Tu("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 qt(e,i,e.selection)}(e,l),g=cr(p).find(e=>e.id===o.id);if(!g)return Tu("target paragraph lost during rebind");const f={...Mu(p,g,Xr(g),u).document,sourcePackage:l};if(Bu(await ve(s.buffer))!==Bu(f))return Tu("staged body projection mismatch");l.rebuiltPartHashes=await ba(f,l);const m=Mu(p,g,a,u),h={...m,document:{...m.document,sourcePackage:l}},b=await nu(h.document);return Bu(await ve(b))!==Bu(h.document)?Tu("exported caret position mismatch"):h}var Au="application/x-oasis-chart-token",Fu="web "+Au;function Du(e){return"application/x-oasis-chart-token"===e||"web application/x-oasis-chart-token"===e}var Eu,Lu=0;function Nu(e){const t=++Lu;Eu=void 0;const n=Ru(e),o=globalThis.crypto.randomUUID();let r=!1;return{token:o,confirm:()=>!r&&t===Lu&&(r=!0,Eu={token:o,manifest:n,expires:Date.now()+3e5},!0)}}function zu(e){return Eu&&Date.now()>=Eu.expires&&(Eu=void 0),Eu&&Eu.token===e?structuredClone(Eu.manifest):void 0}function $u(e){const t=cr(e),n=mr(e,t);if(n.isCollapsed)return!1;for(let o=n.startIndex;o<=n.endIndex;o++){const e=t[o];if(!e)continue;const r=o===n.startIndex?n.startParagraphOffset:0,a=o===n.endIndex?n.endParagraphOffset:Xr(e);let i=0;for(const t of e.runs){const e=i+t.text.length;if("opaque"===t.kind&&i<a&&e>r)return!0;i=e}}return!1}function Hu(e){const t=mr(e);if(t.isCollapsed)return"";const n=cr(e),o=[];let r=null;const a=()=>{r&&(o.push("bullet"===r?"</ul>":"</ol>"),r=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:Xr(s),d=on(s,l,c),u=ho(s,e.document,d.map(e=>e.text).join("")),p=Gt(d,e.document);if(s.list?.kind){const e="bullet"===s.list.kind?"ul":"ol";r!==s.list.kind&&(a(),o.push(`<${e}>`),r=s.list.kind),o.push(`<li${u}>${p}</li>`);continue}a(),o.push(`<p${u}>${p}</p>`)}return a(),o.join("")}function Wu(e,t){if(0===t.length||me(e))return e;const n=sr(e.selection)?e:ee(e),{paragraph:o,index:r,offset:a}=oe(n),i=cr(n),s=0===Xr(o);if(me(n))return e;const{beforeRuns:l,afterRuns:d}=Eo(o,a),u=t.map(e=>{const t=va(e.runs.map(e=>({text:e.text,styles:oa(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 p,g=Y(ci(o,a));if(1===u.length){const e=u[0],t=e.runs.reduce((e,t)=>e+t.text.length,0),n=c(o,[...l,...e.runs.map(Ea),...d],qn(o,a));n.style=s&&void 0!==e.style?.tabs?{...o.style,tabs:e.style.tabs}:o.style?{...o.style}:e.style?{...e.style}:void 0,n.list=o.list?{...o.list}:e.list?{...e.list}:void 0,p=[...Ja(i.slice(0,r)),n,...Ja(i.slice(r+1))],g=Y(ci(n,l.reduce((e,t)=>e+t.text.length,0)+t))}else{const e=u[0],t=u[u.length-1],n=t.runs.reduce((e,t)=>e+t.text.length,0),f=c(o,[...l,...e.runs.map(Ea)],qn(o,a));f.style=s&&void 0!==e.style?.tabs?{...o.style,tabs:e.style.tabs}:o.style?{...o.style}:e.style?{...e.style}:void 0,f.list=o.list?{...o.list}:e.list?{...e.list}:void 0;const m=u.slice(1,-1).map(zo),h=c(t,[...t.runs.map(Ea),...d],void 0);h.list=t.list?{...t.list}:void 0,p=[...Ja(i.slice(0,r)),f,...m,h,...Ja(i.slice(r+1))],g=Y(ci(h,n))}return qt(n,p,g)}function Uu(e){return e.map(Ea)}function ju(e){return e.reduce((e,t)=>e+t.text.length,0)}function Vu(e,t,n){if(0===n.length)return e;const o=cr(e),r=o.findIndex(e=>e.id===t.paragraphId);if(-1===r)return e;const a=o[r],i=Br(a,t),s=Uu(n[0].runs);if(1===n.length){const t=xe(a,i,s),n=o.map((e,n)=>n===r?t:e),l=ju(s),c=ci(t,i),d=ci(t,i+l);return qt(e,n,{anchor:c,focus:d})}const l=on(a,0,i),d=on(a,i,Xr(a)),u=n[n.length-1],p=n.slice(1,-1),g=c(zo(n[0].paragraphTemplate),[...l,...s],qn(a,i)),f=p.map(e=>c(zo(e.paragraphTemplate),Uu(e.runs))),m=c(zo(u.paragraphTemplate),[...Uu(u.runs),...d],qn(a,i)),h=[...o.slice(0,r),g,...f,m,...o.slice(r+1)],b=ci(g,ju(l)),y=ci(m,ju(u.runs));return qt(e,h,{anchor:b,focus:y})}function Ku(e,n,o={}){const r=mr(e);if(r.isCollapsed)return e;if(function(e,t){const n=mr(e);if(n.isCollapsed)return!1;const o=cr(e),r=o.findIndex(e=>e.id===t.paragraphId);if(-1===r)return!1;if(r<n.startIndex||r>n.endIndex)return!1;const a=o[r],i=Br(a,t);return!(r===n.startIndex&&i<n.startParagraphOffset||r===n.endIndex&&i>n.endParagraphOffset)}(e,n))return e;if(me(e))return e;const a=cr(e).find(e=>e.id===n.paragraphId);if(a&&(t(a)||Qe(a,Br(a,n),Br(a,n))))return e;const i=function(e){const t=mr(e);if(t.isCollapsed)return[];const n=cr(e),o=[];for(let r=t.startIndex;r<=t.endIndex;r+=1){const e=n[r],a=r===t.startIndex?t.startParagraphOffset:0,i=r===t.endIndex?t.endParagraphOffset:Xr(e),s=on(e,a,i);o.push({paragraphTemplate:zo(e),runs:s})}return o}(e);if(0===i.length)return e;const s=i.flatMap(e=>e.runs);if(s.some(e=>"opaque"===e.kind)){if(o.copy||e.trackChangesEnabled||1!==s.length||"opaque"!==s[0].kind||s[0].revision||s[0].sdtWrappers?.length||1!==i.length)return e;const t=cr(e),a=t.findIndex(e=>e.id===n.paragraphId);if(a<0)return e;const l=t[a],c=Br(l,n),d=r.endParagraphOffset-r.startParagraphOffset,u=a===r.startIndex&&c>r.endParagraphOffset?c-d:c,p=ee(e),g=cr(p).find(e=>e.id===l.id);return g?Vu(p,ci(g,u),i):e}if(o.copy)return Vu(e,n,i);const l=function(e,t){const n=mr(e),o=cr(e),r=o.findIndex(e=>e.id===t.paragraphId);if(-1===r)return t;const a=o[r],i=Br(a,t);if(n.startIndex===n.endIndex){if(r!==n.startIndex||i<=n.endParagraphOffset)return t;const e=o[n.startIndex];return ci(e,i-(n.endParagraphOffset-n.startParagraphOffset))}return t}(e,n);return Vu(ee(e),l,i)}function _u(e,t,n){if(0===t.length)return e;if(sr(e.selection)&&!e.trackChangesEnabled?$n(e):me(e))return e;const o=sr(e.selection)?e:ee(e),{paragraph:r,index:a,offset:i}=oe(o),s=n?{...n}:qn(r,i),l={id:`run:${Math.random().toString(36).slice(2,9)}`,text:t,styles:s,kind:"text"};o.trackChangesEnabled&&(l.revision={id:`rev:${Math.random().toString(36).slice(2,9)}`,type:"insert",author:"User",date:Date.now()});const c=!e.trackChangesEnabled&&sr(e.selection)?e.selection.focus.fieldBoundaryAffinity:void 0,d=xe(r,i,[l],c),u=cr(o).map((e,t)=>t===a?d:e);return qt(o,u,Y(Qr(d,i+t.length,c)))}function Xu(e){return _u(e,"\v")}function Gu(e,n,o){if(0===n.length)return e;const r=n.replace(/\r\n/g,"\n").replace(/\r/g,"\n");if(!r.includes("\n"))return _u(e,r,o);if(Ve(e))return e;const a=sr(e.selection)?e:ee(e),{paragraph:i,index:s,offset:l}=oe(a);if(Ve(a))return e;const d=r.split("\n"),u=o?{...o}:qn(i,l),{beforeRuns:p,afterRuns:g}=Eo(i,l,a.selection.focus.fieldBoundaryAffinity),f=c(i,[...p,za(d[0],u)],u),m=d.slice(1,-1).map(e=>De([{text:e,styles:u}])),h=c(t(i)?He(i,[]):De([]),[za(d[d.length-1],u),...g],u),b=cr(a),y=[...b.slice(0,s),f,...m,h,...b.slice(s+1)];return qt(a,y,Y(Qr(h,d[d.length-1].length,"before-markers")))}function qu(e,t){const n=cr(e),o=mr(e,n);if(o.startIndex!==o.endIndex)return;const r=n[o.startIndex];if(!r)return;let a=o.startParagraphOffset,i=o.endParagraphOffset;if(o.isCollapsed&&("backward"===t?a-=1:i+=1),a<0||i>Xr(r)||i-a!==1)return;let s,l=0;for(const h of r.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"!==pr(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],g=e.document.opaqueDeletionIntents??[];if(g.some(e=>e.ownerPath===p.ownerPath&&e.ordinal===p.ordinal))return e;const f=ee({...e,selection:{anchor:ci(r,a),focus:ci(r,i)}}),m={ownerPath:p.ownerPath,ordinal:p.ordinal,signature:p.signature};return{...f,document:{...f.document,opaqueDeletionIntents:[...g,m]}}}function Yu(e){const n=qu(e,"backward");if(void 0!==n)return n;if(!sr(e.selection))return ee(e);const{paragraph:o,index:r,offset:a}=oe(e),i=cr(e);if(a>0){if(e.trackChangesEnabled&&Et(e)||M(e,o,a-1,a))return e;if(t(o)){const t={...e,selection:{anchor:ci(o,a-1),focus:ci(o,a)}};return ee(t)}if(e.trackChangesEnabled){const t=o.runs;let n=0,s=-1,l=-1;for(let e=0;e<t.length;e+=1){const o=n+t[e].text.length;if(a<=o){s=e,l=a-n;break}n=o}if(-1!==s){const n=t[s];if("insert"===n.revision?.type){const t=[...on(o,0,a-1),...on(o,a,Xr(o))],n=c(o,t),s=i.map((e,t)=>t===r?n:e);return qt(e,s,Y(ci(n,a-1)))}const d=n.text[l-1],u={id:`run:${Math.random().toString(36).slice(2,9)}`,text:d,kind:"text",styles:{...n.styles},revision:{id:`rev:${Math.random().toString(36).slice(2,9)}`,type:"delete",author:"User",date:Date.now()}},p=[...on(o,0,a-1),u,...on(o,a,Xr(o))],g=c(o,p),f=i.map((e,t)=>t===r?g:e);return qt(e,f,Y(ci(g,a-1)))}}const n=c(o,[...on(o,0,a-1),...on(o,a,Xr(o))],qn(o,a-1)),s=i.map((e,t)=>t===r?n:e);return qt(e,s,Y(ci(n,a-1)))}if(0===r)return e;const s=i[r-1];if(Ge(e,s,o))return e;const l=c(s,[...s.runs.map(Ea),...o.runs.map(Ea)]),d=[...i.slice(0,r-1),l,...i.slice(r+1)];return qt(e,d,Y(Qr(l,Xr(s),H(s,o))))}function Zu(e){const n=qu(e,"forward");if(void 0!==n)return n;if(!sr(e.selection))return ee(e);const{paragraph:o,index:r,offset:a}=oe(e),i=cr(e);if(a<Xr(o)){if(e.trackChangesEnabled&&Et(e)||M(e,o,a,a+1))return e;if(t(o)){const t={...e,selection:{anchor:ci(o,a),focus:ci(o,a+1)}};return ee(t)}if(e.trackChangesEnabled){const t=o.runs;let n=0,s=-1,l=-1;for(let e=0;e<t.length;e+=1){const o=n+t[e].text.length;if(a<o){s=e,l=a-n;break}n=o}if(-1!==s){const n=t[s];if("insert"===n.revision?.type){const t=[...on(o,0,a),...on(o,a+1,Xr(o))],n=c(o,t),s=i.map((e,t)=>t===r?n:e);return qt(e,s,Y(ci(n,a)))}const d=n.text[l],u={id:`run:${Math.random().toString(36).slice(2,9)}`,text:d,kind:"text",styles:{...n.styles},revision:{id:`rev:${Math.random().toString(36).slice(2,9)}`,type:"delete",author:"User",date:Date.now()}},p=[...on(o,0,a),u,...on(o,a+1,Xr(o))],g=c(o,p),f=i.map((e,t)=>t===r?g:e);return qt(e,f,Y(ci(g,a)))}}const n=c(o,[...on(o,0,a),...on(o,a+1,Xr(o))],qn(o,a)),s=i.map((e,t)=>t===r?n:e);return qt(e,s,Y(ci(n,a)))}if(r>=i.length-1)return e;const s=i[r+1];if(Ge(e,o,s))return e;const l=c(o,[...o.runs.map(Ea),...s.runs.map(Ea)]),d=[...i.slice(0,r),l,...i.slice(r+2)];return qt(e,d,Y(Qr(l,a,H(o,s))))}function Ju(e,t,n,o,r){let a=Ba(n,o,r);const i=Oa(a,t.style?.styleId,e.document.styles);return!r&&i[o]&&(a={...a,[o]:!1}),!r||"superscript"!==o&&"subscript"!==o||(a=Ju(e,t,a,"superscript"===o?"subscript":"superscript",!1)),a}function Qu(e,t){const n=mr(e);if(n.isCollapsed||K(e))return e;const o=cr(e),r=o.slice(n.startIndex,n.endIndex+1).flatMap((t,o)=>{const r=n.startIndex+o,a=r===n.startIndex?n.startParagraphOffset:0,i=r===n.endIndex?n.endParagraphOffset:Xr(t);return on(t,a,i).map(n=>({...n,styles:Oa(n.styles,t.style?.styleId,e.document.styles)}))}).filter(e=>e.text.length>0);if(0===r.length)return e;const a=!r.every(e=>Boolean(e.styles?.[t])),i=o.map((o,r)=>{if(r<n.startIndex||r>n.endIndex)return o;const i=r===n.startIndex?n.startParagraphOffset:0,s=r===n.endIndex?n.endParagraphOffset:Xr(o);return P(e,o,i,s,n=>({...n,styles:Ju(e,o,n.styles,t,a)}))});return qt(e,i,N(i,n))}function ep(e,t,n){const o=mr(e);if(o.isCollapsed||K(e))return e;const r=cr(e).map((r,a)=>{if(a<o.startIndex||a>o.endIndex)return r;const i=a===o.startIndex?o.startParagraphOffset:0,s=a===o.endIndex?o.endParagraphOffset:Xr(r);return P(e,r,i,s,e=>({...e,styles:sa(e.styles,t,n)}))});return qt(e,r,N(r,o))}function tp(e,t){const n=mr(e);if(n.isCollapsed||K(e))return e;const o=cr(e),r=e.document.styles,a=o.map((o,a)=>{if(a<n.startIndex||a>n.endIndex)return o;const i=a===n.startIndex?n.startParagraphOffset:0,s=a===n.endIndex?n.endParagraphOffset:Xr(o);return P(e,o,i,s,e=>{const n=(Oa(e.styles,o.style?.styleId,r).fontSize??14.6667)*Ur,a=Math.max(1,Math.min(1638,n+t));return{...e,styles:sa(e.styles,"fontSize",a/Ur)}})});return qt(e,a,N(a,n))}var np={width:.5,type:"solid",color:"#000000"};function op(e,t){const n={...e??{}};return t?n.textBorder=np:delete n.textBorder,Object.keys(n).length>0?n:void 0}function rp(e){return/\p{L}/u.test(e)}function ap(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 o of e){const e=rp(o);t+=e&&!n?o.toUpperCase():o,n=e}return t}(e);case"toggle":return function(e){let t="";for(const n of e){const e=n.toUpperCase(),o=n.toLowerCase();t+=n===o&&n!==e?e:n===e&&n!==o?o:n}return t}(e);default:return function(e){let t="",n=!0;for(const o of e.toLowerCase())n&&rp(o)?(t+=o.toUpperCase(),n=!1):(t+=o,"."!==o&&"!"!==o&&"?"!==o||(n=!0));return t}(e)}}function ip(e,t){return function(e,t){const n=mr(e);if(n.isCollapsed)return e;const o=cr(e).map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const r=o===n.startIndex?n.startParagraphOffset:0,a=o===n.endIndex?n.endParagraphOffset:Xr(e),i=t(on(e,r,a).map(e=>e.text).join(""));let s=0;return pe(e,r,a,e=>{const t=e.text.length,n=i.slice(s,s+t);return s+=t,{...e,text:n}})});return qt(e,o,N(o,n))}(e,e=>ap(e,t))}var sp=["bold","italic","underline","underlineStyle","underlineColor","strike","doubleStrike","smallCaps","allCaps","superscript","subscript","link"];function lp(e,t){const n=oa(e)??{};delete n.link;for(const o of sp)void 0!==t?.[o]&&Object.assign(n,{[o]:t[o]});return Object.keys(n).length>0?n:void 0}function cp(e,t){if(0===t.length)return[];const n=mr(e),o=cr(e)[n.startIndex];if(!o)return t;const r=qn(o,n.startParagraphOffset);return t.map(e=>({runs:e.runs.map(e=>({...e,styles:lp(r,e.styles)})),style:qa(o.style),list:o.list?{...o.list}:void 0}))}function dp(e){if("undefined"==typeof document||0===e.trim().length)return[];const t=document.createElement("template");t.innerHTML=e;const n=[],o=Array.from(t.content.childNodes),r=(e,t,o)=>{const r=t.length>0?t:[za("")];n.push({runs:r.map(e=>{const t=fr(e);return{text:e.text,styles:oa(e.styles),image:t?{...t}:void 0}}),style:e?at(e):void 0,list:o})},a=(e,t)=>{for(const n of Array.from(e.children))"LI"===n.tagName&&r(n,I(n,void 0),{kind:t,level:0})};for(const i of o){if(i.nodeType===Node.TEXT_NODE){const e=i.textContent??"";e.trim().length>0&&r(null,[za(e)]);continue}if(i.nodeType!==Node.ELEMENT_NODE)continue;const e=i,t=le(e.tagName);if(t){a(e,t);continue}if(y(e.tagName)){r(e,I(e,void 0),"LI"===e.tagName?{kind:"bullet",level:0}:void 0);continue}const n=I(e,void 0);n.length>0&&r(null,n)}return n}async function up(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(),o={anchor:{...n.selection.anchor},focus:{...n.selection.focus}};let r;try{r=await async function(e){const t=navigator.clipboard;let n=/* @__PURE__ */new Error("Clipboard access unavailable"),o=!1,r=!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(Du).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};o=!0,r=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:""};o=!0}catch(i){n=i}if(o)return{kind:r?"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"===r.kind){if("rich"!==t||!e.stateSnapshot)return e.onIssue?.("unsupported"),!1;const o=zu(r.token);if(!o)return e.onIssue?.("unsupported"),!1;if(e.stateSnapshot()!==n)return e.onIssue?.("document-changed"),!1;let a;try{a=await Ou(n,o)}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"!==r.kind)return e.onIssue?.(r.kind),!1;const a="text"!==t?dp(r.html):[],i="merge"===t?cp({...n,selection:o},a):a;if(0===i.length&&0===r.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:o},l=e.applyTableAwareParagraphEdit(a,e=>i.length>0?Wu(e,i):Gu(e,r.text));return s=l.document!==t.document,l}),s&&e.focusInput(),s}function pp(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 gp(e){const t="undefined"!=typeof navigator?navigator.clipboard:void 0;if(t?.writeText)try{return t.writeText(e).then(()=>!0,()=>pp(e))}catch{}return Promise.resolve(pp(e))}async function fp(e,t){if($u(e)){let n;try{n=Nu(e)}catch{return t?.("unsupported"),!1}const o="undefined"!=typeof navigator?navigator.clipboard:void 0;if(!o?.write||"undefined"==typeof ClipboardItem)return t?.("unsupported"),!1;try{const e=new ClipboardItem({[Fu]:new Blob([n.token],{type:Fu.slice(4)})});return await o.write([e]),n.confirm()}catch{return t?.("access-denied"),!1}}const n=await function(e){const t=vi(e);if(!t)return Promise.resolve(!1);const n="undefined"!=typeof navigator?navigator.clipboard:void 0;if(n?.write&&"undefined"!=typeof ClipboardItem)try{const o=Hu(e),r=new ClipboardItem({"text/plain":new Blob([t],{type:"text/plain"}),"text/html":new Blob([o],{type:"text/html"})});return n.write([r]).then(()=>!0,()=>gp(t))}catch{}return gp(t)}(e);return!n&&vi(e)&&t?.("access-denied"),n}function mp(e){return function(e){const[t,n]=co();let o,r=0;kt()&&yn(()=>{r++});const a=()=>{n(void 0),o=void 0},i=()=>{r++,a()},s=async(t,i="rich")=>{const s=++r;a();const l=e.stateSnapshot?.()??e.state(),c=a=>{s===r&&(n({action:t,issue:a,..."paste"===t?{mode:i}:{}}),"access-denied"!==a&&"unsupported"!==a||("paste"!==t||"unsupported"===a&&"rich"!==i||(o={document:l.document,mode:i}),e.focusInput()),e.onIssue?.(a))};if("copy"===t)return fp(l,c);const d={...e,onIssue:c,isReadOnly:()=>s!==r||e.isReadOnly()};return"cut"===t?async function(e){if(e.isReadOnly())return!1;const t=e.stateSnapshot?.()??e.state();if($u(t))return e.onIssue?.("unsupported"),!1;if(!vi(t))return!1;if(!(await fp(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 o=!1;return e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(r=>{if(e.isReadOnly()||r.document!==t.document)return r;const a={...r,selection:n},i=e.applyTableAwareParagraphEdit(a,e=>Yu(e));return o=i.document!==r.document,i}),o&&e.focusInput(),o}(d):up(d,i)},l=()=>{const t=o;return i(),t?.document===e.state().document?t.mode:void 0},c=(t,o)=>{r++,a(),n({action:t,issue:o,..."paste"===t?{mode:"rich"}:{}}),e.onIssue?.(o)};return{notice:t,dismiss:i,reportNativeIssue:c,requestGeneration:()=>r,consumePasteMode:l,copy:()=>s("copy"),cut:()=>s("cut"),paste:(e="rich")=>s("paste",e),hasSelection:()=>vi(e.state()).length>0}}(e)}var hp=/*#__PURE__*/oo("<div class=oasis-editor-clipboard-feedback role=status aria-live=polite aria-atomic=true>"),bp=/*#__PURE__*/oo("<div class=oasis-editor-clipboard-feedback-message data-testid=editor-clipboard-feedback>");function yp(e){const t=Ee();let n;const[o,r]=co(12);Zn(()=>{if(!e.notice())return;const t=n?.parentElement;if(!t)return;const o=()=>{const e=t.getBoundingClientRect(),o=t.querySelector(".oasis-editor-toolbar"),a=o?o.getBoundingClientRect().bottom-e.top+8:12,i=Math.max(12,12-e.top),s=window.innerHeight-e.top-(n?.offsetHeight??0)-12;r(Math.max(i,Math.min(a,s)))};queueMicrotask(o);const a=new ResizeObserver(o);a.observe(t),n&&a.observe(n);const i=t.querySelector(".oasis-editor-toolbar");i&&a.observe(i),window.addEventListener("resize",o),window.addEventListener("scroll",o,!0),yn(()=>{a.disconnect(),window.removeEventListener("resize",o),window.removeEventListener("scroll",o,!0)})});return a=hp(),"function"==typeof n?In(n,a):n=a,W(a,Bn(Qt,{get when(){return e.notice()},children:n=>{return o=bp(),W(o,Bn(_n,{name:"clipboard"}),null),W(o,Bn(At,{get children(){return(e=>{const n=`${/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl+"}${"copy"===e.action?"C":"cut"===e.action?"X":"V"}`,o="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(o,[n])})(n())}}),null),W(o,Bn(Ie,{variant:"ghost",size:"sm",icon:"x",get label(){return t("generic.close")},get onClick(){return e.onDismiss},"data-testid":"editor-clipboard-feedback-close"}),null),o;var o}})),gn(e=>he(a,"top",`${o()}px`)),a;var a}var vp=/[\s\-–—/_([{]/;function xp(e,t){const n=e.trim().toLowerCase();if(0===n.length)return 0;const o=t.toLowerCase();if(o===n)return 1e3;const r=o.indexOf(n);if(r>=0){let e=400;return 0===r?e+=400:!function(e,t){return 0===t||vp.test(e[t-1]??"")}(o,r)?e+=100:e+=200,e+=Math.round(n.length/o.length*50),e}let a=0,i=-1,s=-1,l=0;for(const d of n){const e=o.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 wp(e,t){const n=e.trim().toLowerCase();if(0===n.length)return 0;const o=xp(n,t.label),r=xp(n,t.command),a=Math.max(o??Number.NEGATIVE_INFINITY,(r??Number.NEGATIVE_INFINITY)-50);return Number.isFinite(a)?a:null}var Sp=/*#__PURE__*/oo("<ul id=editor-command-search-listbox class=oasis-command-search-list role=listbox data-testid=editor-command-search-listbox>"),Ip=/*#__PURE__*/oo("<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>"),Cp=/*#__PURE__*/oo("<kbd class=oasis-command-search-shortcut>"),Tp=/*#__PURE__*/oo("<li role=option class=oasis-command-search-option data-testid=editor-command-search-item>");function kp(e){const t=Ee(),[n,o]=co(""),[r,a]=co(0);let i;Zn(()=>{e.isOpen&&(o(""),a(0),queueMicrotask(()=>{i?.focus()}))});const s=wt(()=>function(e,t,n=24){const o=e.trim().toLowerCase();if(0===o.length)return t.map(e=>({...e,score:0})).sort((e,t)=>e.label.localeCompare(t.label)).slice(0,n);const r=[];for(const a of t){const e=wp(o,a);null!==e&&r.push({...a,score:e})}return r.sort((e,t)=>t.score-e.score||e.label.length-t.label.length),r.slice(0,n)}(n(),e.entries,12));Zn(()=>{s(),a(e=>Math.min(e,Math.max(0,s().length-1)))});const l=t=>e.isEnabled(t.command,t.payload),c=t=>{l(t)&&e.onExecute(t)},d=e=>{const t=s().length;0!==t&&a(n=>(n+e+t)%t)},u=t=>{switch(t.key){case"ArrowDown":t.preventDefault(),d(1);break;case"ArrowUp":t.preventDefault(),d(-1);break;case"Enter":{t.preventDefault();const e=s()[r()];e&&c(e);break}case"Escape":t.preventDefault(),e.onClose()}};return Bn(Qt,{get when(){return e.isOpen},get children(){var d=Ip(),p=d.firstChild;return O(d,"click",e.onClose,!0),p.$$keydown=u,p.$$click=e=>e.stopPropagation(),W(p,Bn(k,{id:"editor-command-search-input",get placeholder(){return t("commandSearch.placeholder")},get value(){return n()},onChange:e=>{o(e)},ref(e){"function"==typeof i?i(e):i=e},role:"combobox","aria-autocomplete":"list","aria-expanded":"true","aria-controls":"editor-command-search-listbox",get"aria-activedescendant"(){return qe(()=>!!s()[r()])()?`editor-command-search-option-${r()}`:void 0},"data-testid":"editor-command-search-input",autocomplete:"off",spellcheck:!1}),null),W(p,Bn(At,{class:"oasis-command-search-hint",get children(){return t("commandSearch.hint")}}),null),W(p,Bn(Qt,{get when(){return s().length>0},get fallback(){return Bn(At,{as:"p",class:"oasis-command-search-empty","data-testid":"editor-command-search-empty",get children(){return t("commandSearch.noResults")}})},get children(){var e=Sp();return W(e,Bn(Kn,{get each(){return s()},children:(e,t)=>{const n=()=>t()===r(),o=()=>l(e);return(i=Tp()).$$click=()=>c(e),i.addEventListener("mouseenter",()=>{a(t())}),W(i,Bn(At,{as:"span",get children(){return e.label}}),null),W(i,Bn(Qt,{get when(){return e.shortcut},get children(){var t=Cp();return W(t,()=>e.shortcut),t}}),null),gn(r=>{var a=`editor-command-search-option-${t()}`,s=n(),l=!o()||void 0,c=!!n(),d=!o(),u=e.command;return a!==r.e&&et(i,"id",r.e=a),s!==r.t&&et(i,"aria-selected",r.t=s),l!==r.a&&et(i,"aria-disabled",r.a=l),c!==r.o&&i.classList.toggle("oasis-command-search-option-active",r.o=c),d!==r.i&&i.classList.toggle("oasis-command-search-option-disabled",r.i=d),u!==r.n&&et(i,"data-command",r.n=u),r},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),i;var i}})),e}}),null),W(p,Bn(ro,{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),gn(()=>et(p,"aria-label",t("commandSearch.title"))),d}})}function Pp(e){return e?"string"==typeof e?{command:e}:"object"==typeof e&&"string"==typeof e.name?{command:e.name,payload:e.payload}:null:null}function Rp(e){return Pp(e.command)}Hn(["click","keydown"]);var Bp=!1,Mp=null,Op=null,Ap=null,Fp=[];function Dp(){"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}()?Bp&&(delete window.__oasisCanvasDebug,Bp=!1):Bp||(window.__oasisCanvasDebug={getLastHit:()=>Mp?{...Mp}:null,getLayoutSnapshot:()=>Op?{...Op,surfaceRect:{...Op.surfaceRect},pages:Op.pages.map(e=>({...e})),paragraphs:Op.paragraphs.map(e=>({...e,lines:e.lines.map(e=>({...e,slots:e.slots.map(e=>({...e}))})),tableCell:e.tableCell?{...e.tableCell}:void 0})),inlineImages:Op.inlineImages.map(e=>({...e})),inlineTextBoxes:Op.inlineTextBoxes.map(e=>({...e})),unsupportedRegions:Op.unsupportedRegions.map(e=>({...e}))}:null,getSelection:()=>Ap?{anchor:{...Ap.anchor},focus:{...Ap.focus},activeZone:Ap.activeZone,activeSectionIndex:Ap.activeSectionIndex}:null,getMissEvents:()=>Fp.map(e=>({...e})),clearMissEvents:()=>{Fp=[]}},Bp=!0))}function Ep(e){Bp&&e&&(Mp={timestamp:Date.now(),zone:e.zone,paragraphId:e.paragraphId,paragraphOffset:e.paragraphOffset,source:e.source,missReason:e.missReason,resolvedFromParagraph:e.resolvedFromParagraph})}var Lp=["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 Np(e,t,n){const o=n?.trim();if(!o)return;const r=o.toLowerCase();t.has(r)||(t.add(r),e.push(o))}function zp(e){return function(e){const[t,n]=co([]),o=()=>function(e,t,n=[]){const o=/* @__PURE__ */new Set,r=[],a=[];for(const i of Object.values(e?.styles??{}))Np(r,o,i.textStyle?.fontFamily);Np(r,o,t.fontFamily);for(const i of n)Np(a,o,i);for(const i of Lp)Np(a,o,i);return[...r.sort((e,t)=>e.localeCompare(t)),...a.sort((e,t)=>e.localeCompare(t))]}(e.state().document,e.toolbarStyleState(),t()),r=()=>function(e,t){const n=new Set(Sn);for(const r of Object.values(e?.styles??{})){const e=r.textStyle?.fontSize;"number"==typeof e&&Number.isFinite(e)&&n.add(Jt(e))}const o=Jt(Number(t.fontSize));return Number.isFinite(o)&&o>0&&n.add(o),Array.from(n).sort((e,t)=>e-t)}(e.state().document,e.toolbarStyleState());return{computeFontFamilyOptions:o,computeFontSizeOptions:r,loadLocalFontFamilyOptions:async()=>{if(t().length>0)return;const e=await So();e.length>0&&n(e)}}}(e)}var $p="insertText",Hp="composition",Wp="insertImage",Up="insertTable",jp="moveImage",Vp="splitListItem",Kp="link",_p="imageAlt",Xp="imageCaption",Gp="imageResize",qp="imageCrop",Yp="imageFlip",Zp="imageRotate",Jp="imageTransparency",Qp="imageReset",eg="layoutWrapPolygon",tg="specialIndent",ng="paraBorders",og="paragraphMoveUp",rg="paragraphMoveDown",ag="findReplace",ig="findReplaceAll",sg="tableProperties",lg="paragraph-dialog",cg="font-dialog",dg="copyTextByDrag",ug="moveTextByDrag",pg="mergeTable",gg="splitTable",fg="insertTableColumn",mg="deleteTableColumn",hg="insertTableRow",bg="deleteTableRow",yg="tableShading",vg="tableBorders",xg="tableWidth",wg="tableAlign",Sg="tableCellAlignment",Ig="tableCellVerticalAlign",Cg="tableCellTextDirection",Tg="tableCellWidth",kg="tableColumnWidth",Pg="tableToText",Rg="textToTable",Bg="tableSplitAtRow",Mg="tableSortAscending",Og="tableSortDescending",Ag="tableDelete",Fg="deleteTableCell",Dg="tableAutoFit",Eg="tableRepeatHeaderRows",Lg="tableCellMargins",Ng="tableFormula",zg="tableRowHeight",$g="tableStyleOptions",Hg="tableStyleGallery",Wg="tableDistribute",Ug="layoutWrapPreset",jg="layoutFixedPosition",Vg="shapeFill",Kg="shapeOutline",_g="shapeOutlineWidth",Xg="floatingAlign",Gg="floatingReorder",qg="floatingNudge",Yg="floatingFixedPosition",Zg="floatingRotation",Jg="floatingWrap",Qg="floatingWrapText",ef="floatingPositionPreset",tf="shapePreset",nf="textBoxTextDirection",of="textBoxVerticalAlign",rf="textBoxAlt",af="textBoxRotate",sf="textBoxWidthCm",lf="textBoxHeightCm";function cf(e,t){const n={...e},o=(e,t)=>{null==t?delete n[e]:n[e]=t};return o("align",t.align),o("indentLeft",t.indentLeft),o("indentRight",t.indentRight),o("indentFirstLine",t.indentFirstLine),o("indentHanging",t.indentHanging),n.mirrorIndents=t.mirrorIndents,o("spacingBefore",t.spacingBefore),o("spacingAfter",t.spacingAfter),o("lineHeight",t.lineHeight),o("lineRule",t.lineRule),n.contextualSpacing=t.contextualSpacing,o("outlineLevel",t.outlineLevel),o("shading",t.shading),o("borderTop",t.borders.top),o("borderRight",t.borders.right),o("borderBottom",t.borders.bottom),o("borderLeft",t.borders.left),n.pageBreakBefore=t.pageBreakBefore,n.keepWithNext=t.keepWithNext,n.keepLinesTogether=t.keepLinesTogether,n.widowControl=t.widowControl,o("tabs",t.tabs.length>0?t.tabs:null),n}function df(){return{id:`rev:${Math.random().toString(36).slice(2,9)}`,author:"User",date:Date.now()}}function uf(e,t,n){const o={...e??{}};return null===n?delete o[t]:o[t]=n,Object.keys(o).length>0?o:void 0}function pf(e,t){const n=Pa(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})),o=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,r=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:o,endnotes:r}}}function gf(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:gf(e.blocks,t)}))}))}})}function ff(e,t,n){const o=Pa(e)[t];if(o)return"header"===n?o.header:"footer"===n?o.footer:o.blocks}function mf(e){const t=e.tablePath[e.tablePath.length-1];return t?{...e,rowIndex:t.rowIndex,cellIndex:t.cellIndex}:e}function hf(e){const t=nr(e),n=Va(e.document,e.selection.focus.paragraphId,t);return n?{activeSectionIndex:t,loc:mf(n)}:null}function bf(e,t,n){const o=t[0];if(!o)return e;const r=e[o.tableBlockIndex];if(!r||"table"!==r.type)return e;if(1===t.length){const t=n(r);if(t===r)return e;const a=[...e];return a[o.tableBlockIndex]=t,a}const a=r.rows[o.rowIndex],i=a?.cells[o.cellIndex];if(!a||!i)return e;const s=bf(i.blocks,t.slice(1),n);if(s===i.blocks)return e;const l=[...a.cells];l[o.cellIndex]={...i,blocks:s};const c=[...r.rows];c[o.rowIndex]={...a,cells:l};const d=[...e];return d[o.tableBlockIndex]={...r,rows:c},d}function yf(e,t){return Boolean(e?.some(e=>ta(e).some(e=>e.id===t)))}function vf(e,t,n){if("main"===t)return e.blocks;if("header"===t||"footer"===t){const o=function(e,t,n){return"header"===t?yf(e.firstPageHeader,n)?"firstPage":yf(e.evenPageHeader,n)?"evenPage":"default":yf(e.firstPageFooter,n)?"firstPage":yf(e.evenPageFooter,n)?"evenPage":"default"}(e,t,n);return e[Hr(t,o)]??null}return null}function xf(e,t,n,o){return"main"===t?{...e,blocks:o(e.blocks)}:"header"===t?yf(e.firstPageHeader,n)?{...e,firstPageHeader:o(e.firstPageHeader)}:yf(e.evenPageHeader,n)?{...e,evenPageHeader:o(e.evenPageHeader)}:{...e,header:e.header?o(e.header):e.header}:"footer"===t?yf(e.firstPageFooter,n)?{...e,firstPageFooter:o(e.firstPageFooter)}:yf(e.evenPageFooter,n)?{...e,evenPageFooter:o(e.evenPageFooter)}:{...e,footer:e.footer?o(e.footer):e.footer}:e}function wf(e,t){const n=t[0];if(!n||!e)return null;const o=e[n.tableBlockIndex];if(!o||"table"!==o.type)return null;if(1===t.length)return o;const r=o.rows[n.rowIndex],a=r?.cells[n.cellIndex];return r&&a?wf(a.blocks,t.slice(1)):null}function Sf(e,t,n){const o=t[0];if(!o)return null;const r=e[o.tableBlockIndex];if(!r||"table"!==r.type)return null;if(1===t.length)return[...e.slice(0,o.tableBlockIndex),...n,...e.slice(o.tableBlockIndex+1)];const a=r.rows[o.rowIndex],i=a?.cells[o.cellIndex];if(!a||!i)return null;const s=Sf(i.blocks,t.slice(1),n);if(!s)return null;const l=[...a.cells];l[o.cellIndex]={...i,blocks:s};const c=[...r.rows];c[o.rowIndex]={...a,cells:l};const d=[...e];return d[o.tableBlockIndex]={...r,rows:c},d}function If(e){const t=hf(e);if(!t)return null;const{activeSectionIndex:n,loc:o}=t,r=e.selection.focus.paragraphId;if("footnote"===o.zone)return Tf(e,r);const a=Pa(e.document)[n];return a?vf(a,o.zone,r):null}function Cf(e){const t=e.selection.focus.paragraphId,n=pr(e);if("footnote"===n)return Tf(e,t);const o=nr(e),r=Pa(e.document)[o];return r?vf(r,n,t):null}function Tf(e,t){const n=Ya(e.document,t)?.footnoteId??e.activeFootnoteId,o=e.document.footnotes;return(n?o?.items[n]:void 0)?.blocks??null}function kf(e,t){const n=hf(e);if(!n)return e;const{activeSectionIndex:o,loc:r}=n,a=e.selection.focus.paragraphId,i=e=>Sf(e,r.tablePath,t)??e;if("footnote"===r.zone){const t=Ya(e.document,a)?.footnoteId??e.activeFootnoteId,n=e.document.footnotes,o=t?n?.items[t]:void 0;return t&&n&&o?{...e,document:{...e.document,footnotes:{...n,items:{...n.items,[t]:{...o,blocks:i(o.blocks)}}}}}:e}const s=Pa(e.document).map((e,t)=>t===o?xf(e,r.zone,a,i):e);return{...e,document:{...e.document,sections:s}}}function Pf(e,t){const n=hf(e);if(!n)return e;const{activeSectionIndex:o,loc:r}=n,a=e.selection.focus.paragraphId,i=e=>bf(e,r.tablePath,t);if("footnote"===r.zone){const t=Ya(e.document,a)?.footnoteId??e.activeFootnoteId,n=e.document.footnotes,o=t?n?.items[t]:void 0;return t&&n&&o?{...e,document:{...e.document,footnotes:{...n,items:{...n.items,[t]:{...o,blocks:i(o.blocks)}}}}}:e}const s=Pa(e.document).map((e,t)=>t===o?xf(e,r.zone,a,i):e);return{...e,document:{...e.document,sections:s}}}var Rf={width:.5,type:"solid",color:"#000000"},Bf={width:0,type:"none",color:"transparent"};function Mf(e){const t=nr(e),n=Va(e.document,e.selection.anchor.paragraphId,t),o=Va(e.document,e.selection.focus.paragraphId,t);if(!n||!o||n.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 o=e[n],r=t[n];if(o.tableBlockIndex!==r.tableBlockIndex)return!1;if(n<e.length-1&&(o.rowIndex!==r.rowIndex||o.cellIndex!==r.cellIndex))return!1}return!0}(n.tablePath,o.tablePath))return null;const r=ff(e.document,t,n.zone);if(!r)return null;const a=Xa(r,n.tablePath),i=Xa(r,o.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=o.tablePath[o.tablePath.length-1];if(!c||!d)return null;const u=Or(s.table),p=u.find(e=>e.rowIndex===c.rowIndex&&e.cellIndex===c.cellIndex),g=u.find(e=>e.rowIndex===d.rowIndex&&e.cellIndex===d.cellIndex);if(!p||!g)return null;const f=Math.min(p.visualRowIndex,g.visualRowIndex),m=Math.max(p.visualRowIndex+p.rowSpan-1,g.visualRowIndex+g.rowSpan-1),h=Math.min(p.visualColumnIndex,g.visualColumnIndex),b=Math.max(p.visualColumnIndex+p.colSpan-1,g.visualColumnIndex+g.colSpan-1);return{entries:u,selectedEntries:u.filter(e=>e.visualRowIndex<=m&&e.visualRowIndex+e.rowSpan-1>=f&&e.visualColumnIndex<=b&&e.visualColumnIndex+e.colSpan-1>=h),startRow:f,endRow:m,startCol:h,endCol:b}}function Of(e,t,n){const o=function(e){const t=/* @__PURE__ */new Set,n=Mf(e);if(!n)return t;for(const o of n.selectedEntries)for(const e of o.cell.blocks)for(const n of ta(e))t.add(n.id);return t}(e);if(0===o.size)for(const i of function(e){const t=/* @__PURE__ */new Set,n=mr(e),o=cr(e);for(let r=n.startIndex;r<=n.endIndex;r+=1)t.add(o[r].id);return t}(e))o.add(i);const r=o=>{let r=o.style;return e.trackChangesEnabled&&"revision"!==t&&"propertyRevision"!==t&&!r?.propertyRevision&&(r={...r??{},propertyRevision:{...df(),type:"property",previous:{...r??{}}}}),{...o,style:uf(r,t,n)}},a=Pa(e.document).map(e=>({...e,blocks:it(e.blocks,o,r),header:e.header?it(e.header,o,r):void 0,footer:e.footer?it(e.footer,o,r):void 0}));return{...e,document:{...e.document,sections:a}}}function Af(e,t){let n=Of(e,"borderTop",t);return n=Of(n,"borderRight",t),n=Of(n,"borderBottom",t),n=Of(n,"borderLeft",t),n}function Ff(e,t,n){const o=function(e){const t=mr(e),n=cr(e),o=/* @__PURE__ */new Set;for(let r=t.startIndex;r<=t.endIndex;r+=1)o.add(n[r].id);return o}(e),r=a=>a.map(a=>{if("paragraph"===a.type)return a;const i=a.rows.map(e=>({...e,cells:e.cells.map(e=>({...e,blocks:r(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,o)?(o=>{let r=o.style;return e.trackChangesEnabled&&"revision"!==t&&!r?.revision&&(r={...r??{},revision:{...df(),type:"property",previous:{...r??{}}}}),{...o,style:uf(r,t,n)}})(s):s});return pf(e,r)}function Df(e,t,n,o){const r=r=>{if(r.id!==t)return r;let a=r.style;return e.trackChangesEnabled&&"revision"!==n&&!a?.revision&&(a={...a??{},revision:{...df(),type:"property",previous:{...a??{}}}}),{...r,style:uf(a,n,o)}};return pf(e,e=>gf(e,r))}function Ef(e,t,n){const o=hf(e);if(!o)return e;return Pf(e,r=>{const a=r.rows.map((r,a)=>a===o.loc.rowIndex?(()=>{let o=r.style;return e.trackChangesEnabled&&"revision"!==t&&"propertyRevision"!==t&&!o?.propertyRevision&&(o={...o??{},propertyRevision:{...df(),type:"property",previous:{...o??{}}}}),{...r,style:uf(o,t,n)}})():r);return{...r,rows:a}})}function Lf(e,t){const n=hf(e);if(!n)return e;return Pf(e,o=>({...o,rows:o.rows.map((o,r)=>{if(r!==n.loc.rowIndex)return o;let a=o.style;e.trackChangesEnabled&&!a?.propertyRevision&&(a={...a??{},propertyRevision:{...df(),type:"property",previous:{...a??{},isHeader:o.isHeader}}});const i=null===t?void 0:t;return{...o,isHeader:i,style:uf(a,"isHeader",i??null)}})}))}function Nf(e,t,n){const o=o=>{if(o.id!==t)return o;const r=o.rows.map((t,o)=>{if(!Object.prototype.hasOwnProperty.call(n,o))return t;let r=t.style;return e.trackChangesEnabled&&!r?.propertyRevision&&(r={...r??{},propertyRevision:{...df(),type:"property",previous:{...r??{}}}}),{...t,style:uf(r,"height",n[o])}});return{...o,rows:r}};return pf(e,e=>gf(e,o))}function zf(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*Ur:null}if(!/^[+-]?\d+(\.\d+)?$/.test(t))return null;const n=Number.parseFloat(t);return Number.isFinite(n)?n:null}function $f(e,t,n,o,r){const a=a=>{if(a.id!==t)return a;const i=Or(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=zf(n[e]);if(null!==t){c[e]=Math.max(1,t),d=!0;continue}const o=a.gridCols?.[e];if(!("number"==typeof o&&Number.isFinite(o)&&o>0)){u=!1;break}c[e]=o}const p=a.rows.map((t,o)=>{const r=t.cells.map((t,r)=>{const a=s.get(`${o}:${r}`);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?{...df(),type:"property",previous:{...t.style??{}}}:t.style?.propertyRevision;return{...t,style:{...t.style??{},width:i,...n?{propertyRevision:n}:{}}}}return t});return{...t,cells:r}}),g={...a.style??{}};return!e.trackChangesEnabled||g.revision||void 0===o&&void 0===r||(g.revision={...df(),type:"property",previous:{...a.style??{}}}),void 0!==o&&(g.width=o),void 0!==r&&(g.indentLeft="number"==typeof r?r:Number(r)),{...a,rows:p,gridCols:d&&u?c:a.gridCols,gridRevision:e.trackChangesEnabled&&d&&u&&!a.gridRevision?{...df(),type:"grid",previous:[...a.gridCols??[]]}:a.gridRevision,style:Object.keys(g).length>0?g:void 0}};return pf(e,e=>gf(e,a))}function Hf(e){const t=hf(e);if(!t)return e;const n=If(e);if(!n)return e;const o=wf(n,t.loc.tablePath);if(!o)return e;const r=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(zo(n));return t}(o);if(0===r.length)return e;const a=kf(e,r);if(a===e)return e;const i=r[0];return{...a,selection:Y(ci(i,0))}}function Wf(e){if(hf(e))return e;if(!Cf(e))return e;const t=cr(e);if(0===t.length)return e;const n=mr(e,t),o=t.slice(n.startIndex,n.endIndex+1);if(0===o.length)return e;const r=function(e){const t=e.map(Uf),n=Math.max(1,...t.map(e=>e.length)),o=t.map(e=>Ra(Array.from({length:n},(t,n)=>{const o=e[n]??[],r={id:Da("paragraph"),type:"paragraph",runs:o.length>0?o:[Zr("")]};return na([r])})));return Ga(o)}(o),a=o[0].id,i=o[o.length-1].id;let s=null,l=!1;const c=function(e,t){const n=e.selection.focus.paragraphId,o=pr(e),r=nr(e);if("footnote"===o){const o=Ya(e.document,n)?.footnoteId??e.activeFootnoteId,r=e.document.footnotes,a=o?r?.items[o]:void 0;return o&&r&&a?{...e,document:{...e.document,footnotes:{...r,items:{...r.items,[o]:{...a,blocks:t(a.blocks)}}}}}:e}const a=Pa(e.document).map((e,a)=>a===r?xf(e,o,n,t):e);return{...e,document:{...e.document,sections:a}}}(e,e=>{const{nextBlocks:t,cell:n}=function(e,t,n,o){let r=-1,a=-1;for(let s=0;s<e.length;s+=1){const o=e[s];"paragraph"===o.type&&(o.id===t&&(r=s),o.id===n&&(a=s))}if(-1===r||-1===a||r>a)return{nextBlocks:null,cell:null};for(let s=r;s<=a;s+=1)if("paragraph"!==e[s].type)return{nextBlocks:null,cell:null};const i=o.rows[0]?.cells[0]?.blocks.find(e=>"paragraph"===e.type);return{nextBlocks:[...e.slice(0,r),o,...e.slice(a+1)],cell:i??null}}(e,a,i,r);return t&&n?(s=n,l=!0,t):e});return l&&s?{...c,selection:Y(ci(s,0))}:e}function Uf(e){const t=[];let n=[];const o=()=>{n.length>0&&t.push(n),n=[]};for(const r of e.runs){const e=r.text.split("\t");for(let t=0;t<e.length;t+=1){t>0&&o();const a=e[t];if(a.length>0){const e=Ea(r);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 jf(e,t){const n=hf(e);if(!n)return e;const o=n.loc.cellIndex;return Pf(e,e=>{const n=function(e,t,n){const o=[],r=[];for(const l of e.rows)l.isHeader?o.push(l):r.push(l);if(r.length<2)return e.rows;const a="ascending"===n?1:-1,i=[...r].sort((e,n)=>{const o=Vf(e.cells[t]),r=Vf(n.cells[t]);return o.localeCompare(r,void 0,{numeric:!0})*a}),s=[...o,...i];return s.length===e.rows.length&&s.every((t,n)=>t===e.rows[n])?e.rows:s}(e,o,t);return n===e.rows?e:{...e,rows:n}})}function Vf(e){return e?e.blocks.flatMap(e=>"paragraph"===e.type?[e]:ta(e)).map(e=>e.runs.map(e=>e.text).join("")).join("\n"):""}function Kf(e){return!0===e.isHeader}function _f(e){return null!==hf(e)}function Xf(e){return null!==hf(e)}var Gf=/* @__PURE__ */new Set(["left","center","right"]);function qf(e,t){const n=hf(e);if(!n)return e;if(null!==t&&!Gf.has(t))return e;const o=function(e,t){const n=hf(e);if(!n)return null;const o=Xa(t,n.loc.tablePath);return(o?.[o.length-1])?.table??null}(e,ff(e.document,n.activeSectionIndex,n.loc.zone)??[]);if(!o)return e;const r=o.style?.align,a=null===t?void 0:t;return r===a?e:Ff(e,"align",a)}function Yf(e){return null!==hf(e)}var Zf=["SUM","AVERAGE","COUNT","MIN","MAX"];function Jf(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(),o=t[2].toUpperCase();return Zf.includes(n)&&["ABOVE","BELOW","LEFT","RIGHT"].includes(o)?{function:n,direction:o}:null}(t);if(!n)return e;const o=hf(e);if(!o)return e;const r=If(e);if(!r)return e;const a=wf(r,o.loc.tablePath);if(!a)return e;const i=function(e,t,n){const o=Or(e),r=o.find(e=>e.rowIndex===n.rowIndex&&e.cellIndex===n.cellIndex);if(!r)return[];const a=[];for(const i of o){if(i.rowIndex===n.rowIndex&&i.cellIndex===n.cellIndex)continue;if(!em(r,i,t))continue;if(!tm(r,i,t))continue;const e=nm(Qf(i.cell));null!==e&&a.push(e)}return a}(a,n.direction,o.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=o.loc.rowIndex,c=o.loc.cellIndex,d=Pf(e,e=>({...e,rows:e.rows.map((e,t)=>t!==l?e:{...e,cells:e.cells.map((e,t)=>t!==c?e:{...e,blocks:[Ka(s)]})})}));if(d===e)return e;const u=Ka(s);return{...d,selection:Y(ci(u,s.length))}}function Qf(e){return e?e.blocks.flatMap(e=>"paragraph"===e.type?[e]:ta(e)).map(e=>e.runs.map(e=>e.text).join("")).join("\n"):""}function em(e,t,n){if("LEFT"===n||"RIGHT"===n){const n=e.visualRowIndex+e.rowSpan,o=t.visualRowIndex+t.rowSpan;return e.visualRowIndex<o&&t.visualRowIndex<n}const o=e.visualColumnIndex+e.colSpan,r=t.visualColumnIndex+t.colSpan;return e.visualColumnIndex<r&&t.visualColumnIndex<o}function tm(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 nm(e){const t=/\d+(?:[.,]\d+)?/.exec(e);if(!t)return null;const n=t[0].replace(",","."),o=Number(n);return Number.isFinite(o)?o:null}function om(e,t){const n=function(e){const t=hf(e);if(!t)return null;const n=If(e);if(!n)return null;const o=wf(n,t.loc.tablePath);if(!o)return null;const r=Or(o),a=r.find(e=>e.rowIndex===t.loc.rowIndex&&e.cellIndex===t.loc.cellIndex);return a?{table:o,entries:r,active:a}:null}(e);if(!n)return e;const{table:o,entries:r,active:a}=n,i=function(e,t,n,o){switch(o){case"cell":return[n];case"row":{const e=n.visualRowIndex,o=n.visualRowIndex+n.rowSpan;return t.filter(t=>{const n=t.visualRowIndex,r=t.visualRowIndex+t.rowSpan;return n<o&&e<r})}case"column":{const e=n.visualColumnIndex,o=n.visualColumnIndex+n.colSpan;return t.filter(t=>{const n=t.visualColumnIndex,r=t.visualColumnIndex+t.colSpan;return n<o&&e<r})}case"table":return[...t]}}(0,r,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=rm(l),u=rm(c),p=d[0],g=u[u.length-1];return p&&g?{...e,selection:{anchor:ci(p,0),focus:ci(g,oi(g).length)}}:e}function rm(e){return e.blocks.flatMap(ta)}function am(e){const t=function(e){const t=hf(e);if(!t)return null;const n=If(e);if(!n)return null;const o=wf(n,t.loc.tablePath);return o?o.rows[t.loc.rowIndex]??null:null}(e);return Boolean(t&&t.cells.length>1)}function im(e){const t=hf(e);if(!t)return e;const n=If(e);if(!n)return e;const o=wf(n,t.loc.tablePath);if(!o)return e;const r=t.loc.rowIndex,a=t.loc.cellIndex,i=o.rows[r];if(!i||i.cells.length<=1||a>=i.cells.length)return e;const s=Pf(e,e=>{const t=e.rows.map((e,t)=>{if(t!==r)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(ta)[0]??null:null;return c?{...s,selection:Y(ci(c,0))}:s}var sm={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 lm(e){const t=nr(e),n=Va(e.document,e.selection.focus.paragraphId,t),o=n?.tablePath[n.tablePath.length-1];if(!n||!o)return null;const r=Xa(function(e,t){const n=Pa(e.document)[nr(e)];return n?"header"===t?n.header??[]:"footer"===t?n.footer??[]:n.blocks:[]}(e,n.zone),n.tablePath),a=r?.[r.length-1]?.table;if(!a)return null;const i=Or(a).find(e=>e.rowIndex===o.rowIndex&&e.cellIndex===o.cellIndex);return{table:a,tableId:a.id,rowIndex:o.rowIndex,cellIndex:o.cellIndex,visualColumnIndex:i?.visualColumnIndex??o.cellIndex}}function cm(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 dm(e){return!!e&&"none"!==e.type&&e.width>0}function um(e,t="table"){const n=cm(e.table.style?.width),o=e.table.rows[e.rowIndex],r=o?.cells[e.cellIndex],a=cm(o?.style?.height),i=cm(r?.style?.width),s=e.table.gridCols?.[e.visualColumnIndex],l=cm(s),c=r?.style??{},d=[c.borderTop,c.borderRight,c.borderBottom,c.borderLeft,c.borderStart,c.borderEnd,c.borderTopLeftToBottomRight,c.borderTopRightToBottomLeft].filter(dm)[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{...sm,activeTab:t,tableWidth:n.value,tableWidthUnit:n.unit,tableAlign:e.table.style?.align??"",tableIndentLeft:cm(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:o?.style?.heightRule??"",repeatHeader:Boolean(o?.isHeader),allowBreakAcrossPages:!0!==o?.style?.cantSplit,hiddenRow:!0===o?.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:dm(c.borderTop),borderRight:dm(c.borderRight),borderBottom:dm(c.borderBottom),borderLeft:dm(c.borderLeft),borderStart:dm(c.borderStart),borderEnd:dm(c.borderEnd),borderTopLeftToBottomRight:dm(c.borderTopLeftToBottomRight),borderTopRightToBottomLeft:dm(c.borderTopRightToBottomLeft),shading:c.shading??"",altTitle:e.table.style?.altTitle??"",altDescription:e.table.style?.altDescription??""}}function pm(e,t,n){return Of(e,t,n)}function gm(e){return Boolean(lm(e))}function fm(e,t="table"){const n=lm(e);return n?um(n,t):null}function mm(e){const t=()=>gm(e.state());return{isInsideTable:t,openTablePropertiesDialog:(t="table")=>{const n=fm(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=lm(e);if(!n)return e;let o=e;return o=Df(o,n.tableId,"width",t.tableWidth),o=Df(o,n.tableId,"align",t.tableAlign),o=Df(o,n.tableId,"indentLeft",t.tableIndentLeft),o=Df(o,n.tableId,"floating",t.tableFloating),o=Df(o,n.tableId,"tblOverlap",t.tableOverlap),o=Df(o,n.tableId,"altTitle",t.altTitle),o=Df(o,n.tableId,"altDescription",t.altDescription),o=Lf(o,t.repeatHeader),o=Ef(o,"height",t.rowHeight),o=Ef(o,"heightRule",t.rowHeightRule),o=Ef(o,"cantSplit",t.cantSplit),o=Ef(o,"hidden",t.hiddenRow),null!==t.columnWidth&&(o=$f(o,n.tableId,{[n.visualColumnIndex]:t.columnWidth})),o=pm(o,"width",t.cellWidth),o=pm(o,"verticalAlign",t.cellVerticalAlign),o=pm(o,"textDirection",t.cellTextDirection),o=pm(o,"noWrap",t.cellNoWrap),o=pm(o,"fitText",t.cellFitText),o=pm(o,"hideMark",t.cellHideMark),o=pm(o,"paddingTop",t.margins.top),o=pm(o,"paddingRight",t.margins.right),o=pm(o,"paddingBottom",t.margins.bottom),o=pm(o,"paddingLeft",t.margins.left),o=pm(o,"borderTop",t.borders.top),o=pm(o,"borderRight",t.borders.right),o=pm(o,"borderBottom",t.borders.bottom),o=pm(o,"borderLeft",t.borders.left),o=pm(o,"borderStart",t.borders.start),o=pm(o,"borderEnd",t.borders.end),o=pm(o,"borderTopLeftToBottomRight",t.borders.topLeftToBottomRight),o=pm(o,"borderTopRightToBottomLeft",t.borders.topRightToBottomLeft),o=pm(o,"shading",t.shading),o}(e,n),{mergeKey:sg}),e.focusInput())}}}function hm(e){return function(e){const t=e.t,n=e.clipboardActions??mp({...e,onIssue:t=>e.logger.warn("contextMenu:clipboard:not-completed",{issue:t})}),o=n.copy,r=n.cut,a=()=>n.paste("rich"),i=()=>{const n=!sr(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:()=>{r()}},{id:"copy",label:t("contextmenu.copy"),icon:"copy",shortcut:"Ctrl+C",disabled:!n,testId:"editor-context-menu-copy",onSelect:()=>{o()}},{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:o,programmaticCut:r,programmaticPaste:a}}(e)}function bm(e){const{state:t,tableOps:n,applyTableContextCommand:o}=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:()=>o(e=>n.mergeSelectedTable(e),pg),split:()=>o(e=>n.splitSelectedTable(e),gg),insertColumnBefore:()=>o(e=>n.insertSelectedTableColumn(e,-1),fg),insertColumnAfter:()=>o(e=>n.insertSelectedTableColumn(e,1),fg),deleteColumn:()=>o(e=>n.deleteSelectedTableColumn(e),mg),insertRowBefore:()=>o(e=>n.insertSelectedTableRow(e,-1),hg),insertRowAfter:()=>o(e=>n.insertSelectedTableRow(e,1),hg),deleteRow:()=>o(e=>n.deleteSelectedTableRow(e),bg)}}function ym(e){return function(e){const{computeFontFamilyOptions:t,computeFontSizeOptions:n,loadLocalFontFamilyOptions:o}=zp({state:e.state,toolbarStyleState:e.toolbarStyleState}),r=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()||(sr(e.selection())||(e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(e=>{let o=e;t.fontFamily!==(n.fontFamily||null)&&(o=ep(o,"fontFamily",t.fontFamily)),t.fontSize!==(n.fontSize?Number(n.fontSize):null)&&(o=ep(o,"fontSize",Yn(t.fontSize)));const r="automatic"===n.colorMode?null:n.color||null;t.color!==r&&(o=ep(o,"color",t.color)),(t.highlight??"")!==(n.highlight??"")&&(o=ep(o,"highlight",t.highlight)),(t.shading??"")!==(n.shading??"")&&(o=ep(o,"shading",t.shading)),t.bold!==Boolean(n.bold)&&(o=Qu(o,"bold")),t.italic!==Boolean(n.italic)&&(o=Qu(o,"italic"));const a=n.underline?n.underlineStyle??"single":null;(t.underlineStyle??null)!==(a??null)&&(o=ep(o,"underlineStyle",t.underlineStyle));const i=n.underline&&n.underlineColor||null;(t.underlineColor??null)!==(i??null)&&(o=ep(o,"underlineColor",t.underlineColor)),t.underline!==Boolean(n.underline)&&(o=Qu(o,"underline")),t.strike!==Boolean(n.strike)&&(o=Qu(o,"strike")),t.doubleStrike!==Boolean(n.doubleStrike)&&(o=Qu(o,"doubleStrike")),t.superscript!==Boolean(n.superscript)&&(o=Qu(o,"superscript")),t.subscript!==Boolean(n.subscript)&&(o=Qu(o,"subscript")),t.superscript&&t.subscript&&(o=Qu(o,"subscript")),t.strike&&t.doubleStrike&&(o=Qu(o,"doubleStrike")),t.smallCaps!==Boolean(n.smallCaps)&&(o=Qu(o,"smallCaps")),t.allCaps!==Boolean(n.allCaps)&&(o=Qu(o,"allCaps")),t.hidden!==Boolean(n.hidden)&&(o=Qu(o,"hidden"));const s=n.characterScale?Number(n.characterScale):null;(t.characterScale??null)!==(s??null)&&(o=ep(o,"characterScale",t.characterScale));const l=n.characterSpacing?Number(n.characterSpacing):null;(t.characterSpacing??null)!==(l??null)&&(o=ep(o,"characterSpacing",t.characterSpacing));const c=n.baselineShift?Number(n.baselineShift):null;(t.baselineShift??null)!==(c??null)&&(o=ep(o,"baselineShift",t.baselineShift));const d=n.kerningThreshold?Number(n.kerningThreshold):null;(t.kerningThreshold??null)!==(d??null)&&(o=ep(o,"kerningThreshold",t.kerningThreshold)),(t.ligatures??null)!==(n.ligatures||null)&&(o=ep(o,"ligatures",t.ligatures)),(t.numberSpacing??null)!==(n.numberSpacing||null)&&(o=ep(o,"numberSpacing",t.numberSpacing)),(t.numberForm??null)!==(n.numberForm||null)&&(o=ep(o,"numberForm",t.numberForm));const u=n.stylisticSet?Number(n.stylisticSet):null;return(t.stylisticSet??null)!==(u??null)&&(o=ep(o,"stylisticSet",t.stylisticSet)),t.contextualAlternates!==Boolean(n.contextualAlternates)&&(o=Qu(o,"contextualAlternates")),o},{mergeKey:cg})),e.focusInput())}}}({toolbarStyleState:e.toolbarStyleState,selection:e.selection,isReadOnly:e.isReadOnly,loadLocalFontFamilyOptions:o,setFontDialog:e.setFontDialog,setContextMenu:e.setContextMenu,clearPreferredColumn:e.clearPreferredColumn,resetTransactionGrouping:e.resetTransactionGrouping,applyTransactionalState:e.applyTransactionalState,focusInput:e.focusInput}),a=r.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(vn,e)),void e.focusInput();const o=e=>{if(""===e.trim())return null;const t=Number(e);return Number.isFinite(t)?t:null};e.applyTransactionalState(e=>{let r=e;t.align!==(n.align||null)&&(r=se(r,"align",t.align)),t.indentLeft!==o(n.indentLeft)&&(r=se(r,"indentLeft",t.indentLeft)),t.indentRight!==o(n.indentRight)&&(r=se(r,"indentRight",t.indentRight)),t.indentFirstLine!==o(n.indentFirstLine)&&(r=se(r,"indentFirstLine",t.indentFirstLine)),t.indentHanging!==o(n.indentHanging)&&(r=se(r,"indentHanging",t.indentHanging)),t.spacingBefore!==o(n.spacingBefore)&&(r=se(r,"spacingBefore",t.spacingBefore)),t.spacingAfter!==o(n.spacingAfter)&&(r=se(r,"spacingAfter",t.spacingAfter)),t.lineHeight!==o(n.lineHeight)&&(r=se(r,"lineHeight",t.lineHeight));const a=n.lineRule||null;t.lineRule!==a&&(r=se(r,"lineRule",t.lineRule)),t.shading!==(n.shading||null)&&(r=se(r,"shading",t.shading)),t.mirrorIndents!==(n.mirrorIndents??!1)&&(r=se(r,"mirrorIndents",t.mirrorIndents)),t.contextualSpacing!==(n.contextualSpacing??!1)&&(r=se(r,"contextualSpacing",t.contextualSpacing));const i=""===n.outlineLevel.trim()?null:Number(n.outlineLevel);t.outlineLevel!==i&&(r=se(r,"outlineLevel",t.outlineLevel)),t.pageBreakBefore!==(n.pageBreakBefore??!1)&&(r=se(r,"pageBreakBefore",t.pageBreakBefore)),t.keepWithNext!==(n.keepWithNext??!1)&&(r=se(r,"keepWithNext",t.keepWithNext)),t.keepLinesTogether!==(n.keepLinesTogether??!1)&&(r=se(r,"keepLinesTogether",t.keepLinesTogether)),t.widowControl!==(n.widowControl??!0)&&(r=se(r,"widowControl",t.widowControl)),t.tabChanges?.length?r=t.tabChanges.reduce(vn,r):JSON.stringify(t.tabs)!==JSON.stringify(n.tabs??[])&&(r=se(r,"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])&&(r=se(r,t,c[t]));return r},{mergeKey:lg}),e.focusInput()},setParagraphDialogDefault:t=>{e.isReadOnly()||(e.resetTransactionGrouping(),e.applyTransactionalState(e=>{const n=e.document.styles,o=ua(n);if(!o||!n?.[o])return e;const r=n[o];return{...e,document:{...e.document,styles:{...n,[o]:{...r,paragraphStyle:cf(r.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=mm({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=hm({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:bm({state:e.state,tableOps:e.tableOps,isInsideTable:l.isInsideTable,openTablePropertiesDialog:c,applyTableContextCommand:d})});return{computeFontFamilyOptions:t,computeFontSizeOptions:n,applyFontDialogValues:r.applyFontDialogValues,applyParagraphDialogValues:i.applyParagraphDialogValues,setParagraphDialogDefault:i.setParagraphDialogDefault,applyTablePropertiesDialogValues:l.applyTablePropertiesDialogValues,buildContextMenuItems:u.buildContextMenuItems,handleEditorContextMenu:u.handleEditorContextMenu,closeContextMenu:u.closeContextMenu}}(e)}function vm(e){const t=wt(()=>{const t=e.targetPos(),n=e.surfaceRef;if(!n)return null;const o=e.snapshotProvider.getCanvasLayoutSnapshot({surface:n,state:e.state,documentLayout:e.documentLayout(),zoomFactor:e.zoomFactor?.()});let r=0,a=0,i=28;if(o){const n=cr(e.state).find(e=>e.id===t.paragraphId),r=n?Br(n,t):0,a=Un(o,t,r);if(a)return{viewportLeft:a.left,viewportTop:a.top,height:Math.min(a.height||28,32)};const i=Ze(o,t.paragraphId,"end");if(i)return{viewportLeft:i.left,viewportTop:i.top,height:i.height||28}}const s=e.caretViewport?.()??null;if(s)return r=s.left,a=s.top,i=Math.max(12,Math.min(36,s.height)),{viewportLeft:r,viewportTop:a,height:i};const l=e.pointerPos?.()??null;return l?(r=l.x,a=l.y-12,i=24,{viewportLeft:r,viewportTop:a,height:i}):{viewportLeft:r,viewportTop:a,height:i}});return Bn(Qt,{get when(){return t()},children:e=>Bn(fn,{active:!0,fixed:!0,get left(){return e().viewportLeft},get top(){return e().viewportTop},get height(){return e().height}})})}var xm=/*#__PURE__*/oo("<div class=oasis-editor-table-resize-guide>"),wm=/*#__PURE__*/oo("<div class=oasis-editor-table-resize-outline>"),Sm=/*#__PURE__*/oo("<img class=oasis-editor-image-ghost>"),Im=/*#__PURE__*/oo("<div class=oasis-editor-table-ghost>");function Cm(e){return[Bn(Qt,{get when(){return e.tableResize.resizing()},children:e=>{return t=xm(),gn(n=>{var o=!("column"!==e().type),r=!("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 o!==n.e&&t.classList.toggle("oasis-editor-table-resize-guide-column",n.e=o),r!==n.t&&t.classList.toggle("oasis-editor-table-resize-guide-row",n.t=r),n.a=Ot(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t;var t}}),Bn(Qt,{get when(){return e.tableCornerResize.previewRect()},children:e=>{return t=wm(),gn(n=>{var o=`${e().left}px`,r=`${e().top}px`,a=`${e().width}px`,i=`${e().height}px`;return o!==n.e&&he(t,"left",n.e=o),r!==n.t&&he(t,"top",n.t=r),a!==n.a&&he(t,"width",n.a=a),i!==n.o&&he(t,"height",n.o=i),n},{e:void 0,t:void 0,a:void 0,o:void 0}),t;var t}}),Bn(Qt,{get when(){return qe(()=>!!e.imageOps.dragging())()&&e.imageOps.draggedImageInfo()},children:t=>{return n=Sm(),gn(o=>{var r=t().src,a=`${t().width}px`,i=`${t().height}px`,s=e.imageOps.mousePos().x-t().offsetX+"px",l=e.imageOps.mousePos().y-t().offsetY+"px";return r!==o.e&&et(n,"src",o.e=r),a!==o.t&&he(n,"width",o.t=a),i!==o.a&&he(n,"height",o.a=i),s!==o.o&&he(n,"left",o.o=s),l!==o.i&&he(n,"top",o.i=l),o},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),n;var n}}),Bn(Qt,{get when(){return qe(()=>!!e.tableDrag.dragging())()&&e.tableDrag.draggedTableInfo()},children:t=>{return n=Im(),gn(o=>{var r=`${t().width}px`,a=`${t().height}px`,i=e.tableDrag.mousePos().x-t().offsetX+"px",s=e.tableDrag.mousePos().y-t().offsetY+"px";return r!==o.e&&he(n,"width",o.e=r),a!==o.t&&he(n,"height",o.t=a),i!==o.a&&he(n,"left",o.a=i),s!==o.o&&he(n,"top",o.o=s),o},{e:void 0,t:void 0,a:void 0,o:void 0}),n;var n}}),Bn(Qt,{get when(){return qe(()=>!!e.tableDrag.dragging())()&&e.tableDrag.dropTargetPos()},children:t=>Bn(vm,{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})}),Bn(Qt,{get when(){return qe(()=>!!e.imageOps.dragging())()&&e.imageOps.dropTargetPos()},children:t=>Bn(vm,{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})}),Bn(Qt,{get when(){return qe(()=>!!e.textDrag.dragging())()&&e.textDrag.dropTargetPos()},children:t=>Bn(vm,{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 Tm(e){return[Bn(St,{variant:"secondary",get onClick(){return e.onCancel},get"data-testid"(){return e.cancelTestId},get children(){return e.cancelLabel}}),Bn(St,{variant:"primary",get onClick(){return e.onConfirm},get"data-testid"(){return e.confirmTestId},get children(){return e.confirmLabel}})]}function km(e){const t=Ee(),[n,o]=co(e.initialValue);let r;Zn(()=>{e.isOpen&&(o(e.initialValue),setTimeout(()=>r?.focus(),50))});const a=()=>{e.onConfirm(n()),e.onClose()};return Bn(ie,{get isOpen(){return e.isOpen},get title(){return e.title},get onClose(){return e.onClose},get footer(){return Bn(Tm,{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 Bn(k,{ref(e){"function"==typeof r?r(e):r=e},get label(){return e.label},get value(){return n()},onChange:o,onKeyDown:e=>"Enter"===e.key&&a(),get placeholder(){return e.placeholder},get"data-testid"(){return e.testIds?.input}})}})}function Pm(e){const t=Ee();return Bn(km,{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 Rm(e){const t=Ee();return Bn(km,{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 Bm(e){const t=Ee();return Bn(km,{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 Mm=/*#__PURE__*/oo("<div class=oasis-editor-comment-composer-parent data-testid=comment-reply-context>"),Om=/*#__PURE__*/oo("<div class=oasis-editor-comment-composer>");function Am(e){const t=Ee(),[n,o]=co(""),[r,a]=co("");let i;const s=e.composer.draft,l=()=>("edit"===s()?.mode||n().trim().length>0)&&r().trim().length>0,c=()=>{l()&&e.composer.submit(n(),r())};return Zn(()=>{s()&&(o("edit"===s()?.mode?s()?.commentAuthor??"":e.composer.authorName()),a("edit"===s()?.mode?s()?.commentText??"":""),queueMicrotask(()=>i?.focus()))}),Bn(ie,{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[Bn(St,{get onClick(){return e.composer.close},"data-testid":"comment-composer-cancel",get children(){return t("generic.cancel")}}),Bn(St,{variant:"primary",get disabled(){return!l()},onClick:c,"data-testid":"comment-composer-submit",get children(){return t("generic.save")}})]},get children(){var l=Om();return W(l,Bn(Qt,{get when(){return"reply"===s()?.mode},get children(){var e=Mm();return W(e,Bn(At,{as:"strong",get children(){return[qe(()=>t("comment.replyTo"))," ",qe(()=>s()?.parentAuthor)]}}),null),W(e,Bn(At,{as:"p",get children(){return s()?.parentText}}),null),e}}),null),W(l,Bn(k,{get label(){return t("comment.author")},get value(){return n()},onChange:o,maxLength:150,required:!0,get disabled(){return"edit"===s()?.mode||e.composer.authorLocked()},"data-testid":"comment-composer-author"}),null),W(l,Bn(Fe,{ref(e){"function"==typeof i?i(e):i=e},get label(){return t("comment.body")},controlClass:"oasis-editor-comment-composer-textarea",get value(){return r()},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 Fm=[8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72],Dm=[33,50,66,75,90,100,105,110,115,120,150,200];function Em(e){const t=Number(e.trim());return Number.isFinite(t)&&t>0?t:null}function Lm(e){const t=Number(e.trim());return Number.isFinite(t)&&t>=0?t:null}function Nm(e){return null==e||""===e?"":String(e)}function zm(e){const t=Number(e);return Number.isFinite(t)&&0!==t?t>0?"expanded":"condensed":"normal"}function $m(e){const t=Number(e);return Number.isFinite(t)&&0!==t?t>0?"raised":"lowered":"normal"}function Hm(e){if(!e.trim())return null;const t=Number(e);return Number.isInteger(t)&&t>=1&&t<=20?t:null}function Wm(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 Um(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 jm(e,t){const n=[],o=Hm(e);return null!==o&&n.push(`"ss${String(o).padStart(2,"0")}" 1`),t&&n.push('"calt" 1'),n.join(", ")||void 0}function Vm(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 Km(e){return{characterScale:Nm(e.characterScale),spacingMode:zm(e.characterSpacing),spacingAmount:e.characterSpacing?String(Math.abs(Number(e.characterSpacing))):"",positionMode:$m(e.baselineShift),positionAmount:e.baselineShift?String(Math.abs(Number(e.baselineShift))):"",kerningEnabled:""!==e.kerningThreshold,kerningThreshold:Nm(e.kerningThreshold),ligatures:e.ligatures,numberSpacing:e.numberSpacing,numberForm:e.numberForm,stylisticSet:Nm(e.stylisticSet),contextualAlternates:Boolean(e.contextualAlternates)}}function _m(e){const t=Ee(),[n,o]=co("font"),[r,a]=co(Vm(e.initial)),[i,s]=co(Km(e.initial));Zn(()=>{e.isOpen&&(o("font"),a(Vm(e.initial)),s(Km(e.initial)))});const l=wt(()=>{return e=r().bold,t=r().italic,e&&t?"boldItalic":e?"bold":t?"italic":"regular";var e,t}),c=wt(()=>{const t=r().familyFilter.trim().toLowerCase();return t?e.familyOptions.filter(e=>e.toLowerCase().includes(t)):e.familyOptions}),d=wt(()=>{const t=new Set(Fm);for(const o of e.sizeOptions)t.add(o);const n=Number(r().fontSize);return Number.isFinite(n)&&n>0&&t.add(n),Array.from(t).sort((e,t)=>e-t)}),u=wt(()=>{const e=r().fontSize.trim();if(!e)return"";const n=Number(e);return Number.isFinite(n)&&n>0?"":t("dialog.font.sizeInvalid")}),p=wt(()=>{const e=i();return e.characterScale.trim()&&null===Em(e.characterScale)?t("dialog.font.advancedScaleInvalid"):"normal"!==e.spacingMode&&null===Lm(e.spacingAmount)||"normal"!==e.positionMode&&null===Lm(e.positionAmount)?t("dialog.font.advancedAmountInvalid"):e.kerningThreshold.trim()&&null===Lm(e.kerningThreshold)?t("dialog.font.advancedKerningInvalid"):e.stylisticSet.trim()&&null===Hm(e.stylisticSet)?t("dialog.font.advancedStylisticSetInvalid"):""}),g=wt(()=>function(e,t){const n=Number(e.fontSize),o=Em(t.characterScale)??100,r="normal"===t.spacingMode?null:Lm(t.spacingAmount),a="normal"===t.positionMode?null:Lm(t.positionAmount),i=null===r?void 0:"condensed"===t.spacingMode?`-${r}pt`:`${r}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":`${o}%`,"letter-spacing":i,"font-variant-ligatures":Wm(t.ligatures),"font-variant-numeric":Um(t.numberSpacing,t.numberForm),"font-feature-settings":jm(t.stylisticSet,t.contextualAlternates)}}(r(),i()));return{activeTab:n,setActiveTab:e=>o(e),fontTabValues:r,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:g,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),o=Number.isFinite(n)&&n>0,r="none"===e.underlineStyle?null:e.underlineStyle,a=null!==r,i=t.characterScale.trim()?Em(t.characterScale):null,s="normal"===t.spacingMode?null:Lm(t.spacingAmount),l="normal"===t.positionMode?null:Lm(t.positionAmount),c=t.kerningEnabled&&t.kerningThreshold.trim()?Lm(t.kerningThreshold):null,d=Hm(t.stylisticSet);return{fontFamily:e.fontFamily.trim()?e.fontFamily.trim():null,fontSize:o?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:r,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}}(r(),i());e.onApply(t,e.initial),e.onClose()}}}var Xm=/*#__PURE__*/oo("<div>");function Gm(e){const t=Ee();return n=Xm(),W(n,()=>t("dialog.font.previewText")),gn(t=>{var o=e.class??"oasis-editor-dialog-preview",r=e.testId,a=e.style;return o!==t.e&&_(n,t.e=o),r!==t.t&&et(n,"data-testid",t.t=r),t.a=Ot(n,a,t.a),t},{e:void 0,t:void 0,a:void 0}),n;var n}var qm=/*#__PURE__*/oo('<div class="oasis-editor-font-dialog-panel oasis-editor-font-dialog-font-panel">');function Ym(e){const t=Ee(),{ctrl:n}=e;return o=qm(),W(o,Bn(ue,{container:!0,spacing:1.5,get children(){return[Bn(ue,{size:12,get children(){return Bn(k,{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"})}}),Bn(ue,{size:{xs:12,md:8},get children(){return Bn(Re,{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}))]}})}}),Bn(ue,{size:{xs:12,md:4},get children(){return Bn(Re,{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)}))]}})}}),Bn(ue,{size:{xs:12,md:4},get children(){return[Bn(k,{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"}),Bn(l,{class:"oasis-editor-dialog-help-text",get children(){return n.customSizeError()}})]}}),Bn(ue,{size:{xs:12,md:8},get children(){return Bn(Re,{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),W(o,Bn(ue,{container:!0,spacing:1.5,class:"oasis-editor-font-dialog-color-row",get children(){return[Bn(ue,{size:{xs:12,md:4},get children(){return Bn(Re,{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")}]}})}}),Bn(ue,{size:{xs:12,md:4},get children(){return Bn(Co,{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"})}}),Bn(ue,{size:{xs:12,md:2},get children(){return Bn(Co,{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"})}}),Bn(ue,{size:{xs:12,md:2},get children(){return Bn(Co,{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),W(o,Bn(ue,{container:!0,spacing:1.5,get children(){return[Bn(ue,{size:{xs:12,md:8},get children(){return Bn(Re,{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")},...Ct.map(e=>({value:e.value,label:t(e.labelKey)}))]}})}}),Bn(ue,{size:{xs:12,md:4},get children(){return Bn(Co,{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),W(o,Bn(w,{class:"oasis-editor-dialog-input-group-grow",get label(){return t("dialog.font.style")},get children(){return Bn(un,{class:"oasis-editor-dialog-style-row",direction:"row",spacing:1,get children(){return Bn(Kn,{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=>Bn(lt,{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),W(o,Bn(w,{get label(){return t("dialog.font.preview")},get children(){return Bn(Gm,{testId:"editor-font-dialog-preview",get style(){return n.previewStyle()}})}}),null),o;var o}var Zm=/*#__PURE__*/oo("<div class=oasis-editor-font-dialog-kerning-line>"),Jm=/*#__PURE__*/oo('<div class="oasis-editor-font-dialog-panel oasis-editor-font-dialog-advanced-panel">');function Qm(e){const t=Ee(),{ctrl:n}=e;return o=Jm(),W(o,Bn(vo,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("dialog.font.advancedCharacterSpacingGroup")},get children(){return Bn(ue,{container:!0,spacing:1.5,get children(){return[Bn(ue,{size:{xs:12,md:4},get children(){return Bn(Re,{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 Dm.map(e=>({value:String(e),label:`${e}%`}))}})}}),Bn(ue,{size:{xs:12,md:8},get children(){return Bn(ue,{container:!0,spacing:1.5,get children(){return[Bn(ue,{size:{xs:12,md:8},get children(){return Bn(Re,{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")}]}})}}),Bn(ue,{size:{xs:12,md:4},get children(){return Bn(k,{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"})}})]}})}}),Bn(ue,{size:{xs:12,md:8},get children(){return Bn(Re,{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")}]}})}}),Bn(ue,{size:{xs:12,md:4},get children(){return Bn(k,{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"})}}),Bn(ue,{size:12,get children(){var e=Zm();return W(e,Bn(h,{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),W(e,Bn(k,{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),W(e,Bn(l,{class:"oasis-editor-dialog-help-text oasis-editor-font-dialog-kerning-suffix",get children(){return t("dialog.font.advancedKerningAbove")}}),null),e}})]}})}}),null),W(o,Bn(vo,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("dialog.font.advancedOpenTypeGroup")},get children(){return[Bn(ue,{container:!0,spacing:1.5,get children(){return[Bn(ue,{size:{xs:12,md:6},get children(){return Bn(Re,{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")}]}})}}),Bn(ue,{size:{xs:12,md:6},get children(){return Bn(Re,{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")}]}})}}),Bn(ue,{size:{xs:12,md:6},get children(){return Bn(Re,{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")}]}})}}),Bn(ue,{size:{xs:12,md:6},get children(){return Bn(Re,{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)}))]}})}})]}}),Bn(h,{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),W(o,Bn(vo,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("dialog.font.advancedPreviewGroup")},get children(){return Bn(Gm,{class:"oasis-editor-dialog-preview oasis-editor-font-dialog-advanced-preview",testId:"editor-font-dialog-advanced-preview",get style(){return n.previewStyle()}})}}),null),W(o,Bn(l,{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),o;var o}function eh(e){const t=Ee(),n=_m(e);return Bn(ie,{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 Bn(Tm,{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 Bn(ne,{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:Bn(Ym,{ctrl:n})},{id:"advanced",label:t("dialog.font.tabAdvanced"),testId:"editor-font-dialog-tab-advanced",panel:Bn(Qm,{ctrl:n})}]}})}})}var th=/*#__PURE__*/oo("<div class=oasis-editor-word-tabs-fields><div><div class=oasis-editor-word-tabs-list role=group>"),nh=/*#__PURE__*/oo("<div class=oasis-editor-word-tabs-fields>"),oh=/*#__PURE__*/oo("<div class=oasis-editor-word-tabs-actions>"),rh=(e,t)=>Math.abs(e-t)<Nn,ah=e=>null!==e&&Number.isFinite(e)&&Math.abs(e)<=1584;function ih(e){const t=Ee(),[n,o]=co([]),[r,a]=co([]),[i,s]=co(null),[c,d]=co("left"),[u,p]=co("none"),[g,f]=co(36),[m,h]=co(36),b=e=>{s(e.position),"clear"!==e.type&&d(e.type),p(e.leader??"none")};Zn(()=>{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),a([]);const n=e.initialDefault??36;f(n),h(n),s(null),d("left"),p("none");const r=t.find(t=>void 0!==e.selectedPosition&&rh(t.position,e.selectedPosition));r&&b(r)});const y=()=>n().find(e=>null!==i()&&rh(e.position,i())),v=()=>{const e=g();return null!==e&&Number.isFinite(e)&&e>=1&&e<=1584},x=()=>ah(i())&&(Boolean(y())||n().length<64),w=()=>{const e=i();if(!ah(e)||!x())return;const t={position:e,type:c(),..."bar"!==c()&&"none"!==u()?{leader:u()}:{}};o(n=>[...n.filter(t=>!rh(t.position,e)),t].sort((e,t)=>e.position-t.position)),a(e=>[...e,{set:[t]}])},S=()=>{const e=i();ah(e)&&y()&&(o(t=>t.filter(t=>!rh(t.position,e))),a(t=>[...t,{clear:[e]}]),s(null))},I=()=>{o([]),s(null),a(e=>[...e,{clearAll:!0}])},C=()=>{if(!v())return;const t=[...r()];g()!==m()&&t.push({default:g()}),e.onApply(n().map(e=>({...e})),t),e.onClose()};return Bn(ie,{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[Bn(St,{variant:"secondary",get onClick(){return e.onClose},"data-testid":"editor-tab-stops-cancel",get children(){return t("generic.cancel")}}),Bn(St,{variant:"primary",get disabled(){return!v()},onClick:C,"data-testid":"editor-tab-stops-apply",get children(){return t("generic.apply")}})]},get children(){return[(r=th(),a=r.firstChild,m=a.firstChild,W(a,Bn(Bo,{get label(){return t("paragraph.tabsPosition")},step:"0.05",min:-zt,max:zt,get value(){return i()??""},onChange:s,"data-testid":"editor-tab-stops-position",get error(){return qe(()=>!(null===i()||ah(i())))()?t("paragraph.tabsInvalidPosition"):void 0}}),m),W(m,Bn(Kn,{get each(){return n()},get fallback(){return Bn(l,{as:"p",get children(){return t("paragraph.tabsEmpty")}})},children:e=>Bn(St,{variant:"ghost",class:"oasis-editor-word-tabs-option",get"aria-pressed"(){return qe(()=>null!==i())()&&rh(i(),e.position)},onClick:()=>b(e),"data-testid":"editor-tab-stops-option",get children(){return[qe(()=>Number(e.position.toFixed(2)))," pt"]}})})),W(r,Bn(Bo,{get label(){return t("paragraph.tabsDefaultInterval")},step:"0.05",min:"1",max:zt,get value(){return g()??""},onChange:f,"data-testid":"editor-tab-stops-default",get error(){return qe(()=>!v())()?t("paragraph.tabsInvalidInterval"):void 0}}),null),gn(()=>et(m,"aria-label",t("paragraph.tabsDefined"))),r),(o=nh(),W(o,Bn(vt,{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),W(o,Bn(vt,{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=oh(),W(e,Bn(St,{get disabled(){return!x()},onClick:w,"data-testid":"editor-tab-stops-set",get children(){return t("paragraph.tabsSet")}}),null),W(e,Bn(St,{get disabled(){return!y()},onClick:S,"data-testid":"editor-tab-stops-remove",get children(){return t("paragraph.tabsClear")}}),null),W(e,Bn(St,{onClick:I,"data-testid":"editor-tab-stops-clear",get children(){return t("paragraph.tabsClearAll")}}),null),e),Bn(l,{as:"p",get children(){return t("paragraph.tabsDraftHelp")}})];var e,o,r,a,m}})}var sh=96/72;function lh(e){const[t,n]=co(""),[o,r]=co(""),[a,i]=co(null),[s,l]=co(null),[c,d]=co("none"),[u,p]=co(null),[g,f]=co(!1),[m,h]=co(null),[b,y]=co(null),[v,x]=co("multiple"),[w,S]=co(null),[I,C]=co(!1),[T,k]=co(""),[P,R]=co("none"),[B,M]=co(null),[O,A]=co(""),[F,D]=co(!1),[E,L]=co(!1),[N,z]=co(!1),[$,H]=co(!1),[W,U]=co(!1),[j,V]=co(!1),[K,_]=co(!1),[X,G]=co(!0),[q,Y]=co([]),[Z,J]=co([]),[Q,ee]=co(36);Zn(()=>{if(e.isOpen){n(e.initial.align??""),r(e.initial.outlineLevel??""),i(to(e.initial.indentLeft??"")),l(to(e.initial.indentRight??"")),f(e.initial.mirrorIndents??!1),h(to(e.initial.spacingBefore??"")),y(to(e.initial.spacingAfter??"")),C(e.initial.contextualSpacing??!1),k(e.initial.shading??"");const{mode:a,at:s}=(t=e.initial.lineRule??"",o=to(e.initial.lineHeight??""),"exact"===t||"atLeast"===t?{mode:t,at:null!==o?Math.round(o/sh):null}:null===o?{mode:"multiple",at:null}:1===o?{mode:"single",at:null}:1.5===o?{mode:"onePointFive",at:null}:2===o?{mode:"double",at:null}:{mode:"multiple",at:o});x(a),S(s);const c=e.initial.borderStyle;R("solid"===c||"dashed"===c||"dotted"===c?c:"none"),M(to(e.initial.borderWidth??"")),A(e.initial.borderColor??""),D(e.initial.borderSideTop??!1),L(e.initial.borderSideRight??!1),z(e.initial.borderSideBottom??!1),H(e.initial.borderSideLeft??!1),U(e.initial.pageBreakBefore??!1),V(e.initial.keepWithNext??!1),_(e.initial.keepLinesTogether??!1),G(e.initial.widowControl??!0),Y(e.initial.tabs??[]),J([]),ee(e.initial.defaultTabStop??36);const u=to(e.initial.indentFirstLine??""),g=to(e.initial.indentHanging??"");null!==g&&g>0?(d("hanging"),p(g)):null!==u&&u>0?(d("firstLine"),p(u)):(d("none"),p(null))}var t,o});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()*sh:null,lineRule:"atLeast"};case"exact":return{lineHeight:null!==w()?w()*sh:null,lineRule:"exact"}}},ne=wt(()=>{const e=a(),n=s(),o="firstLine"===c()?u():null,r="hanging"===c()?u():null,i=null!==o?o:null!==r?-r:null,l="none"!==P()?`${B()??.5}pt ${P()} ${O().trim()||"#000000"}`:void 0,{lineHeight:d,lineRule:p}=te(),g=null===d?void 0:"exact"===p||"atLeast"===p?`${d}px`:String(d);return{"text-align":t()||void 0,"line-height":g,"padding-left":null!==e?`${e+(r??0)}pt`:void 0,"padding-right":null!==n?`${n}pt`:void 0,"text-indent":null!==i?`${i}pt`:void 0,"background-color":T().trim()||void 0,"border-top":l&&F()?l:void 0,"border-right":l&&E()?l:void 0,"border-bottom":l&&N()?l:void 0,"border-left":l&&$()?l:void 0}}),oe=()=>{const e=P();if("none"===e)return{top:null,right:null,bottom:null,left:null};const t=B(),n={type:e,width:null!==t&&t>0?t:.5,color:O().trim()||"#000000"};return{top:F()?n:null,right:E()?n:null,bottom:N()?n:null,left:$()?n:null}},re=()=>{const e=u(),{lineHeight:n,lineRule:r}=te(),i=o();return{align:t()||null,indentLeft:a(),indentRight:s(),indentFirstLine:"firstLine"===c()?e:null,indentHanging:"hanging"===c()?e:null,mirrorIndents:g(),spacingBefore:m(),spacingAfter:b(),lineHeight:n,lineRule:r,contextualSpacing:I(),outlineLevel:""===i?null:Number(i),shading:T().trim()||null,borders:oe(),pageBreakBefore:W(),keepWithNext:j(),keepLinesTogether:K(),widowControl:X(),tabs:q(),...Z().length?{tabChanges:Z()}:{}}};return{align:t,setAlign:n,outlineLevel:o,setOutlineLevel:r,indentLeft:a,setIndentLeft:i,indentRight:s,setIndentRight:l,special:c,setSpecial:d,specialBy:u,setSpecialBy:p,mirrorIndents:g,setMirrorIndents:f,spacingBefore:m,setSpacingBefore:h,spacingAfter:b,setSpacingAfter:y,lineMode:v,setLineMode:x,lineAt:w,setLineAt:S,contextualSpacing:I,setContextualSpacing:C,shading:T,setShading:k,borderStyle:P,setBorderStyle:R,borderWidth:B,setBorderWidth:M,borderColor:O,setBorderColor:A,sideTop:F,setSideTop:D,sideRight:E,setSideRight:L,sideBottom:N,setSideBottom:z,sideLeft:$,setSideLeft:H,pageBreakBefore:W,setPageBreakBefore:U,keepWithNext:j,setKeepWithNext:V,keepLinesTogether:K,setKeepLinesTogether:_,widowControl:X,setWidowControl:G,tabs:q,setTabs:Y,defaultTabStop:Q,setDefaultTabStop:ee,setTabChanges:J,atEnabled:()=>"multiple"===v()||"atLeast"===v()||"exact"===v(),previewStyle:ne,handleApply:()=>{e.onApply(re(),e.initial),e.onClose()},handleSetDefault:()=>{e.onSetDefault?.(re()),e.onClose()}}}var ch=/*#__PURE__*/oo("<div class=oasis-editor-paragraph-dialog-panel>"),dh=/*#__PURE__*/oo("<div class=oasis-editor-dialog-preview data-testid=editor-paragraph-dialog-preview>"),uh=/*#__PURE__*/oo("<div>"),ph=/*#__PURE__*/oo("<div class=oasis-editor-dialog-footer-split><div class=oasis-editor-dialog-footer-start></div><div class=oasis-editor-dialog-footer-end>");function gh(e){const t=Ee(),[n,o]=co(!1),{align:r,setAlign:a,outlineLevel:i,setOutlineLevel:s,indentLeft:l,setIndentLeft:c,indentRight:d,setIndentRight:u,special:p,setSpecial:g,specialBy:f,setSpecialBy:m,mirrorIndents:b,setMirrorIndents:y,spacingBefore:v,setSpacingBefore:x,spacingAfter:S,setSpacingAfter:I,lineMode:C,setLineMode:T,lineAt:k,setLineAt:P,contextualSpacing:R,setContextualSpacing:B,shading:M,setShading:O,borderStyle:A,setBorderStyle:F,borderWidth:D,setBorderWidth:E,borderColor:L,setBorderColor:N,sideTop:z,setSideTop:$,sideRight:H,setSideRight:U,sideBottom:j,setSideBottom:V,sideLeft:K,setSideLeft:_,pageBreakBefore:X,setPageBreakBefore:G,keepWithNext:q,setKeepWithNext:Y,keepLinesTogether:Z,setKeepLinesTogether:J,widowControl:Q,setWidowControl:ee,tabs:te,setTabs:oe,defaultTabStop:re,setDefaultTabStop:ae,setTabChanges:se,atEnabled:le,previewStyle:ce,handleApply:de,handleSetDefault:pe}=lh(e),ge=Bn(Re,{get label(){return t("paragraph.alignLabel")},get value(){return r()},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=Bn(Re,{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])}))]}}),me=(he=ch(),W(he,Bn(vo,{class:"oasis-editor-dialog-fieldset",get legend(){return t("paragraph.groupGeneral")},get children(){return Bn(ue,{container:!0,spacing:1.5,get children(){return[Bn(ue,{size:{xs:12,md:6},children:ge}),Bn(ue,{size:{xs:12,md:6},children:fe})]}})}}),null),W(he,Bn(vo,{class:"oasis-editor-dialog-fieldset",get legend(){return t("paragraph.groupIndent")},get children(){return Bn(ue,{container:!0,spacing:1.5,get children(){return[Bn(ue,{size:{xs:12,md:6},get children(){return Bn(Bo,{get label(){return t("paragraph.indentLeftLabel")},step:"1",get value(){return l()??""},onChange:c,"data-testid":"editor-paragraph-dialog-indent-left"})}}),Bn(ue,{size:{xs:12,md:6},get children(){return Bn(Bo,{get label(){return t("paragraph.indentRightLabel")},step:"1",get value(){return d()??""},onChange:u,"data-testid":"editor-paragraph-dialog-indent-right"})}}),Bn(ue,{size:{xs:12,md:6},get children(){return Bn(Re,{get label(){return t("paragraph.specialLabel")},get value(){return p()},onChange:e=>{const t=e;g(t),"none"===t&&m(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")}]}})}}),Bn(ue,{size:{xs:12,md:6},get children(){return Bn(Bo,{get label(){return t("paragraph.specialByLabel")},min:"0",step:"1",get disabled(){return"none"===p()},get value(){return f()??""},onChange:m,"data-testid":"editor-paragraph-dialog-special-by"})}}),Bn(ue,{size:12,get children(){return Bn(h,{get label(){return t("paragraph.mirrorIndentsLabel")},get checked(){return b()},onChange:y,"data-testid":"editor-paragraph-dialog-mirror-indents"})}})]}})}}),null),W(he,Bn(vo,{class:"oasis-editor-dialog-fieldset",get legend(){return t("paragraph.groupSpacing")},get children(){return Bn(ue,{container:!0,spacing:1.5,get children(){return[Bn(ue,{size:{xs:12,md:4},get children(){return Bn(Bo,{get label(){return t("paragraph.spacingBeforeLabel")},min:"0",step:"1",get value(){return v()??""},onChange:x,"data-testid":"editor-paragraph-dialog-spacing-before"})}}),Bn(ue,{size:{xs:12,md:4},get children(){return Bn(Bo,{get label(){return t("paragraph.spacingAfterLabel")},min:"0",step:"1",get value(){return S()??""},onChange:I,"data-testid":"editor-paragraph-dialog-spacing-after"})}}),Bn(ue,{size:{xs:12,md:4}}),Bn(ue,{size:{xs:12,md:8},get children(){return Bn(Re,{get label(){return t("paragraph.lineSpacingLabel")},get value(){return C()},onChange:e=>{T(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")}]}})}}),Bn(ue,{size:{xs:12,md:4},get children(){return Bn(Bo,{get label(){return t("paragraph.lineSpacingAt")},min:"0",get step(){return"multiple"===C()?"0.05":"1"},get disabled(){return!le()},get value(){return k()??""},onChange:P,"data-testid":"editor-paragraph-dialog-line-at"})}}),Bn(ue,{size:12,get children(){return Bn(h,{get label(){return t("paragraph.contextualSpacingLabel")},get checked(){return R()},onChange:B,"data-testid":"editor-paragraph-dialog-contextual-spacing"})}})]}})}}),null),W(he,Bn(vo,{class:"oasis-editor-dialog-fieldset",get legend(){return t("paragraph.groupBorders")},get children(){return[Bn(ue,{container:!0,spacing:1.5,get children(){return[Bn(ue,{size:{xs:12,md:3},get children(){return Bn(Re,{get label(){return t("paragraph.borderStyleLabel")},get value(){return A()},onChange:e=>{const t=e;F(t),"none"===t?($(!1),U(!1),V(!1),_(!1)):z()||H()||j()||K()||($(!0),U(!0),V(!0),_(!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")}]}})}}),Bn(ue,{size:{xs:12,md:3},get children(){return Bn(Bo,{get label(){return t("paragraph.borderWidthLabel")},min:"0",step:"0.25",get disabled(){return"none"===A()},get value(){return D()??""},onChange:E,"data-testid":"editor-paragraph-dialog-border-width"})}}),Bn(ue,{size:{xs:12,md:3},get children(){return Bn(Co,{get label(){return t("paragraph.borderColorLabel")},get disabled(){return"none"===A()},get value(){return L()||"#000000"},onChange:N,"data-testid":"editor-paragraph-dialog-border-color"})}}),Bn(ue,{size:{xs:12,md:3},get children(){return Bn(Co,{get label(){return t("paragraph.shadingLabel")},get value(){return M()||"#ffffff"},onChange:O,"data-testid":"editor-paragraph-dialog-shading"})}})]}}),Bn(w,{class:"oasis-editor-dialog-input-group-grow",get label(){return t("paragraph.borderSidesLabel")},get children(){return Bn(un,{class:"oasis-editor-dialog-style-row",direction:"row",spacing:1,get children(){return[Bn(h,{get label(){return t("paragraph.borderSideTop")},get disabled(){return"none"===A()},get checked(){return z()},onChange:$,"data-testid":"editor-paragraph-dialog-border-side-top"}),Bn(h,{get label(){return t("paragraph.borderSideRight")},get disabled(){return"none"===A()},get checked(){return H()},onChange:U,"data-testid":"editor-paragraph-dialog-border-side-right"}),Bn(h,{get label(){return t("paragraph.borderSideBottom")},get disabled(){return"none"===A()},get checked(){return j()},onChange:V,"data-testid":"editor-paragraph-dialog-border-side-bottom"}),Bn(h,{get label(){return t("paragraph.borderSideLeft")},get disabled(){return"none"===A()},get checked(){return K()},onChange:_,"data-testid":"editor-paragraph-dialog-border-side-left"})]}})}})]}}),null),he);var he;const be=(ye=ch(),W(ye,Bn(vo,{class:"oasis-editor-dialog-fieldset",get legend(){return t("paragraph.groupPagination")},get children(){return Bn(un,{direction:"column",spacing:1,get children(){return[Bn(h,{get label(){return t("paragraph.widowControlLabel")},get checked(){return Q()},onChange:ee,"data-testid":"editor-paragraph-dialog-widow-control"}),Bn(h,{get label(){return t("paragraph.keepWithNextLabel")},get checked(){return q()},onChange:Y,"data-testid":"editor-paragraph-dialog-keep-with-next"}),Bn(h,{get label(){return t("paragraph.keepLinesTogetherLabel")},get checked(){return Z()},onChange:J,"data-testid":"editor-paragraph-dialog-keep-lines-together"}),Bn(h,{get label(){return t("paragraph.pageBreakBeforeLabel")},get checked(){return X()},onChange:G,"data-testid":"editor-paragraph-dialog-page-break-before"})]}})}})),ye);var ye,ve;return ve=uh(),W(ve,Bn(ie,{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=ph(),r=n.firstChild,a=r.nextSibling,W(r,Bn(St,{variant:"secondary",onClick:()=>{o(!0)},"data-testid":"editor-paragraph-dialog-tabs",get children(){return t("paragraph.tabsButton")}}),null),W(r,Bn(St,{variant:"secondary",onClick:pe,"data-testid":"editor-paragraph-dialog-set-default",get children(){return t("paragraph.setAsDefault")}}),null),W(a,Bn(St,{variant:"secondary",get onClick(){return e.onClose},"data-testid":"editor-paragraph-dialog-cancel",get children(){return t("generic.cancel")}}),null),W(a,Bn(St,{variant:"primary",onClick:de,"data-testid":"editor-paragraph-dialog-apply",get children(){return t("generic.apply")}}),null),n;var n,r,a},get children(){return[Bn(ne,{get ariaLabel(){return t("paragraph.title")},get items(){return[{id:"indents",label:t("paragraph.tabIndentsSpacing"),panel:me,testId:"editor-paragraph-dialog-tab-indents"},{id:"breaks",label:t("paragraph.tabLineBreaks"),panel:be,testId:"editor-paragraph-dialog-tab-breaks"}]}}),Bn(w,{get label(){return t("paragraph.preview")},get children(){var e=dh();return W(e,()=>t("paragraph.previewText")),gn(t=>Ot(e,ce(),t)),e}})]}}),null),W(ve,Bn(ih,{get isOpen(){return qe(()=>!!e.isOpen)()&&(n()||!!e.initial.tabsOnly)},get initial(){return te()},get initialDefault(){return re()},get selectedPosition(){return e.initial.selectedTabPosition},onClose:()=>{o(!1),e.initial.tabsOnly&&e.onClose()},onApply:(t,n)=>{oe(t),se(e=>[...e,...n]);for(const e of n)"number"==typeof e.default&&ae(e.default);e.initial.tabsOnly&&de()}}),null),ve}function fh(e,t){const n=to(e);return null===n?null:"percent"===t?`${n}%`:n}function mh(e,t,n){if("none"===e)return null;const o=to(t);return{type:e,width:null!==o&&o>0?o:.5,color:n.trim()||"#000000"}}function hh(e){const[t,n]=uo({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:""});Zn(()=>{var t;e.isOpen&&n(Pt({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=mh(e.borderStyle,e.borderWidth,e.borderColor);return{tableWidth:fh(e.tableWidth,e.tableWidthUnit),tableAlign:e.tableAlign||null,tableIndentLeft:fh(e.tableIndentLeft,"points"),tableFloating:"around"===e.tableWrapping?{horizontalAnchor:e.floatingHorizontalAnchor,verticalAnchor:e.floatingVerticalAnchor,...e.floatingXAlign?{xAlign:e.floatingXAlign}:{x:to(e.floatingX)??0},...e.floatingYAlign?{yAlign:e.floatingYAlign}:{y:to(e.floatingY)??0},distanceTop:to(e.floatingDistanceTop)??0,distanceRight:to(e.floatingDistanceRight)??0,distanceBottom:to(e.floatingDistanceBottom)??0,distanceLeft:to(e.floatingDistanceLeft)??0}:null,tableOverlap:"around"===e.tableWrapping?e.floatingOverlap:null,rowHeight:fh(e.rowHeight,"points"),rowHeightRule:e.rowHeightRule||null,repeatHeader:e.repeatHeader,cantSplit:!e.allowBreakAcrossPages,hiddenRow:e.hiddenRow,columnWidth:fh(e.columnWidth,"points"),cellWidth:fh(e.cellWidth,"points"),cellVerticalAlign:e.cellVerticalAlign||null,cellTextDirection:e.cellTextDirection||null,cellNoWrap:e.cellNoWrap,cellFitText:e.cellFitText,cellHideMark:e.cellHideMark,margins:{top:to(e.marginTop),right:to(e.marginRight),bottom:to(e.marginBottom),left:to(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 bh(e,t,n,o,r=!1,a=!1){return Bn(k,{class:"oasis-editor-dialog-input-group-grow",type:"number",label:e,min:a?void 0:"0",step:"1",get value(){return t()},disabled:r,onChange:n,"data-testid":o})}var yh=/*#__PURE__*/oo("<div class=oasis-editor-table-properties-panel>");function vh(e){const t=Ee(),n=()=>e.ctrl.form,o=e.ctrl.set;return r=yh(),W(r,Bn(vo,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("table.sizeSection")},get children(){return Bn(ue,{container:!0,spacing:1.5,get children(){return[Bn(ue,{size:{xs:12,md:6},get children(){return bh(t("table.preferredWidth"),()=>n().tableWidth,e=>o("tableWidth",e),"editor-table-properties-table-width")}}),Bn(ue,{size:{xs:12,md:6},get children(){return Bn(Re,{get label(){return t("table.measureIn")},get value(){return n().tableWidthUnit},onChange:e=>o("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),W(r,Bn(vo,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("table.alignmentSection")},get children(){return[Bn(vt,{class:"oasis-editor-dialog-style-row",name:"table-align",get value(){return n().tableAlign},onChange:e=>o("tableAlign",e),get children(){return["left","center","right"].map(e=>Bn(Do,{value:e,get label(){return t(`table.align${e[0].toUpperCase()}${e.slice(1)}`)},"data-testid":`editor-table-properties-align-${e}`}))}}),Bn(ue,{container:!0,spacing:1.5,get children(){return Bn(ue,{size:{xs:12,md:6},get children(){return bh(t("table.indentFromLeft"),()=>n().tableIndentLeft,e=>o("tableIndentLeft",e),"editor-table-properties-indent-left")}})}})]}}),null),W(r,Bn(vo,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("table.textWrappingSection")},get children(){return[Bn(un,{class:"oasis-editor-dialog-style-row",direction:"row",spacing:1,get children(){return[Bn(h,{get label(){return t("table.wrapNone")},get checked(){return"none"===n().tableWrapping},onChange:()=>o("tableWrapping","none"),"data-testid":"editor-table-properties-wrap-none"}),Bn(h,{get label(){return t("table.wrapAround")},get checked(){return"around"===n().tableWrapping},onChange:()=>o("tableWrapping","around"),"data-testid":"editor-table-properties-wrap-around"})]}}),Bn(Qt,{get when(){return"around"===n().tableWrapping},get children(){return[Bn(ue,{container:!0,spacing:1.5,get children(){return[Bn(ue,{size:{xs:12,md:6},get children(){return Bn(Re,{get label(){return t("table.horizontalAnchor")},get value(){return n().floatingHorizontalAnchor},onChange:e=>o("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")}]}})}}),Bn(ue,{size:{xs:12,md:6},get children(){return Bn(Re,{get label(){return t("table.verticalAnchor")},get value(){return n().floatingVerticalAnchor},onChange:e=>o("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")}]}})}}),Bn(ue,{size:{xs:12,md:3},get children(){return bh(t("table.positionX"),()=>n().floatingX,e=>o("floatingX",e),"editor-table-properties-floating-x",Boolean(n().floatingXAlign),!0)}}),Bn(ue,{size:{xs:12,md:3},get children(){return bh(t("table.positionY"),()=>n().floatingY,e=>o("floatingY",e),"editor-table-properties-floating-y",Boolean(n().floatingYAlign),!0)}}),Bn(ue,{size:{xs:12,md:3},get children(){return Bn(Re,{get label(){return t("table.horizontalAlignment")},get value(){return n().floatingXAlign},onChange:e=>o("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}))]}})}}),Bn(ue,{size:{xs:12,md:3},get children(){return Bn(Re,{get label(){return t("table.verticalAlignment")},get value(){return n().floatingYAlign},onChange:e=>o("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}))]}})}}),Bn(ue,{size:{xs:12,md:3},get children(){return bh(t("table.distanceTop"),()=>n().floatingDistanceTop,e=>o("floatingDistanceTop",e),"editor-table-properties-floating-distance-top")}}),Bn(ue,{size:{xs:12,md:3},get children(){return bh(t("table.distanceRight"),()=>n().floatingDistanceRight,e=>o("floatingDistanceRight",e),"editor-table-properties-floating-distance-right")}}),Bn(ue,{size:{xs:12,md:3},get children(){return bh(t("table.distanceBottom"),()=>n().floatingDistanceBottom,e=>o("floatingDistanceBottom",e),"editor-table-properties-floating-distance-bottom")}}),Bn(ue,{size:{xs:12,md:3},get children(){return bh(t("table.distanceLeft"),()=>n().floatingDistanceLeft,e=>o("floatingDistanceLeft",e),"editor-table-properties-floating-distance-left")}})]}}),Bn(h,{get label(){return t("table.allowOverlap")},get checked(){return"overlap"===n().floatingOverlap},onChange:e=>o("floatingOverlap",e?"overlap":"never"),"data-testid":"editor-table-properties-floating-overlap"})]}})]}}),null),r;var r}var xh=/*#__PURE__*/oo("<div class=oasis-editor-table-properties-panel>");function wh(e){const t=Ee(),n=()=>e.ctrl.form,o=e.ctrl.set;return r=xh(),W(r,Bn(ue,{container:!0,spacing:1.5,get children(){return[Bn(ue,{size:{xs:12,md:6},get children(){return bh(t("table.rowHeight"),()=>n().rowHeight,e=>o("rowHeight",e),"editor-table-properties-row-height")}}),Bn(ue,{size:{xs:12,md:6},get children(){return Bn(Re,{get label(){return t("table.rowHeightRule")},get value(){return n().rowHeightRule},onChange:e=>o("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),W(r,Bn(un,{class:"oasis-editor-dialog-style-row",direction:"row",spacing:1,get children(){return[Bn(h,{get label(){return t("table.repeatHeader")},get checked(){return n().repeatHeader},onChange:e=>o("repeatHeader",e),"data-testid":"editor-table-properties-repeat-header"}),Bn(h,{get label(){return t("table.allowBreakAcrossPages")},get checked(){return n().allowBreakAcrossPages},onChange:e=>o("allowBreakAcrossPages",e),"data-testid":"editor-table-properties-allow-break"}),Bn(h,{get label(){return t("table.hiddenRow")},get checked(){return n().hiddenRow},onChange:e=>o("hiddenRow",e),"data-testid":"editor-table-properties-hidden-row"})]}}),null),r;var r}var Sh=/*#__PURE__*/oo("<div class=oasis-editor-table-properties-panel>");function Ih(e){const t=Ee(),n=e.ctrl.set;return o=Sh(),W(o,Bn(ue,{container:!0,spacing:1.5,get children(){return Bn(ue,{size:{xs:12,md:6},get children(){return bh(t("table.columnWidth"),()=>e.ctrl.form.columnWidth,e=>n("columnWidth",e),"editor-table-properties-column-width")}})}})),o;var o}var Ch=/*#__PURE__*/oo("<div class=oasis-editor-table-properties-cell-preview data-testid=editor-table-properties-cell-preview>"),Th=/*#__PURE__*/oo("<div class=oasis-editor-table-properties-panel>");function kh(e){const t=Ee(),n=()=>e.ctrl.form,o=e.ctrl.set,r=wt(()=>{const e=mh(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=Th(),W(i,Bn(ue,{container:!0,spacing:1.5,get children(){return[Bn(ue,{size:{xs:12,md:4},get children(){return bh(t("table.cellWidth"),()=>n().cellWidth,e=>o("cellWidth",e),"editor-table-properties-cell-width")}}),Bn(ue,{size:{xs:12,md:4},get children(){return Bn(Re,{get label(){return t("table.verticalAlignment")},get value(){return n().cellVerticalAlign},onChange:e=>o("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")}]}})}}),Bn(ue,{size:{xs:12,md:4},get children(){return Bn(Re,{get label(){return t("table.textDirection")},get value(){return n().cellTextDirection},onChange:e=>o("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),W(i,Bn(vo,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("table.options")},get children(){return Bn(un,{class:"oasis-editor-dialog-style-row",direction:"row",spacing:1,get children(){return[Bn(h,{get label(){return t("table.noWrap")},get checked(){return n().cellNoWrap},onChange:e=>o("cellNoWrap",e),"data-testid":"editor-table-properties-cell-nowrap"}),Bn(h,{get label(){return t("table.fitText")},get checked(){return n().cellFitText},onChange:e=>o("cellFitText",e),"data-testid":"editor-table-properties-cell-fit-text"}),Bn(h,{get label(){return t("table.hideMark")},get checked(){return n().cellHideMark},onChange:e=>o("cellHideMark",e),"data-testid":"editor-table-properties-cell-hide-mark"})]}})}}),null),W(i,Bn(vo,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("table.cellMargins")},get children(){return Bn(ue,{container:!0,spacing:1.5,get children(){return[Bn(ue,{size:{xs:12,md:3},get children(){return bh(t("paragraph.borderSideTop"),()=>n().marginTop,e=>o("marginTop",e),"editor-table-properties-margin-top")}}),Bn(ue,{size:{xs:12,md:3},get children(){return bh(t("paragraph.borderSideRight"),()=>n().marginRight,e=>o("marginRight",e),"editor-table-properties-margin-right")}}),Bn(ue,{size:{xs:12,md:3},get children(){return bh(t("paragraph.borderSideBottom"),()=>n().marginBottom,e=>o("marginBottom",e),"editor-table-properties-margin-bottom")}}),Bn(ue,{size:{xs:12,md:3},get children(){return bh(t("paragraph.borderSideLeft"),()=>n().marginLeft,e=>o("marginLeft",e),"editor-table-properties-margin-left")}})]}})}}),null),W(i,Bn(vo,{class:"oasis-editor-font-dialog-fieldset",get legend(){return t("paragraph.bordersSection")},get children(){return[Bn(ue,{container:!0,spacing:1.5,get children(){return[Bn(ue,{size:{xs:12,md:3},get children(){return Bn(Re,{get label(){return t("paragraph.borderStyleLabel")},get value(){return n().borderStyle},onChange:e=>{const t=e;o("borderStyle",t),"none"===t?(o("borderTop",!1),o("borderRight",!1),o("borderBottom",!1),o("borderLeft",!1),o("borderStart",!1),o("borderEnd",!1),o("borderTlBr",!1),o("borderTrBl",!1)):n().borderTop||n().borderRight||n().borderBottom||n().borderLeft||(o("borderTop",!0),o("borderRight",!0),o("borderBottom",!0),o("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")}]}})}}),Bn(ue,{size:{xs:12,md:3},get children(){return bh(t("paragraph.borderWidthLabel"),()=>n().borderWidth,e=>o("borderWidth",e),"editor-table-properties-border-width",a())}}),Bn(ue,{size:{xs:12,md:3},get children(){return Bn(Co,{get label(){return t("paragraph.borderColorLabel")},get value(){return n().borderColor||"#000000"},get disabled(){return a()},onChange:e=>o("borderColor",e),"data-testid":"editor-table-properties-border-color"})}}),Bn(ue,{size:{xs:12,md:3},get children(){return Bn(Co,{get label(){return t("paragraph.shadingLabel")},get value(){return n().shading||"#ffffff"},onChange:e=>o("shading",e),"data-testid":"editor-table-properties-shading"})}})]}}),Bn(un,{class:"oasis-editor-dialog-style-row",direction:"row",spacing:1,get children(){return[Bn(h,{get label(){return t("paragraph.borderSideTop")},get checked(){return n().borderTop},get disabled(){return a()},onChange:e=>o("borderTop",e),"data-testid":"editor-table-properties-border-top"}),Bn(h,{get label(){return t("paragraph.borderSideRight")},get checked(){return n().borderRight},get disabled(){return a()},onChange:e=>o("borderRight",e),"data-testid":"editor-table-properties-border-right"}),Bn(h,{get label(){return t("paragraph.borderSideBottom")},get checked(){return n().borderBottom},get disabled(){return a()},onChange:e=>o("borderBottom",e),"data-testid":"editor-table-properties-border-bottom"}),Bn(h,{get label(){return t("paragraph.borderSideLeft")},get checked(){return n().borderLeft},get disabled(){return a()},onChange:e=>o("borderLeft",e),"data-testid":"editor-table-properties-border-left"}),Bn(h,{get label(){return t("table.borderStart")},get checked(){return n().borderStart},get disabled(){return a()},onChange:e=>o("borderStart",e),"data-testid":"editor-table-properties-border-start"}),Bn(h,{get label(){return t("table.borderEnd")},get checked(){return n().borderEnd},get disabled(){return a()},onChange:e=>o("borderEnd",e),"data-testid":"editor-table-properties-border-end"}),Bn(h,{get label(){return t("table.borderTlBr")},get checked(){return n().borderTlBr},get disabled(){return a()},onChange:e=>o("borderTlBr",e),"data-testid":"editor-table-properties-border-tlbr"}),Bn(h,{get label(){return t("table.borderTrBl")},get checked(){return n().borderTrBl},get disabled(){return a()},onChange:e=>o("borderTrBl",e),"data-testid":"editor-table-properties-border-trbl"})]}}),(e=Ch(),gn(t=>Ot(e,r(),t)),e)];var e}}),null),i;var i}var Ph=/*#__PURE__*/oo("<div class=oasis-editor-table-properties-panel>");function Rh(e){const t=Ee(),n=()=>e.ctrl.form,o=e.ctrl.set;return r=Ph(),W(r,Bn(k,{get label(){return t("table.altTitle")},get value(){return n().altTitle},onChange:e=>o("altTitle",e),"data-testid":"editor-table-properties-alt-title"}),null),W(r,Bn(Fe,{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=>o("altDescription",e),"data-testid":"editor-table-properties-alt-description"}),null),r;var r}function Bh(e){const t=Ee(),n=hh(e);return Bn(ie,{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 Bn(Tm,{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 Bn(ne,{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:Bn(vh,{ctrl:n})},{id:"row",label:t("table.tabRow"),testId:"editor-table-properties-tab-row",panel:Bn(wh,{ctrl:n})},{id:"column",label:t("table.tabColumn"),testId:"editor-table-properties-tab-column",panel:Bn(Ih,{ctrl:n})},{id:"cell",label:t("table.tabCell"),testId:"editor-table-properties-tab-cell",panel:Bn(kh,{ctrl:n})},{id:"altText",label:t("table.tabAltText"),testId:"editor-table-properties-tab-alt-text",panel:Bn(Rh,{ctrl:n})}]}})}})}var Mh=/*#__PURE__*/oo("<p data-testid=editor-new-document-message>");function Oh(e){const t=Ee();return Bn(ie,{get isOpen(){return e.isOpen},get title(){return t("dialog.newDocument.title")},get onClose(){return e.onClose},closeOnOverlayClick:!1,size:"sm",get footer(){return Bn(Tm,{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=Mh();return W(e,()=>t("dialog.newDocument.message")),e}})}function Ah(e){const t=Ee(),n=()=>"accept"===e.action;return Bn(ie,{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 Bn(Tm,{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 Bn(At,{as:"p","data-testid":"editor-revision-bulk-message",get children(){return t(n()?"review.bulkAcceptMessage":"review.bulkRejectMessage",[e.count])}})}})}var Fh=/*#__PURE__*/oo("<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>"),Dh=/*#__PURE__*/oo("<div class=oasis-editor-symbol-dialog-recent><span></span><div class=oasis-editor-symbol-dialog-recent-list>"),Eh=/*#__PURE__*/oo("<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>"),Lh=/*#__PURE__*/oo("<option>"),Nh=/*#__PURE__*/oo("<button type=button class=oasis-editor-symbol-dialog-tile>"),zh=/*#__PURE__*/oo("<button type=button class=oasis-editor-symbol-dialog-tile role=gridcell>"),$h=["Segoe UI Symbol","Arial Unicode MS","Cambria Math","Times New Roman"];function Hh(e){const t=Ee(),[n,o]=co("common"),[r,a]=co(Tt[0]),[i,s]=co($h[0]),[l,c]=co(Tt[0].codePoint),d=wt(()=>(e.isOpen,pn())),u=wt(()=>"all"===n()?Lt.flatMap(e=>e.entries):Lt.find(e=>e.id===n())?.entries??Tt),p=e=>{a(e),c(e.codePoint)},g=()=>{const t=r().character;t&&(lo(t),e.onInsert(t,i()),e.onClose())};return Bn(ie,{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[Bn(St,{variant:"secondary",get onClick(){return e.onClose},"data-testid":"editor-symbol-dialog-cancel",get children(){return t("generic.cancel")}}),Bn(St,{variant:"primary",onClick:g,"data-testid":"editor-symbol-dialog-insert",get children(){return t("dialog.symbol.insert")}})]},get children(){return[(w=Fh(),S=w.firstChild,I=S.firstChild,C=I.nextSibling,T=S.nextSibling.firstChild,k=T.nextSibling,P=k.firstChild,W(I,()=>t("dialog.symbol.font")),C.addEventListener("change",e=>{s(e.currentTarget.value)}),W(C,Bn(Kn,{each:$h,children:e=>{return(t=Lh()).value=e,W(t,e),t;var t}})),W(T,()=>t("dialog.symbol.subset")),k.addEventListener("change",e=>{o(e.currentTarget.value)}),W(P,()=>t("symbols.category.all")),W(k,Bn(Kn,{each:Lt,children:e=>{return n=Lh(),W(n,()=>t(e.labelKey)),gn(()=>n.value=e.id),n;var n}}),null),gn(()=>C.value=i()),gn(()=>k.value=n()),w),(e=Eh(),f=e.firstChild,m=f.nextSibling.firstChild,h=m.nextSibling,b=h.nextSibling,y=b.firstChild,v=y.nextSibling,x=b.nextSibling,W(f,Bn(Qt,{get when(){return d().length>0},get children(){var e=Dh(),n=e.firstChild,o=n.nextSibling;return W(n,()=>t("dialog.symbol.recent")),W(o,Bn(Kn,{get each(){return d()},children:e=>{return(t=Nh()).$$click=()=>p(e),W(t,()=>e.character),gn(n=>{var o=`${e.character} (${e.codePoint})`,r=`${e.character} (${e.codePoint})`;return o!==n.e&&et(t,"title",n.e=o),r!==n.t&&et(t,"aria-label",n.t=r),n},{e:void 0,t:void 0}),t;var t}})),e}}),null),W(f,Bn(Kn,{get each(){return u()},children:e=>{return(t=zh()).$$dblclick=g,t.$$click=()=>p(e),W(t,()=>e.character),gn(n=>{var o=!(r().character!==e.character),a=`${e.character} (${e.codePoint})`,i=`${e.character} (${e.codePoint})`,s=`editor-symbol-dialog-${e.codePoint.replace(/[^A-Z0-9]/g,"-")}`;return o!==n.e&&t.classList.toggle("oasis-editor-symbol-dialog-tile-active",n.e=o),a!==n.t&&et(t,"title",n.t=a),i!==n.a&&et(t,"aria-label",n.a=i),s!==n.o&&et(t,"data-testid",n.o=s),n},{e:void 0,t:void 0,a:void 0,o:void 0}),t;var t}}),null),W(m,()=>t("dialog.symbol.preview")),W(h,()=>r().character),W(y,()=>t("dialog.symbol.code")),v.$$input=e=>(e=>{c(e);const t=e.trim().toUpperCase().replace(/^U\+/,""),n=Number.parseInt(t,16);!Number.isFinite(n)||n<0||n>1114111||a({character:String.fromCodePoint(n),codePoint:`U+${n.toString(16).toUpperCase().padStart(4,"0")}`})})(e.currentTarget.value),et(v,"spellcheck",!1),W(x,()=>t("dialog.symbol.doubleClickHelp")),gn(e=>{var n=t("dialog.symbol.title"),o=i();return n!==e.e&&et(f,"aria-label",e.e=n),o!==e.t&&he(h,"font-family",e.t=o),e},{e:void 0,t:void 0}),gn(()=>v.value=l()),e)];var e,f,m,h,b,y,v,x,w,S,I,C,T,k,P}})}Hn(["input","click","dblclick"]);var Wh=/*#__PURE__*/oo("<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>"),Uh=/*#__PURE__*/oo("<button type=button data-testid=editor-equation-template>"),jh=[["\\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 Vh(e){const t=Ee(),[n,o]=co(""),[r,a]=co(Z);Zn(()=>{if(!e.isOpen)return;const t=e.initial??Z;a(t),o(mn(t))});const i=e=>{o(e),a(It(e))};return Bn(ie,{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[Bn(St,{variant:"secondary",get onClick(){return e.onClose},get children(){return t("generic.cancel")}}),Bn(St,{variant:"primary",onClick:()=>e.onApply(r()),"data-testid":"editor-equation-apply",get children(){return t("dialog.equation.insert")}})]},get children(){var e=Wh(),o=e.firstChild,a=o.nextSibling,s=a.firstChild,l=s.nextSibling,c=a.nextSibling;return W(o,Bn(Kn,{each:jh,children:([e,t])=>{return(n=Uh()).$$click=()=>i(t),W(n,e),n;var n}})),W(s,()=>t("dialog.equation.linear")),l.$$input=e=>i(e.currentTarget.value),et(l,"spellcheck",!1),W(c,()=>mn(r())||t("dialog.equation.empty")),gn(()=>et(o,"aria-label",t("dialog.equation.structures"))),gn(()=>l.value=n()),e}})}Hn(["input","click"]);var Kh=/*#__PURE__*/oo("<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 _h(e){const t=Ee(),{fr:n}=e,o=e=>{n.isOpen()&&"Escape"===e.key&&n.setIsOpen(!1)},r=e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?n.findPrevious():n.findNext())};return Xt(()=>{window.addEventListener("keydown",o,!0)}),yn(()=>{window.removeEventListener("keydown",o,!0)}),Bn(Qt,{get when(){return n.isOpen()},get children(){var e=Kh(),o=e.firstChild,a=o.nextSibling,i=a.firstChild,s=i.firstChild,c=i.nextSibling;return e.$$keydown=r,W(o,Bn(At,{get children(){return t("find.title")}}),null),W(o,Bn(ro,{class:"oasis-editor-fr-close",icon:"x",onClick:()=>n.setIsOpen(!1),get label(){return t("generic.close")}}),null),W(s,Bn(k,{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),W(s,Bn(l,{class:"oasis-editor-fr-counter",get children(){return qe(()=>n.matches().length>0)()?`${n.currentIndex()+1} / ${n.matches().length}`:t("find.noMatches")}}),null),W(i,Bn(un,{class:"oasis-editor-fr-actions",direction:"row",spacing:1,get children(){return[Bn(ro,{get onClick(){return n.findPrevious},get disabled(){return 0===n.matches().length},icon:"chevron-up",get label(){return t("find.prevTooltip")}}),Bn(ro,{get onClick(){return n.findNext},get disabled(){return 0===n.matches().length},icon:"chevron-down",get label(){return t("find.nextTooltip")}})]}}),null),W(c,Bn(k,{type:"text",get placeholder(){return t("replace.placeholder")},get value(){return n.replaceTerm()},onChange:e=>n.setReplaceTerm(e),controlClass:"oasis-editor-fr-input"}),null),W(c,Bn(un,{class:"oasis-editor-fr-actions",direction:"row",spacing:1,get children(){return[Bn(ro,{class:"oasis-editor-fr-btn-text",get onClick(){return n.replace},get disabled(){return 0===n.matches().length},get children(){return t("replace.one")}}),Bn(ro,{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),W(a,Bn(un,{class:"oasis-editor-fr-options",direction:"row",spacing:1,get children(){return[Bn(h,{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})}),Bn(h,{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}})}Hn(["keydown"]);var Xh=/*#__PURE__*/oo("<div class=oasis-editor-context-menu role=menu data-testid=editor-context-menu>"),Gh=/*#__PURE__*/oo("<i>"),qh=/*#__PURE__*/oo("<span class=oasis-editor-context-menu-shortcut>"),Yh=/*#__PURE__*/oo("<button type=button class=oasis-editor-context-menu-item role=menuitem><span class=oasis-editor-context-menu-label>"),Zh=/*#__PURE__*/oo("<div class=oasis-editor-context-menu-separator>"),Jh=/*#__PURE__*/oo("<span aria-hidden=true style=visibility:hidden;flex-shrink:0>");function Qh(e){let t;o({refs:()=>[t],open:()=>e.isOpen,onDismiss:()=>e.onClose()});const n=n=>{e.isOpen&&(t&&n.target instanceof Node&&t.contains(n.target)||e.onClose())},r=()=>{e.isOpen&&e.onClose()};return Xt(()=>{window.addEventListener("contextmenu",n,!0),window.addEventListener("scroll",r,!0),window.addEventListener("resize",r,!0)}),yn(()=>{window.removeEventListener("contextmenu",n,!0),window.removeEventListener("scroll",r,!0),window.removeEventListener("resize",r,!0)}),Zn(()=>{if(!e.isOpen||!t)return;const n=t.getBoundingClientRect(),o=Math.max(4,window.innerWidth-n.width-4),r=Math.max(4,window.innerHeight-n.height-4),a=Math.min(e.x,o),i=Math.min(e.y,r);t.style.left=`${a}px`,t.style.top=`${i}px`}),Bn(Qt,{get when(){return e.isOpen},get children(){var n=Xh();n.$$contextmenu=e=>e.preventDefault();return"function"==typeof t?In(t,n):t=n,W(n,Bn(Kn,{get each(){return e.items},children:t=>Bn(Qt,{get when(){return"separator"!==t.type},get fallback(){return Zh()},get children(){var n=Yh(),o=n.firstChild;return n.$$click=()=>{t.disabled||(t.onSelect?.(),e.onClose())},W(n,Bn(Qt,{get when(){return t.icon},get fallback(){return e=Jh(),W(e,Bn(Cn,{size:16})),e;var e},get children(){var e=Gh();return gn(()=>et(e,"data-lucide",t.icon)),e}}),o),W(o,()=>t.label),W(n,Bn(Qt,{get when(){return t.shortcut},get children(){var e=qh();return W(e,()=>t.shortcut),e}}),null),gn(e=>{var o=t.disabled,r=t.testId;return o!==e.e&&(n.disabled=e.e=o),r!==e.t&&et(n,"data-testid",e.t=r),e},{e:void 0,t:void 0}),n}})})),gn(t=>{var o=`${e.x}px`,r=`${e.y}px`;return o!==t.e&&he(n,"left",t.e=o),r!==t.t&&he(n,"top",t.t=r),t},{e:void 0,t:void 0}),n}})}function eb(e){const{linkDialog:t,setLinkDialog:n,imageAltDialog:o,setImageAltDialog:r,imageCaptionDialog:a,setImageCaptionDialog:i,contextMenu:s,fontDialog:l,setFontDialog:c,paragraphDialog:d,setParagraphDialog:u,tablePropertiesDialog:p,setTablePropertiesDialog:g,newDocumentDialog:f,setNewDocumentDialog:m,revisionBulkDialog:h,setRevisionBulkDialog:b,symbolDialog:y,setSymbolDialog:v,equationDialog:x,setEquationDialog:w}=e.dialogs;return[Bn(Oh,{get isOpen(){return f().isOpen},onClose:()=>{m({isOpen:!1}),e.focusInput()},onConfirm:()=>{m({isOpen:!1}),e.confirmNewDocument()}}),Bn(Ah,{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)}}),Bn(Hh,{get isOpen(){return y().isOpen},onClose:()=>{v({isOpen:!1}),e.focusInput()},onInsert:(t,n)=>{v({isOpen:!1}),e.insertSymbol(t,n)}}),Bn(Vh,{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)}}),Bn(Pm,{get isOpen(){return t().isOpen},get initialHref(){return t().initialHref},onClose:()=>{n({...t(),isOpen:!1}),e.focusInput()},onConfirm:t=>e.applyLinkCommand(t.trim()||null)}),Bn(Rm,{get isOpen(){return o().isOpen},get initialAlt(){return o().initialAlt},onClose:()=>{r({...o(),isOpen:!1}),e.focusInput()},onConfirm:t=>e.applyImageAltCommand(t.trim())}),Bn(Bm,{get isOpen(){return a().isOpen},get initialCaption(){return a().initialCaption},onClose:()=>{i({...a(),isOpen:!1}),e.focusInput()},onConfirm:t=>e.applyImageCaptionCommand(t.trim())}),Bn(Am,{get composer(){return e.commentComposer}}),Bn(_h,{get fr(){return e.findReplace}}),Bn(eh,{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}}),Bn(gh,{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}}),Bn(Bh,{get isOpen(){return p().isOpen},get initial(){return p().initial},onClose:()=>{g({...p(),isOpen:!1}),e.focusInput()},get onApply(){return e.applyTablePropertiesDialogValues}}),Bn(Qh,{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}})]}Hn(["contextmenu","click"]);var tb=/*#__PURE__*/oo("<div class=oasis-editor-main-container><section class=oasis-editor-stage>");function nb(e){let t,n;const o=F(),r=n=>{t=n,e.view.refs.onSurfaceRef?.(n)},a=t=>{n=t,e.view.refs.onViewportRef?.(t)},i=je({state:e.runtime.state,documentLayout:e.view.documentLayout,surfaceRef:()=>t,viewportRef:()=>n,zoomFactor:e.view.layout.zoomFactor,snapshotProvider:o});return[Bn(Qt,{get when(){return e.useComposedShell()},get children(){return(()=>{const t=e.shellComponent(),{runtime:n,chrome:o,view:r}=e;return Bn(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 o.showChrome()},get showTitleBar(){return o.showTitleBar()},get showMenubar(){return o.showMenubar()},get showToolbar(){return o.showToolbar()},get showOutline(){return o.showOutline},get showRuler(){return o.showRuler()},get toolbarView(){return o.toolbarView()},get toolbarLayout(){return o.toolbarLayout()},get isReadOnly(){return r.isReadOnly()},get measuredBlockHeights(){return r.measuredBlockHeights},get measuredParagraphLayouts(){return r.measuredParagraphLayouts},get documentLayout(){return r.documentLayout},get viewportHeight(){return r.viewportHeight},get layout(){return r.layout},get overlays(){return r.overlays},get refs(){return r.refs},get surfaceHandlers(){return r.surfaceHandlers},get inputHandlers(){return r.inputHandlers},get fileHandlers(){return r.fileHandlers}})})()}}),Bn(Qt,{get when(){return!e.useComposedShell()},get children(){return Bn(Q,{get editor(){return e.runtime.runtimeEditor},get children(){var s=tb(),l=s.firstChild;return W(s,Bn(Qt,{get when(){return e.chrome.showOutline()},get children(){return Bn(G,{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:o})}}),l),W(l,Bn(q,{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:r,onViewportRef:a}},get surfaceHandlers(){return e.view.surfaceHandlers},get inputHandlers(){return e.view.inputHandlers},get fileHandlers(){return e.view.fileHandlers}})),s}})}})]}var ob=/*#__PURE__*/oo("<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 rb(e){const t=Ee(),n=()=>{ke(),cn(),e.onClose()},o=()=>{ce(!1),cn(),e.onClose()};return Bn(Qt,{get when(){return e.isOpen},get children(){var e=ob(),r=e.firstChild,a=r.firstChild,i=a.nextSibling,s=i.nextSibling,l=s.nextSibling;return W(r,Bn(ze,{height:72,class:"oasis-editor-welcome-mark"}),a),W(a,()=>t("welcome.title")),W(i,()=>t("welcome.body")),W(s,()=>t("welcome.note")),W(l,Bn(St,{variant:"secondary",onClick:o,"data-testid":"editor-welcome-skip",get children(){return t("welcome.skip")}}),null),W(l,Bn(St,{variant:"primary",onClick:n,"data-testid":"editor-welcome-enable",get children(){return t("welcome.enable")}}),null),e}})}function ab(e){switch(e){case"dashed":return[ft(5),ft(3)];case"dotted":return[ft(1),ft(3)];default:return}}async function ib(e,t,n,o,r,a,i,s){const l=t.rotation;l&&(e.saveGraphicsState(n.pageIndex),e.rotateAbout(n.pageIndex,ft(o+a/2),ft(r+i/2),l)),function(e,t,n,o,r,a,i){const s=z(n.shape?.preset,ft(o),ft(r),ft(a),ft(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,o,r,a,i),await async function(e,t,n,o,r,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=o+l.left,d=r+l.top,u=Math.max(1,a-l.left-l.right),p=Math.max(1,i-l.top-l.bottom),g=A({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===g.length)return;const f=Ho(n.document);e.saveGraphicsState(n.pageIndex),e.clipRect(n.pageIndex,ft(c),ft(d),ft(u),ft(p));let m=d;for(const h of g){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,f,s);break;case"table":await s.drawTableBlock(e,n.pageIndex,h,n.document,c,m,u,n.fontRegistry,f,s);break;default:rr(h.sourceBlock,"block")}m+=Math.max(0,h.estimatedHeight)}e.restoreGraphicsState(n.pageIndex)}(e,t,n,o,r,a,i,s),l&&e.restoreGraphicsState(n.pageIndex)}async function sb(e){const{writer:t,document:n,fontRegistry:o,pageIndex:r,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 g of p.fragments){const f=g.textBox;if(!f?.floating)continue;const m=Boolean(f.floating.behindDoc);if(e.layer&&"behind"===e.layer!==m)continue;const h=s+(a.get(g.startOffset)?.left??0),b=d+p.top,y=Ye({object:U(f),pageSettings:i,contentLeft:s,contentTop:l,contentWidth:c,paragraphTop:d,lineTop:b,anchorLeft:h});await ib(t,f,{document:n,fontRegistry:o,pageIndex:r},y.x,y.y,y.width,y.height,u)}}}var lb=/* @__PURE__ */new WeakMap;function cb(e){const t=/^data:([^;,]+)(;base64)?,(.*)$/i.exec(e);if(!t)return null;const n=t[1].toLowerCase(),o=Boolean(t[2]),r=t[3]??"";if(!o)return{mediaType:n,data:(new TextEncoder).encode(decodeURIComponent(r))};const a="function"==typeof atob?atob(r):Buffer.from(r,"base64").toString("binary");return{mediaType:n,data:Uint8Array.from(a,e=>e.charCodeAt(0))}}async function db(e,t,n){let o=e;o.startsWith("data:")||(o=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(),o=new Uint8Array(await n.arrayBuffer()),r=Array.from(o,e=>String.fromCharCode(e)).join(""),a="function"==typeof btoa?btoa(r):Buffer.from(o).toString("base64");return`data:${n.type||"application/octet-stream"};base64,${a}`}(o)??o);let r=cb(o);if(!r)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})}(o):null,i=null!=a&&a.naturalWidth>0&&a.naturalHeight>0;if("image/jpeg"!==r.mediaType&&"image/jpg"!==r.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(r=e?cb(e):null,!r)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:r.data}}async function ub(e,t,n){const o=aa(t,n.src);if(!o)return null;let r=lb.get(e);r||(r=/* @__PURE__ */new Map,lb.set(e,r));const a=r.get(o);if(a)return a;const i=db(o,n.width,n.height).then(t=>t?e.registerImageResource({width:t.width,height:t.height,data:t.data,filter:"DCTDecode"}):null);return r.set(o,i),i}async function pb(e,t,n,o,r,a,i,s){const l=await ub(e,n,o);if(!l)return;const c=o.intrinsicWidth??o.width,d=o.intrinsicHeight??o.height,u=c/Math.max(1,d),p=i/Math.max(1,s);let g=r,f=a,m=i,h=s;"fit"===o.cropFit&&u>0&&(u>p?(h=i/u,f+=(s-h)/2):(m=s*u,g+=(i-m)/2));const b="fill"!==o.cropFit||o.crop?o.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=o.cropShape?.preset,v=y?function(e,t,n,o,r,a){if(!a)return e;const i=t+o/2,s=n+r/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),o=c(e.x,e.y);return{type:"cubic",x1:t.x,y1:t.y,x2:n.x,y2:n.y,x:o.x,y:o.y}}const t=c(e.x,e.y);return{type:e.type,x:t.x,y:t.y}})}(z(y,r,a,i,s),r,a,i,s,o.rotation??0):null,x=o.transparency??0,w="fit"===o.cropFit&&Boolean(o.rotation);v&&(e.saveGraphicsState(t),e.clipPath(t,v)),w&&(e.saveGraphicsState(t),e.rotateAbout(t,r+i/2,a+s/2,o.rotation??0)),x>0&&e.saveGraphicsState(t),x>0&&e.setOpacity(t,1-Math.min(1,x)),e.drawImage(t,{resourceName:l,x:g,y:f,width:m,height:h,rotation:w?void 0:o.rotation,crop:b}),x>0&&e.restoreGraphicsState(t),w&&e.restoreGraphicsState(t),v&&e.restoreGraphicsState(t);const S=o.border;if(!S)return;const I=o.rotation;I&&!v&&(e.saveGraphicsState(t),e.rotateAbout(t,r+i/2,a+s/2,I));const C=ae(S.dash);v?e.drawPath(t,{segments:v,stroke:S.color,lineWidth:S.widthPt??1}):e.drawRect(t,{x:r,y:a,width:i,height:s,stroke:S.color,lineWidth:S.widthPt??1,...C.length>0?{dashArray:C}:{}}),I&&!v&&e.restoreGraphicsState(t)}function gb(e,t){const n=new Map(e.slots.map(e=>[e.offset,e])),o=[];for(const r of t.chars){if("\n"===r.char||"\t"===r.char)continue;const e=n.get(r.paragraphOffset);e&&o.push({char:r.char,left:e.left,offset:r.paragraphOffset})}return o}function fb(e,t,n){const o=gb(e,t);if(0===o.length)return null;const r=new Map(e.slots.map(e=>[e.offset,e])),a=o[0],i=o[o.length-1],s=r.get(i.offset+1);return{left:a.left,right:s?.left??i.left+.55*n}}function mb(e,t,n,o,r,a,i){const s=fb(e,t,n.fontSize??14.6667);return s?{x:ft(o+s.left),y:ft(r+e.top+a),width:ft(Math.max(0,s.right-s.left)),height:ft(Math.max(2,e.height-i))}:null}function hb(e,t,n,o,r,a,i){const s=i.textFill;if(!s||"gradient"!==s.type||s.stops.length<2)return;const l=fb(n,o,i.fontSize??14.6667);if(!l)return;const c=r+l.left,d=r+l.right,u=a+n.top,p=a+n.top+n.height,g=re(c,u,d,p,s.angle??0);return e.registerAxialGradient(t,{x0:ft(g.x0),y0:ft(g.y0),x1:ft(g.x1),y1:ft(g.y1),stops:s.stops.map(e=>({offset:e.position,color:e.color}))})??void 0}function bb(e,t,n,o,r,a,i){const s=Me(i),l=(r,i)=>{e.drawLine(t,{x1:ft(n),y1:ft(r),x2:ft(o),y2:ft(r),stroke:a,lineWidth:ft(s),dashArray:i})};if(ko(i))return l(r-an),void l(r+an);Te(i)?function(e,t,n,o,r,a,i){let s=n,l=r;for(let c=n;c<=o;c+=1){const o=r+Math.sin((c-n)/4*Math.PI)*ht;e.drawLine(t,{x1:ft(s),y1:ft(l),x2:ft(c),y2:ft(o),stroke:a,lineWidth:ft(i)}),s=c,l=o}}(e,t,n,o,r,a,s):l(r,wo(i))}function yb(e,t,n,o,r,a,i){const s=new Map(n.slots.map(e=>[e.offset,e]));for(const l of o.chars){if("\t"!==l.char)continue;const o=s.get(l.paragraphOffset),c=s.get(l.paragraphOffset+1);if(!o||!c)continue;const d=n.resolvedTabs?.[l.paragraphOffset]?.leader;if(!d||c.left<=o.left+2)continue;const u="underscore"===d?a+2:a;e.drawLine(t,{x1:ft(r+o.left),y1:ft(u),x2:ft(r+c.left),y2:ft(u),stroke:i,lineWidth:ft("heavy"===d?1.5:1),dashArray:"dot"===d||"middleDot"===d?[1,3]:"hyphen"===d?[5,3]:void 0})}}function vb(e,t){const n=Sr(Yo(e));if(!n)return e;const o=Math.max(0,Math.min(1,t));return Ta(255+(n[0]-255)*o,255+(n[1]-255)*o,255+(n[2]-255)*o)}function xb(e,t,n){const{writer:o,pageIndex:r,baselineY:a,fontSizePt:i,mainColor:s,gradientShadingName:l,styles:c,baseTextOptions:d}=e,u=ft(1);if(c.emboss||c.imprint){const e=c.imprint?1:-1;o.drawText(r,{...d,x:ft(t)+u*e,y:ft(a)+u*e,text:n,color:"#BFBFBF"})}if(c.glow){const e=c.glow,i=.5*ft(e.radiusPt*Kr),s=vb(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)o.drawText(r,{...d,x:ft(t)+c,y:ft(a)+u,text:n,color:s})}if(c.textShadow){const e=c.textShadow,i=e.dirDeg*Math.PI/180,s=ft(e.distPt*Kr);o.drawText(r,{...d,x:ft(t)+Math.cos(i)*s,y:ft(a)+Math.sin(i)*s,text:n,color:e.color})}else c.shadow&&o.drawText(r,{...d,x:ft(t)+u,y:ft(a)+u,text:n,color:"#808080"});if(c.reflection){const e=c.reflection,l=vb(s,.6*((e.startAlpha+e.endAlpha)/2));o.drawText(r,{...d,x:ft(t),y:ft(a)+ft(e.distPt*Kr)+i,text:n,color:l})}const p=c.textOutline;o.drawText(r,{...d,x:ft(t),y:ft(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 wb(e){for(const t of e.lines){const n=new Map(t.slots.map(e=>[e.offset,e]));for(const o of t.fragments){const r=o.image;if(!r?.floating)continue;const a=Boolean(r.floating.behindDoc);if("behind"===e.layer!==a)continue;const i=n.get(o.startOffset),s=Ye({object:Wn(r),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 pb(e.writer,e.pageIndex,e.document,r,ft(s.x),ft(s.y),ft(s.width),ft(s.height))}}}function Sb(e,t,n,o,r,a,s,l){const c=fb(n,o,s.fontSize??14.6667);if(!c)return;const d=a+te(l,n.top,n.height),u=r+c.left,p=r+c.right,g="underline"===l?s.underlineColor??s.color??"#000000":s.color??"#000000";if("strike"!==l)return"doubleStrike"===l?(e.drawLine(t,{x1:ft(u),y1:ft(d-i),x2:ft(p),y2:ft(d-i),stroke:g,lineWidth:ft(1)}),void e.drawLine(t,{x1:ft(u),y1:ft(d+i),x2:ft(p),y2:ft(d+i),stroke:g,lineWidth:ft(1)})):void bb(e,t,u,p,d,g,s.underlineStyle);e.drawLine(t,{x1:ft(u),y1:ft(d),x2:ft(p),y2:ft(d),stroke:g,lineWidth:ft(1)})}async function Ib(e,t,n,o,r,a,i,s,l,c){if(r.opaque){const n=o.slots.find(e=>e.offset===r.startOffset);if(!n)return;const a=i+n.left,l=s+o.top+o.height-r.opaque.height,c=r.opaque.width,d=r.opaque.height;for(const[o,r,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:ft(o),y1:ft(r),x2:ft(i),y2:ft(s),stroke:"#64748b",lineWidth:.75});return}if(r.image){if(r.image.floating)return;const n=o.slots.find(e=>e.offset===r.startOffset)??o.slots.find(e=>e.offset>=r.startOffset);if(!n)return;return void(await pb(e,t,a,r.image,ft(i+n.left),ft(s+o.top+o.height-r.image.height),ft(r.image.width),ft(r.image.height)))}if(r.textBox){if(r.textBox.floating)return;const n=o.slots.find(e=>e.offset===r.startOffset)??o.slots.find(e=>e.offset>=r.startOffset);if(!n)return;return void(await ib(e,r.textBox,{document:a,fontRegistry:l,pageIndex:t},i+n.left,s+o.top+o.height-r.textBox.height,r.textBox.width,r.textBox.height,c))}if(r.math){const c=o.slots.find(e=>e.offset===r.startOffset)??o.slots.find(e=>e.offset>=r.startOffset);if(!c)return;const d=Oa(r.styles,n.style?.styleId,a.styles),u=l.resolveFontFace({fontFamily:"Cambria Math",bold:!1,italic:!1});return void e.drawText(t,{x:ft(i+c.left),y:ft(s+o.top+o.height*Vt),text:eo(r.math),fontSize:Fn(d),color:d.color??"#000000",fontResourceName:u.writerResourceName})}const d=Oa(r.styles,n.style?.styleId,a.styles);if(d.hidden)return;const u=l.resolveFontFace({fontFamily:d.fontFamily,bold:d.bold,italic:d.italic}),p=Fn(d),f=(d.baselineShift??0)*Kr,m=Wa(n.style,a.styles),h=yo(m.textAlignment,d.fontSize??14.6667,o.height),b=s+o.top+o.height*Vt-f+h,y=gb(o,r),v=y.map(e=>Bt(e.char,d)).join("");if(0===y.length||0===v.length)return void yb(e,t,o,r,i,b,d.color??"#000000");!function(e,t,n,o,r,a,i){if(!i.link)return;const s=fb(n,o,i.fontSize??14.6667);if(!s||s.right<=s.left)return;const l=i.link.startsWith("#");e.addLinkAnnotation(t,{x:ft(r+s.left),y:ft(a+n.top),width:ft(s.right-s.left),height:ft(n.height),...l?{destName:i.link.slice(1)}:{uri:i.link}})}(e,t,o,r,i,s,d),function(e,t,n,o,r,a,i){if(!i.shading)return;const s=mb(n,o,i,r,a,2,4);s&&e.drawRect(t,{...s,fill:i.shading})}(e,t,o,r,i,s,d),function(e,t,n,o,r,a,i){if(!i.highlight)return;const s=mb(n,o,i,r,a,2,4);s&&e.drawRect(t,{...s,fill:i.highlight})}(e,t,o,r,i,s,d),function(e,t,n,o,r,a,i){const s=i.textBorder;if(!s||"none"===s.type||s.width<=0)return;const l=mb(n,o,i,r,a,1,2);l&&e.drawRect(t,{...l,stroke:s.color,lineWidth:ft(Math.max(.5,s.width*Kr))})}(e,t,o,r,i,s,d),yb(e,t,o,r,i,b,d.color??"#000000");const x=Wa(n.style,a.styles).align??"left",w=g(d,Fn(d)),S={fontSize:p,bold:d.bold,italic:d.italic,fontResourceName:u.writerResourceName,characterSpacing:d.characterSpacing??0,horizontalScale:d.characterScale??100,fontFeatures:w};!function(e,t,n,o,r,a,i){const s="justify"===i?function(e){const t=[];let n=[];for(const o of e){const e=n[n.length-1];e&&o.offset>e.offset+1&&(t.push(n),n=[])," "!==o.char?n.push(o):n.length>0&&(t.push(n),n=[])}return n.length>0&&t.push(n),t}(t):function(e){const t=[];let n=[];for(const o of e){const e=n[n.length-1];e&&o.offset>e.offset+1&&(t.push(n),n=[]),n.push(o)}return n.length>0&&t.push(n),t}(t);for(const l of s){let t=[],r=!1;const a=()=>{if(0===t.length)return;const a=t.map(e=>Bt(e.char,o)).join("");if(a.length>0){const o=r?.8*e.fontSizePt:e.fontSizePt;xb({...e,fontSizePt:o,baseTextOptions:{...e.baseTextOptions,fontSize:o}},n+t[0].left,a)}t=[]};for(const e of l){const n=Boolean(o.smallCaps&&go(e.char));t.length>0&&n!==r&&a(),r=n,t.push(e)}a()}if(r.trailingHyphen&&a.endOffset>=r.endOffset){const t=r.slots.find(e=>e.offset===r.endOffset)??r.slots[r.slots.length-1];t&&xb(e,n+t.left,"-")}}({writer:e,pageIndex:t,baselineY:b,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:hb(e,t,o,r,i,s,d),styles:d,baseTextOptions:S},y,i,d,o,r,x),d.underline&&Sb(e,t,o,r,i,s,d,"underline"),d.strike&&Sb(e,t,o,r,i,s,d,"strike"),d.doubleStrike&&Sb(e,t,o,r,i,s,d,"doubleStrike"),d.emphasisMark&&function(e,t,n,o,r,a,i){const s=i.emphasisMark;if(!s||"none"===s)return;const l=Oo[s];if(!l)return;const c=gb(n,o),d="underDot"===s,u=Math.max(4,.35*n.height),p=d?a+n.top+n.height+u:a+n.top+u;for(let g=0;g<c.length;g+=1){const o=c[g];if(" "===o.char||"\t"===o.char||"\n"===o.char)continue;const a=c[g+1],s=a?(o.left+a.left)/2:o.left+.25*n.height;e.drawText(t,{x:ft(r+s-.25*u),y:ft(p),text:l,fontSize:ft(u),color:i.color??"#000000"})}}(e,t,o,r,i,s,d)}function Cb(e,t,n,o,r,a,i,s,l){if(0!==o.index)return;const c=la(n,l);if(!c)return;const d=o.slots[0];if(!d)return;const u=Oa(void 0,n.style?.styleId,r.styles),p=s.resolveFontFace({fontFamily:u.fontFamily,bold:u.bold,italic:u.italic}),g=An(n,r.styles),f=Fn(u),m=c.length*f*.62*Kr,h=gt(n,r.styles,d.left,m);e.drawText(t,{x:ft(a+Math.max(0,h||g)),y:ft(i+o.top+o.height*Vt),text:c,fontSize:f,color:u.color??"#000000",bold:u.bold,italic:u.italic,fontResourceName:p.writerResourceName})}function Tb(e,t,n,o,r,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 o)c=Math.max(c,h.top+h.height);if(c<=0)return;const d=Fo(n),u=d.top+c+d.bottom,p=r+(n.indentLeft??0),g=r+i-(n.indentRight??0),f=a+u;n.shading&&e.drawRect(t,{x:ft(p),y:ft(a),width:ft(Math.max(0,g-p)),height:ft(u),fill:n.shading});for(const[h,b]of s){if(!h||"none"===h.type||h.width<=0)continue;const[n,o,r,i]="top"===b?[p,a,g,a]:"bottom"===b?[p,f,g,f]:"left"===b?[p,a,p,f]:[g,a,g,f];e.drawLine(t,{x1:ft(n),y1:ft(o),x2:ft(r),y2:ft(i),stroke:h.color,lineWidth:h.width,dashArray:ab(h.type)})}const m=n.borderBar;m&&"none"!==m.type&&m.width>0&&e.drawLine(t,{x1:ft(p),y1:ft(a),x2:ft(p),y2:ft(f),stroke:m.color,lineWidth:m.width,dashArray:ab(m.type)})}async function kb(e,t,n,o,r,a,i,s,l,c){for(const d of o){for(const n of d.barTabPositionsPx??[])e.drawLine(t,{x1:ft(a+n),y1:ft(i+d.top),x2:ft(a+n),y2:ft(i+d.top+d.height),stroke:"#000000",lineWidth:ft(1)});Cb(e,t,n,d,r,a,i,s,l);for(const o of d.fragments)await Ib(e,t,n,d,o,r,a,i,s,c)}}function Pb(e,t,n,o,r,a,i){"none"===n.type||n.width<=0||e.drawLine(t,{x1:ft(o),y1:ft(r),x2:ft(a),y2:ft(i),stroke:n.color,lineWidth:ft(n.width),dashArray:ab(n.type)})}function Rb(e,t,n,o,r){const a=o+n.left,i=r+n.top,s=a+n.width,l=i+n.height;Pb(e,t,n.borders.top,a,i,s,i),Pb(e,t,n.borders.right,s,i,s,l),Pb(e,t,n.borders.bottom,a,l,s,l),Pb(e,t,n.borders.left,a,i,a,l),n.borders.topLeftToBottomRight&&Pb(e,t,n.borders.topLeftToBottomRight,a,i,s,l),n.borders.topRightToBottomLeft&&Pb(e,t,n.borders.topRightToBottomLeft,s,i,a,l)}async function Bb(e,t,n,o,r,a,i,s,l,c){if("table"!==n.sourceBlock.type)return;const d=n.sourceBlock,u=n.tableSegment?si(d,n.tableSegment):d;if(0===u.rows.length)return;const p=J({table:u,state:{document:o},pageIndex:0,originX:0,originY:0,contentWidth:i,estimatedHeight:n.estimatedHeight});for(const g of p.cells)g.shading&&e.drawRect(t,{x:ft(r+g.left),y:ft(a+g.top),width:ft(g.width),height:ft(g.height),fill:g.shading});for(const g of p.cells)if(Rb(e,t,g,r,a),g.revision){const n="insert"===g.revision.type?"#059669":"delete"===g.revision.type?"#dc2626":"#d97706";e.drawRect(t,{x:ft(r+g.left+1),y:ft(a+g.top+1),width:ft(Math.max(0,g.width-2)),height:ft(Math.max(0,g.height-2)),stroke:n,lineWidth:ft(2)})}for(const g of p.cells)for(const n of g.paragraphs)await kb(e,t,n.paragraph,n.lines,o,r+n.originX,a+n.originY,s,l,c)}var Mb={drawParagraph:kb,drawTableBlock:Bb};async function Ob(e,t,n,o,r,a,i,s,l,c,d){if(!n||0===n.length)return;const u=a;let p=a;for(let g=0;g<n.length;g+=1){const f=n[g];switch(f.sourceBlock.type){case"paragraph":{if(!f.layout)break;const n=Wa(f.sourceBlock.style,o.styles),g=p+(0===f.layout.startOffset&&p>a?n.spacingBefore??0:0);d?.(f.sourceBlock.id,g);const m=g+Fo(n).top;Tb(e,t,n,f.layout.lines,r,g,i),c&&(await wb({writer:e,pageIndex:t,lines:f.layout.lines,document:o,pageSettings:c,contentLeft:r,contentTop:u,contentWidth:i,paragraphTop:m,layer:"behind"}),await sb({writer:e,document:o,fontRegistry:s,pageIndex:t,lines:f.layout.lines,pageSettings:c,contentLeft:r,contentTop:u,contentWidth:i,paragraphTop:g,drawers:Mb,layer:"behind"})),await kb(e,t,f.sourceBlock,f.layout.lines,o,r,m,s,l,Mb),c&&(await wb({writer:e,pageIndex:t,lines:f.layout.lines,document:o,pageSettings:c,contentLeft:r,contentTop:u,contentWidth:i,paragraphTop:m,layer:"front"}),await sb({writer:e,document:o,fontRegistry:s,pageIndex:t,lines:f.layout.lines,pageSettings:c,contentLeft:r,contentTop:u,contentWidth:i,paragraphTop:g,drawers:Mb,layer:"front"}));break}case"table":if(f.sourceBlock.style?.floating&&c){const n=Se(f.sourceBlock,i),a=Ke({floating:f.sourceBlock.style.floating,pageSettings:c,contentLeft:r,contentTop:u,contentWidth:i,anchorTop:p,width:n,height:f.floatingTableHeight??1,pageIndex:t});a.y+=f.floatingTableOffsetY??0,await Bb(e,t,{...f,estimatedHeight:a.height},o,a.x,a.y,i,s,l,Mb);break}await Bb(e,t,f,o,r,p,i,s,l,Mb);break;default:rr(f.sourceBlock,"block")}if("paragraph"===f.sourceBlock.type&&f.layout){const s=n[g+1];if("paragraph"===s?.sourceBlock.type&&s.layout&&s.sourceBlock.id!==f.sourceBlock.id){const n=Wa(f.sourceBlock.style,o.styles),l=Wa(s.sourceBlock.style,o.styles);if(yt(n,l)){const o=p+(0===f.layout.startOffset&&p>a?n.spacingBefore??0:0)+Fo(n).top;let s=0;for(const e of f.layout.lines)s=Math.max(s,e.top+e.height);const l=o+s,c=r+(n.indentLeft??0),d=r+i-(n.indentRight??0),u=n.borderBetween;e.drawLine(t,{x1:ft(c),y1:ft(l),x2:ft(d),y2:ft(l),stroke:u.color,lineWidth:u.width,dashArray:ab(u.type)})}}}p+=Math.max(0,f.estimatedHeight)}}async function Ab(e,t,n,o,r,a,i){if(e.drawRect(t,{x:0,y:0,width:n,height:o,fill:r?.pageColor||"#ffffff"}),a){const r=a.distance??12,i="dashed"===a.style?[6,4]:"dotted"===a.style?[1,3]:void 0;if(e.drawRect(t,{x:r,y:r,width:n-2*r,height:o-2*r,fill:void 0,stroke:a.color,lineWidth:a.width,...i?{dashArray:i}:{}}),"double"===a.style){const i=r+2*a.width;e.drawRect(t,{x:i,y:i,width:n-2*i,height:o-2*i,stroke:a.color,lineWidth:a.width})}}const s=r?.watermark;if("text"===s?.kind&&s.text)e.saveGraphicsState(t),e.rotateAbout(t,n/2,o/2,s.rotation??-45),e.setOpacity(t,s.opacity??.25),e.drawText(t,{x:n/2,y:o/2,text:s.text,fontSize:s.fontSize??48,color:s.color??"#94a3b8"}),e.restoreGraphicsState(t);else if("image"===s?.kind&&s.src&&i){const r={src:s.src,width:360,height:180},a=await ub(e,i,r);if(a){const i=s.scale??1,l=r.width*i,c=r.height*i;e.saveGraphicsState(t),e.rotateAbout(t,n/2,o/2,s.rotation??-45),e.setOpacity(t,s.opacity??.25),e.drawImage(t,{resourceName:a,x:(n-l)/2,y:(o-c)/2,width:l,height:c}),e.restoreGraphicsState(t)}}}var Fb=[{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 Db(e,t,n){return`${e.toLowerCase()}:${t?"bold":"regular"}${n?"italic":""}`}function Eb(e){return e.replace(/[^A-Za-z0-9_]/g,"")}var Lb=class{faces=/* @__PURE__ */new Map;fallbackFamily="Helvetica";constructor(){for(const e of Fb)this.registerFontFace(e)}registerFontFace(e){this.faces.set(Db(e.family,e.bold,e.italic),e)}resolveFontFace(e){const t=x(e.fontFamily),n=Boolean(e.bold),o=Boolean(e.italic);return this.faces.get(Db(t,n,o))??this.faces.get(Db(this.fallbackFamily,n,o))??this.faces.get(Db(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(x).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[o,r]of Object.entries(Ae)){const e=await T(r);if(!e)continue;const t="bold"===o||"bolditalic"===o,n="italic"===o||"bolditalic"===o,a=`Roboto${o[0].toUpperCase()}${o.slice(1)}`;this.registerFontFace({key:`roboto:${o}`,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 $t(e.families);for(const n of t){const e=`Remote${Eb(n.postscriptName||n.family)}`;this.registerFontFace({key:Db(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 Io){const o=[n.family,...n.aliases].map(e=>e.toLowerCase());if(e&&!o.some(t=>e.has(t)))continue;for(const e of o)t.add(e);const r=[];for(const[e,t]of Object.entries(n.files)){const o=await T(t);if(!o)continue;const a="bold"===e||"bolditalic"===e,i="italic"===e||"bolditalic"===e,s=`${Eb(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:o}};this.registerFontFace(l),r.push(l)}for(const e of n.aliases)for(const t of r)this.registerFontFace({...t,key:`${e.toLowerCase()}:${t.key.split(":")[1]}`,family:e})}return t}},Nb="%PDF-1.4\n% Oasis PDF\n",zb=[{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 $b(e){return Number.isFinite(e)?Number(e.toFixed(3)).toString():"0"}function Hb(e){return Math.max(0,e).toString(16).padStart(4,"0").slice(-4).toUpperCase()}function Wb(e,t){if(!e)return t;const n=Sr(Yo(e));return n?[n[0]/255,n[1]/255,n[2]/255]:t}function Ub(e,t,n){const[o,r,a]=Wb(e,n);return`${$b(o)} ${$b(r)} ${$b(a)} ${t}`}function jb(e,t){return(e&&e.trim().length>0?e:t).replaceAll(" ","_").replace(/[^A-Za-z0-9_.+-]/g,"")}var Vb=/* @__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 Kb(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:Vb.get(t)??63}(e).toString(16).padStart(2,"0").toUpperCase()).join("")}function _b(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(Hb).join("")}function Xb(e,t=[]){const n=new TextEncoder,o=n.encode(["<< /Length "+e.byteLength,...t,">>"].join(" ")+"\nstream\n"),r=n.encode("\nendstream"),a=new Uint8Array(o.length+e.length+r.length);return a.set(o),a.set(e,o.length),a.set(r,o.length+e.length),a}function Gb(e,t=[]){return Xb(s(e,{level:9}),["/Filter /FlateDecode",...t])}function qb(e,t){const n=[...new Set(t)].sort((e,t)=>e-t),o=[];let r=-1,a=-2,i=[];const s=()=>{i.length&&o.push(r+" ["+i.join(" ")+"]")};for(const l of n)(l!==a+1||r<0)&&(s(),r=l,i=[]),i.push($b(e[l]??0)),a=l;return s(),o.join(" ")}function Yb(e){return Hb(e)}function Zb(e){return`% OasisText ${_b(Array.from(e).map(e=>e.codePointAt(0)??65533))}`}function Jb(e){return e&&0!==e.length?`[${e.map(e=>$b(e)).join(" ")}] 0 d`:null}var Qb=class{page;fonts;images;shadings;constructor(e,t,n,o){this.page=e,this.fonts=t,this.images=n,this.shadings=o}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(Ub(e.fill,"rg",[1,1,1])),e.stroke){n.push(Ub(e.stroke,"RG",[0,0,0])),n.push(`${$b(e.lineWidth??1)} w`);const t=Jb(e.dashArray);t&&n.push(t)}n.push([$b(e.x),$b(t.height-e.y-e.height),$b(e.width),$b(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=Jb(e.dashArray),o=["q",Ub(e.stroke,"RG",[0,0,0])];n&&o.push(n),o.push(`${$b(e.lineWidth??1)} w`,`${$b(e.x1)} ${$b(t.height-e.y1)} m`,`${$b(e.x2)} ${$b(t.height-e.y2)} l`,"S","Q"),t.commands.push(o.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,o=["q"];e.fill&&o.push(Ub(e.fill,"rg",[1,1,1])),e.stroke&&(o.push(Ub(e.stroke,"RG",[0,0,0])),o.push(`${$b(e.lineWidth??1)} w`));for(const r of e.segments)switch(r.type){case"move":o.push(`${$b(r.x)} ${$b(n(r.y))} m`);break;case"line":o.push(`${$b(r.x)} ${$b(n(r.y))} l`);break;case"cubic":o.push(`${$b(r.x1)} ${$b(n(r.y1))} ${$b(r.x2)} ${$b(n(r.y2))} ${$b(r.x)} ${$b(n(r.y))} c`);break;case"close":o.push("h")}e.fill&&e.stroke?o.push("B"):e.fill?o.push("f"):o.push("S"),o.push("Q"),t.commands.push(o.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 o=this.page;if(!n)return;const r=o.height-t,a=-n*Math.PI/180,i=Math.cos(a),s=Math.sin(a),l=e-e*i+r*s,c=r-e*s-r*i;o.commands.push(`${$b(i)} ${$b(s)} ${$b(-s)} ${$b(i)} ${$b(l)} ${$b(c)} cm`)}clipRect(e,t,n,o){const r=this.page;n<=0||o<=0||r.commands.push(`${$b(e)} ${$b(r.height-t-o)} ${$b(n)} ${$b(o)} re`,"W","n")}clipPath(e){const t=this.page;if(0===e.length)return;const n=e=>t.height-e,o=[];for(const r of e)switch(r.type){case"move":o.push(`${$b(r.x)} ${$b(n(r.y))} m`);break;case"line":o.push(`${$b(r.x)} ${$b(n(r.y))} l`);break;case"cubic":o.push(`${$b(r.x1)} ${$b(n(r.y1))} ${$b(r.x2)} ${$b(n(r.y2))} ${$b(r.x)} ${$b(n(r.y))} c`);break;case"close":o.push("h")}o.push("W","n"),t.commands.push(o.join("\n"))}drawText(e){if(0===e.text.length)return;const t=this.fonts.resolveAndMarkFontName(e),n=this.fonts.getUnicodeState(t),o=n?this.fonts.buildUnicodeShowCommand(n,e.text,e.fontFeatures):`<${Kb(e.text)}> Tj`;null!==o&&(e.gradientShadingName?this.emitGradientTextBlock(t,o,e,e.gradientShadingName):this.emitTextBlock(t,o,e))}textSetupCommands(e,t){return[`/${e} ${$b(t.fontSize??12)} Tf`,...t.horizontalScale&&t.horizontalScale>0&&100!==t.horizontalScale?[`${$b(t.horizontalScale)} Tz`]:[],...t.characterSpacing&&0!==t.characterSpacing?[`${$b(t.characterSpacing)} Tc`]:[]]}emitTextBlock(e,t,n){const o=this.page;o.commands.push([Zb(n.text),"BT",Ub(n.color,"rg",[0,0,0]),...n.renderMode&&0!==n.renderMode?[Ub(n.strokeColor??n.color,"RG",[0,0,0]),`${$b(n.strokeWidth??Math.max(.3,.03*(n.fontSize??12)))} w`,`${n.renderMode} Tr`]:[],...this.textSetupCommands(e,n),`${$b(n.x)} ${$b(o.height-n.y)} Td`,t,"ET"].join("\n"))}emitGradientTextBlock(e,t,n,o){const r=this.page;r.commands.push([Zb(n.text),"q","BT",...this.textSetupCommands(e,n),"7 Tr",`${$b(n.x)} ${$b(r.height-n.y)} Td`,t,"ET",`/${o} 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,o=Number.isFinite(e.rotation)?e.rotation??0:0,r=e.crop,a=r?.left??0,i=r?.top??0,s=r?.right??0,l=r?.bottom??0;if(r&&(a>0||i>0||s>0||l>0))return void this.drawCroppedImage(e,n,o,{left:a,top:i,right:s,bottom:l});if(0===o)return void t.commands.push(["q",[$b(e.width),"0","0",$b(e.height),$b(e.x),$b(n),"cm"].join(" "),`/${e.resourceName} Do`,"Q"].join("\n"));const c=-o*Math.PI/180,d=Math.cos(c),u=Math.sin(c),p=e.width*d,g=e.width*u,f=-e.height*u,m=e.height*d,h=e.x+e.width/2-.5*p-.5*f,b=n+e.height/2-.5*g-.5*m;t.commands.push(["q",[$b(p),$b(g),$b(f),$b(m),$b(h),$b(b),"cm"].join(" "),`/${e.resourceName} Do`,"Q"].join("\n"))}drawCroppedImage(e,t,n,o){const r=this.page,{width:a,height:i}=e,s=a/Math.max(1e-4,1-o.left-o.right),l=i/Math.max(1e-4,1-o.top-o.bottom),c=-o.left*s,d=-o.bottom*l,u=-n*Math.PI/180,p=Math.cos(u),g=Math.sin(u),f=a/2,m=i/2,h=p,b=g,y=-g,v=p,x=e.x+a/2-(h*f+y*m),w=t+i/2-(b*f+v*m);r.commands.push(["q",[$b(h),$b(b),$b(y),$b(v),$b(x),$b(w),"cm"].join(" "),`0 0 ${$b(a)} ${$b(i)} re W n`,[$b(s),"0","0",$b(l),$b(c),$b(d),"cm"].join(" "),`/${e.resourceName} Do`,"Q"].join("\n"))}};function ey(e,t,n){if(e.seek(t),1!==e.u16())return null;const o=e.u16();return n(e,t+e.u32(),o)}function ty(e,t){const n=new Array(t);for(let o=0;o<t;o+=1)n[o]=e.u16();return n}function ny(e,t,n){const o=new Array(t);for(let r=0;r<t;r+=1)o[r]=n+e.u16();return o}function oy(e,t){e.seek(t);const n=e.u16();if(1===n){const t=e.u16(),n=/* @__PURE__ */new Map;for(let o=0;o<t;o+=1)n.set(e.u16(),o);return e=>n.get(e)??-1}if(2===n){const t=e.u16(),n=[];for(let o=0;o<t;o+=1){const t=e.u16(),o=e.u16(),r=e.u16();n.push({start:t,end:o,startIndex:r})}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 ry(e,t){e.seek(t);const n=e.u16();if(1===n){const t=e.u16(),n=e.u16(),o=ty(e,n);return e=>{const r=e-t;return r>=0&&r<n?o[r]:0}}if(2===n){const t=e.u16(),n=[];for(let o=0;o<t;o+=1){const t=e.u16(),o=e.u16(),r=e.u16();n.push({start:t,end:o,classValue:r})}return e=>{for(const t of n)if(e>=t.start&&e<=t.end)return t.classValue;return 0}}return()=>0}function ay(e){e.seek(0),e.skip(2),e.skip(2);const t=e.u16(),n=e.u16(),o=e.u16(),r=function(e,t){e.seek(t);const n=e.u16(),o=[];for(let r=0;r<n;r+=1){const n=e.tag(),r=t+e.u16();o.push({tag:n,offset:r})}return o.map(({tag:t,offset:n})=>(e.seek(n),e.skip(2),{tag:t,lookupIndices:ty(e,e.u16())}))}(e,n),a=function(e,t){e.seek(t);const n=e.u16(),o=[];for(let c=0;c<n;c+=1){const n=e.tag(),r=t+e.u16();o.push({tag:n,offset:r})}if(0===o.length)return[];const r=o.find(e=>"latn"===e.tag)??o.find(e=>"DFLT"===e.tag)??o[0];e.seek(r.offset);const a=e.u16();if(0===a)return[];e.seek(r.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=r[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:o}}function iy(e,t,n){return e.seek(t),ny(e,e.u16(),t).map(t=>{e.seek(t);const o=e.u16();e.skip(2);const r=ny(e,e.u16(),t),a=[];for(const i of r)try{const t=n(e,i,o);t&&a.push(t)}catch{}return{lookupType:o,subtables:a}})}function sy(e,t){const n=/* @__PURE__ */new Set;for(const o of t)for(const t of e.get(o)??[])n.add(t);return Array.from(n).sort((e,t)=>e-t)}function ly(e,t){if(e.seek(t),1!==e.u16())return null;const n=t+e.u16(),o=e.u16(),r=ny(e,o,t).map(t=>(e.seek(t),ty(e,e.u16())));return{coverage:oy(e,n),sets:r}}function cy(e,t){const n=new Array(t);for(let o=0;o<t;o+=1){const t=e.u16(),r=e.u16();n[o]={sequenceIndex:t,lookupListIndex:r}}return n}function dy(e,t,n,o){for(const r of n)o.applyLookupIndexAt(r.lookupListIndex,e,t+r.sequenceIndex)}function uy(e,t){e.seek(t);const n=e.u16();return ny(e,n,t).map(t=>(e.seek(t),{backtrack:ty(e,e.u16()),input:ty(e,Math.max(0,e.u16()-1)),lookahead:ty(e,e.u16()),records:cy(e,e.u16())}))}function py(e,t,n,o,r){const a=(e,n)=>{const o=t[e];return o?r?"b"===n?r.backtrack(o.id):"l"===n?r.lookahead(o.id):r.input(o.id):o.id:null};for(const i of e){const e=i.input.length+1;if(n+e>t.length)continue;let r=!0;for(let t=0;t<i.input.length;t+=1)if(a(n+1+t,"i")!==i.input[t]){r=!1;break}if(r){for(let e=0;e<i.backtrack.length;e+=1)if(a(n-1-e,"b")!==i.backtrack[e]){r=!1;break}if(r){for(let t=0;t<i.lookahead.length;t+=1)if(a(n+e+t,"l")!==i.lookahead[t]){r=!1;break}if(r)return dy(t,n,i.records,o),e}}}return null}function gy(e,t,n){switch(n){case 1:return function(e,t){e.seek(t);const n=e.u16(),o=t+e.u16();if(1===n){const t=e.i16(),n=oy(e,o);return{apply(e,o){const r=e[o];return!r||n(r.id)<0?null:(r.id=r.id+t&65535,1)}}}if(2===n){const t=e.u16(),n=ty(e,t),r=oy(e,o);return{apply(e,o){const a=e[o];if(!a)return null;const i=r(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=ly(e,t);if(!n)return null;const{coverage:o,sets:r}=n;return{apply(e,t){const n=e[t];if(!n)return null;const a=o(n.id);if(a<0||a>=r.length)return null;const i=r[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=ly(e,t);if(!n)return null;const{coverage:o,sets:r}=n;return{apply(e,t){const n=e[t];if(!n)return null;const a=o(n.id);if(a<0||a>=r.length)return null;const i=r[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(),o=e.u16(),r=ny(e,o,t).map(t=>(e.seek(t),ny(e,e.u16(),t).map(t=>{e.seek(t);const n=e.u16(),o=e.u16();return{ligatureGlyph:n,components:ty(e,Math.max(0,o-1))}}))),a=oy(e,n);return{apply(e,t){const n=e[t];if(!n)return null;const o=a(n.id);if(o<0||o>=r.length)return null;for(const a of r[o]){const{components:n}=a;if(t+n.length>e.length-1)continue;let o=!0;for(let a=0;a<n.length;a+=1)if(e[t+1+a].id!==n[a]){o=!1;break}if(!o)continue;const r=n.length+1,i=[];for(let a=0;a<r;a+=1)i.push(...e[t+a].codePoints);return e.splice(t,r,{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=ny(e,e.u16(),t),o=ny(e,e.u16(),t),r=ny(e,e.u16(),t),a=cy(e,e.u16()),i=n.map(t=>oy(e,t)),s=o.map(t=>oy(e,t)),l=r.map(t=>oy(e,t));return{apply(e,t,n){if(0===s.length)return null;if(t+s.length>e.length)return null;for(let o=0;o<s.length;o+=1)if(s[o](e[t+o].id)<0)return null;for(let o=0;o<i.length;o+=1){const n=e[t-1-o];if(!n||i[o](n.id)<0)return null}for(let o=0;o<l.length;o+=1){const n=e[t+s.length+o];if(!n||l[o](n.id)<0)return null}return dy(e,t,a,n),s.length}}}if(1===n){const n=t+e.u16(),o=e.u16(),r=ny(e,o,t),a=oy(e,n),i=r.map(t=>uy(e,t));return{apply(e,t,n){const o=e[t];if(!o)return null;const r=a(o.id);return r<0||r>=i.length?null:py(i[r],e,t,n,null)}}}if(2===n){const n=t+e.u16(),o=t+e.u16(),r=t+e.u16(),a=t+e.u16(),i=e.u16(),s=new Array(i);for(let g=0;g<i;g+=1){const n=e.u16();s[g]=0===n?0:t+n}const l=oy(e,n),c=ry(e,o),d=ry(e,r),u=ry(e,a),p=s.map(t=>0===t?[]:uy(e,t));return{apply(e,t,n){const o=e[t];if(!o)return null;if(l(o.id)<0)return null;const r=d(o.id),a=p[r];return a?py(a,e,t,n,{backtrack:c,input:d,lookahead:u}):null}}}return null}(e,t);case 7:return ey(e,t,gy);default:return null}}var fy=class e{lookups;featureToLookups;constructor(e,t){this.lookups=e,this.featureToLookups=t}static parse(t){try{const n=new Yt(t),{featureToLookups:o,lookupListOffset:r}=ay(n),a=iy(n,r,gy);return new e(a,o)}catch{return null}}hasAnyFeature(e){return e.some(e=>this.featureToLookups.has(e))}collectLookupIndices(e){return sy(this.featureToLookups,e)}applyLookupIndexAt(e,t,n){const o=this.lookups[e];if(!o||n<0||n>=t.length)return null;for(const r of o.subtables){const e=r.apply(t,n,this);if(null!==e)return e}return null}shape(e,t){const n=this.collectLookupIndices(t);for(const o of n){let t=0;for(;t<e.length;){const n=this.applyLookupIndexAt(o,e,t);t+=n&&n>0?n:1}}}};function my(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 hy(e){let t=0;for(let n=0;n<8;n+=1)e&1<<n&&(t+=1);return 2*t}function by(e,t,n){switch(n){case 1:return function(e,t){e.seek(t);const n=e.u16(),o=t+e.u16();if(1===n){const t=my(e,e.u16()),n=oy(e,o);return 0===t?null:{apply:(e,o,r)=>n(e[r])<0?null:(o[r]+=t,1)}}if(2===n){const t=e.u16(),n=e.u16(),r=hy(t),a=e.tell(),i=new Array(n);for(let o=0;o<n;o+=1)e.seek(a+o*r),i[o]=my(e,t);const s=oy(e,o);return{apply(e,t,o){const r=s(e[o]);if(r<0||r>=n)return null;const a=i[r];return 0===a?null:(t[o]+=a,1)}}}return null}(e,t);case 2:return function(e,t){e.seek(t);const n=e.u16(),o=t+e.u16(),r=e.u16(),a=e.u16(),i=!!(4&a);if(1===n){const n=e.u16(),s=ny(e,n,t).map(t=>{e.seek(t);const n=e.u16(),o=/* @__PURE__ */new Map;for(let i=0;i<n;i+=1){const t=e.u16(),n=my(e,r),i=my(e,a);o.set(t,{secondGlyph:t,value1XAdvance:n,value2XAdvance:i})}return o}),l=oy(e,o);return{apply(e,t,n){const o=e[n+1];if(void 0===o)return null;const r=l(e[n]);if(r<0||r>=s.length)return null;const a=s[r].get(o);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=hy(r),u=d+hy(a),p=e.tell(),g=new Array(l*c),f=new Array(l*c);for(let t=0;t<l;t+=1)for(let n=0;n<c;n+=1){const o=(t*c+n)*u;e.seek(p+o),g[t*c+n]=my(e,r),e.seek(p+o+d),f[t*c+n]=my(e,a)}const m=oy(e,o),h=ry(e,n),b=ry(e,s);return{apply(e,t,n){const o=e[n],r=e[n+1];if(void 0===r)return null;if(m(o)<0)return null;const a=h(o),s=b(r);if(a>=l||s>=c)return null;const d=a*c+s,u=g[d],p=f[d];return 0===u&&0===p?null:(t[n]+=u,t[n+1]+=p,i?2:1)}}}return null}(e,t);case 9:return ey(e,t,by);default:return null}}var yy=class e{lookups;featureToLookups;constructor(e,t){this.lookups=e,this.featureToLookups=t}static parse(t){try{const n=new Yt(t),{featureToLookups:o,lookupListOffset:r}=ay(n),a=iy(n,r,by);return new e(a,o)}catch{return null}}hasAnyFeature(e){return e.some(e=>this.featureToLookups.has(e))}position(e,t,n){const o=sy(this.featureToLookups,n);for(const r of o){const n=this.lookups[r];if(!n)continue;let o=0;for(;o<e.length;){let r=null;for(const a of n.subtables)if(r=a.apply(e,t,o),null!==r)break;o+=r&&r>0?r:1}}}},vy=/* @__PURE__ */new Set(["kern"]),xy=class{font;gsub;gpos;constructor(e){this.font=e;const t=e.getRawTableData("GSUB");this.gsub=t?fy.parse(t):null;const n=e.getRawTableData("GPOS");this.gpos=n?yy.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 o=t?.filter(e=>!vy.has(e))??[],r=t?.filter(e=>vy.has(e))??[];this.gsub&&o.length>0&&this.gsub.shape(n,o);const a=n.map(e=>this.font.advanceWidthForGlyph(e.id));this.gpos&&r.length>0&&this.gpos.position(n.map(e=>e.id),a,r);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),o=a[c];i.push({id:e.id,codePoints:e.codePoints,advanceWidth:t}),s.push({xAdvance:o}),l+=o}return{glyphs:i,positions:s,advanceWidth:l}}},wy=class{font;constructor(e){this.font=e}layout(e){const t=[],n=[];let o=0;for(const r of e){const e=r.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}),o+=i}return{glyphs:t,positions:n,advanceWidth:o}}};function Sy(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Iy(e,t){return Sy(e).getUint16(t)}function Cy(e,t){return Sy(e).getInt16(t)}function Ty(e,t,n){Sy(e).setUint16(t,n,!1)}function ky(e,t,n){Sy(e).setUint32(t,n,!1)}function Py(e){return e+3&-4}function Ry(e){const t=e.reduce((e,t)=>e+Py(t.byteLength),0),n=new Uint8Array(t);let o=0;for(const r of e)n.set(r,o),o+=Py(r.byteLength);return n}function By(e,t){const n=[],o=Sy(e);if(0===t)for(let r=0;r+1<e.byteLength;r+=2)n.push(2*o.getUint16(r));else for(let r=0;r+3<e.byteLength;r+=4)n.push(o.getUint32(r));return n}function My(e,t){const n=e[t],o=e[t+1];return void 0===n||void 0===o?null:{start:n,end:o}}function Oy(e,t){if(e.byteLength<10||Cy(e,0)>=0)return;let n=10,o=0;do{if(n+4>e.byteLength)throw new Error("Truncated composite glyph");o=Iy(e,n),t(Iy(e,n+2),n+2),n+=4,n+=1&o?4:2,8&o?n+=2:64&o?n+=4:128&o&&(n+=8)}while(32&o)}function Ay(e,t,n){const o=/* @__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 r=n.get(e.glyphForCodePoint(t));r&&o.set(t,r)}const r=[...o].sort(([e],[t])=>e-t),a=[];for(const[h,b]of r){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);Ty(i,0,12),ky(i,4,i.length),ky(i,12,a.length),a.forEach((e,t)=>{const n=16+12*t;ky(i,n,e.start),ky(i,n+4,e.end),ky(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));Ty(d,0,4),Ty(d,2,c),Ty(d,6,2*l),Ty(d,8,2*e),Ty(d,10,Math.log2(e)),Ty(d,12,2*l-2*e),s.forEach((e,t)=>{Ty(d,14+2*t,e.end),Ty(d,16+2*l+2*t,e.start),Ty(d,16+4*l+2*t,e.gid-e.start&65535)})}if(d&&r.every(([e])=>e<65535)){const e=new Uint8Array(12+d.length);return Ty(e,2,1),Ty(e,4,3),Ty(e,6,1),ky(e,8,12),e.set(d,12),e}const u=d?2:1,p=4+8*u,g=new Uint8Array(p+(d?.length??0)+i.length);Ty(g,2,u),d&&(Ty(g,4,3),Ty(g,6,1),ky(g,8,p),g.set(d,p));const f=d?12:4,m=p+(d?.length??0);return Ty(g,f,3),Ty(g,f+2,10),ky(g,f+4,m),g.set(i,m),g}function Fy(e,t,n,o){const r=e.getRawTableData("glyf"),a=e.getRawTableData("loca"),i=e.getRawTableData("head"),s=e.getRawTableData("hhea"),l=e.getRawTableData("maxp");if(!(r&&a&&i&&s&&l))throw new Error("Missing required TrueType tables for subsetting");const c=By(a,Iy(i,50)),d=[],u=[];let p=0;for(const x of t){d.push(p);const e=My(c,x);if(!e||e.end<e.start||e.end>r.length)throw new Error("Invalid glyph range");if(e.end===e.start)continue;const t=r.slice(e.start,e.end);Oy(t,(e,o)=>{const r=n.get(e);if(void 0===r)throw new Error("Missing composite dependency");Ty(t,o,r)}),u.push(t),p+=Py(t.length)}d.push(p);const g=function(e){const t=e.every(e=>e%2==0&&e<=131070),n=new Uint8Array(e.length*(t?2:4));return e.forEach((e,o)=>{t?Ty(n,2*o,e/2):ky(n,4*o,e)}),{data:n,format:t?0:1}}(d),f=function(e,t,n){const o=e.getRawTableData("hmtx"),r=Iy(n,34);if(!o||r<1||r>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<r?4*e+2:4*r+2*(e-r),l=t<i?4*t+2:4*i+2*(t-i);t<i&&Ty(s,4*t,a[t]),Sy(s).setInt16(l,Cy(o,n))}),{data:s,longCount:i}}(e,t,s),m=i.slice();ky(m,8,0),Ty(m,50,g.format);const h=s.slice();Ty(h,34,f.longCount);const b=l.slice();Ty(b,4,t.length);const y={cmap:Ay(e,o,n),head:m,hhea:h,maxp:b,hmtx:f.data,loca:g.data,glyf:Ry(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),ky(y.post,0,196608)),y}var Dy=class{createSubset(e,t){const n=/* @__PURE__ */new Map,o=[];for(const d of t)o.push(d.id),n.has(d.id)||n.set(d.id,d.codePoints);const r=function(e,t){const n=e.getRawTableData("glyf"),o=e.getRawTableData("loca"),r=e.getRawTableData("head");if(!n||!o||!r)return Array.from(/* @__PURE__ */new Set([0,...t])).sort((e,t)=>e-t);const a=By(o,Iy(r,50)),i=/* @__PURE__ */new Set([0,...t]),s=Array.from(i);for(;s.length>0;){const t=s.pop(),o=My(a,t);if(!o||t>=e.glyphCount||o.end<o.start||o.end>n.byteLength)throw new Error("Invalid subset glyph range");o.end!==o.start&&Oy(n.slice(o.start,o.end),e=>{i.has(e)||(i.add(e),s.push(e))})}return Array.from(i).sort((e,t)=>e-t)}(e,o),a=new Map(r.map((e,t)=>[e,t])),i=Fy(e,r,a,n),s=dn(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 r)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 Ey=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 xy(e);return{program:e,layouter:t.hasShaping?t:new wy(e),subsetter:new Dy}}(function(e){const t=de.decodeSync(e);return xn.parse(t)}(e.fontData)),n=1e3/t.program.unitsPerEm,o={id:0,codePoints:[0],advanceWidth:t.program.advanceWidthForGlyph(0)};this.unicodeFontStates.set(e.resourceName,{resource:e,font:t,usedGlyphs:/* @__PURE__ */new Map([[0,o]]),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 o=this.layoutUnicodeText(e,t,n),r=this.encodeUnicodeGlyphRun(e,o);return 0===r.length?null:r.some(e=>Math.abs(e.nominalWidth-e.desiredAdvance)>.01)?`[${r.map(e=>{const t=e.nominalWidth-e.desiredAdvance;return 0===t?`<${Yb(e.glyphId)}>`:`<${Yb(e.glyphId)}> ${$b(t)}`}).join(" ")}] TJ`:`<${r.map(e=>Yb(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 o=`${n?.join(",")??""}\0${t}`,r=e.layoutCache.get(o);if(r)return r;const a=e.font.layouter.layout(t,n);return e.layoutCache.set(o,a),a}encodeUnicodeGlyphRun(e,t){return t.glyphs.map((n,o)=>{e.usedGlyphs.has(n.id)||e.usedGlyphs.set(n.id,n);const r=t.positions[o],a=n.advanceWidth*e.scale,i=(r?.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()),o=n.fontFile,r=t(Gb(o,[`/Length1 ${o.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=`${jb(`${e.resource.resourceName}AAAAAA`,"OASISF").slice(0,6).padEnd(6,"A")}+${jb(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($b).join(" ")}]`,`/ItalicAngle ${$b(a.italicAngle)}`,`/Ascent ${$b(a.ascent*e.scale)}`,`/Descent ${$b(a.descent*e.scale)}`,`/CapHeight ${$b(a.capHeight*e.scale)}`,`/XHeight ${$b(a.xHeight*e.scale)}`,"/StemV 0",`/FontFile2 ${r} 0 R`,">>"].join("\n")),u=[...e.usedGlyphs.keys()],p=Math.max(0,...u),g=new Uint8Array(2*(p+1)),f=new DataView(g.buffer);for(const v of u)f.setUint16(2*v,n.encodeGlyph(v));const m=u.every(e=>n.encodeGlyph(e)===e)?"/Identity":t(Gb(g))+" 0 R",h=t(["<< /Type /Font","/Subtype /CIDFontType2",`/BaseFont /${l}`,"/CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >>",`/FontDescriptor ${d} 0 R`,`/W [${qb(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])=>"<"+Hb(e)+"> <"+_b([...t])+">"),n=[];for(let o=0;o<t.length;o+=100){const e=t.slice(o,o+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(Gb((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"))}},Ly=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(Xb(e.data,["/Filter /DCTDecode","/Type /XObject","/Subtype /Image",`/Width ${e.width}`,`/Height ${e.height}`,"/ColorSpace /DeviceRGB","/BitsPerComponent 8"]))}},Ny=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:o}of this.shadings)t.set(n,this.addShadingObject(o,e));return t}addShadingObject(e,t){const n=t(function(e){if(2===e.length)return zy(e[0].rgb,e[1].rgb);const t=[];for(let r=0;r<e.length-1;r+=1)t.push(zy(e[r].rgb,e[r+1].rgb));const n=e.slice(1,-1).map(e=>$b(e.offset)),o=e.slice(0,-1).map(()=>"0 1").join(" ");return["<< /FunctionType 3","/Domain [0 1]",`/Functions [${t.join(" ")}]`,`/Bounds [${n.join(" ")}]`,`/Encode [${o}]`,">>"].join("\n")}(function(e){const t=e.map(e=>({offset:Math.min(1,Math.max(0,e.offset)),rgb:Wb(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($b).join(" ")}]`,"/Domain [0 1]",`/Function ${n} 0 R`,"/Extend [true true]",">>"].join("\n"))}};function zy(e,t){return["<< /FunctionType 2","/Domain [0 1]",`/C0 [${e.map($b).join(" ")}]`,`/C1 [${t.map($b).join(" ")}]`,"/N 1",">>"].join("\n")}var $y=new TextEncoder;function Hy(e){return"string"==typeof e?(t=e,(new TextEncoder).encode(t).byteLength):e.length;var t}function Wy(e){return Gb($y.encode(e))}function Uy(e){return e.replace(/[\\()]/g,e=>`\\${e}`)}function jy(e){return`<FEFF${_b(Array.from(e).map(e=>e.codePointAt(0)??63))}>`}function Vy(e){const t=[];if(e.title&&t.push(`/Title ${jy(e.title)}`),e.author&&t.push(`/Author ${jy(e.author)}`),e.subject&&t.push(`/Subject ${jy(e.subject)}`),e.keywords&&t.push(`/Keywords ${jy(e.keywords)}`),e.producer&&t.push(`/Producer (${Uy(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 Ky(e){return e.children.reduce((e,t)=>e+1+Ky(t),0)}function _y(e,t,n,o,r=[],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),g=o.buildShadingObjects(l),f=/* @__PURE__ */new Map;for(const B of e)for(const[e,t]of B.graphicsStateOpacities??[])f.has(e)||f.set(e,l(`<< /Type /ExtGState /ca ${$b(t)} /CA ${$b(t)} >>`));const m=[];for(const B of e){const e=l(Wy(`${B.commands.join("\n")}\n`)),t=Array.from(B.imageResourceNames).map(e=>{const t=p.get(e);return t?`/${e} ${t} 0 R`:""}).filter(Boolean).join(" "),n=t?` /XObject << ${t} >>`:"",o=Array.from(B.shadingResourceNames).map(e=>{const t=g.get(e);return t?`/${e} ${t} 0 R`:""}).filter(Boolean).join(" "),r=o?` /Shading << ${o} >>`:"",a=Array.from(B.graphicsStateOpacities?.keys()??[]).map(e=>`/${e} ${f.get(e)} 0 R`).join(" "),i=a?` /ExtGState << ${a} >>`:"",s=B.annotations.map(e=>{const t=e.x,n=e.x+e.width,o=B.height-e.y-e.height,r=B.height-e.y,a=void 0!==e.destName?`/A << /Type /Action /S /GoTo /D (${Uy(e.destName)}) >>`:`/A << /Type /Action /S /URI /URI (${Uy(e.uri??"")}) >>`;return l(["<< /Type /Annot /Subtype /Link",`/Rect [${$b(t)} ${$b(o)} ${$b(n)} ${$b(r)}]`,"/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 ${$b(B.width)} ${$b(B.height)}]`,`/Resources << /Font << ${u} >>${n}${r}${i} >>`,`/Contents ${e} 0 R${c}`,">>"].join("\n"));m.push(h)}let h;const b=r.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],o=e[t.pageIndex].height-t.y;return`(${Uy(t.name)}) [${n} 0 R /XYZ ${$b(t.x)} ${$b(o)} null]`}).join(" ")}] >>`)} 0 R >>`));const v=new Set(b.map(e=>e.name)),x=function(e){const t=[],n=[];for(const o of e){const e={title:o.title,destName:o.destName,children:[]};for(;n.length>0&&n[n.length-1].level>=o.level;)n.pop();0===n.length?t.push(e):n[n.length-1].node.children.push(e),n.push({node:e,level:o.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((o,r)=>{const a=o,i=r>0?e[r-1]:void 0,l=r<e.length-1?e[r+1]:void 0,c=["<< /Title "+jy(o.title),`/Parent ${t} 0 R`,i?`/Prev ${i.id} 0 R`:"",l?`/Next ${l.id} 0 R`:"",`/Dest (${Uy(o.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 ${Ky(o)}`)),c.push(">>"),s[a.id-1].body=c.filter(Boolean).join("\n"),n(o.children,a.id)})};n(x,y);const o=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 ${o}`,">>"].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=Vy(i);e&&(w=l(e))}const S=[Nb];let I=Hy(Nb);const C=[0],T=e=>{S.push(e),I+=Hy(e)};for(const B of s)C[B.id]=I,T(`${B.id} 0 obj\n`),T(B.body),T("\nendobj\n");const k=I;let P=`xref\n0 ${s.length+1}\n`;P+="0000000000 65535 f \n";for(const B of s)P+=`${String(C[B.id]??0).padStart(10,"0")} 00000 n \n`;T(P);const R=void 0!==w?` /Info ${w} 0 R`:"";return T(["trailer",`<< /Size ${s.length+1} /Root ${c} 0 R${R} >>`,"startxref",String(k),"%%EOF",""].join("\n")),function(e){const t=e.reduce((e,t)=>e+Hy(t),0),n=new Uint8Array(t);let o=0;for(const r of e){const e="string"==typeof r?$y.encode(r):r;n.set(e,o),o+=e.length}return n}(S)}var Xy=class{pages=[];streams=[];fonts;images=new Ly;shadings=new Ny;namedDestinations=[];outlineItems=[];documentInfo;constructor(e=zb){this.fonts=new Ey(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 Qb(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,o){this.streams[e]?.rotateAbout(t,n,o)}clipRect(e,t,n,o,r){this.streams[e]?.clipRect(t,n,o,r)}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}),_y(this.pages,this.fonts,this.images,this.shadings,this.namedDestinations,this.outlineItems,this.documentInfo)}};function Gy(e,t,n,o,r){if(0!==o.size||0!==r.size)return(a,i)=>{const s=ft(i),l=ft(n);for(const n of o.get(a)??[])e.addNamedDestination({name:n,pageIndex:t,x:l,y:s});const c=r.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 qy(e){e=ga(e);const t=new Lb,n=Ro(e);await t.loadBundledUnicodeFaces({families:n}),await t.loadRemoteWebFontFaces({families:n});const o=new Xy(t.getPdfFontResources());o.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 r=$e(e),a=function(e){return Ho(e)}(e),i=function(e){const t=/* @__PURE__ */new Map,n=e.bookmarks;if(!n)return t;for(const o of n.order){const e=n.items[o],r=e?.start?.paragraphId;if(!e||!r)continue;const a=t.get(r)??[];a.push(e.name),t.set(r,a)}return t}(e),s=new Map(ye(e).map(e=>[e.id,{level:e.level,title:e.text}]));for(const l of r.pages){const n=Math.max(1,ft(l.pageSettings.width)),r=Math.max(1,ft(l.pageSettings.height)),c=o.addPage({width:n,height:r});await Ab(o,c,n,r,e.design,e.sections?.[l.sectionIndex??0]?.pageBorder,e);const d=l.pageSettings.margins.left+l.pageSettings.margins.gutter,u=wr(l.pageSettings);await Ob(o,c,l.headerBlocks,e,d,l.headerTop??Ca(l.pageSettings),u,t,a,l.pageSettings);const p=l.bodyTop??Jo(l.pageSettings);if(l.blocks.some(e=>void 0!==e.columnIndex)){const n=qo(l.pageSettings),r=/* @__PURE__ */new Map;for(const e of l.blocks){const t=e.columnIndex??0,n=r.get(t)??[];n.push(e),r.set(t,n)}for(const[d,u]of r){const r=n[d]??n[0];await Ob(o,c,u,e,r.left,p,r.width,t,a,l.pageSettings,Gy(o,c,r.left,i,s))}}else await Ob(o,c,l.blocks,e,d,p,u,t,a,l.pageSettings,Gy(o,c,d,i,s));await Ob(o,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&&o.drawLine(c,{x1:ft(d),y1:ft(l.footnoteSeparatorTop+.5),x2:ft(d+Math.min(180,.35*u)),y2:ft(l.footnoteSeparatorTop+.5),stroke:"#64748b",lineWidth:ft(1)}),await Zy(o,c,l.footnoteBlocks,l.footnoteReferenceIds??[],e,d,l.footnoteTop,u,t,a))}if(0===o.getPageCount()){const t=o.addPage({width:612,height:792});await Ab(o,t,612,792,e.design,void 0,e)}return o.toArrayBuffer()}async function Yy(e){const t=await qy(e);return new Blob([t],{type:"application/pdf"})}async function Zy(e,t,n,o,r,a,i,s,l,c){let d=i;const u=/* @__PURE__ */new Set,p=new Map(o.map(e=>[e,ma(r,e)?.run.text??""]));for(const g of n){const n=o.find(e=>g.blockId.startsWith(`${e}:`));if(n&&!u.has(n)){const o=p.get(n);if(o){const n="paragraph"===g.sourceBlock.type?g.sourceBlock:void 0,i=Oa(void 0,n?.style?.styleId,r.styles),s=l.resolveFontFace({fontFamily:i.fontFamily,bold:i.bold,italic:i.italic});e.drawText(t,{x:ft(a),y:ft(d+12),text:o,fontSize:Fn(i),color:i.color??"#000000",bold:i.bold,italic:i.italic,fontResourceName:s.writerResourceName})}u.add(n)}await Ob(e,t,[g],r,a+24,d,Math.max(24,s-24),l,c),d+=Math.max(0,g.estimatedHeight)+2}}function Jy(e,t){const n=URL.createObjectURL(e),o=document.createElement("a");o.href=n,o.download=t,o.click(),URL.revokeObjectURL(n)}function Qy(e){return new Promise(t=>{const n=URL.createObjectURL(e),o=document.createElement("iframe");o.setAttribute("aria-hidden","true"),o.style.position="fixed",o.style.right="0",o.style.bottom="0",o.style.width="0",o.style.height="0",o.style.border="0";let r=!1;const a=()=>{r||(r=!0,o.remove(),URL.revokeObjectURL(n),t())},i=()=>{if(!r){if(!window.open(n,"_blank")){const e=document.createElement("a");e.href=n,e.download="oasis-editor.pdf",e.click()}a()}};o.addEventListener("load",()=>{try{const e=o.contentWindow;if(!e)return void i();e.addEventListener("afterprint",a),globalThis.setTimeout(a,6e4),e.focus(),e.print()}catch{i()}}),o.src=n,document.body.appendChild(o)})}async function ev(e){return"function"==typeof e.arrayBuffer?e.arrayBuffer():new Promise((t,n)=>{const o=new FileReader;o.onerror=()=>n(o.error??/* @__PURE__ */new Error("Failed to read file.")),o.onload=()=>{const e=o.result;e instanceof ArrayBuffer?t(e):n(/* @__PURE__ */new Error("Failed to read file as ArrayBuffer."))},o.readAsArrayBuffer(e)})}function tv(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 nv(e){return function(e){const t=ya(e),n=/* @__PURE__ */new Map,o=/* @__PURE__ */new Map;let r=0,a=0;for(const i of t){const t=Wa(i.style,e.styles);o.set(t.align,(o.get(t.align)??0)+1);for(const o of i.runs){const t=Oa(o.styles,i.style?.styleId,e.styles),s=t.fontFamily??"<null>";n.set(s,(n.get(s)??0)+1),null!==t.characterSpacing&&(r+=1),null!==t.characterScale&&(a+=1)}}return{paragraphCount:t.length,alignCounts:Array.from(o.entries()),fontCounts:Array.from(n.entries()),characterSpacingRuns:r,characterScaleRuns:a,firstParagraphs:t.slice(0,30).map((t,n)=>{const o=Wa(t.style,e.styles),r=t.runs[0],a=Oa(r?.styles,t.style?.styleId,e.styles);return{index:n,textLength:oi(t).length,runCount:t.runs.length,rawParagraphStyle:t.style,align:o.align,indentFirstLine:o.indentFirstLine,lineGridPitch:o.lineGridPitch,lineGridType:o.lineGridType,fontFamily:a.fontFamily,fontSize:a.fontSize,characterSpacing:a.characterSpacing,characterScale:a.characterScale,firstRunStyle:r?.styles}})}}(e)}function ov(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 rv(e){return e?e.behindDoc?"behind":e.wrap&&"none"!==e.wrap?e.wrap:"front":"inline"}function av(e,t){return{...e,positionV:{...e.positionV??{},relativeFrom:t?"page":"paragraph"}}}function iv(e){return"page"===e?.positionV?.relativeFrom}function sv(e){return Ii(e,e=>"image"===e.kind)}function lv(e,t,n){return bv(e,e=>({...e,width:Math.max(24,Math.round(t)),height:Math.max(24,Math.round(n))}))}function cv(e){return!e||!Number.isFinite(e)||e<0?0:Math.min(e,.99)}function dv(e,t){return bv(e,e=>{const n={...e},o=function(e){if(!e)return;const t=cv(e.left),n=cv(e.top),o=cv(e.right),r=cv(e.bottom),a=Math.min(o,Math.max(0,.99-t)),i=Math.min(r,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 o?n.crop=o: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 uv(e,t){const n=sv(e),o=n&&fr(n.run);return o?dv(e,function(e,t){if("reset"===t)return{crop:null};const n=t,{width:o,height:r}=e;if(!Number.isFinite(n)||n<=0||o<=0||r<=0)return{crop:e.crop??null};const a=e.crop??{},i=cv(a.left),s=cv(a.top),l=cv(a.right),c=cv(a.bottom),d=o/r;if(d>n){const e=r*n,t=(o-e)/o*Math.max(0,1-i-l);return{crop:{...a,left:i+t/2,right:l+t/2},width:e}}if(d<n){const e=o/n,t=(r-e)/r*Math.max(0,1-s-c);return{crop:{...a,top:s+t/2,bottom:c+t/2},height:e}}return{crop:e.crop??null}}(o,t)):e}function pv(e){const t=e.intrinsicWidth??e.width,n=e.intrinsicHeight??e.height,o=t>0&&n>0?t/n:e.width/Math.max(1,e.height),r=e.width/Math.max(1,e.height);if(!Number.isFinite(o)||!Number.isFinite(r))return{};if(o>r){const e=r/o,t=Math.max(0,(1-e)/2);return{left:t,right:t}}if(o<r){const e=o/r,t=Math.max(0,(1-e)/2);return{top:t,bottom:t}}return{}}function gv(e){return bv(e,e=>{const t={...e};return delete t.crop,delete t.cropFit,delete t.cropShape,t})}function fv(e){if(!Number.isFinite(e))return;const t=(Math.round(e)%360+360)%360;return 0===t?void 0:t}function mv(e,t,n=90){const o=sv(e);if(!o||!fr(o.run))return e;const r="right"===t?-n:n,a=fv(function(e){const t=sv(e);return(t&&fr(t.run))?.rotation??0}(e)+r);return bv(e,e=>({...e,rotation:a}))}function hv(e,t){const n=function(e){const t=sv(e),n=t&&fr(t.run);return n?{flipH:Boolean(n.flipH),flipV:Boolean(n.flipV)}:null}(e);return n?bv(e,"horizontal"===t?e=>({...e,flipH:!n.flipH}):e=>({...e,flipV:!n.flipV})):e}function bv(e,t){const n=sv(e);if(!n||!fr(n.run))return e;const o=cr(e),{paragraphIndex:r,run:a}=n,i=o.map((e,n)=>n!==r?zo(e):{...zo(e),runs:e.runs.map(e=>e.id===a.id&&"image"===e.kind?{...e,image:t(e.image)}:Ea(e))});return qt(e,i,N(i,mr(e)))}function yv(e,t){return bv(e,e=>{const n=t(e.floating);if(n)return{...e,floating:n};const{floating:o,...r}=e;return r})}function vv(e,t){const n=sv(e);if(!n)return e;const o=cr(e),{paragraphIndex:r,offset:a,run:i}=n,s=er(o,t.paragraphId);if(s<0)return e;const l=o[s],d=Br(l,t),u=s===r&&d>a?d-1:d;if(s===r&&u===a)return e;const p=e=>c(e,[...on(e,0,a),...on(e,a+1,Xr(e))]),g=(e,t)=>xe(e,Math.max(0,Math.min(t,Xr(e))),[za("",qn(e,t),fr(i))]),f=o.map((e,t)=>t===r&&t===s?g(p(e),u):t===r?p(e):t===s?g(e,u):Ja([e])[0]),m=f[s],h=Math.max(0,Math.min(u+1,Xr(m)));return qt(e,f,Y(ci(m,h)))}function xv(e,t,n,o=0){const r=wr(ii(t));if(!n)return r;const a=X(t,n,o);return null!==a&&Number.isFinite(a)&&a>0?Math.min(r,a):r}function wv(e){return{insertImageFromFile:async(t,n)=>{e.logger.info(`image insert:start name="${t.name}" type=${t.type} size=${t.size}`);const o=await ev(t),r=`data:${t.type};base64,${function(e){return btoa(new Uint8Array(e).reduce((e,t)=>e+String.fromCharCode(t),""))}(o)}`,a=new Image;a.src=r,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=xv(e.surfaceRef(),l.document,c,l.activeSectionIndex??0),u=i>d?d/i:1,p=Math.max(24,Math.round(i*u)),g=Math.max(24,Math.round(s*u));e.logger.info(`image insert:decoded natural=${i}x${s} fitted=${p}x${g} maxWidth=${d}`),e.applyTransactionalState(e=>function(e,t){const n=sr(e.selection)?e:ee(e),{paragraph:o,index:r,offset:a}=oe(n),i=za("",qn(o,a),t),s=xe(o,a,[i]),l=cr(n).map((e,t)=>t===r?s:zo(e));return qt(n,l,Y(ci(s,a+1)))}(n?xi(e,{anchor:n,focus:n}):e,{src:r,width:p,height:g,intrinsicWidth:i,intrinsicHeight:s}),{mergeKey:Wp})}}}var Sv={"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 Iv(e){return function(e){const[t,n]=co(null),o=(e,t)=>{const[n,o]=Sv[e];return void 0!==t&&Number.isFinite(t)?Math.round(10*(n+(o-n)*Math.min(1,Math.max(0,t))))/10:o},r=(e,t)=>{n({phase:e,progress:o(e,t),subProgress:t})},a=()=>{globalThis.setTimeout(()=>{n(e=>"done"===e?.phase||"error"===e?.phase?null:e)},1200)},i=function(e){return{handleImportFile:async t=>{if(!t)return;const n=ot(t);if(!n)return e.setImportPhase("error"),e.logger.error("import:unsupported-format",{name:t.name,type:t.type}),void e.clearImportProgressSoon();const o=e.now();e.logger.info("import:start",{format:n.id,name:t.name,size:t.size}),e.setImportPhase("reading-file");const r="docx"===n.id?e.requestLocalFontAccess().catch(()=>!1):Promise.resolve(!1);try{const a=e.now(),i=await ev(t);e.logger.info("import:phase",{phase:"reading-file",durationMs:zn(e.now()-a,2)});let s=null,l=-1,c=0;const d=await n.import(i,(t,n)=>{const o=e.now(),r=void 0!==n&&Number.isFinite(n)?Math.floor(100*n):void 0,a=t!==s;if(!(a||void 0!==r&&(l<0||r-l>=1)||o-c>=40))return;s=t,l=r??l,c=o,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",nv(d));const u=e.now();e.setImportPhase("preparing-fonts"),await r,await e.prepareDocumentFonts(d),e.logger.info("import:phase",{phase:"preparing-fonts",durationMs:zn(e.now()-u,2)}),e.setImportPhase("applying-editor-state"),e.resetEditorChromeState(),e.applyState(jo(d));const p=e.now();e.setImportPhase("stabilizing-layout"),await e.stabilizeLayoutAfterImport(),e.logger.info("import:phase",{phase:"stabilizing-layout",durationMs:zn(e.now()-p,2)});const g=ei(d).reduce((e,t)=>e+(t.header?.length??0)+t.blocks.length+(t.footer?.length??0),0),f=Yr(d).length;e.setImportPhase("done"),e.logger.info("import:done",{format:n.id,blocks:g,paragraphs:f,durationMs:zn(e.now()-o,2)}),e.focusInput()}catch(a){e.setImportPhase("error"),e.logger.error("import:error",a)}finally{e.clearImportProgressSoon()}}}}({applyState:e.applyState,stabilizeLayoutAfterImport:e.stabilizeLayoutAfterImport,resetEditorChromeState:e.resetEditorChromeState,focusInput:e.focusInput,requestLocalFontAccess:e.requestLocalFontAccess,prepareDocumentFonts:e.prepareDocumentFonts,setImportPhase:r,clearImportProgressSoon:a,now:()=>performance.now(),logger:e.logger}),s=wv({state:e.state,applyTransactionalState:e.applyTransactionalState,surfaceRef:e.surfaceRef,logger:e.logger}),l=function(e){const t=e.download??Jy,n=e.print??Qy;let o=!1;return{handleExportDocx:async()=>{const n=await ou(e.document());return t(n,"oasis-editor.docx"),e.focusInput(),n},handleExportPdf:async()=>{const n=await Yy(e.document());return t(n,"oasis-editor.pdf"),e.focusInput(),n},handlePrint:async()=>{const t=await Yy(e.document());if(!o){o=!0;try{await n(t)}finally{o=!1}}return e.focusInput(),t},exportDocxBlob:()=>ou(e.document()),exportPdfBlob:()=>Yy(e.document())}}({document:()=>e.state().document,focusInput:e.focusInput}),c=async t=>{e.isReadOnly()||await i.handleImportFile(t)},d=async(e,t)=>{await s.insertImageFromFile(e,t)},u=async t=>{e.isReadOnly()||t&&(await d(t),e.focusInput())};return{importProgress:t,handleImportFile:c,handleExportDocx:async()=>l.handleExportDocx(),handleExportPdf:async()=>l.handleExportPdf(),handlePrint:async()=>l.handlePrint(),exportDocxBlob:l.exportDocxBlob,exportPdfBlob:l.exportPdfBlob,insertImageFromFile:d,handleInsertImage:u}}(e)}function Cv(e,t){return e.paragraph.runs.map(e=>e.text).join("")[t]??""}function Tv(e){return" "===e||"\t"===e||"\n"===e}function kv(e,t,n){if(n.isCollapsed)return null;const o=t.get(e);return void 0===o||o<n.startIndex||o>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 Pv(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=Pv(n.blocks,t);if(e)return e}}return null}function Rv(e,t){const n=mr(t),o=[],r=e.surfaceRect,a=new Map(cr(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,o=e.inlineImages.find(t)??e.floatingImages.find(t);if(o&&(i={paragraphId:o.paragraphId,startOffset:o.startOffset,endOffset:o.endOffset,left:o.left-r.left,top:o.top-r.top,width:o.width,height:o.height,rotation:o.rotation??0}),!i){const t=e=>e.paragraphId===n.start.paragraphId&&e.startOffset===n.startParagraphOffset&&e.endOffset===n.endParagraphOffset,o=e.floatingTextBoxes.find(t),a=o?void 0:e.inlineTextBoxes.find(t),i=o??a;i&&(s={paragraphId:i.paragraphId,startOffset:i.startOffset,endOffset:i.endOffset,left:i.left-r.left,top:i.top-r.top,width:i.width,height:i.height,rotation:i.rotation??0,floating:Boolean(o)})}}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 Pa(e))for(const e of[n.blocks,n.header,n.firstPageHeader,n.evenPageHeader,n.footer,n.firstPageFooter,n.evenPageFooter]){const n=Pv(e,t);if(n)return n}for(const n of Object.values(e.footnotes?.items??{})){const e=Pv(n.blocks,t);if(e)return e}return null}(t.document,l.tableId);if(n){const t=Or(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),o.push({left:a.tableCell.left-r.left,top:a.tableCell.top-r.top,width:a.tableCell.width,height:a.tableCell.height}))}}}}}}if(!(d||n.isCollapsed||i||s))for(const w of e.paragraphs){const e=kv(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&&Tv(Cv(w,e));)e+=1;for(;a>e&&Tv(Cv(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;o.push({left:s.left-r.left+1,top:d-r.top,width:Math.max(1,l.left-s.left+1-1),height:u})}}const u=t.selection.focus.paragraphId,p=e.paragraphsById.get(u)??[],g=p[0]?.paragraph,f=function(e,t){if(0===e.length)return null;const n=e.find(e=>t>=e.startOffset&&t<=e.endOffset)??e[e.length-1],o=n.lines.flatMap(e=>e.slots);if(0===o.length)return{left:n.left,top:n.top,height:Math.max(18,n.height)};let r=o[0],a=Math.abs(t-r.offset);for(const s of o){const e=Math.abs(t-s.offset);e<a&&(r=s,a=e)}const i=n.lines[0];return 0===n.startOffset&&void 0!==i&&t>=i.startOffset&&t<=i.endOffset&&r.top>n.top?{left:r.left,top:n.top,height:r.top+r.height-n.top}:{left:r.left,top:r.top,height:r.height}}(p,g?Br(g,t.selection.focus):t.selection.focus.offset),m=(f?.left??r.left)-r.left,h=(f?.top??r.top)-r.top,b=Math.max(18,f?.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,o=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(const r of e.paragraphs){const e=r.tableCell;e&&e.tableId===x&&(t=Math.min(t,e.left),n=Math.min(n,e.top),o=Math.max(o,e.left+e.width),a=Math.max(a,e.top+e.height))}Number.isFinite(t)&&o>t&&a>n&&(v={tableId:x,left:t-r.left,top:n-r.top,width:o-t,height:a-n})}return{selectionBoxes:o,inputBox:{left:m,top:h,height:b},caretBox:y,selectedImageBox:i,selectedTextBoxBox:s,selectedTableBox:v}}function Bv(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)Bv(n.blocks,t);else t.push(n.id)}function Mv(e){const t=[],n=e=>{if(e)for(const o of e)if("paragraph"!==o.type)for(const e of o.rows)for(const t of e.cells)n(t.blocks);else for(const e of o.runs)t.push(e.text)};return n(e),t.join("").trim()}function Ov(e){return e.cells.flatMap(e=>e.blocks)}function Av(e){return e.rows.flatMap(Ov)}function Fv(e){return{id:e.id,type:e.type,author:e.author,date:e.date}}function Dv(e){return{id:e.id,type:"property",author:e.author,date:e.date}}function Ev(e){const t=[];return e.style?.revision&&t.push(Fv(e.style.revision)),e.style?.propertyRevision&&t.push(Dv(e.style.propertyRevision)),t}function Lv(e){const t=[];return e.style?.revision&&t.push(Fv(e.style.revision)),e.style?.propertyRevision&&t.push(Dv(e.style.propertyRevision)),e.propertyExceptionsRevision&&t.push(Dv(e.propertyExceptionsRevision)),t}function Nv(e){const t=[];return e.style?.revision&&t.push(Dv(e.style.revision)),e.gridRevision&&t.push({id:e.gridRevision.id,type:"grid",author:e.gridRevision.author,date:e.gridRevision.date}),t}function zv(e){const t=[],n=/* @__PURE__ */new Set,o=(e,o,r,a,i,s)=>{if(n.has(e.id))return;n.add(e.id);const l=[];Bv(s,l),t.push({...e,scope:o,tableId:r,rowIndex:a,cellIndex:i,paragraphIds:l,snippet:Mv(s)})},r=e=>{if(e)for(const t of e)if("paragraph"!==t.type){for(const e of Nv(t))o(e,"table",t.id,void 0,void 0,Av(t));t.rows.forEach((e,n)=>{for(const r of Lv(e))o(r,"row",t.id,n,void 0,Ov(e));e.cells.forEach((e,a)=>{for(const r of Ev(e))o(r,"cell",t.id,n,a,e.blocks);r(e.blocks)})})}};for(const a of Pa(e.document))for(const e of[a.blocks,a.header,a.firstPageHeader,a.evenPageHeader,a.footer,a.firstPageFooter,a.evenPageFooter])r(e);for(const a of Object.values(e.document.footnotes?.items??{}))r(a.blocks);for(const a of Object.values(e.document.endnotes?.items??{}))r(a.blocks);return t}function $v(e){const t=[],n=/* @__PURE__ */new Set;return Pa(e.document).forEach((e,o)=>{const r=e.propertyRevision;if(!r||n.has(r.id))return;n.add(r.id);const a=[];Bv(e.blocks,a);const i=Mv(e.blocks);t.push({id:r.id,type:"property",author:r.author,date:r.date,sectionId:e.id,sectionIndex:o,paragraphIds:a,snippet:i.length>96?`${i.slice(0,93)}…`:i})}),t}var Hv={insertions:"showMarkupInsertions",deletions:"showMarkupDeletions",comments:"showMarkupComments",formatting:"showMarkupFormatting"};function Wv(e,t){return e[Hv[t]]??!0}function Uv(e,t){return"boolean"==typeof t.allAuthors?_v(e,t.allAuthors?void 0:[]):"string"==typeof t.author?function(e,t,n){const o=e.markupAuthors??[...n],r=Xv(o.includes(t)?o.filter(e=>e!==t):[...o,t]),a=Xv(n);return _v(e,r.length===a.length&&r.every((e,t)=>e===a[t])?void 0:r)}(e,t.author,qv(e)):t.section?function(e,t){const n=Hv[t],o=!(e[n]??!0);return e[n]===o?e:{...e,[n]:o}}(e,t.section):e}function jv(e,t){return e.markupAuthors?.includes(t)??!0}function Vv(e,t,n){return!("insert"===t&&!Wv(e,"insertions"))&&(!("delete"===t&&!Wv(e,"deletions"))&&(!("property"===t&&!Wv(e,"formatting"))&&jv(e,n)))}function Kv(e){const t=/* @__PURE__ */new Map;for(const n of zv(e))if(Vv(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 $v(e))Vv(e,n.type,n.author)&&t.push(...n.paragraphIds);return t}(e))t.has(n)||t.set(n,null);for(const n of ya(e.document)){const o=[];let r=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=Vv(e,"property",s.author)):l=Vv(e,a.type,a.author),l&&(i?o.push({start:Math.max(0,r-1),end:r+1}):n>0&&o.push({start:r,end:r+n})),i||(r+=n)}if(0===o.length)continue;const a=t.get(n.id);void 0===a?t.set(n.id,o):null!==a&&t.set(n.id,[...a,...o])}return t}function _v(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 Xv(e){return[...new Set(e)].sort()}function Gv(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 qv(e){const t=/* @__PURE__ */new Set,n=e=>{e&&t.add(e)},o=e=>{if(e)for(const r of e)if("paragraph"!==r.type){n(r.style?.revision?.author),n(r.gridRevision?.author);for(const e of r.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),o(t.blocks)}}else Gv(r,t)},r=ya(e.document);for(const l of r)Gv(l,t);for(const l of Pa(e.document)){for(const e of[l.blocks,l.header,l.firstPageHeader,l.evenPageHeader,l.footer,l.firstPageFooter,l.evenPageFooter])o(e);n(l.propertyRevision?.author)}const a=e.document.footnotes?.items??{};for(const l of Object.values(a))o(l.blocks);const i=e.document.endnotes?.items??{};for(const l of Object.values(i))o(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 Yv(e,t){const n=[];let o=0;for(const r of e.runs){const e=o,a=o+r.text.length;o=a;const i=r.revision,s=r.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&&Vv(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 Zv(e,t){const n=e.surfaceRect,o=[];for(const r of e.paragraphs){const e=Yv(r.paragraph,t);if(0!==e.length)for(const t of r.lines)for(const r of e){const e=Math.max(r.start,t.startOffset),a=Math.min(r.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&&o.push({revisionId:r.revisionId,type:r.type,left:i.left-n.left,top:t.top-n.top,width:Math.max(1,s.left-i.left),height:t.height})}}return o.push(...function(e,t){const{surfaceRect:n}=e,o=[],r=/* @__PURE__ */new Set;for(const i of e.paragraphs){const e=i.tableCell;if(!e)continue;const t=`${e.tableId}:${e.rowIndex}:${e.cellIndex}`;r.has(t)||(r.add(t),o.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 zv(t)){if(!Vv(t,i.type,i.author))continue;const e=o.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 r=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:r-n.left,top:s-n.top,width:l-r,height:c-s})}return a}(e,t)),o.push(...function(e,t){const{surfaceRect:n}=e,o=[];for(const r of $v(t)){if(!Vv(t,r.type,r.author))continue;const a=new Set(r.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));o.push({revisionId:r.id,type:r.type,variant:"section",left:t-n.left,top:a-n.top,width:i-t,height:s-a})}}return o}(e,t)),o}function Jv(e,t){const{surfaceRect:n}=e,o=e.paragraphs,r=/* @__PURE__ */new Map;for(const c of o){const e=c.left+c.width,t=r.get(c.pageIndex);(void 0===t||e>t)&&r.set(c.pageIndex,e)}const a=/* @__PURE__ */new Map;for(const c of e.pages??[]){const e=c.left+c.width,t=r.get(c.index)??e-Math.min(96,c.width),o=Math.max(0,e-t),i=Math.min(168,Math.max(84,o-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,o)=>{const r=t.get(e.id);if(r)return r.paragraphIds.push(...n),void(o&&r.snippetParts.push(o));t.set(e.id,{...e,paragraphIds:[...n],snippetParts:o?[o]:[]})};for(const o of ya(e.document))for(const e of o.runs){const t=e.revision,r=e.styles?.propertyRevision,a=!t||"insert"!==t.type&&"delete"!==t.type?r?{id:r.id,type:"property",author:r.author,date:r.date,scope:"run"}:void 0:{id:t.id,type:t.type,author:t.author,date:t.date,scope:"run"};a&&n(a,[o.id],e.text)}for(const o of zv(e))n({id:o.id,type:o.type,author:o.author,date:o.date,scope:o.scope},o.paragraphIds,o.snippet);for(const o of $v(e))n({id:o.id,type:o.type,author:o.author,date:o.date,scope:"section"},o.paragraphIds,o.snippet);return[...t.values()].map(e=>{return{id:e.id,type:e.type,author:e.author,date:e.date,scope:e.scope,snippet:(t=e.snippetParts.join("").trim(),t.length>96?`${t.slice(0,93)}…`:t),paragraphIds:[...new Set(e.paragraphIds)]};var t})}(t)){if(!Vv(t,c.type,c.author))continue;const e=new Set(c.paragraphIds);let r;for(const t of o)e.has(t.paragraphId)&&(!r||t.top<r.top)&&(r=t);if(!r||!a.has(r.pageIndex))continue;const s=r.lines[0];i.push({descriptor:c,pageIndex:r.pageIndex,top:(s?s.top:r.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),o=c.descriptor;l.push({revisionId:o.id,type:o.type,variant:"balloon",left:n.left,top:t,width:n.width,height:58,author:o.author,date:o.date,snippet:o.snippet})}return l}var Qv={composeMeasuredParagraphLines:e=>Gn.composeMeasuredParagraphLines(e),resolveRenderedLineHeightPx:(e,t)=>Gn.resolveRenderedLineHeightPx(e,t)};function ex(e,t){return(e?.length??0)===(t?.length??0)&&(t??[]).every((t,n)=>e?.[n]===t)}function tx(e,t){return(e?.length??0)===(t?.length??0)&&(t??[]).every((t,n)=>{const o=e?.[n];return o?.blockIndex===t.blockIndex&&o?.offset===t.offset})}function nx(){let e=/* @__PURE__ */new Map,t=/* @__PURE__ */new Map;return function(n){const o=/* @__PURE__ */new Map,r=t=>t?.map(t=>{const n=e.get(t.blockId),r=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&&ex(e.tableSegment?.startRowCellBlockStarts,t.tableSegment?.startRowCellBlockStarts)&&ex(e.tableSegment?.endRowCellBlockEnds,t.tableSegment?.endRowCellBlockEnds)&&tx(e.tableSegment?.startRowCellBlockPositions,t.tableSegment?.startRowCellBlockPositions)&&tx(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 o=e.lines[n];return void 0!==o&&o.startOffset===t.startOffset&&o.endOffset===t.endOffset&&o.top===t.top&&o.height===t.height})}(e.layout,t.layout))}(n,t)?n:t;return o.set(r.blockId,r),r}),a=n.pages.map(e=>{const n={...e,blocks:r(e.blocks)??[],headerBlocks:r(e.headerBlocks),footerBlocks:r(e.footerBlocks),footnoteBlocks:r(e.footnoteBlocks)},o=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 o=(e,t)=>(e?.length??0)===(t?.length??0)&&(t??[]).every((t,n)=>e?.[n]===t);return o(e.blocks,t.blocks)&&o(e.headerBlocks,t.headerBlocks)&&o(e.footerBlocks,t.footerBlocks)&&o(e.footnoteBlocks,t.footnoteBlocks)&&(r=e.footnoteReferenceIds,a=t.footnoteReferenceIds,(r?.length??0)===(a?.length??0)&&(a??[]).every((e,t)=>r?.[t]===e));var r,a}(o,n)?o:n});return e=o,t=new Map(a.map(e=>[e.id,e])),{pages:a}}}function ox(e,t){if(0===t.length)return e;let n;for(const o of t)Object.prototype.hasOwnProperty.call(e,o)&&(n??={...e},delete n[o]);return n??e}function rx(e){return function(e){const[t,n]=co({}),[o,r]=co({}),[a,i]=co({left:0,top:0,height:28}),[s,l]=co([]),[c,d]=co([]),[p,g]=co([]),[f,m]=co([]),[h,b]=co(null),[y,v]=co(null),[x,w]=co(null),[S,I]=co({left:0,top:0,height:28,visible:!1}),[C,T]=co(null),k=nx(),P=wt(()=>{u();const t=void 0===(n=e.state.reviewDisplayMode)||"all"===n?null:"original"===n?"original":"final";var n;return null===t?e.state.document:Mt(e.state.document,t).document}),R=wt(()=>(u(),k($e(P(),void 0,t(),o(),{measurer:Qv})))),B=F();let M=0;const O=(t="selection")=>{const n=e.surfaceRef();if(!n)return l([]),d([]),g([]),m([]),b(null),v(null),w(null),void I(e=>({...e,visible:!1}));const o=B.getCanvasLayoutSnapshot({surface:n,state:e.state,documentLayout:R(),zoomFactor:e.zoomFactor?.()});if(!o)return l([]),d([]),g([]),m([]),b(null),v(null),w(null),void I(e=>({...e,visible:!1}));const r=e.state.reviewDisplayMode??"all";if("all"!==r)return l([]),b(null),v(null),w(null),I({left:0,top:0,height:28,visible:!1}),i({left:0,top:0,height:28}),d([]),g([]),void m("simple"===r&&!1!==e.state.showRevisionMarkup?function(e,t){const n=Kv(t);if(0===n.size)return[];const o=e.surfaceRect,r=/* @__PURE__ */new Map;for(const s of e.paragraphs){const e=r.get(s.pageIndex);(void 0===e||s.left<e)&&r.set(s.pageIndex,s.left)}const a=/* @__PURE__ */new Map;for(const s of e.pages??[]){const e=r.get(s.index),t=void 0===e?0:e-s.left;a.set(s.index,s.left+(t>0?.5*t:12)-o.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-o.left-12,r=s.lines;if(0===r.length){i.push({paragraphId:s.paragraphId,left:t,top:s.top-o.top,height:Math.max(1,s.height)});continue}const l=null===e?r:r.filter(t=>e.some(e=>e.start<t.endOffset&&e.end>t.startOffset)),c=l.length>0?l:[r[0]];for(const n of c)i.push({paragraphId:s.paragraphId,left:t,top:n.top-o.top,height:Math.max(1,n.height)})}return i}(o,e.state):[]);const a=Rv(o,e.state);m([]),l(a.selectionBoxes),g(!1===e.state.showRevisionMarkup?[]:[...Zv(o,e.state),...Jv(o,e.state)]),d(function(e,t){const n=t.document.comments;if(!n||0===n.order.length||!Wv(t,"comments"))return[];const o=e.surfaceRect,r=new Map(cr(t).map((e,t)=>[e.id,t])),a=[];for(const i of n.order){const s=n.items[i];if(!s?.start||!s?.end||!jv(t,s.author))continue;const l=r.get(s.start.paragraphId),c=r.get(s.end.paragraphId);if(void 0!==l&&void 0!==c)for(const t of e.paragraphs){const e=r.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 r of t.lines){const e=Math.max(u,r.startOffset),t=Math.min(p,r.endOffset);if(e>=t)continue;const n=r.slots.find(t=>t.offset===e),s=r.slots.find(e=>e.offset===t)??r.slots[r.slots.length-1];n&&s&&a.push({commentId:i,left:n.left-o.left,top:r.top-o.top,width:Math.max(1,s.left-n.left),height:r.height})}}}return a}(o,e.state)),b(a.selectedImageBox),v(a.selectedTextBoxBox),w(a.selectedTableBox),i(a.inputBox),I(a.caretBox)},A=(e="selection")=>{const t=++M;queueMicrotask(()=>{t===M&&O(e)})},D=(e="content-change")=>(A(e),!1),E=(e,t={})=>(t.paragraphIds&&t.paragraphIds.length>0&&(r(e=>ox(e,t.paragraphIds??[])),No()),A(e),t.resolveWhenDone?Promise.resolve():null),L=t=>{if(!e.isImporting?.()){if(t.dirtyAll||t.structureChanged)n({}),r({}),No();else if((t.dirtyParagraphIds?.length??0)>0){const e=t.dirtyParagraphIds??[];r(t=>ox(t,e)),No()}A("content-change")}},N=async()=>{n({}),r({}),No(),await new Promise(e=>{var t;t=()=>e(),"undefined"!=typeof window&&"function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(()=>t()):globalThis.setTimeout(t,16)}),A("import")};Zn(()=>{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,A("selection")}),Zn(()=>{e.state.document,e.state.activeSectionIndex,e.state.activeZone,e.isImporting?.()||A("content-change")}),Zn(()=>{e.state.showRevisionMarkup,e.state.showMarkupInsertions,e.state.showMarkupDeletions,e.state.showMarkupComments,e.state.showMarkupFormatting,e.state.markupAuthors,A("content-change")}),Zn(()=>{e.state.reviewDisplayMode,A("content-change")}),Zn(()=>{const t=e.viewportRef();if(!t)return;const n=()=>{A("scroll")},o=()=>{A("resize")};t.addEventListener("scroll",n,{passive:!0}),window.addEventListener("resize",o),yn(()=>{t.removeEventListener("scroll",n),window.removeEventListener("resize",o)})});const z=()=>T(null),$=()=>{M+=1,B.clear()};return{measuredBlockHeights:t,measuredParagraphLayouts:o,documentLayout:R,canvasSnapshotProvider:B,inputBox:a,selectionBoxes:s,commentHighlights:c,revisionMarkupBoxes:p,changeBarBoxes:f,selectedImageBox:h,selectedTextBoxBox:y,selectedTableBox:x,caretBox:S,preferredColumnX:C,setPreferredColumnX:T,clearPreferredColumn:z,requestInputBoxSync:A,scheduleDeferredLayoutMeasurement:E,stabilizeLayoutAfterImport:N,syncMeasuredLayoutMetrics:D,syncInputBox:O,setMeasuredBlockHeights:n,setMeasuredParagraphLayouts:r,applyInvalidation:L,onCleanupHook:$}}(e)}function ax(e){return Array.isArray(e)?e.map(ax):e&&"object"==typeof e?Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,ax(t)])):e}function ix(e){const{builtinStyle:t,customStyle:n,...o}=e;return JSON.stringify(ax(o))}var sx=new Map(Object.values(Fr).flatMap(e=>{const t=r(e);return t?[[e.id,{key:t,signature:ix(e)}]]:[]}));function lx(e){if(!0===e.customStyle||void 0!==e.builtinStyle)return;const t=sx.get(e.id);return t?.signature===ix(e)?t.key:void 0}function cx(e,t,n){const[o,r]=co("Initial"),[a,i]=co(!1),s=()=>n.enabled??!1,l=n.persistence,c=_e(async e=>{if(s()&&a()){r("Saving...");try{const t=JSON.parse(JSON.stringify(Nt(e)));await l.saveDocument(t),r("Saved")}catch(t){n.logger?.error("persistence:autosave failed",t),r("Error")}}},1e3);return Zn(En(()=>e.document,e=>{s()&&a()&&c(e)},{defer:!0})),Xt(async()=>{if(!s())return i(!0),void r("Saved");try{const e=await l.loadDocument();e&&t(function(e){if(e.sourcePackage||!e.styles)return e;let t;for(const[n,o]of Object.entries(e.styles)){const r=lx(o);r&&(t??={...e.styles},t[n]={...o,builtinStyle:r})}return t?{...e,styles:t}:e}(e))}catch(e){n.logger?.error("persistence:load failed",e)}finally{i(!0),r("Saved")}}),{status:o}}function dx(e,t){const n=Math.max(0,249),o=Math.max(0,e.length-n);return[...e.slice(o),t]}function ux(e){return function(e){const t=(e,t)=>{const n=ei(e.document),o=Math.max(0,Math.min(nr(e),n.length-1)),r=pr(e),a=n[o];if(!a)return e;const i=[...n],s={...a},l=Ka("");if("header"===r){const e=[...a.header??[]];t<0?e.unshift(l):e.push(l),s.header=e}else if("footer"===r){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[o]=s,{...e,document:{...e.document,sections:i}}},n=()=>{const t=(n=e.getHistoryState(),o=e.stateSnapshot(),0===n.undoStack.length?null:{history:{undoStack:n.undoStack.slice(0,-1),redoStack:dx(n.redoStack,o),lastTransactionMeta:null},nextState:n.undoStack[n.undoStack.length-1]});var n,o;t&&(e.updateHistoryState(()=>t.history),e.clearPreferredColumn(),e.applyHistoryState(t.nextState),e.focusInput())},o=()=>{const t=(n=e.getHistoryState(),o=e.stateSnapshot(),0===n.redoStack.length?null:{history:{undoStack:dx(n.undoStack,o),redoStack:n.redoStack.slice(0,-1),lastTransactionMeta:null},nextState:n.redoStack[n.redoStack.length-1]});var n,o;t&&(e.updateHistoryState(()=>t.history),e.clearPreferredColumn(),e.applyHistoryState(t.nextState),e.focusInput())},r=n=>{const o=e.imageOps().getSelectedImageInfo(e.state());if(!o)return!1;const r=cr(e.state()),a=r.findIndex(e=>e.id===o.paragraph.id);if(a<0)return!1;const i=a+n;if(i<0||i>=r.length){const o=e.state(),r=t(o,n),a=cr(r),i=n<0?a[0]:a[a.length-1];if(!i)return!1;const s=ci(i,n<0?Xr(i):0);return e.applyTransactionalState(()=>vv(r,s),{mergeKey:jp}),e.focusInput(),!0}const s=r[i],l=n<0?Xr(s):0;return e.applyTransactionalState(e=>vv(e,ci(s,l)),{mergeKey:jp}),e.focusInput(),!0},a=t=>{const n=e.stateSnapshot();e.applyHistoryState({...n,document:{...n.document,sections:n.document.sections?.map(Kt)},selection:{anchor:{...t.anchor},focus:{...t.focus}}})};return{performUndo:n,performRedo:o,moveSelectedImageByParagraph:r,applySelectionPreservingStructure:a}}(e)}function px(e={}){const t=e.dbName??"oasis-editor-db",n=e.storeName??"documents",o=e.key??"current-document";let r=null;async function a(){return r||(r=await function(e){return new Promise((t,n)=>{const o=indexedDB.open(e.name,e.version);o.onerror=()=>{n(/* @__PURE__ */new Error(`Failed to open IndexedDB: ${o.error?.message}`))},o.onsuccess=()=>{t(o.result)},o.onupgradeneeded=t=>{const n=o.result;e.onUpgrade(n,t.oldVersion,t.newVersion)}})}({name:t,version:1,onUpgrade:e=>{e.objectStoreNames.contains(n)||e.createObjectStore(n)}}),r)}return{async saveDocument(e){await function(e,t,n,o){return new Promise((r,a)=>{try{const i=e.transaction([t],"readwrite"),s=i.objectStore(t).put(o,n);s.onerror=()=>{a(/* @__PURE__ */new Error(`Failed to put item in ${t}: ${s.error?.message}`))},i.oncomplete=()=>{r()},i.onabort=i.onerror=()=>{a(/* @__PURE__ */new Error(`Transaction failed putting item in ${t}: ${i.error?.message}`))}}catch(i){a(i)}})}(await a(),n,o,e)},loadDocument:async()=>function(e,t,n){return new Promise((o,r)=>{try{const a=e.transaction([t],"readonly").objectStore(t).get(n);a.onerror=()=>{r(/* @__PURE__ */new Error(`Failed to get item from ${t}: ${a.error?.message}`))},a.onsuccess=()=>{o(a.result??null)}}catch(a){r(a)}})}(await a(),n,o),async clearDocument(){await function(e,t,n){return new Promise((o,r)=>{try{const a=e.transaction([t],"readwrite"),i=a.objectStore(t).delete(n);i.onerror=()=>{r(/* @__PURE__ */new Error(`Failed to delete item from ${t}: ${i.error?.message}`))},a.oncomplete=()=>{o()},a.onabort=a.onerror=()=>{r(/* @__PURE__ */new Error(`Transaction failed deleting item from ${t}: ${a.error?.message}`))}}catch(a){r(a)}})}(await a(),n,o)},close(){r&&(r.close(),r=null)}}}function gx(e){return function(e){const[t,n]=co([]),[o,r]=co([]);let a={undoStack:[],redoStack:[],lastTransactionMeta:null};const i=()=>{n(a.undoStack),r(a.redoStack)},s=t=>{e.commitState(e.cloneState(t))},l=(t,n)=>{const o=e.stateSnapshot(),r=Dt("txn:produce",()=>t(o),0);if(r===o)return;a=function(e,t,n,o,r=Date.now()){return{undoStack:void 0!==o?.mergeKey&&e.lastTransactionMeta?.mergeKey===o.mergeKey&&r-e.lastTransactionMeta.timestamp<1e3?e.undoStack:dx(e.undoStack,t),redoStack:[],lastTransactionMeta:o?.mergeKey?{mergeKey:o.mergeKey,timestamp:r}:null}}(a,o,0,n),i();const s=Dt("txn:invalidate",()=>function(e,t){if(e===t||e.document===t.document)return{};const n=e=>ei(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 o=cr(e),r=cr(t),a=/* @__PURE__ */new Map;for(const s of o)a.set(s.id,s);const i=[];for(const s of r){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 o=e.runs[n],r=s.runs[n];if(o===r)continue;if(o.id!==r.id||o.text!==r.text){t=!0;break}const a=fr(o),i=fr(r);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}}(o,r),0);e.applyLayoutInvalidation(s),Dt("txn:setState",()=>e.commitState(r),0)};return{undoStack:t,redoStack:o,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 fx(e){let t=e.state.document,n=e.state.selection;Zn(()=>{const o=e.state.document,r=e.state.selection,a=o!==t,i=r!==n;var s;if(t=o,n=r,e.state.activeSectionIndex,e.state.activeZone,s=e.state,Bp&&(Ap={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 mx(e){return function(e){const{documentOptions:t,logger:n,runtimeClient:o,state:r,commitState:a,getStateSnapshot:i,applyState:s,cloneState:l,isReadOnly:c,focusInput:d,surfaceRef:u,viewportRef:p,zoomFactor:g,getImageOps:f}=e,m=Iv({state:()=>r,applyState:s,applyTransactionalState:(e,t)=>U(e,t),isReadOnly:c,surfaceRef:()=>u()??null,stabilizeLayoutAfterImport:async()=>{await F()},resetEditorChromeState:()=>q(),focusInput:d,requestLocalFontAccess:ke,prepareDocumentFonts:async e=>{await bt(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:S,commentHighlights:I,revisionMarkupBoxes:C,changeBarBoxes:T,selectedImageBox:k,selectedTextBoxBox:P,selectedTableBox:R,caretBox:B,preferredColumnX:M,setPreferredColumnX:O,clearPreferredColumn:A,stabilizeLayoutAfterImport:F,setMeasuredBlockHeights:D,setMeasuredParagraphLayouts:E,applyInvalidation:L,onCleanupHook:N}=rx({state:r,surfaceRef:u,viewportRef:p,isImporting:h,zoomFactor:g}),z=px({key:t().persistenceKey}),{status:$}=cx(r,e=>{n.info("persistence:loaded",{docId:e.id});const t=jo(e);a(t),q()},{enabled:t().persistenceEnabled??!1,persistence:t().persistence??z,logger:n}),{undoStack:H,redoStack:W,applyTransactionalState:U,applyHistoryState:j,resetTransactionGrouping:V,updateHistoryState:K,getHistoryState:_,clearHistory:X}=gx({stateSnapshot:i,commitState:a,cloneState:l,applyLayoutInvalidation:L}),G=ux({state:()=>r,stateSnapshot:i,applyHistoryState:j,applyTransactionalState:U,focusInput:d,clearPreferredColumn:A,imageOps:f,updateHistoryState:K,getHistoryState:_}),q=()=>{A(),D({}),E({}),No(),x.clear(),X()};return fx({state:r,isImportInProgress:h,cloneState:l,getStateSnapshot:i,getOnStateChange:()=>t().onStateChange,emit:o.emit}),{docIO:m,isImportInProgress:h,measuredBlockHeights:b,measuredParagraphLayouts:y,documentLayout:v,canvasSnapshotProvider:x,inputBox:w,selectionBoxes:S,commentHighlights:I,revisionMarkupBoxes:C,changeBarBoxes:T,selectedImageBox:k,selectedTextBoxBox:P,selectedTableBox:R,caretBox:B,preferredColumnX:M,setPreferredColumnX:O,clearPreferredColumn:A,stabilizeLayoutAfterImport:F,setMeasuredBlockHeights:D,setMeasuredParagraphLayouts:E,applyLayoutInvalidation:L,onCleanupHook:N,fallbackPersistence:z,persistenceStatus:$,undoStack:H,redoStack:W,applyTransactionalState:U,applyHistoryState:j,resetTransactionGrouping:V,updateHistoryState:K,getHistoryState:_,clearHistory:X,historyActions:G,resetEditorChromeState:q}}(e)}function hx(e){return Ii(e,e=>"textBox"===e.kind)}function bx(e,t){const n=hx(e);if(!n||!Ko(n.run))return e;const o=function(e){if(!Number.isFinite(e))return;const t=(Math.round(e)%360+360)%360;return 0===t?void 0:t}(t),{paragraphIndex:r,run:a}=n,i=cr(e).map((e,t)=>t!==r?zo(e):{...zo(e),runs:e.runs.map(e=>e.id===a.id&&"textBox"===e.kind?{...e,textBox:{...e.textBox,rotation:o}}:Ea(e))});return qt(e,i,N(i,mr(e)))}function yx(e,t){const n=hx(e);if(!n||!Ko(n.run))return e;const{paragraphIndex:o,run:r}=n,a=cr(e).map((e,n)=>n!==o?zo(e):{...zo(e),runs:e.runs.map(e=>{if(e.id!==r.id||"textBox"!==e.kind)return Ea(e);const n=t(e.textBox.floating),o={...e.textBox};return n?o.floating=n:delete o.floating,{...e,textBox:o}})});return qt(e,a,N(a,mr(e)))}function vx(e,t,n,o={}){const r=hx(e),a=r&&Ko(r.run);if(!r||!a)return e;const i=o.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:g}=r,f=d-a.width,m=u-a.height,h=cr(e).map((e,t)=>t!==p?zo(e):{...zo(e),runs:e.runs.map(e=>{if(e.id!==g.id||"textBox"!==e.kind)return Ea(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,o,r){let a=e;if(o&&0!==t){const n=e.positionH;n?.align||(a={...a,positionH:{...n??{},offset:(n?.offset??0)-t*ur}})}if(r&&0!==n){const e=a.positionV;e?.align||(a={...a,positionV:{...e??{},offset:(e?.offset??0)-n*ur}})}return a}(t.floating,f,m,l,c)),{...e,textBox:n}})});return qt(e,h,N(h,mr(e)))}var xx=e=>e.cells.reduce((e,t)=>e+Math.max(1,t.colSpan??1),0),wx=e=>e.rows.reduce((e,t)=>Math.max(e,xx(t)),0),Sx=(e,t)=>{let n=0;for(const o of e.cells){const e=Math.max(1,o.colSpan??1);if(t>=n&&t<n+e)return o;n+=e}return null};function Ix(e){if(!e)return null;for(const t of e.blocks){const e=ta(t)[0];if(e)return e}return null}var Cx=e=>{for(const t of e.rows)for(const e of t.cells){if("continue"===e.vMerge)continue;const t=Ix(e);if(t)return t}return null};function Tx(e,t){return e.some(e=>ta(e).some(e=>e.id===t))}var kx=(e,t,n)=>{const o=Ya(e,t);if(!o)return{kind:"outside"};const r=Va(e,t,o.sectionIndex);if(!r)return{kind:"outside"};const a=function(e,t,n){for(const o of e){if(!Tx(o,n))continue;const e=Xa(o,t),r=e?.[e.length-1]?.table;if(r)return r}return null}(function(e,t){const n=Ya(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 o=Pa(e)[n.sectionIndex];return o?"main"===n.zone?[o.blocks]:"header"===n.zone?[o.header,o.firstPageHeader,o.evenPageHeader].filter(e=>Boolean(e)):[o.footer,o.firstPageFooter,o.evenPageFooter].filter(e=>Boolean(e)):[]}(e,t),r.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=>ta(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(ta),p=d?u[0]:c.blocks.find(e=>"paragraph"===e.type)??u[0];if(!p)return{kind:"blocked"};const g=d?u[u.length-1]:p;return{kind:"adjacent",selection:{anchor:ci(p,0),focus:ci(g,Xr(g))}}},Px=(e,t,n)=>{const o=kx(e,t,n);return"adjacent"===o.kind?o.selection.anchor:null};function Rx(e,t){return Boolean(e?.some(e=>ta(e).some(e=>e.id===t)))}function Bx(e,t,n){if("main"===n)return"blocks";const o=e.selection.focus.paragraphId;return"header"===n?[["header",t.header],["firstPageHeader",t.firstPageHeader],["evenPageHeader",t.evenPageHeader]].find(([,e])=>Rx(e,o))?.[0]??"header":"footer"===n?[["footer",t.footer],["firstPageFooter",t.firstPageFooter],["evenPageFooter",t.evenPageFooter]].find(([,e])=>Rx(e,o))?.[0]??"footer":"blocks"}function Mx(e){const t=Ya(e.document,e.selection.focus.paragraphId);return"footnote"===t?.zone?t.footnoteId:e.activeFootnoteId}function Ox(e,t){if("footnote"===t){const t=Mx(e);return t?e.document.footnotes?.items[t]?.blocks??[]:[]}const n=ei(e.document),o=nr(e),r=n[Math.max(0,Math.min(o,n.length-1))];if(!r)return[];const a=Bx(e,r,t);return"blocks"===a?r.blocks:r[a]??[]}var Ax=(e,t,n="main")=>{if("footnote"===n){const n=Mx(e),o=e.document.footnotes,r=n?o?.items[n]:void 0;return n&&o&&r?{...e,document:{...e.document,footnotes:{...o,items:{...o.items,[n]:{...r,blocks:t}}}}}:e}const o=nr(e),r=ei(e.document),a=Math.max(0,Math.min(o,r.length-1)),i=r[a];if(!i)return e;const s=Bx(e,i,n),l=[...r];return l[a]="blocks"===s?{...i,blocks:t}:{...i,[s]:t},{...e,document:{...e.document,sections:l}}};function Fx(e){const t=e.tablePath[e.tablePath.length-1];return t?{...e,rowIndex:t.rowIndex,cellIndex:t.cellIndex}:e}function Dx(e,t){const n=Xa(e,t.tablePath),o=n?.[n.length-1];return o?{tableBlock:o.table,targetCell:o.cell,location:Fx(t),targetBlocks:e}:null}function Ex(e,t,n){const o=n.tablePath[0];if(!o)return null;const r=t(e,n.zone),a=r[o.tableBlockIndex];if(!a||"table"!==a.type)return null;const i=[...r];return i[o.tableBlockIndex]=wn(a),Dx(i,n)}var Lx=(e,t,n)=>{const o=Ya(e.document,e.selection.focus.paragraphId),r=Ya(e.document,e.selection.anchor.paragraphId);if(!o||!r)return n(e);if(o.zone!==r.zone||o.sectionIndex!==r.sectionIndex||o.footnoteId!==r.footnoteId)return e;const a=Va(e.document,e.selection.focus.paragraphId,nr(e)),i=o.zone;let s,l;if(a){const n=function(e,t,n){const o=n.tablePath[0];if(!o)return null;const r=t(e,n.zone),a=r[o.tableBlockIndex];return a&&"table"===a.type?Dx(function(e,t){const n=[...e];let o=n;for(let r=0;r<t.length;r+=1){const e=t[r];if(!e)break;const n=o[e.tableBlockIndex];if(!n||"table"!==n.type)break;const a={...n,rows:[...n.rows]};o[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,o=c.blocks}return n}(r,n.tablePath),n):null}(e,t,a);if(!n)return e;s=n.targetBlocks,l=n.targetCell.blocks}else{const o=t(e,i);if(o.length&&o.every(e=>"paragraph"===e.type)&&o.some(t=>t.id===e.selection.anchor.paragraphId)&&o.some(t=>t.id===e.selection.focus.paragraphId))return n(e);s=[...o],l=s}const c=function(e,t){const n=e.findIndex(e=>"paragraph"===e.type&&e.id===t.anchor.paragraphId),o=e.findIndex(e=>"paragraph"===e.type&&e.id===t.focus.paragraphId);if(n<0||o<0)return null;let r=Math.min(n,o),a=Math.max(n,o)+1;if(e.slice(r,a).some(e=>"paragraph"!==e.type))return null;for(;r>0&&"paragraph"===e[r-1]?.type;)r--;for(;a<e.length&&"paragraph"===e[a]?.type;)a++;return{start:r,end:a}}(l,e.selection);if(!c)return e;const d=Pr(l.slice(c.start,c.end).map(e=>"paragraph"===e.type?zo(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}}},p=n(u),g=ei(p.document)[0]?.blocks??[];if(p===u&&JSON.stringify(g)===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,...g);const f=Ax(e,s,i),m=cr(e),h=cr(f),b=e.document.bookmarks,y=e.document.comments;return{...f,document:{...f.document,...b?{bookmarks:Ao(b,m,h)}:{},...y?{comments:bo(y,m,h)}:{}},selection:p.selection}};function Nx(e,t){const n=Va(e.document,e.selection.focus.paragraphId,nr(e));return n?Ex(e,t,n):null}function zx(e,t,n,o){const r=Ax(e,t,n);return o?{...r,selection:{anchor:ci(o,0),focus:ci(o,0)}}:r}function $x(e,t,n,o){const r=t.getTargetBlocks(e,n),a=Xa(r,o);return a?.[a.length-1]?.table??null}function Hx(e,t){const n=Va(e.document,e.selection.focus.paragraphId,nr(e)),o=n?.tablePath[n.tablePath.length-1];if(!n||!o)return null;const r=$x(e,t,n.zone,n.tablePath);return r?{table:r,rowIndex:o.rowIndex,cellIndex:o.cellIndex}:null}function Wx(e){return function(e){const t=t=>{const n=e.resolveHorizontalTableCellRange(t);return Boolean(n&&n.endCellIndex>n.startCellIndex)},n=t=>{const n=Hx(t,e);if(!n)return!1;const o=n.table.rows[n.rowIndex]?.cells[n.cellIndex];return Boolean((o?.colSpan??1)>1)},o=t=>{const n=e.resolveVerticalTableCellRange(t);if(!n)return!1;const o=$x(t,e,n.zone,n.tablePath);if(!o)return!1;for(let e=n.startRowIndex;e<=n.endRowIndex;e+=1){const t=o.rows[e]?.cells[n.cellIndex];if(!t||"continue"===t.vMerge||1!==t.blocks.length||"paragraph"!==t.blocks[0]?.type)return!1}return!0},r=e=>t(e)||o(e),a=t=>{const n=Hx(t,e);if(!n)return!1;const o=n.table.rows[n.rowIndex]?.cells[n.cellIndex];return Boolean((o?.rowSpan??1)>1&&"restart"===o?.vMerge)},i=e=>n(e)||a(e),s=t=>null!==Hx(t,e),l=t=>{const n=Hx(t,e);return Boolean(n&&wx(n.table)>1)};return{canMergeSelectedTableCells:t,canSplitSelectedTableCell:n,canMergeSelectedTableRows:o,canMergeSelectedTable:r,canSplitSelectedTableCellVertically:a,canSplitSelectedTable:i,canEditSelectedTableRow:s,canEditSelectedTableColumn:l}}(e)}function Ux(e,t){return e.visualRowIndex!==t.visualRowIndex?e.visualRowIndex-t.visualRowIndex:e.visualColumnIndex!==t.visualColumnIndex?e.visualColumnIndex-t.visualColumnIndex:0}function jx(e){return e.blocks.flatMap(ta)}function Vx(e){const t=e.tablePath[e.tablePath.length-1];return t?{...e,rowIndex:t.rowIndex,cellIndex:t.cellIndex}:e}function Kx(e,t){return function(e,t){const n=e.selection,o=nr(e),r=Va(e.document,n.anchor.paragraphId,o),a=Va(e.document,n.focus.paragraphId,o);if(!r||!a||r.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 o=e[n],r=t[n];if(o.tableBlockIndex!==r.tableBlockIndex)return!1;if(n<e.length-1&&(o.rowIndex!==r.rowIndex||o.cellIndex!==r.cellIndex))return!1}return!0}(r.tablePath,a.tablePath))return null;const i=t.getTargetBlocks(e,r.zone),s=Xa(i,r.tablePath),l=Xa(i,a.tablePath),c=s?.[s.length-1],d=l?.[l.length-1];if(!c||!d||c.table!==d.table)return null;const u=Vx(r),p=Vx(a),g=c.table,f=Or(g),m=f.find(e=>e.rowIndex===u.rowIndex&&e.cellIndex===u.cellIndex),h=f.find(e=>e.rowIndex===p.rowIndex&&e.cellIndex===p.cellIndex);return m&&h?{anchorLocation:u,focusLocation:p,anchorCell:m,focusCell:h,tableBlock:g,tableLayout:f}:null}(e,t)}function _x(e){return function(e){const t=t=>{const n=t.selection,o=Kx(t,e);if(!o||o.anchorLocation.rowIndex===o.focusLocation.rowIndex&&o.anchorLocation.cellIndex===o.focusLocation.cellIndex)return e.logger?.debug(`resolveTableCellRangeSelection: no expansion (anchor=${n.anchor.paragraphId} focus=${n.focus.paragraphId})`),null;const r=Math.min(o.anchorLocation.rowIndex,o.focusLocation.rowIndex),a=Math.max(o.anchorLocation.rowIndex,o.focusLocation.rowIndex),i=Math.min(o.anchorLocation.cellIndex,o.focusLocation.cellIndex),s=Math.max(o.anchorLocation.cellIndex,o.focusLocation.cellIndex);e.logger?.info(`resolveTableCellRangeSelection: expanding r${o.anchorLocation.rowIndex}:c${o.anchorLocation.cellIndex}->r${o.focusLocation.rowIndex}:c${o.focusLocation.cellIndex} (anchor=${n.anchor.paragraphId} focus=${n.focus.paragraphId}) range=[rows ${r}..${a}, cells ${i}..${s}]`);const l=Ux(o.anchorCell,o.focusCell)<=0?o.anchorLocation:o.focusLocation,c=Ux(o.anchorCell,o.focusCell)<=0?o.focusLocation:o.anchorLocation,d=o.tableBlock.rows[l.rowIndex]?.cells[l.cellIndex],u=o.tableBlock.rows[c.rowIndex]?.cells[c.cellIndex],p=d?jx(d)[0]:void 0,g=u?jx(u):[],f=g[g.length-1];return p&&f?{anchor:ci(p,0),focus:ci(f,Xr(f))}:null},n=t=>{const n=Kx(t,e);if(!n)return null;const o=Math.min(n.anchorCell.visualRowIndex,n.focusCell.visualRowIndex),r=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<=r&&e.visualRowIndex+e.rowSpan-1>=o&&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}},o=t=>{const n=Kx(t,e);if(!n||n.anchorCell.visualRowIndex!==n.focusCell.visualRowIndex)return null;const o=Ux(n.anchorCell,n.focusCell);if(0===o)return null;const r=o<=0?n.anchorLocation:n.focusLocation,a=o<=0?n.focusLocation:n.anchorLocation;return{blockIndex:n.anchorLocation.blockIndex,tablePath:n.anchorLocation.tablePath.map(e=>({...e})),rowIndex:r.rowIndex,startCellIndex:r.cellIndex,endCellIndex:a.cellIndex,zone:n.anchorLocation.zone}},r=t=>{const n=Kx(t,e);if(!n||n.anchorLocation.cellIndex!==n.focusLocation.cellIndex)return null;const o=Math.min(n.anchorCell.visualRowIndex,n.focusCell.visualRowIndex),r=Math.max(n.anchorCell.visualRowIndex,n.focusCell.visualRowIndex);return o===r?null:{blockIndex:n.anchorLocation.blockIndex,tablePath:n.anchorLocation.tablePath.map(e=>({...e})),startRowIndex:o,endRowIndex:r,cellIndex:n.anchorLocation.cellIndex,zone:n.anchorLocation.zone}};return{resolveTableCellRangeSelection:t,resolveSelectedTableCells:n,resolveHorizontalTableCellRange:o,resolveVerticalTableCellRange:r}}(e)}function Xx(e){if(e)for(const t of e.blocks){const e=ta(t)[0];if(e)return e}}function Gx(e,t,n){const o=n.tablePath[n.tablePath.length-1];return o?Ex(e,t.getTargetBlocks,{blockIndex:n.blockIndex,rowIndex:o.rowIndex,cellIndex:o.cellIndex,paragraphIndex:0,tablePath:n.tablePath,zone:n.zone}):null}function qx(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=>wn(e))}),n=n=>{const o=e.resolveHorizontalTableCellRange(n);if(!o)return n;const r=Gx(n,e,o);if(!r)return n;const{tableBlock:a,targetBlocks:i}=r,s=a.rows[o.rowIndex];if(!s)return n;const l=s.cells.slice(o.startCellIndex,o.endCellIndex+1);if(l.length<2)return n;const c=n.trackChangesEnabled?df():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=>wn(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(o.startCellIndex,l.length,d);const u=Xx(d);return u?zx(n,i,o.zone,u):n},o=n=>{const o=e.resolveVerticalTableCellRange(n);if(!o)return n;const r=Gx(n,e,o);if(!r)return n;const{tableBlock:a,targetBlocks:i}=r,s=[];for(let e=o.startRowIndex;e<=o.endRowIndex;e+=1){const t=a.rows[e],r=t?.cells[o.cellIndex];if(!t||!r||"continue"===r.vMerge||1!==r.blocks.length||"paragraph"!==r.blocks[0]?.type)return n;s.push(r)}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?df():void 0,d={...s[0],rowSpan:s.length,vMerge:"restart",blocks:s.flatMap(e=>e.blocks.map(e=>wn(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[o.startRowIndex].cells[o.cellIndex]=d;for(let e=o.startRowIndex+1;e<=o.endRowIndex;e+=1){const t=na([Ka("")],l);t.blocks=[],t.vMerge="continue",a.rows[e].cells[o.cellIndex]=t}const u=Xx(d);return u?zx(n,i,o.zone,u):n},r=t=>e.canMergeSelectedTableCells(t)?n(t):e.canMergeSelectedTableRows(t)?o(t):t,a=n=>{const o=Nx(n,e.getTargetBlocks);if(!o)return n;const{tableBlock:r,location:a,targetBlocks:i}=o,s=r.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?df():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 o=r.rows[a.rowIndex+n+1]?.cells[a.cellIndex];return o?t(o):na([],u)})]});for(let e=1;e<l;e+=1){const t=r.rows[a.rowIndex+e];if(!t)break;const n=na([Ka("")],u);t.cells[a.cellIndex]=n}const p=Xx(s);return p?zx(n,i,a.zone,p):n},i=n=>{const o=Nx(n,e.getTargetBlocks);if(!o)return n;const{tableBlock:r,location:a,targetBlocks:i}=o,s=r.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?df():void 0,p=[{...l,colSpan:void 0,blocks:l.blocks.map(e=>wn(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},()=>na([Ka("")]))];s.cells.splice(a.cellIndex,1,...p);const g=Xx(p[0]);return g?zx(n,i,a.zone,g):n},s=t=>e.canSplitSelectedTableCellVertically(t)?a(t):e.canSplitSelectedTableCell(t)?i(t):t;return{mergeSelectedTableCells:n,mergeSelectedTableRows:o,mergeSelectedTable:r,splitSelectedTableCellVertically:a,splitSelectedTableCell:i,splitSelectedTable:s}}(e)}function Yx(e,t){e.style={...e.style??{},revision:{...df(),type:t}}}function Zx(e){if(!e)return null;for(const t of e.blocks){const e=ta(t)[0];if(e)return e}return null}function Jx(e,t,n){const o=Zx(t);if(o)return o;if(n)for(const r of n.cells){if("continue"===r.vMerge)continue;const e=Zx(r);if(e)return e}return Cx(e)}function Qx(e){return function(e){const t=(t,n)=>{const o=Nx(t,e.getTargetBlocks);if(!o)return t;const{tableBlock:r,location:a,targetBlocks:i}=o,s=r.rows[a.rowIndex];if(!s)return t;const l=Math.max(0,Math.min(r.rows.length,a.rowIndex+(n>0?1:0)));let c;if(r.rows.some(e=>e.cells.some(e=>Math.max(1,e.rowSpan??1)>1||void 0!==e.vMerge))){const e=Or(r),n=e.find(e=>e.rowIndex===a.rowIndex&&e.cellIndex===a.cellIndex),o=e.filter(e=>e.rowIndex===a.rowIndex),s=o.length>0?o:e.filter(e=>e.rowIndex===Math.max(0,a.rowIndex-1));c=Ra(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=na([Ka("")],t.colSpan);return e.blocks=[],e.vMerge="continue",e}return na([Ka("")],t.colSpan)})),t.trackChangesEnabled&&Yx(c,"insert"),r.rows.splice(l,0,c);const d=n?.visualColumnIndex??a.cellIndex,u=Jx(r,Sx(c,d),c);return zx(t,i,a.zone,u)}c=Ra(s.cells.map(e=>na([Ka("")],Math.max(1,e.colSpan??1)))),t.trackChangesEnabled&&Yx(c,"insert"),r.rows.splice(l,0,c);const d=Jx(r,c.cells[Math.min(a.cellIndex,c.cells.length-1)],c);return zx(t,i,a.zone,d)},n=t=>{const n=Nx(t,e.getTargetBlocks);if(!n)return t;const{tableBlock:o,targetBlocks:r,location:a}=n,i=o.rows[o.rows.length-1];if(!i||!i.cells.length)return t;const s=i.cells.map(e=>{const t=na([Ka("")],Math.max(1,e.colSpan??1));if(e.style){const{revision:n,...o}=e.style;t.style=o}return t}),l=Math.max(o.gridCols?.length??0,wx(o));for(let e=s.reduce((e,t)=>e+Math.max(1,t.colSpan??1),0);e<l;e++)s.push(na([Ka("")]));const c=Ra(s);return t.trackChangesEnabled&&Yx(c,"insert"),o.rows.push(c),zx(t,r,a.zone,Zx(s[0]))},o=t=>{const n=Nx(t,e.getTargetBlocks);if(!n)return t;const{tableBlock:o,location:r,targetBlocks:a}=n;if(o.rows.length<=1&&!t.trackChangesEnabled)return t;const i=o.rows[r.rowIndex];if(!i)return t;if(t.trackChangesEnabled)return Yx(i,"delete"),zx(t,a,r.zone,null);if(i.cells.some(e=>"continue"!==e.vMerge&&Math.max(1,e.rowSpan??1)>1))return t;const s=o.rows.some(e=>e.cells.some(e=>Math.max(1,e.rowSpan??1)>1||void 0!==e.vMerge)),l=s?Or(o).find(e=>e.rowIndex===r.rowIndex&&e.cellIndex===r.cellIndex):null;if(s){const e=Or(o);for(const t of e)t.visualRowIndex<r.rowIndex&&t.visualRowIndex+t.rowSpan>r.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")}o.rows.splice(r.rowIndex,1);const c=o.rows[Math.min(r.rowIndex,o.rows.length-1)],d=Jx(o,c?Sx(c,Math.min(l?.visualColumnIndex??r.cellIndex,Math.max(0,xx(c)-1))):null);return zx(t,a,r.zone,d)},r=(t,n)=>{const o=Nx(t,e.getTargetBlocks);if(!o)return t;const{tableBlock:r,location:a,targetBlocks:i}=o;if(r.rows.some(e=>e.cells.some(e=>Math.max(1,e.colSpan??1)>1))){const e=Or(r).find(e=>e.rowIndex===a.rowIndex&&e.cellIndex===a.cellIndex),o=(e?.visualColumnIndex??a.cellIndex)+(n>0?Math.max(1,e?.colSpan??1):0);for(const n of r.rows){const e=[];let r=0,a=!1;for(const i of n.cells){const n=Math.max(1,i.colSpan??1);if(!a&&o<=r){const n=na([Ka("")]);t.trackChangesEnabled&&Yx(n,"insert"),e.push(n),a=!0}!a&&r<o&&o<r+n?(e.push({...i,colSpan:n+1,...t.trackChangesEnabled?{style:{...i.style??{},revision:{...df(),type:"merge",previous:{colSpan:i.colSpan}}}}:{}}),a=!0):e.push(i),r+=n}if(!a){const n=na([Ka("")]);t.trackChangesEnabled&&Yx(n,"insert"),e.push(n)}n.cells=e}const s=r.rows[a.rowIndex],l=Jx(r,s?Sx(s,o):null);return zx(t,i,a.zone,l)}const s=Math.max(0,Math.min(r.rows[0]?.cells.length??0,a.cellIndex+(n>0?1:0)));for(const e of r.rows){const n=na([Ka("")]);t.trackChangesEnabled&&Yx(n,"insert"),e.cells.splice(s,0,n)}const l=r.rows[a.rowIndex]?.cells[s],c=Jx(r,l);return zx(t,i,a.zone,c)},a=t=>{const n=Nx(t,e.getTargetBlocks);if(!n)return t;const{tableBlock:o,location:r,targetBlocks:a}=n;if(wx(o)<=1)return t;if(t.trackChangesEnabled){const e=Or(o).find(e=>e.rowIndex===r.rowIndex&&e.cellIndex===r.cellIndex)?.visualColumnIndex??r.cellIndex;for(const t of o.rows){const n=Sx(t,e);n&&Yx(n,"delete")}return zx(t,a,r.zone,null)}if(o.rows.some(e=>e.cells.some(e=>Math.max(1,e.colSpan??1)>1))){const e=Or(o).find(e=>e.rowIndex===r.rowIndex&&e.cellIndex===r.cellIndex)?.visualColumnIndex??r.cellIndex;for(const t of o.rows){const n=[];let o=0;for(const r of t.cells){const t=Math.max(1,r.colSpan??1);e>=o&&e<o+t?t>1&&n.push({...r,colSpan:t-1>1?t-1:void 0}):n.push(r),o+=t}t.cells=n}const n=o.rows[r.rowIndex],i=Jx(o,n&&Sx(n,Math.min(e,Math.max(0,xx(n)-1))));return zx(t,a,r.zone,i)}if(o.rows[0]?.cells.length<=1)return t;for(const e of o.rows)e.cells.splice(r.cellIndex,1);const i=o.rows[r.rowIndex],s=i?.cells[Math.min(r.cellIndex,i.cells.length-1)],l=Jx(o,s);return zx(t,a,r.zone,l)};return{insertSelectedTableRow:t,appendTableRowForTab:n,deleteSelectedTableRow:o,insertSelectedTableColumn:r,deleteSelectedTableColumn:a}}(e)}function ew(e){return function(e){const t=t=>{const n=e.resolveTableCellRangeSelection(t);return n?e.applySelectionToStatePreservingStructure(t,n):t},n=(n,o)=>{e.applyTransactionalState(r=>{const a=e.resolveSelectedTableCells(r);if(!a||a.cells.length<=1){const a=t(r);return a!==r&&e.logger?.info(`${o}: 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(`${o}: 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(ta);d.push(...t),u.push(t.length)}if(0===d.length)return r;const p={...r,activeSectionIndex:0,activeZone:"main",document:{...Pr(d,r.document.pageSettings,void 0,r.document.styles,void 0,r.document.assets),settings:r.document.settings},selection:{anchor:ci(d[0],0),focus:ci(d[d.length-1],Xr(d[d.length-1]))}},g=n(p);if(g===p)return r;const f=cr(g);if(f.length!==d.length)return r;const m=s[s.length-1];if(!m)return r;const h=Ex(r,e.getTargetBlocks,{blockIndex:i,rowIndex:m.rowIndex,cellIndex:m.cellIndex,paragraphIndex:0,tablePath:s,zone:c});if(!h)return r;let b=0;for(let e=0;e<l.length;e+=1){const t=l[e],n=u[e]??0,o=f.slice(b,b+n);b+=n;const r=h.tableBlock.rows[t.rowIndex]?.cells[t.cellIndex];r&&(r.blocks=jt(r.blocks,o))}return Ax(r,h.targetBlocks,c)})};return{withExpandedTableCellSelection:t,applySelectionAwareTextCommand:e=>{n(e,"applySelectionAwareTextCommand")},applySelectionAwareParagraphCommand:e=>{n(e,"applySelectionAwareParagraphCommand")}}}(e)}function tw(e){return function(e){const t=Ox,{resolveTableCellRangeSelection:n,resolveSelectedTableCells:o,resolveHorizontalTableCellRange:r,resolveVerticalTableCellRange:a}=_x({getTargetBlocks:t,logger:e.logger}),{canMergeSelectedTableCells:i,canSplitSelectedTableCell:s,canMergeSelectedTableRows:l,canMergeSelectedTable:c,canSplitSelectedTableCellVertically:d,canSplitSelectedTable:u,canEditSelectedTableRow:p,canEditSelectedTableColumn:g}=Wx({getTargetBlocks:t,resolveHorizontalTableCellRange:r,resolveVerticalTableCellRange:a}),{mergeSelectedTableCells:f,mergeSelectedTableRows:m,mergeSelectedTable:h,splitSelectedTableCellVertically:b,splitSelectedTableCell:y,splitSelectedTable:v}=qx({getTargetBlocks:t,resolveHorizontalTableCellRange:r,resolveVerticalTableCellRange:a,canMergeSelectedTableCells:i,canMergeSelectedTableRows:l,canSplitSelectedTableCell:s,canSplitSelectedTableCellVertically:d}),{insertSelectedTableRow:x,appendTableRowForTab:w,deleteSelectedTableRow:S,insertSelectedTableColumn:I,deleteSelectedTableColumn:C}=Qx({getTargetBlocks:t}),T=(e,n)=>Lx(e,t,n),{withExpandedTableCellSelection:k,applySelectionAwareTextCommand:P,applySelectionAwareParagraphCommand:R}=ew({applyTransactionalState:e.applyTransactionalState,applySelectionToStatePreservingStructure:e.applySelectionToStatePreservingStructure,getTargetBlocks:t,resolveTableCellRangeSelection:n,resolveSelectedTableCells:o,logger:e.logger}),B=(t,n)=>{e.logger?.info(`insertTableCommand: ${t}x${n}`),e.applyTransactionalState(e=>function(e,t,n){const o=100/Math.max(1,n)+"%",r=e.trackChangesEnabled?df():void 0,a=[];for(let b=0;b<t;b+=1){const e=[];for(let r=0;r<n;r+=1)e.push({...na([Ka("")]),style:{width:o}});const t=Ra(e);r&&(t.style={revision:{...r,type:"insert"}}),a.push(t)}const i={...Ga(a),style:{width:"100%"}},s=br(e,e.selection.focus),l=Pa(e.document),c=nr(e),d=pr(e),u=e=>{const t=e.findIndex(e=>e.id===s.paragraphId||"paragraph"!==e.type&&ta(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 g={...p};let f=!1;if("header"===d){const e=u(p.header??[]);g.header=e.nextBlocks,f=e.found}else if("footer"===d){const e=u(p.footer??[]);g.footer=e.nextBlocks,f=e.found}else{const e=u(p.blocks);g.blocks=e.nextBlocks,f=e.found}if(!f)return e;const m=[...l];m[c]=g;const h=i.rows[0].cells[0].blocks[0];return"paragraph"!==h.type?e:{...e,document:{...e.document,sections:m},selection:Y(ci(h,0))}}(e,t,n),{mergeKey:Up}),e.focusInput()};return{resolveTableCellRangeSelection:n,resolveHorizontalTableCellRange:r,resolveVerticalTableCellRange:a,canMergeSelectedTableCells:i,canSplitSelectedTableCell:s,canMergeSelectedTableRows:l,canMergeSelectedTable:c,canSplitSelectedTableCellVertically:d,canSplitSelectedTable:u,canEditSelectedTableRow:p,canEditSelectedTableColumn:g,mergeSelectedTableCells:f,mergeSelectedTableRows:m,mergeSelectedTable:h,splitSelectedTableCellVertically:b,splitSelectedTableCell:y,splitSelectedTable:v,insertSelectedTableRow:x,appendTableRowForTab:w,deleteSelectedTableRow:S,insertSelectedTableColumn:I,deleteSelectedTableColumn:C,getRowVisualWidth:xx,getTableVisualWidth:wx,findCellAtVisualColumn:Sx,findFirstNavigableParagraphInTable:Cx,updateBlocksInCurrentSection:Ax,resolveAdjacentTableCellPosition:Px,resolveTableTabTarget:kx,applyTableAwareParagraphEdit:T,withExpandedTableCellSelection:k,applySelectionAwareTextCommand:P,applySelectionAwareParagraphCommand:R,insertTableCommand:B}}(e)}function nw(){let e=null;return{claim:t=>{e=t.pointerId??null},owns:t=>null===e||t.pointerId===e,release:()=>{e=null}}}function ow(e,t){let n=null;const o=(e,t,n)=>{const o=cr(e).find(e=>e.id===t);return o?{anchor:ci(o,n),focus:ci(o,n+1)}:null},r=(e,t)=>({...e,selection:{anchor:{...t.anchor},focus:{...t.focus}}}),a=nw(),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:g}=Xe(s,c,d,i.shiftKey,u),f=o(t.state,s.paragraphId,s.paragraphOffset);f?t.applyState(e.applyResize(r(t.state,f),p,g,s.handleDirection)):t.logger.warn(`${e.label} resize:missing paragraph`,s)},s=()=>{const e=n;e&&t.updateHistoryState(n=>({...n,undoStack:dx(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 g=o(p,l,c);if(!g)return;const f=e.getSelected(r(p,g));f&&(n={paragraphId:l,paragraphOffset:c,handleDirection:d,startClientX:u.clientX,startClientY:u.clientY,startWidth:f.width,startHeight:f.height,aspectRatio:f.width/f.height,initialState:t.cloneState(p)},a.claim(u),window.addEventListener("pointermove",i),window.addEventListener("pointerup",s),window.addEventListener("pointercancel",s))},stop:l}}function rw(e,t){let n=null;const o=nw(),r=r=>{if(!o.owns(r))return;const a=n;if(!a)return;let i=((180*Math.atan2(r.clientY-a.centerY,r.clientX-a.centerX)/Math.PI+90)%360+360)%360;r.shiftKey&&(i=15*Math.round(i/15)%360);const s=((e,t,n)=>{const o=cr(e).find(e=>e.id===t);return o?{anchor:ci(o,n),focus:ci(o,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:dx(n.undoStack,t.cloneState(e.initialState)),redoStack:[]})),i(),t.focusInput()},i=()=>{n=null,o.release(),window.removeEventListener("pointermove",r),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)},o.claim(s),window.addEventListener("pointermove",r),window.addEventListener("pointerup",a),window.addEventListener("pointercancel",a)},stop:i}}function aw(e,t){return Math.max(1e-4,1-e-t)}function iw(e,t,n,o){const r=Math.max(.01,1-e-t),a=Math.max(0,Math.min(n,.99-t)),i=Math.max(0,Math.min(o,.99-a));return a+i>=.99?{near:Math.max(0,.99-r-t),far:t}:{near:a,far:i}}function sw(e){let t=null;const n=(e,t,n)=>{const o=cr(e).find(e=>e.id===t);return o?{anchor:ci(o,n),focus:ci(o,n+1)}:null},o=(e,t)=>({...e,selection:{anchor:{...t.anchor},focus:{...t.focus}}}),r=nw(),a=a=>{if(!r.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:o,startHeight:r}=e,a=e.startCrop.left??0,i=e.startCrop.top??0,s=e.startCrop.right??0,l=e.startCrop.bottom??0,c=aw(a,s)/o,d=aw(i,l)/r,u=1-a-s,p=1-i-l,g=Math.max(0,Math.min(1-u,a-t*c)),f=Math.max(0,Math.min(1-p,i-n*d));return{crop:{left:g,right:Math.max(0,1-u-g),top:f,bottom:Math.max(0,1-p-f)},width:Math.round(o),height:Math.round(r)}}(i,l,c):function(e,t,n){const{startWidth:o,startHeight:r}=e,a=e.startCrop.left??0,i=e.startCrop.top??0,s=e.startCrop.right??0,l=e.startCrop.bottom??0,c=aw(a,s)/o,d=aw(i,l)/r,u=V(e.handleDirection,"x"),p=V(e.handleDirection,"y");let g=a,f=s,m=o;if(0!==u)if(u<0){m=Je(o-t,24,o+a/c);const e=iw(a,s,a-(m-o)*c,s);g=e.near,f=e.far}else{m=Je(o+t,24,o+s/c);const e=iw(a,s,a,s-(m-o)*c);g=e.near,f=e.far}let h=i,b=l,y=r;if(0!==p)if(p<0){y=Je(r-n,24,r+i/d);const e=iw(i,l,i-(y-r)*d,l);h=e.near,b=e.far}else{y=Je(r+n,24,r+l/d);const e=iw(i,l,i,l-(y-r)*d);h=e.near,b=e.far}return{crop:{left:g,top:h,right:f,bottom:b},width:Math.round(m),height:Math.round(y)}}(i,l,c),u=n(e.state,i.paragraphId,i.paragraphOffset);u?e.applyState(dv(o(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:dx(t.undoStack,e.cloneState(n.initialState)),redoStack:[]})),s(),e.focusInput()},s=()=>{t=null,r.release(),window.removeEventListener("pointermove",a),window.removeEventListener("pointerup",i),window.removeEventListener("pointercancel",i)},l=(s,l,c,d,u,p)=>{const g=n(u,s,l);if(!g)return;const f=sv(o(u,g)),m=f&&fr(f.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},r.claim(d),window.addEventListener("pointermove",a),window.addEventListener("pointerup",i),window.addEventListener("pointercancel",i)};return{start:(e,t,n,o,r)=>l(e,t,n,o,r,"handle"),startMove:(e,t,n,o)=>l(e,t,"se",n,o,"move"),stop:s}}function lw(e){return function(e){const[t,n]=co(!1),[o,r]=co(!1),[a,i]=co(null);Zn(()=>{o()&&!m(e.state)&&r(!1)});const s=()=>{m(e.state)?r(e=>!e):r(!1)},[l,c]=co({x:0,y:0}),[d,u]=co(null);let p=null,g=null,f=null;const m=e=>{const t=mr(e);if(t.isCollapsed||t.startIndex!==t.endIndex||t.endParagraphOffset-t.startParagraphOffset!==1)return null;const n=cr(e)[t.startIndex];if(!n)return null;let o=0;for(const r of n.runs){const a=o;if(o+=r.text.length,"image"===r.kind&&1===r.text.length&&a===t.startParagraphOffset)return{paragraph:n,run:r,startOffset:a,width:r.image.width,height:r.image.height,src:aa(e.document,r.image.src)}}return null},h=(t,n)=>e.resolvePositionAtSurfacePoint(t,n),b=()=>{f||(f=document.createElement("style"),f.setAttribute("data-oasis-image-drag-cursor",""),f.textContent="*, *::before, *::after { cursor: grabbing !important; }",document.head.appendChild(f))},y=()=>{f&&(f.remove(),f=null),document.body.style.cursor=""},v=nw(),x=()=>{y(),g=null,p=null,n(!1),i(null),u(null),v.release(),window.removeEventListener("pointermove",T),window.removeEventListener("pointerup",k),window.removeEventListener("pointercancel",k)},w=()=>{x()},S=ow({label:"image",getSelected:e=>m(e),applyResize:(e,t,n)=>lv(e,t,n),getMaxWidth:(t,n)=>xv(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}),I=rw({label:"image",applyRotate:(e,t)=>function(e,t){const n=fv(t);return bv(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=sw({state:e.state,applyState:e.applyState,updateHistoryState:e.updateHistoryState,cloneState:e.cloneState,focusInput:e.focusInput,logger:e.logger,zoomFactor:e.zoomFactor}),T=t=>{if(!v.owns(t))return;let o=p;if(!o){const r=g;if(!r)return;if(Math.abs(t.clientX-r.startClientX)+Math.abs(t.clientY-r.startClientY)<4)return;o={paragraphId:r.paragraphId,paragraphOffset:r.paragraphOffset,src:r.src,width:r.width,height:r.height,offsetX:r.offsetX,offsetY:r.offsetY},p=o,g=null,n(!0),b(),e.logger.info(`image drag:start ${o.paragraphId}@${o.paragraphOffset} client=(${t.clientX},${t.clientY})`)}c({x:t.clientX,y:t.clientY}),i({...o}),u(h(t.clientX,t.clientY))},k=t=>{if(!v.owns(t))return;const n=p;if(n||g){if(n){const o=h(t.clientX,t.clientY);o?(e.logger.info(`image drag:done ${n.paragraphId} -> ${o.paragraphId}:${o.runId}[${o.offset}]`),e.applyTransactionalState(e=>vv(e,o),{mergeKey:jp})):e.logger.warn(`image drag:cancel ${n.paragraphId} no target at (${t.clientX},${t.clientY})`)}x(),e.focusInput()}else e.focusInput()},P=(t,o,r,a)=>{const s=r.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);g={paragraphId:t,paragraphOffset:o,startClientX:r.clientX,startClientY:r.clientY,src:d?.src??"",width:d?.width??l.width,height:d?.height??l.height,offsetX:r.clientX-l.left,offsetY:r.clientY-l.top},p=null,c({x:r.clientX,y:r.clientY}),n(!1),i(null),u(null),v.claim(r),window.addEventListener("pointermove",T),window.addEventListener("pointerup",k),window.addEventListener("pointercancel",k)},R=(t,n,o)=>{o.preventDefault(),o.stopPropagation();const r=ya(e.state.document).find(e=>e.id===t);r&&e.applyState(xi(e.state,{anchor:ci(r,n),focus:ci(r,n+1)})),P(t,n,o),e.focusInputAfterPointerSelection()},B=(t,n,o,r)=>{r.preventDefault(),r.stopPropagation(),S.start(t,n,o,r,e.state)},M=(t,n,o)=>{o.preventDefault(),o.stopPropagation(),I.start(t,n,o,e.state)},O=(t,n,o,r)=>{r.preventDefault(),r.stopPropagation(),C.start(t,n,o,r,e.state)},A=(t,n,o)=>{o.preventDefault(),o.stopPropagation(),C.startMove(t,n,o,e.state)};return{dragging:t,cropMode:o,setCropMode:r,toggleCropMode:s,draggedImageInfo:a,mousePos:l,dropTargetPos:d,getSelectedImageInfo:m,startImageDrag:P,stopImageDrag:w,stopImageResize:S.stop,stopImageRotate:I.stop,stopImageCrop:C.stop,handleImagePointerDown:R,handleImageResizeHandlePointerDown:B,handleImageRotateHandlePointerDown:M,handleImageCropHandlePointerDown:O,handleImageCropBodyPointerDown:A}}(e)}function cw(e){return function(e){const t=e=>{const t=hx(e),n=t&&Ko(t.run);return n?{width:n.width,height:R(n,e,0)}:null},n=ow({label:"text box",getSelected:t,applyResize:(e,t,n,o)=>vx(e,t,n,{handleDirection:o}),getMaxWidth:(n,o)=>{const r=xv(e.surfaceRef(),n.document,o,n.activeSectionIndex??0),a=t(n);return a?Math.max(r,a.width):r}},{state:e.state,applyState:e.applyState,updateHistoryState:e.updateHistoryState,cloneState:e.cloneState,focusInput:e.focusInput,logger:e.logger,zoomFactor:e.zoomFactor}),o=rw({label:"text box",applyRotate:(e,t)=>bx(e,t)},{state:e.state,applyState:e.applyState,updateHistoryState:e.updateHistoryState,cloneState:e.cloneState,focusInput:e.focusInput,logger:e.logger}),r=(t,o,r,a)=>{a.preventDefault(),a.stopPropagation(),n.start(t,o,r,a,e.state)},a=(t,n,r)=>{r.preventDefault(),r.stopPropagation(),o.start(t,n,r,e.state)};return{handleTextBoxResizeHandlePointerDown:r,handleTextBoxRotateHandlePointerDown:a,stopTextBoxResize:n.stop,stopTextBoxRotate:o.stop}}(e)}function dw(e){return function(e){const[t,n]=co(void 0),o=()=>{n(void 0)};Zn(()=>{sr(e.state().selection)||o()});const r=(e,t)=>{n(n=>{const o={...n??{}};return null==t||""===t?delete o[e]:o[e]=t,Object.keys(o).length>0?o:void 0})},a=(e,t)=>{n(n=>{const o={...n??{}};return o[e]=t,"superscript"===e&&t&&(o.subscript=!1),"subscript"===e&&t&&(o.superscript=!1),o})},i=()=>{const n=Rt(e.state()),o=t();return sr(e.state().selection)&&o?{...n,bold:o.bold??n.bold,italic:o.italic??n.italic,underline:o.underline??n.underline,underlineStyle:void 0!==o.underlineStyle?String(o.underlineStyle??""):n.underlineStyle,strike:o.strike??n.strike,superscript:o.superscript??n.superscript,subscript:o.subscript??n.subscript,fontFamily:o.fontFamily??n.fontFamily,fontSize:void 0!==o.fontSize&&null!==o.fontSize?String(o.fontSize):n.fontSize,color:o.color??n.color,highlight:o.highlight??n.highlight,textShading:o.shading??n.textShading,link:o.link??n.link,characterStyleId:void 0!==o.styleId&&null!==o.styleId?String(o.styleId):n.characterStyleId}:n},s=(t,n)=>{if(sr(e.state().selection))return e.logger.info(`setPendingStyle:${t}=${JSON.stringify(n)}`),e.clearPreferredColumn(),e.resetTransactionGrouping(),r(t,n),void e.focusInput();e.commandsController().applyValueStyleCommand(t,n)},l=t=>{if(sr(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(sr(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:o,toolbarStyleState:i,applyToolbarValueStyleCommand:s,applyToolbarUnderlineStyleCommand:c,applyToolbarBooleanStyleCommand:l}}(e)}function uw(e,t,n={}){if(!t)return[];const o=[],r=ya(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 r.forEach((e,t)=>{const n=oi(e);let r;for(c.lastIndex=0;null!==(r=c.exec(n));){const n=r.index,a=r.index+r[0].length;o.push({anchor:ci(e,n),focus:ci(e,a),paragraphIndex:t}),r.index===c.lastIndex&&c.lastIndex++}}),o}function pw(e,t,n,o={}){const r=uw(e.document,t,o);if(0===r.length)return e;let a=e;for(let i=r.length-1;i>=0;i-=1){const e=r[i];a=xi(a,{anchor:e.anchor,focus:e.focus}),a=_u(a,n)}return a}function gw(e,t,n,o,r,a){const i=e+n,s=t+o;return(a<t?t-a:a>s?a-s:0)*st+(r<e?e-r:r>i?r-i:0)}function fw(e,t,n){if(0===e.slots.length)return{offset:e.startOffset,score:Number.POSITIVE_INFINITY};let o=e.slots[0].offset,r=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*st+c;d<r&&(r=d,o=l.offset,a=l.left,i=l.top,s=l.height)}return{offset:o,score:r,slotLeft:a,slotTop:i,slotHeight:s}}function mw(e,t,n){let o=e.startOffset,r=Number.POSITIVE_INFINITY;for(const a of e.lines){const{offset:e,score:i}=fw(a,t,n);i<r&&(r=i,o=e)}return Math.max(e.startOffset,Math.min(o,e.endOffset))}function hw(e,t,n){return e>=n.left&&e<=n.left+n.width&&t>=n.top&&t<=n.top+n.height}function bw(e){const{snapshot:t,state:n}=e,o=e.pierce??!1,r=e.zoomFactor&&e.zoomFactor>0?e.zoomFactor:1,a=t.surfaceRect,i=a.left+(e.clientX-a.left)/r,s=a.top+(e.clientY-a.top)/r,l=function(e,t,n){if(0===e.length)return null;let o=e[0],r=Number.POSITIVE_INFINITY;for(const a of e){const e=gw(a.left,a.top,a.width,a.height,t,n);e<r&&(r=e,o=a)}return o}(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,o,r,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)&&o>=s.left&&o<=s.left+s.width&&r>=s.top&&r<=s.top+s.height)return s}return null}(t,l.index,c,i,s,o);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=ci(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,o,r,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)&&hw(o,r,s))return s}for(const i of e.inlineImages)if(i.pageIndex===t&&i.zone===n&&hw(o,r,i))return i;return null}(t,l.index,c,i,s,o);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=ci(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 o=null;for(const i of e)for(const e of i.lines){const r=e.top-2,a=e.top+e.height+2;if(n<r||n>a)continue;const{offset:s,score:l,slotLeft:c,slotTop:d,slotHeight:u}=fw(e,t,n);(!o||l<o.score)&&(o={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(o)return{paragraph:o.paragraph,offset:o.offset,caretViewport:o.caretViewport};let r=null,a=Number.POSITIVE_INFINITY;for(const i of e){const e=gw(i.left,i.top,Math.max(1,i.width),Math.max(1,i.height),t,n);e<a&&(a=e,r=i)}return r?{paragraph:r,offset:mw(r,t,n),caretViewport:{left:r.left,top:r.top,height:Math.max(16,Math.min(32,r.height||24))}}:null}(t.paragraphs.filter(e=>e.pageIndex===l.index&&e.zone===c),i,s);if(!p){const e=n.selection.focus.paragraphId,o=n.selection.focus.offset,r=function(e,t,n,o,r){return e.unsupportedRegions.find(e=>e.pageIndex===t&&e.zone===n&&o>=e.left&&o<=e.left+e.width&&r>=e.top&&r<=e.top+e.height)?.reason??null}(t,l.index,c,i,s);return{zone:c,paragraphId:e,paragraphOffset:o,position:{...n.selection.focus},source:"canvas-layout",resolvedFromParagraph:!1,missReason:r??"zone-without-paragraph"}}const g=p.paragraph,f=Math.max(0,Math.min(p.offset,g.textLength)),m=p.caretViewport;let h;if(m&&i!==m.left){const e=g.lines.filter(e=>s>=e.top&&s<=e.top+e.height&&e.slots.some(e=>e.offset===f&&e.left===m.left&&e.top===m.top));if(1===e.length){const t=e[0].slots,n=t.filter(e=>e.offset===f),o=t.find(e=>e.offset===f-1),r=t.find(e=>e.offset===f+1);1===n.length&&o&&r&&o.left<m.left&&m.left<r.left&&(h=i<m.left?"before-markers":"after-markers")}}const b=Qr(g.paragraph,f,h);return{zone:c,footnoteId:g.footnoteId,paragraphId:g.paragraphId,paragraphOffset:f,position:b,source:"canvas-layout",resolvedFromParagraph:!0,tableCellAnchorPosition:g.tableCell?.anchorPosition,caretViewport:p.caretViewport}}function yw(e){return function(e){const t=(t,n,o={})=>{const r=e.surfaceRef();if(!r)return null;const a=e.state(),i=e.zoomFactor(),s=e.canvasSnapshotProvider.getCanvasLayoutSnapshot({surface:r,state:a,documentLayout:e.documentLayout(),zoomFactor:i});if(function(e){Bp&&(Op=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 Ep(null),null;const l=bw({snapshot:s,state:a,clientX:t,clientY:n,pierce:o.pierce??!1,zoomFactor:i});return Ep(l),l};return{resolveSurfaceHitAtPoint:t}}(e)}var vw=[{x:0,y:0},{x:1,y:0},{x:1,y:1},{x:0,y:1}],xw=/* @__PURE__ */new Map;function ww(){return vw.map(e=>({...e}))}var Sw=[[0,-1],[1,-1],[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1]];function Iw(e,t,n){const[o,r]=e,[a,i]=t,[s,l]=n,c=s-a,d=l-i,u=c*c+d*d;return 0===u?Math.hypot(o-a,r-i):Math.abs(c*(i-r)-d*(a-o))/Math.sqrt(u)}function Cw(e,t){if(e.length<3)return e.slice();let n=0,o=0;const r=e[0],a=e[e.length-1];for(let l=1;l<e.length-1;l+=1){const t=Iw(e[l],r,a);t>n&&(n=t,o=l)}if(n<=t)return[r,a];const i=Cw(e.slice(0,o+1),t),s=Cw(e.slice(o),t);return[...i.slice(0,-1),...s]}function Tw(e,t,n){let o=0;for(let l=0;l<e.length;l+=1)1===e[l]&&(o+=1);if(t<=0||n<=0||0===o||o/(t*n)>=.985)return ww();const r=function(e,t,n){const o=(o,r)=>o>=0&&o<t&&r>=0&&r<n&&1===e[r*t+o];let r=-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]){r=n,a=u;break}if(r<0)return[];const i=[];let s=r,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,[r,a]=Sw[n],d=s+r,u=l+a;if(o(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===r&&l===a&&i.length>1)break}return i}(e,t,n);if(r.length<3)return ww();const a=.012*Math.max(t,n);let i=Cw(r,a),s=a;for(;i.length>40;)s*=1.6,i=Cw(r,s);return i.length<3?ww():i.map(([e,o])=>({x:Math.min(1,Math.max(0,e/t)),y:Math.min(1,Math.max(0,o/n))}))}function kw(e){const t=e.src,n=xw.get(t);if(n)return n.map(e=>({...e}));const o=function(e){const t=e.naturalWidth||e.width,n=e.naturalHeight||e.height;if(!t||!n)return null;const o=Math.min(1,256/Math.max(t,n)),r=Math.max(1,Math.round(t*o)),a=Math.max(1,Math.round(n*o)),i=document.createElement("canvas");i.width=r,i.height=a;const s=i.getContext("2d",{willReadFrequently:!0});if(!s)return null;let l;s.drawImage(e,0,0,r,a);try{l=s.getImageData(0,0,r,a).data}catch{return null}const c=new Uint8Array(r*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:r,height:a,foreground:d}}(e);if(!o)return ww();const r=Tw(o.mask,o.width,o.height);return xw.set(t,r),r.map(e=>({...e}))}function Pw(e){const{state:t,resetTransactionGrouping:n,applyTransactionalState:o,focusInput:r}=e,a=()=>sv(t())?"image":hx(t())?"textBox":null,i=(e,t)=>{const i=a();i&&(n(),o(e=>t(e,i),{mergeKey:e}),r())},s=(e,n)=>{const r=aa(t().document,n),a=t=>{const n=kw(t);o(t=>function(e,t,n){const o=cr(e);let r=!1;const a=o.map(e=>e.runs.some(e=>e.id===t&&"image"===e.kind)?{...zo(e),runs:e.runs.map(e=>{if(e.id!==t||"image"!==e.kind)return Ea(e);r=!0;const o={...e.image};return n&&n.length>0?o.wrapPolygon=n:delete o.wrapPolygon,{...e,image:o}})}:zo(e));return r?qt(e,a,N(a,mr(e))):e}(t,e,n),{mergeKey:eg})},i=ge(r,()=>{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=sv(e),n=t&&fr(t.run);return n?rv(n.floating):null}(t()):"textBox"===e?function(e){const t=hx(e),n=t&&Ko(t.run);return n?rv(n.floating):null}(t()):null},fixedPosition:()=>{const e=a();return"image"===e?function(e){const t=sv(e),n=t&&fr(t.run);return iv(n?.floating)}(t()):"textBox"===e&&function(e){const t=hx(e),n=t&&Ko(t.run);return iv(n?.floating)}(t())},setPreset:e=>{if(i(Ug,(t,n)=>"image"===n?function(e,t){return yv(e,e=>ov(e,t))}(t,e):function(e,t){return yx(e,e=>ov(e,t))}(t,e)),"tight"===e||"through"===e){const e=sv(t()),n=e&&fr(e.run);n&&!n.wrapPolygon&&s(e.run.id,n.src)}},setFixedPosition:e=>i(jg,(t,n)=>"image"===n?function(e,t){return yv(e,e=>e?av(e,t):e)}(t,e):function(e,t){return yx(e,e=>e?av(e,t):e)}(t,e))}}function Rw(e){return function(e){let t=0;kt()&&yn(()=>{t++});const n=n=>{if(t++,e.onNativeClipboardStart?.(),$u(e.state()))return n.preventDefault(),void(n.clipboardData&&function(e,t){try{const n=Nu(e);return t.setData(Au,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 o=vi(e.state());if(0!==o.length&&(n.preventDefault(),n.clipboardData)){try{n.clipboardData.setData("text/plain",o),n.clipboardData.setData("text/html",Hu(e.state()))}catch{return}e.onNativeClipboardSuccess?.()}},o=n=>{if(t++,e.onNativeClipboardStart?.(),e.isReadOnly())return void n.preventDefault();if($u(e.state()))return n.preventDefault(),void e.onNativeClipboardIssue?.("cut","unsupported");const o=vi(e.state());if(0!==o.length&&(n.preventDefault(),n.clipboardData)){try{n.clipboardData.setData("text/plain",o),n.clipboardData.setData("text/html",Hu(e.state()))}catch{return}e.onNativeClipboardSuccess?.(),e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>Yu(e))),e.focusInput()}},r=n=>{const o=++t;if(e.isReadOnly())return void n.preventDefault();const r=e.consumePasteMode?.(),a=e.clipboardRequestGeneration?.(),i=()=>o!==t||e.clipboardRequestGeneration?.()!==a,s=Array.from(n.clipboardData?.types??[]).filter(Du);if(n.clipboardData&&s.length){n.preventDefault();const t=e.forcePlainTextPaste();e.setForcePlainTextPaste(!1);const o=1===s.length?zu(n.clipboardData.getData(s[0])):void 0,a=e.stateSnapshot?.();return t||r&&"rich"!==r||!o||!a?void e.onNativeClipboardIssue?.("paste","unsupported"):(n.currentTarget.value="",(async()=>{let t;try{t=await Ou(a,o)}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(o=>i()||e.isReadOnly()||o!==a?o:(n=!0,t)),n?(e.onNativeClipboardSuccess?.(),e.focusInput()):e.onNativeClipboardIssue?.("paste","document-changed")})())}if(e.forcePlainTextPaste()||"text"===r){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=>Gu(e,t))),n.currentTarget.value="",void e.focusInput())}const l="merge"!==r?tv(n.clipboardData):null;if(l)return n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping(),e.insertImageFromFile(l),n.currentTarget.value="",void e.focusInput();const c=dp(n.clipboardData?.getData("text/html")??""),d="merge"===r?cp(e.state(),c):c;if(d.length>0)return n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>Wu(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=>Gu(e,u))),n.currentTarget.value="",e.focusInput())},a=n=>{if(t++,e.onNativeClipboardStart?.(),e.isReadOnly())return void n.preventDefault();const o=tv(n.dataTransfer);if(!o)return;n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping();const r=e.resolvePositionAtSurfacePoint(n.clientX,n.clientY)??e.state().selection.focus;e.insertImageFromFile(o,r),e.focusInput()};return{handleCopy:n,handleCut:o,handlePaste:r,handleDrop:a}}(e)}var Bw=/* @__PURE__ */new WeakMap;function Mw(e,t){return function(e){return ei(e.document).flatMap(e=>[...e.header??[],...e.blocks,...e.footer??[]])}(e).find(e=>"table"===e.type&&e.id===t)??null}function Ow(e,t,n,o,r){const a=o.getCanvasLayoutSnapshot({surface:e,state:t,documentLayout:n,zoomFactor:r});if(!a)return[];const i=Bw.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 o=n.get(t);o||(o={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,o),s.set(e.tableId,n));const r=d.lines.flatMap(e=>e.slots.map(e=>e.left)),a=d.lines.map(e=>e.top+e.height),i=r.length>0?Math.min(...r):d.left,c=r.length>0?Math.max(...r):d.left,u=d.lines.length>0?d.lines[0].top:d.top,p=a.length>0?Math.max(...a):d.top+d.height,g=`${e.tableId}:${d.pageIndex}:${e.rowIndex}:${e.cellIndex}`,f=l.get(g);f?(f.left=Math.min(f.left,i),f.top=Math.min(f.top,u),f.right=Math.max(f.right,c),f.bottom=Math.max(f.bottom,p)):l.set(g,{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)),o=Math.max(...e.map(e=>e.right)),r=Math.max(...e.map(e=>e.bottom));c.push({tableId:d,cells:e,bounds:{left:t,top:n,right:o,bottom:r,width:Math.max(1,o-t),height:Math.max(1,r-n)}})}return Bw.set(a,c),c}function Aw(e,t,n,o,r,a){const i=Ow(t,n,o,r,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,o=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 o=Math.abs(e.clientX-t.right);o<=4&&(!s||o<s.distance)&&(s={geometry:d,cell:t,side:"right",distance:o})}if(o){const n=Math.abs(e.clientY-t.top);n<=4&&(!s||n<s.distance)&&(s={geometry:d,cell:t,side:"top",distance:n});const o=Math.abs(e.clientY-t.bottom);o<=4&&(!s||o<s.distance)&&(s={geometry:d,cell:t,side:"bottom",distance:o})}}if(!s)return null;const l=Mw(n,s.geometry.tableId);if(!l)return null;const c=Or(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 Fw=1/.75;function Dw(e){return.75*e}function Ew(e){return e*Fw}var Lw=zf;function Nw(e){return("number"==typeof e.style?.padding&&Number.isFinite(e.style.padding)?2*Math.max(0,Ew(e.style.padding)):Math.max(0,(void 0!==e.style?.paddingLeft?Ew(e.style.paddingLeft):7.2)+(void 0!==e.style?.paddingRight?Ew(e.style.paddingRight):7.2)))+(e.style?.borderLeft?Math.max(0,Ew(e.style.borderLeft.width)):1)+(e.style?.borderRight?Math.max(0,Ew(e.style.borderRight.width)):1)}function zw(e,t,n){const o=Math.max(1,e.rows.length),r=n.bounds.height/o,a=Array(o).fill(r),i=new Map(n.cells.map(e=>[`${e.rowIndex}:${e.cellIndex}`,e]));for(let s=0;s<o;s+=1){const n=Lw(e.rows[s]?.style?.height);if(null!==n){a[s]=Math.max(1,Ew(n));continue}const o=t.find(e=>e.rowIndex===s&&1===e.rowSpan);if(o){const e=i.get(`${o.rowIndex}:${o.cellIndex}`);e&&(a[s]=Math.max(1,e.height))}}return a}function $w(e,t,n){const o=Math.max(1,...t.map(e=>e.visualColumnIndex+Math.max(1,e.colSpan))),r=o-1,a=Array(o).fill(n.bounds.width/o),i=new Map(n.cells.map(e=>[`${e.rowIndex}:${e.cellIndex}`,e]));if(e.gridCols&&e.gridCols.length>=o)for(let l=0;l<o;l+=1)a[l]=Math.max(1,Ew(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<o;l+=1)s[l]=Math.max(10,Dw(a[l]));return{widthsPt:s,maxColumnIndex:r}}function Hw(e,t,n){if("row"!==t.type)return e;const o=t.initialRowHeightPx??Ew(10),r=Math.max(Ew(10),t.minRowHeightPx??Ew(10)),a=Math.max(10,Dw(Math.max(r,o+n)));return function(e,t,n,o){return Nf(e,t,{[n]:o})}(e,t.tableId,t.index,a)}function Ww(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 Uw=null;function jw(e,t){Uw=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 Vw(e){e&&Uw!==e||(Uw=null,document.body.classList.remove("oasis-editor-hover-col-resize"),document.body.classList.remove("oasis-editor-hover-row-resize"))}function Kw(e,t){jw(e,t)}function _w(e){return"undefined"!=typeof window&&"function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(e):globalThis.setTimeout(e,16)}function Xw(e){"undefined"==typeof window||"function"!=typeof window.cancelAnimationFrame?globalThis.clearTimeout(e):window.cancelAnimationFrame(e)}function Gw(e){const[t,n]=co(null);let o=null,r=null,a=null,i=null;const s={},l=()=>{o=null;const n=r;if(r=null,!n||t())return;const a=e.surfaceRef();if(!a)return void Vw();const i=Aw(n,a,e.state(),e.documentLayout(),e.canvasSnapshotProvider,e.zoomFactor?.());i?jw("left"===i.side||"right"===i.side,s):Vw()},c=nw(),d=e=>{c.owns(e)&&t()&&(i={clientX:e.clientX,clientY:e.clientY},null===a&&(a=_w(u)))},u=()=>{a=null;const o=i;i=null;const r=t();o&&r&&n({...r,currentPos:"column"===r.type?o.clientX:o.clientY,guideBounds:Ww(e.viewportRef)})},p=()=>{r=null,i=null,null!==o&&(Xw(o),o=null),null!==a&&(Xw(a),a=null),n(null),Vw(s),c.release(),window.removeEventListener("pointermove",d),window.removeEventListener("pointerup",g),window.removeEventListener("pointercancel",g)},g=n=>{if(!c.owns(n))return;const o=t();if(!o)return;const r=e.zoomFactor?.()??1,a=(("column"===o.type?n.clientX:n.clientY)-o.initialPos)/r;Math.abs(a)>=2&&e.applyTransactionalState(e=>"row"===o.type?Hw(e,o,a):function(e,t,n){if("column"!==t.type)return e;const o=Dw(n),r=t.maxColumnIndex??t.index,a={...t.columnWidthsPt??{}};for(let m=0;m<=r;m+=1)void 0===a[m]&&(a[m]=10);const i=t.minColumnWidthsPx??{},s=a[t.index]??10,l=Math.max(10,Dw(i[t.index]??Ew(10)));if(t.resizeFromLeftEdge){const n=Math.max(0,t.initialTableIndentLeftPt??0);let r=Math.max(l,s-o),i=s-r;n+i<0&&(i=-n,r=s-i),a[t.index]=r;const c=Object.values(a).reduce((e,t)=>e+t,0),d=Math.max(0,n+i);return $f(e,t.tableId,a,c,d)}let c=Math.max(l,s+o);const d=t.index===r;if(d)a[t.index]=c;else{const e=t.index+1,n=a[e]??10,o=Math.max(10,Dw(i[e]??Ew(10)));let r=n-(c-s);r<o&&(r=o,c=s+(n-o),c=Math.max(l,c)),a[t.index]=c,a[e]=r}const u=Object.values(a).reduce((e,t)=>e+t,0),p=Mw(e,t.tableId),g=Lw(p?.style?.width),f=d?u:null!==g?g:void 0;return $f(e,t.tableId,a,f)}(e,o,a)),p()};return{resizing:t,handlePointerMove:e=>{c.owns(e)&&(t()||(r={clientX:e.clientX,clientY:e.clientY},null===o&&(o=_w(l))))},handlePointerDown:t=>{r=null,null!==o&&(Xw(o),o=null),Vw();const a=e.surfaceRef();if(!a)return!1;const i=Aw(t,a,e.state(),e.documentLayout(),e.canvasSnapshotProvider,e.zoomFactor?.());if(!i)return!1;const l=e.state(),u=Or(i.tableNode);if("left"===i.side||"right"===i.side){const o="left"===i.side&&0===i.layoutEntry.visualColumnIndex,r=o?0:"left"===i.side?i.layoutEntry.visualColumnIndex-1:i.layoutEntry.visualColumnIndex+i.layoutEntry.colSpan-1;if(r<0)return!1;const a="left"===i.side?i.rect.left:i.rect.right,{widthsPt:p,maxColumnIndex:f}=$w(i.tableNode,u,i.tableGeometry),m=function(e,t,n,o){const r=Ew(10),a={},i=new Map(o.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 o=s.visualColumnIndex,l=a[o]??r,c=n.blocks.reduce((t,n)=>"paragraph"!==n.type?t:Math.max(t,nn(n,e.document.styles)),1);a[o]=Math.max(l,c+Nw(n)+12,r)}return a}(l,i.tableNode,u,i.tableGeometry);return n({type:"column",tableId:i.tableId,index:r,initialPos:a,currentPos:a,columnWidthsPt:p,maxColumnIndex:f,minColumnWidthsPx:m,resizeFromLeftEdge:o,initialTableIndentLeftPt:Lw(i.tableNode.style?.indentLeft)??0,guideBounds:Ww(e.viewportRef)}),Kw(!0,s),c.claim(t),window.addEventListener("pointermove",d),window.addEventListener("pointerup",g),window.addEventListener("pointercancel",g),t.preventDefault(),t.stopPropagation(),!0}const p=zw(i.tableNode,u,i.tableGeometry),f="top"===i.side?i.layoutEntry.visualRowIndex-1:i.layoutEntry.visualRowIndex+i.layoutEntry.rowSpan-1;if(f<0||f>=p.length)return!1;const m="top"===i.side?i.rect.top:i.rect.bottom,h=function(e,t,n,o){const r=e.rows[o];if(!r)return Ew(10);const a=Ew(10);let i=a;for(let s=0;s<r.cells.length;s+=1){if(!r.cells[s])continue;const e=t.find(e=>e.rowIndex===o&&e.cellIndex===s);if(!e||1!==e.rowSpan)continue;const a=n.cells.find(e=>e.rowIndex===o&&e.cellIndex===s);a&&(i=Math.max(i,a.contentMinHeight+4))}return Math.max(a,i)}(i.tableNode,u,i.tableGeometry,f);return n({type:"row",tableId:i.tableId,index:f,initialPos:m,currentPos:m,initialRowHeightPx:p[f],minRowHeightPx:h,guideBounds:Ww(e.viewportRef)}),Kw(!1,s),c.claim(t),window.addEventListener("pointermove",d),window.addEventListener("pointerup",g),window.addEventListener("pointercancel",g),t.preventDefault(),t.stopPropagation(),!0},stop:p}}var qw=null;function Yw(e){const t=(e.bounds.width+(e.currentClientX-e.startClientX))/e.bounds.width,n=(e.bounds.height+(e.currentClientY-e.startClientY))/e.bounds.height,o=Object.values(e.widthsPt),r=o.length>0?Math.min(...o):1,a=r>0?10/r:0,i=Ew(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 Zw(e){const[t,n]=co(null);let o=null,r=null;const a={},i=nw(),s=e=>{i.owns(e)&&t()&&(r={clientX:e.clientX,clientY:e.clientY},null===o&&(o=_w(l)))},l=()=>{o=null;const e=r;r=null,e&&n(t=>t?{...t,currentClientX:e.clientX,currentClientY:e.clientY}:null)},c=()=>{r=null,null!==o&&(Xw(o),o=null),n(null),i.release(),window.removeEventListener("pointermove",s),window.removeEventListener("pointerup",d),window.removeEventListener("pointercancel",d),qw===a&&(qw=null,"nwse-resize"===document.body.style.cursor&&(document.body.style.cursor=""))},d=n=>{if(!i.owns(n))return;const o=t();if(o){const t=Math.abs(n.clientX-o.startClientX),r=Math.abs(n.clientY-o.startClientY);if(t>=2||r>=2){const t={...o,currentClientX:n.clientX,currentClientY:n.clientY},{scaleX:r,scaleY:a}=Yw(t);e.applyTransactionalState(e=>function(e,t,n,o){const r={};for(const l of Object.keys(t.widthsPt)){const e=Number(l);r[e]=Math.max(10,t.widthsPt[e]*n)}const a=Object.values(r).reduce((e,t)=>e+t,0),i=$f(e,t.tableId,r,a),s={};return t.rowHeightsPx.forEach((e,t)=>{s[t]=Math.max(10,Dw(e*o))}),Nf(i,t.tableId,s)}(e,t,r,a))}}c()};return{resizing:t,previewRect:()=>{const e=t();if(!e)return null;const{scaleX:n,scaleY:o}=Yw(e);return{left:e.bounds.left,top:e.bounds.top,width:e.bounds.width*n,height:e.bounds.height*o}},handlePointerDown:(t,o)=>{const r=e.surfaceRef();if(!r)return;const l=Ow(r,e.state(),e.documentLayout(),e.canvasSnapshotProvider,e.zoomFactor?.()).find(e=>e.tableId===t),c=Mw(e.state(),t);if(!l||!c)return;const u=Or(c),{widthsPt:p}=$w(c,u,l),g=zw(c,u,l),f=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:o.clientX,startClientY:o.clientY,currentClientX:o.clientX,currentClientY:o.clientY,widthsPt:p,totalWidthPt:f,rowHeightsPx:g}),qw=a,document.body.style.cursor="nwse-resize",i.claim(o),window.addEventListener("pointermove",s),window.addEventListener("pointerup",d),window.addEventListener("pointercancel",d),o.preventDefault(),o.stopPropagation()},stop:c}}var Jw=null;function Qw(e,t,n,o){if(!e)return null;for(const r of e)if("table"===r.type){if(r.id===t)return{table:r,nested:n,movableTopLevelStory:o};for(const e of r.rows)for(const n of e.cells){const e=Qw(n.blocks,t,!0,!1);if(e)return e}}return null}function eS(e,t){for(const n of Pa(e)){for(const e of[n.blocks,n.header,n.footer]){const n=Qw(e,t,!1,!0);if(n)return n}for(const e of[n.firstPageHeader,n.evenPageHeader,n.firstPageFooter,n.evenPageFooter]){const n=Qw(e,t,!1,!1);if(n)return n}}for(const n of Object.values(e.footnotes?.items??{})){const e=Qw(n.blocks,t,!1,!1);if(e)return e}for(const n of Object.values(e.endnotes?.items??{})){const e=Qw(n.blocks,t,!1,!1);if(e)return e}return null}function tS(e){return function(e){const[t,n]=co(!1),[o,r]=co(null),[a,i]=co(null),[s,l]=co(0),[c,d]=co(0),[u,p]=co({x:0,y:0});let g=null,f=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=nw(),v=()=>{f=null,null!==g&&(Xw(g),g=null),n(!1),r(null),i(null),y.release(),window.removeEventListener("pointermove",w),window.removeEventListener("pointerup",I),window.removeEventListener("pointercancel",I),Jw===m&&(Jw=null,"grabbing"===document.body.style.cursor&&(document.body.style.cursor=""))},x=()=>{g=null;const n=f;if(f=null,!n||!t())return;p({x:n.clientX,y:n.clientY});const r=e.resolvePositionAtSurfacePoint(n.clientX,n.clientY),a=o()?.tableId;r&&a&&function(e,t,n){const o=eS(e,n);return Boolean(o?.table&&ta(o.table).some(e=>e.id===t))}(e.state().document,r.paragraphId,a)?b(null):b(r)},w=e=>{if(y.owns(e)){if(!t()){if(Math.abs(e.clientY-s())<=4)return;n(!0),Jw=m,document.body.style.cursor="grabbing"}f={clientX:e.clientX,clientY:e.clientY},null===g&&(g=_w(x))}},I=n=>{if(!y.owns(n))return;const r=o();if(t()){const t=e.resolvePositionAtSurfacePoint(n.clientX,n.clientY),o=r?.tableId;o&&e.applyTransactionalState(e=>{const r=eS(e.document,o),a=r?.table;if(a?.style?.floating){const t=a.style.floating;return Df(e,o,"floating",{...t,x:(t.x??0)+(n.clientX-c())*Ur,y:(t.y??0)+(n.clientY-s())*Ur,xAlign:void 0,yAlign:void 0})}return r&&!r.nested&&r.movableTopLevelStory&&t?S(e,o,t):e})}v(),e.focusInput()};return{dragging:t,draggedTableInfo:o,mousePos:u,dropTargetPos:a,handlePointerDown:(e,t)=>{t.preventDefault(),t.stopPropagation();const o=t.currentTarget.getBoundingClientRect(),a=o;r({tableId:e,width:a.width,height:a.height,offsetX:t.clientX-o.left,offsetY:t.clientY-o.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)}var nS=e=>"touch"===e.pointerType;function oS(e,t){if(!e||0===e.length){const e=ia(t);return{paragraph:e,blocks:[e]}}const n=e[0];return{paragraph:"paragraph"===n.type?n:ta(n)[0]??null,blocks:e}}function rS(e,t,n){const o=ya(e.document).filter(t=>{const o=Ya(e.document,t.id);return null!==o&&o.zone===n}),r=o.findIndex(e=>e.id===t.id),a=r>=0?o[r+1]:void 0;return{start:ci(t,0),end:a?ci(a,0):ci(t,oi(t).length)}}function aS(e){return function(e){let t=null,n=null,o=null,r=0,a=0,i=0,s=0,l=0,c=null,d=0,u=0,p=0,g=null,f=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,o,r)=>{const a=n!==(t.activeZone??"main"),i="footnote"===n&&r?Ya(o.document,r.paragraphId)?.footnoteId:void 0,s="footnote"===n&&i!==t.activeFootnoteId;if(!a&&!s)return void e.applyState(o);let l=o.document,c=t.activeSectionIndex??0;if(!l.sections||0===l.sections.length){const e=ia("header"),t=ia("footer");l={...l,sections:[{id:"section:1",blocks:[],pageSettings:Uo(l.pageSettings??Xo),header:[e],footer:[t]}]},c=0}const d=l.sections,u=d[c];let p=u.header,g=u.footer,f=null;if("header"===n){const e=oS(p,"header");f=e.paragraph,p=e.blocks}else if("footer"===n){const e=oS(g,"footer");f=e.paragraph,g=e.blocks}if(p!==u.header||g!==u.footer){const e=[...d];e[c]={...u,header:p,footer:g},l={...l,sections:e}}const m=r||(f?ci(f,0):o.selection.anchor);e.applyState({...o,document:l,selection:{anchor:m,focus:m},activeSectionIndex:c,activeZone:n,activeFootnoteId:"footnote"===n?i:void 0})},y=t=>{const n=e.state(),o=n.selection,r=nr(n),a=Fa(n.document,o.anchor.paragraphId,r),i=Fa(n.document,o.focus.paragraphId,r),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} ${o.anchor.paragraphId}[${o.anchor.offset}]→${o.focus.paragraphId}[${o.focus.offset}] [${s}→${l}]`)},v=()=>{f?.longPressHandle&&clearTimeout(f.longPressHandle),f=null},x=()=>{t=null,o=null,g=null,v(),null!==n&&(h(n),n=null),window.removeEventListener("pointermove",C),window.removeEventListener("pointerup",T),window.removeEventListener("pointercancel",k)},w=e=>{g=e,window.addEventListener("pointermove",C),window.addEventListener("pointerup",T),window.addEventListener("pointercancel",k)},S=()=>{if(n=null,!t)return;const r=o;if(o=null,!r)return;const a=e.resolveSurfaceHitAtPoint(r.clientX,r.clientY,{forDrag:!0});if(!a?.resolvedFromParagraph)return;const i=e.state();if(Ya(i.document,t.paragraphId)?.sectionIndex!==Ya(i.document,a.paragraphId)?.sectionIndex)return;const s=xi(i,{anchor:t,focus:a.position});b(i,a.zone,s,a.position),y("selection:drag")},I=()=>{o&&(null!==n&&(h(n),n=null),S())},C=e=>{null!==g&&e.pointerId!==g||(!f||f.longPressFired?t&&(o={clientX:e.clientX,clientY:e.clientY},null===n&&(n=m(S))):Math.hypot(e.clientX-f.clientX,e.clientY-f.clientY)>20&&x())},T=t=>{if(null===g||t.pointerId===g){if(f&&!f.longPressFired){const n=f,o=Math.hypot(t.clientX-n.clientX,t.clientY-n.clientY)<=20&&Date.now()-n.startedAt<=500;return v(),x(),void(o&&(D(n.hit,n.clickDetail,t),e.onSelectionFinalized?.()))}I(),y("selection:end"),x(),e.onSelectionFinalized?.(),e.focusInputAfterPointerSelection()}},k=e=>{null!==g&&e.pointerId!==g||x()},P=(n,o,r)=>{if(r<2)return t=null,x(),void e.focusInputAfterPointerSelection();t=null,o.resolvedFromParagraph?b(n,o.zone,{...n,selection:{anchor:{...o.position},focus:{...o.position}}},o.position):b(n,o.zone,n),x(),e.focusInputAfterPointerSelection()},R=(n,o)=>{const r=e.getParagraphById(n.document,o.textBox.paragraphId);if(!r)return void e.focusInputAfterPointerSelection();t=null;const a=ci(r,o.textBox.startOffset),i=ci(r,o.textBox.endOffset);b(n,o.zone,xi(n,{anchor:a,focus:i}),a),x(),e.focusInputAfterPointerSelection()},B=(n,o,r)=>{const a=e.getParagraphById(n.document,o.image.paragraphId);if(!a)return void e.focusInputAfterPointerSelection();t=null;const i=ci(a,o.image.startOffset),s=ci(a,o.image.endOffset);b(n,o.zone,xi(n,{anchor:i,focus:s}),i),x(),nS(r)||e.imageOps.startImageDrag(o.image.paragraphId,o.image.startOffset,r,{left:o.image.left,top:o.image.top,width:o.image.width,height:o.image.height}),e.focusInputAfterPointerSelection()},M=(n,o,r)=>{t=n.selection.anchor,b(n,o.zone,xi(n,{anchor:n.selection.anchor,focus:o.position}),o.position),w(r),e.focusInputAfterPointerSelection()},O=(n,o,r)=>{t=null;const a=rS(n,r,o.zone);b(n,o.zone,xi(n,{anchor:a.start,focus:a.end}),a.start),x(),e.focusInputAfterPointerSelection()},A=(n,o,r)=>{t=null;let a=0;const i=r.runs.find(e=>{const t="math"===e.kind&&o.paragraphOffset>=a&&o.paragraphOffset<=a+e.text.length;return a+=e.text.length,t});if("math"===i?.kind){const t=ci(r,o.paragraphOffset);return b(n,o.zone,xi(n,{anchor:t,focus:t}),t),x(),void e.openEquationDialog(i.math,i.id)}const s=Qn(oi(r),o.paragraphOffset),l=ci(r,s.start),c=ci(r,s.end);b(n,o.zone,xi(n,{anchor:l,focus:c}),l),x(),e.focusInputAfterPointerSelection()},F=(n,o,r,a)=>{if(e.imageOps.stopImageDrag(),e.imageOps.stopImageResize(),e.clearPreferredColumn(),e.resetTransactionGrouping(),!o)return void e.focusInputAfterPointerSelection();if(!nS(a)&&e.textDrag?.tryStartTextDrag(a,o))return t=null,x(),void e.focusInputAfterPointerSelection();const i=e.getParagraphById(n.document,o.paragraphId);o.zone===(n.activeZone??"main")?o.textBox?R(n,o):o.image?B(n,o,a):a.shiftKey&&o.resolvedFromParagraph?M(n,o,a.pointerId):r>=3&&i?O(n,o,i):2===r&&i?A(n,o,i):o.resolvedFromParagraph?(t=o.position,b(n,o.zone,{...n,selection:{anchor:{...o.position},focus:{...o.position}}},o.position),nS(a)||w(a.pointerId),e.focusInputAfterPointerSelection()):e.focusInputAfterPointerSelection():P(n,o,r)},D=(t,n,o)=>{F(e.state(),t,n,o),e.focusInputSync()},E=()=>{const n=f;if(!n)return;n.longPressHandle=null,n.longPressFired=!0;const o=n.hit;if(!o?.resolvedFromParagraph)return;const r=e.state(),a=e.getParagraphById(r.document,o.paragraphId);if(!a)return;const i=Qn(oi(a),o.paragraphOffset),s=ci(a,i.start),l=ci(a,i.end);b(r,o.zone,xi(r,{anchor:s,focus:l}),s),t=s,e.focusInputSync()},L=t=>{if(0!==t.button)return;const n=Date.now(),o=Math.hypot(t.clientX-i,t.clientY-s);r=n-a<=450&&o<=((e,t)=>nS(e)?20:t)(t,6)&&t.button===l?r+1:1,a=n,i=t.clientX,s=t.clientY,l=t.button;const g=Math.max(t.detail,r),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,nS(t))return v(),f={pointerId:t.pointerId,clientX:t.clientX,clientY:t.clientY,startedAt:n,hit:h,clickDetail:g,longPressHandle:setTimeout(E,500),longPressFired:!1},void w(t.pointerId);t.preventDefault(),F(m,h,g,t)},N=n=>{if(n.detail<3)return;n.preventDefault();const o=e.state(),r=Math.hypot(n.clientX-u,n.clientY-p),a=Date.now()-d<=600&&r<=8?c:e.resolveSurfaceHitAtPoint(n.clientX,n.clientY);if(!a?.resolvedFromParagraph)return void e.focusInputAfterPointerSelection();const i=e.getParagraphById(o.document,a.paragraphId);if(!i)return void e.focusInputAfterPointerSelection();t=null;const s=rS(o,i,a.zone);b(o,a.zone,xi(o,{anchor:s.start,focus:s.end}),s.start),x(),e.focusInputAfterPointerSelection()},z=(e,t)=>{0===t.button&&(nS(t)||t.preventDefault(),L(t))};return{handleSurfacePointerDown:L,handleSurfaceClick:N,handleSurfaceDblClick:e=>{e.preventDefault()},handleParagraphPointerDown:z,stopDragging:x}}(e)}function iS(e){return function(e){const[o,r]=co(!1);let a,i=0,s="",l=null;const d=()=>{i=0,s="",a=void 0},u=(n,o)=>{if(!o&&n===s)return;if(0===i&&0===n.length)return void(o&&d());const r=i,u=oa(a);e.clearPreferredColumn(),e.applyTransactionalState(o=>e.applyTableAwareParagraphEdit(o,e=>{const o=function(e,n){if(n<=0)return e;const{paragraph:o,index:r,offset:a}=oe(e);if(a<n)return e;const i=cr(e),s=a-n;if(M(e,o,s,a))return e;const l=c(o,t(o)?so(o,s,a,()=>null):[...on(o,0,s),...on(o,a,Xr(o))],qn(o,s)),d=i.map((e,t)=>t===r?l:e);return qt(e,d,Y(ci(l,s)))}(e,r);return n.length>0?_u(o,n,u):o}),{mergeKey:Hp}),o?(d(),l=n.length>0?n:null):(i=n.length,s=n)},p=t=>{if(n("input:text"),e.isReadOnly())return e.logger.debug(`input:readonly ignored value=${JSON.stringify(t.currentTarget.value)}`),t.currentTarget.value="",void d();const r=t.currentTarget.value;if(0===r.length)return;if(o())return e.logger.debug(`input:composing buffer=${JSON.stringify(r)}`),void u(r,!1);if(null!==l){const n=r===l;if(l=null,n)return e.logger.debug(`input:suppressed text=${JSON.stringify(r)}`),void(t.currentTarget.value="")}const a=e.state(),i=a.selection,s=cr(a).find(e=>e.id===i.anchor.paragraphId)?.runs.find(e=>e.id===i.anchor.runId),c=s?{bold:s.styles?.bold,italic:s.styles?.italic,underline:s.styles?.underline}:null;e.logger.info(`input:text ${JSON.stringify(r)} (len=${r.length}) at ${i.anchor.paragraphId}:${i.anchor.runId}[${i.anchor.offset}] run:${JSON.stringify(c)}`),e.clearPreferredColumn();const p=oa(e.pendingCaretTextStyle());e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>_u(e,r,p)),{mergeKey:$p}),t.currentTarget.value="",e.focusInput(),be("input:text")},g=()=>{e.logger.debug("input:composition start"),d(),l=null,a=oa(e.pendingCaretTextStyle()),r(!0)},f=t=>{e.isReadOnly()||u(t.data??"",!1)},m=t=>{if(r(!1),e.isReadOnly())return t.currentTarget.value="",void d();const n=t.data??t.currentTarget.value,o=e.state().selection;e.logger.info(`input:composition end ${JSON.stringify(n)} (len=${n.length}) at ${o.anchor.paragraphId}:${o.anchor.runId}[${o.anchor.offset}]`),u(n,!0),t.currentTarget.value="",e.focusInput()};return{handleTextInput:p,handleCompositionStart:g,handleCompositionUpdate:f,handleCompositionEnd:m,composing:o}}(e)}var sS="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 lS(e,t){const n=mr(e);if(n.isCollapsed)return!1;const o=cr(e),r=o.findIndex(e=>e.id===t.paragraphId);if(r<n.startIndex||r>n.endIndex)return!1;const a=o[r];if(!a)return!1;const i=Br(a,t);return!(r===n.startIndex&&i<n.startParagraphOffset)&&!(r===n.endIndex&&i>n.endParagraphOffset)}function cS(e,t,n,o,r,a){if(n.zone===pr(e))return r(e,e=>Ku(e,t,{copy:o}));if(o||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,o=pr(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"!==o&&"header"!==o&&"footer"!==o)throw Error("Unsupported source zone");if(o===t.zone||"main"!==o&&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 r=Ii(e,e=>"opaque"===e.kind);if(!r||"opaque"!==r.run.kind||"inline"!==r.run.opaque.placement||r.run.revision||r.run.sdtWrappers?.length)throw Error("Select exactly one unwrapped inline opaque object");const a=Qa(n,o),i=Qa(n,t.zone),s=r.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=ka(n,c,i),u=e.document.sections[0],p="main"===o?u.blocks:u[o],g="main"===t.zone?u.blocks:u[t.zone];if(!p?.some(e=>"paragraph"===e.type&&e.id===r.paragraph.id)||!g?.some(e=>"paragraph"===e.type&&e.id===t.paragraphId))throw Error("Only top-level paragraphs of existing stories are supported");const f={...e,activeSectionIndex:0,activeZone:t.zone,activeHeaderFooterStory:"default"},m=cr(f).find(e=>e.id===t.paragraphId);if(!m||!Number.isInteger(t.offset)||t.offset<0||t.offset>Xr(m))throw Error("Invalid destination offset");const h={...ee(e),activeZone:t.zone,activeSectionIndex:0,activeHeaderFooterStory:"default"},b=cr(h),y=b.find(e=>e.id===t.paragraphId);if(!y)throw Error("Destination unavailable after deletion");const v=Ea(r.run);if("opaque"!==v.kind)throw Error("Invalid cloned object");const x=xe(y,t.offset,[{...v,opaque:d.destinationRun}]),w=qt(h,b.map(e=>e.id===x.id?x:e),{anchor:ci(x,t.offset),focus:ci(x,t.offset+1)});return{...w,document:{...w.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 dS(e){return function(e){const[t,n]=co(!1),[o,r]=co(null),[a,i]=co(!1),[s,l]=co(null),[c,d]=co(null);let u=null,p=null,g=null,f=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: ${sS} !important; }`,document.head.appendChild(p))},b=nw(),y=()=>{e.logger?.info("text-drag:stop",{dragging:t(),dropTarget:o()?`${o().paragraphId}:${o().runId}[${o().offset}]`:null,copyMode:a()}),u=null,g=null,f=null,n(!1),r(null),i(!1),l(null),d(null),m(),b.release(),window.removeEventListener("pointermove",v),window.removeEventListener("pointerup",x),window.removeEventListener("pointercancel",x)},v=o=>{if(!b.owns(o))return;if(!u)return;const a=o.ctrlKey||o.metaKey;if(i(a),!t()){const t=Math.abs(o.clientX-u.x),r=Math.abs(o.clientY-u.y);if(t+r<4)return;e.logger?.info("text-drag:activate",{start:u,at:{x:o.clientX,y:o.clientY},deltaX:t,deltaY:r}),n(!0),h()}l({x:o.clientX,y:o.clientY});const s=e.resolveSurfaceHitAtPoint(o.clientX,o.clientY,{forDrag:!0});if(f=s?.resolvedFromParagraph?s:null,!s?.resolvedFromParagraph)return e.logger?.debug("text-drag:hit-miss",{x:o.clientX,y:o.clientY}),r(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!==g&&(e.logger?.info("text-drag:target",{x:o.clientX,y:o.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"}),g=p),r(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:o()?`${o().paragraphId}:${o().runId}[${o().offset}]`:null}),"pointercancel"!==n.type){if(t()&&o()&&f){const t=o(),r=n.ctrlKey||n.metaKey,a=f;e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(n=>cS(n,t,a,r,e.applyTableAwareParagraphEdit,t=>e.logger?.warn?.("text-drag:relocation-rejected",t)),{mergeKey:r?dg:ug}),e.logger?.info("text-drag:apply",{mode:r?"copy":"move",destination:`${t.paragraphId}:${t.runId}[${t.offset}]`})}else if(u){const t=u.position,n=e.state(),o=lS(r=n,i=t)?xi(r,{anchor:i,focus:i}):r;o!==n&&e.applyState(o),e.logger?.info("text-drag:collapse",{at:`${t.paragraphId}:${t.runId}[${t.offset}]`})}var r,i;y(),e.focusInputAfterPointerSelection()}else y()},w=(t,o)=>e.isReadOnly()||!o?.resolvedFromParagraph?(e.logger?.debug("text-drag:skip-start",{reason:e.isReadOnly()?"readonly":"no-hit",x:t.clientX,y:t.clientY}),!1):lS(e.state(),o.position)?(e.logger?.info("text-drag:start-pending",{x:t.clientX,y:t.clientY,hit:`${o.position.paragraphId}:${o.position.runId}[${o.position.offset}]`,zone:o.zone}),u={x:t.clientX,y:t.clientY,position:o.position},l({x:t.clientX,y:t.clientY}),i(t.ctrlKey||t.metaKey),r(null),f=null,d(o.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:`${o.position.paragraphId}:${o.position.runId}[${o.position.offset}]`}),!1);return{dragging:t,dropTargetPos:o,copyMode:a,pointerPos:s,caretViewport:c,tryStartTextDrag:w,stopDrag:y}}(e)}function uS(e){return e.blocks.flatMap(ta)}function pS(e,t){if(!e)return;const n=uS(e);return"start"===t?n[0]:n[n.length-1]}function gS(e){return function(e){const t=(t,n)=>{const o=e.state(),r=cr(o).find(e=>e.id===o.selection.focus.paragraphId);if(!r)return!1;const a="start"===t?0:oi(r).length,i=ci(r,a);return e.clearPreferredColumn(),e.applyState(xi(o,{anchor:n?o.selection.anchor:i,focus:i})),!0},n=(t,n)=>{const o=e.state(),r=cr(o);if(0===r.length)return!1;const a="start"===t?r[0]:r[r.length-1],i="start"===t?0:oi(a).length,s=ci(a,i);return e.clearPreferredColumn(),e.applyState(xi(o,{anchor:n?o.selection.anchor:s,focus:s})),!0},o=(t,n)=>{const o=e.state(),r=cr(o),a=r.findIndex(e=>e.id===o.selection.focus.paragraphId),i=r[a];if(!i)return!1;const s=oi(i),l=Br(i,o.selection.focus),c=s.length;if(!n&&!sr(o.selection))return e.clearPreferredColumn(),e.applyState("left"===t?wi(o):Si(o)),!0;let d=i,u=l;"left"===t?0===l&&a>0?(d=r[a-1],u=oi(d).length):u=On(s,l):l===c&&a<r.length-1?(d=r[a+1],u=0):u=pt(s,l);const p=ci(d,u);return e.clearPreferredColumn(),e.applyState(xi(o,{anchor:n?o.selection.anchor:p,focus:p})),!0},r=e=>a(e,!1),a=(t,n)=>{const o=e.state(),r=cr(o),a=r.findIndex(e=>e.id===o.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:o,documentLayout:e.documentLayout(),zoomFactor:e.zoomFactor?.()}):null;let u=a+t;const p=Va(o.document,o.selection.focus.paragraphId,nr(o)),g=p?.tablePath[p.tablePath.length-1];if(p&&g){const e=Ox(o,p.zone),n=Xa(e,p.tablePath),a=n?.[n.length-1]?.table;if(a){const e=Or(a),n=e.find(e=>e.rowIndex===g.rowIndex&&e.cellIndex===g.cellIndex);if(n){const o=[];for(let e=n.visualRowIndex+t;e>=0&&e<a.rows.length;e+=t)o.push(e);for(const n of o){const o=e.filter(e=>e.visualRowIndex===n&&uS(e.cell).length>0&&"continue"!==e.cell.vMerge);if(0===o.length)continue;const i=o.map(e=>{const t=pS(e.cell,"start")?.id,n=t?d?.paragraphs.find(e=>e.paragraphId===t&&e.tableCell&&e.tableCell.tableId===a.id)?.tableCell:null,o=n?.left??c,r=n?n.left+n.width:c;return{entry:e,distance:c<o?o-c:c>r?c-r:0}}).sort((e,t)=>e.distance-t.distance)[0]?.entry;if(!i)continue;const s=pS(i.cell,t<0?"end":"start");u=s?r.findIndex(e=>e.id===s.id):-1;break}}else if(t<0){const e=pS(a.rows[0]?.cells[0],"start");e&&(u=r.findIndex(t=>t.id===e.id)-1)}else{const e=a.rows[a.rows.length-1],t=e?.cells[e.cells.length-1],n=pS(t,"end");n&&(u=r.findIndex(e=>e.id===n.id)+1)}}}if(u<0||u>=r.length)return!1;const f=r[u];let m=0;const h=d?j(d,f.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(Br(f,o.selection.focus),oi(f).length);return e.setPreferredColumnX(c),e.resetTransactionGrouping(),e.applyTransactionalState(e=>xi(e,{anchor:n?e.selection.anchor:ci(f,m),focus:ci(f,m)})),e.focusInput(),!0},i=()=>{const t=e.state();if(!sr(t.selection))return!1;const n=e.surfaceRef(),o=e.caretBox();if(!n||!o.visible)return!1;const r=cr(t).find(e=>e.id===t.selection.focus.paragraphId);if(!r)return!1;const a=Br(r,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 o=e.filter(e=>e.startOffset<=t&&e.endOffset>=t&&n>=e.top-.5&&n<e.top+e.height-.5);return 1===o.length&&o[0].startOffset===t}(j(i,r.id).flatMap(e=>e.lines),a,o.top+i.surfaceRect.top+Math.min(1,o.height/2))};return{isCaretAtWrappedLineStart:i,moveSelectionToParagraphBoundary:t,moveSelectionToDocumentBoundary:n,moveSelectionByWord:o,moveVerticalByBlock:r,moveVerticalSelection:a}}(e)}function fS(e){return function(e){const[t,n]=co(null),o=(t,o)=>{const r=cr(e.state());let a;for(const e of r){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 Pa(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=o.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:o,handleRevisionMouseLeave:()=>{n(null)}}}(e)}function mS(e){const t=cr(e);if(!t.length)return null;const n=mr(e,t),o=t[n.startIndex];if(!o)return null;const r=(n.isCollapsed?[]:on(o,n.startParagraphOffset,n.startIndex===n.endIndex?n.endParagraphOffset:Xr(o))).find(e=>"text"===e.kind&&e.text.length>0),a=function(e){const t=oa(e);if(t)return delete t.link,delete t.propertyRevision,Object.keys(t).length>0?t:void 0}(Oa(r?r.styles:qn(o,n.startParagraphOffset),o.style?.styleId,e.document.styles)),i=n.isCollapsed||0===n.startParagraphOffset&&(n.endIndex>n.startIndex||n.endParagraphOffset===Xr(o));return{text:a,paragraph:i?qa(o.style):void 0,list:i&&o.list?{...o.list}:void 0,copyParagraph:i}}function hS(e,t){const n=cr(e);if(!n.length)return e;const o=mr(e,n);if(o.isCollapsed)return e;let r=!1;const a=n.map((e,n)=>{if(n<o.startIndex||n>o.endIndex)return e;const a=n===o.startIndex?o.startParagraphOffset:0,i=n===o.endIndex?o.endParagraphOffset:Xr(e),s=t.copyParagraph&&function(e,t,n){return(t>n.startIndex||0===n.startParagraphOffset)&&(t<n.endIndex||n.endParagraphOffset===Xr(e))}(e,n,o),l=s?qa(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&&on(e,a,i).some(e=>{if("text"!==e.kind||0===e.text.length)return!1;const n=oa(t.text)??{};void 0!==e.styles?.link&&(n.link=e.styles.link),void 0!==e.styles?.propertyRevision&&(n.propertyRevision=e.styles.propertyRevision);const o=Object.keys(n).length?n:void 0;return!pa(e.styles,o)});if(!d&&!u)return e;r=!0;let p=u?pe(e,a,i,e=>{if("text"!==e.kind)return e;const n=oa(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 r?qt(e,a,N(a,o)):e}function bS(e){const t=cr(e);if(!t.length)return"";const n=mr(e,t);return[e.activeSectionIndex??0,e.activeZone??"main",n.start.paragraphId,n.startParagraphOffset,n.end.paragraphId,n.endParagraphOffset].join(":")}function yS(e){const[t,n]=co(null);let o=null,r=null,a="";const i=()=>{o=null,r=null,a="",n(null)};kt()&&(Zn(()=>{t()&&(e.isReadOnly()||e.state().document!==r)&&i()}),yn(i));const s=()=>!e.isReadOnly()&&cr(e.state()).length>0,l=t=>{if(!s())return!1;const i=e.state(),l=mS(i);return!!l&&(o=l,r=i.document,a=bS(i),n(t),e.focusInput(),!0)};return{mode:t,canCapture:s,armOnce:()=>l("once"),armContinuous:()=>l("continuous"),cancel:i,applyToSelection:n=>{if(!o||!t())return!1;if(e.isReadOnly()||e.state().document!==r)return i(),!1;const s=e.state();if(bS(s)===a)return!1;const l=function(e,t){const n=cr(e);if(0===n.length)return null;const o=mr(e,n);if(!o.isCollapsed)return e;if(!t)return null;const r=n[o.startIndex];if(!r)return null;const a=Qn(oi(r),o.startParagraphOffset);return a.end<=a.start?null:{...e,selection:{anchor:ci(r,a.start),focus:ci(r,a.end)}}}(s,"pointer"===n);if(!l)return!1;e.clearPreferredColumn(),e.resetTransactionGrouping();let c=!1;return dt(()=>{e.applyTransactionalState(t=>{if(e.isReadOnly()||t.document!==r)return t;const n=e.applyTableAwareParagraphEdit({...t,selection:l.selection},e=>hS(e,o));return c=n.document!==t.document,n}),"once"===t()?i():c&&(r=e.state().document)}),c&&e.focusInput(),c}}}function vS(e){return function(e){const{state:t,logger:n,isReadOnly:o,applyState:r,cloneState:a,focusInput:i,focusInputAfterPointerSelection:s,focusInputSync:l,surfaceRef:c,viewportRef:d,zoomFactor:u,insertImageFromFile:p,getForcePlainTextPaste:g,setForcePlainTextPaste:f,getCommandsController:m,applyTransactionalState:h,clearPreferredColumn:b,resetTransactionGrouping:y,updateHistoryState:v,caretBox:x,preferredColumnX:w,setPreferredColumnX:S,documentLayout:I,canvasSnapshotProvider:C}=e,T=()=>sv(t),k=()=>hx(t),P=Pw({state:()=>t,resetTransactionGrouping:y,applyTransactionalState:h,focusInput:i}),R=yw({state:()=>t,surfaceRef:()=>c()??null,viewportRef:()=>d()??null,documentLayout:I,canvasSnapshotProvider:C,zoomFactor:u}).resolveSurfaceHitAtPoint,B=function(e){const[t,n]=co(""),[o,r]=co(""),[a,i]=co({matchCase:!1,wholeWord:!1}),[s,l]=co([]),[c,d]=co(-1),[u,p]=co(!1);Zn(En([()=>e.state.document,t,a],([e,t,n])=>{const o=uw(e,t,n);l(o),0===o.length?d(-1):(c()>=o.length||-1===c())&&d(0)}));const g=t=>{const n=s()[t];n&&e.applyState(xi(e.state,{anchor:n.anchor,focus:n.focus}))};return{searchTerm:t,setSearchTerm:n,replaceTerm:o,setReplaceTerm:r,findOptions:a,setFindOptions:i,matches:s,currentIndex:c,findNext:()=>{const e=s().length;if(0===e)return;const t=(c()+1)%e;d(t),g(t)},findPrevious:()=>{const e=s().length;if(0===e)return;const t=(c()-1+e)%e;d(t),g(t)},replace:()=>{if(0===s().length||-1===c())return;const t=s()[c()];e.applyTransactionalState(e=>_u(xi(e,{anchor:t.anchor,focus:t.focus}),o()),{mergeKey:ag})},replaceAll:()=>{const n=t();0!==n.length&&(e.applyTransactionalState(e=>pw(e,n,o(),a()),{mergeKey:ig}),p(!1),e.focusInput())},isOpen:u,setIsOpen:p}}({state:t,applyState:r,applyTransactionalState:h,focusInput:i}),M=tw({applyTransactionalState:h,applySelectionToStatePreservingStructure:(e,t)=>({...e,document:Zt(e).document,selection:t}),focusInput:i,logger:n}),O=yS({state:()=>t,isReadOnly:o,applyTransactionalState:h,applyTableAwareParagraphEdit:M.applyTableAwareParagraphEdit,clearPreferredColumn:b,resetTransactionGrouping:y,focusInput:i}),A=(e,t)=>R(e,t)?.position??null,F=lw({state:t,surfaceRef:c,resolvePositionAtSurfacePoint:A,applyState:r,applyTransactionalState:h,updateHistoryState:v,focusInput:i,focusInputAfterPointerSelection:s,cloneState:a,logger:n,zoomFactor:u}),D=cw({state:t,surfaceRef:c,applyState:r,updateHistoryState:v,focusInput:i,cloneState:a,logger:n,zoomFactor:u}),E=dw({state:()=>t,commandsController:m,clearPreferredColumn:b,resetTransactionGrouping:y,focusInput:i,logger:n}),L=function(e){const t=()=>e.state,n=Gw({state:t,applyTransactionalState:e.applyTransactionalState,surfaceRef:e.surfaceRef,viewportRef:e.viewportRef,zoomFactor:e.zoomFactor,documentLayout:e.documentLayout,canvasSnapshotProvider:e.canvasSnapshotProvider}),o=Zw({state:t,applyTransactionalState:e.applyTransactionalState,surfaceRef:e.surfaceRef,zoomFactor:e.zoomFactor,documentLayout:e.documentLayout,canvasSnapshotProvider:e.canvasSnapshotProvider}),r=tS({state:t,applyTransactionalState:e.applyTransactionalState,resolvePositionAtSurfacePoint:e.resolvePositionAtSurfacePoint,focusInput:e.focusInput}),a=fS({state:t,surfaceRef:()=>e.surfaceRef()??null,zoomFactor:e.zoomFactor}),i=dS({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=aS({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,resolveSurfaceHitAtPoint:e.resolveSurfaceHitAtPoint,getParagraphById:Na,textDrag:{tryStartTextDrag:i.tryStartTextDrag},logger:e.logger,openEquationDialog:e.openEquationDialog}),l=iS({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=gS({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:g}=Rw({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:o,tableDrag:r,revisionController:a,textDrag:i,surfaceEvents:s,textInput:l,navigation:c,handleCopy:d,handleCut:u,handlePaste:p,handleDrop:g}}({state:t,getStateSnapshot:e.getStateSnapshot,applyState:r,applyTransactionalState:h,isReadOnly:o,logger:n,focusInput:i,focusInputAfterPointerSelection:s,focusInputSync:l,clearPreferredColumn:b,resetTransactionGrouping:y,surfaceRef:c,viewportRef:d,caretBox:()=>x(),preferredColumnX:()=>w(),setPreferredColumnX:S,zoomFactor:u,documentLayout:I,canvasSnapshotProvider:C,resolveSurfaceHitAtPoint:R,resolvePositionAtSurfacePoint:A,tableOps:M,imageOps:F,styleController:E,formatPainter:O,getForcePlainTextPaste:g,setForcePlainTextPaste:f,clipboardActions:e.clipboardActions,insertImageFromFile:p,openEquationDialog:e.openEquationDialog}),N=e=>{0===e.button&&(E.clearPendingCaretTextStyle(),e.preventDefault(),i())};return{selectedImageRun:T,selectedTextBoxRun:k,layoutOptionsOverlay:P,fr:B,resolveSurfaceHitAtPoint:R,resolvePositionAtSurfacePoint:A,tableOps:M,imageOps:F,textBoxOps:D,styleController:E,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 xS(e){if("main"!==(e.activeZone??"main"))return e;const t=sr(e.selection)?e:ee(e),{paragraph:n,index:o,offset:r}=oe(t),a=Za(),i=function(e){const t=e.footnotes,n=t?.settings?.numberFormat??"decimal";let o=(t?.settings?.startAt??1)-1;const r=/* @__PURE__ */new Set;for(const{run:a}of ri(e)){const e=ir(a);e&&!e.customMark&&(r.has(e.footnoteId)||(r.add(e.footnoteId),o+=1))}return Gr(o+1,n)}(t.document),s=ti(a.id,i),l=xe(n,r,[s]),c=cr(t).map((e,t)=>t===o?l:e),d=ci(l,r+i.length),u=qt(t,c,Cr(d)),p=function(e){return e||{items:{}}}(u.document.footnotes),g={...u.document,footnotes:{...p,items:{...p.items,[a.id]:a}}},f=gi(g),m=a.blocks.flatMap(ta).find(Boolean);return m?{...u,document:f,selection:Cr(ci(m,0)),activeZone:"footnote",activeFootnoteId:a.id}:{...u,document:f}}function wS(e){if(!e)return;const{propertyRevision:t,...n}=e;return Object.keys(n).length>0?n:void 0}function SS(e,t,n){return e.flatMap(e=>{if("paragraph"===e.type)return[e];let o=e.style;if(o?.revision?.id===t)if(n){const{revision:e,...t}=o;o=t}else o={...o.revision.previous};let r=e.gridCols,a=e.gridRevision;a?.id===t&&(r=n?r:[...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 o=0;o<e.cells.length;o+=1){const r=e.cells[o],a=r.mergeRevisionState;if(a&&a.revisionId===t){if(n){const{mergeRevisionState:t,...n}=r;e.cells[o]=n;continue}"horizontal"===a.orientation?e.cells.splice(o,a.currentCellCount,...a.previousCells):a.previousCells.forEach((e,t)=>{const n=i[l+t];n&&(n.cells[o]=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 o=e.style;if(o?.propertyRevision?.id===t)if(n){const{propertyRevision:e,...t}=o;o=t}else o={...o.propertyRevision.previous,revision:o.revision};if(o?.revision?.id===t){const{revision:e,...t}=o;o=t}const r=e.cells.flatMap(e=>{if(e.style?.revision?.id===t&&(n&&"delete"===e.style.revision.type||!n&&"insert"===e.style.revision.type))return[];let o=e.style;if(o?.propertyRevision?.id===t)if(n){const{propertyRevision:e,...t}=o;o=t}else o={...o.propertyRevision.previous,revision:o.revision};let r={...e,style:o,blocks:SS(e.blocks,t,n)};if(o?.revision?.id===t&&e.mergeRevisionState?.revisionId!==t){const e=o.revision,{revision:t,...a}=o;r={...r,...n||"merge"!==e.type?{}:e.previous,style:a}}return[r]});return[{...e,isHeader:o&&"isHeader"in o?o.isHeader:e.isHeader,style:o,cells:r}]});return 0===s.length?[]:[{...e,style:o,gridCols:r,gridRevision:a,rows:s}]})}function IS(e,t,n){const o=Pa(e.document).map(e=>({...e,blocks:SS(e.blocks,t,n),header:e.header?SS(e.header,t,n):void 0,firstPageHeader:e.firstPageHeader?SS(e.firstPageHeader,t,n):void 0,evenPageHeader:e.evenPageHeader?SS(e.evenPageHeader,t,n):void 0,footer:e.footer?SS(e.footer,t,n):void 0,firstPageFooter:e.firstPageFooter?SS(e.firstPageFooter,t,n):void 0,evenPageFooter:e.evenPageFooter?SS(e.evenPageFooter,t,n):void 0}));return{...e,document:{...e.document,sections:o}}}function CS(e,t,n){const o=Pa(e.document),r=o.findIndex(e=>e.propertyRevision?.id===t);if(-1===r)return e;const a=o[r],i=a.propertyRevision,s=[...o];if(n)s[r]={...a,propertyRevision:void 0};else{const e=structuredClone(i.previous);s[r]={...a,pageSettings:e.pageSettings,pageBorder:e.pageBorder,pageNumbering:e.pageNumbering,verticalAlignment:e.verticalAlignment,bidi:e.bidi,propertyRevision:void 0};const t=s[r+1];t&&(s[r+1]={...t,breakType:e.nextBreakType})}return{...e,document:{...e.document,sections:s}}}function TS(e,t){const n=cr(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:wS(e.styles)}:e});return n.length===e.runs.length&&n.every((t,n)=>t===e.runs[n])?e:c(e,n)});return CS(IS(qt(e,n,N(n,mr(e))),t,!0),t,!0)}function kS(e,t){const n=cr(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:wS(n.previous)}:e});return n.length===e.runs.length&&n.every((t,n)=>t===e.runs[n])?e:c(e,n)});return CS(IS(qt(e,n,N(n,mr(e))),t,!1),t,!1)}function PS(e,t){return"paragraph"===e.type?t.has(e.id):e.rows.some(e=>e.cells.some(e=>e.blocks.some(e=>PS(e,t))))}function RS(e,t,n){for(const o of e)if("paragraph"!==o.type){PS(o,t)&&(o.style?.revision&&n.add(o.style.revision.id),o.gridRevision&&n.add(o.gridRevision.id));for(const e of o.rows){const o=e.cells.filter(e=>e.blocks.some(e=>PS(e,t)));o.length>0&&(e.style?.revision&&n.add(e.style.revision.id),e.style?.propertyRevision&&n.add(e.style.propertyRevision.id));for(const e of o)e.style?.revision&&n.add(e.style.revision.id),e.style?.propertyRevision&&n.add(e.style.propertyRevision.id),RS(e.blocks,t,n)}}}function BS(e){const t=mr(e),n=cr(e),o=/* @__PURE__ */new Set;for(let a=t.startIndex;a<=t.endIndex;a+=1){const e=n[a],r=a===t.startIndex?t.startParagraphOffset:0,i=a===t.endIndex?t.endParagraphOffset:Xr(e),s=on(e,r,i);for(const t of s)t.revision?.id&&o.add(t.revision.id),t.styles?.propertyRevision?.id&&o.add(t.styles.propertyRevision.id)}const r=new Set(n.slice(t.startIndex,t.endIndex+1).map(e=>e.id));for(const a of Pa(e.document))for(const e of[a.blocks,a.header,a.firstPageHeader,a.evenPageHeader,a.footer,a.firstPageFooter,a.evenPageFooter])e&&RS(e,r,o);for(const a of $v(e))a.paragraphIds.some(e=>r.has(e))&&o.add(a.id);return o}function MS(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)},o=e=>{if(e)for(const r of e)if("paragraph"!==r.type){r.style?.revision&&t.add(r.style.revision.id),r.gridRevision&&t.add(r.gridRevision.id);for(const e of r.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),o(n.blocks)}}else n(r.runs)};for(const i of Pa(e.document))i.propertyRevision&&t.add(i.propertyRevision.id),o(i.blocks),o(i.header),o(i.firstPageHeader),o(i.evenPageHeader),o(i.footer),o(i.firstPageFooter),o(i.evenPageFooter);const r=e.document.footnotes?.items??{};for(const i of Object.values(r))o(i.blocks);const a=e.document.endnotes?.items??{};for(const i of Object.values(a))o(i.blocks);return t}function OS(e){return MS(e).size>0}function AS(e,t){if(!OS(e))return e;const n=Ht(e.document,t);if(!n.changed)return e;const o=cr({...e,document:n.document}),r=N(o,mr(e));return{...e,document:n.document,selection:r}}function FS(e){const t=mr(e),n=cr(e);if(t.isCollapsed){const e=n[t.startIndex];return e?Pn(e,t.startParagraphOffset)?.href??null:null}const o=n.slice(t.startIndex,t.endIndex+1).flatMap((e,n)=>{const o=t.startIndex+n,r=o===t.startIndex?t.startParagraphOffset:0,a=o===t.endIndex?t.endParagraphOffset:Xr(e);return on(e,r,a)}).filter(e=>e.text.length>0&&"image"!==e.kind);if(0===o.length)return null;const r=o[0]?.styles?.link;return r&&o.every(e=>e.styles?.link===r)?r:null}function DS(e){const t=mr(e),n=cr(e).map((e,n)=>{if(n<t.startIndex||n>t.endIndex)return zo(e);if(!e.list)return zo(e);const o=e.list.level??0;return o<=0?Ne(e):D(e,o-1)});return qt(e,n,N(n,t))}function ES(e){return function(e){const{state:t,logger:n,applyState:o,applyTransactionalState:r,applySelectionAwareTextCommand:i,applySelectionAwareParagraphCommand:s,applyTableAwareParagraphEdit:l,focusInput:d,clearPreferredColumn:u,resetTransactionGrouping:p,toolbarStyleState:g,selectionCollapsed:f,selectedImageRun:m}=e,h=e=>{u(),p(),o(e),d()},y=e=>{u(),p(),i(e),d()},v=e=>{u(),p(),s(e),d()},x=(e,t)=>{u(),p(),r(e,t),d()},w=()=>{const e=mr(t);return cr(t).slice(e.startIndex,e.endIndex+1)},S=()=>w().some(e=>Boolean(e.list)),I=()=>{const e=t.selection.focus.paragraphId;return cr(t).find(t=>t.id===e)??null},C=()=>{const e=I();return!!e?.list&&(u(),p(),f()&&0===oi(e).length?s(e=>function(e){const t=mr(e),n=cr(e).map((e,n)=>n<t.startIndex||n>t.endIndex?zo(e):Ne(e));return qt(e,n,N(n,t))}(e)):r(e=>l(e,e=>function(e){if(me(e))return e;const t=sr(e.selection)?e:ee(e),{paragraph:n,index:o,offset:r}=oe(t);if(me(t))return e;const{beforeRuns:a,afterRuns:i}=Eo(n,r),s=c(n,a,qn(n,r)),l=i.length>0?c(He(n,[]),i):(()=>{const e=Ka("");return e.style=n.style?{...n.style}:void 0,e.list=ca(n.list),e})(),d=cr(t),u=[...Ja(d.slice(0,o)),s,l,...Ja(d.slice(o+1))];return qt(t,u,Y(ci(l,0)))}(e)),{mergeKey:Vp}),d(),!0)},T=()=>{const e=t.selection,n=nr(t),o=Fa(t.document,e.anchor.paragraphId,n),r=Fa(t.document,e.focus.paragraphId,n);return o&&r&&o.blockIndex===r.blockIndex?` [table b${o.blockIndex} r${o.rowIndex}:c${o.cellIndex}→r${r.rowIndex}:c${r.cellIndex}]`:""},k=e=>{if(f())return;const o=t.selection;n.info(`toggleStyle:${e} at ${o.anchor.paragraphId}:${o.anchor.runId}[${o.anchor.offset}..${o.focus.offset}]${T()}`),y(t=>Qu(t,e))},R=e=>{f()||y(t=>function(e,t){const n=mr(e);if(n.isCollapsed||K(e))return e;const o=cr(e).map((o,r)=>{if(r<n.startIndex||r>n.endIndex)return o;const a=r===n.startIndex?n.startParagraphOffset:0,i=r===n.endIndex?n.endParagraphOffset:Xr(o);return P(e,o,a,i,n=>{let r=sa(Ju(e,o,n.styles,"underline",null!==t),"underlineStyle","single"===t?null:t);return"single"!==t&&null!==t||!Oa(r,o.style?.styleId,e.document.styles).underlineStyle||(r={...r,underlineStyle:t}),{...n,styles:r}})});return qt(e,o,N(o,n))}(t,e))},B=(e,o)=>{if(f())return;const r=t.selection;n.info(`setStyle:${e}=${JSON.stringify(o)} at ${r.anchor.paragraphId}:${r.anchor.runId}[${r.anchor.offset}..${r.focus.offset}]${T()}`),y(t=>ep(t,e,o))},M=(e,t)=>{v(n=>se(n,e,t))},O=e=>{const t=!g()[e];M(e,"widowControl"===e?t:!!t||null)},A=()=>{x(e=>l(e,e=>xo(e)))},F=()=>"main"===(t.activeZone??"main"),E=()=>{F()&&x(e=>xS(e))},L=e=>{const n=FS(t);f()&&!n||x(t=>function(e,t){const n=mr(e);if(!n.isCollapsed)return ep(e,"link",t);const o=cr(e)[n.startIndex];if(!o)return e;const r=Pn(o,n.startParagraphOffset);if(!r)return e;const a=ep(xi(e,{anchor:ci(o,r.startOffset),focus:ci(o,r.endOffset)}),"link",t),i=cr(a)[n.startIndex];return i?{...a,selection:{anchor:ci(i,r.startOffset),focus:ci(i,r.endOffset)}}:a}(t,e),{mergeKey:Kp})},z=()=>{const n=FS(t)??"";f()&&!n||e.openLinkDialog(n)},$=()=>e.openFontDialog(),H=t=>e.openParagraphDialog(t),W=()=>{L(null)},U=()=>{const t=m();if(!t)return;const n=fr(t.run)?.alt??"";e.openImageAltDialog(n)},j=t=>{m()&&x(n=>function(e,t,n){const o=sv(e);if(!o||!fr(o.run))return e;const r=cr(e),a=o.paragraphIndex+1,i=a<r.length&&Ma(r[a]),s=i?_r(r[a],t,n):ra(t,n,1);if(i&&s===r[a])return e;const l=a<r.length&&Ma(r[a])?[...Ja(r.slice(0,a)),s,...Ja(r.slice(a+1))]:[...Ja(r.slice(0,a)),s,...Ja(r.slice(a))],c=ha(l,e.document.styles),d=c[a]??s;return qt(e,c,Y(ci(d,da(d))))}(n,t,e.imageCaptionLabel()),{mergeKey:Xp})},V=()=>{m()&&e.openImageCaptionDialog(function(e){const t=sv(e);if(!t||!fr(t.run))return null;const n=cr(e);return Ha(n[t.paragraphIndex+1])}(t)??"")};return{applyBooleanStyleCommand:k,applyToggleCharacterBorderCommand:()=>{f()||y(e=>function(e){const t=mr(e);if(t.isCollapsed||K(e))return e;const n=cr(e),o=n.slice(t.startIndex,t.endIndex+1).flatMap((e,n)=>{const o=t.startIndex+n,r=o===t.startIndex?t.startParagraphOffset:0,a=o===t.endIndex?t.endParagraphOffset:Xr(e);return on(e,r,a)}).filter(e=>e.text.length>0);if(0===o.length)return e;const r=!o.every(e=>Boolean(e.styles?.textBorder)),a=n.map((n,o)=>{if(o<t.startIndex||o>t.endIndex)return n;const a=o===t.startIndex?t.startParagraphOffset:0,i=o===t.endIndex?t.endParagraphOffset:Xr(n);return P(e,n,a,i,e=>({...e,styles:op(e.styles,r)}))});return qt(e,a,N(a,t))}(e))},applyValueStyleCommand:B,applyUnderlineStyleCommand:R,applyChangeTextCaseCommand:e=>{f()||y(t=>ip(t,e))},applyClearFormattingCommand:()=>{f()||y(e=>function(e){const t=mr(e);if(t.isCollapsed||K(e))return e;const n=cr(e).map((n,o)=>{if(o<t.startIndex||o>t.endIndex)return n;const r=o===t.startIndex?t.startParagraphOffset:0,a=o===t.endIndex?t.endParagraphOffset:Xr(n);return P(e,n,r,a,e=>{const t=e.styles?.link,n=null!=t&&""!==t?{link:t}:{};return{...e,styles:n}})});return qt(e,n,N(n,t))}(e))},applyParagraphStyleCommand:M,toggleParagraphFlagCommand:O,applyParagraphListCommand:e=>{v(t=>function(e,t){const n=mr(e),o=cr(e),r=n.startIndex,a=n.endIndex,i=o.slice(r,a+1),s=i.length>0&&i.every(e=>e.list?.kind===t),l=o.map((e,n)=>{if(n<r||n>a)return zo(e);const o=zo(e);return s?(delete o.list,o):(o.list={kind:t,level:e.list?.level??0,format:e.list?.format,startAt:e.list?.startAt},o)});return qt(e,l,N(l,n))}(t,e))},handleListFormatChange:e=>{v(t=>function(e,t){const n=mr(e),o=cr(e).map((e,o)=>o<n.startIndex||o>n.endIndex?zo(e):e.list?{...zo(e),list:{...e.list,format:t||void 0}}:zo(e));return qt(e,o,N(o,n))}(t,e))},handleListStartAtChange:e=>{v(t=>function(e,t){const n=mr(e),o=cr(e).map((e,o)=>o<n.startIndex||o>n.endIndex?zo(e):e.list?{...zo(e),list:{...e.list,startAt:null!==t?t:void 0}}:zo(e));return qt(e,o,N(o,n))}(t,e))},applyInsertSectionBreakCommand:e=>{h(Be(t,e))},applyInsertPageBreakCommand:A,canInsertFootnoteCommand:F,applyInsertFootnoteCommand:E,handleStyleChange:e=>{v(t=>b(t,e||null))},applyUpdateSectionSettingsCommand:(e,n)=>{h(a(t,e,n))},applyToggleTrackChangesCommand:()=>{h(function(e){return{...e,trackChangesEnabled:!e.trackChangesEnabled}}(t))},applyToggleRevisionMarkupCommand:()=>{h(function(e){return{...e,showRevisionMarkup:!(e.showRevisionMarkup??!0)}}(t))},applySetReviewDisplayModeCommand:e=>{h(function(e,t){return(e.reviewDisplayMode??"all")===(t??"all")?e:{...e,reviewDisplayMode:t}}(t,e))},applyShowMarkupCommand:e=>{h(Uv(t,e))},applyToggleShowMarginsCommand:()=>{o({...t,showMargins:!t.showMargins}),d()},applyToggleShowParagraphMarksCommand:()=>{o({...t,showParagraphMarks:!t.showParagraphMarks}),d()},applyAcceptRevisionsCommand:()=>{x(e=>function(e){let t=e;for(const n of BS(e))t=TS(t,n);return t}(e))},applyRejectRevisionsCommand:()=>{x(e=>function(e){let t=e;for(const n of BS(e))t=kS(t,n);return t}(e))},applyAcceptAllRevisionsCommand:()=>{x(e=>function(e){return AS(e,"accept")}(e))},applyRejectAllRevisionsCommand:()=>{x(e=>function(e){return AS(e,"reject")}(e))},applyLinkCommand:L,promptForLink:z,openFontDialog:$,openParagraphDialog:H,openStylesDialog:()=>{n.warn("stylesDialog not yet implemented")},openPageSetupDialog:()=>{n.warn("pageSetupDialog not yet implemented")},removeLinkCommand:W,applyImageAltCommand:e=>{m()&&x(t=>function(e,t){return bv(e,e=>({...e,alt:t??void 0}))}(t,e),{mergeKey:_p})},promptForImageAlt:U,applyImageCaptionCommand:j,promptForImageCaption:V,applyImageWidthCmCommand:e=>{!m()||!Number.isFinite(e)||e<=0||x(t=>function(e,t){const n=sv(e),o=n&&fr(n.run);if(!o||!Number.isFinite(t)||t<=0)return e;const r=Math.max(24,Math.round(t*$r));return lv(e,r,r*(o.height/o.width))}(t,e),{mergeKey:Gp})},applyImageHeightCmCommand:e=>{!m()||!Number.isFinite(e)||e<=0||x(t=>function(e,t){const n=sv(e),o=n&&fr(n.run);if(!o||!Number.isFinite(t)||t<=0)return e;const r=Math.max(24,Math.round(t*$r));return lv(e,r*(o.width/o.height),r)}(t,e),{mergeKey:Gp})},applyImageCropAspectCommand:e=>{if(!m())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 o=Number(n[0]),r=Number(n[1]);return!Number.isFinite(o)||!Number.isFinite(r)||o<=0||r<=0?null:o/r}(e);null!==t&&x(e=>"reset"===t?gv(e):uv(e,t),{mergeKey:qp})},applyImageCropShapeCommand:e=>{m()&&x(t=>function(e,t){const n=t?.trim();return bv(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:qp})},applyImageCropFillCommand:()=>{m()&&x(e=>function(e){const t=sv(e),n=t&&fr(t.run);return n?bv(dv(e,{crop:pv(n)}),e=>({...e,cropFit:"fill"})):e}(e),{mergeKey:qp})},applyImageCropFitCommand:()=>{m()&&x(e=>function(e){return bv(e,e=>{const t={...e,cropFit:"fit"};return delete t.crop,t})}(e),{mergeKey:qp})},resetImageCropCommand:()=>{m()&&x(e=>gv(e),{mergeKey:qp})},applyImageBorderCommand:e=>{m()&&x(t=>function(e,t){return bv(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=>{m()&&x(t=>hv(t,e),{mergeKey:Yp})},rotateImageCommand:e=>{m()&&x(t=>mv(t,e),{mergeKey:Zp})},applyImageTransparencyCommand:e=>{m()&&x(t=>function(e,t){return null===sv(e)?e:bv(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:Jp})},resetImageCommand:()=>{m()&&x(e=>function(e){return null===sv(e)?e:bv(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:Qp})},handleListTab:e=>!Fa(t.document,t.selection.focus.paragraphId,nr(t))&&(!!S()&&(v(t=>"indent"===e?function(e){const t=mr(e),n=cr(e).map((e,n)=>n<t.startIndex||n>t.endIndex?zo(e):e.list?D(e,(e.list.level??0)+1):zo(e));return qt(e,n,N(n,t))}(t):DS(t)),!0)),handleListEnter:C,handleListBoundaryBackspace:e=>{const n=I();return!(!n?.list||!f())&&(0===Br(n,t.selection.focus)&&(u(),p(),s(e=>DS(e)),e.currentTarget.value="",d(),!0))}}}(e)}function LS(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 NS(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 zS(e){return function(e){const t=ES({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:()=>sr(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:LS(e.toolbarStyleState())})},openParagraphDialog:t=>{e.setParagraphDialog({isOpen:!0,initial:{...NS(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 $S(e){return()=>{e.isDirty()?e.requestConfirmation():e.resetDocument()}}function HS(e){const t=e.document.settings?.defaultTabStop;return("number"==typeof t&&Number.isFinite(t)&&t>0?t:36)*Kr}function WS(e,t){const n=cr(e);if(!n.length)return e;const o=mr(e,n),r=HS(e);let a=!1;const i=n.map((n,i)=>{if(i<o.startIndex||i>o.endIndex)return n;if(n.list){const e=n.list.level??0,o=Math.max(0,Math.min(8,e+t));return o===e?n:(a=!0,D(n,o))}const s=Wa(n.style,e.document.styles).indentLeft??0;if(t<0&&s<=0)return n;const l=t<0?Math.max(0,s-r):s+r;return l!==s&&Number.isFinite(l)?(a=!0,{...n,style:{...n.style,indentLeft:l}}):n});return a?qt(e,i,e.selection):e}function US(e,t){const n=cr(e);if(!n.length)return e;const o=mr(e,n);if(!o.isCollapsed||0!==o.startParagraphOffset)return e;const r=n[o.startIndex];if(!r||r.list)return e;const a=Wa(r.style,e.document.styles),i=a.indentFirstLine??0,s=a.indentHanging??0;if(t>0&&(0!==i||0!==s))return WS(e,1);if(t<0&&i<=0)return e;const l=t>0?HS(e):Math.max(0,i-HS(e)),c=n.map((e,t)=>t===o.startIndex?{...e,style:{...e.style,indentFirstLine:l,indentHanging:0}}:e);return qt(e,c,e.selection)}function jS(e){const t=cr(e);if(!t.length)return null;const n=mr(e,t);if(!n.isCollapsed||0!==n.startParagraphOffset)return null;const o=t[n.startIndex];if(!o||o.list)return null;const r=Wa(o.style,e.document.styles);return(r.indentLeft??0)>0?"paragraph":(r.indentFirstLine??0)>0&&(r.indentHanging??0)<=0?"firstLine":null}function VS(e){const t=jS(e);return"paragraph"===t?WS(e,-1):"firstLine"===t?US(e,-1):e}var KS=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 o=e.ctrlKey||e.metaKey,r=e.key.toLowerCase();for(const a of this.bindings.values())if(a.key.toLowerCase()===r&&Boolean(a.ctrlOrMeta)===o&&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}},_S=[{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=cr(t);if(0===n.length)return!1;const o=n[0],r=n[n.length-1];return e.clearPreferredColumn(),e.applyState(xi(t,{anchor:ci(o,0),focus:ci(r,oi(r).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=>xo(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=>_u(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=>Xu(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=>ln(e))),e.focusInput()),!0)}];function XS(e){return function(e){const t=new KS;_S.forEach(e=>t.register(e));const n=n=>{if(n.defaultPrevented)return;const o=e.state();if(e.isReadOnly()){const e=n.key,t=e.toLowerCase(),o="Tab"===e||"ArrowLeft"===e||"ArrowRight"===e||"ArrowUp"===e||"ArrowDown"===e||"Home"===e||"End"===e||"PageUp"===e||"PageDown"===e,r="Shift"===e||"Control"===e||"Meta"===e||"Alt"===e,a=(n.ctrlKey||n.metaKey)&&("a"===t||"c"===t);return void(o||r||a||n.preventDefault())}if(n.isComposing||229===n.keyCode)return;const r=e.executeCommand?{executeCommand:(t,n)=>e.executeCommand?.(t,n),canExecuteCommand:(t,n)=>e.canExecuteCommand?.(t,n)}:void 0;if(!t.execute(n,e,r)){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(),!sr(o.selection))return e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>Yu(e))),n.currentTarget.value="",void e.focusInput();const t=cr(o),r=t[t.findIndex(e=>e.id===o.selection.focus.paragraphId)];if(!r)return n.currentTarget.value="",void e.focusInput();if("Backspace"===n.key&&r.list&&0===Br(r,o.selection.focus))return e.applySelectionAwareParagraphCommand(e=>DS(e)),n.currentTarget.value="",void e.focusInput();const a=Br(r,o.selection.focus),i=oi(r),s="Backspace"===n.key?On(i,a):pt(i,a);return"Backspace"===n.key?0===a||s===a?e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>Yu(e))):e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(xi(t,{anchor:ci(r,s),focus:ci(r,a)}),e=>Yu(e))):a>=i.length?e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>Zu(e))):s>a?e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(xi(t,{anchor:ci(r,a),focus:ci(r,s)}),e=>Yu(e))):e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>Zu(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||!jS(o)?(n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>Yu(e))),n.currentTarget.value="",void e.focusInput()):(n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping(),!1!==e.canExecuteCommand?.("outdent")&&e.applySelectionAwareParagraphCommand(VS),n.currentTarget.value="",void e.focusInput());case"Delete":return n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping(),e.applyTransactionalState(t=>e.applyTableAwareParagraphEdit(t,e=>Zu(e))),n.currentTarget.value="",void e.focusInput();case"Tab":return void function(e,t,n){const o=t.selection.focus.paragraphId,r=Ya(t.document,o),a=!!r&&Boolean(Va(t.document,o,r.sectionIndex)),i=cr(t);if(!i.length)return;const s=mr(t,i),l=i[s.startIndex];if(!l)return;const c=!s.isCollapsed&&(s.startIndex!==s.endIndex||0===s.startParagraphOffset&&s.endParagraphOffset===Xr(l)),d=Wa(l.style,t.document.styles),u=s.isCollapsed&&0===s.startParagraphOffset&&!l.list,p=e.autoTabIndentEnabled?.()??!0,g=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&&oi(l).length>0,reverseFirstLineIndent:n.shiftKey&&p&&u&&(d.indentLeft??0)<=0&&(d.indentFirstLine??0)>0});if("passThrough"!==g){switch(n.preventDefault(),e.clearPreferredColumn(),e.resetTransactionGrouping(),g){case"insertLiteralTab":{const t=oa(e.pendingCaretTextStyle?.());e.applyTransactionalState(n=>e.applyTableAwareParagraphEdit(n,e=>_u(e,"\t",t)));break}case"navigateCell":{const r=n.shiftKey?-1:1,a=e.resolveTableTabTarget?.(t.document,o,r);if("adjacent"===a?.kind)e.applySelectionPreservingStructure(a.selection);else if("afterLast"===a?.kind&&1===r&&e.appendTableRowForTab&&!1!==e.canExecuteCommand?.("tableInsertRowAfter"))e.applyTransactionalState(e.appendTableRowForTab);else if(!a){const n=e.resolveAdjacentTableCellPosition(t.document,o,r);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"===g?US(e,n.shiftKey?-1:1):WS(e,n.shiftKey?-1:1));break}}n.currentTarget.value="",e.focusInput()}}(e,o,n);case"ArrowLeft":return n.preventDefault(),e.resetTransactionGrouping(),n.shiftKey?(e.clearPreferredColumn(),e.applyState(bi(o,-1))):(e.clearPreferredColumn(),e.applyState(wi(o))),void e.focusInput();case"ArrowRight":return n.preventDefault(),e.resetTransactionGrouping(),n.shiftKey?(e.clearPreferredColumn(),e.applyState(function(e){return bi(e,1)}(o))):(e.clearPreferredColumn(),e.applyState(Si(o))),void e.focusInput();case"ArrowUp":return n.preventDefault(),e.resetTransactionGrouping(),void(n.shiftKey?e.moveVerticalSelection(-1,!0)||(e.applyState(function(e){return yi(e,-1)}(o)),e.focusInput()):e.moveVerticalByBlock(-1)||(e.applyState(function(e){return hi(e,-1)}(o)),e.focusInput()));case"ArrowDown":return n.preventDefault(),e.resetTransactionGrouping(),void(n.shiftKey?e.moveVerticalSelection(1,!0)||(e.applyState(function(e){return yi(e,1)}(o)),e.focusInput()):e.moveVerticalByBlock(1)||(e.applyState(function(e){return hi(e,1)}(o)),e.focusInput()));default:return}}};return{handleKeyDown:n,registry:t}}(e)}var GS=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown","Escape"];var qS={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"}},YS={oasis:{color:"#0f766e",heading:"#115e59"},office:{color:"#4472c4",heading:"#2f5597"},monochrome:{color:"#374151",heading:"#111827"},warm:{color:"#c2410c",heading:"#9a3412"}},ZS={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 JS(e,t){const n={...e.document.design??{},...t};return{...e,document:{...e.document,design:n}}}function QS(e,t){return function(e,t){const n=qS[t],o=e.document.styles??{},r=Object.fromEntries(Object.entries(o).map(([e,t])=>{if(!/^(normal|title|subtitle|heading[1-9]|quote|intensequote)$/i.test(e))return[e,t];const o=/^heading[1-9]$/i.test(e)||/title|quote/i.test(e);return[e,{...t,textStyle:{...t.textStyle??{},color:o?n.heading:n.body,...o?{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:r}}}(e,t)}function eI(e){return null==e||""===e?null:!0===e||"true"===e||1===e}function tI(e){return null==e||""===e?null:"string"==typeof e?e:String(e)}function nI(e){return null!=e&&""!==e?Number(e):null}function oI({gate:e,style:t,selection:n,history:o,formatting:r,dialog:a,link:i,command:s,valueCommand:l,actionCommand:c}){const d=t.state;return{selectAll:s("selectAll",r.selectAll),selectWord:s("selectWord",r.selectWord),selectSentence:s("selectSentence",r.selectSentence),selectParagraph:s("selectParagraph",r.selectParagraph),selectCollapse:c("selectCollapse",e=>{const t=e??{};r.selectCollapse(Boolean(t.end))}),selectText:l("selectText",e=>{const t=e??{};return r.selectText(t.text??"",null==t.occurrence?1:Number(t.occurrence))},()=>""),selectRange:c("selectRange",e=>{const t=e??{};t.anchor&&t.focus&&r.selectRange(t.anchor,t.focus)}),insertFootnote:s("insertFootnote",r.insertFootnote),setNoteOptions:c("setNoteOptions",e=>{const t=e??{},n="endnote"===t.kind?"endnote":"footnote";r.setNoteOptions({kind:n,...void 0!==t.numberFormat?{numberFormat:t.numberFormat}:{},...void 0!==t.startAt?{startAt:nI(t.startAt)}:{},...void 0!==t.restart?{restart:t.restart}:{}})},()=>({value:r.getNoteOptions("footnote")})),insertTableOfContents:s("insertTableOfContents",r.insertTableOfContents),updateTableOfContents:s("updateTableOfContents",r.updateTableOfContents,()=>({isEnabled:e.isCommandEnabled("updateTableOfContents")&&r.hasTableOfContents()})),insertText:c("insertText",e=>{const t="object"==typeof e&&null!==e&&"text"in e?e:{text:e};r.insertText(String(t.text??""),"string"==typeof t.fontFamily?t.fontFamily:null)}),insertEquation:c("insertEquation",e=>{r.insertEquation(e)}),updateEquation:c("updateEquation",e=>{const t=e;r.updateEquation(t.runId,t.expression)}),pastePlainText:s("pastePlainText",r.pastePlainText),formatPainter:s("formatPainter",r.formatPainterOnce,()=>({isEnabled:e.isCommandEnabled("formatPainter")&&r.canCaptureFormatPainter(),isActive:null!==r.formatPainterMode()})),formatPainterContinuous:s("formatPainterContinuous",r.formatPainterContinuous,()=>({isEnabled:e.isCommandEnabled("formatPainterContinuous")&&r.canCaptureFormatPainter(),isActive:"continuous"===r.formatPainterMode()})),cancelFormatPainter:s("cancelFormatPainter",r.cancelFormatPainter,()=>({isEnabled:null!==r.formatPainterMode()})),bold:s("bold",r.bold,()=>({isActive:Boolean(d().bold)})),italic:s("italic",r.italic,()=>({isActive:Boolean(d().italic)})),underline:s("underline",r.underline,()=>({isActive:Boolean(d().underline)})),doubleUnderline:s("doubleUnderline",r.doubleUnderline,()=>({isActive:"double"===d().underlineStyle})),wordUnderline:s("wordUnderline",r.wordUnderline,()=>({isActive:"words"===d().underlineStyle})),strike:s("strike",r.strike,()=>({isActive:Boolean(d().strike)})),doubleStrike:s("doubleStrike",r.doubleStrike,()=>({isActive:Boolean(d().doubleStrike)})),smallCaps:s("smallCaps",r.smallCaps,()=>({isActive:Boolean(d().smallCaps)})),allCaps:s("allCaps",r.allCaps,()=>({isActive:Boolean(d().allCaps)})),hidden:s("hidden",r.hidden,()=>({isActive:Boolean(d().hidden)})),noProof:s("noProof",r.noProof,()=>({isActive:Boolean(d().noProof)})),webHidden:s("webHidden",r.webHidden,()=>({isActive:Boolean(d().webHidden)})),specVanish:s("specVanish",r.specVanish,()=>({isActive:Boolean(d().specVanish)})),contextualAlternates:s("contextualAlternates",r.contextualAlternates,()=>({isActive:Boolean(d().contextualAlternates)})),characterBorder:s("characterBorder",r.toggleCharacterBorder,()=>({isActive:Boolean(d().characterBorder)})),shadow:s("shadow",r.shadow,()=>({isActive:Boolean(d().shadow)})),emboss:s("emboss",r.emboss,()=>({isActive:Boolean(d().emboss)})),engrave:s("engrave",r.engrave,()=>({isActive:Boolean(d().imprint)})),outline:s("outline",r.outline,()=>({isActive:Boolean(d().outline)})),superscript:s("superscript",r.superscript,()=>({isActive:Boolean(d().superscript)})),subscript:s("subscript",r.subscript,()=>({isActive:Boolean(d().subscript)})),link:s("link",()=>(i.prompt(),!0),()=>({isEnabled:e.isCommandEnabled("link")&&i.canPrompt(),isActive:Boolean(d().link)})),alignLeft:s("alignLeft",r.alignLeft,()=>({isActive:"left"===d().align})),alignCenter:s("alignCenter",r.alignCenter,()=>({isActive:"center"===d().align})),alignRight:s("alignRight",r.alignRight,()=>({isActive:"right"===d().align})),alignJustify:s("alignJustify",r.alignJustify,()=>({isActive:"justify"===d().align})),orderedList:s("orderedList",r.orderedList,()=>({isActive:"ordered"===d().listKind})),bulletList:s("bulletList",r.bulletList,()=>({isActive:"bullet"===d().listKind})),find:s("find",r.find),replace:s("replace",r.replace),replaceAll:c("replaceAll",e=>{const t=e??{};"string"==typeof t.search&&t.search.length>0&&r.replaceAll(t)}),setReviewDisplayMode:l("setReviewDisplayMode",e=>{const t="string"==typeof e?e:e?.mode;return("all"===t||"final"===t||"original"===t||"simple"===t)&&r.setReviewDisplayMode(t)},()=>r.reviewDisplayMode()),toggleTrackChanges:s("toggleTrackChanges",r.toggleTrackChanges,()=>({isActive:r.isTrackChangesEnabled()})),toggleRevisionMarkup:s("toggleRevisionMarkup",r.toggleRevisionMarkup,()=>({isActive:r.areRevisionMarkupVisible()})),showMarkupOptions:l("showMarkupOptions",()=>!1,()=>r.showMarkupOptions()),applyShowMarkup:c("applyShowMarkup",e=>{r.applyShowMarkup(e??{})}),toggleOutlinePanel:s("toggleOutlinePanel",r.toggleOutlinePanel,()=>({isActive:r.areOutlineVisible()})),toggleRevisionsPanel:s("toggleRevisionsPanel",r.toggleRevisionsPanel,()=>({isActive:r.areRevisionsPanelVisible()})),acceptRevisions:s("acceptRevisions",r.acceptRevisions,()=>({isEnabled:e.isCommandEnabled("acceptRevisions")&&r.hasRevisionsInSelection()})),rejectRevisions:s("rejectRevisions",r.rejectRevisions,()=>({isEnabled:e.isCommandEnabled("rejectRevisions")&&r.hasRevisionsInSelection()})),acceptAllRevisions:s("acceptAllRevisions",r.acceptAllRevisions,()=>({isEnabled:e.isCommandEnabled("acceptAllRevisions")&&r.hasRevisionsInDocument()})),rejectAllRevisions:s("rejectAllRevisions",r.rejectAllRevisions,()=>({isEnabled:e.isCommandEnabled("rejectAllRevisions")&&r.hasRevisionsInDocument()})),requestAcceptAllRevisions:s("requestAcceptAllRevisions",()=>(a.requestAcceptAllRevisions(),!0),()=>({isEnabled:e.isCommandEnabled("requestAcceptAllRevisions")&&r.hasRevisionsInDocument()})),requestRejectAllRevisions:s("requestRejectAllRevisions",()=>(a.requestRejectAllRevisions(),!0),()=>({isEnabled:e.isCommandEnabled("requestRejectAllRevisions")&&r.hasRevisionsInDocument()})),nextRevision:s("nextRevision",r.navigateRevisionNext,()=>({isEnabled:e.isCommandEnabled("nextRevision")&&r.hasNavigableRevisions()})),previousRevision:s("previousRevision",r.navigateRevisionPrevious,()=>({isEnabled:e.isCommandEnabled("previousRevision")&&r.hasNavigableRevisions()})),newComment:s("newComment",r.newComment,()=>({isEnabled:e.isCommandEnabled("newComment")&&r.canCreateComment()})),replyComment:s("replyComment",r.replyComment,()=>({isEnabled:e.isCommandEnabled("replyComment")&&r.canReplyToComment()})),toggleCommentsPanel:s("toggleCommentsPanel",r.toggleCommentsPanel,()=>({isEnabled:e.isCommandEnabled("toggleCommentsPanel"),isActive:r.isCommentsPanelOpen()})),editComment:s("editComment",r.editComment,()=>({isEnabled:e.isCommandEnabled("editComment")&&r.canEditComment()})),nextComment:s("nextComment",r.navigateCommentNext,()=>({isEnabled:e.isCommandEnabled("nextComment")&&r.hasNavigableComments()})),previousComment:s("previousComment",r.navigateCommentPrevious,()=>({isEnabled:e.isCommandEnabled("previousComment")&&r.hasNavigableComments()})),resolveComment:s("resolveComment",r.resolveSelectedComment,()=>({isEnabled:e.isCommandEnabled("resolveComment")&&r.canManageSelectedComment()&&!r.isSelectedCommentResolved()})),reopenComment:s("reopenComment",r.reopenSelectedComment,()=>({isEnabled:e.isCommandEnabled("reopenComment")&&r.canManageSelectedComment()&&r.isSelectedCommentResolved()})),deleteComment:s("deleteComment",r.deleteSelectedComment,()=>({isEnabled:e.isCommandEnabled("deleteComment")&&r.canDeleteSelectedComment()})),toggleShowMargins:s("toggleShowMargins",r.toggleShowMargins,()=>({isActive:r.areMarginsVisible()})),toggleShowParagraphMarks:s("toggleShowParagraphMarks",r.toggleShowParagraphMarks,()=>({isActive:r.areParagraphMarksVisible()})),togglePreciseFonts:s("togglePreciseFonts",r.togglePreciseFonts,()=>(m(),{isActive:Pe()})),undo:s("undo",o.undo,()=>({isEnabled:e.isCommandEnabled("undo")&&o.canUndo()})),redo:s("redo",o.redo,()=>({isEnabled:e.isCommandEnabled("redo")&&o.canRedo()})),pageBreak:s("pageBreak",r.pageBreak),lineBreak:s("lineBreak",r.lineBreak),columnBreak:s("columnBreak",r.columnBreak),splitBlock:s("splitBlock",r.splitBlock),insertNonBreakingSpace:s("insertNonBreakingSpace",()=>r.insertSpecialChar("nbsp")),insertNonBreakingHyphen:s("insertNonBreakingHyphen",()=>r.insertSpecialChar("nbHyphen")),insertOptionalHyphen:s("insertOptionalHyphen",()=>r.insertSpecialChar("optionalHyphen")),insertEmDash:s("insertEmDash",()=>r.insertSpecialChar("emDash")),insertEllipsis:s("insertEllipsis",()=>r.insertSpecialChar("ellipsis")),insertCopyright:s("insertCopyright",()=>r.insertSpecialChar("copyright")),insertRegistered:s("insertRegistered",()=>r.insertSpecialChar("registered")),insertTrademark:s("insertTrademark",()=>r.insertSpecialChar("trademark")),setFontFamily:l("setFontFamily",e=>r.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 r.setFontSize(null);if("string"!=typeof t&&"number"!=typeof t)return!1;const n=Yn(t);return null!==n&&r.setFontSize(n)},()=>ct(d().fontSize)),increaseFontSize:s("increaseFontSize",r.increaseFontSize),decreaseFontSize:s("decreaseFontSize",r.decreaseFontSize),growFont1:s("growFont1",r.growFont1),shrinkFont1:s("shrinkFont1",r.shrinkFont1),changeTextCase:c("changeTextCase",e=>{r.changeTextCase(e??"sentence")},()=>({isEnabled:e.isCommandEnabled("changeTextCase")&&!n.isCollapsed()})),clearFormatting:s("clearFormatting",r.clearFormatting),setColor:l("setColor",e=>r.setColor(e??null),()=>d().color||null),setHighlight:l("setHighlight",e=>r.setHighlight(e??null),()=>d().highlight||null),setTextShading:l("setTextShading",e=>r.setTextShading(e??null),()=>d().textShading||null),setStyleId:l("setStyleId",e=>r.setStyleId(String(e)),()=>{const e=d();return e.mixedParagraphStyles?"":e.styleId||"normal"}),setCharacterStyleId:l("setCharacterStyleId",e=>r.setCharacterStyleId(String(e)),()=>d().characterStyleId||""),applyUnderlineStyle:l("applyUnderlineStyle",e=>(r.applyUnderlineStyle(e),!0),()=>d().underlineStyle),setUnderlineStyle:l("setUnderlineStyle",e=>(r.setUnderlineStyle(e||null),!0),()=>d().underlineStyle),setUnderlineColor:l("setUnderlineColor",e=>r.setUnderlineColor(e||null),()=>d().underlineColor),setCharacterScale:l("setCharacterScale",e=>r.setCharacterScale(nI(e)),()=>d().characterScale),setCharacterSpacing:l("setCharacterSpacing",e=>r.setCharacterSpacing(nI(e)),()=>d().characterSpacing),setRunSnapToGrid:l("setRunSnapToGrid",e=>r.setRunSnapToGrid(eI(e)),()=>d().snapToGrid),setFitText:l("setFitText",e=>r.setFitText(nI(e)),()=>d().fitText),setBaselineShift:l("setBaselineShift",e=>r.setBaselineShift(nI(e)),()=>d().baselineShift),setEmphasisMark:l("setEmphasisMark",e=>r.setEmphasisMark(e||null),()=>d().emphasisMark),setTextEffect:l("setTextEffect",e=>r.setTextEffect(e||null),()=>d().textEffect),setKerning:l("setKerning",e=>r.setKerning(nI(e)),()=>d().kerningThreshold),setLigatures:l("setLigatures",e=>r.setLigatures(e||null),()=>d().ligatures),setNumberSpacing:l("setNumberSpacing",e=>r.setNumberSpacing(e||null),()=>d().numberSpacing),setNumberForm:l("setNumberForm",e=>r.setNumberForm(e||null),()=>d().numberForm),setStylisticSet:l("setStylisticSet",e=>r.setStylisticSet(nI(e)),()=>d().stylisticSet)}}function rI({gate:e,style:t,document:n,link:o,image:r,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",()=>o.remove(),()=>({isEnabled:e.isCommandEnabled("unlink")&&Boolean(s().link),isActive:Boolean(s().link)})),editImageAlt:i("editImageAlt",()=>r.promptAlt(),()=>({isEnabled:r.isSelected(),isActive:r.isSelected()})),insertImageCaption:i("insertImageCaption",()=>r.promptCaption(),()=>({isEnabled:r.isSelected(),isActive:r.isSelected()})),imageContext:i("imageContext",()=>{},()=>({isEnabled:r.isSelected(),isActive:r.isSelected(),value:null})),imageWidthCm:i("imageWidthCm",e=>r.setWidthCm(Number(e)),()=>({isEnabled:r.isSelected(),value:r.getSizeCm()?.width??null})),imageHeightCm:i("imageHeightCm",e=>r.setHeightCm(Number(e)),()=>({isEnabled:r.isSelected(),value:r.getSizeCm()?.height??null})),imageCrop:i("imageCrop",()=>r.toggleCrop(),()=>({isEnabled:r.isSelected(),isActive:r.isCropActive()})),imageCropAspect:i("imageCropAspect",e=>r.applyCropAspect(String(e)),()=>({isEnabled:r.isSelected()})),imageCropShape:i("imageCropShape",e=>r.applyCropShape(String(e)),()=>({isEnabled:r.isSelected(),value:r.getCropShape()})),imageCropFill:i("imageCropFill",()=>r.applyCropFill(),()=>({isEnabled:r.isSelected()})),imageCropFit:i("imageCropFit",()=>r.applyCropFit(),()=>({isEnabled:r.isSelected()})),imageCropReset:i("imageCropReset",()=>r.resetCrop(),()=>({isEnabled:r.isSelected()})),imageFlip:i("imageFlip",e=>r.flip(e??"horizontal"),()=>({isEnabled:r.isSelected()})),imageRotate:i("imageRotate",e=>r.rotate(e??"left"),()=>({isEnabled:r.isSelected()})),imageBorder:i("imageBorder",e=>r.setBorder(e),()=>({isEnabled:r.isSelected(),value:r.getBorder()})),imageTransparency:i("imageTransparency",e=>r.setTransparency("number"==typeof e?e:null==e?0:Number(e)),()=>({isEnabled:r.isSelected(),value:r.getTransparency()})),resetImage:i("resetImage",()=>r.reset(),()=>({isEnabled:r.canReset()}))}}function aI({style:e,paragraph:t,section:n,valueCommand:o,actionCommand:r}){const a=e.state;return{outdent:r("outdent",()=>t.outdent()),indent:r("indent",()=>t.indent()),moveParagraphsUp:r("moveParagraphsUp",()=>t.moveParagraphsUp(),()=>({isEnabled:t.canMoveParagraphsUp()})),moveParagraphsDown:r("moveParagraphsDown",()=>t.moveParagraphsDown(),()=>({isEnabled:t.canMoveParagraphsDown()})),togglePageBreakBefore:r("togglePageBreakBefore",()=>t.togglePageBreakBefore(),()=>({isActive:Boolean(a().pageBreakBefore)})),toggleKeepWithNext:r("toggleKeepWithNext",()=>t.toggleKeepWithNext(),()=>({isActive:Boolean(a().keepWithNext)})),toggleKeepLinesTogether:r("toggleKeepLinesTogether",()=>t.toggleKeepLinesTogether(),()=>({isActive:Boolean(a().keepLinesTogether)})),toggleWidowControl:r("toggleWidowControl",()=>t.toggleWidowControl(),()=>({isActive:Boolean(a().widowControl)})),toggleParagraphBidi:r("toggleParagraphBidi",()=>t.setBidi(!a().bidi||null),()=>({isActive:Boolean(a().bidi)})),setParagraphBidi:o("setParagraphBidi",e=>(t.setBidi(eI(e)),!0),()=>a().bidi),setParagraphAlign:o("setParagraphAlign",e=>(t.setParagraphAlign(e),!0),()=>a().align),sortParagraphs:r("sortParagraphs",e=>t.sortParagraphs(!0===e||"true"===e||Boolean(e?.descending))),promote:r("promote",()=>t.promote()),demote:r("demote",()=>t.demote()),resetParagraphFormatting:r("resetParagraphFormatting",()=>t.resetParagraphFormatting()),setOutlineLevel:r("setOutlineLevel",e=>{const n=e??void 0,o=null==n||"body"===n||""===n?null:Number(n);t.setOutlineLevel(null===o||Number.isNaN(o)?null:o)},()=>({value:Number(e.state().outlineLevel)||null})),setParagraphTabStops:r("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:o("setSpacingAfter",e=>(t.setSpacingAfter(nI(e)),!0),()=>a().spacingAfter),setSpacingBefore:o("setSpacingBefore",e=>(t.setSpacingBefore(nI(e)),!0),()=>a().spacingBefore),setContextualSpacing:o("setContextualSpacing",e=>(t.setContextualSpacing(eI(e)),!0),()=>a().contextualSpacing),setLineRule:o("setLineRule",e=>(t.setLineRule(tI(e)),!0),()=>a().lineRule),setTextDirection:o("setTextDirection",e=>(t.setTextDirection(tI(e)),!0),()=>a().textDirection),setSuppressAutoHyphens:o("setSuppressAutoHyphens",e=>(t.setSuppressAutoHyphens(eI(e)),!0),()=>a().suppressAutoHyphens),setSuppressLineNumbers:o("setSuppressLineNumbers",e=>(t.setSuppressLineNumbers(eI(e)),!0),()=>a().suppressLineNumbers),setKinsoku:o("setKinsoku",e=>(t.setKinsoku(eI(e)),!0),()=>a().kinsoku),setOverflowPunct:o("setOverflowPunct",e=>(t.setOverflowPunct(eI(e)),!0),()=>a().overflowPunct),setWordWrap:o("setWordWrap",e=>(t.setWordWrap(eI(e)),!0),()=>a().wordWrap),setAutoSpaceDE:o("setAutoSpaceDE",e=>(t.setAutoSpaceDE(eI(e)),!0),()=>a().autoSpaceDE),setAutoSpaceDN:o("setAutoSpaceDN",e=>(t.setAutoSpaceDN(eI(e)),!0),()=>a().autoSpaceDN),setAdjustRightInd:o("setAdjustRightInd",e=>(t.setAdjustRightInd(eI(e)),!0),()=>a().adjustRightInd),setTopLinePunct:o("setTopLinePunct",e=>(t.setTopLinePunct(eI(e)),!0),()=>a().topLinePunct),setPageBreakBefore:o("setPageBreakBefore",e=>(t.setPageBreakBefore(eI(e)),!0),()=>a().pageBreakBefore),setKeepWithNext:o("setKeepWithNext",e=>(t.setKeepWithNext(eI(e)),!0),()=>a().keepWithNext),setKeepLinesTogether:o("setKeepLinesTogether",e=>(t.setKeepLinesTogether(eI(e)),!0),()=>a().keepLinesTogether),setWidowControl:o("setWidowControl",e=>(t.setWidowControl(eI(e)),!0),()=>a().widowControl),setMirrorIndents:o("setMirrorIndents",e=>(t.setMirrorIndents(eI(e)),!0),()=>a().mirrorIndents),setIndentLeft:o("setIndentLeft",e=>(t.setIndentLeft(nI(e)),!0),()=>a().indentLeft),setIndentRight:o("setIndentRight",e=>(t.setIndentRight(nI(e)),!0),()=>a().indentRight),setIndentFirstLine:o("setIndentFirstLine",e=>(t.setIndentFirstLine(nI(e)),!0),()=>a().indentFirstLine),setIndentHanging:o("setIndentHanging",e=>(t.setIndentHanging(nI(e)),!0),()=>a().indentHanging),setSpecialIndent:r("setSpecialIndent",e=>{const n=e??{};t.setSpecialIndent(n.kind??"none",nI(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:o("setParagraphShading",e=>(t.setShading(e??null),!0),()=>a().shading||"#ffffff"),applyParagraphBorders:r("applyParagraphBorders",()=>t.applyBorders()),applyHorizontalLine:r("applyHorizontalLine",()=>t.addHorizontalLine()),setDropCap:r("setDropCap",e=>{const n=e??{};t.setDropCap(n)},()=>({value:t.hasDropCap()})),setLineHeight:o("setLineHeight",e=>(t.setLineHeight(nI(e)),!0),()=>a().lineHeight),setListFormat:r("setListFormat",e=>t.setListFormat(String(e))),setListStartAt:r("setListStartAt",e=>t.setListStartAt(nI(e))),setListLevel:r("setListLevel",e=>t.setListLevel(nI(e)??0)),toggleOrientation:r("toggleOrientation",()=>n.toggleOrientation(),()=>({isActive:n.isLandscape()})),setOrientation:r("setOrientation",e=>n.setOrientation(e)),sectionBreakNextPage:r("sectionBreakNextPage",()=>n.breakNextPage()),sectionBreakContinuous:r("sectionBreakContinuous",()=>n.breakContinuous()),sectionBreakEvenPage:r("sectionBreakEvenPage",()=>n.breakEvenPage()),sectionBreakOddPage:r("sectionBreakOddPage",()=>n.breakOddPage()),sectionBreakNextColumn:r("sectionBreakNextColumn",()=>n.breakNextColumn()),setPageMargins:r("setPageMargins",e=>{n.setPageMargins(e??{})},()=>({value:n.getMargins()})),setMarginsPreset:r("setMarginsPreset",e=>{"string"==typeof e&&e.length>0&&n.setMarginsPreset(e)}),setSectionPageNumbering:r("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:r("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:r("setPaperSizePreset",e=>{"string"==typeof e&&e.length>0&&n.setPaperSizePreset(e)}),setColumns:r("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:r("setColumnsPreset",e=>{if("string"==typeof e&&e.length>0){const t=_t(e);if(!t)return;n.setColumns({count:t.count})}}),setSectionVerticalAlign:r("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:r("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:r("setSectionBidi",e=>{const t=e??void 0;n.setBidi(t??!0)},()=>({value:n.getBidi()})),setHyphenation:r("setHyphenation",e=>{const t=e??{};n.setHyphenation(t)},()=>({value:n.getHyphenation().value}))}}function iI({gate:e,headerFooter:t,command:n,actionCommand:o}){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:o("exitHeaderFooter",()=>t.exit(),()=>({isEnabled:e.isCommandEnabled("exitHeaderFooter")&&t.isInHeaderFooter()})),setDifferentFirstPage:o("setDifferentFirstPage",e=>{const n=e??void 0;t.setDifferentFirstPage(n??!0)},()=>({value:t.getDifferentFirstPage()})),setDifferentOddEven:o("setDifferentOddEven",e=>{const n=e??void 0;t.setDifferentOddEven(n??!0)},()=>({value:t.getDifferentOddEven()}))}}function sI({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 lI({fields:e,actionCommand:t}){return{updateBodyFields:t("updateBodyFields",()=>{e.updateBodyFields?.()},()=>({isEnabled:!!e.updateBodyFields&&(e.canUpdateBodyFields?.()??!0)})),updateSelectedFields:t("updateSelectedFields",()=>{e.updateSelectedFields?.()},()=>({isEnabled:!!e.updateSelectedFields&&(e.canUpdateBodyFields?.()??!0)})),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 o="PAGEREF"===n.type?"PAGEREF":"REF";e.insertCrossReference({type:o,bookmark:n.bookmark})})}}function cI({gate:e,table:t,actionCommand:n,valueCommand:o}){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(eI(e))),tableSetCellFitText:n("tableSetCellFitText",e=>t.setCellFitText(eI(e))),tableSetRowHeight:n("tableSetRowHeight",e=>t.setActiveTableRowHeight(e??{height:null}),()=>({isEnabled:e.isCommandEnabled("tableSetRowHeight")&&t.canSetActiveTableRowHeight()})),tableSetBreakAcrossPages:o("tableSetBreakAcrossPages",e=>(t.setActiveTableRowBreakAcrossPages(eI(e)),!0),()=>({isEnabled:e.isCommandEnabled("tableSetBreakAcrossPages")&&t.canSetActiveTableRowBreakAcrossPages()})),tableSetHeaderRow:o("tableSetHeaderRow",e=>(t.setActiveTableRowHeader(eI(e)),!0),()=>({isEnabled:e.isCommandEnabled("tableSetHeaderRow")&&t.canSetActiveTableRowHeader()})),tableSetColumnWidth:o("tableSetColumnWidth",e=>(t.setActiveTableColumnWidth(e),!0),()=>({isEnabled:e.isCommandEnabled("tableSetColumnWidth")&&t.canSetActiveTableColumnWidth()})),tableSetTableWidth:o("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(nI(e)),()=>({isEnabled:e.isCommandEnabled("tableSetCellSpacing")&&t.canSetCellSpacing()})),tableSetTableIndent:n("tableSetTableIndent",e=>t.setTableIndent(nI(e)),()=>({isEnabled:e.isCommandEnabled("tableSetTableIndent")&&t.canSetTableIndent()})),tableSetAlignment:n("tableSetAlignment",e=>t.setTableAlignment(tI(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:o,columns:r}=e??{},a=o??r;n&&a&&t.insert(n,a)})}}function dI({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 uI({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 pI=/* @__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"]),gI=/* @__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"]),fI=/* @__PURE__ */new WeakMap;function mI(e){return{isCommandEnabled:t=>"openSymbolDialog"===t||("openEquationDialog"===t||("repeatLastAction"===t?!e.isReadOnly()&&e.canRepeatLastAction():(!gI.has(t)||!function(e){const t=e.state?.();if(!t)return!1;const n=t.document,o=t.selection;if(!n||!o)return!1;let r=fI.get(n);r||(r=/* @__PURE__ */new WeakMap,fI.set(n,r));const a=r.get(o);if(void 0!==a)return a;const i=null!==Ii(t,e=>"image"===e.kind||"textBox"===e.kind);return r.set(o,i),i}(e))&&((pI.has(t)||!e.isReadOnly())&&("insertFootnote"!==t||e.commandsController.canInsertFootnoteCommand()))))}}function hI(e){return{state:()=>e.styleController.toolbarStyleState()}}function bI(e){return{isCollapsed:()=>sr(e.state().selection)}}function yI(e){return{canUndo:()=>e.undoStack().length>0,canRedo:()=>e.redoStack().length>0,undo:()=>(e.historyActions.performUndo(),!0),redo:()=>(e.historyActions.performRedo(),!0)}}var vI={nbsp:" ",nbHyphen:"‑",optionalHyphen:"­",emDash:"—",ellipsis:"…",copyright:"©",registered:"®",trademark:"™"};function xI(e){return/\p{L}|\p{N}/u.test(e)}function wI(e){return"."===e||"!"===e||"?"===e}function SI(e,t){return ci(e,t)}function II(e,t,n,o){return e-n||t-o}function CI(e,t){const n=cr(e),o=n[t.startIndex],r=n[t.endIndex];return o&&r?{...e,selection:{anchor:SI(o,t.startOffset),focus:SI(r,t.endOffset)}}:e}function TI(e,t,n){if(!t.length)return null;const o=cr(e),r=new Map(o.map((e,t)=>[e.id,t])),a="next"===n?mr(e,o).end:mr(e,o).start,i=r.get(a.paragraphId);if(void 0===i)return null;const s=o[i],l=Br(s,a);return("next"===n?t.find(e=>II(e.startIndex,e.startOffset,i,l)>0):[...t].reverse().find(e=>II(e.startIndex,e.startOffset,i,l)<0))??("next"===n?t[0]:t[t.length-1])}function kI(e){const t=cr(e),n=[],o=/* @__PURE__ */new Set,r=/* @__PURE__ */new Map;for(const a of[...zv(e),...$v(e)]){const e=a.paragraphIds[0];if(!e)continue;const t=r.get(e)??[];t.push(a.id),r.set(e,t)}return t.forEach((e,t)=>{for(const i of r.get(e.id)??[])o.has(i)||(o.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 r of e.runs){const e=[r.revision?.id,r.styles?.propertyRevision?.id].filter(e=>"string"==typeof e);for(const i of e)o.has(i)||(o.add(i),n.push({id:i,startIndex:t,startOffset:a,endIndex:t,endOffset:a+r.text.length}));a+=r.text.length}}),n}function PI(e,t){const n=TI(e,kI(e),t);return n?CI(e,n):e}function RI(e){const t=cr(e),n=new Map(t.map((e,t)=>[e.id,t])),o=e.document.comments;if(!o)return[];const r=[];for(const a of o.order){const e=o.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)));II(i,d,s,u)>0||r.push({id:a,startIndex:i,startOffset:d,endIndex:s,endOffset:u})}return r.sort((e,t)=>II(e.startIndex,e.startOffset,t.startIndex,t.startOffset))}function BI(e,t){const n=TI(e,RI(e),t);return n?CI(e,n):e}function MI(e){const t=RI(e);if(!t.length)return null;const n=mr(e),o=t.find(e=>0===II(e.startIndex,e.startOffset,n.startIndex,n.startParagraphOffset)&&0===II(e.endIndex,e.endOffset,n.endIndex,n.endParagraphOffset))??t.find(e=>II(e.startIndex,e.startOffset,n.startIndex,n.startParagraphOffset)<=0&&II(e.endIndex,e.endOffset,n.endIndex,n.endParagraphOffset)>=0);return o?e.document.comments?.items[o.id]??null:null}function OI(e,t){const n=kI(e).find(e=>e.id===t);return n?CI(e,n):e}var AI=e=>Math.round(e/Tr*96);function FI(e,t=3){const n=[];for(const o of ya(e.document)){const e=nt(o.style?.styleId);if(null===e||e>t)continue;const r=oi(o).trim();r&&n.push({id:o.id,level:e,text:r})}return n}function DI(e){const t=Zr(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 EI(e,t){const n=Ka("");return n.runs=e,t&&(n.style=t),n}function LI(e,t,n){const o=void 0!==t?String(t):"";return EI([DI({text:`${e.text}\t${o}`})],{tabs:[{position:n,type:"right",leader:"dot"}],spacingAfter:AI(40),indentLeft:AI(397*(e.level-1))})}function NI(e){const{width:t,margins:n}=e.pageSettings,o=Math.max(0,t-n.left-n.right);return zn(o*Ur,2)}function zI(e,t,n,o){const r=Pa(e.document),a=r[t];if(!a)return e;const i=[...r];return i[t]={...a,blocks:n},{...e,document:{...e.document,sections:i},selection:Y(ci(o,0))}}function $I(e,t=()=>{},n=3){if("main"!==pr(e))return e;const o=nr(e),r=Pa(e.document)[o];if(!r)return e;const a=function(e,t,n){const o=e.map(e=>LI(e,t(e.id),n));return[EI([DI({text:"",fieldChar:{kind:"begin"}}),DI({text:"",fieldInstruction:' TOC \\o "1-3" \\h \\z \\u '}),DI({text:"",fieldChar:{kind:"separate"}})]),...o,EI([DI({text:"",fieldChar:{kind:"end"}})])]}(FI(e,n),t,NI(r)),i=br(e,e.selection.focus),s=r.blocks.findIndex(e=>e.id===i.paragraphId||"paragraph"!==e.type&&ta(e).some(e=>e.id===i.paragraphId)),l=-1===s?r.blocks.length:s+1;return zI(e,o,[...r.blocks.slice(0,l),...a,...r.blocks.slice(l)],a[0])}function HI(e){let t=0,n="",o=-1,r=-1,a=!1;for(let i=0;i<e.length;i+=1){const s=e[i];if("paragraph"===s.type)for(const e of s.runs){const s=Ir(e),l=Qo(e);if("begin"===s?.kind)t+=1,1===t&&(r=i,n="",a=!1,o=-1);else if(1===t&&void 0!==l)n+=l,/\bTOC\b/i.test(n)&&(a=!0);else if("separate"===s?.kind)1===t&&(o=i);else if("end"===s?.kind){if(1===t&&a)return{startBlockIndex:o>=0?o:r,endBlockIndex:i};t=Math.max(0,t-1)}}}return null}function WI(e){const t=t=>{const n=Number(e.styleController.toolbarStyleState().fontSize),o=Number.isFinite(n)&&n>0?Jt(n):11,r="increase"===t?Rn(o):xt(o);return e.styleController.applyToolbarValueStyleCommand("fontSize",Vn(r)),!0},n=e=>{const t=$e(e.document),n=/* @__PURE__ */new Map;for(const o of t.pages)for(const e of o.blocks){const t=e.paragraphId;t&&!n.has(t)&&n.set(t,o.index+1)}return e=>n.get(e)};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=ya(e.state().document);if(0===t.length)return!1;const n=t[0],o=t[t.length-1];return e.applyState({...e.state(),selection:{anchor:ci(n,0),focus:ci(o,oi(o).length)}}),e.focusInput(),!0},selectWord:()=>!e.isReadOnly()&&(e.applyState(function(e){const{paragraph:t,offset:n}=oe(e),o=oi(t);let r=n,a=n;for(;r>0&&xI(o[r-1]);)r-=1;for(;a<o.length&&xI(o[a]);)a+=1;return xi(e,{anchor:ci(t,r),focus:ci(t,a)})}(e.state())),e.focusInput(),!0),selectSentence:()=>!e.isReadOnly()&&(e.applyState(function(e){const{paragraph:t,offset:n}=oe(e),o=oi(t);let r=n;for(;r>0&&!wI(o[r-1]);)r-=1;for(;r<o.length&&/\s/u.test(o[r]);)r+=1;let a=n;for(;a<o.length&&!wI(o[a]);)a+=1;return a<o.length&&(a+=1),xi(e,{anchor:ci(t,r),focus:ci(t,Math.min(a,o.length))})}(e.state())),e.focusInput(),!0),selectParagraph:()=>!e.isReadOnly()&&(e.applyState(function(e){const t=cr(e),n=mr(e),o=t[n.startIndex],r=t[n.endIndex];return o&&r?xi(e,{anchor:ci(o,0),focus:ci(r,Xr(r))}):e}(e.state())),e.focusInput(),!0),selectCollapse:(t=!1)=>!e.isReadOnly()&&(e.applyState(function(e,t=!1){const n=e.selection.anchor,o=e.selection.focus,r=cr(e),a=vr(r,n,o),i=t?a<=0?o:n:a<=0?n:o;return xi(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 o=uw(e.document,t)[Math.max(1,n)-1];return o?xi(e,{anchor:o.anchor,focus:o.focus}):e}(e.state(),t,n)),e.focusInput(),!0),selectRange:(t,n)=>(e.applyState(function(e,t,n){return xi(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,o={...("endnote"===n?e.document.endnotes?.settings:e.document.footnotes?.settings)??{}};let r=!1;if(void 0!==t.numberFormat){const e=null===t.numberFormat?void 0:t.numberFormat;o.numberFormat!==e&&(o.numberFormat=e,r=!0)}if(void 0!==t.startAt){const e=null===t.startAt?void 0:Math.max(1,Math.round(t.startAt));o.startAt!==e&&(o.startAt=e,r=!0)}if(void 0!==t.restart){const e=null===t.restart?void 0:t.restart;o.restart!==e&&(o.restart=e,r=!0)}if(!r)return e;const a=Object.keys(o).length>0?{...o}: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 o=n?{fontFamily:n}:void 0;return e.applyTransactionalState(n=>e.tableOps.applyTableAwareParagraphEdit(n,e=>_u(e,t,o))),e.focusInput(),!0},insertEquation:t=>(e.applyTransactionalState(n=>e.tableOps.applyTableAwareParagraphEdit(n,e=>function(e,t){if(me(e))return e;const n=sr(e.selection)?e:ee(e),{paragraph:o,index:r,offset:a}=oe(n),i=qn(o,a),s={id:`run:${Math.random().toString(36).slice(2,9)}`,text:"",styles:i,kind:"math",math:t},l=xe(o,a,[s]),c=cr(n).map((e,t)=>t===r?l:e);return qt(n,c,Y(ci(l,a+1)))}(e,t))),e.focusInput(),!0),updateEquation:(t,n)=>(e.applyTransactionalState(e=>function(e,t,n){let o=!1;const r=cr(e).map(e=>{let r=!1;const a=e.runs.map(e=>e.id!==t||"math"!==e.kind?e:(o=!0,r=!0,{...e,math:n,text:""}));return r?{...e,runs:a}:e});return o?qt(e,r,e.selection):e}(e,t,n)),e.focusInput(),!0),hasTableOfContents:()=>function(e){const t=Pa(e.document)[nr(e)];return!!t&&null!==HI(t.blocks)}(e.state()),hasRevisionsInSelection:()=>BS(e.state()).size>0,hasRevisionsInDocument:()=>OS(e.state()),hasNavigableRevisions:()=>kI(e.state()).length>0,hasNavigableComments:()=>{return(t=e.state(),RI(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=PI(t,"next");return n!==t&&(e.applyState(n),e.focusInput(),!0)},navigateRevisionPrevious:()=>{const t=e.state(),n=PI(t,"previous");return n!==t&&(e.applyState(n),e.focusInput(),!0)},navigateCommentNext:()=>{const t=e.state(),n=BI(t,"next");return n!==t&&(e.applyState(n),e.focusInput(),!0)},navigateCommentPrevious:()=>{const t=e.state(),n=BI(t,"previous");return n!==t&&(e.applyState(n),e.focusInput(),!0)},hasSelectedComment:()=>null!==MI(e.state()),isSelectedCommentResolved:()=>Boolean(MI(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=>$I(e,n(e))),e.focusInput(),!0),updateTableOfContents:()=>(e.applyTransactionalState(e=>function(e,t=()=>{},n=3){const o=nr(e),r=Pa(e.document)[o];if(!r)return e;const a=HI(r.blocks);if(!a)return e;const i=FI(e,n).map(e=>LI(e,t(e.id),NI(r)));return zI(e,o,[...r.blocks.slice(0,a.startBlockIndex+1),...i,...r.blocks.slice(a.endBlockIndex)],i[0]??r.blocks[a.startBlockIndex])}(e,n(e))),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=>pw(e,t.search,t.replace,{matchCase:t.matchCase,wholeWord:t.wholeWord}),{mergeKey:ig}),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:Wv(e,"insertions"),deletions:Wv(e,"deletions"),comments:Wv(e,"comments"),formatting:Wv(e,"formatting"),allAuthors:t,visibleAuthors:e.markupAuthors??[],knownAuthors:qv(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:()=>(Oe(),!0),pageBreak:()=>(e.applyTransactionalState(t=>e.tableOps.applyTableAwareParagraphEdit(t,e=>xo(e))),e.focusInput(),!0),lineBreak:()=>(e.applyTransactionalState(t=>e.tableOps.applyTableAwareParagraphEdit(t,e=>_u(e,"\n"))),e.focusInput(),!0),columnBreak:()=>(e.applyTransactionalState(t=>e.tableOps.applyTableAwareParagraphEdit(t,e=>Xu(e))),e.focusInput(),!0),splitBlock:()=>(e.commandsController.handleListEnter()||(e.applyTransactionalState(t=>e.tableOps.applyTableAwareParagraphEdit(t,e=>ln(e))),e.focusInput()),!0),insertSpecialChar:t=>(e.applyTransactionalState(n=>e.tableOps.applyTableAwareParagraphEdit(n,e=>function(e,t){return _u(e,vI[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=>tp(e,1)),e.focusInput(),!0),shrinkFont1:()=>(e.applyTransactionalState(e=>tp(e,-1)),e.focusInput(),!0),changeTextCase:t=>(e.commandsController.applyChangeTextCaseCommand(t),!0),clearFormatting:()=>sr(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 UI(e,t){const n=hx(e),o=n&&Ko(n.run);if(!n||!o)return e;const{paragraphIndex:r,run:a}=n,i=cr(e).map((e,n)=>n!==r?zo(e):{...zo(e),runs:e.runs.map(e=>e.id===a.id&&"textBox"===e.kind?{...e,textBox:{...e.textBox,shape:t(e.textBox.shape??{})}}:Ea(e))});return qt(e,i,N(i,mr(e)))}function jI(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 VI(e,t,n){const o={...e??{type:"floating",allowOverlap:!0,positionH:{relativeFrom:"column",offset:0},positionV:{relativeFrom:"paragraph",offset:0}},type:"floating"},r=o.positionH??{},a=o.positionV??{};return{...o,wrap:"none"===o.wrap?o.wrap:o.wrap??"square",positionH:{...r,offset:(r.offset??0)+Math.round(t*ur),align:void 0},positionV:{...a,offset:(a.offset??0)+Math.round(n*ur)}}}function KI(e,t){const n=Ii(e,e=>"image"===e.kind||"textBox"===e.kind);if(!n)return e;const o=function(e){if(!Number.isFinite(e))return;const t=(Math.round(e)%360+360)%360;return 0===t?void 0:t}(t),{paragraphIndex:r,run:a}=n,i=cr(e).map((e,t)=>t!==r?zo(e):{...zo(e),runs:e.runs.map(e=>e.id!==a.id?Ea(e):"image"===e.kind?{...e,image:{...e.image,rotation:o}}:"textBox"===e.kind?{...e,textBox:{...e.textBox,rotation:o}}:Ea(e))});return qt(e,i,N(i,mr(e)))}function _I(e,t,n=90){return XI(e,e=>{const o="right"===t?-n:n,r=function(e){if(!Number.isFinite(e))return;const t=(Math.round(e)%360+360)%360;return 0===t?void 0:t}((e.rotation??0)+o);return{...e,rotation:r}})}function XI(e,t){const n=hx(e);if(!n||!Ko(n.run))return e;const{paragraphIndex:o,run:r}=n,a=cr(e).map((e,n)=>n!==o?zo(e):{...zo(e),runs:e.runs.map(e=>e.id===r.id&&"textBox"===e.kind?{...e,textBox:t(e.textBox)}:Ea(e))});return qt(e,a,N(a,mr(e)))}function GI(e,t){return XI(e,e=>({...e,body:t(e.body??{})}))}var qI={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 YI(e,t=!0){const n=r(e)??(t?lx(e):void 0);return n?qI[n]:void 0}function ZI(e){return{documentStyles:()=>{const t=e.state().document,n=t?.styles??{},o=/* @__PURE__ */new Set;for(const e of ya(t)){e.style?.styleId&&o.add(e.style.styleId);for(const t of e.runs)t.styles?.styleId&&o.add(t.styles.styleId)}return Object.values(n).map(e=>{const r=fa(e.id,n),a="table"===e.type?Dr(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:YI(e,!t.sourcePackage),type:e.type,qFormat:e.qFormat,uiPriority:e.uiPriority,semiHidden:e.semiHidden,unhideWhenUsed:e.unhideWhenUsed,isUsed:o.has(e.id),fontFamily:r.fontFamily?.trim()||void 0,fontSize:"number"==typeof r.fontSize?r.fontSize:void 0,color:r.color??void 0,bold:r.bold??void 0,italic:r.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:()=>gm(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=Ut(t),o=ei(n)[0]?.blocks??[];if(0===o.length)return e;if(o.every(e=>"paragraph"===e.type))return Wu(e,o.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 r=sr(e.selection)?e:ee(e),{paragraph:a,offset:i}=oe(r),s=on(a,0,i),l=on(a,i,Xr(a)),c=Ka(""),d={...a,runs:s.length?s:Ka("").runs},u={...a,id:c.id,runs:l.length?l:c.runs},p=[...i>0?[d]:[],...o,...l.length||"table"===o[o.length-1]?.type?[u]:[]];let g=!1;const f=e=>{let t=!1;const n=e.flatMap(e=>{if("paragraph"===e.type&&e.id===a.id)return g=!0,t=!0,p;if("table"!==e.type)return[e];let n=!1;const o=e.rows.map(e=>{let t=!1;const o=e.cells.map(e=>{const n=f(e.blocks);return n===e.blocks?e:(t=!0,{...e,blocks:n})});return t?(n=!0,{...e,cells:o}):e});return n?(t=!0,[{...e,rows:o}]):[e]});return t?n:e},m=r.activeZone??"main";let h=r.document;if("footnote"===m&&r.activeFootnoteId&&r.document.footnotes?.items[r.activeFootnoteId]){const e=r.document.footnotes,t=e.items[r.activeFootnoteId],n=f(t.blocks);g&&(h={...r.document,footnotes:{...e,items:{...e.items,[r.activeFootnoteId]:{...t,blocks:n}}}})}else{const t=ei(r.document),n=Math.max(0,Math.min(r.activeSectionIndex??0,t.length-1)),o=t[n];if(!o)return e;const a="header"===m?"header":"footer"===m?"footer":"blocks",i=f(o[a]??[]);if(g){const e=[...t];e[n]={...o,[a]:i},h={...r.document,sections:e}}}if(!g)return e;const b=o[o.length-1],y="paragraph"!==b.type||l.length?ci(u,0):ci(b,Xr(b));return{...r,document:h,selection:Y(y)}}(e,t)),insertShape:t=>e.applyTransactionalState(e=>function(e,t){const n=sr(e.selection)?e:ee(e),{paragraph:o,index:r,offset:a}=oe(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:[Ka("")],shape:{preset:t,fill:i.fill,borderColor:i.border,borderWidthPt:1},floating:ov(void 0,"front")},l=za("",qn(o,a),void 0,s),c=xe(o,a,[l]),d=cr(n).map((e,t)=>t===r?c:zo(e));return qt(n,d,Y(ci(c,a+1)))}(e,t)),setShapeFill:t=>e.applyTransactionalState(e=>function(e,t){return UI(e,e=>({...e,fill:t??void 0}))}(e,t),{mergeKey:Vg}),setShapeOutline:t=>e.applyTransactionalState(e=>{return n=t,UI(e,e=>({...e,borderColor:n??void 0}));var n},{mergeKey:Kg}),setShapeOutlineWidth:t=>e.applyTransactionalState(e=>function(e,t){return UI(e,e=>({...e,borderWidthPt:Math.max(0,t)}))}(e,t),{mergeKey:_g}),alignFloatingObject:t=>e.applyTransactionalState(e=>function(e,t){const n=Ii(e,e=>"image"===e.kind||"textBox"===e.kind);if(!n)return e;const{paragraphIndex:o,run:r}=n,a=cr(e).map((e,n)=>n!==o?zo(e):{...zo(e),runs:e.runs.map(e=>e.id!==r.id?Ea(e):"image"===e.kind?{...e,image:{...e.image,floating:jI(e.image.floating,t)}}:"textBox"===e.kind?{...e,textBox:{...e.textBox,floating:jI(e.textBox.floating,t)}}:Ea(e))});return qt(e,a,N(a,mr(e)))}(e,t),{mergeKey:Xg}),reorderFloatingObject:t=>e.applyTransactionalState(e=>function(e,t){const n=Ii(e,e=>"image"===e.kind||"textBox"===e.kind);if(!n)return e;const{paragraphIndex:o,run:r}=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=cr(e).map((e,t)=>t!==o?zo(e):{...zo(e),runs:e.runs.map(e=>e.id!==r.id?Ea(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)}}:Ea(e))});return qt(e,i,N(i,mr(e)))}(e,t),{mergeKey:Gg}),nudgeFloatingObject:(t,n)=>e.applyTransactionalState(e=>function(e,t,n){const o=Ii(e,e=>"image"===e.kind||"textBox"===e.kind);if(!o)return e;const{paragraphIndex:r,run:a}=o,i=cr(e).map((e,o)=>o!==r?zo(e):{...zo(e),runs:e.runs.map(e=>e.id!==a.id?Ea(e):"image"===e.kind?{...e,image:{...e.image,floating:VI(e.image.floating,t,n)}}:"textBox"===e.kind?{...e,textBox:{...e.textBox,floating:VI(e.textBox.floating,t,n)}}:Ea(e))});return qt(e,i,N(i,mr(e)))}(e,t,n),{mergeKey:qg}),setFloatingFixedPosition:t=>e.applyTransactionalState(e=>function(e,t){const n=Ii(e,e=>"image"===e.kind||"textBox"===e.kind);if(!n)return e;const{paragraphIndex:o,run:r}=n,a=cr(e).map((e,n)=>n!==o?zo(e):{...zo(e),runs:e.runs.map(e=>{if(e.id!==r.id)return Ea(e);if("image"===e.kind){const n=e.image.floating;return{...e,image:{...e.image,floating:n?av(n,t):n}}}if("textBox"===e.kind){const n=e.textBox.floating;return{...e,textBox:{...e.textBox,floating:n?av(n,t):n}}}return Ea(e)})});return qt(e,a,N(a,mr(e)))}(e,t),{mergeKey:Yg}),setFloatingRotation:t=>e.applyTransactionalState(e=>KI(e,t),{mergeKey:Zg}),setFloatingWrapPreset:t=>e.applyTransactionalState(e=>function(e,t){const n=Ii(e,e=>"image"===e.kind||"textBox"===e.kind);if(!n)return e;const o=e=>ov(e,t),{paragraphIndex:r,run:a}=n,i=cr(e).map((e,t)=>t!==r?zo(e):{...zo(e),runs:e.runs.map(e=>{if(e.id!==a.id)return Ea(e);if("image"===e.kind){const t=o(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=o(e.textBox.floating),n=t?{...e.textBox,floating:t}:(()=>{const{floating:t,...n}=e.textBox;return n})();return{...e,textBox:n}}return Ea(e)})});return qt(e,i,N(i,mr(e)))}(e,t),{mergeKey:Jg}),setFloatingWrapText:t=>e.applyTransactionalState(e=>function(e,t){const n=Ii(e,e=>"image"===e.kind||"textBox"===e.kind);if(!n)return e;const o=e=>{if(!e)return e;if("bothSides"===t){const{wrapText:t,...n}=e;return n}return{...e,wrapText:t}},{paragraphIndex:r,run:a}=n,i=cr(e).map((e,t)=>t!==r?zo(e):{...zo(e),runs:e.runs.map(e=>e.id!==a.id?Ea(e):"image"===e.kind?{...e,image:{...e.image,floating:o(e.image.floating)}}:"textBox"===e.kind?{...e,textBox:{...e.textBox,floating:o(e.textBox.floating)}}:Ea(e))});return qt(e,i,N(i,mr(e)))}(e,t),{mergeKey:Qg}),setFloatingPositionPreset:t=>e.applyTransactionalState(e=>function(e,t){const n=Ii(e,e=>"image"===e.kind||"textBox"===e.kind);if(!n)return e;const{h:o,v:r}=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:o,offset:0},i={relativeFrom:"margin",align:r,offset:0},{paragraphIndex:s,run:l}=n,c=cr(e).map((e,t)=>t!==s?zo(e):{...zo(e),runs:e.runs.map(e=>{if(e.id!==l.id)return Ea(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 Ea(e)})});return qt(e,c,N(c,mr(e)))}(e,t),{mergeKey:ef}),setShapePreset:t=>e.applyTransactionalState(e=>function(e,t){return UI(e,e=>({...e,preset:t}))}(e,t),{mergeKey:tf}),setTextBoxTextDirection:t=>e.applyTransactionalState(e=>function(e,t){const n="horz"===t?"horz":"vert"===t?"vert":"vert270"===t?"vert270":"wordArtVert";return GI(e,e=>({...e,vert:n}))}(e,t),{mergeKey:nf}),setTextBoxVerticalAlign:t=>e.applyTransactionalState(e=>function(e,t){const n="b"===t?"b":"ctr"===t?"ctr":"t";return GI(e,e=>({...e,anchor:n}))}(e,t),{mergeKey:of}),setTextBoxAlt:t=>e.applyTransactionalState(e=>function(e,t){return XI(e,e=>({...e,alt:t??void 0}))}(e,t),{mergeKey:rf}),rotateTextBox:t=>e.applyTransactionalState(e=>_I(e,t),{mergeKey:af}),getTextBoxSizeCm:()=>function(e){const t=hx(e),n=t&&Ko(t.run);return n?{width:n.width/$r,height:n.height/$r}:null}(e.state()),isTextBoxSelected:()=>null!==hx(e.state()),setTextBoxWidthCm:t=>e.applyTransactionalState(e=>function(e,t){return XI(e,e=>({...e,width:Math.max(24,Math.round(t*$r))}))}(e,t),{mergeKey:sf}),setTextBoxHeightCm:t=>e.applyTransactionalState(e=>function(e,t){return XI(e,e=>({...e,height:Math.max(24,Math.round(t*$r))}))}(e,t),{mergeKey:lf})}}function JI(e){return{prompt:()=>e.commandsController.promptForLink(),remove:()=>e.commandsController.removeLinkCommand(),canPrompt:()=>!sr(e.state().selection)||Boolean(e.styleController.toolbarStyleState().link)}}function QI(e){return{promptAlt:()=>e.commandsController.promptForImageAlt(),promptCaption:()=>e.commandsController.promptForImageCaption(),isSelected:()=>Boolean(e.selectedImageRun()),getSizeCm:()=>function(e){const t=sv(e),n=t&&fr(t.run);return n?{width:n.width/$r,height:n.height/$r}: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=sv(e);return(t&&fr(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=sv(e);return(t&&fr(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=sv(e),n=t&&fr(t.run);return n?n.transparency??0:null}(e.state()),setTransparency:t=>e.commandsController.applyImageTransparencyCommand(t),reset:()=>e.commandsController.resetImageCommand(),canReset:()=>null!==sv(e.state())}}function eC(e){const t=e.clipboardActions??mp({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 tC(e,t){const n=pr(e),o=Pa(e.document);if("header"===n||"footer"===n){const r=nr(e),a=o[r];if(!a)return e;const i=e.activeHeaderFooterStory??"default",s=kr(a,n,i,t),l=[...o];return l[r]=s,{...e,document:{...e.document,sections:l}}}if("main"===n){const n=nr(e),r=o[n];if(!r)return e;const a=[...o];return a[n]={...r,blocks:t},{...e,document:{...e.document,sections:a}}}return e}function nC(e,t){return null!==rC(e,t)}function oC(e,t){const n=rC(e,t);if(!n)return e;const{nextBlocks:o}=n,r=tC(e,o),a=o.flatMap(ta);return{...r,selection:aC(e.selection,a)}}function rC(e,t){const n=pr(e);if("footnote"===n)return null;const o=ja(e,n);if(0===o.length)return null;const r=mr(e),a=function(e,t,n,o){const r=/* @__PURE__ */new Set;for(let s=n;s<=o;s+=1){const e=t[s];if(void 0===e)return null;r.add(e)}if(0===r.size)return null;const a=Math.min(...r),i=Math.max(...r);for(let s=a;s<=i;s+=1)if("paragraph"!==e[s].type)return null;return{lo:a,hi:i}}(o,function(e){const t=[];return e.forEach((e,n)=>{ta(e).forEach(()=>{t.push(n)})}),t}(o),r.startIndex,r.endIndex);if(!a)return null;const{lo:i,hi:s}=a,l=o.slice(i,s+1);let c;if("up"===t){if(0===i)return null;const e=o[i-1];if("paragraph"!==e.type)return null;c=[...o.slice(0,i-1),...l,e,...o.slice(s+1)]}else{if(s===o.length-1)return null;const e=o[s+1];if("paragraph"!==e.type)return null;c=[...o.slice(0,i),e,...l,...o.slice(s+2)]}return{nextBlocks:c}}function aC(e,t){const n=new Map(t.map((e,t)=>[e.id,t])),o=e=>{const o=n.get(e.paragraphId);if(void 0===o)return e;const r=t[o];return ci(r,Math.min(e.offset,Xr(r)))};return{anchor:o(e.anchor),focus:o(e.focus)}}function iC(e,t){const n=function(e){const t=pr(e);if("footnote"===t)return null;const n=ja(e,t);if(0===n.length)return null;const o=mr(e),r=/* @__PURE__ */new Set;for(let s=o.startIndex;s<=o.endIndex;s+=1){let e=0,t=-1;for(let o=0;o<n.length;o+=1){const r=ta(n[o]).length;if(s<e+r){t=o;break}e+=r}if(t<0)return null;r.add(t)}if(0===r.size)return null;const a=Math.min(...r),i=Math.max(...r);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:o,hi:r,blocks:a}=n,i=a.slice(o,r+1).map((e,t)=>({block:e,index:t,key:sC(oi(e))}));i.sort((e,n)=>{const o=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!==o?t?-o:o:e.index-n.index});const s=[...a.slice(0,o),...i.map(e=>e.block),...a.slice(r+1)],l=tC(e,s),c=s.flatMap(ta);return{...l,selection:lC(e.selection,c)}}function sC(e){const t=e.trim(),n=/^(\d+(?:\.\d+)?)/.exec(t)?.[1];return{num:void 0===n?void 0:Number(n),text:e}}function lC(e,t){const n=new Map(t.map((e,t)=>[e.id,t])),o=e=>{const o=n.get(e.paragraphId);if(void 0===o)return e;const r=t[o];return ci(r,Math.min(e.offset,Xr(r)))};return{anchor:o(e.anchor),focus:o(e.focus)}}function cC(e,t){const n=mr(e),o=cr(e);let r=1;for(let s=0;s<n.startIndex;s+=1){const e=nt(o[s]?.style?.styleId);null!==e&&(r=e)}let a=!1;const i=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return zo(e);const i=nt(e.style?.styleId);if(e.list&&e.list.kind){const n=e.list.level??0,o=t?Math.max(0,n-1):Math.min(8,n+1);return o===n?zo(e):(a=!0,D(e,o))}if(null!==i){const n=t?Math.max(1,i-1):Math.min(9,i+1);if(n===i)return zo(e);a=!0;const o=zo(e);return o.style={...e.style??{},styleId:`heading${n}`,outlineLevel:void 0},o}if(!t)return zo(e);a=!0;const s=zo(e);return s.style={...e.style??{},styleId:`heading${r}`,outlineLevel:void 0},s});return a?qt(e,i,N(i,n)):e}var dC=["align","spacingBefore","spacingAfter","lineHeight","lineRule","indentLeft","indentRight","indentFirstLine","indentHanging","mirrorIndents","contextualSpacing","outlineLevel","shading","borderTop","borderRight","borderBottom","borderLeft","tabs","pageBreakBefore","keepWithNext","keepLinesTogether","widowControl","bidi"];var uC=/* @__PURE__ */new Set(["auto","exact","atLeast"]);var pC=/* @__PURE__ */new Set(["lrTb","tbRl","btLr","lrTbV","tbRlV"]);var gC={width:1.5,type:"solid",color:"#000000"};function fC(e,t){const n=t.text??oi(e).slice(0,1),o=Math.max(1,Math.min(10,Math.round(t.lines??3))),r=e.runs[0]?.styles,a=t.font;return{text:n,lines:o,type:"margin"===t.type?"margin":"drop",style:void 0!==a?{...r??{},fontFamily:a}:r}}function mC(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=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.lineRule,i=(()=>{if(null!==t&&"auto"!==t)return uC.has(t)?t:a})();if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setTextDirection:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.textDirection,i=null===t||"lrTb"===t?void 0:pC.has(t)?t:a;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setSuppressAutoHyphens:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.suppressAutoHyphens,i=null===t?void 0:t;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setSuppressLineNumbers:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.suppressLineNumbers,i=null===t?void 0:t;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setKinsoku:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.kinsoku,i=null===t?void 0:t;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setOverflowPunct:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.overflowPunct,i=null===t?void 0:t;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setWordWrap:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.wordWrap,i=null===t?void 0:t;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setAutoSpaceDE:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.autoSpaceDE,i=null===t?void 0:t;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setAutoSpaceDN:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.autoSpaceDN,i=null===t?void 0:t;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setAdjustRightInd:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.adjustRightInd,i=null===t?void 0:t;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setTopLinePunct:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.topLinePunct,i=null===t?void 0:t;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setPageBreakBefore:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.pageBreakBefore,i=null===t?void 0:t;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setKeepWithNext:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.keepWithNext,i=null===t?void 0:t;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setKeepLinesTogether:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.keepLinesTogether,i=null===t?void 0:t;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setWidowControl:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.widowControl,i=null===t?void 0:t;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setContextualSpacing:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.contextualSpacing,i=null===t?void 0:t;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(a,n)):e}(e,t)),setMirrorIndents:t=>e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e);let r=!1;const a=o.map((e,o)=>{if(o<n.startIndex||o>n.endIndex)return e;const a=e.style?.mirrorIndents,i=null===t?void 0:t;if(a===i)return e;r=!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{...zo(e),style:s}});return r?qt(e,a,N(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 o=n??48;e.applyTransactionalState(e=>{let n=se(e,"indentFirstLine",null);return n=se(n,"indentHanging",null),"firstLine"===t?n=se(n,"indentFirstLine",o):"hanging"===t&&(n=se(n,"indentHanging",o)),n},{mergeKey:tg}),e.focusInput()},setShading:t=>e.commandsController.applyParagraphStyleCommand("shading",t),applyBorders:()=>{const t={width:1,type:"solid",color:"#000000"};e.applyTransactionalState(e=>{let n=se(e,"borderTop",t);return n=se(n,"borderRight",t),n=se(n,"borderBottom",t),n=se(n,"borderLeft",t),n},{mergeKey:ng}),e.focusInput()},addHorizontalLine:()=>{e.applyTransactionalState(e=>se(e,"borderBottom",gC),{mergeKey:ng}),e.focusInput()},setLineHeight:t=>e.commandsController.applyParagraphStyleCommand("lineHeight",t),setListFormat:t=>e.commandsController.handleListFormatChange(t),setListStartAt:t=>e.commandsController.handleListStartAtChange(t),setListLevel:t=>{e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=Math.min(8,Math.max(0,Math.round(t))),r=cr(e);let a=!1;const i=r.map((e,t)=>t<n.startIndex||t>n.endIndex?e:e.list?(e.list.level??0)===o?e:(a=!0,D(e,o)):e);return a?qt(e,i,N(i,n)):e}(e,t)),e.focusInput()},outdent:()=>{e.clearPreferredColumn(),e.resetTransactionGrouping(),e.tableOps.applySelectionAwareParagraphCommand(e=>WS(e,-1)),e.focusInput()},indent:()=>{e.clearPreferredColumn(),e.resetTransactionGrouping(),e.tableOps.applySelectionAwareParagraphCommand(e=>WS(e,1)),e.focusInput()},moveParagraphsUp:()=>{nC(e.state(),"up")?(e.applyTransactionalState(e=>oC(e,"up"),{mergeKey:og}),e.focusInput()):e.focusInput()},moveParagraphsDown:()=>{nC(e.state(),"down")?(e.applyTransactionalState(e=>oC(e,"down"),{mergeKey:rg}),e.focusInput()):e.focusInput()},canMoveParagraphsUp:()=>nC(e.state(),"up"),canMoveParagraphsDown:()=>nC(e.state(),"down"),promote:()=>{e.applyTransactionalState(e=>cC(e,!0)),e.focusInput()},demote:()=>{e.applyTransactionalState(e=>cC(e,!1)),e.focusInput()},resetParagraphFormatting:()=>{e.applyTransactionalState(e=>function(e){const t=mr(e),n=cr(e);let o=!1;const r=n.map((e,n)=>{if(n<t.startIndex||n>t.endIndex)return e;const r=e.style;if(!r||dC.every(e=>!(e in r)))return e;o=!0;const a=zo(e),i=r.styleId?{styleId:r.styleId}:{};return a.style=Object.keys(i).length>0?i:void 0,a});return o?qt(e,r,N(r,t)):e}(e)),e.focusInput()},setTabStops:t=>{e.resetTransactionGrouping(),e.applyTransactionalState(e=>vn(e,t),{mergeKey:lg}),e.focusInput()},setOutlineLevel:t=>{e.applyTransactionalState(e=>function(e,t){const n=mr(e),o=cr(e),r=null==t?null:Math.min(8,Math.max(0,Math.round(t)));let a=!1;const i=o.map((e,t)=>{if(t<n.startIndex||t>n.endIndex)return e;if((e.style?.outlineLevel??null)===r)return e;a=!0;const o={...e.style??{}};null===r?delete o.outlineLevel:o.outlineLevel=r;const i=zo(e);return i.style=Object.keys(o).length>0?o:void 0,i});return a?qt(e,i,N(i,n)):e}(e,t)),e.focusInput()},setBidi:t=>e.commandsController.applyParagraphStyleCommand("bidi",t),setParagraphAlign:t=>{e.applyTransactionalState(e=>function(e,t){return se(e,"align",t)}(e,t))},sortParagraphs:(t=!1)=>e.applyTransactionalState(e=>iC(e,t)),hasDropCap:()=>function(e){const t=mr(e);return cr(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=mr(e),o=cr(e),r=n.startIndex,a=n.endIndex,i="none"===t.type||0===t.lines||void 0!==t.text&&0===t.text.length,s=o.map((e,n)=>n<r||n>a?zo(e):i?{...zo(e),dropCap:void 0}:{...zo(e),dropCap:fC(e,{...t,type:"margin"===t.type?"margin":"drop"})});return qt(e,s,N(s,n))}(e,t)),e.focusInput()}}}function hC(e){const t=Pa(e.document);return{sections:t,sectionIndex:Math.max(0,Math.min(nr(e),t.length-1))}}function bC(e,t){const{sections:n,sectionIndex:o}=hC(e);if(0===n.length)return e;const r=t(n[o]);if(r===n[o])return e;const a=[...n];return a[o]=r,{...e,document:{...e.document,sections:a}}}function yC(e,t,n="default"){const o=Hr(t,n);return bC(e,e=>e[o]?e:{...e,[o]:[ia(t)]})}function vC(e,t,n="default"){const o=Hr(t,n),r=bC(e,e=>e[o]?{...e,[o]:void 0}:e);return r===e?e:pr(r)===t?IC(r):r}function xC(e,t,n="default"){const o=yC(e,t,n),{sections:r,sectionIndex:a}=hC(o),i=(r[a][Hr(t,n)]??[]).flatMap(ta).find(Boolean);return i?{...o,selection:Cr(ci(i,0)),activeSectionIndex:a,activeZone:t,activeHeaderFooterStory:n}:o}function wC(e){const{sections:t,sectionIndex:n}=hC(e),o=t[n];return Boolean(o&&(o.firstPageHeader||o.firstPageFooter))}function SC(e){const{sections:t,sectionIndex:n}=hC(e),o=t[n];return Boolean(o&&(o.evenPageHeader||o.evenPageFooter))}function IC(e){const{sections:t,sectionIndex:n}=hC(e),o=(t[n]?.blocks??[]).flatMap(ta).find(Boolean);return o?{...e,selection:Cr(ci(o,0)),activeSectionIndex:n,activeZone:"main",activeHeaderFooterStory:void 0}:{...e,activeZone:"main",activeHeaderFooterStory:void 0}}function CC(e){return function(e,t){const n=sr(e.selection)?e:ee(e),{paragraph:o,index:r,offset:a}=oe(n),i=on(o,0,a),s=on(o,a,Xr(o)),l={id:`run:field:${Math.random().toString(36).slice(2,9)}`,text:"1",kind:"field",field:{type:t},styles:qn(o,a)},d=c(o,[...i,l,...s]),u=cr(n),p=[...Ja(u.slice(0,r)),d,...Ja(u.slice(r+1))];return qt(n,p,Y(ci(d,a+l.text.length)))}(e,"PAGE")}function TC(e,t,n,o){return{id:n,text:"1",kind:"field",field:o&&"decimal"!==o?{type:e,format:o}:{type:e},styles:t}}function kC(e,t){const n=Math.random().toString(36).slice(2,9);return"xOfY"===e?[{id:`run:page-of-prefix:${n}`,text:"Page ",kind:"text"},TC("PAGE",void 0,`run:page-field:${n}`,t),{id:`run:page-of-separator:${n}`,text:" of ",kind:"text"},TC("NUMPAGES",void 0,`run:numpages-field:${n}`,t)]:[TC("PAGE",void 0,`run:page-field:${n}`,t)]}function PC(e,t="page",n){return function(e,t){const n=sr(e.selection)?e:ee(e),{paragraph:o,index:r,offset:a}=oe(n),i=qn(o,a),s=t.map((e,t)=>e.styles?e:{...e,styles:i,id:`${e.id}:${t}`}),l=c(o,[...on(o,0,a),...s,...on(o,a,Xr(o))]),d=cr(n),u=[...Ja(d.slice(0,r)),l,...Ja(d.slice(r+1))],p=s.reduce((e,t)=>e+t.text.length,0);return qt(n,u,Y(ci(l,a+p)))}(e,kC(t,n))}function RC(e){const t=Pa(e.document);return{sections:t,sectionIndex:Math.max(0,Math.min(nr(e),t.length-1))}}function BC(e,t,n={}){const{kind:o="page",format:r,align:a="center"}=n;if("current"===t)return PC(e,o,r);const i="top"===t?"header":"footer",s=Hr(i,"default"),{sections:l,sectionIndex:c}=RC(e);if(0===l.length)return e;const d={id:Da("paragraph"),type:"paragraph",runs:kC(o,r),style:{styleId:i,align:a}},u={...l[c],[s]:[d]},p=[...l];return p[c]=u,{...e,document:{...e.document,sections:p},selection:Cr(ci(d,0)),activeSectionIndex:c,activeZone:i}}function MC(e){const t={isLandscape:()=>{const t=nr(e.state());return"landscape"===(e.state().document.sections?.[t]??e.state().document)?.pageSettings?.orientation},setOrientation:t=>{const n=nr(e.state()),o=e.state().document.sections?.[n]??e.state().document;o&&e.commandsController.applyUpdateSectionSettingsCommand(n,{pageSettings:{...o.pageSettings,orientation:t}})},toggleOrientation:()=>{const n=nr(e.state()),o=e.state().document.sections?.[n]??e.state().document;if(!o)return;const r=o.pageSettings?.orientation??"portrait";t.setOrientation("portrait"===r?"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=nr(e.state());return(e.state().document.sections?.[t]??e.state().document)?.pageSettings?.margins},setPageMargins:t=>{const n=nr(e.state()),o=e.state().document.sections?.[n]??e.state().document;o?.pageSettings&&e.commandsController.applyUpdateSectionSettingsCommand(n,{pageSettings:{...o.pageSettings,margins:{...o.pageSettings.margins,...t}}})},setMarginsPreset:t=>{e.applyTransactionalState(e=>mt(e,t)),e.focusInput()},getPageNumbering:()=>{const t=nr(e.state());return e.state().document.sections?.[t]?.pageNumbering},setPageNumbering:t=>{e.applyTransactionalState(e=>function(e,t){const{sections:n,sectionIndex:o}=RC(e);if(0===n.length)return e;const r={...n[o].pageNumbering,...void 0!==t.start?{start:t.start}:{},...void 0!==t.format?{format:t.format}:{}};return a(e,o,{pageNumbering:r})}(e,t)),e.focusInput()},getPaperSize:()=>bn(e.state()),setPaperSize:t=>{e.applyTransactionalState(e=>To(e,t)),e.focusInput()},setPaperSizePreset:t=>{e.applyTransactionalState(e=>Ce(e,t)),e.focusInput()},getColumns:()=>Dn(e.state()),setColumns:t=>{e.applyTransactionalState(e=>Mo(e,t)),e.focusInput()},getVerticalAlign:()=>rt(e.state()),setVerticalAlign:t=>{e.applyTransactionalState(e=>p(e,t)),e.focusInput()},getSectionStart:()=>{const t=nr(e.state());return e.state().document.sections?.[t]?.breakType},setSectionStart:t=>{const n=nr(e.state());(e.state().document.sections?.[n]??e.state().document)&&e.commandsController.applyUpdateSectionSettingsCommand(n,{breakType:t})},getBidi:()=>Wt(e.state()),setBidi:t=>{e.applyTransactionalState(e=>mo(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,o={...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:o}}}(e,t)),e.focusInput()}};return t}function OC(e){const t=t=>{e.applyTransactionalState(t),e.focusInput()};return{editHeader:()=>t(e=>xC(e,"header")),editFooter:()=>t(e=>xC(e,"footer")),editFirstPageHeader:()=>t(e=>xC(e,"header","firstPage")),editEvenPageHeader:()=>t(e=>xC(e,"header","evenPage")),editFirstPageFooter:()=>t(e=>xC(e,"footer","firstPage")),editEvenPageFooter:()=>t(e=>xC(e,"footer","evenPage")),insertPageNumber:()=>t(e=>CC(e)),insertPageNumberXOfY:()=>t(e=>PC(e,"xOfY")),placePageNumberTop:()=>t(e=>BC(e,"top")),placePageNumberBottom:()=>t(e=>BC(e,"bottom")),exit:()=>t(e=>function(e){return IC(e)}(e)),isInHeaderFooter:()=>{const t=e.state().activeZone;return"header"===t||"footer"===t},getDifferentFirstPage:()=>wC(e.state()),setDifferentFirstPage:e=>t(t=>function(e,t){if(wC(e)===t)return e;let n=e;return t?(n=yC(n,"header","firstPage"),n=yC(n,"footer","firstPage"),n):(n=vC(n,"header","firstPage"),vC(n,"footer","firstPage"))}(t,e)),getDifferentOddEven:()=>SC(e.state()),setDifferentOddEven:e=>t(t=>function(e,t){if(SC(e)===t)return e;let n=e;return t?(n=yC(n,"header","evenPage"),n=yC(n,"footer","evenPage"),n):(n=vC(n,"header","evenPage"),vC(n,"footer","evenPage"))}(t,e))}}function AC(e){const t=e.document.bookmarks;return t?t.order.map(e=>t.items[e]).filter(e=>Boolean(e)):[]}function FC(e){return{insert:t=>{e.applyTransactionalState(e=>function(e,t){const{start:n,end:o,isCollapsed:r}=mr(e),a=e.document.bookmarks,i=a?.order??[],s=t&&t.trim().length>0?t.trim():`Bookmark${i.length+1}`,l={id:$o(),name:s,start:{paragraphId:n.paragraphId,offset:n.offset},...r?{}:{end:{paragraphId:o.paragraphId,offset:o.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 o={...n.items};delete o[t];const r={items:o,order:n.order.filter(e=>e!==t)};return{...e,document:{...e.document,bookmarks:r}}}(e,t)),e.focusInput()},list:()=>AC(e.state()).map(e=>({id:e.id,name:e.name}))}}var DC=["January","February","March","April","May","June","July","August","September","October","November","December"],EC=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function LC(e,t){let n="";const o=e=>String(e).padStart(2,"0");let r=0;const a=t;for(;r<a.length;){const t=a[r];let i=t;for(;r+i.length<a.length&&a[r+i.length]===t;)i+=t;const s=e.getHours();switch(t){case"d":n+=i.length>=4?EC[e.getDay()]:3===i.length?EC[e.getDay()].slice(0,3):2===i.length?o(e.getDate()):String(e.getDate());break;case"M":n+=i.length>=4?DC[e.getMonth()]:3===i.length?DC[e.getMonth()].slice(0,3):2===i.length?o(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+=o(s);break;case"h":n+=i.length>=2?o(s%12==0?12:s%12):String(s%12==0?12:s%12);break;case"m":n+=i.length>=2?o(e.getMinutes()):String(e.getMinutes());break;case"s":n+=i.length>=2?o(e.getSeconds()):String(e.getSeconds());break;default:if(a.slice(r).toLowerCase().startsWith("am/pm")){n+=s<12?"am":"pm",r+=5;continue}n+=t}r+=i.length}return n}var NC=e=>$e(e,void 0,void 0,void 0,{cachedBodyPageFields:!0});function zC(e,t){const n=t.get(e.paragraphId);if(!n)return e;let o=0;for(const r of n.edits){if(e.offset<=r.start)break;if(e.offset<r.end)throw Error("interior anchor must be rejected before mapping");o+=r.text.length-(r.end-r.start)}return o?{...e,offset:e.offset+o}:e}function $C(e,t){if(!e)return e;let n=!1;const o={...e.items};for(const[r,a]of Object.entries(o)){const e=a.start?zC(a.start,t):void 0,i=a.end?zC(a.end,t):void 0;e===a.start&&i===a.end||(o[r]={...a,start:e,end:i},n=!0)}return n?{...e,items:o}:e}function HC(e,t,n){const o=t.get(e.paragraphId)?.edits.find(t=>t.runId===e.runId);if(!o)return e;const r=e.offset===o.end-o.start?o.text.length:"selection"===n?Math.min(e.offset,o.text.length):e.offset;return r===e.offset?e:{...e,offset:r}}function WC(e){return!e.list&&!e.dropCap&&!e.sdtWrappers?.length&&!e.numberingRevision&&!e.style?.bidi&&(!e.style?.textDirection||"lrTb"===e.style.textDirection)&&e.runs.every(Le)&&new Set(e.runs.map(e=>e.id)).size===e.runs.length}function UC(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 jC(e,t=NC,n="all",o){const r=o||e.document.coreTimestamps?{...e.document.coreTimestamps,...o}:void 0,a=t(e.document),i=(t,n)=>({state:e,layout:a,status:t,passes:n,updatedFields:0}),s=Pa(e.document),l=s.flatMap(e=>e.blocks);if(e.trackChangesEnabled||"main"!==pr(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(L(l,c),"selection"===n&&(c=function(e,t,n){const o=e=>{const n=t.findIndex(t=>t.id===e.paragraphId);if(n<0)return;const o=t[n],r=o.runs.findIndex(t=>t.id===e.runId);return r<0||!Number.isInteger(e.offset)||e.offset<0||e.offset>o.runs[r].text.length?void 0:{index:n,runIndex:r,offset:o.runs.slice(0,r).reduce((e,t)=>e+t.text.length,0)+e.offset,affinity:e.fieldBoundaryAffinity}},r=o(e.selection.anchor),a=o(e.selection.focus),i=/* @__PURE__ */new Map;if(!r||!a)return i;const[s,l]=r.index<a.index||r.index===a.index&&r.offset<=a.offset?[r,a]:[a,r],c=s.index===l.index&&s.offset===l.offset;if(c&&(r.runIndex!==a.runIndex||r.affinity!==a.affinity))return i;for(let d=s.index;d<=l.index;d++){const e=t[d],o=n.get(e.id);if(!o)continue;let r=0;const a=e.runs.map(e=>{const t=r;return r+=e.text.length,t}),u=o.filter(t=>{const n=a[t.runIndex],o=n+e.runs[t.runIndex].text.length;return n!==o&&(c?!("before-markers"===s.affinity&&s.offset===n||"after-markers"===s.affinity&&s.offset===o)&&(s.offset>n&&s.offset<o||s.runIndex===t.runIndex&&s.offset>=n&&s.offset<=o):n<(d===l.index?l.offset:r)&&o>(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=ni(e.document);let u=e,p=a;const g=/* @__PURE__ */new Set,f=/* @__PURE__ */new Set;for(let m=1;m<=6;m++){const o=Ue(u.document,p),a=Pa(u.document),s=UC(u),l=/* @__PURE__ */new Map,h=/* @__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,o=t.layout.startOffset??0,r=t.layout.endOffset??o+t.layout.text.length;o!==(h.get(n)??0)||r<o||r-o!==t.layout.text.length||r>Xr(t.sourceBlock)?l.set(n,null):(h.set(n,r),l.has(n)?l.get(n)!==e.index&&l.set(n,null):l.set(n,e.index))}const b=/* @__PURE__ */new Map,y=/* @__PURE__ */new Set,v=[];for(const e of a)for(const t of e.blocks){if("paragraph"!==t.type||!WC(t))continue;const i=c.get(t.id),p=l.get(t.id);if(!i||null==p||h.get(t.id)!==Xr(t))continue;const f=o.forPage(p),m=[];let x=0;for(const e of t.runs)m.push(x),x+=e.text.length;for(const{runIndex:o,field:l}of i){const i=t.runs[o],c=JSON.stringify([t.id,o]);if(v.push(JSON.stringify([c,i.text,p])),"PAGE"===l.type&&!l.format&&e.pageNumbering?.format&&"decimal"!==e.pageNumbering.format)continue;if("PAGEREF"===l.type&&a.some(e=>e.pageNumbering?.format&&"decimal"!==e.pageNumbering.format))continue;const h=i.styles?.language?.value?.toLowerCase(),w="pt-br"===h?"pt-BR":h?.startsWith("en")?"en-US":r?.locale,S=di(l,{...f,sequenceValue:d.get(ui(t.id,o)),temporal:r?{...r,locale:w}:void 0},i.text),I=m[o],C=I+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&&((s.get(t.id)??[]).some(e=>!Number.isInteger(e)||e<0||e>x||e>I&&e<C)||"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(y.add(c),S.text===i.text)continue;const T=b.get(t.id)??{paragraph:t,edits:[]};T.edits.push({runIndex:o,runId:i.id,start:I,end:C,text:S.text}),b.set(t.id,T),g.add(c)}}if([...g].some(e=>!y.has(e)))return i("nonconvergent",m);if(!b.size)return{state:u,layout:p,status:u===e?"unchanged":"updated",passes:m,updatedFields:g.size};const x=JSON.stringify([p.pages.length,v]);if(f.has(x))return i("nonconvergent",m);f.add(x);for(const e of b.values())e.edits.sort((e,t)=>e.start-t.start);const w={...u.document,sections:a.map(e=>({...e,blocks:e.blocks.map(e=>{const t=b.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:$C(u.document.bookmarks,b),comments:$C(u.document.comments,b)};u={...u,document:w,selection:{anchor:HC(u.selection.anchor,b,n),focus:HC(u.selection.focus,b,n)}},p=t(w)}return i("nonconvergent",6)}function VC(e,t){const n=t.type??"REF",o=function(e,t){return AC(e).find(e=>e.name===t)}(e,t.bookmark);if(!o)return e;const r=sr(e.selection)?e:ee(e),{paragraph:a,index:i,offset:s}=oe(r),l=qn(a,s),d={type:n,bookmark:t.bookmark},u="REF"===n?Ue(e.document).bookmarkText(o.name):void 0,p={id:`run:${n.toLowerCase()}:${Math.random().toString(36).slice(2,9)}`,text:u&&!/[\r\n]/.test(u)?u:"1",kind:"field",field:d,styles:l},g=c(a,[...on(a,0,s),p,...on(a,s,Xr(a))]),f=cr(r),m=[...Ja(f.slice(0,i)),g,...Ja(f.slice(i+1))];return qt(r,m,Y(ci(g,s+p.text.length)))}function KC(e){const t=()=>!e.isReadOnly()&&"main"===pr(e.state())&&!e.state().trackChangesEnabled,n=n=>{if(!t())return;e.resetTransactionGrouping();const o={now:Date.now(),timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone};e.applyTransactionalState(e=>jC(e,void 0,n,o).state),e.clearPreferredColumn(),e.focusInput()};return{canUpdateBodyFields:t,updateBodyFields:()=>n("all"),updateSelectedFields:()=>n("selection"),insertDate:()=>{e.applyTransactionalState(e=>function(e,t={}){const n=(t.dateFormat??"M/d/yyyy").trim(),o=t.value??/* @__PURE__ */new Date,r=sr(e.selection)?e:ee(e),{paragraph:a,index:i,offset:s}=oe(r),l=qn(a,s),d=n.length>0&&"M/d/yyyy"!==n?{type:"DATE",dateFormat:n}:{type:"DATE"},u={id:`run:date:${Math.random().toString(36).slice(2,9)}`,text:LC(o,n),kind:"field",field:d,styles:l},p=c(a,[...on(a,0,s),u,...on(a,s,Xr(a))]),g=cr(r),f=[...Ja(g.slice(0,i)),p,...Ja(g.slice(i+1))],m=u.text.length;return qt(r,f,Y(ci(p,s+m)))}(e)),e.focusInput()},insertDateTime:t=>{e.applyTransactionalState(e=>function(e,t="M/d/yyyy",n=/* @__PURE__ */new Date){const o=LC(n,t);return 0===o.length?e:_u(e,o)}(e,t)),e.focusInput()},insertCrossReference:t=>{e.applyTransactionalState(e=>VC(e,t)),e.focusInput()}}}function _C(e){let t=!1,n=!1;const o=(t,n)=>{e.applyTransactionalState(t,{mergeKey:n}),e.focusInput()},r={firstRow:!1,lastRow:!1,firstCol:!1,lastCol:!1,noHBand:!1,noVBand:!1},a=e=>{const t=nr(e),n=Va(e.document,e.selection.focus.paragraphId,t);if(!n)return null;const o=function(e,t,n){if("footnote"===n){const t=e.activeFootnoteId;return t?e.document.footnotes?.items[t]?.blocks??null:null}const o=Pa(e.document)[t];return o?"header"===n?o.header??[]:"footer"===n?o.footer??[]:o.blocks:null}(e,t,n.zone);if(!o)return null;const r=Xa(o,n.tablePath);return r?.[r.length-1]?.table??null},i=e=>{const t=a(e);if(!t)return null;const n=ar(t,e.document.styles);return{...r,...n.tblLook??{}}};return{insideTable:()=>Boolean(Va(e.state().document,e.state().selection.focus.paragraphId,nr(e.state()))),selectionLabel:()=>{const t=e.state();if(mr(t).isCollapsed)return null;const n=nr(t),o=Va(t.document,t.selection.anchor.paragraphId,n),r=Va(t.document,t.selection.focus.paragraphId,n),a=o?.tablePath[o.tablePath.length-1],i=r?.tablePath[r.tablePath.length-1];if(!o||!r||!a||!i||o.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 o=e[n],r=t[n];if(o.tableBlockIndex!==r.tableBlockIndex)return!1;if(n<e.length-1&&(o.rowIndex!==r.rowIndex||o.cellIndex!==r.cellIndex))return!1}return!0}(o.tablePath,r.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=>o(t=>{const n=i(t);if(!n)return t;const o={...n};switch(e){case"firstRow":o.firstRow=!n.firstRow;break;case"lastRow":o.lastRow=!n.lastRow;break;case"firstCol":o.firstCol=!n.firstCol;break;case"lastCol":o.lastCol=!n.lastCol;break;case"bandedRows":o.noHBand=!n.noHBand;break;case"bandedCols":o.noVBand=!n.noVBand}return Ff(t,"tblLook",o)},$g),getStyleId:()=>a(e.state())?.style?.styleId??null,setStyleId:e=>o(t=>Ff(t,"styleId",e||null),Hg),getLayout:()=>a(e.state())?.style?.layout??null,toggleAutoFit:()=>o(e=>Ff(e,"layout","autofit"===a(e)?.style?.layout?"fixed":"autofit"),Wg),canSetAutoFit:()=>null!==hf(e.state()),setAutoFit:e=>o(t=>function(e,t){const n="fixed"===t?"fixed":"autofit";return Pf(e,o=>{let r=o.style;e.trackChangesEnabled&&!r?.revision&&(r={...r??{},revision:{...df(),type:"property",previous:{...r??{}}}});let a=uf(r,"layout",n);return"window"===t?a=uf(a,"width","100%"):"contents"===t&&(a=uf(a,"width",null)),{...o,style:a}})}(t,e),Dg),distributeColumns:()=>o(e=>Pf(e,e=>{const t=Or(e),n=Math.max(1,...t.map(e=>e.visualColumnIndex+Math.max(1,e.colSpan))),o=(e.gridCols??[]).reduce((e,t)=>e+("number"==typeof t&&t>0?t:0),0),r=o>0?o:120*n,a=r/n,i=Array.from({length:n},()=>a),s=e.rows.map((e,n)=>({...e,cells:e.cells.map((e,o)=>{const r=t.find(e=>e.rowIndex===n&&e.cellIndex===o);return r?{...e,style:{...e.style??{},width:a*Math.max(1,r.colSpan)}}:e})}));return{...e,gridCols:i,rows:s,style:{...e.style??{},width:r}}}),Wg),distributeRows:()=>o(e=>Pf(e,e=>{let t=0;for(const o of e.rows){const e=o.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}}),Wg),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!==hf(e.state()),convertToText:()=>o(e=>Hf(e),Pg),canConvertToTable:()=>{return!hf(t=e.state())&&null!==Cf(t);var t},convertToTable:()=>o(e=>Wf(e),Rg),canSplitTableAtRow:()=>function(e){const t=hf(e);if(!t)return!1;const n=If(e);if(!n)return!1;const o=wf(n,t.loc.tablePath);if(!o)return!1;const r=t.loc.rowIndex;return r>0&&r<o.rows.length}(e.state()),splitTableAtRow:()=>o(e=>function(e){const t=hf(e);if(!t)return e;const n=If(e);if(!n)return e;const o=wf(n,t.loc.tablePath);if(!o)return e;const r=t.loc.rowIndex;if(r<=0||r>=o.rows.length)return e;const a=o.rows.slice(0,r),i=o.rows.slice(r),s={...o,rows:a},l=Ga(i),c=kf(e,[s,Ka(""),l]);if(c===e)return e;const d=l.rows[0]?.cells[0]?.blocks.find(e=>"paragraph"===e.type);return d?{...c,selection:Y(ci(d,0))}:e}(e),Bg),canSortTable:()=>function(e){const t=hf(e);if(!t)return!1;const n=If(e);if(!n)return!1;const o=wf(n,t.loc.tablePath);return!!o&&function(e){let t=0;for(const n of e)n.isHeader||(t+=1);return t}(o.rows)>=2}(e.state()),sortTable:e=>o(t=>jf(t,e),"ascending"===e?Mg:Og),canDeleteTable:()=>null!==hf(e.state()),deleteTable:()=>o(e=>function(e){const t=hf(e);if(!t)return e;const n=If(e);if(!n)return e;const o=t.loc.tablePath[0]?.tableBlockIndex;if(void 0===o||"table"!==n[o]?.type)return e;if(1===n.length){const t=Ka(""),n=kf(e,[t]);return n===e?e:{...n,selection:Y(ci(t,0))}}const r=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,o),a=kf(e,[]);if(a===e)return e;if(r){const e=cr(a).find(e=>e.id===r);if(e)return{...a,selection:Y(ci(e,0))}}return a}(e),Ag),canToggleRepeatHeaderRows:()=>function(e){const t=hf(e);if(!t)return!1;const n=If(e);if(!n)return!1;const o=wf(n,t.loc.tablePath);return null!==o&&o.rows.length>0}(e.state()),isRepeatHeaderRowsActive:()=>function(e){const t=hf(e);if(!t)return!1;const n=If(e);if(!n)return!1;const o=wf(n,t.loc.tablePath);return!(!o||0===o.rows.length)&&Kf(o.rows[0])}(e.state()),toggleRepeatHeaderRows:()=>o(e=>function(e){const t=hf(e);if(!t)return e;const n=If(e);if(!n)return e;const o=wf(n,t.loc.tablePath);if(!o||0===o.rows.length)return e;const r=Kf(o.rows[0]);return Pf(e,e=>({...e,rows:e.rows.map((e,t)=>0!==t?e:r?{...e,isHeader:void 0}:{...e,isHeader:!0})}))}(e),Eg),merge:()=>o(t=>e.tableOps.mergeSelectedTable(t),pg),split:()=>o(t=>e.tableOps.splitSelectedTable(t),gg),insertColumnBefore:()=>o(t=>e.tableOps.insertSelectedTableColumn(t,-1),fg),insertColumnAfter:()=>o(t=>e.tableOps.insertSelectedTableColumn(t,1),fg),deleteColumn:()=>o(t=>e.tableOps.deleteSelectedTableColumn(t),mg),insertRowBefore:()=>o(t=>e.tableOps.insertSelectedTableRow(t,-1),hg),insertRowAfter:()=>o(t=>e.tableOps.insertSelectedTableRow(t,1),hg),deleteRow:()=>o(t=>e.tableOps.deleteSelectedTableRow(t),bg),canDeleteCell:()=>am(e.state()),deleteCell:()=>o(e=>im(e),Fg),cellShading:e=>o(t=>Of(t,"shading",e||null),yg),cellBorders:()=>o(e=>Af(e,{width:1,type:"solid",color:"#64748b"}),vg),cellNoBorders:()=>o(e=>Af(e,{width:0,type:"none",color:"transparent"}),vg),applyBorderPreset:e=>o(t=>function(e,t,n=Rf){const o=Mf(e);if(!o)return e;const r=/* @__PURE__ */new Map,a=new Set(o.selectedEntries.map(e=>e.cell.id)),i=/* @__PURE__ */new Map;for(const m of o.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,o=n)=>{if(!e)return;const a=r.get(e.cell.id)??{};a[t]=o,r.set(e.cell.id,a)},l=(e,t,o,r,a=n)=>{s(e,t,a),o&&o.cell.id!==e?.cell.id&&s(o,r,a)},c=(e,t=n)=>{if("top"===e||"bottom"===e){const n="top"===e?o.startRow:o.endRow,r=n+("top"===e?-1:1);for(let s=o.startCol;s<=o.endCol;s+=1){const o=i.get(`${n}:${s}`);o&&a.has(o.cell.id)&&l(o,"top"===e?"borderTop":"borderBottom",i.get(`${r}:${s}`),"top"===e?"borderBottom":"borderTop",t)}return}const r="left"===e?o.startCol:o.endCol,s=r+("left"===e?-1:1);for(let n=o.startRow;n<=o.endRow;n+=1){const o=i.get(`${n}:${r}`);o&&a.has(o.cell.id)&&l(o,"left"===e?"borderLeft":"borderRight",i.get(`${n}:${s}`),"left"===e?"borderRight":"borderLeft",t)}},d=()=>{for(let e=o.startRow+1;e<=o.endRow;e+=1)for(let t=o.startCol;t<=o.endCol;t+=1){const n=i.get(`${e-1}:${t}`),o=i.get(`${e}:${t}`);n&&o&&n.cell.id!==o.cell.id&&a.has(n.cell.id)&&a.has(o.cell.id)&&l(n,"borderBottom",o,"borderTop")}},u=()=>{for(let e=o.startCol+1;e<=o.endCol;e+=1)for(let t=o.startRow;t<=o.endRow;t+=1){const n=i.get(`${t}:${e-1}`),o=i.get(`${t}:${e}`);n&&o&&n.cell.id!==o.cell.id&&a.has(n.cell.id)&&a.has(o.cell.id)&&l(n,"borderRight",o,"borderLeft")}};switch(t){case"none":for(const e of o.selectedEntries)for(const t of["borderTop","borderRight","borderBottom","borderLeft","borderStart","borderEnd","borderTopLeftToBottomRight","borderTopRightToBottomLeft"])s(e,t,Bf);c("top",Bf),c("right",Bf),c("bottom",Bf),c("left",Bf);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 o.selectedEntries)s(e,"borderTopLeftToBottomRight");break;case"diagonalUp":for(const e of o.selectedEntries)s(e,"borderTopRightToBottomLeft")}if(0===r.size)return e;const p=/* @__PURE__ */new Set;for(const m of o.entries)if(r.has(m.cell.id))for(const e of m.cell.blocks)for(const t of ta(e))p.add(t.id);const g=t=>{const n=r.get(t.id);if(!n)return t;let o=t.style;e.trackChangesEnabled&&!o?.propertyRevision&&(o={...o??{},propertyRevision:{...df(),type:"property",previous:{...o??{}}}});for(const[e,r]of Object.entries(n))o=uf(o,e,r);return{...t,style:o}},f=Pa(e.document).map(e=>({...e,blocks:it(e.blocks,p,g),header:e.header?it(e.header,p,g):void 0,footer:e.footer?it(e.footer,p,g):void 0}));return{...e,document:{...e.document,sections:f}}}(t,e),vg),isDrawingBorders:()=>t,toggleDrawingBorders:()=>{t=!t,e.applyState({...e.state()})},isShowingGridlines:()=>n,toggleGridlines:()=>{n=!n,e.applyState({...e.state()})},width100:()=>o(e=>Ff(e,"width","100%"),xg),alignLeft:()=>o(e=>Of(e,"horizontalAlign","left"),wg),alignCenter:()=>o(e=>Of(e,"horizontalAlign","center"),wg),alignRight:()=>o(e=>Of(e,"horizontalAlign","right"),wg),setCellAlignment:e=>o(t=>{return n=t,o=e.horizontal,r=e.vertical,Of(Of(n,"horizontalAlign",o),"verticalAlign",r);var n,o,r},Sg),getCellAlignmentState:()=>function(e){const t=Mf(e);if(!t||0===t.selectedEntries.length)return null;const n=t.selectedEntries.map(({cell:e})=>e.style?.horizontalAlign??"left"),o=t.selectedEntries.map(({cell:e})=>e.style?.verticalAlign??"top"),r=(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:r(n,["left","center","right"]),vertical:r(o,["top","middle","bottom"])}}(e.state()),setCellVerticalAlign:e=>o(t=>Of(t,"verticalAlign",e),Ig),setCellTextDirection:e=>o(t=>Of(t,"textDirection",e),Cg),setCellWidth:e=>o(t=>function(e,t){return Of(e,"width",t)}(t,e),Tg),setCellNoWrap:e=>o(t=>function(e,t){return Of(e,"noWrap",t)}(t,e),Tg),setCellFitText:e=>o(t=>function(e,t){return Of(e,"fitText",t)}(t,e),Tg),canSetCellMargins:()=>null!==hf(e.state()),setCellMargins:e=>o(t=>function(e,t){let n=e;return void 0!==t.top&&(n=Of(n,"paddingTop",t.top)),void 0!==t.right&&(n=Of(n,"paddingRight",t.right)),void 0!==t.bottom&&(n=Of(n,"paddingBottom",t.bottom)),void 0!==t.left&&(n=Of(n,"paddingLeft",t.left)),n}(t,e),Lg),canSetCellSpacing:()=>_f(e.state()),setCellSpacing:e=>o(t=>function(e,t){return _f(e)?Ff(e,"cellSpacing",null===t||t<0?null===t?null:0:Math.round(2*t)/2):e}(t,e),Lg),canSetTableIndent:()=>Xf(e.state()),setTableIndent:e=>o(t=>function(e,t){return Xf(e)?null===t||t<0||Number.isNaN(t)||!Number.isFinite(t)?Ff(e,"indentLeft",null):Ff(e,"indentLeft",Math.round(2*t)/2):e}(t,e),Lg),canSetTableAlignment:()=>null!==hf(e.state()),setTableAlignment:e=>o(t=>qf(t,e),Lg),canEvaluateTableFormula:()=>null!==hf(e.state()),evaluateTableFormula:e=>o(t=>Jf(t,e),Ng),canSelectTable:()=>null!==hf(e.state()),selectTablePart:t=>e.applyState(om(e.state(),t)),canSetActiveTableRowHeight:()=>null!==hf(e.state()),setActiveTableRowHeight:e=>o(t=>function(e,t){let n=e;return n=Ef(n,"height",t.height),void 0!==t.heightRule&&(n=Ef(n,"heightRule",t.heightRule)),n}(t,e),zg),canSetActiveTableRowBreakAcrossPages:()=>Yf(e.state()),setActiveTableRowBreakAcrossPages:e=>o(t=>function(e,t){return Yf(e)?Ef(e,"cantSplit",null===t?null:!t):e}(t,e),zg),canSetActiveTableRowHeader:()=>null!==hf(e.state()),setActiveTableRowHeader:e=>o(t=>Lf(t,e),Eg),canSetActiveTableColumnWidth:()=>null!==hf(e.state()),setActiveTableColumnWidth:e=>o(t=>function(e,t){const n=hf(e);if(!n)return e;const{activeSectionIndex:o,loc:r}=n,a=wf(ff(e.document,o,r.zone),r.tablePath);if(!a)return e;const i=Or(a).find(e=>e.rowIndex===r.rowIndex&&e.cellIndex===r.cellIndex);if(!i)return e;const s=i.visualColumnIndex;return null===t?e:$f(e,a.id,{[s]:t})}(t,e),kg),canSetActiveTableWidth:()=>null!==hf(e.state()),setActiveTableWidth:e=>o(t=>function(e,t){const n=hf(e);if(!n)return e;const{activeSectionIndex:o,loc:r}=n,a=wf(ff(e.document,o,r.zone),r.tablePath);return a?Df(e,a.id,"width",t):e}(t,e),xg),insert:(t,n)=>e.tableOps.insertTableCommand(t,n)}}function XC(e){const t=t=>e.applyTransactionalState(t);return{applyTheme:e=>t(t=>QS(t,e)),setColorScheme:e=>t(t=>function(e,t){const n=YS[t]??YS.oasis,o=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 o=/^heading[1-9]$/i.test(e)||/title|quote/i.test(e);return[e,{...t,textStyle:{...t.textStyle??{},color:o?n.heading:n.color}}]}));return{...e,document:{...e.document,styles:o,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,o]=ZS[t]??ZS.aptos,r=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)?o: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:o.split(",")[0].trim()},minor:{...e.document.design?.themeData?.fonts?.minor??{},minorHAnsi:n.split(",")[0].trim()}}}},styles:r}}}(t,e)),setParagraphSpacing:e=>t(t=>function(e,t){const n={compact:[0,4],tight:[0,6],open:[0,10],relaxed:[4,12]},[o,r]=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:o,spacingAfter:r}}]:[e,t]));return{...e,document:{...e.document,design:{...e.document.design??{},paragraphSpacingId:t},styles:a}}}(t,e)),setEffects:e=>t(t=>JS(t,{effectsId:e,themeData:{...t.document.design?.themeData??{},sourceXml:void 0,effectsXml:void 0}})),setPageColor:e=>t(t=>function(e,t){return JS(e,{pageColor:t})}(t,e)),setWatermark:e=>t(t=>function(e,t){return JS(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 GC(e){return function(e){const t=(n=e.gate.isCommandEnabled,(e,t,o)=>({execute:t,refresh:()=>{const t=o?.()??{};return{...t,isEnabled:n(e)&&(t.isEnabled??!0)}}}));var n;const o=function(e){return(t,n,o)=>({execute:n,refresh:()=>({isEnabled:e(t),value:o()})})}(e.gate.isCommandEnabled),r=function(e){return(t,n,o)=>({execute:e=>(n(e),!0),refresh:()=>{const n=o?.()??{};return{...n,isEnabled:e(t)&&(n.isEnabled??!0)}}})}(e.gate.isCommandEnabled);return{name:"Essentials",commands:{...oI({gate:e.gate,style:e.style,selection:e.selection,history:e.history,formatting:e.formatting,dialog:e.dialog,link:e.link,command:t,valueCommand:o,actionCommand:r}),...rI({gate:e.gate,style:e.style,document:e.document,link:e.link,image:e.image,browser:e.browser,actionCommand:r}),...aI({style:e.style,paragraph:e.paragraph,section:e.section,valueCommand:o,actionCommand:r}),...uI({dialog:e.dialog,actionCommand:r}),...iI({gate:e.gate,headerFooter:e.headerFooter,command:t,actionCommand:r}),...cI({gate:e.gate,table:e.table,actionCommand:r,valueCommand:o}),...dI({design:e.design,actionCommand:r}),...sI({bookmark:e.bookmark,actionCommand:r}),...lI({fields:e.fields,actionCommand:r})}}}({gate:mI(e),style:hI(e),selection:bI(e),history:yI(e),formatting:WI(e),document:ZI(e),link:JI(e),image:QI(e),browser:eC(e),paragraph:mC(e),section:MC(e),headerFooter:OC(e),table:_C(e),design:XC(e),bookmark:FC(e),fields:KC(e),dialog:{openFontDialog:e.openFontDialog,openParagraphDialog:e.openParagraphDialog,requestAcceptAllRevisions:e.requestAcceptAllRevisions,requestRejectAllRevisions:e.requestRejectAllRevisions}})}var qC=[{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 YC(e){const t=GC(e.essentials),{runtimePlugins:n,toolbarRegistry:o,menuRegistry:r,dispose:a}=function(e){const t=[e.essentialsPlugin,...e.externalPlugins??[]],n=[],o=[],r=fo(),a=new hn;for(const i of no(e.t))r.register(i);for(const i of qC)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};r.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}),o.push(e.id)}return e.customizeToolbar?.(r),e.customizeMenubar?.(a),{runtimePlugins:t,toolbarRegistry:r,menuRegistry:a,dispose:()=>{for(const e of n)r.remove(e);for(const e of o)a.unregister(e)}}}({essentialsPlugin:t,externalPlugins:e.externalPlugins,t:e.t,customizeToolbar:e.customizeToolbar,customizeMenubar:e.customizeMenubar}),i=function(e){const[t,n]=co(!1),[o,r]=co(new Jn({doc:e.initialDocument}));let a=!1;const i=e=>{const t=we(e),n=o().commands.get(t);if(!n)return{isEnabled:!1,isActive:!1,value:void 0};const r=n.refresh?.()??{isEnabled:!0};return{isEnabled:!1!==r.isEnabled,isActive:Boolean(r.isActive),value:r.value}};return{runtimeReady:t,runtimeEditor:o,commandStateOf:i,toolbarHost:()=>({commands:{execute:(e,t)=>{const n=Lo(e,t);return o().commands.execute(n.name,n.payload)},canExecute:(e,t)=>{const n=Lo(e,t);return o().commands.canExecute(n.name,n.payload)},state:i},focusEditor:e.focusEditor}),initialize:async()=>{try{const t=await Jn.create({doc:e.initialDocument,plugins:e.runtimePlugins});if(e.onExecuted&&(t.commands.onExecuted=e.onExecuted),a)return void(await t.destroy());const i=o();r(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 o().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 Xt(()=>{i.initialize()}),yn(()=>{i.dispose(),a()}),{toolbarRegistry:o,menuRegistry:r,runtimeReady:i.runtimeReady,runtimeEditor:i.runtimeEditor,commandStateOf:i.commandStateOf,toolbarHost:i.toolbarHost}}var ZC=/* @__PURE__ */new Set(["undo","redo","repeatLastAction","find","replace","replaceAll","print","newDocument","saveDocument","insertHtml","insertImageFromFile","openSymbolDialog","openEquationDialog","openCommandSearch","importDocument","exportDocx","exportPdf"]);function JC(e,t){let n=null;return{lastCommand:()=>n?.command??null,record:(e,t)=>{(function(e){return!ZC.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 QC(e){return function(e){const{document:t,interaction:o,runtimeClient:r}=e,{commandsController:a,keyboardCommandsController:i}=zS({state:e.state,logger:e.logger,applyState:e.applyState,applyTransactionalState:t.applyTransactionalState,clearPreferredColumn:t.clearPreferredColumn,resetTransactionGrouping:t.resetTransactionGrouping,focusInput:e.focusInput,selectedImageRun:o.selectedImageRun,tableOps:o.tableOps,toolbarStyleState:o.styleController.toolbarStyleState,applyBooleanStyleCommand:e=>o.styleController.applyToolbarBooleanStyleCommand(e),locale:e.locale,setLinkDialog:e.setLinkDialog,setImageAltDialog:e.setImageAltDialog,setImageCaptionDialog:e.setImageCaptionDialog,setFontDialog:e.setFontDialog,setParagraphDialog:e.setParagraphDialog});let s;const l=JC((e,t)=>{if(!s)throw new Error("repeat tracking used before ready");return s().commands.execute(e,t)},(e,t)=>!!s&&s().commands.canExecute(e,t)),c=()=>{l.execute()},d=()=>l.canExecute(),{runtimeReady:u,runtimeEditor:p,commandStateOf:g,toolbarHost:f,toolbarRegistry:m,menuRegistry:h}=YC({essentials:{clipboardActions:e.clipboardActions,state:()=>e.state,isReadOnly:e.isReadOnly,forcePlainTextPaste:{get:e.getForcePlainTextPaste,set:e.setForcePlainTextPaste},undoStack:t.undoStack,redoStack:t.redoStack,commandsController:a,keyboardCommandsController:i,historyActions:t.historyActions,styleController:o.styleController,formatPainter:o.formatPainter,commentComposer:e.commentComposer,tableOps:o.tableOps,docIO:t.docIO,importInputRef:e.importInputRef,imageInputRef:e.imageInputRef,selectedImageRun:o.selectedImageRun,imageCropMode:{isActive:o.imageOps.cropMode,toggle:o.imageOps.toggleCropMode},selectionBoxes:t.selectionBoxes,focusInput:e.focusInput,clearPreferredColumn:t.clearPreferredColumn,resetTransactionGrouping:t.resetTransactionGrouping,applyState:e.applyState,applyTransactionalState:t.applyTransactionalState,findReplace:{setIsOpen:o.fr.setIsOpen},newDocument:$S({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:c,canRepeatLastAction:d,openTablePropertiesDialog:t=>{const n=fm(e.state,t??"table");n&&e.setTablePropertiesDialog({isOpen:!0,initial:n})},openEquationDialog:()=>{const t=e.state.selection.focus,n=ya(e.state.document).find(e=>e.id===t.paragraphId);if("paragraph"===n?.type){let o=0;for(const r of n.runs){if("math"===r.kind&&t.offset>=o&&t.offset<=o+r.text.length)return void e.setEquationDialog({isOpen:!0,initial:r.math,targetRunId:r.id});o+=r.text.length}}e.setEquationDialog({isOpen:!0})},openFontDialog:a.openFontDialog,openParagraphDialog:a.openParagraphDialog,requestAcceptAllRevisions:()=>{e.setRevisionBulkDialog({isOpen:!0,action:"accept",count:MS(e.state).size})},requestRejectAllRevisions:()=>{e.setRevisionBulkDialog({isOpen:!0,action:"reject",count:MS(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)=>{l.record(t,n),e.onExecutedTap?.()},onReady:t=>{s=()=>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(jo(e)),t.resetEditorChromeState(),t.focusInput()},applyTransactionalState:t.applyTransactionalState,resetDocument:()=>{let e=Sa();try{const t=globalThis.localStorage?.getItem("oasis-design-default");if(t){const n=JSON.parse(t);n.themeId&&(e=QS(e,n.themeId)),e=JS(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:u,runtimeEditor:p,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:m,menuRegistry:h}),Zn(()=>{if(!u())return;e.state.document,e.state.selection,e.state.activeSectionIndex,e.state.activeZone;const t=e.cloneState(e.getStateSnapshot());p().dispatch(()=>t)});const{handleKeyDown:b}=function(e){const{state:t,isReadOnly:o,logger:r,focusInput:a,clearPreferredColumn:i,resetTransactionGrouping:s,applyState:l,applyTransactionalState:c,setForcePlainTextPaste:d,selectedImageRun:u,commandsController:p,tableOps:g,navigation:f,historyActions:m,styleController:h,findReplace:b,commandSearch:y,runtimeEditor:v}=e,{handleKeyDown:x}=XS({state:t,isReadOnly:o,clearPreferredColumn:i,resetTransactionGrouping:s,applyState:l,applyTransactionalState:c,applyTableAwareParagraphEdit:g.applyTableAwareParagraphEdit,applySelectionAwareParagraphCommand:g.applySelectionAwareParagraphCommand,focusInput:a,commandsController:p,pendingCaretTextStyle:h.pendingCaretTextStyle,autoTabIndentEnabled:C,isMacPlatform:()=>"undefined"!=typeof navigator&&/Mac|iPhone|iPad/.test(navigator.platform),isCaretAtWrappedLineStart:f.isCaretAtWrappedLineStart,selectedImageRun:u,setForcePlainTextPaste:d,moveSelectionByWord:f.moveSelectionByWord,moveSelectionToDocumentBoundary:f.moveSelectionToDocumentBoundary,moveSelectionToParagraphBoundary:f.moveSelectionToParagraphBoundary,moveSelectedImageByParagraph:m.moveSelectedImageByParagraph,performUndo:m.performUndo,performRedo:m.performRedo,moveVerticalSelection:f.moveVerticalSelection,moveVerticalByBlock:f.moveVerticalByBlock,resolveAdjacentTableCellPosition:g.resolveAdjacentTableCellPosition,resolveTableTabTarget:g.resolveTableTabTarget,appendTableRowForTab:g.appendTableRowForTab,applySelectionPreservingStructure:m.applySelectionPreservingStructure,toggleFindReplace:e=>{b.setIsOpen(e??!b.isOpen())},toggleReplace:e=>{b.setIsOpen(e??!b.isOpen())},toggleCommandSearch:e=>{y.setIsOpen(e??!y.isOpen())},executeCommand:(e,t)=>v().commands.execute(e,t),canExecuteCommand:e=>v().commands.canExecute(e)});return{handleKeyDown:e=>{GS.includes(e.key)&&h.clearPendingCaretTextStyle();const o=[e.ctrlKey?"Ctrl":null,e.metaKey?"Meta":null,e.altKey?"Alt":null,e.shiftKey?"Shift":null].filter(Boolean).join("+"),a=o?`${o}+${e.key}`:e.key,i=t().selection;r.debug(`key:down ${a} at ${i.anchor.paragraphId}:${i.anchor.runId}[${i.anchor.offset}]`),n("input-to-layout"),x(e),be("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:o.selectedImageRun,commandsController:i,tableOps:o.tableOps,navigation:o.navigation,historyActions:t.historyActions,styleController:o.styleController,findReplace:o.fr,commandSearch:e.commandSearch,runtimeEditor:p});return{commandsController:a,runtimeReady:u,runtimeEditor:p,commandStateOf:g,toolbarHost:f,toolbarRegistry:m,menuRegistry:h,handleKeyDown:b}}(e)}function eT(e,t){const n=e.document.comments?.items;if(!n?.[t])return null;const o=/* @__PURE__ */new Set;let r=t;for(;n[r]?.parentId&&!o.has(r);){o.add(r);const e=n[r].parentId;if(!n[e])break;r=e}return r}function tT(e,t,n){if(t.document===e.document)return e;const o=e.document.comments?.items[n.commentId]??t.document.comments?.items[n.commentId];if(!o)return t;const r=eT(e,n.commentId)??eT(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:r,...n.parentId?{parentId:n.parentId}:{},actorName:n.actorName,...n.actorId?{actorId:n.actorId}:{},targetAuthor:o.author,timestamp:n.timestamp,..."comment-deleted"===n.kind?{affectedCount:Math.max(1,a-i)}:{}})}function nT(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 oT(e,t,n){if(!t?.items[n])return!1;if(!e||e.canModerate)return!0;if(!nT(e,t.items[n]))return!1;const o=/* @__PURE__ */new Set([n]),r=[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(;r.length;){const n=r.pop();for(const i of a.get(n)??[])if(!o.has(i)){if(o.add(i),!nT(e,t.items[i]))return!1;r.push(i)}}return!0}function rT(e){const[t,n]=co(null),[o,r]=co(""),[a,i]=co(!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!==Tn(e.state()),u=t=>c()&&Boolean(e.state().document.comments?.items[t]),p=()=>c()&&null!==MI(e.state()),g=t=>!e.isReadOnly()&&nT(s(),e.state().document.comments?.items[t]),f=()=>{const t=MI(e.state());return null!==t&&g(t.id)},m=t=>!e.isReadOnly()&&oT(s(),e.state().document.comments,t),h=g,b=(e="Local editor")=>{const t=l();return t?{actorName:t.displayName,actorId:t.id}:{actorName:e}},y=(e,t,n,o,r,a)=>tT(e,t,{id:Da("review-activity"),kind:n,commentId:o,...b(r),timestamp:Date.now(),...a?{parentId:a}:{}}),v=t=>{if(!u(t))return!1;const o=e.state(),r=o.document.comments?.items[t];return!!r&&(n({mode:"reply",snapshot:o,parentId:r.id,parentAuthor:r.author,parentText:r.text}),!0)},x=t=>{if(!g(t))return!1;const o=e.state(),r=o.document.comments?.items[t];return!!r&&(n({mode:"edit",snapshot:o,commentId:t,commentAuthor:r.author,commentText:r.text}),!0)},w=()=>{n(null),e.focusInput()},S=t=>{if(!m(t))return!1;const n=e.state();let o=!1;return e.applyTransactionalState(r=>{if(e.isReadOnly()||r.document!==n.document||!oT(s(),r.document.comments,t))return r;const a=function(e,t){const n=e.document.comments;if(!n?.items[t])return e;const o=/* @__PURE__ */new Set([t]),r=[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(;r.length>0;){const e=r.pop();for(const t of a.get(e)??[])o.has(t)||(o.add(t),r.push(t))}const i=Object.fromEntries(Object.entries(n.items).filter(([e])=>!o.has(e)));return{...e,document:{...e.document,comments:{...n,items:i,order:n.order.filter(e=>!o.has(e))}}}}(r,t);return o=a.document!==r.document,o?y(r,a,"comment-deleted",t):a}),o},I=(t,n)=>{if(!h(t))return!1;const o=e.state();let r=!1;return e.applyTransactionalState(a=>{if(e.isReadOnly()||a.document!==o.document||!nT(s(),a.document.comments?.items[t]))return a;const i=function(e,t,n){const o=e.document.comments,r=o?.items[t];return o&&r&&Boolean(r.resolved)!==n?{...e,document:{...e.document,comments:{...o,items:{...o.items,[t]:{...r,resolved:n}}}}}:e}(a,t,n);return r=i.document!==a.document,r?y(a,i,n?"comment-resolved":"comment-reopened",t):i}),r};return{draft:t,lastAuthor:o,panelOpen:a,togglePanel:()=>(i(!a()),!0),closePanel:()=>{i(!1)},canCreate:d,canReply:p,canReplyId:u,canEdit:f,canEditId:g,canDeleteId:m,canDeleteSelected:()=>{const t=MI(e.state());return null!==t&&m(t.id)},deleteSelected:()=>{const t=MI(e.state());return!!t&&S(t.id)},deleteById:S,canResolveId:h,canResolveSelected:()=>{const t=MI(e.state());return null!==t&&h(t.id)},resolveSelected:t=>{const n=MI(e.state());return!!n&&I(n.id,t)},resolveById:I,authorName:()=>l()?.displayName??o(),authorLocked:()=>void 0!==s(),openNew:()=>!!d()&&(n({mode:"new",snapshot:e.state()}),!0),openReply:()=>{if(!p())return!1;const t=MI(e.state());return!!t&&v(t.id)},openReplyToId:v,openEdit:()=>{if(!f())return!1;const t=MI(e.state());return!!t&&x(t.id)},openEditToId:x,close:w,submit:(n,o)=>{const a=t();if(!a||e.isReadOnly())return!1;if("edit"===a.mode&&!g(a.commentId))return!1;if("edit"!==a.mode&&!c())return!1;const i="edit"===a.mode?a.commentAuthor?.trim()??"":l()?.displayName??n.trim(),d=o.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:Da("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&&!nT(s(),t.document.comments?.items[a.commentId]))return t;if("edit"!==a.mode&&!c())return t;const n="edit"===a.mode?ao(t,a.commentId,d):"reply"===a.mode?tn(t,a.parentId,u):Xn({...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&&r(i),w()),p}}}var aT=/*#__PURE__*/oo("<div class=oasis-review-comments-filters role=group>"),iT=/*#__PURE__*/oo("<div class=oasis-review-comments-list>"),sT=/*#__PURE__*/oo("<div class=oasis-review-activity-list data-testid=review-activity-list role=list>"),lT=/*#__PURE__*/oo("<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>"),cT=/*#__PURE__*/oo("<div class=oasis-review-thread-replies>"),dT=/*#__PURE__*/oo("<div class=oasis-review-thread><div class=oasis-review-thread-header></div><div class=oasis-review-thread-actions>"),uT=/*#__PURE__*/oo("<div class=oasis-review-reply><div class=oasis-review-thread-actions>"),pT=/*#__PURE__*/oo("<div class=oasis-review-activity-entry role=listitem data-testid=review-activity-entry><div class=oasis-review-activity-heading>");function gT(e){const t=Ee(),[n,o]=co("all"),[r,a]=co(!1),[i,s]=co(""),[l,c]=co(null),[d,u]=co(null),p=()=>e.state().document.comments,g=wt(()=>{const e=p();if(!e)return[];const t=i().trim().toLocaleLowerCase();return e.order.map(t=>e.items[t]).filter(t=>Boolean(t&&(!t.parentId||!e.items[t.parentId]))).filter(o=>("open"!==n()||!o.resolved)&&(!("resolved"===n()&&!o.resolved)&&(!t||[o,...Ft(e.items,o.id)].some(e=>(e.text+" "+e.author).toLocaleLowerCase().includes(t)))))}),f=e=>Ft(p()?.items??{},e),m=wt(()=>{const t=i().trim().toLocaleLowerCase();return[...e.state().document.reviewActivity??[]].filter(e=>!t||(e.actorName+" "+e.targetAuthor+" "+e.kind).toLocaleLowerCase().includes(t)).reverse()}),h=t=>Number.isFinite(t)?new Date(t).toLocaleString(e.locale?.()??"pt-BR"):"",b=t=>{d()===t?e.composer.deleteById(t)&&(u(null),l()===t&&c(null)):u(t)};return y=lT(),v=y.firstChild,x=v.nextSibling,W(v,Bn(At,{as:"strong",get children(){return t("review.commentsPanel")}}),null),W(v,Bn(St,{size:"sm",variant:"ghost",get onClick(){return e.onClose},"data-testid":"review-comments-close",get"aria-label"(){return t("generic.close")},children:"✕"}),null),W(x,Bn(St,{size:"sm",variant:"ghost",get"aria-pressed"(){return!r()},onClick:()=>{a(!1)},"data-testid":"review-show-discussions",get children(){return t("review.commentsPanel")}}),null),W(x,Bn(St,{size:"sm",variant:"ghost",get"aria-pressed"(){return r()},onClick:()=>{a(!0)},"data-testid":"review-show-activity",get children(){return t("review.activity.title")}}),null),W(y,Bn(At,{as:"p",get children(){return qe(()=>!!r())()?`${t("review.activity.title")}: ${e.state().document.reviewActivity?.length??0}`:`${t("review.discussionCount")}: ${p()?.order.length??0}`}}),null),W(y,Bn(k,{get label(){return qe(()=>!!r())()?t("review.activity.search"):t("review.searchComments")},get value(){return i()},onChange:s,"data-testid":"review-comments-search"}),null),W(y,Bn(Qt,{get when(){return!r()},get children(){return[(a=aT(),W(a,Bn(St,{size:"sm",variant:"ghost",get"aria-pressed"(){return"all"===n()},onClick:()=>{o("all")},get children(){return t("review.filterAll")}}),null),W(a,Bn(St,{size:"sm",variant:"ghost",get"aria-pressed"(){return"open"===n()},onClick:()=>{o("open")},get children(){return t("review.filterOpen")}}),null),W(a,Bn(St,{size:"sm",variant:"ghost",get"aria-pressed"(){return"resolved"===n()},onClick:()=>{o("resolved")},get children(){return t("review.filterResolved")}}),null),gn(()=>et(a,"aria-label",t("review.filterComments"))),a),(r=iT(),W(r,Bn(Qt,{get when(){return 0===g().length},get children(){return Bn(At,{as:"p",get children(){return t("review.noComments")}})}}),null),W(r,Bn(Kn,{get each(){return g()},children:n=>{return o=dT(),r=o.firstChild,a=r.nextSibling,W(r,Bn(At,{as:"strong",get children(){return n.author||"—"}}),null),W(r,Bn(At,{as:"span",get children(){return qe(()=>!!n.resolved)()?t("review.filterResolved"):t("review.filterOpen")}}),null),W(o,Bn(At,{as:"p",get children(){return n.text}}),a),W(a,Bn(St,{size:"sm",variant:"ghost",onClick:()=>e.onNavigate(n.id),"data-testid":"review-comment-navigate",get children(){return t("review.goToComment")}}),null),W(a,Bn(Qt,{get when(){return e.composer.canEditId(n.id)},get children(){return Bn(St,{size:"sm",variant:"ghost",onClick:()=>{e.composer.openEditToId(n.id)},"data-testid":"review-comment-edit",get children(){return t("toolbar.editComment")}})}}),null),W(a,Bn(Qt,{get when(){return e.composer.canResolveId(n.id)},get children(){return Bn(St,{size:"sm",variant:"ghost",onClick:()=>{e.composer.resolveById(n.id,!n.resolved)},"data-testid":"review-comment-resolve",get children(){return qe(()=>!!n.resolved)()?t("toolbar.reopenComment"):t("toolbar.resolveComment")}})}}),null),W(a,Bn(Qt,{get when(){return e.composer.canReplyId(n.id)},get children(){return Bn(St,{size:"sm",variant:"ghost",onClick:()=>{e.composer.openReplyToId(n.id)},"data-testid":"review-comment-reply",get children(){return t("toolbar.replyComment")}})}}),null),W(a,Bn(Qt,{get when(){return e.composer.canDeleteId(n.id)},get children(){return[Bn(St,{size:"sm",variant:"ghost",onClick:()=>b(n.id),"data-testid":"review-comment-delete",get children(){return qe(()=>d()===n.id)()?t("review.confirmDelete"):t("toolbar.deleteComment")}}),Bn(Qt,{get when(){return d()===n.id},get children(){return Bn(St,{size:"sm",variant:"ghost",onClick:()=>{u(null)},get children(){return t("generic.cancel")}})}})]}}),null),W(o,Bn(Qt,{get when(){return f(n.id).length>0},get children(){return Bn(St,{size:"sm",variant:"ghost",get"aria-expanded"(){return l()===n.id},"data-testid":"review-toggle-replies",onClick:()=>{c(l()===n.id?null:n.id)},get children(){return qe(()=>l()===n.id)()?t("comment.showFewerReplies"):`${t("comment.showAllReplies")} (${f(n.id).length})`}})}}),null),W(o,Bn(Qt,{get when(){return l()===n.id},get children(){var o=cT();return W(o,Bn(Kn,{get each(){return f(n.id)},children:n=>{return o=uT(),r=o.firstChild,W(o,Bn(At,{as:"strong",get children(){return n.author||"—"}}),r),W(o,Bn(At,{as:"p",get children(){return n.text}}),r),W(r,Bn(Qt,{get when(){return e.composer.canEditId(n.id)},get children(){return Bn(St,{size:"sm",variant:"ghost",onClick:()=>{e.composer.openEditToId(n.id)},"data-testid":"review-reply-edit",get children(){return t("toolbar.editComment")}})}}),null),W(r,Bn(Qt,{get when(){return e.composer.canReplyId(n.id)},get children(){return Bn(St,{size:"sm",variant:"ghost",onClick:()=>{e.composer.openReplyToId(n.id)},get children(){return t("toolbar.replyComment")}})}}),null),W(r,Bn(Qt,{get when(){return e.composer.canDeleteId(n.id)},get children(){return[Bn(St,{size:"sm",variant:"ghost",onClick:()=>b(n.id),"data-testid":"review-reply-delete",get children(){return qe(()=>d()===n.id)()?t("review.confirmDelete"):t("toolbar.deleteComment")}}),Bn(Qt,{get when(){return d()===n.id},get children(){return Bn(St,{size:"sm",variant:"ghost",onClick:()=>{u(null)},get children(){return t("generic.cancel")}})}})]}}),null),gn(()=>et(o,"data-comment-id",n.id)),o;var o,r}})),o}}),null),gn(()=>et(o,"data-comment-id",n.id)),o;var o,r,a}}),null),r)];var r,a}}),null),W(y,Bn(Qt,{get when(){return r()},get children(){var n=sT();return W(n,Bn(Qt,{get when(){return 0===m().length},get children(){return Bn(At,{as:"p",get children(){return t("review.activity.empty")}})}}),null),W(n,Bn(Kn,{get each(){return m()},children:n=>{return o=pT(),r=o.firstChild,W(r,Bn(At,{as:"strong",get children(){return n.actorName}}),null),W(r,Bn(At,{as:"span",get children(){return h(n.timestamp)}}),null),W(o,Bn(At,{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")}})(n.kind))," — ",qe(()=>n.targetAuthor),qe(()=>qe(()=>!!(n.affectedCount&&n.affectedCount>1))()?` (${n.affectedCount})`:"")]}}),null),W(o,Bn(Qt,{get when(){return Boolean(p()?.items[n.commentId])},get children(){return Bn(St,{size:"sm",variant:"ghost","data-testid":"review-activity-navigate",onClick:()=>e.onNavigate(n.commentId),get children(){return t("review.goToComment")}})}}),null),gn(()=>et(o,"data-activity-kind",n.kind)),o;var o,r}}),null),gn(()=>et(n,"aria-label",t("review.activity.title"))),n}}),null),gn(e=>{var n=t("review.commentsPanel"),o=t("review.displayMode");return n!==e.e&&et(y,"aria-label",e.e=n),o!==e.t&&et(x,"aria-label",e.t=o),e},{e:void 0,t:void 0}),y;var y,v,x}var fT="oasis-reviewing-pane-v1",mT={open:!1,scrollTop:0};function hT(e){return"number"==typeof e&&Number.isFinite(e)&&e>=0?e:0}function bT(){const e=function(){try{const e=globalThis.localStorage?.getItem(fT);if(!e)return mT;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 mT;const n=t;return{open:!0===n.open,scrollTop:hT(n.scrollTop)}}catch{return mT}}(),[t,n]=co(e.open),[o,r]=co(e.scrollTop),a=()=>{!function(e){try{globalThis.localStorage?.setItem(fT,JSON.stringify(e))}catch{}}({open:t(),scrollTop:o()})},i=e=>{n(e),a()};return{open:()=>t(),toggle:()=>(i(!t()),!0),close:()=>{i(!1)},scrollTop:()=>o(),setScrollTop:e=>{const t=hT(e);t!==o()&&(r(t),a())}}}var yT=/*#__PURE__*/oo("<ul class=oasis-review-revisions-list data-testid=review-revisions-list>"),vT=/*#__PURE__*/oo("<div class=oasis-review-revision-footer>"),xT=/*#__PURE__*/oo('<div role=region class="oasis-review-comments-panel oasis-review-revisions-panel"data-testid=review-revisions-panel><div class=oasis-review-comments-heading>'),wT=/*#__PURE__*/oo("<li class=oasis-review-revision-item><div class=oasis-review-revision-body></div><div class=oasis-review-revision-actions>");function ST(e,t){const n=cr(e),o=[];for(const a of n)for(const e of a.runs)e.revision?.id!==t&&e.styles?.propertyRevision?.id!==t||o.push(e.text);const r=o.join("").trim();return r.length>96?`${r.slice(0,93)}…`:r}function IT(e){const t=Ee(),n=wt(()=>{const t=e.state(),n=cr(t),o=/* @__PURE__ */new Map,r=/* @__PURE__ */new Map;for(const e of n)for(const t of e.runs){const e=t.revision;e&&(o.has(e.id)||o.set(e.id,e.author),r.has(e.id)||r.set(e.id,{date:e.date,type:e.type}));const n=t.styles?.propertyRevision;n&&(o.has(n.id)||o.set(n.id,n.author),r.has(n.id)||r.set(n.id,{date:n.date,type:"property"}))}const a=new Map(zv(t).map(e=>[e.id,e])),i=new Map($v(t).map(e=>[e.id,e]));return kI(t).map(e=>{const n=r.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:o.get(e.id)??s?.author??l?.author??"—",date:n?.date??s?.date??l?.date,snippet:ST(t,e.id)||s?.snippet||l?.snippet||"",section:void 0!==l}})}),o=wt(()=>{const t=e.state();return n().filter(e=>Vv(t,e.type,e.author))});let r,a=!1;const i=()=>{const t=r,n=e.scrollTop;!t||"number"!=typeof n||n<=0||t.scrollHeight<=t.clientHeight||(t.scrollTop=n,a=!0,t.scrollTop!==n&&e.onScroll?.(t.scrollTop))};Zn(()=>{o().length,a||queueMicrotask(i)});return s=xT(),l=s.firstChild,W(l,Bn(At,{as:"strong",get children(){return t("review.reviewingPane")}}),null),W(l,Bn(St,{size:"sm",variant:"ghost",get onClick(){return e.onClose},"data-testid":"review-revisions-close",get"aria-label"(){return t("generic.close")},children:"✕"}),null),W(s,Bn(At,{as:"p",get children(){return[qe(()=>t("review.revisionCount")),": ",qe(()=>o().length)]}}),null),W(s,Bn(Qt,{get when(){return n().length-o().length>0},get children(){return Bn(At,{as:"p",class:"oasis-review-revisions-filtered","data-testid":"review-revisions-filtered",get children(){return t("review.revisionsHiddenByShowMarkup")}})}}),null),W(s,Bn(Qt,{get when(){return o().length>0},get fallback(){return Bn(At,{as:"p",get children(){return t("review.noRevisions")}})},get children(){var n=yT();return n.addEventListener("scroll",t=>{e.onScroll?.(t.currentTarget.scrollTop)}),In(e=>{r=e,queueMicrotask(i)},n),W(n,Bn(Kn,{get each(){return o()},children:n=>{return o=wT(),r=o.firstChild,a=r.nextSibling,W(r,Bn(At,{as:"span",get class(){return"oasis-review-revision-type "+(e=n.type,n.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 n.type},get children(){return[Bn(_n,{get name(){return"delete"===(e=n.type)?"minus":"insert"===e?"plus":"pencil";var e}}),Bn(At,{as:"span",get children(){return e=n.type,o=n.section,t(o?"review.revisionSection":"insert"===e||"delete"===e?"insert"===e?"review.revisionInsert":"review.revisionDelete":"grid"===e?"review.revisionGrid":"review.revisionProperty");var e,o}})]}}),null),W(r,Bn(At,{as:"p",get children(){return n.snippet||"—"}}),null),W(r,Bn(At,{as:"span",get children(){return n.author}}),null),W(a,Bn(St,{size:"sm",variant:"ghost",onClick:()=>e.onNavigate(n.id),"data-testid":"review-revision-navigate",get children(){return t("review.goToComment")}}),null),W(a,Bn(St,{size:"sm",variant:"ghost",onClick:()=>e.onAccept(n.id),"data-testid":"review-revision-accept",get children(){return t("toolbar.accept")}}),null),W(a,Bn(St,{size:"sm",variant:"ghost",onClick:()=>e.onReject(n.id),"data-testid":"review-revision-reject",get children(){return t("toolbar.reject")}}),null),gn(e=>{var t=n.id,r=n.section?"true":void 0;return t!==e.e&&et(o,"data-comment-id",e.e=t),r!==e.t&&et(o,"data-revision-section",e.t=r),e},{e:void 0,t:void 0}),o;var o,r,a}})),n}}),null),W(s,Bn(Qt,{get when(){return o().length>0},get children(){var n=vT();return W(n,Bn(St,{size:"sm",variant:"ghost",get onClick(){return e.onRejectAll},"data-testid":"review-revisions-reject-all",get children(){return t("toolbar.rejectAll")}}),null),W(n,Bn(St,{size:"sm",variant:"primary",get onClick(){return e.onAcceptAll},"data-testid":"review-revisions-accept-all",get children(){return t("toolbar.acceptAll")}}),null),n}}),null),gn(()=>et(s,"aria-label",t("review.reviewingPane"))),s;var s,l}var CT=/*#__PURE__*/oo('<div class="oasis-editor-shell oasis-editor-app">');function TT(e={}){const t=e.runtime?.client??Ln(),[n,o]=co({}),r=()=>({...e.ui??{},...n(),toolbar:{...e.ui?.toolbar??{},...n().toolbar??{}}}),a=()=>({...e.document??{},...void 0===n().readOnly?{}:{readOnly:n().readOnly}}),i=()=>({...r(),readOnly:a().readOnly}),s=e=>(o(t=>({...t,...e,toolbar:{...t.toolbar??{},...e.toolbar??{}}})),{...i(),...e}),l=()=>e.runtime??{};Dp();const c=We(()=>r().locale??"pt-BR"),u=Mn("app"),{state:p,commitState:g,getStateSnapshot:m}=function(e){const t=e.initialState?Zt(e.initialState):e.initialDocument?jo(e.initialDocument):Sa();let n=t;const[o,r]=co(t),a=new Proxy({},{get(e,t){const n=o();if(null!==n&&("object"==typeof n||"function"==typeof n))return Reflect.get(n,t)},has(e,t){const n=o();return null!==n&&("object"==typeof n||"function"==typeof n)&&Reflect.has(n,t)},ownKeys(e){const t=o();return null===t||"object"!=typeof t&&"function"!=typeof t?[]:Reflect.ownKeys(t)},getOwnPropertyDescriptor(e,t){const n=o();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:r,commitState:e=>{const t=jr(e===a?n:e);n=t,r(t)},getStateSnapshot:()=>n}}({initialDocument:a().initialDocument,initialState:a().initialState}),h=e=>{g(e)},b=Zt;let y=!1;const{showChrome:x,showTitleBar:w,showMenubar:S,showToolbar:I,showOutline:C,showRuler:T,toggleOutline:k,toolbarView:P,toolbarLayout:R,isReadOnly:M,useComposedShell:O,loadingOptions:A,loadingLabel:F,shellComponent:D}=function(e){const{ui:t,documentOptions:n,updateUiState:o,state:r}=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:()=>{o({showOutline:!(t().showOutline??!0)})},toolbarView:()=>t().toolbar?.view??"ribbon",toolbarLayout:()=>t().toolbar?.layout??"overflow",isReadOnly:()=>(n().readOnly??!1)||"all"!==(r().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?B:"balloon"===e?fe:$}}}({ui:r,documentOptions:a,updateUiState:s,state:()=>p}),L=function(){const[e,t]=co(!1);let n,o,r,a,i;return{focused:e,setFocused:t,focusInput:()=>{t(!0),queueMicrotask(()=>{r?.focus({preventScroll:!0}),r&&(r.selectionStart=r.value.length,r.selectionEnd=r.value.length)})},focusInputAfterPointerSelection:()=>{t(!0),queueMicrotask(()=>{requestAnimationFrame(()=>{r?.focus({preventScroll:!0}),r&&(r.selectionStart=r.value.length,r.selectionEnd=r.value.length)})})},focusInputSync:()=>{t(!0),r?.focus({preventScroll:!0}),r&&(r.selectionStart=r.value.length,r.selectionEnd=r.value.length)},get viewportRef(){return n},set viewportRef(e){n=e},get surfaceRef(){return o},set surfaceRef(e){o=e},get textareaRef(){return r},set textareaRef(e){r=e},get importInputRef(){return a},set importInputRef(e){a=e},get imageInputRef(){return i},set imageInputRef(e){i=e}}}(),N=L.focused,z=L.setFocused,H=L.focusInput,U=L.focusInputAfterPointerSelection,j=L.focusInputSync,[V,K]=co(!1!==r().loading),_=jn(),{linkDialog:X,setLinkDialog:G,imageAltDialog:q,setImageAltDialog:Y,imageCaptionDialog:Z,setImageCaptionDialog:J,contextMenu:Q,setContextMenu:ee,fontDialog:te,setFontDialog:ne,paragraphDialog:oe,setParagraphDialog:re,tablePropertiesDialog:ae,setTablePropertiesDialog:ie,revisionBulkDialog:se,setRevisionBulkDialog:le,newDocumentDialog:ce,setNewDocumentDialog:de,symbolDialog:ue,setSymbolDialog:pe,equationDialog:ge,setEquationDialog:me}=function(){const[e,t]=co({isOpen:!1}),[n,o]=co({isOpen:!1}),[r,a]=co({isOpen:!1}),[i,s]=co({isOpen:!1,initialHref:""}),[l,c]=co({isOpen:!1,initialAlt:""}),[d,u]=co({isOpen:!1,initialCaption:""}),[p,g]=co({isOpen:!1,x:0,y:0}),[f,m]=co({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]=co({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]=co({isOpen:!1,action:"accept",count:0}),[x,w]=co({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:o,equationDialog:r,setEquationDialog:a,linkDialog:i,setLinkDialog:s,imageAltDialog:l,setImageAltDialog:c,imageCaptionDialog:d,setImageCaptionDialog:u,contextMenu:p,setContextMenu:g,fontDialog:f,setFontDialog:m,paragraphDialog:h,setParagraphDialog:b,tablePropertiesDialog:x,setTablePropertiesDialog:w,revisionBulkDialog:y,setRevisionBulkDialog:v}}(),[he,be]=co(!1),ye=()=>L.viewportRef,ve=()=>L.surfaceRef,xe=mx({documentOptions:a,logger:u,runtimeClient:t,state:p,commitState:g,getStateSnapshot:m,applyState:h,cloneState:b,isReadOnly:M,focusInput:H,surfaceRef:ve,viewportRef:ye,zoomFactor:_.zoomFactor,getImageOps:()=>Ke.imageOps}),{docIO:we,measuredBlockHeights:Se,measuredParagraphLayouts:Ie,documentLayout:Ce,canvasSnapshotProvider:Te,inputBox:ke,selectionBoxes:Pe,commentHighlights:Re,revisionMarkupBoxes:Be,changeBarBoxes:Me,selectedImageBox:Oe,selectedTextBoxBox:Ae,selectedTableBox:Fe,caretBox:De,preferredColumnX:Ee,setPreferredColumnX:Le,clearPreferredColumn:Ne,onCleanupHook:ze,persistenceStatus:$e,applyTransactionalState:He,resetTransactionGrouping:Ue,updateHistoryState:je}=xe,Ve=mp({state:()=>p,stateSnapshot:m,isReadOnly:M,applyTransactionalState:He,applyTableAwareParagraphEdit:(e,t)=>Ke.tableOps.applyTableAwareParagraphEdit(e,t),clearPreferredColumn:Ne,resetTransactionGrouping:Ue,focusInput:H}),Ke=vS({clipboardActions:Ve,state:p,getStateSnapshot:m,logger:u,isReadOnly:M,applyState:h,cloneState:b,focusInput:H,focusInputAfterPointerSelection:U,focusInputSync:j,surfaceRef:ve,viewportRef:ye,zoomFactor:_.zoomFactor,insertImageFromFile:we.insertImageFromFile,getForcePlainTextPaste:()=>y,setForcePlainTextPaste:e=>{y=e},getCommandsController:()=>yt.commandsController,applyTransactionalState:He,clearPreferredColumn:Ne,resetTransactionGrouping:Ue,updateHistoryState:je,caretBox:De,preferredColumnX:Ee,setPreferredColumnX:Le,measuredBlockHeights:Se,measuredParagraphLayouts:Ie,documentLayout:Ce,canvasSnapshotProvider:Te,openEquationDialog:(e,t)=>{me({isOpen:!0,initial:e,targetRunId:t})}}),{layoutOptionsOverlay:_e,fr:Xe,tableOps:Ge,imageOps:Ye,textBoxOps:Ze,styleController:Je,onEditorPointerDown:Qe,tableResize:nt,tableCornerResize:ot,tableDrag:rt,revisionController:at,textDrag:it,surfaceEventsWithTextDrag:st,textInput:lt,handleCopy:ct,handleCut:dt,handlePaste:pt,handleDrop:gt}=Ke,[ft,mt]=co(!1),ht=bT(),bt=rT({state:()=>p,isReadOnly:M,applyTransactionalState:He,focusInput:H,access:()=>l().review}),yt=QC({commandSearch:{isOpen:ft,setIsOpen:e=>{mt(e)}},setCommandSearchOpen:mt,clipboardActions:Ve,document:xe,interaction:Ke,commentComposer:bt,state:p,logger:u,isReadOnly:M,focusInput:H,applyState:h,getStateSnapshot:m,cloneState:b,setFocused:z,setInitialLoading:K,getForcePlainTextPaste:()=>y,setForcePlainTextPaste:e=>{y=e},locale:()=>r().locale??"pt-BR",translator:c,runtimeClient:t,runtimeOptions:l,documentOptions:a,getUiState:i,updateUiState:s,zoom:_,importInputRef:()=>L.importInputRef,imageInputRef:()=>L.imageInputRef,setLinkDialog:G,setImageAltDialog:Y,setImageCaptionDialog:J,setNewDocumentDialog:de,setSymbolDialog:pe,setEquationDialog:me,setTablePropertiesDialog:ie,setFontDialog:ne,setParagraphDialog:re,setRevisionBulkDialog:le,toggleOutline:k,isOutlineVisible:C,toggleRevisionsPanel:()=>{ht.toggle()},revisionsPanelVisible:ht.open}),{commandsController:vt,runtimeReady:xt,runtimeEditor:wt,toolbarHost:St,toolbarRegistry:It,menuRegistry:Ct,handleKeyDown:Tt}=yt,kt=()=>function(e,t,n){const o=[],r=/* @__PURE__ */new Set;for(const a of e){if("hidden"in a&&!0===a.hidden)continue;const e=Rp(a);if(!e)continue;const t=a.label;if("string"!=typeof t||!t.trim())continue;if(r.has(e.command))continue;r.add(e.command);const n={id:a.id,label:t,command:e.command,...void 0===e.payload?{}:{payload:e.payload},source:"ribbon"};o.push(n)}for(const a of t){if(!0===a.hidden)continue;const e=Pp(a.command);if(!e)continue;if(r.has(e.command))continue;r.add(e.command);const t=a.labelKey?n(a.labelKey):a.id;o.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 o}(It.getOrdered(),Ct.getItems(),c),Pt=e=>{try{return!1!==wt().commands.canExecute(e)}catch{return!1}},{computeFontFamilyOptions:Rt,computeFontSizeOptions:Bt,applyFontDialogValues:Mt,applyParagraphDialogValues:At,setParagraphDialogDefault:Ft,applyTablePropertiesDialogValues:Dt,buildContextMenuItems:Et,handleEditorContextMenu:Lt,closeContextMenu:Nt}=ym({clipboardActions:Ve,state:()=>p,selection:()=>p.selection,toolbarStyleState:Je.toolbarStyleState,isReadOnly:M,t:c,logger:u,setFontDialog:ne,setParagraphDialog:re,setTablePropertiesDialog:ie,setContextMenu:ee,clearPreferredColumn:Ne,resetTransactionGrouping:Ue,applyTransactionalState:He,applyTableAwareParagraphEdit:Ge.applyTableAwareParagraphEdit,focusInput:H,promptForLink:vt.promptForLink,tableOps:Ge}),{layout:zt,overlays:$t,refs:Ht,surfaceHandlers:Wt,inputHandlers:Ut,fileHandlers:jt}=function(e){const{layout:t,overlays:n,refs:o,surface:r,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=>{o.focusController.viewportRef=e},onSurfaceRef:e=>{o.focusController.surfaceRef=e},onTextareaRef:e=>{o.focusController.textareaRef=e},onImportInputRef:e=>{o.focusController.importInputRef=e},onImageInputRef:e=>{o.focusController.imageInputRef=e}},surfaceHandlers:{onDragOver:e=>e.preventDefault(),onDrop:r.handleDrop,onEditorPointerDown:r.onEditorPointerDown,onSurfacePointerDown:r.surfaceEvents.handleSurfacePointerDown,onSurfaceClick:r.surfaceEvents.handleSurfaceClick,onSurfacePointerMove:r.tableResize.handlePointerMove,onSurfaceDblClick:r.surfaceEvents.handleSurfaceDblClick,onParagraphPointerDown:r.surfaceEvents.handleParagraphPointerDown,onImagePointerDown:r.handleImagePointerDown,onImageResizeHandlePointerDown:r.handleImageResizeHandlePointerDown,onTextBoxResizeHandlePointerDown:r.handleTextBoxResizeHandlePointerDown,onImageRotateHandlePointerDown:r.handleImageRotateHandlePointerDown,onImageCropHandlePointerDown:r.handleImageCropHandlePointerDown,onImageCropBodyPointerDown:r.handleImageCropBodyPointerDown,onTextBoxRotateHandlePointerDown:r.handleTextBoxRotateHandlePointerDown,onTableDragHandlePointerDown:r.tableDrag.handlePointerDown,onTableCornerResizeHandlePointerDown:r.tableCornerResize.handlePointerDown,onRevisionMouseEnter:r.revisionController.handleRevisionMouseEnter,onRevisionMouseLeave:r.revisionController.handleRevisionMouseLeave,onEditorContextMenu:e=>r.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:Ce,remoteWebFonts:a().remoteWebFonts,pageGutter:r().pageGutter,initialZoomMode:r().zoom?.initialMode,viewportHeight:r().viewportHeight,className:r().class,style:r().style,zoomPercent:_.zoomPercent,setZoomPercent:_.setZoomPercent,zoomFactor:_.zoomFactor},overlays:{selectionBoxes:Pe,commentHighlights:Re,revisionMarkupBoxes:Be,changeBarBoxes:Me,onReplyToComment:e=>{bt.openReplyToId(e)},onEditComment:e=>{bt.openEditToId(e)},canEditComment:bt.canEditId,canReplyComment:bt.canReplyId,selectedImageBox:Oe,selectedTextBoxBox:Ae,selectedTableBox:Fe,layoutOptions:_e,caretBox:De,inputBox:ke,hoveredRevision:at.hoveredRevision,focused:N,showCaret:()=>function(e,t){if(!t.visible||!sr(e.selection))return!1;const n=nr(e),o=Fa(e.document,e.selection.anchor.paragraphId,n),r=Fa(e.document,e.selection.focus.paragraphId,n);return!(o&&r&&o.blockIndex===r.blockIndex&&(o.rowIndex!==r.rowIndex||o.cellIndex!==r.cellIndex))}(p,De()),importProgress:we.importProgress,imageCropMode:Ye.cropMode},refs:{focusController:L},files:{handleImportFile:we.handleImportFile,handleInsertImage:we.handleInsertImage},surface:{surfaceEvents:st,tableResize:nt,tableCornerResize:ot,tableDrag:rt,revisionController:at,handleDrop:gt,onEditorPointerDown:Qe,handleImagePointerDown:Ye.handleImagePointerDown,handleImageResizeHandlePointerDown:Ye.handleImageResizeHandlePointerDown,handleTextBoxResizeHandlePointerDown:Ze.handleTextBoxResizeHandlePointerDown,handleImageRotateHandlePointerDown:Ye.handleImageRotateHandlePointerDown,handleImageCropHandlePointerDown:Ye.handleImageCropHandlePointerDown,handleImageCropBodyPointerDown:Ye.handleImageCropBodyPointerDown,handleTextBoxRotateHandlePointerDown:Ze.handleTextBoxRotateHandlePointerDown,handleEditorContextMenu:Lt},input:{textInput:lt,setFocused:z,handleCopy:ct,handleCut:dt,handlePaste:pt,handleKeyDown:e=>{if("Escape"===e.key&&Ke.formatPainter.mode())return Ke.formatPainter.cancel(),void e.preventDefault();Tt(e)},handleKeyUp:e=>{Ke.formatPainter.mode()&&(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown","Shift"].includes(e.key)||(e.ctrlKey||e.metaKey)&&"a"===e.key.toLowerCase())&&Ke.formatPainter.applyToSelection("keyboard")}}});return Xt(()=>{en(),kn(),tt(),io(()=>ve()??null),Po(),(r().showWelcome??!0)&&!v()&&f()&&be(!0)}),yn(()=>{ze(),st.stopDragging(),it.stopDrag(),nt.stop(),ot.stop(),rt.stop(),Ye.stopImageDrag(),Ye.stopImageResize(),Ye.stopImageCrop(),Ze.stopTextBoxResize(),ut()}),Bn(E,{translator:c,get children(){var e=CT();return W(e,Bn(Qt,{get when(){return qe(()=>!(O()||!x()))()&&I()},get children(){return Bn(sn,{host:St,registry:It,get showFileGroup(){return!!qe(()=>"ribbon"===P())()||!S()},get view(){return P()},get layout(){return R()}})}}),null),W(e,Bn(yp,{get notice(){return Ve.notice},onDismiss:()=>{Ve.dismiss(),H()}}),null),W(e,Bn(Qt,{get when(){return bt.panelOpen()},get children(){return Bn(gT,{state:()=>p,composer:bt,locale:()=>r().locale??"pt-BR",get onClose(){return bt.closePanel},onNavigate:e=>{const t=function(e,t){const n=e.document.comments?.items;if(!n?.[t])return e;let o=n[t];const r=/* @__PURE__ */new Set;for(;o&&!o.start&&o.parentId&&!r.has(o.id);)r.add(o.id),o=n[o.parentId];const a=o?.start,i=o?.end;if(!a||!i)return e;const s=cr(e),l=s.find(e=>e.id===a.paragraphId),c=s.find(e=>e.id===i.paragraphId);return l&&c?{...e,selection:{anchor:ci(l,a.offset),focus:ci(c,i.offset)}}:e}(p,e);t!==p&&(h(t),H())}})}}),null),W(e,Bn(Qt,{get when(){return ht.open()},get children(){return Bn(IT,{state:()=>p,get onClose(){return ht.close},get scrollTop(){return ht.scrollTop()},get onScroll(){return ht.setScrollTop},onNavigate:e=>{const t=OI(p,e);t!==p&&(h(t),H())},onAccept:e=>{const t=OI(p,e);t!==p&&(h(t),vt.applyAcceptRevisionsCommand(),H())},onReject:e=>{const t=OI(p,e);t!==p&&(h(t),vt.applyRejectRevisionsCommand(),H())},onAcceptAll:()=>wt().commands.execute("requestAcceptAllRevisions"),onRejectAll:()=>wt().commands.execute("requestRejectAllRevisions")})}}),null),W(e,Bn(kp,{get isOpen(){return ft()},get entries(){return kt()},isEnabled:Pt,onExecute:e=>{wt().commands.execute(e.command,e.payload),mt(!1),H()},onClose:()=>{mt(!1),H()}}),null),W(e,Bn(eb,{commentComposer:bt,dialogs:{linkDialog:X,setLinkDialog:G,imageAltDialog:q,setImageAltDialog:Y,imageCaptionDialog:Z,setImageCaptionDialog:J,contextMenu:Q,setContextMenu:ee,fontDialog:te,setFontDialog:ne,paragraphDialog:oe,setParagraphDialog:re,tablePropertiesDialog:ae,setTablePropertiesDialog:ie,revisionBulkDialog:se,setRevisionBulkDialog:le,newDocumentDialog:ce,setNewDocumentDialog:de,symbolDialog:ue,setSymbolDialog:pe,equationDialog:ge,setEquationDialog:me},findReplace:Xe,fontFamilyOptions:Rt,fontSizeOptions:Bt,contextMenuItems:Et,focusInput:H,get applyLinkCommand(){return vt.applyLinkCommand},get applyImageAltCommand(){return vt.applyImageAltCommand},get applyImageCaptionCommand(){return vt.applyImageCaptionCommand},applyFontDialogValues:Mt,applyParagraphDialogValues:At,setParagraphDialogDefault:Ft,applyTablePropertiesDialogValues:Dt,confirmNewDocument:()=>t.resetDocument(),applyBulkRevisions:e=>{wt().commands.execute("accept"===e?"acceptAllRevisions":"rejectAllRevisions"),H()},insertSymbol:(e,t)=>{wt().commands.execute("insertText",{text:e,fontFamily:t}),H()},applyEquation:(e,t)=>{t?wt().commands.execute("updateEquation",{runId:t,expression:e}):wt().commands.execute("insertEquation",e),H()},closeContextMenu:Nt}),null),W(e,Bn(nb,{useComposedShell:O,shellComponent:D,runtime:{state:()=>p,toolbarHost:St,runtimeEditor:wt,persistenceStatus:$e,toolbarRegistry:It,menuRegistry:Ct},chrome:{showChrome:x,showTitleBar:w,showMenubar:S,showToolbar:I,showOutline:C,showRuler:T,toolbarView:P,toolbarLayout:R},view:{isReadOnly:M,viewportHeight:()=>r().viewportHeight,measuredBlockHeights:Se,measuredParagraphLayouts:Ie,documentLayout:Ce,layout:zt,overlays:$t,refs:Ht,surfaceHandlers:Wt,inputHandlers:Ut,fileHandlers:jt}}),null),W(e,Bn(Cm,{state:p,get surfaceRef(){return ve()},documentLayout:Ce,snapshotProvider:Te,get zoomFactor(){return _.zoomFactor},tableResize:nt,tableCornerResize:ot,imageOps:Ye,tableDrag:rt,textDrag:it}),null),W(e,Bn(Qt,{get when(){return V()||!xt()},get children(){return Bn(d,{get label(){return F()},get class(){return A()?.class},get style(){return A()?.style}})}}),null),W(e,Bn(rb,{get isOpen(){return qe(()=>!(!he()||V()))()&&xt()},onClose:()=>be(!1)}),null),gn(t=>{var n=r().theme??"light",o=!!O(),a=!!M(),i=!("two-line"!==r().toolbar?.ribbonStyle),s=!("simplified"!==r().toolbar?.ribbonStyle),l=!(null===Ke.formatPainter.mode()),c={"--oasis-editor-gutter-x":`${po(r().pageGutter)}px`,...void 0!==r().pageGutter?{"--oasis-editor-gutter-top":`${po(r().pageGutter)}px`,"--oasis-editor-gutter-bottom":`${po(r().pageGutter)}px`}:{}};return n!==t.e&&et(e,"data-theme",t.e=n),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),i!==t.o&&e.classList.toggle("oasis-editor-ribbon-two-line",t.o=i),s!==t.i&&e.classList.toggle("oasis-editor-ribbon-simplified",t.i=s),l!==t.n&&e.classList.toggle("oasis-editor-format-painter-active",t.n=l),t.s=Ot(e,c,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{TT as OasisEditorApp};