@docx-editor.dev/core 2.25.0 → 2.27.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 -3
- package/dist/automation.cjs +1 -1
- package/dist/automation.d.ts +31 -16
- package/dist/automation.js +1 -1
- package/dist/binding.cjs +1 -1
- package/dist/binding.d.ts +8 -8
- package/dist/binding.js +1 -1
- package/dist/chunk-2GK7YQB2.cjs +2 -0
- package/dist/chunk-4KZ6L5YF.cjs +15 -0
- package/dist/chunk-55AT3MOU.cjs +25 -0
- package/dist/chunk-6ZQMII6V.js +1 -0
- package/dist/chunk-7IGCWG4H.js +2 -0
- package/dist/chunk-7MYITTAH.js +5 -0
- package/dist/chunk-AVKVRU7Z.cjs +5 -0
- package/dist/chunk-CWRBFNK5.cjs +5 -0
- package/dist/chunk-DGPA3TST.cjs +27 -0
- package/dist/{chunk-WVJRO4WY.js → chunk-DNXVNQEO.js} +1 -1
- package/dist/chunk-FQN4KSFL.cjs +7 -0
- package/dist/{chunk-MEF2AK5L.cjs → chunk-GVUOWHTO.cjs} +1 -1
- package/dist/chunk-GWQJ5774.js +5 -0
- package/dist/chunk-HAQ72KD7.js +1 -0
- package/dist/chunk-HO5XFO32.cjs +3 -0
- package/dist/chunk-IGR23DV2.js +1 -0
- package/dist/chunk-JSIX2EOH.js +3 -0
- package/dist/chunk-K246T47S.cjs +1 -0
- package/dist/chunk-KAXOGCGA.js +1 -0
- package/dist/chunk-LZLTN5A3.cjs +1 -0
- package/dist/chunk-NBCVVZOM.cjs +1 -0
- package/dist/{chunk-AJCCS53D.js → chunk-O5INAWZQ.js} +1 -1
- package/dist/chunk-OHAXVTWG.cjs +1 -0
- package/dist/chunk-S74GRBNE.js +7 -0
- package/dist/chunk-UBLUVNZR.js +27 -0
- package/dist/chunk-UMRSBLO7.js +15 -0
- package/dist/chunk-VIPMGGUT.js +25 -0
- package/dist/chunk-WG4KMSX2.cjs +2 -0
- package/dist/chunk-WRLKVNNR.cjs +1 -0
- package/dist/chunk-ZU7IVN6G.js +2 -0
- package/dist/collaboration/replication.cjs +1 -1
- package/dist/collaboration/replication.d.ts +14 -5
- package/dist/collaboration/replication.js +1 -1
- package/dist/collaboration.d.ts +3 -3
- 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 +20 -31
- package/dist/contracts/modules.js +1 -1
- package/dist/contracts/types.d.ts +1 -1
- package/dist/{custom-node-writes-Cy9imOjA.d.ts → custom-node-writes-Vzpq9I8_.d.ts} +2 -2
- package/dist/{document-protection-Bp19Ad4I.d.ts → document-protection-9zpIHWTE.d.ts} +1 -1
- package/dist/{editor-DkfCCTxA.d.ts → editor-B3OBYNrF.d.ts} +29 -34
- package/dist/editor.cjs +1 -1
- package/dist/editor.css +14 -2
- package/dist/editor.d.ts +28 -27
- package/dist/editor.js +1 -1
- package/dist/export.cjs +2 -2
- package/dist/export.d.ts +26 -14
- package/dist/export.js +2 -2
- package/dist/{font-resolver-C295obND.d.ts → font-resolver-DN0xNOf_.d.ts} +5 -3
- package/dist/{headless-document-view-R9bzzepb.d.ts → headless-document-view-ICYqNkQ1.d.ts} +2 -2
- package/dist/{image-resources-DfagDguq.d.ts → image-resources-BDFxcu7W.d.ts} +1 -1
- package/dist/{index-3KAxeSic.d.ts → index-CkQVRJtJ.d.ts} +53 -21
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +18 -17
- package/dist/index.js +1 -1
- package/dist/{layout-shaping-C889tgmj.d.ts → layout-shaping-BvZD_VKP.d.ts} +1 -1
- package/dist/layout.cjs +1 -1
- package/dist/layout.d.ts +104 -202
- package/dist/layout.js +1 -1
- package/dist/{note-properties-CmfvOJsi.d.ts → note-properties-CkAk7g-n.d.ts} +1 -1
- package/dist/{omml-equation-CZ6IG2ja.d.ts → omml-equation-DuczgG5o.d.ts} +1 -1
- package/dist/output.cjs +1 -1
- package/dist/output.d.ts +8 -7
- package/dist/output.js +1 -1
- package/dist/{protocol-BhmenALD.d.ts → protocol-aKYr8r3u.d.ts} +34 -6
- package/dist/{review-paragraph-order-BwhRT264.d.ts → review-paragraph-order-Ddj5d6rp.d.ts} +6 -2
- package/dist/{revision-projection-DfWxdBqA.d.ts → revision-projection-CSNFudZY.d.ts} +74 -3
- package/dist/{semantic-cell-selection-CC3NwCtx.d.ts → semantic-cell-selection-DoqYCz_F.d.ts} +25 -7
- package/dist/{semantic-interaction-BHlV61hK.d.ts → semantic-interaction-G0bjmmmk.d.ts} +1 -1
- package/dist/{semantic-paint-DfWIWUs6.d.ts → semantic-paint-CsMzF8-O.d.ts} +57 -5
- package/dist/semantic-record-queries-1du6lQqS.d.ts +177 -0
- package/dist/{semantic-records-DrExlBy-.d.ts → semantic-records-B9OolWGN.d.ts} +91 -74
- package/dist/store.cjs +1 -1
- package/dist/store.d.ts +74 -17
- package/dist/store.js +1 -1
- package/dist/{tree-package-fragment-YPyYC1aD.d.ts → tree-package-fragment-DYZIk1rY.d.ts} +3 -3
- package/dist/{tree-session-contract-AeY2v0x9.d.ts → tree-session-contract-DQVJOOkv.d.ts} +5 -5
- package/dist/{types-barrel-BO73JqHG.d.ts → types-barrel-BFKR8Pzp.d.ts} +134 -110
- package/package.json +4 -4
- package/dist/chunk-3RMHRNDA.cjs +0 -1
- package/dist/chunk-42N7OV3G.cjs +0 -1
- package/dist/chunk-47ZJEEBT.js +0 -2
- package/dist/chunk-4B3SXBV6.js +0 -4
- package/dist/chunk-5MWFZ7F4.cjs +0 -11
- package/dist/chunk-AS2OC6J4.cjs +0 -26
- package/dist/chunk-B7SYEMZ7.cjs +0 -1
- package/dist/chunk-BME2KUNL.cjs +0 -1
- package/dist/chunk-CDGVVEUK.js +0 -26
- package/dist/chunk-E4RAPI5J.cjs +0 -2
- package/dist/chunk-FZJTQPH4.js +0 -2
- package/dist/chunk-H7XMRUAO.cjs +0 -5
- package/dist/chunk-ILUE2SI5.js +0 -1
- package/dist/chunk-IZT3C23R.js +0 -1
- package/dist/chunk-KJLPVGSX.cjs +0 -4
- package/dist/chunk-LF5LPZOP.cjs +0 -18
- package/dist/chunk-N5WE5O5Q.js +0 -1
- package/dist/chunk-OVDW4XQD.cjs +0 -2
- package/dist/chunk-SNN53UPD.js +0 -1
- package/dist/chunk-TKQH7BNE.cjs +0 -1
- package/dist/chunk-V7LBEUVW.js +0 -5
- package/dist/chunk-VE7YBFQD.js +0 -5
- package/dist/chunk-VOVDX7GW.js +0 -18
- package/dist/chunk-VQ33XGNP.cjs +0 -5
- package/dist/chunk-XUJINXW6.js +0 -1
- package/dist/chunk-Y3TPAITU.cjs +0 -1
- package/dist/chunk-Z65JJLLF.js +0 -11
package/dist/chunk-E4RAPI5J.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';var chunkY3TPAITU_cjs=require('./chunk-Y3TPAITU.cjs'),chunkLF5LPZOP_cjs=require('./chunk-LF5LPZOP.cjs'),chunk3RMHRNDA_cjs=require('./chunk-3RMHRNDA.cjs'),chunkH7XMRUAO_cjs=require('./chunk-H7XMRUAO.cjs'),chunk5MWFZ7F4_cjs=require('./chunk-5MWFZ7F4.cjs');function ii(t){let e=[];for(let o of t.pages){let n=o.pageFieldSource?.pageNumber??o.index+1,a=chunkLF5LPZOP_cjs.Wc(n,o.pageFieldSource?.format),i=l=>{for(let d of l)if(d.kind==="paragraph")for(let u of d.lines)e.push({...u.range,pageNumber:n,pageNumberText:a});else for(let u of d.rows)for(let p of u.cells)i(p.blocks);};i(o.fragments),o.header&&i(o.header.fragments),o.footer&&i(o.footer.fragments);for(let l of o.footnotes?.notes??[])i(l.fragments);for(let l of o.endnotes?.notes??[])i(l.fragments);}return {pageCount:t.pages.length,ranges:e}}function Os(t,e,o,n){if(!t||!Number.isInteger(t.pageCount)||t.pageCount<1)return null;let a=chunk5MWFZ7F4_cjs.Ja(e,o);if(!a||a.kind!=="paragraph")return null;let i=chunk5MWFZ7F4_cjs.of(a).find(d=>d.node.id===n);if(!i)return null;let l=t.ranges.find(d=>d.paragraphId===o&&d.start<=i.start&&d.end>i.start);return !l||!Number.isInteger(l.pageNumber)||l.pageNumber<1?null:{pageNumber:l.pageNumber,pageNumberText:l.pageNumberText,pageCount:t.pageCount}}function Rs(t){return async e=>{let o=chunkY3TPAITU_cjs.e(e,{measurer:t.measurer,producer:t.producer,displayMode:"proposed"});if(!o.ok)throw new Error("field pagination could not open the document");try{return ii(await o.session.layout())}finally{o.session.dispose();}}}var Be=Object.freeze(["default","first","even"]),Pt=Object.freeze({kind:"body"});function Q(t){switch(t.kind){case "body":return "body";case "note":return `note:${t.noteKind}:${String(t.noteId)}`;default:return `${t.kind}:${String(t.sectionIndex)}:${t.variant}`}}function dr(t){if(typeof t!="object"||t===null)return false;let e=t;return e.kind==="body"?true:e.kind==="note"?(e.noteKind==="footnote"||e.noteKind==="endnote")&&Number.isInteger(e.noteId):e.kind!=="header"&&e.kind!=="footer"?false:Number.isInteger(e.sectionIndex)&&e.sectionIndex>=0&&Be.includes(e.variant)}var si=["getTables","getTable","getTableRows","getTableCells","getTableCell","getTableCellProperties","getTableCellBody","getFields","getField","getInlinePictures","getInlinePicture","getChangeTrackingMode","getDocument","getDocumentProperty","getBody","getParagraphs","getRange","getSpanParagraphs","getText","getSpanText","getParagraphId","search","getFont","getParagraphFormat","getStyle","getSections","getPageSetup","getFurniture","getNotes","getNoteBody","getNoteText","getNoteKind","getLists","getListId","getListById","getListParagraphs","getParagraphList","getListLevel","getHyperlink","getBookmarks","getBookmarkName","getBookmarkRange","getComments","getCommentReplies","getCommentId","getCommentAuthor","getCommentDate","getCommentText","getCommentRange","getCommentResolved","getRevisions","getRevisionType","getRevisionAuthor","getRevisionDate","getRevisionRange","getContentControls","getContentControlById","getContentControlsByTag","getContentControlsByTitle","getContentControlTag","getContentControlTitle","getContentControlFileId","getContentControlSubtype","getContentControlLock","getContentControlIsBound","getContentControlPlaceholderShown","getContentControlTemporary","getContentControlText","getContentControlParagraphs","getContentControlRange"],ur=["removeDocumentInformation","setDocumentProperties","insertTableRows","insertTable","updateTable","updateTableCell","setInlinePicture","deleteInlinePicture","insertField","setFieldCode","deleteField","updateFieldResult","insertInlinePicture","insertBreak","setChangeTrackingMode","proposeInsertion","proposeDeletion","proposeReplacement","insertText","replaceSpan","replaceStoryBlocks","insertParagraph","splitParagraph","deleteParagraph","selectSpan","selectBookmark","setFont","setParagraphFormat","setStyle","setPageSetup","deleteNote","setListLevel","startNewList","attachToList","detachFromList","setListLevelFormat","insertListParagraph","setHyperlink","insertComment","setCommentResolved","replyToComment","deleteComment","acceptRevision","rejectRevision","resolveRevisionBatch","acceptAllRevisions","rejectAllRevisions","setContentControlValue","setContentControlProperties","deleteContentControl","insertContentControlText","insertContentControl","insertCustomNode"],cr=["removeDocumentInformation","insertTableRows","resolveRevisionBatch","insertTable","insertInlinePicture","insertBreak","startNewList","deleteNote","insertComment","setCommentResolved","replyToComment","insertCustomNode"],li=new Set(cr);function _e(t){return li.has(t.op)||t.op==="updateTable"&&["addRows","addColumns","deleteRows","deleteColumns","delete"].includes(t.mutation.kind)}var di=new Set(ur);function Bt(t){return di.has(t.op)}var ui=63360;function Ft(t){return Math.round(chunk5MWFZ7F4_cjs.Af(chunk5MWFZ7F4_cjs.yf(t))*100)/100}function ci(t,e){if(typeof t!="number"||!Number.isFinite(t))return null;let o=chunk5MWFZ7F4_cjs.Bf(chunk5MWFZ7F4_cjs.zf(t));return o>ui||o<0||o===0&&!e?null:o}var pi=[["pageWidth","pageWidthTwips",false],["pageHeight","pageHeightTwips",false],["topMargin","marginTopTwips",true],["rightMargin","marginRightTwips",true],["bottomMargin","marginBottomTwips",true],["leftMargin","marginLeftTwips",true]];function pr(t){if(typeof t!="object"||t===null)return {ok:false,reason:"that is not a page setup",detail:"not-an-object"};let e=t,o={},n=0;for(let[i,l,d]of pi){let u=e[i];if(u===void 0)continue;let p=ci(u,d);if(p===null)return {ok:false,reason:`that is not a value for ${i}`,detail:String(u)};o[l]=p,n+=1;}let a=e.orientation;if(a!==void 0){if(a!=="portrait"&&a!=="landscape")return {ok:false,reason:"that is not an orientation",detail:String(a)};o.orientation=a,n+=1;}return n===0?{ok:false,reason:"that page setup names nothing to write",detail:"empty"}:{ok:true,value:o}}function mi(t){let e=chunk5MWFZ7F4_cjs.Ri(t),o=e.widthTwips>e.heightTwips?"landscape":"portrait";return Object.freeze({pageWidth:Ft(e.widthTwips),pageHeight:Ft(e.heightTwips),orientation:o,topMargin:Ft(e.topTwips),rightMargin:Ft(e.rightTwips),bottomMargin:Ft(e.bottomTwips),leftMargin:Ft(e.leftTwips),headerDistance:Ft(e.headerTwips),footerDistance:Ft(e.footerTwips),gutter:Ft(e.gutterTwips)})}function fi(t,e){if(!e)return null;let o=null,n=(a,i,l)=>{if(o!==null||a.kind==="textValue"||l>64)return;let d=a.kind==="paragraph"?a.id:i;if(a.id===e.id){o=d;return}for(let u of a.children)n(u,d,l+1);};return n(t.root,null,0),o}function mr(t,e,o){let n=chunk5MWFZ7F4_cjs.oe(e.root);return Object.freeze(n.map((a,i)=>{let l=o[i];return Object.freeze({index:i,markParagraphId:fi(e,a),pageSetup:mi(a),titlePage:l?.titlePage??false,evenAndOddHeaders:l?.evenAndOddHeaders??false})}))}var gi=255,yi=Object.freeze({nameOf:()=>null,idOf:()=>null,defaultId:null,present:false});function fr(t){let e=chunk5MWFZ7F4_cjs.Sc(t);if(!e)return yi;let o=new Map,n=new Map,a=null;for(let i of chunk5MWFZ7F4_cjs.Rc(e).values())if(i.type==="paragraph"){if(o.set(i.styleId,i.name),i.name!==null){let l=i.name.trim().toLowerCase();n.has(l)||n.set(l,i.styleId);}i.isDefault&&a===null&&(a=i.styleId);}return Object.freeze({nameOf:i=>o.get(i)??null,idOf:i=>n.get(i.trim().toLowerCase())??null,defaultId:a,present:true})}function Ve(t,e,o){let n=chunk5MWFZ7F4_cjs.Ja(t,e);if(!n||n.kind!=="paragraph")return null;let a=hi(chunk5MWFZ7F4_cjs.mf(chunk5MWFZ7F4_cjs.kf(n),"pStyle"));return a!==null?o.nameOf(a):o.defaultId===null?null:o.nameOf(o.defaultId)}function hi(t){if(!t)return null;for(let e of t.attributes)if(e.localName==="val")return e.value;return null}function We(t,e){if(typeof t!="string"||t.trim().length===0)return {ok:false,detail:"style: not a name"};if(t.length>gi)return {ok:false,detail:"style: name too long"};if(!chunk5MWFZ7F4_cjs.O(t))return {ok:false,detail:"style: not valid XML text"};if(!e.present)return {ok:false,detail:"style: this document defines no styles"};let o=e.idOf(t);return o===null?{ok:false,detail:"style: this document defines no paragraph style with that name"}:{ok:true,styleId:o}}function gr(t,e,o){return e>=o?null:{text:t.text.slice(e-t.rawStart,o-t.rawStart),rawStart:e,rawEnd:o}}function ki(t,e){let o=[],n=0;for(let a of t){for(;n<e.length&&e[n].end<=a.rawStart;)n+=1;let i=a.rawEnd-a.rawStart;if(a.text.length!==i){let u=e[n];(!u||u.start>=a.rawEnd)&&o.push(a);continue}let l=a.rawStart;for(;n<e.length;){let u=e[n];if(u.end<=l){n+=1;continue}if(u.start>=a.rawEnd)break;let p=gr(a,l,Math.min(u.start,a.rawEnd));if(p&&o.push(p),l=Math.max(l,u.end),u.end<=a.rawEnd&&(n+=1),l>=a.rawEnd)break}let d=gr(a,l,a.rawEnd);d&&o.push(d);}return o}function Ue(t,e,o){if(o==="model")return chunk3RMHRNDA_cjs.b(e);let n=chunk3RMHRNDA_cjs.c(t,e,o);if(o==="allMarkup")return chunk3RMHRNDA_cjs.a(n);let a=xi(t);if(a.length===0)return chunk3RMHRNDA_cjs.a(n);let i=ki(n,a);return chunk3RMHRNDA_cjs.a(i)}function xi(t){let e=chunk5MWFZ7F4_cjs.qf(t),o=[],n=(i,l)=>{if(!(l>64||i.kind==="textValue")){if(i.kind==="revisionInsert"||i.kind==="revisionMoveTo"){let d=e.spanOf(i);d&&d.end>d.start&&o.push({start:d.start,end:d.end});return}for(let d of i.children)n(d,l+1);}};n(t,0),o.sort((i,l)=>i.start-l.start||l.end-i.end);let a=[];for(let i of o){let l=a[a.length-1];l&&i.start<=l.end?l.end=Math.max(l.end,i.end):a.push({...i});}return a}var bn="\r",bi=Object.freeze({nameOf:()=>null,idOf:()=>null,defaultId:null,present:false}),vi=Object.freeze([]),Ai=Object.freeze([]),yr=Object.freeze([]),Ii=Object.freeze({package:null,body:null,story:()=>null,storyOf:()=>null,sections:()=>Ai,furniture:()=>yr,noteIds:()=>({ok:true,ids:hr}),styles:()=>bi});function Pi(t){return t.kind==="textValue"?vi:Object.freeze(t.children.filter(e=>e.kind!=="textValue").map(e=>{let o=[];chunk5MWFZ7F4_cjs.Hc([e],o,0);let n=e.kind==="paragraph"?"paragraph":e.kind==="table"?"table":"other",a=e.kind==="paragraph"&&chunk5MWFZ7F4_cjs.mf(chunk5MWFZ7F4_cjs.kf(e),"sectPr")!==void 0;return Object.freeze({id:e.id,kind:n,paragraphIds:Object.freeze(o.map(i=>i.id)),removable:n!=="other"&&!a})}))}function $e(t,e,o,n,a){let i=chunk5MWFZ7F4_cjs.Gc(n),l=Object.freeze(i.map(m=>m.id)),d=new Map,u=new Map;i.forEach((m,k)=>{d.set(m.id,k),u.set(m.id,m);});let p=new Map,h=m=>{if(!d.has(m))return null;let k=p.get(m);if(k!==void 0)return k;let A=chunk5MWFZ7F4_cjs.Cj(e,m)??"";return p.set(m,A),A},g=new Map,v=(m,k="allMarkup")=>{let A=u.get(m);if(!A||A.kind!=="paragraph")return null;let P=`${m}:${k}`,w=g.get(P);if(w)return w;let N=Ue(A,h(m)??"",k);return g.set(P,N),N};return {story:t,part:e,root:n,scope:o,paragraphIds:l,blocks:Pi(n),has:m=>d.has(m),indexOf:m=>d.get(m)??-1,paragraph(m){let k=u.get(m);return k?{nodeId:m,paraId:chunk5MWFZ7F4_cjs.Ya(k),text:v(m)?.text??""}:null},node:m=>u.get(m)??null,rawText:h,paragraphText:(m,k)=>v(m,k)?.text??null,projectedText:v,text:m=>l.map(k=>v(k,m)?.text??"").join(bn),styles:a}}function Ke(t,e){let o=$e(t.story,t.part,t.scope,e,t.styles);return {...o,indexOf:n=>o.has(n)?t.indexOf(n):-1}}function ke(t){let e=t.parts.get(t.mainDocumentPart);if(!e)return Ii;let o,n=()=>o??=fr(t),a,i=()=>a??=chunk5MWFZ7F4_cjs.qe(t),l,d=new Map,u=new Map,p=k=>{let A=u.get(k);if(A)return A;let P=chunk5MWFZ7F4_cjs.pg(t,k);if(!P){let S={ok:true,ids:hr};return u.set(k,S),S}let w=[],N=new Set,L=new Set,D=0,M=false;for(let S of P.root.children){if(chunk5MWFZ7F4_cjs.mc(S)!==k)continue;if(D+=1,S.kind!=="note"){M=true;continue}if(!chunk5MWFZ7F4_cjs.pc(S))continue;let _=chunk5MWFZ7F4_cjs.nc(S);if(_===null){M=true;continue}N.has(_)?L.add(_):(N.add(_),w.push(_));}let j=D>chunk5MWFZ7F4_cjs.wc?{ok:false,reason:"truncated"}:M?{ok:false,reason:"malformed"}:L.size>0?{ok:false,reason:"duplicates",duplicateIds:Object.freeze([...L])}:{ok:true,ids:Object.freeze(w)};return u.set(k,j),j},h=k=>{let A=i()[k.sectionIndex];return A?(k.kind==="header"?A.headers:A.footers).get(k.variant)??null:null},g=k=>{if(k.kind==="body"){let P=chunk5MWFZ7F4_cjs.Fc(e);return P?$e(k,e,{kind:"body"},P,n):null}if(k.kind==="note"){let P=p(k.noteKind);if(!P.ok||!P.ids.includes(k.noteId))return null;let w=chunk5MWFZ7F4_cjs.pg(t,k.noteKind);if(!w)return null;let N=chunk5MWFZ7F4_cjs.Ac(w.root,k.noteId);return !N||!chunk5MWFZ7F4_cjs.pc(N)?null:$e(k,w,{kind:"notesPart",noteKind:k.noteKind},N,n)}let A=h(k);return A?$e(k,A.part,{kind:"headerFooter",rId:A.rId},A.part.root,n):null},v=k=>{let A=Q(k);if(d.has(A))return d.get(A)??null;let P=g(k);return d.set(A,P),P};return {package:t,get body(){return v(Pt)},story:v,storyOf:k=>{if(v(Pt)?.has(k))return Pt;for(let[P]of i().entries())for(let w of ["header","footer"])for(let N of Be){let L={kind:w,sectionIndex:P,variant:N};if(v(L)?.has(k))return L}for(let P of ["footnote","endnote"]){let w=p(P);if(w.ok)for(let N of w.ids){let L={kind:"note",noteKind:P,noteId:N};if(v(L)?.has(k))return L}}return null},sections:()=>l??=mr(t,e,i()),furniture(k){let A=i()[k];if(!A)return yr;let P=[];for(let w of ["header","footer"]){let N=w==="header"?A.headers:A.footers;for(let L of Be){let D=N.get(L);D&&P.push(Object.freeze({kind:w,variant:L,declared:!D.inherited}));}}return Object.freeze(P)},noteIds:p,styles:n}}var hr=Object.freeze([]);function kr(t,e,o){let n=a=>({state:o,step:{ok:false,error:{code:"unsupported-capability",message:a,detail:"changeTrackingMode"}}});return t.op==="getChangeTrackingMode"||t.op==="setChangeTrackingMode"?e?t.op==="getChangeTrackingMode"?{state:o,step:{ok:true,kind:"query",value:{kind:"text",text:o.mode}}}:t.mode!=="Off"&&t.mode!=="TrackMineOnly"?n("TrackAll requires shared tracking enforcement for every peer and is not supported"):t.mode==="TrackMineOnly"&&(typeof t.author!="string"||!t.author.trim()||!chunk5MWFZ7F4_cjs.O(t.author))?n("TrackMineOnly requires a non-empty XML-safe runtime author"):{state:{mode:t.mode,...t.mode==="TrackMineOnly"?{author:t.author.trim()}:{}},step:{ok:true,kind:"query",value:{kind:"applied"}}}:n("this host does not support runtime-local change tracking"):o.mode==="Off"||vn(t)?null:n(`${t.op} does not support TrackMineOnly; no permanent edit was applied`)}function vn(t){return !Bt(t)||t.op==="setChangeTrackingMode"||t.op==="insertText"||t.op==="insertTable"||t.op==="insertTableRows"||t.op==="updateTable"||t.op==="updateTableCell"||t.op==="replaceSpan"&&!("body"in t.span)?true:["insertContentControl","setContentControlProperties","startNewList","setListLevelFormat","attachToList","detachFromList","setListLevel","insertParagraph","setFont","setStyle","setParagraphFormat","proposeInsertion","proposeDeletion","proposeReplacement","insertComment","replyToComment","deleteComment","setCommentResolved","acceptRevision","rejectRevision","resolveRevisionBatch","acceptAllRevisions","rejectAllRevisions","selectSpan","selectBookmark"].includes(t.op)}function xr(t,e,o){if(!o||!["setFont","setStyle","setParagraphFormat","insertParagraph","attachToList","detachFromList","setListLevel"].includes(t.op)||!e.ok||e.kind!=="command")return e;let n={author:o,date:new Date().toISOString()};return {...e,ops:e.ops.map(a=>{if(a.op==="insertText")return {...a,revision:n};if(a.op==="splitParagraph")return {op:"splitParagraphMany",paragraphId:a.paragraphId,offsets:[a.offset],revision:n};if(a.op==="setRunProperties"||a.op==="setParagraphProperties"||a.op==="setParagraphMarkProperties"||a.op==="setListNumbering"||a.op==="setListLevel")return {...a,revision:n};throw new Error("Formatting plan contains an operation without property revision support")})}}function Oi(){let t=globalThis.crypto,e=t?.getRandomValues;if(typeof e!="function")throw new Error("automation: no secure random source. globalThis.crypto.getRandomValues is required to scope document handles to one host.");let o=e.call(t,new Uint8Array(16)),n="";for(let a of o)n+=a.toString(16).padStart(2,"0");return n}function Ri(t){return typeof t=="object"&&t!==null&&"kind"in t&&"ref"in t}function br(){let t=new Map,e=new Map,o=new Map,n=new Map,a=Oi(),i=null,l=(u,p)=>{let h=(n.get(u)??0)+1;n.set(u,h);let g=`${u}:${a}:${String(h)}`;return t.set(g,p),Object.freeze({kind:u,ref:g})},d=(u,p,h)=>{let g=`${u}\0${p}`,v=o.get(g);if(v)return Object.freeze({kind:u,ref:v});let m=l(u,h);return o.set(g,m.ref),m};return {document(){return i??=l("document",{kind:"document"}),i},body(u,p){return d("body",`${Q(u)}:${p??""}`,{kind:"body",story:u,...p?{rootNodeId:p}:{}})},table(u,p){return d("table",`${Q(p)}:${u}`,{kind:"table",nodeId:u,story:p})},tableRow(u,p){return d("tableRow",`${Q(p)}:${u}`,{kind:"tableRow",nodeId:u,story:p})},tableCell(u,p){return d("tableCell",`${Q(p)}:${u}`,{kind:"tableCell",nodeId:u,story:p})},field(u,p,h){return d("field",`${Q(h)}:${p}`,{kind:"field",paragraphId:u,fieldNodeId:p,story:h})},inlinePicture(u,p){return d("inlinePicture",`${Q(p)}:${u}`,{kind:"inlinePicture",drawingNodeId:u,story:p})},paragraph(u,p){let h=e.get(u);if(h)return Object.freeze({kind:"paragraph",ref:h});let g=l("paragraph",{kind:"paragraph",paragraphId:u,story:p});return e.set(u,g.ref),g},section(u){return d("section",String(u),{kind:"section",index:u})},note(u,p){return d("note",`${u}:${String(p)}`,{kind:"note",noteKind:u,noteId:p})},comment(u,p){return d("comment",`${Q(p)}\0${u}`,{kind:"comment",commentId:u,story:p})},revision(u,p){return d("revision",`${Q(p)}\0${u}`,{kind:"revision",revisionId:u,story:p})},bookmark(u,p){return d("bookmark",`${Q(p)}\0${u}`,{kind:"bookmark",name:u,story:p})},list(u,p){return d("list",`${Q(p)}\0${u}`,{kind:"list",numId:u,story:p})},contentControl(u,p){return d("contentControl",`${Q(p)}\0${u}`,{kind:"contentControl",nodeId:u,story:p})},retarget(u,p){let h=e.get(u);if(!h||u===p)return;let g=t.get(h);!g||g.kind!=="paragraph"||(e.delete(u),t.set(h,{kind:"paragraph",paragraphId:p,story:g.story}),e.has(p)||e.set(p,h));},resolve(u,p){if(!Ri(u)||u.kind!==p||typeof u.ref!="string")return null;let h=t.get(u.ref);return !h||h.kind!==p?null:h}}}var An="http://schemas.openxmlformats.org/package/2006/relationships",vr="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Si=[{type:"application/vnd.openxmlformats-package.core-properties+xml",namespace:"http://schemas.openxmlformats.org/package/2006/metadata/core-properties",root:"coreProperties",relationship:`${An}/metadata/core-properties`},{type:"application/vnd.openxmlformats-officedocument.extended-properties+xml",namespace:"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties",root:"Properties",relationship:`${vr}/extended-properties`},{type:"application/vnd.openxmlformats-officedocument.custom-properties+xml",namespace:"http://schemas.openxmlformats.org/officeDocument/2006/custom-properties",root:"Properties",relationship:`${vr}/custom-properties`}];function In(t){let e=new Map;for(let n of Si){let a=[...new Set([...t.parts.keys(),...t.partBytes.keys()])].filter(u=>chunk5MWFZ7F4_cjs._d(t,u)===n.type);if(a.length>1)return null;let i=(t.relationships.get("/")??[]).filter(u=>u.type===n.relationship);if(i.length>1)return null;let l=i[0];if(l){if(l.targetMode!=="Internal")return null;let u=chunk5MWFZ7F4_cjs.w("/",l.rawTarget);if(!u.ok||a.length!==1||chunk5MWFZ7F4_cjs.u(u.partName)!==chunk5MWFZ7F4_cjs.u(a[0]))return null}if(a.length===0)continue;let d=t.parts.get(a[0]);if(!d||d.root.namespaceUri!==n.namespace||d.root.localName!==n.root||(t.relationships.get(d.name)?.length??0)>0||t.parts.has(chunk5MWFZ7F4_cjs.$d(d.name))||t.partBytes.has(chunk5MWFZ7F4_cjs.$d(d.name)))return null;e.set(chunk5MWFZ7F4_cjs.u(d.name),{part:d,relationship:n.relationship});}if(e.size===0)return t;if(!chunk5MWFZ7F4_cjs.Wa(t,new Set(e.keys())))return null;for(let[n,a]of t.relationships)for(let i of a){if(i.targetMode==="External")continue;let l=chunk5MWFZ7F4_cjs.w(n,i.rawTarget),d=l.ok&&e.get(chunk5MWFZ7F4_cjs.u(l.partName));if(!d)continue;if(n!=="/"||i.type!==d.relationship)return null;let u=t.parts.get(chunk5MWFZ7F4_cjs.$d(n));if(!u||u.root.namespaceUri!==An||u.root.localName!=="Relationships")return null;let p=u.root.children.filter(g=>g.kind!=="textValue"&&g.attributes.some(v=>v.namespaceUri===""&&v.localName==="Id"&&v.value===i.id));if(p.length!==1)return null;let h=p[0];if(h.kind==="textValue"||h.namespaceUri!==An||h.localName!=="Relationship"||h.attributes.some(g=>g.namespaceUri!==""||!["Id","Type","Target","TargetMode"].includes(g.localName))||h.children.some(g=>g.kind!=="textValue"||!chunk5MWFZ7F4_cjs.Va(g.value)))return null}let o=t;for(let{part:n}of e.values()){let a=chunk5MWFZ7F4_cjs.ce(o,n.name);if(!a.ok||a.pkg.contentTypes.overrides.has(chunk5MWFZ7F4_cjs.u(n.name)))return null;o=a.pkg;}return o}var re="http://schemas.openxmlformats.org/package/2006/metadata/core-properties",ze="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties",xe="http://purl.org/dc/elements/1.1/",Pn="application/vnd.openxmlformats-package.core-properties+xml",On={author:[xe,"creator"],title:[xe,"title"],subject:[xe,"subject"],comments:[xe,"description"],keywords:[re,"keywords"],category:[re,"category"]},Ar={...On,lastAuthor:[re,"lastModifiedBy"]},Ir=Object.keys(Ar);function Ge(t){let e=(t.relationships.get("/")??[]).find(n=>n.type===ze);if(!e||e.targetMode!=="Internal")return null;let o=chunk5MWFZ7F4_cjs.w("/",e.rawTarget);return o.ok?t.parts.get(o.partName)??null:null}function Pr(t,e){let o=Ge(t),[n,a]=Ar[e],i=o?.root.children.find(l=>l.kind!=="textValue"&&l.namespaceUri===n&&l.localName===a);return i&&i.kind!=="textValue"?i.children.map(l=>l.kind==="textValue"?l.value:"").join(""):""}function Rn(t){if(!t||typeof t!="object"||Array.isArray(t))return false;let e=Object.entries(t);return e.length>0&&e.every(([o,n])=>Object.hasOwn(On,o)&&typeof n=="string"&&n.length<=4096&&chunk5MWFZ7F4_cjs.O(n))}function Sn(t,e){if(!Rn(e)||(t.relationships.get("/")??[]).filter(d=>d.type===ze).length>1)return null;let o=Ge(t);if(o&&(o.contentType!==Pn||o.root.namespaceUri!==re||o.root.localName!=="coreProperties")||!o&&(t.relationships.get("/")??[]).some(d=>d.type===ze))return null;let n=o?.name??"/docProps/core.xml";if(!o&&(t.parts.has(n)||t.partBytes.has(n)))return null;let a=chunk5MWFZ7F4_cjs.za(`<cp:coreProperties xmlns:cp="${re}" xmlns:dc="${xe}">${Object.entries(e).map(([d,u])=>{let[p,h]=On[d],g=p===re?"cp":"dc";return `<${g}:${h}>${chunk5MWFZ7F4_cjs.M(u)}</${g}:${h}>`}).join("")}</cp:coreProperties>`,{name:n,contentType:Pn});if(!a.ok)return null;if(o){let d=o,u=chunk5MWFZ7F4_cjs.Ha(o),p=h=>h.kind==="textValue"?{...h,id:u()}:{...h,id:u(),children:h.children.map(p)};for(let h of a.part.root.children){if(h.kind==="textValue")continue;let g=d.root.children.filter(k=>k.kind!=="textValue"&&k.namespaceUri===h.namespaceUri&&k.localName===h.localName);if(g.length>1)return null;let v=g[0],m;if(v&&v.kind!=="textValue"){if(v.children.some(w=>w.kind!=="textValue"))return null;let k=v.children.length===1&&v.children[0]?.kind==="textValue"?v.children[0]:null,A=h.children.find(w=>w.kind==="textValue"),P=k&&A?.kind==="textValue"?[{...k,value:A.value}]:h.children.map(p);m=chunk5MWFZ7F4_cjs.Oa(d,v.id,{...v,children:P});}else {let k=Array.from(d.root.children);k.push(p(h)),m=chunk5MWFZ7F4_cjs.Ma(d,d.root.id,k);}if(!m.ok)return null;d=m.part;}return chunk5MWFZ7F4_cjs.Xd(t,d)}let i=chunk5MWFZ7F4_cjs.fe(t,n,a.part.root,Pn);if(!i.parts.has(n))return null;let l=chunk5MWFZ7F4_cjs.ee(i,"/",ze,n.slice(1));return l.ok?l.pkg:null}function Or(t,e,o,n=true){let a=d=>({ok:false,error:{code:"unsupported-content",message:d}});if(!e.package)return a("document unavailable");if(t.op==="getDocumentProperty")return Ir.includes(t.name)?{ok:true,kind:"query",value:{kind:"text",text:Pr(e.package,t.name)}}:a("unsupported document property");if(t.op==="removeDocumentInformation"){if(t.removeDocInfoType!=="DocumentProperties"||!n)return {ok:false,error:{code:"unsupported-capability",message:"Only direct DocumentProperties removal outside collaboration is supported."}};if(!In(e.package))return {ok:false,error:{code:"unsupported-capability",message:"Document property parts have unsupported structure or dependencies."}};let d=o();return d||{ok:true,kind:"command",story:Pt,ops:[],packageEdits:[u=>{let p=In(u);if(!p)throw new Error("Document property parts changed");return p}],answer:()=>({kind:"applied"})}}if(!Rn(t.values))return a("invalid document property values");if(!n&&!Ge(e.package))return {ok:false,error:{code:"unsupported-capability",message:"Create document properties before joining collaboration; concurrent core-part creation cannot merge safely."}};let i={...t.values};if(!Sn(e.package,i))return {ok:false,error:{code:"unsupported-capability",message:"the core properties part cannot be updated safely"}};let l=o();return l||{ok:true,kind:"command",story:Pt,ops:[],packageEdits:[d=>{let u=Sn(d,i);if(!u)throw new Error("Document properties package changed");return u}],answer:()=>({kind:"applied"})}}function Rr(t,e){let o=[],n=new Set,a=i=>{if(i.kind!=="textValue"){if(i.namespaceUri===chunk5MWFZ7F4_cjs.fa&&i.localName===`${e}Reference`){let l=chunk5MWFZ7F4_cjs.nc(i)??Number.NaN;n.has(l)||(o.push(l),n.add(l));}for(let l of i.children)a(l);}};return a(t),o}var Sr=new WeakMap,Ci=0;function wi(t){if(!t)return;let e=Sr.get(t);return e||(e={...t,cacheKey:`formatting-${++Ci}`},Sr.set(t,e)),e}function Cr(t){let e=new WeakMap;return (o,n,a,i)=>{let l=wi(i),d=chunk5MWFZ7F4_cjs.Ka(o,n.id),u;for(;d&&d.kind!=="table";){if(d.localName==="txbxContent")return;d.kind==="tableCell"&&(u=d.id),d=chunk5MWFZ7F4_cjs.Ka(o,d.id);}if(!d||!u)return;let p=e.get(d);if(!p||p.mode!==a||p.filter!==l){let h=new Map,g=chunkLF5LPZOP_cjs.Cd(d,1,0,t,a,l);for(let v of g?.rows??[])for(let m of v.cells)h.set(m.id,m.styleFormatting);p={mode:a,filter:l,cells:h},e.set(d,p);}return p.cells.get(u)}}var wr={},Tr=new WeakMap;function Nr(t,e=null,o="all-markup",n){let a=t??wr,i=Tr.get(a);i||Tr.set(a,i=new WeakMap);let l=e??wr,d=i.get(l);d||i.set(l,d=Ti(t,e));let u=d;return (p,h,g,v,m=o,k=n)=>u(p,h,g,v,m,k)}function Ti(t,e){let o=chunkLF5LPZOP_cjs.cc(t,void 0,e),n=Cr(o),a=new WeakMap;return (i,l,d,u,p="all-markup",h)=>{let g=n(u,i,p,h),v=a.get(i);if(!v||v.cellStyle!==g){let w=chunkLF5LPZOP_cjs.dc(o,chunk5MWFZ7F4_cjs.Lg(i,"paragraphProperties","pPr"),g);v={cellStyle:g,inherited:w},a.set(i,v);}let{inherited:m}=v,k=d?m.markRunProperties:chunkLF5LPZOP_cjs.fc(m.runProperties,chunkLF5LPZOP_cjs.bb(l),o),A=false,P=false;for(let w of k){if(w.localName!=="rtl"&&w.localName!=="cs")continue;let N=w.attributes?.val,L=N===void 0||["1","true","on"].includes(N);w.localName==="rtl"?A=L:P=L;}return A||P}}function Er(t,e=()=>null,o=()=>"all-markup",n=()=>{}){return {runPropertyEdits(...a){return chunk5MWFZ7F4_cjs._g(a[0],a[1],a[2],a[3],a[4],a[5],a[6],Nr(t(),e(),o(),n()))},mergedParagraphMarkProperties(...a){return chunk5MWFZ7F4_cjs.Vg(a[0],a[1],a[2],Nr(t(),e(),o(),n()))}}}function Ot(t,e){return {ok:false,code:t,detail:e}}function Rt(t){return {ok:true,value:t}}function lt(t,e,o,n){let a=o.resolve(t,e);if(!a||a.kind!=="body"&&a.kind!=="paragraph")return Ot("invalid-handle",`not-a-${e}-handle`);let i=n.story(a.story);if(!i)return Ot("invalid-handle",`no-such-story:${Q(a.story)}`);if(a.kind==="body"&&a.rootNodeId){let l=chunk5MWFZ7F4_cjs.Ja(i.part,a.rootNodeId);return !l||l.kind!=="tableCell"?Ot("invalid-handle","cell no longer exists"):Rt(Ke(i,l))}return Rt(i)}function kt(t,e,o){let n=e.resolve(t,"paragraph");if(!n||n.kind!=="paragraph")return Ot("invalid-handle","not-a-paragraph-handle");let a=o.story(n.story);if(!a)return Ot("invalid-handle",`no-such-story:${Q(n.story)}`);let i=a.indexOf(n.paragraphId);return i<0?Ot("invalid-handle","paragraph-not-in-body"):Rt({story:n.story,paragraphId:n.paragraphId,index:i,offset:0})}function Ni(t,e,o){let n=kt(t.paragraph,e,o);if(!n.ok)return n;let i=(o.story(n.value.story)?.rawText(n.value.paragraphId)??"").length,{offset:l}=t;return !Number.isInteger(l)||l<0||l>i?Ot("invalid-offset",`offset ${String(l)} outside 0..${String(i)}`):Rt({...n.value,offset:l})}function ae(t,e,o){if("paragraph"in t){if(!("at"in t))return Ni(t,e,o);let d=kt(t.paragraph,e,o);if(!d.ok||t.at==="start")return d;let p=(o.story(d.value.story)?.rawText(d.value.paragraphId)??"").length;return Rt({...d.value,offset:p})}let n=lt(t.body,"body",e,o);if(!n.ok)return n;let a=n.value.paragraphIds;if(a.length===0)return Ot("invalid-offset","empty-story");if(t.at==="start")return Rt({story:n.value.story,paragraphId:a[0],index:n.value.indexOf(a[0]),offset:0});let i=a.length-1,l=a[i];return Rt({story:n.value.story,paragraphId:l,index:n.value.indexOf(l),offset:(n.value.rawText(l)??"").length})}function Ei(t,e){return t.index<e.index||t.index===e.index&&t.offset<=e.offset}function Li(t){let e=t.paragraphIds;if(e.length===0)return null;let o=e.length-1,n=e[o];return {start:{story:t.story,paragraphId:e[0],index:t.indexOf(e[0]),offset:0},end:{story:t.story,paragraphId:n,index:t.indexOf(n),offset:(t.rawText(n)??"").length}}}function K(t,e,o){if("body"in t){let i=lt(t.body,"body",e,o);return i.ok?Rt(Li(i.value)):i}if("paragraph"in t){let i=kt(t.paragraph,e,o);if(!i.ok)return i;let d=(o.story(i.value.story)?.rawText(i.value.paragraphId)??"").length;return Rt({start:i.value,end:{...i.value,offset:d}})}let n=ae(t.start,e,o);if(!n.ok)return n;let a=ae(t.end,e,o);return a.ok?Q(n.value.story)!==Q(a.value.story)?Ot("invalid-handle","span-crosses-stories"):Ei(n.value,a.value)?Rt({start:n.value,end:a.value}):Ot("invalid-offset","span-start-after-end"):a}function ot(t,e,o){if("body"in t)return lt(t.body,"body",e,o);if("paragraph"in t)return lt(t.paragraph,"paragraph",e,o);let n=t.start;return "paragraph"in n?lt(n.paragraph,"paragraph",e,o):lt(n.body,"body",e,o)}function Xe(t,e,o){if("paragraph"in t)return kt(t.paragraph,e,o);let n=lt(t.body,"body",e,o);if(!n.ok)return n;let a=n.value.paragraphIds;if(a.length===0)return Ot("invalid-offset","empty-story");let i=t.at==="first"?0:a.length-1;return Rt({story:n.value.story,paragraphId:a[i],index:i,offset:0})}function St(t,e){if(!t)return [];let o=e.paragraphIds,n=o[t.start.index]===t.start.paragraphId?t.start.index:o.indexOf(t.start.paragraphId),a=o[t.end.index]===t.end.paragraphId?t.end.index:o.indexOf(t.end.paragraphId);return n<0||a<n?[]:o.slice(n,a+1)}function Kt(t,e){if(!t)return [];let o=St(t,e),n=o.length-1;return o.map((a,i)=>{let l=(e.rawText(a)??"").length,d=i===0?t.start.offset:0,u=i===n?t.end.offset:l;return {paragraphId:a,start:d,end:u,whole:d===0&&u===l}})}function Lr(t,e,o,n="allMarkup"){if(!t)return "";let a=St(t,e);return a.length===1?e.projectedText(t.start.paragraphId,n)?.sliceRaw(t.start.offset,t.end.offset)??"":a.map((i,l)=>{let d=e.projectedText(i,n);if(!d)return "";let u=(e.rawText(i)??"").length;return l===0?d.sliceRaw(t.start.offset,u):l===a.length-1?d.sliceRaw(0,t.end.offset):d.text}).join(o)}function Mt(t,e){return {start:{paragraph:e.paragraph(t.start.paragraphId,t.start.story),offset:t.start.offset},end:{paragraph:e.paragraph(t.end.paragraphId,t.end.story),offset:t.end.offset}}}function Fi(t){return t?.kind!=="paragraph"?false:t.children.every(e=>e.namespaceUri!==chunk5MWFZ7F4_cjs.fa?false:e.localName==="pPr"?true:e.kind==="run"&&e.children.every(o=>o.namespaceUri===chunk5MWFZ7F4_cjs.fa&&(o.localName==="rPr"||o.localName==="t"&&o.children.every(n=>n.kind==="textValue"))))}function Cn(t,e,o){return Fi(chunk5MWFZ7F4_cjs.Ja(t,e))&&chunk5MWFZ7F4_cjs.gj(t,e,o)===null}function Fr(t,e,o,n){let a=chunk5MWFZ7F4_cjs.gj(t,e,o);if(!a)return null;let i=o===a.offset?chunk5MWFZ7F4_cjs.Bj(t,{op:"insertText",paragraphId:e,offset:o,text:n}):null;return i?.ok&&chunk5MWFZ7F4_cjs.Cj(i.part,e)?.slice(o,o+n.length)===n?null:{ok:false,error:{code:"unsupported-capability",message:"insert at the placeholder start or replace the complete prompt",detail:"placeholder-insertion-offset"}}}function Mi(t,e,o){return t.start===t.end?e<t.start&&t.start<o:e===o?t.start<e&&e<t.end:Math.max(t.start,e)<Math.min(t.end,o)}var Ye=class{#t=new Map;has(e){return this.#t.has(e)}append(e,o,n,a,i=false){let l=this.#t.get(e)??[];if(l.some(g=>Mi(g,o,n)))return null;let d=o,u=n;for(let g of l){let v=g.length-(g.end-g.start);g.end<=o&&!(i&&g.start===o&&g.end===o)&&(d+=v),(g.end<n||g.end===n&&g.start!==g.end)&&(u+=v);}o===n&&(u=d);let p=a-(n-o);for(let g of l)n<=g.start&&!(o===n&&g.start===g.end&&o===g.start&&!i)&&(g.result.start+=p,g.result.end+=p);let h={start:d,end:d+a};return l.push({start:o,end:n,length:a,result:h}),this.#t.set(e,l),{start:d,end:u,result:h}}};function Mr(t,e,o,n,a=false){let i=e.start.paragraphId,l=t.append(i,e.start.offset,e.end.offset,o.length,a);return l?{ok:true,kind:"command",ops:Hr(i,l.start,l.end,o),story:e.start.story,answer:()=>({kind:"span",span:Mt({start:{...e.start,offset:l.result.start},end:{...e.start,offset:l.result.end}},n)})}:{ok:false,error:{code:"conflicting-operations",message:"text edits overlap in the batch snapshot",detail:i}}}function Hr(t,e,o,n){let a=[];return n.length&&a.push({op:"insertText",paragraphId:t,offset:e,text:n,...o>e?{bias:"right"}:{}}),o>e&&a.push({op:"deleteText",paragraphId:t,start:e+n.length,end:o+n.length}),a}function Dr(t,e,o,n){let a=e.start.paragraphId,i=chunk5MWFZ7F4_cjs.Cj(t,a),l=chunk5MWFZ7F4_cjs.gj(t,a,e.start.offset),d=l&&o.length?[{op:"insertText",paragraphId:a,offset:e.start.offset,text:o,bias:"right"}]:Hr(a,e.start.offset,e.end.offset,o),u=t;for(let h of d){let g=chunk5MWFZ7F4_cjs.Bj(u,h);if(!g.ok)return {ok:false,error:{code:"unsupported-content",message:"that replacement cannot preserve the targeted text safely",detail:g.reason}};u=g.part;}let p=chunk5MWFZ7F4_cjs.Cj(u,a);return i===null||p!==i.slice(0,e.start.offset)+o+i.slice(e.end.offset)?{ok:false,error:{code:l?"unsupported-capability":"unsupported-content",message:l?"replace the complete placeholder prompt to avoid consuming unrelated text":"that replacement changes the expected text positions",detail:a}}:{ok:true,kind:"command",ops:d,story:e.start.story,answer:()=>({kind:"span",span:Mt({start:e.start,end:{...e.start,offset:e.start.offset+o.length}},n)})}}var jr=/\s/;function Br(t,e){let o=[],n=0;for(;n<t.length;){let a=null;for(let i of e){let l=t.indexOf(i,n);l<0||(!a||l<a.start||l===a.start&&i.length>a.length)&&(a={start:l,length:i.length});}if(!a)break;o.push(a),n=a.start+a.length;}return o}function _r(t,e,o){let n=e[o]?.markParagraphId??null;if(n!==null)return n;let a=t.paragraphIds,i=a[a.length-1];return i===void 0||new Set(e.map(d=>d.markParagraphId).filter(d=>d!==null)).has(i)?null:i}function Vr(t,e){for(let o of [t.start,t.end]){let n=e.rawText(o.paragraphId);if(n===null||o.offset>n.length)return false}return true}function Wr(t,e,o){let n=e,a=o;for(;n<a&&jr.test(t[n]);)n+=1;for(;a>n&&jr.test(t[a-1]);)a-=1;return [n,a]}function ie(t){let e=t.kind==="contentControl"?chunk5MWFZ7F4_cjs.Mb(t):t;return e?chunk5MWFZ7F4_cjs.Qb(e).map(o=>o.node):[]}var Ur=new Set(["unlocked","sdtLocked","contentLocked","sdtContentLocked"]),$r=new Set(["whole","content","start","end","before","after"]),Kr=new Set(["richText","plainText","dropDownList","comboBox","date"]),Hi=4096;function zr(t,e,o){return ["richText","plainText","comboBox","untyped"].includes(t)?typeof e!="string"?{code:"unsupported-content",message:"text is required",detail:"text"}:o!=="replace"&&o!=="start"&&o!=="end"?{code:"unsupported-content",message:"that is not a place to insert at",detail:String(o)}:null:{code:"unsupported-capability",message:"this control requires a typed value rather than a text insertion",detail:t}}function Gr(t){let e=(a,i)=>({ok:false,code:"unsupported-content",message:a,detail:i});if(typeof t!="object"||t===null||!("kind"in t))return e("a control value states its kind","value");let o=t,n=o.kind;if(n==="text"||n==="listItem"){let a=n==="text"?o.text:o.value;return typeof a!="string"?e("that value is not a string",String(n)):a.length>Hi?e("that value is too long",String(a.length)):{ok:true,value:n==="text"?{kind:"text",text:a}:{kind:"listItem",value:a}}}if(n==="checkbox"){let a=o.checked;return typeof a!="boolean"?e("a checkbox is checked or not","checked"):{ok:true,value:{kind:"checkbox",checked:a}}}if(n==="date"){let a=o.iso;return typeof a!="string"?e("a date is an ISO-8601 string","iso"):a.length>64?e("that is not a date",String(a.length)):{ok:true,value:{kind:"date",iso:a}}}return e("that is not a value any control accepts",String(n))}var Di=/[\r\n\v\f\u2028\u2029]/;function Je(t,e,o){return {code:t,message:e,detail:o}}function Xr(t,e=false){if(typeof t.author!="string"||!t.author.trim()||!chunk5MWFZ7F4_cjs.O(t.author))return Je("unsupported-content","proposals need a non-empty XML-safe author","author");let o=t.op==="proposeInsertion";return !(t.op==="proposeDeletion")&&(typeof t.text!="string"||!e&&!t.text.length||Di.test(t.text)||!chunk5MWFZ7F4_cjs.O(t.text))?Je("unsupported-content","proposals need non-empty inline XML-safe text","text"):o&&t.where!=="Before"&&t.where!=="After"?Je("unsupported-content","insertion needs Before or After","where"):null}function se(t,e,o,n,a,i=false){let l=chunkH7XMRUAO_cjs.xa(t.part),d=new Set;if(l.some(p=>p.revisionKind==="structural"))for(let p=chunk5MWFZ7F4_cjs.Ka(t.part,e);p!==null&&(d.add(p.id),p.id!==t.root.id);p=chunk5MWFZ7F4_cjs.Ka(t.part,p.id));return l.some(p=>{if(a&&p.author===a&&(["insert","paragraphMark","format"].includes(p.revisionKind)||i&&["delete","replace"].includes(p.revisionKind)))return false;if(p.revisionKind==="structural"){let h=chunkH7XMRUAO_cjs.la(p),g=0;for(let v of h){let m=chunk5MWFZ7F4_cjs.Ka(t.part,v),k=m&&chunk5MWFZ7F4_cjs.Ka(t.part,m.id),A=k?.kind==="tableRow"?"trPr":k?.kind==="tableCell"?"tcPr":null;if(!(!k||!A||chunk5MWFZ7F4_cjs.mf(k,A)?.id!==m?.id)){if(d.has(k.id))return true;g+=1;}}if(h.length>0&&g===h.length)return false}return p.ranges.some(h=>{let g=t.indexOf(h.start.paragraphId),v=t.indexOf(h.end.paragraphId),m=t.indexOf(e);if(g<0||v<0||m<g||m>v)return false;let k=m===g?h.start.offset:0,A=m===v?h.end.offset:1/0;return o<=A&&n>=k})})?Je("unsupported-revision","proposal touches or overlaps a pending revision","span"):null}function Yr(t,e,o,n,a,i){let l=!!n,d=(k,A,P)=>({ok:false,error:{code:k,message:A,...P?{detail:P}:{}}});if(l&&a===false)return d("unsupported-capability","tracked content-control creation is unsupported in collaboration");let u=K(t.span,e,o);if(!u.ok)return d(u.code,"that span is not a place",u.detail);if(!u.value)return d("invalid-offset","that story holds nothing to wrap","empty-story");let p=ot(t.span,e,o),h=p.ok?p.value:null;if(!h)return d("invalid-handle","that story is not in this document");let g=u.value;if(g.start.paragraphId!==g.end.paragraphId)return d("unsupported-content","wrapping several paragraphs in one control is not supported here","multi-paragraph");if(!Kr.has(t.subtype))return d("unsupported-content","that control type cannot be inserted",t.subtype);if(l){if(!chunk5MWFZ7F4_cjs.hj(h.part,g.start.paragraphId,g.start.offset,g.end.offset))return d("unsupported-capability","tracked controls require a nonempty ordinary text range without existing review markup");let k=se(h,g.start.paragraphId,g.start.offset,g.end.offset);if(k)return {ok:false,error:k}}let v=new Set(ie(h.root).map(k=>k.id)),m=i(h,g.start.paragraphId);return m||{ok:true,kind:"command",story:h.story,ops:[{op:"insertContentControl",paragraphId:g.start.paragraphId,start:g.start.offset,end:g.end.offset,type:t.subtype,...l?{revision:{author:n,date:new Date().toISOString()}}:{},...t.tag===void 0?{}:{tag:t.tag},...t.title===void 0?{}:{alias:t.title}}],answer:k=>{if(!t.returnHandle)return {kind:"applied"};let A=k.story(h.story),P=A&&ie(A.root).find(w=>!v.has(w.id));if(!P)throw new Error("content control insertion did not create a control");return {kind:"handle",handle:e.contentControl(P.id,h.story)}}}}function Jr(t,e,o){let n=chunk5MWFZ7F4_cjs.Ja(t,e);if(!n||n.kind!=="contentControl")return false;let a=l=>l.kind==="textValue"||!l.kind.startsWith("revision")&&!l.localName.endsWith("Change")&&l.children.every(a);if(!a(n))return false;let i=chunk5MWFZ7F4_cjs.Ka(t,e);return i?.kind==="revisionInsert"&&i.attributes.some(l=>l.namespaceUri===chunk5MWFZ7F4_cjs.fa&&l.localName==="author"&&l.value===o)}function Qr(t){if(t.length>128)return null;let e=t.trim(),o=new Set,n=[];for(;e;){let a=/^\\([ohzu])(?:\s+"([1-9])-([1-9])")?(?=\s|$)/.exec(e);if(!a)return null;let[,i,l,d]=a;if(o.has(i)||(i==="o"?!l||Number(l)>Number(d):l))return null;o.add(i),n.push(a[0]),e=e.slice(a[0].length).trimStart();}return ["TOC",...n].join(" ")}function Qe(t,e){let o=chunk5MWFZ7F4_cjs.Ja(t,e);if(!o||o.kind!=="paragraph")return [];let n=chunk5MWFZ7F4_cjs.of(o);return chunk5MWFZ7F4_cjs.fi(o).flatMap(a=>{let i=n.find(d=>d.node.id===a.fieldNodeId),l=chunk5MWFZ7F4_cjs.Ja(t,a.fieldNodeId);return i?[{paragraphId:e,fieldNodeId:a.fieldNodeId,code:a.instruction,start:i.start,end:i.end,rewritable:a.rewritable,locked:!!l&&chunk5MWFZ7F4_cjs.Ge(l,"fldLock")===true}]:[]})}function Zr(t){let e=chunk5MWFZ7F4_cjs.N(t),o=chunk5MWFZ7F4_cjs.za(`<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:fldSimple w:instr="${e}"><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(!o.ok)throw new Error("could not build a field");let n=o.part.root.children.find(i=>i.kind==="body"),a=n&&chunk5MWFZ7F4_cjs.Gc(n)[0];if(!a||a.kind!=="paragraph")throw new Error("could not build a field paragraph");return a}var ft=(t,e="unsupported-content")=>({ok:false,error:{code:e,message:t}});function qr(t,e,o,n,a){if(t.op==="getFields"||t.op==="insertField"){let h=K(t.span,e,o),g=ot(t.span,e,o);if(!h.ok||!g.ok)return ft("that field range no longer exists","invalid-handle");let v=g.value;if(t.op==="getFields")return {ok:true,kind:"query",value:{kind:"handles",handles:Kt(h.value,v).flatMap(M=>Qe(v.part,M.paragraphId).filter(j=>j.start>=M.start&&j.end<=M.end)).map(M=>e.field(M.paragraphId,M.fieldNodeId,v.story))}};if(!h.value)return ft("insert a paragraph before inserting a field");if(t.removeFormatting!==void 0&&t.removeFormatting!==false)return ft("removeFormatting is not supported");if(t.text!==void 0&&typeof t.text!="string")return ft("field text must be a string");if(t.fieldType!==void 0&&typeof t.fieldType!="string")return ft("field type must be a string");let m=t.fieldType??"Empty",k=null;if(m==="Page"||m==="NumPages"){if(t.text!==void 0&&t.text.trim()!=="")return ft("field switches are not supported");k=m==="Page"?"PAGE":"NUMPAGES";}else m==="TOC"?k=Qr(t.text??""):m==="Empty"&&(k=chunk5MWFZ7F4_cjs.ki(t.text??""));if(!k)return ft("only PAGE, NUMPAGES, and TOC with supported switches can be inserted");let{start:A,end:P}=h.value;if(!["Before","After","Start","End","Replace"].includes(t.location))return ft("unsupported field insert location");if(t.location==="Replace"&&A.paragraphId!==P.paragraphId)return ft("field replacement requires one paragraph");let w=t.location==="After"||t.location==="End"?P:A,N=n(v,w.paragraphId);if(N)return N;let L=[];return t.location==="Replace"&&P.offset>A.offset&&L.push({op:"deleteText",paragraphId:A.paragraphId,start:A.offset,end:P.offset}),L.push({op:"insertFragment",paragraphId:w.paragraphId,offset:w.offset,blocks:[Zr(k)],lastMarkCovered:false}),{ok:true,kind:"command",story:v.story,ops:L,answer:D=>{let M=D.story(v.story)?.part,j=M&&Qe(M,w.paragraphId).find(S=>S.start===w.offset);if(!j)throw new Error("inserted field was not committed");return {kind:"handle",handle:e.field(w.paragraphId,j.fieldNodeId,v.story)}}}}let i=e.resolve(t.field,"field");if(!i||i.kind!=="field")return ft("that is not a field handle","invalid-handle");let l=o.story(i.story),d=l&&Qe(l.part,i.paragraphId).find(h=>h.fieldNodeId===i.fieldNodeId);if(!l||!l.has(i.paragraphId)||!d)return ft("that field no longer exists","invalid-handle");if(t.op==="getField")return {ok:true,kind:"query",value:{kind:"field",field:{code:d.code}}};if(d.locked||chunk5MWFZ7F4_cjs.ff(l.part,i.fieldNodeId).content||chunk5MWFZ7F4_cjs.if(l.part,i.fieldNodeId))return ft("field is protected");let u=n(l,i.paragraphId,t.op==="updateFieldResult");if(u)return u;let p=[];if(t.op==="deleteField")p.push({op:"deleteText",paragraphId:i.paragraphId,start:d.start,end:d.end});else if(t.op==="setFieldCode"){if(!chunk5MWFZ7F4_cjs.ki(d.code)||!chunk5MWFZ7F4_cjs.ki(t.code))return ft("only PAGE and NUMPAGES code writes are supported");p.push({op:"setFieldCode",paragraphId:i.paragraphId,fieldNodeId:i.fieldNodeId,code:t.code});}else {let h=chunk5MWFZ7F4_cjs.ki(d.code);if(!h||!d.rewritable)return ft("this field result cannot be evaluated","unsupported-capability");let g=a?.(l.story,i.paragraphId,i.fieldNodeId);if(!g||!Number.isInteger(g.pageNumber)||g.pageNumber<1||!Number.isInteger(g.pageCount)||g.pageCount<1)return ft("field update requires actual semantic pagination","unsupported-capability");let v=h==="PAGE"?g.pageNumberText??String(g.pageNumber):String(g.pageCount);p.push({op:"refreshFieldResults",updates:[{paragraphId:i.paragraphId,fieldNodeId:i.fieldNodeId,text:v}]});}return {ok:true,kind:"command",story:l.story,ops:p,answer:()=>({kind:"applied"})}}var ut=(t,e)=>({ok:false,error:{code:t,message:e,detail:e}}),zt=t=>({ok:true,kind:"query",value:t}),ji=new Set(["insertTableRows","getTables","getTable","getTableRows","getTableCells","getTableCell","getTableCellProperties","getTableCellBody","updateTable","updateTableCell","insertTable"]);function be(t){let e=new Set,o=[t];for(;o.length;){let n=o.pop();n.kind==="paragraph"&&e.add(n.id),n.kind!=="textValue"&&o.push(...n.children);}return e}function ta(t,e){let o=be(t);return [...be(e)].filter(n=>!o.has(n)).length}function Bi(t,e){let o=[{node:t}];for(;o.length;){let{node:n,table:a}=o.pop();if(n.id===e)return a;if(n.kind==="textValue")continue;let i=n.kind==="table"?n:a;for(let l of n.children)o.push({node:l,table:i});}}function ea(t){let e=t.package&&chunk5MWFZ7F4_cjs.Sc(t.package);return e?[...chunk5MWFZ7F4_cjs.Rc(e).values()].filter(o=>o.type==="table"):[]}function na(t,e){if(!ji.has(t.op))return null;let{handles:o,reads:n}=e;if(t.op==="getTables"||t.op==="insertTable"){let g=t.op==="getTables"?t.scope:t.span,v=ot(g,o,n);if(!v.ok)return ut(v.code,v.detail);let m=K(g,o,n);if(!m.ok)return ut(m.code,m.detail);let k=v.value;if(t.op==="getTables"){let L=m.value,D=chunk5MWFZ7F4_cjs.Dj(k.root).filter(M=>{if("body"in g)return true;if(!L)return false;let j=[...be(M)].sort((Y,$)=>k.indexOf(Y)-k.indexOf($)),S=j[0],_=j[j.length-1];return !S||!_?false:k.indexOf(S)>=L.start.index&&k.indexOf(_)<=L.end.index});return zt({kind:"handles",handles:D.map(M=>o.table(M.id,k.story))})}if(!m.value)return ut("invalid-offset","empty-table-insertion-range");if(!["Before","After"].includes(t.location))return ut("unsupported-content","table-insertion-location");let A=t.location==="Before"?m.value.start:m.value.end,P=chunk5MWFZ7F4_cjs.Hj(k,A.paragraphId,A.offset,t.rowCount,t.columnCount,t.values,e.trackingAuthor?{author:e.trackingAuthor,date:new Date().toISOString()}:void 0);if(!P.ok)return ut("unsupported-content",P.reason);let w=e.admitWrite(k,ta(k.part.root,P.resultPart.root),[A.paragraphId]);if(w)return w;let N=new Set(chunk5MWFZ7F4_cjs.Dj(k.root).map(L=>L.id));return {ok:true,kind:"command",story:k.story,ops:[{op:"authorTable",action:{kind:"insert",paragraphId:A.paragraphId,offset:A.offset,rowCount:t.rowCount,columnCount:t.columnCount,...t.values?{values:t.values}:{}},...e.trackingAuthor?{revision:{author:e.trackingAuthor,date:new Date().toISOString()}}:{}}],answer:L=>{let D=L.story(k.story),M=D&&chunk5MWFZ7F4_cjs.Dj(D.root).find(j=>!N.has(j.id));return M?{kind:"handle",handle:o.table(M.id,k.story)}:{kind:"applied"}}}}let a=t.op==="getTableCells"||t.op==="insertTableRows"?"tableRow":"cell"in t?"tableCell":"table",i=t.op==="getTableCells"||t.op==="insertTableRows"?t.row:"cell"in t?t.cell:"table"in t?t.table:{kind:"document",ref:""},l=o.resolve(i,a);if(!l||!("nodeId"in l)||!("story"in l))return ut("invalid-handle","unknown-table-object");let d=n.story(l.story);if(!d)return ut("invalid-handle","missing-table-story");let u=chunk5MWFZ7F4_cjs.Ja(d.part,l.nodeId);if(!u||u.kind!==a)return ut("invalid-handle","deleted-table-object");let p=a==="table"?u:Bi(d.root,l.nodeId);if(!p)return ut("invalid-handle","missing-parent-table");let h=chunk5MWFZ7F4_cjs.Ej(d,p.id);if(!h)return ut("unsupported-content","unsupported-table-topology");switch(t.op){case "getTable":return zt({kind:"table",table:{values:h.values,headerRowCount:h.headerRowCount,rowCount:h.rowIds.length,columnCount:h.columnCount,style:ea(n).find(g=>g.styleId===h.styleId)?.name??""}});case "getTableRows":return zt({kind:"handles",handles:h.rowIds.map(g=>o.tableRow(g,d.story))});case "getTableCells":{let g=h.rowIds.indexOf(l.nodeId);return zt({kind:"handles",handles:(h.cellIds[g]??[]).map(v=>o.tableCell(v,d.story))})}case "getTableCell":{if(!Number.isInteger(t.rowIndex)||!Number.isInteger(t.cellIndex))return ut("invalid-offset","invalid-cell-index");let g=h.cellIds[t.rowIndex]?.[t.cellIndex];return g?zt({kind:"handle",handle:o.tableCell(g,d.story)}):ut("invalid-handle","cell-not-found")}case "getTableCellBody":return zt({kind:"handle",handle:o.body(d.story,l.nodeId)});case "getTableCellProperties":{let g=chunk5MWFZ7F4_cjs.Fj(d,p.id,l.nodeId);return g?zt({kind:"tableCell",cell:{value:g.value,columnWidth:g.columnWidth,shadingColor:g.shadingColor,verticalAlignment:g.verticalAlignment}}):ut("invalid-handle","cell-not-found")}case "insertTableRows":case "updateTable":case "updateTableCell":{let g=t.op==="insertTableRows"?{kind:"insertRows",rowId:l.nodeId,location:t.location,count:t.count,...t.values?{values:t.values}:{}}:t.op==="updateTable"?t.mutation:{...t.properties,kind:"cell",cellId:l.nodeId};if(g.kind==="properties"&&g.styleId!==void 0){let P=g.styleId;if(typeof P!="string"||P.trim().length===0)return ut("unsupported-content","invalid-table-style-name");let w=ea(n).find(N=>N.name?.trim().toLowerCase()===P.trim().toLowerCase());if(!w)return ut("unsupported-content","table-style-not-defined");g={...g,styleId:w.styleId};}let v=e.trackingAuthor?{author:e.trackingAuthor,date:new Date().toISOString()}:void 0;if(v&&e.trackedRangeReplacement===false&&(g.kind==="values"||g.kind==="cell"&&g.value!==void 0))return ut("unsupported-capability","tracked table value replacement is unsupported in collaboration");let m=chunk5MWFZ7F4_cjs.Gj(d,p.id,g,v);if(!m.ok)return ut(m.reason==="unsupported-revision"?"unsupported-revision":m.reason==="tracked-table-deletion-unsupported"||m.reason==="unsupported-tracked-table-operation"?"unsupported-capability":"unsupported-content",m.reason);let k=e.admitWrite(d,ta(d.part.root,m.resultPart.root),g.kind==="values"?[...be(p)]:g.kind==="cell"&&g.value!==void 0?[...be(u)]:[]);if(k)return k;let A=new Set(h.rowIds);return {ok:true,kind:"command",story:d.story,ops:[{op:"authorTable",action:{kind:"existing",tableId:p.id,mutation:g},...v?{revision:v}:{}}],answer:P=>{if(g.kind!=="addRows"&&g.kind!=="insertRows")return {kind:"applied"};let w=P.story(d.story);return {kind:"handles",handles:((w&&chunk5MWFZ7F4_cjs.Ej(w,p.id))?.rowIds??[]).filter(L=>!A.has(L)).map(L=>o.tableRow(L,d.story))}}}}default:return ut("unsupported-content","unknown-table-operation")}}var oa=t=>({ok:false,error:{code:"unsupported-content",message:t}});function _i(t){if(t.op==="getText")return t.target;if("body"in t)return t.body;if(t.op==="insertText"&&"body"in t.at)return t.at.body;if(t.op==="replaceSpan"&&"body"in t.span)return t.span.body;if(t.op==="insertParagraph"&&"body"in t.anchor)return t.anchor.body}function ra(t,e,o){let n=_i(t);if(!n)return null;let a=e.handles.resolve(n,"body");if(!a||a.kind!=="body"||a.story.kind!=="header"&&a.story.kind!=="footer")return null;let i=a.story,l=e.reads.package;if(!l||e.reads.story(i))return null;if(!e.reads.sections()[i.sectionIndex])return oa("that section no longer exists");if(t.op==="getText")return {ok:true,kind:"query",value:{kind:"text",text:""}};if(t.op==="getParagraphs"||t.op==="getLists")return {ok:true,kind:"query",value:{kind:"handles",handles:[]}};if(t.op!=="insertText"&&t.op!=="replaceSpan"&&t.op!=="insertParagraph")return null;let d=p=>{let h=chunk5MWFZ7F4_cjs._f(p,{op:"createHeaderFooter",sectionIndex:i.sectionIndex,kind:i.kind,variant:i.variant,...i.variant==="first"?{titlePage:true}:{},...i.variant==="even"?{evenAndOddHeaders:true}:{}});if(!h.ok||!h.createdPartName)return null;let g=ke(h.package),v=o(g),m=v.plan(t);if(!m.ok||m.kind!=="command"||m.relate||m.lifecycle||m.packageEdits?.length)return null;let k=h.package.parts.get(h.createdPartName);if(!k)return null;for(let P of m.ops){let w=chunk5MWFZ7F4_cjs.Bj(k,P);if(!w.ok)return null;k=w.part;}let A=chunk5MWFZ7F4_cjs.Xd(h.package,k);return v.settle(ke(A)).ok?{pkg:A,planner:v,step:m}:null},u=d(l);return u?{ok:true,kind:"command",story:{kind:"body"},ops:[],solitary:true,packageEdits:[p=>{let h=d(p);if(!h)throw new Error("header/footer creation changed during transaction");return u=h,h.pkg}],answer:p=>u.step.answer(p)}:oa("cannot create this header or footer with that content")}var Vi=20*1024*1024;function Wi(t){if(typeof t!="string"||t.length===0||t.length>Math.ceil(Vi/3)*4||t.length%4!==0)return null;let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=t.endsWith("==")?2:t.endsWith("=")?1:0,n=new Uint8Array(t.length/4*3-o),a=0;for(let i=0;i<t.length;i+=4){let l=i+4===t.length,d=l?4-o:4,u=[0,0,0,0];for(let h=0;h<d;h++){let g=e.indexOf(t[i+h]);if(g<0)return null;u[h]=g;}if(l&&(o===2&&(u[1]&15)!==0||o===1&&(u[2]&3)!==0))return null;let p=u[0]<<18|u[1]<<12|u[2]<<6|u[3];a<n.length&&(n[a++]=p>>>16),a<n.length&&(n[a++]=p>>>8),a<n.length&&(n[a++]=p);}return n}function aa(t,e,o,n,a){let i=Wi(a);if(!i)return {ok:false,detail:"picture: invalid or oversized base64 (20 MiB maximum)"};let l=chunk5MWFZ7F4_cjs.wd(i);if(l!=="image/png"&&l!=="image/jpeg")return {ok:false,detail:"picture: only PNG and JPEG are supported"};if(!Ui(i,l))return {ok:false,detail:"picture: truncated raster container"};let d=chunk5MWFZ7F4_cjs.Bd(i,l);if(!d||d.pixelWidth*d.pixelHeight>4e7)return {ok:false,detail:"picture: invalid or oversized raster dimensions"};let u=d.pixelWidth*72/(d.dpiX??96),p=d.pixelHeight*72/(d.dpiY??96),h=chunk5MWFZ7F4_cjs.Pd(u),g=chunk5MWFZ7F4_cjs.Pd(p);if(h===null||g===null)return {ok:false,detail:"picture: invalid physical dimensions"};let v=chunk5MWFZ7F4_cjs.Md(t,e,{bytes:i,mime:l});if(!v.ok)return {ok:false,detail:`picture: ${v.reason}`};let m=chunk5MWFZ7F4_cjs.Qd({docPrId:v.docPrId,lockAspectRatio:true,relationshipId:v.relationshipId,extentEmu:{cx:h,cy:g}});return {ok:true,docPrId:v.docPrId,ops:[{op:"insertDrawing",paragraphId:o,offset:n,drawing:m}],packageEdits:[k=>{let A=chunk5MWFZ7F4_cjs.Md(k,e,{bytes:i,mime:l});if(!A.ok||A.relationshipId!==v.relationshipId||A.docPrId!==v.docPrId||A.partName!==v.partName)throw new Error("picture allocation changed during the batch");return A.pkg}]}}function ia(t,e){return chunk5MWFZ7F4_cjs.pd(t).find(o=>o.drawingNodeId===e&&o.kind==="inline"&&o.picture!==null)??null}function sa(t){return {width:t.extentEmu.cx/chunk5MWFZ7F4_cjs.Od,height:t.extentEmu.cy/chunk5MWFZ7F4_cjs.Od,lockAspectRatio:t.locks.changeAspect,altTextDescription:t.description}}function la(t,e){let o=new Set(chunk5MWFZ7F4_cjs.pd(t).filter(a=>a.kind==="inline"&&a.picture!==null).map(a=>a.drawingNodeId)),n=[];for(let a of e){let i=chunk5MWFZ7F4_cjs.Ja(t,a.paragraphId);if(!(!i||i.kind!=="paragraph"))for(let l of chunk5MWFZ7F4_cjs.of(i))l.start>=a.start&&l.end<=a.end&&o.has(l.node.id)&&n.push(l.node.id);}return n}function da(t,e){let o=[],n=t.drawingNodeId;if(e.lockAspectRatio!==void 0&&typeof e.lockAspectRatio!="boolean")return {ok:false,detail:"lockAspectRatio: not a boolean"};let a=e.lockAspectRatio??t.locks.changeAspect;if(e.lockAspectRatio===false&&o.push({op:"setDrawingLocks",drawingNodeId:n,locks:{changeAspect:false}}),e.width!==void 0||e.height!==void 0){let i=e.width??t.extentEmu.cx/chunk5MWFZ7F4_cjs.Od,l=e.height??t.extentEmu.cy/chunk5MWFZ7F4_cjs.Od;if(a){let p=t.extentEmu.cx/t.extentEmu.cy;if(e.width!==void 0&&e.height!==void 0&&Math.abs(i/l-p)>1e-6)return {ok:false,detail:"picture: width and height disagree with the locked aspect ratio"};e.width!==void 0&&e.height===void 0&&(l=i/p),e.height!==void 0&&e.width===void 0&&(i=l*p);}let d=chunk5MWFZ7F4_cjs.Pd(i),u=chunk5MWFZ7F4_cjs.Pd(l);if(d===null||u===null)return {ok:false,detail:"picture: dimensions must be finite positive points"};o.push({op:"resizeDrawing",drawingNodeId:n,extentEmu:{cx:d,cy:u}});}if(e.lockAspectRatio===true&&o.push({op:"setDrawingLocks",drawingNodeId:n,locks:{changeAspect:true}}),e.altTextDescription!==void 0){if(typeof e.altTextDescription!="string"||e.altTextDescription.length>32767||!chunk5MWFZ7F4_cjs.O(e.altTextDescription))return {ok:false,detail:"altTextDescription: invalid XML text or length"};o.push({op:"setDrawingMetadata",drawingNodeId:n,title:t.title,description:e.altTextDescription});}return o.length?{ok:true,ops:o}:{ok:false,detail:"picture: no properties requested"}}function Ui(t,e){if(e==="image/jpeg")return t.length>=4&&t[t.length-2]===255&&t[t.length-1]===217;let o=new DataView(t.buffer,t.byteOffset,t.byteLength),n=8,a=false;for(;n+12<=t.length;){let i=o.getUint32(n);if(i>t.length-n-12)return false;let l=String.fromCharCode(t[n+4],t[n+5],t[n+6],t[n+7]);if(l==="IDAT"&&i>0&&(a=true),n+=i+12,l==="IEND")return a&&i===0&&n===t.length}return false}var Ct=(t,e="unsupported-content")=>({ok:false,error:{code:e,message:t}});function ua(t,e,o,n){if(t.op==="getInlinePictures"||t.op==="insertInlinePicture"){let h=K(t.span,e,o),g=ot(t.span,e,o);if(!h.ok||!g.ok)return Ct("that picture range no longer exists","invalid-handle");let v=g.value;if(t.op==="getInlinePictures")return {ok:true,kind:"query",value:{kind:"handles",handles:la(v.part,Kt(h.value,v)).map(D=>e.inlinePicture(D,v.story))}};if(!h.value||!o.package)return Ct("insert a paragraph before inserting a picture");let{start:m,end:k}=h.value;if(!["Before","After","Start","End","Replace"].includes(t.location))return Ct("unsupported picture insert location");if(t.location==="Replace"&&m.paragraphId!==k.paragraphId)return Ct("picture replacement requires a single paragraph");let A=t.location==="After"||t.location==="End"?k:m;if(chunk5MWFZ7F4_cjs.ff(v.part,A.paragraphId).content||chunk5MWFZ7F4_cjs.if(v.part,A.paragraphId))return Ct("picture insertion is inside protected content");let P=chunk5MWFZ7F4_cjs.Ja(v.part,A.paragraphId);if(P?.kind==="paragraph"){for(let D of chunk5MWFZ7F4_cjs.of(P))if((t.location==="Replace"?D.start<k.offset&&D.end>m.offset:D.start<A.offset&&D.end>A.offset)&&(chunk5MWFZ7F4_cjs.ff(v.part,D.node.id).content||chunk5MWFZ7F4_cjs.if(v.part,D.node.id)))return Ct("picture insertion touches protected content")}let w=n(v,A.paragraphId);if(w)return w;let N=aa(o.package,v.part.name,A.paragraphId,A.offset,t.base64);if(!N.ok)return Ct(N.detail);let L=[];return t.location==="Replace"&&k.offset>m.offset&&L.push({op:"deleteText",paragraphId:m.paragraphId,start:m.offset,end:k.offset}),L.push(...N.ops),{ok:true,kind:"command",story:v.story,ops:L,packageEdits:N.packageEdits,answer:D=>{let M=D.story(v.story)?.part,j=M&&chunk5MWFZ7F4_cjs.pd(M).find(S=>S.docPrId===N.docPrId&&S.kind==="inline");if(!j)throw new Error("inserted picture was not committed");return {kind:"handle",handle:e.inlinePicture(j.drawingNodeId,v.story)}}}}let a=e.resolve(t.picture,"inlinePicture");if(!a||a.kind!=="inlinePicture")return Ct("that is not a picture handle","invalid-handle");let i=o.story(a.story),l=i&&ia(i.part,a.drawingNodeId);if(!i||!l)return Ct("that inline picture no longer exists","invalid-handle");if(t.op==="getInlinePicture")return {ok:true,kind:"query",value:{kind:"inlinePicture",picture:sa(l)}};let d=chunk5MWFZ7F4_cjs.Ja(i.part,a.drawingNodeId);for(;d&&d.kind!=="paragraph";)d=chunk5MWFZ7F4_cjs.nf(i.part,d.id);if(!d||!i.has(d.id))return Ct("picture is outside this story","invalid-handle");let u=n(i,d.id);if(u)return u;let p=t.op==="deleteInlinePicture"?{ok:true,ops:[{op:"deleteDrawing",drawingNodeId:a.drawingNodeId}]}:da(l,t.properties);return p.ok?{ok:true,kind:"command",story:i.story,ops:p.ops,answer:()=>({kind:"applied"})}:Ct(p.detail)}function ca(t,e,o,n){let a=v=>({ok:false,error:{code:"unsupported-content",message:v}});if(t.breakType!=="Page"&&t.breakType!=="SectionNext")return a("only Page and SectionNext breaks are supported");if(!["Before","After","Start","End","Replace"].includes(t.location))return a("invalid break insertion location");let i=K(t.span,e,o);if(!i.ok)return {ok:false,error:{code:i.code,message:i.detail}};let l=i.value;if(!l)return a("empty story has no break position");let d=t.location==="After"||t.location==="End"?l.end:l.start,u=o.story(d.story);if(!u)return a("missing story");if(t.location==="Replace"&&l.start.paragraphId!==l.end.paragraphId)return a("break replacement must remain in one paragraph");let p=t.breakType==="SectionNext";if(p&&(u.story.kind!=="body"||chunk5MWFZ7F4_cjs.Oi(u.part,d.paragraphId)))return a("section breaks require a body paragraph outside a table");let h=n(u,d.paragraphId,p?1:0);if(h)return h;let g=[];return t.location==="Replace"&&l.end.offset>l.start.offset&&g.push({op:"deleteText",paragraphId:d.paragraphId,start:l.start.offset,end:l.end.offset}),p?g.push({op:"splitParagraph",paragraphId:d.paragraphId,offset:d.offset},{op:"setSectionMark",paragraphId:d.paragraphId,breakType:"nextPage"}):g.push({op:"insertPageBreak",paragraphId:d.paragraphId,offset:d.offset}),{ok:true,kind:"command",story:u.story,ops:g,answer:()=>({kind:"applied"})}}var Nt=(t,e)=>t.children.find(o=>o.kind!=="textValue"&&o.namespaceUri===chunk5MWFZ7F4_cjs.fa&&o.localName===e),wt=(t,e)=>t.attributes.find(o=>o.namespaceUri===chunk5MWFZ7F4_cjs.fa&&o.localName===e)?.value,Ze=t=>t.replaceAll("&","&").replaceAll('"',""").replaceAll("<","<").replaceAll(">",">"),wn=t=>typeof t=="string"&&t.length<=255&&!/[\x00-\x08\x0b\x0c\x0e-\x1f\uFFFE\uFFFF]/.test(t),pa={None:"none",Arabic:"decimal",UpperRoman:"upperRoman",LowerRoman:"lowerRoman",UpperLetter:"upperLetter",LowerLetter:"lowerLetter"},ma={Solid:["\uF0B7","Symbol"],Hollow:["o","Courier New"],Square:["\uF0A7","Wingdings"],Diamonds:["\uF076","Wingdings"],Arrow:["\uF0D8","Wingdings"],Checkmark:["\uF0FC","Wingdings"]};function Tn(t){let e=chunk5MWFZ7F4_cjs.Nf(t,"bullet");if(!e)return null;let o=e.pkg;for(let n=0;n<=8;n+=1)if(!ve(o,e.numId,n)){let a=qe(o,e.numId,n,{bullet:n%3===0?"Solid":n%3===1?"Hollow":"Square"});if(!a)return null;o=a;}return {pkg:o,numId:e.numId}}function ve(t,e,o){let n=t.parts.get("/word/numbering.xml")?.root;if(!n)return false;let a=n.children,i=a.find(p=>p.kind!=="textValue"&&p.namespaceUri===chunk5MWFZ7F4_cjs.fa&&p.localName==="num"&&wt(p,"numId")===e);if(!i)return false;let l=i.children.find(p=>p.kind!=="textValue"&&p.namespaceUri===chunk5MWFZ7F4_cjs.fa&&p.localName==="lvlOverride"&&wt(p,"ilvl")===String(o));if(l&&Nt(l,"lvl"))return true;let d=Nt(i,"abstractNumId"),u=d&&a.find(p=>p.kind!=="textValue"&&p.namespaceUri===chunk5MWFZ7F4_cjs.fa&&p.localName==="abstractNum"&&wt(p,"abstractNumId")===wt(d,"val"));return !!u&&!Nt(u,"numStyleLink")&&u.children.some(p=>p.kind!=="textValue"&&p.namespaceUri===chunk5MWFZ7F4_cjs.fa&&p.localName==="lvl"&&wt(p,"ilvl")===String(o))}function Nn(t,e){if(!Number.isInteger(t)||t<0||t>8||!e||typeof e!="object")return false;if(e.bullet!==void 0){if(e.numbering!==void 0)return false;if(e.bullet==="Custom"){if(!Number.isInteger(e.charCode)||e.charCode<1||e.charCode>65535||e.charCode>=55296&&e.charCode<=57343||!wn(String.fromCharCode(e.charCode)))return false}else if(!Object.hasOwn(ma,e.bullet))return false;if(e.fontName!==void 0&&(!wn(e.fontName)||!e.fontName.trim()))return false}if(e.numbering!==void 0&&!Object.hasOwn(pa,e.numbering)||e.formatString!==void 0&&(!Array.isArray(e.formatString)||e.formatString.length>32||e.formatString.some(n=>typeof n=="number"?!Number.isInteger(n)||n<0||n>t:!wn(n)||/%[1-9]/.test(n)))||e.startingNumber!==void 0&&(!Number.isInteger(e.startingNumber)||e.startingNumber<0||e.startingNumber>2147483647))return false;for(let n of [e.textIndent,e.bulletNumberPictureIndent])if(n!==void 0&&(!Number.isFinite(n)||Math.abs(n)>1584))return false;let o=["bullet","charCode","fontName","numbering","formatString","startingNumber","textIndent","bulletNumberPictureIndent"];return Object.keys(e).some(n=>!o.includes(n))||e.bullet===void 0&&(e.charCode!==void 0||e.fontName!==void 0)||e.numbering===void 0&&e.formatString!==void 0?false:Object.keys(e).length>0}function qe(t,e,o,n){if(!Nn(o,n))return null;let a=t.parts.get("/word/numbering.xml");if(!a)return null;let i=a.root.children.find(S=>S.kind!=="textValue"&&S.namespaceUri===chunk5MWFZ7F4_cjs.fa&&S.localName==="num"&&wt(S,"numId")===e),l=i&&Nt(i,"abstractNumId");if(!i||!l)return null;let d=a.root.children.find(S=>S.kind!=="textValue"&&S.namespaceUri===chunk5MWFZ7F4_cjs.fa&&S.localName==="abstractNum"&&wt(S,"abstractNumId")===wt(l,"val"));if(!d||Nt(d,"numStyleLink"))return null;let u=i.children.find(S=>S.kind!=="textValue"&&S.namespaceUri===chunk5MWFZ7F4_cjs.fa&&S.localName==="lvlOverride"&&wt(S,"ilvl")===String(o)),p=(u&&Nt(u,"lvl"))??d.children.find(S=>S.kind!=="textValue"&&S.namespaceUri===chunk5MWFZ7F4_cjs.fa&&S.localName==="lvl"&&wt(S,"ilvl")===String(o));if(p&&Nt(p,"lvlPicBulletId"))return null;let h=chunk5MWFZ7F4_cjs.Ha(a),g=S=>S.kind==="textValue"?{...S,id:h()}:{...S,id:h(),children:S.children.map(g)},v=S=>{let _=chunk5MWFZ7F4_cjs.za(`<w:numbering xmlns:w="${chunk5MWFZ7F4_cjs.fa}">${S}</w:numbering>`,{name:a.name,contentType:a.contentType}),Y=_.ok?_.part.root.children[0]:void 0;return Y&&Y.kind!=="textValue"?g(Y):null};if(p??=v(`<w:lvl w:ilvl="${o}"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%${o+1}."/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="${720*(o+1)}" w:hanging="360"/></w:pPr></w:lvl>`)??void 0,!p)return null;let m=[...p.children],k=["start","numFmt","lvlRestart","pStyle","isLgl","suff","lvlText","lvlPicBulletId","legacy","lvlJc","pPr","rPr"],A=(S,_)=>{let Y=v(_);if(!Y)return false;let $=m.findIndex(V=>V.kind!=="textValue"&&V.namespaceUri===chunk5MWFZ7F4_cjs.fa&&V.localName===S);if($>=0){let V=m[$];m.splice($,1,{...V,attributes:[...V.attributes.filter(rt=>!Y.attributes.some(tt=>tt.namespaceUri===rt.namespaceUri&&tt.localName===rt.localName)),...Y.attributes]});}else {let V=m.findIndex(rt=>rt.kind!=="textValue"&&rt.namespaceUri===chunk5MWFZ7F4_cjs.fa&&k.indexOf(rt.localName)>k.indexOf(S));m.splice(V<0?m.length:V,0,Y);}return true};if(n.startingNumber!==void 0&&!A("start",`<w:start w:val="${n.startingNumber}"/>`))return null;if(n.numbering!==void 0){let S=n.formatString?.map(_=>typeof _=="number"?`%${_+1}`:_).join("")??(n.numbering==="None"?"":`%${o+1}.`);if(!A("numFmt",`<w:numFmt w:val="${pa[n.numbering]}"/>`)||!A("lvlText",`<w:lvlText w:val="${Ze(S)}"/>`))return null}if(n.numbering!==void 0&&(m=m.map(S=>S.kind!=="textValue"&&S.namespaceUri===chunk5MWFZ7F4_cjs.fa&&S.localName==="rPr"?{...S,children:S.children.filter(_=>_.kind==="textValue"||_.namespaceUri!==chunk5MWFZ7F4_cjs.fa||_.localName!=="rFonts")}:S)),n.bullet!==void 0){let[S,_]=n.bullet==="Custom"?[String.fromCharCode(n.charCode),n.fontName??"Symbol"]:ma[n.bullet];if(!A("numFmt",'<w:numFmt w:val="bullet"/>')||!A("lvlText",`<w:lvlText w:val="${Ze(S)}"/>`))return null;let Y=Nt(p,"rPr"),$=v(`<w:rFonts w:ascii="${Ze(_)}" w:hAnsi="${Ze(_)}"/>`);if(!$)return null;let V=Y?.children.filter(nt=>nt.kind==="textValue"||nt.namespaceUri!==chunk5MWFZ7F4_cjs.fa||nt.localName!=="rFonts")??[],rt=Y?{...Y,children:[$,...V]}:v("<w:rPr/>");if(!rt)return null;let tt=m.findIndex(nt=>nt.kind!=="textValue"&&nt.namespaceUri===chunk5MWFZ7F4_cjs.fa&&nt.localName==="rPr");tt<0?m.push({...rt,children:[$,...V]}):m[tt]={...rt,children:[$,...V]};}if(n.textIndent!==void 0||n.bulletNumberPictureIndent!==void 0){let S=Nt(p,"pPr"),_=S&&Nt(S,"ind"),Y=_?.attributes.filter(z=>z.namespaceUri!==chunk5MWFZ7F4_cjs.fa||!["left","start","firstLine","hanging"].includes(z.localName))??[],$=n.textIndent===void 0?wt(_??p,"left")??"0":String(Math.round(n.textIndent*20)),V=n.bulletNumberPictureIndent,rt=V===void 0?_?.attributes.filter(z=>z.namespaceUri===chunk5MWFZ7F4_cjs.fa&&["firstLine","hanging"].includes(z.localName))??[]:[],tt=v(`<w:ind w:left="${$}"${V===void 0?"":` w:${V<0?"hanging":"firstLine"}="${Math.abs(Math.round(V*20))}"`}/>`);if(!tt)return null;let nt={...tt,attributes:[...Y,...rt,...tt.attributes]},At=S?.children.filter(z=>z.kind==="textValue"||z.namespaceUri!==chunk5MWFZ7F4_cjs.fa||z.localName!=="ind")??[],bt=S??v("<w:pPr/>");if(!bt)return null;let it=_?S.children.indexOf(_):-1,st=[...At],W=["contextualSpacing","mirrorIndents","suppressOverlap","jc","textDirection","textAlignment","textboxTightWrap","outlineLvl","divId","cnfStyle","rPr","sectPr","pPrChange"],dt=st.findIndex(z=>z.kind!=="textValue"&&z.namespaceUri===chunk5MWFZ7F4_cjs.fa&&W.includes(z.localName));st.splice(it>=0?it:dt>=0?dt:st.length,0,nt);let yt={...bt,children:st},Z=m.findIndex(z=>z.kind!=="textValue"&&z.namespaceUri===chunk5MWFZ7F4_cjs.fa&&z.localName==="pPr");if(Z>=0)m[Z]=yt;else {let z=m.findIndex(_t=>_t.kind!=="textValue"&&_t.localName==="rPr"&&_t.namespaceUri===chunk5MWFZ7F4_cjs.fa);m.splice(z<0?m.length:z,0,yt);}}let P=g({...p,children:m}),w=u?.children.filter(S=>S.kind==="textValue"||S.namespaceUri!==chunk5MWFZ7F4_cjs.fa||S.localName!=="lvl"&&(n.startingNumber===void 0||S.localName!=="startOverride"))??[],N=u??v(`<w:lvlOverride w:ilvl="${o}"/>`);if(!N)return null;let L={...N,children:[...w,P]},D=[...i.children],M=u?D.indexOf(u):-1;M>=0?D[M]=L:D.push(L);let j=chunk5MWFZ7F4_cjs.Oa(a,i.id,{...i,children:D});return j.ok?chunk5MWFZ7F4_cjs.Xd(t,j.part):null}function Gt(t,e){return t&&"children"in t?t.children.find(o=>o.kind!=="textValue"&&o.namespaceUri===chunk5MWFZ7F4_cjs.fa&&o.localName===e):void 0}function En(t,e){return t&&"attributes"in t?t.attributes.find(o=>o.namespaceUri===chunk5MWFZ7F4_cjs.fa&&o.localName===e)?.value:void 0}function fa(t,e,o,n){return e.length>0&&e.every(a=>{let i=Gt(chunk5MWFZ7F4_cjs.Ja(t.part,a)??void 0,"pPr");if(En(Gt(Gt(i,"rPr"),"ins"),"author")===n)return true;let l=Gt(i,"pPrChange"),d=Gt(l,"pPr");return En(l,"author")===n&&En(Gt(Gt(d,"numPr"),"numId"),"val")!==o})}var le=8;function ga(t){if(!t||t.kind==="textValue")return null;for(let e of t.attributes)if(e.namespaceUri===chunk5MWFZ7F4_cjs.fa&&e.localName==="val")return e.value;return null}function tn(t){let e=chunk5MWFZ7F4_cjs.mf(chunk5MWFZ7F4_cjs.kf(t),"numPr");if(!e)return null;let o=ga(chunk5MWFZ7F4_cjs.mf(e,"numId"));if(o===null||!/^\d{1,10}$/.test(o)||o==="0")return null;let n=ga(chunk5MWFZ7F4_cjs.mf(e,"ilvl")),a=n===null?0:Number(n);return !Number.isInteger(a)||a<0||a>le?null:{numId:o,level:a}}function Xt(t){let e=new Map;for(let o of t.paragraphIds){let n=t.node(o);if(!n)continue;let a=tn(n);if(!a)continue;let i=e.get(a.numId);i?i.push(o):e.set(a.numId,[o]);}return Object.freeze([...e].map(([o,n])=>Object.freeze({numId:o,paragraphIds:Object.freeze(n)})))}function Ae(t,e){let o=t.node(e);return o?tn(o):null}var xt=t=>({ok:false,error:{code:"unsupported-content",message:t}});function $i(t,e){if(t.root.namespaceUri!==chunk5MWFZ7F4_cjs.fa||t.root.localName!=="styles")return false;let o=[t.root];for(;o.length;){let n=o.pop();if(n.kind!=="textValue"){if(n.namespaceUri===chunk5MWFZ7F4_cjs.fa&&n.localName==="numId"&&n.attributes.some(a=>a.namespaceUri===chunk5MWFZ7F4_cjs.fa&&a.localName==="val"&&a.value===e))return true;for(let a of n.children)o.push(a);}}return false}function ya(t,e,o,n,a){let i=o.package;if(!i)return xt("no document");if(t.op==="setListLevelFormat"){let m=e.resolve(t.list,"list");if(!m||m.kind!=="list")return xt("that is not a list");let k=o.story(m.story),A=k&&Xt(k).find(P=>P.numId===m.numId);if(!k||!A)return xt("that list no longer exists");if(a&&!fa(k,A.paragraphIds,m.numId,a))return {ok:false,error:{code:"unsupported-capability",message:"Only a newly proposed list definition can change while tracking"}};if(!Nn(t.level,t.format))return xt("invalid list level format");for(let P of i.parts.values()){if($i(P,m.numId))return xt("list is referenced by a style");for(let w of chunk5MWFZ7F4_cjs.Dc(P))for(let N of chunk5MWFZ7F4_cjs.Gc(w.root))if(tn(N)?.numId===m.numId&&!k.has(N.id))return xt("list is shared across stories")}for(let P of A.paragraphIds){if(chunk5MWFZ7F4_cjs.ff(k.part,P).content||chunk5MWFZ7F4_cjs.if(k.part,P))return xt("list contains protected content");let w=n(k,P,{numId:m.numId,level:t.level});if(w)return w}return qe(i,m.numId,t.level,t.format)?{ok:true,kind:"command",story:k.story,ops:[],packageEdits:[P=>{let w=qe(P,m.numId,t.level,t.format);if(!w)throw new Error("list definition changed during transaction");return w}],answer:()=>({kind:"applied"})}:xt("cannot format this list")}let l=kt(t.paragraph,e,o);if(!l.ok)return {ok:false,error:{code:l.code,message:l.detail}};let d=o.story(l.value.story);if(!d)return xt("missing story");let u=n(d,l.value.paragraphId);if(u)return u;let p=null,h=0,g=[];if(t.op==="startNewList"){let m=Tn(i);if(!m)return xt("cannot create numbering definition");let k=l.value.paragraphId;if(!chunk5MWFZ7F4_cjs.Bj(d.part,{op:"setListNumbering",paragraphId:k,numId:m.numId,level:0}).ok)return xt("cannot number this paragraph");let P=m.numId;return {ok:true,kind:"command",story:d.story,ops:[],packageEdits:[w=>{let N=Tn(w),L=N?.pkg.parts.get(d.part.name);if(!N||!L)throw new Error("cannot create numbering definition");let D=chunk5MWFZ7F4_cjs.Bj(L,{op:"setListNumbering",paragraphId:k,numId:N.numId,level:0,...a?{revision:{author:a,date:new Date().toISOString()}}:{}});if(!D.ok)throw new Error("cannot number this paragraph");return P=N.numId,chunk5MWFZ7F4_cjs.Xd(N.pkg,D.part)}],answer:()=>({kind:"handle",handle:e.list(P,d.story)})}}else if(t.op==="attachToList"){if(!Number.isSafeInteger(t.listId)||t.listId<=0||!Number.isInteger(t.level)||t.level<0||t.level>8)return xt("invalid list identity or level");if(p=String(t.listId),h=t.level,!ve(i,p,h))return xt("list level is not defined; configure that level first");if(!Xt(d).some(m=>m.numId===p))return xt("that list does not exist in this story")}let v=p;return {ok:true,kind:"command",story:d.story,ops:[{op:"setListNumbering",paragraphId:l.value.paragraphId,numId:t.op==="detachFromList"?"0":p,level:h}],packageEdits:g,answer:()=>v===null?{kind:"applied"}:{kind:"handle",handle:e.list(v,d.story)}}}var Ln=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"}),ha=[["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 ka(t){return Object.entries(Ln).find(([,e])=>e===t)?.[0]??null}function xa(t){return ha.find(([,e])=>e===t)?.[2]??null}function ba(t){let e=[];if(t.underline!==void 0){let o=typeof t.underline=="string"&&Object.hasOwn(Ln,t.underline)?Ln[t.underline]:void 0;if(!o)return {ok:false,detail:"underline: unsupported underline style"};e.push({localName:"u",attributes:{val:o}});}if(t.strikeThrough!==void 0){if(typeof t.strikeThrough!="boolean")return {ok:false,detail:"strikeThrough: not a boolean"};e.push({localName:"strike",attributes:{val:t.strikeThrough?"1":"0"}});}for(let o of ["subscript","superscript"])if(t[o]!==void 0&&typeof t[o]!="boolean")return {ok:false,detail:`${o}: not a boolean`};if(t.subscript===true&&t.superscript===true)return {ok:false,detail:"subscript and superscript are mutually exclusive"};if(t.highlightColor!==void 0){let o=t.highlightColor,n=typeof o=="string"?ha.find(([a,,i])=>a.toLowerCase()===o.toLowerCase()||i===o.toUpperCase()):void 0;if(o!==null&&!n)return {ok:false,detail:"highlightColor: use an exact Word palette color or null to clear"};e.push({localName:"highlight",attributes:{val:n?.[1]??"none"}});}return {ok:true,value:e}}var Ki=31680,zi=1999,Gi=Object.freeze({bold:null,italic:null,underline:null,strikeThrough:null,highlightColor:null,subscript:null,superscript:null,name:null,size:null,color:null});function ct(t,e){if(!t)return null;for(let o of t.attributes)if(o.localName===e)return o.value;return null}function nn(t){if(!t)return null;let e=ct(t,"val");if(e===null)return true;let o=e.trim().toLowerCase();return !(o==="0"||o==="false"||o==="off"||o==="none")}function Xi(t){if(t===null)return null;let e=t.trim();return /^[0-9a-fA-F]{6}$/.test(e)?`#${e.toUpperCase()}`:null}function Yi(t){if(t===null)return null;let e=Number(t.trim());return !Number.isFinite(e)||e<=0?null:e/2}function Yt(t){if(t===null)return null;let e=Number(t.trim());return Number.isFinite(e)?chunk5MWFZ7F4_cjs.Af(chunk5MWFZ7F4_cjs.yf(e)):null}function Et(t){if(t.length===0)return null;let e=t[0];if(e===null)return null;for(let o of t)if(o!==e)return null;return e}function Ia(t,e,o=chunk5MWFZ7F4_cjs.Dg){let n=[];for(let a of e)for(let i of chunk5MWFZ7F4_cjs.ah(t,a.paragraphId,a.start,a.end,o))n.push(chunk5MWFZ7F4_cjs.lf(i));return n.length===0?Gi:{bold:Et(n.map(a=>nn(chunk5MWFZ7F4_cjs.mf(a,"b")))),italic:Et(n.map(a=>nn(chunk5MWFZ7F4_cjs.mf(a,"i")))),underline:Et(n.map(a=>ka(ct(chunk5MWFZ7F4_cjs.mf(a,"u"),"val")))),strikeThrough:Et(n.map(a=>nn(chunk5MWFZ7F4_cjs.mf(a,"strike")))),highlightColor:Et(n.map(a=>xa(ct(chunk5MWFZ7F4_cjs.mf(a,"highlight"),"val")))),subscript:Et(n.map(a=>Aa(a,"subscript"))),superscript:Et(n.map(a=>Aa(a,"superscript"))),name:Et(n.map(a=>{let i=chunk5MWFZ7F4_cjs.mf(a,"rFonts"),l=ct(i,"ascii");return l===null||l.length===0?null:l})),size:Et(n.map(a=>Yi(ct(chunk5MWFZ7F4_cjs.mf(a,"sz"),"val")))),color:Et(n.map(a=>Xi(ct(chunk5MWFZ7F4_cjs.mf(a,"color"),"val"))))}}var Ji=Object.freeze({left:"Left",start:"Left",center:"Centered",right:"Right",end:"Right",both:"Justified",distribute:"Justified"}),Qi=Object.freeze({Left:"left",Centered:"center",Right:"right",Justified:"both"});function Zi(t){let e=ct(chunk5MWFZ7F4_cjs.mf(t,"jc"),"val");return e===null?"Unknown":Ji[e.trim().toLowerCase()]??"Unknown"}function Pa(t,e,o){let n=chunk5MWFZ7F4_cjs.Ja(t,e);if(!n||n.kind!=="paragraph")return null;let a=chunk5MWFZ7F4_cjs.kf(n),i=chunk5MWFZ7F4_cjs.mf(a,"spacing"),l=chunk5MWFZ7F4_cjs.mf(a,"ind");return {alignment:Zi(a),style:Ve(t,e,o),firstLineIndent:qi(l),leftIndent:Yt(ct(l,"left")??ct(l,"start")),rightIndent:Yt(ct(l,"right")??ct(l,"end")),lineSpacing:Yt(ct(i,"line")),spaceBefore:Yt(ct(i,"before")),spaceAfter:Yt(ct(i,"after")),widowControl:nn(chunk5MWFZ7F4_cjs.mf(a,"widowControl"))}}function qi(t){let e=Yt(ct(t,"hanging"));if(e!==null&&e>0)return -e;let o=Yt(ct(t,"firstLine"));return o!==null?o:e===null?null:-e}function en(t,e){if(typeof t!="number"||!Number.isFinite(t))return {ok:false,detail:`${e}: not a measurement`};let o=chunk5MWFZ7F4_cjs.Bf(chunk5MWFZ7F4_cjs.zf(t));return Math.abs(o)>Ki?{ok:false,detail:`${e}: out of range`}:{ok:true,value:o}}function Oa(t){let e=ba(t);if(!e.ok)return e;let o=e.value;if(t.bold!==void 0){if(typeof t.bold!="boolean")return {ok:false,detail:"bold: not a boolean"};o.push({localName:"b",...t.bold?{}:{attributes:{val:"0"}}});}if(t.italic!==void 0){if(typeof t.italic!="boolean")return {ok:false,detail:"italic: not a boolean"};o.push({localName:"i",...t.italic?{}:{attributes:{val:"0"}}});}if(t.name!==void 0){let n=t.name;if(typeof n!="string"||n.length===0||n.length>128)return {ok:false,detail:"name: not a font name"};if(!chunk5MWFZ7F4_cjs.O(n))return {ok:false,detail:"name: not valid XML text"};o.push({localName:"rFonts",attributes:{ascii:n,hAnsi:n}});}if(t.size!==void 0){let n=t.size;if(typeof n!="number"||!Number.isFinite(n)||n<=0)return {ok:false,detail:"size: not a positive number of points"};let a=Math.round(n*2);if(a<1||a>zi)return {ok:false,detail:"size: out of range"};o.push({localName:"sz",attributes:{val:String(a)}}),o.push({localName:"szCs",attributes:{val:String(a)}});}if(t.color!==void 0){let n=t.color;if(typeof n!="string"||!/^#[0-9a-fA-F]{6}$/.test(n.trim()))return {ok:false,detail:"color: not a #RRGGBB triplet"};o.push({localName:"color",attributes:{val:n.trim().slice(1).toUpperCase()}});}return o.length===0&&t.subscript===void 0&&t.superscript===void 0?{ok:false,detail:"no formatting was asked for"}:{ok:true,value:o}}function Ra(t,e,o,n){let a=chunk5MWFZ7F4_cjs.Ja(t,e);if(!a||a.kind!=="paragraph")return {ok:false,detail:"not a paragraph"};let i=chunk5MWFZ7F4_cjs.kf(a),l=[];if(o.style!==void 0){let m=We(o.style,n);if(!m.ok)return {ok:false,detail:m.detail};l.push({localName:"pStyle",attributes:{val:m.styleId}});}if(o.alignment!==void 0){let m=Qi[o.alignment];if(m===void 0)return {ok:false,detail:`alignment: ${String(o.alignment)}`};l.push({localName:"jc",attributes:{val:m}});}let d=chunk5MWFZ7F4_cjs.mf(i,"ind"),u=va(d),p=false;if(o.firstLineIndent!==void 0){let m=en(o.firstLineIndent,"firstLineIndent");if(!m.ok)return m;delete u.firstLine,delete u.hanging,m.value<0?u.hanging=String(-m.value):u.firstLine=String(m.value),p=true;}for(let[m,k,A]of [["leftIndent","left","start"],["rightIndent","right","end"]]){let P=o[m];if(P===void 0)continue;let w=en(P,m);if(!w.ok)return w;delete u[A],u[k]=String(w.value),p=true;}p&&l.push({localName:"ind",attributes:u});let h=chunk5MWFZ7F4_cjs.mf(i,"spacing"),g=va(h),v=false;for(let[m,k]of [["spaceBefore","before"],["spaceAfter","after"]]){let A=o[m];if(A===void 0)continue;let P=en(A,m);if(!P.ok)return P;if(P.value<0)return {ok:false,detail:`${m}: out of range`};g[k]=String(P.value),v=true;}if(o.lineSpacing!==void 0){let m=en(o.lineSpacing,"lineSpacing");if(!m.ok)return m;if(m.value<=0)return {ok:false,detail:"lineSpacing: out of range"};g.line=String(m.value),g.lineRule??="auto",v=true;}if(v&&l.push({localName:"spacing",attributes:g}),o.widowControl!==void 0){if(typeof o.widowControl!="boolean")return {ok:false,detail:"widowControl: not a boolean"};l.push({localName:"widowControl",...o.widowControl?{}:{attributes:{val:"0"}}});}return l.length===0?{ok:false,detail:"no formatting was asked for"}:{ok:true,value:chunk5MWFZ7F4_cjs.Pg(chunk5MWFZ7F4_cjs.Ng(t,e),l)}}function va(t){let e=Object.create(null);if(!t)return e;for(let o of t.attributes)e[o.localName]=o.value;return e}function Fn(t,e){if(e.subscript===void 0&&e.superscript===void 0)return [...t];let o=t.find(a=>a.localName==="vertAlign")?.attributes?.val,n=e.subscript===true?"subscript":e.superscript===true?"superscript":o==="subscript"&&e.subscript===false||o==="superscript"&&e.superscript===false?"baseline":o??"baseline";return chunk5MWFZ7F4_cjs.Pg(t,[{localName:"vertAlign",attributes:{val:n}}])}function Aa(t,e){let o=ct(chunk5MWFZ7F4_cjs.mf(t,"vertAlign"),"val");return o===null?null:o===e}function Sa(){let t=false,e=false,o=false,n=false;return {conflict(a){let i=Bt(a),l=_e(a),d=a.op==="deleteComment",u=a.op==="updateFieldResult";return i&&(u&&t&&!n||n&&!u)?{message:"field result updates require a batch without other edits; sync document edits before updating fields",detail:a.op}:l&&t||e&&i?{message:"that command commits on its own and cannot share a batch",detail:a.op}:d&&t&&!o||o&&i&&!d?{message:"comment deletions may share a batch only with other comment deletions",detail:a.op}:null},note(a){Bt(a)&&(t=true,_e(a)&&(e=true),a.op==="deleteComment"&&(o=true),a.op==="updateFieldResult"&&(n=true));},get hasCommands(){return t}}}var ts=256,Ca=1e4;function Mn(t,e){if(t.kind!=="textValue"){for(let o of t.attributes)if(o.namespaceUri===chunk5MWFZ7F4_cjs.fa&&o.localName===e)return o.value}}function es(t){return t.startsWith("_")}function Hn(t){let e=new Map,o=[],n=new Set;for(let a of t.paragraphIds){let i=t.node(a);if(i?.kind!=="paragraph")continue;let l=chunk5MWFZ7F4_cjs.qf(i),d=u=>{if(u.kind!=="textValue"){if(u.kind==="bookmarkStart"){if(o.length>=Ca||e.size>=Ca)return;let p=Mn(u,"id"),h=Mn(u,"name");if(p===void 0||h===void 0||h.length===0||h.length>ts||es(h)||n.has(h)||e.has(p))return;let g=l.spanOf(u)?.start??0;e.set(p,{name:h,start:{paragraphId:a,offset:g}});return}if(u.kind==="bookmarkEnd"){let p=Mn(u,"id");if(p===void 0)return;let h=e.get(p);if(!h)return;e.delete(p),n.add(h.name);let g=l.spanOf(u)?.start??0;o.push(Object.freeze({name:h.name,start:h.start,end:{paragraphId:a,offset:g}}));return}for(let p of u.children)d(p);}};for(let u of i.children)d(u);}return Object.freeze(o)}function Dn(t,e){return Hn(t).find(o=>o.name===e)??null}function wa(t,e){let o=t.node(e);if(o?.kind!=="paragraph")return Object.freeze([]);let n=chunk5MWFZ7F4_cjs.qf(o),a=[],i=(l,d)=>{if(!(l.kind==="textValue"||d>32)){if(chunk5MWFZ7F4_cjs.$c(l)){let u=n.spanOf(l);u&&a.push(Object.freeze({id:l.id,paragraphId:e,start:u.start,end:u.end}));return}for(let u of l.children)i(u,d+1);}};for(let l of o.children)i(l,0);return Object.freeze(a)}function Ta(t,e,o){let n=chunk5MWFZ7F4_cjs.cd(o,a=>chunk5MWFZ7F4_cjs.Vf(t,e,a));if(n.kind==="external")return n.href;if(n.kind==="internal"){let a=chunk5MWFZ7F4_cjs.ad(o);return a===void 0||a.length===0?null:`#${a}`}return null}function Na(t,e,o,n,a){let i=Math.min(a?.limit??2e3,2e3),l=[],d=St(e,t),u=d.length-1;for(let[p,h]of d.entries()){if(i<=0)break;let g=t.projectedText(h,a?.projection??"allMarkup");if(!g)continue;let v=g.findOccurrences(n,i,{matchCase:a?.matchCase===true,wholeWord:a?.matchWholeWord===true,...p===0&&e?{from:g.projectedOffset(e.start.offset)}:{},...p===u&&e?{to:g.projectedOffset(e.end.offset)}:{}});for(let m of v.matches){if(p===0&&e&&m.rawStart<e.start.offset||p===u&&e&&m.rawEnd>e.end.offset)continue;let k=o.paragraph(h,t.story);l.push({start:{paragraph:k,offset:m.rawStart},end:{paragraph:k,offset:m.rawEnd}}),i-=1;}}return {ok:true,spans:l}}var ns={insert:"Insert",delete:"Delete",replace:"Replace",moveFrom:"MovedFrom",moveTo:"MovedTo",format:"Property",paragraphMark:"ParagraphProperty"};function os(t){return t.kind==="note"}function rs(t,e){return e.length===0?!os(t.story):e.every(o=>t.has(o.start.paragraphId))}function as(t){return Object.freeze(chunkH7XMRUAO_cjs.xa(t.part).filter(e=>rs(t,e.ranges)))}function jn(t){let e=[];for(let o of as(t)){if(o.readOnly)continue;let n=o.structuralChanges?.length===1?o.structuralChanges[0]:void 0,a=o.revisionKind==="structural"?n==="rowInsert"?"Insert":n==="rowDelete"?"Delete":void 0:ns[o.revisionKind];a!==void 0&&e.push(Object.freeze({id:o.id,type:a,author:o.author,date:o.date??"",item:o}));}return Object.freeze(e)}function is(t,e){let o=t;for(let n=0;o!==void 0&&n<=64;n+=1){if(o.parentId===void 0)return o.range!==null;o=e.get(o.parentId);}return false}var ss=Object.freeze({items:Object.freeze([]),roots:Object.freeze([]),byId:()=>null,textOf:()=>""});function Ea(t,e){let o=t.parts.get(chunkH7XMRUAO_cjs.Z(t,e.part.name));if(!o)return ss;let n=t.parts.get(chunkH7XMRUAO_cjs._(t,e.part.name)),a=chunk5MWFZ7F4_cjs.kh(o),i=n?chunk5MWFZ7F4_cjs.lh(n):new Map,l=chunk5MWFZ7F4_cjs.ih(e.part).filter(g=>e.has(g.start.paragraphId)),d=chunkH7XMRUAO_cjs.ya(a,l,i),u=new Map(d.map(g=>[g.id,g])),p=d.filter(g=>is(g,u)),h=new Map(p.map(g=>[g.id,g]));return Object.freeze({items:Object.freeze(p),roots:Object.freeze(p.filter(g=>g.parentId===void 0)),byId:g=>h.get(g)??null,textOf:g=>{let v=h.get(g);return v?chunkH7XMRUAO_cjs.ta(v.comment):""}})}function La(t,e,o,n,a,i=true){let l=(j,S,_)=>({ok:false,error:{code:j,message:S,..._===void 0?{}:{detail:_}}}),d=j=>Mt(j,o),u=j=>({ok:true,kind:"query",value:j}),p=Xr(t,e);if(p)return {ok:false,error:p};let h=t.op==="proposeInsertion",g=t.op==="proposeDeletion",v=K(t.span,o,n);if(!v.ok)return l(v.code,"that span is not a place",v.detail);let m=v.value;if(m&&e&&!h&&m.start.paragraphId!==m.end.paragraphId){if(!i)return l("unsupported-capability","tracked paragraph-range replacement is unsupported in collaboration","span");let j=ot(t.span,o,n);if(!j.ok)return l(j.code,"that story is not a place",j.detail);let S=j.value,_=S.indexOf(m.start.paragraphId),Y=S.indexOf(m.end.paragraphId),$=S.paragraphIds.slice(_,Y+1),V=chunk5MWFZ7F4_cjs.Ka(S.part,$[0]),rt=$.map(it=>V?.children.findIndex(st=>st.id===it)??-1);if(!V||rt.some((it,st)=>it<0||st>0&&it!==rt[st-1]+1))return l("unsupported-content","tracked ranges require adjacent sibling paragraphs","span");let tt={author:t.author.trim(),date:new Date().toISOString()},nt=[];for(let it=0;it<$.length;it++){let st=$[it],W=it===0?m.start.offset:0,dt=it===$.length-1?m.end.offset:(S.rawText(st)??"").length,yt=se(S,st,W,dt);if(yt)return {ok:false,error:yt};let Z=a(S,st);if(Z)return Z;dt>W&&nt.push({op:"deleteText",paragraphId:st,start:W,end:dt,revision:tt}),it<$.length-1&&nt.push({op:"setParagraphMarkRevision",paragraphId:st,kind:"del",revision:tt});}let At={...m.start,offset:(S.rawText($[0])??"").length},bt=g?"":t.text;return bt&&nt.push({op:"insertText",paragraphId:$[0],offset:At.offset,text:bt,revision:tt}),{ok:true,kind:"command",ops:nt,story:S.story,answer:()=>({kind:"span",span:d({start:At,end:{...At,offset:At.offset+bt.length}})})}}if(!m||m.start.paragraphId!==m.end.paragraphId)return l("unsupported-content","proposals require a single paragraph range","span");if(!e&&!h&&m.start.offset===m.end.offset)return l("unsupported-content","deletion and replacement need a non-empty range","span");let k=ot(t.span,o,n);if(!k.ok)return l(k.code,"that story is not a place",k.detail);let A=m.start.paragraphId,P=h&&t.where==="After"?m.end.offset:m.start.offset,w=h?P:m.end.offset;if(e&&!g&&P===w&&t.text==="")return u({kind:"span",span:d({start:m.start,end:m.start})});let N=se(k.value,A,P,w,e&&h?t.author.trim():void 0,h&&P===(k.value.rawText(A)??"").length);if(N)return {ok:false,error:N};let L=a(k.value,A);if(L)return L;let D={author:t.author.trim(),date:new Date().toISOString()},M=[];return !h&&w>P&&M.push({op:"deleteText",paragraphId:A,start:P,end:w,revision:D}),!g&&t.text.length>0&&M.push({op:"insertText",paragraphId:A,offset:h?P:w,text:t.text,revision:D}),{ok:true,kind:"command",ops:M,story:k.value.story,answer:()=>{if(!e)return {kind:"applied"};let j={...m.start,offset:h?P:w};return {kind:"span",span:d({start:j,end:{...j,offset:j.offset+(g?0:t.text.length)}})}}}}function Fa(t,e,o){return se(t,e,0,(t.rawText(e)??"").length,o,true)}function Bn(t,e,o){if("body"in t){let n=lt(t.body,"body",e,o);return n.ok?{ok:true,reads:n.value}:{ok:false,code:n.code,message:"that handle does not name a body",detail:n.detail}}return e.resolve(t.document,"document")?o.body?{ok:true,reads:o.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 ls(t,e){if(e.root.kind!=="textValue"&&chunk5MWFZ7F4_cjs.Fi({...e.part,root:e.root}).length===0)return [];let o=t.op==="acceptAllRevisions",n=e.story.kind==="note"?{scopeRootId:e.root.id}:{};return [o?{op:"acceptAllRevisions",...n}:{op:"rejectAllRevisions",...n}]}function ds(t,e,o){let n=Bn({op:"acceptAllRevisions",body:t.body},e,o);if(!n.ok)return n;if(!["accept","reject"].includes(t.action)||t.revisions!==void 0&&!Array.isArray(t.revisions))return {ok:false,code:"unsupported-content",message:"invalid revision batch"};let a=t.revisions===void 0?void 0:[];for(let l of t.revisions??[]){let d=e.resolve(l,"revision");if(!d||d.kind!=="revision"||Q(d.story)!==Q(n.reads.story))return {ok:false,code:"invalid-handle",message:"revision does not belong to this story"};a.push(`revision-${d.revisionId}`);}let i=chunkH7XMRUAO_cjs.Ja(n.reads.part,t.action,a,n.reads.story.kind==="note"?n.reads.root:void 0);return {ok:true,reads:n.reads,...i}}function us(t,e,o,n){let a=Bn({op:"acceptAllRevisions",body:t},o,n);if(!a.ok)throw new Error("resolved story disappeared");let{part:i,root:l,story:d}=a.reads,u=chunkH7XMRUAO_cjs.xa(d.kind==="note"&&l.kind!=="textValue"?{...i,root:l}:i).length;return {kind:"revisionBatch",result:{...e,remaining:u}}}function Ma(t,e,o,n){if(t.op==="resolveRevisionBatch"){let l=ds(t,e,o);if(!l.ok)return {ok:false,error:{code:l.code,message:l.message}};let d=n(l.reads);return d||{ok:true,kind:"command",story:l.reads.story,ops:l.ops,answer:u=>us(t.body,l.result,e,u)}}let a=Bn(t,e,o);if(!a.ok)return {ok:false,error:{code:a.code,message:a.message,detail:a.detail}};let i=n(a.reads);return i||{ok:true,kind:"command",story:a.reads.story,ops:ls(t,a.reads),answer:()=>({kind:"applied"})}}function Ha(t,e,o){if(e.revisionKind==="structural"||chunk5MWFZ7F4_cjs.ti(t.root).length>0||e.revisionKind==="format"&&chunkH7XMRUAO_cjs.la(e).length>1){let n=chunkH7XMRUAO_cjs.Ja(t.part,o,[chunkH7XMRUAO_cjs.ma(e)],t.story.kind==="note"?t.root:void 0);return n.result.skipped.length?[]:n.ops}return e.addresses.map(n=>({op:o==="accept"?"acceptRevision":"rejectRevision",revision:n}))}var cs=/[\r\n\u2028\u2029]/u,ja=Object.freeze({kind:"applied"});function de(t,e,o){return {ok:false,error:Object.freeze(o===void 0?{code:t,message:e}:{code:t,message:e,detail:o})}}function _n(t,e){return de("unsupported-content",t==="author"?"a comment records who wrote it":t==="date"?"a comment date must be a valid ISO-8601 instant":e==="reply"?"a reply says something":"a comment says something",t)}function Vn(t){return chunkH7XMRUAO_cjs.R(t.author)?_n("author",t.kind):chunkH7XMRUAO_cjs.S(t.text)?_n("text",t.kind):typeof t.text=="string"&&cs.test(t.text)?de("unsupported-content",t.kind==="reply"?"a reply is one paragraph in this slice":"a comment is one paragraph in this slice","text"):chunkH7XMRUAO_cjs.U(t.date)?_n("date",t.kind):null}function Wn(t){if(t===void 0)return;let e=chunkH7XMRUAO_cjs.T(t);return e.ok?e.value:void 0}function Da(t,e){let o=chunk5MWFZ7F4_cjs.Ja(t.part,e);for(;o;){if(o.kind==="tableCell"||o.kind!=="textValue"&&o.namespaceUri===chunk5MWFZ7F4_cjs.fa&&o.localName==="tc")return o.id;o=chunk5MWFZ7F4_cjs.Ka(t.part,o.id);}return null}function Ba(t,e,o,n){let a=Vn({author:t.author,text:t.text,date:t.date,kind:"comment"});if(a)return a;let i=K(t.span,e,o);if(!i.ok)return de(i.code,"that span is not a place",i.detail);if(i.value===null)return de("invalid-handle","an empty story has no comment anchor");let l=ot(t.span,e,o);if(!l.ok)return de(l.code,"that span is not a place",l.detail);let d=i.value;if(Da(l.value,d.start.paragraphId)!==Da(l.value,d.end.paragraphId))return de("unsupported-content","a comment range cannot cross a table-cell boundary");let u=n(l.value);if(u)return u;let p=Wn(t.date);return {ok:true,kind:"commentWrite",write:{kind:"create",anchor:{paragraphId:d.start.paragraphId,start:d.start.offset,end:d.end.offset,...d.end.paragraphId===d.start.paragraphId?{}:{endParagraphId:d.end.paragraphId}},text:t.text,author:t.author,...p===void 0?{}:{date:p}},story:l.value.story,answer:(g,v)=>v===void 0?ja:{kind:"handle",handle:e.comment(v,l.value.story)}}}function _a(t,e,o){let n=o(e);if(n)return n;let a=e.story;return {ok:true,kind:"commentWrite",write:{kind:"delete",commentId:t.id,...t.parentId===void 0?{}:{parentCommentId:t.parentId},...a.kind==="note"?{noteId:a.noteId}:{}},story:a,answer:()=>ja}}var ps=1e4;function Va(t,e){let o=[],n=e.kind==="contentControl"?chunk5MWFZ7F4_cjs.Mb(e):e;if(!n)return o;for(let a of chunk5MWFZ7F4_cjs.Qb(n))if(!(a.ancestors.length>0)){if(o.length>=ps)break;o.push(za(t,a.node));}return o}function Wa(t,e){for(let o of chunk5MWFZ7F4_cjs.Qb(t.root))if(o.node.id===e)return za(t,o.node);return null}function Ua(t,e){for(let o of chunk5MWFZ7F4_cjs.Qb(t.root))if(o.node.id===e)return o.node;return null}function $a(t,e){for(let o of t.paragraphIds){let n=t.node(o);if(!(!n||n.kind!=="paragraph")&&chunk5MWFZ7F4_cjs.Qb(n).some(a=>a.node.id===e))return n}return null}function on(t,e){let o=Ga(e);if(o.length>0){let i=o[0],l=o[o.length-1],d=t.rawText(l);return d===null||!t.has(i)?null:{start:{paragraphId:i,offset:0},end:{paragraphId:l,offset:d.length}}}let n=$a(t,e.id);if(!n)return null;let a=chunk5MWFZ7F4_cjs.qf(n).spanOf(e);return a?{start:{paragraphId:n.id,offset:a.start},end:{paragraphId:n.id,offset:a.end}}:null}function ms(t,e,o){let n=$a(t,e.id),a=chunk5MWFZ7F4_cjs.Mb(e);if(!n||!a)return null;let i={...n,children:a.children},l=chunk5MWFZ7F4_cjs.Li(i);return Ue(i,l,o).text}function Ka(t,e,o="allMarkup"){if(o==="allMarkup")return chunk5MWFZ7F4_cjs.Sb(e);let n=ms(t,e,o);if(n!==null)return n;let a=on(t,e);if(!a)return "";let i=t.indexOf(a.start.paragraphId),l=t.indexOf(a.end.paragraphId);if(i<0||l<i)return "";let d=[];for(let u=i;u<=l;u+=1){let p=t.paragraphIds[u],h=t.projectedText(p,o),g=t.rawText(p);if(!h||g===null)return "";d.push(h.sliceRaw(u===i?a.start.offset:0,u===l?a.end.offset:g.length));}return d.join("\r")}function za(t,e){return {nodeId:e.id,properties:chunk5MWFZ7F4_cjs.Ob(e),lock:chunk5MWFZ7F4_cjs.$i(t.part,e.id),paragraphIds:Ga(e)}}function Ga(t){let e=chunk5MWFZ7F4_cjs.Mb(t);if(!e)return [];let o=[];return chunk5MWFZ7F4_cjs.Hc(e.children,o,0),o.map(n=>n.id)}var fs=new Set(["unlocked","sdtLocked","contentLocked","sdtContentLocked"]),gs=4096,Xa=64;function Ya(t){if(t===void 0)return {ok:true,value:null};if(typeof t!="object"||t===null)return {ok:false,field:"payload"};let e=t;for(let o of ["namespaceUri","rootLocalName","nodeId"]){let n=e[o];if(typeof n!="string"||n.length===0||n.length>gs)return {ok:false,field:o}}return typeof e.label!="string"||e.label.length>chunkH7XMRUAO_cjs.da?{ok:false,field:"label"}:typeof e.data!="string"||e.data.length===0||e.data.length>chunkH7XMRUAO_cjs.ca?{ok:false,field:"data"}:{ok:true,value:{namespaceUri:e.namespaceUri,rootLocalName:e.rootLocalName,nodeId:e.nodeId,label:e.label,data:e.data}}}function Ja(t){let e=t.at!==void 0,o=t.span!==void 0;return e===o?{message:"a custom node goes at a position or over a span, not both",detail:e?"at+span":"no-place"}:typeof t.tag!="string"||t.tag.length===0?{message:"a custom node carries its identity in its tag",detail:"tag"}:t.tag.length>Xa?{message:`w:tag caps at ${String(Xa)} characters; a longer payload belongs in the store`,detail:"tag"}:typeof t.text!="string"||t.text.length===0?{message:"a custom node shows some text",detail:"text"}:t.lock!==void 0&&!fs.has(t.lock)?{message:"that is not a lock",detail:String(t.lock)}:null}function Qa(t,e,o,n){return {paragraphId:e.paragraphId,offset:e.offset,...o.offset>e.offset?{replaceUntil:o.offset}:{},tag:t.tag,text:t.text,...t.title===void 0?{}:{alias:t.title},...t.lock===void 0||t.lock==="unlocked"?{}:{lock:t.lock},...n===null?{}:{payload:n}}}function Za(t,e,o){if(t.span){let a=K(t.span,e,o);return a.ok?a.value?a.value.start.paragraphId!==a.value.end.paragraphId?{code:"unsupported-content",message:"a custom node wraps text inside one paragraph",detail:"multi-paragraph"}:{range:a.value}:{code:"invalid-offset",message:"that story holds nothing to wrap",detail:"empty-story"}:{code:a.code,message:"that span is not a place",detail:a.detail}}let n=ae(t.at,e,o);return n.ok?{range:{start:n.value,end:n.value}}:{code:n.code,message:"that is not a place",detail:n.detail}}var Ie=/[\r\n\v\f\u2028\u2029]/,ys=16,hs=64;function ks(t,e,o){return Object.freeze(o===void 0?{code:t,message:e}:{code:t,message:e,detail:o})}function y(t,e,o){return {ok:false,error:ks(t,e,o)}}var at=Object.freeze({kind:"applied"});function E(t){return {ok:true,kind:"query",value:t}}function Un(t){let{runPropertyEdits:e,mergedParagraphMarkProperties:o}=Er(()=>t.reads.package?chunk5MWFZ7F4_cjs.Sc(t.reads.package)?.root??null:null,()=>t.reads.package?chunk5MWFZ7F4_cjs.eg(t.reads.package)?.root??null:null,()=>t.displayMode??"proposed"),{handles:n,capabilities:a}=t,i=t.reads,l=new Map,d=new Map,u=s=>{let f=`${Q(s.story)}:${s.root.id}`,x=l.get(f);if(x)return x;let O=new Map,R=s.paragraphIds.map(c=>{let b={id:c};return O.set(c,b),b}),r={externalCreatedCount:0,reads:s,order:R,slotById:O,created:[],restructured:new Set,touched:new Set,textEdits:new Ye,formatted:new Set,selected:new Set,retargets:[]};return l.set(f,r),r},p=[],h=Sa(),g=false,v=null,m=s=>v===null?(v=s,null):v===s?null:y("conflicting-operations","one batch writes into one story",`${Q(v.reads.story)} then ${Q(s.reads.story)}`),k=s=>m(u(s)),A=s=>{let f=i.package;return f===null?null:Ea(f,s)},P=s=>{let f=n.resolve(s,"comment");if(!f||f.kind!=="comment")return {ok:false,planned:y("invalid-handle","that handle does not name a comment","comment")};let x=i.story(f.story);if(!x)return {ok:false,planned:y("invalid-handle","that story is not in this document")};let R=A(x)?.byId(f.commentId)??null;return R?{ok:true,reads:x,item:R}:{ok:false,planned:y("invalid-handle","this document no longer holds that comment",f.commentId)}},w=s=>{let f=n.resolve(s,"revision");if(!f||f.kind!=="revision")return {ok:false,planned:y("invalid-handle","that handle does not name a tracked change","revision")};let x=i.story(f.story);if(!x)return {ok:false,planned:y("invalid-handle","that story is not in this document")};let O=jn(x).find(R=>R.id===f.revisionId)??null;return O?{ok:true,reads:x,item:O}:{ok:false,planned:y("invalid-handle","this document no longer holds that tracked change",f.revisionId)}},N=(s,f)=>{let x=s.rawText(f.start.paragraphId),O=s.rawText(f.end.paragraphId);if(x===null||O===null)return null;let R={story:s.story,paragraphId:f.start.paragraphId,index:s.indexOf(f.start.paragraphId),offset:Math.min(f.start.offset,x.length)},r={story:s.story,paragraphId:f.end.paragraphId,index:s.indexOf(f.end.paragraphId),offset:Math.min(f.end.offset,O.length)};return Y({start:R,end:r})},L=(s,f)=>s.order.indexOf(f),D=(s,f)=>s.selected.has(f)?y("conflicting-operations","this batch selects a paragraph it also edits",f):null,M=(s,f)=>{let x=D(s,f);return x||(s.restructured.has(f)||s.touched.has(f)?y("conflicting-operations","another operation in this batch already changes that paragraph",f):(s.restructured.add(f),s.touched.add(f),null))},j=(s,f)=>{let x=D(s,f);return x||(s.restructured.has(f)||s.textEdits.has(f)?y("conflicting-operations","another operation in this batch restructures that paragraph",f):(s.touched.add(f),null))},S=(s,f,x)=>{let O=`${x}:${f}`;if(s.formatted.has(O))return y("conflicting-operations","another operation in this batch already writes that formatting",f);let R=j(s,f);return R||(s.formatted.add(O),null)},_=(s,f)=>{let x={id:null};return s.order.splice(f,0,x),s.created.push(x),x},Y=s=>Mt(s,n),$=s=>s===null?null:i.story(s.start.story),V=s=>s===void 0||s==="allMarkup"||s==="original"||s==="model",rt=(s,f,x,O)=>{if(!V(O?.projection))return y("unsupported-content","unknown text projection","projection");if(O?.matchWildcards===true)return y("unsupported-capability","wildcard search is not implemented","matchWildcards");if(O?.ignorePunct===true)return y("unsupported-capability","ignoring punctuation is not implemented","ignorePunct");if(O?.ignoreSpace===true)return y("unsupported-capability","ignoring whitespace is not implemented","ignoreSpace");if(!chunkH7XMRUAO_cjs.Ga(x))return y("unsupported-content","that is not a query this host will scan for","text");let R=O?.limit;if(R!==void 0&&(!Number.isInteger(R)||R<0))return y("invalid-offset","limit must be a non-negative integer",String(R));let r=Na(s,f,n,x,O);return E({kind:"spans",spans:r.spans})},tt=(s,f,x,O=false)=>{let R=f.start.paragraphId,r=s.textEdits.has(R)?D(s,R):s.touched.has(R)?y("conflicting-operations","text edits cannot share a paragraph with other edits",R):j(s,R);return r||Mr(s.textEdits,f,x,n,O)},nt=(s,f,x,O=false)=>{if(typeof x!="string"||Ie.test(x))return y("unsupported-content","insertText needs text without paragraph marks","text");let R=m(s);if(R)return R;let r=t.replacementLanding?.(f.paragraphId,f.offset,f.offset)!=null,c=!r&&Fr(s.reads.part,f.paragraphId,f.offset,x);if(c)return c;if(!r&&Cn(s.reads.part,f.paragraphId,f.offset))return tt(s,{start:f,end:f},x,O);let b=M(s,f.paragraphId);return b||{ok:true,kind:"command",ops:x.length?[{op:"insertText",paragraphId:f.paragraphId,offset:f.offset,text:x}]:[],story:s.reads.story,answer:()=>({kind:"span",span:Y({start:f,end:{...f,offset:f.offset+x.length}})})}},At=(s,f,x)=>{let O=s.reads;if(typeof x!="string")return y("unsupported-content","replaceSpan needs text","text");if(Ie.test(x))return y("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let R=St(f,O),r=f.start.paragraphId,c=[],b=m(s);if(b)return b;let I=R.length===1?f.end.offset:(O.rawText(r)??"").length,C=t.replacementLanding?.(r,f.start.offset,I);if(R.length===1&&C==null&&Cn(O.part,r,f.start.offset))return tt(s,f,x);if(R.length===1){let et=M(s,r);if(et)return et;if(C==null)return Dr(O.part,f,x,n);f.end.offset>f.start.offset&&c.push({op:"deleteText",paragraphId:r,start:f.start.offset,end:f.end.offset});}else {for(let B of R){let U=M(s,B);if(U)return U}let et=f.end.paragraphId,G=(O.rawText(r)??"").length;f.start.offset<G&&c.push({op:"deleteText",paragraphId:r,start:f.start.offset,end:G}),f.end.offset>0&&c.push({op:"deleteText",paragraphId:et,start:0,end:f.end.offset});for(let B of R.slice(1,-1))c.push({op:"deleteBlock",blockId:B});c.push({op:"joinParagraphs",firstId:r,secondId:et});for(let B of R.slice(1)){let U=s.slotById.get(B);U&&s.order.splice(L(s,U),1);}}let T=C??f.start.offset;x.length>0&&c.push({op:"insertText",paragraphId:r,offset:T,text:x});let F={...f.start,paragraphId:r,offset:T},J=()=>({kind:"span",span:Y({start:F,end:{...F,offset:F.offset+x.length}})});return {ok:true,kind:"command",ops:c,story:s.reads.story,answer:J}},bt=(s,f)=>{let x=s.reads;if(typeof f!="string")return y("unsupported-content","replaceSpan needs text","text");if(Ie.test(f))return y("unsupported-content","text carrying a paragraph mark is not written by this host","paragraph-mark-in-text");let O=x.blocks,R=O.filter(B=>B.removable),r=O.filter(B=>!B.removable).flatMap(B=>B.paragraphIds),c=r.length===0?R.find(B=>B.kind==="paragraph"):void 0;if(!c&&r.length===0)return y("invalid-offset","that story holds no paragraph this host can write into","no-top-level-paragraph");let b=m(s);if(b)return b;for(let B of x.paragraphIds){let U=M(s,B);if(U)return U}let I=[],C=(c?[c.id]:[...r]).sort((B,U)=>x.indexOf(B)-x.indexOf(U)),T=C[0],F=(x.rawText(T)??"").length;for(let B of C){let U=(x.rawText(B)??"").length;U>0&&I.push({op:"deleteText",paragraphId:B,start:0,end:U});}for(let B of R)B.id!==c?.id&&I.push({op:"deleteBlock",blockId:B.id});let J=t.replacementLanding?.(T,0,F)??0;f.length>0&&I.push({op:"insertText",paragraphId:T,offset:J,text:f});for(let B of R)if(B.id!==c?.id)for(let U of B.paragraphIds){let It=s.slotById.get(U);It&&s.order.splice(L(s,It),1);}let et={story:x.story,paragraphId:T,index:x.indexOf(T),offset:J},G=()=>({kind:"span",span:Y({start:et,end:{...et,offset:J+f.length}})});return {ok:true,kind:"command",ops:I,story:x.story,answer:G}},it=(s,f)=>{if(!Array.isArray(f)||f.length<1||f.length>1e4||f.some(O=>typeof O!="string"||Ie.test(O)||!chunk5MWFZ7F4_cjs.O(O)))return y("unsupported-content","replaceStoryBlocks needs 1-10000 valid XML text strings without paragraph marks","paragraphs");let x=m(s);if(x)return x;for(let O of s.reads.paragraphIds){let R=M(s,O);if(R)return R}s.order.splice(0,s.order.length);for(let O=0;O<f.length;O+=1)_(s,O);return {ok:true,kind:"command",ops:[{op:"replaceStoryBlocks",storyRootId:s.reads.root.id,paragraphs:f}],story:s.reads.story,answer:()=>at}},st=(s,f,x,O)=>{let R=s.reads;if(typeof O!="string")return y("unsupported-content","insertParagraph needs text","text");if(Ie.test(O))return y("unsupported-content","a paragraph mark inside a paragraph\u2019s text is not written by this host","paragraph-mark-in-text");let r=m(s);if(r)return r;let c=M(s,f.paragraphId);if(c)return c;let b=s.slotById.get(f.paragraphId);if(!b)return y("invalid-handle","that paragraph is not in the body");let I=(R.rawText(f.paragraphId)??"").length,C=[];x==="after"?(O.length>0&&C.push({op:"insertText",paragraphId:f.paragraphId,offset:I,text:O}),C.push({op:"splitParagraph",paragraphId:f.paragraphId,offset:I})):(O.length>0&&C.push({op:"insertText",paragraphId:f.paragraphId,offset:0,text:O}),C.push({op:"splitParagraph",paragraphId:f.paragraphId,offset:O.length}));let T=_(s,L(s,b)+1);x==="before"&&s.retargets.push({from:f.paragraphId,slot:T});let F=()=>{let J=x==="after"?T.id:f.paragraphId;return J===null?at:{kind:"handle",handle:n.paragraph(J,R.story)}};return {ok:true,kind:"command",ops:C,story:R.story,answer:F}},W=(s,f,x,O,R)=>{let r=s.reads;if(!Array.isArray(x)||x.length===0)return y("unsupported-content","split needs at least one delimiter","delimiters");if(x.length>ys)return y("unsupported-content","too many delimiters",String(x.length));for(let U of x){if(typeof U!="string"||U.length===0)return y("unsupported-content","a delimiter must be a non-empty string","delimiters");if(U.length>hs)return y("unsupported-content","that delimiter is too long","delimiters")}let c=m(s);if(c)return c;let b=M(s,f.paragraphId);if(b)return b;let I=s.slotById.get(f.paragraphId);if(!I)return y("invalid-handle","that paragraph is not in the body");let C=r.rawText(f.paragraphId)??"",T=Br(C,x),F=[],J=[],et=[];if(T.length===0)et.push(C);else if(O){for(let pt of [...T].reverse())F.push({op:"deleteText",paragraphId:f.paragraphId,start:pt.start,end:pt.start+pt.length});let U=0,It=0;for(let pt of T){let sn=pt.start-U;J.push(sn),et.push(C.slice(It,pt.start)),It=pt.start+pt.length,U+=pt.length;}et.push(C.slice(It));}else {let U=0;for(let It of T){let pt=It.start+It.length;J.push(pt),et.push(C.slice(U,pt)),U=pt;}et.push(C.slice(U));}J.length>0&&F.push({op:"splitParagraphMany",paragraphId:f.paragraphId,offsets:J});let G=[I];for(let U=0;U<J.length;U+=1)G.push(_(s,L(s,I)+1+U));let B=U=>{let It=U.story(r.story),pt=[];return G.forEach((sn,oi)=>{let ln=sn.id;if(ln===null)return;let dn=It?.rawText(ln)??et[oi]??"",[ri,ai]=R?Wr(dn,0,dn.length):[0,dn.length],Gn=n.paragraph(ln,r.story);pt.push({start:{paragraph:Gn,offset:ri},end:{paragraph:Gn,offset:ai}});}),{kind:"spans",spans:pt}};return {ok:true,kind:"command",ops:F,story:r.story,answer:B}},dt=(s,f)=>{let x=m(s);if(x)return x;let O=M(s,f.paragraphId);if(O)return O;let R=s.slotById.get(f.paragraphId);return R&&s.order.splice(L(s,R),1),{ok:true,kind:"command",ops:[{op:"deleteBlock",blockId:f.paragraphId}],story:s.reads.story,answer:()=>at}},yt=(s,f,x)=>{let O=s.reads,R=O.part,r=m(s);if(r)return r;let c=Oa(x??{});if(!c.ok)return y("unsupported-content","that is not formatting this host writes",c.detail);let b=[];for(let I of Kt(f,O)){if(I.end<=I.start&&!I.whole)continue;let C=S(s,I.paragraphId,"runs");if(C)return C;for(let T of e(R,I.paragraphId,I.start,I.end,c.value.filter(F=>F.localName!=="vertAlign"),t.displayMode))b.push({op:"setRunProperties",paragraphId:I.paragraphId,start:T.start,end:T.end,properties:Fn(T.properties,x),...T.targetRunIds?{targetRunIds:T.targetRunIds}:{}});I.whole&&b.push({op:"setParagraphMarkProperties",paragraphId:I.paragraphId,properties:Fn(o(R,I.paragraphId,c.value.filter(T=>T.localName!=="vertAlign")),x)});}return b.length===0?y("invalid-offset","that range covers no characters to format","collapsed-range"):{ok:true,kind:"command",ops:b,story:O.story,answer:()=>at}},Z=(s,f,x)=>{let O=s.reads,R=O.part,r=m(s);if(r)return r;let c=We(x,O.styles());if(!c.ok)return y("unsupported-content","that is not a style this document has",c.detail);let b={localName:"pStyle",attributes:{val:c.styleId}},I=[];for(let C of St(f,O)){let T=S(s,C,"paragraph");if(T)return T;I.push({op:"setParagraphProperties",paragraphId:C,properties:chunk5MWFZ7F4_cjs.Pg(chunk5MWFZ7F4_cjs.Ng(R,C),b)});}return I.length===0?y("invalid-offset","that story holds no paragraph to style","empty-story"):{ok:true,kind:"command",ops:I,story:O.story,answer:()=>at}},z=(s,f,x)=>{let O=s.reads,R=O.part,r=m(s);if(r)return r;let c=Ra(R,f.paragraphId,x??{},O.styles());if(!c.ok)return y("unsupported-content","that is not paragraph formatting this host writes",c.detail);let b=S(s,f.paragraphId,"paragraph");return b||{ok:true,kind:"command",ops:[{op:"setParagraphProperties",paragraphId:f.paragraphId,properties:c.value}],story:O.story,answer:()=>at}},_t=(s,f)=>{let x=i.body;if(!x)return y("document-unavailable","this host holds no document right now");let O=i.sections();if(!O[s])return y("invalid-handle","that section is not in this document");let r=pr(f);if(!r.ok)return y("unsupported-content",r.reason,r.detail);let c=_r(x,O,s);if(c===null)return y("unsupported-content","that section holds no paragraph to address it by","no-anchor");let b=u(x),I=m(b);return I||{ok:true,kind:"command",ops:[{op:"setSectionProperties",...r.value,anchorParagraphId:c}],story:Pt,answer:()=>at}},Pe=(s,f)=>({ok:true,kind:"command",ops:[{op:"deleteNote",noteKind:s,noteId:f}],story:Pt,lifecycle:true,answer:()=>at}),rn=s=>{let f=n.resolve(s,"list");if(!f||f.kind!=="list")return y("invalid-handle","that handle does not name a list","list");let x=i.story(f.story);if(!x)return y("invalid-handle","that story is not in this document");let O=Xt(x).find(R=>R.numId===f.numId);return O?{ok:true,plan:u(x),list:O}:y("invalid-handle","this story numbers nothing with that list",f.numId)},an=s=>{if(typeof s!="object"||s===null)return y("invalid-handle","that is not a scope a control lives in","scope");let f=s;if("body"in s){let x=lt(f.body,"body",n,i);return x.ok?{reads:x.value,node:x.value.root}:y(x.code,"that handle does not name a body",x.detail)}if("contentControl"in s){let x=Tt(f.contentControl);return "control"in x?{reads:x.reads,node:x.node}:x}return y("invalid-handle","that is not a scope a control lives in","scope")},Tt=s=>{let f=n.resolve(s,"contentControl");if(!f||f.kind!=="contentControl")return y("invalid-handle","that handle does not name a content control","contentControl");let x=i.story(f.story);if(!x)return y("invalid-handle","that story is not in this document");let O=Wa(x,f.nodeId),R=Ua(x,f.nodeId);return !O||!R?y("invalid-handle","this document no longer holds that content control"):{reads:x,control:O,node:R}},qa=(s,f,x)=>{if(!Number.isInteger(x)||x<0||x>le)return y("invalid-offset",`a list level is 0 to ${String(le)}`,String(x));let O=Ae(s.reads,f);if(!O)return y("unsupported-content","that paragraph is not in a list",f);if(!i.package||!ve(i.package,O.numId,x))return y("unsupported-content","list level is not defined; configure that level first",f);let R=m(s);if(R)return R;let r=S(s,f,"paragraph");return r||{ok:true,kind:"command",ops:[{op:"setListLevel",paragraphId:f,level:x}],story:s.reads.story,answer:()=>at}},ti=(s,f,x,O)=>{if(x!=="start"&&x!=="end")return y("unknown-operation","a list takes an item at its start or its end",String(x));let R=s.reads,r=x==="start"?f.paragraphIds[0]:f.paragraphIds[f.paragraphIds.length-1];if(r===void 0)return y("invalid-handle","that list holds no paragraph");let c={story:R.story,paragraphId:r,index:R.indexOf(r)};return st(s,c,x==="start"?"before":"after",O)},$n=(s,f)=>{if(f.start.paragraphId!==f.end.paragraphId)return null;for(let x of wa(s,f.start.paragraphId))if(x.start<=f.start.offset&&x.end>=f.end.offset)return x;return null},ei=(s,f,x)=>{if(typeof x!="string")return y("unsupported-content","a hyperlink target is a string","target");let O=s.reads,R=$n(O,f),r=f.start.paragraphId===f.end.paragraphId&&f.start.offset===f.end.offset,c=R&&(f.start.offset!==R.start||f.end.offset!==R.end),b=c?{range:{start:f.start.offset,end:f.end.offset}}:{};if(c){let G=O.node(R.paragraphId),B=G?.kind==="paragraph"?G.children.find(U=>U.id===R.id):void 0;if(r||!B||!chunk5MWFZ7F4_cjs.ji(B)||G?.kind!=="paragraph"||!G.children.some(U=>U.id===R.id))return y("unsupported-capability","partial hyperlink edits require ordinary text in a paragraph")}if(x.length===0){if(!R)return y("unsupported-content","that text is not a link","no-link");let G=m(s);if(G)return G;let B=j(s,R.paragraphId);return B||{ok:true,kind:"command",ops:[{op:"removeHyperlink",linkId:R.id,...b}],story:O.story,answer:()=>at}}let I={},C=null;if(x.startsWith("#")){let G=x.slice(1);if(G.length===0||!Dn(O,G))return y("unsupported-content","this document declares no such bookmark",x);I={anchor:G};}else {if(chunk5MWFZ7F4_cjs.Tf(x)===null)return y("unsupported-content","this engine will not author that target","target");C=x;}let T=m(s);if(T)return T;let F=G=>C===null?{ok:true,kind:"command",ops:[G(I)],story:O.story,answer:()=>at}:{ok:true,kind:"command",ops:[],relate:{url:C,ops:B=>[G({relationshipId:B})]},story:O.story,answer:()=>at};if(R){let G=j(s,R.paragraphId);return G||F(B=>({op:"setHyperlinkTarget",linkId:R.id,...b,...B}))}if(r)return y("unsupported-content","a link with no text has nothing to click","collapsed");if(f.start.paragraphId!==f.end.paragraphId)return y("unsupported-content","a link lives inside one paragraph","crosses-paragraph-mark");let J=j(s,f.start.paragraphId);if(J)return J;let et=O.styles().idOf("hyperlink");return F(G=>({op:"insertHyperlink",paragraphId:f.start.paragraphId,start:f.start.offset,end:f.end.offset,...G,...et===null?{}:{styleId:et}}))},Kn=(s,f,x)=>{let O=s.reads;if(!a.selection||!t.select)return y("unsupported-capability","this host has no reader to move","selection");if(x!=="select"&&x!=="start"&&x!=="end")return y("unknown-operation","that is not a selection mode",String(x));let R=St(f,O);for(let r of R)if(s.touched.has(r))return y("conflicting-operations","this batch edits a paragraph the selection covers",r);for(let r of R)s.selected.add(r);return p.push({range:f,mode:x}),{ok:true,kind:"command",ops:[],story:O.story,answer:()=>at}},zn=s=>{let f=n.resolve(s,"bookmark");if(!f||f.kind!=="bookmark")return y("invalid-handle","that handle does not name a bookmark","bookmark");let x=i.story(f.story);if(!x)return y("invalid-handle","that story is not in this document");let O=Dn(x,f.name);if(!O)return y("invalid-handle","this document no longer declares that bookmark",f.name);let R=r=>({story:x.story,paragraphId:r.paragraphId,index:x.indexOf(r.paragraphId),offset:r.offset});return {reads:x,range:{start:R(O.start),end:R(O.end)}}},ni=(s,f)=>{let x=ra(s,t,r=>Un({...t,reads:r}));if(x)return f&&x.ok&&x.kind==="command"?y("unsupported-content","header/footer creation cannot be tracked"):x;let O=na(s,{trackingAuthor:f,trackedRangeReplacement:t.trackedRangeReplacement,handles:n,reads:i,admitWrite:(r,c,b)=>{let I=u(r),C=m(I);if(C)return C;for(let T of b){let F=M(I,T);if(F)return F}return I.externalCreatedCount+=c,null}});if(O)return O;let R=f!==void 0;switch(R&&s.op==="insertText"?s={op:"proposeInsertion",span:{start:s.at,end:s.at},text:s.text,where:"Before",author:f}:R&&s.op==="replaceSpan"&&(s={op:"proposeReplacement",span:s.span,text:s.text,author:f}),s.op){case "getFields":case "getField":case "setFieldCode":case "deleteField":case "updateFieldResult":case "insertField":return qr(s,n,i,(r,c,b)=>{let I=u(r);return m(I)??(b?null:M(I,c))},t.fieldPageContext);case "getInlinePictures":case "getInlinePicture":case "setInlinePicture":case "deleteInlinePicture":case "insertInlinePicture":return ua(s,n,i,(r,c)=>{let b=u(r);return m(b)??M(b,c)});case "insertBreak":return ca(s,n,i,(r,c,b)=>{let I=u(r),C=m(I)??M(I,c);return C||(I.externalCreatedCount+=b),C});case "startNewList":case "attachToList":case "detachFromList":case "setListLevelFormat":return ya(s,n,i,(r,c,b)=>{let I=u(r);return m(I)??S(I,c,b?`list:${b.numId}:${b.level}`:"paragraph")},f);case "removeDocumentInformation":case "getDocumentProperty":case "setDocumentProperties":return Or(s,i,()=>m(u(i.body)),!t.collaborative);case "getDocument":return E({kind:"handle",handle:n.document()});case "getBody":return n.resolve(s.document,"document")?i.body?E({kind:"handle",handle:n.body(Pt)}):y("document-unavailable","this host holds no document right now"):y("invalid-handle","that handle does not name a document","document");case "getParagraphs":{let r=lt(s.body,"body",n,i);return r.ok?E({kind:"handles",handles:r.value.paragraphIds.map(c=>n.paragraph(c,r.value.story))}):y(r.code,"that handle does not name a body",r.detail)}case "getRange":{let r=K(s.span,n,i);if(!r.ok)return y(r.code,"that span is not a place",r.detail);if(!r.value)return y("invalid-offset","empty story");if(!["Whole","Content","Start","End"].includes(s.location))return y("unsupported-content","unsupported range location");let c=r.value,b=s.location==="Start"?{start:c.start,end:c.start}:s.location==="End"?{start:c.end,end:c.end}:c;return E({kind:"span",span:Mt(b,n)})}case "getSpanParagraphs":{let r=K(s.span,n,i);if(!r.ok)return y(r.code,"that span is not a place",r.detail);let c=ot(s.span,n,i);return c.ok?E({kind:"handles",handles:St(r.value,c.value).map(b=>n.paragraph(b,c.value.story))}):y(c.code,"that span is not a place",c.detail)}case "getText":{if(!V(s.projection))return y("unsupported-content","unknown text projection","projection");if(n.resolve(s.target,"body")){let I=lt(s.target,"body",n,i);return I.ok?E({kind:"text",text:I.value.text(s.projection??"allMarkup")}):y(I.code,"that handle does not name a body",I.detail)}let c=kt(s.target,n,i);if(!c.ok)return y(c.code,"that handle does not name a body or a paragraph",c.detail);let b=i.story(c.value.story);return E({kind:"text",text:b?.paragraphText(c.value.paragraphId,s.projection??"allMarkup")??""})}case "getSpanText":{if(!V(s.projection))return y("unsupported-content","unknown text projection","projection");let r=K(s.span,n,i);if(!r.ok)return y(r.code,"that span is not a place",r.detail);let c=ot(s.span,n,i);return c.ok?E({kind:"text",text:Lr(r.value,c.value,bn,s.projection??"allMarkup")}):y(c.code,"that span is not a place",c.detail)}case "getParagraphId":{let r=kt(s.paragraph,n,i);if(!r.ok)return y(r.code,"that handle does not name a paragraph",r.detail);let b=i.story(r.value.story)?.paragraph(r.value.paragraphId);return E({kind:"text",text:b?.paraId??""})}case "search":{let r=K(s.scope,n,i);if(!r.ok)return y(r.code,"that is not a scope to search",r.detail);let c=ot(s.scope,n,i);return c.ok?rt(c.value,r.value,s.text,s.options):y(c.code,"that is not a scope to search",c.detail)}case "proposeInsertion":case "proposeDeletion":case "proposeReplacement":return La(s,R,n,i,(r,c)=>{let b=u(r);return m(b)??M(b,c)},t.trackedRangeReplacement!==false);case "insertText":{let r=ae(s.at,n,i);if(!r.ok)return y(r.code,"that is not a place to insert at",r.detail);let c=i.story(r.value.story);return c?nt(u(c),r.value,s.text,"at"in s.at&&s.at.at==="start"):y("invalid-handle","that story is not in this document")}case "replaceSpan":{if("body"in s.span){let b=lt(s.span.body,"body",n,i);return b.ok?bt(u(b.value),s.text):y(b.code,"that handle does not name a body",b.detail)}let r=K(s.span,n,i);if(!r.ok)return y(r.code,"that span is not a place",r.detail);if(!r.value)return y("invalid-offset","that story holds no paragraph to write into","empty-story");let c=$(r.value);return c?At(u(c),r.value,s.text):y("invalid-handle","that story is not in this document")}case "replaceStoryBlocks":{let r=lt(s.body,"body",n,i);return r.ok?it(u(r.value),s.paragraphs):y(r.code,"that handle does not name a body",r.detail)}case "insertParagraph":{let r=Xe(s.anchor,n,i);if(!r.ok)return y(r.code,"that is not a paragraph to insert beside",r.detail);if(s.where!=="before"&&s.where!=="after")return y("unknown-operation","that is not a place to insert",String(s.where));let c=i.story(r.value.story);if(!c)return y("invalid-handle","that story is not in this document");let b=R&&Fa(c,r.value.paragraphId,f);return b?{ok:false,error:b}:st(u(c),r.value,s.where,s.text)}case "splitParagraph":{let r=kt(s.paragraph,n,i);if(!r.ok)return y(r.code,"that handle does not name a paragraph",r.detail);let c=i.story(r.value.story);return c?W(u(c),r.value,s.delimiters,s.trimDelimiters===true,s.trimSpacing===true):y("invalid-handle","that story is not in this document")}case "getFont":{let r=K(s.span,n,i);if(!r.ok)return y(r.code,"that span is not a place",r.detail);let c=ot(s.span,n,i);if(!c.ok)return y(c.code,"that span is not a place",c.detail);let b=Kt(r.value,c.value);return E({kind:"font",font:Ia(c.value.part,b,t.displayMode)})}case "setFont":{let r=K(s.span,n,i);if(!r.ok)return y(r.code,"that span is not a place",r.detail);if(!r.value)return y("invalid-offset","that story holds no paragraph to format","empty-story");let c=$(r.value);return c?yt(u(c),r.value,s.font):y("invalid-handle","that story is not in this document")}case "getStyle":{let r=K(s.span,n,i);if(!r.ok)return y(r.code,"that span is not a place",r.detail);let c=ot(s.span,n,i);if(!c.ok)return y(c.code,"that span is not a place",c.detail);let b=c.value.part,I=c.value.styles(),C=St(r.value,c.value).map(F=>Ve(b,F,I)),T=C.length>0&&C.every(F=>F!==null&&F===C[0])?C[0]:null;return E({kind:"style",name:T})}case "setStyle":{let r=K(s.span,n,i);if(!r.ok)return y(r.code,"that span is not a place",r.detail);if(!r.value)return y("invalid-offset","that story holds no paragraph to style","empty-story");let c=$(r.value);return c?Z(u(c),r.value,s.name):y("invalid-handle","that story is not in this document")}case "getParagraphFormat":{let r=Xe(s.paragraph,n,i);if(!r.ok)return y(r.code,"that is not a paragraph",r.detail);let c=i.story(r.value.story);if(!c)return y("document-unavailable","this host holds no document right now");let b=Pa(c.part,r.value.paragraphId,c.styles());return b?E({kind:"paragraphFormat",format:b}):y("invalid-handle","that handle does not name a paragraph")}case "setParagraphFormat":{let r=Xe(s.paragraph,n,i);if(!r.ok)return y(r.code,"that is not a paragraph",r.detail);let c=i.story(r.value.story);return c?z(u(c),r.value,s.format):y("invalid-handle","that story is not in this document")}case "deleteParagraph":{let r=kt(s.paragraph,n,i);if(!r.ok)return y(r.code,"that handle does not name a paragraph",r.detail);let c=i.story(r.value.story);return c?dt(u(c),r.value):y("invalid-handle","that story is not in this document")}case "getSections":return n.resolve(s.document,"document")?E({kind:"handles",handles:i.sections().map(r=>n.section(r.index))}):y("invalid-handle","that handle does not name a document","document");case "getPageSetup":{let r=n.resolve(s.section,"section");if(!r||r.kind!=="section")return y("invalid-handle","that handle does not name a section","section");let c=i.sections()[r.index];return c?E({kind:"pageSetup",setup:c.pageSetup}):y("invalid-handle","that section is not in this document")}case "setPageSetup":{let r=n.resolve(s.section,"section");return !r||r.kind!=="section"?y("invalid-handle","that handle does not name a section","section"):_t(r.index,s.setup)}case "getFurniture":{let r=n.resolve(s.section,"section");if(!r||r.kind!=="section")return y("invalid-handle","that handle does not name a section","section");if(s.kind!=="header"&&s.kind!=="footer")return y("unknown-operation","that is not furniture",String(s.kind));let c={kind:s.kind,sectionIndex:r.index,variant:s.variant};return dr(c)?i.sections()[r.index]?E({kind:"handle",handle:n.body(c)}):y("invalid-handle","that section no longer exists"):y("unknown-operation","that is not a furniture variant",String(s.variant))}case "getNotes":{if(!n.resolve(s.document,"document"))return y("invalid-handle","that handle does not name a document","document");if(s.noteKind!=="footnote"&&s.noteKind!=="endnote")return y("unknown-operation","that is not a kind of note",String(s.noteKind));let r=s.noteKind,c=i.noteIds(r);if(!c.ok)return y("ambiguous-document",`${r} identities are not completely and unambiguously enumerable`,c.reason==="duplicates"?c.duplicateIds.join(","):c.reason);let b=c.ids;if(s.scope){let I=lt(s.scope,"body",n,i);if(!I.ok)return y(I.code,"that handle does not name a body",I.detail);let C=Rr(I.value.root,r),T=new Set(c.ids);if(C.some(F=>!T.has(F)))return y("ambiguous-document","a note reference has no matching note");b=C;}return E({kind:"handles",handles:b.map(I=>n.note(r,I))})}case "getNoteBody":case "getNoteText":{let r=n.resolve(s.note,"note");if(!r||r.kind!=="note")return y("invalid-handle","that handle does not name a note","note");let c=r,b=i.story(c);return b?s.op==="getNoteText"?E({kind:"text",text:b.text(s.projection)}):E({kind:"handle",handle:n.body(c)}):y("invalid-handle","that note is not in this document",Q(c))}case "getNoteKind":{let r=n.resolve(s.note,"note");return !r||r.kind!=="note"?y("invalid-handle","that handle does not name a note","note"):E({kind:"text",text:r.noteKind})}case "deleteNote":{let r=n.resolve(s.note,"note");if(!r||r.kind!=="note")return y("invalid-handle","that handle does not name a note","note");let c=i.noteIds(r.noteKind);return c.ok?c.ids.includes(r.noteId)?Pe(r.noteKind,r.noteId):y("invalid-handle","that note is not in this document"):y("ambiguous-document",`${r.noteKind} identities are not completely and unambiguously enumerable`,c.reason==="duplicates"?c.duplicateIds.join(","):c.reason)}case "getLists":{let r=lt(s.body,"body",n,i);return r.ok?E({kind:"handles",handles:Xt(r.value).map(c=>n.list(c.numId,r.value.story))}):y(r.code,"that handle does not name a body",r.detail)}case "getListId":{let r=rn(s.list);return "list"in r?E({kind:"number",value:Number(r.list.numId)}):r}case "getListById":{let r=lt(s.body,"body",n,i);if(!r.ok)return y(r.code,"that handle does not name a body",r.detail);if(!Number.isInteger(s.id)||s.id<=0)return y("unsupported-content","a list is numbered from one",String(s.id));let c=String(s.id),b=Xt(r.value).find(I=>I.numId===c);return b?E({kind:"handle",handle:n.list(b.numId,r.value.story)}):y("invalid-handle","no list in that story carries that number",c)}case "getListParagraphs":{let r=rn(s.list);if(!("list"in r))return r;let c=s.level;if(c!==void 0&&(!Number.isInteger(c)||c<0||c>le))return y("invalid-offset",`a list level is 0 to ${String(le)}`,String(c));let b=r.plan.reads,I=c===void 0?r.list.paragraphIds:r.list.paragraphIds.filter(C=>Ae(b,C)?.level===c);return E({kind:"handles",handles:I.map(C=>n.paragraph(C,b.story))})}case "getParagraphList":{let r=kt(s.paragraph,n,i);if(!r.ok)return y(r.code,"that handle does not name a paragraph",r.detail);let c=i.story(r.value.story);if(!c)return y("invalid-handle","that story is not in this document");let b=Ae(c,r.value.paragraphId);return b?E({kind:"handle",handle:n.list(b.numId,c.story)}):y("unsupported-content","that paragraph is not in a list",r.value.paragraphId)}case "getListLevel":{let r=kt(s.paragraph,n,i);if(!r.ok)return y(r.code,"that handle does not name a paragraph",r.detail);let c=i.story(r.value.story);if(!c)return y("invalid-handle","that story is not in this document");let b=Ae(c,r.value.paragraphId);return b?E({kind:"number",value:b.level}):y("unsupported-content","that paragraph is not in a list",r.value.paragraphId)}case "setListLevel":{let r=kt(s.paragraph,n,i);if(!r.ok)return y(r.code,"that handle does not name a paragraph",r.detail);let c=i.story(r.value.story);return c?qa(u(c),r.value.paragraphId,s.level):y("invalid-handle","that story is not in this document")}case "insertListParagraph":{let r=rn(s.list);return "list"in r?ti(r.plan,r.list,s.where,s.text):r}case "getHyperlink":{let r=K(s.span,n,i);if(!r.ok)return y(r.code,"that span is not a place",r.detail);let c=ot(s.span,n,i);if(!c.ok)return y(c.code,"that span is not a place",c.detail);let b=i.package;if(!b||!r.value)return E({kind:"text",text:""});let I=$n(c.value,r.value);if(!I)return E({kind:"text",text:""});let C=chunk5MWFZ7F4_cjs.Ja(c.value.part,I.id),T=C?Ta(b,c.value.part.name,C):null;return E({kind:"text",text:T??""})}case "setHyperlink":{let r=K(s.span,n,i);if(!r.ok)return y(r.code,"that span is not a place",r.detail);if(!r.value)return y("invalid-offset","that story holds no text to link","empty-story");let c=$(r.value);return c?ei(u(c),r.value,s.target):y("invalid-handle","that story is not in this document")}case "getBookmarks":{let r=K(s.scope,n,i);if(!r.ok)return y(r.code,"that span is not a place",r.detail);let c=ot(s.scope,n,i);if(!c.ok)return y(c.code,"that span is not a place",c.detail);let b=c.value,I=r.value,C=I===null?null:new Set(St(I,b)),T=Hn(b).filter(F=>{if(!C||!C.has(F.start.paragraphId)&&!C.has(F.end.paragraphId)||I===null)return false;let J=F.start.paragraphId===I.end.paragraphId&&F.start.offset>I.end.offset,et=F.end.paragraphId===I.start.paragraphId&&F.end.offset<I.start.offset;return !J&&!et});return E({kind:"handles",handles:T.map(F=>n.bookmark(F.name,b.story))})}case "getBookmarkName":{let r=n.resolve(s.bookmark,"bookmark");return !r||r.kind!=="bookmark"?y("invalid-handle","that handle does not name a bookmark","bookmark"):E({kind:"text",text:r.name})}case "getBookmarkRange":{let r=zn(s.bookmark);return "reads"in r?E({kind:"span",span:Y(r.range)}):r}case "getComments":{let r=K(s.scope,n,i);if(!r.ok)return y(r.code,"that scope is not a place",r.detail);let c=ot(s.scope,n,i);if(!c.ok)return y(c.code,"that scope names no story",c.detail);let b=c.value,I=A(b);if(!I)return y("document-unavailable","this host holds no document");let C=r.value,T=I.roots.filter(F=>{if(!C)return true;let J=F.range;if(!J)return false;let et=b.indexOf(J.start.paragraphId),G=b.indexOf(J.end.paragraphId),B=b.indexOf(C.start.paragraphId),U=b.indexOf(C.end.paragraphId);return G<B||et>U?false:G===B&&et===B&&U===B?J.end.offset>C.start.offset&&J.start.offset<C.end.offset:true});return E({kind:"handles",handles:T.map(F=>n.comment(F.id,b.story))})}case "getCommentReplies":{let r=P(s.comment);return r.ok?E({kind:"handles",handles:r.item.replyIds.map(c=>n.comment(c,r.reads.story))}):r.planned}case "getCommentId":{let r=P(s.comment);return r.ok?E({kind:"text",text:r.item.id}):r.planned}case "getCommentAuthor":{let r=P(s.comment);return r.ok?E({kind:"text",text:r.item.comment.author}):r.planned}case "getCommentDate":{let r=P(s.comment);return r.ok?E({kind:"text",text:r.item.comment.date??""}):r.planned}case "getCommentText":{let r=P(s.comment);if(!r.ok)return r.planned;let c=A(r.reads);return E({kind:"text",text:c?.textOf(r.item.id)??""})}case "getCommentRange":{let r=P(s.comment);if(!r.ok)return r.planned;let c=r.item.range;if(!c||r.item.orphaned)return y("invalid-handle","that comment has no range in this document");let b=N(r.reads,c);return b?E({kind:"span",span:b}):y("invalid-handle","that comment\u2019s range is no longer in the story")}case "getCommentResolved":{let r=P(s.comment);return r.ok?E({kind:"flag",value:r.item.resolved}):r.planned}case "insertComment":return Ba(s,n,i,k);case "setCommentResolved":{let r=P(s.comment);if(!r.ok)return r.planned;if(typeof s.resolved!="boolean")return y("unsupported-content","resolved is a yes or a no",String(s.resolved));let c=m(u(r.reads));return c||{ok:true,kind:"commentWrite",write:{kind:"resolve",commentId:r.item.id,resolved:s.resolved},story:r.reads.story,answer:()=>at}}case "replyToComment":{let r=P(s.comment);if(!r.ok)return r.planned;let c=Vn({author:s.author,text:s.text,date:s.date,kind:"reply"});if(c)return c;let b=r.item.range;if(!b||r.item.orphaned)return y("invalid-handle","that comment has no range to reply over");let I=m(u(r.reads));if(I)return I;let C=r.reads.story,T=Wn(s.date);return {ok:true,kind:"commentWrite",write:{kind:"reply",parentCommentId:r.item.id,anchor:{paragraphId:b.start.paragraphId,start:b.start.offset,end:b.end.offset,...b.end.paragraphId===b.start.paragraphId?{}:{endParagraphId:b.end.paragraphId}},text:s.text,author:s.author,...T===void 0?{}:{date:T}},story:r.reads.story,answer:(F,J)=>J===void 0?at:{kind:"handle",handle:n.comment(J,C)}}}case "deleteComment":{let r=P(s.comment);return r.ok?_a(r.item,r.reads,c=>m(u(c))):r.planned}case "getRevisions":{let r=lt(s.body,"body",n,i);if(!r.ok)return y(r.code,"that handle does not name a body",r.detail);let c=r.value;return E({kind:"handles",handles:jn(c).map(b=>n.revision(b.id,c.story))})}case "getRevisionType":{let r=w(s.revision);return r.ok?E({kind:"text",text:r.item.type}):r.planned}case "getRevisionAuthor":{let r=w(s.revision);return r.ok?E({kind:"text",text:r.item.author}):r.planned}case "getRevisionDate":{let r=w(s.revision);return r.ok?E({kind:"text",text:r.item.date}):r.planned}case "getRevisionRange":{let r=w(s.revision);if(!r.ok)return r.planned;let[c]=r.item.item.ranges;if(!c)return y("invalid-handle","that change covers no characters");let b=N(r.reads,c);return b?E({kind:"span",span:b}):y("invalid-handle","that change\u2019s range is no longer in the story")}case "acceptRevision":case "rejectRevision":{let r=w(s.revision);if(!r.ok)return r.planned;let c=u(r.reads),b=m(c);if(b)return b;let I=Ha(r.reads,r.item.item,s.op==="acceptRevision"?"accept":"reject");return I.length?{ok:true,kind:"command",story:r.reads.story,ops:I,answer:()=>at}:y("unsupported-revision","the table decision has unresolved dependencies")}case "resolveRevisionBatch":case "acceptAllRevisions":case "rejectAllRevisions":return Ma(s,n,i,r=>m(u(r)));case "selectSpan":{let r=K(s.span,n,i);if(!r.ok)return y(r.code,"that span is not a place",r.detail);if(!r.value)return y("invalid-offset","that story holds no paragraph to select","empty-story");let c=$(r.value);return c?Kn(u(c),r.value,s.mode):y("invalid-handle","that story is not in this document")}case "selectBookmark":{let r=zn(s.bookmark);return "reads"in r?Kn(u(r.reads),r.range,s.mode):r}case "getContentControls":{let r=an(s.scope);return "reads"in r?E({kind:"handles",handles:Va(r.reads,r.node).map(c=>n.contentControl(c.nodeId,r.reads.story))}):r}case "getContentControlById":{let r=an(s.scope);if(!("reads"in r))return r;if(!Number.isInteger(s.id))return y("unsupported-content","a control id is a whole number",String(s.id));let c=ie(r.node).find(b=>chunk5MWFZ7F4_cjs.Ob(b).id===s.id);return c?E({kind:"handle",handle:n.contentControl(c.id,r.reads.story)}):y("invalid-handle","no control in that scope carries that id",String(s.id))}case "getContentControlsByTag":case "getContentControlsByTitle":{let r=an(s.scope);if(!("reads"in r))return r;let c=s.op==="getContentControlsByTag"?s.tag:s.title;if(typeof c!="string"||c.length===0)return y("unsupported-content","a tag or title to match is required",s.op);let b=ie(r.node).filter(I=>{let C=chunk5MWFZ7F4_cjs.Ob(I);return s.op==="getContentControlsByTag"?C.tag===c:C.alias===c});return E({kind:"handles",handles:b.map(I=>n.contentControl(I.id,r.reads.story))})}case "getContentControlTag":case "getContentControlTitle":case "getContentControlFileId":case "getContentControlSubtype":case "getContentControlLock":{let r=Tt(s.contentControl);if(!("control"in r))return r;let c=r.control.properties;if(s.op==="getContentControlLock")return E({kind:"text",text:r.control.lock});if(s.op==="getContentControlSubtype")return E({kind:"text",text:c.type});if(s.op==="getContentControlFileId")return E({kind:"text",text:c.id===void 0?"":String(c.id)});let b=s.op==="getContentControlTag"?c.tag:c.alias;return E({kind:"text",text:b??""})}case "getContentControlIsBound":case "getContentControlPlaceholderShown":case "getContentControlTemporary":{let r=Tt(s.contentControl);if(!("control"in r))return r;let c=s.op==="getContentControlIsBound"?r.control.properties.dataBinding!==void 0:s.op==="getContentControlPlaceholderShown"?r.control.properties.showingPlaceholder:r.control.properties.temporary;return E({kind:"flag",value:c})}case "getContentControlText":{let r=Tt(s.contentControl);return "control"in r?E({kind:"text",text:Ka(r.reads,r.node,s.projection)}):r}case "getContentControlParagraphs":{let r=Tt(s.contentControl);return "control"in r?E({kind:"handles",handles:r.control.paragraphIds.map(c=>n.paragraph(c,r.reads.story))}):r}case "getContentControlRange":{let r=Tt(s.contentControl);if(!("control"in r))return r;let c=s.location??"whole";if(!$r.has(c))return y("unsupported-content","that is not a place in a control",c);let b=on(r.reads,r.node);if(!b)return y("unsupported-content","that control holds nothing addressable","empty");let I=c==="start"||c==="before"?b.start:b.end,C=c!=="whole"&&c!=="content",T=F=>({story:r.reads.story,paragraphId:F.paragraphId,index:r.reads.indexOf(F.paragraphId),offset:F.offset});return E({kind:"span",span:Mt(C?{start:T(I),end:T(I)}:{start:T(b.start),end:T(b.end)},n)})}case "setContentControlValue":{let r=Tt(s.contentControl);if(!("control"in r))return r;let c=Gr(s.value);if(!c.ok)return y(c.code,c.message,c.detail);let b=u(r.reads),I=m(b);return I||{ok:true,kind:"command",story:r.reads.story,ops:[{op:"setContentControlValue",controlId:r.control.nodeId,value:c.value}],answer:()=>at}}case "setContentControlProperties":{let r=Tt(s.contentControl);if(!("control"in r))return r;if(R&&(!Jr(r.reads.part,r.control.nodeId,f)||s.lock!==void 0||s.cannotEdit!==void 0||s.cannotDelete!==void 0))return y("unsupported-capability","tracked control metadata requires an own pending insertion; locks require direct edits");if(s.tag===void 0&&s.title===void 0&&s.lock===void 0&&s.cannotEdit===void 0&&s.cannotDelete===void 0)return y("unsupported-content","nothing to write","no-properties");if(s.lock!==void 0&&!Ur.has(s.lock))return y("unsupported-content","that is not a lock this schema declares",s.lock);for(let C of [s.cannotEdit,s.cannotDelete])if(C!==void 0&&typeof C!="boolean")return y("unsupported-content","lock flags must be boolean");let c=u(r.reads),b=s.lock;if(s.cannotEdit!==void 0||s.cannotDelete!==void 0){let C=b??d.get(c)?.get(r.control.nodeId)??r.control.properties.lock,T=s.cannotEdit??(C==="contentLocked"||C==="sdtContentLocked"),F=s.cannotDelete??(C==="sdtLocked"||C==="sdtContentLocked");b=T?F?"sdtContentLocked":"contentLocked":F?"sdtLocked":"unlocked";}let I=m(c);if(I)return I;if(b!==void 0){let C=d.get(c)??new Map;C.set(r.control.nodeId,b),d.set(c,C);}return {ok:true,kind:"command",story:r.reads.story,ops:[{op:"setContentControlProperties",controlId:r.control.nodeId,...s.tag===void 0?{}:{tag:s.tag},...s.title===void 0?{}:{alias:s.title},...b===void 0?{}:{lock:b}}],answer:()=>at}}case "insertContentControlText":{let r=Tt(s.contentControl);if(!("control"in r))return r;let c=zr(r.control.properties.type,s.text,s.at);if(c)return {ok:false,error:c};let b=u(r.reads),I=m(b);if(I)return I;let C=on(r.reads,r.node);if(!C)return y("unsupported-content","that control holds nothing addressable","empty");let T=s.at==="end"?C.end:C.start,F=()=>({kind:"span",span:Y({start:{story:r.reads.story,paragraphId:T.paragraphId,index:r.reads.indexOf(T.paragraphId),offset:T.offset},end:{story:r.reads.story,paragraphId:T.paragraphId,index:r.reads.indexOf(T.paragraphId),offset:T.offset+s.text.length}})});return s.at==="replace"?{ok:true,kind:"command",story:r.reads.story,ops:[{op:"setContentControlValue",controlId:r.control.nodeId,value:{kind:"text",text:s.text}}],answer:F}:{ok:true,kind:"command",story:r.reads.story,ops:s.text.length===0?[]:[{op:"insertText",paragraphId:T.paragraphId,offset:T.offset,text:s.text,inside:r.node.id}],answer:F}}case "deleteContentControl":{let r=Tt(s.contentControl);if(!("control"in r))return r;if(typeof s.keepContent!="boolean")return y("unsupported-content","keepContent is required","keepContent");let c=u(r.reads),b=m(c);return b||{ok:true,kind:"command",story:r.reads.story,ops:[{op:"removeContentControl",controlId:r.control.nodeId,keepContent:s.keepContent}],answer:()=>at}}case "insertContentControl":return Yr(s,n,i,f,t.trackedRangeReplacement,(r,c)=>{let b=u(r);return m(b)??M(b,c)});case "insertCustomNode":{let r=Ja(s);if(r)return y("unsupported-content",r.message,r.detail);let c=Ya(s.payload);if(!c.ok)return y("unsupported-content","that payload cannot be written",c.field);let b=Za(s,n,i);if("code"in b)return y(b.code,b.message,b.detail);let{start:I,end:C}=b.range,T=$(b.range);if(!T)return y("invalid-handle","that story is not in this document");let F=m(u(T));return F||{ok:true,kind:"customNodeWrite",story:T.story,write:Qa(s,I,C,c.value),answer:()=>at}}default:return y("unknown-operation","this host does not implement that operation",String(s.op))}};return {plan(s,f){if(g&&Bt(s))return y("conflicting-operations","header/footer creation must commit alone");let x=h.conflict(s);if(x)return y("conflicting-operations",x.message,x.detail);let O=ni(s,f);if(O.ok&&O.kind==="command"&&O.solitary){if(h.hasCommands)return y("conflicting-operations","header/footer creation must commit alone");g=true;}return O.ok&&h.note(s),O},get hasCommands(){return h.hasCommands},get writeScope(){return v?.reads.scope??null},settle(s){let f=v;if(f){let x=s.story(f.reads.story),O=x&&chunk5MWFZ7F4_cjs.Ja(x.part,f.reads.root.id),R=x&&O&&O.id!==x.root.id?Ke(x,O):x;if(!R)return {ok:false,detail:`the story this batch wrote is gone: ${Q(f.reads.story)}`};let r=new Set(f.reads.paragraphIds),c=R.paragraphIds.filter(I=>!r.has(I));if(c.length!==f.created.length+f.externalCreatedCount)return {ok:false,detail:`planned ${String(f.created.length+f.externalCreatedCount)} new paragraphs, the transaction made ${String(c.length)}`};f.order.filter(I=>I.id===null).forEach((I,C)=>{I.id=c[C]??null;});for(let I of f.retargets)I.slot.id&&n.retarget(I.from,I.slot.id);}for(let x of p){let O=s.story(x.range.start.story);!O||!Vr(x.range,O)||t.select?.(x.range,x.mode);}return {ok:true}}}}var xs=Object.freeze({status:"skipped"});function gt(t,e,o){return Object.freeze(o===void 0?{code:t,message:e}:{code:t,message:e,detail:o})}function bs(t){if(t==="review-module-required"||t==="automation-structural-tracking-unsupported")return gt("unsupported-capability","this edit requires a supported review mode",t);let e=t==="unsupported-revision"||t.startsWith("unsupported-revision:");return gt(e?"unsupported-revision":"transaction-refused",e?"that story contains a tracked change this engine cannot resolve":"the document store refused the transaction",t)}function vt(t,e,o,n){return {ok:false,results:t.map((a,i)=>i===e?{status:"error",error:o}:xs),revision:n,changed:false}}function pp(t){let{port:e}=t,o=Object.freeze({...t.capabilities}),n=br(),a=new Set,i=false,l={mode:"Off"},d=0,u=null,p=null,h=o.events?e.subscribe(()=>{if(i)return;let k=Object.freeze({revision:e.revision()});if(d>0)u=k;else for(let A of [...a])A(k);}):()=>{},g=k=>{if(p&&p.pkg===k)return p.value;let A=ke(k);return p={pkg:k,value:A},A},v=k=>{let A=Array.isArray(k?.operations)?k.operations:[],P=e.revision();if(i)return vt(A,0,gt("disposed","this host was disposed"),P);if(!o.document)return vt(A,0,gt("unsupported-capability","this host has no document","document"),P);let w=e.currentPackage();if(!w)return vt(A,0,gt("document-unavailable","this host holds no document right now"),P);if(k.expectedRevision!==void 0&&k.expectedRevision!==P)return vt(A,0,gt("stale-revision","the document moved since that revision",`expected ${String(k.expectedRevision)}, at ${P}`),P);let N=Un({handles:n,reads:g(w),capabilities:o,collaborative:e.collaborative?.()??false,trackedRangeReplacement:e.trackedRangeReplacement?.()??true,...e.revisionDisplayMode?{displayMode:e.revisionDisplayMode()}:{},...e.replacementLanding?{replacementLanding:e.replacementLanding.bind(e)}:{},...e.fieldPageContext?{fieldPageContext:e.fieldPageContext.bind(e)}:{},...e.select?{select:e.select.bind(e)}:{}}),L=[],D=[],M=null,j=[],S=[],_=null,Y,$=null,V=-1,rt=false,tt=l;for(let W=0;W<A.length;W+=1){let dt=A[W];if(e.suggesting?.()&&dt.op!=="replaceSpan"&&(!vn(dt)||!tt.author&&["insertContentControl","setContentControlProperties","startNewList","setListLevelFormat","insertTable","insertTableRows","updateTable","updateTableCell"].includes(dt.op)))return vt(A,W,gt("unsupported-capability","this operation has no supported tracked form in suggesting mode"),P);let yt=kr(dt,e.localChangeTracking===true,tt),Z=yt?.step??xr(dt,N.plan(dt,tt.author),tt.author);if(yt&&(tt=yt.state),!Z.ok)return vt(A,W,Z.error,P);if(L.push(Z),Z.kind==="command")if(tt.author&&(Z.packageEdits?.length||dt.op==="setContentControlProperties")&&(rt=true),Z.packageEdits&&j.push(...Z.packageEdits),V<0&&(V=W),Z.lifecycle)M=Z.ops[0]??null;else if(Z.relate){let z=Z.relate;D.push(_t=>{let Pe=_t(z.url);return Pe===null?null:z.ops(Pe)});}else {let{ops:z}=Z;D.push(()=>z);}else Z.kind==="commentWrite"?(V<0&&(V=W),S.push(Z.write),_=N.writeScope??{kind:"body"}):Z.kind==="customNodeWrite"&&(V<0&&(V=W),$={write:Z.write,scope:N.writeScope??{kind:"body"}});}let nt=false;if(S.length>0){let W=e.applyCommentWrites(S,_??{kind:"body"});if(!W.ok)return vt(A,V<0?0:V,gt("transaction-refused","the document store refused the comment write",W.reason),P);nt=W.changed,Y=W.commentId;}if($){let W=e.applyCustomNodeWrite($.write,$.scope);if(!W.ok)return vt(A,V<0?0:V,gt("transaction-refused","the document store refused the custom-node write",W.reason),P);nt=W.changed;}if(M){let W=e.applyLifecycle(M);if(!W.ok)return vt(A,V<0?0:V,gt("transaction-refused","the document store refused the transaction",W.reason),P);nt=W.changed;}if(D.length>0){let W=e.apply(dt=>{let yt=[];for(let Z of D){let z=Z(dt);if(z===null)return null;yt.push(...z);}return yt},N.writeScope??{kind:"body"},j,rt);if(!W.ok)return vt(A,V<0?0:V,bs(W.reason),P);nt=W.changed;}let At=e.currentPackage();if(!At)return vt(A,0,gt("document-unavailable","this host holds no document right now"),P);let bt=g(At),it=N.settle(bt);return it.ok?(l=tt,{ok:true,results:L.map(W=>({status:"ok",value:W.kind==="query"?W.value:W.kind==="customNodeWrite"?W.answer(bt):W.answer(bt,Y)})),revision:e.revision(),changed:nt}):vt(A,V<0?0:V,gt("transaction-refused","the transaction did not produce the document the batch planned",it.detail),e.revision())};return {capabilities:o,revision:()=>e.revision(),execute:k=>{d+=1;try{return v(k)}finally{if(d-=1,d===0&&u){let A=u;u=null;for(let P of [...a])P(A);}}},...e.prepare?{prepare:e.prepare.bind(e)}:{},save(){if(i)return {ok:false,error:gt("disposed","this host was disposed")};if(!o.save)return {ok:false,error:gt("unsupported-capability","this host cannot save","save")};let k=e.save();return k?{ok:true,bytes:k}:{ok:false,error:gt("document-unavailable","this host holds no document right now")}},subscribe(k){return i||!o.events?()=>{}:(a.add(k),()=>{a.delete(k);})},dispose(){i||(i=true,a.clear(),h(),e.dispose(),p=null);}}}
|
|
2
|
-
exports.a=Nr;exports.b=Er;exports.c=ii;exports.d=Os;exports.e=Rs;exports.f=Be;exports.g=ke;exports.h=si;exports.i=ur;exports.j=cr;exports.k=_e;exports.l=Bt;exports.m=pp;
|