@docx-editor.dev/core 2.35.0-canary.20261104032723.sha-43c2012 → 2.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -14
- package/dist/automation.cjs +1 -1
- package/dist/automation.d.ts +16 -11
- package/dist/automation.js +1 -1
- package/dist/binding.cjs +1 -1
- package/dist/binding.d.ts +12 -12
- package/dist/binding.js +1 -1
- package/dist/{chrome-print-CK3v5NhC.d.ts → chrome-print-H0uSxdg3.d.ts} +70 -17
- package/dist/{chunk-AMOFXSEO.cjs → chunk-2C75IWUN.cjs} +1 -1
- package/dist/chunk-2NFQ7OXY.cjs +1 -0
- package/dist/chunk-2V3V57SC.js +3 -0
- package/dist/chunk-32YOHLEK.cjs +32 -0
- package/dist/chunk-4NISR27M.cjs +31 -0
- package/dist/chunk-5ZE7ROGP.js +31 -0
- package/dist/{chunk-LZ64O473.js → chunk-66ZAVRGB.js} +1 -1
- package/dist/{chunk-A5GMOQWD.js → chunk-6767S7UF.js} +1 -1
- package/dist/chunk-6BZINLEN.cjs +1 -0
- package/dist/{chunk-EBIMIIC3.js → chunk-AVGSD7FB.js} +5 -5
- package/dist/{chunk-TZTKEPCC.cjs → chunk-CBJMRC4L.cjs} +1 -1
- package/dist/chunk-DCILO4XD.cjs +236 -0
- package/dist/{chunk-FBGZOGLU.cjs → chunk-DSIDCA3V.cjs} +4 -4
- package/dist/chunk-FLEFHRJG.cjs +5 -0
- package/dist/chunk-FMSXJ22B.js +2 -0
- package/dist/{chunk-7ACXKFKO.js → chunk-I4OZW2NO.js} +1 -1
- package/dist/chunk-JGE2O6IF.cjs +3 -0
- package/dist/chunk-K2BBJDM7.js +32 -0
- package/dist/chunk-LMASPHYS.js +1 -0
- package/dist/chunk-NYZP5NM3.js +4 -0
- package/dist/chunk-P3XUE72N.js +236 -0
- package/dist/{chunk-JZ4LO3ZZ.js → chunk-Q5YVLUGG.js} +1 -1
- package/dist/chunk-QALWAAPL.cjs +4 -0
- package/dist/{chunk-ELR6HXOO.js → chunk-QDUMZYTX.js} +1 -1
- package/dist/chunk-QLANEOTJ.cjs +7 -0
- package/dist/{chunk-4NPNKO5U.cjs → chunk-SJV6WCTP.cjs} +1 -1
- package/dist/{chunk-I4WSXFY6.js → chunk-TMCMXIBT.js} +4 -4
- package/dist/{chunk-GTICLPKS.cjs → chunk-TY5CE2JR.cjs} +1 -1
- package/dist/chunk-UAUB5YV6.js +7 -0
- package/dist/{chunk-Q4MUV5KX.cjs → chunk-WWZWT26M.cjs} +1 -1
- package/dist/chunk-Y3JSN52G.cjs +2 -0
- package/dist/chunk-YD3KSZJM.js +1 -0
- package/dist/collaboration/replication.cjs +1 -1
- package/dist/collaboration/replication.d.ts +3 -3
- package/dist/collaboration/replication.js +1 -1
- package/dist/collaboration.d.ts +2 -2
- package/dist/contracts/document.d.ts +2 -2
- package/dist/contracts/editor.d.ts +8 -8
- package/dist/contracts/modules.cjs +1 -1
- package/dist/contracts/modules.d.ts +34 -13
- package/dist/contracts/modules.js +1 -1
- package/dist/contracts/types.d.ts +3 -3
- package/dist/{custom-node-writes-BC3z8NwO.d.ts → custom-node-writes-Cj0itq58.d.ts} +2 -2
- package/dist/{document-protection-8hXPdn5U.d.ts → document-protection-CDLoYQI3.d.ts} +1 -1
- package/dist/{drawing-graphic-kind-_5u2E4ee.d.ts → drawing-graphic-kind-8zt6pugF.d.ts} +2 -2
- package/dist/{drawing-preview-package-JyAqL6OV.d.ts → drawing-preview-package-8o9LSfzP.d.ts} +1 -1
- package/dist/{editor-BGCdE3tB.d.ts → editor-CujQcn1z.d.ts} +20 -10
- package/dist/editor.cjs +1 -1
- package/dist/editor.css +3 -3
- package/dist/editor.d.ts +52 -29
- package/dist/editor.js +1 -1
- package/dist/export.cjs +2 -2
- package/dist/export.d.ts +6 -6
- package/dist/export.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +18 -18
- package/dist/index.js +1 -1
- package/dist/{layout-shaping-D2qNes9-.d.ts → layout-shaping-ZjLRz_qa.d.ts} +1 -1
- package/dist/layout.cjs +1 -1
- package/dist/layout.d.ts +25 -21
- package/dist/layout.js +1 -1
- package/dist/{note-properties-DGPzKUuA.d.ts → note-properties-BRpskBeh.d.ts} +1 -1
- package/dist/output.cjs +1 -1
- package/dist/output.d.ts +10 -10
- package/dist/output.js +1 -1
- package/dist/{protocol-0y3iaYj9.d.ts → protocol-GVVQQwCX.d.ts} +13 -2
- package/dist/{review-paragraph-order-DeQp2_iu.d.ts → review-paragraph-order-aEHnQTt7.d.ts} +5 -2
- package/dist/{revision-projection-CrAv-HP6.d.ts → revision-projection-vU_UiTLx.d.ts} +1 -1
- package/dist/{semantic-cell-selection-CeG_qqDV.d.ts → semantic-cell-selection-CaRIISu-.d.ts} +2 -2
- package/dist/{semantic-interaction-DcE_ZsiD.d.ts → semantic-interaction-LJtUJJS5.d.ts} +1 -1
- package/dist/{semantic-paint-DfeN6UQF.d.ts → semantic-paint-2LBYlQcn.d.ts} +11 -4
- package/dist/{semantic-record-queries-qwd9Ict6.d.ts → semantic-record-queries-C_YK2gCz.d.ts} +1 -1
- package/dist/{semantic-records-thL1rcmG.d.ts → semantic-records-AU2pIYRp.d.ts} +3 -3
- package/dist/store.cjs +1 -1
- package/dist/store.d.ts +1664 -1664
- package/dist/store.js +1 -1
- package/dist/{tree-op-types-CGlwCQXg.d.ts → tree-op-types-DmrePCMo.d.ts} +320 -11
- package/dist/{tree-package-store-D0_BOm-r.d.ts → tree-package-fragment-DXZ2B7x0.d.ts} +702 -691
- package/dist/{tree-session-contract-DkThhHjy.d.ts → tree-session-contract-D3e-5YNq.d.ts} +19 -4
- package/dist/{unsupported-elements-qj0sXi2s.d.ts → unsupported-elements-9Pz4I_F6.d.ts} +1 -1
- package/docs/accept-reject-without-scrolling.md +31 -48
- package/docs/comment-on-found-text.md +47 -23
- package/docs/custom-review-cards.md +50 -34
- package/docs/highlight-ranges.md +26 -6
- package/docs/index.md +21 -21
- package/docs/propose-rewrite.md +87 -138
- package/docs/tracked-replacement.md +41 -20
- package/package.json +2 -2
- package/dist/chunk-4C7JUJDX.cjs +0 -1
- package/dist/chunk-4HENIAFG.js +0 -1
- package/dist/chunk-6IYKYYWF.js +0 -32
- package/dist/chunk-CDAFCPT6.cjs +0 -3
- package/dist/chunk-CU6QPXKD.js +0 -2
- package/dist/chunk-EMITIPLN.js +0 -4
- package/dist/chunk-IGB66DIX.cjs +0 -30
- package/dist/chunk-JQPTNBLT.js +0 -236
- package/dist/chunk-JVWRILO3.cjs +0 -4
- package/dist/chunk-KOYEBRLV.js +0 -1
- package/dist/chunk-KZZPOZOF.cjs +0 -2
- package/dist/chunk-NPWMZIPA.cjs +0 -32
- package/dist/chunk-NS2QCOAS.js +0 -7
- package/dist/chunk-O2PGRL5D.js +0 -3
- package/dist/chunk-TFJUIP4X.cjs +0 -236
- package/dist/chunk-V3N4SOAK.cjs +0 -1
- package/dist/chunk-V6FOPP2H.js +0 -30
- package/dist/chunk-XFEIUKOS.cjs +0 -7
- package/dist/chunk-ZF4N3N3L.cjs +0 -5
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import {i,g as g$1,e,f}from'./chunk-LMASPHYS.js';import {hd as hd$1,lf as lf$1,mf as mf$1,pf as pf$1,zb,sd as sd$1,kf as kf$1,zd as zd$1,se as se$1,Md as Md$2,od as od$1,Kd as Kd$1,pd as pd$1,nf as nf$1,_c as _c$2,wf,td as td$1,ud as ud$2}from'./chunk-K2BBJDM7.js';import {b as b$2,c,a as a$1}from'./chunk-Q5YVLUGG.js';import {sa,S,za,Ca,la,da,ba,ca,fa,ea as ea$1,Aa,T,U,W as W$1,V,xa,$,aa as aa$1,na as na$1,pa as pa$1,qa,oa as oa$2,ra as ra$1}from'./chunk-NYZP5NM3.js';import {b as b$1,a}from'./chunk-I4OZW2NO.js';import {eb,Bi,ki,qi,ud as ud$1,Pa,pa,cb,Bk,jb,rg,Bg,zg,Ag,lg,Eb,ng,Hb,sf as sf$1,pj,Qc as Qc$1,Tc as Tc$1,Rc as Rc$1,_c as _c$1,g,qf,re as re$1,se,Xa,ej,vd as vd$1,Bf,pb,wj,ob,Ve as Ve$1,hd as hd$2,cd as cd$1,X,hn,ai,Cd as Cd$1,Ad as Ad$1,yd as yd$1,xd as xd$1,Dd as Dd$1,Ed as Ed$1,Bd as Bd$1,wa,oa as oa$1,ma,id as id$1,wb,Od as Od$1,Md as Md$1,va,Jm as Jm$1,jd as jd$1,Sh,Qh,qc as qc$1,Uh,fb,Mm as Mm$1,xj,Kk,Um as Um$1,Zm as Zm$1,Vm as Vm$1,Ym as Ym$1,Wm as Wm$1,an as an$1,zm as zm$1,yj,Ei,Cj,uc as uc$1,oc,sc,Al as Al$1,Ol as Ol$1,jm as jm$1,mm as mm$1,ml as ml$1,ql as ql$1,Ok,dj,He,fj,Fe,ei,ci,si,Rh,Aj,Nk,fd as fd$1,Kh,Oh,Hn,en as en$1,gn,fn,Wi,Yi,Mk,Ye,Th,Ai,Am as Am$1,tc as tc$1,zl as zl$1,Em as Em$1,Dm as Dm$1,Dn as Dn$1,cm as cm$1,ll as ll$1,Km as Km$1,pm as pm$1,hm as hm$1,im as im$1,Tj,Qj,dm as dm$1,Sj,pl as pl$1,_l as _l$1,Qd as Qd$1,Mh,$k,ym as ym$1,zj,Ej,Ca as Ca$1,Bj,kb,Ti,Of as Of$1,Tf,fg,cg,gg,eg,Fn as Fn$1,lj,Bm as Bm$1,Cm as Cm$1,Ee as Ee$1,Pd as Pd$1,Nd as Nd$1,na as na$2,Yg,ug,E,C,vg,df as df$1,cf as cf$1,yg,An as An$1,gh,Pk,W as W$2,sa as sa$1}from'./chunk-P3XUE72N.js';var Nt=Object.freeze(["default","first","even"]);function hr(e){return e.kind==="body"||e.kind==="header"||e.kind==="footer"}var ve=Object.freeze({kind:"body"});function Y(e){switch(e.kind){case "body":return "body";case "note":return `note:${e.noteKind}:${String(e.noteId)}`;case "textbox":return `textbox:${Y(e.owner)}:${String(e.shapeId)}`;default:return `${e.kind}:${String(e.sectionIndex)}:${e.variant}`}}function yr(e){if(typeof e!="object"||e===null)return false;let t=e;return t.kind==="body"?true:t.kind==="textbox"?yr(t.owner)&&hr(t.owner)&&Number.isInteger(t.shapeId)&&t.shapeId>=0:t.kind==="note"?(t.noteKind==="footnote"||t.noteKind==="endnote")&&Number.isInteger(t.noteId):t.kind!=="header"&&t.kind!=="footer"?false:Number.isInteger(t.sectionIndex)&&t.sectionIndex>=0&&Nt.includes(t.variant)}function _e(e){return e.kind==="note"||e.kind==="textbox"}var Rs=["getTables","getTable","getTableRows","getTableCells","getTableCell","getMergedTableCell","getTableCellProperties","getTableCellBody","getFields","getField","getFieldResult","getInlinePictures","getInlinePicture","getShapes","getShape","getShapeBody","getChangeTrackingMode","getDocument","getDocumentProperty","getStyles","getBody","getParagraphs","getRange","getSpanParagraphs","getText","getSpanText","getTextRanges","expandSpan","getReviewedText","getParagraphId","search","getFont","getParagraphFormat","getStyle","getSections","getPageSetup","getFurniture","getNotes","getNoteBody","getNoteText","getNoteKind","getLists","getListId","getListById","getListParagraphs","getParagraphList","getListLevel","getHyperlink","getBookmarks","getBookmarkName","getBookmarkRange","getBookmarkNames","getBookmarkRangeByName","getComments","getCommentReplies","getCommentId","getCommentAuthor","getCommentDate","getCommentText","getCommentRange","getCommentResolved","getRevisions","getRevisionType","getRevisionAuthor","getRevisionDate","getRevisionRange","getReviewItemRange","getContentControls","getContentControlById","getContentControlsByTag","getContentControlsByTitle","getContentControlTag","getContentControlTitle","getContentControlFileId","getContentControlSubtype","getContentControlLock","getContentControlIsBound","getContentControlPlaceholderShown","getContentControlTemporary","getContentControlText","getContentControlParagraphs","getContentControlRange"],kr=["removeDocumentInformation","compareFromBase64","setDocumentProperties","insertTableRows","insertTable","updateTable","updateTableCell","splitTableCell","setInlinePicture","deleteInlinePicture","insertField","insertOoxml","setFieldCode","setFieldResult","deleteField","updateFieldResult","insertInlinePicture","insertBreak","setChangeTrackingMode","proposeInsertion","proposeDeletion","proposeReplacement","insertText","replaceSpan","replaceStoryBlocks","insertParagraph","splitParagraph","deleteParagraph","selectSpan","selectBookmark","insertBookmark","deleteBookmark","setFont","setParagraphFormat","setStyle","setPageSetup","deleteNote","setListLevel","startNewList","attachToList","detachFromList","setListLevelFormat","insertListParagraph","setHyperlink","insertComment","setCommentResolved","replyToComment","deleteComment","acceptRevision","rejectRevision","resolveRevisionBatch","setRevisionAuthorBatch","acceptAllRevisions","rejectAllRevisions","setContentControlValue","setContentControlProperties","deleteContentControl","insertContentControlText","insertContentControl","insertCustomNode"],xr=["removeDocumentInformation","compareFromBase64","insertTableRows","resolveRevisionBatch","setRevisionAuthorBatch","insertTable","insertInlinePicture","insertBreak","startNewList","deleteNote","insertComment","setCommentResolved","replyToComment","insertCustomNode"],lc=new Set(xr);function bn(e){return lc.has(e.op)&&!(e.op==="insertBreak"&&e.breakType==="Line")||e.op==="updateTable"&&["addRows","addColumns","deleteRows","deleteColumns","delete"].includes(e.mutation.kind)}var dc=new Set(kr);function je(e){return dc.has(e.op)}var uc="http://schemas.openxmlformats.org/officeDocument/2006/relationships",cc="#_x0000_t202",pc=new Set(["#_x0000_t20","#_x0000_t32","#_x0000_t33","#_x0000_t34"]),mc=new Set(["shape","rect","roundrect","oval"]),fc=e=>/^(t|true|1)$/i.test(e?.trim()??"");function gc(e){let t=Cd$1(e).filter(o=>Ad$1(o,xd$1,"textbox"));if(t.length!==1)return null;let n=Cd$1(t[0]);return n.length===1&&Ad$1(n[0],pa,"txbxContent")?n[0]:null}function hc(e){return Bd$1(e,"type")?.trim()===cc||Bd$1(e,"spt",yd$1)?.trim()==="202"}function yc(e){let t=Bd$1(e,"connectortype",yd$1)?.trim();if(t&&t!=="none")return true;let n=Bd$1(e,"type")?.trim(),o=Bd$1(e,"spt",yd$1)?.trim();return pc.has(n??"")||["20","32","33","34"].includes(o??"")}function kc(e){return e.localName==="image"?true:Cd$1(e).some(t=>Ad$1(t,xd$1,"imagedata")&&t.attributes.some(n=>n.namespaceUri===uc&&n.localName==="id"||n.namespaceUri===yd$1&&n.localName==="relid"||!n.namespaceUri&&n.localName==="src"))}function xc(e,t){return e.localName==="group"?"Group":t||fc(Bd$1(e,"hr",yd$1))||Cd$1(e).some(n=>Ad$1(n,xd$1,"textpath"))?"Unsupported":hc(e)?"TextBox":Cd$1(e).some(n=>Ad$1(n,xd$1,"textbox"))?"GeometricShape":kc(e)?"Picture":"GeometricShape"}function Ps(e){let t=Cd$1(e),n=t.some(r=>Ad$1(r,yd$1,"OLEObject")),o=[];for(let r of t){if(r.namespaceUri!==xd$1||!Dd$1.has(r.localName))continue;let a=Ed$1(r);if(a===null)continue;let i=Bd$1(r,"spid",yd$1),s=Bd$1(r,"id")??"",l=xc(r,n),d=l==="TextBox"||l==="GeometricShape"?gc(r):null,m=(l==="TextBox"||l==="GeometricShape")&&mc.has(r.localName)&&!yc(r)&&!Cd$1(r).some(c=>Ad$1(c,xd$1,"textbox")||Ad$1(c,xd$1,"imagedata"));o.push({read:{id:a,name:i===void 0?s.trim():s,type:l},root:d,emptyFrame:m});}return o}var bc="http://schemas.openxmlformats.org/drawingml/2006/picture",vc="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup",Ac="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",Is=4096,Oc=65536;function Rc(e){return e&&e.kind!=="textValue"?e:null}function vn(e,t,n){return e.kind!=="textValue"&&e.namespaceUri===t&&e.localName===n}function et(e,t,n){return Rc(e.children.find(o=>vn(o,t,n)))}function Pc(e){let t=e.children.find(c=>c.kind==="anchoredDrawing"||c.kind==="inlineDrawing"||vn(c,wa,"anchor")||vn(c,wa,"inline"));if(!t||t.kind==="textValue")return null;let n=et(t,wa,"docPr"),o=n?oa$1(n.attributes,"id"):void 0;if(!n||o===void 0||!/^\d{1,10}$/.test(o)||Number(o)>4294967295)return "malformed";let r=oa$1(n.attributes,"name")??"",a=et(t,va,"graphic"),i=a?et(a,va,"graphicData"):null,s=i?oa$1(i.attributes,"uri"):void 0,l="Unsupported",d=null,m=false;if(i&&s===ma){let c=et(i,ma,"wsp"),h=c?et(c,ma,"txbx"):null;d=h?et(h,pa,"txbxContent"):null;let f=c?et(c,ma,"cNvSpPr"):null,y=f?oa$1(f.attributes,"txBox"):void 0;l=c?y==="1"||y==="true"?"TextBox":"GeometricShape":"Unsupported";let x=c?et(c,ma,"spPr"):null,v=x?et(x,va,"prstGeom"):null,P=v?oa$1(v.attributes,"prst"):void 0;m=!!f&&!h&&!et(c,ma,"linkedTxbx")&&P!=="line"&&!P?.includes("Connector");}else s===bc?l="Picture":s===vc?l="Group":s===Ac&&(l="Canvas");return {read:{id:Number(o),name:r,type:l},root:d,emptyFrame:m}}function ko(e,t){let n=[],o=new Set,r=[];for(let s of t){if(s.kind==="textValue")continue;let l=pb(wj(e,s),s),d=[];for(let c=s.children.length-1;c>=0;c-=1)d.push({node:s.children[c],scope:l});let m=0;for(;d.length>0;){if(++m>Oc)return {ok:false,reason:"truncated"};let{node:c,scope:h}=d.pop();if(c.kind==="textValue"||c.kind==="paragraph")continue;let f=pb(h,c),y=ob(c),x=c.kind==="drawing"||vn(c,pa,"drawing")?c:y?Ve$1(c,f).drawing:null;if(!(y&&!x)){if(!y&&vn(c,pa,"pict")){for(let{read:v,root:P,emptyFrame:A}of Ps(c)){if(n.length>=Is)return {ok:false,reason:"truncated"};let N={...v,hostParagraphId:s.id,textboxRoot:P,emptyFrame:A,alternate:null};n.push(N),r.push(N);}continue}if(x){let v=Pc(x);if(v==="malformed")return {ok:false,reason:"malformed"};if(v){if(o.has(v.read.id))return {ok:false,reason:"duplicates"};if(n.length>=Is)return {ok:false,reason:"truncated"};o.add(v.read.id),n.push({...v.read,hostParagraphId:s.id,textboxRoot:v.root,emptyFrame:v.emptyFrame,alternate:y?c:null});}continue}for(let v=c.children.length-1;v>=0;v-=1)d.push({node:c.children[v],scope:f});}}}if(r.length===0)return {ok:true,shapes:Object.freeze(n)};let a=new Map;for(let s of n)a.set(s.id,(a.get(s.id)??0)+1);let i=new Set(r.filter(s=>a.get(s.id)>1));return {ok:true,shapes:Object.freeze(i.size?n.filter(s=>!i.has(s)):n)}}var xo=e=>({ok:false,error:{code:"unsupported-content",message:e}});function br(e){if(!(typeof e!="object"||e===null)){if("body"in e)return e.body;if("start"in e&&"end"in e)return br(e.start)??br(e.end)}}function vr(e){if(e.op==="getText")return e.target;if("body"in e)return e.body;let t=e;for(let n of ["span","scope","at","anchor","paragraph"]){let o=br(t[n]);if(o)return o}}function Ss(e,t){let n=lj(e,{op:"createHeaderFooter",sectionIndex:t.sectionIndex,kind:t.kind,variant:t.variant,...t.variant==="first"?{titlePage:true}:{},...t.variant==="even"?{evenAndOddHeaders:true}:{}});return n.ok&&n.createdPartName?n:null}function Ic(e,t){let n=Ss(e,t),o=n&&n.package.parts.get(n.createdPartName);if(!n||!o)return null;let r={...o.root,children:[]};return Pt(rg(n.package,{...o,root:r}))}function ws(e,t,n){let o=vr(e);if(!o)return null;let r=t.handles.resolve(o,"body");if(!r||r.kind!=="body"||r.story.kind!=="header"&&r.story.kind!=="footer")return null;let a=r.story,i=t.reads.package;if(!i||t.reads.story(a))return null;if(!t.reads.sections()[a.sectionIndex])return xo("that section no longer exists");if(e.op!=="insertText"&&e.op!=="replaceSpan"&&e.op!=="insertParagraph"){let d=Ic(i,a);if(!d)return xo("cannot read this header or footer");let m=n(d).plan(e);return !m.ok||m.kind==="query"?m:m.kind!=="command"||m.ops.length||m.lifecycle||m.packageEdits?.length||m.relate?xo("this header or footer does not exist yet; write text to create it"):{ok:true,kind:"query",value:m.answer(d)}}let s=d=>{let m=Ss(d,a);if(!m)return null;let c=Pt(m.package),h=n(c),f=h.plan(e);if(!f.ok||f.kind!=="command"||f.relate||f.lifecycle||f.packageEdits?.length)return null;let y=m.package.parts.get(m.createdPartName);if(!y)return null;for(let v of f.ops){let P=Hn(y,v);if(!P.ok)return null;y=P.part;}let x=rg(m.package,y);return h.settle(Pt(x)).ok?{pkg:x,planner:h,step:f}:null},l=s(i);return l?{ok:true,kind:"command",story:{kind:"body"},ops:[],solitary:true,packageEdits:[d=>{let m=s(d);if(!m)throw new Kk("header/footer creation changed during transaction");return l=m,m.pkg}],answer:d=>l.step.answer(d)}:xo("cannot create this header or footer with that content")}var Es=new WeakSet;function Ds(e){let t=Object.freeze({kind:"generic",id:`${e.hostParagraphId}#empty-text-frame-${String(e.id)}`,namespaceUri:pa,localName:"txbxContent",namespaceBindings:Object.freeze([]),attributes:Object.freeze([]),children:Object.freeze([])});return Es.add(t),t}var Cs=Object.freeze({ok:false,error:Object.freeze({code:"unsupported-content",message:"that shape has no text story in the file, so it cannot take content",detail:"unsupported-story"})});function Ts(e,t){if(e.kind!=="textbox")return false;let n=t.story(e);return !!n&&Es.has(n.root)}function Ls(e,t,n,o){let r=je(e)?vr(e):void 0,a=r===void 0?null:n.resolve(r,"body");if(a?.kind==="body"&&Ts(a.story,o)){let s=t();return s.ok&&s.kind==="query"||Ns(s)?s:Cs}let i=t();return !i.ok||i.kind==="query"||!("story"in i)?i:Ts(i.story,o)&&!Ns(i)?Cs:i}function Ns(e){return e.ok&&e.kind==="command"&&e.ops.length===0&&!e.lifecycle&&!e.packageEdits?.length&&!e.relate}var Sc=63360;function pt(e){return Math.round(Od$1(Md$1(e))*100)/100}function wc(e,t){if(typeof e!="number"||!Number.isFinite(e))return null;let n=Pd$1(Nd$1(e));return n>Sc||n<0||n===0&&!t?null:n}var Cc=[["pageWidth","pageWidthTwips",false],["pageHeight","pageHeightTwips",false],["topMargin","marginTopTwips",true],["rightMargin","marginRightTwips",true],["bottomMargin","marginBottomTwips",true],["leftMargin","marginLeftTwips",true]];function Ms(e){if(typeof e!="object"||e===null)return {ok:false,reason:"that is not a page setup",detail:"not-an-object"};let t=e,n={},o=0;for(let[a,i,s]of Cc){let l=t[a];if(l===void 0)continue;let d=wc(l,s);if(d===null)return {ok:false,reason:`that is not a value for ${a}`,detail:String(l)};n[i]=d,o+=1;}let r=t.orientation;if(r!==void 0){if(r!=="portrait"&&r!=="landscape")return {ok:false,reason:"that is not an orientation",detail:String(r)};n.orientation=r,o+=1;}return o===0?{ok:false,reason:"that page setup names nothing to write",detail:"empty"}:{ok:true,value:n}}function Tc(e){let t=hn(e),n=t.widthTwips>t.heightTwips?"landscape":"portrait";return Object.freeze({pageWidth:pt(t.widthTwips),pageHeight:pt(t.heightTwips),orientation:n,topMargin:pt(t.topTwips),rightMargin:pt(t.rightTwips),bottomMargin:pt(t.bottomTwips),leftMargin:pt(t.leftTwips),headerDistance:pt(t.headerTwips),footerDistance:pt(t.footerTwips),gutter:pt(t.gutterTwips)})}function Nc(e,t){if(!t)return null;let n=null,o=(r,a,i)=>{if(n!==null||r.kind==="textValue"||i>64)return;let s=r.kind==="paragraph"?r.id:a;if(r.id===t.id){n=s;return}for(let l of r.children)o(l,s,i+1);};return o(e.root,null,0),n}function Fs(e,t,n){let o=qf(t.root);return Object.freeze(o.map((r,a)=>{let i=n[a];return Object.freeze({index:a,markParagraphId:Nc(t,r),pageSetup:Tc(r),titlePage:i?.titlePage??false,evenAndOddHeaders:i?.evenAndOddHeaders??false})}))}var Bs=new WeakMap,Ec=0;function Dc(e){if(!e)return;let t=Bs.get(e);return t||(t={...e,cacheKey:`formatting-${++Ec}`},Bs.set(e,t)),t}function bo(e){let t=new WeakMap;return (n,o,r,a)=>{let i=Dc(a),s=fb(n,o.id),l;for(;s&&s.kind!=="table";){if(s.localName==="txbxContent")return;s.kind==="tableCell"&&(l=s.id),s=fb(n,s.id);}if(!s||!l)return;let d=s,m=d.kind==="table"?d.children.find(h=>h.localName==="tblPr")??d:d,c=t.get(m);if(!c||c.table!==d||c.mode!==r||c.filter!==i){let h=new Map,f=se$1(s,1,0,e,r,i);for(let y of f?.rows??[])for(let x of y.cells)h.set(x.id,x.styleFormatting);c={table:d,mode:r,filter:i,cells:h},t.set(m,c);}return c.cells.get(l)}}var qt={},Hs=new WeakMap;function Lc(e,t){let n=e&&e.kind!=="textValue"?e.children.filter(r=>r.kind==="textValue"||r.localName!=="pStyle"):[];return {...e??{kind:"generic",id:"",localName:"pPr",attributes:[]},children:[{kind:"generic",id:"",namespaceUri:pa,localName:"pStyle",prefix:"w",attributes:[{namespaceUri:pa,localName:"val",prefix:"w",value:t}],children:[]},...n]}}function Mc(e){let t=lf$1(e.styles,void 0,e.settings),n=bo(t),o=Md$2(od$1(e.numbering),t);return (r,a,i,s)=>{let l=ai(a,"paragraphProperties","pPr"),d=s===void 0?l:Lc(l,s),m=Kd$1(mf$1(t,d).paragraphPropertyNodes),c=m?pd$1(o,m.numId,m.ilvl):null,h=nf$1(t,d,n(r,a,i),c?_c$2(c.level):void 0);return wf(h.inheritedParagraphProperties)}}function _s(e,t,n,o,r){let a=Hs.get(e.styles??qt);a||Hs.set(e.styles??qt,a=new WeakMap);let i=a.get(e.settings??qt);i||a.set(e.settings??qt,i=new WeakMap);let s=i.get(e.numbering??qt);return s||i.set(e.numbering??qt,s=Mc(e)),s(t,n,o,r)}var Jt=255;function vo(e){return e.trim().toLowerCase()}function Or(e){return e.trim().length>0&&e.length<=Jt&&X(e)}function Ar(e,t){return `${e}\0${vo(t)}`}var js=new WeakMap;function Et(e){let t=js.get(e.root);if(t)return t;let n=Fc(e.root);return js.set(e.root,n),n}function Fc(e){let t=[],n=new Map,o=null,r=0;for(let s of e.children){if(!sd$1(s)||s.localName!=="style")continue;if(r>=kf$1)break;r+=1;let l=zd$1(s,Jt);if(!l)continue;let{styleId:d}=l,m=Object.freeze({styleId:d,type:l.type,name:l.name??null,basedOn:l.basedOn,next:l.next,element:s});t.push(m),n.set(d,m),m.type==="paragraph"&&(l.isDefault?o=d:o===d&&(o=null));}let a=t.filter(s=>n.get(s.styleId)===s),i=new Map;for(let s of a){if(s.name===null||!Or(s.name))continue;let l=Ar(s.type,s.name);i.has(l)||i.set(l,s.styleId);}return Object.freeze({entries:Object.freeze(a),idOf:(s,l)=>i.get(Ar(s,l))??null,nameOf:(s,l)=>{let d=n.get(l);return !d||d.type!==s||d.name===null?null:i.get(Ar(s,d.name))===l?d.name:null},defaultParagraphId:o})}function Vs(e){let t=ud$1(e),n={styles:t?.root??null,settings:Bf(e)?.root??null,numbering:vd$1(e)},o=(i,s,l)=>_s(n,i,s,"proposed",l);if(!t)return Object.freeze({nameOf:()=>null,idOf:()=>null,characterIdOf:()=>null,defaultId:null,present:false,inheritsRtl:o});let r=Et(t),a=r.defaultParagraphId;return Object.freeze({nameOf:i=>r.nameOf("paragraph",i),idOf:i=>r.idOf("paragraph",i),characterIdOf:i=>r.idOf("character",i),defaultId:a,present:true,inheritsRtl:o})}function Ao(e,t,n){let o=eb(e,t);if(!o||o.kind!=="paragraph")return null;let r=Bc(Sh(Qh(o),"pStyle"));return r!==null?n.nameOf(r):n.defaultId===null?null:n.nameOf(n.defaultId)}function Bc(e){if(!e)return null;for(let t of e.attributes)if(t.localName==="val")return t.value;return null}function Oo(e,t){if(typeof e!="string"||e.trim().length===0)return {ok:false,detail:"style: not a name"};if(e.length>Jt)return {ok:false,detail:"style: name too long"};if(!X(e))return {ok:false,detail:"style: not valid XML text"};if(!t.present)return {ok:false,detail:"no-styles-defined: this document defines no styles"};let n=t.idOf(e);return n===null?{ok:false,detail:"style-not-defined: this document defines no paragraph style with that name"}:{ok:true,styleId:n}}function Us(e,t,n){return t>=n?null:{text:e.text.slice(t-e.rawStart,n-e.rawStart),rawStart:t,rawEnd:n,...e.symbol?{symbol:true}:{},...e.symbol&&e.symbolDisplays?{symbolDisplays:e.symbolDisplays}:{}}}function Ks(e,t){let n=[],o=0;for(let r of e){for(;o<t.length&&t[o].end<=r.rawStart;)o+=1;let a=r.rawEnd-r.rawStart;if(r.text.length!==a||r.resultRuns||r.symbolOffsets){let l=t[o];(!l||l.start>=r.rawEnd)&&n.push(r);continue}let i=r.rawStart;for(;o<t.length;){let l=t[o];if(l.end<=i){o+=1;continue}if(l.start>=r.rawEnd)break;let d=Us(r,i,Math.min(l.start,r.rawEnd));if(d&&n.push(d),i=Math.max(i,l.end),l.end<=r.rawEnd&&(o+=1),i>=r.rawEnd)break}let s=Us(r,i,r.rawEnd);s&&n.push(s);}return n}function Ro(e,t){return t.map(n=>{if(!n.text.includes(`
|
|
2
|
+
`))return n;let r=n.text.length===n.rawEnd-n.rawStart&&!n.resultRuns?n.text.replaceAll(`
|
|
3
|
+
`,(a,i)=>e[n.rawStart+i]):n.text.replaceAll(`
|
|
4
|
+
`,xj);return {...n,text:r}})}function An(e,t,n){let o=Mm$1(e,t);if(n==="model")return b$2(o);let r=c(e,t,n);if(n==="allMarkup")return a$1(Ro(o,r));let a=$s(e,Hc);if(a.length===0)return a$1(Ro(o,r));let i=Ks(r,a);return a$1(Ro(o,i))}function Ws(e,t,n){if(n==="original")return An(e,t,"original");let o=Mm$1(e,t),r=c(e,t,"current"),a=$s(e,_c),i=a.length===0?r:Ks(r,a);return a$1(Ro(o,i))}var Hc=new Set(["revisionInsert","revisionMoveTo"]),_c=new Set(["revisionDelete","revisionMoveFrom"]);function $s(e,t){let n=Ei(e),o=[],r=(i,s)=>{if(!(s>64||i.kind==="textValue")){if(t.has(i.kind)){let l=n.spanOf(i);l&&l.end>l.start&&o.push({start:l.start,end:l.end});return}for(let l of i.children)r(l,s+1);}};r(e,0),o.sort((i,s)=>i.start-s.start||s.end-i.end);let a=[];for(let i of o){let s=a[a.length-1];s&&i.start<=s.end?s.end=Math.max(s.end,i.end):a.push({...i});}return a}var Rn="\r",jc=Object.freeze({nameOf:()=>null,idOf:()=>null,characterIdOf:()=>null,defaultId:null,present:false,inheritsRtl:()=>false}),Vc=Object.freeze([]),Uc=Object.freeze([]),zs=Object.freeze([]),Gs=Object.freeze({ok:true,shapes:[]}),Kc=Object.freeze({package:null,body:null,story:()=>null,storyOf:()=>null,sections:()=>Uc,furniture:()=>zs,noteIds:()=>({ok:true,ids:Xs}),shapes:()=>Gs,styles:()=>jc});function Wc(e){return e.kind==="textValue"?Vc:Object.freeze(e.children.filter(t=>t.kind!=="textValue").map(t=>{let n=[];jd$1([t],n,0);let o=t.kind==="paragraph"?"paragraph":t.kind==="table"?"table":"other",r=t.kind==="paragraph"&&Sh(Qh(t),"sectPr")!==void 0;return Object.freeze({id:t.id,kind:o,paragraphIds:Object.freeze(n.map(a=>a.id)),removable:o!=="other"&&!r})}))}function On(e,t,n,o,r){let a=id$1(o),i=Object.freeze(a.map(f=>f.id)),s=new Map,l=new Map;a.forEach((f,y)=>{s.set(f.id,y),l.set(f.id,f);});let d=new Map,m=f=>{if(!s.has(f))return null;let y=d.get(f);if(y!==void 0)return y;let x=Jm$1(t,f)??"";return d.set(f,x),x},c=new Map,h=(f,y="allMarkup")=>{let x=l.get(f);if(!x||x.kind!=="paragraph")return null;let v=`${f}:${y}`,P=c.get(v);if(P)return P;let A=An(x,m(f)??"",y);return c.set(v,A),A};return {story:e,part:t,root:o,scope:n,paragraphIds:i,blocks:Wc(o),has:f=>s.has(f),indexOf:f=>s.get(f)??-1,paragraph(f){let y=l.get(f);return y?{nodeId:f,paraId:wb(y),text:h(f)?.text??""}:null},node:f=>l.get(f)??null,rawText:m,paragraphText:(f,y)=>h(f,y)?.text??null,projectedText:h,text:f=>i.map(y=>h(y,f)?.text??"").join(Rn),styles:r}}function Po(e,t){let n=On(e.story,e.part,e.scope,t,e.styles);return {...n,indexOf:o=>n.has(o)?e.indexOf(o):-1}}function Pt(e){let t=e.parts.get(e.mainDocumentPart);if(!t)return Kc;let n,o=()=>n??=Vs(e),r,a=()=>r??=sf$1(e),i,s=new Map,l=new Map,d=new Map,m=A=>{let N=Y(A),S=d.get(N);if(S)return S;let M=x(A),j=M?M.paragraphIds.flatMap(C=>{let z=M.node(C);return z?[z]:[]}):[],J=M?ko(M.part,j):Gs;return d.set(N,J),J},c=A=>{let N=l.get(A);if(N)return N;let S=pj(e,A);if(!S){let G={ok:true,ids:Xs};return l.set(A,G),G}let M=[],j=new Set,J=new Set,C=0,z=false;for(let G of S.root.children){if(Qc$1(G)!==A)continue;if(C+=1,G.kind!=="note"){z=true;continue}if(!Tc$1(G))continue;let Q=Rc$1(G);if(Q===null){z=true;continue}j.has(Q)?J.add(Q):(j.add(Q),M.push(Q));}let K=C>_c$1?{ok:false,reason:"truncated"}:z?{ok:false,reason:"malformed"}:J.size>0?{ok:false,reason:"duplicates",duplicateIds:Object.freeze([...J])}:{ok:true,ids:Object.freeze(M)};return l.set(A,K),K},h=A=>{let N=a()[A.sectionIndex];return N?(A.kind==="header"?N.headers:N.footers).get(A.variant)??null:null},f=A=>{if(A.kind==="body"){let S=hd$2(t);return S?On(A,t,{kind:"body"},S,o):null}if(A.kind==="note"){let S=c(A.noteKind);if(!S.ok||!S.ids.includes(A.noteId))return null;let M=pj(e,A.noteKind);if(!M)return null;let j=cd$1(M.root,A.noteId);return !j||!Tc$1(j)?null:On(A,M,{kind:"notesPart",noteKind:A.noteKind},j,o)}if(A.kind==="textbox"){let S=y(A.owner),M=m(A.owner);if(!S||!M.ok)return null;let j=M.shapes.find(C=>C.id===A.shapeId),J=j?.textboxRoot??(j?.emptyFrame?Ds(j):null);return J?On(A,S.part,S.scope,J,o):null}let N=h(A);return N?On(A,N.part,{kind:"headerFooter",rId:N.rId},N.part.root,o):null},y=A=>x(A),x=A=>{let N=Y(A);if(s.has(N))return s.get(N)??null;let S=f(A);return s.set(N,S),S},v=(A,N)=>{let S=m(A);if(!S.ok)return null;for(let M of S.shapes){if(!M.textboxRoot)continue;let j={kind:"textbox",owner:A,shapeId:M.id};if(x(j)?.has(N))return j}return null};return {package:e,get body(){return x(ve)},story:x,storyOf:A=>{if(x(ve)?.has(A))return ve;let S=[{kind:"body"}];for(let[M]of a().entries())for(let j of ["header","footer"])for(let J of Nt){let C={kind:j,sectionIndex:M,variant:J};if(x(C)){if(x(C).has(A))return C;S.push(C);}}for(let M of ["footnote","endnote"]){let j=c(M);if(j.ok)for(let J of j.ids){let C={kind:"note",noteKind:M,noteId:J};if(x(C)?.has(A))return C}}for(let M of S){let j=v(M,A);if(j)return j}return null},sections:()=>i??=Fs(e,t,a()),furniture(A){let N=a()[A];if(!N)return zs;let S=[];for(let M of ["header","footer"]){let j=M==="header"?N.headers:N.footers;for(let J of Nt){let C=j.get(J);C&&S.push(Object.freeze({kind:M,variant:J,declared:!C.inherited}));}}return Object.freeze(S)},noteIds:c,shapes:m,styles:o}}var Xs=Object.freeze([]);function Ys(e){let t=[];for(let n of e.pages){let o=n.pageFieldSource?.pageNumber??n.index+1,r=hd$1(o,n.pageFieldSource?.format),a=i=>{for(let s of i)if(s.kind==="paragraph")for(let l of s.lines)t.push({...l.range,pageNumber:o,pageNumberText:r});else for(let l of s.rows)for(let d of l.cells)a(d.blocks);};a(n.fragments),n.header&&a(n.header.fragments),n.footer&&a(n.footer.fragments);for(let i of n.footnotes?.notes??[])a(i.fragments);for(let i of n.endnotes?.notes??[])a(i.fragments);}return {pageCount:e.pages.length,ranges:t}}function qs(e,t,n,o){if(!e||!Number.isInteger(e.pageCount)||e.pageCount<1)return null;let r=eb(t,n);if(!r||r.kind!=="paragraph")return null;let a=Bi(r).find(s=>s.node.id===o);if(!a)return null;let i=e.ranges.find(s=>s.paragraphId===n&&s.start<=a.start&&s.end>a.start);return !i||!Number.isInteger(i.pageNumber)||i.pageNumber<1?null:{pageNumber:i.pageNumber,pageNumberText:i.pageNumberText,pageCount:e.pageCount}}function $c(e){return async t=>{let n=i(t,{measurer:e.measurer,producer:e.producer,displayMode:"proposed"});if(!n.ok)throw new Error("field pagination could not open the document");try{return Ys(await n.session.layout())}finally{n.session.dispose();}}}var re=()=>`${new Date().toISOString().slice(0,19)}Z`;function Js(e,t,n){let o=(r,a)=>({state:n,step:{ok:false,error:{code:"unsupported-capability",message:r,detail:a}}});return e.op==="getChangeTrackingMode"||e.op==="setChangeTrackingMode"?t?e.op==="getChangeTrackingMode"?{state:n,step:{ok:true,kind:"query",value:{kind:"text",text:n.mode}}}:e.mode!=="Off"&&e.mode!=="TrackMineOnly"?o("TrackAll requires shared tracking enforcement for every peer and is not supported","change-tracking-mode-unsupported"):e.mode==="TrackMineOnly"&&(typeof e.author!="string"||!e.author.trim()||!X(e.author))?o("TrackMineOnly requires a non-empty XML-safe runtime author","change-tracking-author-required"):{state:{mode:e.mode,...e.mode==="TrackMineOnly"?{author:e.author.trim()}:{}},step:{ok:true,kind:"query",value:{kind:"applied"}}}:o("this host does not support runtime-local change tracking","change-tracking-unsupported-host"):n.mode==="Off"||Rr(e)?null:o(`${e.op} does not support TrackMineOnly; no permanent edit was applied`,"change-tracking-operation-unsupported")}function Rr(e){return !je(e)||e.op==="setChangeTrackingMode"||e.op==="insertText"?true:e.op==="insertBreak"?e.breakType!=="Line"||!(e.location==="Replace"&&"body"in e.span):e.op==="splitParagraph"||e.op==="insertTable"||e.op==="insertTableRows"||["insertField","insertOoxml","setFieldResult","deleteField"].includes(e.op)||["updateTable","updateTableCell","splitTableCell"].includes(e.op)||e.op==="replaceSpan"&&!("body"in e.span)||e.op==="deleteParagraph"?true:["insertContentControl","setContentControlProperties","setContentControlValue","insertContentControlText","startNewList","setListLevelFormat","attachToList","detachFromList","setListLevel","insertParagraph","setFont","setStyle","setParagraphFormat","proposeInsertion","proposeDeletion","proposeReplacement","insertComment","replyToComment","deleteComment","setCommentResolved","acceptRevision","rejectRevision","resolveRevisionBatch","setRevisionAuthorBatch","acceptAllRevisions","rejectAllRevisions","selectSpan","selectBookmark","insertBookmark","deleteBookmark"].includes(e.op)}function Qs(e,t,n){if(!n||!["setFont","setStyle","setParagraphFormat","insertParagraph","attachToList","detachFromList","setListLevel","splitParagraph"].includes(e.op)||!t.ok||t.kind!=="command")return t;if(e.op==="splitParagraph"&&t.ops.some(r=>r.op==="deleteText"))return {ok:false,error:{code:"unsupported-capability",message:"a tracked split cannot remove its delimiters; pass trimDelimiters as false",detail:"change-tracking-operation-unsupported"}};let o={author:n,date:re()};return {...t,ops:t.ops.map(r=>{if(r.op==="insertText"||r.op==="insertParagraphBesideTable")return {...r,revision:o};if(r.op==="splitParagraph")return {op:"splitParagraphMany",paragraphId:r.paragraphId,offsets:[r.offset],revision:o};if(r.op==="splitParagraphMany")return {...r,revision:o};if(r.op==="setRunProperties"||r.op==="setParagraphProperties"||r.op==="setParagraphMarkProperties"||r.op==="setListNumbering"||r.op==="setListLevel")return {...r,revision:o};throw new Error("Formatting plan contains an operation without property revision support")})}}function zc(){let e=globalThis.crypto,t=e?.getRandomValues;if(typeof t!="function")throw new Error("automation: no secure random source. globalThis.crypto.getRandomValues is required to scope document handles to one host.");let n=t.call(e,new Uint8Array(16)),o="";for(let r of n)o+=r.toString(16).padStart(2,"0");return o}function Gc(e){return typeof e=="object"&&e!==null&&"kind"in e&&"ref"in e}function Zs(){let e=new Map,t=new Map,n=new Map,o=new Map,r=zc(),a=null,i=(l,d)=>{let m=(o.get(l)??0)+1;o.set(l,m);let c=`${l}:${r}:${String(m)}`;return e.set(c,d),Object.freeze({kind:l,ref:c})},s=(l,d,m)=>{let c=`${l}\0${d}`,h=n.get(c);if(h)return Object.freeze({kind:l,ref:h});let f=i(l,m);return n.set(c,f.ref),f};return {document(){return a??=i("document",{kind:"document"}),a},body(l,d){return s("body",`${Y(l)}:${d??""}`,{kind:"body",story:l,...d?{rootNodeId:d}:{}})},table(l,d){return s("table",`${Y(d)}:${l}`,{kind:"table",nodeId:l,story:d})},tableRow(l,d){return s("tableRow",`${Y(d)}:${l}`,{kind:"tableRow",nodeId:l,story:d})},tableCell(l,d){return s("tableCell",`${Y(d)}:${l}`,{kind:"tableCell",nodeId:l,story:d})},field(l,d,m){return s("field",`${Y(m)}:${d}`,{kind:"field",paragraphId:l,fieldNodeId:d,story:m})},inlinePicture(l,d){return s("inlinePicture",`${Y(d)}:${l}`,{kind:"inlinePicture",drawingNodeId:l,story:d})},shape(l,d){return s("shape",`${Y(d)}:${String(l)}`,{kind:"shape",shapeId:l,owner:d})},paragraph(l,d){let m=t.get(l);if(m)return Object.freeze({kind:"paragraph",ref:m});let c=i("paragraph",{kind:"paragraph",paragraphId:l,story:d});return t.set(l,c.ref),c},section(l){return s("section",String(l),{kind:"section",index:l})},note(l,d){return s("note",`${l}:${String(d)}`,{kind:"note",noteKind:l,noteId:d})},comment(l,d){return s("comment",`${Y(d)}\0${l}`,{kind:"comment",commentId:l,story:d})},revision(l,d){return s("revision",`${Y(d)}\0${l}`,{kind:"revision",revisionId:l,story:d})},bookmark(l,d){return s("bookmark",`${Y(d)}\0${l}`,{kind:"bookmark",name:l,story:d})},list(l,d){return s("list",`${Y(d)}\0${l}`,{kind:"list",numId:l,story:d})},contentControl(l,d){return s("contentControl",`${Y(d)}\0${l}`,{kind:"contentControl",nodeId:l,story:d})},retargetRevisions(l,d){let m=h=>`revision\0${Y(l)}\0${h}`,c=d.flatMap(({from:h,to:f})=>{let y=h===f?void 0:n.get(m(h));return y?[{ref:y,from:h,to:f}]:[]});for(let{from:h}of c)n.delete(m(h));for(let{ref:h,to:f}of c)n.has(m(f))||(n.set(m(f),h),e.set(h,{kind:"revision",revisionId:f,story:l}));},retarget(l,d){let m=t.get(l);if(!m||l===d)return;let c=e.get(m);!c||c.kind!=="paragraph"||(t.delete(l),e.set(m,{kind:"paragraph",paragraphId:d,story:c.story}),t.has(d)||t.set(d,m));},resolve(l,d){if(!Gc(l)||l.kind!==d||typeof l.ref!="string")return null;let m=e.get(l.ref);return !m||m.kind!==d?null:m}}}var tt="target-removed";function Ve(e,t){return {ok:false,code:e,detail:t}}function Ue(e){return {ok:true,value:e}}function le(e,t,n,o){let r=n.resolve(e,t);if(!r||r.kind!=="body"&&r.kind!=="paragraph")return Ve("invalid-handle",`not-a-${t}-handle`);let a=o.story(r.story);if(!a)return Ve("invalid-handle",`no-such-story:${Y(r.story)}`);if(r.kind==="body"&&r.rootNodeId){let i=eb(a.part,r.rootNodeId);return !i||i.kind!=="tableCell"?Ve("invalid-handle","cell-not-in-story"):Ue(Po(a,i))}return Ue(a)}function he(e,t,n){let o=t.resolve(e,"paragraph");if(!o||o.kind!=="paragraph")return Ve("invalid-handle","not-a-paragraph-handle");let r=n.story(o.story);if(!r)return Ve("invalid-handle",`no-such-story:${Y(o.story)}`);let a=r.indexOf(o.paragraphId);return a<0?Ve("invalid-handle","paragraph-not-in-body"):Ue({story:o.story,paragraphId:o.paragraphId,index:a,offset:0})}function Xc(e,t,n){let o=he(e.paragraph,t,n);if(!o.ok)return o;let a=(n.story(o.value.story)?.rawText(o.value.paragraphId)??"").length,{offset:i}=e;return !Number.isInteger(i)||i<0||i>a?Ve("invalid-offset",`offset ${String(i)} outside 0..${String(a)}`):Ue({...o.value,offset:i})}function Qt(e,t,n){if("paragraph"in e){if(!("at"in e))return Xc(e,t,n);let s=he(e.paragraph,t,n);if(!s.ok||e.at==="start")return s;let d=(n.story(s.value.story)?.rawText(s.value.paragraphId)??"").length;return Ue({...s.value,offset:d})}let o=le(e.body,"body",t,n);if(!o.ok)return o;let r=o.value.paragraphIds;if(r.length===0)return Ve("invalid-offset","empty-story");if(e.at==="start")return Ue({story:o.value.story,paragraphId:r[0],index:o.value.indexOf(r[0]),offset:0});let a=r.length-1,i=r[a];return Ue({story:o.value.story,paragraphId:i,index:o.value.indexOf(i),offset:(o.value.rawText(i)??"").length})}function Yc(e,t){return e.index<t.index||e.index===t.index&&e.offset<=t.offset}function qc(e){let t=e.paragraphIds;if(t.length===0)return null;let n=t.length-1,o=t[n];return {start:{story:e.story,paragraphId:t[0],index:e.indexOf(t[0]),offset:0},end:{story:e.story,paragraphId:o,index:e.indexOf(o),offset:(e.rawText(o)??"").length}}}function W(e,t,n){if("body"in e){let a=le(e.body,"body",t,n);return a.ok?Ue(qc(a.value)):a}if("paragraph"in e){let a=he(e.paragraph,t,n);if(!a.ok)return a;let s=(n.story(a.value.story)?.rawText(a.value.paragraphId)??"").length;return Ue({start:a.value,end:{...a.value,offset:s}})}let o=Qt(e.start,t,n);if(!o.ok)return o;let r=Qt(e.end,t,n);return r.ok?Y(o.value.story)!==Y(r.value.story)?Ve("invalid-handle","span-crosses-stories"):Yc(o.value,r.value)?Ue({start:o.value,end:r.value}):Ve("invalid-offset","span-start-after-end"):r}function ee(e,t,n){if("body"in e)return le(e.body,"body",t,n);if("paragraph"in e)return le(e.paragraph,"paragraph",t,n);let o=e.start;return "paragraph"in o?le(o.paragraph,"paragraph",t,n):le(o.body,"body",t,n)}function Io(e,t,n){if("paragraph"in e)return he(e.paragraph,t,n);let o=le(e.body,"body",t,n);if(!o.ok)return o;let r=o.value.paragraphIds;if(r.length===0)return Ve("invalid-offset","empty-story");let a=e.at==="first"?0:r.length-1;return Ue({story:o.value.story,paragraphId:r[a],index:a,offset:0})}function be(e,t){if(!e)return [];let n=t.paragraphIds,o=n[e.start.index]===e.start.paragraphId?e.start.index:n.indexOf(e.start.paragraphId),r=n[e.end.index]===e.end.paragraphId?e.end.index:n.indexOf(e.end.paragraphId);return o<0||r<o?[]:n.slice(o,r+1)}function mt(e,t){if(!e)return [];let n=be(e,t),o=n.length-1;return n.map((r,a)=>{let i=(t.rawText(r)??"").length,s=a===0?e.start.offset:0,l=a===o?e.end.offset:i;return {paragraphId:r,start:s,end:l,whole:s===0&&l===i}})}function el(e,t,n,o="allMarkup"){if(!e)return "";let r=be(e,t);return r.length===1?t.projectedText(e.start.paragraphId,o)?.sliceRaw(e.start.offset,e.end.offset)??"":r.map((a,i)=>{let s=t.projectedText(a,o);if(!s)return "";let l=(t.rawText(a)??"").length;return i===0?s.sliceRaw(e.start.offset,l):i===r.length-1?s.sliceRaw(0,e.end.offset):s.text}).join(n)}function Ae(e,t){return {start:{paragraph:t.paragraph(e.start.paragraphId,e.start.story),offset:e.start.offset},end:{paragraph:t.paragraph(e.end.paragraphId,e.end.story),offset:e.end.offset}}}var Jc=new Set(["TextBox","GeometricShape","Picture","Group","Canvas","Unsupported"]),nt=(e,t,n)=>({ok:false,error:{code:e,message:t,...n===void 0?{}:{detail:n}}}),Pr=e=>({ok:true,kind:"query",value:e});function Qc(e,t,n){let o=t.resolve(e,"shape");if(!o||o.kind!=="shape")return nt("invalid-handle","that handle does not name a shape","shape");let r=n.shapes(o.owner);if(!r.ok)return nt("ambiguous-document","shape identities in that story are not completely and unambiguously enumerable",r.reason);let a=r.shapes.find(i=>i.id===o.shapeId);return a?{owner:o.owner,shape:a}:nt("invalid-handle","that shape is not in this document",Y(o.owner))}function tl(e,t,n){if(e.op==="getShapes"){let a=e.types;if(a!==void 0&&(!Array.isArray(a)||a.some(m=>!Jc.has(m))))return nt("unsupported-content","unknown shape type","types");if(!("body"in e.span)&&!("paragraph"in e.span))return nt("unsupported-content","shapes are listed for a body or a paragraph only");let i=W(e.span,t,n),s=ee(e.span,t,n);if(!i.ok||!s.ok)return nt("invalid-handle","that range no longer exists",i.ok?s.ok?void 0:s.detail:i.detail);let l=n.shapes(s.value.story);if(!l.ok)return nt("ambiguous-document","shape identities in that story are not completely and unambiguously enumerable",l.reason);let d=new Set(i.value?be(i.value,s.value):[]);return Pr({kind:"handles",handles:l.shapes.filter(m=>d.has(m.hostParagraphId)&&(!a||a.includes(m.type))).map(m=>t.shape(m.id,s.value.story))})}let o=Qc(e.shape,t,n);if("ok"in o)return o;if(e.op==="getShape"){let{id:a,name:i,type:s}=o.shape;return Pr({kind:"shape",shape:{id:a,name:i,type:s}})}if(!o.shape.textboxRoot&&!o.shape.emptyFrame)return nt("unsupported-content","that shape holds no text story of its own",o.shape.type);if(!hr(o.owner))return nt("unsupported-content","text boxes are reachable in the body, headers and footers only",Y(o.owner));let r={kind:"textbox",owner:o.owner,shapeId:o.shape.id};return n.story(r)?Pr({kind:"handle",handle:t.body(r)}):nt("invalid-handle","that text box is not in this document",Y(r))}var Zc=32,ep=32,tp=new Set([" "," ",""]);function ft(e,t,n){return {ok:false,error:n===void 0?{code:e,message:t}:{code:e,message:t,detail:n}}}function rl(e,t,n){if(e.op==="expandSpan")return sp(e,t,n);let o=e.op==="getTextRanges"?e.scope:e.span,r=W(o,t,n);if(!r.ok)return ft(r.code,"that span is not a place",r.detail);let a=ee(o,t,n);if(!a.ok)return ft(a.code,"that span is not a place",a.detail);if(e.op==="getReviewedText")return e.version!=="original"&&e.version!=="current"?ft("unsupported-content","unknown change tracking version","version"):{ok:true,kind:"query",value:{kind:"text",text:ip(r.value,a.value,e.version)}};let i=np(e.endingMarks);if(!i)return ft("unsupported-content","ending marks are not usable","endingMarks");let s=e.projection??"allMarkup";return s!=="allMarkup"&&s!=="original"&&s!=="model"?ft("unsupported-content","unknown text projection","projection"):{ok:true,kind:"query",value:{kind:"spans",spans:ap(r.value,a.value,t,i,e.trimSpacing===true,s)}}}function np(e){if(!Array.isArray(e)||e.length===0||e.length>Zc)return null;let t=[];for(let n of e){if(typeof n!="string"||n.length===0||n.length>ep||op(n))return null;t.push(n);}return t.sort((n,o)=>o.length-n.length)}function op(e){for(let t=0;t<e.length;t+=1){let n=e.charCodeAt(t);if(n>=55296&&n<=56319){let o=e.charCodeAt(t+1);if(!(o>=56320&&o<=57343))return true;t+=1;}else if(n>=56320&&n<=57343)return true}return false}function rp(e,t,n,o,r,a=()=>true){let i=[],s=h=>!a(h)||r&&tp.has(e[h]),l=(h,f)=>{let y=h,x=f;for(;y<x&&s(y);)y+=1;for(;x>y&&s(x-1);)x-=1;y<x&&i.push([y,x]);},d=(h,f)=>{for(let y=h;y<h+f;y+=1)if(!a(y))return false;return true},m=t,c=t;for(;c<n;){let h=o.find(x=>c+x.length<=n&&e.startsWith(x,c)&&d(c,x.length));if(h){c+=h.length,l(m,c),m=c;continue}let f=e.charCodeAt(c),y=f>=55296&&f<=56319&&c+1<n;c+=y?2:1;}return m<n&&l(m,n),i}function ap(e,t,n,o,r,a){if(!e)return [];let i=be(e,t),s=i.length-1,l=[];for(let[d,m]of i.entries()){let c=t.projectedText(m,"model"),h=t.projectedText(m,a);if(!c||!h)continue;let f=d===0?e.start.offset:0,y=d===s?e.end.offset:c.text.length,x=n.paragraph(m,t.story),v=h.projectedOffsets(f,y),P=A=>v[A+1-f]>v[A-f];for(let[A,N]of rp(c.text,f,y,o,r,P))l.push({start:{paragraph:x,offset:A},end:{paragraph:x,offset:N}});}return l}function ip(e,t,n){if(!e)return "";let o=be(e,t),r=o.length-1,a="";for(let[i,s]of o.entries()){let l=t.node(s),d=t.rawText(s);if(!l||l.kind!=="paragraph"||d===null)continue;let m=Ws(l,d,n),c=i===0?e.start.offset:0,h=i===r?e.end.offset:d.length;if(a+=m.sliceRaw(c,h),i===r)break;Fn$1(l,n==="current"?"del":"ins")||(a+=Rn);}return a}function nl(e,t){return t.story(e.story)?.indexOf(e.paragraphId)??e.index}function ol(e,t,n){let o=nl(e,n),r=nl(t,n);return o<r||o===r&&e.offset<t.offset}function sp(e,t,n){let o=W(e.span,t,n);if(!o.ok)return ft(o.code,"that span is not a place",o.detail);let r=W(e.to,t,n);if(!r.ok)return ft(r.code,"that span is not a place",r.detail);if(!o.value||!r.value)return ft("invalid-offset","empty story");if(Y(o.value.start.story)!==Y(r.value.start.story))return ft("unsupported-content","the ranges are in different stories","span-crosses-stories");let a=ol(r.value.start,o.value.start,n)?r.value.start:o.value.start,i=ol(o.value.end,r.value.end,n)?r.value.end:o.value.end;return {ok:true,kind:"query",value:{kind:"span",span:Ae({start:a,end:i},t)}}}var lp=1e4;function al(e,t){let n=[],o=t.kind==="contentControl"?oc(t):t;if(!o)return n;for(let r of sc(o))if(!(r.ancestors.length>0)){if(n.length>=lp)break;n.push(ul(e,r.node));}return n}function il(e,t){for(let n of sc(e.root))if(n.node.id===t)return ul(e,n.node);return null}function sl(e,t){for(let n of sc(e.root))if(n.node.id===t)return n.node;return null}function ll(e,t){for(let n of e.paragraphIds){let o=e.node(n);if(!(!o||o.kind!=="paragraph")&&sc(o).some(r=>r.node.id===t))return o}return null}function So(e,t){let n=Zt(t);if(n.length>0){let a=n[0],i=n[n.length-1],s=e.rawText(i);return s===null||!e.has(a)?null:{start:{paragraphId:a,offset:0},end:{paragraphId:i,offset:s.length}}}let o=ll(e,t.id);if(!o)return null;let r=Ei(o).spanOf(t);return r?{start:{paragraphId:o.id,offset:r.start},end:{paragraphId:o.id,offset:r.end}}:null}function dp(e,t,n){let o=ll(e,t.id),r=oc(t);if(!o||!r)return null;let a={...o,children:r.children},i=Km$1(a);return An(a,i,n).text}function dl(e,t,n="allMarkup"){if(n==="allMarkup")return uc$1(t,xj);let o=dp(e,t,n);if(o!==null)return o;let r=So(e,t);if(!r)return "";let a=e.indexOf(r.start.paragraphId),i=e.indexOf(r.end.paragraphId);if(a<0||i<a)return "";let s=[];for(let l=a;l<=i;l+=1){let d=e.paragraphIds[l],m=e.projectedText(d,n),c=e.rawText(d);if(!m||c===null)return "";s.push(m.sliceRaw(l===a?r.start.offset:0,l===i?r.end.offset:c.length));}return s.join("\r")}function ul(e,t){return {nodeId:t.id,properties:qc$1(t),lock:pm$1(e.part,t.id),paragraphIds:Zt(t)}}function Zt(e){let t=oc(e);if(!t)return [];let n=[];return jd$1(t.children,n,0),n.map(o=>o.id)}var up=1e4;function pl(e){return (e.op==="getContentControls"||e.op==="getContentControlById"||e.op==="getContentControlsByTag"||e.op==="getContentControlsByTitle")&&typeof e.scope=="object"&&e.scope!==null&&"span"in e.scope}function Pn(e,t,n){return {ok:false,error:n===void 0?{code:e,message:t}:{code:e,message:t,detail:n}}}var cl=new WeakMap;function cp(e){let t=cl.get(e.root);if(t)return t;let n=new Map;for(let o of sc(e.root))for(let r of Zt(o.node)){let a=n.get(r);a?a.push(o.node):n.set(r,[o.node]);}return cl.set(e.root,n),n}function pp(e,t,n,o){return e===t||n===o?n<=t&&e<=o:Math.max(e,n)<Math.min(t,o)}function mp(e,t){let n=[],o=new Set,r=i=>{o.has(i.id)||n.length>=up||(o.add(i.id),n.push(i));},a=cp(t);for(let i of mt(e,t)){for(let d of a.get(i.paragraphId)??[])r(d);let s=t.node(i.paragraphId);if(!s||s.kind!=="paragraph")continue;let l=Ei(s);for(let d of sc(s)){let m=l.spanOf(d.node);m&&pp(i.start,i.end,m.start,m.end)&&r(d.node);}}return n}function ml(e,t,n){let o=W(e.scope.span,t,n);if(!o.ok)return Pn(o.code,"that span is not a place",o.detail);let r=ee(e.scope.span,t,n);if(!r.ok)return Pn(r.code,"that span is not a place",r.detail);let a=mp(o.value,r.value),i=s=>t.contentControl(s.id,r.value.story);switch(e.op){case "getContentControls":return {ok:true,kind:"query",value:{kind:"handles",handles:a.map(i)}};case "getContentControlById":{if(!Number.isInteger(e.id))return Pn("unsupported-content","a control id is a whole number",String(e.id));let s=a.find(l=>qc$1(l).id===e.id);return s?{ok:true,kind:"query",value:{kind:"handle",handle:i(s)}}:Pn("invalid-handle","no control in that scope carries that id",String(e.id))}default:{let s=e.op==="getContentControlsByTag",l=s?e.tag:e.title;return typeof l!="string"||l.length===0?Pn("unsupported-content","a tag or title to match is required",e.op):{ok:true,kind:"query",value:{kind:"handles",handles:a.filter(m=>{let c=qc$1(m);return (s?c.tag:c.alias)===l}).map(i)}}}}}var fp=256,fl=1e4;function Ir(e,t){if(e.kind!=="textValue"){for(let n of e.attributes)if(n.namespaceUri===pa&&n.localName===t)return n.value}}function gp(e){return e.startsWith("_")}function Dt(e,t={}){let n=new Map,o=[],r=new Set;for(let a of e.paragraphIds){let i=e.node(a);if(i?.kind!=="paragraph")continue;let s=Ei(i),l=d=>{if(d.kind!=="textValue"){if(d.kind==="bookmarkStart"){if(o.length>=fl||n.size>=fl)return;let m=Ir(d,"id"),c=Ir(d,"name");if(m===void 0||c===void 0||c.length===0||c.length>fp||gp(c)&&!t.includeHidden||r.has(c)||n.has(m))return;let h=s.spanOf(d)?.start??0;n.set(m,{name:c,start:{paragraphId:a,offset:h}});return}if(d.kind==="bookmarkEnd"){let m=Ir(d,"id");if(m===void 0)return;let c=n.get(m);if(!c)return;n.delete(m),r.add(c.name);let h=s.spanOf(d)?.start??0;o.push(Object.freeze({name:c.name,start:c.start,end:{paragraphId:a,offset:h}}));return}for(let m of d.children)l(m);}};for(let d of i.children)l(d);}return Object.freeze(o)}function wo(e,t){return Dt(e).find(n=>n.name===t)??null}function gl(e,t){let n=e.node(t);if(n?.kind!=="paragraph")return Object.freeze([]);let o=Ei(n),r=[],a=(i,s)=>{if(!(i.kind==="textValue"||s>32)){if(Ee$1(i)){let l=o.spanOf(i);l&&r.push(Object.freeze({id:i.id,paragraphId:t,start:l.start,end:l.end}));return}for(let l of i.children)a(l,s+1);}};for(let i of n.children)a(i,0);return Object.freeze(r)}function hl(e,t,n){let o=He(n,r=>fj(e,t,r));if(o.kind==="external")return o.href;if(o.kind==="internal"){let r=Fe(n);return r===void 0||r.length===0?null:`#${r}`}return null}var Co=Object.freeze({kind:"applied"}),ye=(e,t,n)=>({ok:false,error:n===void 0?{code:e,message:t}:{code:e,message:t,detail:n}}),Lt=e=>({ok:true,kind:"query",value:e});function xl(e){let t=[],n=new Set,o=r=>{let a=e.story(r);!a||n.has(Y(r))||(n.add(Y(r)),t.push(a));};o(ve),e.sections().forEach((r,a)=>{for(let i of ["header","footer"])for(let s of Nt)e.furniture(a).some(d=>d.kind===i&&d.variant===s&&d.declared)&&o({kind:i,sectionIndex:a,variant:s});});for(let r of ["footnote","endnote"]){let a=e.noteIds(r);if(a.ok)for(let i of a.ids)o({kind:"note",noteKind:r,noteId:i});}return t}function yl(e,t){let n=Yi(t);for(let o of xl(e)){let r=Dt(o,{includeHidden:true}).find(a=>Yi(a.name)===n);if(r)return {story:o,bookmark:r}}return null}var In=(e,t)=>e[0]<t[0]||e[0]===t[0]&&e[1]<t[1],en=(e,t)=>e[0]===t[0]&&e[1]===t[1],kl=(e,t)=>In(e,t)||en(e,t);function hp(e,t,n){let o=en(e.start,e.end),r=en(t.start,t.end),a;return o?a=r?en(t.start,e.start):kl(t.start,e.start)&&In(e.start,t.end):r?a=kl(e.start,t.start)&&In(t.start,e.end):a=In(t.start,e.end)&&In(e.start,t.end),a||!n?a:en(t.end,e.start)||en(t.start,e.end)}function bl(e,t,n){return (o,r)=>{let a=e(o);return t(a)??[...new Set(r)].reduce((i,s)=>i??n(a,s),null)}}function vl(e,t,n,o){if(o||!e.ok||e.kind!=="command"||e.relate)return e;let r=Nk(t.part,n.start,n.end,t.paragraphIds);return r.length===0?e:{...e,ops:[...r,...e.ops]}}function Al(e,t,n){let o=t.resolve(e,"bookmark");if(!o||o.kind!=="bookmark")return ye("invalid-handle","that handle does not name a bookmark","bookmark");let r=n.story(o.story);if(!r)return ye("invalid-handle","that story is not in this document");let a=wo(r,o.name);if(!a)return ye("invalid-handle","this document no longer declares that bookmark",tt);let i=s=>({story:r.story,paragraphId:s.paragraphId,index:r.indexOf(s.paragraphId),offset:s.offset});return {reads:r,range:{start:i(a.start),end:i(a.end)}}}function Ol(e,t,n,{admit:o,pinned:r}){if(e.op==="getBookmarkName"){let d=t.resolve(e.bookmark,"bookmark");return !d||d.kind!=="bookmark"?ye("invalid-handle","that handle does not name a bookmark","bookmark"):Lt({kind:"text",text:d.name})}if(e.op==="getBookmarks"){let d=W(e.scope,t,n);if(!d.ok)return ye(d.code,"that span is not a place",d.detail);let m=ee(e.scope,t,n);if(!m.ok)return ye(m.code,"that span is not a place",m.detail);let c=d.value,h=c===null?null:new Set(be(c,m.value)),f=Dt(m.value).filter(y=>{if(!h||c===null||!h.has(y.start.paragraphId)&&!h.has(y.end.paragraphId))return false;let x=y.start.paragraphId===c.end.paragraphId&&y.start.offset>c.end.offset,v=y.end.paragraphId===c.start.paragraphId&&y.end.offset<c.start.offset;return !x&&!v});return Lt({kind:"handles",handles:f.map(y=>t.bookmark(y.name,m.value.story))})}if(e.op==="getBookmarkNames"){let d=W(e.scope,t,n);if(!d.ok)return ye(d.code,"that range is not a place",d.detail);let m=ee(e.scope,t,n);if(!m.ok)return ye(m.code,"that range is not a place",m.detail);let c=d.value;if(!c)return Lt({kind:"texts",texts:[]});let h=(x,v)=>[m.value.indexOf(x),v],f={start:h(c.start.paragraphId,c.start.offset),end:h(c.end.paragraphId,c.end.offset)},y=Dt(m.value,{includeHidden:e.includeHidden}).filter(x=>hp(f,{start:h(x.start.paragraphId,x.start.offset),end:h(x.end.paragraphId,x.end.offset)},e.includeAdjacent)).map(x=>x.name);return Lt({kind:"texts",texts:Object.freeze(y)})}if(e.op==="getBookmarkRangeByName"){if(!t.resolve(e.document,"document"))return ye("invalid-handle","that handle does not name a document","document");if(typeof e.name!="string")return ye("unsupported-content","a bookmark name is a string");let d=yl(n,e.name);if(!d)return Lt({kind:"spans",spans:[]});let m=c=>({story:d.story.story,paragraphId:c.paragraphId,index:d.story.indexOf(c.paragraphId),offset:c.offset});return Lt({kind:"spans",spans:[Ae({start:m(d.bookmark.start),end:m(d.bookmark.end)},t)]})}if(e.op==="insertBookmark"){if(typeof e.name!="string"||Wi(e.name)!==null)return ye("unsupported-content","a bookmark name starts with a letter or an underscore, holds only letters, digits and underscores, and has at most 40 characters","invalid-bookmark-name");let d=W(e.span,t,n);if(!d.ok)return ye(d.code,"that range is not a place",d.detail);let m=ee(e.span,t,n);if(!m.ok)return ye(m.code,"that range is not a place",m.detail);let c=d.value;if(!c)return ye("invalid-offset","this story holds no paragraph to bookmark");let h=Yi(e.name),f=new Set(xl(n).filter(v=>v.part.name!==m.value.part.name&&Dt(v,{includeHidden:true}).some(P=>Yi(P.name)===h)).map(v=>v.part.name)),y=o(m.value,[c.start.paragraphId,c.end.paragraphId]);return y||{ok:true,kind:"command",ops:[{op:"insertBookmark",name:e.name,start:{paragraphId:c.start.paragraphId,offset:c.start.offset},end:{paragraphId:c.end.paragraphId,offset:c.end.offset}}],story:m.value.story,...f.size>0?{packageEdits:[v=>{let P=v;for(let A of f)P=Mk(P,A,e.name);return P}]}:{},answer:()=>Co}}let a=e.target,i;if("bookmark"in a){let d=t.resolve(a.bookmark,"bookmark");if(!d||d.kind!=="bookmark")return ye("invalid-handle","that handle does not name a bookmark","bookmark");let m=n.story(d.story),c=m?Dt(m,{includeHidden:true}).find(h=>h.name===d.name):void 0;if(!m||!c)return ye("invalid-handle","this document no longer declares that bookmark",d.name);i={story:m,bookmark:c};}else {if(!t.resolve(a.document,"document"))return ye("invalid-handle","that handle does not name a document","document");if(typeof a.name!="string")return ye("unsupported-content","a bookmark name is a string");i=yl(n,a.name);}if(!i)return Lt(Co);let s=r();if(s===null||Y(s)!==Y(i.story.story)){let d=i.story.part.name,m=i.bookmark.name;return {ok:true,kind:"command",ops:[],story:s??i.story.story,packageEdits:[c=>Mk(c,d,m)],answer:()=>Co}}let l=o(i.story,[i.bookmark.start.paragraphId,i.bookmark.end.paragraphId]);return l||{ok:true,kind:"command",ops:[{op:"deleteBookmark",name:i.bookmark.name}],story:i.story.story,answer:()=>Co}}var yp=20*1024*1024;function Sr(e,t=yp){if(typeof e!="string"||e.length===0||e.length>Math.ceil(t/3)*4||e.length%4!==0)return null;let n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=e.endsWith("==")?2:e.endsWith("=")?1:0,r=new Uint8Array(e.length/4*3-o),a=0;for(let i=0;i<e.length;i+=4){let s=i+4===e.length,l=s?4-o:4,d=[0,0,0,0];for(let c=0;c<l;c++){let h=n.indexOf(e[i+c]);if(h<0)return null;d[c]=h;}if(s&&(o===2&&(d[1]&15)!==0||o===1&&(d[2]&3)!==0))return null;let m=d[0]<<18|d[1]<<12|d[2]<<6|d[3];a<r.length&&(r[a++]=m>>>16),a<r.length&&(r[a++]=m>>>8),a<r.length&&(r[a++]=m);}return r}function Rl(e,t,n,o,r){let a=Sr(r);if(!a)return {ok:false,detail:"picture: invalid or oversized base64 (20 MiB maximum)"};let i=Of$1(a);if(i!=="image/png"&&i!=="image/jpeg")return {ok:false,detail:"picture: only PNG and JPEG are supported"};if(!kp(a,i))return {ok:false,detail:"picture: truncated raster container"};let s=Tf(a,i);if(!s||s.pixelWidth*s.pixelHeight>4e7)return {ok:false,detail:"picture: invalid or oversized raster dimensions"};let l=s.pixelWidth*72/(s.dpiX??96),d=s.pixelHeight*72/(s.dpiY??96),m=fg(l),c=fg(d);if(m===null||c===null)return {ok:false,detail:"picture: invalid physical dimensions"};let h=cg(e,t,{bytes:a,mime:i});if(!h.ok)return {ok:false,detail:`picture: ${h.reason}`};let f=gg({docPrId:h.docPrId,lockAspectRatio:true,relationshipId:h.relationshipId,extentEmu:{cx:m,cy:c}});return {ok:true,docPrId:h.docPrId,ops:[{op:"insertDrawing",paragraphId:n,offset:o,drawing:f}],packageEdits:[y=>{let x=cg(y,t,{bytes:a,mime:i});if(!x.ok||x.relationshipId!==h.relationshipId||x.docPrId!==h.docPrId||x.partName!==h.partName)throw new Kk("picture allocation changed during the batch");return x.pkg}]}}function Pl(e,t){return Ye(e).find(n=>n.drawingNodeId===t&&n.kind==="inline"&&n.picture!==null)??null}function Il(e){return {width:e.extentEmu.cx/eg,height:e.extentEmu.cy/eg,lockAspectRatio:e.locks.changeAspect,altTextDescription:e.description}}function Sl(e,t){let n=new Set(Ye(e).filter(r=>r.kind==="inline"&&r.picture!==null).map(r=>r.drawingNodeId)),o=[];for(let r of t){let a=eb(e,r.paragraphId);if(!(!a||a.kind!=="paragraph"))for(let i of Bi(a))i.start>=r.start&&i.end<=r.end&&n.has(i.node.id)&&o.push(i.node.id);}return o}function wl(e,t){let n=[],o=e.drawingNodeId;if(t.lockAspectRatio!==void 0&&typeof t.lockAspectRatio!="boolean")return {ok:false,detail:"lockAspectRatio: not a boolean"};let r=t.lockAspectRatio??e.locks.changeAspect;if(t.lockAspectRatio===false&&n.push({op:"setDrawingLocks",drawingNodeId:o,locks:{changeAspect:false}}),t.width!==void 0||t.height!==void 0){let a=t.width??e.extentEmu.cx/eg,i=t.height??e.extentEmu.cy/eg;if(r){let d=e.extentEmu.cx/e.extentEmu.cy;if(t.width!==void 0&&t.height!==void 0&&Math.abs(a/i-d)>1e-6)return {ok:false,detail:"picture: width and height disagree with the locked aspect ratio"};t.width!==void 0&&t.height===void 0&&(i=a/d),t.height!==void 0&&t.width===void 0&&(a=i*d);}let s=fg(a),l=fg(i);if(s===null||l===null)return {ok:false,detail:"picture: dimensions must be finite positive points"};n.push({op:"resizeDrawing",drawingNodeId:o,extentEmu:{cx:s,cy:l}});}if(t.lockAspectRatio===true&&n.push({op:"setDrawingLocks",drawingNodeId:o,locks:{changeAspect:true}}),t.altTextDescription!==void 0){if(typeof t.altTextDescription!="string"||t.altTextDescription.length>32767||!X(t.altTextDescription))return {ok:false,detail:"altTextDescription: invalid XML text or length"};n.push({op:"setDrawingMetadata",drawingNodeId:o,title:e.title,description:t.altTextDescription});}return n.length?{ok:true,ops:n}:{ok:false,detail:"picture: no properties requested"}}function kp(e,t){if(t==="image/jpeg")return e.length>=4&&e[e.length-2]===255&&e[e.length-1]===217;let n=new DataView(e.buffer,e.byteOffset,e.byteLength),o=8,r=false;for(;o+12<=e.length;){let a=n.getUint32(o);if(a>e.length-o-12)return false;let i=String.fromCharCode(e[o+4],e[o+5],e[o+6],e[o+7]);if(i==="IDAT"&&a>0&&(r=true),o+=a+12,i==="IEND")return r&&a===0&&o===e.length}return false}var Cl=128*1024*1024,xp=Math.ceil(Cl/3)*4;function Tl(e,t){let n=(l,d)=>({ok:false,error:{code:"unsupported-capability",message:l,detail:d}});if(!t.engine)return n("Document compare needs the review module.","review-module-required");if(t.collaborative)return n("Document compare is not available in a collaboration session.","edit.operation-unsupported");let o=t.reads.package;if(!o)return {ok:false,error:{code:"document-unavailable",message:"document unavailable"}};if(typeof e.base64=="string"&&e.base64.length>xp)return n("base64File is larger than the compare size limit.","edit.resource-limit");let r=Sr(e.base64,Cl);if(!r)return {ok:false,error:{code:"unsupported-content",message:"base64File is not valid base64.",detail:"edit.invalid-argument"}};let a=t.engine(o,r,{...e.authorName===void 0?{}:{authorName:e.authorName},...e.detectFormatChanges===void 0?{}:{detectFormatChanges:e.detectFormatChanges},...e.removeDateAndTime===void 0?{}:{removeDateAndTime:e.removeDateAndTime}});if(!a.ok)switch(a.code){case "invalidRevised":case "invalidOptions":return {ok:false,error:{code:"unsupported-content",message:a.message,detail:"edit.invalid-argument"}};case "tooLarge":return n(a.message,"edit.resource-limit");case "protected":return {ok:false,error:{code:"unsupported-revision",message:a.message,detail:"edit.protected-content"}};default:return {ok:false,error:{code:"unsupported-revision",message:a.message,detail:"edit.unsupported-content"}}}let i=t.pin();if(i)return i;let s=a.package;return {ok:true,kind:"command",story:ve,ops:[],packageEdits:[()=>s],answer:()=>({kind:"applied"})}}var wr="http://schemas.openxmlformats.org/package/2006/relationships",Nl="http://schemas.openxmlformats.org/officeDocument/2006/relationships",bp=[{type:"application/vnd.openxmlformats-package.core-properties+xml",namespace:"http://schemas.openxmlformats.org/package/2006/metadata/core-properties",root:"coreProperties",relationship:`${wr}/metadata/core-properties`},{type:"application/vnd.openxmlformats-officedocument.extended-properties+xml",namespace:"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties",root:"Properties",relationship:`${Nl}/extended-properties`},{type:"application/vnd.openxmlformats-officedocument.custom-properties+xml",namespace:"http://schemas.openxmlformats.org/officeDocument/2006/custom-properties",root:"Properties",relationship:`${Nl}/custom-properties`}];function Cr(e){let t=new Map;for(let o of bp){let r=[...new Set([...e.parts.keys(),...e.partBytes.keys()])].filter(l=>ug(e,l)===o.type);if(r.length>1)return null;let a=(e.relationships.get("/")??[]).filter(l=>l.type===o.relationship);if(a.length>1)return null;let i=a[0];if(i){if(i.targetMode!=="Internal")return null;let l=E("/",i.rawTarget);if(!l.ok||r.length!==1||C(l.partName)!==C(r[0]))return null}if(r.length===0)continue;let s=e.parts.get(r[0]);if(!s||s.root.namespaceUri!==o.namespace||s.root.localName!==o.root||(e.relationships.get(s.name)?.length??0)>0||e.parts.has(vg(s.name))||e.partBytes.has(vg(s.name)))return null;t.set(C(s.name),{part:s,relationship:o.relationship});}if(t.size===0)return e;if(!df$1(e,new Set(t.keys())))return null;for(let[o,r]of e.relationships)for(let a of r){if(a.targetMode==="External")continue;let i=E(o,a.rawTarget),s=i.ok&&t.get(C(i.partName));if(!s)continue;if(o!=="/"||a.type!==s.relationship)return null;let l=e.parts.get(vg(o));if(!l||l.root.namespaceUri!==wr||l.root.localName!=="Relationships")return null;let d=l.root.children.filter(c=>c.kind!=="textValue"&&c.attributes.some(h=>h.namespaceUri===""&&h.localName==="Id"&&h.value===a.id));if(d.length!==1)return null;let m=d[0];if(m.kind==="textValue"||m.namespaceUri!==wr||m.localName!=="Relationship"||m.attributes.some(c=>c.namespaceUri!==""||!["Id","Type","Target","TargetMode"].includes(c.localName))||m.children.some(c=>c.kind!=="textValue"||!cf$1(c.value)))return null}let n=e;for(let{part:o}of t.values()){let r=yg(n,o.name);if(!r.ok||r.pkg.contentTypes.overrides.has(C(o.name)))return null;n=r.pkg;}return n}function El(e,t,n,o=true){let r=s=>({ok:false,error:{code:"unsupported-content",message:s}});if(!t.package)return r("document unavailable");if(e.op==="getDocumentProperty")return na$1.includes(e.name)?{ok:true,kind:"query",value:{kind:"text",text:pa$1(t.package,e.name)}}:r("unsupported document property");if(e.op==="removeDocumentInformation"){if(e.removeDocInfoType!=="DocumentProperties"||!o)return {ok:false,error:{code:"unsupported-capability",message:"Only direct DocumentProperties removal outside collaboration is supported."}};if(!Cr(t.package))return {ok:false,error:{code:"unsupported-capability",message:"Document property parts have unsupported structure or dependencies."}};let s=n();return s||{ok:true,kind:"command",story:ve,ops:[],packageEdits:[l=>{let d=Cr(l);if(!d)throw new Kk("document property parts changed");return d}],answer:()=>({kind:"applied"})}}if(!qa(e.values))return r("invalid document property values");if(!o&&!oa$2(t.package))return {ok:false,error:{code:"unsupported-capability",message:"Create document properties before joining collaboration; concurrent core-part creation cannot merge safely."}};let a={...e.values};if(!ra$1(t.package,a))return {ok:false,error:{code:"unsupported-capability",message:"the core properties part cannot be updated safely"}};let i=n();return i||{ok:true,kind:"command",story:ve,ops:[],packageEdits:[s=>{let l=ra$1(s,a);if(!l)throw new Kk("document properties package changed");return l}],answer:()=>({kind:"applied"})}}function b(e,t,n){return {ok:false,error:Object.freeze(n===void 0?{code:e,message:t}:{code:e,message:t,detail:n})}}function _(e){return {ok:true,kind:"query",value:e}}function Ml(e,t){if(!t.package)return b("document-unavailable","this host holds no document right now");let{name:n,id:o,count:r}=e,a=[n,o,r].filter(d=>d!==void 0).length,i=d=>b("unsupported-content",d);if(a>1)return i("give at most one of name, id, and count");if(n!==void 0&&typeof n!="string")return i("a style name is a string");if(o!==void 0&&typeof o!="string")return i("a style id is a string");if(r!==void 0&&r!==true)return i("count is true or omitted");let s=Rp(t.package);if(r)return _({kind:"number",value:s.length});if(n===void 0&&o===void 0)return _({kind:"styles",styles:s});let l=o!==void 0?Fl(s).byId.get(o):n.length>Jt?void 0:Op(s,n);return _({kind:"styles",styles:l?[l]:[]})}var vp=new Set(["paragraph","character","table","numbering"]),Ap=Object.freeze([]),Dl=new WeakMap,Ll=new WeakMap;function Fl(e){let t=Ll.get(e);if(t)return t;let n=new Map,o=new Map;for(let a of e){o.set(a.id,a);let i=vo(a.name),s=n.get(i);(!s||s.type!=="paragraph"&&a.type==="paragraph")&&n.set(i,a);}let r={byKey:n,byId:o};return Ll.set(e,r),r}function Op(e,t){return Fl(e).byKey.get(vo(t))}function Rp(e){let t=ud$1(e);if(!t)return Ap;let n=Dl.get(t.root);if(n)return n;let o=Pp(t);return Dl.set(t.root,o),o}function Pp(e){let t=Et(e),n=[],o=new Map;for(let a of t.entries){if(!vp.has(a.type))continue;let i=t.nameOf(a.type,a.styleId);i!==null&&(n.push(a),o.set(a.styleId,{name:i,type:a.type}));}let r=(a,i)=>{let s=a==null?void 0:o.get(a);return s&&s.type===i?s.name:null};return Object.freeze(n.map(a=>{let i=a.element,s=o.get(a.styleId).name,l=h=>ud$2(i,h),d=l("link"),m=d?td$1(d,"val"):void 0,c=Ip.get(a.type);return Object.freeze({id:a.styleId,name:s,type:a.type,builtIn:!Sp(td$1(i,"customStyle")),basedOn:r(a.basedOn,a.type),next:a.type!=="paragraph"?null:l("next")===void 0?s:r(a.next,"paragraph"),linked:c!==void 0&&m!==a.styleId&&r(m,c)!==null,hidden:To(l("semiHidden"))||To(l("hidden")),uiPriority:wp(l("uiPriority")),quickStyle:To(l("qFormat")),unhideWhenUsed:To(l("unhideWhenUsed"))})}))}var Ip=new Map([["paragraph","character"],["character","paragraph"]]),Bl=new Set(["1","true","on"]);function Sp(e){return e!==void 0&&Bl.has(e)}function To(e){if(!e)return false;let t=td$1(e,"val");return t===void 0||Bl.has(t)}function wp(e){let t=e?td$1(e,"val"):void 0;return t!==void 0&&/^-?\d{1,9}$/.test(t)?Number(t):null}function Hl(e,t){let{reads:n,handles:o}=t;switch(e.op){case "getStyles":return Ml(e,n);case "getSections":return o.resolve(e.document,"document")?_({kind:"handles",handles:n.sections().map(r=>o.section(r.index))}):b("invalid-handle","that handle does not name a document","document");case "getPageSetup":{let r=o.resolve(e.section,"section");if(!r||r.kind!=="section")return b("invalid-handle","that handle does not name a section","section");let a=n.sections()[r.index];return a?_({kind:"pageSetup",setup:a.pageSetup}):b("invalid-handle","that section is not in this document")}default:return El(e,n,t.pin,t.supportsPartCreation)}}function _l(e,t){let n=[],o=new Set,r=a=>{if(a.kind!=="textValue"){if(a.namespaceUri===pa&&a.localName===`${t}Reference`){let i=Rc$1(a)??Number.NaN;o.has(i)||(n.push(i),o.add(i));}for(let i of a.children)r(i);}};return r(e),n}var jl={},Vl=new WeakMap;function Kl(e,t){let n=e??jl,o=Vl.get(n);o||Vl.set(n,o=new WeakMap);let r=t??jl,a=o.get(r);return a||o.set(r,a=Cp(e,t)),a}function Ul(e,t=null,n="all-markup",o){let r=Kl(e,t);return (a,i,s,l,d=n,m=o)=>{let c=r(a,i,s,l,d,m);return c.rtl||c.cs}}function Iy(e,t=null,n="all-markup",o){let r=Kl(e,t);return (a,i,s,l,d=n,m=o)=>r(a,i,s,l,d,m).rtl}function Cp(e,t){let n=lf$1(e,void 0,t),o=bo(n),r=new WeakMap;return (a,i,s,l,d="all-markup",m)=>{let c=o(l,a,d,m),h=r.get(a);if(!h||h.cellStyle!==c){let P=mf$1(n,ai(a,"paragraphProperties","pPr"),c);h={cellStyle:c,inherited:P},r.set(a,h);}let{inherited:f}=h,y=s?f.markRunProperties:pf$1(f.runProperties,zb(i),n),x=false,v=false;for(let P of y){if(P.localName!=="rtl"&&P.localName!=="cs")continue;let A=P.attributes?.val,N=A===void 0||["1","true","on"].includes(A);P.localName==="rtl"?x=N:v=N;}return {rtl:x,cs:v}}}function Wl(e,t=()=>null,n=()=>"all-markup",o=()=>{}){return {runPropertyEdits(...r){return qi(r[0],r[1],r[2],r[3],r[4],r[5],r[6],Ul(e(),t(),n(),o()))},mergedParagraphMarkProperties(...r){return ki(r[0],r[1],r[2],Ul(e(),t(),n(),o()))}}}var gt=xj,ht=/[\r\n\f\u2028\u2029]/;function tn(e,t,n){return n.length?[{op:"insertText",paragraphId:e,offset:t,text:n}]:[]}function Tr(e){return e.replaceAll(gt,`
|
|
5
|
+
`)}var Tp={ok:false,error:{code:"unsupported-content",message:"a single-line control cannot hold a line break",detail:"line-break-in-single-line-control"}};function Np(e,t){return t.includes(gt)&&!yj(qc$1(e))?Tp:null}function It(e,t,n,o,r=gt){if(!r.includes(gt))return null;let a=eb(e,t);if(!Ai(a))return null;let i=Am$1(e,a,n,o);return i?Np(i,r):null}function No(e){return e.replaceAll(`
|
|
6
|
+
`,gt)}function $l(e,t){let n=e.rawText(t)??"",o=e.node(t);return o?.kind==="paragraph"?Mm$1(o,n):n}function Ep(e){return e?.kind!=="paragraph"?false:e.children.every(t=>t.namespaceUri!==pa?false:t.localName==="pPr"?true:t.kind==="run"&&t.children.every(n=>n.namespaceUri===pa&&(n.localName==="rPr"||n.localName==="t"&&n.children.every(o=>o.kind==="textValue"))))}function Nr(e,t,n){return Ep(eb(e,t))&&ym$1(e,t,n)===null}function zl(e,t,n,o){let r=ym$1(e,t,n);if(!r)return null;let a=n===r.offset?Hn(e,{op:"insertText",paragraphId:t,offset:n,text:o}):null;return a?.ok&&Jm$1(a.part,t)?.slice(n,n+o.length)===Tr(o)?null:{ok:false,error:{code:"unsupported-capability",message:"insert at the placeholder start or replace the complete prompt",detail:"placeholder-insertion-offset"}}}function Dp(e,t,n){return e.start===e.end?t<e.start&&e.start<n:t===n?e.start<t&&t<e.end:Math.max(e.start,t)<Math.min(e.end,n)}var Eo=class{#e=new Map;has(t){return this.#e.has(t)}append(t,n,o,r,a=false){let i=this.#e.get(t)??[];if(i.some(c=>Dp(c,n,o)))return null;let s=n,l=o;for(let c of i){let h=c.length-(c.end-c.start);c.end<=n&&!(a&&c.start===n&&c.end===n)&&(s+=h),(c.end<o||c.end===o&&c.start!==c.end)&&(l+=h);}n===o&&(l=s);let d=r-(o-n);for(let c of i)o<=c.start&&!(n===o&&c.start===c.end&&n===c.start&&!a)&&(c.result.start+=d,c.result.end+=d);let m={start:s,end:s+r};return i.push({start:n,end:o,length:r,result:m}),this.#e.set(t,i),{start:s,end:l,result:m}}};function Gl(e,t,n,o,r=false){let a=t.start.paragraphId,i=e.append(a,t.start.offset,t.end.offset,n.length,r);return i?{ok:true,kind:"command",ops:Xl(a,i.start,i.end,n),story:t.start.story,answer:()=>({kind:"span",span:Ae({start:{...t.start,offset:i.result.start},end:{...t.start,offset:i.result.end}},o)})}:{ok:false,error:{code:"conflicting-operations",message:"text edits overlap in the batch snapshot",detail:a}}}function Xl(e,t,n,o){let r=[];return o.length&&r.push({op:"insertText",paragraphId:e,offset:t,text:o,...n>t?{bias:"right"}:{}}),n>t&&r.push({op:"deleteText",paragraphId:e,start:t+o.length,end:n+o.length}),r}function Yl(e,t,n,o){let r=t.start.paragraphId,a=Jm$1(e,r),i=ym$1(e,r,t.start.offset),s=i&&n.length?[{op:"insertText",paragraphId:r,offset:t.start.offset,text:n,bias:"right"}]:Xl(r,t.start.offset,t.end.offset,n),l=e;for(let m of s){let c=Hn(l,m);if(!c.ok)return {ok:false,error:{code:"unsupported-content",message:"that replacement cannot preserve the targeted text safely",detail:c.reason}};l=c.part;}let d=Jm$1(l,r);return a===null||d!==a.slice(0,t.start.offset)+Tr(n)+a.slice(t.end.offset)?{ok:false,error:{code:i?"unsupported-capability":"unsupported-content",message:i?"replace the complete placeholder prompt to avoid consuming unrelated text":"that replacement changes the expected text positions",detail:r}}:{ok:true,kind:"command",ops:s,story:t.start.story,answer:()=>({kind:"span",span:Ae({start:t.start,end:{...t.start,offset:t.start.offset+n.length}},o)})}}function Jl(e,t,n){let o=$l(e,t);return {text:o,occurrences:Lp(o,n)}}var ql=/\s/;function Lp(e,t){let n=[],o=0;for(;o<e.length;){let r=null;for(let a of t){let i=No(a),s=e.indexOf(i,o);s<0||(!r||s<r.start||s===r.start&&i.length>r.length)&&(r={start:s,length:i.length});}if(!r)break;n.push(r),o=r.start+r.length;}return n}function Ql(e,t,n){let o=t[n]?.markParagraphId??null;if(o!==null)return o;let r=e.paragraphIds,a=r[r.length-1];return a===void 0||new Set(t.map(s=>s.markParagraphId).filter(s=>s!==null)).has(a)?null:a}function Zl(e,t){for(let n of [e.start,e.end]){let o=t.rawText(n.paragraphId);if(o===null||n.offset>o.length)return false}return true}function ed(e,t,n){let o=t,r=n;for(;o<r&&ql.test(e[o]);)o+=1;for(;r>o&&ql.test(e[r-1]);)r-=1;return [o,r]}function nn(e){let t=e.kind==="contentControl"?oc(e):e;return t?sc(t).map(n=>n.node):[]}var td=new Set(["unlocked","sdtLocked","contentLocked","sdtContentLocked"]),nd=new Set(["whole","content","start","end","before","after"]),od=new Set(["richText","plainText","dropDownList","comboBox","date"]),Mp=4096;function rd(e,t,n){let{type:o}=e;return ["richText","plainText","comboBox","untyped"].includes(o)?typeof t!="string"?{code:"unsupported-content",message:"text is required",detail:"text"}:t.includes(xj)&&!yj(e)?{code:"unsupported-content",message:"a single-line control cannot hold a line break",detail:"line-break-in-single-line-control"}:n!=="replace"&&n!=="start"&&n!=="end"?{code:"unsupported-content",message:"that is not a place to insert at",detail:String(n)}:null:{code:"unsupported-capability",message:"this control requires a typed value rather than a text insertion",detail:o}}function ad(e){let t=(r,a)=>({ok:false,code:"unsupported-content",message:r,detail:a});if(typeof e!="object"||e===null||!("kind"in e))return t("a control value states its kind","value");let n=e,o=n.kind;if(o==="text"||o==="listItem"){let r=o==="text"?n.text:n.value;return typeof r!="string"?t("that value is not a string",String(o)):r.length>Mp?t("that value is too long",String(r.length)):{ok:true,value:o==="text"?{kind:"text",text:r}:{kind:"listItem",value:r}}}if(o==="checkbox"){let r=n.checked;return typeof r!="boolean"?t("a checkbox is checked or not","checked"):{ok:true,value:{kind:"checkbox",checked:r}}}if(o==="date"){let r=n.iso;return typeof r!="string"?t("a date is an ISO-8601 string","iso"):r.length>64?t("that is not a date",String(r.length)):{ok:true,value:{kind:"date",iso:r}}}return t("that is not a value any control accepts",String(o))}function id(e,t,n){let o=e.indexOf(n),r=[];return t.ranges.forEach((a,i)=>{let s=e.indexOf(a.start.paragraphId),l=e.indexOf(a.end.paragraphId);if(s<0||l<0||o<s||o>l)return;let d=t.revisionKind==="delete"||t.revisionKind==="moveFrom"||t.revisionKind==="replace"&&i<(t.replacedRangeCount??1/0);r.push({start:o===s?a.start.offset:0,end:o===l?a.end.offset:1/0,struck:d});}),r}function Fp(e,t,n,o,r){let a=t.flatMap(s=>id(e,s,n).filter(l=>l.struck)).sort((s,l)=>s.start-l.start),i=o;for(let s of a){if(s.start>i)break;if(i=Math.max(i,s.end),i>=r)return false}return i<r}function sd(e,t,n,o,r,a,i={}){let s=id(e,n,o);return n.revisionKind==="insert"||!s.some(d=>d.struck&&r<=d.end&&a>=d.start)||r===a||i.strikesMark||Fp(e,t,o,r,a)?null:"deleted-text-only"}function Er(e,t,n,o,r){let a=eb(e.part,t);if(!a||a.kind!=="paragraph")return o;let{past:i,landing:s}=Ej(a,n??{start:o,end:o},o,r.author,r.date);return n&&n.end>n.start?s:i}function Do(e,t,n,o){let r=eb(e.part,t);if(!r||r.kind!=="paragraph")return false;let a=Ei(r),i=false,s=r.children;for(let l=0;l<64;l++){let d=s.find(c=>{if(c.kind==="textValue"||c.kind==="run")return false;let h=a.spanOf(c);return h!==null&&h.start<n&&n<h.end});if(!d||d.kind==="textValue"||!(Ca$1(d)&&d.kind!=="revisionDelete"&&d.kind!=="revisionMoveFrom"||d.kind==="contentControl"||d.kind==="contentControlContent"))return false;if(i&&d.kind!=="contentControlContent")return true;d.kind==="revisionInsert"&&(Bj([d])??o)!==o&&(i=true),s=d.children;}return false}function Sn(e,t,n){return {code:e,message:t,detail:n}}function ld(e,t=false){if(typeof e.author!="string"||!e.author.trim()||!X(e.author))return Sn("unsupported-content","proposals need a non-empty XML-safe author","author");let n=e.op==="proposeInsertion";return !(e.op==="proposeDeletion")&&(typeof e.text!="string"||!t&&!e.text.length||ht.test(e.text)||!zj(e.text))?Sn("unsupported-content","proposals need non-empty inline XML-safe text","text"):n&&e.where!=="Before"&&e.where!=="After"?Sn("unsupported-content","insertion needs Before or After","where"):null}function St(e,t,n,o,r,a=false,i,s){let l=cm$1(e.part),d=new Set;if(l.some(f=>f.revisionKind==="structural"))for(let f=fb(e.part,t);f!==null&&(d.add(f.id),f.id!==e.root.id);f=fb(e.part,f.id));let m=null,c=l.find(f=>{if(r&&f.author===r&&(["insert","paragraphMark","format"].includes(f.revisionKind)||a&&["delete","replace"].includes(f.revisionKind)))return false;if(s!==void 0&&f.author!==s.author&&["insert","delete","replace"].includes(f.revisionKind))return m=sd(e,l,f,t,n,o,s),m!==null;if(f.revisionKind==="structural"){let x=ll$1(f),v=0;for(let P of x){let A=fb(e.part,P),N=A&&fb(e.part,A.id),S=N?.kind==="tableRow"?"trPr":N?.kind==="tableCell"?"tcPr":null;if(!(!N||!S||Sh(N,S)?.id!==A?.id)){if(d.has(N.id))return true;v+=1;}}if(x.length>0&&v===x.length)return false}let y=i!==void 0&&f.author===i;return f.ranges.some(x=>{let v=e.indexOf(x.start.paragraphId),P=e.indexOf(x.end.paragraphId),A=e.indexOf(t);if(v<0||P<0||A<v||A>P)return false;let N=A===v?x.start.offset:0,S=A===P?x.end.offset:1/0;return n<S&&o>N?true:n>S||o<N?false:!y||n!==S?true:!(f.revisionKind==="insert"||f.revisionKind==="replace"||f.revisionKind==="paragraphMark"&&f.markDirection==="insert")})});if(!c)return null;if(!s)return Sn("unsupported-revision","proposal touches or overlaps a pending revision","span");let h=m??(c.author===s.author?"own-pending":c.revisionKind==="format"?"foreign-formatting":"foreign-revision");return Sn("unsupported-revision",Bp[h],Hp[h])}var Bp={"deleted-text-only":"a tracked deletion or replacement needs live text, not only deleted text","foreign-revision":"the edit touches another author's pending paragraph mark, formatting, move, or structure","foreign-formatting":"the edit touches another author's pending formatting change; if it leaves the formatting unchanged it has no card, and Accept All or Reject All over the story clears it","own-pending":"the edit would merge with or cover the author's own pending change"},Hp={"deleted-text-only":"edit.tracked-deleted-text-only","foreign-revision":"edit.tracked-foreign-revision-unsupported","foreign-formatting":"edit.tracked-foreign-revision-unsupported","own-pending":"edit.tracked-own-pending-change"};function dd(e,t,n,o,r,a){let i=!!o,s=(y,x,v)=>({ok:false,error:{code:y,message:x,...v?{detail:v}:{}}});if(i&&r===false)return s("unsupported-capability","tracked content-control creation is unsupported in collaboration");let l=W(e.span,t,n);if(!l.ok)return s(l.code,"that span is not a place",l.detail);if(!l.value)return s("invalid-offset","that story holds nothing to wrap","empty-story");let d=ee(e.span,t,n),m=d.ok?d.value:null;if(!m)return s("invalid-handle","that story is not in this document");let c=l.value;if(c.start.paragraphId!==c.end.paragraphId)return s("unsupported-content","wrapping several paragraphs in one control is not supported here","multi-paragraph");if(!od.has(e.subtype))return s("unsupported-content","that control type cannot be inserted",e.subtype);if(i){if(!zm$1(m.part,c.start.paragraphId,c.start.offset,c.end.offset))return s("unsupported-capability","tracked controls require a nonempty ordinary text range without existing review markup");let y=St(m,c.start.paragraphId,c.start.offset,c.end.offset);if(y)return {ok:false,error:y}}let h=new Set(nn(m.root).map(y=>y.id)),f=a(m,c.start.paragraphId);return f||{ok:true,kind:"command",story:m.story,ops:[{op:"insertContentControl",paragraphId:c.start.paragraphId,start:c.start.offset,end:c.end.offset,type:e.subtype,...i?{revision:{author:o,date:re()}}:{},...e.tag===void 0?{}:{tag:e.tag},...e.title===void 0?{}:{alias:e.title}}],answer:y=>{if(!e.returnHandle)return {kind:"applied"};let v=y.story(m.story)?.node(c.start.paragraphId),P=v?nn(v).filter(A=>!h.has(A.id)):[];if(P.length!==1)throw new Error("content control insertion did not create a control");return {kind:"handle",handle:t.contentControl(P[0].id,m.story)}}}}function ud(e,t,n,o){let r=_p(e,t);if(!r)return null;let a=Mh(r),i=n===$k(a.checkedGlyph)?true:n===$k(a.uncheckedGlyph)?false:null;return i===null?b("unsupported-capability","a checkbox shows only its state glyphs; change its checked state instead","checkbox-glyph"):{ok:true,kind:"command",story:t.start.story,ops:[{op:"setContentControlValue",controlId:r.id,value:{kind:"checkbox",checked:i}}],answer:o}}function _p(e,t){let{start:n,end:o}=t;if(n.paragraphId!==o.paragraphId||o.offset<=n.offset)return null;let r=e.node(n.paragraphId);if(r?.kind!=="paragraph")return null;let a=Ei(r);for(let{node:i}of sc(r)){let s=a.spanOf(i);if(s?.start===n.offset&&s.end===o.offset&&Mh(i))return i}if(n.offset!==0||o.offset!==(e.rawText(n.paragraphId)??"").length)return null;for(let{node:i}of sc(e.root)){let s=Zt(i);if(s.length===1&&s[0]===n.paragraphId&&Mh(i))return i}return null}function cd(e,t,n){let o=eb(e,t);if(!o||o.kind!=="contentControl")return false;let r=i=>i.kind==="textValue"||!i.kind.startsWith("revision")&&!i.localName.endsWith("Change")&&i.children.every(r);if(!r(o))return false;let a=fb(e,t);return a?.kind==="revisionInsert"&&a.attributes.some(i=>i.namespaceUri===pa&&i.localName==="author"&&i.value===n)}function pd(e){if(e.length>128)return null;let t=e.trim(),n=new Set,o=[];for(;t;){let r=/^\\([ohzu])(?:\s+"([1-9])-([1-9])")?(?=\s|$)/.exec(t);if(!r)return null;let[,a,i,s]=r;if(n.has(a)||(a==="o"?!i||Number(i)>Number(s):i))return null;n.add(a),o.push(r[0]),t=t.slice(r[0].length).trimStart();}return ["TOC",...o].join(" ")}var md=new WeakMap;function on(e,t){let n=eb(e,t);if(!n||n.kind!=="paragraph")return [];let o=md.get(n);if(o)return o;let r=jp(e,n,t);return md.set(n,r),r}function jp(e,t,n){let o=Bi(t);return An$1(t,false,true).flatMap(r=>{let a=o.find(s=>s.node.id===r.fieldNodeId),i=eb(e,r.fieldNodeId);return a?[{paragraphId:n,fieldNodeId:r.fieldNodeId,code:r.instruction,start:a.start,end:a.end,rewritable:r.rewritable,locked:!!i&&gh(i,"fldLock")===true}]:[]})}function fd(e){let t=W$2(e),n=Pa(`<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:fldSimple w:instr="${t}"><w:r><w:t/></w:r></w:fldSimple></w:p></w:body></w:document>`,{name:"/word/document.xml",contentType:"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"});if(!n.ok)throw new Error("could not build a field");let o=n.part.root.children.find(a=>a.kind==="body"),r=o&&id$1(o)[0];if(!r||r.kind!=="paragraph")throw new Error("could not build a field paragraph");return r}var Vp=64,gd=new WeakMap;function Dr(e,t){if(e.kind==="textValue")return -1;let n=gd.get(e);if(!n){let o=new Map;e.children.forEach((r,a)=>{o.has(r.id)||o.set(r.id,a);}),n=o,gd.set(e,n);}return n.get(t)??-1}var Up=new Set(["drawing","pict","object","AlternateContent","txbxContent"]),Lo=(e,t)=>({code:"unsupported-capability",message:e,detail:t});function hd(e,t){let n=eb(e,t);if(!n||n.kind!=="paragraph")return null;if(Sh(Qh(n),"sectPr"))return Lo("a tracked deletion cannot remove a section break","section-mark");let o=false,r=0,a=false,i=false,s=(l,d)=>{if(!(l.kind==="textValue"||i)){if(d>Vp){i=true;return}if(!(na$2(l.kind)||Up.has(l.localName))){if(l.kind==="contentControl"&&(o=true),l.kind==="fldChar"){let m=Yg(l);m==="begin"?r+=1:m==="end"&&(r===0?a=true:r-=1);}for(let m of l.children)s(m,d+1);}}};for(let l of n.children)s(l,0);return i?Lo("the paragraph nests content too deeply to check","depth"):o?Lo("a tracked paragraph deletion cannot remove an inline content control","control"):a||r>0?Lo("a field crosses this paragraph mark","cross-paragraph-field"):null}function yd(e,t){let n=fb(e,t);if(!n)return null;let o=Dr(n,t);if(o<0)return null;for(let r=o+1;r<n.children.length;r+=1){let a=n.children[r];if(a.kind==="paragraph")return a;if(!zl$1(a))return null}return null}function kd(e,t){if(t.length<2)return true;let n=fb(e,t[0]);if(!n)return false;let o=n.children,r=Dr(n,t[0]);if(r<0)return false;for(let a=1;a<t.length;a+=1){let i=r+1;for(;i<o.length&&o[i].kind!=="paragraph"&&zl$1(o[i]);)i+=1;if(o[i]?.id!==t[a])return false;r=i;}return true}function xd(e,t,n){let o=fb(e,t);if(!o)return false;let r=Dr(o,t);for(let a=r-1;a>=0;a-=1){let i=o.children[a];if(i.kind==="paragraph")return Fn$1(i,"del")?.author===n;if(!zl$1(i))return false}return false}function bd(e,t,n,o){if(e.op==="insertText")return {op:"proposeInsertion",span:{start:e.at,end:e.at},text:e.text,where:"Before",author:t};if(e.op==="replaceSpan")return {op:"proposeReplacement",span:e.span,text:e.text,author:t};if(e.op!=="deleteParagraph")return e;let r=he(e.paragraph,n,o);if(!r.ok)return {ok:false,error:{code:r.code,message:"that handle does not name a paragraph",detail:r.detail}};let{story:a,paragraphId:i,index:s}=r.value,l=o.story(a),d=l?.paragraphIds[s+1];return !l||d===void 0||yd(l.part,i)?.id!==d?{ok:false,error:{code:"unsupported-capability",message:"a tracked paragraph deletion needs a next paragraph in the same container",detail:"paragraph"}}:{op:"proposeDeletion",span:{start:{paragraph:e.paragraph,offset:0},end:{paragraph:n.paragraph(d,a),offset:0}},author:t}}function Mo(e,t,n){return xd(e,t,n.trim())?{ok:false,error:{code:"unsupported-revision",message:"a deletion beside the author's pending deletion would review as one decision",detail:"span"}}:null}function vd(e,t,n,o,r,a=true,i=false){let s=(K,G,Q)=>({ok:false,error:{code:K,message:G,...Q===void 0?{}:{detail:Q}}}),l=K=>Ae(K,n),d=K=>({ok:true,kind:"query",value:K}),m=ld(e,t);if(m)return {ok:false,error:m};let c=e.op==="proposeInsertion",h=e.op==="proposeDeletion",f=W(e.span,n,o);if(!f.ok)return s(f.code,"that span is not a place",f.detail);let y=f.value;if(y&&t&&!c&&y.start.paragraphId!==y.end.paragraphId){if(!a&&!h&&e.text!=="")return s("unsupported-capability","tracked paragraph-range replacement is unsupported in collaboration","span");let K=ee(e.span,n,o);if(!K.ok)return s(K.code,"that story is not a place",K.detail);let G=K.value,Q=G.indexOf(y.start.paragraphId),ae=G.indexOf(y.end.paragraphId),X=G.paragraphIds.slice(Q,ae+1);if(!kd(G.part,X))return s("unsupported-content","tracked ranges require adjacent sibling paragraphs","span");if(y.start.offset===0){let V=Mo(G.part,X[0],e.author);if(V)return V}let ue={author:e.author.trim(),date:re()},fe=[],Oe=[];for(let V=0;V<X.length;V++){let $=X[V],ge=V===0?y.start.offset:0,ie=V===X.length-1?y.end.offset:(G.rawText($)??"").length,Le=St(G,$,ge,ie,void 0,false,void 0,ie>ge?{author:ue.author,strikesMark:V<X.length-1}:void 0)??(V<X.length-1?hd(G.part,$):null);if(Le)return {ok:false,error:Le};let st=ie>ge||V<X.length-1?r(G,$):null;if(st)return st;ie>ge&&fe.push({op:"deleteText",paragraphId:$,start:ge,end:ie,revision:ue}),V<X.length-1&&Oe.push({op:"setParagraphMarkRevision",paragraphId:$,kind:"del",revision:ue});}fe.push(...Oe);let we=(G.rawText(X[0])??"").length,xe=h?"":e.text,De=It(G.part,X[0],y.start.offset,we,xe);if(De)return De;xe&&fe.push({op:"insertText",paragraphId:X[0],offset:we,text:xe,revision:ue});let ze=xe?Er(G,X[0],{start:y.start.offset,end:we},we,ue):we,it={...y.start,offset:ze};return {ok:true,kind:"command",ops:fe,story:G.story,answer:()=>({kind:"span",span:l({start:it,end:{...it,offset:it.offset+xe.length}})})}}if(!y||y.start.paragraphId!==y.end.paragraphId)return s("unsupported-content","proposals require a single paragraph range","span");if(!t&&!c&&y.start.offset===y.end.offset)return s("unsupported-content","deletion and replacement need a non-empty range","span");let x=ee(e.span,n,o);if(!x.ok)return s(x.code,"that story is not a place",x.detail);let v=y.start.paragraphId,P=c&&e.where==="After"?y.end.offset:y.start.offset,A=c?P:y.end.offset;if(t&&!c&&A>P&&P===0){let K=Mo(x.value.part,v,e.author);if(K)return K}if(t&&!h&&P===A&&e.text===""&&!i)return d({kind:"span",span:l({start:y.start,end:y.start})});let N=St(x.value,v,P,A,t&&c?e.author.trim():void 0,c&&P===(x.value.rawText(v)??"").length,t&&!c&&A>P?e.author.trim():void 0,t?{author:e.author.trim()}:void 0);if(N)return {ok:false,error:N};if(!h){let K=It(x.value.part,v,P,A,e.text);if(K)return K}let S={author:e.author.trim(),date:re()},M=c?P:A,j=t&&!h&&e.text.length>0,J=j?Er(x.value,v,c?null:{start:P,end:A},M,S):M;if(j&&Do(x.value,v,J,S.author))return s("unsupported-revision","the new text would land inside a container within another author's pending insertion","edit.tracked-foreign-revision-unsupported");let C=r(x.value,v);if(C)return C;let z=[];return !c&&A>P&&z.push({op:"deleteText",paragraphId:v,start:P,end:A,revision:S}),!h&&e.text.length>0&&z.push({op:"insertText",paragraphId:v,offset:c?P:A,text:e.text,revision:S}),{ok:true,kind:"command",ops:z,story:x.value.story,answer:()=>{if(!t)return {kind:"applied"};let K={...y.start,offset:J};return {kind:"span",span:l({start:K,end:{...K,offset:K.offset+(h?0:e.text.length)}})}}}}function Ad(e,t,n){return St(e,t,0,(e.rawText(t)??"").length,n,true)}var Kp=(e,t,n)=>({ok:false,error:{code:e,message:t,...n===void 0?{}:{detail:n}}});function Wp(e,t,n,o){if(Kh(e.part,t).content||Oh(e.part,t))return true;let r=eb(e.part,t);return !r||r.kind!=="paragraph"?false:Bi(r).some(a=>(n===o?a.start<n&&a.end>n:a.start<o&&a.end>n)&&(Kh(e.part,a.node.id).content||Oh(e.part,a.node.id)))}function Fo(e,t,n,o,r,a){let i=(S,M,j)=>Kp(S,M,j),{start:s,end:l}=n;if(!["Before","After","Start","End","Replace"].includes(t))return i("unsupported-content",`unsupported ${e} insert location`,"invalidArgs");let d=t==="Replace";if(d&&s.paragraphId!==l.paragraphId)return i("unsupported-content",`${e} replacement requires one paragraph`,"invalid-range");let m=t==="After"||t==="End"?l:s,c=m.paragraphId,h=d&&l.offset>s.offset,f=h?s.offset:m.offset,y=h?l.offset:m.offset;if(Wp(o,c,f,y))return i("unsupported-content",`${e} insertion touches protected content`,"locked");let x=()=>{let S=r(o,c);return S&&!S.ok?S:null};if(a===void 0){let S=x();return S||{paragraphId:c,at:m.offset,ops:h?[{op:"deleteText",paragraphId:c,start:f,end:y}]:[]}}let v=a.trim();if(h&&f===0){let S=Mo(o.part,c,v);if(S&&!S.ok)return S}let P=St(o,c,f,y,h?void 0:v,!h&&y===(o.rawText(c)??"").length,h?v:void 0,{author:v});if(P)return {ok:false,error:P};if(Do(o,c,y,v))return i("unsupported-revision",`the ${e} would land inside a container within another author's pending insertion`,"edit.tracked-foreign-revision-unsupported");let A=x();if(A)return A;let N={author:v,date:re()};return {paragraphId:c,at:y,ops:h?[{op:"deleteText",paragraphId:c,start:f,end:y,revision:N}]:[],revision:N}}var $p={Page:"PAGE",NumPages:"NUMPAGES",Ref:"REF",PageRef:"PAGEREF",NoteRef:"NOTEREF",Seq:"SEQ",StyleRef:"STYLEREF",Date:"DATE",Time:"TIME"},wn=(e,t,n)=>({ok:false,error:{code:e,message:t,...n===void 0?{}:{detail:n}}}),Lr=e=>wn("unsupported-content",e,"field-unsupported");function zp(e){let t=e.fieldType??"Empty",n=e.text??"";if(t==="TOC")return pd(n)??Lr("the TOC switches are not supported");let o=t==="Empty"?"":$p[t];return o===void 0?Lr(`the ${t} field type is not supported`):Pk(o?`${o} ${n}`:n)??Lr("the field instruction is not one this API writes, or its arguments refuse")}function Od(e,t,n,o,r,a){if(e.removeFormatting!==void 0&&e.removeFormatting!==false)return wn("unsupported-content","removeFormatting is not supported","unsupported");if(e.text!==void 0&&typeof e.text!="string")return wn("unsupported-content","field text must be a string","invalidArgs");if(e.fieldType!==void 0&&typeof e.fieldType!="string")return wn("unsupported-content","field type must be a string","invalidArgs");if(a!==void 0&&e.fieldType==="TOC")return wn("unsupported-capability","insertField does not support TrackMineOnly for TOC fields; no permanent edit was applied","change-tracking-operation-unsupported");let s=zp(e);if(typeof s!="string")return s;let l=Fo("field",e.location,t,n,r,a);if("ok"in l)return l;let{paragraphId:d,at:m,revision:c}=l,h=new Set(on(n.part,d).map(v=>v.fieldNodeId)),y=!c&&["PAGE","NUMPAGES","TOC"].includes(s.split(" ")[0])?{op:"insertFragment",paragraphId:d,offset:m,blocks:[fd(s)],lastMarkCovered:false}:{op:"insertComplexField",paragraphId:d,offset:m,instruction:s,...c?{revision:c}:{}},x=[...l.ops,y];return {ok:true,kind:"command",story:n.story,ops:x,answer:v=>{let P=v.story(n.story)?.part,A=P?on(P,d).filter(N=>!h.has(N.fieldNodeId)):[];if(A.length!==1)throw new Error("inserted field was not committed");return {kind:"handle",handle:o.field(d,A[0].fieldNodeId,n.story)}}}}var rn=(e,t,n)=>({ok:false,error:{code:e,message:t,detail:n}});function Rd(e,t,n,o,r){if(!Bm$1(e.text))return rn("unsupported-content","a field result is plain text of at most 2048 characters, with no line or paragraph break","invalidArgs");let a=r?.trim(),i=Cm$1(t.part,n.paragraphId,n.fieldNodeId,a);if(i==="locked"||i==="bound")return rn("unsupported-content","field is protected",i);if(i==="field-result-unsupported")return rn("unsupported-capability","this field result holds content other than plain runs","unsupported");if(i==="unsupported-revision")return a===void 0?rn("unsupported-revision","this field is inside a pending revision; write its result with TrackMineOnly as its author","unsupported-revision"):rn("unsupported-capability","TrackMineOnly writes a result only for a field that is your own pending insertion; no permanent edit was applied","change-tracking-operation-unsupported");if(i)return rn("invalid-handle","that field no longer exists",i);let s=o(t,n.paragraphId);return s||{ok:true,kind:"command",story:t.story,ops:[{op:"setFieldResult",paragraphId:n.paragraphId,fieldNodeId:n.fieldNodeId,text:e.text,...a===void 0?{}:{revision:{author:a,date:re()}}}],answer:()=>({kind:"applied"})}}var Cn=(e,t,n)=>({ok:false,error:{code:e,message:t,...n===void 0?{}:{detail:n}}});function Pd(e,t,n,o,r){let a=Em$1(e.ooxml);if(!a.ok)return a.reason==="resource-limit"?Cn("unsupported-content","the OOXML is too large or too deep","resource-limit"):a.reason==="ooxml-invalid"?Cn("unsupported-content","the OOXML is not well-formed or names no namespace","invalidArgs"):Cn("unsupported-capability","insertOoxml inserts one paragraph that holds one inline equation and plain runs","ooxml-unsupported");let i=W(e.span,t,n),s=ee(e.span,t,n);if(!i.ok||!s.ok)return Cn("invalid-handle","that range no longer exists",i.ok?s.ok?void 0:s.detail:i.detail);if(!i.value)return Cn("unsupported-content","insert a paragraph before an equation");let l=s.value,d=Fo("equation",e.location,i.value,l,o,r);if("ok"in d)return d;let{paragraphId:m,at:c,revision:h}=d,{nodes:f,length:y}=a.snippet;return {ok:true,kind:"command",story:l.story,ops:[...d.ops,{op:"insertEquation",paragraphId:m,offset:c,nodes:f,length:y,...h?{revision:h}:{}}],answer:()=>({kind:"span",span:{start:{paragraph:t.paragraph(m,l.story),offset:c},end:{paragraph:t.paragraph(m,l.story),offset:c+y}}})}}var yt=(e,t="unsupported-content",n)=>({ok:false,error:{code:t,message:e,...n===void 0?{}:{detail:n}}}),Gp=new Set(["getFields","getField","setFieldCode","deleteField","updateFieldResult","getFieldResult","setFieldResult","insertField","insertOoxml"]);function Id(e){return Gp.has(e.op)}function Sd(e,t,n,o,r,a){return e.op==="insertOoxml"?Pd(e,t,n,(i,s)=>o(i,s),a):Xp(e,t,n,o,r,a)}function Xp(e,t,n,o,r,a){if(e.op==="getFields"||e.op==="insertField"){let h=W(e.span,t,n),f=ee(e.span,t,n);if(!h.ok||!f.ok)return yt("that field range no longer exists","invalid-handle",h.ok?f.ok?void 0:f.detail:h.detail);let y=f.value;return e.op==="getFields"?{ok:true,kind:"query",value:{kind:"handles",handles:mt(h.value,y).flatMap(v=>on(y.part,v.paragraphId).filter(P=>P.start>=v.start&&P.end<=v.end)).map(v=>t.field(v.paragraphId,v.fieldNodeId,y.story))}}:h.value?Od(e,h.value,y,t,(x,v)=>o(x,v),a):yt("insert a paragraph before inserting a field")}let i=t.resolve(e.field,"field");if(!i||i.kind!=="field")return yt("that is not a field handle","invalid-handle");let s=n.story(i.story),l=s&&on(s.part,i.paragraphId).find(h=>h.fieldNodeId===i.fieldNodeId);if(!s||!s.has(i.paragraphId)||!l)return yt("that field no longer exists","invalid-handle",tt);if(e.op==="getField")return {ok:true,kind:"query",value:{kind:"field",field:{code:l.code}}};if(e.op==="getFieldResult")return {ok:true,kind:"query",value:{kind:"text",text:s.projectedText(i.paragraphId,e.projection??"allMarkup")?.sliceRaw(l.start,l.end)??""}};if(l.locked||Kh(s.part,i.fieldNodeId).content||Oh(s.part,i.fieldNodeId))return yt("field is protected","unsupported-content","locked");if(e.op==="setFieldResult")return Rd(e,s,i,(h,f)=>o(h,f,true),a);let d=o(s,i.paragraphId,e.op==="updateFieldResult");if(d)return d;let m=[],c=a?.trim();if(e.op==="deleteField"){if(c!==void 0&&!Dm$1(s.part,i.paragraphId,i.fieldNodeId,c))return yt("TrackMineOnly deletes only a field that is your own pending insertion; no permanent edit was applied","unsupported-capability","change-tracking-operation-unsupported");m.push({op:"deleteText",paragraphId:i.paragraphId,start:l.start,end:l.end,...c===void 0?{}:{revision:{author:c,date:re()}}});}else if(e.op==="setFieldCode"){if(!Dn$1(l.code)||!Dn$1(e.code))return yt("only PAGE and NUMPAGES code writes are supported");m.push({op:"setFieldCode",paragraphId:i.paragraphId,fieldNodeId:i.fieldNodeId,code:e.code});}else {let h=Dn$1(l.code);if(!h||!l.rewritable)return yt("this field result cannot be evaluated","unsupported-capability");let f=r?.(s.story,i.paragraphId,i.fieldNodeId);if(!f||!Number.isInteger(f.pageNumber)||f.pageNumber<1||!Number.isInteger(f.pageCount)||f.pageCount<1)return yt("field update requires actual semantic pagination","unsupported-capability");let y=h==="PAGE"?f.pageNumberText??String(f.pageNumber):String(f.pageCount);m.push({op:"refreshFieldResults",updates:[{paragraphId:i.paragraphId,fieldNodeId:i.fieldNodeId,text:y}]});}return {ok:true,kind:"command",story:s.story,ops:m,answer:()=>({kind:"applied"})}}var de=(e,t)=>b(e,t,t),wt=_,Yp=new Set(["insertTableRows","getTables","getTable","getTableRows","getTableCells","getTableCell","getMergedTableCell","getTableCellProperties","getTableCellBody","updateTable","updateTableCell","splitTableCell","insertTable"]);function Mt(e){let t=new Set,n=[e];for(;n.length;){let o=n.pop();o.kind==="paragraph"&&t.add(o.id),o.kind!=="textValue"&&n.push(...o.children);}return t}function wd(e,t){let n=Mt(e);return [...Mt(t)].filter(o=>!n.has(o)).length}function Cd(e,t){let n=[{node:e}];for(;n.length;){let{node:o,table:r}=n.pop();if(o.id===t)return r;if(o.kind==="textValue")continue;let a=o.kind==="table"?o:r;for(let i of o.children)n.push({node:i,table:a});}}function qp(e,t){let n=e.package&&ud$1(e.package);return !n||typeof t!="string"?"":Et(n).nameOf("table",t)??""}function Td(e,t){if(!Yp.has(e.op))return null;let{handles:n,reads:o}=t;if(e.op==="getTables"||e.op==="insertTable"){let c=e.op==="getTables"?e.scope:e.span,h=ee(c,n,o);if(!h.ok)return de(h.code,h.detail);let f=W(c,n,o);if(!f.ok)return de(f.code,f.detail);let y=h.value;if(e.op==="getTables"){let S=f.value,M=Um$1(y.root).filter(j=>{if("body"in c)return true;if(!S)return false;let J=[...Mt(j)].sort((K,G)=>y.indexOf(K)-y.indexOf(G)),C=J[0],z=J[J.length-1];return !C||!z?false:y.indexOf(C)>=S.start.index&&y.indexOf(z)<=S.end.index});return wt({kind:"handles",handles:M.map(j=>n.table(j.id,y.story))})}if(!f.value)return de("invalid-offset","empty-table-insertion-range");if(!["Before","After"].includes(e.location))return de("unsupported-content","table-insertion-location");let x=e.location==="Before"?f.value.start:f.value.end;if(Cd(y.part.root,x.paragraphId)){let S="body"in e.span&&y.root.kind!=="textValue"&&y.root.children.some(M=>M.kind==="table"&&Mt(M).has(x.paragraphId));return de("unsupported-content",S?"table-at-body-edge":"nested-table-authoring")}let P=Zm$1(y,x.paragraphId,x.offset,e.rowCount,e.columnCount,e.values,t.trackingAuthor?{author:t.trackingAuthor,date:re()}:void 0);if(!P.ok)return de("unsupported-content",P.reason);let A=t.admitWrite(y,wd(y.part.root,P.resultPart.root),[x.paragraphId]);if(A)return A;let N=new Set(Um$1(y.root).map(S=>S.id));return {ok:true,kind:"command",story:y.story,ops:[{op:"authorTable",action:{kind:"insert",paragraphId:x.paragraphId,offset:x.offset,rowCount:e.rowCount,columnCount:e.columnCount,...e.values?{values:e.values}:{}},...t.trackingAuthor?{revision:{author:t.trackingAuthor,date:re()}}:{}}],answer:S=>{let M=S.story(y.story),j=M&&Um$1(M.root).find(J=>!N.has(J.id));return j?{kind:"handle",handle:n.table(j.id,y.story)}:{kind:"applied"}}}}let r=e.op==="getTableCells"||e.op==="insertTableRows"?"tableRow":"cell"in e?"tableCell":"table",a=e.op==="getTableCells"||e.op==="insertTableRows"?e.row:"cell"in e?e.cell:"table"in e?e.table:{kind:"document",ref:""},i=n.resolve(a,r);if(!i||!("nodeId"in i)||!("story"in i))return de("invalid-handle","unknown-table-object");let s=o.story(i.story);if(!s)return de("invalid-handle","missing-table-story");let l=eb(s.part,i.nodeId);if(!l||l.kind!==r)return de("invalid-handle","deleted-table-object");let d=r==="table"?l:Cd(s.root,i.nodeId);if(!d)return de("invalid-handle","missing-parent-table");let m=Vm$1(s,d.id);if(!m)return de("unsupported-content","unsupported-table-topology");switch(e.op){case "getTable":return wt({kind:"table",table:{values:m.values,headerRowCount:m.headerRowCount,rowCount:m.rowIds.length,columnCount:m.columnCount,style:qp(o,m.styleId)}});case "getTableRows":return wt({kind:"handles",handles:m.rowIds.map(c=>n.tableRow(c,s.story))});case "getTableCells":{let c=m.rowIds.indexOf(i.nodeId);return wt({kind:"handles",handles:(m.cellIds[c]??[]).map(h=>n.tableCell(h,s.story))})}case "getTableCell":{if(!Number.isInteger(e.rowIndex)||!Number.isInteger(e.cellIndex))return de("invalid-offset","invalid-cell-index");let c=m.cellIds[e.rowIndex]?.[e.cellIndex];return c?wt({kind:"handle",handle:n.tableCell(c,s.story)}):de("invalid-handle","cell-not-found")}case "getMergedTableCell":{let c=m.cellIds[e.topRow]?.[e.firstCell],h=m.cellIds[e.bottomRow]?.[e.lastCell];if(!c||!h||e.bottomRow<e.topRow)return de("unsupported-content","invalid-table-index");let f=an$1(s.part,d.id,c===h?[c]:[c,h]);return f.ok?wt({kind:"handle",handle:n.tableCell(f.cellId,s.story)}):de("unsupported-content",f.reason)}case "getTableCellBody":return wt({kind:"handle",handle:n.body(s.story,i.nodeId)});case "getTableCellProperties":{let c=Wm$1(s,d.id,i.nodeId);return c?wt({kind:"tableCell",cell:{value:c.value,columnWidth:c.columnWidth,shadingColor:c.shadingColor,verticalAlignment:c.verticalAlignment}}):de("invalid-handle","cell-not-found")}case "insertTableRows":case "updateTable":case "updateTableCell":case "splitTableCell":{let c=e.op==="splitTableCell"?{kind:"splitCell",cellId:i.nodeId,rowCount:e.rowCount,columnCount:e.columnCount}:e.op==="insertTableRows"?{kind:"insertRows",rowId:i.nodeId,location:e.location,count:e.count,...e.values?{values:e.values}:{}}:e.op==="updateTable"?e.mutation:{...e.properties,kind:"cell",cellId:i.nodeId};if(c.kind==="properties"&&c.styleId!==void 0){let v=c.styleId;if(typeof v!="string"||!Or(v))return de("unsupported-content","invalid-table-style-name");let P=o.package&&ud$1(o.package);if(!P)return de("unsupported-content","no-styles-defined: table");let A=Et(P).idOf("table",v);if(A===null)return de("unsupported-content","style-not-defined: table");c={...c,styleId:A};}let h=t.trackingAuthor?{author:t.trackingAuthor,date:re()}:void 0;if(h&&t.trackedRangeReplacement===false&&(c.kind==="values"||c.kind==="cell"&&c.value!==void 0))return de("unsupported-capability","tracked table value replacement is unsupported in collaboration");let f=Ym$1(s,d.id,c,h);if(!f.ok)return de(h&&f.reason==="cell-has-revision"&&(c.kind==="mergeCells"||c.kind==="splitCell")?"unsupported-capability":f.reason==="unsupported-revision"||f.reason==="cell-has-revision"?"unsupported-revision":f.reason==="tracked-table-deletion-unsupported"||f.reason==="unsupported-tracked-table-operation"?"unsupported-capability":"unsupported-content",f.reason);let y=t.admitWrite(s,wd(s.part.root,f.resultPart.root),c.kind==="values"?[...Mt(d)]:c.kind==="cell"&&c.value!==void 0?[...Mt(l)]:[],c.kind==="mergeCells"?[...Mt(d)]:[]);if(y)return y;let x=new Set(m.rowIds);return {ok:true,kind:"command",story:s.story,ops:[{op:"authorTable",action:{kind:"existing",tableId:d.id,mutation:c},...h?{revision:h}:{}}],answer:v=>{if(c.kind!=="addRows"&&c.kind!=="insertRows")return {kind:"applied"};let P=v.story(s.story);return {kind:"handles",handles:((P&&Vm$1(P,d.id))?.rowIds??[]).filter(N=>!x.has(N)).map(N=>n.tableRow(N,s.story))}}}}default:return de("unsupported-content","unknown-table-operation")}}var Ke=(e,t="unsupported-content",n)=>({ok:false,error:{code:t,message:e,...n===void 0?{}:{detail:n}}});function Nd(e,t,n,o){if(e.op==="getInlinePictures"||e.op==="insertInlinePicture"){let m=W(e.span,t,n),c=ee(e.span,t,n);if(!m.ok||!c.ok)return Ke("that picture range no longer exists","invalid-handle",m.ok?c.ok?void 0:c.detail:m.detail);let h=c.value;if(e.op==="getInlinePictures")return {ok:true,kind:"query",value:{kind:"handles",handles:Sl(h.part,mt(m.value,h)).map(S=>t.inlinePicture(S,h.story))}};if(!m.value||!n.package)return Ke("insert a paragraph before inserting a picture");let{start:f,end:y}=m.value;if(!["Before","After","Start","End","Replace"].includes(e.location))return Ke("unsupported picture insert location");if(e.location==="Replace"&&f.paragraphId!==y.paragraphId)return Ke("picture replacement requires a single paragraph");let x=e.location==="After"||e.location==="End"?y:f;if(Kh(h.part,x.paragraphId).content||Oh(h.part,x.paragraphId))return Ke("picture insertion is inside protected content");let v=eb(h.part,x.paragraphId);if(v?.kind==="paragraph"){for(let S of Bi(v))if((e.location==="Replace"?S.start<y.offset&&S.end>f.offset:S.start<x.offset&&S.end>x.offset)&&(Kh(h.part,S.node.id).content||Oh(h.part,S.node.id)))return Ke("picture insertion touches protected content")}let P=o(h,x.paragraphId);if(P)return P;let A=Rl(n.package,h.part.name,x.paragraphId,x.offset,e.base64);if(!A.ok)return Ke(A.detail);let N=[];return e.location==="Replace"&&y.offset>f.offset&&N.push({op:"deleteText",paragraphId:f.paragraphId,start:f.offset,end:y.offset}),N.push(...A.ops),{ok:true,kind:"command",story:h.story,ops:N,packageEdits:A.packageEdits,answer:S=>{let M=S.story(h.story)?.part,j=M&&Ye(M).find(J=>J.docPrId===A.docPrId&&J.kind==="inline");if(!j)throw new Error("inserted picture was not committed");return {kind:"handle",handle:t.inlinePicture(j.drawingNodeId,h.story)}}}}let r=t.resolve(e.picture,"inlinePicture");if(!r||r.kind!=="inlinePicture")return Ke("that is not a picture handle","invalid-handle");let a=n.story(r.story),i=a&&Pl(a.part,r.drawingNodeId);if(!a||!i)return Ke("that inline picture no longer exists","invalid-handle",tt);if(e.op==="getInlinePicture")return {ok:true,kind:"query",value:{kind:"inlinePicture",picture:Il(i)}};let s=eb(a.part,r.drawingNodeId);for(;s&&s.kind!=="paragraph";)s=Th(a.part,s.id);if(!s||!a.has(s.id))return Ke("picture is outside this story","invalid-handle");let l=o(a,s.id);if(l)return l;let d=e.op==="deleteInlinePicture"?{ok:true,ops:[{op:"deleteDrawing",drawingNodeId:r.drawingNodeId}]}:wl(i,e.properties);return d.ok?{ok:true,kind:"command",story:a.story,ops:d.ops,answer:()=>({kind:"applied"})}:Ke(d.detail)}var Ed=["insert","delete"];function Jp(e,t,n){let o=new Map;t.forEach((l,d)=>{for(let m of ll$1(l))o.set(m,d);});let r=t.map((l,d)=>d),a=l=>{for(;r[l]!==l;)r[l]=r[r[l]],l=r[l];return l};for(let[l,d]of o)for(let m=fb(e,l);m;m=fb(e,m.id)){let c=o.get(m.id);c!==void 0&&(r[a(c)]=a(d));}let i=t.findIndex(l=>ml$1(l)===n);if(i<0)return [];let s=a(i);return t.filter((l,d)=>a(d)===s)}function Dd(e,t,n){if(!Ed.includes(t.revisionKind))return [];let o=_e(e.story)?e.root:void 0,r=o&&o.kind!=="textValue"?{...e.part,root:o}:e.part,a=Jp(e.part,cm$1(r),ml$1(t));if(a.length<2||a.some(m=>!Ed.includes(m.revisionKind)))return [];let i=a.map(ml$1);if(Aa(e.part,n,i,o,{countRemaining:false}).result.skipped.length)return [];let s=new Set(ll$1(t)),l=n==="accept"?"acceptRevision":"rejectRevision",d=new Map;for(let m of Ol$1(e.part)){if(!s.has(m.node.id))continue;let c=v=>m.node.attributes.find(P=>P.namespaceUri===pa&&P.localName===v)?.value,h=t.addresses.find(v=>v.id===c("id")&&v.author===(c("author")??"")&&(v.date??"")===(c("date")??""));if(!h)return [];let f=m.node.localName,y=JSON.stringify([h,f]),x=d.get(y);x?x.siteNodeIds.push(m.node.id):d.set(y,{revision:h,localName:f,siteNodeIds:[m.node.id]});}return [...d.values()].map(m=>({op:l,...m}))}var Fd=256,Qp=1<<22,Ld=new WeakMap,Zp={story:new Map,copy:new Set};function em(e){return e.kind!=="textValue"&&e.namespaceUri===pa&&e.localName==="txbxContent"}function tm(e){let t=e.children.find(r=>r.kind!=="textValue"&&r.namespaceUri===sa$1&&r.localName==="Fallback");if(!t||t.kind==="textValue")return null;let n=null,o=[{node:t,depth:0}];for(;o.length>0;){let{node:r,depth:a}=o.pop();if(!(r.kind==="textValue"||a>Fd)){if(em(r)){if(n)return null;n=r;continue}for(let i of r.children)o.push({node:i,depth:a+1});}}return n}function Md(e,t,n,o,r){let a=[{node:e,depth:0}];for(;a.length>0;){let{node:i,depth:s}=a.pop();if(--o.left<0||s>Fd)return false;if(i.kind!=="textValue"){n.set(i.id,t),r?.add(i.id);for(let l of i.children)a.push({node:l,depth:s+1});}}return true}function Tn(e){let t=Ld.get(e.root);if(t)return t;let n={left:Qp},o=ko(e,id$1(hd$2(e)??e.root)),r=new Map,a=new Set,i=o.ok;for(let l of o.ok?o.shapes:[]){if(!i)break;let d=l.textboxRoot;if(!d)continue;i=Md(d,d.id,r,n);let m=l.alternate?tm(l.alternate):null;i&&m&&(i=Md(m,d.id,r,n,a));}let s=!i||r.size===0?Zp:{story:r,copy:a};return Ld.set(e.root,s),s}function Bd(e,t,n,o){return t.length===0?n===null&&o():n===null?t.every(r=>!e.story.has(r))&&o():t.every(r=>e.story.get(r)===n)&&t.some(r=>!e.copy.has(r))}var nm={insert:"Insert",delete:"Delete",replace:"Replace",moveFrom:"MovedFrom",moveTo:"MovedTo",format:"Property"},om={insert:"Insert",delete:"Delete",moveFrom:"MovedFrom",moveTo:"MovedTo"};function Hd(e,t){return t.length===0?!_e(e.story):t.every(n=>e.has(n.start.paragraphId))}function rm(e,t){if(e.story.kind==="note")return Hd(e,t.ranges);let n=Tn(e.part),o=e.story.kind==="textbox"&&e.root.kind!=="textValue"?e.root.id:null;return Bd(n,ll$1(t),o,()=>Hd(e,t.ranges))}function Ft(e){return Object.freeze(cm$1(e.part).filter(t=>rm(e,t)))}function Mr(e$1,t){let n=Ft(e$1);return t?f(n,e(t)):n}function am(e){let t=e.includes("rowInsert"),n=e.includes("rowDelete");if(t&&n)return;if(t)return "Insert";if(n)return "Delete";let o=new Set(e);if(o.size!==1)return;let[r]=o;return r==="cellInsert"?"CellInsertion":r==="cellDelete"?"CellDeletion":r==="cellMerge"?"CellMerge":r==="numberingInsert"?"ParagraphNumber":void 0}function Nn(e,t){let n=[],o=Mr(e,t);for(let r of o){if(r.readOnly)continue;let a=r.revisionKind==="structural"?am(r.structuralChanges??[]):r.revisionKind==="paragraphMark"?r.markDirection&&om[r.markDirection]:nm[r.revisionKind];a!==void 0&&n.push(Object.freeze({id:r.id,type:a,author:r.author,date:r.date??"",item:r}));}return Object.freeze(n)}function im(e,t){let n=e;for(let o=0;n!==void 0&&o<=64;o+=1){if(n.parentId===void 0)return n.range!==null;n=t.get(n.parentId);}return false}var sm=Object.freeze({items:Object.freeze([]),roots:Object.freeze([]),byId:()=>null,textOf:()=>""});function _d(e,t){let n=e.parts.get($(e,t.part.name));if(!n)return sm;let o=e.parts.get(aa$1(e,t.part.name)),r=Sj(n),a=o?Tj(o):new Map,i=Qj(t.part).filter(c=>t.has(c.start.paragraphId)),s=dm$1(r,i,a),l=new Map(s.map(c=>[c.id,c])),d=s.filter(c=>im(c,l)),m=new Map(d.map(c=>[c.id,c]));return Object.freeze({items:Object.freeze(d),roots:Object.freeze(d.filter(c=>c.parentId===void 0)),byId:c=>m.get(c)??null,textOf:c=>{let h=m.get(c);return h?_l$1(h.comment):""}})}var lm=64,jd=Object.freeze({kind:"applied"});function Ee(e,t,n){return {ok:false,error:Object.freeze(n===void 0?{code:e,message:t}:{code:e,message:t,detail:n})}}function Bo(e){return {ok:true,kind:"query",value:e}}function Kd(){return {decided:new Map,whole:false}}function Fr(e,t,n,o,r){let a=r(e);if(a)return a;if(o.whole)return Ee("conflicting-operations","an earlier decision resolved the whole story");let i=t.filter(y=>o.decided.get(ml$1(y))!=="removed"),s=um(e,i.filter(y=>{let x=o.decided.get(ml$1(y));return dm(y,n)&&(x===void 0||x===n)})),l=[];for(let y of i){let x=ml$1(y),v=o.decided.get(x);if(!s.has(x)){if(v===void 0)l.push(y);else if(v!==n)return Ee("conflicting-operations","an earlier decision took the contrary action")}}let d=y=>{for(let x of y)o.decided.set(x,n);for(let x of s)o.decided.set(x,"removed");};if(l.length===0)return d([]),{ok:true,kind:"command",story:e.story,ops:[],answer:()=>jd};let m=l.map(ml$1),c=Aa(e.part,n,m,_e(e.story)?e.root:void 0,{countRemaining:false,explicit:true}),h=c.ops,f=c.result.skipped;if(f.length>0){let y=f.every(P=>P.reason==="incomplete-group")?cm(e,l,n):null,x=f[0],v=f.find(P=>P.detail==="locked-content"||P.detail==="bound-content");if(!y&&v)return Ee("transaction-refused","a content control keeps that change",v.detail);if(!y)return Ee("unsupported-revision","a tracked change in that decision cannot be resolved",x&&(x.detail?`${x.reason}:${x.detail}`:x.reason));h=y,d(m);}else {d([...m,...c.result.resolved.map(y=>y.key)]);for(let y of c.swept??[])o.decided.set(y,"removed");}return {ok:true,kind:"command",story:e.story,ops:h,answer:()=>jd}}function dm(e,t){return t==="reject"?e.revisionKind==="insert":e.revisionKind==="delete"}function um(e,t){let n=new Set;for(let r of t)for(let a of ll$1(r))n.add(a);if(n.size===0)return new Set;let o=r=>{for(let a=fb(e.part,r);a;a=fb(e.part,a.id))if(n.has(a.id))return true;return false};return new Set(Ft(e).filter(r=>{let a=ll$1(r);return a.length>0&&a.every(o)}).map(ml$1))}function cm(e,t,n){let o=[];for(let r of t){let a=Dd(e,r,n);if(a.length===0)return null;for(let i of a)o.push(i);}return o}function ot(e,t){return e.index===t.index?e.offset-t.offset:e.index-t.index}function pm(e,t,n){let o=e.indexOf(n.start.paragraphId),r=e.indexOf(n.end.paragraphId);if(o<0||r<0)return false;let a={index:o,offset:n.start.offset},i={index:r,offset:n.end.offset},s={index:e.indexOf(t.start.paragraphId),offset:t.start.offset},l={index:e.indexOf(t.end.paragraphId),offset:t.end.offset};return ot(s,l)===0?ot(a,l)<=0&&ot(i,s)>=0:ot(a,i)===0?ot(a,s)>=0&&ot(a,l)<0:ot(a,l)<0&&ot(i,s)>0}function Wd(e,t){return t===null?[]:Ft(e).filter(n=>n.ranges.some(o=>pm(e,t,o)))}function Vd(e,t,n,o){let r=new Set(t.map(a=>a.id));return {kind:"handles",handles:Nn(e,o).filter(a=>r.has(a.id)).map(a=>n.revision(a.id,e.story))}}function $d(e){let t=new Map,n=r=>{r&&!t.has(r.part.name)&&t.set(r.part.name,r.part);};n(e.body);let o=e.sections().length;for(let r=0;r<o;r+=1)for(let a of e.furniture(r))a.declared&&n(e.story({kind:a.kind,sectionIndex:r,variant:a.variant}));for(let r of ["footnote","endnote"]){let a=e.noteIds(r),i=a.ok?a.ids[0]:void 0;i!==void 0&&n(e.story({kind:"note",noteKind:r,noteId:i}));}return [...t.values()]}function zd(e,t){if(t===void 0)return null;let n=e.storyOf(t);return n?e.story(n):null}function Br(e,t){let n=ql$1(t);if(!n||n.kind!=="revision"&&n.kind!=="replacement")return null;let o=n.kind==="replacement"?n.halves:"";for(let r of $d(e)){let a=cm$1(r),i=null;if(n.kind==="revision"){let d=a.find(m=>m.id===n.id);d&&(i=[d]);}else for(let d of a){if(!o.startsWith(`${d.id}+`))continue;let m=o.slice(d.id.length+1),c=a.find(h=>h.id===m);if(c&&pl$1(d,c)){i=[d,c];break}}if(!i)continue;let s=zd(e,i[0].ranges[0]?.start.paragraphId);if(!s)return null;let l=new Set(Ft(s).map(d=>d.id));return i.every(d=>l.has(d.id))?{reads:s,items:i}:null}return null}function mm(e,t){let n=e.package,o=e.body;if(!n||!o)return null;let r=n.parts.get($(n,o.part.name));if(!r)return null;let a=n.parts.get(aa$1(n,o.part.name)),i=a?Tj(a):new Map,s=[];for(let c of $d(e))for(let h of Qj(c))s.push(h);let l=dm$1(Sj(r),s,i),d=new Map(l.map(c=>[c.id,c])),m=d.get(t);for(let c=0;m&&c<=lm;c+=1){if(m.range){if(m.orphaned)return null;let h=zd(e,m.range.start.paragraphId);return h&&h.has(m.range.end.paragraphId)?{reads:h,range:m.range}:null}m=m.parentId===void 0?void 0:d.get(m.parentId);}return null}function Ud(e,t,n){let o=null,r=null;for(let i of t)for(let s of [i.start,i.end]){let l=e.rawText(s.paragraphId);if(l===null)return null;let d={paragraphId:s.paragraphId,index:e.indexOf(s.paragraphId),offset:Math.min(s.offset,l.length)};(!o||ot(d,o)<0)&&(o=d),(!r||ot(d,r)>0)&&(r=d);}if(!o||!r)return null;let a=e.story;return Ae({start:{...o,story:a},end:{...r,story:a}},n)}function Hr(e){return typeof e=="string"&&e.length>0?null:Ee("unsupported-content","a review item key is nonempty text")}function Gd(e,t,n){let o=Hr(e);if(o)return o;if(n.package===null)return Ee("document-unavailable","this host holds no document");let r=ql$1(e),a=null;if(r?.kind==="comment"){let i=mm(n,r.id);a=i?Ud(i.reads,[i.range],t):null;}else {let i=Br(n,e),s=i?.items.flatMap(l=>l.ranges)??[];a=i&&s.length>0?Ud(i.reads,s,t):null;}return Bo({kind:"spans",spans:a?[a]:[]})}function Xd(e,t,n){if("body"in e){let a=le(e.body,"body",t,n);if(!a.ok)return Ee(a.code,"that handle does not name a body",a.detail);let i=a.value;return Bo({kind:"handles",handles:Nn(i,n.package).map(s=>t.revision(s.id,i.story))})}if("key"in e){let a=Hr(e.key);if(a)return a;let i=Br(n,e.key);return Bo(i?Vd(i.reads,i.items,t,n.package):{kind:"handles",handles:[]})}let o=W(e.scope,t,n);if(!o.ok)return Ee(o.code,"that span is not a place",o.detail);let r=ee(e.scope,t,n);return r.ok?Bo(Vd(r.value,Wd(r.value,o.value),t,n.package)):Ee(r.code,"that span names no story",r.detail)}function Yd(e,t,n,o,r){let a=e.op==="acceptAllRevisions"?"accept":"reject",i;if("key"in e){let s=Hr(e.key);if(s)return s;let l=Br(n,e.key);if(!l)return Ee("invalid-handle","that review item is not in this document");i=l;}else {let s=e.scope,l=W(s,t,n);if(!l.ok)return Ee(l.code,"that span is not a place",l.detail);let d=ee(s,t,n);if(!d.ok)return Ee(d.code,"that span names no story",d.detail);i={reads:d.value,items:Wd(d.value,l.value)};}return i.items.some(s=>s.readOnly)?Ee("unsupported-revision","a tracked change in that decision is read-only"):Fr(i.reads,i.items,a,r,o)}function qd(e,t,n,o,r){let a=x=>({ok:false,error:{code:"unsupported-content",message:x}}),i=x=>({ok:false,error:{code:"unsupported-capability",message:x,detail:"change-tracking-operation-unsupported"}});if(e.breakType!=="Page"&&e.breakType!=="SectionNext")return a("only Line, Page, and SectionNext breaks are supported");if(!["Before","After","Start","End","Replace"].includes(e.location))return a("invalid break insertion location");if(r!==void 0&&e.location==="Replace")return i("a tracked page or section break cannot replace text; delete the text, then insert the break");let s=W(e.span,t,n);if(!s.ok)return {ok:false,error:{code:s.code,message:s.detail}};let l=s.value;if(!l)return a("empty story has no break position");let d=e.location==="After"||e.location==="End"?l.end:l.start,m=n.story(d.story);if(!m)return a("missing story");if(e.location==="Replace"&&l.start.paragraphId!==l.end.paragraphId)return a("break replacement must remain in one paragraph");let c=e.breakType==="SectionNext";if(c&&(m.story.kind!=="body"||en$1(m.part,d.paragraphId)))return a("section breaks require a body paragraph outside a table");if(c&&r!==void 0&&gn(fn(m.part,d.paragraphId).section)!=="nextPage")return i("a tracked next-page section break cannot change how the following section starts");let h=o(m,d.paragraphId,c?1:0);if(h)return h;let f=r===void 0?void 0:{author:r.trim(),date:re()},y=[];return e.location==="Replace"&&l.end.offset>l.start.offset&&y.push({op:"deleteText",paragraphId:d.paragraphId,start:l.start.offset,end:l.end.offset}),c?y.push(f?{op:"splitParagraphMany",paragraphId:d.paragraphId,offsets:[d.offset],revision:f}:{op:"splitParagraph",paragraphId:d.paragraphId,offset:d.offset},{op:"setSectionMark",paragraphId:d.paragraphId,breakType:"nextPage"}):y.push({op:"insertPageBreak",paragraphId:d.paragraphId,offset:d.offset,...f?{revision:f}:{}}),{ok:true,kind:"command",story:m.story,ops:y,answer:()=>({kind:"applied"})}}function Jd(e,t){if(e.op!=="insertBreak"||e.breakType!=="Line")return null;let{span:n,location:o}=e,r=s=>"body"in n?{body:n.body,at:s}:"paragraph"in n?{paragraph:n.paragraph,at:s}:s==="start"?n.start:n.end,a=o==="Replace"?{op:"replaceSpan",span:n,text:gt}:o==="Before"||o==="Start"?{op:"insertText",at:r("start"),text:gt}:o==="After"||o==="End"?{op:"insertText",at:r("end"),text:gt}:null;if(!a)return {ok:false,error:{code:"unsupported-content",message:"invalid break insertion location"}};let i=t(a);return i.ok&&i.kind==="command"?{...i,answer:()=>({kind:"applied"})}:i}var fm=/[\r\n]/,gm=/\r\n|\r|\n/,hm=/[\f\u2028\u2029]/;function ym(e,t,n){let o=eb(e.part,t);if(!Ai(o))return false;let r=Am$1(e.part,o,n,n);return r!==null&&tc$1(o,r.id)!==null}var an=(e,t)=>({ok:false,error:{code:"unsupported-content",message:e,detail:t}});function Qd(e,t){if(e.op!=="insertText"&&e.op!=="replaceSpan")return null;let{text:n}=e;if(typeof n!="string"||!fm.test(n))return null;if(hm.test(n))return an("text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let o=n.split(gm),r=t.planJoined({...e,text:o.join("")});if(!r.ok||r.kind!=="command")return r;if(r.lifecycle||r.relate||r.packageEdits?.length)return an("that write cannot also split its paragraph","paragraph-break");let a=r.answer(t.reads);if(a.kind!=="span")return an("that write does not name where its text lands","paragraph-break");let{start:i}=a.span,s=W({start:i,end:i},t.handles,t.reads);if(!s.ok||!s.value)return an("that write does not name where its text lands","paragraph-break");let l=s.value.start,d=t.reads.story(l.story);if(!d)return an("that story is not in this document","paragraph-break");if(ym(d,l.paragraphId,l.offset))return {ok:false,error:{code:"unsupported-capability",message:"a paragraph break cannot split an inline content control",detail:"indivisible-content"}};let m=[],c=l.offset;for(let P of o.slice(0,-1))c+=P.length,m.push(c);let h=t.reserve(l.paragraphId,m.length);if(!h)return an("that paragraph is not in this story","paragraph-break");let f=r.ops.find(P=>P.op==="insertText"&&P.revision!==void 0),y=t.trackingAuthor?f?.revision??{author:t.trackingAuthor.trim(),date:re()}:void 0,x={op:"splitParagraphMany",paragraphId:l.paragraphId,offsets:m,...y?{revision:y}:{}},v=o[o.length-1];return {...r,ops:[...r.ops,x],answer:()=>{let P=h[h.length-1]?.id;return P?{kind:"span",span:{start:{paragraph:t.handles.paragraph(l.paragraphId,d.story),offset:l.offset},end:{paragraph:t.handles.paragraph(P,d.story),offset:v.length}}}:{kind:"applied"}}}}var km=new Set(["p","tbl","sdt","customXml","altChunk"]);function Zd(e,t,n){if(!("body"in e))return null;let o=le(e.body,"body",t,n);return o.ok?xm(o.value.root,e.at):null}function xm(e,t){if(e.kind==="textValue")return null;let n=e.children.filter(r=>r.kind!=="textValue"&&km.has(r.localName)),o=t==="first"?n[0]:n[n.length-1];return o&&o.kind!=="textValue"&&o.localName==="tbl"?o.id:null}function _r(e){return typeof e!="string"?{ok:false,error:{code:"unsupported-content",message:"insertParagraph needs text",detail:"text"}}:ht.test(e)?{ok:false,error:{code:"unsupported-content",message:"a paragraph mark inside a paragraph\u2019s text is not written by this host",detail:"paragraph-mark-in-text"}}:null}var rt=(e,t)=>e.children.find(n=>n.kind!=="textValue"&&n.namespaceUri===pa&&n.localName===t),We=(e,t)=>e.attributes.find(n=>n.namespaceUri===pa&&n.localName===t)?.value,Ho=e=>e.replaceAll("&","&").replaceAll('"',""").replaceAll("<","<").replaceAll(">",">"),jr=e=>typeof e=="string"&&e.length<=255&&!/[\x00-\x08\x0b\x0c\x0e-\x1f\uFFFE\uFFFF]/.test(e),eu={None:"none",Arabic:"decimal",UpperRoman:"upperRoman",LowerRoman:"lowerRoman",UpperLetter:"upperLetter",LowerLetter:"lowerLetter"},tu={Solid:["\uF0B7","Symbol"],Hollow:["o","Courier New"],Square:["\uF0A7","Wingdings"],Diamonds:["\uF076","Wingdings"],Arrow:["\uF0D8","Wingdings"],Checkmark:["\uF0FC","Wingdings"]};function Vr(e){let t=Ti(e,"bullet");if(!t)return null;let n=t.pkg;for(let o=0;o<=8;o+=1)if(!En(n,t.numId,o)){let r=_o(n,t.numId,o,{bullet:o%3===0?"Solid":o%3===1?"Hollow":"Square"});if(!r)return null;n=r;}return {pkg:n,numId:t.numId}}function En(e,t,n){let o=e.parts.get("/word/numbering.xml")?.root;if(!o)return false;let r=o.children,a=r.find(d=>d.kind!=="textValue"&&d.namespaceUri===pa&&d.localName==="num"&&We(d,"numId")===t);if(!a)return false;let i=a.children.find(d=>d.kind!=="textValue"&&d.namespaceUri===pa&&d.localName==="lvlOverride"&&We(d,"ilvl")===String(n));if(i&&rt(i,"lvl"))return true;let s=rt(a,"abstractNumId"),l=s&&r.find(d=>d.kind!=="textValue"&&d.namespaceUri===pa&&d.localName==="abstractNum"&&We(d,"abstractNumId")===We(s,"val"));return !!l&&!rt(l,"numStyleLink")&&l.children.some(d=>d.kind!=="textValue"&&d.namespaceUri===pa&&d.localName==="lvl"&&We(d,"ilvl")===String(n))}function Ur(e,t){if(!Number.isInteger(e)||e<0||e>8||!t||typeof t!="object")return false;if(t.bullet!==void 0){if(t.numbering!==void 0)return false;if(t.bullet==="Custom"){if(!Number.isInteger(t.charCode)||t.charCode<1||t.charCode>65535||t.charCode>=55296&&t.charCode<=57343||!jr(String.fromCharCode(t.charCode)))return false}else if(!Object.hasOwn(tu,t.bullet))return false;if(t.fontName!==void 0&&(!jr(t.fontName)||!t.fontName.trim()))return false}if(t.numbering!==void 0&&!Object.hasOwn(eu,t.numbering)||t.formatString!==void 0&&(!Array.isArray(t.formatString)||t.formatString.length>32||t.formatString.some(o=>typeof o=="number"?!Number.isInteger(o)||o<0||o>e:!jr(o)||/%[1-9]/.test(o)))||t.startingNumber!==void 0&&(!Number.isInteger(t.startingNumber)||t.startingNumber<0||t.startingNumber>2147483647))return false;for(let o of [t.textIndent,t.bulletNumberPictureIndent])if(o!==void 0&&(!Number.isFinite(o)||Math.abs(o)>1584))return false;let n=["bullet","charCode","fontName","numbering","formatString","startingNumber","textIndent","bulletNumberPictureIndent"];return Object.keys(t).some(o=>!n.includes(o))||t.bullet===void 0&&(t.charCode!==void 0||t.fontName!==void 0)||t.numbering===void 0&&t.formatString!==void 0?false:Object.keys(t).length>0}function _o(e,t,n,o){if(!Ur(n,o))return null;let r=e.parts.get("/word/numbering.xml");if(!r)return null;let a=r.root.children.find(C=>C.kind!=="textValue"&&C.namespaceUri===pa&&C.localName==="num"&&We(C,"numId")===t),i=a&&rt(a,"abstractNumId");if(!a||!i)return null;let s=r.root.children.find(C=>C.kind!=="textValue"&&C.namespaceUri===pa&&C.localName==="abstractNum"&&We(C,"abstractNumId")===We(i,"val"));if(!s||rt(s,"numStyleLink"))return null;let l=a.children.find(C=>C.kind!=="textValue"&&C.namespaceUri===pa&&C.localName==="lvlOverride"&&We(C,"ilvl")===String(n)),d=(l&&rt(l,"lvl"))??s.children.find(C=>C.kind!=="textValue"&&C.namespaceUri===pa&&C.localName==="lvl"&&We(C,"ilvl")===String(n));if(d&&rt(d,"lvlPicBulletId"))return null;let m=cb(r),c=C=>C.kind==="textValue"?{...C,id:m()}:{...C,id:m(),children:C.children.map(c)},h=C=>{let z=Pa(`<w:numbering xmlns:w="${pa}">${C}</w:numbering>`,{name:r.name,contentType:r.contentType}),K=z.ok?z.part.root.children[0]:void 0;return K&&K.kind!=="textValue"?c(K):null};if(d??=h(`<w:lvl w:ilvl="${n}"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%${n+1}."/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="${720*(n+1)}" w:hanging="360"/></w:pPr></w:lvl>`)??void 0,!d)return null;let f=[...d.children],y=["start","numFmt","lvlRestart","pStyle","isLgl","suff","lvlText","lvlPicBulletId","legacy","lvlJc","pPr","rPr"],x=(C,z)=>{let K=h(z);if(!K)return false;let G=f.findIndex(Q=>Q.kind!=="textValue"&&Q.namespaceUri===pa&&Q.localName===C);if(G>=0){let Q=f[G];f.splice(G,1,{...Q,attributes:[...Q.attributes.filter(ae=>!K.attributes.some(X=>X.namespaceUri===ae.namespaceUri&&X.localName===ae.localName)),...K.attributes]});}else {let Q=f.findIndex(ae=>ae.kind!=="textValue"&&ae.namespaceUri===pa&&y.indexOf(ae.localName)>y.indexOf(C));f.splice(Q<0?f.length:Q,0,K);}return true};if(o.startingNumber!==void 0&&!x("start",`<w:start w:val="${o.startingNumber}"/>`))return null;if(o.numbering!==void 0){let C=o.formatString?.map(z=>typeof z=="number"?`%${z+1}`:z).join("")??(o.numbering==="None"?"":`%${n+1}.`);if(!x("numFmt",`<w:numFmt w:val="${eu[o.numbering]}"/>`)||!x("lvlText",`<w:lvlText w:val="${Ho(C)}"/>`))return null}if(o.numbering!==void 0&&(f=f.map(C=>C.kind!=="textValue"&&C.namespaceUri===pa&&C.localName==="rPr"?{...C,children:C.children.filter(z=>z.kind==="textValue"||z.namespaceUri!==pa||z.localName!=="rFonts")}:C)),o.bullet!==void 0){let[C,z]=o.bullet==="Custom"?[String.fromCharCode(o.charCode),o.fontName??"Symbol"]:tu[o.bullet];if(!x("numFmt",'<w:numFmt w:val="bullet"/>')||!x("lvlText",`<w:lvlText w:val="${Ho(C)}"/>`))return null;let K=rt(d,"rPr"),G=h(`<w:rFonts w:ascii="${Ho(z)}" w:hAnsi="${Ho(z)}"/>`);if(!G)return null;let Q=K?.children.filter(ue=>ue.kind==="textValue"||ue.namespaceUri!==pa||ue.localName!=="rFonts")??[],ae=K?{...K,children:[G,...Q]}:h("<w:rPr/>");if(!ae)return null;let X=f.findIndex(ue=>ue.kind!=="textValue"&&ue.namespaceUri===pa&&ue.localName==="rPr");X<0?f.push({...ae,children:[G,...Q]}):f[X]={...ae,children:[G,...Q]};}if(o.textIndent!==void 0||o.bulletNumberPictureIndent!==void 0){let C=rt(d,"pPr"),z=C&&rt(C,"ind"),K=z?.attributes.filter($=>$.namespaceUri!==pa||!["left","start","firstLine","hanging"].includes($.localName))??[],G=o.textIndent===void 0?String(Qd$1(We(z??d,"left"))??0):String(Math.round(o.textIndent*20)),Q=o.bulletNumberPictureIndent,ae=Q===void 0?z?.attributes.filter($=>$.namespaceUri===pa&&["firstLine","hanging"].includes($.localName))??[]:[],X=h(`<w:ind w:left="${G}"${Q===void 0?"":` w:${Q<0?"hanging":"firstLine"}="${Math.abs(Math.round(Q*20))}"`}/>`);if(!X)return null;let ue={...X,attributes:[...K,...ae,...X.attributes]},fe=C?.children.filter($=>$.kind==="textValue"||$.namespaceUri!==pa||$.localName!=="ind")??[],Oe=C??h("<w:pPr/>");if(!Oe)return null;let we=z?C.children.indexOf(z):-1,xe=[...fe],De=["contextualSpacing","mirrorIndents","suppressOverlap","jc","textDirection","textAlignment","textboxTightWrap","outlineLvl","divId","cnfStyle","rPr","sectPr","pPrChange"],ze=xe.findIndex($=>$.kind!=="textValue"&&$.namespaceUri===pa&&De.includes($.localName));xe.splice(we>=0?we:ze>=0?ze:xe.length,0,ue);let it={...Oe,children:xe},V=f.findIndex($=>$.kind!=="textValue"&&$.namespaceUri===pa&&$.localName==="pPr");if(V>=0)f[V]=it;else {let $=f.findIndex(ge=>ge.kind!=="textValue"&&ge.localName==="rPr"&&ge.namespaceUri===pa);f.splice($<0?f.length:$,0,it);}}let v=c({...d,children:f}),P=l?.children.filter(C=>C.kind==="textValue"||C.namespaceUri!==pa||C.localName!=="lvl"&&(o.startingNumber===void 0||C.localName!=="startOverride"))??[],A=o.startingNumber===void 0?null:h(`<w:startOverride w:val="${o.startingNumber}"/>`);if(o.startingNumber!==void 0&&!A)return null;let N=l??h(`<w:lvlOverride w:ilvl="${n}"/>`);if(!N)return null;let S={...N,children:[...A?[A]:[],...P,v]},M=[...a.children],j=l?M.indexOf(l):-1;j>=0?M[j]=S:M.push(S);let J=kb(r,a.id,{...a,children:M});return J.ok?rg(e,J.part):null}function Bt(e,t){return e&&"children"in e?e.children.find(n=>n.kind!=="textValue"&&n.namespaceUri===pa&&n.localName===t):void 0}function Kr(e,t){return e&&"attributes"in e?e.attributes.find(n=>n.namespaceUri===pa&&n.localName===t)?.value:void 0}function nu(e,t,n,o){return t.length>0&&t.every(r=>{let a=Bt(eb(e.part,r)??void 0,"pPr");if(Kr(Bt(Bt(a,"rPr"),"ins"),"author")===o)return true;let i=Bt(a,"pPrChange"),s=Bt(i,"pPr");return Kr(i,"author")===o&&Kr(Bt(Bt(s,"numPr"),"numId"),"val")!==n})}var sn=8;function ou(e){if(!e||e.kind==="textValue")return null;for(let t of e.attributes)if(t.namespaceUri===pa&&t.localName==="val")return t.value;return null}function jo(e){let t=Sh(Qh(e),"numPr");if(!t)return null;let n=ou(Sh(t,"numId"));if(n===null||!/^\d{1,10}$/.test(n)||n==="0")return null;let o=ou(Sh(t,"ilvl")),r=o===null?0:Number(o);return !Number.isInteger(r)||r<0||r>sn?null:{numId:n,level:r}}function Ht(e){let t=new Map;for(let n of e.paragraphIds){let o=e.node(n);if(!o)continue;let r=jo(o);if(!r)continue;let a=t.get(r.numId);a?a.push(n):t.set(r.numId,[n]);}return Object.freeze([...t].map(([n,o])=>Object.freeze({numId:n,paragraphIds:Object.freeze(o)})))}function Dn(e,t){let n=e.node(t);return n?jo(n):null}var Pe=e=>({ok:false,error:{code:"unsupported-content",message:e}});function bm(e,t){if(e.root.namespaceUri!==pa||e.root.localName!=="styles")return false;let n=[e.root];for(;n.length;){let o=n.pop();if(o.kind!=="textValue"){if(o.namespaceUri===pa&&o.localName==="numId"&&o.attributes.some(r=>r.namespaceUri===pa&&r.localName==="val"&&r.value===t))return true;for(let r of o.children)n.push(r);}}return false}function ru(e,t,n,o,r){let a=n.package;if(!a)return Pe("no document");if(e.op==="setListLevelFormat"){let f=t.resolve(e.list,"list");if(!f||f.kind!=="list")return Pe("that is not a list");let y=n.story(f.story),x=y&&Ht(y).find(v=>v.numId===f.numId);if(!y||!x)return Pe("that list no longer exists");if(r&&!nu(y,x.paragraphIds,f.numId,r))return {ok:false,error:{code:"unsupported-capability",message:"Only a newly proposed list definition can change while tracking"}};if(!Ur(e.level,e.format))return Pe("invalid list level format");for(let v of a.parts.values()){if(bm(v,f.numId))return Pe("list is referenced by a style");for(let P of fd$1(v))for(let A of id$1(P.root))if(jo(A)?.numId===f.numId&&!y.has(A.id))return Pe("list is shared across stories")}for(let v of x.paragraphIds){if(Kh(y.part,v).content||Oh(y.part,v))return Pe("list contains protected content");let P=o(y,v,{numId:f.numId,level:e.level});if(P)return P}return _o(a,f.numId,e.level,e.format)?{ok:true,kind:"command",story:y.story,ops:[],packageEdits:[v=>{let P=_o(v,f.numId,e.level,e.format);if(!P)throw new Kk("list definition changed during transaction");return P}],answer:()=>({kind:"applied"})}:Pe("cannot format this list")}let i=he(e.paragraph,t,n);if(!i.ok)return {ok:false,error:{code:i.code,message:i.detail}};let s=n.story(i.value.story);if(!s)return Pe("missing story");let l=o(s,i.value.paragraphId);if(l)return l;let d=null,m=0,c=[];if(e.op==="startNewList"){let f=Vr(a);if(!f)return Pe("cannot create numbering definition");let y=i.value.paragraphId;if(!Hn(s.part,{op:"setListNumbering",paragraphId:y,numId:f.numId,level:0}).ok)return Pe("cannot number this paragraph");let v=f.numId;return {ok:true,kind:"command",story:s.story,ops:[],packageEdits:[P=>{let A=Vr(P),N=A?.pkg.parts.get(s.part.name);if(!A||!N)throw new Kk("cannot create numbering definition");let S=Hn(N,{op:"setListNumbering",paragraphId:y,numId:A.numId,level:0,...r?{revision:{author:r,date:re()}}:{}});if(!S.ok)throw new Kk(S.detail??"cannot number this paragraph",S.reason);return v=A.numId,rg(A.pkg,S.part)}],answer:()=>({kind:"handle",handle:t.list(v,s.story)})}}else if(e.op==="attachToList"){if(!Number.isSafeInteger(e.listId)||e.listId<=0||!Number.isInteger(e.level)||e.level<0||e.level>8)return Pe("invalid list identity or level");if(d=String(e.listId),m=e.level,!En(a,d,m))return Pe("list level is not defined; configure that level first");if(!Ht(s).some(f=>f.numId===d))return Pe("that list does not exist in this story")}let h=d;return {ok:true,kind:"command",story:s.story,ops:[{op:"setListNumbering",paragraphId:i.value.paragraphId,numId:e.op==="detachFromList"?"0":d,level:m}],packageEdits:c,answer:()=>h===null?{kind:"applied"}:{kind:"handle",handle:t.list(h,s.story)}}}var au="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml",vm="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",iu=new WeakSet;function Wr(e){return iu.add(e),e}function fv(e){return iu.has(e)}function Vo(e,t){return e.attributes.find(n=>n.localName===t)?.value}function Uo(e){let t=[];for(let n of e.children)n.kind!=="textValue"&&n.localName==="style"&&t.push(n);return t}function su(e,t){for(let n of Uo(e)){if(Vo(n,"type")!==t)continue;let o=Vo(n,"default");if(o==="1"||o==="true"||o==="on")return Vo(n,"styleId")??null}return null}function lu(e,t){return Wr(n=>{let o=ud$1(n),r=o?.name??"/word/styles.xml",a=o?null:Pa(`<w:styles xmlns:w="${pa}"/>`,{name:r,contentType:au}),i=o??(a?.ok?a.part:null);if(!i)throw new Error(`Cannot create style ${e}`);if(Uo(i.root).some(h=>Vo(h,"styleId")===e))return n;let s=cb(i),d={...t((h,f={},y=[])=>({...Bk({localName:h,attributes:f},s()),children:y,...h==="pPr"?{kind:"paragraphProperties"}:{},...h==="rPr"?{kind:"runProperties"}:{}}),i.root),namespaceBindings:[{prefix:"w",namespaceUri:pa}]};if(o){let h=jb(i,i.root.id,i.root.children.length,[d]);if(!h.ok)throw new Error(`Cannot insert style ${e}`);return rg(n,h.part)}let m=Bg(n,r,{...i.root,children:[d]},au);m=zg(m,n.mainDocumentPart);let c=Ag(m,n.mainDocumentPart,vm,r);if(!c.ok)throw new Error(`Cannot link style ${e}`);return c.pkg})}var Am="0563C1",Om=/^[0-9A-Fa-f]{6}$/;function Rm(e){let t=new Set([...e].map(n=>n.toLowerCase()));if(!t.has("hyperlink"))return "Hyperlink";for(let n=1;;n+=1){let o=`Hyperlink${n}`;if(!t.has(o.toLowerCase()))return o}}function Pm(e){return Wr(t=>{let n=re$1(se(t)).get("hlink"),r=n!==void 0&&Om.test(n)?{val:n.toUpperCase(),themeColor:"hyperlink"}:{val:Am};return lu(e,(a,i)=>{let s=su(i,"character");return a("style",{type:"character",styleId:e},[a("name",{val:"Hyperlink"}),...s?[a("basedOn",{val:s})]:[],a("uiPriority",{val:"99"}),a("unhideWhenUsed"),a("rPr",{},[a("color",r),a("u",{val:"single"})])])})(t)})}function du(e,t={}){let n=e?ud$1(e)?.root??null:null,o=new Set,r=null;for(let i of n?Uo(n):[]){let s=i.attributes.find(m=>m.localName==="styleId")?.value;if(!s||(o.add(s),i.attributes.find(m=>m.localName==="type")?.value!=="character"))continue;if(s.toLowerCase()==="hyperlink")return {styleId:s,edit:null};let l=i.children.find(m=>m.kind!=="textValue"&&m.localName==="name"),d=l&&l.kind!=="textValue"?l.attributes.find(m=>m.localName==="val")?.value:void 0;r===null&&d?.toLowerCase()==="hyperlink"&&(r=s);}if(r!==null)return {styleId:r,edit:null};if(t.add===false||t.createPart===false&&!n)return {styleId:null,edit:null};let a=Rm(o);return {styleId:a,edit:Pm(a)}}var $r=Object.freeze({None:"none",Single:"single",Word:"words",Double:"double",Thick:"thick",Dotted:"dotted",DottedHeavy:"dottedHeavy",DashLine:"dash",DashLineHeavy:"dashedHeavy",DashLineLong:"dashLong",DashLineLongHeavy:"dashLongHeavy",DotDashLine:"dotDash",DotDashLineHeavy:"dashDotHeavy",TwoDotDashLine:"dotDotDash",TwoDotDashLineHeavy:"dashDotDotHeavy",Wave:"wave",WaveHeavy:"wavyHeavy",WaveDouble:"wavyDouble"}),uu=[["Yellow","yellow","#FFFF00"],["Lime","green","#00FF00"],["Turquoise","cyan","#00FFFF"],["Pink","magenta","#FF00FF"],["Blue","blue","#0000FF"],["Red","red","#FF0000"],["DarkBlue","darkBlue","#000080"],["Teal","darkCyan","#008080"],["Green","darkGreen","#008000"],["Purple","darkMagenta","#800080"],["DarkRed","darkRed","#800000"],["Olive","darkYellow","#808000"],["Gray","darkGray","#808080"],["LightGray","lightGray","#C0C0C0"],["Black","black","#000000"],["White","white","#FFFFFF"]];function cu(e){return Object.entries($r).find(([,t])=>t===e)?.[0]??null}function pu(e){return uu.find(([,t])=>t===e)?.[2]??null}function mu(e){let t=[];if(e.underline!==void 0){let n=typeof e.underline=="string"&&Object.hasOwn($r,e.underline)?$r[e.underline]:void 0;if(!n)return {ok:false,detail:"underline: unsupported underline style"};t.push({localName:"u",attributes:{val:n}});}if(e.strikeThrough!==void 0){if(typeof e.strikeThrough!="boolean")return {ok:false,detail:"strikeThrough: not a boolean"};t.push({localName:"strike",attributes:{val:e.strikeThrough?"1":"0"}});}for(let n of ["subscript","superscript"])if(e[n]!==void 0&&typeof e[n]!="boolean")return {ok:false,detail:`${n}: not a boolean`};if(e.subscript===true&&e.superscript===true)return {ok:false,detail:"subscript and superscript are mutually exclusive"};if(e.highlightColor!==void 0){let n=e.highlightColor,o=typeof n=="string"?uu.find(([r,,a])=>r.toLowerCase()===n.toLowerCase()||a===n.toUpperCase()):void 0;if(n!==null&&!o)return {ok:false,detail:"highlightColor: use an exact Word palette color or null to clear"};t.push({localName:"highlight",attributes:{val:o?.[1]??"none"}});}return {ok:true,value:t}}var Im=31680,Sm=1999,wm=Object.freeze({bold:null,italic:null,underline:null,strikeThrough:null,highlightColor:null,subscript:null,superscript:null,name:null,size:null,color:null});function ke(e,t){if(!e)return null;for(let n of e.attributes)if(n.localName===t)return n.value;return null}function Wo(e){if(!e)return null;let t=ke(e,"val");if(t===null)return true;let n=t.trim().toLowerCase();return !(n==="0"||n==="false"||n==="off"||n==="none")}function Cm(e){if(e===null)return null;let t=e.trim();return /^[0-9a-fA-F]{6}$/.test(t)?`#${t.toUpperCase()}`:null}function Tm(e){if(e===null)return null;let t=Number(e.trim());return !Number.isFinite(t)||t<=0?null:t/2}function _t(e){let t=Qd$1(e??void 0);return t===null?null:Od$1(Md$1(t))}function at(e){if(e.length===0)return null;let t=e[0];if(t===null)return null;for(let n of e)if(n!==t)return null;return t}function hu(e,t,n=Uh){let o=[];for(let r of t)for(let a of si(e,r.paragraphId,r.start,r.end,n))o.push(Rh(a));return o.length===0?wm:{bold:at(o.map(r=>Wo(Sh(r,"b")))),italic:at(o.map(r=>Wo(Sh(r,"i")))),underline:at(o.map(r=>cu(ke(Sh(r,"u"),"val")))),strikeThrough:at(o.map(r=>Wo(Sh(r,"strike")))),highlightColor:at(o.map(r=>pu(ke(Sh(r,"highlight"),"val")))),subscript:at(o.map(r=>gu(r,"subscript"))),superscript:at(o.map(r=>gu(r,"superscript"))),name:at(o.map(r=>{let a=Sh(r,"rFonts"),i=ke(a,"ascii");return i===null||i.length===0?null:i})),size:at(o.map(r=>Tm(ke(Sh(r,"sz"),"val")))),color:at(o.map(r=>Cm(ke(Sh(r,"color"),"val"))))}}var Nm=Object.freeze({left:"Left",start:"Left",center:"Centered",right:"Right",end:"Right",both:"Justified",distribute:"Justified"}),Em=Object.freeze({Left:"left",Centered:"center",Right:"right",Justified:"both"});function yu(e){let t=null;for(let n of e?.children??[]){if(n.kind==="textValue"||n.localName!=="bidi")continue;let o=ke(n,"val");t=o===null||["1","true","on"].includes(o);}return t}function Dm(e){let t=ke(Sh(e,"jc"),"val");return t===null?"Unknown":Nm[t.trim().toLowerCase()]??"Unknown"}function ku(e,t,n){let o=eb(e,t);if(!o||o.kind!=="paragraph")return null;let r=Qh(o),a=Sh(r,"spacing"),i=Sh(r,"ind");return {alignment:Dm(r),style:Ao(e,t,n),firstLineIndent:Lm(i),leftIndent:_t(ke(i,"left")??ke(i,"start")),rightIndent:_t(ke(i,"right")??ke(i,"end")),lineSpacing:_t(ke(a,"line")),spaceBefore:_t(ke(a,"before")),spaceAfter:_t(ke(a,"after")),widowControl:Wo(Sh(r,"widowControl")),readingOrder:yu(r)??n.inheritsRtl(e,o)?"RightToLeft":"LeftToRight"}}function Lm(e){let t=_t(ke(e,"hanging"));if(t!==null&&t>0)return -t;let n=_t(ke(e,"firstLine"));return n!==null?n:t===null?null:-t}function Ko(e,t){if(typeof e!="number"||!Number.isFinite(e))return {ok:false,detail:`${t}: not a measurement`};let n=Pd$1(Nd$1(e));return Math.abs(n)>Im?{ok:false,detail:`${t}: out of range`}:{ok:true,value:n}}function xu(e){let t=mu(e);if(!t.ok)return t;let n=t.value;if(e.bold!==void 0){if(typeof e.bold!="boolean")return {ok:false,detail:"bold: not a boolean"};n.push({localName:"b",...e.bold?{}:{attributes:{val:"0"}}});}if(e.italic!==void 0){if(typeof e.italic!="boolean")return {ok:false,detail:"italic: not a boolean"};n.push({localName:"i",...e.italic?{}:{attributes:{val:"0"}}});}if(e.name!==void 0){let o=e.name;if(typeof o!="string"||o.length===0||o.length>128)return {ok:false,detail:"name: not a font name"};if(!X(o))return {ok:false,detail:"name: not valid XML text"};n.push({localName:"rFonts",attributes:{ascii:o,hAnsi:o}});}if(e.size!==void 0){let o=e.size;if(typeof o!="number"||!Number.isFinite(o)||o<=0)return {ok:false,detail:"size: not a positive number of points"};let r=Math.round(o*2);if(r<1||r>Sm)return {ok:false,detail:"size: out of range"};n.push({localName:"sz",attributes:{val:String(r)}}),n.push({localName:"szCs",attributes:{val:String(r)}});}if(e.color!==void 0){let o=e.color;if(typeof o!="string"||!/^#[0-9a-fA-F]{6}$/.test(o.trim()))return {ok:false,detail:"color: not a #RRGGBB triplet"};n.push({localName:"color",attributes:{val:o.trim().slice(1).toUpperCase()}});}return n.length===0&&e.subscript===void 0&&e.superscript===void 0?{ok:false,detail:"no formatting was asked for"}:{ok:true,value:n}}function bu(e,t,n,o){let r=eb(e,t);if(!r||r.kind!=="paragraph")return {ok:false,detail:"not a paragraph"};let a=Qh(r),i=[],s;if(n.style!==void 0){let A=Oo(n.style,o);if(!A.ok)return {ok:false,detail:A.detail};s=A.styleId,i.push({localName:"pStyle",attributes:{val:A.styleId}});}if(n.alignment!==void 0){let A=Em[n.alignment];if(A===void 0)return {ok:false,detail:`alignment: ${String(n.alignment)}`};i.push({localName:"jc",attributes:{val:A}});}let l=Sh(a,"ind"),d=fu(l),m=false;if(n.firstLineIndent!==void 0){let A=Ko(n.firstLineIndent,"firstLineIndent");if(!A.ok)return A;delete d.firstLine,delete d.hanging,A.value<0?d.hanging=String(-A.value):d.firstLine=String(A.value),m=true;}for(let[A,N,S]of [["leftIndent","left","start"],["rightIndent","right","end"]]){let M=n[A];if(M===void 0)continue;let j=Ko(M,A);if(!j.ok)return j;delete d[S],d[N]=String(j.value),m=true;}m&&i.push({localName:"ind",attributes:d});let c=Sh(a,"spacing"),h=fu(c),f=false;for(let[A,N]of [["spaceBefore","before"],["spaceAfter","after"]]){let S=n[A];if(S===void 0)continue;let M=Ko(S,A);if(!M.ok)return M;if(M.value<0)return {ok:false,detail:`${A}: out of range`};h[N]=String(M.value),f=true;}if(n.lineSpacing!==void 0){let A=Ko(n.lineSpacing,"lineSpacing");if(!A.ok)return A;if(A.value<=0)return {ok:false,detail:"lineSpacing: out of range"};h.line=String(A.value),h.lineRule??="auto",f=true;}if(f&&i.push({localName:"spacing",attributes:h}),n.widowControl!==void 0){if(typeof n.widowControl!="boolean")return {ok:false,detail:"widowControl: not a boolean"};i.push({localName:"widowControl",...n.widowControl?{}:{attributes:{val:"0"}}});}let y=false;if(n.readingOrder!==void 0){if(n.readingOrder!=="RightToLeft"&&n.readingOrder!=="LeftToRight")return {ok:false,detail:`readingOrder: ${String(n.readingOrder)}`};let A=n.readingOrder==="RightToLeft",N=yu(a),S=o.inheritsRtl(e,r,s);(N??S)!==A&&(S===A?y=true:i.push({localName:"bidi",...A?{}:{attributes:{val:"0"}}}));}if(i.length===0&&!y&&n.readingOrder===void 0)return {ok:false,detail:"no formatting was asked for"};let x=ci(e,t),v=ei(x,i),P=y?v.filter(A=>A.localName!=="bidi"):v;return {ok:true,value:P,unchanged:Mm(x,P)}}function Mm(e,t){if(e.length!==t.length)return false;let n=r=>JSON.stringify([r.localName,Object.entries(r.attributes??{}).sort(([a],[i])=>a<i?-1:a>i?1:0)]),o=new Set(e.map(n));return t.every(r=>o.has(n(r)))}function fu(e){let t=Object.create(null);if(!e)return t;for(let n of e.attributes)t[n.localName]=n.value;return t}function zr(e,t){if(t.subscript===void 0&&t.superscript===void 0)return [...e];let n=e.find(r=>r.localName==="vertAlign")?.attributes?.val,o=t.subscript===true?"subscript":t.superscript===true?"superscript":n==="subscript"&&t.subscript===false||n==="superscript"&&t.superscript===false?"baseline":n??"baseline";return ei(e,[{localName:"vertAlign",attributes:{val:o}}])}function gu(e,t){let n=ke(Sh(e,"vertAlign"),"val");return n===null?null:n===t}function vu(){let e=false,t=false,n=false,o=false;return {conflict(r){let a=je(r),i=bn(r),s=r.op==="deleteComment",l=r.op==="updateFieldResult";return a&&(l&&e&&!o||o&&!l)?{message:"field result updates require a batch without other edits; sync document edits before updating fields",detail:r.op}:i&&e||t&&a?{message:"that command commits on its own and cannot share a batch",detail:r.op}:s&&e&&!n||n&&a&&!s?{message:"comment deletions may share a batch only with other comment deletions",detail:r.op}:null},note(r){je(r)&&(e=true,bn(r)&&(t=true),r.op==="deleteComment"&&(n=true),r.op==="updateFieldResult"&&(o=true));},get hasCommands(){return e}}}function Au(e,t,n,o,r){let a=Math.min(r?.limit??2e3,2e3),i=[],s=be(t,e),l=s.length-1;for(let[d,m]of s.entries()){if(a<=0)break;let c=e.projectedText(m,r?.projection??"allMarkup");if(!c)continue;let h=c.findOccurrences(No(o),a,{matchCase:r?.matchCase===true,wholeWord:r?.matchWholeWord===true,...d===0&&t?{from:c.projectedOffset(t.start.offset)}:{},...d===l&&t?{to:c.projectedOffset(t.end.offset)}:{}});for(let f of h.matches){if(d===0&&t&&f.rawStart<t.start.offset||d===l&&t&&f.rawEnd>t.end.offset)continue;let y=n.paragraph(m,e.story);i.push({start:{paragraph:y,offset:f.rawStart},end:{paragraph:y,offset:f.rawEnd}}),a-=1;}}return {ok:true,spans:i}}function Gr(e){return e===void 0?{}:{revision:{author:e.trim(),date:re()}}}function Xr(e,t,n){return {op:"setContentControlValue",controlId:e,value:t,...Gr(n)}}function Ou(e,t,n){let{start:o,end:r}=t;if(o.paragraphId!==r.paragraphId)return o;let a=eb(e,o.paragraphId);if(!a||a.kind!=="paragraph")return o;let i=Cj(a,o.offset,r.offset,n.trim());return {...o,offset:r.offset-i}}var Ru=5e4;function $o(e,t,n){if("body"in e){let o=le(e.body,"body",t,n);return o.ok?{ok:true,reads:o.value}:{ok:false,code:o.code,message:"that handle does not name a body",detail:o.detail}}return t.resolve(e.document,"document")?n.body?{ok:true,reads:n.body}:{ok:false,code:"document-unavailable",message:"this host holds no document"}:{ok:false,code:"invalid-handle",message:"that handle does not name a document",detail:"document"}}function Fm(e,t){if(t.root.kind!=="textValue"&&Ol$1({...t.part,root:t.root}).length===0)return [];let n=e.op,o=Tn(t.part),r=()=>Ol$1(t.part).map(l=>l.node.id),a=l=>{let d=[];for(let m=0;m<l.length;m+=Ru)d.push({op:n,siteNodeIds:l.slice(m,m+Ru)});return d};if(t.story.kind==="textbox"){let l=t.root.id,d=o.copy.size?r().filter(m=>o.copy.has(m)&&o.story.get(m)===l):[];return [{op:n,scopeRootId:l},...a(d)]}if(_e(t.story))return [{op:n,scopeRootId:t.root.id}];if(o.story.size===0)return [{op:n}];let i=r(),s=i.filter(l=>!o.story.has(l));return s.length===i.length?[{op:n}]:a(s)}function Pu(e,t,n){let o=$o({op:"acceptAllRevisions",body:e.body},t,n);if(!o.ok)return o;if(e.revisions!==void 0&&!Array.isArray(e.revisions))return {ok:false,code:"unsupported-content",message:"invalid revision batch"};let r=e.revisions===void 0?void 0:[];r===void 0&&!_e(o.reads.story)&&Tn(o.reads.part).story.size>0&&(r=Ft(o.reads).map(ml$1));for(let i of e.revisions??[]){let s=t.resolve(i,"revision");if(!s||s.kind!=="revision"||Y(s.story)!==Y(o.reads.story))return {ok:false,code:"invalid-handle",message:"revision does not belong to this story"};r.push(`revision-${s.revisionId}`);}let a=_e(o.reads.story)?o.reads.root:void 0;return {ok:true,reads:o.reads,keys:r,scopeRoot:a}}function Bm(e,t,n){let o=Pu(e,t,n);if(!o.ok)return o;if(!["accept","reject"].includes(e.action))return {ok:false,code:"unsupported-content",message:"invalid revision batch"};let r=Aa(o.reads.part,e.action,o.keys,o.scopeRoot,e.revisions===void 0?void 0:{explicit:true});return {ok:true,reads:o.reads,...r}}function Hm(e,t,n){let o={author:e.author,...e.date===void 0?{}:{date:e.date}};if(typeof e.author!="string"||e.date!==void 0&&typeof e.date!="string"||hm$1(o)||e.authors!==void 0&&(e.revisions!==void 0||!Array.isArray(e.authors)||e.authors.some(s=>typeof s!="string")))return {ok:false,code:"unsupported-content",message:"author must be nonblank text, date an xsd:dateTime, and authors a list without revisions"};let r=Pu(e,t,n);if(!r.ok)return r;let a=e.revisions===void 0?_m(r,n.package):r.keys,i=im$1(r.reads.part,o,a,r.scopeRoot,e.authors);return {ok:true,reads:r.reads,...i}}function _m(e$1,t){if(!t)return e$1.keys;let{part:n}=e$1.reads,o=e$1.scopeRoot,r=cm$1(o&&o.kind!=="textValue"?{...n,root:o}:n),a=new Set(g$1(r,e(t)).map(ml$1));return a.size===0?e$1.keys:(e$1.keys??r.map(ml$1)).filter(i=>!a.has(i))}function jm(e,t,n,o){let r=$o({op:"acceptAllRevisions",body:e},n,o);if(!r.ok)throw new Error("resolved story disappeared");let a=Mr(r.reads,o.package).length;return {kind:"revisionBatch",result:{...t,remaining:a}}}function Iu(e,t,n,o,r){if("scope"in e||"key"in e)return Yd(e,t,n,o,r);if(e.op==="setRevisionAuthorBatch"){let f=Hm(e,t,n);if(!f.ok)return {ok:false,error:{code:f.code,message:f.message}};let y=o(f.reads);return y||{ok:true,kind:"command",story:f.reads.story,ops:f.ops,answer:x=>{let v=$o({op:"acceptAllRevisions",body:e.body},t,x);if(!v.ok)throw new Error("reattributed story disappeared");let P=f.finish(v.reads.part),A="revision-";return t.retargetRevisions(f.reads.story,P.updated.flatMap(({previousKey:N,key:S})=>N.startsWith(A)&&S.startsWith(A)?[{from:N.slice(A.length),to:S.slice(A.length)}]:[])),{kind:"revisionAuthors",result:P}}}}if(e.op==="resolveRevisionBatch"){let f=Bm(e,t,n);if(!f.ok)return {ok:false,error:{code:f.code,message:f.message}};let y=o(f.reads);return y||{ok:true,kind:"command",story:f.reads.story,ops:f.ops,answer:x=>jm(e.body,f.result,t,x)}}let a=$o(e,t,n);if(!a.ok)return {ok:false,error:{code:a.code,message:a.message,detail:a.detail}};let i=o(a.reads);if(i)return i;if(r.whole||r.decided.size>0)return {ok:false,error:{code:"conflicting-operations",message:"an earlier decision in this batch resolved changes"}};let s=_e(a.reads.story)?a.reads.root:void 0,l=e.op==="acceptAllRevisions"?"accept":"reject",d=s&&s.kind!=="textValue"?s:void 0,m=d?{...a.reads.part,root:d}:a.reads.part;if(Al$1(m,Ol$1(m),l).size>0&&Aa(a.reads.part,l,void 0,d,{countRemaining:false}).result.skipped.some(f=>f.reason==="retained-structure"))return {ok:false,error:{code:"unsupported-revision",message:"a tracked row must stay to keep the nested table inside it",detail:"retained-structure:nested-table"}};let c=Fm(e,a.reads),h=jm$1(a.reads.part)?mm$1(a.reads.part,c):null;return h?{ok:false,error:{code:"transaction-refused",message:"a content control keeps a change in that decision",detail:h}}:(r.whole=true,{ok:true,kind:"command",story:a.reads.story,ops:c,answer:()=>({kind:"applied"})})}var Vm=/[\r\n\u2028\u2029]/u,wu=Object.freeze({kind:"applied"});function jt(e,t,n){return {ok:false,error:Object.freeze(n===void 0?{code:e,message:t}:{code:e,message:t,detail:n})}}function Yr(e,t){return jt("unsupported-content",e==="author"?"a comment records who wrote it":e==="date"?"a comment date must be a valid ISO-8601 instant":t==="reply"?"a reply says something":"a comment says something",e)}function qr(e){return T(e.author)?Yr("author",e.kind):U(e.text)?Yr("text",e.kind):typeof e.text=="string"&&Vm.test(e.text)?jt("unsupported-content",e.kind==="reply"?"a reply is one paragraph in this slice":"a comment is one paragraph in this slice","text"):W$1(e.date)?Yr("date",e.kind):null}function Jr(e){if(e===void 0)return re();let t=V(e);return t.ok?t.value:re()}function Su(e,t){let n=eb(e.part,t);for(;n;){if(n.kind==="tableCell"||n.kind!=="textValue"&&n.namespaceUri===pa&&n.localName==="tc")return n.id;n=fb(e.part,n.id);}return null}function Cu(e,t,n,o){let r=qr({author:e.author,text:e.text,date:e.date,kind:"comment"});if(r)return r;let a=W(e.span,t,n);if(!a.ok)return jt(a.code,"that span is not a place",a.detail);if(a.value===null)return jt("invalid-handle","an empty story has no comment anchor");let i=ee(e.span,t,n);if(!i.ok)return jt(i.code,"that span is not a place",i.detail);if(i.value.story.kind==="textbox")return jt("unsupported-content","a comment cannot be anchored in a text box");let s=a.value;if(Su(i.value,s.start.paragraphId)!==Su(i.value,s.end.paragraphId))return jt("unsupported-content","a comment range cannot cross a table-cell boundary");let l=o(i.value);if(l)return l;let d=Jr(e.date);return {ok:true,kind:"commentWrite",write:{kind:"create",anchor:{paragraphId:s.start.paragraphId,start:s.start.offset,end:s.end.offset,...s.end.paragraphId===s.start.paragraphId?{}:{endParagraphId:s.end.paragraphId}},text:e.text,author:e.author,date:d},story:i.value.story,answer:(c,h)=>h===void 0?wu:{kind:"handle",handle:t.comment(h,i.value.story)}}}function Tu(e,t,n){let o=n(t);if(o)return o;let r=t.story;return {ok:true,kind:"commentWrite",write:{kind:"delete",commentId:e.id,...e.parentId===void 0?{}:{parentCommentId:e.parentId},...r.kind==="note"?{noteId:r.noteId}:{}},story:r,answer:()=>wu}}var Um=new Set(["unlocked","sdtLocked","contentLocked","sdtContentLocked"]),Km=4096,Nu=64;function Eu(e){if(e===void 0)return {ok:true,value:null};if(typeof e!="object"||e===null)return {ok:false,field:"payload"};let t=e;for(let n of ["namespaceUri","rootLocalName","nodeId"]){let o=t[n];if(typeof o!="string"||o.length===0||o.length>Km)return {ok:false,field:n}}return typeof t.label!="string"||t.label.length>fa?{ok:false,field:"label"}:typeof t.data!="string"||t.data.length===0||t.data.length>ea$1?{ok:false,field:"data"}:{ok:true,value:{namespaceUri:t.namespaceUri,rootLocalName:t.rootLocalName,nodeId:t.nodeId,label:t.label,data:t.data}}}function Du(e){let t=e.at!==void 0,n=e.span!==void 0;return t===n?{message:"a custom node goes at a position or over a span, not both",detail:t?"at+span":"no-place"}:typeof e.tag!="string"||e.tag.length===0?{message:"a custom node carries its identity in its tag",detail:"tag"}:e.tag.length>Nu?{message:`w:tag caps at ${String(Nu)} characters; a longer payload belongs in the store`,detail:"tag"}:typeof e.text!="string"||e.text.length===0?{message:"a custom node shows some text",detail:"text"}:e.lock!==void 0&&!Um.has(e.lock)?{message:"that is not a lock",detail:String(e.lock)}:null}function Lu(e,t,n,o){return {paragraphId:t.paragraphId,offset:t.offset,...n.offset>t.offset?{replaceUntil:n.offset}:{},tag:e.tag,text:e.text,...e.title===void 0?{}:{alias:e.title},...e.lock===void 0||e.lock==="unlocked"?{}:{lock:e.lock},...o===null?{}:{payload:o}}}function Mu(e,t,n){if(e.span){let r=W(e.span,t,n);return r.ok?r.value?r.value.start.paragraphId!==r.value.end.paragraphId?{code:"unsupported-content",message:"a custom node wraps text inside one paragraph",detail:"multi-paragraph"}:{range:r.value}:{code:"invalid-offset",message:"that story holds nothing to wrap",detail:"empty-story"}:{code:r.code,message:"that span is not a place",detail:r.detail}}let o=Qt(e.at,t,n);return o.ok?{range:{start:o.value,end:o.value}}:{code:o.code,message:"that is not a place",detail:o.detail}}var Wm=16,$m=64,Ln=e=>b("invalid-handle",e,tt),ce=Object.freeze({kind:"applied"});function Qr(e){let{runPropertyEdits:t,mergedParagraphMarkProperties:n}=Wl(()=>e.reads.package?ud$1(e.reads.package)?.root??null:null,()=>e.reads.package?Bf(e.reads.package)?.root??null:null,()=>e.displayMode??"proposed"),{handles:o,capabilities:r}=e,a=e.reads,i=new Map,s=new Map,l=p=>{let k=`${Y(p.story)}:${p.root.id}`,R=i.get(k);if(R)return R;let I=new Map,T=p.paragraphIds.map(H=>{let u={id:H};return I.set(H,u),u}),D={externalCreatedCount:0,wholesale:false,reads:p,order:T,slotById:I,created:[],restructured:new Set,touched:new Set,textEdits:new Eo,formatted:new Set,selected:new Set,retargets:[]};return i.set(k,D),D},d=[],m=vu(),c=false,h=null,f=false,y=p=>h===null?(h=p,null):h===p?null:b("conflicting-operations","one batch writes into one story",`${Y(h.reads.story)} then ${Y(p.reads.story)}`),x=p=>y(l(p)),v=x,P=Kd(),A=p=>{let k=a.package;return k===null?null:_d(k,p)},N=p=>{let k=o.resolve(p,"comment");if(!k||k.kind!=="comment")return {ok:false,planned:b("invalid-handle","that handle does not name a comment","comment")};let R=a.story(k.story);if(!R)return {ok:false,planned:b("invalid-handle","that story is not in this document")};let T=A(R)?.byId(k.commentId)??null;return T?{ok:true,reads:R,item:T}:{ok:false,planned:Ln("this document no longer holds that comment")}},S=p=>{let k=o.resolve(p,"revision");if(!k||k.kind!=="revision")return {ok:false,planned:b("invalid-handle","that handle does not name a tracked change","revision")};let R=a.story(k.story);if(!R)return {ok:false,planned:b("invalid-handle","that story is not in this document")};let I=Nn(R,null).find(T=>T.id===k.revisionId)??null;return I?{ok:true,reads:R,item:I}:{ok:false,planned:Ln("this document no longer holds that tracked change")}},M=(p,k)=>{let R=p.rawText(k.start.paragraphId),I=p.rawText(k.end.paragraphId);if(R===null||I===null)return null;let T={story:p.story,paragraphId:k.start.paragraphId,index:p.indexOf(k.start.paragraphId),offset:Math.min(k.start.offset,R.length)},D={story:p.story,paragraphId:k.end.paragraphId,index:p.indexOf(k.end.paragraphId),offset:Math.min(k.end.offset,I.length)};return Q({start:T,end:D})},j=(p,k)=>p.order.indexOf(k),J=(p,k)=>p.selected.has(k)?b("conflicting-operations","this batch selects a paragraph it also edits",k):null,C=(p,k)=>{let R=J(p,k);return R||(p.restructured.has(k)||p.touched.has(k)?b("conflicting-operations","another operation in this batch already changes that paragraph",k):(p.restructured.add(k),p.touched.add(k),null))},z=(p,k)=>{let R=J(p,k);return R||(p.restructured.has(k)||p.textEdits.has(k)?b("conflicting-operations","another operation in this batch restructures that paragraph",k):(p.touched.add(k),null))},K=(p,k,R)=>{let I=`${R}:${k}`;if(p.formatted.has(I))return b("conflicting-operations","another operation in this batch already writes that formatting",k);let T=z(p,k);return T||(p.formatted.add(I),null)},G=(p,k)=>{let R={id:null};return p.order.splice(k,0,R),p.created.push(R),R},Q=p=>Ae(p,o),ae=p=>p===null?null:a.story(p.start.story),X=p=>p===void 0||p==="allMarkup"||p==="original"||p==="model",ue=(p,k,R,I)=>{if(!X(I?.projection))return b("unsupported-content","unknown text projection","projection");if(I?.matchWildcards===true)return b("unsupported-capability","wildcard search is not implemented","matchWildcards");if(I?.ignorePunct===true)return b("unsupported-capability","ignoring punctuation is not implemented","ignorePunct");if(I?.ignoreSpace===true)return b("unsupported-capability","ignoring whitespace is not implemented","ignoreSpace");if(!xa(R))return b("unsupported-content","that is not a query this host will scan for","text");let T=I?.limit;if(T!==void 0&&(!Number.isInteger(T)||T<0))return b("invalid-offset","limit must be a non-negative integer",String(T));let D=Au(p,k,o,R,I);return D.ok?_({kind:"spans",spans:D.spans}):b("invalid-offset","projection mapping failed",D.paragraphId)},fe=(p,k,R,I=false)=>{let T=k.start.paragraphId,D=p.textEdits.has(T)?J(p,T):p.touched.has(T)?b("conflicting-operations","text edits cannot share a paragraph with other edits",T):z(p,T);return D||Gl(p.textEdits,k,R,o,I)},Oe=(p,k,R,I=false)=>{if(typeof R!="string"||ht.test(R))return b("unsupported-content","insertText needs text without paragraph marks","text");let T=It(p.reads.part,k.paragraphId,k.offset,k.offset,R);if(T)return T;let D=y(p);if(D)return D;let H=e.replacementLanding?.(k.paragraphId,k.offset,k.offset),u=H!=null,g=!u&&zl(p.reads.part,k.paragraphId,k.offset,R);if(g)return g;if(!u&&!f&&Nr(p.reads.part,k.paragraphId,k.offset))return fe(p,{start:k,end:k},R,I);let O=C(p,k.paragraphId);if(O)return O;let w=tn(k.paragraphId,k.offset,R),E=f&&u?{...k,offset:H}:k;return {ok:true,kind:"command",ops:w,story:p.reads.story,answer:()=>({kind:"span",span:Q({start:E,end:{...E,offset:E.offset+R.length}})})}},we=(p,k,R)=>{let I=p.reads;if(typeof R!="string")return b("unsupported-content","replaceSpan needs text","text");if(ht.test(R))return b("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let T=be(k,I),D=k.start.paragraphId,H=[],u=T.length===1?k.end.offset:k.start.offset,g=It(I.part,D,k.start.offset,u,R);if(g)return g;let O=y(p);if(O)return O;let w=ud(I,k,R,()=>({kind:"span",span:Q(k)}));if(w)return C(p,D)??w;let E=T.length===1?k.end.offset:(I.rawText(D)??"").length,F=e.replacementLanding?.(D,k.start.offset,E);if(T.length===1&&F==null&&!f&&Nr(I.part,D,k.start.offset))return fe(p,k,R);if(T.length===1){let L=C(p,D);if(L)return L;if(F==null)return Yl(I.part,k,R,o);k.end.offset>k.start.offset&&H.push({op:"deleteText",paragraphId:D,start:k.start.offset,end:k.end.offset});}else {for(let te of T){let Fe=C(p,te);if(Fe)return Fe}let L=k.end.paragraphId,Z=(I.rawText(D)??"").length;k.start.offset<Z&&H.push({op:"deleteText",paragraphId:D,start:k.start.offset,end:Z}),k.end.offset>0&&H.push({op:"deleteText",paragraphId:L,start:0,end:k.end.offset});for(let te of T.slice(1,-1))H.push({op:"deleteBlock",blockId:te});H.push({op:"joinParagraphs",firstId:D,secondId:L});for(let te of T.slice(1)){let Fe=p.slotById.get(te);Fe&&p.order.splice(j(p,Fe),1);}}let U=F??k.start.offset;H.push(...tn(D,U,R));let ne={...k.start,paragraphId:D,offset:U},me=()=>({kind:"span",span:Q({start:ne,end:{...ne,offset:ne.offset+R.length}})});return {ok:true,kind:"command",ops:H,story:p.reads.story,answer:me}},xe=(p,k)=>{let R=p.reads;if(typeof k!="string")return b("unsupported-content","replaceSpan needs text","text");if(ht.test(k))return b("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let I=R.blocks,T=I.filter(L=>L.removable),D=I.filter(L=>!L.removable).flatMap(L=>L.paragraphIds),H=D.length===0?T.find(L=>L.kind==="paragraph"):void 0;if(!H&&D.length===0)return b("invalid-offset","that story holds no paragraph this host can write into","no-top-level-paragraph");let u=y(p);if(u)return u;for(let L of R.paragraphIds){let Z=C(p,L);if(Z)return Z}let g=[],O=(H?[H.id]:[...D]).sort((L,Z)=>R.indexOf(L)-R.indexOf(Z)),w=O[0],E=(R.rawText(w)??"").length;for(let L of O){let Z=(R.rawText(L)??"").length;Z>0&&g.push({op:"deleteText",paragraphId:L,start:0,end:Z});}for(let L of T)L.id!==H?.id&&g.push({op:"deleteBlock",blockId:L.id});let F=e.replacementLanding?.(w,0,E)??0,U=It(R.part,w,0,E,k);if(U)return U;g.push(...tn(w,F,k));for(let L of T)if(L.id!==H?.id)for(let Z of L.paragraphIds){let te=p.slotById.get(Z);te&&p.order.splice(j(p,te),1);}let ne={story:R.story,paragraphId:w,index:R.indexOf(w),offset:F},me=()=>({kind:"span",span:Q({start:ne,end:{...ne,offset:F+k.length}})});return {ok:true,kind:"command",ops:g,story:R.story,answer:me}},De=(p,k)=>{if(!Array.isArray(k)||k.length<1||k.length>1e4||k.some(I=>typeof I!="string"||ht.test(I))||!Aj(k))return b("unsupported-content","replaceStoryBlocks needs 1-10000 valid XML text strings without paragraph marks","paragraphs");let R=y(p);if(R)return R;for(let I of p.reads.paragraphIds){let T=C(p,I);if(T)return T}p.order.splice(0,p.order.length);for(let I=0;I<k.length;I+=1)G(p,I);return {ok:true,kind:"command",ops:[{op:"replaceStoryBlocks",storyRootId:p.reads.root.id,paragraphs:k}],story:p.reads.story,answer:()=>ce}},ze=(p,k,R,I)=>{let T=p.reads,D=_r(I);if(D)return D;let H=y(p);if(H)return H;let u=C(p,k.paragraphId);if(u)return u;let g=p.slotById.get(k.paragraphId);if(!g)return b("invalid-handle","that paragraph is not in the body");let O=(T.rawText(k.paragraphId)??"").length,w=R==="after"?O:0,E=It(T.part,k.paragraphId,w,w,I);if(E)return E;let F=[];R==="after"?(F.push(...tn(k.paragraphId,O,I)),F.push({op:"splitParagraph",paragraphId:k.paragraphId,offset:O})):(F.push(...tn(k.paragraphId,0,I)),F.push({op:"splitParagraph",paragraphId:k.paragraphId,offset:I.length}));let U=G(p,j(p,g)+1);R==="before"&&p.retargets.push({from:k.paragraphId,slot:U});let ne=()=>{let me=R==="after"?U.id:k.paragraphId;return me===null?ce:{kind:"handle",handle:o.paragraph(me,T.story)}};return {ok:true,kind:"command",ops:F,story:T.story,answer:ne}},it=(p,k,R,I,T)=>{let D=p.reads;if(!Array.isArray(R)||R.length===0)return b("unsupported-content","split needs at least one delimiter","delimiters");if(R.length>Wm)return b("unsupported-content","too many delimiters",String(R.length));for(let L of R){if(typeof L!="string"||L.length===0)return b("unsupported-content","a delimiter must be a non-empty string","delimiters");if(L.length>$m)return b("unsupported-content","that delimiter is too long","delimiters")}let H=y(p);if(H)return H;let u=C(p,k.paragraphId);if(u)return u;let g=p.slotById.get(k.paragraphId);if(!g)return b("invalid-handle","that paragraph is not in the body");let{text:O,occurrences:w}=Jl(D,k.paragraphId,R),E=[],F=[],U=[];if(w.length===0)U.push(O);else if(I){for(let te of [...w].reverse())E.push({op:"deleteText",paragraphId:k.paragraphId,start:te.start,end:te.start+te.length});let L=0,Z=0;for(let te of w){let Fe=te.start-L;F.push(Fe),U.push(O.slice(Z,te.start)),Z=te.start+te.length,L+=te.length;}U.push(O.slice(Z));}else {let L=0;for(let Z of w){let te=Z.start+Z.length;F.push(te),U.push(O.slice(L,te)),L=te;}U.push(O.slice(L));}F.length>0&&E.push({op:"splitParagraphMany",paragraphId:k.paragraphId,offsets:F});let ne=[g];for(let L=0;L<F.length;L+=1)ne.push(G(p,j(p,g)+1+L));let me=L=>{let Z=L.story(D.story),te=[];return ne.forEach((Fe,ac)=>{let Zo=Fe.id;if(Zo===null)return;let er=Z?.rawText(Zo)??U[ac]??"",[ic,sc]=T?ed(er,0,er.length):[0,er.length],da=o.paragraph(Zo,D.story);te.push({start:{paragraph:da,offset:ic},end:{paragraph:da,offset:sc}});}),{kind:"spans",spans:te}};return {ok:true,kind:"command",ops:E,story:D.story,answer:me}},V=(p,k)=>{let R=y(p);if(R)return R;let I=C(p,k.paragraphId);if(I)return I;let T=p.slotById.get(k.paragraphId);return T&&p.order.splice(j(p,T),1),{ok:true,kind:"command",ops:[{op:"deleteBlock",blockId:k.paragraphId}],story:p.reads.story,answer:()=>ce}},$=(p,k,R)=>{let I=p.reads,T=I.part,D=y(p);if(D)return D;let H=xu(R??{});if(!H.ok)return b("unsupported-content","that is not formatting this host writes",H.detail);let u=[];for(let g of mt(k,I)){if(g.end<=g.start&&!g.whole)continue;let O=K(p,g.paragraphId,"runs");if(O)return O;for(let w of t(T,g.paragraphId,g.start,g.end,H.value.filter(E=>E.localName!=="vertAlign"),e.displayMode))u.push({op:"setRunProperties",paragraphId:g.paragraphId,start:w.start,end:w.end,properties:zr(w.properties,R),...w.targetRunIds?{targetRunIds:w.targetRunIds}:{}});g.whole&&u.push({op:"setParagraphMarkProperties",paragraphId:g.paragraphId,properties:zr(n(T,g.paragraphId,H.value.filter(w=>w.localName!=="vertAlign")),R)});}return u.length===0?b("invalid-offset","that range covers no characters to format","collapsed-range"):{ok:true,kind:"command",ops:u,story:I.story,answer:()=>ce}},ge=(p,k,R)=>{let I=p.reads,T=I.part,D=y(p);if(D)return D;let H=Oo(R,I.styles());if(!H.ok)return b("unsupported-content","that is not a style this document has",H.detail);let u={localName:"pStyle",attributes:{val:H.styleId}},g=[];for(let O of be(k,I)){let w=K(p,O,"paragraph");if(w)return w;g.push({op:"setParagraphProperties",paragraphId:O,properties:ei(ci(T,O),u)});}return g.length===0?b("invalid-offset","that story holds no paragraph to style","empty-story"):{ok:true,kind:"command",ops:g,story:I.story,answer:()=>ce}},ie=(p,k,R)=>{let I=p.reads,T=I.part,D=y(p);if(D)return D;let H=bu(T,k.paragraphId,R??{},I.styles());if(!H.ok)return b("unsupported-content","that is not paragraph formatting this host writes",H.detail);let u=K(p,k.paragraphId,"paragraph");return u||{ok:true,kind:"command",ops:H.unchanged?[]:[{op:"setParagraphProperties",paragraphId:k.paragraphId,properties:H.value}],story:I.story,answer:()=>ce}},Le=(p,k)=>{let R=a.body;if(!R)return b("document-unavailable","this host holds no document right now");let I=a.sections();if(!I[p])return b("invalid-handle","that section is not in this document");let D=Ms(k);if(!D.ok)return b("unsupported-content",D.reason,D.detail);let H=Ql(R,I,p);if(H===null)return b("unsupported-content","that section holds no paragraph to address it by","no-anchor");let u=l(R),g=y(u);return g||{ok:true,kind:"command",ops:[{op:"setSectionProperties",...D.value,anchorParagraphId:H}],story:ve,answer:()=>ce}},Bn=(p,k)=>({ok:true,kind:"command",ops:[{op:"deleteNote",noteKind:p,noteId:k}],story:ve,lifecycle:true,answer:()=>ce}),st=p=>{let k=o.resolve(p,"list");if(!k||k.kind!=="list")return b("invalid-handle","that handle does not name a list","list");let R=a.story(k.story);if(!R)return b("invalid-handle","that story is not in this document");let I=Ht(R).find(T=>T.numId===k.numId);return I?{ok:true,plan:l(R),list:I}:Ln("this story numbers nothing with that list")},Jo=p=>{if(typeof p!="object"||p===null)return b("invalid-handle","that is not a scope a control lives in","scope");let k=p;if("body"in p){let R=le(k.body,"body",o,a);return R.ok?{reads:R.value,node:R.value.root}:b(R.code,"that handle does not name a body",R.detail)}if("contentControl"in p){let R=Ge(k.contentControl);return "control"in R?{reads:R.reads,node:R.node}:R}return b("invalid-handle","that is not a scope a control lives in","scope")},Ge=p=>{let k=o.resolve(p,"contentControl");if(!k||k.kind!=="contentControl")return b("invalid-handle","that handle does not name a content control","contentControl");let R=a.story(k.story);if(!R)return b("invalid-handle","that story is not in this document");let I=il(R,k.nodeId),T=sl(R,k.nodeId);return !I||!T?Ln("this document no longer holds that content control"):{reads:R,control:I,node:T}},nc=(p,k,R)=>{if(!Number.isInteger(R)||R<0||R>sn)return b("invalid-offset",`a list level is 0 to ${String(sn)}`,String(R));let I=Dn(p.reads,k);if(!I)return b("unsupported-content","that paragraph is not in a list",k);if(!a.package||!En(a.package,I.numId,R))return b("unsupported-content","list level is not defined; configure that level first",k);let T=y(p);if(T)return T;let D=K(p,k,"paragraph");return D||{ok:true,kind:"command",ops:[{op:"setListLevel",paragraphId:k,level:R}],story:p.reads.story,answer:()=>ce}},oc=(p,k,R,I)=>{if(R!=="start"&&R!=="end")return b("unknown-operation","a list takes an item at its start or its end",String(R));let T=p.reads,D=R==="start"?k.paragraphIds[0]:k.paragraphIds[k.paragraphIds.length-1];if(D===void 0)return b("invalid-handle","that list holds no paragraph");let H={story:T.story,paragraphId:D,index:T.indexOf(D)};return ze(p,H,R==="start"?"before":"after",I)},ia=(p,k)=>{if(k.start.paragraphId!==k.end.paragraphId)return null;for(let R of gl(p,k.start.paragraphId))if(R.start<=k.start.offset&&R.end>=k.end.offset)return R;return null},rc=(p,k,R)=>{if(typeof R!="string")return b("unsupported-content","a hyperlink target is a string","target");let I=p.reads,T=ia(I,k),D=k.start.paragraphId===k.end.paragraphId&&k.start.offset===k.end.offset,H=T&&(k.start.offset!==T.start||k.end.offset!==T.end),u=H?{range:{start:k.start.offset,end:k.end.offset}}:{};if(H){let L=I.node(T.paragraphId),Z=L?.kind==="paragraph"?L.children.find(te=>te.id===T.id):void 0;if(D||!Z||!Ok(Z)||L?.kind!=="paragraph"||!L.children.some(te=>te.id===T.id))return b("unsupported-capability","partial hyperlink edits require ordinary text in a paragraph")}if(R.length===0){if(!T)return b("unsupported-content","that text is not a link","no-link");let L=y(p);if(L)return L;let Z=z(p,T.paragraphId);return Z||{ok:true,kind:"command",ops:[{op:"removeHyperlink",linkId:T.id,...u}],story:I.story,answer:()=>ce}}let g={},O=null;if(R.startsWith("#")){let L=R.slice(1);if(L.length===0||!wo(I,L))return b("unsupported-content","this document declares no such bookmark",R);g={anchor:L};}else {if(dj(R)===null)return b("unsupported-content","this engine will not author that target","target");O=R;}let w=y(p);if(w)return w;let E=L=>O===null?{ok:true,kind:"command",ops:[L(g)],story:I.story,answer:()=>ce}:{ok:true,kind:"command",ops:[],relate:{url:O,ops:Z=>[L({relationshipId:Z})]},story:I.story,answer:()=>ce};if(T){let L=z(p,T.paragraphId);return L||E(Z=>({op:"setHyperlinkTarget",linkId:T.id,...u,...Z}))}if(D)return b("unsupported-content","a link with no text has nothing to click","collapsed");if(k.start.paragraphId!==k.end.paragraphId)return b("unsupported-content","a link lives inside one paragraph","crosses-paragraph-mark");let F=z(p,k.start.paragraphId);if(F)return F;let{styleId:U,edit:ne}=du(a.package,{add:!e.collaborative||e.setupOutsideUndo===true,createPart:!e.collaborative}),me=E(L=>({op:"insertHyperlink",paragraphId:k.start.paragraphId,start:k.start.offset,end:k.end.offset,...L,...U===null?{}:{styleId:U}}));return ne&&me.ok&&me.kind==="command"?{...me,packageEdits:[ne]}:me},sa=(p,k,R)=>{let I=p.reads;if(!r.selection||!e.select)return b("unsupported-capability","this host has no reader to move","selection");if(R!=="select"&&R!=="start"&&R!=="end")return b("unknown-operation","that is not a selection mode",String(R));let T=e.selectRefusal?.(I.story,k.start.paragraphId);if(T)return b("unsupported-capability",T,"selection");let D=be(k,I);for(let H of D)if(p.touched.has(H))return b("conflicting-operations","this batch edits a paragraph the selection covers",H);for(let H of D)p.selected.add(H);return d.push({range:k,mode:R}),{ok:true,kind:"query",value:ce}},la=p=>Al(p,o,a),Qo=(p,k)=>{let R=Jd(p,u=>Qo(u,k));if(R)return R;let I=ws(p,e,u=>Qr({...e,reads:u}));if(I)return k&&I.ok&&I.kind==="command"?b("unsupported-content","header/footer creation cannot be tracked"):I;let T=Td(p,{trackingAuthor:k,trackedRangeReplacement:e.trackedRangeReplacement,handles:o,reads:a,admitWrite:(u,g,O,w=[])=>{let E=l(u),F=y(E);if(F)return F;for(let U of O){E.touched.has(U)||E.restructured.delete(U);let ne=C(E,U);if(ne)return ne}for(let U of w)E.restructured.add(U);return E.externalCreatedCount+=g,null}});if(T)return T;let D=Qd(p,{handles:o,reads:a,trackingAuthor:k,planJoined:u=>{f=true;try{return Qo(u,k)}finally{f=false;}},reserve:(u,g)=>{let O=h,w=O?.slotById.get(u);if(!O||!w)return null;let E=j(O,w)+1;return Array.from({length:g},(F,U)=>G(O,E+U))}});if(D)return D;let H=k!==void 0;if(H){let u=bd(p,k,o,a);if("ok"in u)return u;p=u;}if(pl(p))return ml(p,o,a);if(Id(p))return Sd(p,o,a,(u,g,O)=>{let w=l(u);return y(w)??(O?null:C(w,g))},e.fieldPageContext,k);switch(p.op){case "getShapes":case "getShape":case "getShapeBody":return tl(p,o,a);case "getTextRanges":case "expandSpan":case "getReviewedText":return rl(p,o,a);case "getInlinePictures":case "getInlinePicture":case "setInlinePicture":case "deleteInlinePicture":case "insertInlinePicture":return Nd(p,o,a,(u,g)=>{let O=l(u);return y(O)??C(O,g)});case "getBookmarks":case "getBookmarkName":case "getBookmarkNames":case "getBookmarkRangeByName":case "insertBookmark":case "deleteBookmark":return Ol(p,o,a,{admit:bl(l,y,C),pinned:()=>h?.reads.story??null});case "insertBreak":return qd(p,o,a,(u,g,O)=>{let w=l(u),E=y(w)??C(w,g);return E||(w.externalCreatedCount+=O),E},k);case "startNewList":case "attachToList":case "detachFromList":case "setListLevelFormat":return ru(p,o,a,(u,g,O)=>{let w=l(u);return y(w)??K(w,g,O?`list:${O.numId}:${O.level}`:"paragraph")},k);case "compareFromBase64":return Tl(p,{reads:a,engine:e.compareDocuments,collaborative:e.collaborative??false,pin:()=>{let u=l(a.body),g=y(u);return g||(u.wholesale=true),g}});case "removeDocumentInformation":case "getDocumentProperty":case "setDocumentProperties":case "getStyles":case "getSections":case "getPageSetup":return Hl(p,{reads:a,handles:o,pin:()=>y(l(a.body)),supportsPartCreation:!e.collaborative});case "getDocument":return _({kind:"handle",handle:o.document()});case "getBody":return o.resolve(p.document,"document")?a.body?_({kind:"handle",handle:o.body(ve)}):b("document-unavailable","this host holds no document right now"):b("invalid-handle","that handle does not name a document","document");case "getParagraphs":{let u=le(p.body,"body",o,a);return u.ok?_({kind:"handles",handles:u.value.paragraphIds.map(g=>o.paragraph(g,u.value.story))}):b(u.code,"that handle does not name a body",u.detail)}case "getRange":{let u=W(p.span,o,a);if(!u.ok)return b(u.code,"that span is not a place",u.detail);if(!u.value)return b("invalid-offset","empty story");if(!["Whole","Content","Start","End"].includes(p.location))return b("unsupported-content","unsupported range location");let g=u.value,O=p.location==="Start"?{start:g.start,end:g.start}:p.location==="End"?{start:g.end,end:g.end}:g;return _({kind:"span",span:Ae(O,o)})}case "getSpanParagraphs":{let u=W(p.span,o,a);if(!u.ok)return b(u.code,"that span is not a place",u.detail);let g=ee(p.span,o,a);return g.ok?_({kind:"handles",handles:be(u.value,g.value).map(O=>o.paragraph(O,g.value.story))}):b(g.code,"that span is not a place",g.detail)}case "getText":{if(!X(p.projection))return b("unsupported-content","unknown text projection","projection");if(o.resolve(p.target,"body")){let w=le(p.target,"body",o,a);return w.ok?_({kind:"text",text:w.value.text(p.projection??"allMarkup")}):b(w.code,"that handle does not name a body",w.detail)}let g=he(p.target,o,a);if(!g.ok)return b(g.code,"that handle does not name a body or a paragraph",g.detail);let O=a.story(g.value.story);return _({kind:"text",text:O?.paragraphText(g.value.paragraphId,p.projection??"allMarkup")??""})}case "getSpanText":{if(!X(p.projection))return b("unsupported-content","unknown text projection","projection");let u=W(p.span,o,a);if(!u.ok)return b(u.code,"that span is not a place",u.detail);let g=ee(p.span,o,a);return g.ok?_({kind:"text",text:el(u.value,g.value,Rn,p.projection??"allMarkup")}):b(g.code,"that span is not a place",g.detail)}case "getParagraphId":{let u=he(p.paragraph,o,a);if(!u.ok)return b(u.code,"that handle does not name a paragraph",u.detail);let O=a.story(u.value.story)?.paragraph(u.value.paragraphId);return _({kind:"text",text:O?.paraId??""})}case "search":{let u=W(p.scope,o,a);if(!u.ok)return b(u.code,"that is not a scope to search",u.detail);let g=ee(p.scope,o,a);return g.ok?ue(g.value,u.value,p.text,p.options):b(g.code,"that is not a scope to search",g.detail)}case "proposeInsertion":case "proposeDeletion":case "proposeReplacement":return vd(p,H,o,a,(u,g)=>{let O=l(u);return y(O)??C(O,g)},e.trackedRangeReplacement!==false,f);case "insertText":{let u=Qt(p.at,o,a);if(!u.ok)return b(u.code,"that is not a place to insert at",u.detail);let g=a.story(u.value.story);return g?Oe(l(g),u.value,p.text,"at"in p.at&&p.at.at==="start"):b("invalid-handle","that story is not in this document")}case "replaceSpan":{if("body"in p.span){let O=le(p.span.body,"body",o,a);return O.ok?xe(l(O.value),p.text):b(O.code,"that handle does not name a body",O.detail)}let u=W(p.span,o,a);if(!u.ok)return b(u.code,"that span is not a place",u.detail);if(!u.value)return b("invalid-offset","that story holds no paragraph to write into","empty-story");let g=ae(u.value);return g?vl(we(l(g),u.value,p.text),g,u.value,e.replacementLanding?.(u.value.start.paragraphId,0,0)!=null):b("invalid-handle","that story is not in this document")}case "replaceStoryBlocks":{let u=le(p.body,"body",o,a);return u.ok?De(l(u.value),p.paragraphs):b(u.code,"that handle does not name a body",u.detail)}case "insertParagraph":{let u=Io(p.anchor,o,a);if(!u.ok)return b(u.code,"that is not a paragraph to insert beside",u.detail);if(p.where!=="before"&&p.where!=="after")return b("unknown-operation","that is not a place to insert",String(p.where));let g=a.story(u.value.story);if(!g)return b("invalid-handle","that story is not in this document");let O=Zd(p.anchor,o,a);if(O){let E=l(g),{where:F,text:U}=p,ne=_r(U)??y(E)??C(E,`${O}:${F}`)??C(E,u.value.paragraphId);if(ne)return ne;let me=E.slotById.get(u.value.paragraphId);if(!me)return b("invalid-handle","that paragraph is not in the body");let L=j(E,me),Z=G(E,F==="before"?L:L+1),te={op:"insertParagraphBesideTable",tableId:O,where:F,text:U},Fe=()=>Z.id===null?ce:{kind:"handle",handle:o.paragraph(Z.id,g.story)};return {ok:true,kind:"command",ops:[te],story:g.story,answer:Fe}}let w=H&&Ad(g,u.value.paragraphId,k);return w?{ok:false,error:w}:ze(l(g),u.value,p.where,p.text)}case "splitParagraph":{let u=he(p.paragraph,o,a);if(!u.ok)return b(u.code,"that handle does not name a paragraph",u.detail);let g=a.story(u.value.story);return g?it(l(g),u.value,p.delimiters,p.trimDelimiters===true,p.trimSpacing===true):b("invalid-handle","that story is not in this document")}case "getFont":{let u=W(p.span,o,a);if(!u.ok)return b(u.code,"that span is not a place",u.detail);let g=ee(p.span,o,a);if(!g.ok)return b(g.code,"that span is not a place",g.detail);let O=mt(u.value,g.value);return _({kind:"font",font:hu(g.value.part,O,e.displayMode)})}case "setFont":{let u=W(p.span,o,a);if(!u.ok)return b(u.code,"that span is not a place",u.detail);if(!u.value)return b("invalid-offset","that story holds no paragraph to format","empty-story");let g=ae(u.value);return g?$(l(g),u.value,p.font):b("invalid-handle","that story is not in this document")}case "getStyle":{let u=W(p.span,o,a);if(!u.ok)return b(u.code,"that span is not a place",u.detail);let g=ee(p.span,o,a);if(!g.ok)return b(g.code,"that span is not a place",g.detail);let O=g.value.part,w=g.value.styles(),E=be(u.value,g.value).map(U=>Ao(O,U,w)),F=E.length>0&&E.every(U=>U!==null&&U===E[0])?E[0]:null;return _({kind:"style",name:F})}case "setStyle":{let u=W(p.span,o,a);if(!u.ok)return b(u.code,"that span is not a place",u.detail);if(!u.value)return b("invalid-offset","that story holds no paragraph to style","empty-story");let g=ae(u.value);return g?ge(l(g),u.value,p.name):b("invalid-handle","that story is not in this document")}case "getParagraphFormat":{let u=Io(p.paragraph,o,a);if(!u.ok)return b(u.code,"that is not a paragraph",u.detail);let g=a.story(u.value.story);if(!g)return b("document-unavailable","this host holds no document right now");let O=ku(g.part,u.value.paragraphId,g.styles());return O?_({kind:"paragraphFormat",format:O}):b("invalid-handle","that handle does not name a paragraph")}case "setParagraphFormat":{let u=Io(p.paragraph,o,a);if(!u.ok)return b(u.code,"that is not a paragraph",u.detail);let g=a.story(u.value.story);return g?ie(l(g),u.value,p.format):b("invalid-handle","that story is not in this document")}case "deleteParagraph":{let u=he(p.paragraph,o,a);if(!u.ok)return b(u.code,"that handle does not name a paragraph",u.detail);let g=a.story(u.value.story);return g?V(l(g),u.value):b("invalid-handle","that story is not in this document")}case "setPageSetup":{let u=o.resolve(p.section,"section");return !u||u.kind!=="section"?b("invalid-handle","that handle does not name a section","section"):Le(u.index,p.setup)}case "getFurniture":{let u=o.resolve(p.section,"section");if(!u||u.kind!=="section")return b("invalid-handle","that handle does not name a section","section");if(p.kind!=="header"&&p.kind!=="footer")return b("unknown-operation","that is not furniture",String(p.kind));let g={kind:p.kind,sectionIndex:u.index,variant:p.variant};return yr(g)?a.sections()[u.index]?_({kind:"handle",handle:o.body(g)}):Ln("that section no longer exists"):b("unknown-operation","that is not a furniture variant",String(p.variant))}case "getNotes":{if(!o.resolve(p.document,"document"))return b("invalid-handle","that handle does not name a document","document");if(p.noteKind!=="footnote"&&p.noteKind!=="endnote")return b("unknown-operation","that is not a kind of note",String(p.noteKind));let u=p.noteKind,g=a.noteIds(u);if(!g.ok)return b("ambiguous-document",`${u} identities are not completely and unambiguously enumerable`,g.reason==="duplicates"?g.duplicateIds.join(","):g.reason);let O=g.ids;if(p.scope){let w=le(p.scope,"body",o,a);if(!w.ok)return b(w.code,"that handle does not name a body",w.detail);let E=_l(w.value.root,u),F=new Set(g.ids);if(E.some(U=>!F.has(U)))return b("ambiguous-document","a note reference has no matching note");O=E;}return _({kind:"handles",handles:O.map(w=>o.note(u,w))})}case "getNoteBody":case "getNoteText":{let u=o.resolve(p.note,"note");if(!u||u.kind!=="note")return b("invalid-handle","that handle does not name a note","note");let g=u,O=a.story(g);return O?p.op==="getNoteText"?_({kind:"text",text:O.text(p.projection)}):_({kind:"handle",handle:o.body(g)}):b("invalid-handle","that note is not in this document",Y(g))}case "getNoteKind":{let u=o.resolve(p.note,"note");return !u||u.kind!=="note"?b("invalid-handle","that handle does not name a note","note"):_({kind:"text",text:u.noteKind})}case "deleteNote":{let u=o.resolve(p.note,"note");if(!u||u.kind!=="note")return b("invalid-handle","that handle does not name a note","note");let g=a.noteIds(u.noteKind);return g.ok?g.ids.includes(u.noteId)?Bn(u.noteKind,u.noteId):b("invalid-handle","that note is not in this document"):b("ambiguous-document",`${u.noteKind} identities are not completely and unambiguously enumerable`,g.reason==="duplicates"?g.duplicateIds.join(","):g.reason)}case "getLists":{let u=le(p.body,"body",o,a);return u.ok?_({kind:"handles",handles:Ht(u.value).map(g=>o.list(g.numId,u.value.story))}):b(u.code,"that handle does not name a body",u.detail)}case "getListId":{let u=st(p.list);return "list"in u?_({kind:"number",value:Number(u.list.numId)}):u}case "getListById":{let u=le(p.body,"body",o,a);if(!u.ok)return b(u.code,"that handle does not name a body",u.detail);if(!Number.isInteger(p.id)||p.id<=0)return b("unsupported-content","a list is numbered from one",String(p.id));let g=String(p.id),O=Ht(u.value).find(w=>w.numId===g);return O?_({kind:"handle",handle:o.list(O.numId,u.value.story)}):b("invalid-handle","no list in that story carries that number",g)}case "getListParagraphs":{let u=st(p.list);if(!("list"in u))return u;let g=p.level;if(g!==void 0&&(!Number.isInteger(g)||g<0||g>sn))return b("invalid-offset",`a list level is 0 to ${String(sn)}`,String(g));let O=u.plan.reads,w=g===void 0?u.list.paragraphIds:u.list.paragraphIds.filter(E=>Dn(O,E)?.level===g);return _({kind:"handles",handles:w.map(E=>o.paragraph(E,O.story))})}case "getParagraphList":{let u=he(p.paragraph,o,a);if(!u.ok)return b(u.code,"that handle does not name a paragraph",u.detail);let g=a.story(u.value.story);if(!g)return b("invalid-handle","that story is not in this document");let O=Dn(g,u.value.paragraphId);return O?_({kind:"handle",handle:o.list(O.numId,g.story)}):b("unsupported-content","that paragraph is not in a list",u.value.paragraphId)}case "getListLevel":{let u=he(p.paragraph,o,a);if(!u.ok)return b(u.code,"that handle does not name a paragraph",u.detail);let g=a.story(u.value.story);if(!g)return b("invalid-handle","that story is not in this document");let O=Dn(g,u.value.paragraphId);return O?_({kind:"number",value:O.level}):b("unsupported-content","that paragraph is not in a list",u.value.paragraphId)}case "setListLevel":{let u=he(p.paragraph,o,a);if(!u.ok)return b(u.code,"that handle does not name a paragraph",u.detail);let g=a.story(u.value.story);return g?nc(l(g),u.value.paragraphId,p.level):b("invalid-handle","that story is not in this document")}case "insertListParagraph":{let u=st(p.list);return "list"in u?oc(u.plan,u.list,p.where,p.text):u}case "getHyperlink":{let u=W(p.span,o,a);if(!u.ok)return b(u.code,"that span is not a place",u.detail);let g=ee(p.span,o,a);if(!g.ok)return b(g.code,"that span is not a place",g.detail);let O=a.package;if(!O||!u.value)return _({kind:"text",text:""});let w=ia(g.value,u.value);if(!w)return _({kind:"text",text:""});let E=eb(g.value.part,w.id),F=E?hl(O,g.value.part.name,E):null;return _({kind:"text",text:F??""})}case "setHyperlink":{let u=W(p.span,o,a);if(!u.ok)return b(u.code,"that span is not a place",u.detail);if(!u.value)return b("invalid-offset","that story holds no text to link","empty-story");let g=ae(u.value);return g?rc(l(g),u.value,p.target):b("invalid-handle","that story is not in this document")}case "getBookmarkRange":{let u=la(p.bookmark);return "reads"in u?_({kind:"span",span:Q(u.range)}):u}case "getComments":{let u=W(p.scope,o,a);if(!u.ok)return b(u.code,"that scope is not a place",u.detail);let g=ee(p.scope,o,a);if(!g.ok)return b(g.code,"that scope names no story",g.detail);let O=g.value,w=A(O);if(!w)return b("document-unavailable","this host holds no document");let E=u.value,F=w.roots.filter(U=>{if(!E)return true;let ne=U.range;if(!ne)return false;let me=O.indexOf(ne.start.paragraphId),L=O.indexOf(ne.end.paragraphId),Z=O.indexOf(E.start.paragraphId),te=O.indexOf(E.end.paragraphId);return L<Z||me>te?false:L===Z&&me===Z&&te===Z?ne.end.offset>E.start.offset&&ne.start.offset<E.end.offset:true});return _({kind:"handles",handles:F.map(U=>o.comment(U.id,O.story))})}case "getCommentReplies":{let u=N(p.comment);return u.ok?_({kind:"handles",handles:u.item.replyIds.map(g=>o.comment(g,u.reads.story))}):u.planned}case "getCommentId":{let u=N(p.comment);return u.ok?_({kind:"text",text:u.item.id}):u.planned}case "getCommentAuthor":{let u=N(p.comment);return u.ok?_({kind:"text",text:u.item.comment.author}):u.planned}case "getCommentDate":{let u=N(p.comment);return u.ok?_({kind:"text",text:u.item.comment.date??""}):u.planned}case "getCommentText":{let u=N(p.comment);if(!u.ok)return u.planned;let g=A(u.reads);return _({kind:"text",text:g?.textOf(u.item.id)??""})}case "getCommentRange":{let u=N(p.comment);if(!u.ok)return u.planned;let g=u.item.range;if(!g||u.item.orphaned)return b("invalid-handle","that comment has no range in this document");let O=M(u.reads,g);return O?_({kind:"span",span:O}):b("invalid-handle","that comment\u2019s range is no longer in the story")}case "getCommentResolved":{let u=N(p.comment);return u.ok?_({kind:"flag",value:u.item.resolved}):u.planned}case "insertComment":return Cu(p,o,a,x);case "setCommentResolved":{let u=N(p.comment);if(!u.ok)return u.planned;if(typeof p.resolved!="boolean")return b("unsupported-content","resolved is a yes or a no",String(p.resolved));let g=y(l(u.reads));return g||{ok:true,kind:"commentWrite",write:{kind:"resolve",commentId:u.item.id,resolved:p.resolved},story:u.reads.story,answer:()=>ce}}case "replyToComment":{let u=N(p.comment);if(!u.ok)return u.planned;let g=qr({author:p.author,text:p.text,date:p.date,kind:"reply"});if(g)return g;let O=u.item.range;if(!O||u.item.orphaned)return b("invalid-handle","that comment has no range to reply over");let w=y(l(u.reads));if(w)return w;let E=u.reads.story,F=Jr(p.date);return {ok:true,kind:"commentWrite",write:{kind:"reply",parentCommentId:u.item.id,anchor:{paragraphId:O.start.paragraphId,start:O.start.offset,end:O.end.offset,...O.end.paragraphId===O.start.paragraphId?{}:{endParagraphId:O.end.paragraphId}},text:p.text,author:p.author,date:F},story:u.reads.story,answer:(U,ne)=>ne===void 0?ce:{kind:"handle",handle:o.comment(ne,E)}}}case "deleteComment":{let u=N(p.comment);return u.ok?Tu(u.item,u.reads,g=>y(l(g))):u.planned}case "getRevisions":return Xd(p,o,a);case "getReviewItemRange":return Gd(p.key,o,a);case "getRevisionType":{let u=S(p.revision);return u.ok?_({kind:"text",text:u.item.type}):u.planned}case "getRevisionAuthor":{let u=S(p.revision);return u.ok?_({kind:"text",text:u.item.author}):u.planned}case "getRevisionDate":{let u=S(p.revision);return u.ok?_({kind:"text",text:u.item.date}):u.planned}case "getRevisionRange":{let u=S(p.revision);if(!u.ok)return u.planned;let{ranges:g}=u.item.item,O=g[0];if(!O)return b("invalid-handle","that change covers no characters");let E=u.item.item.revisionKind==="structural"?O:{...O,end:g[g.length-1].end},F=M(u.reads,E)??M(u.reads,O);return F?_({kind:"span",span:F}):b("invalid-handle","that change\u2019s range is no longer in the story")}case "acceptRevision":case "rejectRevision":{let u=S(p.revision);if(!u.ok)return u.planned;let g=p.op==="acceptRevision"?"accept":"reject";return Fr(u.reads,[u.item.item],g,P,v)}case "resolveRevisionBatch":case "setRevisionAuthorBatch":case "acceptAllRevisions":case "rejectAllRevisions":return Iu(p,o,a,v,P);case "selectSpan":{let u=W(p.span,o,a);if(!u.ok)return b(u.code,"that span is not a place",u.detail);if(!u.value)return b("invalid-offset","that story holds no paragraph to select","empty-story");let g=ae(u.value);return g?sa(l(g),u.value,p.mode):b("invalid-handle","that story is not in this document")}case "selectBookmark":{let u=la(p.bookmark);return "reads"in u?sa(l(u.reads),u.range,p.mode):u}case "getContentControls":{let u=Jo(p.scope);return "reads"in u?_({kind:"handles",handles:al(u.reads,u.node).map(g=>o.contentControl(g.nodeId,u.reads.story))}):u}case "getContentControlById":{let u=Jo(p.scope);if(!("reads"in u))return u;if(!Number.isInteger(p.id))return b("unsupported-content","a control id is a whole number",String(p.id));let g=nn(u.node).find(O=>qc$1(O).id===p.id);return g?_({kind:"handle",handle:o.contentControl(g.id,u.reads.story)}):b("invalid-handle","no control in that scope carries that id",String(p.id))}case "getContentControlsByTag":case "getContentControlsByTitle":{let u=Jo(p.scope);if(!("reads"in u))return u;let g=p.op==="getContentControlsByTag"?p.tag:p.title;if(typeof g!="string"||g.length===0)return b("unsupported-content","a tag or title to match is required",p.op);let O=nn(u.node).filter(w=>{let E=qc$1(w);return p.op==="getContentControlsByTag"?E.tag===g:E.alias===g});return _({kind:"handles",handles:O.map(w=>o.contentControl(w.id,u.reads.story))})}case "getContentControlTag":case "getContentControlTitle":case "getContentControlFileId":case "getContentControlSubtype":case "getContentControlLock":{let u=Ge(p.contentControl);if(!("control"in u))return u;let g=u.control.properties;if(p.op==="getContentControlLock")return _({kind:"text",text:u.control.lock});if(p.op==="getContentControlSubtype")return _({kind:"text",text:g.type});if(p.op==="getContentControlFileId")return _({kind:"text",text:g.id===void 0?"":String(g.id)});let O=p.op==="getContentControlTag"?g.tag:g.alias;return _({kind:"text",text:O??""})}case "getContentControlIsBound":case "getContentControlPlaceholderShown":case "getContentControlTemporary":{let u=Ge(p.contentControl);if(!("control"in u))return u;let g=p.op==="getContentControlIsBound"?u.control.properties.dataBinding!==void 0:p.op==="getContentControlPlaceholderShown"?u.control.properties.showingPlaceholder:u.control.properties.temporary;return _({kind:"flag",value:g})}case "getContentControlText":{let u=Ge(p.contentControl);return "control"in u?_({kind:"text",text:dl(u.reads,u.node,p.projection)}):u}case "getContentControlParagraphs":{let u=Ge(p.contentControl);return "control"in u?_({kind:"handles",handles:u.control.paragraphIds.map(g=>o.paragraph(g,u.reads.story))}):u}case "getContentControlRange":{let u=Ge(p.contentControl);if(!("control"in u))return u;let g=p.location??"whole";if(!nd.has(g))return b("unsupported-content","that is not a place in a control",g);let O=So(u.reads,u.node);if(!O)return b("unsupported-content","that control holds nothing addressable","empty");let w=g==="start"||g==="before"?O.start:O.end,E=g!=="whole"&&g!=="content",F=U=>({story:u.reads.story,paragraphId:U.paragraphId,index:u.reads.indexOf(U.paragraphId),offset:U.offset});return _({kind:"span",span:Ae(E?{start:F(w),end:F(w)}:{start:F(O.start),end:F(O.end)},o)})}case "setContentControlValue":{let u=Ge(p.contentControl);if(!("control"in u))return u;let g=ad(p.value);if(!g.ok)return b(g.code,g.message,g.detail);let O=l(u.reads),w=y(O);return w||{ok:true,kind:"command",story:u.reads.story,ops:[Xr(u.control.nodeId,g.value,k)],answer:()=>ce}}case "setContentControlProperties":{let u=Ge(p.contentControl);if(!("control"in u))return u;if(H&&(!cd(u.reads.part,u.control.nodeId,k)||p.lock!==void 0||p.cannotEdit!==void 0||p.cannotDelete!==void 0))return b("unsupported-capability","tracked control metadata requires an own pending insertion; locks require direct edits");if(p.tag===void 0&&p.title===void 0&&p.lock===void 0&&p.cannotEdit===void 0&&p.cannotDelete===void 0)return b("unsupported-content","nothing to write","no-properties");if(p.lock!==void 0&&!td.has(p.lock))return b("unsupported-content","that is not a lock this schema declares",p.lock);for(let E of [p.cannotEdit,p.cannotDelete])if(E!==void 0&&typeof E!="boolean")return b("unsupported-content","lock flags must be boolean");let g=l(u.reads),O=p.lock;if(p.cannotEdit!==void 0||p.cannotDelete!==void 0){let E=O??s.get(g)?.get(u.control.nodeId)??u.control.properties.lock,F=p.cannotEdit??(E==="contentLocked"||E==="sdtContentLocked"),U=p.cannotDelete??(E==="sdtLocked"||E==="sdtContentLocked");O=F?U?"sdtContentLocked":"contentLocked":U?"sdtLocked":"unlocked";}let w=y(g);if(w)return w;if(O!==void 0){let E=s.get(g)??new Map;E.set(u.control.nodeId,O),s.set(g,E);}return {ok:true,kind:"command",story:u.reads.story,ops:[{op:"setContentControlProperties",controlId:u.control.nodeId,...p.tag===void 0?{}:{tag:p.tag},...p.title===void 0?{}:{alias:p.title},...O===void 0?{}:{lock:O}}],answer:()=>ce}}case "insertContentControlText":{let u=Ge(p.contentControl);if(!("control"in u))return u;let g=rd(u.control.properties,p.text,p.at);if(g)return {ok:false,error:g};let O=l(u.reads),w=y(O);if(w)return w;let E=So(u.reads,u.node);if(!E)return b("unsupported-content","that control holds nothing addressable","empty");let F=p.at==="end"?E.end:p.at==="replace"&&H?Ou(u.reads.part,E,k):E.start,U=()=>({kind:"span",span:Q({start:{story:u.reads.story,paragraphId:F.paragraphId,index:u.reads.indexOf(F.paragraphId),offset:F.offset},end:{story:u.reads.story,paragraphId:F.paragraphId,index:u.reads.indexOf(F.paragraphId),offset:F.offset+p.text.length}})});return p.at==="replace"?{ok:true,kind:"command",story:u.reads.story,ops:[Xr(u.control.nodeId,{kind:"text",text:p.text},k)],answer:U}:{ok:true,kind:"command",story:u.reads.story,ops:p.text.length===0?[]:[{op:"insertText",paragraphId:F.paragraphId,offset:F.offset,text:p.text,inside:u.node.id,...Gr(k)}],answer:U}}case "deleteContentControl":{let u=Ge(p.contentControl);if(!("control"in u))return u;if(typeof p.keepContent!="boolean")return b("unsupported-content","keepContent is required","keepContent");let g=l(u.reads),O=y(g);if(O)return O;if(!p.keepContent)for(let w of u.control.paragraphIds){let E=z(g,w);if(E)return E}return {ok:true,kind:"command",story:u.reads.story,ops:[{op:"removeContentControl",controlId:u.control.nodeId,keepContent:p.keepContent}],answer:()=>ce}}case "insertContentControl":return dd(p,o,a,k,e.trackedRangeReplacement,(u,g)=>{let O=l(u);return y(O)??C(O,g)});case "insertCustomNode":{let u=Du(p);if(u)return b("unsupported-content",u.message,u.detail);let g=Eu(p.payload);if(!g.ok)return b("unsupported-content","that payload cannot be written",g.field);let O=Mu(p,o,a);if("code"in O)return b(O.code,O.message,O.detail);let{start:w,end:E}=O.range,F=ae(O.range);if(!F)return b("invalid-handle","that story is not in this document");let U=y(l(F));return U||{ok:true,kind:"customNodeWrite",story:F.story,write:Lu(p,w,E,g.value),answer:()=>ce}}default:return b("unknown-operation","this host does not implement that operation",String(p.op))}};return {plan(p,k){if(c&&je(p))return b("conflicting-operations","header/footer creation must commit alone");let R=m.conflict(p);if(R)return b("conflicting-operations",R.message,R.detail);let I=Ls(p,()=>Qo(p,k),o,a);if(I.ok&&I.kind==="command"&&I.solitary){if(m.hasCommands)return b("conflicting-operations","header/footer creation must commit alone");c=true;}return I.ok&&I.kind!=="query"&&m.note(p),I},get hasCommands(){return m.hasCommands},get writeScope(){return h?.reads.scope??null},settle(p){let k=h;if(k){let R=p.story(k.reads.story),I=R&&eb(R.part,k.reads.root.id),T=R&&I&&I.id!==R.root.id?Po(R,I):R;if(!T)return {ok:false,detail:`the story this batch wrote is gone: ${Y(k.reads.story)}`};let D=new Set(k.reads.paragraphIds),H=T.paragraphIds.filter(g=>!D.has(g));if(!k.wholesale&&H.length!==k.created.length+k.externalCreatedCount)return {ok:false,detail:`planned ${String(k.created.length+k.externalCreatedCount)} new paragraphs, the transaction made ${String(H.length)}`};k.order.filter(g=>g.id===null).forEach((g,O)=>{g.id=H[O]??null;});for(let g of k.retargets)g.slot.id&&o.retarget(g.from,g.slot.id);}for(let[R,I]of d.entries()){let T=p.story(I.range.start.story);if(!(!T||!Zl(I.range,T))&&e.select?.(I.range,I.mode)===false)return {ok:false,detail:"the host could not place the selection",selection:R}}return {ok:true}}}}var zm=4e6,Gm=16e6,Fu=12;function ln(e){if(e===null||typeof e!="object")return false;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function dn(e){return "paragraph"in e&&typeof e.offset=="number"}function Bu(e=zm,t=Gm){let n=new Map,o=[],r=0,a=0,i=(s,l)=>s.length+l.text.length;return {record(s,l,d){let m=n.get(l),c=m?.at(-1);if(m&&(n.delete(l),n.set(l,m)),c&&c.text===d){s>c.to&&(c.to=s);return}let h={from:s,to:s,text:d};if(a+=i(l,h),!m||!c)n.set(l,[h]);else for(m.push(h),a-=i(l,c),o.push({key:l,record:c}),r+=c.text.length;r>e&&o.length>0;){let f=o.shift();r-=f.record.text.length;let y=n.get(f.key);y?.[0]===f.record&&y.shift();}for(;a>t&&n.size>1;){let[f,y]=n.entries().next().value;n.delete(f);let x=y.at(-1);x&&(a-=i(f,x));}},clear(){n.clear(),o.length=0,r=0,a=0;},size(){return n.size},at(s,l){let d=n.get(l);if(d)for(let m=d.length-1;m>=0;m-=1){let c=d[m];if(c.from<=s)return s<=c.to?c.text:void 0}}}}function Vt(e,t,n){let o=he(e.paragraph,t,n);if(!o.ok)return null;let r=n.story(o.value.story),a=r?.rawText(o.value.paragraphId);return a==null||!r?null:{id:o.value.paragraphId,text:a,story:r}}var Hu=e=>`next\0${e}`,_u=(e,t)=>`between\0${e}\0${t}`;function ju(e,t,n,o){let r=Vt(e,n,o),a=Vt(t,n,o);if(!r||!a||r.id===a.id||r.story!==a.story)return null;let i=r.story.indexOf(r.id),s=r.story.indexOf(a.id);if(i<0||s<=i)return null;let l=r.story.paragraphIds.slice(i+1,s);return {key:_u(r.id,a.id),ids:l,texts:l.map(d=>r.story.rawText(d)??"")}}function Mn(e,t,n,o,r,a=0){if(a>Fu)return e;if(Array.isArray(e)){let d=false,m=e.map(c=>{let h=Mn(c,t,n,o,r,a+1);return h!==c&&(d=true),h});return d?Object.freeze(m):e}if(!ln(e))return e;let{start:i,end:s}=e;if(ln(i)&&dn(i)&&ln(s)&&dn(s)){let d=ju(i,s,o,r);d&&(n.record(t,d.key,d.ids.join("\0")),d.ids.forEach((m,c)=>n.record(t,m,d.texts[c])));}if(dn(e)){let d=Vt(e,o,r);if(!d)return e;n.record(t,d.id,d.text);let m=d.story.indexOf(d.id);return n.record(t,Hu(d.id),d.story.paragraphIds[m+1]??""),Object.freeze({...e,readAt:t})}let l=null;for(let[d,m]of Object.entries(e)){let c=Mn(m,t,n,o,r,a+1);c!==m&&(l??={...e},l[d]=c);}return l?Object.freeze(l):e}function zo(e,t,n=0){if(n>Fu)return;if(Array.isArray(e)){for(let a of e)zo(a,t,n+1);return}if(!ln(e))return;if(dn(e)){e.readAt!==void 0&&t.push({endpoint:e});return}let{start:o,end:r}=e;if(ln(o)&&dn(o)&&ln(r)&&dn(r)){o.readAt!==void 0&&t.push({endpoint:o,end:r}),r.readAt!==void 0&&t.push({endpoint:r});for(let[a,i]of Object.entries(e))a!=="start"&&a!=="end"&&zo(i,t,n+1);return}for(let a of Object.values(e))zo(a,t,n+1);}function Vu(e,t,n,o,r){let a=[];zo(e,a);for(let{endpoint:i,end:s}of a){if(i.readAt===t)continue;if(typeof i.readAt!="number"||!Number.isSafeInteger(i.readAt))return "invalid-read-revision";if(i.readAt>t)return `read-at ${String(i.readAt)} was never read: the document is at revision ${String(t)}`;let l=Vt(i,o,r);if(!l)continue;let d=n.at(i.readAt,l.id);if(d===void 0)return `read-at ${String(i.readAt)} is no longer checkable`;let m=l.text,c=i.offset;if(!Number.isInteger(c)||c<0||c>d.length)continue;let h=s!==void 0&&Vt(s,o,r)?.id!==l.id;if(h?d!==m:m.length<c||d.slice(0,c)!==m.slice(0,c))return h?`the paragraph a span starts in changed since revision ${String(i.readAt)}`:`text before offset ${String(c)} changed since revision ${String(i.readAt)}`;if(h){let f=Xm(i,s,i.readAt,n,o,r);if(f)return f}}return null}function Xm(e,t,n,o,r,a){let i=Vt(e,r,a),s=Vt(t,r,a);if(!i||!s)return null;let l=ju(e,t,r,a),d=_u(i.id,s.id),m=o.at(n,d)??(o.at(n,Hu(i.id))===s.id?"":void 0);if(m===void 0)return `the paragraphs a span covers are no longer checkable at revision ${String(n)}`;if(!l||l.ids.join("\0")!==m)return `a paragraph was inserted or removed inside a span since revision ${String(n)}`;for(let[c,h]of l.ids.entries())if(o.at(n,h)!==l.texts[c])return `a paragraph inside a span changed since revision ${String(n)}`;return null}var Ym=Object.freeze({status:"skipped"});function pe(e,t,n){return Object.freeze(n===void 0?{code:e,message:t}:{code:e,message:t,detail:n})}function qm(e){if(e==="review-module-required"||e==="automation-structural-tracking-unsupported"||e==="edit.tracked-structure-unsupported")return pe("unsupported-capability","this edit requires a supported review mode",e);if(e==="unsupported-cell-content")return pe("unsupported-content","that cell is not one plain paragraph",e);if(e==="unsupported-revision:foreign-insertion")return pe("unsupported-revision","the new text would land inside a container within another author's pending insertion",e);let t=e==="unsupported-revision"||e.startsWith("unsupported-revision:");return pe(t?"unsupported-revision":"transaction-refused",t?"that story contains a tracked change this engine cannot resolve":"the document store refused the transaction",e)}function Ie(e,t,n,o){return {ok:false,results:e.map((r,a)=>a===t?{status:"error",error:n}:Ym),revision:o,changed:false}}function Jm(e,t){let n=-1,o=e.findIndex(r=>(r.op==="selectSpan"||r.op==="selectBookmark")&&++n===t);return o<0?0:o}function Uu(e){let{port:t}=e,n=Object.freeze({...e.capabilities}),o=Zs(),r=new Set,a=false,i={mode:"Off"},s=0,l=null,d=null,m=Bu(),c=n.events?t.subscribe(()=>{if(a)return;let x=Object.freeze({revision:t.revision()});if(s>0)l=x;else for(let v of [...r])v(x);}):()=>{},h=x=>{if(d&&d.pkg===x)return d.value;let v=Pt(x);return d={pkg:x,value:v},v},f=x=>{let v=Array.isArray(x?.operations)?x.operations:[],P=t.revision();if(a)return Ie(v,0,pe("disposed","this host was disposed"),P);if(!n.document)return Ie(v,0,pe("unsupported-capability","this host has no document","document"),P);let A=t.currentPackage();if(!A)return Ie(v,0,pe("document-unavailable","this host holds no document right now"),P);if(x.expectedRevision!==void 0&&x.expectedRevision!==P)return Ie(v,0,pe("stale-revision","the document moved since that revision",`expected ${String(x.expectedRevision)}, at ${P}`),P);let N=h(A);for(let V=0;V<v.length;V+=1){let $=Vu(v[V],P,m,o,N);if($)return Ie(v,V,$==="invalid-read-revision"?pe("invalid-offset","an endpoint carries an invalid readAt",$):pe("stale-revision","that range was read before its text changed",$),P)}let S=t.allocationActor?.(),M=Qr({handles:o,reads:N,capabilities:n,collaborative:t.collaborative?.()??false,...t.compareDocuments?{compareDocuments:t.compareDocuments}:{},setupOutsideUndo:t.setupOutsideUndo?.()??false,trackedRangeReplacement:t.trackedRangeReplacement?.()??true,...t.revisionDisplayMode?{displayMode:t.revisionDisplayMode()}:{},...t.replacementLanding?{replacementLanding:t.replacementLanding.bind(t)}:{},...t.fieldPageContext?{fieldPageContext:t.fieldPageContext.bind(t)}:{},...t.select?{select:t.select.bind(t)}:{},...t.selectRefusal?{selectRefusal:t.selectRefusal.bind(t)}:{}}),j=[],J=[],C=null,z=[],K=[],G=null,Q,ae=null,X=-1,ue=false,fe=i;for(let V=0;V<v.length;V+=1){let $=v[V];if(t.suggesting?.()&&$.op!=="replaceSpan"&&(!Rr($)||!fe.author&&(["insertContentControl","insertField","insertOoxml","setFieldResult","deleteField","setContentControlProperties","startNewList","setListLevelFormat","insertTable","insertTableRows","updateTable","updateTableCell","splitParagraph"].includes($.op)||$.op==="insertBreak"&&$.breakType!=="Line")))return Ie(v,V,pe("unsupported-capability","this operation has no supported tracked form in suggesting mode"),P);let ge=Js($,t.localChangeTracking===true,fe),ie=ge?.step??Qs($,Hb(S,()=>M.plan($,fe.author)),fe.author);if(ge&&(fe=ge.state),!ie.ok)return Ie(v,V,ie.error,P);if(j.push(ie),ie.kind==="command")if(fe.author&&(ie.packageEdits?.length||$.op==="setContentControlProperties")&&(ue=true),$.op==="setRevisionAuthorBatch"&&(ue=true),ie.packageEdits&&z.push(...ie.packageEdits),X<0&&(X=V),ie.lifecycle)C=ie.ops[0]??null;else if(ie.relate){let Le=ie.relate;J.push(Bn=>{let st=Bn(Le.url);return st===null?null:Le.ops(st)});}else {let{ops:Le}=ie;J.push(()=>Le);}else ie.kind==="commentWrite"?(X<0&&(X=V),K.push(ie.write),G=M.writeScope??{kind:"body"}):ie.kind==="customNodeWrite"&&(X<0&&(X=V),ae={write:ie.write,scope:M.writeScope??{kind:"body"}});}let Oe=false;if(K.length>0){let V=t.applyCommentWrites(K,G??{kind:"body"});if(!V.ok)return Ie(v,X<0?0:X,pe("transaction-refused","the document store refused the comment write",V.reason),P);Oe=V.changed,Q=V.commentId;}if(ae){let V=t.applyCustomNodeWrite(ae.write,ae.scope);if(!V.ok)return Ie(v,X<0?0:X,pe("transaction-refused","the document store refused the custom-node write",V.reason),P);Oe=V.changed;}if(C){let V=t.applyLifecycle(C);if(!V.ok)return Ie(v,X<0?0:X,pe("transaction-refused","the document store refused the transaction",V.reason),P);Oe=V.changed;}if(J.length>0){let V=t.apply($=>{let ge=[];for(let ie of J){let Le=ie($);if(Le===null)return null;ge.push(...Le);}return ge},M.writeScope??{kind:"body"},z,ue);if(!V.ok)return Ie(v,X<0?0:X,qm(V.reason),P);Oe=V.changed;}let we=t.currentPackage();if(!we)return Ie(v,0,pe("document-unavailable","this host holds no document right now"),P);let xe=h(we),De=M.settle(xe);if(!De.ok&&De.selection!==void 0)return i=fe,{...Ie(v,Jm(v,De.selection),pe("unsupported-capability","the host could not place the selection","selection"),t.revision()),changed:Oe};if(!De.ok)return Ie(v,X<0?0:X,pe("transaction-refused","the transaction did not produce the document the batch planned",De.detail),t.revision());i=fe;let ze=t.revision();return {ok:true,results:j.map(V=>({status:"ok",value:V.kind==="query"?Mn(V.value,P,m,o,N):Mn(V.kind==="customNodeWrite"?V.answer(xe):V.answer(xe,Q),ze,m,o,xe)})),revision:ze,changed:Oe}};return {capabilities:n,revision:()=>t.revision(),execute:x=>{s+=1;try{return f(x)}finally{if(s-=1,s===0&&l){let v=l;l=null;for(let P of [...r])P(v);}}},...t.prepare?{prepare:t.prepare.bind(t)}:{},save(){if(a)return {ok:false,error:pe("disposed","this host was disposed")};if(!n.save)return {ok:false,error:pe("unsupported-capability","this host cannot save","save")};let x=t.save();return x?{ok:true,bytes:x}:{ok:false,error:pe("document-unavailable","this host holds no document right now")}},subscribe(x){return a||!n.events?()=>{}:(r.add(x),()=>{r.delete(x);})},dispose(){a||(a=true,r.clear(),c(),t.dispose(),d=null,m.clear());}}}var Wu=Object.freeze({document:true,save:true,events:true,selection:false,scrolling:false,layout:false}),Ku=Object.freeze({kind:"body"});function Qm(e,t={}){let n=lg(e,t.limits??{});if(!n.ok)return {ok:false,reason:n.reason,...n.limit===void 0?{}:{limit:n.limit},...n.detail?{detail:n.detail}:{}};let o=sa(n.package),r=o.parts.get(o.mainDocumentPart);if(!r)return {ok:false,reason:"no-main-document-part",detail:o.mainDocumentPart};let a=new S(o,za(o,Eb(r)),t.contentLockPolicy?{contentLockPolicy:t.contentLockPolicy}:{}),i=t.collaborationModel?.session,s=()=>{},l=ef(a,i,()=>s()),d=t.compareDocuments?{...l,compareDocuments:t.compareDocuments}:l;if(t.pagination){let c,h=-1,f=t.pagination;d.prepare=async y=>{if(!y.operations.some(P=>P.op==="updateFieldResult"))return;c=void 0;let x=a.packageRevision,v=await f(Ca(a));a.packageRevision===x&&(c=v,h=x);},d.fieldPageContext=(y,x,v)=>{if(a.packageRevision!==h)return null;let P=Pt(a.currentPackage()).story(y);return P?qs(c,P.part,x,v):null};}let m=Uu({port:d,capabilities:Wu});return i&&(s=i.attach(b$1(a,{documentId:i.documentId}))),{ok:true,host:m}}function Zm(e,t,n){let o=e.partFor(n);return o?Xa(e,()=>{let r=ej(e.currentPackage(),t,o.name);return r?(e.replacePackageShell(r.pkg),r.relationshipId):null},r=>r!==null):null}function ef(e,t,n=()=>{}){let o=true,r=0,a$1=()=>t?(r+=1,{origin:t.identity.role==="agent"?g.mutationAgent:g.mutationHuman,actorId:t.identity.actorId,operationId:`${t.identity.actorId}:${t.sessionId}:automation:${r}`,recordsHistory:false}):{},i=s=>(t?.flushPendingJournals(),s);return {localChangeTracking:true,collaborative:()=>!!t,allocationActor:()=>t?.identity.actorId,revision:()=>e.packageRevision,currentPackage:()=>o?e.currentPackage():null,apply(s,l=Ku,d=[]){if(!o)return {ok:false,reason:"disposed"};let m=s(y=>Hb(t?.identity.actorId,()=>Zm(e,y,l)));if(m===null)return {ok:false,reason:"unsupported-target"};let c=t?.gateOperations(m,l);if(c)return {ok:false,reason:c};let h=t?e.partFor(l)?.name:void 0,f=e.transact(l,y=>{for(let x of d)y.applyPackage(x);for(let x of m)y.apply(x);h&&y.applyPackage(x=>a(x,h,m));},a$1());return f.ok?i({ok:true,changed:f.change!==null}):{ok:false,reason:f.detail?`${f.reason}: ${f.detail}`:f.reason}},applyLifecycle(s){if(!o)return {ok:false,reason:"disposed"};let l=t?.gateOperations([s],Ku);if(l)return {ok:false,reason:l};let d=Hb(t?.identity.actorId,()=>e.applyLifecycleOp(s));return d.ok?i({ok:true,changed:d.change!==null}):{ok:false,reason:d.detail?`${d.reason}: ${d.detail}`:d.reason}},applyCommentWrites(s,l){if(!o)return {ok:false,reason:"disposed"};if(s.length===0)return {ok:true,changed:false};let d=t?.gateOperations([],l);if(d)return {ok:false,reason:d};let m=e.resolveStory(l);if(!m.ok)return {ok:false,reason:m.reason};if(m.store.graftPackage(()=>e.currentPackage()),s.every(f=>f.kind==="delete")){let f=s.find(x=>x.kind==="delete"),y=Hb(t?.identity.actorId,()=>da(e,s.flatMap(x=>x.kind==="delete"?[{commentId:x.commentId,...x.parentCommentId===void 0?{}:{parentCommentId:x.parentCommentId}}]:[]),l,f?.kind==="delete"?f.noteId:void 0));return y?i({ok:true,changed:y}):{ok:false,reason:"comment-delete-refused"}}if(s.length!==1)return {ok:false,reason:"mixed-comment-writes"};let c=s[0];if(c.kind==="create"||c.kind==="reply"){let f=Hb(t?.identity.actorId,()=>ba(e,{anchor:c.anchor,author:c.author,text:c.text,...c.date===void 0?{}:{date:c.date},...c.kind==="reply"?{replyToCommentId:c.parentCommentId}:{}},l));return f.ok?i({ok:true,changed:true,..."commentId"in f?{commentId:f.commentId}:{}}):{ok:false,reason:f.reason}}if(c.kind!=="resolve")return {ok:false,reason:"unsupported-comment-write"};let h=Hb(t?.identity.actorId,()=>ca(e,c.commentId,c.resolved));return h.ok?i({ok:true,changed:true}):{ok:false,reason:h.reason}},applyCustomNodeWrite(s,l){if(!o)return {ok:false,reason:"disposed"};let d=t?.gateOperations([],l);if(d)return {ok:false,reason:d};let m=e.resolveStory(l);if(!m.ok)return {ok:false,reason:m.reason};let c=Hb(t?.identity.actorId,()=>la(e,s,l));return c.ok?i({ok:true,changed:c.change!==null}):{ok:false,reason:c.detail?`${c.reason}: ${c.detail}`:c.reason}},save:()=>o?ng(e.currentPackage()):null,subscribe:s=>e.subscribe(()=>s()),dispose(){n(),o=false;}}}var $u="https://docx-editor.dev/docs/2.x/guides/diagnostics";function tf(e){return e.replace(".","-")}var oa={"open.unsupported-source":"The editor was given something that is not DOCX bytes. Pass a Uint8Array or an ArrayBuffer of a .docx file, or 'blank'.","open.zip-corrupt":"The file is not a valid ZIP archive, or a compressed entry is damaged. Ask for a fresh copy of the file.","open.zip-invalid-entry-name":'The archive contains an entry with an unsafe path, such as ".." or a leading "/". The editor refuses it for safety.',"open.zip-entry-limit":"The archive has more entries than the open limit allows. For a trusted file, the server API accepts a higher limit: limits.zip.maxEntries in createServer.","open.zip-size-limit":"The archive expands to more than the total size limit. For a trusted file, the server API accepts a higher limit: limits.zip.maxTotalBytes in createServer.","open.zip-ratio-limit":"The file expands to many times its compressed size, which is how a decompression bomb looks. For a trusted file, the server API accepts a higher limit: limits.zip.maxRatio in createServer.","open.xml-malformed":"An XML part of the document is not well formed. Opening and saving the file in a desktop editor usually repairs it.","open.xml-dtd-forbidden":"An XML part declares a DTD or an entity. The editor refuses these to block XML entity attacks.","open.xml-part-size-limit":"One XML part is larger than the per-part size limit. For a trusted file, the server API accepts a higher limit: limits.xml.maxBytes in createServer.","open.xml-depth-limit":"An XML part nests deeper than the depth limit, often through deeply nested tables. This limit is fixed; flatten the nesting to open the file.","open.xml-element-limit":"An XML part has more elements than the element limit. For a trusted file, the server API accepts a higher limit: limits.xml.maxElements in createServer.","open.invalid-limits":"The limits passed to createServer are not valid numbers. Check the limits option.","open.content-types-invalid":"The file has no valid [Content_Types].xml part, so it is not a usable Office package. Save it again as .docx.","open.missing-main-document":"The package has no main document part. The file may be a different Office format, such as .xlsx or .pptx, renamed to .docx.","open.relationships-invalid":"A relationship in the package is invalid or duplicated. Opening and saving the file in a desktop editor usually repairs it.","open.relationship-limit":"The package has more relationships than the open limit allows. For a trusted file, the server API accepts a higher limit: limits.maxRelationships in createServer.","open.part-limit":"The package has more XML parts than the open limit allows. For a trusted file, the server API accepts a higher limit: limits.maxXmlParts in createServer.","open.failed":"The document could not be opened for a reason without a specific code. Report it with the engine version.","save.no-document":"save() ran before a document was loaded, or after it failed to open. Wait for the open to finish, and check the document.open event for a refusal.","save.document-changed":"A new document was loaded while save() waited for a pending edit. Save again after the new document opens.","save.failed":"save() threw. The errorName and stage fields name the class of the error; its message is never reported. Report it with the editor version.","edit.read-only":"The document is open for viewing or is protected as read-only, so edits are refused. Change the editing mode, or remove the protection.","edit.protected-content":"The edit touches content that document protection or a locked content control does not allow you to change.","edit.suggesting-needs-author":"Suggesting (tracking changes) needs an author to attribute each change to. Pass the author option or call setAuthor.","edit.review-module-required":"This operation needs the review module. Register reviewModule() from @docx-editor.dev/pro in modules.","edit.tracked-drawing-delete-unsupported":"This operation cannot record a drawing deletion as a tracked change, so nothing was deleted. Leave the drawing and report it, or ask a person to delete it in the editor, which records the deletion as a tracked change.","edit.tracked-structure-unsupported":"This structural edit cannot be recorded as a tracked change. Edit the text inside the structure instead, or ask a person to make the change with tracking off.","edit.tracked-operation-unsupported":"This editing API operation cannot be recorded as a tracked change, so nothing was applied. Use text edits such as range.insertText or range.delete, which tracking records. Never switch tracking off to make the edit succeed.","edit.tracking-mode-unsupported":"TrackAll needs every collaborator to enforce tracking, which this runtime cannot guarantee. Use TrackMineOnly instead.","edit.tracking-author-required":"TrackMineOnly needs an author for each tracked change. Pass the author option to createServer or createBrowser. The author set on the editor does not apply to an editing API batch.","edit.comment-author-required":"A comment or reply from the editing API needs an author. Pass the author option to createServer or createBrowser. In a React or Vue host with the review module, use useReview().comment or useReview().reply instead, which write as the author set on the editor.","edit.tracking-unsupported-host":"This automation host does not support change tracking. The runtimes from createServer and from a mounted editor both support TrackMineOnly.","edit.revision-unsupported":"The edit, accept, or reject touches a tracked change of a kind the editor cannot change yet. Edit around it, and leave that change for a person to review.","edit.tracking-required":"Document protection allows edits only as tracked changes. Switch to suggesting mode, or set document.changeTrackingMode to TrackMineOnly in an editing API batch, then edit again.","edit.tracked-image-replace-unsupported":"Replacing a picture cannot be recorded as a tracked change, so the picture did not change. Insert the new picture as a tracked insertion, or ask a person to replace it with tracking off.","edit.tracked-deleted-text-only":"The tracked deletion or replacement covers only text that is already deleted, so nothing was applied. Include live text in the range, or insert next to the deleted text instead.","edit.tracked-foreign-revision-unsupported":"The tracked edit touches a pending change of another author in a way this editor cannot record: their paragraph mark, formatting, move, or structural change, or a link or content control inside their insertion. Nothing was applied. Edit outside that change, or leave it for a person to review first. A formatting change that leaves the formatting unchanged has no review card but still counts; Accept All or Reject All over the story clears it.","edit.tracked-own-pending-change":"The tracked edit covers or borders your own pending change and would merge with that decision, so nothing was applied. Read the proposed text with getReviewedText('Current'), then edit a range outside your pending change. To change your proposal itself, reject it and propose again.","edit.picture-selected":"A picture is selected, so the new picture has no place to go and nothing was inserted. Place the caret in text next to the picture, then insert again.","edit.cross-structure-join":"The edit would join paragraphs that live in different containers, such as two table cells. Edit each container separately.","edit.indivisible-content":"The edit would split content that must stay whole, such as an equation or a field, or a paragraph break would land inside an inline content control. Select the whole item, or make the edit outside the control.","edit.field-structure":"The edit would break the structure of a field. Edit the field result as a whole, or remove the whole field.","edit.field-unsupported":"The field type or instruction is not one the editing API writes. Fields that fetch, embed, link, run, or prompt always refuse. Use Page, NumPages, Ref, PageRef, NoteRef, Seq, StyleRef, Date, Time, or TOC with supported arguments. The instruction is written as text and never run.","edit.field-result-unsupported":"The operation is not one a field result supports. A field result reads its text and takes insertText(text, 'Replace') with plain text; its other range members refuse. A result write also refuses when the result holds content other than plain runs. Read or write the result with those members only.","edit.ooxml-unsupported":"The OOXML is not the one shape insertOoxml inserts: a Flat OPC package (pkg:package) whose document part holds one paragraph with exactly one inline m:oMath and, around it, plain runs. Other parts, relationships, images, fields, paragraph properties, display equations, and unknown elements refuse. Send only that shape.","edit.style-not-defined":"The style name is not defined in this document, or it names a style of another type. List the defined styles with document.getStyles(), then assign the nameLocal of a listed style of the right type: a paragraph style for paragraph, range, and body styles, and a table style for a table.","edit.no-styles-defined":"The document has no styles part, so it defines no styles and no style name applies. Leave the style as it is, or start from a document whose styles part defines the style you need.","edit.section-mark":"The edit would remove a section break that holds page layout settings. Remove the section break on its own.","edit.table-structure-unsupported":"The table edit is not supported for this table shape, for example a legacy horizontal merge, a row that starts or ends with an authored gap, or cells that do not fit the column grid. Edit that row or table directly.","edit.table-merge-not-rectangle":"The cells to merge do not form a rectangle, or the rectangle holds only one cell. Name the top-left and bottom-right cells of a rectangle that no merged cell crosses, then merge again.","edit.table-split-unsupported":"The cell cannot split into these counts. A cell merged over several rows splits into a number of rows that divides its rows, each new column must keep the minimum column width, and a table without a column grid splits into a divisor of the columns the cell spans.","edit.table-insert-refused":"A table cannot be inserted at the selection, for example inside a field or a locked content control. Move the caret first.","edit.table-of-contents-refused":"The table of contents could not be inserted or updated at this place. Check that the selection is in the main document body.","edit.unsupported-content":"The edit touches content the editor shows but cannot change yet. The content is kept as it is.","edit.operation-unsupported":"This editing API operation or option is not supported by this runtime or host. Check the compatibility notes for the member you called.","edit.unsupported-story":"This part of the document, such as a header, a footer or a note, does not support this edit.","edit.unmapped-change":"The browser changed the page in a way the editor could not express as a document edit, so the change was undone.","edit.stale-target":"The operation addresses content that no longer exists, usually after a remote or undone change. Read the document again and retry.","edit.invalid-argument":"The arguments are not valid for this target, such as text with a character the call does not take, a value out of range, or a range that spans more than the call allows. Check each argument against the method or editor command you called.","edit.resource-limit":"The edit would exceed a size or nesting limit. Split the change into smaller edits.","edit.refresh-in-progress":"An external document refresh is in progress. Retry the edit after the refresh completes.","edit.preview-active":"A preview is open over the document, so the editor refuses writes and a second preview. Commit or discard the open preview, then retry.","edit.preview-unsupported":"A preview cannot show this operation, so nothing was shown. Write it with run() after the preview, or leave it out of the preview.","edit.preview-composing":"An input method composition is in progress, so no preview began. Retry after the composition ends.","edit.preview-diverged":"The document answered a replayed read differently from the preview, so the commit wrote nothing. Read the document again and build a new preview.","edit.read-after-commit":"The writes in this sync are applied, and a load that followed them failed. Read the document again before you decide; do not apply the same edit again.","edit.collaboration-not-ready":"The collaboration session is not ready to replicate edits, so this one was refused. Wait for the ready status, then retry; a destroyed session needs a rejoin.","edit.collaboration-text-limit":"One edit inserted more text than a collaboration session accepts at once. Insert the text in smaller parts.","edit.internal-invariant":"The editor refused an edit to protect the document structure. This is an engine defect: report the code with the engine version.","edit.refused":"The edit was refused for a reason without a specific code. Read snapshot().lastRejection for the local message.","review.revision-unsupported":"The editor cannot accept or reject a tracked change of this kind, so it was left in the document. Keep it, or replace the content with a direct edit while change tracking is off.","review.incomplete-group":"The tracked change resolves only together with a change the decision leaves out, such as the deleted row that holds it or a change the filter hides. Decide that change first, or clear the filter to review it.","review.retained-structure":"The row stays because it holds a table whose rows are not tracked. To resolve the changes in its cells, use resolve(), or Accept All or Reject All in the editor; acceptAll() and rejectAll() refuse whole. Delete the row with change tracking off to remove it.","review.locked-content":"A content control locks the content, so the decision would change locked text. Remove the lock (set `ContentControl.cannotEdit` to false, or ask the document owner), then decide the change.","review.bound-content":"The change is in a content control bound to a custom XML part, which the editor cannot keep in step. Keep the change, or update the bound data and remove the binding outside the editor, then decide it.","review.stale-revision":"The tracked change no longer exists, usually because it was resolved already. Read the review items again.","font.shaper-unavailable":"The text shaper did not load, so text is measured with fallback metrics. Check that your bundler serves the HarfBuzz WebAssembly file.","font.load-failed":"A font face could not be loaded. The editor uses a substitute. Check the font source URL and its CORS headers.","font.missing":"A font the document asks for is not available. The editor uses a substitute. Add the face to the fonts option.","font.integrity-mismatch":"A font face does not match its declared hash or metadata, so the editor refused it and used a substitute.","font.malformed":"A font file is not a valid font, so the editor refused it and used a substitute. Check the file the font source points at.","font.size-limit":"A font file is larger than the font byte budget, so the editor used a substitute. Subset the font, or serve a smaller face.","history.split":"An edit started a new undo step inside a gesture you meant as one. Wrap the gesture in beginHistoryGroup and end it when the gesture ends.","history.possible-ungrouped-gesture":"Several commands ran in quick succession without a history group, so undo may take them back one at a time. Use beginHistoryGroup for one user gesture.","history.possible-fragmented-gesture":"One gesture was split across several history groups, so undo may need several steps. Keep one history group open for the whole gesture.","custom-node.payload-invalid":"A custom node payload in the document does not match the node schema, so the node opened without its data. Check the schema version that wrote the file.","custom-node.payload-missing":"A custom node points at a payload the document does not contain, often after a partial export or a manual edit. The node opened without its data.","font.unsupported-face":"A font face uses a format or face index the editor does not support. The editor uses a substitute.","performance.slow-interaction":"More than one key press or click in 20 took over 200 ms to reach the screen. Compare the layout and paint timings in this event: slow layout follows document size, slow paint follows the pages on screen."},Zr="The collaboration session could not take work: it was not attached, not ready yet, or already destroyed. Wait for the ready status, or rejoin when the session was destroyed.",Go="The collaboration factory rejected a value before joining. Fix the document id, session id, or identity that the host passed.",Xo="Joining the room did not complete. Check that the provider is connected and the room id is right, then rejoin.",Fn="The document cannot seed a collaboration room. Open the file on its own to find the problem, or seed the room from another copy.",ea="This client and the room use different collaboration formats. Save local work, then upgrade the client or migrate the room.",ta="The room is unusable. Save a copy, then create a new room from saved document bytes.",Ut="A remote update could not be applied yet. Edits pause and the session heals when a later update arrives. No action is needed unless it persists.",kt="Shared state reached a resource limit. A refused local edit is taken back automatically; a room over a limit must be recreated from a saved copy.",Yo="A value in the shared state is malformed or points at something that does not exist. A refused local edit is taken back automatically; a room that holds such a value must be recreated from a saved copy.",zu="The room server refused the saved room. Check the server storage, then rejoin.",$e="This collaboration code is no longer emitted. Upgrade the packages on every client and server.",nf={"collab.collaboration-session-destroyed":Zr,"collab.collaboration-session-not-attached":Zr,"collab.collaboration-session-not-ready":Zr,"collab.collaboration-text-limit":"One edit inserted more text than a collaboration session accepts at once. Insert the text in smaller parts.","collab.experimental-collaboration-body-text-only":"This session replicates only body text, and the edit touched another part of the document. Make that change outside collaboration.","collab.invalid-document-id":Go,"collab.invalid-identity":Go,"collab.invalid-identity-color":Go,"collab.invalid-session-id":Go,"collab.already-initialized":Xo,"collab.document-id-mismatch":Xo,"collab.initialization-aborted":Xo,"collab.not-initialized":Xo,"collab.baseline-too-large":Fn,"collab.blob-read":Fn,"collab.invalid-baseline":Fn,"collab.missing-local-blob":Fn,"collab.no-main-document-part":Fn,"collab.collaboration-format-mismatch":ea,"collab.protocol-version-mismatch":ea,"collab.schema-version-mismatch":ea,"collab.blob-digest-mismatch":ta,"collab.concurrent-seed":ta,"collab.port-already-attached":ta,"collab.duplicate-paragraph-id":Ut,"collab.invalid-relationships":Ut,"collab.materialize-dropped-content":Ut,"collab.missing-blob":Ut,"collab.missing-root":Ut,"collab.remote-apply-failed":Ut,"collab.unknown-paragraph-id":Ut,"collab.blob-store-full":kt,"collab.blob-too-large":kt,"collab.invalid-blob-descriptor":Yo,"collab.invalid-bound":Yo,"collab.invalid-logical-id":Yo,"collab.invalid-string":"A shared value is not valid XML text, so the session refused it. A peer sent malformed state; save a copy and recreate the room.","collab.prototype-key":"A shared state key would reach object internals, so the session refused it. A peer sent malformed state; save a copy and recreate the room.","collab.text-too-long":kt,"collab.too-many-attributes":kt,"collab.too-many-children":kt,"collab.too-many-nodes":kt,"collab.too-many-parts":kt,"collab.too-many-relationships":kt,"collab.tree-too-deep":kt,"collab.unknown-logical-id":Yo,"collab.unsafe-part-name":"A shared package part has an unsafe name, so the session refused it. A peer sent malformed state; save a copy and recreate the room.","collab.invalid-saved-room":zu,"collab.saved-room-unavailable":zu,"collab.baseline-digest-mismatch":$e,"collab.experimental-collaboration-existing-paragraphs-only":$e,"collab.experimental-collaboration-text-only":$e,"collab.experimental-collaboration-untracked-text-only":$e,"collab.immutable-baseline-changed":$e,"collab.immutable-metadata-changed":$e,"collab.invalid-shared-metadata":$e,"collab.local-mirror-failed":$e,"collab.paragraph-set-mismatch":$e,"collab.shared-schema-invalid":$e,"collab.unsupported-root-key":$e,"collab.initialization-timeout":"Joining the room timed out. Check that the collaboration server is reachable, then rejoin.","collab.authentication-failed":"The collaboration server refused the credential. Refresh the token, then rejoin. Reconnecting with the same token fails again.","collab.room-generation-changed":"The server compacted the room while this client was away. Save a copy if it holds unsent changes, then rejoin.","collab.transport":"The collaboration transport failed. Check the network and the server, then rejoin.","collab.transport-disconnected":"The connection to the collaboration server dropped. The session reconnects on its own; edits continue offline when offline editing is on."},na={...oa,...nf};function of(e){return {hint:na[e]??oa["edit.refused"],docs:Object.hasOwn(na,e)?`${$u}#${tf(e)}`:$u}}function Gu(e){return e.startsWith("edit.")&&Object.hasOwn(oa,e)}function rf(){return Object.keys(na)}var af=1,Yu={unsupported:"open.unsupported-source","inflate-error":"open.zip-corrupt","bad-name":"open.zip-invalid-entry-name","too-many-entries":"open.zip-entry-limit","parse-error":"open.xml-malformed","missing-root":"open.xml-malformed","multiple-roots":"open.xml-malformed","invalid-name":"open.xml-malformed","invalid-namespace":"open.xml-malformed","undeclared-prefix":"open.xml-malformed","duplicate-expanded-attribute":"open.xml-malformed","dtd-forbidden":"open.xml-dtd-forbidden","entity-forbidden":"open.xml-dtd-forbidden","too-deep":"open.xml-depth-limit","too-many-elements":"open.xml-element-limit","invalid-limits":"open.invalid-limits","no-content-types":"open.content-types-invalid","bad-content-types":"open.content-types-invalid","no-main-document":"open.missing-main-document","no-main-document-tree":"open.missing-main-document","bad-relationship-target":"open.relationships-invalid","duplicate-relationship-id":"open.relationships-invalid","too-many-relationships":"open.relationship-limit","too-many-xml-parts":"open.part-limit"};function sf(e,t){return e==="too-large"?t==="zip.maxRatio"?"open.zip-ratio-limit":t==="zip.maxTotalBytes"?"open.zip-size-limit":"open.xml-part-size-limit":un(Yu,e)??"open.failed"}var ra={locked:"edit.protected-content",bound:"edit.protected-content","drawing-locked":"edit.protected-content","not-adjacent-siblings":"edit.cross-structure-join","indivisible-content":"edit.indivisible-content","field-structure":"edit.field-structure","field-result-unsupported":"edit.field-structure","field-unsupported":"edit.field-unsupported","field-result-range-unsupported":"edit.field-result-unsupported","ooxml-unsupported":"edit.ooxml-unsupported","style-not-defined":"edit.style-not-defined","no-styles-defined":"edit.no-styles-defined","carries-section-mark":"edit.section-mark","table-has-merge":"edit.table-structure-unsupported","row-hides-cell":"edit.table-structure-unsupported","unknown-grid-column":"edit.table-structure-unsupported","cross-cell-drawing":"edit.table-structure-unsupported","cells-not-rectangle":"edit.table-merge-not-rectangle","split-rows-not-divisor":"edit.table-split-unsupported","cell-too-narrow":"edit.table-split-unsupported","split-needs-grid":"edit.table-split-unsupported","cell-has-revision":"edit.revision-unsupported","unsupported-cell-content":"edit.unsupported-content",trackedDrawingDeletionUnsupported:"edit.tracked-drawing-delete-unsupported",packageTransactionRequired:"edit.tracked-structure-unsupported","automation-structural-tracking-unsupported":"edit.tracked-structure-unsupported","unsupported-tracked-table-operation":"edit.tracked-structure-unsupported","unsupported-revision":"edit.revision-unsupported","unsupported-revision:foreign-insertion":"edit.tracked-foreign-revision-unsupported","unknown-revision":"edit.stale-target","resource-limit":"edit.resource-limit","fragment-too-deep":"edit.resource-limit","fragment-resource-budget":"edit.resource-limit","fragment-invalid-block":"edit.unsupported-content",unsupported:"edit.unsupported-content","unsupported-property":"edit.unsupported-content","not-a-picture-drawing":"edit.unsupported-content","chart-drawing":"edit.unsupported-content","unknown-op":"edit.invalid-argument","invalid-range":"edit.invalid-argument","offset-out-of-range":"edit.invalid-argument","splits-surrogate-pair":"edit.invalid-argument","invalid-text":"edit.invalid-argument","invalid-property-value":"edit.invalid-argument","invalid-drawing-value":"edit.invalid-argument","not-a-list-paragraph":"edit.invalid-argument",typeMismatch:"edit.invalid-argument",invalidArgs:"edit.invalid-argument","unknown-paragraph":"edit.stale-target",[tt]:"edit.stale-target","paragraph-not-in-body":"edit.stale-target","no-such-story":"edit.stale-target","cell-not-in-story":"edit.stale-target","deleted-table-object":"edit.stale-target","missing-parent-table":"edit.stale-target","missing-table-story":"edit.stale-target","not-a-paragraph":"edit.stale-target","unknown-block":"edit.stale-target","not-a-block":"edit.stale-target","block-required":"edit.stale-target","unknown-part":"edit.stale-target","unknown-content-control":"edit.stale-target","not-a-content-control":"edit.stale-target","unknown-control":"edit.stale-target","unknown-table":"edit.stale-target","unknown-row":"edit.stale-target","unknown-drawing":"edit.stale-target","not-a-drawing":"edit.stale-target","tree-invariant":"edit.internal-invariant","package-invariant":"edit.internal-invariant","package-changed":"edit.internal-invariant","duplicate-property-container":"edit.internal-invariant","unknown-scope":"edit.unsupported-story","dangling-relationship":"edit.unsupported-story","wrong-relationship-type":"edit.unsupported-story","external-relationship":"edit.unsupported-story","missing-part":"edit.unsupported-story","bad-relationship-target":"edit.unsupported-story","not-a-story-part":"edit.unsupported-story","too-many-story-stores":"edit.resource-limit","unsupported-story":"edit.unsupported-story","experimental-collaboration-body-text-only":"edit.unsupported-story","review-module-required":"edit.review-module-required","no-document":"edit.stale-target","table-insert-refused":"edit.table-insert-refused","table-of-contents-refused":"edit.table-of-contents-refused","refresh-in-progress":"edit.refresh-in-progress","preview-active":"edit.preview-active","preview-operation-unsupported":"edit.preview-unsupported","preview-composition-active":"edit.preview-composing","collaboration-session-not-ready":"edit.collaboration-not-ready","collaboration-session-not-attached":"edit.collaboration-not-ready","collaboration-session-destroyed":"edit.collaboration-not-ready","collaboration-text-limit":"edit.collaboration-text-limit","change-tracking-unsupported-host":"edit.tracking-unsupported-host","change-tracking-mode-unsupported":"edit.tracking-mode-unsupported","change-tracking-author-required":"edit.tracking-author-required","change-tracking-operation-unsupported":"edit.tracked-operation-unsupported"};function lf(e){let t=un(ra,e);if(t)return t;let n=e.indexOf(":"),o=n<0?e:e.slice(0,n);return Gu(o)?o:un(ra,o)??null}var qu={"unsupported-revision":"review.revision-unsupported","incomplete-group":"review.incomplete-group","retained-structure":"review.retained-structure","unknown-revision":"review.stale-revision"},aa={"locked-content":"review.locked-content","bound-content":"review.bound-content"};function df(e){return (e.detail===void 0?null:un(aa,e.detail))??qo(e.reason)}function qo(e){return un(qu,e)??un(aa,e)??null}function Ju(){return [...Object.keys(Yu),"too-large",...Object.keys(ra),...Object.keys(qu),...Object.keys(aa)]}var Se=1024,uf=[[64*Se,"0-64KiB"],[128*Se,"64-128KiB"],[256*Se,"128-256KiB"],[512*Se,"256-512KiB"],[1024*Se,"512KiB-1MiB"],[2*1024*Se,"1-2MiB"],[4*1024*Se,"2-4MiB"],[8*1024*Se,"4-8MiB"],[16*1024*Se,"8-16MiB"],[32*1024*Se,"16-32MiB"],[64*1024*Se,"32-64MiB"],[128*1024*Se,"64-128MiB"],[256*1024*Se,"128-256MiB"],[512*1024*Se,"256-512MiB"]];function cf(e){for(let[t,n]of uf)if(e<t)return n;return "512MiB+"}function pf(e){return e<=0?"0":e===1?"1":e<10?"2-9":e<100?"10-99":e<1e3?"100-999":"1000+"}var Xu=0;function mf(){let e=globalThis.crypto;if(e?.randomUUID)return `e_${e.randomUUID()}`;if(e?.getRandomValues){let t=e.getRandomValues(new Uint8Array(16));return `e_${Array.from(t,n=>n.toString(16).padStart(2,"0")).join("")}`}return Xu+=1,`e_${Date.now().toString(36)}_${Xu.toString(36)}`}function ff(e,t=()=>Date.now()){let n=mf();return {editorSessionId:n,deliver(o){let r=Object.freeze({...o,schemaVersion:af,editorSessionId:n,time:t()});for(let a of e())try{let i=a(r);i&&typeof i.then=="function"&&i.then(void 0,()=>{});}catch{}}}}function un(e,t){return Object.hasOwn(e,t)?e[t]:void 0}var gf=["paragraph-count-unexplained","paragraph-reordered","unknown-paragraph-id","unknown-content-moved","unsupported-node","split-not-clean","join-not-clean"],Zu={unaddressed:true,"misplaced-marker":true,"nested-marker":true,"unsupported-structure":true,"unsupported-move":true,"unrecorded-properties":true,"read-only":true,"no-sites":true,"paired-change":true,"removed-content":true,"replaced-properties":true,"emptied-change":true,"enclosing-change":true,"grouped-change":true,"nested-table":true,"locked-content":true,"bound-content":true},ec="exception",Qu;function tc(){return Qu??=new Set([...Ju().filter(e=>!e.includes(":")),...gf,...Object.keys(Zu),ec]),Qu}function hf(){return [...tc()]}function yf(e){if(!e)return;let t=e.indexOf(":"),n=t<0?e:e.slice(0,t);return tc().has(n)?n:void 0}function kf(e){if(!e)return null;let t=e.indexOf(":"),n=qo(t<0?e:e.slice(0,t));if(!n)return null;let o=t<0?void 0:e.slice(t+1);return o!==void 0&&Object.hasOwn(Zu,o)?{code:n,cause:o}:{code:n}}function xf(){return ec}var bf=new Set(["Error","TypeError","RangeError","ReferenceError","SyntaxError"]);function vf(e){let t=e instanceof Error?e.name:void 0;return t&&bf.has(t)?t:"other"}var Af=[[/^\[content_types\]\.xml$/,"content-types"],[/\.rels$/,"relationships"],[/^customxml\//,"custom-xml"],[/^docprops\//,"document-properties"],[/\/media\//,"media"],[/\/embeddings\//,"embedding"],[/\/glossary\//,"glossary"],[/(?:^|\/)theme\/[^/]*\.xml$/,"theme"],[/(?:^|\/)header\d*\.xml$/,"header"],[/(?:^|\/)footer\d*\.xml$/,"footer"],[/(?:^|\/)footnotes\.xml$/,"footnotes"],[/(?:^|\/)endnotes\.xml$/,"endnotes"],[/(?:^|\/)comments[a-z]*\.xml$/,"comments"],[/(?:^|\/)people\.xml$/,"people"],[/(?:^|\/)styles(?:witheffects)?\.xml$/,"styles"],[/(?:^|\/)numbering\.xml$/,"numbering"],[/(?:^|\/)websettings\.xml$/,"web-settings"],[/(?:^|\/)settings\.xml$/,"settings"],[/(?:^|\/)fonttable\.xml$/,"font-table"],[/(?:^|\/)document\d*\.xml$/,"main-document"]],Of=512;function Rf(e){if(!e)return;let t=[": "," -> "].reduce((o,r)=>{let a=e.indexOf(r);return a>=0&&a<o?a:o},e.length);if(t>Of)return "other";let n=e.slice(0,t).replace(/^\/+/,"").toLowerCase().replace(/(\.(?:xml|rels))\/[^/]*$/,"$1");for(let[o,r]of Af)if(o.test(n))return r;return "other"}var Pf={insert:true,delete:true,replace:true,moveFrom:true,moveTo:true,format:true,paragraphMark:true,structural:true};function zO(e){return e&&Object.hasOwn(Pf,e)?e:void 0}var If=new Set(["rPrChange","pPrChange","sectPrChange","tblPrChange","tblPrExChange","tblGridChange","trPrChange","tcPrChange","numberingChange"]);function GO(e){if(e)return If.has(e)?e:"other"}
|
|
7
|
+
export{sf as A,lf as B,df as C,qo as D,cf as E,pf as F,ff as G,hf as H,yf as I,kf as J,xf as K,vf as L,Rf as M,zO as N,GO as O,Ul as a,Iy as b,Wl as c,Wr as d,fv as e,Vo as f,Uo as g,lu as h,du as i,re as j,Nt as k,Rs as l,kr as m,xr as n,bn as o,je as p,Pt as q,Ys as r,qs as s,$c as t,Uu as u,Wu as v,Qm as w,ef as x,of as y,rf as z};
|